brumate 0.0.1 → 0.1.1
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/README.md +43 -72
- package/dist/boot-DN1ZU8Hg.d.ts +37 -0
- package/dist/cli.js +2 -2
- package/dist/{client-DuDTDePF.d.ts → client-DwJInP_a.d.ts} +133 -44
- package/dist/client-routes-DakuM32C.js +94 -0
- package/dist/client-routes-DakuM32C.js.map +1 -0
- package/dist/{cookies-rgIAc8IE.js → cookies-Av5WFmcf.js} +18 -8
- package/dist/cookies-Av5WFmcf.js.map +1 -0
- package/dist/{devtools-Bm8cS7hX.js → devtools-BKjnHrnv.js} +10 -5
- package/dist/devtools-BKjnHrnv.js.map +1 -0
- package/dist/{devtools-panel-CTbDSBBA.js → devtools-panel-AWOn0VK2.js} +23 -26
- package/dist/devtools-panel-AWOn0VK2.js.map +1 -0
- package/dist/{files-D_JUcSU5.js → files-DdT84mPy.js} +22 -3
- package/dist/{files-D_JUcSU5.js.map → files-DdT84mPy.js.map} +1 -1
- package/dist/{html-CxWpXngy.js → html-DEeoepg3.js} +47 -10
- package/dist/html-DEeoepg3.js.map +1 -0
- package/dist/{html-DV-Tezgq.d.ts → html-Du8jY2Cc.d.ts} +14 -2
- package/dist/index.d.ts +65 -6
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/{inspect-CGCWfaEx.js → inspect-BPchdWbU.js} +887 -172
- package/dist/inspect-BPchdWbU.js.map +1 -0
- package/dist/loader-Dc9OwY5I.js +101 -0
- package/dist/loader-Dc9OwY5I.js.map +1 -0
- package/dist/{navigate-C5dP89YL.js → navigate-CzLjnoPH.js} +112 -59
- package/dist/navigate-CzLjnoPH.js.map +1 -0
- package/dist/{produce-BjQGMpqL.d.ts → produce-CtZ32UGG.d.ts} +13 -3
- package/dist/{rpc-B86KKjzx.js → rpc-9fSqL_YK.js} +57 -12
- package/dist/rpc-9fSqL_YK.js.map +1 -0
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +599 -306
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/devtools.d.ts +3 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +9 -5
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +12 -2
- package/dist/runtime/loader.js +3 -1
- package/dist/runtime/server.d.ts +4 -4
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +5 -5
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +3 -0
- package/dist/runtime/static-loader.js +1 -0
- package/dist/runtime/testing.d.ts +21 -2
- package/dist/runtime/testing.js +83 -7
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{server-sQCvduOz.d.ts → server-BxqjLUnV.d.ts} +211 -20
- package/dist/{server-CX3JnPCs.js → server-DZsgnPKS.js} +595 -185
- package/dist/server-DZsgnPKS.js.map +1 -0
- package/dist/shared-CWYOd0H3.js +40 -0
- package/dist/shared-CWYOd0H3.js.map +1 -0
- package/dist/static-loader-BcFh4ebX.d.ts +11 -0
- package/dist/static-loader-ClNkHZGn.js +185 -0
- package/dist/static-loader-ClNkHZGn.js.map +1 -0
- package/dist/stream-bgNCMcaA.js +280 -0
- package/dist/stream-bgNCMcaA.js.map +1 -0
- package/dist/vite.d.ts +30 -5
- package/dist/vite.js +501 -62
- package/dist/vite.js.map +1 -1
- package/package.json +7 -2
- package/types.d.ts +5 -0
- package/dist/cookies-rgIAc8IE.js.map +0 -1
- package/dist/devtools-Bm8cS7hX.js.map +0 -1
- package/dist/devtools-panel-CTbDSBBA.js.map +0 -1
- package/dist/html-CxWpXngy.js.map +0 -1
- package/dist/inspect-CGCWfaEx.js.map +0 -1
- package/dist/loader-BUhNqDHw.d.ts +0 -30
- package/dist/loader-py4qu6tQ.js +0 -215
- package/dist/loader-py4qu6tQ.js.map +0 -1
- package/dist/navigate-C5dP89YL.js.map +0 -1
- package/dist/rpc-B86KKjzx.js.map +0 -1
- package/dist/server-CX3JnPCs.js.map +0 -1
- package/dist/shared-BE_oBSDM.js +0 -176
- package/dist/shared-BE_oBSDM.js.map +0 -1
- package/dist/stream-cvhqOzfs.js +0 -145
- package/dist/stream-cvhqOzfs.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["id","spreadText"],"sources":["../../src/runtime/client.ts"],"sourcesContent":["import { fromCrossJSON } from 'seroval';\nimport {\n VOID_ELEMENTS,\n actionAttributes,\n attributeText,\n insertValue,\n isRaw,\n rawHTML,\n spread as spreadText,\n} from './html.ts';\nimport type { Raw } from './html.ts';\nimport {\n ElementReference,\n FunctionReference,\n disabledFeatures,\n isAsyncIterable,\n plugins,\n} from './shared.ts';\nimport type { PageState, ScopeState } from './shared.ts';\nimport type { Context as ContextValue } from './context.ts';\n\nexport { affix, attribute, escape, raw, spread, vars } from './html.ts';\nexport type { Raw } from './html.ts';\nexport { produce } from './produce.ts';\nexport { createContext } from './context.ts';\n\ntype Update = [kind: number, name: string];\n\n/** The entry of a compiled client module. */\nexport interface ClientModule {\n id: string;\n /** Prop names to slot indices. `*` is the slot of a props object. */\n props: Record<string, number>;\n /** Scope kind, then slot, to the updates that read it. */\n g: Record<number, Record<number, Update[]>>;\n /** Imports a part of the module. */\n load: (part: string) => Promise<Part>;\n /** Server function ID to the memos that call it, as scope kind and update, for `refresh`. */\n refresh?: Record<string, Update[]>;\n}\n\n/** A part of a client module: one client root, or the updates. */\nexport type Part = Record<string, unknown>;\n\n/** The part that holds an export: `h<n>` and `c<n>` have their own, the rest are in `update`. */\nfunction partOf(name: string): string {\n return /^[hc]\\d/.test(name) ? name : 'update';\n}\n\n/** The instance of a scope in the page. */\nexport interface Scope {\n id: number;\n /** The scope's ID in the compiled component. */\n k: number;\n p?: Scope;\n /** The component ID, for a component's root scope. */\n m?: string;\n s: unknown[];\n /** The item of a list item scope. */\n i?: unknown;\n c?: Record<number, number>;\n /** The scope that rendered a component's root scope. */\n o?: Scope;\n /** The values that the scope provides, by context key. */\n v?: Record<string, unknown>;\n /** The slots that hold the contexts that the scope reads, by context key. */\n x?: Record<string, number>;\n children: Set<Scope>;\n cleanups?: Map<string, () => void>;\n keys?: Map<number, unknown>;\n}\n\nexport interface CoreOptions {\n load: (id: string) => Promise<ClientModule>;\n /** Adds event listeners for the `data-on` attributes in new markup. */\n listen: (root: ParentNode) => void;\n /** The URL prefix of server function calls. Defaults to `/_brumate`. */\n rpc?: string;\n}\n\nlet options: CoreOptions;\nconst scopes = new Map<number, Scope>();\n\n/** What the devtools overlay hears from the core. It is set only in development. */\nexport interface DevtoolsHooks {\n /** The core started, with the scopes of the page, and a way to write a slot, as a handler does. */\n attach?(core: {\n scopes: Map<number, Scope>;\n set: (scope: Scope, slot: number, value: unknown) => void;\n }): void;\n /** A handler starts for an event. */\n handler?(ref: string, element: Element, event?: Event): void;\n /** A part of a component's client code loaded. */\n part?(component: string, name: string): void;\n /** A slot got a new value. */\n write?(scope: Scope, slot: number, value: unknown): void;\n}\n\n/** The global key of the devtools hooks. */\nexport const DEVTOOLS: unique symbol = Symbol.for('brumate.devtools');\n\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[DEVTOOLS];\n}\nconst modules = new Map<string, ClientModule>();\nconst loading = new Map<string, Promise<ClientModule>>();\nconst parts = new Map<string, Promise<Part>>();\nconst loadedParts = new Map<string, Part>();\nconst comments = new Map<string, Comment>();\nconst elements = new Map<string, Element>();\n// Scopes that the client creates get negative IDs, so they never match IDs\n// from state records that the server streams later.\nlet nextId = -1;\n\n// Records of one render share references through a map, so a later record can settle a promise\n// of an earlier one. Each render on the page has its own map, by its `data-root`.\nconst refs = new Map<string, Map<number, unknown>>();\nconst read = new WeakSet<Element>();\n\n/**\n * Reads a state record. The first record holds the page state, and later\n * records settle the promises in it.\n */\nfunction readRecord(script: Element): void {\n if (read.has(script)) {\n return;\n }\n read.add(script);\n const root = script.getAttribute('data-root') ?? '0';\n if (!refs.has(root)) {\n refs.set(root, new Map());\n }\n const decoded = fromCrossJSON<PageState>(JSON.parse(script.textContent!), {\n plugins,\n disabledFeatures,\n refs: refs.get(root)!,\n });\n // A page that started its IDs at another number, such as a prerendered file, moves them here.\n // Only records with scopes hold IDs. Later records settle promises, which `shiftState` wraps.\n const offset = Number(script.getAttribute('data-offset') ?? 0);\n const value =\n offset && script.hasAttribute('data-scopes') ? shiftState(decoded, offset) : decoded;\n // Records with scopes: the page state, and the state of each `#loading` body.\n if (script.hasAttribute('data-scopes')) {\n // A page that replaced only some routes of the one before it: see `navigate`.\n const drop = script.getAttribute('data-drop');\n if (drop) {\n dropScopes(new Set(drop.split(',').map(Number)));\n }\n const added = addScopes(value, routeOptions(script));\n if (writes > 0) {\n refresh(added);\n }\n }\n}\n\n/**\n * Updates scopes that the server rendered before values changed on the\n * client, such as the body of a `#loading` block that streams in after an\n * event. Effects do not run: they run only when a value changes.\n */\nfunction refresh(added: Scope[]): void {\n for (const scope of added) {\n const id = rootOf(scope).m;\n if (!id) {\n continue;\n }\n void loadModule(id).then(async (module) => {\n const names = new Set<string>();\n for (const slots of Object.values(module.g)) {\n for (const entries of Object.values(slots)) {\n for (const [kind, name] of entries) {\n if (kind === scope.k && name[0] !== 'e') {\n names.add(name);\n }\n }\n }\n }\n if (names.size === 0) {\n return;\n }\n const updates = await loadPart(module, 'update');\n // Memos first, so the other updates read their new values.\n for (const name of [...names].toSorted(\n (a, b) => Number(b[0] === 'm') - Number(a[0] === 'm'),\n )) {\n if (scopes.has(scope.id)) {\n (updates[name] as (scope: Scope) => void)(scope);\n }\n }\n });\n }\n}\n\n/** Adds a number to the scope IDs of a state record. */\nfunction shiftState(state: PageState, by: number): PageState {\n const seen = new Set<object>();\n // References to elements and client functions name the scope of their markup.\n const shiftValue = (value: unknown): unknown => {\n if (value instanceof ElementReference) {\n return new ElementReference(value.scope + by, value.anchor);\n }\n if (value instanceof FunctionReference) {\n return new FunctionReference(value.ref, value.scope + by);\n }\n // A later record settles it, with a value whose IDs move too.\n if (value instanceof Promise) {\n return value.then(shiftValue);\n }\n if (typeof value === 'object' && value !== null && !seen.has(value)) {\n seen.add(value);\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n value[index] = shiftValue(item);\n });\n } else if (Object.getPrototypeOf(value) === Object.prototype) {\n for (const [key, item] of Object.entries(value)) {\n (value as Record<string, unknown>)[key] = shiftValue(item);\n }\n }\n }\n return value;\n };\n const result: PageState = {};\n for (const [key, record] of Object.entries(state)) {\n result[Number(key) + by] = {\n ...record,\n p: record.p === undefined ? undefined : record.p + by,\n o: record.o === undefined ? undefined : record.o + by,\n c:\n record.c &&\n Object.fromEntries(Object.entries(record.c).map(([anchor, id]) => [anchor, id + by])),\n s: record.s?.map(shiftValue),\n };\n }\n return result;\n}\n\ninterface RouteOptions {\n /** Scopes of the new page that stand for scopes of the kept layouts. */\n alias: Map<number, number>;\n /** The scopes of the routes that replaced old ones. Only they and the scopes inside them are added. */\n roots: Set<number>;\n}\n\nfunction routeOptions(script: Element): RouteOptions | undefined {\n const roots = script.getAttribute('data-roots');\n if (roots === null) {\n return undefined;\n }\n const alias = new Map<number, number>();\n for (const pair of (script.getAttribute('data-alias') ?? '').split(',').filter(Boolean)) {\n const [from, to] = pair.split(':').map(Number) as [number, number];\n alias.set(from, to);\n }\n return { alias, roots: new Set(roots.split(',').filter(Boolean).map(Number)) };\n}\n\n/** Removes scopes and the scopes inside them, and runs their cleanups. */\nfunction dropScopes(roots: Set<number>): void {\n const inside = (scope: Scope): boolean => {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (roots.has(current.id)) {\n return true;\n }\n }\n return false;\n };\n // Deleting from a map while iterating it is safe.\n for (const scope of scopes.values()) {\n if (inside(scope)) {\n for (const cleanup of scope.cleanups?.values() ?? []) {\n cleanup();\n }\n scope.p?.children.delete(scope);\n scopes.delete(scope.id);\n }\n }\n}\n\nfunction addScopes(state: PageState, route?: RouteOptions): Scope[] {\n const added: Scope[] = [];\n const kept = (id: number): boolean => {\n for (let current: number | undefined = id; current !== undefined;) {\n if (route!.roots.has(current)) {\n return true;\n }\n const record: ScopeState | undefined = state[current];\n current = record?.p ?? record?.o;\n }\n return false;\n };\n for (const [key, record] of Object.entries(state)) {\n const id = Number(key);\n // The new page renders the kept layouts again. Their scopes are not added.\n if (route && !kept(id)) {\n continue;\n }\n const scope: Scope = {\n id,\n k: record.k ?? 0,\n m: record.m,\n s: record.s ?? [],\n i: record.i,\n c: record.c,\n v: record.v,\n x: record.x,\n children: new Set(),\n };\n scopes.set(id, scope);\n added.push(scope);\n }\n const resolveId = (id: number): number => route?.alias.get(id) ?? id;\n for (const scope of added) {\n const record = state[scope.id]!;\n if (record.p !== undefined) {\n scope.p = scopes.get(resolveId(record.p));\n scope.p?.children.add(scope);\n }\n if (record.o !== undefined) {\n scope.o = scopes.get(resolveId(record.o));\n }\n }\n const seen = new Set<object>();\n for (const scope of added) {\n // A provided value can hold functions, which a component that reads the context calls.\n for (const key of Object.keys(scope.v ?? {})) {\n scope.v![key] = callable(scope.v![key], seen);\n }\n for (let i = 0; i < scope.s.length; i++) {\n const value = callable(scope.s[i], seen);\n scope.s[i] = value;\n // A value that a later state record settles replaces its promise.\n if (value instanceof Promise) {\n void value.then((result) => {\n settled.set(value, result);\n if (scope.s[i] === value) {\n set(scope, i, result);\n }\n });\n }\n }\n }\n if (remounts.size > 0) {\n restoreRemounts(added);\n }\n return added;\n}\n\nconst STATE = 'script[type=\"brumate/state\"]';\nlet observer: MutationObserver | undefined;\n\n/** Stops reading state records that arrive later. */\nexport function dispose(): void {\n observer?.disconnect();\n observer = undefined;\n document.removeEventListener('brumate:refresh', onRefresh);\n document.removeEventListener('brumate:hot', onHot);\n document.removeEventListener('brumate:remount', onRemount);\n}\n\n/**\n * Forgets the code of components that changed on the dev server, so the next\n * event or update loads the new code. Their state stays. See `brumate/hot`.\n */\nfunction onHot(event: Event): void {\n for (const id of (event as CustomEvent<string[]>).detail) {\n modules.delete(id);\n loading.delete(id);\n // Deleting the entry that a loop is at is safe for a Map.\n for (const key of parts.keys()) {\n if (key.startsWith(`${id}:`)) {\n parts.delete(key);\n loadedParts.delete(key);\n }\n }\n }\n}\n\n/** The values of the signals of components whose markup changed, for when the page renders again. */\nconst remounts = new Map<\n string,\n { after: Record<number, string[]>; values: Record<string, unknown>[] }\n>();\n\n/**\n * Keeps the values of the signals of each instance of a component, by\n * name, before the page renders again with its new markup.\n */\nfunction onRemount(event: Event): void {\n const detail = (\n event as CustomEvent<\n {\n id: string;\n before: Record<number, string[]>;\n after: Record<number, string[]>;\n signals: string[];\n }[]\n >\n ).detail;\n for (const { id, before, after, signals } of detail) {\n const names = new Set(signals);\n const instances = [...scopes.values()].filter((scope) => scope.m === id);\n remounts.set(id, {\n after,\n // The signals of the script of the component. Signals of blocks, such as of a `#for`\n // body, start again.\n values: instances.map((root) => {\n const values: Record<string, unknown> = {};\n (before[root.k] ?? []).forEach((name, slot) => {\n if (names.has(name)) {\n values[name] = root.s[slot];\n }\n });\n return values;\n }),\n });\n }\n}\n\n/** Writes back the values of signals that `onRemount` kept, into the instances of the new page. */\nfunction restoreRemounts(added: Scope[]): void {\n for (const [id, { after, values }] of remounts) {\n const instances = added.filter((scope) => scope.m === id);\n if (instances.length === 0) {\n continue;\n }\n remounts.delete(id);\n instances.forEach((root, index) => {\n const saved = values[index];\n (after[root.k] ?? []).forEach((name, slot) => {\n if (saved && name in saved) {\n set(root, slot, saved[name]);\n }\n });\n });\n }\n}\n\nfunction onRefresh(event: Event): void {\n refreshMemos((event as CustomEvent<string[]>).detail);\n}\n\n/**\n * Loads again the memos that call these server functions, after a server\n * function named them with `refresh`. Each component on the page knows its\n * own memos, from its client module.\n */\nfunction refreshMemos(ids: string[]): void {\n const roots = [...scopes.values()].filter((scope) => scope.m);\n for (const root of roots) {\n void loadModule(root.m!).then(async (module) => {\n const entries = ids.flatMap((id) => module.refresh?.[id] ?? []);\n if (entries.length === 0) {\n return;\n }\n const updates = await loadPart(module, 'update');\n for (const [kind, name] of entries) {\n for (const target of kind === root.k ? [root] : descendants(root, kind)) {\n if (scopes.has(target.id)) {\n (updates[name] as (scope: Scope) => void)(target);\n }\n }\n }\n });\n }\n}\n\n/**\n * Forgets the page, before another page replaces it. Cleanups run. Loaded\n * modules and parts stay, so the next page does not load them again.\n */\nexport function leavePage(): void {\n dispose();\n for (const scope of scopes.values()) {\n for (const cleanup of scope.cleanups?.values() ?? []) {\n cleanup();\n }\n }\n scopes.clear();\n comments.clear();\n elements.clear();\n pendingEffects.clear();\n loads.clear();\n loadingSlots.clear();\n nextId = -1;\n refs.clear();\n writes = 0;\n lastHandler = Promise.resolve();\n}\n\n/** Reads the page state. The loader calls it once, before the first handler. */\nexport function init(value: CoreOptions): void {\n options = value;\n for (const script of document.querySelectorAll(STATE)) {\n readRecord(script);\n }\n // Records that are still streaming settle their promises when they arrive.\n observer = new MutationObserver((records) => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType !== 1) {\n continue;\n }\n // A record can be inside the added node, such as in markup that a script inserts.\n const element = node as Element;\n if (element.matches(STATE)) {\n readRecord(element);\n } else {\n element.querySelectorAll(STATE).forEach(readRecord);\n }\n }\n }\n });\n observer.observe(document, { childList: true, subtree: true });\n document.addEventListener('brumate:refresh', onRefresh);\n document.addEventListener('brumate:hot', onHot);\n document.addEventListener('brumate:remount', onRemount);\n // The whole document, because `#head` content is in the head.\n indexMarkers(document.documentElement);\n devtools()?.attach?.({ scopes, set });\n}\n\n/** Replaces function references with functions that call them. */\nfunction callable(value: unknown, seen: Set<object>): unknown {\n if (value instanceof FunctionReference) {\n return (...args: unknown[]) => call(value.ref, scopes.get(value.scope), args);\n }\n if (typeof value === 'object' && value !== null && !seen.has(value)) {\n seen.add(value);\n const prototype = Object.getPrototypeOf(value);\n if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n record[key] = callable(record[key], seen);\n }\n }\n }\n return value;\n}\n\nexport function loadModule(id: string): Promise<ClientModule> {\n let promise = loading.get(id);\n if (!promise) {\n promise = options.load(id).then((module) => {\n modules.set(id, module);\n return module;\n });\n loading.set(id, promise);\n }\n return promise;\n}\n\nfunction loadPart(module: ClientModule, name: string): Promise<Part> {\n const key = `${module.id}:${name}`;\n let promise = parts.get(key);\n if (!promise) {\n promise = module.load(name).then((part) => {\n loadedParts.set(key, part);\n devtools()?.part?.(module.id, name);\n return part;\n });\n parts.set(key, promise);\n }\n return promise;\n}\n\ntype Handler = (scope: Scope | undefined, ...args: unknown[]) => unknown;\n\nasync function resolve(ref: string): Promise<Handler> {\n const [id, name] = ref.split('#') as [string, string];\n const module = await loadModule(id);\n const part = await loadPart(module, partOf(name));\n return part[name] as Handler;\n}\n\nasync function call(ref: string, scope: Scope | undefined, args: unknown[]): Promise<unknown> {\n return (await resolve(ref))(scope, ...args);\n}\n\n// The handler of the previous event, once it has started.\nlet lastHandler: Promise<unknown> = Promise.resolve();\n\n/**\n * Keeps `currentTarget` on an event. The handler runs after the event has\n * finished dispatching, when the browser has already cleared it.\n */\nfunction withTarget(event: Event, element: Element): Event {\n return new Proxy(event, {\n get(target, key) {\n if (key === 'currentTarget') {\n return element;\n }\n const value: unknown = Reflect.get(target, key);\n return typeof value === 'function' ? value.bind(target) : value;\n },\n });\n}\n\n/** Runs the handler `ref` for an element with a `data-b` anchor. */\nexport function handle(element: Element, ref: string, event?: Event): Promise<unknown> {\n const anchor = element.getAttribute('data-b');\n const scope = anchor ? scopes.get(Number(anchor.split(':')[0])) : undefined;\n const args = event ? [withTarget(event, element)] : [];\n devtools()?.handler?.(ref, element, event);\n // Parts load in parallel, but handlers start in the order of their events,\n // so an input handler runs before the submit handler of a later event.\n const loaded = resolve(ref);\n const started = lastHandler\n .then(() => loaded)\n .then((handler) => ({ value: handler(scope, ...args) }));\n lastHandler = started.catch(() => {});\n return started.then((result) => result.value);\n}\n\n/** Returns the instance of a scope by its ID. */\nexport function scopeOf(id: number): Scope | undefined {\n return scopes.get(id);\n}\n\n// Slots\n\n// oxlint-disable-next-line typescript/no-explicit-any -- Slots hold any value.\nexport function get(scope: Scope, slot: number): any {\n const value = scope.s[slot];\n // A value that the server still streams. A memo that reads it waits for it.\n if (computing > 0 && value instanceof Promise) {\n throw new NotReady(value);\n }\n if (value instanceof ElementReference) {\n const element = findElement(value.scope, value.anchor);\n if (element) {\n scope.s[slot] = element;\n }\n return element ?? undefined;\n }\n return value;\n}\n\n// The number of writes since the page loaded, so scopes that stream in later know to update.\nlet writes = 0;\n\nexport function set<T>(scope: Scope, slot: number, value: T): T {\n if (!Object.is(scope.s[slot], value)) {\n writes++;\n scope.s[slot] = value;\n devtools()?.write?.(scope, slot, value);\n trigger(scope, slot);\n }\n return value;\n}\n\n/**\n * The names of a call of a module function, for its shared code. Each ref\n * is a slot of `scope`, `[scope, slot]` for a slot of another scope, or\n * `[value]` for a value that does not change, such as a literal argument.\n */\nexport function cells(scope: Scope, links: unknown[], names: string[]): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n names.forEach((name, index) => {\n const ref = links[index];\n let owner = scope;\n let slot: number;\n if (typeof ref === 'number') {\n slot = ref;\n } else if ((ref as unknown[]).length === 2) {\n [owner, slot] = ref as [Scope, number];\n } else {\n Object.defineProperty(result, name, { get: () => (ref as unknown[])[0], set: () => {} });\n return;\n }\n Object.defineProperty(result, name, {\n get: () => get(owner, slot),\n set: (value: unknown) => set(owner, slot, value),\n });\n });\n return result;\n}\n\n// The latest load of each async memo, by `<scope>:<slot>`, so older results are dropped.\nconst loads = new Map<string, number>();\nconst loadingSlots = new Set<string>();\n\n/**\n * Writes the result of an async memo when it arrives. Until then the slot\n * keeps its value, and `pending` is true. Only the latest load is written.\n */\nexport function asyncMemo(scope: Scope, slot: number, promise: Promise<unknown>): void {\n const key = `${scope.id}:${slot}`;\n const load = (loads.get(key) ?? 0) + 1;\n loads.set(key, load);\n if (!loadingSlots.has(key)) {\n loadingSlots.add(key);\n // Readers of the memo update, so `$isPending` becomes true.\n trigger(scope, slot);\n }\n const settle = (value?: unknown, failed = false): void => {\n if (loads.get(key) !== load) {\n return;\n }\n loadingSlots.delete(key);\n if (!failed && !Object.is(scope.s[slot], value)) {\n set(scope, slot, value);\n } else {\n trigger(scope, slot);\n }\n };\n const fail = (error: unknown): void => {\n // A newer load of the memo aborted this one.\n if (loads.get(key) === load) {\n console.error(error);\n settle(undefined, true);\n }\n };\n promise.then((value) => {\n if (!isAsyncIterable(value)) {\n settle(value);\n return;\n }\n // A stream, such as a server function that yields: the memo takes each\n // value, and is pending until the first arrives. A newer load stops it.\n void (async () => {\n try {\n for await (const item of value) {\n if (loads.get(key) !== load) {\n break;\n }\n if (loadingSlots.has(key)) {\n settle(item);\n } else if (!Object.is(scope.s[slot], item)) {\n set(scope, slot, item);\n }\n }\n } catch (error) {\n fail(error);\n }\n })();\n }, fail);\n}\n\n/** Writes a new value of a memo. A promise is loaded with `asyncMemo`. */\n/** Thrown when a memo reads a value that is still loading. */\nclass NotReady extends Error {\n readonly source: Promise<unknown>;\n\n constructor(source: Promise<unknown>) {\n super('The value is still loading');\n this.source = source;\n }\n}\n\n// More than 0 while a memo computes, so reading a value that is still loading stops it.\nlet computing = 0;\n\n/** Aborts the server function calls of a memo's compute, by memo key. */\nconst memoControllers = new Map<string, AbortController>();\n/** The signal for server function calls while a memo computes. */\nlet memoSignal: AbortSignal | undefined;\n\n/**\n * Computes a memo. A promise loads, and the memo keeps its value until it\n * settles. A memo that reads a value that is still loading keeps its value\n * too, and is pending until that value arrives and the memo computes again.\n */\nexport function memo(scope: Scope, slot: number, compute: () => unknown): void {\n const key = `${scope.id}:${slot}`;\n // A guess stays while its source has not changed, such as when a value the server streamed arrives.\n if (sameSource(key)) {\n return;\n }\n let value: unknown;\n // Server function calls of the last compute are aborted, because their answers are out of date.\n memoControllers.get(key)?.abort();\n const controller = new AbortController();\n memoControllers.set(key, controller);\n const outer = memoSignal;\n memoSignal = controller.signal;\n computing++;\n try {\n value = compute();\n } catch (error) {\n if (!(error instanceof NotReady)) {\n throw error;\n }\n if (!loadingSlots.has(key)) {\n loadingSlots.add(key);\n trigger(scope, slot);\n }\n return;\n } finally {\n computing--;\n memoSignal = outer;\n }\n if (\n value !== null &&\n typeof value === 'object' &&\n (typeof (value as PromiseLike<unknown>).then === 'function' || isAsyncIterable(value))\n ) {\n asyncMemo(scope, slot, Promise.resolve(value));\n return;\n }\n // The values it read have arrived, so it is no longer pending.\n const waited = loadingSlots.delete(key);\n loads.delete(key);\n // An optimistic value that computes again follows its source, and drops its guess.\n guesses.delete(key);\n if (!Object.is(scope.s[slot], value)) {\n set(scope, slot, value);\n } else if (waited) {\n trigger(scope, slot);\n }\n}\n\n/** Optimistic values that hold a guess, with the slot that each goes back to. */\nconst guesses = new Map<\n string,\n { scope: Scope; slot: number; source?: [Scope, number]; base?: unknown }\n>();\n/** The values of promises that the server streamed, so a guess knows its source did not change. */\nconst settled = new WeakMap<Promise<unknown>, unknown>();\n\n/** True while the source of a guess holds the value it had when the guess was made. */\nfunction sameSource(key: string): boolean {\n const entry = guesses.get(key);\n if (!entry?.source) {\n return false;\n }\n const current = entry.source[0].s[entry.source[1]];\n return (\n Object.is(current, entry.base) ||\n (entry.base instanceof Promise && settled.get(entry.base) === current)\n );\n}\n/** Server calls that have not finished, from forms and from `rpc`. */\nlet calling = 0;\n\n/**\n * Writes a guess into an optimistic value. It goes back to its source when\n * the source changes, which computes it again, or when every server call of\n * the page finishes, such as after a post failed.\n */\nexport function guess<T>(\n scope: Scope,\n slot: number,\n ...rest: [value: T] | [sourceScope: Scope, sourceSlot: number, value: T]\n): T {\n const value = rest.at(-1) as T;\n const source = rest.length === 3 ? ([rest[0], rest[1]] as [Scope, number]) : undefined;\n const base = source && source[0].s[source[1]];\n guesses.set(`${scope.id}:${slot}`, { scope, slot, source, base });\n return set(scope, slot, value);\n}\n\n/** Counts a server call, and puts guesses back when the last one finishes. */\nfunction track<T>(request: Promise<T>): Promise<T> {\n calling++;\n const done = (): void => {\n calling--;\n // Waits a task, so memos that the answer refreshed start to load first.\n setTimeout(resetGuesses, 0);\n };\n request.then(done, done);\n return request;\n}\n\nfunction resetGuesses(): void {\n if (calling > 0) {\n return;\n }\n for (const [key, { scope, slot, source }] of guesses) {\n // A source that loads again, such as a refreshed list, resets the guess when it arrives.\n if (source && pending(source[0], source[1])) {\n continue;\n }\n guesses.delete(key);\n if (source && scopes.has(scope.id) && !Object.is(scope.s[slot], source[0].s[source[1]])) {\n set(scope, slot, source[0].s[source[1]]);\n }\n }\n}\n\n/** True while a new value of a memo loads, or while the server still streams its value. */\nexport function pending(scope: Scope, slot: number): boolean {\n return loadingSlots.has(`${scope.id}:${slot}`) || scope.s[slot] instanceof Promise;\n}\n\n/** `x++`, `x--`, `++x` and `--x`. */\nexport function update(scope: Scope, slot: number, delta: number, prefix: boolean): number {\n const previous = get(scope, slot) as number;\n set(scope, slot, previous + delta);\n return prefix ? previous + delta : previous;\n}\n\nfunction rootOf(scope: Scope): Scope {\n let current = scope;\n while (current.p) {\n current = current.p;\n }\n return current;\n}\n\nfunction trigger(scope: Scope, slot: number): void {\n const id = rootOf(scope).m!;\n const module = modules.get(id);\n const updates = loadedParts.get(`${id}:update`);\n if (module && updates) {\n run(module, updates, scope, slot);\n return;\n }\n // The first write to a component loads its update code. Later writes wait in order.\n void loadModule(id).then(async (loaded) => {\n if (loaded.g[scope.k]?.[slot]) {\n run(loaded, await loadPart(loaded, 'update'), scope, slot);\n }\n });\n}\n\n// Effects wait until every other update of a write has run, and run once each.\nconst pendingEffects = new Map<string, () => void>();\nlet running = 0;\nlet flushing = false;\n\nfunction run(module: ClientModule, updates: Part, scope: Scope, slot: number): void {\n running++;\n try {\n for (const [kind, name] of module.g[scope.k]?.[slot] ?? []) {\n const fn = updates[name] as (scope: Scope) => void;\n for (const target of kind === scope.k ? [scope] : descendants(scope, kind)) {\n if (name[0] === 'e') {\n pendingEffects.set(`${target.id}:${name}`, () => {\n if (scopes.has(target.id)) {\n fn(target);\n }\n });\n } else {\n fn(target);\n }\n }\n }\n } finally {\n running--;\n }\n if (running === 0) {\n flushEffects();\n }\n}\n\n/**\n * Runs the effects that writes scheduled, in the order they were first\n * scheduled. Writes in an effect schedule more effects, which run after.\n */\nfunction flushEffects(): void {\n if (flushing) {\n return;\n }\n flushing = true;\n try {\n for (\n let next = pendingEffects.entries().next();\n !next.done;\n next = pendingEffects.entries().next()\n ) {\n const [key, runEffect] = next.value;\n pendingEffects.delete(key);\n runEffect();\n }\n } finally {\n flushing = false;\n }\n}\n\nfunction descendants(scope: Scope, kind: number, result: Scope[] = []): Scope[] {\n for (const child of scope.children) {\n if (child.k === kind) {\n result.push(child);\n }\n descendants(child, kind, result);\n }\n return result;\n}\n\nfunction destroy(scope: Scope): void {\n for (const child of Array.from(scope.children)) {\n destroy(child);\n }\n // The content of a `#portal` is elsewhere in the page, so it is removed by its markers.\n const start = comments.get(`P${scope.id}`);\n if (start?.isConnected) {\n const end = rangeEnd(start);\n clear(start, end);\n start.remove();\n end.remove();\n }\n for (const cleanup of scope.cleanups?.values() ?? []) {\n cleanup();\n }\n scopes.delete(scope.id);\n scope.p?.children.delete(scope);\n}\n\nfunction disposeKinds(scope: Scope, kinds: number[]): void {\n for (const child of Array.from(scope.children)) {\n if (kinds.includes(child.k)) {\n destroy(child);\n }\n }\n}\n\n// DOM\n\nconst MARKER = /^[btilP]-?\\d/;\n\nfunction markerKey(data: string): string {\n return data[0] === 'b' ? data.split(':').slice(0, 2).join(':') : data;\n}\n\nfunction indexMarkers(root: Node): void {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const data = (node as Comment).data;\n if (MARKER.test(data)) {\n comments.set(markerKey(data), node as Comment);\n }\n }\n}\n\n/**\n * Finds a marker in the page. Returns undefined when the markup is not in\n * the page, such as `children` inside a block that is closed. Updates to it\n * do nothing, and it updates when the client inserts it again.\n */\nfunction findComment(key: string): Comment | undefined {\n let comment = comments.get(key);\n if (!comment?.isConnected) {\n indexMarkers(document.documentElement);\n comment = comments.get(key);\n }\n return comment?.isConnected ? comment : undefined;\n}\n\nfunction findElement(scope: number, anchor: number): Element | null {\n const key = `${scope}:${anchor}`;\n let element = elements.get(key);\n if (!element?.isConnected) {\n element = document.querySelector(`[data-b=\"${key}\"]`) ?? undefined;\n if (element) {\n elements.set(key, element);\n }\n }\n return element ?? null;\n}\n\n/** Returns the marker that ends the range that `start` opens. */\nfunction rangeEnd(start: Comment): Comment {\n let depth = 0;\n for (let node = start.nextSibling; node; node = node.nextSibling) {\n if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data[0] === '/') {\n if (depth === 0) {\n return node as Comment;\n }\n depth--;\n } else if (MARKER.test(data)) {\n depth++;\n }\n }\n }\n throw new Error(`Missing end marker for <!--${start.data}-->`);\n}\n\nfunction clear(start: Node, end: Node): void {\n while (start.nextSibling && start.nextSibling !== end) {\n start.nextSibling.remove();\n }\n}\n\n/**\n * Inserts rendered HTML before a node, or at the end of a parent, and runs\n * the work that waits for it.\n */\nfunction insertHTML(before: Node | { parent: ParentNode }, html: string): void {\n const template = document.createElement('template');\n template.innerHTML = html;\n const fragment = template.content;\n indexMarkers(fragment);\n options.listen(fragment);\n const server = serverScopes(fragment);\n if ('parent' in before) {\n before.parent.append(fragment);\n } else {\n before.parentNode!.insertBefore(fragment, before);\n }\n for (const fn of context.after.splice(0)) {\n fn();\n }\n // HTML from the server, such as `children`, can be older than the values on the client.\n if (server.length > 0) {\n refresh(server);\n }\n}\n\n/**\n * Returns the scopes from the server that markup refers to. Markup that the\n * client renders has client scopes, so these come from HTML that the server\n * rendered, such as the `children` of a component.\n */\nfunction serverScopes(root: ParentNode): Scope[] {\n const ids = new Set<number>();\n for (const element of root.querySelectorAll('[data-b]')) {\n ids.add(Number(element.getAttribute('data-b')!.split(':')[0]));\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const match = /^[tb](\\d+):/.exec((node as Comment).data);\n if (match) {\n ids.add(Number(match[1]));\n }\n }\n return [...ids].flatMap((id) => {\n const scope = scopes.get(id);\n return scope ? [scope] : [];\n });\n}\n\n/**\n * Renders a `#portal` body into its target, between markers with its scope\n * ID. `kinds` names the body, so a new target first removes it from the old one.\n */\nexport function portal(scope: Scope, target: unknown, render: Render, kinds: number[] = []): void {\n disposeKinds(scope, kinds);\n const element = typeof target === 'string' ? document.querySelector(target) : target;\n if (!(element instanceof Element)) {\n return;\n }\n // The body's scope is the first scope that the render creates.\n const id = nextId;\n insertHTML({ parent: element }, `<!--P${id}-->${render(scope)}<!--/P-->`);\n}\n\nexport function text(scope: Scope, anchor: number, value: unknown): void {\n const start = findComment(`t${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n const node = start.nextSibling;\n if (\n (typeof value === 'string' || typeof value === 'number') &&\n node?.nodeType === 3 &&\n node.nextSibling === end\n ) {\n (node as Text).data = String(value);\n return;\n }\n clear(start, end);\n if (isRaw(value)) {\n insertHTML(end, rawHTML(value));\n } else if (typeof value === 'string' || typeof value === 'number') {\n end.parentNode!.insertBefore(document.createTextNode(String(value)), end);\n } else {\n insertHTML(end, insertValue(value));\n }\n}\n\nfunction setAttribute(element: Element, name: string, value: unknown): void {\n if (name === 'value' || name === 'checked') {\n (element as unknown as Record<string, unknown>)[name] =\n name === 'checked' ? Boolean(value) : (value ?? '');\n }\n const content = attributeText(name, value);\n if (content === undefined) {\n element.removeAttribute(name);\n } else {\n element.setAttribute(name, content);\n }\n}\n\nexport function attr(scope: Scope, anchor: number, name: string, value: unknown): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n setAttribute(element, name, value);\n }\n}\n\nexport function attrs(scope: Scope, anchor: number, values: Record<string, unknown>): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n for (const [name, value] of Object.entries(values)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n setAttribute(element, name, value);\n }\n }\n }\n}\n\ntype Render = (parent: Scope, item?: unknown, index?: number) => string;\n\n/** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */\nexport function branch(\n scope: Scope,\n anchor: number,\n index: number,\n renders: (Render | undefined)[],\n kinds: number[],\n): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n if (Number(start.data.split(':')[2]) === index) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n start.data = `b${scope.id}:${anchor}:${index}`;\n const render = renders[index];\n if (render) {\n insertHTML(end, render(scope));\n }\n}\n\n/** Renders the body of `#key` again when its value changes. */\nexport function rekey(\n scope: Scope,\n anchor: number,\n value: unknown,\n render: Render,\n kinds: number[],\n): void {\n scope.keys ??= new Map();\n if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) {\n return;\n }\n scope.keys.set(anchor, value);\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n insertHTML(end, render(scope));\n}\n\n/**\n * Renders the body of a `#try` block again, for its `reset` function. If the\n * body throws, the fallback renders again with the error.\n */\nexport async function reset(\n scope: Scope,\n anchor: number,\n id: string,\n body: string,\n fallback: string,\n kinds: number[],\n): Promise<void> {\n const updates = await loadPart(await loadModule(id), 'update');\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n let html: string;\n try {\n html = (updates[body] as Render)(scope);\n } catch (error) {\n // Scopes that the body created before it threw.\n disposeKinds(scope, kinds);\n context.after.length = 0;\n html = (updates[fallback] as (parent: Scope, error: unknown) => string)(scope, error);\n }\n insertHTML(end, html);\n}\n\n/** Renders the body of a `#client` block once. */\nexport function fill(scope: Scope, anchor: number, render: Render): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n if (start.nextSibling === end) {\n insertHTML(end, render(scope));\n }\n}\n\ninterface Item {\n scope: Scope;\n nodes: Node[];\n}\n\n/** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */\nexport function list(\n scope: Scope,\n anchor: number,\n items: unknown[],\n key: (item: unknown, index: number) => unknown,\n render: Render,\n assign: (scope: Scope, item: unknown, index: number) => void,\n fallback: Render | undefined,\n fallbackKinds: number[],\n): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n const previous = new Map<unknown, Item>();\n const others: Node[] = [];\n let position = 0;\n for (let node = start.nextSibling; node && node !== end;) {\n if (node.nodeType === 8 && /^i-?\\d+$/.test((node as Comment).data)) {\n const itemEnd = rangeEnd(node as Comment);\n const nodes: Node[] = [];\n for (let current: Node | null = node; current; current = current.nextSibling) {\n nodes.push(current);\n if (current === itemEnd) {\n break;\n }\n }\n const item = scopes.get(Number((node as Comment).data.slice(1)))!;\n previous.set(key(item.i, position++), { scope: item, nodes });\n node = itemEnd.nextSibling;\n } else {\n others.push(node);\n node = node.nextSibling;\n }\n }\n\n if (items.length === 0) {\n if (previous.size === 0 && others.length > 0) {\n return;\n }\n for (const item of previous.values()) {\n destroy(item.scope);\n }\n clear(start, end);\n if (fallback) {\n insertHTML(end, fallback(scope));\n }\n return;\n }\n\n disposeKinds(scope, fallbackKinds);\n for (const node of others) {\n node.parentNode?.removeChild(node);\n }\n const parent = end.parentNode!;\n items.forEach((value, index) => {\n const id = key(value, index);\n const item = previous.get(id);\n if (item) {\n previous.delete(id);\n // Slots that keep their values do not trigger updates.\n assign(item.scope, value, index);\n for (const node of item.nodes) {\n parent.insertBefore(node, end);\n }\n } else {\n insertHTML(end, render(scope, value, index));\n }\n });\n for (const item of previous.values()) {\n destroy(item.scope);\n for (const node of item.nodes) {\n node.parentNode?.removeChild(node);\n }\n }\n}\n\n/** Sets a style variable on the top-level elements of a component instance. */\nexport function setVar(scope: Scope, name: string, value: unknown): void {\n const content = value === null || value === undefined || value === false ? '' : String(value);\n for (const element of document.querySelectorAll<HTMLElement>(`[data-v=\"${scope.id}\"]`)) {\n element.style.setProperty(name, content);\n }\n}\n\n/** The scope that provides a context to `scope`: itself or the nearest one above it. */\nfunction findProvider(scope: Scope, key: string): Scope | undefined {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (current.v && key in current.v) {\n return current;\n }\n }\n return undefined;\n}\n\n/** Writes a provided value, and the slot of every scope that reads it from this provider. */\nexport function provide(scope: Scope, context: ContextValue<unknown>, value: unknown): void {\n scope.v ??= {};\n scope.v[context.key] = value;\n for (const target of scopes.values()) {\n const slot = target.x?.[context.key];\n if (slot !== undefined && findProvider(target, context.key) === scope) {\n set(target, slot, value);\n }\n }\n}\n\n/** Sets the title of the page. */\nexport function title(value: unknown): void {\n document.title = value === null || value === undefined ? '' : String(value);\n}\n\n/** Writes a prop of a child component. */\nexport function prop(scope: Scope, anchor: number, name: string, value: unknown): void {\n const id = scope.c?.[anchor];\n const child = id === undefined ? undefined : scopes.get(id);\n if (!child?.m) {\n return;\n }\n const apply = (module: ClientModule): void => {\n const slot = module.props[name];\n if (slot !== undefined) {\n // A promise loads as an async memo does: the prop keeps its value, and is pending until it settles.\n if (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as PromiseLike<unknown>).then === 'function'\n ) {\n asyncMemo(child, slot, Promise.resolve(value));\n } else {\n set(child, slot, value);\n }\n return;\n }\n const all = module.props['*'];\n if (all !== undefined) {\n set(child, all, { ...(get(child, all) as object), [name]: value });\n }\n };\n const module = modules.get(child.m);\n if (module) {\n apply(module);\n } else {\n void loadModule(child.m).then(apply);\n }\n}\n\n/** Runs an effect or a `$client` callback, after the cleanup of its previous run. */\nexport function effect(scope: Scope, name: string, callback: () => unknown): void {\n scope.cleanups ??= new Map();\n scope.cleanups.get(name)?.();\n const cleanup = callback();\n if (typeof cleanup === 'function') {\n scope.cleanups.set(name, cleanup as () => void);\n } else {\n scope.cleanups.delete(name);\n }\n}\n\n/** Renders the attributes of a form or button that posts to a server function. */\nexport function action(name: string, id: string, method?: string, result?: string): string {\n return actionAttributes(options.rpc ?? '/_brumate', name, id, method, result);\n}\n\n/**\n * Sends a form to the server function of its `$action`, and writes the\n * result into the `$action` when it arrives. It is pending until then.\n */\nexport function submitAction(form: HTMLFormElement, submitter: HTMLElement | null): void {\n const [scopeId, slot] = form.getAttribute('data-result')!.split(':').map(Number) as [\n number,\n number,\n ];\n const scope = scopes.get(scopeId);\n if (!scope) {\n return;\n }\n const data = new FormData(form, submitter);\n const sent = track(\n import('./rpc.ts').then(({ submit }) =>\n submit(options.rpc ?? '/_brumate', form.getAttribute('data-action')!, data),\n ),\n );\n asyncMemo(scope, slot, sent);\n}\n\n/** Calls a server function. */\nexport async function rpc(id: string, args: unknown[]): Promise<unknown> {\n // Read before the import, while the memo that calls it computes.\n const signal = memoSignal;\n return track(\n import('./rpc.ts').then(({ call: callServer }) =>\n callServer(options.rpc ?? '/_brumate', id, args, signal),\n ),\n );\n}\n\n// Rendering on the client\n\n/** Renders a value inserted in markup. */\nexport function insert(value: unknown): string {\n return insertValue(value);\n}\n\n/** A component's client render function, from its `?brumate-render` module. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Components take any props.\nexport type Component<P = any> = (props: P) => string;\n\nfunction resolveScope(scope: Scope | number | undefined): Scope | undefined {\n return typeof scope === 'number' ? scopes.get(scope) : scope;\n}\n\n/**\n * Renders a child component on the client. With `scope` and `anchor`,\n * records the child's scope so the parent can update its props.\n */\nexport function component<P>(\n Child: Component<P>,\n props: P,\n _ctx?: unknown,\n scope?: Scope | number,\n anchor?: number,\n): string {\n const parent = resolveScope(scope);\n if (parent && anchor !== undefined) {\n parent.c ??= {};\n parent.c[anchor] = nextId;\n }\n if (parent) {\n context.own(parent);\n }\n return Child(props);\n}\n\nexport function dynamic(\n tag: unknown,\n attributes: Record<string, unknown>,\n children: Raw | undefined,\n _ctx?: unknown,\n scope?: Scope | number,\n): string {\n if (typeof tag === 'function') {\n return component(\n tag as Component,\n children ? { ...attributes, children } : attributes,\n undefined,\n scope,\n );\n }\n const name = String(tag);\n const open = `<${name}${spreadText(attributes)}>`;\n return VOID_ELEMENTS.has(name) ? open : `${open}${children ? rawHTML(children) : ''}</${name}>`;\n}\n\nclass ClientContext {\n /** Work that waits until rendered markup is in the page. */\n readonly after: (() => void)[] = [];\n\n /** The scope that renders the next component, which becomes its owner. */\n private owner: Scope | undefined;\n\n scope(kind: number, parent?: Scope | number, module?: string): number {\n const id = nextId--;\n const parentScope = resolveScope(parent);\n const scope: Scope = { id, k: kind, p: parentScope, m: module, s: [], children: new Set() };\n if (module !== undefined && this.owner) {\n scope.o = this.owner;\n this.owner = undefined;\n }\n parentScope?.children.add(scope);\n scopes.set(id, scope);\n return id;\n }\n\n /** The ID that `$id()` makes. Client scope IDs are negative, so they differ from the server's. */\n id(scope: Scope | number, index: number): string {\n return `b${resolveScope(scope)!.id}-${index}`;\n }\n\n /** Sets the owner of the next component's root scope. */\n own(scope: Scope | number): void {\n this.owner = resolveScope(scope);\n }\n\n /** Provides a value of a context to the scopes inside `scope`. */\n provide<T>(context: ContextValue<T>, value: T, scope: Scope | number): void {\n const target = resolveScope(scope)!;\n target.v ??= {};\n target.v[context.key] = value;\n }\n\n /** Reads a context, and records its slot so that changes to the provided value reach it. */\n consume<T>(context: ContextValue<T>, scope: Scope | number, slot?: number): T {\n const target = resolveScope(scope)!;\n if (slot !== undefined) {\n target.x ??= {};\n target.x[context.key] = slot;\n }\n const provider = findProvider(target, context.key);\n return provider ? (provider.v![context.key] as T) : context.defaultValue;\n }\n\n slots(id: number, values: unknown[]): void {\n scopes.get(id)!.s = values;\n }\n\n item(id: number, value: unknown): void {\n scopes.get(id)!.i = value;\n }\n\n element(scope: number, anchor: number): ElementReference {\n return new ElementReference(scope, anchor);\n }\n\n /** Adds the markup of a `#head` block to the document's head. */\n head(html: string): void {\n this.after.push(() => insertHTML({ parent: document.head }, html));\n }\n\n /** Sets the title of the page, for a component that the client renders. */\n title(value: unknown): void {\n title(value);\n }\n\n /** Adds the markup of a `#portal` block at the end of the page, after the markup around it. */\n portal(html: string): void {\n this.after.push(() => insertHTML({ parent: document.body }, html));\n }\n\n /** Adds a component's stylesheet to the page, if the server did not. */\n style(id: string, css: string): string {\n if (!document.querySelector(`style[data-brm=\"${id}\"]`)) {\n const style = document.createElement('style');\n style.dataset.brm = id;\n style.textContent = css;\n document.head.append(style);\n }\n return '';\n }\n\n /** A function prop rendered on the client calls the parent's exported handler. */\n fn(value: unknown, ref: string, scope: Scope | number): unknown {\n if (typeof value !== 'function') {\n return value;\n }\n const instance = resolveScope(scope);\n return (...args: unknown[]) => call(ref, instance, args);\n }\n}\n\nexport const context: ClientContext = new ClientContext();\n"],"mappings":";;;;;;;AA6CA,SAAS,OAAO,MAAsB;CACpC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO;AACvC;AAiCA,IAAI;AACJ,MAAM,yBAAS,IAAI,IAAmB;;AAkBtC,MAAa,WAA0B,OAAO,IAAI,kBAAkB;AAEpE,SAAS,WAAsC;CAC7C,OAAQ,WAAyD;AACnE;AACA,MAAM,0BAAU,IAAI,IAA0B;AAC9C,MAAM,0BAAU,IAAI,IAAmC;AACvD,MAAM,wBAAQ,IAAI,IAA2B;AAC7C,MAAM,8BAAc,IAAI,IAAkB;AAC1C,MAAM,2BAAW,IAAI,IAAqB;AAC1C,MAAM,2BAAW,IAAI,IAAqB;AAG1C,IAAI,SAAS;AAIb,MAAM,uBAAO,IAAI,IAAkC;AACnD,MAAM,uBAAO,IAAI,QAAiB;;;;;AAMlC,SAAS,WAAW,QAAuB;CACzC,IAAI,KAAK,IAAI,MAAM,GACjB;CAEF,KAAK,IAAI,MAAM;CACf,MAAM,OAAO,OAAO,aAAa,W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;AAEA,MAAa,UAAyB,IAAI,cAAc"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["id","spreadText"],"sources":["../../src/runtime/client.ts"],"sourcesContent":["import {\n VOID_ELEMENTS,\n actionAttributes,\n attributeText,\n insertValue,\n rawHTML,\n spread as spreadText,\n textValue,\n} from './html.ts';\nimport type { Raw } from './html.ts';\nimport {\n CHILDREN,\n ElementReference,\n FunctionReference,\n ITEM,\n ITEM_SLOT,\n MODULE,\n OWNER,\n SOURCE,\n isAsyncIterable,\n stateValues,\n} from './shared.ts';\nimport type { PackedState, PageState, ScopeState } from './shared.ts';\nimport type { Context as ContextValue } from './context.ts';\n\nexport { affix, attribute, classAttribute, escape, raw, spread, vars } from './html.ts';\nexport type { Raw } from './html.ts';\nexport { produce } from './produce.ts';\n// For `client-routes.ts`, which reads the core with `import()`.\nexport { ElementReference, FunctionReference } from './shared.ts';\nexport { createContext } from './context.ts';\n\ntype Update = [kind: number, name: string];\n\n/** The entry of a compiled client module. */\nexport interface ClientModule {\n id: string;\n /** Prop names to slot indices. `*` is the slot of a props object. */\n props: Record<string, number>;\n /** Scope kind, then slot, to the updates that read it. */\n g: Record<number, Record<number, Update[]>>;\n /**\n * Imports a part of the module. A module without it holds every part\n * itself, as a small component's module does.\n */\n load?: (part: string) => Promise<Part>;\n /** Server function ID to the memos that call it, as scope kind and update, for `refresh`. */\n refresh?: Record<string, Update[]>;\n}\n\n/** A part of a client module: one client root, or the updates. */\nexport type Part = Record<string, unknown>;\n\n/** The part that holds an export: `h<n>` and `c<n>` have their own, the rest are in `update`. */\nfunction partOf(name: string): string {\n return /^[hc]\\d/.test(name) ? name : 'update';\n}\n\n/** The instance of a scope in the page. */\nexport interface Scope {\n id: number;\n /** The scope's ID in the compiled component. */\n k: number;\n p?: Scope;\n /** The component ID, for a component's root scope. */\n m?: string;\n s: unknown[];\n /** The item of a list item scope. */\n i?: unknown;\n c?: Record<number, number>;\n /** The scope that rendered a component's root scope. */\n o?: Scope;\n /** The values that the scope provides, by context key. */\n v?: Record<string, unknown>;\n /** The slots that hold the contexts that the scope reads, by context key. */\n x?: Record<string, number>;\n children: Set<Scope>;\n /** The `b-root` of the render that the server rendered the scope in. */\n r?: string;\n cleanups?: Map<string, () => void>;\n keys?: Map<number, unknown>;\n /** Set while the scope is the body of an `#offscreen` block that is hidden. */\n h?: HiddenBody;\n /** Effects and `$client` callbacks to run when the `#offscreen` body around the scope shows. */\n w?: Set<string>;\n}\n\nexport interface CoreOptions {\n /**\n * Imports the client module of a component. Undefined for a component that\n * has no client code, which a build leaves out.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /** Adds event listeners for the `b-on` attributes in new markup. */\n listen: (root: ParentNode) => void;\n /** The URL prefix of server function calls. Defaults to `/_brumate`. */\n rpc?: string;\n}\n\n// The core keeps only what every page needs: it reads the state, runs handlers and updates.\n// Each helper that compiled code calls is an export of its own, so a build leaves out the ones\n// that no component calls. Features that change how the core reads the page, such as client\n// navigation and hot updates, live in their own modules and set `hooks` when they load.\n\nlet options: CoreOptions;\n/** The URL prefix of server function calls, from the options. */\nexport let rpcPrefix = '/_brumate';\n/** The scopes of the page, by ID. */\nexport const scopes: Map<number, Scope> = new Map();\n\n/** What modules of optional features add to the core. See `client-routes.ts` and `hot`. */\nexport const hooks: {\n /** Changes a state record before its scopes are added, such as for a page that navigation added. */\n record?: (script: Element, state: PageState) => PageState;\n /** Runs after the scopes of a state record are added. */\n added?: (added: Scope[]) => void;\n} = {};\n\n/** What the devtools overlay hears from the core. It is set only in development. */\nexport interface DevtoolsHooks {\n /** The core started, with the scopes of the page, and a way to write a slot, as a handler does. */\n attach?(core: {\n scopes: Map<number, Scope>;\n set: (scope: Scope, slot: number, value: unknown) => void;\n }): void;\n /** A handler starts for an event. */\n handler?(ref: string, element: Element, event?: Event): void;\n /** A part of a component's client code loaded. */\n part?(component: string, name: string): void;\n /** A slot got a new value. */\n write?(scope: Scope, slot: number, value: unknown): void;\n}\n\n/** The global key of the devtools hooks. */\nexport const DEVTOOLS: unique symbol = Symbol.for('brumate.devtools');\n\n/**\n * True on the dev server, which has the devtools. A Vite build replaces it\n * with `false`, so the calls of the devtools hooks are left out. Without\n * Vite, `import.meta.env` is undefined, and the hooks are off.\n */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[DEVTOOLS];\n}\nconst modules = new Map<string, ClientModule>();\nconst loading = new Map<string, Promise<ClientModule>>();\nconst parts = new Map<string, Promise<Part>>();\nconst loadedParts = new Map<string, Part>();\nconst comments = new Map<string, Comment>();\nconst elements = new Map<string, Element>();\n// Scopes that the client creates get negative IDs, so they never match IDs\n// from state records that the server streams later.\nlet nextId = -1;\n\n// Records of one render share references through an array, so a later record can settle a\n// promise of an earlier one. Each render on the page has its own array, by its `b-root`.\nconst refs = new Map<string, unknown[]>();\n\n/**\n * A state record: its script, and its code, which seroval wrote. The code\n * takes the references of its render and the functions that make brumate's\n * values, and returns the value of the record.\n */\ntype StateRecord = [\n script: HTMLScriptElement | null,\n code: (refs: unknown[], values: typeof stateValues) => unknown,\n];\n\n/**\n * The records that ran before the core started, or while it stopped. Each\n * state script hands its record to `push`, which the core replaces while it\n * runs, so it reads later records at once.\n */\nfunction stateQueue(): StateRecord[] {\n const global = globalThis as { $brm?: StateRecord[] };\n return (global.$brm ??= []);\n}\n\n/** Reads the records that later state scripts hand over. Set while the core runs. */\nfunction pushRecords(...added: StateRecord[]): number {\n for (const record of added) {\n readRecord(record);\n }\n return 0;\n}\n\n/**\n * Reads a state record. The first record holds the page state, and later\n * records settle the promises in it.\n */\nfunction readRecord([script, code]: StateRecord): void {\n // A record of a page that navigation replaced before the core started.\n if (!script?.isConnected) {\n return;\n }\n const root = script.getAttribute('b-root') ?? '0';\n if (!refs.has(root)) {\n refs.set(root, []);\n }\n const decoded = code(refs.get(root)!, stateValues);\n // Records with scopes: the page state, and the state of each `#loading` body.\n if (script.hasAttribute('b-scopes')) {\n const unpacked = unpackState(decoded as PackedState);\n const added = addScopes(hooks.record ? hooks.record(script, unpacked) : unpacked, root);\n if (writes > 0) {\n refresh(added);\n }\n }\n}\n\n/**\n * Updates scopes that the server rendered before values changed on the\n * client, such as the body of a `#loading` block that streams in after an\n * event. Effects do not run: they run only when a value changes.\n */\nfunction refresh(added: Scope[]): void {\n for (const scope of added) {\n const id = rootOf(scope).m;\n if (!id) {\n continue;\n }\n void loadModule(id).then(async (module) => {\n const names = new Set<string>();\n for (const slots of Object.values(module.g)) {\n for (const entries of Object.values(slots)) {\n for (const [kind, name] of entries) {\n if (kind === scope.k && name[0] !== 'e') {\n names.add(name);\n }\n }\n }\n }\n if (names.size === 0) {\n return;\n }\n const updates = await loadPart(module, 'update');\n // Memos first, so the other updates read their new values.\n for (const name of [...names].toSorted(\n (a, b) => Number(b[0] === 'm') - Number(a[0] === 'm'),\n )) {\n if (scopes.has(scope.id)) {\n (updates[name] as (scope: Scope) => void)(scope);\n }\n }\n });\n }\n}\n\n/** Reads the groups of scope records back into one record per scope. See `PackedState`. */\nfunction unpackState(state: PackedState): PageState {\n // Items to take from the list in a slot of another record, once every record is read.\n const taken: [records: ScopeState[], source: number, slot: number, first: number][] = [];\n for (const group of state.g ?? []) {\n const [k, base, flags] = group as number[];\n const count = group[3] as number;\n let at = 4;\n const m = flags & MODULE ? (group[at++] as string) : undefined;\n const source: ScopeState[] | undefined = flags & SOURCE ? [] : undefined;\n if (source) {\n taken.push([source, group[at++] as number, group[at++] as number, flags & ITEM_SLOT]);\n }\n // The first slot of a taken item is not written. The gap before the slots holds its place.\n const skip = source && flags & ITEM_SLOT ? 1 : 0;\n let id = flags & OWNER ? 0 : base;\n while (at < group.length) {\n id += group[at++] as number;\n const s = group.slice(at - skip, (at += count - skip));\n const record: ScopeState = flags & OWNER ? { k, o: id - base } : { k, p: base };\n record.s = s;\n if (m !== undefined) {\n record.m = m;\n }\n if (source) {\n source.push(record);\n } else if (flags & ITEM_SLOT) {\n record.i = s[0];\n } else if (flags & ITEM) {\n record.i = group[at++];\n }\n if (flags & CHILDREN) {\n record.c = group[at++] as Record<number, number>;\n }\n state[id] = record;\n }\n }\n delete state.g;\n for (const [records, source, slot, first] of taken) {\n // An array, or a Set, whose order the state keeps.\n const values = Array.from(state[source]!.s![slot] as Iterable<unknown>);\n for (let n = 0; n < records.length; n++) {\n const record = records[n]!;\n record.i = values[n];\n if (first) {\n record.s![0] = values[n];\n }\n }\n }\n return state;\n}\n\nfunction addScopes(state: PageState, root: string): Scope[] {\n const added: Scope[] = [];\n for (const [key, record] of Object.entries(state)) {\n const id = Number(key);\n const scope: Scope = {\n id,\n k: record.k ?? 0,\n m: record.m,\n s: record.s ?? [],\n i: record.i,\n c: record.c,\n v: record.v,\n x: record.x,\n children: new Set(),\n r: root,\n };\n scopes.set(id, scope);\n added.push(scope);\n }\n for (const scope of added) {\n const record = state[scope.id]!;\n if (record.p !== undefined) {\n scope.p = scopes.get(record.p);\n scope.p?.children.add(scope);\n treeChanges++;\n }\n if (record.o !== undefined) {\n scope.o = scopes.get(record.o);\n }\n }\n const seen = new Set<object>();\n for (const scope of added) {\n // A provided value can hold functions, which a component that reads the context calls.\n for (const key of Object.keys(scope.v ?? {})) {\n scope.v![key] = callable(scope.v![key], seen);\n }\n for (let i = 0; i < scope.s.length; i++) {\n const value = callable(scope.s[i], seen);\n scope.s[i] = value;\n // A value that a later state record settles replaces its promise.\n if (value instanceof Promise) {\n void value.then((result) => {\n settled.set(value, result);\n if (scope.s[i] === value) {\n set(scope, i, result);\n }\n });\n }\n }\n }\n hooks.added?.(added);\n return added;\n}\n\n/**\n * Indexes the markers of markup that others insert, such as streamed\n * `#loading` bodies and the pages that navigation adds, so `findComment` can\n * take its records at once.\n */\nlet markerObserver: MutationObserver | undefined;\n\n/** Stops reading state records and markers that arrive later. Later records wait for `init`. */\nexport function dispose(): void {\n const queue = stateQueue();\n if (queue.push === pushRecords) {\n // The array's own `push` again, so records wait in it.\n delete (queue as { push?: unknown }).push;\n }\n markerObserver?.disconnect();\n markerObserver = undefined;\n}\n\n/**\n * Stops reading, before client navigation replaces only some routes. The\n * server renders the new routes with its current values, so only the writes\n * that come after count for the records that stream in later.\n */\nexport function leaveRoutes(): void {\n dispose();\n writes = 0;\n}\n\n/**\n * Removes the scopes of a render, by its `b-root`, with the scopes inside\n * them. Their cleanups run, and their memos no longer load. Its markup\n * stays. `brumate/testing` calls it when a mounted component unmounts.\n */\nexport function removeRoot(root: string): void {\n const inside = (scope: Scope): boolean => {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (current.r === root) {\n return true;\n }\n }\n return false;\n };\n // Deleting from a map while iterating it is safe.\n for (const scope of scopes.values()) {\n if (inside(scope)) {\n removeScope(scope);\n }\n }\n refs.delete(root);\n for (const cache of [comments, elements]) {\n for (const [key, node] of cache) {\n if (!node.isConnected) {\n cache.delete(key);\n }\n }\n }\n}\n\n/**\n * Forgets the code of components that changed on the dev server, so the next\n * event or update loads the new code. Their state stays. `brumate/hot` calls it.\n */\nexport function forget(ids: string[]): void {\n for (const id of ids) {\n modules.delete(id);\n loading.delete(id);\n // Deleting the entry that a loop is at is safe for a Map.\n for (const key of parts.keys()) {\n if (key.startsWith(`${id}:`)) {\n parts.delete(key);\n loadedParts.delete(key);\n }\n }\n }\n}\n\n/** The values of the signals of components whose markup changed, for when the page renders again. */\nconst remounts = new Map<\n string,\n { after: Record<number, string[]>; values: Record<string, unknown>[] }\n>();\n\n/**\n * Keeps the values of the signals of each instance of a component, by\n * name, before the page renders again with its new markup. `brumate/hot` calls it.\n */\nexport function remount(\n detail: {\n id: string;\n before: Record<number, string[]>;\n after: Record<number, string[]>;\n signals: string[];\n }[],\n): void {\n hooks.added = restoreRemounts;\n for (const { id, before, after, signals } of detail) {\n const names = new Set(signals);\n const instances = [...scopes.values()].filter((scope) => scope.m === id);\n remounts.set(id, {\n after,\n // The signals of the script of the component. Signals of blocks, such as of a `#for`\n // body, start again.\n values: instances.map((root) => {\n const values: Record<string, unknown> = {};\n (before[root.k] ?? []).forEach((name, slot) => {\n if (names.has(name)) {\n values[name] = root.s[slot];\n }\n });\n return values;\n }),\n });\n }\n}\n\n/** Writes back the values of signals that `onRemount` kept, into the instances of the new page. */\nfunction restoreRemounts(added: Scope[]): void {\n for (const [id, { after, values }] of remounts) {\n const instances = added.filter((scope) => scope.m === id);\n if (instances.length === 0) {\n continue;\n }\n remounts.delete(id);\n instances.forEach((root, index) => {\n const saved = values[index];\n (after[root.k] ?? []).forEach((name, slot) => {\n if (saved && name in saved) {\n set(root, slot, saved[name]);\n }\n });\n });\n }\n}\n\n/**\n * Forgets the page, before another page replaces it. Cleanups run. Loaded\n * modules and parts stay, so the next page does not load them again. Only\n * client navigation calls it.\n */\nexport function leavePage(): void {\n dispose();\n for (const scope of scopes.values()) {\n for (const cleanup of scope.cleanups?.values() ?? []) {\n cleanup();\n }\n }\n scopes.clear();\n comments.clear();\n elements.clear();\n pendingEffects.clear();\n hiding = undefined;\n loads.clear();\n loadingSlots.clear();\n for (const memoController of memoControllers.values()) {\n memoController.abort();\n }\n memoControllers.clear();\n // The next page reuses scope IDs, so a guess left here would match its memos.\n guesses?.map.clear();\n nextId = -1;\n refs.clear();\n writes = 0;\n // Calls of the old page that are still out no longer count for its guesses.\n calling = 0;\n callEpoch++;\n lastHandler = Promise.resolve();\n}\n\n/** Reads the page state. The loader calls it once, before the first handler. */\nexport function init(value: CoreOptions): void {\n options = value;\n rpcPrefix = value.rpc ?? '/_brumate';\n const queue = stateQueue();\n // Records that are still streaming settle their promises when their scripts run.\n queue.push = pushRecords;\n for (const record of queue.splice(0)) {\n readRecord(record);\n }\n markerObserver = new MutationObserver(indexAdded);\n markerObserver.observe(document, { childList: true, subtree: true });\n // The whole document, because `#head` content is in the head.\n indexMarkers(document.documentElement);\n if (DEV) {\n devtools()?.attach?.({ scopes, set });\n }\n}\n\n/** Replaces function references with functions that call them. */\nfunction callable(value: unknown, seen: Set<object>): unknown {\n if (value instanceof FunctionReference) {\n return (...args: unknown[]) => call(value.ref, scopes.get(value.scope), args);\n }\n if (typeof value === 'object' && value !== null && !seen.has(value)) {\n seen.add(value);\n const prototype = Object.getPrototypeOf(value);\n if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {\n const record = value as Record<string, unknown>;\n for (const key of Object.keys(record)) {\n record[key] = callable(record[key], seen);\n }\n }\n }\n return value;\n}\n\nexport function loadModule(id: string): Promise<ClientModule> {\n let promise = loading.get(id);\n if (!promise) {\n // A component without client code has nothing to update.\n promise = Promise.resolve(options.load(id)).then((loaded) => {\n const module = loaded ?? { id, props: {}, g: {} };\n modules.set(id, module);\n return module;\n });\n loading.set(id, promise);\n }\n return promise;\n}\n\nexport function loadPart(module: ClientModule, name: string): Promise<Part> {\n const key = `${module.id}:${name}`;\n let promise = parts.get(key);\n if (!promise) {\n promise = (module.load ? module.load(name) : Promise.resolve(module as unknown as Part)).then(\n (part) => {\n loadedParts.set(key, part);\n if (DEV) {\n devtools()?.part?.(module.id, name);\n }\n return part;\n },\n );\n parts.set(key, promise);\n }\n return promise;\n}\n\ntype Handler = (scope: Scope | undefined, ...args: unknown[]) => unknown;\n\nasync function resolve(ref: string): Promise<Handler> {\n const [id, name] = ref.split('#') as [string, string];\n const module = await loadModule(id);\n const part = await loadPart(module, partOf(name));\n return part[name] as Handler;\n}\n\nasync function call(ref: string, scope: Scope | undefined, args: unknown[]): Promise<unknown> {\n return (await resolve(ref))(scope, ...args);\n}\n\n// The handler of the previous event, once it has started.\nlet lastHandler: Promise<unknown> = Promise.resolve();\n\n/**\n * Keeps `currentTarget` on an event. The handler runs after the event has\n * finished dispatching, when the browser has already cleared it.\n */\nfunction withTarget(event: Event, element: Element): Event {\n return new Proxy(event, {\n get(target, key) {\n if (key === 'currentTarget') {\n return element;\n }\n const value: unknown = Reflect.get(target, key);\n return typeof value === 'function' ? value.bind(target) : value;\n },\n });\n}\n\n/**\n * Runs the handler `ref` for an element. The scope comes from the element's\n * `b-b` anchor, or from the nearest element around it that has one, which\n * the compiler checks is in the same scope.\n */\nexport function handle(element: Element, ref: string, event?: Event): Promise<unknown> {\n const anchor = element.closest('[b-b]')?.getAttribute('b-b');\n const scope = anchor ? scopes.get(Number(anchor.split(':')[0])) : undefined;\n // A `<window>` or `<document>` listener in a hidden `#offscreen` body does not run.\n if (scope && hiding?.hidden(scope) && element.hasAttribute('b-listen')) {\n return Promise.resolve();\n }\n const args = event ? [withTarget(event, element)] : [];\n if (DEV) {\n devtools()?.handler?.(ref, element, event);\n }\n // Parts load in parallel, but handlers start in the order of their events,\n // so an input handler runs before the submit handler of a later event.\n const loaded = resolve(ref);\n const started = lastHandler\n .then(() => loaded)\n .then((handler) => ({ value: handler(scope, ...args) }));\n lastHandler = started.catch(() => {});\n return started.then((result) => result.value);\n}\n\n/** Returns the instance of a scope by its ID. */\nexport function scopeOf(id: number): Scope | undefined {\n return scopes.get(id);\n}\n\n// Slots\n\n// oxlint-disable-next-line typescript/no-explicit-any -- Slots hold any value.\nexport function get(scope: Scope, slot: number): any {\n const value = scope.s[slot];\n // A value that the server still streams. A memo that reads it waits for it.\n if (computing > 0 && value instanceof Promise) {\n throw new NotReady(value);\n }\n if (value instanceof ElementReference) {\n const element = findElement(value.scope, value.anchor);\n if (element) {\n scope.s[slot] = element;\n }\n return element ?? undefined;\n }\n return value;\n}\n\n// The number of writes since the page loaded, so scopes that stream in later know to update.\nlet writes = 0;\n\nexport function set<T>(scope: Scope, slot: number, value: T): T {\n if (!Object.is(scope.s[slot], value)) {\n writes++;\n scope.s[slot] = value;\n if (DEV) {\n devtools()?.write?.(scope, slot, value);\n }\n trigger(scope, slot);\n }\n return value;\n}\n\n/**\n * The names of a call of a module function, for its shared code. Each ref\n * is a slot of `scope`, `[scope, slot]` for a slot of another scope, or\n * `[value]` for a value that does not change, such as a literal argument.\n */\nexport function cells(scope: Scope, links: unknown[], names: string[]): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n names.forEach((name, index) => {\n const ref = links[index];\n let owner = scope;\n let slot: number;\n if (typeof ref === 'number') {\n slot = ref;\n } else if ((ref as unknown[]).length === 2) {\n [owner, slot] = ref as [Scope, number];\n } else {\n Object.defineProperty(result, name, { get: () => (ref as unknown[])[0], set: () => {} });\n return;\n }\n Object.defineProperty(result, name, {\n get: () => get(owner, slot),\n set: (value: unknown) => set(owner, slot, value),\n });\n });\n return result;\n}\n\n// The latest load of each async memo, by `<scope>:<slot>`, so older results are dropped.\nconst loads = new Map<string, number>();\n// Numbers loads across all memos, so a load is never numbered like an older one still in flight.\nlet loadCount = 0;\nconst loadingSlots = new Set<string>();\n\n/** Marks a memo as loading. Its readers update the first time, so `$isPending` becomes true. */\nfunction startLoading(scope: Scope, slot: number, key: string): void {\n if (!loadingSlots.has(key)) {\n loadingSlots.add(key);\n trigger(scope, slot);\n }\n}\n\n/** True for a promise, or any object with a `then` method. */\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as PromiseLike<unknown>).then === 'function'\n );\n}\n\n/**\n * Writes the result of an async memo when it arrives. Until then the slot\n * keeps its value, and `pending` is true. Only the latest load is written.\n */\nexport function asyncMemo(scope: Scope, slot: number, promise: Promise<unknown>): void {\n const key = `${scope.id}:${slot}`;\n const load = ++loadCount;\n loads.set(key, load);\n startLoading(scope, slot, key);\n const settle = (value?: unknown, failed = false): void => {\n if (loads.get(key) !== load) {\n return;\n }\n loadingSlots.delete(key);\n if (!failed && !Object.is(scope.s[slot], value)) {\n set(scope, slot, value);\n } else {\n trigger(scope, slot);\n }\n };\n const fail = (error: unknown): void => {\n // A newer load of the memo aborted this one.\n if (loads.get(key) === load) {\n console.error(error);\n settle(undefined, true);\n }\n };\n promise.then((value) => {\n if (!isAsyncIterable(value)) {\n settle(value);\n return;\n }\n // A stream, such as a server function that yields: the memo takes each\n // value, and is pending until the first arrives. A newer load stops it.\n void (async () => {\n try {\n for await (const item of value) {\n if (loads.get(key) !== load) {\n break;\n }\n if (loadingSlots.has(key)) {\n settle(item);\n } else if (!Object.is(scope.s[slot], item)) {\n set(scope, slot, item);\n }\n }\n } catch (error) {\n fail(error);\n }\n })();\n }, fail);\n}\n\n/** Thrown when a memo reads a value that is still loading. */\nclass NotReady extends Error {\n readonly source: Promise<unknown>;\n\n constructor(source: Promise<unknown>) {\n super('The value is still loading');\n this.source = source;\n }\n}\n\n// More than 0 while a memo computes, so reading a value that is still loading stops it.\nlet computing = 0;\n\n/** Aborts the server function calls of a memo's compute, by memo key. */\nconst memoControllers = new Map<string, AbortController>();\n/** The key of the memo that computes, if any. */\nlet memoKey: string | undefined;\n\n/** The signal for server function calls while a memo computes. It is made on the first call. */\nfunction memoSignal(): AbortSignal | undefined {\n if (memoKey === undefined) {\n return undefined;\n }\n let controller = memoControllers.get(memoKey);\n if (!controller) {\n controller = new AbortController();\n memoControllers.set(memoKey, controller);\n }\n return controller.signal;\n}\n\n/**\n * Computes a memo. A promise loads, and the memo keeps its value until it\n * settles. A memo that reads a value that is still loading keeps its value\n * too, and is pending until that value arrives and the memo computes again.\n */\nexport function memo(scope: Scope, slot: number, compute: () => unknown): void {\n const key = `${scope.id}:${slot}`;\n // A guess stays while its source has not changed, such as when a value the server streamed arrives.\n if (guesses?.same(key)) {\n return;\n }\n let value: unknown;\n // Server function calls of the last compute are aborted, because their answers are out of date.\n memoControllers.get(key)?.abort();\n memoControllers.delete(key);\n const outer = memoKey;\n memoKey = key;\n computing++;\n try {\n value = compute();\n } catch (error) {\n if (!(error instanceof NotReady)) {\n throw error;\n }\n startLoading(scope, slot, key);\n return;\n } finally {\n computing--;\n memoKey = outer;\n }\n if (isThenable(value) || isAsyncIterable(value)) {\n asyncMemo(scope, slot, Promise.resolve(value));\n return;\n }\n // The values it read have arrived, so it is no longer pending.\n const waited = loadingSlots.delete(key);\n loads.delete(key);\n // An optimistic value that computes again follows its source, and drops its guess.\n guesses?.map.delete(key);\n if (!Object.is(scope.s[slot], value)) {\n set(scope, slot, value);\n } else if (waited) {\n trigger(scope, slot);\n }\n}\n\ninterface Guesses {\n /** Optimistic values that hold a guess, with the slot that each goes back to. */\n map: Map<string, { scope: Scope; slot: number; source?: [Scope, number]; base?: unknown }>;\n same: (key: string) => boolean;\n reset: () => void;\n}\n\n/**\n * The guesses of `$optimistic` values. The first `guess` sets it, so the\n * code that reads guesses is left out of a build that makes none.\n */\nlet guesses: Guesses | undefined;\n/** The values of promises that the server streamed, so a guess knows its source did not change. */\nconst settled = new WeakMap<Promise<unknown>, unknown>();\n\n/** True while the source of a guess holds the value it had when the guess was made. */\nfunction sameSource(key: string): boolean {\n const entry = guesses!.map.get(key);\n if (!entry?.source) {\n return false;\n }\n const current = entry.source[0].s[entry.source[1]];\n return (\n Object.is(current, entry.base) ||\n (entry.base instanceof Promise && settled.get(entry.base) === current)\n );\n}\n/** Server calls that have not finished, from forms and from `rpc`. */\nlet calling = 0;\n/** Counts the pages that client navigation left, so calls of an old page are not counted down. */\nlet callEpoch = 0;\n\n/**\n * Writes a guess into an optimistic value. It goes back to its source when\n * the source changes, which computes it again, or when every server call of\n * the page finishes, such as after a post failed.\n */\nexport function guess<T>(\n scope: Scope,\n slot: number,\n ...rest: [value: T] | [sourceScope: Scope, sourceSlot: number, value: T]\n): T {\n const value = rest.at(-1) as T;\n const source = rest.length === 3 ? ([rest[0], rest[1]] as [Scope, number]) : undefined;\n const base = source && source[0].s[source[1]];\n guesses ??= { map: new Map(), same: sameSource, reset: resetGuesses };\n guesses.map.set(`${scope.id}:${slot}`, { scope, slot, source, base });\n return set(scope, slot, value);\n}\n\n/** Counts a server call, and puts guesses back when the last one finishes. */\nexport function track<T>(request: Promise<T>): Promise<T> {\n calling++;\n const epoch = callEpoch;\n const done = (): void => {\n if (epoch !== callEpoch) {\n return;\n }\n calling--;\n // Waits a task, so memos that the answer refreshed start to load first.\n setTimeout(() => calling || guesses?.reset(), 0);\n };\n request.then(done, done);\n return request;\n}\n\nfunction resetGuesses(): void {\n for (const [key, { scope, slot, source }] of guesses!.map) {\n // A source that loads again, such as a refreshed list, resets the guess when it arrives.\n if (source && pending(source[0], source[1])) {\n continue;\n }\n guesses!.map.delete(key);\n if (source && scopes.has(scope.id) && !Object.is(scope.s[slot], source[0].s[source[1]])) {\n set(scope, slot, source[0].s[source[1]]);\n }\n }\n}\n\n/** True while a new value of a memo loads, or while the server still streams its value. */\nexport function pending(scope: Scope, slot: number): boolean {\n return loadingSlots.has(`${scope.id}:${slot}`) || scope.s[slot] instanceof Promise;\n}\n\n/** `x++`, `x--`, `++x` and `--x`. */\nexport function update(scope: Scope, slot: number, delta: number, prefix: boolean): number {\n const previous = get(scope, slot) as number;\n set(scope, slot, previous + delta);\n return prefix ? previous + delta : previous;\n}\n\nfunction rootOf(scope: Scope): Scope {\n let current = scope;\n while (current.p) {\n current = current.p;\n }\n return current;\n}\n\nfunction trigger(scope: Scope, slot: number): void {\n const id = rootOf(scope).m!;\n const module = modules.get(id);\n const updates = loadedParts.get(`${id}:update`);\n if (module && updates) {\n run(module, updates, scope, slot);\n return;\n }\n // The first write to a component loads its update code. Later writes wait in order.\n void loadModule(id).then(async (loaded) => {\n if (loaded.g[scope.k]?.[slot]) {\n run(loaded, await loadPart(loaded, 'update'), scope, slot);\n }\n });\n}\n\n// Effects wait until every other update of a write has run, and run once each.\nconst pendingEffects = new Map<string, () => void>();\nlet running = 0;\nlet flushing = false;\n/** Counts changes to the scope tree, so `run` knows when the descendants it found are out of date. */\nlet treeChanges = 0;\n\nfunction run(module: ClientModule, updates: Part, scope: Scope, slot: number): void {\n running++;\n // The descendants of each kind, found once while the tree does not change.\n let found: Map<number, Scope[]> | undefined;\n let foundAt = treeChanges;\n try {\n for (const [kind, name] of module.g[scope.k]?.[slot] ?? []) {\n const fn = updates[name] as (scope: Scope) => void;\n if (kind === scope.k) {\n runUpdate(fn, name, scope);\n continue;\n }\n if (foundAt !== treeChanges) {\n found = undefined;\n foundAt = treeChanges;\n }\n found ??= new Map();\n let targets = found.get(kind);\n if (!targets) {\n targets = descendants(scope, kind);\n found.set(kind, targets);\n }\n for (const target of targets) {\n runUpdate(fn, name, target);\n }\n }\n } finally {\n running--;\n }\n if (running === 0) {\n flushEffects();\n }\n}\n\n/** Runs an update on a scope. An effect waits until the other updates have run. */\nfunction runUpdate(fn: (scope: Scope) => void, name: string, target: Scope): void {\n if (name[0] === 'e') {\n pendingEffects.set(`${target.id}:${name}`, () => {\n if (scopes.has(target.id)) {\n fn(target);\n }\n });\n } else {\n fn(target);\n }\n}\n\n/**\n * Runs the effects that writes scheduled, in the order they were first\n * scheduled. Writes in an effect schedule more effects, which run after.\n */\nfunction flushEffects(): void {\n if (flushing) {\n return;\n }\n flushing = true;\n try {\n // A map iterator also visits entries that are added while it runs.\n for (const [key, runEffect] of pendingEffects) {\n pendingEffects.delete(key);\n runEffect();\n }\n } finally {\n flushing = false;\n }\n}\n\nexport function descendants(scope: Scope, kind: number, result: Scope[] = []): Scope[] {\n for (const child of scope.children) {\n if (child.k === kind) {\n result.push(child);\n }\n descendants(child, kind, result);\n }\n return result;\n}\n\nfunction destroy(scope: Scope): void {\n for (const child of Array.from(scope.children)) {\n destroy(child);\n }\n // The content of a `#portal` is elsewhere in the page, so it is removed by its markers.\n const start = comments.get(`P${scope.id}`);\n if (start?.isConnected) {\n const end = rangeEnd(start);\n clear(start, end);\n start.remove();\n end.remove();\n }\n removeScope(scope);\n}\n\n/**\n * Removes a scope from the page: its cleanups run, and its memo state goes,\n * so a load that settles later is not written. Its markup stays.\n */\nexport function removeScope(scope: Scope): void {\n for (const cleanup of scope.cleanups?.values() ?? []) {\n cleanup();\n }\n for (let slot = 0; slot < scope.s.length; slot++) {\n const key = `${scope.id}:${slot}`;\n memoControllers.get(key)?.abort();\n memoControllers.delete(key);\n loads.delete(key);\n loadingSlots.delete(key);\n guesses?.map.delete(key);\n }\n if (scope.h) {\n hiding?.bodies.delete(scope.h);\n }\n scopes.delete(scope.id);\n scope.p?.children.delete(scope);\n treeChanges++;\n}\n\nfunction disposeKinds(scope: Scope, kinds: number[]): void {\n for (const child of Array.from(scope.children)) {\n if (kinds.includes(child.k)) {\n destroy(child);\n }\n }\n}\n\n// DOM\n\nconst MARKER = /^[btilP]-?\\d/;\n\nfunction markerKey(data: string): string {\n return data[0] === 'b' ? data.split(':').slice(0, 2).join(':') : data;\n}\n\nfunction indexMarkers(root: Node): void {\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const data = (node as Comment).data;\n if (MARKER.test(data)) {\n comments.set(markerKey(data), node as Comment);\n }\n }\n}\n\n/** Indexes the markers in the nodes that mutation records added. */\nfunction indexAdded(records: MutationRecord[]): void {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n indexMarkers(node);\n } else if (node.nodeType === 8 && MARKER.test((node as Comment).data)) {\n comments.set(markerKey((node as Comment).data), node as Comment);\n }\n }\n }\n}\n\n/**\n * Finds a marker in the page. Returns undefined when the markup is not in\n * the page, such as `children` inside a block that is closed. Updates to it\n * do nothing, and it updates when the client inserts it again.\n */\nfunction findComment(key: string): Comment | undefined {\n let comment = comments.get(key);\n if (!comment?.isConnected) {\n // The index has every marker in the page once it reads the records that\n // are waiting. Before the core starts, or between pages, it reads the page.\n if (markerObserver) {\n indexAdded(markerObserver.takeRecords());\n } else {\n indexMarkers(document.documentElement);\n }\n comment = comments.get(key);\n }\n return comment?.isConnected ? comment : undefined;\n}\n\nfunction findElement(scope: number, anchor: number): Element | null {\n const key = `${scope}:${anchor}`;\n let element = elements.get(key);\n if (!element?.isConnected) {\n element = document.querySelector(`[b-b=\"${key}\"]`) ?? undefined;\n if (element) {\n elements.set(key, element);\n }\n }\n return element ?? null;\n}\n\n/** Returns the marker that ends the range that `start` opens. */\nfunction rangeEnd(start: Comment): Comment {\n let depth = 0;\n for (let node = start.nextSibling; node; node = node.nextSibling) {\n if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data[0] === '/') {\n if (depth === 0) {\n return node as Comment;\n }\n depth--;\n } else if (MARKER.test(data)) {\n depth++;\n }\n }\n }\n throw new Error(`Missing end marker for <!--${start.data}-->`);\n}\n\nfunction clear(start: Node, end: Node): void {\n while (start.nextSibling && start.nextSibling !== end) {\n start.nextSibling.remove();\n }\n}\n\n/**\n * Inserts rendered HTML before a node, or at the end of a parent, and runs\n * the work that waits for it.\n */\nfunction insertHTML(before: Node | { parent: ParentNode }, html: string): void {\n const template = document.createElement('template');\n template.innerHTML = html;\n const fragment = template.content;\n // Markers that others inserted first, so the new markers win over them.\n if (markerObserver) {\n indexAdded(markerObserver.takeRecords());\n }\n indexMarkers(fragment);\n options.listen(fragment);\n const server = serverScopes(fragment);\n // The nodes of the insert, when hidden `#offscreen` markup can contain them.\n const added = hiding?.bodies.size ? [...fragment.childNodes] : undefined;\n if ('parent' in before) {\n before.parent.append(fragment);\n } else {\n before.parentNode!.insertBefore(fragment, before);\n }\n if (added) {\n hiding!.added(added);\n }\n // The records of this insert, whose markers are indexed already.\n markerObserver?.takeRecords();\n for (const fn of afterInsert.splice(0)) {\n fn();\n }\n // HTML from the server, such as `children`, can be older than the values on the client.\n if (server.length > 0) {\n refresh(server);\n }\n}\n\n/**\n * Returns the scopes from the server that markup refers to. Markup that the\n * client renders has client scopes, so these come from HTML that the server\n * rendered, such as the `children` of a component.\n */\nfunction serverScopes(root: ParentNode): Scope[] {\n const ids = new Set<number>();\n for (const element of root.querySelectorAll('[b-b]')) {\n ids.add(Number(element.getAttribute('b-b')!.split(':')[0]));\n }\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_COMMENT);\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const match = /^[tb](\\d+):/.exec((node as Comment).data);\n if (match) {\n ids.add(Number(match[1]));\n }\n }\n return [...ids].flatMap((id) => {\n const scope = scopes.get(id);\n return scope ? [scope] : [];\n });\n}\n\n/**\n * Renders a `#portal` body into its target, between markers with its scope\n * ID. `kinds` names the body, so a new target first removes it from the old one.\n */\nexport function portalTo(\n scope: Scope,\n target: unknown,\n render: Render,\n kinds: number[] = [],\n): void {\n disposeKinds(scope, kinds);\n const element = typeof target === 'string' ? document.querySelector(target) : target;\n if (!(element instanceof Element)) {\n return;\n }\n // The body's scope is the first scope that the render creates.\n const id = nextId;\n insertHTML({ parent: element }, `<!--P${id}-->${render(scope)}<!--/P-->`);\n}\n\n/** Writes an inserted value between `<!--t…-->` and `<!--/t-->`. */\nexport function text(scope: Scope, anchor: number, value: unknown): void {\n const start = findComment(`t${scope.id}:${anchor}`);\n if (start) {\n write(start.parentNode!, start.nextSibling, rangeEnd(start), value);\n }\n}\n\n/** Writes an inserted value that is the whole content of the element with the anchor. */\nexport function content(scope: Scope, anchor: number, value: unknown): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n write(element, element.firstChild, null, value);\n }\n}\n\n/**\n * Writes the text of an element whose content is text, such as a `<textarea>`\n * or a `<title>`. A `<textarea>` gets the value too, as `value` does on an\n * `<input>`, so a change replaces what the user typed.\n */\nexport function writeText(scope: Scope, anchor: number, value: unknown): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n const written = textValue(value);\n element.textContent = written;\n if (element instanceof HTMLTextAreaElement) {\n element.value = written;\n }\n }\n}\n\n/**\n * Replaces the nodes of `parent` from `first` up to `end`, or to its last\n * child, with a value. A text node that stays a text node keeps its node.\n */\nfunction write(\n parent: Node & ParentNode,\n first: ChildNode | null,\n end: Node | null,\n value: unknown,\n): void {\n if (\n (typeof value === 'string' || typeof value === 'number') &&\n first?.nodeType === 3 &&\n first.nextSibling === end\n ) {\n // Hidden text keeps its new value for when it shows.\n const saved = hiding?.nodes.get(first);\n if (saved) {\n saved.v = String(value);\n } else {\n (first as Text).data = String(value);\n }\n return;\n }\n while (first && first !== end) {\n const next = first.nextSibling;\n first.remove();\n first = next;\n }\n insertHTML(end ?? { parent }, insertValue(value));\n}\n\nfunction setAttribute(element: Element, name: string, value: unknown): void {\n if (name === 'value' || name === 'checked') {\n (element as unknown as Record<string, unknown>)[name] =\n name === 'checked' ? Boolean(value) : (value ?? '');\n }\n const written = attributeText(name, value);\n if (written === undefined) {\n element.removeAttribute(name);\n } else {\n element.setAttribute(name, written);\n }\n if (name === 'style') {\n hiding?.styled(element);\n }\n}\n\nexport function attr(scope: Scope, anchor: number, name: string, value: unknown): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n setAttribute(element, name, value);\n }\n}\n\nexport function attrs(scope: Scope, anchor: number, values: Record<string, unknown>): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n for (const [name, value] of Object.entries(values)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n setAttribute(element, name, value);\n }\n }\n }\n}\n\ntype Render = (parent: Scope, item?: unknown, index?: number) => string;\n\n/** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */\nexport function branch(\n scope: Scope,\n anchor: number,\n index: number,\n renders: (Render | undefined)[],\n kinds: number[],\n): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n if (Number(start.data.split(':')[2]) === index) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n start.data = `b${scope.id}:${anchor}:${index}`;\n const render = renders[index];\n if (render) {\n insertHTML(end, render(scope));\n }\n}\n\n/** Renders the body of `#key` again when its value changes. */\nexport function rekey(\n scope: Scope,\n anchor: number,\n value: unknown,\n render: Render,\n kinds: number[],\n): void {\n scope.keys ??= new Map();\n if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) {\n return;\n }\n scope.keys.set(anchor, value);\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n insertHTML(end, render(scope));\n}\n\n/**\n * Renders the body of a `#try` block again, for its `reset` function. If the\n * body throws, the fallback renders again with the error.\n */\nexport async function reset(\n scope: Scope,\n anchor: number,\n id: string,\n body: string,\n fallback: string,\n kinds: number[],\n): Promise<void> {\n const updates = await loadPart(await loadModule(id), 'update');\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n let html: string;\n try {\n html = (updates[body] as Render)(scope);\n } catch (error) {\n // Scopes that the body created before it threw.\n disposeKinds(scope, kinds);\n afterInsert.length = 0;\n html = (updates[fallback] as (parent: Scope, error: unknown) => string)(scope, error);\n }\n insertHTML(end, html);\n}\n\n/** Renders the body of a `#client` block once. */\nexport function fill(scope: Scope, anchor: number, render: Render): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n if (start.nextSibling === end) {\n insertHTML(end, render(scope));\n }\n}\n\n/**\n * Shows or hides the body of an `#offscreen` block. A body that the page\n * does not have yet renders the first time it shows. `kind` is the body's\n * scope ID in the compiled component.\n */\nexport function offscreen(\n scope: Scope,\n anchor: number,\n value: unknown,\n render: Render,\n kind: number,\n): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const visible = Boolean(value);\n // 1 for a body that shows, 0 for one that is hidden, and -1 for one that has not rendered.\n const state = start.data.split(':')[2];\n if (visible ? state === '1' : state !== '1') {\n return;\n }\n start.data = `b${scope.id}:${anchor}:${visible ? 1 : 0}`;\n const end = rangeEnd(start);\n if (state === '-1') {\n insertHTML(end, render(scope));\n return;\n }\n let body: Scope | undefined;\n for (const child of scope.children) {\n if (child.k === kind) {\n body = child;\n }\n }\n if (body) {\n hiding ??= createHiding();\n if (visible) {\n hiding.show(body);\n } else {\n hiding.hide(body, start, end);\n }\n }\n}\n\n/** A hidden `#offscreen` body: its scope, and the ranges of its markup and of its portals. */\nexport interface HiddenBody {\n scope: Scope;\n ranges: [start: Comment, end: Comment][];\n}\n\n/**\n * What a hidden node had before it was hidden: `n` hidden bodies that hide\n * it, and the text of a text node, or the inline `display` of an element\n * with its priority and whether it had a `style` attribute.\n */\ninterface Saved {\n n: number;\n v: string;\n p?: string;\n a?: boolean;\n}\n\ninterface Hiding {\n bodies: Set<HiddenBody>;\n nodes: WeakMap<Node, Saved>;\n hide: (body: Scope, start: Comment, end: Comment) => void;\n show: (body: Scope) => void;\n /** True for a scope in a hidden body. */\n hidden: (scope: Scope) => boolean;\n /** Keeps an effect for when its body shows, and returns true, if its scope is hidden. */\n paused: (scope: Scope, name: string) => boolean;\n /** Hides the nodes that an insert added to hidden markup. */\n added: (nodes: Node[]) => void;\n /** Keeps an element hidden after its `style` attribute changed. */\n styled: (element: Element) => void;\n}\n\n/**\n * The code of hidden `#offscreen` bodies. The first body that hides sets it\n * up, so the core of a page without one only checks that it is not there.\n * A body is hidden with an inline `display: none !important` on each element\n * at its top level, which no stylesheet overrides, and empty text for each\n * text node. The nodes stay in the page, so form fields, focus and media\n * keep their state.\n */\nlet hiding: Hiding | undefined;\n\n/** True for a scope that is `ancestor` or inside it, also through the owner of a component. */\nfunction within(scope: Scope, ancestor: Scope): boolean {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (current === ancestor) {\n return true;\n }\n }\n return false;\n}\n\n/** True for a scope in a hidden `#offscreen` body. */\nfunction hidden(scope: Scope): boolean {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (current.h) {\n return true;\n }\n }\n return false;\n}\n\n/** The nodes between two markers. */\nfunction between([start, end]: [Comment, Comment]): Node[] {\n const result: Node[] = [];\n for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) {\n result.push(node);\n }\n return result;\n}\n\n/** The inline style of an element, which an element that is not HTML or SVG may not have. */\nfunction display(element: Element): CSSStyleDeclaration | undefined {\n return (element as HTMLElement).style;\n}\n\nfunction createHiding(): Hiding {\n const bodies = new Set<HiddenBody>();\n const nodes = new WeakMap<Node, Saved>();\n const hideNode = (node: Node): void => {\n const saved = nodes.get(node);\n if (saved) {\n saved.n++;\n return;\n }\n if (node.nodeType === 3) {\n nodes.set(node, { n: 1, v: (node as Text).data });\n (node as Text).data = '';\n return;\n }\n const style = node.nodeType === 1 ? display(node as Element) : undefined;\n if (style) {\n nodes.set(node, {\n n: 1,\n v: style.getPropertyValue('display'),\n p: style.getPropertyPriority('display'),\n a: (node as Element).hasAttribute('style'),\n });\n style.setProperty('display', 'none', 'important');\n }\n };\n const showNode = (node: Node): void => {\n const saved = nodes.get(node);\n if (!saved || --saved.n > 0) {\n return;\n }\n nodes.delete(node);\n if (node.nodeType === 3) {\n (node as Text).data = saved.v;\n return;\n }\n const element = node as Element;\n const style = display(element)!;\n if (saved.v) {\n style.setProperty('display', saved.v, saved.p);\n } else {\n style.removeProperty('display');\n }\n if (!saved.a && element.getAttribute('style') === '') {\n element.removeAttribute('style');\n }\n };\n return {\n bodies,\n nodes,\n hidden,\n hide(body, start, end) {\n const record: HiddenBody = { scope: body, ranges: [[start, end]] };\n body.h = record;\n bodies.add(record);\n const inside = [...scopes.values()].filter((scope) => within(scope, body));\n for (const scope of inside) {\n // The content of a `#portal` in the body, elsewhere in the page.\n const portal = comments.get(`P${scope.id}`);\n if (portal?.isConnected) {\n record.ranges.push([portal, rangeEnd(portal)]);\n }\n }\n for (const range of record.ranges) {\n between(range).forEach(hideNode);\n }\n // Effects and `$client` callbacks that ran stop, and run again when the body shows.\n for (const scope of inside) {\n for (const [name, cleanup] of scope.cleanups ?? []) {\n cleanup();\n (scope.w ??= new Set()).add(name);\n }\n scope.cleanups?.clear();\n }\n },\n show(body) {\n const record = body.h;\n if (!record) {\n return;\n }\n body.h = undefined;\n bodies.delete(record);\n for (const range of record.ranges) {\n if (range[0].isConnected) {\n between(range).forEach(showNode);\n }\n }\n for (const scope of scopes.values()) {\n if (scope.w && within(scope, body) && !hidden(scope)) {\n const ref = `${rootOf(scope).m}#`;\n for (const name of scope.w) {\n void call(ref + name, scope, []);\n }\n scope.w = undefined;\n }\n }\n },\n paused(scope, name) {\n if (bodies.size === 0 || !hidden(scope)) {\n return false;\n }\n (scope.w ??= new Set()).add(name);\n return true;\n },\n added(added) {\n for (const node of added) {\n for (const record of bodies) {\n for (const [start, end] of record.ranges) {\n if (\n node.parentNode === start.parentNode &&\n start.compareDocumentPosition(node) & 4 &&\n node.compareDocumentPosition(end) & 4\n ) {\n hideNode(node);\n }\n }\n // A `#portal` that renders in a hidden body, whose nodes follow its marker.\n const data = node.nodeType === 8 ? (node as Comment).data : '';\n const scope = /^P-?\\d+$/.test(data) ? scopes.get(Number(data.slice(1))) : undefined;\n if (scope && within(scope, record.scope)) {\n record.ranges.push([node as Comment, rangeEnd(node as Comment)]);\n }\n }\n }\n },\n styled(element) {\n const saved = nodes.get(element);\n const style = display(element);\n if (saved && style) {\n saved.v = style.getPropertyValue('display');\n saved.p = style.getPropertyPriority('display');\n saved.a = element.hasAttribute('style');\n style.setProperty('display', 'none', 'important');\n }\n },\n };\n}\n\ninterface Item {\n scope: Scope;\n nodes: Node[];\n}\n\n/** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */\nexport function list(\n scope: Scope,\n anchor: number,\n items: unknown[],\n key: (item: unknown, index: number) => unknown,\n render: Render,\n assign: (scope: Scope, item: unknown, index: number) => void,\n fallback: Render | undefined,\n fallbackKinds: number[],\n): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n const previous = new Map<unknown, Item>();\n const others: Node[] = [];\n let position = 0;\n for (let node = start.nextSibling; node && node !== end;) {\n const data = node.nodeType === 8 ? (node as Comment).data : undefined;\n // An item between `<!--i…-->` and `<!--/i-->`, or one element whose `b-b` names the scope.\n const id = data\n ? /^i(-?\\d+)$/.exec(data)?.[1]\n : (node as Element).getAttribute?.('b-b')?.split(':')[0];\n const item = id === undefined ? undefined : scopes.get(Number(id));\n let last: Node = node;\n // The elements of the fallback have scopes of its kinds.\n if (item && (data || (item.p === scope && !fallbackKinds.includes(item.k)))) {\n if (data) {\n last = rangeEnd(node as Comment);\n }\n const nodes = [node];\n for (let current = node; current !== last;) {\n nodes.push((current = current.nextSibling!));\n }\n previous.set(key(item.i, position++), { scope: item, nodes });\n } else {\n others.push(node);\n }\n node = last.nextSibling;\n }\n\n if (items.length === 0) {\n if (previous.size === 0 && others.length > 0) {\n return;\n }\n for (const item of previous.values()) {\n destroy(item.scope);\n }\n clear(start, end);\n if (fallback) {\n insertHTML(end, fallback(scope));\n }\n return;\n }\n\n disposeKinds(scope, fallbackKinds);\n for (const node of others) {\n node.parentNode?.removeChild(node);\n }\n const parent = end.parentNode!;\n // The first node after the items placed so far. An item already there is not\n // moved, because moving a node restarts its animations and drops its focus.\n let cursor: Node = start.nextSibling!;\n // New items next to each other go into the page with one insert.\n let added = '';\n const flush = (): void => {\n if (added) {\n insertHTML(cursor, added);\n added = '';\n }\n };\n items.forEach((value, index) => {\n const id = key(value, index);\n const item = previous.get(id);\n if (item) {\n // Before the item's updates run, so they see the new items before it.\n flush();\n previous.delete(id);\n // Slots that keep their values do not trigger updates.\n assign(item.scope, value, index);\n if (item.nodes[0] === cursor) {\n cursor = item.nodes.at(-1)!.nextSibling!;\n } else {\n for (const node of item.nodes) {\n parent.insertBefore(node, cursor);\n }\n }\n } else {\n added += render(scope, value, index);\n }\n });\n flush();\n for (const item of previous.values()) {\n destroy(item.scope);\n for (const node of item.nodes) {\n node.parentNode?.removeChild(node);\n }\n }\n}\n\n/** Sets a style variable on the top-level elements of a component instance. */\nexport function setVar(scope: Scope, name: string, value: unknown): void {\n const css = value === null || value === undefined || value === false ? '' : String(value);\n for (const element of document.querySelectorAll<HTMLElement>(`[b-v=\"${scope.id}\"]`)) {\n element.style.setProperty(name, css);\n }\n}\n\n/** The scope that provides a context to `scope`: itself or the nearest one above it. */\nfunction findProvider(scope: Scope, key: string): Scope | undefined {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (current.v && key in current.v) {\n return current;\n }\n }\n return undefined;\n}\n\n/** Writes a provided value, and the slot of every scope that reads it from this provider. */\nexport function updateContext(scope: Scope, context: ContextValue<unknown>, value: unknown): void {\n scope.v ??= {};\n scope.v[context.key] = value;\n for (const target of scopes.values()) {\n const slot = target.x?.[context.key];\n if (slot !== undefined && findProvider(target, context.key) === scope) {\n set(target, slot, value);\n }\n }\n}\n\n/** Sets the title of the page. */\nexport function title(value: unknown): void {\n document.title = value === null || value === undefined ? '' : String(value);\n}\n\n/** Writes a prop of a child component. */\nexport function prop(scope: Scope, anchor: number, name: string, value: unknown): void {\n const id = scope.c?.[anchor];\n const child = id === undefined ? undefined : scopes.get(id);\n if (!child?.m) {\n return;\n }\n const apply = (module: ClientModule): void => {\n const slot = module.props[name];\n if (slot !== undefined) {\n // A promise loads as an async memo does: the prop keeps its value, and is pending until it settles.\n if (isThenable(value)) {\n asyncMemo(child, slot, Promise.resolve(value));\n } else {\n set(child, slot, value);\n }\n return;\n }\n const all = module.props['*'];\n if (all !== undefined) {\n set(child, all, { ...(get(child, all) as object), [name]: value });\n }\n };\n const module = modules.get(child.m);\n if (module) {\n apply(module);\n } else {\n void loadModule(child.m).then(apply);\n }\n}\n\n/** Runs an effect or a `$client` callback, after the cleanup of its previous run. */\nexport function effect(scope: Scope, name: string, callback: () => unknown): void {\n // In a hidden `#offscreen` body, it runs when the body shows.\n if (hiding?.paused(scope, name)) {\n return;\n }\n scope.cleanups ??= new Map();\n scope.cleanups.get(name)?.();\n const cleanup = callback();\n // An entry without a cleanup too, so a hidden `#offscreen` body knows what to run again.\n scope.cleanups.set(name, typeof cleanup === 'function' ? (cleanup as () => void) : noop);\n}\n\nfunction noop(): void {}\n\n/** Renders the attributes of a form or button that posts to a server function. */\nexport function action(name: string, id: string, method?: string, result?: string): string {\n return actionAttributes(rpcPrefix, name, id, method, result);\n}\n\n/**\n * Sends a form of an `$action`. The code is in `rpc.ts`, which every server\n * call loads, so the core holds only this.\n */\nexport function submitAction(form: HTMLFormElement, submitter: HTMLElement | null): void {\n void import('./rpc.ts').then((module) => module.sendAction(form, submitter));\n}\n\n/** Calls a server function. */\nexport async function rpc(id: string, args: unknown[]): Promise<unknown> {\n // Read before the import, while the memo that calls it computes.\n const signal = memoSignal();\n return track(import('./rpc.ts').then((module) => module.call(rpcPrefix, id, args, signal)));\n}\n\n// Rendering on the client\n\n/** Renders a value inserted in markup. */\nexport function insert(value: unknown): string {\n return insertValue(value);\n}\n\n/** A component's client render function, from its `?brumate-render` module. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Components take any props.\nexport type Component<P = any> = (props: P) => string;\n\nfunction resolveScope(scope: Scope | number | undefined): Scope | undefined {\n return typeof scope === 'number' ? scopes.get(scope) : scope;\n}\n\n/**\n * Renders a child component on the client. With `scope` and `anchor`,\n * records the child's scope so the parent can update its props.\n */\nexport function component<P>(\n Child: Component<P>,\n props: P,\n _ctx?: unknown,\n scope?: Scope | number,\n anchor?: number,\n): string {\n const parent = resolveScope(scope);\n if (parent && anchor !== undefined) {\n parent.c ??= {};\n parent.c[anchor] = nextId;\n }\n if (parent) {\n setOwner(parent);\n }\n return Child(props);\n}\n\nexport function dynamic(\n tag: unknown,\n attributes: Record<string, unknown>,\n children: Raw | undefined,\n _ctx?: unknown,\n scope?: Scope | number,\n): string {\n if (typeof tag === 'function') {\n return component(\n tag as Component,\n children ? { ...attributes, children } : attributes,\n undefined,\n scope,\n );\n }\n const name = String(tag);\n const open = `<${name}${spreadText(attributes)}>`;\n return VOID_ELEMENTS.has(name) ? open : `${open}${children ? rawHTML(children) : ''}</${name}>`;\n}\n\n/** Work that waits until rendered markup is in the page. */\nexport const afterInsert: (() => void)[] = [];\n\n/** The scope that renders the next component, which becomes its owner. */\nlet owner: Scope | undefined;\n\n// The helpers below are what the server's render context does, for markup that the client\n// renders. Each is an export of its own, so a build keeps only those that its components call.\n\n/** Creates a scope for markup that the client renders, and returns its ID. */\nexport function createScope(kind: number, parent?: Scope | number, module?: string): number {\n const id = nextId--;\n const parentScope = resolveScope(parent);\n const created: Scope = { id, k: kind, p: parentScope, m: module, s: [], children: new Set() };\n if (module !== undefined && owner) {\n created.o = owner;\n owner = undefined;\n }\n parentScope?.children.add(created);\n treeChanges++;\n scopes.set(id, created);\n return id;\n}\n\n/** The ID that `$id()` makes. Client scope IDs are negative, so they differ from the server's. */\nexport function makeId(scope: Scope | number, index: number): string {\n return `b${resolveScope(scope)!.id}-${index}`;\n}\n\n/** Sets the owner of the next component's root scope. */\nexport function setOwner(scope: Scope | number): void {\n owner = resolveScope(scope);\n}\n\n/** Provides a value of a context to the scopes inside `scope`. */\nexport function provideValue<T>(context: ContextValue<T>, value: T, scope: Scope | number): void {\n const target = resolveScope(scope)!;\n target.v ??= {};\n target.v[context.key] = value;\n}\n\n/** Reads a context, and records its slot so that changes to the provided value reach it. */\nexport function consumeContext<T>(\n context: ContextValue<T>,\n scope: Scope | number,\n slot?: number,\n): T {\n const target = resolveScope(scope)!;\n if (slot !== undefined) {\n target.x ??= {};\n target.x[context.key] = slot;\n }\n const provider = findProvider(target, context.key);\n return provider ? (provider.v![context.key] as T) : context.defaultValue;\n}\n\nexport function setSlots(id: number, values: unknown[]): void {\n scopes.get(id)!.s = values;\n}\n\nexport function setItem(id: number, value: unknown): void {\n scopes.get(id)!.i = value;\n}\n\nexport function elementAt(scope: number, anchor: number): ElementReference {\n return new ElementReference(scope, anchor);\n}\n\n/** Adds the markup of a `#head` block to the document's head. */\nexport function addHead(html: string): void {\n afterInsert.push(() => insertHTML({ parent: document.head }, html));\n}\n\n/** Adds the markup of a `#portal` block at the end of the page, after the markup around it. */\nexport function addPortal(html: string): void {\n afterInsert.push(() => insertHTML({ parent: document.body }, html));\n}\n\n/** Adds a component's stylesheet to the page, if the server did not. */\nexport function addStyle(id: string, css: string): string {\n if (!document.querySelector(`style[b-style=\"${id}\"]`)) {\n const sheet = document.createElement('style');\n sheet.setAttribute('b-style', id);\n sheet.textContent = css;\n document.head.append(sheet);\n }\n return '';\n}\n\n/** A function prop rendered on the client calls the parent's exported handler. */\nexport function handlerProp(value: unknown, ref: string, scope: Scope | number): unknown {\n if (typeof value !== 'function') {\n return value;\n }\n const instance = resolveScope(scope);\n return (...args: unknown[]) => call(ref, instance, args);\n}\n\n/**\n * What the loader calls. It is one export, so the loader's import of the core\n * names one export, and a build keeps the rest only when components call them.\n */\nexport const loader: {\n init: typeof init;\n handle: typeof handle;\n dispose: typeof dispose;\n submitAction: typeof submitAction;\n} = { init, handle, dispose, submitAction };\n"],"mappings":";;;;;;AAsDA,SAAS,OAAO,MAAsB;CACpC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO;AACvC;AAgDA,IAAI;;AAEJ,IAAW,YAAY;;AAEvB,MAAa,yBAA6B,IAAI,IAAI;;AAGlD,MAAa,QAKT,CAAC;;AAkBL,MAAa,WAA0B,OAAO,IAAI,kBAAkB;;;;;;AAOpE,MAAM,MAAO,YAA4C,KAAK;AAE9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD;AACnE;AACA,MAAM,0BAAU,IAAI,IAA0B;AAC9C,MAAM,0BAAU,IAAI,IAAmC;AACvD,MAAM,wBAAQ,IAAI,IAA2B;AAC7C,MAAM,8BAAc,IAAI,IAAkB;AAC1C,MAAM,2BAAW,IAAI,IAAqB;AAC1C,MAAM,2BAAW,IAAI,IAAqB;AAG1C,IAAI,SAAS;AAIb,MAAM,uBAAO,IAAI,IAAuB;;;;;;AAiBxC,SAAS,aAA4B;CACnC,MAAM,SAAS;CACf,OAAQ,OAAO,SAAS,CAAC;AAC3B;;AAGA,SAAS,YAAY,GAAG,OAA8B;CACpD,KAAK,MAAM,UAAU,OACnB,WAAW,MAAM;CAEnB,OAAO;AACT;;;;;AAMA,SAAS,WAAW,CAAC,QAAQ,OAA0B;CAErD,IAAI,CAAC,QAAQ,aACX;CAEF,MAAM,OAAO,OAAO,aAAa,QAAQ,KAAK;CAC9C,IAAI,CAAC,KAAK,IAAI,IAAI,GAChB,KAAK,IAAI,MAAM,CAAC,CAAC;CAEnB,MAAM,UAAU,KAAK,KAAK,IAAI,IAAI,GAAI,WAAW;CAEjD,IAAI,OAAO,aAAa,UAAU,GAAG;EACnC,MAAM,WAAW,YAAY,OAAsB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AS,KAAA,GAAW;EACtB,OAAO,MAAM,CAAC;EACd,OAAO,EAAE,QAAQ,OAAO;CAC1B;CACA,MAAM,WAAW,aAAa,QAAQ,QAAQ,GAAG;CACjD,OAAO,WAAY,SAAS,EAAG,QAAQ,OAAa,QAAQ;AAC9D;AAEA,SAAgB,SAAS,IAAY,QAAyB;CAC5D,OAAO,IAAI,EAAE,CAAC,CAAE,IAAI;AACtB;AAEA,SAAgB,QAAQ,IAAY,OAAsB;CACxD,OAAO,IAAI,EAAE,CAAC,CAAE,IAAI;AACtB;AAEA,SAAgB,UAAU,OAAe,QAAkC;CACzE,OAAO,IAAI,iBAAiB,OAAO,MAAM;AAC3C;;AAGA,SAAgB,QAAQ,MAAoB;CAC1C,YAAY,WAAW,WAAW,EAAE,QAAQ,SAAS,KAAK,GAAG,IAAI,CAAC;AACpE;;AAGA,SAAgB,UAAU,MAAoB;CAC5C,YAAY,WAAW,WAAW,EAAE,QAAQ,SAAS,KAAK,GAAG,IAAI,CAAC;AACpE;;AAGA,SAAgB,SAAS,IAAY,KAAqB;CACxD,IAAI,CAAC,SAAS,cAAc,kBAAkB,GAAG,GAAG,GAAG;EACrD,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,aAAa,WAAW,EAAE;EAChC,MAAM,cAAc;EACpB,SAAS,KAAK,OAAO,KAAK;CAC5B;CACA,OAAO;AACT;;AAGA,SAAgB,YAAY,OAAgB,KAAa,OAAgC;CACvF,IAAI,OAAO,UAAU,YACnB,OAAO;CAET,MAAM,WAAW,aAAa,KAAK;CACnC,QAAQ,GAAG,SAAoB,KAAK,KAAK,UAAU,IAAI;AACzD;;;;;AAMA,MAAa,SAKT;CAAE;CAAM;CAAQ;CAAS;AAAa"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as Scope } from "../client-DwJInP_a.js";
|
|
2
2
|
//#region src/runtime/devtools.d.ts
|
|
3
3
|
/** Something that happened on the page, for the log of the panel. */
|
|
4
4
|
export interface DevtoolsEntry {
|
|
@@ -26,6 +26,8 @@ export interface DevtoolsState {
|
|
|
26
26
|
/** Called after each change, while the panel is open. */
|
|
27
27
|
changed?: () => void;
|
|
28
28
|
}
|
|
29
|
+
/** The root scope of a scope, whose `m` names its component. */
|
|
30
|
+
export declare function rootOf(scope: Scope): Scope;
|
|
29
31
|
/** A short text for a value in the log. */
|
|
30
32
|
export declare function preview(value: unknown): string;
|
|
31
33
|
/** Listens to the core, and adds the button that opens the panel. */
|
package/dist/runtime/devtools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as installDevtools, n as preview } from "../devtools-
|
|
1
|
+
export { t as installDevtools, n as preview, r as rootOf } from "../devtools-BKjnHrnv.js";
|
package/dist/runtime/hot.d.ts
CHANGED
package/dist/runtime/hot.js
CHANGED
|
@@ -11,7 +11,7 @@ function hotLoad(hot, load) {
|
|
|
11
11
|
const changed = [];
|
|
12
12
|
for (const update of updates) {
|
|
13
13
|
if (update.css !== void 0) {
|
|
14
|
-
const style = document.querySelector(`style[
|
|
14
|
+
const style = document.querySelector(`style[b-style="${CSS.escape(update.id)}"]`);
|
|
15
15
|
if (style) style.textContent = update.css;
|
|
16
16
|
}
|
|
17
17
|
if (update.url) {
|
|
@@ -21,10 +21,14 @@ function hotLoad(hot, load) {
|
|
|
21
21
|
}
|
|
22
22
|
if (changed.length > 0) document.dispatchEvent(new CustomEvent("brumate:hot", { detail: changed }));
|
|
23
23
|
const remounts = updates.filter((update) => update.remount);
|
|
24
|
-
if (remounts.length
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (changed.length === 0 && remounts.length === 0) return;
|
|
25
|
+
import("./client.js").then(({ forget, remount }) => {
|
|
26
|
+
forget(changed);
|
|
27
|
+
if (remounts.length > 0) {
|
|
28
|
+
remount(remounts.map((update) => Object.assign({ id: update.id }, update.remount)));
|
|
29
|
+
document.dispatchEvent(new CustomEvent("brumate:reload"));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
28
32
|
});
|
|
29
33
|
return (id) => {
|
|
30
34
|
const url = fresh.get(id);
|
package/dist/runtime/hot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hot.js","names":[],"sources":["../../src/runtime/hot.ts"],"sourcesContent":["// Hot updates on the dev server. When an edit of a component keeps its\n// markup, its slots and its update table, the plugin sends `brumate:update`\n// instead of reloading the page. New styles replace the old ones, and the\n// next event or update of the component loads its new code. State stays.\n//\n// When the markup changes, the page loads again through the client router,\n// and the signals of the component keep their values, by their names.\n\nimport type { ClientModule } from './client.ts';\n\n/** What `brumate:update` holds for each component that changed. */\nexport interface HotUpdate {\n id: string;\n /** The new styles, when they changed. */\n css?: string;\n /** The URL of the new client entry, when its code changed. */\n url?: string;\n /** Set when the markup changed, so the page renders again with the values of its signals. */\n remount?: Remount;\n}\n\n/** The slots of a component before and after an edit, by the ID of each scope in the component. */\nexport interface Remount {\n /** The names of the slots before the edit. */\n before: Record<number, string[]>;\n /** The names of the slots after the edit. */\n after: Record<number, string[]>;\n /** The names of the signals, whose values stay. */\n signals: string[];\n}\n\n/** The part of `import.meta.hot` that this module uses. */\nexport interface HotContext {\n on(\n event: 'brumate:update',\n listener: (data: { updates: HotUpdate[]; timestamp: number }) => void,\n ): void;\n}\n\n/**\n * Listens for updates of components, and returns a `load` for the loader\n * that loads the new code of a component that changed. Pass\n * `import.meta.hot`, which only the module that reads it gets.\n */\nexport function hotLoad(\n hot: HotContext | undefined,\n load: (id: string) => Promise<ClientModule>,\n): (id: string) => Promise<ClientModule> {\n if (!hot) {\n return load;\n }\n const fresh = new Map<string, string>();\n hot.on('brumate:update', ({ updates, timestamp }) => {\n const changed: string[] = [];\n for (const update of updates) {\n if (update.css !== undefined) {\n const style = document.querySelector(`style[
|
|
1
|
+
{"version":3,"file":"hot.js","names":[],"sources":["../../src/runtime/hot.ts"],"sourcesContent":["// Hot updates on the dev server. When an edit of a component keeps its\n// markup, its slots and its update table, the plugin sends `brumate:update`\n// instead of reloading the page. New styles replace the old ones, and the\n// next event or update of the component loads its new code. State stays.\n//\n// When the markup changes, the page loads again through the client router,\n// and the signals of the component keep their values, by their names.\n\nimport type { ClientModule } from './client.ts';\n\n/** What `brumate:update` holds for each component that changed. */\nexport interface HotUpdate {\n id: string;\n /** The new styles, when they changed. */\n css?: string;\n /** The URL of the new client entry, when its code changed. */\n url?: string;\n /** Set when the markup changed, so the page renders again with the values of its signals. */\n remount?: Remount;\n}\n\n/** The slots of a component before and after an edit, by the ID of each scope in the component. */\nexport interface Remount {\n /** The names of the slots before the edit. */\n before: Record<number, string[]>;\n /** The names of the slots after the edit. */\n after: Record<number, string[]>;\n /** The names of the signals, whose values stay. */\n signals: string[];\n}\n\n/** The part of `import.meta.hot` that this module uses. */\nexport interface HotContext {\n on(\n event: 'brumate:update',\n listener: (data: { updates: HotUpdate[]; timestamp: number }) => void,\n ): void;\n}\n\n/**\n * Listens for updates of components, and returns a `load` for the loader\n * that loads the new code of a component that changed. Pass\n * `import.meta.hot`, which only the module that reads it gets.\n */\nexport function hotLoad(\n hot: HotContext | undefined,\n load: (id: string) => Promise<ClientModule>,\n): (id: string) => Promise<ClientModule> {\n if (!hot) {\n return load;\n }\n const fresh = new Map<string, string>();\n hot.on('brumate:update', ({ updates, timestamp }) => {\n const changed: string[] = [];\n for (const update of updates) {\n if (update.css !== undefined) {\n const style = document.querySelector(`style[b-style=\"${CSS.escape(update.id)}\"]`);\n if (style) {\n style.textContent = update.css;\n }\n }\n if (update.url) {\n fresh.set(update.id, `${update.url}${update.url.includes('?') ? '&' : '?'}t=${timestamp}`);\n changed.push(update.id);\n }\n }\n if (changed.length > 0) {\n document.dispatchEvent(new CustomEvent('brumate:hot', { detail: changed }));\n }\n const remounts = updates.filter((update) => update.remount);\n if (changed.length === 0 && remounts.length === 0) {\n return;\n }\n // The core has the hot update code, which only this module calls, so builds leave it out.\n void import('./client.ts').then(({ forget, remount }) => {\n // The core forgets the old code of these components.\n forget(changed);\n if (remounts.length > 0) {\n // The core keeps the values of the signals, and the loader loads the page again.\n remount(remounts.map((update) => Object.assign({ id: update.id }, update.remount!)));\n document.dispatchEvent(new CustomEvent('brumate:reload'));\n }\n });\n });\n return (id) => {\n const url = fresh.get(id);\n return url ? (import(/* @vite-ignore */ url) as Promise<ClientModule>) : load(id);\n };\n}\n"],"mappings":";;;;;;AA4CA,SAAgB,QACd,KACA,MACuC;CACvC,IAAI,CAAC,KACH,OAAO;CAET,MAAM,wBAAQ,IAAI,IAAoB;CACtC,IAAI,GAAG,mBAAmB,EAAE,SAAS,gBAAgB;EACnD,MAAM,UAAoB,CAAC;EAC3B,KAAK,MAAM,UAAU,SAAS;GAC5B,IAAI,OAAO,QAAQ,KAAA,GAAW;IAC5B,MAAM,QAAQ,SAAS,cAAc,kBAAkB,IAAI,OAAO,OAAO,EAAE,EAAE,GAAG;IAChF,IAAI,OACF,MAAM,cAAc,OAAO;GAE/B;GACA,IAAI,OAAO,KAAK;IACd,MAAM,IAAI,OAAO,IAAI,GAAG,OAAO,MAAM,OAAO,IAAI,SAAS,GAAG,IAAI,MAAM,IAAI,IAAI,WAAW;IACzF,QAAQ,KAAK,OAAO,EAAE;GACxB;EACF;EACA,IAAI,QAAQ,SAAS,GACnB,SAAS,cAAc,IAAI,YAAY,eAAe,EAAE,QAAQ,QAAQ,CAAC,CAAC;EAE5E,MAAM,WAAW,QAAQ,QAAQ,WAAW,OAAO,OAAO;EAC1D,IAAI,QAAQ,WAAW,KAAK,SAAS,WAAW,GAC9C;EAGF,OAAY,cAAc,CAAC,MAAM,EAAE,QAAQ,cAAc;GAEvD,OAAO,OAAO;GACd,IAAI,SAAS,SAAS,GAAG;IAEvB,QAAQ,SAAS,KAAK,WAAW,OAAO,OAAO,EAAE,IAAI,OAAO,GAAG,GAAG,OAAO,OAAQ,CAAC,CAAC;IACnF,SAAS,cAAc,IAAI,YAAY,gBAAgB,CAAC;GAC1D;EACF,CAAC;CACH,CAAC;CACD,QAAQ,OAAO;EACb,MAAM,MAAM,MAAM,IAAI,EAAE;EACxB,OAAO,MAAO;;GAA0B;IAAiC,KAAK,EAAE;CAClF;AACF"}
|
package/dist/runtime/html.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as attribute, c as
|
|
2
|
-
export { Raw, VOID_ELEMENTS, actionAttributes, affix, attribute, attributeText, escape, escapeAttribute, insertValue, isRaw, raw, rawHTML, spread, styleElement, vars };
|
|
1
|
+
import { _ as textValue, a as attribute, c as classValue, d as insertValue, f as isRaw, g as styleElement, h as spread, i as affix, l as escape, m as rawHTML, n as VOID_ELEMENTS, o as attributeText, p as raw, r as actionAttributes, s as classAttribute, t as Raw, u as escapeAttribute, v as vars } from "../html-Du8jY2Cc.js";
|
|
2
|
+
export { Raw, VOID_ELEMENTS, actionAttributes, affix, attribute, attributeText, classAttribute, classValue, escape, escapeAttribute, insertValue, isRaw, raw, rawHTML, spread, styleElement, textValue, vars };
|
package/dist/runtime/html.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as VOID_ELEMENTS, n as actionAttributes, r as affix, i as attribute, a as attributeText, o as
|
|
1
|
+
export { t as VOID_ELEMENTS, n as actionAttributes, r as affix, i as attribute, a as attributeText, o as classAttribute, s as classValue, c as escape, l as escapeAttribute, u as insertValue, d as isRaw, f as raw, p as rawHTML, m as spread, h as styleElement, g as textValue, _ as vars } from "../html-DEeoepg3.js";
|
package/dist/runtime/loader.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
import { n as NavigateOptions,
|
|
2
|
-
|
|
1
|
+
import { n as NavigateOptions, t as LoaderOptions } from "../boot-DN1ZU8Hg.js";
|
|
2
|
+
import { t as startWithoutNavigation } from "../static-loader-BcFh4ebX.js";
|
|
3
|
+
//#region src/runtime/loader.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Starts resuming the page. Listens to the events in `b-on` attributes
|
|
6
|
+
* and loads `brumate/client` and the component's module on the first one.
|
|
7
|
+
* Returns a function that removes the listeners and stops the core.
|
|
8
|
+
*/
|
|
9
|
+
export declare function start(options: LoaderOptions): () => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { type LoaderOptions, type NavigateOptions, startWithoutNavigation };
|
|
12
|
+
//# sourceMappingURL=loader.d.ts.map
|
package/dist/runtime/loader.js
CHANGED
package/dist/runtime/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as attribute,
|
|
2
|
-
import { a as
|
|
1
|
+
import { a as attribute, h as spread, i as affix, l as escape, p as raw, s as classAttribute, t as Raw, u as escapeAttribute, v as vars } from "../html-Du8jY2Cc.js";
|
|
2
|
+
import { a as PageState, n as ElementReference, o as ScopeState, r as FunctionReference, t as produce } from "../produce-CtZ32UGG.js";
|
|
3
3
|
import { n as createContext } from "../context-aeo9esY9.js";
|
|
4
|
-
import { A as
|
|
5
|
-
export { Component, Context, type CookieOptions, DocumentOptions, ElementReference, type EndpointLoader, FunctionReference, type Handler, Lazy, type Loader, Memo, type Middleware, type MiddlewareLoader, NotReady, type PageState, type Raw, type Redirect, RenderOptions, RenderResult, RequestEvent, RequestOptions, type RouteMatch, type RouteNode, RouteOptions, type RouteView, type ScopeState, ServerError, type Session, type SessionOptions, StreamOptions, action, actionResult, affix, attribute, component, createContext, createSession, dedupe, dynamic, escape, escapeAttribute, getEvent, handleRequest, handleRoute, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, parseCookies, produce, raw, read, redirect, render, renderToStream, serializeCookie, spread, stateScript, streamParts, streamState, toNodeHeaders, vars, wait, withEvent };
|
|
4
|
+
import { $ as ServerError, A as stateScript, B as safeParse, C as lazy, D as ready, E as read, F as ValidationError, G as Middleware, H as EndpointLoader, I as ValidationIssue, J as RouteNode, K as MiddlewareLoader, L as fieldErrors, M as streamState, N as wait, O as render, P as ParseResult, Q as RequestEvent, R as parse, S as isCrossSite, T as packState, U as Handler, V as StandardSchemaV1, W as Loader, X as matchRoute, Y as RouteView, Z as Redirect, _ as component, a as Lazy, at as CookieOptions, b as handleRoute, c as NotReady, ct as createSession, d as RequestOptions, dt as toNodeHeaders, et as dedupe, f as RouteOptions, g as actionResult, h as action, i as ItemSource, it as withEvent, j as streamParts, k as renderToStream, l as RenderOptions, lt as parseCookies, m as StreamOptions, n as Context, nt as isRedirect, o as Mark, ot as Session, p as StateAttributes, q as RouteMatch, r as DocumentOptions, rt as redirect, s as Memo, st as SessionOptions, t as Component, tt as getEvent, u as RenderResult, ut as serializeCookie, v as dynamic, w as memo, x as insert, y as handleRequest, z as parseForm } from "../server-BxqjLUnV.js";
|
|
5
|
+
export { Component, Context, type CookieOptions, DocumentOptions, ElementReference, type EndpointLoader, FunctionReference, type Handler, ItemSource, Lazy, type Loader, Mark, Memo, type Middleware, type MiddlewareLoader, NotReady, type PageState, type ParseResult, type Raw, type Redirect, RenderOptions, RenderResult, RequestEvent, RequestOptions, type RouteMatch, type RouteNode, RouteOptions, type RouteView, type ScopeState, ServerError, type Session, type SessionOptions, type StandardSchemaV1, StateAttributes, StreamOptions, ValidationError, type ValidationIssue, action, actionResult, affix, attribute, classAttribute, component, createContext, createSession, dedupe, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, packState, parse, parseCookies, parseForm, produce, raw, read, ready, redirect, render, renderToStream, safeParse, serializeCookie, spread, stateScript, streamParts, streamState, toNodeHeaders, vars, wait, withEvent };
|
package/dist/runtime/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as FunctionReference, t as ElementReference } from "../shared-
|
|
3
|
-
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-
|
|
4
|
-
import {
|
|
1
|
+
import { _ as vars, c as escape, f as raw, i as attribute, l as escapeAttribute, m as spread, o as classAttribute, r as affix } from "../html-DEeoepg3.js";
|
|
2
|
+
import { n as FunctionReference, t as ElementReference } from "../shared-CWYOd0H3.js";
|
|
3
|
+
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-Av5WFmcf.js";
|
|
4
|
+
import { A as dedupe, C as fieldErrors, D as matchRoute, E as safeParse, M as isRedirect, N as redirect, O as RequestEvent, P as withEvent, S as ValidationError, T as parseForm, _ as renderToStream, a as component, b as streamState, c as handleRoute, d as lazy, f as memo, g as render, h as ready, i as actionResult, j as getEvent, k as ServerError, l as insert, m as read, n as NotReady, o as dynamic, p as packState, r as action, s as handleRequest, t as Context, u as isCrossSite, v as stateScript, w as parse, x as wait, y as streamParts } from "../server-DZsgnPKS.js";
|
|
5
5
|
import { t as produce } from "../produce-BRGHP7e0.js";
|
|
6
6
|
import { t as createContext } from "../context-BG8KCF3v.js";
|
|
7
|
-
export { Context, ElementReference, FunctionReference, NotReady, RequestEvent, ServerError, action, actionResult, affix, attribute, component, createContext, createSession, dedupe, dynamic, escape, escapeAttribute, getEvent, handleRequest, handleRoute, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, parseCookies, produce, raw, read, redirect, render, renderToStream, serializeCookie, spread, stateScript, streamParts, streamState, toNodeHeaders, vars, wait, withEvent };
|
|
7
|
+
export { Context, ElementReference, FunctionReference, NotReady, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, classAttribute, component, createContext, createSession, dedupe, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, packState, parse, parseCookies, parseForm, produce, raw, read, ready, redirect, render, renderToStream, safeParse, serializeCookie, spread, stateScript, streamParts, streamState, toNodeHeaders, vars, wait, withEvent };
|