contour-ds 1.1.2 → 1.5.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 (71) hide show
  1. package/README.md +7 -1
  2. package/dist/agent-rules.json +5 -1
  3. package/dist/build-manifest.json +93 -92
  4. package/dist/contour-wc.esm.js +4113 -480
  5. package/dist/contour-wc.esm.min.js +1 -1
  6. package/dist/contour-wc.js +4115 -478
  7. package/dist/contour-wc.min.js +1 -1
  8. package/dist/contour.components.json +2597 -135
  9. package/dist/contour.css +625 -27
  10. package/dist/contour.d.ts +109 -61
  11. package/dist/contour.esm.js +16 -0
  12. package/dist/contour.js +16 -0
  13. package/dist/contour.min.css +1 -1
  14. package/dist/contour.tokens.json +37 -0
  15. package/dist/docs/actions.md +6 -2
  16. package/dist/docs/affordances.md +19 -3
  17. package/dist/docs/colour.md +2 -2
  18. package/dist/docs/componentindex.md +39 -0
  19. package/dist/docs/data.md +38 -3
  20. package/dist/docs/docs.md +6 -2
  21. package/dist/docs/feedback.md +13 -3
  22. package/dist/docs/field.md +7 -2
  23. package/dist/docs/forms.md +35 -3
  24. package/dist/docs/index.json +32 -76
  25. package/dist/docs/install.md +4 -2
  26. package/dist/docs/landing.md +3 -2
  27. package/dist/docs/mapengine.md +9 -3
  28. package/dist/docs/motion.md +5 -2
  29. package/dist/docs/navigation.md +10 -3
  30. package/dist/docs/overlays.md +26 -3
  31. package/dist/docs/overview.md +2 -2
  32. package/dist/docs/patterns.md +38 -3
  33. package/dist/docs/playground.md +5 -2
  34. package/dist/docs/principles.md +2 -2
  35. package/dist/docs/recipes.md +7 -3
  36. package/dist/docs/space.md +2 -2
  37. package/dist/docs/status.md +19 -3
  38. package/dist/docs/surfaces.md +7 -3
  39. package/dist/docs/theming.md +5 -2
  40. package/dist/docs/type.md +2 -2
  41. package/dist/docs/webcomponents.md +26 -3
  42. package/dist/map-chrome.mapbox.css +4 -4
  43. package/dist/map-chrome.maplibre.css +4 -4
  44. package/dist/registry/items/contour-core.json +2 -2
  45. package/dist/registry/items/contour-data.json +2 -2
  46. package/dist/registry/items/contour-docs.json +2 -2
  47. package/dist/registry/items/contour-landing.json +2 -2
  48. package/dist/registry/registry.json +8 -8
  49. package/dist/surfaces/contour-core.min.css +1 -1
  50. package/dist/surfaces/contour-data.min.css +1 -1
  51. package/dist/surfaces/contour-docs.min.css +1 -1
  52. package/dist/surfaces/contour-landing.min.css +1 -1
  53. package/dist/wc/behaviours.mjs +69 -11
  54. package/dist/wc/content.mjs +163 -8
  55. package/dist/wc/core.mjs +145 -34
  56. package/dist/wc/dashboard.mjs +69 -4
  57. package/dist/wc/data.mjs +866 -115
  58. package/dist/wc/docs.mjs +1 -0
  59. package/dist/wc/feedback.mjs +75 -13
  60. package/dist/wc/forms.mjs +371 -34
  61. package/dist/wc/index.mjs +7 -3
  62. package/dist/wc/interaction.mjs +11 -6
  63. package/dist/wc/map.mjs +121 -38
  64. package/dist/wc/misc.mjs +29 -1
  65. package/dist/wc/navigation.mjs +424 -75
  66. package/dist/wc/registration.mjs +8 -4
  67. package/dist/wc/shadow.mjs +29 -12
  68. package/dist/wc/states.mjs +15 -0
  69. package/dist/wc/svg.mjs +10 -0
  70. package/dist/wc/ui.mjs +1710 -126
  71. package/package.json +39 -6
package/dist/wc/map.mjs CHANGED
@@ -75,6 +75,8 @@ class ContourMinimap extends ContourBase {
75
75
  static get properties() { return { label: { attribute: "label" }, viewport: { attribute: "viewport" }, src: { attribute: "src" } }; }
76
76
  render() {
77
77
  this.classList.add("c-minimap");
78
+ this.setAttribute("role", "img");
79
+ this.setAttribute("aria-label", "Minimap");
78
80
  wireStates(this);
79
81
  loadRemote(this, ["label", "viewport"]);
80
82
  if (renderStates(this, "minimap")) return;
@@ -102,6 +104,7 @@ class ContourMinimap extends ContourBase {
102
104
  enhance() {
103
105
  if (this._wiredMinimap) return;
104
106
  this._wiredMinimap = true;
107
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
105
108
  let dragging = false;
106
109
  this.addEventListener("pointerdown", (e) => {
107
110
  const vp = this.querySelector(".c-minimap__viewport");
@@ -114,12 +117,24 @@ class ContourMinimap extends ContourBase {
114
117
  this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag" }, bubbles: true, composed: true }));
115
118
  });
116
119
  this.addEventListener("pointerup", () => { dragging = false; });
120
+ this.addEventListener("keydown", (e) => {
121
+ let dir = null;
122
+ if (e.key === "ArrowUp") dir = "up";
123
+ else if (e.key === "ArrowDown") dir = "down";
124
+ else if (e.key === "ArrowLeft") dir = "left";
125
+ else if (e.key === "ArrowRight") dir = "right";
126
+ else if (e.key === "Home") dir = "home";
127
+ else if (e.key === "End") dir = "end";
128
+ if (!dir) return;
129
+ e.preventDefault();
130
+ this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: dir }, bubbles: true, composed: true }));
131
+ });
117
132
  }
118
133
  }
119
134
  define("contour-minimap", ContourMinimap);
120
135
  class ContourCoordinate extends ContourBase {
121
- static get observed() { return ["value", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
122
- static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
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" } }; }
123
138
  render() {
124
139
  this.classList.add("c-coordinate");
125
140
  wireStates(this);
@@ -136,13 +151,16 @@ class ContourCoordinate extends ContourBase {
136
151
  // simple DMS conversion assuming decimal degrees "lat,lon"
137
152
  const parts = String(value).split(/[,\s]+/).map(Number);
138
153
  if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
139
- const toDMS = (d) => {
154
+ const prec = parseInt(this.getAttribute("precision") || "1", 10);
155
+ const secDigits = Number.isFinite(prec) && prec >= 0 ? prec : 1;
156
+ const toDMS = (d, axis) => {
140
157
  const deg = Math.floor(Math.abs(d));
141
158
  const min = Math.floor((Math.abs(d) - deg) * 60);
142
159
  const sec = (((Math.abs(d) - deg) * 60) - min) * 60;
143
- return deg + "°" + min + "'" + sec.toFixed(1) + '"' + (d < 0 ? "S" : "N");
160
+ const hemi = axis === "lat" ? (d < 0 ? "S" : "N") : (d < 0 ? "W" : "E");
161
+ return deg + "°" + min + "'" + sec.toFixed(secDigits) + '"' + hemi;
144
162
  };
145
- text = toDMS(parts[0]) + " " + toDMS(parts[1]);
163
+ text = toDMS(parts[0], "lat") + " " + toDMS(parts[1], "lon");
146
164
  }
147
165
  } else if (format === "web-mercator") {
148
166
  const parts = String(value).split(/[,\s]+/).map(Number);
@@ -154,7 +172,7 @@ class ContourCoordinate extends ContourBase {
154
172
  } else {
155
173
  text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
156
174
  }
157
- const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value"; return el; });
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; });
158
176
  span.textContent = text;
159
177
  // copy button
160
178
  let btn = this.querySelector(".c-coordinate__copy");
@@ -189,6 +207,8 @@ class ContourLayerPanel extends ContourBase {
189
207
  static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
190
208
  render() {
191
209
  this.classList.add("c-layer-panel");
210
+ this.setAttribute("role", "group");
211
+ this.setAttribute("aria-label", "Layer panel");
192
212
  wireStates(this);
193
213
  loadRemote(this, "items");
194
214
  if (renderStates(this, "layer-panel")) return;
@@ -244,7 +264,7 @@ class ContourLayerPanel extends ContourBase {
244
264
  const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
245
265
  toggle.setAttribute("aria-pressed", String(!!isVisible));
246
266
  toggle.checked = !!isVisible;
247
- toggle.textContent = isVisible ? "●" : "○";
267
+ toggle.innerHTML = isVisible ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
248
268
  item.appendChild(toggle);
249
269
  const nm = document.createElement("span");
250
270
  nm.className = "c-layer-panel__name";
@@ -293,12 +313,12 @@ class ContourLayerPanel extends ContourBase {
293
313
  const removeBtn = document.createElement("button");
294
314
  removeBtn.type = "button";
295
315
  removeBtn.className = "c-layer-panel__remove";
296
- removeBtn.textContent = "✕";
316
+ removeBtn.innerHTML = '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
297
317
  removeBtn.setAttribute("aria-label", "Remove " + (name || "layer"));
298
318
  item.appendChild(removeBtn);
299
319
  }
300
320
  const projSel = document.createElement("select");
301
- projSel.className = "c-layer-panel__projection";
321
+ projSel.className = "c-select c-layer-panel__projection";
302
322
  projSel.setAttribute("aria-label", "Projection of " + (name || "layer"));
303
323
  ["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
304
324
  item.appendChild(projSel);
@@ -323,7 +343,7 @@ class ContourLayerPanel extends ContourBase {
323
343
  const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
324
344
  e.target.checked = now;
325
345
  e.target.setAttribute("aria-pressed", String(now));
326
- e.target.textContent = now ? "●" : "○";
346
+ e.target.innerHTML = now ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
327
347
  this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
328
348
  } else if (e.target.classList.contains("c-layer-panel__opacity")) {
329
349
  this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
@@ -341,19 +361,35 @@ class ContourLayerPanel extends ContourBase {
341
361
  const now = btn.getAttribute("aria-pressed") !== "true";
342
362
  btn.setAttribute("aria-pressed", String(now));
343
363
  btn.checked = now;
344
- btn.textContent = now ? "●" : "○";
364
+ btn.innerHTML = now ? '<svg aria-hidden="true"><use href="#i-check" /></svg>' : '<svg aria-hidden="true"><use href="#i-minus" /></svg>';
345
365
  this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
346
366
  return;
347
367
  }
348
368
  if (!item) return;
349
369
  const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
350
370
  if (btn.classList.contains("c-layer-panel__rename")) {
351
- const newName = prompt("Rename layer", name);
352
- const trimmed = newName ? newName.trim() : "";
353
- if (trimmed && trimmed !== name) {
354
- const nm = item.querySelector(".c-layer-panel__name");
355
- if (nm) nm.textContent = trimmed;
356
- this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
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();
383
+ const span = document.createElement("span");
384
+ span.className = "c-layer-panel__name";
385
+ span.textContent = trimmed || name;
386
+ 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 });
357
393
  }
358
394
  } else if (btn.classList.contains("c-layer-panel__duplicate")) {
359
395
  this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
@@ -391,15 +427,15 @@ class ContourLayerPanel extends ContourBase {
391
427
  }
392
428
  define("contour-layer-panel", ContourLayerPanel);
393
429
  class ContourTimeSlider extends ContourBase {
394
- static get observed() { return ["label", "value", "loop", "speed", "speeds", "show-loop", "loop-label", "current-time", "time-format", "is-playing"]; }
395
- static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
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" } }; }
396
432
  render() {
397
433
  this.classList.add("c-time-slider");
398
434
  const play = this.ensure(".c-time-slider__play", () => {
399
435
  const el = document.createElement("button");
400
436
  el.className = "c-time-slider__play";
401
437
  el.type = "button";
402
- el.setAttribute("aria-label", "Play");
438
+ el.setAttribute("aria-label", this.getAttribute("play-label") || "Play");
403
439
  el.setAttribute("data-state", "play");
404
440
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
405
441
  svg.setAttribute("aria-hidden", "true");
@@ -409,13 +445,13 @@ class ContourTimeSlider extends ContourBase {
409
445
  el.appendChild(svg);
410
446
  return el;
411
447
  });
412
- 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", "Time"); return el; });
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; });
413
449
  const _attrVal = this.getAttribute("value") || "0";
414
450
  if (this._timeSliderAttrLast !== _attrVal) {
415
451
  track.value = _attrVal;
416
452
  this._timeSliderAttrLast = _attrVal;
417
453
  }
418
- track.setAttribute("aria-label", this.getAttribute("label") || "Time");
454
+ track.setAttribute("aria-label", this.getAttribute("label") || this.getAttribute("time-label") || "Time");
419
455
  const time = this.ensure(".c-time-slider__time", () => { const el = document.createElement("span"); el.className = "c-time-slider__time"; return el; });
420
456
  const ct = this.getAttribute("current-time");
421
457
  time.textContent = ct ? ct : (this.getAttribute("label") || "");
@@ -423,7 +459,7 @@ class ContourTimeSlider extends ContourBase {
423
459
  let speeds = null;
424
460
  const speedsAttr = this.getAttribute("speeds");
425
461
  if (speedsAttr) { try { speeds = JSON.parse(speedsAttr); } catch (e) { speeds = null; } }
426
- const speedSel = this.ensure(".c-time-slider__speed", () => { const el = document.createElement("select"); el.className = "c-time-slider__speed"; el.setAttribute("aria-label", "Speed"); return el; });
462
+ 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; });
427
463
  speedSel.innerHTML = "";
428
464
  const speedList = Array.isArray(speeds) ? speeds : [0.5, 1, 2, 5, 10];
429
465
  speedList.forEach((sp) => {
@@ -448,7 +484,7 @@ class ContourTimeSlider extends ContourBase {
448
484
  // is-playing reflects on play button
449
485
  if (this.hasAttribute("is-playing")) {
450
486
  play.setAttribute("data-state", "pause");
451
- play.setAttribute("aria-label", "Pause");
487
+ play.setAttribute("aria-label", this.getAttribute("pause-label") || "Pause");
452
488
  const use = play.querySelector("use");
453
489
  if (use) use.setAttribute("href", "#i-pause");
454
490
  }
@@ -479,7 +515,7 @@ class ContourTimeSlider extends ContourBase {
479
515
  const btn = this.querySelector(".c-time-slider__play");
480
516
  if (btn) {
481
517
  btn.setAttribute("data-state", "play");
482
- btn.setAttribute("aria-label", "Play");
518
+ btn.setAttribute("aria-label", this.getAttribute("play-label") || "Play");
483
519
  const use = btn.querySelector("use");
484
520
  if (use) use.setAttribute("href", "#i-play");
485
521
  }
@@ -490,7 +526,7 @@ class ContourTimeSlider extends ContourBase {
490
526
  if (btn) {
491
527
  const playing = btn.getAttribute("data-state") === "play";
492
528
  btn.setAttribute("data-state", playing ? "pause" : "play");
493
- btn.setAttribute("aria-label", playing ? "Pause" : "Play");
529
+ btn.setAttribute("aria-label", playing ? (this.getAttribute("pause-label") || "Pause") : (this.getAttribute("play-label") || "Play"));
494
530
  const use = btn.querySelector("use");
495
531
  if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
496
532
  if (playing) {
@@ -533,6 +569,8 @@ class ContourHexbin extends ContourBase {
533
569
  static get properties() { return { label: { attribute: "label" }, cells: { attribute: "cells" }, src: { attribute: "src" } }; }
534
570
  render() {
535
571
  this.classList.add("c-hexbin");
572
+ this.setAttribute("role", "img");
573
+ this.setAttribute("aria-label", "Hexbin");
536
574
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
537
575
  if (label) {
538
576
  const l = this.ensure(".c-hexbin__label", () => { const el = document.createElement("span"); el.className = "c-hexbin__label"; return el; });
@@ -590,6 +628,8 @@ class ContourFlowMap extends ContourBase {
590
628
  static get properties() { return { label: { attribute: "label" }, nodes: { attribute: "nodes" }, src: { attribute: "src" } }; }
591
629
  render() {
592
630
  this.classList.add("c-flow-map");
631
+ this.setAttribute("role", "img");
632
+ this.setAttribute("aria-label", "Flow map");
593
633
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
594
634
  if (label) {
595
635
  const l = this.ensure(".c-flow-map__label", () => { const el = document.createElement("span"); el.className = "c-flow-map__label"; return el; });
@@ -644,6 +684,8 @@ class ContourIsochrone extends ContourBase {
644
684
  static get properties() { return { label: { attribute: "label" }, center: { attribute: "center" }, rings: { attribute: "rings" }, src: { attribute: "src" } }; }
645
685
  render() {
646
686
  this.classList.add("c-isochrone");
687
+ this.setAttribute("role", "img");
688
+ this.setAttribute("aria-label", "Isochrone");
647
689
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
648
690
  if (label) {
649
691
  const l = this.ensure(".c-isochrone__label", () => { const el = document.createElement("span"); el.className = "c-isochrone__label"; return el; });
@@ -705,6 +747,8 @@ class ContourCatchment extends ContourBase {
705
747
  static get properties() { return { label: { attribute: "label" }, area: { attribute: "area" }, center: { attribute: "center" }, src: { attribute: "src" } }; }
706
748
  render() {
707
749
  this.classList.add("c-catchment");
750
+ this.setAttribute("role", "img");
751
+ this.setAttribute("aria-label", "Catchment");
708
752
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
709
753
  if (label) {
710
754
  const l = this.ensure(".c-catchment__label", () => { const el = document.createElement("span"); el.className = "c-catchment__label"; return el; });
@@ -763,6 +807,12 @@ class ContourCatchment extends ContourBase {
763
807
  if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
764
808
  this.addEventListener("focusin", showTip);
765
809
  this.addEventListener("focusout", hideTip);
810
+ this.addEventListener("keydown", (e) => {
811
+ if (e.key === "Enter" || e.key === " ") {
812
+ e.preventDefault();
813
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { area: this.getAttribute("area") } }));
814
+ }
815
+ });
766
816
  }
767
817
  }
768
818
  define("contour-catchment", ContourCatchment);
@@ -802,13 +852,20 @@ class ContourCompassFull extends ContourBase {
802
852
  el.setAttribute("class", "c-compass__needle");
803
853
  el.setAttribute("viewBox", "0 0 40 40");
804
854
  el.setAttribute("aria-hidden", "true");
805
- const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
806
- path.setAttribute("d", compassNeedle(20, 20, 16, deg));
807
- el.appendChild(path);
855
+ const pathN = document.createElementNS("http://www.w3.org/2000/svg", "path");
856
+ pathN.setAttribute("class", "c-compass__needle--n");
857
+ pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
858
+ el.appendChild(pathN);
859
+ const pathS = document.createElementNS("http://www.w3.org/2000/svg", "path");
860
+ pathS.setAttribute("class", "c-compass__needle--s");
861
+ pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
862
+ el.appendChild(pathS);
808
863
  return el;
809
864
  });
810
- const path = n.querySelector("path");
811
- if (path) path.setAttribute("d", compassNeedle(20, 20, 16, deg));
865
+ const pathN = n.querySelector(".c-compass__needle--n");
866
+ if (pathN) pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
867
+ const pathS = n.querySelector(".c-compass__needle--s");
868
+ if (pathS) pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
812
869
  } else {
813
870
  const n = this.querySelector("svg.c-compass__needle, .c-compass__needle");
814
871
  if (n) n.remove();
@@ -829,8 +886,10 @@ class ContourCompassFull extends ContourBase {
829
886
  if (deg === undefined) return;
830
887
  const n = this.querySelector(".c-compass__needle");
831
888
  if (n) {
832
- const path = n.querySelector("path");
833
- if (path) path.setAttribute("d", compassNeedle(20, 20, 16, deg));
889
+ const pathN = n.querySelector(".c-compass__needle--n");
890
+ if (pathN) pathN.setAttribute("d", compassNeedle(20, 20, 16, deg));
891
+ const pathS = n.querySelector(".c-compass__needle--s");
892
+ if (pathS) pathS.setAttribute("d", compassNeedle(20, 20, 16, deg + 180));
834
893
  }
835
894
  this.dispatchEvent(new CustomEvent("contour:bearing", { bubbles: true, composed: true, detail: { direction: dir, degrees: deg } }));
836
895
  };
@@ -869,9 +928,11 @@ class ContourLayerSwitch extends ContourBase {
869
928
  capped.forEach((it) => {
870
929
  const item = document.createElement("div");
871
930
  item.className = "c-layer-switch__item";
931
+ item.setAttribute("role", "group");
872
932
  const sw = document.createElement("span");
873
933
  sw.className = "c-layer-switch__swatch";
874
934
  if (it.color) sw.style.background = it.color;
935
+ sw.setAttribute("aria-hidden", "true");
875
936
  item.appendChild(sw);
876
937
  const name = document.createElement("span");
877
938
  name.className = "c-layer-switch__name";
@@ -887,6 +948,7 @@ class ContourLayerSwitch extends ContourBase {
887
948
  toggle.className = "c-layer-switch__toggle";
888
949
  toggle.type = "button";
889
950
  toggle.setAttribute("aria-label", "Toggle " + (typeof it === "string" ? it : (it.name || it.label || "layer")));
951
+ toggle.setAttribute("aria-pressed", "true");
890
952
  toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-check" /></svg>';
891
953
  item.appendChild(toggle);
892
954
  this.appendChild(item);
@@ -905,7 +967,14 @@ class ContourLayerSwitch extends ContourBase {
905
967
  if (!btn || !this.contains(btn)) return;
906
968
  const item = btn.closest(".c-layer-switch__item");
907
969
  const name = item ? (item.querySelector(".c-layer-switch__name")?.textContent || "") : "";
908
- this.dispatchEvent(new CustomEvent("contour:layer-toggle", { bubbles: true, composed: true, detail: { name } }));
970
+ const now = btn.getAttribute("aria-pressed") !== "true";
971
+ btn.setAttribute("aria-pressed", String(now));
972
+ this.dispatchEvent(new CustomEvent("contour:layer-toggle", { bubbles: true, composed: true, detail: { name, visible: now } }));
973
+ });
974
+ this.addEventListener("keydown", (e) => {
975
+ const btn = e.target && e.target.closest ? e.target.closest(".c-layer-switch__toggle") : null;
976
+ if (!btn || !this.contains(btn)) return;
977
+ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
909
978
  });
910
979
  }
911
980
  }
@@ -1058,14 +1127,29 @@ class ContourMapFooter extends ContourBase {
1058
1127
  }
1059
1128
  define("contour-map-footer", ContourMapFooter);
1060
1129
  class ContourScaleBar extends ContourBase {
1061
- static get observed() { return ["label", "value", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1062
- static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
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" } }; }
1063
1132
  render() {
1064
1133
  this.classList.add("c-scale-bar");
1065
1134
  wireStates(this);
1066
1135
  loadRemote(this, ["label", "value"]);
1067
1136
  if (renderStates(this, "scale-bar")) return;
1068
- const label = remoteData(this, "label") || (this._remoteData && this._remoteData.label);
1137
+ let value = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
1138
+ // 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
+ const resolution = parseFloat(this.getAttribute("resolution"));
1144
+ let derivedLabel = null;
1145
+ if (Number.isFinite(resolution) && resolution > 0) {
1146
+ const distance = parseFloat(this.getAttribute("distance")) || 1000;
1147
+ value = String(Math.round(distance / resolution));
1148
+ if (!this.getAttribute("label") && !remoteData(this, "label")) {
1149
+ derivedLabel = distance >= 1000 ? (distance / 1000) + " km" : distance + " m";
1150
+ }
1151
+ }
1152
+ const label = derivedLabel || remoteData(this, "label") || (this._remoteData && this._remoteData.label);
1069
1153
  if (label) {
1070
1154
  const l = this.ensure(".c-scale-bar__label", () => { const el = document.createElement("span"); el.className = "c-scale-bar__label"; return el; });
1071
1155
  l.textContent = label;
@@ -1073,7 +1157,6 @@ class ContourScaleBar extends ContourBase {
1073
1157
  const l = this.querySelector(".c-scale-bar__label");
1074
1158
  if (l) l.remove();
1075
1159
  }
1076
- const value = remoteData(this, "value") || (this._remoteData && this._remoteData.value);
1077
1160
  if (!value) {
1078
1161
  renderEmpty(this, "scale-bar");
1079
1162
  return;
package/dist/wc/misc.mjs CHANGED
@@ -1,7 +1,35 @@
1
- import { ContourBase, define } from './core.mjs';
1
+ class ContourResizeObserver extends ContourBase {
2
+ static get observed() { return ["debounce"]; }
3
+ static get properties() { return { debounce: { attribute: "debounce" } }; }
4
+ render() {
5
+ this.classList.add("c-resize-observer");
6
+ this.setAttribute("aria-hidden", "true");
7
+ }
8
+ enhance() {
9
+ if (this._wiredResizeObserver) return;
10
+ this._wiredResizeObserver = true;
11
+ if (typeof ResizeObserver !== "function") return;
12
+ const debounce = parseInt(this.getAttribute("debounce") || "0", 10) || 0;
13
+ let timer = null;
14
+ const ro = new ResizeObserver((entries) => {
15
+ const fire = () => {
16
+ const e = entries[entries.length - 1];
17
+ const cr = e && e.contentRect ? e.contentRect : this.getBoundingClientRect();
18
+ this.dispatchEvent(new CustomEvent("contour:resize", { bubbles: true, composed: true, detail: { width: cr.width, height: cr.height } }));
19
+ };
20
+ if (debounce > 0) { clearTimeout(timer); timer = setTimeout(fire, debounce); }
21
+ else fire();
22
+ });
23
+ ro.observe(this);
24
+ onDispose(this, () => { ro.disconnect(); clearTimeout(timer); });
25
+ }
26
+ }
27
+ define("contour-resize-observer", ContourResizeObserver);
28
+ import { ContourBase, define, onDispose } from './core.mjs';
2
29
  import { loadRemote, remoteData, remoteRefresh, renderStates, renderEmpty, wireStates } from './states.mjs';
3
30
  class ContourReservedFull extends ContourBase {
4
31
  static get observed() { return ["title"]; }
32
+ static get properties() { return { title: { attribute: "title" } }; }
5
33
  render() {
6
34
  this.classList.add("c-reserved");
7
35
  const title = this.getAttribute("title");