@torpor/view 1.1.1 → 1.1.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/render/context.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/watch/clearSources.ts","../src/watch/deactivateSources.ts","../src/watch/trackSignal.ts","../src/watch/runComputed.ts","../src/watch/checkComputed.ts","../src/watch/checkSources.ts","../src/watch/runCleanups.ts","../src/watch/checkEffect.ts","../src/watch/clearTargets.ts","../src/watch/routeEffectError.ts","../src/watch/triggerEffects.ts","../src/watch/batchEnd.ts","../src/watch/batchStart.ts","../src/watch/runEffect.ts","../src/watch/$run.ts","../src/watch/$peek.ts","../src/watch/flushMountEffects.ts","../src/render/animate.ts","../src/render/delegatedEvents.ts","../src/render/isFragmentNode.ts","../src/render/runMountSideEffects.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearRegion.ts","../src/render/clearLayoutSlot.ts","../src/render/newRegion.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/fillLayoutSlot.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/render/newListItem.ts","../src/render/isCommentNode.ts","../src/render/isTextNode.ts","../src/render/nodeCheckHydrationBreak.ts","../src/render/nodeNext.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/walkHydrationRoot.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/widenAncestorsAtAnchor.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/watch/deepWrap.ts","../src/watch/propagateSignal.ts","../src/watch/trackProxySignal.ts","../src/watch/proxyGet.ts","../src/watch/proxySet.ts","../src/watch/$watch.ts","../src/render/getSequence.ts","../src/render/moveRegion.ts","../src/render/runListItems.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/saveHydration.ts","../src/render/runTry.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$stream.ts"],"sourcesContent":["import type Context from \"../types/Context\";\nimport type Region from \"../types/Region\";\n\nconst CONTEXT_SYMBOL: unique symbol = Symbol.for(\"torp.Context\");\n\nconst context: Context =\n\t// @ts-ignore\n\t(globalThis[CONTEXT_SYMBOL] ??= {\n\t\tactiveTarget: null,\n\t\tpreviousEffect: null,\n\t\textent: 0,\n\t\tbatch: 0,\n\t\tbatchOperation: 0,\n\t\tregisterComputed: null,\n\n\t\teffectsToRun: [],\n\t\tfirstSignalToUpdate: null,\n\t\tlastSignalToUpdate: null,\n\n\t\t// These will definitely be set, in mount or render\n\t\tactiveRegion: null as unknown as Region,\n\t\tpreviousRegion: null as unknown as Region,\n\t\trootRegion: null as unknown as Region,\n\n\t\tawaitBoundary: null,\n\n\t\tsuspendPeek: false,\n\t\tsuspendPeekHit: false,\n\n\t\trefreshSignals: null,\n\t\trefreshInitialized: null,\n\n\t\tmountEffects: [],\n\t\tstashedEvents: [],\n\t\tstashedAnimations: [],\n\n\t\thydrationNode: null,\n\t\t//hn: null,\n\t\t//get hydrationNode() {\n\t\t//\treturn this.hn;\n\t\t//},\n\t\t//set hydrationNode(value) {\n\t\t//\tconsole.log(`set hydration ${printNode(value)}`);\n\t\t//\tthis.hn = value;\n\t\t//},\n\n\t\tserverValues: null,\n\t} satisfies Context);\n\nexport default context;\n","import type Animation from \"../types/Animation\";\nimport context from \"./context\";\n\nexport default function addAnimation(el: HTMLElement, entry?: Animation, exit?: Animation): void {\n\t// Stash the event in context so that it can be added when the fragment is\n\t// added to the DOM\n\t// NOTE: We don't need to do this for hydration, but it's simpler to do it\n\t// the same way in both processes\n\tcontext.stashedAnimations.push({\n\t\tregion: context.activeRegion,\n\t\tel,\n\t\tin: entry,\n\t\tout: exit,\n\t});\n}\n","import context from \"./context\";\n\nexport default function addEvent(\n\tel: Element,\n\ttype: string,\n\tlistener: ((this: Element, ev: any) => any) | undefined | null,\n): void {\n\t// Stash the event in context so that it can be added when the fragment is\n\t// added to the DOM\n\t// NOTE: We don't need to do this for hydration, but it's simpler to do it\n\t// the same way in both processes\n\tif (listener !== undefined && listener !== null) {\n\t\t// NOTE: `region` is intentionally omitted — it was stashed historically\n\t\t// but never read by `addFragment` (the consumer). Dropping it removes\n\t\t// one property write per `addEvent` call (2 per list item in the\n\t\t// js-framework-bench row template, ~2000 writes per 1k-row create).\n\t\tcontext.stashedEvents.push({ el, type, listener });\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * Clear unused source subscriptions after each Computed or Effect has been run.\n */\nexport default function clearSources(target: Computed | Effect): void {\n\tlet previousSub: Subscription | null = null;\n\tfor (\n\t\tlet clearSub: Subscription | null = target.firstSource;\n\t\tclearSub !== null;\n\t\tclearSub = clearSub.nextSource\n\t) {\n\t\tif (target.didError || !clearSub.active) {\n\t\t\t//console.log(\n\t\t\t//\t`clearing source sub ${clearSub.source.name} <-> ${clearSub.target.name} (${clearSub.name})`,\n\t\t\t//);\n\t\t\tif (previousSub === null) {\n\t\t\t\ttarget.firstSource = clearSub.nextSource;\n\t\t\t} else {\n\t\t\t\tpreviousSub.nextSource = clearSub.nextSource;\n\t\t\t}\n\n\t\t\t// Update the targets list too\n\t\t\tif (clearSub.previousTarget === null) {\n\t\t\t\tif (clearSub.source.firstTarget === clearSub) {\n\t\t\t\t\tclearSub.source.firstTarget = clearSub.nextTarget;\n\t\t\t\t}\n\t\t\t\t// TODO: else???\n\t\t\t} else {\n\t\t\t\tclearSub.previousTarget.nextTarget = clearSub.nextTarget;\n\t\t\t}\n\t\t} else {\n\t\t\tclearSub.recalc = false;\n\t\t\tpreviousSub = clearSub;\n\t\t}\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * Sets source subscriptions to inactive for a Computed or Effect.\n */\nexport default function deactivateSources(target: Computed | Effect): void {\n\tfor (\n\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\tsourceSub !== null;\n\t\tsourceSub = sourceSub.nextSource\n\t) {\n\t\tsourceSub.active = false;\n\t\t//console.log(\n\t\t//\t`deactivating ${sourceSub.source.name} <-> ${sourceSub.target.name} (${sourceSub.name})`,\n\t\t//);\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * If there's an active target, subscribe it to this signal, so that it will be\n * run when the signal changes.\n */\nexport default function trackSignal(signal: ProxySignal | Computed): void {\n\tconst target = context.activeTarget;\n\tif (target !== null) {\n\t\t// Walk the target's existing sources (typically a handful) to look for\n\t\t// an existing subscription we can re-use, instead of walking the\n\t\t// signal's target list. A popular signal (e.g. a parent's `selected`\n\t\t// flag fanned out to thousands of list-item effects) can have a very\n\t\t// long target list, which made subscription O(N) per call and O(N²)\n\t\t// total — the dominant cost in the js-framework-bench `runlots` op.\n\t\t// The target's source list is bounded by the number of distinct\n\t\t// signals this single effect depends on (almost always <10).\n\t\tfor (\n\t\t\tlet existingSub: Subscription | null = target.firstSource;\n\t\t\texistingSub !== null;\n\t\t\texistingSub = existingSub.nextSource\n\t\t) {\n\t\t\tif (existingSub.source === signal) {\n\t\t\t\t// Re-use the existing subscription\n\t\t\t\texistingSub.active = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// No existing subscription — create a new one. Prepend to both lists\n\t\t// to keep this O(1); the order of subscriptions within a signal's\n\t\t// target list has no semantic meaning (effect run order is decided by\n\t\t// dependency graph, not subscription order).\n\t\tconst oldFirstTarget = signal.firstTarget;\n\t\tconst sub: Subscription = {\n\t\t\tsource: signal,\n\t\t\ttarget: target,\n\t\t\tpreviousTarget: null,\n\t\t\tnextTarget: oldFirstTarget,\n\t\t\tnextSource: target.firstSource,\n\t\t\tactive: true,\n\t\t\trecalc: false,\n\t\t};\n\t\tif (oldFirstTarget !== null) {\n\t\t\toldFirstTarget.previousTarget = sub;\n\t\t}\n\t\tsignal.firstTarget = sub;\n\t\ttarget.firstSource = sub;\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport trackSignal from \"./trackSignal\";\n\nexport default function runComputed<T>(computed: Computed<T>): T {\n\t//console.log(`running computed '${computed.name}'`);\n\n\t// Store the active target\n\tconst oldActiveTarget = context.activeTarget;\n\n\tcomputed.running = true;\n\tcomputed.didError = false;\n\tcomputed.didSuspend = false;\n\n\ttry {\n\t\t// Set the active target, so that any properties accessed while running it\n\t\t// will trigger it in future\n\t\tcontext.activeTarget = computed;\n\n\t\t// Run the computed and gather its dependencies\n\t\tcomputed.value = computed.run();\n\t} catch (err) {\n\t\tcomputed.didError = true;\n\t\t// @ts-ignore\n\t\tcomputed.value = err;\n\t\tthrow err;\n\t} finally {\n\t\t// Set the active target back to what it was previously\n\t\tcontext.activeTarget = oldActiveTarget;\n\n\t\tcomputed.running = false;\n\t}\n\n\ttrackSignal(computed);\n\n\treturn computed.value;\n}\n","import type Computed from \"../types/Computed\";\nimport type Subscription from \"../types/Subscription\";\nimport checkSources from \"./checkSources\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Checks whether a Computed value should be re-run (which will be true if any\n * of its sources have changed) and re-runs it if necessary.\n */\nexport default function checkComputed(computed: Computed): boolean {\n\tlet rerun = checkSources(computed);\n\n\tlet changed = false;\n\n\tif (rerun) {\n\t\t// Set source subscriptions to inactive\n\t\tdeactivateSources(computed);\n\n\t\t// Run the computed, which will reset subscriptions\n\t\tconst oldValue = computed.value;\n\t\trunComputed(computed);\n\t\tchanged = computed.value !== oldValue;\n\n\t\t// Clear unused source subscriptions\n\t\tclearSources(computed);\n\t}\n\n\tcomputed.recalc = false;\n\n\t// If it hasn't changed, all of its target subscriptions remain active and\n\t// don't need to be recalculated\n\tif (!changed) {\n\t\tfor (\n\t\t\tlet targetSub: Subscription | null = computed.firstTarget;\n\t\t\ttargetSub !== null;\n\t\t\ttargetSub = targetSub.nextTarget\n\t\t) {\n\t\t\ttargetSub.active = true;\n\t\t\ttargetSub.recalc = false;\n\t\t}\n\t}\n\n\treturn changed;\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\nimport { COMPUTED_TYPE, SIGNAL_TYPE } from \"../types/constants\";\nimport checkComputed from \"./checkComputed\";\n\n// RECURSIVE\n\n/**\n * Checks whether a Computed or Effect should be re-run (which will be true if\n * any of its sources have changed).\n */\nexport default function checkSources(target: Computed | Effect): boolean {\n\t// NOTE: We bail early if we know the target needs to be re-run; subsequent\n\t// computed values will be computed in the proxy getter\n\n\t// Check signals first as it's cheap, then computed values\n\tlet haveComputed = false;\n\n\tfor (\n\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\tsourceSub !== null;\n\t\tsourceSub = sourceSub.nextSource\n\t) {\n\t\t//console.log(`checking source sub '${sourceSub.source.name}' (${sourceSub.name})`);\n\t\tif (sourceSub.recalc) {\n\t\t\tif (sourceSub.source.type === SIGNAL_TYPE) {\n\t\t\t\treturn true;\n\t\t\t} /* else if (sourceSub.source.type === COMPUTED_TYPE) */ else {\n\t\t\t\tif (sourceSub.source.recalc) {\n\t\t\t\t\thaveComputed = true;\n\t\t\t\t} else {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (haveComputed) {\n\t\tfor (\n\t\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\t\tsourceSub !== null;\n\t\t\tsourceSub = sourceSub.nextSource\n\t\t) {\n\t\t\t//console.log(`checking source sub '${sourceSub.source.name}' (${sourceSub.name})`);\n\t\t\tif (sourceSub.recalc && sourceSub.source.type === COMPUTED_TYPE && sourceSub.source.recalc) {\n\t\t\t\tconst oldActiveTarget = context.activeTarget;\n\t\t\t\tcontext.activeTarget = target;\n\n\t\t\t\tconst recalc = checkComputed(sourceSub.source);\n\n\t\t\t\tcontext.activeTarget = oldActiveTarget;\n\n\t\t\t\tif (recalc) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\n}\n","import context from \"../render/context\";\nimport type Effect from \"../types/Effect\";\nimport clearSources from \"./clearSources\";\n\n/**\n * Runs cleanup functions for the effect and its children.\n */\nexport default function runCleanups(effect: Effect): void {\n\tlet effectToClean: Effect | null = effect;\n\tfor (let i = 0; i < effect.extent; i++) {\n\t\tif (effectToClean === null) break;\n\t\tif (typeof effectToClean.cleanup === \"function\") {\n\t\t\t//console.log(`cleaning effect '${effectToClean.name}'`);\n\t\t\tconst oldActiveTarget = context.activeTarget;\n\t\t\tcontext.activeTarget = null;\n\n\t\t\ttry {\n\t\t\t\teffectToClean.cleanup();\n\t\t\t} catch (err) {\n\t\t\t\teffectToClean.didError = true;\n\t\t\t\tclearSources(effectToClean);\n\t\t\t\tthrow err;\n\t\t\t} finally {\n\t\t\t\teffectToClean.cleanup = undefined;\n\t\t\t\tcontext.activeTarget = oldActiveTarget;\n\t\t\t}\n\t\t}\n\n\t\tconst nextEffect: Effect = effectToClean.nextEffect!;\n\n\t\teffectToClean = nextEffect;\n\t}\n}\n","import type Effect from \"../types/Effect\";\nimport checkSources from \"./checkSources\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runCleanups from \"./runCleanups\";\nimport runEffect from \"./runEffect\";\n\n/**\n * Checks whether an Effect should be re-run (which will be true if any\n * of its sources have changed) and re-runs it if necessary.\n */\nexport default function checkEffect(effect: Effect): void {\n\tlet rerun = checkSources(effect);\n\n\tif (rerun) {\n\t\t//console.log(`running effect '${String(effect.run)}'`);\n\n\t\t// Run cleanup functions for the effect and its children\n\t\trunCleanups(effect);\n\n\t\t// Set source subscriptions to inactive\n\t\tdeactivateSources(effect);\n\n\t\t// Run the effect, which will reset subscriptions\n\t\trunEffect(effect);\n\n\t\t// Clear unused source subscriptions\n\t\tclearSources(effect);\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\n\n/**\n * Clear unused target subscriptions after all Effects have been run.\n *\n * NOTE: This used to walk `source.firstTarget` and unlink inactive\n * subscriptions. That walk is now skipped: inactive subs are left in the\n * target list so that `trackSignal` (which looks up existing subscriptions\n * via the target's source list) can safely reactivate them on the next run.\n * Actual cleanup of unused subscriptions happens in `clearSources`, which\n * runs after each Effect / Computed re-run and removes from both lists.\n *\n * Why this matters: with the previous design, `trackSignal` walked the\n * signal's target list to find an existing subscription, which was O(N) per\n * call for popular signals. The new design walks the target's source list\n * (bounded by the effect's dependency count, typically <10), but only works\n * if a subscription found in the source list is also still linked into the\n * signal's target list. Removing it here broke that invariant for computed\n * values that hadn't yet re-run.\n */\nexport default function clearTargets(_source: ProxySignal | Computed): void {\n\t// Intentional no-op — see comment above.\n}\n","import type Effect from \"../types/Effect\";\nimport type ErrorBoundary from \"../types/ErrorBoundary\";\nimport type Region from \"../types/Region\";\nimport type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runCleanups from \"./runCleanups\";\nimport runEffect from \"./runEffect\";\n\n/**\n * Routes an error thrown by an effect re-run to the nearest enclosing error\n * boundary (`@try`/`@catch` or top-level `@error`), and forces the boundary's\n * control effect to re-run so it renders its catch branch. Returns true if a\n * boundary handled the error.\n *\n * The boundary is found by walking the flattened region chain from the\n * effect's owning region (`Effect.region`, set by `$run`) through its\n * ancestors (regions with strictly decreasing depth on the `previousRegion`\n * chain — the same shape `clearRegion` walks).\n *\n * For recovery, the boundary holds the failing effect's source signals\n * (captured by `runEffect` before it cleared them, `Effect.errorSources`)\n * together with the boundary effect's own sources: reads wrapped in nested\n * `$run` effects (text/attribute interpolation) are tracked by those\n * effects, not the boundary, so without holding them the catch branch would\n * never re-attempt the try branch. `runTry` re-subscribes the boundary\n * effect to the held signals on every run that shows the catch branch.\n *\n * Called from `triggerEffects`' per-effect catch. If forcing the boundary\n * re-run itself throws (e.g. the catch branch content errors), the error\n * propagates to the caller, which reports it as unhandled — matching the\n * compiled form, where a throwing catch branch escapes the boundary.\n */\nexport default function routeEffectError(effect: Effect, error: any): boolean {\n\tlet region: Region | null = effect.region ?? null;\n\twhile (region !== null) {\n\t\tconst boundary: ErrorBoundary | undefined = region.errorBoundary;\n\t\tif (boundary !== undefined && boundary.effect !== null) {\n\t\t\tconst boundaryEffect = boundary.effect;\n\n\t\t\t// Hold the boundary effect's own sources plus the failing\n\t\t\t// effect's sources, so any of them changing re-attempts the try\n\t\t\t// branch (recovery)\n\t\t\tconst held: (ProxySignal | Computed)[] = [];\n\t\t\tfor (\n\t\t\t\tlet sub: Subscription | null = boundaryEffect.firstSource;\n\t\t\t\tsub !== null;\n\t\t\t\tsub = sub.nextSource\n\t\t\t) {\n\t\t\t\theld.push(sub.source);\n\t\t\t}\n\t\t\tfor (const signal of effect.errorSources ?? []) {\n\t\t\t\tif (!held.includes(signal)) {\n\t\t\t\t\theld.push(signal);\n\t\t\t\t}\n\t\t\t}\n\t\t\tboundary.error = error;\n\t\t\tboundary.hasError = true;\n\t\t\tboundary.heldSignals = held;\n\n\t\t\t// Force the boundary effect to re-run (unconditionally, like\n\t\t\t// `checkEffect` does when a source has changed). runTry renders\n\t\t\t// the catch branch with the routed error and holds the signals\n\t\t\trunCleanups(boundaryEffect);\n\t\t\tdeactivateSources(boundaryEffect);\n\t\t\trunEffect(boundaryEffect);\n\t\t\tclearSources(boundaryEffect);\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Walk to the nearest ancestor: the first previous region with\n\t\t// strictly smaller depth (siblings and children of siblings have\n\t\t// greater-or-equal depth and do not enclose this region)\n\t\tconst depth = region.depth;\n\t\tlet previous: Region | null = region.previousRegion;\n\t\twhile (previous !== null && previous.depth >= depth) {\n\t\t\tprevious = previous.previousRegion;\n\t\t}\n\t\tregion = previous;\n\t}\n\n\treturn false;\n}\n","import context from \"../render/context\";\nimport type Effect from \"../types/Effect\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport checkEffect from \"./checkEffect\";\nimport clearTargets from \"./clearTargets\";\nimport routeEffectError from \"./routeEffectError\";\nimport trackSignal from \"./trackSignal\";\n\n/**\n * Re-subscribes a failed effect to the suspended computeds its run had read,\n * after `runEffect`'s catch detached them via `clearSources`. Called when no\n * error boundary handled the crash: the error still surfaces (see below),\n * but the promise's resolve re-runs the effect, so a crash caused by a\n * pending read's `undefined` heals instead of leaving a dead effect.\n */\nfunction resubscribeSuspendSources(effect: Effect): void {\n\tconst sources = effect.suspendSources;\n\tif (!sources || sources.size === 0) return;\n\tconst oldActive = context.activeTarget;\n\tcontext.activeTarget = effect;\n\tfor (const signal of sources) {\n\t\ttrackSignal(signal);\n\t}\n\tcontext.activeTarget = oldActive;\n}\n\n/**\n * Runs the effects that have been collected during the batch.\n */\nexport default function triggerEffects(): void {\n\t//console.log(`triggering effects for '${String(key)}' on`, proxy);\n\t//console.log(\"===\");\n\t//console.log(`triggering effects for '${String(key)}'`);\n\n\t// The first error that was NOT handled by an error boundary (if any).\n\t// Errors routed to a boundary are consumed by it; unhandled ones are\n\t// rethrown after the batch, as before boundaries existed.\n\tlet unhandledError: { error: any } | null = null;\n\n\t// Run the queued effects. Appends made while running (by signal writes\n\t// within an effect) land in the same array and are picked up by the\n\t// index-based loop. An effect that already ran in this flush can be\n\t// re-queued the same way — `queued` is reset as each effect is\n\t// processed, so a later write re-runs it with fresh values.\n\tconst queue = context.effectsToRun;\n\tfor (let i = 0; i < queue.length; i++) {\n\t\tconst effect = queue[i];\n\t\tcontext.batchOperation++;\n\n\t\t// Mark as not-queued BEFORE running, so that a signal write made\n\t\t// during this run — or during a later effect's run in the same\n\t\t// flush — can re-queue it if a source changed again\n\t\teffect.queued = false;\n\n\t\ttry {\n\t\t\tcheckEffect(effect);\n\t\t} catch (err) {\n\t\t\t// A re-run threw. Route it to the nearest enclosing error\n\t\t\t// boundary (@try/@catch or top-level @error), which re-renders\n\t\t\t// its catch branch; if there is none (or routing itself throws,\n\t\t\t// e.g. the catch content errors), record it to rethrow below\n\t\t\tlet handled = false;\n\t\t\ttry {\n\t\t\t\thandled = routeEffectError(effect, err);\n\t\t\t} catch (routingError) {\n\t\t\t\tif (unhandledError === null) {\n\t\t\t\t\tunhandledError = { error: routingError };\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!handled) {\n\t\t\t\t// No boundary took the error. If the failed run had read a\n\t\t\t\t// suspended $async getter, the crash may be caused by the\n\t\t\t\t// pending `undefined` it returned — keep the effect\n\t\t\t\t// subscribed so resolve re-runs it (self-heal) while the\n\t\t\t\t// error still surfaces below\n\t\t\t\tresubscribeSuspendSources(effect);\n\t\t\t\tif (unhandledError === null) {\n\t\t\t\t\tunhandledError = { error: err };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Clear the queue and reset the queued flag defensively (every processed\n\t// effect already reset its own, but an error may have skipped a run)\n\tfor (let effect of queue) {\n\t\teffect.queued = false;\n\t}\n\tcontext.effectsToRun = [];\n\n\t// Clear unused target subscriptions for the signals that were updated\n\t// during the batch\n\tlet signal: ProxySignal | null = context.firstSignalToUpdate;\n\tcontext.firstSignalToUpdate = null;\n\tcontext.lastSignalToUpdate = null;\n\twhile (signal !== null) {\n\t\tclearTargets(signal);\n\n\t\tconst nextSignal = signal.nextSignalToUpdate;\n\t\tsignal.nextSignalToUpdate = null;\n\t\tsignal = nextSignal;\n\t}\n\n\tif (unhandledError !== null) {\n\t\tthrow unhandledError.error;\n\t}\n}\n","import context from \"../render/context\";\nimport triggerEffects from \"./triggerEffects\";\n\nexport default function batchEnd(): void {\n\tif (context.batch > 1) {\n\t\tcontext.batch--;\n\t\treturn;\n\t}\n\n\ttry {\n\t\ttriggerEffects();\n\t} finally {\n\t\tcontext.batch = 0;\n\t\tcontext.batchOperation = 0;\n\t\tcontext.previousEffect = null;\n\t}\n}\n","import context from \"../render/context\";\n\nexport default function batchStart(): void {\n\tcontext.batch++;\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport clearSources from \"./clearSources\";\n\nexport default function runEffect(effect: Effect): void {\n\t//console.log(`running effect '${effect.name}'`);\n\n\t// DEV:\n\tdevContext.effectRun(effect);\n\n\t// Store the active target\n\tconst oldActiveTarget = context.activeTarget;\n\tconst oldExtent = context.extent;\n\n\teffect.didError = false;\n\teffect.errorSources = null;\n\t// Reset the per-run suspend state, so `didSuspend` reflects the run that\n\t// is about to happen and `suspendSources` doesn't re-subscribe reads\n\t// from a previous run (see triggerEffects)\n\teffect.didSuspend = false;\n\teffect.suspendSources = null;\n\n\tbatchStart();\n\n\ttry {\n\t\t// Set the next effect for navigating through\n\t\tif (context.previousEffect !== null) {\n\t\t\tcontext.previousEffect.nextEffect = effect;\n\t\t}\n\n\t\t// Set the active effect, so that any properties accessed while running it\n\t\t// will trigger it in future\n\t\tcontext.activeTarget = effect;\n\t\tcontext.previousEffect = effect;\n\t\tcontext.extent = 1;\n\n\t\t// Run the effect to register its subscriptions and get its (optional)\n\t\t// cleanup function\n\t\teffect.cleanup = effect.run();\n\n\t\teffect.extent = context.extent;\n\t} catch (err) {\n\t\teffect.didError = true;\n\t\t// Capture the source signals before clearing them, so an error\n\t\t// boundary can hold them for recovery (see routeEffectError) — the\n\t\t// effect's own subscriptions are about to be detached, and without\n\t\t// them the boundary would never re-attempt its try branch\n\t\tlet sources: (ProxySignal | Computed)[] | null = null;\n\t\tfor (let sub = effect.firstSource; sub !== null; sub = sub.nextSource) {\n\t\t\t(sources ??= []).push(sub.source);\n\t\t}\n\t\teffect.errorSources = sources;\n\t\tclearSources(effect);\n\t\tthrow err;\n\t} finally {\n\t\t// Set the active target back to what it was previously\n\t\tcontext.activeTarget = oldActiveTarget;\n\t\tcontext.extent += oldExtent - 1;\n\n\t\tbatchEnd();\n\t}\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\nimport type Effect from \"../types/Effect\";\nimport { EFFECT_TYPE } from \"../types/constants\";\nimport runEffect from \"./runEffect\";\n\n// TODO: Take a pipeline of operators e.g. debounce\n\n/**\n * Runs and re-runs a function that depends on a watched object\n *\n * @param fn The function to run, which may return a cleanup function.\n * @param options Internal fields to set on the constructed Effect (e.g.\n * `isMountEffect`, `forVarDeps`). Not part of the public API.\n */\nexport default function $run(\n\tfn: () => Cleanup | void,\n\tname?: string,\n\toptions?: Pick<Effect, \"isMountEffect\" | \"forVarMask\">,\n): Effect {\n\tlet effect: Effect = {\n\t\ttype: EFFECT_TYPE,\n\t\trun: fn,\n\t\tcleanup: undefined,\n\t\tfirstSource: null,\n\t\tnextEffect: null,\n\t\textent: 0,\n\t\tqueued: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tregion: null,\n\t\terrorSources: null,\n\t\tname,\n\t\tisMountEffect: options?.isMountEffect,\n\t\tforVarMask: options?.forVarMask,\n\t};\n\n\t// Track the effect on the current active region, so it can be\n\t// cleaned up when the region is cleared\n\tconst region = context.activeRegion;\n\tif (region !== null) {\n\t\tregion.effects.push(effect);\n\t\teffect.region = region;\n\t}\n\n\t// DEV:\n\tdevContext.onRun(effect);\n\n\trunEffect(effect);\n\n\treturn effect;\n}\n","import context from \"../render/context\";\n\n/**\n * Runs a function without tracking the reactive values it reads: `$watch`'d\n * state accessed inside `fn` does not become a dependency of the currently\n * running effect or computed. Useful for reading state inside an effect\n * without re-running it when that state changes.\n *\n * @param fn The function to run untracked.\n */\nexport default function $peek<T>(fn: () => T): T {\n\tconst oldActiveTarget = context.activeTarget;\n\tcontext.activeTarget = null;\n\n\tconst result = fn();\n\n\tcontext.activeTarget = oldActiveTarget;\n\n\treturn result;\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\nimport { EFFECT_TYPE } from \"../types/constants\";\nimport $peek from \"./$peek\";\nimport $run from \"./$run\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\n\n/**\n * Runs the collected `$onmount`/`onmount` callbacks — once, after the\n * component's markup has been added to the DOM (or, when hydrating, after\n * hydration is complete). Multiple callbacks run in the order they were\n * added.\n *\n * Each callback becomes an effect with `isMountEffect` set, so the keyed-list\n * reconciler's force-rerun path (`rerunRegionEffects`) skips it. Its body\n * also runs untracked: mount callbacks are once-only, so reactive reads\n * inside them do not subscribe. In dev builds a tracked pass warns when a\n * callback reads reactive state, since that is almost always a mistake — the\n * reactive part should be wrapped in `$run`.\n */\nexport default function flushMountEffects(): void {\n\tif (context.mountEffects.length === 0) return;\n\tconst activeRegion = context.activeRegion;\n\tfor (let effect of context.mountEffects) {\n\t\tcontext.activeRegion = effect.region;\n\t\t$run(() => runMountCallback(effect.fn), undefined, { isMountEffect: true });\n\t}\n\tcontext.activeRegion = activeRegion;\n\tcontext.mountEffects.length = 0;\n}\n\nfunction runMountCallback(fn: () => Cleanup | void): Cleanup | void {\n\tif (!devContext.enabled) {\n\t\t// Mount callbacks run once — reads inside must not create subscriptions\n\t\treturn $peek(fn);\n\t}\n\n\t// DEV: run tracked so stray reactive reads can be detected, then detach\n\t// the subscriptions so the effect still never re-runs\n\tconst result = fn();\n\n\tconst effect = context.activeTarget;\n\tif (effect !== null && effect.type === EFFECT_TYPE && effect.firstSource !== null) {\n\t\tconsole.warn(\n\t\t\t\"[torpor] A $onmount/onmount callback read reactive state, but mount callbacks \" +\n\t\t\t\t\"run only once and will not re-run. Wrap the reactive part in $run(), \" +\n\t\t\t\t\"e.g. $onmount(() => { $run(() => ...); });\",\n\t\t);\n\t\tdeactivateSources(effect);\n\t\tclearSources(effect);\n\t}\n\n\treturn result;\n}\n","import context from \"./context\";\n\n/**\n * Adds an animation for an element\n * @param el The element to animate\n * @param enter Whether the animation is being run on enter\n * @param keyframes The Web Animation API keyframes\n * @param options The Web Animmation API options\n */\nexport default async function animate(\n\tel: HTMLElement,\n\tenter: boolean,\n\tkeyframes: Keyframe[] | PropertyIndexedKeyframes | null,\n\toptions?: number | KeyframeAnimationOptions,\n): Promise<void> {\n\t// This is quite simplistic\n\t// We might need to\n\t// - store the animation\n\t// - reverse it if it's running and the region appears/disappears\n\t// - transfer the animation to the new element\n\tlet animationOptions = Object.assign(\n\t\t{\n\t\t\tdirection: enter ? \"normal\" : \"reverse\",\n\t\t\t// TODO: Should probably have a global setting for these somewhere\n\t\t\t// And respect browser reduce motion settings\n\t\t\tduration: 300,\n\t\t\teasing: \"ease-in-out\",\n\t\t\tfill: \"forwards\",\n\t\t},\n\t\toptions,\n\t);\n\n\tconst animation = el.animate(keyframes, animationOptions);\n\n\t// HACK: I'm not entirely sure why we need to sent the animation's timeline,\n\t// but without it, animations never start\n\t// HACK: We also need to make sure the element has been added to the DOM\n\t// with a timeout\n\tsetTimeout(() => {\n\t\tanimation.timeline = el.ownerDocument.timeline;\n\t}, 1);\n\n\t// Add the animation to the active region, so that the region won't be cleared\n\t// until the animation is completed\n\tconst activeRegion = context.activeRegion;\n\t// TODO: An option for whether to await or cancel events on region remove\n\t// e.g. if you are doing a client side navigation, you don't want to run animations\n\tactiveRegion.animations ??= new Set();\n\tactiveRegion.animations.add(animation);\n\n\tawait animation.finished;\n}\n","/**\n * Event delegation.\n *\n * For event types in `DELEGATED_EVENT_TYPES` (all natively bubbling), we\n * register a single listener on `document` per type and dispatch by walking\n * up from `event.target` to find the closest ancestor with a stashed handler.\n * This replaces per-element `addEventListener` for delegated types.\n *\n * Why: in the js-framework-bench row template, every `<tr>` clones two `<a>`\n * elements each with a `click` handler. With per-element `addEventListener`,\n * `runlots` (10k rows) issues 20000 `addEventListener` calls and the browser\n * allocates 20000 `Listener` objects. With delegation it's 2 calls total\n * (one per delegated type, registered lazily on first use) and zero\n * per-element `Listener` allocations — the handler is stored as a property\n * on the element.\n *\n * Model: last-write-wins per element per type (same as Solid's\n * `delegateEvents`). Repeated `t_event(el, \"click\", h)` calls with the same\n * element reassign the property; calling with `null`/`undefined` clears it.\n * Torpor's compiler emits `t_event(el, type, h)` exactly once per element\n * lifetime (outside any tracked effect), so this is the natural shape.\n *\n * Non-bubbling events (`focus`, `blur`, `scroll`, `load`, `error`, `abort`,\n * `unload`, `resize`, etc.) bypass delegation and use direct\n * `addEventListener` on the element, preserving native semantics.\n */\n\nconst DELEGATED_EVENT_TYPES: ReadonlySet<string> = new Set([\n\t\"auxclick\",\n\t\"beforeinput\",\n\t\"change\",\n\t\"click\",\n\t\"compositionend\",\n\t\"compositionstart\",\n\t\"compositionupdate\",\n\t\"contextmenu\",\n\t\"dblclick\",\n\t\"drag\",\n\t\"dragend\",\n\t\"dragenter\",\n\t\"dragleave\",\n\t\"dragover\",\n\t\"dragstart\",\n\t\"drop\",\n\t\"focusin\",\n\t\"focusout\",\n\t\"input\",\n\t\"keydown\",\n\t\"keypress\",\n\t\"keyup\",\n\t\"mousedown\",\n\t\"mousemove\",\n\t\"mouseout\",\n\t\"mouseover\",\n\t\"mouseup\",\n\t\"pointerdown\",\n\t\"pointermove\",\n\t\"pointerout\",\n\t\"pointerover\",\n\t\"pointerup\",\n\t\"reset\",\n\t\"submit\",\n\t\"touchend\",\n\t\"touchmove\",\n\t\"touchstart\",\n\t\"wheel\",\n]);\n\nexport function isDelegatedEventType(type: string): boolean {\n\treturn DELEGATED_EVENT_TYPES.has(type);\n}\n\n// Property name on each element holding the handler for a given type.\n// Matches Solid's `$$`-prefixed convention. Single string property per type,\n// so there's no per-element Map allocation — just a named slot on the element.\nconst DELEGATE_PREFIX = \"torp.$$\";\n\n// Marker on `document` tracking which types already have a listener\n// registered. Storing on `document` (rather than a module-scoped Set) means\n// the registration state is correctly scoped to the current document —\n// important for tests that swap the global document (rare, but possible).\nconst DELEGATE_REGISTERED = Symbol.for(\"torp.delegated.registered\");\n\nfunction delegatedHandler(event: Event): void {\n\tlet node: Node | null = event.target as Node | null;\n\tconst stopAt: Node | null = event.currentTarget as Node | null;\n\tconst key = DELEGATE_PREFIX + event.type;\n\t// Walk from the deepest target up to (but not including) the listener\n\t// node (document). First ancestor with a stashed handler wins.\n\twhile (node != null && node !== stopAt) {\n\t\tconst handler = (node as any)[key];\n\t\tif (handler !== undefined) {\n\t\t\t// Override `currentTarget` so the user's handler sees the element\n\t\t\t// the handler was attached to, not `document`. `currentTarget`\n\t\t\t// is otherwise read-only. Configurable so the override can be\n\t\t\t// removed below.\n\t\t\tObject.defineProperty(event, \"currentTarget\", {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: node,\n\t\t\t\twritable: false,\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t(handler as (this: Node, ev: Event) => any).call(node, event);\n\t\t\t} finally {\n\t\t\t\t// Remove the override so the prototype getter takes over\n\t\t\t\t// again (returns `null` once dispatch completes).\n\t\t\t\tdelete (event as any).currentTarget;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tnode = node.parentNode;\n\t}\n}\n\nfunction ensureDelegatedListener(type: string): void {\n\tif (typeof document === \"undefined\") return;\n\tlet registered = (document as any)[DELEGATE_REGISTERED] as Set<string> | undefined;\n\tif (!registered) {\n\t\tregistered = new Set();\n\t\t(document as any)[DELEGATE_REGISTERED] = registered;\n\t}\n\tif (registered.has(type)) return;\n\tregistered.add(type);\n\t// Bubble phase (default). All events in DELEGATED_EVENT_TYPES bubble, so\n\t// the listener at `document` fires after the event has traversed the\n\t// target and any intermediary elements — matching the natural event flow\n\t// the user expects from `addEventListener` on the element itself.\n\tdocument.addEventListener(type, delegatedHandler);\n}\n\n/**\n * Attach a delegated event handler to an element.\n *\n * Stores the handler as a property on the element and ensures a single\n * document-level listener exists for the type. Idempotent for the\n * document-level listener: the first call for a given type registers it,\n * subsequent calls are a Set-has check.\n *\n * Passing `null` or `undefined` as the listener clears any previously-set\n * handler for that type on the element (mirroring `addEvent`'s existing\n * null-skipping semantics, extended to support explicit removal).\n */\nexport function attachDelegatedEvent(\n\tel: Element,\n\ttype: string,\n\tlistener: ((this: Element, ev: any) => any) | undefined | null,\n): void {\n\tconst key = DELEGATE_PREFIX + type;\n\tif (listener === undefined || listener === null) {\n\t\t(el as any)[key] = undefined;\n\t\treturn;\n\t}\n\tensureDelegatedListener(type);\n\t(el as any)[key] = listener;\n}\n\n// Property on an element recording its direct (non-delegated) listeners, so\n// a dynamic-element tag swap (`t_dynamic`) can re-attach them. Direct\n// listeners are the rare path (focus, blur, scroll, …), so the extra\n// per-element array is acceptable next to the delegated-handler slots.\nconst DIRECT_LISTENERS = \"torp.$directListeners\";\n\n/**\n * Records a direct (non-delegated) listener on the element at attach time,\n * so `copyEventListeners` can re-attach it after a dynamic-element tag\n * swap. `addEventListener` listeners can't be discovered after the fact.\n */\nexport function recordDirectListener(\n\tel: Element,\n\ttype: string,\n\tlistener: (this: Element, ev: any) => any,\n): void {\n\tlet list = (el as any)[DIRECT_LISTENERS] as\n\t\t| { type: string; listener: (this: Element, ev: any) => any }[]\n\t\t| undefined;\n\tif (!list) {\n\t\tlist = [];\n\t\t(el as any)[DIRECT_LISTENERS] = list;\n\t}\n\tlist.push({ type, listener });\n}\n\n/**\n * Copies the event listeners attached to one element onto another — used by\n * `t_dynamic` so a dynamic element keeps its listeners when its tag changes.\n * Delegated handlers are `torp.$$<type>` properties, copied per known\n * delegated type (swaps are rare, so the fixed set of checks is fine);\n * direct listeners are re-registered from the list `recordDirectListener`\n * built at attach time.\n */\nexport function copyEventListeners(from: Element, to: Element): void {\n\tfor (const type of DELEGATED_EVENT_TYPES) {\n\t\tconst key = DELEGATE_PREFIX + type;\n\t\tconst handler = (from as any)[key];\n\t\tif (handler !== undefined) {\n\t\t\t(to as any)[key] = handler;\n\t\t}\n\t}\n\tconst direct = (from as any)[DIRECT_LISTENERS] as\n\t\t| { type: string; listener: (this: Element, ev: any) => any }[]\n\t\t| undefined;\n\tif (direct) {\n\t\t(to as any)[DIRECT_LISTENERS] = direct;\n\t\tfor (const { type, listener } of direct) {\n\t\t\tto.addEventListener(type, listener);\n\t\t}\n\t}\n}\n","export default function isFragmentNode(node: Node): node is DocumentFragment {\n\treturn node.nodeType === 11;\n}\n","import type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport flushMountEffects from \"../watch/flushMountEffects\";\nimport animate from \"./animate\";\nimport context from \"./context\";\nimport {\n\tattachDelegatedEvent,\n\tisDelegatedEventType,\n\trecordDirectListener,\n} from \"./delegatedEvents\";\nimport isFragmentNode from \"./isFragmentNode\";\n\n/**\n * Runs the mount-time side effects that both `addFragment` and `addElement`\n * share: `$onmount` effects (only when not hydrating), stashed event\n * listeners, and stashed animations. No-op when `parent` is itself a\n * `DocumentFragment` (we're being inserted into a detached tree, so\n * `$onmount` and event hookup would be premature — they'll run when the\n * outer fragment attaches).\n *\n * Extracted so the `DocumentFragment` path (`addFragment`) and the\n * single-element path (`addElement`) don't duplicate this logic.\n */\nexport default function runMountSideEffects(\n\tparent: ParentNode,\n\tactiveRegion: Region,\n\thydrationNode: Node | null,\n): void {\n\tif (isFragmentNode(parent)) return;\n\n\t// Only run $onmount effects if not hydrating (if hydrating, they will get\n\t// run at the end when everything is hooked up)\n\tif (hydrationNode === null) {\n\t\tflushMountEffects();\n\t}\n\n\t// Attach event listeners. For bubbling event types (the majority —\n\t// `click`, `input`, `change`, `keydown`, …) we delegate: a single\n\t// listener per type lives on `document`, and each element's handler is\n\t// stored as a property. This avoids N `addEventListener` calls per N-row\n\t// list (js-framework-bench `runlots` goes from 20000 calls to 2) and the\n\t// matching browser-side `Listener` allocations. Non-bubbling types\n\t// (`focus`, `blur`, `scroll`, …) fall back to direct `addEventListener`\n\t// on the element. Listeners are not tied to region lifecycle — when an\n\t// element is removed from the DOM, its handler property is GC'd with it.\n\tif (context.stashedEvents.length > 0) {\n\t\tfor (let event of context.stashedEvents) {\n\t\t\tif (isDelegatedEventType(event.type)) {\n\t\t\t\tattachDelegatedEvent(event.el, event.type, event.listener);\n\t\t\t} else {\n\t\t\t\tevent.el.addEventListener(event.type, event.listener);\n\t\t\t\t// Record it on the element, so a dynamic-element tag swap\n\t\t\t\t// (t_dynamic) can re-attach the listener on the new element\n\t\t\t\trecordDirectListener(event.el, event.type, event.listener);\n\t\t\t}\n\t\t}\n\t\tcontext.stashedEvents.length = 0;\n\t}\n\n\t// Set the active region for each animation so it will get attached to\n\t// the right one and set it back afterwards\n\t// Don't await animations\n\tfor (let animation of context.stashedAnimations) {\n\t\tcontext.activeRegion = animation.region;\n\t\t$run(function runMountSideEffectsAnimation() {\n\t\t\tif (animation.in !== undefined) {\n\t\t\t\t// eslint-disable-next-line no-floating-promises\n\t\t\t\tanimate(animation.el, true, animation.in.keyframes, animation.in.options);\n\t\t\t}\n\t\t\tif (animation.out !== undefined) {\n\t\t\t\treturn () => {\n\t\t\t\t\t// eslint-disable-next-line no-floating-promises\n\t\t\t\t\tanimate(animation.el, false, animation.out!.keyframes, animation.out!.options);\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\t}\n\tcontext.stashedAnimations.length = 0;\n\n\t// Set the active region back\n\tcontext.activeRegion = activeRegion;\n}\n","import context from \"./context\";\nimport runMountSideEffects from \"./runMountSideEffects\";\n\n/**\n * Companion to `addFragment` for the single-root-element codegen path. Wires\n * a cloned root element (produced by `getElementFragment`) into the live DOM\n * tree, sets the active region's start/end nodes, and runs the same\n * mount-time side effects as `addFragment` (`$onmount` effects, stashed event\n * listeners, stashed animations).\n *\n * Differences from `addFragment`:\n * - `node` is both the start and end of the region (no\n * `fragment.firstChild`/`fragment.lastChild` indirection).\n * - When hydrating, the existing DOM node is reused (the cloned `node` is\n * discarded); `endNode` is still `node` because `nodeRootElement` returns\n * the hydration cursor's node in that case, not the cloned one.\n *\n * @param node The root element (cloned by `getElementFragment`, or the\n * hydration cursor's node when hydrating).\n * @param parent The intended parent element.\n * @param before The sibling to insert before (or `null` to append).\n */\nexport default function addElement(node: Element, parent: ParentNode, before: Node | null): void {\n\tconst activeRegion = context.activeRegion;\n\tconst hydrationNode = context.hydrationNode;\n\n\t// The single root element is both the start and the end of the region.\n\t// When hydrating, `node` is already the existing DOM node (returned by\n\t// `nodeRootElement`'s cursor walk), so this is correct in both branches.\n\tactiveRegion.startNode = node;\n\tactiveRegion.endNode = node;\n\n\tparent = before?.parentNode ?? parent;\n\n\t// Add the node\n\tif (hydrationNode === null) {\n\t\tparent.insertBefore(node, before);\n\t}\n\n\t// If we're adding this node to the DOM, we can now run any $onmount\n\t// effects, add our stashed events and play our stashed animations\n\trunMountSideEffects(parent, activeRegion, hydrationNode);\n}\n","import context from \"./context\";\nimport runMountSideEffects from \"./runMountSideEffects\";\n\nexport default function addFragment(\n\tfragment: DocumentFragment,\n\tparent: ParentNode,\n\tbefore: Node | null,\n\tendNode?: ChildNode,\n\tstartNode?: ChildNode,\n): void {\n\t//console.log(`adding fragment '${fragment.textContent}' to `, parent);\n\t//console.log(\"before\", before);\n\n\tconst activeRegion = context.activeRegion;\n\tconst hydrationNode = context.hydrationNode;\n\n\t// Set the active region's start/end nodes to the first and last nodes in\n\t// the fragment. During hydration, child component rendering (via\n\t// `addElement`) may have overwritten these — the `startNode` parameter\n\t// (the root node) restores the correct bounds. But when the root node was\n\t// a hydration start marker, `nodeAnchor` will have removed it from the\n\t// DOM and set the region's start node to the first node inside the block\n\t// — restoring the removed marker here would leave the region with a\n\t// detached start node (which breaks clearing the region later).\n\tif (hydrationNode !== null) {\n\t\tif (startNode !== undefined && startNode.parentNode !== null) {\n\t\t\tactiveRegion.startNode = startNode;\n\t\t}\n\t\tactiveRegion.endNode = endNode ?? hydrationNode;\n\t} else {\n\t\tactiveRegion.startNode = fragment.firstChild;\n\t\tactiveRegion.endNode = fragment.lastChild;\n\t}\n\n\tparent = before?.parentNode ?? parent;\n\n\t// Add the fragment\n\tif (hydrationNode === null) {\n\t\tparent.insertBefore(fragment, before);\n\t}\n\n\t// If we're adding this fragment to the DOM, we can now run any $onmount\n\t// effects, add our stashed events and play our stashed animations\n\trunMountSideEffects(parent, activeRegion, hydrationNode);\n}\n","import $run from \"../watch/$run\";\nimport { attachDelegatedEvent, isDelegatedEventType } from \"./delegatedEvents\";\n\nexport default function applyProps(\n\tel: Element,\n\tprops: Record<string, any> | undefined,\n\tpropNamesUsed: string[],\n): void {\n\tif (props !== undefined) {\n\t\tfor (let [name, value] of Object.entries(props)) {\n\t\t\tif (!propNamesUsed.includes(name)) {\n\t\t\t\tif (name.startsWith(\"on\")) {\n\t\t\t\t\tconst eventName = name.substring(2);\n\t\t\t\t\tif (isDelegatedEventType(eventName)) {\n\t\t\t\t\t\tattachDelegatedEvent(el, eventName, value);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tel.addEventListener(eventName, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t$run(function setAttribute() {\n\t\t\t\t\t\tel.setAttribute(name, value);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\n\nexport default function clearRegion(region: Region): void {\n\t//console.log(\"clearing region\", region.name, \"from\", region.startNode, \"to\", region.endNode);\n\n\t// DEV:\n\tdevContext.onRegionCleared(region);\n\n\t// Clear child regions and collect animations that take place within this\n\t// region and its children\n\tlet animations: Animation[] | undefined =\n\t\tregion.animations !== null ? Array.from(region.animations) : undefined;\n\tlet childRegion = region.nextRegion;\n\twhile (childRegion !== null && childRegion.depth > region.depth) {\n\t\tif (childRegion.animations !== null) {\n\t\t\tanimations ??= [];\n\t\t\tanimations.push(...childRegion.animations);\n\t\t}\n\t\tconst nextChild = childRegion.nextRegion;\n\t\treleaseRegion(childRegion);\n\t\t// HACK: see runControlBranch\n\t\tchildRegion.depth = -2;\n\t\tchildRegion = nextChild;\n\t}\n\tregion.nextRegion = childRegion;\n\n\tif (region.previousRegion !== null) {\n\t\tregion.previousRegion.nextRegion = region.nextRegion;\n\t}\n\tif (region.nextRegion !== null) {\n\t\tregion.nextRegion.previousRegion = region.previousRegion;\n\t}\n\n\t// Wait for animations, if any, then clear the region's nodes\n\tif (animations !== undefined) {\n\t\tanimations.forEach((a) => {\n\t\t\ta.reverse();\n\t\t\ta.play();\n\t\t});\n\t\t// eslint-disable-next-line no-floating-promises\n\t\tPromise.all(animations.map((a) => a.finished)).then(() => clearNodes(region));\n\t} else {\n\t\tclearNodes(region);\n\t}\n}\n\nfunction clearNodes(region: Region) {\n\t// Clear the nodes for this region\n\tif (region.startNode !== null && region.endNode !== null) {\n\t\t// The node that follows the region's content, captured before any\n\t\t// removal — after the backward walk below, it is the first remaining\n\t\t// node at the region's position (e.g. the control's anchor that\n\t\t// branch content was rendered before).\n\t\tconst after = region.endNode.nextSibling;\n\n\t\t// The stop boundary is normally the region's own start node. But when\n\t\t// an inner control (e.g. an @if inside a @for item) has re-rendered and\n\t\t// replaced the nodes the start node originally pointed at, the start\n\t\t// node becomes detached from the DOM. In that case fall back to the\n\t\t// preceding sibling region's end node (walking past any deeper child\n\t\t// regions that link this region to its sibling), so we only clear this\n\t\t// region's content instead of walking past it into a previous sibling.\n\t\tlet stop: Node | null = region.startNode;\n\t\tconst startDetached = region.startNode.parentNode === null;\n\t\tlet fallback = false;\n\t\tif (startDetached) {\n\t\t\tlet prev: Region | null = region.previousRegion;\n\t\t\twhile (prev !== null && prev.depth > region.depth) {\n\t\t\t\tprev = prev.previousRegion;\n\t\t\t}\n\t\t\tif (prev !== null && prev.endNode !== null && prev.endNode.parentNode !== null) {\n\t\t\t\tstop = prev.endNode;\n\t\t\t\tfallback = true;\n\t\t\t}\n\t\t}\n\t\tlet currentNode = region.endNode;\n\t\twhile (currentNode !== null && currentNode !== stop) {\n\t\t\tlet previousNode = currentNode.previousSibling;\n\t\t\tcurrentNode.remove();\n\t\t\tif (previousNode === null) {\n\t\t\t\t// The region's node chain is no longer connected — everything\n\t\t\t\t// that still needs clearing has been cleared.\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentNode = previousNode;\n\t\t}\n\t\t// When clearing against the region's own start node, remove it too.\n\t\t// When using the fallback (previous sibling's end node), leave it — it\n\t\t// belongs to the sibling.\n\t\tif (!fallback && currentNode === region.startNode) {\n\t\t\tcurrentNode.remove();\n\t\t}\n\n\t\t// Repair ancestor node windows whose start node was just removed.\n\t\t//\n\t\t// When a control branch's content is cleared, ancestor regions whose\n\t\t// window was WIDENED to that content (see widenAncestorsAtAnchor) are\n\t\t// left with a detached startNode. A later moveRegion on such an\n\t\t// ancestor would resurrect the detached node (insertBefore re-attaches\n\t\t// it). Reset any detached ancestor start to the first node that\n\t\t// remains at the cleared position: the node after the removed span —\n\t\t// `after`, or `stop` when the fallback kept the preceding sibling's\n\t\t// end node as the boundary.\n\t\tconst firstRemaining = (fallback ? stop : after) as ChildNode | null;\n\t\tif (firstRemaining !== null) {\n\t\t\tlet ancestor: Region | null = region.previousRegion;\n\t\t\tlet ancestorDepth = region.depth;\n\t\t\twhile (ancestor !== null && ancestor.depth < ancestorDepth) {\n\t\t\t\tif (ancestor.startNode !== null && ancestor.startNode.parentNode === null) {\n\t\t\t\t\tancestor.startNode = firstRemaining;\n\t\t\t\t}\n\t\t\t\tancestorDepth = ancestor.depth;\n\t\t\t\tancestor = ancestor.previousRegion;\n\t\t\t}\n\t\t}\n\t}\n\treleaseRegion(region);\n}\n\nfunction releaseRegion(region: Region) {\n\t(region as any).generation = -1;\n\tregion.startNode = null;\n\tregion.endNode = null;\n\tregion.previousRegion = null;\n\tregion.nextRegion = null;\n\tregion.animations = null;\n\t// Detach any error boundary: the region (and the effects that could\n\t// route errors to it) is being released, and its boundary effect is\n\t// destroyed with its owning region\n\tregion.errorBoundary = undefined;\n\n\t// Clean up effects owned by this region. For each effect we both run its\n\t// optional cleanup function AND detach every source subscription from the\n\t// source signal's `firstTarget` list. Without the detach, the destroyed\n\t// effect stays in `signal.firstTarget` forever — every subsequent change\n\t// to any of its sources re-queues the (no-longer-reachable-via-DOM)\n\t// effect, which re-runs, re-subscribes, and leaks indefinitely. This is\n\t// the dominant cost in long-lived sessions where list items are\n\t// repeatedly created and cleared (e.g. js-framework-bench iterations).\n\tfor (const effect of region.effects) {\n\t\tif (typeof effect.cleanup === \"function\") {\n\t\t\teffect.cleanup();\n\t\t\teffect.cleanup = undefined;\n\t\t}\n\n\t\t// Detach every source subscription from its signal's target list.\n\t\t// `clearSources` only removes subscriptions marked inactive, but a\n\t\t// freshly-destroyed effect's subscriptions are still active (they\n\t\t// were never marked inactive because the effect was never re-run),\n\t\t// so we walk and unlink explicitly.\n\t\tlet sub = effect.firstSource;\n\t\teffect.firstSource = null;\n\t\twhile (sub !== null) {\n\t\t\tconst nextSource = sub.nextSource;\n\n\t\t\t// Unlink this subscription from the signal's target list (the\n\t\t\t// doubly-linked `previousTarget`/`nextTarget` chain).\n\t\t\tconst prev = sub.previousTarget;\n\t\t\tconst next = sub.nextTarget;\n\t\t\tif (prev === null) {\n\t\t\t\t// We're the head of the signal's target list — promote the\n\t\t\t\t// next target, but only if we still are the head. A popular\n\t\t\t\t// signal may have had new subscriptions prepended since this\n\t\t\t\t// sub was created, in which case `firstTarget` no longer\n\t\t\t\t// points at us and the head has already moved on.\n\t\t\t\tif (sub.source.firstTarget === sub) {\n\t\t\t\t\tsub.source.firstTarget = next;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tprev.nextTarget = next;\n\t\t\t}\n\t\t\tif (next !== null) {\n\t\t\t\tnext.previousTarget = prev;\n\t\t\t}\n\n\t\t\t// Clear pointers so this subscription is no longer reachable\n\t\t\t// from either list, even transitively.\n\t\t\tsub.previousTarget = null;\n\t\t\tsub.nextTarget = null;\n\t\t\tsub.nextSource = null;\n\n\t\t\tsub = nextSource;\n\t\t}\n\t}\n\tregion.effects.length = 0;\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\n\n/**\n * Clears a region that was created by `fillLayoutSlot`: tears down the\n * rendered content and its effects, leaving the surrounding layout intact\n * so the slot can be refilled.\n *\n * @param region The region to clear\n */\nexport default function clearLayoutSlot(region: Region): void {\n\tcontext.previousRegion = region.previousRegion!;\n\tclearRegion(region);\n}\n","import type Region from \"../types/Region\";\n\nexport default function newRegion(name?: string): Region {\n\treturn {\n\t\tstartNode: null,\n\t\tendNode: null,\n\t\tpreviousRegion: null,\n\t\tnextRegion: null,\n\t\tdepth: -1,\n\t\tanimations: null,\n\t\tname,\n\t\teffects: [],\n\t};\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\nimport context from \"./context\";\n\nexport default function popRegion(oldRegion: Region): void {\n\tcontext.activeRegion = oldRegion;\n\n\tdevContext.onRegionPopped();\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\nimport context from \"./context\";\n\nexport default function pushRegion(region: Region, toParent = false): Region {\n\tconst activeRegion = context.activeRegion;\n\n\t// Add the new region to the currently active region's children, so that we\n\t// can delete the children with the parent\n\tif (toParent) {\n\t\tconst previousRegion = context.previousRegion;\n\t\tregion.previousRegion = previousRegion;\n\n\t\tconst nextRegion = previousRegion.nextRegion;\n\t\tpreviousRegion.nextRegion = region;\n\t\tregion.nextRegion = nextRegion;\n\t\t// Keep the sibling chain doubly-linked: the region we displaced must\n\t\t// point back at us. Without this, `clearRegion`'s unlink\n\t\t// (`region.previousRegion.nextRegion = region.nextRegion`) writes\n\t\t// through a stale back-pointer and detaches live regions.\n\t\tif (nextRegion !== null) {\n\t\t\tnextRegion.previousRegion = region;\n\t\t}\n\n\t\tregion.depth = activeRegion.depth + 1;\n\t}\n\n\t// Set the new active region\n\tcontext.activeRegion = region;\n\tcontext.previousRegion = region;\n\n\t// DEV:\n\tdevContext.onRegionPushed(region, toParent);\n\n\t// Return the old active region, so that it can be reset when done\n\treturn activeRegion;\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type Region from \"../types/Region\";\nimport type SlotRender from \"../types/SlotRender\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Renders a component into a persistent layout slot, and returns the region\n * it was rendered into. Used by the layout engine during navigation: the\n * component is created inside `parent` at `anchor`, with `slot` as its child\n * slot render, and the returned region can later be passed to\n * `clearLayoutSlot` to tear the page down — leaving the layout itself\n * intact — before refilling the slot.\n *\n * @param component The component to render into the slot\n * @param slot The slot render to pass to the component\n * @param parent The parent node to render into\n * @param anchor The node to insert content before, or null to append\n * @param $props Optional props to pass to the component\n * @param $context Optional context to pass to the component\n */\nexport default function fillLayoutSlot(\n\tcomponent: Component,\n\tslot: SlotRender,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\t$props?: Record<PropertyKey, any>,\n\t$context?: Record<PropertyKey, any>,\n): Region {\n\tconst region = newRegion(devContext.enabled ? \"Layout slot\" : undefined);\n\tconst oldRegion = pushRegion(region, true);\n\n\tcomponent(parent, anchor, $props, $context, {\n\t\t_: slot,\n\t});\n\n\tpopRegion(oldRegion);\n\n\treturn region;\n}\n","/**\n * During hydration, `nodeAnchor` finds the first node inside a hydration\n * block and removes the start/end marker comments. Generated code for\n * `@html` needs that first node later (to adopt the server-rendered nodes\n * as the region's bounds), but by then the markers are gone — so the only\n * reliable way to recover it is to stash it here, keyed by the anchor node\n * that `nodeAnchor` returns.\n */\nconst firstInsideNodes = new WeakMap<ChildNode, ChildNode | null>();\n\nexport function setFirstInsideNode(anchor: ChildNode, node: ChildNode | null): void {\n\tfirstInsideNodes.set(anchor, node);\n}\n\n/**\n * Gets the first node that was inside the hydration block for the given\n * anchor node, or `undefined` if the anchor wasn't hydrated through\n * hydration markers.\n */\nexport default function firstInsideNode(anchor: ChildNode): ChildNode | null | undefined {\n\treturn firstInsideNodes.get(anchor);\n}\n","export default function getFragment(\n\tdocument: Document,\n\tarray: DocumentFragment[],\n\tindex: number,\n\thtml: string,\n\tns?: boolean,\n): DocumentFragment {\n\t// Create the fragment in the array if it hasn't yet been used\n\tif (array[index] === undefined) {\n\t\t// TODO: Should pass a string for the ns, when we support other element types\n\t\tif (ns === true) {\n\t\t\tconst template = document.createElementNS(\"http://www.w3.org/2000/svg\", \"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tconst fragment = new DocumentFragment();\n\t\t\tfragment.append(...template.childNodes);\n\t\t\tarray[index] = fragment;\n\t\t} else {\n\t\t\tconst template = document.createElement(\"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.content;\n\t\t}\n\t}\n\n\t// Get the fragment from the array\n\t// TODO: If we're hydrating we probably don't want to create and return a\n\t// fragment unless we really need to\n\tlet fragment = array[index].cloneNode(true) as DocumentFragment;\n\n\treturn fragment;\n}\n","/**\n * Returns a clone of the cached template's single root element, bypassing the\n * `DocumentFragment` wrapper that `getFragment` produces.\n *\n * Used by the compiler-emitted `createListItem` for `@for` bodies (and other\n * fragments) whose template has exactly one rendering root child — e.g.\n * `<tr><td>...</td>...</tr>`. Cloning `template.content.firstElementChild`\n * directly saves the per-row `DocumentFragment` allocation that `getFragment`'s\n * `cloneNode(true)` on the cached template's content would otherwise produce,\n * which dominates the cost of bulk-row creates (`run`/`add`/`runlots`).\n *\n * Contract: the compiler only emits `t_fragment_el` for fragment indices whose\n * template has exactly one rendering root, and that root is an `Element`. The\n * cache array (`t_fragment_els`) is separate from `t_fragments` so each helper\n * only ever sees its own cached type at a given index.\n *\n * @param document The owner document (used to build the cached `<template>`).\n * @param array The per-component `t_fragment_els` cache.\n * @param index The fragment's index in the cache.\n * @param html The fragment's HTML source, with `#` placeholders for reactive\n * text and `<!>` for anchor comments.\n * @param ns When true, the template is created in the SVG namespace (its\n * `firstElementChild` is then an SVG element).\n */\nexport default function getElementFragment(\n\tdocument: Document,\n\tarray: Element[],\n\tindex: number,\n\thtml: string,\n\tns?: boolean,\n): Element {\n\t// Create the cached element if it hasn't yet been used\n\tif (array[index] === undefined) {\n\t\t// TODO: Should pass a string for the ns, when we support other element types\n\t\tif (ns === true) {\n\t\t\tconst template = document.createElementNS(\"http://www.w3.org/2000/svg\", \"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.firstElementChild!;\n\t\t} else {\n\t\t\tconst template = document.createElement(\"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.content.firstElementChild!;\n\t\t}\n\t}\n\n\treturn array[index]!.cloneNode(true) as Element;\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type SlotRender from \"../types/SlotRender\";\nimport flushMountEffects from \"../watch/flushMountEffects\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Hydrates a component into an existing DOM tree\n * @param parent The parent node\n * @param component The component to mount\n * @param props An object containing component props\n */\nexport default function hydrate(\n\tparent: ParentNode,\n\tcomponent: Component,\n\tprops?: Record<string, any>,\n\tslots?: Record<string, SlotRender>,\n): void {\n\t// When mounting, the parent must have no child elements, so we can just set\n\t// the hydration node to the first child node\n\tcontext.hydrationNode = parent.firstChild;\n\n\t// Create and push the root region\n\t// TODO: Does it need to be on context??\n\tcontext.rootRegion = newRegion(devContext.enabled ? \"Root\" : undefined);\n\tcontext.previousRegion = context.rootRegion;\n\tpushRegion(context.rootRegion);\n\n\t// Call the component's render function\n\tcomponent(parent, null, props, undefined, slots);\n\n\tcontext.hydrationNode = null;\n\n\t// Now that we've hydrated, we can run $onmount effects\n\tflushMountEffects();\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type SlotRender from \"../types/SlotRender\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Mounts a component into a DOM node\n *\n * @param parent The node to mount the component into\n * @param component The component to mount\n * @param props An object containing component props\n */\nexport default function mount(\n\tparent: ParentNode,\n\tcomponent: Component,\n\tprops?: Record<string, any>,\n\tslots?: Record<string, SlotRender>,\n): void {\n\t// The parent node must have no child elements, so that we can hydrate\n\t// without worrying about where to start\n\tif (parent.childElementCount > 0) {\n\t\tthrow new Error(\"The parent node must have no child elements\");\n\t}\n\n\t// Remove all text, commments, etc\n\twhile (parent.firstChild !== null) {\n\t\tparent.firstChild.remove();\n\t}\n\n\t// Create and push the root region\n\tif (context.rootRegion === null) {\n\t\tcontext.rootRegion = newRegion(devContext.enabled ? \"Root\" : undefined);\n\t\tcontext.previousRegion = context.rootRegion;\n\t\tpushRegion(context.rootRegion);\n\t}\n\n\t// Call the component's render function\n\tcomponent(parent, null, props, undefined, slots);\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\n\n/**\n * Tears down the current UI: disposes the root region tree (running effect\n * cleanups and detaching subscriptions), resets the render context, and\n * removes any remaining child nodes from `parent`.\n *\n * Call this before `mount`ing a fresh component tree into the same container\n * (e.g. when client-side navigating to a route whose layout chain differs\n * from the previous one). `mount` refuses to mount into a non-empty parent\n * and reuses an existing root region, so both must be cleared first.\n *\n * @param parent The container that the previous UI was mounted into\n */\nexport default function unmount(parent: ParentNode): void {\n\tif (context.rootRegion !== null) {\n\t\tclearRegion(context.rootRegion);\n\t\tcontext.rootRegion = null as unknown as Region;\n\t\tcontext.previousRegion = null as unknown as Region;\n\t\tcontext.activeRegion = null as unknown as Region;\n\t}\n\n\t// The root region has no start/end markers of its own, so `clearRegion`\n\t// disposes its descendants' effects but leaves their DOM nodes behind.\n\t// Remove them so `mount` finds an empty container.\n\twhile (parent.firstChild !== null) {\n\t\tparent.firstChild.remove();\n\t}\n}\n","import type ListItem from \"../types/ListItem\";\n\nexport default function newListItem(\n\tdata: Record<PropertyKey, any>,\n\tkey?: any,\n\tname?: string,\n): ListItem {\n\treturn {\n\t\tstartNode: null,\n\t\tendNode: null,\n\t\tpreviousRegion: null,\n\t\tnextRegion: null,\n\t\tdepth: -1,\n\t\tanimations: null,\n\t\tname,\n\t\tdata,\n\t\tkey,\n\t\teffects: [],\n\t};\n}\n","export default function isCommentNode(node: Node): node is Comment {\n\treturn node.nodeType === 8;\n}\n","export default function isTextNode(node: Node): node is Text {\n\treturn node.nodeType === 3;\n}\n","import context from \"./context\";\nimport { HYDRATION_BREAK } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\n\n// TODO: It would be good to remove this, if possible\n\n/**\n * When hydrating, removes and skips hydration comments that are inserted at the\n * start of branches and used to split up text nodes that would otherwise be\n * joined in HTML.\n *\n * @param node The node to check and maybe skip.\n * @returns The next node.\n */\nexport default function nodeCheckHydrationBreak(node: ChildNode | null): ChildNode | null {\n\tif (node !== null && isCommentNode(node) && node.data === HYDRATION_BREAK) {\n\t\tlet comment = node;\n\t\tnode = node.nextSibling;\n\t\tcomment.remove();\n\t}\n\tcontext.hydrationNode = node;\n\treturn node;\n}\n","import context from \"./context\";\nimport isTextNode from \"./isTextNode\";\nimport nodeCheckHydrationBreak from \"./nodeCheckHydrationBreak\";\n\n/**\n * Gets the next sibling of a node.\n *\n * When hydrating, sets the hydration node.\n *\n * @param node The node.\n * @param text Whether we require a text node.\n */\nexport default function nodeNext(node: ChildNode, text = false): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\t// If the required node is a text node, and we already have one, just use\n\t\t// it. This is caused by text nodes being merged in HTML\n\t\tif (text && isTextNode(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tlet next = nodeCheckHydrationBreak(node.nextSibling);\n\n\t\t// When seeking non-text nodes during hydration, skip past whitespace-only\n\t\t// text nodes and any trailing break markers, so callers land on the\n\t\t// expected element node rather than an intervening text node\n\t\twhile (!text && next !== null && isTextNode(next) && next.textContent?.trim() === \"\") {\n\t\t\tnext = nodeCheckHydrationBreak(next.nextSibling);\n\t\t}\n\n\t\t// Descend through auto-inserted <tbody> elements. The HTML parser\n\t\t// wraps <tr> elements in <tbody> automatically, which shifts the\n\t\t// hydration cursor one level deeper than the fragment template expects.\n\t\t// Only do this when navigating from a text node (root → element pattern\n\t\t// in generated code), not from comment nodes (e.g. inside nodeAnchor)\n\t\tif (\n\t\t\t!text &&\n\t\t\tnext !== null &&\n\t\t\tnext.nodeName === \"TBODY\" &&\n\t\t\tnext.firstChild &&\n\t\t\tisTextNode(node)\n\t\t) {\n\t\t\tnext = next.firstChild;\n\t\t\tcontext.hydrationNode = next;\n\t\t}\n\n\t\treturn next!;\n\t}\n\n\t// NOTE: We know this is not null as it is being called from generated code\n\treturn node.nextSibling!;\n}\n","import context from \"./context\";\nimport { setFirstInsideNode } from \"./firstInsideNode\";\nimport { HYDRATION_END, HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport nodeNext from \"./nodeNext\";\n\n/**\n * Gets the anchor node for a control statement or component.\n *\n * When mounting, this just returns the anchor node parameter (because it was\n * created).\n *\n * When hydrating, there should be matched <![> and <!]> comments in the HTML,\n * and the anchor node should be after the end comment. The matched comment\n * nodes will be deleted, and the hydration node set to the first node inside\n * the matched comments.\n *\n * @param node The potential anchor node.\n * @returns The anchor node.\n */\nexport default function nodeAnchor(node: ChildNode): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\tif (isCommentNode(node) && node.data === HYDRATION_START) {\n\t\t\t// Save the parent before removing the node, so we know when to\n\t\t\t// stop walking up the tree during document-order traversal\n\t\t\tconst startParent = node.parentNode;\n\n\t\t\t// Skip and remove the start node, setting the hydration node in\n\t\t\t// nodeNext. The node returned here is the first node inside the\n\t\t\t// block (after any leading branch-break marker), which becomes the\n\t\t\t// active region's start node.\n\t\t\tlet currentNode: ChildNode | null = nodeNext(node);\n\t\t\tconst firstInside: ChildNode | null = currentNode;\n\t\t\tnode.remove();\n\n\t\t\t// Go through nodes in document order until we get to the end.\n\t\t\t// We use document order (descending into child elements) rather\n\t\t\t// than just siblings, because the HTML parser may move hydration\n\t\t\t// markers into auto-inserted elements (e.g. <tbody> inside <table>)\n\t\t\tlet level = 1;\n\t\t\twhile (currentNode !== null) {\n\t\t\t\tif (isCommentNode(currentNode)) {\n\t\t\t\t\tif (currentNode.data === HYDRATION_START) {\n\t\t\t\t\t\tlevel += 1;\n\t\t\t\t\t} else if (currentNode.data === HYDRATION_END) {\n\t\t\t\t\t\tlevel -= 1;\n\t\t\t\t\t\tif (level === 0) {\n\t\t\t\t\t\t\t// Remove the end node and return the next one\n\t\t\t\t\t\t\tconst endNode = currentNode.nextSibling;\n\t\t\t\t\t\t\tcurrentNode.remove();\n\n\t\t\t\t\t\t\t// If the statement is empty (i.e. the end comment\n\t\t\t\t\t\t\t// immediately follows the start comment), move the\n\t\t\t\t\t\t\t// hydration node past the removed end comment to\n\t\t\t\t\t\t\t// the anchor, so that we can continue to the next\n\t\t\t\t\t\t\t// nodes\n\t\t\t\t\t\t\tif (context.hydrationNode === currentNode) {\n\t\t\t\t\t\t\t\tcontext.hydrationNode = endNode;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Set the active region's start node to the first\n\t\t\t\t\t\t\t// node inside the block. This mirrors mounting,\n\t\t\t\t\t\t\t// where the start node is the fragment's first\n\t\t\t\t\t\t\t// child — the actual content — rather than a marker.\n\t\t\t\t\t\t\tconst region = context.activeRegion;\n\t\t\t\t\t\t\tif (region.startNode === null && firstInside !== null) {\n\t\t\t\t\t\t\t\tregion.startNode = firstInside;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Stash the first node inside the block, keyed by\n\t\t\t\t\t\t\t// the anchor being returned. Generated code (e.g.\n\t\t\t\t\t\t\t// for `@html`) reads it back to adopt the\n\t\t\t\t\t\t\t// server-rendered nodes, since the markers that\n\t\t\t\t\t\t\t// bounded them have now been removed.\n\t\t\t\t\t\t\tsetFirstInsideNode(endNode!, firstInside);\n\n\t\t\t\t\t\t\t// NOTE: We know this is not null as it is being\n\t\t\t\t\t\t\t// called from generated code\n\t\t\t\t\t\t\treturn endNode!;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Document-order traversal: descend into children first,\n\t\t\t\t// then try siblings. When siblings are exhausted, walk up\n\t\t\t\t// to ancestors (but not past startParent) and try their siblings\n\t\t\t\tif (currentNode.firstChild) {\n\t\t\t\t\tcurrentNode = currentNode.firstChild;\n\t\t\t\t} else if (currentNode.nextSibling) {\n\t\t\t\t\tcurrentNode = currentNode.nextSibling;\n\t\t\t\t} else {\n\t\t\t\t\t// No children and no next sibling: walk up to find an\n\t\t\t\t\t// ancestor that has a next sibling\n\t\t\t\t\tlet parent: Node | null = currentNode.parentNode;\n\t\t\t\t\twhile (parent !== null && parent.nextSibling === null && parent !== startParent) {\n\t\t\t\t\t\tparent = parent.parentNode;\n\t\t\t\t\t}\n\t\t\t\t\t// Don't go past startParent\n\t\t\t\t\tif (parent === null || parent === startParent) {\n\t\t\t\t\t\tcurrentNode = null;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrentNode = parent.nextSibling;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentNode === null) {\n\t\t\t\tthrow new Error(\"End hydration comment not found\");\n\t\t\t}\n\t\t}\n\t}\n\n\treturn node;\n}\n","import context from \"./context\";\n\n/**\n * Gets the first child of a node.\n *\n * Sets the hydration node.\n *\n * @param parent The parent node.\n */\nexport default function nodeChild(parent: Node): ChildNode {\n\tlet childNode = parent.firstChild;\n\tif (context.hydrationNode !== null) {\n\t\t// The child may be null when hydrating the sole text child of an\n\t\t// element with no text\n\t\tif (childNode === null) {\n\t\t\tchildNode = parent.appendChild(parent.ownerDocument!.createTextNode(\"\"));\n\t\t}\n\t\tcontext.hydrationNode = childNode;\n\t}\n\n\t// NOTE: We know this is not null as it is being called from generated code\n\treturn childNode!;\n}\n","import context from \"./context\";\nimport { HYDRATION_BREAK, HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport isTextNode from \"./isTextNode\";\n\n/**\n * Walks the hydration cursor past skippable leading nodes (whitespace text,\n * branch-break markers, auto-inserted `<tbody>`) and lands on the first real\n * content node — the same walk `nodeRoot` performs for the non-text case.\n *\n * Sets `region.startNode` to the landed node (unless it's a control-start\n * marker, which `nodeAnchor` consumes next). Returns the landed node and\n * advances `context.hydrationNode` to it.\n *\n * Extracted so `nodeRoot` and `nodeRootElement` share one implementation of\n * the cursor walk.\n */\nexport default function walkHydrationRoot(): ChildNode {\n\tlet rootNode: ChildNode | null = context.hydrationNode;\n\n\t// For non-text fragments, skip leading branch-break markers (removing\n\t// them), empty anchor comments from preceding siblings, and whitespace\n\t// text nodes. Stop at a control-start marker (nodeAnchor walks it) or\n\t// real content.\n\twhile (rootNode !== null && isSkippable(rootNode)) {\n\t\tconst next: ChildNode | null = rootNode.nextSibling;\n\t\tif (isCommentNode(rootNode) && rootNode.data === HYDRATION_BREAK) {\n\t\t\trootNode.remove();\n\t\t}\n\t\trootNode = next;\n\t\tcontext.hydrationNode = rootNode;\n\t}\n\n\t// Descend through auto-inserted <tbody> elements. The HTML parser wraps\n\t// <tr> elements in <tbody>, which can leave the cursor on the <tbody>\n\t// rather than its first <tr> when entering a @for inside a table.\n\twhile (\n\t\trootNode !== null &&\n\t\t(rootNode as HTMLElement).nodeName === \"TBODY\" &&\n\t\trootNode.firstChild !== null\n\t) {\n\t\trootNode = rootNode.firstChild as ChildNode;\n\t\tcontext.hydrationNode = rootNode;\n\t}\n\n\t// If hydrating, set the active region's start node. Control-start markers\n\t// are left for nodeAnchor to walk — it sets the start node to the first\n\t// inner node.\n\tconst region = context.activeRegion;\n\tconst isControlStart =\n\t\trootNode !== null && isCommentNode(rootNode) && rootNode.data === HYDRATION_START;\n\tif (region.startNode === null && !isControlStart) {\n\t\tregion.startNode = rootNode;\n\t}\n\n\treturn rootNode!;\n}\n\nfunction isSkippable(node: ChildNode): boolean {\n\tif (isTextNode(node) && (node.textContent ?? \"\").trim() === \"\") return true;\n\tif (isCommentNode(node)) {\n\t\t// Skip branch-break markers and empty anchor comments. Control-start\n\t\t// (`[`) and control-end (`]`) markers are NOT skipped.\n\t\treturn node.data === HYDRATION_BREAK || node.data === \"\";\n\t}\n\treturn false;\n}\n","import context from \"./context\";\nimport walkHydrationRoot from \"./walkHydrationRoot\";\n\n/**\n * Gets the root element of a single-root fragment built via `getElementFragment`.\n *\n * Companion to `nodeRoot`, for the codegen path where the compiler has emitted\n * `t_fragment_el` (cloning the cached template's `firstElementChild` directly)\n * instead of `t_fragment` (cloning into a `DocumentFragment`). In the\n * non-hydrating case the cloned element is already the root, so this is a\n * no-op pass-through. In the hydrating case we perform the same cursor walk as\n * `nodeRoot`'s non-text branch so the region's `startNode` lands on the\n * existing DOM node and the hydration cursor advances past any leading\n * whitespace, branch-break markers, and auto-inserted `<tbody>` wrappers.\n *\n * @param node The cloned root element (ignored when hydrating).\n */\nexport default function nodeRootElement(node: Element): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\treturn walkHydrationRoot();\n\t}\n\treturn node;\n}\n","import context from \"./context\";\nimport { HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport isTextNode from \"./isTextNode\";\nimport walkHydrationRoot from \"./walkHydrationRoot\";\n\n/**\n * Gets the first child in a fragment.\n *\n * When hydrating, also sets the active region's start node, while we have it.\n *\n * If the hydration cursor is on a control-start marker (`<![>`), the node is\n * left in place for `nodeAnchor` (called next as `t_anchor(t_root(...))`) to\n * walk — it consumes the matched `<![>...<!]>` pair, removes the markers and\n * sets the region's start node to the first node inside the block.\n *\n * For non-text fragments, leading branch-break markers (`<!^>`), empty anchor\n * comments left by preceding siblings, and residual whitespace-only text nodes\n * are skipped (break markers removed) so the region's start node lands on real\n * content. This replaces the per-sibling `t_next` calls that the codegen used\n * to emit when leading whitespace separated siblings; with whitespace trimmed\n * those calls are gone, so the advancement happens here.\n *\n * @param parent The parent of the fragment.\n * @param text Whether we require a text node.\n */\nexport default function nodeRoot(parent: Node, text = false): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\tlet rootNode: ChildNode | null = context.hydrationNode;\n\n\t\t// If the root node we need is a text node, and the hydration node is\n\t\t// not a text node but the previous node is, use the previous node. This\n\t\t// is caused by text nodes being merged in HTML\n\t\tif (\n\t\t\ttext &&\n\t\t\t!isTextNode(rootNode) &&\n\t\t\trootNode.previousSibling !== null &&\n\t\t\tisTextNode(rootNode.previousSibling)\n\t\t) {\n\t\t\trootNode = rootNode.previousSibling;\n\t\t\tcontext.hydrationNode = rootNode;\n\t\t}\n\n\t\t// For non-text fragments, walk past skippable leading nodes and set\n\t\t// the region's start node. Text fragments opt out because their\n\t\t// leading text node is the value the caller expects.\n\t\tif (!text) {\n\t\t\treturn walkHydrationRoot();\n\t\t}\n\n\t\tconst region = context.activeRegion;\n\t\tconst isControlStart =\n\t\t\trootNode !== null && isCommentNode(rootNode) && rootNode.data === HYDRATION_START;\n\t\tif (region.startNode === null && !isControlStart) {\n\t\t\tregion.startNode = rootNode;\n\t\t}\n\n\t\treturn rootNode!;\n\t} else {\n\t\t// NOTE: We know this is not null as it is being called from generated\n\t\t// code\n\t\treturn parent.firstChild!;\n\t}\n}\n","import context from \"./context\";\nimport nodeCheckHydrationBreak from \"./nodeCheckHydrationBreak\";\n\n/**\n * Gets the sibling of a node, x nodes after it.\n *\n * When hydrating, sets the hydration node.\n *\n * @param node The node.\n * @param count The number of nodes to skip.\n */\nexport default function nodeSkip(node: ChildNode, count: number): ChildNode {\n\tlet nextNode = node;\n\n\t// NOTE: We know these are not null as it is being called from generated code\n\tif (context.hydrationNode !== null) {\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tnextNode = nodeCheckHydrationBreak(nextNode.nextSibling)!;\n\t\t}\n\t} else {\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tnextNode = nextNode.nextSibling!;\n\t\t}\n\t}\n\n\treturn nextNode;\n}\n","import type Region from \"../types/Region\";\nimport clearSources from \"../watch/clearSources\";\nimport deactivateSources from \"../watch/deactivateSources\";\nimport runCleanups from \"../watch/runCleanups\";\nimport runEffect from \"../watch/runEffect\";\n\n/**\n * Force re-runs every effect owned by `region` and its descendant regions\n * that depends on at least one of the for-vars set in `changedMask`.\n *\n * Used by keyed-list `updateListItem` callbacks emitted by the compiler when\n * the `@for` body has been classified \"no-proxy safe\" — i.e. the per-item\n * data bag is *not* wrapped in a shallow `$watch` Proxy. Without that Proxy,\n * a write such as `t_old_item.data.row = newRow` doesn't propagate through a\n * signal, so any effects that read `data.row` must be re-run manually.\n *\n * `changedMask` is a bitmask of the for-var positions whose references\n * actually changed in this update. Each effect carries `forVarMask`\n * (computed at compile time) listing the for-vars its body reads; effects\n * whose `forVarMask & changedMask === 0` are skipped. Mount callbacks\n * (`isMountEffect` — `$onmount`/`onmount`) are always skipped: they run\n * once per DOM mount and their bodies are untracked.\n *\n * Equivalent to what `checkEffect` does when a signal has propagated, but\n * unconditional for the effects that do match: cleanup → deactivate sources\n * → run → clear unused sources, for every matching effect on the region and\n * on every descendant region (`depth > region.depth`, the same chain shape\n * `clearRegion` walks).\n */\nexport default function rerunRegionEffects(region: Region, changedMask: number): void {\n\trerunEffectsOnRegion(region, changedMask);\n\tlet child: Region | null = region.nextRegion;\n\twhile (child !== null && child.depth > region.depth) {\n\t\trerunEffectsOnRegion(child, changedMask);\n\t\tchild = child.nextRegion;\n\t}\n}\n\nfunction rerunEffectsOnRegion(region: Region, changedMask: number): void {\n\tfor (let effect of region.effects) {\n\t\t// Mount callbacks run once per region mount (their `$onmount`/`onmount`\n\t\t// semantics) and are untracked, so re-running them here would fire\n\t\t// `onmount` again on every keyed-list item update even when the DOM node\n\t\t// is reused.\n\t\tif (effect.isMountEffect) continue;\n\t\t// When `forVarMask` is set (effect emitted inside a no-proxy `@for`\n\t\t// body), skip effects that don't read any of the changed for-vars.\n\t\t// `0` means the effect reads no for-vars at all — always skip.\n\t\t// `undefined` means no dependency info — re-run unconditionally.\n\t\tif (effect.forVarMask !== undefined && (effect.forVarMask & changedMask) === 0) continue;\n\t\trunCleanups(effect);\n\t\tdeactivateSources(effect);\n\t\trunEffect(effect);\n\t\tclearSources(effect);\n\t}\n}\n","import context from \"./context\";\n\n/**\n * Restores the hydration cursor to a previously-snapshotted node. Used by\n * `@try`/`@catch`: if the try branch throws partway through its hydration\n * walk, the catch branch must resume hydrating from where the try group\n * started, not from wherever the failed branch left the cursor.\n *\n * The cursor is set unconditionally: a failed try-branch build can walk the\n * cursor past the last node (setting it to `null` via `nodeNext`), and the\n * rewind must still restore it — otherwise the catch branch would think it\n * isn't hydrating and insert fresh nodes alongside the server's. When not\n * hydrating at all, the snapshot itself is `null`, so this is a no-op.\n *\n * @param node The snapshotted cursor node (from `saveHydration`).\n */\nexport default function restoreHydration(node: ChildNode | null): void {\n\tcontext.hydrationNode = node;\n}\n","import type Region from \"../types/Region\";\n\n/**\n * Widens ancestor region node windows after a control re-run rendered\n * content at its anchor.\n *\n * A region that owns only a control's anchor comment captures\n * `startNode = endNode = anchor` when it mounts (e.g. a `@for` row whose\n * body is a single `@if`, or an outer `@if` whose body is a single control).\n * Content rendered by a LATER re-run of that control is inserted into the\n * live DOM just BEFORE the anchor — outside that window — so clearing the\n * owning region would remove only the anchor and orphan the branch content.\n * At mount time this can't happen (content is added to the region's detached\n * fragment first, so its `startNode` already covers it), which is why only\n * re-runs need this fix.\n *\n * The first node of the newly rendered content is the first DESCENDANT region\n * of the control that owns nodes (control regions themselves have null\n * `startNode`). Ancestors are the regions with strictly decreasing depth on\n * the `previousRegion` chain; only those whose window starts exactly at the\n * anchor are widened.\n */\nexport default function widenAncestorsAtAnchor(region: Region, anchor: Node | null): void {\n\tif (anchor === null) return;\n\n\t// Find the first node-bearing descendant of this control run\n\tlet child: Region | null = region.nextRegion;\n\twhile (child !== null && child.depth > region.depth && child.startNode === null) {\n\t\tchild = child.nextRegion;\n\t}\n\tif (child === null || child.depth <= region.depth || child.startNode === anchor) {\n\t\treturn;\n\t}\n\tconst firstNode = child.startNode;\n\n\t// Widen every ancestor whose window starts at the anchor. Walk\n\t// `previousRegion` while depth strictly decreases, so sibling chains\n\t// (equal depth) terminate the walk — only true ancestors can own the\n\t// anchor as their window start.\n\tlet ancestor: Region | null = region.previousRegion;\n\tlet ancestorDepth = region.depth;\n\twhile (ancestor !== null && ancestor.depth < ancestorDepth) {\n\t\tif (ancestor.startNode === anchor) {\n\t\t\tancestor.startNode = firstNode;\n\t\t}\n\t\tancestorDepth = ancestor.depth;\n\t\tancestor = ancestor.previousRegion;\n\t}\n}\n","import type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport context from \"./context\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Runs an `if`, `switch` or `await` control statement\n * @param create A function that creates the control statement's branches\n */\nexport default function runControl(\n\tregion: Region,\n\tanchor: Node | null,\n\tcreate: (anchor: Node | null) => void,\n\tname?: string,\n): void {\n\tlet first = true;\n\n\t// Use a generation counter so stale effects (created by previous\n\t// runControl calls for the same region) can detect they're no longer\n\t// current and skip execution. The generation is incremented each time\n\t// runControl is called with this region.\n\tconst gen = ((region as any).generation = ((region as any).generation ?? 0) + 1);\n\n\t// Run the control statement in an effect\n\t$run(function runControl() {\n\t\t// If this effect was created by a previous runControl call for the\n\t\t// same region, it is stale and should not execute\n\t\tif ((region as any).generation !== gen) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (region.depth === -2) {\n\t\t\t(region as any).recreate = true;\n\t\t}\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Run the function that creates the control statement's branches\n\t\tcreate(anchor);\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later re-run may have rendered content before our anchor that\n\t\t// an ancestor's node window doesn't cover — widen those windows so\n\t\t// clearing the ancestor can't orphan the content (see\n\t\t// widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\n\t\t// While hydrating, reset the cursor to the control's anchor after its\n\t\t// content has been hydrated. The branches leave the cursor deep inside\n\t\t// (at the last nested node), but the parent fragment needs a stable\n\t\t// end node — the anchor persists until the parent clears it, so it is\n\t\t// safe to capture.\n\t\tif (context.hydrationNode !== null && anchor !== null) {\n\t\t\tcontext.hydrationNode = anchor as ChildNode;\n\t\t}\n\t}, name);\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\n\nexport default function runControlBranch(region: Region, oldIndex: number, index: number): boolean {\n\t// Clear the recreate flag if it was set — it only needs to trigger once\n\tconst recreate = (region as any).recreate;\n\tif (recreate) {\n\t\t(region as any).recreate = false;\n\t}\n\n\t// Whether this region has rendered a branch before. A region's first\n\t// render has no previous branch of its own to clear — its `nextRegion`\n\t// link may point at an unrelated sibling region pushed after it in the\n\t// region chain, and clearing it would destroy live content mounted\n\t// elsewhere. (Callers like `runTry` still force clears on later runs by\n\t// passing a sentinel old index.)\n\tconst firstRender = (region as any).hasRenderedBranch !== true;\n\t(region as any).hasRenderedBranch = true;\n\n\tif (oldIndex === index) {\n\t\tif (recreate) {\n\t\t\tif (region.nextRegion !== null && region.nextRegion.depth > region.depth) {\n\t\t\t\tclearRegion(region.nextRegion);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tif (!firstRender && region.nextRegion !== null && region.nextRegion.depth > region.depth) {\n\t\tclearRegion(region.nextRegion);\n\t}\n\n\treturn true;\n}\n","import $watch from \"./$watch\";\nimport { proxyDataSymbol } from \"./symbols\";\n\n/**\n * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that\n * is not already watched and is not a promise. Returns the value unchanged\n * otherwise.\n *\n * Used by the `get` trap (wrap values on read) and the `set` trap (wrap\n * values on write), so a value stored in watched state is reactive whether\n * it's been read yet or not.\n */\nconst proxyCache = new WeakMap<object, object>();\n\nexport default function deepWrap(value: any): any {\n\tif (value === undefined || value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\tif (value[proxyDataSymbol] !== undefined) {\n\t\t// Already watched -- it's either a proxy itself, or a raw target whose\n\t\t// proxy wasn't cached (e.g. it was wrapped directly via `$watch` and\n\t\t// never deep-wrapped). Short-circuit BEFORE reading `then`, otherwise\n\t\t// the read goes through the proxy's `get` trap and creates a spurious\n\t\t// signal for a property nothing ever sets\n\t\treturn proxyCache.get(value) ?? value;\n\t}\n\t// But not if it's a Promise (i.e. has a `then` method)\n\tif (value.then !== undefined) {\n\t\treturn value;\n\t}\n\t// And not DOM nodes / other host objects -- they have internal state and\n\t// accessor-only prototype properties, so wrapping them breaks (e.g.\n\t// writing a wrapped `parentElement` back onto a node throws, because the\n\t// property has only a getter). They're not reactive state either; effects\n\t// still track the key they're stored under\n\tif (value.nodeType !== undefined) {\n\t\treturn value;\n\t}\n\tconst cached = proxyCache.get(value);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\tconst proxy = $watch(value);\n\tproxyCache.set(value, proxy);\n\treturn proxy;\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type ProxyData from \"../types/ProxyData\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\nimport { COMPUTED_TYPE, EFFECT_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\n\n/**\n * Walk the target graph from a signal source (ProxySignal or Computed),\n * marking each dependent as needing recalculation and queuing effects for\n * re-run. Shared between `propagateSignal` (for proxy writes) and `$async`'s\n * promise-resolve handler (for async value resolution).\n *\n * Must be called inside `batchStart`/`batchEnd` — callers own the batch.\n */\nexport function propagateFromSignal(signal: { firstTarget: Subscription | null }): void {\n\tconst first = signal.firstTarget;\n\tif (first === null) return;\n\tlet targetSub: Subscription = first;\n\n\tlet computed: Computed | undefined;\n\touter: while (true) {\n\t\t// De-activate all targets, so they can be re-used/updated/deleted\n\t\ttargetSub.active = false;\n\t\ttargetSub.recalc = true;\n\n\t\tconst target = targetSub.target;\n\t\tif (target.type === EFFECT_TYPE) {\n\t\t\t// Add the effect to the queue for running after triggering.\n\t\t\t// Dedupe on the `queued` flag — NOT on a link into the queue —\n\t\t\t// because link-based dedupe can't tell an effect still pending\n\t\t\t// in this flush from one that already ran earlier in this flush\n\t\t\t// but whose link hasn't been cleared yet. That gap silently\n\t\t\t// dropped re-queues for effects downstream of a computed whose\n\t\t\t// value oscillated within a single batch (e.g. a derived flag\n\t\t\t// during a props → state → props round-trip), freezing them at\n\t\t\t// a stale value.\n\t\t\tif (!target.queued) {\n\t\t\t\ttarget.queued = true;\n\t\t\t\tcontext.effectsToRun.push(target);\n\t\t\t}\n\t\t} else if (/*target.type === COMPUTED_TYPE*/ !target.recalc) {\n\t\t\t// This may need to be re-computed in the pull phase\n\t\t\ttarget.recalc = true;\n\n\t\t\t// Check the computed's targets\n\t\t\tif (target.firstTarget !== null) {\n\t\t\t\tcomputed = target;\n\t\t\t\tcomputed.rollback = targetSub;\n\t\t\t\ttargetSub = target.firstTarget;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t// If there are no more targets, we may need to rollback to the\n\t\t// last computed that had more targets\n\t\twhile (targetSub.nextTarget === null && computed !== undefined) {\n\t\t\tconst rollback = computed.rollback;\n\t\t\tif (rollback === null) break; // reached the root signal\n\t\t\ttargetSub = rollback;\n\t\t\tif (targetSub.source.type !== COMPUTED_TYPE) {\n\t\t\t\tcomputed = undefined;\n\t\t\t\tcontinue outer;\n\t\t\t}\n\t\t\tcomputed = targetSub.source;\n\t\t}\n\n\t\tif (targetSub.nextTarget === null) {\n\t\t\tbreak;\n\t\t}\n\n\t\ttargetSub = targetSub.nextTarget;\n\t}\n}\n\n/**\n * When a signal is changed, we need to\n * - Set the signal's subscriptions to recalc\n * - Set any dependent computed values to recalc\n * - Gather dependent effects that will need to be re-run\n */\nexport default function propagateSignal(proxy: ProxyData, key: PropertyKey): void {\n\t//console.log(`triggering effects for '${String(key)}' on`, proxy);\n\t//console.log(\"===\");\n\t//console.log(`triggering effects for '${String(key)}'`);\n\n\tlet signal = proxy.signals.get(key) as ProxySignal;\n\tif (signal !== undefined && signal.firstTarget !== null) {\n\t\tbatchStart();\n\n\t\ttry {\n\t\t\t// Add the signal to the context for updating after triggering.\n\t\t\t// Append via a tail pointer so this stays O(1), rather than walking\n\t\t\t// the whole chain on every write (which made batched mutations O(N²)).\n\t\t\tif (context.lastSignalToUpdate === null) {\n\t\t\t\tcontext.firstSignalToUpdate = signal;\n\t\t\t\tcontext.lastSignalToUpdate = signal;\n\t\t\t} else if (signal.nextSignalToUpdate === null) {\n\t\t\t\tcontext.lastSignalToUpdate.nextSignalToUpdate = signal;\n\t\t\t\tcontext.lastSignalToUpdate = signal;\n\t\t\t}\n\n\t\t\tpropagateFromSignal(signal);\n\t\t} finally {\n\t\t\tbatchEnd();\n\t\t}\n\t}\n}\n","import type ProxyData from \"../types/ProxyData\";\nimport { SIGNAL_TYPE } from \"../types/constants\";\nimport trackSignal from \"./trackSignal\";\n\nexport default function trackProxySignal(data: ProxyData, key: PropertyKey): void {\n\t//console.log(`tracking effect '${context.activeTarget.name}' for '${String(key)}' prop`);\n\n\t// Create or get the signals\n\tlet signal = data.signals.get(key);\n\tif (signal === undefined) {\n\t\tsignal = {\n\t\t\ttype: SIGNAL_TYPE,\n\t\t\tfirstTarget: null,\n\t\t\tnextSignalToUpdate: null,\n\t\t\t//name: dev.propName(key),\n\t\t};\n\t\tdata.signals.set(key, signal);\n\t}\n\n\ttrackSignal(signal);\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type ProxyData from \"../types/ProxyData\";\nimport { COMPUTED_TYPE, EFFECT_TYPE, SIGNAL_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport checkComputed from \"./checkComputed\";\nimport deepWrap from \"./deepWrap\";\nimport $unwrap from \"./$unwrap\";\nimport propagateSignal from \"./propagateSignal\";\nimport { proxyDataSymbol } from \"./symbols\";\nimport trackProxySignal from \"./trackProxySignal\";\nimport trackSignal from \"./trackSignal\";\n\n/**\n * Called when a read hits a `didSuspend` computed. Subscribes the reader (so\n * resolve re-runs it through the normal reactive graph), propagates the\n * suspend up the cache chain by tainting the active reader, and notifies the\n * nearest `@await` boundary.\n *\n * Return value (ASYNC.md → \"Stale-while-revalidate\"): on a refresh suspend\n * (the computed has resolved before) returns the previously resolved value\n * held in `staleValue`, so readers keep displaying the old content instead of\n * a placeholder — an `@await` boundary thus keeps its content mounted\n * rather than flashing the `with` branch. On a first load (`staleValue` is\n * undefined) returns `undefined`, which the boundary replaces with its\n * `with` branch. In peek mode (used by `$pending`) always returns `undefined`\n * — the value isn't needed, only the subscription.\n */\nfunction suspendRead(signal: Computed): any {\n\ttrackSignal(signal);\n\t// In peek mode (used by $pending), track the signal for subscription but\n\t// don't taint the reader or notify the boundary. Record a \"loud\" hit only\n\t// for non-quiet suspends — a silent refresh (suspendQuiet) stays quiet per\n\t// ASYNC.md → \"Loud vs quiet\"), so $pending returns false for it. The signal is still\n\t// tracked above so $pending re-evaluates when the silent refresh resolves.\n\tif (context.suspendPeek) {\n\t\tif (!signal.suspendQuiet) {\n\t\t\tcontext.suspendPeekHit = true;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (context.activeTarget !== null) {\n\t\tcontext.activeTarget.didSuspend = true;\n\t\tif (context.activeTarget.type === EFFECT_TYPE) {\n\t\t\t// Record the suspended read on the effect, so `triggerEffects`\n\t\t\t// can re-subscribe it if the run crashes with no error boundary\n\t\t\t// to handle the error — otherwise the crash would detach the\n\t\t\t// subscription above and the effect would never re-run on\n\t\t\t// resolve\n\t\t\tconst effect = context.activeTarget as Effect;\n\t\t\t(effect.suspendSources ??= new Set()).add(signal);\n\t\t}\n\t}\n\tif (context.awaitBoundary !== null) {\n\t\tcontext.awaitBoundary.suspended = true;\n\t\t// Record the suspended computed on the boundary, so its effect can\n\t\t// re-check (and re-subscribe to) just the pending reads on each\n\t\t// re-run instead of walking its whole source list\n\t\tcontext.awaitBoundary.pending.add(signal);\n\t\t// Subscribe the boundary effect to this computed so the boundary\n\t\t// re-runs when the promise resolves. Without this, the subscription\n\t\t// would only exist on child effects that are destroyed when content\n\t\t// is cleared.\n\t\tconst boundaryEffect = context.awaitBoundary.effect;\n\t\tif (boundaryEffect !== null && boundaryEffect !== context.activeTarget) {\n\t\t\tconst oldActive = context.activeTarget;\n\t\t\tcontext.activeTarget = boundaryEffect;\n\t\t\ttrackSignal(signal);\n\t\t\tcontext.activeTarget = oldActive;\n\t\t}\n\t}\n\treturn signal.staleValue;\n}\n\nexport default function proxyGet(\n\ttarget: Record<PropertyKey, any>,\n\tkey: PropertyKey,\n\treceiver: any,\n): any {\n\tlet data: ProxyData = target[proxyDataSymbol];\n\n\tif (key === proxyDataSymbol) {\n\t\treturn data;\n\t}\n\n\t// Dates, Maps and Sets can't be proxied transparently -- their prototype\n\t// methods (`getFullYear`, `get`, `size`...) throw when invoked with the\n\t// proxy as `this`, because they need internal slots of the raw object --\n\t// so method access is routed through wrapper handlers instead. Own\n\t// properties set by user code (`date.foo = 1`) still go through the\n\t// generic property path below.\n\tif (\n\t\t(data.isDate || data.isMap || data.isSet) &&\n\t\t!Object.prototype.hasOwnProperty.call(target, key)\n\t) {\n\t\treturn collectionGet(data, target, key, receiver);\n\t}\n\n\t//console.log(`object get '${String(key)}' on`, target);\n\t//console.log(`object get '${String(key)}'`);\n\n\tlet signal = data.signals.get(key);\n\tif (signal === undefined) {\n\t\tconst propDescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (propDescriptor !== undefined) {\n\t\t\tif (propDescriptor.writable) {\n\t\t\t\t// Setup data for the property\n\t\t\t\tif (data.shallow !== true) {\n\t\t\t\t\t// Set the value to a new proxy if it's an object\n\t\t\t\t\tconst value = target[key];\n\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\ttarget[key] = wrapped;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If a property is being accessed in the course of setting up an\n\t\t\t\t// effect, track it\n\t\t\t\ttrackProxySignal(data, key);\n\t\t\t} else if (propDescriptor.get) {\n\t\t\t\t// OK, we're only checking for computed values if it's read-only for\n\t\t\t\t// now, but we probably need to check any getter's value -- e.g. the\n\t\t\t\t// user may wish to add a setter to optimistically set a value, have\n\t\t\t\t// the UI update, then set the value concretely later (e.g. if\n\t\t\t\t// updating a `count` via a fetch)\n\n\t\t\t\tconst oldRegisterComputed = context.registerComputed;\n\t\t\t\ttry {\n\t\t\t\t\t// Allow calling `$cache`/`$async` to assign the computed to a\n\t\t\t\t\t// proxy signal\n\t\t\t\t\tcontext.registerComputed = (computed: Computed) => {\n\t\t\t\t\t\tdata.signals.set(key, computed);\n\t\t\t\t\t};\n\t\t\t\t\tconst result = Reflect.get(target, key, receiver);\n\t\t\t\t\t// After running the getter, check if the just-registered\n\t\t\t\t\t// computed suspended (e.g. an $async getter returning a\n\t\t\t\t\t// pending promise). If so, handle suspend instead of\n\t\t\t\t\t// returning the raw promise.\n\t\t\t\t\tconst registered = data.signals.get(key) as Computed | undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tcontext.refreshSignals !== null &&\n\t\t\t\t\t\tregistered !== undefined &&\n\t\t\t\t\t\tregistered.type === COMPUTED_TYPE &&\n\t\t\t\t\t\tregistered.isAsync\n\t\t\t\t\t) {\n\t\t\t\t\t\t// $refresh collection: record the $async computed (this is\n\t\t\t\t\t\t// the first-ever read, so it isn't in data.signals yet).\n\t\t\t\t\t\t// suspendRead below still runs in peek mode ($refresh sets\n\t\t\t\t\t\t// suspendPeek), so no taint/boundary notification happens.\n\t\t\t\t\t\tcontext.refreshSignals.push(registered);\n\t\t\t\t\t\t// The collection read itself just initialized this computed\n\t\t\t\t\t\t// — its fetch is already in flight, so $refresh must not\n\t\t\t\t\t\t// re-run it (that would start a duplicate fetch whose\n\t\t\t\t\t\t// resolve the generation guard would drop)\n\t\t\t\t\t\tcontext.refreshInitialized?.add(registered);\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tregistered !== undefined &&\n\t\t\t\t\t\tregistered.type === COMPUTED_TYPE &&\n\t\t\t\t\t\tregistered.didSuspend\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn suspendRead(registered);\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t} finally {\n\t\t\t\t\tcontext.registerComputed = oldRegisterComputed;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isArray) {\n\t\t\t// If it's a function in an array, we may intercept it\n\t\t\tif (arrayWrapper[key] !== undefined) {\n\t\t\t\treturn arrayWrapper[key](data, target, key);\n\t\t\t}\n\t\t} else {\n\t\t\t// If it's a non-existent property we still set up a subscription so\n\t\t\t// that if its value is set to something it will re-run the effect\n\t\t\ttrackProxySignal(data, key);\n\t\t}\n\t} else if (signal.type === SIGNAL_TYPE) {\n\t\t// The signal may have been created for a PREVIOUS value at this key —\n\t\t// e.g. the property was assigned between reads. Make sure the current\n\t\t// value is deep-wrapped, the same as the first-read path above -- but\n\t\t// only for writable own data properties, since prototype accessors\n\t\t// (e.g. a DOM node's `parentElement`) can't be written back\n\t\tif (data.shallow !== true) {\n\t\t\tconst value = target[key];\n\t\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\t\tconst propDescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\t\t\tif (propDescriptor !== undefined && propDescriptor.writable) {\n\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\ttarget[key] = wrapped;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If a property is being accessed in the course of setting up an\n\t\t// effect, track it\n\t\ttrackProxySignal(data, key);\n\t} else if (signal.type === COMPUTED_TYPE) {\n\t\tif (context.refreshSignals !== null && signal.isAsync) {\n\t\t\t// $refresh collection: record the $async computed so it can be\n\t\t\t// re-run as a bare refresh, then return its current value without\n\t\t\t// recalc/taint/boundary handling — collection is a pure peek. fn's\n\t\t\t// result is ignored by $refresh, so the value is only read to\n\t\t\t// trigger the same read path a UI read would.\n\t\t\tcontext.refreshSignals.push(signal);\n\t\t\treturn signal.value;\n\t\t}\n\t\tif (signal.running) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t} else if (signal.recalc) {\n\t\t\t// If a signal that the computed depends on has been changed,\n\t\t\t// but the computed hasn't yet been read, it may need to be\n\t\t\t// re-computed\n\t\t\tcheckComputed(signal);\n\t\t}\n\t\tif (signal.didError) {\n\t\t\t// If there was a previous error, and no dependencies have\n\t\t\t// changed, throw the error again. Subscribe first so the reader\n\t\t\t// re-runs if the computed later recovers (e.g. via a `$refresh`\n\t\t\t// that resolves a fresh fetch) — without this, the reader loses\n\t\t\t// its subscription on the throwing read and recovery can never\n\t\t\t// reach it.\n\t\t\ttrackSignal(signal);\n\t\t\tthrow signal.value;\n\t\t}\n\t\tif (signal.didSuspend) {\n\t\t\t// The computed returned a pending promise — subscribe the reader\n\t\t\t// (so resolve re-runs it), taint up the cache chain, and notify\n\t\t\t// the nearest boundary\n\t\t\treturn suspendRead(signal);\n\t\t}\n\t\ttrackSignal(signal);\n\t\treturn signal.value;\n\t}\n\n\t// Return the property value\n\t// NOTE: equivalent to `Reflect.get(target, key, receiver)` for the cases\n\t// that reach here (data properties or missing keys — anything with a\n\t// getter has early-returned above). Avoids a `Reflect.get` function call\n\t// per property read on a watched object, which is the dominant per-effect-\n\t// run cost: each row effect reads `$state.selected`, `data.row.id`, and\n\t// `data.row.label` (the `.row` access goes through this trap), so a 1k-row\n\t// render triggers ~3k of these calls.\n\treturn target[key];\n}\n\n// Prevent array functions from calling functions and properties in breakable\n// ways (e.g. calling splice sets length before adding items)\nconst arrayWrapper: Record<PropertyKey, any> = {\n\t// Iterating a watched array (`for…of`, spread, `Array.from`) must NOT walk\n\t// the proxy per element. The old path returned `Array.prototype[Symbol.iterator]`\n\t// unchanged, so for-of invoked it with the PROXY as `this` and every element\n\t// read `proxy[i]` hit the `get` trap (descriptor lookup, deep-wrap checks,\n\t// per-index signal creation, Map ops) — a 1k-row list cost ~100x the raw\n\t// iteration. Lists re-iterate their source array on EVERY run (the\n\t// compiler-emitted `buildItems`), making this the dominant cost of pure\n\t// bookkeeping ops (rotate/remove).\n\t//\n\t// Instead we iterate the RAW target directly and lazily `$watch`-wrap each\n\t// element, writing the proxy back (`target[i] = proxy`) exactly like the\n\t// `get` trap does on first access. That keeps a SINGLE proxy instance per\n\t// element, so in-place mutation (`$state.data[i].label = …`) still reaches\n\t// the row effects that subscribed through `item.data.row`, while skipping\n\t// the per-element trap entirely. `data.shallow` arrays are left unwrapped,\n\t// matching the `get` trap's deep-only behaviour.\n\t[Symbol.iterator]: function (data: ProxyData, target: any, _key: PropertyKey) {\n\t\ttrackProxySignal(data, \"length\");\n\t\t// HACK: This prevents lists being re-run on every random property\n\t\t// access by disabling the active effect before properties get\n\t\t// accessed. I'm not sure if this is the best way to achieve this...\n\t\tcontext.activeTarget = null;\n\t\treturn function arrayIterator() {\n\t\t\tlet index = 0;\n\t\t\treturn {\n\t\t\t\tnext() {\n\t\t\t\t\tif (index >= target.length) return { value: undefined, done: true };\n\t\t\t\t\tlet value = target[index];\n\t\t\t\t\tif (data.shallow !== true) {\n\t\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\t\tvalue = wrapped;\n\t\t\t\t\t\t\ttarget[index] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Mirror the `get` trap's per-index signal creation (a plain\n\t\t\t\t\t// index is never subscribed during iteration — activeTarget is\n\t\t\t\t\t// null — but keeping the signal means a later direct `arr[i]`\n\t\t\t\t\t// read inside an effect reuses it, exactly as before).\n\t\t\t\t\ttrackProxySignal(data, String(index));\n\t\t\t\t\tindex++;\n\t\t\t\t\treturn { value, done: false };\n\t\t\t\t},\n\t\t\t\t[Symbol.iterator]() {\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\t},\n\tpop: arrayHandle,\n\tpush: arrayHandle,\n\treverse: arrayHandle,\n\tshift: arrayHandle,\n\tsort: arrayHandle,\n\tsplice: arrayHandle,\n\tunshift: arrayHandle,\n\t// Read-only methods must also run on the raw target. `slice`/`filter`/`concat`\n\t// etc. called on the proxy walk every element through the `get` trap — the\n\t// same ~100x penalty — for nothing, since their results are either assigned\n\t// back into `$state.data` (re-wrapped by `$watch` in the `set` trap) or read\n\t// transiently. Running them on the raw array keeps the elements' proxy\n\t// identity unchanged (wrapped elements stay wrapped; raw elements stay raw\n\t// until the next iteration wraps them).\n\tslice: readHandle,\n\tconcat: readHandle,\n\tfilter: readHandle,\n\tmap: readHandle,\n\ttoReversed: readHandle,\n\ttoSorted: readHandle,\n\ttoSpliced: readHandle,\n\tindexOf: readHandle,\n\tlastIndexOf: readHandle,\n\tincludes: readHandle,\n\tfind: readHandle,\n\tfindIndex: readHandle,\n\tsome: readHandle,\n\tevery: readHandle,\n\tjoin: readHandle,\n\tforEach: readHandle,\n\treduce: readHandle,\n\treduceRight: readHandle,\n\tflat: readHandle,\n\tflatMap: readHandle,\n\tat: readHandle,\n};\n\nfunction readHandle(data: ProxyData, target: any, key: PropertyKey): Function {\n\t// Call the function on the target (so proxy properties don't get\n\t// intercepted). Read-only, so no `length` propagation — but an effect that\n\t// READS the array through one of these (`items.join(\"\")`, `items.slice(1)`)\n\t// must still subscribe to `length` so it re-runs on push/splice/index-set\n\t// (every array mutation propagates `length`). When no effect is active this\n\t// is a cheap no-op.\n\treturn function (...args: any[]) {\n\t\ttrackProxySignal(data, \"length\");\n\t\tconst func = target[key];\n\t\treturn func.apply(target, args);\n\t};\n}\n\nfunction arrayHandle(data: ProxyData, target: any, key: PropertyKey): Function {\n\t// Call the function on the target (so proxy properties don't get\n\t// intercepted) and trigger effects that depend on `length`\n\treturn function (...args: any[]) {\n\t\tconst func = target[key];\n\t\tconst result = func.apply(target, args);\n\t\tpropagateSignal(data, \"length\");\n\t\treturn result;\n\t};\n}\n\n// #region Date/Map/Set wrappers\n\n// Signal key for collection-wide reads (`size`, iteration). Also the fallback\n// per-key signal for keys that aren't primitives (object keys can't be signal\n// keys, since `data.signals` is keyed by PropertyKey)\nconst COLLECTION_KEY = Symbol(\"torp.collection\");\n// Signal key for all Date reads/writes (a Date only has one value, its time)\nconst TIME_KEY = \"#time\";\n\n/**\n * Routes a `get` on a watched Date/Map/Set to the right wrapper handler.\n *\n * Note the two levels of indirection for methods: the handler runs at get-trap\n * time (returning the method to call), and the returned function runs when the\n * method is invoked. `size` is the exception -- it returns its value at\n * get-trap time, because it's a readonly property, not a method.\n */\nfunction collectionGet(data: ProxyData, target: any, key: PropertyKey, receiver: any): any {\n\tif (data.isDate) {\n\t\treturn dateGet(data, target, key);\n\t}\n\tconst wrapper = data.isMap ? mapWrapper : setWrapper;\n\tconst handle = wrapper[key];\n\tif (handle !== undefined) {\n\t\treturn handle(data, target, key, receiver);\n\t}\n\treturn target[key];\n}\n\n/**\n * Returns the signal key for a Map/Set operation: primitives get a per-key\n * signal, so reading one key doesn't re-run effects when an unrelated key\n * changes. Anything else shares the collection-wide signal.\n */\nfunction collectionKey(key: any): PropertyKey {\n\tconst type = typeof key;\n\treturn type === \"string\" || type === \"number\" || type === \"symbol\" ? key : COLLECTION_KEY;\n}\n\n/**\n * Propagates a Map/Set mutation: the per-key signal (when the key is a\n * primitive) plus the collection-wide signal. The collection signal is always\n * enough for object keys, and propagating the same signal twice would re-run\n * effects twice (they re-subscribe between flushes).\n */\nfunction propagateCollection(data: ProxyData, key: PropertyKey): void {\n\tif (key !== COLLECTION_KEY) {\n\t\tpropagateSignal(data, key);\n\t}\n\tpropagateSignal(data, COLLECTION_KEY);\n}\n\nfunction dateGet(data: ProxyData, target: any, key: PropertyKey): any {\n\tif (typeof key === \"symbol\") {\n\t\t// `Symbol.toPrimitive` is looked up by the language itself for `==`\n\t\t// comparisons, arithmetic, template literals and JSON.stringify. It\n\t\t// must be invoked on the raw target (internal slots), and reading it\n\t\t// counts as a read of the date's value\n\t\tif (key === Symbol.toPrimitive) {\n\t\t\treturn function (hint: string) {\n\t\t\t\tconst result = target[Symbol.toPrimitive](hint);\n\t\t\t\ttrackProxySignal(data, TIME_KEY);\n\t\t\t\treturn result;\n\t\t\t};\n\t\t}\n\t\treturn target[key];\n\t}\n\tif (typeof key !== \"string\") {\n\t\treturn target[key];\n\t}\n\tconst value = target[key];\n\tif (typeof value !== \"function\") {\n\t\treturn value;\n\t}\n\tif (key.startsWith(\"set\")) {\n\t\treturn function (...args: any[]) {\n\t\t\t// Only propagate if the time actually changed, so setting the same\n\t\t\t// value is a no-op (same as the `set` trap)\n\t\t\tconst before = target.getTime();\n\t\t\tconst result = value.apply(target, args);\n\t\t\tif (target.getTime() !== before) {\n\t\t\t\tpropagateSignal(data, TIME_KEY);\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t}\n\tif (key.startsWith(\"get\") || key.startsWith(\"to\") || key === \"valueOf\") {\n\t\treturn function (...args: any[]) {\n\t\t\tconst result = value.apply(target, args);\n\t\t\ttrackProxySignal(data, TIME_KEY);\n\t\t\treturn result;\n\t\t};\n\t}\n\treturn value;\n}\n\nconst mapWrapper: Record<PropertyKey, any> = {\n\tsize: function (data: ProxyData, target: any): number {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\treturn target.size;\n\t},\n\tget: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\ttrackProxySignal(data, collectionKey(key));\n\t\t\tconst value = target.get(key);\n\t\t\tif (data.shallow !== true) {\n\t\t\t\t// Deep-wrap the value and write the proxy back, so repeated\n\t\t\t\t// reads return the same proxy (same as array elements)\n\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\ttarget.set(key, wrapped);\n\t\t\t\t}\n\t\t\t\treturn wrapped;\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t},\n\thas: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\ttrackProxySignal(data, collectionKey(key));\n\t\t\treturn target.has(key);\n\t\t};\n\t},\n\tset: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (key: any, value: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\t// Only propagate if the value actually changed or the key is new\n\t\t\t// (same as the `set` trap). Note a stored value may be a proxy\n\t\t\t// (see `get`), so unwrap both sides before comparing\n\t\t\tif (target.has(key) && $unwrap(target.get(key)) === $unwrap(value)) {\n\t\t\t\treturn receiver ?? target;\n\t\t\t}\n\t\t\t// A watched object is stored as its proxy, so reads return it\n\t\t\t// reactively (same as array elements written back by the iterator)\n\t\t\tconst result = target.set(key, value);\n\t\t\tpropagateCollection(data, collectionKey(key));\n\t\t\t// Map.set returns the map for chaining -- return the proxy so\n\t\t\t// chained mutations stay reactive\n\t\t\treturn receiver ?? result;\n\t\t};\n\t},\n\tdelete: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\tconst result = target.delete(key);\n\t\t\tpropagateCollection(data, collectionKey(key));\n\t\t\treturn result;\n\t\t};\n\t},\n\tclear: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\tconst result = target.clear();\n\t\t\t// Per-key readers must re-run too, and the keys are gone, so\n\t\t\t// propagate every signal this collection created -- in one batch,\n\t\t\t// so readers of several signals re-run only once\n\t\t\tbatchStart();\n\t\t\ttry {\n\t\t\t\tfor (const key of data.signals.keys()) {\n\t\t\t\t\tpropagateSignal(data, key);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tbatchEnd();\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t},\n\tkeys: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\treturn [...target.keys()][Symbol.iterator]();\n\t\t};\n\t},\n\tvalues: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tlet values = [...target.values()];\n\t\t\tif (data.shallow !== true) {\n\t\t\t\tvalues = values.map(deepWrap);\n\t\t\t}\n\t\t\treturn values[Symbol.iterator]();\n\t\t};\n\t},\n\tentries: mapEntries,\n\t// Map's default iteration protocol yields entries\n\t[Symbol.iterator]: mapEntries,\n\tforEach: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (callback: (value: any, key: any, collection: any) => void, thisArg?: any) {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tconst wrap = data.shallow !== true;\n\t\t\ttarget.forEach((value: any, key: any) => {\n\t\t\t\tcallback.call(thisArg, wrap ? deepWrap(value) : value, key, receiver ?? target);\n\t\t\t});\n\t\t};\n\t},\n};\n\nfunction mapEntries(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tconst wrap = data.shallow !== true;\n\t\tconst entries = [...target.entries()].map((entry) => [\n\t\t\tentry[0],\n\t\t\twrap ? deepWrap(entry[1]) : entry[1],\n\t\t]);\n\t\treturn entries[Symbol.iterator]();\n\t};\n}\n\nconst setWrapper: Record<PropertyKey, any> = {\n\tsize: function (data: ProxyData, target: any): number {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\treturn target.size;\n\t},\n\thas: function (data: ProxyData, target: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\ttrackProxySignal(data, collectionKey(value));\n\t\t\treturn target.has(value);\n\t\t};\n\t},\n\tadd: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\t// Adding an existing element is a no-op (same as the `set` trap)\n\t\t\tif (target.has(value)) {\n\t\t\t\treturn receiver ?? target;\n\t\t\t}\n\t\t\tconst result = target.add(value);\n\t\t\tpropagateCollection(data, collectionKey(value));\n\t\t\t// Set.add returns the set for chaining -- return the proxy so\n\t\t\t// chained mutations stay reactive\n\t\t\treturn receiver ?? result;\n\t\t};\n\t},\n\tdelete: function (data: ProxyData, target: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\tconst result = target.delete(value);\n\t\t\tpropagateCollection(data, collectionKey(value));\n\t\t\treturn result;\n\t\t};\n\t},\n\tclear: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\tconst result = target.clear();\n\t\t\t// Per-element readers must re-run too, and the elements are gone,\n\t\t\t// so propagate every signal this collection created -- in one\n\t\t\t// batch, so readers of several signals re-run only once\n\t\t\tbatchStart();\n\t\t\ttry {\n\t\t\t\tfor (const key of data.signals.keys()) {\n\t\t\t\t\tpropagateSignal(data, key);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tbatchEnd();\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t},\n\t// Sets yield the same elements from keys/values/iteration -- all wrapped,\n\t// so mutating an element re-runs readers\n\tkeys: setValues,\n\tvalues: setValues,\n\t[Symbol.iterator]: setValues,\n\tentries: setEntries,\n\tforEach: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (callback: (value: any, value2: any, collection: any) => void, thisArg?: any) {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tconst wrap = data.shallow !== true;\n\t\t\ttarget.forEach((value: any) => {\n\t\t\t\tconst wrapped = wrap ? deepWrap(value) : value;\n\t\t\t\tcallback.call(thisArg, wrapped, wrapped, receiver ?? target);\n\t\t\t});\n\t\t};\n\t},\n};\n\nfunction setValues(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tlet values = [...target.values()];\n\t\tif (data.shallow !== true) {\n\t\t\tvalues = values.map(deepWrap);\n\t\t}\n\t\treturn values[Symbol.iterator]();\n\t};\n}\n\nfunction setEntries(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tconst wrap = data.shallow !== true;\n\t\tconst entries = [...target.values()].map((value) => {\n\t\t\tconst wrapped = wrap ? deepWrap(value) : value;\n\t\t\treturn [wrapped, wrapped];\n\t\t});\n\t\treturn entries[Symbol.iterator]();\n\t};\n}\n\n// #endregion\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport deepWrap from \"./deepWrap\";\nimport propagateSignal from \"./propagateSignal\";\nimport { proxyDataSymbol } from \"./symbols\";\n\nexport default function proxySet(\n\ttarget: Record<PropertyKey, any>,\n\tkey: PropertyKey,\n\tvalue: any,\n\treceiver: any,\n): boolean {\n\t//console.log(`object set '${String(key)}' to`, value, \"on\", target);\n\t//console.log(`object set '${String(key)}'`);\n\n\t// Only do things if the value has changed\n\tconst oldValue = target[key];\n\tif (value !== oldValue) {\n\t\tif (context.batchOperation > 100) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\n\t\tlet data = target[proxyDataSymbol];\n\n\t\t// DEV:\n\t\tdevContext.signalSet(data, key);\n\n\t\t// Wrap the new value if it's an object (plain objects, arrays, Dates,\n\t\t// Maps, Sets), so storing it and mutating it through the proxy is\n\t\t// reactive right away -- same as the `get` trap's deep-wrap on read.\n\t\t// Skipped for shallow watches, whose children stay unwrapped.\n\t\t// NOTE: this is mostly an ergonomics/consistency win (raw values\n\t\t// assigned here used to leak out of raw-target paths like the array\n\t\t// `slice`/`map` handles). The `get` trap's lazy wrap still covers the\n\t\t// common read paths, so if profiling ever shows this line being slow\n\t\t// (it allocates a proxy per assigned object), just delete it and\n\t\t// everything reverts to wrap-on-read\n\t\tif (data.shallow !== true) {\n\t\t\tvalue = deepWrap(value);\n\t\t}\n\n\t\t// Set the property value on the target\n\t\tReflect.set(target, key, value, receiver);\n\n\t\t// Re-run effects\n\t\tpropagateSignal(data, key);\n\n\t\t// If an item in an array is being set directly, trigger the length to\n\t\t// cause any lists to be re-run and data re-bound\n\t\t// TODO: Can we update the single item's data directly somehow?\n\t\tif (data.isArray && typeof key !== \"symbol\" && !isNaN(+key)) {\n\t\t\tpropagateSignal(data, \"length\");\n\t\t}\n\t}\n\n\treturn true;\n}\n","import devContext from \"../dev/devContext\";\nimport type ProxyData from \"../types/ProxyData\";\nimport type WatchOptions from \"../types/WatchOptions\";\nimport proxyGet from \"./proxyGet\";\nimport proxySet from \"./proxySet\";\nimport { proxyDataSymbol } from \"./symbols\";\n\n// The Proxy handler is stateless — every trap looks up state via the\n// `proxyDataSymbol` property on the target itself — so a single shared\n// handler can serve every $watch'd object. Avoiding a fresh `{ get, set }`\n// allocation per $watch() call removes N object allocations per N-item list\n// render (the per-row `$watch(data, { shallow: true })` in runListItems is\n// called once for every keyed list item).\nconst sharedHandler: ProxyHandler<Record<PropertyKey, any>> = {\n\tget: proxyGet,\n\tset: proxySet,\n};\n\n/**\n * Watches an object and runs effects when its properties are changed.\n *\n * Dates, Maps and Sets are supported too: their methods are reactive (reads\n * track, writes notify), so `new Date()`, `new Map()` and `new Set()` can be\n * used in watched state directly.\n *\n * @param object The object to watch\n */\nexport default function $watch<T extends object>(object: T, options?: WatchOptions): T {\n\t// Return the object itself if it is undefined or null, or if it is already a proxy\n\tif (object === undefined || object === null || (object as any)[proxyDataSymbol] !== undefined) {\n\t\treturn object;\n\t}\n\n\t// Create a proxy handler for each object, and store some data for it here\n\tconst data: ProxyData = {\n\t\ttarget: object as Record<PropertyKey, any>,\n\t\tisArray: Array.isArray(object),\n\t\tisDate: object instanceof Date,\n\t\tisMap: object instanceof Map,\n\t\tisSet: object instanceof Set,\n\t\tshallow: options?.shallow === true,\n\t\tsignals: new Map(),\n\t};\n\n\t// Non-enumerable, so spreading or `Object.assign`-ing a watched object\n\t// (`$state.a = $state.a.map(c => ({ ...c }))`) doesn't copy the marker\n\t// into the new object — a copied ProxyData points at the OLD target and\n\t// makes the new object look already-watched, so it never gets deep-wrapped\n\tObject.defineProperty(object, proxyDataSymbol, {\n\t\tvalue: data,\n\t\twritable: true,\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t});\n\n\tconst proxy = new Proxy(object, sharedHandler) as T;\n\n\t// DEV:\n\tdevContext.onWatch(data);\n\n\treturn proxy;\n}\n","/**\n * Computes the indices (into `arr`) of a longest strictly-increasing\n * subsequence, skipping zero entries. Adapted from Vue 3's `getSequence`.\n *\n * Used by the keyed-list reconciler (`runListItems`): `arr` is the\n * `newIndexToOldIndex` map where `arr[i] = oldIndex + 1` (so `0` marks a\n * new/unmounted slot, which is skipped). The returned indices identify the\n * items that are already in correct relative order and therefore don't need\n * to be moved — everything else is moved or mounted.\n *\n * Runs in O(n log n).\n */\nexport default function getSequence(arr: number[]): number[] {\n\tconst p = arr.slice();\n\tconst result = [0];\n\tlet i: number;\n\tlet j: number;\n\tlet u: number;\n\tlet v: number;\n\tlet c: number;\n\tconst len = arr.length;\n\tfor (i = 0; i < len; i++) {\n\t\tconst arrI = arr[i]!;\n\t\tif (arrI !== 0) {\n\t\t\tj = result[result.length - 1]!;\n\t\t\tif (arr[j]! < arrI) {\n\t\t\t\tp[i] = j;\n\t\t\t\tresult.push(i);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tu = 0;\n\t\t\tv = result.length - 1;\n\t\t\twhile (u < v) {\n\t\t\t\tc = (u + v) >> 1;\n\t\t\t\tif (arr[result[c]!]! < arrI) {\n\t\t\t\t\tu = c + 1;\n\t\t\t\t} else {\n\t\t\t\t\tv = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (arrI < arr[result[u]!]!) {\n\t\t\t\tif (u > 0) {\n\t\t\t\t\tp[i] = result[u - 1]!;\n\t\t\t\t}\n\t\t\t\tresult[u] = i;\n\t\t\t}\n\t\t}\n\t}\n\tu = result.length;\n\tv = result[u - 1]!;\n\twhile (u-- > 0) {\n\t\tresult[u] = v;\n\t\tv = p[v]!;\n\t}\n\treturn result;\n}\n","import type Region from \"../types/Region\";\n\nexport default function moveRegion(parent: Node, region: Region, before: Node | null): void {\n\tparent = before?.parentNode ?? parent;\n\tconst endNode = region.endNode ?? region.startNode;\n\tlet currentNode = region.startNode;\n\n\twhile (currentNode !== null) {\n\t\tconst nextNode = currentNode.nextSibling;\n\t\tparent.insertBefore(currentNode, before);\n\t\tif (currentNode === endNode) break;\n\t\tcurrentNode = nextNode;\n\t}\n}\n","// Keyed list reconciliation with survivor reuse.\n//\n// The compiler-emitted `buildItems` callback returns a lightweight array of\n// `ListItemSpec`s ({key, data}) — one per row of the new data, with no DOM\n// nodes, effects, or sibling-chain pointers. This reconciler maps each spec\n// to either an EXISTING old ListItem (matched by key, reused wholesale — its\n// DOM nodes, effects, and depth are already correct) or a freshly mounted\n// ListItem (for genuinely new keys). This keeps the per-update cost\n// proportional to what actually changed: a single remove from a 1000-row list\n// touches one clearRegion, not a full per-row field-shuffle across all 999\n// survivors.\n//\n// Replaces an earlier snabbdom-derived 4-way head/tail heuristic with a\n// prefix/suffix sync + longest-increasing-subsequence (LIS) pass, which\n// produces the minimal move set. Operations (`moveRegion` / `mountSpec` /\n// `clearRegion`) and the LIS are unchanged in spirit from the\n// transferListItemData-based version — only the survivor handling is smarter\n// (reuse vs. copy-back).\n//\n// The sibling region chain (`previousRegion`/`nextRegion`) is relinked ONCE\n// at the end from the final item order. Nothing during reconciliation reads\n// it (moves and mounts use DOM `startNode`/`endNode`; `clearRegion` walks\n// each cleared region's own subtree), so a single end-of-pass relink is\n// sufficient and gives a clean invariant regardless of which path produced\n// `newItems`. This means `buildItems` no longer pre-links the chain.\nimport type ListItem from \"../types/ListItem\";\nimport type ListItemSpec from \"../types/ListItemSpec\";\nimport type Region from \"../types/Region\";\nimport type WatchOptions from \"../types/WatchOptions\";\nimport $watch from \"../watch/$watch\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\nimport getSequence from \"./getSequence\";\nimport moveRegion from \"./moveRegion\";\nimport newListItem from \"./newListItem\";\n\n// Hoisted options object — `$watch` only reads `options?.shallow`, so a single\n// shared constant can serve every per-item `$watch(data, { shallow: true })`\n// call in the mount path below. Removes one object allocation per mounted\n// list item (i.e. one per row in `run`/`add`/`runlots`).\nconst SHALLOW_WATCH_OPTIONS: WatchOptions = { shallow: true };\n\n/**\n * Mounts a new list item from a spec: allocates the ListItem, establishes it\n * as the active region (so the compiler-emitted `create` callback attaches\n * effects/events to the right region), sets its depth, optionally wraps its\n * data in a shallow watch, then runs `create`. Returns the mounted item so the\n * caller can slot it into the live list. The sibling chain is left for the\n * end-of-pass relink.\n */\nfunction mountSpec(\n\tspec: ListItemSpec,\n\tregion: Region,\n\tbefore: Node | null,\n\tcreate: (item: ListItem, before: Node | null) => void,\n\tnoWatch?: boolean,\n): ListItem {\n\tconst item: ListItem = newListItem(spec.data, spec.key);\n\tconst savedActiveRegion = context.activeRegion;\n\titem.depth = region.depth + 1;\n\tcontext.activeRegion = item;\n\tif (noWatch !== true) {\n\t\titem.data = $watch(item.data, SHALLOW_WATCH_OPTIONS);\n\t}\n\tcreate(item, before);\n\tcontext.activeRegion = savedActiveRegion;\n\treturn item;\n}\n\n/**\n * Reconciles an old keyed list against a new keyed list, reusing old\n * ListItems for survivors and producing the minimal set of DOM moves /\n * mounts / clears.\n *\n * @returns The new live list of ListItems (reused old items + freshly\n * mounted ones), which the caller keeps for the next reconciliation.\n *\n * @param region The list's region\n * @param parent The parent DOM element\n * @param anchor The DOM node to create new items before (the list's trailing anchor)\n * @param oldItems The list of current (live) items from the previous run\n * @param newSpecs The lightweight {key, data} specs for the new data\n * @param create A function that creates the DOM elements for a new item\n * @param update A function that syncs a matched item's data from its spec\n * (re-runs effects if a loop variable's reference actually changed)\n * @param noWatch When true, skip the per-item shallow `$watch` wrap. The\n * compiler guarantees the `@for` body never writes to its loop variables,\n * and emits an `update` callback that re-runs item effects manually when a\n * loop variable's reference actually changes (via `t_rerun_region_effects`).\n */\nexport default function runListItems(\n\tregion: Region,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\toldItems: ListItem[],\n\tnewSpecs: ListItemSpec[],\n\tcreate: (item: ListItem, before: Node | null) => void,\n\tupdate: (oldItem: ListItem, newSpec: ListItemSpec) => void,\n\tnoWatch?: boolean,\n): ListItem[] {\n\tconst newItems: ListItem[] = Array.from({ length: newSpecs.length });\n\n\t// Capture the region that follows the entire list BEFORE reconciliation —\n\t// `clearRegion` during the messy middle releases old items and nulls their\n\t// chain pointers, so the only safe moment to read the list's trailing\n\t// sibling is now. When the list has items, that sibling lives after the\n\t// old last item's LAST DESCENDANT: an item with an inner `@if`/`@for` owns\n\t// deeper child regions linked off `item.nextRegion`, so we must walk past\n\t// them — reading `oldItems[last].nextRegion` directly would capture the\n\t// item's first child, and the full relink below would then splice the\n\t// child into its own subtree (e.g. `if.nextRegion = if`), creating the\n\t// cycle that hangs the relink walk. When the list is empty, the sibling\n\t// lives on the list region's own `nextRegion` (set by\n\t// `pushRegion(region, true)` on first mount, or by a prior empty-list pass\n\t// through the relink below).\n\tlet nextSibling: Region | null;\n\tif (oldItems.length > 0) {\n\t\tconst lastOld = oldItems[oldItems.length - 1]!;\n\t\tnextSibling = lastOld.nextRegion;\n\t\twhile (nextSibling !== null && nextSibling.depth > lastOld.depth) {\n\t\t\tnextSibling = nextSibling.nextRegion;\n\t\t}\n\t} else {\n\t\tnextSibling = region.nextRegion;\n\t}\n\n\tlet oldStart = 0;\n\tlet oldEnd = oldItems.length - 1;\n\tlet newStart = 0;\n\tlet newEnd = newSpecs.length - 1;\n\n\t// Whether any item was mounted or moved during reconciliation. Mounts\n\t// produce items with null chain pointers (from `newListItem`); moves leave\n\t// an item's chain pointers pointing at its OLD neighbours. Both invalidate\n\t// the incremental relink fast path below. Pure updates and pure clears do\n\t// NOT set this: `update` only re-runs effects within an item's own subtree\n\t// (nested @if/@for push/pop and clearRegion splices preserve the sibling\n\t// links), and `clearRegion` splices the cleared item out and re-links its\n\t// neighbours, so the survivor chain stays correct without a relink.\n\tlet chainNeedsRelink = false;\n\n\t// 1. Fast path: peel off matching heads/tails and boundary rotations\n\t// (head→tail / tail→head) one item at a time, without building a\n\t// keymap. This handles append / prepend / swap / rotate and the\n\t// common-prefix/suffix portions of any change in O(1) per item.\n\t// rotateb/rotatef land here entirely (no keymap, no LIS). When no\n\t// boundary key matches, break and fall through to the LIS pass for\n\t// the messy middle (displace/shuffle). On a match we REUSE the old\n\t// ListItem (DOM nodes, effects, depth already correct) and just call\n\t// `update` to sync the spec's data references.\n\twhile (oldStart <= oldEnd && newStart <= newEnd) {\n\t\tif (oldItems[oldStart]!.key === newSpecs[newStart]!.key) {\n\t\t\t// common head — reuse the survivor in place\n\t\t\tconst item = oldItems[oldStart]!;\n\t\t\tupdate(item, newSpecs[newStart]!);\n\t\t\tnewItems[newStart] = item;\n\t\t\toldStart++;\n\t\t\tnewStart++;\n\t\t} else if (oldItems[oldEnd]!.key === newSpecs[newEnd]!.key) {\n\t\t\t// common tail — reuse the survivor in place\n\t\t\tconst item = oldItems[oldEnd]!;\n\t\t\tupdate(item, newSpecs[newEnd]!);\n\t\t\tnewItems[newEnd] = item;\n\t\t\toldEnd--;\n\t\t\tnewEnd--;\n\t\t} else if (oldItems[oldStart]!.key === newSpecs[newEnd]!.key) {\n\t\t\t// rotated head → tail: move the old head to just past the old tail\n\t\t\tconst item = oldItems[oldStart]!;\n\t\t\tmoveRegion(parent, item, oldItems[oldEnd]!.endNode?.nextSibling ?? anchor);\n\t\t\tchainNeedsRelink = true;\n\t\t\tupdate(item, newSpecs[newEnd]!);\n\t\t\tnewItems[newEnd] = item;\n\t\t\toldStart++;\n\t\t\tnewEnd--;\n\t\t} else if (oldItems[oldEnd]!.key === newSpecs[newStart]!.key) {\n\t\t\t// rotated tail → head: move the old tail to just before the old head\n\t\t\tconst item = oldItems[oldEnd]!;\n\t\t\tmoveRegion(parent, item, oldItems[oldStart]!.startNode);\n\t\t\tchainNeedsRelink = true;\n\t\t\tupdate(item, newSpecs[newStart]!);\n\t\t\tnewItems[newStart] = item;\n\t\t\toldEnd--;\n\t\t\tnewStart++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 2. Old middle exhausted → mount remaining new middle (common: append,\n\t// fresh create, or prefix-only change). Insert before the first suffix\n\t// node (or the list anchor if there's no suffix). Guarded on\n\t// `newStart <= newEnd` so a pass fully consumed by the head/tail fast\n\t// path (pure update — nothing mounted) does NOT flag the chain for a\n\t// relink it doesn't need.\n\tif (oldStart > oldEnd && newStart <= newEnd) {\n\t\tconst before = newEnd + 1 < newSpecs.length ? newItems[newEnd + 1]!.startNode : anchor;\n\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\tnewItems[i] = mountSpec(newSpecs[i]!, region, before, create, noWatch);\n\t\t}\n\t\tchainNeedsRelink = true;\n\t}\n\t// 3. New middle exhausted → clear remaining old middle (common: truncate / remove).\n\telse if (newStart > newEnd) {\n\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\tclearRegion(oldItems[i]!);\n\t\t}\n\t}\n\t// 4. Messy middle — LIS-based reconciliation (moves + mounts + clears).\n\telse {\n\t\t// 4a. Build newKey → newIndex for the new middle.\n\t\tconst newKeyToIndex = new Map<unknown, number>();\n\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\tnewKeyToIndex.set(newSpecs[i]!.key, i);\n\t\t}\n\n\t\t// 4b. No-overlap fast path: every old middle key is absent from the new\n\t\t// middle → full replacement. Batch-clear the old middle (reverse, so\n\t\t// each region's DOM is still attached when clearRegion walks it) and\n\t\t// batch-mount the new middle. Avoids the keymap/LIS allocation for\n\t\t// the common \"replace all\" / \"rebuild from scratch\" case (e.g. `run`,\n\t\t// `runlots`).\n\t\tlet anyOverlap = false;\n\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\tif (newKeyToIndex.has(oldItems[i]!.key)) {\n\t\t\t\tanyOverlap = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!anyOverlap) {\n\t\t\tconst lastOld = oldItems[oldEnd];\n\t\t\tlet before = (lastOld?.endNode?.nextSibling ?? anchor) as Node | null;\n\t\t\tfor (let i = oldEnd; i >= oldStart; i--) {\n\t\t\t\tclearRegion(oldItems[i]!);\n\t\t\t}\n\t\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\t\tnewItems[i] = mountSpec(newSpecs[i]!, region, before, create, noWatch);\n\t\t\t\tbefore = newItems[i]!.endNode!.nextSibling;\n\t\t\t}\n\t\t\tchainNeedsRelink = true;\n\t\t} else {\n\t\t\t// 4c. Walk the old middle: reuse matches into their new positions\n\t\t\t// (via update) and clear the rest. `newIndexToOld[i] = oldIndex\n\t\t\t// + 1` (0 marks a new slot that has no matching old item and\n\t\t\t// must be mounted).\n\t\t\tconst newMidLen = newEnd - newStart + 1;\n\t\t\tconst newIndexToOld = Array.from({ length: newMidLen }).fill(0) as number[];\n\t\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\t\tconst oldItem = oldItems[i]!;\n\t\t\t\tconst newIdx = newKeyToIndex.get(oldItem.key);\n\t\t\t\tif (newIdx !== undefined) {\n\t\t\t\t\tnewIndexToOld[newIdx - newStart] = i + 1;\n\t\t\t\t\tupdate(oldItem, newSpecs[newIdx]!);\n\t\t\t\t\tnewItems[newIdx] = oldItem;\n\t\t\t\t} else {\n\t\t\t\t\tclearRegion(oldItem);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 4d. LIS of `newIndexToOld` → indices of items already in correct\n\t\t\t// relative order (they stay; everything else moves or mounts).\n\t\t\tconst seq = getSequence(newIndexToOld);\n\n\t\t\t// 4e. Move/mount right-to-left. The right neighbour (newIdx+1) was\n\t\t\t// placed in the previous iteration (or is a patched suffix\n\t\t\t// item), so its `startNode` is the correct insertion anchor.\n\t\t\tlet j = seq.length - 1;\n\t\t\tfor (let i = newMidLen - 1; i >= 0; i--) {\n\t\t\t\tconst newIdx = newStart + i;\n\t\t\t\tconst before = newIdx + 1 < newSpecs.length ? newItems[newIdx + 1]!.startNode : anchor;\n\t\t\t\tif (newIndexToOld[i] === 0) {\n\t\t\t\t\t// No matching old item → mount.\n\t\t\t\t\tnewItems[newIdx] = mountSpec(newSpecs[newIdx]!, region, before, create, noWatch);\n\t\t\t\t\tchainNeedsRelink = true;\n\t\t\t\t} else if (j < 0 || i !== seq[j]) {\n\t\t\t\t\t// Not in the LIS → move to its new position.\n\t\t\t\t\tmoveRegion(parent, newItems[newIdx]!, before);\n\t\t\t\t\tchainNeedsRelink = true;\n\t\t\t\t} else {\n\t\t\t\t\t// In the LIS → already in correct relative order.\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// 5. Relink the sibling region chain across the final items, in order.\n\t// Nothing during reconciliation reads `previousRegion`/`nextRegion`\n\t// (moves and mounts use DOM `startNode`/`endNode`; `clearRegion` walks\n\t// each cleared region's own subtree and unlinks the cleared node from\n\t// its then-current neighbours), so a single end-of-pass relink from the\n\t// final `newItems` order is correct regardless of which path produced\n\t// it. This replaces the old design where `buildItems` pre-linked the\n\t// chain and `transferListItemData` copied it field-by-field.\n\t//\n\t// The chain is a flat doubly-linked list in render order, with `depth`\n\t// marking nesting. A @for item at depth D may own descendant regions\n\t// (e.g. an `@if` body) at D+1 linked off `item.nextRegion`. So siblings\n\t// must link through each item's LAST DESCENDANT (walk `nextRegion` while\n\t// it's deeper than the item), not through the item itself — otherwise\n\t// the item→child link gets overwritten and `clearRegion` can no longer\n\t// walk the subtree to run cleanups on removal.\n\t//\n\t// FAST PATH (incremental end-of-pass relink): when NO item was mounted\n\t// or moved (`chainNeedsRelink === false`), the survivor chain is already\n\t// correct. `clearRegion` splices each cleared item out and re-links its\n\t// neighbours; `update` only re-runs effects within an item's own subtree\n\t// (a nested @if/@for branch switch pushes/clears CHILD regions, which\n\t// `pushRegion`/`clearRegion` keep spliced correctly into the chain, so\n\t// the item's sibling links — and its tail link to the next sibling — are\n\t// preserved). So the head link (`region.nextRegion`), every inter-item\n\t// link, and the tail link (`lastDescendant → nextSibling`) are all still\n\t// valid. The only write still required is publishing\n\t// `context.previousRegion` for whatever region gets pushed after us,\n\t// which the full relink would overwrite anyway. This turns a 1000-row\n\t// `removefirst`/`removeevery10` (pure-removal shapes) from a 1000-item\n\t// relink walk into an O(1) tail-fixup — matching octane's one-pointer\n\t// patch on the same shapes.\n\tif (!chainNeedsRelink && newItems.length > 0) {\n\t\tlet lastRegion: Region = newItems[newItems.length - 1]!;\n\t\tlet next: Region | null = lastRegion.nextRegion;\n\t\twhile (next !== null && next.depth > lastRegion.depth) {\n\t\t\tlastRegion = next;\n\t\t\tnext = next.nextRegion;\n\t\t}\n\t\tcontext.previousRegion = lastRegion;\n\t\treturn newItems;\n\t}\n\n\tif (newItems.length > 0) {\n\t\tlet prevTail: Region = region;\n\t\tfor (let i = 0; i < newItems.length; i++) {\n\t\t\tconst item = newItems[i]!;\n\t\t\titem.previousRegion = prevTail;\n\t\t\tprevTail.nextRegion = item;\n\t\t\t// Advance to the last region in this item's subtree: follow\n\t\t\t// `nextRegion` as long as it descends deeper than the item. A leaf\n\t\t\t// row has no descendants, so `last` stays `item` and the next\n\t\t\t// iteration's `prevTail.nextRegion = nextItem` updates the item's\n\t\t\t// own `nextRegion` (preserving the old sibling-only behaviour).\n\t\t\tlet last: Region = item;\n\t\t\tlet next: Region | null = item.nextRegion;\n\t\t\twhile (next !== null && next.depth > item.depth) {\n\t\t\t\tlast = next;\n\t\t\t\tnext = next.nextRegion;\n\t\t\t}\n\t\t\tprevTail = last;\n\t\t}\n\t\t// `prevTail` is now the very last region in the list. Link it to\n\t\t// whatever followed the list, and publish it as the insertion point\n\t\t// for the next sibling region pushed after us.\n\t\tprevTail.nextRegion = nextSibling;\n\t\tif (nextSibling !== null) {\n\t\t\tnextSibling.previousRegion = prevTail;\n\t\t}\n\t\tregion.nextRegion = newItems[0]!;\n\t\tcontext.previousRegion = prevTail;\n\t} else {\n\t\t// Empty list: link the list region directly to its trailing sibling,\n\t\t// and publish the list region itself as the insertion point for the\n\t\t// next sibling region pushed after us.\n\t\tregion.nextRegion = nextSibling;\n\t\tif (nextSibling !== null) {\n\t\t\tnextSibling.previousRegion = region;\n\t\t}\n\t\tcontext.previousRegion = region;\n\t}\n\n\treturn newItems;\n}\n","import type ListItem from \"../types/ListItem\";\nimport type ListItemSpec from \"../types/ListItemSpec\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport context from \"./context\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport runListItems from \"./runListItems\";\n\n/**\n * Runs a `for` control statement\n * @param buildItems A function that returns the current list of lightweight\n * `{key, data}` specs (one per row of the source data)\n * @param create A function that creates the control statement's branches\n * @param noWatch When true, the compiler has determined the `@for` body never\n * writes to its loop variables, so each item's `data` bag can be left\n * unwrapped (skipping the per-item shallow `$watch` Proxy + ProxyData +\n * signals Map allocations). The compiler-emitted `update` callback is then\n * responsible for re-running item effects when a loop variable's reference\n * actually changes (via `t_rerun_region_effects`).\n */\nexport default function runList(\n\tregion: Region,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\tbuildItems: () => ListItemSpec[],\n\tcreate: (item: ListItem, anchor: Node | null) => void,\n\tupdate: (oldItem: ListItem, newSpec: ListItemSpec) => void,\n\tnoWatch?: boolean,\n): void {\n\tlet first = true;\n\tlet listItems: ListItem[] = [];\n\n\t// Run the list in an effect\n\t$run(function runList() {\n\t\t// If this region has been cleared (e.g. a parent @if switched to a\n\t\t// different branch), skip the update — the list will be re-created\n\t\t// when the parent branch re-renders\n\t\tif (region.depth === -2) return;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Build the array of lightweight {key, data} specs for the new data\n\t\tconst newSpecs = buildItems();\n\n\t\t// Do NOT re-run the list for properties accessed while updating its\n\t\t// items. E.g. we want to re-run the list for `@for (item of $items)`\n\t\t// (in buildItems, above) but not for `<span>{item.id}</span>` (in\n\t\t// runListItems, below)\n\t\tcontext.activeTarget = null;\n\n\t\t// Reconcile: reuse old ListItems for survivors, mount fresh ones for\n\t\t// new keys, clear dropped ones. Returns the new live list, which we\n\t\t// keep for the next run.\n\t\tlistItems = runListItems(region, parent, anchor, listItems, newSpecs, create, update, noWatch);\n\n\t\tpopRegion(oldRegion);\n\t});\n}\n","import type Effect from \"../types/Effect\";\nimport type AwaitBoundary from \"../types/AwaitBoundary\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport trackSignal from \"../watch/trackSignal\";\nimport context from \"./context\";\nimport isCommentNode from \"./isCommentNode\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport runControlBranch from \"./runControlBranch\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Comment prefix marking the embedded `source: \"server\"` values that the\n * server writes after a resolved boundary's anchor (`<!--t-await:[...]-->`,\n * see ASYNC.md → \"Server rendering\").\n */\nconst SERVER_VALUES_PREFIX = \"t-await:\";\n\n/**\n * Renders an `@await` boundary. On the first run, content is rendered\n * speculatively; if any read inside suspends (`didSuspend`), the boundary\n * discards the partial render and shows the `with` branch instead.\n *\n * Hydration of a server-resolved boundary (ASYNC.md → \"Server rendering\"): when the server\n * shipped resolved content, its values ride in a payload comment after the\n * anchor. The boundary renders the content branch *with* hydration enabled\n * and `$async` seeds its computeds from the payload, so the server's HTML is\n * adopted directly — no speculative render, no `with`-branch dance, no\n * fallback flash.\n *\n * Fine-grained updates: on subsequent runs the boundary only decides whether\n * to SWITCH branches. It does so from its `pending` set — the suspended\n * computeds recorded by `suspendRead` — dropping entries that resolved and\n * re-subscribing the still-suspended ones (a re-run deactivates all of the\n * effect's source subscriptions, so they must be re-tracked to survive\n * `clearSources`). That check is O(pending reads), not O(all sources), and\n * non-suspend dependency changes inside content are left to the child\n * effects that read them — the boundary isn't re-run by them at all.\n *\n * Stale-while-revalidate (ASYNC.md): once content has been produced\n * (`hasContent`), a subsequent suspend during a refresh does NOT switch to\n * the `with` branch — the boundary keeps the stale content mounted. `$async`\n * retains the previous resolved value (`Computed.staleValue`) and\n * `suspendRead` returns it, so child effects keep displaying the old value\n * until the new promise resolves and updates them in place. The `with` branch\n * is shown only on the first load, before content has ever rendered\n * successfully.\n *\n * @param renderContent Builds the content children (may read $async getters).\n * @param renderWith Builds the `with`-branch children, or null for empty.\n */\nexport default function runAwait(\n\tregion: Region,\n\tanchor: Node | null,\n\trenderContent: (anchor: Node | null) => void,\n\trenderWith: ((anchor: Node | null) => void) | null,\n\tname?: string,\n): void {\n\tconst boundary: AwaitBoundary = {\n\t\tsuspended: false,\n\t\tpending: new Set(),\n\t\teffect: null,\n\t};\n\tlet index = -1; // -1 = initial, 0 = content, 1 = with\n\tlet first = true;\n\tlet hasContent = false; // true once content has rendered without suspending\n\tlet theEffect: Effect | null = null;\n\n\t// Resolved values embedded by the server for this boundary, read once\n\t// during hydration\n\tlet serverValues: any[] | null = null;\n\tif (context.hydrationNode !== null && anchor !== null) {\n\t\tconst next = anchor.nextSibling;\n\t\tif (next !== null && isCommentNode(next) && next.data.startsWith(SERVER_VALUES_PREFIX)) {\n\t\t\ttry {\n\t\t\t\tserverValues = JSON.parse(next.data.substring(SERVER_VALUES_PREFIX.length));\n\t\t\t} catch {\n\t\t\t\tserverValues = null;\n\t\t\t}\n\t\t\tnext.remove();\n\t\t}\n\t}\n\n\tconst gen = (region.generation = (region.generation ?? 0) + 1);\n\n\t$run(function runAwait() {\n\t\tif (region.generation !== gen) return;\n\n\t\t// On the first call, $run hasn't returned yet so theEffect is null.\n\t\t// runEffect sets context.activeTarget to this effect before calling\n\t\t// run(), so capture it here for suspendRead's subscription.\n\t\ttheEffect = context.activeTarget as Effect;\n\t\tboundary.effect = theEffect;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Render a branch into a fresh child region, clearing the old branch\n\t\tconst renderBranch = (targetIndex: number, fn: (anchor: Node | null) => void) => {\n\t\t\trunControlBranch(region, index, targetIndex);\n\t\t\t// runControlBranch may have cleared the previous branch, leaving\n\t\t\t// context.previousRegion pointing at a released region. Reset it\n\t\t\t// to the await region so the new branch links correctly.\n\t\t\tcontext.previousRegion = region;\n\t\t\tconst branchRegion = newRegion(targetIndex === 0 ? \"await_content\" : \"await_with\");\n\t\t\tconst oldR = pushRegion(branchRegion, true);\n\t\t\tfn(anchor);\n\t\t\tpopRegion(oldR);\n\t\t\tindex = targetIndex;\n\t\t};\n\n\t\t// Render content with boundary context active; if it suspends and a\n\t\t// with-branch exists, immediately switch to it\n\t\tconst attemptContent = () => {\n\t\t\tconst oldBoundary = context.awaitBoundary;\n\t\t\tcontext.awaitBoundary = boundary;\n\t\t\tboundary.suspended = false;\n\n\t\t\t// During hydration of a server-resolved boundary, the values\n\t\t\t// embedded by the server are made available to `$async` while the\n\t\t\t// content branch renders, and hydration stays enabled so the\n\t\t\t// content adopts the server's nodes directly.\n\t\t\t//\n\t\t\t// Otherwise (a client-fetch boundary), hydration is temporarily\n\t\t\t// disabled: the speculative content render creates fresh nodes\n\t\t\t// instead of reusing the server's with-branch nodes (which would\n\t\t\t// be destroyed when content is cleared on suspend, leaving\n\t\t\t// nothing for the with-branch to hydrate against).\n\t\t\tconst savedHydration = context.hydrationNode;\n\t\t\tconst savedServerValues = context.serverValues;\n\t\t\tif (serverValues !== null && savedHydration !== null) {\n\t\t\t\tcontext.serverValues = { values: serverValues, index: 0 };\n\t\t\t} else if (savedHydration !== null) {\n\t\t\t\tcontext.hydrationNode = null;\n\t\t\t}\n\n\t\t\trenderBranch(0, renderContent);\n\n\t\t\tcontext.hydrationNode = savedHydration;\n\t\t\tcontext.serverValues = savedServerValues;\n\n\t\t\tcontext.awaitBoundary = oldBoundary;\n\n\t\t\tif (boundary.suspended && renderWith !== null) {\n\t\t\t\trenderBranch(1, renderWith);\n\t\t\t} else if (!boundary.suspended) {\n\t\t\t\t// Content rendered without suspending — mark it so a later\n\t\t\t\t// refresh suspend keeps showing stale content (§6.2).\n\t\t\t\thasContent = true;\n\t\t\t}\n\t\t};\n\n\t\tif (theEffect === null) {\n\t\t\t// First run (theEffect is assigned after $run returns): render\n\t\t\t// content speculatively to detect suspend\n\t\t\tattemptContent();\n\t\t} else {\n\t\t\t// Subsequent run: refresh the pending set — resolved computeds\n\t\t\t// drop out, still-suspended ones re-subscribe the boundary effect\n\t\t\t// (checkEffect deactivated every source subscription before this\n\t\t\t// run; without re-tracking, clearSources would detach the\n\t\t\t// boundary from its pending reads and it would never re-run when\n\t\t\t// they resolve). Only switch branches when the suspend state\n\t\t\t// actually changed.\n\t\t\tlet suspended = false;\n\t\t\tfor (const signal of boundary.pending) {\n\t\t\t\tif (signal.didSuspend) {\n\t\t\t\t\tsuspended = true;\n\t\t\t\t\ttrackSignal(signal);\n\t\t\t\t} else {\n\t\t\t\t\tboundary.pending.delete(signal);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst targetIndex = suspended ? 1 : 0;\n\n\t\t\tif (targetIndex !== index) {\n\t\t\t\tif (targetIndex === 0) {\n\t\t\t\t\t// Switching to content — render and check for re-suspend\n\t\t\t\t\tattemptContent();\n\t\t\t\t} else if (!hasContent) {\n\t\t\t\t\t// First-load suspend (content never shown): show the\n\t\t\t\t\t// with-branch. When hasContent, a refresh suspend keeps\n\t\t\t\t\t// the stale content mounted instead of flashing the\n\t\t\t\t\t// with-branch — stale-while-revalidate (ASYNC.md).\n\t\t\t\t\t// Child effects read the retained value via $async's\n\t\t\t\t\t// staleValue and re-render with the new value when the\n\t\t\t\t\t// promise resolves.\n\t\t\t\t\tif (renderWith !== null) {\n\t\t\t\t\t\trenderBranch(1, renderWith);\n\t\t\t\t\t} else {\n\t\t\t\t\t\trunControlBranch(region, index, 1);\n\t\t\t\t\t\tindex = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later run that switched branches may have rendered content\n\t\t// before our anchor that an ancestor's node window doesn't cover —\n\t\t// widen those windows so clearing the ancestor can't orphan the\n\t\t// content (see widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\t}, name);\n}\n","import context from \"./context\";\n\n/**\n * Snapshots the hydration cursor so a `@try` branch's partial hydration walk\n * can be rewound if the branch throws and the `@catch` branch renders instead.\n *\n * @returns The current hydration cursor node, or `null` when not hydrating.\n */\nexport default function saveHydration(): ChildNode | null {\n\treturn context.hydrationNode;\n}\n","import type Effect from \"../types/Effect\";\nimport type ErrorBoundary from \"../types/ErrorBoundary\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport trackSignal from \"../watch/trackSignal\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport restoreHydration from \"./restoreHydration\";\nimport runControlBranch from \"./runControlBranch\";\nimport saveHydration from \"./saveHydration\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Renders a `@try`/`@catch` group, or a top-level `@error` block (which the\n * compiler wraps around the whole render).\n *\n * Like `runAwait`, the boundary is a control effect that renders one branch\n * at a time into a fresh child region (`runControlBranch` clears the old\n * branch on switch). Unlike the old compiled form, the try/catch lives in\n * this runtime, which gives it three capabilities the compiled form lacked:\n *\n * - **Effect-rerun error routing.** The boundary registers itself on its\n * region (`region.errorBoundary`); when an effect inside the try content\n * throws on a later re-run, `triggerEffects` → `routeEffectError` stores\n * the error here and force re-runs the boundary effect, which renders the\n * catch branch with it.\n * - **Recovery outside direct reads.** Reactive reads wrapped in nested\n * `$run` effects (text/attribute interpolation) are tracked by those\n * effects, not the boundary. When an error is routed, the boundary holds\n * the erroring effect's source signals (`heldSignals`) and re-subscribes\n * to them on every run that shows the catch branch, so a later change\n * re-attempts the try branch.\n * - **Top-level `@error` recovery.** Because the whole render is a\n * re-runnable branch, a later re-render error (from a nested control\n * re-running after a prop change) is caught by the same routing, and a\n * recovery re-render clears the error content and restores the normal\n * content.\n *\n * Semantics preserved from the compiled form:\n *\n * - Synchronous build errors in the try content render the catch branch\n * (rewinding the hydration cursor and restoring the control region, which\n * the failed partial build left active).\n * - While the try branch is showing, a boundary re-run with no routed error\n * does NOT rebuild it (`runControlBranch` same-index skip) — exactly like\n * `@if`/`@switch` branches.\n * - While the catch branch is showing, any boundary re-run re-attempts the\n * try branch (the recovery path for errors read directly by the boundary\n * effect, e.g. via `@const`).\n * - With no catch branch, errors propagate up to the nearest outer boundary\n * and no boundary is registered on the region.\n *\n * @param renderTry Builds the try content. May read reactive state.\n * @param renderCatch Builds the catch content, or null for `@try` without\n * `@catch`. Receives the error (the `@catch (err)` variable).\n */\nexport default function runTry(\n\tregion: Region,\n\tanchor: Node | null,\n\trenderTry: (anchor: Node | null) => void,\n\trenderCatch: ((anchor: Node | null, error: any) => void) | null,\n\tname?: string,\n): void {\n\tconst boundary: ErrorBoundary = {\n\t\terror: undefined,\n\t\thasError: false,\n\t\teffect: null,\n\t\theldSignals: null,\n\t};\n\tif (renderCatch !== null) {\n\t\tregion.errorBoundary = boundary;\n\t}\n\n\tlet index = -1; // -1 = initial, 0 = try, 1 = catch\n\tlet first = true;\n\n\tconst gen = (region.generation = (region.generation ?? 0) + 1);\n\n\t$run(function runTry() {\n\t\t// If this effect was created by a previous runTry call for the same\n\t\t// region, it is stale and should not execute\n\t\tif (region.generation !== gen) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst theEffect = context.activeTarget as Effect;\n\t\tboundary.effect = theEffect;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Render a branch into a fresh child region, clearing the old branch\n\t\tconst renderBranch = (targetIndex: number, fn: (anchor: Node | null) => void) => {\n\t\t\trunControlBranch(region, index, targetIndex);\n\t\t\t// runControlBranch may have cleared the previous branch, leaving\n\t\t\t// context.previousRegion pointing at a released region. Reset it\n\t\t\t// to the boundary region so the new branch links correctly.\n\t\t\tcontext.previousRegion = region;\n\t\t\tconst branchRegion = newRegion(targetIndex === 0 ? \"try\" : \"catch\");\n\t\t\tconst oldR = pushRegion(branchRegion, true);\n\t\t\tfn(anchor);\n\t\t\tpopRegion(oldR);\n\t\t\tindex = targetIndex;\n\t\t};\n\n\t\t// (Re-)subscribe the boundary effect to the held signals. Called\n\t\t// while the boundary effect is the active target, so the\n\t\t// subscriptions are active and survive `clearSources`\n\t\tconst holdSignals = () => {\n\t\t\tif (boundary.heldSignals === null || theEffect === null) return;\n\t\t\tfor (const signal of boundary.heldSignals) {\n\t\t\t\ttrackSignal(signal);\n\t\t\t}\n\t\t};\n\n\t\t// An effect error routed from triggerEffects renders the catch branch\n\t\t// via the stored boundary error\n\t\tconst hasRoutedError = boundary.hasError;\n\t\tconst routedError = boundary.error;\n\t\tboundary.hasError = false;\n\n\t\tif (hasRoutedError && renderCatch !== null) {\n\t\t\t// Force a re-render of the catch branch (the try branch's content\n\t\t\t// — including the erroring effect — is cleared by the branch\n\t\t\t// switch), then hold the routed signals for recovery\n\t\t\tindex = -1;\n\t\t\trenderBranch(1, (a) => renderCatch(a, routedError));\n\t\t\tholdSignals();\n\t\t} else if (index !== 0) {\n\t\t\t// First run, or the catch branch is showing and a dependency\n\t\t\t// changed: (re-)attempt the try content\n\t\t\tconst snapshot = saveHydration();\n\t\t\ttry {\n\t\t\t\trenderBranch(0, renderTry);\n\t\t\t\t// The try attempt succeeded: stop holding routed signals (the\n\t\t\t\t// attempt's own reads now drive future re-runs)\n\t\t\t\tboundary.heldSignals = null;\n\t\t\t} catch (err) {\n\t\t\t\t// The failed attempt left its branch region active/stale and\n\t\t\t\t// may have advanced the hydration cursor. Restore the control\n\t\t\t\t// region and rewind the cursor before rendering the catch\n\t\t\t\t// branch (the branch switch below clears the partial try\n\t\t\t\t// content)\n\t\t\t\tpushRegion(region);\n\t\t\t\trestoreHydration(snapshot);\n\t\t\t\tif (renderCatch !== null) {\n\t\t\t\t\tindex = -1;\n\t\t\t\t\trenderBranch(1, (a) => renderCatch(a, err));\n\t\t\t\t\tholdSignals();\n\t\t\t\t} else {\n\t\t\t\t\t// No catch branch: propagate to the nearest outer boundary\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later re-run may have rendered content before our anchor that an\n\t\t// ancestor's node window doesn't cover — widen those windows so\n\t\t// clearing the ancestor can't orphan the content (see\n\t\t// widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\n\t\t// While hydrating, reset the cursor to the boundary's anchor after\n\t\t// its content has been hydrated (see runControl)\n\t\tif (context.hydrationNode !== null && anchor !== null) {\n\t\t\tcontext.hydrationNode = anchor as ChildNode;\n\t\t}\n\t}, name);\n}\n","/**\n * Gets an element from the document head matching the selector, creating and\n * appending a new one if there isn't a match. Used by the code generated for\n * a @head block, so that elements which were server rendered (or rendered by\n * a previously visited page) are adopted rather than duplicated.\n */\nexport default function headElement(tagName: string, selector: string): Element {\n\tif (selector) {\n\t\tconst existing = document.head.querySelector(selector);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\t}\n\tconst element = document.createElement(tagName);\n\tdocument.head.appendChild(element);\n\treturn element;\n}\n","export default function setAttribute(el: Element, name: string, value: any): void {\n\tif (value === false || value === undefined || value === null) {\n\t\tel.removeAttribute(name);\n\t} else {\n\t\tel.setAttribute(name, value);\n\t}\n}\n","import context from \"./context\";\nimport { copyEventListeners } from \"./delegatedEvents\";\n\n// TODO: Should we @toggle this instead? That would call onmount etc again for the new element\n\nexport default function setDynamicElement(el: HTMLElement, tag: string): HTMLElement {\n\t// If hydrating, it should already have been created as the correct element\n\tif (context.hydrationNode !== null) {\n\t\treturn el;\n\t}\n\n\t// Replace the old element with the new element\n\tlet newElement = el.ownerDocument.createElement(tag);\n\tfor (const attr of el.attributes) {\n\t\tnewElement.setAttributeNS(null, attr.name, attr.value);\n\t}\n\t// Carry over event listeners, so a reactive `self` tag change doesn't\n\t// silently drop the element's handlers\n\tcopyEventListeners(el, newElement);\n\tnewElement.replaceChildren(...el.childNodes.values());\n\tel.replaceWith(newElement);\n\n\treturn newElement;\n}\n","import context from \"../render/context\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\n\n/**\n * Runs updates to proxy values in a batch, where the updates are stored in\n * context, and dependent effects are run all at once at the end.\n *\n * @param fn The function containing the batched updates to run.\n */\nexport default function $batch<T>(fn: () => T): T {\n\tif (context.batch > 0) {\n\t\treturn fn();\n\t}\n\n\tbatchStart();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tbatchEnd();\n\t}\n}\n","import context from \"../render/context\";\nimport type AsyncOptions from \"../types/AsyncOptions\";\nimport type Computed from \"../types/Computed\";\nimport { COMPUTED_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport { propagateFromSignal } from \"./propagateSignal\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Caches an async computed value from a thunk that returns a Promise. A peer\n * of `$cache` for async getters: the returned Computed carries a `didSuspend`\n * indicator that the proxy get trap reads to suspend callers until the promise\n * resolves.\n *\n * The thenable check and `.then` wiring live inside `computed.run` (a closure\n * over the computed object), so they fire on both the initial run and every\n * recalculation — `runComputed` and `checkComputed` are unchanged.\n *\n * Hydration seeding (ASYNC.md → \"Server rendering\"): while hydrating the content branch of\n * a boundary whose server HTML embedded resolved `source: \"server\"` values,\n * `context.serverValues` is set, and this read consumes the value at the\n * current position instead of suspending. The thunk still runs — once, in\n * the background — so the getter's dependencies are tracked and later\n * dependency changes re-fetch; the embedded value wins the generation race,\n * so there's no re-fetch wait and no fallback flash.\n *\n * @param fn A thunk returning the Promise to await. Signal reads inside `fn`\n * are tracked, so the fetch re-runs when dependencies change.\n * @param _options Accepted so the same getter source compiles into client and\n * server builds (`source: \"server\"` fetches during SSR); ignored here.\n */\nexport default function $async<T>(fn: () => Promise<T>, _options?: AsyncOptions): T {\n\tif (context.registerComputed === null) {\n\t\tthrow new Error(\"$async must be used in a getter\");\n\t}\n\n\tconst computed: Computed = {\n\t\ttype: COMPUTED_TYPE,\n\t\tisAsync: true,\n\t\tvalue: null,\n\t\trun: null as unknown as () => any,\n\t\tfirstSource: null,\n\t\tfirstTarget: null,\n\t\trecalc: false,\n\t\trunning: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tgeneration: 0,\n\t\thasResolved: false,\n\t\tlastErrored: false,\n\t\tsuspendQuiet: false,\n\t\tstaleValue: undefined,\n\t\trollback: null,\n\t};\n\n\t// The runner wraps the user's thunk: call fn(), and if the result is a\n\t// thenable, set didSuspend + wire the resolve/reject handlers. This runs\n\t// inside runComputed (with activeTarget set for dep tracking) on both the\n\t// initial call and every recalc, so stale resolves are handled by the\n\t// generation guard without any changes to runComputed or checkComputed.\n\t//\n\t// `staleValue` is maintained by the settle handlers below — it always\n\t// holds the last RESOLVED value, cleared on rejection. It is NOT derived\n\t// here from `computed.value`: when changes overlap (a re-suspend while an\n\t// earlier fetch is still in flight), `computed.value` holds that earlier\n\t// run's pending promise, and handing it to readers would render\n\t// \"[object Promise]\" — a superseded generation's value leaking into the\n\t// UI. The settle handlers are generation-guarded, so `staleValue` is\n\t// generation-safe by construction: the read-side token matching the\n\t// resolve-side one (ASYNC.md → \"Generation guards\").\n\tcomputed.run = () => {\n\t\tconst value = fn();\n\t\tif (value !== null && value !== undefined && typeof (value as any).then === \"function\") {\n\t\t\tconst gen = ++computed.generation;\n\t\t\tcomputed.didSuspend = true;\n\t\t\t// Capture the quiet-on-refresh decision at suspend time\n\t\t\t// (ASYNC.md → \"Loud vs quiet\"). `recalc` is still true during a source-driven\n\t\t\t// re-run — `checkComputed` clears it only after `runComputed`\n\t\t\t// returns — so a suspend is quiet iff the computed has resolved\n\t\t\t// before AND this run wasn't triggered by a dependency change\n\t\t\t// (i.e. a silent `$refresh(fn, { silent: true })`).\n\t\t\t// First loads are loud (`hasResolved` is false); dep-change\n\t\t\t// refreshes and loud `$refresh` calls are loud (`recalc` is true).\n\t\t\tcomputed.suspendQuiet = computed.hasResolved && !computed.recalc;\n\t\t\t(value as Promise<T>).then(\n\t\t\t\t(v: T) => {\n\t\t\t\t\tif (computed.generation !== gen) return;\n\t\t\t\t\tcomputed.value = v;\n\t\t\t\t\tcomputed.didSuspend = false;\n\t\t\t\t\tcomputed.hasResolved = true;\n\t\t\t\t\tcomputed.lastErrored = false;\n\t\t\t\t\t// Retain the resolved value for the next refresh suspend\n\t\t\t\t\t// (stale-while-revalidate, ASYNC.md → \"Stale-while-revalidate\")\n\t\t\t\t\tcomputed.staleValue = v;\n\t\t\t\t\tbatchStart();\n\t\t\t\t\tpropagateFromSignal(computed);\n\t\t\t\t\tbatchEnd();\n\t\t\t\t},\n\t\t\t\t(e: any) => {\n\t\t\t\t\tif (computed.generation !== gen) return;\n\t\t\t\t\tcomputed.value = e;\n\t\t\t\t\tcomputed.didError = true;\n\t\t\t\t\tcomputed.didSuspend = false;\n\t\t\t\t\tcomputed.hasResolved = true;\n\t\t\t\t\tcomputed.lastErrored = true;\n\t\t\t\t\t// A retry-after-error re-suspend must not hand the previous\n\t\t\t\t\t// error (or a pre-error value) to readers as \"stale content\"\n\t\t\t\t\tcomputed.staleValue = undefined;\n\t\t\t\t\tbatchStart();\n\t\t\t\t\tpropagateFromSignal(computed);\n\t\t\t\t\tbatchEnd();\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t};\n\n\tcontext.registerComputed(computed);\n\n\trunComputed(computed);\n\n\t// Hydration seeding: the server embedded a resolved value for this read.\n\t// Bump the generation so the background fetch's settle is dropped as\n\t// stale, and surface the embedded value instead — the reader sees the\n\t// server's data immediately\n\tconst serverValues = context.serverValues;\n\tif (serverValues !== null && serverValues.index < serverValues.values.length) {\n\t\tcomputed.generation++;\n\t\tcomputed.didSuspend = false;\n\t\tcomputed.didError = false;\n\t\tcomputed.hasResolved = true;\n\t\tcomputed.lastErrored = false;\n\t\tcomputed.value = serverValues.values[serverValues.index++];\n\t\tcomputed.staleValue = computed.value;\n\t}\n\n\treturn computed.value;\n}\n","import $run from \"./$run\";\n\n/**\n * Establishes two-way reactive sync between matching keys on a state object\n * and a props object.\n *\n * For each key, `$bind` creates:\n * - **Forward sync** (`props → state`): when the parent pushes a new value via\n * `$props[key]`, it flows into `$state[key]`. Skips `undefined` values so\n * that defaults set in the initial `$watch(...)` are preserved when the\n * parent doesn't provide a value.\n * - **Backward sync** (`state → props`): when the component mutates\n * `$state[key]`, the new value is written back to `$props[key]`, which the\n * call site's `&key={...}` binding picks up and propagates to the parent.\n *\n * Same-value writes are no-ops (handled by the proxy layer), so two-way sync\n * stabilises without infinite loops.\n *\n * `$bind` syncs same-named keys, so the key must exist on the state object.\n * A state key named differently from the prop (e.g. `values` against a\n * `value` prop) would silently do nothing -- the binding reads and writes\n * keys that nothing else touches -- which is almost impossible to debug. The\n * key is therefore required to exist on the state object, and `$bind` throws\n * at setup otherwise.\n *\n * The prop does *not* need to exist on `props` yet: when the parent doesn't\n * pass an optional prop, the compiled props object has no key for it, and\n * the binding is simply inert (uncontrolled mode) until a value is pushed.\n *\n * @param state The component's reactive state (created via `$watch`).\n * @param props The component's `$props` proxy. When `undefined` (component\n * called with no props), `$bind` does nothing.\n * @param keys Keys to sync. Each key must exist on `state`.\n * @throws When a key does not exist on the state object.\n */\nexport default function $bind(\n\tstate: Record<PropertyKey, any>,\n\tprops: Record<PropertyKey, any> | undefined,\n\t...keys: (string | string[])[]\n): void {\n\tif (props === undefined) return;\n\tfor (let key of keys.flat()) {\n\t\tif (!(key in state)) {\n\t\t\tthrow new Error(\n\t\t\t\t`$bind: the key \"${key}\" does not exist on the state object. ` +\n\t\t\t\t\t`$bind syncs same-named keys, so the state object must declare it (e.g. in the initial $watch).`,\n\t\t\t);\n\t\t}\n\t\t// Forward: props → state (skip undefined so $watch defaults survive)\n\t\t$run(() => {\n\t\t\tconst v = props[key];\n\t\t\tif (v !== undefined) state[key] = v;\n\t\t}, `bind:forward:${key}`);\n\t\t// Backward: state → props (skip the initial write — there's nothing to\n\t\t// propagate yet, and echoing the initial state into props would make\n\t\t// the forward effect fire spuriously and clobber state changes that\n\t\t// happen during mount). The read still subscribes us to state[key].\n\t\tlet firstBackward = true;\n\t\t$run(() => {\n\t\t\tconst value = state[key];\n\t\t\tif (!firstBackward) props[key] = value;\n\t\t\tfirstBackward = false;\n\t\t}, `bind:backward:${key}`);\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport { COMPUTED_TYPE } from \"../types/constants\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Caches a computed value from signals accessed in a property getter.\n *\n * @param fn The function containing the signals to compute and cache.\n */\nexport default function $cache<T>(fn: () => T): T {\n\tif (context.registerComputed === null) {\n\t\tif (typeof window !== \"undefined\") {\n\t\t\tthrow new Error(\"$cache must be used in a getter\");\n\t\t}\n\t\t// Server render: getters are evaluated without reactive tracking (state\n\t\t// objects aren't proxied), so there is nothing to register with. Just\n\t\t// evaluate the function — this happens when a shared helper that uses\n\t\t// $cache (e.g. in @torpor/ui) is rendered on the server\n\t\treturn fn();\n\t}\n\n\tlet computed: Computed = {\n\t\ttype: COMPUTED_TYPE,\n\t\tisAsync: false,\n\t\tvalue: null,\n\t\trun: fn,\n\t\tfirstSource: null,\n\t\tfirstTarget: null,\n\t\trecalc: false,\n\t\trunning: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tgeneration: 0,\n\t\thasResolved: false,\n\t\tlastErrored: false,\n\t\tsuspendQuiet: false,\n\t\tstaleValue: undefined,\n\t\trollback: null,\n\t\t//name: dev.effectName(fn),\n\t};\n\n\tcontext.registerComputed(computed);\n\n\trunComputed(computed);\n\n\t// Guard: a Promise return from $cache would be cached as a raw value and\n\t// never suspend — the value would render as [object Promise]. This runtime\n\t// guard is the enforcement (torpor doesn't parse JS statically, so there's\n\t// no compiler check — ASYNC.md → \"The promise indicator\"); it fires on the getter's first read.\n\tif (\n\t\tcomputed.value !== null &&\n\t\tcomputed.value !== undefined &&\n\t\ttypeof (computed.value as any).then === \"function\"\n\t) {\n\t\tthrow new Error(\"$cache returned a Promise — use $async for async getters\");\n\t}\n\n\treturn computed.value;\n}\n","import context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\n\n/**\n * Runs `fn` once after the component is mounted to the DOM. May return a\n * cleanup function that runs on unmount / region clear.\n *\n * The callback is **not reactive**: it runs exactly once per mount, and\n * reactive values it reads are not tracked. To set up something that should\n * keep updating, wrap the reactive part in `$run`:\n *\n * ```ts\n * $onmount(() => {\n * \t$run(() => {\n * \t\tlabel.textContent = $state.count > 0 ? \"+\" : \"\";\n * \t});\n * });\n * ```\n *\n * The element-level equivalent is the `onmount` attribute:\n * `<input onmount={(el) => el.focus()} />`.\n *\n * @param fn The function to run, which may return a cleanup function\n */\nexport default function $onmount(fn: () => Cleanup | void): void {\n\tcontext.mountEffects.push({\n\t\tregion: context.activeRegion,\n\t\tfn,\n\t});\n}\n","import context from \"../render/context\";\n\n/**\n * Returns `true` if any value read inside `fn` is currently suspended in a\n * \"loud\" way — a `$async` getter whose promise hasn't resolved yet. A reactive\n * query for inline \"loading…\" indicators: the calling effect subscribes to the\n * same computeds, so `$pending` re-evaluates when they resolve.\n *\n * Uses a \"peek mode\" internally: reads during `fn` are tracked for\n * subscription but don't propagate taint or notify a `@await` boundary.\n * This lets `$pending` return a plain boolean without itself suspending.\n *\n * Quiet-on-refresh semantics (ASYNC.md → \"Loud vs quiet\"): a suspend is *quiet* — and\n * therefore `$pending` returns `false` for it — when the computed has resolved\n * before and the re-fetch was a *silent* `$refresh(fn, { silent: true })` (a\n * bare refresh with no tracked dependency change, used for background\n * revalidation). This matches Solid's stale-while-revalidate default: quietly\n * re-asking the same question shouldn't ping the user. First loads and\n * dependency-change refreshes are loud (`true`), as is the default (loud)\n * `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via\n * `suspendQuiet` (computed in `$async`'s run from `hasResolved` and `recalc`).\n *\n * @param fn A function that reads the reactive values to check.\n */\nexport default function $pending(fn: () => any): boolean {\n\tconst oldPeek = context.suspendPeek;\n\tcontext.suspendPeek = true;\n\tcontext.suspendPeekHit = false;\n\ttry {\n\t\tfn();\n\t\treturn context.suspendPeekHit;\n\t} finally {\n\t\tcontext.suspendPeek = oldPeek;\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport { propagateFromSignal } from \"./propagateSignal\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Options for `$refresh`.\n */\nexport interface RefreshOptions {\n\t/**\n\t * Re-fetch silently — stale-while-revalidate. The suspend is *quiet*\n\t * (`$pending` stays `false`) and subscribers aren't notified until the new\n\t * promise resolves. For background revalidation: polling, refetch-on-\n\t * focus. Defaults to `false` — a refresh is loud, so `$pending` reads\n\t * `true` and inline \"updating…\" indicators flip on at refresh start.\n\t */\n\tsilent?: boolean;\n}\n\n/**\n * Re-fetches the `$async` getters read inside `fn` without changing a\n * dependency. A companion to `$pending` (ASYNC.md): pull-to-refresh,\n * refresh buttons, refetch-on-focus, polling, retry-after-error.\n *\n * `fn` is run in a tracking context that collects every `$async` computed it\n * reads (`$cache` computeds are ignored). Each collected computed is then\n * re-run with `recalc` left true — a \"bare refresh\" — so the suspend is\n * *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and\n * subscribers are notified at suspend *start*, so an inline \"updating…\"\n * indicator appears immediately. Readers keep displaying the previous\n * resolved value (`Computed.staleValue`) until the new promise resolves and\n * propagates through the reactive graph; an `@await` boundary keeps its\n * content mounted instead of flashing fallback.\n *\n * Pass `{ silent: true }` to re-fetch quietly (stale-while-revalidate):\n * `$pending(fn)` stays `false` and nothing re-runs until the new promise\n * resolves. For background revalidation where feedback would be noise —\n * polling, refetch-on-focus:\n *\n * ```torp\n * // poll quietly every 30s\n * $run(() => {\n * \tconst id = setInterval(() => $refresh(() => $state.data, { silent: true }), 30_000);\n * \treturn () => clearInterval(id);\n * });\n * ```\n *\n * A refresh is loud regardless of `silent` when the computed has never\n * resolved — e.g. retrying after an error that left `didError` set on a first\n * load — or when the re-fetch is triggered by a dependency change, which\n * flows through the normal `recalc` path instead of here.\n *\n * If `fn` reads a getter the UI has never read, the collection read\n * initializes it — and that fetch IS the refresh: the computed is not re-run\n * (a second fetch would be a duplicate whose resolve the generation guard\n * drops). Getters already read (pending, resolved, or errored) are re-run as\n * usual.\n *\n * The returned value of `fn` is ignored; use `fn` to reference the getters.\n */\nexport default function $refresh(fn: () => any, options?: RefreshOptions): void {\n\tconst silent = options?.silent === true;\n\n\tconst oldRefreshSignals = context.refreshSignals;\n\tconst oldPeek = context.suspendPeek;\n\tconst oldInitialized = context.refreshInitialized;\n\tcontext.refreshSignals = [];\n\tcontext.suspendPeek = true;\n\tcontext.refreshInitialized = new Set();\n\tlet unique: Set<Computed>;\n\tlet initialized: Set<Computed>;\n\ttry {\n\t\tfn();\n\t\t// Dedupe — fn may read the same getter several times.\n\t\tunique = new Set<Computed>(context.refreshSignals ?? []);\n\t\tinitialized = context.refreshInitialized;\n\t} finally {\n\t\tcontext.refreshSignals = oldRefreshSignals;\n\t\tcontext.suspendPeek = oldPeek;\n\t\tcontext.refreshInitialized = oldInitialized;\n\t}\n\n\tfor (const computed of unique) {\n\t\tif (initialized.has(computed)) {\n\t\t\t// The collection read was this computed's first-ever read: it\n\t\t\t// initialized the getter and started the fetch the caller is\n\t\t\t// asking for. Re-running would start a duplicate fetch (its\n\t\t\t// resolve dropped by the generation guard), so the\n\t\t\t// initialization IS the refresh — skip the re-run and its\n\t\t\t// notifications. First loads are loud regardless of `silent`\n\t\t\t// (`suspendQuiet` is false while `hasResolved` is false), so\n\t\t\t// `$pending` still reads `true` for it.\n\t\t\tcontinue;\n\t\t}\n\t\t// Bare refresh: recalc must be true when `$async`'s run captures\n\t\t// suspendQuiet so the suspend reads as loud (suspendQuiet =\n\t\t// hasResolved && !recalc = false), and false for a silent refresh\n\t\t// (quiet). Restore it after the run.\n\t\tcomputed.recalc = !silent;\n\t\tdeactivateSources(computed);\n\t\t// Re-run with no active target so the refresh doesn't subscribe the\n\t\t// caller (e.g. the effect that triggered it) to the computed — an\n\t\t// imperative refresh must not make its caller re-run on resolve\n\t\t// (which could loop if the caller refreshes unconditionally). The\n\t\t// computed still subscribes to its own sources for future\n\t\t// dependency-change re-fetches.\n\t\tconst oldActiveTarget = context.activeTarget;\n\t\tcontext.activeTarget = null;\n\t\ttry {\n\t\t\trunComputed(computed);\n\t\t} finally {\n\t\t\tcontext.activeTarget = oldActiveTarget;\n\t\t}\n\t\tcomputed.recalc = false;\n\t\tclearSources(computed);\n\n\t\tif (!silent) {\n\t\t\t// A loud refresh notifies subscribers at suspend *start* so\n\t\t\t// `$pending` indicators (which subscribe to the computed) flip on\n\t\t\t// immediately and show the \"updating…\" UI while the fetch is in\n\t\t\t// flight. Readers re-read the retained staleValue, so content\n\t\t\t// doesn't flicker. A silent refresh stays quiet until resolve.\n\t\t\tbatchStart();\n\t\t\tpropagateFromSignal(computed);\n\t\t\tbatchEnd();\n\t\t}\n\t}\n}\n","import context from \"../render/context\";\nimport type StreamSource from \"../types/StreamSource\";\nimport $run from \"./$run\";\n\n/**\n * Subscribes to an external source of events — server-sent events,\n * WebSockets, DOM events, or any custom `StreamSource` — and calls\n * `handler` for each event it pushes. Events are typically written into\n * reactive state, which keeps templates, computeds and effects updating\n * through the normal reactivity model:\n *\n * ```torp\n * let $state = $watch({ messages: [] as string[] });\n *\n * $stream(fromServer(`/sse/${$props.id}`), (e) => {\n * \t$state.messages.push(e.data);\n * });\n * ```\n *\n * The subscription is managed by the framework:\n *\n * - It starts when the component is mounted to the DOM (so `&ref`-bound\n * elements are available), and is unsubscribed when the component\n * unmounts or its region is cleared.\n * - Reactive state read *inside* the source is tracked: when it changes,\n * the source is unsubscribed and re-subscribed with fresh values (e.g.\n * re-opening a connection when a user id changes). A pending debounced\n * call is dropped on re-subscribe.\n * - The source is never invoked during a server render, so browser-only\n * APIs are safe to use.\n *\n * Errors are values like any other: a source that can fail should push an\n * error-shaped value and own its own reconnection (e.g. `EventSource`\n * reconnects automatically).\n *\n * @param source The stream source to subscribe to\n * @param handler Called for each event the source pushes\n * @param options Timing options. `debounce` delays each handler call until\n * the source has been quiet for that many milliseconds, resetting on\n * every event (only the last event in a burst is handled).\n */\nexport default function $stream<T>(\n\tsource: StreamSource<T>,\n\thandler: (value: T) => void,\n\toptions?: { debounce?: number },\n): void {\n\tconst fn = () => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\t// Mount callbacks are once-only and untracked, so the source is set\n\t\t// up inside a `$run`: reactive state it reads is tracked, and when it\n\t\t// changes the source is unsubscribed and re-subscribed with fresh\n\t\t// values. The debounce timer lives outside the effect so re-runs\n\t\t// share it; the effect's cleanup drops any pending call.\n\t\t$run(() => {\n\t\t\tconst unsub = source((value) => {\n\t\t\t\tif (options?.debounce) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ttimer = setTimeout(() => handler(value), options.debounce);\n\t\t\t\t} else {\n\t\t\t\t\thandler(value);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tunsub?.();\n\t\t\t\tclearTimeout(timer);\n\t\t\t};\n\t\t});\n\t};\n\tcontext.mountEffects.push({\n\t\tregion: context.activeRegion,\n\t\tfn,\n\t});\n}\n"],"mappings":";;;AAGA,MAAM,iBAAgC,OAAO,IAAI,cAAc;AAE/D,MAAM,UAEJ,WA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AQ,GAS3B;EAMD,SAAS,SAAS,CAAC;EACnB,kBAAkB,QAAQ;EAO1B,MAAM,kBAAkB,QAAQ;EAChC,QAAQ,eAAe;EACvB,IAAI;GACH,YAAY,QAAQ;EACrB,UAAU;GACT,QAAQ,eAAe;EACxB;EACA,SAAS,SAAS;EAClB,aAAa,QAAQ;EAErB,IAAI,CAAC,QAAQ;GAMZ,WAAW;GACX,oBAAoB,QAAQ;GAC5B,SAAS;EACV;CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC1FA,SAAwB,QACvB,QACA,SACA,SACO;CACP,MAAM,WAAW;EAChB,IAAI;EAOJ,WAAW;GACV,MAAM,QAAQ,QAAQ,UAAU;IAC/B,IAAI,SAAS,UAAU;KACtB,aAAa,KAAK;KAClB,QAAQ,iBAAiB,QAAQ,KAAK,GAAG,QAAQ,QAAQ;IAC1D,OACC,QAAQ,KAAK;GAEf,CAAC;GAED,aAAa;IACZ,QAAQ;IACR,aAAa,KAAK;GACnB;EACD,CAAC;CACF;CACA,QAAQ,aAAa,KAAK;EACzB,QAAQ,QAAQ;EAChB;CACD,CAAC;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/render/context.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/watch/clearSources.ts","../src/watch/deactivateSources.ts","../src/watch/trackSignal.ts","../src/watch/runComputed.ts","../src/watch/checkComputed.ts","../src/watch/checkSources.ts","../src/watch/runCleanups.ts","../src/watch/checkEffect.ts","../src/watch/clearTargets.ts","../src/watch/routeEffectError.ts","../src/watch/triggerEffects.ts","../src/watch/batchEnd.ts","../src/watch/batchStart.ts","../src/watch/runEffect.ts","../src/watch/$run.ts","../src/watch/$peek.ts","../src/watch/flushMountEffects.ts","../src/render/animate.ts","../src/render/delegatedEvents.ts","../src/render/isFragmentNode.ts","../src/render/runMountSideEffects.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearRegion.ts","../src/render/clearLayoutSlot.ts","../src/render/newRegion.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/fillLayoutSlot.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/isServerComponent.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/render/newListItem.ts","../src/render/isCommentNode.ts","../src/render/isTextNode.ts","../src/render/nodeCheckHydrationBreak.ts","../src/render/nodeNext.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/walkHydrationRoot.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/widenAncestorsAtAnchor.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/checkListKeys.ts","../src/watch/deepWrap.ts","../src/watch/propagateSignal.ts","../src/watch/trackProxySignal.ts","../src/watch/proxyGet.ts","../src/watch/proxySet.ts","../src/watch/$watch.ts","../src/render/getSequence.ts","../src/render/moveRegion.ts","../src/render/runListItems.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/saveHydration.ts","../src/render/runTry.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$stream.ts"],"sourcesContent":["import type Context from \"../types/Context\";\nimport type Region from \"../types/Region\";\n\nconst CONTEXT_SYMBOL: unique symbol = Symbol.for(\"torp.Context\");\n\nconst context: Context =\n\t// @ts-ignore\n\t(globalThis[CONTEXT_SYMBOL] ??= {\n\t\tactiveTarget: null,\n\t\tpreviousEffect: null,\n\t\textent: 0,\n\t\tbatch: 0,\n\t\tbatchOperation: 0,\n\t\tregisterComputed: null,\n\n\t\teffectsToRun: [],\n\t\tfirstSignalToUpdate: null,\n\t\tlastSignalToUpdate: null,\n\n\t\t// These will definitely be set, in mount or render\n\t\tactiveRegion: null as unknown as Region,\n\t\tpreviousRegion: null as unknown as Region,\n\t\trootRegion: null as unknown as Region,\n\n\t\tawaitBoundary: null,\n\n\t\tsuspendPeek: false,\n\t\tsuspendPeekHit: false,\n\n\t\trefreshSignals: null,\n\t\trefreshInitialized: null,\n\n\t\tmountEffects: [],\n\t\tstashedEvents: [],\n\t\tstashedAnimations: [],\n\n\t\thydrationNode: null,\n\t\t//hn: null,\n\t\t//get hydrationNode() {\n\t\t//\treturn this.hn;\n\t\t//},\n\t\t//set hydrationNode(value) {\n\t\t//\tconsole.log(`set hydration ${printNode(value)}`);\n\t\t//\tthis.hn = value;\n\t\t//},\n\n\t\tserverValues: null,\n\t} satisfies Context);\n\nexport default context;\n","import type Animation from \"../types/Animation\";\nimport context from \"./context\";\n\nexport default function addAnimation(el: HTMLElement, entry?: Animation, exit?: Animation): void {\n\t// Stash the event in context so that it can be added when the fragment is\n\t// added to the DOM\n\t// NOTE: We don't need to do this for hydration, but it's simpler to do it\n\t// the same way in both processes\n\tcontext.stashedAnimations.push({\n\t\tregion: context.activeRegion,\n\t\tel,\n\t\tin: entry,\n\t\tout: exit,\n\t});\n}\n","import context from \"./context\";\n\nexport default function addEvent(\n\tel: Element,\n\ttype: string,\n\tlistener: ((this: Element, ev: any) => any) | undefined | null,\n): void {\n\t// Stash the event in context so that it can be added when the fragment is\n\t// added to the DOM\n\t// NOTE: We don't need to do this for hydration, but it's simpler to do it\n\t// the same way in both processes\n\tif (listener !== undefined && listener !== null) {\n\t\t// NOTE: `region` is intentionally omitted — it was stashed historically\n\t\t// but never read by `addFragment` (the consumer). Dropping it removes\n\t\t// one property write per `addEvent` call (2 per list item in the\n\t\t// js-framework-bench row template, ~2000 writes per 1k-row create).\n\t\tcontext.stashedEvents.push({ el, type, listener });\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * Clear unused source subscriptions after each Computed or Effect has been run.\n */\nexport default function clearSources(target: Computed | Effect): void {\n\tlet previousSub: Subscription | null = null;\n\tfor (\n\t\tlet clearSub: Subscription | null = target.firstSource;\n\t\tclearSub !== null;\n\t\tclearSub = clearSub.nextSource\n\t) {\n\t\tif (target.didError || !clearSub.active) {\n\t\t\t//console.log(\n\t\t\t//\t`clearing source sub ${clearSub.source.name} <-> ${clearSub.target.name} (${clearSub.name})`,\n\t\t\t//);\n\t\t\tif (previousSub === null) {\n\t\t\t\ttarget.firstSource = clearSub.nextSource;\n\t\t\t} else {\n\t\t\t\tpreviousSub.nextSource = clearSub.nextSource;\n\t\t\t}\n\n\t\t\t// Update the targets list too\n\t\t\tif (clearSub.previousTarget === null) {\n\t\t\t\tif (clearSub.source.firstTarget === clearSub) {\n\t\t\t\t\tclearSub.source.firstTarget = clearSub.nextTarget;\n\t\t\t\t}\n\t\t\t\t// TODO: else???\n\t\t\t} else {\n\t\t\t\tclearSub.previousTarget.nextTarget = clearSub.nextTarget;\n\t\t\t}\n\t\t} else {\n\t\t\tclearSub.recalc = false;\n\t\t\tpreviousSub = clearSub;\n\t\t}\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * Sets source subscriptions to inactive for a Computed or Effect.\n */\nexport default function deactivateSources(target: Computed | Effect): void {\n\tfor (\n\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\tsourceSub !== null;\n\t\tsourceSub = sourceSub.nextSource\n\t) {\n\t\tsourceSub.active = false;\n\t\t//console.log(\n\t\t//\t`deactivating ${sourceSub.source.name} <-> ${sourceSub.target.name} (${sourceSub.name})`,\n\t\t//);\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\n\n/**\n * If there's an active target, subscribe it to this signal, so that it will be\n * run when the signal changes.\n */\nexport default function trackSignal(signal: ProxySignal | Computed): void {\n\tconst target = context.activeTarget;\n\tif (target !== null) {\n\t\t// Walk the target's existing sources (typically a handful) to look for\n\t\t// an existing subscription we can re-use, instead of walking the\n\t\t// signal's target list. A popular signal (e.g. a parent's `selected`\n\t\t// flag fanned out to thousands of list-item effects) can have a very\n\t\t// long target list, which made subscription O(N) per call and O(N²)\n\t\t// total — the dominant cost in the js-framework-bench `runlots` op.\n\t\t// The target's source list is bounded by the number of distinct\n\t\t// signals this single effect depends on (almost always <10).\n\t\tfor (\n\t\t\tlet existingSub: Subscription | null = target.firstSource;\n\t\t\texistingSub !== null;\n\t\t\texistingSub = existingSub.nextSource\n\t\t) {\n\t\t\tif (existingSub.source === signal) {\n\t\t\t\t// Re-use the existing subscription\n\t\t\t\texistingSub.active = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// No existing subscription — create a new one. Prepend to both lists\n\t\t// to keep this O(1); the order of subscriptions within a signal's\n\t\t// target list has no semantic meaning (effect run order is decided by\n\t\t// dependency graph, not subscription order).\n\t\tconst oldFirstTarget = signal.firstTarget;\n\t\tconst sub: Subscription = {\n\t\t\tsource: signal,\n\t\t\ttarget: target,\n\t\t\tpreviousTarget: null,\n\t\t\tnextTarget: oldFirstTarget,\n\t\t\tnextSource: target.firstSource,\n\t\t\tactive: true,\n\t\t\trecalc: false,\n\t\t};\n\t\tif (oldFirstTarget !== null) {\n\t\t\toldFirstTarget.previousTarget = sub;\n\t\t}\n\t\tsignal.firstTarget = sub;\n\t\ttarget.firstSource = sub;\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport trackSignal from \"./trackSignal\";\n\nexport default function runComputed<T>(computed: Computed<T>): T {\n\t//console.log(`running computed '${computed.name}'`);\n\n\t// Store the active target\n\tconst oldActiveTarget = context.activeTarget;\n\n\tcomputed.running = true;\n\tcomputed.didError = false;\n\tcomputed.didSuspend = false;\n\n\ttry {\n\t\t// Set the active target, so that any properties accessed while running it\n\t\t// will trigger it in future\n\t\tcontext.activeTarget = computed;\n\n\t\t// Run the computed and gather its dependencies\n\t\tcomputed.value = computed.run();\n\t} catch (err) {\n\t\tcomputed.didError = true;\n\t\t// @ts-ignore\n\t\tcomputed.value = err;\n\t\tthrow err;\n\t} finally {\n\t\t// Set the active target back to what it was previously\n\t\tcontext.activeTarget = oldActiveTarget;\n\n\t\tcomputed.running = false;\n\t}\n\n\ttrackSignal(computed);\n\n\treturn computed.value;\n}\n","import type Computed from \"../types/Computed\";\nimport type Subscription from \"../types/Subscription\";\nimport checkSources from \"./checkSources\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Checks whether a Computed value should be re-run (which will be true if any\n * of its sources have changed) and re-runs it if necessary.\n */\nexport default function checkComputed(computed: Computed): boolean {\n\tlet rerun = checkSources(computed);\n\n\tlet changed = false;\n\n\tif (rerun) {\n\t\t// Set source subscriptions to inactive\n\t\tdeactivateSources(computed);\n\n\t\t// Run the computed, which will reset subscriptions\n\t\tconst oldValue = computed.value;\n\t\trunComputed(computed);\n\t\tchanged = computed.value !== oldValue;\n\n\t\t// Clear unused source subscriptions\n\t\tclearSources(computed);\n\t}\n\n\tcomputed.recalc = false;\n\n\t// If it hasn't changed, all of its target subscriptions remain active and\n\t// don't need to be recalculated\n\tif (!changed) {\n\t\tfor (\n\t\t\tlet targetSub: Subscription | null = computed.firstTarget;\n\t\t\ttargetSub !== null;\n\t\t\ttargetSub = targetSub.nextTarget\n\t\t) {\n\t\t\ttargetSub.active = true;\n\t\t\ttargetSub.recalc = false;\n\t\t}\n\t}\n\n\treturn changed;\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type Subscription from \"../types/Subscription\";\nimport { COMPUTED_TYPE, SIGNAL_TYPE } from \"../types/constants\";\nimport checkComputed from \"./checkComputed\";\n\n// RECURSIVE\n\n/**\n * Checks whether a Computed or Effect should be re-run (which will be true if\n * any of its sources have changed).\n */\nexport default function checkSources(target: Computed | Effect): boolean {\n\t// NOTE: We bail early if we know the target needs to be re-run; subsequent\n\t// computed values will be computed in the proxy getter\n\n\t// Check signals first as it's cheap, then computed values\n\tlet haveComputed = false;\n\n\tfor (\n\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\tsourceSub !== null;\n\t\tsourceSub = sourceSub.nextSource\n\t) {\n\t\t//console.log(`checking source sub '${sourceSub.source.name}' (${sourceSub.name})`);\n\t\tif (sourceSub.recalc) {\n\t\t\tif (sourceSub.source.type === SIGNAL_TYPE) {\n\t\t\t\treturn true;\n\t\t\t} /* else if (sourceSub.source.type === COMPUTED_TYPE) */ else {\n\t\t\t\tif (sourceSub.source.recalc) {\n\t\t\t\t\thaveComputed = true;\n\t\t\t\t} else {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (haveComputed) {\n\t\tfor (\n\t\t\tlet sourceSub: Subscription | null = target.firstSource;\n\t\t\tsourceSub !== null;\n\t\t\tsourceSub = sourceSub.nextSource\n\t\t) {\n\t\t\t//console.log(`checking source sub '${sourceSub.source.name}' (${sourceSub.name})`);\n\t\t\tif (sourceSub.recalc && sourceSub.source.type === COMPUTED_TYPE && sourceSub.source.recalc) {\n\t\t\t\tconst oldActiveTarget = context.activeTarget;\n\t\t\t\tcontext.activeTarget = target;\n\n\t\t\t\tconst recalc = checkComputed(sourceSub.source);\n\n\t\t\t\tcontext.activeTarget = oldActiveTarget;\n\n\t\t\t\tif (recalc) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\n}\n","import context from \"../render/context\";\nimport type Effect from \"../types/Effect\";\nimport clearSources from \"./clearSources\";\n\n/**\n * Runs cleanup functions for the effect and its children.\n */\nexport default function runCleanups(effect: Effect): void {\n\tlet effectToClean: Effect | null = effect;\n\tfor (let i = 0; i < effect.extent; i++) {\n\t\tif (effectToClean === null) break;\n\t\tif (typeof effectToClean.cleanup === \"function\") {\n\t\t\t//console.log(`cleaning effect '${effectToClean.name}'`);\n\t\t\tconst oldActiveTarget = context.activeTarget;\n\t\t\tcontext.activeTarget = null;\n\n\t\t\ttry {\n\t\t\t\teffectToClean.cleanup();\n\t\t\t} catch (err) {\n\t\t\t\teffectToClean.didError = true;\n\t\t\t\tclearSources(effectToClean);\n\t\t\t\tthrow err;\n\t\t\t} finally {\n\t\t\t\teffectToClean.cleanup = undefined;\n\t\t\t\tcontext.activeTarget = oldActiveTarget;\n\t\t\t}\n\t\t}\n\n\t\tconst nextEffect: Effect = effectToClean.nextEffect!;\n\n\t\teffectToClean = nextEffect;\n\t}\n}\n","import type Effect from \"../types/Effect\";\nimport checkSources from \"./checkSources\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runCleanups from \"./runCleanups\";\nimport runEffect from \"./runEffect\";\n\n/**\n * Checks whether an Effect should be re-run (which will be true if any\n * of its sources have changed) and re-runs it if necessary.\n */\nexport default function checkEffect(effect: Effect): void {\n\tlet rerun = checkSources(effect);\n\n\tif (rerun) {\n\t\t//console.log(`running effect '${String(effect.run)}'`);\n\n\t\t// Run cleanup functions for the effect and its children\n\t\trunCleanups(effect);\n\n\t\t// Set source subscriptions to inactive\n\t\tdeactivateSources(effect);\n\n\t\t// Run the effect, which will reset subscriptions\n\t\trunEffect(effect);\n\n\t\t// Clear unused source subscriptions\n\t\tclearSources(effect);\n\t}\n}\n","import type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\n\n/**\n * Clear unused target subscriptions after all Effects have been run.\n *\n * NOTE: This used to walk `source.firstTarget` and unlink inactive\n * subscriptions. That walk is now skipped: inactive subs are left in the\n * target list so that `trackSignal` (which looks up existing subscriptions\n * via the target's source list) can safely reactivate them on the next run.\n * Actual cleanup of unused subscriptions happens in `clearSources`, which\n * runs after each Effect / Computed re-run and removes from both lists.\n *\n * Why this matters: with the previous design, `trackSignal` walked the\n * signal's target list to find an existing subscription, which was O(N) per\n * call for popular signals. The new design walks the target's source list\n * (bounded by the effect's dependency count, typically <10), but only works\n * if a subscription found in the source list is also still linked into the\n * signal's target list. Removing it here broke that invariant for computed\n * values that hadn't yet re-run.\n */\nexport default function clearTargets(_source: ProxySignal | Computed): void {\n\t// Intentional no-op — see comment above.\n}\n","import type Effect from \"../types/Effect\";\nimport type ErrorBoundary from \"../types/ErrorBoundary\";\nimport type Region from \"../types/Region\";\nimport type Computed from \"../types/Computed\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport runCleanups from \"./runCleanups\";\nimport runEffect from \"./runEffect\";\n\n/**\n * Routes an error thrown by an effect re-run to the nearest enclosing error\n * boundary (`@try`/`@catch` or top-level `@error`), and forces the boundary's\n * control effect to re-run so it renders its catch branch. Returns true if a\n * boundary handled the error.\n *\n * The boundary is found by walking the flattened region chain from the\n * effect's owning region (`Effect.region`, set by `$run`) through its\n * ancestors (regions with strictly decreasing depth on the `previousRegion`\n * chain — the same shape `clearRegion` walks).\n *\n * For recovery, the boundary holds the failing effect's source signals\n * (captured by `runEffect` before it cleared them, `Effect.errorSources`)\n * together with the boundary effect's own sources: reads wrapped in nested\n * `$run` effects (text/attribute interpolation) are tracked by those\n * effects, not the boundary, so without holding them the catch branch would\n * never re-attempt the try branch. `runTry` re-subscribes the boundary\n * effect to the held signals on every run that shows the catch branch.\n *\n * Called from `triggerEffects`' per-effect catch. If forcing the boundary\n * re-run itself throws (e.g. the catch branch content errors), the error\n * propagates to the caller, which reports it as unhandled — matching the\n * compiled form, where a throwing catch branch escapes the boundary.\n */\nexport default function routeEffectError(effect: Effect, error: any): boolean {\n\tlet region: Region | null = effect.region ?? null;\n\twhile (region !== null) {\n\t\tconst boundary: ErrorBoundary | undefined = region.errorBoundary;\n\t\tif (boundary !== undefined && boundary.effect !== null) {\n\t\t\tconst boundaryEffect = boundary.effect;\n\n\t\t\t// Hold the boundary effect's own sources plus the failing\n\t\t\t// effect's sources, so any of them changing re-attempts the try\n\t\t\t// branch (recovery)\n\t\t\tconst held: (ProxySignal | Computed)[] = [];\n\t\t\tfor (\n\t\t\t\tlet sub: Subscription | null = boundaryEffect.firstSource;\n\t\t\t\tsub !== null;\n\t\t\t\tsub = sub.nextSource\n\t\t\t) {\n\t\t\t\theld.push(sub.source);\n\t\t\t}\n\t\t\tfor (const signal of effect.errorSources ?? []) {\n\t\t\t\tif (!held.includes(signal)) {\n\t\t\t\t\theld.push(signal);\n\t\t\t\t}\n\t\t\t}\n\t\t\tboundary.error = error;\n\t\t\tboundary.hasError = true;\n\t\t\tboundary.heldSignals = held;\n\n\t\t\t// Force the boundary effect to re-run (unconditionally, like\n\t\t\t// `checkEffect` does when a source has changed). runTry renders\n\t\t\t// the catch branch with the routed error and holds the signals\n\t\t\trunCleanups(boundaryEffect);\n\t\t\tdeactivateSources(boundaryEffect);\n\t\t\trunEffect(boundaryEffect);\n\t\t\tclearSources(boundaryEffect);\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Walk to the nearest ancestor: the first previous region with\n\t\t// strictly smaller depth (siblings and children of siblings have\n\t\t// greater-or-equal depth and do not enclose this region)\n\t\tconst depth = region.depth;\n\t\tlet previous: Region | null = region.previousRegion;\n\t\twhile (previous !== null && previous.depth >= depth) {\n\t\t\tprevious = previous.previousRegion;\n\t\t}\n\t\tregion = previous;\n\t}\n\n\treturn false;\n}\n","import context from \"../render/context\";\nimport type Effect from \"../types/Effect\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport checkEffect from \"./checkEffect\";\nimport clearTargets from \"./clearTargets\";\nimport routeEffectError from \"./routeEffectError\";\nimport trackSignal from \"./trackSignal\";\n\n/**\n * Re-subscribes a failed effect to the suspended computeds its run had read,\n * after `runEffect`'s catch detached them via `clearSources`. Called when no\n * error boundary handled the crash: the error still surfaces (see below),\n * but the promise's resolve re-runs the effect, so a crash caused by a\n * pending read's `undefined` heals instead of leaving a dead effect.\n */\nfunction resubscribeSuspendSources(effect: Effect): void {\n\tconst sources = effect.suspendSources;\n\tif (!sources || sources.size === 0) return;\n\tconst oldActive = context.activeTarget;\n\tcontext.activeTarget = effect;\n\tfor (const signal of sources) {\n\t\ttrackSignal(signal);\n\t}\n\tcontext.activeTarget = oldActive;\n}\n\n/**\n * Runs the effects that have been collected during the batch.\n */\nexport default function triggerEffects(): void {\n\t//console.log(`triggering effects for '${String(key)}' on`, proxy);\n\t//console.log(\"===\");\n\t//console.log(`triggering effects for '${String(key)}'`);\n\n\t// The first error that was NOT handled by an error boundary (if any).\n\t// Errors routed to a boundary are consumed by it; unhandled ones are\n\t// rethrown after the batch, as before boundaries existed.\n\tlet unhandledError: { error: any } | null = null;\n\n\t// Run the queued effects. Appends made while running (by signal writes\n\t// within an effect) land in the same array and are picked up by the\n\t// index-based loop. An effect that already ran in this flush can be\n\t// re-queued the same way — `queued` is reset as each effect is\n\t// processed, so a later write re-runs it with fresh values.\n\tconst queue = context.effectsToRun;\n\tfor (let i = 0; i < queue.length; i++) {\n\t\tconst effect = queue[i];\n\t\tcontext.batchOperation++;\n\n\t\t// Mark as not-queued BEFORE running, so that a signal write made\n\t\t// during this run — or during a later effect's run in the same\n\t\t// flush — can re-queue it if a source changed again\n\t\teffect.queued = false;\n\n\t\ttry {\n\t\t\tcheckEffect(effect);\n\t\t} catch (err) {\n\t\t\t// A re-run threw. Route it to the nearest enclosing error\n\t\t\t// boundary (@try/@catch or top-level @error), which re-renders\n\t\t\t// its catch branch; if there is none (or routing itself throws,\n\t\t\t// e.g. the catch content errors), record it to rethrow below\n\t\t\tlet handled = false;\n\t\t\ttry {\n\t\t\t\thandled = routeEffectError(effect, err);\n\t\t\t} catch (routingError) {\n\t\t\t\tif (unhandledError === null) {\n\t\t\t\t\tunhandledError = { error: routingError };\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!handled) {\n\t\t\t\t// No boundary took the error. If the failed run had read a\n\t\t\t\t// suspended $async getter, the crash may be caused by the\n\t\t\t\t// pending `undefined` it returned — keep the effect\n\t\t\t\t// subscribed so resolve re-runs it (self-heal) while the\n\t\t\t\t// error still surfaces below\n\t\t\t\tresubscribeSuspendSources(effect);\n\t\t\t\tif (unhandledError === null) {\n\t\t\t\t\tunhandledError = { error: err };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Clear the queue and reset the queued flag defensively (every processed\n\t// effect already reset its own, but an error may have skipped a run)\n\tfor (let effect of queue) {\n\t\teffect.queued = false;\n\t}\n\tcontext.effectsToRun = [];\n\n\t// Clear unused target subscriptions for the signals that were updated\n\t// during the batch\n\tlet signal: ProxySignal | null = context.firstSignalToUpdate;\n\tcontext.firstSignalToUpdate = null;\n\tcontext.lastSignalToUpdate = null;\n\twhile (signal !== null) {\n\t\tclearTargets(signal);\n\n\t\tconst nextSignal = signal.nextSignalToUpdate;\n\t\tsignal.nextSignalToUpdate = null;\n\t\tsignal = nextSignal;\n\t}\n\n\tif (unhandledError !== null) {\n\t\tthrow unhandledError.error;\n\t}\n}\n","import context from \"../render/context\";\nimport triggerEffects from \"./triggerEffects\";\n\nexport default function batchEnd(): void {\n\tif (context.batch > 1) {\n\t\tcontext.batch--;\n\t\treturn;\n\t}\n\n\ttry {\n\t\ttriggerEffects();\n\t} finally {\n\t\tcontext.batch = 0;\n\t\tcontext.batchOperation = 0;\n\t\tcontext.previousEffect = null;\n\t}\n}\n","import context from \"../render/context\";\n\nexport default function batchStart(): void {\n\tcontext.batch++;\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport clearSources from \"./clearSources\";\n\nexport default function runEffect(effect: Effect): void {\n\t//console.log(`running effect '${effect.name}'`);\n\n\t// DEV:\n\tdevContext.effectRun(effect);\n\n\t// Store the active target\n\tconst oldActiveTarget = context.activeTarget;\n\tconst oldExtent = context.extent;\n\n\teffect.didError = false;\n\teffect.errorSources = null;\n\t// Reset the per-run suspend state, so `didSuspend` reflects the run that\n\t// is about to happen and `suspendSources` doesn't re-subscribe reads\n\t// from a previous run (see triggerEffects)\n\teffect.didSuspend = false;\n\teffect.suspendSources = null;\n\n\tbatchStart();\n\n\ttry {\n\t\t// Set the next effect for navigating through\n\t\tif (context.previousEffect !== null) {\n\t\t\tcontext.previousEffect.nextEffect = effect;\n\t\t}\n\n\t\t// Set the active effect, so that any properties accessed while running it\n\t\t// will trigger it in future\n\t\tcontext.activeTarget = effect;\n\t\tcontext.previousEffect = effect;\n\t\tcontext.extent = 1;\n\n\t\t// Run the effect to register its subscriptions and get its (optional)\n\t\t// cleanup function\n\t\teffect.cleanup = effect.run();\n\n\t\teffect.extent = context.extent;\n\t} catch (err) {\n\t\teffect.didError = true;\n\t\t// Capture the source signals before clearing them, so an error\n\t\t// boundary can hold them for recovery (see routeEffectError) — the\n\t\t// effect's own subscriptions are about to be detached, and without\n\t\t// them the boundary would never re-attempt its try branch\n\t\tlet sources: (ProxySignal | Computed)[] | null = null;\n\t\tfor (let sub = effect.firstSource; sub !== null; sub = sub.nextSource) {\n\t\t\t(sources ??= []).push(sub.source);\n\t\t}\n\t\teffect.errorSources = sources;\n\t\tclearSources(effect);\n\t\tthrow err;\n\t} finally {\n\t\t// Set the active target back to what it was previously\n\t\tcontext.activeTarget = oldActiveTarget;\n\t\tcontext.extent += oldExtent - 1;\n\n\t\tbatchEnd();\n\t}\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\nimport type Effect from \"../types/Effect\";\nimport { EFFECT_TYPE } from \"../types/constants\";\nimport runEffect from \"./runEffect\";\n\n// TODO: Take a pipeline of operators e.g. debounce\n\n/**\n * Runs and re-runs a function that depends on a watched object\n *\n * @param fn The function to run, which may return a cleanup function.\n * @param options Internal fields to set on the constructed Effect (e.g.\n * `isMountEffect`, `forVarDeps`). Not part of the public API.\n */\nexport default function $run(\n\tfn: () => Cleanup | void,\n\tname?: string,\n\toptions?: Pick<Effect, \"isMountEffect\" | \"forVarMask\">,\n): Effect {\n\tlet effect: Effect = {\n\t\ttype: EFFECT_TYPE,\n\t\trun: fn,\n\t\tcleanup: undefined,\n\t\tfirstSource: null,\n\t\tnextEffect: null,\n\t\textent: 0,\n\t\tqueued: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tregion: null,\n\t\terrorSources: null,\n\t\tname,\n\t\tisMountEffect: options?.isMountEffect,\n\t\tforVarMask: options?.forVarMask,\n\t};\n\n\t// Track the effect on the current active region, so it can be\n\t// cleaned up when the region is cleared\n\tconst region = context.activeRegion;\n\tif (region !== null) {\n\t\tregion.effects.push(effect);\n\t\teffect.region = region;\n\t}\n\n\t// DEV:\n\tdevContext.onRun(effect);\n\n\trunEffect(effect);\n\n\treturn effect;\n}\n","import context from \"../render/context\";\n\n/**\n * Runs a function without tracking the reactive values it reads: `$watch`'d\n * state accessed inside `fn` does not become a dependency of the currently\n * running effect or computed. Useful for reading state inside an effect\n * without re-running it when that state changes.\n *\n * @param fn The function to run untracked.\n */\nexport default function $peek<T>(fn: () => T): T {\n\tconst oldActiveTarget = context.activeTarget;\n\tcontext.activeTarget = null;\n\n\tconst result = fn();\n\n\tcontext.activeTarget = oldActiveTarget;\n\n\treturn result;\n}\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\nimport { EFFECT_TYPE } from \"../types/constants\";\nimport $peek from \"./$peek\";\nimport $run from \"./$run\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\n\n/**\n * Runs the collected `$onmount`/`onmount` callbacks — once, after the\n * component's markup has been added to the DOM (or, when hydrating, after\n * hydration is complete). Multiple callbacks run in the order they were\n * added.\n *\n * Each callback becomes an effect with `isMountEffect` set, so the keyed-list\n * reconciler's force-rerun path (`rerunRegionEffects`) skips it. Its body\n * also runs untracked: mount callbacks are once-only, so reactive reads\n * inside them do not subscribe. In dev builds a tracked pass warns when a\n * callback reads reactive state, since that is almost always a mistake — the\n * reactive part should be wrapped in `$run`.\n */\nexport default function flushMountEffects(): void {\n\tif (context.mountEffects.length === 0) return;\n\tconst activeRegion = context.activeRegion;\n\tfor (let effect of context.mountEffects) {\n\t\tcontext.activeRegion = effect.region;\n\t\t$run(() => runMountCallback(effect.fn), undefined, { isMountEffect: true });\n\t}\n\tcontext.activeRegion = activeRegion;\n\tcontext.mountEffects.length = 0;\n}\n\nfunction runMountCallback(fn: () => Cleanup | void): Cleanup | void {\n\tif (!devContext.enabled) {\n\t\t// Mount callbacks run once — reads inside must not create subscriptions\n\t\treturn $peek(fn);\n\t}\n\n\t// DEV: run tracked so stray reactive reads can be detected, then detach\n\t// the subscriptions so the effect still never re-runs\n\tconst result = fn();\n\n\tconst effect = context.activeTarget;\n\tif (effect !== null && effect.type === EFFECT_TYPE && effect.firstSource !== null) {\n\t\tconsole.warn(\n\t\t\t\"[torpor] A $onmount/onmount callback read reactive state, but mount callbacks \" +\n\t\t\t\t\"run only once and will not re-run. Wrap the reactive part in $run(), \" +\n\t\t\t\t\"e.g. $onmount(() => { $run(() => ...); });\",\n\t\t);\n\t\tdeactivateSources(effect);\n\t\tclearSources(effect);\n\t}\n\n\treturn result;\n}\n","import context from \"./context\";\n\n/**\n * Adds an animation for an element\n * @param el The element to animate\n * @param enter Whether the animation is being run on enter\n * @param keyframes The Web Animation API keyframes\n * @param options The Web Animmation API options\n */\nexport default async function animate(\n\tel: HTMLElement,\n\tenter: boolean,\n\tkeyframes: Keyframe[] | PropertyIndexedKeyframes | null,\n\toptions?: number | KeyframeAnimationOptions,\n): Promise<void> {\n\t// This is quite simplistic\n\t// We might need to\n\t// - store the animation\n\t// - reverse it if it's running and the region appears/disappears\n\t// - transfer the animation to the new element\n\tlet animationOptions = Object.assign(\n\t\t{\n\t\t\tdirection: enter ? \"normal\" : \"reverse\",\n\t\t\t// TODO: Should probably have a global setting for these somewhere\n\t\t\t// And respect browser reduce motion settings\n\t\t\tduration: 300,\n\t\t\teasing: \"ease-in-out\",\n\t\t\tfill: \"forwards\",\n\t\t},\n\t\toptions,\n\t);\n\n\tconst animation = el.animate(keyframes, animationOptions);\n\n\t// HACK: I'm not entirely sure why we need to sent the animation's timeline,\n\t// but without it, animations never start\n\t// HACK: We also need to make sure the element has been added to the DOM\n\t// with a timeout\n\tsetTimeout(() => {\n\t\tanimation.timeline = el.ownerDocument.timeline;\n\t}, 1);\n\n\t// Add the animation to the active region, so that the region won't be cleared\n\t// until the animation is completed\n\tconst activeRegion = context.activeRegion;\n\t// TODO: An option for whether to await or cancel events on region remove\n\t// e.g. if you are doing a client side navigation, you don't want to run animations\n\tactiveRegion.animations ??= new Set();\n\tactiveRegion.animations.add(animation);\n\n\tawait animation.finished;\n}\n","/**\n * Event delegation.\n *\n * For event types in `DELEGATED_EVENT_TYPES` (all natively bubbling), we\n * register a single listener on `document` per type and dispatch by walking\n * up from `event.target` to find the closest ancestor with a stashed handler.\n * This replaces per-element `addEventListener` for delegated types.\n *\n * Why: in the js-framework-bench row template, every `<tr>` clones two `<a>`\n * elements each with a `click` handler. With per-element `addEventListener`,\n * `runlots` (10k rows) issues 20000 `addEventListener` calls and the browser\n * allocates 20000 `Listener` objects. With delegation it's 2 calls total\n * (one per delegated type, registered lazily on first use) and zero\n * per-element `Listener` allocations — the handler is stored as a property\n * on the element.\n *\n * Model: last-write-wins per element per type (same as Solid's\n * `delegateEvents`). Repeated `t_event(el, \"click\", h)` calls with the same\n * element reassign the property; calling with `null`/`undefined` clears it.\n * Torpor's compiler emits `t_event(el, type, h)` exactly once per element\n * lifetime (outside any tracked effect), so this is the natural shape.\n *\n * Non-bubbling events (`focus`, `blur`, `scroll`, `load`, `error`, `abort`,\n * `unload`, `resize`, etc.) bypass delegation and use direct\n * `addEventListener` on the element, preserving native semantics.\n */\n\nconst DELEGATED_EVENT_TYPES: ReadonlySet<string> = new Set([\n\t\"auxclick\",\n\t\"beforeinput\",\n\t\"change\",\n\t\"click\",\n\t\"compositionend\",\n\t\"compositionstart\",\n\t\"compositionupdate\",\n\t\"contextmenu\",\n\t\"dblclick\",\n\t\"drag\",\n\t\"dragend\",\n\t\"dragenter\",\n\t\"dragleave\",\n\t\"dragover\",\n\t\"dragstart\",\n\t\"drop\",\n\t\"focusin\",\n\t\"focusout\",\n\t\"input\",\n\t\"keydown\",\n\t\"keypress\",\n\t\"keyup\",\n\t\"mousedown\",\n\t\"mousemove\",\n\t\"mouseout\",\n\t\"mouseover\",\n\t\"mouseup\",\n\t\"pointerdown\",\n\t\"pointermove\",\n\t\"pointerout\",\n\t\"pointerover\",\n\t\"pointerup\",\n\t\"reset\",\n\t\"submit\",\n\t\"touchend\",\n\t\"touchmove\",\n\t\"touchstart\",\n\t\"wheel\",\n]);\n\nexport function isDelegatedEventType(type: string): boolean {\n\treturn DELEGATED_EVENT_TYPES.has(type);\n}\n\n// Property name on each element holding the handler for a given type.\n// Matches Solid's `$$`-prefixed convention. Single string property per type,\n// so there's no per-element Map allocation — just a named slot on the element.\nconst DELEGATE_PREFIX = \"torp.$$\";\n\n// Marker on `document` tracking which types already have a listener\n// registered. Storing on `document` (rather than a module-scoped Set) means\n// the registration state is correctly scoped to the current document —\n// important for tests that swap the global document (rare, but possible).\nconst DELEGATE_REGISTERED = Symbol.for(\"torp.delegated.registered\");\n\nfunction delegatedHandler(event: Event): void {\n\tlet node: Node | null = event.target as Node | null;\n\tconst stopAt: Node | null = event.currentTarget as Node | null;\n\tconst key = DELEGATE_PREFIX + event.type;\n\t// Walk from the deepest target up to (but not including) the listener\n\t// node (document). First ancestor with a stashed handler wins.\n\twhile (node != null && node !== stopAt) {\n\t\tconst handler = (node as any)[key];\n\t\tif (handler !== undefined) {\n\t\t\t// Override `currentTarget` so the user's handler sees the element\n\t\t\t// the handler was attached to, not `document`. `currentTarget`\n\t\t\t// is otherwise read-only. Configurable so the override can be\n\t\t\t// removed below.\n\t\t\tObject.defineProperty(event, \"currentTarget\", {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue: node,\n\t\t\t\twritable: false,\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t(handler as (this: Node, ev: Event) => any).call(node, event);\n\t\t\t} finally {\n\t\t\t\t// Remove the override so the prototype getter takes over\n\t\t\t\t// again (returns `null` once dispatch completes).\n\t\t\t\tdelete (event as any).currentTarget;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tnode = node.parentNode;\n\t}\n}\n\nfunction ensureDelegatedListener(type: string): void {\n\tif (typeof document === \"undefined\") return;\n\tlet registered = (document as any)[DELEGATE_REGISTERED] as Set<string> | undefined;\n\tif (!registered) {\n\t\tregistered = new Set();\n\t\t(document as any)[DELEGATE_REGISTERED] = registered;\n\t}\n\tif (registered.has(type)) return;\n\tregistered.add(type);\n\t// Bubble phase (default). All events in DELEGATED_EVENT_TYPES bubble, so\n\t// the listener at `document` fires after the event has traversed the\n\t// target and any intermediary elements — matching the natural event flow\n\t// the user expects from `addEventListener` on the element itself.\n\tdocument.addEventListener(type, delegatedHandler);\n}\n\n/**\n * Attach a delegated event handler to an element.\n *\n * Stores the handler as a property on the element and ensures a single\n * document-level listener exists for the type. Idempotent for the\n * document-level listener: the first call for a given type registers it,\n * subsequent calls are a Set-has check.\n *\n * Passing `null` or `undefined` as the listener clears any previously-set\n * handler for that type on the element (mirroring `addEvent`'s existing\n * null-skipping semantics, extended to support explicit removal).\n */\nexport function attachDelegatedEvent(\n\tel: Element,\n\ttype: string,\n\tlistener: ((this: Element, ev: any) => any) | undefined | null,\n): void {\n\tconst key = DELEGATE_PREFIX + type;\n\tif (listener === undefined || listener === null) {\n\t\t(el as any)[key] = undefined;\n\t\treturn;\n\t}\n\tensureDelegatedListener(type);\n\t(el as any)[key] = listener;\n}\n\n// Property on an element recording its direct (non-delegated) listeners, so\n// a dynamic-element tag swap (`t_dynamic`) can re-attach them. Direct\n// listeners are the rare path (focus, blur, scroll, …), so the extra\n// per-element array is acceptable next to the delegated-handler slots.\nconst DIRECT_LISTENERS = \"torp.$directListeners\";\n\n/**\n * Records a direct (non-delegated) listener on the element at attach time,\n * so `copyEventListeners` can re-attach it after a dynamic-element tag\n * swap. `addEventListener` listeners can't be discovered after the fact.\n */\nexport function recordDirectListener(\n\tel: Element,\n\ttype: string,\n\tlistener: (this: Element, ev: any) => any,\n): void {\n\tlet list = (el as any)[DIRECT_LISTENERS] as\n\t\t| { type: string; listener: (this: Element, ev: any) => any }[]\n\t\t| undefined;\n\tif (!list) {\n\t\tlist = [];\n\t\t(el as any)[DIRECT_LISTENERS] = list;\n\t}\n\tlist.push({ type, listener });\n}\n\n/**\n * Copies the event listeners attached to one element onto another — used by\n * `t_dynamic` so a dynamic element keeps its listeners when its tag changes.\n * Delegated handlers are `torp.$$<type>` properties, copied per known\n * delegated type (swaps are rare, so the fixed set of checks is fine);\n * direct listeners are re-registered from the list `recordDirectListener`\n * built at attach time.\n */\nexport function copyEventListeners(from: Element, to: Element): void {\n\tfor (const type of DELEGATED_EVENT_TYPES) {\n\t\tconst key = DELEGATE_PREFIX + type;\n\t\tconst handler = (from as any)[key];\n\t\tif (handler !== undefined) {\n\t\t\t(to as any)[key] = handler;\n\t\t}\n\t}\n\tconst direct = (from as any)[DIRECT_LISTENERS] as\n\t\t| { type: string; listener: (this: Element, ev: any) => any }[]\n\t\t| undefined;\n\tif (direct) {\n\t\t(to as any)[DIRECT_LISTENERS] = direct;\n\t\tfor (const { type, listener } of direct) {\n\t\t\tto.addEventListener(type, listener);\n\t\t}\n\t}\n}\n","export default function isFragmentNode(node: Node): node is DocumentFragment {\n\treturn node.nodeType === 11;\n}\n","import type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport flushMountEffects from \"../watch/flushMountEffects\";\nimport animate from \"./animate\";\nimport context from \"./context\";\nimport {\n\tattachDelegatedEvent,\n\tisDelegatedEventType,\n\trecordDirectListener,\n} from \"./delegatedEvents\";\nimport isFragmentNode from \"./isFragmentNode\";\n\n/**\n * Runs the mount-time side effects that both `addFragment` and `addElement`\n * share: `$onmount` effects (only when not hydrating), stashed event\n * listeners, and stashed animations. No-op when `parent` is itself a\n * `DocumentFragment` (we're being inserted into a detached tree, so\n * `$onmount` and event hookup would be premature — they'll run when the\n * outer fragment attaches).\n *\n * Extracted so the `DocumentFragment` path (`addFragment`) and the\n * single-element path (`addElement`) don't duplicate this logic.\n */\nexport default function runMountSideEffects(\n\tparent: ParentNode,\n\tactiveRegion: Region,\n\thydrationNode: Node | null,\n): void {\n\tif (isFragmentNode(parent)) return;\n\n\t// Only run $onmount effects if not hydrating (if hydrating, they will get\n\t// run at the end when everything is hooked up)\n\tif (hydrationNode === null) {\n\t\tflushMountEffects();\n\t}\n\n\t// Attach event listeners. For bubbling event types (the majority —\n\t// `click`, `input`, `change`, `keydown`, …) we delegate: a single\n\t// listener per type lives on `document`, and each element's handler is\n\t// stored as a property. This avoids N `addEventListener` calls per N-row\n\t// list (js-framework-bench `runlots` goes from 20000 calls to 2) and the\n\t// matching browser-side `Listener` allocations. Non-bubbling types\n\t// (`focus`, `blur`, `scroll`, …) fall back to direct `addEventListener`\n\t// on the element. Listeners are not tied to region lifecycle — when an\n\t// element is removed from the DOM, its handler property is GC'd with it.\n\tif (context.stashedEvents.length > 0) {\n\t\tfor (let event of context.stashedEvents) {\n\t\t\tif (isDelegatedEventType(event.type)) {\n\t\t\t\tattachDelegatedEvent(event.el, event.type, event.listener);\n\t\t\t} else {\n\t\t\t\tevent.el.addEventListener(event.type, event.listener);\n\t\t\t\t// Record it on the element, so a dynamic-element tag swap\n\t\t\t\t// (t_dynamic) can re-attach the listener on the new element\n\t\t\t\trecordDirectListener(event.el, event.type, event.listener);\n\t\t\t}\n\t\t}\n\t\tcontext.stashedEvents.length = 0;\n\t}\n\n\t// Set the active region for each animation so it will get attached to\n\t// the right one and set it back afterwards\n\t// Don't await animations\n\tfor (let animation of context.stashedAnimations) {\n\t\tcontext.activeRegion = animation.region;\n\t\t$run(function runMountSideEffectsAnimation() {\n\t\t\tif (animation.in !== undefined) {\n\t\t\t\t// eslint-disable-next-line no-floating-promises\n\t\t\t\tanimate(animation.el, true, animation.in.keyframes, animation.in.options);\n\t\t\t}\n\t\t\tif (animation.out !== undefined) {\n\t\t\t\treturn () => {\n\t\t\t\t\t// eslint-disable-next-line no-floating-promises\n\t\t\t\t\tanimate(animation.el, false, animation.out!.keyframes, animation.out!.options);\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\t}\n\tcontext.stashedAnimations.length = 0;\n\n\t// Set the active region back\n\tcontext.activeRegion = activeRegion;\n}\n","import context from \"./context\";\nimport runMountSideEffects from \"./runMountSideEffects\";\n\n/**\n * Companion to `addFragment` for the single-root-element codegen path. Wires\n * a cloned root element (produced by `getElementFragment`) into the live DOM\n * tree, sets the active region's start/end nodes, and runs the same\n * mount-time side effects as `addFragment` (`$onmount` effects, stashed event\n * listeners, stashed animations).\n *\n * Differences from `addFragment`:\n * - `node` is both the start and end of the region (no\n * `fragment.firstChild`/`fragment.lastChild` indirection).\n * - When hydrating, the existing DOM node is reused (the cloned `node` is\n * discarded); `endNode` is still `node` because `nodeRootElement` returns\n * the hydration cursor's node in that case, not the cloned one.\n *\n * @param node The root element (cloned by `getElementFragment`, or the\n * hydration cursor's node when hydrating).\n * @param parent The intended parent element.\n * @param before The sibling to insert before (or `null` to append).\n */\nexport default function addElement(node: Element, parent: ParentNode, before: Node | null): void {\n\tconst activeRegion = context.activeRegion;\n\tconst hydrationNode = context.hydrationNode;\n\n\t// The single root element is both the start and the end of the region.\n\t// When hydrating, `node` is already the existing DOM node (returned by\n\t// `nodeRootElement`'s cursor walk), so this is correct in both branches.\n\tactiveRegion.startNode = node;\n\tactiveRegion.endNode = node;\n\n\tparent = before?.parentNode ?? parent;\n\n\t// Add the node\n\tif (hydrationNode === null) {\n\t\tparent.insertBefore(node, before);\n\t}\n\n\t// If we're adding this node to the DOM, we can now run any $onmount\n\t// effects, add our stashed events and play our stashed animations\n\trunMountSideEffects(parent, activeRegion, hydrationNode);\n}\n","import context from \"./context\";\nimport runMountSideEffects from \"./runMountSideEffects\";\n\nexport default function addFragment(\n\tfragment: DocumentFragment,\n\tparent: ParentNode,\n\tbefore: Node | null,\n\tendNode?: ChildNode,\n\tstartNode?: ChildNode,\n): void {\n\t//console.log(`adding fragment '${fragment.textContent}' to `, parent);\n\t//console.log(\"before\", before);\n\n\tconst activeRegion = context.activeRegion;\n\tconst hydrationNode = context.hydrationNode;\n\n\t// Set the active region's start/end nodes to the first and last nodes in\n\t// the fragment. During hydration, child component rendering (via\n\t// `addElement`) may have overwritten these — the `startNode` parameter\n\t// (the root node) restores the correct bounds. But when the root node was\n\t// a hydration start marker, `nodeAnchor` will have removed it from the\n\t// DOM and set the region's start node to the first node inside the block\n\t// — restoring the removed marker here would leave the region with a\n\t// detached start node (which breaks clearing the region later).\n\tif (hydrationNode !== null) {\n\t\tif (startNode !== undefined && startNode.parentNode !== null) {\n\t\t\tactiveRegion.startNode = startNode;\n\t\t}\n\t\tactiveRegion.endNode = endNode ?? hydrationNode;\n\t} else {\n\t\tactiveRegion.startNode = fragment.firstChild;\n\t\tactiveRegion.endNode = fragment.lastChild;\n\t}\n\n\tparent = before?.parentNode ?? parent;\n\n\t// Add the fragment\n\tif (hydrationNode === null) {\n\t\tparent.insertBefore(fragment, before);\n\t}\n\n\t// If we're adding this fragment to the DOM, we can now run any $onmount\n\t// effects, add our stashed events and play our stashed animations\n\trunMountSideEffects(parent, activeRegion, hydrationNode);\n}\n","import $run from \"../watch/$run\";\nimport { attachDelegatedEvent, isDelegatedEventType } from \"./delegatedEvents\";\n\nexport default function applyProps(\n\tel: Element,\n\tprops: Record<string, any> | undefined,\n\tpropNamesUsed: string[],\n): void {\n\tif (props !== undefined) {\n\t\tfor (let [name, value] of Object.entries(props)) {\n\t\t\tif (!propNamesUsed.includes(name)) {\n\t\t\t\tif (name.startsWith(\"on\")) {\n\t\t\t\t\tconst eventName = name.substring(2);\n\t\t\t\t\tif (isDelegatedEventType(eventName)) {\n\t\t\t\t\t\tattachDelegatedEvent(el, eventName, value);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tel.addEventListener(eventName, value);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t$run(function setAttribute() {\n\t\t\t\t\t\tel.setAttribute(name, value);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\n\nexport default function clearRegion(region: Region): void {\n\t//console.log(\"clearing region\", region.name, \"from\", region.startNode, \"to\", region.endNode);\n\n\t// DEV:\n\tdevContext.onRegionCleared(region);\n\n\t// Clear child regions and collect animations that take place within this\n\t// region and its children\n\tlet animations: Animation[] | undefined =\n\t\tregion.animations !== null ? Array.from(region.animations) : undefined;\n\tlet childRegion = region.nextRegion;\n\twhile (childRegion !== null && childRegion.depth > region.depth) {\n\t\tif (childRegion.animations !== null) {\n\t\t\tanimations ??= [];\n\t\t\tanimations.push(...childRegion.animations);\n\t\t}\n\t\tconst nextChild = childRegion.nextRegion;\n\t\treleaseRegion(childRegion);\n\t\t// HACK: see runControlBranch\n\t\tchildRegion.depth = -2;\n\t\tchildRegion = nextChild;\n\t}\n\tregion.nextRegion = childRegion;\n\n\tif (region.previousRegion !== null) {\n\t\tregion.previousRegion.nextRegion = region.nextRegion;\n\t}\n\tif (region.nextRegion !== null) {\n\t\tregion.nextRegion.previousRegion = region.previousRegion;\n\t}\n\n\t// Wait for animations, if any, then clear the region's nodes\n\tif (animations !== undefined) {\n\t\tanimations.forEach((a) => {\n\t\t\ta.reverse();\n\t\t\ta.play();\n\t\t});\n\t\t// eslint-disable-next-line no-floating-promises\n\t\tPromise.all(animations.map((a) => a.finished)).then(() => clearNodes(region));\n\t} else {\n\t\tclearNodes(region);\n\t}\n}\n\nfunction clearNodes(region: Region) {\n\t// Clear the nodes for this region\n\tif (region.startNode !== null && region.endNode !== null) {\n\t\t// The node that follows the region's content, captured before any\n\t\t// removal — after the backward walk below, it is the first remaining\n\t\t// node at the region's position (e.g. the control's anchor that\n\t\t// branch content was rendered before).\n\t\tconst after = region.endNode.nextSibling;\n\n\t\t// The stop boundary is normally the region's own start node. But when\n\t\t// an inner control (e.g. an @if inside a @for item) has re-rendered and\n\t\t// replaced the nodes the start node originally pointed at, the start\n\t\t// node becomes detached from the DOM. In that case fall back to the\n\t\t// preceding sibling region's end node (walking past any deeper child\n\t\t// regions that link this region to its sibling), so we only clear this\n\t\t// region's content instead of walking past it into a previous sibling.\n\t\tlet stop: Node | null = region.startNode;\n\t\tconst startDetached = region.startNode.parentNode === null;\n\t\tlet fallback = false;\n\t\tif (startDetached) {\n\t\t\tlet prev: Region | null = region.previousRegion;\n\t\t\twhile (prev !== null && prev.depth > region.depth) {\n\t\t\t\tprev = prev.previousRegion;\n\t\t\t}\n\t\t\tif (prev !== null && prev.endNode !== null && prev.endNode.parentNode !== null) {\n\t\t\t\tstop = prev.endNode;\n\t\t\t\tfallback = true;\n\t\t\t}\n\t\t}\n\t\tlet currentNode = region.endNode;\n\t\twhile (currentNode !== null && currentNode !== stop) {\n\t\t\tlet previousNode = currentNode.previousSibling;\n\t\t\tcurrentNode.remove();\n\t\t\tif (previousNode === null) {\n\t\t\t\t// The region's node chain is no longer connected — everything\n\t\t\t\t// that still needs clearing has been cleared.\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentNode = previousNode;\n\t\t}\n\t\t// When clearing against the region's own start node, remove it too.\n\t\t// When using the fallback (previous sibling's end node), leave it — it\n\t\t// belongs to the sibling.\n\t\tif (!fallback && currentNode === region.startNode) {\n\t\t\tcurrentNode.remove();\n\t\t}\n\n\t\t// Repair ancestor node windows whose start node was just removed.\n\t\t//\n\t\t// When a control branch's content is cleared, ancestor regions whose\n\t\t// window was WIDENED to that content (see widenAncestorsAtAnchor) are\n\t\t// left with a detached startNode. A later moveRegion on such an\n\t\t// ancestor would resurrect the detached node (insertBefore re-attaches\n\t\t// it). Reset any detached ancestor start to the first node that\n\t\t// remains at the cleared position: the node after the removed span —\n\t\t// `after`, or `stop` when the fallback kept the preceding sibling's\n\t\t// end node as the boundary.\n\t\tconst firstRemaining = (fallback ? stop : after) as ChildNode | null;\n\t\tif (firstRemaining !== null) {\n\t\t\tlet ancestor: Region | null = region.previousRegion;\n\t\t\tlet ancestorDepth = region.depth;\n\t\t\twhile (ancestor !== null && ancestor.depth < ancestorDepth) {\n\t\t\t\tif (ancestor.startNode !== null && ancestor.startNode.parentNode === null) {\n\t\t\t\t\tancestor.startNode = firstRemaining;\n\t\t\t\t}\n\t\t\t\tancestorDepth = ancestor.depth;\n\t\t\t\tancestor = ancestor.previousRegion;\n\t\t\t}\n\t\t}\n\t}\n\treleaseRegion(region);\n}\n\nfunction releaseRegion(region: Region) {\n\t(region as any).generation = -1;\n\tregion.startNode = null;\n\tregion.endNode = null;\n\tregion.previousRegion = null;\n\tregion.nextRegion = null;\n\tregion.animations = null;\n\t// Detach any error boundary: the region (and the effects that could\n\t// route errors to it) is being released, and its boundary effect is\n\t// destroyed with its owning region\n\tregion.errorBoundary = undefined;\n\n\t// Clean up effects owned by this region. For each effect we both run its\n\t// optional cleanup function AND detach every source subscription from the\n\t// source signal's `firstTarget` list. Without the detach, the destroyed\n\t// effect stays in `signal.firstTarget` forever — every subsequent change\n\t// to any of its sources re-queues the (no-longer-reachable-via-DOM)\n\t// effect, which re-runs, re-subscribes, and leaks indefinitely. This is\n\t// the dominant cost in long-lived sessions where list items are\n\t// repeatedly created and cleared (e.g. js-framework-bench iterations).\n\tfor (const effect of region.effects) {\n\t\tif (typeof effect.cleanup === \"function\") {\n\t\t\teffect.cleanup();\n\t\t\teffect.cleanup = undefined;\n\t\t}\n\n\t\t// Detach every source subscription from its signal's target list.\n\t\t// `clearSources` only removes subscriptions marked inactive, but a\n\t\t// freshly-destroyed effect's subscriptions are still active (they\n\t\t// were never marked inactive because the effect was never re-run),\n\t\t// so we walk and unlink explicitly.\n\t\tlet sub = effect.firstSource;\n\t\teffect.firstSource = null;\n\t\twhile (sub !== null) {\n\t\t\tconst nextSource = sub.nextSource;\n\n\t\t\t// Unlink this subscription from the signal's target list (the\n\t\t\t// doubly-linked `previousTarget`/`nextTarget` chain).\n\t\t\tconst prev = sub.previousTarget;\n\t\t\tconst next = sub.nextTarget;\n\t\t\tif (prev === null) {\n\t\t\t\t// We're the head of the signal's target list — promote the\n\t\t\t\t// next target, but only if we still are the head. A popular\n\t\t\t\t// signal may have had new subscriptions prepended since this\n\t\t\t\t// sub was created, in which case `firstTarget` no longer\n\t\t\t\t// points at us and the head has already moved on.\n\t\t\t\tif (sub.source.firstTarget === sub) {\n\t\t\t\t\tsub.source.firstTarget = next;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tprev.nextTarget = next;\n\t\t\t}\n\t\t\tif (next !== null) {\n\t\t\t\tnext.previousTarget = prev;\n\t\t\t}\n\n\t\t\t// Clear pointers so this subscription is no longer reachable\n\t\t\t// from either list, even transitively.\n\t\t\tsub.previousTarget = null;\n\t\t\tsub.nextTarget = null;\n\t\t\tsub.nextSource = null;\n\n\t\t\tsub = nextSource;\n\t\t}\n\t}\n\tregion.effects.length = 0;\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\n\n/**\n * Clears a region that was created by `fillLayoutSlot`: tears down the\n * rendered content and its effects, leaving the surrounding layout intact\n * so the slot can be refilled.\n *\n * @param region The region to clear\n */\nexport default function clearLayoutSlot(region: Region): void {\n\tcontext.previousRegion = region.previousRegion!;\n\tclearRegion(region);\n}\n","import type Region from \"../types/Region\";\n\nexport default function newRegion(name?: string): Region {\n\treturn {\n\t\tstartNode: null,\n\t\tendNode: null,\n\t\tpreviousRegion: null,\n\t\tnextRegion: null,\n\t\tdepth: -1,\n\t\tanimations: null,\n\t\tname,\n\t\teffects: [],\n\t};\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\nimport context from \"./context\";\n\nexport default function popRegion(oldRegion: Region): void {\n\tcontext.activeRegion = oldRegion;\n\n\tdevContext.onRegionPopped();\n}\n","import devContext from \"../dev/devContext\";\nimport type Region from \"../types/Region\";\nimport context from \"./context\";\n\nexport default function pushRegion(region: Region, toParent = false): Region {\n\tconst activeRegion = context.activeRegion;\n\n\t// Add the new region to the currently active region's children, so that we\n\t// can delete the children with the parent\n\tif (toParent) {\n\t\tconst previousRegion = context.previousRegion;\n\t\tregion.previousRegion = previousRegion;\n\n\t\tconst nextRegion = previousRegion.nextRegion;\n\t\tpreviousRegion.nextRegion = region;\n\t\tregion.nextRegion = nextRegion;\n\t\t// Keep the sibling chain doubly-linked: the region we displaced must\n\t\t// point back at us. Without this, `clearRegion`'s unlink\n\t\t// (`region.previousRegion.nextRegion = region.nextRegion`) writes\n\t\t// through a stale back-pointer and detaches live regions.\n\t\tif (nextRegion !== null) {\n\t\t\tnextRegion.previousRegion = region;\n\t\t}\n\n\t\tregion.depth = activeRegion.depth + 1;\n\t}\n\n\t// Set the new active region\n\tcontext.activeRegion = region;\n\tcontext.previousRegion = region;\n\n\t// DEV:\n\tdevContext.onRegionPushed(region, toParent);\n\n\t// Return the old active region, so that it can be reset when done\n\treturn activeRegion;\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type Region from \"../types/Region\";\nimport type SlotRender from \"../types/SlotRender\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Renders a component into a persistent layout slot, and returns the region\n * it was rendered into. Used by the layout engine during navigation: the\n * component is created inside `parent` at `anchor`, with `slot` as its child\n * slot render, and the returned region can later be passed to\n * `clearLayoutSlot` to tear the page down — leaving the layout itself\n * intact — before refilling the slot.\n *\n * @param component The component to render into the slot\n * @param slot The slot render to pass to the component\n * @param parent The parent node to render into\n * @param anchor The node to insert content before, or null to append\n * @param $props Optional props to pass to the component\n * @param $context Optional context to pass to the component\n */\nexport default function fillLayoutSlot(\n\tcomponent: Component,\n\tslot: SlotRender,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\t$props?: Record<PropertyKey, any>,\n\t$context?: Record<PropertyKey, any>,\n): Region {\n\tconst region = newRegion(devContext.enabled ? \"Layout slot\" : undefined);\n\tconst oldRegion = pushRegion(region, true);\n\n\tcomponent(parent, anchor, $props, $context, {\n\t\t_: slot,\n\t});\n\n\tpopRegion(oldRegion);\n\n\treturn region;\n}\n","/**\n * During hydration, `nodeAnchor` finds the first node inside a hydration\n * block and removes the start/end marker comments. Generated code for\n * `@html` needs that first node later (to adopt the server-rendered nodes\n * as the region's bounds), but by then the markers are gone — so the only\n * reliable way to recover it is to stash it here, keyed by the anchor node\n * that `nodeAnchor` returns.\n */\nconst firstInsideNodes = new WeakMap<ChildNode, ChildNode | null>();\n\nexport function setFirstInsideNode(anchor: ChildNode, node: ChildNode | null): void {\n\tfirstInsideNodes.set(anchor, node);\n}\n\n/**\n * Gets the first node that was inside the hydration block for the given\n * anchor node, or `undefined` if the anchor wasn't hydrated through\n * hydration markers.\n */\nexport default function firstInsideNode(anchor: ChildNode): ChildNode | null | undefined {\n\treturn firstInsideNodes.get(anchor);\n}\n","export default function getFragment(\n\tdocument: Document,\n\tarray: DocumentFragment[],\n\tindex: number,\n\thtml: string,\n\tns?: boolean,\n): DocumentFragment {\n\t// Create the fragment in the array if it hasn't yet been used\n\tif (array[index] === undefined) {\n\t\t// TODO: Should pass a string for the ns, when we support other element types\n\t\tif (ns === true) {\n\t\t\tconst template = document.createElementNS(\"http://www.w3.org/2000/svg\", \"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tconst fragment = new DocumentFragment();\n\t\t\tfragment.append(...template.childNodes);\n\t\t\tarray[index] = fragment;\n\t\t} else {\n\t\t\tconst template = document.createElement(\"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.content;\n\t\t}\n\t}\n\n\t// Get the fragment from the array\n\t// TODO: If we're hydrating we probably don't want to create and return a\n\t// fragment unless we really need to\n\tlet fragment = array[index].cloneNode(true) as DocumentFragment;\n\n\treturn fragment;\n}\n","/**\n * Returns a clone of the cached template's single root element, bypassing the\n * `DocumentFragment` wrapper that `getFragment` produces.\n *\n * Used by the compiler-emitted `createListItem` for `@for` bodies (and other\n * fragments) whose template has exactly one rendering root child — e.g.\n * `<tr><td>...</td>...</tr>`. Cloning `template.content.firstElementChild`\n * directly saves the per-row `DocumentFragment` allocation that `getFragment`'s\n * `cloneNode(true)` on the cached template's content would otherwise produce,\n * which dominates the cost of bulk-row creates (`run`/`add`/`runlots`).\n *\n * Contract: the compiler only emits `t_fragment_el` for fragment indices whose\n * template has exactly one rendering root, and that root is an `Element`. The\n * cache array (`t_fragment_els`) is separate from `t_fragments` so each helper\n * only ever sees its own cached type at a given index.\n *\n * @param document The owner document (used to build the cached `<template>`).\n * @param array The per-component `t_fragment_els` cache.\n * @param index The fragment's index in the cache.\n * @param html The fragment's HTML source, with `#` placeholders for reactive\n * text and `<!>` for anchor comments.\n * @param ns When true, the template is created in the SVG namespace (its\n * `firstElementChild` is then an SVG element).\n */\nexport default function getElementFragment(\n\tdocument: Document,\n\tarray: Element[],\n\tindex: number,\n\thtml: string,\n\tns?: boolean,\n): Element {\n\t// Create the cached element if it hasn't yet been used\n\tif (array[index] === undefined) {\n\t\t// TODO: Should pass a string for the ns, when we support other element types\n\t\tif (ns === true) {\n\t\t\tconst template = document.createElementNS(\"http://www.w3.org/2000/svg\", \"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.firstElementChild!;\n\t\t} else {\n\t\t\tconst template = document.createElement(\"template\");\n\t\t\ttemplate.innerHTML = html;\n\t\t\tarray[index] = template.content.firstElementChild!;\n\t\t}\n\t}\n\n\treturn array[index]!.cloneNode(true) as Element;\n}\n","import type Component from \"../types/Component\";\n\n/**\n * Whether a component function was compiled for SSR\n *\n * Server components are emitted as `async function`s taking\n * `(props, context, slots)` and returning a `{ body, head }` pair, while\n * client components are plain functions taking\n * `(parent, anchor, props, context, slots)`. Checking the function's\n * constructor distinguishes the two without calling it (which would start\n * the render). The name lives on the intrinsic `AsyncFunction` object, so\n * it survives minification.\n */\nexport default function isServerComponent(component: Component): boolean {\n\treturn component.constructor?.name === \"AsyncFunction\";\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type SlotRender from \"../types/SlotRender\";\nimport flushMountEffects from \"../watch/flushMountEffects\";\nimport isServerComponent from \"./isServerComponent\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Hydrates a component into an existing DOM tree\n * @param parent The parent node\n * @param component The component to mount\n * @param props An object containing component props\n */\nexport default function hydrate(\n\tparent: ParentNode,\n\tcomponent: Component,\n\tprops?: Record<string, any>,\n\tslots?: Record<string, SlotRender>,\n): void {\n\tif (isServerComponent(component)) {\n\t\tthrow new Error(\n\t\t\t\"The component was compiled for SSR (it renders to an HTML string) and cannot be hydrated in the browser. Import the client build instead, e.g. with the '?client' import query\",\n\t\t);\n\t}\n\n\t// When mounting, the parent must have no child elements, so we can just set\n\t// the hydration node to the first child node\n\tcontext.hydrationNode = parent.firstChild;\n\n\t// Create and push the root region\n\t// TODO: Does it need to be on context??\n\tcontext.rootRegion = newRegion(devContext.enabled ? \"Root\" : undefined);\n\tcontext.previousRegion = context.rootRegion;\n\tpushRegion(context.rootRegion);\n\n\t// Call the component's render function\n\tcomponent(parent, null, props, undefined, slots);\n\n\tcontext.hydrationNode = null;\n\n\t// Now that we've hydrated, we can run $onmount effects\n\tflushMountEffects();\n}\n","import devContext from \"../dev/devContext\";\nimport type Component from \"../types/Component\";\nimport type SlotRender from \"../types/SlotRender\";\nimport isServerComponent from \"./isServerComponent\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport pushRegion from \"./pushRegion\";\n\n/**\n * Mounts a component into a DOM node\n *\n * @param parent The node to mount the component into\n * @param component The component to mount\n * @param props An object containing component props\n */\nexport default function mount(\n\tparent: ParentNode,\n\tcomponent: Component,\n\tprops?: Record<string, any>,\n\tslots?: Record<string, SlotRender>,\n): void {\n\tif (isServerComponent(component)) {\n\t\tthrow new Error(\n\t\t\t\"The component was compiled for SSR (it renders to an HTML string) and cannot be mounted in the browser. Import the client build instead, e.g. with the '?client' import query\",\n\t\t);\n\t}\n\n\t// The parent node must have no child elements, so that we can hydrate\n\t// without worrying about where to start\n\tif (parent.childElementCount > 0) {\n\t\tthrow new Error(\"The parent node must have no child elements\");\n\t}\n\n\t// Remove all text, commments, etc\n\twhile (parent.firstChild !== null) {\n\t\tparent.firstChild.remove();\n\t}\n\n\t// Create and push the root region\n\tif (context.rootRegion === null) {\n\t\tcontext.rootRegion = newRegion(devContext.enabled ? \"Root\" : undefined);\n\t\tcontext.previousRegion = context.rootRegion;\n\t\tpushRegion(context.rootRegion);\n\t}\n\n\t// Call the component's render function\n\tcomponent(parent, null, props, undefined, slots);\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\n\n/**\n * Tears down the current UI: disposes the root region tree (running effect\n * cleanups and detaching subscriptions), resets the render context, and\n * removes any remaining child nodes from `parent`.\n *\n * Call this before `mount`ing a fresh component tree into the same container\n * (e.g. when client-side navigating to a route whose layout chain differs\n * from the previous one). `mount` refuses to mount into a non-empty parent\n * and reuses an existing root region, so both must be cleared first.\n *\n * @param parent The container that the previous UI was mounted into\n */\nexport default function unmount(parent: ParentNode): void {\n\tif (context.rootRegion !== null) {\n\t\tclearRegion(context.rootRegion);\n\t\tcontext.rootRegion = null as unknown as Region;\n\t\tcontext.previousRegion = null as unknown as Region;\n\t\tcontext.activeRegion = null as unknown as Region;\n\t}\n\n\t// The root region has no start/end markers of its own, so `clearRegion`\n\t// disposes its descendants' effects but leaves their DOM nodes behind.\n\t// Remove them so `mount` finds an empty container.\n\twhile (parent.firstChild !== null) {\n\t\tparent.firstChild.remove();\n\t}\n}\n","import type ListItem from \"../types/ListItem\";\n\nexport default function newListItem(\n\tdata: Record<PropertyKey, any>,\n\tkey?: any,\n\tname?: string,\n): ListItem {\n\treturn {\n\t\tstartNode: null,\n\t\tendNode: null,\n\t\tpreviousRegion: null,\n\t\tnextRegion: null,\n\t\tdepth: -1,\n\t\tanimations: null,\n\t\tname,\n\t\tdata,\n\t\tkey,\n\t\teffects: [],\n\t};\n}\n","export default function isCommentNode(node: Node): node is Comment {\n\treturn node.nodeType === 8;\n}\n","export default function isTextNode(node: Node): node is Text {\n\treturn node.nodeType === 3;\n}\n","import context from \"./context\";\nimport { HYDRATION_BREAK } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\n\n// TODO: It would be good to remove this, if possible\n\n/**\n * When hydrating, removes and skips hydration comments that are inserted at the\n * start of branches and used to split up text nodes that would otherwise be\n * joined in HTML.\n *\n * @param node The node to check and maybe skip.\n * @returns The next node.\n */\nexport default function nodeCheckHydrationBreak(node: ChildNode | null): ChildNode | null {\n\tif (node !== null && isCommentNode(node) && node.data === HYDRATION_BREAK) {\n\t\tlet comment = node;\n\t\tnode = node.nextSibling;\n\t\tcomment.remove();\n\t}\n\tcontext.hydrationNode = node;\n\treturn node;\n}\n","import context from \"./context\";\nimport isTextNode from \"./isTextNode\";\nimport nodeCheckHydrationBreak from \"./nodeCheckHydrationBreak\";\n\n/**\n * Gets the next sibling of a node.\n *\n * When hydrating, sets the hydration node.\n *\n * @param node The node.\n * @param text Whether we require a text node.\n */\nexport default function nodeNext(node: ChildNode, text = false): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\t// If the required node is a text node, and we already have one, just use\n\t\t// it. This is caused by text nodes being merged in HTML\n\t\tif (text && isTextNode(node)) {\n\t\t\treturn node;\n\t\t}\n\n\t\tlet next = nodeCheckHydrationBreak(node.nextSibling);\n\n\t\t// When seeking non-text nodes during hydration, skip past whitespace-only\n\t\t// text nodes and any trailing break markers, so callers land on the\n\t\t// expected element node rather than an intervening text node\n\t\twhile (!text && next !== null && isTextNode(next) && next.textContent?.trim() === \"\") {\n\t\t\tnext = nodeCheckHydrationBreak(next.nextSibling);\n\t\t}\n\n\t\t// Descend through auto-inserted <tbody> elements. The HTML parser\n\t\t// wraps <tr> elements in <tbody> automatically, which shifts the\n\t\t// hydration cursor one level deeper than the fragment template expects.\n\t\t// Only do this when navigating from a text node (root → element pattern\n\t\t// in generated code), not from comment nodes (e.g. inside nodeAnchor)\n\t\tif (\n\t\t\t!text &&\n\t\t\tnext !== null &&\n\t\t\tnext.nodeName === \"TBODY\" &&\n\t\t\tnext.firstChild &&\n\t\t\tisTextNode(node)\n\t\t) {\n\t\t\tnext = next.firstChild;\n\t\t\tcontext.hydrationNode = next;\n\t\t}\n\n\t\treturn next!;\n\t}\n\n\t// NOTE: We know this is not null as it is being called from generated code\n\treturn node.nextSibling!;\n}\n","import context from \"./context\";\nimport { setFirstInsideNode } from \"./firstInsideNode\";\nimport { HYDRATION_BREAK, HYDRATION_END, HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport nodeNext from \"./nodeNext\";\n\n/**\n * Gets the anchor node for a control statement or component.\n *\n * When mounting, this just returns the anchor node parameter (because it was\n * created).\n *\n * When hydrating, there should be matched <![> and <!]> comments in the HTML,\n * and the anchor node should be after the end comment. The matched comment\n * nodes will be deleted, and the hydration node set to the first node inside\n * the matched comments.\n *\n * @param node The potential anchor node.\n * @returns The anchor node.\n */\nexport default function nodeAnchor(node: ChildNode): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\tif (isCommentNode(node) && node.data === HYDRATION_START) {\n\t\t\t// Save the parent before removing the node, so we know when to\n\t\t\t// stop walking up the tree during document-order traversal\n\t\t\tconst startParent = node.parentNode;\n\n\t\t\t// Skip and remove the start node, setting the hydration node in\n\t\t\t// nodeNext. The node returned here is the first node inside the\n\t\t\t// block (after any leading branch-break marker), which becomes the\n\t\t\t// active region's start node.\n\t\t\tlet currentNode: ChildNode | null = nodeNext(node);\n\t\t\tnode.remove();\n\n\t\t\t// An empty control block can emit one branch-break marker per\n\t\t\t// non-taken branch (e.g. an `@if`/`else if` where no branch\n\t\t\t// matched), and `nodeNext` only strips the first. Skip any that\n\t\t\t// remain: they are server-only artifacts, not content, and must not\n\t\t\t// become the region's start node.\n\t\t\twhile (\n\t\t\t\tcurrentNode !== null &&\n\t\t\t\tisCommentNode(currentNode) &&\n\t\t\t\tcurrentNode.data === HYDRATION_BREAK\n\t\t\t) {\n\t\t\t\tconst next: ChildNode | null = currentNode.nextSibling;\n\t\t\t\tcurrentNode.remove();\n\t\t\t\tcurrentNode = next;\n\t\t\t\tcontext.hydrationNode = currentNode;\n\t\t\t}\n\n\t\t\tconst firstInside: ChildNode | null = currentNode;\n\n\t\t\t// Go through nodes in document order until we get to the end.\n\t\t\t// We use document order (descending into child elements) rather\n\t\t\t// than just siblings, because the HTML parser may move hydration\n\t\t\t// markers into auto-inserted elements (e.g. <tbody> inside <table>)\n\t\t\tlet level = 1;\n\t\t\twhile (currentNode !== null) {\n\t\t\t\tif (isCommentNode(currentNode)) {\n\t\t\t\t\tif (currentNode.data === HYDRATION_START) {\n\t\t\t\t\t\tlevel += 1;\n\t\t\t\t\t} else if (currentNode.data === HYDRATION_END) {\n\t\t\t\t\t\tlevel -= 1;\n\t\t\t\t\t\tif (level === 0) {\n\t\t\t\t\t\t\t// Remove the end node and return the next one\n\t\t\t\t\t\t\tconst endNode = currentNode.nextSibling;\n\t\t\t\t\t\t\tcurrentNode.remove();\n\n\t\t\t\t\t\t\t// If the statement is empty (i.e. the end comment\n\t\t\t\t\t\t\t// immediately follows the start comment), move the\n\t\t\t\t\t\t\t// hydration node past the removed end comment to\n\t\t\t\t\t\t\t// the anchor, so that we can continue to the next\n\t\t\t\t\t\t\t// nodes\n\t\t\t\t\t\t\tif (context.hydrationNode === currentNode) {\n\t\t\t\t\t\t\t\tcontext.hydrationNode = endNode;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// If the first node inside the block is the end\n\t\t\t\t\t\t\t// marker itself, the block has no content (only\n\t\t\t\t\t\t\t// markers). `firstInside` would then point at a node\n\t\t\t\t\t\t\t// that's about to be removed, leaving the region's\n\t\t\t\t\t\t\t// start node detached and its clear walk running past\n\t\t\t\t\t\t\t// into preceding siblings.\n\t\t\t\t\t\t\tconst firstContent = firstInside === currentNode ? null : firstInside;\n\n\t\t\t\t\t\t\t// Set the active region's start node to the first\n\t\t\t\t\t\t\t// node inside the block. This mirrors mounting,\n\t\t\t\t\t\t\t// where the start node is the fragment's first\n\t\t\t\t\t\t\t// child — the actual content — rather than a marker.\n\t\t\t\t\t\t\t// For an empty block, mounting captures the anchor\n\t\t\t\t\t\t\t// comment as both bounds, so match that.\n\t\t\t\t\t\t\tconst region = context.activeRegion;\n\t\t\t\t\t\t\tif (region.startNode === null) {\n\t\t\t\t\t\t\t\tregion.startNode = firstContent ?? endNode;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Stash the first node inside the block, keyed by\n\t\t\t\t\t\t\t// the anchor being returned. Generated code (e.g.\n\t\t\t\t\t\t\t// for `@html`) reads it back to adopt the\n\t\t\t\t\t\t\t// server-rendered nodes, since the markers that\n\t\t\t\t\t\t\t// bounded them have now been removed.\n\t\t\t\t\t\t\tsetFirstInsideNode(endNode!, firstContent);\n\n\t\t\t\t\t\t\t// NOTE: We know this is not null as it is being\n\t\t\t\t\t\t\t// called from generated code\n\t\t\t\t\t\t\treturn endNode!;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Document-order traversal: descend into children first,\n\t\t\t\t// then try siblings. When siblings are exhausted, walk up\n\t\t\t\t// to ancestors (but not past startParent) and try their siblings\n\t\t\t\tif (currentNode.firstChild) {\n\t\t\t\t\tcurrentNode = currentNode.firstChild;\n\t\t\t\t} else if (currentNode.nextSibling) {\n\t\t\t\t\tcurrentNode = currentNode.nextSibling;\n\t\t\t\t} else {\n\t\t\t\t\t// No children and no next sibling: walk up to find an\n\t\t\t\t\t// ancestor that has a next sibling\n\t\t\t\t\tlet parent: Node | null = currentNode.parentNode;\n\t\t\t\t\twhile (parent !== null && parent.nextSibling === null && parent !== startParent) {\n\t\t\t\t\t\tparent = parent.parentNode;\n\t\t\t\t\t}\n\t\t\t\t\t// Don't go past startParent\n\t\t\t\t\tif (parent === null || parent === startParent) {\n\t\t\t\t\t\tcurrentNode = null;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrentNode = parent.nextSibling;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentNode === null) {\n\t\t\t\tthrow new Error(\"End hydration comment not found\");\n\t\t\t}\n\t\t}\n\t}\n\n\treturn node;\n}\n","import context from \"./context\";\n\n/**\n * Gets the first child of a node.\n *\n * Sets the hydration node.\n *\n * @param parent The parent node.\n */\nexport default function nodeChild(parent: Node): ChildNode {\n\tlet childNode = parent.firstChild;\n\tif (context.hydrationNode !== null) {\n\t\t// The child may be null when hydrating the sole text child of an\n\t\t// element with no text\n\t\tif (childNode === null) {\n\t\t\tchildNode = parent.appendChild(parent.ownerDocument!.createTextNode(\"\"));\n\t\t}\n\t\tcontext.hydrationNode = childNode;\n\t}\n\n\t// NOTE: We know this is not null as it is being called from generated code\n\treturn childNode!;\n}\n","import context from \"./context\";\nimport { HYDRATION_BREAK, HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport isTextNode from \"./isTextNode\";\n\n/**\n * Walks the hydration cursor past skippable leading nodes (whitespace text,\n * branch-break markers, auto-inserted `<tbody>`) and lands on the first real\n * content node — the same walk `nodeRoot` performs for the non-text case.\n *\n * Sets `region.startNode` to the landed node (unless it's a control-start\n * marker, which `nodeAnchor` consumes next). Returns the landed node and\n * advances `context.hydrationNode` to it.\n *\n * Extracted so `nodeRoot` and `nodeRootElement` share one implementation of\n * the cursor walk.\n */\nexport default function walkHydrationRoot(): ChildNode {\n\tlet rootNode: ChildNode | null = context.hydrationNode;\n\n\t// For non-text fragments, skip leading branch-break markers (removing\n\t// them), empty anchor comments from preceding siblings, and whitespace\n\t// text nodes. Stop at a control-start marker (nodeAnchor walks it) or\n\t// real content.\n\twhile (rootNode !== null && isSkippable(rootNode)) {\n\t\tconst next: ChildNode | null = rootNode.nextSibling;\n\t\tif (isCommentNode(rootNode) && rootNode.data === HYDRATION_BREAK) {\n\t\t\trootNode.remove();\n\t\t}\n\t\trootNode = next;\n\t\tcontext.hydrationNode = rootNode;\n\t}\n\n\t// Descend through auto-inserted <tbody> elements. The HTML parser wraps\n\t// <tr> elements in <tbody>, which can leave the cursor on the <tbody>\n\t// rather than its first <tr> when entering a @for inside a table.\n\twhile (\n\t\trootNode !== null &&\n\t\t(rootNode as HTMLElement).nodeName === \"TBODY\" &&\n\t\trootNode.firstChild !== null\n\t) {\n\t\trootNode = rootNode.firstChild as ChildNode;\n\t\tcontext.hydrationNode = rootNode;\n\t}\n\n\t// If hydrating, set the active region's start node. Control-start markers\n\t// are left for nodeAnchor to walk — it sets the start node to the first\n\t// inner node.\n\tconst region = context.activeRegion;\n\tconst isControlStart =\n\t\trootNode !== null && isCommentNode(rootNode) && rootNode.data === HYDRATION_START;\n\tif (region.startNode === null && !isControlStart) {\n\t\tregion.startNode = rootNode;\n\t}\n\n\treturn rootNode!;\n}\n\nfunction isSkippable(node: ChildNode): boolean {\n\tif (isTextNode(node) && (node.textContent ?? \"\").trim() === \"\") return true;\n\tif (isCommentNode(node)) {\n\t\t// Skip branch-break markers and empty anchor comments. Control-start\n\t\t// (`[`) and control-end (`]`) markers are NOT skipped.\n\t\treturn node.data === HYDRATION_BREAK || node.data === \"\";\n\t}\n\treturn false;\n}\n","import context from \"./context\";\nimport walkHydrationRoot from \"./walkHydrationRoot\";\n\n/**\n * Gets the root element of a single-root fragment built via `getElementFragment`.\n *\n * Companion to `nodeRoot`, for the codegen path where the compiler has emitted\n * `t_fragment_el` (cloning the cached template's `firstElementChild` directly)\n * instead of `t_fragment` (cloning into a `DocumentFragment`). In the\n * non-hydrating case the cloned element is already the root, so this is a\n * no-op pass-through. In the hydrating case we perform the same cursor walk as\n * `nodeRoot`'s non-text branch so the region's `startNode` lands on the\n * existing DOM node and the hydration cursor advances past any leading\n * whitespace, branch-break markers, and auto-inserted `<tbody>` wrappers.\n *\n * @param node The cloned root element (ignored when hydrating).\n */\nexport default function nodeRootElement(node: Element): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\treturn walkHydrationRoot();\n\t}\n\treturn node;\n}\n","import context from \"./context\";\nimport { HYDRATION_START } from \"./hydrationMarkers\";\nimport isCommentNode from \"./isCommentNode\";\nimport isTextNode from \"./isTextNode\";\nimport walkHydrationRoot from \"./walkHydrationRoot\";\n\n/**\n * Gets the first child in a fragment.\n *\n * When hydrating, also sets the active region's start node, while we have it.\n *\n * If the hydration cursor is on a control-start marker (`<![>`), the node is\n * left in place for `nodeAnchor` (called next as `t_anchor(t_root(...))`) to\n * walk — it consumes the matched `<![>...<!]>` pair, removes the markers and\n * sets the region's start node to the first node inside the block.\n *\n * For non-text fragments, leading branch-break markers (`<!^>`), empty anchor\n * comments left by preceding siblings, and residual whitespace-only text nodes\n * are skipped (break markers removed) so the region's start node lands on real\n * content. This replaces the per-sibling `t_next` calls that the codegen used\n * to emit when leading whitespace separated siblings; with whitespace trimmed\n * those calls are gone, so the advancement happens here.\n *\n * @param parent The parent of the fragment.\n * @param text Whether we require a text node.\n */\nexport default function nodeRoot(parent: Node, text = false): ChildNode {\n\tif (context.hydrationNode !== null) {\n\t\tlet rootNode: ChildNode | null = context.hydrationNode;\n\n\t\t// If the root node we need is a text node, and the hydration node is\n\t\t// not a text node but the previous node is, use the previous node. This\n\t\t// is caused by text nodes being merged in HTML\n\t\tif (\n\t\t\ttext &&\n\t\t\t!isTextNode(rootNode) &&\n\t\t\trootNode.previousSibling !== null &&\n\t\t\tisTextNode(rootNode.previousSibling)\n\t\t) {\n\t\t\trootNode = rootNode.previousSibling;\n\t\t\tcontext.hydrationNode = rootNode;\n\t\t}\n\n\t\t// For non-text fragments, walk past skippable leading nodes and set\n\t\t// the region's start node. Text fragments opt out because their\n\t\t// leading text node is the value the caller expects.\n\t\tif (!text) {\n\t\t\treturn walkHydrationRoot();\n\t\t}\n\n\t\tconst region = context.activeRegion;\n\t\tconst isControlStart =\n\t\t\trootNode !== null && isCommentNode(rootNode) && rootNode.data === HYDRATION_START;\n\t\tif (region.startNode === null && !isControlStart) {\n\t\t\tregion.startNode = rootNode;\n\t\t}\n\n\t\treturn rootNode!;\n\t} else {\n\t\t// NOTE: We know this is not null as it is being called from generated\n\t\t// code\n\t\treturn parent.firstChild!;\n\t}\n}\n","import context from \"./context\";\nimport nodeCheckHydrationBreak from \"./nodeCheckHydrationBreak\";\n\n/**\n * Gets the sibling of a node, x nodes after it.\n *\n * When hydrating, sets the hydration node.\n *\n * @param node The node.\n * @param count The number of nodes to skip.\n */\nexport default function nodeSkip(node: ChildNode, count: number): ChildNode {\n\tlet nextNode = node;\n\n\t// NOTE: We know these are not null as it is being called from generated code\n\tif (context.hydrationNode !== null) {\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tnextNode = nodeCheckHydrationBreak(nextNode.nextSibling)!;\n\t\t}\n\t} else {\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tnextNode = nextNode.nextSibling!;\n\t\t}\n\t}\n\n\treturn nextNode;\n}\n","import type Region from \"../types/Region\";\nimport clearSources from \"../watch/clearSources\";\nimport deactivateSources from \"../watch/deactivateSources\";\nimport runCleanups from \"../watch/runCleanups\";\nimport runEffect from \"../watch/runEffect\";\n\n/**\n * Force re-runs every effect owned by `region` and its descendant regions\n * that depends on at least one of the for-vars set in `changedMask`.\n *\n * Used by keyed-list `updateListItem` callbacks emitted by the compiler when\n * the `@for` body has been classified \"no-proxy safe\" — i.e. the per-item\n * data bag is *not* wrapped in a shallow `$watch` Proxy. Without that Proxy,\n * a write such as `t_old_item.data.row = newRow` doesn't propagate through a\n * signal, so any effects that read `data.row` must be re-run manually.\n *\n * `changedMask` is a bitmask of the for-var positions whose references\n * actually changed in this update. Each effect carries `forVarMask`\n * (computed at compile time) listing the for-vars its body reads; effects\n * whose `forVarMask & changedMask === 0` are skipped. Mount callbacks\n * (`isMountEffect` — `$onmount`/`onmount`) are always skipped: they run\n * once per DOM mount and their bodies are untracked.\n *\n * Equivalent to what `checkEffect` does when a signal has propagated, but\n * unconditional for the effects that do match: cleanup → deactivate sources\n * → run → clear unused sources, for every matching effect on the region and\n * on every descendant region (`depth > region.depth`, the same chain shape\n * `clearRegion` walks).\n */\nexport default function rerunRegionEffects(region: Region, changedMask: number): void {\n\trerunEffectsOnRegion(region, changedMask);\n\tlet child: Region | null = region.nextRegion;\n\twhile (child !== null && child.depth > region.depth) {\n\t\trerunEffectsOnRegion(child, changedMask);\n\t\tchild = child.nextRegion;\n\t}\n}\n\nfunction rerunEffectsOnRegion(region: Region, changedMask: number): void {\n\tfor (let effect of region.effects) {\n\t\t// Mount callbacks run once per region mount (their `$onmount`/`onmount`\n\t\t// semantics) and are untracked, so re-running them here would fire\n\t\t// `onmount` again on every keyed-list item update even when the DOM node\n\t\t// is reused.\n\t\tif (effect.isMountEffect) continue;\n\t\t// When `forVarMask` is set (effect emitted inside a no-proxy `@for`\n\t\t// body), skip effects that don't read any of the changed for-vars.\n\t\t// `0` means the effect reads no for-vars at all — always skip.\n\t\t// `undefined` means no dependency info — re-run unconditionally.\n\t\tif (effect.forVarMask !== undefined && (effect.forVarMask & changedMask) === 0) continue;\n\t\trunCleanups(effect);\n\t\tdeactivateSources(effect);\n\t\trunEffect(effect);\n\t\tclearSources(effect);\n\t}\n}\n","import context from \"./context\";\n\n/**\n * Restores the hydration cursor to a previously-snapshotted node. Used by\n * `@try`/`@catch`: if the try branch throws partway through its hydration\n * walk, the catch branch must resume hydrating from where the try group\n * started, not from wherever the failed branch left the cursor.\n *\n * The cursor is set unconditionally: a failed try-branch build can walk the\n * cursor past the last node (setting it to `null` via `nodeNext`), and the\n * rewind must still restore it — otherwise the catch branch would think it\n * isn't hydrating and insert fresh nodes alongside the server's. When not\n * hydrating at all, the snapshot itself is `null`, so this is a no-op.\n *\n * @param node The snapshotted cursor node (from `saveHydration`).\n */\nexport default function restoreHydration(node: ChildNode | null): void {\n\tcontext.hydrationNode = node;\n}\n","import type Region from \"../types/Region\";\n\n/**\n * Widens ancestor region node windows after a control re-run rendered\n * content at its anchor.\n *\n * A region that owns only a control's anchor comment captures\n * `startNode = endNode = anchor` when it mounts (e.g. a `@for` row whose\n * body is a single `@if`, or an outer `@if` whose body is a single control).\n * Content rendered by a LATER re-run of that control is inserted into the\n * live DOM just BEFORE the anchor — outside that window — so clearing the\n * owning region would remove only the anchor and orphan the branch content.\n * At mount time this can't happen (content is added to the region's detached\n * fragment first, so its `startNode` already covers it), which is why only\n * re-runs need this fix.\n *\n * The first node of the newly rendered content is the first DESCENDANT region\n * of the control that owns nodes (control regions themselves have null\n * `startNode`). Ancestors are the regions with strictly decreasing depth on\n * the `previousRegion` chain; only those whose window starts exactly at the\n * anchor are widened.\n */\nexport default function widenAncestorsAtAnchor(region: Region, anchor: Node | null): void {\n\tif (anchor === null) return;\n\n\t// Find the first node-bearing descendant of this control run\n\tlet child: Region | null = region.nextRegion;\n\twhile (child !== null && child.depth > region.depth && child.startNode === null) {\n\t\tchild = child.nextRegion;\n\t}\n\tif (child === null || child.depth <= region.depth || child.startNode === anchor) {\n\t\treturn;\n\t}\n\tconst firstNode = child.startNode;\n\n\t// Widen every ancestor whose window starts at the anchor. Walk\n\t// `previousRegion` while depth strictly decreases, so sibling chains\n\t// (equal depth) terminate the walk — only true ancestors can own the\n\t// anchor as their window start.\n\tlet ancestor: Region | null = region.previousRegion;\n\tlet ancestorDepth = region.depth;\n\twhile (ancestor !== null && ancestor.depth < ancestorDepth) {\n\t\tif (ancestor.startNode === anchor) {\n\t\t\tancestor.startNode = firstNode;\n\t\t}\n\t\tancestorDepth = ancestor.depth;\n\t\tancestor = ancestor.previousRegion;\n\t}\n}\n","import type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport context from \"./context\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Runs an `if`, `switch` or `await` control statement\n * @param create A function that creates the control statement's branches\n */\nexport default function runControl(\n\tregion: Region,\n\tanchor: Node | null,\n\tcreate: (anchor: Node | null) => void,\n\tname?: string,\n): void {\n\tlet first = true;\n\n\t// Use a generation counter so stale effects (created by previous\n\t// runControl calls for the same region) can detect they're no longer\n\t// current and skip execution. The generation is incremented each time\n\t// runControl is called with this region.\n\tconst gen = ((region as any).generation = ((region as any).generation ?? 0) + 1);\n\n\t// Run the control statement in an effect\n\t$run(function runControl() {\n\t\t// If this effect was created by a previous runControl call for the\n\t\t// same region, it is stale and should not execute\n\t\tif ((region as any).generation !== gen) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (region.depth === -2) {\n\t\t\t(region as any).recreate = true;\n\t\t}\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Run the function that creates the control statement's branches\n\t\tcreate(anchor);\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later re-run may have rendered content before our anchor that\n\t\t// an ancestor's node window doesn't cover — widen those windows so\n\t\t// clearing the ancestor can't orphan the content (see\n\t\t// widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\n\t\t// While hydrating, reset the cursor to the control's anchor after its\n\t\t// content has been hydrated. The branches leave the cursor deep inside\n\t\t// (at the last nested node), but the parent fragment needs a stable\n\t\t// end node — the anchor persists until the parent clears it, so it is\n\t\t// safe to capture.\n\t\tif (context.hydrationNode !== null && anchor !== null) {\n\t\t\tcontext.hydrationNode = anchor as ChildNode;\n\t\t}\n\t}, name);\n}\n","import type Region from \"../types/Region\";\nimport clearRegion from \"./clearRegion\";\n\nexport default function runControlBranch(region: Region, oldIndex: number, index: number): boolean {\n\t// Clear the recreate flag if it was set — it only needs to trigger once\n\tconst recreate = (region as any).recreate;\n\tif (recreate) {\n\t\t(region as any).recreate = false;\n\t}\n\n\t// Whether this region has rendered a branch before. A region's first\n\t// render has no previous branch of its own to clear — its `nextRegion`\n\t// link may point at an unrelated sibling region pushed after it in the\n\t// region chain, and clearing it would destroy live content mounted\n\t// elsewhere. (Callers like `runTry` still force clears on later runs by\n\t// passing a sentinel old index.)\n\tconst firstRender = (region as any).hasRenderedBranch !== true;\n\t(region as any).hasRenderedBranch = true;\n\n\tif (oldIndex === index) {\n\t\tif (recreate) {\n\t\t\tif (region.nextRegion !== null && region.nextRegion.depth > region.depth) {\n\t\t\t\tclearRegion(region.nextRegion);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tif (!firstRender && region.nextRegion !== null && region.nextRegion.depth > region.depth) {\n\t\tclearRegion(region.nextRegion);\n\t}\n\n\treturn true;\n}\n","import type ListItemSpec from \"../types/ListItemSpec\";\nimport type Region from \"../types/Region\";\n\n// Warn once per (list region, key value), so a list that re-renders on every\n// keystroke doesn't flood the console. Keyed by region identity because a\n// region is stable for the lifetime of one `@for` instance.\nconst warnedByRegion = new WeakMap<Region, Set<unknown>>();\n\n/**\n * DEV-ONLY: warns when a keyed `@for` list contains duplicate `@key` values.\n *\n * `runListItems` matches old and new rows by key (first match wins), so\n * duplicate keys make updates and removals hit the wrong rows, desyncing the\n * DOM from the data. Called from `runList` only when `devContext.enabled`, so\n * it never runs in a production build.\n *\n * `undefined`/`null` keys are the \"unkeyed\" case (rows are matched\n * positionally) and are ignored.\n *\n * @param region The `@for` list's region, used to dedupe warnings per list.\n * @param specs The new row specs, in order.\n */\nexport default function checkListKeys(region: Region, specs: ListItemSpec[]): void {\n\tlet seen: Set<unknown> | undefined;\n\tfor (let i = 0; i < specs.length; i++) {\n\t\tconst key = specs[i]!.key;\n\t\tif (key === undefined || key === null) continue;\n\n\t\tif (seen === undefined) seen = new Set();\n\t\tif (!seen.has(key)) {\n\t\t\tseen.add(key);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet warned = warnedByRegion.get(region);\n\t\tif (warned === undefined) {\n\t\t\twarned = new Set();\n\t\t\twarnedByRegion.set(region, warned);\n\t\t}\n\t\tif (!warned.has(key)) {\n\t\t\twarned.add(key);\n\t\t\tconsole.warn(\n\t\t\t\t`[torpor] Duplicate @key value ${formatKey(key)} in a keyed @for list. ` +\n\t\t\t\t\t\"Keys must be unique, or updates and removals will affect the wrong rows.\",\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction formatKey(key: unknown): string {\n\ttry {\n\t\tconst json = JSON.stringify(key);\n\t\treturn json === undefined ? String(key) : json;\n\t} catch {\n\t\treturn String(key);\n\t}\n}\n","import $watch from \"./$watch\";\nimport { proxyDataSymbol } from \"./symbols\";\n\n/**\n * Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that\n * is not already watched and is not a promise. Returns the value unchanged\n * otherwise.\n *\n * Used by the `get` trap (wrap values on read) and the `set` trap (wrap\n * values on write), so a value stored in watched state is reactive whether\n * it's been read yet or not.\n */\nconst proxyCache = new WeakMap<object, object>();\n\nexport default function deepWrap(value: any): any {\n\tif (value === undefined || value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\tif (value[proxyDataSymbol] !== undefined) {\n\t\t// Already watched -- it's either a proxy itself, or a raw target whose\n\t\t// proxy wasn't cached (e.g. it was wrapped directly via `$watch` and\n\t\t// never deep-wrapped). Short-circuit BEFORE reading `then`, otherwise\n\t\t// the read goes through the proxy's `get` trap and creates a spurious\n\t\t// signal for a property nothing ever sets\n\t\treturn proxyCache.get(value) ?? value;\n\t}\n\t// But not if it's a Promise (i.e. has a `then` method)\n\tif (value.then !== undefined) {\n\t\treturn value;\n\t}\n\t// And not DOM nodes / other host objects -- they have internal state and\n\t// accessor-only prototype properties, so wrapping them breaks (e.g.\n\t// writing a wrapped `parentElement` back onto a node throws, because the\n\t// property has only a getter). They're not reactive state either; effects\n\t// still track the key they're stored under\n\tif (value.nodeType !== undefined) {\n\t\treturn value;\n\t}\n\tconst cached = proxyCache.get(value);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\tconst proxy = $watch(value);\n\tproxyCache.set(value, proxy);\n\treturn proxy;\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type ProxyData from \"../types/ProxyData\";\nimport type ProxySignal from \"../types/ProxySignal\";\nimport type Subscription from \"../types/Subscription\";\nimport { COMPUTED_TYPE, EFFECT_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\n\n/**\n * Walk the target graph from a signal source (ProxySignal or Computed),\n * marking each dependent as needing recalculation and queuing effects for\n * re-run. Shared between `propagateSignal` (for proxy writes) and `$async`'s\n * promise-resolve handler (for async value resolution).\n *\n * Must be called inside `batchStart`/`batchEnd` — callers own the batch.\n */\nexport function propagateFromSignal(signal: { firstTarget: Subscription | null }): void {\n\tconst first = signal.firstTarget;\n\tif (first === null) return;\n\tlet targetSub: Subscription = first;\n\n\tlet computed: Computed | undefined;\n\touter: while (true) {\n\t\t// De-activate all targets, so they can be re-used/updated/deleted\n\t\ttargetSub.active = false;\n\t\ttargetSub.recalc = true;\n\n\t\tconst target = targetSub.target;\n\t\tif (target.type === EFFECT_TYPE) {\n\t\t\t// Add the effect to the queue for running after triggering.\n\t\t\t// Dedupe on the `queued` flag — NOT on a link into the queue —\n\t\t\t// because link-based dedupe can't tell an effect still pending\n\t\t\t// in this flush from one that already ran earlier in this flush\n\t\t\t// but whose link hasn't been cleared yet. That gap silently\n\t\t\t// dropped re-queues for effects downstream of a computed whose\n\t\t\t// value oscillated within a single batch (e.g. a derived flag\n\t\t\t// during a props → state → props round-trip), freezing them at\n\t\t\t// a stale value.\n\t\t\tif (!target.queued) {\n\t\t\t\ttarget.queued = true;\n\t\t\t\tcontext.effectsToRun.push(target);\n\t\t\t}\n\t\t} else if (/*target.type === COMPUTED_TYPE*/ !target.recalc) {\n\t\t\t// This may need to be re-computed in the pull phase\n\t\t\ttarget.recalc = true;\n\n\t\t\t// Check the computed's targets\n\t\t\tif (target.firstTarget !== null) {\n\t\t\t\tcomputed = target;\n\t\t\t\tcomputed.rollback = targetSub;\n\t\t\t\ttargetSub = target.firstTarget;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\t// If there are no more targets, we may need to rollback to the\n\t\t// last computed that had more targets\n\t\twhile (targetSub.nextTarget === null && computed !== undefined) {\n\t\t\tconst rollback = computed.rollback;\n\t\t\tif (rollback === null) break; // reached the root signal\n\t\t\ttargetSub = rollback;\n\t\t\tif (targetSub.source.type !== COMPUTED_TYPE) {\n\t\t\t\tcomputed = undefined;\n\t\t\t\tcontinue outer;\n\t\t\t}\n\t\t\tcomputed = targetSub.source;\n\t\t}\n\n\t\tif (targetSub.nextTarget === null) {\n\t\t\tbreak;\n\t\t}\n\n\t\ttargetSub = targetSub.nextTarget;\n\t}\n}\n\n/**\n * When a signal is changed, we need to\n * - Set the signal's subscriptions to recalc\n * - Set any dependent computed values to recalc\n * - Gather dependent effects that will need to be re-run\n */\nexport default function propagateSignal(proxy: ProxyData, key: PropertyKey): void {\n\t//console.log(`triggering effects for '${String(key)}' on`, proxy);\n\t//console.log(\"===\");\n\t//console.log(`triggering effects for '${String(key)}'`);\n\n\tlet signal = proxy.signals.get(key) as ProxySignal;\n\tif (signal !== undefined && signal.firstTarget !== null) {\n\t\tbatchStart();\n\n\t\ttry {\n\t\t\t// Add the signal to the context for updating after triggering.\n\t\t\t// Append via a tail pointer so this stays O(1), rather than walking\n\t\t\t// the whole chain on every write (which made batched mutations O(N²)).\n\t\t\tif (context.lastSignalToUpdate === null) {\n\t\t\t\tcontext.firstSignalToUpdate = signal;\n\t\t\t\tcontext.lastSignalToUpdate = signal;\n\t\t\t} else if (signal.nextSignalToUpdate === null) {\n\t\t\t\tcontext.lastSignalToUpdate.nextSignalToUpdate = signal;\n\t\t\t\tcontext.lastSignalToUpdate = signal;\n\t\t\t}\n\n\t\t\tpropagateFromSignal(signal);\n\t\t} finally {\n\t\t\tbatchEnd();\n\t\t}\n\t}\n}\n","import type ProxyData from \"../types/ProxyData\";\nimport { SIGNAL_TYPE } from \"../types/constants\";\nimport trackSignal from \"./trackSignal\";\n\nexport default function trackProxySignal(data: ProxyData, key: PropertyKey): void {\n\t//console.log(`tracking effect '${context.activeTarget.name}' for '${String(key)}' prop`);\n\n\t// Create or get the signals\n\tlet signal = data.signals.get(key);\n\tif (signal === undefined) {\n\t\tsignal = {\n\t\t\ttype: SIGNAL_TYPE,\n\t\t\tfirstTarget: null,\n\t\t\tnextSignalToUpdate: null,\n\t\t\t//name: dev.propName(key),\n\t\t};\n\t\tdata.signals.set(key, signal);\n\t}\n\n\ttrackSignal(signal);\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport type Effect from \"../types/Effect\";\nimport type ProxyData from \"../types/ProxyData\";\nimport { COMPUTED_TYPE, EFFECT_TYPE, SIGNAL_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport checkComputed from \"./checkComputed\";\nimport deepWrap from \"./deepWrap\";\nimport $unwrap from \"./$unwrap\";\nimport propagateSignal from \"./propagateSignal\";\nimport { proxyDataSymbol } from \"./symbols\";\nimport trackProxySignal from \"./trackProxySignal\";\nimport trackSignal from \"./trackSignal\";\n\n/**\n * Called when a read hits a `didSuspend` computed. Subscribes the reader (so\n * resolve re-runs it through the normal reactive graph), propagates the\n * suspend up the cache chain by tainting the active reader, and notifies the\n * nearest `@await` boundary.\n *\n * Return value (ASYNC.md → \"Stale-while-revalidate\"): on a refresh suspend\n * (the computed has resolved before) returns the previously resolved value\n * held in `staleValue`, so readers keep displaying the old content instead of\n * a placeholder — an `@await` boundary thus keeps its content mounted\n * rather than flashing the `with` branch. On a first load (`staleValue` is\n * undefined) returns `undefined`, which the boundary replaces with its\n * `with` branch. In peek mode (used by `$pending`) always returns `undefined`\n * — the value isn't needed, only the subscription.\n */\nfunction suspendRead(signal: Computed): any {\n\ttrackSignal(signal);\n\t// In peek mode (used by $pending), track the signal for subscription but\n\t// don't taint the reader or notify the boundary. Record a \"loud\" hit only\n\t// for non-quiet suspends — a silent refresh (suspendQuiet) stays quiet per\n\t// ASYNC.md → \"Loud vs quiet\"), so $pending returns false for it. The signal is still\n\t// tracked above so $pending re-evaluates when the silent refresh resolves.\n\tif (context.suspendPeek) {\n\t\tif (!signal.suspendQuiet) {\n\t\t\tcontext.suspendPeekHit = true;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (context.activeTarget !== null) {\n\t\tcontext.activeTarget.didSuspend = true;\n\t\tif (context.activeTarget.type === EFFECT_TYPE) {\n\t\t\t// Record the suspended read on the effect, so `triggerEffects`\n\t\t\t// can re-subscribe it if the run crashes with no error boundary\n\t\t\t// to handle the error — otherwise the crash would detach the\n\t\t\t// subscription above and the effect would never re-run on\n\t\t\t// resolve\n\t\t\tconst effect = context.activeTarget as Effect;\n\t\t\t(effect.suspendSources ??= new Set()).add(signal);\n\t\t}\n\t}\n\tif (context.awaitBoundary !== null) {\n\t\tcontext.awaitBoundary.suspended = true;\n\t\t// Record the suspended computed on the boundary, so its effect can\n\t\t// re-check (and re-subscribe to) just the pending reads on each\n\t\t// re-run instead of walking its whole source list\n\t\tcontext.awaitBoundary.pending.add(signal);\n\t\t// Subscribe the boundary effect to this computed so the boundary\n\t\t// re-runs when the promise resolves. Without this, the subscription\n\t\t// would only exist on child effects that are destroyed when content\n\t\t// is cleared.\n\t\tconst boundaryEffect = context.awaitBoundary.effect;\n\t\tif (boundaryEffect !== null && boundaryEffect !== context.activeTarget) {\n\t\t\tconst oldActive = context.activeTarget;\n\t\t\tcontext.activeTarget = boundaryEffect;\n\t\t\ttrackSignal(signal);\n\t\t\tcontext.activeTarget = oldActive;\n\t\t}\n\t}\n\treturn signal.staleValue;\n}\n\nexport default function proxyGet(\n\ttarget: Record<PropertyKey, any>,\n\tkey: PropertyKey,\n\treceiver: any,\n): any {\n\tlet data: ProxyData = target[proxyDataSymbol];\n\n\tif (key === proxyDataSymbol) {\n\t\treturn data;\n\t}\n\n\t// Dates, Maps and Sets can't be proxied transparently -- their prototype\n\t// methods (`getFullYear`, `get`, `size`...) throw when invoked with the\n\t// proxy as `this`, because they need internal slots of the raw object --\n\t// so method access is routed through wrapper handlers instead. Own\n\t// properties set by user code (`date.foo = 1`) still go through the\n\t// generic property path below.\n\tif (\n\t\t(data.isDate || data.isMap || data.isSet) &&\n\t\t!Object.prototype.hasOwnProperty.call(target, key)\n\t) {\n\t\treturn collectionGet(data, target, key, receiver);\n\t}\n\n\t//console.log(`object get '${String(key)}' on`, target);\n\t//console.log(`object get '${String(key)}'`);\n\n\tlet signal = data.signals.get(key);\n\tif (signal === undefined) {\n\t\tconst propDescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\tif (propDescriptor !== undefined) {\n\t\t\tif (propDescriptor.writable) {\n\t\t\t\t// Setup data for the property\n\t\t\t\tif (data.shallow !== true) {\n\t\t\t\t\t// Set the value to a new proxy if it's an object\n\t\t\t\t\tconst value = target[key];\n\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\ttarget[key] = wrapped;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If a property is being accessed in the course of setting up an\n\t\t\t\t// effect, track it\n\t\t\t\ttrackProxySignal(data, key);\n\t\t\t} else if (propDescriptor.get) {\n\t\t\t\t// OK, we're only checking for computed values if it's read-only for\n\t\t\t\t// now, but we probably need to check any getter's value -- e.g. the\n\t\t\t\t// user may wish to add a setter to optimistically set a value, have\n\t\t\t\t// the UI update, then set the value concretely later (e.g. if\n\t\t\t\t// updating a `count` via a fetch)\n\n\t\t\t\tconst oldRegisterComputed = context.registerComputed;\n\t\t\t\ttry {\n\t\t\t\t\t// Allow calling `$cache`/`$async` to assign the computed to a\n\t\t\t\t\t// proxy signal\n\t\t\t\t\tcontext.registerComputed = (computed: Computed) => {\n\t\t\t\t\t\tdata.signals.set(key, computed);\n\t\t\t\t\t};\n\t\t\t\t\tconst result = Reflect.get(target, key, receiver);\n\t\t\t\t\t// After running the getter, check if the just-registered\n\t\t\t\t\t// computed suspended (e.g. an $async getter returning a\n\t\t\t\t\t// pending promise). If so, handle suspend instead of\n\t\t\t\t\t// returning the raw promise.\n\t\t\t\t\tconst registered = data.signals.get(key) as Computed | undefined;\n\t\t\t\t\tif (\n\t\t\t\t\t\tcontext.refreshSignals !== null &&\n\t\t\t\t\t\tregistered !== undefined &&\n\t\t\t\t\t\tregistered.type === COMPUTED_TYPE &&\n\t\t\t\t\t\tregistered.isAsync\n\t\t\t\t\t) {\n\t\t\t\t\t\t// $refresh collection: record the $async computed (this is\n\t\t\t\t\t\t// the first-ever read, so it isn't in data.signals yet).\n\t\t\t\t\t\t// suspendRead below still runs in peek mode ($refresh sets\n\t\t\t\t\t\t// suspendPeek), so no taint/boundary notification happens.\n\t\t\t\t\t\tcontext.refreshSignals.push(registered);\n\t\t\t\t\t\t// The collection read itself just initialized this computed\n\t\t\t\t\t\t// — its fetch is already in flight, so $refresh must not\n\t\t\t\t\t\t// re-run it (that would start a duplicate fetch whose\n\t\t\t\t\t\t// resolve the generation guard would drop)\n\t\t\t\t\t\tcontext.refreshInitialized?.add(registered);\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tregistered !== undefined &&\n\t\t\t\t\t\tregistered.type === COMPUTED_TYPE &&\n\t\t\t\t\t\tregistered.didSuspend\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn suspendRead(registered);\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t} finally {\n\t\t\t\t\tcontext.registerComputed = oldRegisterComputed;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isArray) {\n\t\t\t// If it's a function in an array, we may intercept it\n\t\t\tif (arrayWrapper[key] !== undefined) {\n\t\t\t\treturn arrayWrapper[key](data, target, key);\n\t\t\t}\n\t\t} else {\n\t\t\t// If it's a non-existent property we still set up a subscription so\n\t\t\t// that if its value is set to something it will re-run the effect\n\t\t\ttrackProxySignal(data, key);\n\t\t}\n\t} else if (signal.type === SIGNAL_TYPE) {\n\t\t// The signal may have been created for a PREVIOUS value at this key —\n\t\t// e.g. the property was assigned between reads. Make sure the current\n\t\t// value is deep-wrapped, the same as the first-read path above -- but\n\t\t// only for writable own data properties, since prototype accessors\n\t\t// (e.g. a DOM node's `parentElement`) can't be written back\n\t\tif (data.shallow !== true) {\n\t\t\tconst value = target[key];\n\t\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\t\tconst propDescriptor = Object.getOwnPropertyDescriptor(target, key);\n\t\t\t\tif (propDescriptor !== undefined && propDescriptor.writable) {\n\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\ttarget[key] = wrapped;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If a property is being accessed in the course of setting up an\n\t\t// effect, track it\n\t\ttrackProxySignal(data, key);\n\t} else if (signal.type === COMPUTED_TYPE) {\n\t\tif (context.refreshSignals !== null && signal.isAsync) {\n\t\t\t// $refresh collection: record the $async computed so it can be\n\t\t\t// re-run as a bare refresh, then return its current value without\n\t\t\t// recalc/taint/boundary handling — collection is a pure peek. fn's\n\t\t\t// result is ignored by $refresh, so the value is only read to\n\t\t\t// trigger the same read path a UI read would.\n\t\t\tcontext.refreshSignals.push(signal);\n\t\t\treturn signal.value;\n\t\t}\n\t\tif (signal.running) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t} else if (signal.recalc) {\n\t\t\t// If a signal that the computed depends on has been changed,\n\t\t\t// but the computed hasn't yet been read, it may need to be\n\t\t\t// re-computed\n\t\t\tcheckComputed(signal);\n\t\t}\n\t\tif (signal.didError) {\n\t\t\t// If there was a previous error, and no dependencies have\n\t\t\t// changed, throw the error again. Subscribe first so the reader\n\t\t\t// re-runs if the computed later recovers (e.g. via a `$refresh`\n\t\t\t// that resolves a fresh fetch) — without this, the reader loses\n\t\t\t// its subscription on the throwing read and recovery can never\n\t\t\t// reach it.\n\t\t\ttrackSignal(signal);\n\t\t\tthrow signal.value;\n\t\t}\n\t\tif (signal.didSuspend) {\n\t\t\t// The computed returned a pending promise — subscribe the reader\n\t\t\t// (so resolve re-runs it), taint up the cache chain, and notify\n\t\t\t// the nearest boundary\n\t\t\treturn suspendRead(signal);\n\t\t}\n\t\ttrackSignal(signal);\n\t\treturn signal.value;\n\t}\n\n\t// Return the property value\n\t// NOTE: equivalent to `Reflect.get(target, key, receiver)` for the cases\n\t// that reach here (data properties or missing keys — anything with a\n\t// getter has early-returned above). Avoids a `Reflect.get` function call\n\t// per property read on a watched object, which is the dominant per-effect-\n\t// run cost: each row effect reads `$state.selected`, `data.row.id`, and\n\t// `data.row.label` (the `.row` access goes through this trap), so a 1k-row\n\t// render triggers ~3k of these calls.\n\treturn target[key];\n}\n\n// Prevent array functions from calling functions and properties in breakable\n// ways (e.g. calling splice sets length before adding items)\nconst arrayWrapper: Record<PropertyKey, any> = {\n\t// Iterating a watched array (`for…of`, spread, `Array.from`) must NOT walk\n\t// the proxy per element. The old path returned `Array.prototype[Symbol.iterator]`\n\t// unchanged, so for-of invoked it with the PROXY as `this` and every element\n\t// read `proxy[i]` hit the `get` trap (descriptor lookup, deep-wrap checks,\n\t// per-index signal creation, Map ops) — a 1k-row list cost ~100x the raw\n\t// iteration. Lists re-iterate their source array on EVERY run (the\n\t// compiler-emitted `buildItems`), making this the dominant cost of pure\n\t// bookkeeping ops (rotate/remove).\n\t//\n\t// Instead we iterate the RAW target directly and lazily `$watch`-wrap each\n\t// element, writing the proxy back (`target[i] = proxy`) exactly like the\n\t// `get` trap does on first access. That keeps a SINGLE proxy instance per\n\t// element, so in-place mutation (`$state.data[i].label = …`) still reaches\n\t// the row effects that subscribed through `item.data.row`, while skipping\n\t// the per-element trap entirely. `data.shallow` arrays are left unwrapped,\n\t// matching the `get` trap's deep-only behaviour.\n\t[Symbol.iterator]: function (data: ProxyData, target: any, _key: PropertyKey) {\n\t\ttrackProxySignal(data, \"length\");\n\t\t// HACK: This prevents lists being re-run on every random property\n\t\t// access by disabling the active effect before properties get\n\t\t// accessed. I'm not sure if this is the best way to achieve this...\n\t\tcontext.activeTarget = null;\n\t\treturn function arrayIterator() {\n\t\t\tlet index = 0;\n\t\t\treturn {\n\t\t\t\tnext() {\n\t\t\t\t\tif (index >= target.length) return { value: undefined, done: true };\n\t\t\t\t\tlet value = target[index];\n\t\t\t\t\tif (data.shallow !== true) {\n\t\t\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\t\t\tvalue = wrapped;\n\t\t\t\t\t\t\ttarget[index] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Mirror the `get` trap's per-index signal creation (a plain\n\t\t\t\t\t// index is never subscribed during iteration — activeTarget is\n\t\t\t\t\t// null — but keeping the signal means a later direct `arr[i]`\n\t\t\t\t\t// read inside an effect reuses it, exactly as before).\n\t\t\t\t\ttrackProxySignal(data, String(index));\n\t\t\t\t\tindex++;\n\t\t\t\t\treturn { value, done: false };\n\t\t\t\t},\n\t\t\t\t[Symbol.iterator]() {\n\t\t\t\t\treturn this;\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\t},\n\tpop: arrayHandle,\n\tpush: arrayHandle,\n\treverse: arrayHandle,\n\tshift: arrayHandle,\n\tsort: arrayHandle,\n\tsplice: arrayHandle,\n\tunshift: arrayHandle,\n\t// Read-only methods must also run on the raw target. `slice`/`filter`/`concat`\n\t// etc. called on the proxy walk every element through the `get` trap — the\n\t// same ~100x penalty — for nothing, since their results are either assigned\n\t// back into `$state.data` (re-wrapped by `$watch` in the `set` trap) or read\n\t// transiently. Running them on the raw array keeps the elements' proxy\n\t// identity unchanged (wrapped elements stay wrapped; raw elements stay raw\n\t// until the next iteration wraps them).\n\tslice: readHandle,\n\tconcat: readHandle,\n\tfilter: readHandle,\n\tmap: readHandle,\n\ttoReversed: readHandle,\n\ttoSorted: readHandle,\n\ttoSpliced: readHandle,\n\tindexOf: readHandle,\n\tlastIndexOf: readHandle,\n\tincludes: readHandle,\n\tfind: readHandle,\n\tfindIndex: readHandle,\n\tsome: readHandle,\n\tevery: readHandle,\n\tjoin: readHandle,\n\tforEach: readHandle,\n\treduce: readHandle,\n\treduceRight: readHandle,\n\tflat: readHandle,\n\tflatMap: readHandle,\n\tat: readHandle,\n};\n\nfunction readHandle(data: ProxyData, target: any, key: PropertyKey): Function {\n\t// Call the function on the target (so proxy properties don't get\n\t// intercepted). Read-only, so no `length` propagation — but an effect that\n\t// READS the array through one of these (`items.join(\"\")`, `items.slice(1)`)\n\t// must still subscribe to `length` so it re-runs on push/splice/index-set\n\t// (every array mutation propagates `length`). When no effect is active this\n\t// is a cheap no-op.\n\treturn function (...args: any[]) {\n\t\ttrackProxySignal(data, \"length\");\n\t\tconst func = target[key];\n\t\treturn func.apply(target, args);\n\t};\n}\n\nfunction arrayHandle(data: ProxyData, target: any, key: PropertyKey): Function {\n\t// Call the function on the target (so proxy properties don't get\n\t// intercepted) and trigger effects that depend on `length`\n\treturn function (...args: any[]) {\n\t\tconst func = target[key];\n\t\tconst result = func.apply(target, args);\n\t\tpropagateSignal(data, \"length\");\n\t\treturn result;\n\t};\n}\n\n// #region Date/Map/Set wrappers\n\n// Signal key for collection-wide reads (`size`, iteration). Also the fallback\n// per-key signal for keys that aren't primitives (object keys can't be signal\n// keys, since `data.signals` is keyed by PropertyKey)\nconst COLLECTION_KEY = Symbol(\"torp.collection\");\n// Signal key for all Date reads/writes (a Date only has one value, its time)\nconst TIME_KEY = \"#time\";\n\n/**\n * Routes a `get` on a watched Date/Map/Set to the right wrapper handler.\n *\n * Note the two levels of indirection for methods: the handler runs at get-trap\n * time (returning the method to call), and the returned function runs when the\n * method is invoked. `size` is the exception -- it returns its value at\n * get-trap time, because it's a readonly property, not a method.\n */\nfunction collectionGet(data: ProxyData, target: any, key: PropertyKey, receiver: any): any {\n\tif (data.isDate) {\n\t\treturn dateGet(data, target, key);\n\t}\n\tconst wrapper = data.isMap ? mapWrapper : setWrapper;\n\tconst handle = wrapper[key];\n\tif (handle !== undefined) {\n\t\treturn handle(data, target, key, receiver);\n\t}\n\treturn target[key];\n}\n\n/**\n * Returns the signal key for a Map/Set operation: primitives get a per-key\n * signal, so reading one key doesn't re-run effects when an unrelated key\n * changes. Anything else shares the collection-wide signal.\n */\nfunction collectionKey(key: any): PropertyKey {\n\tconst type = typeof key;\n\treturn type === \"string\" || type === \"number\" || type === \"symbol\" ? key : COLLECTION_KEY;\n}\n\n/**\n * Propagates a Map/Set mutation: the per-key signal (when the key is a\n * primitive) plus the collection-wide signal. The collection signal is always\n * enough for object keys, and propagating the same signal twice would re-run\n * effects twice (they re-subscribe between flushes).\n */\nfunction propagateCollection(data: ProxyData, key: PropertyKey): void {\n\tif (key !== COLLECTION_KEY) {\n\t\tpropagateSignal(data, key);\n\t}\n\tpropagateSignal(data, COLLECTION_KEY);\n}\n\nfunction dateGet(data: ProxyData, target: any, key: PropertyKey): any {\n\tif (typeof key === \"symbol\") {\n\t\t// `Symbol.toPrimitive` is looked up by the language itself for `==`\n\t\t// comparisons, arithmetic, template literals and JSON.stringify. It\n\t\t// must be invoked on the raw target (internal slots), and reading it\n\t\t// counts as a read of the date's value\n\t\tif (key === Symbol.toPrimitive) {\n\t\t\treturn function (hint: string) {\n\t\t\t\tconst result = target[Symbol.toPrimitive](hint);\n\t\t\t\ttrackProxySignal(data, TIME_KEY);\n\t\t\t\treturn result;\n\t\t\t};\n\t\t}\n\t\treturn target[key];\n\t}\n\tif (typeof key !== \"string\") {\n\t\treturn target[key];\n\t}\n\tconst value = target[key];\n\tif (typeof value !== \"function\") {\n\t\treturn value;\n\t}\n\tif (key.startsWith(\"set\")) {\n\t\treturn function (...args: any[]) {\n\t\t\t// Only propagate if the time actually changed, so setting the same\n\t\t\t// value is a no-op (same as the `set` trap)\n\t\t\tconst before = target.getTime();\n\t\t\tconst result = value.apply(target, args);\n\t\t\tif (target.getTime() !== before) {\n\t\t\t\tpropagateSignal(data, TIME_KEY);\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t}\n\tif (key.startsWith(\"get\") || key.startsWith(\"to\") || key === \"valueOf\") {\n\t\treturn function (...args: any[]) {\n\t\t\tconst result = value.apply(target, args);\n\t\t\ttrackProxySignal(data, TIME_KEY);\n\t\t\treturn result;\n\t\t};\n\t}\n\treturn value;\n}\n\nconst mapWrapper: Record<PropertyKey, any> = {\n\tsize: function (data: ProxyData, target: any): number {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\treturn target.size;\n\t},\n\tget: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\ttrackProxySignal(data, collectionKey(key));\n\t\t\tconst value = target.get(key);\n\t\t\tif (data.shallow !== true) {\n\t\t\t\t// Deep-wrap the value and write the proxy back, so repeated\n\t\t\t\t// reads return the same proxy (same as array elements)\n\t\t\t\tconst wrapped = deepWrap(value);\n\t\t\t\tif (wrapped !== value) {\n\t\t\t\t\ttarget.set(key, wrapped);\n\t\t\t\t}\n\t\t\t\treturn wrapped;\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t},\n\thas: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\ttrackProxySignal(data, collectionKey(key));\n\t\t\treturn target.has(key);\n\t\t};\n\t},\n\tset: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (key: any, value: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\t// Only propagate if the value actually changed or the key is new\n\t\t\t// (same as the `set` trap). Note a stored value may be a proxy\n\t\t\t// (see `get`), so unwrap both sides before comparing\n\t\t\tif (target.has(key) && $unwrap(target.get(key)) === $unwrap(value)) {\n\t\t\t\treturn receiver ?? target;\n\t\t\t}\n\t\t\t// A watched object is stored as its proxy, so reads return it\n\t\t\t// reactively (same as array elements written back by the iterator)\n\t\t\tconst result = target.set(key, value);\n\t\t\tpropagateCollection(data, collectionKey(key));\n\t\t\t// Map.set returns the map for chaining -- return the proxy so\n\t\t\t// chained mutations stay reactive\n\t\t\treturn receiver ?? result;\n\t\t};\n\t},\n\tdelete: function (data: ProxyData, target: any): Function {\n\t\treturn function (key: any) {\n\t\t\tkey = $unwrap(key);\n\t\t\tconst result = target.delete(key);\n\t\t\tpropagateCollection(data, collectionKey(key));\n\t\t\treturn result;\n\t\t};\n\t},\n\tclear: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\tconst result = target.clear();\n\t\t\t// Per-key readers must re-run too, and the keys are gone, so\n\t\t\t// propagate every signal this collection created -- in one batch,\n\t\t\t// so readers of several signals re-run only once\n\t\t\tbatchStart();\n\t\t\ttry {\n\t\t\t\tfor (const key of data.signals.keys()) {\n\t\t\t\t\tpropagateSignal(data, key);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tbatchEnd();\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t},\n\tkeys: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\treturn [...target.keys()][Symbol.iterator]();\n\t\t};\n\t},\n\tvalues: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tlet values = [...target.values()];\n\t\t\tif (data.shallow !== true) {\n\t\t\t\tvalues = values.map(deepWrap);\n\t\t\t}\n\t\t\treturn values[Symbol.iterator]();\n\t\t};\n\t},\n\tentries: mapEntries,\n\t// Map's default iteration protocol yields entries\n\t[Symbol.iterator]: mapEntries,\n\tforEach: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (callback: (value: any, key: any, collection: any) => void, thisArg?: any) {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tconst wrap = data.shallow !== true;\n\t\t\ttarget.forEach((value: any, key: any) => {\n\t\t\t\tcallback.call(thisArg, wrap ? deepWrap(value) : value, key, receiver ?? target);\n\t\t\t});\n\t\t};\n\t},\n};\n\nfunction mapEntries(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tconst wrap = data.shallow !== true;\n\t\tconst entries = [...target.entries()].map((entry) => [\n\t\t\tentry[0],\n\t\t\twrap ? deepWrap(entry[1]) : entry[1],\n\t\t]);\n\t\treturn entries[Symbol.iterator]();\n\t};\n}\n\nconst setWrapper: Record<PropertyKey, any> = {\n\tsize: function (data: ProxyData, target: any): number {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\treturn target.size;\n\t},\n\thas: function (data: ProxyData, target: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\ttrackProxySignal(data, collectionKey(value));\n\t\t\treturn target.has(value);\n\t\t};\n\t},\n\tadd: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\t// Adding an existing element is a no-op (same as the `set` trap)\n\t\t\tif (target.has(value)) {\n\t\t\t\treturn receiver ?? target;\n\t\t\t}\n\t\t\tconst result = target.add(value);\n\t\t\tpropagateCollection(data, collectionKey(value));\n\t\t\t// Set.add returns the set for chaining -- return the proxy so\n\t\t\t// chained mutations stay reactive\n\t\t\treturn receiver ?? result;\n\t\t};\n\t},\n\tdelete: function (data: ProxyData, target: any): Function {\n\t\treturn function (value: any) {\n\t\t\tvalue = $unwrap(value);\n\t\t\tconst result = target.delete(value);\n\t\t\tpropagateCollection(data, collectionKey(value));\n\t\t\treturn result;\n\t\t};\n\t},\n\tclear: function (data: ProxyData, target: any): Function {\n\t\treturn function () {\n\t\t\tconst result = target.clear();\n\t\t\t// Per-element readers must re-run too, and the elements are gone,\n\t\t\t// so propagate every signal this collection created -- in one\n\t\t\t// batch, so readers of several signals re-run only once\n\t\t\tbatchStart();\n\t\t\ttry {\n\t\t\t\tfor (const key of data.signals.keys()) {\n\t\t\t\t\tpropagateSignal(data, key);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tbatchEnd();\n\t\t\t}\n\t\t\treturn result;\n\t\t};\n\t},\n\t// Sets yield the same elements from keys/values/iteration -- all wrapped,\n\t// so mutating an element re-runs readers\n\tkeys: setValues,\n\tvalues: setValues,\n\t[Symbol.iterator]: setValues,\n\tentries: setEntries,\n\tforEach: function (data: ProxyData, target: any, _key: PropertyKey, receiver: any): Function {\n\t\treturn function (callback: (value: any, value2: any, collection: any) => void, thisArg?: any) {\n\t\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\t\tconst wrap = data.shallow !== true;\n\t\t\ttarget.forEach((value: any) => {\n\t\t\t\tconst wrapped = wrap ? deepWrap(value) : value;\n\t\t\t\tcallback.call(thisArg, wrapped, wrapped, receiver ?? target);\n\t\t\t});\n\t\t};\n\t},\n};\n\nfunction setValues(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tlet values = [...target.values()];\n\t\tif (data.shallow !== true) {\n\t\t\tvalues = values.map(deepWrap);\n\t\t}\n\t\treturn values[Symbol.iterator]();\n\t};\n}\n\nfunction setEntries(data: ProxyData, target: any): Function {\n\treturn function () {\n\t\ttrackProxySignal(data, COLLECTION_KEY);\n\t\tconst wrap = data.shallow !== true;\n\t\tconst entries = [...target.values()].map((value) => {\n\t\t\tconst wrapped = wrap ? deepWrap(value) : value;\n\t\t\treturn [wrapped, wrapped];\n\t\t});\n\t\treturn entries[Symbol.iterator]();\n\t};\n}\n\n// #endregion\n","import devContext from \"../dev/devContext\";\nimport context from \"../render/context\";\nimport deepWrap from \"./deepWrap\";\nimport propagateSignal from \"./propagateSignal\";\nimport { proxyDataSymbol } from \"./symbols\";\n\nexport default function proxySet(\n\ttarget: Record<PropertyKey, any>,\n\tkey: PropertyKey,\n\tvalue: any,\n\treceiver: any,\n): boolean {\n\t//console.log(`object set '${String(key)}' to`, value, \"on\", target);\n\t//console.log(`object set '${String(key)}'`);\n\n\t// Only do things if the value has changed\n\tconst oldValue = target[key];\n\tif (value !== oldValue) {\n\t\tif (context.batchOperation > 100) {\n\t\t\tthrow new Error(\"Cycle detected\");\n\t\t}\n\n\t\tlet data = target[proxyDataSymbol];\n\n\t\t// DEV:\n\t\tdevContext.signalSet(data, key);\n\n\t\t// Wrap the new value if it's an object (plain objects, arrays, Dates,\n\t\t// Maps, Sets), so storing it and mutating it through the proxy is\n\t\t// reactive right away -- same as the `get` trap's deep-wrap on read.\n\t\t// Skipped for shallow watches, whose children stay unwrapped.\n\t\t// NOTE: this is mostly an ergonomics/consistency win (raw values\n\t\t// assigned here used to leak out of raw-target paths like the array\n\t\t// `slice`/`map` handles). The `get` trap's lazy wrap still covers the\n\t\t// common read paths, so if profiling ever shows this line being slow\n\t\t// (it allocates a proxy per assigned object), just delete it and\n\t\t// everything reverts to wrap-on-read\n\t\tif (data.shallow !== true) {\n\t\t\tvalue = deepWrap(value);\n\t\t}\n\n\t\t// Set the property value on the target\n\t\tReflect.set(target, key, value, receiver);\n\n\t\t// Re-run effects\n\t\tpropagateSignal(data, key);\n\n\t\t// If an item in an array is being set directly, trigger the length to\n\t\t// cause any lists to be re-run and data re-bound\n\t\t// TODO: Can we update the single item's data directly somehow?\n\t\tif (data.isArray && typeof key !== \"symbol\" && !isNaN(+key)) {\n\t\t\tpropagateSignal(data, \"length\");\n\t\t}\n\t}\n\n\treturn true;\n}\n","import devContext from \"../dev/devContext\";\nimport type ProxyData from \"../types/ProxyData\";\nimport type WatchOptions from \"../types/WatchOptions\";\nimport proxyGet from \"./proxyGet\";\nimport proxySet from \"./proxySet\";\nimport { proxyDataSymbol } from \"./symbols\";\n\n// The Proxy handler is stateless — every trap looks up state via the\n// `proxyDataSymbol` property on the target itself — so a single shared\n// handler can serve every $watch'd object. Avoiding a fresh `{ get, set }`\n// allocation per $watch() call removes N object allocations per N-item list\n// render (the per-row `$watch(data, { shallow: true })` in runListItems is\n// called once for every keyed list item).\nconst sharedHandler: ProxyHandler<Record<PropertyKey, any>> = {\n\tget: proxyGet,\n\tset: proxySet,\n};\n\n/**\n * Watches an object and runs effects when its properties are changed.\n *\n * Dates, Maps and Sets are supported too: their methods are reactive (reads\n * track, writes notify), so `new Date()`, `new Map()` and `new Set()` can be\n * used in watched state directly.\n *\n * @param object The object to watch\n */\nexport default function $watch<T extends object>(object: T, options?: WatchOptions): T {\n\t// Return the object itself if it is undefined or null, or if it is already a proxy\n\tif (object === undefined || object === null || (object as any)[proxyDataSymbol] !== undefined) {\n\t\treturn object;\n\t}\n\n\t// Create a proxy handler for each object, and store some data for it here\n\tconst data: ProxyData = {\n\t\ttarget: object as Record<PropertyKey, any>,\n\t\tisArray: Array.isArray(object),\n\t\tisDate: object instanceof Date,\n\t\tisMap: object instanceof Map,\n\t\tisSet: object instanceof Set,\n\t\tshallow: options?.shallow === true,\n\t\tsignals: new Map(),\n\t};\n\n\t// Non-enumerable, so spreading or `Object.assign`-ing a watched object\n\t// (`$state.a = $state.a.map(c => ({ ...c }))`) doesn't copy the marker\n\t// into the new object — a copied ProxyData points at the OLD target and\n\t// makes the new object look already-watched, so it never gets deep-wrapped\n\tObject.defineProperty(object, proxyDataSymbol, {\n\t\tvalue: data,\n\t\twritable: true,\n\t\tenumerable: false,\n\t\tconfigurable: true,\n\t});\n\n\tconst proxy = new Proxy(object, sharedHandler) as T;\n\n\t// DEV:\n\tdevContext.onWatch(data);\n\n\treturn proxy;\n}\n","/**\n * Computes the indices (into `arr`) of a longest strictly-increasing\n * subsequence, skipping zero entries. Adapted from Vue 3's `getSequence`.\n *\n * Used by the keyed-list reconciler (`runListItems`): `arr` is the\n * `newIndexToOldIndex` map where `arr[i] = oldIndex + 1` (so `0` marks a\n * new/unmounted slot, which is skipped). The returned indices identify the\n * items that are already in correct relative order and therefore don't need\n * to be moved — everything else is moved or mounted.\n *\n * Runs in O(n log n).\n */\nexport default function getSequence(arr: number[]): number[] {\n\tconst p = arr.slice();\n\tconst result = [0];\n\tlet i: number;\n\tlet j: number;\n\tlet u: number;\n\tlet v: number;\n\tlet c: number;\n\tconst len = arr.length;\n\tfor (i = 0; i < len; i++) {\n\t\tconst arrI = arr[i]!;\n\t\tif (arrI !== 0) {\n\t\t\tj = result[result.length - 1]!;\n\t\t\tif (arr[j]! < arrI) {\n\t\t\t\tp[i] = j;\n\t\t\t\tresult.push(i);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tu = 0;\n\t\t\tv = result.length - 1;\n\t\t\twhile (u < v) {\n\t\t\t\tc = (u + v) >> 1;\n\t\t\t\tif (arr[result[c]!]! < arrI) {\n\t\t\t\t\tu = c + 1;\n\t\t\t\t} else {\n\t\t\t\t\tv = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (arrI < arr[result[u]!]!) {\n\t\t\t\tif (u > 0) {\n\t\t\t\t\tp[i] = result[u - 1]!;\n\t\t\t\t}\n\t\t\t\tresult[u] = i;\n\t\t\t}\n\t\t}\n\t}\n\tu = result.length;\n\tv = result[u - 1]!;\n\twhile (u-- > 0) {\n\t\tresult[u] = v;\n\t\tv = p[v]!;\n\t}\n\treturn result;\n}\n","import type Region from \"../types/Region\";\n\nexport default function moveRegion(parent: Node, region: Region, before: Node | null): void {\n\tparent = before?.parentNode ?? parent;\n\tconst endNode = region.endNode ?? region.startNode;\n\tlet currentNode = region.startNode;\n\n\twhile (currentNode !== null) {\n\t\tconst nextNode = currentNode.nextSibling;\n\t\tparent.insertBefore(currentNode, before);\n\t\tif (currentNode === endNode) break;\n\t\tcurrentNode = nextNode;\n\t}\n}\n","// Keyed list reconciliation with survivor reuse.\n//\n// The compiler-emitted `buildItems` callback returns a lightweight array of\n// `ListItemSpec`s ({key, data}) — one per row of the new data, with no DOM\n// nodes, effects, or sibling-chain pointers. This reconciler maps each spec\n// to either an EXISTING old ListItem (matched by key, reused wholesale — its\n// DOM nodes, effects, and depth are already correct) or a freshly mounted\n// ListItem (for genuinely new keys). This keeps the per-update cost\n// proportional to what actually changed: a single remove from a 1000-row list\n// touches one clearRegion, not a full per-row field-shuffle across all 999\n// survivors.\n//\n// Replaces an earlier snabbdom-derived 4-way head/tail heuristic with a\n// prefix/suffix sync + longest-increasing-subsequence (LIS) pass, which\n// produces the minimal move set. Operations (`moveRegion` / `mountSpec` /\n// `clearRegion`) and the LIS are unchanged in spirit from the\n// transferListItemData-based version — only the survivor handling is smarter\n// (reuse vs. copy-back).\n//\n// The sibling region chain (`previousRegion`/`nextRegion`) is relinked ONCE\n// at the end from the final item order. Nothing during reconciliation reads\n// it (moves and mounts use DOM `startNode`/`endNode`; `clearRegion` walks\n// each cleared region's own subtree), so a single end-of-pass relink is\n// sufficient and gives a clean invariant regardless of which path produced\n// `newItems`. This means `buildItems` no longer pre-links the chain.\nimport type ListItem from \"../types/ListItem\";\nimport type ListItemSpec from \"../types/ListItemSpec\";\nimport type Region from \"../types/Region\";\nimport type WatchOptions from \"../types/WatchOptions\";\nimport $watch from \"../watch/$watch\";\nimport clearRegion from \"./clearRegion\";\nimport context from \"./context\";\nimport getSequence from \"./getSequence\";\nimport moveRegion from \"./moveRegion\";\nimport newListItem from \"./newListItem\";\n\n// Hoisted options object — `$watch` only reads `options?.shallow`, so a single\n// shared constant can serve every per-item `$watch(data, { shallow: true })`\n// call in the mount path below. Removes one object allocation per mounted\n// list item (i.e. one per row in `run`/`add`/`runlots`).\nconst SHALLOW_WATCH_OPTIONS: WatchOptions = { shallow: true };\n\n/**\n * Mounts a new list item from a spec: allocates the ListItem, establishes it\n * as the active region (so the compiler-emitted `create` callback attaches\n * effects/events to the right region), sets its depth, optionally wraps its\n * data in a shallow watch, then runs `create`. Returns the mounted item so the\n * caller can slot it into the live list. The sibling chain is left for the\n * end-of-pass relink.\n */\nfunction mountSpec(\n\tspec: ListItemSpec,\n\tregion: Region,\n\tbefore: Node | null,\n\tcreate: (item: ListItem, before: Node | null) => void,\n\tnoWatch?: boolean,\n): ListItem {\n\tconst item: ListItem = newListItem(spec.data, spec.key);\n\tconst savedActiveRegion = context.activeRegion;\n\titem.depth = region.depth + 1;\n\tcontext.activeRegion = item;\n\tif (noWatch !== true) {\n\t\titem.data = $watch(item.data, SHALLOW_WATCH_OPTIONS);\n\t}\n\tcreate(item, before);\n\tcontext.activeRegion = savedActiveRegion;\n\treturn item;\n}\n\n/**\n * Reconciles an old keyed list against a new keyed list, reusing old\n * ListItems for survivors and producing the minimal set of DOM moves /\n * mounts / clears.\n *\n * @returns The new live list of ListItems (reused old items + freshly\n * mounted ones), which the caller keeps for the next reconciliation.\n *\n * @param region The list's region\n * @param parent The parent DOM element\n * @param anchor The DOM node to create new items before (the list's trailing anchor)\n * @param oldItems The list of current (live) items from the previous run\n * @param newSpecs The lightweight {key, data} specs for the new data\n * @param create A function that creates the DOM elements for a new item\n * @param update A function that syncs a matched item's data from its spec\n * (re-runs effects if a loop variable's reference actually changed)\n * @param noWatch When true, skip the per-item shallow `$watch` wrap. The\n * compiler guarantees the `@for` body never writes to its loop variables,\n * and emits an `update` callback that re-runs item effects manually when a\n * loop variable's reference actually changes (via `t_rerun_region_effects`).\n */\nexport default function runListItems(\n\tregion: Region,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\toldItems: ListItem[],\n\tnewSpecs: ListItemSpec[],\n\tcreate: (item: ListItem, before: Node | null) => void,\n\tupdate: (oldItem: ListItem, newSpec: ListItemSpec) => void,\n\tnoWatch?: boolean,\n): ListItem[] {\n\tconst newItems: ListItem[] = Array.from({ length: newSpecs.length });\n\n\t// Capture the region that follows the entire list BEFORE reconciliation —\n\t// `clearRegion` during the messy middle releases old items and nulls their\n\t// chain pointers, so the only safe moment to read the list's trailing\n\t// sibling is now. When the list has items, that sibling lives after the\n\t// old last item's LAST DESCENDANT: an item with an inner `@if`/`@for` owns\n\t// deeper child regions linked off `item.nextRegion`, so we must walk past\n\t// them — reading `oldItems[last].nextRegion` directly would capture the\n\t// item's first child, and the full relink below would then splice the\n\t// child into its own subtree (e.g. `if.nextRegion = if`), creating the\n\t// cycle that hangs the relink walk. When the list is empty, the sibling\n\t// lives on the list region's own `nextRegion` (set by\n\t// `pushRegion(region, true)` on first mount, or by a prior empty-list pass\n\t// through the relink below).\n\tlet nextSibling: Region | null;\n\tif (oldItems.length > 0) {\n\t\tconst lastOld = oldItems[oldItems.length - 1]!;\n\t\tnextSibling = lastOld.nextRegion;\n\t\twhile (nextSibling !== null && nextSibling.depth > lastOld.depth) {\n\t\t\tnextSibling = nextSibling.nextRegion;\n\t\t}\n\t} else {\n\t\tnextSibling = region.nextRegion;\n\t}\n\n\tlet oldStart = 0;\n\tlet oldEnd = oldItems.length - 1;\n\tlet newStart = 0;\n\tlet newEnd = newSpecs.length - 1;\n\n\t// Whether any item was mounted or moved during reconciliation. Mounts\n\t// produce items with null chain pointers (from `newListItem`); moves leave\n\t// an item's chain pointers pointing at its OLD neighbours. Both invalidate\n\t// the incremental relink fast path below. Pure updates and pure clears do\n\t// NOT set this: `update` only re-runs effects within an item's own subtree\n\t// (nested @if/@for push/pop and clearRegion splices preserve the sibling\n\t// links), and `clearRegion` splices the cleared item out and re-links its\n\t// neighbours, so the survivor chain stays correct without a relink.\n\tlet chainNeedsRelink = false;\n\n\t// 1. Fast path: peel off matching heads/tails and boundary rotations\n\t// (head→tail / tail→head) one item at a time, without building a\n\t// keymap. This handles append / prepend / swap / rotate and the\n\t// common-prefix/suffix portions of any change in O(1) per item.\n\t// rotateb/rotatef land here entirely (no keymap, no LIS). When no\n\t// boundary key matches, break and fall through to the LIS pass for\n\t// the messy middle (displace/shuffle). On a match we REUSE the old\n\t// ListItem (DOM nodes, effects, depth already correct) and just call\n\t// `update` to sync the spec's data references.\n\twhile (oldStart <= oldEnd && newStart <= newEnd) {\n\t\tif (oldItems[oldStart]!.key === newSpecs[newStart]!.key) {\n\t\t\t// common head — reuse the survivor in place\n\t\t\tconst item = oldItems[oldStart]!;\n\t\t\tupdate(item, newSpecs[newStart]!);\n\t\t\tnewItems[newStart] = item;\n\t\t\toldStart++;\n\t\t\tnewStart++;\n\t\t} else if (oldItems[oldEnd]!.key === newSpecs[newEnd]!.key) {\n\t\t\t// common tail — reuse the survivor in place\n\t\t\tconst item = oldItems[oldEnd]!;\n\t\t\tupdate(item, newSpecs[newEnd]!);\n\t\t\tnewItems[newEnd] = item;\n\t\t\toldEnd--;\n\t\t\tnewEnd--;\n\t\t} else if (oldItems[oldStart]!.key === newSpecs[newEnd]!.key) {\n\t\t\t// rotated head → tail: move the old head to just past the old tail\n\t\t\tconst item = oldItems[oldStart]!;\n\t\t\tmoveRegion(parent, item, oldItems[oldEnd]!.endNode?.nextSibling ?? anchor);\n\t\t\tchainNeedsRelink = true;\n\t\t\tupdate(item, newSpecs[newEnd]!);\n\t\t\tnewItems[newEnd] = item;\n\t\t\toldStart++;\n\t\t\tnewEnd--;\n\t\t} else if (oldItems[oldEnd]!.key === newSpecs[newStart]!.key) {\n\t\t\t// rotated tail → head: move the old tail to just before the old head\n\t\t\tconst item = oldItems[oldEnd]!;\n\t\t\tmoveRegion(parent, item, oldItems[oldStart]!.startNode);\n\t\t\tchainNeedsRelink = true;\n\t\t\tupdate(item, newSpecs[newStart]!);\n\t\t\tnewItems[newStart] = item;\n\t\t\toldEnd--;\n\t\t\tnewStart++;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t// 2. Old middle exhausted → mount remaining new middle (common: append,\n\t// fresh create, or prefix-only change). Insert before the first suffix\n\t// node (or the list anchor if there's no suffix). Guarded on\n\t// `newStart <= newEnd` so a pass fully consumed by the head/tail fast\n\t// path (pure update — nothing mounted) does NOT flag the chain for a\n\t// relink it doesn't need.\n\tif (oldStart > oldEnd && newStart <= newEnd) {\n\t\tconst before = newEnd + 1 < newSpecs.length ? newItems[newEnd + 1]!.startNode : anchor;\n\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\tnewItems[i] = mountSpec(newSpecs[i]!, region, before, create, noWatch);\n\t\t}\n\t\tchainNeedsRelink = true;\n\t}\n\t// 3. New middle exhausted → clear remaining old middle (common: truncate / remove).\n\telse if (newStart > newEnd) {\n\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\tclearRegion(oldItems[i]!);\n\t\t}\n\t}\n\t// 4. Messy middle — LIS-based reconciliation (moves + mounts + clears).\n\telse {\n\t\t// 4a. Build newKey → newIndex for the new middle.\n\t\tconst newKeyToIndex = new Map<unknown, number>();\n\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\tnewKeyToIndex.set(newSpecs[i]!.key, i);\n\t\t}\n\n\t\t// 4b. No-overlap fast path: every old middle key is absent from the new\n\t\t// middle → full replacement. Batch-clear the old middle (reverse, so\n\t\t// each region's DOM is still attached when clearRegion walks it) and\n\t\t// batch-mount the new middle. Avoids the keymap/LIS allocation for\n\t\t// the common \"replace all\" / \"rebuild from scratch\" case (e.g. `run`,\n\t\t// `runlots`).\n\t\tlet anyOverlap = false;\n\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\tif (newKeyToIndex.has(oldItems[i]!.key)) {\n\t\t\t\tanyOverlap = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!anyOverlap) {\n\t\t\tconst lastOld = oldItems[oldEnd];\n\t\t\tlet before = (lastOld?.endNode?.nextSibling ?? anchor) as Node | null;\n\t\t\tfor (let i = oldEnd; i >= oldStart; i--) {\n\t\t\t\tclearRegion(oldItems[i]!);\n\t\t\t}\n\t\t\tfor (let i = newStart; i <= newEnd; i++) {\n\t\t\t\tnewItems[i] = mountSpec(newSpecs[i]!, region, before, create, noWatch);\n\t\t\t\tbefore = newItems[i]!.endNode!.nextSibling;\n\t\t\t}\n\t\t\tchainNeedsRelink = true;\n\t\t} else {\n\t\t\t// 4c. Walk the old middle: reuse matches into their new positions\n\t\t\t// (via update) and clear the rest. `newIndexToOld[i] = oldIndex\n\t\t\t// + 1` (0 marks a new slot that has no matching old item and\n\t\t\t// must be mounted).\n\t\t\tconst newMidLen = newEnd - newStart + 1;\n\t\t\tconst newIndexToOld = Array.from({ length: newMidLen }).fill(0) as number[];\n\t\t\tfor (let i = oldStart; i <= oldEnd; i++) {\n\t\t\t\tconst oldItem = oldItems[i]!;\n\t\t\t\tconst newIdx = newKeyToIndex.get(oldItem.key);\n\t\t\t\tif (newIdx !== undefined) {\n\t\t\t\t\tnewIndexToOld[newIdx - newStart] = i + 1;\n\t\t\t\t\tupdate(oldItem, newSpecs[newIdx]!);\n\t\t\t\t\tnewItems[newIdx] = oldItem;\n\t\t\t\t} else {\n\t\t\t\t\tclearRegion(oldItem);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 4d. LIS of `newIndexToOld` → indices of items already in correct\n\t\t\t// relative order (they stay; everything else moves or mounts).\n\t\t\tconst seq = getSequence(newIndexToOld);\n\n\t\t\t// 4e. Move/mount right-to-left. The right neighbour (newIdx+1) was\n\t\t\t// placed in the previous iteration (or is a patched suffix\n\t\t\t// item), so its `startNode` is the correct insertion anchor.\n\t\t\tlet j = seq.length - 1;\n\t\t\tfor (let i = newMidLen - 1; i >= 0; i--) {\n\t\t\t\tconst newIdx = newStart + i;\n\t\t\t\tconst before = newIdx + 1 < newSpecs.length ? newItems[newIdx + 1]!.startNode : anchor;\n\t\t\t\tif (newIndexToOld[i] === 0) {\n\t\t\t\t\t// No matching old item → mount.\n\t\t\t\t\tnewItems[newIdx] = mountSpec(newSpecs[newIdx]!, region, before, create, noWatch);\n\t\t\t\t\tchainNeedsRelink = true;\n\t\t\t\t} else if (j < 0 || i !== seq[j]) {\n\t\t\t\t\t// Not in the LIS → move to its new position.\n\t\t\t\t\tmoveRegion(parent, newItems[newIdx]!, before);\n\t\t\t\t\tchainNeedsRelink = true;\n\t\t\t\t} else {\n\t\t\t\t\t// In the LIS → already in correct relative order.\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// 5. Relink the sibling region chain across the final items, in order.\n\t// Nothing during reconciliation reads `previousRegion`/`nextRegion`\n\t// (moves and mounts use DOM `startNode`/`endNode`; `clearRegion` walks\n\t// each cleared region's own subtree and unlinks the cleared node from\n\t// its then-current neighbours), so a single end-of-pass relink from the\n\t// final `newItems` order is correct regardless of which path produced\n\t// it. This replaces the old design where `buildItems` pre-linked the\n\t// chain and `transferListItemData` copied it field-by-field.\n\t//\n\t// The chain is a flat doubly-linked list in render order, with `depth`\n\t// marking nesting. A @for item at depth D may own descendant regions\n\t// (e.g. an `@if` body) at D+1 linked off `item.nextRegion`. So siblings\n\t// must link through each item's LAST DESCENDANT (walk `nextRegion` while\n\t// it's deeper than the item), not through the item itself — otherwise\n\t// the item→child link gets overwritten and `clearRegion` can no longer\n\t// walk the subtree to run cleanups on removal.\n\t//\n\t// FAST PATH (incremental end-of-pass relink): when NO item was mounted\n\t// or moved (`chainNeedsRelink === false`), the survivor chain is already\n\t// correct. `clearRegion` splices each cleared item out and re-links its\n\t// neighbours; `update` only re-runs effects within an item's own subtree\n\t// (a nested @if/@for branch switch pushes/clears CHILD regions, which\n\t// `pushRegion`/`clearRegion` keep spliced correctly into the chain, so\n\t// the item's sibling links — and its tail link to the next sibling — are\n\t// preserved). So the head link (`region.nextRegion`), every inter-item\n\t// link, and the tail link (`lastDescendant → nextSibling`) are all still\n\t// valid. The only write still required is publishing\n\t// `context.previousRegion` for whatever region gets pushed after us,\n\t// which the full relink would overwrite anyway. This turns a 1000-row\n\t// `removefirst`/`removeevery10` (pure-removal shapes) from a 1000-item\n\t// relink walk into an O(1) tail-fixup — matching octane's one-pointer\n\t// patch on the same shapes.\n\tif (!chainNeedsRelink && newItems.length > 0) {\n\t\tlet lastRegion: Region = newItems[newItems.length - 1]!;\n\t\tlet next: Region | null = lastRegion.nextRegion;\n\t\twhile (next !== null && next.depth > lastRegion.depth) {\n\t\t\tlastRegion = next;\n\t\t\tnext = next.nextRegion;\n\t\t}\n\t\tcontext.previousRegion = lastRegion;\n\t\treturn newItems;\n\t}\n\n\tif (newItems.length > 0) {\n\t\tlet prevTail: Region = region;\n\t\tfor (let i = 0; i < newItems.length; i++) {\n\t\t\tconst item = newItems[i]!;\n\t\t\titem.previousRegion = prevTail;\n\t\t\tprevTail.nextRegion = item;\n\t\t\t// Advance to the last region in this item's subtree: follow\n\t\t\t// `nextRegion` as long as it descends deeper than the item. A leaf\n\t\t\t// row has no descendants, so `last` stays `item` and the next\n\t\t\t// iteration's `prevTail.nextRegion = nextItem` updates the item's\n\t\t\t// own `nextRegion` (preserving the old sibling-only behaviour).\n\t\t\tlet last: Region = item;\n\t\t\tlet next: Region | null = item.nextRegion;\n\t\t\twhile (next !== null && next.depth > item.depth) {\n\t\t\t\tlast = next;\n\t\t\t\tnext = next.nextRegion;\n\t\t\t}\n\t\t\tprevTail = last;\n\t\t}\n\t\t// `prevTail` is now the very last region in the list. Link it to\n\t\t// whatever followed the list, and publish it as the insertion point\n\t\t// for the next sibling region pushed after us.\n\t\tprevTail.nextRegion = nextSibling;\n\t\tif (nextSibling !== null) {\n\t\t\tnextSibling.previousRegion = prevTail;\n\t\t}\n\t\tregion.nextRegion = newItems[0]!;\n\t\tcontext.previousRegion = prevTail;\n\t} else {\n\t\t// Empty list: link the list region directly to its trailing sibling,\n\t\t// and publish the list region itself as the insertion point for the\n\t\t// next sibling region pushed after us.\n\t\tregion.nextRegion = nextSibling;\n\t\tif (nextSibling !== null) {\n\t\t\tnextSibling.previousRegion = region;\n\t\t}\n\t\tcontext.previousRegion = region;\n\t}\n\n\treturn newItems;\n}\n","import devContext from \"../dev/devContext\";\nimport type ListItem from \"../types/ListItem\";\nimport type ListItemSpec from \"../types/ListItemSpec\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport checkListKeys from \"./checkListKeys\";\nimport context from \"./context\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport runListItems from \"./runListItems\";\n\n/**\n * Runs a `for` control statement\n * @param buildItems A function that returns the current list of lightweight\n * `{key, data}` specs (one per row of the source data)\n * @param create A function that creates the control statement's branches\n * @param noWatch When true, the compiler has determined the `@for` body never\n * writes to its loop variables, so each item's `data` bag can be left\n * unwrapped (skipping the per-item shallow `$watch` Proxy + ProxyData +\n * signals Map allocations). The compiler-emitted `update` callback is then\n * responsible for re-running item effects when a loop variable's reference\n * actually changes (via `t_rerun_region_effects`).\n */\nexport default function runList(\n\tregion: Region,\n\tparent: ParentNode,\n\tanchor: Node | null,\n\tbuildItems: () => ListItemSpec[],\n\tcreate: (item: ListItem, anchor: Node | null) => void,\n\tupdate: (oldItem: ListItem, newSpec: ListItemSpec) => void,\n\tnoWatch?: boolean,\n): void {\n\tlet first = true;\n\tlet listItems: ListItem[] = [];\n\n\t// Run the list in an effect\n\t$run(function runList() {\n\t\t// If this region has been cleared (e.g. a parent @if switched to a\n\t\t// different branch), skip the update — the list will be re-created\n\t\t// when the parent branch re-renders\n\t\tif (region.depth === -2) return;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Build the array of lightweight {key, data} specs for the new data\n\t\tconst newSpecs = buildItems();\n\n\t\t// DEV: surface duplicate keys, which the reconciler matches\n\t\t// first-match-wins and would otherwise silently desync the DOM.\n\t\tif (devContext.enabled) {\n\t\t\tcheckListKeys(region, newSpecs);\n\t\t}\n\n\t\t// Do NOT re-run the list for properties accessed while updating its\n\t\t// items. E.g. we want to re-run the list for `@for (item of $items)`\n\t\t// (in buildItems, above) but not for `<span>{item.id}</span>` (in\n\t\t// runListItems, below)\n\t\tcontext.activeTarget = null;\n\n\t\t// Reconcile: reuse old ListItems for survivors, mount fresh ones for\n\t\t// new keys, clear dropped ones. Returns the new live list, which we\n\t\t// keep for the next run.\n\t\tlistItems = runListItems(region, parent, anchor, listItems, newSpecs, create, update, noWatch);\n\n\t\tpopRegion(oldRegion);\n\t});\n}\n","import type Effect from \"../types/Effect\";\nimport type AwaitBoundary from \"../types/AwaitBoundary\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport trackSignal from \"../watch/trackSignal\";\nimport context from \"./context\";\nimport isCommentNode from \"./isCommentNode\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport runControlBranch from \"./runControlBranch\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Comment prefix marking the embedded `source: \"server\"` values that the\n * server writes after a resolved boundary's anchor (`<!--t-await:[...]-->`,\n * see ASYNC.md → \"Server rendering\").\n */\nconst SERVER_VALUES_PREFIX = \"t-await:\";\n\n/**\n * Renders an `@await` boundary. On the first run, content is rendered\n * speculatively; if any read inside suspends (`didSuspend`), the boundary\n * discards the partial render and shows the `with` branch instead.\n *\n * Hydration of a server-resolved boundary (ASYNC.md → \"Server rendering\"): when the server\n * shipped resolved content, its values ride in a payload comment after the\n * anchor. The boundary renders the content branch *with* hydration enabled\n * and `$async` seeds its computeds from the payload, so the server's HTML is\n * adopted directly — no speculative render, no `with`-branch dance, no\n * fallback flash.\n *\n * Fine-grained updates: on subsequent runs the boundary only decides whether\n * to SWITCH branches. It does so from its `pending` set — the suspended\n * computeds recorded by `suspendRead` — dropping entries that resolved and\n * re-subscribing the still-suspended ones (a re-run deactivates all of the\n * effect's source subscriptions, so they must be re-tracked to survive\n * `clearSources`). That check is O(pending reads), not O(all sources), and\n * non-suspend dependency changes inside content are left to the child\n * effects that read them — the boundary isn't re-run by them at all.\n *\n * Stale-while-revalidate (ASYNC.md): once content has been produced\n * (`hasContent`), a subsequent suspend during a refresh does NOT switch to\n * the `with` branch — the boundary keeps the stale content mounted. `$async`\n * retains the previous resolved value (`Computed.staleValue`) and\n * `suspendRead` returns it, so child effects keep displaying the old value\n * until the new promise resolves and updates them in place. The `with` branch\n * is shown only on the first load, before content has ever rendered\n * successfully.\n *\n * @param renderContent Builds the content children (may read $async getters).\n * @param renderWith Builds the `with`-branch children, or null for empty.\n */\nexport default function runAwait(\n\tregion: Region,\n\tanchor: Node | null,\n\trenderContent: (anchor: Node | null) => void,\n\trenderWith: ((anchor: Node | null) => void) | null,\n\tname?: string,\n): void {\n\tconst boundary: AwaitBoundary = {\n\t\tsuspended: false,\n\t\tpending: new Set(),\n\t\teffect: null,\n\t};\n\tlet index = -1; // -1 = initial, 0 = content, 1 = with\n\tlet first = true;\n\tlet hasContent = false; // true once content has rendered without suspending\n\tlet theEffect: Effect | null = null;\n\n\t// Resolved values embedded by the server for this boundary, read once\n\t// during hydration\n\tlet serverValues: any[] | null = null;\n\tif (context.hydrationNode !== null && anchor !== null) {\n\t\tconst next = anchor.nextSibling;\n\t\tif (next !== null && isCommentNode(next) && next.data.startsWith(SERVER_VALUES_PREFIX)) {\n\t\t\ttry {\n\t\t\t\tserverValues = JSON.parse(next.data.substring(SERVER_VALUES_PREFIX.length));\n\t\t\t} catch {\n\t\t\t\tserverValues = null;\n\t\t\t}\n\t\t\tnext.remove();\n\t\t}\n\t}\n\n\tconst gen = (region.generation = (region.generation ?? 0) + 1);\n\n\t$run(function runAwait() {\n\t\tif (region.generation !== gen) return;\n\n\t\t// On the first call, $run hasn't returned yet so theEffect is null.\n\t\t// runEffect sets context.activeTarget to this effect before calling\n\t\t// run(), so capture it here for suspendRead's subscription.\n\t\ttheEffect = context.activeTarget as Effect;\n\t\tboundary.effect = theEffect;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Render a branch into a fresh child region, clearing the old branch\n\t\tconst renderBranch = (targetIndex: number, fn: (anchor: Node | null) => void) => {\n\t\t\trunControlBranch(region, index, targetIndex);\n\t\t\t// runControlBranch may have cleared the previous branch, leaving\n\t\t\t// context.previousRegion pointing at a released region. Reset it\n\t\t\t// to the await region so the new branch links correctly.\n\t\t\tcontext.previousRegion = region;\n\t\t\tconst branchRegion = newRegion(targetIndex === 0 ? \"await_content\" : \"await_with\");\n\t\t\tconst oldR = pushRegion(branchRegion, true);\n\t\t\tfn(anchor);\n\t\t\tpopRegion(oldR);\n\t\t\tindex = targetIndex;\n\t\t};\n\n\t\t// Render content with boundary context active; if it suspends and a\n\t\t// with-branch exists, immediately switch to it\n\t\tconst attemptContent = () => {\n\t\t\tconst oldBoundary = context.awaitBoundary;\n\t\t\tcontext.awaitBoundary = boundary;\n\t\t\tboundary.suspended = false;\n\n\t\t\t// During hydration of a server-resolved boundary, the values\n\t\t\t// embedded by the server are made available to `$async` while the\n\t\t\t// content branch renders, and hydration stays enabled so the\n\t\t\t// content adopts the server's nodes directly.\n\t\t\t//\n\t\t\t// Otherwise (a client-fetch boundary), hydration is temporarily\n\t\t\t// disabled: the speculative content render creates fresh nodes\n\t\t\t// instead of reusing the server's with-branch nodes (which would\n\t\t\t// be destroyed when content is cleared on suspend, leaving\n\t\t\t// nothing for the with-branch to hydrate against).\n\t\t\tconst savedHydration = context.hydrationNode;\n\t\t\tconst savedServerValues = context.serverValues;\n\t\t\tif (serverValues !== null && savedHydration !== null) {\n\t\t\t\tcontext.serverValues = { values: serverValues, index: 0 };\n\t\t\t} else if (savedHydration !== null) {\n\t\t\t\tcontext.hydrationNode = null;\n\t\t\t}\n\n\t\t\trenderBranch(0, renderContent);\n\n\t\t\tcontext.hydrationNode = savedHydration;\n\t\t\tcontext.serverValues = savedServerValues;\n\n\t\t\tcontext.awaitBoundary = oldBoundary;\n\n\t\t\tif (boundary.suspended && renderWith !== null) {\n\t\t\t\trenderBranch(1, renderWith);\n\t\t\t} else if (!boundary.suspended) {\n\t\t\t\t// Content rendered without suspending — mark it so a later\n\t\t\t\t// refresh suspend keeps showing stale content (§6.2).\n\t\t\t\thasContent = true;\n\t\t\t}\n\t\t};\n\n\t\tif (theEffect === null) {\n\t\t\t// First run (theEffect is assigned after $run returns): render\n\t\t\t// content speculatively to detect suspend\n\t\t\tattemptContent();\n\t\t} else {\n\t\t\t// Subsequent run: refresh the pending set — resolved computeds\n\t\t\t// drop out, still-suspended ones re-subscribe the boundary effect\n\t\t\t// (checkEffect deactivated every source subscription before this\n\t\t\t// run; without re-tracking, clearSources would detach the\n\t\t\t// boundary from its pending reads and it would never re-run when\n\t\t\t// they resolve). Only switch branches when the suspend state\n\t\t\t// actually changed.\n\t\t\tlet suspended = false;\n\t\t\tfor (const signal of boundary.pending) {\n\t\t\t\tif (signal.didSuspend) {\n\t\t\t\t\tsuspended = true;\n\t\t\t\t\ttrackSignal(signal);\n\t\t\t\t} else {\n\t\t\t\t\tboundary.pending.delete(signal);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst targetIndex = suspended ? 1 : 0;\n\n\t\t\tif (targetIndex !== index) {\n\t\t\t\tif (targetIndex === 0) {\n\t\t\t\t\t// Switching to content — render and check for re-suspend\n\t\t\t\t\tattemptContent();\n\t\t\t\t} else if (!hasContent) {\n\t\t\t\t\t// First-load suspend (content never shown): show the\n\t\t\t\t\t// with-branch. When hasContent, a refresh suspend keeps\n\t\t\t\t\t// the stale content mounted instead of flashing the\n\t\t\t\t\t// with-branch — stale-while-revalidate (ASYNC.md).\n\t\t\t\t\t// Child effects read the retained value via $async's\n\t\t\t\t\t// staleValue and re-render with the new value when the\n\t\t\t\t\t// promise resolves.\n\t\t\t\t\tif (renderWith !== null) {\n\t\t\t\t\t\trenderBranch(1, renderWith);\n\t\t\t\t\t} else {\n\t\t\t\t\t\trunControlBranch(region, index, 1);\n\t\t\t\t\t\tindex = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later run that switched branches may have rendered content\n\t\t// before our anchor that an ancestor's node window doesn't cover —\n\t\t// widen those windows so clearing the ancestor can't orphan the\n\t\t// content (see widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\t}, name);\n}\n","import context from \"./context\";\n\n/**\n * Snapshots the hydration cursor so a `@try` branch's partial hydration walk\n * can be rewound if the branch throws and the `@catch` branch renders instead.\n *\n * @returns The current hydration cursor node, or `null` when not hydrating.\n */\nexport default function saveHydration(): ChildNode | null {\n\treturn context.hydrationNode;\n}\n","import type Effect from \"../types/Effect\";\nimport type ErrorBoundary from \"../types/ErrorBoundary\";\nimport type Region from \"../types/Region\";\nimport $run from \"../watch/$run\";\nimport trackSignal from \"../watch/trackSignal\";\nimport context from \"./context\";\nimport newRegion from \"./newRegion\";\nimport popRegion from \"./popRegion\";\nimport pushRegion from \"./pushRegion\";\nimport restoreHydration from \"./restoreHydration\";\nimport runControlBranch from \"./runControlBranch\";\nimport saveHydration from \"./saveHydration\";\nimport widenAncestorsAtAnchor from \"./widenAncestorsAtAnchor\";\n\n/**\n * Renders a `@try`/`@catch` group, or a top-level `@error` block (which the\n * compiler wraps around the whole render).\n *\n * Like `runAwait`, the boundary is a control effect that renders one branch\n * at a time into a fresh child region (`runControlBranch` clears the old\n * branch on switch). Unlike the old compiled form, the try/catch lives in\n * this runtime, which gives it three capabilities the compiled form lacked:\n *\n * - **Effect-rerun error routing.** The boundary registers itself on its\n * region (`region.errorBoundary`); when an effect inside the try content\n * throws on a later re-run, `triggerEffects` → `routeEffectError` stores\n * the error here and force re-runs the boundary effect, which renders the\n * catch branch with it.\n * - **Recovery outside direct reads.** Reactive reads wrapped in nested\n * `$run` effects (text/attribute interpolation) are tracked by those\n * effects, not the boundary. When an error is routed, the boundary holds\n * the erroring effect's source signals (`heldSignals`) and re-subscribes\n * to them on every run that shows the catch branch, so a later change\n * re-attempts the try branch.\n * - **Top-level `@error` recovery.** Because the whole render is a\n * re-runnable branch, a later re-render error (from a nested control\n * re-running after a prop change) is caught by the same routing, and a\n * recovery re-render clears the error content and restores the normal\n * content.\n *\n * Semantics preserved from the compiled form:\n *\n * - Synchronous build errors in the try content render the catch branch\n * (rewinding the hydration cursor and restoring the control region, which\n * the failed partial build left active).\n * - While the try branch is showing, a boundary re-run with no routed error\n * does NOT rebuild it (`runControlBranch` same-index skip) — exactly like\n * `@if`/`@switch` branches.\n * - While the catch branch is showing, any boundary re-run re-attempts the\n * try branch (the recovery path for errors read directly by the boundary\n * effect, e.g. via `@const`).\n * - With no catch branch, errors propagate up to the nearest outer boundary\n * and no boundary is registered on the region.\n *\n * @param renderTry Builds the try content. May read reactive state.\n * @param renderCatch Builds the catch content, or null for `@try` without\n * `@catch`. Receives the error (the `@catch (err)` variable).\n */\nexport default function runTry(\n\tregion: Region,\n\tanchor: Node | null,\n\trenderTry: (anchor: Node | null) => void,\n\trenderCatch: ((anchor: Node | null, error: any) => void) | null,\n\tname?: string,\n): void {\n\tconst boundary: ErrorBoundary = {\n\t\terror: undefined,\n\t\thasError: false,\n\t\teffect: null,\n\t\theldSignals: null,\n\t};\n\tif (renderCatch !== null) {\n\t\tregion.errorBoundary = boundary;\n\t}\n\n\tlet index = -1; // -1 = initial, 0 = try, 1 = catch\n\tlet first = true;\n\n\tconst gen = (region.generation = (region.generation ?? 0) + 1);\n\n\t$run(function runTry() {\n\t\t// If this effect was created by a previous runTry call for the same\n\t\t// region, it is stale and should not execute\n\t\tif (region.generation !== gen) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst theEffect = context.activeTarget as Effect;\n\t\tboundary.effect = theEffect;\n\n\t\tconst oldRegion = pushRegion(region, first);\n\t\tfirst = false;\n\n\t\t// Render a branch into a fresh child region, clearing the old branch\n\t\tconst renderBranch = (targetIndex: number, fn: (anchor: Node | null) => void) => {\n\t\t\trunControlBranch(region, index, targetIndex);\n\t\t\t// runControlBranch may have cleared the previous branch, leaving\n\t\t\t// context.previousRegion pointing at a released region. Reset it\n\t\t\t// to the boundary region so the new branch links correctly.\n\t\t\tcontext.previousRegion = region;\n\t\t\tconst branchRegion = newRegion(targetIndex === 0 ? \"try\" : \"catch\");\n\t\t\tconst oldR = pushRegion(branchRegion, true);\n\t\t\tfn(anchor);\n\t\t\tpopRegion(oldR);\n\t\t\tindex = targetIndex;\n\t\t};\n\n\t\t// (Re-)subscribe the boundary effect to the held signals. Called\n\t\t// while the boundary effect is the active target, so the\n\t\t// subscriptions are active and survive `clearSources`\n\t\tconst holdSignals = () => {\n\t\t\tif (boundary.heldSignals === null || theEffect === null) return;\n\t\t\tfor (const signal of boundary.heldSignals) {\n\t\t\t\ttrackSignal(signal);\n\t\t\t}\n\t\t};\n\n\t\t// An effect error routed from triggerEffects renders the catch branch\n\t\t// via the stored boundary error\n\t\tconst hasRoutedError = boundary.hasError;\n\t\tconst routedError = boundary.error;\n\t\tboundary.hasError = false;\n\n\t\tif (hasRoutedError && renderCatch !== null) {\n\t\t\t// Force a re-render of the catch branch (the try branch's content\n\t\t\t// — including the erroring effect — is cleared by the branch\n\t\t\t// switch), then hold the routed signals for recovery\n\t\t\tindex = -1;\n\t\t\trenderBranch(1, (a) => renderCatch(a, routedError));\n\t\t\tholdSignals();\n\t\t} else if (index !== 0) {\n\t\t\t// First run, or the catch branch is showing and a dependency\n\t\t\t// changed: (re-)attempt the try content\n\t\t\tconst snapshot = saveHydration();\n\t\t\ttry {\n\t\t\t\trenderBranch(0, renderTry);\n\t\t\t\t// The try attempt succeeded: stop holding routed signals (the\n\t\t\t\t// attempt's own reads now drive future re-runs)\n\t\t\t\tboundary.heldSignals = null;\n\t\t\t} catch (err) {\n\t\t\t\t// The failed attempt left its branch region active/stale and\n\t\t\t\t// may have advanced the hydration cursor. Restore the control\n\t\t\t\t// region and rewind the cursor before rendering the catch\n\t\t\t\t// branch (the branch switch below clears the partial try\n\t\t\t\t// content)\n\t\t\t\tpushRegion(region);\n\t\t\t\trestoreHydration(snapshot);\n\t\t\t\tif (renderCatch !== null) {\n\t\t\t\t\tindex = -1;\n\t\t\t\t\trenderBranch(1, (a) => renderCatch(a, err));\n\t\t\t\t\tholdSignals();\n\t\t\t\t} else {\n\t\t\t\t\t// No catch branch: propagate to the nearest outer boundary\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpopRegion(oldRegion);\n\n\t\t// A later re-run may have rendered content before our anchor that an\n\t\t// ancestor's node window doesn't cover — widen those windows so\n\t\t// clearing the ancestor can't orphan the content (see\n\t\t// widenAncestorsAtAnchor).\n\t\twidenAncestorsAtAnchor(region, anchor);\n\n\t\t// While hydrating, reset the cursor to the boundary's anchor after\n\t\t// its content has been hydrated (see runControl)\n\t\tif (context.hydrationNode !== null && anchor !== null) {\n\t\t\tcontext.hydrationNode = anchor as ChildNode;\n\t\t}\n\t}, name);\n}\n","/**\n * Gets an element from the document head matching the selector, creating and\n * appending a new one if there isn't a match. Used by the code generated for\n * a @head block, so that elements which were server rendered (or rendered by\n * a previously visited page) are adopted rather than duplicated.\n */\nexport default function headElement(tagName: string, selector: string): Element {\n\tif (selector) {\n\t\tconst existing = document.head.querySelector(selector);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\t}\n\tconst element = document.createElement(tagName);\n\tdocument.head.appendChild(element);\n\treturn element;\n}\n","export default function setAttribute(el: Element, name: string, value: any): void {\n\tif (value === false || value === undefined || value === null) {\n\t\tel.removeAttribute(name);\n\t} else {\n\t\tel.setAttribute(name, value);\n\t}\n}\n","import context from \"./context\";\nimport { copyEventListeners } from \"./delegatedEvents\";\n\n// TODO: Should we @toggle this instead? That would call onmount etc again for the new element\n\nexport default function setDynamicElement(el: HTMLElement, tag: string): HTMLElement {\n\t// If hydrating, it should already have been created as the correct element\n\tif (context.hydrationNode !== null) {\n\t\treturn el;\n\t}\n\n\t// Replace the old element with the new element\n\tlet newElement = el.ownerDocument.createElement(tag);\n\tfor (const attr of el.attributes) {\n\t\tnewElement.setAttributeNS(null, attr.name, attr.value);\n\t}\n\t// Carry over event listeners, so a reactive `self` tag change doesn't\n\t// silently drop the element's handlers\n\tcopyEventListeners(el, newElement);\n\tnewElement.replaceChildren(...el.childNodes.values());\n\tel.replaceWith(newElement);\n\n\treturn newElement;\n}\n","import context from \"../render/context\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\n\n/**\n * Runs updates to proxy values in a batch, where the updates are stored in\n * context, and dependent effects are run all at once at the end.\n *\n * @param fn The function containing the batched updates to run.\n */\nexport default function $batch<T>(fn: () => T): T {\n\tif (context.batch > 0) {\n\t\treturn fn();\n\t}\n\n\tbatchStart();\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tbatchEnd();\n\t}\n}\n","import context from \"../render/context\";\nimport type AsyncOptions from \"../types/AsyncOptions\";\nimport type Computed from \"../types/Computed\";\nimport { COMPUTED_TYPE } from \"../types/constants\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport { propagateFromSignal } from \"./propagateSignal\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Caches an async computed value from a thunk that returns a Promise. A peer\n * of `$cache` for async getters: the returned Computed carries a `didSuspend`\n * indicator that the proxy get trap reads to suspend callers until the promise\n * resolves.\n *\n * The thenable check and `.then` wiring live inside `computed.run` (a closure\n * over the computed object), so they fire on both the initial run and every\n * recalculation — `runComputed` and `checkComputed` are unchanged.\n *\n * Hydration seeding (ASYNC.md → \"Server rendering\"): while hydrating the content branch of\n * a boundary whose server HTML embedded resolved `source: \"server\"` values,\n * `context.serverValues` is set, and this read consumes the value at the\n * current position instead of suspending. The thunk still runs — once, in\n * the background — so the getter's dependencies are tracked and later\n * dependency changes re-fetch; the embedded value wins the generation race,\n * so there's no re-fetch wait and no fallback flash.\n *\n * @param fn A thunk returning the Promise to await. Signal reads inside `fn`\n * are tracked, so the fetch re-runs when dependencies change.\n * @param _options Accepted so the same getter source compiles into client and\n * server builds (`source: \"server\"` fetches during SSR); ignored here.\n */\nexport default function $async<T>(fn: () => Promise<T>, _options?: AsyncOptions): T {\n\tif (context.registerComputed === null) {\n\t\tthrow new Error(\"$async must be used in a getter\");\n\t}\n\n\tconst computed: Computed = {\n\t\ttype: COMPUTED_TYPE,\n\t\tisAsync: true,\n\t\tvalue: null,\n\t\trun: null as unknown as () => any,\n\t\tfirstSource: null,\n\t\tfirstTarget: null,\n\t\trecalc: false,\n\t\trunning: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tgeneration: 0,\n\t\thasResolved: false,\n\t\tlastErrored: false,\n\t\tsuspendQuiet: false,\n\t\tstaleValue: undefined,\n\t\trollback: null,\n\t};\n\n\t// The runner wraps the user's thunk: call fn(), and if the result is a\n\t// thenable, set didSuspend + wire the resolve/reject handlers. This runs\n\t// inside runComputed (with activeTarget set for dep tracking) on both the\n\t// initial call and every recalc, so stale resolves are handled by the\n\t// generation guard without any changes to runComputed or checkComputed.\n\t//\n\t// `staleValue` is maintained by the settle handlers below — it always\n\t// holds the last RESOLVED value, cleared on rejection. It is NOT derived\n\t// here from `computed.value`: when changes overlap (a re-suspend while an\n\t// earlier fetch is still in flight), `computed.value` holds that earlier\n\t// run's pending promise, and handing it to readers would render\n\t// \"[object Promise]\" — a superseded generation's value leaking into the\n\t// UI. The settle handlers are generation-guarded, so `staleValue` is\n\t// generation-safe by construction: the read-side token matching the\n\t// resolve-side one (ASYNC.md → \"Generation guards\").\n\tcomputed.run = () => {\n\t\tconst value = fn();\n\t\tif (value !== null && value !== undefined && typeof (value as any).then === \"function\") {\n\t\t\tconst gen = ++computed.generation;\n\t\t\tcomputed.didSuspend = true;\n\t\t\t// Capture the quiet-on-refresh decision at suspend time\n\t\t\t// (ASYNC.md → \"Loud vs quiet\"). `recalc` is still true during a source-driven\n\t\t\t// re-run — `checkComputed` clears it only after `runComputed`\n\t\t\t// returns — so a suspend is quiet iff the computed has resolved\n\t\t\t// before AND this run wasn't triggered by a dependency change\n\t\t\t// (i.e. a silent `$refresh(fn, { silent: true })`).\n\t\t\t// First loads are loud (`hasResolved` is false); dep-change\n\t\t\t// refreshes and loud `$refresh` calls are loud (`recalc` is true).\n\t\t\tcomputed.suspendQuiet = computed.hasResolved && !computed.recalc;\n\t\t\t(value as Promise<T>).then(\n\t\t\t\t(v: T) => {\n\t\t\t\t\tif (computed.generation !== gen) return;\n\t\t\t\t\tcomputed.value = v;\n\t\t\t\t\tcomputed.didSuspend = false;\n\t\t\t\t\tcomputed.hasResolved = true;\n\t\t\t\t\tcomputed.lastErrored = false;\n\t\t\t\t\t// Retain the resolved value for the next refresh suspend\n\t\t\t\t\t// (stale-while-revalidate, ASYNC.md → \"Stale-while-revalidate\")\n\t\t\t\t\tcomputed.staleValue = v;\n\t\t\t\t\tbatchStart();\n\t\t\t\t\tpropagateFromSignal(computed);\n\t\t\t\t\tbatchEnd();\n\t\t\t\t},\n\t\t\t\t(e: any) => {\n\t\t\t\t\tif (computed.generation !== gen) return;\n\t\t\t\t\tcomputed.value = e;\n\t\t\t\t\tcomputed.didError = true;\n\t\t\t\t\tcomputed.didSuspend = false;\n\t\t\t\t\tcomputed.hasResolved = true;\n\t\t\t\t\tcomputed.lastErrored = true;\n\t\t\t\t\t// A retry-after-error re-suspend must not hand the previous\n\t\t\t\t\t// error (or a pre-error value) to readers as \"stale content\"\n\t\t\t\t\tcomputed.staleValue = undefined;\n\t\t\t\t\tbatchStart();\n\t\t\t\t\tpropagateFromSignal(computed);\n\t\t\t\t\tbatchEnd();\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t};\n\n\tcontext.registerComputed(computed);\n\n\trunComputed(computed);\n\n\t// Hydration seeding: the server embedded a resolved value for this read.\n\t// Bump the generation so the background fetch's settle is dropped as\n\t// stale, and surface the embedded value instead — the reader sees the\n\t// server's data immediately\n\tconst serverValues = context.serverValues;\n\tif (serverValues !== null && serverValues.index < serverValues.values.length) {\n\t\tcomputed.generation++;\n\t\tcomputed.didSuspend = false;\n\t\tcomputed.didError = false;\n\t\tcomputed.hasResolved = true;\n\t\tcomputed.lastErrored = false;\n\t\tcomputed.value = serverValues.values[serverValues.index++];\n\t\tcomputed.staleValue = computed.value;\n\t}\n\n\treturn computed.value;\n}\n","import $run from \"./$run\";\n\n/**\n * Establishes two-way reactive sync between matching keys on a state object\n * and a props object.\n *\n * For each key, `$bind` creates:\n * - **Forward sync** (`props → state`): when the parent pushes a new value via\n * `$props[key]`, it flows into `$state[key]`. Skips `undefined` values so\n * that defaults set in the initial `$watch(...)` are preserved when the\n * parent doesn't provide a value.\n * - **Backward sync** (`state → props`): when the component mutates\n * `$state[key]`, the new value is written back to `$props[key]`, which the\n * call site's `&key={...}` binding picks up and propagates to the parent.\n *\n * Same-value writes are no-ops (handled by the proxy layer), so two-way sync\n * stabilises without infinite loops.\n *\n * `$bind` syncs same-named keys, so the key must exist on the state object.\n * A state key named differently from the prop (e.g. `values` against a\n * `value` prop) would silently do nothing -- the binding reads and writes\n * keys that nothing else touches -- which is almost impossible to debug. The\n * key is therefore required to exist on the state object, and `$bind` throws\n * at setup otherwise.\n *\n * The prop does *not* need to exist on `props` yet: when the parent doesn't\n * pass an optional prop, the compiled props object has no key for it, and\n * the binding is simply inert (uncontrolled mode) until a value is pushed.\n *\n * @param state The component's reactive state (created via `$watch`).\n * @param props The component's `$props` proxy. When `undefined` (component\n * called with no props), `$bind` does nothing.\n * @param keys Keys to sync. Each key must exist on `state`.\n * @throws When a key does not exist on the state object.\n */\nexport default function $bind(\n\tstate: Record<PropertyKey, any>,\n\tprops: Record<PropertyKey, any> | undefined,\n\t...keys: (string | string[])[]\n): void {\n\tif (props === undefined) return;\n\tfor (let key of keys.flat()) {\n\t\tif (!(key in state)) {\n\t\t\tthrow new Error(\n\t\t\t\t`$bind: the key \"${key}\" does not exist on the state object. ` +\n\t\t\t\t\t`$bind syncs same-named keys, so the state object must declare it (e.g. in the initial $watch).`,\n\t\t\t);\n\t\t}\n\t\t// Forward: props → state (skip undefined so $watch defaults survive)\n\t\t$run(() => {\n\t\t\tconst v = props[key];\n\t\t\tif (v !== undefined) state[key] = v;\n\t\t}, `bind:forward:${key}`);\n\t\t// Backward: state → props (skip the initial write — there's nothing to\n\t\t// propagate yet, and echoing the initial state into props would make\n\t\t// the forward effect fire spuriously and clobber state changes that\n\t\t// happen during mount). The read still subscribes us to state[key].\n\t\tlet firstBackward = true;\n\t\t$run(() => {\n\t\t\tconst value = state[key];\n\t\t\tif (!firstBackward) props[key] = value;\n\t\t\tfirstBackward = false;\n\t\t}, `bind:backward:${key}`);\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport { COMPUTED_TYPE } from \"../types/constants\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Caches a computed value from signals accessed in a property getter.\n *\n * @param fn The function containing the signals to compute and cache.\n */\nexport default function $cache<T>(fn: () => T): T {\n\tif (context.registerComputed === null) {\n\t\tif (typeof window !== \"undefined\") {\n\t\t\tthrow new Error(\"$cache must be used in a getter\");\n\t\t}\n\t\t// Server render: getters are evaluated without reactive tracking (state\n\t\t// objects aren't proxied), so there is nothing to register with. Just\n\t\t// evaluate the function — this happens when a shared helper that uses\n\t\t// $cache (e.g. in @torpor/ui) is rendered on the server\n\t\treturn fn();\n\t}\n\n\tlet computed: Computed = {\n\t\ttype: COMPUTED_TYPE,\n\t\tisAsync: false,\n\t\tvalue: null,\n\t\trun: fn,\n\t\tfirstSource: null,\n\t\tfirstTarget: null,\n\t\trecalc: false,\n\t\trunning: false,\n\t\tdidError: false,\n\t\tdidSuspend: false,\n\t\tgeneration: 0,\n\t\thasResolved: false,\n\t\tlastErrored: false,\n\t\tsuspendQuiet: false,\n\t\tstaleValue: undefined,\n\t\trollback: null,\n\t\t//name: dev.effectName(fn),\n\t};\n\n\tcontext.registerComputed(computed);\n\n\trunComputed(computed);\n\n\t// Guard: a Promise return from $cache would be cached as a raw value and\n\t// never suspend — the value would render as [object Promise]. This runtime\n\t// guard is the enforcement (torpor doesn't parse JS statically, so there's\n\t// no compiler check — ASYNC.md → \"The promise indicator\"); it fires on the getter's first read.\n\tif (\n\t\tcomputed.value !== null &&\n\t\tcomputed.value !== undefined &&\n\t\ttypeof (computed.value as any).then === \"function\"\n\t) {\n\t\tthrow new Error(\"$cache returned a Promise — use $async for async getters\");\n\t}\n\n\treturn computed.value;\n}\n","import context from \"../render/context\";\nimport type Cleanup from \"../types/Cleanup\";\n\n/**\n * Runs `fn` once after the component is mounted to the DOM. May return a\n * cleanup function that runs on unmount / region clear.\n *\n * The callback is **not reactive**: it runs exactly once per mount, and\n * reactive values it reads are not tracked. To set up something that should\n * keep updating, wrap the reactive part in `$run`:\n *\n * ```ts\n * $onmount(() => {\n * \t$run(() => {\n * \t\tlabel.textContent = $state.count > 0 ? \"+\" : \"\";\n * \t});\n * });\n * ```\n *\n * The element-level equivalent is the `onmount` attribute:\n * `<input onmount={(el) => el.focus()} />`.\n *\n * @param fn The function to run, which may return a cleanup function\n */\nexport default function $onmount(fn: () => Cleanup | void): void {\n\tcontext.mountEffects.push({\n\t\tregion: context.activeRegion,\n\t\tfn,\n\t});\n}\n","import context from \"../render/context\";\n\n/**\n * Returns `true` if any value read inside `fn` is currently suspended in a\n * \"loud\" way — a `$async` getter whose promise hasn't resolved yet. A reactive\n * query for inline \"loading…\" indicators: the calling effect subscribes to the\n * same computeds, so `$pending` re-evaluates when they resolve.\n *\n * Uses a \"peek mode\" internally: reads during `fn` are tracked for\n * subscription but don't propagate taint or notify a `@await` boundary.\n * This lets `$pending` return a plain boolean without itself suspending.\n *\n * Quiet-on-refresh semantics (ASYNC.md → \"Loud vs quiet\"): a suspend is *quiet* — and\n * therefore `$pending` returns `false` for it — when the computed has resolved\n * before and the re-fetch was a *silent* `$refresh(fn, { silent: true })` (a\n * bare refresh with no tracked dependency change, used for background\n * revalidation). This matches Solid's stale-while-revalidate default: quietly\n * re-asking the same question shouldn't ping the user. First loads and\n * dependency-change refreshes are loud (`true`), as is the default (loud)\n * `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via\n * `suspendQuiet` (computed in `$async`'s run from `hasResolved` and `recalc`).\n *\n * @param fn A function that reads the reactive values to check.\n */\nexport default function $pending(fn: () => any): boolean {\n\tconst oldPeek = context.suspendPeek;\n\tcontext.suspendPeek = true;\n\tcontext.suspendPeekHit = false;\n\ttry {\n\t\tfn();\n\t\treturn context.suspendPeekHit;\n\t} finally {\n\t\tcontext.suspendPeek = oldPeek;\n\t}\n}\n","import context from \"../render/context\";\nimport type Computed from \"../types/Computed\";\nimport batchEnd from \"./batchEnd\";\nimport batchStart from \"./batchStart\";\nimport clearSources from \"./clearSources\";\nimport deactivateSources from \"./deactivateSources\";\nimport { propagateFromSignal } from \"./propagateSignal\";\nimport runComputed from \"./runComputed\";\n\n/**\n * Options for `$refresh`.\n */\nexport interface RefreshOptions {\n\t/**\n\t * Re-fetch silently — stale-while-revalidate. The suspend is *quiet*\n\t * (`$pending` stays `false`) and subscribers aren't notified until the new\n\t * promise resolves. For background revalidation: polling, refetch-on-\n\t * focus. Defaults to `false` — a refresh is loud, so `$pending` reads\n\t * `true` and inline \"updating…\" indicators flip on at refresh start.\n\t */\n\tsilent?: boolean;\n}\n\n/**\n * Re-fetches the `$async` getters read inside `fn` without changing a\n * dependency. A companion to `$pending` (ASYNC.md): pull-to-refresh,\n * refresh buttons, refetch-on-focus, polling, retry-after-error.\n *\n * `fn` is run in a tracking context that collects every `$async` computed it\n * reads (`$cache` computeds are ignored). Each collected computed is then\n * re-run with `recalc` left true — a \"bare refresh\" — so the suspend is\n * *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and\n * subscribers are notified at suspend *start*, so an inline \"updating…\"\n * indicator appears immediately. Readers keep displaying the previous\n * resolved value (`Computed.staleValue`) until the new promise resolves and\n * propagates through the reactive graph; an `@await` boundary keeps its\n * content mounted instead of flashing fallback.\n *\n * Pass `{ silent: true }` to re-fetch quietly (stale-while-revalidate):\n * `$pending(fn)` stays `false` and nothing re-runs until the new promise\n * resolves. For background revalidation where feedback would be noise —\n * polling, refetch-on-focus:\n *\n * ```torp\n * // poll quietly every 30s\n * $run(() => {\n * \tconst id = setInterval(() => $refresh(() => $state.data, { silent: true }), 30_000);\n * \treturn () => clearInterval(id);\n * });\n * ```\n *\n * A refresh is loud regardless of `silent` when the computed has never\n * resolved — e.g. retrying after an error that left `didError` set on a first\n * load — or when the re-fetch is triggered by a dependency change, which\n * flows through the normal `recalc` path instead of here.\n *\n * If `fn` reads a getter the UI has never read, the collection read\n * initializes it — and that fetch IS the refresh: the computed is not re-run\n * (a second fetch would be a duplicate whose resolve the generation guard\n * drops). Getters already read (pending, resolved, or errored) are re-run as\n * usual.\n *\n * The returned value of `fn` is ignored; use `fn` to reference the getters.\n */\nexport default function $refresh(fn: () => any, options?: RefreshOptions): void {\n\tconst silent = options?.silent === true;\n\n\tconst oldRefreshSignals = context.refreshSignals;\n\tconst oldPeek = context.suspendPeek;\n\tconst oldInitialized = context.refreshInitialized;\n\tcontext.refreshSignals = [];\n\tcontext.suspendPeek = true;\n\tcontext.refreshInitialized = new Set();\n\tlet unique: Set<Computed>;\n\tlet initialized: Set<Computed>;\n\ttry {\n\t\tfn();\n\t\t// Dedupe — fn may read the same getter several times.\n\t\tunique = new Set<Computed>(context.refreshSignals ?? []);\n\t\tinitialized = context.refreshInitialized;\n\t} finally {\n\t\tcontext.refreshSignals = oldRefreshSignals;\n\t\tcontext.suspendPeek = oldPeek;\n\t\tcontext.refreshInitialized = oldInitialized;\n\t}\n\n\tfor (const computed of unique) {\n\t\tif (initialized.has(computed)) {\n\t\t\t// The collection read was this computed's first-ever read: it\n\t\t\t// initialized the getter and started the fetch the caller is\n\t\t\t// asking for. Re-running would start a duplicate fetch (its\n\t\t\t// resolve dropped by the generation guard), so the\n\t\t\t// initialization IS the refresh — skip the re-run and its\n\t\t\t// notifications. First loads are loud regardless of `silent`\n\t\t\t// (`suspendQuiet` is false while `hasResolved` is false), so\n\t\t\t// `$pending` still reads `true` for it.\n\t\t\tcontinue;\n\t\t}\n\t\t// Bare refresh: recalc must be true when `$async`'s run captures\n\t\t// suspendQuiet so the suspend reads as loud (suspendQuiet =\n\t\t// hasResolved && !recalc = false), and false for a silent refresh\n\t\t// (quiet). Restore it after the run.\n\t\tcomputed.recalc = !silent;\n\t\tdeactivateSources(computed);\n\t\t// Re-run with no active target so the refresh doesn't subscribe the\n\t\t// caller (e.g. the effect that triggered it) to the computed — an\n\t\t// imperative refresh must not make its caller re-run on resolve\n\t\t// (which could loop if the caller refreshes unconditionally). The\n\t\t// computed still subscribes to its own sources for future\n\t\t// dependency-change re-fetches.\n\t\tconst oldActiveTarget = context.activeTarget;\n\t\tcontext.activeTarget = null;\n\t\ttry {\n\t\t\trunComputed(computed);\n\t\t} finally {\n\t\t\tcontext.activeTarget = oldActiveTarget;\n\t\t}\n\t\tcomputed.recalc = false;\n\t\tclearSources(computed);\n\n\t\tif (!silent) {\n\t\t\t// A loud refresh notifies subscribers at suspend *start* so\n\t\t\t// `$pending` indicators (which subscribe to the computed) flip on\n\t\t\t// immediately and show the \"updating…\" UI while the fetch is in\n\t\t\t// flight. Readers re-read the retained staleValue, so content\n\t\t\t// doesn't flicker. A silent refresh stays quiet until resolve.\n\t\t\tbatchStart();\n\t\t\tpropagateFromSignal(computed);\n\t\t\tbatchEnd();\n\t\t}\n\t}\n}\n","import context from \"../render/context\";\nimport type StreamSource from \"../types/StreamSource\";\nimport $run from \"./$run\";\n\n/**\n * Subscribes to an external source of events — server-sent events,\n * WebSockets, DOM events, or any custom `StreamSource` — and calls\n * `handler` for each event it pushes. Events are typically written into\n * reactive state, which keeps templates, computeds and effects updating\n * through the normal reactivity model:\n *\n * ```torp\n * let $state = $watch({ messages: [] as string[] });\n *\n * $stream(fromServer(`/sse/${$props.id}`), (e) => {\n * \t$state.messages.push(e.data);\n * });\n * ```\n *\n * The subscription is managed by the framework:\n *\n * - It starts when the component is mounted to the DOM (so `&ref`-bound\n * elements are available), and is unsubscribed when the component\n * unmounts or its region is cleared.\n * - Reactive state read *inside* the source is tracked: when it changes,\n * the source is unsubscribed and re-subscribed with fresh values (e.g.\n * re-opening a connection when a user id changes). A pending debounced\n * call is dropped on re-subscribe.\n * - The source is never invoked during a server render, so browser-only\n * APIs are safe to use.\n *\n * Errors are values like any other: a source that can fail should push an\n * error-shaped value and own its own reconnection (e.g. `EventSource`\n * reconnects automatically).\n *\n * @param source The stream source to subscribe to\n * @param handler Called for each event the source pushes\n * @param options Timing options. `debounce` delays each handler call until\n * the source has been quiet for that many milliseconds, resetting on\n * every event (only the last event in a burst is handled).\n */\nexport default function $stream<T>(\n\tsource: StreamSource<T>,\n\thandler: (value: T) => void,\n\toptions?: { debounce?: number },\n): void {\n\tconst fn = () => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\t// Mount callbacks are once-only and untracked, so the source is set\n\t\t// up inside a `$run`: reactive state it reads is tracked, and when it\n\t\t// changes the source is unsubscribed and re-subscribed with fresh\n\t\t// values. The debounce timer lives outside the effect so re-runs\n\t\t// share it; the effect's cleanup drops any pending call.\n\t\t$run(() => {\n\t\t\tconst unsub = source((value) => {\n\t\t\t\tif (options?.debounce) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ttimer = setTimeout(() => handler(value), options.debounce);\n\t\t\t\t} else {\n\t\t\t\t\thandler(value);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\treturn () => {\n\t\t\t\tunsub?.();\n\t\t\t\tclearTimeout(timer);\n\t\t\t};\n\t\t});\n\t};\n\tcontext.mountEffects.push({\n\t\tregion: context.activeRegion,\n\t\tfn,\n\t});\n}\n"],"mappings":";;;AAGA,MAAM,iBAAgC,OAAO,IAAI,cAAc;AAE/D,MAAM,UAEJ,WAAW,oBAAoB;CAC/B,cAAc;CACd,gBAAgB;CAChB,QAAQ;CACR,OAAO;CACP,gBAAgB;CAChB,kBAAkB;CAElB,cAAc,CAAC;CACf,qBAAqB;CACrB,oBAAoB;CAGpB,cAAc;CACd,gBAAgB;CAChB,YAAY;CAEZ,eAAe;CAEf,aAAa;CACb,gBAAgB;CAEhB,gBAAgB;CAChB,oBAAoB;CAEpB,cAAc,CAAC;CACf,eAAe,CAAC;CAChB,mBAAmB,CAAC;CAEpB,eAAe;CAUf,cAAc;AACf;;;AC5CD,SAAwB,aAAa,IAAiB,OAAmB,MAAwB;CAKhG,QAAQ,kBAAkB,KAAK;EAC9B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