/** * 公開パスプレフィックス(ブラウザ URL)。PHP boot が window/globalThis に注入する。 * /test 等の販売版固定フォールバックは禁止。未注入時は ''。 * * MUST: * - prefix "/" は空(ルート公開)とみなす。`/` + `/property/` → `//property/` を禁止。 * - 結合は joinPublicPath のみ。スラッシュ重複・protocol-relative を生成しない。 * - 物件詳細 href は propertyHref(条件検索・TOP新着・一覧・駅・建物・お気に入りで共通)。 */ (function (root) { 'use strict'; var UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i; function normalizePrefix(raw) { var s = raw == null ? '' : String(raw).trim(); if (!s || s === '/' || s === '//' || s === '.') return ''; s = s.replace(/\\/g, '/'); s = s.replace(/^\/+|\/+$/g, ''); if (!s || s === '.') return ''; return '/' + s; } function collapseLeadingSlashes(href) { var s = String(href == null ? '' : href); if (/^https?:\/\//i.test(s) || /^data:/i.test(s) || /^mailto:/i.test(s) || /^javascript:/i.test(s)) { return s; } if (s.indexOf('//') === 0) { return '/' + s.replace(/^\/+/, ''); } return s.replace(/^\/{2,}/, '/'); } function joinPublicPath() { var pre = normalizePrefix(getPublicPathPrefix()); var parts = []; var i; for (i = 0; i < arguments.length; i++) { var chunk = String(arguments[i] == null ? '' : arguments[i]).replace(/\\/g, '/'); chunk.split('/').forEach(function (p) { p = String(p || '').trim(); if (p) parts.push(p); }); } var path = parts.join('/'); var href; if (!path) { href = pre === '' ? '/' : pre + '/'; } else { href = (pre === '' ? '' : pre) + '/' + path + '/'; } href = collapseLeadingSlashes(href); if (href.indexOf('//') === 0 && href.indexOf('://') < 0) { href = '/' + href.replace(/^\/+/, ''); } return href; } function canonicalPropertyId(rowOrId) { var raw = ''; if (rowOrId && typeof rowOrId === 'object') { raw = String( rowOrId.id || rowOrId.propertyId || rowOrId.property_id || rowOrId.propertyUUID || rowOrId.propertyUuid || '', ).trim(); } else { raw = String(rowOrId == null ? '' : rowOrId).trim(); } if (!raw) return ''; var m = raw.match(UUID_RE); if (m) return m[0]; return raw.replace(/^\/+|\/+$/g, ''); } function propertyHref(rowOrId) { var id = canonicalPropertyId(rowOrId); if (!id) return collapseLeadingSlashes(joinPublicPath('property')); var encoded; try { encoded = encodeURIComponent(id); } catch (_e) { encoded = String(id); } return collapseLeadingSlashes(joinPublicPath('property', encoded)); } function getPublicPathPrefix() { if (typeof root.__RAKUSUMO_PUBLIC_PATH_PREFIX__ === 'string') { return normalizePrefix(root.__RAKUSUMO_PUBLIC_PATH_PREFIX__); } return ''; } function publicSiteHref(segment) { var seg = String(segment == null ? '' : segment).replace(/^\/+|\/+$/g, ''); if (!seg) return joinPublicPath(); return joinPublicPath(seg); } function publicSiteAsset(path) { var pre = getPublicPathPrefix(); var p = String(path == null ? '' : path).replace(/^\/+/, ''); var href = (pre === '' ? '' : pre) + '/' + p; return collapseLeadingSlashes(href).replace(/\/$/, '') || '/' + p; } root.RakusumoPublicPath = { getPrefix: getPublicPathPrefix, normalizePrefix: normalizePrefix, join: joinPublicPath, joinPublicPath: joinPublicPath, canonicalPropertyId: canonicalPropertyId, propertyHref: propertyHref, href: publicSiteHref, asset: publicSiteAsset, collapseLeadingSlashes: collapseLeadingSlashes, }; if (typeof module === 'object' && module.exports) { module.exports = root.RakusumoPublicPath; } })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this);