@adia-ai/web-components 0.6.6 → 0.6.8

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 (103) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/USAGE.md +286 -5
  3. package/bin/doc.mjs +379 -0
  4. package/components/accordion/accordion.examples.md +49 -0
  5. package/components/action-list/action-list.examples.md +33 -0
  6. package/components/agent-artifact/agent-artifact.examples.md +28 -0
  7. package/components/agent-feedback-bar/agent-feedback-bar.examples.md +24 -0
  8. package/components/agent-questions/agent-questions.examples.md +13 -0
  9. package/components/agent-reasoning/agent-reasoning.examples.md +28 -0
  10. package/components/agent-suggestions/agent-suggestions.examples.md +19 -0
  11. package/components/agent-trace/agent-trace.examples.md +19 -0
  12. package/components/alert/alert.examples.md +19 -0
  13. package/components/aside/aside.examples.md +38 -0
  14. package/components/avatar/avatar.examples.md +19 -0
  15. package/components/badge/badge.examples.md +19 -0
  16. package/components/block/block.examples.md +29 -0
  17. package/components/breadcrumb/breadcrumb.examples.md +32 -0
  18. package/components/button/button.examples.md +19 -0
  19. package/components/calendar-picker/calendar-picker.examples.md +23 -0
  20. package/components/canvas/canvas.examples.md +49 -0
  21. package/components/card/card.examples.md +25 -0
  22. package/components/chart/chart.examples.md +19 -0
  23. package/components/chart-legend/chart-legend.examples.md +22 -0
  24. package/components/chat-thread/chat-thread.examples.md +35 -0
  25. package/components/check/check.examples.md +19 -0
  26. package/components/code/code.examples.md +31 -0
  27. package/components/col/col.examples.md +11 -0
  28. package/components/color-input/color-input.examples.md +19 -0
  29. package/components/color-picker/color-picker.examples.md +19 -0
  30. package/components/command/command.examples.md +58 -0
  31. package/components/demo-toggle/demo-toggle.examples.md +19 -0
  32. package/components/description-list/description-list.examples.md +37 -0
  33. package/components/divider/divider.examples.md +31 -0
  34. package/components/drawer/drawer.examples.md +63 -0
  35. package/components/embed/embed.examples.md +19 -0
  36. package/components/empty-state/empty-state.examples.md +21 -0
  37. package/components/feed/feed.examples.md +19 -0
  38. package/components/field/field.examples.md +29 -0
  39. package/components/fields/fields.examples.md +58 -0
  40. package/components/footer/footer.examples.md +18 -0
  41. package/components/grid/grid.examples.md +21 -0
  42. package/components/header/header.examples.md +32 -0
  43. package/components/heatmap/heatmap.examples.md +19 -0
  44. package/components/icon/icon.examples.md +19 -0
  45. package/components/image/image.examples.md +19 -0
  46. package/components/input/input.examples.md +21 -0
  47. package/components/inspector/inspector.examples.md +27 -0
  48. package/components/kbd/kbd.examples.md +29 -0
  49. package/components/link/link.examples.md +25 -0
  50. package/components/list/list.examples.md +33 -0
  51. package/components/menu/menu.examples.md +37 -0
  52. package/components/modal/modal.examples.md +43 -0
  53. package/components/nav/nav.examples.md +39 -0
  54. package/components/nav-group/nav-group.examples.md +35 -0
  55. package/components/nav-item/nav-item.examples.md +25 -0
  56. package/components/noodles/noodles.examples.md +30 -0
  57. package/components/option-card/option-card.examples.md +47 -0
  58. package/components/otp-input/otp-input.examples.md +19 -0
  59. package/components/page/page.examples.md +46 -0
  60. package/components/pagination/pagination.examples.md +19 -0
  61. package/components/pane/pane.examples.md +40 -0
  62. package/components/pipeline-status/pipeline-status.examples.md +19 -0
  63. package/components/popover/popover.examples.md +34 -0
  64. package/components/progress/progress.examples.md +19 -0
  65. package/components/progress-row/progress-row.examples.md +19 -0
  66. package/components/radio/radio.examples.md +19 -0
  67. package/components/range/range.examples.md +19 -0
  68. package/components/rating/rating.examples.md +19 -0
  69. package/components/richtext/richtext.examples.md +19 -0
  70. package/components/row/row.examples.md +11 -0
  71. package/components/search/search.examples.md +19 -0
  72. package/components/section/section.examples.md +37 -0
  73. package/components/segment/segment.examples.md +32 -0
  74. package/components/segmented/segmented.examples.md +31 -0
  75. package/components/select/select.examples.md +49 -0
  76. package/components/skeleton/skeleton.examples.md +19 -0
  77. package/components/slider/slider.examples.md +21 -0
  78. package/components/stack/stack.examples.md +10 -0
  79. package/components/stat/stat.examples.md +19 -0
  80. package/components/step-progress/step-progress.examples.md +19 -0
  81. package/components/stepper/stepper.examples.md +37 -0
  82. package/components/stream/stream.examples.md +19 -0
  83. package/components/swatch/swatch.examples.md +23 -0
  84. package/components/swiper/swiper.examples.md +139 -0
  85. package/components/switch/switch.examples.md +19 -0
  86. package/components/table/table.examples.md +19 -0
  87. package/components/table-toolbar/table-toolbar.examples.md +12 -0
  88. package/components/tabs/tabs.examples.md +49 -0
  89. package/components/tag/tag.examples.md +19 -0
  90. package/components/text/text.examples.md +19 -0
  91. package/components/textarea/textarea.examples.md +23 -0
  92. package/components/timeline/timeline.examples.md +35 -0
  93. package/components/toast/toast.examples.md +19 -0
  94. package/components/toggle-group/toggle-group.examples.md +33 -0
  95. package/components/toggle-scheme/toggle-scheme.examples.md +19 -0
  96. package/components/toolbar/toolbar.examples.md +46 -0
  97. package/components/tooltip/tooltip.examples.md +25 -0
  98. package/components/tree/tree.examples.md +57 -0
  99. package/components/upload/upload.examples.md +19 -0
  100. package/core/template.js +236 -7
  101. package/core/template.test.js +294 -0
  102. package/custom-elements.json +9012 -0
  103. package/package.json +7 -1
package/core/template.js CHANGED
@@ -91,6 +91,106 @@ function getTemplate(strings) {
91
91
  return tpl;
92
92
  }
93
93
 
94
+ // §-TBD (FB-55, P1): the HTML parser lowercases attribute names inside
95
+ // <template>.innerHTML per HTML5 §13.2.5.32, so `.className=${expr}`
96
+ // arrives at scan() as `.classname`. The `name.slice(1)` strips the dot
97
+ // and the binding writes to a lowercase enumerable expando instead of
98
+ // invoking the camelCase property setter. Net: classes never apply, no
99
+ // warning, no error.
100
+ //
101
+ // The trap affects every camelCase DOM property surface — `.className`,
102
+ // `.innerText`, `.tabIndex`, `.ariaLabel`, `.contentEditable`,
103
+ // `.readOnly`, `.maxLength`, `.minLength`, `.colSpan`, `.rowSpan` — AND
104
+ // every camelCase property declared via `UIElement.static properties`
105
+ // (e.g. `.minL`, `.maxChroma`, `.hueDriftMax`, `.colorScheme`,
106
+ // `.strokeWidth`, `.collapseKeepLeading`). Even the canonical example
107
+ // `<my-panel .minL=${minL}>` from packages/web-components/README.md:212
108
+ // silently failed pre-fix.
109
+ //
110
+ // Two-layer fix:
111
+ //
112
+ // 1. Static PROP_CASE_FIX map covers built-in DOM camelCase property
113
+ // names (zero-cost lookup, no prototype walk per binding for the
114
+ // common case).
115
+ //
116
+ // 2. Prototype-walk fallback finds the canonical camelCase property
117
+ // name on the element's prototype chain via case-insensitive
118
+ // match. Cost is O(prototype-chain-depth × prototype-key-count)
119
+ // per UNIQUE template binding (cached in parts[i].name, not
120
+ // re-walked per update() tick). Custom-element prototype chains
121
+ // are short (subclass → UIElement → HTMLElement → Element → Node
122
+ // → EventTarget); cost is negligible.
123
+ //
124
+ // Backward-compatible: when the prototype walk finds no case-insensitive
125
+ // match (genuine lowercase-expando case — rare but possible), the
126
+ // original lowercase name is preserved. No consumer that was
127
+ // deliberately writing to a lowercase expando regresses.
128
+ //
129
+ // Verification: 8-test matrix in core/template.test.js's FB-55 describe
130
+ // block. RESPONSE-55 documents the trap end-to-end.
131
+ const PROP_CASE_FIX = {
132
+ classname: 'className',
133
+ innertext: 'innerText',
134
+ innerhtml: 'innerHTML',
135
+ outerhtml: 'outerHTML',
136
+ textcontent: 'textContent',
137
+ tabindex: 'tabIndex',
138
+ arialabel: 'ariaLabel',
139
+ ariadescribedby: 'ariaDescribedBy',
140
+ arialabelledby: 'ariaLabelledBy',
141
+ ariarole: 'role',
142
+ contenteditable: 'contentEditable',
143
+ readonly: 'readOnly',
144
+ maxlength: 'maxLength',
145
+ minlength: 'minLength',
146
+ colspan: 'colSpan',
147
+ rowspan: 'rowSpan',
148
+ cellpadding: 'cellPadding',
149
+ cellspacing: 'cellSpacing',
150
+ usemap: 'useMap',
151
+ ismap: 'isMap',
152
+ accesskey: 'accessKey',
153
+ defaultchecked: 'defaultChecked',
154
+ defaultvalue: 'defaultValue',
155
+ defaultselected: 'defaultSelected',
156
+ };
157
+
158
+ // Resolve a lowercase property name to its canonical camelCase form on
159
+ // the given element. Returns the original `lower` name when no
160
+ // case-insensitive match exists (preserves expando semantics). Walks
161
+ // instance own-properties first (UIElement installs camelCase props via
162
+ // `Object.defineProperty(this, ...)` in the constructor, so they live
163
+ // on the instance, not the prototype), then prototype chain. Skips
164
+ // Object.prototype to avoid noisy matches on `toString` etc.
165
+ //
166
+ // IMPORTANT: at scan() time the custom element has typically NOT yet
167
+ // been constructed (template fragment is cloned + scanned before
168
+ // insertion → upgrade), so instance-defined props aren't visible yet.
169
+ // PROP_CASE_FIX covers built-in DOM camelCase props at scan() time;
170
+ // the per-element walk runs ALSO at applyValue() time (lazy resolve,
171
+ // cached on the part after first hit) to catch UIElement instance props
172
+ // once the element has been upgraded.
173
+ function resolvePropName(el, lower) {
174
+ if (PROP_CASE_FIX[lower]) return PROP_CASE_FIX[lower];
175
+ // Instance own-properties (UIElement installProps lives here).
176
+ const ownNames = Object.getOwnPropertyNames(el);
177
+ for (let i = 0; i < ownNames.length; i++) {
178
+ const n = ownNames[i];
179
+ if (n !== lower && n.toLowerCase() === lower) return n;
180
+ }
181
+ // Prototype chain (built-in DOM camelCase + class-defined accessors).
182
+ let proto = Object.getPrototypeOf(el);
183
+ while (proto && proto !== Object.prototype) {
184
+ const names = Object.getOwnPropertyNames(proto);
185
+ for (let i = 0; i < names.length; i++) {
186
+ const n = names[i];
187
+ if (n !== lower && n.toLowerCase() === lower) return n;
188
+ }
189
+ proto = Object.getPrototypeOf(proto);
190
+ }
191
+ return lower;
192
+ }
193
+
94
194
  export function stamp(result, container) {
95
195
  let inst = container._i;
96
196
  if (!inst || inst.s !== result.strings) {
@@ -104,12 +204,118 @@ export function stamp(result, container) {
104
204
  function mount(result, container) {
105
205
  const { strings } = result;
106
206
  const tpl = getTemplate(strings);
107
- const f = tpl.content.cloneNode(true);
207
+ let f = tpl.content.cloneNode(true);
208
+
209
+ // §-TBD (FB-57, P1): when stamping into an SVG or MathML context, the
210
+ // fragment's Elements arrive HTML-namespaced because `tpl.innerHTML =
211
+ // m` is parsed at document level without foreign-content context. SVG
212
+ // and MathML layout are namespace-strict — HTMLUnknownElement nodes
213
+ // inside an SVG render to zero-bound-rect invisible. Re-namespace the
214
+ // fragment before insertion, respecting `<foreignObject>` and
215
+ // `<annotation-xml>` HTML boundaries per the HTML5 foreign-content
216
+ // insertion-mode spec.
217
+ //
218
+ // Discriminator runs once per mount() call (no per-update cost).
219
+ // Re-namespacing walks the fragment recursively (O(node-count)),
220
+ // cheap for typical interpolation arrays (16 lines + 11 stops in
221
+ // the canonical curve-preview case = 27 createElementNS calls).
222
+ //
223
+ // Implementation site choice: mount() rather than getTemplate(),
224
+ // because:
225
+ // - container reference is in hand only at mount()
226
+ // - the same cached template may be stamped into either context;
227
+ // namespacing per-cache-entry would double the WeakMap size
228
+ // and require a cache-key extension
229
+ // - cloning is already happening here; re-namespacing piggybacks
230
+ // on the existing fragment walk
231
+ //
232
+ // RESPONSE-57 documents the trap end-to-end. Regression tests pin
233
+ // the inline-SVG path (must keep working), nested-SVG path (would
234
+ // fail pre-fix), foreignObject boundary (HTML inside SVG stays
235
+ // HTML), and MathML parallel.
236
+ const ns = foreignContentNS(container);
237
+ if (ns) f = renamespaceFragment(f, ns);
238
+
108
239
  const parts = scan(f, result.values.length);
109
240
  container.replaceChildren(f);
110
241
  return { s: strings, p: parts };
111
242
  }
112
243
 
244
+ const SVG_NS = 'http://www.w3.org/2000/svg';
245
+ const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';
246
+ const XHTML_NS = 'http://www.w3.org/1999/xhtml';
247
+
248
+ // Determine whether `container` is inside an SVG or MathML subtree, and
249
+ // return the namespace to re-namespace stamped fragments into. Returns
250
+ // null when the container is in HTML context (the no-op case — vast
251
+ // majority of templates). Respects `<foreignObject>` (SVG) and
252
+ // `<annotation-xml encoding=text/html|application/xhtml+xml>` (MathML)
253
+ // HTML boundaries per HTML5 §12.2.5 foreign-content insertion mode.
254
+ function foreignContentNS(container) {
255
+ if (!container || container.nodeType !== 1) return null;
256
+ // Direct check — container's own namespace is a fast-path.
257
+ if (container.namespaceURI === SVG_NS) return SVG_NS;
258
+ if (container.namespaceURI === MATHML_NS) return MATHML_NS;
259
+ // Walk ancestors to find a foreign-content root. `closest()` matches
260
+ // the element itself + ancestors, so this catches the wrap()-span
261
+ // case (HTML span inside an SVG subtree). The first match wins —
262
+ // foreignObject/annotation-xml inside SVG short-circuits before we
263
+ // see the outer <svg>, correctly returning null (HTML context).
264
+ if (typeof container.closest !== 'function') return null;
265
+ const anchor = container.closest('svg, math, foreignObject, annotation-xml');
266
+ if (!anchor) return null;
267
+ const tag = anchor.localName;
268
+ if (tag === 'foreignobject' || tag === 'foreignObject') return null;
269
+ if (tag === 'annotation-xml') {
270
+ const enc = (anchor.getAttribute('encoding') || '').toLowerCase();
271
+ if (enc === 'text/html' || enc === 'application/xhtml+xml') return null;
272
+ return MATHML_NS;
273
+ }
274
+ if (tag === 'svg') return SVG_NS;
275
+ if (tag === 'math') return MATHML_NS;
276
+ return null;
277
+ }
278
+
279
+ // Recursively transfer fragment children into a new fragment with each
280
+ // Element recreated in the target namespace. Text/comment nodes clone
281
+ // unchanged. `<foreignObject>` and `<annotation-xml encoding=text/html>`
282
+ // stay in the target namespace themselves, but their descendants revert
283
+ // to HTML (matches the browser parser's foreign-content insertion mode).
284
+ function renamespaceFragment(fragment, ns) {
285
+ const out = document.createDocumentFragment();
286
+ transferChildren(fragment, out, ns);
287
+ return out;
288
+ }
289
+
290
+ function transferChildren(src, dstParent, ns) {
291
+ for (const child of [...src.childNodes]) {
292
+ const t = child.nodeType;
293
+ if (t === 1 /* Element */) {
294
+ const dst = document.createElementNS(ns, child.localName);
295
+ for (const a of child.attributes) {
296
+ if (a.namespaceURI) dst.setAttributeNS(a.namespaceURI, a.name, a.value);
297
+ else dst.setAttribute(a.name, a.value);
298
+ }
299
+ dstParent.appendChild(dst);
300
+ // Boundary handling: <foreignObject> (SVG) and
301
+ // <annotation-xml encoding=text/html> (MathML) revert to HTML.
302
+ const local = child.localName;
303
+ let childNs = ns;
304
+ if (ns === SVG_NS && (local === 'foreignObject' || local === 'foreignobject')) {
305
+ childNs = XHTML_NS;
306
+ } else if (ns === MATHML_NS && local === 'annotation-xml') {
307
+ const enc = (child.getAttribute('encoding') || '').toLowerCase();
308
+ if (enc === 'text/html' || enc === 'application/xhtml+xml') childNs = XHTML_NS;
309
+ }
310
+ transferChildren(child, dst, childNs);
311
+ } else {
312
+ // Text, comment, etc. — clone unchanged. Comments are load-bearing
313
+ // (the `<!--p:N-->` placeholders scan() looks for).
314
+ dstParent.appendChild(child.cloneNode(true));
315
+ }
316
+ }
317
+ }
318
+
113
319
  function scan(fragment, count) {
114
320
  const parts = new Array(count);
115
321
  const w = document.createTreeWalker(fragment, 129);
@@ -146,14 +352,21 @@ function scan(fragment, count) {
146
352
  // canonical style-object path; for everything else keep
147
353
  // the generic property-assignment recipe.
148
354
  const a = attr.name;
355
+ // §-TBD (FB-55 #2, P1): updated post-fix. The v0.5.5 §184
356
+ // recommendation had `.className=${expression}` first;
357
+ // that path now works (§-TBD PROP_CASE_FIX above) but
358
+ // `class="${expression}"` is the more discoverable form
359
+ // that doesn't require knowing the camelCase property
360
+ // name. Promoting it first. The `.classList=` line is
361
+ // removed entirely — classList is a read-only getter, no
362
+ // PROP_CASE_FIX entry can make it assignable.
149
363
  const specific =
150
364
  a === 'class'
151
- ? ` .className=\${expression} write to the className property (NOT .class, which is an expando)\n` +
152
- ` class="\${expression}" full replacement (whole class string is the expression)\n` +
153
- ` .classList=\${{foo: true, bar: false}} ← if/when implemented; verify in USAGE.md\n`
365
+ ? ` class="\${expression}" full replacement (whole class string is the expression)\n` +
366
+ ` .className=\${expression} writes to the className property (resolved camelCase since FB-55 fix)\n`
154
367
  : a === 'style'
155
- ? ` .style.cssText=\${expression} write CSS text to .style.cssText\n` +
156
- ` style="\${expression}" full replacement of the style string\n`
368
+ ? ` style="\${expression}" full replacement of the style string\n` +
369
+ ` .style.cssText=\${expression} write CSS text via the style.cssText accessor\n`
157
370
  : ` ${a}="\${expression}" ← full replacement (whole attr is the placeholder)\n` +
158
371
  ` .${a}=\${expression} ← property assignment (preferred for objects/functions)\n`;
159
372
  // eslint-disable-next-line no-console
@@ -173,8 +386,12 @@ function scan(fragment, count) {
173
386
  n.removeAttribute(name);
174
387
  parts[i] = { t: 'e', n, name: name.slice(1), c: undefined, _fx: null };
175
388
  } else if (name[0] === '.') {
389
+ // §-TBD (FB-55, P1): resolve the parser-lowercased property
390
+ // name back to its canonical camelCase via PROP_CASE_FIX +
391
+ // prototype walk. See PROP_CASE_FIX comment above for context.
392
+ // Lazy-resolve in applyValue() too — see _resolved guard there.
176
393
  n.removeAttribute(name);
177
- parts[i] = { t: 'p', n, name: name.slice(1), c: undefined, _fx: null };
394
+ parts[i] = { t: 'p', n, name: resolvePropName(n, name.slice(1)), c: undefined, _fx: null, _resolved: false };
178
395
  } else if (name[0] === '?') {
179
396
  // §250 (v0.5.11, FEEDBACK-27): Lit-style boolean attribute syntax
180
397
  // (`?attr=${bool}`) is NOT supported. Without this branch, the
@@ -256,6 +473,18 @@ function applyValue(p, v) {
256
473
  if (v == null || v === false) p.n.removeAttribute(p.name);
257
474
  else p.n.setAttribute(p.name, v === true ? '' : v);
258
475
  } else if (p.t === 'p') {
476
+ // §-TBD (FB-55, P1): two-phase property-name resolution. PROP_CASE_FIX
477
+ // resolved at scan() time for zero-cost built-in DOM camelCase (the
478
+ // common case). For UIElement custom-element props installed on the
479
+ // INSTANCE via the constructor's installProps(), the property doesn't
480
+ // exist at scan() time (element not yet upgraded), so a lazy lookup
481
+ // here catches them. Resolution is cached back into p.name on first
482
+ // hit — subsequent updates skip the walk.
483
+ if (!p._resolved) {
484
+ const resolved = resolvePropName(p.n, p.name);
485
+ if (resolved !== p.name) p.name = resolved;
486
+ p._resolved = true;
487
+ }
259
488
  p.n[p.name] = v;
260
489
  } else if (p.t === 'e') {
261
490
  if (isHandler(p.c)) p.n.removeEventListener(p.name, p.c);
@@ -279,3 +279,297 @@ describe('html template — FB-47 (v0.5.19) stamp() cache + repeat() keyed reuse
279
279
  expect(secondDiv.textContent).toBe('second');
280
280
  });
281
281
  });
282
+
283
+ describe('html template — FB-55 (v0.6.8) `.camelCase=${expr}` property-binding lowercase trap close', () => {
284
+ // FEEDBACK-55: the HTML parser lowercases attribute names inside
285
+ // <template>.innerHTML per HTML5 §13.2.5.32. Pre-fix, `.className=` arrived
286
+ // at scan() as `.classname`, then `name.slice(1)` yielded `"classname"`,
287
+ // and `applyValue()` wrote `p.n["classname"] = v` — an enumerable expando,
288
+ // never invoking the camelCase property setter. Classes never applied; no
289
+ // warn, no error.
290
+ //
291
+ // Fix: PROP_CASE_FIX static map (for built-in DOM camelCase props) +
292
+ // prototype-walk fallback (for UIElement-defined custom-element props).
293
+ // Backward-compatible: when no case-insensitive match exists, the
294
+ // original lowercase name is preserved (genuine expando consumers
295
+ // unaffected).
296
+ //
297
+ // RESPONSE-55 documents the trap end-to-end + reviewer-#A scope
298
+ // expansion to UIElement primitives.
299
+
300
+ let container;
301
+ let warnSpy;
302
+
303
+ beforeEach(() => {
304
+ container = document.createElement('div');
305
+ document.body.appendChild(container);
306
+ warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
307
+ });
308
+
309
+ afterEach(() => {
310
+ container.remove();
311
+ warnSpy.mockRestore();
312
+ });
313
+
314
+ it('.className=${expr} writes to the real className property (not lowercase expando)', () => {
315
+ const tpl = html`<span .className=${'foo bar'}>x</span>`;
316
+ stamp(tpl, container);
317
+ const span = container.querySelector('span');
318
+ expect(span.className).toBe('foo bar'); // ✅ real className set
319
+ expect(span.getAttribute('class')).toBe('foo bar'); // ✅ reflected to DOM attr
320
+ expect(span.classname).toBeUndefined(); // ✅ NO lowercase expando
321
+ });
322
+
323
+ it('.tabIndex=${n} writes to the real tabIndex property', () => {
324
+ const tpl = html`<div .tabIndex=${3}></div>`;
325
+ stamp(tpl, container);
326
+ const div = container.querySelector('div');
327
+ expect(div.tabIndex).toBe(3);
328
+ expect(div.getAttribute('tabindex')).toBe('3');
329
+ });
330
+
331
+ it('.innerHTML=${str} survives unchanged (already-lowercase name)', () => {
332
+ // .innerHTML is one of the few camelCase-looking names whose
333
+ // canonical form is already lowercase (well, it's `innerHTML` but
334
+ // the parser lowercases it to `innerhtml` AND PROP_CASE_FIX maps
335
+ // back to `innerHTML`). Verify it lands on the property regardless.
336
+ const tpl = html`<div .innerHTML=${'<span class="inner">payload</span>'}></div>`;
337
+ stamp(tpl, container);
338
+ const div = container.querySelector('div');
339
+ expect(div.querySelector('.inner')?.textContent).toBe('payload');
340
+ });
341
+
342
+ it('.lowercaseProp=${v} on a stock element preserves expando semantics (backward compat)', () => {
343
+ // The fallback prototype walk skips Object.prototype to avoid noisy
344
+ // matches. A genuinely-lowercase property name with no matching
345
+ // camelCase pair on the chain (e.g. `.myexpando`) lands on the
346
+ // element as a lowercase expando — the documented escape hatch
347
+ // for arbitrary data attachment. Verify no regression.
348
+ const tpl = html`<div .myexpando=${'attached'}></div>`;
349
+ stamp(tpl, container);
350
+ const div = container.querySelector('div');
351
+ expect(div.myexpando).toBe('attached');
352
+ });
353
+
354
+ it('.camelCaseProp=${v} on a UIElement-style custom element invokes the canonical setter', async () => {
355
+ // Reviewer-addition #A from RESPONSE-55: UIElement defines
356
+ // properties under camelCase keys via Object.defineProperty. The
357
+ // pre-fix trap wrote `el['camelprop'] = v` (expando) instead of
358
+ // invoking the setter. Verify the fix routes correctly through
359
+ // the prototype-walk fallback.
360
+ class FB55El extends HTMLElement {
361
+ constructor() {
362
+ super();
363
+ let _camelProp = '';
364
+ Object.defineProperty(this, 'camelProp', {
365
+ get() { return _camelProp; },
366
+ set(v) { _camelProp = v; this.dataset.lastSet = v; },
367
+ configurable: true,
368
+ enumerable: true,
369
+ });
370
+ }
371
+ }
372
+ if (!customElements.get('fb55-el')) customElements.define('fb55-el', FB55El);
373
+
374
+ const tpl = html`<fb55-el .camelProp=${'via-setter'}></fb55-el>`;
375
+ stamp(tpl, container);
376
+ const el = container.querySelector('fb55-el');
377
+ expect(el.camelProp).toBe('via-setter'); // ✅ getter returns set value
378
+ expect(el.dataset.lastSet).toBe('via-setter'); // ✅ setter side-effect ran
379
+ expect(el.camelprop).toBeUndefined(); // ✅ NO lowercase expando
380
+ });
381
+
382
+ it('.maxChroma=${n} on a UIElement-style ce reaches the camelCase property', () => {
383
+ // Real-world surface: <color-picker max-chroma> and <color-input
384
+ // max-chroma> declare `maxChroma` as a static property. Consumers
385
+ // reaching for `.maxChroma=${value}` template binding must invoke
386
+ // the setter, not write an expando.
387
+ class FB55Numeric extends HTMLElement {
388
+ constructor() {
389
+ super();
390
+ let _maxChroma = 0;
391
+ Object.defineProperty(this, 'maxChroma', {
392
+ get() { return _maxChroma; },
393
+ set(v) { _maxChroma = v; },
394
+ configurable: true, enumerable: true,
395
+ });
396
+ }
397
+ }
398
+ if (!customElements.get('fb55-num')) customElements.define('fb55-num', FB55Numeric);
399
+
400
+ const tpl = html`<fb55-num .maxChroma=${0.42}></fb55-num>`;
401
+ stamp(tpl, container);
402
+ const el = container.querySelector('fb55-num');
403
+ expect(el.maxChroma).toBe(0.42);
404
+ });
405
+
406
+ it('updates to .className=${expr} re-route through the setter on every value change', () => {
407
+ // The PROP_CASE_FIX resolution is cached in parts[i].name at scan()
408
+ // time. Subsequent update() ticks must continue to use the resolved
409
+ // camelCase name. Verify by re-stamping with a new value.
410
+ const make = (cls) => html`<span .className=${cls}>x</span>`;
411
+ stamp(make('a'), container);
412
+ let span = container.querySelector('span');
413
+ expect(span.className).toBe('a');
414
+
415
+ stamp(make('b'), container);
416
+ span = container.querySelector('span');
417
+ expect(span.className).toBe('b'); // ✅ second update routes correctly
418
+ expect(span.getAttribute('class')).toBe('b');
419
+ });
420
+
421
+ it('warning text no longer recommends .className= as the FIRST option for class= partial interp', () => {
422
+ // FB-55 #2: pre-fix, the v0.5.5 §184 warn text put `.className=`
423
+ // first; post-fix, `class="${expr}"` (the discoverable form) leads.
424
+ // Both work now (FB-55 #1), but the recommended ordering matters
425
+ // for new consumers reading the warning cold.
426
+ const cls = 'foo';
427
+ const tpl = html`<span class="prefix ${cls}">x</span>`;
428
+ stamp(tpl, container);
429
+ expect(warnSpy).toHaveBeenCalled();
430
+ const msg = warnSpy.mock.calls[0][0];
431
+ const classFullPos = msg.indexOf('class="${expression}"');
432
+ const classNamePos = msg.indexOf('.className=${expression}');
433
+ expect(classFullPos).toBeGreaterThan(-1);
434
+ expect(classNamePos).toBeGreaterThan(-1);
435
+ expect(classFullPos).toBeLessThan(classNamePos); // ✅ class="" first, .className= second
436
+ });
437
+
438
+ it('warning text dropped the .classList= aspirational line (FB-55 #2)', () => {
439
+ // Pre-fix the warn text mentioned `.classList=${{foo: true, bar: false}}`
440
+ // as "if/when implemented". classList is a read-only DOMTokenList
441
+ // accessor — no PROP_CASE_FIX could make it assignable, so the line
442
+ // was misleading. Post-fix it's removed.
443
+ const cls = 'foo';
444
+ const tpl = html`<span class="prefix ${cls}">x</span>`;
445
+ stamp(tpl, container);
446
+ const msg = warnSpy.mock.calls[0][0];
447
+ expect(msg).not.toMatch(/\.classList=/);
448
+ });
449
+
450
+ it('does not regress: canonical .style=${cssText}, .title=${str}, .value=${v} still work', () => {
451
+ // These property names are already lowercase, so they survived
452
+ // the parser pre-fix. Verify PROP_CASE_FIX didn't break them.
453
+ const tpl = html`<input .title=${'tip'} .value=${'val'}>`;
454
+ stamp(tpl, container);
455
+ const input = container.querySelector('input');
456
+ expect(input.title).toBe('tip');
457
+ expect(input.value).toBe('val');
458
+ });
459
+ });
460
+
461
+ describe('html template — FB-57 (v0.6.8) nested SVG/MathML template namespace re-routing', () => {
462
+ // FEEDBACK-57: nested `${html`<svg-child/>`}` interpolations produce
463
+ // HTML-namespaced elements (HTMLUnknownElement) instead of SVGElement.
464
+ // Root cause: each nested html`` is a SEPARATE cached template, and
465
+ // `tpl.innerHTML = m` is parsed at document level without SVG context.
466
+ // The <span style="display:contents"> wrapper from wrap() doesn't fix
467
+ // it because display:contents is layout-level not namespace-level;
468
+ // SVG layout is namespace-strict → invisible-but-present output.
469
+ //
470
+ // Fix: namespace-aware mount() — when the container is inside an SVG
471
+ // (or MathML) subtree, recursively re-namespace the cloned fragment
472
+ // via createElementNS. <foreignObject> and <annotation-xml
473
+ // encoding=text/html> revert to HTML per HTML5 §12.2.5 foreign-content
474
+ // insertion mode.
475
+ //
476
+ // RESPONSE-57 documents the trap end-to-end + the implementation-site
477
+ // choice (mount() not getTemplate(), to keep cache coherent).
478
+
479
+ const SVG_NS = 'http://www.w3.org/2000/svg';
480
+ const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';
481
+
482
+ let container;
483
+
484
+ beforeEach(() => {
485
+ container = document.createElement('div');
486
+ document.body.appendChild(container);
487
+ });
488
+
489
+ afterEach(() => {
490
+ container.remove();
491
+ });
492
+
493
+ it('inline <svg><circle/></svg> in a single template keeps working (regression)', () => {
494
+ // Pre-fix this case already worked because the HTML parser sees
495
+ // <svg> in tpl.innerHTML and enters SVG insertion mode for its
496
+ // descendants. Post-fix it must still work — the container is
497
+ // HTML-namespaced (<div>), so foreignContentNS() returns null,
498
+ // re-namespacing is skipped, and the inline parser's NS survives.
499
+ const tpl = html`<svg viewBox="0 0 10 10"><circle cx="5" cy="5" r="3"/></svg>`;
500
+ stamp(tpl, container);
501
+ const svg = container.querySelector('svg');
502
+ const circle = container.querySelector('circle');
503
+ expect(svg.namespaceURI).toBe(SVG_NS);
504
+ expect(circle.namespaceURI).toBe(SVG_NS);
505
+ });
506
+
507
+ it('nested ${html`<circle/>`} inside an SVG container now lands in SVG namespace', () => {
508
+ // The canonical fix surface. Pre-fix, the inner template's <circle>
509
+ // arrived as HTMLUnknownElement (NS xhtml). Post-fix, the wrap()
510
+ // span is HTML-namespaced (correct — it has display:contents) but
511
+ // its children get re-namespaced via the wrap-span's closest('svg')
512
+ // matching the outer SVG.
513
+ const svgRoot = document.createElementNS(SVG_NS, 'svg');
514
+ container.appendChild(svgRoot);
515
+ const dots = [{ x: 1 }, { x: 2 }, { x: 3 }];
516
+ const tpl = html`${dots.map(d => html`<circle cx=${d.x} cy="5" r="2"/>`)}`;
517
+ stamp(tpl, svgRoot);
518
+ const circles = svgRoot.querySelectorAll('circle');
519
+ expect(circles.length).toBe(3);
520
+ for (const c of circles) {
521
+ expect(c.namespaceURI).toBe(SVG_NS); // ✅ SVG-NS
522
+ }
523
+ });
524
+
525
+ it('a directly-stamped html`<circle/>` template into an SVG container is SVG-namespaced', () => {
526
+ // Even without array interpolation, stamping a single SVG-content
527
+ // template into an SVG container must re-namespace.
528
+ const svgRoot = document.createElementNS(SVG_NS, 'svg');
529
+ container.appendChild(svgRoot);
530
+ const tpl = html`<circle cx="5" cy="5" r="3"/>`;
531
+ stamp(tpl, svgRoot);
532
+ const circle = svgRoot.querySelector('circle');
533
+ expect(circle.namespaceURI).toBe(SVG_NS);
534
+ });
535
+
536
+ it('<foreignObject> children REVERT to HTML namespace (per HTML5 spec)', () => {
537
+ // <foreignObject> is the spec-defined HTML escape hatch inside SVG.
538
+ // Re-namespacing must stop at the foreignObject boundary; its
539
+ // children stay HTML-namespaced.
540
+ const svgRoot = document.createElementNS(SVG_NS, 'svg');
541
+ container.appendChild(svgRoot);
542
+ const tpl = html`<foreignObject><div class="html-inside-svg">html content</div></foreignObject>`;
543
+ stamp(tpl, svgRoot);
544
+ const fo = svgRoot.querySelector('foreignObject');
545
+ const innerDiv = svgRoot.querySelector('.html-inside-svg');
546
+ expect(fo.namespaceURI).toBe(SVG_NS); // ✅ foreignObject itself is SVG
547
+ expect(innerDiv.namespaceURI).toBe('http://www.w3.org/1999/xhtml'); // ✅ children HTML
548
+ });
549
+
550
+ it('MathML <math><mi/></math> inline template stays in MathML namespace via the HTML parser', () => {
551
+ // Like inline-SVG: the HTML parser enters MathML insertion mode for
552
+ // <math>, so inline children arrive correctly namespaced even
553
+ // pre-fix. Post-fix this remains true (no re-namespacing because
554
+ // the container is HTML).
555
+ const tpl = html`<math><mi>x</mi></math>`;
556
+ stamp(tpl, container);
557
+ const math = container.querySelector('math');
558
+ const mi = container.querySelector('mi');
559
+ // happy-dom may or may not surface MathML namespace; smoke that the
560
+ // elements at least exist and the math element is acknowledged.
561
+ expect(math).not.toBeNull();
562
+ expect(mi).not.toBeNull();
563
+ expect(math.localName).toBe('math');
564
+ });
565
+
566
+ it('does not re-namespace when stamping into an HTML container (no overhead in the common case)', () => {
567
+ // Probe the discriminator: a plain <div> container should skip the
568
+ // re-namespacing path entirely. Verify by stamping a template
569
+ // whose children are HTML elements and confirming they stay HTML.
570
+ const tpl = html`<p class="probe">html paragraph</p>`;
571
+ stamp(tpl, container);
572
+ const p = container.querySelector('p.probe');
573
+ expect(p.namespaceURI).toBe('http://www.w3.org/1999/xhtml');
574
+ });
575
+ });