brumate 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BvDsC6Qr.js +3463 -0
  7. package/dist/client-BvDsC6Qr.js.map +1 -0
  8. package/dist/client-DBwL2wKQ.d.ts +669 -0
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
  14. package/dist/defer-CKWZLv2K.js.map +1 -0
  15. package/dist/devtools-4uTPwR_v.js +597 -0
  16. package/dist/devtools-4uTPwR_v.js.map +1 -0
  17. package/dist/devtools-panel-Be9pxYgv.js +1994 -0
  18. package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
  19. package/dist/events-LgLdp1R7.js +114 -0
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-WW4RlajL.js +506 -0
  24. package/dist/files-WW4RlajL.js.map +1 -0
  25. package/dist/forms-j1xPAR14.d.ts +281 -0
  26. package/dist/forms-nXK7-Lv_.js +440 -0
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.d.ts +17 -0
  29. package/dist/highlight.js +278 -0
  30. package/dist/highlight.js.map +1 -0
  31. package/dist/html-BtKRyi7g.js +305 -0
  32. package/dist/html-BtKRyi7g.js.map +1 -0
  33. package/dist/html-Bw9Qwu6F.d.ts +107 -0
  34. package/dist/index.d.ts +142 -11
  35. package/dist/index.js +641 -106
  36. package/dist/index.js.map +1 -1
  37. package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
  38. package/dist/inspect-Y6y4uNZp.js.map +1 -0
  39. package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -14
  40. package/dist/loader-BjKGJzLN.js.map +1 -0
  41. package/dist/logo-DQ_OYhBi.js +10 -0
  42. package/dist/logo-DQ_OYhBi.js.map +1 -0
  43. package/dist/{navigate-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
  44. package/dist/navigate-CfOr-TRF.js.map +1 -0
  45. package/dist/nesting-DA5vJw9X.js +265 -0
  46. package/dist/nesting-DA5vJw9X.js.map +1 -0
  47. package/dist/produce-B7X9ori9.js +402 -0
  48. package/dist/produce-B7X9ori9.js.map +1 -0
  49. package/dist/produce-DIgHBVwL.d.ts +148 -0
  50. package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
  51. package/dist/rpc-Q-XkLwFh.js.map +1 -0
  52. package/dist/runtime/batch.js +9 -7
  53. package/dist/runtime/batch.js.map +1 -1
  54. package/dist/runtime/client.d.ts +4 -4
  55. package/dist/runtime/client.js +4 -4
  56. package/dist/runtime/devtools.d.ts +172 -5
  57. package/dist/runtime/devtools.js +3 -1
  58. package/dist/runtime/env.js +14 -2
  59. package/dist/runtime/env.js.map +1 -1
  60. package/dist/runtime/events.d.ts +38 -1
  61. package/dist/runtime/events.js +1 -1
  62. package/dist/runtime/forms.d.ts +2 -0
  63. package/dist/runtime/forms.js +1 -0
  64. package/dist/runtime/gather.d.ts +25 -0
  65. package/dist/runtime/gather.js +33 -0
  66. package/dist/runtime/gather.js.map +1 -0
  67. package/dist/runtime/hot.d.ts +1 -1
  68. package/dist/runtime/hot.js +5 -2
  69. package/dist/runtime/hot.js.map +1 -1
  70. package/dist/runtime/html.d.ts +2 -2
  71. package/dist/runtime/html.js +1 -1
  72. package/dist/runtime/loader.d.ts +2 -2
  73. package/dist/runtime/loader.js +2 -2
  74. package/dist/runtime/routes.js +4 -1
  75. package/dist/runtime/routes.js.map +1 -1
  76. package/dist/runtime/server.d.ts +5 -4
  77. package/dist/runtime/server.js +5 -5
  78. package/dist/runtime/signals.d.ts +75 -2
  79. package/dist/runtime/signals.js +44 -2
  80. package/dist/runtime/signals.js.map +1 -1
  81. package/dist/runtime/static-loader.d.ts +2 -2
  82. package/dist/runtime/static-loader.js +1 -1
  83. package/dist/runtime/testing.d.ts +18 -3
  84. package/dist/runtime/testing.js +150 -33
  85. package/dist/runtime/testing.js.map +1 -1
  86. package/dist/runtime/values.d.ts +2 -0
  87. package/dist/runtime/values.js +24 -0
  88. package/dist/runtime/values.js.map +1 -0
  89. package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
  90. package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
  91. package/dist/server-DjyOVJtJ.js.map +1 -0
  92. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
  93. package/dist/static-loader-BZR17hSw.js +312 -0
  94. package/dist/static-loader-BZR17hSw.js.map +1 -0
  95. package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
  96. package/dist/stream-BP5AVmg5.js.map +1 -0
  97. package/dist/values-B8C7CLvG.d.ts +63 -0
  98. package/dist/vite.d.ts +20 -20
  99. package/dist/vite.js +2031 -539
  100. package/dist/vite.js.map +1 -1
  101. package/elements.d.ts +951 -0
  102. package/forms/forms.brm.ts +141 -0
  103. package/package.json +41 -3
  104. package/skills/brumate/SKILL.md +58 -0
  105. package/skills/brumate/references/errors.md +2078 -0
  106. package/skills/brumate/references/events.md +117 -0
  107. package/skills/brumate/references/signals.md +61 -0
  108. package/skills/brumate/references/state.md +235 -0
  109. package/skills/brumate/references/syntax.md +250 -0
  110. package/types.d.ts +4 -4
  111. package/dist/client-C0UCNL3J.js +0 -1643
  112. package/dist/client-C0UCNL3J.js.map +0 -1
  113. package/dist/client-MD0ZmcFR.d.ts +0 -354
  114. package/dist/client-routes-JTbGtukf.js.map +0 -1
  115. package/dist/cookies-Av5WFmcf.js.map +0 -1
  116. package/dist/defer-D0bo1Gqx.js.map +0 -1
  117. package/dist/devtools-C50VH8gZ.js +0 -113
  118. package/dist/devtools-C50VH8gZ.js.map +0 -1
  119. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  120. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  121. package/dist/events-BKWRqtMg.js +0 -52
  122. package/dist/events-BKWRqtMg.js.map +0 -1
  123. package/dist/files-Bnn1JqHx.js +0 -192
  124. package/dist/files-Bnn1JqHx.js.map +0 -1
  125. package/dist/html-bHZbkK-h.js +0 -170
  126. package/dist/html-bHZbkK-h.js.map +0 -1
  127. package/dist/html-y1q7-t7D.d.ts +0 -60
  128. package/dist/inspect-BJtACnQp.js.map +0 -1
  129. package/dist/loader-B18i3_-T.js.map +0 -1
  130. package/dist/navigate-BwuZveDF.js.map +0 -1
  131. package/dist/produce-CWfJ4byV.js +0 -167
  132. package/dist/produce-CWfJ4byV.js.map +0 -1
  133. package/dist/produce-D4K7qpaL.d.ts +0 -72
  134. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  135. package/dist/server-BqfM95r1.js.map +0 -1
  136. package/dist/static-loader-DOygOFj5.js +0 -216
  137. package/dist/static-loader-DOygOFj5.js.map +0 -1
  138. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-C0UCNL3J.js","names":["id","spreadText"],"sources":["../src/runtime/client.ts"],"sourcesContent":["import { trustedHTML } from './trusted.ts';\nimport { loadOnce } from './skew.ts';\nimport {\n VOID_ELEMENTS,\n actionAttributes,\n attributeText,\n insertValue,\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 PREFIX,\n SOURCE,\n isAsyncIterable,\n parseId,\n stateValues,\n} from './shared.ts';\nimport type { PackedState, PageState, ScopeId, ScopeState } from './shared.ts';\nimport { ROUTE_KEY } from './context.ts';\nexport { navigationContext, routeContext } from './context.ts';\nimport type { Context as ContextValue, Route } from './context.ts';\n\nexport {\n affix,\n attribute,\n classAttribute,\n escape,\n mergeAttributes,\n raw,\n spread,\n vars,\n} 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 * The `#try` blocks that catch errors of client code, by the scope kinds\n * inside their bodies: the kind of the scope that holds the block, the\n * anchor of the block, the render functions of the body and the `#catch`\n * body, and the kinds of both bodies.\n */\n t?: Record<\n number,\n [owner: number, anchor: number, body: string, fallback: string, kinds: number[]]\n >;\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 /^[hct]\\d/.test(name) ? name : 'update';\n}\n\n/** The instance of a scope in the page. */\nexport interface Scope {\n id: ScopeId;\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, ScopeId>;\n /** The scope that rendered a component's root scope. */\n o?: Scope;\n /** For children that a component inserted, the scope where they are, for contexts. */\n t?: 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 /** The ID of the build of the page, for skew protection. Calls send it, and a deploy is noticed. */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads. `scope` is the ID of the scope\n * that the code belongs to, when it has one.\n */\n onError?: (error: unknown, info: { scope?: ScopeId }) => void;\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 ID of the build of the page, from the loader. Undefined on the dev server. */\nexport let build: string | undefined;\n\n/**\n * Tells the page that the site changed since it loaded: a call answered 409\n * with another build, or the code of a handler is gone. The loader then\n * loads the next page in full, and an app can save a draft first.\n */\nexport function skew(reason: 'call' | 'code' | 'defer'): void {\n document.dispatchEvent(new CustomEvent('brumate:skew', { detail: reason }));\n}\n/** The scopes of the page, by ID. */\nexport const scopes: Map<ScopeId, 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<ScopeId, 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: ScopeId, 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 ScopeId, group[at++] as number, flags & ITEM_SLOT]);\n }\n // Scopes inside a `#loading` body: their IDs are this prefix and a number.\n const prefix = flags & PREFIX ? (group[at++] as string) : '';\n const id = (n: number): ScopeId => (prefix ? prefix + n : 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 n = flags & (OWNER | PREFIX) ? 0 : base;\n while (at < group.length) {\n n += group[at++] as number;\n const s = group.slice(at - skip, (at += count - skip));\n const record: ScopeState = flags & OWNER ? { k, o: id(n - 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, ScopeId>;\n }\n state[id(n)] = 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 = parseId(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 if (record.t !== undefined) {\n scope.t = scopes.get(record.t);\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 renderedLoads.clear();\n for (const { timer } of timers.values()) {\n clearTimeout(timer);\n }\n timers.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 build = value.build;\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 watchTitles(document);\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 isTemplate(value.ref)\n ? templateReference(value.ref, scopes.get(value.scope))\n : (...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\n/** Waits forever once the page loads again, so no error shows before it goes. */\nlet reloading: Promise<never> | undefined;\n\nasync function resolve(ref: string): Promise<Handler> {\n const [id, name] = ref.split('#') as [string, string];\n try {\n const module = await loadModule(id);\n const part = await loadPart(module, partOf(name));\n return part[name] as Handler;\n } catch (error) {\n // After a deploy, the files of a build can be gone. The page loads again, with the new code,\n // once for each build. Any other error, such as a module that throws, goes to `#try`.\n const next = await serverBuild();\n if (!reloading && next !== undefined && loadOnce(next)) {\n skew('code');\n location.reload();\n reloading = new Promise(() => {});\n }\n if (reloading) {\n return reloading;\n }\n throw error;\n }\n}\n\n/**\n * Asks the server for its build, after the code of a handler failed to\n * load. Returns it when it is not the build of the page. Undefined without\n * a build, when the request fails, or when the builds are the same.\n */\nasync function serverBuild(): Promise<string | undefined> {\n if (build === undefined) {\n return undefined;\n }\n try {\n const response = await fetch(`${rpcPrefix}/`, {\n method: 'POST',\n headers: { 'x-brumate-build': build },\n });\n const current = response.headers.get('x-brumate-build');\n return current !== null && current !== build ? current : undefined;\n } catch {\n return undefined;\n }\n}\n\nasync function call(ref: string, scope: Scope | undefined, args: unknown[]): Promise<unknown> {\n return (await resolve(ref))(scope, ...args);\n}\n\n/** True for a reference to a `#template` that a component got as a prop, such as `Page#t3`. */\nfunction isTemplate(ref: string): boolean {\n return /#t\\d/.test(ref);\n}\n\n/** The code of templates that is still loading. Updates wait for it, since a render cannot. */\nconst loadingTemplates = new Set<Promise<unknown>>();\n\n/**\n * A `#template` of another component, which renders at once, as markup does.\n * Its code starts to load when the page state is read, and updates wait for it.\n */\nfunction templateReference(ref: string, scope: Scope | undefined): (...args: unknown[]) => unknown {\n let render: Handler | undefined;\n // A template that fails to load stops holding up updates too, and its error is reported.\n const code: Promise<unknown> = resolve(ref)\n .then((handler) => {\n render = handler;\n })\n .finally(() => loadingTemplates.delete(code));\n loadingTemplates.add(code);\n return (...args) => (render ? render(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, entry: string, event?: Event): Promise<unknown> {\n // A handler that a spread passed on, such as `Parent#h1@3`, runs in the scope of its owner.\n const [ref, owner] = entry.split('@') as [string, string | undefined];\n const anchor = owner ?? element.closest('[b-b]')?.getAttribute('b-b')?.split(':')[0];\n const scope = anchor ? scopes.get(parseId(anchor)) : 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 // An error of the handler, or of the promise that an async one returns, goes to the nearest\n // `#try` around its scope.\n return started\n .then((result) => result.value)\n .catch((error: unknown) => {\n fail(scope, error);\n });\n}\n\n/**\n * Reports an error of client code: a handler, an effect, a `$client`\n * callback or a memo that loads. It renders the `#catch` body of the nearest\n * `#try` around the scope of the code, through the parents and the owners of\n * scopes. Without one, the page gets a `brumate:error` event on `window`,\n * with the error and the scope, and the error is logged.\n */\nexport function fail(scope: Scope | undefined, error: unknown): void {\n options.onError?.(error, { scope: scope?.id });\n void (async () => {\n for (let current = scope; current; current = current.p ?? current.o) {\n const id = rootOf(current).m;\n if (!id) {\n continue;\n }\n // oxlint-disable-next-line no-await-in-loop -- Each scope can belong to another component.\n const module = await loadModule(id);\n const entry = module.t?.[current.k];\n if (!entry) {\n continue;\n }\n // The scope that holds the block, which the anchor of the block counts from.\n let owner = current.p;\n while (owner && owner.k !== entry[0]) {\n owner = owner.p;\n }\n if (owner) {\n // oxlint-disable-next-line no-await-in-loop -- The first `#try` found catches the error.\n await catchInto(owner, module, entry, error);\n return;\n }\n }\n window.dispatchEvent(new CustomEvent('brumate:error', { detail: { error, scope } }));\n console.error(error);\n })();\n}\n\n/** Renders the `#catch` body of a `#try` with an error, in place of what the block shows. */\nasync function catchInto(\n owner: Scope,\n module: ClientModule,\n [, anchor, , fallback, kinds]: NonNullable<ClientModule['t']>[number],\n error: unknown,\n): Promise<void> {\n const updates = await loadPart(module, 'update');\n const start = findComment(`b${owner.id}:${anchor}`);\n if (!start) {\n return;\n }\n const end = rangeEnd(start);\n disposeKinds(owner, kinds);\n clear(start, end);\n insertHTML(end, (updates[fallback] as (parent: Scope, error: unknown) => string)(owner, error));\n}\n\n/** Returns the instance of a scope by its ID. */\nexport function scopeOf(id: ScopeId): 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/** The timers of debounced and throttled memos, by `scope:slot`, with when each last computed. */\nconst timers = new Map<string, { timer?: ReturnType<typeof setTimeout>; last: number }>();\n\n/**\n * Computes a memo of `$debounced` after its value stops changing for `ms`,\n * or one of `$throttled` at most once every `ms`, with the last value after\n * the wait. The memo is pending while it waits.\n */\nexport function timed(\n scope: Scope,\n slot: number,\n ms: number,\n throttle: boolean,\n compute: () => unknown,\n): void {\n const key = `${scope.id}:${slot}`;\n const state = timers.get(key) ?? { last: -Infinity };\n timers.set(key, state);\n const run = (): void => {\n state.timer = undefined;\n state.last = Date.now();\n // A scope that left the page computes no more.\n if (scopes.get(scope.id) === scope) {\n memo(scope, slot, compute);\n }\n };\n const since = Date.now() - state.last;\n if (throttle && state.timer === undefined && since >= ms) {\n run();\n return;\n }\n if (!throttle) {\n clearTimeout(state.timer);\n state.timer = undefined;\n }\n state.timer ??= setTimeout(run, throttle ? ms - since : ms);\n startLoading(scope, slot, key);\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 failed = (error: unknown): void => {\n // A newer load of the memo aborted this one. The memo keeps its value, and the error goes\n // to the nearest `#try` around the memo.\n if (loads.get(key) === load) {\n fail(scope, 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 failed(error);\n }\n })();\n }, failed);\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 const rendered = scope.s[slot];\n if (renderedLoads.delete(key) && isThenable(rendered)) {\n asyncMemo(scope, slot, Promise.resolve(rendered));\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 && loadingTemplates.size === 0) {\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, and\n // for the templates that the updates can render.\n void loadModule(id).then(async (loaded) => {\n if (loaded.g[scope.k]?.[slot]) {\n const code = await loadPart(loaded, 'update');\n await Promise.allSettled(loadingTemplates);\n run(loaded, code, 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 clearTimeout(timers.get(key)?.timer);\n timers.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: ScopeId, 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 = trustedHTML(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 watchTitles(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<ScopeId>();\n for (const element of root.querySelectorAll('[b-b]')) {\n ids.add(parseId(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(parseId(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\n/** The attributes that the last update of a spread wrote, so the next one removes those it drops. */\nconst spreadNames = new WeakMap<Element, Set<string>>();\n\nexport function attrs(\n scope: Scope,\n anchor: number,\n values: Record<string, unknown>,\n own: string[] = [],\n): void {\n const element = findElement(scope.id, anchor);\n if (element) {\n // The first update in the browser takes the attributes that are not the element's own, nor\n // those of brumate, as the ones that the server's spread wrote.\n if (!spreadNames.has(element)) {\n spreadNames.set(\n element,\n new Set(\n element\n .getAttributeNames()\n .filter((name) => !own.includes(name) && !/^(b-|data-prefetch$)/.test(name)),\n ),\n );\n }\n const names = new Set<string>();\n for (const [name, value] of Object.entries(values)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n names.add(name);\n setAttribute(element, name, value);\n }\n }\n for (const name of spreadNames.get(element) ?? []) {\n if (!names.has(name)) {\n setAttribute(element, name, undefined);\n }\n }\n spreadNames.set(element, names);\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/**\n * Renders the body of a `#client` block once, in place of its fallback.\n * `kinds` are the scope IDs inside the fallback, whose instances go.\n */\nexport function fill(scope: Scope, anchor: number, render: Render, kinds: number[] = []): void {\n const start = findComment(`b${scope.id}:${anchor}`);\n // A block that rendered its body has a third number.\n if (!start || start.data.split(':').length > 2) {\n return;\n }\n start.data += ':1';\n const end = rangeEnd(start);\n disposeKinds(scope, kinds);\n clear(start, end);\n insertHTML(end, render(scope));\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(parseId(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(parseId(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 // Children that a component inserted find their contexts where they are, through `t`.\n for (\n let current: Scope | undefined = scope;\n current;\n current = current.t ?? current.p ?? current.o\n ) {\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 setTitle(value === null || value === undefined ? '' : String(value));\n}\n\n/**\n * Sets `document.title`, which writes the first `<title>` of the document.\n * The head gets a `<title>` of its own first, so a `<title>` in markup keeps its text.\n */\nfunction setTitle(text: string): void {\n if (!document.head.querySelector('title:not([b-t])')) {\n document.head.prepend(document.createElement('title'));\n }\n document.title = text;\n}\n\n/** Watches the `<title>` elements of markup, once one is in the page. */\nlet titleObserver: MutationObserver | undefined;\n\nconst PAGE_TITLE = 'title[b-t]';\n\n/** True when a node is or holds a `<title>` of markup. */\nfunction holdsTitle(node: Node): boolean {\n return node instanceof Element && (node.matches(PAGE_TITLE) || !!node.querySelector(PAGE_TITLE));\n}\n\n/** Gives the page the text of its last `<title>` in markup. Without one, the title stays. */\nfunction syncTitle(): void {\n const titles = document.querySelectorAll(PAGE_TITLE);\n const last = titles[titles.length - 1];\n if (last && document.title !== last.textContent) {\n setTitle(last.textContent ?? '');\n }\n}\n\n/**\n * Starts to follow the `<title>` elements of markup, when `root` has one. A\n * block that adds or removes one, or a change of its text, sets the title.\n */\nfunction watchTitles(root: ParentNode): void {\n if (titleObserver || !root.querySelector(PAGE_TITLE)) {\n return;\n }\n titleObserver = new MutationObserver((records) => {\n for (const record of records) {\n const target = record.target instanceof Element ? record.target : record.target.parentElement;\n if (\n target?.closest(PAGE_TITLE) ||\n [...record.addedNodes].some(holdsTitle) ||\n [...record.removedNodes].some(holdsTitle)\n ) {\n syncTitle();\n return;\n }\n }\n });\n titleObserver.observe(document, { childList: true, subtree: true, characterData: true });\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 let cleanup: unknown;\n try {\n cleanup = callback();\n } catch (error) {\n // The error goes to the nearest `#try` around the effect. The effect runs again on the next change.\n fail(scope, error);\n }\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, build);\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. Children render here, at `scope`, for their contexts. */\nexport function insert(value: unknown, _ctx?: unknown, scope?: Scope | ScopeId): string {\n return value instanceof Children ? value.render(resolveScope(scope)) : insertValue(value);\n}\n\n/** Children that render where they are inserted, and the scopes that they find contexts from. */\nconst insertedChildren: { from: Scope | undefined; at: Scope }[] = [];\n\n/**\n * Children of a component that the client renders. They render where the\n * component inserts them, so they read the contexts that it provides. `from`\n * is the scope of the markup that wrote them.\n */\nclass Children {\n private readonly from: Scope | undefined;\n private readonly html: () => string;\n\n constructor(from: Scope | ScopeId | undefined, html: () => string) {\n this.from = resolveScope(from);\n this.html = html;\n }\n\n render(at: Scope | undefined): string {\n if (!at) {\n return this.html();\n }\n const entry = { from: this.from, at };\n insertedChildren.push(entry);\n try {\n return this.html();\n } finally {\n insertedChildren.splice(insertedChildren.indexOf(entry), 1);\n }\n }\n}\n\n/** The children of a component that the client renders. See `Children`. */\nexport function children(from: Scope | ScopeId | undefined, html: () => string): Children {\n return new Children(from, html);\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 | ScopeId | undefined): Scope | undefined {\n return typeof scope === 'object' ? scope : scope === undefined ? undefined : scopes.get(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 inner: Raw | Children | undefined,\n _ctx?: unknown,\n scope?: Scope | number,\n): string {\n if (typeof tag === 'function') {\n return component(\n tag as Component,\n inner ? { ...attributes, children: inner } : attributes,\n undefined,\n scope,\n );\n }\n const name = String(tag);\n const open = `<${name}${spreadText(attributes)}>`;\n return VOID_ELEMENTS.has(name)\n ? open\n : `${open}${inner ? insert(inner, undefined, scope) : ''}</${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 | ScopeId, 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 // A scope at the top of children that are inserted elsewhere finds its contexts there.\n const up = created.o ?? parentScope;\n const inserted = insertedChildren.findLast((entry) => entry.from === up);\n if (inserted) {\n created.t = inserted.at;\n }\n parentScope?.children.add(created);\n treeChanges++;\n scopes.set(id, created);\n return id;\n}\n\n/**\n * The ID that `$id()` makes, as the server does. Client scope IDs are\n * negative, so they differ from the server's.\n */\nexport function makeId(scope: Scope | ScopeId, index: number): string {\n return `b${String(resolveScope(scope)!.id).replace(/\\./g, '_')}-${index}`;\n}\n\n/** Sets the owner of the next component's root scope. */\nexport function setOwner(scope: Scope | ScopeId): 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 | ScopeId): 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 | ScopeId,\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 if (provider) {\n return provider.v![context.key] as T;\n }\n if (context.key === ROUTE_KEY && !globals.has(ROUTE_KEY)) {\n globals.set(ROUTE_KEY, currentRoute());\n }\n return (globals.has(context.key) ? globals.get(context.key) : context.defaultValue) as T;\n}\n\n/** The values of the contexts that the runtime provides to the whole page, by key. */\nconst globals = new Map<string, unknown>();\n\n/** The route of the page: `location`, and the params of the route from the last page state. */\nfunction currentRoute(): Route {\n const records = document.querySelectorAll('script[b-state][b-params]');\n const params = records[records.length - 1]?.getAttribute('b-params');\n const url = new URL(location.href);\n return { url, search: url.searchParams, params: params ? JSON.parse(params) : {} };\n}\n\n/**\n * Writes a context that the runtime provides to the whole page, and the\n * slot of every scope that reads it without a provider above it.\n */\nexport function setGlobal(key: string, value: unknown): void {\n globals.set(key, value);\n for (const target of scopes.values()) {\n const slot = target.x?.[key];\n if (slot !== undefined && !findProvider(target, key)) {\n set(target, slot, value);\n }\n }\n}\n\n/** Reads the route of the page again, after navigation changed it. */\nexport function updateRoute(): void {\n setGlobal(ROUTE_KEY, currentRoute());\n}\n\n/**\n * Slots that the render of a component in the browser filled with a promise,\n * by `scope:slot`. The first compute of their memo takes that promise\n * instead of calling again, so a server function is called once per row.\n */\nconst renderedLoads = new Set<string>();\n\nexport function setSlots(id: ScopeId, values: unknown[]): void {\n scopes.get(id)!.s = values;\n // A render function computes a memo that loads as a promise, which the first compute of the\n // memo takes. Its failure is the memo's to report, not an unhandled rejection.\n values.forEach((value, slot) => {\n if (isThenable(value)) {\n renderedLoads.add(`${id}:${slot}`);\n Promise.resolve(value).catch(noop);\n }\n });\n}\n\nexport function setItem(id: ScopeId, value: unknown): void {\n scopes.get(id)!.i = value;\n}\n\nexport function elementAt(scope: ScopeId, anchor: number): ElementReference {\n return new ElementReference(scope, anchor);\n}\n\n/**\n * Warns in development that the browser renders a `#defer` block of a\n * component, such as inside a `#client` body of its parent. Only the server\n * renders the body, so the fallback stays.\n */\nexport function deferInBrowser(id: string): void {\n if (DEV) {\n console.warn(\n `${id} renders a #defer block in the browser, so it shows its fallback only. Render the component in markup that the server renders.`,\n );\n }\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 // A template renders at once, and the client has its code already.\n if (typeof value !== 'function' || isTemplate(ref)) {\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 setGlobal: typeof setGlobal;\n updateRoute: typeof updateRoute;\n} = { init, handle, dispose, submitAction, setGlobal, updateRoute };\n"],"mappings":";;;;;;AA8EA,SAAS,OAAO,MAAsB;CACpC,OAAO,WAAW,KAAK,IAAI,IAAI,OAAO;AACxC;AA0DA,IAAI;;AAEJ,IAAW,YAAY;;AAEvB,IAAW;;;;;;AAOX,SAAgB,KAAK,QAAyC;CAC5D,SAAS,cAAc,IAAI,YAAY,gBAAgB,EAAE,QAAQ,OAAO,CAAC,CAAC;AAC5E;;AAEA,MAAa,yBAA8B,IAAI,IAAI;;AAGnD,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,W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