@llui/dom 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/primitives/branch.d.ts.map +1 -1
- package/dist/primitives/branch.js +18 -3
- package/dist/primitives/branch.js.map +1 -1
- package/dist/primitives/child.d.ts.map +1 -1
- package/dist/primitives/child.js +15 -3
- package/dist/primitives/child.js.map +1 -1
- package/dist/primitives/each.d.ts.map +1 -1
- package/dist/primitives/each.js +36 -14
- package/dist/primitives/each.js.map +1 -1
- package/dist/primitives/foreign.d.ts.map +1 -1
- package/dist/primitives/foreign.js +15 -3
- package/dist/primitives/foreign.js.map +1 -1
- package/dist/primitives/sample.d.ts +32 -1
- package/dist/primitives/sample.d.ts.map +1 -1
- package/dist/primitives/sample.js +52 -2
- package/dist/primitives/sample.js.map +1 -1
- package/dist/primitives/show.d.ts.map +1 -1
- package/dist/primitives/show.js +13 -1
- package/dist/primitives/show.js.map +1 -1
- package/dist/primitives/virtual-each.d.ts.map +1 -1
- package/dist/primitives/virtual-each.js +25 -5
- package/dist/primitives/virtual-each.js.map +1 -1
- package/dist/render-context.d.ts +3 -0
- package/dist/render-context.d.ts.map +1 -1
- package/dist/render-context.js +27 -1
- package/dist/render-context.js.map +1 -1
- package/dist/update-loop.d.ts.map +1 -1
- package/dist/update-loop.js +150 -78
- package/dist/update-loop.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/primitives/branch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/primitives/branch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,aAAa,CAAA;AAe1D,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAC9D,IAAI,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC3B,IAAI,EAAE,CAuKR"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRenderContext, setRenderContext, clearRenderContext } from '../render-context.js';
|
|
1
|
+
import { getRenderContext, setRenderContext, clearRenderContext, enterAccessor, exitAccessor, } from '../render-context.js';
|
|
2
2
|
import { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js';
|
|
3
3
|
import { setFlatBindings } from '../binding.js';
|
|
4
4
|
import { createView } from '../view-helpers.js';
|
|
@@ -10,13 +10,28 @@ export function branch(opts) {
|
|
|
10
10
|
const blocks = ctx.structuralBlocks;
|
|
11
11
|
const send = ctx.send;
|
|
12
12
|
const anchor = ctx.dom.createComment('branch');
|
|
13
|
-
|
|
13
|
+
// `on` accessor wrapped so sample()/h.sample() called from inside throws a
|
|
14
|
+
// targeted error. Both initial and reconcile paths route through callOn.
|
|
15
|
+
// `Discriminant<S, K>` is `((s: S) => K) | (() => K)` — passing `state`
|
|
16
|
+
// works for either arm at runtime (zero-arg ignores the extra), but a
|
|
17
|
+
// typed wrapper forces a union-call inference TypeScript can't unify.
|
|
18
|
+
// The runtime cast keeps the wrapper transparent.
|
|
19
|
+
const callOn = (state) => {
|
|
20
|
+
enterAccessor('branch().on');
|
|
21
|
+
try {
|
|
22
|
+
return opts.on(state);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
exitAccessor();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
let currentKey = callOn(ctx.state);
|
|
14
29
|
let currentLifetime = null;
|
|
15
30
|
let currentNodes = [];
|
|
16
31
|
const block = {
|
|
17
32
|
mask: opts.__mask ?? FULL_MASK,
|
|
18
33
|
reconcile(state) {
|
|
19
|
-
const newKey =
|
|
34
|
+
const newKey = callOn(state);
|
|
20
35
|
if (Object.is(newKey, currentKey))
|
|
21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CAAA;QACrC,8DAA8D;QAC9D,iEAAiE;QACjE,6DAA6D;QAC7D,4DAA4D;QAC5D,6DAA6D;QAC7D,gEAAgE;QAChE,2DAA2D;QAC3D,0DAA0D;QAC1D,8DAA8D;QAC9D,6CAA6C;QAC7C,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;YAChC,IAAI,IAAI,CAAC,UAAU;gBAAE,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACxD,CAAC;QACD,IAAI,MAAM,CAAC,UAAU;YAAE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QAC5D,IAAI,eAAe,EAAE,CAAC;YACpB,eAAe,CAAC,eAAe,CAAC,CAAA;YAChC,eAAe,GAAG,IAAI,CAAA;QACxB,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import type { BranchOptions, Lifetime } from '../types.js'\nimport { getRenderContext, setRenderContext, clearRenderContext } from '../render-context.js'\nimport { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js'\nimport { setFlatBindings } from '../binding.js'\nimport { createView } from '../view-helpers.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport { pushMountQueue, popMountQueue, flushMountQueue } from './on-mount.js'\nimport type { StructuralBlock } from '../structural.js'\n\nexport function branch<S, M = unknown, K extends string = string>(\n opts: BranchOptions<S, M, K>,\n): Node[] {\n const ctx = getRenderContext('branch')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n const send = ctx.send as (msg: M) => void\n\n const anchor = ctx.dom.createComment('branch')\n\n let currentKey = opts.on(ctx.state as S)\n let currentLifetime: Lifetime | null = null\n let currentNodes: Node[] = []\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const newKey = opts.on(state as S)\n if (Object.is(newKey, currentKey)) return\n\n const parent = anchor.parentNode\n if (!parent) return\n\n const leavingNodes = currentNodes\n const leavingLifetime = currentLifetime\n\n // Build new arm first (before removing old — for FLIP animations)\n currentNodes = []\n currentLifetime = null\n currentKey = newKey\n\n const newCaseKey = String(newKey) as K\n const newBuilder = opts.cases?.[newCaseKey] ?? opts.default\n // Collect onMount callbacks from the new case into a local queue,\n // then flush them SYNCHRONOUSLY after the new nodes are inserted.\n // Without this, onMount inside a branch case would see stale DOM\n // (nodes not yet attached) OR fall back to queueMicrotask and\n // race with synchronous event dispatches after the reconcile.\n let onMountQueue: Array<() => void> | null = null\n if (newBuilder) {\n const mq = pushMountQueue()\n onMountQueue = mq.queue\n currentLifetime = createLifetime(parentLifetime)\n currentLifetime._kind =\n opts.__disposalCause === 'show-hide'\n ? 'show'\n : opts.__disposalCause === 'scope-rebuild'\n ? 'scope'\n : 'branch'\n setFlatBindings(ctx.allBindings)\n setRenderContext({ ...ctx, rootLifetime: currentLifetime, state })\n currentNodes = newBuilder(createView<S, M>(send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(mq.prev)\n\n const ref = anchor.nextSibling\n for (const node of currentNodes) {\n parent.insertBefore(node, ref)\n }\n }\n if (onMountQueue) flushMountQueue(onMountQueue)\n\n // Fire enter for new nodes\n if (opts.enter && currentNodes.length > 0) {\n opts.enter(currentNodes)\n }\n\n // Handle leave — may be deferred via Promise\n const removeOld = () => {\n for (const node of leavingNodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n if (leavingLifetime) {\n // Tag BEFORE dispose so the disposer log records the cause.\n // `show()` passes `__disposalCause: 'show-hide'`; raw branch()\n // defaults to `'branch-swap'`. Tag wins over any pre-existing\n // value set by an inner primitive so the outermost cause is\n // reported (matches how humans describe the event).\n leavingLifetime.disposalCause = opts.__disposalCause ?? 'branch-swap'\n disposeLifetime(leavingLifetime)\n }\n }\n\n if (leavingNodes.length > 0 && opts.leave) {\n const result = opts.leave(leavingNodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n ;(result as Promise<void>).then(removeOld)\n } else {\n removeOld()\n }\n } else {\n removeOld()\n }\n },\n }\n\n // Register the block BEFORE running the initial builder so that parent\n // blocks always precede their nested children in the flat blocks array.\n // This guarantees correct Phase 1 iteration order: parents reconcile\n // first, so a parent that unmounts its old arm can dispose nested child\n // blocks (splicing them out of this array) without corrupting the loop\n // index — the splice only affects entries to the RIGHT of the parent.\n blocks.push(block)\n\n const caseKey = String(currentKey) as K\n const builder = opts.cases?.[caseKey] ?? opts.default\n // Initial-mount onMount callbacks are handled by the outer mountApp\n // queue — we're still inside the first view() call. branch doesn't\n // insert into the DOM at this point (the anchor + initial children\n // are returned to the parent), so we don't need to flush here.\n if (builder) {\n currentLifetime = createLifetime(parentLifetime)\n currentLifetime._kind =\n opts.__disposalCause === 'show-hide'\n ? 'show'\n : opts.__disposalCause === 'scope-rebuild'\n ? 'scope'\n : 'branch'\n setRenderContext({ ...ctx, rootLifetime: currentLifetime })\n currentNodes = builder(createView<S, M>(send))\n clearRenderContext()\n setRenderContext(ctx)\n\n // Fire enter on initial mount\n if (opts.enter && currentNodes.length > 0) {\n opts.enter(currentNodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // Remove arm DOM nodes + the anchor. The parent's own cleanup\n // (e.g. an outer branch's removeOld) only walks what its initial\n // render captured — nodes that THIS branch inserted into the\n // shared parent AFTER the outer's snapshot (including every\n // arm swap since initial mount) aren't in that list. Walking\n // `currentNodes` here and guarding with `parentNode` closes the\n // leak: if the parent DOM is already cascade-removed by an\n // ancestor, `node.parentNode` is null and the removeChild\n // no-ops. If the parent is still live (spread-into-arm case),\n // the removal is what cleans up the orphans.\n for (const node of currentNodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n if (currentLifetime) {\n disposeLifetime(currentLifetime)\n currentLifetime = null\n }\n })\n\n return [an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,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;IAED,WAAW,CAAC,cAAc,EAAE,GAAG,EAAE;QAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACjC,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACrC,8DAA8D;QAC9D,iEAAiE;QACjE,6DAA6D;QAC7D,4DAA4D;QAC5D,6DAA6D;QAC7D,gEAAgE;QAChE,2DAA2D;QAC3D,0DAA0D;QAC1D,8DAA8D;QAC9D,6CAA6C;QAC7C,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;YAChC,IAAI,IAAI,CAAC,UAAU;gBAAE,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACxD,CAAC;QACD,IAAI,MAAM,CAAC,UAAU;YAAE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;QAC5D,IAAI,eAAe,EAAE,CAAC;YACpB,eAAe,CAAC,eAAe,CAAC,CAAA;YAChC,eAAe,GAAG,IAAI,CAAA;QACxB,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import type { BranchOptions, Lifetime } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n} from '../render-context.js'\nimport { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js'\nimport { setFlatBindings } from '../binding.js'\nimport { createView } from '../view-helpers.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport { pushMountQueue, popMountQueue, flushMountQueue } from './on-mount.js'\nimport type { StructuralBlock } from '../structural.js'\n\nexport function branch<S, M = unknown, K extends string = string>(\n opts: BranchOptions<S, M, K>,\n): Node[] {\n const ctx = getRenderContext('branch')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n const send = ctx.send as (msg: M) => void\n\n const anchor = ctx.dom.createComment('branch')\n\n // `on` accessor wrapped so sample()/h.sample() called from inside throws a\n // targeted error. Both initial and reconcile paths route through callOn.\n // `Discriminant<S, K>` is `((s: S) => K) | (() => K)` — passing `state`\n // works for either arm at runtime (zero-arg ignores the extra), but a\n // typed wrapper forces a union-call inference TypeScript can't unify.\n // The runtime cast keeps the wrapper transparent.\n const callOn = (state: S) => {\n enterAccessor('branch().on')\n try {\n return (opts.on as (s: S) => K)(state)\n } finally {\n exitAccessor()\n }\n }\n\n let currentKey = callOn(ctx.state as S)\n let currentLifetime: Lifetime | null = null\n let currentNodes: Node[] = []\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const newKey = callOn(state as S)\n if (Object.is(newKey, currentKey)) return\n\n const parent = anchor.parentNode\n if (!parent) return\n\n const leavingNodes = currentNodes\n const leavingLifetime = currentLifetime\n\n // Build new arm first (before removing old — for FLIP animations)\n currentNodes = []\n currentLifetime = null\n currentKey = newKey\n\n const newCaseKey = String(newKey) as K\n const newBuilder = opts.cases?.[newCaseKey] ?? opts.default\n // Collect onMount callbacks from the new case into a local queue,\n // then flush them SYNCHRONOUSLY after the new nodes are inserted.\n // Without this, onMount inside a branch case would see stale DOM\n // (nodes not yet attached) OR fall back to queueMicrotask and\n // race with synchronous event dispatches after the reconcile.\n let onMountQueue: Array<() => void> | null = null\n if (newBuilder) {\n const mq = pushMountQueue()\n onMountQueue = mq.queue\n currentLifetime = createLifetime(parentLifetime)\n currentLifetime._kind =\n opts.__disposalCause === 'show-hide'\n ? 'show'\n : opts.__disposalCause === 'scope-rebuild'\n ? 'scope'\n : 'branch'\n setFlatBindings(ctx.allBindings)\n setRenderContext({ ...ctx, rootLifetime: currentLifetime, state })\n currentNodes = newBuilder(createView<S, M>(send))\n clearRenderContext()\n setFlatBindings(null)\n popMountQueue(mq.prev)\n\n const ref = anchor.nextSibling\n for (const node of currentNodes) {\n parent.insertBefore(node, ref)\n }\n }\n if (onMountQueue) flushMountQueue(onMountQueue)\n\n // Fire enter for new nodes\n if (opts.enter && currentNodes.length > 0) {\n opts.enter(currentNodes)\n }\n\n // Handle leave — may be deferred via Promise\n const removeOld = () => {\n for (const node of leavingNodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n if (leavingLifetime) {\n // Tag BEFORE dispose so the disposer log records the cause.\n // `show()` passes `__disposalCause: 'show-hide'`; raw branch()\n // defaults to `'branch-swap'`. Tag wins over any pre-existing\n // value set by an inner primitive so the outermost cause is\n // reported (matches how humans describe the event).\n leavingLifetime.disposalCause = opts.__disposalCause ?? 'branch-swap'\n disposeLifetime(leavingLifetime)\n }\n }\n\n if (leavingNodes.length > 0 && opts.leave) {\n const result = opts.leave(leavingNodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n ;(result as Promise<void>).then(removeOld)\n } else {\n removeOld()\n }\n } else {\n removeOld()\n }\n },\n }\n\n // Register the block BEFORE running the initial builder so that parent\n // blocks always precede their nested children in the flat blocks array.\n // This guarantees correct Phase 1 iteration order: parents reconcile\n // first, so a parent that unmounts its old arm can dispose nested child\n // blocks (splicing them out of this array) without corrupting the loop\n // index — the splice only affects entries to the RIGHT of the parent.\n blocks.push(block)\n\n const caseKey = String(currentKey) as K\n const builder = opts.cases?.[caseKey] ?? opts.default\n // Initial-mount onMount callbacks are handled by the outer mountApp\n // queue — we're still inside the first view() call. branch doesn't\n // insert into the DOM at this point (the anchor + initial children\n // are returned to the parent), so we don't need to flush here.\n if (builder) {\n currentLifetime = createLifetime(parentLifetime)\n currentLifetime._kind =\n opts.__disposalCause === 'show-hide'\n ? 'show'\n : opts.__disposalCause === 'scope-rebuild'\n ? 'scope'\n : 'branch'\n setRenderContext({ ...ctx, rootLifetime: currentLifetime })\n currentNodes = builder(createView<S, M>(send))\n clearRenderContext()\n setRenderContext(ctx)\n\n // Fire enter on initial mount\n if (opts.enter && currentNodes.length > 0) {\n opts.enter(currentNodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // Remove arm DOM nodes + the anchor. The parent's own cleanup\n // (e.g. an outer branch's removeOld) only walks what its initial\n // render captured — nodes that THIS branch inserted into the\n // shared parent AFTER the outer's snapshot (including every\n // arm swap since initial mount) aren't in that list. Walking\n // `currentNodes` here and guarding with `parentNode` closes the\n // leak: if the parent DOM is already cascade-removed by an\n // ancestor, `node.parentNode` is null and the removeChild\n // no-ops. If the parent is still live (spread-into-arm case),\n // the removal is what cleans up the orphans.\n for (const node of currentNodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n if (currentLifetime) {\n disposeLifetime(currentLifetime)\n currentLifetime = null\n }\n })\n\n return [anchor, ...currentNodes]\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child.d.ts","sourceRoot":"","sources":["../../src/primitives/child.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"child.d.ts","sourceRoot":"","sources":["../../src/primitives/child.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAA;AAgB7D,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,CAoHtE"}
|
package/dist/primitives/child.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRenderContext, setRenderContext, clearRenderContext } from '../render-context.js';
|
|
1
|
+
import { getRenderContext, setRenderContext, clearRenderContext, enterAccessor, exitAccessor, } from '../render-context.js';
|
|
2
2
|
import { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js';
|
|
3
3
|
import { createComponentInstance, flushInstance } from '../update-loop.js';
|
|
4
4
|
import { createBinding, setFlatBindings } from '../binding.js';
|
|
@@ -24,7 +24,19 @@ export function child(opts) {
|
|
|
24
24
|
childLifetime.disposalCause = 'child-unmount';
|
|
25
25
|
const parentSend = parentCtx.send;
|
|
26
26
|
const childDef = opts.def;
|
|
27
|
-
|
|
27
|
+
// `props` accessor wrapped so sample()/h.sample() inside throws a targeted
|
|
28
|
+
// error. Both initial read and the per-update binding accessor route through
|
|
29
|
+
// callProps.
|
|
30
|
+
const callProps = (parentState) => {
|
|
31
|
+
enterAccessor('child().props');
|
|
32
|
+
try {
|
|
33
|
+
return opts.props(parentState);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
exitAccessor();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const initialProps = callProps(parentCtx.state);
|
|
28
40
|
// Child component inherits the parent's DOM env — render-context
|
|
29
41
|
// threading means the same env flows from mountApp to child() to any
|
|
30
42
|
// nested primitives inside the child's view.
|
|
@@ -53,7 +65,7 @@ export function child(opts) {
|
|
|
53
65
|
createBinding(childLifetime, {
|
|
54
66
|
mask: FULL_MASK,
|
|
55
67
|
accessor: ((parentState) => {
|
|
56
|
-
const newProps =
|
|
68
|
+
const newProps = callProps(parentState);
|
|
57
69
|
let changed = false;
|
|
58
70
|
for (const key of Object.keys(newProps)) {
|
|
59
71
|
if (!Object.is(newProps[key], prevProps[key])) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child.js","sourceRoot":"","sources":["../../src/primitives/child.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"child.js","sourceRoot":"","sources":["../../src/primitives/child.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,sBAAsB,CA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AAI,CAAC,GAAG,CAAC,CAAA;QACzB,SAAS,CAAC,YAAY,CAAC,aAAa,GAAG,eAAe,CAAA;QACtD,eAAe,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import type { ChildOptions, ComponentDef } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n} from '../render-context.js'\nimport { createLifetime, disposeLifetime, addDisposer } from '../lifetime.js'\nimport { createComponentInstance, flushInstance, type ComponentInstance } from '../update-loop.js'\nimport { createBinding, setFlatBindings } from '../binding.js'\nimport { registerChild, unregisterChild } from '../addressed.js'\nimport { createView } from '../view-helpers.js'\n\nconst FULL_MASK = 0xffffffff\n\nexport function child<S, ChildM>(opts: ChildOptions<S, ChildM>): Node[] {\n // Dev-mode guard: props must be a function, not a static object\n if (typeof opts.props !== 'function') {\n throw new Error(\n `child(\"${String(opts.key)}\"): props must be a reactive accessor function ` +\n `(s => ({ ... })), not a static object. Static props are captured once at mount ` +\n `and never update.`,\n )\n }\n\n const parentCtx = getRenderContext('child')\n const parentLifetime = parentCtx.rootLifetime\n const childLifetime = createLifetime(parentLifetime)\n childLifetime._kind = 'child'\n // Tag eagerly: childLifetime lives as long as the child component is mounted,\n // so disposing it IS the child-unmount event. Setting the cause up front\n // (instead of inside the disposer closure below) ensures the parent's\n // _disposerLog sees it when `disposeLifetime` walks up the parent chain —\n // `childInst.rootLifetime` is an orphan (parent = null) and cannot emit.\n childLifetime.disposalCause = 'child-unmount'\n const parentSend = parentCtx.send\n\n const childDef = opts.def as ComponentDef<unknown, ChildM, unknown, Record<string, unknown>>\n // `props` accessor wrapped so sample()/h.sample() inside throws a targeted\n // error. Both initial read and the per-update binding accessor route through\n // callProps.\n const callProps = (parentState: S): Record<string, unknown> => {\n enterAccessor('child().props')\n try {\n return opts.props(parentState)\n } finally {\n exitAccessor()\n }\n }\n const initialProps = callProps(parentCtx.state as S)\n // Child component inherits the parent's DOM env — render-context\n // threading means the same env flows from mountApp to child() to any\n // nested primitives inside the child's view.\n const childInst = createComponentInstance(childDef, initialProps, null, parentCtx.dom)\n\n // Wrap child's send to intercept messages for onMsg → parent\n const originalSend = childInst.send\n childInst.send = (msg: ChildM) => {\n originalSend(msg)\n if (opts.onMsg && parentSend) {\n // Defer to after the child processes — use microtask\n queueMicrotask(() => {\n const parentMsg = opts.onMsg!(msg)\n if (parentMsg != null) {\n parentSend(parentMsg)\n }\n })\n }\n }\n\n // Track props for shallow-diff\n let prevProps: Record<string, unknown> = { ...initialProps }\n\n // Register a binding on the child scope that watches parent props changes.\n // This is a side-effect-only (`kind: 'effect'`) binding: Phase 2 runs the\n // accessor purely to fire the diff + propsMsg dispatch below. There is no\n // DOM output — the comment node is a detached anchor kept only so the\n // Binding shape stays uniform with other kinds.\n createBinding(childLifetime, {\n mask: FULL_MASK,\n accessor: ((parentState: S) => {\n const newProps = callProps(parentState)\n\n let changed = false\n for (const key of Object.keys(newProps)) {\n if (!Object.is(newProps[key], prevProps[key])) {\n changed = true\n break\n }\n }\n\n if (changed && childDef.propsMsg) {\n const msg = childDef.propsMsg(newProps)\n // Dispatch via `originalSend` so framework-synthesized propsMsg\n // traffic bypasses the `onMsg` wrapper below. Otherwise a naive\n // `onMsg: m => forward(m)` echoes props/set back to the parent,\n // which mutates parent state, re-fires this accessor, and loops\n // forever.\n originalSend(msg)\n flushInstance(childInst)\n }\n prevProps = { ...newProps }\n }) as (state: never) => unknown,\n kind: 'effect',\n node: parentCtx.dom.createComment('child:' + opts.key),\n perItem: false,\n })\n\n // Run the child's view within the child's render context\n setFlatBindings(childInst.allBindings)\n setRenderContext({\n ...childInst,\n send: childInst.send as (msg: unknown) => void,\n instance: childInst as ComponentInstance,\n })\n const nodes = childDef.view(createView(childInst.send))\n clearRenderContext()\n setFlatBindings(parentCtx.allBindings)\n setRenderContext(parentCtx)\n\n // Register in component registry for addressed effects\n registerChild(opts.key, { send: childInst.send as (msg: unknown) => void })\n\n // Cleanup: dispose child instance when parent scope disposes\n addDisposer(childLifetime, () => {\n unregisterChild(opts.key)\n childInst.rootLifetime.disposalCause = 'child-unmount'\n disposeLifetime(childInst.rootLifetime)\n })\n\n return nodes\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"each.d.ts","sourceRoot":"","sources":["../../src/primitives/each.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA0B,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"each.d.ts","sourceRoot":"","sources":["../../src/primitives/each.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA0B,MAAM,aAAa,CAAA;AA0BtE,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAEpD;AAED,sEAAsE;AACtE,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,GAAG,IAAI,CAEzE;AAwDD,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CA+R1E"}
|
package/dist/primitives/each.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRenderContext, setRenderContext, clearRenderContext, } from '../render-context.js';
|
|
1
|
+
import { getRenderContext, setRenderContext, clearRenderContext, enterAccessor, exitAccessor, } from '../render-context.js';
|
|
2
2
|
import { createLifetime, disposeLifetime, disposeLifetimesBulk, addDisposer, removeOrphanedChildren, } from '../lifetime.js';
|
|
3
3
|
import { getFlatBindings, setFlatBindings } from '../binding.js';
|
|
4
4
|
import { FULL_MASK } from '../update-loop.js';
|
|
@@ -17,6 +17,27 @@ export function registerOnRemove(cb) {
|
|
|
17
17
|
if (activeRemoveCallbacks)
|
|
18
18
|
activeRemoveCallbacks.push(cb);
|
|
19
19
|
}
|
|
20
|
+
// Wrap accessor invocations so `sample()` calls inside them throw a targeted
|
|
21
|
+
// error. The wrappers also localise the contract: every items/key call goes
|
|
22
|
+
// through these, so a future change (e.g. instrumentation) has one site.
|
|
23
|
+
function callItems(opts, state) {
|
|
24
|
+
enterAccessor('each().items');
|
|
25
|
+
try {
|
|
26
|
+
return opts.items(state);
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
exitAccessor();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function callKey(opts, item) {
|
|
33
|
+
enterAccessor('each().key');
|
|
34
|
+
try {
|
|
35
|
+
return opts.key(item);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
exitAccessor();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
20
41
|
// Reusable render context for buildEntry — avoids object allocation per entry.
|
|
21
42
|
// All fields except `rootLifetime`, `state`, `allBindings`, `structuralBlocks`, `dom`
|
|
22
43
|
// are copied from the surrounding render context per reconcile call, so the
|
|
@@ -49,7 +70,7 @@ export function each(opts) {
|
|
|
49
70
|
// Entries whose leave animation is still in progress. Their DOM nodes
|
|
50
71
|
// remain in the parent until the leave Promise resolves.
|
|
51
72
|
const leaving = [];
|
|
52
|
-
const initialItems = opts
|
|
73
|
+
const initialItems = callItems(opts, ctx.state);
|
|
53
74
|
let lastItemsRef = initialItems;
|
|
54
75
|
// Dev-only diff tracking: if the owning component has an _eachDiffLog
|
|
55
76
|
// (installed by devtools), we capture key sets before/after each
|
|
@@ -109,7 +130,7 @@ export function each(opts) {
|
|
|
109
130
|
const parent = anchor.parentNode;
|
|
110
131
|
if (!parent)
|
|
111
132
|
return;
|
|
112
|
-
const newItems = opts
|
|
133
|
+
const newItems = callItems(opts, state);
|
|
113
134
|
// Fast path: same array reference → skip entirely.
|
|
114
135
|
if (newItems === lastItemsRef)
|
|
115
136
|
return;
|
|
@@ -125,7 +146,7 @@ export function each(opts) {
|
|
|
125
146
|
/** Same keys, only item data changed — skip mismatch/swap detection.
|
|
126
147
|
* Compiler calls this when it knows the array structure is unchanged. */
|
|
127
148
|
reconcileItems(state) {
|
|
128
|
-
const newItems = opts
|
|
149
|
+
const newItems = callItems(opts, state);
|
|
129
150
|
lastItemsRef = newItems;
|
|
130
151
|
const len = Math.min(entries.length, newItems.length);
|
|
131
152
|
for (let i = 0; i < len; i++) {
|
|
@@ -173,7 +194,7 @@ export function each(opts) {
|
|
|
173
194
|
* patterns where items are removed but order is preserved. Walks old
|
|
174
195
|
* and new arrays in parallel — O(n) with no Map/Set allocation. */
|
|
175
196
|
reconcileRemove(state) {
|
|
176
|
-
const newItems = opts
|
|
197
|
+
const newItems = callItems(opts, state);
|
|
177
198
|
lastItemsRef = newItems;
|
|
178
199
|
const parent = anchor.parentNode;
|
|
179
200
|
if (!parent)
|
|
@@ -192,7 +213,7 @@ export function each(opts) {
|
|
|
192
213
|
let didRemove = false;
|
|
193
214
|
for (let oi = 0; oi < oldLen; oi++) {
|
|
194
215
|
const entry = entries[oi];
|
|
195
|
-
if (ni < newLen && entry.key === opts
|
|
216
|
+
if (ni < newLen && entry.key === callKey(opts, newItems[ni])) {
|
|
196
217
|
// Entry survives — update if item ref changed
|
|
197
218
|
if (entry.item !== newItems[ni]) {
|
|
198
219
|
updateEntry(entry, newItems[ni], ni);
|
|
@@ -230,7 +251,7 @@ export function each(opts) {
|
|
|
230
251
|
/** Update only entries at stride intervals — O(k) where k = n/stride.
|
|
231
252
|
* The compiler passes the stride from the detected for-loop pattern. */
|
|
232
253
|
reconcileChanged(state, stride) {
|
|
233
|
-
const newItems = opts
|
|
254
|
+
const newItems = callItems(opts, state);
|
|
234
255
|
lastItemsRef = newItems;
|
|
235
256
|
for (let i = 0; i < entries.length && i < newItems.length; i += stride) {
|
|
236
257
|
const entry = entries[i];
|
|
@@ -338,7 +359,7 @@ function fireEnter(entry, opts) {
|
|
|
338
359
|
}
|
|
339
360
|
}
|
|
340
361
|
function buildEntry(item, index, opts, parentLifetime, ctx, state) {
|
|
341
|
-
const key = opts
|
|
362
|
+
const key = callKey(opts, item);
|
|
342
363
|
// Use a lightweight scope — just needs itemUpdaters for per-item bindings.
|
|
343
364
|
// Full scope features (disposers, bindings, children) are only needed when
|
|
344
365
|
// the render callback uses structural primitives or selector.bind().
|
|
@@ -513,7 +534,7 @@ function reconcileEntries(entries, newItems, opts, parentLifetime, parent, ancho
|
|
|
513
534
|
const newItem = newItems[i];
|
|
514
535
|
if (entry.item === newItem)
|
|
515
536
|
continue;
|
|
516
|
-
const newKey = opts
|
|
537
|
+
const newKey = callKey(opts, newItem);
|
|
517
538
|
if (entry.key === newKey) {
|
|
518
539
|
updateEntry(entry, newItem, i);
|
|
519
540
|
continue;
|
|
@@ -534,7 +555,8 @@ function reconcileEntries(entries, newItems, opts, parentLifetime, parent, ancho
|
|
|
534
555
|
if (mismatchCount === 2) {
|
|
535
556
|
const e1 = entries[mismatch1];
|
|
536
557
|
const e2 = entries[mismatch2];
|
|
537
|
-
if (e1.key === opts
|
|
558
|
+
if (e1.key === callKey(opts, newItems[mismatch2]) &&
|
|
559
|
+
e2.key === callKey(opts, newItems[mismatch1])) {
|
|
538
560
|
// DOM swap
|
|
539
561
|
const refI = e1.nodes[0];
|
|
540
562
|
const refAfterJ = e2.nodes[e2.nodes.length - 1].nextSibling;
|
|
@@ -553,13 +575,13 @@ function reconcileEntries(entries, newItems, opts, parentLifetime, parent, ancho
|
|
|
553
575
|
}
|
|
554
576
|
// Fast path 5: full replace — no shared keys between old and new.
|
|
555
577
|
// Skipped when opts.leave is set so departing items can animate individually.
|
|
556
|
-
if (!hasLeave && oldLen > 0 && opts
|
|
578
|
+
if (!hasLeave && oldLen > 0 && callKey(opts, newItems[0]) !== entries[0].key) {
|
|
557
579
|
const oldKeys = new Set();
|
|
558
580
|
for (const entry of entries)
|
|
559
581
|
oldKeys.add(entry.key);
|
|
560
582
|
let anyShared = false;
|
|
561
583
|
for (let i = 0; i < newLen; i++) {
|
|
562
|
-
if (oldKeys.has(opts
|
|
584
|
+
if (oldKeys.has(callKey(opts, newItems[i]))) {
|
|
563
585
|
anyShared = true;
|
|
564
586
|
break;
|
|
565
587
|
}
|
|
@@ -615,7 +637,7 @@ function reconcileEntries(entries, newItems, opts, parentLifetime, parent, ancho
|
|
|
615
637
|
const newlyAdded = [];
|
|
616
638
|
for (let i = 0; i < newLen; i++) {
|
|
617
639
|
const item = newItems[i];
|
|
618
|
-
const key = opts
|
|
640
|
+
const key = callKey(opts, item);
|
|
619
641
|
usedKeys.add(key);
|
|
620
642
|
const existing = oldByKey.get(key);
|
|
621
643
|
if (existing) {
|
|
@@ -724,7 +746,7 @@ function updateEntry(entry, item, index) {
|
|
|
724
746
|
}
|
|
725
747
|
function isAppendOnly(entries, newItems, opts) {
|
|
726
748
|
for (let i = 0; i < entries.length; i++) {
|
|
727
|
-
if (entries[i].key !== opts
|
|
749
|
+
if (entries[i].key !== callKey(opts, newItems[i]))
|
|
728
750
|
return false;
|
|
729
751
|
}
|
|
730
752
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"each.js","sourceRoot":"","sources":["../../src/primitives/each.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,6FAA6F;AAC7F,kFAAkF;AAClF,IAAI,oBAAoB,GAA6B,IAAI,CAAA;AACzD,IAAI,qBAAqB,GAAiD,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CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,IAAI,WAAW,GAAG,CAAC,CAAC,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,SAAQ,CAAC,kBAAkB;QACrD,IAAI,MAAM,GAAG,WAAW;YAAE,OAAO,KAAK,CAAA;QACtC,WAAW,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import type { EachOptions, ItemAccessor, Lifetime } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n type RenderContext,\n} from '../render-context.js'\nimport {\n createLifetime,\n disposeLifetime,\n disposeLifetimesBulk,\n addDisposer,\n removeOrphanedChildren,\n} from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\nimport { createView } from '../view-helpers.js'\n\n// Clear callbacks — registered by selector.bind() during render, called by reconcileClear().\n// Eliminates per-row disposers (1000 Set.delete calls → 1 registry.clear() call).\nlet activeClearCallbacks: Array<() => void> | null = null\nlet activeRemoveCallbacks: Array<(key: string | number) => void> | null = null\n\n/** Register a callback to run when the current each() block clears. */\nexport function registerOnClear(cb: () => void): void {\n if (activeClearCallbacks) activeClearCallbacks.push(cb)\n}\n\n/** Register a callback to run when a single row is removed by key. */\nexport function registerOnRemove(cb: (key: string | number) => void): void {\n if (activeRemoveCallbacks) activeRemoveCallbacks.push(cb)\n}\n\n// Reusable render context for buildEntry — avoids object allocation per entry.\n// All fields except `rootLifetime`, `state`, `allBindings`, `structuralBlocks`, `dom`\n// are copied from the surrounding render context per reconcile call, so the\n// initial shape's null/empty values are never observed in practice.\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n// Reusable render bag — mutated per entry instead of allocating new objects\nconst buildBag: Record<string, unknown> = {\n send: null,\n get item() {\n return (buildBag._getItemProxy as () => unknown)()\n },\n acc: null,\n index: null,\n _getItemProxy: null,\n}\n\ninterface Entry<T> {\n key: string | number\n item: T\n current: T\n index: number\n scope: Lifetime\n nodes: Node[]\n /** Per-item updaters — stored on entry directly to avoid scope overhead for leaf rows */\n updaters: Array<() => void>\n}\n\nexport function each<S, T, M = unknown>(opts: EachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('each')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n\n const anchor = ctx.dom.createComment('each')\n const entries: Entry<T>[] = []\n const clearCallbacks: Array<() => void> = []\n const removeCallbacks: Array<(key: string | number) => void> = []\n // Entries whose leave animation is still in progress. Their DOM nodes\n // remain in the parent until the leave Promise resolves.\n const leaving: Entry<T>[] = []\n\n const initialItems = opts.items(ctx.state as S)\n let lastItemsRef = initialItems\n\n // Dev-only diff tracking: if the owning component has an _eachDiffLog\n // (installed by devtools), we capture key sets before/after each\n // key-mutating reconcile call and emit an EachDiff entry. The siteId\n // is derived from this each() block's position in the flat block\n // array at registration time — stable for the lifetime of the block.\n const inst = ctx.instance\n const eachSiteId = inst?._eachDiffLog !== undefined ? `each#${blocks.length}` : ''\n const snapshotKeys = (): string[] | null => {\n if (inst?._eachDiffLog === undefined) return null\n const keys: string[] = []\n for (let i = 0; i < entries.length; i++) keys.push(String(entries[i]!.key))\n return keys\n }\n const emitDiff = (oldKeys: string[] | null): void => {\n if (oldKeys === null || inst?._eachDiffLog === undefined) return\n const newKeys: string[] = []\n for (let i = 0; i < entries.length; i++) newKeys.push(String(entries[i]!.key))\n const oldKeySet = new Set(oldKeys)\n const newKeySet = new Set(newKeys)\n const added: string[] = []\n const removed: string[] = []\n const moved: Array<{ key: string; from: number; to: number }> = []\n const reused: string[] = []\n for (const k of newKeys) if (!oldKeySet.has(k)) added.push(k)\n for (const k of oldKeys) if (!newKeySet.has(k)) removed.push(k)\n for (let i = 0; i < newKeys.length; i++) {\n const k = newKeys[i]!\n if (!oldKeySet.has(k)) continue\n const from = oldKeys.indexOf(k)\n if (from !== i) moved.push({ key: k, from, to: i })\n else reused.push(k)\n }\n inst._eachDiffLog.push({\n updateIndex: inst._updateCounter ?? 0,\n eachSiteId,\n added,\n removed,\n moved,\n reused,\n })\n }\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const parent = anchor.parentNode\n if (!parent) return\n\n const newItems = opts.items(state as S)\n\n // Fast path: same array reference → skip entirely.\n if (newItems === lastItemsRef) return\n lastItemsRef = newItems\n\n const oldKeys = snapshotKeys()\n const report = opts.onTransition ? { entering: [] as Node[], leaving: [] as Node[] } : null\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n ctx,\n state,\n leaving,\n report,\n )\n if (opts.onTransition && report) {\n opts.onTransition({ entering: report.entering, leaving: report.leaving, parent })\n }\n emitDiff(oldKeys)\n },\n\n /** Same keys, only item data changed — skip mismatch/swap detection.\n * Compiler calls this when it knows the array structure is unchanged. */\n reconcileItems(state: unknown) {\n const newItems = opts.items(state as S)\n lastItemsRef = newItems\n const len = Math.min(entries.length, newItems.length)\n for (let i = 0; i < len; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n\n /** Remove all items — skip items accessor, go straight to clear path. */\n reconcileClear() {\n lastItemsRef = [] as unknown as T[]\n const parent = anchor.parentNode\n if (!parent) return\n if (entries.length === 0) return\n\n const oldKeys = snapshotKeys()\n\n // Call registered clear callbacks (e.g., selector registry.clear())\n // BEFORE scope disposal — avoids 1000 individual Set.delete calls\n for (let i = 0; i < clearCallbacks.length; i++) clearCallbacks[i]!()\n\n // Bulk DOM removal\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n const lastNode = lastEntry.nodes[lastEntry.nodes.length - 1]!\n range.setEndAfter(lastNode)\n range.deleteContents()\n\n // Bulk scope disposal — disposers that were replaced by clearCallbacks\n // are now no-ops, making this much faster\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n\n emitDiff(oldKeys)\n },\n\n /** Remove entries not present in the new items. Optimized for filter()\n * patterns where items are removed but order is preserved. Walks old\n * and new arrays in parallel — O(n) with no Map/Set allocation. */\n reconcileRemove(state: unknown) {\n const newItems = opts.items(state as S)\n lastItemsRef = newItems\n const parent = anchor.parentNode\n if (!parent) return\n\n const oldKeys = snapshotKeys()\n const oldLen = entries.length\n const newLen = newItems.length\n if (newLen >= oldLen) {\n // Not a removal — fallback (shouldn't happen if compiler detected correctly)\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n ctx,\n state,\n leaving,\n null,\n )\n emitDiff(oldKeys)\n return\n }\n\n // Parallel walk: new items are a subsequence of old items (same order, some removed)\n let ni = 0\n let didRemove = false\n for (let oi = 0; oi < oldLen; oi++) {\n const entry = entries[oi]!\n if (ni < newLen && entry.key === opts.key(newItems[ni]!)) {\n // Entry survives — update if item ref changed\n if (entry.item !== newItems[ni]) {\n updateEntry(entry, newItems[ni]!, ni)\n }\n ni++\n } else {\n // Entry removed — notify selectors before scope disposal\n for (let ci = 0; ci < removeCallbacks.length; ci++) removeCallbacks[ci]!(entry.key)\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n entries[oi] = null!\n didRemove = true\n }\n }\n\n // Compact entries array\n if (didRemove) {\n let w = 0\n for (let r = 0; r < oldLen; r++) {\n if (entries[r]) entries[w++] = entries[r]!\n }\n entries.length = w\n removeOrphanedChildren(parentLifetime)\n }\n\n // Update indices for remaining entries\n for (let i = 0; i < entries.length; i++) {\n entries[i]!.index = i\n }\n\n emitDiff(oldKeys)\n },\n\n /** Update only entries at stride intervals — O(k) where k = n/stride.\n * The compiler passes the stride from the detected for-loop pattern. */\n reconcileChanged(state: unknown, stride: number) {\n const newItems = opts.items(state as S)\n lastItemsRef = newItems\n for (let i = 0; i < entries.length && i < newItems.length; i += stride) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n }\n\n // Register the block BEFORE building initial row entries so that this\n // each() block precedes any nested structural blocks its rows register.\n // Parents must come first in the flat blocks array — see branch.ts for\n // the full rationale (Phase 1 iteration safety when disposing nested).\n blocks.push(block)\n\n activeClearCallbacks = clearCallbacks\n activeRemoveCallbacks = removeCallbacks\n for (let i = 0; i < initialItems.length; i++) {\n const item = initialItems[i]!\n const entry = buildEntry(item, i, opts, parentLifetime, ctx)\n entries.push(entry)\n }\n activeClearCallbacks = null\n activeRemoveCallbacks = null\n\n // Fire initial enter for mount-time items\n if (opts.enter) {\n for (const entry of entries) {\n if (entry.nodes.length > 0) opts.enter(entry.nodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // parentLifetime is being disposed — its children array is about to be\n // cleared by the recursive dispose pass, so skip per-entry parent\n // removal (avoids O(N²) indexOf+splice).\n //\n // Rows created AFTER the parent's initial render (each reconciled\n // with a new item list) are siblings of the anchor inside the\n // parent's DOM container, but aren't tracked by the parent's\n // snapshot (e.g. an outer branch's currentNodes). Walking entries\n // here and removing their DOM — guarded by parentNode — closes\n // the leak: cascade-removed subtrees no-op, live-parent cases get\n // the orphans cleaned up.\n for (const entry of entries) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n entries.length = 0\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n // Force-remove any mid-leave entries immediately\n for (const entry of leaving) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n leaving.length = 0\n })\n\n const result: Node[] = [anchor]\n for (const entry of entries) {\n const nodes = entry.nodes\n for (let i = 0; i < nodes.length; i++) result.push(nodes[i]!)\n }\n return result\n}\n\n/**\n * Remove an entry's DOM + dispose its scope, running opts.leave first if\n * provided. When leave returns a Promise, the DOM removal is deferred until\n * resolution (entry is tracked in `leaving`).\n */\nfunction removeEntry<T>(\n entry: Entry<T>,\n opts: { leave?: (nodes: Node[]) => void | Promise<void> },\n leaving: Entry<T>[],\n): void {\n const removeNow = (): void => {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n const idx = leaving.indexOf(entry)\n if (idx !== -1) leaving.splice(idx, 1)\n }\n if (opts.leave && entry.nodes.length > 0) {\n const result = opts.leave(entry.nodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n leaving.push(entry)\n ;(result as Promise<void>).then(removeNow)\n return\n }\n }\n removeNow()\n}\n\nfunction fireEnter<T>(\n entry: Entry<T>,\n opts: { enter?: (nodes: Node[]) => void | Promise<void> },\n): void {\n if (opts.enter && entry.nodes.length > 0) {\n void opts.enter(entry.nodes)\n }\n}\n\nfunction buildEntry<S, T, M>(\n item: T,\n index: number,\n opts: EachOptions<S, T, M>,\n parentLifetime: Lifetime,\n ctx: ReturnType<typeof getRenderContext>,\n state?: unknown,\n): Entry<T> {\n const key = opts.key(item)\n // Use a lightweight scope — just needs itemUpdaters for per-item bindings.\n // Full scope features (disposers, bindings, children) are only needed when\n // the render callback uses structural primitives or selector.bind().\n const scope = createLifetime(parentLifetime)\n scope._kind = 'each'\n const currentState = (state ?? ctx.state) as S\n const send = ctx.send as (msg: M) => void\n\n // Create entry before render so itemAccessor closures can capture it\n const entry: Entry<T> = { key, item, current: item, index, scope, nodes: null!, updaters: [] }\n\n // Base callable: item(selector) for computed expressions\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = () => selector(entry.current)\n accessor.__perItem = true as const\n return accessor\n }\n\n // Proxy for item.field shorthand: LAZILY created. Compiled code uses\n // `acc(fn)` instead (the compiler rewrites item.x → acc(r => r.x)),\n // so the Proxy is never constructed in the common case. This saves\n // ~300ns × N Proxy allocations per create cycle.\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n let fieldCache: Map<string, () => unknown> | null = null\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const key = prop as string\n if (fieldCache) {\n const cached = fieldCache.get(key)\n if (cached) return cached\n } else {\n fieldCache = new Map()\n }\n // `current` returns the whole item — essential for primitive T\n // (where the field map is useless) and for whole-record sampling.\n // Caller must call it like a method: `item.current()`.\n const accessor =\n key === 'current'\n ? () => entry.current\n : () => (entry.current as Record<string, unknown>)[key]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(key, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n // Reuse a single context object to avoid allocation per entry\n buildCtx.rootLifetime = scope\n buildCtx.state = currentState\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n const prevFlatBindings = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n // Reuse a single render bag object across entries — mutate `acc` and\n // `index` per entry to avoid per-entry object allocation.\n buildBag.send = send\n buildBag.acc = itemFn\n buildBag.index = indexAccessor\n buildBag._getItemProxy = getItemProxy\n buildBag.entry = entry\n // The View bag — lets each.render use `h.text`, `h.scope`, `h.sample`,\n // etc. without reaching for the top-level imports. Each entry gets a\n // fresh View so its `send` is bound to this row's dispatch path.\n buildBag.h = createView<S, M>(send)\n // Row factory: pass compiler-injected template + update function through to render\n const rfOpts = opts as unknown as Record<string, unknown>\n if (rfOpts.__tpl) buildBag.__tpl = rfOpts.__tpl\n if (rfOpts.__rowUpd) buildBag.__rowUpd = rfOpts.__rowUpd\n entry.nodes = opts.render(buildBag as Parameters<typeof opts.render>[0])\n\n // Move itemUpdaters from scope to entry for direct access during updateEntry.\n // This avoids scope.itemUpdaters lookup overhead on every item update.\n if (scope.itemUpdaters.length > 0) {\n entry.updaters = scope.itemUpdaters\n scope.itemUpdaters = []\n }\n\n clearRenderContext()\n setFlatBindings(prevFlatBindings)\n setRenderContext(ctx)\n\n return entry\n}\n\ninterface TransitionReport {\n entering: Node[]\n leaving: Node[]\n}\n\nfunction collectNodes(target: Node[], nodes: Node[]): void {\n for (const n of nodes) target.push(n)\n}\n\nfunction reconcileEntries<S, T>(\n entries: Entry<T>[],\n newItems: T[],\n opts: EachOptions<S, T>,\n parentLifetime: Lifetime,\n parent: Node,\n anchor: Node,\n ctx: ReturnType<typeof getRenderContext>,\n state: unknown,\n leaving: Entry<T>[],\n report: TransitionReport | null,\n): void {\n const oldLen = entries.length\n const newLen = newItems.length\n const hasLeave = !!opts.leave\n\n // Fast path 1: clear all — bulk DOM removal.\n // When opts.leave is set, each item needs its own leave animation, so\n // fall through to per-item removal instead of Range.deleteContents().\n if (newLen === 0) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n if (hasLeave) {\n const toRemove = entries.slice()\n entries.length = 0\n for (const entry of toRemove) removeEntry(entry, opts, leaving)\n return\n }\n // Remove all DOM nodes in one operation using Range\n if (entries.length > 0) {\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n const lastNode = lastEntry.nodes[lastEntry.nodes.length - 1]!\n range.setEndAfter(lastNode)\n range.deleteContents()\n }\n // Bulk dispose all entry scopes — avoids per-scope function call overhead\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n return\n }\n\n // Fast path 2: append-only — old keys are a prefix of new keys\n if (newLen > oldLen && isAppendOnly(entries, newItems, opts)) {\n for (let i = 0; i < oldLen; i++) {\n updateEntry(entries[i]!, newItems[i]!, i)\n }\n // Find insertion point: after last existing entry's last node, or after anchor\n const lastEntry = oldLen > 0 ? entries[oldLen - 1]! : null\n const ref = lastEntry\n ? lastEntry.nodes[lastEntry.nodes.length - 1]!.nextSibling\n : anchor.nextSibling\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = oldLen; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, ref)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n\n // Fast path 3: same length — single pass handles both same-keys update\n // and two-element swap detection. Avoids a second O(n) pass.\n if (newLen === oldLen) {\n let mismatch1 = -1\n let mismatch2 = -1\n let mismatchCount = 0\n\n for (let i = 0; i < newLen; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item === newItem) continue\n const newKey = opts.key(newItem)\n if (entry.key === newKey) {\n updateEntry(entry, newItem, i)\n continue\n }\n // Key mismatch — track for swap detection\n mismatchCount++\n if (mismatchCount === 1) mismatch1 = i\n else if (mismatchCount === 2) mismatch2 = i\n else break // 3+ mismatches → fall through to general path\n }\n\n // All keys matched (with possible item updates) → done\n if (mismatchCount === 0) return\n\n // Exactly 2 key mismatches — check if it's a swap\n if (mismatchCount === 2) {\n const e1 = entries[mismatch1]!\n const e2 = entries[mismatch2]!\n if (e1.key === opts.key(newItems[mismatch2]!) && e2.key === opts.key(newItems[mismatch1]!)) {\n // DOM swap\n const refI = e1.nodes[0]!\n const refAfterJ = e2.nodes[e2.nodes.length - 1]!.nextSibling\n for (const node of e2.nodes) parent.insertBefore(node, refI)\n for (const node of e1.nodes) parent.insertBefore(node, refAfterJ)\n entries[mismatch1] = e2\n entries[mismatch2] = e1\n updateEntry(e2, newItems[mismatch1]!, mismatch1)\n updateEntry(e1, newItems[mismatch2]!, mismatch2)\n return\n }\n }\n // Fall through to general path for 3+ mismatches or non-swap\n }\n\n // Fast path 5: full replace — no shared keys between old and new.\n // Skipped when opts.leave is set so departing items can animate individually.\n if (!hasLeave && oldLen > 0 && opts.key(newItems[0]!) !== entries[0]!.key) {\n const oldKeys = new Set<string | number>()\n for (const entry of entries) oldKeys.add(entry.key)\n let anyShared = false\n for (let i = 0; i < newLen; i++) {\n if (oldKeys.has(opts.key(newItems[i]!))) {\n anyShared = true\n break\n }\n }\n if (!anyShared) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n // Bulk DOM removal using Range\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n range.setEndAfter(lastEntry.nodes[lastEntry.nodes.length - 1]!)\n range.deleteContents()\n // Bulk dispose all old scopes\n const oldLifetimes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n oldLifetimes.push(s)\n }\n disposeLifetimesBulk(oldLifetimes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n // Build all new entries into a fragment\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = 0; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n }\n\n // General path: keyed reconciliation\n const oldByKey = new Map<string | number, Entry<T>>()\n for (const entry of entries) {\n oldByKey.set(entry.key, entry)\n }\n\n const newEntries: Entry<T>[] = []\n const usedKeys = new Set<string | number>()\n const newlyAdded: Entry<T>[] = []\n\n for (let i = 0; i < newLen; i++) {\n const item = newItems[i]!\n const key = opts.key(item)\n usedKeys.add(key)\n\n const existing = oldByKey.get(key)\n if (existing) {\n updateEntry(existing, item, i)\n newEntries.push(existing)\n } else {\n const entry = buildEntry(item, i, opts, parentLifetime, ctx, state)\n newEntries.push(entry)\n newlyAdded.push(entry)\n }\n }\n\n // Remove entries not in the new list. Use bulk-detach pattern so\n // disposing K removals costs O(K+P) rather than O(K*P) where P is\n // parentLifetime.children.length (avoids K * indexOf+splice).\n let didBulkDetach = false\n for (const entry of entries) {\n if (!usedKeys.has(entry.key)) {\n if (report) collectNodes(report.leaving, entry.nodes)\n if (hasLeave) {\n removeEntry(entry, opts, leaving)\n } else {\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n didBulkDetach = true\n }\n }\n }\n if (didBulkDetach) removeOrphanedChildren(parentLifetime)\n\n // Reorder DOM\n const hasSurvivors = newEntries.some((e) => oldByKey.has(e.key))\n\n if (!hasSurvivors || !survivorsInOrder(entries, newEntries, usedKeys)) {\n // Full fragment rebuild — one reflow\n const frag = ctx.dom.createDocumentFragment()\n for (const entry of newEntries) {\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n } else {\n // Survivors in order — batch-insert new entries between survivors\n let frag: DocumentFragment | null = null\n let insertRef: ChildNode | null = anchor.nextSibling\n for (const entry of newEntries) {\n if (oldByKey.has(entry.key)) {\n // Flush any pending fragment before this survivor\n if (frag) {\n parent.insertBefore(frag, insertRef)\n frag = null\n }\n // Skip past survivor's nodes\n const lastNode = entry.nodes[entry.nodes.length - 1]\n insertRef = lastNode ? lastNode.nextSibling : insertRef\n } else {\n // Batch new entries into a fragment\n if (!frag) frag = ctx.dom.createDocumentFragment()\n for (const node of entry.nodes) frag.appendChild(node)\n }\n }\n if (frag) parent.insertBefore(frag, insertRef)\n }\n\n entries.length = newEntries.length\n for (let i = 0; i < newEntries.length; i++) entries[i] = newEntries[i]!\n\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n\n // Fire enter for newly-added entries (after DOM insertion)\n if (opts.enter) {\n for (const entry of newlyAdded) fireEnter(entry, opts)\n }\n}\n\nfunction updateEntry<T>(entry: Entry<T>, item: T, index: number): void {\n const changed = !Object.is(entry.item, item)\n entry.item = item\n entry.current = item\n entry.index = index\n // eachItemStable removed — unused\n // Directly run per-item updaters when item changed — bypasses Phase 2\n if (changed) {\n // Row factory fast path: shared update function, zero closures\n const rowUpd = (entry as unknown as Record<string, unknown>).__rowUpdate as\n | ((e: Entry<T>) => void)\n | undefined\n if (rowUpd) {\n rowUpd(entry)\n } else {\n // Closure-based fallback\n const updaters = entry.updaters.length > 0 ? entry.updaters : entry.scope.itemUpdaters\n for (let i = 0; i < updaters.length; i++) {\n updaters[i]!()\n }\n }\n }\n}\n\nfunction isAppendOnly<S, T>(entries: Entry<T>[], newItems: T[], opts: EachOptions<S, T>): boolean {\n for (let i = 0; i < entries.length; i++) {\n if (entries[i]!.key !== opts.key(newItems[i]!)) return false\n }\n return true\n}\n\nfunction survivorsInOrder<T>(\n oldEntries: Entry<T>[],\n newEntries: Entry<T>[],\n usedKeys: Set<string | number>,\n): boolean {\n // Build old-index map for survivors\n const oldIndexMap = new Map<string | number, number>()\n for (let i = 0; i < oldEntries.length; i++) {\n if (usedKeys.has(oldEntries[i]!.key)) {\n oldIndexMap.set(oldEntries[i]!.key, i)\n }\n }\n // Check that survivors appear in increasing old-index order in newEntries\n let maxOldIndex = -1\n for (const entry of newEntries) {\n const oldIdx = oldIndexMap.get(entry.key)\n if (oldIdx === undefined) continue // new entry, skip\n if (oldIdx < maxOldIndex) return false\n maxOldIndex = oldIdx\n }\n return true\n}\n"]}
|
|
1
|
+
{"version":3,"file":"each.js","sourceRoot":"","sources":["../../src/primitives/each.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,YAAY,GAEb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,6FAA6F;AAC7F,kFAAkF;AAClF,IAAI,oBAAoB,GAA6B,IAAI,CAAA;AACzD,IAAI,qBAAqB,GAAiD,IAAI,CAAA;AAE9E,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,EAAc;IAC5C,IAAI,oBAAoB;QAAE,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACzD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,gBAAgB,CAAC,EAAkC;IACjE,IAAI,qBAAqB;QAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC3D,CAAC;AAED,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,SAAS,SAAS,CAAO,IAA8B,EAAE,KAAQ;IAC/D,aAAa,CAAC,cAAc,CAAC,CAA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CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,IAAI,WAAW,GAAG,CAAC,CAAC,CAAA;IACpB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,SAAQ,CAAC,kBAAkB;QACrD,IAAI,MAAM,GAAG,WAAW;YAAE,OAAO,KAAK,CAAA;QACtC,WAAW,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import type { EachOptions, ItemAccessor, Lifetime } from '../types.js'\nimport {\n getRenderContext,\n setRenderContext,\n clearRenderContext,\n enterAccessor,\n exitAccessor,\n type RenderContext,\n} from '../render-context.js'\nimport {\n createLifetime,\n disposeLifetime,\n disposeLifetimesBulk,\n addDisposer,\n removeOrphanedChildren,\n} from '../lifetime.js'\nimport { getFlatBindings, setFlatBindings } from '../binding.js'\nimport { FULL_MASK } from '../update-loop.js'\nimport type { StructuralBlock } from '../structural.js'\nimport { createView } from '../view-helpers.js'\n\n// Clear callbacks — registered by selector.bind() during render, called by reconcileClear().\n// Eliminates per-row disposers (1000 Set.delete calls → 1 registry.clear() call).\nlet activeClearCallbacks: Array<() => void> | null = null\nlet activeRemoveCallbacks: Array<(key: string | number) => void> | null = null\n\n/** Register a callback to run when the current each() block clears. */\nexport function registerOnClear(cb: () => void): void {\n if (activeClearCallbacks) activeClearCallbacks.push(cb)\n}\n\n/** Register a callback to run when a single row is removed by key. */\nexport function registerOnRemove(cb: (key: string | number) => void): void {\n if (activeRemoveCallbacks) activeRemoveCallbacks.push(cb)\n}\n\n// Wrap accessor invocations so `sample()` calls inside them throw a targeted\n// error. The wrappers also localise the contract: every items/key call goes\n// through these, so a future change (e.g. instrumentation) has one site.\nfunction callItems<S, T>(opts: { items: (s: S) => T[] }, state: S): T[] {\n enterAccessor('each().items')\n try {\n return opts.items(state)\n } finally {\n exitAccessor()\n }\n}\nfunction callKey<T>(opts: { key: (t: T) => string | number }, item: T): string | number {\n enterAccessor('each().key')\n try {\n return opts.key(item)\n } finally {\n exitAccessor()\n }\n}\n\n// Reusable render context for buildEntry — avoids object allocation per entry.\n// All fields except `rootLifetime`, `state`, `allBindings`, `structuralBlocks`, `dom`\n// are copied from the surrounding render context per reconcile call, so the\n// initial shape's null/empty values are never observed in practice.\nconst buildCtx: RenderContext = {\n rootLifetime: null as unknown as Lifetime,\n state: null,\n allBindings: [],\n structuralBlocks: [],\n dom: null as unknown as import('../dom-env.js').DomEnv,\n}\n\n// Reusable render bag — mutated per entry instead of allocating new objects\nconst buildBag: Record<string, unknown> = {\n send: null,\n get item() {\n return (buildBag._getItemProxy as () => unknown)()\n },\n acc: null,\n index: null,\n _getItemProxy: null,\n}\n\ninterface Entry<T> {\n key: string | number\n item: T\n current: T\n index: number\n scope: Lifetime\n nodes: Node[]\n /** Per-item updaters — stored on entry directly to avoid scope overhead for leaf rows */\n updaters: Array<() => void>\n}\n\nexport function each<S, T, M = unknown>(opts: EachOptions<S, T, M>): Node[] {\n const ctx = getRenderContext('each')\n const parentLifetime = ctx.rootLifetime\n const blocks = ctx.structuralBlocks\n\n const anchor = ctx.dom.createComment('each')\n const entries: Entry<T>[] = []\n const clearCallbacks: Array<() => void> = []\n const removeCallbacks: Array<(key: string | number) => void> = []\n // Entries whose leave animation is still in progress. Their DOM nodes\n // remain in the parent until the leave Promise resolves.\n const leaving: Entry<T>[] = []\n\n const initialItems = callItems(opts, ctx.state as S)\n let lastItemsRef = initialItems\n\n // Dev-only diff tracking: if the owning component has an _eachDiffLog\n // (installed by devtools), we capture key sets before/after each\n // key-mutating reconcile call and emit an EachDiff entry. The siteId\n // is derived from this each() block's position in the flat block\n // array at registration time — stable for the lifetime of the block.\n const inst = ctx.instance\n const eachSiteId = inst?._eachDiffLog !== undefined ? `each#${blocks.length}` : ''\n const snapshotKeys = (): string[] | null => {\n if (inst?._eachDiffLog === undefined) return null\n const keys: string[] = []\n for (let i = 0; i < entries.length; i++) keys.push(String(entries[i]!.key))\n return keys\n }\n const emitDiff = (oldKeys: string[] | null): void => {\n if (oldKeys === null || inst?._eachDiffLog === undefined) return\n const newKeys: string[] = []\n for (let i = 0; i < entries.length; i++) newKeys.push(String(entries[i]!.key))\n const oldKeySet = new Set(oldKeys)\n const newKeySet = new Set(newKeys)\n const added: string[] = []\n const removed: string[] = []\n const moved: Array<{ key: string; from: number; to: number }> = []\n const reused: string[] = []\n for (const k of newKeys) if (!oldKeySet.has(k)) added.push(k)\n for (const k of oldKeys) if (!newKeySet.has(k)) removed.push(k)\n for (let i = 0; i < newKeys.length; i++) {\n const k = newKeys[i]!\n if (!oldKeySet.has(k)) continue\n const from = oldKeys.indexOf(k)\n if (from !== i) moved.push({ key: k, from, to: i })\n else reused.push(k)\n }\n inst._eachDiffLog.push({\n updateIndex: inst._updateCounter ?? 0,\n eachSiteId,\n added,\n removed,\n moved,\n reused,\n })\n }\n\n const block: StructuralBlock = {\n mask: (opts as { __mask?: number }).__mask ?? FULL_MASK,\n reconcile(state: unknown) {\n const parent = anchor.parentNode\n if (!parent) return\n\n const newItems = callItems(opts, state as S)\n\n // Fast path: same array reference → skip entirely.\n if (newItems === lastItemsRef) return\n lastItemsRef = newItems\n\n const oldKeys = snapshotKeys()\n const report = opts.onTransition ? { entering: [] as Node[], leaving: [] as Node[] } : null\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n ctx,\n state,\n leaving,\n report,\n )\n if (opts.onTransition && report) {\n opts.onTransition({ entering: report.entering, leaving: report.leaving, parent })\n }\n emitDiff(oldKeys)\n },\n\n /** Same keys, only item data changed — skip mismatch/swap detection.\n * Compiler calls this when it knows the array structure is unchanged. */\n reconcileItems(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const len = Math.min(entries.length, newItems.length)\n for (let i = 0; i < len; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n\n /** Remove all items — skip items accessor, go straight to clear path. */\n reconcileClear() {\n lastItemsRef = [] as unknown as T[]\n const parent = anchor.parentNode\n if (!parent) return\n if (entries.length === 0) return\n\n const oldKeys = snapshotKeys()\n\n // Call registered clear callbacks (e.g., selector registry.clear())\n // BEFORE scope disposal — avoids 1000 individual Set.delete calls\n for (let i = 0; i < clearCallbacks.length; i++) clearCallbacks[i]!()\n\n // Bulk DOM removal\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n const lastNode = lastEntry.nodes[lastEntry.nodes.length - 1]!\n range.setEndAfter(lastNode)\n range.deleteContents()\n\n // Bulk scope disposal — disposers that were replaced by clearCallbacks\n // are now no-ops, making this much faster\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n\n emitDiff(oldKeys)\n },\n\n /** Remove entries not present in the new items. Optimized for filter()\n * patterns where items are removed but order is preserved. Walks old\n * and new arrays in parallel — O(n) with no Map/Set allocation. */\n reconcileRemove(state: unknown) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n const parent = anchor.parentNode\n if (!parent) return\n\n const oldKeys = snapshotKeys()\n const oldLen = entries.length\n const newLen = newItems.length\n if (newLen >= oldLen) {\n // Not a removal — fallback (shouldn't happen if compiler detected correctly)\n reconcileEntries(\n entries,\n newItems,\n opts,\n parentLifetime,\n parent,\n anchor,\n ctx,\n state,\n leaving,\n null,\n )\n emitDiff(oldKeys)\n return\n }\n\n // Parallel walk: new items are a subsequence of old items (same order, some removed)\n let ni = 0\n let didRemove = false\n for (let oi = 0; oi < oldLen; oi++) {\n const entry = entries[oi]!\n if (ni < newLen && entry.key === callKey(opts, newItems[ni]!)) {\n // Entry survives — update if item ref changed\n if (entry.item !== newItems[ni]) {\n updateEntry(entry, newItems[ni]!, ni)\n }\n ni++\n } else {\n // Entry removed — notify selectors before scope disposal\n for (let ci = 0; ci < removeCallbacks.length; ci++) removeCallbacks[ci]!(entry.key)\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n entries[oi] = null!\n didRemove = true\n }\n }\n\n // Compact entries array\n if (didRemove) {\n let w = 0\n for (let r = 0; r < oldLen; r++) {\n if (entries[r]) entries[w++] = entries[r]!\n }\n entries.length = w\n removeOrphanedChildren(parentLifetime)\n }\n\n // Update indices for remaining entries\n for (let i = 0; i < entries.length; i++) {\n entries[i]!.index = i\n }\n\n emitDiff(oldKeys)\n },\n\n /** Update only entries at stride intervals — O(k) where k = n/stride.\n * The compiler passes the stride from the detected for-loop pattern. */\n reconcileChanged(state: unknown, stride: number) {\n const newItems = callItems(opts, state as S)\n lastItemsRef = newItems\n for (let i = 0; i < entries.length && i < newItems.length; i += stride) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item !== newItem) {\n updateEntry(entry, newItem, i)\n }\n }\n },\n }\n\n // Register the block BEFORE building initial row entries so that this\n // each() block precedes any nested structural blocks its rows register.\n // Parents must come first in the flat blocks array — see branch.ts for\n // the full rationale (Phase 1 iteration safety when disposing nested).\n blocks.push(block)\n\n activeClearCallbacks = clearCallbacks\n activeRemoveCallbacks = removeCallbacks\n for (let i = 0; i < initialItems.length; i++) {\n const item = initialItems[i]!\n const entry = buildEntry(item, i, opts, parentLifetime, ctx)\n entries.push(entry)\n }\n activeClearCallbacks = null\n activeRemoveCallbacks = null\n\n // Fire initial enter for mount-time items\n if (opts.enter) {\n for (const entry of entries) {\n if (entry.nodes.length > 0) opts.enter(entry.nodes)\n }\n }\n\n addDisposer(parentLifetime, () => {\n const idx = blocks.indexOf(block)\n if (idx !== -1) blocks.splice(idx, 1)\n // parentLifetime is being disposed — its children array is about to be\n // cleared by the recursive dispose pass, so skip per-entry parent\n // removal (avoids O(N²) indexOf+splice).\n //\n // Rows created AFTER the parent's initial render (each reconciled\n // with a new item list) are siblings of the anchor inside the\n // parent's DOM container, but aren't tracked by the parent's\n // snapshot (e.g. an outer branch's currentNodes). Walking entries\n // here and removing their DOM — guarded by parentNode — closes\n // the leak: cascade-removed subtrees no-op, live-parent cases get\n // the orphans cleaned up.\n for (const entry of entries) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n entries.length = 0\n if (anchor.parentNode) anchor.parentNode.removeChild(anchor)\n // Force-remove any mid-leave entries immediately\n for (const entry of leaving) {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n disposeLifetime(entry.scope, true)\n }\n leaving.length = 0\n })\n\n const result: Node[] = [anchor]\n for (const entry of entries) {\n const nodes = entry.nodes\n for (let i = 0; i < nodes.length; i++) result.push(nodes[i]!)\n }\n return result\n}\n\n/**\n * Remove an entry's DOM + dispose its scope, running opts.leave first if\n * provided. When leave returns a Promise, the DOM removal is deferred until\n * resolution (entry is tracked in `leaving`).\n */\nfunction removeEntry<T>(\n entry: Entry<T>,\n opts: { leave?: (nodes: Node[]) => void | Promise<void> },\n leaving: Entry<T>[],\n): void {\n const removeNow = (): void => {\n for (const node of entry.nodes) {\n if (node.parentNode) node.parentNode.removeChild(node)\n }\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope)\n const idx = leaving.indexOf(entry)\n if (idx !== -1) leaving.splice(idx, 1)\n }\n if (opts.leave && entry.nodes.length > 0) {\n const result = opts.leave(entry.nodes)\n if (result && typeof (result as Promise<void>).then === 'function') {\n leaving.push(entry)\n ;(result as Promise<void>).then(removeNow)\n return\n }\n }\n removeNow()\n}\n\nfunction fireEnter<T>(\n entry: Entry<T>,\n opts: { enter?: (nodes: Node[]) => void | Promise<void> },\n): void {\n if (opts.enter && entry.nodes.length > 0) {\n void opts.enter(entry.nodes)\n }\n}\n\nfunction buildEntry<S, T, M>(\n item: T,\n index: number,\n opts: EachOptions<S, T, M>,\n parentLifetime: Lifetime,\n ctx: ReturnType<typeof getRenderContext>,\n state?: unknown,\n): Entry<T> {\n const key = callKey(opts, item)\n // Use a lightweight scope — just needs itemUpdaters for per-item bindings.\n // Full scope features (disposers, bindings, children) are only needed when\n // the render callback uses structural primitives or selector.bind().\n const scope = createLifetime(parentLifetime)\n scope._kind = 'each'\n const currentState = (state ?? ctx.state) as S\n const send = ctx.send as (msg: M) => void\n\n // Create entry before render so itemAccessor closures can capture it\n const entry: Entry<T> = { key, item, current: item, index, scope, nodes: null!, updaters: [] }\n\n // Base callable: item(selector) for computed expressions\n const itemFn = <R>(selector: (t: T) => R): (() => R) => {\n const accessor = () => selector(entry.current)\n accessor.__perItem = true as const\n return accessor\n }\n\n // Proxy for item.field shorthand: LAZILY created. Compiled code uses\n // `acc(fn)` instead (the compiler rewrites item.x → acc(r => r.x)),\n // so the Proxy is never constructed in the common case. This saves\n // ~300ns × N Proxy allocations per create cycle.\n let itemProxy: ItemAccessor<T> | null = null\n const getItemProxy = (): ItemAccessor<T> => {\n if (itemProxy) return itemProxy\n let fieldCache: Map<string, () => unknown> | null = null\n itemProxy = new Proxy(itemFn as object, {\n get(target, prop) {\n if (typeof prop === 'symbol' || prop === 'then' || prop === 'prototype') {\n return Reflect.get(target, prop)\n }\n const key = prop as string\n if (fieldCache) {\n const cached = fieldCache.get(key)\n if (cached) return cached\n } else {\n fieldCache = new Map()\n }\n // `current` returns the whole item — essential for primitive T\n // (where the field map is useless) and for whole-record sampling.\n // Caller must call it like a method: `item.current()`.\n const accessor =\n key === 'current'\n ? () => entry.current\n : () => (entry.current as Record<string, unknown>)[key]\n ;(accessor as unknown as { __perItem: true }).__perItem = true\n fieldCache.set(key, accessor)\n return accessor\n },\n }) as ItemAccessor<T>\n return itemProxy\n }\n\n const indexAccessor = (): number => entry.index\n\n // Reuse a single context object to avoid allocation per entry\n buildCtx.rootLifetime = scope\n buildCtx.state = currentState\n buildCtx.allBindings = ctx.allBindings\n buildCtx.structuralBlocks = ctx.structuralBlocks\n buildCtx.dom = ctx.dom\n buildCtx.instance = ctx.instance\n const prevFlatBindings = getFlatBindings()\n setFlatBindings(ctx.allBindings)\n setRenderContext(buildCtx)\n\n // Reuse a single render bag object across entries — mutate `acc` and\n // `index` per entry to avoid per-entry object allocation.\n buildBag.send = send\n buildBag.acc = itemFn\n buildBag.index = indexAccessor\n buildBag._getItemProxy = getItemProxy\n buildBag.entry = entry\n // The View bag — lets each.render use `h.text`, `h.scope`, `h.sample`,\n // etc. without reaching for the top-level imports. Each entry gets a\n // fresh View so its `send` is bound to this row's dispatch path.\n buildBag.h = createView<S, M>(send)\n // Row factory: pass compiler-injected template + update function through to render\n const rfOpts = opts as unknown as Record<string, unknown>\n if (rfOpts.__tpl) buildBag.__tpl = rfOpts.__tpl\n if (rfOpts.__rowUpd) buildBag.__rowUpd = rfOpts.__rowUpd\n entry.nodes = opts.render(buildBag as Parameters<typeof opts.render>[0])\n\n // Move itemUpdaters from scope to entry for direct access during updateEntry.\n // This avoids scope.itemUpdaters lookup overhead on every item update.\n if (scope.itemUpdaters.length > 0) {\n entry.updaters = scope.itemUpdaters\n scope.itemUpdaters = []\n }\n\n clearRenderContext()\n setFlatBindings(prevFlatBindings)\n setRenderContext(ctx)\n\n return entry\n}\n\ninterface TransitionReport {\n entering: Node[]\n leaving: Node[]\n}\n\nfunction collectNodes(target: Node[], nodes: Node[]): void {\n for (const n of nodes) target.push(n)\n}\n\nfunction reconcileEntries<S, T>(\n entries: Entry<T>[],\n newItems: T[],\n opts: EachOptions<S, T>,\n parentLifetime: Lifetime,\n parent: Node,\n anchor: Node,\n ctx: ReturnType<typeof getRenderContext>,\n state: unknown,\n leaving: Entry<T>[],\n report: TransitionReport | null,\n): void {\n const oldLen = entries.length\n const newLen = newItems.length\n const hasLeave = !!opts.leave\n\n // Fast path 1: clear all — bulk DOM removal.\n // When opts.leave is set, each item needs its own leave animation, so\n // fall through to per-item removal instead of Range.deleteContents().\n if (newLen === 0) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n if (hasLeave) {\n const toRemove = entries.slice()\n entries.length = 0\n for (const entry of toRemove) removeEntry(entry, opts, leaving)\n return\n }\n // Remove all DOM nodes in one operation using Range\n if (entries.length > 0) {\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n const lastNode = lastEntry.nodes[lastEntry.nodes.length - 1]!\n range.setEndAfter(lastNode)\n range.deleteContents()\n }\n // Bulk dispose all entry scopes — avoids per-scope function call overhead\n const scopes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n scopes.push(s)\n }\n disposeLifetimesBulk(scopes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n return\n }\n\n // Fast path 2: append-only — old keys are a prefix of new keys\n if (newLen > oldLen && isAppendOnly(entries, newItems, opts)) {\n for (let i = 0; i < oldLen; i++) {\n updateEntry(entries[i]!, newItems[i]!, i)\n }\n // Find insertion point: after last existing entry's last node, or after anchor\n const lastEntry = oldLen > 0 ? entries[oldLen - 1]! : null\n const ref = lastEntry\n ? lastEntry.nodes[lastEntry.nodes.length - 1]!.nextSibling\n : anchor.nextSibling\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = oldLen; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, ref)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n\n // Fast path 3: same length — single pass handles both same-keys update\n // and two-element swap detection. Avoids a second O(n) pass.\n if (newLen === oldLen) {\n let mismatch1 = -1\n let mismatch2 = -1\n let mismatchCount = 0\n\n for (let i = 0; i < newLen; i++) {\n const entry = entries[i]!\n const newItem = newItems[i]!\n if (entry.item === newItem) continue\n const newKey = callKey(opts, newItem)\n if (entry.key === newKey) {\n updateEntry(entry, newItem, i)\n continue\n }\n // Key mismatch — track for swap detection\n mismatchCount++\n if (mismatchCount === 1) mismatch1 = i\n else if (mismatchCount === 2) mismatch2 = i\n else break // 3+ mismatches → fall through to general path\n }\n\n // All keys matched (with possible item updates) → done\n if (mismatchCount === 0) return\n\n // Exactly 2 key mismatches — check if it's a swap\n if (mismatchCount === 2) {\n const e1 = entries[mismatch1]!\n const e2 = entries[mismatch2]!\n if (\n e1.key === callKey(opts, newItems[mismatch2]!) &&\n e2.key === callKey(opts, newItems[mismatch1]!)\n ) {\n // DOM swap\n const refI = e1.nodes[0]!\n const refAfterJ = e2.nodes[e2.nodes.length - 1]!.nextSibling\n for (const node of e2.nodes) parent.insertBefore(node, refI)\n for (const node of e1.nodes) parent.insertBefore(node, refAfterJ)\n entries[mismatch1] = e2\n entries[mismatch2] = e1\n updateEntry(e2, newItems[mismatch1]!, mismatch1)\n updateEntry(e1, newItems[mismatch2]!, mismatch2)\n return\n }\n }\n // Fall through to general path for 3+ mismatches or non-swap\n }\n\n // Fast path 5: full replace — no shared keys between old and new.\n // Skipped when opts.leave is set so departing items can animate individually.\n if (!hasLeave && oldLen > 0 && callKey(opts, newItems[0]!) !== entries[0]!.key) {\n const oldKeys = new Set<string | number>()\n for (const entry of entries) oldKeys.add(entry.key)\n let anyShared = false\n for (let i = 0; i < newLen; i++) {\n if (oldKeys.has(callKey(opts, newItems[i]!))) {\n anyShared = true\n break\n }\n }\n if (!anyShared) {\n if (report) {\n for (const entry of entries) collectNodes(report.leaving, entry.nodes)\n }\n // Bulk DOM removal using Range\n const range = ctx.dom.createRange()\n range.setStartAfter(anchor)\n const lastEntry = entries[entries.length - 1]!\n range.setEndAfter(lastEntry.nodes[lastEntry.nodes.length - 1]!)\n range.deleteContents()\n // Bulk dispose all old scopes\n const oldLifetimes: Lifetime[] = []\n for (let i = 0; i < entries.length; i++) {\n const s = entries[i]!.scope\n s.disposalCause = 'each-remove'\n oldLifetimes.push(s)\n }\n disposeLifetimesBulk(oldLifetimes)\n removeOrphanedChildren(parentLifetime)\n entries.length = 0\n // Build all new entries into a fragment\n const frag = ctx.dom.createDocumentFragment()\n const newlyAdded: Entry<T>[] = []\n for (let i = 0; i < newLen; i++) {\n const entry = buildEntry(newItems[i]!, i, opts, parentLifetime, ctx, state)\n entries.push(entry)\n newlyAdded.push(entry)\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n for (const entry of newlyAdded) fireEnter(entry, opts)\n return\n }\n }\n\n // General path: keyed reconciliation\n const oldByKey = new Map<string | number, Entry<T>>()\n for (const entry of entries) {\n oldByKey.set(entry.key, entry)\n }\n\n const newEntries: Entry<T>[] = []\n const usedKeys = new Set<string | number>()\n const newlyAdded: Entry<T>[] = []\n\n for (let i = 0; i < newLen; i++) {\n const item = newItems[i]!\n const key = callKey(opts, item)\n usedKeys.add(key)\n\n const existing = oldByKey.get(key)\n if (existing) {\n updateEntry(existing, item, i)\n newEntries.push(existing)\n } else {\n const entry = buildEntry(item, i, opts, parentLifetime, ctx, state)\n newEntries.push(entry)\n newlyAdded.push(entry)\n }\n }\n\n // Remove entries not in the new list. Use bulk-detach pattern so\n // disposing K removals costs O(K+P) rather than O(K*P) where P is\n // parentLifetime.children.length (avoids K * indexOf+splice).\n let didBulkDetach = false\n for (const entry of entries) {\n if (!usedKeys.has(entry.key)) {\n if (report) collectNodes(report.leaving, entry.nodes)\n if (hasLeave) {\n removeEntry(entry, opts, leaving)\n } else {\n for (const node of entry.nodes) parent.removeChild(node)\n entry.scope.disposalCause = 'each-remove'\n disposeLifetime(entry.scope, true)\n didBulkDetach = true\n }\n }\n }\n if (didBulkDetach) removeOrphanedChildren(parentLifetime)\n\n // Reorder DOM\n const hasSurvivors = newEntries.some((e) => oldByKey.has(e.key))\n\n if (!hasSurvivors || !survivorsInOrder(entries, newEntries, usedKeys)) {\n // Full fragment rebuild — one reflow\n const frag = ctx.dom.createDocumentFragment()\n for (const entry of newEntries) {\n for (const node of entry.nodes) frag.appendChild(node)\n }\n parent.insertBefore(frag, anchor.nextSibling)\n } else {\n // Survivors in order — batch-insert new entries between survivors\n let frag: DocumentFragment | null = null\n let insertRef: ChildNode | null = anchor.nextSibling\n for (const entry of newEntries) {\n if (oldByKey.has(entry.key)) {\n // Flush any pending fragment before this survivor\n if (frag) {\n parent.insertBefore(frag, insertRef)\n frag = null\n }\n // Skip past survivor's nodes\n const lastNode = entry.nodes[entry.nodes.length - 1]\n insertRef = lastNode ? lastNode.nextSibling : insertRef\n } else {\n // Batch new entries into a fragment\n if (!frag) frag = ctx.dom.createDocumentFragment()\n for (const node of entry.nodes) frag.appendChild(node)\n }\n }\n if (frag) parent.insertBefore(frag, insertRef)\n }\n\n entries.length = newEntries.length\n for (let i = 0; i < newEntries.length; i++) entries[i] = newEntries[i]!\n\n if (report) {\n for (const entry of newlyAdded) collectNodes(report.entering, entry.nodes)\n }\n\n // Fire enter for newly-added entries (after DOM insertion)\n if (opts.enter) {\n for (const entry of newlyAdded) fireEnter(entry, opts)\n }\n}\n\nfunction updateEntry<T>(entry: Entry<T>, item: T, index: number): void {\n const changed = !Object.is(entry.item, item)\n entry.item = item\n entry.current = item\n entry.index = index\n // eachItemStable removed — unused\n // Directly run per-item updaters when item changed — bypasses Phase 2\n if (changed) {\n // Row factory fast path: shared update function, zero closures\n const rowUpd = (entry as unknown as Record<string, unknown>).__rowUpdate as\n | ((e: Entry<T>) => void)\n | undefined\n if (rowUpd) {\n rowUpd(entry)\n } else {\n // Closure-based fallback\n const updaters = entry.updaters.length > 0 ? entry.updaters : entry.scope.itemUpdaters\n for (let i = 0; i < updaters.length; i++) {\n updaters[i]!()\n }\n }\n }\n}\n\nfunction isAppendOnly<S, T>(entries: Entry<T>[], newItems: T[], opts: EachOptions<S, T>): boolean {\n for (let i = 0; i < entries.length; i++) {\n if (entries[i]!.key !== callKey(opts, newItems[i]!)) return false\n }\n return true\n}\n\nfunction survivorsInOrder<T>(\n oldEntries: Entry<T>[],\n newEntries: Entry<T>[],\n usedKeys: Set<string | number>,\n): boolean {\n // Build old-index map for survivors\n const oldIndexMap = new Map<string | number, number>()\n for (let i = 0; i < oldEntries.length; i++) {\n if (usedKeys.has(oldEntries[i]!.key)) {\n oldIndexMap.set(oldEntries[i]!.key, i)\n }\n }\n // Check that survivors appear in increasing old-index order in newEntries\n let maxOldIndex = -1\n for (const entry of newEntries) {\n const oldIdx = oldIndexMap.get(entry.key)\n if (oldIdx === undefined) continue // new entry, skip\n if (oldIdx < maxOldIndex) return false\n maxOldIndex = oldIdx\n }\n return true\n}\n"]}
|