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,2411 @@
|
|
|
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
|
+
|
|
610
|
+
|
|
611
|
+
// R31-154: the layer-type vocabulary. A map layer is a shape first, a colour
|
|
612
|
+
// second; these are the shapes a swatch can draw (`.c-swatch--<shape>`).
|
|
613
|
+
const SHAPES = new Set(["point", "line", "polygon", "raster", "heatmap", "symbol"]);
|
|
614
|
+
|
|
615
|
+
// Shared tooltip + roving + select wiring for the map components that render a
|
|
616
|
+
function wireMapItems(host, itemSelector, tooltipClass) {
|
|
617
|
+
if (host._wiredMapItems) return;
|
|
618
|
+
host._wiredMapItems = true;
|
|
619
|
+
const items = () => Array.from(host.querySelectorAll(itemSelector));
|
|
620
|
+
const showTip = (e) => {
|
|
621
|
+
const tip = host.querySelector(tooltipClass);
|
|
622
|
+
if (!tip) return;
|
|
623
|
+
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
624
|
+
if (!item || !host.contains(item)) { tip.setAttribute("hidden", ""); return; }
|
|
625
|
+
const title = item.getAttribute("data-title") || item.getAttribute("title");
|
|
626
|
+
if (title) tip.textContent = title;
|
|
627
|
+
const rect = host.getBoundingClientRect();
|
|
628
|
+
const ir = item.getBoundingClientRect();
|
|
629
|
+
tip.style.setProperty("--chart-tip-inline-start", (ir.left - rect.left + ir.width / 2) + "px");
|
|
630
|
+
tip.style.setProperty("--chart-tip-block-start", (ir.top - rect.top) + "px");
|
|
631
|
+
tip.removeAttribute("hidden");
|
|
632
|
+
};
|
|
633
|
+
const hideTip = () => {
|
|
634
|
+
const tip = host.querySelector(tooltipClass);
|
|
635
|
+
if (tip) tip.setAttribute("hidden", "");
|
|
636
|
+
};
|
|
637
|
+
host.addEventListener("mouseover", showTip);
|
|
638
|
+
host.addEventListener("mouseout", (e) => { if (!e.relatedTarget || !host.contains(e.relatedTarget)) hideTip(); });
|
|
639
|
+
host.addEventListener("focusin", (e) => {
|
|
640
|
+
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
641
|
+
if (item && host.contains(item)) showTip({ target: item });
|
|
642
|
+
});
|
|
643
|
+
host.addEventListener("focusout", (e) => { if (!host.contains(e.relatedTarget)) hideTip(); });
|
|
644
|
+
host.addEventListener("click", (e) => {
|
|
645
|
+
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
646
|
+
if (!item || !host.contains(item)) return;
|
|
647
|
+
const all = items();
|
|
648
|
+
const index = all.indexOf(item);
|
|
649
|
+
if (index < 0) return;
|
|
650
|
+
host.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index, label: item.getAttribute("data-title") || item.getAttribute("title") || item.textContent.trim() } }));
|
|
651
|
+
});
|
|
652
|
+
host.addEventListener("keydown", (e) => {
|
|
653
|
+
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
654
|
+
if (!item || !host.contains(item)) return;
|
|
655
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
656
|
+
e.preventDefault();
|
|
657
|
+
const all = items();
|
|
658
|
+
const index = all.indexOf(item);
|
|
659
|
+
if (index >= 0) host.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index, label: item.getAttribute("data-title") || item.getAttribute("title") || item.textContent.trim() } }));
|
|
660
|
+
} else {
|
|
661
|
+
const all = items();
|
|
662
|
+
navKey(e, all, { wrap: false, homeEnd: true, rtl: isRtl(host), onNavigate: (i) => all.forEach((c, j) => c.setAttribute("tabindex", j === i ? "0" : "-1")) });
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
class ContourMinimap extends ContourBase {
|
|
668
|
+
static get observed() { return ["label", "viewport", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
669
|
+
static get properties() { return { label: { attribute: "label" }, viewport: { attribute: "viewport" }, src: { attribute: "src" } }; }
|
|
670
|
+
render() {
|
|
671
|
+
this.classList.add("c-minimap");
|
|
672
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
673
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Minimap");
|
|
674
|
+
wireStates(this);
|
|
675
|
+
loadRemote(this, ["label", "viewport"]);
|
|
676
|
+
if (renderStates(this, "minimap")) return;
|
|
677
|
+
const label = remoteData(this, "label") || (this._remoteData && this._remoteData.label);
|
|
678
|
+
const viewport = remoteData(this, "viewport") || (this._remoteData && (this._remoteData.viewport || this._remoteData.value));
|
|
679
|
+
if (!label && !viewport) {
|
|
680
|
+
renderEmpty(this, "minimap");
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (label) {
|
|
684
|
+
const l = this.ensure(".c-minimap__label", () => { const el = document.createElement("span"); el.className = "c-minimap__label"; return el; });
|
|
685
|
+
l.textContent = label;
|
|
686
|
+
} else {
|
|
687
|
+
const l = this.querySelector(".c-minimap__label");
|
|
688
|
+
if (l) l.remove();
|
|
689
|
+
}
|
|
690
|
+
if (viewport) {
|
|
691
|
+
const v = this.ensure(".c-minimap__viewport", () => { const el = document.createElement("div"); el.className = "c-minimap__viewport"; return el; });
|
|
692
|
+
v.textContent = viewport;
|
|
693
|
+
} else {
|
|
694
|
+
const v = this.querySelector(".c-minimap__viewport");
|
|
695
|
+
if (v) v.remove();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
enhance() {
|
|
699
|
+
if (this._wiredMinimap) return;
|
|
700
|
+
this._wiredMinimap = true;
|
|
701
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
702
|
+
let dragging = false;
|
|
703
|
+
let dragStartX = 0, dragStartY = 0;
|
|
704
|
+
this.addEventListener("pointerdown", (e) => {
|
|
705
|
+
const vp = this.querySelector(".c-minimap__viewport");
|
|
706
|
+
if (!vp || !vp.contains(e.target)) return;
|
|
707
|
+
dragging = true;
|
|
708
|
+
dragStartX = e.clientX;
|
|
709
|
+
dragStartY = e.clientY;
|
|
710
|
+
try { vp.setPointerCapture(e.pointerId); } catch (err) {}
|
|
711
|
+
});
|
|
712
|
+
this.addEventListener("pointermove", (e) => {
|
|
713
|
+
if (!dragging) return;
|
|
714
|
+
// R24-19: emit pan-delta so consumers can track the drag distance.
|
|
715
|
+
const dx = e.clientX - dragStartX;
|
|
716
|
+
const dy = e.clientY - dragStartY;
|
|
717
|
+
this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag", dx, dy }, bubbles: true, composed: true }));
|
|
718
|
+
});
|
|
719
|
+
this.addEventListener("pointerup", () => { dragging = false; });
|
|
720
|
+
this.addEventListener("keydown", (e) => {
|
|
721
|
+
let dir = null;
|
|
722
|
+
if (e.key === "ArrowUp") dir = "up";
|
|
723
|
+
else if (e.key === "ArrowDown") dir = "down";
|
|
724
|
+
else if (e.key === "ArrowLeft") dir = "left";
|
|
725
|
+
else if (e.key === "ArrowRight") dir = "right";
|
|
726
|
+
else if (e.key === "Home") dir = "home";
|
|
727
|
+
else if (e.key === "End") dir = "end";
|
|
728
|
+
if (!dir) return;
|
|
729
|
+
e.preventDefault();
|
|
730
|
+
this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: dir }, bubbles: true, composed: true }));
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
define("contour-minimap", ContourMinimap);
|
|
735
|
+
class ContourCoordinate extends ContourBase {
|
|
736
|
+
static get observed() { return ["value", "format", "locale", "precision", "live", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
737
|
+
static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" }, precision: { attribute: "precision" }, live: { attribute: "live" }, src: { attribute: "src" } }; }
|
|
738
|
+
render() {
|
|
739
|
+
this.classList.add("c-coordinate");
|
|
740
|
+
wireStates(this);
|
|
741
|
+
loadRemote(this, "value");
|
|
742
|
+
if (renderStates(this, "coordinate")) return;
|
|
743
|
+
const value = remoteData(this, "value") || (this._remoteData && (this._remoteData.value || this._remoteData.coordinate));
|
|
744
|
+
if (!value) {
|
|
745
|
+
renderEmpty(this, "coordinate");
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
const format = this.getAttribute("format") || "decimal";
|
|
749
|
+
let text = String(value);
|
|
750
|
+
if (format === "dms") {
|
|
751
|
+
// simple DMS conversion assuming decimal degrees "lat,lon"
|
|
752
|
+
const parts = String(value).split(/[,\s]+/).map(Number);
|
|
753
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
754
|
+
const prec = parseInt(this.getAttribute("precision") || "1", 10);
|
|
755
|
+
const secDigits = Number.isFinite(prec) && prec >= 0 ? prec : 1;
|
|
756
|
+
const toDMS = (d, axis) => {
|
|
757
|
+
const deg = Math.floor(Math.abs(d));
|
|
758
|
+
const min = Math.floor((Math.abs(d) - deg) * 60);
|
|
759
|
+
const sec = (((Math.abs(d) - deg) * 60) - min) * 60;
|
|
760
|
+
const hemi = axis === "lat" ? (d < 0 ? "S" : "N") : (d < 0 ? "W" : "E");
|
|
761
|
+
return deg + "°" + min + "'" + sec.toFixed(secDigits) + '"' + hemi;
|
|
762
|
+
};
|
|
763
|
+
text = toDMS(parts[0], "lat") + " " + toDMS(parts[1], "lon");
|
|
764
|
+
}
|
|
765
|
+
} else if (format === "web-mercator") {
|
|
766
|
+
const parts = String(value).split(/[,\s]+/).map(Number);
|
|
767
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
768
|
+
const x = parts[1] * 20037508.34 / 180;
|
|
769
|
+
const y = Math.log(Math.tan((90 + parts[0]) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180;
|
|
770
|
+
text = x.toFixed(2) + ", " + y.toFixed(2);
|
|
771
|
+
}
|
|
772
|
+
} else if (format === "decimal") {
|
|
773
|
+
// R24-77: honour DD precision. `precision` was only read in the DMS
|
|
774
|
+
const parts = String(value).split(/[,\s]+/).map(Number);
|
|
775
|
+
const prec = parseInt(this.getAttribute("precision") || "", 10);
|
|
776
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1]) && Number.isFinite(prec) && prec >= 0) {
|
|
777
|
+
text = parts[0].toFixed(prec) + ", " + parts[1].toFixed(prec);
|
|
778
|
+
} else {
|
|
779
|
+
text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
780
|
+
}
|
|
781
|
+
} else {
|
|
782
|
+
text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
783
|
+
}
|
|
784
|
+
const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value"; return el; });
|
|
785
|
+
// R24-77: the readout updates on every pointer move, so a live region
|
|
786
|
+
if (this.hasAttribute("live")) {
|
|
787
|
+
span.setAttribute("role", "status");
|
|
788
|
+
span.setAttribute("aria-live", "polite");
|
|
789
|
+
} else {
|
|
790
|
+
span.removeAttribute("role");
|
|
791
|
+
span.removeAttribute("aria-live");
|
|
792
|
+
}
|
|
793
|
+
span.textContent = text;
|
|
794
|
+
// copy button
|
|
795
|
+
let btn = this.querySelector(".c-coordinate__copy");
|
|
796
|
+
if (!btn) { btn = document.createElement("button"); btn.type = "button"; btn.className = "c-btn c-btn--sm c-btn--icon c-coordinate__copy"; setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-copy" /></svg>'); btn.setAttribute("aria-label", labelText(this, "copy-coordinate", "Copy coordinate")); btn.setAttribute("data-contour-label", "true"); this.appendChild(btn); }
|
|
797
|
+
btn.onclick = () => {
|
|
798
|
+
try {
|
|
799
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
800
|
+
navigator.clipboard.writeText(text).catch(() => { fallbackCopy(text); });
|
|
801
|
+
} else {
|
|
802
|
+
fallbackCopy(text);
|
|
803
|
+
}
|
|
804
|
+
} catch (e) { fallbackCopy(text); }
|
|
805
|
+
this.dispatchEvent(new CustomEvent("contour:copy", { detail: { text }, bubbles: true, composed: true }));
|
|
806
|
+
};
|
|
807
|
+
function fallbackCopy(t) {
|
|
808
|
+
try {
|
|
809
|
+
const ta = document.createElement("textarea");
|
|
810
|
+
ta.value = t;
|
|
811
|
+
ta.style.position = "fixed";
|
|
812
|
+
ta.style.opacity = "0";
|
|
813
|
+
document.body.appendChild(ta);
|
|
814
|
+
ta.select();
|
|
815
|
+
document.execCommand("copy");
|
|
816
|
+
document.body.removeChild(ta);
|
|
817
|
+
} catch (e) {}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
define("contour-coordinate", ContourCoordinate);
|
|
822
|
+
class ContourLayerPanel extends ContourBase {
|
|
823
|
+
static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "allow-rename", "allow-remove", "allow-duplicate", "allow-zoom", "allow-opacity", "allow-reorder", "allow-projection", "cache-key", "no-cache"]; }
|
|
824
|
+
static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
825
|
+
render() {
|
|
826
|
+
this.classList.add("c-layer-panel");
|
|
827
|
+
this.setAttribute("role", "group");
|
|
828
|
+
this.setAttribute("aria-label", labelText(this, "layer-panel", "Layer panel"));
|
|
829
|
+
// Reset the id minter each render: ids are a function of the item set, not
|
|
830
|
+
this._layerIdSeen = new Set();
|
|
831
|
+
wireStates(this);
|
|
832
|
+
loadRemote(this, "items");
|
|
833
|
+
if (renderStates(this, "layer-panel")) return;
|
|
834
|
+
const items = remoteData(this, "items");
|
|
835
|
+
const label = this.getAttribute("label");
|
|
836
|
+
if (label) {
|
|
837
|
+
const l = this.ensure(".c-layer-panel__label", () => { const el = document.createElement("span"); el.className = "c-layer-panel__label"; return el; });
|
|
838
|
+
l.textContent = label;
|
|
839
|
+
} else {
|
|
840
|
+
const l = this.querySelector(".c-layer-panel__label");
|
|
841
|
+
if (l) l.remove();
|
|
842
|
+
}
|
|
843
|
+
// Slotted content support: authored .c-layer-panel__item children take
|
|
844
|
+
// precedence over the JSON `items` attribute.
|
|
845
|
+
const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
|
|
846
|
+
// Preserve user-toggled visibility across re-renders (B3-09): a src
|
|
847
|
+
// reload must not re-check a layer the user un-checked.
|
|
848
|
+
const savedVisibility = new Map();
|
|
849
|
+
// R31-87: preserve the opacity the user dragged across a re-render, keyed
|
|
850
|
+
// by layer name, the same way visibility is preserved.
|
|
851
|
+
const savedOpacity = new Map();
|
|
852
|
+
this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
|
|
853
|
+
const nm = el.querySelector(".c-layer-panel__name");
|
|
854
|
+
const tg = el.querySelector(".c-layer-panel__toggle");
|
|
855
|
+
if (nm && tg) {
|
|
856
|
+
const v = tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked;
|
|
857
|
+
savedVisibility.set(nm.textContent, v);
|
|
858
|
+
}
|
|
859
|
+
const op = el.querySelector(".c-layer-panel__opacity");
|
|
860
|
+
if (nm && op) savedOpacity.set(nm.textContent, op.value);
|
|
861
|
+
});
|
|
862
|
+
let parsed = null;
|
|
863
|
+
if (authoredLayerItems.length) {
|
|
864
|
+
parsed = authoredLayerItems.map((el) => {
|
|
865
|
+
const nm = el.querySelector(".c-layer-panel__name");
|
|
866
|
+
const tg = el.querySelector(".c-layer-panel__toggle");
|
|
867
|
+
const visible = tg ? (tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked) : true;
|
|
868
|
+
const cap = el.querySelector(".c-layer-panel__caption");
|
|
869
|
+
return { name: nm ? nm.textContent : "", visible, caption: cap ? cap.textContent : (el.dataset.caption || undefined) };
|
|
870
|
+
});
|
|
871
|
+
authoredLayerItems.forEach((el) => el.remove());
|
|
872
|
+
} else if (items) {
|
|
873
|
+
try {
|
|
874
|
+
parsed = JSON.parse(items);
|
|
875
|
+
Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
|
|
876
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
877
|
+
}
|
|
878
|
+
if (parsed) { parsed.forEach((it) => {
|
|
879
|
+
const name = typeof it === "string" ? it : (it.name || it.label || "");
|
|
880
|
+
const caption = (typeof it === "object" && it) ? (it.caption || it.subtitle || "") : "";
|
|
881
|
+
// Mint a stable per-item id (MAP-3): the reorder detail and every
|
|
882
|
+
// R31-86: prefer an explicit id; otherwise reuse a previously minted
|
|
883
|
+
// id for this name (so a rename + re-render does not change the
|
|
884
|
+
// layer's identity), else slug the name. The map persists across
|
|
885
|
+
// renders; the per-render Set only de-duplicates within one render.
|
|
886
|
+
if (this._layerIdByName == null) this._layerIdByName = new Map();
|
|
887
|
+
const explicitId = (typeof it === "object" && it && it.id) ? String(it.id) : "";
|
|
888
|
+
let layerId;
|
|
889
|
+
if (explicitId) {
|
|
890
|
+
layerId = explicitId;
|
|
891
|
+
} else if (this._layerIdByName.has(name)) {
|
|
892
|
+
layerId = this._layerIdByName.get(name);
|
|
893
|
+
} else {
|
|
894
|
+
const slug = name ? name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "";
|
|
895
|
+
layerId = slug || "layer";
|
|
896
|
+
this._layerIdByName.set(name, layerId);
|
|
897
|
+
}
|
|
898
|
+
if (this._layerIdSeen == null) this._layerIdSeen = new Set();
|
|
899
|
+
if (this._layerIdSeen.has(layerId)) {
|
|
900
|
+
let n = 2;
|
|
901
|
+
while (this._layerIdSeen.has(layerId + "-" + n)) n++;
|
|
902
|
+
layerId = layerId + "-" + n;
|
|
903
|
+
}
|
|
904
|
+
this._layerIdSeen.add(layerId);
|
|
905
|
+
const item = document.createElement("div");
|
|
906
|
+
item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
|
|
907
|
+
item.dataset.layerId = layerId;
|
|
908
|
+
// Drag handle: focusable grip for keyboard reorder (CDS-049).
|
|
909
|
+
// R31-89: gated by allow-reorder (default on), like the other
|
|
910
|
+
// per-layer controls, so a consumer can drop it.
|
|
911
|
+
if (this.getAttribute("allow-reorder") !== "false") {
|
|
912
|
+
const drag = document.createElement("button");
|
|
913
|
+
drag.type = "button";
|
|
914
|
+
drag.className = "c-drag-handle--dots";
|
|
915
|
+
drag.setAttribute("aria-label", labelText(this, "reorder", "Reorder") + " " + (name || labelText(this, "layer", "layer")));
|
|
916
|
+
drag.setAttribute("tabindex", "0");
|
|
917
|
+
item.appendChild(drag);
|
|
918
|
+
}
|
|
919
|
+
const toggle = document.createElement("button");
|
|
920
|
+
toggle.type = "button";
|
|
921
|
+
toggle.className = "c-layer-panel__toggle";
|
|
922
|
+
toggle.setAttribute("part", "visibility-toggle");
|
|
923
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle") + " " + (name || labelText(this, "layer", "layer")));
|
|
924
|
+
const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
|
|
925
|
+
toggle.setAttribute("aria-pressed", String(!!isVisible));
|
|
926
|
+
toggle.checked = !!isVisible;
|
|
927
|
+
setHTML(toggle, isVisible ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-check" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
928
|
+
item.appendChild(toggle);
|
|
929
|
+
const nm = document.createElement("span");
|
|
930
|
+
nm.className = "c-layer-panel__name";
|
|
931
|
+
nm.textContent = name;
|
|
932
|
+
item.appendChild(nm);
|
|
933
|
+
if (caption) {
|
|
934
|
+
const cap = document.createElement("span");
|
|
935
|
+
cap.className = "c-layer-panel__caption";
|
|
936
|
+
cap.textContent = caption;
|
|
937
|
+
item.appendChild(cap);
|
|
938
|
+
}
|
|
939
|
+
// R31-89: opacity is gated by allow-opacity (default on).
|
|
940
|
+
if (this.getAttribute("allow-opacity") !== "false") {
|
|
941
|
+
const opacity = document.createElement("input");
|
|
942
|
+
opacity.type = "range";
|
|
943
|
+
opacity.className = "c-layer-panel__opacity";
|
|
944
|
+
opacity.min = "0";
|
|
945
|
+
opacity.max = "100";
|
|
946
|
+
opacity.setAttribute("aria-label", labelText(this, "opacity-of", "Opacity of") + " " + (name || "layer"));
|
|
947
|
+
// R31-87: a re-render restores the value the user dragged, not the
|
|
948
|
+
// authored default.
|
|
949
|
+
opacity.value = savedOpacity.has(name) ? savedOpacity.get(name) : ((typeof it === "object" && it.opacity != null) ? it.opacity : "100");
|
|
950
|
+
item.appendChild(opacity);
|
|
951
|
+
}
|
|
952
|
+
// rename input (hidden by default, toggled via button)
|
|
953
|
+
if (this.getAttribute("allow-rename") !== "false") {
|
|
954
|
+
const renameBtn = document.createElement("button");
|
|
955
|
+
renameBtn.type = "button";
|
|
956
|
+
renameBtn.className = "c-btn c-btn--icon c-btn--ghost c-btn--sm c-layer-panel__rename";
|
|
957
|
+
// R31-144: icon-only rename; the name stays on aria-label.
|
|
958
|
+
setHTML(renameBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-pen" /></svg>');
|
|
959
|
+
renameBtn.setAttribute("aria-label", labelText(this, "rename", "Rename") + " " + (name || "layer"));
|
|
960
|
+
item.appendChild(renameBtn);
|
|
961
|
+
}
|
|
962
|
+
if (this.getAttribute("allow-duplicate") !== "false") {
|
|
963
|
+
const dupBtn = document.createElement("button");
|
|
964
|
+
dupBtn.type = "button";
|
|
965
|
+
dupBtn.className = "c-btn c-btn--icon c-btn--ghost c-btn--sm c-layer-panel__duplicate";
|
|
966
|
+
// R31-144: icon-only duplicate.
|
|
967
|
+
setHTML(dupBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-copy" /></svg>');
|
|
968
|
+
dupBtn.setAttribute("aria-label", labelText(this, "duplicate", "Duplicate") + " " + (name || "layer"));
|
|
969
|
+
item.appendChild(dupBtn);
|
|
970
|
+
}
|
|
971
|
+
if (this.getAttribute("allow-zoom") !== "false") {
|
|
972
|
+
const zoomBtn = document.createElement("button");
|
|
973
|
+
zoomBtn.type = "button";
|
|
974
|
+
zoomBtn.className = "c-layer-panel__zoom";
|
|
975
|
+
zoomBtn.textContent = labelText(this, "zoom", "Zoom");
|
|
976
|
+
zoomBtn.setAttribute("aria-label", labelText(this, "zoom-to", "Zoom to") + " " + (name || "layer"));
|
|
977
|
+
item.appendChild(zoomBtn);
|
|
978
|
+
}
|
|
979
|
+
if (this.getAttribute("allow-remove") !== "false") {
|
|
980
|
+
const removeBtn = document.createElement("button");
|
|
981
|
+
removeBtn.type = "button";
|
|
982
|
+
removeBtn.className = "c-layer-panel__remove";
|
|
983
|
+
setHTML(removeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
984
|
+
removeBtn.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + (name || "layer"));
|
|
985
|
+
item.appendChild(removeBtn);
|
|
986
|
+
}
|
|
987
|
+
// R31-89: the projection selector is opt-in (allow-projection),
|
|
988
|
+
// because most maps do not reproject a single layer. Render it only
|
|
989
|
+
// when the author asks for it.
|
|
990
|
+
if (this.hasAttribute("allow-projection") && this.getAttribute("allow-projection") !== "false") {
|
|
991
|
+
const projSel = document.createElement("select");
|
|
992
|
+
projSel.className = "c-select c-layer-panel__projection";
|
|
993
|
+
projSel.setAttribute("aria-label", labelText(this, "projection-of", "Projection of") + " " + (name || labelText(this, "layer", "layer")));
|
|
994
|
+
["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
|
|
995
|
+
item.appendChild(projSel);
|
|
996
|
+
}
|
|
997
|
+
this.appendChild(item);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
if (!parsed && !authoredLayerItems.length && !items) {
|
|
1001
|
+
Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
|
|
1002
|
+
renderEmpty(this, "layer-panel");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
enhance() {
|
|
1006
|
+
if (this._wiredLayerPanel) return;
|
|
1007
|
+
this._wiredLayerPanel = true;
|
|
1008
|
+
// The panel's two controls (visibility toggle, opacity range) are rebuilt
|
|
1009
|
+
const idOf = (item) => (item && item.dataset && item.dataset.layerId) || "";
|
|
1010
|
+
this.addEventListener("change", (e) => {
|
|
1011
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
|
|
1012
|
+
if (!item || !this.contains(item)) return;
|
|
1013
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
1014
|
+
const layerId = idOf(item);
|
|
1015
|
+
if (e.target.classList.contains("c-layer-panel__toggle")) {
|
|
1016
|
+
const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
|
|
1017
|
+
e.target.checked = now;
|
|
1018
|
+
e.target.setAttribute("aria-pressed", String(now));
|
|
1019
|
+
setHTML(e.target, now ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-check" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
1020
|
+
this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
1021
|
+
} else if (e.target.classList.contains("c-layer-panel__opacity")) {
|
|
1022
|
+
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { layerId, name, opacity: Number(e.target.value) } }));
|
|
1023
|
+
} else if (e.target.classList.contains("c-layer-panel__projection")) {
|
|
1024
|
+
this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { layerId, name, projection: e.target.value } }));
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
// R31-87: opacity is live — `input` fires as the slider drags, so the
|
|
1028
|
+
// engine follows the thumb, not only the released value (`change`).
|
|
1029
|
+
this.addEventListener("input", (e) => {
|
|
1030
|
+
const op = e.target;
|
|
1031
|
+
if (!op || !op.classList || !op.classList.contains("c-layer-panel__opacity")) return;
|
|
1032
|
+
const item = op.closest(".c-layer-panel__item");
|
|
1033
|
+
if (!item || !this.contains(item)) return;
|
|
1034
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
1035
|
+
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { layerId: idOf(item), name, opacity: Number(op.value) } }));
|
|
1036
|
+
});
|
|
1037
|
+
this.addEventListener("click", (e) => {
|
|
1038
|
+
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
1039
|
+
if (!btn || !this.contains(btn)) return;
|
|
1040
|
+
const item = btn.closest(".c-layer-panel__item");
|
|
1041
|
+
if (btn.classList.contains("c-layer-panel__toggle")) {
|
|
1042
|
+
if (!item) return;
|
|
1043
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
1044
|
+
const layerId = idOf(item);
|
|
1045
|
+
const now = btn.getAttribute("aria-pressed") !== "true";
|
|
1046
|
+
btn.setAttribute("aria-pressed", String(now));
|
|
1047
|
+
btn.checked = now;
|
|
1048
|
+
setHTML(btn, now ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-check" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
1049
|
+
this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (!item) return;
|
|
1053
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
1054
|
+
const layerId = idOf(item);
|
|
1055
|
+
if (btn.classList.contains("c-layer-panel__rename")) {
|
|
1056
|
+
const nm = item.querySelector(".c-layer-panel__name");
|
|
1057
|
+
if (nm) {
|
|
1058
|
+
const input = document.createElement("input");
|
|
1059
|
+
input.type = "text";
|
|
1060
|
+
input.className = "c-input c-layer-panel__rename-input";
|
|
1061
|
+
input.value = name;
|
|
1062
|
+
input.setAttribute("aria-label", labelText(this, "rename-layer", "Rename layer"));
|
|
1063
|
+
nm.replaceWith(input);
|
|
1064
|
+
input.focus();
|
|
1065
|
+
input.select();
|
|
1066
|
+
let committed = false;
|
|
1067
|
+
const commit = () => {
|
|
1068
|
+
// R24-09: a committed flag set BEFORE replaceWith. The blur
|
|
1069
|
+
if (committed) return;
|
|
1070
|
+
if (!input.isConnected) return;
|
|
1071
|
+
committed = true;
|
|
1072
|
+
const trimmed = (input.value || "").trim();
|
|
1073
|
+
const span = document.createElement("span");
|
|
1074
|
+
span.className = "c-layer-panel__name";
|
|
1075
|
+
span.textContent = trimmed || name;
|
|
1076
|
+
input.replaceWith(span);
|
|
1077
|
+
if (trimmed && trimmed !== name) {
|
|
1078
|
+
// R31-86: keep the layer's id across the rename so a re-render
|
|
1079
|
+
// does not mint a new one from the new name.
|
|
1080
|
+
if (this._layerIdByName == null) this._layerIdByName = new Map();
|
|
1081
|
+
this._layerIdByName.set(trimmed, layerId);
|
|
1082
|
+
this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { layerId, name, newName: trimmed } }));
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
input.addEventListener("keydown", (ev) => { if (ev.key === "Enter") { ev.preventDefault(); commit(); } else if (ev.key === "Escape") { ev.preventDefault(); input.value = name; commit(); } });
|
|
1086
|
+
input.addEventListener("blur", commit, { once: true });
|
|
1087
|
+
}
|
|
1088
|
+
} else if (btn.classList.contains("c-layer-panel__duplicate")) {
|
|
1089
|
+
this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
1090
|
+
} else if (btn.classList.contains("c-layer-panel__zoom")) {
|
|
1091
|
+
this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
1092
|
+
} else if (btn.classList.contains("c-layer-panel__remove")) {
|
|
1093
|
+
this.dispatchEvent(new CustomEvent("contour:layer-remove", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
this.addEventListener("keydown", (e) => {
|
|
1097
|
+
if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
|
|
1098
|
+
e.preventDefault();
|
|
1099
|
+
e.target.click();
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
|
|
1103
|
+
if (!item || !this.contains(item)) return;
|
|
1104
|
+
const isDrag = e.target && e.target.classList && e.target.classList.contains("c-drag-handle--dots");
|
|
1105
|
+
// Drag handle: ArrowUp/ArrowDown reorder without Alt modifier (CDS-049).
|
|
1106
|
+
// Item-level: Alt+ArrowUp/ArrowDown as an alternative.
|
|
1107
|
+
if ((isDrag && (e.key === "ArrowUp" || e.key === "ArrowDown")) || (e.altKey && (e.key === "ArrowUp" || e.key === "ArrowDown"))) {
|
|
1108
|
+
e.preventDefault();
|
|
1109
|
+
const items = Array.from(this.querySelectorAll(".c-layer-panel__item"));
|
|
1110
|
+
const idx = items.indexOf(item);
|
|
1111
|
+
if (idx < 0) return;
|
|
1112
|
+
const dir = e.key === "ArrowUp" ? -1 : 1;
|
|
1113
|
+
const newIdx = idx + dir;
|
|
1114
|
+
if (newIdx < 0 || newIdx >= items.length) return;
|
|
1115
|
+
item.classList.add("c-layer-panel__item--dragging");
|
|
1116
|
+
if (dir < 0) this.insertBefore(item, items[newIdx]);
|
|
1117
|
+
else this.insertBefore(items[newIdx], item);
|
|
1118
|
+
(isDrag ? e.target : item).focus();
|
|
1119
|
+
setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
|
|
1120
|
+
// A stable per-layer id, not the display name: two layers can share
|
|
1121
|
+
const layerIds = Array.from(this.querySelectorAll(".c-layer-panel__item")).map((el, i) => el.dataset.layerId || el.getAttribute("data-layer-id") || String(i));
|
|
1122
|
+
this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
define("contour-layer-panel", ContourLayerPanel);
|
|
1128
|
+
class ContourTimeSlider extends ContourBase {
|
|
1129
|
+
static get observed() { return ["label", "value", "min", "max", "loop", "speed", "speeds", "show-loop", "loop-label", "current-time", "time-format", "is-playing", "play-label", "pause-label", "time-label", "speed-label"]; }
|
|
1130
|
+
static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, distance: { attribute: "distance" }, resolution: { attribute: "resolution" }, latitude: { attribute: "latitude" }, src: { attribute: "src" }, loop: { attribute: "loop", type: Boolean }, speed: { attribute: "speed" }, speeds: { attribute: "speeds" }, showLoop: { attribute: "show-loop", type: Boolean }, loopLabel: { attribute: "loop-label" }, currentTime: { attribute: "current-time" }, timeFormat: { attribute: "time-format" }, isPlaying: { attribute: "is-playing", type: Boolean }, playLabel: { attribute: "play-label" }, pauseLabel: { attribute: "pause-label" }, timeLabel: { attribute: "time-label" }, speedLabel: { attribute: "speed-label" } }; }
|
|
1131
|
+
render() {
|
|
1132
|
+
this.classList.add("c-time-slider");
|
|
1133
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1134
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Time slider");
|
|
1135
|
+
const play = this.ensure(".c-time-slider__play", () => {
|
|
1136
|
+
const el = document.createElement("button");
|
|
1137
|
+
el.className = "c-time-slider__play";
|
|
1138
|
+
el.type = "button";
|
|
1139
|
+
el.setAttribute("aria-label", this.getAttribute("play-label") || "Play");
|
|
1140
|
+
el.setAttribute("data-state", "play");
|
|
1141
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1142
|
+
svg.setAttribute("aria-hidden", "true");
|
|
1143
|
+
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
1144
|
+
use.setAttribute("href", "#i-play");
|
|
1145
|
+
svg.appendChild(use);
|
|
1146
|
+
el.appendChild(svg);
|
|
1147
|
+
return el;
|
|
1148
|
+
});
|
|
1149
|
+
const track = this.ensure(".c-time-slider__track", () => { const el = document.createElement("input"); el.className = "c-time-slider__track"; el.type = "range"; el.min = "0"; el.max = "100"; el.setAttribute("part", "input"); el.setAttribute("aria-label", this.getAttribute("time-label") || "Time"); return el; });
|
|
1150
|
+
// min/max are attributes, not factory constants (R20 T-30): the guide's
|
|
1151
|
+
// own 17d snippet passes them and they used to be ignored.
|
|
1152
|
+
track.min = this.getAttribute("min") || "0";
|
|
1153
|
+
track.max = this.getAttribute("max") || "100";
|
|
1154
|
+
const _attrVal = this.getAttribute("value") || "0";
|
|
1155
|
+
if (this._timeSliderAttrLast !== _attrVal) {
|
|
1156
|
+
track.value = _attrVal;
|
|
1157
|
+
this._timeSliderAttrLast = _attrVal;
|
|
1158
|
+
}
|
|
1159
|
+
track.setAttribute("aria-label", this.getAttribute("label") || this.getAttribute("time-label") || "Time");
|
|
1160
|
+
const time = this.ensure(".c-time-slider__time", () => { const el = document.createElement("span"); el.className = "c-time-slider__time"; return el; });
|
|
1161
|
+
const ct = this.getAttribute("current-time");
|
|
1162
|
+
const timeFormat = this.getAttribute("time-format");
|
|
1163
|
+
// R24-77: honour `time-format` through the shared Intl formatter instead
|
|
1164
|
+
if (ct) { time.textContent = ct; track.setAttribute("aria-valuetext", ct); }
|
|
1165
|
+
else if (timeFormat) { time.textContent = formatValue(String(track.value), timeFormat); track.removeAttribute("aria-valuetext"); }
|
|
1166
|
+
else { time.textContent = String(track.value); track.removeAttribute("aria-valuetext"); }
|
|
1167
|
+
// R24-77: a <datalist> gives the range real tick marks (the platform
|
|
1168
|
+
const ticks = this.ensure("datalist", () => document.createElement("datalist"));
|
|
1169
|
+
if (!ticks.id) ticks.id = contourId("time-slider-ticks");
|
|
1170
|
+
setHTML(ticks, "");
|
|
1171
|
+
const tMin = Number(track.min) || 0;
|
|
1172
|
+
const tMax = Number(track.max) || 100;
|
|
1173
|
+
for (let i = 0; i < 5; i++) {
|
|
1174
|
+
const opt = document.createElement("option");
|
|
1175
|
+
opt.value = String(Math.round(tMin + (tMax - tMin) * (i / 4)));
|
|
1176
|
+
ticks.appendChild(opt);
|
|
1177
|
+
}
|
|
1178
|
+
track.setAttribute("list", ticks.id);
|
|
1179
|
+
if (ticks.parentNode !== this) this.appendChild(ticks);
|
|
1180
|
+
// speed selector
|
|
1181
|
+
let speeds = null;
|
|
1182
|
+
const speedsAttr = this.getAttribute("speeds");
|
|
1183
|
+
if (speedsAttr) { try { speeds = JSON.parse(speedsAttr); } catch (e) { speeds = null; } }
|
|
1184
|
+
const speedSel = this.ensure(".c-time-slider__speed", () => { const el = document.createElement("select"); el.className = "c-select c-time-slider__speed"; el.setAttribute("aria-label", this.getAttribute("speed-label") || "Speed"); return el; });
|
|
1185
|
+
setHTML(speedSel, "");
|
|
1186
|
+
const speedList = Array.isArray(speeds) ? speeds : [0.5, 1, 2, 5, 10];
|
|
1187
|
+
speedList.forEach((sp) => {
|
|
1188
|
+
const opt = document.createElement("option");
|
|
1189
|
+
opt.value = String(sp);
|
|
1190
|
+
opt.textContent = String(sp);
|
|
1191
|
+
if (String(sp) === (this.getAttribute("speed") || "")) opt.selected = true;
|
|
1192
|
+
speedSel.appendChild(opt);
|
|
1193
|
+
});
|
|
1194
|
+
const speedAttr = this.getAttribute("speed");
|
|
1195
|
+
if (speedAttr) speedSel.value = speedAttr;
|
|
1196
|
+
// loop toggle
|
|
1197
|
+
const showLoop = this.hasAttribute("show-loop");
|
|
1198
|
+
if (showLoop) {
|
|
1199
|
+
const loopBtn = this.ensure(".c-time-slider__loop", () => { const el = document.createElement("button"); el.className = "c-time-slider__loop"; el.type = "button"; el.setAttribute("aria-label", this.getAttribute("loop-label") || "Loop"); return el; });
|
|
1200
|
+
loopBtn.setAttribute("aria-pressed", this.hasAttribute("loop") ? "true" : "false");
|
|
1201
|
+
// R31-137: icon-only loop toggle; the name stays on aria-label.
|
|
1202
|
+
setHTML(loopBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-refresh" /></svg>');
|
|
1203
|
+
} else {
|
|
1204
|
+
const lb = this.querySelector(".c-time-slider__loop");
|
|
1205
|
+
if (lb) lb.remove();
|
|
1206
|
+
}
|
|
1207
|
+
// is-playing reflects on play button, both directions (R20 T-30).
|
|
1208
|
+
const playing = this.hasAttribute("is-playing");
|
|
1209
|
+
play.setAttribute("data-state", playing ? "pause" : "play");
|
|
1210
|
+
play.setAttribute("aria-label", playing ? (this.getAttribute("pause-label") || "Pause") : (this.getAttribute("play-label") || "Play"));
|
|
1211
|
+
const use = play.querySelector("use");
|
|
1212
|
+
if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
|
|
1213
|
+
}
|
|
1214
|
+
enhance() {
|
|
1215
|
+
// Playback reconciles with the is-playing attribute on EVERY render
|
|
1216
|
+
if (this._timeSliderReconcile) this._timeSliderReconcile();
|
|
1217
|
+
if (this._wiredTimeSlider) return;
|
|
1218
|
+
this._wiredTimeSlider = true;
|
|
1219
|
+
// Play advances the track one step per cadence and announces each move
|
|
1220
|
+
let timer = undefined;
|
|
1221
|
+
const stop = () => { if (timer !== undefined) { clearInterval(timer); timer = undefined; } };
|
|
1222
|
+
const syncReadout = () => {
|
|
1223
|
+
const track = this.querySelector(".c-time-slider__track");
|
|
1224
|
+
if (!track) return;
|
|
1225
|
+
const time = this.querySelector(".c-time-slider__time");
|
|
1226
|
+
const ct = this.getAttribute("current-time");
|
|
1227
|
+
const tf = this.getAttribute("time-format");
|
|
1228
|
+
if (time) time.textContent = ct ? ct : (tf ? formatValue(String(track.value), tf) : String(track.value));
|
|
1229
|
+
if (ct) track.setAttribute("aria-valuetext", ct);
|
|
1230
|
+
else track.removeAttribute("aria-valuetext");
|
|
1231
|
+
};
|
|
1232
|
+
const step = () => {
|
|
1233
|
+
const track = this.querySelector(".c-time-slider__track");
|
|
1234
|
+
if (!track) { stop(); return; }
|
|
1235
|
+
const max = Number(track.max) || 100;
|
|
1236
|
+
const min = Number(track.min) || 0;
|
|
1237
|
+
const loop = this.hasAttribute("loop");
|
|
1238
|
+
let next = (Number(track.value) || 0) + 1;
|
|
1239
|
+
if (next > max) next = loop ? min : max;
|
|
1240
|
+
track.value = String(next);
|
|
1241
|
+
// The playhead writes back so a consumer reading `value` sees it —
|
|
1242
|
+
const speedSel = this.querySelector(".c-time-slider__speed");
|
|
1243
|
+
const interacting = this._timeSliderScrubbing || (speedSel && document.activeElement === speedSel);
|
|
1244
|
+
if (!interacting) this.setAttribute("value", String(next));
|
|
1245
|
+
syncReadout();
|
|
1246
|
+
this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: String(next) }, bubbles: true, composed: true }));
|
|
1247
|
+
if (!loop && next >= max) {
|
|
1248
|
+
stop();
|
|
1249
|
+
this.removeAttribute("is-playing");
|
|
1250
|
+
this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
const start = () => {
|
|
1254
|
+
stop();
|
|
1255
|
+
const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
|
|
1256
|
+
timer = setInterval(step, Math.max(100, 1000 / speed));
|
|
1257
|
+
};
|
|
1258
|
+
this._timeSliderReconcile = () => {
|
|
1259
|
+
const want = this.hasAttribute("is-playing");
|
|
1260
|
+
if (want && timer === undefined) {
|
|
1261
|
+
start();
|
|
1262
|
+
this.dispatchEvent(new CustomEvent("contour:play", { bubbles: true, composed: true }));
|
|
1263
|
+
} else if (!want && timer !== undefined) {
|
|
1264
|
+
stop();
|
|
1265
|
+
this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
this.addEventListener("click", (e) => {
|
|
1269
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-time-slider__play") : null;
|
|
1270
|
+
if (btn) {
|
|
1271
|
+
// The attribute is the source of truth: toggling it re-renders the
|
|
1272
|
+
// icon and the reconciler starts/stops the timer and emits.
|
|
1273
|
+
this.toggleAttribute("is-playing", !this.hasAttribute("is-playing"));
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
const loopBtn = e.target && e.target.closest ? e.target.closest(".c-time-slider__loop") : null;
|
|
1277
|
+
if (loopBtn) {
|
|
1278
|
+
const next = loopBtn.getAttribute("aria-pressed") !== "true";
|
|
1279
|
+
loopBtn.setAttribute("aria-pressed", String(next));
|
|
1280
|
+
this.toggleAttribute("loop", next);
|
|
1281
|
+
this.dispatchEvent(new CustomEvent("contour:loop-change", { detail: { loop: next }, bubbles: true, composed: true }));
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
// Manual scrubbing is a first-class input (R20 T-30): it emits the same
|
|
1285
|
+
this.addEventListener("pointerdown", (e) => {
|
|
1286
|
+
if (e.target && e.target.closest && e.target.closest(".c-time-slider__track")) this._timeSliderScrubbing = true;
|
|
1287
|
+
}, { passive: true });
|
|
1288
|
+
const endScrub = () => { this._timeSliderScrubbing = false; };
|
|
1289
|
+
this.addEventListener("pointerup", endScrub, { passive: true });
|
|
1290
|
+
this.addEventListener("pointercancel", endScrub, { passive: true });
|
|
1291
|
+
this.addEventListener("input", (e) => {
|
|
1292
|
+
const track = e.target && e.target.closest ? e.target.closest(".c-time-slider__track") : null;
|
|
1293
|
+
if (!track) return;
|
|
1294
|
+
if (!this._timeSliderScrubbing) this.setAttribute("value", track.value);
|
|
1295
|
+
syncReadout();
|
|
1296
|
+
this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: track.value }, bubbles: true, composed: true }));
|
|
1297
|
+
});
|
|
1298
|
+
this.addEventListener("change", (e) => {
|
|
1299
|
+
const sel = e.target && e.target.closest ? e.target.closest(".c-time-slider__speed") : null;
|
|
1300
|
+
if (sel) {
|
|
1301
|
+
const speed = Number(sel.value);
|
|
1302
|
+
this.setAttribute("speed", String(speed));
|
|
1303
|
+
// A speed change mid-play restarts the interval at the new cadence.
|
|
1304
|
+
if (timer !== undefined) start();
|
|
1305
|
+
this.dispatchEvent(new CustomEvent("contour:speed-change", { detail: { speed }, bubbles: true, composed: true }));
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
const track = e.target && e.target.closest ? e.target.closest(".c-time-slider__track") : null;
|
|
1309
|
+
if (track) {
|
|
1310
|
+
this.setAttribute("value", track.value);
|
|
1311
|
+
syncReadout();
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
onDispose(this, stop);
|
|
1315
|
+
this._timeSliderReconcile();
|
|
1316
|
+
}
|
|
1317
|
+
disconnectedCallback() {
|
|
1318
|
+
super.disconnectedCallback();
|
|
1319
|
+
this._wiredTimeSlider = false;
|
|
1320
|
+
// Drop the stale closure too: a reconnect re-wires, and the old
|
|
1321
|
+
// reconciler would start a second timer over the new one.
|
|
1322
|
+
this._timeSliderReconcile = null;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
define("contour-time-slider", ContourTimeSlider);
|
|
1326
|
+
class ContourHexbin extends ContourBase {
|
|
1327
|
+
static get observed() { return ["label", "cells", "width", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1328
|
+
static get properties() { return { label: { attribute: "label" }, cells: { attribute: "cells" }, width: { attribute: "width" }, src: { attribute: "src" } }; }
|
|
1329
|
+
render() {
|
|
1330
|
+
this.classList.add("c-hexbin");
|
|
1331
|
+
// Cells are focusable marks; role=img makes them presentational.
|
|
1332
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1333
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Hexbin");
|
|
1334
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
1335
|
+
if (label) {
|
|
1336
|
+
const l = this.ensure(".c-hexbin__label", () => { const el = document.createElement("span"); el.className = "c-hexbin__label"; return el; });
|
|
1337
|
+
l.textContent = label;
|
|
1338
|
+
} else {
|
|
1339
|
+
const l = this.querySelector(".c-hexbin__label");
|
|
1340
|
+
if (l) l.remove();
|
|
1341
|
+
}
|
|
1342
|
+
wireStates(this);
|
|
1343
|
+
loadRemote(this, "cells");
|
|
1344
|
+
if (renderStates(this, "hexbin")) return;
|
|
1345
|
+
const cells = remoteData(this, "cells");
|
|
1346
|
+
const effectiveCells = cells || (this._remoteData && this._remoteData.cells ? JSON.stringify(this._remoteData.cells) : null);
|
|
1347
|
+
// Slotted content support: authored .c-hexbin__cell children take
|
|
1348
|
+
// precedence over the JSON `cells` attribute.
|
|
1349
|
+
const authoredCells = Array.from(this.querySelectorAll(":scope > .c-hexbin__cell"));
|
|
1350
|
+
const tip = this.ensure(".c-hexbin__tooltip", () => { const el = document.createElement("div"); el.className = "c-hexbin__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
1351
|
+
tip.setAttribute("hidden", "");
|
|
1352
|
+
// Container width: author-supplied `width` attribute wins, otherwise the
|
|
1353
|
+
// component sizes itself to its grid (no hardcoded 16rem).
|
|
1354
|
+
const width = this.getAttribute("width");
|
|
1355
|
+
if (width) this.style.inlineSize = width;
|
|
1356
|
+
else this.style.removeProperty("inline-size");
|
|
1357
|
+
if (authoredCells.length) {
|
|
1358
|
+
// R28-33 (CONS-08): authored cells keep the styles the author painted
|
|
1359
|
+
const cols = Math.ceil(Math.sqrt(authoredCells.length || 1));
|
|
1360
|
+
// minmax(0, 1fr), not 1fr: a bare 1fr is minmax(auto, 1fr), so a cell's
|
|
1361
|
+
// text min-content floors the track and the grid overflows its host on
|
|
1362
|
+
// a narrow viewport. Cells clip their own text (clip-path), so the track
|
|
1363
|
+
// is free to shrink to the container.
|
|
1364
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", minmax(0, 1fr))";
|
|
1365
|
+
authoredCells.forEach((el, i) => el.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
1366
|
+
} else {
|
|
1367
|
+
let parsed = null;
|
|
1368
|
+
if (effectiveCells) { try { parsed = JSON.parse(effectiveCells); } catch (e) { parsed = null; } }
|
|
1369
|
+
if (Array.isArray(parsed)) {
|
|
1370
|
+
try {
|
|
1371
|
+
Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
|
|
1372
|
+
const cols = Math.ceil(Math.sqrt(parsed.length || 1));
|
|
1373
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", minmax(0, 1fr))";
|
|
1374
|
+
// R28-33 (CONS-08): restore the value→color ramp. Normalise each
|
|
1375
|
+
const nums = parsed.map((c) => Number(typeof c === "object" && c !== null ? c.value : c)).filter((n) => Number.isFinite(n));
|
|
1376
|
+
const min = nums.length ? Math.min(...nums) : 0;
|
|
1377
|
+
const max = nums.length ? Math.max(...nums) : 0;
|
|
1378
|
+
const span = max - min;
|
|
1379
|
+
parsed.forEach((c, i) => {
|
|
1380
|
+
const cell = document.createElement("div");
|
|
1381
|
+
cell.className = "c-hexbin__cell";
|
|
1382
|
+
cell.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
1383
|
+
const val = (typeof c === "object" && c !== null && c.value != null) ? c.value : c;
|
|
1384
|
+
if (val != null && val !== "") { cell.textContent = val; cell.setAttribute("data-title", String(val)); }
|
|
1385
|
+
const n = Number(val);
|
|
1386
|
+
if (Number.isFinite(n)) {
|
|
1387
|
+
const t = span > 0 ? (n - min) / span : 1;
|
|
1388
|
+
const pct = Math.round(20 + t * 60);
|
|
1389
|
+
cell.style.background = "color-mix(in oklab, var(--color-primary) " + pct + "%, var(--color-surface-2))";
|
|
1390
|
+
}
|
|
1391
|
+
this.appendChild(cell);
|
|
1392
|
+
});
|
|
1393
|
+
// Legend: a value→color ramp so the hexbin encodes value, not just
|
|
1394
|
+
// hue. Low = surface-2 tinted, high = primary tinted.
|
|
1395
|
+
if (span > 0 && nums.length) {
|
|
1396
|
+
const legend = this.ensure(".c-hexbin__legend", () => { const el = document.createElement("div"); el.className = "c-hexbin__legend"; return el; });
|
|
1397
|
+
legend.textContent = "";
|
|
1398
|
+
const lo = document.createElement("div"); lo.className = "c-hexbin__legend-swatch"; lo.style.background = "color-mix(in oklab, var(--color-primary) 20%, var(--color-surface-2))"; lo.setAttribute("title", String(min));
|
|
1399
|
+
const hi = document.createElement("div"); hi.className = "c-hexbin__legend-swatch"; hi.style.background = "color-mix(in oklab, var(--color-primary) 80%, var(--color-surface-2))"; hi.setAttribute("title", String(max));
|
|
1400
|
+
const loLab = document.createElement("span"); loLab.className = "c-hexbin__legend-label"; loLab.textContent = String(min);
|
|
1401
|
+
const hiLab = document.createElement("span"); hiLab.className = "c-hexbin__legend-label"; hiLab.textContent = String(max);
|
|
1402
|
+
legend.appendChild(lo); legend.appendChild(loLab); legend.appendChild(hi); legend.appendChild(hiLab);
|
|
1403
|
+
}
|
|
1404
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1405
|
+
} else {
|
|
1406
|
+
Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
|
|
1407
|
+
renderEmpty(this, "hexbin");
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
enhance() {
|
|
1412
|
+
if (this._wiredHexbin) return;
|
|
1413
|
+
this._wiredHexbin = true;
|
|
1414
|
+
wireMapItems(this, ".c-hexbin__cell", ".c-hexbin__tooltip");
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
define("contour-hexbin", ContourHexbin);
|
|
1418
|
+
class ContourFlowMap extends ContourBase {
|
|
1419
|
+
static get observed() { return ["label", "nodes", "flows", "edges", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1420
|
+
static get properties() { return { label: { attribute: "label" }, nodes: { attribute: "nodes" }, flows: { attribute: "flows" }, edges: { attribute: "edges" }, src: { attribute: "src" } }; }
|
|
1421
|
+
render() {
|
|
1422
|
+
this.classList.add("c-flow-map");
|
|
1423
|
+
// Nodes are focusable marks; role=img makes them presentational.
|
|
1424
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1425
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Flow map");
|
|
1426
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
1427
|
+
if (label) {
|
|
1428
|
+
const l = this.ensure(".c-flow-map__label", () => { const el = document.createElement("span"); el.className = "c-flow-map__label"; return el; });
|
|
1429
|
+
l.textContent = label;
|
|
1430
|
+
} else {
|
|
1431
|
+
const l = this.querySelector(".c-flow-map__label");
|
|
1432
|
+
if (l) l.remove();
|
|
1433
|
+
}
|
|
1434
|
+
wireStates(this);
|
|
1435
|
+
loadRemote(this, "nodes");
|
|
1436
|
+
if (renderStates(this, "flow-map")) return;
|
|
1437
|
+
const nodes = remoteData(this, "nodes");
|
|
1438
|
+
const effectiveNodes = nodes || (this._remoteData && this._remoteData.nodes ? JSON.stringify(this._remoteData.nodes) : null);
|
|
1439
|
+
// Slotted content support: authored .c-flow-map__node children take
|
|
1440
|
+
// precedence over the JSON `nodes` attribute.
|
|
1441
|
+
const authoredNodes = Array.from(this.querySelectorAll(":scope > .c-flow-map__node"));
|
|
1442
|
+
let parsed = null;
|
|
1443
|
+
if (authoredNodes.length) {
|
|
1444
|
+
parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
|
|
1445
|
+
authoredNodes.forEach((el) => el.remove());
|
|
1446
|
+
} else if (effectiveNodes) {
|
|
1447
|
+
try { parsed = JSON.parse(effectiveNodes); } catch (e) { parsed = null; }
|
|
1448
|
+
}
|
|
1449
|
+
if (parsed) {
|
|
1450
|
+
try {
|
|
1451
|
+
Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
|
|
1452
|
+
parsed.forEach((n, i) => {
|
|
1453
|
+
const node = document.createElement("span");
|
|
1454
|
+
node.className = "c-flow-map__node" + (n.source ? " c-flow-map__node--source" : "") + (n.target ? " c-flow-map__node--target" : "");
|
|
1455
|
+
node.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
1456
|
+
node.textContent = typeof n === "string" ? n : (n.label || n.name || "");
|
|
1457
|
+
if (typeof n === "object" && (n.label || n.name)) node.setAttribute("data-title", n.label || n.name);
|
|
1458
|
+
this.appendChild(node);
|
|
1459
|
+
});
|
|
1460
|
+
const tip = this.ensure(".c-flow-map__tooltip", () => { const el = document.createElement("div"); el.className = "c-flow-map__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
1461
|
+
tip.setAttribute("hidden", "");
|
|
1462
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1463
|
+
} else if (!parsed) {
|
|
1464
|
+
Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
|
|
1465
|
+
renderEmpty(this, "flow-map");
|
|
1466
|
+
}
|
|
1467
|
+
// UG-11 (D1): a `flows` (alias `edges`) JSON array renders a visible,
|
|
1468
|
+
const flowsRaw = (this.flows != null && this.flows !== "") ? this.flows
|
|
1469
|
+
: ((this.edges != null && this.edges !== "") ? this.edges
|
|
1470
|
+
: (this._remoteData && this._remoteData.flows != null ? JSON.stringify(this._remoteData.flows) : null));
|
|
1471
|
+
let flows = null;
|
|
1472
|
+
if (flowsRaw != null) {
|
|
1473
|
+
try {
|
|
1474
|
+
const parsedFlows = JSON.parse(flowsRaw);
|
|
1475
|
+
if (Array.isArray(parsedFlows)) flows = parsedFlows;
|
|
1476
|
+
else warnBadJson(this, "flows", new Error("expected an array"));
|
|
1477
|
+
} catch (e) { warnBadJson(this, "flows", e); }
|
|
1478
|
+
}
|
|
1479
|
+
const oldSummary = this.querySelector(".c-flow-map__summary");
|
|
1480
|
+
if (flows) {
|
|
1481
|
+
const wrap = this.ensure(".c-flow-map__summary", () => { const el = document.createElement("div"); el.className = "c-flow-map__summary c-table-wrap"; return el; });
|
|
1482
|
+
let table = wrap.querySelector("table");
|
|
1483
|
+
if (!table) { table = document.createElement("table"); table.className = "c-table c-flow-map__table"; wrap.appendChild(table); }
|
|
1484
|
+
setHTML(table, "");
|
|
1485
|
+
// A caption names the table before the first cell, the same contract
|
|
1486
|
+
// the chart's data-table fallback follows.
|
|
1487
|
+
const cap = document.createElement("caption");
|
|
1488
|
+
cap.textContent = labelText(this, "flow-summary", "Flow summary");
|
|
1489
|
+
table.appendChild(cap);
|
|
1490
|
+
const thead = document.createElement("thead");
|
|
1491
|
+
const hr = document.createElement("tr");
|
|
1492
|
+
[["source", "Source"], ["target", "Target"], ["magnitude", "Magnitude"]].forEach(([key, fallback]) => {
|
|
1493
|
+
const th = document.createElement("th");
|
|
1494
|
+
th.setAttribute("scope", "col");
|
|
1495
|
+
th.textContent = labelText(this, key, fallback);
|
|
1496
|
+
hr.appendChild(th);
|
|
1497
|
+
});
|
|
1498
|
+
thead.appendChild(hr);
|
|
1499
|
+
table.appendChild(thead);
|
|
1500
|
+
const tbody = document.createElement("tbody");
|
|
1501
|
+
const endName = (v) => typeof v === "string" ? v : ((v && typeof v === "object") ? String(v.label || v.name || v.id || "") : "");
|
|
1502
|
+
flows.forEach((f) => {
|
|
1503
|
+
const edge = (f && typeof f === "object") ? f : {};
|
|
1504
|
+
const tr = document.createElement("tr");
|
|
1505
|
+
const th = document.createElement("th");
|
|
1506
|
+
th.setAttribute("scope", "row");
|
|
1507
|
+
th.textContent = endName(edge.source);
|
|
1508
|
+
tr.appendChild(th);
|
|
1509
|
+
const tdTarget = document.createElement("td");
|
|
1510
|
+
tdTarget.textContent = endName(edge.target);
|
|
1511
|
+
tr.appendChild(tdTarget);
|
|
1512
|
+
const tdMag = document.createElement("td");
|
|
1513
|
+
const raw = edge.value != null ? edge.value : edge.magnitude;
|
|
1514
|
+
const n = Number(raw);
|
|
1515
|
+
tdMag.textContent = (raw == null || raw === "") ? "" : (Number.isFinite(n) ? (n > 0 ? "+" : "") + n : String(raw));
|
|
1516
|
+
tr.appendChild(tdMag);
|
|
1517
|
+
tbody.appendChild(tr);
|
|
1518
|
+
});
|
|
1519
|
+
table.appendChild(tbody);
|
|
1520
|
+
} else if (oldSummary) {
|
|
1521
|
+
oldSummary.remove();
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
enhance() {
|
|
1525
|
+
if (this._wiredFlowMap) return;
|
|
1526
|
+
this._wiredFlowMap = true;
|
|
1527
|
+
wireMapItems(this, ".c-flow-map__node", ".c-flow-map__tooltip");
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
define("contour-flow-map", ContourFlowMap);
|
|
1531
|
+
class ContourIsochrone extends ContourBase {
|
|
1532
|
+
static get observed() { return ["label", "center", "rings", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1533
|
+
static get properties() { return { label: { attribute: "label" }, center: { attribute: "center" }, rings: { attribute: "rings" }, src: { attribute: "src" } }; }
|
|
1534
|
+
render() {
|
|
1535
|
+
this.classList.add("c-isochrone");
|
|
1536
|
+
// Rings are focusable marks; role=img makes them presentational.
|
|
1537
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1538
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Isochrone");
|
|
1539
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
1540
|
+
if (label) {
|
|
1541
|
+
const l = this.ensure(".c-isochrone__label", () => { const el = document.createElement("span"); el.className = "c-isochrone__label"; return el; });
|
|
1542
|
+
l.textContent = label;
|
|
1543
|
+
} else {
|
|
1544
|
+
const l = this.querySelector(".c-isochrone__label");
|
|
1545
|
+
if (l) l.remove();
|
|
1546
|
+
}
|
|
1547
|
+
const center = this.getAttribute("center") || (this._remoteData && this._remoteData.center);
|
|
1548
|
+
if (center) {
|
|
1549
|
+
const c = this.ensure(".c-isochrone__center", () => { const el = document.createElement("span"); el.className = "c-isochrone__center"; return el; });
|
|
1550
|
+
c.textContent = center;
|
|
1551
|
+
} else {
|
|
1552
|
+
const c = this.querySelector(".c-isochrone__center");
|
|
1553
|
+
if (c) c.remove();
|
|
1554
|
+
}
|
|
1555
|
+
wireStates(this);
|
|
1556
|
+
loadRemote(this, "rings");
|
|
1557
|
+
if (renderStates(this, "isochrone")) return;
|
|
1558
|
+
const rings = remoteData(this, "rings");
|
|
1559
|
+
const effectiveRings = rings || (this._remoteData && this._remoteData.rings ? JSON.stringify(this._remoteData.rings) : null);
|
|
1560
|
+
// Slotted content support: authored .c-isochrone__ring children take
|
|
1561
|
+
// precedence over the JSON `rings` attribute.
|
|
1562
|
+
const authoredRings = Array.from(this.querySelectorAll(":scope > .c-isochrone__ring"));
|
|
1563
|
+
let parsed = null;
|
|
1564
|
+
if (authoredRings.length) {
|
|
1565
|
+
parsed = authoredRings.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
|
|
1566
|
+
authoredRings.forEach((el) => el.remove());
|
|
1567
|
+
} else if (effectiveRings) {
|
|
1568
|
+
try { parsed = JSON.parse(effectiveRings); } catch (e) { parsed = null; }
|
|
1569
|
+
}
|
|
1570
|
+
if (parsed) {
|
|
1571
|
+
try {
|
|
1572
|
+
Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
|
|
1573
|
+
parsed.forEach((r, i) => {
|
|
1574
|
+
const ring = document.createElement("span");
|
|
1575
|
+
// A ring may be a string or an object. Concatenating the object put
|
|
1576
|
+
const raw = typeof r === "string" ? r : (r && (r.label || r.name || r.value || r.min));
|
|
1577
|
+
const ringLabel = raw === undefined || raw === null ? "" : String(raw);
|
|
1578
|
+
const slug = ringLabel.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1579
|
+
ring.className = "c-isochrone__ring" + (slug ? " c-isochrone__ring--" + slug : "");
|
|
1580
|
+
ring.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
1581
|
+
ring.setAttribute("aria-label", ringLabel || "Isochrone ring " + (i + 1));
|
|
1582
|
+
if (ringLabel) ring.setAttribute("data-title", ringLabel);
|
|
1583
|
+
this.appendChild(ring);
|
|
1584
|
+
});
|
|
1585
|
+
const tip = this.ensure(".c-isochrone__tooltip", () => { const el = document.createElement("div"); el.className = "c-isochrone__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
1586
|
+
tip.setAttribute("hidden", "");
|
|
1587
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1588
|
+
} else if (!parsed) {
|
|
1589
|
+
Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
|
|
1590
|
+
renderEmpty(this, "isochrone");
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
enhance() {
|
|
1594
|
+
if (this._wiredIsochrone) return;
|
|
1595
|
+
this._wiredIsochrone = true;
|
|
1596
|
+
wireMapItems(this, ".c-isochrone__ring", ".c-isochrone__tooltip");
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
define("contour-isochrone", ContourIsochrone);
|
|
1600
|
+
class ContourCatchment extends ContourBase {
|
|
1601
|
+
static get observed() { return ["label", "area", "center", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1602
|
+
static get properties() { return { label: { attribute: "label" }, area: { attribute: "area" }, center: { attribute: "center" }, src: { attribute: "src" } }; }
|
|
1603
|
+
render() {
|
|
1604
|
+
this.classList.add("c-catchment");
|
|
1605
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1606
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Catchment");
|
|
1607
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
1608
|
+
if (label) {
|
|
1609
|
+
const l = this.ensure(".c-catchment__label", () => { const el = document.createElement("span"); el.className = "c-catchment__label"; return el; });
|
|
1610
|
+
l.textContent = label;
|
|
1611
|
+
} else {
|
|
1612
|
+
const l = this.querySelector(".c-catchment__label");
|
|
1613
|
+
if (l) l.remove();
|
|
1614
|
+
}
|
|
1615
|
+
const area = this.getAttribute("area") || (this._remoteData && this._remoteData.area);
|
|
1616
|
+
if (area) {
|
|
1617
|
+
const a = this.ensure(".c-catchment__area", () => { const el = document.createElement("span"); el.className = "c-catchment__area"; return el; });
|
|
1618
|
+
a.textContent = area;
|
|
1619
|
+
} else {
|
|
1620
|
+
const a = this.querySelector(".c-catchment__area");
|
|
1621
|
+
if (a) a.remove();
|
|
1622
|
+
}
|
|
1623
|
+
const center = this.getAttribute("center") || (this._remoteData && this._remoteData.center);
|
|
1624
|
+
if (center) {
|
|
1625
|
+
const c = this.ensure(".c-catchment__center", () => { const el = document.createElement("span"); el.className = "c-catchment__center"; return el; });
|
|
1626
|
+
c.textContent = center;
|
|
1627
|
+
} else {
|
|
1628
|
+
const c = this.querySelector(".c-catchment__center");
|
|
1629
|
+
if (c) c.remove();
|
|
1630
|
+
}
|
|
1631
|
+
wireStates(this);
|
|
1632
|
+
loadRemote(this, ["label", "area", "center"]);
|
|
1633
|
+
if (renderStates(this, "catchment")) return;
|
|
1634
|
+
const rLabel = remoteData(this, "label") || (this._remoteData && this._remoteData.label);
|
|
1635
|
+
const rArea = remoteData(this, "area") || (this._remoteData && this._remoteData.area);
|
|
1636
|
+
const rCenter = remoteData(this, "center") || (this._remoteData && this._remoteData.center);
|
|
1637
|
+
if (!rLabel && !rArea && !rCenter) {
|
|
1638
|
+
renderEmpty(this, "catchment");
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
const tip = this.ensure(".c-catchment__tooltip", () => { const el = document.createElement("div"); el.className = "c-catchment__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
|
|
1642
|
+
tip.setAttribute("hidden", "");
|
|
1643
|
+
if (rArea) tip.textContent = rArea;
|
|
1644
|
+
}
|
|
1645
|
+
enhance() {
|
|
1646
|
+
if (this._wiredCatchment) return;
|
|
1647
|
+
this._wiredCatchment = true;
|
|
1648
|
+
// Per-event re-query (rule 12): the tip is rebuilt on every render, so a
|
|
1649
|
+
// capture at wiring time is a detached node after the first change.
|
|
1650
|
+
const showTip = () => {
|
|
1651
|
+
const tip = this.querySelector(".c-catchment__tooltip");
|
|
1652
|
+
if (tip) tip.removeAttribute("hidden");
|
|
1653
|
+
};
|
|
1654
|
+
const hideTip = () => {
|
|
1655
|
+
const tip = this.querySelector(".c-catchment__tooltip");
|
|
1656
|
+
if (tip) tip.setAttribute("hidden", "");
|
|
1657
|
+
};
|
|
1658
|
+
this.addEventListener("mouseenter", showTip);
|
|
1659
|
+
this.addEventListener("mouseleave", hideTip);
|
|
1660
|
+
// Keyboard path (BY-39): catchment has no per-cell marks to rove, so the
|
|
1661
|
+
// host itself is the focusable surface, exactly like the sparkline.
|
|
1662
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1663
|
+
this.addEventListener("focusin", showTip);
|
|
1664
|
+
this.addEventListener("focusout", hideTip);
|
|
1665
|
+
this.addEventListener("keydown", (e) => {
|
|
1666
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1667
|
+
e.preventDefault();
|
|
1668
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { area: this.getAttribute("area") } }));
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
define("contour-catchment", ContourCatchment);
|
|
1674
|
+
class ContourCompassFull extends ContourBase {
|
|
1675
|
+
static get observed() { return ["label", "needle", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "empty", "no-cache"]; }
|
|
1676
|
+
static get properties() { return { label: { attribute: "label" }, needle: { attribute: "needle" }, src: { attribute: "src" } }; }
|
|
1677
|
+
render() {
|
|
1678
|
+
this.classList.add("c-compass");
|
|
1679
|
+
// R24-47: role=img so screen readers announce the compass as a single
|
|
1680
|
+
// image with a label, not a collection of unlabeled text nodes.
|
|
1681
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1682
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Compass");
|
|
1683
|
+
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
1684
|
+
wireStates(this);
|
|
1685
|
+
loadRemote(this, "needle");
|
|
1686
|
+
if (renderStates(this, "compass")) return;
|
|
1687
|
+
const needle = remoteData(this, "needle") || (this._remoteData && (this._remoteData.needle || this._remoteData.value));
|
|
1688
|
+
// R24-78: an empty compass shows only its empty state. The four cardinal
|
|
1689
|
+
if (!needle && !label) {
|
|
1690
|
+
renderEmpty(this, "compass");
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
// Cardinal directions.
|
|
1694
|
+
for (const dir of ["n", "s", "e", "w"]) {
|
|
1695
|
+
const cls = ".c-compass__label--" + dir;
|
|
1696
|
+
let l = this.querySelector(cls);
|
|
1697
|
+
if (!l) {
|
|
1698
|
+
l = document.createElement("span");
|
|
1699
|
+
l.className = "c-compass__label " + cls.slice(1);
|
|
1700
|
+
l.textContent = dir.toUpperCase();
|
|
1701
|
+
// The cardinals are the compass's input: each one is a button-like
|
|
1702
|
+
// target that sets the bearing (BY-22 `contour:bearing`).
|
|
1703
|
+
l.setAttribute("role", "button");
|
|
1704
|
+
l.setAttribute("tabindex", "0");
|
|
1705
|
+
this.appendChild(l);
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
if (label && label.toLowerCase() !== "compass") {
|
|
1709
|
+
const l = this.ensure(".c-compass__label:not([class*='--'])", () => { const el = document.createElement("span"); el.className = "c-compass__label"; return el; });
|
|
1710
|
+
l.textContent = label;
|
|
1711
|
+
}
|
|
1712
|
+
if (needle) {
|
|
1713
|
+
const deg = Number(needle) || 0;
|
|
1714
|
+
const n = this.ensure("svg.c-compass__needle", () => {
|
|
1715
|
+
const el = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1716
|
+
el.setAttribute("class", "c-compass__needle");
|
|
1717
|
+
el.setAttribute("viewBox", "0 0 40 40");
|
|
1718
|
+
el.setAttribute("aria-hidden", "true");
|
|
1719
|
+
const pathN = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1720
|
+
pathN.setAttribute("class", "c-compass__needle--n");
|
|
1721
|
+
pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
|
|
1722
|
+
el.appendChild(pathN);
|
|
1723
|
+
const pathS = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1724
|
+
pathS.setAttribute("class", "c-compass__needle--s");
|
|
1725
|
+
pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
|
|
1726
|
+
el.appendChild(pathS);
|
|
1727
|
+
return el;
|
|
1728
|
+
});
|
|
1729
|
+
const pathN = n.querySelector(".c-compass__needle--n");
|
|
1730
|
+
if (pathN) pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
|
|
1731
|
+
const pathS = n.querySelector(".c-compass__needle--s");
|
|
1732
|
+
if (pathS) pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
|
|
1733
|
+
} else {
|
|
1734
|
+
const n = this.querySelector("svg.c-compass__needle, .c-compass__needle");
|
|
1735
|
+
if (n) n.remove();
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
enhance() {
|
|
1739
|
+
if (this._wiredCompass) return;
|
|
1740
|
+
this._wiredCompass = true;
|
|
1741
|
+
// A cardinal is the compass's input: activate one to set the bearing and
|
|
1742
|
+
const DEGREES = { n: 0, e: 90, s: 180, w: 270 };
|
|
1743
|
+
const setBearing = (dir) => {
|
|
1744
|
+
const deg = DEGREES[dir];
|
|
1745
|
+
if (deg === undefined) return;
|
|
1746
|
+
const n = this.querySelector(".c-compass__needle");
|
|
1747
|
+
if (n) {
|
|
1748
|
+
const pathN = n.querySelector(".c-compass__needle--n");
|
|
1749
|
+
if (pathN) pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
|
|
1750
|
+
const pathS = n.querySelector(".c-compass__needle--s");
|
|
1751
|
+
if (pathS) pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
|
|
1752
|
+
}
|
|
1753
|
+
this.dispatchEvent(new CustomEvent("contour:bearing", { bubbles: true, composed: true, detail: { direction: dir, degrees: deg } }));
|
|
1754
|
+
};
|
|
1755
|
+
this.addEventListener("click", (e) => {
|
|
1756
|
+
const label = e.target && e.target.closest ? e.target.closest(".c-compass__label--n, .c-compass__label--e, .c-compass__label--s, .c-compass__label--w") : null;
|
|
1757
|
+
if (!label || !this.contains(label)) return;
|
|
1758
|
+
const m = label.className.match(/c-compass__label--([nsew])/);
|
|
1759
|
+
if (m) setBearing(m[1]);
|
|
1760
|
+
});
|
|
1761
|
+
this.addEventListener("keydown", (e) => {
|
|
1762
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
1763
|
+
const label = e.target && e.target.closest ? e.target.closest(".c-compass__label--n, .c-compass__label--e, .c-compass__label--s, .c-compass__label--w") : null;
|
|
1764
|
+
if (!label || !this.contains(label)) return;
|
|
1765
|
+
e.preventDefault();
|
|
1766
|
+
const m = label.className.match(/c-compass__label--([nsew])/);
|
|
1767
|
+
if (m) setBearing(m[1]);
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
define("contour-compass", ContourCompassFull);
|
|
1772
|
+
class ContourLayerSwitch extends ContourBase {
|
|
1773
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1774
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
1775
|
+
render() {
|
|
1776
|
+
this.classList.add("c-layer-switch");
|
|
1777
|
+
// R31-90: a labelled list of layers, so AT announces the group and each
|
|
1778
|
+
// item's position rather than a bare run of buttons.
|
|
1779
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "list");
|
|
1780
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "layer-switch", "Layer switch"));
|
|
1781
|
+
wireStates(this);
|
|
1782
|
+
loadRemote(this, "items");
|
|
1783
|
+
if (renderStates(this, "layer-switch")) return;
|
|
1784
|
+
const items = remoteData(this, "items");
|
|
1785
|
+
const authored = Array.from(this.children).filter((n) => n.classList && n.classList.contains("c-layer-switch__item"));
|
|
1786
|
+
if (items && !authored.length) {
|
|
1787
|
+
Array.from(this.querySelectorAll(".c-layer-switch__item")).forEach((n) => n.remove());
|
|
1788
|
+
try {
|
|
1789
|
+
const parsed = JSON.parse(items);
|
|
1790
|
+
const capped = Array.isArray(parsed) ? parsed.slice(0, 50) : parsed;
|
|
1791
|
+
capped.forEach((it) => {
|
|
1792
|
+
const item = document.createElement("div");
|
|
1793
|
+
item.className = "c-layer-switch__item";
|
|
1794
|
+
item.setAttribute("role", "listitem");
|
|
1795
|
+
// R31-90: mint a stable layerId (id, else a name slug, else a
|
|
1796
|
+
// sequence) so the toggle event identifies the layer. The switch
|
|
1797
|
+
// previously emitted layerId:"" on every toggle.
|
|
1798
|
+
const itemName = typeof it === "string" ? it : (it.name || it.label || "");
|
|
1799
|
+
const baseId = (typeof it === "object" && it && it.id) ? String(it.id) : (itemName ? itemName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "");
|
|
1800
|
+
this._layerSwitchSeq = (this._layerSwitchSeq || 0) + 1;
|
|
1801
|
+
item.dataset.layerId = baseId || ("layer-" + this._layerSwitchSeq);
|
|
1802
|
+
const sw = document.createElement("span");
|
|
1803
|
+
sw.className = "c-layer-switch__swatch";
|
|
1804
|
+
// R31-154: shape is the primary channel, colour the secondary. A
|
|
1805
|
+
// known shape draws with currentColor; the colour sets that color.
|
|
1806
|
+
const shape = (typeof it === "object" && it && it.shape) ? String(it.shape) : "";
|
|
1807
|
+
if (SHAPES.has(shape)) sw.classList.add("c-swatch--" + shape);
|
|
1808
|
+
if (it.color) { const safe = safeColor(it.color); if (safe) { if (SHAPES.has(shape)) sw.style.color = safe; else sw.style.background = safe; } }
|
|
1809
|
+
sw.setAttribute("aria-hidden", "true");
|
|
1810
|
+
item.appendChild(sw);
|
|
1811
|
+
const name = document.createElement("span");
|
|
1812
|
+
name.className = "c-layer-switch__name";
|
|
1813
|
+
name.textContent = typeof it === "string" ? it : (it.name || it.label || "");
|
|
1814
|
+
item.appendChild(name);
|
|
1815
|
+
if (it.count != null) {
|
|
1816
|
+
const c = document.createElement("span");
|
|
1817
|
+
c.className = "c-layer-switch__count";
|
|
1818
|
+
c.textContent = it.count;
|
|
1819
|
+
item.appendChild(c);
|
|
1820
|
+
}
|
|
1821
|
+
const toggle = document.createElement("button");
|
|
1822
|
+
toggle.className = "c-layer-switch__toggle";
|
|
1823
|
+
toggle.type = "button";
|
|
1824
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle") + " " + (typeof it === "string" ? it : (it.name || it.label || labelText(this, "layer", "layer"))));
|
|
1825
|
+
// R24-45: honor items[].visible (default true).
|
|
1826
|
+
const visible = typeof it === "object" && it.visible === false ? false : true;
|
|
1827
|
+
toggle.setAttribute("aria-pressed", String(visible));
|
|
1828
|
+
setHTML(toggle, visible ? '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-check" /></svg>' : '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
1829
|
+
item.appendChild(toggle);
|
|
1830
|
+
this.appendChild(item);
|
|
1831
|
+
});
|
|
1832
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1833
|
+
} else if (!items && !authored.length) {
|
|
1834
|
+
Array.from(this.querySelectorAll(".c-layer-switch__item")).forEach((n) => n.remove());
|
|
1835
|
+
renderEmpty(this, "layer-switch");
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
enhance() {
|
|
1839
|
+
if (this._wiredLayerSwitch) return;
|
|
1840
|
+
this._wiredLayerSwitch = true;
|
|
1841
|
+
this.addEventListener("click", (e) => {
|
|
1842
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-layer-switch__toggle") : null;
|
|
1843
|
+
if (!btn || !this.contains(btn)) return;
|
|
1844
|
+
const item = btn.closest(".c-layer-switch__item");
|
|
1845
|
+
const name = item ? (item.querySelector(".c-layer-switch__name")?.textContent || "") : "";
|
|
1846
|
+
const layerId = item && item.dataset ? (item.dataset.layerId || "") : "";
|
|
1847
|
+
const now = btn.getAttribute("aria-pressed") !== "true";
|
|
1848
|
+
btn.setAttribute("aria-pressed", String(now));
|
|
1849
|
+
// R31-90: the toggle now carries a real layerId (minted in render). The
|
|
1850
|
+
// switch keeps its own contour:layer-toggle event; the layer panel emits
|
|
1851
|
+
// the equivalent contour:layer-visibility. Both are in the vocabulary.
|
|
1852
|
+
this.dispatchEvent(new CustomEvent("contour:layer-toggle", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
1853
|
+
});
|
|
1854
|
+
this.addEventListener("keydown", (e) => {
|
|
1855
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-layer-switch__toggle") : null;
|
|
1856
|
+
if (!btn || !this.contains(btn)) return;
|
|
1857
|
+
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
define("contour-layer-switch", ContourLayerSwitch);
|
|
1862
|
+
// R31-128: basemap switcher. A row of style buttons; clicking one sets `value`
|
|
1863
|
+
// and emits contour:map-style {style,name} (the contract the map-area drives).
|
|
1864
|
+
class ContourBasemapSwitcher extends ContourBase {
|
|
1865
|
+
static get observed() { return ["items", "value", "label"]; }
|
|
1866
|
+
static get properties() { return { items: { attribute: "items" }, value: { attribute: "value" }, label: { attribute: "label" } }; }
|
|
1867
|
+
render() {
|
|
1868
|
+
this.classList.add("c-basemap-switcher");
|
|
1869
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1870
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || labelText(this, "basemap", "Basemap"));
|
|
1871
|
+
let items = [];
|
|
1872
|
+
try { const p = JSON.parse(this.getAttribute("items") || "[]"); if (Array.isArray(p)) items = p; } catch (e) { /* empty */ }
|
|
1873
|
+
const value = this.getAttribute("value");
|
|
1874
|
+
Array.from(this.querySelectorAll(".c-basemap-switcher__item")).forEach((n) => n.remove());
|
|
1875
|
+
items.forEach((it) => {
|
|
1876
|
+
const name = typeof it === "string" ? it : (it.label || it.value || it);
|
|
1877
|
+
const val = typeof it === "string" ? it : (it.value || it.label || it);
|
|
1878
|
+
const b = document.createElement("button");
|
|
1879
|
+
b.type = "button";
|
|
1880
|
+
b.className = "c-basemap-switcher__item c-btn c-btn--sm" + (value === val ? " is-active" : "");
|
|
1881
|
+
b.textContent = name;
|
|
1882
|
+
b.dataset.value = val;
|
|
1883
|
+
if (value === val) b.setAttribute("aria-pressed", "true");
|
|
1884
|
+
this.appendChild(b);
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
enhance() {
|
|
1888
|
+
if (this._wiredBasemap) return;
|
|
1889
|
+
this._wiredBasemap = true;
|
|
1890
|
+
this.addEventListener("click", (e) => {
|
|
1891
|
+
const b = e.target && e.target.closest ? e.target.closest(".c-basemap-switcher__item") : null;
|
|
1892
|
+
if (!b || !this.contains(b)) return;
|
|
1893
|
+
const val = b.dataset.value;
|
|
1894
|
+
const name = (b.textContent || "").trim();
|
|
1895
|
+
this.setAttribute("value", val);
|
|
1896
|
+
this.dispatchEvent(new CustomEvent("contour:map-style", { bubbles: true, composed: true, detail: { style: val, name } }));
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
define("contour-basemap-switcher", ContourBasemapSwitcher);
|
|
1901
|
+
class ContourMapSlot extends ContourBase {
|
|
1902
|
+
static get observed() { return ["attribution", "scale", "chrome"]; }
|
|
1903
|
+
static get properties() { return { attribution: { attribute: "attribution" }, scale: { attribute: "scale" }, chrome: { attribute: "chrome" } }; }
|
|
1904
|
+
render() {
|
|
1905
|
+
this.classList.add("c-map-slot");
|
|
1906
|
+
const chrome = this.getAttribute("chrome");
|
|
1907
|
+
if (chrome) {
|
|
1908
|
+
const c = this.ensure(".c-map-slot__chrome", () => { const el = document.createElement("div"); el.className = "c-map-slot__chrome"; return el; });
|
|
1909
|
+
c.textContent = chrome;
|
|
1910
|
+
} else {
|
|
1911
|
+
const c = this.querySelector(".c-map-slot__chrome");
|
|
1912
|
+
if (c) c.remove();
|
|
1913
|
+
}
|
|
1914
|
+
const attribution = this.getAttribute("attribution");
|
|
1915
|
+
if (attribution) {
|
|
1916
|
+
const a = this.ensure(".c-map-slot__attribution", () => { const el = document.createElement("div"); el.className = "c-map-slot__attribution"; return el; });
|
|
1917
|
+
a.textContent = attribution;
|
|
1918
|
+
} else {
|
|
1919
|
+
const a = this.querySelector(".c-map-slot__attribution");
|
|
1920
|
+
if (a) a.remove();
|
|
1921
|
+
}
|
|
1922
|
+
const scale = this.getAttribute("scale");
|
|
1923
|
+
if (scale) {
|
|
1924
|
+
const sc = this.ensure(".c-map-slot__scale", () => { const el = document.createElement("div"); el.className = "c-map-slot__scale"; return el; });
|
|
1925
|
+
sc.textContent = scale;
|
|
1926
|
+
} else {
|
|
1927
|
+
const sc = this.querySelector(".c-map-slot__scale");
|
|
1928
|
+
if (sc) sc.remove();
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
define("contour-map-slot", ContourMapSlot);
|
|
1933
|
+
class ContourMapArea extends ContourBase {
|
|
1934
|
+
static get observed() { return ["attribution", "attribution-mark", "scale", "controls", "style", "style-name", "src"]; }
|
|
1935
|
+
static get properties() { return { attribution: { attribute: "attribution" }, "attribution-mark": { attribute: "attribution-mark" }, scale: { attribute: "scale" }, controls: { attribute: "controls" }, "style-name": { attribute: "style-name" } }; }
|
|
1936
|
+
render() {
|
|
1937
|
+
this.classList.add("c-map-area");
|
|
1938
|
+
// R31-92: the engine container is styled through `.c-map-slot` (the seam
|
|
1939
|
+
// `.c-map-slot > [data-map]` fills). The map-area carries both classes so a
|
|
1940
|
+
// consumer's engine div gets the slot's sizing and chrome tokens.
|
|
1941
|
+
this.classList.add("c-map-slot");
|
|
1942
|
+
// R31-85: the style-switch contract. When a `style` is set (by a basemap
|
|
1943
|
+
// switcher or the author) and it changed, emit contour:map-style so the
|
|
1944
|
+
// engine swaps styles, then re-emit contour:map-ready once the new style
|
|
1945
|
+
// is applied. Without this path a switcher had no event to drive.
|
|
1946
|
+
const style = this.getAttribute("style");
|
|
1947
|
+
if (style && style !== this._lastMapStyle) {
|
|
1948
|
+
this._lastMapStyle = style;
|
|
1949
|
+
const name = this.getAttribute("style-name") || style;
|
|
1950
|
+
this.dispatchEvent(new CustomEvent("contour:map-style", { bubbles: true, composed: true, detail: { style, name } }));
|
|
1951
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => this.dispatchEvent(new CustomEvent("contour:map-ready", { bubbles: true, composed: true })));
|
|
1952
|
+
}
|
|
1953
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
1954
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "map-area", "Map area"));
|
|
1955
|
+
const attribution = this.getAttribute("attribution");
|
|
1956
|
+
// `attribution="engine"` means the engine draws its own credit (an
|
|
1957
|
+
// AttributionControl): the seam renders nothing, so the two never double.
|
|
1958
|
+
if (attribution && attribution !== "engine") {
|
|
1959
|
+
const a = this.ensure(".c-map-slot__attribution", () => { const el = document.createElement("div"); el.className = "c-map-slot__attribution"; return el; });
|
|
1960
|
+
a.textContent = attribution;
|
|
1961
|
+
} else {
|
|
1962
|
+
const a = this.querySelector(".c-map-slot__attribution");
|
|
1963
|
+
if (a) a.remove();
|
|
1964
|
+
}
|
|
1965
|
+
const mark = this.getAttribute("attribution-mark");
|
|
1966
|
+
if (mark) {
|
|
1967
|
+
const m = this.ensure(".c-map-slot__attribution-mark", () => { const el = document.createElement("span"); el.className = "c-map-slot__attribution-mark"; return el; });
|
|
1968
|
+
m.textContent = mark;
|
|
1969
|
+
} else {
|
|
1970
|
+
const m = this.querySelector(".c-map-slot__attribution-mark");
|
|
1971
|
+
if (m) m.remove();
|
|
1972
|
+
}
|
|
1973
|
+
const scale = this.getAttribute("scale");
|
|
1974
|
+
// `scale="engine"` defers to the engine's own ScaleControl (no doubling).
|
|
1975
|
+
if (scale && scale !== "engine") {
|
|
1976
|
+
const sc = this.ensure(".c-map-slot__scale", () => { const el = document.createElement("div"); el.className = "c-map-slot__scale"; return el; });
|
|
1977
|
+
sc.textContent = scale;
|
|
1978
|
+
} else {
|
|
1979
|
+
const sc = this.querySelector(".c-map-slot__scale");
|
|
1980
|
+
if (sc) sc.remove();
|
|
1981
|
+
}
|
|
1982
|
+
const controls = this.getAttribute("controls");
|
|
1983
|
+
if (controls) {
|
|
1984
|
+
try {
|
|
1985
|
+
const parsed = JSON.parse(controls);
|
|
1986
|
+
const wrap = this.ensure(".c-map-slot__controls", () => { const el = document.createElement("div"); el.className = "c-map-slot__controls"; return el; });
|
|
1987
|
+
setHTML(wrap, "");
|
|
1988
|
+
parsed.forEach((c) => {
|
|
1989
|
+
const btn = document.createElement("button");
|
|
1990
|
+
btn.className = "c-map-slot__control";
|
|
1991
|
+
btn.type = "button";
|
|
1992
|
+
// R31-83: a control is a string or `{label, action}`. `action` names
|
|
1993
|
+
// the engine method (zoomIn/zoomOut/…), so the click handler never
|
|
1994
|
+
// guesses from the visible text; `label` is the accessible name.
|
|
1995
|
+
const isObj = typeof c === "object" && c;
|
|
1996
|
+
const label = isObj ? (c.label || c.action || "") : String(c);
|
|
1997
|
+
// R31-146: a known action carries a glyph (icon+text); an unknown
|
|
1998
|
+
// action stays text-only so the control is never blank.
|
|
1999
|
+
const GLYPH = { zoomIn: "i-plus", zoomOut: "i-minus", zoomReset: "i-crosshair", zoom: "i-zoom", reset: "i-refresh", locate: "i-crosshair", recenter: "i-crosshair" };
|
|
2000
|
+
const glyph = isObj && c.action ? GLYPH[String(c.action)] : null;
|
|
2001
|
+
if (glyph) setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + glyph + '" /></svg>');
|
|
2002
|
+
btn.appendChild(document.createTextNode((glyph ? " " : "") + label));
|
|
2003
|
+
if (isObj && c.action) btn.dataset.mapAction = String(c.action);
|
|
2004
|
+
if (isObj && c.label) btn.setAttribute("aria-label", String(c.label));
|
|
2005
|
+
wrap.appendChild(btn);
|
|
2006
|
+
});
|
|
2007
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
2008
|
+
} else {
|
|
2009
|
+
const w = this.querySelector(".c-map-slot__controls");
|
|
2010
|
+
if (w) w.remove();
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
enhance() {
|
|
2014
|
+
if (this._wiredMapArea) return;
|
|
2015
|
+
this._wiredMapArea = true;
|
|
2016
|
+
// Map-engine seam (BY3-I3): Contour never imports a map library. A
|
|
2017
|
+
// consumer creates the engine (MapLibre, Mapbox, deck.gl …) and hands it
|
|
2018
|
+
// over; the seam stores it, reports the viewport and drives the authored
|
|
2019
|
+
// chrome, and stays engine-agnostic throughout.
|
|
2020
|
+
this._map = null;
|
|
2021
|
+
this.getViewport = () => {
|
|
2022
|
+
const m = this._map;
|
|
2023
|
+
if (!m) return null;
|
|
2024
|
+
try {
|
|
2025
|
+
if (typeof m.getBounds === "function") {
|
|
2026
|
+
const b = m.getBounds();
|
|
2027
|
+
// A box that crosses the antimeridian arrives as west > east; the
|
|
2028
|
+
// unwrapped form keeps the span positive and names the case.
|
|
2029
|
+
return unwrapBounds({ west: b.getWest(), south: b.getSouth(), east: b.getEast(), north: b.getNorth() });
|
|
2030
|
+
}
|
|
2031
|
+
if (m.transform && typeof m.transform === "object") {
|
|
2032
|
+
return { zoom: m.transform.zoom, center: m.transform.center };
|
|
2033
|
+
}
|
|
2034
|
+
} catch (e) { /* engine API mismatch */ }
|
|
2035
|
+
return null;
|
|
2036
|
+
};
|
|
2037
|
+
// The viewport is announced on every moveend so a table, a filter or a
|
|
2038
|
+
// minimap can follow the engine without polling getViewport().
|
|
2039
|
+
this._emitViewport = () => {
|
|
2040
|
+
this.dispatchEvent(new CustomEvent("contour:map-viewport", { bubbles: true, composed: true, detail: this.getViewport() }));
|
|
2041
|
+
};
|
|
2042
|
+
// R31-78: detach the previous engine's listeners and observer before a new
|
|
2043
|
+
// engine overwrites `this._map`, so a swapped engine does not leave the old
|
|
2044
|
+
// one's moveend/idle handlers firing against a stale map.
|
|
2045
|
+
this._detachEngine = () => {
|
|
2046
|
+
const m = this._map;
|
|
2047
|
+
if (m && typeof m.off === "function") {
|
|
2048
|
+
try { m.off("moveend", this._emitViewport); } catch (e) { /* engine without events */ }
|
|
2049
|
+
try { m.off("idle", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
2050
|
+
try { m.off("load", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
2051
|
+
}
|
|
2052
|
+
if (this._mapRO) { try { this._mapRO.disconnect(); } catch (e) { /* ignore */ } this._mapRO = null; }
|
|
2053
|
+
};
|
|
2054
|
+
// R31-77: readiness is announced once, after the first idle/load — not at
|
|
2055
|
+
// attach, when the engine may still be loading its style/tiles.
|
|
2056
|
+
this._onMapIdle = () => {
|
|
2057
|
+
if (this._mapReadySent) return;
|
|
2058
|
+
this._mapReadySent = true;
|
|
2059
|
+
this.dispatchEvent(new CustomEvent("contour:map-ready", { bubbles: true, composed: true }));
|
|
2060
|
+
};
|
|
2061
|
+
this.attachMap = (map) => {
|
|
2062
|
+
this._detachEngine();
|
|
2063
|
+
this._map = map || null;
|
|
2064
|
+
this._mapReadySent = false;
|
|
2065
|
+
// R31-84: the `data-map` hook is the engine container the seam fills
|
|
2066
|
+
// (`.c-map-slot > [data-map]`). If it has zero size at attach time the
|
|
2067
|
+
// engine cannot render — usually a hidden tab or a display:none
|
|
2068
|
+
// ancestor — so say so once instead of failing silently.
|
|
2069
|
+
if (this._map) {
|
|
2070
|
+
const zeroSizeCheck = () => {
|
|
2071
|
+
if (!this.isConnected || this._map !== map) return;
|
|
2072
|
+
if (!this.clientWidth || !this.clientHeight) {
|
|
2073
|
+
this.dispatchEvent(new CustomEvent("contour:error", { bubbles: true, composed: true, detail: { src: this.getAttribute("src") || "", message: "Map container has zero size; the engine cannot render.", name: "map-zero-size", status: 0 } }));
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(zeroSizeCheck);
|
|
2077
|
+
else zeroSizeCheck();
|
|
2078
|
+
}
|
|
2079
|
+
if (this._map && typeof this._map.on === "function") {
|
|
2080
|
+
try { this._map.on("moveend", this._emitViewport); } catch (e) { /* engine without events */ }
|
|
2081
|
+
try { this._map.on("idle", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
2082
|
+
try { this._map.on("load", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
2083
|
+
}
|
|
2084
|
+
// R31-80: drive the engine's own resize/invalidateSize when the host box
|
|
2085
|
+
// changes, so the canvas matches its container after a layout change.
|
|
2086
|
+
if (typeof ResizeObserver !== "undefined" && this._map) {
|
|
2087
|
+
try {
|
|
2088
|
+
// R31-82: coalesce to one resize per frame — a split/sidebar toggle
|
|
2089
|
+
// fires several observations in a row and each engine.resize() is a
|
|
2090
|
+
// full relayout.
|
|
2091
|
+
let resizeRaf = 0;
|
|
2092
|
+
this._mapRO = new ResizeObserver(() => {
|
|
2093
|
+
if (resizeRaf) return;
|
|
2094
|
+
resizeRaf = requestAnimationFrame(() => {
|
|
2095
|
+
resizeRaf = 0;
|
|
2096
|
+
const mm = this._map;
|
|
2097
|
+
if (!mm) return;
|
|
2098
|
+
try {
|
|
2099
|
+
if (typeof mm.resize === "function") mm.resize();
|
|
2100
|
+
else if (typeof mm.invalidateSize === "function") mm.invalidateSize();
|
|
2101
|
+
} catch (e) { /* engine without resize */ }
|
|
2102
|
+
});
|
|
2103
|
+
});
|
|
2104
|
+
this._mapRO.observe(this);
|
|
2105
|
+
} catch (e) { this._mapRO = null; }
|
|
2106
|
+
}
|
|
2107
|
+
this.dispatchEvent(new CustomEvent("contour:map-attach", { bubbles: true, composed: true }));
|
|
2108
|
+
this._emitViewport();
|
|
2109
|
+
// An engine that is already loaded fires no idle/load; send ready now.
|
|
2110
|
+
if (this._map && typeof this._map.loaded === "function") {
|
|
2111
|
+
try { if (this._map.loaded()) this._onMapIdle(); } catch (e) { /* engine without loaded() */ }
|
|
2112
|
+
}
|
|
2113
|
+
};
|
|
2114
|
+
this.detachMap = () => {
|
|
2115
|
+
this._detachEngine();
|
|
2116
|
+
this._map = null;
|
|
2117
|
+
this.dispatchEvent(new CustomEvent("contour:map-detach", { bubbles: true, composed: true }));
|
|
2118
|
+
};
|
|
2119
|
+
if (!this.hasOwnProperty("map")) {
|
|
2120
|
+
Object.defineProperty(this, "map", { get: () => this._map, set: (m) => this.attachMap(m) });
|
|
2121
|
+
} // R24-76: avoid redefine on reconnect.
|
|
2122
|
+
// Camera passthroughs. Both are no-ops when no engine is attached or the
|
|
2123
|
+
// engine lacks the method, so a consumer can call them unconditionally.
|
|
2124
|
+
this.fitBounds = (bounds, options) => {
|
|
2125
|
+
const m = this._map;
|
|
2126
|
+
if (!m || typeof m.fitBounds !== "function") return;
|
|
2127
|
+
// MapLibre/Mapbox accept both [w, s, e, n] and [[w, s], [e, n]], so the
|
|
2128
|
+
// GeoJSON bbox form a consumer already has passes straight through.
|
|
2129
|
+
try { m.fitBounds(bounds, options); } catch (e) { /* engine API mismatch */ }
|
|
2130
|
+
};
|
|
2131
|
+
this.flyTo = (options) => {
|
|
2132
|
+
const m = this._map;
|
|
2133
|
+
if (!m || typeof m.flyTo !== "function") return;
|
|
2134
|
+
try { m.flyTo(options); } catch (e) { /* engine API mismatch */ }
|
|
2135
|
+
};
|
|
2136
|
+
// Chrome wiring (the documented recipe): attachMap(map) then
|
|
2137
|
+
// attachChrome(map) and the authored zoom buttons, readout and compass
|
|
2138
|
+
// drive the live engine. Engine-agnostic — it only uses the map-like
|
|
2139
|
+
// surface (zoomIn/zoomOut/getCenter/getZoom/getBearing/on). Layer
|
|
2140
|
+
// toggles stay event-driven (contour:layer-*), so the consumer applies
|
|
2141
|
+
// them; this does not reach into engine layers.
|
|
2142
|
+
this.attachChrome = (map) => {
|
|
2143
|
+
const m = map || this._map;
|
|
2144
|
+
if (!m || this._chromeMap === m) return;
|
|
2145
|
+
this._chromeMap = m;
|
|
2146
|
+
// Zoom controls are delegated on the host so a render() that rebuilds
|
|
2147
|
+
// the buttons (the `controls` attribute) cannot leave them unwired.
|
|
2148
|
+
if (!this._chromeDelegated) {
|
|
2149
|
+
this._chromeDelegated = true;
|
|
2150
|
+
// R31-88: the grip is a real control. A `cursor: grab` that cannot grab
|
|
2151
|
+
// is a lie; ArrowUp/ArrowDown on the focused grip reorders the layer and
|
|
2152
|
+
// emits contour:layer-reorder with the new position.
|
|
2153
|
+
this.addEventListener("keydown", (e) => {
|
|
2154
|
+
const handle = e.target && e.target.closest ? e.target.closest(".c-drag-handle--dots, .c-layer-panel__grip") : null;
|
|
2155
|
+
if (!handle || !this.contains(handle)) return;
|
|
2156
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
|
2157
|
+
const item = handle.closest(".c-layer-panel__item");
|
|
2158
|
+
if (!item) return;
|
|
2159
|
+
const parent = item.parentNode;
|
|
2160
|
+
const sib = e.key === "ArrowUp" ? item.previousElementSibling : item.nextElementSibling;
|
|
2161
|
+
if (!sib || !sib.classList || !sib.classList.contains("c-layer-panel__item")) return;
|
|
2162
|
+
e.preventDefault();
|
|
2163
|
+
if (e.key === "ArrowUp") parent.insertBefore(item, sib);
|
|
2164
|
+
else parent.insertBefore(sib, item);
|
|
2165
|
+
try { handle.focus(); } catch (err) { /* ignore */ }
|
|
2166
|
+
// R31-88: one detail shape for both pointer and keyboard reorder — the
|
|
2167
|
+
// full ordered id list, same as the drag path.
|
|
2168
|
+
const layerIds = Array.from(parent.querySelectorAll(":scope > .c-layer-panel__item")).map((el, i) => el.dataset.layerId || el.getAttribute("data-layer-id") || String(i));
|
|
2169
|
+
this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
|
|
2170
|
+
});
|
|
2171
|
+
this.addEventListener("click", (e) => {
|
|
2172
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-map-slot__control") : null;
|
|
2173
|
+
if (!btn || !this.contains(btn)) return;
|
|
2174
|
+
// R31-79: read the live engine, not the one captured at attach time,
|
|
2175
|
+
// so a swapped engine (attachMap) is driven by the chrome.
|
|
2176
|
+
const mm = this._map;
|
|
2177
|
+
if (!mm) return;
|
|
2178
|
+
// R31-83: an explicit `data-map-action` wins; fall back to the text
|
|
2179
|
+
// heuristic only for a plain string control.
|
|
2180
|
+
const action = btn.dataset.mapAction;
|
|
2181
|
+
const label = (btn.getAttribute("aria-label") || btn.textContent || "").toLowerCase();
|
|
2182
|
+
const out = action ? /out|minus|zoomout/i.test(action) : (/out|minus|−|-/.test(label) && !/in\b/.test(label));
|
|
2183
|
+
try { out ? mm.zoomOut() : mm.zoomIn(); } catch (err) { /* engine without zoom */ }
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
const readout = this.querySelector(".c-readout");
|
|
2187
|
+
if (readout && typeof m.getCenter === "function") {
|
|
2188
|
+
const coord = readout.querySelector(".c-readout__value--coord");
|
|
2189
|
+
const zoom = readout.querySelector(".c-readout__row:nth-child(2) .c-readout__value");
|
|
2190
|
+
const write = () => {
|
|
2191
|
+
const mm = this._map || m; // R31-79: live engine.
|
|
2192
|
+
if (typeof mm.getCenter !== "function") return;
|
|
2193
|
+
const c = mm.getCenter();
|
|
2194
|
+
if (coord && c) coord.textContent = `${c.lng.toFixed(6)}, ${c.lat.toFixed(6)}`;
|
|
2195
|
+
if (zoom && typeof mm.getZoom === "function") zoom.textContent = mm.getZoom().toFixed(1);
|
|
2196
|
+
};
|
|
2197
|
+
try { m.on("move", write); } catch (e) { /* engine without events */ }
|
|
2198
|
+
write();
|
|
2199
|
+
}
|
|
2200
|
+
const needle = this.querySelector(".c-compass__needle");
|
|
2201
|
+
if (needle && typeof m.getBearing === "function") {
|
|
2202
|
+
const n = needle.querySelector(".c-compass__needle--n");
|
|
2203
|
+
const s = needle.querySelector(".c-compass__needle--s");
|
|
2204
|
+
const compass = needle.closest("contour-compass");
|
|
2205
|
+
const pt = (deg) => { const r = (deg * Math.PI) / 180; return [20 + 16 * Math.sin(r), 20 - 16 * Math.cos(r)]; };
|
|
2206
|
+
const draw = () => {
|
|
2207
|
+
const mm = this._map || m; // R31-79: live engine.
|
|
2208
|
+
if (typeof mm.getBearing !== "function") return;
|
|
2209
|
+
const deg = -mm.getBearing();
|
|
2210
|
+
const [nx, ny] = pt(deg), [sx, sy] = pt(deg + 180);
|
|
2211
|
+
if (n) n.setAttribute("d", `M ${nx} ${ny} L 20 20 Z`);
|
|
2212
|
+
if (s) s.setAttribute("d", `M ${sx} ${sy} L 20 20 Z`);
|
|
2213
|
+
// R31-81: the needle is decorative (aria-hidden); the compass's own
|
|
2214
|
+
// accessible name carries the bearing so a rotation is announced.
|
|
2215
|
+
if (compass) {
|
|
2216
|
+
const cur = compass.getAttribute("aria-label") || "";
|
|
2217
|
+
if (!cur || /^compass\b/i.test(cur)) {
|
|
2218
|
+
const bearing = Math.round(((deg % 360) + 360) % 360);
|
|
2219
|
+
compass.setAttribute("aria-label", `Compass, bearing ${bearing} degrees`);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
try { m.on("rotate", draw); } catch (e) { /* engine without events */ }
|
|
2224
|
+
draw();
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
this.addEventListener("click", (e) => {
|
|
2228
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-map-slot__control") : null;
|
|
2229
|
+
if (!btn || !this.contains(btn)) return;
|
|
2230
|
+
this.dispatchEvent(new CustomEvent("contour:map-control", { bubbles: true, composed: true, detail: { control: btn.textContent } }));
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
define("contour-map-area", ContourMapArea);
|
|
2235
|
+
class ContourMapPanel extends ContourBase {
|
|
2236
|
+
static get observed() { return ["title"]; }
|
|
2237
|
+
static get properties() { return { title: { attribute: "title" } }; }
|
|
2238
|
+
render() {
|
|
2239
|
+
this.classList.add("c-map-panel");
|
|
2240
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
2241
|
+
const title = this.getAttribute("title");
|
|
2242
|
+
// The accessible name follows the title only while it is the one we
|
|
2243
|
+
if (title) {
|
|
2244
|
+
const prev = this._mapPanelTitle;
|
|
2245
|
+
if (!this.hasAttribute("aria-label") || (prev && this.getAttribute("aria-label") === prev)) {
|
|
2246
|
+
this.setAttribute("aria-label", title);
|
|
2247
|
+
}
|
|
2248
|
+
this._mapPanelTitle = title;
|
|
2249
|
+
} else if (this._mapPanelTitle && this.getAttribute("aria-label") === this._mapPanelTitle) {
|
|
2250
|
+
this.removeAttribute("aria-label");
|
|
2251
|
+
this._mapPanelTitle = null;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
define("contour-map-panel", ContourMapPanel);
|
|
2256
|
+
class ContourMapFooter extends ContourBase {
|
|
2257
|
+
static get observed() { return ["brand"]; }
|
|
2258
|
+
static get properties() { return { brand: { attribute: "brand" } }; }
|
|
2259
|
+
render() {
|
|
2260
|
+
this.classList.add("c-map-footer");
|
|
2261
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "contentinfo");
|
|
2262
|
+
const brand = this.getAttribute("brand");
|
|
2263
|
+
// The footer's own rule is `.c-map-footer > *`, which reaches any direct
|
|
2264
|
+
// child, so the brand is a plain span: visible, and inventing no name.
|
|
2265
|
+
if (brand) {
|
|
2266
|
+
const b = this.ensure(".c-map-footer__brand", () => { const el = document.createElement("span"); el.className = "c-map-footer__brand"; return el; });
|
|
2267
|
+
b.textContent = brand;
|
|
2268
|
+
} else {
|
|
2269
|
+
const b = this.querySelector(".c-map-footer__brand");
|
|
2270
|
+
if (b) b.remove();
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
define("contour-map-footer", ContourMapFooter);
|
|
2275
|
+
class ContourScaleBar extends ContourBase {
|
|
2276
|
+
static get observed() { return ["label", "value", "distance", "resolution", "latitude", "zoom", "units", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
2277
|
+
static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, distance: { attribute: "distance" }, resolution: { attribute: "resolution" }, latitude: { attribute: "latitude" }, zoom: { attribute: "zoom" }, src: { attribute: "src" } }; }
|
|
2278
|
+
render() {
|
|
2279
|
+
this.classList.add("c-scale-bar");
|
|
2280
|
+
// R24-49: role=img + aria-label so screen readers announce the scale.
|
|
2281
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
2282
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "map-scale", "Map scale"));
|
|
2283
|
+
wireStates(this);
|
|
2284
|
+
loadRemote(this, ["label", "value"]);
|
|
2285
|
+
if (renderStates(this, "scale-bar")) return;
|
|
2286
|
+
let value = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
|
|
2287
|
+
// BY-23: derive the bar width from map resolution + latitude when the
|
|
2288
|
+
const resolution = parseFloat(this.getAttribute("resolution"));
|
|
2289
|
+
// R24-49: use mercatorResolution when latitude + zoom are provided.
|
|
2290
|
+
const lat = parseFloat(this.getAttribute("latitude"));
|
|
2291
|
+
const zoom = parseFloat(this.getAttribute("zoom"));
|
|
2292
|
+
let effectiveResolution = resolution;
|
|
2293
|
+
if (!Number.isFinite(effectiveResolution) && Number.isFinite(lat) && Number.isFinite(zoom)) {
|
|
2294
|
+
effectiveResolution = mercatorResolution(lat, zoom);
|
|
2295
|
+
}
|
|
2296
|
+
let derivedLabel = null;
|
|
2297
|
+
if (Number.isFinite(effectiveResolution) && effectiveResolution > 0) {
|
|
2298
|
+
const distance = parseFloat(this.getAttribute("distance")) || 1000;
|
|
2299
|
+
value = String(Math.round(distance / effectiveResolution));
|
|
2300
|
+
if (!this.getAttribute("label") && !remoteData(this, "label")) {
|
|
2301
|
+
const units = this.getAttribute("units") || "metric";
|
|
2302
|
+
if (units === "imperial") {
|
|
2303
|
+
derivedLabel = distance >= 1609.34 ? (distance / 1609.34).toFixed(1) + " mi" : Math.round(distance * 3.28084) + " ft";
|
|
2304
|
+
} else {
|
|
2305
|
+
derivedLabel = distance >= 1000 ? (distance / 1000) + " km" : distance + " m";
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
const label = derivedLabel || remoteData(this, "label") || (this._remoteData && this._remoteData.label);
|
|
2310
|
+
if (label) {
|
|
2311
|
+
const l = this.ensure(".c-scale-bar__label", () => { const el = document.createElement("span"); el.className = "c-scale-bar__label"; return el; });
|
|
2312
|
+
l.textContent = label;
|
|
2313
|
+
} else {
|
|
2314
|
+
const l = this.querySelector(".c-scale-bar__label");
|
|
2315
|
+
if (l) l.remove();
|
|
2316
|
+
}
|
|
2317
|
+
// R24-49: metric/imperial unit toggle.
|
|
2318
|
+
const unitBtn = this.ensure(".c-scale-bar__units", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-scale-bar__units"; return b; });
|
|
2319
|
+
const units = this.getAttribute("units") || "metric";
|
|
2320
|
+
unitBtn.textContent = units === "imperial" ? "mi" : "km";
|
|
2321
|
+
unitBtn.onclick = () => { this.setAttribute("units", (this.getAttribute("units") || "metric") === "imperial" ? "metric" : "imperial"); };
|
|
2322
|
+
if (!value) {
|
|
2323
|
+
renderEmpty(this, "scale-bar");
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
const line = this.ensure(".c-scale-bar__line", () => { const el = document.createElement("span"); el.className = "c-scale-bar__line"; return el; });
|
|
2327
|
+
// CSS lengths need a unit; a bare number would be dropped as an invalid
|
|
2328
|
+
// property value and the bar would render at zero width.
|
|
2329
|
+
line.style.inlineSize = /^\d+(\.\d+)?$/.test(String(value)) ? value + "px" : value;
|
|
2330
|
+
const ticks = scaleBarTicks(parseFloat(value) || 0, 4);
|
|
2331
|
+
const max = ticks[ticks.length - 1] || 1;
|
|
2332
|
+
Array.from(line.querySelectorAll(".c-scale-bar__tick")).forEach((t) => t.remove());
|
|
2333
|
+
ticks.forEach((tv) => {
|
|
2334
|
+
const tick = document.createElement("span");
|
|
2335
|
+
tick.className = "c-scale-bar__tick";
|
|
2336
|
+
// Logical (BY-48): insetInlineStart mirrors the bar in RTL instead of
|
|
2337
|
+
// pinning the tick to the physical left edge.
|
|
2338
|
+
tick.style.insetInlineStart = ((tv / max) * 100) + "%";
|
|
2339
|
+
line.appendChild(tick);
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
define("contour-scale-bar", ContourScaleBar);
|
|
2344
|
+
|
|
2345
|
+
class ContourSplitMap extends ContourBase {
|
|
2346
|
+
// R24-77: split-map is a static two-pane layout primitive, not an interactive
|
|
2347
|
+
static get observed() { return []; }
|
|
2348
|
+
render() {
|
|
2349
|
+
this.classList.add("c-split-map");
|
|
2350
|
+
const left = this.ensure(".c-split-map__pane--left", () => {
|
|
2351
|
+
const e = document.createElement("div");
|
|
2352
|
+
e.className = "c-split-map__pane c-split-map__pane--left";
|
|
2353
|
+
return e;
|
|
2354
|
+
});
|
|
2355
|
+
const right = this.ensure(".c-split-map__pane--right", () => {
|
|
2356
|
+
const e = document.createElement("div");
|
|
2357
|
+
e.className = "c-split-map__pane c-split-map__pane--right";
|
|
2358
|
+
return e;
|
|
2359
|
+
});
|
|
2360
|
+
if (left.parentNode !== this) this.appendChild(left);
|
|
2361
|
+
if (right.parentNode !== this) this.appendChild(right);
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
define("contour-split-map", ContourSplitMap);
|
|
2365
|
+
// R31-131: a collapsible map overlay legend. Composes a legend list + a
|
|
2366
|
+
// toggle head; the engine owns the layers, the legend only shows their names.
|
|
2367
|
+
class ContourMapLegend extends ContourBase {
|
|
2368
|
+
static get observed() { return ["items", "label", "collapsed"]; }
|
|
2369
|
+
static get properties() { return { items: { attribute: "items" }, label: { attribute: "label" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
2370
|
+
render() {
|
|
2371
|
+
this.classList.add("c-map-legend");
|
|
2372
|
+
const label = this.getAttribute("label") || labelText(this, "legend", "Legend");
|
|
2373
|
+
const head = this.ensure(".c-map-legend__head", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-map-legend__head"; return b; });
|
|
2374
|
+
setHTML(head, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-layers" /></svg>');
|
|
2375
|
+
head.appendChild(document.createTextNode(" " + label));
|
|
2376
|
+
const collapsed = this.hasAttribute("collapsed");
|
|
2377
|
+
head.setAttribute("aria-expanded", collapsed ? "false" : "true");
|
|
2378
|
+
let items = [];
|
|
2379
|
+
try { const p = JSON.parse(this.getAttribute("items") || "[]"); if (Array.isArray(p)) items = p; } catch (e) { /* empty */ }
|
|
2380
|
+
const list = this.ensure(".c-map-legend__list", () => { const l = document.createElement("ul"); l.className = "c-map-legend__list"; return l; });
|
|
2381
|
+
setHTML(list, "");
|
|
2382
|
+
if (!collapsed) {
|
|
2383
|
+
items.forEach((it) => {
|
|
2384
|
+
const name = typeof it === "string" ? it : (it.label || it.name || "");
|
|
2385
|
+
const color = (typeof it === "object" && it) ? it.color : null;
|
|
2386
|
+
const li = document.createElement("li");
|
|
2387
|
+
li.className = "c-map-legend__item";
|
|
2388
|
+
const shape = (typeof it === "object" && it && it.shape) ? String(it.shape) : "";
|
|
2389
|
+
if (color || SHAPES.has(shape)) {
|
|
2390
|
+
const sw = document.createElement("span");
|
|
2391
|
+
sw.className = "c-map-legend__swatch";
|
|
2392
|
+
if (SHAPES.has(shape)) sw.classList.add("c-swatch--" + shape);
|
|
2393
|
+
if (color) { if (SHAPES.has(shape)) sw.style.color = color; else sw.style.setProperty("--c", color); }
|
|
2394
|
+
li.appendChild(sw);
|
|
2395
|
+
}
|
|
2396
|
+
li.appendChild(document.createTextNode(" " + name));
|
|
2397
|
+
list.appendChild(li);
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
enhance() {
|
|
2402
|
+
if (this._wiredMapLegend) return;
|
|
2403
|
+
this._wiredMapLegend = true;
|
|
2404
|
+
this.addEventListener("click", (e) => {
|
|
2405
|
+
const h = e.target && e.target.closest ? e.target.closest(".c-map-legend__head") : null;
|
|
2406
|
+
if (!h || !this.contains(h)) return;
|
|
2407
|
+
this.toggleAttribute("collapsed");
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
define("contour-map-legend", ContourMapLegend);
|