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,845 @@
1
+ import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERVED, REGISTERED, applyLabel, bearing, clampLat, contourId, cssLength, define, flagOn, flagOnValue, formatValue, haversine, headingTag, iconMarkup, isRtl, labelText, levelFromAttributes, mercatorResolution, navKey, normaliseLng, onDispose, safeColor, safeHref, sanitizeHtml, setHTML, simple, statusIcon, supportsUntilFound, unwrapBounds, warnBadJson, wcEmitOverlay, withBrownout, MARKER_SHAPES, arcPath, assignMarkers, barRects, compassNeedle, contourPaths, donutSlices, isMissing, marchingSquares, markerStyles, niceTicks, polylinePoints, scaleBarTicks, smoothPath, modalContain, wcReset, wireCombobox, wireCopy, wireMenu, wirePagination, wireRemovable, wireSegmented, wireTabs, wireTree, STATE_FALLBACK, loadRemote, parseArrayAttr, remoteData, remoteInvalidate, remoteRefresh, remoteVisible, renderEmpty, renderStates, stateLabel, watchViewport, wireStates } from "./contour-wc-core.esm.js";
2
+
3
+ // ---- Registration: class-only wrappers run last (define() skips claimed names) ----
4
+ define("contour-box", simple(["c-box"]));
5
+ define("contour-cluster", simple(["c-cluster"]));
6
+ define("contour-container", simple(["c-container"]));
7
+ define("contour-row", simple(["c-row"]));
8
+ define("contour-scrim", simple(["c-scrim"]));
9
+ define("contour-stack", simple(["c-stack"]));
10
+
11
+
12
+
13
+
14
+ // R31-19: the text a shadow <label> shows through its <slot>, read from the
15
+ // light-tree assigned nodes (the shadow label's own textContent is empty).
16
+ const assignedText = (label) => {
17
+ const slot = label.querySelector("slot");
18
+ const nodes = slot ? slot.assignedElements({ flatten: true }) : [];
19
+ const text = nodes.map((n) => (n.textContent || "").trim()).join(" ").trim();
20
+ return text || (label.textContent || "").trim();
21
+ };
22
+ // ---- Shadow DOM wrappers (opt-in) ------------------------------------
23
+ let ADOPTED = null;
24
+ let ADOPTED_KEY = "";
25
+ const _hashCss = (str) => {
26
+ let h = 2166136261;
27
+ for (let i = 0; i < str.length; i++) {
28
+ h ^= str.charCodeAt(i);
29
+ h = Math.imul(h, 16777619);
30
+ }
31
+ return (h >>> 0).toString(36);
32
+ };
33
+ export const adoptedSheets = () => {
34
+ let key = document.styleSheets.length + ":";
35
+ for (const sheet of document.styleSheets) {
36
+ let sig = "-1";
37
+ try {
38
+ const rules = sheet.cssRules;
39
+ let text = "";
40
+ for (let i = 0; i < rules.length; i++) text += rules[i].cssText + "\n";
41
+ sig = rules.length + ":" + _hashCss(text);
42
+ } catch (e) { /* cross-origin: unreadable */ }
43
+ key += (sheet.href || "inline") + "~" + sig + "|";
44
+ }
45
+ if (ADOPTED && key === ADOPTED_KEY) return ADOPTED;
46
+ ADOPTED_KEY = key;
47
+ ADOPTED = [];
48
+ // Collect every rule a sheet carries, descending into @imported sheets,
49
+ const collect = (sheet, out) => {
50
+ let rules;
51
+ try { rules = sheet.cssRules; } catch (e) { return; }
52
+ if (!rules) return;
53
+ for (const r of rules) {
54
+ if (r instanceof CSSImportRule) {
55
+ if (r.styleSheet) collect(r.styleSheet, out);
56
+ } else {
57
+ try { out.push(r.cssText); } catch (e) { /* unreadable */ }
58
+ }
59
+ }
60
+ };
61
+ for (const sheet of document.styleSheets) {
62
+ try {
63
+ // Include same-origin linked sheets AND same-origin inline <style> sheets (!sheet.href).
64
+ if (!sheet.href || new URL(sheet.href).origin === location.origin) {
65
+ const collected = [];
66
+ collect(sheet, collected);
67
+ const built = new CSSStyleSheet();
68
+ if (collected.length) built.replaceSync(collected.join("\n"));
69
+ ADOPTED.push(built);
70
+ }
71
+ } catch (e) { /* cross-origin or unreadable */ }
72
+ }
73
+ return ADOPTED;
74
+ };
75
+
76
+ // One base for every wrapper: adopt the sheets, clone the subclass template,
77
+ const _ShadowParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
78
+ class ContourShadow extends _ShadowParent {
79
+ // R30-33: observe `labels` alongside the modifier attributes so a labels
80
+ // change re-runs _applyLabels(). applyMods() ignores it (it only maps MODS),
81
+ // so adding it here does not create a bogus modifier class.
82
+ static get observedAttributes() { return MODS.concat("labels"); }
83
+ constructor() {
84
+ super();
85
+ // Reuse a Declarative Shadow Root when the platform already attached one
86
+ // (SSR/DSD hydration); otherwise create and populate the shadow root.
87
+ let root = this.shadowRoot;
88
+ if (!root) {
89
+ root = this.attachShadow({ mode: "open" });
90
+ if (this.constructor.contourTemplate) {
91
+ root.appendChild(this.constructor.contourTemplate.content.cloneNode(true));
92
+ }
93
+ }
94
+ const sheets = adoptedSheets();
95
+ if (sheets.length) {
96
+ try { root.adoptedStyleSheets = sheets; } catch (e) { /* unsupported or read-only */ }
97
+ }
98
+ this._shadowBase = root.firstElementChild ? root.firstElementChild.className : "";
99
+ }
100
+ // Subclasses with behaviour beyond the template override this.
101
+ enhance(root) {
102
+ if (!root) root = this.shadowRoot;
103
+ if (!root) return;
104
+ // ARIA setup is idempotent (guards on hasAttribute), so it re-runs on
105
+ root.querySelectorAll("details").forEach((d) => {
106
+ const summary = d.querySelector("summary");
107
+ if (summary && !summary.hasAttribute("aria-expanded")) {
108
+ summary.setAttribute("aria-expanded", String(d.open));
109
+ d.addEventListener("toggle", () => {
110
+ summary.setAttribute("aria-expanded", String(d.open));
111
+ });
112
+ }
113
+ });
114
+ // ARIA: ensure live regions have proper roles
115
+ root.querySelectorAll("[data-live]").forEach((el) => {
116
+ if (!el.hasAttribute("role")) el.setAttribute("role", "status");
117
+ if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
118
+ });
119
+ // ARIA: spinners and toasts get live region roles (opt-in: an author-set role wins)
120
+ root.querySelectorAll(".c-spinner").forEach((el) => {
121
+ if (!el.hasAttribute("role")) el.setAttribute("role", "status");
122
+ if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
123
+ });
124
+ // ARIA: toast elements get live region roles
125
+ root.querySelectorAll(".c-toast, .c-toast-host").forEach((el) => {
126
+ if (!el.hasAttribute("role")) el.setAttribute("role", "status");
127
+ if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
128
+ if (!el.hasAttribute("aria-atomic")) el.setAttribute("aria-atomic", "true");
129
+ });
130
+ // ARIA: link tabs to panels via aria-controls
131
+ root.querySelectorAll("[role='tab']").forEach((tab) => {
132
+ const ctrl = tab.getAttribute("aria-controls");
133
+ if (ctrl) {
134
+ const panel = root.querySelector("#" + CSS.escape(ctrl)) || document.getElementById(ctrl);
135
+ if (panel && !panel.hasAttribute("aria-labelledby")) {
136
+ if (!tab.id) tab.id = contourId("tab");
137
+ panel.setAttribute("aria-labelledby", tab.id);
138
+ }
139
+ }
140
+ });
141
+ // ARIA: link inputs to their labels/hints via aria-describedby
142
+ root.querySelectorAll("input, textarea, select").forEach((input) => {
143
+ if (input.hasAttribute("aria-describedby")) return;
144
+ const field = input.closest(".c-field");
145
+ if (field) {
146
+ const hint = field.querySelector(".c-field__hint");
147
+ if (hint) {
148
+ if (!hint.id) hint.id = contourId("hint");
149
+ input.setAttribute("aria-describedby", hint.id);
150
+ }
151
+ const err = field.querySelector(".c-field__error");
152
+ if (err) {
153
+ if (!err.id) err.id = contourId("err");
154
+ const existing = input.getAttribute("aria-describedby") || "";
155
+ input.setAttribute("aria-describedby", (existing + " " + err.id).trim());
156
+ }
157
+ }
158
+ });
159
+ // ARIA: alert elements are live regions, and the variant sets the volume.
160
+ root.querySelectorAll(".c-alert").forEach((el) => {
161
+ const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
162
+ const role = urgent ? "alert" : "status";
163
+ const live = urgent ? "assertive" : "polite";
164
+ if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
165
+ el.setAttribute("role", role);
166
+ el.dataset.contourAutoRole = role;
167
+ }
168
+ if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
169
+ el.setAttribute("aria-live", live);
170
+ el.dataset.contourAutoLive = live;
171
+ }
172
+ });
173
+ // ARIA: required form fields
174
+ root.querySelectorAll("input[required], textarea[required], select[required]").forEach((el) => {
175
+ if (!el.hasAttribute("aria-required")) el.setAttribute("aria-required", "true");
176
+ });
177
+ // Interaction is delegated to the implementation the light-DOM wrappers
178
+ this._wireLabels(root);
179
+ this._wireClose(root);
180
+ }
181
+ // R31-22: the shadow callout/alert/tag/filter-pill close/remove buttons were
182
+ // inert — a control the reader could focus and never use. Wire them to
183
+ // dismiss the host (hide + emit contour:close/dismiss), once per host.
184
+ _wireClose(root) {
185
+ if (!root || this._wiredShadowClose) return;
186
+ const btns = root.querySelectorAll(".c-callout__close, .c-alert__close, .c-tag__remove, .c-filter-pill__remove");
187
+ if (!btns.length) return;
188
+ this._wiredShadowClose = true;
189
+ for (const b of btns) {
190
+ b.addEventListener("click", () => {
191
+ this.hidden = true;
192
+ this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
193
+ });
194
+ }
195
+ }
196
+ // R31-03: a shadow <label> wrapping a <slot> does not label a slotted input.
197
+ // The input is in the light tree, the label in the shadow tree, and HTML's
198
+ // label/for association does not cross the boundary. Give the slotted
199
+ // control an id and point the shadow label's `for` at it, and mirror the
200
+ // field hint/error into aria-describedby. Idempotent.
201
+ _wireLabels(root) {
202
+ if (!root) return;
203
+ root.querySelectorAll("label").forEach((label) => {
204
+ const slot = label.querySelector("slot");
205
+ const field = label.closest(".c-field") || label.parentElement;
206
+ const host = this;
207
+ const controls = [];
208
+ if (slot) {
209
+ for (const n of slot.assignedElements({ flatten: true })) {
210
+ if (n.matches("input, textarea, select")) controls.push(n);
211
+ }
212
+ }
213
+ // A field's input lives in a named "input" slot, not inside the label.
214
+ if (!controls.length && field) {
215
+ const inputSlot = field.querySelector('slot[name="input"]');
216
+ if (inputSlot) {
217
+ for (const n of inputSlot.assignedElements({ flatten: true })) {
218
+ if (n.matches("input, textarea, select")) controls.push(n);
219
+ }
220
+ }
221
+ }
222
+ for (const input of controls) {
223
+ if (!input.id) input.id = contourId("shadow-input");
224
+ if (!label.hasAttribute("for")) label.setAttribute("for", input.id);
225
+ // R31-19: `for` does not cross the shadow boundary — the label is in
226
+ // the shadow tree, the input in the light tree, so `label.control`
227
+ // is null and `input.labels` is empty. Give the input an explicit
228
+ // accessible name from the label's slotted text, and forward a label
229
+ // click to the control, so the visible label actually toggles it.
230
+ if (!input.hasAttribute("aria-label") && !input.hasAttribute("aria-labelledby")) {
231
+ const text = assignedText(label);
232
+ if (text) input.setAttribute("aria-label", text);
233
+ }
234
+ if (!input._contourLabelWired) {
235
+ input._contourLabelWired = true;
236
+ label.addEventListener("click", (e) => {
237
+ if (e.target.closest("a, button, input, textarea, select")) return;
238
+ try { input.click(); } catch (err) { /* control without click */ }
239
+ });
240
+ }
241
+ // Mirror the field hint/error into aria-describedby (once).
242
+ if (field && !input.hasAttribute("aria-describedby")) {
243
+ const hint = field.querySelector(".c-field__hint");
244
+ const err = field.querySelector(".c-field__error");
245
+ const ids = [];
246
+ if (hint) { if (!hint.id) hint.id = contourId("hint"); ids.push(hint.id); }
247
+ if (err) { if (!err.id) err.id = contourId("err"); ids.push(err.id); }
248
+ if (ids.length) input.setAttribute("aria-describedby", ids.join(" "));
249
+ }
250
+ }
251
+ });
252
+ }
253
+ connectedCallback() {
254
+ this.applyMods();
255
+ try { this.enhance(this.shadowRoot); } catch (e) { /* ignore */ }
256
+ this._applyLabels();
257
+ // Wire behaviours now that slotted content is present.
258
+ try {
259
+ wcReset(this);
260
+ wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
261
+ wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
262
+ } catch (e) { /* ignore */ }
263
+ // Re-wire behaviour when slotted content changes. Reset the wired set so
264
+ if (this.shadowRoot && !this._wiredSlotchange) {
265
+ this._wiredSlotchange = true;
266
+ this.shadowRoot.addEventListener("slotchange", () => {
267
+ try { this.enhance(this.shadowRoot);
268
+ this._applyLabels();
269
+ wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
270
+ wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
271
+ } catch (e) { /* ignore */ }
272
+ });
273
+ }
274
+ }
275
+ attributeChangedCallback() { this.applyMods(); this._applyLabels(); }
276
+ // R30-33: localise the static aria-labels/copy baked into shadow templates.
277
+ // The light-DOM sweep (R30-13) routes literals through labelText(); the
278
+ // shadow layer has no such path because its markup is a static template
279
+ // string. This post-processes the rendered shadowRoot, replacing the
280
+ // English defaults with the host's `labels` overrides where present. It is
281
+ // idempotent and only touches nodes that still carry the default text, so
282
+ // an author's own shadow content (slotted) is never overwritten.
283
+ _applyLabels() {
284
+ const root = this.shadowRoot;
285
+ if (!root) return;
286
+ const set = (selector, key, fallback) => {
287
+ const node = root.querySelector(selector);
288
+ if (node) node.setAttribute("aria-label", labelText(this, key, fallback));
289
+ };
290
+ set(".c-callout__close", "close", "Close");
291
+ set(".c-alert__close", "close", "Close");
292
+ set(".c-tag__remove", "remove", "Remove");
293
+ set(".c-filter-pill__remove", "remove-filter", "Remove filter");
294
+ set(".c-breadcrumb", "breadcrumb", "Breadcrumb");
295
+ set(".c-spinner", "loading", "Loading");
296
+ set(".c-install__copy", "copy-command", "Copy command");
297
+ // The install/code copy buttons carry visible "Copy" text as well as an
298
+ // aria-label; localise both, but only while they still read "Copy" so a
299
+ // consumer who set their own label keeps it.
300
+ const copyBtn = root.querySelector(".c-install__copy, .c-code__copy");
301
+ if (copyBtn && copyBtn.textContent.trim() === "Copy") {
302
+ copyBtn.textContent = labelText(this, "copy", "Copy");
303
+ }
304
+ }
305
+ applyMods() {
306
+ const el = this.shadowRoot.firstElementChild;
307
+ if (!el || !this._shadowBase) return;
308
+ const mods = [];
309
+ for (const attr of MODS) {
310
+ const val = this.getAttribute(attr);
311
+ if (!val) continue;
312
+ for (const cls of this._shadowBase.split(/\s+/)) {
313
+ if (cls) mods.push("c-" + cls.replace(/^c-/, "") + "--" + val);
314
+ }
315
+ }
316
+ el.className = (this._shadowBase + " " + mods.join(" ")).trim();
317
+ // An alert's live region follows its variant, and rewriting the class above
318
+ if (el.classList.contains("c-alert")) {
319
+ const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
320
+ const role = urgent ? "alert" : "status";
321
+ const live = urgent ? "assertive" : "polite";
322
+ if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
323
+ el.setAttribute("role", role);
324
+ el.dataset.contourAutoRole = role;
325
+ }
326
+ if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
327
+ el.setAttribute("aria-live", live);
328
+ el.dataset.contourAutoLive = live;
329
+ }
330
+ }
331
+ }
332
+ }
333
+
334
+ // Registers a wrapper. The template markup is always recorded so Node/SSR
335
+ const SHADOW_PARTS_PUBLIC = {};
336
+ const SHADOW_MARKUP = {};
337
+ const recordParts = (name, markup) => {
338
+ SHADOW_PARTS_PUBLIC[name] = [...markup.matchAll(/part="([^"]+)"/g)]
339
+ .flatMap((m) => m[1].split(/\s+/))
340
+ .filter(Boolean);
341
+ };
342
+ const shadow = (name, markup) => {
343
+ SHADOW_MARKUP[name] = markup;
344
+ recordParts(name, markup);
345
+ if (typeof document === "undefined") return;
346
+ const tpl = document.createElement("template");
347
+ setHTML(tpl, markup);
348
+ const cls = class extends ContourShadow {};
349
+ cls.contourTemplate = tpl;
350
+ define(name, cls);
351
+ };
352
+
353
+ // A wrapper that is one default slot needs no markup of its own: the element,
354
+ const slotWrapper = (tag, block, part) =>
355
+ "<" + tag + ' class="c-' + block + '" part="' + (part || block) + '"' + (tag === "button" ? ' type="button"' : "") + "><slot></slot></" + tag + ">";
356
+ const SHADOW_SLOTS = {
357
+ div: [
358
+ "accordion", "activity", "advanced", "affordance", "affordances", "anchor", "app", "app-body", "box", "btn-group", "chart-grid",
359
+ "catchment", "cluster", "command", "compare", "comparison", "compass",
360
+ "contour-plot", "cta", "dash-freshness", "dash-kpi-row", "dash-shell", "dash-toolbar", "datamark", "delta", "draggable", "drag-handle", "drop-indicator", "drop-zone",
361
+ "destructive-hint", "docs-shell", "drawer", "elevation",
362
+ "filter-bar", "flow-map", "heatmap", "hexbin", "icon-badge", "input-group", "instrument", "range-scale", "resizable", "table-wrap", "time-range", "toast-host", "scroll-area",
363
+ "isochrone", "landing-features", "landing-hero", "layer-panel", "layer-switch", "legend", "logos", "map-area",
364
+ "map-footer", "map-panel", "map-slot", "measure", "metrics", "minimap", "pager", "pagination",
365
+ "panel", "plate", "price", "pricing", "progress", "prose", "pullquote", "radio-list",
366
+ "range", "readout", "recipe", "reserved", "resize-handle", "row",
367
+ "row-action", "scale-bar", "scrim", "segmented", "sheet", "shortcut-list", "shortcut-overlay", "shortcut-panel",
368
+ "shortcut-row", "showcase", "sidebar", "skeleton", "sparkline", "stack", "steps", "streaming-chart",
369
+ "survey", "theme-scope", "time-slider", "timeline", "toast",
370
+ "toolbar", "tooltip", "tree", "version", "version-banner"
371
+ ],
372
+ button: [
373
+ "btn", "pressable"
374
+ ],
375
+ span: [
376
+ "avatar", "badge", "chip", "dot", "flag", "live-badge", "mark", "pill"
377
+ ],
378
+ a: [
379
+ "link", "linkish"
380
+ ],
381
+ kbd: [
382
+ "kbd"
383
+ ],
384
+ label: [
385
+ "check", "radio", "switch"
386
+ ],
387
+ nav: [
388
+ "docs-nav"
389
+ ],
390
+ };
391
+
392
+ // Two wrappers name their part after the region it holds rather than after
393
+ const SHADOW_PARTS = {
394
+ "version-banner": "banner",
395
+ "contour-plot": "plot",
396
+ };
397
+
398
+ // The slot wrappers are recorded wherever this module runs. `shadow()` already
399
+ for (const [tag, blocks] of Object.entries(SHADOW_SLOTS)) {
400
+ for (const block of blocks) {
401
+ const part = SHADOW_PARTS[block] || block;
402
+ shadow("contour-shadow-" + block, slotWrapper(tag, block, part));
403
+ }
404
+ }
405
+
406
+ // Structured templates: more than one slot, or a class that is not the block's
407
+ // own, so the markup is the definition and is written out.
408
+ shadow("contour-shadow-callout", `<div class="c-callout" part="callout"><div class="c-callout__title" part="title"><slot name="title"></slot></div><div class="c-callout__body" part="body"><slot></slot></div><button class="c-callout__close" part="close" type="button" aria-label="Close">×</button></div>`);
409
+ shadow("contour-shadow-empty", `<div class="c-empty" part="empty"><div class="c-empty__illustration" part="illustration"><slot name="illustration"></slot></div><div class="c-empty__title" part="title"><slot name="title"></slot></div><div class="c-empty__text" part="body"><slot></slot></div><div><slot name="action"></slot></div></div>`);
410
+ shadow("contour-shadow-feature", `<div class="c-feature" part="feature"><span class="c-feature__index" part="index"><slot name="index"></slot></span><div class="c-feature__title" part="title"><slot name="title"></slot></div><div class="c-feature__body" part="body"><slot></slot></div></div>`);
411
+ shadow("contour-shadow-kpi", `<div class="c-kpi" part="kpi"><div class="c-kpi__value" part="value"><slot name="value"></slot></div><div class="c-kpi__label" part="label"><slot name="label"></slot></div><div class="c-kpi__foot" part="foot"><slot name="delta"></slot><slot name="note"></slot></div></div>`);
412
+ shadow("contour-shadow-stat", `<div class="c-stat" part="stat"><div class="c-stat__value" part="value"><slot name="value"></slot></div><div class="c-stat__label" part="label"><slot name="label"></slot></div><div class="c-stat__delta" part="delta"><slot name="delta"></slot></div></div>`);
413
+ shadow("contour-shadow-meter", `<div class="c-meter" part="meter"><span class="c-meter__core" part="core"><span class="c-meter__value" part="value"><slot name="value"></slot></span><span class="c-meter__label" part="label"><slot name="label"></slot></span></span></div>`);
414
+ shadow("contour-shadow-brownout", `<div class="c-brownout" part="brownout" data-level="0"><slot></slot></div>`);
415
+ shadow("contour-shadow-widget-state", `<div class="c-widget-state" part="widget-state"><slot></slot></div>`);
416
+ shadow("contour-shadow-donut", `<div class="c-donut" part="donut"><svg class="c-donut__ring" part="ring" viewBox="0 0 32 32"></svg><div class="c-donut__center" part="center"><slot name="value"></slot></div><div class="c-donut__list" part="list"><slot></slot></div></div>`);
417
+ shadow("contour-shadow-axis", `<div class="c-axis" part="axis"><slot></slot></div>`);
418
+ shadow("contour-shadow-brush", `<div class="c-brush" part="brush"><div class="c-brush__selection" part="selection"></div></div>`);
419
+ shadow("contour-shadow-stacked-bar", `<div class="c-stacked-bar" part="bar"><slot></slot></div>`);
420
+ shadow("contour-shadow-category", `<div class="c-category" part="category" role="listbox"><slot></slot></div>`);
421
+ shadow("contour-shadow-gauge", `<div class="c-gauge" part="gauge"><svg class="c-gauge__dial" part="dial" aria-hidden="true" viewBox="0 0 100 100"><path class="c-gauge__track" part="track" d="M 10 90 A 40 40 0 0 1 90 90"></path><g class="c-gauge__zones"></g><line class="c-gauge__needle" part="needle" x1="50" y1="50" x2="50" y2="15"></line><circle class="c-gauge__hub" part="hub" cx="50" cy="50" r="4"></circle></svg><div class="c-gauge__value" part="value"><slot name="value"></slot></div><div class="c-gauge__band" part="band"><slot name="band"></slot></div></div>`);
422
+ shadow("contour-shadow-diff", `<div class="c-diff" part="diff"><div class="c-diff__line c-diff__line--del" part="before"><span class="c-diff__sign">−</span><span><slot name="before"></slot></span></div><div class="c-diff__line c-diff__line--add" part="after"><span class="c-diff__sign">+</span><span><slot name="after"></slot></span></div></div>`);
423
+ shadow("contour-shadow-do-dont", `<div class="c-do-dont" part="do-dont"><div class="c-do-dont__item c-do-dont__item--do" part="do"><slot name="do"></slot></div><div class="c-do-dont__item c-do-dont__item--dont" part="dont"><slot name="dont"></slot></div></div>`);
424
+ shadow("contour-shadow-threshold", `<div class="c-threshold" part="threshold"><span class="c-threshold__fill" part="value"></span><span class="c-threshold__target" part="target"></span></div>`);
425
+ shadow("contour-shadow-coordinate", `<div class="c-coordinate" part="coordinate"><span class="c-coordinate__value" part="value"><slot name="value"></slot></span></div>`);
426
+ shadow("contour-shadow-install", `<div class="c-install" part="install"><span class="c-install__prompt" part="prompt"><slot name="prompt"></slot></span><span class="c-install__command" part="command"><slot name="command"></slot></span><button class="c-btn c-btn--ghost c-btn--sm c-install__copy" part="copy" type="button" aria-label="Copy command">Copy</button></div>`);
427
+ shadow("contour-shadow-toc", `<div class="c-toc" part="toc"><div class="c-toc__title" part="title"><slot name="title"></slot></div><nav class="c-toc__list" part="list"><slot></slot></nav></div>`);
428
+ shadow("contour-shadow-testimonial", `<div class="c-testimonial" part="testimonial"><blockquote class="c-testimonial__quote" part="quote"><slot name="quote"></slot></blockquote><div class="c-testimonial__byline" part="byline"><span class="c-testimonial__name" part="name"><slot name="name"></slot></span><span class="c-testimonial__role" part="role"><slot name="role"></slot></span></div></div>`);
429
+ shadow("contour-shadow-search-trigger", `<button class="c-search-trigger" part="trigger"><span><slot name="label"></slot></span><kbd class="c-search-trigger__kbd"><slot name="shortcut"></slot></kbd></button>`);
430
+ shadow("contour-shadow-brand", `<a class="c-brand" part="brand"><span class="c-mark" part="mark"><slot name="mark"></slot></span><span class="c-brand__name" part="name"><slot name="name"></slot></span></a>`);
431
+ shadow("contour-shadow-section-head", `<div class="c-section-head" part="head"><h2 class="c-section-head__title" part="title"><slot name="title"></slot></h2><p class="c-section-head__desc" part="desc"><slot name="desc"></slot></p></div>`);
432
+ shadow("contour-shadow-loading", `<div class="c-loading" part="loading"><span class="c-spinner" part="spinner"></span><slot></slot></div>`);
433
+ // Shadow tabs are a styling shell: panels are authored by the consumer
434
+ shadow("contour-shadow-tabs", `<div class="c-tabs" part="tabs"><div class="c-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-tabs__panels" role="presentation"><slot></slot></div></div>`);
435
+ shadow("contour-shadow-breadcrumb", `<nav class="c-breadcrumb" part="breadcrumb" aria-label="Breadcrumb"><ol><slot></slot></ol></nav>`);
436
+ shadow("contour-shadow-menu", `<div class="c-menu" part="menu" role="menu"><slot></slot></div>`);
437
+ shadow("contour-shadow-combobox", `<div class="c-combobox" part="combobox"><input class="c-combobox__input" part="input" type="text" /><ul class="c-combobox__list" part="list" hidden><slot></slot></ul></div>`);
438
+ shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
439
+ shadow("contour-shadow-bivariate", `<div class="c-bivariate" part="bivariate"><div class="c-bivariate__matrix" part="matrix"><slot></slot></div></div>`);
440
+ shadow("contour-shadow-bivariate-legend", `<div class="c-bivariate-legend" part="legend"><div class="c-bivariate-legend__matrix" part="matrix"><slot></slot></div></div>`);
441
+ shadow("contour-shadow-expandable", `<details class="c-expandable" part="expandable"><summary class="c-expandable__summary"><slot name="summary"></slot></summary><div class="c-expandable__body" part="body"><slot></slot></div></details>`);
442
+ shadow("contour-shadow-disclosure", `<details class="c-disclosure" part="disclosure"><summary><slot name="summary"></slot></summary><div class="c-disclosure__body" part="body"><slot></slot></div></details>`);
443
+ shadow("contour-shadow-faq", `<div class="c-faq" part="faq"><div class="c-faq__question" part="question"><slot name="question"></slot></div><div class="c-faq__answer" part="answer"><slot name="answer"></slot></div></div>`);
444
+ shadow("contour-shadow-code-tabs", `<div class="c-code-tabs" part="code-tabs"><div class="c-code-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-code-tabs__panels"><slot></slot></div></div>`);
445
+ shadow("contour-shadow-header", `<header class="c-header" part="header"><div class="container c-header__inner" part="inner"><a class="c-brand" part="brand"><slot name="brand"></slot></a><nav class="c-header__nav" part="nav"><slot name="nav"></slot></nav><div class="c-header__actions" part="actions"><slot name="actions"></slot></div></div></header>`);
446
+ shadow("contour-shadow-footer", `<footer class="c-footer" part="footer"><div class="container c-footer__grid" part="grid"><div class="c-footer__brand" part="brand"><slot name="brand"></slot></div><div class="c-footer__links" part="links"><slot name="links"></slot></div></div></footer>`);
447
+ shadow("contour-shadow-container", `<div class="container" part="container"><slot></slot></div>`);
448
+ // R31-03: contour-shadow-input / -textarea / -select / -table / -scheme-toggle
449
+ // were removed. Each was a control shell that could not hold the state its
450
+ // light twin holds (no value, no options, no rows, no toggle), so it was a
451
+ // trap rather than a styling seam. Use the light <contour-input>,
452
+ // <contour-select>, <contour-table> and <contour-scheme-toggle>, or style a
453
+ // native control with the `.c-input` / `.c-table` classes directly.
454
+ shadow("contour-shadow-spinner", `<span class="c-spinner" part="spinner" aria-label="Loading"></span>`);
455
+ shadow("contour-shadow-code", `<pre class="c-code" part="code"><code><slot></slot></code><button class="c-code__copy" part="copy" type="button">Copy</button></pre>`);
456
+ // (folded in from the hand-written component that used to carry its own copy of the sheet logic)
457
+ shadow("contour-shadow-card", `<div class="c-card" part="card"> <div class="c-card__title" part="head"><slot name="title">Untitled</slot></div> <div class="c-card__body" part="body"><slot></slot></div> <div class="c-card__foot" part="foot"><slot name="foot"></slot></div> </div>`);
458
+ // (folded in from the hand-written component that used to carry its own copy of the sheet logic)
459
+ // (folded in from the hand-written component that used to carry its own copy of the sheet logic)
460
+ shadow("contour-shadow-field", `<div class="c-field" part="field"> <label class="c-field__label" part="label"><slot name="label">Label</slot></label> <slot name="input"></slot> <span class="c-field__hint" part="hint"><slot name="hint"></slot></span> </div>`);
461
+ // (folded in from the hand-written component that used to carry its own copy of the sheet logic)
462
+ shadow("contour-shadow-alert", `<div class="c-alert" part="alert"> <div class="c-alert__title" part="title"><slot name="title"></slot></div> <div class="c-alert__body" part="body"><slot></slot></div> <div class="c-alert__actions" part="actions"><slot name="action"></slot></div> <button class="c-alert__close" part="close" type="button" aria-label="Close">×</button> </div>`);
463
+ shadow("contour-shadow-tag", `<span class="c-tag" part="tag"><slot></slot><button class="c-tag__remove" part="remove" type="button" aria-label="Remove">×</button></span>`);
464
+ shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-pill"><slot></slot><button class="c-filter-pill__remove" part="remove" type="button" aria-label="Remove filter">×</button></span>`);
465
+
466
+ // The dialog is the one wrapper with behaviour, because a close button that
467
+ // does not close is a control the reader cannot use.
468
+ const DIALOG_MARKUP = "<dialog class=\"c-dialog\" part=\"dialog\"> <div class=\"c-dialog__head\" part=\"head\"> <slot name=\"title\"></slot> <button class=\"c-btn c-btn--icon c-btn--ghost\" part=\"close\" type=\"button\" aria-label=\"Close\"> <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\"><path d=\"m18 6-12 12M6 6l12 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\"/></svg> </button> </div> <div class=\"c-dialog__body\" part=\"body\"><slot></slot></div> <div class=\"c-dialog__foot\" part=\"foot\"><slot name=\"foot\"></slot></div> </dialog>";
469
+ SHADOW_MARKUP["contour-shadow-dialog"] = DIALOG_MARKUP;
470
+ recordParts("contour-shadow-dialog", DIALOG_MARKUP);
471
+ class ContourShadowDialog extends ContourShadow {
472
+ static contourTemplate = (typeof document !== "undefined") ? (() => {
473
+ const tpl = document.createElement("template");
474
+ setHTML(tpl, DIALOG_MARKUP);
475
+ return tpl;
476
+ })() : null;
477
+ enhance(root) {
478
+ super.enhance(root);
479
+ // The base constructor AND connectedCallback both call enhance; the base's
480
+ if (this._wiredShadowDialog) return;
481
+ this._wiredShadowDialog = true;
482
+ const dlg = root.querySelector("dialog");
483
+ const close = root.querySelector('[part="close"]');
484
+ if (close) close.addEventListener("click", () => dlg?.close());
485
+ if (dlg) {
486
+ let lastFocus = null;
487
+ // `<dialog>` fires no `show` or `close` events in this engine (measured
488
+ dlg.addEventListener("beforetoggle", (e) => {
489
+ if (e.newState === "open") {
490
+ lastFocus = document.activeElement;
491
+ // beforetoggle fires BEFORE dialog.open flips, so the attribute
492
+ // write must not re-enter attributeChangedCallback's show() path.
493
+ this._syncingOpenAttr = true;
494
+ if (!this.hasAttribute("open")) this.setAttribute("open", "");
495
+ this._syncingOpenAttr = false;
496
+ this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
497
+ // Focus the close button or first focusable element
498
+ const focusable = dlg.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
499
+ if (focusable) try { focusable.focus(); } catch (e) {}
500
+ } else if (e.newState === "closed") {
501
+ this._syncingOpenAttr = true;
502
+ if (this.hasAttribute("open")) this.removeAttribute("open");
503
+ this._syncingOpenAttr = false;
504
+ this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
505
+ // Restore focus
506
+ if (lastFocus && typeof lastFocus.focus === "function") {
507
+ try { lastFocus.focus(); } catch (e) {}
508
+ }
509
+ }
510
+ });
511
+ // Focus trap: keep Tab within the dialog. R31-04: the focusables are not
512
+ // only in the shadow tree — slotted light-DOM controls (the dialog body
513
+ // is a <slot>) are real tab stops too, and `document.activeElement` is
514
+ // the shadow host, not the control. Collect both, and read the
515
+ // shadow-aware active element.
516
+ const collectFocusable = () => {
517
+ const sel = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
518
+ const out = Array.from(dlg.querySelectorAll(sel));
519
+ for (const slot of dlg.querySelectorAll("slot")) {
520
+ for (const n of slot.assignedElements({ flatten: true })) {
521
+ if (n.matches(sel)) out.push(n);
522
+ for (const sub of n.querySelectorAll(sel)) out.push(sub);
523
+ }
524
+ }
525
+ return out;
526
+ };
527
+ const activeEl = () => (this.shadowRoot && this.shadowRoot.activeElement) || document.activeElement;
528
+ dlg.addEventListener("keydown", (e) => {
529
+ if (e.key !== "Tab") return;
530
+ const focusables = collectFocusable();
531
+ if (!focusables.length) return;
532
+ const first = focusables[0];
533
+ const last = focusables[focusables.length - 1];
534
+ if (e.shiftKey && activeEl() === first) {
535
+ e.preventDefault();
536
+ last.focus();
537
+ } else if (!e.shiftKey && activeEl() === last) {
538
+ e.preventDefault();
539
+ first.focus();
540
+ }
541
+ });
542
+ }
543
+ }
544
+ static get observedAttributes() { return [...super.observedAttributes, "open"]; }
545
+ attributeChangedCallback(name, oldValue, newValue) {
546
+ super.attributeChangedCallback(name, oldValue, newValue);
547
+ // The host's `open` attribute drives the inner native dialog, matching
548
+ // the light family; without this the attribute was inert (R25-12).
549
+ if (name === "open" && this.shadowRoot && !this._syncingOpenAttr) {
550
+ const dlg = this.shadowRoot.querySelector("dialog");
551
+ if (dlg) {
552
+ if (newValue !== null && !dlg.open) this.show();
553
+ else if (newValue === null && dlg.open) this.close();
554
+ }
555
+ }
556
+ }
557
+ connectedCallback() {
558
+ super.connectedCallback();
559
+ // R31-33: an `open` attribute set before the element was connected (or a
560
+ // show() called while disconnected) must engage the dialog once it lands
561
+ // in the document; showModal() on a disconnected dialog throws.
562
+ if (this.hasAttribute("open")) this.show();
563
+ }
564
+ show() {
565
+ // R31-33: showModal() throws on a disconnected element. If not yet
566
+ // connected, leave the `open` attribute set; connectedCallback applies it.
567
+ if (!this.isConnected) { if (!this.hasAttribute("open")) this.setAttribute("open", ""); return; }
568
+ const d = this.shadowRoot?.querySelector("dialog");
569
+ if (d && !d.open) d.showModal();
570
+ }
571
+ close() { const d = this.shadowRoot?.querySelector("dialog"); if (d && d.open) d.close(); }
572
+ // Native-dialog parity with the light family (R20 T-32): showModal() is
573
+ showModal() { this.show(); }
574
+ get open() { return !!this.shadowRoot?.querySelector("dialog")?.open; }
575
+ set open(v) { if (v) this.show(); else this.close(); }
576
+ get returnValue() { return this.shadowRoot?.querySelector("dialog")?.returnValue ?? ""; }
577
+ set returnValue(v) { const d = this.shadowRoot?.querySelector("dialog"); if (d) d.returnValue = String(v); }
578
+ }
579
+ define("contour-shadow-dialog", ContourShadowDialog);
580
+
581
+ /**
582
+ * Render a Declarative Shadow DOM string for a registered contour-shadow-* element.
583
+ * Intended for SSR/string emission; returns null for unknown tags.
584
+ */
585
+ const renderShadowDSD = (tag, attrs = "", light = "") => {
586
+ const markup = SHADOW_MARKUP[tag];
587
+ if (typeof markup !== "string") return null;
588
+ const attrStr = attrs ? (attrs.startsWith(" ") ? attrs : " " + attrs) : "";
589
+ return `<${tag}${attrStr}><template shadowrootmode="open">${markup}</template>${light}</${tag}>`;
590
+ };
591
+
592
+ // Published once, at the end, so the array holds what the browser was actually
593
+ const FROZEN_SHADOW_MARKUP = Object.freeze({ ...SHADOW_MARKUP });
594
+ if (typeof globalThis !== "undefined") {
595
+ globalThis.ContourShadowTemplates = FROZEN_SHADOW_MARKUP;
596
+ }
597
+ // Only the SHADOW vocabulary publishes here (R25-06). ContourElements and
598
+ if (typeof window !== "undefined") {
599
+ window.ContourShadowParts = Object.freeze(Object.fromEntries(
600
+ Object.entries(SHADOW_PARTS_PUBLIC).map(([name, parts]) => [name, Object.freeze([...new Set(parts)])]),
601
+ ));
602
+ if (!window.Contour) window.Contour = {};
603
+ try { window.Contour.shadowTemplates = FROZEN_SHADOW_MARKUP; } catch {}
604
+ }
605
+
606
+ export { SHADOW_MARKUP, renderShadowDSD };
607
+
608
+
609
+ class ContourApp extends ContourBase {
610
+ static get observed() { return ["title"]; }
611
+ static get properties() { return { title: { attribute: "title" } }; }
612
+ render() {
613
+ this.classList.add("c-app");
614
+ const header = this.ensure(".c-app__header", () => { const el = document.createElement("header"); el.className = "c-app__header"; return el; });
615
+ const title = this.getAttribute("title");
616
+ if (title) {
617
+ const t = this.ensure(".c-app__title", () => { const el = document.createElement("div"); el.className = "c-app__title"; return el; });
618
+ t.textContent = title;
619
+ if (t.parentNode !== header) header.appendChild(t);
620
+ }
621
+ const main = this.ensure(".c-app__main", () => { const el = document.createElement("main"); el.className = "c-app__main"; return el; });
622
+ if (main.parentNode !== this) this.appendChild(main);
623
+ if (header.parentNode !== this) this.insertBefore(header, main);
624
+ // Authored children move into <main>; siblings took flex share and sat outside the only main landmark.
625
+ Array.from(this.children).forEach((child) => {
626
+ if (child === header || child === main) return;
627
+ main.appendChild(child);
628
+ });
629
+ }
630
+ }
631
+ define("contour-app", ContourApp);
632
+ class ContourAppBody extends ContourBase {
633
+ static get observed() { return ["title"]; }
634
+ static get properties() { return { title: { attribute: "title" } }; }
635
+ render() {
636
+ this.classList.add("c-app-body");
637
+ // One visible <main> per document; nested → plain div, standalone → main.
638
+ const nested = !!(this.parentElement && this.parentElement.closest && this.parentElement.closest("contour-app"));
639
+ const tag = nested ? "div" : "main";
640
+ let main = this.querySelector(":scope > .c-app-body__main");
641
+ if (main && main.tagName.toLowerCase() !== tag) { main.remove(); main = null; }
642
+ if (!main) {
643
+ main = document.createElement(tag);
644
+ main.className = "c-app-body__main";
645
+ this.appendChild(main);
646
+ }
647
+ const title = this.getAttribute("title");
648
+ if (title) {
649
+ const t = this.ensure(".c-app-body__title", () => { const el = document.createElement("div"); el.className = "c-app-body__title"; return el; });
650
+ t.textContent = title;
651
+ if (t.parentNode !== main) main.appendChild(t);
652
+ }
653
+ if (main.parentNode !== this) this.appendChild(main);
654
+ }
655
+ }
656
+ define("contour-app-body", ContourAppBody);
657
+ class ContourBtnGroup extends ContourBase {
658
+ static get observed() { return ["title"]; }
659
+ static get properties() { return { title: { attribute: "title" } }; }
660
+ render() {
661
+ this.classList.add("c-btn-group");
662
+ this.setAttribute("role", "group");
663
+ if (this.getAttribute("title")) this.setAttribute("aria-label", this.getAttribute("title"));
664
+ // Author supplies <button> children; component doesn't invent them.
665
+ }
666
+ enhance() {
667
+ if (this._wiredBtnGroup) return;
668
+ this._wiredBtnGroup = true;
669
+ this.addEventListener("click", (e) => {
670
+ const btn = e.target && e.target.closest ? e.target.closest(".c-btn") : null;
671
+ if (btn && this.contains(btn)) {
672
+ const buttons = Array.from(this.querySelectorAll(".c-btn"));
673
+ const index = buttons.indexOf(btn);
674
+ this.dispatchEvent(new CustomEvent("contour:btn-group-change", { bubbles: true, composed: true, detail: { index, label: btn.textContent } }));
675
+ }
676
+ });
677
+ this.addEventListener("keydown", (e) => {
678
+ const buttons = Array.from(this.querySelectorAll(".c-btn"));
679
+ if (!buttons.length) return;
680
+ navKey(e, buttons, { wrap: false, homeEnd: true, rtl: isRtl(this) });
681
+ });
682
+ }
683
+ }
684
+ define("contour-btn-group", ContourBtnGroup);
685
+ class ContourRangeScale extends ContourBase {
686
+ static get observed() { return ["label", "ticks"]; }
687
+ static get properties() { return { label: { attribute: "label" }, ticks: { attribute: "ticks" } }; }
688
+ render() {
689
+ this.classList.add("c-range-scale");
690
+ this.setAttribute("role", "group");
691
+ if (this.getAttribute("label")) this.setAttribute("aria-label", this.getAttribute("label"));
692
+ const label = this.getAttribute("label");
693
+ if (label) {
694
+ const t = this.ensure(".c-range-scale__label", () => { const el = document.createElement("span"); el.className = "c-range-scale__label"; return el; });
695
+ t.textContent = label;
696
+ }
697
+ // Tick marks (G-10): render a tick for each comma-separated value.
698
+ const ticksAttr = this.getAttribute("ticks");
699
+ Array.from(this.querySelectorAll(".c-range-scale__tick")).forEach((n) => n.remove());
700
+ if (ticksAttr) {
701
+ ticksAttr.split(",").map((s) => s.trim()).filter(Boolean).forEach((tk) => {
702
+ const t = document.createElement("span");
703
+ t.className = "c-range-scale__tick";
704
+ t.textContent = tk;
705
+ this.appendChild(t);
706
+ });
707
+ }
708
+ }
709
+ enhance() {
710
+ if (this._wiredRangeScale) return;
711
+ this._wiredRangeScale = true;
712
+ this.addEventListener("input", (e) => {
713
+ const t = e.target;
714
+ if (t && t.matches && t.matches("input")) {
715
+ this.dispatchEvent(new CustomEvent("contour:range-change", { bubbles: true, composed: true, detail: { value: t.value } }));
716
+ }
717
+ });
718
+ this.addEventListener("change", (e) => {
719
+ const t = e.target;
720
+ if (t && t.matches && t.matches("input")) {
721
+ this.dispatchEvent(new CustomEvent("contour:range-change", { bubbles: true, composed: true, detail: { value: t.value } }));
722
+ }
723
+ });
724
+ }
725
+ }
726
+ define("contour-range-scale", ContourRangeScale);
727
+ class ContourTimeRange extends ContourBase {
728
+ static get observed() { return ["label", "value", "ticks", "required", "disabled"]; }
729
+ static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, ticks: { attribute: "ticks" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
730
+ render() {
731
+ this.classList.add("c-time-range");
732
+ this.setAttribute("role", "group");
733
+ if (this.getAttribute("label")) this.setAttribute("aria-label", this.getAttribute("label"));
734
+ const label = this.getAttribute("label");
735
+ if (label) {
736
+ const t = this.ensure(".c-time-range__label", () => { const el = document.createElement("span"); el.className = "c-time-range__label"; return el; });
737
+ t.textContent = label;
738
+ }
739
+ // Slotted input gets host's label when unnamed.
740
+ const inp = this.querySelector("input");
741
+ if (inp && label && !inp.hasAttribute("aria-label") && !(inp.labels && inp.labels.length)) inp.setAttribute("aria-label", label);
742
+ // sync observed `value` onto slotted input.
743
+ const value = this.getAttribute("value");
744
+ if (value !== null && inp && inp.value !== value) inp.value = value;
745
+ const ticksAttr = this.getAttribute("ticks");
746
+ Array.from(this.querySelectorAll(".c-time-range__tick")).forEach((n) => n.remove());
747
+ if (ticksAttr) {
748
+ ticksAttr.split(",").map((s) => s.trim()).filter(Boolean).forEach((tk) => {
749
+ const t = document.createElement("span");
750
+ t.className = "c-time-range__tick";
751
+ t.textContent = tk;
752
+ this.appendChild(t);
753
+ });
754
+ }
755
+ }
756
+ enhance() {
757
+ if (this._wiredTimeRange) return;
758
+ this._wiredTimeRange = true;
759
+ this.addEventListener("input", (e) => {
760
+ const t = e.target;
761
+ if (t && t.matches && t.matches("input")) {
762
+ this.dispatchEvent(new CustomEvent("contour:time-range-change", { bubbles: true, composed: true, detail: { value: t.value } }));
763
+ }
764
+ });
765
+ this.addEventListener("change", (e) => {
766
+ const t = e.target;
767
+ if (t && t.matches && t.matches("input")) {
768
+ this.dispatchEvent(new CustomEvent("contour:time-range-change", { bubbles: true, composed: true, detail: { value: t.value } }));
769
+ }
770
+ });
771
+ }
772
+ }
773
+ define("contour-time-range", ContourTimeRange);
774
+
775
+ // Skip link: visually hidden until focused; class does the work.
776
+ class ContourSkipLink extends ContourBase {
777
+ static get observed() { return ["href", "label"]; }
778
+ static get properties() { return { href: { attribute: "href" }, label: { attribute: "label" } }; }
779
+ render() {
780
+ // drop authored text nodes so the authored label isn't rendered a
781
+ // second time beside the generated <a> (which carries the `label` attribute).
782
+ Array.from(this.childNodes).forEach((n) => { if (n.nodeType === Node.TEXT_NODE) n.remove(); });
783
+ const a = this.ensure("a", () => { const el = document.createElement("a"); el.className = "c-skip-link"; return el; });
784
+ a.setAttribute("href", safeHref(this.getAttribute("href") || "#main"));
785
+ a.textContent = this.getAttribute("label") || "Skip to content";
786
+ }
787
+ }
788
+ define("contour-skip-link", ContourSkipLink);
789
+
790
+ // Icon: renders sprite <use> by name; consumer points name at an id.
791
+ class ContourIcon extends ContourBase {
792
+ static get observed() { return ["name", "size", "label"]; }
793
+ static get properties() { return { name: { attribute: "name" }, size: { attribute: "size" }, label: { attribute: "label" } }; }
794
+ render() {
795
+ const name = this.getAttribute("name") || "";
796
+ // accept `name="check"` or `name="i-check"` (prevents "#i-i-check").
797
+ const iconName = name.startsWith("i-") ? name.slice(2) : name;
798
+ const size = this.getAttribute("size");
799
+ const label = this.getAttribute("label");
800
+ this.innerHTML = "";
801
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
802
+ svg.setAttribute("class", "c-icon");
803
+ svg.setAttribute("aria-hidden", "true");
804
+ if (size) svg.style.width = size, svg.style.height = size;
805
+ const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
806
+ use.setAttribute("href", "#i-" + iconName);
807
+ svg.appendChild(use);
808
+ this.appendChild(svg);
809
+ if (label) { this.setAttribute("role", "img"); this.setAttribute("aria-label", label); }
810
+ else { this.removeAttribute("role"); this.removeAttribute("aria-label"); }
811
+ }
812
+ }
813
+ define("contour-icon", ContourIcon);
814
+
815
+ // Dashboard grid: layout primitive for responsive grid of widget cells.
816
+ class ContourDashboardGrid extends ContourBase {
817
+ static get observed() { return ["cols", "gap"]; }
818
+ static get properties() { return { cols: { attribute: "cols" }, gap: { attribute: "gap" } }; }
819
+ render() {
820
+ this.classList.add("c-dashboard-grid");
821
+ const cols = this.getAttribute("cols");
822
+ if (cols) this.style.setProperty("--dashboard-grid-cols", cols);
823
+ const gap = this.getAttribute("gap");
824
+ if (gap) this.style.setProperty("--dashboard-grid-gap", gap);
825
+ }
826
+ }
827
+ define("contour-dashboard-grid", ContourDashboardGrid);
828
+
829
+ // Analysis stack: vertical stack of panels with shared header.
830
+ class ContourAnalysisStack extends ContourBase {
831
+ static get observed() { return ["title", "heading"]; }
832
+ static get properties() { return { title: { attribute: "title" }, heading: { attribute: "heading" } }; }
833
+ render() {
834
+ this.classList.add("c-analysis-stack");
835
+ const title = this.getAttribute("title");
836
+ let header = this.querySelector(".c-analysis-stack__header");
837
+ if (title) {
838
+ if (!header) { header = document.createElement("div"); header.className = "c-analysis-stack__header"; this.prepend(header); }
839
+ let h = header.querySelector(".c-analysis-stack__title");
840
+ if (!h) { h = document.createElement(headingTag(this, "h3")); h.className = "c-analysis-stack__title"; header.appendChild(h); }
841
+ h.textContent = title;
842
+ } else if (header) header.remove();
843
+ }
844
+ }
845
+ define("contour-analysis-stack", ContourAnalysisStack);