brumate 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{boot-DQuAhAd5.d.ts → boot-ej-9NRT3.d.ts} +20 -2
- package/dist/cli.js +88 -82
- package/dist/cli.js.map +1 -1
- package/dist/{client-CwVcmymi.js → client-B-ww-PQ7.js} +304 -48
- package/dist/client-B-ww-PQ7.js.map +1 -0
- package/dist/{client-4eabQtYJ.d.ts → client-Do6IBIhI.d.ts} +35 -9
- package/dist/{defer-BaXWydb0.js → defer-JD2FK9mV.js} +5 -3
- package/dist/defer-JD2FK9mV.js.map +1 -0
- package/dist/{devtools-calls-DGW6nLZ2.js → devtools-calls-DCjuSkim.js} +3 -3
- package/dist/{devtools-calls-DGW6nLZ2.js.map → devtools-calls-DCjuSkim.js.map} +1 -1
- package/dist/{devtools-panel-Cq8LpsyW.js → devtools-panel-DLeWTPhU.js} +4 -4
- package/dist/{devtools-panel-Cq8LpsyW.js.map → devtools-panel-DLeWTPhU.js.map} +1 -1
- package/dist/{devtools-CMuj12yR.js → devtools-tuq7ATGN.js} +10 -7
- package/dist/devtools-tuq7ATGN.js.map +1 -0
- package/dist/{error-catalog-DakxjSgj.js → error-catalog-BBWB7w-E.js} +11 -4
- package/dist/error-catalog-BBWB7w-E.js.map +1 -0
- package/dist/{error-catalog-VxLbz-6p.js → error-catalog-CbmQqfat.js} +1 -1
- package/dist/{events-LgLdp1R7.js → events-BDVITj3P.js} +3 -5
- package/dist/events-BDVITj3P.js.map +1 -0
- package/dist/{features-DwMYKBIC.js → features-Cte5aj20.js} +8 -2
- package/dist/features-Cte5aj20.js.map +1 -0
- package/dist/{files-DXS8RAtZ.js → files-Bz0lAQzD.js} +2 -2
- package/dist/{files-DXS8RAtZ.js.map → files-Bz0lAQzD.js.map} +1 -1
- package/dist/{html-Cf5uKhLs.js → html-BYuHDvxy.js} +10 -3
- package/dist/html-BYuHDvxy.js.map +1 -0
- package/dist/index.d.ts +71 -19
- package/dist/index.js +3 -3
- package/dist/{inspect-B5AoHh5O.js → inspect-fpaBJ5pm.js} +1247 -62
- package/dist/inspect-fpaBJ5pm.js.map +1 -0
- package/dist/{loader-CTeT6ie9.js → loader-DMxuZ6He.js} +14 -6
- package/dist/loader-DMxuZ6He.js.map +1 -0
- package/dist/{navigate-Bj73X4ZS.js → navigate-C5PjwYMh.js} +101 -20
- package/dist/navigate-C5PjwYMh.js.map +1 -0
- package/dist/{produce-CLABZ8k2.d.ts → produce-BDkCsGH7.d.ts} +3 -3
- package/dist/{rpc-kVB0Ujdx.js → rpc-DOdrekhP.js} +23 -13
- package/dist/rpc-DOdrekhP.js.map +1 -0
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/bundles.js +6 -2
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -3
- package/dist/runtime/client.js +5 -5
- package/dist/runtime/devtools.d.ts +3 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/otel.d.ts +18 -0
- package/dist/runtime/otel.js +127 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-qGERTLi3.js +382 -0
- package/dist/search-params-qGERTLi3.js.map +1 -0
- package/dist/{serial-ribg9NAj.js → serial-B2AJ9VGx.js} +1 -1
- package/dist/{serial-ioa17MuY.js → serial-Cj6pDGOq.js} +6 -6
- package/dist/{serial-ioa17MuY.js.map → serial-Cj6pDGOq.js.map} +1 -1
- package/dist/{server-DesBZv5g.d.ts → server-2-LS_KFo.d.ts} +125 -9
- package/dist/{server-BUuf7XPZ.js → server-CRGZMWnK.js} +545 -236
- package/dist/server-CRGZMWnK.js.map +1 -0
- package/dist/{shared-CX_YacDm.js → shared-CUBWrbiM.js} +4 -4
- package/dist/{shared-CX_YacDm.js.map → shared-CUBWrbiM.js.map} +1 -1
- package/dist/sheets-B9Zr50mf.js +105 -0
- package/dist/sheets-B9Zr50mf.js.map +1 -0
- package/dist/{signals-7VVD9C_H.d.ts → signals-BgsJK-uT.d.ts} +16 -6
- package/dist/{static-loader-BM0-wdIc.js → static-loader-BDBtWsdg.js} +107 -19
- package/dist/static-loader-BDBtWsdg.js.map +1 -0
- package/dist/{static-loader-BSAyFqG0.d.ts → static-loader-CAFn6p0l.d.ts} +2 -2
- package/dist/{store-9_oa0HG1.d.ts → store-BwWg-Iei.d.ts} +79 -2
- package/dist/store-DNr24Z8L.js +950 -0
- package/dist/store-DNr24Z8L.js.map +1 -0
- package/dist/{stream-read-BTsYstJY.js → stream-read-CiLDH60b.js} +2 -2
- package/dist/{stream-read-BTsYstJY.js.map → stream-read-CiLDH60b.js.map} +1 -1
- package/dist/{stream-read-Dek3HnqO.js → stream-read-DVoregpA.js} +1 -1
- package/dist/trace-DT7RGRAV.d.ts +52 -0
- package/dist/trace-browser-C7MFMove.js +170 -0
- package/dist/trace-browser-C7MFMove.js.map +1 -0
- package/dist/trace-flag-Dy267snx.js +7 -0
- package/dist/trace-flag-Dy267snx.js.map +1 -0
- package/dist/{trusted-g_zUJbh2.js → trusted-Bmwg4_hf.js} +12 -5
- package/dist/trusted-Bmwg4_hf.js.map +1 -0
- package/dist/view-transitions-BpnVwtS4.js +141 -0
- package/dist/view-transitions-BpnVwtS4.js.map +1 -0
- package/dist/vite.d.ts +8 -1
- package/dist/vite.js +356 -46
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +8 -0
- package/package.json +13 -1
- package/skills/brumate/SKILL.md +9 -5
- package/skills/brumate/references/errors.md +95 -14
- package/skills/brumate/references/events.md +27 -1
- package/skills/brumate/references/signals.md +4 -4
- package/skills/brumate/references/state.md +79 -4
- package/skills/brumate/references/syntax.md +58 -9
- package/dist/client-CwVcmymi.js.map +0 -1
- package/dist/defer-BaXWydb0.js.map +0 -1
- package/dist/devtools-CMuj12yR.js.map +0 -1
- package/dist/error-catalog-DakxjSgj.js.map +0 -1
- package/dist/events-LgLdp1R7.js.map +0 -1
- package/dist/features-DwMYKBIC.js.map +0 -1
- package/dist/html-Cf5uKhLs.js.map +0 -1
- package/dist/inspect-B5AoHh5O.js.map +0 -1
- package/dist/loader-CTeT6ie9.js.map +0 -1
- package/dist/navigate-Bj73X4ZS.js.map +0 -1
- package/dist/rpc-kVB0Ujdx.js.map +0 -1
- package/dist/search-params-Wg-0FsMj.js +0 -148
- package/dist/search-params-Wg-0FsMj.js.map +0 -1
- package/dist/server-BUuf7XPZ.js.map +0 -1
- package/dist/static-loader-BM0-wdIc.js.map +0 -1
- package/dist/store-Cy4EEyZ7.js +0 -439
- package/dist/store-Cy4EEyZ7.js.map +0 -1
- package/dist/trusted-g_zUJbh2.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"static-loader-BM0-wdIc.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count. A\n * single letter after a modifier matches in either case, as the browser sends `k` for Cmd+K and\n * `K` for Cmd+Shift+K. A letter alone keeps its case, as `a` and `A` type different text.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n let name = plus > 0 ? key.slice(plus + 1) : key;\n let pressed = event.key === ' ' ? 'Space' : event.key;\n if (plus > 0 && name.length === 1) {\n name = name.toLowerCase();\n pressed = pressed.toLowerCase();\n }\n if (pressed !== name) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref` (`b-b`), or that a component\n // forwards to its signal (`b-r`), or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const selector = `[b-b=\"${near}\"],[b-r=\"${near}\"]`;\n const next =\n (near && (root.querySelector(selector) ?? document.querySelector(selector))) || after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AA0DA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ,aAAa,MAAM,KAAK;CAC9C,OAAQ,OAAO,IAAI,KAAK,KACtB,OACG,IACC,OACA,MACG,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CAAC,CACf,KAAK,UAAU;EACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;EACnC,MAAM,CAAC,MAAM,GAAG,aAAa,KAAK,MAAM,GAAG;EAC3C,OAAO;GAAE,KAAK;GAAO;GAAM;GAAW;EAAI;CAC5C,CAAC,CACL,CAAC,CACA,IAAI,KAAK;AAChB;;;;;AASA,IAAI;AACJ,MAAa,mBACV,gBAAgB,OAAO,sBAAc,CAAC,MACpC,WAAW,OAAO,SAClB,UAAmB;CAElB,cAAc,KAAA;CACd,MAAM;AACR,CACF;;AAGF,MAAM,QAAQ,QAA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AACrB"}
|
package/dist/store-Cy4EEyZ7.js
DELETED
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import { i as HAS_BRIDGES } from "./features-DwMYKBIC.js";
|
|
2
|
-
//#region src/runtime/store.ts
|
|
3
|
-
/** The pass of the core, which the browser sets, so a store's readers update in one pass. */
|
|
4
|
-
const PASS = Symbol.for("brumate.pass");
|
|
5
|
-
/** True for a context, which `createContext` made. */
|
|
6
|
-
function isContext(value) {
|
|
7
|
-
return typeof value === "object" && value !== null && typeof value.key === "string" && Object.keys(value).length === 1 && !isContract(value);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* The store that `$store` reads: `value` is the store, or for `path` an object that holds it there.
|
|
11
|
-
* `key` names the context that gave `value`, for the message. Throws a `TypeError` for a value that
|
|
12
|
-
* is no store, such as `undefined` or a context, and for `write` on a store that has no `set`.
|
|
13
|
-
*/
|
|
14
|
-
function findStored(value, path, write, key) {
|
|
15
|
-
const found = path === void 0 ? value : value?.[path];
|
|
16
|
-
if (!isContract(found)) {
|
|
17
|
-
if (isContext(found)) throw new TypeError(`$store reads the context "${found.key}", which is no store. Read the store in it with $store($getContext(Context))`);
|
|
18
|
-
throw new TypeError(`$store reads ${key === void 0 ? "a value" : `the context "${key}"`}${path === void 0 ? "" : ` at "${path}"`}, which gives no store: a store has the functions get and subscribe`);
|
|
19
|
-
}
|
|
20
|
-
if (write && !canSet(found)) throw new TypeError(`let $store(${key ?? "…"}) writes the store, but the store has no set. Read it with const`);
|
|
21
|
-
return found;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The error of `$store` for a store of another library in a value that the page sends, such as a
|
|
25
|
-
* prop: only the value of a store of `brumate/store` crosses. The fix is said here only.
|
|
26
|
-
*/
|
|
27
|
-
function sentForeignStore(component, value) {
|
|
28
|
-
return /* @__PURE__ */ new Error(`$store in ${component} reads a store of another library from ${value}, which the page sends, and only a store of brumate/store crosses. Wrap the library's store with bridge() in a module, or read it from an import, <script module> or a call in this component`);
|
|
29
|
-
}
|
|
30
|
-
/** A value that changes, with the functions that read it and write it. */
|
|
31
|
-
var Store = class {
|
|
32
|
-
/** The value. */
|
|
33
|
-
v;
|
|
34
|
-
/** The functions that `subscribe` added. */
|
|
35
|
-
l = /* @__PURE__ */ new Set();
|
|
36
|
-
/** For a store of `$toStore(signal)`, the write of the signal, which the browser sets. */
|
|
37
|
-
w;
|
|
38
|
-
/** True for a store of `$toStore(memo)`, which only its provider writes. */
|
|
39
|
-
r;
|
|
40
|
-
/** Where `$toStore` made it, for the page state. */
|
|
41
|
-
o;
|
|
42
|
-
/** True for a store of `$toStore` in the browser until its first update. */
|
|
43
|
-
f;
|
|
44
|
-
/**
|
|
45
|
-
* The mark of a store, which `isStore` reads in every copy of the runtime. A field, so a build
|
|
46
|
-
* without stores drops the class.
|
|
47
|
-
*/
|
|
48
|
-
k = "brumate.store";
|
|
49
|
-
constructor(value) {
|
|
50
|
-
this.v = value;
|
|
51
|
-
}
|
|
52
|
-
/** The current value. */
|
|
53
|
-
get() {
|
|
54
|
-
return this.v;
|
|
55
|
-
}
|
|
56
|
-
/** Calls `listener` with each new value. Returns the function that stops it. */
|
|
57
|
-
subscribe(listener) {
|
|
58
|
-
this.l.add(listener);
|
|
59
|
-
return () => {
|
|
60
|
-
this.l.delete(listener);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Writes the value, and calls the listeners when it changed. A store of `$toStore(signal)`
|
|
65
|
-
* writes the signal, and a store of a memo throws.
|
|
66
|
-
*/
|
|
67
|
-
set(value) {
|
|
68
|
-
if (this.r) throw new Error("This store follows a memo, so only its provider writes it");
|
|
69
|
-
if (Object.is(this.v, value)) return;
|
|
70
|
-
if (this.w) {
|
|
71
|
-
this.v = value;
|
|
72
|
-
this.w(value);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
sendStore(this, value);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
/** True for a store of `brumate/store`, of any copy of the runtime. */
|
|
79
|
-
function isStore(value) {
|
|
80
|
-
return typeof value === "object" && value !== null && value.k === "brumate.store";
|
|
81
|
-
}
|
|
82
|
-
/** True for a value with the functions `get` and `subscribe` of the store contract. */
|
|
83
|
-
function isContract(value) {
|
|
84
|
-
return typeof value === "object" && value !== null && typeof value.get === "function" && typeof value.subscribe === "function";
|
|
85
|
-
}
|
|
86
|
-
/** True for a value of the store contract that is not a store of brumate. */
|
|
87
|
-
function isForeignStore(value) {
|
|
88
|
-
return isContract(value) && !isStore(value) && !(HAS_BRIDGES && isBridged(value));
|
|
89
|
-
}
|
|
90
|
-
/** True when `$store` can write the store: it has `set`, and is not the store of a memo. */
|
|
91
|
-
function canSet(value) {
|
|
92
|
-
return typeof value.set === "function" && !value.r;
|
|
93
|
-
}
|
|
94
|
-
/** Makes a store, such as one that a module holds for the whole app. */
|
|
95
|
-
function store(value) {
|
|
96
|
-
return new Store(value);
|
|
97
|
-
}
|
|
98
|
-
/** Writes the value of a store and calls its listeners, in one pass of the page. */
|
|
99
|
-
function sendStore(target, value, force) {
|
|
100
|
-
if (!force && Object.is(target.v, value)) return;
|
|
101
|
-
target.v = value;
|
|
102
|
-
const listeners = () => {
|
|
103
|
-
for (const listener of target.l) listener(value);
|
|
104
|
-
};
|
|
105
|
-
const pass = globalThis[PASS];
|
|
106
|
-
if (pass) pass(listeners);
|
|
107
|
-
else listeners();
|
|
108
|
-
}
|
|
109
|
-
/** The derived stores that heard of a change and wait to compute. */
|
|
110
|
-
const waiting = [];
|
|
111
|
-
/** The listener sets that have a trailing listener, which computes the waiting stores. */
|
|
112
|
-
const armed = /* @__PURE__ */ new Set();
|
|
113
|
-
/** True while the waiting stores compute. */
|
|
114
|
-
let flushing = false;
|
|
115
|
-
/** Computes the waiting derived stores, the ones that read the fewest derived stores first. */
|
|
116
|
-
function flushComputed() {
|
|
117
|
-
flushing = true;
|
|
118
|
-
try {
|
|
119
|
-
while (waiting.length > 0) {
|
|
120
|
-
let next = 0;
|
|
121
|
-
for (let i = 1; i < waiting.length; i++) if (waiting[i].level < waiting[next].level) next = i;
|
|
122
|
-
const [computed] = waiting.splice(next, 1);
|
|
123
|
-
computed.waits = false;
|
|
124
|
-
computed.run();
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
for (const computed of waiting) computed.waits = false;
|
|
128
|
-
waiting.length = 0;
|
|
129
|
-
throw error;
|
|
130
|
-
} finally {
|
|
131
|
-
flushing = false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function derived(sources, fn, initial) {
|
|
135
|
-
const single = !Array.isArray(sources);
|
|
136
|
-
const list = single ? [sources] : sources;
|
|
137
|
-
for (const source of list) if (!source) throw new Error("derived() expects stores as input, got a falsy value");
|
|
138
|
-
const auto = fn.length < 2;
|
|
139
|
-
const out = new Store(initial);
|
|
140
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
141
|
-
let level = 1;
|
|
142
|
-
for (const source of list) level = Math.max(level, (source.d ?? 0) + 1);
|
|
143
|
-
let cleanup;
|
|
144
|
-
let started = false;
|
|
145
|
-
let starting = false;
|
|
146
|
-
let stops = [];
|
|
147
|
-
/** Runs `fn` over the current values of the sources. */
|
|
148
|
-
const compute = (write) => {
|
|
149
|
-
const values = [];
|
|
150
|
-
for (const source of list) values.push(source.get());
|
|
151
|
-
const set = write;
|
|
152
|
-
const update = (change) => write(change(out.v));
|
|
153
|
-
cleanup?.();
|
|
154
|
-
cleanup = void 0;
|
|
155
|
-
const result = fn(single ? values[0] : values, set, update);
|
|
156
|
-
if (auto) write(result);
|
|
157
|
-
else if (typeof result === "function") cleanup = result;
|
|
158
|
-
};
|
|
159
|
-
const send = (value) => {
|
|
160
|
-
if (starting) out.v = value;
|
|
161
|
-
else if (started) sendStore(out, value);
|
|
162
|
-
else out.v = value;
|
|
163
|
-
};
|
|
164
|
-
const state = {
|
|
165
|
-
level,
|
|
166
|
-
waits: false,
|
|
167
|
-
run() {
|
|
168
|
-
if (started) compute(send);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Called by a source. The store waits until the source has called all its listeners, so a store
|
|
173
|
-
* that reads this one and the source computes once, after this one.
|
|
174
|
-
*/
|
|
175
|
-
const heard = (source) => {
|
|
176
|
-
if (!started || state.waits) return;
|
|
177
|
-
state.waits = true;
|
|
178
|
-
waiting.push(state);
|
|
179
|
-
if (flushing) return;
|
|
180
|
-
const listeners = source.l;
|
|
181
|
-
if (!listeners || armed.has(listeners)) {
|
|
182
|
-
if (!listeners) flushComputed();
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const trail = () => {
|
|
186
|
-
listeners.delete(trail);
|
|
187
|
-
armed.delete(listeners);
|
|
188
|
-
flushComputed();
|
|
189
|
-
};
|
|
190
|
-
armed.add(listeners);
|
|
191
|
-
listeners.add(trail);
|
|
192
|
-
};
|
|
193
|
-
const start = () => {
|
|
194
|
-
starting = true;
|
|
195
|
-
started = true;
|
|
196
|
-
try {
|
|
197
|
-
compute(send);
|
|
198
|
-
for (const source of list) stops.push(source.subscribe(() => heard(source)));
|
|
199
|
-
} catch (error) {
|
|
200
|
-
started = false;
|
|
201
|
-
for (const end of stops) end();
|
|
202
|
-
stops = [];
|
|
203
|
-
cleanup?.();
|
|
204
|
-
cleanup = void 0;
|
|
205
|
-
throw error;
|
|
206
|
-
} finally {
|
|
207
|
-
starting = false;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
const stop = () => {
|
|
211
|
-
started = false;
|
|
212
|
-
for (const end of stops) end();
|
|
213
|
-
stops = [];
|
|
214
|
-
cleanup?.();
|
|
215
|
-
cleanup = void 0;
|
|
216
|
-
if (state.waits) {
|
|
217
|
-
state.waits = false;
|
|
218
|
-
waiting.splice(waiting.indexOf(state), 1);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
return Object.assign({
|
|
222
|
-
get() {
|
|
223
|
-
if (started) return out.v;
|
|
224
|
-
let value = out.v;
|
|
225
|
-
started = true;
|
|
226
|
-
try {
|
|
227
|
-
compute((next) => {
|
|
228
|
-
value = next;
|
|
229
|
-
});
|
|
230
|
-
} finally {
|
|
231
|
-
started = false;
|
|
232
|
-
cleanup?.();
|
|
233
|
-
cleanup = void 0;
|
|
234
|
-
}
|
|
235
|
-
return value;
|
|
236
|
-
},
|
|
237
|
-
subscribe(listener) {
|
|
238
|
-
const stopListening = out.subscribe(listener);
|
|
239
|
-
if (!started) try {
|
|
240
|
-
start();
|
|
241
|
-
} catch (error) {
|
|
242
|
-
stopListening();
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
subscribers.add(stopListening);
|
|
246
|
-
return () => {
|
|
247
|
-
if (subscribers.delete(stopListening)) {
|
|
248
|
-
stopListening();
|
|
249
|
-
if (subscribers.size === 0) stop();
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
}, { d: level });
|
|
254
|
-
}
|
|
255
|
-
const BRIDGES = Symbol.for("brumate.bridges");
|
|
256
|
-
const BRIDGE_LOAD = Symbol.for("brumate.bridge-load");
|
|
257
|
-
/** The bridges by name, which any copy of the runtime shares. */
|
|
258
|
-
function bridges() {
|
|
259
|
-
return globalThis[BRIDGES] ??= /* @__PURE__ */ new Map();
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Sets how the browser loads the module of a bridge, and where a failed load is reported. The
|
|
263
|
-
* core calls it when it starts.
|
|
264
|
-
*/
|
|
265
|
-
function setBridgeLoader(...loader) {
|
|
266
|
-
globalThis[BRIDGE_LOAD] = loader;
|
|
267
|
-
}
|
|
268
|
-
/** The module of a bridge, from its name. */
|
|
269
|
-
function bridgeModule(id) {
|
|
270
|
-
return id.slice(0, id.lastIndexOf("#"));
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Makes a bridge. Keep its value in a module-level export, so the page state can name it:
|
|
274
|
-
* `export const bears = bridge({ … })`. The compiler gives it its name.
|
|
275
|
-
*/
|
|
276
|
-
function bridge(options) {
|
|
277
|
-
const made = Object.assign((snapshot) => new Bridged(made, options.create(snapshot)), { b: options });
|
|
278
|
-
return made;
|
|
279
|
-
}
|
|
280
|
-
/** Gives a bridge its name, which the compiler writes at the end of its module. */
|
|
281
|
-
function nameBridge(made, id) {
|
|
282
|
-
made.i = id;
|
|
283
|
-
bridges().set(id, made);
|
|
284
|
-
}
|
|
285
|
-
/** True for a store of `bridge()`, of any copy of the runtime. */
|
|
286
|
-
function isBridged(value) {
|
|
287
|
-
return typeof value === "object" && value !== null && value.k === "brumate.bridge";
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Whether two values hold the same data: the same value, or arrays and plain objects whose items
|
|
291
|
-
* hold the same data. A store that the browser makes again holds a new object with the content
|
|
292
|
-
* the server sent, which needs no repair.
|
|
293
|
-
*/
|
|
294
|
-
function sameData(a, b, open) {
|
|
295
|
-
if (Object.is(a, b)) return true;
|
|
296
|
-
const array = Array.isArray(a);
|
|
297
|
-
if (array ? !Array.isArray(b) || a.length !== b.length : !isPlain(a) || !isPlain(b)) return false;
|
|
298
|
-
const left = a;
|
|
299
|
-
const right = b;
|
|
300
|
-
open ??= /* @__PURE__ */ new Map();
|
|
301
|
-
let pairs = open.get(left);
|
|
302
|
-
if (pairs?.has(right)) return true;
|
|
303
|
-
if (!pairs) {
|
|
304
|
-
pairs = /* @__PURE__ */ new Set();
|
|
305
|
-
open.set(left, pairs);
|
|
306
|
-
}
|
|
307
|
-
pairs.add(right);
|
|
308
|
-
const keys = Object.keys(left);
|
|
309
|
-
if (!array && keys.length !== Object.keys(right).length) return false;
|
|
310
|
-
for (const key of keys) if (!(key in right) || !sameData(left[key], right[key], open)) return false;
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
/** Whether a value is an object of `Object` or of no prototype, as page state holds. */
|
|
314
|
-
function isPlain(value) {
|
|
315
|
-
if (typeof value !== "object" || value === null) return false;
|
|
316
|
-
const proto = Object.getPrototypeOf(value);
|
|
317
|
-
return proto === Object.prototype || proto === null;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* The store that a bridge makes. On the server it holds the library's store from the start. In
|
|
321
|
-
* the browser the page state makes it with the name of the bridge and the data of the server, and
|
|
322
|
-
* it makes the library's store at its first subscriber.
|
|
323
|
-
*/
|
|
324
|
-
var Bridged = class {
|
|
325
|
-
/** The mark of a bridged store, which `isBridged` reads in every copy of the runtime. */
|
|
326
|
-
k = "brumate.bridge";
|
|
327
|
-
/** The bridge. Undefined for a store of the page state until the module of the bridge loads. */
|
|
328
|
-
f;
|
|
329
|
-
/** The name of the bridge, for a store of the page state. */
|
|
330
|
-
i;
|
|
331
|
-
/** The library's store. */
|
|
332
|
-
s;
|
|
333
|
-
/** True once the library's store exists. */
|
|
334
|
-
m = false;
|
|
335
|
-
/** The data that the server sent, until the library's store exists. */
|
|
336
|
-
v;
|
|
337
|
-
/** Whether the bridge has `set`, as the server sent it, until the module loads. */
|
|
338
|
-
w;
|
|
339
|
-
constructor(made, source, id, snapshot, writable) {
|
|
340
|
-
this.f = made;
|
|
341
|
-
this.i = id;
|
|
342
|
-
this.v = snapshot;
|
|
343
|
-
this.w = writable;
|
|
344
|
-
if (made) {
|
|
345
|
-
this.s = source;
|
|
346
|
-
this.m = true;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* The library's store. In the browser it is undefined until the store has a subscriber and the
|
|
351
|
-
* module of the bridge has loaded.
|
|
352
|
-
*/
|
|
353
|
-
get source() {
|
|
354
|
-
return this.s;
|
|
355
|
-
}
|
|
356
|
-
/** The name of the bridge. */
|
|
357
|
-
get id() {
|
|
358
|
-
return this.f?.i ?? this.i;
|
|
359
|
-
}
|
|
360
|
-
/** The data of the store: what `get` reads, or what the server sent before the first subscriber. */
|
|
361
|
-
get() {
|
|
362
|
-
return this.m ? this.f.b.get(this.s) : this.v;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Calls `listener` with the data when it changes. The first subscriber makes the library's
|
|
366
|
-
* store in the browser. When the module of the bridge has not loaded, the subscription starts
|
|
367
|
-
* when it has.
|
|
368
|
-
*/
|
|
369
|
-
subscribe(listener, ...seen) {
|
|
370
|
-
let stopped = false;
|
|
371
|
-
let stop;
|
|
372
|
-
let last = seen.length > 0 ? seen[0] : this.get();
|
|
373
|
-
const start = () => {
|
|
374
|
-
if (stopped) return;
|
|
375
|
-
const options = this.f.b;
|
|
376
|
-
const source = this.make();
|
|
377
|
-
stop = options.subscribe(source, () => {
|
|
378
|
-
const next = options.get(source);
|
|
379
|
-
if (!sameData(next, last)) {
|
|
380
|
-
last = next;
|
|
381
|
-
listener(next);
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
const first = options.get(source);
|
|
385
|
-
if (!sameData(first, last)) {
|
|
386
|
-
last = first;
|
|
387
|
-
listener(first);
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
if (this.find()) start();
|
|
391
|
-
else this.load().then((loaded) => loaded && start());
|
|
392
|
-
return () => {
|
|
393
|
-
stopped = true;
|
|
394
|
-
stop?.();
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
/** Writes the library's store, when the bridge has `set`. */
|
|
398
|
-
get set() {
|
|
399
|
-
return (this.find() ? !!this.f.b.set : this.w !== false) ? (value) => this.write(value) : void 0;
|
|
400
|
-
}
|
|
401
|
-
/** Writes the library's store, after the module of the bridge has loaded. */
|
|
402
|
-
write(value) {
|
|
403
|
-
if (this.find()) this.f.b.set(this.make(), value);
|
|
404
|
-
else this.load().then((loaded) => loaded && this.write(value));
|
|
405
|
-
}
|
|
406
|
-
/** The bridge, once its module has loaded. */
|
|
407
|
-
find() {
|
|
408
|
-
if (!this.f && this.i !== void 0) this.f = bridges().get(this.i);
|
|
409
|
-
return this.f;
|
|
410
|
-
}
|
|
411
|
-
/** Loads the module of the bridge. A failure goes to the core's error path; it gives false. */
|
|
412
|
-
load() {
|
|
413
|
-
const [load, report] = globalThis[BRIDGE_LOAD] ?? [];
|
|
414
|
-
return Promise.resolve(load?.(bridgeModule(this.i))).then(() => {
|
|
415
|
-
if (this.find()) return true;
|
|
416
|
-
this.fail(report, /* @__PURE__ */ new Error(`The bridge "${this.i}" is not in its module. Keep bridge() in a module-level export, as "export const name = bridge({ … })"`));
|
|
417
|
-
return false;
|
|
418
|
-
}, (error) => {
|
|
419
|
-
this.fail(report, error);
|
|
420
|
-
return false;
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
fail(report, error) {
|
|
424
|
-
if (report) report(error);
|
|
425
|
-
else console.error(error);
|
|
426
|
-
}
|
|
427
|
-
/** Makes the library's store once, with the data of the server. */
|
|
428
|
-
make() {
|
|
429
|
-
if (!this.m) {
|
|
430
|
-
this.s = this.f.b.create(this.v);
|
|
431
|
-
this.m = true;
|
|
432
|
-
}
|
|
433
|
-
return this.s;
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
//#endregion
|
|
437
|
-
export { store as _, derived as a, isContext as c, isStore as d, nameBridge as f, setBridgeLoader as g, sentForeignStore as h, canSet as i, isContract as l, sendStore as m, Store as n, findStored as o, sameData as p, bridge as r, isBridged as s, Bridged as t, isForeignStore as u };
|
|
438
|
-
|
|
439
|
-
//# sourceMappingURL=store-Cy4EEyZ7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store-Cy4EEyZ7.js","names":[],"sources":["../src/runtime/store.ts"],"sourcesContent":["// Stores: values that change, which a context can hold while the context itself stays the same.\n// `$toStore` makes the store of a provider, and `$store` reads one in a component. The page state\n// sends only the value of a store; the browser makes a new store for it.\n\nimport type { Context } from './context.ts';\nimport { HAS_BRIDGES } from './features.ts';\n\n/** The pass of the core, which the browser sets, so a store's readers update in one pass. */\nconst PASS = Symbol.for('brumate.pass');\n\n/** True for a context, which `createContext` made. */\nexport function isContext(value: unknown): value is Context<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { key?: unknown }).key === 'string' &&\n Object.keys(value).length === 1 &&\n !isContract(value)\n );\n}\n\n/**\n * The store that `$store` reads: `value` is the store, or for `path` an object that holds it there.\n * `key` names the context that gave `value`, for the message. Throws a `TypeError` for a value that\n * is no store, such as `undefined` or a context, and for `write` on a store that has no `set`.\n */\nexport function findStored(\n value: unknown,\n path: string | undefined,\n write: boolean | undefined,\n key?: string,\n): StoreLike<unknown> {\n const found = path === undefined ? value : (value as Record<string, unknown> | undefined)?.[path];\n if (!isContract(found)) {\n // A context is the most likely mistake, so its message names the read that gives its store.\n if (isContext(found)) {\n throw new TypeError(\n `$store reads the context \"${found.key}\", which is no store. Read the store in it with $store($getContext(Context))`,\n );\n }\n throw new TypeError(\n `$store reads ${key === undefined ? 'a value' : `the context \"${key}\"`}${path === undefined ? '' : ` at \"${path}\"`}, which gives no store: a store has the functions get and subscribe`,\n );\n }\n if (write && !canSet(found)) {\n throw new TypeError(\n `let $store(${key ?? '…'}) writes the store, but the store has no set. Read it with const`,\n );\n }\n return found;\n}\n\n/**\n * The error of `$store` for a store of another library in a value that the page sends, such as a\n * prop: only the value of a store of `brumate/store` crosses. The fix is said here only.\n */\nexport function sentForeignStore(component: string, value: string): Error {\n return new Error(\n `$store in ${component} reads a store of another library from ${value}, which the page sends, and only a store of brumate/store crosses. Wrap the library's store with bridge() in a module, or read it from an import, <script module> or a call in this component`,\n );\n}\n\n/** Where `$toStore` made a store: its scope, the ID of its site, and the slot of its signal. */\nexport type StoreOrigin = [scope: number | string, site: number, slot?: number];\n\n/**\n * The contract of a store, which `$store` reads: `get`, `subscribe` (which returns the function\n * that stops it, and does not call the listener at once) and, for a two-way binding, `set`.\n */\nexport interface StoreLike<T> {\n get(): T;\n subscribe(listener: (value: T) => void): () => void;\n set?(value: T): void;\n}\n\n/** A value that changes, with the functions that read it and write it. */\nexport class Store<T> implements StoreLike<T> {\n /** The value. */\n v: T;\n /** The functions that `subscribe` added. */\n l: Set<(value: T) => void> = new Set();\n /** For a store of `$toStore(signal)`, the write of the signal, which the browser sets. */\n w?: (value: T) => void;\n /** True for a store of `$toStore(memo)`, which only its provider writes. */\n r?: boolean;\n /** Where `$toStore` made it, for the page state. */\n o?: StoreOrigin;\n /** True for a store of `$toStore` in the browser until its first update. */\n f?: boolean;\n /**\n * The mark of a store, which `isStore` reads in every copy of the runtime. A field, so a build\n * without stores drops the class.\n */\n k = 'brumate.store' as const;\n\n constructor(value: T) {\n this.v = value;\n }\n\n /** The current value. */\n get(): T {\n return this.v;\n }\n\n /** Calls `listener` with each new value. Returns the function that stops it. */\n subscribe(listener: (value: T) => void): () => void {\n this.l.add(listener);\n return () => {\n this.l.delete(listener);\n };\n }\n\n /**\n * Writes the value, and calls the listeners when it changed. A store of `$toStore(signal)`\n * writes the signal, and a store of a memo throws.\n */\n set(value: T): void {\n if (this.r) {\n throw new Error('This store follows a memo, so only its provider writes it');\n }\n if (Object.is(this.v, value)) {\n return;\n }\n if (this.w) {\n this.v = value;\n this.w(value);\n return;\n }\n sendStore(this, value);\n }\n}\n\n/** True for a store of `brumate/store`, of any copy of the runtime. */\nexport function isStore(value: unknown): value is Store<unknown> {\n return (\n typeof value === 'object' && value !== null && (value as { k?: unknown }).k === 'brumate.store'\n );\n}\n\n/** True for a value with the functions `get` and `subscribe` of the store contract. */\nexport function isContract(value: unknown): value is StoreLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { get?: unknown }).get === 'function' &&\n typeof (value as { subscribe?: unknown }).subscribe === 'function'\n );\n}\n\n/** True for a value of the store contract that is not a store of brumate. */\nexport function isForeignStore(value: unknown): boolean {\n return isContract(value) && !isStore(value) && !(HAS_BRIDGES && isBridged(value));\n}\n\n/** True when `$store` can write the store: it has `set`, and is not the store of a memo. */\nexport function canSet(value: StoreLike<unknown>): boolean {\n return typeof value.set === 'function' && !(value as Store<unknown>).r;\n}\n\n/** Makes a store, such as one that a module holds for the whole app. */\nexport function store<T>(value: T): Store<T> {\n return new Store(value);\n}\n\n/** Writes the value of a store and calls its listeners, in one pass of the page. */\nexport function sendStore<T>(target: Store<T>, value: T, force?: boolean): void {\n // The listeners hear of a change only. A provider's update forces it, since a `set` of\n // `$toStore(signal)` wrote the value before the signal's update came.\n if (!force && Object.is(target.v, value)) {\n return;\n }\n target.v = value;\n const listeners = () => {\n for (const listener of target.l) {\n listener(value);\n }\n };\n const pass = (globalThis as { [key: symbol]: (<R>(run: () => R) => R) | undefined })[PASS];\n if (pass) {\n pass(listeners);\n } else {\n listeners();\n }\n}\n\n// Derived stores: a read-only store that computes its value from other stores, with the API of\n// Svelte 4's `derived`.\n\n/** The stores that `derived` reads: one store, or an array of them. */\nexport type Stores = StoreLike<any> | [StoreLike<any>, ...StoreLike<any>[]] | StoreLike<any>[];\n\n/** The values of `Stores`: a value for one store, an array of values for an array. */\nexport type StoresValues<S> =\n S extends StoreLike<infer U>\n ? U\n : { [K in keyof S]: S[K] extends StoreLike<infer U> ? U : never };\n\n/** The derived stores that heard of a change and wait to compute. */\nconst waiting: Computed[] = [];\n/** The listener sets that have a trailing listener, which computes the waiting stores. */\nconst armed = new Set<Set<unknown>>();\n/** True while the waiting stores compute. */\nlet flushing = false;\n\n/** Computes the waiting derived stores, the ones that read the fewest derived stores first. */\nfunction flushComputed(): void {\n flushing = true;\n try {\n while (waiting.length > 0) {\n let next = 0;\n for (let i = 1; i < waiting.length; i++) {\n if (waiting[i]!.level < waiting[next]!.level) {\n next = i;\n }\n }\n const [computed] = waiting.splice(next, 1);\n computed!.waits = false;\n computed!.run();\n }\n } catch (error) {\n // The stores that still wait would never hear a source again, so they leave the queue.\n for (const computed of waiting) {\n computed.waits = false;\n }\n waiting.length = 0;\n throw error;\n } finally {\n flushing = false;\n }\n}\n\n/** The state of a derived store while it has subscribers. */\ninterface Computed {\n /** The number of derived stores below it, so a store computes after the ones it reads. */\n level: number;\n /** True while it waits in the queue. */\n waits: boolean;\n run(): void;\n}\n\n/**\n * A store computed from `sources`. With a function of one parameter, the result is the value. With\n * two or three, the function calls `set` or `update`, and a function it returns runs before the\n * next call and when the last subscriber leaves. It follows its sources only while it has\n * subscribers; `get` computes from the sources otherwise. A source change that reaches it in one\n * pass computes it once, after the stores it reads.\n */\nexport function derived<S extends Stores, T>(\n sources: S,\n fn: (\n values: StoresValues<S>,\n set: (value: T) => void,\n update: (change: (value: T) => T) => void,\n ) => (() => void) | void,\n initial?: T,\n): StoreLike<T>;\nexport function derived<S extends Stores, T>(\n sources: S,\n fn: (values: StoresValues<S>) => T,\n initial?: T,\n): StoreLike<T>;\nexport function derived<T>(\n sources: Stores,\n fn: (\n values: unknown,\n set: (value: T) => void,\n update: (change: (value: T) => T) => void,\n ) => unknown,\n initial?: T,\n): StoreLike<T> {\n const single = !Array.isArray(sources);\n const list: StoreLike<unknown>[] = single ? [sources] : sources;\n for (const source of list) {\n if (!source) {\n throw new Error('derived() expects stores as input, got a falsy value');\n }\n }\n const auto = fn.length < 2;\n const out = new Store<T>(initial as T);\n const subscribers = new Set<() => void>();\n let level = 1;\n for (const source of list) {\n level = Math.max(level, ((source as { d?: number }).d ?? 0) + 1);\n }\n\n // The state of one run: `cleanup` is what `fn` returned, and `write` is where `set` goes.\n let cleanup: (() => void) | undefined;\n let started = false;\n let starting = false;\n let stops: (() => void)[] = [];\n\n /** Runs `fn` over the current values of the sources. */\n const compute = (write: (value: T) => void): void => {\n const values: unknown[] = [];\n for (const source of list) {\n values.push(source.get());\n }\n const set = write;\n const update = (change: (value: T) => T): void => write(change(out.v));\n cleanup?.();\n cleanup = undefined;\n const result = fn(single ? values[0] : values, set, update);\n if (auto) {\n write(result as T);\n } else if (typeof result === 'function') {\n cleanup = result as () => void;\n }\n };\n\n // The value is written without a notice while the first subscriber starts it, since nobody\n // listens yet and `subscribe` does not call the listener.\n const send = (value: T): void => {\n if (starting) {\n out.v = value;\n } else if (started) {\n sendStore(out, value);\n } else {\n // A late `set` after the last subscriber left keeps its value, as Svelte's store does.\n out.v = value;\n }\n };\n\n const state: Computed = {\n level,\n waits: false,\n run() {\n if (started) {\n compute(send);\n }\n },\n };\n\n /**\n * Called by a source. The store waits until the source has called all its listeners, so a store\n * that reads this one and the source computes once, after this one.\n */\n const heard = (source: StoreLike<unknown>): void => {\n if (!started || state.waits) {\n return;\n }\n state.waits = true;\n waiting.push(state);\n if (flushing) {\n return;\n }\n const listeners = (source as Partial<Store<unknown>>).l;\n if (!listeners || armed.has(listeners)) {\n if (!listeners) {\n // A store of another library has no listeners to wait behind.\n flushComputed();\n }\n return;\n }\n // A listener added now runs after the ones of the source, in the same send.\n const trail = (): void => {\n listeners.delete(trail);\n armed.delete(listeners);\n flushComputed();\n };\n armed.add(listeners);\n listeners.add(trail as never);\n };\n\n const start = (): void => {\n starting = true;\n started = true;\n try {\n compute(send);\n for (const source of list) {\n stops.push(source.subscribe(() => heard(source)));\n }\n } catch (error) {\n // A store that failed to start has no subscriptions, so it can start again.\n started = false;\n for (const end of stops) {\n end();\n }\n stops = [];\n cleanup?.();\n cleanup = undefined;\n throw error;\n } finally {\n starting = false;\n }\n };\n\n const stop = (): void => {\n started = false;\n for (const end of stops) {\n end();\n }\n stops = [];\n cleanup?.();\n cleanup = undefined;\n if (state.waits) {\n state.waits = false;\n waiting.splice(waiting.indexOf(state), 1);\n }\n };\n\n return Object.assign(\n {\n get(): T {\n if (started) {\n return out.v;\n }\n // No subscriber: compute once from the sources and stop. The async form keeps the\n // initial value until `set` runs.\n let value = out.v;\n started = true;\n try {\n compute((next) => {\n value = next;\n });\n } finally {\n started = false;\n cleanup?.();\n cleanup = undefined;\n }\n return value;\n },\n subscribe(listener: (value: T) => void): () => void {\n const stopListening = out.subscribe(listener);\n if (!started) {\n try {\n start();\n } catch (error) {\n stopListening();\n throw error;\n }\n }\n subscribers.add(stopListening);\n return () => {\n if (subscribers.delete(stopListening)) {\n stopListening();\n if (subscribers.size === 0) {\n stop();\n }\n }\n };\n },\n },\n { d: level },\n );\n}\n\n// Bridges: a store of another library that can cross the page state. `bridge()` names how to make\n// the library's store, read it and listen to it, and the page state sends the data that `get`\n// reads, with the name of the bridge. The browser makes the library's store again, once, from\n// that data.\n\n/** What `bridge` takes. */\nexport interface BridgeOptions<S, T> {\n /**\n * Makes the library's store. On the server it runs once for each call of the bridge. In the\n * browser it runs once, when the store gets its first subscriber, with the data that the server\n * sent. It must be in a module that the browser can load.\n */\n create: (snapshot: T | undefined) => S;\n /** The data of the store: plain data that the page state can send. */\n get: (source: S) => T;\n /** Calls `listener` when the store changes. Returns the function that stops it. */\n subscribe: (source: S, listener: () => void) => () => void;\n /** Writes the store. The browser never calls it when the page resumes. */\n set?: (source: S, value: T) => void;\n}\n\n/** A store of `bridge()`: the contract of a store, and the store of the library. */\nexport interface BridgedStore<S, T> extends StoreLike<T> {\n /**\n * The store of the library. In the browser it is undefined until the store has a subscriber,\n * since the browser makes it at the first subscriber.\n */\n readonly source: S | undefined;\n}\n\n/** What `bridge` returns: makes a store, from the data of the server in the browser. */\nexport interface Bridge<S, T> {\n (snapshot?: T): BridgedStore<S, T>;\n /** The options. */\n b: BridgeOptions<S, T>;\n /** The name that the compiler gave, `bridge:<file>#<export>`. */\n i?: string;\n}\n\nconst BRIDGES = Symbol.for('brumate.bridges');\nconst BRIDGE_LOAD = Symbol.for('brumate.bridge-load');\n\ntype Global = { [BRIDGES]?: Map<string, Bridge<never, never>>; [BRIDGE_LOAD]?: Loader };\ntype Loader = [load: (module: string) => Promise<unknown>, report: (error: unknown) => void];\n\n/** The bridges by name, which any copy of the runtime shares. */\nfunction bridges(): Map<string, Bridge<never, never>> {\n return ((globalThis as Global)[BRIDGES] ??= new Map());\n}\n\n/**\n * Sets how the browser loads the module of a bridge, and where a failed load is reported. The\n * core calls it when it starts.\n */\nexport function setBridgeLoader(...loader: Loader): void {\n (globalThis as Global)[BRIDGE_LOAD] = loader;\n}\n\n/** The module of a bridge, from its name. */\nfunction bridgeModule(id: string): string {\n return id.slice(0, id.lastIndexOf('#'));\n}\n\n/**\n * Makes a bridge. Keep its value in a module-level export, so the page state can name it:\n * `export const bears = bridge({ … })`. The compiler gives it its name.\n */\nexport function bridge<S, T>(options: BridgeOptions<S, T>): Bridge<S, T> {\n const made = Object.assign(\n (snapshot?: T): BridgedStore<S, T> => new Bridged(made, options.create(snapshot)),\n { b: options },\n ) as Bridge<S, T>;\n return made;\n}\n\n/** Gives a bridge its name, which the compiler writes at the end of its module. */\nexport function nameBridge(made: Bridge<never, never>, id: string): void {\n made.i = id;\n bridges().set(id, made);\n}\n\n/** True for a store of `bridge()`, of any copy of the runtime. */\nexport function isBridged(value: unknown): value is Bridged<unknown, unknown> {\n return (\n typeof value === 'object' && value !== null && (value as { k?: unknown }).k === 'brumate.bridge'\n );\n}\n\n/**\n * Whether two values hold the same data: the same value, or arrays and plain objects whose items\n * hold the same data. A store that the browser makes again holds a new object with the content\n * the server sent, which needs no repair.\n */\nexport function sameData(a: unknown, b: unknown, open?: Map<object, Set<unknown>>): boolean {\n if (Object.is(a, b)) {\n return true;\n }\n const array = Array.isArray(a);\n if (array ? !Array.isArray(b) || a.length !== b.length : !isPlain(a) || !isPlain(b)) {\n return false;\n }\n const left = a as Record<string, unknown>;\n const right = b as Record<string, unknown>;\n // A pair already under compare is a cycle: it counts as the same, so each pair is compared once.\n open ??= new Map();\n let pairs = open.get(left);\n if (pairs?.has(right)) {\n return true;\n }\n if (!pairs) {\n pairs = new Set();\n open.set(left, pairs);\n }\n pairs.add(right);\n const keys = Object.keys(left);\n if (!array && keys.length !== Object.keys(right).length) {\n return false;\n }\n for (const key of keys) {\n if (!(key in right) || !sameData(left[key], right[key], open)) {\n return false;\n }\n }\n return true;\n}\n\n/** Whether a value is an object of `Object` or of no prototype, as page state holds. */\nfunction isPlain(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * The store that a bridge makes. On the server it holds the library's store from the start. In\n * the browser the page state makes it with the name of the bridge and the data of the server, and\n * it makes the library's store at its first subscriber.\n */\nexport class Bridged<S, T> implements BridgedStore<S, T> {\n /** The mark of a bridged store, which `isBridged` reads in every copy of the runtime. */\n k = 'brumate.bridge' as const;\n /** The bridge. Undefined for a store of the page state until the module of the bridge loads. */\n f?: Bridge<S, T>;\n /** The name of the bridge, for a store of the page state. */\n i?: string;\n /** The library's store. */\n s?: S;\n /** True once the library's store exists. */\n m = false;\n /** The data that the server sent, until the library's store exists. */\n v?: T;\n /** Whether the bridge has `set`, as the server sent it, until the module loads. */\n w?: boolean;\n\n constructor(\n made: Bridge<S, T> | undefined,\n source: S | undefined,\n id?: string,\n snapshot?: T,\n writable?: boolean,\n ) {\n this.f = made;\n this.i = id;\n this.v = snapshot;\n this.w = writable;\n if (made) {\n this.s = source;\n this.m = true;\n }\n }\n\n /**\n * The library's store. In the browser it is undefined until the store has a subscriber and the\n * module of the bridge has loaded.\n */\n get source(): S | undefined {\n return this.s;\n }\n\n /** The name of the bridge. */\n get id(): string | undefined {\n return this.f?.i ?? this.i;\n }\n\n /** The data of the store: what `get` reads, or what the server sent before the first subscriber. */\n get(): T {\n return this.m ? this.f!.b.get(this.s as S) : (this.v as T);\n }\n\n /**\n * Calls `listener` with the data when it changes. The first subscriber makes the library's\n * store in the browser. When the module of the bridge has not loaded, the subscription starts\n * when it has.\n */\n subscribe(listener: (value: T) => void, ...seen: [value?: T]): () => void {\n let stopped = false;\n let stop: (() => void) | undefined;\n // What this subscriber has seen, which `seen` can name: a source that starts later compares\n // with it.\n let last = seen.length > 0 ? (seen[0] as T) : this.get();\n const start = (): void => {\n if (stopped) {\n return;\n }\n const options = this.f!.b;\n const source = this.make();\n stop = options.subscribe(source, () => {\n const next = options.get(source);\n if (!sameData(next, last)) {\n last = next;\n listener(next);\n }\n });\n // A source that starts from other data than this subscriber saw, such as one that keeps its\n // own state, is written once.\n const first = options.get(source);\n if (!sameData(first, last)) {\n last = first;\n listener(first);\n }\n };\n if (this.find()) {\n start();\n } else {\n void this.load().then((loaded) => loaded && start());\n }\n return () => {\n stopped = true;\n stop?.();\n };\n }\n\n /** Writes the library's store, when the bridge has `set`. */\n get set(): ((value: T) => void) | undefined {\n // Before the module loads, the server's word is all there is, so `let` checks the same.\n const writable = this.find() ? !!this.f!.b.set : this.w !== false;\n return writable ? (value) => this.write(value) : undefined;\n }\n\n /** Writes the library's store, after the module of the bridge has loaded. */\n private write(value: T): void {\n if (this.find()) {\n this.f!.b.set!(this.make(), value);\n } else {\n void this.load().then((loaded) => loaded && this.write(value));\n }\n }\n\n /** The bridge, once its module has loaded. */\n private find(): Bridge<S, T> | undefined {\n if (!this.f && this.i !== undefined) {\n this.f = bridges().get(this.i) as Bridge<S, T> | undefined;\n }\n return this.f;\n }\n\n /** Loads the module of the bridge. A failure goes to the core's error path; it gives false. */\n private load(): Promise<boolean> {\n const [load, report] = (globalThis as Global)[BRIDGE_LOAD] ?? [];\n return Promise.resolve(load?.(bridgeModule(this.i!))).then(\n () => {\n if (this.find()) {\n return true;\n }\n this.fail(\n report,\n new Error(\n `The bridge \"${this.i}\" is not in its module. Keep bridge() in a module-level export, as \"export const name = bridge({ … })\"`,\n ),\n );\n return false;\n },\n (error: unknown) => {\n this.fail(report, error);\n return false;\n },\n );\n }\n\n private fail(report: ((error: unknown) => void) | undefined, error: unknown): void {\n if (report) {\n report(error);\n } else {\n console.error(error);\n }\n }\n\n /** Makes the library's store once, with the data of the server. */\n private make(): S {\n if (!this.m) {\n this.s = this.f!.b.create(this.v);\n this.m = true;\n }\n return this.s as S;\n }\n}\n"],"mappings":";;;AAQA,MAAM,OAAO,OAAO,IAAI,cAAc;;AAGtC,SAAgB,UAAU,OAA2C;CACnE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA4B,QAAQ,YAC5C,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAC9B,CAAC,WAAW,KAAK;AAErB;;;;;;AAOA,SAAgB,WACd,OACA,MACA,OACA,KACoB;CACpB,MAAM,QAAQ,SAAS,KAAA,IAAY,QAAS,QAAgD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KAAK,IAAI,CAAC,CAAC,KAAK,EAAG,EAAE,MAAM,KAAK,MAAM,UACzC,UAAU,KAAK,MAAM,KAAK,IAAI,KAAA;CACnD;;CAGA,MAAc,OAAgB;EAC5B,IAAI,KAAK,KAAK,GACZ,KAAK,EAAG,EAAE,IAAK,KAAK,KAAK,GAAG,KAAK;OAEjC,KAAU,KAAK,CAAC,CAAC,MAAM,WAAW,UAAU,KAAK,MAAM,KAAK,CAAC;CAEjE;;CAGA,OAAyC;EACvC,IAAI,CAAC,KAAK,KAAK,KAAK,MAAM,KAAA,GACxB,KAAK,IAAI,QAAQ,CAAC,CAAC,IAAI,KAAK,CAAC;EAE/B,OAAO,KAAK;CACd;;CAGA,OAAiC;EAC/B,MAAM,CAAC,MAAM,UAAW,WAAsB,gBAAgB,CAAC;EAC/D,OAAO,QAAQ,QAAQ,OAAO,aAAa,KAAK,CAAE,CAAC,CAAC,CAAC,CAAC,WAC9C;GACJ,IAAI,KAAK,KAAK,GACZ,OAAO;GAET,KAAK,KACH,wBACA,IAAI,MACF,eAAe,KAAK,EAAE,uGACxB,CACF;GACA,OAAO;EACT,IACC,UAAmB;GAClB,KAAK,KAAK,QAAQ,KAAK;GACvB,OAAO;EACT,CACF;CACF;CAEA,KAAa,QAAgD,OAAsB;EACjF,IAAI,QACF,OAAO,KAAK;OAEZ,QAAQ,MAAM,KAAK;CAEvB;;CAGA,OAAkB;EAChB,IAAI,CAAC,KAAK,GAAG;GACX,KAAK,IAAI,KAAK,EAAG,EAAE,OAAO,KAAK,CAAC;GAChC,KAAK,IAAI;EACX;EACA,OAAO,KAAK;CACd;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trusted-g_zUJbh2.js","names":[],"sources":["../src/runtime/trusted.ts"],"sourcesContent":["// Trusted Types. A site whose Content Security Policy has\n// `require-trusted-types-for 'script'` refuses a string in `innerHTML` and\n// in the text of a script. The core passes the markup that it inserts, and\n// the scripts that it copies to run them, through a policy named `brumate`:\n// the markup of renders, deferred blocks, client navigation and the devtools.\n// The markup is what brumate's own render code made, with every value\n// escaped, and the scripts come from the server with the page, so the\n// policy passes them as they are.\n\n/** The name of the policy, for `trusted-types brumate` in the policy of the site. */\nexport const POLICY = 'brumate';\n\ninterface Policy {\n createHTML(html: string): string;\n createScript(code: string): string;\n}\n\n/**\n * The key of the policy on the browser's `trustedTypes`. A second copy of the core on the page, or\n * the core after a hot update, reuses it, since the browser refuses a second policy of the same\n * name unless the policy of the site says `'allow-duplicates'`.\n */\nconst KEY = Symbol.for('brumate.trusted-types');\n\ninterface Factory {\n createPolicy(name: string, rules: Policy): Policy;\n [KEY]?: Policy;\n}\n\n/** The policy, made on the first insert. Null where the browser has no Trusted Types. */\nlet policy: Policy | null | undefined;\n\nfunction ensure(): Policy | null {\n if (policy !== undefined) {\n return policy;\n }\n const factory = (globalThis as { trustedTypes?: Factory }).trustedTypes;\n policy = factory?.[KEY] ?? null;\n if (factory && !policy) {\n try {\n policy = factory.createPolicy(POLICY, {\n createHTML: (html) => html,\n createScript: (code) => code,\n });\n factory[KEY] = policy;\n } catch (error) {\n // The policy of the site names other policies, so the inserts below fail too.\n console.error(\n `brumate: the Content Security Policy does not allow the Trusted Types policy \"${POLICY}\". Add \"trusted-types ${POLICY}\" to it`,\n error,\n );\n }\n }\n return policy;\n}\n\n/** Markup that the core made, as the browser accepts it in `innerHTML`. */\nexport function trustedHTML(html: string): string {\n return ensure()?.createHTML(html) ?? html;\n}\n\n/** The code of a script that came with the page, as the browser accepts it in a script's text. */\nexport function trustedScript(code: string): string {\n return ensure()?.createScript(code) ?? code;\n}\n"],"mappings":";;AAUA,MAAa,SAAS;;;;;;AAYtB,MAAM,MAAM,OAAO,IAAI,uBAAuB;;AAQ9C,IAAI;AAEJ,SAAS,SAAwB;CAC/B,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,UAAW,WAA0C;CAC3D,SAAS,UAAU,QAAQ;CAC3B,IAAI,WAAW,CAAC,QACd,IAAI;EACF,SAAS,QAAQ,aAAa,QAAQ;GACpC,aAAa,SAAS;GACtB,eAAe,SAAS;EAC1B,CAAC;EACD,QAAQ,OAAO;CACjB,SAAS,OAAO;EAEd,QAAQ,MACN,iFAAiF,OAAO,wBAAwB,OAAO,UACvH,KACF;CACF;CAEF,OAAO;AACT;;AAGA,SAAgB,YAAY,MAAsB;CAChD,OAAO,OAAO,CAAC,EAAE,WAAW,IAAI,KAAK;AACvC;;AAGA,SAAgB,cAAc,MAAsB;CAClD,OAAO,OAAO,CAAC,EAAE,aAAa,IAAI,KAAK;AACzC"}
|