contour-ds 1.7.2 → 1.8.1

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 (109) hide show
  1. package/README.md +80 -11
  2. package/dist/agent-rules.json +16 -0
  3. package/dist/build-manifest.json +181 -104
  4. package/dist/contour-wc-content.esm.js +5125 -0
  5. package/dist/contour-wc-content.esm.min.js +1 -0
  6. package/dist/contour-wc-dashboard.esm.js +8654 -0
  7. package/dist/contour-wc-dashboard.esm.min.js +1 -0
  8. package/dist/contour-wc-data.esm.js +8260 -0
  9. package/dist/contour-wc-data.esm.min.js +1 -0
  10. package/dist/contour-wc-docs.esm.js +4305 -0
  11. package/dist/contour-wc-docs.esm.min.js +1 -0
  12. package/dist/contour-wc-feedback.esm.js +4917 -0
  13. package/dist/contour-wc-feedback.esm.min.js +1 -0
  14. package/dist/contour-wc-forms.esm.js +5688 -0
  15. package/dist/contour-wc-forms.esm.min.js +1 -0
  16. package/dist/contour-wc-interaction.esm.js +4580 -0
  17. package/dist/contour-wc-interaction.esm.min.js +1 -0
  18. package/dist/contour-wc-layout.esm.js +4174 -0
  19. package/dist/contour-wc-layout.esm.min.js +1 -0
  20. package/dist/contour-wc-map.esm.js +5205 -0
  21. package/dist/contour-wc-map.esm.min.js +1 -0
  22. package/dist/contour-wc-misc.esm.js +4264 -0
  23. package/dist/contour-wc-misc.esm.min.js +1 -0
  24. package/dist/contour-wc-navigation.esm.js +5844 -0
  25. package/dist/contour-wc-navigation.esm.min.js +1 -0
  26. package/dist/contour-wc-ui.esm.js +9009 -0
  27. package/dist/contour-wc-ui.esm.min.js +1 -0
  28. package/dist/contour-wc.esm.js +6109 -1641
  29. package/dist/contour-wc.esm.min.js +1 -1
  30. package/dist/contour-wc.js +6108 -1641
  31. package/dist/contour-wc.min.js +1 -1
  32. package/dist/contour.code-snippets +4512 -0
  33. package/dist/contour.components.json +2597 -799
  34. package/dist/contour.css +5275 -4050
  35. package/dist/contour.d.ts +560 -1085
  36. package/dist/contour.esm.js +7 -0
  37. package/dist/contour.esm.min.js +1 -1
  38. package/dist/contour.html-data.json +10311 -0
  39. package/dist/contour.js +7 -0
  40. package/dist/contour.min.css +1 -1
  41. package/dist/contour.min.js +1 -1
  42. package/dist/contour.react.d.ts +420 -0
  43. package/dist/contour.single.html +17 -0
  44. package/dist/contour.single.min.css +1 -0
  45. package/dist/contour.tokens.json +940 -902
  46. package/dist/contour.vue.d.ts +418 -0
  47. package/dist/contour.web-types.json +10703 -0
  48. package/dist/custom-elements.json +30708 -0
  49. package/dist/docs/actions.md +3 -2
  50. package/dist/docs/affordances.md +23 -9
  51. package/dist/docs/apireference.md +1 -1
  52. package/dist/docs/colour.md +1 -1
  53. package/dist/docs/componentindex.md +6 -2
  54. package/dist/docs/data.md +7 -2
  55. package/dist/docs/docs.md +9 -2
  56. package/dist/docs/feedback.md +1 -1
  57. package/dist/docs/field.md +1 -1
  58. package/dist/docs/forms.md +1 -1
  59. package/dist/docs/index.json +22 -20
  60. package/dist/docs/install.md +1 -1
  61. package/dist/docs/landing.md +1 -1
  62. package/dist/docs/mapengine.md +19 -2
  63. package/dist/docs/motion.md +1 -1
  64. package/dist/docs/navigation.md +1 -1
  65. package/dist/docs/overlays.md +1 -1
  66. package/dist/docs/overview.md +1 -1
  67. package/dist/docs/patterns.md +2 -2
  68. package/dist/docs/playground.md +22 -2
  69. package/dist/docs/principles.md +1 -1
  70. package/dist/docs/recipes.md +13 -8
  71. package/dist/docs/space.md +1 -1
  72. package/dist/docs/status.md +14 -2
  73. package/dist/docs/surfaces.md +1 -1
  74. package/dist/docs/theming.md +1 -1
  75. package/dist/docs/type.md +1 -1
  76. package/dist/docs/webcomponents.md +17 -3
  77. package/dist/registry/items/contour-core.json +2 -2
  78. package/dist/registry/items/contour-data.json +2 -2
  79. package/dist/registry/items/contour-docs.json +2 -2
  80. package/dist/registry/items/contour-landing.json +2 -2
  81. package/dist/registry/registry.json +8 -8
  82. package/dist/surfaces/contour-core.min.css +1 -1
  83. package/dist/surfaces/contour-data.min.css +1 -1
  84. package/dist/surfaces/contour-docs.min.css +1 -1
  85. package/dist/surfaces/contour-landing.min.css +1 -1
  86. package/dist/wc/behaviours.mjs +45 -57
  87. package/dist/wc/content.mjs +263 -63
  88. package/dist/wc/core.mjs +390 -71
  89. package/dist/wc/dashboard.mjs +220 -13
  90. package/dist/wc/data.mjs +1075 -460
  91. package/dist/wc/docs.mjs +105 -12
  92. package/dist/wc/feedback.mjs +63 -14
  93. package/dist/wc/forms.mjs +733 -104
  94. package/dist/wc/index.mjs +9 -2
  95. package/dist/wc/interaction.mjs +182 -28
  96. package/dist/wc/layout.mjs +95 -25
  97. package/dist/wc/map.mjs +185 -118
  98. package/dist/wc/misc.mjs +124 -24
  99. package/dist/wc/navigation.mjs +384 -115
  100. package/dist/wc/shadow.mjs +94 -18
  101. package/dist/wc/states.mjs +21 -3
  102. package/dist/wc/svg.mjs +104 -0
  103. package/dist/wc/ui.mjs +1988 -476
  104. package/integrations/README.md +2 -0
  105. package/integrations/ai/CLAUDE.md +3 -3
  106. package/integrations/frameworks/README.md +235 -0
  107. package/integrations/native/style-dictionary.config.json +1 -1
  108. package/integrations/tailwind/contour-theme.css +5 -6
  109. package/package.json +53 -24
package/dist/wc/forms.mjs CHANGED
@@ -11,7 +11,7 @@
11
11
  * @module contour-wc/forms
12
12
  */
13
13
 
14
- import { ContourBase, define, contourId } from './core.mjs';
14
+ import { ContourBase, define, contourId, cssLength , warnBadJson, labelText, applyLabel } from './core.mjs';
15
15
  import { wireCombobox } from './behaviours.mjs';
16
16
  import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
17
17
  /**
@@ -23,11 +23,14 @@ import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from '.
23
23
  * filter. ArrowUp/Down/Home/End rove the cursor; Enter commits; Escape closes.
24
24
  */
25
25
  class ContourCombobox extends ContourBase {
26
- static get observed() { return ["options", "placeholder", "label", "value", "multiple", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "empty", "skeleton", "virtual"]; }
26
+ static get observed() { return ["options", "placeholder", "label", "value", "multiple", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "empty", "skeleton", "virtual", "disabled", "required", "name"]; }
27
27
  static get formAssociated() { return true; }
28
- static get properties() { return { options: { attribute: "options" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, value: { attribute: "value" }, multiple: { attribute: "multiple", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, src: { attribute: "src" } }; }
28
+ static get properties() { return { options: { attribute: "options" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, value: { attribute: "value" }, multiple: { attribute: "multiple", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, src: { attribute: "src" }, disabled: { attribute: "disabled", type: Boolean }, required: { attribute: "required", type: Boolean }, name: { attribute: "name" } }; }
29
29
  render() {
30
30
  this.classList.add("c-combobox");
31
+ // The authored default, captured before any commit reflects into the
32
+ // attribute: form reset restores THIS, not the last committed value.
33
+ if (this._comboboxDefault === undefined) this._comboboxDefault = this.getAttribute("value");
31
34
  wireStates(this);
32
35
  loadRemote(this, "options");
33
36
  if (renderStates(this, "combobox")) return;
@@ -37,16 +40,28 @@ class ContourCombobox extends ContourBase {
37
40
  if ((options) && !authored.length) {
38
41
  try {
39
42
  const parsed = options ? JSON.parse(options) : [];
43
+ this._comboboxOptions = parsed;
40
44
  const input = this.ensure(".c-combobox__input", () => { const el = document.createElement("input"); el.className = "c-combobox__input"; el.type = "text"; return el; });
41
45
  input.type = "text";
42
46
  input.placeholder = this.getAttribute("placeholder") || "Search…";
43
47
  input.setAttribute("aria-label", this.getAttribute("label") || "Search");
48
+ // Reflect the native constraint state so the platform validates the
49
+ // field and FormData sees the name.
50
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
51
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
52
+ if (this.hasAttribute("required")) { input.setAttribute("required", ""); input.setAttribute("aria-required", "true"); }
53
+ else { input.removeAttribute("required"); input.removeAttribute("aria-required"); }
54
+ if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
44
55
  const val = this.getAttribute("value");
45
- if (val !== null) input.value = val;
56
+ if (val !== null) {
57
+ // The attribute holds the submitted value; the field shows the
58
+ // matching option's label so the two can differ (value "us" -> "United States").
59
+ const match = parsed.find((o) => String(typeof o === "string" ? o : o.value) === String(val));
60
+ input.value = match ? String(typeof match === "string" ? match : match.label) : val;
61
+ }
46
62
  const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
47
63
  list.innerHTML = "";
48
64
  list.setAttribute("hidden", "");
49
- this._comboboxOptions = parsed;
50
65
  this._comboboxVirtual = this.hasAttribute("virtual") && parsed.length > 100;
51
66
  if (this._comboboxVirtual) {
52
67
  list.classList.add("c-combobox__list--virtual");
@@ -59,7 +74,7 @@ class ContourCombobox extends ContourBase {
59
74
  list.style.overflow = "";
60
75
  this._renderComboboxWindow("", true);
61
76
  }
62
- } catch (e) { /* keep existing */ }
77
+ } catch (e) { warnBadJson(this, "attribute", e); }
63
78
  } else if (!authored.length && !options) {
64
79
  renderEmpty(this, "combobox");
65
80
  }
@@ -90,7 +105,7 @@ class ContourCombobox extends ContourBase {
90
105
  value: typeof opt === "string" ? opt : opt.value,
91
106
  })).filter((item) => !q || String(item.label).toLowerCase().includes(q));
92
107
  this._comboboxFiltered = filtered;
93
- const rowHeight = 32;
108
+ const rowHeight = cssLength("--combobox-row-height", 32);
94
109
  const windowSize = 20;
95
110
  const overscan = 6;
96
111
  const oldScrollTop = list.scrollTop;
@@ -121,6 +136,7 @@ class ContourCombobox extends ContourBase {
121
136
  const li = document.createElement("li");
122
137
  li.className = "c-combobox__option";
123
138
  li.dataset.optionIndex = String(item.index);
139
+ li.dataset.optionValue = String(item.value != null ? item.value : item.label);
124
140
  li.setAttribute("role", "option");
125
141
  const label = String(item.label);
126
142
  const q = String(query || "").toLowerCase();
@@ -147,6 +163,15 @@ class ContourCombobox extends ContourBase {
147
163
  if (this._comboboxVirtual) addSpacer(Math.max(0, filtered.length - end) * rowHeight);
148
164
  if (this._comboboxVirtual && !reset) list.scrollTop = oldScrollTop;
149
165
  }
166
+ _syncFormValue() {
167
+ if (!this._internals) return;
168
+ // The committed value lives on the host attribute, not in the text field
169
+ // (which shows the option label), so the form submits the value.
170
+ const raw = this.getAttribute("value");
171
+ const value = raw != null && raw !== "" ? raw : null;
172
+ this._internals.setFormValue(value);
173
+ this._syncValidity(this.hasAttribute("required") && !value);
174
+ }
150
175
  enhance() {
151
176
  wireCombobox(this);
152
177
  // Form sync (D-02): commit writes the input value; mirror it into the
@@ -174,6 +199,20 @@ class ContourCombobox extends ContourBase {
174
199
  });
175
200
  }
176
201
  }
202
+ formResetCallback() {
203
+ // Restore the authored default and let render map it back to the
204
+ // option's LABEL — the generic base reset wrote the raw value into the
205
+ // text field, which shows labels, not values.
206
+ this._contourResetting = true;
207
+ try {
208
+ const def = this._comboboxDefault ?? null;
209
+ if (def === null) this.removeAttribute("value");
210
+ else this.setAttribute("value", def);
211
+ this._syncFormValue();
212
+ } finally {
213
+ this._contourResetting = false;
214
+ }
215
+ }
177
216
  }
178
217
  define("contour-combobox", ContourCombobox);
179
218
  /**
@@ -184,9 +223,9 @@ define("contour-combobox", ContourCombobox);
184
223
  * sync via `_internals.setFormValue`. Emits `contour:input` / `contour:change`.
185
224
  */
186
225
  class ContourField extends ContourBase {
187
- static get observed() { return ["label", "hint", "error", "placeholder", "type", "required"]; }
226
+ static get observed() { return ["label", "hint", "error", "placeholder", "type", "required", "name", "value", "disabled", "custom-error"]; }
188
227
  static get formAssociated() { return true; }
189
- static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, placeholder: { attribute: "placeholder" }, type: { attribute: "type" }, required: { attribute: "required", type: Boolean } }; }
228
+ static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, placeholder: { attribute: "placeholder" }, type: { attribute: "type" }, required: { attribute: "required", type: Boolean }, name: { attribute: "name" }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, customError: { attribute: "custom-error" } }; }
190
229
  render() {
191
230
  this.classList.add("c-field");
192
231
  const label = this.getAttribute("label");
@@ -207,10 +246,13 @@ class ContourField extends ContourBase {
207
246
  });
208
247
  input.type = this.getAttribute("type") || "text";
209
248
  input.placeholder = placeholder;
210
- if (!input.id) input.id = contourId("contour-field");
249
+ // Stable across renders: a fresh id per render breaks the base class's
250
+ // keyed value/focus matching for a field with no `name` (R20 T-02).
251
+ if (!input.id) input.id = this._fieldInputId || (this._fieldInputId = contourId("contour-field"));
211
252
  // Associate the label with the input so the control is labelled.
212
253
  const lbl = this.querySelector(".c-field__label");
213
254
  if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); input.setAttribute("aria-label", lbl.textContent); }
255
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Field");
214
256
  if (hint) {
215
257
  const h = this.ensure(".c-field__hint", () => { const el = document.createElement("span"); el.className = "c-field__hint"; return el; });
216
258
  h.textContent = hint;
@@ -225,6 +267,24 @@ class ContourField extends ContourBase {
225
267
  const e = this.querySelector(".c-field__error");
226
268
  if (e) e.remove();
227
269
  }
270
+ // R22 WC4-26: custom-error attribute — declarative setCustomValidity().
271
+ // When set, the input's validation message is overridden and the field
272
+ // is marked invalid, matching the platform's customError semantics.
273
+ const customError = this.getAttribute("custom-error");
274
+ if (customError !== null) {
275
+ input.setAttribute("aria-invalid", "true");
276
+ this.classList.add("is-invalid");
277
+ this.setAttribute("data-invalid", "");
278
+ let errEl = this.querySelector(".c-field__error");
279
+ if (!errEl) {
280
+ errEl = document.createElement("span");
281
+ errEl.className = "c-field__error";
282
+ this.appendChild(errEl);
283
+ }
284
+ errEl.textContent = customError;
285
+ if (!errEl.id) errEl.id = contourId("err");
286
+ input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
287
+ }
228
288
  // ARIA: link the input to its hint and its error message (parity with the
229
289
  // shadow layer's bootstrap). The ids are generated so a screen reader does
230
290
  // not hear one message without the other.
@@ -234,7 +294,15 @@ class ContourField extends ContourBase {
234
294
  if (hintEl) { if (!hintEl.id) hintEl.id = contourId("hint"); describedBy.push(hintEl.id); }
235
295
  if (errEl) { if (!errEl.id) errEl.id = contourId("err"); describedBy.push(errEl.id); }
236
296
  if (describedBy.length) input.setAttribute("aria-describedby", describedBy.join(" "));
237
- if (this.hasAttribute("required")) input.setAttribute("aria-required", "true");
297
+ // Reflect the native constraint state, not only ARIA: `checkValidity()`
298
+ // and the form's own validation must see `required`, and FormData must
299
+ // see `name`/`value`. ARIA alone never blocks submit.
300
+ if (this.hasAttribute("required")) { input.setAttribute("aria-required", "true"); input.setAttribute("required", ""); }
301
+ else { input.removeAttribute("aria-required"); input.removeAttribute("required"); }
302
+ if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
303
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
304
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
305
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
238
306
  }
239
307
  }
240
308
  ContourField.prototype.enhance = function() {
@@ -260,7 +328,9 @@ class ContourField extends ContourBase {
260
328
  // Inline validation (BY2-U6): on blur, reflect validity on the input via
261
329
  // aria-invalid and toggle the error/success state. The CSS already paints
262
330
  // the invalid ring (components.css aria-invalid rules); this just drives it.
263
- this.addEventListener("blur", (e) => {
331
+ // `focusout` bubbles; `blur` does not, so a listener on the host would
332
+ // never see the input lose focus.
333
+ this.addEventListener("focusout", (e) => {
264
334
  const input = this.querySelector("input, textarea, select");
265
335
  if (!input || e.target !== input) return;
266
336
  const valid = input.checkValidity();
@@ -268,22 +338,44 @@ class ContourField extends ContourBase {
268
338
  input.setAttribute("aria-invalid", "false");
269
339
  this.classList.remove("is-invalid");
270
340
  this.removeAttribute("data-invalid");
341
+ // Clear a transient validation error the blur handler surfaced, but
342
+ // never an error the author set explicitly.
343
+ if (!this.getAttribute("error")) {
344
+ const stale = this.querySelector(".c-field__error");
345
+ if (stale) {
346
+ const id = stale.id;
347
+ stale.remove();
348
+ if (id) input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== id).join(" "));
349
+ }
350
+ }
271
351
  } else {
272
352
  input.setAttribute("aria-invalid", "true");
273
353
  this.classList.add("is-invalid");
274
354
  this.setAttribute("data-invalid", "");
275
- // Surface the browser's validation message when no explicit error attr.
276
- if (!this.getAttribute("error")) {
277
- const msg = input.validationMessage || "Invalid value";
278
- let errEl = this.querySelector(".c-field__error");
279
- if (!errEl) {
280
- errEl = document.createElement("span");
281
- errEl.className = "c-field__error";
282
- this.appendChild(errEl);
355
+ // R22 WC4-26: emit a cancelable contour:invalid event. A listener
356
+ // can preventDefault() to suppress the invalid state (e.g. to show
357
+ // a custom message instead of the browser's).
358
+ const invalidEvent = new CustomEvent("contour:invalid", {
359
+ bubbles: true,
360
+ composed: true,
361
+ cancelable: true,
362
+ detail: { field: this, input, message: input.validationMessage || "Invalid value" },
363
+ });
364
+ const notCancelled = this.dispatchEvent(invalidEvent);
365
+ if (notCancelled) {
366
+ // Surface the browser's validation message when no explicit error attr.
367
+ if (!this.getAttribute("error") && !this.getAttribute("custom-error")) {
368
+ const msg = input.validationMessage || "Invalid value";
369
+ let errEl = this.querySelector(".c-field__error");
370
+ if (!errEl) {
371
+ errEl = document.createElement("span");
372
+ errEl.className = "c-field__error";
373
+ this.appendChild(errEl);
374
+ }
375
+ errEl.textContent = msg;
376
+ if (!errEl.id) errEl.id = contourId("err");
377
+ input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
283
378
  }
284
- errEl.textContent = msg;
285
- if (!errEl.id) errEl.id = contourId("err");
286
- input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
287
379
  }
288
380
  }
289
381
  sync();
@@ -345,11 +437,19 @@ class ContourFieldGroup extends ContourBase {
345
437
  * listing the invalid fields. Emits `contour:submit` on valid submit.
346
438
  */
347
439
  class ContourForm extends ContourBase {
348
- static get observed() { return ["submitting", "error", "summary"]; }
349
- static get properties() { return { submitting: { attribute: "submitting", type: Boolean }, error: { attribute: "error" }, summary: { attribute: "summary" } }; }
440
+ static get observed() { return ["submitting", "error", "summary", "title", "submit-label"]; }
441
+ static get properties() { return { submitting: { attribute: "submitting", type: Boolean }, error: { attribute: "error" }, summary: { attribute: "summary" }, title: { attribute: "title" }, submitLabel: { attribute: "submit-label" } }; }
350
442
  render() {
351
443
  this.classList.add("c-form");
352
444
  if (this.hasAttribute("submitting")) this.classList.add("is-submitting"); else this.classList.remove("is-submitting");
445
+ const title = this.getAttribute("title");
446
+ let titleEl = this.querySelector(".c-form__title");
447
+ if (title) {
448
+ if (!titleEl) { titleEl = document.createElement("h2"); titleEl.className = "c-form__title"; this.prepend(titleEl); }
449
+ titleEl.textContent = title;
450
+ } else if (titleEl) {
451
+ titleEl.remove();
452
+ }
353
453
  const summaryText = this.getAttribute("summary") || this.getAttribute("error");
354
454
  let summary = this.querySelector(".c-form__summary");
355
455
  if (summaryText) {
@@ -359,35 +459,66 @@ class ContourForm extends ContourBase {
359
459
  } else if (summary) {
360
460
  summary.setAttribute("hidden", "");
361
461
  }
362
- const submit = this.querySelector("[type='submit'], .c-form__submit");
363
- if (submit) {
364
- if (this.hasAttribute("submitting")) submit.setAttribute("disabled", "");
365
- else submit.removeAttribute("disabled");
462
+ // The component owns submission: it renders its own submit control when
463
+ // the author gives a `submit-label`, so an empty <contour-form> still
464
+ // shows a title and a button instead of rendering nothing.
465
+ const submitLabel = this.getAttribute("submit-label");
466
+ let submit = this.querySelector(".c-form__submit");
467
+ if (!submit) {
468
+ submit = document.createElement("button");
469
+ submit.type = "submit";
470
+ submit.className = "c-btn c-btn--primary c-form__submit";
471
+ this.appendChild(submit);
366
472
  }
473
+ // `submit-label` is the authored override; `labels.submit` is the localised
474
+ // default. `applyLabel` re-applies the default on every render — so a
475
+ // `labels` change reaches a button an earlier render created — while an
476
+ // author's own button text still wins.
477
+ if (submitLabel) {
478
+ submit.textContent = submitLabel;
479
+ if (submit.dataset) delete submit.dataset.contourLabel;
480
+ } else {
481
+ applyLabel(submit, this, "submit", "Submit");
482
+ }
483
+ if (this.hasAttribute("submitting")) submit.setAttribute("disabled", "");
484
+ else submit.removeAttribute("disabled");
367
485
  }
368
486
  enhance() {
369
487
  if (this._wiredForm) return;
370
488
  this._wiredForm = true;
489
+ // A click on the component's own submit control is the submission path
490
+ // when there is no nested real <form>; prevent the default (there is no
491
+ // form to submit) and run the same validate-then-emit flow.
492
+ this.addEventListener("click", (e) => {
493
+ const btn = e.target && e.target.closest ? e.target.closest(".c-form__submit") : null;
494
+ if (!btn || !this.contains(btn)) return;
495
+ if (e.target.closest("form")) return; // a nested real form handles it
496
+ e.preventDefault();
497
+ this._submit();
498
+ });
371
499
  this.addEventListener("submit", (e) => {
372
500
  const form = e.target;
501
+ // The component claims ownership of submission: never let a nested
502
+ // real <form> navigate away.
503
+ e.preventDefault();
373
504
  if (form && typeof form.checkValidity === "function" && !form.checkValidity()) {
374
- e.preventDefault();
375
505
  const invalid = Array.from(form.querySelectorAll(":invalid"));
376
506
  const names = invalid.map((el) => el.getAttribute("aria-label") || el.name || el.id || "field").join(", ");
377
- // Update DOM directly (avoid setAttribute on observed attr -> re-entrancy).
378
507
  let summary = this.querySelector(".c-form__summary");
379
508
  if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
380
- summary.textContent = "Please fix: " + (names || "invalid fields");
509
+ summary.textContent = labelText(this, "validation-summary", "Please fix") + ": " + (names || labelText(this, "invalid-fields", "invalid fields"));
381
510
  summary.removeAttribute("hidden");
382
511
  return;
383
512
  }
384
- // submitting state via class + button, not attribute.
385
- this.classList.add("is-submitting");
386
- const submit = this.querySelector("[type='submit'], .c-form__submit");
387
- if (submit) submit.setAttribute("disabled", "");
388
- this.dispatchEvent(new CustomEvent("contour:submit", { bubbles: true, composed: true, detail: { submitting: true } }));
513
+ this._submit();
389
514
  });
390
515
  }
516
+ _submit() {
517
+ this.classList.add("is-submitting");
518
+ const submit = this.querySelector("[type='submit'], .c-form__submit");
519
+ if (submit) submit.setAttribute("disabled", "");
520
+ this.dispatchEvent(new CustomEvent("contour:submit", { bubbles: true, composed: true, detail: { submitting: true } }));
521
+ }
391
522
  }
392
523
  define("contour-form", ContourForm);
393
524
 
@@ -399,9 +530,9 @@ class ContourForm extends ContourBase {
399
530
  * filled track.
400
531
  */
401
532
  class ContourRange extends ContourBase {
402
- static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help"]; }
533
+ static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help", "name", "step"]; }
403
534
  static get formAssociated() { return true; }
404
- static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
535
+ static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, name: { attribute: "name" }, step: { attribute: "step" } }; }
405
536
  render() {
406
537
  this.classList.add("c-range");
407
538
  const min = this.getAttribute("min") || "0";
@@ -421,11 +552,14 @@ class ContourRange extends ContourBase {
421
552
  const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
422
553
  // keep generic input? We'll use two named inputs
423
554
  let lowInput = this.querySelector("input.c-range__low");
424
- if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; this.appendChild(lowInput); }
555
+ if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; lowInput.setAttribute("part", "input"); this.appendChild(lowInput); }
425
556
  let highInput = this.querySelector("input.c-range__high");
426
- if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; this.appendChild(highInput); }
557
+ if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; highInput.setAttribute("part", "input"); this.appendChild(highInput); }
427
558
  lowInput.min = min; lowInput.max = max;
428
559
  highInput.min = min; highInput.max = max;
560
+ const step = this.getAttribute("step");
561
+ if (step) { lowInput.step = step; highInput.step = step; } else { lowInput.removeAttribute("step"); highInput.removeAttribute("step"); }
562
+ if (this.hasAttribute("disabled")) { lowInput.setAttribute("disabled", ""); highInput.setAttribute("disabled", ""); } else { lowInput.removeAttribute("disabled"); highInput.removeAttribute("disabled"); }
429
563
  const lowVal = this.getAttribute("low") || min;
430
564
  const highVal = this.getAttribute("high") || max;
431
565
  if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
@@ -434,15 +568,25 @@ class ContourRange extends ContourBase {
434
568
  else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
435
569
  const label = this.getAttribute("label");
436
570
  if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
571
+ // A dual range submits two entries under the host's name through
572
+ // the ElementInternals FormData form value (_syncFormValue below).
573
+ // The old hidden native mirrors submitted NOTHING: the base class's
574
+ // form="" detachment cannot tell a mirror from a double submission,
575
+ // so it detached them too — measured as zero entries by the R20
576
+ // form-participation arm. Remove any a previous render left behind.
577
+ Array.from(this.querySelectorAll('input[type="hidden"][data-range]')).forEach((n) => n.remove());
437
578
  } else {
438
- // remove dual inputs
439
- Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high")).forEach((n) => n.remove());
440
- const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; return el; });
579
+ // remove dual inputs and any leftover mirrors from a dual render
580
+ Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high, input[type='hidden'][data-range]")).forEach((n) => n.remove());
581
+ const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; el.setAttribute("part", "input"); return el; });
441
582
  // ensure class
442
583
  input.className = "c-range";
443
584
  input.type = "range";
444
585
  input.min = min;
445
586
  input.max = max;
587
+ const step = this.getAttribute("step");
588
+ if (step) input.step = step; else input.removeAttribute("step");
589
+ if (this.hasAttribute("disabled")) input.setAttribute("disabled", ""); else input.removeAttribute("disabled");
446
590
  const attrVal = this.getAttribute("value") || "50";
447
591
  if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
448
592
  input.value = this._rangeUserValue;
@@ -477,18 +621,61 @@ class ContourRange extends ContourBase {
477
621
  if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
478
622
  return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
479
623
  };
624
+ // Form value (R20 T-08): single submits the handle's value; dual submits
625
+ // TWO entries under the one host name via the FormData form value. The
626
+ // base generic would submit only the first handle, and the formdata
627
+ // re-sync calls THIS, so the override is what keeps the entry list right.
628
+ ContourRange.prototype._syncFormValue = function() {
629
+ if (!this._internals) return;
630
+ const low = this.querySelector("input.c-range__low");
631
+ const high = this.querySelector("input.c-range__high");
632
+ if (low && high) {
633
+ const name = this.getAttribute("name");
634
+ if (name) {
635
+ const fd = new FormData();
636
+ fd.append(name, low.value);
637
+ fd.append(name, high.value);
638
+ this._internals.setFormValue(fd);
639
+ } else {
640
+ this._internals.setFormValue(null);
641
+ }
642
+ } else {
643
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
644
+ if (single) this._internals.setFormValue(single.value);
645
+ }
646
+ };
647
+ ContourRange.prototype.formResetCallback = function() {
648
+ // The authored defaults are the value/low/high attributes; clear the
649
+ // user-drag tracking so the re-render reads them, under the resetting
650
+ // flag so the base restore cannot resurrect the dragged handles.
651
+ this._contourResetting = true;
652
+ try {
653
+ this._rangeUserValue = null; this._rangeAttrAtDirty = null;
654
+ this._rangeUserLow = null; this._rangeAttrLowAtDirty = null;
655
+ this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null;
656
+ if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
657
+ this._syncFormValue();
658
+ } finally {
659
+ this._contourResetting = false;
660
+ }
661
+ };
662
+ ContourRange.prototype.formStateRestoreCallback = function(state) {
663
+ if (!this._internals || state === null || state === undefined) return;
664
+ const low = this.querySelector("input.c-range__low");
665
+ const high = this.querySelector("input.c-range__high");
666
+ if (low && high && state instanceof FormData) {
667
+ const vals = state.getAll(this.getAttribute("name"));
668
+ if (vals.length >= 2) { low.value = String(vals[0]); high.value = String(vals[1]); }
669
+ } else {
670
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
671
+ if (single) single.value = String(state);
672
+ }
673
+ this._syncFormValue();
674
+ };
480
675
  ContourRange.prototype.enhance = function() {
481
676
  if (this._wiredRange) return;
482
677
  this._wiredRange = true;
483
- const sync = () => {
484
- const low = this.querySelector("input.c-range__low");
485
- const high = this.querySelector("input.c-range__high");
486
- const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
487
- if (this._internals) {
488
- if (low && high) this._internals.setFormValue(low.value + "," + high.value);
489
- else if (single) this._internals.setFormValue(single.value);
490
- }
491
- };
678
+ const sync = () => { this._syncFormValue(); };
492
679
  this.addEventListener("input", (e) => {
493
680
  const low = this.querySelector("input.c-range__low");
494
681
  const high = this.querySelector("input.c-range__high");
@@ -527,8 +714,7 @@ class ContourRange extends ContourBase {
527
714
  /**
528
715
  * Switch: a `role="switch"` checkbox control with label, required, disabled,
529
716
  * error and help states. Form associated; emits `contour:change` on toggle.
530
- * Renders a `c-switch__track` element after the input for the sheet's track
531
- * styling.
717
+ * The input's ::after draws the track; there is no separate track element.
532
718
  */
533
719
  class ContourSwitch extends ContourBase {
534
720
  static get observed() { return ["label", "required", "checked", "disabled", "error", "help"]; }
@@ -536,6 +722,8 @@ class ContourSwitch extends ContourBase {
536
722
  static get formAssociated() { return true; }
537
723
  render() {
538
724
  this.classList.add("c-switch");
725
+ // Authored default captured before any toggle reflects into `checked`.
726
+ if (this._switchDefaultChecked === undefined) this._switchDefaultChecked = this.hasAttribute("checked");
539
727
  const label = this.getAttribute("label");
540
728
  // The guide's control is `label.c-switch` wrapping `input.c-switch__input`
541
729
  // and a bare span of text; the sheet paints the track on the input itself.
@@ -555,19 +743,14 @@ class ContourSwitch extends ContourBase {
555
743
  msg.classList.toggle("c-switch__message--error", !!err);
556
744
  } else if (msg) { msg.remove(); }
557
745
  if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
558
- // Ensure track element follows the input (CSS: input + track).
559
- if (!input.nextElementSibling || !input.nextElementSibling.classList.contains("c-switch__track")) {
560
- const track = document.createElement("span");
561
- track.className = "c-switch__track";
562
- track.setAttribute("aria-hidden", "true");
563
- if (input.nextSibling) this.insertBefore(track, input.nextSibling);
564
- else this.appendChild(track);
565
- }
746
+ // The input's ::after draws the track; a separate .c-switch__track span
747
+ // would be a second, unstyled element the CSS never reaches (R18-41).
566
748
  if (label) {
567
749
  input.setAttribute("aria-label", label);
568
- const txt = this.querySelector(":scope > span:not([class]):not(.c-switch__track)") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
750
+ const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
569
751
  txt.textContent = label;
570
752
  }
753
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Switch");
571
754
  }
572
755
  enhance() {
573
756
  const input = this.querySelector("input");
@@ -579,23 +762,48 @@ class ContourSwitch extends ContourBase {
579
762
  }
580
763
  if (this._wiredSwitch) return;
581
764
  this._wiredSwitch = true;
765
+ // Label activation: the host is not a native <label>, so a click on the
766
+ // text or track must toggle the input. The input's own click is left to
767
+ // the platform (early return) so it toggles exactly once.
768
+ this.addEventListener("click", (e) => {
769
+ if (e.target && e.target.closest && e.target.closest("input")) return;
770
+ const inp = this.querySelector("input");
771
+ if (!inp || inp.disabled) return;
772
+ e.preventDefault();
773
+ inp.click();
774
+ });
582
775
  this.addEventListener("change", (e) => {
583
776
  const inp = this.querySelector("input");
584
777
  if (!inp || e.target !== inp || !this._internals) return;
585
778
  inp.setAttribute("aria-checked", String(inp.checked));
586
779
  this._setCustomState("data-checked", inp.checked);
780
+ this.toggleAttribute("checked", inp.checked);
587
781
  this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
588
782
  this._emitForm("contour:change");
589
783
  this._syncValidity(this.hasAttribute("required") && !inp.checked);
590
784
  });
591
785
  }
786
+ formResetCallback() {
787
+ // `checked` is reflected on every toggle, so the authored default must
788
+ // come from the first-render capture — native defaultChecked semantics,
789
+ // not the last reflected state (R20 T-08).
790
+ this._contourResetting = true;
791
+ try {
792
+ this.toggleAttribute("checked", !!this._switchDefaultChecked);
793
+ const inp = this.querySelector("input");
794
+ if (inp) inp.checked = this.hasAttribute("checked");
795
+ this._syncFormValue();
796
+ } finally {
797
+ this._contourResetting = false;
798
+ }
799
+ }
592
800
  }
593
801
  define("contour-switch", ContourSwitch);
594
802
  /**
595
803
  * Check: a checkbox (or `type="radio"` when `type` is set) with label, name,
596
- * value, required, checked, disabled, error and help states. Renders a
597
- * `c-check__box` element after the input. Form associated; emits
598
- * `contour:change` on toggle.
804
+ * value, required, checked, disabled, error and help states. The input's
805
+ * ::after draws the box; there is no separate box element. Form associated;
806
+ * emits `contour:change` on toggle.
599
807
  */
600
808
  class ContourCheck extends ContourBase {
601
809
  static get observed() { return ["label", "name", "value", "required", "type", "checked", "disabled", "error", "help"]; }
@@ -603,22 +811,19 @@ class ContourCheck extends ContourBase {
603
811
  static get formAssociated() { return true; }
604
812
  render() {
605
813
  this.classList.add("c-check");
814
+ // Authored default captured before any toggle reflects into `checked`.
815
+ if (this._checkDefaultChecked === undefined) this._checkDefaultChecked = this.hasAttribute("checked");
606
816
  const label = this.getAttribute("label");
607
817
  const input = this.ensure("input.c-check__input", () => { const el = document.createElement("input"); el.className = "c-check__input"; el.type = this.getAttribute("type") === "radio" ? "radio" : "checkbox"; return el; });
608
818
  input.checked = this.hasAttribute("checked");
609
- // Ensure box element follows the input (CSS: input + box).
610
- if (!input.nextElementSibling || !input.nextElementSibling.classList.contains("c-check__box")) {
611
- const box = document.createElement("span");
612
- box.className = "c-check__box";
613
- box.setAttribute("aria-hidden", "true");
614
- if (input.nextSibling) this.insertBefore(box, input.nextSibling);
615
- else this.appendChild(box);
616
- }
819
+ // The input's ::after draws the box; a separate .c-check__box span would
820
+ // be a second, unstyled element the CSS never reaches (R18-41).
617
821
  if (label) {
618
822
  input.setAttribute("aria-label", label);
619
- const txt = this.querySelector(":scope > span:not([class]):not(.c-check__box)") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
823
+ const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
620
824
  txt.textContent = label;
621
825
  }
826
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Checkbox");
622
827
  if (this.hasAttribute("name")) input.name = this.getAttribute("name");
623
828
  if (this.hasAttribute("value")) input.value = this.getAttribute("value");
624
829
  if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
@@ -642,15 +847,38 @@ class ContourCheck extends ContourBase {
642
847
  }
643
848
  if (this._wiredCheck) return;
644
849
  this._wiredCheck = true;
850
+ // Label activation: the host is not a native <label>, so a click on the
851
+ // text or box must toggle the input. The input's own click is left to
852
+ // the platform (early return) so it toggles exactly once.
853
+ this.addEventListener("click", (e) => {
854
+ if (e.target && e.target.closest && e.target.closest("input")) return;
855
+ const inp = this.querySelector("input");
856
+ if (!inp || inp.disabled) return;
857
+ e.preventDefault();
858
+ inp.click();
859
+ });
645
860
  this.addEventListener("change", (e) => {
646
861
  const inp = this.querySelector("input");
647
862
  if (!inp || e.target !== inp || !this._internals) return;
648
863
  this._setCustomState("data-checked", inp.checked);
864
+ this.toggleAttribute("checked", inp.checked);
649
865
  this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
650
866
  this._emitForm("contour:change");
651
867
  this._syncValidity(this.hasAttribute("required") && !inp.checked);
652
868
  });
653
869
  }
870
+ formResetCallback() {
871
+ // Same default-capture contract as contour-switch (R20 T-08).
872
+ this._contourResetting = true;
873
+ try {
874
+ this.toggleAttribute("checked", !!this._checkDefaultChecked);
875
+ const inp = this.querySelector("input");
876
+ if (inp) inp.checked = this.hasAttribute("checked");
877
+ this._syncFormValue();
878
+ } finally {
879
+ this._contourResetting = false;
880
+ }
881
+ }
654
882
  }
655
883
  define("contour-check", ContourCheck);
656
884
  /**
@@ -685,6 +913,7 @@ class ContourRadio extends ContourBase {
685
913
  const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
686
914
  txt.textContent = label;
687
915
  }
916
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Radio");
688
917
  }
689
918
  enhance() {
690
919
  const input = this.querySelector("input");
@@ -695,6 +924,16 @@ class ContourRadio extends ContourBase {
695
924
  }
696
925
  if (this._wiredRadio) return;
697
926
  this._wiredRadio = true;
927
+ // Label activation: the host is not a native <label>, so a click on the
928
+ // text must select the radio. The input's own click is left to the
929
+ // platform (early return) so it toggles exactly once.
930
+ this.addEventListener("click", (e) => {
931
+ if (e.target && e.target.closest && e.target.closest("input")) return;
932
+ const inp = this.querySelector("input");
933
+ if (!inp || inp.disabled) return;
934
+ e.preventDefault();
935
+ inp.click();
936
+ });
698
937
  this.addEventListener("change", (e) => {
699
938
  const inp = this.querySelector("input");
700
939
  if (!inp || e.target !== inp || !this._internals) return;
@@ -714,11 +953,13 @@ class ContourRadio extends ContourBase {
714
953
  * required, disabled, error and help. Form associated; emits `contour:change`.
715
954
  */
716
955
  class ContourSelect extends ContourBase {
717
- static get observed() { return ["options", "required", "label", "placeholder", "disabled", "error", "help"]; }
718
- static get properties() { return { options: { attribute: "options" }, required: { attribute: "required", type: Boolean }, label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
956
+ static get observed() { return ["options", "required", "label", "placeholder", "disabled", "error", "help", "value", "name", "multiple", "autocomplete"]; }
957
+ static get properties() { return { options: { attribute: "options" }, required: { attribute: "required", type: Boolean }, label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, multiple: { attribute: "multiple", type: Boolean }, autocomplete: { attribute: "autocomplete" } }; }
719
958
  static get formAssociated() { return true; }
720
959
  render() {
721
960
  this.classList.add("c-select");
961
+ // Authored default captured before any commit reflects into `value`.
962
+ if (this._selectDefault === undefined) this._selectDefault = this.getAttribute("value");
722
963
  const options = this.getAttribute("options");
723
964
  // Slot composition: an authored <select> wins over the JSON attribute.
724
965
  const generated = new Set(this._contourGenerated || []);
@@ -761,7 +1002,7 @@ class ContourSelect extends ContourBase {
761
1002
  if (select.parentNode !== this) this.appendChild(select);
762
1003
  this.classList.remove("c-select");
763
1004
  select.classList.add("c-select");
764
- } catch (e) { /* keep existing */ }
1005
+ } catch (e) { warnBadJson(this, "attribute", e); }
765
1006
  }
766
1007
  // Ensure authored select gets c-select styling.
767
1008
  const authoredSel = this.querySelector("select");
@@ -774,6 +1015,22 @@ class ContourSelect extends ContourBase {
774
1015
  if (sel) {
775
1016
  if (this.hasAttribute("disabled")) { sel.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
776
1017
  else { sel.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1018
+ // Reflect the native attributes the platform reads: FormData needs
1019
+ // `name`, a multi-select needs `multiple`, and the value must be the
1020
+ // committed selection rather than whatever the first option happens to be.
1021
+ if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
1022
+ if (this.hasAttribute("multiple")) sel.setAttribute("multiple", ""); else sel.removeAttribute("multiple");
1023
+ if (this.hasAttribute("autocomplete")) sel.setAttribute("autocomplete", this.getAttribute("autocomplete"));
1024
+ if (this.hasAttribute("required")) sel.setAttribute("required", ""); else sel.removeAttribute("required");
1025
+ const val = this.getAttribute("value");
1026
+ if (val !== null) {
1027
+ if (sel.multiple) {
1028
+ const wanted = new Set(String(val).split(",").map((v) => v.trim()).filter(Boolean));
1029
+ Array.from(sel.options).forEach((o) => { o.selected = wanted.has(o.value); });
1030
+ } else {
1031
+ sel.value = val;
1032
+ }
1033
+ }
777
1034
  }
778
1035
  // Label (applies to both JSON and authored options).
779
1036
  const label = this.getAttribute("label");
@@ -781,7 +1038,15 @@ class ContourSelect extends ContourBase {
781
1038
  let lbl = this.querySelector("label.c-select__label");
782
1039
  if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; this.insertBefore(lbl, sel || this.firstChild); }
783
1040
  lbl.textContent = label;
784
- if (sel) sel.setAttribute("aria-label", label);
1041
+ if (sel) {
1042
+ if (!sel.id) sel.id = contourId("contour-select");
1043
+ lbl.setAttribute("for", sel.id);
1044
+ sel.setAttribute("aria-label", label);
1045
+ }
1046
+ }
1047
+ if (!this.querySelector("select")?.hasAttribute("aria-label")) {
1048
+ const sel = this.querySelector("select");
1049
+ if (sel) sel.setAttribute("aria-label", "Select");
785
1050
  }
786
1051
  const err = this.getAttribute("error");
787
1052
  const help = this.getAttribute("help");
@@ -794,21 +1059,85 @@ class ContourSelect extends ContourBase {
794
1059
  if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
795
1060
  }
796
1061
  enhance() {
797
- const select = this.querySelector("select");
798
- if (select && this._internals) {
799
- this._internals.setFormValue(select.value);
800
- this._syncValidity(this.hasAttribute("required") && !select.value);
801
- }
1062
+ if (this._internals) this._syncFormValue();
802
1063
  if (this._wiredSelect) return;
803
1064
  this._wiredSelect = true;
1065
+ this.addEventListener("input", (e) => {
1066
+ const sel = this.querySelector("select");
1067
+ if (!sel || e.target !== sel) return;
1068
+ this._emitForm("contour:input");
1069
+ });
804
1070
  this.addEventListener("change", (e) => {
805
1071
  const sel = this.querySelector("select");
806
1072
  if (!sel || e.target !== sel || !this._internals) return;
807
- this._internals.setFormValue(sel.value);
1073
+ // Reflect the WHOLE selection: for a multi-select sel.value is only
1074
+ // the first selected option, and the reflected attribute is what a
1075
+ // re-render rebuilds from (R20 T-06).
1076
+ const committed = sel.multiple ? Array.from(sel.selectedOptions).map((o) => o.value).join(",") : sel.value;
1077
+ this.setAttribute("value", committed);
1078
+ this._syncFormValue();
808
1079
  this._emitForm("contour:change");
809
- this._syncValidity(this.hasAttribute("required") && !sel.value);
810
1080
  });
811
1081
  }
1082
+ // Multi-select submits every selected option as its own entry under the
1083
+ // host name — the FormData form value, not select.value (first option
1084
+ // only). The formdata re-sync in _wireFormData calls THIS, so the base
1085
+ // generic must not collapse the selection back to one entry.
1086
+ _syncFormValue() {
1087
+ if (!this._internals) return;
1088
+ const sel = this.querySelector("select");
1089
+ if (!sel) return;
1090
+ if (sel.multiple) {
1091
+ const chosen = Array.from(sel.selectedOptions).map((o) => o.value);
1092
+ const name = this.getAttribute("name");
1093
+ if (name && chosen.length) {
1094
+ const fd = new FormData();
1095
+ for (const v of chosen) fd.append(name, v);
1096
+ this._internals.setFormValue(fd);
1097
+ } else {
1098
+ this._internals.setFormValue(null);
1099
+ }
1100
+ this._syncValidity(this.hasAttribute("required") && !chosen.length);
1101
+ } else {
1102
+ this._internals.setFormValue(sel.value);
1103
+ this._syncValidity(this.hasAttribute("required") && !sel.value);
1104
+ }
1105
+ }
1106
+ formResetCallback() {
1107
+ // Restore the authored default, not the first option and not the last
1108
+ // reflected commit (R20 T-08). The attribute write re-renders the
1109
+ // selection; the resetting flag keeps the base restore out of it.
1110
+ this._contourResetting = true;
1111
+ try {
1112
+ const def = this._selectDefault ?? null;
1113
+ if (def === null) this.removeAttribute("value");
1114
+ else this.setAttribute("value", def);
1115
+ this._syncFormValue();
1116
+ } finally {
1117
+ this._contourResetting = false;
1118
+ }
1119
+ }
1120
+ formStateRestoreCallback(state) {
1121
+ const sel = this.querySelector("select");
1122
+ if (!sel || !this._internals) return;
1123
+ const values = state instanceof FormData
1124
+ ? Array.from(state.getAll(this.getAttribute("name"))).map(String)
1125
+ : (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
1126
+ this._contourResetting = true;
1127
+ try {
1128
+ if (sel.multiple) {
1129
+ const wanted = new Set(values);
1130
+ for (const o of sel.options) o.selected = wanted.has(o.value);
1131
+ this.setAttribute("value", values.join(","));
1132
+ } else {
1133
+ sel.value = values[0] || "";
1134
+ this.setAttribute("value", sel.value);
1135
+ }
1136
+ this._syncFormValue();
1137
+ } finally {
1138
+ this._contourResetting = false;
1139
+ }
1140
+ }
812
1141
  }
813
1142
  define("contour-select", ContourSelect);
814
1143
  /**
@@ -816,11 +1145,13 @@ class ContourSelect extends ContourBase {
816
1145
  * with `selected` support per option. Form associated; emits `contour:change`.
817
1146
  */
818
1147
  class ContourVersion extends ContourBase {
819
- static get observed() { return ["options"]; }
1148
+ static get observed() { return ["options", "value", "name"]; }
820
1149
  static get formAssociated() { return true; }
821
- static get properties() { return { options: { attribute: "options" } }; }
1150
+ static get properties() { return { options: { attribute: "options" }, value: { attribute: "value" }, name: { attribute: "name" } }; }
822
1151
  render() {
823
1152
  this.classList.add("c-version");
1153
+ // Authored default captured before any commit reflects into `value`.
1154
+ if (this._versionDefault === undefined) this._versionDefault = this.getAttribute("value");
824
1155
  const options = this.getAttribute("options");
825
1156
  const generated = new Set(this._contourGenerated || []);
826
1157
  const authored = Array.from(this.children).filter((n) => !generated.has(n));
@@ -839,24 +1170,47 @@ class ContourVersion extends ContourBase {
839
1170
  if (select.parentNode !== this) this.appendChild(select);
840
1171
  this.classList.remove("c-version");
841
1172
  select.classList.add("c-version");
842
- } catch (e) { /* keep existing */ }
1173
+ } catch (e) { warnBadJson(this, "attribute", e); }
1174
+ }
1175
+ // The committed value selects the option (R20 T-07): without this the
1176
+ // host always submitted the first option regardless of `value`.
1177
+ const sel = this.querySelector("select");
1178
+ if (sel) {
1179
+ if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
1180
+ const val = this.getAttribute("value");
1181
+ if (val !== null) sel.value = val;
843
1182
  }
844
1183
  }
845
1184
  enhance() {
846
- if (this._wiredVersion) return;
847
- this._wiredVersion = true;
848
1185
  const sync = () => {
849
1186
  const select = this.querySelector("select");
850
1187
  if (!select || !this._internals) return;
851
1188
  this._internals.setFormValue(select.value);
852
1189
  };
1190
+ sync();
1191
+ if (this._wiredVersion) return;
1192
+ this._wiredVersion = true;
853
1193
  this.addEventListener("change", (e) => {
854
1194
  const select = this.querySelector("select");
855
1195
  if (!select || e.target !== select) return;
1196
+ // Reflect the committed selection so a consumer reading `value` sees
1197
+ // what the user picked, and a re-render rebuilds it.
1198
+ this.setAttribute("value", select.value);
856
1199
  sync();
857
1200
  this._emitForm("contour:change");
858
1201
  });
859
- sync();
1202
+ }
1203
+ formResetCallback() {
1204
+ // Restore the authored default, not the first option (R20 T-08).
1205
+ this._contourResetting = true;
1206
+ try {
1207
+ const def = this._versionDefault ?? null;
1208
+ if (def === null) this.removeAttribute("value");
1209
+ else this.setAttribute("value", def);
1210
+ this._syncFormValue();
1211
+ } finally {
1212
+ this._contourResetting = false;
1213
+ }
860
1214
  }
861
1215
  }
862
1216
  define("contour-version", ContourVersion);
@@ -865,13 +1219,23 @@ class ContourVersion extends ContourBase {
865
1219
  * and help states. Form associated; emits `contour:input` / `contour:change`.
866
1220
  */
867
1221
  class ContourTextarea extends ContourBase {
868
- static get observed() { return ["placeholder", "required", "disabled", "error", "help"]; }
869
- static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
1222
+ static get observed() { return ["placeholder", "required", "disabled", "error", "help", "value", "name", "label"]; }
1223
+ static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, label: { attribute: "label" } }; }
870
1224
  static get formAssociated() { return true; }
871
1225
  render() {
872
1226
  const ta = this.ensure("textarea", () => { const el = document.createElement("textarea"); el.className = "c-textarea"; return el; });
873
1227
  ta.className = "c-textarea";
874
- ta.placeholder = this.getAttribute("placeholder") || "";
1228
+ // value and name reach the generated control (R20 T-01): without them
1229
+ // the host submitted an empty entry under no name at all. Typed text
1230
+ // survives re-renders through the base class's user-dirty tracking.
1231
+ if (this.hasAttribute("name")) ta.name = this.getAttribute("name");
1232
+ else ta.removeAttribute("name");
1233
+ if (this.hasAttribute("value")) ta.value = this.getAttribute("value");
1234
+ if (this.hasAttribute("aria-label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("aria-label"));
1235
+ if (this.hasAttribute("label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("label"));
1236
+ if (!ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", "Textarea");
1237
+ if (this.hasAttribute("placeholder")) ta.placeholder = this.getAttribute("placeholder");
1238
+ else ta.removeAttribute("placeholder");
875
1239
  if (this.hasAttribute("required")) ta.setAttribute("required", "");
876
1240
  else ta.removeAttribute("required");
877
1241
  if (this.hasAttribute("disabled")) { ta.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
@@ -916,8 +1280,8 @@ class ContourTextarea extends ContourBase {
916
1280
  * error and help states. Form associated; emits `contour:input` / `contour:change`.
917
1281
  */
918
1282
  class ContourInputFull extends ContourBase {
919
- static get observed() { return ["type", "placeholder", "required", "value", "disabled", "error", "help", "label"]; }
920
- static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, label: { attribute: "label" } }; }
1283
+ static get observed() { return ["type", "placeholder", "required", "value", "disabled", "error", "help", "label", "name"]; }
1284
+ static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, label: { attribute: "label" }, name: { attribute: "name" } }; }
921
1285
  static get formAssociated() { return true; }
922
1286
  render() {
923
1287
  this.classList.add("c-input");
@@ -925,6 +1289,10 @@ class ContourInputFull extends ContourBase {
925
1289
  input.className = "c-input";
926
1290
  input.type = this.getAttribute("type") || "text";
927
1291
  input.placeholder = this.getAttribute("placeholder") || "";
1292
+ // The name keys the base class's value/focus preservation and matches
1293
+ // the native control's own contract (R20 T-02/T-08).
1294
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
1295
+ else input.removeAttribute("name");
928
1296
  let label = this.getAttribute("label");
929
1297
  if (!label) {
930
1298
  const field = this.closest("contour-field");
@@ -976,17 +1344,31 @@ class ContourInputFull extends ContourBase {
976
1344
  /**
977
1345
  * InputGroup: a text input with an optional search icon, a clear (×) affordance
978
1346
  * and a submit (→) affordance. Attributes: `label`, `placeholder`, `clearable`,
979
- * `submit`. Emits `contour:change` (bubbles, composed) with `{ value: "" }` on
980
- * clear.
1347
+ * `submit`, `value`, `name`, `required`, `disabled`. Form associated: the host
1348
+ * submits its value through ElementInternals. Emits `contour:input` /
1349
+ * `contour:change`, and `contour:change` (bubbles, composed) with `{ value: "" }`
1350
+ * on clear.
981
1351
  */
982
1352
  class ContourInputGroup extends ContourBase {
983
- static get observed() { return ["label", "placeholder", "clearable", "submit"]; }
984
- static get properties() { return { label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, clearable: { attribute: "clearable", type: Boolean }, submit: { attribute: "submit", type: Boolean } }; }
1353
+ static get observed() { return ["label", "placeholder", "clearable", "submit", "value", "name", "required", "disabled"]; }
1354
+ static get properties() { return { label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, clearable: { attribute: "clearable", type: Boolean }, submit: { attribute: "submit", type: Boolean }, value: { attribute: "value" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
1355
+ static get formAssociated() { return true; }
985
1356
  render() {
986
1357
  this.classList.add("c-input-group");
987
1358
  const icon = this.ensure("svg", () => { const el = document.createElementNS("http://www.w3.org/2000/svg", "svg"); el.setAttribute("aria-hidden", "true"); const use = document.createElementNS("http://www.w3.org/2000/svg", "use"); use.setAttribute("href", "#i-search"); el.appendChild(use); return el; });
988
1359
  const input = this.ensure("input.c-input", () => { const el = document.createElement("input"); el.className = "c-input"; el.type = "text"; return el; });
989
1360
  input.placeholder = this.getAttribute("placeholder") || this.getAttribute("label") || "";
1361
+ // Form participation (R20 T-05): the host submits through internals,
1362
+ // and the inner control carries the name/value the author wrote.
1363
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
1364
+ else input.removeAttribute("name");
1365
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
1366
+ if (this.hasAttribute("required")) input.setAttribute("required", "");
1367
+ else input.removeAttribute("required");
1368
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1369
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1370
+ const label = this.getAttribute("label");
1371
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", label || "Search");
990
1372
  // Clear affordance.
991
1373
  const oldClear = this.querySelector(".c-input-group__clear");
992
1374
  if (oldClear) oldClear.remove();
@@ -1011,14 +1393,37 @@ class ContourInputGroup extends ContourBase {
1011
1393
  }
1012
1394
  }
1013
1395
  enhance() {
1396
+ const input = this.querySelector("input.c-input");
1397
+ if (input && this._internals) {
1398
+ this._internals.setFormValue(input.value);
1399
+ this._syncValidity(this.hasAttribute("required") && !input.value.trim());
1400
+ }
1014
1401
  if (this._wiredInputGroup) return;
1015
1402
  this._wiredInputGroup = true;
1403
+ this.addEventListener("input", (e) => {
1404
+ const inp = this.querySelector("input.c-input");
1405
+ if (!inp || e.target !== inp || !this._internals) return;
1406
+ this._internals.setFormValue(inp.value);
1407
+ this._emitForm("contour:input");
1408
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
1409
+ });
1410
+ this.addEventListener("change", (e) => {
1411
+ const inp = this.querySelector("input.c-input");
1412
+ if (!inp || e.target !== inp || !this._internals) return;
1413
+ this._internals.setFormValue(inp.value);
1414
+ this._emitForm("contour:change");
1415
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
1416
+ });
1016
1417
  this.addEventListener("click", (e) => {
1017
1418
  const clear = e.target && e.target.closest ? e.target.closest(".c-input-group__clear") : null;
1018
1419
  if (clear && this.contains(clear)) {
1019
1420
  e.preventDefault();
1020
1421
  const input = this.querySelector("input.c-input");
1021
1422
  if (input) { input.value = ""; input.focus(); }
1423
+ if (this._internals) {
1424
+ this._internals.setFormValue("");
1425
+ this._syncValidity(this.hasAttribute("required"));
1426
+ }
1022
1427
  this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: "" } }));
1023
1428
  }
1024
1429
  });
@@ -1065,7 +1470,7 @@ class ContourRadioList extends ContourBase {
1065
1470
  const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
1066
1471
  const checked = radios.find((r) => r.checked) || radios[0];
1067
1472
  if (checked) checked.tabIndex = 0;
1068
- } catch (e) { /* keep existing */ }
1473
+ } catch (e) { warnBadJson(this, "attribute", e); }
1069
1474
  } else {
1070
1475
  renderEmpty(this, "radio-list");
1071
1476
  }
@@ -1117,7 +1522,231 @@ class ContourRadioList extends ContourBase {
1117
1522
  // The authored default lives in the `items` payload (`it.checked`), not
1118
1523
  // in checked attributes on generated radios, so re-render from the data
1119
1524
  // rather than blanking every selection like the generic base reset.
1120
- if (this._contourAuthored) this.requestRender();
1525
+ // Synchronous and under the resetting flag: the base class's checked
1526
+ // restore would otherwise resurrect the user's selection over the
1527
+ // payload (measured by the R20 form-participation arm).
1528
+ this._contourResetting = true;
1529
+ try {
1530
+ if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
1531
+ this._syncFormValue();
1532
+ } finally {
1533
+ this._contourResetting = false;
1534
+ }
1121
1535
  }
1122
1536
  }
1123
1537
  define("contour-radio-list", ContourRadioList);
1538
+
1539
+ // Fieldset: a <fieldset> with a <legend>, for grouping related controls. The
1540
+ // platform already draws the group boundary; the component wraps it so a
1541
+ // consumer can drop <contour-fieldset legend="…"> and get the semantics.
1542
+ class ContourFieldset extends ContourBase {
1543
+ static get observed() { return ["legend", "disabled"]; }
1544
+ static get properties() { return { legend: { attribute: "legend" }, disabled: { attribute: "disabled", type: Boolean } }; }
1545
+ render() {
1546
+ const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-fieldset"; return el; });
1547
+ if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
1548
+ const legend = this.getAttribute("legend");
1549
+ let lg = fs.querySelector("legend");
1550
+ if (legend) {
1551
+ if (!lg) { lg = document.createElement("legend"); lg.className = "c-fieldset__legend"; fs.prepend(lg); }
1552
+ lg.textContent = legend;
1553
+ } else if (lg) lg.remove();
1554
+ // Move authored children into the fieldset (light DOM).
1555
+ const authored = Array.from(this.children).filter((c) => c !== fs);
1556
+ if (authored.length) { authored.forEach((c) => fs.appendChild(c)); }
1557
+ }
1558
+ }
1559
+ define("contour-fieldset", ContourFieldset);
1560
+
1561
+ // Checkbox group: a fieldset of checkboxes with a shared name. Form
1562
+ // associated (R20 T-03): the host owns the group value — each checked box
1563
+ // submits as its own entry under the host name (the FormData form value),
1564
+ // `value` reflects the comma-joined selection, reset restores the authored
1565
+ // default, and `required` reports group validity. Emits contour:change with
1566
+ // { value, values }.
1567
+ class ContourCheckboxGroup extends ContourBase {
1568
+ static get observed() { return ["legend", "name", "options", "value", "required", "disabled"]; }
1569
+ static get properties() { return { legend: { attribute: "legend" }, name: { attribute: "name" }, options: { attribute: "options" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
1570
+ static get formAssociated() { return true; }
1571
+ render() {
1572
+ this.classList.add("c-checkbox-group");
1573
+ // Authored default captured before any toggle reflects into `value`.
1574
+ if (this._checkboxGroupDefault === undefined) this._checkboxGroupDefault = this.getAttribute("value");
1575
+ const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-checkbox-group__fieldset"; return el; });
1576
+ if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
1577
+ if (this.hasAttribute("required")) fs.setAttribute("aria-required", "true"); else fs.removeAttribute("aria-required");
1578
+ const legend = this.getAttribute("legend");
1579
+ let lg = fs.querySelector("legend");
1580
+ if (legend) {
1581
+ if (!lg) { lg = document.createElement("legend"); lg.className = "c-checkbox-group__legend"; fs.prepend(lg); }
1582
+ lg.textContent = legend;
1583
+ } else if (lg) lg.remove();
1584
+ const name = this.getAttribute("name") || "group";
1585
+ const options = this.getAttribute("options");
1586
+ const selected = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean);
1587
+ if (options) {
1588
+ try {
1589
+ const parsed = JSON.parse(options);
1590
+ Array.from(fs.querySelectorAll(".c-check")).forEach((n) => n.remove());
1591
+ parsed.forEach((opt) => {
1592
+ const label = typeof opt === "string" ? opt : (opt.label || opt.value || "");
1593
+ const value = typeof opt === "string" ? opt : (opt.value || opt.label || "");
1594
+ const wrap = document.createElement("label");
1595
+ wrap.className = "c-check";
1596
+ const input = document.createElement("input");
1597
+ input.type = "checkbox";
1598
+ input.className = "c-check__input";
1599
+ input.name = name;
1600
+ input.value = value;
1601
+ // Every box shares the group name, so name-based focus matching
1602
+ // would land on the FIRST box after the reflection re-render; the
1603
+ // per-option preserve key puts focus back on the box clicked.
1604
+ input.setAttribute("data-contour-preserve-key", value);
1605
+ if (selected.includes(value)) input.checked = true;
1606
+ const span = document.createElement("span");
1607
+ span.textContent = label;
1608
+ wrap.appendChild(input);
1609
+ wrap.appendChild(span);
1610
+ fs.appendChild(wrap);
1611
+ });
1612
+ } catch (e) { warnBadJson(this, "attribute", e); }
1613
+ }
1614
+ }
1615
+ enhance() {
1616
+ if (this._internals) this._syncFormValue();
1617
+ if (this._wiredCheckboxGroup) return;
1618
+ this._wiredCheckboxGroup = true;
1619
+ this.addEventListener("change", (e) => {
1620
+ const t = e.target;
1621
+ if (t && t.matches && t.matches("input[type=checkbox]")) {
1622
+ const values = Array.from(this.querySelectorAll("input[type=checkbox]:checked")).map((i) => i.value);
1623
+ // Reflect the group value so `el.value` reads the live selection and
1624
+ // a re-render rebuilds it; the attribute write re-renders synchronously.
1625
+ this.setAttribute("value", values.join(","));
1626
+ this._syncFormValue();
1627
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: values.join(","), values } }));
1628
+ }
1629
+ });
1630
+ }
1631
+ // Each checked box is its own entry under the host name — the FormData
1632
+ // form value, which keeps the native repeated-entry wire shape while the
1633
+ // host owns reset and validity. The formdata re-sync calls THIS.
1634
+ _syncFormValue() {
1635
+ if (!this._internals) return;
1636
+ const checked = Array.from(this.querySelectorAll("input[type=checkbox]:checked"));
1637
+ const name = this.getAttribute("name");
1638
+ if (name && checked.length) {
1639
+ const fd = new FormData();
1640
+ for (const c of checked) fd.append(name, c.value);
1641
+ this._internals.setFormValue(fd);
1642
+ } else {
1643
+ this._internals.setFormValue(null);
1644
+ }
1645
+ this._syncValidity(this.hasAttribute("required") && !checked.length);
1646
+ }
1647
+ formResetCallback() {
1648
+ // Restore the authored default, not the last reflected selection.
1649
+ this._contourResetting = true;
1650
+ try {
1651
+ const def = this._checkboxGroupDefault ?? null;
1652
+ if (def === null) this.removeAttribute("value");
1653
+ else this.setAttribute("value", def);
1654
+ this._syncFormValue();
1655
+ } finally {
1656
+ this._contourResetting = false;
1657
+ }
1658
+ }
1659
+ formStateRestoreCallback(state) {
1660
+ const values = state instanceof FormData
1661
+ ? Array.from(state.getAll(this.getAttribute("name"))).map(String)
1662
+ : (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
1663
+ this._contourResetting = true;
1664
+ try {
1665
+ this.setAttribute("value", values.join(","));
1666
+ this._syncFormValue();
1667
+ } finally {
1668
+ this._contourResetting = false;
1669
+ }
1670
+ }
1671
+ }
1672
+ define("contour-checkbox-group", ContourCheckboxGroup);
1673
+
1674
+ // Search field: a text input with a search icon and a clear button. The
1675
+ // platform's type=search gives the clear affordance; the component adds the
1676
+ // icon and the accessible name. Form associated (R20 T-04): the host submits
1677
+ // its value through ElementInternals, with reset and required validity.
1678
+ class ContourSearchField extends ContourBase {
1679
+ static get observed() { return ["value", "placeholder", "label", "name", "required", "disabled"]; }
1680
+ static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
1681
+ static get formAssociated() { return true; }
1682
+ render() {
1683
+ this.classList.add("c-search-field");
1684
+ const input = this.ensure("input", () => { const el = document.createElement("input"); el.type = "search"; el.className = "c-search-field__input"; return el; });
1685
+ input.placeholder = this.getAttribute("placeholder") || "Search";
1686
+ if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
1687
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
1688
+ if (this.hasAttribute("required")) input.setAttribute("required", "");
1689
+ else input.removeAttribute("required");
1690
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1691
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1692
+ const label = this.getAttribute("label");
1693
+ if (label) input.setAttribute("aria-label", label);
1694
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Search");
1695
+ }
1696
+ enhance() {
1697
+ const input = this.querySelector("input");
1698
+ if (input && this._internals) {
1699
+ this._internals.setFormValue(input.value);
1700
+ this._syncValidity(this.hasAttribute("required") && !input.value.trim());
1701
+ }
1702
+ if (this._wiredSearchField) return;
1703
+ this._wiredSearchField = true;
1704
+ this.addEventListener("input", (e) => {
1705
+ const t = e.target;
1706
+ if (t && t.matches && t.matches("input")) {
1707
+ if (this._internals) {
1708
+ this._internals.setFormValue(t.value);
1709
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
1710
+ }
1711
+ this._emitForm("contour:input");
1712
+ }
1713
+ });
1714
+ this.addEventListener("change", (e) => {
1715
+ const t = e.target;
1716
+ if (!t || !t.matches || !t.matches("input") || !this._internals) return;
1717
+ this._internals.setFormValue(t.value);
1718
+ this._emitForm("contour:change");
1719
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
1720
+ });
1721
+ }
1722
+ }
1723
+ define("contour-search-field", ContourSearchField);
1724
+
1725
+ // Density toggle: a two-state control (comfortable / compact) that sets a
1726
+ // data-density attribute on the host. The consumer's CSS reads it.
1727
+ class ContourDensityToggle extends ContourBase {
1728
+ static get observed() { return ["value", "label"]; }
1729
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
1730
+ render() {
1731
+ this.classList.add("c-density-toggle");
1732
+ const value = this.getAttribute("value") || "comfortable";
1733
+ this.setAttribute("data-density", value);
1734
+ const btn = this.ensure("button", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-density-toggle__btn"; el.type = "button"; return el; });
1735
+ const label = this.getAttribute("label") || (value === "compact" ? "Compact" : "Comfortable");
1736
+ btn.textContent = label;
1737
+ btn.setAttribute("aria-pressed", value === "compact" ? "true" : "false");
1738
+ }
1739
+ enhance() {
1740
+ if (this._wiredDensityToggle) return;
1741
+ this._wiredDensityToggle = true;
1742
+ this.addEventListener("click", () => {
1743
+ const next = this.getAttribute("data-density") === "compact" ? "comfortable" : "compact";
1744
+ this.setAttribute("value", next);
1745
+ this.setAttribute("data-density", next);
1746
+ const btn = this.querySelector(".c-density-toggle__btn");
1747
+ if (btn) { btn.textContent = next === "compact" ? "Compact" : "Comfortable"; btn.setAttribute("aria-pressed", next === "compact" ? "true" : "false"); }
1748
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: next } }));
1749
+ });
1750
+ }
1751
+ }
1752
+ define("contour-density-toggle", ContourDensityToggle);