contour-ds 1.7.2 → 1.8.1
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.
- package/README.md +80 -11
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +181 -104
- package/dist/contour-wc-content.esm.js +5125 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +8654 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +8260 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +4305 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +4917 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +5688 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +4580 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +4174 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +5205 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +4264 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +5844 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +9009 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +6109 -1641
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +6108 -1641
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.code-snippets +4512 -0
- package/dist/contour.components.json +2597 -799
- package/dist/contour.css +5275 -4050
- package/dist/contour.d.ts +560 -1085
- package/dist/contour.esm.js +7 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +10311 -0
- package/dist/contour.js +7 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +420 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.tokens.json +940 -902
- package/dist/contour.vue.d.ts +418 -0
- package/dist/contour.web-types.json +10703 -0
- package/dist/custom-elements.json +30708 -0
- package/dist/docs/actions.md +3 -2
- package/dist/docs/affordances.md +23 -9
- package/dist/docs/apireference.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/componentindex.md +6 -2
- package/dist/docs/data.md +7 -2
- package/dist/docs/docs.md +9 -2
- package/dist/docs/feedback.md +1 -1
- package/dist/docs/field.md +1 -1
- package/dist/docs/forms.md +1 -1
- package/dist/docs/index.json +22 -20
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +19 -2
- package/dist/docs/motion.md +1 -1
- package/dist/docs/navigation.md +1 -1
- package/dist/docs/overlays.md +1 -1
- package/dist/docs/overview.md +1 -1
- package/dist/docs/patterns.md +2 -2
- package/dist/docs/playground.md +22 -2
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +13 -8
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +14 -2
- package/dist/docs/surfaces.md +1 -1
- package/dist/docs/theming.md +1 -1
- package/dist/docs/type.md +1 -1
- package/dist/docs/webcomponents.md +17 -3
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/behaviours.mjs +45 -57
- package/dist/wc/content.mjs +263 -63
- package/dist/wc/core.mjs +390 -71
- package/dist/wc/dashboard.mjs +220 -13
- package/dist/wc/data.mjs +1075 -460
- package/dist/wc/docs.mjs +105 -12
- package/dist/wc/feedback.mjs +63 -14
- package/dist/wc/forms.mjs +733 -104
- package/dist/wc/index.mjs +9 -2
- package/dist/wc/interaction.mjs +182 -28
- package/dist/wc/layout.mjs +95 -25
- package/dist/wc/map.mjs +185 -118
- package/dist/wc/misc.mjs +124 -24
- package/dist/wc/navigation.mjs +384 -115
- package/dist/wc/shadow.mjs +94 -18
- package/dist/wc/states.mjs +21 -3
- package/dist/wc/svg.mjs +104 -0
- package/dist/wc/ui.mjs +1988 -476
- package/integrations/README.md +2 -0
- package/integrations/ai/CLAUDE.md +3 -3
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +5 -6
- package/package.json +53 -24
package/dist/wc/navigation.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag } from './core.mjs';
|
|
1
|
+
import { ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag, navKey, safeHref, cssLength , warnBadJson, labelText, applyLabel } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
3
|
import { wireMenu, wirePagination, wireTabs, wireTree, wireRemovable } from './behaviours.mjs';
|
|
4
4
|
class ContourMenu extends ContourBase {
|
|
@@ -12,16 +12,42 @@ class ContourMenu extends ContourBase {
|
|
|
12
12
|
if (renderStates(this, "menu")) return;
|
|
13
13
|
const items = remoteData(this, "items");
|
|
14
14
|
// Slot composition wins over the JSON attribute.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
// Authored menu items (li[role="menuitem"] or li.c-menu__item in light DOM)
|
|
16
|
+
// are used as-is; the JSON `items` attribute only fills in when the host
|
|
17
|
+
// has no authored menu content.
|
|
18
|
+
const authoredItems = Array.from(this.querySelectorAll("li[role='menuitem'], li.c-menu__item, [role='menuitem']"));
|
|
19
|
+
const authoredUl = this.querySelector("ul.c-menu");
|
|
20
|
+
if (authoredItems.length) {
|
|
21
|
+
// Ensure authored items are inside a ul.c-menu wrapper.
|
|
22
|
+
if (!authoredUl) {
|
|
23
|
+
const ul = document.createElement("ul");
|
|
24
|
+
ul.className = "c-menu";
|
|
25
|
+
ul.setAttribute("role", "menu");
|
|
26
|
+
// Re-parent authored items into the wrapper, preserving order.
|
|
27
|
+
for (const item of authoredItems) {
|
|
28
|
+
if (item.parentElement === this) ul.appendChild(item);
|
|
29
|
+
}
|
|
30
|
+
this.appendChild(ul);
|
|
31
|
+
} else {
|
|
32
|
+
// Ensure classes/roles on authored items inside the existing wrapper.
|
|
33
|
+
for (const item of authoredItems) {
|
|
34
|
+
if (!item.classList.contains("c-menu__item")) item.classList.add("c-menu__item");
|
|
35
|
+
if (!item.getAttribute("role")) item.setAttribute("role", "menuitem");
|
|
36
|
+
if (!item.hasAttribute("tabindex")) item.setAttribute("tabindex", "-1");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Set the first enabled item to tabindex 0 for roving focus.
|
|
40
|
+
const first = authoredItems.find((it) => it.getAttribute("aria-disabled") !== "true");
|
|
41
|
+
if (first) first.setAttribute("tabindex", "0");
|
|
42
|
+
this.classList.remove("c-menu");
|
|
43
|
+
if (authoredUl) authoredUl.classList.add("c-menu");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (authoredUl) {
|
|
47
|
+
// Authored ul.c-menu exists but no menu items yet: keep it, don't generate.
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (items) {
|
|
25
51
|
try {
|
|
26
52
|
const parsed = JSON.parse(items);
|
|
27
53
|
const ul = this.ensure("ul.c-menu", () => { const el = document.createElement("ul"); el.className = "c-menu"; el.setAttribute("role", "menu"); return el; });
|
|
@@ -71,7 +97,10 @@ class ContourMenu extends ContourBase {
|
|
|
71
97
|
} else {
|
|
72
98
|
const li = document.createElement("li");
|
|
73
99
|
li.className = "c-menu__item" + (item.danger ? " c-menu__item--danger" : "") + (item.disabled ? " c-menu__item--disabled" : "");
|
|
74
|
-
|
|
100
|
+
// A checkbox/radio item carries its state, not just a label.
|
|
101
|
+
const role = item.type === "checkbox" ? "menuitemcheckbox" : item.type === "radio" ? "menuitemradio" : "menuitem";
|
|
102
|
+
li.setAttribute("role", role);
|
|
103
|
+
if (item.type === "checkbox" || item.type === "radio") li.setAttribute("aria-checked", String(!!item.checked));
|
|
75
104
|
if (item.disabled) li.setAttribute("aria-disabled", "true");
|
|
76
105
|
if (item.items && Array.isArray(item.items)) {
|
|
77
106
|
li.setAttribute("aria-haspopup", "menu");
|
|
@@ -89,13 +118,34 @@ class ContourMenu extends ContourBase {
|
|
|
89
118
|
sc.textContent = item.shortcut;
|
|
90
119
|
li.appendChild(sc);
|
|
91
120
|
}
|
|
121
|
+
// Build the nested submenu the haspopup promised: without it the
|
|
122
|
+
// item advertises a menu that opens onto nothing.
|
|
123
|
+
if (item.items && Array.isArray(item.items)) {
|
|
124
|
+
const sub = document.createElement("ul");
|
|
125
|
+
sub.className = "c-menu";
|
|
126
|
+
sub.setAttribute("role", "menu");
|
|
127
|
+
item.items.forEach((subItem) => {
|
|
128
|
+
const sli = document.createElement("li");
|
|
129
|
+
sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
|
|
130
|
+
sli.setAttribute("role", "menuitem");
|
|
131
|
+
if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
|
|
132
|
+
if (subItem.label || subItem.title) {
|
|
133
|
+
const sl = document.createElement("span");
|
|
134
|
+
sl.className = "c-menu__label";
|
|
135
|
+
sl.textContent = subItem.label || subItem.title || "";
|
|
136
|
+
sli.appendChild(sl);
|
|
137
|
+
}
|
|
138
|
+
sub.appendChild(sli);
|
|
139
|
+
});
|
|
140
|
+
li.appendChild(sub);
|
|
141
|
+
}
|
|
92
142
|
ul.appendChild(li);
|
|
93
143
|
}
|
|
94
144
|
});
|
|
95
145
|
if (ul.parentNode !== this) this.appendChild(ul);
|
|
96
146
|
this.classList.remove("c-menu");
|
|
97
147
|
ul.classList.add("c-menu");
|
|
98
|
-
} catch (e) {
|
|
148
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
99
149
|
} else {
|
|
100
150
|
renderEmpty(this, "menu");
|
|
101
151
|
}
|
|
@@ -115,10 +165,59 @@ class ContourTabs extends ContourBase {
|
|
|
115
165
|
if (renderStates(this, "tabs")) return;
|
|
116
166
|
const tabs = remoteData(this, "tabs");
|
|
117
167
|
// Slot composition wins over the JSON attribute, same as ContourMenu:
|
|
118
|
-
// authored tab buttons and panels
|
|
119
|
-
// JSON
|
|
120
|
-
|
|
121
|
-
|
|
168
|
+
// authored tab buttons ([role='tab']) and panels (.c-tabs__panel) in light
|
|
169
|
+
// DOM are used as-is; the JSON `tabs` attribute only fills in when the host
|
|
170
|
+
// has no authored tab content.
|
|
171
|
+
const authoredTabs = Array.from(this.querySelectorAll("[role='tab']"));
|
|
172
|
+
const authoredList = this.querySelector(".c-tabs__list");
|
|
173
|
+
const authoredPanels = Array.from(this.querySelectorAll(".c-tabs__panel"));
|
|
174
|
+
|
|
175
|
+
if (authoredTabs.length) {
|
|
176
|
+
// Ensure authored tabs are inside a .c-tabs__list wrapper.
|
|
177
|
+
if (!authoredList) {
|
|
178
|
+
const list = document.createElement("div");
|
|
179
|
+
list.className = "c-tabs__list";
|
|
180
|
+
list.setAttribute("role", "tablist");
|
|
181
|
+
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
182
|
+
list.setAttribute("aria-orientation", orientation);
|
|
183
|
+
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
184
|
+
for (const tab of authoredTabs) {
|
|
185
|
+
if (tab.parentElement === this) list.appendChild(tab);
|
|
186
|
+
}
|
|
187
|
+
this.prepend(list);
|
|
188
|
+
}
|
|
189
|
+
// Normalise attributes on authored tabs and link panels.
|
|
190
|
+
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
191
|
+
if (authoredList) authoredList.setAttribute("aria-orientation", orientation);
|
|
192
|
+
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
193
|
+
|
|
194
|
+
authoredTabs.forEach((tab, i) => {
|
|
195
|
+
if (!tab.classList.contains("c-tabs__tab")) tab.classList.add("c-tabs__tab");
|
|
196
|
+
if (!tab.getAttribute("role")) tab.setAttribute("role", "tab");
|
|
197
|
+
let panelId = tab.getAttribute("aria-controls");
|
|
198
|
+
if (!panelId) {
|
|
199
|
+
panelId = contourId("c-tabs-panel");
|
|
200
|
+
tab.setAttribute("aria-controls", panelId);
|
|
201
|
+
let panel = authoredPanels.find((p) => p.id === panelId);
|
|
202
|
+
if (!panel) {
|
|
203
|
+
panel = document.createElement("div");
|
|
204
|
+
panel.className = "c-tabs__panel";
|
|
205
|
+
panel.id = panelId;
|
|
206
|
+
panel.setAttribute("role", "tabpanel");
|
|
207
|
+
this.appendChild(panel);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const selected = i === 0 || tab.getAttribute("aria-selected") === "true";
|
|
211
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
212
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
213
|
+
const ctrl = tab.getAttribute("aria-controls");
|
|
214
|
+
const panel = ctrl ? document.getElementById(ctrl) : null;
|
|
215
|
+
if (panel) panel.hidden = !selected;
|
|
216
|
+
});
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (tabs && !authoredTabs.length) {
|
|
122
221
|
try {
|
|
123
222
|
const parsed = JSON.parse(tabs);
|
|
124
223
|
const list = this.ensure(".c-tabs__list", () => { const el = document.createElement("div"); el.className = "c-tabs__list"; el.setAttribute("role", "tablist"); return el; });
|
|
@@ -137,13 +236,22 @@ class ContourTabs extends ContourBase {
|
|
|
137
236
|
parsed.forEach((t, i) => {
|
|
138
237
|
const label = typeof t === "string" ? t : (t.label || t.title || "");
|
|
139
238
|
const panelId = contourId("c-tabs-panel");
|
|
140
|
-
|
|
239
|
+
// A tab is not a <button> when it is closable: HTML forbids
|
|
240
|
+
// interactive content inside a button, so the close control would
|
|
241
|
+
// be invalid markup and unreachable as its own target. The tab is
|
|
242
|
+
// a focusable element with role=tab, and the close is a sibling
|
|
243
|
+
// control inside it.
|
|
244
|
+
const btn = document.createElement(this.hasAttribute("closable") ? "div" : "button");
|
|
141
245
|
btn.className = "c-tabs__tab";
|
|
246
|
+
if (btn.tagName === "BUTTON") btn.type = "button";
|
|
142
247
|
btn.setAttribute("role", "tab");
|
|
143
248
|
btn.setAttribute("aria-selected", String(i === _keepIdx));
|
|
144
249
|
btn.setAttribute("aria-controls", panelId);
|
|
145
250
|
btn.tabIndex = i === _keepIdx ? 0 : -1;
|
|
146
|
-
|
|
251
|
+
const tabLabel = document.createElement("span");
|
|
252
|
+
tabLabel.textContent = label;
|
|
253
|
+
btn.textContent = "";
|
|
254
|
+
btn.appendChild(tabLabel);
|
|
147
255
|
if (this.hasAttribute("closable")) {
|
|
148
256
|
const closeBtn = document.createElement("button");
|
|
149
257
|
closeBtn.type = "button";
|
|
@@ -177,8 +285,8 @@ class ContourTabs extends ContourBase {
|
|
|
177
285
|
this.appendChild(panel);
|
|
178
286
|
});
|
|
179
287
|
if (list.parentNode !== this) this.prepend(list);
|
|
180
|
-
} catch (e) {
|
|
181
|
-
} else if (!tabs && !
|
|
288
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
289
|
+
} else if (!tabs && !authoredTabs.length) {
|
|
182
290
|
const list = this.querySelector(".c-tabs__list");
|
|
183
291
|
if (list) list.remove();
|
|
184
292
|
renderEmpty(this, "tabs");
|
|
@@ -232,6 +340,8 @@ class ContourHeader extends ContourBase {
|
|
|
232
340
|
static get properties() { return { brand: { attribute: "brand" }, links: { attribute: "links" } }; }
|
|
233
341
|
render() {
|
|
234
342
|
this.classList.add("c-header");
|
|
343
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "banner");
|
|
344
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("brand") || "Header");
|
|
235
345
|
const brand = this.getAttribute("brand");
|
|
236
346
|
const links = this.getAttribute("links");
|
|
237
347
|
const inner = this.ensure(".c-header__inner", () => { const el = document.createElement("div"); el.className = "container c-header__inner"; return el; });
|
|
@@ -271,7 +381,7 @@ class ContourHeader extends ContourBase {
|
|
|
271
381
|
nav.innerHTML = "";
|
|
272
382
|
parsed.forEach((l) => {
|
|
273
383
|
const a = document.createElement("a");
|
|
274
|
-
a.href = l.href || "#";
|
|
384
|
+
a.href = safeHref(l.href || "#");
|
|
275
385
|
a.textContent = l.label || l;
|
|
276
386
|
nav.appendChild(a);
|
|
277
387
|
});
|
|
@@ -297,7 +407,9 @@ class ContourHeader extends ContourBase {
|
|
|
297
407
|
// the closest existing menu-like glyph is used with the real label.
|
|
298
408
|
const navEl = inner.querySelector(".c-header__nav");
|
|
299
409
|
if (navEl) {
|
|
300
|
-
|
|
410
|
+
// A page may carry two headers; a fixed id makes both toggles point at the
|
|
411
|
+
// first nav in document order. Each generated nav gets its own id.
|
|
412
|
+
if (!navEl.id) navEl.id = contourId("header-nav");
|
|
301
413
|
const actions = inner.querySelector(".c-header__actions");
|
|
302
414
|
if (actions && !actions.querySelector(".c-header__toggle")) {
|
|
303
415
|
const toggle = document.createElement("button");
|
|
@@ -333,6 +445,7 @@ class ContourHeader extends ContourBase {
|
|
|
333
445
|
if (!nav) return;
|
|
334
446
|
const open = nav.classList.toggle("is-open");
|
|
335
447
|
toggle.setAttribute("aria-expanded", String(open));
|
|
448
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open } }));
|
|
336
449
|
});
|
|
337
450
|
this.addEventListener("keydown", (e) => {
|
|
338
451
|
if (e.key !== "Escape") return;
|
|
@@ -351,7 +464,8 @@ class ContourTree extends ContourBase {
|
|
|
351
464
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
|
|
352
465
|
_itemHeight() {
|
|
353
466
|
const h = Number(this.getAttribute("item-height"));
|
|
354
|
-
|
|
467
|
+
if (Number.isFinite(h) && h > 0) return h;
|
|
468
|
+
return cssLength("--virtual-list-item-height", 28);
|
|
355
469
|
}
|
|
356
470
|
_labelToPaths(nodes, pathPrefix, map) {
|
|
357
471
|
(nodes || []).forEach((node, i) => {
|
|
@@ -586,7 +700,7 @@ render() {
|
|
|
586
700
|
this.classList.remove("c-tree");
|
|
587
701
|
rootUl.classList.add("c-tree");
|
|
588
702
|
if (rootUl.parentNode !== this) this.appendChild(rootUl);
|
|
589
|
-
} catch (e) {
|
|
703
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
590
704
|
} else if (!items && !authored.length) {
|
|
591
705
|
renderEmpty(this, "tree");
|
|
592
706
|
}
|
|
@@ -608,6 +722,7 @@ render() {
|
|
|
608
722
|
toggle.setAttribute("aria-expanded", String(!expanded));
|
|
609
723
|
const row = toggle.closest(".c-tree__row");
|
|
610
724
|
if (row) row.setAttribute("aria-expanded", String(!expanded));
|
|
725
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path, expanded: !expanded } }));
|
|
611
726
|
if (this.hasAttribute("virtual") && this._treeRoot) {
|
|
612
727
|
const s = this._treeRoot;
|
|
613
728
|
this._treeScrollTop = s.scrollTop || 0;
|
|
@@ -728,7 +843,7 @@ class ContourCodeTabs extends ContourBase {
|
|
|
728
843
|
this.appendChild(panel);
|
|
729
844
|
});
|
|
730
845
|
if (l.parentNode !== this) this.prepend(l);
|
|
731
|
-
} catch (e) {
|
|
846
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
732
847
|
} else if (!tabs && list) {
|
|
733
848
|
list.remove();
|
|
734
849
|
renderEmpty(this, "code-tabs");
|
|
@@ -746,6 +861,8 @@ class ContourBreadcrumb extends ContourBase {
|
|
|
746
861
|
static get properties() { return { items: { attribute: "items" }, separator: { attribute: "separator" }, max: { attribute: "max", type: Number }, src: { attribute: "src" } } };
|
|
747
862
|
render() {
|
|
748
863
|
this.classList.add("c-breadcrumb");
|
|
864
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
865
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Breadcrumb");
|
|
749
866
|
wireStates(this);
|
|
750
867
|
loadRemote(this, "items");
|
|
751
868
|
if (renderStates(this, "breadcrumb")) return;
|
|
@@ -757,9 +874,11 @@ class ContourBreadcrumb extends ContourBase {
|
|
|
757
874
|
if (items && !authored.length) {
|
|
758
875
|
try {
|
|
759
876
|
const parsed = JSON.parse(items);
|
|
760
|
-
const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", "Breadcrumb");
|
|
877
|
+
const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", "Breadcrumb"); return el; });
|
|
761
878
|
n.setAttribute("aria-label", "Breadcrumb");
|
|
762
|
-
|
|
879
|
+
// A unique id per instance: two breadcrumbs on a page must not share
|
|
880
|
+
// one, and the overflow button points at this one through aria-controls.
|
|
881
|
+
if (!n.id) n.id = contourId("contour-breadcrumb-list");
|
|
763
882
|
n.innerHTML = "";
|
|
764
883
|
const sep = this.getAttribute("separator") || "/";
|
|
765
884
|
const max = this._overflowExpanded ? null : this.max;
|
|
@@ -772,7 +891,7 @@ class ContourBreadcrumb extends ContourBase {
|
|
|
772
891
|
btn.className = "c-breadcrumb__overflow";
|
|
773
892
|
btn.setAttribute("aria-label", `Show ${parsed.length - shown.length + 1} more items`);
|
|
774
893
|
btn.setAttribute("aria-expanded", "false");
|
|
775
|
-
btn.setAttribute("aria-controls",
|
|
894
|
+
btn.setAttribute("aria-controls", n.id);
|
|
776
895
|
btn.textContent = "…";
|
|
777
896
|
btn.addEventListener("click", () => {
|
|
778
897
|
// A handler-owned property, not an attribute: flipping a
|
|
@@ -780,13 +899,14 @@ class ContourBreadcrumb extends ContourBase {
|
|
|
780
899
|
// (the arm-7 trap), so the flag lives outside OBSERVED.
|
|
781
900
|
this._overflowExpanded = true;
|
|
782
901
|
this.requestRender();
|
|
902
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { expanded: true } }));
|
|
783
903
|
});
|
|
784
904
|
n.appendChild(btn);
|
|
785
905
|
}
|
|
786
906
|
shown.forEach((item, i) => {
|
|
787
907
|
if (i < shown.length - 1) {
|
|
788
908
|
const a = document.createElement("a");
|
|
789
|
-
a.href = item.href || "#";
|
|
909
|
+
a.href = safeHref(item.href || "#");
|
|
790
910
|
a.textContent = item.label || item;
|
|
791
911
|
n.appendChild(a);
|
|
792
912
|
const s = document.createElement("span");
|
|
@@ -801,7 +921,7 @@ class ContourBreadcrumb extends ContourBase {
|
|
|
801
921
|
n.appendChild(span);
|
|
802
922
|
}
|
|
803
923
|
});
|
|
804
|
-
} catch (e) {
|
|
924
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
805
925
|
} else if (!items && nav) {
|
|
806
926
|
nav.remove();
|
|
807
927
|
} else if (!items && !nav) {
|
|
@@ -815,6 +935,10 @@ class ContourPagination extends ContourBase {
|
|
|
815
935
|
static get properties() { return { pages: { attribute: "pages" }, current: { attribute: "current" }, src: { attribute: "src" } }; }
|
|
816
936
|
render() {
|
|
817
937
|
this.classList.add("c-pagination");
|
|
938
|
+
// A pagination control is a navigation landmark: the APG names it, and a
|
|
939
|
+
// screen reader's landmark list is where a reader looks for "page N of M".
|
|
940
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
941
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Pagination");
|
|
818
942
|
wireStates(this);
|
|
819
943
|
loadRemote(this, "pages");
|
|
820
944
|
if (renderStates(this, "pagination")) return;
|
|
@@ -839,7 +963,7 @@ class ContourPagination extends ContourBase {
|
|
|
839
963
|
prev.className = "c-pagination__link c-pagination__prev";
|
|
840
964
|
prev.setAttribute("data-action", "prev");
|
|
841
965
|
prev.textContent = "‹";
|
|
842
|
-
prev.setAttribute("aria-label", "Previous page");
|
|
966
|
+
prev.setAttribute("aria-label", labelText(this, "prev", "Previous page"));
|
|
843
967
|
this.appendChild(prev);
|
|
844
968
|
for (let i = 1; i <= count; i++) {
|
|
845
969
|
const btn = document.createElement("button");
|
|
@@ -857,7 +981,7 @@ class ContourPagination extends ContourBase {
|
|
|
857
981
|
next.className = "c-pagination__link c-pagination__next";
|
|
858
982
|
next.setAttribute("data-action", "next");
|
|
859
983
|
next.textContent = "›";
|
|
860
|
-
next.setAttribute("aria-label", "Next page");
|
|
984
|
+
next.setAttribute("aria-label", labelText(this, "next", "Next page"));
|
|
861
985
|
this.appendChild(next);
|
|
862
986
|
} else {
|
|
863
987
|
renderEmpty(this, "pagination");
|
|
@@ -880,7 +1004,7 @@ class ContourPagerFull extends ContourBase {
|
|
|
880
1004
|
if (prev) {
|
|
881
1005
|
const a = document.createElement("a");
|
|
882
1006
|
a.className = "c-pager__link";
|
|
883
|
-
a.href = prev.split("|")[1] || "#";
|
|
1007
|
+
a.href = safeHref(prev.split("|")[1] || "#");
|
|
884
1008
|
const dir = document.createElement("span");
|
|
885
1009
|
dir.className = "c-pager__dir";
|
|
886
1010
|
dir.textContent = "← Previous";
|
|
@@ -894,10 +1018,10 @@ class ContourPagerFull extends ContourBase {
|
|
|
894
1018
|
if (next) {
|
|
895
1019
|
const a = document.createElement("a");
|
|
896
1020
|
a.className = "c-pager__link c-pager__link--next";
|
|
897
|
-
a.href = next.split("|")[1] || "#";
|
|
1021
|
+
a.href = safeHref(next.split("|")[1] || "#");
|
|
898
1022
|
const dir = document.createElement("span");
|
|
899
1023
|
dir.className = "c-pager__dir";
|
|
900
|
-
dir.textContent = "Next →";
|
|
1024
|
+
dir.textContent = labelText(this, "next", "Next") + " →";
|
|
901
1025
|
a.appendChild(dir);
|
|
902
1026
|
const title = document.createElement("span");
|
|
903
1027
|
title.className = "c-pager__title";
|
|
@@ -913,7 +1037,7 @@ class ContourTocFull extends ContourBase {
|
|
|
913
1037
|
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
914
1038
|
render() {
|
|
915
1039
|
this.classList.add("c-toc");
|
|
916
|
-
this.setAttribute("role", "
|
|
1040
|
+
this.setAttribute("role", "group");
|
|
917
1041
|
wireStates(this);
|
|
918
1042
|
loadRemote(this, "items");
|
|
919
1043
|
if (renderStates(this, "toc")) return;
|
|
@@ -930,15 +1054,16 @@ class ContourTocFull extends ContourBase {
|
|
|
930
1054
|
l.className = "c-toc__list";
|
|
931
1055
|
l.setAttribute("aria-label", title);
|
|
932
1056
|
l.innerHTML = "";
|
|
933
|
-
parsed.forEach((item) => {
|
|
1057
|
+
parsed.forEach((item, i) => {
|
|
934
1058
|
const a = document.createElement("a");
|
|
935
1059
|
a.className = "c-toc__link" + (item.sub ? " c-toc__link--sub" : "");
|
|
936
|
-
a.href = item.href || "#";
|
|
1060
|
+
a.href = safeHref(item.href || "#");
|
|
937
1061
|
a.textContent = item.label || item;
|
|
1062
|
+
a.tabIndex = i === 0 ? 0 : -1;
|
|
938
1063
|
if (item.current) a.setAttribute("aria-current", "true");
|
|
939
1064
|
l.appendChild(a);
|
|
940
1065
|
});
|
|
941
|
-
} catch (e) {
|
|
1066
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
942
1067
|
} else if (!items && list) {
|
|
943
1068
|
list.remove();
|
|
944
1069
|
renderEmpty(this, "toc");
|
|
@@ -947,37 +1072,79 @@ class ContourTocFull extends ContourBase {
|
|
|
947
1072
|
}
|
|
948
1073
|
}
|
|
949
1074
|
enhance() {
|
|
950
|
-
// Scroll-spy (BY-29). The toc links point at page sections by
|
|
951
|
-
//
|
|
1075
|
+
// Scroll-spy (BY-29, CDS-075). The toc links point at page sections by
|
|
1076
|
+
// href; the section whose top has most recently crossed the reading line
|
|
952
1077
|
// marks its link aria-current="true" and clears the rest. The shipped CSS
|
|
953
1078
|
// already styles .c-toc__link[aria-current="true"], so the hook needs no
|
|
954
|
-
// new rule.
|
|
955
|
-
//
|
|
1079
|
+
// new rule.
|
|
1080
|
+
//
|
|
1081
|
+
// This reads geometry on scroll rather than IntersectionObserver: an
|
|
1082
|
+
// observer callback reports the entries that changed, not the current
|
|
1083
|
+
// reading position, so `visible[0]` is whichever section happened to
|
|
1084
|
+
// fire first — order is delivery, not document order. Geometry has one
|
|
1085
|
+
// answer for one scroll position. rAF-throttled, passive listener.
|
|
1086
|
+
// Enhancement-only: without it the links stay as rendered, with any
|
|
1087
|
+
// author-provided aria-current left untouched.
|
|
956
1088
|
if (this._wiredTocSpy) return;
|
|
957
|
-
if (typeof IntersectionObserver !== "function") return;
|
|
958
1089
|
const links = () => Array.from(this.querySelectorAll(".c-toc__link"));
|
|
959
|
-
const
|
|
1090
|
+
const pairs = () => links()
|
|
960
1091
|
.map((a) => {
|
|
961
1092
|
const href = a.getAttribute("href") || "";
|
|
962
1093
|
if (!href.startsWith("#") || href.length < 2) return null;
|
|
963
|
-
|
|
1094
|
+
const el = document.getElementById(href.slice(1));
|
|
1095
|
+
return el ? { a, el } : null;
|
|
964
1096
|
})
|
|
965
1097
|
.filter(Boolean);
|
|
966
|
-
if (!
|
|
1098
|
+
if (!pairs().length) return;
|
|
967
1099
|
this._wiredTocSpy = true;
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1100
|
+
|
|
1101
|
+
const readingLine = () => {
|
|
1102
|
+
const raw = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--header-height"));
|
|
1103
|
+
return (Number.isFinite(raw) ? raw : 0) + Math.min(120, window.innerHeight * 0.2);
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
const update = () => {
|
|
1107
|
+
const all = pairs();
|
|
1108
|
+
if (!all.length) return;
|
|
1109
|
+
const line = readingLine();
|
|
1110
|
+
let current = all[0];
|
|
1111
|
+
for (const p of all) {
|
|
1112
|
+
if (p.el.getBoundingClientRect().top <= line) current = p;
|
|
1113
|
+
}
|
|
1114
|
+
// The last section never crosses the line on a short page; at the
|
|
1115
|
+
// bottom of a scrollable document the last link is the honest answer.
|
|
1116
|
+
// A document shorter than the viewport is not "at the bottom" — it is
|
|
1117
|
+
// simply not scrollable, and the first section is where the reader is.
|
|
1118
|
+
const scrollable = document.documentElement.scrollHeight > window.innerHeight + 2;
|
|
1119
|
+
if (scrollable && window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2) {
|
|
1120
|
+
current = all[all.length - 1];
|
|
1121
|
+
}
|
|
1122
|
+
const id = current.el.id;
|
|
972
1123
|
links().forEach((a) => {
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
else if (
|
|
1124
|
+
const isCurrent = a.getAttribute("href") === "#" + id;
|
|
1125
|
+
if (isCurrent) {
|
|
1126
|
+
if (a.getAttribute("aria-current") !== "true") a.setAttribute("aria-current", "true");
|
|
1127
|
+
} else if (a.hasAttribute("aria-current")) {
|
|
1128
|
+
a.removeAttribute("aria-current");
|
|
1129
|
+
}
|
|
977
1130
|
});
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
let queued = 0;
|
|
1134
|
+
const schedule = () => {
|
|
1135
|
+
if (queued) return;
|
|
1136
|
+
queued = requestAnimationFrame(() => { queued = 0; update(); });
|
|
1137
|
+
};
|
|
1138
|
+
window.addEventListener("scroll", schedule, { passive: true });
|
|
1139
|
+
window.addEventListener("resize", schedule);
|
|
1140
|
+
window.addEventListener("hashchange", schedule);
|
|
1141
|
+
update();
|
|
1142
|
+
onDispose(this, () => {
|
|
1143
|
+
window.removeEventListener("scroll", schedule);
|
|
1144
|
+
window.removeEventListener("resize", schedule);
|
|
1145
|
+
window.removeEventListener("hashchange", schedule);
|
|
1146
|
+
if (queued) cancelAnimationFrame(queued);
|
|
1147
|
+
});
|
|
981
1148
|
// Smooth scroll on link click (F-23).
|
|
982
1149
|
if (!this._wiredTocScroll) {
|
|
983
1150
|
this._wiredTocScroll = true;
|
|
@@ -990,14 +1157,21 @@ class ContourTocFull extends ContourBase {
|
|
|
990
1157
|
if (!target) return;
|
|
991
1158
|
e.preventDefault();
|
|
992
1159
|
try { target.scrollIntoView({ behavior: "smooth", block: "start" }); } catch (err) { target.scrollIntoView(); }
|
|
1160
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { href } }));
|
|
1161
|
+
});
|
|
1162
|
+
// Keyboard: roving tabindex over TOC links, Enter follows the link.
|
|
1163
|
+
this.addEventListener("keydown", (e) => {
|
|
1164
|
+
const links = Array.from(this.querySelectorAll(".c-toc__link"));
|
|
1165
|
+
if (!links.length) return;
|
|
1166
|
+
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(); } } } });
|
|
993
1167
|
});
|
|
994
1168
|
}
|
|
995
1169
|
}
|
|
996
1170
|
}
|
|
997
1171
|
define("contour-toc", ContourTocFull);
|
|
998
1172
|
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" } }; }
|
|
1173
|
+
static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "scope", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "count", "clearable"]; }
|
|
1174
|
+
static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" }, count: { attribute: "count" }, clearable: { attribute: "clearable" }, scope: { attribute: "scope" } }; }
|
|
1001
1175
|
render() {
|
|
1002
1176
|
this.classList.add("c-filter-bar");
|
|
1003
1177
|
wireStates(this);
|
|
@@ -1048,11 +1222,33 @@ class ContourFilterBar extends ContourBase {
|
|
|
1048
1222
|
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
1049
1223
|
bar.appendChild(btn);
|
|
1050
1224
|
});
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1225
|
+
} else {
|
|
1226
|
+
const bar = this.querySelector(".c-filter-bar__modes");
|
|
1227
|
+
if (bar) bar.remove();
|
|
1228
|
+
}
|
|
1229
|
+
// Scope toggle (viewport / global) — CARTO-inspired.
|
|
1230
|
+
const scope = this.getAttribute("scope");
|
|
1231
|
+
if (scope === "viewport" || scope === "global") {
|
|
1232
|
+
Array.from(this.querySelectorAll(".c-filter-bar__scope")).forEach((n) => n.remove());
|
|
1233
|
+
const bar = document.createElement("div");
|
|
1234
|
+
bar.className = "c-filter-bar__modes c-filter-bar__scope";
|
|
1235
|
+
bar.setAttribute("role", "toolbar");
|
|
1236
|
+
bar.setAttribute("aria-label", "Data scope");
|
|
1237
|
+
["viewport", "global"].forEach((s) => {
|
|
1238
|
+
const btn = document.createElement("button");
|
|
1239
|
+
btn.type = "button";
|
|
1240
|
+
btn.className = "c-filter-bar__mode c-filter-bar__scope-btn";
|
|
1241
|
+
btn.textContent = s === "viewport" ? "Viewport" : "Global";
|
|
1242
|
+
btn.dataset.scope = s;
|
|
1243
|
+
if (scope === s) btn.setAttribute("aria-pressed", "true");
|
|
1244
|
+
bar.appendChild(btn);
|
|
1245
|
+
});
|
|
1246
|
+
this.appendChild(bar);
|
|
1247
|
+
} else {
|
|
1248
|
+
const bar = this.querySelector(".c-filter-bar__scope");
|
|
1249
|
+
if (bar) bar.remove();
|
|
1250
|
+
}
|
|
1251
|
+
// Render filter pills from items.
|
|
1056
1252
|
Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
|
|
1057
1253
|
const items = remoteData(this, "items");
|
|
1058
1254
|
// Slotted content: authored .c-filter-pill children take precedence.
|
|
@@ -1095,24 +1291,23 @@ class ContourFilterBar extends ContourBase {
|
|
|
1095
1291
|
wireRemovable(this);
|
|
1096
1292
|
if (this._wiredFilterBar) return;
|
|
1097
1293
|
this._wiredFilterBar = true;
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
});
|
|
1294
|
+
this.addEventListener("click", (e) => {
|
|
1295
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
|
|
1296
|
+
if (!btn || !this.contains(btn)) return;
|
|
1297
|
+
const mode = btn.dataset.mode || btn.textContent.trim();
|
|
1298
|
+
Array.from(this.querySelectorAll(".c-filter-bar__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
1299
|
+
this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
|
|
1300
|
+
// Scope toggle: dispatch contour:scope-change for viewport/global buttons.
|
|
1301
|
+
if (btn.classList.contains("c-filter-bar__scope-btn")) {
|
|
1302
|
+
const scope = btn.dataset.scope || null;
|
|
1303
|
+
if (scope) this.setAttribute("scope", scope);
|
|
1304
|
+
this.dispatchEvent(new CustomEvent("contour:scope-change", { bubbles: true, composed: true, detail: { scope } }));
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
this.addEventListener("keydown", (e) => {
|
|
1308
|
+
const modes = Array.from(this.querySelectorAll(".c-filter-bar__mode"));
|
|
1309
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
1310
|
+
});
|
|
1116
1311
|
// text input
|
|
1117
1312
|
const inp = this.querySelector(".c-filter-bar__input");
|
|
1118
1313
|
if (inp && !inp._wiredFilterInput) {
|
|
@@ -1176,7 +1371,7 @@ class ContourFilterBar extends ContourBase {
|
|
|
1176
1371
|
group.className = "c-command__group";
|
|
1177
1372
|
const gt = document.createElement("div");
|
|
1178
1373
|
gt.className = "c-command__group-title";
|
|
1179
|
-
gt.textContent = "Recent";
|
|
1374
|
+
gt.textContent = labelText(this, "recent", "Recent");
|
|
1180
1375
|
group.appendChild(gt);
|
|
1181
1376
|
recentParsed.forEach((it) => {
|
|
1182
1377
|
const item = document.createElement("div");
|
|
@@ -1268,7 +1463,7 @@ class ContourFilterBar extends ContourBase {
|
|
|
1268
1463
|
l.appendChild(item);
|
|
1269
1464
|
}
|
|
1270
1465
|
});
|
|
1271
|
-
} catch (e) {
|
|
1466
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1272
1467
|
} else if (!items && list) {
|
|
1273
1468
|
list.remove();
|
|
1274
1469
|
}
|
|
@@ -1371,6 +1566,9 @@ class ContourFooter extends ContourBase {
|
|
|
1371
1566
|
static get properties() { return { brand: { attribute: "brand" }, note: { attribute: "note" }, links: { attribute: "links" }, cols: { attribute: "cols" } }; }
|
|
1372
1567
|
render() {
|
|
1373
1568
|
this.classList.add("c-footer");
|
|
1569
|
+
// A footer is a contentinfo landmark: the APG names it, and a reader who
|
|
1570
|
+
// jumps to the landmark list expects the page's footer there.
|
|
1571
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "contentinfo");
|
|
1374
1572
|
const brand = this.getAttribute("brand");
|
|
1375
1573
|
if (brand) {
|
|
1376
1574
|
const b = this.ensure(".c-footer__brand", () => { const el = document.createElement("div"); el.className = "c-footer__brand"; return el; });
|
|
@@ -1395,11 +1593,11 @@ class ContourFooter extends ContourBase {
|
|
|
1395
1593
|
wrap.innerHTML = "";
|
|
1396
1594
|
parsed.forEach((l) => {
|
|
1397
1595
|
const a = document.createElement("a");
|
|
1398
|
-
a.href = typeof l === "string" ? "#" : (l.href || "#");
|
|
1596
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1399
1597
|
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1400
1598
|
wrap.appendChild(a);
|
|
1401
1599
|
});
|
|
1402
|
-
} catch (e) {
|
|
1600
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1403
1601
|
} else {
|
|
1404
1602
|
const w = this.querySelector(".c-footer__links");
|
|
1405
1603
|
if (w) w.remove();
|
|
@@ -1420,13 +1618,13 @@ class ContourFooter extends ContourBase {
|
|
|
1420
1618
|
}
|
|
1421
1619
|
(col.links || []).forEach((l) => {
|
|
1422
1620
|
const a = document.createElement("a");
|
|
1423
|
-
a.href = typeof l === "string" ? "#" : (l.href || "#");
|
|
1621
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1424
1622
|
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1425
1623
|
c.appendChild(a);
|
|
1426
1624
|
});
|
|
1427
1625
|
this.appendChild(c);
|
|
1428
1626
|
});
|
|
1429
|
-
} catch (e) {
|
|
1627
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1430
1628
|
} else {
|
|
1431
1629
|
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
1432
1630
|
}
|
|
@@ -1435,7 +1633,7 @@ class ContourFooter extends ContourBase {
|
|
|
1435
1633
|
define("contour-footer", ContourFooter);
|
|
1436
1634
|
class ContourSchemeToggle extends ContourBase {
|
|
1437
1635
|
static get observed() { return []; }
|
|
1438
|
-
render() { this.classList.add("c-scheme-toggle"); }
|
|
1636
|
+
render() { this.classList.add("c-scheme-toggle"); if (!this.hasAttribute("role")) this.setAttribute("role", "button"); if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0"); if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Toggle color scheme"); }
|
|
1439
1637
|
enhance() {
|
|
1440
1638
|
if (this._wiredScheme) return;
|
|
1441
1639
|
this._wiredScheme = true;
|
|
@@ -1449,6 +1647,12 @@ class ContourSchemeToggle extends ContourBase {
|
|
|
1449
1647
|
requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove("is-theme-switching")));
|
|
1450
1648
|
this.dispatchEvent(new CustomEvent("contour:theme-change", { detail: { theme: next }, bubbles: true, composed: true }));
|
|
1451
1649
|
});
|
|
1650
|
+
this.addEventListener("keydown", (e) => {
|
|
1651
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1652
|
+
e.preventDefault();
|
|
1653
|
+
this.click();
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1452
1656
|
// restore persisted theme on connect
|
|
1453
1657
|
try {
|
|
1454
1658
|
const stored = localStorage.getItem("contour-theme");
|
|
@@ -1462,6 +1666,8 @@ class ContourSidebar extends ContourBase {
|
|
|
1462
1666
|
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
1463
1667
|
render() {
|
|
1464
1668
|
this.classList.add("c-sidebar");
|
|
1669
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
1670
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Sidebar");
|
|
1465
1671
|
if (this.hasAttribute("collapsed")) this.classList.add("c-sidebar--collapsed"); else this.classList.remove("c-sidebar--collapsed");
|
|
1466
1672
|
const title = this.getAttribute("title");
|
|
1467
1673
|
if (title) {
|
|
@@ -1477,14 +1683,15 @@ class ContourSidebar extends ContourBase {
|
|
|
1477
1683
|
const parsed = JSON.parse(items);
|
|
1478
1684
|
const nav = this.ensure("nav.c-sidebar__nav", () => { const el = document.createElement("nav"); el.className = "c-sidebar__nav"; return el; });
|
|
1479
1685
|
nav.innerHTML = "";
|
|
1480
|
-
parsed.forEach((it) => {
|
|
1686
|
+
parsed.forEach((it, i) => {
|
|
1481
1687
|
const a = document.createElement("a");
|
|
1482
1688
|
a.className = "c-sidebar__link";
|
|
1483
|
-
a.href = (it && it.href) || "#";
|
|
1689
|
+
a.href = safeHref((it && it.href) || "#");
|
|
1484
1690
|
a.textContent = (it && (it.label || it)) || "";
|
|
1691
|
+
a.tabIndex = i === 0 ? 0 : -1;
|
|
1485
1692
|
nav.appendChild(a);
|
|
1486
1693
|
});
|
|
1487
|
-
} catch (e) {
|
|
1694
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1488
1695
|
}
|
|
1489
1696
|
}
|
|
1490
1697
|
enhance() {
|
|
@@ -1494,6 +1701,15 @@ class ContourSidebar extends ContourBase {
|
|
|
1494
1701
|
const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
|
|
1495
1702
|
if (!btn || !this.contains(btn)) return;
|
|
1496
1703
|
this.toggleAttribute("collapsed");
|
|
1704
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { collapsed: this.hasAttribute("collapsed") } }));
|
|
1705
|
+
});
|
|
1706
|
+
// Keyboard: roving tabindex over sidebar links, Enter follows the link.
|
|
1707
|
+
this.addEventListener("keydown", (e) => {
|
|
1708
|
+
const nav = this.querySelector("nav.c-sidebar__nav");
|
|
1709
|
+
if (!nav) return;
|
|
1710
|
+
const links = Array.from(nav.querySelectorAll(".c-sidebar__link"));
|
|
1711
|
+
if (!links.length) return;
|
|
1712
|
+
navKey(e, links, { wrap: true, homeEnd: true, onNavigate: (i) => { links.forEach((l, j) => l.tabIndex = j === i ? 0 : -1); }, onKey: (k) => { if (k === "Enter") { const a = document.activeElement; if (a) { e.preventDefault(); a.click(); } } } });
|
|
1497
1713
|
});
|
|
1498
1714
|
}
|
|
1499
1715
|
}
|
|
@@ -1513,10 +1729,11 @@ class ContourToolbar extends ContourBase {
|
|
|
1513
1729
|
const limit = this.overflow && this.overflow > 0 ? this.overflow : parsed.length;
|
|
1514
1730
|
const visible = parsed.slice(0, limit);
|
|
1515
1731
|
const excess = parsed.slice(limit);
|
|
1516
|
-
visible.forEach((a) => {
|
|
1732
|
+
visible.forEach((a, i) => {
|
|
1517
1733
|
const btn = document.createElement("button");
|
|
1518
1734
|
btn.className = "c-toolbar__btn";
|
|
1519
1735
|
btn.type = "button";
|
|
1736
|
+
btn.tabIndex = i === 0 ? 0 : -1;
|
|
1520
1737
|
btn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
1521
1738
|
this.appendChild(btn);
|
|
1522
1739
|
});
|
|
@@ -1545,7 +1762,7 @@ class ContourToolbar extends ContourBase {
|
|
|
1545
1762
|
wrap.appendChild(menu);
|
|
1546
1763
|
this.appendChild(wrap);
|
|
1547
1764
|
}
|
|
1548
|
-
} catch (e) {
|
|
1765
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1549
1766
|
}
|
|
1550
1767
|
}
|
|
1551
1768
|
enhance() {
|
|
@@ -1553,12 +1770,25 @@ class ContourToolbar extends ContourBase {
|
|
|
1553
1770
|
this._wiredToolbar = true;
|
|
1554
1771
|
this.addEventListener("click", (e) => {
|
|
1555
1772
|
const btn = e.target && e.target.closest ? e.target.closest(".c-toolbar__overflow-btn") : null;
|
|
1556
|
-
if (
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1773
|
+
if (btn && this.contains(btn)) {
|
|
1774
|
+
const menu = btn.parentElement && btn.parentElement.querySelector(".c-toolbar__overflow-menu");
|
|
1775
|
+
if (menu) {
|
|
1776
|
+
const open = menu.hasAttribute("hidden");
|
|
1777
|
+
if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
|
|
1778
|
+
btn.setAttribute("aria-expanded", String(open));
|
|
1779
|
+
}
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
const actionBtn = e.target && e.target.closest ? e.target.closest(".c-toolbar__btn") : null;
|
|
1783
|
+
if (actionBtn && this.contains(actionBtn)) {
|
|
1784
|
+
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { label: actionBtn.textContent.trim() } }));
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
// Keyboard: roving tabindex over visible toolbar buttons, Enter/Space activates.
|
|
1788
|
+
this.addEventListener("keydown", (e) => {
|
|
1789
|
+
const btns = Array.from(this.querySelectorAll(":scope > .c-toolbar__btn:not(.c-toolbar__overflow-btn)"));
|
|
1790
|
+
if (!btns.length) return;
|
|
1791
|
+
navKey(e, btns, { wrap: true, homeEnd: true, onNavigate: (i) => { btns.forEach((b, j) => b.tabIndex = j === i ? 0 : -1); }, onKey: (k) => { if (k === "Enter" || k === " ") { const b = document.activeElement; if (b) { e.preventDefault(); b.click(); } } } });
|
|
1562
1792
|
});
|
|
1563
1793
|
}
|
|
1564
1794
|
}
|
|
@@ -1573,10 +1803,11 @@ class ContourToolbar extends ContourBase {
|
|
|
1573
1803
|
* `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1574
1804
|
*/
|
|
1575
1805
|
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" } }; }
|
|
1806
|
+
static get observed() { return ["modes", "mode", "active", "bounds", "operator", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1807
|
+
static get properties() { return { modes: { attribute: "modes" }, mode: { attribute: "mode" }, active: { attribute: "active" }, bounds: { attribute: "bounds" }, operator: { attribute: "operator" }, src: { attribute: "src" } }; }
|
|
1578
1808
|
render() {
|
|
1579
1809
|
this.classList.add("c-spatial-filter");
|
|
1810
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Spatial filter");
|
|
1580
1811
|
wireStates(this);
|
|
1581
1812
|
loadRemote(this, []);
|
|
1582
1813
|
if (renderStates(this, "spatial-filter")) return;
|
|
@@ -1599,6 +1830,34 @@ class ContourSpatialFilter extends ContourBase {
|
|
|
1599
1830
|
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
1600
1831
|
bar.appendChild(btn);
|
|
1601
1832
|
});
|
|
1833
|
+
// Operator selection
|
|
1834
|
+
let operator = this.querySelector(".c-spatial-filter__operator");
|
|
1835
|
+
if (!operator) { operator = document.createElement("div"); operator.className = "c-spatial-filter__operator"; this.appendChild(operator); }
|
|
1836
|
+
const ops = ["intersects", "contains", "within", "disjoint"];
|
|
1837
|
+
const currentOp = this.getAttribute("operator") || "intersects";
|
|
1838
|
+
operator.innerHTML = "";
|
|
1839
|
+
const opLabel = document.createElement("span");
|
|
1840
|
+
opLabel.textContent = labelText(this, "operator", "Operator") + ":";
|
|
1841
|
+
operator.appendChild(opLabel);
|
|
1842
|
+
const opSelect = document.createElement("select");
|
|
1843
|
+
opSelect.className = "c-spatial-filter__operator-select";
|
|
1844
|
+
ops.forEach((op) => {
|
|
1845
|
+
const o = document.createElement("option");
|
|
1846
|
+
o.value = op;
|
|
1847
|
+
o.textContent = op;
|
|
1848
|
+
if (op === currentOp) o.setAttribute("selected", "");
|
|
1849
|
+
opSelect.appendChild(o);
|
|
1850
|
+
});
|
|
1851
|
+
operator.appendChild(opSelect);
|
|
1852
|
+
// Bounds readout
|
|
1853
|
+
let readout = this.querySelector(".c-spatial-filter__readout");
|
|
1854
|
+
if (!readout) { readout = document.createElement("div"); readout.className = "c-spatial-filter__readout"; this.appendChild(readout); }
|
|
1855
|
+
const bounds = this.getAttribute("bounds");
|
|
1856
|
+
readout.textContent = bounds || "—";
|
|
1857
|
+
// Clear all
|
|
1858
|
+
let clearAll = this.querySelector(".c-spatial-filter__clear-all");
|
|
1859
|
+
if (!clearAll) { clearAll = document.createElement("button"); clearAll.type = "button"; clearAll.className = "c-spatial-filter__clear-all"; this.appendChild(clearAll); }
|
|
1860
|
+
applyLabel(clearAll, this, "clear-all", "Clear all");
|
|
1602
1861
|
if (this.hasAttribute("active")) {
|
|
1603
1862
|
this.classList.add("c-spatial-filter--active");
|
|
1604
1863
|
} else {
|
|
@@ -1609,9 +1868,18 @@ class ContourSpatialFilter extends ContourBase {
|
|
|
1609
1868
|
if (this._wiredSpatialFilter) return;
|
|
1610
1869
|
this._wiredSpatialFilter = true;
|
|
1611
1870
|
this.addEventListener("click", (e) => {
|
|
1612
|
-
const btn = e.target && e.target.closest ? e.target.closest("
|
|
1871
|
+
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
1613
1872
|
if (!btn || !this.contains(btn)) return;
|
|
1614
|
-
|
|
1873
|
+
if (btn.classList.contains("c-spatial-filter__clear-all")) {
|
|
1874
|
+
this.classList.remove("c-spatial-filter--active");
|
|
1875
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
1876
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
1877
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "clear-all" } }));
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
const modeBtn = btn.closest(".c-spatial-filter__mode");
|
|
1881
|
+
if (!modeBtn) return;
|
|
1882
|
+
const mode = modeBtn.dataset.mode || modeBtn.textContent.trim();
|
|
1615
1883
|
if (mode === "clear") {
|
|
1616
1884
|
this.classList.remove("c-spatial-filter--active");
|
|
1617
1885
|
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
@@ -1619,19 +1887,20 @@ class ContourSpatialFilter extends ContourBase {
|
|
|
1619
1887
|
return;
|
|
1620
1888
|
}
|
|
1621
1889
|
this.classList.add("c-spatial-filter--active");
|
|
1622
|
-
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b ===
|
|
1890
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === modeBtn)));
|
|
1623
1891
|
this.dispatchEvent(new CustomEvent("contour:draw-start", { bubbles: true, composed: true, detail: { mode } }));
|
|
1892
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "draw-start", mode } }));
|
|
1893
|
+
});
|
|
1894
|
+
this.addEventListener("change", (e) => {
|
|
1895
|
+
const select = e.target;
|
|
1896
|
+
if (select && select.classList.contains("c-spatial-filter__operator-select")) {
|
|
1897
|
+
this.setAttribute("operator", select.value);
|
|
1898
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "operator", operator: select.value } }));
|
|
1899
|
+
}
|
|
1624
1900
|
});
|
|
1625
1901
|
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
1902
|
const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
|
|
1629
|
-
|
|
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(); }
|
|
1903
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
1635
1904
|
});
|
|
1636
1905
|
}
|
|
1637
1906
|
}
|