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
@@ -0,0 +1,547 @@
1
+ import { ContourBase, define, contourId, cssLength , warnBadJson, labelText, applyLabel, onDispose } from './core.mjs';
2
+ import { wireCombobox } from './behaviours.mjs';
3
+ import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
4
+
5
+ /**
6
+ * Combobox: a filterable, keyboard-navigable listbox backed by a JSON `options`
7
+ * attribute or authored `<li>` options. Supports single and multi-select
8
+ * (`multiple`), fixed-row virtualization (`virtual`), async/remote options
9
+ * (`src`, `loading`, `error`, `retry`, `empty`, `skeleton`), a clear button and
10
+ * form association. Emits `contour:select` on commit and `contour:input` on
11
+ * filter. ArrowUp/Down/Home/End rove the cursor; Enter commits; Escape closes.
12
+ */
13
+ class ContourCombobox extends ContourBase {
14
+ static get observed() { return ["options", "items", "placeholder", "label", "value", "multiple", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "empty", "skeleton", "virtual", "disabled", "required", "name", "cache-key", "no-cache"]; }
15
+ static get formAssociated() { return true; }
16
+ static get properties() { return { options: { attribute: "options" }, items: { attribute: "items" }, 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" } }; }
17
+ render() {
18
+ this.classList.add("c-combobox");
19
+ // Authored default captured before commit; form reset restores this.
20
+ if (this._comboboxDefault === undefined) this._comboboxDefault = this.getAttribute("value");
21
+ wireStates(this);
22
+ loadRemote(this, "options");
23
+ if (renderStates(this, "combobox")) return;
24
+ const options = remoteData(this, "options") || this.getAttribute("options") || this.getAttribute("items");
25
+ // Slot composition: authored <li> wins over JSON attribute.
26
+ const authored = Array.from(this.children).filter((n) => !n.classList || (!n.classList.contains("c-combobox__input") && !n.classList.contains("c-combobox__list")));
27
+ if ((options) && !authored.length) {
28
+ try {
29
+ const parsed = options ? JSON.parse(options) : [];
30
+ this._comboboxOptions = parsed;
31
+ const input = this.ensure(".c-combobox__input", () => { const el = document.createElement("input"); el.className = "c-input c-combobox__input"; el.type = "text"; return el; });
32
+ input.type = "text";
33
+ input.placeholder = this.getAttribute("placeholder") || labelText(this, "search", "Search…");
34
+ input.setAttribute("aria-label", this.getAttribute("label") || labelText(this, "search", "Search"));
35
+ // Reflect native constraints so platform validates and FormData sees name.
36
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
37
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
38
+ if (this.hasAttribute("required")) { input.setAttribute("required", ""); input.setAttribute("aria-required", "true"); }
39
+ else { input.removeAttribute("required"); input.removeAttribute("aria-required"); }
40
+ if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
41
+ const val = this.getAttribute("value");
42
+ if (val !== null) {
43
+ // Attribute holds submitted value; field shows option label, so they can differ.
44
+ const values = String(val).split(",").map((s) => s.trim()).filter(Boolean);
45
+ const labels = values.map((v) => {
46
+ const match = parsed.find((o) => String(typeof o === "string" ? o : o.value) === v);
47
+ return match ? String(typeof match === "string" ? match : match.label) : v;
48
+ });
49
+ if (this.hasAttribute("multiple")) {
50
+ // R31-05: a multi-select must not put "Alpha,Charlie" in the
51
+ // search field — that string filters out every option. Keep the
52
+ // query empty and show the chosen labels as the placeholder.
53
+ input.value = "";
54
+ input.placeholder = labels.join(", ") || (this.getAttribute("placeholder") || labelText(this, "search", "Search…"));
55
+ } else {
56
+ const match = parsed.find((o) => String(typeof o === "string" ? o : o.value) === String(val));
57
+ input.value = match ? String(typeof match === "string" ? match : match.label) : val;
58
+ }
59
+ }
60
+ const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
61
+ list.innerHTML = "";
62
+ list.setAttribute("hidden", "");
63
+ this._comboboxVirtual = this.hasAttribute("virtual") && parsed.length > 100;
64
+ if (this._comboboxVirtual) {
65
+ list.classList.add("c-combobox__list--virtual");
66
+ list.style.maxBlockSize = "20rem";
67
+ list.style.overflow = "auto";
68
+ this._renderComboboxWindow("", true);
69
+ } else {
70
+ list.classList.remove("c-combobox__list--virtual");
71
+ list.style.maxBlockSize = "";
72
+ list.style.overflow = "";
73
+ this._renderComboboxWindow("", true);
74
+ }
75
+ } catch (e) { warnBadJson(this, "attribute", e); }
76
+ } else if (!authored.length && !options) {
77
+ renderEmpty(this, "combobox");
78
+ } else if (authored.length) {
79
+ // R31-18: authored <li> options. Build the input + list shell and adopt
80
+ // the authored <li> as options (role=option), so a consumer can write
81
+ // the list in markup instead of a JSON `options` attribute.
82
+ const input = this.ensure(".c-combobox__input", () => { const el = document.createElement("input"); el.className = "c-input c-combobox__input"; el.type = "text"; return el; });
83
+ input.type = "text";
84
+ input.placeholder = this.getAttribute("placeholder") || labelText(this, "search", "Search…");
85
+ input.setAttribute("aria-label", this.getAttribute("label") || labelText(this, "search", "Search"));
86
+ if (this.hasAttribute("required")) { input.setAttribute("required", ""); input.setAttribute("aria-required", "true"); }
87
+ else { input.removeAttribute("required"); input.removeAttribute("aria-required"); }
88
+ if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
89
+ const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
90
+ for (const li of authored) {
91
+ if (li.tagName === "LI") { list.appendChild(li); li.setAttribute("role", "option"); }
92
+ }
93
+ this._comboboxOptions = Array.from(list.querySelectorAll("li")).map((li) => ({
94
+ label: li.textContent.trim(),
95
+ value: li.dataset.value != null ? li.dataset.value : li.textContent.trim(),
96
+ }));
97
+ }
98
+
99
+ if (this.getAttribute("value")) {
100
+ this.ensure(".c-combobox__clear", () => {
101
+ const btn = document.createElement("button");
102
+ btn.className = "c-combobox__clear";
103
+ btn.type = "button";
104
+ btn.setAttribute("aria-label", labelText(this, "clear", "Clear"));
105
+ btn.textContent = "×";
106
+ return btn;
107
+ });
108
+ } else {
109
+ const btn = this.querySelector(".c-combobox__clear");
110
+ if (btn) btn.remove();
111
+ }
112
+ }
113
+ _renderComboboxWindow(query = "", reset = false) {
114
+ const list = this.querySelector(".c-combobox__list");
115
+ const options = this._comboboxOptions || [];
116
+ if (!list) return;
117
+ const q = String(query || "").toLowerCase();
118
+ const filtered = options.map((opt, index) => ({
119
+ opt,
120
+ index,
121
+ label: typeof opt === "string" ? opt : opt.label,
122
+ value: typeof opt === "string" ? opt : opt.value,
123
+ })).filter((item) => !q || String(item.label).toLowerCase().includes(q));
124
+ this._comboboxFiltered = filtered;
125
+ const rowHeight = cssLength("--combobox-row-height", 32);
126
+ const windowSize = 20;
127
+ const overscan = 6;
128
+ const oldScrollTop = list.scrollTop;
129
+ const start = this._comboboxVirtual && !reset
130
+ ? Math.min(Math.max(0, filtered.length - windowSize), Math.max(0, Math.floor(oldScrollTop / rowHeight) - overscan))
131
+ : 0;
132
+ this._comboboxWindowStart = start;
133
+ const end = this._comboboxVirtual ? Math.min(filtered.length, start + windowSize + overscan * 2) : filtered.length;
134
+ const selectedVals = (this.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
135
+ list.innerHTML = "";
136
+ const addSpacer = (height) => {
137
+ const spacer = document.createElement("li");
138
+ spacer.setAttribute("aria-hidden", "true");
139
+ spacer.style.blockSize = `${height}px`;
140
+ list.appendChild(spacer);
141
+ };
142
+ if (this._comboboxVirtual) addSpacer(start * rowHeight);
143
+ if (!filtered.length) {
144
+ const empty = document.createElement("li");
145
+ empty.className = "c-combobox__empty";
146
+ // Disabled option, not a live region: a listbox may only contain
147
+ // `option`, and `role="status"` inside one is an axe violation.
148
+ empty.setAttribute("role", "option");
149
+ empty.setAttribute("aria-disabled", "true");
150
+ empty.setAttribute("aria-selected", "false");
151
+ empty.textContent = this.getAttribute("empty") || labelText(this, "no-matches", "No matches");
152
+ list.appendChild(empty);
153
+ }
154
+ if (this.hasAttribute("multiple")) list.setAttribute("aria-multiselectable", "true");
155
+ else list.removeAttribute("aria-multiselectable");
156
+ filtered.slice(start, end).forEach((item) => {
157
+ const li = document.createElement("li");
158
+ li.className = "c-combobox__option";
159
+ li.dataset.optionIndex = String(item.index);
160
+ li.dataset.optionValue = String(item.value != null ? item.value : item.label);
161
+ li.setAttribute("role", "option");
162
+ const label = String(item.label);
163
+ const q = String(query || "").toLowerCase();
164
+ if (q && label.toLowerCase().includes(q)) {
165
+ const idx = label.toLowerCase().indexOf(q);
166
+ const before = label.slice(0, idx);
167
+ const match = label.slice(idx, idx + q.length);
168
+ const after = label.slice(idx + q.length);
169
+ li.innerHTML = "";
170
+ if (before) li.appendChild(document.createTextNode(before));
171
+ const mark = document.createElement("mark");
172
+ mark.className = "c-combobox__match";
173
+ mark.textContent = match;
174
+ li.appendChild(mark);
175
+ if (after) li.appendChild(document.createTextNode(after));
176
+ } else {
177
+ li.textContent = label;
178
+ }
179
+ const isSelected = this.hasAttribute("multiple") && selectedVals.includes(String(item.value));
180
+ li.setAttribute("aria-selected", String(isSelected));
181
+ if (isSelected) li.classList.add("c-combobox__option--selected");
182
+ list.appendChild(li);
183
+ });
184
+ if (this._comboboxVirtual) addSpacer(Math.max(0, filtered.length - end) * rowHeight);
185
+ if (this._comboboxVirtual && !reset) list.scrollTop = oldScrollTop;
186
+ }
187
+ _syncFormValue() {
188
+ if (!this._internals) return;
189
+ // Committed value on host attribute; form submits value, field shows label.
190
+ const raw = this.getAttribute("value");
191
+ const value = raw != null && raw !== "" ? raw : null;
192
+ this._internals.setFormValue(value);
193
+ this._syncValidity(this.hasAttribute("required") && !value);
194
+ }
195
+ enhance() {
196
+ wireCombobox(this);
197
+ // Mirror committed input value into form association so host submits.
198
+ if (this._internals && !this._wiredComboboxForm) {
199
+ this._wiredComboboxForm = true;
200
+ this._syncFormValue();
201
+ this.addEventListener("contour:select", (e) => {
202
+ const v = e && e.detail && (e.detail.value || e.detail.label);
203
+ if (v != null) this.setAttribute("value", String(v));
204
+ this._syncFormValue();
205
+ });
206
+ }
207
+ if (!this._wiredComboboxClear) {
208
+ this._wiredComboboxClear = true;
209
+ this.addEventListener("click", (e) => {
210
+ const btn = e.target && e.target.closest ? e.target.closest(".c-combobox__clear") : null;
211
+ if (!btn || !this.contains(btn)) return;
212
+ e.preventDefault();
213
+ this.removeAttribute("value");
214
+ const input = this.querySelector(".c-combobox__input");
215
+ if (input) input.value = "";
216
+ this._syncFormValue();
217
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { name: this.getAttribute("name"), value: null, checked: null } }));
218
+ });
219
+ }
220
+ }
221
+ formResetCallback() {
222
+ // Restore authored default; render maps to option label, base reset writes raw values.
223
+ this._contourResetting = true;
224
+ try {
225
+ const def = this._comboboxDefault ?? null;
226
+ if (def === null) this.removeAttribute("value");
227
+ else this.setAttribute("value", def);
228
+ this._syncFormValue();
229
+ } finally {
230
+ this._contourResetting = false;
231
+ }
232
+ }
233
+ }
234
+ define("contour-combobox", ContourCombobox);
235
+ /**
236
+ * Field: a labelled form control wrapper. Renders an `<input>`/`<textarea>`/
237
+ * `<select>` (or adopts an authored one), associates a label via `for`/`id`,
238
+ * and attaches hint and error text with `aria-describedby`. Drives inline
239
+ * validation on blur (`aria-invalid`, `is-invalid`) and keeps the form value in
240
+ * sync via `_internals.setFormValue`. Emits `contour:input` / `contour:change`.
241
+ */
242
+ class ContourField extends ContourBase {
243
+ static get observed() { return ["label", "hint", "error", "placeholder", "type", "required", "name", "value", "disabled", "custom-error"]; }
244
+ static get formAssociated() { return true; }
245
+ 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" } }; }
246
+ render() {
247
+ this.classList.add("c-field");
248
+ const label = this.getAttribute("label");
249
+ const hint = this.getAttribute("hint");
250
+ const error = this.getAttribute("error");
251
+ const placeholder = this.getAttribute("placeholder") || "";
252
+ if (label) {
253
+ const lbl = this.ensure(".c-field__label", () => { const el = document.createElement("label"); el.className = "c-field__label"; return el; });
254
+ lbl.textContent = label;
255
+ } else {
256
+ const lbl = this.querySelector(".c-field__label");
257
+ if (lbl) lbl.remove();
258
+ }
259
+ // Skip generating input when nested form host submits its own value.
260
+ const nestedFormHost = Array.from(this.children).find((c) => c.constructor && c.constructor.formAssociated);
261
+ const input = nestedFormHost ? null : this.ensure("input.c-input, textarea, select", () => {
262
+ const el = document.createElement("input");
263
+ el.className = "c-input";
264
+ return el;
265
+ });
266
+ if (input) {
267
+ input.type = this.getAttribute("type") || "text";
268
+ input.placeholder = placeholder;
269
+ // Stable id across renders; fresh id breaks keyed value/focus matching.
270
+ if (!input.id) input.id = this._fieldInputId || (this._fieldInputId = contourId("contour-field"));
271
+
272
+ const lbl = this.querySelector(".c-field__label");
273
+ if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); input.setAttribute("aria-label", lbl.textContent); }
274
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "field", "Field"));
275
+ if (hint) {
276
+ const h = this.ensure(".c-field__hint", () => { const el = document.createElement("span"); el.className = "c-field__hint"; return el; });
277
+ h.textContent = hint;
278
+ } else {
279
+ const h = this.querySelector(".c-field__hint");
280
+ if (h) h.remove();
281
+ }
282
+ if (error) {
283
+ const e = this.ensure(".c-field__error", () => { const el = document.createElement("span"); el.className = "c-field__error"; return el; });
284
+ e.textContent = error;
285
+ } else {
286
+ const e = this.querySelector(".c-field__error");
287
+ if (e) e.remove();
288
+ }
289
+ // R22 WC4-26: custom-error attribute — declarative setCustomValidity.
290
+ const customError = this.getAttribute("custom-error");
291
+ if (customError !== null) {
292
+ input.setAttribute("aria-invalid", "true");
293
+ this.classList.add("is-invalid");
294
+ this.setAttribute("data-invalid", "");
295
+ let errEl = this.querySelector(".c-field__error");
296
+ if (!errEl) {
297
+ errEl = document.createElement("span");
298
+ errEl.className = "c-field__error";
299
+ this.appendChild(errEl);
300
+ }
301
+ errEl.textContent = customError;
302
+ if (!errEl.id) errEl.id = contourId("err");
303
+ input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
304
+ }
305
+ // Link input to hint/error via aria-describedby; generated ids ensure both are announced.
306
+ const hintEl = this.querySelector(".c-field__hint");
307
+ const errEl = this.querySelector(".c-field__error");
308
+ const describedBy = [];
309
+ if (hintEl) { if (!hintEl.id) hintEl.id = contourId("hint"); describedBy.push(hintEl.id); }
310
+ if (errEl) { if (!errEl.id) errEl.id = contourId("err"); describedBy.push(errEl.id); }
311
+ if (describedBy.length) input.setAttribute("aria-describedby", describedBy.join(" "));
312
+ // Reflect native constraints: checkValidity and FormData must see required/name/value.
313
+ if (this.hasAttribute("required")) { input.setAttribute("aria-required", "true"); input.setAttribute("required", ""); }
314
+ else { input.removeAttribute("aria-required"); input.removeAttribute("required"); }
315
+ if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
316
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
317
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
318
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
319
+ } // end if (input)
320
+ }
321
+ }
322
+ ContourField.prototype.enhance = function() {
323
+ if (this._wiredField) return;
324
+ this._wiredField = true;
325
+ const sync = () => {
326
+ const input = this.querySelector("input, textarea, select");
327
+ if (!input || !this._internals) return;
328
+ this._internals.setFormValue(input.value);
329
+ // Mirror required-missing into form association (not just ARIA) so checkValidity fails.
330
+ this._syncValidity(this.hasAttribute("required") && !input.value);
331
+ };
332
+ this.addEventListener("input", (e) => {
333
+ const input = this.querySelector("input, textarea, select");
334
+ if (!input || e.target !== input) return;
335
+ sync();
336
+ this._emitForm("contour:input");
337
+ });
338
+ this.addEventListener("change", (e) => {
339
+ const input = this.querySelector("input, textarea, select");
340
+ if (!input || e.target !== input) return;
341
+ sync();
342
+ this._emitForm("contour:change");
343
+ });
344
+ // Inline validation on blur: reflect validity via aria-invalid; focusout bubbles, blur doesn't.
345
+ this.addEventListener("focusout", (e) => {
346
+ const input = this.querySelector("input, textarea, select");
347
+ if (!input || e.target !== input) return;
348
+ const valid = input.checkValidity();
349
+ if (valid) {
350
+ input.setAttribute("aria-invalid", "false");
351
+ this.classList.remove("is-invalid");
352
+ this.removeAttribute("data-invalid");
353
+ // Clear transient validation error, not author-set error.
354
+ if (!this.getAttribute("error")) {
355
+ const stale = this.querySelector(".c-field__error");
356
+ if (stale) {
357
+ const id = stale.id;
358
+ stale.remove();
359
+ if (id) input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== id).join(" "));
360
+ }
361
+ }
362
+ } else {
363
+ input.setAttribute("aria-invalid", "true");
364
+ this.classList.add("is-invalid");
365
+ this.setAttribute("data-invalid", "");
366
+ // R22 WC4-26: emit cancelable contour:invalid; listener can suppress invalid state.
367
+ const invalidEvent = new CustomEvent("contour:invalid", {
368
+ bubbles: true,
369
+ composed: true,
370
+ cancelable: true,
371
+ detail: { field: this, input, message: input.validationMessage || "Invalid value" },
372
+ });
373
+ const notCancelled = this.dispatchEvent(invalidEvent);
374
+ if (notCancelled) {
375
+ // Surface browser validation message when no explicit error/custom-error attr.
376
+ if (!this.getAttribute("error") && !this.getAttribute("custom-error")) {
377
+ const msg = input.validationMessage || "Invalid value";
378
+ let errEl = this.querySelector(".c-field__error");
379
+ if (!errEl) {
380
+ errEl = document.createElement("span");
381
+ errEl.className = "c-field__error";
382
+ this.appendChild(errEl);
383
+ }
384
+ errEl.textContent = msg;
385
+ if (!errEl.id) errEl.id = contourId("err");
386
+ input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
387
+ }
388
+ }
389
+ }
390
+ sync();
391
+ }, true);
392
+ sync();
393
+ };
394
+ define("contour-field", ContourField);
395
+
396
+ /**
397
+ * Field-group: a grouped field with a shared label, optional hint and error
398
+ * text. Sets `role="group"` and `aria-required` when required; toggles
399
+ * `is-error` when an error is present. Child fields are labelled by the group.
400
+ */
401
+ class ContourFieldGroup extends ContourBase {
402
+ static get observed() { return ["label", "hint", "error", "required"]; }
403
+ static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, required: { attribute: "required", type: Boolean } }; }
404
+ render() {
405
+ this.classList.add("c-field-group");
406
+ this.setAttribute("role", "group");
407
+ const label = this.getAttribute("label");
408
+ if (label) {
409
+ const lbl = this.ensure(".c-field-group__label", () => { const el = document.createElement("div"); el.className = "c-field-group__label"; return el; });
410
+ lbl.textContent = label;
411
+ } else {
412
+ const lbl = this.querySelector(".c-field-group__label");
413
+ if (lbl) lbl.remove();
414
+ }
415
+ const hint = this.getAttribute("hint");
416
+ if (hint) {
417
+ const h = this.ensure(".c-field-group__hint", () => { const el = document.createElement("span"); el.className = "c-field-group__hint"; return el; });
418
+ h.textContent = hint;
419
+ } else {
420
+ const h = this.querySelector(".c-field-group__hint");
421
+ if (h) h.remove();
422
+ }
423
+ const error = this.getAttribute("error");
424
+ if (error) {
425
+ const e = this.ensure(".c-field-group__error", () => { const el = document.createElement("span"); el.className = "c-field-group__error"; return el; });
426
+ e.textContent = error;
427
+ } else {
428
+ const e = this.querySelector(".c-field-group__error");
429
+ if (e) e.remove();
430
+ }
431
+ if (error) this.classList.add("is-error"); else this.classList.remove("is-error");
432
+ // aria-required not allowed on role="group"; required semantics go on inner controls.
433
+ const required = this.hasAttribute("required");
434
+ this.querySelectorAll("input, select, textarea").forEach((el) => {
435
+ if (required) { if (!el.hasAttribute("aria-required")) el.setAttribute("aria-required", "true"); }
436
+ else if (el.getAttribute("aria-required") === "true") el.removeAttribute("aria-required");
437
+ });
438
+ }
439
+ enhance() {
440
+ if (this._wiredFieldGroup) return;
441
+ this._wiredFieldGroup = true;
442
+ }
443
+ }
444
+ define("contour-field-group", ContourFieldGroup);
445
+
446
+ /**
447
+ * Form: a form wrapper with submission state and a validation summary. Adds
448
+ * `is-submitting` and disables the submit button while `submitting` is set.
449
+ * On invalid submit, prevents default and renders a `role="alert"` summary
450
+ * listing the invalid fields. Emits `contour:submit` on valid submit.
451
+ *
452
+ * Nesting contract: when `contour-form` is nested inside a real `<form>`,
453
+ * submission listens on that enclosing form so `contour:submit` fires and
454
+ * the real form is prevented from navigating. When standalone, the host
455
+ * itself is the submit target. The component's own submit button (rendered
456
+ * when `submit-label` is given) only handles the standalone case; inside a
457
+ * real form the native button drives the form's submit event which the
458
+ * enclosing-form listener catches.
459
+ */
460
+ class ContourForm extends ContourBase {
461
+ static get observed() { return ["submitting", "error", "summary", "title", "submit-label"]; }
462
+ static get properties() { return { submitting: { attribute: "submitting", type: Boolean }, error: { attribute: "error" }, summary: { attribute: "summary" }, title: { attribute: "title" }, submitLabel: { attribute: "submit-label" } }; }
463
+ render() {
464
+ this.classList.add("c-form");
465
+ if (this.hasAttribute("submitting")) this.classList.add("is-submitting"); else this.classList.remove("is-submitting");
466
+ const title = this.getAttribute("title");
467
+ let titleEl = this.querySelector(".c-form__title");
468
+ if (title) {
469
+ if (!titleEl) { titleEl = document.createElement("h2"); titleEl.className = "c-form__title"; this.prepend(titleEl); }
470
+ titleEl.textContent = title;
471
+ } else if (titleEl) {
472
+ titleEl.remove();
473
+ }
474
+ const summaryText = this.getAttribute("summary") || this.getAttribute("error");
475
+ let summary = this.querySelector(".c-form__summary");
476
+ if (summaryText) {
477
+ if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
478
+ summary.textContent = summaryText;
479
+ summary.removeAttribute("hidden");
480
+ } else if (summary) {
481
+ summary.setAttribute("hidden", "");
482
+ }
483
+ // Component owns submission: renders submit control when submit-label given.
484
+ const submitLabel = this.getAttribute("submit-label");
485
+ let submit = this.querySelector(".c-form__submit");
486
+ if (!submit) {
487
+ submit = document.createElement("button");
488
+ submit.type = "submit";
489
+ submit.className = "c-btn c-btn--primary c-form__submit";
490
+ this.appendChild(submit);
491
+ }
492
+ // submit-label is authored override; labels.submit is localised default; applyLabel re-applies default each render.
493
+ if (submitLabel) {
494
+ submit.textContent = submitLabel;
495
+ if (submit.dataset) delete submit.dataset.contourLabel;
496
+ } else {
497
+ applyLabel(submit, this, "submit", "Submit");
498
+ }
499
+ if (this.hasAttribute("submitting")) submit.setAttribute("disabled", "");
500
+ else submit.removeAttribute("disabled");
501
+ }
502
+ enhance() {
503
+ if (this._wiredForm) return;
504
+ this._wiredForm = true;
505
+ // Nesting contract: submit bubbles to enclosing form; listen on closest form or host.
506
+ const closestForm = this.closest("form");
507
+ const submitTarget = closestForm || this;
508
+
509
+ const onSubmit = (e) => {
510
+ const form = e.target;
511
+ // Component claims submission ownership: never let nested form navigate.
512
+ e.preventDefault();
513
+ if (form && typeof form.checkValidity === "function" && !form.checkValidity()) {
514
+ const invalid = Array.from(form.querySelectorAll(":invalid"));
515
+ const names = invalid.map((el) => el.getAttribute("aria-label") || el.name || el.id || "field").join(", ");
516
+ let summary = this.querySelector(".c-form__summary");
517
+ if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
518
+ summary.textContent = labelText(this, "validation-summary", "Please fix") + ": " + (names || labelText(this, "invalid-fields", "invalid fields"));
519
+ summary.removeAttribute("hidden");
520
+ return;
521
+ }
522
+ this._submit();
523
+ };
524
+
525
+ // Click on component's submit control is submission path when no nested form.
526
+ this.addEventListener("click", (e) => {
527
+ const btn = e.target && e.target.closest ? e.target.closest(".c-form__submit") : null;
528
+ if (!btn || !this.contains(btn)) return;
529
+ if (e.target.closest("form")) return; // a nested real form handles it
530
+ e.preventDefault();
531
+ this._submit();
532
+ });
533
+ submitTarget.addEventListener("submit", onSubmit);
534
+ onDispose(this, () => {
535
+ if (submitTarget !== this) {
536
+ submitTarget.removeEventListener("submit", onSubmit);
537
+ }
538
+ });
539
+ }
540
+ _submit() {
541
+ this.classList.add("is-submitting");
542
+ const submit = this.querySelector("[type='submit'], .c-form__submit");
543
+ if (submit) submit.setAttribute("disabled", "");
544
+ this.dispatchEvent(new CustomEvent("contour:submit", { bubbles: true, composed: true, detail: { submitting: true } }));
545
+ }
546
+ }
547
+ define("contour-form", ContourForm);