contour-ds 1.7.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +244 -326
  2. package/dist/agent-cookbook.json +960 -0
  3. package/dist/agent-examples.json +65 -0
  4. package/dist/agent-map-wiring.json +152 -0
  5. package/dist/agent-rules.json +16 -0
  6. package/dist/build-manifest.json +344 -126
  7. package/dist/contour-wc-content.esm.js +1939 -0
  8. package/dist/contour-wc-content.esm.min.js +1 -0
  9. package/dist/contour-wc-core.esm.js +3724 -0
  10. package/dist/contour-wc-core.esm.min.js +1 -0
  11. package/dist/contour-wc-dashboard.esm.js +6986 -0
  12. package/dist/contour-wc-dashboard.esm.min.js +1 -0
  13. package/dist/contour-wc-data.esm.js +6572 -0
  14. package/dist/contour-wc-data.esm.min.js +1 -0
  15. package/dist/contour-wc-docs.esm.js +976 -0
  16. package/dist/contour-wc-docs.esm.min.js +1 -0
  17. package/dist/contour-wc-feedback.esm.js +1742 -0
  18. package/dist/contour-wc-feedback.esm.min.js +1 -0
  19. package/dist/contour-wc-forms.esm.js +2437 -0
  20. package/dist/contour-wc-forms.esm.min.js +1 -0
  21. package/dist/contour-wc-interaction.esm.js +1343 -0
  22. package/dist/contour-wc-interaction.esm.min.js +1 -0
  23. package/dist/contour-wc-layout.esm.js +845 -0
  24. package/dist/contour-wc-layout.esm.min.js +1 -0
  25. package/dist/contour-wc-map.esm.js +2411 -0
  26. package/dist/contour-wc-map.esm.min.js +1 -0
  27. package/dist/contour-wc-misc.esm.js +945 -0
  28. package/dist/contour-wc-misc.esm.min.js +1 -0
  29. package/dist/contour-wc-navigation.esm.js +2842 -0
  30. package/dist/contour-wc-navigation.esm.min.js +1 -0
  31. package/dist/contour-wc-ui.esm.js +6519 -0
  32. package/dist/contour-wc-ui.esm.min.js +1 -0
  33. package/dist/contour-wc.esm.js +14435 -5723
  34. package/dist/contour-wc.esm.min.js +1 -1
  35. package/dist/contour-wc.js +14436 -5725
  36. package/dist/contour-wc.min.js +1 -1
  37. package/dist/contour.a11y.json +402 -0
  38. package/dist/contour.code-snippets +4534 -0
  39. package/dist/contour.components.json +4870 -1222
  40. package/dist/contour.css +6672 -4711
  41. package/dist/contour.d.ts +753 -1085
  42. package/dist/contour.esm.js +440 -18
  43. package/dist/contour.esm.min.js +1 -1
  44. package/dist/contour.html-data.json +11343 -0
  45. package/dist/contour.js +440 -18
  46. package/dist/contour.min.css +1 -1
  47. package/dist/contour.min.js +1 -1
  48. package/dist/contour.react.d.ts +422 -0
  49. package/dist/contour.single.html +17 -0
  50. package/dist/contour.single.min.css +1 -0
  51. package/dist/contour.themes.json +56 -12
  52. package/dist/contour.tokens.json +1318 -1053
  53. package/dist/contour.vue.d.ts +420 -0
  54. package/dist/contour.web-types.json +11703 -0
  55. package/dist/custom-elements.json +36120 -0
  56. package/dist/docs/actions.md +16 -6
  57. package/dist/docs/affordances.md +21 -85
  58. package/dist/docs/apireference.md +9 -5
  59. package/dist/docs/colour.md +10 -4
  60. package/dist/docs/componentindex.md +9 -22
  61. package/dist/docs/data.md +39 -58
  62. package/dist/docs/docs.md +12 -7
  63. package/dist/docs/feedback.md +30 -12
  64. package/dist/docs/field.md +28 -13
  65. package/dist/docs/forms.md +35 -19
  66. package/dist/docs/index.json +70 -61
  67. package/dist/docs/install.md +12 -7
  68. package/dist/docs/landing.md +7 -4
  69. package/dist/docs/mapengine.md +30 -8
  70. package/dist/docs/motion.md +12 -6
  71. package/dist/docs/navigation.md +31 -7
  72. package/dist/docs/overlays.md +32 -25
  73. package/dist/docs/overview.md +3 -2
  74. package/dist/docs/patterns.md +20 -10
  75. package/dist/docs/playground.md +11 -4
  76. package/dist/docs/principles.md +8 -6
  77. package/dist/docs/recipes.md +117 -13
  78. package/dist/docs/space.md +10 -6
  79. package/dist/docs/status.md +13 -14
  80. package/dist/docs/surfaces.md +17 -22
  81. package/dist/docs/theming.md +18 -32
  82. package/dist/docs/type.md +12 -5
  83. package/dist/docs/webcomponents.md +75 -33
  84. package/dist/hljs.css +1 -20
  85. package/dist/map-chrome.mapbox.css +68 -92
  86. package/dist/map-chrome.maplibre.css +68 -92
  87. package/dist/registry/items/contour-core.json +2 -2
  88. package/dist/registry/items/contour-data.json +2 -2
  89. package/dist/registry/items/contour-docs.json +2 -2
  90. package/dist/registry/items/contour-landing.json +2 -2
  91. package/dist/registry/registry.json +8 -8
  92. package/dist/surfaces/contour-core.min.css +1 -1
  93. package/dist/surfaces/contour-data.min.css +1 -1
  94. package/dist/surfaces/contour-docs.min.css +1 -1
  95. package/dist/surfaces/contour-landing.min.css +1 -1
  96. package/dist/svg/icons.svg +367 -0
  97. package/dist/wc/behaviours.mjs +222 -192
  98. package/dist/wc/content.mjs +486 -142
  99. package/dist/wc/core.mjs +917 -395
  100. package/dist/wc/dashboard.mjs +252 -25
  101. package/dist/wc/data-chart.mjs +1333 -0
  102. package/dist/wc/data-export.mjs +391 -0
  103. package/dist/wc/data-gauge.mjs +779 -0
  104. package/dist/wc/data-geo.mjs +696 -0
  105. package/dist/wc/data-glyphs.mjs +133 -0
  106. package/dist/wc/data-legend.mjs +431 -0
  107. package/dist/wc/data-readout.mjs +227 -0
  108. package/dist/wc/data-series.mjs +1004 -0
  109. package/dist/wc/data-table.mjs +751 -0
  110. package/dist/wc/data.mjs +15 -3707
  111. package/dist/wc/docs.mjs +113 -19
  112. package/dist/wc/feedback.mjs +320 -116
  113. package/dist/wc/forms-controls.mjs +635 -0
  114. package/dist/wc/forms-field.mjs +547 -0
  115. package/dist/wc/forms-groups.mjs +347 -0
  116. package/dist/wc/forms-input.mjs +292 -0
  117. package/dist/wc/forms.mjs +10 -1122
  118. package/dist/wc/glyph.mjs +204 -0
  119. package/dist/wc/index.mjs +16 -7
  120. package/dist/wc/interaction.mjs +322 -75
  121. package/dist/wc/layout.mjs +100 -29
  122. package/dist/wc/map.mjs +888 -285
  123. package/dist/wc/misc.mjs +137 -26
  124. package/dist/wc/navigation-menu.mjs +735 -0
  125. package/dist/wc/navigation-shell.mjs +495 -0
  126. package/dist/wc/navigation-tree.mjs +995 -0
  127. package/dist/wc/navigation.mjs +9 -1636
  128. package/dist/wc/registration.mjs +1 -8
  129. package/dist/wc/shadow.mjs +285 -113
  130. package/dist/wc/states.mjs +75 -78
  131. package/dist/wc/svg.mjs +209 -34
  132. package/dist/wc/ui-atoms.mjs +608 -0
  133. package/dist/wc/ui-data.mjs +1404 -0
  134. package/dist/wc/ui-feedback.mjs +419 -0
  135. package/dist/wc/ui-inputs.mjs +1570 -0
  136. package/dist/wc/ui-menus.mjs +307 -0
  137. package/dist/wc/ui-overlays.mjs +1605 -0
  138. package/integrations/README.md +25 -5
  139. package/integrations/ai/CLAUDE.md +6 -3
  140. package/integrations/ai/COPILOT.md +14 -0
  141. package/integrations/ai/GEMINI.md +14 -0
  142. package/integrations/ai/WINDSURF.md +14 -0
  143. package/integrations/ai/v0-prompt.md +13 -1
  144. package/integrations/frameworks/README.md +235 -0
  145. package/integrations/native/README.md +0 -3
  146. package/integrations/native/style-dictionary.config.json +1 -1
  147. package/integrations/tailwind/contour-theme.css +71 -13
  148. package/integrations/validate-markup.mjs +172 -0
  149. package/package.json +103 -39
  150. package/dist/wc/ui.mjs +0 -3560
package/dist/wc/map.mjs CHANGED
@@ -1,10 +1,12 @@
1
- import { ContourBase, define, onDispose, formatValue } 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,35 +50,21 @@ 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) return;
52
- 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() } }));
54
+ } else {
55
+ const all = items();
56
+ navKey(e, all, { wrap: false, homeEnd: true, rtl: isRtl(host), onNavigate: (i) => all.forEach((c, j) => c.setAttribute("tabindex", j === i ? "0" : "-1")) });
53
57
  }
54
- // Roving tabindex keyboard nav.
55
- const all = items();
56
- const idx = all.indexOf(item);
57
- if (idx < 0) return;
58
- let next = -1;
59
- const rtl = (host.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
60
- if (e.key === "ArrowDown") next = Math.min(idx + 1, all.length - 1);
61
- else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
62
- else if (e.key === "ArrowRight") next = rtl ? Math.max(idx - 1, 0) : Math.min(idx + 1, all.length - 1);
63
- else if (e.key === "ArrowLeft") next = rtl ? Math.min(idx + 1, all.length - 1) : Math.max(idx - 1, 0);
64
- else if (e.key === "Home") next = 0;
65
- else if (e.key === "End") next = all.length - 1;
66
- if (next < 0 || next === idx) return;
67
- e.preventDefault();
68
- all.forEach((c, i) => c.setAttribute("tabindex", i === next ? "0" : "-1"));
69
- try { all[next].focus(); } catch (err) {}
70
58
  });
71
59
  }
72
60
 
73
61
  class ContourMinimap extends ContourBase {
74
- 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"]; }
75
63
  static get properties() { return { label: { attribute: "label" }, viewport: { attribute: "viewport" }, src: { attribute: "src" } }; }
76
64
  render() {
77
65
  this.classList.add("c-minimap");
78
- this.setAttribute("role", "img");
79
- this.setAttribute("aria-label", "Minimap");
66
+ if (!this.hasAttribute("role")) this.setAttribute("role", "img");
67
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Minimap");
80
68
  wireStates(this);
81
69
  loadRemote(this, ["label", "viewport"]);
82
70
  if (renderStates(this, "minimap")) return;
@@ -106,15 +94,21 @@ class ContourMinimap extends ContourBase {
106
94
  this._wiredMinimap = true;
107
95
  if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
108
96
  let dragging = false;
97
+ let dragStartX = 0, dragStartY = 0;
109
98
  this.addEventListener("pointerdown", (e) => {
110
99
  const vp = this.querySelector(".c-minimap__viewport");
111
100
  if (!vp || !vp.contains(e.target)) return;
112
101
  dragging = true;
102
+ dragStartX = e.clientX;
103
+ dragStartY = e.clientY;
113
104
  try { vp.setPointerCapture(e.pointerId); } catch (err) {}
114
105
  });
115
106
  this.addEventListener("pointermove", (e) => {
116
107
  if (!dragging) return;
117
- this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag" }, bubbles: true, composed: true }));
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 }));
118
112
  });
119
113
  this.addEventListener("pointerup", () => { dragging = false; });
120
114
  this.addEventListener("keydown", (e) => {
@@ -133,8 +127,8 @@ class ContourMinimap extends ContourBase {
133
127
  }
134
128
  define("contour-minimap", ContourMinimap);
135
129
  class ContourCoordinate extends ContourBase {
136
- static get observed() { return ["value", "format", "locale", "precision", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
137
- 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" } }; }
138
132
  render() {
139
133
  this.classList.add("c-coordinate");
140
134
  wireStates(this);
@@ -169,14 +163,31 @@ class ContourCoordinate extends ContourBase {
169
163
  const y = Math.log(Math.tan((90 + parts[0]) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180;
170
164
  text = x.toFixed(2) + ", " + y.toFixed(2);
171
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
+ }
172
175
  } else {
173
176
  text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
174
177
  }
175
- const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value"; el.setAttribute("role", "status"); el.setAttribute("aria-live", "polite"); return el; });
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
+ }
176
187
  span.textContent = text;
177
188
  // copy button
178
189
  let btn = this.querySelector(".c-coordinate__copy");
179
- if (!btn) { btn = document.createElement("button"); btn.type = "button"; btn.className = "c-coordinate__copy"; btn.textContent = "Copy"; btn.setAttribute("aria-label", "Copy coordinate"); this.appendChild(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); }
180
191
  btn.onclick = () => {
181
192
  try {
182
193
  if (navigator.clipboard && navigator.clipboard.writeText) {
@@ -203,12 +214,14 @@ class ContourCoordinate extends ContourBase {
203
214
  }
204
215
  define("contour-coordinate", ContourCoordinate);
205
216
  class ContourLayerPanel extends ContourBase {
206
- 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"]; }
207
218
  static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
208
219
  render() {
209
220
  this.classList.add("c-layer-panel");
210
221
  this.setAttribute("role", "group");
211
- 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();
212
225
  wireStates(this);
213
226
  loadRemote(this, "items");
214
227
  if (renderStates(this, "layer-panel")) return;
@@ -226,15 +239,20 @@ class ContourLayerPanel extends ContourBase {
226
239
  const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
227
240
  // Preserve user-toggled visibility across re-renders (B3-09): a src
228
241
  // reload must not re-check a layer the user un-checked.
229
- const savedVisibility = new Map();
230
- this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
231
- const nm = el.querySelector(".c-layer-panel__name");
232
- const tg = el.querySelector(".c-layer-panel__toggle");
233
- if (nm && tg) {
234
- const v = tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked;
235
- savedVisibility.set(nm.textContent, v);
236
- }
237
- });
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
+ });
238
256
  let parsed = null;
239
257
  if (authoredLayerItems.length) {
240
258
  parsed = authoredLayerItems.map((el) => {
@@ -249,22 +267,58 @@ class ContourLayerPanel extends ContourBase {
249
267
  try {
250
268
  parsed = JSON.parse(items);
251
269
  Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
252
- } catch (e) { /* keep existing */ }
270
+ } catch (e) { warnBadJson(this, "attribute", e); }
253
271
  }
254
272
  if (parsed) { parsed.forEach((it) => {
255
273
  const name = typeof it === "string" ? it : (it.name || it.label || "");
256
274
  const caption = (typeof it === "object" && it) ? (it.caption || it.subtitle || "") : "";
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);
257
299
  const item = document.createElement("div");
258
300
  item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
259
- const toggle = document.createElement("button");
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
+ }
313
+ const toggle = document.createElement("button");
260
314
  toggle.type = "button";
261
315
  toggle.className = "c-layer-panel__toggle";
262
316
  toggle.setAttribute("part", "visibility-toggle");
263
- toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
317
+ toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle") + " " + (name || labelText(this, "layer", "layer")));
264
318
  const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
265
319
  toggle.setAttribute("aria-pressed", String(!!isVisible));
266
320
  toggle.checked = !!isVisible;
267
- toggle.innerHTML = isVisible ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
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>');
268
322
  item.appendChild(toggle);
269
323
  const nm = document.createElement("span");
270
324
  nm.className = "c-layer-panel__name";
@@ -276,52 +330,64 @@ class ContourLayerPanel extends ContourBase {
276
330
  cap.textContent = caption;
277
331
  item.appendChild(cap);
278
332
  }
279
- const opacity = document.createElement("input");
280
- opacity.type = "range";
281
- opacity.className = "c-layer-panel__opacity";
282
- opacity.min = "0";
283
- opacity.max = "100";
284
- opacity.setAttribute("aria-label", "Opacity of " + (name || "layer"));
285
- opacity.value = (typeof it === "object" && it.opacity != null) ? it.opacity : "100";
286
- item.appendChild(opacity);
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
+ }
287
346
  // rename input (hidden by default, toggled via button)
288
347
  if (this.getAttribute("allow-rename") !== "false") {
289
348
  const renameBtn = document.createElement("button");
290
349
  renameBtn.type = "button";
291
- renameBtn.className = "c-layer-panel__rename";
292
- renameBtn.textContent = "Rename";
293
- renameBtn.setAttribute("aria-label", "Rename " + (name || "layer"));
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>');
353
+ renameBtn.setAttribute("aria-label", labelText(this, "rename", "Rename") + " " + (name || "layer"));
294
354
  item.appendChild(renameBtn);
295
355
  }
296
356
  if (this.getAttribute("allow-duplicate") !== "false") {
297
357
  const dupBtn = document.createElement("button");
298
358
  dupBtn.type = "button";
299
- dupBtn.className = "c-layer-panel__duplicate";
300
- dupBtn.textContent = "Duplicate";
301
- dupBtn.setAttribute("aria-label", "Duplicate " + (name || "layer"));
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>');
362
+ dupBtn.setAttribute("aria-label", labelText(this, "duplicate", "Duplicate") + " " + (name || "layer"));
302
363
  item.appendChild(dupBtn);
303
364
  }
304
365
  if (this.getAttribute("allow-zoom") !== "false") {
305
366
  const zoomBtn = document.createElement("button");
306
367
  zoomBtn.type = "button";
307
368
  zoomBtn.className = "c-layer-panel__zoom";
308
- zoomBtn.textContent = "Zoom";
309
- zoomBtn.setAttribute("aria-label", "Zoom to " + (name || "layer"));
369
+ zoomBtn.textContent = labelText(this, "zoom", "Zoom");
370
+ zoomBtn.setAttribute("aria-label", labelText(this, "zoom-to", "Zoom to") + " " + (name || "layer"));
310
371
  item.appendChild(zoomBtn);
311
372
  }
312
373
  if (this.getAttribute("allow-remove") !== "false") {
313
374
  const removeBtn = document.createElement("button");
314
375
  removeBtn.type = "button";
315
376
  removeBtn.className = "c-layer-panel__remove";
316
- removeBtn.innerHTML = '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
317
- removeBtn.setAttribute("aria-label", "Remove " + (name || "layer"));
377
+ setHTML(removeBtn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-minus" /></svg>');
378
+ removeBtn.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + (name || "layer"));
318
379
  item.appendChild(removeBtn);
319
380
  }
320
- const projSel = document.createElement("select");
321
- projSel.className = "c-select c-layer-panel__projection";
322
- projSel.setAttribute("aria-label", "Projection of " + (name || "layer"));
323
- ["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
324
- item.appendChild(projSel);
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
+ }
325
391
  this.appendChild(item);
326
392
  });
327
393
  }
@@ -334,103 +400,132 @@ class ContourLayerPanel extends ContourBase {
334
400
  if (this._wiredLayerPanel) return;
335
401
  this._wiredLayerPanel = true;
336
402
  // The panel's two controls (visibility toggle, opacity range) are rebuilt
337
- // on every render, so both keep the host-delegated pattern (rule 12).
403
+ const idOf = (item) => (item && item.dataset && item.dataset.layerId) || "";
338
404
  this.addEventListener("change", (e) => {
339
405
  const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
340
406
  if (!item || !this.contains(item)) return;
341
407
  const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
408
+ const layerId = idOf(item);
342
409
  if (e.target.classList.contains("c-layer-panel__toggle")) {
343
410
  const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
344
411
  e.target.checked = now;
345
412
  e.target.setAttribute("aria-pressed", String(now));
346
- e.target.innerHTML = now ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
347
- 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 } }));
348
415
  } else if (e.target.classList.contains("c-layer-panel__opacity")) {
349
- 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) } }));
350
417
  } else if (e.target.classList.contains("c-layer-panel__projection")) {
351
- this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
352
- }
353
- });
354
- this.addEventListener("click", (e) => {
355
- const btn = e.target && e.target.closest ? e.target.closest("button") : null;
356
- if (!btn || !this.contains(btn)) return;
357
- const item = btn.closest(".c-layer-panel__item");
358
- if (btn.classList.contains("c-layer-panel__toggle")) {
359
- if (!item) return;
360
- const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
361
- const now = btn.getAttribute("aria-pressed") !== "true";
362
- btn.setAttribute("aria-pressed", String(now));
363
- btn.checked = now;
364
- btn.innerHTML = now ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
365
- this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
366
- return;
418
+ this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { layerId, name, projection: e.target.value } }));
367
419
  }
368
- if (!item) return;
369
- const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
370
- if (btn.classList.contains("c-layer-panel__rename")) {
371
- const nm = item.querySelector(".c-layer-panel__name");
372
- if (nm) {
373
- const input = document.createElement("input");
374
- input.type = "text";
375
- input.className = "c-input c-layer-panel__rename-input";
376
- input.value = name;
377
- input.setAttribute("aria-label", "Rename layer");
378
- nm.replaceWith(input);
379
- input.focus();
380
- input.select();
381
- const commit = () => {
382
- const trimmed = (input.value || "").trim();
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();
383
467
  const span = document.createElement("span");
384
468
  span.className = "c-layer-panel__name";
385
469
  span.textContent = trimmed || name;
386
470
  input.replaceWith(span);
387
- if (trimmed && trimmed !== name) {
388
- this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
389
- }
390
- };
391
- input.addEventListener("keydown", (ev) => { if (ev.key === "Enter") { ev.preventDefault(); commit(); } else if (ev.key === "Escape") { ev.preventDefault(); input.value = name; commit(); } });
392
- input.addEventListener("blur", commit, { once: true });
393
- }
394
- } else if (btn.classList.contains("c-layer-panel__duplicate")) {
395
- this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
396
- } else if (btn.classList.contains("c-layer-panel__zoom")) {
397
- this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { name } }));
398
- } else if (btn.classList.contains("c-layer-panel__remove")) {
399
- this.dispatchEvent(new CustomEvent("contour:layer-remove", { bubbles: true, composed: true, detail: { name } }));
400
- }
401
- });
402
- this.addEventListener("keydown", (e) => {
403
- if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
404
- e.preventDefault();
405
- e.target.click();
406
- return;
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 } }));
407
488
  }
408
- const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
409
- if (!item || !this.contains(item)) return;
410
- if (!(e.altKey) || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
411
- e.preventDefault();
412
- const items = Array.from(this.querySelectorAll(".c-layer-panel__item"));
413
- const idx = items.indexOf(item);
414
- if (idx < 0) return;
415
- const dir = e.key === "ArrowUp" ? -1 : 1;
416
- const newIdx = idx + dir;
417
- if (newIdx < 0 || newIdx >= items.length) return;
418
- item.classList.add("c-layer-panel__item--dragging");
419
- if (dir < 0) this.insertBefore(item, items[newIdx]);
420
- else this.insertBefore(items[newIdx], item);
421
- item.focus();
422
- setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
423
- const layerIds = Array.from(this.querySelectorAll(".c-layer-panel__item")).map((el) => el.querySelector(".c-layer-panel__name")?.textContent || "");
424
- this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
425
- });
489
+ });
490
+ this.addEventListener("keydown", (e) => {
491
+ if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
492
+ e.preventDefault();
493
+ e.target.click();
494
+ return;
495
+ }
496
+ const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
497
+ if (!item || !this.contains(item)) return;
498
+ const isDrag = e.target && e.target.classList && e.target.classList.contains("c-drag-handle--dots");
499
+ // Drag handle: ArrowUp/ArrowDown reorder without Alt modifier (CDS-049).
500
+ // Item-level: Alt+ArrowUp/ArrowDown as an alternative.
501
+ if ((isDrag && (e.key === "ArrowUp" || e.key === "ArrowDown")) || (e.altKey && (e.key === "ArrowUp" || e.key === "ArrowDown"))) {
502
+ e.preventDefault();
503
+ const items = Array.from(this.querySelectorAll(".c-layer-panel__item"));
504
+ const idx = items.indexOf(item);
505
+ if (idx < 0) return;
506
+ const dir = e.key === "ArrowUp" ? -1 : 1;
507
+ const newIdx = idx + dir;
508
+ if (newIdx < 0 || newIdx >= items.length) return;
509
+ item.classList.add("c-layer-panel__item--dragging");
510
+ if (dir < 0) this.insertBefore(item, items[newIdx]);
511
+ else this.insertBefore(items[newIdx], item);
512
+ (isDrag ? e.target : item).focus();
513
+ setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
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));
516
+ this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
517
+ }
518
+ });
426
519
  }
427
520
  }
428
521
  define("contour-layer-panel", ContourLayerPanel);
429
522
  class ContourTimeSlider extends ContourBase {
430
- static get observed() { return ["label", "value", "loop", "speed", "speeds", "show-loop", "loop-label", "current-time", "time-format", "is-playing", "play-label", "pause-label", "time-label", "speed-label"]; }
431
- static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, distance: { attribute: "distance" }, resolution: { attribute: "resolution" }, latitude: { attribute: "latitude" }, src: { attribute: "src" }, loop: { attribute: "loop", type: Boolean }, speed: { attribute: "speed" }, speeds: { attribute: "speeds" }, showLoop: { attribute: "show-loop", type: Boolean }, loopLabel: { attribute: "loop-label" }, currentTime: { attribute: "current-time" }, timeFormat: { attribute: "time-format" }, isPlaying: { attribute: "is-playing", type: Boolean }, playLabel: { attribute: "play-label" }, pauseLabel: { attribute: "pause-label" }, timeLabel: { attribute: "time-label" }, speedLabel: { attribute: "speed-label" } }; }
523
+ static get observed() { return ["label", "value", "min", "max", "loop", "speed", "speeds", "show-loop", "loop-label", "current-time", "time-format", "is-playing", "play-label", "pause-label", "time-label", "speed-label"]; }
524
+ static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, distance: { attribute: "distance" }, resolution: { attribute: "resolution" }, latitude: { attribute: "latitude" }, src: { attribute: "src" }, loop: { attribute: "loop", type: Boolean }, speed: { attribute: "speed" }, speeds: { attribute: "speeds" }, showLoop: { attribute: "show-loop", type: Boolean }, loopLabel: { attribute: "loop-label" }, currentTime: { attribute: "current-time" }, timeFormat: { attribute: "time-format" }, isPlaying: { attribute: "is-playing", type: Boolean }, playLabel: { attribute: "play-label" }, pauseLabel: { attribute: "pause-label" }, timeLabel: { attribute: "time-label" }, speedLabel: { attribute: "speed-label" } }; }
432
525
  render() {
433
526
  this.classList.add("c-time-slider");
527
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
528
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Time slider");
434
529
  const play = this.ensure(".c-time-slider__play", () => {
435
530
  const el = document.createElement("button");
436
531
  el.className = "c-time-slider__play";
@@ -445,7 +540,11 @@ class ContourTimeSlider extends ContourBase {
445
540
  el.appendChild(svg);
446
541
  return el;
447
542
  });
448
- const track = this.ensure(".c-time-slider__track", () => { const el = document.createElement("input"); el.className = "c-time-slider__track"; el.type = "range"; el.min = "0"; el.max = "100"; el.setAttribute("aria-label", this.getAttribute("time-label") || "Time"); return el; });
543
+ const track = this.ensure(".c-time-slider__track", () => { const el = document.createElement("input"); el.className = "c-time-slider__track"; el.type = "range"; el.min = "0"; el.max = "100"; el.setAttribute("part", "input"); el.setAttribute("aria-label", this.getAttribute("time-label") || "Time"); return el; });
544
+ // min/max are attributes, not factory constants (R20 T-30): the guide's
545
+ // own 17d snippet passes them and they used to be ignored.
546
+ track.min = this.getAttribute("min") || "0";
547
+ track.max = this.getAttribute("max") || "100";
449
548
  const _attrVal = this.getAttribute("value") || "0";
450
549
  if (this._timeSliderAttrLast !== _attrVal) {
451
550
  track.value = _attrVal;
@@ -454,13 +553,30 @@ class ContourTimeSlider extends ContourBase {
454
553
  track.setAttribute("aria-label", this.getAttribute("label") || this.getAttribute("time-label") || "Time");
455
554
  const time = this.ensure(".c-time-slider__time", () => { const el = document.createElement("span"); el.className = "c-time-slider__time"; return el; });
456
555
  const ct = this.getAttribute("current-time");
457
- time.textContent = ct ? ct : (this.getAttribute("label") || "");
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);
458
574
  // speed selector
459
575
  let speeds = null;
460
576
  const speedsAttr = this.getAttribute("speeds");
461
577
  if (speedsAttr) { try { speeds = JSON.parse(speedsAttr); } catch (e) { speeds = null; } }
462
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; });
463
- speedSel.innerHTML = "";
579
+ setHTML(speedSel, "");
464
580
  const speedList = Array.isArray(speeds) ? speeds : [0.5, 1, 2, 5, 10];
465
581
  speedList.forEach((sp) => {
466
582
  const opt = document.createElement("option");
@@ -476,69 +592,79 @@ class ContourTimeSlider extends ContourBase {
476
592
  if (showLoop) {
477
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; });
478
594
  loopBtn.setAttribute("aria-pressed", this.hasAttribute("loop") ? "true" : "false");
479
- loopBtn.textContent = this.getAttribute("loop-label") || "Loop";
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>');
480
597
  } else {
481
598
  const lb = this.querySelector(".c-time-slider__loop");
482
599
  if (lb) lb.remove();
483
600
  }
484
- // is-playing reflects on play button
485
- if (this.hasAttribute("is-playing")) {
486
- play.setAttribute("data-state", "pause");
487
- play.setAttribute("aria-label", this.getAttribute("pause-label") || "Pause");
488
- const use = play.querySelector("use");
489
- if (use) use.setAttribute("href", "#i-pause");
490
- }
601
+ // is-playing reflects on play button, both directions (R20 T-30).
602
+ const playing = this.hasAttribute("is-playing");
603
+ play.setAttribute("data-state", playing ? "pause" : "play");
604
+ play.setAttribute("aria-label", playing ? (this.getAttribute("pause-label") || "Pause") : (this.getAttribute("play-label") || "Play"));
605
+ const use = play.querySelector("use");
606
+ if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
491
607
  }
492
608
  enhance() {
609
+ // Playback reconciles with the is-playing attribute on EVERY render
610
+ if (this._timeSliderReconcile) this._timeSliderReconcile();
493
611
  if (this._wiredTimeSlider) return;
494
612
  this._wiredTimeSlider = true;
495
- // Play advances the track one step per second and announces each move as
496
- // contour:time-change, so a dashboard can animate a chart in lockstep.
497
- // The loop stops at max, or on a second click, or when the host leaves
498
- // the page (the disposer is registered once, like the loader's).
613
+ // Play advances the track one step per cadence and announces each move
499
614
  let timer = undefined;
500
615
  const stop = () => { if (timer !== undefined) { clearInterval(timer); timer = undefined; } };
616
+ const syncReadout = () => {
617
+ const track = this.querySelector(".c-time-slider__track");
618
+ if (!track) return;
619
+ const time = this.querySelector(".c-time-slider__time");
620
+ const ct = this.getAttribute("current-time");
621
+ const tf = this.getAttribute("time-format");
622
+ if (time) time.textContent = ct ? ct : (tf ? formatValue(String(track.value), tf) : String(track.value));
623
+ if (ct) track.setAttribute("aria-valuetext", ct);
624
+ else track.removeAttribute("aria-valuetext");
625
+ };
501
626
  const step = () => {
502
627
  const track = this.querySelector(".c-time-slider__track");
503
628
  if (!track) { stop(); return; }
504
629
  const max = Number(track.max) || 100;
630
+ const min = Number(track.min) || 0;
505
631
  const loop = this.hasAttribute("loop");
506
632
  let next = (Number(track.value) || 0) + 1;
507
- if (next > max) {
508
- if (loop) next = 0;
509
- else next = max;
510
- }
633
+ if (next > max) next = loop ? min : max;
511
634
  track.value = String(next);
635
+ // The playhead writes back so a consumer reading `value` sees it —
636
+ const speedSel = this.querySelector(".c-time-slider__speed");
637
+ const interacting = this._timeSliderScrubbing || (speedSel && document.activeElement === speedSel);
638
+ if (!interacting) this.setAttribute("value", String(next));
639
+ syncReadout();
512
640
  this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: String(next) }, bubbles: true, composed: true }));
513
641
  if (!loop && next >= max) {
514
642
  stop();
515
- const btn = this.querySelector(".c-time-slider__play");
516
- if (btn) {
517
- btn.setAttribute("data-state", "play");
518
- btn.setAttribute("aria-label", this.getAttribute("play-label") || "Play");
519
- const use = btn.querySelector("use");
520
- if (use) use.setAttribute("href", "#i-play");
521
- }
643
+ this.removeAttribute("is-playing");
644
+ this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
645
+ }
646
+ };
647
+ const start = () => {
648
+ stop();
649
+ const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
650
+ timer = setInterval(step, Math.max(100, 1000 / speed));
651
+ };
652
+ this._timeSliderReconcile = () => {
653
+ const want = this.hasAttribute("is-playing");
654
+ if (want && timer === undefined) {
655
+ start();
656
+ this.dispatchEvent(new CustomEvent("contour:play", { bubbles: true, composed: true }));
657
+ } else if (!want && timer !== undefined) {
658
+ stop();
659
+ this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
522
660
  }
523
661
  };
524
662
  this.addEventListener("click", (e) => {
525
663
  const btn = e.target && e.target.closest ? e.target.closest(".c-time-slider__play") : null;
526
664
  if (btn) {
527
- const playing = btn.getAttribute("data-state") === "play";
528
- btn.setAttribute("data-state", playing ? "pause" : "play");
529
- btn.setAttribute("aria-label", playing ? (this.getAttribute("pause-label") || "Pause") : (this.getAttribute("play-label") || "Play"));
530
- const use = btn.querySelector("use");
531
- if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
532
- if (playing) {
533
- stop();
534
- const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
535
- const delay = Math.max(100, 1000 / speed);
536
- timer = setInterval(step, delay);
537
- this.dispatchEvent(new CustomEvent("contour:play", { bubbles: true, composed: true }));
538
- } else {
539
- stop();
540
- this.dispatchEvent(new CustomEvent("contour:pause", { bubbles: true, composed: true }));
541
- }
665
+ // The attribute is the source of truth: toggling it re-renders the
666
+ // icon and the reconciler starts/stops the timer and emits.
667
+ this.toggleAttribute("is-playing", !this.hasAttribute("is-playing"));
542
668
  return;
543
669
  }
544
670
  const loopBtn = e.target && e.target.closest ? e.target.closest(".c-time-slider__loop") : null;
@@ -549,28 +675,56 @@ class ContourTimeSlider extends ContourBase {
549
675
  this.dispatchEvent(new CustomEvent("contour:loop-change", { detail: { loop: next }, bubbles: true, composed: true }));
550
676
  }
551
677
  });
552
- // speed select change (delegated)
678
+ // Manual scrubbing is a first-class input (R20 T-30): it emits the same
679
+ this.addEventListener("pointerdown", (e) => {
680
+ if (e.target && e.target.closest && e.target.closest(".c-time-slider__track")) this._timeSliderScrubbing = true;
681
+ }, { passive: true });
682
+ const endScrub = () => { this._timeSliderScrubbing = false; };
683
+ this.addEventListener("pointerup", endScrub, { passive: true });
684
+ this.addEventListener("pointercancel", endScrub, { passive: true });
685
+ this.addEventListener("input", (e) => {
686
+ const track = e.target && e.target.closest ? e.target.closest(".c-time-slider__track") : null;
687
+ if (!track) return;
688
+ if (!this._timeSliderScrubbing) this.setAttribute("value", track.value);
689
+ syncReadout();
690
+ this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: track.value }, bubbles: true, composed: true }));
691
+ });
553
692
  this.addEventListener("change", (e) => {
554
693
  const sel = e.target && e.target.closest ? e.target.closest(".c-time-slider__speed") : null;
555
- if (!sel) return;
556
- const speed = Number(sel.value);
557
- this.dispatchEvent(new CustomEvent("contour:speed-change", { detail: { speed }, bubbles: true, composed: true }));
694
+ if (sel) {
695
+ const speed = Number(sel.value);
696
+ this.setAttribute("speed", String(speed));
697
+ // A speed change mid-play restarts the interval at the new cadence.
698
+ if (timer !== undefined) start();
699
+ this.dispatchEvent(new CustomEvent("contour:speed-change", { detail: { speed }, bubbles: true, composed: true }));
700
+ return;
701
+ }
702
+ const track = e.target && e.target.closest ? e.target.closest(".c-time-slider__track") : null;
703
+ if (track) {
704
+ this.setAttribute("value", track.value);
705
+ syncReadout();
706
+ }
558
707
  });
559
708
  onDispose(this, stop);
709
+ this._timeSliderReconcile();
560
710
  }
561
711
  disconnectedCallback() {
562
712
  super.disconnectedCallback();
563
713
  this._wiredTimeSlider = false;
714
+ // Drop the stale closure too: a reconnect re-wires, and the old
715
+ // reconciler would start a second timer over the new one.
716
+ this._timeSliderReconcile = null;
564
717
  }
565
718
  }
566
719
  define("contour-time-slider", ContourTimeSlider);
567
720
  class ContourHexbin extends ContourBase {
568
- static get observed() { return ["label", "cells", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
569
- 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" } }; }
570
723
  render() {
571
724
  this.classList.add("c-hexbin");
572
- this.setAttribute("role", "img");
573
- this.setAttribute("aria-label", "Hexbin");
725
+ // Cells are focusable marks; role=img makes them presentational.
726
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
727
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Hexbin");
574
728
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
575
729
  if (label) {
576
730
  const l = this.ensure(".c-hexbin__label", () => { const el = document.createElement("span"); el.className = "c-hexbin__label"; return el; });
@@ -587,33 +741,65 @@ class ContourHexbin extends ContourBase {
587
741
  // Slotted content support: authored .c-hexbin__cell children take
588
742
  // precedence over the JSON `cells` attribute.
589
743
  const authoredCells = Array.from(this.querySelectorAll(":scope > .c-hexbin__cell"));
590
- let parsed = null;
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");
591
751
  if (authoredCells.length) {
592
- parsed = authoredCells.map((el) => el.textContent || el.getAttribute("title") || "");
593
- authoredCells.forEach((el) => el.remove());
594
- } else if (effectiveCells) {
595
- try { parsed = JSON.parse(effectiveCells); } catch (e) { parsed = null; }
596
- }
597
- if (parsed) {
598
- try {
599
- Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
600
- const cols = Math.ceil(Math.sqrt(parsed.length || 1));
601
- this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
602
- this.style.inlineSize = "16rem";
603
- parsed.forEach((c, i) => {
604
- const cell = document.createElement("div");
605
- cell.className = "c-hexbin__cell";
606
- cell.setAttribute("tabindex", i === 0 ? "0" : "-1");
607
- if (typeof c === "object" && c.value != null) { cell.textContent = c.value; cell.setAttribute("title", String(c.value)); }
608
- else if (typeof c !== "object") { cell.textContent = c; cell.setAttribute("title", String(c)); }
609
- this.appendChild(cell);
610
- });
611
- 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; });
612
- tip.setAttribute("hidden", "");
613
- } catch (e) { /* keep existing */ }
614
- } else if (!parsed) {
615
- Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
616
- renderEmpty(this, "hexbin");
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
+ }
617
803
  }
618
804
  }
619
805
  enhance() {
@@ -621,15 +807,16 @@ class ContourHexbin extends ContourBase {
621
807
  this._wiredHexbin = true;
622
808
  wireMapItems(this, ".c-hexbin__cell", ".c-hexbin__tooltip");
623
809
  }
624
- }
625
- define("contour-hexbin", ContourHexbin);
810
+ }
811
+ define("contour-hexbin", ContourHexbin);
626
812
  class ContourFlowMap extends ContourBase {
627
- static get observed() { return ["label", "nodes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
628
- 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" } }; }
629
815
  render() {
630
816
  this.classList.add("c-flow-map");
631
- this.setAttribute("role", "img");
632
- this.setAttribute("aria-label", "Flow map");
817
+ // Nodes are focusable marks; role=img makes them presentational.
818
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
819
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Flow map");
633
820
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
634
821
  if (label) {
635
822
  const l = this.ensure(".c-flow-map__label", () => { const el = document.createElement("span"); el.className = "c-flow-map__label"; return el; });
@@ -648,7 +835,7 @@ class ContourFlowMap extends ContourBase {
648
835
  const authoredNodes = Array.from(this.querySelectorAll(":scope > .c-flow-map__node"));
649
836
  let parsed = null;
650
837
  if (authoredNodes.length) {
651
- parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("title") || "");
838
+ parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
652
839
  authoredNodes.forEach((el) => el.remove());
653
840
  } else if (effectiveNodes) {
654
841
  try { parsed = JSON.parse(effectiveNodes); } catch (e) { parsed = null; }
@@ -661,16 +848,72 @@ class ContourFlowMap extends ContourBase {
661
848
  node.className = "c-flow-map__node" + (n.source ? " c-flow-map__node--source" : "") + (n.target ? " c-flow-map__node--target" : "");
662
849
  node.setAttribute("tabindex", i === 0 ? "0" : "-1");
663
850
  node.textContent = typeof n === "string" ? n : (n.label || n.name || "");
664
- 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);
665
852
  this.appendChild(node);
666
853
  });
667
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; });
668
855
  tip.setAttribute("hidden", "");
669
- } catch (e) { /* keep existing */ }
856
+ } catch (e) { warnBadJson(this, "attribute", e); }
670
857
  } else if (!parsed) {
671
858
  Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
672
859
  renderEmpty(this, "flow-map");
673
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
+ }
674
917
  }
675
918
  enhance() {
676
919
  if (this._wiredFlowMap) return;
@@ -680,12 +923,13 @@ class ContourFlowMap extends ContourBase {
680
923
  }
681
924
  define("contour-flow-map", ContourFlowMap);
682
925
  class ContourIsochrone extends ContourBase {
683
- 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"]; }
684
927
  static get properties() { return { label: { attribute: "label" }, center: { attribute: "center" }, rings: { attribute: "rings" }, src: { attribute: "src" } }; }
685
928
  render() {
686
929
  this.classList.add("c-isochrone");
687
- this.setAttribute("role", "img");
688
- this.setAttribute("aria-label", "Isochrone");
930
+ // Rings are focusable marks; role=img makes them presentational.
931
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
932
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Isochrone");
689
933
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
690
934
  if (label) {
691
935
  const l = this.ensure(".c-isochrone__label", () => { const el = document.createElement("span"); el.className = "c-isochrone__label"; return el; });
@@ -712,7 +956,7 @@ class ContourIsochrone extends ContourBase {
712
956
  const authoredRings = Array.from(this.querySelectorAll(":scope > .c-isochrone__ring"));
713
957
  let parsed = null;
714
958
  if (authoredRings.length) {
715
- parsed = authoredRings.map((el) => el.textContent || el.getAttribute("title") || "");
959
+ parsed = authoredRings.map((el) => el.textContent || el.getAttribute("data-title") || el.getAttribute("title") || "");
716
960
  authoredRings.forEach((el) => el.remove());
717
961
  } else if (effectiveRings) {
718
962
  try { parsed = JSON.parse(effectiveRings); } catch (e) { parsed = null; }
@@ -722,14 +966,19 @@ class ContourIsochrone extends ContourBase {
722
966
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
723
967
  parsed.forEach((r, i) => {
724
968
  const ring = document.createElement("span");
725
- ring.className = "c-isochrone__ring c-isochrone__ring--" + (r.label || r);
969
+ // A ring may be a string or an object. Concatenating the object put
970
+ const raw = typeof r === "string" ? r : (r && (r.label || r.name || r.value || r.min));
971
+ const ringLabel = raw === undefined || raw === null ? "" : String(raw);
972
+ const slug = ringLabel.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
973
+ ring.className = "c-isochrone__ring" + (slug ? " c-isochrone__ring--" + slug : "");
726
974
  ring.setAttribute("tabindex", i === 0 ? "0" : "-1");
727
- if (r.label) ring.setAttribute("title", r.label || r);
975
+ ring.setAttribute("aria-label", ringLabel || "Isochrone ring " + (i + 1));
976
+ if (ringLabel) ring.setAttribute("data-title", ringLabel);
728
977
  this.appendChild(ring);
729
978
  });
730
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; });
731
980
  tip.setAttribute("hidden", "");
732
- } catch (e) { /* keep existing */ }
981
+ } catch (e) { warnBadJson(this, "attribute", e); }
733
982
  } else if (!parsed) {
734
983
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
735
984
  renderEmpty(this, "isochrone");
@@ -743,12 +992,12 @@ class ContourIsochrone extends ContourBase {
743
992
  }
744
993
  define("contour-isochrone", ContourIsochrone);
745
994
  class ContourCatchment extends ContourBase {
746
- 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"]; }
747
996
  static get properties() { return { label: { attribute: "label" }, area: { attribute: "area" }, center: { attribute: "center" }, src: { attribute: "src" } }; }
748
997
  render() {
749
998
  this.classList.add("c-catchment");
750
- this.setAttribute("role", "img");
751
- this.setAttribute("aria-label", "Catchment");
999
+ if (!this.hasAttribute("role")) this.setAttribute("role", "img");
1000
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Catchment");
752
1001
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
753
1002
  if (label) {
754
1003
  const l = this.ensure(".c-catchment__label", () => { const el = document.createElement("span"); el.className = "c-catchment__label"; return el; });
@@ -817,15 +1066,24 @@ class ContourCatchment extends ContourBase {
817
1066
  }
818
1067
  define("contour-catchment", ContourCatchment);
819
1068
  class ContourCompassFull extends ContourBase {
820
- 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"]; }
821
1070
  static get properties() { return { label: { attribute: "label" }, needle: { attribute: "needle" }, src: { attribute: "src" } }; }
822
1071
  render() {
823
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");
1076
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("label") || "Compass");
824
1077
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
825
1078
  wireStates(this);
826
1079
  loadRemote(this, "needle");
827
1080
  if (renderStates(this, "compass")) return;
828
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
+ }
829
1087
  // Cardinal directions.
830
1088
  for (const dir of ["n", "s", "e", "w"]) {
831
1089
  const cls = ".c-compass__label--" + dir;
@@ -870,16 +1128,11 @@ class ContourCompassFull extends ContourBase {
870
1128
  const n = this.querySelector("svg.c-compass__needle, .c-compass__needle");
871
1129
  if (n) n.remove();
872
1130
  }
873
- if (!needle && !label) {
874
- renderEmpty(this, "compass");
875
- }
876
1131
  }
877
1132
  enhance() {
878
1133
  if (this._wiredCompass) return;
879
1134
  this._wiredCompass = true;
880
1135
  // A cardinal is the compass's input: activate one to set the bearing and
881
- // report it. The labels are rebuilt by render, so the handler is delegated
882
- // on the host (rule 12) and resolves the degrees from the label itself.
883
1136
  const DEGREES = { n: 0, e: 90, s: 180, w: 270 };
884
1137
  const setBearing = (dir) => {
885
1138
  const deg = DEGREES[dir];
@@ -911,10 +1164,14 @@ class ContourCompassFull extends ContourBase {
911
1164
  }
912
1165
  define("contour-compass", ContourCompassFull);
913
1166
  class ContourLayerSwitch extends ContourBase {
914
- 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"]; }
915
1168
  static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
916
1169
  render() {
917
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"));
918
1175
  wireStates(this);
919
1176
  loadRemote(this, "items");
920
1177
  if (renderStates(this, "layer-switch")) return;
@@ -928,10 +1185,21 @@ class ContourLayerSwitch extends ContourBase {
928
1185
  capped.forEach((it) => {
929
1186
  const item = document.createElement("div");
930
1187
  item.className = "c-layer-switch__item";
931
- item.setAttribute("role", "group");
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);
932
1196
  const sw = document.createElement("span");
933
1197
  sw.className = "c-layer-switch__swatch";
934
- if (it.color) sw.style.background = it.color;
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; } }
935
1203
  sw.setAttribute("aria-hidden", "true");
936
1204
  item.appendChild(sw);
937
1205
  const name = document.createElement("span");
@@ -944,16 +1212,18 @@ class ContourLayerSwitch extends ContourBase {
944
1212
  c.textContent = it.count;
945
1213
  item.appendChild(c);
946
1214
  }
947
- const toggle = document.createElement("button");
948
- toggle.className = "c-layer-switch__toggle";
949
- toggle.type = "button";
950
- toggle.setAttribute("aria-label", "Toggle " + (typeof it === "string" ? it : (it.name || it.label || "layer")));
951
- toggle.setAttribute("aria-pressed", "true");
952
- toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-check" /></svg>';
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>');
953
1223
  item.appendChild(toggle);
954
1224
  this.appendChild(item);
955
1225
  });
956
- } catch (e) { /* keep existing */ }
1226
+ } catch (e) { warnBadJson(this, "attribute", e); }
957
1227
  } else if (!items && !authored.length) {
958
1228
  Array.from(this.querySelectorAll(".c-layer-switch__item")).forEach((n) => n.remove());
959
1229
  renderEmpty(this, "layer-switch");
@@ -967,9 +1237,13 @@ class ContourLayerSwitch extends ContourBase {
967
1237
  if (!btn || !this.contains(btn)) return;
968
1238
  const item = btn.closest(".c-layer-switch__item");
969
1239
  const name = item ? (item.querySelector(".c-layer-switch__name")?.textContent || "") : "";
1240
+ const layerId = item && item.dataset ? (item.dataset.layerId || "") : "";
970
1241
  const now = btn.getAttribute("aria-pressed") !== "true";
971
1242
  btn.setAttribute("aria-pressed", String(now));
972
- this.dispatchEvent(new CustomEvent("contour:layer-toggle", { bubbles: true, composed: true, detail: { name, visible: now } }));
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 } }));
973
1247
  });
974
1248
  this.addEventListener("keydown", (e) => {
975
1249
  const btn = e.target && e.target.closest ? e.target.closest(".c-layer-switch__toggle") : null;
@@ -979,6 +1253,45 @@ class ContourLayerSwitch extends ContourBase {
979
1253
  }
980
1254
  }
981
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);
982
1295
  class ContourMapSlot extends ContourBase {
983
1296
  static get observed() { return ["attribution", "scale", "chrome"]; }
984
1297
  static get properties() { return { attribution: { attribute: "attribution" }, scale: { attribute: "scale" }, chrome: { attribute: "chrome" } }; }
@@ -1012,12 +1325,31 @@ class ContourMapSlot extends ContourBase {
1012
1325
  }
1013
1326
  define("contour-map-slot", ContourMapSlot);
1014
1327
  class ContourMapArea extends ContourBase {
1015
- static get observed() { return ["attribution", "attribution-mark", "scale", "controls"]; }
1016
- 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" } }; }
1017
1330
  render() {
1018
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
+ }
1347
+ if (!this.hasAttribute("role")) this.setAttribute("role", "region");
1348
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "map-area", "Map area"));
1019
1349
  const attribution = this.getAttribute("attribution");
1020
- if (attribution) {
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") {
1021
1353
  const a = this.ensure(".c-map-slot__attribution", () => { const el = document.createElement("div"); el.className = "c-map-slot__attribution"; return el; });
1022
1354
  a.textContent = attribution;
1023
1355
  } else {
@@ -1033,7 +1365,8 @@ class ContourMapArea extends ContourBase {
1033
1365
  if (m) m.remove();
1034
1366
  }
1035
1367
  const scale = this.getAttribute("scale");
1036
- if (scale) {
1368
+ // `scale="engine"` defers to the engine's own ScaleControl (no doubling).
1369
+ if (scale && scale !== "engine") {
1037
1370
  const sc = this.ensure(".c-map-slot__scale", () => { const el = document.createElement("div"); el.className = "c-map-slot__scale"; return el; });
1038
1371
  sc.textContent = scale;
1039
1372
  } else {
@@ -1045,15 +1378,27 @@ class ContourMapArea extends ContourBase {
1045
1378
  try {
1046
1379
  const parsed = JSON.parse(controls);
1047
1380
  const wrap = this.ensure(".c-map-slot__controls", () => { const el = document.createElement("div"); el.className = "c-map-slot__controls"; return el; });
1048
- wrap.innerHTML = "";
1381
+ setHTML(wrap, "");
1049
1382
  parsed.forEach((c) => {
1050
1383
  const btn = document.createElement("button");
1051
1384
  btn.className = "c-map-slot__control";
1052
1385
  btn.type = "button";
1053
- btn.textContent = typeof c === "string" ? c : (c.label || c);
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));
1054
1399
  wrap.appendChild(btn);
1055
1400
  });
1056
- } catch (e) { /* keep existing */ }
1401
+ } catch (e) { warnBadJson(this, "attribute", e); }
1057
1402
  } else {
1058
1403
  const w = this.querySelector(".c-map-slot__controls");
1059
1404
  if (w) w.remove();
@@ -1063,20 +1408,19 @@ class ContourMapArea extends ContourBase {
1063
1408
  if (this._wiredMapArea) return;
1064
1409
  this._wiredMapArea = true;
1065
1410
  // Map-engine seam (BY3-I3): Contour never imports a map library. A
1066
- // consumer attaches a live engine instance via attachMap(); the component
1067
- // stores the reference and reads viewport bounds through duck-typing so
1068
- // the boundary (no engine imports, no GeoJSON) holds. detachMap() clears it.
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.
1069
1414
  this._map = null;
1070
- this.attachMap = (map) => { this._map = map || null; this.dispatchEvent(new CustomEvent("contour:map-attach", { bubbles: true, composed: true })); };
1071
- this.detachMap = () => { this._map = null; this.dispatchEvent(new CustomEvent("contour:map-detach", { bubbles: true, composed: true })); };
1072
- Object.defineProperty(this, "map", { get: () => this._map, set: (m) => this.attachMap(m) });
1073
1415
  this.getViewport = () => {
1074
1416
  const m = this._map;
1075
1417
  if (!m) return null;
1076
1418
  try {
1077
1419
  if (typeof m.getBounds === "function") {
1078
1420
  const b = m.getBounds();
1079
- return { west: b.getWest(), south: b.getSouth(), east: b.getEast(), north: b.getNorth() };
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() });
1080
1424
  }
1081
1425
  if (m.transform && typeof m.transform === "object") {
1082
1426
  return { zoom: m.transform.zoom, center: m.transform.center };
@@ -1084,6 +1428,196 @@ class ContourMapArea extends ContourBase {
1084
1428
  } catch (e) { /* engine API mismatch */ }
1085
1429
  return null;
1086
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
+ };
1087
1621
  this.addEventListener("click", (e) => {
1088
1622
  const btn = e.target && e.target.closest ? e.target.closest(".c-map-slot__control") : null;
1089
1623
  if (!btn || !this.contains(btn)) return;
@@ -1099,10 +1633,16 @@ class ContourMapPanel extends ContourBase {
1099
1633
  this.classList.add("c-map-panel");
1100
1634
  if (!this.hasAttribute("role")) this.setAttribute("role", "region");
1101
1635
  const title = this.getAttribute("title");
1636
+ // The accessible name follows the title only while it is the one we
1102
1637
  if (title) {
1103
- if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", title);
1104
- } else {
1105
- if (this.getAttribute("aria-label") === this.getAttribute("title")) this.removeAttribute("aria-label");
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;
1106
1646
  }
1107
1647
  }
1108
1648
  }
@@ -1117,36 +1657,47 @@ class ContourMapFooter extends ContourBase {
1117
1657
  // The footer's own rule is `.c-map-footer > *`, which reaches any direct
1118
1658
  // child, so the brand is a plain span: visible, and inventing no name.
1119
1659
  if (brand) {
1120
- const b = this.ensure("[data-map-footer-brand]", () => { const el = document.createElement("span"); el.setAttribute("data-map-footer-brand", ""); return el; });
1660
+ const b = this.ensure(".c-map-footer__brand", () => { const el = document.createElement("span"); el.className = "c-map-footer__brand"; return el; });
1121
1661
  b.textContent = brand;
1122
1662
  } else {
1123
- const b = this.querySelector("[data-map-footer-brand]");
1663
+ const b = this.querySelector(".c-map-footer__brand");
1124
1664
  if (b) b.remove();
1125
1665
  }
1126
1666
  }
1127
1667
  }
1128
1668
  define("contour-map-footer", ContourMapFooter);
1129
1669
  class ContourScaleBar extends ContourBase {
1130
- static get observed() { return ["label", "value", "distance", "resolution", "latitude", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1131
- 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" } }; }
1132
1672
  render() {
1133
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"));
1134
1677
  wireStates(this);
1135
1678
  loadRemote(this, ["label", "value"]);
1136
1679
  if (renderStates(this, "scale-bar")) return;
1137
1680
  let value = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
1138
1681
  // BY-23: derive the bar width from map resolution + latitude when the
1139
- // author gives a resolution (meters per pixel) instead of a raw pixel
1140
- // length. A scale bar is a ground distance, so its pixel length is
1141
- // distance / resolution; latitude is recorded for the Mercator-aware
1142
- // consumers that read it back.
1143
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
+ }
1144
1690
  let derivedLabel = null;
1145
- if (Number.isFinite(resolution) && resolution > 0) {
1691
+ if (Number.isFinite(effectiveResolution) && effectiveResolution > 0) {
1146
1692
  const distance = parseFloat(this.getAttribute("distance")) || 1000;
1147
- value = String(Math.round(distance / resolution));
1693
+ value = String(Math.round(distance / effectiveResolution));
1148
1694
  if (!this.getAttribute("label") && !remoteData(this, "label")) {
1149
- derivedLabel = distance >= 1000 ? (distance / 1000) + " km" : distance + " m";
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
+ }
1150
1701
  }
1151
1702
  }
1152
1703
  const label = derivedLabel || remoteData(this, "label") || (this._remoteData && this._remoteData.label);
@@ -1157,6 +1708,11 @@ class ContourScaleBar extends ContourBase {
1157
1708
  const l = this.querySelector(".c-scale-bar__label");
1158
1709
  if (l) l.remove();
1159
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"); };
1160
1716
  if (!value) {
1161
1717
  renderEmpty(this, "scale-bar");
1162
1718
  return;
@@ -1181,8 +1737,8 @@ class ContourScaleBar extends ContourBase {
1181
1737
  define("contour-scale-bar", ContourScaleBar);
1182
1738
 
1183
1739
  class ContourSplitMap extends ContourBase {
1184
- static get observed() { return ["left", "right"]; }
1185
- static get properties() { return { left: { attribute: "left" }, right: { attribute: "right" } }; }
1740
+ // R24-77: split-map is a static two-pane layout primitive, not an interactive
1741
+ static get observed() { return []; }
1186
1742
  render() {
1187
1743
  this.classList.add("c-split-map");
1188
1744
  const left = this.ensure(".c-split-map__pane--left", () => {
@@ -1200,3 +1756,50 @@ class ContourSplitMap extends ContourBase {
1200
1756
  }
1201
1757
  }
1202
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);