@verajs/ssr 0.2.0 → 0.3.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 (63) hide show
  1. package/README.md +510 -373
  2. package/dist/vera/diagnostics.d.ts +20 -0
  3. package/dist/vera/diagnostics.js +98 -0
  4. package/dist/vera/escaping.d.ts +142 -0
  5. package/dist/vera/escaping.js +267 -0
  6. package/dist/vera/events.d.ts +41 -0
  7. package/dist/vera/events.js +162 -0
  8. package/dist/vera/frames.d.ts +38 -0
  9. package/dist/vera/frames.js +195 -0
  10. package/dist/vera/index.d.ts +48 -0
  11. package/dist/vera/index.js +480 -0
  12. package/{types → dist/vera}/nodes.d.ts +397 -300
  13. package/dist/vera/nodes.js +2322 -0
  14. package/dist/vera/parse.d.ts +37 -0
  15. package/dist/vera/parse.js +390 -0
  16. package/dist/vera/reflections.d.ts +566 -0
  17. package/dist/vera/reflections.js +820 -0
  18. package/dist/vera/registry.d.ts +14 -0
  19. package/{src → dist}/vera/registry.js +5 -1
  20. package/dist/vera/report.d.ts +27 -0
  21. package/dist/vera/report.js +56 -0
  22. package/dist/vera/scan.d.ts +37 -0
  23. package/dist/vera/scan.js +143 -0
  24. package/dist/vera/select.d.ts +40 -0
  25. package/dist/vera/select.js +261 -0
  26. package/dist/vera/serializer.d.ts +39 -0
  27. package/dist/vera/serializer.js +1372 -0
  28. package/dist/vera/shim.d.ts +42 -0
  29. package/dist/vera/shim.js +853 -0
  30. package/dist/vera/slots.d.ts +5 -0
  31. package/dist/vera/slots.js +104 -0
  32. package/dist/vera/stylesheets.d.ts +62 -0
  33. package/dist/vera/stylesheets.js +180 -0
  34. package/dist/vera/tokenizer.d.ts +32 -0
  35. package/dist/vera/tokenizer.js +528 -0
  36. package/dist/vera/types.d.ts +117 -0
  37. package/dist/vera/views.d.ts +63 -0
  38. package/dist/vera/views.js +245 -0
  39. package/package.json +12 -13
  40. package/src/vera/escaping.js +0 -135
  41. package/src/vera/events.js +0 -164
  42. package/src/vera/frames.js +0 -102
  43. package/src/vera/index.js +0 -1171
  44. package/src/vera/nodes.js +0 -2270
  45. package/src/vera/parse.js +0 -381
  46. package/src/vera/reflections.js +0 -811
  47. package/src/vera/select.js +0 -234
  48. package/src/vera/serializer.js +0 -928
  49. package/src/vera/shim.js +0 -761
  50. package/src/vera/stylesheets.js +0 -155
  51. package/src/vera/views.js +0 -240
  52. package/types/escaping.d.ts +0 -27
  53. package/types/events.d.ts +0 -4
  54. package/types/frames.d.ts +0 -12
  55. package/types/index.d.ts +0 -13
  56. package/types/parse.d.ts +0 -19
  57. package/types/reflections.d.ts +0 -657
  58. package/types/registry.d.ts +0 -8
  59. package/types/select.d.ts +0 -5
  60. package/types/serializer.d.ts +0 -26
  61. package/types/shim.d.ts +0 -23
  62. package/types/stylesheets.d.ts +0 -53
  63. package/types/views.d.ts +0 -26
@@ -0,0 +1,820 @@
1
+ /**
2
+ * The properties that exist only on *some* elements — `input.disabled`, `a.href`, `td.colSpan` —
3
+ * and the content attributes they reflect.
4
+ *
5
+ * **Why this file exists.** The server DOM had one element type for every tag, carrying only the
6
+ * members every element shares (`id`, `title`, `hidden`, `tabIndex`, the enumerated states). Nothing
7
+ * element-specific existed at all, so `button.disabled = true` stored a plain JavaScript property,
8
+ * wrote no attribute, and **rendered a button that was not disabled** — while reading the property
9
+ * back said `true`, so the code looked right. Setting `input.value`, `input.checked` and
10
+ * `option.selected` failed the same way, and reading any of them before writing gave `undefined`
11
+ * where a browser gives `''` or `false`, so `input.value.trim()` threw on the server and worked in
12
+ * the client.
13
+ *
14
+ * Nothing failed loudly, which is what made it bad: a control that must not be interactive shipped
15
+ * interactive, and stayed that way until the bundle landed and the client set the property for real.
16
+ *
17
+ * **The table is measured, not remembered.** `scripts/measure-element-reflections.mjs` drives
18
+ * Chromium, Firefox and WebKit: for every property on every element-specific interface it reads the
19
+ * value with the attribute absent, assigns a probe, and looks at which attribute appeared and what
20
+ * reading it back gives. A property is only recorded when all three engines agree on every one of
21
+ * those cells, and when reading the attribute back yields exactly what was written — which is what
22
+ * drops `input.width` (laid out, so it reads `0`), `meter.value` (clamped to its max) and
23
+ * `form.action` (resolved against a document URL this DOM does not have). The reasons are listed at
24
+ * the bottom of this file rather than left to be rediscovered.
25
+ *
26
+ * This is the same discipline the generic table in `nodes.js` was built with, and for the same
27
+ * reason: every value there that was written from memory turned out to be wrong. `tabIndex` had no
28
+ * default, so every element claimed to be in the tab order; `draggable` and `spellcheck` were given
29
+ * one shared default when they do not share one.
30
+ *
31
+ * **Enumerated states follow the majority where the engines differ**, as `popover: 'hint'` already
32
+ * does — an enumerated state cannot reach the markup, because the attribute is stored verbatim, so
33
+ * the cost of being in the minority is a property read and nothing else. The six that needed it are
34
+ * named at the bottom.
35
+ *
36
+ * `tests/browser/element-reflections.test.js` re-measures in a real engine and fails if this table
37
+ * and the browser have drifted apart.
38
+ */
39
+ /**
40
+ * `[kind, attribute, ...]`, where kind is one of:
41
+ *
42
+ * - `presence` — a boolean; the attribute's presence is the value. A third entry is the answer when
43
+ * the attribute is absent, for the one case where that is not `false` (`script.async`).
44
+ * - `string` — the attribute's text, or `''` when it is absent.
45
+ * - `number` — the attribute parsed as an integer, or the third entry when absent or unparseable.
46
+ * - `enum` — `[missing, invalid, states]`: a limited set of states, answered canonically, with its
47
+ * own answer for absent and for anything outside the set.
48
+ *
49
+ * **An enumerated *content* attribute is not an enumerated *IDL* attribute**, and three rows here
50
+ * confused the two. `area.shape`, `ol.type` and `textarea.wrap` all name a limited set of keywords
51
+ * that affect rendering — but their IDL is a plain `attribute DOMString`, so the property echoes
52
+ * whatever was written. They were listed as `enum` with an invalid-value answer of
53
+ * `"zzz-not-a-state"`, which is not a string any engine produces: it is the **probe value** whoever
54
+ * wrote those rows used to discover an invalid-value default, recorded as though it were the answer.
55
+ *
56
+ * So `area.shape = 'probe'` answered `"zzz-not-a-state"` and `shape = 'CIRCLE'` answered `"circle"`,
57
+ * where every engine echoes the input. The header above says every enumerated state here "was
58
+ * measured on three engines instead of read off a spec" — these three were not; a measurement would
59
+ * have shown the echo. Reclassified as `string`, which is what the IDL says and what a real DOM does.
60
+ */
61
+ export const ELEMENT_REFLECTIONS = {
62
+ a: {
63
+ charset: ["string", "charset"],
64
+ coords: ["string", "coords"],
65
+ download: ["string", "download"],
66
+ href: ["string", "href"],
67
+ hreflang: ["string", "hreflang"],
68
+ name: ["string", "name"],
69
+ ping: ["string", "ping"],
70
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
71
+ rel: ["string", "rel"],
72
+ rev: ["string", "rev"],
73
+ shape: ["string", "shape"],
74
+ target: ["string", "target"],
75
+ type: ["string", "type"],
76
+ },
77
+ area: {
78
+ alt: ["string", "alt"],
79
+ coords: ["string", "coords"],
80
+ download: ["string", "download"],
81
+ href: ["string", "href"],
82
+ noHref: ["presence", "nohref"],
83
+ ping: ["string", "ping"],
84
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
85
+ rel: ["string", "rel"],
86
+ shape: ["string", "shape"],
87
+ target: ["string", "target"],
88
+ },
89
+ base: {
90
+ target: ["string", "target"],
91
+ },
92
+ blockquote: {
93
+ cite: ["string", "cite"],
94
+ },
95
+ br: {
96
+ clear: ["string", "clear"],
97
+ },
98
+ button: {
99
+ disabled: ["presence", "disabled"],
100
+ formEnctype: ["enum", "formenctype", "", "application/x-www-form-urlencoded", ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]],
101
+ formMethod: ["enum", "formmethod", "", "get", ["get", "post", "dialog"]],
102
+ formNoValidate: ["presence", "formnovalidate"],
103
+ formTarget: ["string", "formtarget"],
104
+ name: ["string", "name"],
105
+ popoverTargetAction: ["enum", "popovertargetaction", "toggle", "toggle", ["toggle", "show", "hide"]],
106
+ type: ["enum", "type", "submit", "submit", ["submit", "reset", "button"]],
107
+ value: ["string", "value"],
108
+ },
109
+ canvas: {
110
+ height: ["number", "height", 150],
111
+ width: ["number", "width", 300],
112
+ },
113
+ caption: {
114
+ align: ["string", "align"],
115
+ },
116
+ col: {
117
+ align: ["string", "align"],
118
+ ch: ["string", "char"],
119
+ chOff: ["string", "charoff"],
120
+ span: ["number", "span", 1],
121
+ vAlign: ["string", "valign"],
122
+ width: ["string", "width"],
123
+ },
124
+ colgroup: {
125
+ align: ["string", "align"],
126
+ ch: ["string", "char"],
127
+ chOff: ["string", "charoff"],
128
+ span: ["number", "span", 1],
129
+ vAlign: ["string", "valign"],
130
+ width: ["string", "width"],
131
+ },
132
+ data: {
133
+ value: ["string", "value"],
134
+ },
135
+ del: {
136
+ cite: ["string", "cite"],
137
+ dateTime: ["string", "datetime"],
138
+ },
139
+ details: {
140
+ name: ["string", "name"],
141
+ open: ["presence", "open"],
142
+ },
143
+ dialog: {
144
+ closedBy: ["enum", "closedby", "none", "none", ["any", "closerequest", "none"]],
145
+ open: ["presence", "open"],
146
+ },
147
+ div: {
148
+ align: ["string", "align"],
149
+ },
150
+ dl: {
151
+ compact: ["presence", "compact"],
152
+ },
153
+ embed: {
154
+ align: ["string", "align"],
155
+ height: ["string", "height"],
156
+ name: ["string", "name"],
157
+ src: ["string", "src"],
158
+ type: ["string", "type"],
159
+ width: ["string", "width"],
160
+ },
161
+ fieldset: {
162
+ disabled: ["presence", "disabled"],
163
+ name: ["string", "name"],
164
+ },
165
+ form: {
166
+ acceptCharset: ["string", "accept-charset"],
167
+ autocomplete: ["enum", "autocomplete", "on", "on", ["on", "off"]],
168
+ encoding: ["enum", "enctype", "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]],
169
+ enctype: ["enum", "enctype", "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]],
170
+ method: ["enum", "method", "get", "get", ["get", "post", "dialog"]],
171
+ name: ["string", "name"],
172
+ noValidate: ["presence", "novalidate"],
173
+ rel: ["string", "rel"],
174
+ target: ["string", "target"],
175
+ },
176
+ h1: {
177
+ align: ["string", "align"],
178
+ },
179
+ h2: {
180
+ align: ["string", "align"],
181
+ },
182
+ h3: {
183
+ align: ["string", "align"],
184
+ },
185
+ h4: {
186
+ align: ["string", "align"],
187
+ },
188
+ h5: {
189
+ align: ["string", "align"],
190
+ },
191
+ h6: {
192
+ align: ["string", "align"],
193
+ },
194
+ hr: {
195
+ align: ["string", "align"],
196
+ color: ["string", "color"],
197
+ noShade: ["presence", "noshade"],
198
+ size: ["string", "size"],
199
+ width: ["string", "width"],
200
+ },
201
+ iframe: {
202
+ align: ["string", "align"],
203
+ allow: ["string", "allow"],
204
+ allowFullscreen: ["presence", "allowfullscreen"],
205
+ frameBorder: ["string", "frameborder"],
206
+ height: ["string", "height"],
207
+ loading: ["enum", "loading", "eager", "eager", ["eager", "lazy"]],
208
+ longDesc: ["string", "longdesc"],
209
+ marginHeight: ["string", "marginheight"],
210
+ marginWidth: ["string", "marginwidth"],
211
+ name: ["string", "name"],
212
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
213
+ scrolling: ["string", "scrolling"],
214
+ src: ["string", "src"],
215
+ srcdoc: ["string", "srcdoc"],
216
+ width: ["string", "width"],
217
+ },
218
+ img: {
219
+ align: ["string", "align"],
220
+ alt: ["string", "alt"],
221
+ border: ["string", "border"],
222
+ decoding: ["enum", "decoding", "auto", "auto", ["sync", "async", "auto"]],
223
+ fetchPriority: ["enum", "fetchpriority", "auto", "auto", ["high", "low", "auto"]],
224
+ height: ["number", "height", 0],
225
+ hspace: ["number", "hspace", 0],
226
+ isMap: ["presence", "ismap"],
227
+ loading: ["enum", "loading", "eager", "eager", ["eager", "lazy"]],
228
+ longDesc: ["string", "longdesc"],
229
+ lowsrc: ["string", "lowsrc"],
230
+ name: ["string", "name"],
231
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
232
+ sizes: ["string", "sizes"],
233
+ src: ["string", "src"],
234
+ srcset: ["string", "srcset"],
235
+ useMap: ["string", "usemap"],
236
+ vspace: ["number", "vspace", 0],
237
+ width: ["number", "width", 0],
238
+ },
239
+ input: {
240
+ accept: ["string", "accept"],
241
+ align: ["string", "align"],
242
+ alt: ["string", "alt"],
243
+ autocomplete: ["enum", "autocomplete", "", "", ["on", "off"]],
244
+ defaultChecked: ["presence", "checked"],
245
+ defaultValue: ["string", "value"],
246
+ dirName: ["string", "dirname"],
247
+ disabled: ["presence", "disabled"],
248
+ formEnctype: ["enum", "formenctype", "", "application/x-www-form-urlencoded", ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]],
249
+ formMethod: ["enum", "formmethod", "", "get", ["get", "post", "dialog"]],
250
+ formNoValidate: ["presence", "formnovalidate"],
251
+ formTarget: ["string", "formtarget"],
252
+ max: ["string", "max"],
253
+ maxLength: ["number", "maxlength", -1],
254
+ min: ["string", "min"],
255
+ minLength: ["number", "minlength", -1],
256
+ multiple: ["presence", "multiple"],
257
+ name: ["string", "name"],
258
+ pattern: ["string", "pattern"],
259
+ placeholder: ["string", "placeholder"],
260
+ popoverTargetAction: ["enum", "popovertargetaction", "toggle", "toggle", ["toggle", "show", "hide"]],
261
+ readOnly: ["presence", "readonly"],
262
+ required: ["presence", "required"],
263
+ size: ["number", "size", 20],
264
+ src: ["string", "src"],
265
+ step: ["string", "step"],
266
+ type: ["enum", "type", "text", "text", ["text", "password", "checkbox", "radio", "submit", "reset", "button", "hidden", "image", "file", "number", "range", "date", "month", "week", "time", "datetime-local", "email", "url", "search", "tel", "color"]],
267
+ useMap: ["string", "usemap"],
268
+ webkitdirectory: ["presence", "webkitdirectory"],
269
+ },
270
+ ins: {
271
+ cite: ["string", "cite"],
272
+ dateTime: ["string", "datetime"],
273
+ },
274
+ label: {
275
+ htmlFor: ["string", "for"],
276
+ },
277
+ legend: {
278
+ align: ["string", "align"],
279
+ },
280
+ li: {
281
+ type: ["string", "type"],
282
+ value: ["number", "value", 0],
283
+ },
284
+ link: {
285
+ as: ["enum", "as", "", "", ["fetch", "font", "image", "script", "style", "track", "audio", "video"]],
286
+ charset: ["string", "charset"],
287
+ disabled: ["presence", "disabled"],
288
+ fetchPriority: ["enum", "fetchpriority", "auto", "auto", ["high", "low", "auto"]],
289
+ href: ["string", "href"],
290
+ hreflang: ["string", "hreflang"],
291
+ imageSizes: ["string", "imagesizes"],
292
+ imageSrcset: ["string", "imagesrcset"],
293
+ integrity: ["string", "integrity"],
294
+ media: ["string", "media"],
295
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
296
+ rel: ["string", "rel"],
297
+ rev: ["string", "rev"],
298
+ target: ["string", "target"],
299
+ type: ["string", "type"],
300
+ },
301
+ map: {
302
+ name: ["string", "name"],
303
+ },
304
+ menu: {
305
+ compact: ["presence", "compact"],
306
+ },
307
+ meta: {
308
+ content: ["string", "content"],
309
+ httpEquiv: ["string", "http-equiv"],
310
+ media: ["string", "media"],
311
+ name: ["string", "name"],
312
+ scheme: ["string", "scheme"],
313
+ },
314
+ meter: {
315
+ max: ["number", "max", 1],
316
+ min: ["number", "min", 0],
317
+ },
318
+ object: {
319
+ align: ["string", "align"],
320
+ archive: ["string", "archive"],
321
+ border: ["string", "border"],
322
+ code: ["string", "code"],
323
+ codeBase: ["string", "codebase"],
324
+ codeType: ["string", "codetype"],
325
+ data: ["string", "data"],
326
+ declare: ["presence", "declare"],
327
+ height: ["string", "height"],
328
+ hspace: ["number", "hspace", 0],
329
+ name: ["string", "name"],
330
+ standby: ["string", "standby"],
331
+ type: ["string", "type"],
332
+ useMap: ["string", "usemap"],
333
+ vspace: ["number", "vspace", 0],
334
+ width: ["string", "width"],
335
+ },
336
+ ol: {
337
+ compact: ["presence", "compact"],
338
+ reversed: ["presence", "reversed"],
339
+ start: ["number", "start", 1],
340
+ type: ["string", "type"],
341
+ },
342
+ optgroup: {
343
+ disabled: ["presence", "disabled"],
344
+ label: ["string", "label"],
345
+ },
346
+ option: {
347
+ defaultSelected: ["presence", "selected"],
348
+ disabled: ["presence", "disabled"],
349
+ label: ["string", "label"],
350
+ value: ["string", "value"],
351
+ },
352
+ output: {
353
+ name: ["string", "name"],
354
+ },
355
+ p: {
356
+ align: ["string", "align"],
357
+ },
358
+ param: {
359
+ name: ["string", "name"],
360
+ type: ["string", "type"],
361
+ value: ["string", "value"],
362
+ valueType: ["string", "valuetype"],
363
+ },
364
+ pre: {
365
+ width: ["number", "width", 0],
366
+ },
367
+ progress: {
368
+ max: ["number", "max", 1],
369
+ },
370
+ q: {
371
+ cite: ["string", "cite"],
372
+ },
373
+ script: {
374
+ async: ["presence", "async", true],
375
+ charset: ["string", "charset"],
376
+ defer: ["presence", "defer"],
377
+ event: ["string", "event"],
378
+ fetchPriority: ["enum", "fetchpriority", "auto", "auto", ["high", "low", "auto"]],
379
+ htmlFor: ["string", "for"],
380
+ integrity: ["string", "integrity"],
381
+ noModule: ["presence", "nomodule"],
382
+ referrerPolicy: ["enum", "referrerpolicy", "", "", ["", "no-referrer", "no-referrer-when-downgrade", "same-origin", "origin", "strict-origin", "origin-when-cross-origin", "strict-origin-when-cross-origin", "unsafe-url"]],
383
+ src: ["string", "src"],
384
+ type: ["string", "type"],
385
+ },
386
+ select: {
387
+ autocomplete: ["enum", "autocomplete", "", "", ["on", "off"]],
388
+ disabled: ["presence", "disabled"],
389
+ multiple: ["presence", "multiple"],
390
+ name: ["string", "name"],
391
+ required: ["presence", "required"],
392
+ size: ["number", "size", 0],
393
+ },
394
+ slot: {
395
+ name: ["string", "name"],
396
+ },
397
+ source: {
398
+ height: ["number", "height", 0],
399
+ media: ["string", "media"],
400
+ sizes: ["string", "sizes"],
401
+ src: ["string", "src"],
402
+ srcset: ["string", "srcset"],
403
+ type: ["string", "type"],
404
+ width: ["number", "width", 0],
405
+ },
406
+ style: {
407
+ media: ["string", "media"],
408
+ type: ["string", "type"],
409
+ },
410
+ table: {
411
+ align: ["string", "align"],
412
+ bgColor: ["string", "bgcolor"],
413
+ border: ["string", "border"],
414
+ cellPadding: ["string", "cellpadding"],
415
+ cellSpacing: ["string", "cellspacing"],
416
+ frame: ["string", "frame"],
417
+ rules: ["string", "rules"],
418
+ summary: ["string", "summary"],
419
+ width: ["string", "width"],
420
+ },
421
+ tbody: {
422
+ align: ["string", "align"],
423
+ ch: ["string", "char"],
424
+ chOff: ["string", "charoff"],
425
+ vAlign: ["string", "valign"],
426
+ },
427
+ td: {
428
+ abbr: ["string", "abbr"],
429
+ align: ["string", "align"],
430
+ axis: ["string", "axis"],
431
+ bgColor: ["string", "bgcolor"],
432
+ ch: ["string", "char"],
433
+ chOff: ["string", "charoff"],
434
+ colSpan: ["number", "colspan", 1],
435
+ headers: ["string", "headers"],
436
+ height: ["string", "height"],
437
+ noWrap: ["presence", "nowrap"],
438
+ rowSpan: ["number", "rowspan", 1],
439
+ scope: ["enum", "scope", "", "", ["row", "col", "rowgroup", "colgroup"]],
440
+ vAlign: ["string", "valign"],
441
+ width: ["string", "width"],
442
+ },
443
+ template: {
444
+ /**
445
+ * Measured identical on Chromium, Firefox and WebKit: absent and invalid both answer `''`, and a
446
+ * valid keyword is answered lowercased (`'OPEN'` → `'open'`). It is here rather than excluded
447
+ * because this package **emits** `<template shadowrootmode>` for declarative shadow DOM, so a
448
+ * component reading it back on the server is asking about markup this renderer wrote.
449
+ */
450
+ shadowRootMode: ["enum", "shadowrootmode", "", "", ["open", "closed"]],
451
+ shadowRootClonable: ["presence", "shadowrootclonable"],
452
+ shadowRootDelegatesFocus: ["presence", "shadowrootdelegatesfocus"],
453
+ shadowRootSerializable: ["presence", "shadowrootserializable"],
454
+ },
455
+ textarea: {
456
+ autocomplete: ["enum", "autocomplete", "", "", ["on", "off"]],
457
+ cols: ["number", "cols", 20],
458
+ dirName: ["string", "dirname"],
459
+ disabled: ["presence", "disabled"],
460
+ maxLength: ["number", "maxlength", -1],
461
+ minLength: ["number", "minlength", -1],
462
+ name: ["string", "name"],
463
+ placeholder: ["string", "placeholder"],
464
+ readOnly: ["presence", "readonly"],
465
+ required: ["presence", "required"],
466
+ rows: ["number", "rows", 2],
467
+ wrap: ["string", "wrap"],
468
+ },
469
+ tfoot: {
470
+ align: ["string", "align"],
471
+ ch: ["string", "char"],
472
+ chOff: ["string", "charoff"],
473
+ vAlign: ["string", "valign"],
474
+ },
475
+ th: {
476
+ abbr: ["string", "abbr"],
477
+ align: ["string", "align"],
478
+ axis: ["string", "axis"],
479
+ bgColor: ["string", "bgcolor"],
480
+ ch: ["string", "char"],
481
+ chOff: ["string", "charoff"],
482
+ colSpan: ["number", "colspan", 1],
483
+ headers: ["string", "headers"],
484
+ height: ["string", "height"],
485
+ noWrap: ["presence", "nowrap"],
486
+ rowSpan: ["number", "rowspan", 1],
487
+ scope: ["enum", "scope", "", "", ["row", "col", "rowgroup", "colgroup"]],
488
+ vAlign: ["string", "valign"],
489
+ width: ["string", "width"],
490
+ },
491
+ thead: {
492
+ align: ["string", "align"],
493
+ ch: ["string", "char"],
494
+ chOff: ["string", "charoff"],
495
+ vAlign: ["string", "valign"],
496
+ },
497
+ time: {
498
+ dateTime: ["string", "datetime"],
499
+ },
500
+ tr: {
501
+ align: ["string", "align"],
502
+ bgColor: ["string", "bgcolor"],
503
+ ch: ["string", "char"],
504
+ chOff: ["string", "charoff"],
505
+ vAlign: ["string", "valign"],
506
+ },
507
+ track: {
508
+ default: ["presence", "default"],
509
+ kind: ["enum", "kind", "subtitles", "metadata", ["subtitles", "captions", "descriptions", "chapters", "metadata"]],
510
+ label: ["string", "label"],
511
+ src: ["string", "src"],
512
+ srclang: ["string", "srclang"],
513
+ },
514
+ ul: {
515
+ compact: ["presence", "compact"],
516
+ type: ["string", "type"],
517
+ },
518
+ video: {
519
+ disablePictureInPicture: ["presence", "disablepictureinpicture"],
520
+ height: ["number", "height", 0],
521
+ poster: ["string", "poster"],
522
+ width: ["number", "width", 0],
523
+ },
524
+ };
525
+ /**
526
+ * The four properties a browser deliberately does **not** reflect, and which this DOM does anyway.
527
+ *
528
+ * `input.value`, `input.checked`, `option.selected` and `textarea.value` carry a "dirty value" in
529
+ * the platform: assigning one changes what the control shows without touching the markup, so that a
530
+ * reload restores what the author wrote. Copying that exactly would be wrong here for a reason that
531
+ * has nothing to do with fidelity — **on a server the markup is the whole output**, so an assignment
532
+ * the markup cannot carry is an assignment that is silently lost.
533
+ *
534
+ * `@verajs/ssr` had already made this call for template bindings: `serializer.js` mirrors
535
+ * `.value`/`.checked`/`.selected` to attributes on form elements "so hydration can read form state
536
+ * back out of the markup". Doing it here too is that same rule applied to the other way of writing
537
+ * the same thing — a property assignment in `connectedCallback` now behaves like the binding, rather
538
+ * than being the one path that quietly drops the value.
539
+ *
540
+ * The reads follow the platform exactly: absent means `''` or `false`, `textarea.value` is its
541
+ * content, and `select.value` is the value of the option that is selected.
542
+ */
543
+ /**
544
+ * **`[LegacyNullToEmptyString]`** — a handful of IDL string attributes store `''` for `null` rather
545
+ * than the word `"null"`, and `input.value`, `textarea.value` and `innerHTML` are three of them.
546
+ *
547
+ * This is the same defect the README already records as found and fixed: *"`textContent = null`
548
+ * writing the word 'null'"*. It was fixed where it was found rather than for the rule, so the other
549
+ * members of the class stayed wrong — the exact pattern `tests/ssr-spread-equivalence.test.mjs`
550
+ * opens by describing.
551
+ *
552
+ * It matters because `element.value = maybeNull` in a component is ordinary code. The server wrote
553
+ * `value="null"` where the client stores `''`, so the control showed the word "null" until hydration
554
+ * replaced it — and the surface comparison could not catch it, because that check compares a member's
555
+ * *shape* rather than its answer to a particular input, which the README says in as many words.
556
+ *
557
+ * `undefined` is **not** included: the platform stringifies it to `"undefined"`, and only `null` is
558
+ * special-cased by the extended attribute.
559
+ */
560
+ const legacyNullToEmptyString = (value) => (value === null ? '' : `${value}`);
561
+ const FORM_STATE = {
562
+ input: {
563
+ value: {
564
+ get() {
565
+ return this.getAttribute('value') ?? '';
566
+ },
567
+ set(value) {
568
+ this.setAttribute('value', legacyNullToEmptyString(value));
569
+ },
570
+ },
571
+ checked: {
572
+ get() {
573
+ return this.hasAttribute('checked');
574
+ },
575
+ set(value) {
576
+ if (value)
577
+ this.setAttribute('checked', '');
578
+ else
579
+ this.removeAttribute('checked');
580
+ },
581
+ },
582
+ },
583
+ textarea: {
584
+ /** A `<textarea>` has no `value` attribute — its value *is* its content, in markup and here. */
585
+ value: {
586
+ get() {
587
+ return this.textContent;
588
+ },
589
+ set(value) {
590
+ this.textContent = legacyNullToEmptyString(value);
591
+ },
592
+ },
593
+ },
594
+ option: {
595
+ selected: {
596
+ get() {
597
+ return this.hasAttribute('selected');
598
+ },
599
+ set(value) {
600
+ if (value)
601
+ this.setAttribute('selected', '');
602
+ else
603
+ this.removeAttribute('selected');
604
+ },
605
+ },
606
+ },
607
+ select: {
608
+ /**
609
+ * A `<select>` has no `value` content attribute at all: its value is whichever option is
610
+ * selected, so reading walks the options and writing selects one. A value matching no option
611
+ * cannot be served — the same limitation the README records, since there is no markup for it.
612
+ */
613
+ value: {
614
+ get() {
615
+ const options = this.querySelectorAll('option');
616
+ const chosen = options.find((option) => option.hasAttribute('selected')) ?? options[0];
617
+ return chosen === undefined ? '' : (chosen.getAttribute('value') ?? chosen.textContent);
618
+ },
619
+ set(value) {
620
+ const wanted = `${value}`;
621
+ for (const option of this.querySelectorAll('option')) {
622
+ const own = option.getAttribute('value') ?? option.textContent;
623
+ if (own === wanted)
624
+ option.setAttribute('selected', '');
625
+ else
626
+ option.removeAttribute('selected');
627
+ }
628
+ },
629
+ },
630
+ },
631
+ };
632
+ /** Per-tag constructors, built once and shared by every element of that tag. */
633
+ const constructors = new Map();
634
+ const define = (proto, property, accessors) => Object.defineProperty(proto, property, { ...accessors, configurable: true });
635
+ /**
636
+ * The constructor an element of this tag should be built with: `Base` when the tag has no interface
637
+ * of its own, otherwise a subclass carrying its properties.
638
+ *
639
+ * A class per tag rather than accessors on the shared prototype, because `'disabled' in paragraph`
640
+ * must stay `false` — an element answering for members its interface does not have is the same lie
641
+ * as one missing the members it does.
642
+ *
643
+ * A subclass rather than `Object.setPrototypeOf` on a finished element, which was the first shape
644
+ * this took. Measured over 20,000 elements, three runs each: setting the prototype afterwards cost
645
+ * **~745 ns** per `<input>` (and once wandered to 1004) against ~400 ns for a `<div>`; building it
646
+ * as its own class costs **~458 ns**. The `<div>` figure is unchanged either way, which is the part
647
+ * worth recording — the penalty was local to the element whose prototype was mutated, not spread
648
+ * across the shared path, so the first draft of this comment blamed a deopt it had not measured.
649
+ */
650
+ export const interfaceFor = (tag, Base) => {
651
+ const table = ELEMENT_REFLECTIONS[tag];
652
+ const state = FORM_STATE[tag];
653
+ if (table === undefined && state === undefined)
654
+ return Base;
655
+ const cached = constructors.get(tag);
656
+ if (cached !== undefined)
657
+ return cached;
658
+ const Element = class extends Base {
659
+ };
660
+ const proto = Element.prototype;
661
+ for (const [property, entry] of Object.entries(table ?? {})) {
662
+ const [kind, attribute] = entry;
663
+ if (kind === 'presence') {
664
+ const absent = entry[2] ?? false;
665
+ define(proto, property, {
666
+ get() {
667
+ return this.hasAttribute(attribute) ? true : absent;
668
+ },
669
+ set(value) {
670
+ if (value)
671
+ this.setAttribute(attribute, '');
672
+ else
673
+ this.removeAttribute(attribute);
674
+ },
675
+ });
676
+ }
677
+ else if (kind === 'string') {
678
+ define(proto, property, {
679
+ get() {
680
+ return this.getAttribute(attribute) ?? '';
681
+ },
682
+ set(value) {
683
+ this.setAttribute(attribute, `${value}`);
684
+ },
685
+ });
686
+ }
687
+ else if (kind === 'number') {
688
+ /**
689
+ * **HTML's "rules for parsing integers", which `Number.parseInt` is not.**
690
+ *
691
+ * Measured against Chromium, Firefox and WebKit by `tests/browser/reflection-parsing.test.js`;
692
+ * `Number.parseInt(raw, 10)` diverged from all three on two inputs, and both are the shape this
693
+ * package's README calls its worst: the server and the client disagree about something neither of
694
+ * them renders, so nothing fails until a hydration mismatch surfaces somewhere else entirely.
695
+ *
696
+ * | attribute value | every engine | `parseInt` |
697
+ * | -------------------- | ------------ | ---------- |
698
+ * | `9007199254740993` | the default | 9007199254740992 |
699
+ * | `"\u00a05"` (NBSP) | the default | 5 |
700
+ *
701
+ * The first: the value is outside a `long`, so it is INVALID and the property answers its default —
702
+ * not a float that lost its last digits. The second: these rules skip ASCII whitespace only, while
703
+ * `parseInt` skips every Unicode space, so a non-breaking space made a value parse here that no
704
+ * engine accepts.
705
+ */
706
+ const ASCII_SPACE = ' \t\n\f\r';
707
+ const LONG_MIN = -2147483648;
708
+ const LONG_MAX = 2147483647;
709
+ const parseReflectedInteger = (raw) => {
710
+ let i = 0;
711
+ while (i < raw.length && ASCII_SPACE.includes(raw[i]))
712
+ i++;
713
+ let sign = 1;
714
+ if (raw[i] === '-') {
715
+ sign = -1;
716
+ i++;
717
+ }
718
+ else if (raw[i] === '+')
719
+ i++;
720
+ const start = i;
721
+ while (i < raw.length && raw[i] >= '0' && raw[i] <= '9')
722
+ i++;
723
+ if (i === start)
724
+ return null;
725
+ const value = sign * Number(raw.slice(start, i));
726
+ return value < LONG_MIN || value > LONG_MAX ? null : value;
727
+ };
728
+ const absent = entry[2];
729
+ define(proto, property, {
730
+ get() {
731
+ const raw = this.getAttribute(attribute);
732
+ if (raw === null)
733
+ return absent;
734
+ /** A browser answers the default for anything it cannot parse, not `NaN`. */
735
+ const parsed = parseReflectedInteger(raw);
736
+ return parsed === null ? absent : parsed;
737
+ },
738
+ /**
739
+ * **A numeric property converts before it writes, and this wrote the value verbatim.**
740
+ *
741
+ * The platform applies the WebIDL conversion for the property's type at *assignment*, and
742
+ * writes the **converted** number to the attribute — not what the caller passed. Measured in
743
+ * Chromium across all 31 `number` reflections here, and every one shares this part:
744
+ *
745
+ * | written | attribute a browser writes | this wrote |
746
+ * | --- | --- | --- |
747
+ * | `3.9` | `"3"` | `"3.9"` |
748
+ * | `'probe'` | `"0"` | `"probe"` |
749
+ * | `''` | `"0"` | `""` |
750
+ *
751
+ * The reachable case is the first. `element.width = someComputedValue` is ordinary code, and
752
+ * a fractional result made the server write `width="3.9"` where the client writes `width="3"`
753
+ * — a hydration mismatch nobody did anything wrong to earn.
754
+ *
755
+ * **What this deliberately does not do** is the per-property part. A *negative* value is
756
+ * clamped to 0 by eleven of these properties, to 1 by six, refused outright by four
757
+ * (`maxLength`, `minLength`), allowed by two, and replaced with an element default by
758
+ * `canvas.width`/`height` and `input.size`. Three more (`meter.min`/`max`, `progress.max`) are
759
+ * `double` rather than `unsigned long` and do not truncate at all.
760
+ *
761
+ * Encoding that means thirty-one hand-classified rows in this table — which is how
762
+ * `area.shape`, `ol.type` and `textarea.wrap` came to answer with the probe value used to
763
+ * measure them. A negative width is already a caller's mistake; a fractional one is not. The
764
+ * thirty-one rows were classified against a measured table, kept with the project's private
765
+ * audits, if that trade is ever worth revisiting.
766
+ */
767
+ set(value) {
768
+ const number = Number(value);
769
+ this.setAttribute(attribute, `${Number.isFinite(number) ? Math.trunc(number) : 0}`);
770
+ },
771
+ });
772
+ }
773
+ else {
774
+ const [, , missing, invalid, states] = entry;
775
+ define(proto, property, {
776
+ get() {
777
+ const raw = this.getAttribute(attribute);
778
+ if (raw === null)
779
+ return missing;
780
+ /** Enumerated attributes are ASCII case-insensitive and the getter answers canonically. */
781
+ const state = raw.toLowerCase();
782
+ return states.includes(state) ? state : invalid;
783
+ },
784
+ /** The setter writes what it is given; only the getter maps to a state. */
785
+ set(value) {
786
+ this.setAttribute(attribute, `${value}`);
787
+ },
788
+ });
789
+ }
790
+ }
791
+ for (const [property, accessors] of Object.entries(state ?? {}))
792
+ define(proto, property, accessors);
793
+ constructors.set(tag, Element);
794
+ return Element;
795
+ };
796
+ /**
797
+ * **What the engines expose that this table deliberately does not**, so the next reader does not
798
+ * have to measure it again to find out why:
799
+ *
800
+ * - `base.href`, `form.action`, `button.formAction`, `input.formAction` — resolved against the
801
+ * document's URL, which a server render does not have. Answering the raw attribute would be a
802
+ * different value from the browser's; answering an absolute URL would require inventing an origin.
803
+ * - `input.width`, `input.height` — read back from layout, so a browser answers `0` for anything it
804
+ * has not laid out, whatever the attribute says.
805
+ * - `meter.value`, `meter.low`, `meter.high`, `meter.optimum`, `progress.value` — clamped against
806
+ * each other and against `max`, so the property is not the attribute.
807
+ * - `button.command` — canonicalized to `''` for anything outside its state list, which is not yet
808
+ * stable across engines.
809
+ * - Vendor extensions present in one engine only: `a.attributionSourceId` and its two neighbors,
810
+ * `area.hreflang`, `area.type`, `canvas.mozOpaque`, `iframe.csp`, `iframe.credentialless`,
811
+ * `iframe.allowPaymentRequest`, `input.incremental`, `input.alpha`, `input.colorSpace`,
812
+ * `input.switch`, `video.playsInline`, `video.autoPictureInPicture`,
813
+ * `video.webkitWirelessVideoPlaybackDisabled`.
814
+ *
815
+ * And the six where the engines disagree and the majority was taken, none of which can reach the
816
+ * markup: `input.type` (Chromium accepts `month` and `week`; the others do not), `link.as` (three
817
+ * different state lists), `img.loading` and `iframe.loading` (absent reads `auto` in Chromium and
818
+ * `eager` elsewhere), `button.popoverTargetAction` and `input.popoverTargetAction` (absent reads
819
+ * `''` in Firefox and `toggle` elsewhere).
820
+ */