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
@@ -1,1638 +1,11 @@
1
- import { ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag } from './core.mjs';
2
- import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
3
- import { wireMenu, wirePagination, wireTabs, wireTree, wireRemovable } from './behaviours.mjs';
4
- class ContourMenu extends ContourBase {
5
- static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
6
- static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
7
- render() {
8
- this.classList.add("c-menu");
9
- if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
10
- wireStates(this);
11
- loadRemote(this, "items");
12
- if (renderStates(this, "menu")) return;
13
- const items = remoteData(this, "items");
14
- // Slot composition wins over the JSON attribute.
15
- const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-menu"));
16
- if (authored.length) {
17
- if (this.querySelector("ul.c-menu")) return;
18
- const ul = document.createElement("ul");
19
- ul.className = "c-menu";
20
- ul.setAttribute("role", "menu");
21
- this.appendChild(ul);
22
- return;
23
- }
24
- if (items) {
25
- try {
26
- const parsed = JSON.parse(items);
27
- const ul = this.ensure("ul.c-menu", () => { const el = document.createElement("ul"); el.className = "c-menu"; el.setAttribute("role", "menu"); return el; });
28
- ul.innerHTML = "";
29
- ul.setAttribute("role", "menu");
30
- parsed.forEach((item) => {
31
- if (item === "---" || item === "separator") {
32
- const li = document.createElement("li");
33
- li.className = "c-menu__separator";
34
- li.setAttribute("role", "separator");
35
- ul.appendChild(li);
36
- } else if (typeof item === "string") {
37
- const li = document.createElement("li");
38
- li.className = "c-menu__item";
39
- li.setAttribute("role", "menuitem");
40
- li.textContent = item;
41
- ul.appendChild(li);
42
- } else if (item.group) {
43
- const li = document.createElement("li");
44
- li.className = "c-menu__group";
45
- li.setAttribute("role", "group");
46
- if (item.group) li.setAttribute("aria-label", String(item.group));
47
- const hdr = document.createElement("div");
48
- hdr.className = "c-menu__group-label";
49
- hdr.textContent = String(item.group);
50
- li.appendChild(hdr);
51
- if (Array.isArray(item.items)) {
52
- const sub = document.createElement("ul");
53
- sub.className = "c-menu";
54
- sub.setAttribute("role", "menu");
55
- item.items.forEach((subItem) => {
56
- const sli = document.createElement("li");
57
- sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
58
- sli.setAttribute("role", "menuitem");
59
- if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
60
- if (subItem.label || subItem.title) {
61
- const lbl = document.createElement("span");
62
- lbl.className = "c-menu__label";
63
- lbl.textContent = subItem.label || subItem.title || "";
64
- sli.appendChild(lbl);
65
- }
66
- sub.appendChild(sli);
67
- });
68
- li.appendChild(sub);
69
- }
70
- ul.appendChild(li);
71
- } else {
72
- const li = document.createElement("li");
73
- li.className = "c-menu__item" + (item.danger ? " c-menu__item--danger" : "") + (item.disabled ? " c-menu__item--disabled" : "");
74
- li.setAttribute("role", "menuitem");
75
- if (item.disabled) li.setAttribute("aria-disabled", "true");
76
- if (item.items && Array.isArray(item.items)) {
77
- li.setAttribute("aria-haspopup", "menu");
78
- li.setAttribute("aria-expanded", "false");
79
- }
80
- if (item.label || item.title) {
81
- const lbl = document.createElement("span");
82
- lbl.className = "c-menu__label";
83
- lbl.textContent = item.label || item.title || "";
84
- li.appendChild(lbl);
85
- }
86
- if (item.shortcut) {
87
- const sc = document.createElement("span");
88
- sc.className = "c-menu__shortcut";
89
- sc.textContent = item.shortcut;
90
- li.appendChild(sc);
91
- }
92
- ul.appendChild(li);
93
- }
94
- });
95
- if (ul.parentNode !== this) this.appendChild(ul);
96
- this.classList.remove("c-menu");
97
- ul.classList.add("c-menu");
98
- } catch (e) { /* keep existing */ }
99
- } else {
100
- renderEmpty(this, "menu");
101
- }
102
- }
103
- enhance() {
104
- wireMenu(this);
105
- }
106
- }
107
- define("contour-menu", ContourMenu);
108
- class ContourTabs extends ContourBase {
109
- static get observed() { return ["tabs", "autoplay", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "orientation", "closable"]; }
110
- 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 } }; }
111
- render() {
112
- this.classList.add("c-tabs");
113
- wireStates(this);
114
- loadRemote(this, "tabs");
115
- if (renderStates(this, "tabs")) return;
116
- const tabs = remoteData(this, "tabs");
117
- // Slot composition wins over the JSON attribute, same as ContourMenu:
118
- // authored tab buttons and panels stay across re-renders and the
119
- // JSON scaffolding only fills in when the host is empty.
120
- const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-tabs__list"));
121
- if (tabs && !authored.length) {
122
- try {
123
- const parsed = JSON.parse(tabs);
124
- const list = this.ensure(".c-tabs__list", () => { const el = document.createElement("div"); el.className = "c-tabs__list"; el.setAttribute("role", "tablist"); return el; });
125
- list.setAttribute("role", "tablist");
126
- const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
127
- list.setAttribute("aria-orientation", orientation);
128
- if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
129
- // Preserve the selected tab across rebuilds (G-31): read the
130
- // pre-drop selection before clearing, then re-apply it.
131
- const _prevTabs = Array.from(list.querySelectorAll("[role='tab']"));
132
- const _prevSel = _prevTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
133
- const _keepIdx = _prevSel >= 0 ? _prevSel : 0;
134
- list.innerHTML = "";
135
- // Remove any previously generated panels so re-render doesn't stack.
136
- Array.from(this.querySelectorAll(".c-tabs__panel")).forEach((n) => n.remove());
137
- parsed.forEach((t, i) => {
138
- const label = typeof t === "string" ? t : (t.label || t.title || "");
139
- const panelId = contourId("c-tabs-panel");
140
- const btn = document.createElement("button");
141
- btn.className = "c-tabs__tab";
142
- btn.setAttribute("role", "tab");
143
- btn.setAttribute("aria-selected", String(i === _keepIdx));
144
- btn.setAttribute("aria-controls", panelId);
145
- btn.tabIndex = i === _keepIdx ? 0 : -1;
146
- btn.textContent = label;
147
- if (this.hasAttribute("closable")) {
148
- const closeBtn = document.createElement("button");
149
- closeBtn.type = "button";
150
- closeBtn.className = "c-tabs__close";
151
- closeBtn.setAttribute("aria-label", "Close " + label);
152
- closeBtn.textContent = "×";
153
- closeBtn.addEventListener("click", (e) => {
154
- e.stopPropagation();
155
- const idx = Array.from(list.querySelectorAll("[role='tab']")).indexOf(btn);
156
- // remove tab + panel
157
- const ctrl = btn.getAttribute("aria-controls");
158
- const panel = ctrl ? document.getElementById(ctrl) : null;
159
- btn.remove();
160
- if (panel) panel.remove();
161
- this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true, detail: { index: idx, label } }));
162
- // activate first remaining tab
163
- const remaining = list.querySelectorAll("[role='tab']");
164
- if (remaining.length) remaining[0].click();
165
- });
166
- btn.appendChild(closeBtn);
167
- }
168
- list.appendChild(btn);
169
- const panel = document.createElement("div");
170
- panel.className = "c-tabs__panel";
171
- panel.id = panelId;
172
- panel.setAttribute("role", "tabpanel");
173
- if (typeof t === "object" && t !== null && t.content !== undefined) {
174
- panel.textContent = String(t.content);
175
- }
176
- if (i !== _keepIdx) panel.hidden = true;
177
- this.appendChild(panel);
178
- });
179
- if (list.parentNode !== this) this.prepend(list);
180
- } catch (e) { /* keep existing */ }
181
- } else if (!tabs && !authored.length) {
182
- const list = this.querySelector(".c-tabs__list");
183
- if (list) list.remove();
184
- renderEmpty(this, "tabs");
185
- }
186
- }
187
- enhance() {
188
- wireTabs(this);
189
- // Tabs autoplay (BY-29). Mirrors the streaming chart's interval contract
190
- // (data.mjs): `autoplay` (seconds) advances the selection, `pause` stops
191
- // it, the timer is owned once and disposed with the host, and the whole
192
- // thing is gated on reduced motion. The advance is a click on the next
193
- // tab, so wireTabs' own listener performs the activation and emits the
194
- // manifest's contour:tab-change — this component never re-emits what its
195
- // wiring already announced. Hover and focus also stop the loop (WCAG
196
- // 2.2.2: auto-updating content needs a mechanism to pause, stop or hide;
197
- // the pause attribute is the explicit one, hover/focus the implicit two).
198
- const sync = () => {
199
- const seconds = parseFloat(this.getAttribute("autoplay") || "");
200
- const paused = this.hasAttribute("pause") || this._tabsHover || this._tabsFocus;
201
- const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
202
- const want = Number.isFinite(seconds) && seconds > 0 && !paused && !reduced;
203
- if (want === this._tabsAutoplayRunning) return;
204
- this._tabsAutoplayRunning = want;
205
- if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; }
206
- if (!want) return;
207
- this._tabsTimer = setInterval(() => {
208
- if (!this.isConnected || this.hasAttribute("pause") || this._tabsHover || this._tabsFocus) return;
209
- const list = this.querySelector(".c-tabs__list");
210
- const tabs = list ? Array.from(list.querySelectorAll("[role='tab']")) : [];
211
- if (!tabs.length) return;
212
- const cur = tabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
213
- const next = tabs[(cur + 1) % tabs.length];
214
- if (next) next.click();
215
- }, Math.max(1000, seconds * 1000));
216
- };
217
- // Re-run on every render so autoplay/pause attribute changes are picked
218
- // up; the listeners and the disposer are installed exactly once.
219
- sync();
220
- if (this._wiredTabsAutoplay) return;
221
- this._wiredTabsAutoplay = true;
222
- this.addEventListener("pointerenter", () => { this._tabsHover = true; sync(); });
223
- this.addEventListener("pointerleave", () => { this._tabsHover = false; sync(); });
224
- this.addEventListener("focusin", () => { this._tabsFocus = true; sync(); });
225
- this.addEventListener("focusout", () => { this._tabsFocus = false; sync(); });
226
- onDispose(this, () => { if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; } });
227
- }
228
- }
229
- define("contour-tabs", ContourTabs);
230
- class ContourHeader extends ContourBase {
231
- static get observed() { return ["brand", "links"]; }
232
- static get properties() { return { brand: { attribute: "brand" }, links: { attribute: "links" } }; }
233
- render() {
234
- this.classList.add("c-header");
235
- const brand = this.getAttribute("brand");
236
- const links = this.getAttribute("links");
237
- const inner = this.ensure(".c-header__inner", () => { const el = document.createElement("div"); el.className = "container c-header__inner"; return el; });
238
- inner.className = "container c-header__inner";
239
- // Brand
240
- let brandEl = inner.querySelector(".c-brand");
241
- if (brand) {
242
- if (!brandEl) {
243
- brandEl = document.createElement("a");
244
- brandEl.className = "c-brand";
245
- brandEl.setAttribute("data-contour-generated", "");
246
- brandEl.href = "#";
247
- brandEl.innerHTML = `<span class="c-mark"><svg aria-hidden="true"><use href="#i-mark" /></svg></span>`;
248
- const brandName = document.createElement("span");
249
- brandName.className = "c-brand__name";
250
- brandEl.appendChild(brandName);
251
- inner.insertBefore(brandEl, inner.firstChild);
252
- }
253
- const brandName = brandEl.querySelector(".c-brand__name");
254
- if (brandName) brandName.textContent = brand;
255
- } else if (brandEl && brandEl.hasAttribute("data-contour-generated")) {
256
- brandEl.remove();
257
- }
258
- // Nav
259
- let nav = inner.querySelector(".c-header__nav");
260
- const authoredNav = nav ? Array.from(nav.children).filter((n) => n.tagName === "A") : [];
261
- if (links && !authoredNav.length) {
262
- try {
263
- const parsed = JSON.parse(links);
264
- if (!nav) {
265
- nav = document.createElement("nav");
266
- nav.className = "c-header__nav";
267
- nav.setAttribute("aria-label", "Main");
268
- nav.setAttribute("data-contour-generated", "");
269
- inner.appendChild(nav);
270
- }
271
- nav.innerHTML = "";
272
- parsed.forEach((l) => {
273
- const a = document.createElement("a");
274
- a.href = l.href || "#";
275
- a.textContent = l.label || l;
276
- nav.appendChild(a);
277
- });
278
- } catch (e) { /* skip */ }
279
- } else if (links && authoredNav.length) {
280
- // authored nav wins; keep it
281
- } else if (nav && !links && !authoredNav.length && nav.hasAttribute("data-contour-generated")) {
282
- nav.remove();
283
- }
284
- // Actions container
285
- if (!inner.querySelector(".c-header__actions")) {
286
- const actions = document.createElement("div");
287
- actions.className = "c-header__actions";
288
- inner.appendChild(actions);
289
- }
290
- // Mobile toggle (BY-29). Below 60rem the sheet hides .c-header__nav with
291
- // no way to open it; the toggle is the way. It is created only when a nav
292
- // exists, controls that nav by id, and starts closed so the first paint
293
- // matches the closed CSS state. It rides inside .c-header__actions so the
294
- // group's margin-inline-start:auto keeps it at the far right under 60rem.
295
- // `i-grid` stands in for a hamburger: the sprite ships no i-menu symbol
296
- // (index.html is the guide's own, and a dead <use> would be a defect), so
297
- // the closest existing menu-like glyph is used with the real label.
298
- const navEl = inner.querySelector(".c-header__nav");
299
- if (navEl) {
300
- if (!navEl.id) navEl.id = "contour-header-nav";
301
- const actions = inner.querySelector(".c-header__actions");
302
- if (actions && !actions.querySelector(".c-header__toggle")) {
303
- const toggle = document.createElement("button");
304
- toggle.type = "button";
305
- toggle.className = "c-header__toggle";
306
- toggle.setAttribute("aria-label", "Toggle navigation");
307
- toggle.setAttribute("aria-expanded", "false");
308
- toggle.setAttribute("aria-controls", navEl.id);
309
- toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-grid" /></svg>';
310
- actions.appendChild(toggle);
311
- }
312
- }
313
- if (inner.parentNode !== this) this.appendChild(inner);
314
- }
315
- enhance() {
316
- if (this._wiredHeader) return;
317
- this._wiredHeader = true;
318
- // Scroll state (BY-29): past a small threshold the header gains
319
- // c-header--scrolled so the sheet can raise it above the page.
320
- const update = () => {
321
- const y = window.scrollY || document.documentElement.scrollTop || 0;
322
- this.classList.toggle("c-header--scrolled", y > 8);
323
- };
324
- update();
325
- window.addEventListener("scroll", update, { passive: true });
326
- onDispose(this, () => window.removeEventListener("scroll", update));
327
- // Toggle: the button shows/hides the nav under 60rem and keeps
328
- // aria-expanded in step. Close on Escape while open.
329
- this.addEventListener("click", (e) => {
330
- const toggle = e.target && e.target.closest ? e.target.closest(".c-header__toggle") : null;
331
- if (!toggle || !this.contains(toggle)) return;
332
- const nav = this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
333
- if (!nav) return;
334
- const open = nav.classList.toggle("is-open");
335
- toggle.setAttribute("aria-expanded", String(open));
336
- });
337
- this.addEventListener("keydown", (e) => {
338
- if (e.key !== "Escape") return;
339
- const toggle = this.querySelector(".c-header__toggle");
340
- const nav = toggle && this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
341
- if (!toggle || !nav || !nav.classList.contains("is-open")) return;
342
- nav.classList.remove("is-open");
343
- toggle.setAttribute("aria-expanded", "false");
344
- });
345
- }
346
- }
347
- define("contour-header", ContourHeader);
348
- class ContourTree extends ContourBase {
349
- static get updateMode() { return "keyed"; }
350
- static get observed() { return ["items", "virtual", "item-height", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "selectable"]; }
351
- static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
352
- _itemHeight() {
353
- const h = Number(this.getAttribute("item-height"));
354
- return Number.isFinite(h) && h > 0 ? h : 28;
355
- }
356
- _labelToPaths(nodes, pathPrefix, map) {
357
- (nodes || []).forEach((node, i) => {
358
- const p = pathPrefix + "." + i;
359
- const label = String(node.label || node).trim().slice(0, 120);
360
- if (!map.has(label)) map.set(label, []);
361
- map.get(label).push(p);
362
- if (Array.isArray(node.children)) this._labelToPaths(node.children, p, map);
363
- });
364
- }
365
- _restoreExpanded() {
366
- const persist = this.getAttribute("persist");
367
- if (!persist || !this._treeData) return;
368
- let labels = null;
369
- try {
370
- if (persist === "storage" && this.id) {
371
- const saved = localStorage.getItem("contour-tree:" + this.id);
372
- if (saved !== null) labels = JSON.parse(saved);
373
- } else if (persist === "url") {
374
- const v = new URLSearchParams(window.location.search).get("c-tree");
375
- if (v !== null) labels = JSON.parse(v);
376
- }
377
- } catch (e) { labels = null; }
378
- if (!Array.isArray(labels)) return;
379
- const want = new Set(labels.map((l) => String(l)));
380
- const map = new Map();
381
- this._labelToPaths(this._treeData, "", map);
382
- const expanded = this._expanded || (this._expanded = new Set());
383
- for (const lbl of want) {
384
- const paths = map.get(lbl);
385
- if (paths) paths.forEach((p) => expanded.add(p));
386
- }
387
- }
388
- _persistExpanded() {
389
- const persist = this.getAttribute("persist");
390
- if (!persist || !this._expanded) return;
391
- // Map expanded paths back to labels.
392
- const pathToNode = new Map();
393
- const walk = (nodes, pathPrefix) => {
394
- (nodes || []).forEach((node, i) => {
395
- const p = pathPrefix + "." + i;
396
- pathToNode.set(p, node);
397
- if (Array.isArray(node.children)) walk(node.children, p);
398
- });
399
- };
400
- walk(this._treeData, "");
401
- const open = [];
402
- for (const p of this._expanded) {
403
- const node = pathToNode.get(p);
404
- if (node) open.push(String(node.label || node).trim().slice(0, 120));
405
- }
406
- try {
407
- if (persist === "storage" && this.id) {
408
- localStorage.setItem("contour-tree:" + this.id, JSON.stringify(open));
409
- } else if (persist === "url") {
410
- const url = new URL(window.location.href);
411
- url.searchParams.set("c-tree", JSON.stringify(open));
412
- window.history.replaceState(null, "", url.toString());
413
- }
414
- } catch (e) {}
415
- }
416
- _flatten(nodes, pathPrefix, depth, expanded, out) {
417
- (nodes || []).forEach((node, i) => {
418
- const p = pathPrefix + "." + i;
419
- const hasChildren = Array.isArray(node.children) && node.children.length > 0;
420
- const isExpanded = expanded.has(p);
421
- out.push({ node, path: p, depth, hasChildren, expanded: isExpanded });
422
- if (hasChildren && isExpanded) {
423
- this._flatten(node.children, p, depth + 1, expanded, out);
424
- }
425
- });
426
- }
427
- _renderNodeFlat(rootUl, f) {
428
- const node = f.node;
429
- const depth = f.depth;
430
- const li = document.createElement("div");
431
- li.className = "c-tree__node";
432
- li.setAttribute("role", "treeitem");
433
- li.setAttribute("aria-level", String(depth));
434
- li.dataset.path = f.path;
435
- if (f.hasChildren) {
436
- li.setAttribute("aria-expanded", String(f.expanded));
437
- const row = document.createElement("div");
438
- row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
439
- row.style.paddingInlineStart = ((depth - 1) * 1) + "rem";
440
- const toggle = document.createElement("button");
441
- toggle.className = "c-tree__toggle";
442
- toggle.setAttribute("type", "button");
443
- toggle.setAttribute("aria-expanded", String(f.expanded));
444
- toggle.setAttribute("aria-label", "Toggle");
445
- toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
446
- row.appendChild(toggle);
447
- const span = document.createElement("span");
448
- span.textContent = node.label;
449
- row.appendChild(span);
450
- li.appendChild(row);
451
- } else {
452
- const leaf = document.createElement("div");
453
- leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
454
- leaf.style.paddingInlineStart = (depth * 1) + "rem";
455
- if (this.hasAttribute("selectable")) {
456
- const cb = document.createElement("input");
457
- cb.type = "checkbox";
458
- cb.className = "c-tree__select";
459
- cb.setAttribute("aria-label", "Select " + (node.label || node));
460
- const label = String(node.label || node).trim().slice(0, 120);
461
- if (this._selectedTree && this._selectedTree.has(label)) cb.checked = true;
462
- leaf.insertBefore(cb, leaf.firstChild);
463
- }
464
- leaf.appendChild(document.createTextNode(node.label || node));
465
- li.appendChild(leaf);
466
- }
467
- return li;
468
- }
469
- _renderWindow(rootUl, scrollTop) {
470
- if (!this._treeData) return;
471
- const ih = this._itemHeight();
472
- const expanded = this._expanded || (this._expanded = new Set());
473
- const flat = [];
474
- this._flatten(this._treeData, "", 1, expanded, flat);
475
- const total = flat.length;
476
- const viewportSize = rootUl.clientHeight || 320;
477
- const visibleCount = Math.ceil(viewportSize / ih) + 6;
478
- let start = Math.floor((scrollTop || 0) / ih);
479
- if (start < 0) start = 0;
480
- if (start > Math.max(0, total - visibleCount)) start = Math.max(0, total - visibleCount);
481
- const end = Math.min(total, start + visibleCount);
482
- const topSize = start * ih;
483
- const bottomSize = Math.max(0, (total - end) * ih);
484
- rootUl.innerHTML = "";
485
- const top = document.createElement("div");
486
- top.className = "c-tree__spacer c-tree__spacer--top";
487
- top.style.height = topSize + "px";
488
- rootUl.appendChild(top);
489
- for (let i = start; i < end; i++) {
490
- rootUl.appendChild(this._renderNodeFlat(rootUl, flat[i]));
491
- }
492
- const bottom = document.createElement("div");
493
- bottom.className = "c-tree__spacer c-tree__spacer--bottom";
494
- bottom.style.height = bottomSize + "px";
495
- rootUl.appendChild(bottom);
496
- }
497
- render() {
498
- this.classList.add("c-tree");
499
- // Slot composition wins over the JSON attribute, same as ContourMenu:
500
- // an authored tree is preserved across re-renders instead of being
501
- // rebuilt from `items` and losing whatever the reader put in it.
502
- const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-tree"));
503
- wireStates(this);
504
- loadRemote(this, "items");
505
- if (renderStates(this, "tree")) return;
506
- const items = remoteData(this, "items");
507
- if (items && !authored.length) {
508
- try {
509
- const parsed = JSON.parse(items);
510
- const rootUl = this.ensure("div.c-tree", () => { const el = document.createElement("div"); el.className = "c-tree"; el.setAttribute("role", "tree"); return el; });
511
- rootUl.innerHTML = "";
512
- rootUl.className = "c-tree";
513
- rootUl.setAttribute("role", "tree");
514
- const virtual = this.hasAttribute("virtual");
515
- if (virtual) {
516
- this._treeData = parsed;
517
- this._expanded = this._expanded || new Set();
518
- this._treeRoot = rootUl;
519
- this._restoreExpanded();
520
- rootUl.style.maxHeight = rootUl.style.maxHeight || "24rem";
521
- rootUl.style.overflow = "auto";
522
- const scrollTop = this._treeScrollTop || 0;
523
- this._renderWindow(rootUl, scrollTop);
524
- try { rootUl.scrollTop = scrollTop; } catch (e) {}
525
- } else {
526
- this._treeData = null;
527
- const render = (nodes, parent, depth) => {
528
- const ul = parent ? document.createElement("div") : rootUl;
529
- if (parent) {
530
- ul.className = "c-tree__children";
531
- ul.setAttribute("role", "group");
532
- if (supportsUntilFound()) ul.setAttribute("hidden", "until-found"); else ul.setAttribute("hidden", "");
533
- }
534
- nodes.forEach((node) => {
535
- const li = document.createElement("div");
536
- li.className = "c-tree__node";
537
- li.setAttribute("role", "treeitem");
538
- li.setAttribute("aria-level", String(depth));
539
- if (node.children) {
540
- li.setAttribute("aria-expanded", "false");
541
- const row = document.createElement("div");
542
- row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
543
- if (node.indent) {
544
- const ind = document.createElement("span");
545
- ind.className = "c-tree__indent";
546
- ind.style.inlineSize = (node.indent * 1) + "rem";
547
- row.appendChild(ind);
548
- }
549
- const toggle = document.createElement("button");
550
- toggle.className = "c-tree__toggle";
551
- toggle.setAttribute("type", "button");
552
- toggle.setAttribute("aria-expanded", "false");
553
- toggle.setAttribute("aria-label", "Toggle");
554
- toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
555
- row.appendChild(toggle);
556
- const span = document.createElement("span");
557
- span.textContent = node.label;
558
- row.appendChild(span);
559
- li.appendChild(row);
560
- render(node.children, li, depth + 1);
561
- } else {
562
- const leaf = document.createElement("div");
563
- leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
564
- if (node.indent) {
565
- const ind = document.createElement("span");
566
- ind.className = "c-tree__indent";
567
- ind.style.inlineSize = (node.indent * 1) + "rem";
568
- leaf.appendChild(ind);
569
- }
570
- if (this.hasAttribute("selectable")) {
571
- const cb = document.createElement("input");
572
- cb.type = "checkbox";
573
- cb.className = "c-tree__select";
574
- cb.setAttribute("aria-label", "Select " + (node.label || node));
575
- leaf.insertBefore(cb, leaf.firstChild);
576
- }
577
- leaf.appendChild(document.createTextNode(node.label || node));
578
- li.appendChild(leaf);
579
- }
580
- ul.appendChild(li);
581
- });
582
- if (parent) parent.appendChild(ul);
583
- };
584
- render(parsed, null, 1);
585
- }
586
- this.classList.remove("c-tree");
587
- rootUl.classList.add("c-tree");
588
- if (rootUl.parentNode !== this) this.appendChild(rootUl);
589
- } catch (e) { /* keep existing */ }
590
- } else if (!items && !authored.length) {
591
- renderEmpty(this, "tree");
592
- }
593
- }
594
- enhance() {
595
- // Toggle handling via delegation (works for windowed + static trees).
596
- if (!this._wiredTreeToggle) {
597
- this._wiredTreeToggle = true;
598
- this.addEventListener("click", (e) => {
599
- const toggle = e.target && e.target.closest ? e.target.closest(".c-tree__toggle") : null;
600
- if (!toggle || !this.contains(toggle)) return;
601
- e.stopPropagation();
602
- const nodeEl = toggle.closest(".c-tree__node");
603
- const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
604
- const expanded = toggle.getAttribute("aria-expanded") === "true";
605
- if (path && this._expanded) {
606
- if (expanded) this._expanded.delete(path); else this._expanded.add(path);
607
- }
608
- toggle.setAttribute("aria-expanded", String(!expanded));
609
- const row = toggle.closest(".c-tree__row");
610
- if (row) row.setAttribute("aria-expanded", String(!expanded));
611
- if (this.hasAttribute("virtual") && this._treeRoot) {
612
- const s = this._treeRoot;
613
- this._treeScrollTop = s.scrollTop || 0;
614
- this._renderWindow(s, this._treeScrollTop);
615
- try { s.scrollTop = this._treeScrollTop; } catch (err) {}
616
- this._persistExpanded();
617
- }
618
- });
619
- }
620
- // Scroll-driven windowing for virtual trees.
621
- if (this.hasAttribute("virtual") && !this._wiredTreeScroll) {
622
- this._wiredTreeScroll = true;
623
- const attach = () => {
624
- const s = this.querySelector(".c-tree");
625
- if (!s || s._treeScrollWired) return;
626
- s._treeScrollWired = true;
627
- let raf = 0;
628
- const onScroll = () => {
629
- if (raf) return;
630
- raf = requestAnimationFrame(() => {
631
- raf = 0;
632
- this._treeScrollTop = s.scrollTop || 0;
633
- this._renderWindow(s, this._treeScrollTop);
634
- try { s.scrollTop = this._treeScrollTop; } catch (err) {}
635
- });
636
- };
637
- s.addEventListener("scroll", onScroll, { passive: true });
638
- onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
639
- };
640
- attach();
641
- // retry if root not ready
642
- if (!this.querySelector(".c-tree")) {
643
- const mo = new MutationObserver(() => { if (this.querySelector(".c-tree")) { attach(); mo.disconnect(); } });
644
- mo.observe(this, { childList: true, subtree: true });
645
- onDispose(this, () => mo.disconnect());
646
- }
647
- }
648
- // Auto-scroll during drag for virtual trees (so off-screen targets
649
- // become reachable). Delegated on the host; only active in virtual mode.
650
- if (this.hasAttribute("virtual") && !this._wiredTreeDragScroll) {
651
- this._wiredTreeDragScroll = true;
652
- let dragScrollRaf = 0;
653
- let dragScrollDir = 0;
654
- const tick = () => {
655
- if (!dragScrollDir) { dragScrollRaf = 0; return; }
656
- const s = this._treeRoot;
657
- if (s) {
658
- s.scrollTop += dragScrollDir * 8;
659
- this._treeScrollTop = s.scrollTop;
660
- this._renderWindow(s, this._treeScrollTop);
661
- }
662
- dragScrollRaf = requestAnimationFrame(tick);
663
- };
664
- this.addEventListener("dragover", (e) => {
665
- const s = this._treeRoot;
666
- if (!s) return;
667
- const rect = s.getBoundingClientRect();
668
- const edge = 40;
669
- if (e.clientY < rect.top + edge) dragScrollDir = -1;
670
- else if (e.clientY > rect.bottom - edge) dragScrollDir = 1;
671
- else dragScrollDir = 0;
672
- if (dragScrollDir && !dragScrollRaf) dragScrollRaf = requestAnimationFrame(tick);
673
- });
674
- const stop = () => {
675
- dragScrollDir = 0;
676
- if (dragScrollRaf) { cancelAnimationFrame(dragScrollRaf); dragScrollRaf = 0; }
677
- };
678
- this.addEventListener("dragend", stop);
679
- this.addEventListener("drop", stop);
680
- }
681
- // Interaction lives in behaviours.mjs, which the shadow wrappers call too.
682
- // One implementation, so the two layers cannot drift apart again: the shadow
683
- // copy queried its root for slotted nodes, found none, and wired nothing.
684
- wireTree(this);
685
- }
686
- }
687
- define("contour-tree", ContourTree);
688
- class ContourCodeTabs extends ContourBase {
689
- static get observed() { return ["tabs", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist"]; }
690
- static get properties() { return { tabs: { attribute: "tabs" }, src: { attribute: "src" } }; }
691
- render() {
692
- this.classList.add("c-code-tabs");
693
- wireStates(this);
694
- loadRemote(this, "tabs");
695
- if (renderStates(this, "code-tabs")) return;
696
- const tabs = remoteData(this, "tabs");
697
- const list = this.querySelector(".c-code-tabs__list");
698
- const authored = list ? Array.from(list.children).filter((n) => n.getAttribute && n.getAttribute("role") === "tab") : [];
699
- if (tabs && !authored.length) {
700
- try {
701
- const parsed = JSON.parse(tabs);
702
- 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; });
703
- l.setAttribute("role", "tablist");
704
- const _prevCodeTabs = Array.from(l.querySelectorAll("[role='tab']"));
705
- const _prevCodeSel = _prevCodeTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
706
- const _keepCodeIdx = _prevCodeSel >= 0 ? _prevCodeSel : 0;
707
- l.innerHTML = "";
708
- Array.from(this.querySelectorAll(".c-code-tabs__panel")).forEach((n) => n.remove());
709
- parsed.forEach((t, i) => {
710
- const label = typeof t === "string" ? t : (t.label || t.title || "");
711
- const panelId = contourId("c-code-tabs-panel");
712
- const btn = document.createElement("button");
713
- btn.className = "c-code-tabs__tab";
714
- btn.setAttribute("role", "tab");
715
- btn.setAttribute("aria-selected", String(i === _keepCodeIdx));
716
- btn.setAttribute("aria-controls", panelId);
717
- btn.tabIndex = i === _keepCodeIdx ? 0 : -1;
718
- btn.textContent = label;
719
- l.appendChild(btn);
720
- const panel = document.createElement("div");
721
- panel.className = "c-code-tabs__panel";
722
- panel.id = panelId;
723
- panel.setAttribute("role", "tabpanel");
724
- if (typeof t === "object" && t !== null && t.content !== undefined) {
725
- panel.textContent = String(t.content);
726
- }
727
- if (i !== _keepCodeIdx) panel.hidden = true;
728
- this.appendChild(panel);
729
- });
730
- if (l.parentNode !== this) this.prepend(l);
731
- } catch (e) { /* keep existing */ }
732
- } else if (!tabs && list) {
733
- list.remove();
734
- renderEmpty(this, "code-tabs");
735
- } else if (!tabs && !list) {
736
- renderEmpty(this, "code-tabs");
737
- }
738
- }
739
- enhance() {
740
- wireTabs(this);
741
- }
742
- }
743
- define("contour-code-tabs", ContourCodeTabs);
744
- class ContourBreadcrumb extends ContourBase {
745
- static get observed() { return ["items", "separator", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
746
- static get properties() { return { items: { attribute: "items" }, separator: { attribute: "separator" }, max: { attribute: "max", type: Number }, src: { attribute: "src" } } };
747
- render() {
748
- this.classList.add("c-breadcrumb");
749
- wireStates(this);
750
- loadRemote(this, "items");
751
- if (renderStates(this, "breadcrumb")) return;
752
- const items = remoteData(this, "items");
753
- // Slot composition: authored <li> items win over the JSON attribute.
754
- const nav = this.querySelector("nav");
755
- const ol = nav ? nav.querySelector("ol") : null;
756
- const authored = ol ? Array.from(ol.children).filter((n) => n.tagName === "LI") : [];
757
- if (items && !authored.length) {
758
- try {
759
- const parsed = JSON.parse(items);
760
- const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", "Breadcrumb"); el.id = "contour-breadcrumb-list"; return el; });
761
- n.setAttribute("aria-label", "Breadcrumb");
762
- n.id = "contour-breadcrumb-list";
763
- n.innerHTML = "";
764
- const sep = this.getAttribute("separator") || "/";
765
- const max = this._overflowExpanded ? null : this.max;
766
- const shown = Number.isFinite(max) && max > 1 && parsed.length > max
767
- ? parsed.slice(-max)
768
- : parsed;
769
- if (Number.isFinite(max) && max > 1 && parsed.length > max) {
770
- const btn = document.createElement("button");
771
- btn.type = "button";
772
- btn.className = "c-breadcrumb__overflow";
773
- btn.setAttribute("aria-label", `Show ${parsed.length - shown.length + 1} more items`);
774
- btn.setAttribute("aria-expanded", "false");
775
- btn.setAttribute("aria-controls", "contour-breadcrumb-list");
776
- btn.textContent = "…";
777
- btn.addEventListener("click", () => {
778
- // A handler-owned property, not an attribute: flipping a
779
- // self-observed attribute from a handler would re-enter render
780
- // (the arm-7 trap), so the flag lives outside OBSERVED.
781
- this._overflowExpanded = true;
782
- this.requestRender();
783
- });
784
- n.appendChild(btn);
785
- }
786
- shown.forEach((item, i) => {
787
- if (i < shown.length - 1) {
788
- const a = document.createElement("a");
789
- a.href = item.href || "#";
790
- a.textContent = item.label || item;
791
- n.appendChild(a);
792
- const s = document.createElement("span");
793
- s.className = "c-breadcrumb__sep";
794
- s.setAttribute("aria-hidden", "true");
795
- s.textContent = sep;
796
- n.appendChild(s);
797
- } else {
798
- const span = document.createElement("span");
799
- span.textContent = item.label || item;
800
- span.setAttribute("aria-current", "page");
801
- n.appendChild(span);
802
- }
803
- });
804
- } catch (e) { /* keep existing */ }
805
- } else if (!items && nav) {
806
- nav.remove();
807
- } else if (!items && !nav) {
808
- renderEmpty(this, "breadcrumb");
809
- }
810
- }
811
- }
812
- define("contour-breadcrumb", ContourBreadcrumb);
813
- class ContourPagination extends ContourBase {
814
- static get observed() { return ["pages", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist"]; }
815
- static get properties() { return { pages: { attribute: "pages" }, current: { attribute: "current" }, src: { attribute: "src" } }; }
816
- render() {
817
- this.classList.add("c-pagination");
818
- wireStates(this);
819
- loadRemote(this, "pages");
820
- if (renderStates(this, "pagination")) return;
821
- const pages = remoteData(this, "pages");
822
- // Drop previously generated links so a re-render cannot stack a second set.
823
- Array.from(this.querySelectorAll(".c-pagination__link")).forEach((n) => n.remove());
824
- let currentAttr = this.getAttribute("current") || "1";
825
- if (this.getAttribute("persist") === "storage" && this.id) {
826
- try { const stored = localStorage.getItem("contour-pagination:" + this.id); if (stored !== null) currentAttr = stored; } catch (e) {}
827
- } else if (this.getAttribute("persist") === "url") {
828
- try { const v = new URLSearchParams(window.location.search).get("c-pagination"); if (v !== null) currentAttr = v; } catch (e) {}
829
- }
830
- const current = parseInt(currentAttr, "10") || 1;
831
- if (pages) {
832
- let count = parseInt(pages, 10);
833
- if (!Number.isFinite(count) || count < 1) {
834
- try { const p = JSON.parse(pages); if (Array.isArray(p)) count = p.length; } catch (e) {}
835
- }
836
- // Prev button.
837
- const prev = document.createElement("button");
838
- prev.type = "button";
839
- prev.className = "c-pagination__link c-pagination__prev";
840
- prev.setAttribute("data-action", "prev");
841
- prev.textContent = "‹";
842
- prev.setAttribute("aria-label", "Previous page");
843
- this.appendChild(prev);
844
- for (let i = 1; i <= count; i++) {
845
- const btn = document.createElement("button");
846
- btn.type = "button";
847
- btn.className = "c-pagination__link";
848
- btn.textContent = String(i);
849
- if (i === current) {
850
- btn.setAttribute("aria-current", "page");
851
- }
852
- this.appendChild(btn);
853
- }
854
- // Next button.
855
- const next = document.createElement("button");
856
- next.type = "button";
857
- next.className = "c-pagination__link c-pagination__next";
858
- next.setAttribute("data-action", "next");
859
- next.textContent = "›";
860
- next.setAttribute("aria-label", "Next page");
861
- this.appendChild(next);
862
- } else {
863
- renderEmpty(this, "pagination");
864
- }
865
- }
866
- enhance() {
867
- wirePagination(this);
868
- }
869
- }
870
- define("contour-pagination", ContourPagination);
871
- class ContourPagerFull extends ContourBase {
872
- static get observed() { return ["prev", "next"]; }
873
- static get properties() { return { prev: { attribute: "prev" }, next: { attribute: "next" } }; }
874
- render() {
875
- this.classList.add("c-pager");
876
- // Drop previously generated links so a re-render cannot stack a second set.
877
- Array.from(this.querySelectorAll(".c-pager__link")).forEach((n) => n.remove());
878
- const prev = this.getAttribute("prev");
879
- const next = this.getAttribute("next");
880
- if (prev) {
881
- const a = document.createElement("a");
882
- a.className = "c-pager__link";
883
- a.href = prev.split("|")[1] || "#";
884
- const dir = document.createElement("span");
885
- dir.className = "c-pager__dir";
886
- dir.textContent = "← Previous";
887
- a.appendChild(dir);
888
- const title = document.createElement("span");
889
- title.className = "c-pager__title";
890
- title.textContent = prev.split("|")[0];
891
- a.appendChild(title);
892
- this.appendChild(a);
893
- }
894
- if (next) {
895
- const a = document.createElement("a");
896
- a.className = "c-pager__link c-pager__link--next";
897
- a.href = next.split("|")[1] || "#";
898
- const dir = document.createElement("span");
899
- dir.className = "c-pager__dir";
900
- dir.textContent = "Next →";
901
- a.appendChild(dir);
902
- const title = document.createElement("span");
903
- title.className = "c-pager__title";
904
- title.textContent = next.split("|")[0];
905
- a.appendChild(title);
906
- this.appendChild(a);
907
- }
908
- }
909
- }
910
- define("contour-pager", ContourPagerFull);
911
- class ContourTocFull extends ContourBase {
912
- static get observed() { return ["title", "items", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
913
- static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
914
- render() {
915
- this.classList.add("c-toc");
916
- this.setAttribute("role", "list");
917
- wireStates(this);
918
- loadRemote(this, "items");
919
- if (renderStates(this, "toc")) return;
920
- const items = remoteData(this, "items");
921
- const title = this.getAttribute("title") || "On this page";
922
- const titleEl = this.ensure(".c-toc__title", () => { const el = document.createElement("div"); el.className = "c-toc__title"; return el; });
923
- titleEl.textContent = title;
924
- const list = this.querySelector(".c-toc__list");
925
- const authored = list ? Array.from(list.children).filter((n) => n.tagName === "A") : [];
926
- if (items && !authored.length) {
927
- try {
928
- const parsed = JSON.parse(items);
929
- const l = this.ensure(".c-toc__list", () => { const el = document.createElement("nav"); el.className = "c-toc__list"; return el; });
930
- l.className = "c-toc__list";
931
- l.setAttribute("aria-label", title);
932
- l.innerHTML = "";
933
- parsed.forEach((item) => {
934
- const a = document.createElement("a");
935
- a.className = "c-toc__link" + (item.sub ? " c-toc__link--sub" : "");
936
- a.href = item.href || "#";
937
- a.textContent = item.label || item;
938
- if (item.current) a.setAttribute("aria-current", "true");
939
- l.appendChild(a);
940
- });
941
- } catch (e) { /* keep existing */ }
942
- } else if (!items && list) {
943
- list.remove();
944
- renderEmpty(this, "toc");
945
- } else if (!items && !list) {
946
- renderEmpty(this, "toc");
947
- }
948
- }
949
- enhance() {
950
- // Scroll-spy (BY-29). The toc links point at page sections by href; when
951
- // IntersectionObserver exists, the section currently in the reading band
952
- // marks its link aria-current="true" and clears the rest. The shipped CSS
953
- // already styles .c-toc__link[aria-current="true"], so the hook needs no
954
- // new rule. Enhancement-only: without IntersectionObserver the links stay
955
- // as rendered, with author-provided aria-current left untouched.
956
- if (this._wiredTocSpy) return;
957
- if (typeof IntersectionObserver !== "function") return;
958
- const links = () => Array.from(this.querySelectorAll(".c-toc__link"));
959
- const targets = links()
960
- .map((a) => {
961
- const href = a.getAttribute("href") || "";
962
- if (!href.startsWith("#") || href.length < 2) return null;
963
- return document.getElementById(href.slice(1));
964
- })
965
- .filter(Boolean);
966
- if (!targets.length) return;
967
- this._wiredTocSpy = true;
968
- const spy = new IntersectionObserver((entries) => {
969
- const visible = entries.filter((en) => en.isIntersecting).map((en) => en.target.id);
970
- if (!visible.length) return;
971
- const top = visible[0];
972
- links().forEach((a) => {
973
- const href = a.getAttribute("href") || "";
974
- const isCurrent = href === "#" + top;
975
- if (isCurrent && a.getAttribute("aria-current") !== "true") a.setAttribute("aria-current", "true");
976
- else if (!isCurrent && a.hasAttribute("aria-current")) a.removeAttribute("aria-current");
977
- });
978
- }, { rootMargin: "0px 0px -60% 0px", threshold: 0 });
979
- targets.forEach((t) => spy.observe(t));
980
- onDispose(this, () => spy.disconnect());
981
- // Smooth scroll on link click (F-23).
982
- if (!this._wiredTocScroll) {
983
- this._wiredTocScroll = true;
984
- this.addEventListener("click", (e) => {
985
- const a = e.target && e.target.closest ? e.target.closest(".c-toc__link") : null;
986
- if (!a || !this.contains(a)) return;
987
- const href = a.getAttribute("href") || "";
988
- if (!href.startsWith("#") || href.length < 2) return;
989
- const target = document.getElementById(href.slice(1));
990
- if (!target) return;
991
- e.preventDefault();
992
- try { target.scrollIntoView({ behavior: "smooth", block: "start" }); } catch (err) { target.scrollIntoView(); }
993
- });
994
- }
995
- }
996
- }
997
- define("contour-toc", ContourTocFull);
998
- class ContourFilterBar extends ContourBase {
999
- static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "count", "clearable"]; }
1000
- static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" }, count: { attribute: "count" }, clearable: { attribute: "clearable" } }; }
1001
- render() {
1002
- this.classList.add("c-filter-bar");
1003
- wireStates(this);
1004
- loadRemote(this, "items");
1005
- if (renderStates(this, "filter-bar")) return;
1006
- const label = this.getAttribute("label");
1007
- if (label) {
1008
- const l = this.ensure(".c-filter-bar__label", () => { const el = document.createElement("span"); el.className = "c-filter-bar__label"; return el; });
1009
- l.textContent = label;
1010
- } else {
1011
- const l = this.querySelector(".c-filter-bar__label");
1012
- if (l) l.remove();
1013
- }
1014
- if (this.hasAttribute("divider")) {
1015
- this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
1016
- } else {
1017
- const d = this.querySelector(".c-filter-bar__divider");
1018
- if (d) d.remove();
1019
- }
1020
- // Text input support
1021
- if (this.hasAttribute("input") || this.hasAttribute("placeholder")) {
1022
- let inp = this.querySelector(".c-filter-bar__input");
1023
- if (!inp) { inp = document.createElement("input"); inp.type = "search"; inp.className = "c-filter-bar__input"; this.appendChild(inp); }
1024
- const ph = this.getAttribute("placeholder");
1025
- if (ph) inp.setAttribute("placeholder", ph);
1026
- } else {
1027
- const inp = this.querySelector(".c-filter-bar__input");
1028
- if (inp) inp.remove();
1029
- }
1030
- // Mode toolbar
1031
- const modesAttr = this.getAttribute("modes");
1032
- let modes = null;
1033
- if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
1034
- if (modes || this.hasAttribute("mode")) {
1035
- let bar = this.querySelector(".c-filter-bar__modes");
1036
- if (!bar) { bar = document.createElement("div"); bar.className = "c-filter-bar__modes"; bar.setAttribute("role", "toolbar"); bar.setAttribute("aria-label", label || "Filter modes"); this.appendChild(bar); }
1037
- bar.innerHTML = "";
1038
- const current = this.getAttribute("mode");
1039
- const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
1040
- list.forEach((m) => {
1041
- const name = typeof m === "string" ? m : (m.label || m.value || m);
1042
- const val = typeof m === "string" ? m : (m.value || m.label || m);
1043
- const btn = document.createElement("button");
1044
- btn.type = "button";
1045
- btn.className = "c-filter-bar__mode";
1046
- btn.textContent = name;
1047
- btn.dataset.mode = val;
1048
- if (current && current === val) btn.setAttribute("aria-pressed", "true");
1049
- bar.appendChild(btn);
1050
- });
1051
- } else {
1052
- const bar = this.querySelector(".c-filter-bar__modes");
1053
- if (bar) bar.remove();
1054
- }
1055
- // Render filter pills from items.
1056
- Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
1057
- const items = remoteData(this, "items");
1058
- // Slotted content: authored .c-filter-pill children take precedence.
1059
- const authoredPills = Array.from(this.querySelectorAll(":scope > .c-filter-pill"));
1060
- let parsed = null;
1061
- if (authoredPills.length) {
1062
- parsed = authoredPills.map((p) => p.textContent.trim());
1063
- authoredPills.forEach((p) => p.remove());
1064
- } else if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
1065
- if (Array.isArray(parsed)) {
1066
- parsed.forEach((it) => {
1067
- const pill = document.createElement("span");
1068
- pill.className = "c-filter-pill";
1069
- const txt = typeof it === "string" ? it : (it.label || it.value || "");
1070
- pill.textContent = txt;
1071
- if (typeof it === "object" && it !== null && it.removable !== false) {
1072
- const btn = document.createElement("button");
1073
- btn.className = "c-filter-pill__remove";
1074
- btn.type = "button";
1075
- btn.setAttribute("aria-label", "Remove " + txt);
1076
- btn.textContent = "×";
1077
- pill.appendChild(btn);
1078
- }
1079
- this.appendChild(pill);
1080
- });
1081
- }
1082
- // Clear-all affordance (CARTO-inspired): panel-level clear with active count.
1083
- Array.from(this.querySelectorAll(".c-filter-bar__clear-all")).forEach((n) => n.remove());
1084
- if (this.hasAttribute("clearable")) {
1085
- const btn = document.createElement("button");
1086
- btn.type = "button";
1087
- btn.className = "c-btn c-btn--ghost c-btn--sm c-filter-bar__clear-all";
1088
- const count = this.getAttribute("count");
1089
- btn.textContent = count ? ("Clear all (" + count + ")") : "Clear all";
1090
- this.appendChild(btn);
1091
- }
1092
- if (!parsed && !label) renderEmpty(this, "filter-bar");
1093
- }
1094
- enhance() {
1095
- wireRemovable(this);
1096
- if (this._wiredFilterBar) return;
1097
- this._wiredFilterBar = true;
1098
- this.addEventListener("click", (e) => {
1099
- const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
1100
- if (!btn || !this.contains(btn)) return;
1101
- const mode = btn.dataset.mode || btn.textContent.trim();
1102
- Array.from(this.querySelectorAll(".c-filter-bar__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
1103
- this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
1104
- });
1105
- this.addEventListener("keydown", (e) => {
1106
- const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
1107
- if (!btn || !this.contains(btn)) return;
1108
- const modes = Array.from(this.querySelectorAll(".c-filter-bar__mode"));
1109
- const idx = modes.indexOf(btn);
1110
- let next = -1;
1111
- if (e.key === "ArrowRight") next = Math.min(modes.length - 1, idx + 1);
1112
- else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
1113
- if (next >= 0) { e.preventDefault(); try { modes[next].focus(); } catch (err) {} }
1114
- else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
1115
- });
1116
- // text input
1117
- const inp = this.querySelector(".c-filter-bar__input");
1118
- if (inp && !inp._wiredFilterInput) {
1119
- inp._wiredFilterInput = true;
1120
- inp.addEventListener("input", () => {
1121
- this.dispatchEvent(new CustomEvent("contour:input", { bubbles: true, composed: true, detail: { value: inp.value } }));
1122
- });
1123
- inp.addEventListener("change", () => {
1124
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
1125
- });
1126
- }
1127
- // Clear-all (CARTO-inspired): delegated on host.
1128
- if (!this._wiredClearAll) {
1129
- this._wiredClearAll = true;
1130
- this.addEventListener("click", (e) => {
1131
- const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__clear-all") : null;
1132
- if (!btn || !this.contains(btn)) return;
1133
- e.preventDefault();
1134
- this.dispatchEvent(new CustomEvent("contour:clear-all", { bubbles: true, composed: true, detail: {} }));
1135
- });
1136
- }
1137
- }
1138
- }
1139
- define("contour-filter-bar", ContourFilterBar);
1140
- class ContourCommand extends ContourBase {
1141
- static get observed() { return ["placeholder", "items", "recent", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1142
- static get properties() { return { placeholder: { attribute: "placeholder" }, items: { attribute: "items" }, recent: { attribute: "recent" }, empty: { attribute: "empty" }, src: { attribute: "src" } }; }
1143
- render() {
1144
- this.classList.add("c-command");
1145
- if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
1146
- if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Command palette");
1147
- if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
1148
- wireStates(this);
1149
- loadRemote(this, "items");
1150
- if (renderStates(this, "command")) return;
1151
- const placeholder = this.getAttribute("placeholder") || "Search…";
1152
- const input = this.ensure(".c-command__input", () => { const el = document.createElement("input"); el.className = "c-command__input"; el.type = "text"; return el; });
1153
- input.type = "text";
1154
- input.placeholder = placeholder;
1155
- input.setAttribute("aria-label", "Command");
1156
- input.setAttribute("role", "combobox");
1157
- input.setAttribute("aria-autocomplete", "list");
1158
- input.setAttribute("aria-expanded", "true");
1159
- const list = this.querySelector(".c-command__list");
1160
- if (list && !list.id) list.id = contourId("c-command-list");
1161
- if (list && list.id) input.setAttribute("aria-controls", list.id);
1162
- const items = remoteData(this, "items");
1163
- const list2 = this.querySelector(".c-command__list");
1164
- const authored = list2 ? Array.from(list2.children).filter((n) => n.classList && n.classList.contains("c-command__item") || n.classList && n.classList.contains("c-command__group")) : [];
1165
- if (items && !authored.length) {
1166
- try {
1167
- const parsed = JSON.parse(items);
1168
- const l = this.ensure(".c-command__list", () => { const el = document.createElement("div"); el.className = "c-command__list"; el.setAttribute("role", "listbox"); el.id = contourId("c-command-list"); return el; });
1169
- l.setAttribute("role", "listbox");
1170
- l.innerHTML = "";
1171
- const recentRaw = this.getAttribute("recent");
1172
- if (recentRaw) {
1173
- try {
1174
- const recentParsed = JSON.parse(recentRaw);
1175
- const group = document.createElement("div");
1176
- group.className = "c-command__group";
1177
- const gt = document.createElement("div");
1178
- gt.className = "c-command__group-title";
1179
- gt.textContent = "Recent";
1180
- group.appendChild(gt);
1181
- recentParsed.forEach((it) => {
1182
- const item = document.createElement("div");
1183
- item.className = "c-command__item";
1184
- item.setAttribute("role", "option");
1185
- const body = document.createElement("div");
1186
- body.className = "c-command__item-body";
1187
- const t = document.createElement("div");
1188
- t.className = "c-command__item-title";
1189
- t.textContent = typeof it === "string" ? it : (it.title || it.label || "");
1190
- body.appendChild(t);
1191
- item.appendChild(body);
1192
- group.appendChild(item);
1193
- });
1194
- l.appendChild(group);
1195
- } catch (e) { /* skip */ }
1196
- }
1197
- parsed.forEach((it) => {
1198
- if (it.group) {
1199
- const group = document.createElement("div");
1200
- group.className = "c-command__group";
1201
- const gt = document.createElement("div");
1202
- gt.className = "c-command__group-title";
1203
- gt.textContent = it.group;
1204
- group.appendChild(gt);
1205
- const item = document.createElement("div");
1206
- item.className = "c-command__item";
1207
- item.setAttribute("role", "option");
1208
- if (it.icon) {
1209
- const ic = document.createElement("span");
1210
- ic.className = "c-command__item-icon";
1211
- ic.textContent = it.icon;
1212
- item.appendChild(ic);
1213
- }
1214
- const body = document.createElement("div");
1215
- body.className = "c-command__item-body";
1216
- if (it.title || it.label) {
1217
- const t = document.createElement("div");
1218
- t.className = "c-command__item-title";
1219
- t.textContent = it.title || it.label;
1220
- body.appendChild(t);
1221
- }
1222
- if (it.hint) {
1223
- const h = document.createElement("span");
1224
- h.className = "c-command__item-hint";
1225
- h.textContent = it.hint;
1226
- body.appendChild(h);
1227
- }
1228
- if (it.shortcut) {
1229
- const sc = document.createElement("kbd");
1230
- sc.className = "c-command__item-shortcut";
1231
- sc.textContent = it.shortcut;
1232
- item.appendChild(sc);
1233
- }
1234
- item.appendChild(body);
1235
- group.appendChild(item);
1236
- l.appendChild(group);
1237
- } else {
1238
- const item = document.createElement("div");
1239
- item.className = "c-command__item";
1240
- item.setAttribute("role", "option");
1241
- if (it.icon) {
1242
- const ic = document.createElement("span");
1243
- ic.className = "c-command__item-icon";
1244
- ic.textContent = it.icon;
1245
- item.appendChild(ic);
1246
- }
1247
- const body = document.createElement("div");
1248
- body.className = "c-command__item-body";
1249
- if (it.title || it.label) {
1250
- const t = document.createElement("div");
1251
- t.className = "c-command__item-title";
1252
- t.textContent = it.title || it.label;
1253
- body.appendChild(t);
1254
- }
1255
- if (it.hint) {
1256
- const h = document.createElement("span");
1257
- h.className = "c-command__item-hint";
1258
- h.textContent = it.hint;
1259
- body.appendChild(h);
1260
- }
1261
- if (it.shortcut) {
1262
- const sc = document.createElement("kbd");
1263
- sc.className = "c-command__item-shortcut";
1264
- sc.textContent = it.shortcut;
1265
- item.appendChild(sc);
1266
- }
1267
- item.appendChild(body);
1268
- l.appendChild(item);
1269
- }
1270
- });
1271
- } catch (e) { /* keep existing */ }
1272
- } else if (!items && list) {
1273
- list.remove();
1274
- }
1275
- const empty = this.getAttribute("empty");
1276
- if (empty) {
1277
- const e = this.ensure(".c-command__empty", () => { const el = document.createElement("div"); el.className = "c-command__empty"; return el; });
1278
- e.textContent = empty;
1279
- } else {
1280
- const e = this.querySelector(".c-command__empty");
1281
- if (e) e.remove();
1282
- }
1283
- // Live filter results (BY-29). The region must exist EMPTY at mount —
1284
- // the contrast gate refuses a pre-populated live region — and is filled
1285
- // only when typing starts. The option ids the keydown handler writes are
1286
- // the "keyed rows" half; this is the aria-live half.
1287
- const status = this.ensure(".c-command__status", () => { const el = document.createElement("div"); el.className = "c-command__status"; el.setAttribute("role", "status"); return el; });
1288
- status.textContent = "";
1289
- if (!items && !list) {
1290
- renderEmpty(this, "command");
1291
- }
1292
- }
1293
- enhance() {
1294
- if (this._wiredCommand) return;
1295
- this._wiredCommand = true;
1296
- const input = () => this.querySelector(".c-command__input");
1297
- const items = () => Array.from(this.querySelectorAll(".c-command__item"));
1298
- let cursor = -1;
1299
- const mark = () => {
1300
- items().forEach((it, i) => {
1301
- it.classList.toggle("c-command__item--active", i === cursor);
1302
- it.setAttribute("aria-selected", String(i === cursor));
1303
- if (i === cursor) {
1304
- if (!it.id) it.id = "contour-command-option-" + i;
1305
- const inp = input();
1306
- if (inp) inp.setAttribute("aria-activedescendant", it.id);
1307
- }
1308
- });
1309
- if (cursor < 0) {
1310
- const inp = input();
1311
- if (inp) inp.removeAttribute("aria-activedescendant");
1312
- }
1313
- };
1314
- this.addEventListener("keydown", (e) => {
1315
- const inp = input();
1316
- if (!inp || e.target !== inp) return;
1317
- const its = items();
1318
- if (!its.length) return;
1319
- if (e.key === "ArrowDown") { e.preventDefault(); cursor = Math.min(cursor + 1, its.length - 1); mark(); }
1320
- else if (e.key === "ArrowUp") { e.preventDefault(); cursor = Math.max(cursor - 1, 0); mark(); }
1321
- else if (e.key === "Home") { e.preventDefault(); cursor = 0; mark(); }
1322
- else if (e.key === "End") { e.preventDefault(); cursor = its.length - 1; mark(); }
1323
- else if (e.key === "Enter") {
1324
- e.preventDefault();
1325
- if (cursor >= 0 && its[cursor]) {
1326
- const item = its[cursor];
1327
- const idx = items().indexOf(item);
1328
- this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
1329
- }
1330
- } else if (e.key === "Escape") {
1331
- if (typeof this.hidePopover === "function") this.hidePopover();
1332
- }
1333
- });
1334
- this.addEventListener("click", (e) => {
1335
- const item = e.target && e.target.closest ? e.target.closest(".c-command__item") : null;
1336
- if (item && this.contains(item)) {
1337
- const idx = items().indexOf(item);
1338
- this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
1339
- }
1340
- });
1341
- // Filter (BY-29): typing narrows the option set. The region was created
1342
- // empty at mount; only a real query fills it, so a mount announces
1343
- // nothing. Hidden items are taken out of the cursor walk, matching the
1344
- // tree/keydown roving: cursor is reset and aria-activedescendant cleared
1345
- // so the next mark() cannot point at a hidden option.
1346
- this.addEventListener("input", (e) => {
1347
- const inp = input();
1348
- if (!inp || e.target !== inp) return;
1349
- const q = inp.value.trim().toLowerCase();
1350
- const all = items();
1351
- let visible = 0;
1352
- all.forEach((it) => {
1353
- const match = !q || (it.textContent || "").toLowerCase().includes(q);
1354
- it.hidden = !match;
1355
- if (match) visible += 1;
1356
- });
1357
- this.querySelectorAll(".c-command__group").forEach((g) => {
1358
- const hasVisible = Array.from(g.querySelectorAll(".c-command__item")).some((it) => !it.hidden);
1359
- g.hidden = !hasVisible;
1360
- });
1361
- cursor = -1;
1362
- mark();
1363
- const status = this.querySelector(".c-command__status");
1364
- if (status) status.textContent = q ? `${visible} of ${all.length}` : "";
1365
- });
1366
- }
1367
- }
1368
- define("contour-command", ContourCommand);
1369
- class ContourFooter extends ContourBase {
1370
- static get observed() { return ["brand", "note", "links", "cols", "heading"]; }
1371
- static get properties() { return { brand: { attribute: "brand" }, note: { attribute: "note" }, links: { attribute: "links" }, cols: { attribute: "cols" } }; }
1372
- render() {
1373
- this.classList.add("c-footer");
1374
- const brand = this.getAttribute("brand");
1375
- if (brand) {
1376
- const b = this.ensure(".c-footer__brand", () => { const el = document.createElement("div"); el.className = "c-footer__brand"; return el; });
1377
- b.textContent = brand;
1378
- } else {
1379
- const b = this.querySelector(".c-footer__brand");
1380
- if (b) b.remove();
1381
- }
1382
- const note = this.getAttribute("note");
1383
- if (note) {
1384
- const n = this.ensure(".c-footer__note", () => { const el = document.createElement("p"); el.className = "c-footer__note"; return el; });
1385
- n.textContent = note;
1386
- } else {
1387
- const n = this.querySelector(".c-footer__note");
1388
- if (n) n.remove();
1389
- }
1390
- const links = this.getAttribute("links");
1391
- if (links) {
1392
- try {
1393
- const parsed = JSON.parse(links);
1394
- const wrap = this.ensure(".c-footer__links", () => { const el = document.createElement("div"); el.className = "c-footer__links"; return el; });
1395
- wrap.innerHTML = "";
1396
- parsed.forEach((l) => {
1397
- const a = document.createElement("a");
1398
- a.href = typeof l === "string" ? "#" : (l.href || "#");
1399
- a.textContent = typeof l === "string" ? l : (l.label || l);
1400
- wrap.appendChild(a);
1401
- });
1402
- } catch (e) { /* keep existing */ }
1403
- } else {
1404
- const w = this.querySelector(".c-footer__links");
1405
- if (w) w.remove();
1406
- }
1407
- const cols = this.getAttribute("cols");
1408
- if (cols) {
1409
- try {
1410
- const parsed = JSON.parse(cols);
1411
- // Remove previous cols
1412
- this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
1413
- parsed.forEach((col) => {
1414
- const c = document.createElement("div");
1415
- c.className = "c-footer__col";
1416
- if (col.title) {
1417
- const h = document.createElement(headingTag(this, "h3"));
1418
- h.textContent = col.title;
1419
- c.appendChild(h);
1420
- }
1421
- (col.links || []).forEach((l) => {
1422
- const a = document.createElement("a");
1423
- a.href = typeof l === "string" ? "#" : (l.href || "#");
1424
- a.textContent = typeof l === "string" ? l : (l.label || l);
1425
- c.appendChild(a);
1426
- });
1427
- this.appendChild(c);
1428
- });
1429
- } catch (e) { /* keep existing */ }
1430
- } else {
1431
- this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
1432
- }
1433
- }
1434
- }
1435
- define("contour-footer", ContourFooter);
1436
- class ContourSchemeToggle extends ContourBase {
1437
- static get observed() { return []; }
1438
- render() { this.classList.add("c-scheme-toggle"); }
1439
- enhance() {
1440
- if (this._wiredScheme) return;
1441
- this._wiredScheme = true;
1442
- this.addEventListener("click", () => {
1443
- const root = document.documentElement;
1444
- root.classList.add("is-theme-switching");
1445
- const current = root.getAttribute("data-theme") || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
1446
- const next = current === "dark" ? "light" : "dark";
1447
- root.setAttribute("data-theme", next);
1448
- try { localStorage.setItem("contour-theme", next); } catch (e) {}
1449
- requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove("is-theme-switching")));
1450
- this.dispatchEvent(new CustomEvent("contour:theme-change", { detail: { theme: next }, bubbles: true, composed: true }));
1451
- });
1452
- // restore persisted theme on connect
1453
- try {
1454
- const stored = localStorage.getItem("contour-theme");
1455
- if (stored) document.documentElement.setAttribute("data-theme", stored);
1456
- } catch (e) {}
1457
- }
1458
- }
1459
- define("contour-scheme-toggle", ContourSchemeToggle);
1460
- class ContourSidebar extends ContourBase {
1461
- static get observed() { return ["title", "items", "collapsed"]; }
1462
- static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
1463
- render() {
1464
- this.classList.add("c-sidebar");
1465
- if (this.hasAttribute("collapsed")) this.classList.add("c-sidebar--collapsed"); else this.classList.remove("c-sidebar--collapsed");
1466
- const title = this.getAttribute("title");
1467
- if (title) {
1468
- const t = this.ensure(".c-sidebar__title", () => { const el = document.createElement("div"); el.className = "c-sidebar__title"; return el; });
1469
- t.textContent = title;
1470
- } else {
1471
- const t = this.querySelector(".c-sidebar__title");
1472
- if (t) t.remove();
1473
- }
1474
- const items = this.getAttribute("items");
1475
- if (items) {
1476
- try {
1477
- const parsed = JSON.parse(items);
1478
- const nav = this.ensure("nav.c-sidebar__nav", () => { const el = document.createElement("nav"); el.className = "c-sidebar__nav"; return el; });
1479
- nav.innerHTML = "";
1480
- parsed.forEach((it) => {
1481
- const a = document.createElement("a");
1482
- a.className = "c-sidebar__link";
1483
- a.href = (it && it.href) || "#";
1484
- a.textContent = (it && (it.label || it)) || "";
1485
- nav.appendChild(a);
1486
- });
1487
- } catch (e) { /* keep existing */ }
1488
- }
1489
- }
1490
- enhance() {
1491
- if (this._wiredSidebar) return;
1492
- this._wiredSidebar = true;
1493
- this.addEventListener("click", (e) => {
1494
- const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
1495
- if (!btn || !this.contains(btn)) return;
1496
- this.toggleAttribute("collapsed");
1497
- });
1498
- }
1499
- }
1500
- define("contour-sidebar", ContourSidebar);
1501
- class ContourToolbar extends ContourBase {
1502
- static get observed() { return ["title", "actions", "overflow"]; }
1503
- static get properties() { return { title: { attribute: "title" }, actions: { attribute: "actions" }, overflow: { attribute: "overflow", type: Number } }; }
1504
- render() {
1505
- this.classList.add("c-toolbar");
1506
- const title = this.getAttribute("title");
1507
- this.setAttribute("role", "toolbar");
1508
- if (title) this.setAttribute("aria-label", title);
1509
- const actions = this.getAttribute("actions");
1510
- if (actions) {
1511
- try {
1512
- const parsed = JSON.parse(actions);
1513
- const limit = this.overflow && this.overflow > 0 ? this.overflow : parsed.length;
1514
- const visible = parsed.slice(0, limit);
1515
- const excess = parsed.slice(limit);
1516
- visible.forEach((a) => {
1517
- const btn = document.createElement("button");
1518
- btn.className = "c-toolbar__btn";
1519
- btn.type = "button";
1520
- btn.textContent = typeof a === "string" ? a : (a.label || a);
1521
- this.appendChild(btn);
1522
- });
1523
- if (excess.length) {
1524
- const wrap = document.createElement("div");
1525
- wrap.className = "c-toolbar__overflow";
1526
- const btn = document.createElement("button");
1527
- btn.className = "c-toolbar__btn c-toolbar__overflow-btn";
1528
- btn.type = "button";
1529
- btn.setAttribute("aria-haspopup", "menu");
1530
- btn.setAttribute("aria-expanded", "false");
1531
- btn.textContent = "…";
1532
- wrap.appendChild(btn);
1533
- const menu = document.createElement("div");
1534
- menu.className = "c-toolbar__overflow-menu";
1535
- menu.setAttribute("role", "menu");
1536
- menu.setAttribute("hidden", "");
1537
- excess.forEach((a) => {
1538
- const mbtn = document.createElement("button");
1539
- mbtn.className = "c-toolbar__btn";
1540
- mbtn.type = "button";
1541
- mbtn.setAttribute("role", "menuitem");
1542
- mbtn.textContent = typeof a === "string" ? a : (a.label || a);
1543
- menu.appendChild(mbtn);
1544
- });
1545
- wrap.appendChild(menu);
1546
- this.appendChild(wrap);
1547
- }
1548
- } catch (e) { /* keep existing */ }
1549
- }
1550
- }
1551
- enhance() {
1552
- if (this._wiredToolbar) return;
1553
- this._wiredToolbar = true;
1554
- this.addEventListener("click", (e) => {
1555
- const btn = e.target && e.target.closest ? e.target.closest(".c-toolbar__overflow-btn") : null;
1556
- if (!btn || !this.contains(btn)) return;
1557
- const menu = btn.parentElement && btn.parentElement.querySelector(".c-toolbar__overflow-menu");
1558
- if (!menu) return;
1559
- const open = menu.hasAttribute("hidden");
1560
- if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
1561
- btn.setAttribute("aria-expanded", String(open));
1562
- });
1563
- }
1564
- }
1565
- define("contour-toolbar", ContourToolbar);
1566
-
1567
1
  /**
1568
- * Spatial filter (CARTO-inspired): draw-on-map affordance. Engine-agnostic:
1569
- * Contour renders the mode toolbar and emits `contour:draw-start`/`contour:draw-end`
1570
- * (with a geometry payload) and `contour:clear`; the consumer runs the spatial
1571
- * query against its map engine.
1572
- * Attributes: `modes`, `mode`, `active`, `empty`, `loading`, `error`, `retry`,
1573
- * `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2
+ * Navigation family barrel — the navigation-surface web components, split into
3
+ * semantic fragments. Importing this module registers every navigation
4
+ * component (the fragments are side-effectful: each defines its own custom
5
+ * elements). The build concatenates the fragments for the IIFE/ESM bundles;
6
+ * this barrel keeps `contour-ds/wc/navigation.mjs` working for consumers who
7
+ * import the family by name.
1574
8
  */
1575
- class ContourSpatialFilter extends ContourBase {
1576
- static get observed() { return ["modes", "mode", "active", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1577
- static get properties() { return { modes: { attribute: "modes" }, mode: { attribute: "mode" }, active: { attribute: "active" }, src: { attribute: "src" } }; }
1578
- render() {
1579
- this.classList.add("c-spatial-filter");
1580
- wireStates(this);
1581
- loadRemote(this, []);
1582
- if (renderStates(this, "spatial-filter")) return;
1583
- const modesAttr = this.getAttribute("modes");
1584
- let modes = null;
1585
- if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
1586
- const list = Array.isArray(modes) ? modes : ["rect", "circle", "polygon", "clear"];
1587
- let bar = this.querySelector(".c-spatial-filter__modes");
1588
- if (!bar) { bar = document.createElement("div"); bar.className = "c-spatial-filter__modes"; bar.setAttribute("role", "toolbar"); this.appendChild(bar); }
1589
- bar.innerHTML = "";
1590
- const current = this.getAttribute("mode");
1591
- list.forEach((m) => {
1592
- const name = typeof m === "string" ? m : (m.label || m.value || m);
1593
- const val = typeof m === "string" ? m : (m.value || m.label || m);
1594
- const btn = document.createElement("button");
1595
- btn.type = "button";
1596
- btn.className = "c-spatial-filter__mode c-btn c-btn--ghost c-btn--sm";
1597
- btn.textContent = name;
1598
- btn.dataset.mode = val;
1599
- if (current && current === val) btn.setAttribute("aria-pressed", "true");
1600
- bar.appendChild(btn);
1601
- });
1602
- if (this.hasAttribute("active")) {
1603
- this.classList.add("c-spatial-filter--active");
1604
- } else {
1605
- this.classList.remove("c-spatial-filter--active");
1606
- }
1607
- }
1608
- enhance() {
1609
- if (this._wiredSpatialFilter) return;
1610
- this._wiredSpatialFilter = true;
1611
- this.addEventListener("click", (e) => {
1612
- const btn = e.target && e.target.closest ? e.target.closest(".c-spatial-filter__mode") : null;
1613
- if (!btn || !this.contains(btn)) return;
1614
- const mode = btn.dataset.mode || btn.textContent.trim();
1615
- if (mode === "clear") {
1616
- this.classList.remove("c-spatial-filter--active");
1617
- Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
1618
- this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
1619
- return;
1620
- }
1621
- this.classList.add("c-spatial-filter--active");
1622
- Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
1623
- this.dispatchEvent(new CustomEvent("contour:draw-start", { bubbles: true, composed: true, detail: { mode } }));
1624
- });
1625
- this.addEventListener("keydown", (e) => {
1626
- const btn = e.target && e.target.closest ? e.target.closest(".c-spatial-filter__mode") : null;
1627
- if (!btn || !this.contains(btn)) return;
1628
- const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
1629
- const idx = modes.indexOf(btn);
1630
- let next = -1;
1631
- if (e.key === "ArrowRight") next = Math.min(modes.length - 1, idx + 1);
1632
- else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
1633
- if (next >= 0) { e.preventDefault(); try { modes[next].focus(); } catch (err) {} }
1634
- else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
1635
- });
1636
- }
1637
- }
1638
- define("contour-spatial-filter", ContourSpatialFilter);
9
+ import "./navigation-menu.mjs";
10
+ import "./navigation-shell.mjs";
11
+ import "./navigation-tree.mjs";