contour-ds 1.7.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +244 -326
  2. package/dist/agent-cookbook.json +960 -0
  3. package/dist/agent-examples.json +65 -0
  4. package/dist/agent-map-wiring.json +152 -0
  5. package/dist/agent-rules.json +16 -0
  6. package/dist/build-manifest.json +344 -126
  7. package/dist/contour-wc-content.esm.js +1939 -0
  8. package/dist/contour-wc-content.esm.min.js +1 -0
  9. package/dist/contour-wc-core.esm.js +3724 -0
  10. package/dist/contour-wc-core.esm.min.js +1 -0
  11. package/dist/contour-wc-dashboard.esm.js +6986 -0
  12. package/dist/contour-wc-dashboard.esm.min.js +1 -0
  13. package/dist/contour-wc-data.esm.js +6572 -0
  14. package/dist/contour-wc-data.esm.min.js +1 -0
  15. package/dist/contour-wc-docs.esm.js +976 -0
  16. package/dist/contour-wc-docs.esm.min.js +1 -0
  17. package/dist/contour-wc-feedback.esm.js +1742 -0
  18. package/dist/contour-wc-feedback.esm.min.js +1 -0
  19. package/dist/contour-wc-forms.esm.js +2437 -0
  20. package/dist/contour-wc-forms.esm.min.js +1 -0
  21. package/dist/contour-wc-interaction.esm.js +1343 -0
  22. package/dist/contour-wc-interaction.esm.min.js +1 -0
  23. package/dist/contour-wc-layout.esm.js +845 -0
  24. package/dist/contour-wc-layout.esm.min.js +1 -0
  25. package/dist/contour-wc-map.esm.js +2411 -0
  26. package/dist/contour-wc-map.esm.min.js +1 -0
  27. package/dist/contour-wc-misc.esm.js +945 -0
  28. package/dist/contour-wc-misc.esm.min.js +1 -0
  29. package/dist/contour-wc-navigation.esm.js +2842 -0
  30. package/dist/contour-wc-navigation.esm.min.js +1 -0
  31. package/dist/contour-wc-ui.esm.js +6519 -0
  32. package/dist/contour-wc-ui.esm.min.js +1 -0
  33. package/dist/contour-wc.esm.js +14435 -5723
  34. package/dist/contour-wc.esm.min.js +1 -1
  35. package/dist/contour-wc.js +14436 -5725
  36. package/dist/contour-wc.min.js +1 -1
  37. package/dist/contour.a11y.json +402 -0
  38. package/dist/contour.code-snippets +4534 -0
  39. package/dist/contour.components.json +4870 -1222
  40. package/dist/contour.css +6672 -4711
  41. package/dist/contour.d.ts +753 -1085
  42. package/dist/contour.esm.js +440 -18
  43. package/dist/contour.esm.min.js +1 -1
  44. package/dist/contour.html-data.json +11343 -0
  45. package/dist/contour.js +440 -18
  46. package/dist/contour.min.css +1 -1
  47. package/dist/contour.min.js +1 -1
  48. package/dist/contour.react.d.ts +422 -0
  49. package/dist/contour.single.html +17 -0
  50. package/dist/contour.single.min.css +1 -0
  51. package/dist/contour.themes.json +56 -12
  52. package/dist/contour.tokens.json +1318 -1053
  53. package/dist/contour.vue.d.ts +420 -0
  54. package/dist/contour.web-types.json +11703 -0
  55. package/dist/custom-elements.json +36120 -0
  56. package/dist/docs/actions.md +16 -6
  57. package/dist/docs/affordances.md +21 -85
  58. package/dist/docs/apireference.md +9 -5
  59. package/dist/docs/colour.md +10 -4
  60. package/dist/docs/componentindex.md +9 -22
  61. package/dist/docs/data.md +39 -58
  62. package/dist/docs/docs.md +12 -7
  63. package/dist/docs/feedback.md +30 -12
  64. package/dist/docs/field.md +28 -13
  65. package/dist/docs/forms.md +35 -19
  66. package/dist/docs/index.json +70 -61
  67. package/dist/docs/install.md +12 -7
  68. package/dist/docs/landing.md +7 -4
  69. package/dist/docs/mapengine.md +30 -8
  70. package/dist/docs/motion.md +12 -6
  71. package/dist/docs/navigation.md +31 -7
  72. package/dist/docs/overlays.md +32 -25
  73. package/dist/docs/overview.md +3 -2
  74. package/dist/docs/patterns.md +20 -10
  75. package/dist/docs/playground.md +11 -4
  76. package/dist/docs/principles.md +8 -6
  77. package/dist/docs/recipes.md +117 -13
  78. package/dist/docs/space.md +10 -6
  79. package/dist/docs/status.md +13 -14
  80. package/dist/docs/surfaces.md +17 -22
  81. package/dist/docs/theming.md +18 -32
  82. package/dist/docs/type.md +12 -5
  83. package/dist/docs/webcomponents.md +75 -33
  84. package/dist/hljs.css +1 -20
  85. package/dist/map-chrome.mapbox.css +68 -92
  86. package/dist/map-chrome.maplibre.css +68 -92
  87. package/dist/registry/items/contour-core.json +2 -2
  88. package/dist/registry/items/contour-data.json +2 -2
  89. package/dist/registry/items/contour-docs.json +2 -2
  90. package/dist/registry/items/contour-landing.json +2 -2
  91. package/dist/registry/registry.json +8 -8
  92. package/dist/surfaces/contour-core.min.css +1 -1
  93. package/dist/surfaces/contour-data.min.css +1 -1
  94. package/dist/surfaces/contour-docs.min.css +1 -1
  95. package/dist/surfaces/contour-landing.min.css +1 -1
  96. package/dist/svg/icons.svg +367 -0
  97. package/dist/wc/behaviours.mjs +222 -192
  98. package/dist/wc/content.mjs +486 -142
  99. package/dist/wc/core.mjs +917 -395
  100. package/dist/wc/dashboard.mjs +252 -25
  101. package/dist/wc/data-chart.mjs +1333 -0
  102. package/dist/wc/data-export.mjs +391 -0
  103. package/dist/wc/data-gauge.mjs +779 -0
  104. package/dist/wc/data-geo.mjs +696 -0
  105. package/dist/wc/data-glyphs.mjs +133 -0
  106. package/dist/wc/data-legend.mjs +431 -0
  107. package/dist/wc/data-readout.mjs +227 -0
  108. package/dist/wc/data-series.mjs +1004 -0
  109. package/dist/wc/data-table.mjs +751 -0
  110. package/dist/wc/data.mjs +15 -3707
  111. package/dist/wc/docs.mjs +113 -19
  112. package/dist/wc/feedback.mjs +320 -116
  113. package/dist/wc/forms-controls.mjs +635 -0
  114. package/dist/wc/forms-field.mjs +547 -0
  115. package/dist/wc/forms-groups.mjs +347 -0
  116. package/dist/wc/forms-input.mjs +292 -0
  117. package/dist/wc/forms.mjs +10 -1122
  118. package/dist/wc/glyph.mjs +204 -0
  119. package/dist/wc/index.mjs +16 -7
  120. package/dist/wc/interaction.mjs +322 -75
  121. package/dist/wc/layout.mjs +100 -29
  122. package/dist/wc/map.mjs +888 -285
  123. package/dist/wc/misc.mjs +137 -26
  124. package/dist/wc/navigation-menu.mjs +735 -0
  125. package/dist/wc/navigation-shell.mjs +495 -0
  126. package/dist/wc/navigation-tree.mjs +995 -0
  127. package/dist/wc/navigation.mjs +9 -1636
  128. package/dist/wc/registration.mjs +1 -8
  129. package/dist/wc/shadow.mjs +285 -113
  130. package/dist/wc/states.mjs +75 -78
  131. package/dist/wc/svg.mjs +209 -34
  132. package/dist/wc/ui-atoms.mjs +608 -0
  133. package/dist/wc/ui-data.mjs +1404 -0
  134. package/dist/wc/ui-feedback.mjs +419 -0
  135. package/dist/wc/ui-inputs.mjs +1570 -0
  136. package/dist/wc/ui-menus.mjs +307 -0
  137. package/dist/wc/ui-overlays.mjs +1605 -0
  138. package/integrations/README.md +25 -5
  139. package/integrations/ai/CLAUDE.md +6 -3
  140. package/integrations/ai/COPILOT.md +14 -0
  141. package/integrations/ai/GEMINI.md +14 -0
  142. package/integrations/ai/WINDSURF.md +14 -0
  143. package/integrations/ai/v0-prompt.md +13 -1
  144. package/integrations/frameworks/README.md +235 -0
  145. package/integrations/native/README.md +0 -3
  146. package/integrations/native/style-dictionary.config.json +1 -1
  147. package/integrations/tailwind/contour-theme.css +71 -13
  148. package/integrations/validate-markup.mjs +172 -0
  149. package/package.json +103 -39
  150. package/dist/wc/ui.mjs +0 -3560
package/dist/wc/forms.mjs CHANGED
@@ -1,1123 +1,11 @@
1
1
  /**
2
- * Form controls: field, field-group, form, combobox, select, check, radio,
3
- * switch, textarea, input, input-group, range, radio-list, version.
4
- *
5
- * All form controls are `ContourBase` subclasses. They render light-DOM markup
6
- * from observed attributes, reflect properties back to attributes, take part in
7
- * form association (`formAssociated`, `_internals.setFormValue`) where the
8
- * platform allows it, and emit `contour:input` / `contour:change` / `contour:submit`
9
- * events. Inline validation (blur-driven `aria-invalid`) is handled by
10
- * `ContourField`; `ContourForm` owns submission state and a live-region summary.
11
- * @module contour-wc/forms
12
- */
13
-
14
- import { ContourBase, define, contourId } from './core.mjs';
15
- import { wireCombobox } from './behaviours.mjs';
16
- import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
17
- /**
18
- * Combobox: a filterable, keyboard-navigable listbox backed by a JSON `options`
19
- * attribute or authored `<li>` options. Supports single and multi-select
20
- * (`multiple`), fixed-row virtualization (`virtual`), async/remote options
21
- * (`src`, `loading`, `error`, `retry`, `empty`, `skeleton`), a clear button and
22
- * form association. Emits `contour:select` on commit and `contour:input` on
23
- * filter. ArrowUp/Down/Home/End rove the cursor; Enter commits; Escape closes.
24
- */
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"]; }
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" } }; }
29
- render() {
30
- this.classList.add("c-combobox");
31
- wireStates(this);
32
- loadRemote(this, "options");
33
- if (renderStates(this, "combobox")) return;
34
- const options = remoteData(this, "options");
35
- // Slot composition: authored <li> options win over the JSON attribute.
36
- const authored = Array.from(this.children).filter((n) => !n.classList || (!n.classList.contains("c-combobox__input") && !n.classList.contains("c-combobox__list")));
37
- if ((options) && !authored.length) {
38
- try {
39
- const parsed = options ? JSON.parse(options) : [];
40
- const input = this.ensure(".c-combobox__input", () => { const el = document.createElement("input"); el.className = "c-combobox__input"; el.type = "text"; return el; });
41
- input.type = "text";
42
- input.placeholder = this.getAttribute("placeholder") || "Search…";
43
- input.setAttribute("aria-label", this.getAttribute("label") || "Search");
44
- const val = this.getAttribute("value");
45
- if (val !== null) input.value = val;
46
- const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
47
- list.innerHTML = "";
48
- list.setAttribute("hidden", "");
49
- this._comboboxOptions = parsed;
50
- this._comboboxVirtual = this.hasAttribute("virtual") && parsed.length > 100;
51
- if (this._comboboxVirtual) {
52
- list.classList.add("c-combobox__list--virtual");
53
- list.style.maxBlockSize = "20rem";
54
- list.style.overflow = "auto";
55
- this._renderComboboxWindow("", true);
56
- } else {
57
- list.classList.remove("c-combobox__list--virtual");
58
- list.style.maxBlockSize = "";
59
- list.style.overflow = "";
60
- this._renderComboboxWindow("", true);
61
- }
62
- } catch (e) { /* keep existing */ }
63
- } else if (!authored.length && !options) {
64
- renderEmpty(this, "combobox");
65
- }
66
- // Clear button (F-11).
67
- if (this.getAttribute("value")) {
68
- this.ensure(".c-combobox__clear", () => {
69
- const btn = document.createElement("button");
70
- btn.className = "c-combobox__clear";
71
- btn.type = "button";
72
- btn.setAttribute("aria-label", "Clear");
73
- btn.textContent = "×";
74
- return btn;
75
- });
76
- } else {
77
- const btn = this.querySelector(".c-combobox__clear");
78
- if (btn) btn.remove();
79
- }
80
- }
81
- _renderComboboxWindow(query = "", reset = false) {
82
- const list = this.querySelector(".c-combobox__list");
83
- const options = this._comboboxOptions || [];
84
- if (!list) return;
85
- const q = String(query || "").toLowerCase();
86
- const filtered = options.map((opt, index) => ({
87
- opt,
88
- index,
89
- label: typeof opt === "string" ? opt : opt.label,
90
- value: typeof opt === "string" ? opt : opt.value,
91
- })).filter((item) => !q || String(item.label).toLowerCase().includes(q));
92
- this._comboboxFiltered = filtered;
93
- const rowHeight = 32;
94
- const windowSize = 20;
95
- const overscan = 6;
96
- const oldScrollTop = list.scrollTop;
97
- const start = this._comboboxVirtual && !reset
98
- ? Math.min(Math.max(0, filtered.length - windowSize), Math.max(0, Math.floor(oldScrollTop / rowHeight) - overscan))
99
- : 0;
100
- this._comboboxWindowStart = start;
101
- const end = this._comboboxVirtual ? Math.min(filtered.length, start + windowSize + overscan * 2) : filtered.length;
102
- const selectedVals = (this.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
103
- list.innerHTML = "";
104
- const addSpacer = (height) => {
105
- const spacer = document.createElement("li");
106
- spacer.setAttribute("aria-hidden", "true");
107
- spacer.style.blockSize = `${height}px`;
108
- list.appendChild(spacer);
109
- };
110
- if (this._comboboxVirtual) addSpacer(start * rowHeight);
111
- if (!filtered.length) {
112
- const empty = document.createElement("li");
113
- empty.className = "c-combobox__empty";
114
- empty.setAttribute("role", "status");
115
- empty.textContent = this.getAttribute("empty") || "No matches";
116
- list.appendChild(empty);
117
- }
118
- if (this.hasAttribute("multiple")) list.setAttribute("aria-multiselectable", "true");
119
- else list.removeAttribute("aria-multiselectable");
120
- filtered.slice(start, end).forEach((item) => {
121
- const li = document.createElement("li");
122
- li.className = "c-combobox__option";
123
- li.dataset.optionIndex = String(item.index);
124
- li.setAttribute("role", "option");
125
- const label = String(item.label);
126
- const q = String(query || "").toLowerCase();
127
- if (q && label.toLowerCase().includes(q)) {
128
- const idx = label.toLowerCase().indexOf(q);
129
- const before = label.slice(0, idx);
130
- const match = label.slice(idx, idx + q.length);
131
- const after = label.slice(idx + q.length);
132
- li.innerHTML = "";
133
- if (before) li.appendChild(document.createTextNode(before));
134
- const mark = document.createElement("mark");
135
- mark.className = "c-combobox__match";
136
- mark.textContent = match;
137
- li.appendChild(mark);
138
- if (after) li.appendChild(document.createTextNode(after));
139
- } else {
140
- li.textContent = label;
141
- }
142
- const isSelected = this.hasAttribute("multiple") && selectedVals.includes(String(item.value));
143
- li.setAttribute("aria-selected", String(isSelected));
144
- if (isSelected) li.classList.add("c-combobox__option--selected");
145
- list.appendChild(li);
146
- });
147
- if (this._comboboxVirtual) addSpacer(Math.max(0, filtered.length - end) * rowHeight);
148
- if (this._comboboxVirtual && !reset) list.scrollTop = oldScrollTop;
149
- }
150
- enhance() {
151
- wireCombobox(this);
152
- // Form sync (D-02): commit writes the input value; mirror it into the
153
- // form association so the host actually submits.
154
- if (this._internals && !this._wiredComboboxForm) {
155
- this._wiredComboboxForm = true;
156
- this._syncFormValue();
157
- this.addEventListener("contour:select", (e) => {
158
- const v = e && e.detail && (e.detail.value || e.detail.label);
159
- if (v != null) this.setAttribute("value", String(v));
160
- this._syncFormValue();
161
- });
162
- }
163
- if (!this._wiredComboboxClear) {
164
- this._wiredComboboxClear = true;
165
- this.addEventListener("click", (e) => {
166
- const btn = e.target && e.target.closest ? e.target.closest(".c-combobox__clear") : null;
167
- if (!btn || !this.contains(btn)) return;
168
- e.preventDefault();
169
- this.removeAttribute("value");
170
- const input = this.querySelector(".c-combobox__input");
171
- if (input) input.value = "";
172
- this._syncFormValue();
173
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { name: this.getAttribute("name"), value: null, checked: null } }));
174
- });
175
- }
176
- }
177
- }
178
- define("contour-combobox", ContourCombobox);
179
- /**
180
- * Field: a labelled form control wrapper. Renders an `<input>`/`<textarea>`/
181
- * `<select>` (or adopts an authored one), associates a label via `for`/`id`,
182
- * and attaches hint and error text with `aria-describedby`. Drives inline
183
- * validation on blur (`aria-invalid`, `is-invalid`) and keeps the form value in
184
- * sync via `_internals.setFormValue`. Emits `contour:input` / `contour:change`.
185
- */
186
- class ContourField extends ContourBase {
187
- static get observed() { return ["label", "hint", "error", "placeholder", "type", "required"]; }
188
- 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 } }; }
190
- render() {
191
- this.classList.add("c-field");
192
- const label = this.getAttribute("label");
193
- const hint = this.getAttribute("hint");
194
- const error = this.getAttribute("error");
195
- const placeholder = this.getAttribute("placeholder") || "";
196
- if (label) {
197
- const lbl = this.ensure(".c-field__label", () => { const el = document.createElement("label"); el.className = "c-field__label"; return el; });
198
- lbl.textContent = label;
199
- } else {
200
- const lbl = this.querySelector(".c-field__label");
201
- if (lbl) lbl.remove();
202
- }
203
- const input = this.ensure("input.c-input, textarea, select", () => {
204
- const el = document.createElement("input");
205
- el.className = "c-input";
206
- return el;
207
- });
208
- input.type = this.getAttribute("type") || "text";
209
- input.placeholder = placeholder;
210
- if (!input.id) input.id = contourId("contour-field");
211
- // Associate the label with the input so the control is labelled.
212
- const lbl = this.querySelector(".c-field__label");
213
- if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); input.setAttribute("aria-label", lbl.textContent); }
214
- if (hint) {
215
- const h = this.ensure(".c-field__hint", () => { const el = document.createElement("span"); el.className = "c-field__hint"; return el; });
216
- h.textContent = hint;
217
- } else {
218
- const h = this.querySelector(".c-field__hint");
219
- if (h) h.remove();
220
- }
221
- if (error) {
222
- const e = this.ensure(".c-field__error", () => { const el = document.createElement("span"); el.className = "c-field__error"; return el; });
223
- e.textContent = error;
224
- } else {
225
- const e = this.querySelector(".c-field__error");
226
- if (e) e.remove();
227
- }
228
- // ARIA: link the input to its hint and its error message (parity with the
229
- // shadow layer's bootstrap). The ids are generated so a screen reader does
230
- // not hear one message without the other.
231
- const hintEl = this.querySelector(".c-field__hint");
232
- const errEl = this.querySelector(".c-field__error");
233
- const describedBy = [];
234
- if (hintEl) { if (!hintEl.id) hintEl.id = contourId("hint"); describedBy.push(hintEl.id); }
235
- if (errEl) { if (!errEl.id) errEl.id = contourId("err"); describedBy.push(errEl.id); }
236
- if (describedBy.length) input.setAttribute("aria-describedby", describedBy.join(" "));
237
- if (this.hasAttribute("required")) input.setAttribute("aria-required", "true");
238
- }
239
- }
240
- ContourField.prototype.enhance = function() {
241
- if (this._wiredField) return;
242
- this._wiredField = true;
243
- const sync = () => {
244
- const input = this.querySelector("input, textarea, select");
245
- if (!input || !this._internals) return;
246
- this._internals.setFormValue(input.value);
247
- };
248
- this.addEventListener("input", (e) => {
249
- const input = this.querySelector("input, textarea, select");
250
- if (!input || e.target !== input) return;
251
- sync();
252
- this._emitForm("contour:input");
253
- });
254
- this.addEventListener("change", (e) => {
255
- const input = this.querySelector("input, textarea, select");
256
- if (!input || e.target !== input) return;
257
- sync();
258
- this._emitForm("contour:change");
259
- });
260
- // Inline validation (BY2-U6): on blur, reflect validity on the input via
261
- // aria-invalid and toggle the error/success state. The CSS already paints
262
- // the invalid ring (components.css aria-invalid rules); this just drives it.
263
- this.addEventListener("blur", (e) => {
264
- const input = this.querySelector("input, textarea, select");
265
- if (!input || e.target !== input) return;
266
- const valid = input.checkValidity();
267
- if (valid) {
268
- input.setAttribute("aria-invalid", "false");
269
- this.classList.remove("is-invalid");
270
- this.removeAttribute("data-invalid");
271
- } else {
272
- input.setAttribute("aria-invalid", "true");
273
- this.classList.add("is-invalid");
274
- 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);
283
- }
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
- }
288
- }
289
- sync();
290
- }, true);
291
- sync();
292
- };
293
- define("contour-field", ContourField);
294
-
295
- /**
296
- * Field-group: a grouped field with a shared label, optional hint and error
297
- * text. Sets `role="group"` and `aria-required` when required; toggles
298
- * `is-error` when an error is present. Child fields are labelled by the group.
299
- */
300
- class ContourFieldGroup extends ContourBase {
301
- static get observed() { return ["label", "hint", "error", "required"]; }
302
- static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, required: { attribute: "required", type: Boolean } }; }
303
- render() {
304
- this.classList.add("c-field-group");
305
- this.setAttribute("role", "group");
306
- const label = this.getAttribute("label");
307
- if (label) {
308
- const lbl = this.ensure(".c-field-group__label", () => { const el = document.createElement("div"); el.className = "c-field-group__label"; return el; });
309
- lbl.textContent = label;
310
- } else {
311
- const lbl = this.querySelector(".c-field-group__label");
312
- if (lbl) lbl.remove();
313
- }
314
- const hint = this.getAttribute("hint");
315
- if (hint) {
316
- const h = this.ensure(".c-field-group__hint", () => { const el = document.createElement("span"); el.className = "c-field-group__hint"; return el; });
317
- h.textContent = hint;
318
- } else {
319
- const h = this.querySelector(".c-field-group__hint");
320
- if (h) h.remove();
321
- }
322
- const error = this.getAttribute("error");
323
- if (error) {
324
- const e = this.ensure(".c-field-group__error", () => { const el = document.createElement("span"); el.className = "c-field-group__error"; return el; });
325
- e.textContent = error;
326
- } else {
327
- const e = this.querySelector(".c-field-group__error");
328
- if (e) e.remove();
329
- }
330
- if (error) this.classList.add("is-error"); else this.classList.remove("is-error");
331
- if (this.hasAttribute("required")) this.setAttribute("aria-required", "true");
332
- else this.removeAttribute("aria-required");
333
- }
334
- enhance() {
335
- if (this._wiredFieldGroup) return;
336
- this._wiredFieldGroup = true;
337
- }
338
- }
339
- define("contour-field-group", ContourFieldGroup);
340
-
341
- /**
342
- * Form: a form wrapper with submission state and a validation summary. Adds
343
- * `is-submitting` and disables the submit button while `submitting` is set.
344
- * On invalid submit, prevents default and renders a `role="alert"` summary
345
- * listing the invalid fields. Emits `contour:submit` on valid submit.
346
- */
347
- 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" } }; }
350
- render() {
351
- this.classList.add("c-form");
352
- if (this.hasAttribute("submitting")) this.classList.add("is-submitting"); else this.classList.remove("is-submitting");
353
- const summaryText = this.getAttribute("summary") || this.getAttribute("error");
354
- let summary = this.querySelector(".c-form__summary");
355
- if (summaryText) {
356
- if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
357
- summary.textContent = summaryText;
358
- summary.removeAttribute("hidden");
359
- } else if (summary) {
360
- summary.setAttribute("hidden", "");
361
- }
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");
366
- }
367
- }
368
- enhance() {
369
- if (this._wiredForm) return;
370
- this._wiredForm = true;
371
- this.addEventListener("submit", (e) => {
372
- const form = e.target;
373
- if (form && typeof form.checkValidity === "function" && !form.checkValidity()) {
374
- e.preventDefault();
375
- const invalid = Array.from(form.querySelectorAll(":invalid"));
376
- 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
- let summary = this.querySelector(".c-form__summary");
379
- 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");
381
- summary.removeAttribute("hidden");
382
- return;
383
- }
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 } }));
389
- });
390
- }
391
- }
392
- define("contour-form", ContourForm);
393
-
394
- /**
395
- * Range: a native `<input type=range>` wrapper with optional dual-handle range
396
- * mode (`range`, `low`, `high`) and a sparkline canvas (`sparkline`). Form
397
- * associated; emits `contour:input` / `contour:change` with the current value
398
- * (or `{low, high}` in range mode). Renders a `--fill` custom property for the
399
- * filled track.
400
- */
401
- class ContourRange extends ContourBase {
402
- static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help"]; }
403
- 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" } }; }
405
- render() {
406
- this.classList.add("c-range");
407
- const min = this.getAttribute("min") || "0";
408
- const max = this.getAttribute("max") || "100";
409
- const rangeMode = this.hasAttribute("range") || this.hasAttribute("low") || this.hasAttribute("high");
410
- // sparkline canvas
411
- const spark = this.getAttribute("sparkline");
412
- if (spark) {
413
- let canvas = this.querySelector(".c-range__sparkline");
414
- if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-range__sparkline"; canvas.setAttribute("part", "sparkline-canvas"); this.insertBefore(canvas, this.firstChild); }
415
- } else {
416
- const c = this.querySelector(".c-range__sparkline");
417
- if (c) c.remove();
418
- }
419
- if (rangeMode) {
420
- // remove single input if present
421
- const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
422
- // keep generic input? We'll use two named inputs
423
- 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); }
425
- 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); }
427
- lowInput.min = min; lowInput.max = max;
428
- highInput.min = min; highInput.max = max;
429
- const lowVal = this.getAttribute("low") || min;
430
- const highVal = this.getAttribute("high") || max;
431
- if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
432
- else { lowInput.value = lowVal; this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
433
- if (this._rangeUserHigh !== null && this._rangeAttrHighAtDirty === (this.getAttribute("high") || max)) highInput.value = this._rangeUserHigh;
434
- else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
435
- const label = this.getAttribute("label");
436
- if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
437
- } 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; });
441
- // ensure class
442
- input.className = "c-range";
443
- input.type = "range";
444
- input.min = min;
445
- input.max = max;
446
- const attrVal = this.getAttribute("value") || "50";
447
- if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
448
- input.value = this._rangeUserValue;
449
- } else {
450
- input.value = attrVal;
451
- this._rangeUserValue = null;
452
- this._rangeAttrAtDirty = null;
453
- }
454
- const label = this.getAttribute("label");
455
- if (label) input.setAttribute("aria-label", label);
456
- else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
457
- const updateFill = () => {
458
- const mn = Number(input.min) || 0;
459
- const mx = Number(input.max) || 100;
460
- const val = Number(input.value) || 0;
461
- const pct = mx > mn ? ((val - mn) / (mx - mn)) * 100 : 0;
462
- input.style.setProperty("--fill", pct + "%");
463
- };
464
- updateFill();
465
- if (!input._fillWired) {
466
- input._fillWired = true;
467
- input.addEventListener("input", updateFill);
468
- }
469
- }
470
- }
471
- }
472
- // patch enhance onto ContourRange
473
- const _origRangeRender = ContourRange.prototype.render;
474
- ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
475
- if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
476
- if (name === "low") { this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
477
- if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
478
- return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
479
- };
480
- ContourRange.prototype.enhance = function() {
481
- if (this._wiredRange) return;
482
- 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
- };
492
- this.addEventListener("input", (e) => {
493
- const low = this.querySelector("input.c-range__low");
494
- const high = this.querySelector("input.c-range__high");
495
- const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
496
- if (low && high && (e.target === low || e.target === high)) {
497
- this._rangeUserLow = low.value;
498
- this._rangeUserHigh = high.value;
499
- this._rangeAttrLowAtDirty = this.getAttribute("low") || (this.getAttribute("min") || "0");
500
- this._rangeAttrHighAtDirty = this.getAttribute("high") || (this.getAttribute("max") || "100");
501
- sync();
502
- this._emitForm("contour:input", { low: Number(low.value), high: Number(high.value) });
503
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
504
- } else if (single && e.target === single) {
505
- this._rangeUserValue = single.value;
506
- this._rangeAttrAtDirty = this.getAttribute("value") || "50";
507
- sync();
508
- this._emitForm("contour:input");
509
- }
510
- });
511
- this.addEventListener("change", (e) => {
512
- const low = this.querySelector("input.c-range__low");
513
- const high = this.querySelector("input.c-range__high");
514
- const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
515
- if (low && high && (e.target === low || e.target === high)) {
516
- sync();
517
- this._emitForm("contour:change", { low: Number(low.value), high: Number(high.value) });
518
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
519
- } else if (single && e.target === single) {
520
- sync();
521
- this._emitForm("contour:change");
522
- }
523
- });
524
- sync();
525
- };
526
- define("contour-range", ContourRange);
527
- /**
528
- * Switch: a `role="switch"` checkbox control with label, required, disabled,
529
- * 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.
532
- */
533
- class ContourSwitch extends ContourBase {
534
- static get observed() { return ["label", "required", "checked", "disabled", "error", "help"]; }
535
- static get properties() { return { label: { attribute: "label" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
536
- static get formAssociated() { return true; }
537
- render() {
538
- this.classList.add("c-switch");
539
- const label = this.getAttribute("label");
540
- // The guide's control is `label.c-switch` wrapping `input.c-switch__input`
541
- // and a bare span of text; the sheet paints the track on the input itself.
542
- const input = this.ensure("input.c-switch__input", () => { const el = document.createElement("input"); el.className = "c-switch__input"; el.type = "checkbox"; return el; });
543
- input.checked = this.hasAttribute("checked");
544
- input.setAttribute("role", "switch");
545
- input.setAttribute("aria-checked", String(input.checked));
546
- this._setCustomState("data-checked", input.checked);
547
- if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
548
- else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
549
- const err = this.getAttribute("error");
550
- const help = this.getAttribute("help");
551
- let msg = this.querySelector(".c-switch__message");
552
- if (err || help) {
553
- if (!msg) { msg = document.createElement("div"); msg.className = "c-switch__message"; this.appendChild(msg); }
554
- msg.textContent = err || help || "";
555
- msg.classList.toggle("c-switch__message--error", !!err);
556
- } else if (msg) { msg.remove(); }
557
- 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
- }
566
- if (label) {
567
- 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; })();
569
- txt.textContent = label;
570
- }
571
- }
572
- enhance() {
573
- const input = this.querySelector("input");
574
- if (input && this._internals) {
575
- input.setAttribute("aria-checked", String(input.checked));
576
- this._setCustomState("data-checked", input.checked);
577
- this._internals.setFormValue(input.checked ? (input.value || "on") : null);
578
- this._syncValidity(this.hasAttribute("required") && !input.checked);
579
- }
580
- if (this._wiredSwitch) return;
581
- this._wiredSwitch = true;
582
- this.addEventListener("change", (e) => {
583
- const inp = this.querySelector("input");
584
- if (!inp || e.target !== inp || !this._internals) return;
585
- inp.setAttribute("aria-checked", String(inp.checked));
586
- this._setCustomState("data-checked", inp.checked);
587
- this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
588
- this._emitForm("contour:change");
589
- this._syncValidity(this.hasAttribute("required") && !inp.checked);
590
- });
591
- }
592
- }
593
- define("contour-switch", ContourSwitch);
594
- /**
595
- * 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.
599
- */
600
- class ContourCheck extends ContourBase {
601
- static get observed() { return ["label", "name", "value", "required", "type", "checked", "disabled", "error", "help"]; }
602
- static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, type: { attribute: "type" }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
603
- static get formAssociated() { return true; }
604
- render() {
605
- this.classList.add("c-check");
606
- const label = this.getAttribute("label");
607
- 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
- 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
- }
617
- if (label) {
618
- 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; })();
620
- txt.textContent = label;
621
- }
622
- if (this.hasAttribute("name")) input.name = this.getAttribute("name");
623
- if (this.hasAttribute("value")) input.value = this.getAttribute("value");
624
- if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
625
- else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
626
- const err = this.getAttribute("error");
627
- const help = this.getAttribute("help");
628
- let msg = this.querySelector(".c-check__message");
629
- if (err || help) {
630
- if (!msg) { msg = document.createElement("div"); msg.className = "c-check__message"; this.appendChild(msg); }
631
- msg.textContent = err || help || "";
632
- msg.classList.toggle("c-check__message--error", !!err);
633
- } else if (msg) { msg.remove(); }
634
- if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
635
- }
636
- enhance() {
637
- const input = this.querySelector("input");
638
- if (input && this._internals) {
639
- this._setCustomState("data-checked", input.checked);
640
- this._internals.setFormValue(input.checked ? (input.value || "on") : null);
641
- this._syncValidity(this.hasAttribute("required") && !input.checked);
642
- }
643
- if (this._wiredCheck) return;
644
- this._wiredCheck = true;
645
- this.addEventListener("change", (e) => {
646
- const inp = this.querySelector("input");
647
- if (!inp || e.target !== inp || !this._internals) return;
648
- this._setCustomState("data-checked", inp.checked);
649
- this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
650
- this._emitForm("contour:change");
651
- this._syncValidity(this.hasAttribute("required") && !inp.checked);
652
- });
653
- }
654
- }
655
- define("contour-check", ContourCheck);
656
- /**
657
- * Radio: a radio button with label, name, value, required, checked, disabled,
658
- * error and help states. Form associated; unchecking clears the stale FormData
659
- * entry. Emits `contour:change` on toggle.
660
- */
661
- class ContourRadio extends ContourBase {
662
- static get observed() { return ["label", "name", "value", "required", "checked", "disabled", "error", "help"]; }
663
- static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
664
- static get formAssociated() { return true; }
665
- render() {
666
- this.classList.add("c-radio");
667
- const label = this.getAttribute("label");
668
- const input = this.ensure("input.c-radio__input", () => { const el = document.createElement("input"); el.className = "c-radio__input"; el.type = "radio"; return el; });
669
- input.checked = this.hasAttribute("checked");
670
- if (this.hasAttribute("name")) input.name = this.getAttribute("name");
671
- if (this.hasAttribute("value")) input.value = this.getAttribute("value");
672
- if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
673
- else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
674
- const err = this.getAttribute("error");
675
- const help = this.getAttribute("help");
676
- let msg = this.querySelector(".c-radio__message");
677
- if (err || help) {
678
- if (!msg) { msg = document.createElement("div"); msg.className = "c-radio__message"; this.appendChild(msg); }
679
- msg.textContent = err || help || "";
680
- msg.classList.toggle("c-radio__message--error", !!err);
681
- } else if (msg) { msg.remove(); }
682
- if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
683
- if (label) {
684
- input.setAttribute("aria-label", label);
685
- const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
686
- txt.textContent = label;
687
- }
688
- }
689
- enhance() {
690
- const input = this.querySelector("input");
691
- if (input && this._internals) {
692
- this._setCustomState("data-checked", input.checked);
693
- this._internals.setFormValue(input.checked ? (input.value || "on") : null);
694
- this._syncValidity(this.hasAttribute("required") && !input.checked);
695
- }
696
- if (this._wiredRadio) return;
697
- this._wiredRadio = true;
698
- this.addEventListener("change", (e) => {
699
- const inp = this.querySelector("input");
700
- if (!inp || e.target !== inp || !this._internals) return;
701
- // Unchecking (group movement) must clear the stale FormData entry,
702
- // not leave it behind beside the new selection.
703
- this._setCustomState("data-checked", inp.checked);
704
- this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
705
- this._emitForm("contour:change");
706
- this._syncValidity(this.hasAttribute("required") && !inp.checked);
707
- });
708
- }
709
- }
710
- define("contour-radio", ContourRadio);
711
- /**
712
- * Select: a native `<select>` wrapper populated from a JSON `options` attribute
713
- * (with optgroup support) or an authored `<select>`. Supports label, placeholder,
714
- * required, disabled, error and help. Form associated; emits `contour:change`.
715
- */
716
- 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" } }; }
719
- static get formAssociated() { return true; }
720
- render() {
721
- this.classList.add("c-select");
722
- const options = this.getAttribute("options");
723
- // Slot composition: an authored <select> wins over the JSON attribute.
724
- const generated = new Set(this._contourGenerated || []);
725
- const authored = Array.from(this.children).filter((n) => !generated.has(n));
726
- if (options && !authored.length) {
727
- try {
728
- const parsed = JSON.parse(options);
729
- const select = this.ensure("select.c-select", () => { const el = document.createElement("select"); el.className = "c-select"; return el; });
730
- select.innerHTML = "";
731
- const label = this.getAttribute("label");
732
- if (label) {
733
- select.setAttribute("aria-label", label);
734
- }
735
- const placeholder = this.getAttribute("placeholder");
736
- if (placeholder) {
737
- const ph = document.createElement("option");
738
- ph.value = "";
739
- ph.textContent = placeholder;
740
- ph.disabled = true;
741
- ph.selected = true;
742
- select.appendChild(ph);
743
- }
744
- // Group support.
745
- const groups = {};
746
- parsed.forEach((opt) => {
747
- const g = (typeof opt === "object" && opt !== null) ? opt.group : null;
748
- if (g) {
749
- if (!groups[g]) { groups[g] = document.createElement("optgroup"); groups[g].label = g; select.appendChild(groups[g]); }
750
- const option = document.createElement("option");
751
- option.value = typeof opt === "string" ? opt : opt.value;
752
- option.textContent = typeof opt === "string" ? opt : opt.label;
753
- groups[g].appendChild(option);
754
- } else {
755
- const option = document.createElement("option");
756
- option.value = typeof opt === "string" ? opt : opt.value;
757
- option.textContent = typeof opt === "string" ? opt : opt.label;
758
- select.appendChild(option);
759
- }
760
- });
761
- if (select.parentNode !== this) this.appendChild(select);
762
- this.classList.remove("c-select");
763
- select.classList.add("c-select");
764
- } catch (e) { /* keep existing */ }
765
- }
766
- // Ensure authored select gets c-select styling.
767
- const authoredSel = this.querySelector("select");
768
- if (authoredSel && !authoredSel.classList.contains("c-select")) {
769
- authoredSel.classList.add("c-select");
770
- this.classList.remove("c-select");
771
- }
772
- // Disabled / error / help contract (applies to authored or generated select).
773
- const sel = this.querySelector("select");
774
- if (sel) {
775
- if (this.hasAttribute("disabled")) { sel.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
776
- else { sel.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
777
- }
778
- // Label (applies to both JSON and authored options).
779
- const label = this.getAttribute("label");
780
- if (label) {
781
- let lbl = this.querySelector("label.c-select__label");
782
- if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; this.insertBefore(lbl, sel || this.firstChild); }
783
- lbl.textContent = label;
784
- if (sel) sel.setAttribute("aria-label", label);
785
- }
786
- const err = this.getAttribute("error");
787
- const help = this.getAttribute("help");
788
- let msg = this.querySelector(".c-select__message");
789
- if (err || help) {
790
- if (!msg) { msg = document.createElement("div"); msg.className = "c-select__message"; this.appendChild(msg); }
791
- msg.textContent = err || help || "";
792
- msg.classList.toggle("c-select__message--error", !!err);
793
- } else if (msg) { msg.remove(); }
794
- if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
795
- }
796
- 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
- }
802
- if (this._wiredSelect) return;
803
- this._wiredSelect = true;
804
- this.addEventListener("change", (e) => {
805
- const sel = this.querySelector("select");
806
- if (!sel || e.target !== sel || !this._internals) return;
807
- this._internals.setFormValue(sel.value);
808
- this._emitForm("contour:change");
809
- this._syncValidity(this.hasAttribute("required") && !sel.value);
810
- });
811
- }
812
- }
813
- define("contour-select", ContourSelect);
814
- /**
815
- * Version: a `<select>` of version options from a JSON `options` attribute,
816
- * with `selected` support per option. Form associated; emits `contour:change`.
817
- */
818
- class ContourVersion extends ContourBase {
819
- static get observed() { return ["options"]; }
820
- static get formAssociated() { return true; }
821
- static get properties() { return { options: { attribute: "options" } }; }
822
- render() {
823
- this.classList.add("c-version");
824
- const options = this.getAttribute("options");
825
- const generated = new Set(this._contourGenerated || []);
826
- const authored = Array.from(this.children).filter((n) => !generated.has(n));
827
- if (options && !authored.length) {
828
- try {
829
- const parsed = JSON.parse(options);
830
- const select = this.ensure("select.c-version", () => { const el = document.createElement("select"); el.className = "c-version"; return el; });
831
- select.innerHTML = "";
832
- if (!select.hasAttribute("aria-label")) select.setAttribute("aria-label", "Version");
833
- parsed.forEach((opt) => {
834
- const option = document.createElement("option");
835
- if (typeof opt === "string") { option.value = opt; option.textContent = opt; }
836
- else { option.value = opt.value || opt.label; option.textContent = opt.label || opt.value; if (opt.selected) option.selected = true; }
837
- select.appendChild(option);
838
- });
839
- if (select.parentNode !== this) this.appendChild(select);
840
- this.classList.remove("c-version");
841
- select.classList.add("c-version");
842
- } catch (e) { /* keep existing */ }
843
- }
844
- }
845
- enhance() {
846
- if (this._wiredVersion) return;
847
- this._wiredVersion = true;
848
- const sync = () => {
849
- const select = this.querySelector("select");
850
- if (!select || !this._internals) return;
851
- this._internals.setFormValue(select.value);
852
- };
853
- this.addEventListener("change", (e) => {
854
- const select = this.querySelector("select");
855
- if (!select || e.target !== select) return;
856
- sync();
857
- this._emitForm("contour:change");
858
- });
859
- sync();
860
- }
861
- }
862
- define("contour-version", ContourVersion);
863
- /**
864
- * Textarea: a `<textarea>` wrapper with placeholder, required, disabled, error
865
- * and help states. Form associated; emits `contour:input` / `contour:change`.
866
- */
867
- 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" } }; }
870
- static get formAssociated() { return true; }
871
- render() {
872
- const ta = this.ensure("textarea", () => { const el = document.createElement("textarea"); el.className = "c-textarea"; return el; });
873
- ta.className = "c-textarea";
874
- ta.placeholder = this.getAttribute("placeholder") || "";
875
- if (this.hasAttribute("required")) ta.setAttribute("required", "");
876
- else ta.removeAttribute("required");
877
- if (this.hasAttribute("disabled")) { ta.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
878
- else { ta.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
879
- const err = this.getAttribute("error");
880
- const help = this.getAttribute("help");
881
- let msg = this.querySelector(".c-textarea__message");
882
- if (err || help) {
883
- if (!msg) { msg = document.createElement("div"); msg.className = "c-textarea__message"; this.appendChild(msg); }
884
- msg.textContent = err || help || "";
885
- msg.classList.toggle("c-textarea__message--error", !!err);
886
- } else if (msg) { msg.remove(); }
887
- if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
888
- }
889
- enhance() {
890
- const ta = this.querySelector("textarea");
891
- if (ta && this._internals) {
892
- this._internals.setFormValue(ta.value);
893
- this._syncValidity(this.hasAttribute("required") && !ta.value.trim());
894
- }
895
- if (this._wiredTextarea) return;
896
- this._wiredTextarea = true;
897
- this.addEventListener("input", (e) => {
898
- const t = this.querySelector("textarea");
899
- if (!t || e.target !== t || !this._internals) return;
900
- this._internals.setFormValue(t.value);
901
- this._emitForm("contour:input");
902
- this._syncValidity(this.hasAttribute("required") && !t.value.trim());
903
- });
904
- this.addEventListener("change", (e) => {
905
- const t = this.querySelector("textarea");
906
- if (!t || e.target !== t || !this._internals) return;
907
- this._internals.setFormValue(t.value);
908
- this._emitForm("contour:change");
909
- this._syncValidity(this.hasAttribute("required") && !t.value.trim());
910
- });
911
- }
912
- }
913
- define("contour-textarea", ContourTextarea);
914
- /**
915
- * Input: an `<input>` wrapper with type, placeholder, required, value, disabled,
916
- * error and help states. Form associated; emits `contour:input` / `contour:change`.
917
- */
918
- 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" } }; }
921
- static get formAssociated() { return true; }
922
- render() {
923
- this.classList.add("c-input");
924
- const input = this.ensure("input", () => { const el = document.createElement("input"); el.className = "c-input"; return el; });
925
- input.className = "c-input";
926
- input.type = this.getAttribute("type") || "text";
927
- input.placeholder = this.getAttribute("placeholder") || "";
928
- let label = this.getAttribute("label");
929
- if (!label) {
930
- const field = this.closest("contour-field");
931
- if (field) label = field.getAttribute("label");
932
- }
933
- if (label) input.setAttribute("aria-label", label);
934
- else if (!input.getAttribute("aria-label")) input.setAttribute("aria-label", "Input");
935
- if (this.hasAttribute("value")) input.value = this.getAttribute("value");
936
- if (this.hasAttribute("required")) input.setAttribute("required", "");
937
- else input.removeAttribute("required");
938
- if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
939
- else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
940
- // Error/help text
941
- const err = this.getAttribute("error");
942
- const help = this.getAttribute("help");
943
- let msg = this.querySelector(".c-input__message");
944
- if (err || help) {
945
- if (!msg) { msg = document.createElement("div"); msg.className = "c-input__message"; this.appendChild(msg); }
946
- msg.textContent = err || help || "";
947
- msg.classList.toggle("c-input__message--error", !!err);
948
- } else if (msg) { msg.remove(); }
949
- if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
950
- }
951
- enhance() {
952
- const input = this.querySelector("input");
953
- if (input && this._internals) {
954
- this._internals.setFormValue(input.value);
955
- this._syncValidity(this.hasAttribute("required") && !input.value.trim());
956
- }
957
- if (this._wiredInput) return;
958
- this._wiredInput = true;
959
- this.addEventListener("input", (e) => {
960
- const inp = this.querySelector("input");
961
- if (!inp || e.target !== inp || !this._internals) return;
962
- this._internals.setFormValue(inp.value);
963
- this._emitForm("contour:input");
964
- this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
965
- });
966
- this.addEventListener("change", (e) => {
967
- const inp = this.querySelector("input");
968
- if (!inp || e.target !== inp || !this._internals) return;
969
- this._internals.setFormValue(inp.value);
970
- this._emitForm("contour:change");
971
- this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
972
- });
973
- }
974
- }
975
- define("contour-input", ContourInputFull);
976
- /**
977
- * InputGroup: a text input with an optional search icon, a clear (×) affordance
978
- * and a submit (→) affordance. Attributes: `label`, `placeholder`, `clearable`,
979
- * `submit`. Emits `contour:change` (bubbles, composed) with `{ value: "" }` on
980
- * clear.
981
- */
982
- 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 } }; }
985
- render() {
986
- this.classList.add("c-input-group");
987
- 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
- const input = this.ensure("input.c-input", () => { const el = document.createElement("input"); el.className = "c-input"; el.type = "text"; return el; });
989
- input.placeholder = this.getAttribute("placeholder") || this.getAttribute("label") || "";
990
- // Clear affordance.
991
- const oldClear = this.querySelector(".c-input-group__clear");
992
- if (oldClear) oldClear.remove();
993
- if (this.hasAttribute("clearable")) {
994
- const btn = document.createElement("button");
995
- btn.className = "c-input-group__clear";
996
- btn.type = "button";
997
- btn.setAttribute("aria-label", "Clear");
998
- btn.textContent = "×";
999
- this.appendChild(btn);
1000
- }
1001
- // Submit affordance.
1002
- const oldSubmit = this.querySelector(".c-input-group__submit");
1003
- if (oldSubmit) oldSubmit.remove();
1004
- if (this.hasAttribute("submit")) {
1005
- const btn = document.createElement("button");
1006
- btn.className = "c-input-group__submit";
1007
- btn.type = "submit";
1008
- btn.setAttribute("aria-label", "Submit");
1009
- btn.textContent = "→";
1010
- this.appendChild(btn);
1011
- }
1012
- }
1013
- enhance() {
1014
- if (this._wiredInputGroup) return;
1015
- this._wiredInputGroup = true;
1016
- this.addEventListener("click", (e) => {
1017
- const clear = e.target && e.target.closest ? e.target.closest(".c-input-group__clear") : null;
1018
- if (clear && this.contains(clear)) {
1019
- e.preventDefault();
1020
- const input = this.querySelector("input.c-input");
1021
- if (input) { input.value = ""; input.focus(); }
1022
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: "" } }));
1023
- }
1024
- });
1025
- }
1026
- }
1027
- define("contour-input-group", ContourInputGroup);
1028
- /**
1029
- * RadioList: a `role="radiogroup"` of radio options from a JSON `items`
1030
- * attribute (or remote `src`). Supports roving tabindex, Home/End navigation,
1031
- * RTL, empty/loading/error states, and `formResetCallback` that re-renders from
1032
- * the authored `items` payload. Form associated; emits `contour:change`.
1033
- */
1034
- class ContourRadioList extends ContourBase {
1035
- static get observed() { return ["items", "name", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1036
- static get properties() { return { items: { attribute: "items" }, name: { attribute: "name" }, src: { attribute: "src" } }; }
1037
- static get formAssociated() { return true; }
1038
- render() {
1039
- this.classList.add("c-radio-list");
1040
- this.setAttribute("role", "radiogroup");
1041
- if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("name") || "Options");
1042
- wireStates(this);
1043
- loadRemote(this, "items");
1044
- if (renderStates(this, "radio-list")) return;
1045
- const items = remoteData(this, "items");
1046
- Array.from(this.querySelectorAll("label.c-radio")).forEach((l) => l.remove());
1047
- if (items) {
1048
- try {
1049
- const parsed = JSON.parse(items);
1050
- const groupName = this.getAttribute("name") || contourId("radio-list");
1051
- parsed.forEach((it) => {
1052
- const lbl = document.createElement("label");
1053
- lbl.className = "c-radio";
1054
- const input = document.createElement("input");
1055
- input.type = "radio";
1056
- input.className = "c-radio__input";
1057
- input.name = groupName;
1058
- input.tabIndex = -1;
1059
- if (typeof it === "string") { input.value = it; lbl.appendChild(input); lbl.appendChild(document.createTextNode(" " + it)); }
1060
- else { input.value = it.value || it.label; if (it.checked) input.checked = true; lbl.appendChild(input); const span = document.createElement("span"); span.textContent = it.label || it.value; lbl.appendChild(span); }
1061
- this.appendChild(lbl);
1062
- });
1063
- // Roving tabindex: only the checked item (or the first) is in the tab
1064
- // order, exactly like a native radiogroup.
1065
- const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
1066
- const checked = radios.find((r) => r.checked) || radios[0];
1067
- if (checked) checked.tabIndex = 0;
1068
- } catch (e) { /* keep existing */ }
1069
- } else {
1070
- renderEmpty(this, "radio-list");
1071
- }
1072
- }
1073
- enhance() {
1074
- const sync = () => {
1075
- if (!this._internals) return;
1076
- const checked = this.querySelector("input.c-radio__input:checked");
1077
- this._internals.setFormValue(checked ? checked.value : null);
1078
- };
1079
- sync();
1080
- if (this._wiredRadioList) return;
1081
- this._wiredRadioList = true;
1082
- // Form life + group semantics, delegated on the host (rule 12): the
1083
- // inputs are rebuilt on every render, so node-bound listeners would die.
1084
- this.addEventListener("change", (e) => {
1085
- const input = e.target && e.target.closest ? e.target.closest("input.c-radio__input") : null;
1086
- if (!input || !this.contains(input)) return;
1087
- sync();
1088
- this._emitForm("contour:change");
1089
- });
1090
- this.addEventListener("keydown", (e) => {
1091
- const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
1092
- if (!radios.length) return;
1093
- const idx = radios.indexOf(e.target);
1094
- if (idx === -1) return;
1095
- const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
1096
- let next = -1;
1097
- if (e.key === "ArrowDown") next = (idx + 1) % radios.length;
1098
- else if (e.key === "ArrowUp") next = (idx - 1 + radios.length) % radios.length;
1099
- else if (e.key === "ArrowRight") next = rtl ? (idx - 1 + radios.length) % radios.length : (idx + 1) % radios.length;
1100
- else if (e.key === "ArrowLeft") next = rtl ? (idx + 1) % radios.length : (idx - 1 + radios.length) % radios.length;
1101
- else if (e.key === "Home") next = 0;
1102
- else if (e.key === "End") next = radios.length - 1;
1103
- else return;
1104
- e.preventDefault();
1105
- const before = radios.find((r) => r.checked);
1106
- for (const r of radios) r.tabIndex = -1;
1107
- radios[next].tabIndex = 0;
1108
- radios[next].checked = true;
1109
- radios[next].focus();
1110
- sync();
1111
- // Native radio groups fire change when an arrow moves the selection;
1112
- // wrap-around onto the same radio is not a change.
1113
- if (before !== radios[next]) this._emitForm("contour:change");
1114
- });
1115
- }
1116
- formResetCallback() {
1117
- // The authored default lives in the `items` payload (`it.checked`), not
1118
- // in checked attributes on generated radios, so re-render from the data
1119
- // rather than blanking every selection like the generic base reset.
1120
- if (this._contourAuthored) this.requestRender();
1121
- }
1122
- }
1123
- define("contour-radio-list", ContourRadioList);
2
+ * Forms family barrel — the form-control web components, split into semantic
3
+ * fragments. Importing this module registers every form component (the
4
+ * fragments are side-effectful: each defines its own custom elements). The
5
+ * build concatenates the fragments for the IIFE/ESM bundles; this barrel keeps
6
+ * `contour-ds/wc/forms.mjs` working for consumers who import the family by name.
7
+ */
8
+ import "./forms-field.mjs";
9
+ import "./forms-controls.mjs";
10
+ import "./forms-input.mjs";
11
+ import "./forms-groups.mjs";