contour-ds 1.7.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- 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 +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- 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 +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- 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 +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- 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 +75 -33
- 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 +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- 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 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- 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 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- 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 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- 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 +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- 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/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
|
@@ -0,0 +1,2842 @@
|
|
|
1
|
+
import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERVED, REGISTERED, applyLabel, bearing, clampLat, contourId, cssLength, define, flagOn, flagOnValue, formatValue, haversine, headingTag, iconMarkup, isRtl, labelText, levelFromAttributes, mercatorResolution, navKey, normaliseLng, onDispose, safeColor, safeHref, sanitizeHtml, setHTML, simple, statusIcon, supportsUntilFound, unwrapBounds, warnBadJson, wcEmitOverlay, withBrownout, MARKER_SHAPES, arcPath, assignMarkers, barRects, compassNeedle, contourPaths, donutSlices, isMissing, marchingSquares, markerStyles, niceTicks, polylinePoints, scaleBarTicks, smoothPath, modalContain, wcReset, wireCombobox, wireCopy, wireMenu, wirePagination, wireRemovable, wireSegmented, wireTabs, wireTree, STATE_FALLBACK, loadRemote, parseArrayAttr, remoteData, remoteInvalidate, remoteRefresh, remoteVisible, renderEmpty, renderStates, stateLabel, watchViewport, wireStates } from "./contour-wc-core.esm.js";
|
|
2
|
+
|
|
3
|
+
// ---- Registration: class-only wrappers run last (define() skips claimed names) ----
|
|
4
|
+
define("contour-box", simple(["c-box"]));
|
|
5
|
+
define("contour-cluster", simple(["c-cluster"]));
|
|
6
|
+
define("contour-container", simple(["c-container"]));
|
|
7
|
+
define("contour-row", simple(["c-row"]));
|
|
8
|
+
define("contour-scrim", simple(["c-scrim"]));
|
|
9
|
+
define("contour-stack", simple(["c-stack"]));
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// R31-19: the text a shadow <label> shows through its <slot>, read from the
|
|
15
|
+
// light-tree assigned nodes (the shadow label's own textContent is empty).
|
|
16
|
+
const assignedText = (label) => {
|
|
17
|
+
const slot = label.querySelector("slot");
|
|
18
|
+
const nodes = slot ? slot.assignedElements({ flatten: true }) : [];
|
|
19
|
+
const text = nodes.map((n) => (n.textContent || "").trim()).join(" ").trim();
|
|
20
|
+
return text || (label.textContent || "").trim();
|
|
21
|
+
};
|
|
22
|
+
// ---- Shadow DOM wrappers (opt-in) ------------------------------------
|
|
23
|
+
let ADOPTED = null;
|
|
24
|
+
let ADOPTED_KEY = "";
|
|
25
|
+
const _hashCss = (str) => {
|
|
26
|
+
let h = 2166136261;
|
|
27
|
+
for (let i = 0; i < str.length; i++) {
|
|
28
|
+
h ^= str.charCodeAt(i);
|
|
29
|
+
h = Math.imul(h, 16777619);
|
|
30
|
+
}
|
|
31
|
+
return (h >>> 0).toString(36);
|
|
32
|
+
};
|
|
33
|
+
export const adoptedSheets = () => {
|
|
34
|
+
let key = document.styleSheets.length + ":";
|
|
35
|
+
for (const sheet of document.styleSheets) {
|
|
36
|
+
let sig = "-1";
|
|
37
|
+
try {
|
|
38
|
+
const rules = sheet.cssRules;
|
|
39
|
+
let text = "";
|
|
40
|
+
for (let i = 0; i < rules.length; i++) text += rules[i].cssText + "\n";
|
|
41
|
+
sig = rules.length + ":" + _hashCss(text);
|
|
42
|
+
} catch (e) { /* cross-origin: unreadable */ }
|
|
43
|
+
key += (sheet.href || "inline") + "~" + sig + "|";
|
|
44
|
+
}
|
|
45
|
+
if (ADOPTED && key === ADOPTED_KEY) return ADOPTED;
|
|
46
|
+
ADOPTED_KEY = key;
|
|
47
|
+
ADOPTED = [];
|
|
48
|
+
// Collect every rule a sheet carries, descending into @imported sheets,
|
|
49
|
+
const collect = (sheet, out) => {
|
|
50
|
+
let rules;
|
|
51
|
+
try { rules = sheet.cssRules; } catch (e) { return; }
|
|
52
|
+
if (!rules) return;
|
|
53
|
+
for (const r of rules) {
|
|
54
|
+
if (r instanceof CSSImportRule) {
|
|
55
|
+
if (r.styleSheet) collect(r.styleSheet, out);
|
|
56
|
+
} else {
|
|
57
|
+
try { out.push(r.cssText); } catch (e) { /* unreadable */ }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
for (const sheet of document.styleSheets) {
|
|
62
|
+
try {
|
|
63
|
+
// Include same-origin linked sheets AND same-origin inline <style> sheets (!sheet.href).
|
|
64
|
+
if (!sheet.href || new URL(sheet.href).origin === location.origin) {
|
|
65
|
+
const collected = [];
|
|
66
|
+
collect(sheet, collected);
|
|
67
|
+
const built = new CSSStyleSheet();
|
|
68
|
+
if (collected.length) built.replaceSync(collected.join("\n"));
|
|
69
|
+
ADOPTED.push(built);
|
|
70
|
+
}
|
|
71
|
+
} catch (e) { /* cross-origin or unreadable */ }
|
|
72
|
+
}
|
|
73
|
+
return ADOPTED;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// One base for every wrapper: adopt the sheets, clone the subclass template,
|
|
77
|
+
const _ShadowParent = (typeof HTMLElement !== "undefined") ? HTMLElement : Object;
|
|
78
|
+
class ContourShadow extends _ShadowParent {
|
|
79
|
+
// R30-33: observe `labels` alongside the modifier attributes so a labels
|
|
80
|
+
// change re-runs _applyLabels(). applyMods() ignores it (it only maps MODS),
|
|
81
|
+
// so adding it here does not create a bogus modifier class.
|
|
82
|
+
static get observedAttributes() { return MODS.concat("labels"); }
|
|
83
|
+
constructor() {
|
|
84
|
+
super();
|
|
85
|
+
// Reuse a Declarative Shadow Root when the platform already attached one
|
|
86
|
+
// (SSR/DSD hydration); otherwise create and populate the shadow root.
|
|
87
|
+
let root = this.shadowRoot;
|
|
88
|
+
if (!root) {
|
|
89
|
+
root = this.attachShadow({ mode: "open" });
|
|
90
|
+
if (this.constructor.contourTemplate) {
|
|
91
|
+
root.appendChild(this.constructor.contourTemplate.content.cloneNode(true));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const sheets = adoptedSheets();
|
|
95
|
+
if (sheets.length) {
|
|
96
|
+
try { root.adoptedStyleSheets = sheets; } catch (e) { /* unsupported or read-only */ }
|
|
97
|
+
}
|
|
98
|
+
this._shadowBase = root.firstElementChild ? root.firstElementChild.className : "";
|
|
99
|
+
}
|
|
100
|
+
// Subclasses with behaviour beyond the template override this.
|
|
101
|
+
enhance(root) {
|
|
102
|
+
if (!root) root = this.shadowRoot;
|
|
103
|
+
if (!root) return;
|
|
104
|
+
// ARIA setup is idempotent (guards on hasAttribute), so it re-runs on
|
|
105
|
+
root.querySelectorAll("details").forEach((d) => {
|
|
106
|
+
const summary = d.querySelector("summary");
|
|
107
|
+
if (summary && !summary.hasAttribute("aria-expanded")) {
|
|
108
|
+
summary.setAttribute("aria-expanded", String(d.open));
|
|
109
|
+
d.addEventListener("toggle", () => {
|
|
110
|
+
summary.setAttribute("aria-expanded", String(d.open));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
// ARIA: ensure live regions have proper roles
|
|
115
|
+
root.querySelectorAll("[data-live]").forEach((el) => {
|
|
116
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
117
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
118
|
+
});
|
|
119
|
+
// ARIA: spinners and toasts get live region roles (opt-in: an author-set role wins)
|
|
120
|
+
root.querySelectorAll(".c-spinner").forEach((el) => {
|
|
121
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
122
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
123
|
+
});
|
|
124
|
+
// ARIA: toast elements get live region roles
|
|
125
|
+
root.querySelectorAll(".c-toast, .c-toast-host").forEach((el) => {
|
|
126
|
+
if (!el.hasAttribute("role")) el.setAttribute("role", "status");
|
|
127
|
+
if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "polite");
|
|
128
|
+
if (!el.hasAttribute("aria-atomic")) el.setAttribute("aria-atomic", "true");
|
|
129
|
+
});
|
|
130
|
+
// ARIA: link tabs to panels via aria-controls
|
|
131
|
+
root.querySelectorAll("[role='tab']").forEach((tab) => {
|
|
132
|
+
const ctrl = tab.getAttribute("aria-controls");
|
|
133
|
+
if (ctrl) {
|
|
134
|
+
const panel = root.querySelector("#" + CSS.escape(ctrl)) || document.getElementById(ctrl);
|
|
135
|
+
if (panel && !panel.hasAttribute("aria-labelledby")) {
|
|
136
|
+
if (!tab.id) tab.id = contourId("tab");
|
|
137
|
+
panel.setAttribute("aria-labelledby", tab.id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// ARIA: link inputs to their labels/hints via aria-describedby
|
|
142
|
+
root.querySelectorAll("input, textarea, select").forEach((input) => {
|
|
143
|
+
if (input.hasAttribute("aria-describedby")) return;
|
|
144
|
+
const field = input.closest(".c-field");
|
|
145
|
+
if (field) {
|
|
146
|
+
const hint = field.querySelector(".c-field__hint");
|
|
147
|
+
if (hint) {
|
|
148
|
+
if (!hint.id) hint.id = contourId("hint");
|
|
149
|
+
input.setAttribute("aria-describedby", hint.id);
|
|
150
|
+
}
|
|
151
|
+
const err = field.querySelector(".c-field__error");
|
|
152
|
+
if (err) {
|
|
153
|
+
if (!err.id) err.id = contourId("err");
|
|
154
|
+
const existing = input.getAttribute("aria-describedby") || "";
|
|
155
|
+
input.setAttribute("aria-describedby", (existing + " " + err.id).trim());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
// ARIA: alert elements are live regions, and the variant sets the volume.
|
|
160
|
+
root.querySelectorAll(".c-alert").forEach((el) => {
|
|
161
|
+
const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
|
|
162
|
+
const role = urgent ? "alert" : "status";
|
|
163
|
+
const live = urgent ? "assertive" : "polite";
|
|
164
|
+
if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
|
|
165
|
+
el.setAttribute("role", role);
|
|
166
|
+
el.dataset.contourAutoRole = role;
|
|
167
|
+
}
|
|
168
|
+
if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
|
|
169
|
+
el.setAttribute("aria-live", live);
|
|
170
|
+
el.dataset.contourAutoLive = live;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
// ARIA: required form fields
|
|
174
|
+
root.querySelectorAll("input[required], textarea[required], select[required]").forEach((el) => {
|
|
175
|
+
if (!el.hasAttribute("aria-required")) el.setAttribute("aria-required", "true");
|
|
176
|
+
});
|
|
177
|
+
// Interaction is delegated to the implementation the light-DOM wrappers
|
|
178
|
+
this._wireLabels(root);
|
|
179
|
+
this._wireClose(root);
|
|
180
|
+
}
|
|
181
|
+
// R31-22: the shadow callout/alert/tag/filter-pill close/remove buttons were
|
|
182
|
+
// inert — a control the reader could focus and never use. Wire them to
|
|
183
|
+
// dismiss the host (hide + emit contour:close/dismiss), once per host.
|
|
184
|
+
_wireClose(root) {
|
|
185
|
+
if (!root || this._wiredShadowClose) return;
|
|
186
|
+
const btns = root.querySelectorAll(".c-callout__close, .c-alert__close, .c-tag__remove, .c-filter-pill__remove");
|
|
187
|
+
if (!btns.length) return;
|
|
188
|
+
this._wiredShadowClose = true;
|
|
189
|
+
for (const b of btns) {
|
|
190
|
+
b.addEventListener("click", () => {
|
|
191
|
+
this.hidden = true;
|
|
192
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// R31-03: a shadow <label> wrapping a <slot> does not label a slotted input.
|
|
197
|
+
// The input is in the light tree, the label in the shadow tree, and HTML's
|
|
198
|
+
// label/for association does not cross the boundary. Give the slotted
|
|
199
|
+
// control an id and point the shadow label's `for` at it, and mirror the
|
|
200
|
+
// field hint/error into aria-describedby. Idempotent.
|
|
201
|
+
_wireLabels(root) {
|
|
202
|
+
if (!root) return;
|
|
203
|
+
root.querySelectorAll("label").forEach((label) => {
|
|
204
|
+
const slot = label.querySelector("slot");
|
|
205
|
+
const field = label.closest(".c-field") || label.parentElement;
|
|
206
|
+
const host = this;
|
|
207
|
+
const controls = [];
|
|
208
|
+
if (slot) {
|
|
209
|
+
for (const n of slot.assignedElements({ flatten: true })) {
|
|
210
|
+
if (n.matches("input, textarea, select")) controls.push(n);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// A field's input lives in a named "input" slot, not inside the label.
|
|
214
|
+
if (!controls.length && field) {
|
|
215
|
+
const inputSlot = field.querySelector('slot[name="input"]');
|
|
216
|
+
if (inputSlot) {
|
|
217
|
+
for (const n of inputSlot.assignedElements({ flatten: true })) {
|
|
218
|
+
if (n.matches("input, textarea, select")) controls.push(n);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const input of controls) {
|
|
223
|
+
if (!input.id) input.id = contourId("shadow-input");
|
|
224
|
+
if (!label.hasAttribute("for")) label.setAttribute("for", input.id);
|
|
225
|
+
// R31-19: `for` does not cross the shadow boundary — the label is in
|
|
226
|
+
// the shadow tree, the input in the light tree, so `label.control`
|
|
227
|
+
// is null and `input.labels` is empty. Give the input an explicit
|
|
228
|
+
// accessible name from the label's slotted text, and forward a label
|
|
229
|
+
// click to the control, so the visible label actually toggles it.
|
|
230
|
+
if (!input.hasAttribute("aria-label") && !input.hasAttribute("aria-labelledby")) {
|
|
231
|
+
const text = assignedText(label);
|
|
232
|
+
if (text) input.setAttribute("aria-label", text);
|
|
233
|
+
}
|
|
234
|
+
if (!input._contourLabelWired) {
|
|
235
|
+
input._contourLabelWired = true;
|
|
236
|
+
label.addEventListener("click", (e) => {
|
|
237
|
+
if (e.target.closest("a, button, input, textarea, select")) return;
|
|
238
|
+
try { input.click(); } catch (err) { /* control without click */ }
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
// Mirror the field hint/error into aria-describedby (once).
|
|
242
|
+
if (field && !input.hasAttribute("aria-describedby")) {
|
|
243
|
+
const hint = field.querySelector(".c-field__hint");
|
|
244
|
+
const err = field.querySelector(".c-field__error");
|
|
245
|
+
const ids = [];
|
|
246
|
+
if (hint) { if (!hint.id) hint.id = contourId("hint"); ids.push(hint.id); }
|
|
247
|
+
if (err) { if (!err.id) err.id = contourId("err"); ids.push(err.id); }
|
|
248
|
+
if (ids.length) input.setAttribute("aria-describedby", ids.join(" "));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
connectedCallback() {
|
|
254
|
+
this.applyMods();
|
|
255
|
+
try { this.enhance(this.shadowRoot); } catch (e) { /* ignore */ }
|
|
256
|
+
this._applyLabels();
|
|
257
|
+
// Wire behaviours now that slotted content is present.
|
|
258
|
+
try {
|
|
259
|
+
wcReset(this);
|
|
260
|
+
wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
|
|
261
|
+
wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
|
|
262
|
+
} catch (e) { /* ignore */ }
|
|
263
|
+
// Re-wire behaviour when slotted content changes. Reset the wired set so
|
|
264
|
+
if (this.shadowRoot && !this._wiredSlotchange) {
|
|
265
|
+
this._wiredSlotchange = true;
|
|
266
|
+
this.shadowRoot.addEventListener("slotchange", () => {
|
|
267
|
+
try { this.enhance(this.shadowRoot);
|
|
268
|
+
this._applyLabels();
|
|
269
|
+
wireTabs(this); wireSegmented(this); wireCombobox(this); wireTree(this);
|
|
270
|
+
wireMenu(this); wirePagination(this); wireCopy(this); wireRemovable(this);
|
|
271
|
+
} catch (e) { /* ignore */ }
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
attributeChangedCallback() { this.applyMods(); this._applyLabels(); }
|
|
276
|
+
// R30-33: localise the static aria-labels/copy baked into shadow templates.
|
|
277
|
+
// The light-DOM sweep (R30-13) routes literals through labelText(); the
|
|
278
|
+
// shadow layer has no such path because its markup is a static template
|
|
279
|
+
// string. This post-processes the rendered shadowRoot, replacing the
|
|
280
|
+
// English defaults with the host's `labels` overrides where present. It is
|
|
281
|
+
// idempotent and only touches nodes that still carry the default text, so
|
|
282
|
+
// an author's own shadow content (slotted) is never overwritten.
|
|
283
|
+
_applyLabels() {
|
|
284
|
+
const root = this.shadowRoot;
|
|
285
|
+
if (!root) return;
|
|
286
|
+
const set = (selector, key, fallback) => {
|
|
287
|
+
const node = root.querySelector(selector);
|
|
288
|
+
if (node) node.setAttribute("aria-label", labelText(this, key, fallback));
|
|
289
|
+
};
|
|
290
|
+
set(".c-callout__close", "close", "Close");
|
|
291
|
+
set(".c-alert__close", "close", "Close");
|
|
292
|
+
set(".c-tag__remove", "remove", "Remove");
|
|
293
|
+
set(".c-filter-pill__remove", "remove-filter", "Remove filter");
|
|
294
|
+
set(".c-breadcrumb", "breadcrumb", "Breadcrumb");
|
|
295
|
+
set(".c-spinner", "loading", "Loading");
|
|
296
|
+
set(".c-install__copy", "copy-command", "Copy command");
|
|
297
|
+
// The install/code copy buttons carry visible "Copy" text as well as an
|
|
298
|
+
// aria-label; localise both, but only while they still read "Copy" so a
|
|
299
|
+
// consumer who set their own label keeps it.
|
|
300
|
+
const copyBtn = root.querySelector(".c-install__copy, .c-code__copy");
|
|
301
|
+
if (copyBtn && copyBtn.textContent.trim() === "Copy") {
|
|
302
|
+
copyBtn.textContent = labelText(this, "copy", "Copy");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
applyMods() {
|
|
306
|
+
const el = this.shadowRoot.firstElementChild;
|
|
307
|
+
if (!el || !this._shadowBase) return;
|
|
308
|
+
const mods = [];
|
|
309
|
+
for (const attr of MODS) {
|
|
310
|
+
const val = this.getAttribute(attr);
|
|
311
|
+
if (!val) continue;
|
|
312
|
+
for (const cls of this._shadowBase.split(/\s+/)) {
|
|
313
|
+
if (cls) mods.push("c-" + cls.replace(/^c-/, "") + "--" + val);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
el.className = (this._shadowBase + " " + mods.join(" ")).trim();
|
|
317
|
+
// An alert's live region follows its variant, and rewriting the class above
|
|
318
|
+
if (el.classList.contains("c-alert")) {
|
|
319
|
+
const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
|
|
320
|
+
const role = urgent ? "alert" : "status";
|
|
321
|
+
const live = urgent ? "assertive" : "polite";
|
|
322
|
+
if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
|
|
323
|
+
el.setAttribute("role", role);
|
|
324
|
+
el.dataset.contourAutoRole = role;
|
|
325
|
+
}
|
|
326
|
+
if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
|
|
327
|
+
el.setAttribute("aria-live", live);
|
|
328
|
+
el.dataset.contourAutoLive = live;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Registers a wrapper. The template markup is always recorded so Node/SSR
|
|
335
|
+
const SHADOW_PARTS_PUBLIC = {};
|
|
336
|
+
const SHADOW_MARKUP = {};
|
|
337
|
+
const recordParts = (name, markup) => {
|
|
338
|
+
SHADOW_PARTS_PUBLIC[name] = [...markup.matchAll(/part="([^"]+)"/g)]
|
|
339
|
+
.flatMap((m) => m[1].split(/\s+/))
|
|
340
|
+
.filter(Boolean);
|
|
341
|
+
};
|
|
342
|
+
const shadow = (name, markup) => {
|
|
343
|
+
SHADOW_MARKUP[name] = markup;
|
|
344
|
+
recordParts(name, markup);
|
|
345
|
+
if (typeof document === "undefined") return;
|
|
346
|
+
const tpl = document.createElement("template");
|
|
347
|
+
setHTML(tpl, markup);
|
|
348
|
+
const cls = class extends ContourShadow {};
|
|
349
|
+
cls.contourTemplate = tpl;
|
|
350
|
+
define(name, cls);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// A wrapper that is one default slot needs no markup of its own: the element,
|
|
354
|
+
const slotWrapper = (tag, block, part) =>
|
|
355
|
+
"<" + tag + ' class="c-' + block + '" part="' + (part || block) + '"' + (tag === "button" ? ' type="button"' : "") + "><slot></slot></" + tag + ">";
|
|
356
|
+
const SHADOW_SLOTS = {
|
|
357
|
+
div: [
|
|
358
|
+
"accordion", "activity", "advanced", "affordance", "affordances", "anchor", "app", "app-body", "box", "btn-group", "chart-grid",
|
|
359
|
+
"catchment", "cluster", "command", "compare", "comparison", "compass",
|
|
360
|
+
"contour-plot", "cta", "dash-freshness", "dash-kpi-row", "dash-shell", "dash-toolbar", "datamark", "delta", "draggable", "drag-handle", "drop-indicator", "drop-zone",
|
|
361
|
+
"destructive-hint", "docs-shell", "drawer", "elevation",
|
|
362
|
+
"filter-bar", "flow-map", "heatmap", "hexbin", "icon-badge", "input-group", "instrument", "range-scale", "resizable", "table-wrap", "time-range", "toast-host", "scroll-area",
|
|
363
|
+
"isochrone", "landing-features", "landing-hero", "layer-panel", "layer-switch", "legend", "logos", "map-area",
|
|
364
|
+
"map-footer", "map-panel", "map-slot", "measure", "metrics", "minimap", "pager", "pagination",
|
|
365
|
+
"panel", "plate", "price", "pricing", "progress", "prose", "pullquote", "radio-list",
|
|
366
|
+
"range", "readout", "recipe", "reserved", "resize-handle", "row",
|
|
367
|
+
"row-action", "scale-bar", "scrim", "segmented", "sheet", "shortcut-list", "shortcut-overlay", "shortcut-panel",
|
|
368
|
+
"shortcut-row", "showcase", "sidebar", "skeleton", "sparkline", "stack", "steps", "streaming-chart",
|
|
369
|
+
"survey", "theme-scope", "time-slider", "timeline", "toast",
|
|
370
|
+
"toolbar", "tooltip", "tree", "version", "version-banner"
|
|
371
|
+
],
|
|
372
|
+
button: [
|
|
373
|
+
"btn", "pressable"
|
|
374
|
+
],
|
|
375
|
+
span: [
|
|
376
|
+
"avatar", "badge", "chip", "dot", "flag", "live-badge", "mark", "pill"
|
|
377
|
+
],
|
|
378
|
+
a: [
|
|
379
|
+
"link", "linkish"
|
|
380
|
+
],
|
|
381
|
+
kbd: [
|
|
382
|
+
"kbd"
|
|
383
|
+
],
|
|
384
|
+
label: [
|
|
385
|
+
"check", "radio", "switch"
|
|
386
|
+
],
|
|
387
|
+
nav: [
|
|
388
|
+
"docs-nav"
|
|
389
|
+
],
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// Two wrappers name their part after the region it holds rather than after
|
|
393
|
+
const SHADOW_PARTS = {
|
|
394
|
+
"version-banner": "banner",
|
|
395
|
+
"contour-plot": "plot",
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// The slot wrappers are recorded wherever this module runs. `shadow()` already
|
|
399
|
+
for (const [tag, blocks] of Object.entries(SHADOW_SLOTS)) {
|
|
400
|
+
for (const block of blocks) {
|
|
401
|
+
const part = SHADOW_PARTS[block] || block;
|
|
402
|
+
shadow("contour-shadow-" + block, slotWrapper(tag, block, part));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Structured templates: more than one slot, or a class that is not the block's
|
|
407
|
+
// own, so the markup is the definition and is written out.
|
|
408
|
+
shadow("contour-shadow-callout", `<div class="c-callout" part="callout"><div class="c-callout__title" part="title"><slot name="title"></slot></div><div class="c-callout__body" part="body"><slot></slot></div><button class="c-callout__close" part="close" type="button" aria-label="Close">×</button></div>`);
|
|
409
|
+
shadow("contour-shadow-empty", `<div class="c-empty" part="empty"><div class="c-empty__illustration" part="illustration"><slot name="illustration"></slot></div><div class="c-empty__title" part="title"><slot name="title"></slot></div><div class="c-empty__text" part="body"><slot></slot></div><div><slot name="action"></slot></div></div>`);
|
|
410
|
+
shadow("contour-shadow-feature", `<div class="c-feature" part="feature"><span class="c-feature__index" part="index"><slot name="index"></slot></span><div class="c-feature__title" part="title"><slot name="title"></slot></div><div class="c-feature__body" part="body"><slot></slot></div></div>`);
|
|
411
|
+
shadow("contour-shadow-kpi", `<div class="c-kpi" part="kpi"><div class="c-kpi__value" part="value"><slot name="value"></slot></div><div class="c-kpi__label" part="label"><slot name="label"></slot></div><div class="c-kpi__foot" part="foot"><slot name="delta"></slot><slot name="note"></slot></div></div>`);
|
|
412
|
+
shadow("contour-shadow-stat", `<div class="c-stat" part="stat"><div class="c-stat__value" part="value"><slot name="value"></slot></div><div class="c-stat__label" part="label"><slot name="label"></slot></div><div class="c-stat__delta" part="delta"><slot name="delta"></slot></div></div>`);
|
|
413
|
+
shadow("contour-shadow-meter", `<div class="c-meter" part="meter"><span class="c-meter__core" part="core"><span class="c-meter__value" part="value"><slot name="value"></slot></span><span class="c-meter__label" part="label"><slot name="label"></slot></span></span></div>`);
|
|
414
|
+
shadow("contour-shadow-brownout", `<div class="c-brownout" part="brownout" data-level="0"><slot></slot></div>`);
|
|
415
|
+
shadow("contour-shadow-widget-state", `<div class="c-widget-state" part="widget-state"><slot></slot></div>`);
|
|
416
|
+
shadow("contour-shadow-donut", `<div class="c-donut" part="donut"><svg class="c-donut__ring" part="ring" viewBox="0 0 32 32"></svg><div class="c-donut__center" part="center"><slot name="value"></slot></div><div class="c-donut__list" part="list"><slot></slot></div></div>`);
|
|
417
|
+
shadow("contour-shadow-axis", `<div class="c-axis" part="axis"><slot></slot></div>`);
|
|
418
|
+
shadow("contour-shadow-brush", `<div class="c-brush" part="brush"><div class="c-brush__selection" part="selection"></div></div>`);
|
|
419
|
+
shadow("contour-shadow-stacked-bar", `<div class="c-stacked-bar" part="bar"><slot></slot></div>`);
|
|
420
|
+
shadow("contour-shadow-category", `<div class="c-category" part="category" role="listbox"><slot></slot></div>`);
|
|
421
|
+
shadow("contour-shadow-gauge", `<div class="c-gauge" part="gauge"><svg class="c-gauge__dial" part="dial" aria-hidden="true" viewBox="0 0 100 100"><path class="c-gauge__track" part="track" d="M 10 90 A 40 40 0 0 1 90 90"></path><g class="c-gauge__zones"></g><line class="c-gauge__needle" part="needle" x1="50" y1="50" x2="50" y2="15"></line><circle class="c-gauge__hub" part="hub" cx="50" cy="50" r="4"></circle></svg><div class="c-gauge__value" part="value"><slot name="value"></slot></div><div class="c-gauge__band" part="band"><slot name="band"></slot></div></div>`);
|
|
422
|
+
shadow("contour-shadow-diff", `<div class="c-diff" part="diff"><div class="c-diff__line c-diff__line--del" part="before"><span class="c-diff__sign">−</span><span><slot name="before"></slot></span></div><div class="c-diff__line c-diff__line--add" part="after"><span class="c-diff__sign">+</span><span><slot name="after"></slot></span></div></div>`);
|
|
423
|
+
shadow("contour-shadow-do-dont", `<div class="c-do-dont" part="do-dont"><div class="c-do-dont__item c-do-dont__item--do" part="do"><slot name="do"></slot></div><div class="c-do-dont__item c-do-dont__item--dont" part="dont"><slot name="dont"></slot></div></div>`);
|
|
424
|
+
shadow("contour-shadow-threshold", `<div class="c-threshold" part="threshold"><span class="c-threshold__fill" part="value"></span><span class="c-threshold__target" part="target"></span></div>`);
|
|
425
|
+
shadow("contour-shadow-coordinate", `<div class="c-coordinate" part="coordinate"><span class="c-coordinate__value" part="value"><slot name="value"></slot></span></div>`);
|
|
426
|
+
shadow("contour-shadow-install", `<div class="c-install" part="install"><span class="c-install__prompt" part="prompt"><slot name="prompt"></slot></span><span class="c-install__command" part="command"><slot name="command"></slot></span><button class="c-btn c-btn--ghost c-btn--sm c-install__copy" part="copy" type="button" aria-label="Copy command">Copy</button></div>`);
|
|
427
|
+
shadow("contour-shadow-toc", `<div class="c-toc" part="toc"><div class="c-toc__title" part="title"><slot name="title"></slot></div><nav class="c-toc__list" part="list"><slot></slot></nav></div>`);
|
|
428
|
+
shadow("contour-shadow-testimonial", `<div class="c-testimonial" part="testimonial"><blockquote class="c-testimonial__quote" part="quote"><slot name="quote"></slot></blockquote><div class="c-testimonial__byline" part="byline"><span class="c-testimonial__name" part="name"><slot name="name"></slot></span><span class="c-testimonial__role" part="role"><slot name="role"></slot></span></div></div>`);
|
|
429
|
+
shadow("contour-shadow-search-trigger", `<button class="c-search-trigger" part="trigger"><span><slot name="label"></slot></span><kbd class="c-search-trigger__kbd"><slot name="shortcut"></slot></kbd></button>`);
|
|
430
|
+
shadow("contour-shadow-brand", `<a class="c-brand" part="brand"><span class="c-mark" part="mark"><slot name="mark"></slot></span><span class="c-brand__name" part="name"><slot name="name"></slot></span></a>`);
|
|
431
|
+
shadow("contour-shadow-section-head", `<div class="c-section-head" part="head"><h2 class="c-section-head__title" part="title"><slot name="title"></slot></h2><p class="c-section-head__desc" part="desc"><slot name="desc"></slot></p></div>`);
|
|
432
|
+
shadow("contour-shadow-loading", `<div class="c-loading" part="loading"><span class="c-spinner" part="spinner"></span><slot></slot></div>`);
|
|
433
|
+
// Shadow tabs are a styling shell: panels are authored by the consumer
|
|
434
|
+
shadow("contour-shadow-tabs", `<div class="c-tabs" part="tabs"><div class="c-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-tabs__panels" role="presentation"><slot></slot></div></div>`);
|
|
435
|
+
shadow("contour-shadow-breadcrumb", `<nav class="c-breadcrumb" part="breadcrumb" aria-label="Breadcrumb"><ol><slot></slot></ol></nav>`);
|
|
436
|
+
shadow("contour-shadow-menu", `<div class="c-menu" part="menu" role="menu"><slot></slot></div>`);
|
|
437
|
+
shadow("contour-shadow-combobox", `<div class="c-combobox" part="combobox"><input class="c-combobox__input" part="input" type="text" /><ul class="c-combobox__list" part="list" hidden><slot></slot></ul></div>`);
|
|
438
|
+
shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
|
|
439
|
+
shadow("contour-shadow-bivariate", `<div class="c-bivariate" part="bivariate"><div class="c-bivariate__matrix" part="matrix"><slot></slot></div></div>`);
|
|
440
|
+
shadow("contour-shadow-bivariate-legend", `<div class="c-bivariate-legend" part="legend"><div class="c-bivariate-legend__matrix" part="matrix"><slot></slot></div></div>`);
|
|
441
|
+
shadow("contour-shadow-expandable", `<details class="c-expandable" part="expandable"><summary class="c-expandable__summary"><slot name="summary"></slot></summary><div class="c-expandable__body" part="body"><slot></slot></div></details>`);
|
|
442
|
+
shadow("contour-shadow-disclosure", `<details class="c-disclosure" part="disclosure"><summary><slot name="summary"></slot></summary><div class="c-disclosure__body" part="body"><slot></slot></div></details>`);
|
|
443
|
+
shadow("contour-shadow-faq", `<div class="c-faq" part="faq"><div class="c-faq__question" part="question"><slot name="question"></slot></div><div class="c-faq__answer" part="answer"><slot name="answer"></slot></div></div>`);
|
|
444
|
+
shadow("contour-shadow-code-tabs", `<div class="c-code-tabs" part="code-tabs"><div class="c-code-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-code-tabs__panels"><slot></slot></div></div>`);
|
|
445
|
+
shadow("contour-shadow-header", `<header class="c-header" part="header"><div class="container c-header__inner" part="inner"><a class="c-brand" part="brand"><slot name="brand"></slot></a><nav class="c-header__nav" part="nav"><slot name="nav"></slot></nav><div class="c-header__actions" part="actions"><slot name="actions"></slot></div></div></header>`);
|
|
446
|
+
shadow("contour-shadow-footer", `<footer class="c-footer" part="footer"><div class="container c-footer__grid" part="grid"><div class="c-footer__brand" part="brand"><slot name="brand"></slot></div><div class="c-footer__links" part="links"><slot name="links"></slot></div></div></footer>`);
|
|
447
|
+
shadow("contour-shadow-container", `<div class="container" part="container"><slot></slot></div>`);
|
|
448
|
+
// R31-03: contour-shadow-input / -textarea / -select / -table / -scheme-toggle
|
|
449
|
+
// were removed. Each was a control shell that could not hold the state its
|
|
450
|
+
// light twin holds (no value, no options, no rows, no toggle), so it was a
|
|
451
|
+
// trap rather than a styling seam. Use the light <contour-input>,
|
|
452
|
+
// <contour-select>, <contour-table> and <contour-scheme-toggle>, or style a
|
|
453
|
+
// native control with the `.c-input` / `.c-table` classes directly.
|
|
454
|
+
shadow("contour-shadow-spinner", `<span class="c-spinner" part="spinner" aria-label="Loading"></span>`);
|
|
455
|
+
shadow("contour-shadow-code", `<pre class="c-code" part="code"><code><slot></slot></code><button class="c-code__copy" part="copy" type="button">Copy</button></pre>`);
|
|
456
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
457
|
+
shadow("contour-shadow-card", `<div class="c-card" part="card"> <div class="c-card__title" part="head"><slot name="title">Untitled</slot></div> <div class="c-card__body" part="body"><slot></slot></div> <div class="c-card__foot" part="foot"><slot name="foot"></slot></div> </div>`);
|
|
458
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
459
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
460
|
+
shadow("contour-shadow-field", `<div class="c-field" part="field"> <label class="c-field__label" part="label"><slot name="label">Label</slot></label> <slot name="input"></slot> <span class="c-field__hint" part="hint"><slot name="hint"></slot></span> </div>`);
|
|
461
|
+
// (folded in from the hand-written component that used to carry its own copy of the sheet logic)
|
|
462
|
+
shadow("contour-shadow-alert", `<div class="c-alert" part="alert"> <div class="c-alert__title" part="title"><slot name="title"></slot></div> <div class="c-alert__body" part="body"><slot></slot></div> <div class="c-alert__actions" part="actions"><slot name="action"></slot></div> <button class="c-alert__close" part="close" type="button" aria-label="Close">×</button> </div>`);
|
|
463
|
+
shadow("contour-shadow-tag", `<span class="c-tag" part="tag"><slot></slot><button class="c-tag__remove" part="remove" type="button" aria-label="Remove">×</button></span>`);
|
|
464
|
+
shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-pill"><slot></slot><button class="c-filter-pill__remove" part="remove" type="button" aria-label="Remove filter">×</button></span>`);
|
|
465
|
+
|
|
466
|
+
// The dialog is the one wrapper with behaviour, because a close button that
|
|
467
|
+
// does not close is a control the reader cannot use.
|
|
468
|
+
const DIALOG_MARKUP = "<dialog class=\"c-dialog\" part=\"dialog\"> <div class=\"c-dialog__head\" part=\"head\"> <slot name=\"title\"></slot> <button class=\"c-btn c-btn--icon c-btn--ghost\" part=\"close\" type=\"button\" aria-label=\"Close\"> <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\"><path d=\"m18 6-12 12M6 6l12 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.7\" stroke-linecap=\"round\"/></svg> </button> </div> <div class=\"c-dialog__body\" part=\"body\"><slot></slot></div> <div class=\"c-dialog__foot\" part=\"foot\"><slot name=\"foot\"></slot></div> </dialog>";
|
|
469
|
+
SHADOW_MARKUP["contour-shadow-dialog"] = DIALOG_MARKUP;
|
|
470
|
+
recordParts("contour-shadow-dialog", DIALOG_MARKUP);
|
|
471
|
+
class ContourShadowDialog extends ContourShadow {
|
|
472
|
+
static contourTemplate = (typeof document !== "undefined") ? (() => {
|
|
473
|
+
const tpl = document.createElement("template");
|
|
474
|
+
setHTML(tpl, DIALOG_MARKUP);
|
|
475
|
+
return tpl;
|
|
476
|
+
})() : null;
|
|
477
|
+
enhance(root) {
|
|
478
|
+
super.enhance(root);
|
|
479
|
+
// The base constructor AND connectedCallback both call enhance; the base's
|
|
480
|
+
if (this._wiredShadowDialog) return;
|
|
481
|
+
this._wiredShadowDialog = true;
|
|
482
|
+
const dlg = root.querySelector("dialog");
|
|
483
|
+
const close = root.querySelector('[part="close"]');
|
|
484
|
+
if (close) close.addEventListener("click", () => dlg?.close());
|
|
485
|
+
if (dlg) {
|
|
486
|
+
let lastFocus = null;
|
|
487
|
+
// `<dialog>` fires no `show` or `close` events in this engine (measured
|
|
488
|
+
dlg.addEventListener("beforetoggle", (e) => {
|
|
489
|
+
if (e.newState === "open") {
|
|
490
|
+
lastFocus = document.activeElement;
|
|
491
|
+
// beforetoggle fires BEFORE dialog.open flips, so the attribute
|
|
492
|
+
// write must not re-enter attributeChangedCallback's show() path.
|
|
493
|
+
this._syncingOpenAttr = true;
|
|
494
|
+
if (!this.hasAttribute("open")) this.setAttribute("open", "");
|
|
495
|
+
this._syncingOpenAttr = false;
|
|
496
|
+
this.dispatchEvent(new CustomEvent("contour:open", { bubbles: true, composed: true }));
|
|
497
|
+
// Focus the close button or first focusable element
|
|
498
|
+
const focusable = dlg.querySelector("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");
|
|
499
|
+
if (focusable) try { focusable.focus(); } catch (e) {}
|
|
500
|
+
} else if (e.newState === "closed") {
|
|
501
|
+
this._syncingOpenAttr = true;
|
|
502
|
+
if (this.hasAttribute("open")) this.removeAttribute("open");
|
|
503
|
+
this._syncingOpenAttr = false;
|
|
504
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true }));
|
|
505
|
+
// Restore focus
|
|
506
|
+
if (lastFocus && typeof lastFocus.focus === "function") {
|
|
507
|
+
try { lastFocus.focus(); } catch (e) {}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
// Focus trap: keep Tab within the dialog. R31-04: the focusables are not
|
|
512
|
+
// only in the shadow tree — slotted light-DOM controls (the dialog body
|
|
513
|
+
// is a <slot>) are real tab stops too, and `document.activeElement` is
|
|
514
|
+
// the shadow host, not the control. Collect both, and read the
|
|
515
|
+
// shadow-aware active element.
|
|
516
|
+
const collectFocusable = () => {
|
|
517
|
+
const sel = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
|
|
518
|
+
const out = Array.from(dlg.querySelectorAll(sel));
|
|
519
|
+
for (const slot of dlg.querySelectorAll("slot")) {
|
|
520
|
+
for (const n of slot.assignedElements({ flatten: true })) {
|
|
521
|
+
if (n.matches(sel)) out.push(n);
|
|
522
|
+
for (const sub of n.querySelectorAll(sel)) out.push(sub);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return out;
|
|
526
|
+
};
|
|
527
|
+
const activeEl = () => (this.shadowRoot && this.shadowRoot.activeElement) || document.activeElement;
|
|
528
|
+
dlg.addEventListener("keydown", (e) => {
|
|
529
|
+
if (e.key !== "Tab") return;
|
|
530
|
+
const focusables = collectFocusable();
|
|
531
|
+
if (!focusables.length) return;
|
|
532
|
+
const first = focusables[0];
|
|
533
|
+
const last = focusables[focusables.length - 1];
|
|
534
|
+
if (e.shiftKey && activeEl() === first) {
|
|
535
|
+
e.preventDefault();
|
|
536
|
+
last.focus();
|
|
537
|
+
} else if (!e.shiftKey && activeEl() === last) {
|
|
538
|
+
e.preventDefault();
|
|
539
|
+
first.focus();
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
static get observedAttributes() { return [...super.observedAttributes, "open"]; }
|
|
545
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
546
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
547
|
+
// The host's `open` attribute drives the inner native dialog, matching
|
|
548
|
+
// the light family; without this the attribute was inert (R25-12).
|
|
549
|
+
if (name === "open" && this.shadowRoot && !this._syncingOpenAttr) {
|
|
550
|
+
const dlg = this.shadowRoot.querySelector("dialog");
|
|
551
|
+
if (dlg) {
|
|
552
|
+
if (newValue !== null && !dlg.open) this.show();
|
|
553
|
+
else if (newValue === null && dlg.open) this.close();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
connectedCallback() {
|
|
558
|
+
super.connectedCallback();
|
|
559
|
+
// R31-33: an `open` attribute set before the element was connected (or a
|
|
560
|
+
// show() called while disconnected) must engage the dialog once it lands
|
|
561
|
+
// in the document; showModal() on a disconnected dialog throws.
|
|
562
|
+
if (this.hasAttribute("open")) this.show();
|
|
563
|
+
}
|
|
564
|
+
show() {
|
|
565
|
+
// R31-33: showModal() throws on a disconnected element. If not yet
|
|
566
|
+
// connected, leave the `open` attribute set; connectedCallback applies it.
|
|
567
|
+
if (!this.isConnected) { if (!this.hasAttribute("open")) this.setAttribute("open", ""); return; }
|
|
568
|
+
const d = this.shadowRoot?.querySelector("dialog");
|
|
569
|
+
if (d && !d.open) d.showModal();
|
|
570
|
+
}
|
|
571
|
+
close() { const d = this.shadowRoot?.querySelector("dialog"); if (d && d.open) d.close(); }
|
|
572
|
+
// Native-dialog parity with the light family (R20 T-32): showModal() is
|
|
573
|
+
showModal() { this.show(); }
|
|
574
|
+
get open() { return !!this.shadowRoot?.querySelector("dialog")?.open; }
|
|
575
|
+
set open(v) { if (v) this.show(); else this.close(); }
|
|
576
|
+
get returnValue() { return this.shadowRoot?.querySelector("dialog")?.returnValue ?? ""; }
|
|
577
|
+
set returnValue(v) { const d = this.shadowRoot?.querySelector("dialog"); if (d) d.returnValue = String(v); }
|
|
578
|
+
}
|
|
579
|
+
define("contour-shadow-dialog", ContourShadowDialog);
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Render a Declarative Shadow DOM string for a registered contour-shadow-* element.
|
|
583
|
+
* Intended for SSR/string emission; returns null for unknown tags.
|
|
584
|
+
*/
|
|
585
|
+
const renderShadowDSD = (tag, attrs = "", light = "") => {
|
|
586
|
+
const markup = SHADOW_MARKUP[tag];
|
|
587
|
+
if (typeof markup !== "string") return null;
|
|
588
|
+
const attrStr = attrs ? (attrs.startsWith(" ") ? attrs : " " + attrs) : "";
|
|
589
|
+
return `<${tag}${attrStr}><template shadowrootmode="open">${markup}</template>${light}</${tag}>`;
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// Published once, at the end, so the array holds what the browser was actually
|
|
593
|
+
const FROZEN_SHADOW_MARKUP = Object.freeze({ ...SHADOW_MARKUP });
|
|
594
|
+
if (typeof globalThis !== "undefined") {
|
|
595
|
+
globalThis.ContourShadowTemplates = FROZEN_SHADOW_MARKUP;
|
|
596
|
+
}
|
|
597
|
+
// Only the SHADOW vocabulary publishes here (R25-06). ContourElements and
|
|
598
|
+
if (typeof window !== "undefined") {
|
|
599
|
+
window.ContourShadowParts = Object.freeze(Object.fromEntries(
|
|
600
|
+
Object.entries(SHADOW_PARTS_PUBLIC).map(([name, parts]) => [name, Object.freeze([...new Set(parts)])]),
|
|
601
|
+
));
|
|
602
|
+
if (!window.Contour) window.Contour = {};
|
|
603
|
+
try { window.Contour.shadowTemplates = FROZEN_SHADOW_MARKUP; } catch {}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export { SHADOW_MARKUP, renderShadowDSD };
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Navigation family barrel — the navigation-surface web components, split into
|
|
610
|
+
* semantic fragments. Importing this module registers every navigation
|
|
611
|
+
* component (the fragments are side-effectful: each defines its own custom
|
|
612
|
+
* elements). The build concatenates the fragments for the IIFE/ESM bundles;
|
|
613
|
+
* this barrel keeps `contour-ds/wc/navigation.mjs` working for consumers who
|
|
614
|
+
* import the family by name.
|
|
615
|
+
*/
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
class ContourMenu extends ContourBase {
|
|
623
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
624
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
625
|
+
render() {
|
|
626
|
+
this.classList.add("c-menu");
|
|
627
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "menu");
|
|
628
|
+
wireStates(this);
|
|
629
|
+
loadRemote(this, "items");
|
|
630
|
+
if (renderStates(this, "menu")) return;
|
|
631
|
+
const items = remoteData(this, "items");
|
|
632
|
+
// Slot composition wins over JSON attribute: authored items used as-is; JSON fills gaps only.
|
|
633
|
+
const authoredItems = Array.from(this.querySelectorAll("li[role='menuitem'], li.c-menu__item, [role='menuitem']"));
|
|
634
|
+
const authoredUl = this.querySelector("ul.c-menu");
|
|
635
|
+
if (authoredItems.length) {
|
|
636
|
+
// Ensure authored items are inside a ul.c-menu wrapper.
|
|
637
|
+
if (!authoredUl) {
|
|
638
|
+
const ul = document.createElement("ul");
|
|
639
|
+
ul.className = "c-menu";
|
|
640
|
+
ul.setAttribute("role", "menu");
|
|
641
|
+
// Re-parent authored items into the wrapper, preserving order.
|
|
642
|
+
for (const item of authoredItems) {
|
|
643
|
+
if (item.parentElement === this) ul.appendChild(item);
|
|
644
|
+
}
|
|
645
|
+
this.appendChild(ul);
|
|
646
|
+
} else {
|
|
647
|
+
// Ensure classes/roles on authored items inside existing wrapper.
|
|
648
|
+
for (const item of authoredItems) {
|
|
649
|
+
if (!item.classList.contains("c-menu__item")) item.classList.add("c-menu__item");
|
|
650
|
+
if (!item.getAttribute("role")) item.setAttribute("role", "menuitem");
|
|
651
|
+
if (!item.hasAttribute("tabindex")) item.setAttribute("tabindex", "-1");
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
// Set first enabled item to tabindex 0 for roving focus.
|
|
655
|
+
const first = authoredItems.find((it) => it.getAttribute("aria-disabled") !== "true");
|
|
656
|
+
if (first) first.setAttribute("tabindex", "0");
|
|
657
|
+
this.classList.remove("c-menu");
|
|
658
|
+
if (authoredUl) authoredUl.classList.add("c-menu");
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (authoredUl) {
|
|
662
|
+
// Authored ul.c-menu exists but no items yet: keep it, don't generate.
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (items) {
|
|
666
|
+
try {
|
|
667
|
+
const parsed = JSON.parse(items);
|
|
668
|
+
const ul = this.ensure("ul.c-menu", () => { const el = document.createElement("ul"); el.className = "c-menu"; el.setAttribute("role", "menu"); return el; });
|
|
669
|
+
ul.innerHTML = "";
|
|
670
|
+
ul.setAttribute("role", "menu");
|
|
671
|
+
parsed.forEach((item) => {
|
|
672
|
+
if (item === "---" || item === "separator") {
|
|
673
|
+
const li = document.createElement("li");
|
|
674
|
+
li.className = "c-menu__separator";
|
|
675
|
+
li.setAttribute("role", "separator");
|
|
676
|
+
ul.appendChild(li);
|
|
677
|
+
} else if (typeof item === "string") {
|
|
678
|
+
const li = document.createElement("li");
|
|
679
|
+
li.className = "c-menu__item";
|
|
680
|
+
li.setAttribute("role", "menuitem");
|
|
681
|
+
li.textContent = item;
|
|
682
|
+
ul.appendChild(li);
|
|
683
|
+
} else if (item.group) {
|
|
684
|
+
const li = document.createElement("li");
|
|
685
|
+
li.className = "c-menu__group";
|
|
686
|
+
li.setAttribute("role", "group");
|
|
687
|
+
if (item.group) li.setAttribute("aria-label", String(item.group));
|
|
688
|
+
const hdr = document.createElement("div");
|
|
689
|
+
hdr.className = "c-menu__group-label";
|
|
690
|
+
hdr.textContent = String(item.group);
|
|
691
|
+
li.appendChild(hdr);
|
|
692
|
+
if (Array.isArray(item.items)) {
|
|
693
|
+
const sub = document.createElement("ul");
|
|
694
|
+
sub.className = "c-menu";
|
|
695
|
+
sub.setAttribute("role", "menu");
|
|
696
|
+
item.items.forEach((subItem) => {
|
|
697
|
+
const sli = document.createElement("li");
|
|
698
|
+
sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
|
|
699
|
+
sli.setAttribute("role", "menuitem");
|
|
700
|
+
if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
|
|
701
|
+
if (subItem.label || subItem.title) {
|
|
702
|
+
const lbl = document.createElement("span");
|
|
703
|
+
lbl.className = "c-menu__label";
|
|
704
|
+
lbl.textContent = subItem.label || subItem.title || "";
|
|
705
|
+
sli.appendChild(lbl);
|
|
706
|
+
}
|
|
707
|
+
sub.appendChild(sli);
|
|
708
|
+
});
|
|
709
|
+
li.appendChild(sub);
|
|
710
|
+
}
|
|
711
|
+
ul.appendChild(li);
|
|
712
|
+
} else {
|
|
713
|
+
const li = document.createElement("li");
|
|
714
|
+
li.className = "c-menu__item" + (item.danger ? " c-menu__item--danger" : "") + (item.disabled ? " c-menu__item--disabled" : "");
|
|
715
|
+
// A checkbox/radio item carries its state, not just a label.
|
|
716
|
+
const role = item.type === "checkbox" ? "menuitemcheckbox" : item.type === "radio" ? "menuitemradio" : "menuitem";
|
|
717
|
+
li.setAttribute("role", role);
|
|
718
|
+
if (item.type === "checkbox" || item.type === "radio") li.setAttribute("aria-checked", String(!!item.checked));
|
|
719
|
+
if (item.disabled) li.setAttribute("aria-disabled", "true");
|
|
720
|
+
if (item.items && Array.isArray(item.items)) {
|
|
721
|
+
li.setAttribute("aria-haspopup", "menu");
|
|
722
|
+
li.setAttribute("aria-expanded", "false");
|
|
723
|
+
}
|
|
724
|
+
if (item.label || item.title) {
|
|
725
|
+
const lbl = document.createElement("span");
|
|
726
|
+
lbl.className = "c-menu__label";
|
|
727
|
+
lbl.textContent = item.label || item.title || "";
|
|
728
|
+
li.appendChild(lbl);
|
|
729
|
+
}
|
|
730
|
+
if (item.shortcut) {
|
|
731
|
+
const sc = document.createElement("span");
|
|
732
|
+
sc.className = "c-menu__shortcut";
|
|
733
|
+
sc.textContent = item.shortcut;
|
|
734
|
+
li.appendChild(sc);
|
|
735
|
+
}
|
|
736
|
+
// Build nested submenu for haspopup: without it the item advertises a menu that opens onto nothing.
|
|
737
|
+
if (item.items && Array.isArray(item.items)) {
|
|
738
|
+
const sub = document.createElement("ul");
|
|
739
|
+
sub.className = "c-menu";
|
|
740
|
+
sub.setAttribute("role", "menu");
|
|
741
|
+
item.items.forEach((subItem) => {
|
|
742
|
+
const sli = document.createElement("li");
|
|
743
|
+
sli.className = "c-menu__item" + (subItem.danger ? " c-menu__item--danger" : "") + (subItem.disabled ? " c-menu__item--disabled" : "");
|
|
744
|
+
sli.setAttribute("role", "menuitem");
|
|
745
|
+
if (subItem.disabled) sli.setAttribute("aria-disabled", "true");
|
|
746
|
+
if (subItem.label || subItem.title) {
|
|
747
|
+
const sl = document.createElement("span");
|
|
748
|
+
sl.className = "c-menu__label";
|
|
749
|
+
sl.textContent = subItem.label || subItem.title || "";
|
|
750
|
+
sli.appendChild(sl);
|
|
751
|
+
}
|
|
752
|
+
sub.appendChild(sli);
|
|
753
|
+
});
|
|
754
|
+
li.appendChild(sub);
|
|
755
|
+
}
|
|
756
|
+
ul.appendChild(li);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
if (ul.parentNode !== this) this.appendChild(ul);
|
|
760
|
+
this.classList.remove("c-menu");
|
|
761
|
+
ul.classList.add("c-menu");
|
|
762
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
763
|
+
} else {
|
|
764
|
+
renderEmpty(this, "menu");
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
enhance() {
|
|
768
|
+
wireMenu(this);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
define("contour-menu", ContourMenu);
|
|
772
|
+
class ContourTabs extends ContourBase {
|
|
773
|
+
static get observed() { return ["tabs", "items", "autoplay", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "orientation", "closable", "cache-key", "no-cache"]; }
|
|
774
|
+
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 } }; }
|
|
775
|
+
render() {
|
|
776
|
+
this.classList.add("c-tabs");
|
|
777
|
+
wireStates(this);
|
|
778
|
+
loadRemote(this, "tabs");
|
|
779
|
+
if (renderStates(this, "tabs")) return;
|
|
780
|
+
// `items` is the attribute the guide's counterpart markup uses (same name CSS block reads); `tabs` is legacy. Accept both so documented markup works.
|
|
781
|
+
const tabs = remoteData(this, "tabs") || remoteData(this, "items") || this.getAttribute("tabs") || this.getAttribute("items");
|
|
782
|
+
// Slot composition wins over JSON attribute (same as ContourMenu): authored tabs/panels used as-is; JSON fills gaps only.
|
|
783
|
+
const authoredTabs = Array.from(this.querySelectorAll("[role='tab']"));
|
|
784
|
+
const authoredList = this.querySelector(".c-tabs__list");
|
|
785
|
+
const authoredPanels = Array.from(this.querySelectorAll(".c-tabs__panel"));
|
|
786
|
+
|
|
787
|
+
if (authoredTabs.length) {
|
|
788
|
+
// Ensure authored tabs are inside a .c-tabs__list wrapper.
|
|
789
|
+
if (!authoredList) {
|
|
790
|
+
const list = document.createElement("div");
|
|
791
|
+
list.className = "c-tabs__list";
|
|
792
|
+
list.setAttribute("role", "tablist");
|
|
793
|
+
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
794
|
+
list.setAttribute("aria-orientation", orientation);
|
|
795
|
+
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
796
|
+
for (const tab of authoredTabs) {
|
|
797
|
+
if (tab.parentElement === this) list.appendChild(tab);
|
|
798
|
+
}
|
|
799
|
+
this.prepend(list);
|
|
800
|
+
}
|
|
801
|
+
// Normalise attributes on authored tabs and link panels.
|
|
802
|
+
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
803
|
+
if (authoredList) authoredList.setAttribute("aria-orientation", orientation);
|
|
804
|
+
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
805
|
+
|
|
806
|
+
const authoredIndex = authoredTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
807
|
+
authoredTabs.forEach((tab, i) => {
|
|
808
|
+
if (!tab.classList.contains("c-tabs__tab")) tab.classList.add("c-tabs__tab");
|
|
809
|
+
if (!tab.getAttribute("role")) tab.setAttribute("role", "tab");
|
|
810
|
+
let panelId = tab.getAttribute("aria-controls");
|
|
811
|
+
if (!panelId) {
|
|
812
|
+
// Only generate a panel if there's authored content to pair with. Empty generated panel is worse — screen reader announces "blank".
|
|
813
|
+
const authoredPanel = authoredPanels[i];
|
|
814
|
+
if (authoredPanel) {
|
|
815
|
+
panelId = authoredPanel.id || contourId("c-tabs-panel");
|
|
816
|
+
authoredPanel.id = panelId;
|
|
817
|
+
tab.setAttribute("aria-controls", panelId);
|
|
818
|
+
}
|
|
819
|
+
} else {
|
|
820
|
+
// Tab has aria-controls: ensure the panel exists and is linked.
|
|
821
|
+
let panel = authoredPanels.find((p) => p.id === panelId);
|
|
822
|
+
if (!panel) {
|
|
823
|
+
panel = document.createElement("div");
|
|
824
|
+
panel.className = "c-tabs__panel";
|
|
825
|
+
panel.id = panelId;
|
|
826
|
+
panel.setAttribute("role", "tabpanel");
|
|
827
|
+
this.appendChild(panel);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const selected = authoredIndex >= 0 ? i === authoredIndex : i === 0;
|
|
831
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
832
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
833
|
+
const ctrl = tab.getAttribute("aria-controls");
|
|
834
|
+
const panel = ctrl ? document.getElementById(ctrl) : null;
|
|
835
|
+
if (panel) panel.hidden = !selected;
|
|
836
|
+
});
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
if (tabs && !authoredTabs.length) {
|
|
841
|
+
try {
|
|
842
|
+
const parsed = JSON.parse(tabs);
|
|
843
|
+
const list = this.ensure(".c-tabs__list", () => { const el = document.createElement("div"); el.className = "c-tabs__list"; el.setAttribute("role", "tablist"); return el; });
|
|
844
|
+
list.setAttribute("role", "tablist");
|
|
845
|
+
const orientation = this.getAttribute("orientation") === "vertical" ? "vertical" : "horizontal";
|
|
846
|
+
list.setAttribute("aria-orientation", orientation);
|
|
847
|
+
if (orientation === "vertical") this.classList.add("c-tabs--vertical"); else this.classList.remove("c-tabs--vertical");
|
|
848
|
+
// Preserve the selected tab across rebuilds (G-31): read the
|
|
849
|
+
// pre-drop selection before clearing, then re-apply it.
|
|
850
|
+
const _prevTabs = Array.from(list.querySelectorAll("[role='tab']"));
|
|
851
|
+
const _prevSel = _prevTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
852
|
+
const _keepIdx = _prevSel >= 0 ? _prevSel : 0;
|
|
853
|
+
list.innerHTML = "";
|
|
854
|
+
// Remove any previously generated panels so re-render doesn't stack.
|
|
855
|
+
Array.from(this.querySelectorAll(".c-tabs__panel")).forEach((n) => n.remove());
|
|
856
|
+
parsed.forEach((t, i) => {
|
|
857
|
+
const label = typeof t === "string" ? t : (t.label || t.title || "");
|
|
858
|
+
const panelId = contourId("c-tabs-panel");
|
|
859
|
+
// A tab is not a <button> when closable: HTML forbids interactive content inside a button, so close control would be invalid markup and unreachable.
|
|
860
|
+
const btn = document.createElement(this.hasAttribute("closable") ? "div" : "button");
|
|
861
|
+
btn.className = "c-tabs__tab";
|
|
862
|
+
if (btn.tagName === "BUTTON") btn.type = "button";
|
|
863
|
+
btn.setAttribute("role", "tab");
|
|
864
|
+
btn.setAttribute("aria-selected", String(i === _keepIdx));
|
|
865
|
+
btn.setAttribute("aria-controls", panelId);
|
|
866
|
+
btn.tabIndex = i === _keepIdx ? 0 : -1;
|
|
867
|
+
const tabLabel = document.createElement("span");
|
|
868
|
+
tabLabel.textContent = label;
|
|
869
|
+
btn.textContent = "";
|
|
870
|
+
btn.appendChild(tabLabel);
|
|
871
|
+
if (this.hasAttribute("closable")) {
|
|
872
|
+
const closeBtn = document.createElement("button");
|
|
873
|
+
closeBtn.type = "button";
|
|
874
|
+
closeBtn.className = "c-tabs__close";
|
|
875
|
+
closeBtn.setAttribute("aria-label", labelText(this, "close", "Close") + " " + label);
|
|
876
|
+
closeBtn.textContent = "×";
|
|
877
|
+
closeBtn.addEventListener("click", (e) => {
|
|
878
|
+
e.stopPropagation();
|
|
879
|
+
const idx = Array.from(list.querySelectorAll("[role='tab']")).indexOf(btn);
|
|
880
|
+
// remove tab + panel
|
|
881
|
+
const ctrl = btn.getAttribute("aria-controls");
|
|
882
|
+
const panel = ctrl ? document.getElementById(ctrl) : null;
|
|
883
|
+
btn.remove();
|
|
884
|
+
if (panel) panel.remove();
|
|
885
|
+
this.dispatchEvent(new CustomEvent("contour:close", { bubbles: true, composed: true, detail: { index: idx, label } }));
|
|
886
|
+
// activate first remaining tab
|
|
887
|
+
const remaining = list.querySelectorAll("[role='tab']");
|
|
888
|
+
if (remaining.length) remaining[0].click();
|
|
889
|
+
});
|
|
890
|
+
btn.appendChild(closeBtn);
|
|
891
|
+
}
|
|
892
|
+
list.appendChild(btn);
|
|
893
|
+
const panel = document.createElement("div");
|
|
894
|
+
panel.className = "c-tabs__panel";
|
|
895
|
+
panel.id = panelId;
|
|
896
|
+
panel.setAttribute("role", "tabpanel");
|
|
897
|
+
if (typeof t === "object" && t !== null && t.content !== undefined) {
|
|
898
|
+
panel.textContent = String(t.content);
|
|
899
|
+
}
|
|
900
|
+
if (i !== _keepIdx) panel.hidden = true;
|
|
901
|
+
this.appendChild(panel);
|
|
902
|
+
});
|
|
903
|
+
if (list.parentNode !== this) this.prepend(list);
|
|
904
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
905
|
+
} else if (!tabs && !authoredTabs.length) {
|
|
906
|
+
const list = this.querySelector(".c-tabs__list");
|
|
907
|
+
if (list) list.remove();
|
|
908
|
+
renderEmpty(this, "tabs");
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
enhance() {
|
|
912
|
+
wireTabs(this);
|
|
913
|
+
// Tabs autoplay mirrors streaming chart's interval contract (data.mjs): autoplay advances, pause stops, timer owned once, gated on reduced motion. Advance is a click on next tab, so wireTabs' listener handles activation and emits contour:tab-change. Hover/focus also stop loop (WCAG 2.2.2).
|
|
914
|
+
const sync = () => {
|
|
915
|
+
const seconds = parseFloat(this.getAttribute("autoplay") || "");
|
|
916
|
+
const paused = this.hasAttribute("pause") || this._tabsHover || this._tabsFocus;
|
|
917
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
918
|
+
const want = Number.isFinite(seconds) && seconds > 0 && !paused && !reduced;
|
|
919
|
+
if (want === this._tabsAutoplayRunning) return;
|
|
920
|
+
this._tabsAutoplayRunning = want;
|
|
921
|
+
if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; }
|
|
922
|
+
if (!want) return;
|
|
923
|
+
this._tabsTimer = setInterval(() => {
|
|
924
|
+
if (!this.isConnected || this.hasAttribute("pause") || this._tabsHover || this._tabsFocus) return;
|
|
925
|
+
const list = this.querySelector(".c-tabs__list");
|
|
926
|
+
const tabs = list ? Array.from(list.querySelectorAll("[role='tab']")) : [];
|
|
927
|
+
if (!tabs.length) return;
|
|
928
|
+
const cur = tabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
929
|
+
const next = tabs[(cur + 1) % tabs.length];
|
|
930
|
+
if (next) next.click();
|
|
931
|
+
}, Math.max(1000, seconds * 1000));
|
|
932
|
+
};
|
|
933
|
+
// Re-run on every render so autoplay/pause attribute changes are picked up; listeners and disposer installed once.
|
|
934
|
+
sync();
|
|
935
|
+
if (this._wiredTabsAutoplay) return;
|
|
936
|
+
this._wiredTabsAutoplay = true;
|
|
937
|
+
this.addEventListener("pointerenter", () => { this._tabsHover = true; sync(); });
|
|
938
|
+
this.addEventListener("pointerleave", () => { this._tabsHover = false; sync(); });
|
|
939
|
+
this.addEventListener("focusin", () => { this._tabsFocus = true; sync(); });
|
|
940
|
+
this.addEventListener("focusout", () => { this._tabsFocus = false; sync(); });
|
|
941
|
+
onDispose(this, () => { if (this._tabsTimer !== undefined) { clearInterval(this._tabsTimer); this._tabsTimer = undefined; } });
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
define("contour-tabs", ContourTabs);
|
|
945
|
+
class ContourCodeTabs extends ContourBase {
|
|
946
|
+
static get observed() { return ["tabs", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "cache-key", "no-cache"]; }
|
|
947
|
+
static get properties() { return { tabs: { attribute: "tabs" }, src: { attribute: "src" } }; }
|
|
948
|
+
render() {
|
|
949
|
+
this.classList.add("c-code-tabs");
|
|
950
|
+
wireStates(this);
|
|
951
|
+
loadRemote(this, "tabs");
|
|
952
|
+
if (renderStates(this, "code-tabs")) return;
|
|
953
|
+
const tabs = remoteData(this, "tabs");
|
|
954
|
+
const list = this.querySelector(".c-code-tabs__list");
|
|
955
|
+
const authored = list ? Array.from(list.children).filter((n) => n.getAttribute && n.getAttribute("role") === "tab") : [];
|
|
956
|
+
if (tabs && !authored.length) {
|
|
957
|
+
try {
|
|
958
|
+
const parsed = JSON.parse(tabs);
|
|
959
|
+
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; });
|
|
960
|
+
l.setAttribute("role", "tablist");
|
|
961
|
+
const _prevCodeTabs = Array.from(l.querySelectorAll("[role='tab']"));
|
|
962
|
+
const _prevCodeSel = _prevCodeTabs.findIndex((t) => t.getAttribute("aria-selected") === "true");
|
|
963
|
+
const _keepCodeIdx = _prevCodeSel >= 0 ? _prevCodeSel : 0;
|
|
964
|
+
l.innerHTML = "";
|
|
965
|
+
Array.from(this.querySelectorAll(".c-code-tabs__panel")).forEach((n) => n.remove());
|
|
966
|
+
parsed.forEach((t, i) => {
|
|
967
|
+
const label = typeof t === "string" ? t : (t.label || t.title || "");
|
|
968
|
+
const panelId = contourId("c-code-tabs-panel");
|
|
969
|
+
const btn = document.createElement("button");
|
|
970
|
+
btn.className = "c-code-tabs__tab";
|
|
971
|
+
btn.type = "button";
|
|
972
|
+
btn.setAttribute("role", "tab");
|
|
973
|
+
btn.setAttribute("aria-selected", String(i === _keepCodeIdx));
|
|
974
|
+
btn.setAttribute("aria-controls", panelId);
|
|
975
|
+
btn.tabIndex = i === _keepCodeIdx ? 0 : -1;
|
|
976
|
+
btn.textContent = label;
|
|
977
|
+
l.appendChild(btn);
|
|
978
|
+
const panel = document.createElement("div");
|
|
979
|
+
panel.className = "c-code-tabs__panel";
|
|
980
|
+
panel.id = panelId;
|
|
981
|
+
panel.setAttribute("role", "tabpanel");
|
|
982
|
+
if (typeof t === "object" && t !== null && t.content !== undefined) {
|
|
983
|
+
// Use <pre><code> for code panels.
|
|
984
|
+
const pre = document.createElement("pre");
|
|
985
|
+
const code = document.createElement("code");
|
|
986
|
+
code.textContent = String(t.content);
|
|
987
|
+
pre.appendChild(code);
|
|
988
|
+
panel.appendChild(pre);
|
|
989
|
+
// Copy button.
|
|
990
|
+
const copyBtn = document.createElement("button");
|
|
991
|
+
copyBtn.className = "c-btn c-btn--ghost c-btn--sm c-code-tabs__copy";
|
|
992
|
+
copyBtn.type = "button";
|
|
993
|
+
copyBtn.textContent = labelText(this, "copy", "Copy");
|
|
994
|
+
copyBtn.setAttribute("aria-label", labelText(this, "copy-code", "Copy code"));
|
|
995
|
+
copyBtn.dataset.copy = String(t.content);
|
|
996
|
+
panel.appendChild(copyBtn);
|
|
997
|
+
}
|
|
998
|
+
if (i !== _keepCodeIdx) panel.hidden = true;
|
|
999
|
+
this.appendChild(panel);
|
|
1000
|
+
});
|
|
1001
|
+
if (l.parentNode !== this) this.prepend(l);
|
|
1002
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1003
|
+
} else if (!tabs && list) {
|
|
1004
|
+
list.remove();
|
|
1005
|
+
renderEmpty(this, "code-tabs");
|
|
1006
|
+
} else if (!tabs && !list) {
|
|
1007
|
+
renderEmpty(this, "code-tabs");
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
enhance() {
|
|
1011
|
+
wireTabs(this);
|
|
1012
|
+
// R24-42: copy button handler.
|
|
1013
|
+
if (!this._wiredCodeTabs) {
|
|
1014
|
+
this._wiredCodeTabs = true;
|
|
1015
|
+
this.addEventListener("click", (e) => {
|
|
1016
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-code-tabs__copy") : null;
|
|
1017
|
+
if (!btn || !this.contains(btn)) return;
|
|
1018
|
+
const text = btn.dataset.copy || "";
|
|
1019
|
+
if (text) {
|
|
1020
|
+
try { navigator.clipboard.writeText(text); btn.textContent = labelText(this, "copied", "Copied!"); setTimeout(() => { btn.textContent = labelText(this, "copy", "Copy"); }, 2000); } catch (err) {}
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
define("contour-code-tabs", ContourCodeTabs);
|
|
1027
|
+
class ContourBreadcrumb extends ContourBase {
|
|
1028
|
+
static get observed() { return ["items", "separator", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1029
|
+
static get properties() { return { items: { attribute: "items" }, separator: { attribute: "separator" }, max: { attribute: "max", type: Number }, src: { attribute: "src" } } };
|
|
1030
|
+
render() {
|
|
1031
|
+
this.classList.add("c-breadcrumb");
|
|
1032
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
1033
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb"));
|
|
1034
|
+
wireStates(this);
|
|
1035
|
+
loadRemote(this, "items");
|
|
1036
|
+
if (renderStates(this, "breadcrumb")) return;
|
|
1037
|
+
const items = remoteData(this, "items");
|
|
1038
|
+
// Slot composition: authored <li> items win over the JSON attribute.
|
|
1039
|
+
const nav = this.querySelector("nav");
|
|
1040
|
+
const ol = nav ? nav.querySelector("ol") : null;
|
|
1041
|
+
const authored = ol ? Array.from(ol.children).filter((n) => n.tagName === "LI") : [];
|
|
1042
|
+
if (items && !authored.length) {
|
|
1043
|
+
try {
|
|
1044
|
+
const parsed = JSON.parse(items);
|
|
1045
|
+
const n = this.ensure("nav", () => { const el = document.createElement("nav"); el.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb")); return el; });
|
|
1046
|
+
n.setAttribute("aria-label", labelText(this, "breadcrumb", "Breadcrumb"));
|
|
1047
|
+
// A unique id per instance: two breadcrumbs on a page must not share
|
|
1048
|
+
// one, and the overflow button points at this one through aria-controls.
|
|
1049
|
+
if (!n.id) n.id = contourId("contour-breadcrumb-list");
|
|
1050
|
+
n.innerHTML = "";
|
|
1051
|
+
// Items are an ordered list so screen readers announce position.
|
|
1052
|
+
const ol = document.createElement("ol");
|
|
1053
|
+
ol.className = "c-breadcrumb__list";
|
|
1054
|
+
n.appendChild(ol);
|
|
1055
|
+
const sep = this.getAttribute("separator") || "/";
|
|
1056
|
+
const max = this._overflowExpanded ? null : this.max;
|
|
1057
|
+
const shown = Number.isFinite(max) && max > 1 && parsed.length > max
|
|
1058
|
+
? parsed.slice(-max)
|
|
1059
|
+
: parsed;
|
|
1060
|
+
if (Number.isFinite(max) && max > 1 && parsed.length > max) {
|
|
1061
|
+
const btn = document.createElement("button");
|
|
1062
|
+
btn.type = "button";
|
|
1063
|
+
btn.className = "c-breadcrumb__overflow";
|
|
1064
|
+
btn.setAttribute("aria-label", `Show ${parsed.length - shown.length + 1} more items`);
|
|
1065
|
+
btn.setAttribute("aria-expanded", "false");
|
|
1066
|
+
btn.setAttribute("aria-controls", n.id);
|
|
1067
|
+
btn.textContent = "…";
|
|
1068
|
+
btn.addEventListener("click", () => {
|
|
1069
|
+
// Handler-owned flag outside OBSERVED to avoid re-entering render.
|
|
1070
|
+
this._overflowExpanded = true;
|
|
1071
|
+
this.requestRender();
|
|
1072
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { expanded: true } }));
|
|
1073
|
+
});
|
|
1074
|
+
const li = document.createElement("li");
|
|
1075
|
+
li.appendChild(btn);
|
|
1076
|
+
ol.appendChild(li);
|
|
1077
|
+
}
|
|
1078
|
+
shown.forEach((item, i) => {
|
|
1079
|
+
const li = document.createElement("li");
|
|
1080
|
+
if (i < shown.length - 1) {
|
|
1081
|
+
const a = document.createElement("a");
|
|
1082
|
+
a.href = safeHref(item.href || "#");
|
|
1083
|
+
a.textContent = item.label || item;
|
|
1084
|
+
li.appendChild(a);
|
|
1085
|
+
const s = document.createElement("span");
|
|
1086
|
+
s.className = "c-breadcrumb__sep";
|
|
1087
|
+
s.setAttribute("aria-hidden", "true");
|
|
1088
|
+
s.textContent = sep;
|
|
1089
|
+
li.appendChild(s);
|
|
1090
|
+
} else {
|
|
1091
|
+
const span = document.createElement("span");
|
|
1092
|
+
span.textContent = item.label || item;
|
|
1093
|
+
span.setAttribute("aria-current", "page");
|
|
1094
|
+
li.appendChild(span);
|
|
1095
|
+
}
|
|
1096
|
+
ol.appendChild(li);
|
|
1097
|
+
});
|
|
1098
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1099
|
+
} else if (!items && nav) {
|
|
1100
|
+
nav.remove();
|
|
1101
|
+
} else if (!items && !nav) {
|
|
1102
|
+
renderEmpty(this, "breadcrumb");
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
define("contour-breadcrumb", ContourBreadcrumb);
|
|
1107
|
+
class ContourPagination extends ContourBase {
|
|
1108
|
+
static get observed() { return ["pages", "current", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "cache-key", "no-cache"]; }
|
|
1109
|
+
static get properties() { return { pages: { attribute: "pages" }, current: { attribute: "current" }, src: { attribute: "src" } }; }
|
|
1110
|
+
render() {
|
|
1111
|
+
this.classList.add("c-pagination");
|
|
1112
|
+
// Pagination is a navigation landmark: APG names it; screen reader's landmark list is where readers look for "page N of M".
|
|
1113
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
1114
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "pagination", "Pagination"));
|
|
1115
|
+
wireStates(this);
|
|
1116
|
+
loadRemote(this, "pages");
|
|
1117
|
+
if (renderStates(this, "pagination")) return;
|
|
1118
|
+
const pages = remoteData(this, "pages");
|
|
1119
|
+
// Drop previously generated links so a re-render cannot stack a second set.
|
|
1120
|
+
Array.from(this.querySelectorAll(".c-pagination__link")).forEach((n) => n.remove());
|
|
1121
|
+
let currentAttr = this.getAttribute("current") || "1";
|
|
1122
|
+
if (this.getAttribute("persist") === "storage" && this.id) {
|
|
1123
|
+
try { const stored = localStorage.getItem("contour-pagination:" + this.id); if (stored !== null) currentAttr = stored; } catch (e) {}
|
|
1124
|
+
} else if (this.getAttribute("persist") === "url") {
|
|
1125
|
+
try { const v = new URLSearchParams(window.location.search).get("c-pagination"); if (v !== null) currentAttr = v; } catch (e) {}
|
|
1126
|
+
}
|
|
1127
|
+
const current = parseInt(currentAttr, "10") || 1;
|
|
1128
|
+
// Publish current page as `page` attribute so state is readable without a click (activate handler sets it on navigation).
|
|
1129
|
+
this.setAttribute("page", String(current));
|
|
1130
|
+
if (pages) {
|
|
1131
|
+
let count = parseInt(pages, 10);
|
|
1132
|
+
if (!Number.isFinite(count) || count < 1) {
|
|
1133
|
+
try { const p = JSON.parse(pages); if (Array.isArray(p)) count = p.length; } catch (e) {}
|
|
1134
|
+
}
|
|
1135
|
+
// Prev button.
|
|
1136
|
+
const prev = document.createElement("button");
|
|
1137
|
+
prev.type = "button";
|
|
1138
|
+
prev.className = "c-pagination__link c-pagination__prev";
|
|
1139
|
+
prev.setAttribute("data-action", "prev");
|
|
1140
|
+
setHTML(prev, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-left" /></svg>');
|
|
1141
|
+
prev.setAttribute("aria-label", labelText(this, "prev", "Previous page"));
|
|
1142
|
+
// Disable prev at page 1.
|
|
1143
|
+
if (current <= 1) prev.setAttribute("disabled", "");
|
|
1144
|
+
this.appendChild(prev);
|
|
1145
|
+
// Ellipsis windowing: show first, last, current±1, with ellipsis for gaps. Keeps button count bounded for large page counts (60 pages → ~7 buttons).
|
|
1146
|
+
const window = new Set([1, count, current]);
|
|
1147
|
+
if (current > 1) window.add(current - 1);
|
|
1148
|
+
if (current < count) window.add(current + 1);
|
|
1149
|
+
const sorted = [...window].filter(p => p >= 1 && p <= count).sort((a, b) => a - b);
|
|
1150
|
+
let prevPage = 0;
|
|
1151
|
+
for (const i of sorted) {
|
|
1152
|
+
if (prevPage && i - prevPage > 1) {
|
|
1153
|
+
const gap = document.createElement("span");
|
|
1154
|
+
gap.className = "c-pagination__ellipsis";
|
|
1155
|
+
gap.textContent = "…";
|
|
1156
|
+
gap.setAttribute("aria-hidden", "true");
|
|
1157
|
+
this.appendChild(gap);
|
|
1158
|
+
}
|
|
1159
|
+
const btn = document.createElement("button");
|
|
1160
|
+
btn.type = "button";
|
|
1161
|
+
btn.className = "c-pagination__link";
|
|
1162
|
+
btn.textContent = String(i);
|
|
1163
|
+
if (i === current) {
|
|
1164
|
+
btn.setAttribute("aria-current", "page");
|
|
1165
|
+
}
|
|
1166
|
+
this.appendChild(btn);
|
|
1167
|
+
prevPage = i;
|
|
1168
|
+
}
|
|
1169
|
+
// Next button.
|
|
1170
|
+
const next = document.createElement("button");
|
|
1171
|
+
next.type = "button";
|
|
1172
|
+
next.className = "c-pagination__link c-pagination__next";
|
|
1173
|
+
next.setAttribute("data-action", "next");
|
|
1174
|
+
setHTML(next, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
1175
|
+
next.setAttribute("aria-label", labelText(this, "next", "Next page"));
|
|
1176
|
+
// Disable next on last page.
|
|
1177
|
+
if (current >= count) next.setAttribute("disabled", "");
|
|
1178
|
+
this.appendChild(next);
|
|
1179
|
+
} else {
|
|
1180
|
+
renderEmpty(this, "pagination");
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
enhance() {
|
|
1184
|
+
wirePagination(this);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
define("contour-pagination", ContourPagination);
|
|
1188
|
+
class ContourPagerFull extends ContourBase {
|
|
1189
|
+
static get observed() { return ["prev", "next"]; }
|
|
1190
|
+
static get properties() { return { prev: { attribute: "prev" }, next: { attribute: "next" } }; }
|
|
1191
|
+
render() {
|
|
1192
|
+
this.classList.add("c-pager");
|
|
1193
|
+
// Pager is a navigation landmark like pagination: screen reader's landmark list is where readers look for prev/next.
|
|
1194
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
1195
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "pagination", "Pagination"));
|
|
1196
|
+
// Drop previously generated links so a re-render cannot stack a second set.
|
|
1197
|
+
Array.from(this.querySelectorAll(".c-pager__link")).forEach((n) => n.remove());
|
|
1198
|
+
const prev = this.getAttribute("prev");
|
|
1199
|
+
const next = this.getAttribute("next");
|
|
1200
|
+
if (prev) {
|
|
1201
|
+
const a = document.createElement("a");
|
|
1202
|
+
a.className = "c-pager__link";
|
|
1203
|
+
a.href = safeHref(prev.split("|")[1] || "#");
|
|
1204
|
+
const dir = document.createElement("span");
|
|
1205
|
+
dir.className = "c-pager__dir";
|
|
1206
|
+
dir.textContent = labelText(this, "previous", "← Previous");
|
|
1207
|
+
a.appendChild(dir);
|
|
1208
|
+
const title = document.createElement("span");
|
|
1209
|
+
title.className = "c-pager__title";
|
|
1210
|
+
title.textContent = prev.split("|")[0];
|
|
1211
|
+
a.appendChild(title);
|
|
1212
|
+
this.appendChild(a);
|
|
1213
|
+
}
|
|
1214
|
+
if (next) {
|
|
1215
|
+
const a = document.createElement("a");
|
|
1216
|
+
a.className = "c-pager__link c-pager__link--next";
|
|
1217
|
+
a.href = safeHref(next.split("|")[1] || "#");
|
|
1218
|
+
const dir = document.createElement("span");
|
|
1219
|
+
dir.className = "c-pager__dir";
|
|
1220
|
+
dir.textContent = labelText(this, "next", "Next") + " →";
|
|
1221
|
+
a.appendChild(dir);
|
|
1222
|
+
const title = document.createElement("span");
|
|
1223
|
+
title.className = "c-pager__title";
|
|
1224
|
+
title.textContent = next.split("|")[0];
|
|
1225
|
+
a.appendChild(title);
|
|
1226
|
+
this.appendChild(a);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
define("contour-pager", ContourPagerFull);
|
|
1231
|
+
class ContourTocFull extends ContourBase {
|
|
1232
|
+
static get observed() { return ["title", "items", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "empty", "no-cache"]; }
|
|
1233
|
+
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
1234
|
+
render() {
|
|
1235
|
+
this.classList.add("c-toc");
|
|
1236
|
+
this.setAttribute("role", "group");
|
|
1237
|
+
wireStates(this);
|
|
1238
|
+
loadRemote(this, "items");
|
|
1239
|
+
if (renderStates(this, "toc")) return;
|
|
1240
|
+
const items = remoteData(this, "items");
|
|
1241
|
+
const title = this.getAttribute("title") || "On this page";
|
|
1242
|
+
const titleEl = this.ensure(".c-toc__title", () => { const el = document.createElement("div"); el.className = "c-toc__title"; return el; });
|
|
1243
|
+
titleEl.textContent = title;
|
|
1244
|
+
const list = this.querySelector(".c-toc__list");
|
|
1245
|
+
const authored = list ? Array.from(list.children).filter((n) => n.tagName === "A") : [];
|
|
1246
|
+
if (items && !authored.length) {
|
|
1247
|
+
try {
|
|
1248
|
+
const parsed = JSON.parse(items);
|
|
1249
|
+
const l = this.ensure(".c-toc__list", () => { const el = document.createElement("nav"); el.className = "c-toc__list"; return el; });
|
|
1250
|
+
l.className = "c-toc__list";
|
|
1251
|
+
l.setAttribute("aria-label", title);
|
|
1252
|
+
l.innerHTML = "";
|
|
1253
|
+
parsed.forEach((item, i) => {
|
|
1254
|
+
const a = document.createElement("a");
|
|
1255
|
+
a.className = "c-toc__link" + (item.sub ? " c-toc__link--sub" : "");
|
|
1256
|
+
a.href = safeHref(item.href || "#");
|
|
1257
|
+
a.textContent = item.label || item;
|
|
1258
|
+
a.tabIndex = i === 0 ? 0 : -1;
|
|
1259
|
+
if (item.current) a.setAttribute("aria-current", "true");
|
|
1260
|
+
l.appendChild(a);
|
|
1261
|
+
});
|
|
1262
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1263
|
+
} else if (!items && list) {
|
|
1264
|
+
list.remove();
|
|
1265
|
+
renderEmpty(this, "toc");
|
|
1266
|
+
} else if (!items && !list) {
|
|
1267
|
+
renderEmpty(this, "toc");
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
enhance() {
|
|
1271
|
+
// Scroll-spy marks the toc link whose section crossed the reading line; geometry-based, rAF-throttled.
|
|
1272
|
+
if (this._wiredTocSpy) return;
|
|
1273
|
+
const links = () => Array.from(this.querySelectorAll(".c-toc__link"));
|
|
1274
|
+
const pairs = () => links()
|
|
1275
|
+
.map((a) => {
|
|
1276
|
+
const href = a.getAttribute("href") || "";
|
|
1277
|
+
if (!href.startsWith("#") || href.length < 2) return null;
|
|
1278
|
+
const el = document.getElementById(href.slice(1));
|
|
1279
|
+
return el ? { a, el } : null;
|
|
1280
|
+
})
|
|
1281
|
+
.filter(Boolean);
|
|
1282
|
+
if (!pairs().length) return;
|
|
1283
|
+
this._wiredTocSpy = true;
|
|
1284
|
+
|
|
1285
|
+
const readingLine = () => {
|
|
1286
|
+
const raw = parseFloat(getComputedStyle(document.documentElement).getPropertyValue("--header-height"));
|
|
1287
|
+
return (Number.isFinite(raw) ? raw : 0) + Math.min(120, window.innerHeight * 0.2);
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
const update = () => {
|
|
1291
|
+
const all = pairs();
|
|
1292
|
+
if (!all.length) return;
|
|
1293
|
+
const line = readingLine();
|
|
1294
|
+
let current = all[0];
|
|
1295
|
+
for (const p of all) {
|
|
1296
|
+
if (p.el.getBoundingClientRect().top <= line) current = p;
|
|
1297
|
+
}
|
|
1298
|
+
// Last section wins at bottom of scrollable page; short documents stay on first.
|
|
1299
|
+
const scrollable = document.documentElement.scrollHeight > window.innerHeight + 2;
|
|
1300
|
+
if (scrollable && window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 2) {
|
|
1301
|
+
current = all[all.length - 1];
|
|
1302
|
+
}
|
|
1303
|
+
const id = current.el.id;
|
|
1304
|
+
links().forEach((a) => {
|
|
1305
|
+
const isCurrent = a.getAttribute("href") === "#" + id;
|
|
1306
|
+
if (isCurrent) {
|
|
1307
|
+
if (a.getAttribute("aria-current") !== "true") a.setAttribute("aria-current", "true");
|
|
1308
|
+
} else if (a.hasAttribute("aria-current")) {
|
|
1309
|
+
a.removeAttribute("aria-current");
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
let queued = 0;
|
|
1315
|
+
const schedule = () => {
|
|
1316
|
+
if (queued) return;
|
|
1317
|
+
queued = requestAnimationFrame(() => { queued = 0; update(); });
|
|
1318
|
+
};
|
|
1319
|
+
window.addEventListener("scroll", schedule, { passive: true });
|
|
1320
|
+
window.addEventListener("resize", schedule);
|
|
1321
|
+
window.addEventListener("hashchange", schedule);
|
|
1322
|
+
update();
|
|
1323
|
+
onDispose(this, () => {
|
|
1324
|
+
window.removeEventListener("scroll", schedule);
|
|
1325
|
+
window.removeEventListener("resize", schedule);
|
|
1326
|
+
window.removeEventListener("hashchange", schedule);
|
|
1327
|
+
if (queued) cancelAnimationFrame(queued);
|
|
1328
|
+
});
|
|
1329
|
+
// Smooth scroll on link click (F-23).
|
|
1330
|
+
if (!this._wiredTocScroll) {
|
|
1331
|
+
this._wiredTocScroll = true;
|
|
1332
|
+
this.addEventListener("click", (e) => {
|
|
1333
|
+
const a = e.target && e.target.closest ? e.target.closest(".c-toc__link") : null;
|
|
1334
|
+
if (!a || !this.contains(a)) return;
|
|
1335
|
+
const href = a.getAttribute("href") || "";
|
|
1336
|
+
if (!href.startsWith("#") || href.length < 2) return;
|
|
1337
|
+
const target = document.getElementById(href.slice(1));
|
|
1338
|
+
if (!target) return;
|
|
1339
|
+
e.preventDefault();
|
|
1340
|
+
try { target.scrollIntoView({ behavior: "smooth", block: "start" }); } catch (err) { target.scrollIntoView(); }
|
|
1341
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { href } }));
|
|
1342
|
+
});
|
|
1343
|
+
// Keyboard: roving tabindex over TOC links, Enter follows the link.
|
|
1344
|
+
this.addEventListener("keydown", (e) => {
|
|
1345
|
+
const links = Array.from(this.querySelectorAll(".c-toc__link"));
|
|
1346
|
+
if (!links.length) return;
|
|
1347
|
+
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(); } } } });
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
define("contour-toc", ContourTocFull);
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
class ContourHeader extends ContourBase {
|
|
1358
|
+
static get observed() { return ["brand", "brand-href", "links"]; }
|
|
1359
|
+
static get properties() { return { brand: { attribute: "brand" }, "brand-href": { attribute: "brand-href" }, links: { attribute: "links" } }; }
|
|
1360
|
+
render() {
|
|
1361
|
+
this.classList.add("c-header");
|
|
1362
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "banner");
|
|
1363
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("brand") || "Header");
|
|
1364
|
+
const brand = this.getAttribute("brand");
|
|
1365
|
+
const links = this.getAttribute("links");
|
|
1366
|
+
const inner = this.ensure(".c-header__inner", () => { const el = document.createElement("div"); el.className = "container c-header__inner"; return el; });
|
|
1367
|
+
inner.className = "container c-header__inner";
|
|
1368
|
+
// Brand
|
|
1369
|
+
let brandEl = inner.querySelector(".c-brand");
|
|
1370
|
+
if (brand) {
|
|
1371
|
+
if (!brandEl) {
|
|
1372
|
+
brandEl = document.createElement("a");
|
|
1373
|
+
brandEl.className = "c-brand";
|
|
1374
|
+
brandEl.setAttribute("data-contour-generated", "");
|
|
1375
|
+
brandEl.href = safeHref(this.getAttribute("brand-href") || "#");
|
|
1376
|
+
setHTML(brandEl, `<span class="c-mark"><svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-mark" /></svg></span>`);
|
|
1377
|
+
const brandName = document.createElement("span");
|
|
1378
|
+
brandName.className = "c-brand__name";
|
|
1379
|
+
brandEl.appendChild(brandName);
|
|
1380
|
+
inner.insertBefore(brandEl, inner.firstChild);
|
|
1381
|
+
}
|
|
1382
|
+
const brandName = brandEl.querySelector(".c-brand__name");
|
|
1383
|
+
if (brandName) brandName.textContent = brand;
|
|
1384
|
+
} else if (brandEl && brandEl.hasAttribute("data-contour-generated")) {
|
|
1385
|
+
brandEl.remove();
|
|
1386
|
+
}
|
|
1387
|
+
// Nav
|
|
1388
|
+
let nav = inner.querySelector(".c-header__nav");
|
|
1389
|
+
const authoredNav = nav ? Array.from(nav.children).filter((n) => n.tagName === "A") : [];
|
|
1390
|
+
if (links && !authoredNav.length) {
|
|
1391
|
+
try {
|
|
1392
|
+
const parsed = JSON.parse(links);
|
|
1393
|
+
if (!nav) {
|
|
1394
|
+
nav = document.createElement("nav");
|
|
1395
|
+
nav.className = "c-header__nav";
|
|
1396
|
+
nav.setAttribute("aria-label", labelText(this, "main", "Main"));
|
|
1397
|
+
nav.setAttribute("data-contour-generated", "");
|
|
1398
|
+
inner.appendChild(nav);
|
|
1399
|
+
}
|
|
1400
|
+
nav.innerHTML = "";
|
|
1401
|
+
parsed.forEach((l) => {
|
|
1402
|
+
const a = document.createElement("a");
|
|
1403
|
+
a.href = safeHref(l.href || "#");
|
|
1404
|
+
a.textContent = l.label || l;
|
|
1405
|
+
nav.appendChild(a);
|
|
1406
|
+
});
|
|
1407
|
+
} catch (e) { /* skip */ }
|
|
1408
|
+
} else if (links && authoredNav.length) {
|
|
1409
|
+
// authored nav wins; keep it
|
|
1410
|
+
} else if (nav && !links && !authoredNav.length && nav.hasAttribute("data-contour-generated")) {
|
|
1411
|
+
nav.remove();
|
|
1412
|
+
}
|
|
1413
|
+
// Actions container
|
|
1414
|
+
if (!inner.querySelector(".c-header__actions")) {
|
|
1415
|
+
const actions = document.createElement("div");
|
|
1416
|
+
actions.className = "c-header__actions";
|
|
1417
|
+
inner.appendChild(actions);
|
|
1418
|
+
}
|
|
1419
|
+
// Mobile toggle: below 60rem the sheet hides .c-header__nav; toggle is the way. Created only when nav exists, controls it by id, starts closed to match CSS. R31-150: i-menu (hamburger) now that the glyph is in the sprite.
|
|
1420
|
+
const navEl = inner.querySelector(".c-header__nav");
|
|
1421
|
+
if (navEl) {
|
|
1422
|
+
// A page may carry two headers; fixed id makes both toggles point at first nav in document order. Each generated nav gets its own id.
|
|
1423
|
+
if (!navEl.id) navEl.id = contourId("header-nav");
|
|
1424
|
+
const actions = inner.querySelector(".c-header__actions");
|
|
1425
|
+
if (actions && !actions.querySelector(".c-header__toggle")) {
|
|
1426
|
+
const toggle = document.createElement("button");
|
|
1427
|
+
toggle.type = "button";
|
|
1428
|
+
toggle.className = "c-header__toggle";
|
|
1429
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle-navigation", "Toggle navigation"));
|
|
1430
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
1431
|
+
toggle.setAttribute("aria-controls", navEl.id);
|
|
1432
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-menu" /></svg>');
|
|
1433
|
+
actions.appendChild(toggle);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (inner.parentNode !== this) this.appendChild(inner);
|
|
1437
|
+
}
|
|
1438
|
+
enhance() {
|
|
1439
|
+
if (this._wiredHeader) return;
|
|
1440
|
+
this._wiredHeader = true;
|
|
1441
|
+
// Scroll state: past threshold header gains c-header--scrolled so sheet can raise it.
|
|
1442
|
+
const update = () => {
|
|
1443
|
+
const y = window.scrollY || document.documentElement.scrollTop || 0;
|
|
1444
|
+
this.classList.toggle("c-header--scrolled", y > 8);
|
|
1445
|
+
};
|
|
1446
|
+
update();
|
|
1447
|
+
window.addEventListener("scroll", update, { passive: true });
|
|
1448
|
+
onDispose(this, () => window.removeEventListener("scroll", update));
|
|
1449
|
+
// Toggle: button shows/hides nav under 60rem and keeps aria-expanded in step. Close on Escape while open.
|
|
1450
|
+
this.addEventListener("click", (e) => {
|
|
1451
|
+
const toggle = e.target && e.target.closest ? e.target.closest(".c-header__toggle") : null;
|
|
1452
|
+
if (!toggle || !this.contains(toggle)) return;
|
|
1453
|
+
const nav = this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
1454
|
+
if (!nav) return;
|
|
1455
|
+
const open = nav.classList.toggle("is-open");
|
|
1456
|
+
toggle.setAttribute("aria-expanded", String(open));
|
|
1457
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { open } }));
|
|
1458
|
+
});
|
|
1459
|
+
this.addEventListener("keydown", (e) => {
|
|
1460
|
+
if (e.key !== "Escape") return;
|
|
1461
|
+
const toggle = this.querySelector(".c-header__toggle");
|
|
1462
|
+
const nav = toggle && this.querySelector("#" + CSS.escape(toggle.getAttribute("aria-controls") || ""));
|
|
1463
|
+
if (!toggle || !nav || !nav.classList.contains("is-open")) return;
|
|
1464
|
+
nav.classList.remove("is-open");
|
|
1465
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
define("contour-header", ContourHeader);
|
|
1470
|
+
class ContourFooter extends ContourBase {
|
|
1471
|
+
static get observed() { return ["brand", "note", "links", "cols", "heading"]; }
|
|
1472
|
+
static get properties() { return { brand: { attribute: "brand" }, note: { attribute: "note" }, links: { attribute: "links" }, cols: { attribute: "cols" } }; }
|
|
1473
|
+
render() {
|
|
1474
|
+
this.classList.add("c-footer");
|
|
1475
|
+
// A footer is a contentinfo landmark: the APG names it, and a reader who
|
|
1476
|
+
// jumps to the landmark list expects the page's footer there.
|
|
1477
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "contentinfo");
|
|
1478
|
+
const brand = this.getAttribute("brand");
|
|
1479
|
+
if (brand) {
|
|
1480
|
+
const b = this.ensure(".c-footer__brand", () => { const el = document.createElement("div"); el.className = "c-footer__brand"; return el; });
|
|
1481
|
+
b.textContent = brand;
|
|
1482
|
+
} else {
|
|
1483
|
+
const b = this.querySelector(".c-footer__brand");
|
|
1484
|
+
if (b) b.remove();
|
|
1485
|
+
}
|
|
1486
|
+
const note = this.getAttribute("note");
|
|
1487
|
+
if (note) {
|
|
1488
|
+
const n = this.ensure(".c-footer__note", () => { const el = document.createElement("p"); el.className = "c-footer__note"; return el; });
|
|
1489
|
+
n.textContent = note;
|
|
1490
|
+
} else {
|
|
1491
|
+
const n = this.querySelector(".c-footer__note");
|
|
1492
|
+
if (n) n.remove();
|
|
1493
|
+
}
|
|
1494
|
+
const links = this.getAttribute("links");
|
|
1495
|
+
if (links) {
|
|
1496
|
+
try {
|
|
1497
|
+
const parsed = JSON.parse(links);
|
|
1498
|
+
const wrap = this.ensure(".c-footer__links", () => { const el = document.createElement("div"); el.className = "c-footer__links"; return el; });
|
|
1499
|
+
wrap.innerHTML = "";
|
|
1500
|
+
parsed.forEach((l) => {
|
|
1501
|
+
const a = document.createElement("a");
|
|
1502
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1503
|
+
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1504
|
+
wrap.appendChild(a);
|
|
1505
|
+
});
|
|
1506
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1507
|
+
} else {
|
|
1508
|
+
const w = this.querySelector(".c-footer__links");
|
|
1509
|
+
if (w) w.remove();
|
|
1510
|
+
}
|
|
1511
|
+
const cols = this.getAttribute("cols");
|
|
1512
|
+
if (cols) {
|
|
1513
|
+
try {
|
|
1514
|
+
const parsed = JSON.parse(cols);
|
|
1515
|
+
// Remove previous cols
|
|
1516
|
+
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
1517
|
+
parsed.forEach((col) => {
|
|
1518
|
+
const c = document.createElement("div");
|
|
1519
|
+
c.className = "c-footer__col";
|
|
1520
|
+
if (col.title) {
|
|
1521
|
+
const h = document.createElement(headingTag(this, "h3"));
|
|
1522
|
+
h.textContent = col.title;
|
|
1523
|
+
c.appendChild(h);
|
|
1524
|
+
}
|
|
1525
|
+
(col.links || []).forEach((l) => {
|
|
1526
|
+
const a = document.createElement("a");
|
|
1527
|
+
a.href = safeHref(typeof l === "string" ? "#" : (l.href || "#"));
|
|
1528
|
+
a.textContent = typeof l === "string" ? l : (l.label || l);
|
|
1529
|
+
c.appendChild(a);
|
|
1530
|
+
});
|
|
1531
|
+
this.appendChild(c);
|
|
1532
|
+
});
|
|
1533
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1534
|
+
} else {
|
|
1535
|
+
this.querySelectorAll(".c-footer__col").forEach((c) => c.remove());
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
define("contour-footer", ContourFooter);
|
|
1540
|
+
class ContourSchemeToggle extends ContourBase {
|
|
1541
|
+
static get observed() { return []; }
|
|
1542
|
+
// One persistence contract with ds.js; meta element is source of truth.
|
|
1543
|
+
_stored() {
|
|
1544
|
+
try { return localStorage.getItem("contour-scheme") ?? "light dark"; } catch (e) { return "light dark"; }
|
|
1545
|
+
}
|
|
1546
|
+
_resolved() {
|
|
1547
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1548
|
+
}
|
|
1549
|
+
_rendered() {
|
|
1550
|
+
const stored = this._stored();
|
|
1551
|
+
return stored === "light dark" ? this._resolved() : stored;
|
|
1552
|
+
}
|
|
1553
|
+
render() {
|
|
1554
|
+
this.classList.add("c-scheme-toggle");
|
|
1555
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "button");
|
|
1556
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1557
|
+
// The text glyph is the standalone fallback; when the author slots the
|
|
1558
|
+
// svg pair (__icons) the CSS shows the active svg and no glyph is added.
|
|
1559
|
+
if (!this.querySelector(".c-scheme-toggle__icons") && !this.querySelector(".c-scheme-toggle__glyph")) {
|
|
1560
|
+
const glyph = document.createElement("span");
|
|
1561
|
+
glyph.className = "c-scheme-toggle__glyph";
|
|
1562
|
+
glyph.setAttribute("aria-hidden", "true");
|
|
1563
|
+
this.appendChild(glyph);
|
|
1564
|
+
}
|
|
1565
|
+
this._sync();
|
|
1566
|
+
}
|
|
1567
|
+
_sync() {
|
|
1568
|
+
const rendered = this._rendered();
|
|
1569
|
+
const target = rendered === "dark" ? "light" : "dark";
|
|
1570
|
+
this.setAttribute("aria-pressed", String(rendered === "dark"));
|
|
1571
|
+
this.setAttribute("aria-label", target === "dark" ? "Switch to dark theme" : "Switch to light theme");
|
|
1572
|
+
const glyph = this.querySelector(".c-scheme-toggle__glyph");
|
|
1573
|
+
// Target-action convention: the glyph is what a click switches TO, matching
|
|
1574
|
+
// the svg pair (moon in light mode, sun in dark mode) and the aria-label.
|
|
1575
|
+
if (glyph) glyph.textContent = rendered === "dark" ? "☀" : "☾";
|
|
1576
|
+
}
|
|
1577
|
+
_apply(value) {
|
|
1578
|
+
const root = document.documentElement;
|
|
1579
|
+
const rendered = value === "light dark" ? this._resolved() : value;
|
|
1580
|
+
root.classList.add("is-theme-switching");
|
|
1581
|
+
const meta = document.querySelector('meta[name="color-scheme"]');
|
|
1582
|
+
if (meta) meta.setAttribute("content", value);
|
|
1583
|
+
// data-theme stays published as a consumer hook, resolved to a concrete
|
|
1584
|
+
// scheme; the cascade itself reads the meta element, not this attribute.
|
|
1585
|
+
root.setAttribute("data-theme", rendered);
|
|
1586
|
+
try {
|
|
1587
|
+
if (value === "light dark") localStorage.removeItem("contour-scheme");
|
|
1588
|
+
else localStorage.setItem("contour-scheme", value);
|
|
1589
|
+
} catch (e) {}
|
|
1590
|
+
requestAnimationFrame(() => requestAnimationFrame(() => root.classList.remove("is-theme-switching")));
|
|
1591
|
+
this._sync();
|
|
1592
|
+
this.dispatchEvent(new CustomEvent("contour:theme-change", { detail: { theme: rendered }, bubbles: true, composed: true }));
|
|
1593
|
+
}
|
|
1594
|
+
enhance() {
|
|
1595
|
+
if (this._wiredScheme) return;
|
|
1596
|
+
this._wiredScheme = true;
|
|
1597
|
+
this.addEventListener("click", () => {
|
|
1598
|
+
const target = this._rendered() === "dark" ? "light" : "dark";
|
|
1599
|
+
this._apply(target === this._resolved() ? "light dark" : target);
|
|
1600
|
+
});
|
|
1601
|
+
this.addEventListener("keydown", (e) => {
|
|
1602
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1603
|
+
e.preventDefault();
|
|
1604
|
+
this.click();
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1608
|
+
const onSystemChange = () => {
|
|
1609
|
+
if (this._stored() === "light dark") {
|
|
1610
|
+
document.documentElement.setAttribute("data-theme", this._resolved());
|
|
1611
|
+
this._sync();
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
if (mq.addEventListener) mq.addEventListener("change", onSystemChange);
|
|
1615
|
+
// Migrate the pre-R25 `contour-theme` key once, then restore the stored
|
|
1616
|
+
// override so a standalone consumer page (no ds.js) lands on its theme.
|
|
1617
|
+
try {
|
|
1618
|
+
const legacy = localStorage.getItem("contour-theme");
|
|
1619
|
+
if (legacy) {
|
|
1620
|
+
if (!localStorage.getItem("contour-scheme") && (legacy === "dark" || legacy === "light")) localStorage.setItem("contour-scheme", legacy);
|
|
1621
|
+
localStorage.removeItem("contour-theme");
|
|
1622
|
+
}
|
|
1623
|
+
} catch (e) {}
|
|
1624
|
+
const stored = this._stored();
|
|
1625
|
+
if (stored !== "light dark") this._apply(stored);
|
|
1626
|
+
else this._sync();
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
define("contour-scheme-toggle", ContourSchemeToggle);
|
|
1630
|
+
class ContourSidebar extends ContourBase {
|
|
1631
|
+
static get observed() { return ["title", "items", "collapsed"]; }
|
|
1632
|
+
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
1633
|
+
render() {
|
|
1634
|
+
this.classList.add("c-sidebar");
|
|
1635
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "navigation");
|
|
1636
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Sidebar");
|
|
1637
|
+
// R24-74: collapsed state as a data-attribute, not a --modifier class, so
|
|
1638
|
+
// the layout ratchet (check-layout) does not read it as a new primitive.
|
|
1639
|
+
if (this.hasAttribute("collapsed")) this.setAttribute("data-collapsed", ""); else this.removeAttribute("data-collapsed");
|
|
1640
|
+
const title = this.getAttribute("title");
|
|
1641
|
+
if (title) {
|
|
1642
|
+
const t = this.ensure(".c-sidebar__title", () => { const el = document.createElement("div"); el.className = "c-sidebar__title"; return el; });
|
|
1643
|
+
t.textContent = title;
|
|
1644
|
+
} else {
|
|
1645
|
+
const t = this.querySelector(".c-sidebar__title");
|
|
1646
|
+
if (t) t.remove();
|
|
1647
|
+
}
|
|
1648
|
+
// R24-74: collapse toggle — a real control that narrows the sidebar.
|
|
1649
|
+
const collapsed = this.hasAttribute("collapsed");
|
|
1650
|
+
const t = this.ensure(".c-sidebar__toggle", () => {
|
|
1651
|
+
const el = document.createElement("button");
|
|
1652
|
+
el.className = "c-sidebar__toggle";
|
|
1653
|
+
el.type = "button";
|
|
1654
|
+
return el;
|
|
1655
|
+
});
|
|
1656
|
+
t.setAttribute("aria-label", collapsed ? "Expand sidebar" : "Collapse sidebar");
|
|
1657
|
+
t.setAttribute("aria-pressed", String(collapsed));
|
|
1658
|
+
setHTML(t, collapsed
|
|
1659
|
+
? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>'
|
|
1660
|
+
: '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-down" /></svg>');
|
|
1661
|
+
const items = this.getAttribute("items");
|
|
1662
|
+
if (items) {
|
|
1663
|
+
try {
|
|
1664
|
+
const parsed = JSON.parse(items);
|
|
1665
|
+
const nav = this.ensure("nav.c-sidebar__nav", () => { const el = document.createElement("nav"); el.className = "c-sidebar__nav"; return el; });
|
|
1666
|
+
nav.innerHTML = "";
|
|
1667
|
+
parsed.forEach((it, i) => {
|
|
1668
|
+
const a = document.createElement("a");
|
|
1669
|
+
a.className = "c-sidebar__link";
|
|
1670
|
+
a.href = safeHref((it && it.href) || "#");
|
|
1671
|
+
a.textContent = (it && (it.label || it)) || "";
|
|
1672
|
+
a.tabIndex = i === 0 ? 0 : -1;
|
|
1673
|
+
nav.appendChild(a);
|
|
1674
|
+
});
|
|
1675
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
enhance() {
|
|
1679
|
+
if (this._wiredSidebar) return;
|
|
1680
|
+
this._wiredSidebar = true;
|
|
1681
|
+
this.addEventListener("click", (e) => {
|
|
1682
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
|
|
1683
|
+
if (!btn || !this.contains(btn)) return;
|
|
1684
|
+
this.toggleAttribute("collapsed");
|
|
1685
|
+
this.dispatchEvent(new CustomEvent("contour:toggle", { bubbles: true, composed: true, detail: { collapsed: this.hasAttribute("collapsed") } }));
|
|
1686
|
+
});
|
|
1687
|
+
// Keyboard: roving tabindex over sidebar links, Enter follows the link.
|
|
1688
|
+
this.addEventListener("keydown", (e) => {
|
|
1689
|
+
const nav = this.querySelector("nav.c-sidebar__nav");
|
|
1690
|
+
if (!nav) return;
|
|
1691
|
+
const links = Array.from(nav.querySelectorAll(".c-sidebar__link"));
|
|
1692
|
+
if (!links.length) return;
|
|
1693
|
+
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(); } } } });
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
define("contour-sidebar", ContourSidebar);
|
|
1698
|
+
class ContourToolbar extends ContourBase {
|
|
1699
|
+
static get observed() { return ["title", "actions", "overflow"]; }
|
|
1700
|
+
static get properties() { return { title: { attribute: "title" }, actions: { attribute: "actions" }, overflow: { attribute: "overflow", type: Number } }; }
|
|
1701
|
+
render() {
|
|
1702
|
+
this.classList.add("c-toolbar");
|
|
1703
|
+
const title = this.getAttribute("title");
|
|
1704
|
+
this.setAttribute("role", "toolbar");
|
|
1705
|
+
if (title) this.setAttribute("aria-label", title);
|
|
1706
|
+
const actions = this.getAttribute("actions");
|
|
1707
|
+
if (actions) {
|
|
1708
|
+
try {
|
|
1709
|
+
const parsed = JSON.parse(actions);
|
|
1710
|
+
const limit = this.overflow && this.overflow > 0 ? this.overflow : parsed.length;
|
|
1711
|
+
const visible = parsed.slice(0, limit);
|
|
1712
|
+
const excess = parsed.slice(limit);
|
|
1713
|
+
visible.forEach((a, i) => {
|
|
1714
|
+
const btn = document.createElement("button");
|
|
1715
|
+
btn.className = "c-toolbar__btn";
|
|
1716
|
+
btn.type = "button";
|
|
1717
|
+
btn.tabIndex = i === 0 ? 0 : -1;
|
|
1718
|
+
btn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
1719
|
+
// R24-41: text actions size to content; icon-only keep the fixed square.
|
|
1720
|
+
if (typeof a === "string" || (a && a.label)) btn.classList.add("c-toolbar__btn--text");
|
|
1721
|
+
this.appendChild(btn);
|
|
1722
|
+
});
|
|
1723
|
+
if (excess.length) {
|
|
1724
|
+
const wrap = document.createElement("div");
|
|
1725
|
+
wrap.className = "c-toolbar__overflow";
|
|
1726
|
+
const btn = document.createElement("button");
|
|
1727
|
+
btn.className = "c-toolbar__btn c-toolbar__overflow-btn";
|
|
1728
|
+
btn.type = "button";
|
|
1729
|
+
btn.tabIndex = -1;
|
|
1730
|
+
btn.setAttribute("aria-haspopup", "menu");
|
|
1731
|
+
btn.setAttribute("aria-expanded", "false");
|
|
1732
|
+
btn.textContent = "…";
|
|
1733
|
+
btn.setAttribute("aria-label", labelText(this, "more-options", "More options"));
|
|
1734
|
+
wrap.appendChild(btn);
|
|
1735
|
+
const menu = document.createElement("div");
|
|
1736
|
+
menu.className = "c-toolbar__overflow-menu";
|
|
1737
|
+
menu.setAttribute("role", "menu");
|
|
1738
|
+
menu.setAttribute("hidden", "");
|
|
1739
|
+
excess.forEach((a) => {
|
|
1740
|
+
const mbtn = document.createElement("button");
|
|
1741
|
+
mbtn.className = "c-toolbar__btn";
|
|
1742
|
+
mbtn.type = "button";
|
|
1743
|
+
mbtn.setAttribute("role", "menuitem");
|
|
1744
|
+
mbtn.textContent = typeof a === "string" ? a : (a.label || a);
|
|
1745
|
+
menu.appendChild(mbtn);
|
|
1746
|
+
});
|
|
1747
|
+
wrap.appendChild(menu);
|
|
1748
|
+
this.appendChild(wrap);
|
|
1749
|
+
}
|
|
1750
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
enhance() {
|
|
1754
|
+
if (this._wiredToolbar) return;
|
|
1755
|
+
this._wiredToolbar = true;
|
|
1756
|
+
this.addEventListener("click", (e) => {
|
|
1757
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-toolbar__overflow-btn") : null;
|
|
1758
|
+
if (btn && this.contains(btn)) {
|
|
1759
|
+
const menu = btn.parentElement && btn.parentElement.querySelector(".c-toolbar__overflow-menu");
|
|
1760
|
+
if (menu) {
|
|
1761
|
+
const open = menu.hasAttribute("hidden");
|
|
1762
|
+
if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
|
|
1763
|
+
btn.setAttribute("aria-expanded", String(open));
|
|
1764
|
+
// R24-41: one tab stop in the overflow menu (first item), none on the
|
|
1765
|
+
// overflow button while the menu is open.
|
|
1766
|
+
btn.tabIndex = open ? -1 : 0;
|
|
1767
|
+
const items = Array.from(menu.querySelectorAll("[role='menuitem']"));
|
|
1768
|
+
items.forEach((it, j) => it.tabIndex = open ? (j === 0 ? 0 : -1) : -1);
|
|
1769
|
+
if (open) { try { items[0]?.focus(); } catch (err) {} }
|
|
1770
|
+
}
|
|
1771
|
+
return;
|
|
1772
|
+
}
|
|
1773
|
+
const actionBtn = e.target && e.target.closest ? e.target.closest(".c-toolbar__btn") : null;
|
|
1774
|
+
if (actionBtn && this.contains(actionBtn)) {
|
|
1775
|
+
this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { label: actionBtn.textContent.trim() } }));
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
// Roving tabindex over visible toolbar buttons; overflow menu is roving too.
|
|
1779
|
+
this.addEventListener("keydown", (e) => {
|
|
1780
|
+
// R24-41: Escape closes the overflow menu.
|
|
1781
|
+
if (e.key === "Escape") {
|
|
1782
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
1783
|
+
if (openMenu) {
|
|
1784
|
+
openMenu.setAttribute("hidden", "");
|
|
1785
|
+
const btn = this.querySelector(".c-toolbar__overflow-btn");
|
|
1786
|
+
if (btn) { btn.setAttribute("aria-expanded", "false"); btn.tabIndex = 0; btn.focus(); }
|
|
1787
|
+
e.preventDefault();
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
1792
|
+
if (openMenu) {
|
|
1793
|
+
const items = Array.from(openMenu.querySelectorAll("[role='menuitem']"));
|
|
1794
|
+
if (items.length) {
|
|
1795
|
+
navKey(e, items, {
|
|
1796
|
+
wrap: true,
|
|
1797
|
+
homeEnd: true,
|
|
1798
|
+
onNavigate: (i) => { items.forEach((it, j) => it.tabIndex = j === i ? 0 : -1); },
|
|
1799
|
+
onKey: (k) => { if (k === "Enter" || k === " ") { const b = document.activeElement; if (b) { e.preventDefault(); b.click(); } } }
|
|
1800
|
+
});
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
const btns = Array.from(this.querySelectorAll(":scope > .c-toolbar__btn"));
|
|
1805
|
+
if (!btns.length) return;
|
|
1806
|
+
navKey(e, btns, {
|
|
1807
|
+
wrap: true,
|
|
1808
|
+
homeEnd: true,
|
|
1809
|
+
onNavigate: (i) => { btns.forEach((b, j) => b.tabIndex = j === i ? 0 : -1); },
|
|
1810
|
+
onKey: (k) => {
|
|
1811
|
+
if (k === "Enter" || k === " ") {
|
|
1812
|
+
const b = document.activeElement;
|
|
1813
|
+
if (b) {
|
|
1814
|
+
e.preventDefault();
|
|
1815
|
+
if (b.classList.contains("c-toolbar__overflow-btn")) {
|
|
1816
|
+
const menu = b.parentElement && b.parentElement.querySelector(".c-toolbar__overflow-menu");
|
|
1817
|
+
if (menu) {
|
|
1818
|
+
const open = menu.hasAttribute("hidden");
|
|
1819
|
+
if (open) menu.removeAttribute("hidden"); else menu.setAttribute("hidden", "");
|
|
1820
|
+
b.setAttribute("aria-expanded", String(open));
|
|
1821
|
+
b.tabIndex = open ? -1 : 0;
|
|
1822
|
+
const items = Array.from(menu.querySelectorAll("[role='menuitem']"));
|
|
1823
|
+
items.forEach((it, j) => it.tabIndex = open ? (j === 0 ? 0 : -1) : -1);
|
|
1824
|
+
if (open) { try { items[0]?.focus(); } catch (err) {} }
|
|
1825
|
+
}
|
|
1826
|
+
} else {
|
|
1827
|
+
b.click();
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
});
|
|
1834
|
+
// R24-41: outside-click closes the overflow menu.
|
|
1835
|
+
this.addEventListener("focusout", (e) => {
|
|
1836
|
+
if (!this.contains(e.relatedTarget)) {
|
|
1837
|
+
const openMenu = this.querySelector(".c-toolbar__overflow-menu:not([hidden])");
|
|
1838
|
+
if (openMenu) {
|
|
1839
|
+
openMenu.setAttribute("hidden", "");
|
|
1840
|
+
const btn = this.querySelector(".c-toolbar__overflow-btn");
|
|
1841
|
+
if (btn) btn.setAttribute("aria-expanded", "false");
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
define("contour-toolbar", ContourToolbar);
|
|
1848
|
+
|
|
1849
|
+
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
class ContourTree extends ContourBase {
|
|
1853
|
+
static get updateMode() { return "keyed"; }
|
|
1854
|
+
static get observed() { return ["items", "virtual", "item-height", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "selectable", "cache-key", "no-cache", "density"]; }
|
|
1855
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
|
|
1856
|
+
_itemHeight() {
|
|
1857
|
+
const h = Number(this.getAttribute("item-height"));
|
|
1858
|
+
if (Number.isFinite(h) && h > 0) return h;
|
|
1859
|
+
return cssLength("--virtual-list-item-height", 28);
|
|
1860
|
+
}
|
|
1861
|
+
_labelToPaths(nodes, pathPrefix, map) {
|
|
1862
|
+
(nodes || []).forEach((node, i) => {
|
|
1863
|
+
const p = pathPrefix + "." + i;
|
|
1864
|
+
const label = String(node.label || node).trim().slice(0, 120);
|
|
1865
|
+
if (!map.has(label)) map.set(label, []);
|
|
1866
|
+
map.get(label).push(p);
|
|
1867
|
+
if (Array.isArray(node.children)) this._labelToPaths(node.children, p, map);
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
_restoreExpanded() {
|
|
1871
|
+
const persist = this.getAttribute("persist");
|
|
1872
|
+
if (!persist || !this._treeData) return;
|
|
1873
|
+
let labels = null;
|
|
1874
|
+
try {
|
|
1875
|
+
if (persist === "storage" && this.id) {
|
|
1876
|
+
const saved = localStorage.getItem("contour-tree:" + this.id);
|
|
1877
|
+
if (saved !== null) labels = JSON.parse(saved);
|
|
1878
|
+
} else if (persist === "url") {
|
|
1879
|
+
const v = new URLSearchParams(window.location.search).get("c-tree");
|
|
1880
|
+
if (v !== null) labels = JSON.parse(v);
|
|
1881
|
+
}
|
|
1882
|
+
} catch (e) { labels = null; }
|
|
1883
|
+
if (!Array.isArray(labels)) return;
|
|
1884
|
+
const want = new Set(labels.map((l) => String(l)));
|
|
1885
|
+
const map = new Map();
|
|
1886
|
+
this._labelToPaths(this._treeData, "", map);
|
|
1887
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
1888
|
+
for (const lbl of want) {
|
|
1889
|
+
const paths = map.get(lbl);
|
|
1890
|
+
if (paths) paths.forEach((p) => expanded.add(p));
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
_persistExpanded() {
|
|
1894
|
+
const persist = this.getAttribute("persist");
|
|
1895
|
+
if (!persist || !this._expanded) return;
|
|
1896
|
+
// Map expanded paths back to labels.
|
|
1897
|
+
const pathToNode = new Map();
|
|
1898
|
+
const walk = (nodes, pathPrefix) => {
|
|
1899
|
+
(nodes || []).forEach((node, i) => {
|
|
1900
|
+
const p = pathPrefix + "." + i;
|
|
1901
|
+
pathToNode.set(p, node);
|
|
1902
|
+
if (Array.isArray(node.children)) walk(node.children, p);
|
|
1903
|
+
});
|
|
1904
|
+
};
|
|
1905
|
+
walk(this._treeData, "");
|
|
1906
|
+
const open = [];
|
|
1907
|
+
for (const p of this._expanded) {
|
|
1908
|
+
const node = pathToNode.get(p);
|
|
1909
|
+
if (node) open.push(String(node.label || node).trim().slice(0, 120));
|
|
1910
|
+
}
|
|
1911
|
+
try {
|
|
1912
|
+
if (persist === "storage" && this.id) {
|
|
1913
|
+
localStorage.setItem("contour-tree:" + this.id, JSON.stringify(open));
|
|
1914
|
+
} else if (persist === "url") {
|
|
1915
|
+
const url = new URL(window.location.href);
|
|
1916
|
+
url.searchParams.set("c-tree", JSON.stringify(open));
|
|
1917
|
+
window.history.replaceState(null, "", url.toString());
|
|
1918
|
+
}
|
|
1919
|
+
} catch (e) {}
|
|
1920
|
+
}
|
|
1921
|
+
_flatten(nodes, pathPrefix, depth, expanded, out) {
|
|
1922
|
+
(nodes || []).forEach((node, i) => {
|
|
1923
|
+
const p = pathPrefix + "." + i;
|
|
1924
|
+
const hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
1925
|
+
const isExpanded = expanded.has(p);
|
|
1926
|
+
out.push({ node, path: p, depth, hasChildren, expanded: isExpanded });
|
|
1927
|
+
if (hasChildren && isExpanded) {
|
|
1928
|
+
this._flatten(node.children, p, depth + 1, expanded, out);
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
_renderNodeFlat(rootUl, f, setsize, posinset) {
|
|
1933
|
+
const node = f.node;
|
|
1934
|
+
const depth = f.depth;
|
|
1935
|
+
const li = document.createElement("div");
|
|
1936
|
+
li.className = "c-tree__node";
|
|
1937
|
+
li.setAttribute("role", "treeitem");
|
|
1938
|
+
li.setAttribute("aria-level", String(depth));
|
|
1939
|
+
li.setAttribute("aria-setsize", String(setsize));
|
|
1940
|
+
li.setAttribute("aria-posinset", String(posinset));
|
|
1941
|
+
li.dataset.path = f.path;
|
|
1942
|
+
if (f.hasChildren) {
|
|
1943
|
+
li.setAttribute("aria-expanded", String(f.expanded));
|
|
1944
|
+
const row = document.createElement("div");
|
|
1945
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
1946
|
+
// Density-aware indent matching plain tree's indent token, not hardcoded rem ignoring scoped density.
|
|
1947
|
+
row.style.paddingInlineStart = `calc(${depth - 1} * 1rem * var(--density, 1))`;
|
|
1948
|
+
const toggle = document.createElement("button");
|
|
1949
|
+
toggle.className = "c-tree__toggle";
|
|
1950
|
+
toggle.setAttribute("type", "button");
|
|
1951
|
+
toggle.setAttribute("aria-expanded", String(f.expanded));
|
|
1952
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle"));
|
|
1953
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
1954
|
+
row.appendChild(toggle);
|
|
1955
|
+
const span = document.createElement("span");
|
|
1956
|
+
span.textContent = node.label;
|
|
1957
|
+
row.appendChild(span);
|
|
1958
|
+
li.appendChild(row);
|
|
1959
|
+
} else {
|
|
1960
|
+
const leaf = document.createElement("div");
|
|
1961
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
1962
|
+
leaf.style.paddingInlineStart = `calc(${depth} * 1rem * var(--density, 1))`;
|
|
1963
|
+
if (this.hasAttribute("selectable")) {
|
|
1964
|
+
const cb = document.createElement("input");
|
|
1965
|
+
cb.type = "checkbox";
|
|
1966
|
+
cb.className = "c-tree__select";
|
|
1967
|
+
cb.setAttribute("aria-label", labelText(this, "select", "Select") + " " + (node.label || node));
|
|
1968
|
+
// Key selection by path, not label, so duplicate labels (e.g. two "Dups") don't collide.
|
|
1969
|
+
if (this._selectedTree && this._selectedTree.has(f.path)) cb.checked = true;
|
|
1970
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
1971
|
+
}
|
|
1972
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
1973
|
+
li.appendChild(leaf);
|
|
1974
|
+
}
|
|
1975
|
+
return li;
|
|
1976
|
+
}
|
|
1977
|
+
_renderWindow(rootUl, scrollTop) {
|
|
1978
|
+
if (!this._treeData) return;
|
|
1979
|
+
const ih = this._itemHeight();
|
|
1980
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
1981
|
+
const flat = [];
|
|
1982
|
+
this._flatten(this._treeData, "", 1, expanded, flat);
|
|
1983
|
+
const total = flat.length;
|
|
1984
|
+
const viewportSize = rootUl.clientHeight || 320;
|
|
1985
|
+
const visibleCount = Math.ceil(viewportSize / ih) + 6;
|
|
1986
|
+
let start = Math.floor((scrollTop || 0) / ih);
|
|
1987
|
+
if (start < 0) start = 0;
|
|
1988
|
+
if (start > Math.max(0, total - visibleCount)) start = Math.max(0, total - visibleCount);
|
|
1989
|
+
const end = Math.min(total, start + visibleCount);
|
|
1990
|
+
const topSize = start * ih;
|
|
1991
|
+
const bottomSize = Math.max(0, (total - end) * ih);
|
|
1992
|
+
setHTML(rootUl, "");
|
|
1993
|
+
const top = document.createElement("div");
|
|
1994
|
+
top.className = "c-tree__spacer c-tree__spacer--top";
|
|
1995
|
+
top.style.height = topSize + "px";
|
|
1996
|
+
rootUl.appendChild(top);
|
|
1997
|
+
// Sibling sets for aria-setsize/aria-posinset (group by parent path).
|
|
1998
|
+
const byParent = new Map();
|
|
1999
|
+
flat.forEach((f, k) => {
|
|
2000
|
+
const pp = f.path.includes(".") ? f.path.slice(0, f.path.lastIndexOf(".")) : "";
|
|
2001
|
+
let s = byParent.get(pp);
|
|
2002
|
+
if (!s) { s = []; byParent.set(pp, s); }
|
|
2003
|
+
s.push(k);
|
|
2004
|
+
});
|
|
2005
|
+
for (let i = start; i < end; i++) {
|
|
2006
|
+
const f = flat[i];
|
|
2007
|
+
const pp = f.path.includes(".") ? f.path.slice(0, f.path.lastIndexOf(".")) : "";
|
|
2008
|
+
const sibs = byParent.get(pp);
|
|
2009
|
+
rootUl.appendChild(this._renderNodeFlat(rootUl, f, sibs.length, sibs.indexOf(i) + 1));
|
|
2010
|
+
}
|
|
2011
|
+
const bottom = document.createElement("div");
|
|
2012
|
+
bottom.className = "c-tree__spacer c-tree__spacer--bottom";
|
|
2013
|
+
bottom.style.height = bottomSize + "px";
|
|
2014
|
+
rootUl.appendChild(bottom);
|
|
2015
|
+
}
|
|
2016
|
+
render() {
|
|
2017
|
+
this.classList.add("c-tree");
|
|
2018
|
+
// Slot composition wins over JSON attribute (same as ContourMenu): authored tree preserved across re-renders instead of rebuilt from items.
|
|
2019
|
+
const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-tree"));
|
|
2020
|
+
wireStates(this);
|
|
2021
|
+
loadRemote(this, "items");
|
|
2022
|
+
if (renderStates(this, "tree")) return;
|
|
2023
|
+
const items = remoteData(this, "items");
|
|
2024
|
+
if (items && !authored.length) {
|
|
2025
|
+
try {
|
|
2026
|
+
const parsed = JSON.parse(items);
|
|
2027
|
+
const rootUl = this.ensure("div.c-tree", () => { const el = document.createElement("div"); el.className = "c-tree"; el.setAttribute("role", "tree"); return el; });
|
|
2028
|
+
setHTML(rootUl, "");
|
|
2029
|
+
rootUl.className = "c-tree";
|
|
2030
|
+
rootUl.setAttribute("role", "tree");
|
|
2031
|
+
const virtual = this.hasAttribute("virtual");
|
|
2032
|
+
if (virtual) {
|
|
2033
|
+
this._treeData = parsed;
|
|
2034
|
+
this._expanded = this._expanded || new Set();
|
|
2035
|
+
this._treeRoot = rootUl;
|
|
2036
|
+
this._restoreExpanded();
|
|
2037
|
+
rootUl.style.maxHeight = rootUl.style.maxHeight || "24rem";
|
|
2038
|
+
rootUl.style.overflow = "auto";
|
|
2039
|
+
const scrollTop = this._treeScrollTop || 0;
|
|
2040
|
+
this._renderWindow(rootUl, scrollTop);
|
|
2041
|
+
try { rootUl.scrollTop = scrollTop; } catch (e) {}
|
|
2042
|
+
} else {
|
|
2043
|
+
this._treeData = null;
|
|
2044
|
+
const render = (nodes, parent, depth, pathPrefix) => {
|
|
2045
|
+
const ul = parent ? document.createElement("div") : rootUl;
|
|
2046
|
+
if (parent) {
|
|
2047
|
+
ul.className = "c-tree__children";
|
|
2048
|
+
ul.setAttribute("role", "group");
|
|
2049
|
+
if (supportsUntilFound()) ul.setAttribute("hidden", "until-found"); else ul.setAttribute("hidden", "");
|
|
2050
|
+
}
|
|
2051
|
+
nodes.forEach((node, i) => {
|
|
2052
|
+
const p = (pathPrefix || "") + "." + i;
|
|
2053
|
+
const li = document.createElement("div");
|
|
2054
|
+
li.className = "c-tree__node";
|
|
2055
|
+
li.setAttribute("role", "treeitem");
|
|
2056
|
+
li.setAttribute("aria-level", String(depth));
|
|
2057
|
+
li.setAttribute("aria-setsize", String(nodes.length));
|
|
2058
|
+
li.setAttribute("aria-posinset", String(i + 1));
|
|
2059
|
+
li.dataset.path = p;
|
|
2060
|
+
if (node.children) {
|
|
2061
|
+
li.setAttribute("aria-expanded", "false");
|
|
2062
|
+
const row = document.createElement("div");
|
|
2063
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
2064
|
+
if (node.indent) {
|
|
2065
|
+
const ind = document.createElement("span");
|
|
2066
|
+
ind.className = "c-tree__indent";
|
|
2067
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
2068
|
+
row.appendChild(ind);
|
|
2069
|
+
}
|
|
2070
|
+
const toggle = document.createElement("button");
|
|
2071
|
+
toggle.className = "c-tree__toggle";
|
|
2072
|
+
toggle.setAttribute("type", "button");
|
|
2073
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
2074
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle"));
|
|
2075
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
2076
|
+
row.appendChild(toggle);
|
|
2077
|
+
const span = document.createElement("span");
|
|
2078
|
+
span.textContent = node.label;
|
|
2079
|
+
row.appendChild(span);
|
|
2080
|
+
li.appendChild(row);
|
|
2081
|
+
render(node.children, li, depth + 1, p);
|
|
2082
|
+
} else {
|
|
2083
|
+
const leaf = document.createElement("div");
|
|
2084
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
2085
|
+
if (node.indent) {
|
|
2086
|
+
const ind = document.createElement("span");
|
|
2087
|
+
ind.className = "c-tree__indent";
|
|
2088
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
2089
|
+
leaf.appendChild(ind);
|
|
2090
|
+
}
|
|
2091
|
+
if (this.hasAttribute("selectable")) {
|
|
2092
|
+
const cb = document.createElement("input");
|
|
2093
|
+
cb.type = "checkbox";
|
|
2094
|
+
cb.className = "c-tree__select";
|
|
2095
|
+
cb.setAttribute("aria-label", labelText(this, "select", "Select") + " " + (node.label || node));
|
|
2096
|
+
if (this._selectedTree && this._selectedTree.has(p)) cb.checked = true;
|
|
2097
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
2098
|
+
}
|
|
2099
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
2100
|
+
li.appendChild(leaf);
|
|
2101
|
+
}
|
|
2102
|
+
ul.appendChild(li);
|
|
2103
|
+
});
|
|
2104
|
+
if (parent) parent.appendChild(ul);
|
|
2105
|
+
};
|
|
2106
|
+
render(parsed, null, 1, "");
|
|
2107
|
+
}
|
|
2108
|
+
this.classList.remove("c-tree");
|
|
2109
|
+
rootUl.classList.add("c-tree");
|
|
2110
|
+
if (rootUl.parentNode !== this) this.appendChild(rootUl);
|
|
2111
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2112
|
+
} else if (!items && !authored.length) {
|
|
2113
|
+
renderEmpty(this, "tree");
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
enhance() {
|
|
2117
|
+
// Toggle handling for virtual trees only. Non-virtual handled by wireTree in behaviours.mjs. Both firing on same click canceled each other: ContourTree set aria-expanded to !expanded, then wireTree read new value and set it back.
|
|
2118
|
+
if (!this._wiredTreeToggle) {
|
|
2119
|
+
this._wiredTreeToggle = true;
|
|
2120
|
+
this.addEventListener("click", (e) => {
|
|
2121
|
+
if (!this.hasAttribute("virtual")) return;
|
|
2122
|
+
let toggle = e.target && e.target.closest ? e.target.closest(".c-tree__toggle") : null;
|
|
2123
|
+
if (!toggle) {
|
|
2124
|
+
const row = e.target && e.target.closest ? e.target.closest(".c-tree__row") : null;
|
|
2125
|
+
if (row) toggle = row.querySelector(":scope > .c-tree__toggle");
|
|
2126
|
+
}
|
|
2127
|
+
if (!toggle || !this.contains(toggle)) return;
|
|
2128
|
+
e.stopPropagation();
|
|
2129
|
+
const nodeEl = toggle.closest(".c-tree__node");
|
|
2130
|
+
const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
|
|
2131
|
+
const expanded = toggle.getAttribute("aria-expanded") === "true";
|
|
2132
|
+
if (path && this._expanded) {
|
|
2133
|
+
if (expanded) this._expanded.delete(path); else this._expanded.add(path);
|
|
2134
|
+
}
|
|
2135
|
+
toggle.setAttribute("aria-expanded", String(!expanded));
|
|
2136
|
+
const row = toggle.closest(".c-tree__row");
|
|
2137
|
+
if (row) row.setAttribute("aria-expanded", String(!expanded));
|
|
2138
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path, expanded: !expanded } }));
|
|
2139
|
+
if (this.hasAttribute("virtual") && this._treeRoot) {
|
|
2140
|
+
const s = this._treeRoot;
|
|
2141
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
2142
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
2143
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
2144
|
+
this._persistExpanded();
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
// Scroll-driven windowing for virtual trees.
|
|
2149
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeScroll) {
|
|
2150
|
+
this._wiredTreeScroll = true;
|
|
2151
|
+
const attach = () => {
|
|
2152
|
+
const s = this.querySelector(".c-tree");
|
|
2153
|
+
if (!s || s._treeScrollWired) return;
|
|
2154
|
+
s._treeScrollWired = true;
|
|
2155
|
+
let raf = 0;
|
|
2156
|
+
const onScroll = () => {
|
|
2157
|
+
if (raf) return;
|
|
2158
|
+
raf = requestAnimationFrame(() => {
|
|
2159
|
+
raf = 0;
|
|
2160
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
2161
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
2162
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
2163
|
+
});
|
|
2164
|
+
};
|
|
2165
|
+
s.addEventListener("scroll", onScroll, { passive: true });
|
|
2166
|
+
onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
|
|
2167
|
+
};
|
|
2168
|
+
attach();
|
|
2169
|
+
// retry if root not ready
|
|
2170
|
+
if (!this.querySelector(".c-tree")) {
|
|
2171
|
+
const mo = new MutationObserver(() => { if (this.querySelector(".c-tree")) { attach(); mo.disconnect(); } });
|
|
2172
|
+
mo.observe(this, { childList: true, subtree: true });
|
|
2173
|
+
onDispose(this, () => mo.disconnect());
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
// Auto-scroll during drag for virtual trees (so off-screen targets
|
|
2177
|
+
// become reachable). Delegated on the host; only active in virtual mode.
|
|
2178
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeDragScroll) {
|
|
2179
|
+
this._wiredTreeDragScroll = true;
|
|
2180
|
+
let dragScrollRaf = 0;
|
|
2181
|
+
let dragScrollDir = 0;
|
|
2182
|
+
const tick = () => {
|
|
2183
|
+
if (!dragScrollDir) { dragScrollRaf = 0; return; }
|
|
2184
|
+
const s = this._treeRoot;
|
|
2185
|
+
if (s) {
|
|
2186
|
+
s.scrollTop += dragScrollDir * 8;
|
|
2187
|
+
this._treeScrollTop = s.scrollTop;
|
|
2188
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
2189
|
+
}
|
|
2190
|
+
dragScrollRaf = requestAnimationFrame(tick);
|
|
2191
|
+
};
|
|
2192
|
+
this.addEventListener("dragover", (e) => {
|
|
2193
|
+
const s = this._treeRoot;
|
|
2194
|
+
if (!s) return;
|
|
2195
|
+
const rect = s.getBoundingClientRect();
|
|
2196
|
+
const edge = 40;
|
|
2197
|
+
if (e.clientY < rect.top + edge) dragScrollDir = -1;
|
|
2198
|
+
else if (e.clientY > rect.bottom - edge) dragScrollDir = 1;
|
|
2199
|
+
else dragScrollDir = 0;
|
|
2200
|
+
if (dragScrollDir && !dragScrollRaf) dragScrollRaf = requestAnimationFrame(tick);
|
|
2201
|
+
});
|
|
2202
|
+
const stop = () => {
|
|
2203
|
+
dragScrollDir = 0;
|
|
2204
|
+
if (dragScrollRaf) { cancelAnimationFrame(dragScrollRaf); dragScrollRaf = 0; }
|
|
2205
|
+
};
|
|
2206
|
+
this.addEventListener("dragend", stop);
|
|
2207
|
+
this.addEventListener("drop", stop);
|
|
2208
|
+
}
|
|
2209
|
+
// Interaction lives in behaviours.mjs (shared with shadow wrappers). One implementation prevents drift: shadow copy queried root for slotted nodes, found none, wired nothing.
|
|
2210
|
+
wireTree(this);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
define("contour-tree", ContourTree);
|
|
2214
|
+
class ContourFilterBar extends ContourBase {
|
|
2215
|
+
static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "scope", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "count", "clearable", "cache-key", "no-cache"]; }
|
|
2216
|
+
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" } }; }
|
|
2217
|
+
render() {
|
|
2218
|
+
this.classList.add("c-filter-bar");
|
|
2219
|
+
wireStates(this);
|
|
2220
|
+
loadRemote(this, "items");
|
|
2221
|
+
if (renderStates(this, "filter-bar")) return;
|
|
2222
|
+
const label = this.getAttribute("label");
|
|
2223
|
+
if (label) {
|
|
2224
|
+
const l = this.ensure(".c-filter-bar__label", () => { const el = document.createElement("span"); el.className = "c-filter-bar__label"; return el; });
|
|
2225
|
+
l.textContent = label;
|
|
2226
|
+
} else {
|
|
2227
|
+
const l = this.querySelector(".c-filter-bar__label");
|
|
2228
|
+
if (l) l.remove();
|
|
2229
|
+
}
|
|
2230
|
+
if (this.hasAttribute("divider")) {
|
|
2231
|
+
this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
|
|
2232
|
+
} else {
|
|
2233
|
+
const d = this.querySelector(".c-filter-bar__divider");
|
|
2234
|
+
if (d) d.remove();
|
|
2235
|
+
}
|
|
2236
|
+
// Text input support
|
|
2237
|
+
if (this.hasAttribute("input") || this.hasAttribute("placeholder")) {
|
|
2238
|
+
let inp = this.querySelector(".c-filter-bar__input");
|
|
2239
|
+
if (!inp) { inp = document.createElement("input"); inp.type = "search"; inp.className = "c-filter-bar__input"; this.appendChild(inp); }
|
|
2240
|
+
const ph = this.getAttribute("placeholder");
|
|
2241
|
+
if (ph) inp.setAttribute("placeholder", ph);
|
|
2242
|
+
} else {
|
|
2243
|
+
const inp = this.querySelector(".c-filter-bar__input");
|
|
2244
|
+
if (inp) inp.remove();
|
|
2245
|
+
}
|
|
2246
|
+
// Mode toolbar
|
|
2247
|
+
const modesAttr = this.getAttribute("modes");
|
|
2248
|
+
let modes = null;
|
|
2249
|
+
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
2250
|
+
if (modes || this.hasAttribute("mode")) {
|
|
2251
|
+
let bar = this.querySelector(".c-filter-bar__modes");
|
|
2252
|
+
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); }
|
|
2253
|
+
setHTML(bar, "");
|
|
2254
|
+
const current = this.getAttribute("mode");
|
|
2255
|
+
const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
|
|
2256
|
+
list.forEach((m) => {
|
|
2257
|
+
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
2258
|
+
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
2259
|
+
const btn = document.createElement("button");
|
|
2260
|
+
btn.type = "button";
|
|
2261
|
+
btn.className = "c-filter-bar__mode";
|
|
2262
|
+
btn.textContent = name;
|
|
2263
|
+
btn.dataset.mode = val;
|
|
2264
|
+
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
2265
|
+
bar.appendChild(btn);
|
|
2266
|
+
});
|
|
2267
|
+
} else {
|
|
2268
|
+
const bar = this.querySelector(".c-filter-bar__modes");
|
|
2269
|
+
if (bar) bar.remove();
|
|
2270
|
+
}
|
|
2271
|
+
// Scope toggle (viewport / global) — CARTO-inspired.
|
|
2272
|
+
const scope = this.getAttribute("scope");
|
|
2273
|
+
if (scope === "viewport" || scope === "global") {
|
|
2274
|
+
Array.from(this.querySelectorAll(".c-filter-bar__scope")).forEach((n) => n.remove());
|
|
2275
|
+
const bar = document.createElement("div");
|
|
2276
|
+
bar.className = "c-filter-bar__modes c-filter-bar__scope";
|
|
2277
|
+
bar.setAttribute("role", "toolbar");
|
|
2278
|
+
bar.setAttribute("aria-label", labelText(this, "data-scope", "Data scope"));
|
|
2279
|
+
["viewport", "global"].forEach((s) => {
|
|
2280
|
+
const btn = document.createElement("button");
|
|
2281
|
+
btn.type = "button";
|
|
2282
|
+
btn.className = "c-filter-bar__mode c-filter-bar__scope-btn";
|
|
2283
|
+
btn.textContent = s === "viewport" ? "Viewport" : "Global";
|
|
2284
|
+
btn.dataset.scope = s;
|
|
2285
|
+
if (scope === s) btn.setAttribute("aria-pressed", "true");
|
|
2286
|
+
bar.appendChild(btn);
|
|
2287
|
+
});
|
|
2288
|
+
this.appendChild(bar);
|
|
2289
|
+
} else {
|
|
2290
|
+
const bar = this.querySelector(".c-filter-bar__scope");
|
|
2291
|
+
if (bar) bar.remove();
|
|
2292
|
+
}
|
|
2293
|
+
// Render filter pills from items.
|
|
2294
|
+
Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
|
|
2295
|
+
const items = remoteData(this, "items");
|
|
2296
|
+
// Slotted content: authored .c-filter-pill children take precedence.
|
|
2297
|
+
const authoredPills = Array.from(this.querySelectorAll(":scope > .c-filter-pill"));
|
|
2298
|
+
let parsed = null;
|
|
2299
|
+
if (authoredPills.length) {
|
|
2300
|
+
parsed = authoredPills.map((p) => p.textContent.trim());
|
|
2301
|
+
authoredPills.forEach((p) => p.remove());
|
|
2302
|
+
} else if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
2303
|
+
if (Array.isArray(parsed)) {
|
|
2304
|
+
parsed.forEach((it) => {
|
|
2305
|
+
const pill = document.createElement("span");
|
|
2306
|
+
pill.className = "c-filter-pill";
|
|
2307
|
+
const isObj = typeof it === "object" && it !== null;
|
|
2308
|
+
const txt = typeof it === "string" ? it : (it.label || it.value || "");
|
|
2309
|
+
// Carry identity on pill so contour:remove reports key/value.
|
|
2310
|
+
const key = isObj ? it.key : null;
|
|
2311
|
+
const value = isObj ? it.value : it;
|
|
2312
|
+
if (key != null && key !== "") pill.setAttribute("key", String(key));
|
|
2313
|
+
if (value != null && value !== "") pill.setAttribute("value", String(value));
|
|
2314
|
+
pill.textContent = txt;
|
|
2315
|
+
// R24-40: a string pill is removable too. Only an object that sets
|
|
2316
|
+
// removable:false suppresses the remove button.
|
|
2317
|
+
if (!isObj || it.removable !== false) {
|
|
2318
|
+
const btn = document.createElement("button");
|
|
2319
|
+
btn.className = "c-filter-pill__remove";
|
|
2320
|
+
btn.type = "button";
|
|
2321
|
+
btn.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + txt);
|
|
2322
|
+
btn.textContent = "×";
|
|
2323
|
+
pill.appendChild(btn);
|
|
2324
|
+
}
|
|
2325
|
+
this.appendChild(pill);
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
// Clear-all affordance (CARTO-inspired): panel-level clear with active count.
|
|
2329
|
+
Array.from(this.querySelectorAll(".c-filter-bar__clear-all")).forEach((n) => n.remove());
|
|
2330
|
+
if (this.hasAttribute("clearable")) {
|
|
2331
|
+
const btn = document.createElement("button");
|
|
2332
|
+
btn.type = "button";
|
|
2333
|
+
btn.className = "c-btn c-btn--ghost c-btn--sm c-filter-bar__clear-all";
|
|
2334
|
+
const count = this.getAttribute("count");
|
|
2335
|
+
// R31-145: clear-all is icon+text (never icon-only destructive).
|
|
2336
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
2337
|
+
btn.appendChild(document.createTextNode(" " + (count ? (labelText(this, "clear-all", "Clear all") + " (" + count + ")") : labelText(this, "clear-all", "Clear all"))));
|
|
2338
|
+
this.appendChild(btn);
|
|
2339
|
+
}
|
|
2340
|
+
if (!parsed && !label) renderEmpty(this, "filter-bar");
|
|
2341
|
+
}
|
|
2342
|
+
enhance() {
|
|
2343
|
+
wireRemovable(this);
|
|
2344
|
+
if (this._wiredFilterBar) return;
|
|
2345
|
+
this._wiredFilterBar = true;
|
|
2346
|
+
this.addEventListener("click", (e) => {
|
|
2347
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
|
|
2348
|
+
if (!btn || !this.contains(btn)) return;
|
|
2349
|
+
// Mode and scope buttons are independent pressed pools.
|
|
2350
|
+
if (btn.classList.contains("c-filter-bar__scope-btn")) {
|
|
2351
|
+
const scope = btn.dataset.scope || null;
|
|
2352
|
+
Array.from(this.querySelectorAll(".c-filter-bar__scope-btn")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
2353
|
+
if (scope) this.setAttribute("scope", scope);
|
|
2354
|
+
this.dispatchEvent(new CustomEvent("contour:scope-change", { bubbles: true, composed: true, detail: { scope } }));
|
|
2355
|
+
} else {
|
|
2356
|
+
const mode = btn.dataset.mode || btn.textContent.trim();
|
|
2357
|
+
Array.from(this.querySelectorAll(".c-filter-bar__mode:not(.c-filter-bar__scope-btn)")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
2358
|
+
this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
this.addEventListener("keydown", (e) => {
|
|
2362
|
+
const modes = Array.from(this.querySelectorAll(".c-filter-bar__mode"));
|
|
2363
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
2364
|
+
});
|
|
2365
|
+
// text input
|
|
2366
|
+
const inp = this.querySelector(".c-filter-bar__input");
|
|
2367
|
+
if (inp && !inp._wiredFilterInput) {
|
|
2368
|
+
inp._wiredFilterInput = true;
|
|
2369
|
+
inp.addEventListener("input", () => {
|
|
2370
|
+
this.dispatchEvent(new CustomEvent("contour:input", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
2371
|
+
});
|
|
2372
|
+
inp.addEventListener("change", () => {
|
|
2373
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
// Clear-all (CARTO-inspired): delegated on host.
|
|
2377
|
+
if (!this._wiredClearAll) {
|
|
2378
|
+
this._wiredClearAll = true;
|
|
2379
|
+
this.addEventListener("click", (e) => {
|
|
2380
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__clear-all") : null;
|
|
2381
|
+
if (!btn || !this.contains(btn)) return;
|
|
2382
|
+
e.preventDefault();
|
|
2383
|
+
this.dispatchEvent(new CustomEvent("contour:clear-all", { bubbles: true, composed: true, detail: {} }));
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
define("contour-filter-bar", ContourFilterBar);
|
|
2389
|
+
class ContourCommand extends ContourBase {
|
|
2390
|
+
static get observed() { return ["placeholder", "items", "recent", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache", "anchor"]; }
|
|
2391
|
+
static get properties() { return { placeholder: { attribute: "placeholder" }, items: { attribute: "items" }, recent: { attribute: "recent" }, empty: { attribute: "empty" }, src: { attribute: "src" } }; }
|
|
2392
|
+
render() {
|
|
2393
|
+
this.classList.add("c-command");
|
|
2394
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
2395
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "command-palette", "Command palette"));
|
|
2396
|
+
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
2397
|
+
wireStates(this);
|
|
2398
|
+
loadRemote(this, "items");
|
|
2399
|
+
if (renderStates(this, "command")) return;
|
|
2400
|
+
const placeholder = this.getAttribute("placeholder") || "Search…";
|
|
2401
|
+
// Mirror palette structure so CSS applies instead of UA input border.
|
|
2402
|
+
const inputWrap = this.ensure(".c-command__input", () => { const el = document.createElement("div"); el.className = "c-command__input"; return el; });
|
|
2403
|
+
const input = this.ensure(".c-command__field", () => { const el = document.createElement("input"); el.className = "c-command__field"; el.type = "text"; return el; });
|
|
2404
|
+
if (!inputWrap.contains(input)) inputWrap.appendChild(input);
|
|
2405
|
+
input.type = "text";
|
|
2406
|
+
input.placeholder = placeholder;
|
|
2407
|
+
input.setAttribute("aria-label", labelText(this, "command", "Command"));
|
|
2408
|
+
input.setAttribute("role", "combobox");
|
|
2409
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
2410
|
+
input.setAttribute("aria-expanded", "true");
|
|
2411
|
+
const list = this.querySelector(".c-command__list");
|
|
2412
|
+
if (list && !list.id) list.id = contourId("c-command-list");
|
|
2413
|
+
if (list && list.id) input.setAttribute("aria-controls", list.id);
|
|
2414
|
+
// R24-38: anchor wiring — position-anchor on the host, anchor-name on the
|
|
2415
|
+
// trigger element, like map-popup / ContourPopover.
|
|
2416
|
+
this._applyCommandAnchor();
|
|
2417
|
+
const items = remoteData(this, "items");
|
|
2418
|
+
const list2 = this.querySelector(".c-command__list");
|
|
2419
|
+
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")) : [];
|
|
2420
|
+
if (items && !authored.length) {
|
|
2421
|
+
try {
|
|
2422
|
+
const parsed = JSON.parse(items);
|
|
2423
|
+
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; });
|
|
2424
|
+
l.setAttribute("role", "listbox");
|
|
2425
|
+
setHTML(l, "");
|
|
2426
|
+
const recentRaw = this.getAttribute("recent");
|
|
2427
|
+
if (recentRaw) {
|
|
2428
|
+
try {
|
|
2429
|
+
const recentParsed = JSON.parse(recentRaw);
|
|
2430
|
+
const group = document.createElement("div");
|
|
2431
|
+
group.className = "c-command__group";
|
|
2432
|
+
const gt = document.createElement("div");
|
|
2433
|
+
gt.className = "c-command__group-title";
|
|
2434
|
+
gt.textContent = labelText(this, "recent", "Recent");
|
|
2435
|
+
group.appendChild(gt);
|
|
2436
|
+
recentParsed.forEach((it) => {
|
|
2437
|
+
const item = document.createElement("div");
|
|
2438
|
+
item.className = "c-command__item";
|
|
2439
|
+
item.setAttribute("role", "option");
|
|
2440
|
+
const body = document.createElement("div");
|
|
2441
|
+
body.className = "c-command__item-body";
|
|
2442
|
+
const t = document.createElement("div");
|
|
2443
|
+
t.className = "c-command__item-title";
|
|
2444
|
+
t.textContent = typeof it === "string" ? it : (it.title || it.label || "");
|
|
2445
|
+
body.appendChild(t);
|
|
2446
|
+
item.appendChild(body);
|
|
2447
|
+
group.appendChild(item);
|
|
2448
|
+
});
|
|
2449
|
+
l.appendChild(group);
|
|
2450
|
+
} catch (e) { /* skip */ }
|
|
2451
|
+
}
|
|
2452
|
+
parsed.forEach((it) => {
|
|
2453
|
+
if (it.group) {
|
|
2454
|
+
const group = document.createElement("div");
|
|
2455
|
+
group.className = "c-command__group";
|
|
2456
|
+
const gt = document.createElement("div");
|
|
2457
|
+
gt.className = "c-command__group-title";
|
|
2458
|
+
gt.textContent = it.group;
|
|
2459
|
+
group.appendChild(gt);
|
|
2460
|
+
const item = document.createElement("div");
|
|
2461
|
+
item.className = "c-command__item";
|
|
2462
|
+
item.setAttribute("role", "option");
|
|
2463
|
+
if (it.icon) {
|
|
2464
|
+
const ic = document.createElement("span");
|
|
2465
|
+
ic.className = "c-command__item-icon";
|
|
2466
|
+
ic.textContent = it.icon;
|
|
2467
|
+
item.appendChild(ic);
|
|
2468
|
+
}
|
|
2469
|
+
const body = document.createElement("div");
|
|
2470
|
+
body.className = "c-command__item-body";
|
|
2471
|
+
if (it.title || it.label) {
|
|
2472
|
+
const t = document.createElement("div");
|
|
2473
|
+
t.className = "c-command__item-title";
|
|
2474
|
+
t.textContent = it.title || it.label;
|
|
2475
|
+
body.appendChild(t);
|
|
2476
|
+
}
|
|
2477
|
+
if (it.hint) {
|
|
2478
|
+
const h = document.createElement("span");
|
|
2479
|
+
h.className = "c-command__item-hint";
|
|
2480
|
+
h.textContent = it.hint;
|
|
2481
|
+
body.appendChild(h);
|
|
2482
|
+
}
|
|
2483
|
+
if (it.shortcut) {
|
|
2484
|
+
const sc = document.createElement("kbd");
|
|
2485
|
+
sc.className = "c-command__item-shortcut";
|
|
2486
|
+
sc.textContent = it.shortcut;
|
|
2487
|
+
item.appendChild(sc);
|
|
2488
|
+
}
|
|
2489
|
+
item.appendChild(body);
|
|
2490
|
+
group.appendChild(item);
|
|
2491
|
+
l.appendChild(group);
|
|
2492
|
+
} else {
|
|
2493
|
+
const item = document.createElement("div");
|
|
2494
|
+
item.className = "c-command__item";
|
|
2495
|
+
item.setAttribute("role", "option");
|
|
2496
|
+
if (it.icon) {
|
|
2497
|
+
const ic = document.createElement("span");
|
|
2498
|
+
ic.className = "c-command__item-icon";
|
|
2499
|
+
ic.textContent = it.icon;
|
|
2500
|
+
item.appendChild(ic);
|
|
2501
|
+
}
|
|
2502
|
+
const body = document.createElement("div");
|
|
2503
|
+
body.className = "c-command__item-body";
|
|
2504
|
+
if (it.title || it.label) {
|
|
2505
|
+
const t = document.createElement("div");
|
|
2506
|
+
t.className = "c-command__item-title";
|
|
2507
|
+
t.textContent = it.title || it.label;
|
|
2508
|
+
body.appendChild(t);
|
|
2509
|
+
}
|
|
2510
|
+
if (it.hint) {
|
|
2511
|
+
const h = document.createElement("span");
|
|
2512
|
+
h.className = "c-command__item-hint";
|
|
2513
|
+
h.textContent = it.hint;
|
|
2514
|
+
body.appendChild(h);
|
|
2515
|
+
}
|
|
2516
|
+
if (it.shortcut) {
|
|
2517
|
+
const sc = document.createElement("kbd");
|
|
2518
|
+
sc.className = "c-command__item-shortcut";
|
|
2519
|
+
sc.textContent = it.shortcut;
|
|
2520
|
+
item.appendChild(sc);
|
|
2521
|
+
}
|
|
2522
|
+
item.appendChild(body);
|
|
2523
|
+
l.appendChild(item);
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2526
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2527
|
+
} else if (!items && list) {
|
|
2528
|
+
list.remove();
|
|
2529
|
+
}
|
|
2530
|
+
const empty = this.getAttribute("empty");
|
|
2531
|
+
if (empty) {
|
|
2532
|
+
const e = this.ensure(".c-command__empty", () => { const el = document.createElement("div"); el.className = "c-command__empty"; return el; });
|
|
2533
|
+
e.textContent = empty;
|
|
2534
|
+
// Empty message shown only when query yields nothing.
|
|
2535
|
+
e.hidden = this.querySelectorAll(".c-command__item").length > 0;
|
|
2536
|
+
} else {
|
|
2537
|
+
const e = this.querySelector(".c-command__empty");
|
|
2538
|
+
if (e) e.remove();
|
|
2539
|
+
}
|
|
2540
|
+
// Live filter region exists empty at mount; filled only when typing.
|
|
2541
|
+
const status = this.ensure(".c-command__status", () => { const el = document.createElement("div"); el.className = "c-command__status"; el.setAttribute("role", "status"); return el; });
|
|
2542
|
+
status.textContent = "";
|
|
2543
|
+
if (!items && !list) {
|
|
2544
|
+
renderEmpty(this, "command");
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
// R24-38: anchor wiring — position-anchor on the host, anchor-name on the
|
|
2548
|
+
// trigger element, like map-popup / ContourPopover.
|
|
2549
|
+
_applyCommandAnchor() {
|
|
2550
|
+
const anchorSel = this.getAttribute("anchor");
|
|
2551
|
+
const anchorEl = anchorSel ? (anchorSel.startsWith("#") ? document.getElementById(anchorSel.slice(1)) : document.querySelector(anchorSel)) : null;
|
|
2552
|
+
if (this._commandAnchorEl && this._commandAnchorEl !== anchorEl) {
|
|
2553
|
+
this._commandAnchorEl.style.removeProperty("anchor-name");
|
|
2554
|
+
this._commandAnchorEl.removeAttribute("aria-controls");
|
|
2555
|
+
this._commandAnchorEl.removeAttribute("aria-expanded");
|
|
2556
|
+
}
|
|
2557
|
+
this._commandAnchorEl = anchorEl || null;
|
|
2558
|
+
if (anchorEl) {
|
|
2559
|
+
const anchorName = "--command-" + this.id;
|
|
2560
|
+
anchorEl.style.setProperty("anchor-name", anchorName);
|
|
2561
|
+
this.style.setProperty("position-anchor", anchorName);
|
|
2562
|
+
anchorEl.setAttribute("aria-controls", this.id);
|
|
2563
|
+
if (!this._commandAnchorDispose) {
|
|
2564
|
+
this._commandAnchorDispose = true;
|
|
2565
|
+
onDispose(this, () => {
|
|
2566
|
+
if (this._commandAnchorEl) { this._commandAnchorEl.style.removeProperty("anchor-name"); this._commandAnchorEl.removeAttribute("aria-controls"); this._commandAnchorEl.removeAttribute("aria-expanded"); }
|
|
2567
|
+
this._commandAnchorDispose = false;
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
} else {
|
|
2571
|
+
this.style.removeProperty("position-anchor");
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
// R24-38: show/hide/toggle with aria-expanded sync, mirroring
|
|
2575
|
+
// ContourCommandPalette (ui.mjs) and ContourPopover.
|
|
2576
|
+
show() {
|
|
2577
|
+
if (this.matches(":popover-open")) { if (!this.hasAttribute("open")) this.setAttribute("open", ""); return; }
|
|
2578
|
+
if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (e) {} }
|
|
2579
|
+
this.classList.add("is-open");
|
|
2580
|
+
const inp = this.querySelector(".c-command__field");
|
|
2581
|
+
if (inp) inp.setAttribute("aria-expanded", "true");
|
|
2582
|
+
if (!this.hasAttribute("open")) this.setAttribute("open", "");
|
|
2583
|
+
this._setCommandTriggerExpanded(true);
|
|
2584
|
+
}
|
|
2585
|
+
hide() {
|
|
2586
|
+
const isOpen = this.matches(":popover-open");
|
|
2587
|
+
if (!isOpen) { if (this.hasAttribute("open")) this.removeAttribute("open"); return; }
|
|
2588
|
+
if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (e) {} }
|
|
2589
|
+
this.classList.remove("is-open");
|
|
2590
|
+
const inp = this.querySelector(".c-command__field");
|
|
2591
|
+
if (inp) inp.setAttribute("aria-expanded", "false");
|
|
2592
|
+
if (this.hasAttribute("open")) this.removeAttribute("open");
|
|
2593
|
+
this._setCommandTriggerExpanded(false);
|
|
2594
|
+
}
|
|
2595
|
+
toggle() { if (this.matches(":popover-open")) this.hide(); else this.show(); }
|
|
2596
|
+
_setCommandTriggerExpanded(open) {
|
|
2597
|
+
const trg = this._commandAnchorEl;
|
|
2598
|
+
if (!trg) return;
|
|
2599
|
+
trg.setAttribute("aria-controls", this.id);
|
|
2600
|
+
trg.setAttribute("aria-expanded", String(!!open));
|
|
2601
|
+
}
|
|
2602
|
+
enhance() {
|
|
2603
|
+
if (this._wiredCommand) return;
|
|
2604
|
+
this._wiredCommand = true;
|
|
2605
|
+
// Emit contour:open/close (canonical) plus deprecated aliases; sync aria-expanded.
|
|
2606
|
+
this.addEventListener("beforetoggle", (e) => {
|
|
2607
|
+
if (e.newState === "open") {
|
|
2608
|
+
this.classList.add("is-open");
|
|
2609
|
+
wcEmitOverlay(this, "contour:open", {});
|
|
2610
|
+
const inp = this.querySelector(".c-command__field");
|
|
2611
|
+
if (inp) { inp.setAttribute("aria-expanded", "true"); try { inp.focus(); } catch (e) {} }
|
|
2612
|
+
this._setCommandTriggerExpanded(true);
|
|
2613
|
+
} else {
|
|
2614
|
+
this.classList.remove("is-open");
|
|
2615
|
+
wcEmitOverlay(this, "contour:close", {});
|
|
2616
|
+
this._setCommandTriggerExpanded(false);
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2619
|
+
// Re-apply anchor on open (like map-popup).
|
|
2620
|
+
this.addEventListener("toggle", (e) => {
|
|
2621
|
+
if (e.newState === "open") { requestAnimationFrame(() => { this._applyCommandAnchor(); }); }
|
|
2622
|
+
});
|
|
2623
|
+
const input = () => this.querySelector(".c-command__field");
|
|
2624
|
+
const items = () => Array.from(this.querySelectorAll(".c-command__item"));
|
|
2625
|
+
// R31-100: the cursor walks only items the reader can see. A hidden option
|
|
2626
|
+
// (filtered out by typing) is not a stop; arrowing onto it moved the active
|
|
2627
|
+
// descendant to an invisible row.
|
|
2628
|
+
const visibleItems = () => items().filter((el) => !el.hidden && !el.closest("[hidden]"));
|
|
2629
|
+
let cursor = -1;
|
|
2630
|
+
const mark = () => {
|
|
2631
|
+
visibleItems().forEach((it, i) => {
|
|
2632
|
+
it.classList.toggle("c-command__item--active", i === cursor);
|
|
2633
|
+
it.setAttribute("aria-selected", String(i === cursor));
|
|
2634
|
+
if (i === cursor) {
|
|
2635
|
+
if (!it.id) it.id = contourId("contour-command-option");
|
|
2636
|
+
const inp = input();
|
|
2637
|
+
if (inp) inp.setAttribute("aria-activedescendant", it.id);
|
|
2638
|
+
}
|
|
2639
|
+
});
|
|
2640
|
+
if (cursor < 0) {
|
|
2641
|
+
const inp = input();
|
|
2642
|
+
if (inp) inp.removeAttribute("aria-activedescendant");
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
this.addEventListener("keydown", (e) => {
|
|
2646
|
+
const inp = input();
|
|
2647
|
+
if (!inp || e.target !== inp) return;
|
|
2648
|
+
const its = visibleItems();
|
|
2649
|
+
if (!its.length) return;
|
|
2650
|
+
if (e.key === "ArrowDown") { e.preventDefault(); cursor = Math.min(cursor + 1, its.length - 1); mark(); }
|
|
2651
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); cursor = Math.max(cursor - 1, 0); mark(); }
|
|
2652
|
+
else if (e.key === "Home") { e.preventDefault(); cursor = 0; mark(); }
|
|
2653
|
+
else if (e.key === "End") { e.preventDefault(); cursor = its.length - 1; mark(); }
|
|
2654
|
+
else if (e.key === "Enter") {
|
|
2655
|
+
e.preventDefault();
|
|
2656
|
+
if (cursor >= 0 && its[cursor]) {
|
|
2657
|
+
const item = its[cursor];
|
|
2658
|
+
const idx = items().indexOf(item);
|
|
2659
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
2660
|
+
this.hide();
|
|
2661
|
+
}
|
|
2662
|
+
} else if (e.key === "Escape") {
|
|
2663
|
+
this.hide();
|
|
2664
|
+
}
|
|
2665
|
+
});
|
|
2666
|
+
this.addEventListener("click", (e) => {
|
|
2667
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-command__item") : null;
|
|
2668
|
+
if (item && this.contains(item)) {
|
|
2669
|
+
const idx = items().indexOf(item);
|
|
2670
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
2671
|
+
this.hide();
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
// Typing narrows option set; hidden items excluded from cursor walk.
|
|
2675
|
+
this.addEventListener("input", (e) => {
|
|
2676
|
+
const inp = input();
|
|
2677
|
+
if (!inp || e.target !== inp) return;
|
|
2678
|
+
const q = inp.value.trim().toLowerCase();
|
|
2679
|
+
const all = items();
|
|
2680
|
+
let visible = 0;
|
|
2681
|
+
all.forEach((it) => {
|
|
2682
|
+
const match = !q || (it.textContent || "").toLowerCase().includes(q);
|
|
2683
|
+
it.hidden = !match;
|
|
2684
|
+
if (match) visible += 1;
|
|
2685
|
+
});
|
|
2686
|
+
this.querySelectorAll(".c-command__group").forEach((g) => {
|
|
2687
|
+
const hasVisible = Array.from(g.querySelectorAll(".c-command__item")).some((it) => !it.hidden);
|
|
2688
|
+
g.hidden = !hasVisible;
|
|
2689
|
+
});
|
|
2690
|
+
// Highlight first visible result; reveal empty message only on no match.
|
|
2691
|
+
const firstVisible = all.findIndex((it) => !it.hidden);
|
|
2692
|
+
// mark() numbers the visible set, not the full item list.
|
|
2693
|
+
cursor = firstVisible >= 0 ? 0 : -1;
|
|
2694
|
+
mark();
|
|
2695
|
+
const emptyEl = this.querySelector(".c-command__empty");
|
|
2696
|
+
if (emptyEl) emptyEl.hidden = visible !== 0;
|
|
2697
|
+
const status = this.querySelector(".c-command__status");
|
|
2698
|
+
if (status) status.textContent = q ? `${visible} of ${all.length}` : "";
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
define("contour-command", ContourCommand);
|
|
2703
|
+
|
|
2704
|
+
/**
|
|
2705
|
+
* Spatial filter (CARTO-inspired): draw-on-map affordance. Engine-agnostic:
|
|
2706
|
+
* Contour renders the mode toolbar and emits `contour:draw-start` (with the
|
|
2707
|
+
* `mode`) and `contour:spatial-filter` to signal intent; it does NOT own the
|
|
2708
|
+
* drawn geometry. The engine that owns the canvas emits its own draw-end with
|
|
2709
|
+
* the geometry payload (R31-94: engine ownership is explicit, so a consumer
|
|
2710
|
+
* never waits for a `contour:draw-end` the seam does not send). The consumer
|
|
2711
|
+
* runs the spatial query against its map engine.
|
|
2712
|
+
* Attributes: `modes`, `mode`, `active`, `bounds`, `operator`, `loading`,
|
|
2713
|
+
* `error`, `retry`, `skeleton`, `src`, `cache-key`.
|
|
2714
|
+
*/
|
|
2715
|
+
class ContourSpatialFilter extends ContourBase {
|
|
2716
|
+
// Pure UI component; unused loader attrs dropped from observed.
|
|
2717
|
+
static get observed() { return ["modes", "mode", "active", "bounds", "operator", "loading", "error", "retry", "cache-key", "skeleton", "src"]; }
|
|
2718
|
+
static get properties() { return { modes: { attribute: "modes" }, mode: { attribute: "mode" }, active: { attribute: "active" }, bounds: { attribute: "bounds" }, operator: { attribute: "operator" } }; }
|
|
2719
|
+
render() {
|
|
2720
|
+
this.classList.add("c-spatial-filter");
|
|
2721
|
+
// The host is a labelled group; the mode bar is a labelled toolbar, so a
|
|
2722
|
+
// screen reader announces both the filter and its control set (NAV-19).
|
|
2723
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
2724
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "spatial-filter", "Spatial filter"));
|
|
2725
|
+
wireStates(this);
|
|
2726
|
+
// No remote src; loader call and attrs removed.
|
|
2727
|
+
if (renderStates(this, "spatial-filter")) return;
|
|
2728
|
+
const modesAttr = this.getAttribute("modes");
|
|
2729
|
+
let modes = null;
|
|
2730
|
+
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
2731
|
+
const list = Array.isArray(modes) ? modes : ["rect", "circle", "polygon", "clear"];
|
|
2732
|
+
let bar = this.querySelector(".c-spatial-filter__modes");
|
|
2733
|
+
if (!bar) { bar = document.createElement("div"); bar.className = "c-spatial-filter__modes"; bar.setAttribute("role", "toolbar"); bar.setAttribute("aria-label", labelText(this, "spatial-filter-modes", "Spatial filter modes")); this.appendChild(bar); }
|
|
2734
|
+
setHTML(bar, "");
|
|
2735
|
+
// Clicked mode persists across re-renders via private field.
|
|
2736
|
+
const attrMode = this.getAttribute("mode");
|
|
2737
|
+
if (attrMode !== this._spatialSeenMode) { this._spatialMode = null; this._spatialSeenMode = attrMode; }
|
|
2738
|
+
const current = this._spatialMode != null ? this._spatialMode : attrMode;
|
|
2739
|
+
list.forEach((m) => {
|
|
2740
|
+
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
2741
|
+
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
2742
|
+
const btn = document.createElement("button");
|
|
2743
|
+
btn.type = "button";
|
|
2744
|
+
btn.className = "c-spatial-filter__mode c-btn c-btn--ghost c-btn--sm";
|
|
2745
|
+
// R31-155: each mode carries a shape glyph (icon+text); the name stays.
|
|
2746
|
+
const MODE_GLYPH = { rect: "i-square", circle: "i-circle", polygon: "i-triangle", lasso: "i-lasso", clear: "i-x" };
|
|
2747
|
+
const glyph = MODE_GLYPH[val];
|
|
2748
|
+
if (glyph) setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + glyph + '" /></svg>');
|
|
2749
|
+
btn.appendChild(document.createTextNode((glyph ? " " : "") + name));
|
|
2750
|
+
btn.dataset.mode = val;
|
|
2751
|
+
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
2752
|
+
bar.appendChild(btn);
|
|
2753
|
+
});
|
|
2754
|
+
// Operator selection
|
|
2755
|
+
let operator = this.querySelector(".c-spatial-filter__operator");
|
|
2756
|
+
if (!operator) { operator = document.createElement("div"); operator.className = "c-spatial-filter__operator"; this.appendChild(operator); }
|
|
2757
|
+
const ops = ["intersects", "contains", "within", "disjoint"];
|
|
2758
|
+
const currentOp = this.getAttribute("operator") || "intersects";
|
|
2759
|
+
setHTML(operator, "");
|
|
2760
|
+
const opLabel = document.createElement("span");
|
|
2761
|
+
opLabel.textContent = labelText(this, "operator", "Operator") + ":";
|
|
2762
|
+
operator.appendChild(opLabel);
|
|
2763
|
+
const opSelect = document.createElement("select");
|
|
2764
|
+
opSelect.className = "c-spatial-filter__operator-select";
|
|
2765
|
+
opSelect.setAttribute("aria-label", labelText(this, "operator", "Operator"));
|
|
2766
|
+
opSelect.setAttribute("data-contour-label", "true");
|
|
2767
|
+
ops.forEach((op) => {
|
|
2768
|
+
const o = document.createElement("option");
|
|
2769
|
+
o.value = op;
|
|
2770
|
+
o.textContent = op;
|
|
2771
|
+
if (op === currentOp) o.setAttribute("selected", "");
|
|
2772
|
+
opSelect.appendChild(o);
|
|
2773
|
+
});
|
|
2774
|
+
operator.appendChild(opSelect);
|
|
2775
|
+
// Bounds readout
|
|
2776
|
+
let readout = this.querySelector(".c-spatial-filter__readout");
|
|
2777
|
+
if (!readout) { readout = document.createElement("div"); readout.className = "c-spatial-filter__readout"; this.appendChild(readout); }
|
|
2778
|
+
const bounds = this.getAttribute("bounds");
|
|
2779
|
+
readout.textContent = bounds || "—";
|
|
2780
|
+
// Clear all
|
|
2781
|
+
let clearAll = this.querySelector(".c-spatial-filter__clear-all");
|
|
2782
|
+
if (!clearAll) { clearAll = document.createElement("button"); clearAll.type = "button"; clearAll.className = "c-spatial-filter__clear-all"; this.appendChild(clearAll); }
|
|
2783
|
+
applyLabel(clearAll, this, "clear-all", "Clear all");
|
|
2784
|
+
// R24-43: same field-over-attribute persistence as `mode` above.
|
|
2785
|
+
const attrActive = this.hasAttribute("active");
|
|
2786
|
+
if (attrActive !== this._spatialSeenActive) { this._spatialActive = null; this._spatialSeenActive = attrActive; }
|
|
2787
|
+
if (this._spatialActive != null ? this._spatialActive : attrActive) {
|
|
2788
|
+
this.classList.add("c-spatial-filter--active");
|
|
2789
|
+
} else {
|
|
2790
|
+
this.classList.remove("c-spatial-filter--active");
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
enhance() {
|
|
2794
|
+
if (this._wiredSpatialFilter) return;
|
|
2795
|
+
this._wiredSpatialFilter = true;
|
|
2796
|
+
this.addEventListener("click", (e) => {
|
|
2797
|
+
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
2798
|
+
if (!btn || !this.contains(btn)) return;
|
|
2799
|
+
if (btn.classList.contains("c-spatial-filter__clear-all")) {
|
|
2800
|
+
this.classList.remove("c-spatial-filter--active");
|
|
2801
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
2802
|
+
// R24-43: clear the persisted mode + active fields so a re-render
|
|
2803
|
+
// cannot restore the old selection.
|
|
2804
|
+
this._spatialActive = false;
|
|
2805
|
+
this._spatialMode = null;
|
|
2806
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
2807
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "clear-all" } }));
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
const modeBtn = btn.closest(".c-spatial-filter__mode");
|
|
2811
|
+
if (!modeBtn) return;
|
|
2812
|
+
const mode = modeBtn.dataset.mode || modeBtn.textContent.trim();
|
|
2813
|
+
if (mode === "clear") {
|
|
2814
|
+
this.classList.remove("c-spatial-filter--active");
|
|
2815
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
2816
|
+
this._spatialActive = false;
|
|
2817
|
+
this._spatialMode = null;
|
|
2818
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
this.classList.add("c-spatial-filter--active");
|
|
2822
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === modeBtn)));
|
|
2823
|
+
// Persist mode/active in private fields to survive re-render.
|
|
2824
|
+
this._spatialActive = true;
|
|
2825
|
+
this._spatialMode = mode;
|
|
2826
|
+
this.dispatchEvent(new CustomEvent("contour:draw-start", { bubbles: true, composed: true, detail: { mode } }));
|
|
2827
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "draw-start", mode } }));
|
|
2828
|
+
});
|
|
2829
|
+
this.addEventListener("change", (e) => {
|
|
2830
|
+
const select = e.target;
|
|
2831
|
+
if (select && select.classList.contains("c-spatial-filter__operator-select")) {
|
|
2832
|
+
this.setAttribute("operator", select.value);
|
|
2833
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "operator", operator: select.value } }));
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
this.addEventListener("keydown", (e) => {
|
|
2837
|
+
const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
|
|
2838
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
2839
|
+
});
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
define("contour-spatial-filter", ContourSpatialFilter);
|