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,1939 @@
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
+
610
+
611
+ /* Line numbers are real elements, not a CSS counter: a counter cannot be left
612
+ out of a selection or the copied text. wireCopy drops them before copying.
613
+ A highlight token can span several lines (a multi-line string or comment is
614
+ one <span> whose text holds "\n"). Such a span cannot live inside one grid
615
+ row, so the splitter walks the subtree, breaks at every newline and rebuilds
616
+ each line with its own shallow clone of the spans it touches — the markup is
617
+ preserved per line and no span crosses a row boundary (R24-149). */
618
+ const splitCodeLines = (code) => {
619
+ // Flatten to per-line runs: { chain: [ancestor elements], text } split at "\n".
620
+ const lines = [[]];
621
+ let cur = lines[0];
622
+ const walk = (node, chain) => {
623
+ if (node.nodeType === 3) {
624
+ String(node.textContent || "").split("\n").forEach((p, i) => {
625
+ if (i) { cur = []; lines.push(cur); }
626
+ if (p) cur.push({ chain, text: p });
627
+ });
628
+ return;
629
+ }
630
+ if (node.nodeType !== 1) return;
631
+ const next = chain.concat(node);
632
+ Array.from(node.childNodes).forEach((c) => walk(c, next));
633
+ };
634
+ Array.from(code.childNodes).forEach((n) => walk(n, []));
635
+ const lastLine = lines[lines.length - 1];
636
+ if (!lastLine.length && lines.length > 1) lines.pop();
637
+ if (!lines.length) return;
638
+
639
+ const frag = document.createDocumentFragment();
640
+ lines.forEach((runs, i) => {
641
+ const lineEl = document.createElement("span");
642
+ lineEl.className = "c-code__line";
643
+ lineEl.setAttribute("data-contour-generated", "line");
644
+ // Reuse a clone while consecutive runs share the same ancestor at a depth.
645
+ const clones = [];
646
+ for (const run of runs) {
647
+ for (let d = 0; d < run.chain.length; d++) {
648
+ if (!clones[d] || clones[d]._contourSrc !== run.chain[d]) {
649
+ const clone = run.chain[d].cloneNode(false); // shallow: attrs/class only
650
+ clone._contourSrc = run.chain[d];
651
+ if (d === 0) lineEl.appendChild(clone);
652
+ else clones[d - 1].appendChild(clone);
653
+ clones[d] = clone;
654
+ clones.length = d + 1; // drop deeper clones from a different parent
655
+ }
656
+ }
657
+ const parent = run.chain.length ? clones[run.chain.length - 1] : lineEl;
658
+ parent.appendChild(document.createTextNode(run.text));
659
+ }
660
+ const num = document.createElement("span");
661
+ num.className = "c-code__line-number";
662
+ num.setAttribute("aria-hidden", "true");
663
+ num.textContent = String(i + 1);
664
+ lineEl.prepend(num);
665
+ frag.appendChild(lineEl);
666
+ });
667
+ code.textContent = "";
668
+ code.appendChild(frag);
669
+ };
670
+
671
+ const joinCodeLines = (code) => {
672
+ const frag = document.createDocumentFragment();
673
+ Array.from(code.querySelectorAll(".c-code__line")).forEach((l) => {
674
+ Array.from(l.childNodes).forEach((n) => {
675
+ if (n.classList && n.classList.contains("c-code__line-number")) return;
676
+ frag.appendChild(n);
677
+ });
678
+ frag.appendChild(document.createTextNode("\n"));
679
+ });
680
+ code.textContent = "";
681
+ code.appendChild(frag);
682
+ };
683
+
684
+ class ContourCard extends ContourBase {
685
+ static get observed() { return ["title", "variant", "heading"]; }
686
+ static get properties() { return { title: { attribute: "title" }, variant: { attribute: "variant" } }; }
687
+ render() {
688
+ this.classList.add("c-card");
689
+ const variant = this.getAttribute("variant");
690
+ Array.from(this.classList).forEach((c) => { if (c.startsWith("c-card--")) this.classList.remove(c); });
691
+ if (variant) this.classList.add("c-card--" + variant);
692
+ const title = this.getAttribute("title");
693
+ if (title) {
694
+ const h = this.ensure(".c-card__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-card__title"; return el; });
695
+ if (h.parentNode === this && this.firstChild !== h) this.prepend(h);
696
+ h.textContent = title;
697
+ } else {
698
+ const h = this.querySelector(".c-card__title");
699
+ if (h) h.remove();
700
+ }
701
+ }
702
+ }
703
+ define("contour-card", ContourCard);
704
+ class ContourFeature extends ContourBase {
705
+ static get observed() { return ["index", "title", "body", "heading"]; }
706
+ static get properties() { return { index: { attribute: "index" }, title: { attribute: "title" }, body: { attribute: "body" } }; }
707
+ render() {
708
+ this.classList.add("c-feature");
709
+ // `.c-feature` has no icon slot; the index line is its label.
710
+ const index = this.getAttribute("index");
711
+ const title = this.getAttribute("title");
712
+ const body = this.getAttribute("body");
713
+ if (index) {
714
+ const x = this.ensure(".c-feature__index", () => { const el = document.createElement("span"); el.className = "c-feature__index"; return el; });
715
+ x.textContent = index;
716
+ } else {
717
+ const x = this.querySelector(".c-feature__index");
718
+ if (x) x.remove();
719
+ }
720
+ if (title) {
721
+ const t = this.ensure(".c-feature__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-feature__title"; return el; });
722
+ t.textContent = title;
723
+ } else {
724
+ const t = this.querySelector(".c-feature__title");
725
+ if (t) t.remove();
726
+ }
727
+ if (body) {
728
+ const b = this.ensure(".c-feature__body", () => { const el = document.createElement("p"); el.className = "c-feature__body"; return el; });
729
+ b.textContent = body;
730
+ } else {
731
+ const b = this.querySelector(".c-feature__body");
732
+ if (b) b.remove();
733
+ }
734
+ }
735
+ }
736
+ define("contour-feature", ContourFeature);
737
+ class ContourSteps extends ContourBase {
738
+ static get observed() { return ["steps", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading", "cache-key", "no-cache"]; }
739
+ static get properties() { return { steps: { attribute: "steps" }, current: { attribute: "current", type: Number }, src: { attribute: "src" } }; }
740
+ render() {
741
+ this.classList.add("c-steps");
742
+ // Native list semantics: an <ol> numbers itself and <li> are list items.
743
+ let list = this.querySelector(".c-steps__list");
744
+ if (!list) {
745
+ list = document.createElement("ol");
746
+ list.className = "c-steps__list";
747
+ list.setAttribute("aria-label", this.getAttribute("aria-label") || "Steps");
748
+ this.appendChild(list);
749
+ }
750
+ wireStates(this);
751
+ loadRemote(this, "steps");
752
+ if (renderStates(this, "steps")) return;
753
+ const steps = remoteData(this, "steps");
754
+ const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-steps__item"));
755
+ // Adopt authored items into the ol so they share its semantics.
756
+ authored.forEach((it) => { if (it.parentNode !== list) list.appendChild(it); });
757
+ if (steps && !authored.length) {
758
+ // Drop previously generated items so a re-render cannot stack a second set.
759
+ Array.from(list.querySelectorAll(".c-steps__item")).forEach((n) => n.remove());
760
+ try {
761
+ const parsed = JSON.parse(steps);
762
+ parsed.forEach((st, i) => {
763
+ const item = document.createElement("li");
764
+ item.className = "c-steps__item";
765
+ item.tabIndex = -1;
766
+ const title = typeof st === "string" ? st : st.title;
767
+ const body = typeof st === "string" ? "" : st.body;
768
+ if (title) {
769
+ const h = document.createElement(headingTag(this, "h3"));
770
+ h.className = "c-steps__title";
771
+ h.textContent = title;
772
+ item.appendChild(h);
773
+ }
774
+ if (body) {
775
+ const p = document.createElement("p");
776
+ p.className = "c-steps__body";
777
+ p.textContent = body;
778
+ item.appendChild(p);
779
+ }
780
+ list.appendChild(item);
781
+ });
782
+ } catch (e) { warnBadJson(this, "attribute", e); }
783
+ } else if (!steps && !authored.length) {
784
+ renderEmpty(this, "steps");
785
+ }
786
+ // Reflect the current step onto the items without clobbering generated nodes.
787
+ const attrCurrent = this.getAttribute("current");
788
+ const current = (this._current != null) ? this._current : (attrCurrent != null ? parseInt(attrCurrent, 10) : NaN);
789
+ const items = Array.from(this.querySelectorAll(".c-steps__item"));
790
+ items.forEach((it, i) => {
791
+ if (Number.isFinite(current) && i === current) it.setAttribute("aria-current", "step");
792
+ else it.removeAttribute("aria-current");
793
+ it.tabIndex = (Number.isFinite(current) && i === current) ? 0 : -1;
794
+ });
795
+ if (items.length && !Number.isFinite(current)) {
796
+ items[0].tabIndex = 0;
797
+ }
798
+ }
799
+ enhance() {
800
+ if (!this._wiredSteps) {
801
+ this._wiredSteps = true;
802
+ this.addEventListener("keydown", (e) => {
803
+ const items = Array.from(this.querySelectorAll(".c-steps__item"));
804
+ if (!items.length) return;
805
+ navKey(e, items, { wrap: false, homeEnd: true, rtl: isRtl(this), onNavigate: (i) => { this._current = i; items.forEach((it, j) => { if (j === i) it.setAttribute("aria-current", "step"); else it.removeAttribute("aria-current"); it.tabIndex = j === i ? 0 : -1; }); const title = items[i].querySelector(".c-steps__title")?.textContent || ""; this.dispatchEvent(new CustomEvent("contour:step-change", { bubbles: true, composed: true, detail: { index: i, title } })); }, onKey: () => { if (e.key === "Enter" || e.key === " ") { const idx = items.indexOf(document.activeElement); const title = document.activeElement.querySelector(".c-steps__title")?.textContent || ""; this.dispatchEvent(new CustomEvent("contour:step-activate", { bubbles: true, composed: true, detail: { index: idx, title } })); } } });
806
+ });
807
+ this.addEventListener("click", (e) => {
808
+ const item = e.target && e.target.closest ? e.target.closest(".c-steps__item") : null;
809
+ if (!item || !this.contains(item)) return;
810
+ const items = Array.from(this.querySelectorAll(".c-steps__item"));
811
+ const idx = items.indexOf(item);
812
+ if (idx < 0) return;
813
+ this._current = idx;
814
+ items.forEach((it, i) => {
815
+ if (i === idx) it.setAttribute("aria-current", "step");
816
+ else it.removeAttribute("aria-current");
817
+ it.tabIndex = i === idx ? 0 : -1;
818
+ });
819
+ const title = item.querySelector(".c-steps__title")?.textContent || "";
820
+ this.dispatchEvent(new CustomEvent("contour:step-activate", { bubbles: true, composed: true, detail: { index: idx, title } }));
821
+ });
822
+ }
823
+ }
824
+ }
825
+ define("contour-steps", ContourSteps);
826
+ class ContourLink extends ContourBase {
827
+ static get observed() { return ["href", "label"]; }
828
+ static get properties() { return { href: { attribute: "href" }, label: { attribute: "label" } }; }
829
+ render() {
830
+ this.classList.add("c-link");
831
+ const href = this.getAttribute("href");
832
+ const label = this.getAttribute("label");
833
+ // Remove only generated anchors; an authored-only link renders nothing.
834
+ Array.from(this.querySelectorAll("a[data-contour-generated]")).forEach((n) => n.remove());
835
+ if (href && label) {
836
+ const a = document.createElement("a");
837
+ a.dataset.contourGenerated = "";
838
+ a.href = safeHref(href);
839
+ a.textContent = label;
840
+ const ariaLabel = this.getAttribute("aria-label");
841
+ if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
842
+ this.appendChild(a);
843
+ }
844
+ }
845
+ }
846
+ define("contour-link", ContourLink);
847
+ class ContourBrand extends ContourBase {
848
+ static get observed() { return ["name", "tag"]; }
849
+ static get properties() { return { name: { attribute: "name" }, tag: { attribute: "tag" } }; }
850
+ render() {
851
+ this.classList.add("c-brand");
852
+ const name = this.getAttribute("name");
853
+ const tag = this.getAttribute("tag");
854
+ if (name) {
855
+ const n = this.ensure(".c-brand__name", () => { const el = document.createElement("span"); el.className = "c-brand__name"; return el; });
856
+ n.textContent = name;
857
+ } else {
858
+ const n = this.querySelector(".c-brand__name");
859
+ if (n) n.remove();
860
+ }
861
+ if (tag) {
862
+ const t = this.ensure(".c-brand__tag", () => { const el = document.createElement("span"); el.className = "c-brand__tag"; return el; });
863
+ t.textContent = tag;
864
+ } else {
865
+ const t = this.querySelector(".c-brand__tag");
866
+ if (t) t.remove();
867
+ }
868
+ }
869
+ }
870
+ define("contour-brand", ContourBrand);
871
+ class ContourSectionHead extends ContourBase {
872
+ static get observed() { return ["title", "desc", "heading"]; }
873
+ static get properties() { return { title: { attribute: "title" }, desc: { attribute: "desc" } }; }
874
+ render() {
875
+ this.classList.add("c-section-head");
876
+ const title = this.getAttribute("title");
877
+ const desc = this.getAttribute("desc");
878
+ // icon badge
879
+ if (!this.querySelector(".c-icon-badge")) {
880
+ const badge = document.createElement("div");
881
+ badge.className = "c-icon-badge";
882
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
883
+ svg.setAttribute("aria-hidden", "true");
884
+ const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
885
+ use.setAttribute("href", "#i-crosshair");
886
+ svg.appendChild(use);
887
+ badge.replaceChildren(svg);
888
+ this.prepend(badge);
889
+ }
890
+ // content wrapper
891
+ let content = this.querySelector(":scope > div:not(.c-icon-badge)");
892
+ if (!content) {
893
+ content = document.createElement("div");
894
+ this.appendChild(content);
895
+ }
896
+ if (title) {
897
+ const t = this.ensure(".c-section-head__title", () => { const el = document.createElement(headingTag(this, "h2")); el.className = "c-section-head__title"; return el; });
898
+ t.textContent = title;
899
+ if (t.parentNode !== content) content.appendChild(t);
900
+ } else {
901
+ const t = this.querySelector(".c-section-head__title");
902
+ if (t) t.remove();
903
+ }
904
+ if (desc) {
905
+ const d = this.ensure(".c-section-head__desc", () => { const el = document.createElement("p"); el.className = "c-section-head__desc"; return el; });
906
+ d.textContent = desc;
907
+ if (d.parentNode !== content) content.appendChild(d);
908
+ } else {
909
+ const d = this.querySelector(".c-section-head__desc");
910
+ if (d) d.remove();
911
+ }
912
+ }
913
+ }
914
+ define("contour-section-head", ContourSectionHead);
915
+ class ContourDiff extends ContourBase {
916
+ static get observed() { return ["before", "after"]; }
917
+ static get properties() { return { before: { attribute: "before" }, after: { attribute: "after" } }; }
918
+ render() {
919
+ this.classList.add("c-diff");
920
+ this.setAttribute("role", "group");
921
+ this.setAttribute("aria-label", labelText(this, "diff", "Diff"));
922
+ // The block is a list of lines, not two panes: each `.c-diff__line` carries
923
+ // a sign, number and text, with `--add`/`--del` as its only states.
924
+ Array.from(this.querySelectorAll(".c-diff__line")).forEach((n) => n.remove());
925
+ const line = (kind, sign, text, num) => {
926
+ const el = document.createElement("div");
927
+ el.className = kind ? `c-diff__line c-diff__line--${kind}` : "c-diff__line";
928
+ el.setAttribute("role", "listitem");
929
+ el.setAttribute("tabindex", "0");
930
+ // Emit sign+number+text (3 children matching the grid).
931
+ const s = document.createElement("span");
932
+ s.className = "c-diff__sign";
933
+ s.textContent = sign;
934
+ const n = document.createElement("span");
935
+ n.className = "c-diff__num";
936
+ n.setAttribute("aria-hidden", "true");
937
+ n.textContent = String(num || "");
938
+ const code = document.createElement("span");
939
+ code.textContent = text;
940
+ el.append(s, n, code);
941
+ return el;
942
+ };
943
+ const before = this.getAttribute("before");
944
+ const after = this.getAttribute("after");
945
+ // Split before/after on newlines so multi-line values render as separate lines.
946
+ let lineNum = 1;
947
+ if (before) {
948
+ String(before).split("\n").forEach((l) => {
949
+ this.appendChild(line("del", "−", l, lineNum++));
950
+ });
951
+ }
952
+ if (after) {
953
+ String(after).split("\n").forEach((l) => {
954
+ this.appendChild(line("add", "+", l, lineNum++));
955
+ });
956
+ }
957
+ }
958
+ enhance() {
959
+ if (this._wiredDiff) return;
960
+ this._wiredDiff = true;
961
+ this.addEventListener("click", (e) => {
962
+ const line = e.target && e.target.closest ? e.target.closest(".c-diff__line") : null;
963
+ if (line && this.contains(line)) {
964
+ const kind = line.classList.contains("c-diff__line--add") ? "add" : line.classList.contains("c-diff__line--del") ? "del" : "context";
965
+ const text = line.querySelector("span:last-child")?.textContent || "";
966
+ this.dispatchEvent(new CustomEvent("contour:diff-activate", { bubbles: true, composed: true, detail: { kind, text } }));
967
+ }
968
+ });
969
+ this.addEventListener("keydown", (e) => {
970
+ const line = e.target && e.target.closest ? e.target.closest(".c-diff__line") : null;
971
+ if (!line || !this.contains(line)) return;
972
+ if (e.key === "Enter" || e.key === " ") {
973
+ e.preventDefault();
974
+ line.click();
975
+ }
976
+ });
977
+ }
978
+ }
979
+ define("contour-diff", ContourDiff);
980
+ class ContourDoDont extends ContourBase {
981
+ static get observed() { return ["do", "dont"]; }
982
+ static get properties() { return { do: { attribute: "do" }, dont: { attribute: "dont" } }; }
983
+ render() {
984
+ this.classList.add("c-do-dont");
985
+ this.setAttribute("role", "group");
986
+ this.setAttribute("aria-label", labelText(this, "do-and-dont", "Do and don't"));
987
+ // An item is one element with a state modifier (`__item--do`/`--dont`) and
988
+ // a `__label`; there is no `__do`/`__dont` element.
989
+ Array.from(this.querySelectorAll(".c-do-dont__item")).forEach((n) => n.remove());
990
+ // role + tabindex are set in render so they survive re-render (enhance() runs
991
+ // once); items are keyboard-activated, so they are buttons, not listitems.
992
+ const item = (kind, word, text) => {
993
+ const el = document.createElement("div");
994
+ el.className = `c-do-dont__item c-do-dont__item--${kind}`;
995
+ el.setAttribute("role", "button");
996
+ el.setAttribute("tabindex", "0");
997
+ const label = document.createElement("p");
998
+ label.className = "c-do-dont__label";
999
+ label.textContent = word;
1000
+ const body = document.createElement("p");
1001
+ body.className = "u-muted";
1002
+ body.textContent = text;
1003
+ el.append(label, body);
1004
+ return el;
1005
+ };
1006
+ const doText = this.getAttribute("do");
1007
+ const dontText = this.getAttribute("dont");
1008
+ if (doText) this.appendChild(item("do", "Do", doText));
1009
+ if (dontText) this.appendChild(item("dont", "Don't", dontText));
1010
+ }
1011
+ enhance() {
1012
+ if (this._wiredDoDont) return;
1013
+ this._wiredDoDont = true;
1014
+ this.addEventListener("click", (e) => {
1015
+ const item = e.target && e.target.closest ? e.target.closest(".c-do-dont__item") : null;
1016
+ if (item && this.contains(item)) {
1017
+ const kind = item.classList.contains("c-do-dont__item--do") ? "do" : "dont";
1018
+ const text = item.querySelector(".u-muted")?.textContent || "";
1019
+ this.dispatchEvent(new CustomEvent("contour:do-dont-activate", { bubbles: true, composed: true, detail: { kind, text } }));
1020
+ }
1021
+ });
1022
+ // Make items focusable and keyboard-activatable.
1023
+ Array.from(this.querySelectorAll(".c-do-dont__item")).forEach((it) => {
1024
+ if (!it.hasAttribute("tabindex")) it.setAttribute("tabindex", "0");
1025
+ if (!it.hasAttribute("role")) it.setAttribute("role", "button");
1026
+ });
1027
+ this.addEventListener("keydown", (e) => {
1028
+ const item = e.target && e.target.closest ? e.target.closest(".c-do-dont__item") : null;
1029
+ if (!item || !this.contains(item)) return;
1030
+ if (e.key === "Enter" || e.key === " ") {
1031
+ e.preventDefault();
1032
+ item.click();
1033
+ }
1034
+ });
1035
+ }
1036
+ }
1037
+ define("contour-do-dont", ContourDoDont);
1038
+ class ContourFlag extends ContourBase {
1039
+ static get observed() { return ["variant", "label"]; }
1040
+ static get properties() { return { variant: { attribute: "variant" }, label: { attribute: "label" } }; }
1041
+ render() {
1042
+ this.classList.add("c-flag");
1043
+ const variant = this.getAttribute("variant");
1044
+ Array.from(this.classList).forEach((c) => { if (c.startsWith("c-flag--")) this.classList.remove(c); });
1045
+ if (variant) this.classList.add("c-flag--" + variant);
1046
+ const label = this.getAttribute("label");
1047
+ if (label) {
1048
+ // Update the text node, not textContent, so authored children survive.
1049
+ let text = Array.from(this.childNodes).find((n) => n.nodeType === 3);
1050
+ if (!text) { text = document.createTextNode(""); this.appendChild(text); }
1051
+ text.nodeValue = label;
1052
+ }
1053
+ }
1054
+ }
1055
+ define("contour-flag", ContourFlag);
1056
+ class ContourInstallFull extends ContourBase {
1057
+ static get observed() { return ["command", "prompt", "copyable"]; }
1058
+ static get properties() { return { command: { attribute: "command" }, prompt: { attribute: "prompt" }, copyable: { attribute: "copyable" } }; }
1059
+ render() {
1060
+ this.classList.add("c-install");
1061
+ const prompt = this.getAttribute("prompt") || "$";
1062
+ const command = this.getAttribute("command") || "";
1063
+ if (command) {
1064
+ const p = this.ensure(".c-install__prompt", () => { const el = document.createElement("span"); el.className = "c-install__prompt"; return el; });
1065
+ p.textContent = prompt;
1066
+ const c = this.ensure(".c-install__command", () => { const el = document.createElement("span"); el.className = "c-install__command"; return el; });
1067
+ c.textContent = command;
1068
+ if (this.hasAttribute("copyable")) {
1069
+ this.ensure(".c-install__copy", () => {
1070
+ const btn = document.createElement("button");
1071
+ btn.className = "c-btn c-btn--ghost c-btn--sm c-install__copy";
1072
+ btn.type = "button";
1073
+ btn.setAttribute("aria-label", labelText(this, "copy-command", "Copy command"));
1074
+ btn.textContent = labelText(this, "copy", "Copy");
1075
+ return btn;
1076
+ });
1077
+ } else {
1078
+ const btn = this.querySelector(".c-install__copy");
1079
+ if (btn) btn.remove();
1080
+ }
1081
+ }
1082
+ }
1083
+ enhance() {
1084
+ // Interaction lives in behaviours.mjs so the shadow wrappers share it.
1085
+ wireCopy(this);
1086
+ }
1087
+ }
1088
+ define("contour-install", ContourInstallFull);
1089
+ class ContourTestimonialFull extends ContourBase {
1090
+ static get observed() { return ["quote", "name", "role"]; }
1091
+ static get properties() { return { quote: { attribute: "quote" }, name: { attribute: "name" }, role: { attribute: "role" } }; }
1092
+ render() {
1093
+ this.classList.add("c-testimonial");
1094
+ const quote = this.getAttribute("quote");
1095
+ if (quote) {
1096
+ const q = this.ensure(".c-testimonial__quote", () => { const el = document.createElement("blockquote"); el.className = "c-testimonial__quote"; return el; });
1097
+ q.textContent = quote;
1098
+ } else {
1099
+ const q = this.querySelector(".c-testimonial__quote");
1100
+ if (q) q.remove();
1101
+ }
1102
+ const name = this.getAttribute("name");
1103
+ const role = this.getAttribute("role");
1104
+ if (name) {
1105
+ const by = this.ensure(".c-testimonial__byline", () => { const el = document.createElement("figcaption"); el.className = "c-testimonial__byline"; return el; });
1106
+ const n = by.querySelector(".c-testimonial__name") || (() => { const el = document.createElement("cite"); el.className = "c-testimonial__name"; by.appendChild(el); return el; })();
1107
+ n.className = "c-testimonial__name";
1108
+ n.textContent = name;
1109
+ if (role) {
1110
+ const r = by.querySelector(".c-testimonial__role") || (() => { const el = document.createElement("span"); el.className = "c-testimonial__role"; by.appendChild(el); return el; })();
1111
+ r.className = "c-testimonial__role";
1112
+ r.textContent = role;
1113
+ } else {
1114
+ const r = by.querySelector(".c-testimonial__role");
1115
+ if (r) r.remove();
1116
+ }
1117
+ } else {
1118
+ const by = this.querySelector(".c-testimonial__byline");
1119
+ if (by) by.remove();
1120
+ }
1121
+ }
1122
+ }
1123
+ define("contour-testimonial", ContourTestimonialFull);
1124
+ class ContourShowcaseFull extends ContourBase {
1125
+ static get observed() { return ["title", "text", "media", "reverse", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "heading", "cache-key", "no-cache"]; }
1126
+ static get properties() { return { title: { attribute: "title" }, text: { attribute: "text" }, media: { attribute: "media" }, reverse: { attribute: "reverse" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
1127
+ render() {
1128
+ this.classList.add("c-showcase");
1129
+ this.setAttribute("role", "list");
1130
+ if (this.hasAttribute("reverse")) this.classList.add("c-showcase--reverse"); else this.classList.remove("c-showcase--reverse");
1131
+ const title = this.getAttribute("title");
1132
+ if (title) this.setAttribute("aria-label", title);
1133
+ else this.removeAttribute("aria-label");
1134
+ this.setAttribute("role", "region");
1135
+ wireStates(this);
1136
+ loadRemote(this, "items");
1137
+ if (renderStates(this, "showcase")) return;
1138
+ const items = remoteData(this, "items");
1139
+ const text = this.getAttribute("text");
1140
+ const media = this.getAttribute("media");
1141
+ if (media) {
1142
+ // A figure with a figcaption is the native shape for an image + caption.
1143
+ const m = this.ensure(".c-showcase__media", () => { const el = document.createElement("figure"); el.className = "c-showcase__media"; return el; });
1144
+ if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(media.trim())) {
1145
+ let img = m.querySelector("img");
1146
+ if (!img) { img = document.createElement("img"); m.appendChild(img); }
1147
+ img.src = media.trim();
1148
+ img.alt = title || "";
1149
+ } else {
1150
+ setHTML(m, sanitizeHtml(media));
1151
+ }
1152
+ if (title) {
1153
+ let cap = m.querySelector(".c-showcase__caption");
1154
+ if (!cap) { cap = document.createElement("figcaption"); cap.className = "c-showcase__caption"; m.appendChild(cap); }
1155
+ cap.textContent = title;
1156
+ }
1157
+ } else {
1158
+ const m = this.querySelector(".c-showcase__media");
1159
+ if (m) m.remove();
1160
+ }
1161
+ if (title) {
1162
+ const t = this.ensure(".c-showcase__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-showcase__title"; return el; });
1163
+ t.textContent = title;
1164
+ } else {
1165
+ const t = this.querySelector(".c-showcase__title");
1166
+ if (t) t.remove();
1167
+ }
1168
+ if (text) {
1169
+ const p = this.ensure(".c-showcase__text", () => { const el = document.createElement("p"); el.className = "c-showcase__text"; return el; });
1170
+ p.textContent = text;
1171
+ } else {
1172
+ const p = this.querySelector(".c-showcase__text");
1173
+ if (p) p.remove();
1174
+ }
1175
+ const ul = this.querySelector(".c-showcase__list");
1176
+ const authored = ul ? Array.from(ul.children).filter((n) => n.tagName === "LI") : [];
1177
+ if (items && !authored.length) {
1178
+ try {
1179
+ const parsed = JSON.parse(items);
1180
+ const l = this.ensure(".c-showcase__list", () => { const el = document.createElement("ul"); el.className = "c-showcase__list"; return el; });
1181
+ l.replaceChildren();
1182
+ parsed.forEach((it) => {
1183
+ const li = document.createElement("li");
1184
+ li.textContent = typeof it === "string" ? it : (it.label || it.title || "");
1185
+ l.appendChild(li);
1186
+ });
1187
+ } catch (e) { warnBadJson(this, "attribute", e); }
1188
+ } else if (!items && !authored.length && !title && !text && !media) {
1189
+ renderEmpty(this, "showcase");
1190
+ } else if (!items && ul) {
1191
+ ul.remove();
1192
+ }
1193
+ }
1194
+ enhance() {
1195
+ if (this._wiredShowcase) return;
1196
+ this._wiredShowcase = true;
1197
+ this.addEventListener("click", (e) => {
1198
+ const media = e.target && e.target.closest ? e.target.closest(".c-showcase__media") : null;
1199
+ if (media && this.contains(media)) {
1200
+ const title = this.getAttribute("title") || "";
1201
+ this.dispatchEvent(new CustomEvent("contour:showcase-activate", { bubbles: true, composed: true, detail: { title } }));
1202
+ }
1203
+ });
1204
+ this.addEventListener("keydown", (e) => {
1205
+ // Authored interactive children own Enter/Space; only act on other targets.
1206
+ const target = e.target && e.target.closest ? e.target.closest("button, a, input, select, textarea, [role='button'], [role='link'], [role='checkbox'], [role='menuitem'], [role='option'], [role='tab']") : null;
1207
+ if (target && this.contains(target)) return;
1208
+ if (e.key === "Enter" || e.key === " ") {
1209
+ const media = this.querySelector(".c-showcase__media");
1210
+ if (media) {
1211
+ e.preventDefault();
1212
+ const title = this.getAttribute("title") || "";
1213
+ this.dispatchEvent(new CustomEvent("contour:showcase-activate", { bubbles: true, composed: true, detail: { title } }));
1214
+ }
1215
+ }
1216
+ });
1217
+ }
1218
+ }
1219
+ define("contour-showcase", ContourShowcaseFull);
1220
+ class ContourPricingFull extends ContourBase {
1221
+ static get observed() { return []; }
1222
+ render() {
1223
+ // `.c-pricing` is the grid; its parts live on `.c-price`. It stays a container.
1224
+ this.classList.add("c-pricing");
1225
+ }
1226
+ }
1227
+ define("contour-pricing", ContourPricingFull);
1228
+ class ContourRecipeFull extends ContourBase {
1229
+ static get observed() { return ["title", "body", "canvas", "heading", "url", "tags", "head", "index"]; }
1230
+ static get properties() { return { title: { attribute: "title" }, body: { attribute: "body" }, canvas: { attribute: "canvas" }, url: { attribute: "url" }, tags: { attribute: "tags" }, head: { attribute: "head" }, index: { attribute: "index" } }; }
1231
+ render() {
1232
+ this.classList.add("c-recipe");
1233
+ // Frame chrome (browser mockup): opt-in via `url` attribute.
1234
+ const url = this.getAttribute("url");
1235
+ let frame = this.querySelector(".c-recipe__frame");
1236
+ if (url) {
1237
+ if (!frame) {
1238
+ frame = document.createElement("div");
1239
+ frame.className = "c-recipe__frame";
1240
+ const bar = document.createElement("div");
1241
+ bar.className = "c-recipe__frame-bar";
1242
+ for (let i = 0; i < 3; i++) { const dot = document.createElement("span"); dot.className = "c-recipe__frame-dot"; bar.appendChild(dot); }
1243
+ const urlEl = document.createElement("span");
1244
+ urlEl.className = "c-recipe__frame-url";
1245
+ bar.appendChild(urlEl);
1246
+ frame.appendChild(bar);
1247
+ this.prepend(frame);
1248
+ }
1249
+ const urlEl = frame.querySelector(".c-recipe__frame-url");
1250
+ if (urlEl) urlEl.textContent = url;
1251
+ } else if (frame) {
1252
+ frame.remove();
1253
+ }
1254
+ // Head (category/eyebrow above title).
1255
+ const head = this.getAttribute("head");
1256
+ if (head) {
1257
+ const h = this.ensure(".c-recipe__head", () => { const el = document.createElement("div"); el.className = "c-recipe__head"; return el; });
1258
+ h.textContent = head;
1259
+ } else {
1260
+ const h = this.querySelector(".c-recipe__head");
1261
+ if (h) h.remove();
1262
+ }
1263
+ const title = this.getAttribute("title");
1264
+ if (title) {
1265
+ const t = this.ensure(".c-recipe__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-recipe__title"; return el; });
1266
+ t.textContent = title;
1267
+ } else {
1268
+ const t = this.querySelector(".c-recipe__title");
1269
+ if (t) t.remove();
1270
+ }
1271
+ // Index (recipe number, e.g. "01").
1272
+ const index = this.getAttribute("index");
1273
+ if (index) {
1274
+ const idx = this.ensure(".c-recipe__index", () => { const el = document.createElement("span"); el.className = "c-recipe__index"; return el; });
1275
+ idx.textContent = index;
1276
+ } else {
1277
+ const idx = this.querySelector(".c-recipe__index");
1278
+ if (idx) idx.remove();
1279
+ }
1280
+ const body = this.getAttribute("body");
1281
+ if (body) {
1282
+ const b = this.ensure(".c-recipe__desc", () => { const el = document.createElement("p"); el.className = "c-recipe__desc"; return el; });
1283
+ b.textContent = body;
1284
+ } else {
1285
+ const b = this.querySelector(".c-recipe__desc");
1286
+ if (b) b.remove();
1287
+ }
1288
+ // Tags (comma-separated list).
1289
+ const tags = this.getAttribute("tags");
1290
+ if (tags) {
1291
+ const t = this.ensure(".c-recipe__tags", () => { const el = document.createElement("div"); el.className = "c-recipe__tags"; return el; });
1292
+ t.innerHTML = "";
1293
+ tags.split(",").map((s) => s.trim()).filter(Boolean).forEach((tag) => {
1294
+ const span = document.createElement("span");
1295
+ span.textContent = tag;
1296
+ t.appendChild(span);
1297
+ });
1298
+ } else {
1299
+ const t = this.querySelector(".c-recipe__tags");
1300
+ if (t) t.remove();
1301
+ }
1302
+ const canvas = this.getAttribute("canvas");
1303
+ if (canvas) {
1304
+ const c = this.ensure(".c-recipe__canvas", () => { const el = document.createElement("div"); el.className = "c-recipe__canvas"; return el; });
1305
+ if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(canvas.trim())) {
1306
+ let img = c.querySelector("img");
1307
+ if (!img) { img = document.createElement("img"); c.appendChild(img); }
1308
+ img.src = canvas.trim();
1309
+ img.alt = "";
1310
+ } else {
1311
+ setHTML(c, sanitizeHtml(canvas));
1312
+ }
1313
+ } else {
1314
+ const c = this.querySelector(".c-recipe__canvas");
1315
+ if (c) c.remove();
1316
+ }
1317
+ }
1318
+ }
1319
+ define("contour-recipe", ContourRecipeFull);
1320
+ class ContourLogosFull extends ContourBase {
1321
+ static get observed() { return []; }
1322
+ render() {
1323
+ this.classList.add("c-logos");
1324
+ // No invented brands — an empty logo wall renders nothing.
1325
+ }
1326
+ }
1327
+ define("contour-logos", ContourLogosFull);
1328
+ class ContourLandingFeaturesFull extends ContourBase {
1329
+ static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
1330
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
1331
+ render() {
1332
+ this.classList.add("c-landing-features");
1333
+ wireStates(this);
1334
+ loadRemote(this, "items");
1335
+ if (renderStates(this, "landing-features")) return;
1336
+ const items = remoteData(this, "items");
1337
+ const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-landing-features__item"));
1338
+ if (items && !authored.length) {
1339
+ try {
1340
+ const parsed = JSON.parse(items);
1341
+ this.querySelectorAll(".c-landing-features__item").forEach((el) => el.remove());
1342
+ parsed.forEach((it) => {
1343
+ const item = document.createElement("div");
1344
+ item.className = "c-landing-features__item";
1345
+ if (it.icon) {
1346
+ const ic = document.createElement("span");
1347
+ ic.className = "c-landing-features__icon";
1348
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1349
+ svg.setAttribute("aria-hidden", "true");
1350
+ const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
1351
+ use.setAttribute("href", "#" + String(it.icon).replace(/[^a-zA-Z0-9_-]/g, ""));
1352
+ svg.appendChild(use);
1353
+ ic.appendChild(svg);
1354
+ item.appendChild(ic);
1355
+ }
1356
+ if (it.title) {
1357
+ const t = document.createElement("span");
1358
+ t.className = "c-landing-features__title";
1359
+ t.textContent = it.title;
1360
+ item.appendChild(t);
1361
+ }
1362
+ if (it.text) {
1363
+ const tx = document.createElement("p");
1364
+ tx.className = "c-landing-features__text";
1365
+ tx.textContent = it.text;
1366
+ item.appendChild(tx);
1367
+ }
1368
+ this.appendChild(item);
1369
+ });
1370
+ } catch (e) { warnBadJson(this, "attribute", e); }
1371
+ } else if (!items && !authored.length) {
1372
+ this.querySelectorAll(".c-landing-features__item").forEach((el) => el.remove());
1373
+ renderEmpty(this, "landing-features");
1374
+ }
1375
+ }
1376
+ }
1377
+ define("contour-landing-features", ContourLandingFeaturesFull);
1378
+ class ContourLandingHeroFull extends ContourBase {
1379
+ static get observed() { return ["actions", "title", "text", "heading", "preview"]; }
1380
+ static get properties() { return { actions: { attribute: "actions" }, title: { attribute: "title" }, text: { attribute: "text" }, preview: { attribute: "preview" } }; }
1381
+ render() {
1382
+ this.classList.add("c-landing-hero");
1383
+ // Preview mockup (product screenshot): opt-in via `preview` attribute.
1384
+ const preview = this.getAttribute("preview");
1385
+ let pv = this.querySelector(".c-landing-hero__preview");
1386
+ if (preview) {
1387
+ if (!pv) {
1388
+ pv = document.createElement("div");
1389
+ pv.className = "c-landing-hero__preview";
1390
+ const bar = document.createElement("div");
1391
+ bar.className = "c-landing-hero__preview-bar";
1392
+ for (let i = 0; i < 3; i++) { const dot = document.createElement("span"); dot.className = "c-landing-hero__preview-dot"; bar.appendChild(dot); }
1393
+ const body = document.createElement("div");
1394
+ body.className = "c-landing-hero__preview-body";
1395
+ pv.appendChild(bar);
1396
+ pv.appendChild(body);
1397
+ this.appendChild(pv);
1398
+ }
1399
+ const body = pv.querySelector(".c-landing-hero__preview-body");
1400
+ if (body) {
1401
+ if (/^https?:\/\/|^\/|^\.\/|\.(png|jpg|jpeg|svg|webp|gif|avif)$/i.test(preview.trim())) {
1402
+ body.innerHTML = "";
1403
+ const img = document.createElement("img");
1404
+ img.src = preview.trim();
1405
+ img.alt = "";
1406
+ body.appendChild(img);
1407
+ } else {
1408
+ setHTML(body, sanitizeHtml(preview));
1409
+ }
1410
+ }
1411
+ } else if (pv) {
1412
+ pv.remove();
1413
+ }
1414
+ const title = this.getAttribute("title");
1415
+ if (title) {
1416
+ const t = this.ensure(".c-landing-hero__title", () => { const el = document.createElement(headingTag(this, "h2")); el.className = "c-landing-hero__title"; return el; });
1417
+ t.textContent = title;
1418
+ }
1419
+ const text = this.getAttribute("text");
1420
+ if (text) {
1421
+ const t = this.ensure(".c-landing-hero__text", () => { const el = document.createElement("p"); el.className = "c-landing-hero__text"; return el; });
1422
+ t.textContent = text;
1423
+ }
1424
+ const actions = this.getAttribute("actions");
1425
+ const a = this.querySelector(".c-landing-hero__actions");
1426
+ const authored = a ? Array.from(a.children) : [];
1427
+ if (actions && !authored.length) {
1428
+ const el = this.ensure(".c-landing-hero__actions", () => { const e = document.createElement("div"); e.className = "c-landing-hero__actions"; return e; });
1429
+ try {
1430
+ const parsed = JSON.parse(actions);
1431
+ if (Array.isArray(parsed)) {
1432
+ el.replaceChildren();
1433
+ parsed.forEach((act) => {
1434
+ const btn = document.createElement(act.href ? "a" : "button");
1435
+ btn.className = "c-btn" + (act.primary ? " c-btn--primary" : "");
1436
+ if (act.href) btn.href = safeHref(act.href);
1437
+ else btn.type = "button";
1438
+ btn.textContent = act.label || act.text || "";
1439
+ el.appendChild(btn);
1440
+ });
1441
+ } else {
1442
+ setHTML(el, sanitizeHtml(actions));
1443
+ }
1444
+ } catch (_) {
1445
+ setHTML(el, sanitizeHtml(actions));
1446
+ }
1447
+ } else if (!actions && a && !authored.length) {
1448
+ a.remove();
1449
+ }
1450
+ }
1451
+ }
1452
+ define("contour-landing-hero", ContourLandingHeroFull);
1453
+ class ContourLinkishFull extends ContourBase {
1454
+ static get observed() { return []; }
1455
+ render() { this.classList.add("c-linkish"); }
1456
+ }
1457
+ define("contour-linkish", ContourLinkishFull);
1458
+ class ContourPriceFull extends ContourBase {
1459
+ static get observed() { return ["value", "format", "locale"]; }
1460
+ static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" } }; }
1461
+ render() {
1462
+ this.classList.add("c-price");
1463
+ const value = this.getAttribute("value");
1464
+ // Format into a generated .c-price__amount span, preserving authored parts.
1465
+ let amount = this.querySelector(".c-price__amount");
1466
+ if (value) {
1467
+ if (!amount) {
1468
+ amount = document.createElement("span");
1469
+ amount.className = "c-price__amount";
1470
+ this.appendChild(amount);
1471
+ }
1472
+ amount.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
1473
+ } else if (amount) {
1474
+ amount.remove();
1475
+ }
1476
+ }
1477
+ }
1478
+ define("contour-price", ContourPriceFull);
1479
+ class ContourProseFull extends ContourBase {
1480
+ static get observed() { return []; }
1481
+ render() { this.classList.add("c-prose"); }
1482
+ }
1483
+ define("contour-prose", ContourProseFull);
1484
+ class ContourPanel extends ContourBase {
1485
+ static get observed() { return ["title", "subtitle", "status", "heading", "collapsible", "collapsed", "flush"]; }
1486
+ static get properties() { return { title: { attribute: "title" }, subtitle: { attribute: "subtitle" }, status: { attribute: "status" }, collapsible: { attribute: "collapsible", type: Boolean }, collapsed: { attribute: "collapsed", type: Boolean }, flush: { attribute: "flush", type: Boolean } }; }
1487
+ render() {
1488
+ this.classList.add("c-panel");
1489
+ if (!this.hasAttribute("role")) this.setAttribute("role", "region");
1490
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Panel");
1491
+ const title = this.getAttribute("title");
1492
+ const subtitle = this.getAttribute("subtitle");
1493
+ const status = this.getAttribute("status");
1494
+ if (title) {
1495
+ const h = this.ensure(".c-panel__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-panel__title"; return el; });
1496
+ if (h.parentNode === this && this.firstChild !== h) this.prepend(h);
1497
+ h.textContent = title;
1498
+ } else {
1499
+ const h = this.querySelector(".c-panel__title");
1500
+ if (h) h.remove();
1501
+ }
1502
+ if (subtitle) {
1503
+ const sub = this.ensure(".c-panel__subtitle", () => { const el = document.createElement("p"); el.className = "c-panel__subtitle"; return el; });
1504
+ sub.textContent = subtitle;
1505
+ } else {
1506
+ const sub = this.querySelector(".c-panel__subtitle");
1507
+ if (sub) sub.remove();
1508
+ }
1509
+ if (status) {
1510
+ const st = this.ensure(".c-panel__status", () => { const el = document.createElement("span"); el.className = "c-panel__status"; return el; });
1511
+ Array.from(st.classList).forEach((c) => { if (c.startsWith("c-panel__status--")) st.classList.remove(c); });
1512
+ if (status === "error" || status === "live") st.classList.add("c-panel__status--" + status);
1513
+ st.textContent = status;
1514
+ } else {
1515
+ const st = this.querySelector(".c-panel__status");
1516
+ if (st) st.remove();
1517
+ }
1518
+ // Collapsible widget chrome (CARTO-inspired): opt-in via `collapsible`.
1519
+ if (this.hasAttribute("collapsible")) {
1520
+ let btn = this.querySelector(".c-panel__collapse");
1521
+ if (!btn) {
1522
+ btn = document.createElement("button");
1523
+ btn.type = "button";
1524
+ btn.className = "c-panel__collapse c-btn c-btn--ghost c-btn--sm";
1525
+ btn.setAttribute("aria-label", labelText(this, "collapse", "Toggle panel"));
1526
+ // R24-134: SVG glyph instead of text arrows.
1527
+ setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-down" /></svg>');
1528
+ this.appendChild(btn);
1529
+ }
1530
+ if (this.hasAttribute("collapsed")) {
1531
+ this.classList.add("c-panel--collapsed");
1532
+ btn.setAttribute("aria-expanded", "false");
1533
+ setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-right" /></svg>');
1534
+ } else {
1535
+ this.classList.remove("c-panel--collapsed");
1536
+ btn.setAttribute("aria-expanded", "true");
1537
+ setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16"><use href="#i-chevron-down" /></svg>');
1538
+ }
1539
+ } else {
1540
+ const btn = this.querySelector(".c-panel__collapse");
1541
+ if (btn) btn.remove();
1542
+ this.classList.remove("c-panel--collapsed");
1543
+ }
1544
+ // Wrap authored content in a body so it picks up the panel's padding.
1545
+ const body = this.ensure(".c-panel__body", () => { const el = document.createElement("div"); el.className = "c-panel__body"; return el; });
1546
+ body.classList.toggle("c-panel__body--flush", this.hasAttribute("flush"));
1547
+ const head = this.querySelector(".c-panel__head");
1548
+ // Exclude the collapse toggle from the body wrap so it stays visible when collapsed.
1549
+ const collapseBtn = this.querySelector(".c-panel__collapse");
1550
+ Array.from(this.childNodes).forEach((n) => {
1551
+ if (n === body || n === head) return;
1552
+ if (n.nodeType === 1 && (n.classList.contains("c-panel__title") || n.classList.contains("c-panel__subtitle") || n.classList.contains("c-panel__status"))) return;
1553
+ if (n === collapseBtn) return;
1554
+ body.appendChild(n);
1555
+ });
1556
+ if (!body.parentNode) this.appendChild(body);
1557
+ // keep head before body
1558
+ if (head && head.parentNode === this && body.parentNode === this && head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_PRECEDING) {
1559
+ this.insertBefore(body, head.nextSibling);
1560
+ }
1561
+ }
1562
+ enhance() {
1563
+ if (this._wiredPanel) return;
1564
+ this._wiredPanel = true;
1565
+ this.addEventListener("click", (e) => {
1566
+ const btn = e.target && e.target.closest ? e.target.closest(".c-panel__collapse") : null;
1567
+ if (!btn || !this.contains(btn)) return;
1568
+ e.preventDefault();
1569
+ this.toggleAttribute("collapsed");
1570
+ this.dispatchEvent(new CustomEvent("contour:collapse", { bubbles: true, composed: true, detail: { collapsed: this.hasAttribute("collapsed") } }));
1571
+ });
1572
+ }
1573
+ }
1574
+ define("contour-panel", ContourPanel);
1575
+ class ContourCta extends ContourBase {
1576
+ static get observed() { return ["title", "text", "actions", "heading"]; }
1577
+ static get properties() { return { title: { attribute: "title" }, text: { attribute: "text" }, actions: { attribute: "actions" } }; }
1578
+ render() {
1579
+ this.classList.add("c-cta");
1580
+ const title = this.getAttribute("title");
1581
+ const text = this.getAttribute("text");
1582
+ if (title) {
1583
+ const t = this.ensure(".c-cta__title", () => { const el = document.createElement(headingTag(this, "h3")); el.className = "c-cta__title"; return el; });
1584
+ t.textContent = title;
1585
+ } else {
1586
+ const t = this.querySelector(".c-cta__title");
1587
+ if (t) t.remove();
1588
+ }
1589
+ if (text) {
1590
+ const p = this.ensure(".c-cta__text", () => { const el = document.createElement("p"); el.className = "c-cta__text"; return el; });
1591
+ p.textContent = text;
1592
+ } else {
1593
+ const p = this.querySelector(".c-cta__text");
1594
+ if (p) p.remove();
1595
+ }
1596
+ const actions = this.getAttribute("actions");
1597
+ // Remove only the generated actions wrap, not authored actions.
1598
+ const prevWrap = this.querySelector(".c-cta__actions");
1599
+ if (prevWrap) prevWrap.remove();
1600
+ if (actions) {
1601
+ try {
1602
+ const parsed = JSON.parse(actions);
1603
+ const wrap = document.createElement("div");
1604
+ wrap.className = "c-cta__actions";
1605
+ // Support {label, href, primary} like landing-hero.
1606
+ let hasPrimary = false;
1607
+ parsed.forEach((a) => {
1608
+ const label = typeof a === "string" ? a : (a.label || a);
1609
+ const href = typeof a === "object" && a ? a.href : null;
1610
+ const primary = typeof a === "object" && a ? a.primary : false;
1611
+ // Single-primary signal: first primary wins, rest are secondary.
1612
+ const isPrimary = primary && !hasPrimary;
1613
+ if (isPrimary) hasPrimary = true;
1614
+ const btn = document.createElement(href ? "a" : "button");
1615
+ btn.className = isPrimary ? "c-btn c-btn--primary" : "c-btn c-btn--ghost";
1616
+ if (href) { btn.href = safeHref(href); btn.setAttribute("role", "button"); }
1617
+ else btn.type = "button";
1618
+ btn.textContent = label;
1619
+ wrap.appendChild(btn);
1620
+ });
1621
+ this.appendChild(wrap);
1622
+ } catch (e) { warnBadJson(this, "attribute", e); }
1623
+ }
1624
+ }
1625
+ }
1626
+ define("contour-cta", ContourCta);
1627
+ class ContourCode extends ContourBase {
1628
+ static get observed() { return ["title", "copyable", "numbered"]; }
1629
+ static get properties() { return { title: { attribute: "title" }, copyable: { attribute: "copyable", type: Boolean }, numbered: { attribute: "numbered", type: Boolean } }; }
1630
+ render() {
1631
+ this.classList.add("c-code");
1632
+ const title = this.getAttribute("title");
1633
+ if (title) {
1634
+ const head = this.ensure(".c-code__head", () => { const el = document.createElement("div"); el.className = "c-code__head"; return el; });
1635
+ if (head.parentNode === this && this.firstChild !== head) this.prepend(head);
1636
+ const t = head.querySelector(".c-code__title") || (() => { const el = document.createElement("div"); el.className = "c-code__title"; head.appendChild(el); return el; })();
1637
+ t.textContent = title;
1638
+ } else {
1639
+ const head = this.querySelector(".c-code__head");
1640
+ if (head) head.remove();
1641
+ const t = this.querySelector(".c-code__title");
1642
+ if (t) t.remove();
1643
+ }
1644
+ if (this.hasAttribute("copyable")) {
1645
+ const head = this.ensure(".c-code__head", () => { const el = document.createElement("div"); el.className = "c-code__head"; return el; });
1646
+ // Copy button into head with c-btn classes + icon + labelText.
1647
+ this.ensure(".c-code__copy", () => {
1648
+ const btn = document.createElement("button");
1649
+ btn.className = "c-btn c-btn--ghost c-btn--sm c-code__copy";
1650
+ btn.type = "button";
1651
+ setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24" width="14" height="14"><use href="#i-copy" /></svg>');
1652
+ btn.setAttribute("aria-label", labelText(this, "copy", "Copy"));
1653
+ head.appendChild(btn);
1654
+ return btn;
1655
+ });
1656
+ } else {
1657
+ const btn = this.querySelector(".c-code__copy");
1658
+ if (btn) btn.remove();
1659
+ }
1660
+ // Wrap authored code text in a pre so it picks up padding.
1661
+ const pre = this.ensure("pre", () => { const el = document.createElement("pre"); return el; });
1662
+ Array.from(this.childNodes).forEach((n) => {
1663
+ if (n === pre || (n.nodeType === 1 && (n.classList.contains("c-code__head") || n.classList.contains("c-code__copy")))) return;
1664
+ pre.appendChild(n);
1665
+ });
1666
+ if (!pre.querySelector("code")) {
1667
+ const code = document.createElement("code");
1668
+ while (pre.firstChild) code.appendChild(pre.firstChild);
1669
+ pre.appendChild(code);
1670
+ }
1671
+ if (pre.parentNode !== this) this.appendChild(pre);
1672
+ // keep head before pre
1673
+ const head = this.querySelector(".c-code__head");
1674
+ if (head && head.parentNode === this && pre.parentNode === this && head.compareDocumentPosition(pre) & Node.DOCUMENT_POSITION_PRECEDING) {
1675
+ this.insertBefore(pre, head.nextSibling);
1676
+ }
1677
+ // Line numbers are applied after wrapping and are idempotent: a flag on the
1678
+ // <code> prevents numbering the same source twice.
1679
+ const numbered = this.hasAttribute("numbered");
1680
+ this.classList.toggle("c-code--numbered", numbered);
1681
+ const codeEl = pre.querySelector("code");
1682
+ if (codeEl) {
1683
+ const split = codeEl.dataset.contourLines === "1";
1684
+ if (numbered && !split) {
1685
+ splitCodeLines(codeEl);
1686
+ codeEl.dataset.contourLines = "1";
1687
+ } else if (!numbered && split) {
1688
+ joinCodeLines(codeEl);
1689
+ delete codeEl.dataset.contourLines;
1690
+ }
1691
+ }
1692
+ }
1693
+ enhance() {
1694
+ // Interaction lives in behaviours.mjs so the shadow wrappers share it.
1695
+ wireCopy(this);
1696
+ }
1697
+ }
1698
+ define("contour-code", ContourCode);
1699
+ class ContourPlate extends ContourBase {
1700
+ static get observed() { return []; }
1701
+ render() { this.classList.add("c-plate"); }
1702
+ }
1703
+ define("contour-plate", ContourPlate);
1704
+ class ContourPullquote extends ContourBase {
1705
+ static get observed() { return ["quote", "name"]; }
1706
+ static get properties() { return { quote: { attribute: "quote" }, name: { attribute: "name" } }; }
1707
+ render() {
1708
+ this.classList.add("c-pullquote");
1709
+ const quote = this.getAttribute("quote");
1710
+ // `.c-pullquote` styles the paragraph and `cite`; there is no `__quote`/`__byline`.
1711
+ if (quote) {
1712
+ // Preserve a generated <cite> (attribution) while updating the quote text.
1713
+ Array.from(this.childNodes).forEach((n) => { if (n.nodeType === 3) n.remove(); });
1714
+ const cite = this.querySelector("cite");
1715
+ this.insertBefore(document.createTextNode(quote), cite);
1716
+ }
1717
+ const name = this.getAttribute("name");
1718
+ if (name) {
1719
+ const by = this.ensure("cite", () => { const el = document.createElement("cite"); this.appendChild(el); return el; });
1720
+ by.textContent = name;
1721
+ } else {
1722
+ const by = this.querySelector("cite");
1723
+ if (by) by.remove();
1724
+ }
1725
+ }
1726
+ }
1727
+ define("contour-pullquote", ContourPullquote);
1728
+ class ContourAnchor extends ContourBase {
1729
+ static get observed() { return ["href", "label"]; }
1730
+ static get properties() { return { href: { attribute: "href" }, label: { attribute: "label" } }; }
1731
+ render() {
1732
+ this.classList.add("c-anchor");
1733
+ const href = this.getAttribute("href");
1734
+ const label = this.getAttribute("label");
1735
+ // Remove only generated anchors; an authored-only link renders nothing.
1736
+ Array.from(this.querySelectorAll("a[data-contour-generated]")).forEach((n) => n.remove());
1737
+ if (href && label) {
1738
+ const a = document.createElement("a");
1739
+ a.dataset.contourGenerated = "";
1740
+ a.href = safeHref(href);
1741
+ a.textContent = label;
1742
+ const ariaLabel = this.getAttribute("aria-label");
1743
+ if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
1744
+ this.appendChild(a);
1745
+ }
1746
+ }
1747
+ }
1748
+ define("contour-anchor", ContourAnchor);
1749
+
1750
+ /**
1751
+ * Geocoder (CARTO-inspired): engine-agnostic search input + result list.
1752
+ * The consumer runs the geocoding service and passes results via `results`
1753
+ * (JSON array of {label, lat, lon}) or `src`. Contour renders the input and
1754
+ * list and emits `contour:search` (query) and `contour:select` (result).
1755
+ * Attributes: `placeholder`, `value`, `results`, `empty`, `loading`, `error`,
1756
+ * `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1757
+ */
1758
+ class ContourGeocoder extends ContourBase {
1759
+ static get observed() { return ["placeholder", "value", "results", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
1760
+ static get properties() { return { placeholder: { attribute: "placeholder" }, value: { attribute: "value" }, results: { attribute: "results" }, src: { attribute: "src" } }; }
1761
+ render() {
1762
+ this.classList.add("c-geocoder");
1763
+ wireStates(this);
1764
+ loadRemote(this, ["results"]);
1765
+ if (renderStates(this, "geocoder")) return;
1766
+ // The input carries `c-input` so it inherits the system control contract.
1767
+ let inp = this.querySelector(".c-geocoder__input");
1768
+ if (!inp) {
1769
+ inp = document.createElement("input");
1770
+ inp.type = "search";
1771
+ inp.className = "c-input c-geocoder__input";
1772
+ if (!inp.hasAttribute("aria-label")) inp.setAttribute("aria-label", this.getAttribute("placeholder") || "Search location");
1773
+ // Combobox contract: the input owns the list and announces the active option.
1774
+ inp.setAttribute("role", "combobox");
1775
+ inp.setAttribute("aria-autocomplete", "list");
1776
+ inp.setAttribute("aria-expanded", "false");
1777
+ this.appendChild(inp);
1778
+ }
1779
+ const ph = this.getAttribute("placeholder");
1780
+ if (ph) inp.setAttribute("placeholder", ph);
1781
+ const val = this.getAttribute("value");
1782
+ if (val !== null && inp.value !== val) inp.value = val;
1783
+ // Results
1784
+ Array.from(this.querySelectorAll(".c-geocoder__result")).forEach((n) => n.remove());
1785
+ Array.from(this.querySelectorAll(".c-geocoder__list")).forEach((n) => n.remove());
1786
+ let results = [];
1787
+ const rAttr = this.getAttribute("results");
1788
+ if (rAttr) { try { results = JSON.parse(rAttr); } catch (e) { results = []; } }
1789
+ const remote = remoteData(this, "results");
1790
+ // remoteData returns a string; parse it so fetched results render.
1791
+ if (typeof remote === "string") {
1792
+ try { const parsed = JSON.parse(remote); if (Array.isArray(parsed)) results = parsed; } catch (e) {}
1793
+ } else if (Array.isArray(remote)) {
1794
+ results = remote;
1795
+ }
1796
+ if (Array.isArray(results) && results.length) {
1797
+ // A rebuilt list has no active option, whatever was active before.
1798
+ this._geocoderIndex = -1;
1799
+ // One list id per host, so aria-controls survives a re-render.
1800
+ if (!this._geocoderListId) this._geocoderListId = contourId("geocoder-list");
1801
+ const list = document.createElement("ul");
1802
+ list.className = "c-geocoder__list";
1803
+ list.id = this._geocoderListId;
1804
+ list.setAttribute("role", "listbox");
1805
+ results.forEach((r, idx) => {
1806
+ const li = document.createElement("li");
1807
+ li.className = "c-geocoder__result";
1808
+ li.id = this._geocoderListId + "-" + idx;
1809
+ li.setAttribute("role", "option");
1810
+ li.setAttribute("aria-selected", "false");
1811
+ li.setAttribute("tabindex", "-1");
1812
+ li.textContent = (typeof r === "object") ? (r.label || r.name || "") : String(r);
1813
+ if (typeof r === "object") {
1814
+ if (r.lat != null) li.dataset.lat = String(r.lat);
1815
+ if (r.lon != null) li.dataset.lon = String(r.lon);
1816
+ }
1817
+ list.appendChild(li);
1818
+ });
1819
+ this.appendChild(list);
1820
+ inp.setAttribute("aria-controls", this._geocoderListId);
1821
+ inp.setAttribute("aria-expanded", "true");
1822
+ } else {
1823
+ inp.removeAttribute("aria-controls");
1824
+ inp.setAttribute("aria-expanded", "false");
1825
+ inp.removeAttribute("aria-activedescendant");
1826
+ this._geocoderIndex = -1;
1827
+ if (!this.hasAttribute("loading") && !this.hasAttribute("error")) {
1828
+ // Suppress the empty state before the user has typed anything.
1829
+ const inp = this.querySelector(".c-geocoder__input");
1830
+ if (inp && inp.value) renderEmpty(this, "geocoder");
1831
+ }
1832
+ }
1833
+ }
1834
+ enhance() {
1835
+ if (this._wiredGeocoder) return;
1836
+ this._wiredGeocoder = true;
1837
+ const inp = this.querySelector(".c-geocoder__input");
1838
+ // Active option index, re-derived from the DOM per event (rule 12). Must be
1839
+ // a number starting at -1: `undefined + 1` is NaN and selects nothing.
1840
+ if (typeof this._geocoderIndex !== "number") this._geocoderIndex = -1;
1841
+ const options = () => Array.from(this.querySelectorAll(".c-geocoder__result"));
1842
+ const active = () => {
1843
+ const opts = options();
1844
+ const i = this._geocoderIndex;
1845
+ return i >= 0 && i < opts.length ? opts[i] : null;
1846
+ };
1847
+ const setActive = (i) => {
1848
+ const opts = options();
1849
+ if (!opts.length) return;
1850
+ const next = Math.max(0, Math.min(opts.length - 1, Number.isFinite(i) ? i : 0));
1851
+ opts.forEach((o, n) => o.setAttribute("aria-selected", n === next ? "true" : "false"));
1852
+ this._geocoderIndex = next;
1853
+ if (inp) {
1854
+ if (next >= 0) inp.setAttribute("aria-activedescendant", opts[next].id);
1855
+ else inp.removeAttribute("aria-activedescendant");
1856
+ }
1857
+ };
1858
+ const clearActive = () => {
1859
+ this._geocoderIndex = -1;
1860
+ options().forEach((o) => o.setAttribute("aria-selected", "false"));
1861
+ if (inp) inp.removeAttribute("aria-activedescendant");
1862
+ };
1863
+ const select = (li) => {
1864
+ if (!li) return;
1865
+ // R24-132: emit numeric lat/lon, not strings.
1866
+ const result = { label: li.textContent.trim(), lat: li.dataset.lat ? Number(li.dataset.lat) : undefined, lon: li.dataset.lon ? Number(li.dataset.lon) : undefined };
1867
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
1868
+ };
1869
+ if (inp) {
1870
+ // Delegate input/keydown on host (rule 12): input is rebuilt every render, so listeners on it are lost.
1871
+ this.addEventListener("input", (e) => {
1872
+ if (e.target !== inp) return;
1873
+ clearActive();
1874
+ if (this._geocoderTimer) clearTimeout(this._geocoderTimer);
1875
+ this._geocoderTimer = setTimeout(() => {
1876
+ this._geocoderTimer = null;
1877
+ if (!this.isConnected) return;
1878
+ this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
1879
+ }, 200);
1880
+ });
1881
+ this.addEventListener("keydown", (e) => {
1882
+ if (e.target !== inp) return;
1883
+ const opts = options();
1884
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
1885
+ if (!opts.length) return;
1886
+ e.preventDefault();
1887
+ const cur = this._geocoderIndex < 0 ? (e.key === "ArrowDown" ? -1 : opts.length) : this._geocoderIndex;
1888
+ setActive(cur + (e.key === "ArrowDown" ? 1 : -1));
1889
+ return;
1890
+ }
1891
+ if (e.key === "Enter") {
1892
+ e.preventDefault();
1893
+ // R24-132: Enter commits the label + closes the list.
1894
+ const li = active();
1895
+ if (li) {
1896
+ select(li);
1897
+ inp.setAttribute("aria-expanded", "false");
1898
+ inp.removeAttribute("aria-controls");
1899
+ clearActive();
1900
+ } else {
1901
+ this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
1902
+ }
1903
+ return;
1904
+ }
1905
+ if (e.key === "Escape") {
1906
+ // R24-132: Escape hides the list (not ARIA-only).
1907
+ if (opts.length && inp.getAttribute("aria-expanded") === "true") {
1908
+ e.preventDefault();
1909
+ clearActive();
1910
+ inp.setAttribute("aria-expanded", "false");
1911
+ inp.removeAttribute("aria-controls");
1912
+ // Actually hide the list from the DOM.
1913
+ const list = this.querySelector(".c-geocoder__list");
1914
+ if (list) list.remove();
1915
+ }
1916
+ }
1917
+ });
1918
+ }
1919
+ this.addEventListener("click", (e) => {
1920
+ const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
1921
+ if (!li || !this.contains(li)) return;
1922
+ select(li);
1923
+ });
1924
+ this.addEventListener("keydown", (e) => {
1925
+ const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
1926
+ if (!li || !this.contains(li)) return;
1927
+ if (e.key === "Enter" || e.key === " ") {
1928
+ e.preventDefault();
1929
+ select(li);
1930
+ }
1931
+ });
1932
+ }
1933
+ disconnectedCallback() {
1934
+ // A pending debounce must not outlive its host (F-RO10).
1935
+ if (this._geocoderTimer) { clearTimeout(this._geocoderTimer); this._geocoderTimer = null; }
1936
+ super.disconnectedCallback();
1937
+ }
1938
+ }
1939
+ define("contour-geocoder", ContourGeocoder);