@torpor/view 1.3.3 → 1.4.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.
Files changed (60) hide show
  1. package/dist/{Effect-Bp-BIDDm.d.cts → Effect-Bi_nt6cx.d.cts} +16 -3
  2. package/dist/Effect-Bi_nt6cx.d.cts.map +1 -0
  3. package/dist/{Effect-VsIY2vPx.d.mts → Effect-Bi_nt6cx.d.mts} +16 -3
  4. package/dist/Effect-Bi_nt6cx.d.mts.map +1 -0
  5. package/dist/ListItemSpec-DFkYr2TE.d.cts +28 -0
  6. package/dist/ListItemSpec-DFkYr2TE.d.cts.map +1 -0
  7. package/dist/ListItemSpec-DFkYr2TE.d.mts +28 -0
  8. package/dist/ListItemSpec-DFkYr2TE.d.mts.map +1 -0
  9. package/dist/{AsyncOptions-BDtArmeL.d.mts → WatchOptions--xq-Gn4e.d.cts} +77 -4
  10. package/dist/WatchOptions--xq-Gn4e.d.cts.map +1 -0
  11. package/dist/{AsyncOptions-C_7mWR6F.d.cts → WatchOptions-DWF4EqB6.d.mts} +77 -4
  12. package/dist/WatchOptions-DWF4EqB6.d.mts.map +1 -0
  13. package/dist/compile.cjs +1399 -406
  14. package/dist/compile.d.cts +26 -12
  15. package/dist/compile.d.cts.map +1 -1
  16. package/dist/compile.d.mts +26 -12
  17. package/dist/compile.d.mts.map +1 -1
  18. package/dist/compile.mjs +1399 -406
  19. package/dist/compile.mjs.map +1 -1
  20. package/dist/dev.cjs +101 -51
  21. package/dist/dev.d.cts +33 -2
  22. package/dist/dev.d.cts.map +1 -1
  23. package/dist/dev.d.mts +33 -2
  24. package/dist/dev.d.mts.map +1 -1
  25. package/dist/dev.mjs +51 -2
  26. package/dist/dev.mjs.map +1 -1
  27. package/dist/{fromWebSocket-ERhd9KZR.mjs → fromWebSocket-B22DIys7.mjs} +11 -2
  28. package/dist/fromWebSocket-B22DIys7.mjs.map +1 -0
  29. package/dist/{fromWebSocket-Cdoghvmh.cjs → fromWebSocket-C56rkQpZ.cjs} +15 -0
  30. package/dist/index.cjs +605 -266
  31. package/dist/index.d.cts +36 -129
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.mts +36 -129
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs +593 -255
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/runtime.iife.js +1 -1
  38. package/dist/ssr.cjs +122 -22
  39. package/dist/ssr.d.cts +46 -12
  40. package/dist/ssr.d.cts.map +1 -1
  41. package/dist/ssr.d.mts +46 -12
  42. package/dist/ssr.d.mts.map +1 -1
  43. package/dist/ssr.mjs +121 -23
  44. package/dist/ssr.mjs.map +1 -1
  45. package/dist/titleWarning-BMjLAXpn.mjs +72 -0
  46. package/dist/titleWarning-BMjLAXpn.mjs.map +1 -0
  47. package/dist/titleWarning-DXp4fK7q.cjs +87 -0
  48. package/package.json +2 -1
  49. package/dist/AsyncOptions-BDtArmeL.d.mts.map +0 -1
  50. package/dist/AsyncOptions-C_7mWR6F.d.cts.map +0 -1
  51. package/dist/Cleanup-D0wvGW5d.d.cts +0 -9
  52. package/dist/Cleanup-D0wvGW5d.d.cts.map +0 -1
  53. package/dist/Cleanup-D0wvGW5d.d.mts +0 -9
  54. package/dist/Cleanup-D0wvGW5d.d.mts.map +0 -1
  55. package/dist/Effect-Bp-BIDDm.d.cts.map +0 -1
  56. package/dist/Effect-VsIY2vPx.d.mts.map +0 -1
  57. package/dist/devContext-BulTn3U5.cjs +0 -27
  58. package/dist/devContext-ZNsPyOgB.mjs +0 -24
  59. package/dist/devContext-ZNsPyOgB.mjs.map +0 -1
  60. package/dist/fromWebSocket-ERhd9KZR.mjs.map +0 -1
package/dist/ssr.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.mjs","names":[],"sources":["../src/render/formatAttributeText.ts","../src/ssr/buildAttribute.ts","../src/ssr/formatText.ts","../src/ssr/buildClasses.ts","../src/ssr/buildStyles.ts","../src/ssr/slotGuard.ts","../src/ssr/$serverWatch.ts","../src/ssr/serverAwaitState.ts","../src/ssr/$serverAsync.ts","../src/ssr/$serverBatch.ts","../src/ssr/$serverBind.ts","../src/ssr/$serverCache.ts","../src/ssr/$serverOnmount.ts","../src/ssr/$serverPeek.ts","../src/ssr/$serverPending.ts","../src/ssr/$serverRefresh.ts","../src/ssr/$serverRun.ts","../src/ssr/$serverStream.ts","../src/ssr/$serverUnwrap.ts","../src/ssr/serverSentinels.ts","../src/ssr/runServerAwait.ts","../src/ssr/unavailable.ts"],"sourcesContent":["export default function formatAttributeText(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll('\"', \"&quot;\");\n}\n","import formatAttributeText from \"../render/formatAttributeText\";\n\n/**\n * Builds a `name=\"value\"` attribute for server-compiled code, dropping the\n * attribute entirely for `null`, `undefined` and `false` — matching the\n * client-side `t_attribute` — while an empty string or `0` still renders\n * (e.g. the meaningful `alt=\"\"`). The value is HTML-escaped. Exported as\n * `t_attr_if` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag.\n */\nexport default function buildServerAttribute(name: string, value: any): string {\n\tif (value == null || value === false) {\n\t\treturn \"\";\n\t}\n\treturn `${name}=\"${formatAttributeText(value)}\"`;\n}\n","import formatText from \"../render/formatText\";\n\nconst ESCAPABLE: Record<string, string> = {\n\t\"&\": \"&amp;\",\n\t\"<\": \"&lt;\",\n\t\">\": \"&gt;\",\n};\n\n/**\n * Formats a text value for inclusion in server-rendered HTML.\n *\n * Unlike the client version (which assigns to `textContent` and so needs no\n * escaping), the server interpolates values into an HTML string, so the\n * characters that would otherwise be parsed as markup are escaped here.\n */\nexport default function formatServerText(value: any): string {\n\treturn formatText(value).replace(/[&<>]/g, (c) => ESCAPABLE[c]);\n}\n","import type ClassValue from \"../types/ClassValue\";\nimport buildClasses from \"../render/buildClasses\";\n\n/**\n * Server counterpart of `render/buildClasses`: builds the class string and\n * wraps it in a `class=\"...\"` attribute, or returns `\"\"` when there are no\n * classes, so the attribute is omitted rather than rendered empty. Exported\n * as `t_class` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag.\n */\nexport default function buildServerClasses(value: ClassValue, styleHash?: string): string {\n\tconst classes = buildClasses(value, styleHash);\n\treturn classes === \"\" ? \"\" : `class=\"${classes}\"`;\n}\n","import type StyleValue from \"../types/StyleValue\";\nimport buildStyles from \"../render/buildStyles\";\n\n/**\n * Server counterpart of `render/buildStyles`: builds the style string and\n * wraps it in a `style=\"...\"` attribute, or returns `\"\"` when there are no\n * styles, so the attribute is omitted rather than rendered empty. Exported\n * as `t_style` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag.\n */\nexport default function buildServerStyles(value: StyleValue): string {\n\tconst styles = buildStyles(value);\n\treturn styles === \"\" ? \"\" : `style=\"${styles}\"`;\n}\n","import { autoCloseMessage, closesAncestor, firstElementTag } from \"../compile/utils/slotAutoClose\";\n\n/**\n * Server counterpart for generated slot regions whose wrapper the HTML\n * parser can auto-close (e.g. a `<slot>` inside `<li>`). Checks the rendered\n * fill content and throws when the parser would re-nest the region, so\n * broken shapes fail loudly at SSR instead of shipping markup hydration\n * can't adopt. Exported as `t_slot_guard` from `@torpor/view/ssr`.\n *\n * @param closeTags The slot's enclosing tags that some start tag can\n * auto-close (nearest last).\n * @param content The rendered fill content.\n * @param slotName The slot name, for the error message.\n */\nexport default function slotGuard(closeTags: string[], content: string, slotName: string): string {\n\tconst firstTag = firstElementTag(content);\n\tif (firstTag !== undefined && closesAncestor(firstTag, closeTags)) {\n\t\tconst ancestor = closeTags\n\t\t\t.slice()\n\t\t\t.reverse()\n\t\t\t.find((ancestor) => closesAncestor(firstTag, [ancestor]));\n\t\tthrow new Error(`Slot \"${slotName}\": ${autoCloseMessage(firstTag, ancestor ?? closeTags[0]!)}`);\n\t}\n\treturn content;\n}\n","/**\n * The identity of a `source: \"server\"` getter read: the watched object and the\n * property key being read. The server await state records reads by identity\n * (rather than position) so the render pass can read a getter a different\n * number of times than the collect pass did — e.g. when markup branches on the\n * resolved value.\n */\nexport interface ServerReadSite {\n\towner: object | null;\n\tkey: PropertyKey | string;\n}\n\nlet currentSite: ServerReadSite | null = null;\n\n/** The watched getter currently being read, or null outside a `$watch` get. */\nexport function currentServerReadSite(): ServerReadSite | null {\n\treturn currentSite;\n}\n\n/**\n * Server-render counterpart of `$watch`.\n *\n * State doesn't need to be reactive on the server, so values aren't wrapped\n * for tracking. Plain objects and arrays are wrapped in a lightweight proxy\n * that only records the property key while an accessor getter runs:\n * `$serverAsync` uses that to identify the getter site across the collect and\n * render passes. Other objects (Maps, class instances, …) are returned\n * untouched — proxying them would break internal slots or private fields, and\n * they rarely carry async getters.\n */\nexport default function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T {\n\tif (object === null || object === undefined) {\n\t\treturn object;\n\t}\n\tconst prototype = Object.getPrototypeOf(object);\n\tif (!Array.isArray(object) && prototype !== Object.prototype && prototype !== null) {\n\t\treturn object;\n\t}\n\n\treturn new Proxy(object, {\n\t\tget(target, key, receiver) {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\t\tif (descriptor?.get === undefined) {\n\t\t\t\treturn Reflect.get(target, key, receiver);\n\t\t\t}\n\t\t\tconst previous = currentSite;\n\t\t\tcurrentSite = { owner: target, key };\n\t\t\ttry {\n\t\t\t\treturn Reflect.get(target, key, receiver);\n\t\t\t} finally {\n\t\t\t\tcurrentSite = previous;\n\t\t\t}\n\t\t},\n\t});\n}\n","/**\n * The per-request state for a `source: \"server\"` async render. Server awaits\n * are orchestrated by `t_server_flush` (the component's render) and\n * `t_await_server` (each `@await` boundary), which coordinate through the\n * module-level `current` pointer:\n *\n * - **Collect phase** — the boundary's content is rendered speculatively (a\n * discarded pass) purely to invoke its getters. Each `source: \"server\"`\n * getter read calls its thunk (starting the fetch) and records the promise\n * here. Sibling reads in the same pass therefore start in one wave, exactly\n * like the client's speculative render.\n * - **Render phase** — after the recorded promises settle, the content is\n * rendered again; getter reads look up the settled value by getter identity\n * (watched object + property key), so the pass may read a getter a different\n * number of times than the collect pass did. The second pass's output is\n * what ships.\n *\n * `current` is only ever read synchronously (inside a helper's render\n * segments), so concurrent requests interleave safely: each helper captures\n * and restores the pointer around its awaits.\n */\nexport default interface ServerAwaitState {\n\t/** \"collect\" during the speculative pass, \"render\" during the resolved pass. */\n\tphase: \"collect\" | \"render\";\n\n\t/**\n\t * Recorded `source: \"server\"` reads, in first-read order. Each entry holds\n\t * the getter identity, the promise, its per-getter timeout, and — once\n\t * settled — the fulfilled value or rejection. A getter read more than once\n\t * is recorded once, so repeated reads share one fetch.\n\t */\n\tpromises: ServerPromiseEntry[];\n\n\t/**\n\t * Recorded reads made during the render pass, in first-read order. This is\n\t * the order the client will read the getters during hydration, so it also\n\t * determines the payload's value order.\n\t */\n\trenderEntries: ServerPromiseEntry[];\n\n\t/** Entries in `renderEntries`, for O(1) dedup while rendering. */\n\trenderSeen: Set<ServerPromiseEntry>;\n\n\t/**\n\t * Client-fetch `$async` reads made during the render pass (the server\n\t * stub's no-option calls). Any of these would suspend on the client, so a\n\t * boundary that touched one cannot ship resolved content — it degrades.\n\t */\n\tclientReads: number;\n\n\t/**\n\t * Nested boundary states created inside this boundary's collect pass,\n\t * keyed by `\"<site id>:<occurrence>\"`. The render pass re-invokes each\n\t * nested boundary in the same order, so it looks up the state by the same\n\t * key and awaits its final HTML instead of re-fetching.\n\t */\n\tchildren: Map<string, Promise<{ body: string; head: string }>>;\n\n\t/** Per-site occurrence counters, reset at the start of each pass. */\n\tcounters: Map<string, number>;\n\n\t/** Set when the boundary degrades to its `with` branch. */\n\tdegraded: boolean;\n\n\t/**\n\t * True for component flush roots. A flush root is a collect-phase context\n\t * but not a recording one: `source: \"server\"` reads outside any boundary\n\t * don't fetch. Boundaries created directly under the root stash their\n\t * final HTML here, keyed by the sentinel they returned.\n\t */\n\tisRoot: boolean;\n\n\t/**\n\t * Stashed boundary lifecycles keyed by sentinel comment, for substitution\n\t * at the end of the flush (or a degraded `with` branch's render). Only\n\t * used by flush roots.\n\t */\n\tsentinels: Map<string, Promise<{ body: string; head: string }>>;\n}\n\n/**\n * A recorded `source: \"server\"` read: the getter identity, the promise\n * returned by the getter's thunk, and the settled outcome once it arrives.\n */\nexport interface ServerPromiseEntry {\n\t/** The watched object (or null for an untracked getter). */\n\towner: object | null;\n\t/** The property key on `owner` (or the thunk source when untracked). */\n\tkey: PropertyKey | string;\n\tpromise: Promise<any>;\n\ttimeout: number;\n\t/** Set by the settle handler: `{ ok: true, value }` or `{ ok: false, error }`. */\n\tresult?: { ok: true; value: any } | { ok: false; error: any };\n}\n\n/**\n * The sentinel thrown when the render pass reads a `source: \"server\"` getter\n * that the collect pass never recorded (or one whose value hasn't settled).\n * Only this error degrades the boundary; real render errors propagate.\n */\nexport class ServerAwaitMisaligned extends Error {\n\tconstructor() {\n\t\tsuper(\"Server await render pass did not match the collect pass\");\n\t}\n}\n\n/** The innermost active server await state, or null outside any. */\nlet current: ServerAwaitState | null = null;\n\n/**\n * Runs `fn` with `state` as the current server await state. `fn` may be sync\n * or async; the pointer is restored when it settles. Because the pointer is\n * only read synchronously, interleaved async renders restore it correctly.\n */\nexport async function withServerAwait<T>(\n\tstate: ServerAwaitState | null,\n\tfn: () => T | Promise<T>,\n): Promise<T> {\n\tconst previous = current;\n\tcurrent = state;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\tcurrent = previous;\n\t}\n}\n\n/** The current server await state, or null. Only read synchronously. */\nexport function currentServerAwait(): ServerAwaitState | null {\n\treturn current;\n}\n\n/** Creates a fresh state for one boundary (or component flush root). */\nexport function newServerAwaitState(): ServerAwaitState {\n\treturn {\n\t\tphase: \"collect\",\n\t\tpromises: [],\n\t\trenderEntries: [],\n\t\trenderSeen: new Set(),\n\t\tclientReads: 0,\n\t\tchildren: new Map(),\n\t\tcounters: new Map(),\n\t\tdegraded: false,\n\t\tisRoot: false,\n\t\tsentinels: new Map(),\n\t};\n}\n\n/**\n * The occurrence key for a nested boundary call site: `\"<id>:<n>\"`. The\n * counter lives on the enclosing state and resets each pass, so the collect\n * and render passes derive identical key sequences.\n */\nexport function childKey(state: ServerAwaitState, id: string): string {\n\tconst n = state.counters.get(id) ?? 0;\n\tstate.counters.set(id, n + 1);\n\treturn `${id}:${n}`;\n}\n","import type AsyncOptions from \"../types/AsyncOptions\";\nimport { currentServerReadSite } from \"./$serverWatch\";\nimport type ServerAwaitState from \"./serverAwaitState\";\nimport {\n\tcurrentServerAwait,\n\tServerAwaitMisaligned,\n\ttype ServerPromiseEntry,\n} from \"./serverAwaitState\";\n\n/**\n * Default number of milliseconds a `source: \"server\"` read may take before\n * its boundary degrades to the `with` branch and the client fetches instead\n * (ASYNC.md → \"Server rendering\").\n */\nexport const SERVER_ASYNC_TIMEOUT = 5000;\n\n/**\n * Server counterpart of the client-side `$async` getter primitive.\n *\n * Without options (the default), this is a no-op stub: server renders are\n * synchronous, an async value never resolves during SSR, and `@await`\n * boundaries render their `with` branch and never read the getter. The stub\n * exists so server builds importing `$async` don't emit a dangling import.\n * A read inside a boundary's render pass is still recorded, so the boundary\n * degrades to the `with` branch + client fetch instead of shipping content\n * that would suspend on the client.\n *\n * With `{ source: \"server\" }` the getter participates in the server's\n * collect/render pass (ASYNC.md → \"Server rendering\"):\n *\n * - **Collect pass** — calls the thunk (starting the fetch) and records the\n * promise on the enclosing boundary, so sibling reads start in one wave.\n * The read is keyed by getter identity (watched object + property key), so\n * reading the same getter again reuses the recorded fetch. Returns\n * `undefined`; the speculative pass's output is discarded.\n * - **Render pass** — returns the settled value for the same getter identity,\n * without calling the thunk again. The pass may read a getter any number of\n * times, so markup may branch on the resolved value. A rejection is\n * re-thrown here so `@try`/`@error` handles it like any other render error.\n * Reading a getter the collect pass never touched throws a sentinel that\n * degrades the boundary (its value can't be resolved without fetching, and\n * the shipped HTML can't be trusted).\n *\n * Outside any `@await` boundary (including in a `with` branch) a\n * `source: \"server\"` read returns `undefined` without fetching — the same\n * undefined-then-recover contract the client has for un-boundaried reads.\n */\nexport default function $serverAsync<T>(\n\tfn: (serverValue?: T) => Promise<T>,\n\toptions?: AsyncOptions,\n): T {\n\tconst state = currentServerAwait();\n\n\tif (state === null || state.isRoot || options?.source !== \"server\") {\n\t\tif (state !== null && !state.isRoot && state.phase === \"render\") {\n\t\t\t// A client-fetch read during a boundary's render pass: the client\n\t\t\t// will suspend on it, so the boundary can't ship resolved content\n\t\t\tstate.clientReads++;\n\t\t}\n\t\treturn undefined as T;\n\t}\n\n\t// Identity captured before the thunk runs: reads inside the thunk (e.g.\n\t// `$state.id`) must not be mistaken for the getter being read here\n\tconst site = currentServerReadSite();\n\tconst owner = site?.owner ?? null;\n\tconst key = site?.key ?? fn.toString();\n\n\tif (state.phase === \"collect\") {\n\t\t// A repeated read of the same getter shares the first fetch\n\t\tconst existing = findEntry(state, owner, key);\n\t\tif (existing === undefined) {\n\t\t\tconst entry: ServerPromiseEntry = {\n\t\t\t\towner,\n\t\t\t\tkey,\n\t\t\t\tpromise: fn(),\n\t\t\t\ttimeout: options.timeout ?? SERVER_ASYNC_TIMEOUT,\n\t\t\t};\n\t\t\t// Record the outcome as soon as it settles — this both captures the\n\t\t\t// value/error for the render pass and consumes the rejection, so a\n\t\t\t// boundary that degrades (timeout) or a superseded fetch can never\n\t\t\t// surface as an unhandled rejection\n\t\t\tentry.promise.then(\n\t\t\t\t(value) => {\n\t\t\t\t\tentry.result = { ok: true, value };\n\t\t\t\t},\n\t\t\t\t(error) => {\n\t\t\t\t\tentry.result = { ok: false, error };\n\t\t\t\t},\n\t\t\t);\n\t\t\tstate.promises.push(entry);\n\t\t}\n\t\treturn undefined as T;\n\t}\n\n\t// Render pass: look the recorded read up by getter identity\n\tconst entry = findEntry(state, owner, key);\n\tif (entry === undefined) {\n\t\tthrow new ServerAwaitMisaligned();\n\t}\n\tif (!state.renderSeen.has(entry)) {\n\t\tstate.renderSeen.add(entry);\n\t\tstate.renderEntries.push(entry);\n\t}\n\tconst result = entry.result;\n\tif (result === undefined) {\n\t\t// Not settled — only possible when the boundary already blew its\n\t\t// timeout, which degrades before rendering; treat as misaligned\n\t\tthrow new ServerAwaitMisaligned();\n\t}\n\tif (result.ok) {\n\t\treturn result.value as T;\n\t}\n\tthrow result.error;\n}\n\nfunction findEntry(\n\tstate: ServerAwaitState,\n\towner: object | null,\n\tkey: PropertyKey | string,\n): ServerPromiseEntry | undefined {\n\tfor (const entry of state.promises) {\n\t\tif (entry.owner === owner && entry.key === key) {\n\t\t\treturn entry;\n\t\t}\n\t}\n\treturn undefined;\n}\n","export default function $serverBatch<T>(fn: () => T): T {\n\treturn fn();\n}\n","/**\n * Server no-op for the client-side `$bind` two-way sync primitive. Two-way\n * binding is a client runtime feature — there are no reactive updates during\n * SSR, so there is nothing to sync. The stub exists so server builds\n * importing `$bind` don't emit a dangling import.\n */\nexport default function $serverBind(\n\t_state: Record<PropertyKey, any>,\n\t_props: Record<PropertyKey, any> | undefined,\n\t..._keys: (string | string[])[]\n): void {}\n","export default function $serverCache<T>(fn: () => T): T {\n\treturn fn();\n}\n","import type Cleanup from \"../types/Cleanup\";\n\nexport default function $serverOnmount(_fn: () => Cleanup | void): void {}\n","export default function $serverPeek<T>(fn: () => T): T {\n\treturn fn();\n}\n","/**\n * Server no-op for the client-side `$pending` query. Nothing is ever pending\n * during a synchronous SSR render, so the query is always `false`. The stub\n * exists so server builds importing `$pending` don't emit a dangling import.\n */\nexport default function $serverPending(_fn: () => any): boolean {\n\treturn false;\n}\n","/**\n * Server no-op for the client-side `$refresh` primitive. A refresh is an\n * imperative action that never runs during SSR. The stub exists so server\n * builds importing `$refresh` don't emit a dangling import.\n */\nexport default function $serverRefresh(_fn: () => any): void {}\n","import type Cleanup from \"../types/Cleanup\";\n\nexport default function $serverRun(_fn: () => Cleanup | void): void {}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Server stub for `$stream` — external sources are never subscribed to\n * during a server render. The subscription starts when the component is\n * mounted on the client.\n */\nexport default function $serverStream<T>(\n\t_source: StreamSource<T>,\n\t_handler: (value: T) => void,\n\t_options?: { debounce?: number },\n): void {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","import { newServerAwaitState, withServerAwait } from \"./serverAwaitState\";\nimport type ServerAwaitState from \"./serverAwaitState\";\n\n/** Comment prefix marking an unsubstituted boundary sentinel. */\nexport const SENTINEL_PREFIX = \"<!--t-aw:\";\n\n/** The body/head pair that server components and boundaries render into. */\nexport interface ServerHtml {\n\tbody: string;\n\thead: string;\n}\n\n/**\n * Renders a component's (or a degraded boundary's `with` branch's) markup\n * with a fresh flush root as the enclosing await state, then substitutes any\n * boundary sentinels with their final HTML.\n *\n * Boundaries created during the render stash their lifecycle promise under a\n * sentinel comment and return the sentinel immediately, so the render itself\n * never blocks on a fetch — every `source: \"server\"` read in the render\n * starts in the same wave. Substitution awaits the stashed promises at the\n * end, which is the only point an async component render actually waits.\n *\n * On the client this has no counterpart: `render` here is the compiled\n * component body closure that the generated component function returns.\n */\nexport async function serverFlush(render: () => Promise<ServerHtml>): Promise<ServerHtml> {\n\tconst state = newServerAwaitState();\n\tstate.isRoot = true;\n\tconst result = await withServerAwait(state, render);\n\treturn substituteSentinels(result, state);\n}\n\n/**\n * Renders a degraded boundary's `with` branch inside its own flush root, so\n * a `with` branch containing its own `@await` boundaries still resolves\n * them, then wraps it in the boundary's hydration markers. The `with` branch\n * must not start server fetches for its own reads — the flush root isn't a\n * recording context.\n */\nexport async function renderWithBranch(\n\trenderWith: (() => Promise<ServerHtml>) | null,\n): Promise<ServerHtml> {\n\tconst html = await serverFlush(async () => {\n\t\tif (renderWith === null) {\n\t\t\treturn { body: \"\", head: \"\" };\n\t\t}\n\t\treturn renderWith();\n\t});\n\treturn { body: `<![>${html.body}<!]><!>`, head: html.head };\n}\n\n/**\n * Replaces every sentinel the state stashed with its boundary's final HTML.\n * Boundary head tags are appended to the head (they hoist into the document\n * head regardless of where the boundary sits in the body). Any sentinel left\n * over means a boundary's state was lost — a bug, not a degradation path, so\n * it throws.\n */\nexport async function substituteSentinels(\n\tresult: ServerHtml,\n\tstate: ServerAwaitState,\n): Promise<ServerHtml> {\n\tlet { body, head } = result;\n\tfor (const [sentinel, promise] of state.sentinels) {\n\t\tconst html = await promise;\n\t\tbody = body.split(sentinel).join(html.body);\n\t\thead += html.head;\n\t}\n\tif (body.includes(SENTINEL_PREFIX) || head.includes(SENTINEL_PREFIX)) {\n\t\tthrow new Error(\"Unsubstituted async boundary sentinel — boundary state was lost\");\n\t}\n\treturn { body, head };\n}\n","import {\n\tchildKey,\n\tcurrentServerAwait,\n\tnewServerAwaitState,\n\tServerAwaitMisaligned,\n\twithServerAwait,\n} from \"./serverAwaitState\";\nimport type ServerAwaitState from \"./serverAwaitState\";\nimport { renderWithBranch } from \"./serverSentinels\";\n\nlet sentinelCount = 0;\n\nfunction nextSentinel(): string {\n\treturn `<!--t-aw:${sentinelCount++}-->`;\n}\n\n/**\n * Renders an `@await` boundary on the server (compiled as `t_await_server`).\n *\n * The generated code calls this for every `@await`, passing the boundary's\n * site id, a closure that renders the content branch, and one that renders\n * the `with` branch. It always returns a `{ body, head }` pair to append:\n *\n * - **Inside a boundary's render pass** — this boundary was already started\n * during the collect pass; its body/head is the finished HTML (awaited if\n * still in flight). A missing entry means the render pass doesn't match\n * the collect pass, which degrades the enclosing boundary.\n * - **Inside a collect pass or a component flush** — start the full\n * lifecycle (collect, settle, render) without blocking the enclosing\n * render, and return a sentinel comment as the body. Sibling reads and\n * nested boundaries keep rendering, so every fetch in the pass starts in\n * one wave. The sentinel is substituted later: by the enclosing boundary's\n * render pass (which re-invokes this helper and awaits the finished HTML),\n * or by the component flush (which replaces top-level sentinels directly).\n *\n * The lifecycle: render content once to start the `source: \"server\"` fetches\n * (discarding the output), wait for them with a per-getter timeout, then\n * render again with the settled values. Reads are matched by getter identity,\n * so the render pass may read a getter more than once (e.g. branch on it).\n * The second pass ships wrapped in hydration markers plus a\n * `<!--t-await:...-->` comment carrying the values for the client's `$async`\n * hydration path. Any instability — timeout, a render pass that reads a getter\n * the collect pass never touched, a client-fetch read — degrades to the `with`\n * branch + client fetch, exactly the pre-`source` behavior.\n *\n * @param id The boundary's site id (unique per `@await` in the component)\n * @param renderContent Renders the content branch (may read `$async` getters)\n * @param renderWith Renders the `with` branch, or null for empty\n */\nexport default function runServerAwait(\n\tid: string,\n\trenderContent: () => Promise<{ body: string; head: string }>,\n\trenderWith: (() => Promise<{ body: string; head: string }>) | null,\n): { body: string; head: string } | Promise<{ body: string; head: string }> {\n\tconst parent = currentServerAwait();\n\n\tif (parent !== null && parent.phase === \"render\") {\n\t\t// The enclosing boundary is rendering its resolved pass: this nested\n\t\t// boundary was started during the collect pass, so reuse its result\n\t\tconst cached = parent.children.get(childKey(parent, id));\n\t\tif (cached === undefined) {\n\t\t\tthrow new ServerAwaitMisaligned();\n\t\t}\n\t\treturn cached;\n\t}\n\n\tconst state = newServerAwaitState();\n\tconst final = renderBoundary(state, renderContent, renderWith);\n\n\tconst sentinel = nextSentinel();\n\tif (parent !== null) {\n\t\tif (parent.isRoot) {\n\t\t\t// Top-level boundary: the component flush substitutes the sentinel\n\t\t\tparent.sentinels.set(sentinel, final);\n\t\t} else {\n\t\t\t// Nested boundary: the enclosing boundary's render pass looks this\n\t\t\t// up by occurrence key\n\t\t\tparent.children.set(childKey(parent, id), final);\n\t\t}\n\t}\n\t// The sentinel body is replaced by the finished content; the head tags a\n\t// resolved boundary renders are hoisted when it finishes\n\treturn { body: sentinel, head: \"\" };\n}\n\n/**\n * The full lifecycle for one boundary: speculative collect pass, settle, and\n * resolved render pass. Runs concurrently with the enclosing render; the\n * returned promise resolves to the boundary's final HTML.\n */\nasync function renderBoundary(\n\tstate: ServerAwaitState,\n\trenderContent: () => Promise<{ body: string; head: string }>,\n\trenderWith: (() => Promise<{ body: string; head: string }>) | null,\n): Promise<{ body: string; head: string }> {\n\t// Collect pass: render content speculatively to invoke the getters. Each\n\t// `source: \"server\"` read starts its fetch and is recorded; sibling reads\n\t// in this pass therefore start together. The output is discarded — reads\n\t// return undefined, so user markup that dereferences them may throw, and\n\t// a throw here costs nothing.\n\tawait withServerAwait(state, renderContent).catch(() => {\n\t\t// Expected when unresolved values are dereferenced; fetches already\n\t\t// started. Any other error resurfaces in the render pass below.\n\t});\n\n\tif (state.promises.length === 0) {\n\t\t// No server-source reads: nothing was (or can be) resolved here, so\n\t\t// ship the `with` branch and let the client fetch — the default SSR\n\t\t// behavior for client-fetch getters\n\t\treturn renderWithBranch(renderWith);\n\t}\n\n\t// Settle the recorded fetches. Each getter carries its own timeout; the\n\t// boundary waits for the longest, and a miss degrades the whole boundary\n\t// (content ships only when every read resolved)\n\tconst timeout = Math.max(...state.promises.map((entry) => entry.timeout));\n\tconst settled = await Promise.race([\n\t\tPromise.all(\n\t\t\tstate.promises.map((entry) =>\n\t\t\t\tentry.promise.then(\n\t\t\t\t\t() => true,\n\t\t\t\t\t() => true,\n\t\t\t\t),\n\t\t\t),\n\t\t).then(\n\t\t\t() => true,\n\t\t\t() => true,\n\t\t),\n\t\tnew Promise<false>((resolve) => setTimeout(resolve, timeout, false)),\n\t]);\n\n\t// Render pass: same reads, now looking settled values up by getter\n\t// identity. The pass may read a getter more than once (markup can branch\n\t// on its value), but every read must have been recorded by the collect\n\t// pass. A read the collect pass never touched, a client-fetch read, or a\n\t// render error means the content can't be trusted, and the boundary\n\t// degrades.\n\t//\n\t// A rejection (or any render error) also degrades: the boundary's\n\t// lifecycle runs detached from the enclosing render (which has already\n\t// moved on after the sentinel), so the error can't propagate to the\n\t// emitted `@try` positionally. Instead the with branch ships and the\n\t// client re-runs the getter, rejects there, and its `@try` renders the\n\t// catch branch — the same path a client-fetch error takes.\n\tlet degraded = settled === false;\n\tlet content: { body: string; head: string } | undefined;\n\tif (!degraded) {\n\t\tstate.phase = \"render\";\n\t\tstate.renderEntries.length = 0;\n\t\tstate.renderSeen.clear();\n\t\tstate.clientReads = 0;\n\t\tstate.counters.clear();\n\t\ttry {\n\t\t\tcontent = await withServerAwait(state, renderContent);\n\t\t\tif (state.clientReads > 0) {\n\t\t\t\tdegraded = true;\n\t\t\t}\n\t\t} catch {\n\t\t\tdegraded = true;\n\t\t}\n\t}\n\n\tif (degraded || content === undefined) {\n\t\tstate.degraded = true;\n\t\ttry {\n\t\t\treturn await renderWithBranch(renderWith);\n\t\t} catch {\n\t\t\t// A with-branch render error can't be positioned either; ship an\n\t\t\t// empty boundary rather than failing the whole response\n\t\t\treturn { body: \"<![><!]><!>\", head: \"\" };\n\t\t}\n\t}\n\n\t// Ship the resolved content with the embedded values for hydration.\n\t// Rejections never reach here — the render pass consumes them and\n\t// degrades — but guard anyway so a bad entry can't ship as `undefined`\n\tconst values: any[] = [];\n\tfor (const entry of state.renderEntries) {\n\t\tconst result = entry.result;\n\t\tif (result === undefined) {\n\t\t\tdegraded = true;\n\t\t\tbreak;\n\t\t}\n\t\tvalues.push(result.ok ? result.value : undefined);\n\t}\n\tif (degraded) {\n\t\tstate.degraded = true;\n\t\treturn renderWithBranch(renderWith);\n\t}\n\treturn {\n\t\tbody: `${\"<![>\"}${content.body}${\"<!]><!>\"}${payloadComment(values)}`,\n\t\thead: content.head,\n\t};\n}\n\n/**\n * The `<!--t-await:...-->` comment carrying the boundary's resolved values,\n * in the order the render pass first read them, for the client's `$async`\n * hydration path. `-->` inside the JSON is escaped so the comment can't\n * terminate early.\n */\nfunction payloadComment(values: any[]): string {\n\tconst json = JSON.stringify(values).replaceAll(\"-->\", \"--\\\\u003E\");\n\treturn `<!--t-await:${json}-->`;\n}\n","/**\n * Server stubs for the client-only runtime, so that modules compiled for the\n * client -- or shared helpers that import them from the main `@torpor/view`\n * entry -- still resolve when they end up in a server bundle (the SSR\n * environment resolves `@torpor/view` to this module; see @torpor/build's\n * ssr-view plugin).\n *\n * They throw when called: mounting, hydrating and DOM rendering must not run\n * during SSR. Importing them is fine, which keeps a stray client-only import\n * from failing the server build.\n */\ntype Unavailable = (...args: unknown[]) => never;\n\nfunction unavailable(name: string): Unavailable {\n\treturn (..._args: unknown[]): never => {\n\t\tthrow new Error(`${name} is not available during server rendering`);\n\t};\n}\n\nexport const mount: Unavailable = unavailable(\"mount\");\nexport const hydrate: Unavailable = unavailable(\"hydrate\");\nexport const unmount: Unavailable = unavailable(\"unmount\");\nexport const fillLayoutSlot: Unavailable = unavailable(\"fillLayoutSlot\");\nexport const clearLayoutSlot: Unavailable = unavailable(\"clearLayoutSlot\");\n\nexport const t_add_element: Unavailable = unavailable(\"t_add_element\");\nexport const t_add_fragment: Unavailable = unavailable(\"t_add_fragment\");\nexport const t_anchor: Unavailable = unavailable(\"t_anchor\");\nexport const t_animate: Unavailable = unavailable(\"t_animate\");\nexport const t_apply_props: Unavailable = unavailable(\"t_apply_props\");\nexport const t_attribute: Unavailable = unavailable(\"t_attribute\");\nexport const t_child: Unavailable = unavailable(\"t_child\");\nexport const t_dynamic: Unavailable = unavailable(\"t_dynamic\");\nexport const t_event: Unavailable = unavailable(\"t_event\");\nexport const t_first_inside: Unavailable = unavailable(\"t_first_inside\");\nexport const t_fragment: Unavailable = unavailable(\"t_fragment\");\nexport const t_fragment_el: Unavailable = unavailable(\"t_fragment_el\");\nexport const t_head_element: Unavailable = unavailable(\"t_head_element\");\nexport const t_list_item: Unavailable = unavailable(\"t_list_item\");\nexport const t_next: Unavailable = unavailable(\"t_next\");\nexport const t_pop_region: Unavailable = unavailable(\"t_pop_region\");\nexport const t_push_region: Unavailable = unavailable(\"t_push_region\");\nexport const t_region: Unavailable = unavailable(\"t_region\");\nexport const t_rerun_region_effects: Unavailable = unavailable(\"t_rerun_region_effects\");\nexport const t_restore_hydration: Unavailable = unavailable(\"t_restore_hydration\");\nexport const t_root: Unavailable = unavailable(\"t_root\");\nexport const t_root_el: Unavailable = unavailable(\"t_root_el\");\nexport const t_run_await: Unavailable = unavailable(\"t_run_await\");\nexport const t_run_branch: Unavailable = unavailable(\"t_run_branch\");\nexport const t_run_control: Unavailable = unavailable(\"t_run_control\");\nexport const t_run_list: Unavailable = unavailable(\"t_run_list\");\nexport const t_run_try: Unavailable = unavailable(\"t_run_try\");\nexport const t_save_hydration: Unavailable = unavailable(\"t_save_hydration\");\nexport const t_skip: Unavailable = unavailable(\"t_skip\");\n"],"mappings":";;;AAAA,SAAwB,oBAAoB,OAAoB;CAC/D,QAAQ,SAAS,GAAA,CAAI,SAAS,CAAC,CAAC,WAAW,MAAK,QAAQ;AACzD;;;;;;;;;;;ACQA,SAAwB,qBAAqB,MAAc,OAAoB;CAC9E,IAAI,SAAS,QAAQ,UAAU,OAC9B,OAAO;CAER,OAAO,GAAG,KAAK,IAAI,oBAAoB,KAAK,EAAE;AAC/C;;;ACbA,MAAM,YAAoC;CACzC,KAAK;CACL,KAAK;CACL,KAAK;AACN;;;;;;;;AASA,SAAwB,iBAAiB,OAAoB;CAC5D,OAAO,WAAW,KAAK,CAAC,CAAC,QAAQ,WAAW,MAAM,UAAU,EAAE;AAC/D;;;;;;;;;;ACPA,SAAwB,mBAAmB,OAAmB,WAA4B;CACzF,MAAM,UAAU,aAAa,OAAO,SAAS;CAC7C,OAAO,YAAY,KAAK,KAAK,UAAU,QAAQ;AAChD;;;;;;;;;;ACHA,SAAwB,kBAAkB,OAA2B;CACpE,MAAM,SAAS,YAAY,KAAK;CAChC,OAAO,WAAW,KAAK,KAAK,UAAU,OAAO;AAC9C;;;;;;;;;;;;;;;ACCA,SAAwB,UAAU,WAAqB,SAAiB,UAA0B;CACjG,MAAM,WAAW,gBAAgB,OAAO;CACxC,IAAI,aAAa,KAAA,KAAa,eAAe,UAAU,SAAS,GAAG;EAClE,MAAM,WAAW,UACf,MAAM,CAAC,CACP,QAAQ,CAAC,CACT,MAAM,aAAa,eAAe,UAAU,CAAC,QAAQ,CAAC,CAAC;EACzD,MAAM,IAAI,MAAM,SAAS,SAAS,KAAK,iBAAiB,UAAU,YAAY,UAAU,EAAG,GAAG;CAC/F;CACA,OAAO;AACR;;;ACZA,IAAI,cAAqC;;AAG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S;AACzD,MAAa,iBAA8B,YAAY,gBAAgB;AACvE,MAAa,aAA0B,YAAY,YAAY;AAC/D,MAAa,gBAA6B,YAAY,eAAe;AACrE,MAAa,iBAA8B,YAAY,gBAAgB;AACvE,MAAa,cAA2B,YAAY,aAAa;AACjE,MAAa,SAAsB,YAAY,QAAQ;AACvD,MAAa,eAA4B,YAAY,cAAc;AACnE,MAAa,gBAA6B,YAAY,eAAe;AACrE,MAAa,WAAwB,YAAY,UAAU;AAC3D,MAAa,yBAAsC,YAAY,wBAAwB;AACvF,MAAa,sBAAmC,YAAY,qBAAqB;AACjF,MAAa,SAAsB,YAAY,QAAQ;AACvD,MAAa,YAAyB,YAAY,WAAW;AAC7D,MAAa,cAA2B,YAAY,aAAa;AACjE,MAAa,eAA4B,YAAY,cAAc;AACnE,MAAa,gBAA6B,YAAY,eAAe;AACrE,MAAa,aAA0B,YAAY,YAAY;AAC/D,MAAa,YAAyB,YAAY,WAAW;AAC7D,MAAa,mBAAgC,YAAY,kBAAkB;AAC3E,MAAa,SAAsB,YAAY,QAAQ"}
1
+ {"version":3,"file":"ssr.mjs","names":[],"sources":["../src/ssr/escape.ts","../src/render/formatAttributeText.ts","../src/ssr/buildAttribute.ts","../src/ssr/formatText.ts","../src/ssr/buildClasses.ts","../src/ssr/buildStyles.ts","../src/ssr/slotGuard.ts","../src/ssr/$serverWatch.ts","../src/ssr/serverAwaitState.ts","../src/ssr/$serverAsync.ts","../src/ssr/$serverBatch.ts","../src/ssr/$serverBind.ts","../src/ssr/$serverCache.ts","../src/ssr/$serverOnmount.ts","../src/ssr/$serverPeek.ts","../src/ssr/$serverPending.ts","../src/ssr/$serverRefresh.ts","../src/ssr/$serverRun.ts","../src/ssr/$serverStream.ts","../src/ssr/$serverUnwrap.ts","../src/ssr/renderContext.ts","../src/ssr/serverSentinels.ts","../src/ssr/runServerAwait.ts","../src/ssr/unavailable.ts"],"sourcesContent":["import formatText from \"../render/formatText\";\n\n/**\n * The single place the server-side escaping rules live.\n *\n * Client helpers assign to `textContent`/`setAttribute`, so they need no\n * escaping; everything that interpolates into a server-rendered HTML string\n * goes through one of these two functions instead.\n */\n\nconst TEXT_ESCAPES: Record<string, string> = {\n\t\"&\": \"&amp;\",\n\t\"<\": \"&lt;\",\n\t\">\": \"&gt;\",\n};\n\n/**\n * Escapes a value for HTML text content: `&`, `<` and `>` could otherwise be\n * parsed as markup. Values are formatted with the shared `formatText` first\n * (null/undefined become `\"\"`, proxies are unwrapped).\n */\nexport function escapeText(value: any): string {\n\treturn formatText(value).replace(/[&<>]/g, (c) => TEXT_ESCAPES[c]);\n}\n\n/**\n * Escapes a value for a double-quoted HTML attribute. `&` is escaped first,\n * so literal entity text in a value (`a&quot;b`) survives the browser's\n * decoding unchanged, then `\"` so the value can't close the attribute.\n */\nexport function escapeAttribute(value: any): string {\n\treturn (value ?? \"\").toString().replaceAll(\"&\", \"&amp;\").replaceAll('\"', \"&quot;\");\n}\n","import { escapeAttribute } from \"../ssr/escape\";\n\n/**\n * Formats a value for inclusion in a double-quoted HTML attribute in\n * server-rendered markup. The escaping rules (and why `&` goes first) live in\n * `ssr/escape.ts`.\n *\n * Exported as `t_attr` from `@torpor/view/ssr`, so generated server code can\n * use it for interpolated attribute values; the other server helpers\n * (`ssr/buildAttribute`, `ssr/buildClasses`, `ssr/buildStyles`) use\n * `escapeAttribute` directly.\n */\nexport default function formatAttributeText(value: any): string {\n\treturn escapeAttribute(value);\n}\n","import { escapeAttribute } from \"./escape\";\n\n/**\n * Builds a `name=\"value\"` attribute for server-compiled code, dropping the\n * attribute entirely for `null`, `undefined` and `false` — matching the\n * client-side `t_attribute` — while an empty string or `0` still renders\n * (e.g. the meaningful `alt=\"\"`). The value is HTML-escaped. Exported as\n * `t_attr_if` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag.\n */\nexport default function buildServerAttribute(name: string, value: any): string {\n\tif (value == null || value === false) {\n\t\treturn \"\";\n\t}\n\treturn `${name}=\"${escapeAttribute(value)}\"`;\n}\n","import { escapeText } from \"./escape\";\n\n/**\n * Formats a text value for inclusion in server-rendered HTML.\n *\n * Unlike the client version (which assigns to `textContent` and so needs no\n * escaping), the server interpolates values into an HTML string, so the\n * characters that would otherwise be parsed as markup are escaped here — the\n * rules live in `ssr/escape.ts`.\n */\nexport default function formatServerText(value: any): string {\n\treturn escapeText(value);\n}\n","import type ClassValue from \"../types/ClassValue\";\nimport buildClasses from \"../render/buildClasses\";\nimport { escapeAttribute } from \"./escape\";\n\n/**\n * Server counterpart of `render/buildClasses`: builds the class string and\n * wraps it in a `class=\"...\"` attribute, or returns `\"\"` when there are no\n * classes, so the attribute is omitted rather than rendered empty. Exported\n * as `t_class` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag. The value is\n * HTML-escaped, so a class name can't break out of the attribute.\n */\nexport default function buildServerClasses(value: ClassValue, styleHash?: string): string {\n\tconst classes = buildClasses(value, styleHash);\n\treturn classes === \"\" ? \"\" : `class=\"${escapeAttribute(classes)}\"`;\n}\n","import type StyleValue from \"../types/StyleValue\";\nimport buildStyles from \"../render/buildStyles\";\nimport { escapeAttribute } from \"./escape\";\n\n/**\n * Server counterpart of `render/buildStyles`: builds the style string and\n * wraps it in a `style=\"...\"` attribute, or returns `\"\"` when there are no\n * styles, so the attribute is omitted rather than rendered empty. Exported\n * as `t_style` from `@torpor/view/ssr` — the only way server-compiled code\n * uses it is to interpolate the attribute into a tag. The value is\n * HTML-escaped, so a style value can't break out of the attribute.\n */\nexport default function buildServerStyles(value: StyleValue): string {\n\tconst styles = buildStyles(value);\n\treturn styles === \"\" ? \"\" : `style=\"${escapeAttribute(styles)}\"`;\n}\n","import { autoCloseMessage, closesAncestor, firstElementTag } from \"../compile/utils/slotAutoClose\";\n\n/**\n * Server counterpart for generated slot regions whose wrapper the HTML\n * parser can auto-close (e.g. a `<slot>` inside `<li>`). Checks the rendered\n * fill content and throws when the parser would re-nest the region, so\n * broken shapes fail loudly at SSR instead of shipping markup hydration\n * can't adopt. Exported as `t_slot_guard` from `@torpor/view/ssr`.\n *\n * @param closeTags The slot's enclosing tags that some start tag can\n * auto-close (nearest last).\n * @param content The rendered fill content.\n * @param slotName The slot name, for the error message.\n */\nexport default function slotGuard(closeTags: string[], content: string, slotName: string): string {\n\tconst firstTag = firstElementTag(content);\n\tif (firstTag !== undefined && closesAncestor(firstTag, closeTags)) {\n\t\tconst ancestor = closeTags\n\t\t\t.slice()\n\t\t\t.reverse()\n\t\t\t.find((ancestor) => closesAncestor(firstTag, [ancestor]));\n\t\tthrow new Error(`Slot \"${slotName}\": ${autoCloseMessage(firstTag, ancestor ?? closeTags[0]!)}`);\n\t}\n\treturn content;\n}\n","import type WatchOptions from \"../types/WatchOptions\";\n\n/**\n * The identity of a `source: \"server\"` getter read: the watched object and the\n * property key being read. The server await state records reads by identity\n * (rather than position) so the render pass can read a getter a different\n * number of times than the collect pass did — e.g. when markup branches on the\n * resolved value.\n */\nexport interface ServerReadSite {\n\towner: object | null;\n\tkey: PropertyKey | string;\n}\n\nlet currentSite: ServerReadSite | null = null;\n\n/** The watched getter currently being read, or null outside a `$watch` get. */\nexport function currentServerReadSite(): ServerReadSite | null {\n\treturn currentSite;\n}\n\n/**\n * Server-render counterpart of `$watch`.\n *\n * State doesn't need to be reactive on the server, so values aren't wrapped\n * for tracking. Plain objects and arrays are wrapped in a lightweight proxy\n * that only records the property key while an accessor getter runs:\n * `$serverAsync` uses that to identify the getter site across the collect and\n * render passes. Other objects (Maps, class instances, …) are returned\n * untouched — proxying them would break internal slots or private fields, and\n * they rarely carry async getters.\n */\nexport default function $serverWatch<T extends object>(object: T, _options?: WatchOptions): T {\n\tif (object === null || object === undefined) {\n\t\treturn object;\n\t}\n\tconst prototype = Object.getPrototypeOf(object);\n\tif (!Array.isArray(object) && prototype !== Object.prototype && prototype !== null) {\n\t\treturn object;\n\t}\n\n\treturn new Proxy(object, {\n\t\tget(target, key, receiver) {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\t\tif (descriptor?.get === undefined) {\n\t\t\t\treturn Reflect.get(target, key, receiver);\n\t\t\t}\n\t\t\tconst previous = currentSite;\n\t\t\tcurrentSite = { owner: target, key };\n\t\t\ttry {\n\t\t\t\treturn Reflect.get(target, key, receiver);\n\t\t\t} finally {\n\t\t\t\tcurrentSite = previous;\n\t\t\t}\n\t\t},\n\t});\n}\n","/**\n * The per-request state for a `source: \"server\"` async render. Server awaits\n * are orchestrated by `t_server_flush` (the component's render) and\n * `t_await_server` (each `@await` boundary), which coordinate through the\n * module-level `current` pointer:\n *\n * - **Collect phase** — the boundary's content is rendered speculatively (a\n * discarded pass) purely to invoke its getters. Each `source: \"server\"`\n * getter read calls its thunk (starting the fetch) and records the promise\n * here. Sibling reads in the same pass therefore start in one wave, exactly\n * like the client's speculative render.\n * - **Render phase** — after the recorded promises settle, the content is\n * rendered again; getter reads look up the settled value by getter identity\n * (watched object + property key), so the pass may read a getter a different\n * number of times than the collect pass did. The second pass's output is\n * what ships.\n *\n * `current` is only ever read synchronously (inside a helper's render\n * segments), so concurrent requests interleave safely: each helper captures\n * and restores the pointer around its awaits.\n */\nexport default interface ServerAwaitState {\n\t/** \"collect\" during the speculative pass, \"render\" during the resolved pass. */\n\tphase: \"collect\" | \"render\";\n\n\t/**\n\t * Recorded `source: \"server\"` reads, in first-read order. Each entry holds\n\t * the getter identity, the promise, its per-getter timeout, and — once\n\t * settled — the fulfilled value or rejection. A getter read more than once\n\t * is recorded once, so repeated reads share one fetch.\n\t */\n\tpromises: ServerPromiseEntry[];\n\n\t/**\n\t * Recorded reads made during the render pass, in first-read order. This is\n\t * the order the client will read the getters during hydration, so it also\n\t * determines the payload's value order.\n\t */\n\trenderEntries: ServerPromiseEntry[];\n\n\t/** Entries in `renderEntries`, for O(1) dedup while rendering. */\n\trenderSeen: Set<ServerPromiseEntry>;\n\n\t/**\n\t * Client-fetch `$async` reads made during the render pass (the server\n\t * stub's no-option calls). Any of these would suspend on the client, so a\n\t * boundary that touched one cannot ship resolved content — it degrades.\n\t */\n\tclientReads: number;\n\n\t/**\n\t * Nested boundary states created inside this boundary's collect pass,\n\t * keyed by `\"<site id>:<occurrence>\"`. The render pass re-invokes each\n\t * nested boundary in the same order, so it looks up the state by the same\n\t * key and awaits its final HTML instead of re-fetching.\n\t */\n\tchildren: Map<string, Promise<{ body: string; head: string }>>;\n\n\t/** Per-site occurrence counters, reset at the start of each pass. */\n\tcounters: Map<string, number>;\n\n\t/**\n\t * When the server render started (from `Date.now()`). Read timeouts count\n\t * from it, so a boundary that starts late gets only what's left.\n\t */\n\tstartedAt: number;\n\n\t/** Set when the boundary degrades to its `with` branch. */\n\tdegraded: boolean;\n\n\t/**\n\t * True for component flush roots. A flush root is a collect-phase context\n\t * but not a recording one: `source: \"server\"` reads outside any boundary\n\t * don't fetch. Boundaries created directly under the root stash their\n\t * final HTML here, keyed by the sentinel they returned.\n\t */\n\tisRoot: boolean;\n\n\t/**\n\t * Stashed boundary lifecycles keyed by sentinel comment, for substitution\n\t * at the end of the flush (or a degraded `with` branch's render). Only\n\t * used by flush roots.\n\t */\n\tsentinels: Map<string, Promise<{ body: string; head: string }>>;\n}\n\n/**\n * A recorded `source: \"server\"` read: the getter identity, the promise\n * returned by the getter's thunk, and the settled outcome once it arrives.\n */\nexport interface ServerPromiseEntry {\n\t/** The watched object (or null for an untracked getter). */\n\towner: object | null;\n\t/** The property key on `owner` (or the thunk source when untracked). */\n\tkey: PropertyKey | string;\n\tpromise: Promise<any>;\n\t/** How long (ms) after the render started the read may settle. */\n\ttimeout: number;\n\t/** Set by the settle handler: `{ ok: true, value }` or `{ ok: false, error }`. */\n\tresult?: { ok: true; value: any } | { ok: false; error: any };\n}\n\n/**\n * The sentinel thrown when the render pass reads a `source: \"server\"` getter\n * that the collect pass never recorded (or one whose value hasn't settled).\n * Only this error degrades the boundary; real render errors propagate.\n */\nexport class ServerAwaitMisaligned extends Error {\n\tconstructor() {\n\t\tsuper(\"Server await render pass did not match the collect pass\");\n\t}\n}\n\n/** The innermost active server await state, or null outside any. */\nlet current: ServerAwaitState | null = null;\n\n/**\n * Runs `fn` with `state` as the current server await state. `fn` may be sync\n * or async; the pointer is restored when it settles. Because the pointer is\n * only read synchronously, interleaved async renders restore it correctly.\n */\nexport async function withServerAwait<T>(\n\tstate: ServerAwaitState | null,\n\tfn: () => T | Promise<T>,\n): Promise<T> {\n\tconst previous = current;\n\tcurrent = state;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\tcurrent = previous;\n\t}\n}\n\n/** The current server await state, or null. Only read synchronously. */\nexport function currentServerAwait(): ServerAwaitState | null {\n\treturn current;\n}\n\n/** Creates a fresh state for one boundary (or component flush root). */\nexport function newServerAwaitState(): ServerAwaitState {\n\treturn {\n\t\tphase: \"collect\",\n\t\tpromises: [],\n\t\trenderEntries: [],\n\t\trenderSeen: new Set(),\n\t\tclientReads: 0,\n\t\tchildren: new Map(),\n\t\tcounters: new Map(),\n\t\tstartedAt: Date.now(),\n\t\tdegraded: false,\n\t\tisRoot: false,\n\t\tsentinels: new Map(),\n\t};\n}\n\n/**\n * The occurrence key for a nested boundary call site: `\"<id>:<n>\"`. The\n * counter lives on the enclosing state and resets each pass, so the collect\n * and render passes derive identical key sequences.\n */\nexport function childKey(state: ServerAwaitState, id: string): string {\n\tconst n = state.counters.get(id) ?? 0;\n\tstate.counters.set(id, n + 1);\n\treturn `${id}:${n}`;\n}\n","import type AsyncOptions from \"../types/AsyncOptions\";\nimport { currentServerReadSite } from \"./$serverWatch\";\nimport type ServerAwaitState from \"./serverAwaitState\";\nimport {\n\tcurrentServerAwait,\n\tServerAwaitMisaligned,\n\ttype ServerPromiseEntry,\n} from \"./serverAwaitState\";\n\n/**\n * Default number of milliseconds a `source: \"server\"` read may take before\n * its boundary degrades to the `with` branch and the client fetches instead\n * (ASYNC.md → \"Server rendering\").\n */\nexport const SERVER_ASYNC_TIMEOUT = 5000;\n\n/**\n * Server counterpart of the client-side `$async` getter primitive.\n *\n * Without options (the default), this is a no-op stub: server renders are\n * synchronous, an async value never resolves during SSR, and `@await`\n * boundaries render their `with` branch and never read the getter. The stub\n * exists so server builds importing `$async` don't emit a dangling import.\n * A read inside a boundary's render pass is still recorded, so the boundary\n * degrades to the `with` branch + client fetch instead of shipping content\n * that would suspend on the client.\n *\n * With `{ source: \"server\" }` the getter participates in the server's\n * collect/render pass (ASYNC.md → \"Server rendering\"):\n *\n * - **Collect pass** — calls the thunk (starting the fetch) and records the\n * promise on the enclosing boundary, so sibling reads start in one wave.\n * The read is keyed by getter identity (watched object + property key), so\n * reading the same getter again reuses the recorded fetch. Returns\n * `undefined`; the speculative pass's output is discarded.\n * - **Render pass** — returns the settled value for the same getter identity,\n * without calling the thunk again. The pass may read a getter any number of\n * times, so markup may branch on the resolved value. A rejection is\n * re-thrown here so `@try`/`@error` handles it like any other render error.\n * Reading a getter the collect pass never touched throws a sentinel that\n * degrades the boundary (its value can't be resolved without fetching, and\n * the shipped HTML can't be trusted).\n *\n * Outside any `@await` boundary (including in a `with` branch) a\n * `source: \"server\"` read returns `undefined` without fetching — the same\n * undefined-then-recover contract the client has for un-boundaried reads.\n */\nexport default function $serverAsync<T>(\n\tfn: (serverValue?: T) => Promise<T>,\n\toptions?: AsyncOptions,\n): T {\n\tconst state = currentServerAwait();\n\n\tif (state === null || state.isRoot || options?.source !== \"server\") {\n\t\tif (state !== null && !state.isRoot && state.phase === \"render\") {\n\t\t\t// A client-fetch read during a boundary's render pass: the client\n\t\t\t// will suspend on it, so the boundary can't ship resolved content\n\t\t\tstate.clientReads++;\n\t\t}\n\t\treturn undefined as T;\n\t}\n\n\t// Identity captured before the thunk runs: reads inside the thunk (e.g.\n\t// `$state.id`) must not be mistaken for the getter being read here\n\tconst site = currentServerReadSite();\n\tconst owner = site?.owner ?? null;\n\tconst key = site?.key ?? fn.toString();\n\n\tif (state.phase === \"collect\") {\n\t\t// A repeated read of the same getter shares the first fetch\n\t\tconst existing = findEntry(state, owner, key);\n\t\tif (existing === undefined) {\n\t\t\tconst entry: ServerPromiseEntry = {\n\t\t\t\towner,\n\t\t\t\tkey,\n\t\t\t\tpromise: fn(),\n\t\t\t\ttimeout: options.timeout ?? SERVER_ASYNC_TIMEOUT,\n\t\t\t};\n\t\t\t// Record the outcome as soon as it settles — this both captures the\n\t\t\t// value/error for the render pass and consumes the rejection, so a\n\t\t\t// boundary that degrades (timeout) or a superseded fetch can never\n\t\t\t// surface as an unhandled rejection\n\t\t\tentry.promise.then(\n\t\t\t\t(value) => {\n\t\t\t\t\tentry.result = { ok: true, value };\n\t\t\t\t},\n\t\t\t\t(error) => {\n\t\t\t\t\tentry.result = { ok: false, error };\n\t\t\t\t},\n\t\t\t);\n\t\t\tstate.promises.push(entry);\n\t\t}\n\t\treturn undefined as T;\n\t}\n\n\t// Render pass: look the recorded read up by getter identity\n\tconst entry = findEntry(state, owner, key);\n\tif (entry === undefined) {\n\t\tthrow new ServerAwaitMisaligned();\n\t}\n\tif (!state.renderSeen.has(entry)) {\n\t\tstate.renderSeen.add(entry);\n\t\tstate.renderEntries.push(entry);\n\t}\n\tconst result = entry.result;\n\tif (result === undefined) {\n\t\t// Not settled — only possible when the boundary already blew its\n\t\t// timeout, which degrades before rendering; treat as misaligned\n\t\tthrow new ServerAwaitMisaligned();\n\t}\n\tif (result.ok) {\n\t\treturn result.value as T;\n\t}\n\tthrow result.error;\n}\n\nfunction findEntry(\n\tstate: ServerAwaitState,\n\towner: object | null,\n\tkey: PropertyKey | string,\n): ServerPromiseEntry | undefined {\n\tfor (const entry of state.promises) {\n\t\tif (entry.owner === owner && entry.key === key) {\n\t\t\treturn entry;\n\t\t}\n\t}\n\treturn undefined;\n}\n","export default function $serverBatch<T>(fn: () => T): T {\n\treturn fn();\n}\n","/**\n * Server no-op for the client-side `$bind` two-way sync primitive. Two-way\n * binding is a client runtime feature — there are no reactive updates during\n * SSR, so there is nothing to sync. The stub exists so server builds\n * importing `$bind` don't emit a dangling import.\n */\nexport default function $serverBind(\n\t_state: Record<PropertyKey, any>,\n\t_props: Record<PropertyKey, any> | undefined,\n\t..._keys: (string | string[])[]\n): void {}\n","export default function $serverCache<T>(fn: () => T): T {\n\treturn fn();\n}\n","import type Cleanup from \"../types/Cleanup\";\n\nexport default function $serverOnmount(_fn: () => Cleanup | void): void {}\n","export default function $serverPeek<T>(fn: () => T): T {\n\treturn fn();\n}\n","/**\n * Server no-op for the client-side `$pending` query. Nothing is ever pending\n * during a synchronous SSR render, so the query is always `false`. The stub\n * exists so server builds importing `$pending` don't emit a dangling import.\n */\nexport default function $serverPending(_fn: () => any): boolean {\n\treturn false;\n}\n","import type { RefreshOptions } from \"../watch/$refresh\";\n\n/**\n * Server no-op for the client-side `$refresh` primitive. A refresh is an\n * imperative action that never runs during SSR. The stub exists so server\n * builds importing `$refresh` don't emit a dangling import, and its signature\n * matches the client primitive exactly (see\n * `test/types/server-twin-signatures.test.ts`).\n */\nexport default function $serverRefresh(_fn: () => any, _options?: RefreshOptions): void {}\n","import type Cleanup from \"../types/Cleanup\";\nimport type Effect from \"../types/Effect\";\n\n/**\n * Server no-op for the client-side `$run` primitive. Effects never run during\n * SSR, but the stub signature matches the client primitive exactly (so the two\n * can't drift — see `test/types/server-twin-signatures.test.ts`). The returned\n * `Effect` is never meaningful here, because nothing is created.\n */\nexport default function $serverRun(\n\t_fn: () => Cleanup | void,\n\t_name?: string,\n\t_options?: Pick<Effect, \"isMountEffect\" | \"forVarMask\">,\n): Effect {\n\treturn undefined as unknown as Effect;\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Server stub for `$stream` — external sources are never subscribed to\n * during a server render. The subscription starts when the component is\n * mounted on the client.\n */\nexport default function $serverStream<T>(\n\t_source: StreamSource<T>,\n\t_handler: (value: T) => void,\n\t_options?: { debounce?: number },\n): void {}\n","export default function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object;\n}\n","/**\n * The `$context` key holding the time (from `Date.now()`) a server render\n * started. `source: \"server\"` `$async` timeouts count from it, so nested\n * boundaries -- which only start once the boundary around them has resolved\n * -- share one time limit rather than each adding its own wait to the\n * response.\n */\nconst RENDER_STARTED: unique symbol = Symbol.for(\"torp.RenderStarted\");\n\n/**\n * Returns the context for a server component's render (compiled as\n * `t_render_context`). The component at the root of a render stamps the\n * start time into a copy of the context it was given, so the caller's object\n * isn't changed and a later render with the same context starts afresh; its\n * descendants receive the stamped context and keep it.\n */\nexport function renderContext(\n\tcontext: Record<PropertyKey, any> | undefined,\n): Record<PropertyKey, any> {\n\tif (context?.[RENDER_STARTED] !== undefined) {\n\t\treturn context;\n\t}\n\treturn { ...context, [RENDER_STARTED]: Date.now() };\n}\n\n/**\n * The time the server render started, or now when the context wasn't\n * stamped (e.g. code compiled before the stamp existed).\n */\nexport function renderStarted(context: Record<PropertyKey, any> | undefined): number {\n\treturn context?.[RENDER_STARTED] ?? Date.now();\n}\n","import { newServerAwaitState, withServerAwait } from \"./serverAwaitState\";\nimport type ServerAwaitState from \"./serverAwaitState\";\n\n/** Comment prefix marking an unsubstituted boundary sentinel. */\nexport const SENTINEL_PREFIX = \"<!--t-aw:\";\n\n/** The body/head pair that server components and boundaries render into. */\nexport interface ServerHtml {\n\tbody: string;\n\thead: string;\n}\n\n/**\n * Renders a component's (or a degraded boundary's `with` branch's) markup\n * with a fresh flush root as the enclosing await state, then substitutes any\n * boundary sentinels with their final HTML.\n *\n * Boundaries created during the render stash their lifecycle promise under a\n * sentinel comment and return the sentinel immediately, so the render itself\n * never blocks on a fetch — every `source: \"server\"` read in the render\n * starts in the same wave. Substitution awaits the stashed promises at the\n * end, which is the only point an async component render actually waits.\n *\n * On the client this has no counterpart: `render` here is the compiled\n * component body closure that the generated component function returns.\n */\nexport async function serverFlush(render: () => Promise<ServerHtml>): Promise<ServerHtml> {\n\tconst state = newServerAwaitState();\n\tstate.isRoot = true;\n\tconst result = await withServerAwait(state, render);\n\treturn substituteSentinels(result, state);\n}\n\n/**\n * Renders a degraded boundary's `with` branch inside its own flush root, so\n * a `with` branch containing its own `@await` boundaries still resolves\n * them, then wraps it in the boundary's hydration markers. The `with` branch\n * must not start server fetches for its own reads — the flush root isn't a\n * recording context.\n */\nexport async function renderWithBranch(\n\trenderWith: (() => Promise<ServerHtml>) | null,\n): Promise<ServerHtml> {\n\tconst html = await serverFlush(async () => {\n\t\tif (renderWith === null) {\n\t\t\treturn { body: \"\", head: \"\" };\n\t\t}\n\t\treturn renderWith();\n\t});\n\treturn { body: `<![>${html.body}<!]><!>`, head: html.head };\n}\n\n/**\n * Replaces every sentinel the state stashed with its boundary's final HTML.\n * Boundary head tags are appended to the head (they hoist into the document\n * head regardless of where the boundary sits in the body). Any sentinel left\n * over means a boundary's state was lost — a bug, not a degradation path, so\n * it throws.\n */\nexport async function substituteSentinels(\n\tresult: ServerHtml,\n\tstate: ServerAwaitState,\n): Promise<ServerHtml> {\n\tlet { body, head } = result;\n\tfor (const [sentinel, promise] of state.sentinels) {\n\t\tconst html = await promise;\n\t\tbody = body.split(sentinel).join(html.body);\n\t\thead += html.head;\n\t}\n\tif (body.includes(SENTINEL_PREFIX) || head.includes(SENTINEL_PREFIX)) {\n\t\tthrow new Error(\"Unsubstituted async boundary sentinel — boundary state was lost\");\n\t}\n\treturn { body, head };\n}\n","import {\n\tchildKey,\n\tcurrentServerAwait,\n\tnewServerAwaitState,\n\tServerAwaitMisaligned,\n\twithServerAwait,\n} from \"./serverAwaitState\";\nimport type ServerAwaitState from \"./serverAwaitState\";\nimport { renderStarted } from \"./renderContext\";\nimport { renderWithBranch } from \"./serverSentinels\";\n\nlet sentinelCount = 0;\n\nfunction nextSentinel(): string {\n\treturn `<!--t-aw:${sentinelCount++}-->`;\n}\n\n/**\n * Renders an `@await` boundary on the server (compiled as `t_await_server`).\n *\n * The generated code calls this for every `@await`, passing the boundary's\n * site id, a closure that renders the content branch, and one that renders\n * the `with` branch. It always returns a `{ body, head }` pair to append:\n *\n * - **Inside a boundary's render pass** — this boundary was already started\n * during the collect pass; its body/head is the finished HTML (awaited if\n * still in flight). A missing entry means the render pass doesn't match\n * the collect pass, which degrades the enclosing boundary.\n * - **Inside a collect pass or a component flush** — start the full\n * lifecycle (collect, settle, render) without blocking the enclosing\n * render, and return a sentinel comment as the body. Sibling reads and\n * nested boundaries keep rendering, so every fetch in the pass starts in\n * one wave. The sentinel is substituted later: by the enclosing boundary's\n * render pass (which re-invokes this helper and awaits the finished HTML),\n * or by the component flush (which replaces top-level sentinels directly).\n *\n * The lifecycle: render content once to start the `source: \"server\"` fetches\n * (discarding the output), wait for them until each getter's timeout (counted\n * from the start of the server render, so nested boundaries share it), then\n * render again with the settled values. Reads are matched by getter identity,\n * so the render pass may read a getter more than once (e.g. branch on it).\n * The second pass ships wrapped in hydration markers plus a\n * `<!--t-await:...-->` comment carrying the values for the client's `$async`\n * hydration path. Any instability — timeout, a render pass that reads a getter\n * the collect pass never touched, a client-fetch read — degrades to the `with`\n * branch + client fetch, exactly the pre-`source` behavior.\n *\n * @param id The boundary's site id (unique per `@await` in the component)\n * @param renderContent Renders the content branch (may read `$async` getters)\n * @param renderWith Renders the `with` branch, or null for empty\n * @param context The rendering component's context, carrying the render's\n * start time\n */\nexport default function runServerAwait(\n\tid: string,\n\trenderContent: () => Promise<{ body: string; head: string }>,\n\trenderWith: (() => Promise<{ body: string; head: string }>) | null,\n\tcontext?: Record<PropertyKey, any>,\n): { body: string; head: string } | Promise<{ body: string; head: string }> {\n\tconst parent = currentServerAwait();\n\n\tif (parent !== null && parent.phase === \"render\") {\n\t\t// The enclosing boundary is rendering its resolved pass: this nested\n\t\t// boundary was started during the collect pass, so reuse its result\n\t\tconst cached = parent.children.get(childKey(parent, id));\n\t\tif (cached === undefined) {\n\t\t\tthrow new ServerAwaitMisaligned();\n\t\t}\n\t\treturn cached;\n\t}\n\n\tconst state = newServerAwaitState();\n\tstate.startedAt = renderStarted(context);\n\tconst final = renderBoundary(state, renderContent, renderWith);\n\n\tconst sentinel = nextSentinel();\n\tif (parent !== null) {\n\t\tif (parent.isRoot) {\n\t\t\t// Top-level boundary: the component flush substitutes the sentinel\n\t\t\tparent.sentinels.set(sentinel, final);\n\t\t} else {\n\t\t\t// Nested boundary: the enclosing boundary's render pass looks this\n\t\t\t// up by occurrence key\n\t\t\tparent.children.set(childKey(parent, id), final);\n\t\t}\n\t}\n\t// The sentinel body is replaced by the finished content; the head tags a\n\t// resolved boundary renders are hoisted when it finishes\n\treturn { body: sentinel, head: \"\" };\n}\n\n/**\n * The full lifecycle for one boundary: speculative collect pass, settle, and\n * resolved render pass. Runs concurrently with the enclosing render; the\n * returned promise resolves to the boundary's final HTML.\n */\nasync function renderBoundary(\n\tstate: ServerAwaitState,\n\trenderContent: () => Promise<{ body: string; head: string }>,\n\trenderWith: (() => Promise<{ body: string; head: string }>) | null,\n): Promise<{ body: string; head: string }> {\n\t// Collect pass: render content speculatively to invoke the getters. Each\n\t// `source: \"server\"` read starts its fetch and is recorded; sibling reads\n\t// in this pass therefore start together. The output is discarded — reads\n\t// return undefined, so user markup that dereferences them may throw, and\n\t// a throw here costs nothing.\n\tawait withServerAwait(state, renderContent).catch(() => {\n\t\t// Expected when unresolved values are dereferenced; fetches already\n\t\t// started. Any other error resurfaces in the render pass below.\n\t});\n\n\tif (state.promises.length === 0) {\n\t\t// No server-source reads: nothing was (or can be) resolved here, so\n\t\t// ship the `with` branch and let the client fetch — the default SSR\n\t\t// behavior for client-fetch getters\n\t\treturn renderWithBranch(renderWith);\n\t}\n\n\t// Settle the recorded fetches. Each getter carries its own timeout,\n\t// counted from the start of the render: a boundary that only started once\n\t// the boundary around it resolved gets what's left, rather than adding its\n\t// whole wait to the response. The boundary waits for the longest, and a\n\t// miss degrades the whole boundary (content ships only when every read\n\t// resolved). Reads that have already settled still win over a timeout of\n\t// zero, since they resolve in microtasks before the timer fires\n\tconst timeout = Math.max(\n\t\t0,\n\t\tMath.max(...state.promises.map((entry) => entry.timeout)) - (Date.now() - state.startedAt),\n\t);\n\tconst settled = await Promise.race([\n\t\tPromise.all(\n\t\t\tstate.promises.map((entry) =>\n\t\t\t\tentry.promise.then(\n\t\t\t\t\t() => true,\n\t\t\t\t\t() => true,\n\t\t\t\t),\n\t\t\t),\n\t\t).then(\n\t\t\t() => true,\n\t\t\t() => true,\n\t\t),\n\t\tnew Promise<false>((resolve) => setTimeout(resolve, timeout, false)),\n\t]);\n\n\t// Render pass: same reads, now looking settled values up by getter\n\t// identity. The pass may read a getter more than once (markup can branch\n\t// on its value), but every read must have been recorded by the collect\n\t// pass. A read the collect pass never touched, a client-fetch read, or a\n\t// render error means the content can't be trusted, and the boundary\n\t// degrades.\n\t//\n\t// A rejection (or any render error) also degrades: the boundary's\n\t// lifecycle runs detached from the enclosing render (which has already\n\t// moved on after the sentinel), so the error can't propagate to the\n\t// emitted `@try` positionally. Instead the with branch ships and the\n\t// client re-runs the getter, rejects there, and its `@try` renders the\n\t// catch branch — the same path a client-fetch error takes.\n\tlet degraded = settled === false;\n\tif (degraded) {\n\t\twarnTimedOut(state);\n\t}\n\tlet content: { body: string; head: string } | undefined;\n\tif (!degraded) {\n\t\tstate.phase = \"render\";\n\t\tstate.renderEntries.length = 0;\n\t\tstate.renderSeen.clear();\n\t\tstate.clientReads = 0;\n\t\tstate.counters.clear();\n\t\ttry {\n\t\t\tcontent = await withServerAwait(state, renderContent);\n\t\t\tif (state.clientReads > 0) {\n\t\t\t\tdegraded = true;\n\t\t\t}\n\t\t} catch {\n\t\t\tdegraded = true;\n\t\t}\n\t}\n\n\tif (degraded || content === undefined) {\n\t\tstate.degraded = true;\n\t\ttry {\n\t\t\treturn await renderWithBranch(renderWith);\n\t\t} catch {\n\t\t\t// A with-branch render error can't be positioned either; ship an\n\t\t\t// empty boundary rather than failing the whole response\n\t\t\treturn { body: \"<![><!]><!>\", head: \"\" };\n\t\t}\n\t}\n\n\t// Ship the resolved content with the embedded values for hydration.\n\t// Rejections never reach here — the render pass consumes them and\n\t// degrades — but guard anyway so a bad entry can't ship as `undefined`\n\tconst values: any[] = [];\n\tfor (const entry of state.renderEntries) {\n\t\tconst result = entry.result;\n\t\tif (result === undefined) {\n\t\t\tdegraded = true;\n\t\t\tbreak;\n\t\t}\n\t\tvalues.push(result.ok ? result.value : undefined);\n\t}\n\tif (degraded) {\n\t\tstate.degraded = true;\n\t\treturn renderWithBranch(renderWith);\n\t}\n\treturn {\n\t\tbody: `${\"<![>\"}${content.body}${\"<!]><!>\"}${payloadComment(values)}`,\n\t\thead: content.head,\n\t};\n}\n\n// The reads already warned about, so a slow getter warns once per process\n// rather than on every request\nconst warned = new Set<string>();\n\n/**\n * Warns (once per read) that a boundary gave up waiting for its server reads,\n * so the slow read shows up somewhere other than the response time.\n */\nfunction warnTimedOut(state: ServerAwaitState): void {\n\tfor (const entry of state.promises) {\n\t\tif (entry.result !== undefined) continue;\n\t\tconst name = typeof entry.key === \"string\" && entry.key.length < 50 ? entry.key : \"(getter)\";\n\t\tif (warned.has(name)) continue;\n\t\twarned.add(name);\n\t\tconsole.warn(\n\t\t\t`[torpor] The source: \"server\" $async read \"${name}\" didn't settle within its ` +\n\t\t\t\t`${entry.timeout}ms timeout (counted from the start of the render), so its @await ` +\n\t\t\t\t\"boundary rendered its `with` branch and the client will fetch it. Raise the \" +\n\t\t\t\t\"read's `timeout`, or load slow data without blocking the render (in \" +\n\t\t\t\t\"@torpor/build, return a promise from the route's load).\",\n\t\t);\n\t}\n}\n\n/**\n * The `<!--t-await:...-->` comment carrying the boundary's resolved values,\n * in the order the render pass first read them, for the client's `$async`\n * hydration path. `-->` inside the JSON is escaped so the comment can't\n * terminate early.\n */\nfunction payloadComment(values: any[]): string {\n\tconst json = JSON.stringify(values).replaceAll(\"-->\", \"--\\\\u003E\");\n\treturn `<!--t-await:${json}-->`;\n}\n","/**\n * Server stubs for the client-only runtime, so that modules compiled for the\n * client -- or shared helpers that import them from the main `@torpor/view`\n * entry -- still resolve when they end up in a server bundle (the SSR\n * environment resolves `@torpor/view` to this module; see @torpor/build's\n * ssr-view plugin).\n *\n * They throw when called: mounting, hydrating and DOM rendering must not run\n * during SSR. Importing them is fine, which keeps a stray client-only import\n * from failing the server build.\n */\ntype Unavailable = (...args: unknown[]) => never;\n\nfunction unavailable(name: string): Unavailable {\n\treturn (..._args: unknown[]): never => {\n\t\tthrow new Error(`${name} is not available during server rendering`);\n\t};\n}\n\nexport const mount: Unavailable = unavailable(\"mount\");\nexport const hydrate: Unavailable = unavailable(\"hydrate\");\nexport const unmount: Unavailable = unavailable(\"unmount\");\nexport const fillLayoutSlot: Unavailable = unavailable(\"fillLayoutSlot\");\nexport const clearLayoutSlot: Unavailable = unavailable(\"clearLayoutSlot\");\n\nexport const t_add_element: Unavailable = unavailable(\"t_add_element\");\nexport const t_add_fragment: Unavailable = unavailable(\"t_add_fragment\");\nexport const t_anchor: Unavailable = unavailable(\"t_anchor\");\nexport const t_animate: Unavailable = unavailable(\"t_animate\");\nexport const t_apply_props: Unavailable = unavailable(\"t_apply_props\");\nexport const t_attribute: Unavailable = unavailable(\"t_attribute\");\nexport const t_child: Unavailable = unavailable(\"t_child\");\nexport const t_dynamic: Unavailable = unavailable(\"t_dynamic\");\nexport const t_event: Unavailable = unavailable(\"t_event\");\nexport const t_first_inside: Unavailable = unavailable(\"t_first_inside\");\nexport const t_fragment: Unavailable = unavailable(\"t_fragment\");\nexport const t_fragment_el: Unavailable = unavailable(\"t_fragment_el\");\nexport const t_head_element: Unavailable = unavailable(\"t_head_element\");\nexport const t_list_item: Unavailable = unavailable(\"t_list_item\");\nexport const t_next: Unavailable = unavailable(\"t_next\");\nexport const t_pop_region: Unavailable = unavailable(\"t_pop_region\");\nexport const t_push_region: Unavailable = unavailable(\"t_push_region\");\nexport const t_region: Unavailable = unavailable(\"t_region\");\nexport const t_rerun_region_effects: Unavailable = unavailable(\"t_rerun_region_effects\");\nexport const t_restore_hydration: Unavailable = unavailable(\"t_restore_hydration\");\nexport const t_root: Unavailable = unavailable(\"t_root\");\nexport const t_root_el: Unavailable = unavailable(\"t_root_el\");\nexport const t_run_await: Unavailable = unavailable(\"t_run_await\");\nexport const t_run_branch: Unavailable = unavailable(\"t_run_branch\");\nexport const t_run_control: Unavailable = unavailable(\"t_run_control\");\nexport const t_run_list: Unavailable = unavailable(\"t_run_list\");\nexport const t_run_try: Unavailable = unavailable(\"t_run_try\");\nexport const t_save_hydration: Unavailable = unavailable(\"t_save_hydration\");\nexport const t_skip: Unavailable = unavailable(\"t_skip\");\n"],"mappings":";;;;;;;;;;AAUA,MAAM,eAAuC;CAC5C,KAAK;CACL,KAAK;CACL,KAAK;AACN;;;;;;AAOA,SAAgB,WAAW,OAAoB;CAC9C,OAAO,WAAW,KAAK,CAAC,CAAC,QAAQ,WAAW,MAAM,aAAa,EAAE;AAClE;;;;;;AAOA,SAAgB,gBAAgB,OAAoB;CACnD,QAAQ,SAAS,GAAA,CAAI,SAAS,CAAC,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,MAAK,QAAQ;AAClF;;;;;;;;;;;;;ACpBA,SAAwB,oBAAoB,OAAoB;CAC/D,OAAO,gBAAgB,KAAK;AAC7B;;;;;;;;;;;ACJA,SAAwB,qBAAqB,MAAc,OAAoB;CAC9E,IAAI,SAAS,QAAQ,UAAU,OAC9B,OAAO;CAER,OAAO,GAAG,KAAK,IAAI,gBAAgB,KAAK,EAAE;AAC3C;;;;;;;;;;;ACLA,SAAwB,iBAAiB,OAAoB;CAC5D,OAAO,WAAW,KAAK;AACxB;;;;;;;;;;;ACAA,SAAwB,mBAAmB,OAAmB,WAA4B;CACzF,MAAM,UAAU,aAAa,OAAO,SAAS;CAC7C,OAAO,YAAY,KAAK,KAAK,UAAU,gBAAgB,OAAO,EAAE;AACjE;;;;;;;;;;;ACHA,SAAwB,kBAAkB,OAA2B;CACpE,MAAM,SAAS,YAAY,KAAK;CAChC,OAAO,WAAW,KAAK,KAAK,UAAU,gBAAgB,MAAM,EAAE;AAC/D;;;;;;;;;;;;;;;ACDA,SAAwB,UAAU,WAAqB,SAAiB,UAA0B;CACjG,MAAM,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Aa,iBAA8B,YAAY,gBAAgB;AACvE,MAAa,cAA2B,YAAY,aAAa;AACjE,MAAa,SAAsB,YAAY,QAAQ;AACvD,MAAa,eAA4B,YAAY,cAAc;AACnE,MAAa,gBAA6B,YAAY,eAAe;AACrE,MAAa,WAAwB,YAAY,UAAU;AAC3D,MAAa,yBAAsC,YAAY,wBAAwB;AACvF,MAAa,sBAAmC,YAAY,qBAAqB;AACjF,MAAa,SAAsB,YAAY,QAAQ;AACvD,MAAa,YAAyB,YAAY,WAAW;AAC7D,MAAa,cAA2B,YAAY,aAAa;AACjE,MAAa,eAA4B,YAAY,cAAc;AACnE,MAAa,gBAA6B,YAAY,eAAe;AACrE,MAAa,aAA0B,YAAY,YAAY;AAC/D,MAAa,YAAyB,YAAY,WAAW;AAC7D,MAAa,mBAAgC,YAAY,kBAAkB;AAC3E,MAAa,SAAsB,YAAY,QAAQ"}
@@ -0,0 +1,72 @@
1
+ //#region src/dev/devContext.ts
2
+ const DEV_CONTEXT_SYMBOL = Symbol.for("t_dev_context");
3
+ const noop = () => {};
4
+ const devContext = globalThis[DEV_CONTEXT_SYMBOL] ??= {
5
+ enabled: false,
6
+ depth: 0,
7
+ index: -1,
8
+ boundaries: [],
9
+ format: () => "",
10
+ getDetails: () => "",
11
+ unmark: noop,
12
+ mark: noop,
13
+ onWatch: noop,
14
+ onRun: noop,
15
+ onRegionPushed: noop,
16
+ onRegionPopped: noop,
17
+ onRegionCleared: noop,
18
+ signalSet: noop,
19
+ effectRun: noop,
20
+ checkListKeys: noop
21
+ };
22
+ //#endregion
23
+ //#region src/dev/titleWarning.ts
24
+ /** The titles currently set by mounted components. */
25
+ const titles = /* @__PURE__ */ new Set();
26
+ /**
27
+ * The titles already warned about, so that a component used many times (or
28
+ * on every page) is only reported once.
29
+ */
30
+ const warned = /* @__PURE__ */ new Set();
31
+ /** The depth of the layout slot being rendered (see `fillLayoutSlot`). */
32
+ let slotDepth = -1;
33
+ /**
34
+ * Sets the depth of the layout slot being rendered, returning the previous
35
+ * one to restore. Called by `fillLayoutSlot` in dev mode.
36
+ */
37
+ function setDevSlotDepth(depth) {
38
+ const previous = slotDepth;
39
+ slotDepth = depth;
40
+ return previous;
41
+ }
42
+ /**
43
+ * Tracks a component's `@head` title, from the code generated for dev
44
+ * builds. Call at render time, then `set` and `unset` from the title's
45
+ * effect.
46
+ */
47
+ function devTitle() {
48
+ const title = {
49
+ slotDepth,
50
+ value: ""
51
+ };
52
+ return {
53
+ set(value) {
54
+ title.value = value;
55
+ if (!warned.has(value)) {
56
+ const others = new Set([...titles].filter((t) => t.slotDepth >= title.slotDepth && t.value !== value).map((t) => JSON.stringify(t.value)));
57
+ if (others.size > 0) {
58
+ warned.add(value);
59
+ console.warn(`[torpor] More than one mounted component sets the page title: ${[...others].join(", ")} and ${JSON.stringify(value)}. The server keeps the page's title but the client shows the last one set, so the title changes as the page hydrates. Remove the <title> from the @head of the component that shouldn't set it (e.g. a shared child component).`);
60
+ }
61
+ }
62
+ titles.add(title);
63
+ },
64
+ unset() {
65
+ titles.delete(title);
66
+ }
67
+ };
68
+ }
69
+ //#endregion
70
+ export { setDevSlotDepth as n, devContext as r, devTitle as t };
71
+
72
+ //# sourceMappingURL=titleWarning-BMjLAXpn.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"titleWarning-BMjLAXpn.mjs","names":[],"sources":["../src/dev/devContext.ts","../src/dev/titleWarning.ts"],"sourcesContent":["import type DevContext from \"./types/DevContext\";\n\n// TODO: rename this the next time we release the dev tools\nconst DEV_CONTEXT_SYMBOL: unique symbol = Symbol.for(\"t_dev_context\");\n\nconst noop = () => {};\n\nconst devContext: DevContext =\n\t// @ts-ignore\n\t(globalThis[DEV_CONTEXT_SYMBOL] ??= {\n\t\tenabled: false,\n\t\tdepth: 0,\n\t\tindex: -1,\n\t\tboundaries: [],\n\n\t\tformat: () => \"\",\n\t\tgetDetails: () => \"\",\n\t\tunmark: noop,\n\t\tmark: noop,\n\n\t\t// Hooks\n\t\tonWatch: noop,\n\t\tonRun: noop,\n\t\tonRegionPushed: noop,\n\t\tonRegionPopped: noop,\n\t\tonRegionCleared: noop,\n\n\t\tsignalSet: noop,\n\t\teffectRun: noop,\n\n\t\tcheckListKeys: noop,\n\t} satisfies DevContext);\n\nexport default devContext;\n","/**\n * Dev-only check for components whose `@head` titles compete: when two\n * mounted components set a `<title>`, the client shows the last one set, but\n * `@torpor/build`'s server keeps the first one it renders (the page's), so\n * the title changes as the page hydrates. A page's title over its layouts'\n * is fine (both pick the page's); anything else is usually a stray `@head`\n * in a child component.\n */\n\ninterface DevTitle {\n\t/** The depth of the layout slot the component rendered in, or -1. */\n\tslotDepth: number;\n\tvalue: string;\n}\n\n/** The titles currently set by mounted components. */\nconst titles = new Set<DevTitle>();\n\n/**\n * The titles already warned about, so that a component used many times (or\n * on every page) is only reported once.\n */\nconst warned = new Set<string>();\n\n/** The depth of the layout slot being rendered (see `fillLayoutSlot`). */\nlet slotDepth = -1;\n\n/**\n * Sets the depth of the layout slot being rendered, returning the previous\n * one to restore. Called by `fillLayoutSlot` in dev mode.\n */\nexport function setDevSlotDepth(depth: number): number {\n\tconst previous = slotDepth;\n\tslotDepth = depth;\n\treturn previous;\n}\n\n/**\n * Tracks a component's `@head` title, from the code generated for dev\n * builds. Call at render time, then `set` and `unset` from the title's\n * effect.\n */\nexport default function devTitle(): { set: (value: string) => void; unset: () => void } {\n\tconst title: DevTitle = { slotDepth, value: \"\" };\n\treturn {\n\t\tset(value) {\n\t\t\ttitle.value = value;\n\t\t\tif (!warned.has(value)) {\n\t\t\t\t// Only a title rendered in a deeper layout slot than all the\n\t\t\t\t// others (a page over its layouts) shows the same on both sides\n\t\t\t\tconst others = new Set(\n\t\t\t\t\t[...titles]\n\t\t\t\t\t\t.filter((t) => t.slotDepth >= title.slotDepth && t.value !== value)\n\t\t\t\t\t\t.map((t) => JSON.stringify(t.value)),\n\t\t\t\t);\n\t\t\t\tif (others.size > 0) {\n\t\t\t\t\twarned.add(value);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[torpor] More than one mounted component sets the page title: ` +\n\t\t\t\t\t\t\t`${[...others].join(\", \")} and ${JSON.stringify(value)}. The server ` +\n\t\t\t\t\t\t\t`keeps the page's title but the client shows the last one set, so the ` +\n\t\t\t\t\t\t\t`title changes as the page hydrates. Remove the <title> from the ` +\n\t\t\t\t\t\t\t`@head of the component that shouldn't set it (e.g. a shared child ` +\n\t\t\t\t\t\t\t`component).`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\ttitles.add(title);\n\t\t},\n\t\tunset() {\n\t\t\ttitles.delete(title);\n\t\t},\n\t};\n}\n"],"mappings":";AAGA,MAAM,qBAAoC,OAAO,IAAI,eAAe;AAEpE,MAAM,aAAa,CAAC;AAEpB,MAAM,aAEJ,WAAW,wBAAwB;CACnC,SAAS;CACT,OAAO;CACP,OAAO;CACP,YAAY,CAAC;CAEb,cAAc;CACd,kBAAkB;CAClB,QAAQ;CACR,MAAM;CAGN,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,gBAAgB;CAChB,iBAAiB;CAEjB,WAAW;CACX,WAAW;CAEX,eAAe;AAChB;;;;ACfD,MAAM,yBAAS,IAAI,IAAc;;;;;AAMjC,MAAM,yBAAS,IAAI,IAAY;;AAG/B,IAAI,YAAY;;;;;AAMhB,SAAgB,gBAAgB,OAAuB;CACtD,MAAM,WAAW;CACjB,YAAY;CACZ,OAAO;AACR;;;;;;AAOA,SAAwB,WAAgE;CACvF,MAAM,QAAkB;EAAE;EAAW,OAAO;CAAG;CAC/C,OAAO;EACN,IAAI,OAAO;GACV,MAAM,QAAQ;GACd,IAAI,CAAC,OAAO,IAAI,KAAK,GAAG;IAGvB,MAAM,SAAS,IAAI,IAClB,CAAC,GAAG,MAAM,CAAC,CACT,QAAQ,MAAM,EAAE,aAAa,MAAM,aAAa,EAAE,UAAU,KAAK,CAAC,CAClE,KAAK,MAAM,KAAK,UAAU,EAAE,KAAK,CAAC,CACrC;IACA,IAAI,OAAO,OAAO,GAAG;KACpB,OAAO,IAAI,KAAK;KAChB,QAAQ,KACP,iEACI,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,KAAK,UAAU,KAAK,EAAE,gOAKzD;IACD;GACD;GACA,OAAO,IAAI,KAAK;EACjB;EACA,QAAQ;GACP,OAAO,OAAO,KAAK;EACpB;CACD;AACD"}
@@ -0,0 +1,87 @@
1
+ //#region src/dev/devContext.ts
2
+ const DEV_CONTEXT_SYMBOL = Symbol.for("t_dev_context");
3
+ const noop = () => {};
4
+ const devContext = globalThis[DEV_CONTEXT_SYMBOL] ??= {
5
+ enabled: false,
6
+ depth: 0,
7
+ index: -1,
8
+ boundaries: [],
9
+ format: () => "",
10
+ getDetails: () => "",
11
+ unmark: noop,
12
+ mark: noop,
13
+ onWatch: noop,
14
+ onRun: noop,
15
+ onRegionPushed: noop,
16
+ onRegionPopped: noop,
17
+ onRegionCleared: noop,
18
+ signalSet: noop,
19
+ effectRun: noop,
20
+ checkListKeys: noop
21
+ };
22
+ //#endregion
23
+ //#region src/dev/titleWarning.ts
24
+ /** The titles currently set by mounted components. */
25
+ const titles = /* @__PURE__ */ new Set();
26
+ /**
27
+ * The titles already warned about, so that a component used many times (or
28
+ * on every page) is only reported once.
29
+ */
30
+ const warned = /* @__PURE__ */ new Set();
31
+ /** The depth of the layout slot being rendered (see `fillLayoutSlot`). */
32
+ let slotDepth = -1;
33
+ /**
34
+ * Sets the depth of the layout slot being rendered, returning the previous
35
+ * one to restore. Called by `fillLayoutSlot` in dev mode.
36
+ */
37
+ function setDevSlotDepth(depth) {
38
+ const previous = slotDepth;
39
+ slotDepth = depth;
40
+ return previous;
41
+ }
42
+ /**
43
+ * Tracks a component's `@head` title, from the code generated for dev
44
+ * builds. Call at render time, then `set` and `unset` from the title's
45
+ * effect.
46
+ */
47
+ function devTitle() {
48
+ const title = {
49
+ slotDepth,
50
+ value: ""
51
+ };
52
+ return {
53
+ set(value) {
54
+ title.value = value;
55
+ if (!warned.has(value)) {
56
+ const others = new Set([...titles].filter((t) => t.slotDepth >= title.slotDepth && t.value !== value).map((t) => JSON.stringify(t.value)));
57
+ if (others.size > 0) {
58
+ warned.add(value);
59
+ console.warn(`[torpor] More than one mounted component sets the page title: ${[...others].join(", ")} and ${JSON.stringify(value)}. The server keeps the page's title but the client shows the last one set, so the title changes as the page hydrates. Remove the <title> from the @head of the component that shouldn't set it (e.g. a shared child component).`);
60
+ }
61
+ }
62
+ titles.add(title);
63
+ },
64
+ unset() {
65
+ titles.delete(title);
66
+ }
67
+ };
68
+ }
69
+ //#endregion
70
+ Object.defineProperty(exports, "devContext", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return devContext;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "devTitle", {
77
+ enumerable: true,
78
+ get: function() {
79
+ return devTitle;
80
+ }
81
+ });
82
+ Object.defineProperty(exports, "setDevSlotDepth", {
83
+ enumerable: true,
84
+ get: function() {
85
+ return setDevSlotDepth;
86
+ }
87
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/view",
3
- "version": "1.3.3",
3
+ "version": "1.4.1",
4
4
  "description": "Torpor's view library, for writing and mounting components",
5
5
  "type": "module",
6
6
  "exports": {
@@ -35,6 +35,7 @@
35
35
  "dist",
36
36
  "package.json"
37
37
  ],
38
+ "sideEffects": false,
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"AsyncOptions-BDtArmeL.d.mts","names":[],"sources":["../src/types/ClassValue.ts","../src/types/StyleValue.ts","../src/types/StreamSource.ts","../src/stream/fromElement.ts","../src/stream/fromServer.ts","../src/stream/fromWebSocket.ts","../src/types/AsyncOptions.ts"],"mappings":";;KAAK,sBAEF,6CACA,MAAM;;;KCHJ,sBAEF,4CACA,MAAM;;;;;;;;;;;;;;;;;KCaJ,aAAa,MAAM,OAAO,OAAO,eAAe;;;;;;;;;;;;;;KCHhD,mBAAmB,qBAAqB;;;;;;;;;;;iBAYrB,YAAY,UAAU,QAAQ,OACrD,QAAQ,kBACR,eACE,aAAa;;;;;;;;;;;;;;;;;iBCZQ,WAAW,+BAA+B,aAAa;;;;;;;;;;;;;;;;;iBCAvD,cAAc,+BAA+B,aAAa;;;;;;UCbzD;;;;;;EAMxB;;;;;;EAOA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AsyncOptions-C_7mWR6F.d.cts","names":[],"sources":["../src/types/ClassValue.ts","../src/types/StyleValue.ts","../src/types/StreamSource.ts","../src/stream/fromElement.ts","../src/stream/fromServer.ts","../src/stream/fromWebSocket.ts","../src/types/AsyncOptions.ts"],"mappings":";;KAAK,sBAEF,6CACA,MAAM;;;KCHJ,sBAEF,4CACA,MAAM;;;;;;;;;;;;;;;;;KCaJ,aAAa,MAAM,OAAO,OAAO,eAAe;;;;;;;;;;;;;;KCHhD,mBAAmB,qBAAqB;;;;;;;;;;;iBAYrB,YAAY,UAAU,QAAQ,OACrD,QAAQ,kBACR,eACE,aAAa;;;;;;;;;;;;;;;;;iBCZQ,WAAW,+BAA+B,aAAa;;;;;;;;;;;;;;;;;iBCAvD,cAAc,+BAA+B,aAAa;;;;;;UCbzD;;;;;;EAMxB;;;;;;EAOA"}
@@ -1,9 +0,0 @@
1
- //#region src/types/Cleanup.d.ts
2
- /**
3
- * A function that may be returned from an effect, and is run before the effect
4
- * is run or destroyed
5
- */
6
- type Cleanup = () => void;
7
- //#endregion
8
- export { Cleanup as t };
9
- //# sourceMappingURL=Cleanup-D0wvGW5d.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cleanup-D0wvGW5d.d.cts","names":[],"sources":["../src/types/Cleanup.ts"],"mappings":";;;;;KAIK"}
@@ -1,9 +0,0 @@
1
- //#region src/types/Cleanup.d.ts
2
- /**
3
- * A function that may be returned from an effect, and is run before the effect
4
- * is run or destroyed
5
- */
6
- type Cleanup = () => void;
7
- //#endregion
8
- export { Cleanup as t };
9
- //# sourceMappingURL=Cleanup-D0wvGW5d.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cleanup-D0wvGW5d.d.mts","names":[],"sources":["../src/types/Cleanup.ts"],"mappings":";;;;;KAIK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Effect-Bp-BIDDm.d.cts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Effect-VsIY2vPx.d.mts","names":[],"sources":["../src/types/AsyncSettle.ts","../src/types/constants.ts","../src/types/ProxySignal.ts","../src/types/Subscription.ts","../src/types/Computed.ts","../src/types/ErrorBoundary.ts","../src/types/Region.ts","../src/types/Effect.ts"],"mappings":";;;;;;;;;;;;;;;KAaK;EAAgB;EAAU;;EAAiB;EAAW;;;;;;;cCV9C;;;;cAKA;;;;cAKA;;;;;;;UCNY;;;;EAIxB,aAAa;;;;EAKb,aAAa;;;;EAKb,oBAAoB;;;;EAKpB;;;;;;;;UClBwB;;;;EAIxB,QAAQ,cAAc;;;;EAKtB,QAAQ,WAAW;;;;;EAMnB,YAAY;;;;;EAMZ,YAAY;;;;;;;EAQZ,gBAAgB;;;;;;EAOhB;;;;;EAMA;;;;EAKA;;;;;;;;;UC9CwB,SAAS;;;;EAIjC,aAAa;;;;;;;;EASb;;;;EAKA,OAAO;;;;EAKP,WAAW;;;;EAKX,aAAa;;;;EAKb,aAAa;;;;;;;EAQb;;;;EAKA;;;;EAKA;;;;;;;EAQA;;;;;;;EAQA;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,QAAQ;;;;;;;;;;;;;;;EAgBR;;;;EAKA,UAAU;;;;EAKV;;;;;;;;;;UCrHwB;;;;;;EAMxB;;;;;EAMA;;;;;EAMA,QAAQ;;;;;;;;;EAUR,cAAc,cAAc;;;;UCnCJ;EACxB,WAAW;EACX,SAAS;EAET,gBAAgB;EAChB,YAAY;EACZ;;;;;EAMA,YAAY,IAAI;;;;EAKhB;;;;EAKA,SAAS;;;;;;;EAQT,gBAAgB;;;;;;;EAQhB;;;;;;EAOA;;;;;;;UCtCwB;;;;EAIxB,aAAa;;;;;EAMb,WAAW;;;;EAKX,SAAS;;;;EAKT,aAAa;EAKb,YAAY;;;;EAKZ;;;;;;;;EASA;;;;;;;EAQA;;;;;;EAOA;;;;EAKA;;;;;;;EAQA;;;;;;;;;;EAWA,iBAAiB,IAAI;;;;EAKrB;;;;;;EAOA,SAAS;;;;;;EAOT,gBAAgB,cAAc;;;;;;;;;EAU9B;;;;;;;;;;;;;;;;EAiBA"}
@@ -1,27 +0,0 @@
1
- //#region src/dev/devContext.ts
2
- const DEV_CONTEXT_SYMBOL = Symbol.for("t_dev_context");
3
- const noop = () => {};
4
- const devContext = globalThis[DEV_CONTEXT_SYMBOL] ??= {
5
- enabled: false,
6
- depth: 0,
7
- index: -1,
8
- boundaries: [],
9
- format: () => "",
10
- getDetails: () => "",
11
- unmark: noop,
12
- mark: noop,
13
- onWatch: noop,
14
- onRun: noop,
15
- onRegionPushed: noop,
16
- onRegionPopped: noop,
17
- onRegionCleared: noop,
18
- signalSet: noop,
19
- effectRun: noop
20
- };
21
- //#endregion
22
- Object.defineProperty(exports, "devContext", {
23
- enumerable: true,
24
- get: function() {
25
- return devContext;
26
- }
27
- });
@@ -1,24 +0,0 @@
1
- //#region src/dev/devContext.ts
2
- const DEV_CONTEXT_SYMBOL = Symbol.for("t_dev_context");
3
- const noop = () => {};
4
- const devContext = globalThis[DEV_CONTEXT_SYMBOL] ??= {
5
- enabled: false,
6
- depth: 0,
7
- index: -1,
8
- boundaries: [],
9
- format: () => "",
10
- getDetails: () => "",
11
- unmark: noop,
12
- mark: noop,
13
- onWatch: noop,
14
- onRun: noop,
15
- onRegionPushed: noop,
16
- onRegionPopped: noop,
17
- onRegionCleared: noop,
18
- signalSet: noop,
19
- effectRun: noop
20
- };
21
- //#endregion
22
- export { devContext as t };
23
-
24
- //# sourceMappingURL=devContext-ZNsPyOgB.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devContext-ZNsPyOgB.mjs","names":[],"sources":["../src/dev/devContext.ts"],"sourcesContent":["import type DevContext from \"./types/DevContext\";\n\n// TODO: Rename this next time we release the dev tools\nconst DEV_CONTEXT_SYMBOL: unique symbol = Symbol.for(\"t_dev_context\");\n\nconst noop = () => {};\n\nconst devContext: DevContext =\n\t// @ts-ignore\n\t(globalThis[DEV_CONTEXT_SYMBOL] ??= {\n\t\tenabled: false,\n\t\tdepth: 0,\n\t\tindex: -1,\n\t\tboundaries: [],\n\n\t\tformat: () => \"\",\n\t\tgetDetails: () => \"\",\n\t\tunmark: noop,\n\t\tmark: noop,\n\n\t\t// Hooks\n\t\tonWatch: noop,\n\t\tonRun: noop,\n\t\tonRegionPushed: noop,\n\t\tonRegionPopped: noop,\n\t\tonRegionCleared: noop,\n\n\t\tsignalSet: noop,\n\t\teffectRun: noop,\n\t} satisfies DevContext);\n\nexport default devContext;\n"],"mappings":";AAGA,MAAM,qBAAoC,OAAO,IAAI,eAAe;AAEpE,MAAM,aAAa,CAAC;AAEpB,MAAM,aAEJ,WAAW,wBAAwB;CACnC,SAAS;CACT,OAAO;CACP,OAAO;CACP,YAAY,CAAC;CAEb,cAAc;CACd,kBAAkB;CAClB,QAAQ;CACR,MAAM;CAGN,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB,gBAAgB;CAChB,iBAAiB;CAEjB,WAAW;CACX,WAAW;AACZ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fromWebSocket-ERhd9KZR.mjs","names":[],"sources":["../src/watch/symbols.ts","../src/watch/$unwrap.ts","../src/render/buildClasses.ts","../src/render/buildStyles.ts","../src/render/formatText.ts","../src/stream/fromElement.ts","../src/stream/fromServer.ts","../src/stream/fromWebSocket.ts"],"sourcesContent":["const proxyDataSymbol: unique symbol = Symbol.for(\"torp.ProxyData\");\n\n/**\n * Signal key for a watched object's key-set membership (`ownKeys`). Tracked by\n * the proxy's `ownKeys` trap — so `Object.keys`/`values`/`entries`, spread,\n * `for…in` and `JSON.stringify` re-run when a key is added or deleted — and\n * propagated by the `set`/`deleteProperty` traps (and the array mutation\n * handles) when the key set actually changes. A Symbol so it can't collide\n * with a user property name.\n */\nconst proxyKeysSymbol: unique symbol = Symbol.for(\"torp.ProxyKeys\");\n\nexport { proxyDataSymbol, proxyKeysSymbol };\n","import { proxyDataSymbol } from \"./symbols\";\n\n/**\n * Returns the target object of a proxy\n *\n * @param object The proxy object\n */\nexport default function $unwrap<T extends Record<PropertyKey, any>>(object: T): T {\n\treturn object !== undefined && object !== null && object[proxyDataSymbol] !== undefined\n\t\t? (object[proxyDataSymbol].target ?? object)\n\t\t: object;\n}\n","import ClassValue from \"../types/ClassValue\";\nimport $unwrap from \"../watch/$unwrap\";\n\nexport default function buildClasses(value: ClassValue, styleHash?: string): string {\n\tif (typeof value === \"string\") {\n\t\tif (styleHash !== undefined) {\n\t\t\tvalue += \" \" + styleHash;\n\t\t}\n\t\treturn value;\n\t} else {\n\t\tlet classes: string[] = [];\n\t\tgatherClasses(\"\", value, classes);\n\t\tif (styleHash !== undefined) {\n\t\t\tclasses.push(styleHash);\n\t\t}\n\t\treturn classes.join(\" \");\n\t}\n}\n\nfunction gatherClasses(name: string, value: unknown, classes: string[]) {\n\tif (value) {\n\t\t// Unwrap watched values before iterating: component props are\n\t\t// deep-wrapped, and iterating a watched array disables the active\n\t\t// effect (see the array iterator in proxyGet), which would break\n\t\t// tracking of reads later in the same effect. Per-element tracking is\n\t\t// unnecessary here anyway -- the caller has already subscribed to the\n\t\t// property read that produced the value\n\t\tvalue = $unwrap(value as Record<PropertyKey, any>);\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherClasses(v as string, v, classes);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\t// Use `for-in` instead of `Object.entries(value)`. The entries\n\t\t\t// call allocates a new array (plus a [k, v] pair per entry) on\n\t\t\t// every invocation; `for-in` allocates nothing. Object literals\n\t\t\t// (the dominant case — e.g. `{ danger: bool }` in the row\n\t\t\t// template) have no inherited enumerable properties, so the two\n\t\t\t// are equivalent for our usage. This is on the per-effect re-run\n\t\t\t// hot path: a `select` op re-runs every row effect, each calling\n\t\t\t// `buildClasses({ danger: ... })`.\n\t\t\tfor (const n in value) {\n\t\t\t\tgatherClasses(n, (value as Record<string, unknown>)[n], classes);\n\t\t\t}\n\t\t} else {\n\t\t\tclasses.push(name);\n\t\t}\n\t}\n}\n","import type StyleValue from \"../types/StyleValue\";\n\nconst CAMEL_TO_DASH = /[A-Z]+(?![a-z])|[A-Z]/g;\n\nexport default function buildStyles(value: StyleValue): string {\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t} else {\n\t\tlet styles: string[] = [];\n\t\tgatherStyles(value, styles);\n\t\treturn styles.join(\"; \");\n\t}\n}\n\nfunction gatherStyles(value: unknown, styles: string[]) {\n\tif (value) {\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (let v of value) {\n\t\t\t\tgatherStyles(v, styles);\n\t\t\t}\n\t\t} else if (typeof value === \"object\") {\n\t\t\tfor (let [n, v] of Object.entries(value)) {\n\t\t\t\tif (v === null || v === undefined) continue;\n\t\t\t\tconst key = n.replace(CAMEL_TO_DASH, (char, i) => (i > 0 ? \"-\" : \"\") + char.toLowerCase());\n\t\t\t\tstyles.push(`${key}: ${v}`);\n\t\t\t}\n\t\t} else {\n\t\t\t// oxlint-disable-next-line typescript/no-base-to-string\n\t\t\tstyles.push(String(value));\n\t\t}\n\t}\n}\n","import $unwrap from \"../watch/$unwrap\";\n\nexport default function formatText(value: any): string {\n\t// We could have anything in value, so we need to\n\t// - use String(...) because Symbols can't be implicitly converted\n\t// - use $unwrap because Proxies can't be converted to a string\n\tif (value === undefined || value === null) {\n\t\treturn \"\";\n\t}\n\t// Fast path: strings already satisfy both concerns above. Skipping the\n\t// `String($unwrap(value))` pair saves two function calls per text\n\t// interpolation on the dominant `typeof value === \"string\"` branch —\n\t// e.g. row labels in js-framework-bench hit this on every effect run.\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\treturn String($unwrap(value));\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * The element to listen on, or a getter returning it. Use a getter for\n * `&ref`-bound variables — they are only assigned once the element is\n * created, and subscriptions start at mount time:\n *\n * ```torp\n * let saveButton: HTMLButtonElement;\n *\n * $stream(fromElement(() => saveButton, \"click\"), () => save());\n * ```\n */\ntype EventTargetInput = HTMLElement | (() => HTMLElement | null | undefined);\n\n/**\n * Creates a StreamSource that pushes DOM events of the given type from an\n * element.\n *\n * ```torp\n * $stream(fromElement(() => saveButton, \"click\"), (e) => {\n * \t$state.clicks.push(e);\n * });\n * ```\n */\nexport default function fromElement<E extends Event = Event>(\n\ttarget: EventTargetInput,\n\ttype: string,\n): StreamSource<E> {\n\treturn (push) => {\n\t\tconst el = typeof target === \"function\" ? target() : target;\n\t\tif (!el) {\n\t\t\tthrow new Error(\n\t\t\t\t'fromElement: element not found. When passing a &ref variable, wrap it in a getter: fromElement(() => buttonEl, \"click\")',\n\t\t\t);\n\t\t}\n\t\tconst listener = push as EventListener;\n\t\tel.addEventListener(type, listener);\n\t\treturn () => {\n\t\t\tel.removeEventListener(type, listener);\n\t\t};\n\t};\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Creates a StreamSource that receives `message` events from a server-sent\n * events endpoint. The URL may be a getter, so reactive state can be read\n * inside it — when it changes, the connection is closed and re-opened:\n *\n * ```torp\n * $stream(fromServer(`/sse/${$props.id}`), (e) => {\n * \t$state.messages.push(e.data);\n * });\n * ```\n *\n * Reconnection is handled by `EventSource` itself; errors are not pushed —\n * a source that can fail should surface errors as values.\n */\nexport default function fromServer(url: string | (() => string)): StreamSource<MessageEvent> {\n\treturn (push) => {\n\t\tconst eventSource = new EventSource(typeof url === \"function\" ? url() : url);\n\t\teventSource.onmessage = push;\n\t\treturn () => {\n\t\t\teventSource.close();\n\t\t};\n\t};\n}\n","import type StreamSource from \"../types/StreamSource\";\n\n/**\n * Creates a StreamSource that receives `message` events from a WebSocket.\n * The URL may be a getter, so reactive state can be read inside it — when\n * it changes, the socket is closed and re-opened:\n *\n * ```torp\n * $stream(fromWebSocket(`/ws/${$props.id}`), (e) => {\n * \t$state.inbox.push(e.data);\n * });\n * ```\n *\n * Errors are not pushed — a source that can fail should surface errors as\n * values and own its own reconnection.\n */\nexport default function fromWebSocket(url: string | (() => string)): StreamSource<MessageEvent> {\n\treturn (push) => {\n\t\tconst socket = new WebSocket(typeof url === \"function\" ? url() : url);\n\t\tsocket.onmessage = push;\n\t\treturn () => {\n\t\t\tsocket.close();\n\t\t};\n\t};\n}\n"],"mappings":";AAAA,MAAM,kBAAiC,OAAO,IAAI,gBAAgB;;;;;;;;;AAUlE,MAAM,kBAAiC,OAAO,IAAI,gBAAgB;;;;;;;;ACHlE,SAAwB,QAA4C,QAAc;CACjF,OAAO,WAAW,KAAA,KAAa,WAAW,QAAQ,OAAO,qBAAqB,KAAA,IAC1E,OAAO,gBAAgB,CAAC,UAAU,SACnC;AACJ;;;ACRA,SAAwB,aAAa,OAAmB,WAA4B;CACnF,IAAI,OAAO,UAAU,UAAU;EAC9B,IAAI,cAAc,KAAA,GACjB,SAAS,MAAM;EAEhB,OAAO;CACR,OAAO;EACN,IAAI,UAAoB,CAAC;EACzB,cAAc,IAAI,OAAO,OAAO;EAChC,IAAI,cAAc,KAAA,GACjB,QAAQ,KAAK,SAAS;EAEvB,OAAO,QAAQ,KAAK,GAAG;CACxB;AACD;AAEA,SAAS,cAAc,MAAc,OAAgB,SAAmB;CACvE,IAAI,OAAO;EAOV,QAAQ,QAAQ,KAAiC;EACjD,IAAI,MAAM,QAAQ,KAAK,GACtB,KAAK,IAAI,KAAK,OACb,cAAc,GAAa,GAAG,OAAO;OAEhC,IAAI,OAAO,UAAU,UAS3B,KAAK,MAAM,KAAK,OACf,cAAc,GAAI,MAAkC,IAAI,OAAO;OAGhE,QAAQ,KAAK,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