/** * embedBase.js — Where THIS bundle's built tree is served from, resolved at runtime. * * WHY: the built tree (//.js + //index.html …) is * dropped onto many hosts — the dev plugin gallery, doxa.life under /js/doxa-maps-build/, * any CDN subpath. Share links + embed snippets must point INTO that tree wherever it * lands, so profiles declare their embed page TREE-RELATIVE (`//index.html` * or `///index.html`) and this module supplies the tree root. * A hardcoded `/js/doxa-maps/…` 404s the moment the tree is served anywhere else. * * Tree root — derived from the bundle's OWN script URL. Rollup rewrites `import.meta.url` * in the IIFE build to `document.currentScript.src` (captured at script start, with a * `document.baseURI` fallback), so in a built bundle it is `//.js` * and the root is two path segments up. It is trusted ONLY when the last two segments look * like `/.js` (the layout generate-tree.mjs emits). In dev (ESM) it is this * module's own URL (`…/library/utils/embedBase.js`) and is rejected — the plugin gallery passes * a whole `shareUrl` instead. * * Embed base ladder — resolveEmbedBase(profileConfig): * 1. profileConfig.embedBaseUrl — host-supplied per embed (`profile-config` JSON) * 2. window.MAP_EMBED_BASE_URL — host-supplied page global, set before the IIFE loads * 3. bundleTreeRoot() — derived from the script URL (a dropped tree works anywhere) * 4. '' — none known; a tree-relative path resolves against the page * * Share URL ladder — resolveShareUrl({ shareUrl, embedPath, profileConfig }): * 1. shareUrl | profileConfig.shareUrl — a WHOLE url from the host wins (plugin gallery deep link) * 2. embedPath | profileConfig.shareEmbedPath * absolute http(s) → passes through * leading '/' → legacy root-relative: location.origin + path * otherwise (tree-relative) → embedBase + '/' + path when a base is known, * else resolved against document.baseURI * 3. location.origin + location.pathname — the page itself ("Share shares THE MAP") * * Host usage (inject before the IIFE loads): * * * * Pure JS, SSR-safe: every window/document access is guarded. */ // Evaluated ONCE at module init — inside the IIFE that is script start, while // document.currentScript still points at the bundle's own