@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,499 @@
1
+ /**
2
+ * `true ` only: the one home for *"is this value something an attribute can carry?"*
3
+ *
4
+ * **Why it is a closed vocabulary and not a predicate.** The first design asked whether a value
5
+ * stringifies meaningfully — `String(v) === '[object Object]'` means it lost its data. Driven
6
+ * through 16 value shapes rather than reasoned about, that broke four ways, and the first is
7
+ * disqualifying: `String()` THROWS on `Object.create(null)`, on `{ toString: null }`, and on any
8
+ * object whose `toString` throws — so a diagnostic would have killed the page for an author using
9
+ * the recommended dictionary idiom. It also passed `["a","b"]` as `"a,b"` (one junk class, if that
10
+ * was a `class` binding) and `new Date()` as a timezone-bearing string, which is an SSR/CSR
11
+ * divergence manufactured out of correct-looking code. And it passed `Symbol('s')` while
12
+ * `` `${sym}` `` throws — a guard and its sink disagreeing about a single expression.
13
+ *
14
+ * "Does it stringify meaningfully" is an OPEN predicate over an unbounded, environment-dependent
15
+ * space, and open predicates cannot be audited. So the test is inverted and closed: **primitives
16
+ * pass; everything else is reported; anything else that should pass is a named row added on
17
+ * evidence.** The list has exactly one member so far.
18
+ *
19
+ * Credit where it is due: the four breaks were found by the omni engine's session, which drove the
20
+ * shapes rather than arguing about them, and the closed-vocabulary form is theirs.
21
+ */
22
+ /**
23
+ * Blessed non-primitives — types whose `toString` IS the value the author means.
24
+ *
25
+ * Tested by brand rather than `instanceof`, which is false across realms: a `URL` built in an
26
+ * iframe is not `instanceof` the parent's `URL`, and a diagnostic that fires on a correct value in
27
+ * one frame and not another is worse than none.
28
+ */
29
+ const brand = (value) => Object.prototype.toString.call(value);
30
+ /** One message per element+name+kind, so a value rebuilt every render does not flood the console. */
31
+ let reported;
32
+ /**
33
+ * Returns the complaint, or `null` when the value is fine. Never throws — the shapes that break a
34
+ * naive guard are exactly the ones worth reporting, so they reach the `object` arm and are named.
35
+ */
36
+ const attributeValueComplaint = (tag, name, value) => {
37
+ const type = typeof value;
38
+ if (type === 'string' || type === 'number' || type === 'boolean' || type === 'bigint')
39
+ return null;
40
+ if (type === 'object' && brand(value) === '[object URL]')
41
+ return null;
42
+ /**
43
+ * Keyed by BRAND, not by `typeof` — `Date`, `Array` and a plain object are all `'object'`, so a
44
+ * coarser key reported whichever arrived first and silently swallowed the rest. An author who
45
+ * fixed the Date would never have been told about the array.
46
+ */
47
+ const key = `${tag}|${name}|${type === 'object' ? brand(value) : type}`;
48
+ reported ??= new Set();
49
+ if (reported.has(key))
50
+ return null;
51
+ reported.add(key);
52
+ /**
53
+ * A function into an attribute is never what the author meant, but the REASON matters: on a
54
+ * custom element the Lit-era convention is that complex values are set as properties, so
55
+ * `<my-chart formatter={fn}>` is a coherent intention that this sink simply cannot express. The
56
+ * message names the binding that can, rather than blaming the author.
57
+ */
58
+ const said = type === 'function'
59
+ ? `a function, which becomes its own SOURCE TEXT`
60
+ : type === 'symbol'
61
+ ? `a symbol, which every DOM conversion refuses`
62
+ : Array.isArray(value)
63
+ ? `an array, which becomes its members joined by commas`
64
+ : brand(value) === '[object Date]'
65
+ ? `a Date, whose text carries the TIMEZONE of whichever side rendered it`
66
+ : `an ${type}, which cannot survive as text`;
67
+ /**
68
+ * Returned WITHOUT the `[vera]` prefix, which each call site writes as a literal.
69
+ * `tests/diagnostics-convention.test.mjs` reads the prefix off the call, so a message handed over
70
+ * as a variable is invisible to it — and its answer to that is an allowance list. Taking the
71
+ * allowance would have excused these two calls rather than checked them, which is the
72
+ * reclassification this audit keeps refusing; the literal at the call site is what every other
73
+ * diagnostic in the repo does anyway.
74
+ */
75
+ return (`renderer: the attribute \`${name}\` on <${tag}> was given ${said}. ` +
76
+ `An attribute value is a string and nothing else.\n` +
77
+ `If the element is meant to RECEIVE this value, bind a property instead — \`.${name}=\${value}\` ` +
78
+ `— which is how a custom element takes anything that is not text. If it is meant to be read as ` +
79
+ `text, convert it where you know what it means: \`date.toISOString()\`, \`list.join(' ')\`. ` +
80
+ `A Date in particular serializes with the SERVER's timezone on one side and the browser's on ` +
81
+ `the other, so it will not survive hydration.`);
82
+ };
83
+
84
+ /**
85
+ * `<div ${spread(props)}>` — bindings whose names are not known when the template is parsed.
86
+ *
87
+ * Template renderers bake attribute names in at parse time; that is what makes them small and fast,
88
+ * and it is why neither this renderer nor lit-html has had spread. Lit's spread PR has sat open as a
89
+ * draft since 2021, blocked on the questions answered below.
90
+ *
91
+ * **Why this ships separately.** The renderer holds one property read — a value at element position
92
+ * carrying `_$apply$` applies itself — and nothing else, so a base bundle grows 16 B rather than
93
+ * 176 B and an app that never spreads pays only that. Core and the renderer are the two packages
94
+ * where weight is absolute; this is not one of them, but it is still measured.
95
+ *
96
+ * The sigil rules are repeated here rather than shared through `@verajs/shared-utils`. That was
97
+ * tried: a shared resolver has to hand back both a kind and a name, and the tuple it allocates cost
98
+ * the renderer 10 B. Principle #5 permits deliberate duplication where two callers can legitimately
99
+ * diverge; #7 decides it, because the renderer is where bytes are not negotiable.
100
+ */
101
+ const ATTR = 0;
102
+ const PROPERTY = 1;
103
+ const BOOLEAN = 2;
104
+ /** `!name` — a property compared against the live DOM rather than against what this last wrote. */
105
+ const LIVE = 3;
106
+ const EVENT = 4;
107
+ const REF = 5;
108
+ /**
109
+ * A key that cannot be written into a tag, and therefore cannot be used at all.
110
+ *
111
+ * Measured in Chromium, `setAttribute` accepts `"`, `'` and `<` and rejects whitespace, `>`, `=`,
112
+ * `/` and NUL — but a name carrying a quote or a `<` cannot survive **markup**, so `@verajs/ssr`
113
+ * has to refuse it, and a key that works here and vanishes server-side is worse than one that works
114
+ * nowhere. The rule is therefore the HTML attribute-name restriction (control characters,
115
+ * whitespace, `"`, `'`, `>`, `/`, `=`) plus `<` and a backtick, applied identically on both sides.
116
+ *
117
+ * Skipped rather than thrown. `setAttribute` throws `InvalidCharacterError` on some of these, which
118
+ * took down the whole render — for one bad key in a props bag, on a binding whose entire purpose is
119
+ * names that are not known until runtime.
120
+ *
121
+ * The control-character range is the point of the rule, not a mistake in it: a name carrying one
122
+ * is exactly what must never reach markup.
123
+ */
124
+
125
+ const UNSAFE_NAME = /^$|[\s"'>/=<`]|[\u0000-\u001f\u007f]/;
126
+ /**
127
+ * **Sinks spread refuses, because spread is the one place the template security model breaks.**
128
+ *
129
+ * The renderer's posture on `.innerHTML` (README, "security") rests on three properties of the
130
+ * template spelling: greppable, obviously yours, reviewable as the decision it is. A spread key
131
+ * arrives at RUNTIME inside a props object — often built from data — and has none of the three:
132
+ * `spread(fromJson)` carrying `.innerHTML` or an inline `onclick` attribute is markup or code
133
+ * injection through a door no grep can see. So spread refuses the sinks and points at the template
134
+ * spelling, which remains fully available to an author who means it.
135
+ *
136
+ * The list, deliberately minimal and named: `innerHTML`/`outerHTML` as property or live-property
137
+ * keys; `srcdoc` as an attribute (an iframe's inline document); and any attribute whose name the
138
+ * browser would treat as an inline handler (`on…` in any casing) — EXCEPT the documented event
139
+ * spelling `on` + Capital, which the constructor converts to a real listener and which therefore
140
+ * never becomes an attribute. The exemption mirrors the constructor's test byte for byte, because
141
+ * `ONCLICK` must not slip through as "looks like the event spelling": the constructor only
142
+ * converts a lowercase `on`, so only that exact shape is exempt.
143
+ *
144
+ * Returns the hint for the diagnostic, or null for a permitted key.
145
+ */
146
+ const refusedSink = (key) => {
147
+ const first = key[0];
148
+ if (first === '.' || first === '!') {
149
+ const name = key.slice(1);
150
+ if (name === 'innerHTML' || name === 'outerHTML')
151
+ return 'write it in the template — html`<div .innerHTML=${trusted}>` — sanitized first (renderer README, security note)';
152
+ /**
153
+ * `element.__proto__ = value` is not a property write — it hits Object.prototype's
154
+ * `__proto__` ACCESSOR and replaces the element's prototype, stripping every DOM method it
155
+ * has. The element is bricked, and the crash lands LATER, in whatever binding next calls
156
+ * `removeAttribute` on it — a data-driven render-kill with a stack that names the renderer
157
+ * and not the data. Found by the run-14 payload probe; there is no legitimate use, so unlike
158
+ * `.innerHTML` there is no template spelling to point at.
159
+ */
160
+ /** The deliberate twin of the same refusal in `AttrPart`'s constructor (`./renderer.ts`), for
161
+ * the template spellings `.name` / `!name`. Independent bundles, neither imports the other, so
162
+ * the rule is copied — and a fix visits both. `tests/dangerous-binding-matrix.test.mjs` holds
163
+ * the two spellings to the same answer. */
164
+ if (name === '__proto__')
165
+ return "assigning __proto__ replaces the element's own prototype and destroys it — no property write does this, and no use of it is legitimate";
166
+ return null;
167
+ }
168
+ if (first === '?' || first === '@' || first === '&')
169
+ return null;
170
+ /** The event spelling the constructor converts: `on` + Capital, lowercase `on` only. */
171
+ if (first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91)
172
+ return null;
173
+ const lower = key.toLowerCase();
174
+ if (lower === 'srcdoc')
175
+ return 'an inline iframe document is markup injection by definition — bind it in the template if you truly mean it';
176
+ if (lower.length > 2 && lower.startsWith('on'))
177
+ return 'an inline handler attribute is code from data — pass a function as `on` + Capital (onClick) or `@click` instead';
178
+ return null;
179
+ };
180
+ /** Module-local: one identity comparison, not a global symbol-registry lookup per binding. */
181
+ const UNSET = Symbol();
182
+ /**
183
+ * A class, not an object literal, so `handleEvent` exists once on the prototype. As a literal it was
184
+ * a fresh closure per bound key — allocation proportional to the size of every props bag.
185
+ */
186
+ class Binding {
187
+ _kind;
188
+ _name;
189
+ _element;
190
+ /** What the element held before this binding took over. Releasing puts it back. */
191
+ _initial;
192
+ _committed = UNSET;
193
+ _handler = null;
194
+ constructor(element, key) {
195
+ const first = key[0];
196
+ let kind = first === '.'
197
+ ? PROPERTY
198
+ : first === '?'
199
+ ? BOOLEAN
200
+ : first === '@'
201
+ ? EVENT
202
+ : first === '&'
203
+ ? REF
204
+ : first === '!'
205
+ ? LIVE
206
+ : ATTR;
207
+ let name = kind ? key.slice(1) : key;
208
+ /** `on` + a capital: `onClick` ≡ `@click`. All-lowercase `onclick` never reaches here — it is
209
+ * an inline-handler attribute, which `refusedSink` rejects before a binding exists. */
210
+ if (kind === ATTR && first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91) {
211
+ kind = EVENT;
212
+ name = key.slice(2).toLowerCase();
213
+ }
214
+ this._kind = kind;
215
+ this._name = name;
216
+ this._element = element;
217
+ this._initial =
218
+ kind === ATTR
219
+ ? element.getAttribute(name)
220
+ : kind === BOOLEAN
221
+ ? element.hasAttribute(name)
222
+ : kind === PROPERTY || kind === LIVE
223
+ ? element[name]
224
+ : null;
225
+ }
226
+ /**
227
+ * **Two shapes, because `addEventListener` takes two** — the same rule `AttrPart.handleEvent`
228
+ * applies, and it did not travel here when that one was fixed. A function is called with the
229
+ * element as `this`; an object with a `handleEvent` method is invoked through it — the platform's
230
+ * own `EventListenerObject` protocol, which every engine accepts. This called `.call()`
231
+ * unconditionally, so `spread({ onClick: { handleEvent } })` bound without complaint, never
232
+ * fired, and raised `this._handler.call is not a function` on **every** dispatch — while the
233
+ * identical value through a written `@click` worked.
234
+ *
235
+ * Anything else is inert rather than throwing, exactly as there: development names it at the
236
+ * binding (see the event branch in `write`), where the mistake still is.
237
+ */
238
+ handleEvent(event) {
239
+ const handler = this._handler;
240
+ if (typeof handler === 'function')
241
+ handler.call(this._element, event);
242
+ else if (typeof handler?.handleEvent === 'function')
243
+ handler.handleEvent(event);
244
+ }
245
+ }
246
+ /**
247
+ * Keyed by the **part**, not the element.
248
+ *
249
+ * Keyed by element, `<div ${spread(a)} ${spread(b)}>` shares one map: whichever applies second sees
250
+ * the other's keys as absent from its own props and releases them. Measured — the first spread's
251
+ * attributes silently vanished. The part is one per element-position slot, which is exactly the
252
+ * ownership boundary, and the renderer reuses it across renders.
253
+ */
254
+ const owned = new WeakMap();
255
+ const write = (binding, value) => {
256
+ /** One comparison per key per render — the same dirty check a written binding gets. */
257
+ /**
258
+ * A live property asks the element rather than its own memory — see `AttrPart` in the renderer.
259
+ * The dirty check is what keeps a field someone typed into, and it is exactly wrong for a control
260
+ * whose DOM state changes when a *sibling* is interacted with, a radio group being the case.
261
+ */
262
+ if (binding._kind === LIVE) {
263
+ binding._committed = value;
264
+ const live = binding._element;
265
+ if (live[binding._name] !== value)
266
+ live[binding._name] = value;
267
+ return;
268
+ }
269
+ if (value === binding._committed)
270
+ return;
271
+ binding._committed = value;
272
+ const element = binding._element;
273
+ const name = binding._name;
274
+ const kind = binding._kind;
275
+ if (kind === ATTR) {
276
+ if (value == null)
277
+ element.removeAttribute(name);
278
+ else {
279
+ if (true ) {
280
+ const complaint = attributeValueComplaint(element.localName, name, value);
281
+ if (complaint !== null)
282
+ console.warn(`[vera] ${complaint}`);
283
+ }
284
+ /**
285
+ * `` `${value}` ``, never `String(value)` — the two differ on exactly one thing and it is the
286
+ * one that matters here. `String(sym)` returns `"Symbol(s)"` while every DOM conversion and
287
+ * `@verajs/ssr`'s own escaper throw, so this sink was the ONLY one of three that accepted a
288
+ * symbol, writing to the client an attribute the server refuses to produce. The rule was
289
+ * already recorded in `@verajs/ssr`'s `escapeHtml` — "serving Symbol(s) into markup the client
290
+ * cannot reproduce does not make anything work, it moves the failure across the boundary and
291
+ * strips the context" — and this file used the other form anyway. A house rule written down
292
+ * in one of three homes is a house rule in none of them.
293
+ */
294
+ element.setAttribute(name, `${value}`);
295
+ }
296
+ }
297
+ else if (kind === PROPERTY) {
298
+ element[name] = value;
299
+ }
300
+ else if (kind === BOOLEAN) {
301
+ element.toggleAttribute(name, !!value);
302
+ }
303
+ else if (kind === REF) {
304
+ /**
305
+ * `&name` is the written form's ref sigil (`<input &field=${myRef} />`), and it was the one
306
+ * binding kind a spread could not express: the key fell through to `ATTR` and
307
+ * `setAttribute('&field', …)` threw on the client while the server wrote `&field="[object
308
+ * Object]"` into the markup. A function is called with the element, an object gets it assigned
309
+ * to `.value` — the same two shapes `AttrPart` handles.
310
+ */
311
+ if (typeof value === 'function')
312
+ value(element);
313
+ else if (value !== null && typeof value === 'object')
314
+ value.value = element;
315
+ }
316
+ else {
317
+ /**
318
+ * A listener is validated when a *user* clicks, which in development may be never — so it is
319
+ * checked where it is written, the same rule `AttrPart` applies to `@event`. `false` stays
320
+ * silent: `{ onClick: enabled && onClick }` is the ordinary conditional form and already
321
+ * behaves correctly, since `handleEvent` finds nothing callable and does nothing.
322
+ */
323
+ if (true && value != null && value !== false && typeof value !== 'function' &&
324
+ typeof value?.handleEvent !== 'function')
325
+ console.warn(`[vera] spread: @${name} on <${element.localName}> was given ` +
326
+ `${typeof value === 'object' ? 'an object with no handleEvent method' : `a ${typeof value}`}, ` +
327
+ `which cannot listen — the event will do nothing.\n` +
328
+ `Pass a function, or an object with a handleEvent method. A missing handler is ` +
329
+ `\`undefined\` or \`false\`, both of which are fine; this is neither.`);
330
+ if (binding._handler === null && value != null)
331
+ element.addEventListener(name, binding);
332
+ binding._handler = value ?? null;
333
+ }
334
+ };
335
+ /**
336
+ * A key that disappeared between renders restores what the element held before the binding existed.
337
+ *
338
+ * This is the question Lit's PR is stuck on, and the trap is asking it as "what value means absent".
339
+ * For a property there is no answer: assigning `undefined` runs through coercing setters, so
340
+ * dropping `.value` yields `""` rather than reverting, and `delete` cannot remove a prototype
341
+ * accessor. Asked instead as *"undo what this binding did"* it is well defined for every kind and
342
+ * never invents a value the author did not write — the initial state was, by definition, acceptable
343
+ * before the binding arrived.
344
+ *
345
+ * And asked that way it needs no code of its own: releasing is writing the initial value back.
346
+ * `null` removes an attribute, `false` untoggles a boolean, `undefined` restores a property to
347
+ * pristine, and an event handler falls to `null` — every case the existing commit already handles.
348
+ * The separate per-kind teardown this replaced was fourteen lines saying the same thing twice.
349
+ *
350
+ * Deliberately unguarded by an ownership check (`is the value still the one we wrote?`). That only
351
+ * matters when a component reassigns a property its parent is binding, which is already confused;
352
+ * per principle #3 the machinery waits for evidence rather than being pre-built.
353
+ */
354
+ function apply(element, part) {
355
+ const props = this._props;
356
+ let bindings = owned.get(part);
357
+ if (bindings === undefined)
358
+ owned.set(part, (bindings = new Map()));
359
+ /**
360
+ * Counted here rather than with `Object.keys(props).length`, which allocates an array on every
361
+ * render of every spread — garbage in the render path, for a number already being walked.
362
+ */
363
+ let count = 0;
364
+ for (const key in props) {
365
+ count++;
366
+ /**
367
+ * Counted before it is skipped, so the size comparison below still describes the key set — a
368
+ * refused key that changed the count would make every render look like a removal.
369
+ */
370
+ if (UNSAFE_NAME.test(key[0] === '.' || key[0] === '?' || key[0] === '@' || key[0] === '&' ? key.slice(1) : key)) {
371
+ if (true )
372
+ console.warn(`[vera] spread: ignoring the key ${JSON.stringify(key)} — an attribute name ` +
373
+ `cannot contain whitespace, a quote, \`<\`, \`>\`, \`/\`, \`=\` or a control character, ` +
374
+ `and one that cannot be written into markup would not survive server rendering.`);
375
+ continue;
376
+ }
377
+ /** Counted above for the same reason the unsafe skip is. */
378
+ const refused = refusedSink(key);
379
+ if (refused !== null) {
380
+ if (true )
381
+ console.warn(`[vera] spread: refusing ${JSON.stringify(key)} — spread names arrive at runtime, which is ` +
382
+ `exactly the property that makes this sink unreviewable; ${refused}.`);
383
+ continue;
384
+ }
385
+ let binding = bindings.get(key);
386
+ if (binding === undefined)
387
+ bindings.set(key, (binding = new Binding(element, key)));
388
+ write(binding, props[key]);
389
+ }
390
+ /**
391
+ * A size mismatch is the only way a key can have gone: every key in `props` was just visited, so
392
+ * equal sizes means equal sets. The steady-state render of an unchanged shape — overwhelmingly the
393
+ * common case — costs one integer comparison, not a scan.
394
+ */
395
+ if (bindings.size !== count) {
396
+ for (const [key, binding] of bindings) {
397
+ if (key in props)
398
+ continue;
399
+ bindings.delete(key);
400
+ write(binding, binding._initial);
401
+ }
402
+ }
403
+ }
404
+ /**
405
+ * The server half of the protocol: hand back every binding, resolved, and let the renderer that
406
+ * asked decide what belongs in markup.
407
+ *
408
+ * Deliberately *not* a serializer. This package knows what a key means — `.value` is a property,
409
+ * `?disabled` a boolean, `onClick` an event — and nothing else. Whether a property belongs in
410
+ * server markup (`value`, `checked`, `selected` do; the rest are client state) and how a value is
411
+ * escaped are `@verajs/ssr`'s decisions, and principle #8 wants escaping in exactly one place. So
412
+ * this returns data, never a string.
413
+ *
414
+ * Kinds are single characters rather than the module's numeric constants, because this crosses a
415
+ * package boundary: `a`ttribute, `b`oolean, `p`roperty, `e`vent, `r`ef. A ref is client state with
416
+ * no markup, exactly like an event, and the serializer drops both.
417
+ */
418
+ function attributes() {
419
+ const out = [];
420
+ for (const key in this._props) {
421
+ /** The client refusal, applied at the serializer boundary too — one predicate, both renders.
422
+ * Without this, a refused key was merely inert in the browser and LIVE in server markup. */
423
+ if (refusedSink(key) !== null)
424
+ continue;
425
+ const first = key[0];
426
+ /** `!` reports as a property: the server has nothing to re-read, so it serializes as `.` does. */
427
+ const kind = first === '.' || first === '!'
428
+ ? 'p'
429
+ : first === '?'
430
+ ? 'b'
431
+ : first === '@'
432
+ ? 'e'
433
+ : first === '&'
434
+ ? 'r'
435
+ : 'a';
436
+ if (kind !== 'a') {
437
+ out.push([kind, key.slice(1), this._props[key]]);
438
+ }
439
+ else if (first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91) {
440
+ out.push(['e', key.slice(2).toLowerCase(), this._props[key]]);
441
+ }
442
+ else {
443
+ out.push(['a', key, this._props[key]]);
444
+ }
445
+ }
446
+ return out;
447
+ }
448
+ /**
449
+ * Branded rather than duck-typed: the element position already means "element ref", and a props bag
450
+ * is indistinguishable from a ref object — `{ value: 5 }` is legitimately either.
451
+ */
452
+ const spread = (props) => {
453
+ /**
454
+ * **A props bag that is not an object is iterated anyway, and a browser accepts the result.**
455
+ *
456
+ * Everything below reads `props` with `Object.keys`/`Object.entries`, which answer for any value:
457
+ * a **string** yields its character indices, so `spread('text')` sets four attributes named `0`,
458
+ * `1`, `2`, `3` — measured in Chromium, with no error and no warning. A number, a boolean and
459
+ * `null` yield nothing at all, so `spread(someUndefinedVariable)` applies no props and says
460
+ * nothing, which reads as a renderer that ignored the spread.
461
+ *
462
+ * **jsdom hides this rather than catching it.** It implements the XML Name production and throws
463
+ * `InvalidCharacterError` on `setAttribute('0', …)`, so a probe under jsdom sees a loud failure
464
+ * for the case a real engine performs silently — the inverse of the usual trap, and the reason
465
+ * this was verified in a browser before being called a defect (`tests/browser/spread-names.test.js`
466
+ * records the engines' actual rule).
467
+ *
468
+ * Warned and ignored rather than thrown, which is exactly what an unusable *key* already does a
469
+ * few lines above: one bad props bag should not cost the render.
470
+ *
471
+ * **The message is `true `-only; the refusal is not.** They were both inside the guard, which
472
+ * made the two builds behave differently for the same code — and differently in the direction that
473
+ * hides the bug. Measured: `spread('text')` applies nothing in development, so the app under test
474
+ * looks fine; in production the string is iterated by character index and the element ends up with
475
+ * attributes named `0`, `1`, `2` and `3` (under jsdom, an `InvalidCharacterError` instead — the
476
+ * usual inversion, and why this was measured against both builds rather than reasoned about).
477
+ *
478
+ * A diagnostic belongs in `true `. A guard that changes what the program does cannot, or the
479
+ * development build stops being a faithful model of the production one, which is the property that
480
+ * makes testing in it worth anything. Costs 27 B gzipped (842 → 869, A-B-A) and buys the two builds agreeing.
481
+ */
482
+ if (props === null || typeof props !== 'object' || Array.isArray(props)) {
483
+ if (true )
484
+ console.warn(`[vera] spread: ignoring a props bag that is not a plain object — received ` +
485
+ `${Array.isArray(props) ? 'an array' : typeof props === 'object' ? 'null' : `a ${typeof props}`}. ` +
486
+ `A string is iterated by character index, so \`spread('text')\` would set attributes named ` +
487
+ `0, 1, 2 and 3; anything else applies nothing at all. This is usually an import or a ` +
488
+ `property that resolved to something unexpected.`);
489
+ props = {};
490
+ }
491
+ return {
492
+ _props: props,
493
+ _$apply$: apply,
494
+ _$attrs$: attributes,
495
+ };
496
+ };
497
+
498
+ export { spread };
499
+ //# sourceMappingURL=vera-renderer-spread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vera-renderer-spread.js","sources":["../../src/dev-values.ts","../../src/spread.ts"],"sourcesContent":["/**\n * `__DEV__` only: the one home for *\"is this value something an attribute can carry?\"*\n *\n * **Why it is a closed vocabulary and not a predicate.** The first design asked whether a value\n * stringifies meaningfully — `String(v) === '[object Object]'` means it lost its data. Driven\n * through 16 value shapes rather than reasoned about, that broke four ways, and the first is\n * disqualifying: `String()` THROWS on `Object.create(null)`, on `{ toString: null }`, and on any\n * object whose `toString` throws — so a diagnostic would have killed the page for an author using\n * the recommended dictionary idiom. It also passed `[\"a\",\"b\"]` as `\"a,b\"` (one junk class, if that\n * was a `class` binding) and `new Date()` as a timezone-bearing string, which is an SSR/CSR\n * divergence manufactured out of correct-looking code. And it passed `Symbol('s')` while\n * `` `${sym}` `` throws — a guard and its sink disagreeing about a single expression.\n *\n * \"Does it stringify meaningfully\" is an OPEN predicate over an unbounded, environment-dependent\n * space, and open predicates cannot be audited. So the test is inverted and closed: **primitives\n * pass; everything else is reported; anything else that should pass is a named row added on\n * evidence.** The list has exactly one member so far.\n *\n * Credit where it is due: the four breaks were found by the omni engine's session, which drove the\n * shapes rather than arguing about them, and the closed-vocabulary form is theirs.\n */\n\n/**\n * Blessed non-primitives — types whose `toString` IS the value the author means.\n *\n * Tested by brand rather than `instanceof`, which is false across realms: a `URL` built in an\n * iframe is not `instanceof` the parent's `URL`, and a diagnostic that fires on a correct value in\n * one frame and not another is worse than none.\n */\nconst brand = (value: object) => Object.prototype.toString.call(value);\n\n/** One message per element+name+kind, so a value rebuilt every render does not flood the console. */\nlet reported: Set<string> | undefined;\n\n/**\n * Returns the complaint, or `null` when the value is fine. Never throws — the shapes that break a\n * naive guard are exactly the ones worth reporting, so they reach the `object` arm and are named.\n */\nexport const attributeValueComplaint = (tag: string, name: string, value: unknown): string | null => {\n const type = typeof value;\n if (type === 'string' || type === 'number' || type === 'boolean' || type === 'bigint') return null;\n if (type === 'object' && brand(value as object) === '[object URL]') return null;\n\n /**\n * Keyed by BRAND, not by `typeof` — `Date`, `Array` and a plain object are all `'object'`, so a\n * coarser key reported whichever arrived first and silently swallowed the rest. An author who\n * fixed the Date would never have been told about the array.\n */\n const key = `${tag}|${name}|${type === 'object' ? brand(value as object) : type}`;\n reported ??= new Set();\n if (reported.has(key)) return null;\n reported.add(key);\n\n /**\n * A function into an attribute is never what the author meant, but the REASON matters: on a\n * custom element the Lit-era convention is that complex values are set as properties, so\n * `<my-chart formatter={fn}>` is a coherent intention that this sink simply cannot express. The\n * message names the binding that can, rather than blaming the author.\n */\n const said = type === 'function'\n ? `a function, which becomes its own SOURCE TEXT`\n : type === 'symbol'\n ? `a symbol, which every DOM conversion refuses`\n : Array.isArray(value)\n ? `an array, which becomes its members joined by commas`\n : brand(value as object) === '[object Date]'\n ? `a Date, whose text carries the TIMEZONE of whichever side rendered it`\n : `an ${type}, which cannot survive as text`;\n\n /**\n * Returned WITHOUT the `[vera]` prefix, which each call site writes as a literal.\n * `tests/diagnostics-convention.test.mjs` reads the prefix off the call, so a message handed over\n * as a variable is invisible to it — and its answer to that is an allowance list. Taking the\n * allowance would have excused these two calls rather than checked them, which is the\n * reclassification this audit keeps refusing; the literal at the call site is what every other\n * diagnostic in the repo does anyway.\n */\n return (\n `renderer: the attribute \\`${name}\\` on <${tag}> was given ${said}. ` +\n `An attribute value is a string and nothing else.\\n` +\n `If the element is meant to RECEIVE this value, bind a property instead — \\`.${name}=\\${value}\\` ` +\n `— which is how a custom element takes anything that is not text. If it is meant to be read as ` +\n `text, convert it where you know what it means: \\`date.toISOString()\\`, \\`list.join(' ')\\`. ` +\n `A Date in particular serializes with the SERVER's timezone on one side and the browser's on ` +\n `the other, so it will not survive hydration.`\n );\n};\n","import { attributeValueComplaint } from './dev-values.js';\n/**\n * `<div ${spread(props)}>` — bindings whose names are not known when the template is parsed.\n *\n * Template renderers bake attribute names in at parse time; that is what makes them small and fast,\n * and it is why neither this renderer nor lit-html has had spread. Lit's spread PR has sat open as a\n * draft since 2021, blocked on the questions answered below.\n *\n * **Why this ships separately.** The renderer holds one property read — a value at element position\n * carrying `_$apply$` applies itself — and nothing else, so a base bundle grows 16 B rather than\n * 176 B and an app that never spreads pays only that. Core and the renderer are the two packages\n * where weight is absolute; this is not one of them, but it is still measured.\n *\n * The sigil rules are repeated here rather than shared through `@verajs/shared-utils`. That was\n * tried: a shared resolver has to hand back both a kind and a name, and the tuple it allocates cost\n * the renderer 10 B. Principle #5 permits deliberate duplication where two callers can legitimately\n * diverge; #7 decides it, because the renderer is where bytes are not negotiable.\n */\n\nconst ATTR = 0;\nconst PROPERTY = 1;\nconst BOOLEAN = 2;\n/** `!name` — a property compared against the live DOM rather than against what this last wrote. */\nconst LIVE = 3;\nconst EVENT = 4;\nconst REF = 5;\n\n/**\n * A key that cannot be written into a tag, and therefore cannot be used at all.\n *\n * Measured in Chromium, `setAttribute` accepts `\"`, `'` and `<` and rejects whitespace, `>`, `=`,\n * `/` and NUL — but a name carrying a quote or a `<` cannot survive **markup**, so `@verajs/ssr`\n * has to refuse it, and a key that works here and vanishes server-side is worse than one that works\n * nowhere. The rule is therefore the HTML attribute-name restriction (control characters,\n * whitespace, `\"`, `'`, `>`, `/`, `=`) plus `<` and a backtick, applied identically on both sides.\n *\n * Skipped rather than thrown. `setAttribute` throws `InvalidCharacterError` on some of these, which\n * took down the whole render — for one bad key in a props bag, on a binding whose entire purpose is\n * names that are not known until runtime.\n *\n * The control-character range is the point of the rule, not a mistake in it: a name carrying one\n * is exactly what must never reach markup.\n */\n// eslint-disable-next-line no-control-regex\nconst UNSAFE_NAME = /^$|[\\s\"'>/=<`]|[\\u0000-\\u001f\\u007f]/;\n\n/**\n * **Sinks spread refuses, because spread is the one place the template security model breaks.**\n *\n * The renderer's posture on `.innerHTML` (README, \"security\") rests on three properties of the\n * template spelling: greppable, obviously yours, reviewable as the decision it is. A spread key\n * arrives at RUNTIME inside a props object — often built from data — and has none of the three:\n * `spread(fromJson)` carrying `.innerHTML` or an inline `onclick` attribute is markup or code\n * injection through a door no grep can see. So spread refuses the sinks and points at the template\n * spelling, which remains fully available to an author who means it.\n *\n * The list, deliberately minimal and named: `innerHTML`/`outerHTML` as property or live-property\n * keys; `srcdoc` as an attribute (an iframe's inline document); and any attribute whose name the\n * browser would treat as an inline handler (`on…` in any casing) — EXCEPT the documented event\n * spelling `on` + Capital, which the constructor converts to a real listener and which therefore\n * never becomes an attribute. The exemption mirrors the constructor's test byte for byte, because\n * `ONCLICK` must not slip through as \"looks like the event spelling\": the constructor only\n * converts a lowercase `on`, so only that exact shape is exempt.\n *\n * Returns the hint for the diagnostic, or null for a permitted key.\n */\nconst refusedSink = (key: string): string | null => {\n const first = key[0];\n if (first === '.' || first === '!') {\n const name = key.slice(1);\n if (name === 'innerHTML' || name === 'outerHTML')\n return 'write it in the template — html`<div .innerHTML=${trusted}>` — sanitized first (renderer README, security note)';\n /**\n * `element.__proto__ = value` is not a property write — it hits Object.prototype's\n * `__proto__` ACCESSOR and replaces the element's prototype, stripping every DOM method it\n * has. The element is bricked, and the crash lands LATER, in whatever binding next calls\n * `removeAttribute` on it — a data-driven render-kill with a stack that names the renderer\n * and not the data. Found by the run-14 payload probe; there is no legitimate use, so unlike\n * `.innerHTML` there is no template spelling to point at.\n */\n /** The deliberate twin of the same refusal in `AttrPart`'s constructor (`./renderer.ts`), for\n * the template spellings `.name` / `!name`. Independent bundles, neither imports the other, so\n * the rule is copied — and a fix visits both. `tests/dangerous-binding-matrix.test.mjs` holds\n * the two spellings to the same answer. */\n if (name === '__proto__')\n return \"assigning __proto__ replaces the element's own prototype and destroys it — no property write does this, and no use of it is legitimate\";\n return null;\n }\n if (first === '?' || first === '@' || first === '&') return null;\n /** The event spelling the constructor converts: `on` + Capital, lowercase `on` only. */\n if (first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91) return null;\n const lower = key.toLowerCase();\n if (lower === 'srcdoc') return 'an inline iframe document is markup injection by definition — bind it in the template if you truly mean it';\n if (lower.length > 2 && lower.startsWith('on'))\n return 'an inline handler attribute is code from data — pass a function as `on` + Capital (onClick) or `@click` instead';\n return null;\n};\n\n/** Module-local: one identity comparison, not a global symbol-registry lookup per binding. */\nconst UNSET = Symbol();\n\n/**\n * A class, not an object literal, so `handleEvent` exists once on the prototype. As a literal it was\n * a fresh closure per bound key — allocation proportional to the size of every props bag.\n */\nclass Binding {\n _kind: number;\n _name: string;\n _element: Element;\n /** What the element held before this binding took over. Releasing puts it back. */\n _initial: unknown;\n _committed: unknown = UNSET;\n _handler: EventListener | null = null;\n\n constructor(element: Element, key: string) {\n const first = key[0];\n let kind =\n first === '.'\n ? PROPERTY\n : first === '?'\n ? BOOLEAN\n : first === '@'\n ? EVENT\n : first === '&'\n ? REF\n : first === '!'\n ? LIVE\n : ATTR;\n let name = kind ? key.slice(1) : key;\n /** `on` + a capital: `onClick` ≡ `@click`. All-lowercase `onclick` never reaches here — it is\n * an inline-handler attribute, which `refusedSink` rejects before a binding exists. */\n if (kind === ATTR && first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91) {\n kind = EVENT;\n name = key.slice(2).toLowerCase();\n }\n this._kind = kind;\n this._name = name;\n this._element = element;\n this._initial =\n kind === ATTR\n ? element.getAttribute(name)\n : kind === BOOLEAN\n ? element.hasAttribute(name)\n : kind === PROPERTY || kind === LIVE\n ? (element as unknown as Record<string, unknown>)[name]\n : null;\n }\n\n /**\n * **Two shapes, because `addEventListener` takes two** — the same rule `AttrPart.handleEvent`\n * applies, and it did not travel here when that one was fixed. A function is called with the\n * element as `this`; an object with a `handleEvent` method is invoked through it — the platform's\n * own `EventListenerObject` protocol, which every engine accepts. This called `.call()`\n * unconditionally, so `spread({ onClick: { handleEvent } })` bound without complaint, never\n * fired, and raised `this._handler.call is not a function` on **every** dispatch — while the\n * identical value through a written `@click` worked.\n *\n * Anything else is inert rather than throwing, exactly as there: development names it at the\n * binding (see the event branch in `write`), where the mistake still is.\n */\n handleEvent(event: Event) {\n const handler = this._handler as EventListener | EventListenerObject | null;\n if (typeof handler === 'function') handler.call(this._element as never, event);\n else if (typeof (handler as EventListenerObject)?.handleEvent === 'function')\n (handler as EventListenerObject).handleEvent(event);\n }\n}\n\n/**\n * Keyed by the **part**, not the element.\n *\n * Keyed by element, `<div ${spread(a)} ${spread(b)}>` shares one map: whichever applies second sees\n * the other's keys as absent from its own props and releases them. Measured — the first spread's\n * attributes silently vanished. The part is one per element-position slot, which is exactly the\n * ownership boundary, and the renderer reuses it across renders.\n */\nconst owned = new WeakMap<object, Map<string, Binding>>();\n\nconst write = (binding: Binding, value: unknown) => {\n /** One comparison per key per render — the same dirty check a written binding gets. */\n /**\n * A live property asks the element rather than its own memory — see `AttrPart` in the renderer.\n * The dirty check is what keeps a field someone typed into, and it is exactly wrong for a control\n * whose DOM state changes when a *sibling* is interacted with, a radio group being the case.\n */\n if (binding._kind === LIVE) {\n binding._committed = value;\n const live = binding._element as unknown as Record<string, unknown>;\n if (live[binding._name] !== value) live[binding._name] = value;\n return;\n }\n if (value === binding._committed) return;\n binding._committed = value;\n const element = binding._element;\n const name = binding._name;\n const kind = binding._kind;\n if (kind === ATTR) {\n if (value == null) element.removeAttribute(name);\n else {\n if (__DEV__) {\n const complaint = attributeValueComplaint(element.localName, name, value);\n if (complaint !== null) console.warn(`[vera] ${complaint}`);\n }\n /**\n * `` `${value}` ``, never `String(value)` — the two differ on exactly one thing and it is the\n * one that matters here. `String(sym)` returns `\"Symbol(s)\"` while every DOM conversion and\n * `@verajs/ssr`'s own escaper throw, so this sink was the ONLY one of three that accepted a\n * symbol, writing to the client an attribute the server refuses to produce. The rule was\n * already recorded in `@verajs/ssr`'s `escapeHtml` — \"serving Symbol(s) into markup the client\n * cannot reproduce does not make anything work, it moves the failure across the boundary and\n * strips the context\" — and this file used the other form anyway. A house rule written down\n * in one of three homes is a house rule in none of them.\n */\n element.setAttribute(name, `${value}`);\n }\n } else if (kind === PROPERTY) {\n (element as unknown as Record<string, unknown>)[name] = value;\n } else if (kind === BOOLEAN) {\n element.toggleAttribute(name, !!value);\n } else if (kind === REF) {\n /**\n * `&name` is the written form's ref sigil (`<input &field=${myRef} />`), and it was the one\n * binding kind a spread could not express: the key fell through to `ATTR` and\n * `setAttribute('&field', …)` threw on the client while the server wrote `&field=\"[object\n * Object]\"` into the markup. A function is called with the element, an object gets it assigned\n * to `.value` — the same two shapes `AttrPart` handles.\n */\n if (typeof value === 'function') (value as (el: Element) => void)(element);\n else if (value !== null && typeof value === 'object') (value as { value: unknown }).value = element;\n } else {\n /**\n * A listener is validated when a *user* clicks, which in development may be never — so it is\n * checked where it is written, the same rule `AttrPart` applies to `@event`. `false` stays\n * silent: `{ onClick: enabled && onClick }` is the ordinary conditional form and already\n * behaves correctly, since `handleEvent` finds nothing callable and does nothing.\n */\n if (__DEV__ && value != null && value !== false && typeof value !== 'function' &&\n typeof (value as EventListenerObject)?.handleEvent !== 'function')\n console.warn(\n `[vera] spread: @${name} on <${element.localName}> was given ` +\n `${typeof value === 'object' ? 'an object with no handleEvent method' : `a ${typeof value}`}, ` +\n `which cannot listen — the event will do nothing.\\n` +\n `Pass a function, or an object with a handleEvent method. A missing handler is ` +\n `\\`undefined\\` or \\`false\\`, both of which are fine; this is neither.`\n );\n if (binding._handler === null && value != null) element.addEventListener(name, binding);\n binding._handler = (value as EventListener) ?? null;\n }\n};\n\n/**\n * A key that disappeared between renders restores what the element held before the binding existed.\n *\n * This is the question Lit's PR is stuck on, and the trap is asking it as \"what value means absent\".\n * For a property there is no answer: assigning `undefined` runs through coercing setters, so\n * dropping `.value` yields `\"\"` rather than reverting, and `delete` cannot remove a prototype\n * accessor. Asked instead as *\"undo what this binding did\"* it is well defined for every kind and\n * never invents a value the author did not write — the initial state was, by definition, acceptable\n * before the binding arrived.\n *\n * And asked that way it needs no code of its own: releasing is writing the initial value back.\n * `null` removes an attribute, `false` untoggles a boolean, `undefined` restores a property to\n * pristine, and an event handler falls to `null` — every case the existing commit already handles.\n * The separate per-kind teardown this replaced was fourteen lines saying the same thing twice.\n *\n * Deliberately unguarded by an ownership check (`is the value still the one we wrote?`). That only\n * matters when a component reassigns a property its parent is binding, which is already confused;\n * per principle #3 the machinery waits for evidence rather than being pre-built.\n */\nfunction apply(this: { _props: Record<string, unknown> }, element: Element, part: object) {\n const props = this._props;\n let bindings = owned.get(part);\n if (bindings === undefined) owned.set(part, (bindings = new Map()));\n\n /**\n * Counted here rather than with `Object.keys(props).length`, which allocates an array on every\n * render of every spread — garbage in the render path, for a number already being walked.\n */\n let count = 0;\n for (const key in props) {\n count++;\n /**\n * Counted before it is skipped, so the size comparison below still describes the key set — a\n * refused key that changed the count would make every render look like a removal.\n */\n if (UNSAFE_NAME.test(key[0] === '.' || key[0] === '?' || key[0] === '@' || key[0] === '&' ? key.slice(1) : key)) {\n if (__DEV__)\n console.warn(\n `[vera] spread: ignoring the key ${JSON.stringify(key)} — an attribute name ` +\n `cannot contain whitespace, a quote, \\`<\\`, \\`>\\`, \\`/\\`, \\`=\\` or a control character, ` +\n `and one that cannot be written into markup would not survive server rendering.`\n );\n continue;\n }\n /** Counted above for the same reason the unsafe skip is. */\n const refused = refusedSink(key);\n if (refused !== null) {\n if (__DEV__)\n console.warn(\n `[vera] spread: refusing ${JSON.stringify(key)} — spread names arrive at runtime, which is ` +\n `exactly the property that makes this sink unreviewable; ${refused}.`\n );\n continue;\n }\n let binding = bindings.get(key);\n if (binding === undefined) bindings.set(key, (binding = new Binding(element, key)));\n write(binding, props[key]);\n }\n\n /**\n * A size mismatch is the only way a key can have gone: every key in `props` was just visited, so\n * equal sizes means equal sets. The steady-state render of an unchanged shape — overwhelmingly the\n * common case — costs one integer comparison, not a scan.\n */\n if (bindings.size !== count) {\n for (const [key, binding] of bindings) {\n if (key in props) continue;\n bindings.delete(key);\n write(binding, binding._initial);\n }\n }\n}\n\n/**\n * The server half of the protocol: hand back every binding, resolved, and let the renderer that\n * asked decide what belongs in markup.\n *\n * Deliberately *not* a serializer. This package knows what a key means — `.value` is a property,\n * `?disabled` a boolean, `onClick` an event — and nothing else. Whether a property belongs in\n * server markup (`value`, `checked`, `selected` do; the rest are client state) and how a value is\n * escaped are `@verajs/ssr`'s decisions, and principle #8 wants escaping in exactly one place. So\n * this returns data, never a string.\n *\n * Kinds are single characters rather than the module's numeric constants, because this crosses a\n * package boundary: `a`ttribute, `b`oolean, `p`roperty, `e`vent, `r`ef. A ref is client state with\n * no markup, exactly like an event, and the serializer drops both.\n */\nfunction attributes(this: { _props: Record<string, unknown> }): [string, string, unknown][] {\n const out: [string, string, unknown][] = [];\n for (const key in this._props) {\n /** The client refusal, applied at the serializer boundary too — one predicate, both renders.\n * Without this, a refused key was merely inert in the browser and LIVE in server markup. */\n if (refusedSink(key) !== null) continue;\n const first = key[0];\n /** `!` reports as a property: the server has nothing to re-read, so it serializes as `.` does. */\n const kind =\n first === '.' || first === '!'\n ? 'p'\n : first === '?'\n ? 'b'\n : first === '@'\n ? 'e'\n : first === '&'\n ? 'r'\n : 'a';\n if (kind !== 'a') {\n out.push([kind, key.slice(1), this._props[key]]);\n } else if (first === 'o' && key.charCodeAt(1) === 110 && key.charCodeAt(2) > 64 && key.charCodeAt(2) < 91) {\n out.push(['e', key.slice(2).toLowerCase(), this._props[key]]);\n } else {\n out.push(['a', key, this._props[key]]);\n }\n }\n return out;\n}\n\n/**\n * Branded rather than duck-typed: the element position already means \"element ref\", and a props bag\n * is indistinguishable from a ref object — `{ value: 5 }` is legitimately either.\n */\nexport const spread = (props: Record<string, unknown>) => {\n /**\n * **A props bag that is not an object is iterated anyway, and a browser accepts the result.**\n *\n * Everything below reads `props` with `Object.keys`/`Object.entries`, which answer for any value:\n * a **string** yields its character indices, so `spread('text')` sets four attributes named `0`,\n * `1`, `2`, `3` — measured in Chromium, with no error and no warning. A number, a boolean and\n * `null` yield nothing at all, so `spread(someUndefinedVariable)` applies no props and says\n * nothing, which reads as a renderer that ignored the spread.\n *\n * **jsdom hides this rather than catching it.** It implements the XML Name production and throws\n * `InvalidCharacterError` on `setAttribute('0', …)`, so a probe under jsdom sees a loud failure\n * for the case a real engine performs silently — the inverse of the usual trap, and the reason\n * this was verified in a browser before being called a defect (`tests/browser/spread-names.test.js`\n * records the engines' actual rule).\n *\n * Warned and ignored rather than thrown, which is exactly what an unusable *key* already does a\n * few lines above: one bad props bag should not cost the render.\n *\n * **The message is `__DEV__`-only; the refusal is not.** They were both inside the guard, which\n * made the two builds behave differently for the same code — and differently in the direction that\n * hides the bug. Measured: `spread('text')` applies nothing in development, so the app under test\n * looks fine; in production the string is iterated by character index and the element ends up with\n * attributes named `0`, `1`, `2` and `3` (under jsdom, an `InvalidCharacterError` instead — the\n * usual inversion, and why this was measured against both builds rather than reasoned about).\n *\n * A diagnostic belongs in `__DEV__`. A guard that changes what the program does cannot, or the\n * development build stops being a faithful model of the production one, which is the property that\n * makes testing in it worth anything. Costs 27 B gzipped (842 → 869, A-B-A) and buys the two builds agreeing.\n */\n if (props === null || typeof props !== 'object' || Array.isArray(props)) {\n if (__DEV__)\n console.warn(\n `[vera] spread: ignoring a props bag that is not a plain object — received ` +\n `${Array.isArray(props) ? 'an array' : typeof props === 'object' ? 'null' : `a ${typeof props}`}. ` +\n `A string is iterated by character index, so \\`spread('text')\\` would set attributes named ` +\n `0, 1, 2 and 3; anything else applies nothing at all. This is usually an import or a ` +\n `property that resolved to something unexpected.`\n );\n props = {};\n }\n return {\n _props: props,\n _$apply$: apply,\n _$attrs$: attributes,\n };\n};\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;AAEH;;;;;;AAMG;AACH,MAAM,KAAK,GAAG,CAAC,KAAa,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;AAEtE;AACA,IAAI,QAAiC;AAErC;;;AAGG;AACI,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,IAAY,EAA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GAAG,MAAM,GAAG,CAAA,EAAA,EAAK,OAAO,KAAK,CAAA,CAAE,CAAA,EAAA,CAAI;gBACnG,CAAA,0FAAA,CAA4F;gBAC5F,CAAA,oFAAA,CAAsF;AACtF,gBAAA,CAAA,+CAAA,CAAiD,CACpD;QACH,KAAK,GAAG,EAAE;IACZ;IACA,OAAO;AACL,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,QAAQ,EAAE,UAAU;KACrB;AACH;;;;"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * `@verajs/renderer/tag` — an element whose **tag name** is decided at runtime.
3
+ *
4
+ * A template renderer bakes tag names into its statics; that is what makes template identity work
5
+ * and what every fast path in this renderer depends on. So a runtime tag cannot be a binding — it
6
+ * has to become part of the statics *before* the renderer sees the template, which is what this
7
+ * entry does. Downstream nothing changes: the renderer, `@verajs/ssr` and hydration all receive an
8
+ * ordinary template and are unaware this exists.
9
+ *
10
+ * ```js
11
+ * import { html, tag } from '@verajs/renderer/tag';
12
+ *
13
+ * const HEADING = { 1: tag`h1`, 2: tag`h2`, 3: tag`h3` };
14
+ * const H = HEADING[state.level];
15
+ * html`<${H} class="title">${state.text}</${H}>`;
16
+ * ```
17
+ *
18
+ * **A tag is also a JSX component**, so the same value works in both notations with no compiler
19
+ * change — `<H className="title">{state.text}</H>` compiles to `H({…})`, which is exactly what a
20
+ * capitalized JSX tag already compiles to.
21
+ *
22
+ * Additive, like `@verajs/renderer/spread` and unlike the other entries: it inlines no renderer
23
+ * internals, so it is safe alongside any of them.
24
+ */
25
+ /** The brand a tag carries. `_$…$` is exempt from this package's `/^_[a-z]/` property mangling. */
26
+ declare const STATIC = "_$static$";
27
+ type Tag = ((props?: Record<string, unknown>) => unknown) & {
28
+ [STATIC]: string;
29
+ };
30
+ /**
31
+ * The `html` to use in a template containing a runtime tag. With no tags in it, this is the
32
+ * ordinary template shape and costs one loop.
33
+ *
34
+ * It builds `{ _$litType$: 1, strings, values }` directly rather than calling core's `html`, so this
35
+ * entry keeps the renderer's independence from core. The consequence is that a `setHtml` swap does
36
+ * not reach here — which is right, since a swapped `html` belongs to a different renderer and this
37
+ * is a renderer feature.
38
+ */
39
+ declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => {
40
+ _$litType$: number;
41
+ strings: TemplateStringsArray;
42
+ values: unknown[];
43
+ } | {
44
+ _$litType$: number;
45
+ strings: string[];
46
+ values: unknown[];
47
+ };
48
+ declare const BOOLEAN_ATTRIBUTES: Set<string>;
49
+ declare const jsxName: (key: string) => string;
50
+ /**
51
+ * Declares a tag name.
52
+ *
53
+ * **A string can never become one.** Only another tag may be interpolated, so the set of tags an
54
+ * app can produce is fixed by its source — which is what keeps a tag out of reach of a request, and
55
+ * incidentally what bounds the template cache. There is no `unsafeStatic` here for the same reason
56
+ * there is no `unsafeHTML`: a sanctioned opt-out reads as blessed in tutorials and in review.
57
+ */
58
+ declare const tag: (strings: TemplateStringsArray, ...values: unknown[]) => Tag;
59
+
60
+ export { BOOLEAN_ATTRIBUTES, html, jsxName, tag };
61
+ //# sourceMappingURL=vera-renderer-tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vera-renderer-tag.d.ts","sources":["../../src/tag.ts"],"mappings":"AAAA;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AAEH,cAAA,MAAA;AACA,KAAA,GAAM,aAAS,MAAY;AAI3B,KAAA,MAAA;;;;;;;;AAQG;AACH;AAEA;;;;;;;;AAQG;AACH;cACY,kBAAG,EAAA,GAAA;AACb,cAAU,OAAO;AACf;AACA;;AACA;;;;;;;;;","names":[]}