{ "version": 3, "sources": ["site/lib/shell-chrome-ready.mjs"], "sourcesContent": ["/**\n * Ticket 10164: the shell chrome site.js renders, registered once per page.\n * Ticket 11361: from the raw module graph, with the prebuilt everything-bundle\n * as the fallback.\n *\n * site/index.html starts site/lib/shell-chrome.mjs next to site.js on every\n * page and defines `window.__nonounLoadBundle()`, which appends\n * /packages/web-modules/dist/everything.min.js once and returns\n * `window.__nonounBundle` (true on load, false on error). Until ticket 11361\n * every https view loaded that bundle (956 KB raw) next to the raw graph and\n * most components registered twice; now it loads only when a tag the page\n * needs is still unregistered BUNDLE_WAIT_MS after the boot asked for it: a\n * chrome tag here, a route tag in site.js's templateResolver\n * (armBundleFallback()). The bundle registers every tag in SHELL_CHROME_TAGS\n * and every component a route renders; whichever source registers a tag\n * second no-ops (defineIfFree). The page's 8 s watchdog (index.html) is the\n * last resort when neither source registers router-ui.\n */\n\n/**\n * How long a needed tag may stay unregistered before the bundle loads. The\n * 10164 boot waited as long for the bundle before it imported the raw chrome;\n * the order is the other way round now, the bound is the same.\n */\nexport const BUNDLE_WAIT_MS = 4000;\n\n/** Every tag site/lib/shell-chrome.mjs defines. */\nexport const SHELL_CHROME_TAGS = Object.freeze([\n 'brand-mark-ui', 'breadcrumb-ui', 'button-ui', 'command-ui', 'divider-ui', 'drawer-ui', 'icon-ui',\n 'menu-ui', 'menu-item-ui', 'menu-divider-ui', 'menu-label-ui',\n 'nav-group-ui', 'nav-item-ui', 'nav-ui', 'page-ui', 'popover-ui', 'segment-ui', 'segmented-ui',\n 'select-ui', 'slider-ui', 'tag-ui', 'text-ui',\n 'admin-command', 'admin-shell', 'admin-sidebar', 'theme-panel', 'router-ui',\n]);\n\n/**\n * The page's bundle loader (site/index.html), or a no-op where there is none.\n * Off on the Vite dev server (`import.meta.env.DEV`), where a cold transform\n * can outlast the wait with nothing stalled; ?force-bundle still loads the\n * bundle there.\n */\nexport const loadBundle = () => (import.meta.env?.DEV ? undefined : globalThis.__nonounLoadBundle?.());\n\n/**\n * Load the bundle if any of `tags` is still unregistered `waitMs` from now.\n * Returns a cancel function; `stale()` true at that time skips the check (a\n * route the reader has already left).\n * @param {readonly string[]} tags\n * @param {{registry?: {get: (tag: string) => unknown}, fallback?: () => unknown, waitMs?: number, stale?: () => boolean}} [opts]\n * @returns {() => void}\n */\nexport function armBundleFallback(tags, {\n registry = globalThis.customElements,\n fallback = loadBundle,\n waitMs = BUNDLE_WAIT_MS,\n stale = () => false,\n} = {}) {\n if (!tags.length) return () => {};\n const timer = setTimeout(() => {\n if (!stale() && tags.some((tag) => !registry.get(tag))) fallback();\n }, waitMs);\n return () => clearTimeout(timer);\n}\n\n/**\n * Resolves once the chrome is registered: 'graph' when the raw import did it,\n * 'bundle' when the raw import stalled past BUNDLE_WAIT_MS with a chrome tag\n * unregistered and the bundle was asked for, 'failed' when the raw import threw (logged,\n * and the bundle is asked for at once; the caller's whenDefined() waits still\n * decide, and the page watchdog covers a hang). Never rejects.\n * @param {{registry?: {get: (tag: string) => unknown, whenDefined: (tag: string) => Promise}, load?: () => Promise, fallback?: () => unknown, waitMs?: number}} [opts]\n * @returns {Promise<'graph'|'bundle'|'failed'>}\n */\nexport async function shellChromeReady({\n registry = globalThis.customElements,\n load = () => import('./shell-chrome.mjs'),\n fallback = loadBundle,\n waitMs = BUNDLE_WAIT_MS,\n} = {}) {\n let fired = false;\n const ask = () => { fired = true; return fallback(); };\n const cancel = armBundleFallback(SHELL_CHROME_TAGS, { registry, fallback: ask, waitMs });\n const registered = Promise.all(SHELL_CHROME_TAGS.map((tag) => registry.whenDefined(tag)));\n try {\n await Promise.race([load(), registered]);\n return fired ? 'bundle' : 'graph';\n } catch (err) {\n console.error('[site] the shell chrome modules failed to load:', err);\n ask();\n return 'failed';\n } finally {\n cancel();\n }\n}\n"], "mappings": "AAwBO,aAAM,eAAiB,IAGjB,kBAAoB,OAAO,OAAO,CAC7C,gBAAiB,gBAAiB,YAAa,aAAc,aAAc,YAAa,UACxF,UAAW,eAAgB,kBAAmB,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