@verajs/renderer 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +1000 -12
  2. package/dist/development/vera-renderer-hydrate.d.ts +32 -13
  3. package/dist/development/vera-renderer-hydrate.d.ts.map +1 -1
  4. package/dist/development/vera-renderer-hydrate.js +1812 -234
  5. package/dist/development/vera-renderer-hydrate.js.map +1 -1
  6. package/dist/development/vera-renderer-keyed.d.ts +17 -0
  7. package/dist/development/vera-renderer-keyed.d.ts.map +1 -0
  8. package/dist/development/vera-renderer-keyed.js +322 -0
  9. package/dist/development/vera-renderer-keyed.js.map +1 -0
  10. package/dist/development/vera-renderer-profiler.d.ts +57 -17
  11. package/dist/development/vera-renderer-profiler.d.ts.map +1 -1
  12. package/dist/development/vera-renderer-profiler.js +1445 -209
  13. package/dist/development/vera-renderer-profiler.js.map +1 -1
  14. package/dist/development/vera-renderer-slots.d.ts +103 -0
  15. package/dist/development/vera-renderer-slots.d.ts.map +1 -0
  16. package/dist/development/vera-renderer-slots.js +1387 -0
  17. package/dist/development/vera-renderer-slots.js.map +1 -0
  18. package/dist/development/vera-renderer-spread.d.ts +51 -0
  19. package/dist/development/vera-renderer-spread.d.ts.map +1 -0
  20. package/dist/development/vera-renderer-spread.js +499 -0
  21. package/dist/development/vera-renderer-spread.js.map +1 -0
  22. package/dist/development/vera-renderer-tag.d.ts +61 -0
  23. package/dist/development/vera-renderer-tag.d.ts.map +1 -0
  24. package/dist/development/vera-renderer-tag.js +727 -0
  25. package/dist/development/vera-renderer-tag.js.map +1 -0
  26. package/dist/development/vera-renderer.d.ts +41 -16
  27. package/dist/development/vera-renderer.d.ts.map +1 -1
  28. package/dist/development/vera-renderer.js +1375 -200
  29. package/dist/development/vera-renderer.js.map +1 -1
  30. package/dist/vera-renderer-hydrate.min.js +1 -1
  31. package/dist/vera-renderer-hydrate.min.js.map +1 -1
  32. package/dist/vera-renderer-keyed.min.js +2 -0
  33. package/dist/vera-renderer-keyed.min.js.map +1 -0
  34. package/dist/vera-renderer-slots.min.js +2 -0
  35. package/dist/vera-renderer-slots.min.js.map +1 -0
  36. package/dist/vera-renderer-spread.min.js +2 -0
  37. package/dist/vera-renderer-spread.min.js.map +1 -0
  38. package/dist/vera-renderer-tag.min.js +2 -0
  39. package/dist/vera-renderer-tag.min.js.map +1 -0
  40. package/dist/vera-renderer.min.js +1 -1
  41. package/dist/vera-renderer.min.js.map +1 -1
  42. package/package.json +24 -1
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Marks a template result with a stable key so list reconciliation moves it instead of rewriting
3
+ * it. Key all items in a list or none — mixing is undefined behaviour, as are duplicate keys.
4
+ *
5
+ * **Undefined means the list is arbitrary, not that the render fails.** With a repeated key, which
6
+ * item keeps the existing node is unspecified; the render still completes and the DOM still holds
7
+ * what the list holds. Development warns, once per render.
8
+ *
9
+ * ```js
10
+ * import { keyed } from '@verajs/renderer/keyed';
11
+ * rows.map((r) => keyed(r.id, html`<tr>...</tr>`))
12
+ * ```
13
+ */
14
+ declare const keyed: <T>(key: unknown, result: T) => T;
15
+
16
+ export { keyed };
17
+ //# sourceMappingURL=vera-renderer-keyed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vera-renderer-keyed.d.ts","sources":["../../src/keyed.ts"],"mappings":"AAEA;;;;;;;;;;;;AAYG;AAEH,cAAA,KAAA;;;;","names":[]}
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Keyed list reconciliation, as its own entry.
3
+ *
4
+ * **This module imports nothing.** Every other renderer entry inlines `./renderer.js` and carries
5
+ * its own template cache, so a module that imported one of them would be wrong for the others —
6
+ * `hydrate` in particular. Like `spread`, this one talks to whatever renderer is present through a
7
+ * mangling-exempt protocol, which is what makes it additive rather than a substitute.
8
+ *
9
+ * It also does not register. `keyed()` stamps `$r` onto the result it marks, so the algorithm
10
+ * travels with the values that need it: importing the marker is the whole installation, and a list
11
+ * always names the strategy that understands it. Two strategies therefore cannot disagree — there
12
+ * is nothing to disagree about, because the decision is per value rather than per registry.
13
+ */
14
+ /**
15
+ * The standard head/tail algorithm (as in lit's `repeat` and Vue): skip matching prefixes and
16
+ * suffixes, detect the two swap shapes directly, and fall back to key maps for arbitrary moves,
17
+ * removals and insertions.
18
+ *
19
+ * Everything before reconciliation — the mode switch, the empty list, the initial fill — has
20
+ * already happened in the renderer and is passed in, so this function only ever runs against a
21
+ * non-empty list that is already keyed.
22
+ */
23
+ /**
24
+ * **Reconciliation for a list whose nodes no longer live where its markers do.**
25
+ *
26
+ * `@verajs/renderer/slots` distributes a light-DOM host's children by MOVING them into the
27
+ * component's tree. A keyed list that renders those children therefore ends up split: the items are
28
+ * inside the component, the part's own markers stay behind in the host. The two-ended diff below
29
+ * positions against those markers and against `end`, so every move it makes asks the host to insert
30
+ * before a reference that is somewhere else — `NotFoundError`, in both builds. Shadow DOM never hits
31
+ * this because the platform PROJECTS rather than moves: the nodes stay children of the host.
32
+ *
33
+ * The way out is to stop looking for an anchor. Walking the new order in REVERSE, each item is
34
+ * placed immediately before its successor **in its own container**, and the last item in each
35
+ * container is left exactly where it is. That needs no end marker, no part boundary, and no
36
+ * knowledge of slots — and it is what makes a list SPLIT ACROSS SLOTS come out right for free,
37
+ * since items in different containers simply have different successors. Native does the same thing
38
+ * for the same input: order within each slot follows the logical order.
39
+ *
40
+ * Items created here go into the host, not into a container, because distribution is the observer's
41
+ * job and has not run yet. They are skipped by the placement pass for that render and land in slot
42
+ * order when it does.
43
+ */
44
+ const reconcileRelocated = (part, newValues, items, parent, end) => {
45
+ const count = newValues.length;
46
+ const byKey = new Map();
47
+ for (const item of items)
48
+ if (item !== null)
49
+ byKey.set(item.$k, item);
50
+ const newItems = new Array(count);
51
+ for (let i = 0; i < count; i++) {
52
+ const existing = byKey.get(newValues[i].key);
53
+ if (existing !== undefined) {
54
+ part.$u(existing, newValues[i]);
55
+ newItems[i] = existing;
56
+ byKey.delete(newValues[i].key);
57
+ }
58
+ }
59
+ /** Whatever kept no key is gone. `$d` moves into a scratch fragment, so its parent is irrelevant. */
60
+ for (const dropped of byKey.values())
61
+ part.$d(dropped);
62
+ /**
63
+ * **One reverse pass that both places and creates**, so an item's successor is already final when
64
+ * it is needed — and it is needed twice. Placing reads it as the reference; CREATING reads the
65
+ * container it lives in, which is the only way a new item can land among its logical neighbours.
66
+ *
67
+ * Creating in the host instead would be simpler and is wrong: the observer distributes it later
68
+ * and appends it, so an insertion in the middle of a list arrives at the end. Creating it in the
69
+ * successor's container puts it where native would — and if it names a DIFFERENT slot than its
70
+ * neighbour, it is in the host's subtree with a `slot` attribute, which is exactly what the
71
+ * observer is watching for, so that case corrects itself.
72
+ *
73
+ * `$m` short-circuits an item already in position, which is what keeps this from re-attaching a
74
+ * whole list; re-attaching is not free, it blurs focus and restarts transitions.
75
+ */
76
+ const successorIn = new Map();
77
+ for (let i = count - 1; i >= 0; i--) {
78
+ const item = newItems[i];
79
+ if (item === undefined)
80
+ continue; // created below, in forward order, once neighbours are final
81
+ const container = part.$f(item).parentNode;
82
+ if (container === null)
83
+ continue;
84
+ const successor = successorIn.get(container);
85
+ if (successor !== undefined)
86
+ part.$m(item, successor, container);
87
+ successorIn.set(container, part.$f(item));
88
+ }
89
+ /**
90
+ * **Creations run FORWARD, after every surviving item is in its final place.** Two reasons.
91
+ * A new item belongs beside its logical successor, and the successor's position is only final
92
+ * once the reverse pass above has run. And consecutive new rows must land in logical order:
93
+ * created back-to-front they arrive in the host reversed, the observer captures them in
94
+ * arrival order, and the list renders permuted.
95
+ *
96
+ * Created under the HOST, before `end` — the part's own boundary. Created straight into the
97
+ * component's tree they would read as the component's own output and never be captured;
98
+ * appended to the host's tail they would sit in the component's region, which is the same
99
+ * mistake. Between the part's markers they are unambiguously the host's content, which the
100
+ * observer captures with native semantics. A new item whose logical successor lives inside
101
+ * the component is then moved beside it — a move, which the observer already reads correctly.
102
+ */
103
+ for (let i = 0; i < count; i++) {
104
+ if (newItems[i] !== undefined)
105
+ continue;
106
+ const created = part.$c(newValues[i], parent, end);
107
+ const following = i + 1 < count ? newItems[i + 1] : undefined;
108
+ if (following !== undefined) {
109
+ const first = part.$f(following);
110
+ if (first.parentNode !== null && first.parentNode !== parent)
111
+ part.$m(created, first, first.parentNode);
112
+ }
113
+ newItems[i] = created;
114
+ }
115
+ return newItems;
116
+ };
117
+ const reconcile = (part, newValues, items, parent, end) => {
118
+ const count = newValues.length;
119
+ /**
120
+ * Zero-allocation fast path for the dominant case: same length, same key order — a pure in-place
121
+ * update (a selection change, a field edit). No key array, no output array, no null checks. Falls
122
+ * through to the full algorithm on the first mismatch; the items already updated re-verify there
123
+ * as cheap no-op compares.
124
+ */
125
+ if (items.length === count) {
126
+ let i = 0;
127
+ while (i < count && items[i].$k === newValues[i].key) {
128
+ part.$u(items[i], newValues[i]);
129
+ i++;
130
+ }
131
+ if (i === count)
132
+ return items;
133
+ }
134
+ /**
135
+ * **Has anything moved this list's nodes out from under its markers?**
136
+ *
137
+ * Only `@verajs/renderer/slots` does today, but the question is asked of the DOM rather than of
138
+ * that module — keyed imports nothing, and a list does not need to know what moved its nodes to
139
+ * know that they moved.
140
+ *
141
+ * Placed after the no-change fast path, so the dominant case (same keys, same order) never
142
+ * reaches it. What remains is one `parentNode` read per item against a diff that already does far
143
+ * more per item, and it breaks on the first mismatch, so the case it exists for costs exactly one.
144
+ */
145
+ for (let i = 0; i < items.length; i++)
146
+ if (part.$f(items[i]).parentNode !== parent)
147
+ return reconcileRelocated(part, newValues, items, parent, end);
148
+ const oldItems = items;
149
+ const newKeys = new Array(count);
150
+ for (let i = 0; i < count; i++)
151
+ newKeys[i] = newValues[i].key;
152
+ /**
153
+ * Said once, where it is nearly free: the general algorithm already walks every key, and a list
154
+ * whose keys never move never reaches here at all. A duplicate key is a mistake that behaves
155
+ * *correctly* in the common case and arbitrarily in the rest, which is the shape of bug that
156
+ * survives a test suite.
157
+ */
158
+ if (true && new Set(newKeys).size !== count) {
159
+ const seen = new Set();
160
+ const repeated = newKeys.filter((key) => (seen.has(key) ? true : (seen.add(key), false)));
161
+ console.warn(`[vera] keyed: the key ${String(repeated[0])} is used by more than one item in this list. ` +
162
+ `A key identifies one item, so which of them keeps the existing DOM is not defined — ` +
163
+ `the list still renders, but nothing about which node ends up where can be relied on.`);
164
+ }
165
+ const newItems = new Array(count);
166
+ let oldHead = 0;
167
+ let oldTail = oldItems.length - 1;
168
+ let newHead = 0;
169
+ let newTail = count - 1;
170
+ let newKeyToIndex;
171
+ let oldKeyToIndex;
172
+ const refAt = (i) => i < count && newItems[i] !== undefined ? part.$f(newItems[i]) : end;
173
+ while (oldHead <= oldTail && newHead <= newTail) {
174
+ if (oldItems[oldHead] === null)
175
+ oldHead++;
176
+ else if (oldItems[oldTail] === null)
177
+ oldTail--;
178
+ else if (oldItems[oldHead].$k === newKeys[newHead]) {
179
+ part.$u((newItems[newHead] = oldItems[oldHead]), newValues[newHead]);
180
+ oldHead++;
181
+ newHead++;
182
+ }
183
+ else if (oldItems[oldTail].$k === newKeys[newTail]) {
184
+ part.$u((newItems[newTail] = oldItems[oldTail]), newValues[newTail]);
185
+ oldTail--;
186
+ newTail--;
187
+ }
188
+ else if (oldItems[oldHead].$k === newKeys[newTail]) {
189
+ const item = oldItems[oldHead];
190
+ part.$m(item, refAt(newTail + 1), parent);
191
+ part.$u(item, newValues[newTail]);
192
+ newItems[newTail] = item;
193
+ oldHead++;
194
+ newTail--;
195
+ }
196
+ else if (oldItems[oldTail].$k === newKeys[newHead]) {
197
+ const item = oldItems[oldTail];
198
+ part.$m(item, part.$f(oldItems[oldHead]), parent);
199
+ part.$u(item, newValues[newHead]);
200
+ newItems[newHead] = item;
201
+ oldTail--;
202
+ newHead++;
203
+ }
204
+ else {
205
+ if (newKeyToIndex === undefined) {
206
+ newKeyToIndex = new Map();
207
+ for (let i = newHead; i <= newTail; i++)
208
+ newKeyToIndex.set(newKeys[i], i);
209
+ oldKeyToIndex = new Map();
210
+ for (let i = oldHead; i <= oldTail; i++) {
211
+ if (oldItems[i] !== null)
212
+ oldKeyToIndex.set(oldItems[i].$k, i);
213
+ }
214
+ }
215
+ if (!newKeyToIndex.has(oldItems[oldHead].$k)) {
216
+ part.$d(oldItems[oldHead]);
217
+ oldHead++;
218
+ }
219
+ else if (!newKeyToIndex.has(oldItems[oldTail].$k)) {
220
+ part.$d(oldItems[oldTail]);
221
+ oldTail--;
222
+ }
223
+ else {
224
+ const oldIndex = oldKeyToIndex.get(newKeys[newHead]);
225
+ /**
226
+ * **`oldItems[oldIndex]` can be null, and reading it crashed the render.** The map holds one
227
+ * index per key, so a list where a key appears twice finds, for the second one, the slot the
228
+ * first already consumed and nulled. `part.$m(null, …)` then read `_element` of null and took
229
+ * the whole render down with a `TypeError` naming the renderer's internals rather than
230
+ * anything the caller wrote.
231
+ *
232
+ * Duplicate keys are documented as undefined behaviour and stay that way — which of the two
233
+ * keeps the existing node is not specified. Undefined must still mean *a list*, though, not
234
+ * an exception from three frames inside a private algorithm: the shapes that crash are
235
+ * particular (a duplicate **and** a reorder **and** a new key, found by fuzzing over a
236
+ * four-key alphabet), so this passes in development and takes the page down later.
237
+ *
238
+ * Two ways a slot can already be spoken for, and both have to be checked. The map nulls what
239
+ * it consumes, so `oldItems[oldIndex] === null` catches one. The other is invisible: the map
240
+ * is built once, and the head/tail branches above consume items by *moving the pointers*
241
+ * without nulling anything — so an index that was live when the map was built can now sit
242
+ * outside `[oldHead, oldTail]`. With unique keys that is unreachable, because a key is looked
243
+ * up at most once; with a repeated key it hands the same item to two positions, and the list
244
+ * then renders one item short of what it holds. Checking only for null fixed the crash and
245
+ * left that, which is the worse of the two — nothing throws and the page is quietly wrong.
246
+ *
247
+ * Treating either as "not found" gives the second occurrence a fresh item, which is what the
248
+ * branch below already does for a key that never existed.
249
+ */
250
+ const reusable = oldIndex === undefined || oldIndex < oldHead || oldIndex > oldTail
251
+ ? null
252
+ : oldItems[oldIndex];
253
+ if (reusable === null) {
254
+ newItems[newHead] = part.$c(newValues[newHead], parent, part.$f(oldItems[oldHead]));
255
+ }
256
+ else {
257
+ const item = reusable;
258
+ part.$m(item, part.$f(oldItems[oldHead]), parent);
259
+ part.$u(item, newValues[newHead]);
260
+ newItems[newHead] = item;
261
+ oldItems[oldIndex] = null;
262
+ }
263
+ newHead++;
264
+ }
265
+ }
266
+ }
267
+ /**
268
+ * The trailing fill inserts every remaining item before the same reference — `refAt(newTail + 1)`
269
+ * cannot move while the loop runs, because the loop itself only fills slots *below* it. Built
270
+ * into a fragment and landed with one `insertBefore`, an append of 1 000 rows costs one live-DOM
271
+ * insertion instead of 1 000 — the same batching the renderer's index-mode grow path has always
272
+ * had, which this path silently lacked. A single item skips the fragment: one insert either way.
273
+ */
274
+ if (newHead < newTail) {
275
+ const ref = refAt(newTail + 1);
276
+ const fragment = parent.ownerDocument.createDocumentFragment();
277
+ while (newHead <= newTail) {
278
+ newItems[newHead] = part.$c(newValues[newHead], fragment, null);
279
+ newHead++;
280
+ }
281
+ parent.insertBefore(fragment, ref);
282
+ }
283
+ else if (newHead === newTail) {
284
+ newItems[newHead] = part.$c(newValues[newHead], parent, refAt(newTail + 1));
285
+ newHead++;
286
+ }
287
+ while (oldHead <= oldTail) {
288
+ const item = oldItems[oldHead++];
289
+ if (item !== null)
290
+ part.$d(item);
291
+ }
292
+ return newItems;
293
+ };
294
+ /**
295
+ * Marks a template result with a stable key so list reconciliation moves it instead of rewriting
296
+ * it. Key all items in a list or none — mixing is undefined behaviour, as are duplicate keys.
297
+ *
298
+ * **Undefined means the list is arbitrary, not that the render fails.** With a repeated key, which
299
+ * item keeps the existing node is unspecified; the render still completes and the DOM still holds
300
+ * what the list holds. Development warns, once per render.
301
+ *
302
+ * ```js
303
+ * import { keyed } from '@verajs/renderer/keyed';
304
+ * rows.map((r) => keyed(r.id, html`<tr>...</tr>`))
305
+ * ```
306
+ */
307
+ const keyed = (key, result) => {
308
+ /**
309
+ * Two arguments, and the second is the one that goes missing — `keyed(row.id)` instead of
310
+ * `keyed(row.id, html\`…\`)`. It failed with `Cannot set properties of undefined (setting 'key')`,
311
+ * which names this function's internals and not the call.
312
+ */
313
+ if (true && (result === null || typeof result !== 'object'))
314
+ throw new TypeError(`keyed: expected a template as the second argument and received ${String(result)}. ` +
315
+ `It marks a template with a key — \`keyed(row.id, html\`<li>…</li>\`)\`.`);
316
+ result.key = key;
317
+ result.$r = reconcile;
318
+ return result;
319
+ };
320
+
321
+ export { keyed };
322
+ //# sourceMappingURL=vera-renderer-keyed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vera-renderer-keyed.js","sources":["../../src/keyed.ts"],"sourcesContent":["import type { Item, KeyedResult, ListStrategy } from './renderer.js';\n\n/**\n * Keyed list reconciliation, as its own entry.\n *\n * **This module imports nothing.** Every other renderer entry inlines `./renderer.js` and carries\n * its own template cache, so a module that imported one of them would be wrong for the others —\n * `hydrate` in particular. Like `spread`, this one talks to whatever renderer is present through a\n * mangling-exempt protocol, which is what makes it additive rather than a substitute.\n *\n * It also does not register. `keyed()` stamps `$r` onto the result it marks, so the algorithm\n * travels with the values that need it: importing the marker is the whole installation, and a list\n * always names the strategy that understands it. Two strategies therefore cannot disagree — there\n * is nothing to disagree about, because the decision is per value rather than per registry.\n */\n\n/**\n * The standard head/tail algorithm (as in lit's `repeat` and Vue): skip matching prefixes and\n * suffixes, detect the two swap shapes directly, and fall back to key maps for arbitrary moves,\n * removals and insertions.\n *\n * Everything before reconciliation — the mode switch, the empty list, the initial fill — has\n * already happened in the renderer and is passed in, so this function only ever runs against a\n * non-empty list that is already keyed.\n */\n/**\n * **Reconciliation for a list whose nodes no longer live where its markers do.**\n *\n * `@verajs/renderer/slots` distributes a light-DOM host's children by MOVING them into the\n * component's tree. A keyed list that renders those children therefore ends up split: the items are\n * inside the component, the part's own markers stay behind in the host. The two-ended diff below\n * positions against those markers and against `end`, so every move it makes asks the host to insert\n * before a reference that is somewhere else — `NotFoundError`, in both builds. Shadow DOM never hits\n * this because the platform PROJECTS rather than moves: the nodes stay children of the host.\n *\n * The way out is to stop looking for an anchor. Walking the new order in REVERSE, each item is\n * placed immediately before its successor **in its own container**, and the last item in each\n * container is left exactly where it is. That needs no end marker, no part boundary, and no\n * knowledge of slots — and it is what makes a list SPLIT ACROSS SLOTS come out right for free,\n * since items in different containers simply have different successors. Native does the same thing\n * for the same input: order within each slot follows the logical order.\n *\n * Items created here go into the host, not into a container, because distribution is the observer's\n * job and has not run yet. They are skipped by the placement pass for that render and land in slot\n * order when it does.\n */\nconst reconcileRelocated: ListStrategy = (part, newValues, items, parent, end) => {\n const count = newValues.length;\n const byKey = new Map<unknown, Item>();\n for (const item of items) if (item !== null) byKey.set(item.$k, item);\n\n const newItems: Item[] = new Array(count);\n for (let i = 0; i < count; i++) {\n const existing = byKey.get((newValues[i] as KeyedResult).key);\n if (existing !== undefined) {\n part.$u(existing, newValues[i]);\n newItems[i] = existing;\n byKey.delete((newValues[i] as KeyedResult).key);\n }\n }\n /** Whatever kept no key is gone. `$d` moves into a scratch fragment, so its parent is irrelevant. */\n for (const dropped of byKey.values()) part.$d(dropped);\n\n /**\n * **One reverse pass that both places and creates**, so an item's successor is already final when\n * it is needed — and it is needed twice. Placing reads it as the reference; CREATING reads the\n * container it lives in, which is the only way a new item can land among its logical neighbours.\n *\n * Creating in the host instead would be simpler and is wrong: the observer distributes it later\n * and appends it, so an insertion in the middle of a list arrives at the end. Creating it in the\n * successor's container puts it where native would — and if it names a DIFFERENT slot than its\n * neighbour, it is in the host's subtree with a `slot` attribute, which is exactly what the\n * observer is watching for, so that case corrects itself.\n *\n * `$m` short-circuits an item already in position, which is what keeps this from re-attaching a\n * whole list; re-attaching is not free, it blurs focus and restarts transitions.\n */\n const successorIn = new Map<Node, Node>();\n for (let i = count - 1; i >= 0; i--) {\n const item = newItems[i];\n if (item === undefined) continue; // created below, in forward order, once neighbours are final\n const container = part.$f(item).parentNode;\n if (container === null) continue;\n const successor = successorIn.get(container);\n if (successor !== undefined) part.$m(item, successor, container);\n successorIn.set(container, part.$f(item));\n }\n /**\n * **Creations run FORWARD, after every surviving item is in its final place.** Two reasons.\n * A new item belongs beside its logical successor, and the successor's position is only final\n * once the reverse pass above has run. And consecutive new rows must land in logical order:\n * created back-to-front they arrive in the host reversed, the observer captures them in\n * arrival order, and the list renders permuted.\n *\n * Created under the HOST, before `end` — the part's own boundary. Created straight into the\n * component's tree they would read as the component's own output and never be captured;\n * appended to the host's tail they would sit in the component's region, which is the same\n * mistake. Between the part's markers they are unambiguously the host's content, which the\n * observer captures with native semantics. A new item whose logical successor lives inside\n * the component is then moved beside it — a move, which the observer already reads correctly.\n */\n for (let i = 0; i < count; i++) {\n if (newItems[i] !== undefined) continue;\n const created = part.$c(newValues[i], parent, end);\n const following = i + 1 < count ? newItems[i + 1] : undefined;\n if (following !== undefined) {\n const first = part.$f(following);\n if (first.parentNode !== null && first.parentNode !== parent) part.$m(created, first, first.parentNode);\n }\n newItems[i] = created;\n }\n return newItems;\n};\n\nconst reconcile: ListStrategy = (part, newValues, items, parent, end) => {\n const count = newValues.length;\n\n /**\n * Zero-allocation fast path for the dominant case: same length, same key order — a pure in-place\n * update (a selection change, a field edit). No key array, no output array, no null checks. Falls\n * through to the full algorithm on the first mismatch; the items already updated re-verify there\n * as cheap no-op compares.\n */\n if (items.length === count) {\n let i = 0;\n while (i < count && items[i].$k === (newValues[i] as KeyedResult).key) {\n part.$u(items[i], newValues[i]);\n i++;\n }\n if (i === count) return items;\n }\n\n /**\n * **Has anything moved this list's nodes out from under its markers?**\n *\n * Only `@verajs/renderer/slots` does today, but the question is asked of the DOM rather than of\n * that module — keyed imports nothing, and a list does not need to know what moved its nodes to\n * know that they moved.\n *\n * Placed after the no-change fast path, so the dominant case (same keys, same order) never\n * reaches it. What remains is one `parentNode` read per item against a diff that already does far\n * more per item, and it breaks on the first mismatch, so the case it exists for costs exactly one.\n */\n for (let i = 0; i < items.length; i++)\n if (part.$f(items[i]).parentNode !== parent)\n return reconcileRelocated(part, newValues, items, parent, end);\n\n const oldItems: (Item | null)[] = items;\n const newKeys: unknown[] = new Array(count);\n for (let i = 0; i < count; i++) newKeys[i] = (newValues[i] as KeyedResult).key;\n /**\n * Said once, where it is nearly free: the general algorithm already walks every key, and a list\n * whose keys never move never reaches here at all. A duplicate key is a mistake that behaves\n * *correctly* in the common case and arbitrarily in the rest, which is the shape of bug that\n * survives a test suite.\n */\n if (__DEV__ && new Set(newKeys).size !== count) {\n const seen = new Set<unknown>();\n const repeated = newKeys.filter((key) => (seen.has(key) ? true : (seen.add(key), false)));\n console.warn(\n `[vera] keyed: the key ${String(repeated[0])} is used by more than one item in this list. ` +\n `A key identifies one item, so which of them keeps the existing DOM is not defined — ` +\n `the list still renders, but nothing about which node ends up where can be relied on.`\n );\n }\n const newItems: Item[] = new Array(count);\n let oldHead = 0;\n let oldTail = oldItems.length - 1;\n let newHead = 0;\n let newTail = count - 1;\n let newKeyToIndex: Map<unknown, number> | undefined;\n let oldKeyToIndex: Map<unknown, number> | undefined;\n const refAt = (i: number): Node | null =>\n i < count && newItems[i] !== undefined ? part.$f(newItems[i]) : end;\n\n while (oldHead <= oldTail && newHead <= newTail) {\n if (oldItems[oldHead] === null) oldHead++;\n else if (oldItems[oldTail] === null) oldTail--;\n else if (oldItems[oldHead]!.$k === newKeys[newHead]) {\n part.$u((newItems[newHead] = oldItems[oldHead]!), newValues[newHead]);\n oldHead++;\n newHead++;\n } else if (oldItems[oldTail]!.$k === newKeys[newTail]) {\n part.$u((newItems[newTail] = oldItems[oldTail]!), newValues[newTail]);\n oldTail--;\n newTail--;\n } else if (oldItems[oldHead]!.$k === newKeys[newTail]) {\n const item = oldItems[oldHead]!;\n part.$m(item, refAt(newTail + 1), parent);\n part.$u(item, newValues[newTail]);\n newItems[newTail] = item;\n oldHead++;\n newTail--;\n } else if (oldItems[oldTail]!.$k === newKeys[newHead]) {\n const item = oldItems[oldTail]!;\n part.$m(item, part.$f(oldItems[oldHead]!), parent);\n part.$u(item, newValues[newHead]);\n newItems[newHead] = item;\n oldTail--;\n newHead++;\n } else {\n if (newKeyToIndex === undefined) {\n newKeyToIndex = new Map();\n for (let i = newHead; i <= newTail; i++) newKeyToIndex.set(newKeys[i], i);\n oldKeyToIndex = new Map();\n for (let i = oldHead; i <= oldTail; i++) {\n if (oldItems[i] !== null) oldKeyToIndex.set(oldItems[i]!.$k, i);\n }\n }\n if (!newKeyToIndex.has(oldItems[oldHead]!.$k)) {\n part.$d(oldItems[oldHead]!);\n oldHead++;\n } else if (!newKeyToIndex.has(oldItems[oldTail]!.$k)) {\n part.$d(oldItems[oldTail]!);\n oldTail--;\n } else {\n const oldIndex = oldKeyToIndex!.get(newKeys[newHead]);\n /**\n * **`oldItems[oldIndex]` can be null, and reading it crashed the render.** The map holds one\n * index per key, so a list where a key appears twice finds, for the second one, the slot the\n * first already consumed and nulled. `part.$m(null, …)` then read `_element` of null and took\n * the whole render down with a `TypeError` naming the renderer's internals rather than\n * anything the caller wrote.\n *\n * Duplicate keys are documented as undefined behaviour and stay that way — which of the two\n * keeps the existing node is not specified. Undefined must still mean *a list*, though, not\n * an exception from three frames inside a private algorithm: the shapes that crash are\n * particular (a duplicate **and** a reorder **and** a new key, found by fuzzing over a\n * four-key alphabet), so this passes in development and takes the page down later.\n *\n * Two ways a slot can already be spoken for, and both have to be checked. The map nulls what\n * it consumes, so `oldItems[oldIndex] === null` catches one. The other is invisible: the map\n * is built once, and the head/tail branches above consume items by *moving the pointers*\n * without nulling anything — so an index that was live when the map was built can now sit\n * outside `[oldHead, oldTail]`. With unique keys that is unreachable, because a key is looked\n * up at most once; with a repeated key it hands the same item to two positions, and the list\n * then renders one item short of what it holds. Checking only for null fixed the crash and\n * left that, which is the worse of the two — nothing throws and the page is quietly wrong.\n *\n * Treating either as \"not found\" gives the second occurrence a fresh item, which is what the\n * branch below already does for a key that never existed.\n */\n const reusable =\n oldIndex === undefined || oldIndex < oldHead || oldIndex > oldTail\n ? null\n : oldItems[oldIndex];\n if (reusable === null) {\n newItems[newHead] = part.$c(newValues[newHead], parent, part.$f(oldItems[oldHead]!));\n } else {\n const item = reusable;\n part.$m(item, part.$f(oldItems[oldHead]!), parent);\n part.$u(item, newValues[newHead]);\n newItems[newHead] = item;\n oldItems[oldIndex!] = null;\n }\n newHead++;\n }\n }\n }\n /**\n * The trailing fill inserts every remaining item before the same reference — `refAt(newTail + 1)`\n * cannot move while the loop runs, because the loop itself only fills slots *below* it. Built\n * into a fragment and landed with one `insertBefore`, an append of 1 000 rows costs one live-DOM\n * insertion instead of 1 000 — the same batching the renderer's index-mode grow path has always\n * had, which this path silently lacked. A single item skips the fragment: one insert either way.\n */\n if (newHead < newTail) {\n const ref = refAt(newTail + 1);\n const fragment = parent.ownerDocument!.createDocumentFragment();\n while (newHead <= newTail) {\n newItems[newHead] = part.$c(newValues[newHead], fragment, null);\n newHead++;\n }\n parent.insertBefore(fragment, ref);\n } else if (newHead === newTail) {\n newItems[newHead] = part.$c(newValues[newHead], parent, refAt(newTail + 1));\n newHead++;\n }\n while (oldHead <= oldTail) {\n const item = oldItems[oldHead++];\n if (item !== null) part.$d(item);\n }\n return newItems;\n};\n\n/**\n * Marks a template result with a stable key so list reconciliation moves it instead of rewriting\n * it. Key all items in a list or none — mixing is undefined behaviour, as are duplicate keys.\n *\n * **Undefined means the list is arbitrary, not that the render fails.** With a repeated key, which\n * item keeps the existing node is unspecified; the render still completes and the DOM still holds\n * what the list holds. Development warns, once per render.\n *\n * ```js\n * import { keyed } from '@verajs/renderer/keyed';\n * rows.map((r) => keyed(r.id, html`<tr>...</tr>`))\n * ```\n */\nexport const keyed = <T>(key: unknown, result: T): T => {\n /**\n * Two arguments, and the second is the one that goes missing — `keyed(row.id)` instead of\n * `keyed(row.id, html\\`…\\`)`. It failed with `Cannot set properties of undefined (setting 'key')`,\n * which names this function's internals and not the call.\n */\n if (__DEV__ && (result === null || typeof result !== 'object'))\n throw new TypeError(\n `keyed: expected a template as the second argument and received ${String(result)}. ` +\n `It marks a template with a key — \\`keyed(row.id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EAAE,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAC3E,QAAA,OAAO,EAAE;IACX;AACA,IAAA,OAAO,OAAO,IAAI,OAAO,EAAE;AACzB,QAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,IAAI,KAAK,IAAI;AAAE,YAAA,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;IAClC;AACA,IAAA,OAAO,QAAQ;AACjB,CAAC;AAED;;;;;;;;;;;;AAYG;MACU,KAAK,GAAG,CAAI,GAAY,EAAE,MAAS,KAAO;AACrD;;;;AAIG;IACH,IAAI,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC;QAC5D,MAAM,IAAI,SAAS,CACjB,CAAA,+DAAA,EAAkE,MAAM,CAAC,MAAM,CAAC,CAAA,EAAA,CAAI;AAClF,YAAA,CAAA,uEAAA,CAAyE,CAC5E;AACF,IAAA,MAAsB,CAAC,GAAG,GAAG,GAAG;AAChC,IAAA,MAAsB,CAAC,EAAE,GAAG,SAAS;AACtC,IAAA,OAAO,MAAM;AACf;;;;"}
@@ -88,15 +88,6 @@ type TemplateResult = {
88
88
  /** Set by `keyed()`; drives keyed list reconciliation. */
89
89
  key?: unknown;
90
90
  };
91
- /**
92
- * Marks a template result with a stable key so list reconciliation moves it instead of rewriting
93
- * it. Key all items in a list or none — mixing is undefined behaviour, as are duplicate keys.
94
- *
95
- * ```js
96
- * rows.map((r) => keyed(r.id, html`<tr>...</tr>`))
97
- * ```
98
- */
99
- declare const keyed: <T>(key: unknown, result: T) => T;
100
91
  /**
101
92
  * Preserves the DOM of templates a child position toggles away from, instead of destroying it —
102
93
  * form values, scroll positions and media playback survive the round trip (lit-html calls this
@@ -105,20 +96,54 @@ declare const keyed: <T>(key: unknown, result: T) => T;
105
96
  * ```js
106
97
  * html`<div>${hold(editing ? editor() : viewer())}</div>`
107
98
  * ```
99
+ *
100
+ * **Anything that is not a template passes straight through.** There is nothing to park for a
101
+ * string, a list, `null` or `false`, and the branch that produces one is the ordinary shape of the
102
+ * expression this wraps — `hold(editing && editor())`, `hold(row ?? null)`. Wrapping those handed
103
+ * the renderer a `{ $h }` carrying a non-template, which reached the held-commit path and threw on
104
+ * `result.strings`: a whole render lost, from a value the same expression renders happily one
105
+ * character to the left. Decided here rather than in the renderer so the hot path pays nothing.
108
106
  */
109
- declare const hold: (result: TemplateResult) => {
107
+ declare const hold: <T>(result: T) => T | {
110
108
  $h: TemplateResult;
111
109
  };
112
110
  /**
113
- * Renders a template result into a container. Slots into Vera via `setRenderer(render)`; core's
114
- * built-in `html` tag already produces the accepted shape, so no `setHtml` call is required —
115
- * though lit-html's `html` also works, its results being structurally identical.
111
+ * Writes a template result into a container. The renderer's imperative draw: no reactivity, no
112
+ * lifecycle, no knowledge of components. Slots into Vera via `wire([renderer])`; core's built-in
113
+ * `html` tag already produces the accepted shape, so no `setHtml` call is required — though
114
+ * lit-html's `html` also works, its results being structurally identical.
115
+ *
116
+ * **It owns its own range and nothing else.** The first call appends a marker and anchors a root
117
+ * part there; later calls with the same container reuse that part and walk only the value slots, so
118
+ * nodes are updated in place rather than rebuilt. Content that was already in the container stays.
116
119
  *
117
- * HYDRATION lives in `@verajs/renderer/hydrate` — a drop-in superset entry whose `render` adopts
120
+ * **Named for the relationship, not the act.** It was `render` until 0.2.0, which collided with
121
+ * core's `render` — a different function, with a different arity, that declares a *reactive*
122
+ * template and commits a component's setup. Both were public and both were documented, so a reader
123
+ * who knew one misread the other. `renderElement` and `renderDom` were considered and rejected: this
124
+ * renders *into* a container, and the container is a `Node` — a shadow root and a fragment are both
125
+ * valid, so "element" would be a lie in the type. Argument order is lit-html's on purpose.
126
+ *
127
+ * HYDRATION lives in `@verajs/renderer/hydrate` — a drop-in superset entry whose `renderInto` adopts
118
128
  * existing server-rendered children on first render. SSR apps import from there instead of here;
119
129
  * this entry carries zero hydration code.
120
130
  */
121
- declare const render: (result: unknown, container: Node) => void;
131
+ declare const renderInto: (result: unknown, container: Node) => void;
132
+ declare const renderer: {
133
+ name: string;
134
+ on: "render";
135
+ fn: never;
136
+ priority: number;
137
+ /**
138
+ * Typed against the registry `wire` actually hands over, not a narrower shape that happens to
139
+ * describe the one lookup this makes. A structural `{ get(name: 'value'): … }` is **not**
140
+ * assignable from `Inserts`, so `wire([renderer])` failed to compile in a consumer's project while
141
+ * this repo's own typecheck — which reads sources, not the shipped `.d.ts` — saw nothing.
142
+ */
143
+ connect: (given: {
144
+ get(name: never): unknown;
145
+ }) => void;
146
+ };
122
147
 
123
148
  /** One template identity replacing another at the same position, and how often. */
124
149
  interface Churn {
@@ -155,7 +180,11 @@ declare const getReport: () => ProfileReport;
155
180
  declare const stopProfiling: () => ProfileReport;
156
181
  declare const isProfiling: () => boolean;
157
182
  /** Profile one synchronous stretch of work. */
158
- declare const profile: <T>(fn: () => T) => {
183
+ declare function profile<T>(fn: () => Promise<T>): Promise<{
184
+ result: T;
185
+ report: ProfileReport;
186
+ }>;
187
+ declare function profile<T>(fn: () => T): {
159
188
  result: T;
160
189
  report: ProfileReport;
161
190
  };
@@ -163,11 +192,22 @@ declare const profile: <T>(fn: () => T) => {
163
192
  * Mounts a live panel in the corner of the page and starts profiling. Returns a function that
164
193
  * removes it and stops. Plain DOM in a closed shadow root — it never renders itself through the
165
194
  * renderer, which would fold its own commits into the numbers it reports.
195
+ *
196
+ * **Calling it twice replaces the panel; it does not stack a second one.** Two panels are positioned
197
+ * in the same corner, so they overlap and neither is readable — and the failure went further than
198
+ * cosmetic. Each panel owns a `setInterval`, and each teardown calls `stopProfiling()`, which is
199
+ * global: closing the *second* panel stopped profiling for the *first*, which then repainted a
200
+ * frozen report on its own timer with nothing to say it had stopped. Worse, the natural way to reach
201
+ * this is a console — `showProfiler()`, look, `showProfiler()` again — where the first return value
202
+ * is gone, so that first interval could never be stopped at all.
203
+ *
204
+ * Replacing rather than returning the existing teardown, so a second call with different `options`
205
+ * takes effect instead of being silently ignored.
166
206
  */
167
207
  declare const showProfiler: (options?: OverlayOptions) => (() => void);
168
208
  /** Human-readable summary. The overlay renders the same data; this is for a console or a log. */
169
209
  declare const formatReport: (report: ProfileReport) => string;
170
210
 
171
- export { formatReport, getReport, hold, isProfiling, keyed, profile, render, showProfiler, startProfiling, stopProfiling };
211
+ export { formatReport, getReport, hold, isProfiling, profile, renderInto, renderer, showProfiler, startProfiling, stopProfiling };
172
212
  export type { Churn, OverlayOptions, ProfileReport, TemplateResult };
173
213
  //# sourceMappingURL=vera-renderer-profiler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vera-renderer-profiler.d.ts","sources":["../../../../../../src/overlay.ts","../../../../../../src/renderer.ts","../../../../../../src/profiler.ts"],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;;;;;;ACxBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DG;AAWH,KAAA,cAAA;;;;;;;AAOG;AACH;AACG;AACD;AACF;AAEA;;;;;;;;AAQG;AACH;AAEA;;;AAGG;AACH,kBAAe,WAAc,cAAc;AAC3C,QAAA,cAAA;AACA;;;;;;AA2IU;;AAGA;;oBAED,+BAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;ACvNN;AACH,WACE,KAAA;AAQF;AAKA;AAgCA,cAAa,cAAM;AACnB;AACA,cAAc,SAAE,QAAA,aAAA;AAChB;AACA,cAAY,aAAK,QAAA,aAAA;AACjB,cAAc,WAAE;AAChB;AACA,cAAc,OAAA;AACd;AACA,YAAY,aAAyB;AAErC;AACA;AACA;AACA;;;AAEwB,cAAI,YAAc,aAAa,cAAG;AACxD;AACF,cAAE,YAAA,WAAA,aAAA;;;;","names":[]}
1
+ {"version":3,"file":"vera-renderer-profiler.d.ts","sources":["../../src/overlay.ts","../../src/renderer.ts","../../src/profiler.ts"],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;;;;;;ACxBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DG;AAEH,KAAA,cAAS;AAYT;;;;;;;;;;;;;;;AAeG;AACH;AAEI;;AAGJ;;;AAGG;AACH,cAAA,IAAA;AACA,QAAM,cAAgB;AACtB;AAugBI;AACE;;AAEE;;AAEI;AACE;;;;;;;;;;;;AAYG;;AAEH;AACE,cAAA,UAAA,+BAAW,IAAA;;AACX;AAAG;;;AAGL;;;;AAIG;AACH;;AAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACxmBb,cAAA,SAAA,QAAA,aAAA;AACH;AASA,cAAS,aAAc,qBAAqB;AAK5C,yBAAyB;AAgCzB;AACA,iBAAe,OAAA,cAAA,OAAA,MAAA,OAAA;AACf;AACA,YAAW,aAAK;AAChB;AACA,iBAAgB,OAAA;AAChB;AACA,YAAY,aAAE;AACd;AACA;AAEA;AACA;AACA;AACA;;;AAEwB;AACtB;AACF;AAEA;AACA;AACA;;AAEE;AACE;AACA,cAAI,YAAc,aAAE,cAAA;;AACpB,cAAA,uBAA6B,aAAA;;;;","names":[]}