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,635 @@
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
+ /**
7
+ * Range: a native `<input type=range>` wrapper with optional dual-handle range
8
+ * mode (`range`, `low`, `high`) and a sparkline canvas (`sparkline`). Form
9
+ * associated; emits `contour:input` / `contour:change` with the current value
10
+ * (or `{low, high}` in range mode). Renders a `--fill` custom property for the
11
+ * filled track.
12
+ */
13
+ class ContourRange extends ContourBase {
14
+ static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help", "name", "step"]; }
15
+ static get formAssociated() { return true; }
16
+ static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, name: { attribute: "name" }, step: { attribute: "step" } }; }
17
+ render() {
18
+ this.classList.add("c-range");
19
+ const min = this.getAttribute("min") || "0";
20
+ const max = this.getAttribute("max") || "100";
21
+ const rangeMode = this.hasAttribute("range") || this.hasAttribute("low") || this.hasAttribute("high");
22
+ // sparkline canvas
23
+ const spark = this.getAttribute("sparkline");
24
+ if (spark) {
25
+ let canvas = this.querySelector(".c-range__sparkline");
26
+ if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-range__sparkline"; canvas.setAttribute("part", "sparkline-canvas"); canvas.setAttribute("aria-hidden", "true"); this.insertBefore(canvas, this.firstChild); }
27
+ // R31-67: the canvas was created but never painted. Draw the series.
28
+ this._drawRangeSpark(canvas, spark);
29
+ } else {
30
+ const c = this.querySelector(".c-range__sparkline");
31
+ if (c) c.remove();
32
+ }
33
+ if (rangeMode) {
34
+ // remove single input if present
35
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
36
+ // keep generic input? We'll use two named inputs
37
+ let lowInput = this.querySelector("input.c-range__low");
38
+ if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; lowInput.setAttribute("part", "input"); this.appendChild(lowInput); }
39
+ let highInput = this.querySelector("input.c-range__high");
40
+ if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; highInput.setAttribute("part", "input"); this.appendChild(highInput); }
41
+ lowInput.min = min; lowInput.max = max;
42
+ highInput.min = min; highInput.max = max;
43
+ const step = this.getAttribute("step");
44
+ if (step) { lowInput.step = step; highInput.step = step; } else { lowInput.removeAttribute("step"); highInput.removeAttribute("step"); }
45
+ if (this.hasAttribute("disabled")) { lowInput.setAttribute("disabled", ""); highInput.setAttribute("disabled", ""); } else { lowInput.removeAttribute("disabled"); highInput.removeAttribute("disabled"); }
46
+ const lowVal = this.getAttribute("low") || min;
47
+ const highVal = this.getAttribute("high") || max;
48
+ if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
49
+ else { lowInput.value = lowVal; this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
50
+ if (this._rangeUserHigh !== null && this._rangeAttrHighAtDirty === (this.getAttribute("high") || max)) highInput.value = this._rangeUserHigh;
51
+ else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
52
+ const label = this.getAttribute("label");
53
+ if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
54
+ // Remove hidden mirrors from previous dual render.
55
+ } else {
56
+ // remove dual inputs and any leftover mirrors from a dual render
57
+ Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high, input[type='hidden'][data-range]")).forEach((n) => n.remove());
58
+ const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; el.setAttribute("part", "input"); return el; });
59
+ // ensure class
60
+ input.className = "c-range";
61
+ input.type = "range";
62
+ input.min = min;
63
+ input.max = max;
64
+ const step = this.getAttribute("step");
65
+ if (step) input.step = step; else input.removeAttribute("step");
66
+ if (this.hasAttribute("disabled")) input.setAttribute("disabled", ""); else input.removeAttribute("disabled");
67
+ const attrVal = this.getAttribute("value") || "50";
68
+ if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
69
+ input.value = this._rangeUserValue;
70
+ } else {
71
+ input.value = attrVal;
72
+ this._rangeUserValue = null;
73
+ this._rangeAttrAtDirty = null;
74
+ }
75
+ const label = this.getAttribute("label");
76
+ if (label) input.setAttribute("aria-label", label);
77
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "range", "Range"));
78
+ const updateFill = () => {
79
+ const mn = Number(input.min) || 0;
80
+ const mx = Number(input.max) || 100;
81
+ const val = Number(input.value) || 0;
82
+ const pct = mx > mn ? ((val - mn) / (mx - mn)) * 100 : 0;
83
+ input.style.setProperty("--fill", pct + "%");
84
+ };
85
+ updateFill();
86
+ if (!input._fillWired) {
87
+ input._fillWired = true;
88
+ input.addEventListener("input", updateFill);
89
+ }
90
+ }
91
+ }
92
+ // R31-67: paint the sparkline series onto the canvas. The canvas has no
93
+ // box until it is laid out, so the first draw waits a frame; a 0-width
94
+ // canvas silently draws nothing.
95
+ _drawRangeSpark(canvas, raw) {
96
+ let nums = [];
97
+ try { const p = JSON.parse(raw); if (Array.isArray(p)) nums = p.map(Number).filter(Number.isFinite); } catch (e) { /* not JSON */ }
98
+ if (nums.length < 2) return;
99
+ const draw = () => {
100
+ if (!canvas.isConnected) return;
101
+ const w = canvas.clientWidth, h = canvas.clientHeight;
102
+ if (!w || !h) return;
103
+ const dpr = (typeof window !== "undefined" && window.devicePixelRatio) || 1;
104
+ canvas.width = Math.round(w * dpr);
105
+ canvas.height = Math.round(h * dpr);
106
+ const ctx = canvas.getContext && canvas.getContext("2d");
107
+ if (!ctx) return;
108
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
109
+ ctx.clearRect(0, 0, w, h);
110
+ const lo = Math.min.apply(null, nums), hi = Math.max.apply(null, nums), range = (hi - lo) || 1;
111
+ const pad = 2;
112
+ const x = (i) => (i / (nums.length - 1)) * (w - pad * 2) + pad;
113
+ const y = (v) => h - pad - ((v - lo) / range) * (h - pad * 2);
114
+ let stroke = "";
115
+ try { stroke = getComputedStyle(this).getPropertyValue("--chart-1").trim(); } catch (e) { /* no computed style */ }
116
+ if (!stroke || /^(var|light-dark)\(/.test(stroke)) stroke = "#1f77b4";
117
+ ctx.beginPath();
118
+ ctx.lineWidth = 1.5;
119
+ ctx.strokeStyle = stroke;
120
+ nums.forEach((v, i) => { const px = x(i), py = y(v); if (i === 0) ctx.moveTo(px, py); else ctx.lineTo(px, py); });
121
+ ctx.stroke();
122
+ };
123
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(draw); else draw();
124
+ }
125
+ }
126
+ // patch enhance onto ContourRange
127
+ const _origRangeRender = ContourRange.prototype.render;
128
+ ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
129
+ if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
130
+ if (name === "low") { this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
131
+ if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
132
+ return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
133
+ };
134
+ // Form value (R20 T-08): single submits handle value; dual submits two entries via FormData.
135
+ ContourRange.prototype._syncFormValue = function() {
136
+ if (!this._internals) return;
137
+ const low = this.querySelector("input.c-range__low");
138
+ const high = this.querySelector("input.c-range__high");
139
+ if (low && high) {
140
+ const name = this.getAttribute("name");
141
+ if (name) {
142
+ const fd = new FormData();
143
+ fd.append(name, low.value);
144
+ fd.append(name, high.value);
145
+ this._internals.setFormValue(fd);
146
+ } else {
147
+ this._internals.setFormValue(null);
148
+ }
149
+ } else {
150
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
151
+ if (single) this._internals.setFormValue(single.value);
152
+ }
153
+ };
154
+ ContourRange.prototype.formResetCallback = function() {
155
+ // Clear user-drag tracking so re-render reads authored defaults under resetting flag.
156
+ this._contourResetting = true;
157
+ try {
158
+ this._rangeUserValue = null; this._rangeAttrAtDirty = null;
159
+ this._rangeUserLow = null; this._rangeAttrLowAtDirty = null;
160
+ this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null;
161
+ if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
162
+ this._syncFormValue();
163
+ } finally {
164
+ this._contourResetting = false;
165
+ }
166
+ };
167
+ ContourRange.prototype.formStateRestoreCallback = function(state) {
168
+ if (!this._internals || state === null || state === undefined) return;
169
+ const low = this.querySelector("input.c-range__low");
170
+ const high = this.querySelector("input.c-range__high");
171
+ if (low && high && state instanceof FormData) {
172
+ const vals = state.getAll(this.getAttribute("name"));
173
+ if (vals.length >= 2) { low.value = String(vals[0]); high.value = String(vals[1]); }
174
+ } else {
175
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
176
+ if (single) single.value = String(state);
177
+ }
178
+ this._syncFormValue();
179
+ };
180
+ ContourRange.prototype.enhance = function() {
181
+ if (this._wiredRange) return;
182
+ this._wiredRange = true;
183
+ // R24-59: sync form value on every render, not only after _wiredRange guard.
184
+ this._syncFormValue();
185
+ const sync = () => { this._syncFormValue(); };
186
+ this.addEventListener("input", (e) => {
187
+ const low = this.querySelector("input.c-range__low");
188
+ const high = this.querySelector("input.c-range__high");
189
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
190
+ if (low && high && (e.target === low || e.target === high)) {
191
+ this._rangeUserLow = low.value;
192
+ this._rangeUserHigh = high.value;
193
+ this._rangeAttrLowAtDirty = this.getAttribute("low") || (this.getAttribute("min") || "0");
194
+ this._rangeAttrHighAtDirty = this.getAttribute("high") || (this.getAttribute("max") || "100");
195
+ sync();
196
+ this._emitForm("contour:input", { low: Number(low.value), high: Number(high.value) });
197
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
198
+ } else if (single && e.target === single) {
199
+ this._rangeUserValue = single.value;
200
+ this._rangeAttrAtDirty = this.getAttribute("value") || "50";
201
+ sync();
202
+ this._emitForm("contour:input");
203
+ }
204
+ });
205
+ this.addEventListener("change", (e) => {
206
+ const low = this.querySelector("input.c-range__low");
207
+ const high = this.querySelector("input.c-range__high");
208
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
209
+ if (low && high && (e.target === low || e.target === high)) {
210
+ sync();
211
+ this._emitForm("contour:change", { low: Number(low.value), high: Number(high.value) });
212
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
213
+ } else if (single && e.target === single) {
214
+ sync();
215
+ this._emitForm("contour:change");
216
+ }
217
+ });
218
+ sync();
219
+ };
220
+ define("contour-range", ContourRange);
221
+ /**
222
+ * Switch: a `role="switch"` checkbox control with label, required, disabled,
223
+ * error and help states. Form associated; emits `contour:change` on toggle.
224
+ * The input's ::after draws the track; there is no separate track element.
225
+ */
226
+ class ContourSwitch extends ContourBase {
227
+ static get observed() { return ["label", "required", "checked", "disabled", "error", "help"]; }
228
+ 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" } }; }
229
+ static get formAssociated() { return true; }
230
+ render() {
231
+ this.classList.add("c-switch");
232
+ // Authored default captured before toggle reflects into checked.
233
+ if (this._switchDefaultChecked === undefined) this._switchDefaultChecked = this.hasAttribute("checked");
234
+ const label = this.getAttribute("label");
235
+ // Guide's control is label.c-switch wrapping input; sheet paints track on input.
236
+ const input = this.ensure("input.c-switch__input", () => { const el = document.createElement("input"); el.className = "c-switch__input"; el.type = "checkbox"; return el; });
237
+ input.checked = this.hasAttribute("checked");
238
+ input.setAttribute("role", "switch");
239
+ input.setAttribute("aria-checked", String(input.checked));
240
+ this._setCustomState("data-checked", input.checked);
241
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
242
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
243
+ const err = this.getAttribute("error");
244
+ const help = this.getAttribute("help");
245
+ let msg = this.querySelector(".c-switch__message");
246
+ if (err || help) {
247
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-switch__message"; this.appendChild(msg); }
248
+ msg.textContent = err || help || "";
249
+ msg.classList.toggle("c-switch__message--error", !!err);
250
+ } else if (msg) { msg.remove(); }
251
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
252
+ // Input's ::after draws track; separate track span would be unstyled (R18-41).
253
+ if (label) {
254
+ input.setAttribute("aria-label", label);
255
+ const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
256
+ txt.textContent = label;
257
+ }
258
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "switch", "Switch"));
259
+ }
260
+ enhance() {
261
+ const input = this.querySelector("input");
262
+ if (input && this._internals) {
263
+ input.setAttribute("aria-checked", String(input.checked));
264
+ this._setCustomState("data-checked", input.checked);
265
+ this._internals.setFormValue(input.checked ? (input.value || "on") : null);
266
+ this._syncValidity(this.hasAttribute("required") && !input.checked);
267
+ }
268
+ if (this._wiredSwitch) return;
269
+ this._wiredSwitch = true;
270
+ // Label activation: host not native label, click text/track toggles input; input click left to platform.
271
+ this.addEventListener("click", (e) => {
272
+ if (e.target && e.target.closest && e.target.closest("input")) return;
273
+ const inp = this.querySelector("input");
274
+ if (!inp || inp.disabled) return;
275
+ e.preventDefault();
276
+ inp.click();
277
+ });
278
+ this.addEventListener("change", (e) => {
279
+ const inp = this.querySelector("input");
280
+ if (!inp || e.target !== inp || !this._internals) return;
281
+ inp.setAttribute("aria-checked", String(inp.checked));
282
+ this._setCustomState("data-checked", inp.checked);
283
+ this._setCustomState("data-indeterminate", false);
284
+ this.removeAttribute("indeterminate");
285
+ this.toggleAttribute("checked", inp.checked);
286
+ this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
287
+ this._emitForm("contour:change");
288
+ this._syncValidity(this.hasAttribute("required") && !inp.checked);
289
+ });
290
+ }
291
+ formResetCallback() {
292
+ // checked reflected on toggle; authored default from first-render capture (R20 T-08).
293
+ this._contourResetting = true;
294
+ try {
295
+ this.toggleAttribute("checked", !!this._switchDefaultChecked);
296
+ const inp = this.querySelector("input");
297
+ if (inp) inp.checked = this.hasAttribute("checked");
298
+ this._syncFormValue();
299
+ } finally {
300
+ this._contourResetting = false;
301
+ }
302
+ }
303
+ }
304
+ define("contour-switch", ContourSwitch);
305
+ /**
306
+ * Check: a checkbox (or `type="radio"` when `type` is set) with label, name,
307
+ * value, required, checked, disabled, error and help states. The input's
308
+ * ::after draws the box; there is no separate box element. Form associated;
309
+ * emits `contour:change` on toggle.
310
+ */
311
+ class ContourCheck extends ContourBase {
312
+ static get observed() { return ["label", "name", "value", "required", "type", "checked", "indeterminate", "disabled", "error", "help"]; }
313
+ 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 }, indeterminate: { attribute: "indeterminate", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
314
+ static get formAssociated() { return true; }
315
+ render() {
316
+ this.classList.add("c-check");
317
+ // Authored default captured before toggle reflects into checked.
318
+ if (this._checkDefaultChecked === undefined) this._checkDefaultChecked = this.hasAttribute("checked");
319
+ const label = this.getAttribute("label");
320
+ 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; });
321
+ input.checked = this.hasAttribute("checked");
322
+ input.indeterminate = this.hasAttribute("indeterminate") && !input.checked;
323
+ // Input's ::after draws box; separate box span would be unstyled (R18-41).
324
+ if (label) {
325
+ input.setAttribute("aria-label", label);
326
+ const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
327
+ txt.textContent = label;
328
+ }
329
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "checkbox", "Checkbox"));
330
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
331
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
332
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
333
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
334
+ const err = this.getAttribute("error");
335
+ const help = this.getAttribute("help");
336
+ let msg = this.querySelector(".c-check__message");
337
+ if (err || help) {
338
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-check__message"; this.appendChild(msg); }
339
+ msg.textContent = err || help || "";
340
+ msg.classList.toggle("c-check__message--error", !!err);
341
+ } else if (msg) { msg.remove(); }
342
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
343
+ }
344
+ enhance() {
345
+ const input = this.querySelector("input");
346
+ if (input && this._internals) {
347
+ this._setCustomState("data-checked", input.checked);
348
+ this._setCustomState("data-indeterminate", input.indeterminate);
349
+ this._internals.setFormValue(input.checked ? (input.value || "on") : null);
350
+ this._syncValidity(this.hasAttribute("required") && !input.checked);
351
+ }
352
+ if (this._wiredCheck) return;
353
+ this._wiredCheck = true;
354
+ // Label activation: host not native label, click text/box toggles input; input click left to platform.
355
+ this.addEventListener("click", (e) => {
356
+ if (e.target && e.target.closest && e.target.closest("input")) return;
357
+ const inp = this.querySelector("input");
358
+ if (!inp || inp.disabled) return;
359
+ e.preventDefault();
360
+ inp.click();
361
+ });
362
+ this.addEventListener("change", (e) => {
363
+ const inp = this.querySelector("input");
364
+ if (!inp || e.target !== inp || !this._internals) return;
365
+ this._setCustomState("data-checked", inp.checked);
366
+ this._setCustomState("data-indeterminate", false);
367
+ this.removeAttribute("indeterminate");
368
+ this.toggleAttribute("checked", inp.checked);
369
+ this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
370
+ this._emitForm("contour:change");
371
+ this._syncValidity(this.hasAttribute("required") && !inp.checked);
372
+ });
373
+ }
374
+ formResetCallback() {
375
+ // Same default-capture contract as contour-switch (R20 T-08).
376
+ this._contourResetting = true;
377
+ try {
378
+ this.toggleAttribute("checked", !!this._checkDefaultChecked);
379
+ const inp = this.querySelector("input");
380
+ if (inp) inp.checked = this.hasAttribute("checked");
381
+ this._syncFormValue();
382
+ } finally {
383
+ this._contourResetting = false;
384
+ }
385
+ }
386
+ }
387
+ define("contour-check", ContourCheck);
388
+ /**
389
+ * Radio: a radio button with label, name, value, required, checked, disabled,
390
+ * error and help states. Form associated; unchecking clears the stale FormData
391
+ * entry. Emits `contour:change` on toggle.
392
+ */
393
+ class ContourRadio extends ContourBase {
394
+ static get observed() { return ["label", "name", "value", "required", "checked", "disabled", "error", "help"]; }
395
+ 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" } }; }
396
+ static get formAssociated() { return true; }
397
+ render() {
398
+ this.classList.add("c-radio");
399
+ const label = this.getAttribute("label");
400
+ const input = this.ensure("input.c-radio__input", () => { const el = document.createElement("input"); el.className = "c-radio__input"; el.type = "radio"; return el; });
401
+ input.checked = this.hasAttribute("checked");
402
+ if (this.hasAttribute("name")) input.name = this.getAttribute("name");
403
+ if (this.hasAttribute("value")) input.value = this.getAttribute("value");
404
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
405
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
406
+ const err = this.getAttribute("error");
407
+ const help = this.getAttribute("help");
408
+ let msg = this.querySelector(".c-radio__message");
409
+ if (err || help) {
410
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-radio__message"; this.appendChild(msg); }
411
+ msg.textContent = err || help || "";
412
+ msg.classList.toggle("c-radio__message--error", !!err);
413
+ } else if (msg) { msg.remove(); }
414
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
415
+ if (label) {
416
+ input.setAttribute("aria-label", label);
417
+ const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
418
+ txt.textContent = label;
419
+ }
420
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", labelText(this, "radio", "Radio"));
421
+ }
422
+ enhance() {
423
+ const input = this.querySelector("input");
424
+ if (input && this._internals) {
425
+ this._setCustomState("data-checked", input.checked);
426
+ this._setCustomState("data-indeterminate", input.indeterminate);
427
+ this._internals.setFormValue(input.checked ? (input.value || "on") : null);
428
+ this._syncValidity(this.hasAttribute("required") && !input.checked);
429
+ }
430
+ if (this._wiredRadio) return;
431
+ this._wiredRadio = true;
432
+ // Label activation: host not native label, click text selects radio; input click left to platform.
433
+ this.addEventListener("click", (e) => {
434
+ if (e.target && e.target.closest && e.target.closest("input")) return;
435
+ const inp = this.querySelector("input");
436
+ if (!inp || inp.disabled) return;
437
+ e.preventDefault();
438
+ inp.click();
439
+ });
440
+ this.addEventListener("change", (e) => {
441
+ const inp = this.querySelector("input");
442
+ if (!inp || e.target !== inp || !this._internals) return;
443
+ // Unchecking (group movement) must clear stale FormData entry.
444
+ this._setCustomState("data-checked", inp.checked);
445
+ this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
446
+ this._emitForm("contour:change");
447
+ this._syncValidity(this.hasAttribute("required") && !inp.checked);
448
+ });
449
+ }
450
+ }
451
+ define("contour-radio", ContourRadio);
452
+ /**
453
+ * Select: a native `<select>` wrapper populated from a JSON `options` attribute
454
+ * (with optgroup support) or an authored `<select>`. Supports label, placeholder,
455
+ * required, disabled, error and help. Form associated; emits `contour:change`.
456
+ */
457
+ class ContourSelect extends ContourBase {
458
+ static get observed() { return ["options", "items", "required", "label", "placeholder", "disabled", "error", "help", "value", "name", "multiple", "autocomplete"]; }
459
+ static get properties() { return { options: { attribute: "options" }, items: { attribute: "items" }, required: { attribute: "required", type: Boolean }, label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, multiple: { attribute: "multiple", type: Boolean }, autocomplete: { attribute: "autocomplete" } }; }
460
+ static get formAssociated() { return true; }
461
+ render() {
462
+ this.classList.add("c-select");
463
+ // Authored default captured before commit reflects into value.
464
+ if (this._selectDefault === undefined) this._selectDefault = this.getAttribute("value");
465
+ const options = this.getAttribute("options") || this.getAttribute("items");
466
+ // Slot composition: authored <select> wins over JSON attribute.
467
+ const generated = new Set(this._contourGenerated || []);
468
+ const authored = Array.from(this.children).filter((n) => !generated.has(n));
469
+ if (options && !authored.length) {
470
+ try {
471
+ const parsed = JSON.parse(options);
472
+ const select = this.ensure("select.c-select", () => { const el = document.createElement("select"); el.className = "c-select"; return el; });
473
+ select.innerHTML = "";
474
+ const label = this.getAttribute("label");
475
+ if (label) {
476
+ select.setAttribute("aria-label", label);
477
+ }
478
+ const placeholder = this.getAttribute("placeholder");
479
+ if (placeholder) {
480
+ const ph = document.createElement("option");
481
+ ph.value = "";
482
+ ph.textContent = placeholder;
483
+ ph.disabled = true;
484
+ ph.selected = true;
485
+ select.appendChild(ph);
486
+ }
487
+ // Group support.
488
+ const groups = {};
489
+ parsed.forEach((opt) => {
490
+ const g = (typeof opt === "object" && opt !== null) ? opt.group : null;
491
+ if (g) {
492
+ if (!groups[g]) { groups[g] = document.createElement("optgroup"); groups[g].label = g; select.appendChild(groups[g]); }
493
+ const option = document.createElement("option");
494
+ option.value = typeof opt === "string" ? opt : opt.value;
495
+ option.textContent = typeof opt === "string" ? opt : opt.label;
496
+ groups[g].appendChild(option);
497
+ } else {
498
+ const option = document.createElement("option");
499
+ option.value = typeof opt === "string" ? opt : opt.value;
500
+ option.textContent = typeof opt === "string" ? opt : opt.label;
501
+ select.appendChild(option);
502
+ }
503
+ });
504
+ if (select.parentNode !== this) this.appendChild(select);
505
+ this.classList.remove("c-select");
506
+ select.classList.add("c-select");
507
+ } catch (e) { warnBadJson(this, "attribute", e); }
508
+ }
509
+ // Ensure authored select gets c-select styling.
510
+ const authoredSel = this.querySelector("select");
511
+ if (authoredSel && !authoredSel.classList.contains("c-select")) {
512
+ authoredSel.classList.add("c-select");
513
+ this.classList.remove("c-select");
514
+ }
515
+ // Disabled / error / help contract (applies to authored or generated select).
516
+ const sel = this.querySelector("select");
517
+ if (sel) {
518
+ if (this.hasAttribute("disabled")) { sel.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
519
+ else { sel.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
520
+ // Reflect native attrs: FormData needs name, multi-select needs multiple, value is committed selection.
521
+ if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
522
+ if (this.hasAttribute("multiple")) sel.setAttribute("multiple", ""); else sel.removeAttribute("multiple");
523
+ if (this.hasAttribute("autocomplete")) sel.setAttribute("autocomplete", this.getAttribute("autocomplete"));
524
+ if (this.hasAttribute("required")) sel.setAttribute("required", ""); else sel.removeAttribute("required");
525
+ const val = this.getAttribute("value");
526
+ if (val !== null) {
527
+ if (sel.multiple) {
528
+ const wanted = new Set(String(val).split(",").map((v) => v.trim()).filter(Boolean));
529
+ Array.from(sel.options).forEach((o) => { o.selected = wanted.has(o.value); });
530
+ } else {
531
+ sel.value = val;
532
+ }
533
+ }
534
+ }
535
+ // Label (applies to both JSON and authored options).
536
+ const label = this.getAttribute("label");
537
+ if (label) {
538
+ let lbl = this.querySelector("label.c-select__label");
539
+ if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; this.insertBefore(lbl, sel || this.firstChild); }
540
+ lbl.textContent = label;
541
+ if (sel) {
542
+ if (!sel.id) sel.id = contourId("contour-select");
543
+ lbl.setAttribute("for", sel.id);
544
+ sel.setAttribute("aria-label", label);
545
+ }
546
+ }
547
+ if (!this.querySelector("select")?.hasAttribute("aria-label")) {
548
+ const sel = this.querySelector("select");
549
+ if (sel) sel.setAttribute("aria-label", labelText(this, "select", "Select"));
550
+ }
551
+ const err = this.getAttribute("error");
552
+ const help = this.getAttribute("help");
553
+ let msg = this.querySelector(".c-select__message");
554
+ if (err || help) {
555
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-select__message"; this.appendChild(msg); }
556
+ msg.textContent = err || help || "";
557
+ msg.classList.toggle("c-select__message--error", !!err);
558
+ } else if (msg) { msg.remove(); }
559
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
560
+ }
561
+ enhance() {
562
+ if (this._internals) this._syncFormValue();
563
+ if (this._wiredSelect) return;
564
+ this._wiredSelect = true;
565
+ this.addEventListener("input", (e) => {
566
+ const sel = this.querySelector("select");
567
+ if (!sel || e.target !== sel) return;
568
+ this._emitForm("contour:input");
569
+ });
570
+ this.addEventListener("change", (e) => {
571
+ const sel = this.querySelector("select");
572
+ if (!sel || e.target !== sel || !this._internals) return;
573
+ // Reflect whole selection: multi-select sel.value is first only; reflected attr rebuilds on re-render (R20 T-06).
574
+ const committed = sel.multiple ? Array.from(sel.selectedOptions).map((o) => o.value).join(",") : sel.value;
575
+ this.setAttribute("value", committed);
576
+ this._syncFormValue();
577
+ this._emitForm("contour:change");
578
+ });
579
+ }
580
+ // Multi-select submits every selected option under the host name (not select.value); base generic must not collapse to one entry.
581
+ _syncFormValue() {
582
+ if (!this._internals) return;
583
+ const sel = this.querySelector("select");
584
+ if (!sel) return;
585
+ if (sel.multiple) {
586
+ const chosen = Array.from(sel.selectedOptions).map((o) => o.value);
587
+ const name = this.getAttribute("name");
588
+ if (name && chosen.length) {
589
+ const fd = new FormData();
590
+ for (const v of chosen) fd.append(name, v);
591
+ this._internals.setFormValue(fd);
592
+ } else {
593
+ this._internals.setFormValue(null);
594
+ }
595
+ this._syncValidity(this.hasAttribute("required") && !chosen.length);
596
+ } else {
597
+ this._internals.setFormValue(sel.value);
598
+ this._syncValidity(this.hasAttribute("required") && !sel.value);
599
+ }
600
+ }
601
+ formResetCallback() {
602
+ // Restore authored default (not first option or last commit); resetting flag keeps base restore out.
603
+ this._contourResetting = true;
604
+ try {
605
+ const def = this._selectDefault ?? null;
606
+ if (def === null) this.removeAttribute("value");
607
+ else this.setAttribute("value", def);
608
+ this._syncFormValue();
609
+ } finally {
610
+ this._contourResetting = false;
611
+ }
612
+ }
613
+ formStateRestoreCallback(state) {
614
+ const sel = this.querySelector("select");
615
+ if (!sel || !this._internals) return;
616
+ const values = state instanceof FormData
617
+ ? Array.from(state.getAll(this.getAttribute("name"))).map(String)
618
+ : (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
619
+ this._contourResetting = true;
620
+ try {
621
+ if (sel.multiple) {
622
+ const wanted = new Set(values);
623
+ for (const o of sel.options) o.selected = wanted.has(o.value);
624
+ this.setAttribute("value", values.join(","));
625
+ } else {
626
+ sel.value = values[0] || "";
627
+ this.setAttribute("value", sel.value);
628
+ }
629
+ this._syncFormValue();
630
+ } finally {
631
+ this._contourResetting = false;
632
+ }
633
+ }
634
+ }
635
+ define("contour-select", ContourSelect);