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,1570 @@
1
+ import { setHTML, ContourBase, define, contourId, onDispose, navKey, safeColor, safeHref, cssLength , warnBadJson, labelText, flagOn, formatValue, wcEmitOverlay } from './core.mjs';
2
+ import { wireRemovable, modalContain } from './behaviours.mjs';
3
+ import { parseArrayAttr, renderEmpty } from './states.mjs';
4
+
5
+ /**
6
+ * Responsive Content: web component wrapper.
7
+ * Attributes: `breakpoint`.
8
+ */
9
+ class ContourResponsiveContent extends ContourBase {
10
+ static get observed() { return ["breakpoint"]; }
11
+ static get properties() { return { breakpoint: { attribute: "breakpoint" } }; }
12
+ render() {
13
+ this.classList.add("c-responsive-content");
14
+ const bp = this.getAttribute("breakpoint") || "md";
15
+ this.dataset.breakpoint = bp;
16
+ }
17
+ }
18
+ define("contour-responsive-content", ContourResponsiveContent);
19
+ /**
20
+ * Palette Editor: web component wrapper.
21
+ * Attributes: `colors`.
22
+ */
23
+ class ContourPaletteEditor extends ContourBase {
24
+ static get observed() { return ["colors"]; }
25
+ static get properties() { return { colors: { attribute: "colors" } }; }
26
+ _palette() {
27
+ let parsed = [];
28
+ try { const c = this.getAttribute("colors"); parsed = c ? JSON.parse(c) : []; } catch (e) { warnBadJson(this, "colors", e); }
29
+ if (!Array.isArray(parsed)) parsed = [];
30
+ return parsed.map((c) => typeof c === "string" ? { color: c, name: c } : { color: String(c.color || c.value || "#000000"), name: String(c.name || c.label || c.color || c.value || "color") });
31
+ }
32
+ _writePalette(entries) {
33
+ // Colors attribute IS the serialization: every edit/add/remove writes it back, so re-render keeps user's work.
34
+ this.setAttribute("colors", JSON.stringify(entries.map((e) => e.name === e.color ? e.color : { color: e.color, name: e.name })));
35
+ }
36
+ render() {
37
+ this.classList.add("c-palette-editor");
38
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
39
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "palette-editor", "Palette editor"));
40
+ const entries = this._palette();
41
+ Array.from(this.querySelectorAll(".c-palette-editor__swatch, .c-palette-editor__edit, .c-palette-editor__remove, .c-palette-editor__add, .c-palette-editor__contrast")).forEach((n) => n.remove());
42
+ entries.forEach((entry, i) => {
43
+ const sw = document.createElement("button");
44
+ sw.className = "c-palette-editor__swatch c-swatch" + (this._paletteSelected === i ? " is-selected" : "");
45
+ sw.type = "button";
46
+ sw.style.background = safeColor(entry.color);
47
+ sw.dataset.color = entry.color;
48
+ sw.dataset.index = String(i);
49
+ sw.setAttribute("aria-label", entry.name);
50
+ sw.setAttribute("aria-pressed", String(this._paletteSelected === i));
51
+ this.appendChild(sw);
52
+ // Native color input is the edit surface — platform's picker, not reinvented.
53
+ const edit = document.createElement("input");
54
+ edit.type = "color";
55
+ edit.className = "c-palette-editor__edit";
56
+ edit.value = /^#[0-9a-f]{6}$/i.test(entry.color) ? entry.color : "#000000";
57
+ edit.dataset.index = String(i);
58
+ edit.setAttribute("aria-label", labelText(this, "edit", "Edit") + " " + entry.name);
59
+ this.appendChild(edit);
60
+ const rm = document.createElement("button");
61
+ rm.type = "button";
62
+ rm.className = "c-palette-editor__remove";
63
+ rm.dataset.index = String(i);
64
+ rm.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + entry.name);
65
+ rm.textContent = "×";
66
+ this.appendChild(rm);
67
+ });
68
+ const add = document.createElement("button");
69
+ add.type = "button";
70
+ add.className = "c-palette-editor__add";
71
+ add.setAttribute("aria-label", labelText(this, "add-color", "Add color"));
72
+ add.textContent = "+";
73
+ this.appendChild(add);
74
+ // Contrast feedback for selected color: ratio against white/black, whether better meets AA.
75
+ const sel = entries[this._paletteSelected];
76
+ if (sel) {
77
+ const lum = (hex) => {
78
+ const m = /^#([0-9a-f]{6})$/i.exec(hex);
79
+ if (!m) return null;
80
+ const n = parseInt(m[1], 16);
81
+ const ch = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); });
82
+ return 0.2126 * ch[0] + 0.7152 * ch[1] + 0.0722 * ch[2];
83
+ };
84
+ const l = lum(sel.color);
85
+ const out = document.createElement("span");
86
+ out.className = "c-palette-editor__contrast";
87
+ if (l === null) {
88
+ out.textContent = sel.color;
89
+ } else {
90
+ const ratio = (a, b) => (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
91
+ const onWhite = ratio(l, 1), onBlack = ratio(l, 0);
92
+ const best = Math.max(onWhite, onBlack);
93
+ out.textContent = sel.name + ": " + onWhite.toFixed(1) + ":1 on white, " + onBlack.toFixed(1) + ":1 on black — " + (best >= 4.5 ? "AA" : "below AA");
94
+ }
95
+ this.appendChild(out);
96
+ }
97
+ }
98
+ enhance() {
99
+ if (this._wiredPaletteEditor) return;
100
+ this._wiredPaletteEditor = true;
101
+ this.addEventListener("click", (e) => {
102
+ const t = e.target && e.target.closest ? e.target : null;
103
+ if (!t) return;
104
+ const sw = t.closest(".c-palette-editor__swatch");
105
+ if (sw && this.contains(sw)) {
106
+ this._paletteSelected = Number(sw.dataset.index);
107
+ this.requestRender();
108
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: sw.dataset.color } }));
109
+ return;
110
+ }
111
+ const rm = t.closest(".c-palette-editor__remove");
112
+ if (rm && this.contains(rm)) {
113
+ const entries = this._palette();
114
+ const i = Number(rm.dataset.index);
115
+ const [gone] = entries.splice(i, 1);
116
+ if (this._paletteSelected >= entries.length) this._paletteSelected = entries.length - 1;
117
+ this._writePalette(entries);
118
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: gone ? gone.color : "" } }));
119
+ return;
120
+ }
121
+ if (t.closest(".c-palette-editor__add")) {
122
+ const entries = this._palette();
123
+ const next = "#888888";
124
+ entries.push({ color: next, name: next });
125
+ this._paletteSelected = entries.length - 1;
126
+ this._writePalette(entries);
127
+ this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: next } }));
128
+ }
129
+ });
130
+ this.addEventListener("change", (e) => {
131
+ const edit = e.target && e.target.closest ? e.target.closest(".c-palette-editor__edit") : null;
132
+ if (!edit || !this.contains(edit)) return;
133
+ const entries = this._palette();
134
+ const i = Number(edit.dataset.index);
135
+ if (!entries[i]) return;
136
+ entries[i].color = edit.value;
137
+ if (entries[i].name === entries[i].color || /^#[0-9a-f]{6}$/i.test(entries[i].name)) entries[i].name = edit.value;
138
+ this._writePalette(entries);
139
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { color: edit.value, values: entries.map((en) => en.color) } }));
140
+ });
141
+ this.addEventListener("keydown", (e) => {
142
+ const swatches = Array.from(this.querySelectorAll(".c-palette-editor__swatch"));
143
+ if (!swatches.includes(e.target)) return;
144
+ navKey(e, swatches, { wrap: true, enter: true, onKey: (k, idx, item) => { if (k === "Enter" || k === " ") item.click(); } });
145
+ });
146
+ }
147
+ }
148
+ define("contour-palette-editor", ContourPaletteEditor);
149
+
150
+ /**
151
+ * Date Range: two native date (or datetime-local with `time`) inputs with a
152
+ * shared label. Attributes: `start`, `end`, `label`, `time`, `min`, `max`,
153
+ * `locale`, `name`, `required`, `disabled`. Form associated (R20 T-16): the
154
+ * host submits the two dates as repeated entries under its name, reports
155
+ * required/inverted validity, and resets to the authored defaults. The
156
+ * inputs are distinctly named for assistive tech and cross-constrained
157
+ * (end.min = start, start.max = end); a committed change writes start/end
158
+ * back. The native pickers supply the calendar; timezone is the consumer's
159
+ * (the values are local ISO strings, date-only unless `time`).
160
+ */
161
+ class ContourDateRange extends ContourBase {
162
+ static get observed() { return ["start", "end", "label", "time", "min", "max", "locale", "name", "required", "disabled"]; }
163
+ static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, label: { attribute: "label" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
164
+ static get formAssociated() { return true; }
165
+ render() {
166
+ this.classList.add("c-date-range");
167
+ // Authored defaults captured before commit reflects into them.
168
+ if (this._dateRangeDefaultStart === undefined) {
169
+ this._dateRangeDefaultStart = this.getAttribute("start");
170
+ this._dateRangeDefaultEnd = this.getAttribute("end");
171
+ }
172
+ this.setAttribute("role", "group");
173
+ this.setAttribute("aria-label", this.getAttribute("label") || "Date range");
174
+ const label = this.getAttribute("label");
175
+ if (label) {
176
+ const l = this.ensure(".c-date-range__label", () => { const el = document.createElement("span"); el.className = "c-date-range__label"; return el; });
177
+ l.textContent = label;
178
+ }
179
+ const start = this.ensure(".c-date-range__start", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__start"; return el; });
180
+ start.type = this.hasAttribute("time") ? "datetime-local" : "date";
181
+ start.value = this.getAttribute("start") || "";
182
+ // Distinct names: both inputs had identical aria-label, so screen reader couldn't tell start from end.
183
+ start.setAttribute("aria-label", label ? label + " — start" : "Start date");
184
+ const end = this.ensure(".c-date-range__end", () => { const el = document.createElement("input"); el.className = "c-input c-date-range__end"; return el; });
185
+ end.type = start.type;
186
+ end.value = this.getAttribute("end") || "";
187
+ end.setAttribute("aria-label", label ? label + " — end" : "End date");
188
+ const min = this.getAttribute("min");
189
+ const max = this.getAttribute("max");
190
+ [start, end].forEach((input) => {
191
+ if (min) input.min = min; else input.removeAttribute("min");
192
+ if (max) input.max = max; else input.removeAttribute("max");
193
+ if (this.getAttribute("locale")) input.lang = this.getAttribute("locale");
194
+ if (this.hasAttribute("disabled")) input.setAttribute("disabled", ""); else input.removeAttribute("disabled");
195
+ });
196
+ // Cross-constraint: picker cannot offer inverted range.
197
+ if (start.value) end.min = min && min > start.value ? min : start.value;
198
+ if (end.value) start.max = max && max < end.value ? max : end.value;
199
+ if (this.hasAttribute("required")) this.setAttribute("aria-required", "true"); else this.removeAttribute("aria-required");
200
+ if (this._internals) this._syncFormValue();
201
+ }
202
+ enhance() {
203
+ if (this._wiredDateRange) return;
204
+ this._wiredDateRange = true;
205
+ this.addEventListener("change", (e) => {
206
+ const t = e.target;
207
+ if (t && (t.classList.contains("c-date-range__start") || t.classList.contains("c-date-range__end"))) {
208
+ const s = this.querySelector(".c-date-range__start");
209
+ const en = this.querySelector(".c-date-range__end");
210
+ // Commit writes back; re-render re-applies values and refreshes cross-constraint.
211
+ this.batch(() => {
212
+ if (s) this.setAttribute("start", s.value);
213
+ if (en) this.setAttribute("end", en.value);
214
+ });
215
+ this._syncFormValue();
216
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { start: s?.value, end: en?.value } }));
217
+ }
218
+ });
219
+ }
220
+ _syncFormValue() {
221
+ if (!this._internals) return;
222
+ const start = this.querySelector(".c-date-range__start")?.value || "";
223
+ const end = this.querySelector(".c-date-range__end")?.value || "";
224
+ const name = this.getAttribute("name");
225
+ if (name && (start || end)) {
226
+ const fd = new FormData();
227
+ if (start) fd.append(name, start);
228
+ if (end) fd.append(name, end);
229
+ this._internals.setFormValue(fd);
230
+ } else {
231
+ this._internals.setFormValue(null);
232
+ }
233
+ const missing = this.hasAttribute("required") && (!start || !end);
234
+ const inverted = !!(start && end && start > end);
235
+ if (missing) this._internals.setValidity({ valueMissing: true }, "Both dates are required.");
236
+ else if (inverted) this._internals.setValidity({ customError: true }, "Start must be on or before end.");
237
+ else this._internals.setValidity({});
238
+ this._setCustomState("data-invalid", missing || inverted);
239
+ for (const input of this.querySelectorAll("input")) input.setAttribute("aria-invalid", String(missing || inverted));
240
+ }
241
+ formResetCallback() {
242
+ this._contourResetting = true;
243
+ try {
244
+ if (this._dateRangeDefaultStart === null) this.removeAttribute("start"); else this.setAttribute("start", this._dateRangeDefaultStart);
245
+ if (this._dateRangeDefaultEnd === null) this.removeAttribute("end"); else this.setAttribute("end", this._dateRangeDefaultEnd);
246
+ this._syncFormValue();
247
+ } finally {
248
+ this._contourResetting = false;
249
+ }
250
+ }
251
+ formStateRestoreCallback(state) {
252
+ if (!this._internals || state == null) return;
253
+ const values = state instanceof FormData ? Array.from(state.getAll(this.getAttribute("name"))).map(String) : String(state).split(",");
254
+ this._contourResetting = true;
255
+ try {
256
+ this.setAttribute("start", values[0] || "");
257
+ this.setAttribute("end", values[1] || "");
258
+ this._syncFormValue();
259
+ } finally {
260
+ this._contourResetting = false;
261
+ }
262
+ }
263
+ }
264
+ define("contour-date-range", ContourDateRange);
265
+
266
+ /**
267
+ * Shortcut: web component wrapper.
268
+ * Attributes: `key`, `label`.
269
+ */
270
+ class ContourShortcut extends ContourBase {
271
+ static get observed() { return ["key", "label"]; }
272
+ static get properties() { return { key: { attribute: "key" }, label: { attribute: "label" } }; }
273
+ render() {
274
+ this.classList.add("c-shortcut");
275
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
276
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Keyboard shortcut");
277
+ const key = this.getAttribute("key") || "";
278
+ const label = this.getAttribute("label") || "";
279
+ if (key) {
280
+ const k = this.ensure(".c-shortcut__key", () => { const el = document.createElement("kbd"); el.className = "c-shortcut__key"; return el; });
281
+ k.textContent = key;
282
+ }
283
+ if (label) {
284
+ const l = this.ensure(".c-shortcut__label", () => { const el = document.createElement("span"); el.className = "c-shortcut__label"; return el; });
285
+ l.textContent = label;
286
+ }
287
+ }
288
+ enhance() {
289
+ if (this._wiredShortcut) return;
290
+ this._wiredShortcut = true;
291
+ // Read key attribute PER EVENT: capturing at wire time left old combo firing after key change.
292
+ // Arming unconditionally lets key added after upgrade work; empty/absent key never matches.
293
+ const handler = (e) => {
294
+ const key = this.getAttribute("key");
295
+ if (key && e.key === key && (e.metaKey || e.ctrlKey)) {
296
+ e.preventDefault();
297
+ this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true }));
298
+ }
299
+ };
300
+ document.addEventListener("keydown", handler);
301
+ onDispose(this, () => document.removeEventListener("keydown", handler));
302
+ }
303
+ }
304
+ define("contour-shortcut", ContourShortcut);
305
+ /**
306
+ * Date Picker: web component wrapper.
307
+ * Attributes: `value`, `range`, `range-start`, `range-end`, `label`, `disabled`, `error`, `help`, `time`, `min`, `max`, `locale`.
308
+ */
309
+ class ContourDatePicker extends ContourBase {
310
+ static get formAssociated() { return true; }
311
+ static get observed() { return ["value", "range", "range-start", "range-end", "label", "disabled", "error", "help", "time", "min", "max", "locale", "required", "name"]; }
312
+ static get properties() { return { value: { attribute: "value" }, range: { attribute: "range", type: Boolean }, rangeStart: { attribute: "range-start" }, rangeEnd: { attribute: "range-end" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, time: { attribute: "time", type: Boolean }, min: { attribute: "min" }, max: { attribute: "max" }, locale: { attribute: "locale" } }; }
313
+ render() {
314
+ this.classList.add("c-date-picker");
315
+ this.setAttribute("role", "group");
316
+ this.setAttribute("aria-label", labelText(this, "date-picker", "Date picker"));
317
+ const label = this.getAttribute("label");
318
+ if (label) {
319
+ const l = this.ensure(".c-date-picker__label", () => { const el = document.createElement("label"); el.className = "c-date-picker__label"; return el; });
320
+ l.textContent = label;
321
+ }
322
+ const input = this.keepNode(this.ensure(".c-date-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-date-picker__input"; return el; }));
323
+ const range = this.hasAttribute("range");
324
+ const type = this.hasAttribute("time") ? "datetime-local" : "date";
325
+ const configure = (control, value, name) => {
326
+ control.type = type;
327
+ // Don't clobber typed value: only write when not focused and value differs. Old code set value on every render, reverting typed date.
328
+ const next = value || "";
329
+ if (document.activeElement !== control && control.value !== next) control.value = next;
330
+ control.setAttribute("aria-label", name);
331
+ if (this.hasAttribute("min")) control.min = this.getAttribute("min"); else control.removeAttribute("min");
332
+ if (this.hasAttribute("max")) control.max = this.getAttribute("max"); else control.removeAttribute("max");
333
+ if (this.hasAttribute("locale")) control.lang = this.getAttribute("locale"); else control.removeAttribute("lang");
334
+ if (this.hasAttribute("disabled")) control.setAttribute("disabled", ""); else control.removeAttribute("disabled");
335
+ };
336
+ configure(input, range ? this.getAttribute("range-start") : this.getAttribute("value"), range ? "Start date" : (label || "Date"));
337
+ let end = this.querySelector(".c-date-picker__end");
338
+ if (range) {
339
+ end = this.keepNode(end || document.createElement("input"));
340
+ end.className = "c-input c-date-picker__input c-date-picker__end";
341
+ configure(end, this.getAttribute("range-end"), "End date");
342
+ if (end.parentNode !== this) this.appendChild(end);
343
+ } else if (end) end.remove();
344
+ // Clamp values to [min, max] so picker never holds out-of-range date native input would accept.
345
+ const dpMin = this.getAttribute("min");
346
+ const dpMax = this.getAttribute("max");
347
+ const clampDp = (control) => {
348
+ if (!dpMin && !dpMax) return;
349
+ const v = control.value;
350
+ if (!v) return;
351
+ let next = v;
352
+ if (dpMin && next < dpMin) next = dpMin;
353
+ if (dpMax && next > dpMax) next = dpMax;
354
+ if (next !== v && document.activeElement !== control) control.value = next;
355
+ };
356
+ clampDp(input);
357
+ if (end) clampDp(end);
358
+ if (this.hasAttribute("disabled")) this.classList.add("is-disabled"); else this.classList.remove("is-disabled");
359
+ const err = this.getAttribute("error");
360
+ const help = this.getAttribute("help");
361
+ let msg = this.querySelector(".c-date-picker__message");
362
+ if (err || help) {
363
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-date-picker__message"; if (!msg.id) msg.id = contourId("c-date-picker-message"); this.appendChild(msg); }
364
+ msg.textContent = err || help || "";
365
+ msg.classList.toggle("c-date-picker__message--error", !!err);
366
+ } else if (msg) { msg.remove(); }
367
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
368
+ // Associate error/help with inputs; flag inverted range.
369
+ let pickerInvalid = !!err;
370
+ if (this.hasAttribute("range")) pickerInvalid = pickerInvalid || this._validateRange();
371
+ const describedBy = msg ? msg.id : "";
372
+ const applyMsg = (ctrl) => {
373
+ if (pickerInvalid) ctrl.setAttribute("aria-invalid", "true"); else ctrl.removeAttribute("aria-invalid");
374
+ if (describedBy) ctrl.setAttribute("aria-describedby", describedBy); else ctrl.removeAttribute("aria-describedby");
375
+ };
376
+ applyMsg(input);
377
+ const endEl = this.querySelector(".c-date-picker__end");
378
+ if (endEl) applyMsg(endEl);
379
+ // Calendar affordance: toggle + month grid alongside native input.
380
+ const toggle = this.keepNode(this.ensure(".c-date-picker__calendar-toggle", () => {
381
+ const el = document.createElement("button");
382
+ el.className = "c-btn c-btn--sm c-date-picker__calendar-toggle";
383
+ el.type = "button";
384
+ el.setAttribute("aria-label", labelText(this, "open-calendar", "Open calendar"));
385
+ el.setAttribute("aria-expanded", "false");
386
+ // SVG glyph, not an emoji: the platform draws emoji in its own font,
387
+ // off the DS type ramp.
388
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
389
+ svg.setAttribute("aria-hidden", "true");
390
+ const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
391
+ use.setAttribute("href", "#i-chevron-down");
392
+ svg.appendChild(use);
393
+ el.appendChild(svg);
394
+ return el;
395
+ }));
396
+ let cal = this.querySelector(".c-date-picker__calendar");
397
+ if (!cal) { cal = document.createElement("div"); cal.className = "c-date-picker__calendar"; cal.setAttribute("hidden", ""); cal.setAttribute("role", "dialog"); cal.setAttribute("aria-label", labelText(this, "calendar", "Calendar")); this.appendChild(cal); }
398
+ this.keepNode(cal);
399
+ // `required` observed; post-upgrade change re-renders. Re-sync validity so empty required picker reports invalid.
400
+ if (this._internals) this._syncFormValue();
401
+ }
402
+ _renderCalendar() {
403
+ const cal = this.querySelector(".c-date-picker__calendar");
404
+ if (!cal) return;
405
+ const input = this.querySelector(".c-date-picker__input");
406
+ // R31-72: a date-only string parsed by `new Date()` is UTC midnight, which
407
+ // renders the previous day west of Greenwich. Build the local calendar day.
408
+ const localDate = (s) => {
409
+ const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(s || "");
410
+ return m ? new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : new Date();
411
+ };
412
+ const base = (input && input.value) ? localDate(input.value) : new Date();
413
+ const month = this._calMonth || new Date(base.getFullYear(), base.getMonth(), 1);
414
+ this._calMonth = month;
415
+ const y = month.getFullYear();
416
+ const m = month.getMonth();
417
+ const locale = this.getAttribute("locale") || undefined;
418
+ const firstDow = this._datePickerFirstDayOfWeek(locale);
419
+ const first = new Date(y, m, 1);
420
+ const startDay = (first.getDay() - firstDow + 7) % 7;
421
+ const daysInMonth = new Date(y, m + 1, 0).getDate();
422
+ setHTML(cal, "");
423
+ const header = document.createElement("div");
424
+ header.className = "c-date-picker__calendar-header";
425
+ const prev = document.createElement("button"); prev.type = "button"; prev.className = "c-btn c-btn--sm c-btn--icon"; setHTML(prev, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-left" /></svg>'); prev.setAttribute("aria-label", labelText(this, "previous-month", "Previous month"));
426
+ const title = document.createElement("span"); title.className = "c-date-picker__calendar-title"; title.textContent = month.toLocaleString(this.getAttribute("locale") || undefined, { month: "long", year: "numeric" });
427
+ const next = document.createElement("button"); next.type = "button"; next.className = "c-btn c-btn--sm c-btn--icon"; setHTML(next, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>'); next.setAttribute("aria-label", labelText(this, "next-month", "Next month"));
428
+ header.appendChild(prev); header.appendChild(title); header.appendChild(next);
429
+ cal.appendChild(header);
430
+ const grid = document.createElement("div");
431
+ grid.className = "c-date-picker__calendar-grid";
432
+ grid.setAttribute("role", "grid");
433
+ // Grid rows use `display: contents`: visual 7-col layout untouched; a11y tree gets real row/gridcell structure.
434
+ grid.setAttribute("aria-label", title.textContent);
435
+ const rowEl = () => {
436
+ const row = document.createElement("div");
437
+ row.className = "c-date-picker__calendar-row";
438
+ row.setAttribute("role", "row");
439
+ grid.appendChild(row);
440
+ return row;
441
+ };
442
+ let row = rowEl();
443
+ let cells = 0;
444
+ const push = (cell) => {
445
+ if (cells === 7) { row = rowEl(); cells = 0; }
446
+ row.appendChild(cell);
447
+ cells++;
448
+ };
449
+ const weekdaysShort = ["Su","Mo","Tu","We","Th","Fr","Sa"];
450
+ const weekdaysLong = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
451
+ for (let i = 0; i < 7; i++) {
452
+ const w = (firstDow + i) % 7;
453
+ const h = document.createElement("div");
454
+ h.className = "c-date-picker__calendar-weekday";
455
+ h.setAttribute("role", "columnheader");
456
+ const ref = new Date(2026, 0, w + 1);
457
+ h.setAttribute("aria-label", ref.toLocaleDateString(locale, { weekday: "long" }) || weekdaysLong[w]);
458
+ h.textContent = ref.toLocaleDateString(locale, { weekday: "short" }) || weekdaysShort[w];
459
+ push(h);
460
+ }
461
+ for (let i = 0; i < startDay; i++) {
462
+ const empty = document.createElement("div");
463
+ empty.className = "c-date-picker__calendar-day c-date-picker__calendar-day--empty";
464
+ empty.setAttribute("role", "gridcell");
465
+ empty.setAttribute("aria-hidden", "true");
466
+ push(empty);
467
+ }
468
+ const selected = input ? input.value : "";
469
+ const inMonth = selected && selected.slice(0, 7) === `${y}-${String(m + 1).padStart(2, "0")}`;
470
+ const stopDay = inMonth ? parseInt(selected.slice(8, 10), 10) || 1 : 1;
471
+ const dpMin = this.getAttribute("min");
472
+ const dpMax = this.getAttribute("max");
473
+ for (let d = 1; d <= daysInMonth; d++) {
474
+ const btn = document.createElement("button");
475
+ btn.type = "button";
476
+ btn.className = "c-date-picker__calendar-day";
477
+ btn.textContent = String(d);
478
+ btn.setAttribute("role", "gridcell");
479
+ // One tab stop for month; arrows move within grid.
480
+ btn.setAttribute("tabindex", d === stopDay ? "0" : "-1");
481
+ // "12" is a number, not a date; cell's name says the whole date.
482
+ btn.setAttribute("aria-label", new Date(y, m, d).toLocaleDateString(this.getAttribute("locale") || undefined, { weekday: "long", day: "numeric", month: "long", year: "numeric" }));
483
+ const iso = `${y}-${String(m + 1).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
484
+ if (selected && selected.startsWith(iso)) { btn.classList.add("is-selected"); btn.setAttribute("aria-selected", "true"); }
485
+ // Days outside [min, max] disabled and never commit.
486
+ const outOfRange = (dpMin && iso < dpMin) || (dpMax && iso > dpMax);
487
+ btn.disabled = outOfRange;
488
+ if (outOfRange) btn.setAttribute("aria-disabled", "true");
489
+ btn.setAttribute("tabindex", outOfRange ? "-1" : (d === stopDay ? "0" : "-1"));
490
+ if (outOfRange) {
491
+ push(btn);
492
+ continue;
493
+ }
494
+ btn.addEventListener("click", () => {
495
+ if (!input) return;
496
+ const range = this.hasAttribute("range");
497
+ // R31-63: write the HOST value attribute, not only the inner input, so
498
+ // `valueAttr` reflects the pick and a re-render restores it. The base
499
+ // re-renders on the attribute write; _syncFormValue below reads the
500
+ // rebuilt control, and the change event is emitted from the host.
501
+ if (range) {
502
+ const endInput = this.querySelector(".c-date-picker__end");
503
+ const setStart = this._rangeStartNext !== false;
504
+ if (setStart) { this.setAttribute("range-start", iso); this._rangeStartNext = false; }
505
+ else if (endInput) { this.setAttribute("range-end", iso); this._rangeStartNext = true; }
506
+ } else {
507
+ this.setAttribute("value", iso);
508
+ }
509
+ cal.setAttribute("hidden", "");
510
+ const tgl = this.querySelector(".c-date-picker__calendar-toggle");
511
+ if (tgl) tgl.setAttribute("aria-expanded", "false");
512
+ this._validateRange();
513
+ if (this._internals) this._syncFormValue();
514
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: this.getAttribute("value") } }));
515
+ });
516
+ push(btn);
517
+ }
518
+ cal.appendChild(grid);
519
+ prev.addEventListener("click", () => { this._calMonth = new Date(y, m - 1, 1); this._renderCalendar(); });
520
+ next.addEventListener("click", () => { this._calMonth = new Date(y, m + 1, 1); this._renderCalendar(); });
521
+ if (this._internals) this._syncFormValue();
522
+ }
523
+ _syncFormValue() {
524
+ if (!this._internals) return;
525
+ const start = this.querySelector(".c-date-picker__input");
526
+ const end = this.querySelector(".c-date-picker__end");
527
+ // A range picker submits both ends; a single picker submits its value.
528
+ if (this.hasAttribute("range") && end) {
529
+ const s = start ? start.value : "";
530
+ const e = end.value || "";
531
+ const name = this.getAttribute("name");
532
+ if (name && (s || e)) {
533
+ const fd = new FormData();
534
+ if (s) fd.append(name, s);
535
+ if (e) fd.append(name, e);
536
+ this._internals.setFormValue(fd);
537
+ } else {
538
+ this._internals.setFormValue(null);
539
+ }
540
+ } else {
541
+ this._internals.setFormValue(start && start.value ? start.value : null);
542
+ }
543
+ this._syncValidity(this.hasAttribute("required") && !(start && start.value));
544
+ }
545
+ formResetCallback() {
546
+ const apply = () => {
547
+ const start = this.querySelector(".c-date-picker__input");
548
+ const end = this.querySelector(".c-date-picker__end");
549
+ if (start) start.value = this.getAttribute("range-start") || this.getAttribute("value") || "";
550
+ if (end) end.value = this.getAttribute("range-end") || "";
551
+ this._syncFormValue();
552
+ };
553
+ apply();
554
+ // The platform reset clears the inner inputs after this callback; re-apply
555
+ // on the next microtask so the authored range survives.
556
+ if (typeof queueMicrotask === "function") queueMicrotask(apply);
557
+ }
558
+ // R24-81: first day of week respected from locale (Sunday vs Monday).
559
+ _datePickerFirstDayOfWeek(locale) {
560
+ const sundayStart = ["en-US","en-CA","en-PH","ja-JP","ko-KR","th-TH","ar-SA","he-IL"];
561
+ return sundayStart.includes(String(locale || "").toLowerCase()) ? 0 : 1;
562
+ }
563
+ // R24-81: flag an inverted range (start > end) on both inputs, unless an
564
+ // explicit error attribute already owns aria-invalid.
565
+ _validateRange() {
566
+ if (!this.hasAttribute("range")) return false;
567
+ const start = this.querySelector(".c-date-picker__input");
568
+ const end = this.querySelector(".c-date-picker__end");
569
+ if (!start || !end) return false;
570
+ const inverted = !!start.value && !!end.value && start.value > end.value;
571
+ if (this.getAttribute("error")) return inverted;
572
+ if (inverted) { start.setAttribute("aria-invalid", "true"); end.setAttribute("aria-invalid", "true"); }
573
+ else { start.removeAttribute("aria-invalid"); end.removeAttribute("aria-invalid"); }
574
+ return inverted;
575
+ }
576
+ enhance() {
577
+ if (this._wiredDatePicker) return;
578
+ this._wiredDatePicker = true;
579
+ this._syncFormValue();
580
+ this.addEventListener("change", () => { this._syncFormValue(); });
581
+ this.addEventListener("change", (e) => {
582
+ const t = e.target;
583
+ if (t && t.classList.contains("c-date-picker__input")) {
584
+ const end = this.querySelector(".c-date-picker__end");
585
+ const detail = end ? { start: this.querySelector(".c-date-picker__input").value, end: end.value } : { value: t.value };
586
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail }));
587
+ }
588
+ });
589
+ const toggle = () => {
590
+ const cal = this.querySelector(".c-date-picker__calendar");
591
+ const btn = this.querySelector(".c-date-picker__calendar-toggle");
592
+ if (!cal) return;
593
+ const hidden = cal.hasAttribute("hidden");
594
+ if (hidden) { cal.removeAttribute("hidden"); if (btn) btn.setAttribute("aria-expanded", "true"); this._renderCalendar(); }
595
+ else { cal.setAttribute("hidden", ""); if (btn) btn.setAttribute("aria-expanded", "false"); }
596
+ };
597
+ this.addEventListener("click", (e) => {
598
+ const btn = e.target && e.target.closest ? e.target.closest(".c-date-picker__calendar-toggle") : null;
599
+ if (btn && this.contains(btn)) { e.preventDefault(); toggle(); }
600
+ // R24-52: outside-click closes the calendar.
601
+ const cal = this.querySelector(".c-date-picker__calendar");
602
+ if (cal && !cal.hasAttribute("hidden") && !cal.contains(e.target) && !btn) {
603
+ cal.setAttribute("hidden", "");
604
+ const toggleBtn = this.querySelector(".c-date-picker__calendar-toggle");
605
+ if (toggleBtn) toggleBtn.setAttribute("aria-expanded", "false");
606
+ }
607
+ });
608
+ // Grid keyboard: one tab stop, arrows move by day/week, Home/End reach month ends, PageUp/Down change month; delegated on the host since cells are rebuilt.
609
+ this.addEventListener("keydown", (e) => {
610
+ const cal = this.querySelector(".c-date-picker__calendar");
611
+ if (!cal || cal.hasAttribute("hidden")) return;
612
+ // R24-52: Escape closes the calendar and returns focus to the toggle.
613
+ if (e.key === "Escape") {
614
+ e.preventDefault();
615
+ cal.setAttribute("hidden", "");
616
+ const btn = this.querySelector(".c-date-picker__calendar-toggle");
617
+ if (btn) { btn.setAttribute("aria-expanded", "false"); btn.focus(); }
618
+ return;
619
+ }
620
+ const cells = Array.from(cal.querySelectorAll('[role="gridcell"]:not([aria-hidden="true"])'));
621
+ const i = cells.indexOf(document.activeElement);
622
+ if (i < 0) return;
623
+ if (e.key === "PageUp" || e.key === "PageDown") {
624
+ e.preventDefault();
625
+ const btn = this.querySelector(e.key === "PageUp" ? ".c-date-picker__calendar-header button:first-child" : ".c-date-picker__calendar-header button:last-child");
626
+ if (btn) btn.click();
627
+ return;
628
+ }
629
+ let next = -1;
630
+ if (e.key === "ArrowRight") next = i + 1;
631
+ else if (e.key === "ArrowLeft") next = i - 1;
632
+ else if (e.key === "ArrowDown") next = i + 7;
633
+ else if (e.key === "ArrowUp") next = i - 7;
634
+ else if (e.key === "Home") next = 0;
635
+ else if (e.key === "End") next = cells.length - 1;
636
+ else return;
637
+ e.preventDefault();
638
+ if (next < 0 || next >= cells.length) return;
639
+ cells.forEach((cell, j) => cell.setAttribute("tabindex", j === next ? "0" : "-1"));
640
+ cells[next].focus();
641
+ });
642
+ }
643
+ }
644
+ define("contour-date-picker", ContourDatePicker);
645
+
646
+ /**
647
+ * Rating: web component wrapper.
648
+ * Attributes: `value`, `max`, `color`, `readonly`, `disabled`, `name`.
649
+ */
650
+ class ContourRating extends ContourBase {
651
+ static get observed() { return ["value", "max", "color", "readonly", "disabled", "name"]; }
652
+ static get properties() { return { value: { attribute: "value", type: Number }, max: { attribute: "max", type: Number }, color: { attribute: "color" }, readonly: { attribute: "readonly", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, name: { attribute: "name" } }; }
653
+ static get formAssociated() { return true; }
654
+ render() {
655
+ this.classList.add("c-rating");
656
+ if (!this.hasAttribute("role")) this.setAttribute("role", "radiogroup");
657
+ // The group's name is the author's choice; "Rating" is only the fallback.
658
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "rating", "Rating"));
659
+ const max = parseInt(this.getAttribute("max") || "5", 10) || 5;
660
+ const value = parseInt(this.getAttribute("value") || "0", 10) || 0;
661
+ const color = this.getAttribute("color");
662
+ const readonly = flagOn(this, "readonly");
663
+ const disabled = flagOn(this, "disabled");
664
+ Array.from(this.querySelectorAll(".c-rating__star")).forEach((n) => n.remove());
665
+ // A radiogroup is one tab stop, arrow keys move within it. The checked
666
+ // star (or the first when nothing is rated) is the one Tab reaches.
667
+ const stop = value >= 1 && value <= max ? value : 1;
668
+ for (let i = 1; i <= max; i++) {
669
+ const star = document.createElement("button");
670
+ star.className = "c-rating__star" + (i <= value ? " c-rating__star--filled" : "");
671
+ star.type = "button";
672
+ star.setAttribute("role", "radio");
673
+ star.setAttribute("aria-checked", String(i === value));
674
+ // A radio with no name is unnamed; the swatch is aria-hidden, so the star must carry a name.
675
+ star.setAttribute("aria-label", i + (i === 1 ? " star" : " stars"));
676
+ star.setAttribute("tabindex", String(i === stop ? 0 : -1));
677
+ if (readonly || disabled) {
678
+ star.setAttribute("aria-disabled", "true");
679
+ star.disabled = true;
680
+ star.tabIndex = -1;
681
+ }
682
+ setHTML(star, '<span class="c-rating__swatch' + (i <= value ? ' c-rating__swatch--filled' : '') + '" aria-hidden="true"></span>');
683
+ if (color && i <= value) {
684
+ const sw = star.firstChild;
685
+ const safe = safeColor(color);
686
+ if (sw && safe) {
687
+ sw.style.backgroundColor = safe;
688
+ sw.style.borderColor = safe;
689
+ }
690
+ }
691
+ star.dataset.value = String(i);
692
+ star.setAttribute("aria-label", i + " star" + (i > 1 ? "s" : ""));
693
+ this.appendChild(star);
694
+ }
695
+ if (this._internals) this._syncFormValue();
696
+ }
697
+ _syncFormValue() {
698
+ if (!this._internals) return;
699
+ const name = this.getAttribute("name");
700
+ const value = this.getAttribute("value");
701
+ if (name && value) this._internals.setFormValue(value);
702
+ else this._internals.setFormValue(null);
703
+ }
704
+ enhance() {
705
+ if (this._wiredRating) return;
706
+ this._wiredRating = true;
707
+ const stars = () => Array.from(this.querySelectorAll(".c-rating__star"));
708
+ // Selection is one state change: aria-checked, the roving tab stop and the event move together.
709
+ const select = (v) => {
710
+ if (flagOn(this, "readonly") || flagOn(this, "disabled")) return;
711
+ stars().forEach((st) => {
712
+ const on = parseInt(st.dataset.value, 10) === v;
713
+ st.setAttribute("aria-checked", String(on));
714
+ st.setAttribute("tabindex", on ? "0" : "-1");
715
+ st.classList.toggle("c-rating__star--filled", parseInt(st.dataset.value, 10) <= v);
716
+ const sw = st.querySelector(".c-rating__swatch");
717
+ if (sw) sw.classList.toggle("c-rating__swatch--filled", parseInt(st.dataset.value, 10) <= v);
718
+ });
719
+ // R24-50: write the value back to the attribute so the selection
720
+ // survives a re-render.
721
+ this.setAttribute("value", String(v));
722
+ this._syncFormValue();
723
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: v } }));
724
+ };
725
+ this.addEventListener("click", (e) => {
726
+ const star = e.target && e.target.closest ? e.target.closest(".c-rating__star") : null;
727
+ if (star && this.contains(star)) select(parseInt(star.dataset.value, 10));
728
+ });
729
+ this.addEventListener("keydown", (e) => {
730
+ const all = stars();
731
+ if (!all.length) return;
732
+ navKey(e, all, {
733
+ wrap: false,
734
+ homeEnd: true,
735
+ onNavigate: (i) => { select(parseInt(all[i].dataset.value, 10)); },
736
+ onKey: (key, i) => { if (key === "Enter" || key === " ") select(parseInt(all[i].dataset.value, 10)); },
737
+ });
738
+ });
739
+ }
740
+ }
741
+ define("contour-rating", ContourRating);
742
+
743
+ /**
744
+ * Time Picker: web component wrapper.
745
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`.
746
+ */
747
+ class ContourTimePicker extends ContourBase {
748
+ static get formAssociated() { return true; }
749
+ static get observed() { return ["value", "label", "disabled", "error", "help"]; }
750
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
751
+ render() {
752
+ this.classList.add("c-time-picker");
753
+ this.setAttribute("role", "group");
754
+ this.setAttribute("aria-label", labelText(this, "time-picker", "Time picker"));
755
+ const label = this.getAttribute("label");
756
+ if (label) {
757
+ const l = this.ensure(".c-time-picker__label", () => { const el = document.createElement("label"); el.className = "c-time-picker__label"; return el; });
758
+ l.textContent = label;
759
+ }
760
+ const input = this.ensure(".c-time-picker__input", () => { const el = document.createElement("input"); el.className = "c-input c-time-picker__input"; el.type = "time"; el.setAttribute("aria-label", this.getAttribute("label") || "Time picker"); return el; });
761
+ input.value = this.getAttribute("value") || "";
762
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
763
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
764
+ const err = this.getAttribute("error");
765
+ const help = this.getAttribute("help");
766
+ let msg = this.querySelector(".c-time-picker__message");
767
+ if (err || help) {
768
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-time-picker__message"; if (!msg.id) msg.id = contourId("c-time-picker-message"); this.appendChild(msg); }
769
+ msg.textContent = err || help || "";
770
+ msg.classList.toggle("c-time-picker__message--error", !!err);
771
+ } else if (msg) { msg.remove(); }
772
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
773
+ // R24-81: associate the error/help message with the input.
774
+ const tMsg = msg ? msg.id : "";
775
+ if (err) input.setAttribute("aria-invalid", "true"); else input.removeAttribute("aria-invalid");
776
+ if (tMsg) input.setAttribute("aria-describedby", tMsg); else input.removeAttribute("aria-describedby");
777
+ if (this._internals) this._syncFormValue();
778
+ }
779
+ enhance() {
780
+ if (this._wiredTimePicker) return;
781
+ this._wiredTimePicker = true;
782
+ this._syncFormValue();
783
+ this.addEventListener("change", () => { this._syncFormValue(); });
784
+ this.addEventListener("change", (e) => {
785
+ const t = e.target;
786
+ if (t && t.classList.contains("c-time-picker__input")) {
787
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
788
+ }
789
+ });
790
+ }
791
+ }
792
+ define("contour-time-picker", ContourTimePicker);
793
+
794
+ /**
795
+ * Color Picker: web component wrapper.
796
+ * Attributes: `value`, `label`, `disabled`, `error`, `help`, `alpha`, `presets`.
797
+ */
798
+ class ContourColorPicker extends ContourBase {
799
+ static get formAssociated() { return true; }
800
+ static get observed() { return ["value", "label", "disabled", "required", "error", "help", "alpha", "presets"]; }
801
+ static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, required: { attribute: "required", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, alpha: { attribute: "alpha", type: Boolean }, presets: { attribute: "presets" } }; }
802
+ render() {
803
+ this.classList.add("c-color-picker");
804
+ this.setAttribute("role", "group");
805
+ this.setAttribute("aria-label", labelText(this, "color-picker", "Color picker"));
806
+ const label = this.getAttribute("label");
807
+ if (label) {
808
+ const l = this.ensure(".c-color-picker__label", () => { const el = document.createElement("label"); el.className = "c-color-picker__label"; return el; });
809
+ l.textContent = label;
810
+ }
811
+ const input = this.ensure(".c-color-picker__input", () => { const el = document.createElement("input"); el.className = "c-color-picker__input"; el.type = "color"; return el; });
812
+ // R31-68: do not default an unset picker to #000000. A native color input
813
+ // always paints some colour, so an unset value is marked `data-empty`
814
+ // (CSS shows a "No colour" swatch) and the input is left at the platform
815
+ // default rather than the component asserting black.
816
+ const rawValue = this.getAttribute("value") || "";
817
+ const hasColor = /^#?[0-9a-f]{6}([0-9a-f]{2})?$/i.test(rawValue);
818
+ if (hasColor) { input.value = rawValue.slice(0, 7); this.removeAttribute("data-empty"); }
819
+ else { input.value = ""; this.setAttribute("data-empty", ""); }
820
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", label || "Color");
821
+ // R31-68: a required picker propagates `required` to the native input, so
822
+ // an empty (data-empty) value blocks form submission.
823
+ if (this.hasAttribute("required")) input.setAttribute("required", ""); else input.removeAttribute("required");
824
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
825
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
826
+ // Alpha channel (optional).
827
+ if (this.hasAttribute("alpha")) {
828
+ const alpha = this.ensure(".c-color-picker__alpha", () => { const el = document.createElement("input"); el.className = "c-color-picker__alpha"; el.type = "range"; el.min = "0"; el.max = "1"; el.step = "0.01"; return el; });
829
+ // R31-68: parse alpha only from a real #rrggbbaa value; an unset picker
830
+ // must not report alpha 1 over an implicit black.
831
+ const a = hasColor && rawValue.length === 9 ? parseInt(rawValue.slice(7, 9), 16) / 255 : 1;
832
+ alpha.value = String(a);
833
+ alpha.setAttribute("aria-label", labelText(this, "alpha", "Alpha"));
834
+ } else {
835
+ const a = this.querySelector(".c-color-picker__alpha");
836
+ if (a) a.remove();
837
+ }
838
+ // Presets.
839
+ const presetsAttr = this.getAttribute("presets");
840
+ let presets = [];
841
+ if (presetsAttr) { try { presets = JSON.parse(presetsAttr); } catch (e) { warnBadJson(this, "presets", e); presets = []; } }
842
+ const oldPresets = this.querySelector(".c-color-picker__presets");
843
+ if (oldPresets) oldPresets.remove();
844
+ if (Array.isArray(presets) && presets.length) {
845
+ const wrap = document.createElement("div");
846
+ wrap.className = "c-color-picker__presets";
847
+ presets.forEach((c) => {
848
+ const btn = document.createElement("button");
849
+ btn.type = "button";
850
+ btn.className = "c-color-picker__preset";
851
+ const safe = safeColor(c);
852
+ if (!safe) return;
853
+ btn.style.background = safe;
854
+ btn.dataset.color = safe;
855
+ btn.setAttribute("aria-label", labelText(this, "preset", "Preset") + " " + c);
856
+ wrap.appendChild(btn);
857
+ });
858
+ this.appendChild(wrap);
859
+ }
860
+ // Eyedropper (if supported).
861
+ if (typeof window !== "undefined" && "EyeDropper" in window) {
862
+ const ed = this.ensure(".c-color-picker__eyedropper", () => { const el = document.createElement("button"); el.className = "c-color-picker__eyedropper"; el.type = "button"; el.textContent = labelText(this, "pick", "Pick"); el.setAttribute("aria-label", labelText(this, "pick-color", "Pick color from screen")); return el; });
863
+ if (this.hasAttribute("disabled")) ed.setAttribute("disabled", "");
864
+ else ed.removeAttribute("disabled");
865
+ } else {
866
+ const ed = this.querySelector(".c-color-picker__eyedropper");
867
+ if (ed) ed.remove();
868
+ }
869
+ const err = this.getAttribute("error");
870
+ const help = this.getAttribute("help");
871
+ let msg = this.querySelector(".c-color-picker__message");
872
+ if (err || help) {
873
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-color-picker__message"; if (!msg.id) msg.id = contourId("c-color-picker-message"); this.appendChild(msg); }
874
+ msg.textContent = err || help || "";
875
+ msg.classList.toggle("c-color-picker__message--error", !!err);
876
+ } else if (msg) { msg.remove(); }
877
+ if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
878
+ // R24-81: associate the error/help message with the input.
879
+ const cMsg = msg ? msg.id : "";
880
+ if (err) input.setAttribute("aria-invalid", "true"); else input.removeAttribute("aria-invalid");
881
+ if (cMsg) input.setAttribute("aria-describedby", cMsg); else input.removeAttribute("aria-describedby");
882
+ if (this._internals) this._syncFormValue();
883
+ }
884
+ enhance() {
885
+ if (this._wiredColorPicker) return;
886
+ this._wiredColorPicker = true;
887
+ this._syncFormValue();
888
+ this.addEventListener("change", () => { this._syncFormValue(); });
889
+ this.addEventListener("contour:change", () => { this._syncFormValue(); });
890
+ this.addEventListener("change", (e) => {
891
+ const t = e.target;
892
+ if (t && t.classList.contains("c-color-picker__input")) {
893
+ // R24-50: write the value back to the attribute so the selection
894
+ // survives a re-render. R31-68: keep any existing alpha suffix so a
895
+ // base-colour change does not silently drop the alpha channel.
896
+ const prev = this.getAttribute("value") || "";
897
+ const alphaSuffix = prev.length === 9 ? prev.slice(7, 9) : "";
898
+ const next = t.value.slice(0, 7) + alphaSuffix;
899
+ this.setAttribute("value", next);
900
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: next } }));
901
+ }
902
+ if (t && t.classList.contains("c-color-picker__alpha")) {
903
+ const base = (this.getAttribute("value") || "#000000").slice(0, 7);
904
+ const a = Math.round(parseFloat(t.value) * 255).toString(16).padStart(2, "0");
905
+ const val = base + a;
906
+ this.setAttribute("value", val);
907
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: val } }));
908
+ }
909
+ });
910
+ this.addEventListener("click", (e) => {
911
+ const btn = e.target && e.target.closest ? e.target.closest(".c-color-picker__preset") : null;
912
+ if (btn && this.contains(btn)) {
913
+ const c = btn.dataset.color;
914
+ if (c) {
915
+ this.setAttribute("value", c);
916
+ const input = this.querySelector(".c-color-picker__input");
917
+ if (input) input.value = c.slice(0, 7);
918
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: c } }));
919
+ }
920
+ }
921
+ const ed = e.target && e.target.closest ? e.target.closest(".c-color-picker__eyedropper") : null;
922
+ if (ed && this.contains(ed) && typeof window !== "undefined" && "EyeDropper" in window) {
923
+ e.preventDefault();
924
+ const dropper = new window.EyeDropper();
925
+ dropper.open().then((r) => {
926
+ if (r && r.sRGBHex) {
927
+ this.setAttribute("value", r.sRGBHex);
928
+ const input = this.querySelector(".c-color-picker__input");
929
+ if (input) input.value = r.sRGBHex;
930
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: r.sRGBHex } }));
931
+ }
932
+ }).catch(() => {});
933
+ }
934
+ });
935
+ }
936
+ }
937
+ define("contour-color-picker", ContourColorPicker);
938
+
939
+ /**
940
+ * Number Field: web component wrapper.
941
+ * Attributes: `value`, `min`, `max`, `step`, `label`, `disabled`, `error`, `help`.
942
+ */
943
+ class ContourNumberField extends ContourBase {
944
+ static get formAssociated() { return true; }
945
+ static get observed() { return ["value", "min", "max", "step", "label", "disabled", "error", "help"]; }
946
+ static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, step: { attribute: "step" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
947
+ render() {
948
+ this.classList.add("c-number-field");
949
+ const label = this.getAttribute("label");
950
+ if (label) {
951
+ const l = this.ensure(".c-number-field__label", () => { const el = document.createElement("label"); el.className = "c-number-field__label"; return el; });
952
+ l.textContent = label;
953
+ }
954
+ const input = this.ensure(".c-number-field__input", () => { const el = document.createElement("input"); el.className = "c-input c-number-field__input"; el.type = "number"; el.setAttribute("role", "spinbutton"); return el; });
955
+ if (!input.id) input.id = contourId("nf-input");
956
+ const lblEl = this.querySelector(".c-number-field__label");
957
+ if (lblEl) lblEl.setAttribute("for", input.id);
958
+ if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
959
+ if (this.getAttribute("min") !== null) input.min = this.getAttribute("min");
960
+ if (this.getAttribute("max") !== null) input.max = this.getAttribute("max");
961
+ if (this.getAttribute("step") !== null) input.step = this.getAttribute("step");
962
+ const v = input.value;
963
+ input.setAttribute("aria-valuenow", v === "" ? "" : v);
964
+ if (input.min !== "") input.setAttribute("aria-valuemin", input.min);
965
+ if (input.max !== "") input.setAttribute("aria-valuemax", input.max);
966
+ if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", label || "Number");
967
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
968
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
969
+ const err = this.getAttribute("error");
970
+ const help = this.getAttribute("help");
971
+ let msg = this.querySelector(".c-number-field__message");
972
+ if (err || help) {
973
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-number-field__message"; this.appendChild(msg); }
974
+ if (!msg.id) msg.id = contourId("nf-msg");
975
+ msg.textContent = err || help || "";
976
+ msg.classList.toggle("c-number-field__message--error", !!err);
977
+ if (err) msg.setAttribute("role", "alert"); else msg.removeAttribute("role");
978
+ input.setAttribute("aria-describedby", msg.id);
979
+ } else {
980
+ if (msg) msg.remove();
981
+ input.removeAttribute("aria-describedby");
982
+ }
983
+ if (err) {
984
+ this.classList.add("is-error");
985
+ input.setAttribute("aria-invalid", "true");
986
+ } else {
987
+ this.classList.remove("is-error");
988
+ input.removeAttribute("aria-invalid");
989
+ }
990
+ // R24-117: removed dead calendar toggle — a number field has no calendar.
991
+ if (this._internals) this._syncFormValue();
992
+ }
993
+ enhance() {
994
+ if (this._wiredNumberField) return;
995
+ this._wiredNumberField = true;
996
+ this._syncFormValue();
997
+ this.addEventListener("change", () => { this._syncFormValue(); });
998
+ this.addEventListener("change", (e) => {
999
+ const t = e.target;
1000
+ if (t && t.classList.contains("c-number-field__input")) {
1001
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: t.value } }));
1002
+ }
1003
+ });
1004
+ this.addEventListener("keydown", (e) => {
1005
+ const input = this.querySelector(".c-number-field__input");
1006
+ if (!input || document.activeElement !== input) return;
1007
+ const step = Number(input.step) || 1;
1008
+ const min = input.min === "" ? -Infinity : Number(input.min);
1009
+ const max = input.max === "" ? Infinity : Number(input.max);
1010
+ let next = null;
1011
+ if (e.key === "ArrowUp") next = (Number(input.value) || 0) + step;
1012
+ else if (e.key === "ArrowDown") next = (Number(input.value) || 0) - step;
1013
+ else if (e.key === "Home") next = min === -Infinity ? 0 : min;
1014
+ else if (e.key === "End") next = max === Infinity ? (Number(input.value) || 0) : max;
1015
+ if (next !== null) {
1016
+ e.preventDefault();
1017
+ next = Math.min(max, Math.max(min, next));
1018
+ input.value = String(next);
1019
+ input.setAttribute("aria-valuenow", String(next));
1020
+ // R24-117: write value back to attribute so it survives re-render.
1021
+ this.setAttribute("value", String(next));
1022
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: input.value } }));
1023
+ }
1024
+ });
1025
+ }
1026
+ }
1027
+ define("contour-number-field", ContourNumberField);
1028
+ /**
1029
+ * File Upload: web component wrapper.
1030
+ * Attributes: `label`, `accept`, `multiple`, `progress`.
1031
+ */
1032
+ class ContourFileUpload extends ContourBase {
1033
+ static get formAssociated() { return true; }
1034
+ static get observed() { return ["label", "accept", "multiple", "progress", "name"]; }
1035
+ static get properties() { return { label: { attribute: "label" }, accept: { attribute: "accept" }, multiple: { attribute: "multiple", type: Boolean }, progress: { attribute: "progress" }, name: { attribute: "name" } }; }
1036
+ render() {
1037
+ this.classList.add("c-file-upload");
1038
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "File upload");
1039
+ const label = this.getAttribute("label") || "Drop files here or click to browse";
1040
+ const dz = this.ensure(".c-file-upload__dropzone", () => { const el = document.createElement("div"); el.className = "c-file-upload__dropzone"; el.setAttribute("role", "button"); el.tabIndex = 0; return el; });
1041
+ dz.textContent = label;
1042
+ const input = this.ensure(".c-file-upload__input", () => { const el = document.createElement("input"); el.className = "c-file-upload__input"; el.type = "file"; el.hidden = true; return el; });
1043
+ // Keep the file input alive across re-renders: it carries the selected FileList, which a rebuild would drop.
1044
+ this.keepNode(input);
1045
+ input.accept = this.getAttribute("accept") || "";
1046
+ input.multiple = this.hasAttribute("multiple");
1047
+ const p = this.getAttribute("progress");
1048
+ if (p !== null) {
1049
+ const bar = this.ensure(".c-file-upload__progress", () => { const el = document.createElement("progress"); el.className = "c-file-upload__progress"; return el; });
1050
+ bar.value = Number(p) || 0;
1051
+ bar.max = 100;
1052
+ } else {
1053
+ const bar = this.querySelector(".c-file-upload__progress");
1054
+ if (bar) bar.remove();
1055
+ }
1056
+ const preview = this.ensure(".c-file-upload__preview", () => { const el = document.createElement("div"); el.className = "c-file-upload__preview"; return el; });
1057
+ if (!preview) {}
1058
+ if (this._internals) this._syncFormValue();
1059
+ }
1060
+ enhance() {
1061
+ if (this._wiredFileUpload) return;
1062
+ this._wiredFileUpload = true;
1063
+ this._syncFormValue();
1064
+ this.addEventListener("change", () => { this._syncFormValue(); });
1065
+ const dz = () => this.querySelector(".c-file-upload__dropzone");
1066
+ const input = () => this.querySelector(".c-file-upload__input");
1067
+ const activate = () => { const i = input(); if (i) i.click(); };
1068
+ // `input.files` is a FileList, not an Array; build a real one via DataTransfer so the drop reaches the input.
1069
+ const assignFiles = (i, files) => {
1070
+ try {
1071
+ const dt = new DataTransfer();
1072
+ Array.from(files || []).forEach((f) => dt.items.add(f));
1073
+ i.files = dt.files;
1074
+ } catch (err) { /* unsupported: leave the native picker as the source */ }
1075
+ };
1076
+ this.addEventListener("click", (e) => { const d = dz(); if (e.target === d || (d && d.contains(e.target))) { activate(); } });
1077
+ this.addEventListener("keydown", (e) => { const d = dz(); if ((e.target === d || (d && d.contains(e.target))) && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); activate(); } });
1078
+ const renderPreview = (files) => {
1079
+ const preview = this.querySelector(".c-file-upload__preview");
1080
+ if (!preview) return;
1081
+ // Revoke the previous object URLs before dropping the <img> nodes, or
1082
+ // every re-render leaks a blob.
1083
+ this._revokeObjectUrls();
1084
+ setHTML(preview, "");
1085
+ Array.from(files || []).forEach((f) => {
1086
+ const item = document.createElement("div");
1087
+ item.className = "c-file-upload__preview-item";
1088
+ if (f.type && f.type.startsWith("image/")) {
1089
+ const img = document.createElement("img");
1090
+ img.className = "c-file-upload__preview-thumb";
1091
+ img.alt = f.name;
1092
+ img.loading = "lazy";
1093
+ img.decoding = "async";
1094
+ try { const u = URL.createObjectURL(f); img.src = u; (this._objectUrls || (this._objectUrls = [])).push(u); } catch (e) {}
1095
+ item.appendChild(img);
1096
+ } else {
1097
+ const name = document.createElement("span");
1098
+ name.className = "c-file-upload__preview-name";
1099
+ name.textContent = f.name;
1100
+ item.appendChild(name);
1101
+ }
1102
+ preview.appendChild(item);
1103
+ });
1104
+ };
1105
+ this.addEventListener("change", (e) => { const t = e.target; if (t && t.classList.contains("c-file-upload__input")) { renderPreview(t.files); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: t.files } })); } });
1106
+ // drag-drop already dispatches contour:change; also render preview there
1107
+ this.addEventListener("dragover", (e) => { e.preventDefault(); this.classList.add("is-dragover"); });
1108
+ this.addEventListener("dragleave", () => this.classList.remove("is-dragover"));
1109
+ this.addEventListener("drop", (e) => {
1110
+ e.preventDefault();
1111
+ this.classList.remove("is-dragover");
1112
+ const i = input();
1113
+ if (i && e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length) {
1114
+ // R24-116: enforce accept on drop.
1115
+ const accept = this.getAttribute("accept");
1116
+ if (accept) {
1117
+ const acceptTypes = accept.split(",").map((s) => s.trim().toLowerCase());
1118
+ const valid = Array.from(e.dataTransfer.files).filter((f) => {
1119
+ const name = f.name.toLowerCase();
1120
+ return acceptTypes.some((a) => {
1121
+ if (a.startsWith(".")) return name.endsWith(a);
1122
+ if (a.endsWith("/*")) return f.type.toLowerCase().startsWith(a.slice(0, -1));
1123
+ return f.type.toLowerCase() === a;
1124
+ });
1125
+ });
1126
+ if (valid.length === 0) return;
1127
+ assignFiles(i, valid);
1128
+ renderPreview(valid);
1129
+ // R24-116: sync form value on drop.
1130
+ this._syncFormValue();
1131
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: valid } }));
1132
+ } else {
1133
+ assignFiles(i, e.dataTransfer.files);
1134
+ renderPreview(e.dataTransfer.files);
1135
+ this._syncFormValue();
1136
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { files: e.dataTransfer.files } }));
1137
+ }
1138
+ }
1139
+ });
1140
+ }
1141
+ disconnectedCallback() {
1142
+ super.disconnectedCallback();
1143
+ this._revokeObjectUrls();
1144
+ }
1145
+ _revokeObjectUrls() {
1146
+ if (!this._objectUrls) return;
1147
+ this._objectUrls.forEach((u) => { try { URL.revokeObjectURL(u); } catch (e) {} });
1148
+ this._objectUrls = [];
1149
+ }
1150
+ // Form-value sync override (R16-06): submit the selected File(s) via
1151
+ // FormData rather than the input's (useless) path string.
1152
+ _syncFormValue() {
1153
+ if (!this._internals) return;
1154
+ const inp = this.querySelector(".c-file-upload__input");
1155
+ if (inp && inp.files && inp.files.length) {
1156
+ const fd = new FormData();
1157
+ // Use the host's name so the entry matches the control the author
1158
+ // declared, not a hard-coded "file" key.
1159
+ const key = this.getAttribute("name") || "file";
1160
+ Array.from(inp.files).forEach((f) => fd.append(key, f));
1161
+ this._internals.setFormValue(fd);
1162
+ } else {
1163
+ this._internals.setFormValue(null);
1164
+ }
1165
+ }
1166
+ }
1167
+ define("contour-file-upload", ContourFileUpload);
1168
+ /**
1169
+ * Tags Input: web component wrapper.
1170
+ * Attributes: `value`, `placeholder`, `disabled`, `error`, `help`.
1171
+ */
1172
+ class ContourTagsInput extends ContourBase {
1173
+ static get formAssociated() { return true; }
1174
+ static get observed() { return ["value", "placeholder", "disabled", "error", "help", "required", "max"]; }
1175
+ static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, required: { attribute: "required", type: Boolean }, max: { attribute: "max" } }; }
1176
+ render() {
1177
+ this.classList.add("c-tags-input");
1178
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
1179
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "tags-input", "Tags input"));
1180
+ const input = this.ensure(".c-tags-input__input", () => { const el = document.createElement("input"); el.className = "c-input c-tags-input__input"; el.type = "text"; el.setAttribute("aria-label", labelText(this, "add-tag", "Add tag")); return el; });
1181
+ input.placeholder = this.getAttribute("placeholder") || "Add tag…";
1182
+ if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
1183
+ else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
1184
+ const err = this.getAttribute("error");
1185
+ const help = this.getAttribute("help");
1186
+ let msg = this.querySelector(".c-tags-input__message");
1187
+ if (err || help) {
1188
+ if (!msg) { msg = document.createElement("div"); msg.className = "c-tags-input__message"; this.appendChild(msg); }
1189
+ if (!msg.id) msg.id = contourId("ti-msg");
1190
+ msg.textContent = err || help || "";
1191
+ msg.classList.toggle("c-tags-input__message--error", !!err);
1192
+ if (err) msg.setAttribute("role", "alert"); else msg.removeAttribute("role");
1193
+ input.setAttribute("aria-describedby", msg.id);
1194
+ } else {
1195
+ if (msg) msg.remove();
1196
+ input.removeAttribute("aria-describedby");
1197
+ }
1198
+ if (err) {
1199
+ this.classList.add("is-error");
1200
+ input.setAttribute("aria-invalid", "true");
1201
+ } else {
1202
+ this.classList.remove("is-error");
1203
+ input.removeAttribute("aria-invalid");
1204
+ }
1205
+ const tags = this.getAttribute("value");
1206
+ let parsed = [];
1207
+ try { parsed = tags ? JSON.parse(tags) : []; } catch (e) { parsed = tags ? tags.split(",").map((s) => s.trim()).filter(Boolean) : []; }
1208
+ Array.from(this.querySelectorAll(".c-tags-input__tag")).forEach((n) => n.remove());
1209
+ parsed.forEach((t) => {
1210
+ const chip = document.createElement("span");
1211
+ chip.className = "c-tag c-tags-input__tag";
1212
+ chip.textContent = t;
1213
+ const rm = document.createElement("button");
1214
+ rm.className = "c-tags-input__remove";
1215
+ rm.type = "button";
1216
+ rm.textContent = "×";
1217
+ rm.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + t);
1218
+ rm.dataset.value = t;
1219
+ chip.appendChild(rm);
1220
+ this.insertBefore(chip, input);
1221
+ });
1222
+ if (this._internals) this._syncFormValue();
1223
+ }
1224
+ enhance() {
1225
+ if (this._wiredTagsInput) return;
1226
+ this._wiredTagsInput = true;
1227
+ this._syncFormValue();
1228
+ this.addEventListener("contour:add", () => { this._syncFormValue(); });
1229
+ this.addEventListener("contour:remove", () => { this._syncFormValue(); });
1230
+ // The live region is a generated node: a re-render drops it, so look
1231
+ // it up (and recreate it) per announcement — rule 12.
1232
+ const announce = (msg) => {
1233
+ let live = this.querySelector(".c-tags-input__live");
1234
+ if (!live) {
1235
+ live = document.createElement("span");
1236
+ live.className = "c-tags-input__live visually-hidden";
1237
+ live.setAttribute("aria-live", "polite");
1238
+ live.setAttribute("aria-atomic", "true");
1239
+ this.appendChild(live);
1240
+ }
1241
+ live.textContent = msg;
1242
+ };
1243
+ const readTags = () => {
1244
+ const raw = this.getAttribute("value") || "";
1245
+ let tags = [];
1246
+ try { tags = JSON.parse(raw); } catch (err) { tags = raw.split(",").map((s) => s.trim()).filter(Boolean); }
1247
+ return Array.isArray(tags) ? tags.map(String) : [];
1248
+ };
1249
+ // One add path for Enter, comma and paste (R20 T-21): dedupe and the
1250
+ // `max` limit are announced, not silent.
1251
+ const addMany = (candidates) => {
1252
+ if (this.hasAttribute("disabled")) return;
1253
+ const tags = readTags();
1254
+ const max = Number(this.getAttribute("max"));
1255
+ const added = [], dups = [];
1256
+ let limitHit = false;
1257
+ for (const raw of candidates) {
1258
+ const v = String(raw).trim();
1259
+ if (!v) continue;
1260
+ if (tags.includes(v)) { dups.push(v); continue; }
1261
+ if (Number.isFinite(max) && max > 0 && tags.length >= max) { limitHit = true; break; }
1262
+ tags.push(v);
1263
+ added.push(v);
1264
+ }
1265
+ if (added.length) {
1266
+ this.setAttribute("value", JSON.stringify(tags));
1267
+ for (const v of added) this.dispatchEvent(new CustomEvent("contour:add", { bubbles: true, composed: true, detail: { value: v } }));
1268
+ }
1269
+ // One composed announcement AFTER the writeback re-render, so the
1270
+ // limit/duplicate feedback is not overwritten by the "Added" line.
1271
+ const parts = [];
1272
+ if (added.length) parts.push("Added " + added.join(", "));
1273
+ if (dups.length) parts.push(dups.join(", ") + " already added");
1274
+ if (limitHit) parts.push("Tag limit reached (" + max + ")");
1275
+ if (parts.length) announce(parts.join(". "));
1276
+ };
1277
+ this.addEventListener("keydown", (e) => {
1278
+ const input = this.querySelector(".c-tags-input__input");
1279
+ if (!input || this.hasAttribute("disabled")) return;
1280
+ if (e.key === "Enter" && e.target === input) {
1281
+ e.preventDefault();
1282
+ // Clear before addMany: its attribute write re-renders, so a later clear would hit the detached node.
1283
+ const v = input.value;
1284
+ input.value = "";
1285
+ addMany([v]);
1286
+ } else if (e.key === "Backspace" && e.target === input && input.value === "") {
1287
+ const tags = readTags();
1288
+ if (tags.length) {
1289
+ const removed = tags.pop();
1290
+ this.setAttribute("value", JSON.stringify(tags));
1291
+ announce("Removed " + removed);
1292
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: removed } }));
1293
+ }
1294
+ }
1295
+ });
1296
+ // A typed comma commits the segment before it, the way tag fields do.
1297
+ this.addEventListener("input", (e) => {
1298
+ const input = this.querySelector(".c-tags-input__input");
1299
+ if (!input || e.target !== input || this.hasAttribute("disabled")) return;
1300
+ if (input.value.includes(",")) {
1301
+ const parts = input.value.split(",");
1302
+ input.value = parts.pop();
1303
+ addMany(parts);
1304
+ }
1305
+ });
1306
+ // Paste splits on commas, semicolons and newlines into separate tags.
1307
+ this.addEventListener("paste", (e) => {
1308
+ const input = this.querySelector(".c-tags-input__input");
1309
+ if (!input || e.target !== input || this.hasAttribute("disabled")) return;
1310
+ const text = e.clipboardData && e.clipboardData.getData("text/plain");
1311
+ if (text && /[,;\n]/.test(text)) {
1312
+ e.preventDefault();
1313
+ addMany(text.split(/[,;\n]+/));
1314
+ }
1315
+ });
1316
+ this.addEventListener("click", (e) => {
1317
+ const rm = e.target && e.target.closest ? e.target.closest(".c-tags-input__remove") : null;
1318
+ // The remove buttons used to work while the host was disabled.
1319
+ if (rm && this.contains(rm) && !this.hasAttribute("disabled")) {
1320
+ const val = rm.dataset.value;
1321
+ const next = readTags().filter((t) => t !== val);
1322
+ this.setAttribute("value", JSON.stringify(next));
1323
+ announce("Removed " + val);
1324
+ this.dispatchEvent(new CustomEvent("contour:remove", { bubbles: true, composed: true, detail: { value: val } }));
1325
+ }
1326
+ });
1327
+ }
1328
+ // Form-value sync override: tags live as a JSON array on the host, so submit the host's value; required means at least one tag.
1329
+ _syncFormValue() {
1330
+ if (!this._internals) return;
1331
+ this._internals.setFormValue(this.getAttribute("value") || "[]");
1332
+ let count = 0;
1333
+ try { const p = JSON.parse(this.getAttribute("value") || "[]"); count = Array.isArray(p) ? p.length : 0; } catch (err) { count = (this.getAttribute("value") || "").split(",").filter((s) => s.trim()).length; }
1334
+ this._syncValidity(this.hasAttribute("required") && count === 0);
1335
+ }
1336
+ }
1337
+ define("contour-tags-input", ContourTagsInput);
1338
+ /**
1339
+ * Swatch: web component wrapper.
1340
+ * Attributes: `color`, `selected`, `label`.
1341
+ */
1342
+ class ContourSwatch extends ContourBase {
1343
+ static get observed() { return ["color", "selected", "label"]; }
1344
+ static get properties() { return { color: { attribute: "color" }, selected: { attribute: "selected", type: Boolean }, label: { attribute: "label" } }; }
1345
+ render() {
1346
+ this.classList.add("c-swatch");
1347
+ if (!this.hasAttribute("role")) this.setAttribute("role", "button");
1348
+ // role=button on a span is not focusable by itself. Without a tab stop the
1349
+ // swatch is mouse-only; a keyboard user cannot reach the picker at all.
1350
+ if (this.getAttribute("role") === "button" && !this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
1351
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || this.getAttribute("color") || "Swatch");
1352
+ const color = safeColor(this.getAttribute("color")) || "var(--color-surface-3)";
1353
+ this.style.setProperty("--swatch-color", color);
1354
+ if (this.hasAttribute("selected")) this.classList.add("is-selected");
1355
+ else this.classList.remove("is-selected");
1356
+ if (this.getAttribute("role") === "button") {
1357
+ this.setAttribute("aria-pressed", String(this.hasAttribute("selected")));
1358
+ }
1359
+ if (!this.hasAttribute("aria-label")) {
1360
+ const label = this.getAttribute("label") || color;
1361
+ this.setAttribute("aria-label", label);
1362
+ }
1363
+ if (!this.querySelector("button") && !this.querySelector("span")) {
1364
+ const span = document.createElement("span");
1365
+ span.className = "c-swatch__btn";
1366
+ span.setAttribute("aria-hidden", "true");
1367
+ this.appendChild(span);
1368
+ }
1369
+ }
1370
+ enhance() {
1371
+ if (this._wiredSwatch) return;
1372
+ this._wiredSwatch = true;
1373
+ this.addEventListener("click", () => {
1374
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: this.getAttribute("color") } }));
1375
+ });
1376
+ // A role=button must answer Enter and Space as well as the pointer.
1377
+ this.addEventListener("keydown", (e) => {
1378
+ if (e.key !== "Enter" && e.key !== " ") return;
1379
+ e.preventDefault();
1380
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: this.getAttribute("color") } }));
1381
+ });
1382
+ }
1383
+ }
1384
+ define("contour-swatch", ContourSwatch);
1385
+
1386
+ /**
1387
+ * Calendar: a month grid with keyboard navigation and optional range
1388
+ * selection (R20 T-23). Attributes: `value` (ISO date), `month` (0-11),
1389
+ * `year`, and `range` with `start`/`end`. Dates are local ISO date strings —
1390
+ * deliberately timezone-free; a consumer who needs instants converts at its
1391
+ * own boundary. One tab stop roves the grid: arrows move by day/week and
1392
+ * cross month boundaries, PageUp/PageDown change month (Shift: year),
1393
+ * Home/End jump to the month's first/last day. Weekday columnheaders name
1394
+ * the columns. In range mode the first click sets start, the second sets
1395
+ * end (ordered), and contour:select carries { value, range: [start, end] }.
1396
+ */
1397
+ class ContourCalendar extends ContourBase {
1398
+ static get observed() { return ["value", "month", "year", "range", "start", "end"]; }
1399
+ static get properties() { return { value: { attribute: "value" }, month: { attribute: "month" }, year: { attribute: "year" }, range: { attribute: "range", type: Boolean }, start: { attribute: "start" }, end: { attribute: "end" } }; }
1400
+ // month="0" is January, not "unset": the old `Number(attr) || fallback`
1401
+ // made January unreachable unless the current month happened to be it.
1402
+ _attrNum(name, fallback) {
1403
+ const raw = this.getAttribute(name);
1404
+ const n = Number(raw);
1405
+ return raw !== null && Number.isFinite(n) ? n : fallback;
1406
+ }
1407
+ _ym() {
1408
+ const now = new Date();
1409
+ return { year: this._attrNum("year", now.getFullYear()), month: this._attrNum("month", now.getMonth()) };
1410
+ }
1411
+ render() {
1412
+ this.classList.add("c-calendar");
1413
+ const now = new Date();
1414
+ const { year, month } = this._ym();
1415
+ const header = this.ensure(".c-calendar__header", () => { const el = document.createElement("div"); el.className = "c-calendar__header"; return el; });
1416
+ setHTML(header, "");
1417
+ const navBtn = (cls, glyph, label) => {
1418
+ const b = document.createElement("button");
1419
+ b.type = "button"; b.className = "c-btn c-btn--sm " + cls; b.textContent = glyph; b.setAttribute("aria-label", label);
1420
+ return b;
1421
+ };
1422
+ const prevYear = navBtn("c-calendar__prev-year", "", "Previous year");
1423
+ // R31-142: year jump uses the double-chevron sprite, not a text glyph.
1424
+ setHTML(prevYear, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevrons-left" /></svg>');
1425
+ const prev = navBtn("c-calendar__prev", "", "Previous month");
1426
+ // R31-143: month prev/next use the chevron sprite, not a text glyph.
1427
+ setHTML(prev, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-left" /></svg>');
1428
+ const title = document.createElement("span");
1429
+ title.className = "c-calendar__title";
1430
+ title.textContent = new Date(year, month, 1).toLocaleString(undefined, { month: "long", year: "numeric" });
1431
+ const next = navBtn("c-calendar__next", "", "Next month");
1432
+ setHTML(next, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
1433
+ const nextYear = navBtn("c-calendar__next-year", "", "Next year");
1434
+ setHTML(nextYear, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevrons-right" /></svg>');
1435
+ header.append(prevYear, prev, title, next, nextYear);
1436
+ const grid = this.ensure(".c-calendar__grid", () => { const el = document.createElement("div"); el.className = "c-calendar__grid"; el.setAttribute("role", "grid"); return el; });
1437
+ grid.setAttribute("aria-label", title.textContent);
1438
+ setHTML(grid, "");
1439
+ const first = new Date(year, month, 1);
1440
+ const startDay = first.getDay();
1441
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
1442
+ const isRange = this.hasAttribute("range");
1443
+ const selected = this.getAttribute("value");
1444
+ const rStart = this.getAttribute("start");
1445
+ const rEnd = this.getAttribute("end");
1446
+ let row = null;
1447
+ let col = 0;
1448
+ const newRow = () => { row = document.createElement("div"); row.className = "c-calendar__row"; row.setAttribute("role", "row"); grid.appendChild(row); col = 0; };
1449
+ // Weekday columnheaders: the grid's columns had no names.
1450
+ const wdFmt = new Intl.DateTimeFormat(undefined, { weekday: "short" });
1451
+ newRow();
1452
+ for (let i = 0; i < 7; i++) {
1453
+ const wd = document.createElement("div");
1454
+ wd.className = "c-calendar__weekday";
1455
+ wd.setAttribute("role", "columnheader");
1456
+ wd.textContent = wdFmt.format(new Date(2023, 0, 1 + i)); // 2023-01-01 was a Sunday
1457
+ row.appendChild(wd);
1458
+ }
1459
+ newRow();
1460
+ for (let i = 0; i < startDay; i++) {
1461
+ const empty = document.createElement("div");
1462
+ empty.className = "c-calendar__day c-calendar__day--empty";
1463
+ row.appendChild(empty);
1464
+ col++;
1465
+ if (col === 7) newRow();
1466
+ }
1467
+ const todayIso = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0") + "-" + String(now.getDate()).padStart(2, "0");
1468
+ // One tab stop: the selected day, else today, else the first of the month.
1469
+ const focusIso = (selected && selected.startsWith(year + "-" + String(month + 1).padStart(2, "0"))) ? selected
1470
+ : (todayIso.startsWith(year + "-" + String(month + 1).padStart(2, "0")) ? todayIso : year + "-" + String(month + 1).padStart(2, "0") + "-01");
1471
+ for (let d = 1; d <= daysInMonth; d++) {
1472
+ const cell = document.createElement("button");
1473
+ cell.className = "c-calendar__day";
1474
+ cell.type = "button";
1475
+ cell.setAttribute("role", "gridcell");
1476
+ cell.textContent = String(d);
1477
+ const iso = year + "-" + String(month + 1).padStart(2, "0") + "-" + String(d).padStart(2, "0");
1478
+ const isSelected = isRange ? (iso === rStart || iso === rEnd) : iso === selected;
1479
+ if (isSelected) cell.classList.add("is-selected");
1480
+ if (isRange && rStart && rEnd && iso > rStart && iso < rEnd) cell.classList.add("is-in-range");
1481
+ cell.setAttribute("aria-selected", String(isSelected));
1482
+ if (iso === todayIso) cell.setAttribute("aria-current", "date");
1483
+ cell.setAttribute("tabindex", iso === focusIso ? "0" : "-1");
1484
+ cell.dataset.value = iso;
1485
+ row.appendChild(cell);
1486
+ col++;
1487
+ if (col === 7) newRow();
1488
+ }
1489
+ if (header.parentNode !== this) this.insertBefore(header, grid);
1490
+ }
1491
+ enhance() {
1492
+ if (this._wiredCalendar) return;
1493
+ this._wiredCalendar = true;
1494
+ const navigate = (m, y) => {
1495
+ this.batch(() => {
1496
+ this.setAttribute("month", String(m));
1497
+ this.setAttribute("year", String(y));
1498
+ });
1499
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { month: m, year: y } }));
1500
+ };
1501
+ const focusIso = (iso) => {
1502
+ const cell = this.querySelector('.c-calendar__day[data-value="' + iso + '"]');
1503
+ if (cell) { try { cell.focus(); } catch (err) {} }
1504
+ };
1505
+ // Roving tab stop follows focus wherever it lands (click or keyboard).
1506
+ this.addEventListener("focusin", (e) => {
1507
+ const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day:not(.c-calendar__day--empty)") : null;
1508
+ if (!cell || !this.contains(cell)) return;
1509
+ for (const c of this.querySelectorAll(".c-calendar__day")) c.tabIndex = -1;
1510
+ cell.tabIndex = 0;
1511
+ });
1512
+ this.addEventListener("click", (e) => {
1513
+ const t = e.target && e.target.closest ? e.target : null;
1514
+ if (!t) return;
1515
+ const { year, month } = this._ym();
1516
+ if (t.closest(".c-calendar__prev")) { const d = new Date(year, month - 1, 1); navigate(d.getMonth(), d.getFullYear()); return; }
1517
+ if (t.closest(".c-calendar__next")) { const d = new Date(year, month + 1, 1); navigate(d.getMonth(), d.getFullYear()); return; }
1518
+ if (t.closest(".c-calendar__prev-year")) { navigate(month, year - 1); return; }
1519
+ if (t.closest(".c-calendar__next-year")) { navigate(month, year + 1); return; }
1520
+ const cell = t.closest(".c-calendar__day");
1521
+ if (cell && this.contains(cell) && cell.dataset.value) {
1522
+ const iso = cell.dataset.value;
1523
+ if (this.hasAttribute("range")) {
1524
+ const start = this.getAttribute("start");
1525
+ const end = this.getAttribute("end");
1526
+ let s, en;
1527
+ if (!start || (start && end)) { s = iso; en = null; }
1528
+ else { s = iso < start ? iso : start; en = iso < start ? start : iso; }
1529
+ this.batch(() => {
1530
+ this.setAttribute("start", s);
1531
+ if (en === null) this.removeAttribute("end"); else this.setAttribute("end", en);
1532
+ });
1533
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: iso, range: en ? [s, en] : [s] } }));
1534
+ } else {
1535
+ this.setAttribute("value", iso);
1536
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: iso } }));
1537
+ }
1538
+ }
1539
+ });
1540
+ this.addEventListener("keydown", (e) => {
1541
+ const cell = e.target && e.target.closest ? e.target.closest(".c-calendar__day:not(.c-calendar__day--empty)") : null;
1542
+ if (!cell || !this.contains(cell) || !cell.dataset.value) return;
1543
+ const [y, m, d] = cell.dataset.value.split("-").map(Number);
1544
+ const cur = new Date(y, m - 1, d);
1545
+ const { year, month } = this._ym();
1546
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
1547
+ const isoOf = (dt) => dt.getFullYear() + "-" + String(dt.getMonth() + 1).padStart(2, "0") + "-" + String(dt.getDate()).padStart(2, "0");
1548
+ let target = null;
1549
+ if (e.key === "ArrowRight") target = new Date(y, m - 1, d + 1);
1550
+ else if (e.key === "ArrowLeft") target = new Date(y, m - 1, d - 1);
1551
+ else if (e.key === "ArrowDown") target = new Date(y, m - 1, d + 7);
1552
+ else if (e.key === "ArrowUp") target = new Date(y, m - 1, d - 7);
1553
+ else if (e.key === "PageUp") target = e.shiftKey ? new Date(y - 1, m - 1, Math.min(d, new Date(y - 1, m, 0).getDate())) : new Date(y, m - 2, Math.min(d, new Date(y, m - 1, 0).getDate()));
1554
+ else if (e.key === "PageDown") target = e.shiftKey ? new Date(y + 1, m - 1, Math.min(d, new Date(y + 1, m, 0).getDate())) : new Date(y, m, Math.min(d, new Date(y, m + 1, 0).getDate()));
1555
+ else if (e.key === "Home") target = new Date(year, month, 1);
1556
+ else if (e.key === "End") target = new Date(year, month, daysInMonth);
1557
+ else return; // Enter/Space are the native button's own click
1558
+ e.preventDefault();
1559
+ const iso = isoOf(target);
1560
+ if (target.getFullYear() === year && target.getMonth() === month) {
1561
+ focusIso(iso);
1562
+ } else {
1563
+ // Cross the month boundary, then land on the target day.
1564
+ navigate(target.getMonth(), target.getFullYear());
1565
+ focusIso(iso);
1566
+ }
1567
+ });
1568
+ }
1569
+ }
1570
+ define("contour-calendar", ContourCalendar);