contour-ds 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
package/dist/wc/map.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ContourBase, define, onDispose, formatValue, navKey, isRtl , warnBadJson, labelText } from './core.mjs';
|
|
1
|
+
import { setHTML, ContourBase, define, onDispose, formatValue, navKey, isRtl , safeColor, warnBadJson, labelText, mercatorResolution, unwrapBounds, contourId } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
3
|
import { compassNeedle, scaleBarTicks } from './svg.mjs';
|
|
4
4
|
|
|
5
|
+
// R31-154: the layer-type vocabulary. A map layer is a shape first, a colour
|
|
6
|
+
// second; these are the shapes a swatch can draw (`.c-swatch--<shape>`).
|
|
7
|
+
const SHAPES = new Set(["point", "line", "polygon", "raster", "heatmap", "symbol"]);
|
|
8
|
+
|
|
5
9
|
// Shared tooltip + roving + select wiring for the map components that render a
|
|
6
|
-
// grid of items (hexbin cells, flow-map nodes, isochrone rings). Extracted from
|
|
7
|
-
// three near-identical copies (D-13) so the behaviour cannot drift apart again.
|
|
8
10
|
function wireMapItems(host, itemSelector, tooltipClass) {
|
|
9
11
|
if (host._wiredMapItems) return;
|
|
10
12
|
host._wiredMapItems = true;
|
|
@@ -14,7 +16,7 @@ function wireMapItems(host, itemSelector, tooltipClass) {
|
|
|
14
16
|
if (!tip) return;
|
|
15
17
|
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
16
18
|
if (!item || !host.contains(item)) { tip.setAttribute("hidden", ""); return; }
|
|
17
|
-
const title = item.getAttribute("title");
|
|
19
|
+
const title = item.getAttribute("data-title") || item.getAttribute("title");
|
|
18
20
|
if (title) tip.textContent = title;
|
|
19
21
|
const rect = host.getBoundingClientRect();
|
|
20
22
|
const ir = item.getBoundingClientRect();
|
|
@@ -39,7 +41,7 @@ function wireMapItems(host, itemSelector, tooltipClass) {
|
|
|
39
41
|
const all = items();
|
|
40
42
|
const index = all.indexOf(item);
|
|
41
43
|
if (index < 0) return;
|
|
42
|
-
host.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index, label: item.getAttribute("title") || item.textContent.trim() } }));
|
|
44
|
+
host.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index, label: item.getAttribute("data-title") || item.getAttribute("title") || item.textContent.trim() } }));
|
|
43
45
|
});
|
|
44
46
|
host.addEventListener("keydown", (e) => {
|
|
45
47
|
const item = e && e.target && typeof e.target.closest === "function" ? e.target.closest(itemSelector) : null;
|
|
@@ -48,7 +50,7 @@ function wireMapItems(host, itemSelector, tooltipClass) {
|
|
|
48
50
|
e.preventDefault();
|
|
49
51
|
const all = items();
|
|
50
52
|
const index = all.indexOf(item);
|
|
51
|
-
if (index >= 0) host.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index, label: item.getAttribute("title") || item.textContent.trim() } }));
|
|
53
|
+
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() } }));
|
|
52
54
|
} else {
|
|
53
55
|
const all = items();
|
|
54
56
|
navKey(e, all, { wrap: false, homeEnd: true, rtl: isRtl(host), onNavigate: (i) => all.forEach((c, j) => c.setAttribute("tabindex", j === i ? "0" : "-1")) });
|
|
@@ -57,7 +59,7 @@ function wireMapItems(host, itemSelector, tooltipClass) {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
class ContourMinimap extends ContourBase {
|
|
60
|
-
static get observed() { return ["label", "viewport", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
62
|
+
static get observed() { return ["label", "viewport", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
61
63
|
static get properties() { return { label: { attribute: "label" }, viewport: { attribute: "viewport" }, src: { attribute: "src" } }; }
|
|
62
64
|
render() {
|
|
63
65
|
this.classList.add("c-minimap");
|
|
@@ -92,15 +94,21 @@ class ContourMinimap extends ContourBase {
|
|
|
92
94
|
this._wiredMinimap = true;
|
|
93
95
|
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
94
96
|
let dragging = false;
|
|
97
|
+
let dragStartX = 0, dragStartY = 0;
|
|
95
98
|
this.addEventListener("pointerdown", (e) => {
|
|
96
99
|
const vp = this.querySelector(".c-minimap__viewport");
|
|
97
100
|
if (!vp || !vp.contains(e.target)) return;
|
|
98
101
|
dragging = true;
|
|
102
|
+
dragStartX = e.clientX;
|
|
103
|
+
dragStartY = e.clientY;
|
|
99
104
|
try { vp.setPointerCapture(e.pointerId); } catch (err) {}
|
|
100
105
|
});
|
|
101
106
|
this.addEventListener("pointermove", (e) => {
|
|
102
107
|
if (!dragging) return;
|
|
103
|
-
|
|
108
|
+
// R24-19: emit pan-delta so consumers can track the drag distance.
|
|
109
|
+
const dx = e.clientX - dragStartX;
|
|
110
|
+
const dy = e.clientY - dragStartY;
|
|
111
|
+
this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag", dx, dy }, bubbles: true, composed: true }));
|
|
104
112
|
});
|
|
105
113
|
this.addEventListener("pointerup", () => { dragging = false; });
|
|
106
114
|
this.addEventListener("keydown", (e) => {
|
|
@@ -119,8 +127,8 @@ class ContourMinimap extends ContourBase {
|
|
|
119
127
|
}
|
|
120
128
|
define("contour-minimap", ContourMinimap);
|
|
121
129
|
class ContourCoordinate extends ContourBase {
|
|
122
|
-
static get observed() { return ["value", "format", "locale", "precision", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
123
|
-
static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" }, precision: { attribute: "precision" }, src: { attribute: "src" } }; }
|
|
130
|
+
static get observed() { return ["value", "format", "locale", "precision", "live", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
131
|
+
static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" }, precision: { attribute: "precision" }, live: { attribute: "live" }, src: { attribute: "src" } }; }
|
|
124
132
|
render() {
|
|
125
133
|
this.classList.add("c-coordinate");
|
|
126
134
|
wireStates(this);
|
|
@@ -155,14 +163,31 @@ class ContourCoordinate extends ContourBase {
|
|
|
155
163
|
const y = Math.log(Math.tan((90 + parts[0]) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180;
|
|
156
164
|
text = x.toFixed(2) + ", " + y.toFixed(2);
|
|
157
165
|
}
|
|
166
|
+
} else if (format === "decimal") {
|
|
167
|
+
// R24-77: honour DD precision. `precision` was only read in the DMS
|
|
168
|
+
const parts = String(value).split(/[,\s]+/).map(Number);
|
|
169
|
+
const prec = parseInt(this.getAttribute("precision") || "", 10);
|
|
170
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1]) && Number.isFinite(prec) && prec >= 0) {
|
|
171
|
+
text = parts[0].toFixed(prec) + ", " + parts[1].toFixed(prec);
|
|
172
|
+
} else {
|
|
173
|
+
text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
174
|
+
}
|
|
158
175
|
} else {
|
|
159
176
|
text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
160
177
|
}
|
|
161
|
-
const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value";
|
|
178
|
+
const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value"; return el; });
|
|
179
|
+
// R24-77: the readout updates on every pointer move, so a live region
|
|
180
|
+
if (this.hasAttribute("live")) {
|
|
181
|
+
span.setAttribute("role", "status");
|
|
182
|
+
span.setAttribute("aria-live", "polite");
|
|
183
|
+
} else {
|
|
184
|
+
span.removeAttribute("role");
|
|
185
|
+
span.removeAttribute("aria-live");
|
|
186
|
+
}
|
|
162
187
|
span.textContent = text;
|
|
163
188
|
// copy button
|
|
164
189
|
let btn = this.querySelector(".c-coordinate__copy");
|
|
165
|
-
if (!btn) { btn = document.createElement("button"); btn.type = "button"; btn.className = "c-coordinate__copy"; btn
|
|
190
|
+
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); }
|
|
166
191
|
btn.onclick = () => {
|
|
167
192
|
try {
|
|
168
193
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
@@ -189,12 +214,14 @@ class ContourCoordinate extends ContourBase {
|
|
|
189
214
|
}
|
|
190
215
|
define("contour-coordinate", ContourCoordinate);
|
|
191
216
|
class ContourLayerPanel extends ContourBase {
|
|
192
|
-
static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "allow-rename", "allow-remove", "allow-duplicate", "allow-zoom"]; }
|
|
217
|
+
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"]; }
|
|
193
218
|
static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
194
219
|
render() {
|
|
195
220
|
this.classList.add("c-layer-panel");
|
|
196
221
|
this.setAttribute("role", "group");
|
|
197
|
-
this.setAttribute("aria-label", "Layer panel");
|
|
222
|
+
this.setAttribute("aria-label", labelText(this, "layer-panel", "Layer panel"));
|
|
223
|
+
// Reset the id minter each render: ids are a function of the item set, not
|
|
224
|
+
this._layerIdSeen = new Set();
|
|
198
225
|
wireStates(this);
|
|
199
226
|
loadRemote(this, "items");
|
|
200
227
|
if (renderStates(this, "layer-panel")) return;
|
|
@@ -212,15 +239,20 @@ class ContourLayerPanel extends ContourBase {
|
|
|
212
239
|
const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
|
|
213
240
|
// Preserve user-toggled visibility across re-renders (B3-09): a src
|
|
214
241
|
// reload must not re-check a layer the user un-checked.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
242
|
+
const savedVisibility = new Map();
|
|
243
|
+
// R31-87: preserve the opacity the user dragged across a re-render, keyed
|
|
244
|
+
// by layer name, the same way visibility is preserved.
|
|
245
|
+
const savedOpacity = new Map();
|
|
246
|
+
this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
|
|
247
|
+
const nm = el.querySelector(".c-layer-panel__name");
|
|
248
|
+
const tg = el.querySelector(".c-layer-panel__toggle");
|
|
249
|
+
if (nm && tg) {
|
|
250
|
+
const v = tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked;
|
|
251
|
+
savedVisibility.set(nm.textContent, v);
|
|
252
|
+
}
|
|
253
|
+
const op = el.querySelector(".c-layer-panel__opacity");
|
|
254
|
+
if (nm && op) savedOpacity.set(nm.textContent, op.value);
|
|
255
|
+
});
|
|
224
256
|
let parsed = null;
|
|
225
257
|
if (authoredLayerItems.length) {
|
|
226
258
|
parsed = authoredLayerItems.map((el) => {
|
|
@@ -240,24 +272,53 @@ class ContourLayerPanel extends ContourBase {
|
|
|
240
272
|
if (parsed) { parsed.forEach((it) => {
|
|
241
273
|
const name = typeof it === "string" ? it : (it.name || it.label || "");
|
|
242
274
|
const caption = (typeof it === "object" && it) ? (it.caption || it.subtitle || "") : "";
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
275
|
+
// Mint a stable per-item id (MAP-3): the reorder detail and every
|
|
276
|
+
// R31-86: prefer an explicit id; otherwise reuse a previously minted
|
|
277
|
+
// id for this name (so a rename + re-render does not change the
|
|
278
|
+
// layer's identity), else slug the name. The map persists across
|
|
279
|
+
// renders; the per-render Set only de-duplicates within one render.
|
|
280
|
+
if (this._layerIdByName == null) this._layerIdByName = new Map();
|
|
281
|
+
const explicitId = (typeof it === "object" && it && it.id) ? String(it.id) : "";
|
|
282
|
+
let layerId;
|
|
283
|
+
if (explicitId) {
|
|
284
|
+
layerId = explicitId;
|
|
285
|
+
} else if (this._layerIdByName.has(name)) {
|
|
286
|
+
layerId = this._layerIdByName.get(name);
|
|
287
|
+
} else {
|
|
288
|
+
const slug = name ? name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "";
|
|
289
|
+
layerId = slug || "layer";
|
|
290
|
+
this._layerIdByName.set(name, layerId);
|
|
291
|
+
}
|
|
292
|
+
if (this._layerIdSeen == null) this._layerIdSeen = new Set();
|
|
293
|
+
if (this._layerIdSeen.has(layerId)) {
|
|
294
|
+
let n = 2;
|
|
295
|
+
while (this._layerIdSeen.has(layerId + "-" + n)) n++;
|
|
296
|
+
layerId = layerId + "-" + n;
|
|
297
|
+
}
|
|
298
|
+
this._layerIdSeen.add(layerId);
|
|
299
|
+
const item = document.createElement("div");
|
|
300
|
+
item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
|
|
301
|
+
item.dataset.layerId = layerId;
|
|
302
|
+
// Drag handle: focusable grip for keyboard reorder (CDS-049).
|
|
303
|
+
// R31-89: gated by allow-reorder (default on), like the other
|
|
304
|
+
// per-layer controls, so a consumer can drop it.
|
|
305
|
+
if (this.getAttribute("allow-reorder") !== "false") {
|
|
306
|
+
const drag = document.createElement("button");
|
|
307
|
+
drag.type = "button";
|
|
308
|
+
drag.className = "c-drag-handle--dots";
|
|
309
|
+
drag.setAttribute("aria-label", labelText(this, "reorder", "Reorder") + " " + (name || labelText(this, "layer", "layer")));
|
|
310
|
+
drag.setAttribute("tabindex", "0");
|
|
311
|
+
item.appendChild(drag);
|
|
312
|
+
}
|
|
252
313
|
const toggle = document.createElement("button");
|
|
253
314
|
toggle.type = "button";
|
|
254
315
|
toggle.className = "c-layer-panel__toggle";
|
|
255
316
|
toggle.setAttribute("part", "visibility-toggle");
|
|
256
|
-
toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
|
|
317
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle") + " " + (name || labelText(this, "layer", "layer")));
|
|
257
318
|
const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
|
|
258
319
|
toggle.setAttribute("aria-pressed", String(!!isVisible));
|
|
259
320
|
toggle.checked = !!isVisible;
|
|
260
|
-
toggle
|
|
321
|
+
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>');
|
|
261
322
|
item.appendChild(toggle);
|
|
262
323
|
const nm = document.createElement("span");
|
|
263
324
|
nm.className = "c-layer-panel__name";
|
|
@@ -269,28 +330,35 @@ class ContourLayerPanel extends ContourBase {
|
|
|
269
330
|
cap.textContent = caption;
|
|
270
331
|
item.appendChild(cap);
|
|
271
332
|
}
|
|
272
|
-
|
|
273
|
-
opacity
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
333
|
+
// R31-89: opacity is gated by allow-opacity (default on).
|
|
334
|
+
if (this.getAttribute("allow-opacity") !== "false") {
|
|
335
|
+
const opacity = document.createElement("input");
|
|
336
|
+
opacity.type = "range";
|
|
337
|
+
opacity.className = "c-layer-panel__opacity";
|
|
338
|
+
opacity.min = "0";
|
|
339
|
+
opacity.max = "100";
|
|
340
|
+
opacity.setAttribute("aria-label", labelText(this, "opacity-of", "Opacity of") + " " + (name || "layer"));
|
|
341
|
+
// R31-87: a re-render restores the value the user dragged, not the
|
|
342
|
+
// authored default.
|
|
343
|
+
opacity.value = savedOpacity.has(name) ? savedOpacity.get(name) : ((typeof it === "object" && it.opacity != null) ? it.opacity : "100");
|
|
344
|
+
item.appendChild(opacity);
|
|
345
|
+
}
|
|
280
346
|
// rename input (hidden by default, toggled via button)
|
|
281
347
|
if (this.getAttribute("allow-rename") !== "false") {
|
|
282
348
|
const renameBtn = document.createElement("button");
|
|
283
349
|
renameBtn.type = "button";
|
|
284
|
-
renameBtn.className = "c-layer-panel__rename";
|
|
285
|
-
|
|
350
|
+
renameBtn.className = "c-btn c-btn--icon c-btn--ghost c-btn--sm c-layer-panel__rename";
|
|
351
|
+
// R31-144: icon-only rename; the name stays on aria-label.
|
|
352
|
+
setHTML(renameBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-pen" /></svg>');
|
|
286
353
|
renameBtn.setAttribute("aria-label", labelText(this, "rename", "Rename") + " " + (name || "layer"));
|
|
287
354
|
item.appendChild(renameBtn);
|
|
288
355
|
}
|
|
289
356
|
if (this.getAttribute("allow-duplicate") !== "false") {
|
|
290
357
|
const dupBtn = document.createElement("button");
|
|
291
358
|
dupBtn.type = "button";
|
|
292
|
-
dupBtn.className = "c-layer-panel__duplicate";
|
|
293
|
-
|
|
359
|
+
dupBtn.className = "c-btn c-btn--icon c-btn--ghost c-btn--sm c-layer-panel__duplicate";
|
|
360
|
+
// R31-144: icon-only duplicate.
|
|
361
|
+
setHTML(dupBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-copy" /></svg>');
|
|
294
362
|
dupBtn.setAttribute("aria-label", labelText(this, "duplicate", "Duplicate") + " " + (name || "layer"));
|
|
295
363
|
item.appendChild(dupBtn);
|
|
296
364
|
}
|
|
@@ -306,15 +374,20 @@ class ContourLayerPanel extends ContourBase {
|
|
|
306
374
|
const removeBtn = document.createElement("button");
|
|
307
375
|
removeBtn.type = "button";
|
|
308
376
|
removeBtn.className = "c-layer-panel__remove";
|
|
309
|
-
removeBtn
|
|
377
|
+
setHTML(removeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
|
|
310
378
|
removeBtn.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + (name || "layer"));
|
|
311
379
|
item.appendChild(removeBtn);
|
|
312
380
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
381
|
+
// R31-89: the projection selector is opt-in (allow-projection),
|
|
382
|
+
// because most maps do not reproject a single layer. Render it only
|
|
383
|
+
// when the author asks for it.
|
|
384
|
+
if (this.hasAttribute("allow-projection") && this.getAttribute("allow-projection") !== "false") {
|
|
385
|
+
const projSel = document.createElement("select");
|
|
386
|
+
projSel.className = "c-select c-layer-panel__projection";
|
|
387
|
+
projSel.setAttribute("aria-label", labelText(this, "projection-of", "Projection of") + " " + (name || labelText(this, "layer", "layer")));
|
|
388
|
+
["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
|
|
389
|
+
item.appendChild(projSel);
|
|
390
|
+
}
|
|
318
391
|
this.appendChild(item);
|
|
319
392
|
});
|
|
320
393
|
}
|
|
@@ -327,71 +400,93 @@ class ContourLayerPanel extends ContourBase {
|
|
|
327
400
|
if (this._wiredLayerPanel) return;
|
|
328
401
|
this._wiredLayerPanel = true;
|
|
329
402
|
// The panel's two controls (visibility toggle, opacity range) are rebuilt
|
|
330
|
-
|
|
403
|
+
const idOf = (item) => (item && item.dataset && item.dataset.layerId) || "";
|
|
331
404
|
this.addEventListener("change", (e) => {
|
|
332
405
|
const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
|
|
333
406
|
if (!item || !this.contains(item)) return;
|
|
334
407
|
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
408
|
+
const layerId = idOf(item);
|
|
335
409
|
if (e.target.classList.contains("c-layer-panel__toggle")) {
|
|
336
410
|
const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
|
|
337
411
|
e.target.checked = now;
|
|
338
412
|
e.target.setAttribute("aria-pressed", String(now));
|
|
339
|
-
e.target
|
|
340
|
-
this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
|
|
413
|
+
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>');
|
|
414
|
+
this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
341
415
|
} else if (e.target.classList.contains("c-layer-panel__opacity")) {
|
|
342
|
-
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
|
|
416
|
+
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { layerId, name, opacity: Number(e.target.value) } }));
|
|
343
417
|
} else if (e.target.classList.contains("c-layer-panel__projection")) {
|
|
344
|
-
this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
|
|
418
|
+
this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { layerId, name, projection: e.target.value } }));
|
|
345
419
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
420
|
+
});
|
|
421
|
+
// R31-87: opacity is live — `input` fires as the slider drags, so the
|
|
422
|
+
// engine follows the thumb, not only the released value (`change`).
|
|
423
|
+
this.addEventListener("input", (e) => {
|
|
424
|
+
const op = e.target;
|
|
425
|
+
if (!op || !op.classList || !op.classList.contains("c-layer-panel__opacity")) return;
|
|
426
|
+
const item = op.closest(".c-layer-panel__item");
|
|
427
|
+
if (!item || !this.contains(item)) return;
|
|
428
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
429
|
+
this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { layerId: idOf(item), name, opacity: Number(op.value) } }));
|
|
430
|
+
});
|
|
431
|
+
this.addEventListener("click", (e) => {
|
|
432
|
+
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
433
|
+
if (!btn || !this.contains(btn)) return;
|
|
434
|
+
const item = btn.closest(".c-layer-panel__item");
|
|
435
|
+
if (btn.classList.contains("c-layer-panel__toggle")) {
|
|
436
|
+
if (!item) return;
|
|
437
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
438
|
+
const layerId = idOf(item);
|
|
439
|
+
const now = btn.getAttribute("aria-pressed") !== "true";
|
|
440
|
+
btn.setAttribute("aria-pressed", String(now));
|
|
441
|
+
btn.checked = now;
|
|
442
|
+
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>');
|
|
443
|
+
this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (!item) return;
|
|
447
|
+
const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
|
|
448
|
+
const layerId = idOf(item);
|
|
449
|
+
if (btn.classList.contains("c-layer-panel__rename")) {
|
|
450
|
+
const nm = item.querySelector(".c-layer-panel__name");
|
|
451
|
+
if (nm) {
|
|
452
|
+
const input = document.createElement("input");
|
|
453
|
+
input.type = "text";
|
|
454
|
+
input.className = "c-input c-layer-panel__rename-input";
|
|
455
|
+
input.value = name;
|
|
456
|
+
input.setAttribute("aria-label", labelText(this, "rename-layer", "Rename layer"));
|
|
457
|
+
nm.replaceWith(input);
|
|
458
|
+
input.focus();
|
|
459
|
+
input.select();
|
|
460
|
+
let committed = false;
|
|
461
|
+
const commit = () => {
|
|
462
|
+
// R24-09: a committed flag set BEFORE replaceWith. The blur
|
|
463
|
+
if (committed) return;
|
|
464
|
+
if (!input.isConnected) return;
|
|
465
|
+
committed = true;
|
|
466
|
+
const trimmed = (input.value || "").trim();
|
|
376
467
|
const span = document.createElement("span");
|
|
377
468
|
span.className = "c-layer-panel__name";
|
|
378
469
|
span.textContent = trimmed || name;
|
|
379
470
|
input.replaceWith(span);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
471
|
+
if (trimmed && trimmed !== name) {
|
|
472
|
+
// R31-86: keep the layer's id across the rename so a re-render
|
|
473
|
+
// does not mint a new one from the new name.
|
|
474
|
+
if (this._layerIdByName == null) this._layerIdByName = new Map();
|
|
475
|
+
this._layerIdByName.set(trimmed, layerId);
|
|
476
|
+
this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { layerId, name, newName: trimmed } }));
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
input.addEventListener("keydown", (ev) => { if (ev.key === "Enter") { ev.preventDefault(); commit(); } else if (ev.key === "Escape") { ev.preventDefault(); input.value = name; commit(); } });
|
|
480
|
+
input.addEventListener("blur", commit, { once: true });
|
|
481
|
+
}
|
|
482
|
+
} else if (btn.classList.contains("c-layer-panel__duplicate")) {
|
|
483
|
+
this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
484
|
+
} else if (btn.classList.contains("c-layer-panel__zoom")) {
|
|
485
|
+
this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
486
|
+
} else if (btn.classList.contains("c-layer-panel__remove")) {
|
|
487
|
+
this.dispatchEvent(new CustomEvent("contour:layer-remove", { bubbles: true, composed: true, detail: { layerId, name } }));
|
|
488
|
+
}
|
|
489
|
+
});
|
|
395
490
|
this.addEventListener("keydown", (e) => {
|
|
396
491
|
if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
|
|
397
492
|
e.preventDefault();
|
|
@@ -416,7 +511,8 @@ class ContourLayerPanel extends ContourBase {
|
|
|
416
511
|
else this.insertBefore(items[newIdx], item);
|
|
417
512
|
(isDrag ? e.target : item).focus();
|
|
418
513
|
setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
|
|
419
|
-
|
|
514
|
+
// A stable per-layer id, not the display name: two layers can share
|
|
515
|
+
const layerIds = Array.from(this.querySelectorAll(".c-layer-panel__item")).map((el, i) => el.dataset.layerId || el.getAttribute("data-layer-id") || String(i));
|
|
420
516
|
this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
|
|
421
517
|
}
|
|
422
518
|
});
|
|
@@ -457,15 +553,30 @@ class ContourTimeSlider extends ContourBase {
|
|
|
457
553
|
track.setAttribute("aria-label", this.getAttribute("label") || this.getAttribute("time-label") || "Time");
|
|
458
554
|
const time = this.ensure(".c-time-slider__time", () => { const el = document.createElement("span"); el.className = "c-time-slider__time"; return el; });
|
|
459
555
|
const ct = this.getAttribute("current-time");
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
556
|
+
const timeFormat = this.getAttribute("time-format");
|
|
557
|
+
// R24-77: honour `time-format` through the shared Intl formatter instead
|
|
558
|
+
if (ct) { time.textContent = ct; track.setAttribute("aria-valuetext", ct); }
|
|
559
|
+
else if (timeFormat) { time.textContent = formatValue(String(track.value), timeFormat); track.removeAttribute("aria-valuetext"); }
|
|
560
|
+
else { time.textContent = String(track.value); track.removeAttribute("aria-valuetext"); }
|
|
561
|
+
// R24-77: a <datalist> gives the range real tick marks (the platform
|
|
562
|
+
const ticks = this.ensure("datalist", () => document.createElement("datalist"));
|
|
563
|
+
if (!ticks.id) ticks.id = contourId("time-slider-ticks");
|
|
564
|
+
setHTML(ticks, "");
|
|
565
|
+
const tMin = Number(track.min) || 0;
|
|
566
|
+
const tMax = Number(track.max) || 100;
|
|
567
|
+
for (let i = 0; i < 5; i++) {
|
|
568
|
+
const opt = document.createElement("option");
|
|
569
|
+
opt.value = String(Math.round(tMin + (tMax - tMin) * (i / 4)));
|
|
570
|
+
ticks.appendChild(opt);
|
|
571
|
+
}
|
|
572
|
+
track.setAttribute("list", ticks.id);
|
|
573
|
+
if (ticks.parentNode !== this) this.appendChild(ticks);
|
|
463
574
|
// speed selector
|
|
464
575
|
let speeds = null;
|
|
465
576
|
const speedsAttr = this.getAttribute("speeds");
|
|
466
577
|
if (speedsAttr) { try { speeds = JSON.parse(speedsAttr); } catch (e) { speeds = null; } }
|
|
467
578
|
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; });
|
|
468
|
-
speedSel
|
|
579
|
+
setHTML(speedSel, "");
|
|
469
580
|
const speedList = Array.isArray(speeds) ? speeds : [0.5, 1, 2, 5, 10];
|
|
470
581
|
speedList.forEach((sp) => {
|
|
471
582
|
const opt = document.createElement("option");
|
|
@@ -481,7 +592,8 @@ class ContourTimeSlider extends ContourBase {
|
|
|
481
592
|
if (showLoop) {
|
|
482
593
|
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; });
|
|
483
594
|
loopBtn.setAttribute("aria-pressed", this.hasAttribute("loop") ? "true" : "false");
|
|
484
|
-
|
|
595
|
+
// R31-137: icon-only loop toggle; the name stays on aria-label.
|
|
596
|
+
setHTML(loopBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-refresh" /></svg>');
|
|
485
597
|
} else {
|
|
486
598
|
const lb = this.querySelector(".c-time-slider__loop");
|
|
487
599
|
if (lb) lb.remove();
|
|
@@ -495,17 +607,10 @@ class ContourTimeSlider extends ContourBase {
|
|
|
495
607
|
}
|
|
496
608
|
enhance() {
|
|
497
609
|
// Playback reconciles with the is-playing attribute on EVERY render
|
|
498
|
-
// (R20 T-30): setting the attribute from outside starts the timer and
|
|
499
|
-
// removing it stops — it used to swap only the icon, contradicting the
|
|
500
|
-
// attribute-driven playback prose. The reconciler owns the play/pause
|
|
501
|
-
// events so every path (click, attribute, end-of-track) emits once.
|
|
502
610
|
if (this._timeSliderReconcile) this._timeSliderReconcile();
|
|
503
611
|
if (this._wiredTimeSlider) return;
|
|
504
612
|
this._wiredTimeSlider = true;
|
|
505
613
|
// Play advances the track one step per cadence and announces each move
|
|
506
|
-
// as contour:time-change, so a dashboard can animate a chart in lockstep.
|
|
507
|
-
// The loop stops at max, or on a second click, or when the host leaves
|
|
508
|
-
// the page (the disposer is registered once, like the loader's).
|
|
509
614
|
let timer = undefined;
|
|
510
615
|
const stop = () => { if (timer !== undefined) { clearInterval(timer); timer = undefined; } };
|
|
511
616
|
const syncReadout = () => {
|
|
@@ -513,7 +618,8 @@ class ContourTimeSlider extends ContourBase {
|
|
|
513
618
|
if (!track) return;
|
|
514
619
|
const time = this.querySelector(".c-time-slider__time");
|
|
515
620
|
const ct = this.getAttribute("current-time");
|
|
516
|
-
|
|
621
|
+
const tf = this.getAttribute("time-format");
|
|
622
|
+
if (time) time.textContent = ct ? ct : (tf ? formatValue(String(track.value), tf) : String(track.value));
|
|
517
623
|
if (ct) track.setAttribute("aria-valuetext", ct);
|
|
518
624
|
else track.removeAttribute("aria-valuetext");
|
|
519
625
|
};
|
|
@@ -527,9 +633,6 @@ class ContourTimeSlider extends ContourBase {
|
|
|
527
633
|
if (next > max) next = loop ? min : max;
|
|
528
634
|
track.value = String(next);
|
|
529
635
|
// The playhead writes back so a consumer reading `value` sees it —
|
|
530
|
-
// but not while the user is mid-gesture: the write re-renders, and a
|
|
531
|
-
// rebuilt node would break a track drag or close an open speed popup.
|
|
532
|
-
// The next tick after the gesture ends catches the attribute up.
|
|
533
636
|
const speedSel = this.querySelector(".c-time-slider__speed");
|
|
534
637
|
const interacting = this._timeSliderScrubbing || (speedSel && document.activeElement === speedSel);
|
|
535
638
|
if (!interacting) this.setAttribute("value", String(next));
|
|
@@ -573,10 +676,6 @@ class ContourTimeSlider extends ContourBase {
|
|
|
573
676
|
}
|
|
574
677
|
});
|
|
575
678
|
// Manual scrubbing is a first-class input (R20 T-30): it emits the same
|
|
576
|
-
// contour:time-change playback does and writes the playhead back. The
|
|
577
|
-
// track used to be silent under the user's hand.
|
|
578
|
-
// Track the drag so playhead writeback never rebuilds the node under
|
|
579
|
-
// the user's pointer; the commit (change) writes the value back.
|
|
580
679
|
this.addEventListener("pointerdown", (e) => {
|
|
581
680
|
if (e.target && e.target.closest && e.target.closest(".c-time-slider__track")) this._timeSliderScrubbing = true;
|
|
582
681
|
}, { passive: true });
|
|
@@ -619,8 +718,8 @@ class ContourTimeSlider extends ContourBase {
|
|
|
619
718
|
}
|
|
620
719
|
define("contour-time-slider", ContourTimeSlider);
|
|
621
720
|
class ContourHexbin extends ContourBase {
|
|
622
|
-
static get observed() { return ["label", "cells", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
623
|
-
static get properties() { return { label: { attribute: "label" }, cells: { attribute: "cells" }, src: { attribute: "src" } }; }
|
|
721
|
+
static get observed() { return ["label", "cells", "width", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
722
|
+
static get properties() { return { label: { attribute: "label" }, cells: { attribute: "cells" }, width: { attribute: "width" }, src: { attribute: "src" } }; }
|
|
624
723
|
render() {
|
|
625
724
|
this.classList.add("c-hexbin");
|
|
626
725
|
// Cells are focusable marks; role=img makes them presentational.
|
|
@@ -642,33 +741,65 @@ class ContourHexbin extends ContourBase {
|
|
|
642
741
|
// Slotted content support: authored .c-hexbin__cell children take
|
|
643
742
|
// precedence over the JSON `cells` attribute.
|
|
644
743
|
const authoredCells = Array.from(this.querySelectorAll(":scope > .c-hexbin__cell"));
|
|
645
|
-
|
|
744
|
+
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; });
|
|
745
|
+
tip.setAttribute("hidden", "");
|
|
746
|
+
// Container width: author-supplied `width` attribute wins, otherwise the
|
|
747
|
+
// component sizes itself to its grid (no hardcoded 16rem).
|
|
748
|
+
const width = this.getAttribute("width");
|
|
749
|
+
if (width) this.style.inlineSize = width;
|
|
750
|
+
else this.style.removeProperty("inline-size");
|
|
646
751
|
if (authoredCells.length) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
752
|
+
// R28-33 (CONS-08): authored cells keep the styles the author painted
|
|
753
|
+
const cols = Math.ceil(Math.sqrt(authoredCells.length || 1));
|
|
754
|
+
// minmax(0, 1fr), not 1fr: a bare 1fr is minmax(auto, 1fr), so a cell's
|
|
755
|
+
// text min-content floors the track and the grid overflows its host on
|
|
756
|
+
// a narrow viewport. Cells clip their own text (clip-path), so the track
|
|
757
|
+
// is free to shrink to the container.
|
|
758
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", minmax(0, 1fr))";
|
|
759
|
+
authoredCells.forEach((el, i) => el.setAttribute("tabindex", i === 0 ? "0" : "-1"));
|
|
760
|
+
} else {
|
|
761
|
+
let parsed = null;
|
|
762
|
+
if (effectiveCells) { try { parsed = JSON.parse(effectiveCells); } catch (e) { parsed = null; } }
|
|
763
|
+
if (Array.isArray(parsed)) {
|
|
764
|
+
try {
|
|
765
|
+
Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
|
|
766
|
+
const cols = Math.ceil(Math.sqrt(parsed.length || 1));
|
|
767
|
+
this.style.gridTemplateColumns = "repeat(" + cols + ", minmax(0, 1fr))";
|
|
768
|
+
// R28-33 (CONS-08): restore the value→color ramp. Normalise each
|
|
769
|
+
const nums = parsed.map((c) => Number(typeof c === "object" && c !== null ? c.value : c)).filter((n) => Number.isFinite(n));
|
|
770
|
+
const min = nums.length ? Math.min(...nums) : 0;
|
|
771
|
+
const max = nums.length ? Math.max(...nums) : 0;
|
|
772
|
+
const span = max - min;
|
|
773
|
+
parsed.forEach((c, i) => {
|
|
774
|
+
const cell = document.createElement("div");
|
|
775
|
+
cell.className = "c-hexbin__cell";
|
|
776
|
+
cell.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
777
|
+
const val = (typeof c === "object" && c !== null && c.value != null) ? c.value : c;
|
|
778
|
+
if (val != null && val !== "") { cell.textContent = val; cell.setAttribute("data-title", String(val)); }
|
|
779
|
+
const n = Number(val);
|
|
780
|
+
if (Number.isFinite(n)) {
|
|
781
|
+
const t = span > 0 ? (n - min) / span : 1;
|
|
782
|
+
const pct = Math.round(20 + t * 60);
|
|
783
|
+
cell.style.background = "color-mix(in oklab, var(--color-primary) " + pct + "%, var(--color-surface-2))";
|
|
784
|
+
}
|
|
785
|
+
this.appendChild(cell);
|
|
786
|
+
});
|
|
787
|
+
// Legend: a value→color ramp so the hexbin encodes value, not just
|
|
788
|
+
// hue. Low = surface-2 tinted, high = primary tinted.
|
|
789
|
+
if (span > 0 && nums.length) {
|
|
790
|
+
const legend = this.ensure(".c-hexbin__legend", () => { const el = document.createElement("div"); el.className = "c-hexbin__legend"; return el; });
|
|
791
|
+
legend.textContent = "";
|
|
792
|
+
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));
|
|
793
|
+
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));
|
|
794
|
+
const loLab = document.createElement("span"); loLab.className = "c-hexbin__legend-label"; loLab.textContent = String(min);
|
|
795
|
+
const hiLab = document.createElement("span"); hiLab.className = "c-hexbin__legend-label"; hiLab.textContent = String(max);
|
|
796
|
+
legend.appendChild(lo); legend.appendChild(loLab); legend.appendChild(hi); legend.appendChild(hiLab);
|
|
797
|
+
}
|
|
798
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
799
|
+
} else {
|
|
800
|
+
Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
|
|
801
|
+
renderEmpty(this, "hexbin");
|
|
802
|
+
}
|
|
672
803
|
}
|
|
673
804
|
}
|
|
674
805
|
enhance() {
|
|
@@ -676,11 +807,11 @@ class ContourHexbin extends ContourBase {
|
|
|
676
807
|
this._wiredHexbin = true;
|
|
677
808
|
wireMapItems(this, ".c-hexbin__cell", ".c-hexbin__tooltip");
|
|
678
809
|
}
|
|
679
|
-
|
|
680
|
-
define("contour-hexbin", ContourHexbin);
|
|
810
|
+
}
|
|
811
|
+
define("contour-hexbin", ContourHexbin);
|
|
681
812
|
class ContourFlowMap extends ContourBase {
|
|
682
|
-
static get observed() { return ["label", "nodes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
683
|
-
static get properties() { return { label: { attribute: "label" }, nodes: { attribute: "nodes" }, src: { attribute: "src" } }; }
|
|
813
|
+
static get observed() { return ["label", "nodes", "flows", "edges", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
814
|
+
static get properties() { return { label: { attribute: "label" }, nodes: { attribute: "nodes" }, flows: { attribute: "flows" }, edges: { attribute: "edges" }, src: { attribute: "src" } }; }
|
|
684
815
|
render() {
|
|
685
816
|
this.classList.add("c-flow-map");
|
|
686
817
|
// Nodes are focusable marks; role=img makes them presentational.
|
|
@@ -704,7 +835,7 @@ class ContourFlowMap extends ContourBase {
|
|
|
704
835
|
const authoredNodes = Array.from(this.querySelectorAll(":scope > .c-flow-map__node"));
|
|
705
836
|
let parsed = null;
|
|
706
837
|
if (authoredNodes.length) {
|
|
707
|
-
parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("title") || "");
|
|
838
|
+
parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
|
|
708
839
|
authoredNodes.forEach((el) => el.remove());
|
|
709
840
|
} else if (effectiveNodes) {
|
|
710
841
|
try { parsed = JSON.parse(effectiveNodes); } catch (e) { parsed = null; }
|
|
@@ -717,7 +848,7 @@ class ContourFlowMap extends ContourBase {
|
|
|
717
848
|
node.className = "c-flow-map__node" + (n.source ? " c-flow-map__node--source" : "") + (n.target ? " c-flow-map__node--target" : "");
|
|
718
849
|
node.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
719
850
|
node.textContent = typeof n === "string" ? n : (n.label || n.name || "");
|
|
720
|
-
if (typeof n === "object" && (n.label || n.name)) node.setAttribute("title", n.label || n.name);
|
|
851
|
+
if (typeof n === "object" && (n.label || n.name)) node.setAttribute("data-title", n.label || n.name);
|
|
721
852
|
this.appendChild(node);
|
|
722
853
|
});
|
|
723
854
|
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; });
|
|
@@ -727,6 +858,62 @@ class ContourFlowMap extends ContourBase {
|
|
|
727
858
|
Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
|
|
728
859
|
renderEmpty(this, "flow-map");
|
|
729
860
|
}
|
|
861
|
+
// UG-11 (D1): a `flows` (alias `edges`) JSON array renders a visible,
|
|
862
|
+
const flowsRaw = (this.flows != null && this.flows !== "") ? this.flows
|
|
863
|
+
: ((this.edges != null && this.edges !== "") ? this.edges
|
|
864
|
+
: (this._remoteData && this._remoteData.flows != null ? JSON.stringify(this._remoteData.flows) : null));
|
|
865
|
+
let flows = null;
|
|
866
|
+
if (flowsRaw != null) {
|
|
867
|
+
try {
|
|
868
|
+
const parsedFlows = JSON.parse(flowsRaw);
|
|
869
|
+
if (Array.isArray(parsedFlows)) flows = parsedFlows;
|
|
870
|
+
else warnBadJson(this, "flows", new Error("expected an array"));
|
|
871
|
+
} catch (e) { warnBadJson(this, "flows", e); }
|
|
872
|
+
}
|
|
873
|
+
const oldSummary = this.querySelector(".c-flow-map__summary");
|
|
874
|
+
if (flows) {
|
|
875
|
+
const wrap = this.ensure(".c-flow-map__summary", () => { const el = document.createElement("div"); el.className = "c-flow-map__summary c-table-wrap"; return el; });
|
|
876
|
+
let table = wrap.querySelector("table");
|
|
877
|
+
if (!table) { table = document.createElement("table"); table.className = "c-table c-flow-map__table"; wrap.appendChild(table); }
|
|
878
|
+
setHTML(table, "");
|
|
879
|
+
// A caption names the table before the first cell, the same contract
|
|
880
|
+
// the chart's data-table fallback follows.
|
|
881
|
+
const cap = document.createElement("caption");
|
|
882
|
+
cap.textContent = labelText(this, "flow-summary", "Flow summary");
|
|
883
|
+
table.appendChild(cap);
|
|
884
|
+
const thead = document.createElement("thead");
|
|
885
|
+
const hr = document.createElement("tr");
|
|
886
|
+
[["source", "Source"], ["target", "Target"], ["magnitude", "Magnitude"]].forEach(([key, fallback]) => {
|
|
887
|
+
const th = document.createElement("th");
|
|
888
|
+
th.setAttribute("scope", "col");
|
|
889
|
+
th.textContent = labelText(this, key, fallback);
|
|
890
|
+
hr.appendChild(th);
|
|
891
|
+
});
|
|
892
|
+
thead.appendChild(hr);
|
|
893
|
+
table.appendChild(thead);
|
|
894
|
+
const tbody = document.createElement("tbody");
|
|
895
|
+
const endName = (v) => typeof v === "string" ? v : ((v && typeof v === "object") ? String(v.label || v.name || v.id || "") : "");
|
|
896
|
+
flows.forEach((f) => {
|
|
897
|
+
const edge = (f && typeof f === "object") ? f : {};
|
|
898
|
+
const tr = document.createElement("tr");
|
|
899
|
+
const th = document.createElement("th");
|
|
900
|
+
th.setAttribute("scope", "row");
|
|
901
|
+
th.textContent = endName(edge.source);
|
|
902
|
+
tr.appendChild(th);
|
|
903
|
+
const tdTarget = document.createElement("td");
|
|
904
|
+
tdTarget.textContent = endName(edge.target);
|
|
905
|
+
tr.appendChild(tdTarget);
|
|
906
|
+
const tdMag = document.createElement("td");
|
|
907
|
+
const raw = edge.value != null ? edge.value : edge.magnitude;
|
|
908
|
+
const n = Number(raw);
|
|
909
|
+
tdMag.textContent = (raw == null || raw === "") ? "" : (Number.isFinite(n) ? (n > 0 ? "+" : "") + n : String(raw));
|
|
910
|
+
tr.appendChild(tdMag);
|
|
911
|
+
tbody.appendChild(tr);
|
|
912
|
+
});
|
|
913
|
+
table.appendChild(tbody);
|
|
914
|
+
} else if (oldSummary) {
|
|
915
|
+
oldSummary.remove();
|
|
916
|
+
}
|
|
730
917
|
}
|
|
731
918
|
enhance() {
|
|
732
919
|
if (this._wiredFlowMap) return;
|
|
@@ -736,7 +923,7 @@ class ContourFlowMap extends ContourBase {
|
|
|
736
923
|
}
|
|
737
924
|
define("contour-flow-map", ContourFlowMap);
|
|
738
925
|
class ContourIsochrone extends ContourBase {
|
|
739
|
-
static get observed() { return ["label", "center", "rings", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
926
|
+
static get observed() { return ["label", "center", "rings", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
740
927
|
static get properties() { return { label: { attribute: "label" }, center: { attribute: "center" }, rings: { attribute: "rings" }, src: { attribute: "src" } }; }
|
|
741
928
|
render() {
|
|
742
929
|
this.classList.add("c-isochrone");
|
|
@@ -769,7 +956,7 @@ class ContourIsochrone extends ContourBase {
|
|
|
769
956
|
const authoredRings = Array.from(this.querySelectorAll(":scope > .c-isochrone__ring"));
|
|
770
957
|
let parsed = null;
|
|
771
958
|
if (authoredRings.length) {
|
|
772
|
-
parsed = authoredRings.map((el) => el.textContent || el.getAttribute("title") || "");
|
|
959
|
+
parsed = authoredRings.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
|
|
773
960
|
authoredRings.forEach((el) => el.remove());
|
|
774
961
|
} else if (effectiveRings) {
|
|
775
962
|
try { parsed = JSON.parse(effectiveRings); } catch (e) { parsed = null; }
|
|
@@ -780,15 +967,13 @@ class ContourIsochrone extends ContourBase {
|
|
|
780
967
|
parsed.forEach((r, i) => {
|
|
781
968
|
const ring = document.createElement("span");
|
|
782
969
|
// A ring may be a string or an object. Concatenating the object put
|
|
783
|
-
// "[object Object]" in the class list and produced two bogus classes
|
|
784
|
-
// for a label containing a space; the modifier is one slug now.
|
|
785
970
|
const raw = typeof r === "string" ? r : (r && (r.label || r.name || r.value || r.min));
|
|
786
971
|
const ringLabel = raw === undefined || raw === null ? "" : String(raw);
|
|
787
972
|
const slug = ringLabel.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
788
973
|
ring.className = "c-isochrone__ring" + (slug ? " c-isochrone__ring--" + slug : "");
|
|
789
974
|
ring.setAttribute("tabindex", i === 0 ? "0" : "-1");
|
|
790
975
|
ring.setAttribute("aria-label", ringLabel || "Isochrone ring " + (i + 1));
|
|
791
|
-
if (ringLabel) ring.setAttribute("title", ringLabel);
|
|
976
|
+
if (ringLabel) ring.setAttribute("data-title", ringLabel);
|
|
792
977
|
this.appendChild(ring);
|
|
793
978
|
});
|
|
794
979
|
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; });
|
|
@@ -807,7 +992,7 @@ class ContourIsochrone extends ContourBase {
|
|
|
807
992
|
}
|
|
808
993
|
define("contour-isochrone", ContourIsochrone);
|
|
809
994
|
class ContourCatchment extends ContourBase {
|
|
810
|
-
static get observed() { return ["label", "area", "center", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
995
|
+
static get observed() { return ["label", "area", "center", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
811
996
|
static get properties() { return { label: { attribute: "label" }, area: { attribute: "area" }, center: { attribute: "center" }, src: { attribute: "src" } }; }
|
|
812
997
|
render() {
|
|
813
998
|
this.classList.add("c-catchment");
|
|
@@ -881,16 +1066,24 @@ class ContourCatchment extends ContourBase {
|
|
|
881
1066
|
}
|
|
882
1067
|
define("contour-catchment", ContourCatchment);
|
|
883
1068
|
class ContourCompassFull extends ContourBase {
|
|
884
|
-
static get observed() { return ["label", "needle", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1069
|
+
static get observed() { return ["label", "needle", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "empty", "no-cache"]; }
|
|
885
1070
|
static get properties() { return { label: { attribute: "label" }, needle: { attribute: "needle" }, src: { attribute: "src" } }; }
|
|
886
1071
|
render() {
|
|
887
1072
|
this.classList.add("c-compass");
|
|
1073
|
+
// R24-47: role=img so screen readers announce the compass as a single
|
|
1074
|
+
// image with a label, not a collection of unlabeled text nodes.
|
|
1075
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
888
1076
|
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Compass");
|
|
889
1077
|
const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
|
|
890
1078
|
wireStates(this);
|
|
891
1079
|
loadRemote(this, "needle");
|
|
892
1080
|
if (renderStates(this, "compass")) return;
|
|
893
1081
|
const needle = remoteData(this, "needle") || (this._remoteData && (this._remoteData.needle || this._remoteData.value));
|
|
1082
|
+
// R24-78: an empty compass shows only its empty state. The four cardinal
|
|
1083
|
+
if (!needle && !label) {
|
|
1084
|
+
renderEmpty(this, "compass");
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
894
1087
|
// Cardinal directions.
|
|
895
1088
|
for (const dir of ["n", "s", "e", "w"]) {
|
|
896
1089
|
const cls = ".c-compass__label--" + dir;
|
|
@@ -935,16 +1128,11 @@ class ContourCompassFull extends ContourBase {
|
|
|
935
1128
|
const n = this.querySelector("svg.c-compass__needle, .c-compass__needle");
|
|
936
1129
|
if (n) n.remove();
|
|
937
1130
|
}
|
|
938
|
-
if (!needle && !label) {
|
|
939
|
-
renderEmpty(this, "compass");
|
|
940
|
-
}
|
|
941
1131
|
}
|
|
942
1132
|
enhance() {
|
|
943
1133
|
if (this._wiredCompass) return;
|
|
944
1134
|
this._wiredCompass = true;
|
|
945
1135
|
// A cardinal is the compass's input: activate one to set the bearing and
|
|
946
|
-
// report it. The labels are rebuilt by render, so the handler is delegated
|
|
947
|
-
// on the host (rule 12) and resolves the degrees from the label itself.
|
|
948
1136
|
const DEGREES = { n: 0, e: 90, s: 180, w: 270 };
|
|
949
1137
|
const setBearing = (dir) => {
|
|
950
1138
|
const deg = DEGREES[dir];
|
|
@@ -976,10 +1164,14 @@ class ContourCompassFull extends ContourBase {
|
|
|
976
1164
|
}
|
|
977
1165
|
define("contour-compass", ContourCompassFull);
|
|
978
1166
|
class ContourLayerSwitch extends ContourBase {
|
|
979
|
-
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1167
|
+
static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
980
1168
|
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
981
1169
|
render() {
|
|
982
1170
|
this.classList.add("c-layer-switch");
|
|
1171
|
+
// R31-90: a labelled list of layers, so AT announces the group and each
|
|
1172
|
+
// item's position rather than a bare run of buttons.
|
|
1173
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "list");
|
|
1174
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "layer-switch", "Layer switch"));
|
|
983
1175
|
wireStates(this);
|
|
984
1176
|
loadRemote(this, "items");
|
|
985
1177
|
if (renderStates(this, "layer-switch")) return;
|
|
@@ -993,10 +1185,21 @@ class ContourLayerSwitch extends ContourBase {
|
|
|
993
1185
|
capped.forEach((it) => {
|
|
994
1186
|
const item = document.createElement("div");
|
|
995
1187
|
item.className = "c-layer-switch__item";
|
|
996
|
-
item.setAttribute("role", "
|
|
1188
|
+
item.setAttribute("role", "listitem");
|
|
1189
|
+
// R31-90: mint a stable layerId (id, else a name slug, else a
|
|
1190
|
+
// sequence) so the toggle event identifies the layer. The switch
|
|
1191
|
+
// previously emitted layerId:"" on every toggle.
|
|
1192
|
+
const itemName = typeof it === "string" ? it : (it.name || it.label || "");
|
|
1193
|
+
const baseId = (typeof it === "object" && it && it.id) ? String(it.id) : (itemName ? itemName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") : "");
|
|
1194
|
+
this._layerSwitchSeq = (this._layerSwitchSeq || 0) + 1;
|
|
1195
|
+
item.dataset.layerId = baseId || ("layer-" + this._layerSwitchSeq);
|
|
997
1196
|
const sw = document.createElement("span");
|
|
998
1197
|
sw.className = "c-layer-switch__swatch";
|
|
999
|
-
|
|
1198
|
+
// R31-154: shape is the primary channel, colour the secondary. A
|
|
1199
|
+
// known shape draws with currentColor; the colour sets that color.
|
|
1200
|
+
const shape = (typeof it === "object" && it && it.shape) ? String(it.shape) : "";
|
|
1201
|
+
if (SHAPES.has(shape)) sw.classList.add("c-swatch--" + shape);
|
|
1202
|
+
if (it.color) { const safe = safeColor(it.color); if (safe) { if (SHAPES.has(shape)) sw.style.color = safe; else sw.style.background = safe; } }
|
|
1000
1203
|
sw.setAttribute("aria-hidden", "true");
|
|
1001
1204
|
item.appendChild(sw);
|
|
1002
1205
|
const name = document.createElement("span");
|
|
@@ -1009,12 +1212,14 @@ class ContourLayerSwitch extends ContourBase {
|
|
|
1009
1212
|
c.textContent = it.count;
|
|
1010
1213
|
item.appendChild(c);
|
|
1011
1214
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1215
|
+
const toggle = document.createElement("button");
|
|
1216
|
+
toggle.className = "c-layer-switch__toggle";
|
|
1217
|
+
toggle.type = "button";
|
|
1218
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle") + " " + (typeof it === "string" ? it : (it.name || it.label || labelText(this, "layer", "layer"))));
|
|
1219
|
+
// R24-45: honor items[].visible (default true).
|
|
1220
|
+
const visible = typeof it === "object" && it.visible === false ? false : true;
|
|
1221
|
+
toggle.setAttribute("aria-pressed", String(visible));
|
|
1222
|
+
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>');
|
|
1018
1223
|
item.appendChild(toggle);
|
|
1019
1224
|
this.appendChild(item);
|
|
1020
1225
|
});
|
|
@@ -1032,9 +1237,13 @@ class ContourLayerSwitch extends ContourBase {
|
|
|
1032
1237
|
if (!btn || !this.contains(btn)) return;
|
|
1033
1238
|
const item = btn.closest(".c-layer-switch__item");
|
|
1034
1239
|
const name = item ? (item.querySelector(".c-layer-switch__name")?.textContent || "") : "";
|
|
1240
|
+
const layerId = item && item.dataset ? (item.dataset.layerId || "") : "";
|
|
1035
1241
|
const now = btn.getAttribute("aria-pressed") !== "true";
|
|
1036
1242
|
btn.setAttribute("aria-pressed", String(now));
|
|
1037
|
-
|
|
1243
|
+
// R31-90: the toggle now carries a real layerId (minted in render). The
|
|
1244
|
+
// switch keeps its own contour:layer-toggle event; the layer panel emits
|
|
1245
|
+
// the equivalent contour:layer-visibility. Both are in the vocabulary.
|
|
1246
|
+
this.dispatchEvent(new CustomEvent("contour:layer-toggle", { bubbles: true, composed: true, detail: { layerId, name, visible: now } }));
|
|
1038
1247
|
});
|
|
1039
1248
|
this.addEventListener("keydown", (e) => {
|
|
1040
1249
|
const btn = e.target && e.target.closest ? e.target.closest(".c-layer-switch__toggle") : null;
|
|
@@ -1044,6 +1253,45 @@ class ContourLayerSwitch extends ContourBase {
|
|
|
1044
1253
|
}
|
|
1045
1254
|
}
|
|
1046
1255
|
define("contour-layer-switch", ContourLayerSwitch);
|
|
1256
|
+
// R31-128: basemap switcher. A row of style buttons; clicking one sets `value`
|
|
1257
|
+
// and emits contour:map-style {style,name} (the contract the map-area drives).
|
|
1258
|
+
class ContourBasemapSwitcher extends ContourBase {
|
|
1259
|
+
static get observed() { return ["items", "value", "label"]; }
|
|
1260
|
+
static get properties() { return { items: { attribute: "items" }, value: { attribute: "value" }, label: { attribute: "label" } }; }
|
|
1261
|
+
render() {
|
|
1262
|
+
this.classList.add("c-basemap-switcher");
|
|
1263
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
1264
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || labelText(this, "basemap", "Basemap"));
|
|
1265
|
+
let items = [];
|
|
1266
|
+
try { const p = JSON.parse(this.getAttribute("items") || "[]"); if (Array.isArray(p)) items = p; } catch (e) { /* empty */ }
|
|
1267
|
+
const value = this.getAttribute("value");
|
|
1268
|
+
Array.from(this.querySelectorAll(".c-basemap-switcher__item")).forEach((n) => n.remove());
|
|
1269
|
+
items.forEach((it) => {
|
|
1270
|
+
const name = typeof it === "string" ? it : (it.label || it.value || it);
|
|
1271
|
+
const val = typeof it === "string" ? it : (it.value || it.label || it);
|
|
1272
|
+
const b = document.createElement("button");
|
|
1273
|
+
b.type = "button";
|
|
1274
|
+
b.className = "c-basemap-switcher__item c-btn c-btn--sm" + (value === val ? " is-active" : "");
|
|
1275
|
+
b.textContent = name;
|
|
1276
|
+
b.dataset.value = val;
|
|
1277
|
+
if (value === val) b.setAttribute("aria-pressed", "true");
|
|
1278
|
+
this.appendChild(b);
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
enhance() {
|
|
1282
|
+
if (this._wiredBasemap) return;
|
|
1283
|
+
this._wiredBasemap = true;
|
|
1284
|
+
this.addEventListener("click", (e) => {
|
|
1285
|
+
const b = e.target && e.target.closest ? e.target.closest(".c-basemap-switcher__item") : null;
|
|
1286
|
+
if (!b || !this.contains(b)) return;
|
|
1287
|
+
const val = b.dataset.value;
|
|
1288
|
+
const name = (b.textContent || "").trim();
|
|
1289
|
+
this.setAttribute("value", val);
|
|
1290
|
+
this.dispatchEvent(new CustomEvent("contour:map-style", { bubbles: true, composed: true, detail: { style: val, name } }));
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
define("contour-basemap-switcher", ContourBasemapSwitcher);
|
|
1047
1295
|
class ContourMapSlot extends ContourBase {
|
|
1048
1296
|
static get observed() { return ["attribution", "scale", "chrome"]; }
|
|
1049
1297
|
static get properties() { return { attribution: { attribute: "attribution" }, scale: { attribute: "scale" }, chrome: { attribute: "chrome" } }; }
|
|
@@ -1077,14 +1325,31 @@ class ContourMapSlot extends ContourBase {
|
|
|
1077
1325
|
}
|
|
1078
1326
|
define("contour-map-slot", ContourMapSlot);
|
|
1079
1327
|
class ContourMapArea extends ContourBase {
|
|
1080
|
-
static get observed() { return ["attribution", "attribution-mark", "scale", "controls"]; }
|
|
1081
|
-
static get properties() { return { attribution: { attribute: "attribution" }, "attribution-mark": { attribute: "attribution-mark" }, scale: { attribute: "scale" }, controls: { attribute: "controls" } }; }
|
|
1328
|
+
static get observed() { return ["attribution", "attribution-mark", "scale", "controls", "style", "style-name", "src"]; }
|
|
1329
|
+
static get properties() { return { attribution: { attribute: "attribution" }, "attribution-mark": { attribute: "attribution-mark" }, scale: { attribute: "scale" }, controls: { attribute: "controls" }, "style-name": { attribute: "style-name" } }; }
|
|
1082
1330
|
render() {
|
|
1083
1331
|
this.classList.add("c-map-area");
|
|
1332
|
+
// R31-92: the engine container is styled through `.c-map-slot` (the seam
|
|
1333
|
+
// `.c-map-slot > [data-map]` fills). The map-area carries both classes so a
|
|
1334
|
+
// consumer's engine div gets the slot's sizing and chrome tokens.
|
|
1335
|
+
this.classList.add("c-map-slot");
|
|
1336
|
+
// R31-85: the style-switch contract. When a `style` is set (by a basemap
|
|
1337
|
+
// switcher or the author) and it changed, emit contour:map-style so the
|
|
1338
|
+
// engine swaps styles, then re-emit contour:map-ready once the new style
|
|
1339
|
+
// is applied. Without this path a switcher had no event to drive.
|
|
1340
|
+
const style = this.getAttribute("style");
|
|
1341
|
+
if (style && style !== this._lastMapStyle) {
|
|
1342
|
+
this._lastMapStyle = style;
|
|
1343
|
+
const name = this.getAttribute("style-name") || style;
|
|
1344
|
+
this.dispatchEvent(new CustomEvent("contour:map-style", { bubbles: true, composed: true, detail: { style, name } }));
|
|
1345
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => this.dispatchEvent(new CustomEvent("contour:map-ready", { bubbles: true, composed: true })));
|
|
1346
|
+
}
|
|
1084
1347
|
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
1085
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Map area");
|
|
1348
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "map-area", "Map area"));
|
|
1086
1349
|
const attribution = this.getAttribute("attribution");
|
|
1087
|
-
|
|
1350
|
+
// `attribution="engine"` means the engine draws its own credit (an
|
|
1351
|
+
// AttributionControl): the seam renders nothing, so the two never double.
|
|
1352
|
+
if (attribution && attribution !== "engine") {
|
|
1088
1353
|
const a = this.ensure(".c-map-slot__attribution", () => { const el = document.createElement("div"); el.className = "c-map-slot__attribution"; return el; });
|
|
1089
1354
|
a.textContent = attribution;
|
|
1090
1355
|
} else {
|
|
@@ -1100,7 +1365,8 @@ class ContourMapArea extends ContourBase {
|
|
|
1100
1365
|
if (m) m.remove();
|
|
1101
1366
|
}
|
|
1102
1367
|
const scale = this.getAttribute("scale");
|
|
1103
|
-
|
|
1368
|
+
// `scale="engine"` defers to the engine's own ScaleControl (no doubling).
|
|
1369
|
+
if (scale && scale !== "engine") {
|
|
1104
1370
|
const sc = this.ensure(".c-map-slot__scale", () => { const el = document.createElement("div"); el.className = "c-map-slot__scale"; return el; });
|
|
1105
1371
|
sc.textContent = scale;
|
|
1106
1372
|
} else {
|
|
@@ -1112,12 +1378,24 @@ class ContourMapArea extends ContourBase {
|
|
|
1112
1378
|
try {
|
|
1113
1379
|
const parsed = JSON.parse(controls);
|
|
1114
1380
|
const wrap = this.ensure(".c-map-slot__controls", () => { const el = document.createElement("div"); el.className = "c-map-slot__controls"; return el; });
|
|
1115
|
-
wrap
|
|
1381
|
+
setHTML(wrap, "");
|
|
1116
1382
|
parsed.forEach((c) => {
|
|
1117
1383
|
const btn = document.createElement("button");
|
|
1118
1384
|
btn.className = "c-map-slot__control";
|
|
1119
1385
|
btn.type = "button";
|
|
1120
|
-
|
|
1386
|
+
// R31-83: a control is a string or `{label, action}`. `action` names
|
|
1387
|
+
// the engine method (zoomIn/zoomOut/…), so the click handler never
|
|
1388
|
+
// guesses from the visible text; `label` is the accessible name.
|
|
1389
|
+
const isObj = typeof c === "object" && c;
|
|
1390
|
+
const label = isObj ? (c.label || c.action || "") : String(c);
|
|
1391
|
+
// R31-146: a known action carries a glyph (icon+text); an unknown
|
|
1392
|
+
// action stays text-only so the control is never blank.
|
|
1393
|
+
const GLYPH = { zoomIn: "i-plus", zoomOut: "i-minus", zoomReset: "i-crosshair", zoom: "i-zoom", reset: "i-refresh", locate: "i-crosshair", recenter: "i-crosshair" };
|
|
1394
|
+
const glyph = isObj && c.action ? GLYPH[String(c.action)] : null;
|
|
1395
|
+
if (glyph) setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + glyph + '" /></svg>');
|
|
1396
|
+
btn.appendChild(document.createTextNode((glyph ? " " : "") + label));
|
|
1397
|
+
if (isObj && c.action) btn.dataset.mapAction = String(c.action);
|
|
1398
|
+
if (isObj && c.label) btn.setAttribute("aria-label", String(c.label));
|
|
1121
1399
|
wrap.appendChild(btn);
|
|
1122
1400
|
});
|
|
1123
1401
|
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
@@ -1130,20 +1408,19 @@ class ContourMapArea extends ContourBase {
|
|
|
1130
1408
|
if (this._wiredMapArea) return;
|
|
1131
1409
|
this._wiredMapArea = true;
|
|
1132
1410
|
// Map-engine seam (BY3-I3): Contour never imports a map library. A
|
|
1133
|
-
// consumer
|
|
1134
|
-
//
|
|
1135
|
-
//
|
|
1411
|
+
// consumer creates the engine (MapLibre, Mapbox, deck.gl …) and hands it
|
|
1412
|
+
// over; the seam stores it, reports the viewport and drives the authored
|
|
1413
|
+
// chrome, and stays engine-agnostic throughout.
|
|
1136
1414
|
this._map = null;
|
|
1137
|
-
this.attachMap = (map) => { this._map = map || null; this.dispatchEvent(new CustomEvent("contour:map-attach", { bubbles: true, composed: true })); };
|
|
1138
|
-
this.detachMap = () => { this._map = null; this.dispatchEvent(new CustomEvent("contour:map-detach", { bubbles: true, composed: true })); };
|
|
1139
|
-
Object.defineProperty(this, "map", { get: () => this._map, set: (m) => this.attachMap(m) });
|
|
1140
1415
|
this.getViewport = () => {
|
|
1141
1416
|
const m = this._map;
|
|
1142
1417
|
if (!m) return null;
|
|
1143
1418
|
try {
|
|
1144
1419
|
if (typeof m.getBounds === "function") {
|
|
1145
1420
|
const b = m.getBounds();
|
|
1146
|
-
|
|
1421
|
+
// A box that crosses the antimeridian arrives as west > east; the
|
|
1422
|
+
// unwrapped form keeps the span positive and names the case.
|
|
1423
|
+
return unwrapBounds({ west: b.getWest(), south: b.getSouth(), east: b.getEast(), north: b.getNorth() });
|
|
1147
1424
|
}
|
|
1148
1425
|
if (m.transform && typeof m.transform === "object") {
|
|
1149
1426
|
return { zoom: m.transform.zoom, center: m.transform.center };
|
|
@@ -1151,6 +1428,196 @@ class ContourMapArea extends ContourBase {
|
|
|
1151
1428
|
} catch (e) { /* engine API mismatch */ }
|
|
1152
1429
|
return null;
|
|
1153
1430
|
};
|
|
1431
|
+
// The viewport is announced on every moveend so a table, a filter or a
|
|
1432
|
+
// minimap can follow the engine without polling getViewport().
|
|
1433
|
+
this._emitViewport = () => {
|
|
1434
|
+
this.dispatchEvent(new CustomEvent("contour:map-viewport", { bubbles: true, composed: true, detail: this.getViewport() }));
|
|
1435
|
+
};
|
|
1436
|
+
// R31-78: detach the previous engine's listeners and observer before a new
|
|
1437
|
+
// engine overwrites `this._map`, so a swapped engine does not leave the old
|
|
1438
|
+
// one's moveend/idle handlers firing against a stale map.
|
|
1439
|
+
this._detachEngine = () => {
|
|
1440
|
+
const m = this._map;
|
|
1441
|
+
if (m && typeof m.off === "function") {
|
|
1442
|
+
try { m.off("moveend", this._emitViewport); } catch (e) { /* engine without events */ }
|
|
1443
|
+
try { m.off("idle", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
1444
|
+
try { m.off("load", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
1445
|
+
}
|
|
1446
|
+
if (this._mapRO) { try { this._mapRO.disconnect(); } catch (e) { /* ignore */ } this._mapRO = null; }
|
|
1447
|
+
};
|
|
1448
|
+
// R31-77: readiness is announced once, after the first idle/load — not at
|
|
1449
|
+
// attach, when the engine may still be loading its style/tiles.
|
|
1450
|
+
this._onMapIdle = () => {
|
|
1451
|
+
if (this._mapReadySent) return;
|
|
1452
|
+
this._mapReadySent = true;
|
|
1453
|
+
this.dispatchEvent(new CustomEvent("contour:map-ready", { bubbles: true, composed: true }));
|
|
1454
|
+
};
|
|
1455
|
+
this.attachMap = (map) => {
|
|
1456
|
+
this._detachEngine();
|
|
1457
|
+
this._map = map || null;
|
|
1458
|
+
this._mapReadySent = false;
|
|
1459
|
+
// R31-84: the `data-map` hook is the engine container the seam fills
|
|
1460
|
+
// (`.c-map-slot > [data-map]`). If it has zero size at attach time the
|
|
1461
|
+
// engine cannot render — usually a hidden tab or a display:none
|
|
1462
|
+
// ancestor — so say so once instead of failing silently.
|
|
1463
|
+
if (this._map) {
|
|
1464
|
+
const zeroSizeCheck = () => {
|
|
1465
|
+
if (!this.isConnected || this._map !== map) return;
|
|
1466
|
+
if (!this.clientWidth || !this.clientHeight) {
|
|
1467
|
+
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 } }));
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(zeroSizeCheck);
|
|
1471
|
+
else zeroSizeCheck();
|
|
1472
|
+
}
|
|
1473
|
+
if (this._map && typeof this._map.on === "function") {
|
|
1474
|
+
try { this._map.on("moveend", this._emitViewport); } catch (e) { /* engine without events */ }
|
|
1475
|
+
try { this._map.on("idle", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
1476
|
+
try { this._map.on("load", this._onMapIdle); } catch (e) { /* engine without events */ }
|
|
1477
|
+
}
|
|
1478
|
+
// R31-80: drive the engine's own resize/invalidateSize when the host box
|
|
1479
|
+
// changes, so the canvas matches its container after a layout change.
|
|
1480
|
+
if (typeof ResizeObserver !== "undefined" && this._map) {
|
|
1481
|
+
try {
|
|
1482
|
+
// R31-82: coalesce to one resize per frame — a split/sidebar toggle
|
|
1483
|
+
// fires several observations in a row and each engine.resize() is a
|
|
1484
|
+
// full relayout.
|
|
1485
|
+
let resizeRaf = 0;
|
|
1486
|
+
this._mapRO = new ResizeObserver(() => {
|
|
1487
|
+
if (resizeRaf) return;
|
|
1488
|
+
resizeRaf = requestAnimationFrame(() => {
|
|
1489
|
+
resizeRaf = 0;
|
|
1490
|
+
const mm = this._map;
|
|
1491
|
+
if (!mm) return;
|
|
1492
|
+
try {
|
|
1493
|
+
if (typeof mm.resize === "function") mm.resize();
|
|
1494
|
+
else if (typeof mm.invalidateSize === "function") mm.invalidateSize();
|
|
1495
|
+
} catch (e) { /* engine without resize */ }
|
|
1496
|
+
});
|
|
1497
|
+
});
|
|
1498
|
+
this._mapRO.observe(this);
|
|
1499
|
+
} catch (e) { this._mapRO = null; }
|
|
1500
|
+
}
|
|
1501
|
+
this.dispatchEvent(new CustomEvent("contour:map-attach", { bubbles: true, composed: true }));
|
|
1502
|
+
this._emitViewport();
|
|
1503
|
+
// An engine that is already loaded fires no idle/load; send ready now.
|
|
1504
|
+
if (this._map && typeof this._map.loaded === "function") {
|
|
1505
|
+
try { if (this._map.loaded()) this._onMapIdle(); } catch (e) { /* engine without loaded() */ }
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
this.detachMap = () => {
|
|
1509
|
+
this._detachEngine();
|
|
1510
|
+
this._map = null;
|
|
1511
|
+
this.dispatchEvent(new CustomEvent("contour:map-detach", { bubbles: true, composed: true }));
|
|
1512
|
+
};
|
|
1513
|
+
if (!this.hasOwnProperty("map")) {
|
|
1514
|
+
Object.defineProperty(this, "map", { get: () => this._map, set: (m) => this.attachMap(m) });
|
|
1515
|
+
} // R24-76: avoid redefine on reconnect.
|
|
1516
|
+
// Camera passthroughs. Both are no-ops when no engine is attached or the
|
|
1517
|
+
// engine lacks the method, so a consumer can call them unconditionally.
|
|
1518
|
+
this.fitBounds = (bounds, options) => {
|
|
1519
|
+
const m = this._map;
|
|
1520
|
+
if (!m || typeof m.fitBounds !== "function") return;
|
|
1521
|
+
// MapLibre/Mapbox accept both [w, s, e, n] and [[w, s], [e, n]], so the
|
|
1522
|
+
// GeoJSON bbox form a consumer already has passes straight through.
|
|
1523
|
+
try { m.fitBounds(bounds, options); } catch (e) { /* engine API mismatch */ }
|
|
1524
|
+
};
|
|
1525
|
+
this.flyTo = (options) => {
|
|
1526
|
+
const m = this._map;
|
|
1527
|
+
if (!m || typeof m.flyTo !== "function") return;
|
|
1528
|
+
try { m.flyTo(options); } catch (e) { /* engine API mismatch */ }
|
|
1529
|
+
};
|
|
1530
|
+
// Chrome wiring (the documented recipe): attachMap(map) then
|
|
1531
|
+
// attachChrome(map) and the authored zoom buttons, readout and compass
|
|
1532
|
+
// drive the live engine. Engine-agnostic — it only uses the map-like
|
|
1533
|
+
// surface (zoomIn/zoomOut/getCenter/getZoom/getBearing/on). Layer
|
|
1534
|
+
// toggles stay event-driven (contour:layer-*), so the consumer applies
|
|
1535
|
+
// them; this does not reach into engine layers.
|
|
1536
|
+
this.attachChrome = (map) => {
|
|
1537
|
+
const m = map || this._map;
|
|
1538
|
+
if (!m || this._chromeMap === m) return;
|
|
1539
|
+
this._chromeMap = m;
|
|
1540
|
+
// Zoom controls are delegated on the host so a render() that rebuilds
|
|
1541
|
+
// the buttons (the `controls` attribute) cannot leave them unwired.
|
|
1542
|
+
if (!this._chromeDelegated) {
|
|
1543
|
+
this._chromeDelegated = true;
|
|
1544
|
+
// R31-88: the grip is a real control. A `cursor: grab` that cannot grab
|
|
1545
|
+
// is a lie; ArrowUp/ArrowDown on the focused grip reorders the layer and
|
|
1546
|
+
// emits contour:layer-reorder with the new position.
|
|
1547
|
+
this.addEventListener("keydown", (e) => {
|
|
1548
|
+
const handle = e.target && e.target.closest ? e.target.closest(".c-drag-handle--dots, .c-layer-panel__grip") : null;
|
|
1549
|
+
if (!handle || !this.contains(handle)) return;
|
|
1550
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
|
1551
|
+
const item = handle.closest(".c-layer-panel__item");
|
|
1552
|
+
if (!item) return;
|
|
1553
|
+
const parent = item.parentNode;
|
|
1554
|
+
const sib = e.key === "ArrowUp" ? item.previousElementSibling : item.nextElementSibling;
|
|
1555
|
+
if (!sib || !sib.classList || !sib.classList.contains("c-layer-panel__item")) return;
|
|
1556
|
+
e.preventDefault();
|
|
1557
|
+
if (e.key === "ArrowUp") parent.insertBefore(item, sib);
|
|
1558
|
+
else parent.insertBefore(sib, item);
|
|
1559
|
+
try { handle.focus(); } catch (err) { /* ignore */ }
|
|
1560
|
+
// R31-88: one detail shape for both pointer and keyboard reorder — the
|
|
1561
|
+
// full ordered id list, same as the drag path.
|
|
1562
|
+
const layerIds = Array.from(parent.querySelectorAll(":scope > .c-layer-panel__item")).map((el, i) => el.dataset.layerId || el.getAttribute("data-layer-id") || String(i));
|
|
1563
|
+
this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
|
|
1564
|
+
});
|
|
1565
|
+
this.addEventListener("click", (e) => {
|
|
1566
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-map-slot__control") : null;
|
|
1567
|
+
if (!btn || !this.contains(btn)) return;
|
|
1568
|
+
// R31-79: read the live engine, not the one captured at attach time,
|
|
1569
|
+
// so a swapped engine (attachMap) is driven by the chrome.
|
|
1570
|
+
const mm = this._map;
|
|
1571
|
+
if (!mm) return;
|
|
1572
|
+
// R31-83: an explicit `data-map-action` wins; fall back to the text
|
|
1573
|
+
// heuristic only for a plain string control.
|
|
1574
|
+
const action = btn.dataset.mapAction;
|
|
1575
|
+
const label = (btn.getAttribute("aria-label") || btn.textContent || "").toLowerCase();
|
|
1576
|
+
const out = action ? /out|minus|zoomout/i.test(action) : (/out|minus|−|-/.test(label) && !/in\b/.test(label));
|
|
1577
|
+
try { out ? mm.zoomOut() : mm.zoomIn(); } catch (err) { /* engine without zoom */ }
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
const readout = this.querySelector(".c-readout");
|
|
1581
|
+
if (readout && typeof m.getCenter === "function") {
|
|
1582
|
+
const coord = readout.querySelector(".c-readout__value--coord");
|
|
1583
|
+
const zoom = readout.querySelector(".c-readout__row:nth-child(2) .c-readout__value");
|
|
1584
|
+
const write = () => {
|
|
1585
|
+
const mm = this._map || m; // R31-79: live engine.
|
|
1586
|
+
if (typeof mm.getCenter !== "function") return;
|
|
1587
|
+
const c = mm.getCenter();
|
|
1588
|
+
if (coord && c) coord.textContent = `${c.lng.toFixed(6)}, ${c.lat.toFixed(6)}`;
|
|
1589
|
+
if (zoom && typeof mm.getZoom === "function") zoom.textContent = mm.getZoom().toFixed(1);
|
|
1590
|
+
};
|
|
1591
|
+
try { m.on("move", write); } catch (e) { /* engine without events */ }
|
|
1592
|
+
write();
|
|
1593
|
+
}
|
|
1594
|
+
const needle = this.querySelector(".c-compass__needle");
|
|
1595
|
+
if (needle && typeof m.getBearing === "function") {
|
|
1596
|
+
const n = needle.querySelector(".c-compass__needle--n");
|
|
1597
|
+
const s = needle.querySelector(".c-compass__needle--s");
|
|
1598
|
+
const compass = needle.closest("contour-compass");
|
|
1599
|
+
const pt = (deg) => { const r = (deg * Math.PI) / 180; return [20 + 16 * Math.sin(r), 20 - 16 * Math.cos(r)]; };
|
|
1600
|
+
const draw = () => {
|
|
1601
|
+
const mm = this._map || m; // R31-79: live engine.
|
|
1602
|
+
if (typeof mm.getBearing !== "function") return;
|
|
1603
|
+
const deg = -mm.getBearing();
|
|
1604
|
+
const [nx, ny] = pt(deg), [sx, sy] = pt(deg + 180);
|
|
1605
|
+
if (n) n.setAttribute("d", `M ${nx} ${ny} L 20 20 Z`);
|
|
1606
|
+
if (s) s.setAttribute("d", `M ${sx} ${sy} L 20 20 Z`);
|
|
1607
|
+
// R31-81: the needle is decorative (aria-hidden); the compass's own
|
|
1608
|
+
// accessible name carries the bearing so a rotation is announced.
|
|
1609
|
+
if (compass) {
|
|
1610
|
+
const cur = compass.getAttribute("aria-label") || "";
|
|
1611
|
+
if (!cur || /^compass\b/i.test(cur)) {
|
|
1612
|
+
const bearing = Math.round(((deg % 360) + 360) % 360);
|
|
1613
|
+
compass.setAttribute("aria-label", `Compass, bearing ${bearing} degrees`);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
try { m.on("rotate", draw); } catch (e) { /* engine without events */ }
|
|
1618
|
+
draw();
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1154
1621
|
this.addEventListener("click", (e) => {
|
|
1155
1622
|
const btn = e.target && e.target.closest ? e.target.closest(".c-map-slot__control") : null;
|
|
1156
1623
|
if (!btn || !this.contains(btn)) return;
|
|
@@ -1166,10 +1633,16 @@ class ContourMapPanel extends ContourBase {
|
|
|
1166
1633
|
this.classList.add("c-map-panel");
|
|
1167
1634
|
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
1168
1635
|
const title = this.getAttribute("title");
|
|
1636
|
+
// The accessible name follows the title only while it is the one we
|
|
1169
1637
|
if (title) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1638
|
+
const prev = this._mapPanelTitle;
|
|
1639
|
+
if (!this.hasAttribute("aria-label") || (prev && this.getAttribute("aria-label") === prev)) {
|
|
1640
|
+
this.setAttribute("aria-label", title);
|
|
1641
|
+
}
|
|
1642
|
+
this._mapPanelTitle = title;
|
|
1643
|
+
} else if (this._mapPanelTitle && this.getAttribute("aria-label") === this._mapPanelTitle) {
|
|
1644
|
+
this.removeAttribute("aria-label");
|
|
1645
|
+
this._mapPanelTitle = null;
|
|
1173
1646
|
}
|
|
1174
1647
|
}
|
|
1175
1648
|
}
|
|
@@ -1194,26 +1667,37 @@ class ContourMapFooter extends ContourBase {
|
|
|
1194
1667
|
}
|
|
1195
1668
|
define("contour-map-footer", ContourMapFooter);
|
|
1196
1669
|
class ContourScaleBar extends ContourBase {
|
|
1197
|
-
static get observed() { return ["label", "value", "distance", "resolution", "latitude", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1198
|
-
static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, distance: { attribute: "distance" }, resolution: { attribute: "resolution" }, latitude: { attribute: "latitude" }, src: { attribute: "src" } }; }
|
|
1670
|
+
static get observed() { return ["label", "value", "distance", "resolution", "latitude", "zoom", "units", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
|
|
1671
|
+
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" } }; }
|
|
1199
1672
|
render() {
|
|
1200
1673
|
this.classList.add("c-scale-bar");
|
|
1674
|
+
// R24-49: role=img + aria-label so screen readers announce the scale.
|
|
1675
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "img");
|
|
1676
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "map-scale", "Map scale"));
|
|
1201
1677
|
wireStates(this);
|
|
1202
1678
|
loadRemote(this, ["label", "value"]);
|
|
1203
1679
|
if (renderStates(this, "scale-bar")) return;
|
|
1204
1680
|
let value = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
|
|
1205
1681
|
// BY-23: derive the bar width from map resolution + latitude when the
|
|
1206
|
-
// author gives a resolution (meters per pixel) instead of a raw pixel
|
|
1207
|
-
// length. A scale bar is a ground distance, so its pixel length is
|
|
1208
|
-
// distance / resolution; latitude is recorded for the Mercator-aware
|
|
1209
|
-
// consumers that read it back.
|
|
1210
1682
|
const resolution = parseFloat(this.getAttribute("resolution"));
|
|
1683
|
+
// R24-49: use mercatorResolution when latitude + zoom are provided.
|
|
1684
|
+
const lat = parseFloat(this.getAttribute("latitude"));
|
|
1685
|
+
const zoom = parseFloat(this.getAttribute("zoom"));
|
|
1686
|
+
let effectiveResolution = resolution;
|
|
1687
|
+
if (!Number.isFinite(effectiveResolution) && Number.isFinite(lat) && Number.isFinite(zoom)) {
|
|
1688
|
+
effectiveResolution = mercatorResolution(lat, zoom);
|
|
1689
|
+
}
|
|
1211
1690
|
let derivedLabel = null;
|
|
1212
|
-
if (Number.isFinite(
|
|
1691
|
+
if (Number.isFinite(effectiveResolution) && effectiveResolution > 0) {
|
|
1213
1692
|
const distance = parseFloat(this.getAttribute("distance")) || 1000;
|
|
1214
|
-
value = String(Math.round(distance /
|
|
1693
|
+
value = String(Math.round(distance / effectiveResolution));
|
|
1215
1694
|
if (!this.getAttribute("label") && !remoteData(this, "label")) {
|
|
1216
|
-
|
|
1695
|
+
const units = this.getAttribute("units") || "metric";
|
|
1696
|
+
if (units === "imperial") {
|
|
1697
|
+
derivedLabel = distance >= 1609.34 ? (distance / 1609.34).toFixed(1) + " mi" : Math.round(distance * 3.28084) + " ft";
|
|
1698
|
+
} else {
|
|
1699
|
+
derivedLabel = distance >= 1000 ? (distance / 1000) + " km" : distance + " m";
|
|
1700
|
+
}
|
|
1217
1701
|
}
|
|
1218
1702
|
}
|
|
1219
1703
|
const label = derivedLabel || remoteData(this, "label") || (this._remoteData && this._remoteData.label);
|
|
@@ -1224,6 +1708,11 @@ class ContourScaleBar extends ContourBase {
|
|
|
1224
1708
|
const l = this.querySelector(".c-scale-bar__label");
|
|
1225
1709
|
if (l) l.remove();
|
|
1226
1710
|
}
|
|
1711
|
+
// R24-49: metric/imperial unit toggle.
|
|
1712
|
+
const unitBtn = this.ensure(".c-scale-bar__units", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-scale-bar__units"; return b; });
|
|
1713
|
+
const units = this.getAttribute("units") || "metric";
|
|
1714
|
+
unitBtn.textContent = units === "imperial" ? "mi" : "km";
|
|
1715
|
+
unitBtn.onclick = () => { this.setAttribute("units", (this.getAttribute("units") || "metric") === "imperial" ? "metric" : "imperial"); };
|
|
1227
1716
|
if (!value) {
|
|
1228
1717
|
renderEmpty(this, "scale-bar");
|
|
1229
1718
|
return;
|
|
@@ -1248,8 +1737,8 @@ class ContourScaleBar extends ContourBase {
|
|
|
1248
1737
|
define("contour-scale-bar", ContourScaleBar);
|
|
1249
1738
|
|
|
1250
1739
|
class ContourSplitMap extends ContourBase {
|
|
1251
|
-
|
|
1252
|
-
static get
|
|
1740
|
+
// R24-77: split-map is a static two-pane layout primitive, not an interactive
|
|
1741
|
+
static get observed() { return []; }
|
|
1253
1742
|
render() {
|
|
1254
1743
|
this.classList.add("c-split-map");
|
|
1255
1744
|
const left = this.ensure(".c-split-map__pane--left", () => {
|
|
@@ -1267,3 +1756,50 @@ class ContourSplitMap extends ContourBase {
|
|
|
1267
1756
|
}
|
|
1268
1757
|
}
|
|
1269
1758
|
define("contour-split-map", ContourSplitMap);
|
|
1759
|
+
// R31-131: a collapsible map overlay legend. Composes a legend list + a
|
|
1760
|
+
// toggle head; the engine owns the layers, the legend only shows their names.
|
|
1761
|
+
class ContourMapLegend extends ContourBase {
|
|
1762
|
+
static get observed() { return ["items", "label", "collapsed"]; }
|
|
1763
|
+
static get properties() { return { items: { attribute: "items" }, label: { attribute: "label" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
1764
|
+
render() {
|
|
1765
|
+
this.classList.add("c-map-legend");
|
|
1766
|
+
const label = this.getAttribute("label") || labelText(this, "legend", "Legend");
|
|
1767
|
+
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; });
|
|
1768
|
+
setHTML(head, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-layers" /></svg>');
|
|
1769
|
+
head.appendChild(document.createTextNode(" " + label));
|
|
1770
|
+
const collapsed = this.hasAttribute("collapsed");
|
|
1771
|
+
head.setAttribute("aria-expanded", collapsed ? "false" : "true");
|
|
1772
|
+
let items = [];
|
|
1773
|
+
try { const p = JSON.parse(this.getAttribute("items") || "[]"); if (Array.isArray(p)) items = p; } catch (e) { /* empty */ }
|
|
1774
|
+
const list = this.ensure(".c-map-legend__list", () => { const l = document.createElement("ul"); l.className = "c-map-legend__list"; return l; });
|
|
1775
|
+
setHTML(list, "");
|
|
1776
|
+
if (!collapsed) {
|
|
1777
|
+
items.forEach((it) => {
|
|
1778
|
+
const name = typeof it === "string" ? it : (it.label || it.name || "");
|
|
1779
|
+
const color = (typeof it === "object" && it) ? it.color : null;
|
|
1780
|
+
const li = document.createElement("li");
|
|
1781
|
+
li.className = "c-map-legend__item";
|
|
1782
|
+
const shape = (typeof it === "object" && it && it.shape) ? String(it.shape) : "";
|
|
1783
|
+
if (color || SHAPES.has(shape)) {
|
|
1784
|
+
const sw = document.createElement("span");
|
|
1785
|
+
sw.className = "c-map-legend__swatch";
|
|
1786
|
+
if (SHAPES.has(shape)) sw.classList.add("c-swatch--" + shape);
|
|
1787
|
+
if (color) { if (SHAPES.has(shape)) sw.style.color = color; else sw.style.setProperty("--c", color); }
|
|
1788
|
+
li.appendChild(sw);
|
|
1789
|
+
}
|
|
1790
|
+
li.appendChild(document.createTextNode(" " + name));
|
|
1791
|
+
list.appendChild(li);
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
enhance() {
|
|
1796
|
+
if (this._wiredMapLegend) return;
|
|
1797
|
+
this._wiredMapLegend = true;
|
|
1798
|
+
this.addEventListener("click", (e) => {
|
|
1799
|
+
const h = e.target && e.target.closest ? e.target.closest(".c-map-legend__head") : null;
|
|
1800
|
+
if (!h || !this.contains(h)) return;
|
|
1801
|
+
this.toggleAttribute("collapsed");
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
define("contour-map-legend", ContourMapLegend);
|