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,735 @@
1
+ import { setHTML, ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag, navKey, safeHref, cssLength , warnBadJson, labelText, applyLabel, wcEmitOverlay } from './core.mjs';
2
+ import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
3
+ import { wireMenu, wirePagination, wireTabs, wireTree, wireRemovable } from './behaviours.mjs';
4
+
5
+ class ContourMenu extends ContourBase {
6
+ static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
7
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
8
+ render() {
9
+ this.classList.add("c-menu");
10
+ if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
11
+ wireStates(this);
12
+ loadRemote(this, "items");
13
+ if (renderStates(this, "menu")) return;
14
+ const items = remoteData(this, "items");
15
+ // Slot composition wins over JSON attribute: authored items used as-is; JSON fills gaps only.
16
+ const authoredItems = Array.from(this.querySelectorAll("li[role='menuitem'], li.c-menu__item, [role='menuitem']"));
17
+ const authoredUl = this.querySelector("ul.c-menu");
18
+ if (authoredItems.length) {
19
+ // Ensure authored items are inside a ul.c-menu wrapper.
20
+ if (!authoredUl) {
21
+ const ul = document.createElement("ul");
22
+ ul.className = "c-menu";
23
+ ul.setAttribute("role", "menu");
24
+ // Re-parent authored items into the wrapper, preserving order.
25
+ for (const item of authoredItems) {
26
+ if (item.parentElement === this) ul.appendChild(item);
27
+ }
28
+ this.appendChild(ul);
29
+ } else {
30
+ // Ensure classes/roles on authored items inside existing wrapper.
31
+ for (const item of authoredItems) {
32
+ if (!item.classList.contains("c-menu__item")) item.classList.add("c-menu__item");
33
+ if (!item.getAttribute("role")) item.setAttribute("role", "menuitem");
34
+ if (!item.hasAttribute("tabindex")) item.setAttribute("tabindex", "-1");
35
+ }
36
+ }
37
+ // Set first enabled item to tabindex 0 for roving focus.
38
+ const first = authoredItems.find((it) => it.getAttribute("aria-disabled") !== "true");
39
+ if (first) first.setAttribute("tabindex", "0");
40
+ this.classList.remove("c-menu");
41
+ if (authoredUl) authoredUl.classList.add("c-menu");
42
+ return;
43
+ }
44
+ if (authoredUl) {
45
+ // Authored ul.c-menu exists but no items yet: keep it, don't generate.
46
+ return;
47
+ }
48
+ if (items) {
49
+ try {
50
+ const parsed = JSON.parse(items);
51
+ const ul = this.ensure("ul.c-menu", () => { const el = document.createElement("ul"); el.className = "c-menu"; el.setAttribute("role", "menu"); return el; });
52
+ ul.innerHTML = "";
53
+ ul.setAttribute("role", "menu");
54
+ parsed.forEach((item) => {
55
+ if (item === "---" || item === "separator") {
56
+ const li = document.createElement("li");
57
+ li.className = "c-menu__separator";
58
+ li.setAttribute("role", "separator");
59
+ ul.appendChild(li);
60
+ } else if (typeof item === "string") {
61
+ const li = document.createElement("li");
62
+ li.className = "c-menu__item";
63
+ li.setAttribute("role", "menuitem");
64
+ li.textContent = item;
65
+ ul.appendChild(li);
66
+ } else if (item.group) {
67
+ const li = document.createElement("li");
68
+ li.className = "c-menu__group";
69
+ li.setAttribute("role", "group");
70
+ if (item.group) li.setAttribute("aria-label", String(item.group));
71
+ const hdr = document.createElement("div");
72
+ hdr.className = "c-menu__group-label";
73
+ hdr.textContent = String(item.group);
74
+ li.appendChild(hdr);
75
+ if (Array.isArray(item.items)) {
76
+ const sub = document.createElement("ul");
77
+ sub.className = "c-menu";
78
+ sub.setAttribute("role", "menu");
79
+ item.items.forEach((subItem) => {
80
+ const sli = document.createElement("li");
81
+ sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
82
+ sli.setAttribute("role", "menuitem");
83
+ if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
84
+ if (subItem.label || subItem.title) {
85
+ const lbl = document.createElement("span");
86
+ lbl.className = "c-menu__label";
87
+ lbl.textContent = subItem.label || subItem.title || "";
88
+ sli.appendChild(lbl);
89
+ }
90
+ sub.appendChild(sli);
91
+ });
92
+ li.appendChild(sub);
93
+ }
94
+ ul.appendChild(li);
95
+ } else {
96
+ const li = document.createElement("li");
97
+ li.className = "c-menu__item" + (item.danger ? " c-menu__item--danger" : "") + (item.disabled ? " c-menu__item--disabled" : "");
98
+ // A checkbox/radio item carries its state, not just a label.
99
+ const role = item.type === "checkbox" ? "menuitemcheckbox" : item.type === "radio" ? "menuitemradio" : "menuitem";
100
+ li.setAttribute("role", role);
101
+ if (item.type === "checkbox" || item.type === "radio") li.setAttribute("aria-checked", String(!!item.checked));
102
+ if (item.disabled) li.setAttribute("aria-disabled", "true");
103
+ if (item.items && Array.isArray(item.items)) {
104
+ li.setAttribute("aria-haspopup", "menu");
105
+ li.setAttribute("aria-expanded", "false");
106
+ }
107
+ if (item.label || item.title) {
108
+ const lbl = document.createElement("span");
109
+ lbl.className = "c-menu__label";
110
+ lbl.textContent = item.label || item.title || "";
111
+ li.appendChild(lbl);
112
+ }
113
+ if (item.shortcut) {
114
+ const sc = document.createElement("span");
115
+ sc.className = "c-menu__shortcut";
116
+ sc.textContent = item.shortcut;
117
+ li.appendChild(sc);
118
+ }
119
+ // Build nested submenu for haspopup: without it the item advertises a menu that opens onto nothing.
120
+ if (item.items && Array.isArray(item.items)) {
121
+ const sub = document.createElement("ul");
122
+ sub.className = "c-menu";
123
+ sub.setAttribute("role", "menu");
124
+ item.items.forEach((subItem) => {
125
+ const sli = document.createElement("li");
126
+ sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
127
+ sli.setAttribute("role", "menuitem");
128
+ if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
129
+ if (subItem.label || subItem.title) {
130
+ const sl = document.createElement("span");
131
+ sl.className = "c-menu__label";
132
+ sl.textContent = subItem.label || subItem.title || "";
133
+ sli.appendChild(sl);
134
+ }
135
+ sub.appendChild(sli);
136
+ });
137
+ li.appendChild(sub);
138
+ }
139
+ ul.appendChild(li);
140
+ }
141
+ });
142
+ if (ul.parentNode !== this) this.appendChild(ul);
143
+ this.classList.remove("c-menu");
144
+ ul.classList.add("c-menu");
145
+ } catch (e) { warnBadJson(this, "attribute", e); }
146
+ } else {
147
+ renderEmpty(this, "menu");
148
+ }
149
+ }
150
+ enhance() {
151
+ wireMenu(this);
152
+ }
153
+ }
154
+ define("contour-menu", ContourMenu);
155
+ class ContourTabs extends ContourBase {
156
+ static get observed() { return ["tabs", "items", "autoplay", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "orientation", "closable", "cache-key", "no-cache"]; }
157
+ static get properties() { return { tabs: { attribute: "tabs" }, autoplay: { attribute: "autoplay", type: Number }, pause: { attribute: "pause", type: Boolean }, src: { attribute: "src" }, orientation: { attribute: "orientation" }, closable: { attribute: "closable", type: Boolean } }; }
158
+ render() {
159
+ this.classList.add("c-tabs");
160
+ wireStates(this);
161
+ loadRemote(this, "tabs");
162
+ if (renderStates(this, "tabs")) return;
163
+ // `items` is the attribute the guide's counterpart markup uses (same name CSS block reads); `tabs` is legacy. Accept both so documented markup works.
164
+ const tabs = remoteData(this, "tabs") || remoteData(this, "items") || this.getAttribute("tabs") || this.getAttribute("items");
165
+ // Slot composition wins over JSON attribute (same as ContourMenu): authored tabs/panels used as-is; JSON fills gaps only.
166
+ const authoredTabs = Array.from(this.querySelectorAll("[role='tab']"));
167
+ const authoredList = this.querySelector(".c-tabs__list");
168
+ const authoredPanels = Array.from(this.querySelectorAll(".c-tabs__panel"));
169
+
170
+ if (authoredTabs.length) {
171
+ // Ensure authored tabs are inside a .c-tabs__list wrapper.
172
+ if (!authoredList) {
173
+ const list = document.createElement("div");
174
+ list.className = "c-tabs__list";
175
+ list.setAttribute("role", "tablist");
176
+ const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
177
+ list.setAttribute("aria-orientation", orientation);
178
+ if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
179
+ for (const tab of authoredTabs) {
180
+ if (tab.parentElement === this) list.appendChild(tab);
181
+ }
182
+ this.prepend(list);
183
+ }
184
+ // Normalise attributes on authored tabs and link panels.
185
+ const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
186
+ if (authoredList) authoredList.setAttribute("aria-orientation", orientation);
187
+ if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
188
+
189
+ const authoredIndex = authoredTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
190
+ authoredTabs.forEach((tab, i) => {
191
+ if (!tab.classList.contains("c-tabs__tab")) tab.classList.add("c-tabs__tab");
192
+ if (!tab.getAttribute("role")) tab.setAttribute("role", "tab");
193
+ let panelId = tab.getAttribute("aria-controls");
194
+ if (!panelId) {
195
+ // Only generate a panel if there's authored content to pair with. Empty generated panel is worse — screen reader announces "blank".
196
+ const authoredPanel = authoredPanels[i];
197
+ if (authoredPanel) {
198
+ panelId = authoredPanel.id || contourId("c-tabs-panel");
199
+ authoredPanel.id = panelId;
200
+ tab.setAttribute("aria-controls", panelId);
201
+ }
202
+ } else {
203
+ // Tab has aria-controls: ensure the panel exists and is linked.
204
+ let panel = authoredPanels.find((p) => p.id === panelId);
205
+ if (!panel) {
206
+ panel = document.createElement("div");
207
+ panel.className = "c-tabs__panel";
208
+ panel.id = panelId;
209
+ panel.setAttribute("role", "tabpanel");
210
+ this.appendChild(panel);
211
+ }
212
+ }
213
+ const selected = authoredIndex >= 0 ? i === authoredIndex : i === 0;
214
+ tab.setAttribute("aria-selected", String(selected));
215
+ tab.tabIndex = selected ? 0 : -1;
216
+ const ctrl = tab.getAttribute("aria-controls");
217
+ const panel = ctrl ? document.getElementById(ctrl) : null;
218
+ if (panel) panel.hidden = !selected;
219
+ });
220
+ return;
221
+ }
222
+
223
+ if (tabs && !authoredTabs.length) {
224
+ try {
225
+ const parsed = JSON.parse(tabs);
226
+ const list = this.ensure(".c-tabs__list", () => { const el = document.createElement("div"); el.className = "c-tabs__list"; el.setAttribute("role", "tablist"); return el; });
227
+ list.setAttribute("role", "tablist");
228
+ const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
229
+ list.setAttribute("aria-orientation", orientation);
230
+ if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
231
+ // Preserve the selected tab across rebuilds (G-31): read the
232
+ // pre-drop selection before clearing, then re-apply it.
233
+ const _prevTabs = Array.from(list.querySelectorAll("[role='tab']"));
234
+ const _prevSel = _prevTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
235
+ const _keepIdx = _prevSel >= 0 ? _prevSel : 0;
236
+ list.innerHTML = "";
237
+ // Remove any previously generated panels so re-render doesn't stack.
238
+ Array.from(this.querySelectorAll(".c-tabs__panel")).forEach((n) => n.remove());
239
+ parsed.forEach((t, i) => {
240
+ const label = typeof t === "string" ? t : (t.label || t.title || "");
241
+ const panelId = contourId("c-tabs-panel");
242
+ // A tab is not a <button> when closable: HTML forbids interactive content inside a button, so close control would be invalid markup and unreachable.
243
+ const btn = document.createElement(this.hasAttribute("closable") ? "div" : "button");
244
+ btn.className = "c-tabs__tab";
245
+ if (btn.tagName === "BUTTON") btn.type = "button";
246
+ btn.setAttribute("role", "tab");
247
+ btn.setAttribute("aria-selected", String(i === _keepIdx));
248
+ btn.setAttribute("aria-controls", panelId);
249
+ btn.tabIndex = i === _keepIdx ? 0 : -1;
250
+ const tabLabel = document.createElement("span");
251
+ tabLabel.textContent = label;
252
+ btn.textContent = "";
253
+ btn.appendChild(tabLabel);
254
+ if (this.hasAttribute("closable")) {
255
+ const closeBtn = document.createElement("button");
256
+ closeBtn.type = "button";
257
+ closeBtn.className = "c-tabs__close";
258
+ closeBtn.setAttribute("aria-label", labelText(this, "close", "Close") + " " + label);
259
+ closeBtn.textContent = "×";
260
+ closeBtn.addEventListener("click", (e) => {
261
+ e.stopPropagation();
262
+ const idx = Array.from(list.querySelectorAll("[role='tab']")).indexOf(btn);
263
+ // remove tab + panel
264
+ const ctrl = btn.getAttribute("aria-controls");
265
+ const panel = ctrl ? document.getElementById(ctrl) : null;
266
+ btn.remove();
267
+ if (panel) panel.remove();
268
+ this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true, detail: { index: idx, label } }));
269
+ // activate first remaining tab
270
+ const remaining = list.querySelectorAll("[role='tab']");
271
+ if (remaining.length) remaining[0].click();
272
+ });
273
+ btn.appendChild(closeBtn);
274
+ }
275
+ list.appendChild(btn);
276
+ const panel = document.createElement("div");
277
+ panel.className = "c-tabs__panel";
278
+ panel.id = panelId;
279
+ panel.setAttribute("role", "tabpanel");
280
+ if (typeof t === "object" && t !== null && t.content !== undefined) {
281
+ panel.textContent = String(t.content);
282
+ }
283
+ if (i !== _keepIdx) panel.hidden = true;
284
+ this.appendChild(panel);
285
+ });
286
+ if (list.parentNode !== this) this.prepend(list);
287
+ } catch (e) { warnBadJson(this, "attribute", e); }
288
+ } else if (!tabs && !authoredTabs.length) {
289
+ const list = this.querySelector(".c-tabs__list");
290
+ if (list) list.remove();
291
+ renderEmpty(this, "tabs");
292
+ }
293
+ }
294
+ enhance() {
295
+ wireTabs(this);
296
+ // Tabs autoplay mirrors streaming chart's interval contract (data.mjs): autoplay advances, pause stops, timer owned once, gated on reduced motion. Advance is a click on next tab, so wireTabs' listener handles activation and emits contour:tab-change. Hover/focus also stop loop (WCAG 2.2.2).
297
+ const sync = () => {
298
+ const seconds = parseFloat(this.getAttribute("autoplay") || "");
299
+ const paused = this.hasAttribute("pause") || this._tabsHover || this._tabsFocus;
300
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
301
+ const want = Number.isFinite(seconds) && seconds > 0 && !paused && !reduced;
302
+ if (want === this._tabsAutoplayRunning) return;
303
+ this._tabsAutoplayRunning = want;
304
+ if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; }
305
+ if (!want) return;
306
+ this._tabsTimer = setInterval(() => {
307
+ if (!this.isConnected || this.hasAttribute("pause") || this._tabsHover || this._tabsFocus) return;
308
+ const list = this.querySelector(".c-tabs__list");
309
+ const tabs = list ? Array.from(list.querySelectorAll("[role='tab']")) : [];
310
+ if (!tabs.length) return;
311
+ const cur = tabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
312
+ const next = tabs[(cur + 1) % tabs.length];
313
+ if (next) next.click();
314
+ }, Math.max(1000, seconds * 1000));
315
+ };
316
+ // Re-run on every render so autoplay/pause attribute changes are picked up; listeners and disposer installed once.
317
+ sync();
318
+ if (this._wiredTabsAutoplay) return;
319
+ this._wiredTabsAutoplay = true;
320
+ this.addEventListener("pointerenter", () => { this._tabsHover = true; sync(); });
321
+ this.addEventListener("pointerleave", () => { this._tabsHover = false; sync(); });
322
+ this.addEventListener("focusin", () => { this._tabsFocus = true; sync(); });
323
+ this.addEventListener("focusout", () => { this._tabsFocus = false; sync(); });
324
+ onDispose(this, () => { if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; } });
325
+ }
326
+ }
327
+ define("contour-tabs", ContourTabs);
328
+ class ContourCodeTabs extends ContourBase {
329
+ static get observed() { return ["tabs", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "cache-key", "no-cache"]; }
330
+ static get properties() { return { tabs: { attribute: "tabs" }, src: { attribute: "src" } }; }
331
+ render() {
332
+ this.classList.add("c-code-tabs");
333
+ wireStates(this);
334
+ loadRemote(this, "tabs");
335
+ if (renderStates(this, "code-tabs")) return;
336
+ const tabs = remoteData(this, "tabs");
337
+ const list = this.querySelector(".c-code-tabs__list");
338
+ const authored = list ? Array.from(list.children).filter((n) => n.getAttribute && n.getAttribute("role") === "tab") : [];
339
+ if (tabs && !authored.length) {
340
+ try {
341
+ const parsed = JSON.parse(tabs);
342
+ const l = this.ensure(".c-code-tabs__list", () => { const el = document.createElement("div"); el.className = "c-code-tabs__list"; el.setAttribute("role", "tablist"); return el; });
343
+ l.setAttribute("role", "tablist");
344
+ const _prevCodeTabs = Array.from(l.querySelectorAll("[role='tab']"));
345
+ const _prevCodeSel = _prevCodeTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
346
+ const _keepCodeIdx = _prevCodeSel >= 0 ? _prevCodeSel : 0;
347
+ l.innerHTML = "";
348
+ Array.from(this.querySelectorAll(".c-code-tabs__panel")).forEach((n) => n.remove());
349
+ parsed.forEach((t, i) => {
350
+ const label = typeof t === "string" ? t : (t.label || t.title || "");
351
+ const panelId = contourId("c-code-tabs-panel");
352
+ const btn = document.createElement("button");
353
+ btn.className = "c-code-tabs__tab";
354
+ btn.type = "button";
355
+ btn.setAttribute("role", "tab");
356
+ btn.setAttribute("aria-selected", String(i === _keepCodeIdx));
357
+ btn.setAttribute("aria-controls", panelId);
358
+ btn.tabIndex = i === _keepCodeIdx ? 0 : -1;
359
+ btn.textContent = label;
360
+ l.appendChild(btn);
361
+ const panel = document.createElement("div");
362
+ panel.className = "c-code-tabs__panel";
363
+ panel.id = panelId;
364
+ panel.setAttribute("role", "tabpanel");
365
+ if (typeof t === "object" && t !== null && t.content !== undefined) {
366
+ // Use <pre><code> for code panels.
367
+ const pre = document.createElement("pre");
368
+ const code = document.createElement("code");
369
+ code.textContent = String(t.content);
370
+ pre.appendChild(code);
371
+ panel.appendChild(pre);
372
+ // Copy button.
373
+ const copyBtn = document.createElement("button");
374
+ copyBtn.className = "c-btn c-btn--ghost c-btn--sm c-code-tabs__copy";
375
+ copyBtn.type = "button";
376
+ copyBtn.textContent = labelText(this, "copy", "Copy");
377
+ copyBtn.setAttribute("aria-label", labelText(this, "copy-code", "Copy code"));
378
+ copyBtn.dataset.copy = String(t.content);
379
+ panel.appendChild(copyBtn);
380
+ }
381
+ if (i !== _keepCodeIdx) panel.hidden = true;
382
+ this.appendChild(panel);
383
+ });
384
+ if (l.parentNode !== this) this.prepend(l);
385
+ } catch (e) { warnBadJson(this, "attribute", e); }
386
+ } else if (!tabs && list) {
387
+ list.remove();
388
+ renderEmpty(this, "code-tabs");
389
+ } else if (!tabs && !list) {
390
+ renderEmpty(this, "code-tabs");
391
+ }
392
+ }
393
+ enhance() {
394
+ wireTabs(this);
395
+ // R24-42: copy button handler.
396
+ if (!this._wiredCodeTabs) {
397
+ this._wiredCodeTabs = true;
398
+ this.addEventListener("click", (e) => {
399
+ const btn = e.target && e.target.closest ? e.target.closest(".c-code-tabs__copy") : null;
400
+ if (!btn || !this.contains(btn)) return;
401
+ const text = btn.dataset.copy || "";
402
+ if (text) {
403
+ try { navigator.clipboard.writeText(text); btn.textContent = labelText(this, "copied", "Copied!"); setTimeout(() => { btn.textContent = labelText(this, "copy", "Copy"); }, 2000); } catch (err) {}
404
+ }
405
+ });
406
+ }
407
+ }
408
+ }
409
+ define("contour-code-tabs", ContourCodeTabs);
410
+ class ContourBreadcrumb extends ContourBase {
411
+ static get observed() { return ["items", "separator", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
412
+ static get properties() { return { items: { attribute: "items" }, separator: { attribute: "separator" }, max: { attribute: "max", type: Number }, src: { attribute: "src" } } };
413
+ render() {
414
+ this.classList.add("c-breadcrumb");
415
+ if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
416
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb"));
417
+ wireStates(this);
418
+ loadRemote(this, "items");
419
+ if (renderStates(this, "breadcrumb")) return;
420
+ const items = remoteData(this, "items");
421
+ // Slot composition: authored <li> items win over the JSON attribute.
422
+ const nav = this.querySelector("nav");
423
+ const ol = nav ? nav.querySelector("ol") : null;
424
+ const authored = ol ? Array.from(ol.children).filter((n) => n.tagName === "LI") : [];
425
+ if (items && !authored.length) {
426
+ try {
427
+ const parsed = JSON.parse(items);
428
+ const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb")); return el; });
429
+ n.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb"));
430
+ // A unique id per instance: two breadcrumbs on a page must not share
431
+ // one, and the overflow button points at this one through aria-controls.
432
+ if (!n.id) n.id = contourId("contour-breadcrumb-list");
433
+ n.innerHTML = "";
434
+ // Items are an ordered list so screen readers announce position.
435
+ const ol = document.createElement("ol");
436
+ ol.className = "c-breadcrumb__list";
437
+ n.appendChild(ol);
438
+ const sep = this.getAttribute("separator") || "/";
439
+ const max = this._overflowExpanded ? null : this.max;
440
+ const shown = Number.isFinite(max) && max > 1 && parsed.length > max
441
+ ? parsed.slice(-max)
442
+ : parsed;
443
+ if (Number.isFinite(max) && max > 1 && parsed.length > max) {
444
+ const btn = document.createElement("button");
445
+ btn.type = "button";
446
+ btn.className = "c-breadcrumb__overflow";
447
+ btn.setAttribute("aria-label", `Show ${parsed.length - shown.length + 1} more items`);
448
+ btn.setAttribute("aria-expanded", "false");
449
+ btn.setAttribute("aria-controls", n.id);
450
+ btn.textContent = "…";
451
+ btn.addEventListener("click", () => {
452
+ // Handler-owned flag outside OBSERVED to avoid re-entering render.
453
+ this._overflowExpanded = true;
454
+ this.requestRender();
455
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { expanded: true } }));
456
+ });
457
+ const li = document.createElement("li");
458
+ li.appendChild(btn);
459
+ ol.appendChild(li);
460
+ }
461
+ shown.forEach((item, i) => {
462
+ const li = document.createElement("li");
463
+ if (i < shown.length - 1) {
464
+ const a = document.createElement("a");
465
+ a.href = safeHref(item.href || "#");
466
+ a.textContent = item.label || item;
467
+ li.appendChild(a);
468
+ const s = document.createElement("span");
469
+ s.className = "c-breadcrumb__sep";
470
+ s.setAttribute("aria-hidden", "true");
471
+ s.textContent = sep;
472
+ li.appendChild(s);
473
+ } else {
474
+ const span = document.createElement("span");
475
+ span.textContent = item.label || item;
476
+ span.setAttribute("aria-current", "page");
477
+ li.appendChild(span);
478
+ }
479
+ ol.appendChild(li);
480
+ });
481
+ } catch (e) { warnBadJson(this, "attribute", e); }
482
+ } else if (!items && nav) {
483
+ nav.remove();
484
+ } else if (!items && !nav) {
485
+ renderEmpty(this, "breadcrumb");
486
+ }
487
+ }
488
+ }
489
+ define("contour-breadcrumb", ContourBreadcrumb);
490
+ class ContourPagination extends ContourBase {
491
+ static get observed() { return ["pages", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "cache-key", "no-cache"]; }
492
+ static get properties() { return { pages: { attribute: "pages" }, current: { attribute: "current" }, src: { attribute: "src" } }; }
493
+ render() {
494
+ this.classList.add("c-pagination");
495
+ // Pagination is a navigation landmark: APG names it; screen reader's landmark list is where readers look for "page N of M".
496
+ if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
497
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "pagination", "Pagination"));
498
+ wireStates(this);
499
+ loadRemote(this, "pages");
500
+ if (renderStates(this, "pagination")) return;
501
+ const pages = remoteData(this, "pages");
502
+ // Drop previously generated links so a re-render cannot stack a second set.
503
+ Array.from(this.querySelectorAll(".c-pagination__link")).forEach((n) => n.remove());
504
+ let currentAttr = this.getAttribute("current") || "1";
505
+ if (this.getAttribute("persist") === "storage" && this.id) {
506
+ try { const stored = localStorage.getItem("contour-pagination:" + this.id); if (stored !== null) currentAttr = stored; } catch (e) {}
507
+ } else if (this.getAttribute("persist") === "url") {
508
+ try { const v = new URLSearchParams(window.location.search).get("c-pagination"); if (v !== null) currentAttr = v; } catch (e) {}
509
+ }
510
+ const current = parseInt(currentAttr, "10") || 1;
511
+ // Publish current page as `page` attribute so state is readable without a click (activate handler sets it on navigation).
512
+ this.setAttribute("page", String(current));
513
+ if (pages) {
514
+ let count = parseInt(pages, 10);
515
+ if (!Number.isFinite(count) || count < 1) {
516
+ try { const p = JSON.parse(pages); if (Array.isArray(p)) count = p.length; } catch (e) {}
517
+ }
518
+ // Prev button.
519
+ const prev = document.createElement("button");
520
+ prev.type = "button";
521
+ prev.className = "c-pagination__link c-pagination__prev";
522
+ prev.setAttribute("data-action", "prev");
523
+ setHTML(prev, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-left" /></svg>');
524
+ prev.setAttribute("aria-label", labelText(this, "prev", "Previous page"));
525
+ // Disable prev at page 1.
526
+ if (current <= 1) prev.setAttribute("disabled", "");
527
+ this.appendChild(prev);
528
+ // Ellipsis windowing: show first, last, current±1, with ellipsis for gaps. Keeps button count bounded for large page counts (60 pages → ~7 buttons).
529
+ const window = new Set([1, count, current]);
530
+ if (current > 1) window.add(current - 1);
531
+ if (current < count) window.add(current + 1);
532
+ const sorted = [...window].filter(p => p >= 1 && p <= count).sort((a, b) => a - b);
533
+ let prevPage = 0;
534
+ for (const i of sorted) {
535
+ if (prevPage && i - prevPage > 1) {
536
+ const gap = document.createElement("span");
537
+ gap.className = "c-pagination__ellipsis";
538
+ gap.textContent = "…";
539
+ gap.setAttribute("aria-hidden", "true");
540
+ this.appendChild(gap);
541
+ }
542
+ const btn = document.createElement("button");
543
+ btn.type = "button";
544
+ btn.className = "c-pagination__link";
545
+ btn.textContent = String(i);
546
+ if (i === current) {
547
+ btn.setAttribute("aria-current", "page");
548
+ }
549
+ this.appendChild(btn);
550
+ prevPage = i;
551
+ }
552
+ // Next button.
553
+ const next = document.createElement("button");
554
+ next.type = "button";
555
+ next.className = "c-pagination__link c-pagination__next";
556
+ next.setAttribute("data-action", "next");
557
+ setHTML(next, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
558
+ next.setAttribute("aria-label", labelText(this, "next", "Next page"));
559
+ // Disable next on last page.
560
+ if (current >= count) next.setAttribute("disabled", "");
561
+ this.appendChild(next);
562
+ } else {
563
+ renderEmpty(this, "pagination");
564
+ }
565
+ }
566
+ enhance() {
567
+ wirePagination(this);
568
+ }
569
+ }
570
+ define("contour-pagination", ContourPagination);
571
+ class ContourPagerFull extends ContourBase {
572
+ static get observed() { return ["prev", "next"]; }
573
+ static get properties() { return { prev: { attribute: "prev" }, next: { attribute: "next" } }; }
574
+ render() {
575
+ this.classList.add("c-pager");
576
+ // Pager is a navigation landmark like pagination: screen reader's landmark list is where readers look for prev/next.
577
+ if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
578
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "pagination", "Pagination"));
579
+ // Drop previously generated links so a re-render cannot stack a second set.
580
+ Array.from(this.querySelectorAll(".c-pager__link")).forEach((n) => n.remove());
581
+ const prev = this.getAttribute("prev");
582
+ const next = this.getAttribute("next");
583
+ if (prev) {
584
+ const a = document.createElement("a");
585
+ a.className = "c-pager__link";
586
+ a.href = safeHref(prev.split("|")[1] || "#");
587
+ const dir = document.createElement("span");
588
+ dir.className = "c-pager__dir";
589
+ dir.textContent = labelText(this, "previous", "← Previous");
590
+ a.appendChild(dir);
591
+ const title = document.createElement("span");
592
+ title.className = "c-pager__title";
593
+ title.textContent = prev.split("|")[0];
594
+ a.appendChild(title);
595
+ this.appendChild(a);
596
+ }
597
+ if (next) {
598
+ const a = document.createElement("a");
599
+ a.className = "c-pager__link c-pager__link--next";
600
+ a.href = safeHref(next.split("|")[1] || "#");
601
+ const dir = document.createElement("span");
602
+ dir.className = "c-pager__dir";
603
+ dir.textContent = labelText(this, "next", "Next") + " →";
604
+ a.appendChild(dir);
605
+ const title = document.createElement("span");
606
+ title.className = "c-pager__title";
607
+ title.textContent = next.split("|")[0];
608
+ a.appendChild(title);
609
+ this.appendChild(a);
610
+ }
611
+ }
612
+ }
613
+ define("contour-pager", ContourPagerFull);
614
+ class ContourTocFull extends ContourBase {
615
+ static get observed() { return ["title", "items", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "empty", "no-cache"]; }
616
+ static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
617
+ render() {
618
+ this.classList.add("c-toc");
619
+ this.setAttribute("role", "group");
620
+ wireStates(this);
621
+ loadRemote(this, "items");
622
+ if (renderStates(this, "toc")) return;
623
+ const items = remoteData(this, "items");
624
+ const title = this.getAttribute("title") || "On this page";
625
+ const titleEl = this.ensure(".c-toc__title", () => { const el = document.createElement("div"); el.className = "c-toc__title"; return el; });
626
+ titleEl.textContent = title;
627
+ const list = this.querySelector(".c-toc__list");
628
+ const authored = list ? Array.from(list.children).filter((n) => n.tagName === "A") : [];
629
+ if (items && !authored.length) {
630
+ try {
631
+ const parsed = JSON.parse(items);
632
+ const l = this.ensure(".c-toc__list", () => { const el = document.createElement("nav"); el.className = "c-toc__list"; return el; });
633
+ l.className = "c-toc__list";
634
+ l.setAttribute("aria-label", title);
635
+ l.innerHTML = "";
636
+ parsed.forEach((item, i) => {
637
+ const a = document.createElement("a");
638
+ a.className = "c-toc__link" + (item.sub ? " c-toc__link--sub" : "");
639
+ a.href = safeHref(item.href || "#");
640
+ a.textContent = item.label || item;
641
+ a.tabIndex = i === 0 ? 0 : -1;
642
+ if (item.current) a.setAttribute("aria-current", "true");
643
+ l.appendChild(a);
644
+ });
645
+ } catch (e) { warnBadJson(this, "attribute", e); }
646
+ } else if (!items && list) {
647
+ list.remove();
648
+ renderEmpty(this, "toc");
649
+ } else if (!items && !list) {
650
+ renderEmpty(this, "toc");
651
+ }
652
+ }
653
+ enhance() {
654
+ // Scroll-spy marks the toc link whose section crossed the reading line; geometry-based, rAF-throttled.
655
+ if (this._wiredTocSpy) return;
656
+ const links = () => Array.from(this.querySelectorAll(".c-toc__link"));
657
+ const pairs = () => links()
658
+ .map((a) => {
659
+ const href = a.getAttribute("href") || "";
660
+ if (!href.startsWith("#") || href.length < 2) return null;
661
+ const el = document.getElementById(href.slice(1));
662
+ return el ? { a, el } : null;
663
+ })
664
+ .filter(Boolean);
665
+ if (!pairs().length) return;
666
+ this._wiredTocSpy = true;
667
+
668
+ const readingLine = () => {
669
+ const raw = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--header-height"));
670
+ return (Number.isFinite(raw) ? raw : 0) + Math.min(120, window.innerHeight * 0.2);
671
+ };
672
+
673
+ const update = () => {
674
+ const all = pairs();
675
+ if (!all.length) return;
676
+ const line = readingLine();
677
+ let current = all[0];
678
+ for (const p of all) {
679
+ if (p.el.getBoundingClientRect().top <= line) current = p;
680
+ }
681
+ // Last section wins at bottom of scrollable page; short documents stay on first.
682
+ const scrollable = document.documentElement.scrollHeight > window.innerHeight + 2;
683
+ if (scrollable && window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2) {
684
+ current = all[all.length - 1];
685
+ }
686
+ const id = current.el.id;
687
+ links().forEach((a) => {
688
+ const isCurrent = a.getAttribute("href") === "#" + id;
689
+ if (isCurrent) {
690
+ if (a.getAttribute("aria-current") !== "true") a.setAttribute("aria-current", "true");
691
+ } else if (a.hasAttribute("aria-current")) {
692
+ a.removeAttribute("aria-current");
693
+ }
694
+ });
695
+ };
696
+
697
+ let queued = 0;
698
+ const schedule = () => {
699
+ if (queued) return;
700
+ queued = requestAnimationFrame(() => { queued = 0; update(); });
701
+ };
702
+ window.addEventListener("scroll", schedule, { passive: true });
703
+ window.addEventListener("resize", schedule);
704
+ window.addEventListener("hashchange", schedule);
705
+ update();
706
+ onDispose(this, () => {
707
+ window.removeEventListener("scroll", schedule);
708
+ window.removeEventListener("resize", schedule);
709
+ window.removeEventListener("hashchange", schedule);
710
+ if (queued) cancelAnimationFrame(queued);
711
+ });
712
+ // Smooth scroll on link click (F-23).
713
+ if (!this._wiredTocScroll) {
714
+ this._wiredTocScroll = true;
715
+ this.addEventListener("click", (e) => {
716
+ const a = e.target && e.target.closest ? e.target.closest(".c-toc__link") : null;
717
+ if (!a || !this.contains(a)) return;
718
+ const href = a.getAttribute("href") || "";
719
+ if (!href.startsWith("#") || href.length < 2) return;
720
+ const target = document.getElementById(href.slice(1));
721
+ if (!target) return;
722
+ e.preventDefault();
723
+ try { target.scrollIntoView({ behavior: "smooth", block: "start" }); } catch (err) { target.scrollIntoView(); }
724
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { href } }));
725
+ });
726
+ // Keyboard: roving tabindex over TOC links, Enter follows the link.
727
+ this.addEventListener("keydown", (e) => {
728
+ const links = Array.from(this.querySelectorAll(".c-toc__link"));
729
+ if (!links.length) return;
730
+ navKey(e, links, { wrap: true, homeEnd: true, onNavigate: (i) => { links.forEach((a, j) => a.tabIndex = j === i ? 0 : -1); }, onKey: (k) => { if (k === "Enter") { const a = document.activeElement; if (a) { e.preventDefault(); a.click(); } } } });
731
+ });
732
+ }
733
+ }
734
+ }
735
+ define("contour-toc", ContourTocFull);