contour-ds 1.8.1 → 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 (147) hide show
  1. package/README.md +227 -378
  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/build-manifest.json +320 -179
  6. package/dist/contour-wc-content.esm.js +479 -3665
  7. package/dist/contour-wc-content.esm.min.js +1 -1
  8. package/dist/contour-wc-core.esm.js +3724 -0
  9. package/dist/contour-wc-core.esm.min.js +1 -0
  10. package/dist/contour-wc-dashboard.esm.js +2713 -4381
  11. package/dist/contour-wc-dashboard.esm.min.js +1 -1
  12. package/dist/contour-wc-data.esm.js +2658 -4346
  13. package/dist/contour-wc-data.esm.min.js +1 -1
  14. package/dist/contour-wc-docs.esm.js +218 -3547
  15. package/dist/contour-wc-docs.esm.min.js +1 -1
  16. package/dist/contour-wc-feedback.esm.js +483 -3658
  17. package/dist/contour-wc-feedback.esm.min.js +1 -1
  18. package/dist/contour-wc-forms.esm.js +503 -3754
  19. package/dist/contour-wc-forms.esm.min.js +1 -1
  20. package/dist/contour-wc-interaction.esm.js +379 -3616
  21. package/dist/contour-wc-interaction.esm.min.js +1 -1
  22. package/dist/contour-wc-layout.esm.js +234 -3563
  23. package/dist/contour-wc-layout.esm.min.js +1 -1
  24. package/dist/contour-wc-map.esm.js +949 -3743
  25. package/dist/contour-wc-map.esm.min.js +1 -1
  26. package/dist/contour-wc-misc.esm.js +237 -3556
  27. package/dist/contour-wc-misc.esm.min.js +1 -1
  28. package/dist/contour-wc-navigation.esm.js +2235 -5237
  29. package/dist/contour-wc-navigation.esm.min.js +1 -1
  30. package/dist/contour-wc-ui.esm.js +4638 -7128
  31. package/dist/contour-wc-ui.esm.min.js +1 -1
  32. package/dist/contour-wc.esm.js +11971 -7727
  33. package/dist/contour-wc.esm.min.js +1 -1
  34. package/dist/contour-wc.js +11971 -7727
  35. package/dist/contour-wc.min.js +1 -1
  36. package/dist/contour.a11y.json +402 -0
  37. package/dist/contour.code-snippets +96 -74
  38. package/dist/contour.components.json +2591 -741
  39. package/dist/contour.css +2624 -1888
  40. package/dist/contour.d.ts +421 -228
  41. package/dist/contour.esm.js +433 -18
  42. package/dist/contour.esm.min.js +1 -1
  43. package/dist/contour.html-data.json +1231 -199
  44. package/dist/contour.js +433 -18
  45. package/dist/contour.min.css +1 -1
  46. package/dist/contour.min.js +1 -1
  47. package/dist/contour.react.d.ts +100 -98
  48. package/dist/contour.single.html +2 -2
  49. package/dist/contour.single.min.css +1 -1
  50. package/dist/contour.themes.json +56 -12
  51. package/dist/contour.tokens.json +482 -255
  52. package/dist/contour.vue.d.ts +100 -98
  53. package/dist/contour.web-types.json +1226 -226
  54. package/dist/custom-elements.json +7649 -2237
  55. package/dist/docs/actions.md +15 -6
  56. package/dist/docs/affordances.md +18 -96
  57. package/dist/docs/apireference.md +9 -5
  58. package/dist/docs/colour.md +10 -4
  59. package/dist/docs/componentindex.md +9 -26
  60. package/dist/docs/data.md +36 -60
  61. package/dist/docs/docs.md +10 -12
  62. package/dist/docs/feedback.md +30 -12
  63. package/dist/docs/field.md +28 -13
  64. package/dist/docs/forms.md +35 -19
  65. package/dist/docs/index.json +63 -56
  66. package/dist/docs/install.md +12 -7
  67. package/dist/docs/landing.md +7 -4
  68. package/dist/docs/mapengine.md +18 -13
  69. package/dist/docs/motion.md +12 -6
  70. package/dist/docs/navigation.md +31 -7
  71. package/dist/docs/overlays.md +32 -25
  72. package/dist/docs/overview.md +3 -2
  73. package/dist/docs/patterns.md +19 -9
  74. package/dist/docs/playground.md +9 -22
  75. package/dist/docs/principles.md +8 -6
  76. package/dist/docs/recipes.md +113 -14
  77. package/dist/docs/space.md +10 -6
  78. package/dist/docs/status.md +12 -25
  79. package/dist/docs/surfaces.md +17 -22
  80. package/dist/docs/theming.md +18 -32
  81. package/dist/docs/type.md +12 -5
  82. package/dist/docs/webcomponents.md +66 -38
  83. package/dist/hljs.css +1 -20
  84. package/dist/map-chrome.mapbox.css +68 -92
  85. package/dist/map-chrome.maplibre.css +68 -92
  86. package/dist/registry/items/contour-core.json +2 -2
  87. package/dist/registry/items/contour-data.json +2 -2
  88. package/dist/registry/items/contour-docs.json +2 -2
  89. package/dist/registry/items/contour-landing.json +2 -2
  90. package/dist/registry/registry.json +8 -8
  91. package/dist/surfaces/contour-core.min.css +1 -1
  92. package/dist/surfaces/contour-data.min.css +1 -1
  93. package/dist/surfaces/contour-docs.min.css +1 -1
  94. package/dist/surfaces/contour-landing.min.css +1 -1
  95. package/dist/svg/icons.svg +367 -0
  96. package/dist/wc/behaviours.mjs +190 -148
  97. package/dist/wc/content.mjs +273 -129
  98. package/dist/wc/core.mjs +598 -395
  99. package/dist/wc/dashboard.mjs +64 -44
  100. package/dist/wc/data-chart.mjs +1333 -0
  101. package/dist/wc/data-export.mjs +391 -0
  102. package/dist/wc/data-gauge.mjs +779 -0
  103. package/dist/wc/data-geo.mjs +696 -0
  104. package/dist/wc/data-glyphs.mjs +133 -0
  105. package/dist/wc/data-legend.mjs +431 -0
  106. package/dist/wc/data-readout.mjs +227 -0
  107. package/dist/wc/data-series.mjs +1004 -0
  108. package/dist/wc/data-table.mjs +751 -0
  109. package/dist/wc/data.mjs +15 -4322
  110. package/dist/wc/docs.mjs +12 -11
  111. package/dist/wc/feedback.mjs +277 -122
  112. package/dist/wc/forms-controls.mjs +635 -0
  113. package/dist/wc/forms-field.mjs +547 -0
  114. package/dist/wc/forms-groups.mjs +347 -0
  115. package/dist/wc/forms-input.mjs +292 -0
  116. package/dist/wc/forms.mjs +10 -1751
  117. package/dist/wc/glyph.mjs +204 -0
  118. package/dist/wc/index.mjs +11 -9
  119. package/dist/wc/interaction.mjs +173 -80
  120. package/dist/wc/layout.mjs +28 -27
  121. package/dist/wc/map.mjs +743 -207
  122. package/dist/wc/misc.mjs +31 -20
  123. package/dist/wc/navigation-menu.mjs +735 -0
  124. package/dist/wc/navigation-shell.mjs +495 -0
  125. package/dist/wc/navigation-tree.mjs +995 -0
  126. package/dist/wc/navigation.mjs +9 -1905
  127. package/dist/wc/registration.mjs +1 -8
  128. package/dist/wc/shadow.mjs +206 -110
  129. package/dist/wc/states.mjs +54 -75
  130. package/dist/wc/svg.mjs +118 -47
  131. package/dist/wc/ui-atoms.mjs +608 -0
  132. package/dist/wc/ui-data.mjs +1404 -0
  133. package/dist/wc/ui-feedback.mjs +419 -0
  134. package/dist/wc/ui-inputs.mjs +1570 -0
  135. package/dist/wc/ui-menus.mjs +307 -0
  136. package/dist/wc/ui-overlays.mjs +1605 -0
  137. package/integrations/README.md +23 -5
  138. package/integrations/ai/CLAUDE.md +3 -0
  139. package/integrations/ai/COPILOT.md +14 -0
  140. package/integrations/ai/GEMINI.md +14 -0
  141. package/integrations/ai/WINDSURF.md +14 -0
  142. package/integrations/ai/v0-prompt.md +13 -1
  143. package/integrations/native/README.md +0 -3
  144. package/integrations/tailwind/contour-theme.css +66 -7
  145. package/integrations/validate-markup.mjs +172 -0
  146. package/package.json +77 -42
  147. package/dist/wc/ui.mjs +0 -5072
@@ -0,0 +1,347 @@
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
+ * RadioList: a `role="radiogroup"` of radio options from a JSON `items`
7
+ * attribute (or remote `src`). Supports roving tabindex, Home/End navigation,
8
+ * RTL, empty/loading/error states, and `formResetCallback` that re-renders from
9
+ * the authored `items` payload. Form associated; emits `contour:change`.
10
+ */
11
+ class ContourRadioList extends ContourBase {
12
+ static get observed() { return ["items", "options", "name", "value", "required", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "dir", "no-cache"]; }
13
+ static get properties() { return { items: { attribute: "items" }, options: { attribute: "options" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, src: { attribute: "src" } }; }
14
+ static get formAssociated() { return true; }
15
+ attributeChangedCallback(name, oldValue, newValue) {
16
+ // A `value` written by sync() reflects the user's pick; the radios already
17
+ // show it, so a re-render would only rebuild the list and detach the
18
+ // focused input (losing focus mid-interaction). The attribute still sets,
19
+ // so el.value reads it and a later render restores from it.
20
+ if (name === "value" && this._radioSync) return;
21
+ super.attributeChangedCallback(name, oldValue, newValue);
22
+ }
23
+ render() {
24
+ this.classList.add("c-radio-list");
25
+ this.setAttribute("role", "radiogroup");
26
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("name") || "Options");
27
+ // R31-74: required is a group constraint; mirror it to the radiogroup.
28
+ if (this.hasAttribute("required")) this.setAttribute("aria-required", "true"); else this.removeAttribute("aria-required");
29
+ wireStates(this);
30
+ loadRemote(this, "items");
31
+ if (renderStates(this, "radio-list")) return;
32
+ const items = remoteData(this, "items") || this.getAttribute("options") || this.getAttribute("items");
33
+ // R31-74: keep the current selection across a re-render. The radios are
34
+ // rebuilt from `items` every render, so without this a host attribute
35
+ // change (or a form reset) drops the checked item. The authored `value`
36
+ // attribute seeds it; otherwise the previously checked item is kept.
37
+ const prevChecked = this.querySelector("input.c-radio__input:checked");
38
+ const desired = this.hasAttribute("value") ? this.getAttribute("value") : (prevChecked ? prevChecked.value : null);
39
+ Array.from(this.querySelectorAll("label.c-radio")).forEach((l) => l.remove());
40
+ if (items) {
41
+ try {
42
+ const parsed = JSON.parse(items);
43
+ const groupName = this.getAttribute("name") || contourId("radio-list");
44
+ parsed.forEach((it) => {
45
+ const lbl = document.createElement("label");
46
+ lbl.className = "c-radio";
47
+ const input = document.createElement("input");
48
+ input.type = "radio";
49
+ input.className = "c-radio__input";
50
+ input.name = groupName;
51
+ input.tabIndex = -1;
52
+ if (typeof it === "string") { input.value = it; if (it === desired) input.checked = true; lbl.appendChild(input); lbl.appendChild(document.createTextNode(" " + it)); }
53
+ else { input.value = it.value || it.label; if (it.checked || (desired != null && String(it.value || it.label) === String(desired))) input.checked = true; lbl.appendChild(input); const span = document.createElement("span"); span.textContent = it.label || it.value; lbl.appendChild(span); }
54
+ this.appendChild(lbl);
55
+ });
56
+ // Roving tabindex: only the checked item (or the first) is in the tab
57
+ // order, exactly like a native radiogroup.
58
+ const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
59
+ const checked = radios.find((r) => r.checked) || radios[0];
60
+ if (checked) checked.tabIndex = 0;
61
+ } catch (e) { warnBadJson(this, "attribute", e); }
62
+ } else {
63
+ renderEmpty(this, "radio-list");
64
+ }
65
+ }
66
+ enhance() {
67
+ const sync = () => {
68
+ const checked = this.querySelector("input.c-radio__input:checked");
69
+ const val = checked ? checked.value : null;
70
+ if (this._internals) this._internals.setFormValue(val);
71
+ // R31-74: reflect the selection into `value` so el.value reads it and a
72
+ // re-render restores it; required reports group validity. The self-write
73
+ // is flagged so it does not re-render and detach the focused radio.
74
+ if (val != null && this.getAttribute("value") !== val) {
75
+ this._radioSync = true;
76
+ try { this.setAttribute("value", val); } finally { this._radioSync = false; }
77
+ }
78
+ this._syncValidity(this.hasAttribute("required") && val == null);
79
+ };
80
+ sync();
81
+ if (this._wiredRadioList) return;
82
+ this._wiredRadioList = true;
83
+ // Form life + group semantics, delegated on the host (rule 12): the
84
+ // inputs are rebuilt on every render, so node-bound listeners would die.
85
+ this.addEventListener("change", (e) => {
86
+ const input = e.target && e.target.closest ? e.target.closest("input.c-radio__input") : null;
87
+ if (!input || !this.contains(input)) return;
88
+ sync();
89
+ this._emitForm("contour:change");
90
+ });
91
+ this.addEventListener("keydown", (e) => {
92
+ const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
93
+ if (!radios.length) return;
94
+ const idx = radios.indexOf(e.target);
95
+ if (idx === -1) return;
96
+ const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
97
+ let next = -1;
98
+ if (e.key === "ArrowDown") next = (idx + 1) % radios.length;
99
+ else if (e.key === "ArrowUp") next = (idx - 1 + radios.length) % radios.length;
100
+ else if (e.key === "ArrowRight") next = rtl ? (idx - 1 + radios.length) % radios.length : (idx + 1) % radios.length;
101
+ else if (e.key === "ArrowLeft") next = rtl ? (idx + 1) % radios.length : (idx - 1 + radios.length) % radios.length;
102
+ else if (e.key === "Home") next = 0;
103
+ else if (e.key === "End") next = radios.length - 1;
104
+ else return;
105
+ e.preventDefault();
106
+ const before = radios.find((r) => r.checked);
107
+ for (const r of radios) r.tabIndex = -1;
108
+ radios[next].tabIndex = 0;
109
+ radios[next].checked = true;
110
+ radios[next].focus();
111
+ sync();
112
+ // Native radio groups fire change when an arrow moves the selection;
113
+ // wrap-around onto the same radio is not a change.
114
+ if (before !== radios[next]) this._emitForm("contour:change");
115
+ });
116
+ }
117
+ formResetCallback() {
118
+ // Authored default lives in the `items` payload (it.checked); re-render from data under the resetting flag so base checked-restore doesn't resurrect the user's selection.
119
+ this._contourResetting = true;
120
+ try {
121
+ if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
122
+ this._syncFormValue();
123
+ } finally {
124
+ this._contourResetting = false;
125
+ }
126
+ }
127
+ }
128
+ define("contour-radio-list", ContourRadioList);
129
+
130
+ // Fieldset: a <fieldset> with a <legend> for grouping controls; platform draws the boundary.
131
+ class ContourFieldset extends ContourBase {
132
+ static get observed() { return ["legend", "disabled"]; }
133
+ static get properties() { return { legend: { attribute: "legend" }, disabled: { attribute: "disabled", type: Boolean } }; }
134
+ render() {
135
+ const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-fieldset"; return el; });
136
+ if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
137
+ const legend = this.getAttribute("legend");
138
+ let lg = fs.querySelector("legend");
139
+ if (legend) {
140
+ if (!lg) { lg = document.createElement("legend"); lg.className = "c-fieldset__legend"; fs.prepend(lg); }
141
+ lg.textContent = legend;
142
+ } else if (lg) lg.remove();
143
+ // Move authored children into the fieldset (light DOM).
144
+ const authored = Array.from(this.children).filter((c) => c !== fs);
145
+ if (authored.length) { authored.forEach((c) => fs.appendChild(c)); }
146
+ }
147
+ }
148
+ define("contour-fieldset", ContourFieldset);
149
+
150
+ // Checkbox group: a fieldset of checkboxes with a shared name. Form associated: host owns group value, value reflects comma-joined selection, required reports group validity, emits contour:change { value, values }.
151
+ // R31-36: the option payload answers to both spellings this system uses — `options` (a select's word) and `items` (a list's word) — so one vocabulary does not stop at the component boundary.
152
+ class ContourCheckboxGroup extends ContourBase {
153
+ static get observed() { return ["legend", "name", "options", "items", "value", "required", "disabled"]; }
154
+ static get properties() { return { legend: { attribute: "legend" }, name: { attribute: "name" }, options: { attribute: "options" }, items: { attribute: "items" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
155
+ static get formAssociated() { return true; }
156
+ render() {
157
+ this.classList.add("c-checkbox-group");
158
+ // Authored default captured before any toggle reflects into `value`.
159
+ if (this._checkboxGroupDefault === undefined) this._checkboxGroupDefault = this.getAttribute("value");
160
+ const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-checkbox-group__fieldset"; return el; });
161
+ if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
162
+ if (this.hasAttribute("required")) fs.setAttribute("aria-required", "true"); else fs.removeAttribute("aria-required");
163
+ const legend = this.getAttribute("legend");
164
+ let lg = fs.querySelector("legend");
165
+ if (legend) {
166
+ if (!lg) { lg = document.createElement("legend"); lg.className = "c-checkbox-group__legend"; fs.prepend(lg); }
167
+ lg.textContent = legend;
168
+ } else if (lg) lg.remove();
169
+ const name = this.getAttribute("name") || "group";
170
+ const options = this.getAttribute("options") || this.getAttribute("items");
171
+ const selected = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean);
172
+ if (options) {
173
+ try {
174
+ const parsed = JSON.parse(options);
175
+ Array.from(fs.querySelectorAll(".c-check")).forEach((n) => n.remove());
176
+ parsed.forEach((opt) => {
177
+ const label = typeof opt === "string" ? opt : (opt.label || opt.value || "");
178
+ const value = typeof opt === "string" ? opt : (opt.value || opt.label || "");
179
+ const wrap = document.createElement("label");
180
+ wrap.className = "c-check";
181
+ const input = document.createElement("input");
182
+ input.type = "checkbox";
183
+ input.className = "c-check__input";
184
+ input.name = name;
185
+ input.value = value;
186
+ // Boxes share the group name, so name-based focus matching lands on the first; per-option preserve key restores focus to the clicked box.
187
+ input.setAttribute("data-contour-preserve-key", value);
188
+ if (selected.includes(value)) input.checked = true;
189
+ const span = document.createElement("span");
190
+ span.textContent = label;
191
+ wrap.appendChild(input);
192
+ wrap.appendChild(span);
193
+ fs.appendChild(wrap);
194
+ });
195
+ } catch (e) { warnBadJson(this, "attribute", e); }
196
+ }
197
+ // R31-62: apply `value` to authored checkbox children too, not only the JSON
198
+ // `options` branch. A consumer who authors <input type="checkbox" value="a">
199
+ // with value="a,c" must see both boxes checked and submit both entries.
200
+ // Authored <contour-check> children upgrade after this render and only then
201
+ // create their inner input, so re-apply on the next microtask and frame.
202
+ if (selected.length) {
203
+ const apply = () => {
204
+ if (!this.isConnected) return;
205
+ for (const input of this.querySelectorAll("input[type=checkbox]")) {
206
+ if (selected.includes(input.value)) input.checked = true;
207
+ }
208
+ if (this._internals) this._syncFormValue();
209
+ };
210
+ apply();
211
+ if (typeof queueMicrotask === "function") queueMicrotask(apply);
212
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(apply);
213
+ }
214
+ }
215
+ enhance() {
216
+ if (this._internals) this._syncFormValue();
217
+ if (this._wiredCheckboxGroup) return;
218
+ this._wiredCheckboxGroup = true;
219
+ this.addEventListener("change", (e) => {
220
+ const t = e.target;
221
+ if (t && t.matches && t.matches("input[type=checkbox]")) {
222
+ const values = Array.from(this.querySelectorAll("input[type=checkbox]:checked")).map((i) => i.value);
223
+ // Reflect the group value so `el.value` reads the live selection and
224
+ // a re-render rebuilds it; the attribute write re-renders synchronously.
225
+ this.setAttribute("value", values.join(","));
226
+ this._syncFormValue();
227
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: values.join(","), values } }));
228
+ }
229
+ });
230
+ }
231
+ // Each checked box is its own entry under the host name (native repeated-entry shape); host owns reset/validity; formdata re-sync calls this.
232
+ _syncFormValue() {
233
+ if (!this._internals) return;
234
+ const checked = Array.from(this.querySelectorAll("input[type=checkbox]:checked"));
235
+ const name = this.getAttribute("name");
236
+ if (name && checked.length) {
237
+ const fd = new FormData();
238
+ for (const c of checked) fd.append(name, c.value);
239
+ this._internals.setFormValue(fd);
240
+ } else {
241
+ this._internals.setFormValue(null);
242
+ }
243
+ this._syncValidity(this.hasAttribute("required") && !checked.length);
244
+ }
245
+ formResetCallback() {
246
+ // Restore the authored default, not the last reflected selection.
247
+ this._contourResetting = true;
248
+ try {
249
+ const def = this._checkboxGroupDefault ?? null;
250
+ if (def === null) this.removeAttribute("value");
251
+ else this.setAttribute("value", def);
252
+ this._syncFormValue();
253
+ } finally {
254
+ this._contourResetting = false;
255
+ }
256
+ }
257
+ formStateRestoreCallback(state) {
258
+ const values = state instanceof FormData
259
+ ? Array.from(state.getAll(this.getAttribute("name"))).map(String)
260
+ : (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
261
+ this._contourResetting = true;
262
+ try {
263
+ this.setAttribute("value", values.join(","));
264
+ this._syncFormValue();
265
+ } finally {
266
+ this._contourResetting = false;
267
+ }
268
+ }
269
+ }
270
+ define("contour-checkbox-group", ContourCheckboxGroup);
271
+
272
+ // Search field: type=search with a search icon and accessible name; form associated via ElementInternals with reset/required validity.
273
+ class ContourSearchField extends ContourBase {
274
+ static get observed() { return ["value", "placeholder", "label", "name", "required", "disabled"]; }
275
+ static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
276
+ static get formAssociated() { return true; }
277
+ render() {
278
+ this.classList.add("c-search-field");
279
+ const input = this.ensure("input", () => { const el = document.createElement("input"); el.type = "search"; el.className = "c-search-field__input"; return el; });
280
+ input.placeholder = this.getAttribute("placeholder") || "Search";
281
+ if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
282
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
283
+ if (this.hasAttribute("required")) input.setAttribute("required", "");
284
+ else input.removeAttribute("required");
285
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
286
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
287
+ const label = this.getAttribute("label");
288
+ if (label) input.setAttribute("aria-label", label);
289
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "search", "Search"));
290
+ }
291
+ enhance() {
292
+ const input = this.querySelector("input");
293
+ if (input && this._internals) {
294
+ this._internals.setFormValue(input.value);
295
+ this._syncValidity(this.hasAttribute("required") && !input.value.trim());
296
+ }
297
+ if (this._wiredSearchField) return;
298
+ this._wiredSearchField = true;
299
+ this.addEventListener("input", (e) => {
300
+ const t = e.target;
301
+ if (t && t.matches && t.matches("input")) {
302
+ if (this._internals) {
303
+ this._internals.setFormValue(t.value);
304
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
305
+ }
306
+ this._emitForm("contour:input");
307
+ }
308
+ });
309
+ this.addEventListener("change", (e) => {
310
+ const t = e.target;
311
+ if (!t || !t.matches || !t.matches("input") || !this._internals) return;
312
+ this._internals.setFormValue(t.value);
313
+ this._emitForm("contour:change");
314
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
315
+ });
316
+ }
317
+ }
318
+ define("contour-search-field", ContourSearchField);
319
+
320
+ // Density toggle: a two-state control (comfortable / compact) that sets a
321
+ // data-density attribute on the host. The consumer's CSS reads it.
322
+ class ContourDensityToggle extends ContourBase {
323
+ static get observed() { return ["value", "label"]; }
324
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
325
+ render() {
326
+ this.classList.add("c-density-toggle");
327
+ const value = this.getAttribute("value") || "comfortable";
328
+ this.setAttribute("data-density", value);
329
+ const btn = this.ensure("button", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-density-toggle__btn"; el.type = "button"; return el; });
330
+ const label = this.getAttribute("label") || (value === "compact" ? "Compact" : "Comfortable");
331
+ btn.textContent = label;
332
+ btn.setAttribute("aria-pressed", value === "compact" ? "true" : "false");
333
+ }
334
+ enhance() {
335
+ if (this._wiredDensityToggle) return;
336
+ this._wiredDensityToggle = true;
337
+ this.addEventListener("click", () => {
338
+ const next = this.getAttribute("data-density") === "compact" ? "comfortable" : "compact";
339
+ this.setAttribute("value", next);
340
+ this.setAttribute("data-density", next);
341
+ const btn = this.querySelector(".c-density-toggle__btn");
342
+ if (btn) { btn.textContent = next === "compact" ? "Compact" : "Comfortable"; btn.setAttribute("aria-pressed", next === "compact" ? "true" : "false"); }
343
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: next } }));
344
+ });
345
+ }
346
+ }
347
+ define("contour-density-toggle", ContourDensityToggle);
@@ -0,0 +1,292 @@
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
+ * Version: a `<select>` of version options from a JSON `options` attribute,
7
+ * with `selected` support per option. Form associated; emits `contour:change`.
8
+ */
9
+ class ContourVersionControl extends ContourBase {
10
+ static get observed() { return ["options", "items", "value", "name"]; }
11
+ static get formAssociated() { return true; }
12
+ static get properties() { return { options: { attribute: "options" }, items: { attribute: "items" }, value: { attribute: "value" }, name: { attribute: "name" } }; }
13
+ render() {
14
+ this.classList.add("c-version");
15
+ // Authored default captured before any commit reflects into `value`.
16
+ if (this._versionDefault === undefined) this._versionDefault = this.getAttribute("value");
17
+ const options = this.getAttribute("options") || this.getAttribute("items");
18
+ const generated = new Set(this._contourGenerated || []);
19
+ const authored = Array.from(this.children).filter((n) => !generated.has(n));
20
+ if (options && !authored.length) {
21
+ try {
22
+ const parsed = JSON.parse(options);
23
+ const select = this.ensure("select.c-version", () => { const el = document.createElement("select"); el.className = "c-version"; return el; });
24
+ select.innerHTML = "";
25
+ if (!select.hasAttribute("aria-label")) select.setAttribute("aria-label", labelText(this, "version", "Version"));
26
+ parsed.forEach((opt) => {
27
+ const option = document.createElement("option");
28
+ if (typeof opt === "string") { option.value = opt; option.textContent = opt; }
29
+ else { option.value = opt.value || opt.label; option.textContent = opt.label || opt.value; if (opt.selected) option.selected = true; }
30
+ select.appendChild(option);
31
+ });
32
+ if (select.parentNode !== this) this.appendChild(select);
33
+ this.classList.remove("c-version");
34
+ select.classList.add("c-version");
35
+ } catch (e) { warnBadJson(this, "attribute", e); }
36
+ }
37
+ // The committed value selects the option (R20 T-07): without this the
38
+ // host always submitted the first option regardless of `value`.
39
+ const sel = this.querySelector("select");
40
+ if (sel) {
41
+ if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
42
+ const val = this.getAttribute("value");
43
+ if (val !== null) sel.value = val;
44
+ }
45
+ }
46
+ enhance() {
47
+ const sync = () => {
48
+ const select = this.querySelector("select");
49
+ if (!select || !this._internals) return;
50
+ this._internals.setFormValue(select.value);
51
+ };
52
+ sync();
53
+ if (this._wiredVersion) return;
54
+ this._wiredVersion = true;
55
+ this.addEventListener("change", (e) => {
56
+ const select = this.querySelector("select");
57
+ if (!select || e.target !== select) return;
58
+ // Reflect the committed selection so a consumer reading `value` sees
59
+ // what the user picked, and a re-render rebuilds it.
60
+ this.setAttribute("value", select.value);
61
+ sync();
62
+ this._emitForm("contour:change");
63
+ });
64
+ }
65
+ formResetCallback() {
66
+ // Restore the authored default, not the first option (R20 T-08).
67
+ this._contourResetting = true;
68
+ try {
69
+ const def = this._versionDefault ?? null;
70
+ if (def === null) this.removeAttribute("value");
71
+ else this.setAttribute("value", def);
72
+ this._syncFormValue();
73
+ } finally {
74
+ this._contourResetting = false;
75
+ }
76
+ }
77
+ }
78
+ define("contour-version", ContourVersionControl);
79
+ /**
80
+ * Textarea: a `<textarea>` wrapper with placeholder, required, disabled, error
81
+ * and help states. Form associated; emits `contour:input` / `contour:change`.
82
+ */
83
+ class ContourTextarea extends ContourBase {
84
+ static get observed() { return ["placeholder", "required", "disabled", "error", "help", "value", "name", "label"]; }
85
+ static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, label: { attribute: "label" } }; }
86
+ static get formAssociated() { return true; }
87
+ render() {
88
+ const ta = this.ensure("textarea", () => { const el = document.createElement("textarea"); el.className = "c-textarea"; return el; });
89
+ ta.className = "c-textarea";
90
+ // value and name reach the generated control; typed text survives re-renders via base user-dirty tracking.
91
+ if (this.hasAttribute("name")) ta.name = this.getAttribute("name");
92
+ else ta.removeAttribute("name");
93
+ if (this.hasAttribute("value")) ta.value = this.getAttribute("value");
94
+ if (this.hasAttribute("aria-label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("aria-label"));
95
+ if (this.hasAttribute("label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("label"));
96
+ if (!ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", labelText(this, "textarea", "Textarea"));
97
+ if (this.hasAttribute("placeholder")) ta.placeholder = this.getAttribute("placeholder");
98
+ else ta.removeAttribute("placeholder");
99
+ if (this.hasAttribute("required")) ta.setAttribute("required", "");
100
+ else ta.removeAttribute("required");
101
+ if (this.hasAttribute("disabled")) { ta.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
102
+ else { ta.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
103
+ const err = this.getAttribute("error");
104
+ const help = this.getAttribute("help");
105
+ let msg = this.querySelector(".c-textarea__message");
106
+ if (err || help) {
107
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-textarea__message"; this.appendChild(msg); }
108
+ msg.textContent = err || help || "";
109
+ msg.classList.toggle("c-textarea__message--error", !!err);
110
+ } else if (msg) { msg.remove(); }
111
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
112
+ }
113
+ enhance() {
114
+ const ta = this.querySelector("textarea");
115
+ if (ta && this._internals) {
116
+ this._internals.setFormValue(ta.value);
117
+ this._syncValidity(this.hasAttribute("required") && !ta.value.trim());
118
+ }
119
+ if (this._wiredTextarea) return;
120
+ this._wiredTextarea = true;
121
+ this.addEventListener("input", (e) => {
122
+ const t = this.querySelector("textarea");
123
+ if (!t || e.target !== t || !this._internals) return;
124
+ this._internals.setFormValue(t.value);
125
+ this._emitForm("contour:input");
126
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
127
+ });
128
+ this.addEventListener("change", (e) => {
129
+ const t = this.querySelector("textarea");
130
+ if (!t || e.target !== t || !this._internals) return;
131
+ this._internals.setFormValue(t.value);
132
+ this._emitForm("contour:change");
133
+ this._syncValidity(this.hasAttribute("required") && !t.value.trim());
134
+ });
135
+ }
136
+ }
137
+ define("contour-textarea", ContourTextarea);
138
+ /**
139
+ * Input: an `<input>` wrapper with type, placeholder, required, value, disabled,
140
+ * error and help states. Form associated; emits `contour:input` / `contour:change`.
141
+ */
142
+ class ContourInputFull extends ContourBase {
143
+ static get observed() { return ["type", "placeholder", "required", "value", "disabled", "error", "help", "label", "name"]; }
144
+ static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, label: { attribute: "label" }, name: { attribute: "name" } }; }
145
+ static get formAssociated() { return true; }
146
+ render() {
147
+ this.classList.add("c-input");
148
+ const input = this.ensure("input", () => { const el = document.createElement("input"); el.className = "c-input"; return el; });
149
+ input.className = "c-input";
150
+ input.type = this.getAttribute("type") || "text";
151
+ input.placeholder = this.getAttribute("placeholder") || "";
152
+ // The name keys the base class's value/focus preservation and matches
153
+ // the native control's own contract (R20 T-02/T-08).
154
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
155
+ else input.removeAttribute("name");
156
+ let label = this.getAttribute("label");
157
+ if (!label) {
158
+ const field = this.closest("contour-field");
159
+ if (field) label = field.getAttribute("label");
160
+ }
161
+ if (label) input.setAttribute("aria-label", label);
162
+ else if (!input.getAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "input", "Input"));
163
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
164
+ if (this.hasAttribute("required")) input.setAttribute("required", "");
165
+ else input.removeAttribute("required");
166
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
167
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
168
+ // Error/help text
169
+ const err = this.getAttribute("error");
170
+ const help = this.getAttribute("help");
171
+ let msg = this.querySelector(".c-input__message");
172
+ if (err || help) {
173
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-input__message"; this.appendChild(msg); }
174
+ msg.textContent = err || help || "";
175
+ msg.classList.toggle("c-input__message--error", !!err);
176
+ } else if (msg) { msg.remove(); }
177
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
178
+ }
179
+ enhance() {
180
+ const input = this.querySelector("input");
181
+ if (input && this._internals) {
182
+ this._internals.setFormValue(input.value);
183
+ this._syncValidity(this.hasAttribute("required") && !input.value.trim());
184
+ }
185
+ if (this._wiredInput) return;
186
+ this._wiredInput = true;
187
+ this.addEventListener("input", (e) => {
188
+ const inp = this.querySelector("input");
189
+ if (!inp || e.target !== inp || !this._internals) return;
190
+ this._internals.setFormValue(inp.value);
191
+ this._emitForm("contour:input");
192
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
193
+ });
194
+ this.addEventListener("change", (e) => {
195
+ const inp = this.querySelector("input");
196
+ if (!inp || e.target !== inp || !this._internals) return;
197
+ this._internals.setFormValue(inp.value);
198
+ this._emitForm("contour:change");
199
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
200
+ });
201
+ }
202
+ }
203
+ define("contour-input", ContourInputFull);
204
+ /**
205
+ * InputGroup: a text input with an optional search icon, a clear (×) affordance
206
+ * and a submit (→) affordance. Attributes: `label`, `placeholder`, `clearable`,
207
+ * `submit`, `value`, `name`, `required`, `disabled`. Form associated: the host
208
+ * submits its value through ElementInternals. Emits `contour:input` /
209
+ * `contour:change`, and `contour:change` (bubbles, composed) with `{ value: "" }`
210
+ * on clear.
211
+ */
212
+ class ContourInputGroup extends ContourBase {
213
+ static get observed() { return ["label", "placeholder", "clearable", "submit", "value", "name", "required", "disabled"]; }
214
+ static get properties() { return { label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, clearable: { attribute: "clearable", type: Boolean }, submit: { attribute: "submit", type: Boolean }, value: { attribute: "value" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
215
+ static get formAssociated() { return true; }
216
+ render() {
217
+ this.classList.add("c-input-group");
218
+ 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; });
219
+ const input = this.ensure("input.c-input", () => { const el = document.createElement("input"); el.className = "c-input"; el.type = "text"; return el; });
220
+ input.placeholder = this.getAttribute("placeholder") || this.getAttribute("label") || "";
221
+ // Form participation (R20 T-05): the host submits through internals,
222
+ // and the inner control carries the name/value the author wrote.
223
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
224
+ else input.removeAttribute("name");
225
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
226
+ if (this.hasAttribute("required")) input.setAttribute("required", "");
227
+ else input.removeAttribute("required");
228
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
229
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
230
+ const label = this.getAttribute("label");
231
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", label || "Search");
232
+ // Clear affordance.
233
+ const oldClear = this.querySelector(".c-input-group__clear");
234
+ if (oldClear) oldClear.remove();
235
+ if (this.hasAttribute("clearable")) {
236
+ const btn = document.createElement("button");
237
+ btn.className = "c-input-group__clear";
238
+ btn.type = "button";
239
+ btn.setAttribute("aria-label", labelText(this, "clear", "Clear"));
240
+ btn.textContent = "×";
241
+ this.appendChild(btn);
242
+ }
243
+ // Submit affordance.
244
+ const oldSubmit = this.querySelector(".c-input-group__submit");
245
+ if (oldSubmit) oldSubmit.remove();
246
+ if (this.hasAttribute("submit")) {
247
+ const btn = document.createElement("button");
248
+ btn.className = "c-input-group__submit";
249
+ btn.type = "submit";
250
+ btn.setAttribute("aria-label", labelText(this, "submit", "Submit"));
251
+ btn.textContent = "→";
252
+ this.appendChild(btn);
253
+ }
254
+ }
255
+ enhance() {
256
+ const input = this.querySelector("input.c-input");
257
+ if (input && this._internals) {
258
+ this._internals.setFormValue(input.value);
259
+ this._syncValidity(this.hasAttribute("required") && !input.value.trim());
260
+ }
261
+ if (this._wiredInputGroup) return;
262
+ this._wiredInputGroup = true;
263
+ this.addEventListener("input", (e) => {
264
+ const inp = this.querySelector("input.c-input");
265
+ if (!inp || e.target !== inp || !this._internals) return;
266
+ this._internals.setFormValue(inp.value);
267
+ this._emitForm("contour:input");
268
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
269
+ });
270
+ this.addEventListener("change", (e) => {
271
+ const inp = this.querySelector("input.c-input");
272
+ if (!inp || e.target !== inp || !this._internals) return;
273
+ this._internals.setFormValue(inp.value);
274
+ this._emitForm("contour:change");
275
+ this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
276
+ });
277
+ this.addEventListener("click", (e) => {
278
+ const clear = e.target && e.target.closest ? e.target.closest(".c-input-group__clear") : null;
279
+ if (clear && this.contains(clear)) {
280
+ e.preventDefault();
281
+ const input = this.querySelector("input.c-input");
282
+ if (input) { input.value = ""; input.focus(); }
283
+ if (this._internals) {
284
+ this._internals.setFormValue("");
285
+ this._syncValidity(this.hasAttribute("required"));
286
+ }
287
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: "" } }));
288
+ }
289
+ });
290
+ }
291
+ }
292
+ define("contour-input-group", ContourInputGroup);