contour-ds 1.8.1 → 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.
- package/README.md +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- 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/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
package/dist/wc/navigation.mjs
CHANGED
|
@@ -1,1907 +1,11 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag, navKey, safeHref, cssLength , warnBadJson, labelText, applyLabel } 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
|
-
// 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) {
|
|
51
|
-
try {
|
|
52
|
-
const parsed = JSON.parse(items);
|
|
53
|
-
const ul = this.ensure("ul.c-menu", () => { const el = document.createElement("ul"); el.className = "c-menu"; el.setAttribute("role", "menu"); return el; });
|
|
54
|
-
ul.innerHTML = "";
|
|
55
|
-
ul.setAttribute("role", "menu");
|
|
56
|
-
parsed.forEach((item) => {
|
|
57
|
-
if (item === "---" || item === "separator") {
|
|
58
|
-
const li = document.createElement("li");
|
|
59
|
-
li.className = "c-menu__separator";
|
|
60
|
-
li.setAttribute("role", "separator");
|
|
61
|
-
ul.appendChild(li);
|
|
62
|
-
} else if (typeof item === "string") {
|
|
63
|
-
const li = document.createElement("li");
|
|
64
|
-
li.className = "c-menu__item";
|
|
65
|
-
li.setAttribute("role", "menuitem");
|
|
66
|
-
li.textContent = item;
|
|
67
|
-
ul.appendChild(li);
|
|
68
|
-
} else if (item.group) {
|
|
69
|
-
const li = document.createElement("li");
|
|
70
|
-
li.className = "c-menu__group";
|
|
71
|
-
li.setAttribute("role", "group");
|
|
72
|
-
if (item.group) li.setAttribute("aria-label", String(item.group));
|
|
73
|
-
const hdr = document.createElement("div");
|
|
74
|
-
hdr.className = "c-menu__group-label";
|
|
75
|
-
hdr.textContent = String(item.group);
|
|
76
|
-
li.appendChild(hdr);
|
|
77
|
-
if (Array.isArray(item.items)) {
|
|
78
|
-
const sub = document.createElement("ul");
|
|
79
|
-
sub.className = "c-menu";
|
|
80
|
-
sub.setAttribute("role", "menu");
|
|
81
|
-
item.items.forEach((subItem) => {
|
|
82
|
-
const sli = document.createElement("li");
|
|
83
|
-
sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
|
|
84
|
-
sli.setAttribute("role", "menuitem");
|
|
85
|
-
if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
|
|
86
|
-
if (subItem.label || subItem.title) {
|
|
87
|
-
const lbl = document.createElement("span");
|
|
88
|
-
lbl.className = "c-menu__label";
|
|
89
|
-
lbl.textContent = subItem.label || subItem.title || "";
|
|
90
|
-
sli.appendChild(lbl);
|
|
91
|
-
}
|
|
92
|
-
sub.appendChild(sli);
|
|
93
|
-
});
|
|
94
|
-
li.appendChild(sub);
|
|
95
|
-
}
|
|
96
|
-
ul.appendChild(li);
|
|
97
|
-
} else {
|
|
98
|
-
const li = document.createElement("li");
|
|
99
|
-
li.className = "c-menu__item" + (item.danger ? " c-menu__item--danger" : "") + (item.disabled ? " c-menu__item--disabled" : "");
|
|
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));
|
|
104
|
-
if (item.disabled) li.setAttribute("aria-disabled", "true");
|
|
105
|
-
if (item.items && Array.isArray(item.items)) {
|
|
106
|
-
li.setAttribute("aria-haspopup", "menu");
|
|
107
|
-
li.setAttribute("aria-expanded", "false");
|
|
108
|
-
}
|
|
109
|
-
if (item.label || item.title) {
|
|
110
|
-
const lbl = document.createElement("span");
|
|
111
|
-
lbl.className = "c-menu__label";
|
|
112
|
-
lbl.textContent = item.label || item.title || "";
|
|
113
|
-
li.appendChild(lbl);
|
|
114
|
-
}
|
|
115
|
-
if (item.shortcut) {
|
|
116
|
-
const sc = document.createElement("span");
|
|
117
|
-
sc.className = "c-menu__shortcut";
|
|
118
|
-
sc.textContent = item.shortcut;
|
|
119
|
-
li.appendChild(sc);
|
|
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
|
-
}
|
|
142
|
-
ul.appendChild(li);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
if (ul.parentNode !== this) this.appendChild(ul);
|
|
146
|
-
this.classList.remove("c-menu");
|
|
147
|
-
ul.classList.add("c-menu");
|
|
148
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
149
|
-
} else {
|
|
150
|
-
renderEmpty(this, "menu");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
enhance() {
|
|
154
|
-
wireMenu(this);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
define("contour-menu", ContourMenu);
|
|
158
|
-
class ContourTabs extends ContourBase {
|
|
159
|
-
static get observed() { return ["tabs", "autoplay", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "orientation", "closable"]; }
|
|
160
|
-
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 } }; }
|
|
161
|
-
render() {
|
|
162
|
-
this.classList.add("c-tabs");
|
|
163
|
-
wireStates(this);
|
|
164
|
-
loadRemote(this, "tabs");
|
|
165
|
-
if (renderStates(this, "tabs")) return;
|
|
166
|
-
const tabs = remoteData(this, "tabs");
|
|
167
|
-
// Slot composition wins over the JSON attribute, same as ContourMenu:
|
|
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) {
|
|
221
|
-
try {
|
|
222
|
-
const parsed = JSON.parse(tabs);
|
|
223
|
-
const list = this.ensure(".c-tabs__list", () => { const el = document.createElement("div"); el.className = "c-tabs__list"; el.setAttribute("role", "tablist"); return el; });
|
|
224
|
-
list.setAttribute("role", "tablist");
|
|
225
|
-
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
226
|
-
list.setAttribute("aria-orientation", orientation);
|
|
227
|
-
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
228
|
-
// Preserve the selected tab across rebuilds (G-31): read the
|
|
229
|
-
// pre-drop selection before clearing, then re-apply it.
|
|
230
|
-
const _prevTabs = Array.from(list.querySelectorAll("[role='tab']"));
|
|
231
|
-
const _prevSel = _prevTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
232
|
-
const _keepIdx = _prevSel >= 0 ? _prevSel : 0;
|
|
233
|
-
list.innerHTML = "";
|
|
234
|
-
// Remove any previously generated panels so re-render doesn't stack.
|
|
235
|
-
Array.from(this.querySelectorAll(".c-tabs__panel")).forEach((n) => n.remove());
|
|
236
|
-
parsed.forEach((t, i) => {
|
|
237
|
-
const label = typeof t === "string" ? t : (t.label || t.title || "");
|
|
238
|
-
const panelId = contourId("c-tabs-panel");
|
|
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");
|
|
245
|
-
btn.className = "c-tabs__tab";
|
|
246
|
-
if (btn.tagName === "BUTTON") btn.type = "button";
|
|
247
|
-
btn.setAttribute("role", "tab");
|
|
248
|
-
btn.setAttribute("aria-selected", String(i === _keepIdx));
|
|
249
|
-
btn.setAttribute("aria-controls", panelId);
|
|
250
|
-
btn.tabIndex = i === _keepIdx ? 0 : -1;
|
|
251
|
-
const tabLabel = document.createElement("span");
|
|
252
|
-
tabLabel.textContent = label;
|
|
253
|
-
btn.textContent = "";
|
|
254
|
-
btn.appendChild(tabLabel);
|
|
255
|
-
if (this.hasAttribute("closable")) {
|
|
256
|
-
const closeBtn = document.createElement("button");
|
|
257
|
-
closeBtn.type = "button";
|
|
258
|
-
closeBtn.className = "c-tabs__close";
|
|
259
|
-
closeBtn.setAttribute("aria-label", "Close " + label);
|
|
260
|
-
closeBtn.textContent = "×";
|
|
261
|
-
closeBtn.addEventListener("click", (e) => {
|
|
262
|
-
e.stopPropagation();
|
|
263
|
-
const idx = Array.from(list.querySelectorAll("[role='tab']")).indexOf(btn);
|
|
264
|
-
// remove tab + panel
|
|
265
|
-
const ctrl = btn.getAttribute("aria-controls");
|
|
266
|
-
const panel = ctrl ? document.getElementById(ctrl) : null;
|
|
267
|
-
btn.remove();
|
|
268
|
-
if (panel) panel.remove();
|
|
269
|
-
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true, detail: { index: idx, label } }));
|
|
270
|
-
// activate first remaining tab
|
|
271
|
-
const remaining = list.querySelectorAll("[role='tab']");
|
|
272
|
-
if (remaining.length) remaining[0].click();
|
|
273
|
-
});
|
|
274
|
-
btn.appendChild(closeBtn);
|
|
275
|
-
}
|
|
276
|
-
list.appendChild(btn);
|
|
277
|
-
const panel = document.createElement("div");
|
|
278
|
-
panel.className = "c-tabs__panel";
|
|
279
|
-
panel.id = panelId;
|
|
280
|
-
panel.setAttribute("role", "tabpanel");
|
|
281
|
-
if (typeof t === "object" && t !== null && t.content !== undefined) {
|
|
282
|
-
panel.textContent = String(t.content);
|
|
283
|
-
}
|
|
284
|
-
if (i !== _keepIdx) panel.hidden = true;
|
|
285
|
-
this.appendChild(panel);
|
|
286
|
-
});
|
|
287
|
-
if (list.parentNode !== this) this.prepend(list);
|
|
288
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
289
|
-
} else if (!tabs && !authoredTabs.length) {
|
|
290
|
-
const list = this.querySelector(".c-tabs__list");
|
|
291
|
-
if (list) list.remove();
|
|
292
|
-
renderEmpty(this, "tabs");
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
enhance() {
|
|
296
|
-
wireTabs(this);
|
|
297
|
-
// Tabs autoplay (BY-29). Mirrors the streaming chart's interval contract
|
|
298
|
-
// (data.mjs): `autoplay` (seconds) advances the selection, `pause` stops
|
|
299
|
-
// it, the timer is owned once and disposed with the host, and the whole
|
|
300
|
-
// thing is gated on reduced motion. The advance is a click on the next
|
|
301
|
-
// tab, so wireTabs' own listener performs the activation and emits the
|
|
302
|
-
// manifest's contour:tab-change — this component never re-emits what its
|
|
303
|
-
// wiring already announced. Hover and focus also stop the loop (WCAG
|
|
304
|
-
// 2.2.2: auto-updating content needs a mechanism to pause, stop or hide;
|
|
305
|
-
// the pause attribute is the explicit one, hover/focus the implicit two).
|
|
306
|
-
const sync = () => {
|
|
307
|
-
const seconds = parseFloat(this.getAttribute("autoplay") || "");
|
|
308
|
-
const paused = this.hasAttribute("pause") || this._tabsHover || this._tabsFocus;
|
|
309
|
-
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
310
|
-
const want = Number.isFinite(seconds) && seconds > 0 && !paused && !reduced;
|
|
311
|
-
if (want === this._tabsAutoplayRunning) return;
|
|
312
|
-
this._tabsAutoplayRunning = want;
|
|
313
|
-
if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; }
|
|
314
|
-
if (!want) return;
|
|
315
|
-
this._tabsTimer = setInterval(() => {
|
|
316
|
-
if (!this.isConnected || this.hasAttribute("pause") || this._tabsHover || this._tabsFocus) return;
|
|
317
|
-
const list = this.querySelector(".c-tabs__list");
|
|
318
|
-
const tabs = list ? Array.from(list.querySelectorAll("[role='tab']")) : [];
|
|
319
|
-
if (!tabs.length) return;
|
|
320
|
-
const cur = tabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
321
|
-
const next = tabs[(cur + 1) % tabs.length];
|
|
322
|
-
if (next) next.click();
|
|
323
|
-
}, Math.max(1000, seconds * 1000));
|
|
324
|
-
};
|
|
325
|
-
// Re-run on every render so autoplay/pause attribute changes are picked
|
|
326
|
-
// up; the listeners and the disposer are installed exactly once.
|
|
327
|
-
sync();
|
|
328
|
-
if (this._wiredTabsAutoplay) return;
|
|
329
|
-
this._wiredTabsAutoplay = true;
|
|
330
|
-
this.addEventListener("pointerenter", () => { this._tabsHover = true; sync(); });
|
|
331
|
-
this.addEventListener("pointerleave", () => { this._tabsHover = false; sync(); });
|
|
332
|
-
this.addEventListener("focusin", () => { this._tabsFocus = true; sync(); });
|
|
333
|
-
this.addEventListener("focusout", () => { this._tabsFocus = false; sync(); });
|
|
334
|
-
onDispose(this, () => { if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; } });
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
define("contour-tabs", ContourTabs);
|
|
338
|
-
class ContourHeader extends ContourBase {
|
|
339
|
-
static get observed() { return ["brand", "links"]; }
|
|
340
|
-
static get properties() { return { brand: { attribute: "brand" }, links: { attribute: "links" } }; }
|
|
341
|
-
render() {
|
|
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");
|
|
345
|
-
const brand = this.getAttribute("brand");
|
|
346
|
-
const links = this.getAttribute("links");
|
|
347
|
-
const inner = this.ensure(".c-header__inner", () => { const el = document.createElement("div"); el.className = "container c-header__inner"; return el; });
|
|
348
|
-
inner.className = "container c-header__inner";
|
|
349
|
-
// Brand
|
|
350
|
-
let brandEl = inner.querySelector(".c-brand");
|
|
351
|
-
if (brand) {
|
|
352
|
-
if (!brandEl) {
|
|
353
|
-
brandEl = document.createElement("a");
|
|
354
|
-
brandEl.className = "c-brand";
|
|
355
|
-
brandEl.setAttribute("data-contour-generated", "");
|
|
356
|
-
brandEl.href = "#";
|
|
357
|
-
brandEl.innerHTML = `<span class="c-mark"><svg aria-hidden="true"><use href="#i-mark" /></svg></span>`;
|
|
358
|
-
const brandName = document.createElement("span");
|
|
359
|
-
brandName.className = "c-brand__name";
|
|
360
|
-
brandEl.appendChild(brandName);
|
|
361
|
-
inner.insertBefore(brandEl, inner.firstChild);
|
|
362
|
-
}
|
|
363
|
-
const brandName = brandEl.querySelector(".c-brand__name");
|
|
364
|
-
if (brandName) brandName.textContent = brand;
|
|
365
|
-
} else if (brandEl && brandEl.hasAttribute("data-contour-generated")) {
|
|
366
|
-
brandEl.remove();
|
|
367
|
-
}
|
|
368
|
-
// Nav
|
|
369
|
-
let nav = inner.querySelector(".c-header__nav");
|
|
370
|
-
const authoredNav = nav ? Array.from(nav.children).filter((n) => n.tagName === "A") : [];
|
|
371
|
-
if (links && !authoredNav.length) {
|
|
372
|
-
try {
|
|
373
|
-
const parsed = JSON.parse(links);
|
|
374
|
-
if (!nav) {
|
|
375
|
-
nav = document.createElement("nav");
|
|
376
|
-
nav.className = "c-header__nav";
|
|
377
|
-
nav.setAttribute("aria-label", "Main");
|
|
378
|
-
nav.setAttribute("data-contour-generated", "");
|
|
379
|
-
inner.appendChild(nav);
|
|
380
|
-
}
|
|
381
|
-
nav.innerHTML = "";
|
|
382
|
-
parsed.forEach((l) => {
|
|
383
|
-
const a = document.createElement("a");
|
|
384
|
-
a.href = safeHref(l.href || "#");
|
|
385
|
-
a.textContent = l.label || l;
|
|
386
|
-
nav.appendChild(a);
|
|
387
|
-
});
|
|
388
|
-
} catch (e) { /* skip */ }
|
|
389
|
-
} else if (links && authoredNav.length) {
|
|
390
|
-
// authored nav wins; keep it
|
|
391
|
-
} else if (nav && !links && !authoredNav.length && nav.hasAttribute("data-contour-generated")) {
|
|
392
|
-
nav.remove();
|
|
393
|
-
}
|
|
394
|
-
// Actions container
|
|
395
|
-
if (!inner.querySelector(".c-header__actions")) {
|
|
396
|
-
const actions = document.createElement("div");
|
|
397
|
-
actions.className = "c-header__actions";
|
|
398
|
-
inner.appendChild(actions);
|
|
399
|
-
}
|
|
400
|
-
// Mobile toggle (BY-29). Below 60rem the sheet hides .c-header__nav with
|
|
401
|
-
// no way to open it; the toggle is the way. It is created only when a nav
|
|
402
|
-
// exists, controls that nav by id, and starts closed so the first paint
|
|
403
|
-
// matches the closed CSS state. It rides inside .c-header__actions so the
|
|
404
|
-
// group's margin-inline-start:auto keeps it at the far right under 60rem.
|
|
405
|
-
// `i-grid` stands in for a hamburger: the sprite ships no i-menu symbol
|
|
406
|
-
// (index.html is the guide's own, and a dead <use> would be a defect), so
|
|
407
|
-
// the closest existing menu-like glyph is used with the real label.
|
|
408
|
-
const navEl = inner.querySelector(".c-header__nav");
|
|
409
|
-
if (navEl) {
|
|
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");
|
|
413
|
-
const actions = inner.querySelector(".c-header__actions");
|
|
414
|
-
if (actions && !actions.querySelector(".c-header__toggle")) {
|
|
415
|
-
const toggle = document.createElement("button");
|
|
416
|
-
toggle.type = "button";
|
|
417
|
-
toggle.className = "c-header__toggle";
|
|
418
|
-
toggle.setAttribute("aria-label", "Toggle navigation");
|
|
419
|
-
toggle.setAttribute("aria-expanded", "false");
|
|
420
|
-
toggle.setAttribute("aria-controls", navEl.id);
|
|
421
|
-
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-grid" /></svg>';
|
|
422
|
-
actions.appendChild(toggle);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (inner.parentNode !== this) this.appendChild(inner);
|
|
426
|
-
}
|
|
427
|
-
enhance() {
|
|
428
|
-
if (this._wiredHeader) return;
|
|
429
|
-
this._wiredHeader = true;
|
|
430
|
-
// Scroll state (BY-29): past a small threshold the header gains
|
|
431
|
-
// c-header--scrolled so the sheet can raise it above the page.
|
|
432
|
-
const update = () => {
|
|
433
|
-
const y = window.scrollY || document.documentElement.scrollTop || 0;
|
|
434
|
-
this.classList.toggle("c-header--scrolled", y > 8);
|
|
435
|
-
};
|
|
436
|
-
update();
|
|
437
|
-
window.addEventListener("scroll", update, { passive: true });
|
|
438
|
-
onDispose(this, () => window.removeEventListener("scroll", update));
|
|
439
|
-
// Toggle: the button shows/hides the nav under 60rem and keeps
|
|
440
|
-
// aria-expanded in step. Close on Escape while open.
|
|
441
|
-
this.addEventListener("click", (e) => {
|
|
442
|
-
const toggle = e.target && e.target.closest ? e.target.closest(".c-header__toggle") : null;
|
|
443
|
-
if (!toggle || !this.contains(toggle)) return;
|
|
444
|
-
const nav = this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
445
|
-
if (!nav) return;
|
|
446
|
-
const open = nav.classList.toggle("is-open");
|
|
447
|
-
toggle.setAttribute("aria-expanded", String(open));
|
|
448
|
-
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open } }));
|
|
449
|
-
});
|
|
450
|
-
this.addEventListener("keydown", (e) => {
|
|
451
|
-
if (e.key !== "Escape") return;
|
|
452
|
-
const toggle = this.querySelector(".c-header__toggle");
|
|
453
|
-
const nav = toggle && this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
454
|
-
if (!toggle || !nav || !nav.classList.contains("is-open")) return;
|
|
455
|
-
nav.classList.remove("is-open");
|
|
456
|
-
toggle.setAttribute("aria-expanded", "false");
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
define("contour-header", ContourHeader);
|
|
461
|
-
class ContourTree extends ContourBase {
|
|
462
|
-
static get updateMode() { return "keyed"; }
|
|
463
|
-
static get observed() { return ["items", "virtual", "item-height", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "selectable"]; }
|
|
464
|
-
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
|
|
465
|
-
_itemHeight() {
|
|
466
|
-
const h = Number(this.getAttribute("item-height"));
|
|
467
|
-
if (Number.isFinite(h) && h > 0) return h;
|
|
468
|
-
return cssLength("--virtual-list-item-height", 28);
|
|
469
|
-
}
|
|
470
|
-
_labelToPaths(nodes, pathPrefix, map) {
|
|
471
|
-
(nodes || []).forEach((node, i) => {
|
|
472
|
-
const p = pathPrefix + "." + i;
|
|
473
|
-
const label = String(node.label || node).trim().slice(0, 120);
|
|
474
|
-
if (!map.has(label)) map.set(label, []);
|
|
475
|
-
map.get(label).push(p);
|
|
476
|
-
if (Array.isArray(node.children)) this._labelToPaths(node.children, p, map);
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
_restoreExpanded() {
|
|
480
|
-
const persist = this.getAttribute("persist");
|
|
481
|
-
if (!persist || !this._treeData) return;
|
|
482
|
-
let labels = null;
|
|
483
|
-
try {
|
|
484
|
-
if (persist === "storage" && this.id) {
|
|
485
|
-
const saved = localStorage.getItem("contour-tree:" + this.id);
|
|
486
|
-
if (saved !== null) labels = JSON.parse(saved);
|
|
487
|
-
} else if (persist === "url") {
|
|
488
|
-
const v = new URLSearchParams(window.location.search).get("c-tree");
|
|
489
|
-
if (v !== null) labels = JSON.parse(v);
|
|
490
|
-
}
|
|
491
|
-
} catch (e) { labels = null; }
|
|
492
|
-
if (!Array.isArray(labels)) return;
|
|
493
|
-
const want = new Set(labels.map((l) => String(l)));
|
|
494
|
-
const map = new Map();
|
|
495
|
-
this._labelToPaths(this._treeData, "", map);
|
|
496
|
-
const expanded = this._expanded || (this._expanded = new Set());
|
|
497
|
-
for (const lbl of want) {
|
|
498
|
-
const paths = map.get(lbl);
|
|
499
|
-
if (paths) paths.forEach((p) => expanded.add(p));
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
_persistExpanded() {
|
|
503
|
-
const persist = this.getAttribute("persist");
|
|
504
|
-
if (!persist || !this._expanded) return;
|
|
505
|
-
// Map expanded paths back to labels.
|
|
506
|
-
const pathToNode = new Map();
|
|
507
|
-
const walk = (nodes, pathPrefix) => {
|
|
508
|
-
(nodes || []).forEach((node, i) => {
|
|
509
|
-
const p = pathPrefix + "." + i;
|
|
510
|
-
pathToNode.set(p, node);
|
|
511
|
-
if (Array.isArray(node.children)) walk(node.children, p);
|
|
512
|
-
});
|
|
513
|
-
};
|
|
514
|
-
walk(this._treeData, "");
|
|
515
|
-
const open = [];
|
|
516
|
-
for (const p of this._expanded) {
|
|
517
|
-
const node = pathToNode.get(p);
|
|
518
|
-
if (node) open.push(String(node.label || node).trim().slice(0, 120));
|
|
519
|
-
}
|
|
520
|
-
try {
|
|
521
|
-
if (persist === "storage" && this.id) {
|
|
522
|
-
localStorage.setItem("contour-tree:" + this.id, JSON.stringify(open));
|
|
523
|
-
} else if (persist === "url") {
|
|
524
|
-
const url = new URL(window.location.href);
|
|
525
|
-
url.searchParams.set("c-tree", JSON.stringify(open));
|
|
526
|
-
window.history.replaceState(null, "", url.toString());
|
|
527
|
-
}
|
|
528
|
-
} catch (e) {}
|
|
529
|
-
}
|
|
530
|
-
_flatten(nodes, pathPrefix, depth, expanded, out) {
|
|
531
|
-
(nodes || []).forEach((node, i) => {
|
|
532
|
-
const p = pathPrefix + "." + i;
|
|
533
|
-
const hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
534
|
-
const isExpanded = expanded.has(p);
|
|
535
|
-
out.push({ node, path: p, depth, hasChildren, expanded: isExpanded });
|
|
536
|
-
if (hasChildren && isExpanded) {
|
|
537
|
-
this._flatten(node.children, p, depth + 1, expanded, out);
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
_renderNodeFlat(rootUl, f) {
|
|
542
|
-
const node = f.node;
|
|
543
|
-
const depth = f.depth;
|
|
544
|
-
const li = document.createElement("div");
|
|
545
|
-
li.className = "c-tree__node";
|
|
546
|
-
li.setAttribute("role", "treeitem");
|
|
547
|
-
li.setAttribute("aria-level", String(depth));
|
|
548
|
-
li.dataset.path = f.path;
|
|
549
|
-
if (f.hasChildren) {
|
|
550
|
-
li.setAttribute("aria-expanded", String(f.expanded));
|
|
551
|
-
const row = document.createElement("div");
|
|
552
|
-
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
553
|
-
row.style.paddingInlineStart = ((depth - 1) * 1) + "rem";
|
|
554
|
-
const toggle = document.createElement("button");
|
|
555
|
-
toggle.className = "c-tree__toggle";
|
|
556
|
-
toggle.setAttribute("type", "button");
|
|
557
|
-
toggle.setAttribute("aria-expanded", String(f.expanded));
|
|
558
|
-
toggle.setAttribute("aria-label", "Toggle");
|
|
559
|
-
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
|
|
560
|
-
row.appendChild(toggle);
|
|
561
|
-
const span = document.createElement("span");
|
|
562
|
-
span.textContent = node.label;
|
|
563
|
-
row.appendChild(span);
|
|
564
|
-
li.appendChild(row);
|
|
565
|
-
} else {
|
|
566
|
-
const leaf = document.createElement("div");
|
|
567
|
-
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
568
|
-
leaf.style.paddingInlineStart = (depth * 1) + "rem";
|
|
569
|
-
if (this.hasAttribute("selectable")) {
|
|
570
|
-
const cb = document.createElement("input");
|
|
571
|
-
cb.type = "checkbox";
|
|
572
|
-
cb.className = "c-tree__select";
|
|
573
|
-
cb.setAttribute("aria-label", "Select " + (node.label || node));
|
|
574
|
-
const label = String(node.label || node).trim().slice(0, 120);
|
|
575
|
-
if (this._selectedTree && this._selectedTree.has(label)) cb.checked = true;
|
|
576
|
-
leaf.insertBefore(cb, leaf.firstChild);
|
|
577
|
-
}
|
|
578
|
-
leaf.appendChild(document.createTextNode(node.label || node));
|
|
579
|
-
li.appendChild(leaf);
|
|
580
|
-
}
|
|
581
|
-
return li;
|
|
582
|
-
}
|
|
583
|
-
_renderWindow(rootUl, scrollTop) {
|
|
584
|
-
if (!this._treeData) return;
|
|
585
|
-
const ih = this._itemHeight();
|
|
586
|
-
const expanded = this._expanded || (this._expanded = new Set());
|
|
587
|
-
const flat = [];
|
|
588
|
-
this._flatten(this._treeData, "", 1, expanded, flat);
|
|
589
|
-
const total = flat.length;
|
|
590
|
-
const viewportSize = rootUl.clientHeight || 320;
|
|
591
|
-
const visibleCount = Math.ceil(viewportSize / ih) + 6;
|
|
592
|
-
let start = Math.floor((scrollTop || 0) / ih);
|
|
593
|
-
if (start < 0) start = 0;
|
|
594
|
-
if (start > Math.max(0, total - visibleCount)) start = Math.max(0, total - visibleCount);
|
|
595
|
-
const end = Math.min(total, start + visibleCount);
|
|
596
|
-
const topSize = start * ih;
|
|
597
|
-
const bottomSize = Math.max(0, (total - end) * ih);
|
|
598
|
-
rootUl.innerHTML = "";
|
|
599
|
-
const top = document.createElement("div");
|
|
600
|
-
top.className = "c-tree__spacer c-tree__spacer--top";
|
|
601
|
-
top.style.height = topSize + "px";
|
|
602
|
-
rootUl.appendChild(top);
|
|
603
|
-
for (let i = start; i < end; i++) {
|
|
604
|
-
rootUl.appendChild(this._renderNodeFlat(rootUl, flat[i]));
|
|
605
|
-
}
|
|
606
|
-
const bottom = document.createElement("div");
|
|
607
|
-
bottom.className = "c-tree__spacer c-tree__spacer--bottom";
|
|
608
|
-
bottom.style.height = bottomSize + "px";
|
|
609
|
-
rootUl.appendChild(bottom);
|
|
610
|
-
}
|
|
611
|
-
render() {
|
|
612
|
-
this.classList.add("c-tree");
|
|
613
|
-
// Slot composition wins over the JSON attribute, same as ContourMenu:
|
|
614
|
-
// an authored tree is preserved across re-renders instead of being
|
|
615
|
-
// rebuilt from `items` and losing whatever the reader put in it.
|
|
616
|
-
const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-tree"));
|
|
617
|
-
wireStates(this);
|
|
618
|
-
loadRemote(this, "items");
|
|
619
|
-
if (renderStates(this, "tree")) return;
|
|
620
|
-
const items = remoteData(this, "items");
|
|
621
|
-
if (items && !authored.length) {
|
|
622
|
-
try {
|
|
623
|
-
const parsed = JSON.parse(items);
|
|
624
|
-
const rootUl = this.ensure("div.c-tree", () => { const el = document.createElement("div"); el.className = "c-tree"; el.setAttribute("role", "tree"); return el; });
|
|
625
|
-
rootUl.innerHTML = "";
|
|
626
|
-
rootUl.className = "c-tree";
|
|
627
|
-
rootUl.setAttribute("role", "tree");
|
|
628
|
-
const virtual = this.hasAttribute("virtual");
|
|
629
|
-
if (virtual) {
|
|
630
|
-
this._treeData = parsed;
|
|
631
|
-
this._expanded = this._expanded || new Set();
|
|
632
|
-
this._treeRoot = rootUl;
|
|
633
|
-
this._restoreExpanded();
|
|
634
|
-
rootUl.style.maxHeight = rootUl.style.maxHeight || "24rem";
|
|
635
|
-
rootUl.style.overflow = "auto";
|
|
636
|
-
const scrollTop = this._treeScrollTop || 0;
|
|
637
|
-
this._renderWindow(rootUl, scrollTop);
|
|
638
|
-
try { rootUl.scrollTop = scrollTop; } catch (e) {}
|
|
639
|
-
} else {
|
|
640
|
-
this._treeData = null;
|
|
641
|
-
const render = (nodes, parent, depth) => {
|
|
642
|
-
const ul = parent ? document.createElement("div") : rootUl;
|
|
643
|
-
if (parent) {
|
|
644
|
-
ul.className = "c-tree__children";
|
|
645
|
-
ul.setAttribute("role", "group");
|
|
646
|
-
if (supportsUntilFound()) ul.setAttribute("hidden", "until-found"); else ul.setAttribute("hidden", "");
|
|
647
|
-
}
|
|
648
|
-
nodes.forEach((node) => {
|
|
649
|
-
const li = document.createElement("div");
|
|
650
|
-
li.className = "c-tree__node";
|
|
651
|
-
li.setAttribute("role", "treeitem");
|
|
652
|
-
li.setAttribute("aria-level", String(depth));
|
|
653
|
-
if (node.children) {
|
|
654
|
-
li.setAttribute("aria-expanded", "false");
|
|
655
|
-
const row = document.createElement("div");
|
|
656
|
-
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
657
|
-
if (node.indent) {
|
|
658
|
-
const ind = document.createElement("span");
|
|
659
|
-
ind.className = "c-tree__indent";
|
|
660
|
-
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
661
|
-
row.appendChild(ind);
|
|
662
|
-
}
|
|
663
|
-
const toggle = document.createElement("button");
|
|
664
|
-
toggle.className = "c-tree__toggle";
|
|
665
|
-
toggle.setAttribute("type", "button");
|
|
666
|
-
toggle.setAttribute("aria-expanded", "false");
|
|
667
|
-
toggle.setAttribute("aria-label", "Toggle");
|
|
668
|
-
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
|
|
669
|
-
row.appendChild(toggle);
|
|
670
|
-
const span = document.createElement("span");
|
|
671
|
-
span.textContent = node.label;
|
|
672
|
-
row.appendChild(span);
|
|
673
|
-
li.appendChild(row);
|
|
674
|
-
render(node.children, li, depth + 1);
|
|
675
|
-
} else {
|
|
676
|
-
const leaf = document.createElement("div");
|
|
677
|
-
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
678
|
-
if (node.indent) {
|
|
679
|
-
const ind = document.createElement("span");
|
|
680
|
-
ind.className = "c-tree__indent";
|
|
681
|
-
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
682
|
-
leaf.appendChild(ind);
|
|
683
|
-
}
|
|
684
|
-
if (this.hasAttribute("selectable")) {
|
|
685
|
-
const cb = document.createElement("input");
|
|
686
|
-
cb.type = "checkbox";
|
|
687
|
-
cb.className = "c-tree__select";
|
|
688
|
-
cb.setAttribute("aria-label", "Select " + (node.label || node));
|
|
689
|
-
leaf.insertBefore(cb, leaf.firstChild);
|
|
690
|
-
}
|
|
691
|
-
leaf.appendChild(document.createTextNode(node.label || node));
|
|
692
|
-
li.appendChild(leaf);
|
|
693
|
-
}
|
|
694
|
-
ul.appendChild(li);
|
|
695
|
-
});
|
|
696
|
-
if (parent) parent.appendChild(ul);
|
|
697
|
-
};
|
|
698
|
-
render(parsed, null, 1);
|
|
699
|
-
}
|
|
700
|
-
this.classList.remove("c-tree");
|
|
701
|
-
rootUl.classList.add("c-tree");
|
|
702
|
-
if (rootUl.parentNode !== this) this.appendChild(rootUl);
|
|
703
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
704
|
-
} else if (!items && !authored.length) {
|
|
705
|
-
renderEmpty(this, "tree");
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
enhance() {
|
|
709
|
-
// Toggle handling via delegation (works for windowed + static trees).
|
|
710
|
-
if (!this._wiredTreeToggle) {
|
|
711
|
-
this._wiredTreeToggle = true;
|
|
712
|
-
this.addEventListener("click", (e) => {
|
|
713
|
-
const toggle = e.target && e.target.closest ? e.target.closest(".c-tree__toggle") : null;
|
|
714
|
-
if (!toggle || !this.contains(toggle)) return;
|
|
715
|
-
e.stopPropagation();
|
|
716
|
-
const nodeEl = toggle.closest(".c-tree__node");
|
|
717
|
-
const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
|
|
718
|
-
const expanded = toggle.getAttribute("aria-expanded") === "true";
|
|
719
|
-
if (path && this._expanded) {
|
|
720
|
-
if (expanded) this._expanded.delete(path); else this._expanded.add(path);
|
|
721
|
-
}
|
|
722
|
-
toggle.setAttribute("aria-expanded", String(!expanded));
|
|
723
|
-
const row = toggle.closest(".c-tree__row");
|
|
724
|
-
if (row) row.setAttribute("aria-expanded", String(!expanded));
|
|
725
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path, expanded: !expanded } }));
|
|
726
|
-
if (this.hasAttribute("virtual") && this._treeRoot) {
|
|
727
|
-
const s = this._treeRoot;
|
|
728
|
-
this._treeScrollTop = s.scrollTop || 0;
|
|
729
|
-
this._renderWindow(s, this._treeScrollTop);
|
|
730
|
-
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
731
|
-
this._persistExpanded();
|
|
732
|
-
}
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
// Scroll-driven windowing for virtual trees.
|
|
736
|
-
if (this.hasAttribute("virtual") && !this._wiredTreeScroll) {
|
|
737
|
-
this._wiredTreeScroll = true;
|
|
738
|
-
const attach = () => {
|
|
739
|
-
const s = this.querySelector(".c-tree");
|
|
740
|
-
if (!s || s._treeScrollWired) return;
|
|
741
|
-
s._treeScrollWired = true;
|
|
742
|
-
let raf = 0;
|
|
743
|
-
const onScroll = () => {
|
|
744
|
-
if (raf) return;
|
|
745
|
-
raf = requestAnimationFrame(() => {
|
|
746
|
-
raf = 0;
|
|
747
|
-
this._treeScrollTop = s.scrollTop || 0;
|
|
748
|
-
this._renderWindow(s, this._treeScrollTop);
|
|
749
|
-
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
s.addEventListener("scroll", onScroll, { passive: true });
|
|
753
|
-
onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
|
|
754
|
-
};
|
|
755
|
-
attach();
|
|
756
|
-
// retry if root not ready
|
|
757
|
-
if (!this.querySelector(".c-tree")) {
|
|
758
|
-
const mo = new MutationObserver(() => { if (this.querySelector(".c-tree")) { attach(); mo.disconnect(); } });
|
|
759
|
-
mo.observe(this, { childList: true, subtree: true });
|
|
760
|
-
onDispose(this, () => mo.disconnect());
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
// Auto-scroll during drag for virtual trees (so off-screen targets
|
|
764
|
-
// become reachable). Delegated on the host; only active in virtual mode.
|
|
765
|
-
if (this.hasAttribute("virtual") && !this._wiredTreeDragScroll) {
|
|
766
|
-
this._wiredTreeDragScroll = true;
|
|
767
|
-
let dragScrollRaf = 0;
|
|
768
|
-
let dragScrollDir = 0;
|
|
769
|
-
const tick = () => {
|
|
770
|
-
if (!dragScrollDir) { dragScrollRaf = 0; return; }
|
|
771
|
-
const s = this._treeRoot;
|
|
772
|
-
if (s) {
|
|
773
|
-
s.scrollTop += dragScrollDir * 8;
|
|
774
|
-
this._treeScrollTop = s.scrollTop;
|
|
775
|
-
this._renderWindow(s, this._treeScrollTop);
|
|
776
|
-
}
|
|
777
|
-
dragScrollRaf = requestAnimationFrame(tick);
|
|
778
|
-
};
|
|
779
|
-
this.addEventListener("dragover", (e) => {
|
|
780
|
-
const s = this._treeRoot;
|
|
781
|
-
if (!s) return;
|
|
782
|
-
const rect = s.getBoundingClientRect();
|
|
783
|
-
const edge = 40;
|
|
784
|
-
if (e.clientY < rect.top + edge) dragScrollDir = -1;
|
|
785
|
-
else if (e.clientY > rect.bottom - edge) dragScrollDir = 1;
|
|
786
|
-
else dragScrollDir = 0;
|
|
787
|
-
if (dragScrollDir && !dragScrollRaf) dragScrollRaf = requestAnimationFrame(tick);
|
|
788
|
-
});
|
|
789
|
-
const stop = () => {
|
|
790
|
-
dragScrollDir = 0;
|
|
791
|
-
if (dragScrollRaf) { cancelAnimationFrame(dragScrollRaf); dragScrollRaf = 0; }
|
|
792
|
-
};
|
|
793
|
-
this.addEventListener("dragend", stop);
|
|
794
|
-
this.addEventListener("drop", stop);
|
|
795
|
-
}
|
|
796
|
-
// Interaction lives in behaviours.mjs, which the shadow wrappers call too.
|
|
797
|
-
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
798
|
-
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
799
|
-
wireTree(this);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
define("contour-tree", ContourTree);
|
|
803
|
-
class ContourCodeTabs extends ContourBase {
|
|
804
|
-
static get observed() { return ["tabs", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist"]; }
|
|
805
|
-
static get properties() { return { tabs: { attribute: "tabs" }, src: { attribute: "src" } }; }
|
|
806
|
-
render() {
|
|
807
|
-
this.classList.add("c-code-tabs");
|
|
808
|
-
wireStates(this);
|
|
809
|
-
loadRemote(this, "tabs");
|
|
810
|
-
if (renderStates(this, "code-tabs")) return;
|
|
811
|
-
const tabs = remoteData(this, "tabs");
|
|
812
|
-
const list = this.querySelector(".c-code-tabs__list");
|
|
813
|
-
const authored = list ? Array.from(list.children).filter((n) => n.getAttribute && n.getAttribute("role") === "tab") : [];
|
|
814
|
-
if (tabs && !authored.length) {
|
|
815
|
-
try {
|
|
816
|
-
const parsed = JSON.parse(tabs);
|
|
817
|
-
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; });
|
|
818
|
-
l.setAttribute("role", "tablist");
|
|
819
|
-
const _prevCodeTabs = Array.from(l.querySelectorAll("[role='tab']"));
|
|
820
|
-
const _prevCodeSel = _prevCodeTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
821
|
-
const _keepCodeIdx = _prevCodeSel >= 0 ? _prevCodeSel : 0;
|
|
822
|
-
l.innerHTML = "";
|
|
823
|
-
Array.from(this.querySelectorAll(".c-code-tabs__panel")).forEach((n) => n.remove());
|
|
824
|
-
parsed.forEach((t, i) => {
|
|
825
|
-
const label = typeof t === "string" ? t : (t.label || t.title || "");
|
|
826
|
-
const panelId = contourId("c-code-tabs-panel");
|
|
827
|
-
const btn = document.createElement("button");
|
|
828
|
-
btn.className = "c-code-tabs__tab";
|
|
829
|
-
btn.setAttribute("role", "tab");
|
|
830
|
-
btn.setAttribute("aria-selected", String(i === _keepCodeIdx));
|
|
831
|
-
btn.setAttribute("aria-controls", panelId);
|
|
832
|
-
btn.tabIndex = i === _keepCodeIdx ? 0 : -1;
|
|
833
|
-
btn.textContent = label;
|
|
834
|
-
l.appendChild(btn);
|
|
835
|
-
const panel = document.createElement("div");
|
|
836
|
-
panel.className = "c-code-tabs__panel";
|
|
837
|
-
panel.id = panelId;
|
|
838
|
-
panel.setAttribute("role", "tabpanel");
|
|
839
|
-
if (typeof t === "object" && t !== null && t.content !== undefined) {
|
|
840
|
-
panel.textContent = String(t.content);
|
|
841
|
-
}
|
|
842
|
-
if (i !== _keepCodeIdx) panel.hidden = true;
|
|
843
|
-
this.appendChild(panel);
|
|
844
|
-
});
|
|
845
|
-
if (l.parentNode !== this) this.prepend(l);
|
|
846
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
847
|
-
} else if (!tabs && list) {
|
|
848
|
-
list.remove();
|
|
849
|
-
renderEmpty(this, "code-tabs");
|
|
850
|
-
} else if (!tabs && !list) {
|
|
851
|
-
renderEmpty(this, "code-tabs");
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
enhance() {
|
|
855
|
-
wireTabs(this);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
define("contour-code-tabs", ContourCodeTabs);
|
|
859
|
-
class ContourBreadcrumb extends ContourBase {
|
|
860
|
-
static get observed() { return ["items", "separator", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
861
|
-
static get properties() { return { items: { attribute: "items" }, separator: { attribute: "separator" }, max: { attribute: "max", type: Number }, src: { attribute: "src" } } };
|
|
862
|
-
render() {
|
|
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");
|
|
866
|
-
wireStates(this);
|
|
867
|
-
loadRemote(this, "items");
|
|
868
|
-
if (renderStates(this, "breadcrumb")) return;
|
|
869
|
-
const items = remoteData(this, "items");
|
|
870
|
-
// Slot composition: authored <li> items win over the JSON attribute.
|
|
871
|
-
const nav = this.querySelector("nav");
|
|
872
|
-
const ol = nav ? nav.querySelector("ol") : null;
|
|
873
|
-
const authored = ol ? Array.from(ol.children).filter((n) => n.tagName === "LI") : [];
|
|
874
|
-
if (items && !authored.length) {
|
|
875
|
-
try {
|
|
876
|
-
const parsed = JSON.parse(items);
|
|
877
|
-
const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", "Breadcrumb"); return el; });
|
|
878
|
-
n.setAttribute("aria-label", "Breadcrumb");
|
|
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");
|
|
882
|
-
n.innerHTML = "";
|
|
883
|
-
const sep = this.getAttribute("separator") || "/";
|
|
884
|
-
const max = this._overflowExpanded ? null : this.max;
|
|
885
|
-
const shown = Number.isFinite(max) && max > 1 && parsed.length > max
|
|
886
|
-
? parsed.slice(-max)
|
|
887
|
-
: parsed;
|
|
888
|
-
if (Number.isFinite(max) && max > 1 && parsed.length > max) {
|
|
889
|
-
const btn = document.createElement("button");
|
|
890
|
-
btn.type = "button";
|
|
891
|
-
btn.className = "c-breadcrumb__overflow";
|
|
892
|
-
btn.setAttribute("aria-label", `Show ${parsed.length - shown.length + 1} more items`);
|
|
893
|
-
btn.setAttribute("aria-expanded", "false");
|
|
894
|
-
btn.setAttribute("aria-controls", n.id);
|
|
895
|
-
btn.textContent = "…";
|
|
896
|
-
btn.addEventListener("click", () => {
|
|
897
|
-
// A handler-owned property, not an attribute: flipping a
|
|
898
|
-
// self-observed attribute from a handler would re-enter render
|
|
899
|
-
// (the arm-7 trap), so the flag lives outside OBSERVED.
|
|
900
|
-
this._overflowExpanded = true;
|
|
901
|
-
this.requestRender();
|
|
902
|
-
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { expanded: true } }));
|
|
903
|
-
});
|
|
904
|
-
n.appendChild(btn);
|
|
905
|
-
}
|
|
906
|
-
shown.forEach((item, i) => {
|
|
907
|
-
if (i < shown.length - 1) {
|
|
908
|
-
const a = document.createElement("a");
|
|
909
|
-
a.href = safeHref(item.href || "#");
|
|
910
|
-
a.textContent = item.label || item;
|
|
911
|
-
n.appendChild(a);
|
|
912
|
-
const s = document.createElement("span");
|
|
913
|
-
s.className = "c-breadcrumb__sep";
|
|
914
|
-
s.setAttribute("aria-hidden", "true");
|
|
915
|
-
s.textContent = sep;
|
|
916
|
-
n.appendChild(s);
|
|
917
|
-
} else {
|
|
918
|
-
const span = document.createElement("span");
|
|
919
|
-
span.textContent = item.label || item;
|
|
920
|
-
span.setAttribute("aria-current", "page");
|
|
921
|
-
n.appendChild(span);
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
925
|
-
} else if (!items && nav) {
|
|
926
|
-
nav.remove();
|
|
927
|
-
} else if (!items && !nav) {
|
|
928
|
-
renderEmpty(this, "breadcrumb");
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
define("contour-breadcrumb", ContourBreadcrumb);
|
|
933
|
-
class ContourPagination extends ContourBase {
|
|
934
|
-
static get observed() { return ["pages", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist"]; }
|
|
935
|
-
static get properties() { return { pages: { attribute: "pages" }, current: { attribute: "current" }, src: { attribute: "src" } }; }
|
|
936
|
-
render() {
|
|
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");
|
|
942
|
-
wireStates(this);
|
|
943
|
-
loadRemote(this, "pages");
|
|
944
|
-
if (renderStates(this, "pagination")) return;
|
|
945
|
-
const pages = remoteData(this, "pages");
|
|
946
|
-
// Drop previously generated links so a re-render cannot stack a second set.
|
|
947
|
-
Array.from(this.querySelectorAll(".c-pagination__link")).forEach((n) => n.remove());
|
|
948
|
-
let currentAttr = this.getAttribute("current") || "1";
|
|
949
|
-
if (this.getAttribute("persist") === "storage" && this.id) {
|
|
950
|
-
try { const stored = localStorage.getItem("contour-pagination:" + this.id); if (stored !== null) currentAttr = stored; } catch (e) {}
|
|
951
|
-
} else if (this.getAttribute("persist") === "url") {
|
|
952
|
-
try { const v = new URLSearchParams(window.location.search).get("c-pagination"); if (v !== null) currentAttr = v; } catch (e) {}
|
|
953
|
-
}
|
|
954
|
-
const current = parseInt(currentAttr, "10") || 1;
|
|
955
|
-
if (pages) {
|
|
956
|
-
let count = parseInt(pages, 10);
|
|
957
|
-
if (!Number.isFinite(count) || count < 1) {
|
|
958
|
-
try { const p = JSON.parse(pages); if (Array.isArray(p)) count = p.length; } catch (e) {}
|
|
959
|
-
}
|
|
960
|
-
// Prev button.
|
|
961
|
-
const prev = document.createElement("button");
|
|
962
|
-
prev.type = "button";
|
|
963
|
-
prev.className = "c-pagination__link c-pagination__prev";
|
|
964
|
-
prev.setAttribute("data-action", "prev");
|
|
965
|
-
prev.textContent = "‹";
|
|
966
|
-
prev.setAttribute("aria-label", labelText(this, "prev", "Previous page"));
|
|
967
|
-
this.appendChild(prev);
|
|
968
|
-
for (let i = 1; i <= count; i++) {
|
|
969
|
-
const btn = document.createElement("button");
|
|
970
|
-
btn.type = "button";
|
|
971
|
-
btn.className = "c-pagination__link";
|
|
972
|
-
btn.textContent = String(i);
|
|
973
|
-
if (i === current) {
|
|
974
|
-
btn.setAttribute("aria-current", "page");
|
|
975
|
-
}
|
|
976
|
-
this.appendChild(btn);
|
|
977
|
-
}
|
|
978
|
-
// Next button.
|
|
979
|
-
const next = document.createElement("button");
|
|
980
|
-
next.type = "button";
|
|
981
|
-
next.className = "c-pagination__link c-pagination__next";
|
|
982
|
-
next.setAttribute("data-action", "next");
|
|
983
|
-
next.textContent = "›";
|
|
984
|
-
next.setAttribute("aria-label", labelText(this, "next", "Next page"));
|
|
985
|
-
this.appendChild(next);
|
|
986
|
-
} else {
|
|
987
|
-
renderEmpty(this, "pagination");
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
enhance() {
|
|
991
|
-
wirePagination(this);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
define("contour-pagination", ContourPagination);
|
|
995
|
-
class ContourPagerFull extends ContourBase {
|
|
996
|
-
static get observed() { return ["prev", "next"]; }
|
|
997
|
-
static get properties() { return { prev: { attribute: "prev" }, next: { attribute: "next" } }; }
|
|
998
|
-
render() {
|
|
999
|
-
this.classList.add("c-pager");
|
|
1000
|
-
// Drop previously generated links so a re-render cannot stack a second set.
|
|
1001
|
-
Array.from(this.querySelectorAll(".c-pager__link")).forEach((n) => n.remove());
|
|
1002
|
-
const prev = this.getAttribute("prev");
|
|
1003
|
-
const next = this.getAttribute("next");
|
|
1004
|
-
if (prev) {
|
|
1005
|
-
const a = document.createElement("a");
|
|
1006
|
-
a.className = "c-pager__link";
|
|
1007
|
-
a.href = safeHref(prev.split("|")[1] || "#");
|
|
1008
|
-
const dir = document.createElement("span");
|
|
1009
|
-
dir.className = "c-pager__dir";
|
|
1010
|
-
dir.textContent = "← Previous";
|
|
1011
|
-
a.appendChild(dir);
|
|
1012
|
-
const title = document.createElement("span");
|
|
1013
|
-
title.className = "c-pager__title";
|
|
1014
|
-
title.textContent = prev.split("|")[0];
|
|
1015
|
-
a.appendChild(title);
|
|
1016
|
-
this.appendChild(a);
|
|
1017
|
-
}
|
|
1018
|
-
if (next) {
|
|
1019
|
-
const a = document.createElement("a");
|
|
1020
|
-
a.className = "c-pager__link c-pager__link--next";
|
|
1021
|
-
a.href = safeHref(next.split("|")[1] || "#");
|
|
1022
|
-
const dir = document.createElement("span");
|
|
1023
|
-
dir.className = "c-pager__dir";
|
|
1024
|
-
dir.textContent = labelText(this, "next", "Next") + " →";
|
|
1025
|
-
a.appendChild(dir);
|
|
1026
|
-
const title = document.createElement("span");
|
|
1027
|
-
title.className = "c-pager__title";
|
|
1028
|
-
title.textContent = next.split("|")[0];
|
|
1029
|
-
a.appendChild(title);
|
|
1030
|
-
this.appendChild(a);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
define("contour-pager", ContourPagerFull);
|
|
1035
|
-
class ContourTocFull extends ContourBase {
|
|
1036
|
-
static get observed() { return ["title", "items", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1037
|
-
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
1038
|
-
render() {
|
|
1039
|
-
this.classList.add("c-toc");
|
|
1040
|
-
this.setAttribute("role", "group");
|
|
1041
|
-
wireStates(this);
|
|
1042
|
-
loadRemote(this, "items");
|
|
1043
|
-
if (renderStates(this, "toc")) return;
|
|
1044
|
-
const items = remoteData(this, "items");
|
|
1045
|
-
const title = this.getAttribute("title") || "On this page";
|
|
1046
|
-
const titleEl = this.ensure(".c-toc__title", () => { const el = document.createElement("div"); el.className = "c-toc__title"; return el; });
|
|
1047
|
-
titleEl.textContent = title;
|
|
1048
|
-
const list = this.querySelector(".c-toc__list");
|
|
1049
|
-
const authored = list ? Array.from(list.children).filter((n) => n.tagName === "A") : [];
|
|
1050
|
-
if (items && !authored.length) {
|
|
1051
|
-
try {
|
|
1052
|
-
const parsed = JSON.parse(items);
|
|
1053
|
-
const l = this.ensure(".c-toc__list", () => { const el = document.createElement("nav"); el.className = "c-toc__list"; return el; });
|
|
1054
|
-
l.className = "c-toc__list";
|
|
1055
|
-
l.setAttribute("aria-label", title);
|
|
1056
|
-
l.innerHTML = "";
|
|
1057
|
-
parsed.forEach((item, i) => {
|
|
1058
|
-
const a = document.createElement("a");
|
|
1059
|
-
a.className = "c-toc__link" + (item.sub ? " c-toc__link--sub" : "");
|
|
1060
|
-
a.href = safeHref(item.href || "#");
|
|
1061
|
-
a.textContent = item.label || item;
|
|
1062
|
-
a.tabIndex = i === 0 ? 0 : -1;
|
|
1063
|
-
if (item.current) a.setAttribute("aria-current", "true");
|
|
1064
|
-
l.appendChild(a);
|
|
1065
|
-
});
|
|
1066
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1067
|
-
} else if (!items && list) {
|
|
1068
|
-
list.remove();
|
|
1069
|
-
renderEmpty(this, "toc");
|
|
1070
|
-
} else if (!items && !list) {
|
|
1071
|
-
renderEmpty(this, "toc");
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
enhance() {
|
|
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
|
|
1077
|
-
// marks its link aria-current="true" and clears the rest. The shipped CSS
|
|
1078
|
-
// already styles .c-toc__link[aria-current="true"], so the hook needs no
|
|
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.
|
|
1088
|
-
if (this._wiredTocSpy) return;
|
|
1089
|
-
const links = () => Array.from(this.querySelectorAll(".c-toc__link"));
|
|
1090
|
-
const pairs = () => links()
|
|
1091
|
-
.map((a) => {
|
|
1092
|
-
const href = a.getAttribute("href") || "";
|
|
1093
|
-
if (!href.startsWith("#") || href.length < 2) return null;
|
|
1094
|
-
const el = document.getElementById(href.slice(1));
|
|
1095
|
-
return el ? { a, el } : null;
|
|
1096
|
-
})
|
|
1097
|
-
.filter(Boolean);
|
|
1098
|
-
if (!pairs().length) return;
|
|
1099
|
-
this._wiredTocSpy = true;
|
|
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;
|
|
1123
|
-
links().forEach((a) => {
|
|
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
|
-
}
|
|
1130
|
-
});
|
|
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
|
-
});
|
|
1148
|
-
// Smooth scroll on link click (F-23).
|
|
1149
|
-
if (!this._wiredTocScroll) {
|
|
1150
|
-
this._wiredTocScroll = true;
|
|
1151
|
-
this.addEventListener("click", (e) => {
|
|
1152
|
-
const a = e.target && e.target.closest ? e.target.closest(".c-toc__link") : null;
|
|
1153
|
-
if (!a || !this.contains(a)) return;
|
|
1154
|
-
const href = a.getAttribute("href") || "";
|
|
1155
|
-
if (!href.startsWith("#") || href.length < 2) return;
|
|
1156
|
-
const target = document.getElementById(href.slice(1));
|
|
1157
|
-
if (!target) return;
|
|
1158
|
-
e.preventDefault();
|
|
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(); } } } });
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
define("contour-toc", ContourTocFull);
|
|
1172
|
-
class ContourFilterBar extends ContourBase {
|
|
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" } }; }
|
|
1175
|
-
render() {
|
|
1176
|
-
this.classList.add("c-filter-bar");
|
|
1177
|
-
wireStates(this);
|
|
1178
|
-
loadRemote(this, "items");
|
|
1179
|
-
if (renderStates(this, "filter-bar")) return;
|
|
1180
|
-
const label = this.getAttribute("label");
|
|
1181
|
-
if (label) {
|
|
1182
|
-
const l = this.ensure(".c-filter-bar__label", () => { const el = document.createElement("span"); el.className = "c-filter-bar__label"; return el; });
|
|
1183
|
-
l.textContent = label;
|
|
1184
|
-
} else {
|
|
1185
|
-
const l = this.querySelector(".c-filter-bar__label");
|
|
1186
|
-
if (l) l.remove();
|
|
1187
|
-
}
|
|
1188
|
-
if (this.hasAttribute("divider")) {
|
|
1189
|
-
this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
|
|
1190
|
-
} else {
|
|
1191
|
-
const d = this.querySelector(".c-filter-bar__divider");
|
|
1192
|
-
if (d) d.remove();
|
|
1193
|
-
}
|
|
1194
|
-
// Text input support
|
|
1195
|
-
if (this.hasAttribute("input") || this.hasAttribute("placeholder")) {
|
|
1196
|
-
let inp = this.querySelector(".c-filter-bar__input");
|
|
1197
|
-
if (!inp) { inp = document.createElement("input"); inp.type = "search"; inp.className = "c-filter-bar__input"; this.appendChild(inp); }
|
|
1198
|
-
const ph = this.getAttribute("placeholder");
|
|
1199
|
-
if (ph) inp.setAttribute("placeholder", ph);
|
|
1200
|
-
} else {
|
|
1201
|
-
const inp = this.querySelector(".c-filter-bar__input");
|
|
1202
|
-
if (inp) inp.remove();
|
|
1203
|
-
}
|
|
1204
|
-
// Mode toolbar
|
|
1205
|
-
const modesAttr = this.getAttribute("modes");
|
|
1206
|
-
let modes = null;
|
|
1207
|
-
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
1208
|
-
if (modes || this.hasAttribute("mode")) {
|
|
1209
|
-
let bar = this.querySelector(".c-filter-bar__modes");
|
|
1210
|
-
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); }
|
|
1211
|
-
bar.innerHTML = "";
|
|
1212
|
-
const current = this.getAttribute("mode");
|
|
1213
|
-
const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
|
|
1214
|
-
list.forEach((m) => {
|
|
1215
|
-
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
1216
|
-
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
1217
|
-
const btn = document.createElement("button");
|
|
1218
|
-
btn.type = "button";
|
|
1219
|
-
btn.className = "c-filter-bar__mode";
|
|
1220
|
-
btn.textContent = name;
|
|
1221
|
-
btn.dataset.mode = val;
|
|
1222
|
-
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
1223
|
-
bar.appendChild(btn);
|
|
1224
|
-
});
|
|
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.
|
|
1252
|
-
Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
|
|
1253
|
-
const items = remoteData(this, "items");
|
|
1254
|
-
// Slotted content: authored .c-filter-pill children take precedence.
|
|
1255
|
-
const authoredPills = Array.from(this.querySelectorAll(":scope > .c-filter-pill"));
|
|
1256
|
-
let parsed = null;
|
|
1257
|
-
if (authoredPills.length) {
|
|
1258
|
-
parsed = authoredPills.map((p) => p.textContent.trim());
|
|
1259
|
-
authoredPills.forEach((p) => p.remove());
|
|
1260
|
-
} else if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
1261
|
-
if (Array.isArray(parsed)) {
|
|
1262
|
-
parsed.forEach((it) => {
|
|
1263
|
-
const pill = document.createElement("span");
|
|
1264
|
-
pill.className = "c-filter-pill";
|
|
1265
|
-
const txt = typeof it === "string" ? it : (it.label || it.value || "");
|
|
1266
|
-
pill.textContent = txt;
|
|
1267
|
-
if (typeof it === "object" && it !== null && it.removable !== false) {
|
|
1268
|
-
const btn = document.createElement("button");
|
|
1269
|
-
btn.className = "c-filter-pill__remove";
|
|
1270
|
-
btn.type = "button";
|
|
1271
|
-
btn.setAttribute("aria-label", "Remove " + txt);
|
|
1272
|
-
btn.textContent = "×";
|
|
1273
|
-
pill.appendChild(btn);
|
|
1274
|
-
}
|
|
1275
|
-
this.appendChild(pill);
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
// Clear-all affordance (CARTO-inspired): panel-level clear with active count.
|
|
1279
|
-
Array.from(this.querySelectorAll(".c-filter-bar__clear-all")).forEach((n) => n.remove());
|
|
1280
|
-
if (this.hasAttribute("clearable")) {
|
|
1281
|
-
const btn = document.createElement("button");
|
|
1282
|
-
btn.type = "button";
|
|
1283
|
-
btn.className = "c-btn c-btn--ghost c-btn--sm c-filter-bar__clear-all";
|
|
1284
|
-
const count = this.getAttribute("count");
|
|
1285
|
-
btn.textContent = count ? ("Clear all (" + count + ")") : "Clear all";
|
|
1286
|
-
this.appendChild(btn);
|
|
1287
|
-
}
|
|
1288
|
-
if (!parsed && !label) renderEmpty(this, "filter-bar");
|
|
1289
|
-
}
|
|
1290
|
-
enhance() {
|
|
1291
|
-
wireRemovable(this);
|
|
1292
|
-
if (this._wiredFilterBar) return;
|
|
1293
|
-
this._wiredFilterBar = true;
|
|
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
|
-
});
|
|
1311
|
-
// text input
|
|
1312
|
-
const inp = this.querySelector(".c-filter-bar__input");
|
|
1313
|
-
if (inp && !inp._wiredFilterInput) {
|
|
1314
|
-
inp._wiredFilterInput = true;
|
|
1315
|
-
inp.addEventListener("input", () => {
|
|
1316
|
-
this.dispatchEvent(new CustomEvent("contour:input", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
1317
|
-
});
|
|
1318
|
-
inp.addEventListener("change", () => {
|
|
1319
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
// Clear-all (CARTO-inspired): delegated on host.
|
|
1323
|
-
if (!this._wiredClearAll) {
|
|
1324
|
-
this._wiredClearAll = true;
|
|
1325
|
-
this.addEventListener("click", (e) => {
|
|
1326
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__clear-all") : null;
|
|
1327
|
-
if (!btn || !this.contains(btn)) return;
|
|
1328
|
-
e.preventDefault();
|
|
1329
|
-
this.dispatchEvent(new CustomEvent("contour:clear-all", { bubbles: true, composed: true, detail: {} }));
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
define("contour-filter-bar", ContourFilterBar);
|
|
1335
|
-
class ContourCommand extends ContourBase {
|
|
1336
|
-
static get observed() { return ["placeholder", "items", "recent", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1337
|
-
static get properties() { return { placeholder: { attribute: "placeholder" }, items: { attribute: "items" }, recent: { attribute: "recent" }, empty: { attribute: "empty" }, src: { attribute: "src" } }; }
|
|
1338
|
-
render() {
|
|
1339
|
-
this.classList.add("c-command");
|
|
1340
|
-
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
1341
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Command palette");
|
|
1342
|
-
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
1343
|
-
wireStates(this);
|
|
1344
|
-
loadRemote(this, "items");
|
|
1345
|
-
if (renderStates(this, "command")) return;
|
|
1346
|
-
const placeholder = this.getAttribute("placeholder") || "Search…";
|
|
1347
|
-
const input = this.ensure(".c-command__input", () => { const el = document.createElement("input"); el.className = "c-command__input"; el.type = "text"; return el; });
|
|
1348
|
-
input.type = "text";
|
|
1349
|
-
input.placeholder = placeholder;
|
|
1350
|
-
input.setAttribute("aria-label", "Command");
|
|
1351
|
-
input.setAttribute("role", "combobox");
|
|
1352
|
-
input.setAttribute("aria-autocomplete", "list");
|
|
1353
|
-
input.setAttribute("aria-expanded", "true");
|
|
1354
|
-
const list = this.querySelector(".c-command__list");
|
|
1355
|
-
if (list && !list.id) list.id = contourId("c-command-list");
|
|
1356
|
-
if (list && list.id) input.setAttribute("aria-controls", list.id);
|
|
1357
|
-
const items = remoteData(this, "items");
|
|
1358
|
-
const list2 = this.querySelector(".c-command__list");
|
|
1359
|
-
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")) : [];
|
|
1360
|
-
if (items && !authored.length) {
|
|
1361
|
-
try {
|
|
1362
|
-
const parsed = JSON.parse(items);
|
|
1363
|
-
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; });
|
|
1364
|
-
l.setAttribute("role", "listbox");
|
|
1365
|
-
l.innerHTML = "";
|
|
1366
|
-
const recentRaw = this.getAttribute("recent");
|
|
1367
|
-
if (recentRaw) {
|
|
1368
|
-
try {
|
|
1369
|
-
const recentParsed = JSON.parse(recentRaw);
|
|
1370
|
-
const group = document.createElement("div");
|
|
1371
|
-
group.className = "c-command__group";
|
|
1372
|
-
const gt = document.createElement("div");
|
|
1373
|
-
gt.className = "c-command__group-title";
|
|
1374
|
-
gt.textContent = labelText(this, "recent", "Recent");
|
|
1375
|
-
group.appendChild(gt);
|
|
1376
|
-
recentParsed.forEach((it) => {
|
|
1377
|
-
const item = document.createElement("div");
|
|
1378
|
-
item.className = "c-command__item";
|
|
1379
|
-
item.setAttribute("role", "option");
|
|
1380
|
-
const body = document.createElement("div");
|
|
1381
|
-
body.className = "c-command__item-body";
|
|
1382
|
-
const t = document.createElement("div");
|
|
1383
|
-
t.className = "c-command__item-title";
|
|
1384
|
-
t.textContent = typeof it === "string" ? it : (it.title || it.label || "");
|
|
1385
|
-
body.appendChild(t);
|
|
1386
|
-
item.appendChild(body);
|
|
1387
|
-
group.appendChild(item);
|
|
1388
|
-
});
|
|
1389
|
-
l.appendChild(group);
|
|
1390
|
-
} catch (e) { /* skip */ }
|
|
1391
|
-
}
|
|
1392
|
-
parsed.forEach((it) => {
|
|
1393
|
-
if (it.group) {
|
|
1394
|
-
const group = document.createElement("div");
|
|
1395
|
-
group.className = "c-command__group";
|
|
1396
|
-
const gt = document.createElement("div");
|
|
1397
|
-
gt.className = "c-command__group-title";
|
|
1398
|
-
gt.textContent = it.group;
|
|
1399
|
-
group.appendChild(gt);
|
|
1400
|
-
const item = document.createElement("div");
|
|
1401
|
-
item.className = "c-command__item";
|
|
1402
|
-
item.setAttribute("role", "option");
|
|
1403
|
-
if (it.icon) {
|
|
1404
|
-
const ic = document.createElement("span");
|
|
1405
|
-
ic.className = "c-command__item-icon";
|
|
1406
|
-
ic.textContent = it.icon;
|
|
1407
|
-
item.appendChild(ic);
|
|
1408
|
-
}
|
|
1409
|
-
const body = document.createElement("div");
|
|
1410
|
-
body.className = "c-command__item-body";
|
|
1411
|
-
if (it.title || it.label) {
|
|
1412
|
-
const t = document.createElement("div");
|
|
1413
|
-
t.className = "c-command__item-title";
|
|
1414
|
-
t.textContent = it.title || it.label;
|
|
1415
|
-
body.appendChild(t);
|
|
1416
|
-
}
|
|
1417
|
-
if (it.hint) {
|
|
1418
|
-
const h = document.createElement("span");
|
|
1419
|
-
h.className = "c-command__item-hint";
|
|
1420
|
-
h.textContent = it.hint;
|
|
1421
|
-
body.appendChild(h);
|
|
1422
|
-
}
|
|
1423
|
-
if (it.shortcut) {
|
|
1424
|
-
const sc = document.createElement("kbd");
|
|
1425
|
-
sc.className = "c-command__item-shortcut";
|
|
1426
|
-
sc.textContent = it.shortcut;
|
|
1427
|
-
item.appendChild(sc);
|
|
1428
|
-
}
|
|
1429
|
-
item.appendChild(body);
|
|
1430
|
-
group.appendChild(item);
|
|
1431
|
-
l.appendChild(group);
|
|
1432
|
-
} else {
|
|
1433
|
-
const item = document.createElement("div");
|
|
1434
|
-
item.className = "c-command__item";
|
|
1435
|
-
item.setAttribute("role", "option");
|
|
1436
|
-
if (it.icon) {
|
|
1437
|
-
const ic = document.createElement("span");
|
|
1438
|
-
ic.className = "c-command__item-icon";
|
|
1439
|
-
ic.textContent = it.icon;
|
|
1440
|
-
item.appendChild(ic);
|
|
1441
|
-
}
|
|
1442
|
-
const body = document.createElement("div");
|
|
1443
|
-
body.className = "c-command__item-body";
|
|
1444
|
-
if (it.title || it.label) {
|
|
1445
|
-
const t = document.createElement("div");
|
|
1446
|
-
t.className = "c-command__item-title";
|
|
1447
|
-
t.textContent = it.title || it.label;
|
|
1448
|
-
body.appendChild(t);
|
|
1449
|
-
}
|
|
1450
|
-
if (it.hint) {
|
|
1451
|
-
const h = document.createElement("span");
|
|
1452
|
-
h.className = "c-command__item-hint";
|
|
1453
|
-
h.textContent = it.hint;
|
|
1454
|
-
body.appendChild(h);
|
|
1455
|
-
}
|
|
1456
|
-
if (it.shortcut) {
|
|
1457
|
-
const sc = document.createElement("kbd");
|
|
1458
|
-
sc.className = "c-command__item-shortcut";
|
|
1459
|
-
sc.textContent = it.shortcut;
|
|
1460
|
-
item.appendChild(sc);
|
|
1461
|
-
}
|
|
1462
|
-
item.appendChild(body);
|
|
1463
|
-
l.appendChild(item);
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1467
|
-
} else if (!items && list) {
|
|
1468
|
-
list.remove();
|
|
1469
|
-
}
|
|
1470
|
-
const empty = this.getAttribute("empty");
|
|
1471
|
-
if (empty) {
|
|
1472
|
-
const e = this.ensure(".c-command__empty", () => { const el = document.createElement("div"); el.className = "c-command__empty"; return el; });
|
|
1473
|
-
e.textContent = empty;
|
|
1474
|
-
} else {
|
|
1475
|
-
const e = this.querySelector(".c-command__empty");
|
|
1476
|
-
if (e) e.remove();
|
|
1477
|
-
}
|
|
1478
|
-
// Live filter results (BY-29). The region must exist EMPTY at mount —
|
|
1479
|
-
// the contrast gate refuses a pre-populated live region — and is filled
|
|
1480
|
-
// only when typing starts. The option ids the keydown handler writes are
|
|
1481
|
-
// the "keyed rows" half; this is the aria-live half.
|
|
1482
|
-
const status = this.ensure(".c-command__status", () => { const el = document.createElement("div"); el.className = "c-command__status"; el.setAttribute("role", "status"); return el; });
|
|
1483
|
-
status.textContent = "";
|
|
1484
|
-
if (!items && !list) {
|
|
1485
|
-
renderEmpty(this, "command");
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
enhance() {
|
|
1489
|
-
if (this._wiredCommand) return;
|
|
1490
|
-
this._wiredCommand = true;
|
|
1491
|
-
const input = () => this.querySelector(".c-command__input");
|
|
1492
|
-
const items = () => Array.from(this.querySelectorAll(".c-command__item"));
|
|
1493
|
-
let cursor = -1;
|
|
1494
|
-
const mark = () => {
|
|
1495
|
-
items().forEach((it, i) => {
|
|
1496
|
-
it.classList.toggle("c-command__item--active", i === cursor);
|
|
1497
|
-
it.setAttribute("aria-selected", String(i === cursor));
|
|
1498
|
-
if (i === cursor) {
|
|
1499
|
-
if (!it.id) it.id = "contour-command-option-" + i;
|
|
1500
|
-
const inp = input();
|
|
1501
|
-
if (inp) inp.setAttribute("aria-activedescendant", it.id);
|
|
1502
|
-
}
|
|
1503
|
-
});
|
|
1504
|
-
if (cursor < 0) {
|
|
1505
|
-
const inp = input();
|
|
1506
|
-
if (inp) inp.removeAttribute("aria-activedescendant");
|
|
1507
|
-
}
|
|
1508
|
-
};
|
|
1509
|
-
this.addEventListener("keydown", (e) => {
|
|
1510
|
-
const inp = input();
|
|
1511
|
-
if (!inp || e.target !== inp) return;
|
|
1512
|
-
const its = items();
|
|
1513
|
-
if (!its.length) return;
|
|
1514
|
-
if (e.key === "ArrowDown") { e.preventDefault(); cursor = Math.min(cursor + 1, its.length - 1); mark(); }
|
|
1515
|
-
else if (e.key === "ArrowUp") { e.preventDefault(); cursor = Math.max(cursor - 1, 0); mark(); }
|
|
1516
|
-
else if (e.key === "Home") { e.preventDefault(); cursor = 0; mark(); }
|
|
1517
|
-
else if (e.key === "End") { e.preventDefault(); cursor = its.length - 1; mark(); }
|
|
1518
|
-
else if (e.key === "Enter") {
|
|
1519
|
-
e.preventDefault();
|
|
1520
|
-
if (cursor >= 0 && its[cursor]) {
|
|
1521
|
-
const item = its[cursor];
|
|
1522
|
-
const idx = items().indexOf(item);
|
|
1523
|
-
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
1524
|
-
}
|
|
1525
|
-
} else if (e.key === "Escape") {
|
|
1526
|
-
if (typeof this.hidePopover === "function") this.hidePopover();
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1529
|
-
this.addEventListener("click", (e) => {
|
|
1530
|
-
const item = e.target && e.target.closest ? e.target.closest(".c-command__item") : null;
|
|
1531
|
-
if (item && this.contains(item)) {
|
|
1532
|
-
const idx = items().indexOf(item);
|
|
1533
|
-
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
1534
|
-
}
|
|
1535
|
-
});
|
|
1536
|
-
// Filter (BY-29): typing narrows the option set. The region was created
|
|
1537
|
-
// empty at mount; only a real query fills it, so a mount announces
|
|
1538
|
-
// nothing. Hidden items are taken out of the cursor walk, matching the
|
|
1539
|
-
// tree/keydown roving: cursor is reset and aria-activedescendant cleared
|
|
1540
|
-
// so the next mark() cannot point at a hidden option.
|
|
1541
|
-
this.addEventListener("input", (e) => {
|
|
1542
|
-
const inp = input();
|
|
1543
|
-
if (!inp || e.target !== inp) return;
|
|
1544
|
-
const q = inp.value.trim().toLowerCase();
|
|
1545
|
-
const all = items();
|
|
1546
|
-
let visible = 0;
|
|
1547
|
-
all.forEach((it) => {
|
|
1548
|
-
const match = !q || (it.textContent || "").toLowerCase().includes(q);
|
|
1549
|
-
it.hidden = !match;
|
|
1550
|
-
if (match) visible += 1;
|
|
1551
|
-
});
|
|
1552
|
-
this.querySelectorAll(".c-command__group").forEach((g) => {
|
|
1553
|
-
const hasVisible = Array.from(g.querySelectorAll(".c-command__item")).some((it) => !it.hidden);
|
|
1554
|
-
g.hidden = !hasVisible;
|
|
1555
|
-
});
|
|
1556
|
-
cursor = -1;
|
|
1557
|
-
mark();
|
|
1558
|
-
const status = this.querySelector(".c-command__status");
|
|
1559
|
-
if (status) status.textContent = q ? `${visible} of ${all.length}` : "";
|
|
1560
|
-
});
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
define("contour-command", ContourCommand);
|
|
1564
|
-
class ContourFooter extends ContourBase {
|
|
1565
|
-
static get observed() { return ["brand", "note", "links", "cols", "heading"]; }
|
|
1566
|
-
static get properties() { return { brand: { attribute: "brand" }, note: { attribute: "note" }, links: { attribute: "links" }, cols: { attribute: "cols" } }; }
|
|
1567
|
-
render() {
|
|
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");
|
|
1572
|
-
const brand = this.getAttribute("brand");
|
|
1573
|
-
if (brand) {
|
|
1574
|
-
const b = this.ensure(".c-footer__brand", () => { const el = document.createElement("div"); el.className = "c-footer__brand"; return el; });
|
|
1575
|
-
b.textContent = brand;
|
|
1576
|
-
} else {
|
|
1577
|
-
const b = this.querySelector(".c-footer__brand");
|
|
1578
|
-
if (b) b.remove();
|
|
1579
|
-
}
|
|
1580
|
-
const note = this.getAttribute("note");
|
|
1581
|
-
if (note) {
|
|
1582
|
-
const n = this.ensure(".c-footer__note", () => { const el = document.createElement("p"); el.className = "c-footer__note"; return el; });
|
|
1583
|
-
n.textContent = note;
|
|
1584
|
-
} else {
|
|
1585
|
-
const n = this.querySelector(".c-footer__note");
|
|
1586
|
-
if (n) n.remove();
|
|
1587
|
-
}
|
|
1588
|
-
const links = this.getAttribute("links");
|
|
1589
|
-
if (links) {
|
|
1590
|
-
try {
|
|
1591
|
-
const parsed = JSON.parse(links);
|
|
1592
|
-
const wrap = this.ensure(".c-footer__links", () => { const el = document.createElement("div"); el.className = "c-footer__links"; return el; });
|
|
1593
|
-
wrap.innerHTML = "";
|
|
1594
|
-
parsed.forEach((l) => {
|
|
1595
|
-
const a = document.createElement("a");
|
|
1596
|
-
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1597
|
-
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1598
|
-
wrap.appendChild(a);
|
|
1599
|
-
});
|
|
1600
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1601
|
-
} else {
|
|
1602
|
-
const w = this.querySelector(".c-footer__links");
|
|
1603
|
-
if (w) w.remove();
|
|
1604
|
-
}
|
|
1605
|
-
const cols = this.getAttribute("cols");
|
|
1606
|
-
if (cols) {
|
|
1607
|
-
try {
|
|
1608
|
-
const parsed = JSON.parse(cols);
|
|
1609
|
-
// Remove previous cols
|
|
1610
|
-
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
1611
|
-
parsed.forEach((col) => {
|
|
1612
|
-
const c = document.createElement("div");
|
|
1613
|
-
c.className = "c-footer__col";
|
|
1614
|
-
if (col.title) {
|
|
1615
|
-
const h = document.createElement(headingTag(this, "h3"));
|
|
1616
|
-
h.textContent = col.title;
|
|
1617
|
-
c.appendChild(h);
|
|
1618
|
-
}
|
|
1619
|
-
(col.links || []).forEach((l) => {
|
|
1620
|
-
const a = document.createElement("a");
|
|
1621
|
-
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1622
|
-
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1623
|
-
c.appendChild(a);
|
|
1624
|
-
});
|
|
1625
|
-
this.appendChild(c);
|
|
1626
|
-
});
|
|
1627
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1628
|
-
} else {
|
|
1629
|
-
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
define("contour-footer", ContourFooter);
|
|
1634
|
-
class ContourSchemeToggle extends ContourBase {
|
|
1635
|
-
static get observed() { return []; }
|
|
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"); }
|
|
1637
|
-
enhance() {
|
|
1638
|
-
if (this._wiredScheme) return;
|
|
1639
|
-
this._wiredScheme = true;
|
|
1640
|
-
this.addEventListener("click", () => {
|
|
1641
|
-
const root = document.documentElement;
|
|
1642
|
-
root.classList.add("is-theme-switching");
|
|
1643
|
-
const current = root.getAttribute("data-theme") || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
1644
|
-
const next = current === "dark" ? "light" : "dark";
|
|
1645
|
-
root.setAttribute("data-theme", next);
|
|
1646
|
-
try { localStorage.setItem("contour-theme", next); } catch (e) {}
|
|
1647
|
-
requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove("is-theme-switching")));
|
|
1648
|
-
this.dispatchEvent(new CustomEvent("contour:theme-change", { detail: { theme: next }, bubbles: true, composed: true }));
|
|
1649
|
-
});
|
|
1650
|
-
this.addEventListener("keydown", (e) => {
|
|
1651
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
1652
|
-
e.preventDefault();
|
|
1653
|
-
this.click();
|
|
1654
|
-
}
|
|
1655
|
-
});
|
|
1656
|
-
// restore persisted theme on connect
|
|
1657
|
-
try {
|
|
1658
|
-
const stored = localStorage.getItem("contour-theme");
|
|
1659
|
-
if (stored) document.documentElement.setAttribute("data-theme", stored);
|
|
1660
|
-
} catch (e) {}
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
define("contour-scheme-toggle", ContourSchemeToggle);
|
|
1664
|
-
class ContourSidebar extends ContourBase {
|
|
1665
|
-
static get observed() { return ["title", "items", "collapsed"]; }
|
|
1666
|
-
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
1667
|
-
render() {
|
|
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");
|
|
1671
|
-
if (this.hasAttribute("collapsed")) this.classList.add("c-sidebar--collapsed"); else this.classList.remove("c-sidebar--collapsed");
|
|
1672
|
-
const title = this.getAttribute("title");
|
|
1673
|
-
if (title) {
|
|
1674
|
-
const t = this.ensure(".c-sidebar__title", () => { const el = document.createElement("div"); el.className = "c-sidebar__title"; return el; });
|
|
1675
|
-
t.textContent = title;
|
|
1676
|
-
} else {
|
|
1677
|
-
const t = this.querySelector(".c-sidebar__title");
|
|
1678
|
-
if (t) t.remove();
|
|
1679
|
-
}
|
|
1680
|
-
const items = this.getAttribute("items");
|
|
1681
|
-
if (items) {
|
|
1682
|
-
try {
|
|
1683
|
-
const parsed = JSON.parse(items);
|
|
1684
|
-
const nav = this.ensure("nav.c-sidebar__nav", () => { const el = document.createElement("nav"); el.className = "c-sidebar__nav"; return el; });
|
|
1685
|
-
nav.innerHTML = "";
|
|
1686
|
-
parsed.forEach((it, i) => {
|
|
1687
|
-
const a = document.createElement("a");
|
|
1688
|
-
a.className = "c-sidebar__link";
|
|
1689
|
-
a.href = safeHref((it && it.href) || "#");
|
|
1690
|
-
a.textContent = (it && (it.label || it)) || "";
|
|
1691
|
-
a.tabIndex = i === 0 ? 0 : -1;
|
|
1692
|
-
nav.appendChild(a);
|
|
1693
|
-
});
|
|
1694
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
enhance() {
|
|
1698
|
-
if (this._wiredSidebar) return;
|
|
1699
|
-
this._wiredSidebar = true;
|
|
1700
|
-
this.addEventListener("click", (e) => {
|
|
1701
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
|
|
1702
|
-
if (!btn || !this.contains(btn)) return;
|
|
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(); } } } });
|
|
1713
|
-
});
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
define("contour-sidebar", ContourSidebar);
|
|
1717
|
-
class ContourToolbar extends ContourBase {
|
|
1718
|
-
static get observed() { return ["title", "actions", "overflow"]; }
|
|
1719
|
-
static get properties() { return { title: { attribute: "title" }, actions: { attribute: "actions" }, overflow: { attribute: "overflow", type: Number } }; }
|
|
1720
|
-
render() {
|
|
1721
|
-
this.classList.add("c-toolbar");
|
|
1722
|
-
const title = this.getAttribute("title");
|
|
1723
|
-
this.setAttribute("role", "toolbar");
|
|
1724
|
-
if (title) this.setAttribute("aria-label", title);
|
|
1725
|
-
const actions = this.getAttribute("actions");
|
|
1726
|
-
if (actions) {
|
|
1727
|
-
try {
|
|
1728
|
-
const parsed = JSON.parse(actions);
|
|
1729
|
-
const limit = this.overflow && this.overflow > 0 ? this.overflow : parsed.length;
|
|
1730
|
-
const visible = parsed.slice(0, limit);
|
|
1731
|
-
const excess = parsed.slice(limit);
|
|
1732
|
-
visible.forEach((a, i) => {
|
|
1733
|
-
const btn = document.createElement("button");
|
|
1734
|
-
btn.className = "c-toolbar__btn";
|
|
1735
|
-
btn.type = "button";
|
|
1736
|
-
btn.tabIndex = i === 0 ? 0 : -1;
|
|
1737
|
-
btn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
1738
|
-
this.appendChild(btn);
|
|
1739
|
-
});
|
|
1740
|
-
if (excess.length) {
|
|
1741
|
-
const wrap = document.createElement("div");
|
|
1742
|
-
wrap.className = "c-toolbar__overflow";
|
|
1743
|
-
const btn = document.createElement("button");
|
|
1744
|
-
btn.className = "c-toolbar__btn c-toolbar__overflow-btn";
|
|
1745
|
-
btn.type = "button";
|
|
1746
|
-
btn.setAttribute("aria-haspopup", "menu");
|
|
1747
|
-
btn.setAttribute("aria-expanded", "false");
|
|
1748
|
-
btn.textContent = "…";
|
|
1749
|
-
wrap.appendChild(btn);
|
|
1750
|
-
const menu = document.createElement("div");
|
|
1751
|
-
menu.className = "c-toolbar__overflow-menu";
|
|
1752
|
-
menu.setAttribute("role", "menu");
|
|
1753
|
-
menu.setAttribute("hidden", "");
|
|
1754
|
-
excess.forEach((a) => {
|
|
1755
|
-
const mbtn = document.createElement("button");
|
|
1756
|
-
mbtn.className = "c-toolbar__btn";
|
|
1757
|
-
mbtn.type = "button";
|
|
1758
|
-
mbtn.setAttribute("role", "menuitem");
|
|
1759
|
-
mbtn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
1760
|
-
menu.appendChild(mbtn);
|
|
1761
|
-
});
|
|
1762
|
-
wrap.appendChild(menu);
|
|
1763
|
-
this.appendChild(wrap);
|
|
1764
|
-
}
|
|
1765
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
enhance() {
|
|
1769
|
-
if (this._wiredToolbar) return;
|
|
1770
|
-
this._wiredToolbar = true;
|
|
1771
|
-
this.addEventListener("click", (e) => {
|
|
1772
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-toolbar__overflow-btn") : null;
|
|
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(); } } } });
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
define("contour-toolbar", ContourToolbar);
|
|
1796
|
-
|
|
1797
1
|
/**
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
1800
|
-
* (
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
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.
|
|
1804
8
|
*/
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
render() {
|
|
1809
|
-
this.classList.add("c-spatial-filter");
|
|
1810
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Spatial filter");
|
|
1811
|
-
wireStates(this);
|
|
1812
|
-
loadRemote(this, []);
|
|
1813
|
-
if (renderStates(this, "spatial-filter")) return;
|
|
1814
|
-
const modesAttr = this.getAttribute("modes");
|
|
1815
|
-
let modes = null;
|
|
1816
|
-
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
1817
|
-
const list = Array.isArray(modes) ? modes : ["rect", "circle", "polygon", "clear"];
|
|
1818
|
-
let bar = this.querySelector(".c-spatial-filter__modes");
|
|
1819
|
-
if (!bar) { bar = document.createElement("div"); bar.className = "c-spatial-filter__modes"; bar.setAttribute("role", "toolbar"); this.appendChild(bar); }
|
|
1820
|
-
bar.innerHTML = "";
|
|
1821
|
-
const current = this.getAttribute("mode");
|
|
1822
|
-
list.forEach((m) => {
|
|
1823
|
-
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
1824
|
-
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
1825
|
-
const btn = document.createElement("button");
|
|
1826
|
-
btn.type = "button";
|
|
1827
|
-
btn.className = "c-spatial-filter__mode c-btn c-btn--ghost c-btn--sm";
|
|
1828
|
-
btn.textContent = name;
|
|
1829
|
-
btn.dataset.mode = val;
|
|
1830
|
-
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
1831
|
-
bar.appendChild(btn);
|
|
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");
|
|
1861
|
-
if (this.hasAttribute("active")) {
|
|
1862
|
-
this.classList.add("c-spatial-filter--active");
|
|
1863
|
-
} else {
|
|
1864
|
-
this.classList.remove("c-spatial-filter--active");
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
enhance() {
|
|
1868
|
-
if (this._wiredSpatialFilter) return;
|
|
1869
|
-
this._wiredSpatialFilter = true;
|
|
1870
|
-
this.addEventListener("click", (e) => {
|
|
1871
|
-
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
1872
|
-
if (!btn || !this.contains(btn)) return;
|
|
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();
|
|
1883
|
-
if (mode === "clear") {
|
|
1884
|
-
this.classList.remove("c-spatial-filter--active");
|
|
1885
|
-
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
1886
|
-
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
this.classList.add("c-spatial-filter--active");
|
|
1890
|
-
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === modeBtn)));
|
|
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
|
-
}
|
|
1900
|
-
});
|
|
1901
|
-
this.addEventListener("keydown", (e) => {
|
|
1902
|
-
const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
|
|
1903
|
-
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
1904
|
-
});
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
define("contour-spatial-filter", ContourSpatialFilter);
|
|
9
|
+
import "./navigation-menu.mjs";
|
|
10
|
+
import "./navigation-shell.mjs";
|
|
11
|
+
import "./navigation-tree.mjs";
|