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,1404 @@
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
+ * Notification Center: web component wrapper.
7
+ * Attributes: `count`, `items`, `color`.
8
+ */
9
+ class ContourNotificationCenter extends ContourBase {
10
+ static get observed() { return ["count", "items", "color"]; }
11
+ static get properties() { return { count: { attribute: "count" }, items: { attribute: "items" }, color: { attribute: "color" } }; }
12
+ render() {
13
+ this.classList.add("c-notification-center");
14
+ this.setAttribute("role", "group");
15
+ const btn = this.ensure(".c-notification-center__trigger", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-btn--icon c-notification-center__trigger"; el.type = "button"; setHTML(el, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-bell" /></svg><span class="c-notification-center__bullet" aria-hidden="true"></span>'); el.setAttribute("aria-haspopup", "dialog"); el.setAttribute("aria-expanded", "false"); el.setAttribute("aria-label", labelText(this, "notifications", "Notifications")); return el; });
16
+ const color = this.getAttribute("color");
17
+ const bullet = btn.querySelector(".c-notification-center__bullet");
18
+ if (bullet && color) { bullet.style.background = safeColor(color); bullet.dataset.color = color; }
19
+ const panel = this.ensure(".c-notification-center__panel", () => { const el = document.createElement("div"); el.className = "c-notification-center__panel"; el.hidden = true; el.setAttribute("role", "dialog"); el.setAttribute("aria-label", labelText(this, "notifications", "Notifications")); return el; });
20
+ // The panel is a generated node: a re-render (show more, items change)
21
+ // rebuilds it, so the open state lives on the host, not on the node.
22
+ panel.hidden = !this._notifOpen;
23
+ btn.setAttribute("aria-expanded", String(!!this._notifOpen));
24
+ // Slotted content: authored .c-notification-center__item children take
25
+ // precedence over the JSON `items` attribute.
26
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-notification-center__item"));
27
+ const items = this.getAttribute("items");
28
+ if (authoredItems.length) {
29
+ setHTML(panel, "");
30
+ const lb = document.createElement("div");
31
+ // R24-113: list not listbox.
32
+ lb.setAttribute("role", "list");
33
+ lb.setAttribute("aria-label", labelText(this, "notifications", "Notifications"));
34
+ // R24-113: preserve authored items — move them into the list but
35
+ // keep a reference so they can be restored on re-render.
36
+ if (!this._notifAuthored) this._notifAuthored = [];
37
+ authoredItems.forEach((it) => { lb.appendChild(it); this._notifAuthored.push(it); });
38
+ panel.appendChild(lb);
39
+ } else if (items) {
40
+ let parsed = null;
41
+ try { parsed = JSON.parse(items); } catch (e) { warnBadJson(this, "items", e); }
42
+ setHTML(panel, "");
43
+ if (!Array.isArray(parsed)) {
44
+ // A malformed payload is an error state, not a silent empty panel.
45
+ const err = document.createElement("div");
46
+ err.className = "c-notification-center__error";
47
+ err.setAttribute("role", "alert");
48
+ err.textContent = labelText(this, "error", "Could not load notifications");
49
+ panel.appendChild(err);
50
+ } else {
51
+ const lb = document.createElement("div");
52
+ // R24-113: list not listbox.
53
+ lb.setAttribute("role", "list");
54
+ lb.setAttribute("aria-label", labelText(this, "notifications", "Notifications"));
55
+ // Incremental rendering keeps a long list's DOM bounded: the first
56
+ // window renders, and a control asks for the next (R20 T-17).
57
+ const shown = this._notifShown || 50;
58
+ parsed.slice(0, shown).forEach((it) => {
59
+ const row = document.createElement("div");
60
+ row.className = "c-notification-center__item" + (it && it.read ? " is-read" : "");
61
+ row.setAttribute("tabindex", "-1");
62
+ // R24-113: rows are listitems, not options. aria-current not aria-selected.
63
+ row.setAttribute("role", "listitem");
64
+ if (it && it.current) row.setAttribute("aria-current", "true");
65
+ row.dataset.read = it && it.read ? "true" : "false";
66
+ const label = document.createElement("span");
67
+ label.className = "c-notification-center__item-label";
68
+ label.textContent = typeof it === "string" ? it : (it.text || it.title || "");
69
+ row.appendChild(label);
70
+ // Archive keeps the notification out of the list without the
71
+ // dismiss semantics; both are reachable by keyboard.
72
+ const archive = document.createElement("button");
73
+ archive.type = "button";
74
+ archive.className = "c-notification-center__archive";
75
+ archive.setAttribute("aria-label", labelText(this, "archive", "Archive notification"));
76
+ archive.textContent = "⤓";
77
+ archive.tabIndex = -1;
78
+ row.appendChild(archive);
79
+ const dismiss = document.createElement("button");
80
+ dismiss.type = "button";
81
+ dismiss.className = "c-notification-center__dismiss";
82
+ dismiss.setAttribute("aria-label", labelText(this, "dismiss", "Dismiss notification"));
83
+ dismiss.textContent = "×";
84
+ dismiss.tabIndex = -1;
85
+ row.appendChild(dismiss);
86
+ lb.appendChild(row);
87
+ });
88
+ // Roving tab stop: the first row is reachable, arrows rove.
89
+ const firstRow = lb.querySelector(".c-notification-center__item");
90
+ if (firstRow) firstRow.tabIndex = 0;
91
+ panel.appendChild(lb);
92
+ if (!parsed.length) {
93
+ const empty = document.createElement("div");
94
+ empty.className = "c-notification-center__empty";
95
+ empty.textContent = labelText(this, "empty", "No notifications");
96
+ panel.appendChild(empty);
97
+ } else if (parsed.length > shown) {
98
+ const more = document.createElement("button");
99
+ more.type = "button";
100
+ more.className = "c-btn c-btn--sm c-notification-center__more";
101
+ more.textContent = labelText(this, "more", "Show more") + " (" + (parsed.length - shown) + ")";
102
+ panel.appendChild(more);
103
+ }
104
+ }
105
+ }
106
+ this._syncNotifBadge();
107
+ }
108
+ // The badge follows the LIVE unread count after read/dismiss/archive;
109
+ // the authored `count` seeds it until the first interaction (R20 T-17).
110
+ _syncNotifBadge() {
111
+ const btn = this.querySelector(".c-notification-center__trigger");
112
+ if (!btn) return;
113
+ const rows = Array.from(this.querySelectorAll(".c-notification-center__item"));
114
+ let unread;
115
+ if (this._notifInteracted || !this.hasAttribute("count")) unread = rows.filter((r) => r.dataset.read !== "true").length;
116
+ else unread = Number(this.getAttribute("count")) || 0;
117
+ let badge = btn.querySelector(".c-notification-center__badge");
118
+ if (unread > 0) {
119
+ if (!badge) { badge = document.createElement("span"); badge.className = "c-notification-center__badge c-badge c-badge--dot"; btn.appendChild(badge); }
120
+ badge.textContent = String(unread);
121
+ } else if (badge) { badge.remove(); }
122
+ }
123
+ enhance() {
124
+ if (this._wiredNotifCenter) return;
125
+ this._wiredNotifCenter = true;
126
+ const activate = (item) => {
127
+ if (item.dataset.read !== "true") {
128
+ item.dataset.read = "true";
129
+ item.classList.add("is-read");
130
+ this._notifInteracted = true;
131
+ this._syncNotifBadge();
132
+ this.dispatchEvent(new CustomEvent("contour:read", { bubbles: true, composed: true, detail: { label: item.querySelector(".c-notification-center__item-label")?.textContent || item.textContent } }));
133
+ }
134
+ // R24-113: aria-current not aria-selected.
135
+ for (const r of this.querySelectorAll(".c-notification-center__item")) {
136
+ if (r === item) r.setAttribute("aria-current", "true");
137
+ else r.removeAttribute("aria-current");
138
+ }
139
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { label: item.querySelector(".c-notification-center__item-label")?.textContent || item.textContent } }));
140
+ };
141
+ const removeRow = (item, kind) => {
142
+ const label = item.querySelector(".c-notification-center__item-label")?.textContent || item.textContent;
143
+ item.remove();
144
+ this._notifInteracted = true;
145
+ this._syncNotifBadge();
146
+ this.dispatchEvent(new CustomEvent(kind === "archive" ? "contour:remove" : "contour:dismiss", { bubbles: true, composed: true, detail: { label } }));
147
+ };
148
+ this.addEventListener("click", (e) => {
149
+ const btn = this.querySelector(".c-notification-center__trigger");
150
+ const panel = this.querySelector(".c-notification-center__panel");
151
+ if (btn && (e.target === btn || btn.contains(e.target))) {
152
+ if (panel) { panel.hidden = !panel.hidden; this._notifOpen = !panel.hidden; btn.setAttribute("aria-expanded", String(!panel.hidden)); this.dispatchEvent(new CustomEvent(panel.hidden ? "contour:close" : "contour:open", { bubbles: true, composed: true })); }
153
+ return;
154
+ }
155
+ const more = e.target && e.target.closest ? e.target.closest(".c-notification-center__more") : null;
156
+ if (more && this.contains(more)) {
157
+ this._notifShown = (this._notifShown || 50) + 50;
158
+ this.requestRender();
159
+ return;
160
+ }
161
+ const archive = e.target && e.target.closest ? e.target.closest(".c-notification-center__archive") : null;
162
+ if (archive && this.contains(archive)) {
163
+ const item = archive.closest(".c-notification-center__item");
164
+ if (item) removeRow(item, "archive");
165
+ return;
166
+ }
167
+ const dismiss = e.target && e.target.closest ? e.target.closest(".c-notification-center__dismiss") : null;
168
+ if (dismiss && this.contains(dismiss)) {
169
+ const item = dismiss.closest(".c-notification-center__item");
170
+ if (item) removeRow(item, "dismiss");
171
+ return;
172
+ }
173
+ const item = e.target && e.target.closest ? e.target.closest(".c-notification-center__item") : null;
174
+ if (item && this.contains(item)) activate(item);
175
+ });
176
+ const docClick = (e) => {
177
+ const panel = this.querySelector(".c-notification-center__panel");
178
+ const btn = this.querySelector(".c-notification-center__trigger");
179
+ if (panel && !panel.hidden && !this.contains(e.target)) { panel.hidden = true; this._notifOpen = false; if (btn) btn.setAttribute("aria-expanded", "false"); }
180
+ };
181
+ document.addEventListener("click", docClick);
182
+ onDispose(this, () => document.removeEventListener("click", docClick));
183
+ const keyHandler = (e) => {
184
+ const panel = this.querySelector(".c-notification-center__panel");
185
+ const btn = this.querySelector(".c-notification-center__trigger");
186
+ if (e.key === "Escape" && panel && !panel.hidden) { panel.hidden = true; this._notifOpen = false; if (btn) { btn.setAttribute("aria-expanded", "false"); try { btn.focus(); } catch (err) {} } return; }
187
+ if (!panel || panel.hidden) return;
188
+ const items = Array.from(panel.querySelectorAll(".c-notification-center__item"));
189
+ if (!items.length) return;
190
+ // Enter/Space activate the focused row (a div synthesizes no click);
191
+ // Delete dismisses it. navKey roves the tab stop with the focus. The
192
+ // row's buttons are pointer shortcuts (tabindex -1) so the row is the
193
+ // single tab stop and the listitem is not a nested tab stop.
194
+ if ((e.key === "Enter" || e.key === " ") && items.includes(e.target)) {
195
+ e.preventDefault();
196
+ activate(e.target);
197
+ return;
198
+ }
199
+ if ((e.key === "Delete" || e.key === "Backspace") && items.includes(e.target)) {
200
+ e.preventDefault();
201
+ const idx = items.indexOf(e.target);
202
+ removeRow(e.target, "dismiss");
203
+ const next = items[idx + 1] || items[idx - 1];
204
+ if (next && next.isConnected) { try { next.focus(); } catch (err) {} }
205
+ return;
206
+ }
207
+ navKey(e, items, { wrap: true, onNavigate: (i) => { items.forEach((r, j) => { r.tabIndex = j === i ? 0 : -1; }); } });
208
+ };
209
+ document.addEventListener("keydown", keyHandler);
210
+ onDispose(this, () => document.removeEventListener("keydown", keyHandler));
211
+ }
212
+ }
213
+ define("contour-notification-center", ContourNotificationCenter);
214
+
215
+ /**
216
+ * Stepper: web component wrapper.
217
+ * Attributes: `steps`, `current`.
218
+ */
219
+ class ContourStepper extends ContourBase {
220
+ static get observed() { return ["steps", "current"]; }
221
+ static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current" } }; }
222
+ render() {
223
+ this.classList.add("c-stepper");
224
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
225
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "stepper", "Stepper"));
226
+ const steps = this.getAttribute("steps");
227
+ const current = Number(this.getAttribute("current") || 0);
228
+ const list = this.ensure(".c-stepper__list", () => { const el = document.createElement("ol"); el.className = "c-stepper__list"; return el; });
229
+ setHTML(list, "");
230
+ // Slotted content: authored .c-stepper__step children take precedence.
231
+ const authoredSteps = Array.from(this.querySelectorAll(":scope > .c-stepper__step"));
232
+ let parsed = [];
233
+ if (authoredSteps.length) {
234
+ parsed = authoredSteps.map((el) => el.textContent.trim());
235
+ // Keep authored steps in a private cache across re-renders; an explicit `steps` attribute still wins.
236
+ this._stepperAuthored = parsed;
237
+ authoredSteps.forEach((el) => el.remove());
238
+ } else if (steps) {
239
+ try { parsed = JSON.parse(steps); } catch (e) { warnBadJson(this, "steps", e); parsed = this._stepperAuthored || []; }
240
+ } else {
241
+ parsed = this._stepperAuthored || [];
242
+ }
243
+ parsed.forEach((s, i) => {
244
+ const li = document.createElement("li");
245
+ li.className = "c-stepper__step" + (i === current ? " is-current" : "") + (i < current ? " is-done" : "");
246
+ if (i === current) li.setAttribute("aria-current", "step");
247
+ // R24-114: steps are focusable.
248
+ li.setAttribute("tabindex", i === current ? "0" : "-1");
249
+ // R31-149: a done step shows a check, the rest show their number; the
250
+ // marker is decorative (aria-hidden) and the label carries the name.
251
+ const marker = document.createElement("span");
252
+ marker.className = "c-stepper__marker";
253
+ marker.setAttribute("aria-hidden", "true");
254
+ if (i < current) setHTML(marker, '<svg viewBox="0 0 24 24"><use href="#i-check" /></svg>');
255
+ else marker.textContent = String(i + 1);
256
+ li.appendChild(marker);
257
+ const label = document.createElement("span");
258
+ label.className = "c-stepper__label";
259
+ label.textContent = typeof s === "string" ? s : (s.title || s.label || "");
260
+ li.appendChild(label);
261
+ list.appendChild(li);
262
+ });
263
+ const nav = this.ensure(".c-stepper__nav", () => { const el = document.createElement("div"); el.className = "c-stepper__nav c-btn-group"; return el; });
264
+ const prev = this.ensure(".c-stepper__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-stepper__prev"; el.type = "button"; return el; });
265
+ // Copy is set on every render, not only at creation: `ensure()` builds the
266
+ // node once, so a `labels` change would otherwise reach nothing.
267
+ prev.textContent = labelText(this, "prev", "Back");
268
+ // R24-114: disable prev at boundary.
269
+ if (current <= 0) prev.setAttribute("disabled", ""); else prev.removeAttribute("disabled");
270
+ const next = this.ensure(".c-stepper__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-stepper__next"; el.type = "button"; return el; });
271
+ next.textContent = labelText(this, "next", "Next");
272
+ // R24-114: disable next at boundary.
273
+ if (current >= parsed.length - 1) next.setAttribute("disabled", ""); else next.removeAttribute("disabled");
274
+ if (!nav.contains(prev)) nav.appendChild(prev);
275
+ if (!nav.contains(next)) nav.appendChild(next);
276
+ if (nav.parentNode !== this) this.appendChild(nav);
277
+ }
278
+ enhance() {
279
+ if (this._wiredStepper) return;
280
+ this._wiredStepper = true;
281
+ const go = (dir) => {
282
+ const list = this.querySelector(".c-stepper__list");
283
+ const total = list ? list.querySelectorAll(".c-stepper__step").length : 0;
284
+ if (!total) return;
285
+ let cur = Number(this.getAttribute("current") || 0);
286
+ if (dir === "prev") cur = Math.max(0, cur - 1);
287
+ else cur = Math.min(total - 1, cur + 1);
288
+ this.setAttribute("current", String(cur));
289
+ this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: dir, index: cur } }));
290
+ };
291
+ this.addEventListener("click", (e) => {
292
+ const prev = e.target && e.target.closest ? e.target.closest(".c-stepper__prev") : null;
293
+ const next = e.target && e.target.closest ? e.target.closest(".c-stepper__next") : null;
294
+ if (prev && this.contains(prev)) { go("prev"); return; }
295
+ if (next && this.contains(next)) { go("next"); return; }
296
+ // Click a step to jump to it: the step is a control, not just a label.
297
+ const step = e.target && e.target.closest ? e.target.closest(".c-stepper__step") : null;
298
+ if (step && this.contains(step)) {
299
+ const items = Array.from(this.querySelectorAll(".c-stepper__step"));
300
+ const idx = items.indexOf(step);
301
+ if (idx >= 0 && idx !== Number(this.getAttribute("current") || 0)) {
302
+ this.setAttribute("current", String(idx));
303
+ this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { direction: "jump", index: idx } }));
304
+ }
305
+ }
306
+ });
307
+ this.addEventListener("keydown", (e) => {
308
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
309
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
310
+ });
311
+ }
312
+ }
313
+ define("contour-stepper", ContourStepper);
314
+
315
+ /**
316
+ * Virtual List: web component wrapper.
317
+ * Attributes: `items`, `item-height`, `orientation`, `sticky`.
318
+ */
319
+ class ContourVirtualList extends ContourBase {
320
+ static get updateMode() { return "keyed"; }
321
+ static get observed() { return ["items", "item-height", "orientation", "sticky"]; }
322
+ static get properties() { return { items: { attribute: "items" }, "item-height": { attribute: "item-height" }, orientation: { attribute: "orientation" }, sticky: { attribute: "sticky", type: Boolean } }; }
323
+ _items() {
324
+ const items = this.getAttribute("items");
325
+ let parsed = [];
326
+ try { parsed = items ? JSON.parse(items) : []; } catch (e) { warnBadJson(this, "items", e); parsed = []; }
327
+ return Array.isArray(parsed) ? parsed : [];
328
+ }
329
+ _itemHeight() {
330
+ const h = Number(this.getAttribute("item-height"));
331
+ if (Number.isFinite(h) && h > 0) return h;
332
+ return cssLength("--virtual-list-item-height", 28);
333
+ }
334
+ _autoHeight() {
335
+ return this.getAttribute("item-height") === "auto";
336
+ }
337
+ render() {
338
+ this.classList.add("c-virtual-list");
339
+ this.setAttribute("role", "list");
340
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "virtual-list", "Virtual list"));
341
+ const scroller = this.ensure(".c-virtual-list__scroller", () => { const el = document.createElement("div"); el.className = "c-virtual-list__scroller"; return el; });
342
+ scroller.setAttribute("role", "presentation");
343
+ const horizontal = this.getAttribute("orientation") === "horizontal";
344
+ scroller.style.overflowX = horizontal ? "auto" : "hidden";
345
+ scroller.style.overflowY = horizontal ? "hidden" : "auto";
346
+ const inner = this.ensure(".c-virtual-list__inner", () => { const el = document.createElement("div"); el.className = "c-virtual-list__inner"; el.style.position = "relative"; return el; });
347
+ if (inner.parentNode !== scroller) scroller.appendChild(inner);
348
+ this._renderWindow(scroller, inner, horizontal ? (scroller.scrollLeft || 0) : (scroller.scrollTop || 0));
349
+ }
350
+ _measureHeights(inner, horizontal) {
351
+ const rows = Array.from(inner.querySelectorAll(".c-virtual-list__item"));
352
+ return rows.map((r) => horizontal ? (r.getBoundingClientRect().width || this._itemHeight()) : (r.getBoundingClientRect().height || this._itemHeight()));
353
+ }
354
+ _renderWindow(scroller, inner, scrollTop) {
355
+ const items = this._items();
356
+ const ih = this._itemHeight();
357
+ const horizontal = this.getAttribute("orientation") === "horizontal";
358
+ const autoHeight = this._autoHeight();
359
+ const viewportSize = horizontal ? (scroller.clientWidth || 320) : (scroller.clientHeight || 320);
360
+ const total = items.length;
361
+ // Reset measured heights when item count changes.
362
+ if (this._vlItemCount !== total) { this._vlHeights = null; this._vlItemCount = total; }
363
+ let heights = autoHeight ? this._vlHeights : null;
364
+ let cumulative = null;
365
+ if (autoHeight && heights && heights.length === total) {
366
+ cumulative = [0];
367
+ for (let i = 0; i < total; i++) cumulative.push(cumulative[i] + (heights[i] || this._itemHeight()));
368
+ }
369
+ const visibleCount = autoHeight && !cumulative ? total : (autoHeight ? Math.ceil(viewportSize / this._itemHeight()) + 6 : Math.ceil(viewportSize / ih) + 4);
370
+ let start = 0;
371
+ if (autoHeight && cumulative) {
372
+ // binary search for start
373
+ let lo = 0, hi = total;
374
+ while (lo < hi) {
375
+ const mid = (lo + hi) >> 1;
376
+ if (cumulative[mid] < (scrollTop || 0)) lo = mid + 1; else hi = mid;
377
+ }
378
+ start = Math.max(0, lo - 3);
379
+ } else if (!autoHeight) {
380
+ start = Math.floor((scrollTop || 0) / ih);
381
+ }
382
+ if (start < 0) start = 0;
383
+ const end = autoHeight && cumulative
384
+ ? Math.min(total, start + visibleCount)
385
+ : Math.min(total, start + visibleCount);
386
+ if (start > Math.max(0, total - visibleCount) && !autoHeight) start = Math.max(0, total - visibleCount);
387
+ const topSpacerSize = autoHeight && cumulative ? cumulative[start] : (autoHeight ? 0 : start * ih);
388
+ const bottomSpacerSize = autoHeight && cumulative ? Math.max(0, cumulative[total] - cumulative[end]) : (autoHeight ? 0 : Math.max(0, (total - end) * ih));
389
+ inner.style.display = horizontal ? "flex" : "block";
390
+ inner.style.width = horizontal && autoHeight ? "max-content" : "";
391
+ inner.style.height = horizontal || autoHeight ? "" : (total * ih) + "px";
392
+ setHTML(inner, "");
393
+ const top = document.createElement("div");
394
+ top.className = "c-virtual-list__spacer c-virtual-list__spacer--top";
395
+ top.style[horizontal ? "width" : "height"] = topSpacerSize + "px";
396
+ inner.appendChild(top);
397
+ for (let i = start; i < end; i++) {
398
+ const row = document.createElement("div");
399
+ row.className = "c-virtual-list__item";
400
+ row.setAttribute("role", "listitem");
401
+ // A windowed list must publish its position in the whole set, or a
402
+ // screen reader cannot tell "item 3 of 1,000" from "item 3 of 12".
403
+ row.setAttribute("aria-setsize", String(total));
404
+ row.setAttribute("aria-posinset", String(i + 1));
405
+ row.setAttribute("tabindex", i === 0 ? "0" : "-1");
406
+ row.textContent = typeof items[i] === "string" ? items[i] : (items[i].label || items[i].text || JSON.stringify(items[i]));
407
+ if (this.hasAttribute("sticky") && items[i] && items[i].sticky) {
408
+ row.style.position = "sticky";
409
+ row.style.insetBlockStart = "0";
410
+ row.style.zIndex = "1";
411
+ }
412
+ if (horizontal && !autoHeight) row.style.flex = "0 0 " + ih + "px";
413
+ row.dataset.index = String(i);
414
+ inner.appendChild(row);
415
+ }
416
+ const bottom = document.createElement("div");
417
+ bottom.className = "c-virtual-list__spacer c-virtual-list__spacer--bottom";
418
+ bottom.style[horizontal ? "width" : "height"] = bottomSpacerSize + "px";
419
+ inner.appendChild(bottom);
420
+ if (horizontal && !autoHeight) inner.style.width = (total * ih) + "px";
421
+ // Measure heights in auto mode for future windowing.
422
+ if (autoHeight && !this._vlHeights) {
423
+ // defer measurement to next frame so layout is done
424
+ requestAnimationFrame(() => {
425
+ this._vlHeights = this._measureHeights(inner, horizontal);
426
+ // re-render windowed now that heights known
427
+ const s = scroller;
428
+ const i = inner;
429
+ if (s && i) this._renderWindow(s, i, s.scrollTop || 0);
430
+ });
431
+ }
432
+ }
433
+ enhance() {
434
+ if (this._wiredVirtualList) return;
435
+ this._wiredVirtualList = true;
436
+ const scroller = () => this.querySelector(".c-virtual-list__scroller");
437
+ const inner = () => this.querySelector(".c-virtual-list__inner");
438
+ let raf = 0;
439
+ const onScroll = () => {
440
+ if (raf) return;
441
+ raf = requestAnimationFrame(() => {
442
+ raf = 0;
443
+ const s = scroller(); const i = inner();
444
+ if (s && i) this._renderWindow(s, i, this.getAttribute("orientation") === "horizontal" ? s.scrollLeft : s.scrollTop);
445
+ });
446
+ };
447
+ // Delegate scroll on the host with capture: the scroller is rebuilt every render, so a listener on it is lost.
448
+ this.addEventListener("scroll", onScroll, { passive: true, capture: true });
449
+ onDispose(this, () => { this.removeEventListener("scroll", onScroll, { capture: true }); if (raf) cancelAnimationFrame(raf); });
450
+ // keyboard + selection
451
+ this.addEventListener("keydown", (e) => {
452
+ const rows = Array.from(this.querySelectorAll(".c-virtual-list__item"));
453
+ if (!rows.length) return;
454
+ const horizontal = this.getAttribute("orientation") === "horizontal";
455
+ const fwd = horizontal ? "ArrowRight" : "ArrowDown";
456
+ const back = horizontal ? "ArrowLeft" : "ArrowUp";
457
+ const active = document.activeElement;
458
+ const at = rows.indexOf(active);
459
+ const scroller = this.querySelector(".c-virtual-list__scroller");
460
+ const inner = this.querySelector(".c-virtual-list__inner");
461
+ // At the window edge the next item is not rendered: scroll one row and
462
+ // re-render, then move focus, instead of stopping at the last node.
463
+ if ((e.key === fwd && at === rows.length - 1) || (e.key === back && at === 0 && Number(active && active.dataset.index) > 0)) {
464
+ e.preventDefault();
465
+ if (scroller && inner) {
466
+ const delta = (e.key === fwd ? 1 : -1) * this._itemHeight();
467
+ if (horizontal) scroller.scrollLeft += delta; else scroller.scrollTop += delta;
468
+ this._renderWindow(scroller, inner, horizontal ? scroller.scrollLeft : scroller.scrollTop);
469
+ const targetIndex = Number(active && active.dataset.index) + (e.key === fwd ? 1 : -1);
470
+ requestAnimationFrame(() => {
471
+ const next = this.querySelector(`.c-virtual-list__item[data-index="${targetIndex}"]`);
472
+ // R24-115: re-query rows after re-render — the old `rows` array
473
+ // contains stale nodes that were removed by innerHTML = "".
474
+ const freshRows = Array.from(this.querySelectorAll(".c-virtual-list__item"));
475
+ if (next) { freshRows.forEach((r) => r.setAttribute("tabindex", "-1")); next.setAttribute("tabindex", "0"); try { next.focus(); } catch (err) {} }
476
+ });
477
+ }
478
+ return;
479
+ }
480
+ navKey(e, rows, { wrap: false, homeEnd: true, onNavigate: (i) => rows.forEach((r, j) => r.setAttribute("tabindex", j === i ? "0" : "-1")), onKey: () => { if (e.key === "Enter" || e.key === " ") { const i = Number(document.activeElement.dataset.index); this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: document.activeElement.textContent } })); } } });
481
+ });
482
+ this.addEventListener("click", (e) => {
483
+ const row = e.target && e.target.closest ? e.target.closest(".c-virtual-list__item") : null;
484
+ if (!row || !this.contains(row)) return;
485
+ const i = Number(row.dataset.index);
486
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: i, value: row.textContent } }));
487
+ });
488
+ }
489
+ }
490
+ define("contour-virtual-list", ContourVirtualList);
491
+ /**
492
+ * Sortable List: a reorderable list. Attributes: `items` (JSON, the authored
493
+ * data) and `order` (JSON array of source indices — the user's permutation,
494
+ * written back on every move so a re-render never reverts it, R20 T-22).
495
+ * Drag with the pointer, or focus a handle and use ArrowUp/Down/Home/End;
496
+ * moves announce position and emit contour:move + contour:reorder.
497
+ * Update mode is scaffold: the list rebuilds on render (the old "keyed"
498
+ * claim was false — render cleared innerHTML).
499
+ */
500
+ class ContourSortableList extends ContourBase {
501
+ static get observed() { return ["items", "order"]; }
502
+ static get properties() { return { items: { attribute: "items" }, order: { attribute: "order" } }; }
503
+ render() {
504
+ this.classList.add("c-sortable-list");
505
+ const list = this.ensure(".c-sortable-list__list", () => { const el = document.createElement("ul"); el.className = "c-sortable-list__list"; return el; });
506
+ const items = this.getAttribute("items");
507
+ let parsed = [];
508
+ try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
509
+ if (!Array.isArray(parsed)) parsed = [];
510
+ // Apply the user's permutation when it still fits the data; a changed
511
+ // items payload with a stale order falls back to the authored sequence.
512
+ let sourceOrder = Array.from({ length: parsed.length }, (_, i) => i);
513
+ const orderRaw = this.getAttribute("order");
514
+ if (orderRaw) {
515
+ try {
516
+ const order = JSON.parse(orderRaw);
517
+ if (Array.isArray(order) && order.length === parsed.length && order.every((i) => Number.isInteger(i) && i >= 0 && i < parsed.length)) {
518
+ sourceOrder = order.slice();
519
+ parsed = order.map((i) => parsed[i]);
520
+ }
521
+ } catch (e) { /* a malformed order is ignored, not fatal */ }
522
+ }
523
+ this._sortableSourceOrder = sourceOrder;
524
+ this._sortableItems = parsed;
525
+ setHTML(list, "");
526
+ parsed.forEach((it, i) => {
527
+ const li = document.createElement("li");
528
+ li.className = "c-sortable-list__item";
529
+ li.setAttribute("draggable", "true");
530
+ li.dataset.index = String(i);
531
+ const itemLabel = typeof it === "string" ? it : (it.label || it.text || "");
532
+ const handle = document.createElement("span");
533
+ handle.className = "c-sortable-list__handle";
534
+ handle.textContent = "⋮⋮";
535
+ handle.setAttribute("role", "button");
536
+ // "⋮⋮" is the glyph, not a name. A screen reader hears the glyph as
537
+ // punctuation unless the handle says what it moves.
538
+ handle.setAttribute("aria-label", labelText(this, "reorder", "Reorder") + " " + (itemLabel || String(i + 1)));
539
+ // The writeback re-render rebuilds the list; the preserve key puts
540
+ // focus back on the handle that moved, not the one at its old index.
541
+ handle.setAttribute("data-contour-preserve-key", itemLabel || String(i));
542
+ handle.tabIndex = 0;
543
+ li.appendChild(handle);
544
+ const labelEl = document.createElement("span");
545
+ labelEl.className = "c-sortable-list__label";
546
+ labelEl.textContent = itemLabel;
547
+ li.appendChild(labelEl);
548
+ list.appendChild(li);
549
+ });
550
+ }
551
+ enhance() {
552
+ if (this._wiredSortableList) return;
553
+ this._wiredSortableList = true;
554
+ const list = () => this.querySelector(".c-sortable-list__list");
555
+ // Live region for position announcements. Generated node: the writeback
556
+ // re-render drops it, so look it up (and recreate it) per call — rule 12.
557
+ const announce = (msg) => {
558
+ let live = this.querySelector(".c-sortable-list__live");
559
+ if (!live) {
560
+ live = document.createElement("span");
561
+ live.className = "c-sortable-list__live visually-hidden";
562
+ live.setAttribute("aria-live", "polite");
563
+ live.setAttribute("aria-atomic", "true");
564
+ this.appendChild(live);
565
+ }
566
+ live.textContent = msg;
567
+ };
568
+ const index = (li) => Array.from(list().children).indexOf(li);
569
+ // Persist the permutation: the DOM move alone is reverted by the next re-render; `order` maps display positions to source indices.
570
+ const writeBack = (from, to) => {
571
+ const n = (this._sortableItems || []).length;
572
+ const cur = Array.isArray(this._sortableSourceOrder) && this._sortableSourceOrder.length === n
573
+ ? this._sortableSourceOrder.slice()
574
+ : Array.from({ length: n }, (_, i) => i);
575
+ const [src] = cur.splice(from, 1);
576
+ cur.splice(to, 0, src);
577
+ this.setAttribute("order", JSON.stringify(cur));
578
+ };
579
+ // Pointer drag reorder.
580
+ let dragFrom = null;
581
+ this.addEventListener("dragstart", (e) => {
582
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
583
+ if (!li || !this.contains(li)) return;
584
+ dragFrom = index(li);
585
+ if (e.dataTransfer) { e.dataTransfer.effectAllowed = "move"; try { e.dataTransfer.setData("text/plain", String(dragFrom)); } catch (err) {} }
586
+ li.classList.add("is-dragging");
587
+ });
588
+ this.addEventListener("dragover", (e) => {
589
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
590
+ if (!li || !this.contains(li) || dragFrom === null) return;
591
+ e.preventDefault();
592
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
593
+ });
594
+ this.addEventListener("drop", (e) => {
595
+ const li = e.target && e.target.closest ? e.target.closest(".c-sortable-list__item") : null;
596
+ if (!li || !this.contains(li) || dragFrom === null) return;
597
+ e.preventDefault();
598
+ const to = index(li);
599
+ const l = list();
600
+ const fromLi = l.children[dragFrom];
601
+ if (fromLi && dragFrom !== to) {
602
+ if (dragFrom < to) l.insertBefore(fromLi, l.children[to + 1] || null);
603
+ else l.insertBefore(fromLi, l.children[to]);
604
+ const item = fromLi.querySelector(".c-sortable-list__label");
605
+ announce((item ? item.textContent : "Item") + " moved to position " + (to + 1));
606
+ const from = dragFrom;
607
+ writeBack(from, to);
608
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
609
+ }
610
+ dragFrom = null;
611
+ Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
612
+ });
613
+ this.addEventListener("dragend", () => {
614
+ dragFrom = null;
615
+ const l = list();
616
+ if (l) Array.from(l.children).forEach((n) => n.classList.remove("is-dragging"));
617
+ });
618
+ // Handle activation (role=button must activate on click/Enter/Space).
619
+ this.addEventListener("click", (e) => {
620
+ const handle = e.target && e.target.closest ? e.target.closest(".c-sortable-list__handle") : null;
621
+ if (!handle || !this.contains(handle)) return;
622
+ const pressed = handle.getAttribute("aria-pressed") === "true";
623
+ handle.setAttribute("aria-pressed", String(!pressed));
624
+ handle.classList.toggle("is-grabbed", !pressed);
625
+ const li = handle.closest(".c-sortable-list__item");
626
+ const label = li && li.querySelector(".c-sortable-list__label");
627
+ const name = label ? label.textContent : "Item";
628
+ announce(!pressed ? `${name} grabbed; use Up or Down arrows to reorder` : `${name} released`);
629
+ });
630
+ // Keyboard reorder.
631
+ this.addEventListener("keydown", (e) => {
632
+ const handle = e.target && e.target.closest ? e.target.closest(".c-sortable-list__handle") : null;
633
+ if (!handle) return;
634
+ if (e.key === "Enter" || e.key === " ") {
635
+ e.preventDefault();
636
+ handle.click();
637
+ return;
638
+ }
639
+ const li = handle.closest(".c-sortable-list__item");
640
+ if (!li) return;
641
+ const l = list();
642
+ const from = index(li);
643
+ const moved = (direction, to) => {
644
+ const label = li.querySelector(".c-sortable-list__label");
645
+ announce((label ? label.textContent : "Item") + " moved to position " + (to + 1));
646
+ writeBack(from, to);
647
+ this.dispatchEvent(new CustomEvent("contour:move", { bubbles: true, composed: true, detail: { direction, from, to } }));
648
+ this.dispatchEvent(new CustomEvent("contour:reorder", { bubbles: true, composed: true, detail: { from, to } }));
649
+ };
650
+ if (e.key === "ArrowUp" && li.previousElementSibling) {
651
+ e.preventDefault();
652
+ l.insertBefore(li, li.previousElementSibling);
653
+ moved("up", index(li));
654
+ } else if (e.key === "ArrowDown" && li.nextElementSibling) {
655
+ e.preventDefault();
656
+ l.insertBefore(li.nextElementSibling, li);
657
+ moved("down", index(li));
658
+ } else if (e.key === "Home" && from > 0) {
659
+ e.preventDefault();
660
+ l.insertBefore(li, l.firstElementChild);
661
+ moved("up", 0);
662
+ } else if (e.key === "End" && from < l.children.length - 1) {
663
+ e.preventDefault();
664
+ l.appendChild(li);
665
+ moved("down", l.children.length - 1);
666
+ }
667
+ });
668
+ }
669
+ }
670
+ define("contour-sortable-list", ContourSortableList);
671
+ /**
672
+ * Carousel: slides with prev/next, dots, swipe and arrow keys. Attributes:
673
+ * `items`, `index`, `autoplay` (milliseconds per slide) and `paused`.
674
+ * Autoplay ships with a pause/play control and never starts under
675
+ * prefers-reduced-motion (WCAG 2.2.2, R20 T-24); the timer reconciles with
676
+ * the attributes on every render and dies with the host.
677
+ */
678
+ class ContourCarousel extends ContourBase {
679
+ static get observed() { return ["items", "index", "autoplay", "paused"]; }
680
+ static get properties() { return { items: { attribute: "items" }, index: { attribute: "index" }, autoplay: { attribute: "autoplay" }, paused: { attribute: "paused", type: Boolean } }; }
681
+ _items() {
682
+ const items = this.getAttribute("items");
683
+ let parsed = [];
684
+ try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
685
+ return Array.isArray(parsed) ? parsed : [];
686
+ }
687
+ _index() {
688
+ const i = Number(this.getAttribute("index"));
689
+ const items = this._items();
690
+ if (Number.isFinite(i) && i >= 0 && i < items.length) return i;
691
+ return 0;
692
+ }
693
+ render() {
694
+ this.classList.add("c-carousel");
695
+ this.setAttribute("role", "region");
696
+ this.setAttribute("aria-roledescription", "carousel");
697
+ // Authored slides (direct children) are replaced by generated ones from
698
+ // the `items` attribute; clear them so they don't show alongside the track.
699
+ Array.from(this.children).forEach((child) => {
700
+ if (child.classList && child.classList.contains("c-carousel__slide") && child.parentElement === this) child.remove();
701
+ });
702
+ const track = this.ensure(".c-carousel__track", () => { const el = document.createElement("div"); el.className = "c-carousel__track"; el.setAttribute("role", "group"); el.setAttribute("aria-roledescription", "slide container"); return el; });
703
+ const items = this._items();
704
+ setHTML(track, "");
705
+ const idx = this._index();
706
+ items.forEach((it, i) => {
707
+ const slide = document.createElement("div");
708
+ slide.className = "c-carousel__slide" + (i === idx ? " is-active" : "");
709
+ slide.setAttribute("role", "group");
710
+ slide.setAttribute("aria-roledescription", "slide");
711
+ slide.setAttribute("aria-label", (i + 1) + " of " + items.length);
712
+ slide.setAttribute("aria-hidden", i === idx ? "false" : "true");
713
+ // R31-75: a slide may carry media (it.src / it.image / it.video) instead
714
+ // of text. An <img> gets alt text; a <video> is controlled. A plain
715
+ // string or {label|text} still renders as text.
716
+ const mediaSrc = (typeof it === "object" && it) ? (it.src || it.image || it.video) : null;
717
+ if (mediaSrc) {
718
+ const isVideo = (typeof it === "object" && it) ? (it.type === "video" || !!it.video) : false;
719
+ slide.classList.add("c-carousel__slide--media");
720
+ const media = document.createElement(isVideo ? "video" : "img");
721
+ media.src = mediaSrc;
722
+ if (isVideo) {
723
+ media.controls = true;
724
+ if (it.poster) media.poster = it.poster;
725
+ } else {
726
+ media.alt = (typeof it === "object" && (it.alt || it.label)) || "";
727
+ }
728
+ slide.appendChild(media);
729
+ } else {
730
+ slide.textContent = typeof it === "string" ? it : (it.label || it.text || "");
731
+ }
732
+ slide.dataset.index = String(i);
733
+ track.appendChild(slide);
734
+ });
735
+ const prev = this.ensure(".c-carousel__prev", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-btn--icon c-carousel__prev"; el.type = "button"; setHTML(el, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-left" /></svg>'); el.setAttribute("aria-label", labelText(this, "previous-slide", "Previous slide")); return el; });
736
+ const next = this.ensure(".c-carousel__next", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-btn--icon c-carousel__next"; el.type = "button"; setHTML(el, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>'); el.setAttribute("aria-label", labelText(this, "next-slide", "Next slide")); return el; });
737
+ const status = this.ensure(".c-carousel__status", () => { const el = document.createElement("span"); el.className = "c-carousel__status"; return el; });
738
+ const autoplayAttr = Number(this.getAttribute("autoplay"));
739
+ const isAutoplaying = Number.isFinite(autoplayAttr) && autoplayAttr > 0 && !this.hasAttribute("paused") && !this._reducedMotion();
740
+ status.setAttribute("aria-live", isAutoplaying ? "off" : "polite");
741
+ status.textContent = items.length ? ((idx + 1) + " of " + items.length) : "0 of 0";
742
+ // Indicators: one dot per slide, using button + aria-current (not role=tab
743
+ // without tabpanel/aria-controls, which violates axe aria-required-attr).
744
+ const dots = this.ensure(".c-carousel__dots", () => { const el = document.createElement("div"); el.className = "c-carousel__dots"; el.setAttribute("role", "group"); el.setAttribute("aria-label", labelText(this, "slide-controls", "Slide controls")); return el; });
745
+ dots.setAttribute("role", "group");
746
+ dots.setAttribute("aria-label", labelText(this, "slide-controls", "Slide controls"));
747
+ setHTML(dots, "");
748
+ items.forEach((it, i) => {
749
+ const dot = document.createElement("button");
750
+ dot.type = "button";
751
+ dot.className = "c-carousel__dot" + (i === idx ? " is-active" : "");
752
+ dot.setAttribute("aria-label", labelText(this, "go-to-slide", "Go to slide") + " " + (i + 1));
753
+ dot.setAttribute("aria-current", i === idx ? "true" : "false");
754
+ dot.tabIndex = i === idx ? 0 : -1;
755
+ dot.dataset.index = String(i);
756
+ dots.appendChild(dot);
757
+ });
758
+ // Autoplay ships with its own pause control (WCAG 2.2.2): auto-starting content must be pausable.
759
+ const autoplay = autoplayAttr;
760
+ if (Number.isFinite(autoplay) && autoplay > 0) {
761
+ const paused = this.hasAttribute("paused") || this._reducedMotion();
762
+ const pp = this.ensure(".c-carousel__pause", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-btn--icon c-carousel__pause"; el.type = "button"; return el; });
763
+ // R31-139/R31-142: sprite glyph (not a Unicode triangle) and a
764
+ // labelText'd name, so the control is icon-only and translatable.
765
+ setHTML(pp, paused ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-play" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-pause" /></svg>');
766
+ pp.setAttribute("aria-label", paused ? labelText(this, "play-slides", "Play slides automatically") : labelText(this, "pause-slides", "Pause automatic slides"));
767
+ pp.setAttribute("aria-pressed", String(paused));
768
+ pp.disabled = this._reducedMotion();
769
+ } else {
770
+ const pp = this.querySelector(".c-carousel__pause");
771
+ if (pp) pp.remove();
772
+ }
773
+ }
774
+ _reducedMotion() {
775
+ try { return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches; } catch (e) { return false; }
776
+ }
777
+ enhance() {
778
+ // Autoplay reconciles with the attributes every render: `paused`, a removed `autoplay`, or reduced motion stops the timer.
779
+ const autoplay = Number(this.getAttribute("autoplay"));
780
+ const want = Number.isFinite(autoplay) && autoplay > 0 && !this.hasAttribute("paused") && !this._reducedMotion() && this._items().length > 1;
781
+ if (want && !this._carouselTimer) {
782
+ this._carouselTimer = setInterval(() => {
783
+ const items = this._items();
784
+ if (!items.length) return;
785
+ const idx = (this._index() + 1) % items.length;
786
+ this.setAttribute("index", String(idx));
787
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: idx, direction: "next" } }));
788
+ }, Math.max(500, autoplay));
789
+ } else if (!want && this._carouselTimer) {
790
+ clearInterval(this._carouselTimer);
791
+ this._carouselTimer = null;
792
+ }
793
+ if (this._wiredCarousel) return;
794
+ this._wiredCarousel = true;
795
+ onDispose(this, () => { if (this._carouselTimer) { clearInterval(this._carouselTimer); this._carouselTimer = null; } });
796
+ const go = (dir) => {
797
+ const items = this._items();
798
+ if (!items.length) return;
799
+ let idx = this._index();
800
+ if (dir === "prev") idx = (idx - 1 + items.length) % items.length;
801
+ else idx = (idx + 1) % items.length;
802
+ this.setAttribute("index", String(idx));
803
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: idx, direction: dir } }));
804
+ };
805
+ this.addEventListener("click", (e) => {
806
+ const pp = e.target && e.target.closest ? e.target.closest(".c-carousel__pause") : null;
807
+ if (pp && this.contains(pp)) {
808
+ // Reduced motion keeps the carousel static; the control cannot
809
+ // start motion the reader asked not to see.
810
+ if (this._reducedMotion()) return;
811
+ const nowPaused = !this.hasAttribute("paused");
812
+ this.toggleAttribute("paused", nowPaused);
813
+ this.dispatchEvent(new CustomEvent(nowPaused ? "contour:pause" : "contour:play", { bubbles: true, composed: true }));
814
+ return;
815
+ }
816
+ const prev = e.target && e.target.closest ? e.target.closest(".c-carousel__prev") : null;
817
+ const next = e.target && e.target.closest ? e.target.closest(".c-carousel__next") : null;
818
+ if (prev && this.contains(prev)) { go("prev"); return; }
819
+ if (next && this.contains(next)) { go("next"); return; }
820
+ const dot = e.target && e.target.closest ? e.target.closest(".c-carousel__dot") : null;
821
+ if (dot && this.contains(dot)) {
822
+ const i = Number(dot.dataset.index);
823
+ if (Number.isFinite(i) && i !== this._index()) {
824
+ this.setAttribute("index", String(i));
825
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: i, direction: "jump" } }));
826
+ }
827
+ }
828
+ });
829
+ // Swipe: a horizontal drag past the threshold advances one slide.
830
+ let startX = null;
831
+ this.addEventListener("pointerdown", (e) => { startX = e.clientX; });
832
+ this.addEventListener("pointerup", (e) => {
833
+ if (startX === null) return;
834
+ const dx = e.clientX - startX;
835
+ startX = null;
836
+ if (Math.abs(dx) > 40) { if (dx < 0) go("next"); else go("prev"); }
837
+ });
838
+ this.addEventListener("pointercancel", () => { startX = null; });
839
+ this.addEventListener("keydown", (e) => {
840
+ if (e.key === "ArrowLeft") { e.preventDefault(); go("prev"); }
841
+ else if (e.key === "ArrowRight") { e.preventDefault(); go("next"); }
842
+ // index is observed: the attribute write re-renders through the base lifecycle, preserving focus.
843
+ else if (e.key === "Home") { e.preventDefault(); this.setAttribute("index", "0"); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: 0, direction: "home" } })); }
844
+ else if (e.key === "End") { e.preventDefault(); const last = this._items().length - 1; if (last >= 0) { this.setAttribute("index", String(last)); this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { index: last, direction: "end" } })); } }
845
+ });
846
+ }
847
+ }
848
+ define("contour-carousel", ContourCarousel);
849
+
850
+ /**
851
+ * Data Grid: web component wrapper.
852
+ * Attributes: `columns`, `rows`, `page`, `filter`, `page-size`, `resizable`, `selected`.
853
+ *
854
+ * R25-04 (grid half, mirrors ContourTable's contract): `selected` is a JSON
855
+ * array of row keys driving `aria-selected` from an external store; the
856
+ * `selected` property is the same door and wins while pushed. Keys, in order:
857
+ * an object row's `id` → its `key` field → the cell of a column declared
858
+ * `{key:true}` (read by that column's label as the property name) → the row
859
+ * datum's canonical JSON (content identity; duplicate rows share a key, so
860
+ * declare a key column when the data repeats). Every rendered row carries
861
+ * `data-row-key` and its DATUM index as `data-index` — not its DOM position,
862
+ * which the virtual spacers shift. Row click toggles the key in the selection
863
+ * and emits `contour:select {row, key, index}` (row/index are the datum index;
864
+ * the legacy positional-only detail was the R24-122 identity bug). The
865
+ * attribute is read only when it changes; the component never reflects it
866
+ * back. Without a `selected` write, clicks still emit identity-bearing detail.
867
+ */
868
+ class ContourDataGrid extends ContourBase {
869
+ static get updateMode() { return "keyed"; }
870
+ static get observed() { return ["columns", "rows", "page", "filter", "page-size", "resizable", "virtual", "row-height", "selected", "loading", "error", "empty"]; }
871
+ static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page" }, filter: { attribute: "filter" }, "page-size": { attribute: "page-size" }, resizable: { attribute: "resizable", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, "row-height": { attribute: "row-height" }, loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" } }; }
872
+ get selected() { return Array.from(this._dgSelectedKeys || []); }
873
+ set selected(value) {
874
+ this._dgPushedSelection = Array.isArray(value) ? value.map(String) : [];
875
+ this._dgSelectionControlled = true;
876
+ this.requestRender();
877
+ }
878
+ _dgRowKey(row) {
879
+ if (row && typeof row === "object" && !Array.isArray(row)) {
880
+ if (row.id !== undefined && row.id !== null) return String(row.id);
881
+ if (row.key !== undefined && row.key !== null) return String(row.key);
882
+ }
883
+ const cols = this._dgCols || [];
884
+ const ki = cols.findIndex((c) => c && typeof c === "object" && c.key === true);
885
+ if (ki >= 0 && row) {
886
+ const prop = typeof cols[ki].label === "string" ? cols[ki].label : "";
887
+ const v = prop && row[prop] != null ? String(row[prop]) : "";
888
+ if (v !== "") return v;
889
+ }
890
+ return JSON.stringify(row === undefined ? null : row);
891
+ }
892
+ _dgReadSelection() {
893
+ if (this._dgPushedSelection) { this._dgSelectedKeys = new Set(this._dgPushedSelection); return; }
894
+ const raw = this.getAttribute("selected");
895
+ if (raw !== null && raw !== this._dgLastSelectedRaw) {
896
+ this._dgLastSelectedRaw = raw;
897
+ this._dgSelectionControlled = true;
898
+ try {
899
+ const parsed = JSON.parse(raw);
900
+ this._dgSelectedKeys = new Set(Array.isArray(parsed) ? parsed.map(String) : []);
901
+ } catch (e) { this._dgSelectedKeys = new Set(); }
902
+ } else {
903
+ this._dgSelectedKeys = this._dgSelectedKeys || new Set();
904
+ }
905
+ }
906
+ _dgApplySelection(tbody) {
907
+ if (!tbody) return;
908
+ const keys = this._dgSelectedKeys || new Set();
909
+ tbody.querySelectorAll("tr[data-row-key]").forEach((tr) => {
910
+ tr.setAttribute("aria-selected", String(keys.has(tr.dataset.rowKey)));
911
+ });
912
+ }
913
+ render() {
914
+ this.classList.add("c-data-grid");
915
+ if (this.hasAttribute("loading") || this.hasAttribute("error") || this.hasAttribute("empty")) {
916
+ const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
917
+ const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
918
+ if (tbody.parentNode !== table) table.appendChild(tbody);
919
+ setHTML(tbody, "");
920
+ const tr = document.createElement("tr");
921
+ const td = document.createElement("td");
922
+ td.colSpan = 1;
923
+ td.style.textAlign = "center";
924
+ td.style.color = "var(--color-text-muted)";
925
+ if (this.hasAttribute("loading")) td.textContent = this.getAttribute("loading") || "Loading…";
926
+ else if (this.hasAttribute("error")) td.textContent = this.getAttribute("error") || "Error";
927
+ else td.textContent = this.getAttribute("empty") || "No data";
928
+ tr.appendChild(td);
929
+ tbody.appendChild(tr);
930
+ // Wrap in a scroll container for virtualization of large datasets.
931
+ let wrap = this.querySelector(".c-data-grid__wrap");
932
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-table-wrap c-data-grid__wrap"; }
933
+ if (table.parentNode !== wrap) wrap.appendChild(table);
934
+ if (wrap.parentNode !== this) this.appendChild(wrap);
935
+ return;
936
+ }
937
+ const table = this.ensure(".c-data-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-data-grid__table"; el.setAttribute("role", "grid"); return el; });
938
+ const thead = this.ensure("thead", () => { const el = document.createElement("thead"); return el; });
939
+ const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
940
+ if (thead.parentNode !== table) table.appendChild(thead);
941
+ if (tbody.parentNode !== table) table.appendChild(tbody);
942
+ const cols = this.getAttribute("columns");
943
+ let parsedCols = [];
944
+ try { parsedCols = cols ? JSON.parse(cols) : []; } catch (e) { parsedCols = []; }
945
+ if (parsedCols.length && !thead.querySelector("tr")) {
946
+ const tr = document.createElement("tr");
947
+ parsedCols.forEach((c) => {
948
+ const th = document.createElement("th");
949
+ th.setAttribute("role", "columnheader");
950
+ th.setAttribute("aria-sort", "none");
951
+ th.setAttribute("tabindex", "0");
952
+ th.textContent = typeof c === "string" ? c : (c.label || c.key || "");
953
+ tr.appendChild(th);
954
+ });
955
+ thead.appendChild(tr);
956
+ }
957
+ if (this.hasAttribute("resizable")) {
958
+ Array.from(thead.querySelectorAll("th")).forEach((th) => {
959
+ th.style.position = "relative";
960
+ th.setAttribute("data-resizable", "true");
961
+ });
962
+ }
963
+ const rows = this.getAttribute("rows");
964
+ let parsedRows = [];
965
+ try { parsedRows = rows ? JSON.parse(rows) : []; } catch (e) { parsedRows = []; }
966
+ table.setAttribute("aria-rowcount", String(parsedRows.length));
967
+ table.setAttribute("aria-colcount", String(parsedCols.length));
968
+ const filter = this.getAttribute("filter");
969
+ if (filter) {
970
+ const q = filter.toLowerCase();
971
+ parsedRows = parsedRows.filter((r) => JSON.stringify(r).toLowerCase().includes(q));
972
+ }
973
+ // Re-apply active sort across re-renders (page change, filter, etc.).
974
+ if (this._dgSortCol != null && this._dgSortCol >= 0 && this._dgSortCol < parsedCols.length) {
975
+ const si = this._dgSortCol;
976
+ const sdir = this._dgSortDir || "asc";
977
+ const sc = parsedCols[si];
978
+ const skey = sc ? (typeof sc === "string" ? sc : (sc.key || sc.label || "")) : String(si);
979
+ parsedRows = parsedRows.slice().sort((a, b) => {
980
+ const va = Array.isArray(a) ? (a[si] ?? "") : (a && a[skey] != null ? a[skey] : "");
981
+ const vb = Array.isArray(b) ? (b[si] ?? "") : (b && b[skey] != null ? b[skey] : "");
982
+ const na = Number(va), nb = Number(vb);
983
+ const cmp = (va !== "" && vb !== "" && !isNaN(na) && !isNaN(nb)) ? na - nb : String(va).localeCompare(String(vb));
984
+ return sdir === "asc" ? cmp : -cmp;
985
+ });
986
+ Array.from(thead.querySelectorAll("th")).forEach((h, i) => {
987
+ h.setAttribute("aria-sort", i === si ? (sdir === "asc" ? "ascending" : "descending") : "none");
988
+ });
989
+ }
990
+ this._dgFilteredRows = parsedRows;
991
+ const page = Number(this.getAttribute("page") || 1);
992
+ const pageSize = Number(this.getAttribute("page-size") || 0);
993
+ if (pageSize > 0) {
994
+ const start = (page - 1) * pageSize;
995
+ parsedRows = parsedRows.slice(start, start + pageSize);
996
+ }
997
+ this._dgCols = parsedCols;
998
+ this._dgRows = parsedRows;
999
+ this._dgReadSelection();
1000
+ const virtual = this.hasAttribute("virtual") && !(Number(this.getAttribute("page-size")) > 0);
1001
+ if (virtual) {
1002
+ const wrapEl = this.querySelector(".c-data-grid__wrap");
1003
+ this._renderDataGridWindow(wrapEl ? wrapEl.scrollTop : 0);
1004
+ } else {
1005
+ setHTML(tbody, "");
1006
+ const selStart = pageSize > 0 ? (page - 1) * pageSize : 0;
1007
+ parsedRows.forEach((r, di) => {
1008
+ const tr = document.createElement("tr");
1009
+ tr.dataset.rowKey = this._dgRowKey(r);
1010
+ tr.dataset.index = String(selStart + di);
1011
+ parsedCols.forEach((c, ci) => {
1012
+ const key = typeof c === "string" ? c : (c.key || c.label || "");
1013
+ const td = document.createElement("td");
1014
+ td.setAttribute("role", "gridcell");
1015
+ td.setAttribute("tabindex", "-1");
1016
+ const val = Array.isArray(r) ? r[ci] : (r ? r[key] : undefined);
1017
+ td.textContent = val != null ? val : "";
1018
+ if (!String(td.textContent).trim()) td.setAttribute("aria-label", labelText(this, "empty", "Empty"));
1019
+ tr.appendChild(td);
1020
+ });
1021
+ tbody.appendChild(tr);
1022
+ });
1023
+ this._dgApplySelection(tbody);
1024
+ }
1025
+ // Wrap in a scroll container for virtualization of large datasets.
1026
+ let wrap = this.querySelector(".c-data-grid__wrap");
1027
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-table-wrap c-data-grid__wrap"; }
1028
+ if (table.parentNode !== wrap) wrap.appendChild(table);
1029
+ if (wrap.parentNode !== this) this.appendChild(wrap);
1030
+ // One tab stop per grid: cells are -1 and the arrow keys move a roving
1031
+ // tabindex, so a 1,000-row grid is not 1,000 tab stops.
1032
+ if (!table.querySelector('[tabindex="0"]')) {
1033
+ const first = table.querySelector("tbody td, thead th");
1034
+ if (first) first.setAttribute("tabindex", "0");
1035
+ }
1036
+ }
1037
+ _rowHeight() {
1038
+ const h = Number(this.getAttribute("row-height"));
1039
+ if (Number.isFinite(h) && h > 0) return h;
1040
+ if (this._measuredRowHeight > 0) return this._measuredRowHeight;
1041
+ return cssLength("--data-grid-row-height", 32);
1042
+ }
1043
+ _renderDataGridWindow(scrollTop) {
1044
+ const table = this.querySelector(".c-data-grid__table");
1045
+ const tbody = table && table.querySelector("tbody");
1046
+ if (!tbody) return;
1047
+ const cols = this._dgCols || [];
1048
+ const rows = this._dgRows || [];
1049
+ const rh = this._rowHeight();
1050
+ const viewport = 400;
1051
+ const visibleCount = Math.ceil(viewport / rh) + 6;
1052
+ let start = Math.floor((scrollTop || 0) / rh);
1053
+ if (start < 0) start = 0;
1054
+ if (start > Math.max(0, rows.length - visibleCount)) start = Math.max(0, rows.length - visibleCount);
1055
+ const end = Math.min(rows.length, start + visibleCount);
1056
+ setHTML(tbody, "");
1057
+ // top spacer
1058
+ if (start > 0) {
1059
+ const sp = document.createElement("tr");
1060
+ const td = document.createElement("td");
1061
+ td.colSpan = Math.max(1, cols.length);
1062
+ td.style.blockSize = (start * rh) + "px";
1063
+ td.style.padding = "0";
1064
+ sp.appendChild(td);
1065
+ tbody.appendChild(sp);
1066
+ }
1067
+ for (let i = start; i < end; i++) {
1068
+ const r = rows[i];
1069
+ const tr = document.createElement("tr");
1070
+ tr.dataset.index = String(i);
1071
+ tr.dataset.rowKey = this._dgRowKey(r);
1072
+ cols.forEach((c, ci) => {
1073
+ const key = typeof c === "string" ? c : (c.key || c.label || "");
1074
+ const td = document.createElement("td");
1075
+ td.setAttribute("role", "gridcell");
1076
+ td.setAttribute("tabindex", "-1");
1077
+ const val = Array.isArray(r) ? r[ci] : (r ? r[key] : undefined);
1078
+ td.textContent = val != null ? val : "";
1079
+ if (!String(td.textContent).trim()) td.setAttribute("aria-label", labelText(this, "empty", "Empty"));
1080
+ tr.appendChild(td);
1081
+ });
1082
+ tbody.appendChild(tr);
1083
+ }
1084
+ if (end < rows.length) {
1085
+ const sp = document.createElement("tr");
1086
+ const td = document.createElement("td");
1087
+ td.colSpan = Math.max(1, cols.length);
1088
+ td.style.blockSize = ((rows.length - end) * rh) + "px";
1089
+ td.style.padding = "0";
1090
+ sp.appendChild(td);
1091
+ tbody.appendChild(sp);
1092
+ }
1093
+ // The window re-renders rows, so the single tab stop has to be re-seeded
1094
+ // here too, or a scroll would leave the grid with no tabbable cell.
1095
+ if (!tbody.querySelector('[tabindex="0"]')) {
1096
+ const first = tbody.querySelector("tr[data-index] td");
1097
+ if (first) first.setAttribute("tabindex", "0");
1098
+ }
1099
+ this._dgApplySelection(tbody);
1100
+ }
1101
+ enhance() {
1102
+ if (this._wiredDataGrid) return;
1103
+ this._wiredDataGrid = true;
1104
+ const wrap = () => this.querySelector(".c-data-grid__wrap");
1105
+ const onScroll = () => {
1106
+ const w = wrap();
1107
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
1108
+ };
1109
+ // attach after render creates wrap; use delegated listener on host
1110
+ this.addEventListener("scroll", (e) => {
1111
+ const w = e.target && e.target.classList && e.target.classList.contains("c-data-grid__wrap") ? e.target : null;
1112
+ if (w && this.hasAttribute("virtual")) this._renderDataGridWindow(w.scrollTop);
1113
+ }, true);
1114
+ this.addEventListener("keydown", (e) => {
1115
+ const cell = e.target && e.target.closest ? e.target.closest("[role='gridcell'], [role='columnheader']") : null;
1116
+ if (!cell || !this.contains(cell)) return;
1117
+ const row = cell.parentElement;
1118
+ const table = this.querySelector(".c-data-grid__table");
1119
+ if (!table) return;
1120
+ // Keyboard column resize (Alt+ArrowLeft/Right on resizable th).
1121
+ if (e.altKey && (e.key === "ArrowLeft" || e.key === "ArrowRight") && cell.hasAttribute("data-resizable")) {
1122
+ e.preventDefault();
1123
+ const ci = Array.from(row.children).indexOf(cell);
1124
+ const cur = cell.getBoundingClientRect().width || 100;
1125
+ const width = Math.max(48, cur + (e.key === "ArrowRight" ? 16 : -16));
1126
+ Array.from(table.rows).forEach((r) => { if (r.children[ci]) r.children[ci].style.inlineSize = width + "px"; });
1127
+ this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { column: ci, width } }));
1128
+ return;
1129
+ }
1130
+ // Keyboard sort on columnheader, keyboard select on gridcell.
1131
+ if (e.key === "Enter" || e.key === " ") {
1132
+ e.preventDefault();
1133
+ if (cell.getAttribute("role") === "columnheader") cell.click();
1134
+ else if (row) row.click();
1135
+ return;
1136
+ }
1137
+ const rows = Array.from(table.querySelectorAll("tr"));
1138
+ const ri = rows.indexOf(row);
1139
+ const ci = Array.from(row.children).indexOf(cell);
1140
+ let target = null;
1141
+ if (e.key === "ArrowRight") target = row.children[ci + 1];
1142
+ else if (e.key === "ArrowLeft") target = row.children[ci - 1];
1143
+ else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
1144
+ else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
1145
+ if (target) {
1146
+ e.preventDefault();
1147
+ // Move the single tab stop with the focus.
1148
+ table.querySelectorAll('[tabindex="0"]').forEach((c) => c.setAttribute("tabindex", "-1"));
1149
+ target.setAttribute("tabindex", "0");
1150
+ try { target.focus(); } catch (err) {}
1151
+ }
1152
+ });
1153
+ this.addEventListener("click", (e) => {
1154
+ const tr = e.target && e.target.closest ? e.target.closest("tr") : null;
1155
+ const th = e.target && e.target.closest ? e.target.closest("th") : null;
1156
+ if (tr && this.contains(tr) && !th && tr.dataset.rowKey !== undefined) {
1157
+ const key = tr.dataset.rowKey;
1158
+ const di = Number(tr.dataset.index);
1159
+ const keys = this._dgSelectedKeys || (this._dgSelectedKeys = new Set());
1160
+ if (keys.has(key)) keys.delete(key); else keys.add(key);
1161
+ this._dgApplySelection(tr.parentElement);
1162
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { row: di, key, index: di } }));
1163
+ }
1164
+ if (th && this.contains(th)) {
1165
+ const idx = Array.from(th.parentElement.children).indexOf(th);
1166
+ if (this._dgSortCol === idx) this._dgSortDir = this._dgSortDir === "asc" ? "desc" : "asc";
1167
+ else { this._dgSortCol = idx; this._dgSortDir = "asc"; }
1168
+ const dir = this._dgSortDir;
1169
+ const table = this.querySelector(".c-data-grid__table");
1170
+ const tbody = table && table.querySelector("tbody");
1171
+ const thead = table && table.querySelector("thead");
1172
+ const cols = this._dgCols || [];
1173
+ const key = cols[idx] ? (typeof cols[idx] === "string" ? cols[idx] : (cols[idx].key || cols[idx].label || "")) : String(idx);
1174
+ const full = (this._dgFilteredRows || []).slice();
1175
+ full.sort((a, b) => {
1176
+ const va = Array.isArray(a) ? (a[idx] ?? "") : (a && a[key] != null ? a[key] : "");
1177
+ const vb = Array.isArray(b) ? (b[idx] ?? "") : (b && b[key] != null ? b[key] : "");
1178
+ const na = Number(va), nb = Number(vb);
1179
+ const cmp = (va !== "" && vb !== "" && !isNaN(na) && !isNaN(nb)) ? na - nb : String(va).localeCompare(String(vb));
1180
+ return dir === "asc" ? cmp : -cmp;
1181
+ });
1182
+ this._dgFilteredRows = full;
1183
+ if (this.hasAttribute("virtual") && !(Number(this.getAttribute("page-size")) > 0)) {
1184
+ this._dgRows = full;
1185
+ const w = wrap();
1186
+ this._renderDataGridWindow(w ? w.scrollTop : 0);
1187
+ } else if (tbody) {
1188
+ const page = Number(this.getAttribute("page") || 1);
1189
+ const pageSize = Number(this.getAttribute("page-size") || 0);
1190
+ let pageRows = full;
1191
+ if (pageSize > 0) { const start = (page - 1) * pageSize; pageRows = full.slice(start, start + pageSize); }
1192
+ setHTML(tbody, "");
1193
+ const selStart = pageSize > 0 ? (page - 1) * pageSize : 0;
1194
+ pageRows.forEach((r, li) => {
1195
+ const tr = document.createElement("tr");
1196
+ tr.dataset.rowKey = this._dgRowKey(r);
1197
+ tr.dataset.index = String(selStart + li);
1198
+ cols.forEach((c, ci) => {
1199
+ const k = typeof c === "string" ? c : (c.key || c.label || "");
1200
+ const td = document.createElement("td");
1201
+ td.setAttribute("role", "gridcell");
1202
+ td.setAttribute("tabindex", "-1");
1203
+ const val = Array.isArray(r) ? r[ci] : (r ? r[k] : undefined);
1204
+ td.textContent = val != null ? val : "";
1205
+ tr.appendChild(td);
1206
+ });
1207
+ tbody.appendChild(tr);
1208
+ });
1209
+ this._dgApplySelection(tbody);
1210
+ }
1211
+ // Update aria-sort on headers.
1212
+ if (thead) Array.from(thead.querySelectorAll("th")).forEach((h, i) => {
1213
+ h.setAttribute("aria-sort", i === idx ? (dir === "asc" ? "ascending" : "descending") : "none");
1214
+ });
1215
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: dir } }));
1216
+ }
1217
+ });
1218
+ this.addEventListener("pointerdown", (e) => {
1219
+ if (!this.hasAttribute("resizable")) return;
1220
+ const th = e.target && e.target.closest ? e.target.closest("th[data-resizable]") : null;
1221
+ if (!th || !this.contains(th) || th.getBoundingClientRect().right - e.clientX > 10) return;
1222
+ e.preventDefault();
1223
+ const startX = e.clientX;
1224
+ const startWidth = th.getBoundingClientRect().width;
1225
+ const index = Array.from(th.parentElement.children).indexOf(th);
1226
+ let lastWidth = startWidth;
1227
+ const move = (event) => {
1228
+ lastWidth = Math.max(48, startWidth + event.clientX - startX);
1229
+ const table = this.querySelector(".c-data-grid__table");
1230
+ if (table) Array.from(table.rows).forEach((row) => { if (row.children[index]) row.children[index].style.inlineSize = lastWidth + "px"; });
1231
+ };
1232
+ const stop = () => {
1233
+ window.removeEventListener("pointermove", move);
1234
+ this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { column: index, width: lastWidth } }));
1235
+ };
1236
+ window.addEventListener("pointermove", move);
1237
+ window.addEventListener("pointerup", stop, { once: true });
1238
+ onDispose(this, stop);
1239
+ });
1240
+ // The base class's keyed restore runs before enhance; re-assert the
1241
+ // store-driven selection so a restore cannot clobber it (R25-04).
1242
+ this._dgApplySelection(this.querySelector(".c-data-grid__table tbody"));
1243
+ }
1244
+ }
1245
+ define("contour-data-grid", ContourDataGrid);
1246
+
1247
+ /**
1248
+ * Tree Grid: web component wrapper.
1249
+ * Attributes: `items`, `expanded`.
1250
+ */
1251
+ class ContourTreeGrid extends ContourBase {
1252
+ static get updateMode() { return "keyed"; }
1253
+ static get observed() { return ["items", "rows", "expanded", "loading", "error", "empty"]; }
1254
+ static get properties() { return { items: { attribute: "items" }, rows: { attribute: "rows" }, expanded: { attribute: "expanded" }, loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" } }; }
1255
+ _expandedSet() {
1256
+ const raw = this.getAttribute("expanded");
1257
+ if (!raw) return new Set();
1258
+ try { return new Set(JSON.parse(raw)); } catch (e) { return new Set([raw]); }
1259
+ }
1260
+ render() {
1261
+ this.classList.add("c-tree-grid");
1262
+ const table = this.ensure(".c-tree-grid__table", () => { const el = document.createElement("table"); el.className = "c-table c-tree-grid__table"; el.setAttribute("role", "treegrid"); return el; });
1263
+ table.setAttribute("aria-label", labelText(this, "tree-grid", "Tree grid"));
1264
+ const tbody = this.ensure("tbody", () => { const el = document.createElement("tbody"); return el; });
1265
+ if (tbody.parentNode !== table) table.appendChild(tbody);
1266
+ setHTML(tbody, "");
1267
+ if (this.hasAttribute("loading") || this.hasAttribute("error") || this.hasAttribute("empty")) {
1268
+ const tr = document.createElement("tr");
1269
+ const td = document.createElement("td");
1270
+ td.style.textAlign = "center";
1271
+ td.style.color = "var(--color-text-muted)";
1272
+ if (this.hasAttribute("loading")) td.textContent = this.getAttribute("loading") || "Loading…";
1273
+ else if (this.hasAttribute("error")) td.textContent = this.getAttribute("error") || "Error";
1274
+ else td.textContent = this.getAttribute("empty") || "No data";
1275
+ tr.appendChild(td);
1276
+ tbody.appendChild(tr);
1277
+ } else {
1278
+ const items = this.getAttribute("items") || this.getAttribute("rows");
1279
+ let parsed = [];
1280
+ try { parsed = items ? JSON.parse(items) : []; } catch (e) { parsed = []; }
1281
+ if (!Array.isArray(parsed)) parsed = [];
1282
+ const expanded = this._expandedSet();
1283
+ const rows = [];
1284
+ const renderNode = (node, depth, path, posInSet, setSize) => {
1285
+ const tr = document.createElement("tr");
1286
+ tr.setAttribute("role", "row");
1287
+ tr.setAttribute("tabindex", rows.length === 0 ? "0" : "-1");
1288
+ tr.setAttribute("aria-level", String(depth + 1));
1289
+ tr.setAttribute("aria-posinset", String(posInSet));
1290
+ tr.setAttribute("aria-setsize", String(setSize));
1291
+ tr.dataset.path = path;
1292
+ if (this._tgSelectedPath === path) tr.setAttribute("aria-selected", "true");
1293
+ const hasChildren = !!(node && Array.isArray(node.children) && node.children.length);
1294
+ if (hasChildren) {
1295
+ tr.setAttribute("aria-expanded", expanded.has(path) ? "true" : "false");
1296
+ }
1297
+ const td = document.createElement("td");
1298
+ td.setAttribute("role", "gridcell");
1299
+ td.style.setProperty("--tree-depth", String(depth));
1300
+ const label = (node && (node.label || node.text || node.name)) || "";
1301
+ if (hasChildren) {
1302
+ const toggle = document.createElement("button");
1303
+ toggle.type = "button";
1304
+ toggle.className = "c-tree-grid__toggle";
1305
+ toggle.tabIndex = -1;
1306
+ toggle.textContent = expanded.has(path) ? "▾" : "▸";
1307
+ toggle.setAttribute("aria-label", (expanded.has(path) ? "Collapse" : "Expand") + " " + label);
1308
+ td.appendChild(toggle);
1309
+ }
1310
+ const span = document.createElement("span");
1311
+ span.className = "c-tree-grid__label";
1312
+ span.textContent = label;
1313
+ td.appendChild(span);
1314
+ tr.appendChild(td);
1315
+ tbody.appendChild(tr);
1316
+ rows.push(tr);
1317
+ if (hasChildren && expanded.has(path)) {
1318
+ node.children.forEach((c, i) => renderNode(c, depth + 1, path + "." + i, i + 1, node.children.length));
1319
+ }
1320
+ };
1321
+ parsed.forEach((n, i) => renderNode(n, 0, String(i), i + 1, parsed.length));
1322
+ }
1323
+ // Wrap the table in the same scroller the reflow gate requires, so a
1324
+ // tree grid is not a bare .c-table that stretches the page.
1325
+ let wrap = this.querySelector(".c-tree-grid__wrap");
1326
+ if (!wrap) { wrap = document.createElement("div"); wrap.className = "c-table-wrap c-tree-grid__wrap"; }
1327
+ if (table.parentNode !== wrap) wrap.appendChild(table);
1328
+ if (wrap.parentNode !== this) this.appendChild(wrap);
1329
+ }
1330
+ enhance() {
1331
+ if (this._wiredTreeGrid) return;
1332
+ this._wiredTreeGrid = true;
1333
+ const rows = () => Array.from(this.querySelectorAll("tr[role='row']"));
1334
+ const focusRow = (target) => {
1335
+ if (!target) return;
1336
+ rows().forEach((r) => r.setAttribute("tabindex", r === target ? "0" : "-1"));
1337
+ try { target.focus(); } catch (err) {}
1338
+ };
1339
+ this.addEventListener("click", (e) => {
1340
+ const toggle = e.target && e.target.closest ? e.target.closest(".c-tree-grid__toggle") : null;
1341
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
1342
+ if (!tr || !this.contains(tr)) return;
1343
+ const path = tr.dataset.path;
1344
+ focusRow(tr);
1345
+ if (toggle) {
1346
+ e.preventDefault();
1347
+ const expanded = this._expandedSet();
1348
+ if (expanded.has(path)) expanded.delete(path); else expanded.add(path);
1349
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
1350
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: expanded.has(path) } }));
1351
+ } else {
1352
+ this._tgSelectedPath = path;
1353
+ rows().forEach((r) => r.setAttribute("aria-selected", String(r === tr)));
1354
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path } }));
1355
+ }
1356
+ });
1357
+ this.addEventListener("keydown", (e) => {
1358
+ const tr = e.target && e.target.closest ? e.target.closest("tr[role='row']") : null;
1359
+ if (!tr || !this.contains(tr)) return;
1360
+ const all = rows();
1361
+ const idx = all.indexOf(tr);
1362
+ const path = tr.dataset.path || "";
1363
+ const hasChildren = tr.getAttribute("aria-expanded") !== null;
1364
+ const expanded = this._expandedSet();
1365
+ if (e.key === "ArrowRight") {
1366
+ e.preventDefault();
1367
+ if (hasChildren && !expanded.has(path)) {
1368
+ expanded.add(path);
1369
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
1370
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: true } }));
1371
+ } else if (hasChildren && expanded.has(path) && all[idx + 1]) {
1372
+ focusRow(all[idx + 1]);
1373
+ }
1374
+ } else if (e.key === "ArrowLeft") {
1375
+ e.preventDefault();
1376
+ if (hasChildren && expanded.has(path)) {
1377
+ expanded.delete(path);
1378
+ this.setAttribute("expanded", JSON.stringify([...expanded]));
1379
+ this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { path, expanded: false } }));
1380
+ } else if (path.includes(".")) {
1381
+ const parentPath = path.slice(0, path.lastIndexOf("."));
1382
+ const parent = all.find((r) => r.dataset.path === parentPath);
1383
+ if (parent) focusRow(parent);
1384
+ }
1385
+ } else if (e.key === "ArrowDown") {
1386
+ e.preventDefault();
1387
+ if (all[idx + 1]) focusRow(all[idx + 1]);
1388
+ } else if (e.key === "ArrowUp") {
1389
+ e.preventDefault();
1390
+ if (all[idx - 1]) focusRow(all[idx - 1]);
1391
+ } else if (e.key === "Enter" || e.key === " ") {
1392
+ e.preventDefault();
1393
+ const toggle = tr.querySelector(".c-tree-grid__toggle");
1394
+ if (e.key === "Enter" && toggle) toggle.click();
1395
+ else {
1396
+ this._tgSelectedPath = path;
1397
+ all.forEach((r) => r.setAttribute("aria-selected", String(r === tr)));
1398
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path } }));
1399
+ }
1400
+ }
1401
+ });
1402
+ }
1403
+ }
1404
+ define("contour-tree-grid", ContourTreeGrid);