contour-ds 1.0.0 → 1.1.1

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 (60) hide show
  1. package/README.md +1 -1
  2. package/dist/build-manifest.json +55 -55
  3. package/dist/contour-wc.esm.js +1461 -182
  4. package/dist/contour-wc.esm.min.js +1 -1
  5. package/dist/contour-wc.js +1461 -182
  6. package/dist/contour-wc.min.js +1 -1
  7. package/dist/contour.components.json +435 -22
  8. package/dist/contour.css +426 -45
  9. package/dist/contour.d.ts +31 -0
  10. package/dist/contour.esm.js +12 -0
  11. package/dist/contour.esm.min.js +1 -1
  12. package/dist/contour.js +12 -0
  13. package/dist/contour.min.css +1 -1
  14. package/dist/contour.min.js +1 -1
  15. package/dist/docs/actions.md +1 -1
  16. package/dist/docs/affordances.md +1 -1
  17. package/dist/docs/colour.md +1 -1
  18. package/dist/docs/data.md +1 -1
  19. package/dist/docs/docs.md +1 -1
  20. package/dist/docs/feedback.md +1 -1
  21. package/dist/docs/field.md +1 -1
  22. package/dist/docs/forms.md +1 -1
  23. package/dist/docs/index.json +15 -4
  24. package/dist/docs/install.md +1 -1
  25. package/dist/docs/landing.md +1 -1
  26. package/dist/docs/mapengine.md +1 -1
  27. package/dist/docs/motion.md +1 -1
  28. package/dist/docs/navigation.md +1 -1
  29. package/dist/docs/overlays.md +1 -1
  30. package/dist/docs/overview.md +1 -1
  31. package/dist/docs/patterns.md +1 -1
  32. package/dist/docs/playground.md +1 -1
  33. package/dist/docs/principles.md +1 -1
  34. package/dist/docs/recipes.md +1 -1
  35. package/dist/docs/space.md +1 -1
  36. package/dist/docs/status.md +1 -1
  37. package/dist/docs/surfaces.md +1 -1
  38. package/dist/docs/theming.md +1 -1
  39. package/dist/docs/type.md +1 -1
  40. package/dist/docs/webcomponents.md +1 -1
  41. package/dist/registry/items/contour-core.json +2 -2
  42. package/dist/registry/items/contour-data.json +2 -2
  43. package/dist/registry/items/contour-docs.json +2 -2
  44. package/dist/registry/items/contour-landing.json +2 -2
  45. package/dist/registry/registry.json +8 -8
  46. package/dist/surfaces/contour-core.min.css +1 -1
  47. package/dist/surfaces/contour-data.min.css +1 -1
  48. package/dist/surfaces/contour-docs.min.css +1 -1
  49. package/dist/surfaces/contour-landing.min.css +1 -1
  50. package/dist/wc/core.mjs +17 -6
  51. package/dist/wc/data.mjs +816 -45
  52. package/dist/wc/forms.mjs +119 -61
  53. package/dist/wc/index.mjs +1 -1
  54. package/dist/wc/interaction.mjs +3 -2
  55. package/dist/wc/map.mjs +280 -49
  56. package/dist/wc/navigation.mjs +66 -11
  57. package/dist/wc/shadow.mjs +29 -1
  58. package/dist/wc/svg.mjs +16 -1
  59. package/dist/wc/ui.mjs +117 -9
  60. package/package.json +1 -1
@@ -77,10 +77,14 @@
77
77
  "contour:activate": { payload: [], composed: true },
78
78
  "contour:add": { payload: ["value"], composed: true },
79
79
  "contour:activity-select": { payload: ["index", "text"], composed: true },
80
+ "contour:break-change": { payload: ["value"], composed: true },
81
+ "contour:style-resolved": { payload: ["value"], composed: true },
80
82
  "contour:advanced-toggle": { payload: ["title"], composed: true },
81
83
  "contour:affordance-activate": { payload: ["name"], composed: true },
82
84
  "contour:bearing": { payload: ["direction", "degrees"], composed: true },
83
85
  "contour:btn-group-change": { payload: ["index", "label"], composed: true },
86
+ "contour:brush-start": { payload: ["value"], composed: true },
87
+ "contour:brush-end": { payload: ["value"], composed: true },
84
88
  "contour:change": { payload: ["name", "value", "checked"], composed: true },
85
89
  "contour:close": { payload: [], composed: true },
86
90
  "contour:copy": { payload: ["text"], composed: true },
@@ -97,6 +101,12 @@
97
101
  "contour:hide": { payload: [], composed: true },
98
102
  "contour:input": { payload: ["name", "value", "checked"], composed: true },
99
103
  "contour:layer-opacity": { payload: ["name", "opacity"], composed: true },
104
+ "contour:layer-rename": { payload: ["name", "newName"], composed: true },
105
+ "contour:layer-duplicate": { payload: ["name"], composed: true },
106
+ "contour:layer-zoom": { payload: ["name"], composed: true },
107
+ "contour:layer-projection": { payload: ["name", "projection"], composed: true },
108
+ "contour:layer-remove": { payload: ["name"], composed: true },
109
+ "contour:layer-reorder": { payload: ["layerIds"], composed: true },
100
110
  "contour:layer-toggle": { payload: ["name"], composed: true },
101
111
  "contour:layer-visibility": { payload: ["name", "visible"], composed: true },
102
112
  "contour:legend-toggle": { payload: ["label", "key", "layers", "pressed"], composed: true },
@@ -104,6 +114,7 @@
104
114
  "contour:map-control": { payload: ["control"], composed: true },
105
115
  "contour:map-attach": { payload: [], composed: true },
106
116
  "contour:map-detach": { payload: [], composed: true },
117
+ "contour:mode-change": { payload: ["mode"], composed: true },
107
118
  "contour:move": { payload: ["direction"], composed: true },
108
119
  "contour:open": { payload: [], composed: true },
109
120
  "contour:page": { payload: ["page"], composed: true },
@@ -166,13 +177,13 @@
166
177
  // role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
167
178
  // Adding one of those back to this list makes that component recurse.
168
179
  export const OBSERVED = [
169
- "accept", "action", "actions", "after", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "autoplay", "axis", "axis-x", "axis-y", "before", "body", "brand", "breakpoint", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
170
- "cells", "checked", "chrome", "closable", "colors", "content", "controls", "copyable", "count", "current", "date", "delta", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot",
171
- "empty", "error", "exclusive", "format", "heading", "hint", "href", "icon", "illustration", "index", "instrument", "interval", "items", "key", "layers",
172
- "label", "lazy", "lede", "legend", "line", "link", "links", "live", "loading", "locale", "max", "media", "message", "method", "month", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "nodes", "note", "norm",
180
+ "accept", "action", "actions", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "breaks", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
181
+ "cells", "checked", "chrome", "closable", "classification", "colors", "continuous", "content", "controls", "copyable", "count", "current", "data", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot", "ends", "high", "input", "layer", "low", "mode", "modes", "n", "opacity", "palette", "polarity", "range", "single",
182
+ "empty", "error", "exclusive", "format", "heading", "hint", "href", "icon", "illustration", "index", "instrument", "interval", "items", "key", "layers", "level",
183
+ "label", "lazy", "lede", "legend", "line", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "month", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
173
184
  "options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "progress", "prompt", "question", "recent", "required",
174
- "quote", "ramp", "refresh", "removable", "reverse", "rings", "retry", "rows", "scale", "selectable", "start", "end", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "speed", "status", "step", "submit", "timeout", "trigger", "virtual",
175
- "state", "steps", "subtitle", "summary", "src", "tabs", "tag", "text", "ticks", "title", "type", "unit",
185
+ "quote", "ramp", "refresh", "removable", "reverse", "rings", "retry", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "start", "end", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "speed", "status", "step", "submit", "timeout", "trigger", "virtual",
186
+ "state", "steps", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks", "title", "type", "unit",
176
187
  "variant", "values", "viewport", "yes", "zoomable", "x", "y",
177
188
  ];
178
189
 
@@ -1099,6 +1110,22 @@ export function scaleBarTicks(value, segments) {
1099
1110
  }
1100
1111
  return out;
1101
1112
  }
1113
+ // Marker shape encoding utility (G-13)
1114
+ export const MARKER_SHAPES = ["circle", "square", "triangle", "diamond", "star"];
1115
+ export function markerStyles(shape) {
1116
+ const map = {
1117
+ circle: "border-radius:50%",
1118
+ square: "border-radius:0",
1119
+ triangle: "clip-path:polygon(50% 0%,0% 100%,100% 100%)",
1120
+ diamond: "transform:rotate(45deg)",
1121
+ star: "clip-path:polygon(50% 0%,61% 35%,98% 35%,68% 57%,79% 91%,50% 70%,21% 91%,32% 57%,2% 35%,39% 35%)",
1122
+ };
1123
+ return map[shape] || "";
1124
+ }
1125
+ export function assignMarkers(items) {
1126
+ return (items || []).map((it, i) => ({ ...it, marker: MARKER_SHAPES[i % MARKER_SHAPES.length] }));
1127
+ }
1128
+
1102
1129
  /* ============================================================================
1103
1130
  CONTOUR — shared behaviour
1104
1131
  ----------------------------------------------------------------------------
@@ -3733,9 +3760,9 @@ class ContourReadout extends ContourBase {
3733
3760
  }
3734
3761
  define("contour-readout", ContourReadout);
3735
3762
  class ContourKpi extends ContourBase {
3736
- static get observed() { return ["value", "label", "delta", "direction", "note", "variant", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
3763
+ static get observed() { return ["value", "label", "delta", "direction", "note", "variant", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "thresholds", "threshold", "sparkline", "polarity"]; }
3737
3764
  static get properties() {
3738
- return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, direction: { attribute: "direction" }, note: { attribute: "note" }, variant: { attribute: "variant" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" } };
3765
+ return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, direction: { attribute: "direction" }, note: { attribute: "note" }, variant: { attribute: "variant" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, thresholds: { attribute: "thresholds" }, threshold: { attribute: "threshold" }, sparkline: { attribute: "sparkline" }, polarity: { attribute: "polarity" } };
3739
3766
  }
3740
3767
  render() {
3741
3768
  this.classList.add("c-kpi");
@@ -3765,13 +3792,18 @@ class ContourKpi extends ContourBase {
3765
3792
  const h = this.querySelector(".c-kpi__head");
3766
3793
  if (h) h.remove();
3767
3794
  }
3768
- if (delta) {
3769
- const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
3770
- const d = f.querySelector(".c-delta") || document.createElement("span");
3771
- if (!d.parentNode) f.insertBefore(d, f.firstChild);
3772
- d.className = "c-delta c-delta--" + (this.getAttribute("direction") || "up");
3773
- d.textContent = delta;
3774
- } else {
3795
+ if (delta) {
3796
+ const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
3797
+ const d = f.querySelector(".c-delta") || document.createElement("span");
3798
+ if (!d.parentNode) f.insertBefore(d, f.firstChild);
3799
+ const dir = this.getAttribute("direction") || "up";
3800
+ const polarity = this.getAttribute("polarity") || "neutral";
3801
+ let tone = "neutral";
3802
+ if (polarity === "good") tone = (dir === "up") ? "good" : "bad";
3803
+ else if (polarity === "bad") tone = (dir === "up") ? "bad" : "good";
3804
+ d.className = "c-delta c-delta--" + dir + " c-delta--" + tone;
3805
+ d.textContent = delta;
3806
+ } else {
3775
3807
  const d = this.querySelector(".c-kpi__foot .c-delta");
3776
3808
  if (d) d.remove();
3777
3809
  }
@@ -3796,6 +3828,30 @@ class ContourKpi extends ContourBase {
3796
3828
  if (u) u.remove();
3797
3829
  }
3798
3830
  }
3831
+ // threshold badge
3832
+ const threshold = this.getAttribute("threshold") || this.getAttribute("thresholds");
3833
+ if (threshold) {
3834
+ const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
3835
+ let badge = f.querySelector(".c-kpi__threshold-badge");
3836
+ if (!badge) { badge = document.createElement("span"); badge.className = "c-kpi__threshold-badge"; f.appendChild(badge); }
3837
+ badge.textContent = threshold;
3838
+ badge.setAttribute("part", "threshold-badge");
3839
+ } else {
3840
+ const b = this.querySelector(".c-kpi__threshold-badge");
3841
+ if (b) b.remove();
3842
+ }
3843
+ // remove orphaned foot container when no children remain
3844
+ const foot = this.querySelector(".c-kpi__foot");
3845
+ if (foot && !foot.querySelector(".c-delta, .c-kpi__note, .c-kpi__threshold-badge")) foot.remove();
3846
+ // sparkline canvas
3847
+ const spark = this.getAttribute("sparkline");
3848
+ if (spark) {
3849
+ let canvas = this.querySelector(".c-kpi__sparkline-canvas");
3850
+ if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-kpi__sparkline-canvas"; canvas.setAttribute("part", "sparkline-canvas"); this.appendChild(canvas); }
3851
+ } else {
3852
+ const c = this.querySelector(".c-kpi__sparkline-canvas");
3853
+ if (c) c.remove();
3854
+ }
3799
3855
  if (!value && !label) {
3800
3856
  renderEmpty(this, "kpi");
3801
3857
  }
@@ -4639,24 +4695,32 @@ const series = this.getAttribute("series");
4639
4695
  }
4640
4696
  define("contour-chart", ContourChart);
4641
4697
  class ContourComparison extends ContourBase {
4642
- static get observed() { return ["divider", "value"]; }
4643
- static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" } }; }
4698
+ static get observed() { return ["divider", "value", "before", "after"]; }
4699
+ static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
4644
4700
  render() {
4645
4701
  this.classList.add("c-comparison");
4646
- this.style.blockSize = "12rem";
4702
+ if (!this.style.blockSize) this.style.blockSize = "12rem";
4647
4703
  this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
4648
4704
  // Ensure two panes exist.
4705
+ const beforeLabel = this.getAttribute("before") || "Before";
4706
+ const afterLabel = this.getAttribute("after") || "After";
4649
4707
  if (!this.querySelector(".c-comparison__pane--before")) {
4650
4708
  const p = document.createElement("div");
4651
4709
  p.className = "c-comparison__pane c-comparison__pane--before";
4652
- p.textContent = "Before";
4710
+ p.textContent = beforeLabel;
4653
4711
  this.appendChild(p);
4712
+ } else {
4713
+ const p = this.querySelector(".c-comparison__pane--before");
4714
+ if (p) p.textContent = beforeLabel;
4654
4715
  }
4655
4716
  if (!this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)")) {
4656
4717
  const p = document.createElement("div");
4657
4718
  p.className = "c-comparison__pane";
4658
- p.textContent = "After";
4719
+ p.textContent = afterLabel;
4659
4720
  this.appendChild(p);
4721
+ } else {
4722
+ const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
4723
+ if (p) p.textContent = afterLabel;
4660
4724
  }
4661
4725
  const divider = this.getAttribute("divider");
4662
4726
  if (divider !== null) {
@@ -4930,6 +4994,517 @@ class ContourStat extends ContourBase {
4930
4994
  }
4931
4995
  }
4932
4996
  define("contour-stat", ContourStat);
4997
+ class ContourGauge extends ContourBase {
4998
+ static get observed() { return ["value", "min", "max", "heading", "thresholds", "format", "locale", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "no-data-message", "show-header", "description"]; }
4999
+ static get properties() { return { value: { attribute: "value" }, min: { attribute: "min" }, max: { attribute: "max" }, heading: { attribute: "heading" }, thresholds: { attribute: "thresholds" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" }, src: { attribute: "src" }, brownout: { attribute: "brownout" } }; }
5000
+ render() {
5001
+ this.classList.add("c-gauge");
5002
+ wireStates(this);
5003
+ loadRemote(this, ["value"]);
5004
+ if (renderStates(this, "gauge")) return;
5005
+ const rawValue = this.getAttribute("value");
5006
+ const num = parseFloat(rawValue);
5007
+ const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
5008
+ const min = parseFloat(this.getAttribute("min") || "0");
5009
+ const max = parseFloat(this.getAttribute("max") || "100");
5010
+ const heading = this.getAttribute("heading");
5011
+ const showHeader = this.getAttribute("show-header") !== "false";
5012
+ const description = this.getAttribute("description");
5013
+ const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
5014
+ const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
5015
+ // empty state
5016
+ if (!hasValue) {
5017
+ if (heading && showHeader) {
5018
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
5019
+ t.textContent = heading;
5020
+ }
5021
+ const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
5022
+ empty.textContent = noDataMessage;
5023
+ // remove dial/value/band if present
5024
+ [".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
5025
+ return;
5026
+ }
5027
+ // heading
5028
+ if (heading && showHeader) {
5029
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
5030
+ t.textContent = heading;
5031
+ } else {
5032
+ const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
5033
+ }
5034
+ // thresholds
5035
+ let thresholds = [];
5036
+ const tAttr = this.getAttribute("thresholds");
5037
+ if (tAttr) { try { thresholds = JSON.parse(tAttr); } catch (e) { thresholds = []; } }
5038
+ // band determination
5039
+ let band = null;
5040
+ if (thresholds && thresholds.length) {
5041
+ // thresholds sorted ascending by value
5042
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
5043
+ for (let i = sorted.length - 1; i >= 0; i--) {
5044
+ if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
5045
+ }
5046
+ }
5047
+ // dial (unless brownout >= 3)
5048
+ const shedDial = brownoutLevel >= 3;
5049
+ let dial = this.querySelector(".c-gauge__dial");
5050
+ if (shedDial) {
5051
+ if (dial) dial.remove();
5052
+ } else {
5053
+ if (!dial) {
5054
+ dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5055
+ dial.setAttribute("class", "c-gauge__dial");
5056
+ dial.setAttribute("part", "dial");
5057
+ dial.setAttribute("aria-hidden", "true");
5058
+ dial.setAttribute("viewBox", "0 0 100 100");
5059
+ this.appendChild(dial);
5060
+ }
5061
+ // rebuild dial content
5062
+ dial.innerHTML = "";
5063
+ // track arc (semicircle)
5064
+ const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
5065
+ track.setAttribute("class", "c-gauge__track");
5066
+ track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
5067
+ dial.appendChild(track);
5068
+ // zones: each threshold defines a band from its value to the next
5069
+ // threshold's value (or max), drawn as an arc along the track so the
5070
+ // bands no longer stack on top of one another.
5071
+ if (thresholds && thresholds.length) {
5072
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
5073
+ const toPoint = (v) => {
5074
+ const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
5075
+ return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
5076
+ };
5077
+ for (let i = 0; i < sorted.length; i++) {
5078
+ const v1 = sorted[i].value || 0;
5079
+ const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
5080
+ const p1 = toPoint(v1);
5081
+ const p2 = toPoint(v2);
5082
+ const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
5083
+ z.setAttribute("class", "c-gauge__zone");
5084
+ z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
5085
+ z.setAttribute("d", "M " + p1.x.toFixed(2) + " " + p1.y.toFixed(2) + " A 40 40 0 0 1 " + p2.x.toFixed(2) + " " + p2.y.toFixed(2));
5086
+ dial.appendChild(z);
5087
+ }
5088
+ }
5089
+ // needle
5090
+ const angle = ((num - min) / (max - min || 1)) * 180 - 90;
5091
+ const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
5092
+ needle.setAttribute("class", "c-gauge__needle needle");
5093
+ needle.setAttribute("x1", "50"); needle.setAttribute("y1", "50");
5094
+ needle.setAttribute("x2", String(50 + 35 * Math.cos(angle * Math.PI / 180)));
5095
+ needle.setAttribute("y2", String(50 + 35 * Math.sin(angle * Math.PI / 180)));
5096
+ dial.appendChild(needle);
5097
+ const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5098
+ hub.setAttribute("class", "c-gauge__hub hub");
5099
+ hub.setAttribute("cx", "50"); hub.setAttribute("cy", "50"); hub.setAttribute("r", "4");
5100
+ dial.appendChild(hub);
5101
+ }
5102
+ // value element (meter)
5103
+ const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
5104
+ valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
5105
+ valueEl.setAttribute("role", "meter");
5106
+ valueEl.setAttribute("aria-valuenow", String(num));
5107
+ valueEl.setAttribute("aria-valuemin", String(min));
5108
+ valueEl.setAttribute("aria-valuemax", String(max));
5109
+ if (heading) {
5110
+ // labelledby
5111
+ if (!valueEl.id) valueEl.id = contourId("gauge-value");
5112
+ }
5113
+ if (band) {
5114
+ valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
5115
+ } else {
5116
+ valueEl.setAttribute("aria-valuetext", String(num));
5117
+ }
5118
+ // aria-labelledby / aria-label
5119
+ const titleEl = this.querySelector(".c-gauge__title");
5120
+ if (titleEl) {
5121
+ if (!titleEl.id) titleEl.id = contourId("gauge-title");
5122
+ valueEl.setAttribute("aria-labelledby", titleEl.id);
5123
+ valueEl.removeAttribute("aria-label");
5124
+ } else {
5125
+ valueEl.removeAttribute("aria-labelledby");
5126
+ if (heading) valueEl.setAttribute("aria-label", heading);
5127
+ }
5128
+ // band word
5129
+ const bandEl = this.querySelector(".c-gauge__band");
5130
+ if (band) {
5131
+ const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
5132
+ b.textContent = band.label || (">= " + band.value);
5133
+ } else {
5134
+ if (bandEl) bandEl.remove();
5135
+ }
5136
+ // description
5137
+ if (description) {
5138
+ let d = this.querySelector(".c-gauge__desc");
5139
+ if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
5140
+ d.textContent = description;
5141
+ }
5142
+ }
5143
+ enhance() {}
5144
+ }
5145
+ define("contour-gauge", ContourGauge);
5146
+ class ContourAxis extends ContourBase {
5147
+ static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5148
+ static get properties() { return { orientation: { attribute: "orientation" }, values: { attribute: "values" }, ticks: { attribute: "ticks" }, format: { attribute: "format" }, locale: { attribute: "locale" }, padding: { attribute: "padding" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
5149
+ render() {
5150
+ this.classList.add("c-axis");
5151
+ const orientation = this.getAttribute("orientation") || "horizontal";
5152
+ this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
5153
+ this.classList.toggle("c-axis--vertical", orientation === "vertical");
5154
+ if (orientation === "horizontal") this.setAttribute("part", "axis-x");
5155
+ else this.setAttribute("part", "axis-y");
5156
+ wireStates(this);
5157
+ loadRemote(this, ["values"]);
5158
+ if (renderStates(this, "axis")) return;
5159
+ // parse values
5160
+ let values = [];
5161
+ const vAttr = this.getAttribute("values");
5162
+ if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
5163
+ const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
5164
+ // Slotted content support: authored .c-axis__tick children take
5165
+ // precedence over the JSON `values` attribute.
5166
+ const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
5167
+ if (authoredTicks.length) {
5168
+ // keep authored ticks, just ensure labels are formatted
5169
+ authoredTicks.forEach((tick) => {
5170
+ const label = tick.querySelector(".c-axis__label");
5171
+ if (label && !label.textContent) label.textContent = tick.textContent;
5172
+ });
5173
+ } else {
5174
+ // clear
5175
+ Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
5176
+ const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
5177
+ list.forEach((v) => {
5178
+ const tick = document.createElement("span");
5179
+ tick.className = "c-axis__tick";
5180
+ const label = document.createElement("span");
5181
+ label.className = "c-axis__label";
5182
+ label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
5183
+ tick.appendChild(label);
5184
+ this.appendChild(tick);
5185
+ });
5186
+ }
5187
+ }
5188
+ enhance() {}
5189
+ }
5190
+ define("contour-axis", ContourAxis);
5191
+ class ContourBrush extends ContourBase {
5192
+ static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5193
+ static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
5194
+ render() {
5195
+ this.classList.add("c-brush");
5196
+ wireStates(this);
5197
+ loadRemote(this, []);
5198
+ if (renderStates(this, "brush")) return;
5199
+ let sel = this.querySelector(".c-brush__selection");
5200
+ if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
5201
+ const start = parseFloat(this.getAttribute("start") || "0");
5202
+ const end = parseFloat(this.getAttribute("end") || "100");
5203
+ const min = parseFloat(this.getAttribute("min") || "0");
5204
+ const max = parseFloat(this.getAttribute("max") || "100");
5205
+ const range = max - min || 1;
5206
+ const left = ((start - min) / range) * 100;
5207
+ const width = ((end - start) / range) * 100;
5208
+ sel.style.insetInlineStart = left + "%";
5209
+ sel.style.inlineSize = width + "%";
5210
+ // handles
5211
+ ["start","end"].forEach((h) => {
5212
+ let handle = this.querySelector(".c-brush__handle--" + h);
5213
+ if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
5214
+ const val = h === "start" ? start : end;
5215
+ handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
5216
+ });
5217
+ }
5218
+ enhance() {
5219
+ if (this._wiredBrush) return;
5220
+ this._wiredBrush = true;
5221
+ this.addEventListener("pointerdown", (e) => {
5222
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
5223
+ });
5224
+ this.addEventListener("pointerup", (e) => {
5225
+ this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
5226
+ });
5227
+ }
5228
+ }
5229
+ define("contour-brush", ContourBrush);
5230
+ class ContourStackedBar extends ContourBase {
5231
+ static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
5232
+ static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
5233
+ render() {
5234
+ this.classList.add("c-stacked-bar");
5235
+ wireStates(this);
5236
+ loadRemote(this, ["segments", "values"]);
5237
+ if (renderStates(this, "stacked-bar")) return;
5238
+ Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
5239
+ // Slotted content support: authored .c-stacked-bar__segment children take
5240
+ // precedence over the JSON `segments` attribute.
5241
+ const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
5242
+ let segments = [];
5243
+ if (authoredSegments.length) {
5244
+ segments = authoredSegments.map((el) => ({
5245
+ label: el.getAttribute("title") || el.textContent || "",
5246
+ value: parseFloat(el.style.inlineSize) || 0,
5247
+ color: el.style.background || undefined,
5248
+ }));
5249
+ authoredSegments.forEach((el) => el.remove());
5250
+ } else {
5251
+ const sAttr = this.getAttribute("segments");
5252
+ if (sAttr) { try { segments = JSON.parse(sAttr); } catch (e) { segments = []; } }
5253
+ }
5254
+ const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
5255
+ const total = values.reduce((a, b) => a + b, 0) || 1;
5256
+ const normalize = this.hasAttribute("normalize");
5257
+ const denom = normalize ? total : (parseFloat(this.getAttribute("max") || String(total)) || total);
5258
+ segments.forEach((seg, i) => {
5259
+ const v = values[i];
5260
+ const el = document.createElement("div");
5261
+ el.className = "c-stacked-bar__segment";
5262
+ el.style.inlineSize = ((v / denom) * 100) + "%";
5263
+ el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
5264
+ el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
5265
+ this.appendChild(el);
5266
+ });
5267
+ if (!segments.length) renderEmpty(this, "stacked-bar");
5268
+ }
5269
+ enhance() {}
5270
+ }
5271
+ define("contour-stacked-bar", ContourStackedBar);
5272
+ class ContourCategory extends ContourBase {
5273
+ static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
5274
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
5275
+ render() {
5276
+ this.classList.add("c-category");
5277
+ this.setAttribute("role", "listbox");
5278
+ wireStates(this);
5279
+ loadRemote(this, ["items"]);
5280
+ if (renderStates(this, "category")) return;
5281
+ Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
5282
+ // Slotted content support: authored .c-category__item children take
5283
+ // precedence over the JSON `items` attribute.
5284
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
5285
+ let items = [];
5286
+ if (authoredItems.length) {
5287
+ authoredItems.forEach((el) => {
5288
+ const lbl = el.querySelector(".c-category__label");
5289
+ items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
5290
+ });
5291
+ authoredItems.forEach((el) => el.remove());
5292
+ } else {
5293
+ const iAttr = this.getAttribute("items");
5294
+ if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
5295
+ }
5296
+ const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
5297
+ items.forEach((it, idx) => {
5298
+ const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
5299
+ const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
5300
+ const item = document.createElement("div");
5301
+ item.className = "c-category__item";
5302
+ item.setAttribute("role", "option");
5303
+ item.setAttribute("aria-selected", "false");
5304
+ const lbl = document.createElement("span");
5305
+ lbl.className = "c-category__label";
5306
+ lbl.textContent = label;
5307
+ const barWrap = document.createElement("div");
5308
+ barWrap.style.flex = "1";
5309
+ const bar = document.createElement("div");
5310
+ bar.className = "c-category__bar";
5311
+ bar.style.inlineSize = ((value / max) * 100) + "%";
5312
+ barWrap.appendChild(bar);
5313
+ const val = document.createElement("span");
5314
+ val.className = "c-category__value";
5315
+ val.textContent = String(value);
5316
+ item.appendChild(lbl);
5317
+ item.appendChild(barWrap);
5318
+ item.appendChild(val);
5319
+ this.appendChild(item);
5320
+ });
5321
+ if (!items.length) renderEmpty(this, "category");
5322
+ }
5323
+ enhance() {}
5324
+ }
5325
+ define("contour-category", ContourCategory);
5326
+ class ContourDonut extends ContourBase {
5327
+ static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
5328
+ static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
5329
+ render() {
5330
+ this.classList.add("c-donut");
5331
+ wireStates(this);
5332
+ loadRemote(this, ["items", "values"]);
5333
+ if (renderStates(this, "donut")) return;
5334
+ Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
5335
+ // Slotted content support: authored .c-donut__item children take precedence
5336
+ // over the JSON `items` attribute, so consumers can compose legend rows
5337
+ // by hand instead of serialising them into an attribute.
5338
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
5339
+ let items = [];
5340
+ if (authoredItems.length) {
5341
+ authoredItems.forEach((el) => {
5342
+ const sw = el.querySelector(".c-donut__swatch");
5343
+ const lbl = el.querySelector("span:last-child");
5344
+ const text = lbl ? lbl.textContent : el.textContent;
5345
+ const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
5346
+ items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? sw.style.background : undefined });
5347
+ });
5348
+ // remove authored items from DOM (they will be regenerated below)
5349
+ authoredItems.forEach((el) => el.remove());
5350
+ } else {
5351
+ const iAttr = this.getAttribute("items");
5352
+ if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
5353
+ }
5354
+ const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
5355
+ const total = values.reduce((a, b) => a + b, 0) || 1;
5356
+ const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
5357
+ const shedRing = brownoutLevel >= 3;
5358
+ if (!shedRing) {
5359
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5360
+ svg.setAttribute("class", "c-donut__ring");
5361
+ svg.setAttribute("viewBox", "0 0 32 32");
5362
+ let offset = 0;
5363
+ items.forEach((it, i) => {
5364
+ const v = values[i];
5365
+ const pct = v / total;
5366
+ const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5367
+ circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
5368
+ circle.setAttribute("fill", "none");
5369
+ circle.setAttribute("stroke", (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
5370
+ circle.setAttribute("stroke-width", "6");
5371
+ const circ = 2 * Math.PI * 12;
5372
+ circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
5373
+ circle.setAttribute("stroke-dashoffset", String(-offset * circ));
5374
+ circle.setAttribute("transform", "rotate(-90 16 16)");
5375
+ svg.appendChild(circle);
5376
+ offset += pct;
5377
+ });
5378
+ // center hole
5379
+ const hole = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5380
+ hole.setAttribute("cx", "16"); hole.setAttribute("cy", "16"); hole.setAttribute("r", "9");
5381
+ hole.setAttribute("fill", "var(--color-surface-0)");
5382
+ svg.appendChild(hole);
5383
+ this.appendChild(svg);
5384
+ }
5385
+ const center = document.createElement("div");
5386
+ center.className = "c-donut__center";
5387
+ center.textContent = this.getAttribute("value") || String(total);
5388
+ this.appendChild(center);
5389
+ // text list
5390
+ const list = document.createElement("div");
5391
+ list.className = "c-donut__list";
5392
+ items.forEach((it, i) => {
5393
+ const row = document.createElement("div");
5394
+ row.className = "c-donut__item";
5395
+ const sw = document.createElement("span");
5396
+ sw.className = "c-donut__swatch";
5397
+ sw.style.background = (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")";
5398
+ row.appendChild(sw);
5399
+ const lbl = document.createElement("span");
5400
+ lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
5401
+ row.appendChild(lbl);
5402
+ list.appendChild(row);
5403
+ });
5404
+ this.appendChild(list);
5405
+ if (!items.length) renderEmpty(this, "donut");
5406
+ }
5407
+ enhance() {}
5408
+ }
5409
+ define("contour-donut", ContourDonut);
5410
+ class ContourTimeSeries extends ContourBase {
5411
+ static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
5412
+ static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
5413
+ render() {
5414
+ this.classList.add("c-time-series");
5415
+ wireStates(this);
5416
+ loadRemote(this, ["values", "points"]);
5417
+ if (renderStates(this, "time-series")) return;
5418
+ Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
5419
+ let values = [];
5420
+ const vAttr = this.getAttribute("values");
5421
+ if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
5422
+ const max = Math.max(...values, 1);
5423
+ const plot = document.createElement("div");
5424
+ plot.className = "c-time-series__plot";
5425
+ plot.setAttribute("part", "plot");
5426
+ values.forEach((v) => {
5427
+ const bar = document.createElement("div");
5428
+ bar.className = "c-time-series__bar";
5429
+ bar.style.blockSize = ((v / max) * 100) + "%";
5430
+ bar.setAttribute("title", String(v));
5431
+ plot.appendChild(bar);
5432
+ });
5433
+ this.appendChild(plot);
5434
+ if (!values.length) renderEmpty(this, "time-series");
5435
+ }
5436
+ enhance() {}
5437
+ }
5438
+ define("contour-time-series", ContourTimeSeries);
5439
+ class ContourPivot extends ContourBase {
5440
+ static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5441
+ static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
5442
+ render() {
5443
+ this.classList.add("c-pivot");
5444
+ wireStates(this);
5445
+ loadRemote(this, ["data"]);
5446
+ if (renderStates(this, "pivot")) return;
5447
+ Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
5448
+ let data = [];
5449
+ const dAttr = this.getAttribute("data");
5450
+ if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
5451
+ const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
5452
+ const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
5453
+ const table = document.createElement("table");
5454
+ const thead = document.createElement("thead");
5455
+ const hr = document.createElement("tr");
5456
+ const corner = document.createElement("th");
5457
+ corner.textContent = "";
5458
+ hr.appendChild(corner);
5459
+ cols.forEach((c) => { const th = document.createElement("th"); th.textContent = c.trim(); hr.appendChild(th); });
5460
+ thead.appendChild(hr);
5461
+ table.appendChild(thead);
5462
+ const tbody = document.createElement("tbody");
5463
+ rows.forEach((r) => {
5464
+ const tr = document.createElement("tr");
5465
+ const th = document.createElement("th");
5466
+ th.textContent = r.trim();
5467
+ tr.appendChild(th);
5468
+ cols.forEach((c) => {
5469
+ const td = document.createElement("td");
5470
+ const cell = data.find((d) => d.row === r.trim() && d.col === c.trim());
5471
+ td.textContent = cell ? String(cell.value) : "";
5472
+ tr.appendChild(td);
5473
+ });
5474
+ tbody.appendChild(tr);
5475
+ });
5476
+ table.appendChild(tbody);
5477
+ this.appendChild(table);
5478
+ if (!data.length && !rows.length) renderEmpty(this, "pivot");
5479
+ }
5480
+ enhance() {}
5481
+ }
5482
+ define("contour-pivot", ContourPivot);
5483
+ class ContourWidgetState extends ContourBase {
5484
+ static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5485
+ static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
5486
+ render() {
5487
+ this.classList.add("c-widget-state");
5488
+ wireStates(this);
5489
+ loadRemote(this, []);
5490
+ if (renderStates(this, "widget-state")) return;
5491
+ // if no state, render slotted content (already in DOM)
5492
+ }
5493
+ enhance() {}
5494
+ }
5495
+ define("contour-widget-state", ContourWidgetState);
5496
+ class ContourBrownout extends ContourBase {
5497
+ static get observed() { return ["level"]; }
5498
+ static get properties() { return { level: { attribute: "level" } }; }
5499
+ render() {
5500
+ this.classList.add("c-brownout");
5501
+ const level = this.getAttribute("level") || "0";
5502
+ this.dataset.level = level;
5503
+ this.setAttribute("data-level", level);
5504
+ }
5505
+ enhance() {}
5506
+ }
5507
+ define("contour-brownout", ContourBrownout);
4933
5508
  class ContourInstrument extends ContourBase {
4934
5509
  static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
4935
5510
  static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
@@ -4964,21 +5539,31 @@ class ContourInstrument extends ContourBase {
4964
5539
  }
4965
5540
  define("contour-instrument", ContourInstrument);
4966
5541
  class ContourBivariate extends ContourBase {
4967
- static get observed() { return ["size", "axis-x", "axis-y"]; }
4968
- static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" } }; }
5542
+ static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
5543
+ static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
4969
5544
  render() {
4970
5545
  this.classList.add("c-bivariate");
4971
5546
  const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
4972
5547
  const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
4973
5548
  matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
5549
+ matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
4974
5550
  // Slot composition: authored cells win over the generated grid.
4975
5551
  const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate__cell"));
4976
5552
  if (!authored.length) {
4977
5553
  matrix.innerHTML = "";
4978
- for (let i = 0; i < size * size; i++) {
4979
- const cell = document.createElement("div");
4980
- cell.className = "c-bivariate__cell";
4981
- matrix.appendChild(cell);
5554
+ let colors = [];
5555
+ const cAttr = this.getAttribute("colors");
5556
+ if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
5557
+ for (let r = 0; r < size; r++) {
5558
+ for (let c = 0; c < size; c++) {
5559
+ const cell = document.createElement("div");
5560
+ cell.className = "c-bivariate__cell";
5561
+ // Palette runs from bottom-left (low/low) to top-right (high/high):
5562
+ // reverse the row order so the first palette row sits at the bottom.
5563
+ const srcIndex = (size - 1 - r) * size + c;
5564
+ if (colors[srcIndex]) cell.style.background = colors[srcIndex];
5565
+ matrix.appendChild(cell);
5566
+ }
4982
5567
  }
4983
5568
  }
4984
5569
  const axisX = this.getAttribute("axis-x");
@@ -5000,6 +5585,49 @@ class ContourBivariate extends ContourBase {
5000
5585
  }
5001
5586
  }
5002
5587
  define("contour-bivariate", ContourBivariate);
5588
+ class ContourBivariateLegend extends ContourBase {
5589
+ static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
5590
+ static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
5591
+ render() {
5592
+ this.classList.add("c-bivariate-legend");
5593
+ const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
5594
+ const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
5595
+ matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
5596
+ // Slotted content support: authored cells win over the generated grid.
5597
+ const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
5598
+ if (!authored.length) {
5599
+ matrix.innerHTML = "";
5600
+ let colors = [];
5601
+ const cAttr = this.getAttribute("colors");
5602
+ if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
5603
+ for (let i = 0; i < size * size; i++) {
5604
+ const cell = document.createElement("div");
5605
+ cell.className = "c-bivariate-legend__cell";
5606
+ if (colors[i]) cell.style.background = colors[i];
5607
+ else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
5608
+ matrix.appendChild(cell);
5609
+ }
5610
+ }
5611
+ const axisX = this.getAttribute("axis-x");
5612
+ const ax = this.querySelector(".c-bivariate-legend__axis--x");
5613
+ if (axisX) {
5614
+ const el = ax || this.ensure(".c-bivariate-legend__axis--x", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--x"; return e; });
5615
+ el.textContent = axisX;
5616
+ } else if (ax) {
5617
+ ax.remove();
5618
+ }
5619
+ const axisY = this.getAttribute("axis-y");
5620
+ const ay = this.querySelector(".c-bivariate-legend__axis--y");
5621
+ if (axisY) {
5622
+ const el = ay || this.ensure(".c-bivariate-legend__axis--y", () => { const e = document.createElement("div"); e.className = "c-bivariate-legend__axis c-bivariate-legend__axis--y"; return e; });
5623
+ el.textContent = axisY;
5624
+ } else if (ay) {
5625
+ ay.remove();
5626
+ }
5627
+ }
5628
+ enhance() {}
5629
+ }
5630
+ define("contour-bivariate-legend", ContourBivariateLegend);
5003
5631
  class ContourSurvey extends ContourBase {
5004
5632
  static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5005
5633
  static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
@@ -5109,7 +5737,7 @@ class ContourMetricsFull extends ContourBase {
5109
5737
  }
5110
5738
  define("contour-metrics", ContourMetricsFull);
5111
5739
  class ContourLegend extends ContourBase {
5112
- static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5740
+ static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "size", "table", "classification", "audit", "continuous", "ends", "caption"]; }
5113
5741
  static get properties() { return { title: { attribute: "title" }, ramp: { attribute: "ramp" }, scale: { attribute: "scale" }, items: { attribute: "items" }, method: { attribute: "method" }, norm: { attribute: "norm" }, selectable: { attribute: "selectable", type: Boolean }, src: { attribute: "src" } }; }
5114
5742
  render() {
5115
5743
  this.classList.add("c-legend");
@@ -5148,9 +5776,38 @@ class ContourLegend extends ContourBase {
5148
5776
  sw.className = "c-legend__swatch";
5149
5777
  if (it && it.color) sw.style.background = it.color;
5150
5778
  item.appendChild(sw);
5151
- const lbl = document.createElement("span");
5152
- lbl.textContent = label;
5153
- item.appendChild(lbl);
5779
+ // geometry glyph
5780
+ const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
5781
+ if (glyphShape) {
5782
+ const g = document.createElement("span");
5783
+ g.className = "c-legend__glyph";
5784
+ g.setAttribute("part", "glyph");
5785
+ g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
5786
+ if (it && it.size != null) g.style.fontSize = (typeof it.size === "number" ? it.size + "px" : String(it.size));
5787
+ item.appendChild(g);
5788
+ }
5789
+ // threshold break marker
5790
+ if (it && it.break != null) {
5791
+ const b = document.createElement("span");
5792
+ b.className = "c-legend__break";
5793
+ b.textContent = String(it.break);
5794
+ item.appendChild(b);
5795
+ }
5796
+ const lbl = document.createElement("span");
5797
+ lbl.textContent = label;
5798
+ item.appendChild(lbl);
5799
+ // caption (source-and-method line)
5800
+ const caption = (typeof it === "object" && it) ? (it.caption || it.note || "") : "";
5801
+ if (caption) {
5802
+ const cap = document.createElement("span");
5803
+ cap.className = "c-legend__caption";
5804
+ cap.textContent = caption;
5805
+ item.appendChild(cap);
5806
+ }
5807
+ // threshold mark: outline on swatches that begin at a threshold
5808
+ if (it && (it.threshold || it.break != null)) {
5809
+ sw.style.outline = "2px solid var(--color-border-strong)";
5810
+ }
5154
5811
  list.appendChild(item);
5155
5812
  });
5156
5813
  } catch (e) { /* keep existing */ }
@@ -5162,7 +5819,79 @@ class ContourLegend extends ContourBase {
5162
5819
  renderEmpty(this, "legend");
5163
5820
  }
5164
5821
  }
5165
- const method = this.getAttribute("method");
5822
+ // audit notice
5823
+ const audit = this.getAttribute("audit");
5824
+ if (audit) {
5825
+ const a = this.ensure(".c-legend__audit", () => { const el = document.createElement("div"); el.className = "c-legend__audit"; return el; });
5826
+ a.textContent = audit;
5827
+ } else {
5828
+ const a = this.querySelector(".c-legend__audit");
5829
+ if (a) a.remove();
5830
+ }
5831
+ // continuous variant: ramp with two ends labelled
5832
+ if (this.hasAttribute("continuous")) {
5833
+ const ends = this.getAttribute("ends");
5834
+ let parsedEnds = null;
5835
+ if (ends) { try { parsedEnds = JSON.parse(ends); } catch (e) { parsedEnds = ends.split(","); } }
5836
+ if (Array.isArray(parsedEnds) && parsedEnds.length >= 2) {
5837
+ const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
5838
+ // labels
5839
+ let left = this.querySelector(".c-legend__ramp-label--start");
5840
+ if (!left) { left = document.createElement("span"); left.className = "c-legend__ramp-label c-legend__ramp-label--start"; r.appendChild(left); }
5841
+ left.textContent = parsedEnds[0];
5842
+ let right = this.querySelector(".c-legend__ramp-label--end");
5843
+ if (!right) { right = document.createElement("span"); right.className = "c-legend__ramp-label c-legend__ramp-label--end"; r.appendChild(right); }
5844
+ right.textContent = parsedEnds[parsedEnds.length - 1];
5845
+ }
5846
+ }
5847
+ // size variant: differently-sized glyphs
5848
+ const sizeAttr = this.getAttribute("size");
5849
+ if (sizeAttr) {
5850
+ const sc = this.ensure(".c-legend__size", () => { const el = document.createElement("div"); el.className = "c-legend__size"; return el; });
5851
+ sc.textContent = sizeAttr;
5852
+ } else {
5853
+ const sc = this.querySelector(".c-legend__size");
5854
+ if (sc) sc.remove();
5855
+ }
5856
+ // classification line
5857
+ const classification = this.getAttribute("classification");
5858
+ if (classification) {
5859
+ const c = this.ensure(".c-legend__classification", () => { const el = document.createElement("div"); el.className = "c-legend__classification"; return el; });
5860
+ c.textContent = classification;
5861
+ } else {
5862
+ const c = this.querySelector(".c-legend__classification");
5863
+ if (c) c.remove();
5864
+ }
5865
+ // data table (collapsible)
5866
+ const tableAttr = this.getAttribute("table");
5867
+ if (tableAttr) {
5868
+ let parsed = null;
5869
+ try { parsed = JSON.parse(tableAttr); } catch (e) { parsed = null; }
5870
+ if (Array.isArray(parsed)) {
5871
+ let det = this.querySelector(".c-legend__table-wrap");
5872
+ if (!det) { det = document.createElement("details"); det.className = "c-legend__table-wrap"; this.appendChild(det); }
5873
+ det.innerHTML = "";
5874
+ const sum = document.createElement("summary"); sum.textContent = "Data table"; det.appendChild(sum);
5875
+ const tbl = document.createElement("table"); tbl.className = "c-legend__table";
5876
+ const tbody = document.createElement("tbody");
5877
+ parsed.forEach((row) => {
5878
+ const tr = document.createElement("tr");
5879
+ const cells = Array.isArray(row) ? row : [row.label ?? row.key ?? "", row.value ?? ""];
5880
+ cells.forEach((cell) => { const td = document.createElement("td"); td.textContent = cell; tr.appendChild(td); });
5881
+ tbody.appendChild(tr);
5882
+ });
5883
+ tbl.appendChild(tbody);
5884
+ det.appendChild(tbl);
5885
+ }
5886
+ } else {
5887
+ const det = this.querySelector(".c-legend__table-wrap");
5888
+ if (det) det.remove();
5889
+ }
5890
+ // size variant on glyphs
5891
+ if (items) {
5892
+ // apply size to glyphs already rendered? handled below via re-render not needed
5893
+ }
5894
+ const method = this.getAttribute("method");
5166
5895
  if (method) {
5167
5896
  const m = this.ensure(".c-legend__method", () => { const el = document.createElement("div"); el.className = "c-legend__method"; return el; });
5168
5897
  m.textContent = method;
@@ -5178,14 +5907,34 @@ class ContourLegend extends ContourBase {
5178
5907
  const n = this.querySelector(".c-legend__norm");
5179
5908
  if (n) n.remove();
5180
5909
  }
5181
- const ramp = this.getAttribute("ramp");
5182
- if (ramp) {
5183
- const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
5184
- r.style.background = ramp;
5185
- } else {
5186
- const r = this.querySelector(".c-legend__ramp");
5187
- if (r) r.remove();
5188
- }
5910
+ const ramp = this.getAttribute("ramp");
5911
+ if (ramp) {
5912
+ const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
5913
+ r.style.background = ramp;
5914
+ // ramp routing: equal-width segments with break labels
5915
+ const breaksAttr = this.getAttribute("breaks");
5916
+ if (breaksAttr) {
5917
+ let breaks = null;
5918
+ try { breaks = JSON.parse(breaksAttr); } catch (e) { breaks = breaksAttr.split(",").map((s) => s.trim()); }
5919
+ if (Array.isArray(breaks)) {
5920
+ // remove old segments
5921
+ Array.from(r.querySelectorAll(".c-legend__ramp-segment")).forEach((n) => n.remove());
5922
+ breaks.forEach((b, i) => {
5923
+ const seg = document.createElement("span");
5924
+ seg.className = "c-legend__ramp-segment";
5925
+ seg.style.flex = "1";
5926
+ const lbl = document.createElement("span");
5927
+ lbl.className = "c-legend__ramp-break";
5928
+ lbl.textContent = String(b);
5929
+ seg.appendChild(lbl);
5930
+ r.appendChild(seg);
5931
+ });
5932
+ }
5933
+ }
5934
+ } else {
5935
+ const r = this.querySelector(".c-legend__ramp");
5936
+ if (r) r.remove();
5937
+ }
5189
5938
  const scale = this.getAttribute("scale");
5190
5939
  if (scale) {
5191
5940
  const sc = this.ensure(".c-legend__scale", () => { const el = document.createElement("div"); el.className = "c-legend__scale"; return el; });
@@ -5198,10 +5947,6 @@ class ContourLegend extends ContourBase {
5198
5947
  enhance() {
5199
5948
  if (this._wiredLegend) return;
5200
5949
  this._wiredLegend = true;
5201
- // Host-delegated (rule 12): the item buttons are rebuilt by every
5202
- // render, so the handler re-queries per click. The gate-visible name is
5203
- // `contour:legend-toggle` — the plan's `contour:legend:toggle` carries a
5204
- // colon inside the name, which the check-wc manifest regex cannot see.
5205
5950
  this.addEventListener("click", (e) => {
5206
5951
  const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
5207
5952
  if (!btn || !this.contains(btn)) return;
@@ -5212,6 +5957,44 @@ class ContourLegend extends ContourBase {
5212
5957
  bubbles: true,
5213
5958
  composed: true,
5214
5959
  }));
5960
+ this.dispatchEvent(new CustomEvent("contour:select", {
5961
+ detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), value: btn.dataset.key || btn.textContent.trim() },
5962
+ bubbles: true,
5963
+ composed: true,
5964
+ }));
5965
+ });
5966
+ // emit style-resolved once on enhance
5967
+ try {
5968
+ let parsed = null;
5969
+ try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
5970
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
5971
+ } catch (e) {}
5972
+ // break-change delegated
5973
+ this.addEventListener("change", (e) => {
5974
+ const t = e.target;
5975
+ if (t && t.classList && t.classList.contains("c-legend__break-input")) {
5976
+ this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
5977
+ }
5978
+ });
5979
+ // keyboard nav (listbox)
5980
+ this.addEventListener("keydown", (e) => {
5981
+ const items = Array.from(this.querySelectorAll(".c-legend__item"));
5982
+ if (!items.length) return;
5983
+ const idx = items.indexOf(document.activeElement);
5984
+ if (e.key === "ArrowDown" || e.key === "ArrowRight") {
5985
+ e.preventDefault();
5986
+ const next = items[(idx + 1) % items.length];
5987
+ if (next) next.focus();
5988
+ } else if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
5989
+ e.preventDefault();
5990
+ const prev = items[(idx - 1 + items.length) % items.length];
5991
+ if (prev) prev.focus();
5992
+ } else if (e.key === "Enter" || e.key === " ") {
5993
+ e.preventDefault();
5994
+ if (document.activeElement && document.activeElement.classList.contains("c-legend__item")) {
5995
+ document.activeElement.click();
5996
+ }
5997
+ }
5215
5998
  });
5216
5999
  }
5217
6000
  }
@@ -5246,6 +6029,12 @@ class ContourMeasure extends ContourBase {
5246
6029
  const r = this.querySelector(".c-measure__readout");
5247
6030
  if (r) r.remove();
5248
6031
  }
6032
+ // unit selector
6033
+ let sel = this.querySelector(".c-measure__unit-select");
6034
+ if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; this.appendChild(sel); }
6035
+ ["m","km","mi","ft"].forEach((u) => {
6036
+ if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
6037
+ });
5249
6038
  if (rPoint) {
5250
6039
  const p = this.ensure(".c-measure__point", () => { const el = document.createElement("span"); el.className = "c-measure__point"; return el; });
5251
6040
  p.textContent = rPoint;
@@ -5325,12 +6114,20 @@ class ContourHeatmap extends ContourBase {
5325
6114
  wireStates(this);
5326
6115
  loadRemote(this, "cells");
5327
6116
  if (renderStates(this, "heatmap")) return;
5328
- Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
5329
- const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
5330
- const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
5331
- this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
5332
- this.style.inlineSize = "16rem";
5333
- if (count > 0) {
6117
+ // Slotted content support: authored .c-heatmap__cell children take
6118
+ // precedence over the generated grid.
6119
+ const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
6120
+ if (authoredCells.length) {
6121
+ const cols = Math.ceil(Math.sqrt(authoredCells.length));
6122
+ this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
6123
+ this.style.inlineSize = "16rem";
6124
+ } else {
6125
+ Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
6126
+ const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
6127
+ const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
6128
+ this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
6129
+ this.style.inlineSize = "16rem";
6130
+ if (count > 0) {
5334
6131
  let values = [];
5335
6132
  try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
5336
6133
  for (let i = 0; i < count; i++) {
@@ -5344,9 +6141,10 @@ class ContourHeatmap extends ContourBase {
5344
6141
  }
5345
6142
  const tip = this.ensure(".c-heatmap__tooltip", () => { const el = document.createElement("div"); el.className = "c-heatmap__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
5346
6143
  tip.setAttribute("hidden", "");
5347
- } else {
6144
+ } else if (!authoredCells.length) {
5348
6145
  renderEmpty(this, "heatmap");
5349
6146
  }
6147
+ }
5350
6148
  if (this.hasAttribute("legend")) {
5351
6149
  const leg = this.ensure(".c-heatmap__legend", () => {
5352
6150
  const el = document.createElement("div");
@@ -6865,72 +7663,130 @@ class ContourField extends ContourBase {
6865
7663
  };
6866
7664
  define("contour-field", ContourField);
6867
7665
  class ContourRange extends ContourBase {
6868
- static get observed() { return ["min", "max", "value", "label"]; }
7666
+ static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label"]; }
6869
7667
  static get formAssociated() { return true; }
6870
7668
  static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" } }; }
6871
- render() {
6872
- this.classList.add("c-range");
6873
- const input = this.ensure("input", () => { const el = document.createElement("input"); el.type = "range"; return el; });
6874
- input.type = "range";
6875
- input.className = "c-range";
6876
- input.min = this.getAttribute("min") || "0";
6877
- input.max = this.getAttribute("max") || "100";
6878
- const attrVal = this.getAttribute("value") || "50";
6879
- if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
6880
- input.value = this._rangeUserValue;
6881
- } else {
6882
- input.value = attrVal;
6883
- this._rangeUserValue = null;
6884
- this._rangeAttrAtDirty = null;
6885
- }
6886
- const label = this.getAttribute("label");
6887
- if (label) input.setAttribute("aria-label", label);
6888
- else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
6889
- // Fill the track to the left of the thumb.
6890
- const updateFill = () => {
6891
- const min = Number(input.min) || 0;
6892
- const max = Number(input.max) || 100;
6893
- const val = Number(input.value) || 0;
6894
- const pct = max > min ? ((val - min) / (max - min)) * 100 : 0;
6895
- input.style.setProperty("--fill", pct + "%");
6896
- };
6897
- updateFill();
6898
- if (!input._fillWired) {
6899
- input._fillWired = true;
6900
- input.addEventListener("input", updateFill);
6901
- }
6902
- }
7669
+ render() {
7670
+ this.classList.add("c-range");
7671
+ const min = this.getAttribute("min") || "0";
7672
+ const max = this.getAttribute("max") || "100";
7673
+ const rangeMode = this.hasAttribute("range") || this.hasAttribute("low") || this.hasAttribute("high");
7674
+ // sparkline canvas
7675
+ const spark = this.getAttribute("sparkline");
7676
+ if (spark) {
7677
+ let canvas = this.querySelector(".c-range__sparkline");
7678
+ if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-range__sparkline"; canvas.setAttribute("part", "sparkline-canvas"); this.insertBefore(canvas, this.firstChild); }
7679
+ } else {
7680
+ const c = this.querySelector(".c-range__sparkline");
7681
+ if (c) c.remove();
7682
+ }
7683
+ if (rangeMode) {
7684
+ // remove single input if present
7685
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
7686
+ // keep generic input? We'll use two named inputs
7687
+ let lowInput = this.querySelector("input.c-range__low");
7688
+ if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; this.appendChild(lowInput); }
7689
+ let highInput = this.querySelector("input.c-range__high");
7690
+ if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; this.appendChild(highInput); }
7691
+ lowInput.min = min; lowInput.max = max;
7692
+ highInput.min = min; highInput.max = max;
7693
+ const lowVal = this.getAttribute("low") || min;
7694
+ const highVal = this.getAttribute("high") || max;
7695
+ if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
7696
+ else { lowInput.value = lowVal; this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
7697
+ if (this._rangeUserHigh !== null && this._rangeAttrHighAtDirty === (this.getAttribute("high") || max)) highInput.value = this._rangeUserHigh;
7698
+ else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
7699
+ const label = this.getAttribute("label");
7700
+ if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
7701
+ } else {
7702
+ // remove dual inputs
7703
+ Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high")).forEach((n) => n.remove());
7704
+ const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; return el; });
7705
+ // ensure class
7706
+ input.className = "c-range";
7707
+ input.type = "range";
7708
+ input.min = min;
7709
+ input.max = max;
7710
+ const attrVal = this.getAttribute("value") || "50";
7711
+ if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
7712
+ input.value = this._rangeUserValue;
7713
+ } else {
7714
+ input.value = attrVal;
7715
+ this._rangeUserValue = null;
7716
+ this._rangeAttrAtDirty = null;
7717
+ }
7718
+ const label = this.getAttribute("label");
7719
+ if (label) input.setAttribute("aria-label", label);
7720
+ else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
7721
+ const updateFill = () => {
7722
+ const mn = Number(input.min) || 0;
7723
+ const mx = Number(input.max) || 100;
7724
+ const val = Number(input.value) || 0;
7725
+ const pct = mx > mn ? ((val - mn) / (mx - mn)) * 100 : 0;
7726
+ input.style.setProperty("--fill", pct + "%");
7727
+ };
7728
+ updateFill();
7729
+ if (!input._fillWired) {
7730
+ input._fillWired = true;
7731
+ input.addEventListener("input", updateFill);
7732
+ }
7733
+ }
7734
+ }
6903
7735
  }
6904
7736
  // patch enhance onto ContourRange
6905
7737
  const _origRangeRender = ContourRange.prototype.render;
6906
- ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
6907
- if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
6908
- return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
6909
- };
6910
- ContourRange.prototype.enhance = function() {
6911
- if (this._wiredRange) return;
6912
- this._wiredRange = true;
6913
- const sync = () => {
6914
- const input = this.querySelector("input");
6915
- if (!input || !this._internals) return;
6916
- this._internals.setFormValue(input.value);
6917
- };
6918
- this.addEventListener("input", (e) => {
6919
- const input = this.querySelector("input");
6920
- if (!input || e.target !== input) return;
6921
- this._rangeUserValue = input.value;
6922
- this._rangeAttrAtDirty = this.getAttribute("value") || "50";
6923
- sync();
6924
- this._emitForm("contour:input");
6925
- });
6926
- this.addEventListener("change", (e) => {
6927
- const input = this.querySelector("input");
6928
- if (!input || e.target !== input) return;
6929
- sync();
6930
- this._emitForm("contour:change");
6931
- });
6932
- sync();
6933
- };
7738
+ ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
7739
+ if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
7740
+ if (name === "low") { this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
7741
+ if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
7742
+ return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
7743
+ };
7744
+ ContourRange.prototype.enhance = function() {
7745
+ if (this._wiredRange) return;
7746
+ this._wiredRange = true;
7747
+ const sync = () => {
7748
+ const low = this.querySelector("input.c-range__low");
7749
+ const high = this.querySelector("input.c-range__high");
7750
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
7751
+ if (this._internals) {
7752
+ if (low && high) this._internals.setFormValue(low.value + "," + high.value);
7753
+ else if (single) this._internals.setFormValue(single.value);
7754
+ }
7755
+ };
7756
+ this.addEventListener("input", (e) => {
7757
+ const low = this.querySelector("input.c-range__low");
7758
+ const high = this.querySelector("input.c-range__high");
7759
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
7760
+ if (low && high && (e.target === low || e.target === high)) {
7761
+ this._rangeUserLow = low.value;
7762
+ this._rangeUserHigh = high.value;
7763
+ this._rangeAttrLowAtDirty = this.getAttribute("low") || (this.getAttribute("min") || "0");
7764
+ this._rangeAttrHighAtDirty = this.getAttribute("high") || (this.getAttribute("max") || "100");
7765
+ sync();
7766
+ this._emitForm("contour:input", { low: Number(low.value), high: Number(high.value) });
7767
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
7768
+ } else if (single && e.target === single) {
7769
+ this._rangeUserValue = single.value;
7770
+ this._rangeAttrAtDirty = this.getAttribute("value") || "50";
7771
+ sync();
7772
+ this._emitForm("contour:input");
7773
+ }
7774
+ });
7775
+ this.addEventListener("change", (e) => {
7776
+ const low = this.querySelector("input.c-range__low");
7777
+ const high = this.querySelector("input.c-range__high");
7778
+ const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
7779
+ if (low && high && (e.target === low || e.target === high)) {
7780
+ sync();
7781
+ this._emitForm("contour:change", { low: Number(low.value), high: Number(high.value) });
7782
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
7783
+ } else if (single && e.target === single) {
7784
+ sync();
7785
+ this._emitForm("contour:change");
7786
+ }
7787
+ });
7788
+ sync();
7789
+ };
6934
7790
  define("contour-range", ContourRange);
6935
7791
  class ContourSwitch extends ContourBase {
6936
7792
  static get observed() { return ["label", "required", "checked"]; }
@@ -7751,7 +8607,7 @@ class ContourResizable extends ContourBase {
7751
8607
  this.appendChild(handle);
7752
8608
  this.appendChild(p2);
7753
8609
  }
7754
- const v = this.getAttribute("value");
8610
+ const v = this._splitValue || this.getAttribute("value");
7755
8611
  if (v) {
7756
8612
  const p1 = this.querySelector(".c-resizable__pane");
7757
8613
  if (p1) p1.style.flex = `0 0 ${v}%`;
@@ -7772,7 +8628,7 @@ class ContourResizable extends ContourBase {
7772
8628
  const frac = span > 0 ? Math.min(0.9, Math.max(0.1, pos / span)) : 0.5;
7773
8629
  const p1 = this.querySelector(".c-resizable__pane");
7774
8630
  if (p1) p1.style.flex = `0 0 ${Math.round(frac * 100)}%`;
7775
- this.setAttribute("value", String(Math.round(frac * 100)));
8631
+ this._splitValue = String(Math.round(frac * 100));
7776
8632
  };
7777
8633
  this.addEventListener("pointerdown", (e) => {
7778
8634
  const handle = this.querySelector(".c-resize-handle");
@@ -7789,6 +8645,7 @@ class ContourResizable extends ContourBase {
7789
8645
  const stopResize = (e) => {
7790
8646
  if (!this._resizing) return;
7791
8647
  this._resizing = false;
8648
+ if (this._splitValue) { this.setAttribute("value", this._splitValue); this._splitValue = null; }
7792
8649
  const handle = this.querySelector(".c-resize-handle");
7793
8650
  if (handle) {
7794
8651
  handle.classList.remove("c-resize-handle--dragging");
@@ -8147,6 +9004,22 @@ class ContourMinimap extends ContourBase {
8147
9004
  if (v) v.remove();
8148
9005
  }
8149
9006
  }
9007
+ enhance() {
9008
+ if (this._wiredMinimap) return;
9009
+ this._wiredMinimap = true;
9010
+ let dragging = false;
9011
+ this.addEventListener("pointerdown", (e) => {
9012
+ const vp = this.querySelector(".c-minimap__viewport");
9013
+ if (!vp || !vp.contains(e.target)) return;
9014
+ dragging = true;
9015
+ try { vp.setPointerCapture(e.pointerId); } catch (err) {}
9016
+ });
9017
+ this.addEventListener("pointermove", (e) => {
9018
+ if (!dragging) return;
9019
+ this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag" }, bubbles: true, composed: true }));
9020
+ });
9021
+ this.addEventListener("pointerup", () => { dragging = false; });
9022
+ }
8150
9023
  }
8151
9024
  define("contour-minimap", ContourMinimap);
8152
9025
  class ContourCoordinate extends ContourBase {
@@ -8162,13 +9035,62 @@ class ContourCoordinate extends ContourBase {
8162
9035
  renderEmpty(this, "coordinate");
8163
9036
  return;
8164
9037
  }
9038
+ const format = this.getAttribute("format") || "decimal";
9039
+ let text = String(value);
9040
+ if (format === "dms") {
9041
+ // simple DMS conversion assuming decimal degrees "lat,lon"
9042
+ const parts = String(value).split(/[,\s]+/).map(Number);
9043
+ if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
9044
+ const toDMS = (d) => {
9045
+ const deg = Math.floor(Math.abs(d));
9046
+ const min = Math.floor((Math.abs(d) - deg) * 60);
9047
+ const sec = (((Math.abs(d) - deg) * 60) - min) * 60;
9048
+ return deg + "°" + min + "'" + sec.toFixed(1) + '"' + (d < 0 ? "S" : "N");
9049
+ };
9050
+ text = toDMS(parts[0]) + " " + toDMS(parts[1]);
9051
+ }
9052
+ } else if (format === "web-mercator") {
9053
+ const parts = String(value).split(/[,\s]+/).map(Number);
9054
+ if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
9055
+ const x = parts[1] * 20037508.34 / 180;
9056
+ const y = Math.log(Math.tan((90 + parts[0]) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180;
9057
+ text = x.toFixed(2) + ", " + y.toFixed(2);
9058
+ }
9059
+ } else {
9060
+ text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
9061
+ }
8165
9062
  const span = this.ensure(".c-coordinate__value", () => { const el = document.createElement("span"); el.className = "c-coordinate__value"; return el; });
8166
- span.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
9063
+ span.textContent = text;
9064
+ // copy button
9065
+ let btn = this.querySelector(".c-coordinate__copy");
9066
+ 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); }
9067
+ btn.onclick = () => {
9068
+ try {
9069
+ if (navigator.clipboard && navigator.clipboard.writeText) {
9070
+ navigator.clipboard.writeText(text).catch(() => { fallbackCopy(text); });
9071
+ } else {
9072
+ fallbackCopy(text);
9073
+ }
9074
+ } catch (e) { fallbackCopy(text); }
9075
+ this.dispatchEvent(new CustomEvent("contour:copy", { detail: { text }, bubbles: true, composed: true }));
9076
+ };
9077
+ function fallbackCopy(t) {
9078
+ try {
9079
+ const ta = document.createElement("textarea");
9080
+ ta.value = t;
9081
+ ta.style.position = "fixed";
9082
+ ta.style.opacity = "0";
9083
+ document.body.appendChild(ta);
9084
+ ta.select();
9085
+ document.execCommand("copy");
9086
+ document.body.removeChild(ta);
9087
+ } catch (e) {}
9088
+ }
8167
9089
  }
8168
9090
  }
8169
9091
  define("contour-coordinate", ContourCoordinate);
8170
9092
  class ContourLayerPanel extends ContourBase {
8171
- static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
9093
+ static get observed() { return ["label", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "allow-rename", "allow-remove", "allow-duplicate", "allow-zoom"]; }
8172
9094
  static get properties() { return { label: { attribute: "label" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
8173
9095
  render() {
8174
9096
  this.classList.add("c-layer-panel");
@@ -8184,34 +9106,62 @@ class ContourLayerPanel extends ContourBase {
8184
9106
  const l = this.querySelector(".c-layer-panel__label");
8185
9107
  if (l) l.remove();
8186
9108
  }
8187
- if (items) {
9109
+ // Slotted content support: authored .c-layer-panel__item children take
9110
+ // precedence over the JSON `items` attribute.
9111
+ const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
9112
+ // Preserve user-toggled visibility across re-renders (B3-09): a src
9113
+ // reload must not re-check a layer the user un-checked.
9114
+ const savedVisibility = new Map();
9115
+ this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
9116
+ const nm = el.querySelector(".c-layer-panel__name");
9117
+ const tg = el.querySelector(".c-layer-panel__toggle");
9118
+ if (nm && tg) {
9119
+ const v = tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked;
9120
+ savedVisibility.set(nm.textContent, v);
9121
+ }
9122
+ });
9123
+ let parsed = null;
9124
+ if (authoredLayerItems.length) {
9125
+ parsed = authoredLayerItems.map((el) => {
9126
+ const nm = el.querySelector(".c-layer-panel__name");
9127
+ const tg = el.querySelector(".c-layer-panel__toggle");
9128
+ const visible = tg ? (tg.hasAttribute("aria-pressed") ? tg.getAttribute("aria-pressed") === "true" : !!tg.checked) : true;
9129
+ const cap = el.querySelector(".c-layer-panel__caption");
9130
+ return { name: nm ? nm.textContent : "", visible, caption: cap ? cap.textContent : (el.dataset.caption || undefined) };
9131
+ });
9132
+ authoredLayerItems.forEach((el) => el.remove());
9133
+ } else if (items) {
8188
9134
  try {
8189
- const parsed = JSON.parse(items);
8190
- // Preserve user-toggled visibility across re-renders (B3-09): a src
8191
- // reload must not re-check a layer the user un-checked.
8192
- const savedVisibility = new Map();
8193
- this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
8194
- const nm = el.querySelector(".c-layer-panel__name");
8195
- const tg = el.querySelector(".c-layer-panel__toggle");
8196
- if (nm && tg) savedVisibility.set(nm.textContent, tg.checked);
8197
- });
9135
+ parsed = JSON.parse(items);
8198
9136
  Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
8199
- parsed.forEach((it) => {
8200
- const name = typeof it === "string" ? it : (it.name || it.label || "");
8201
- const item = document.createElement("div");
8202
- item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
8203
- const toggle = document.createElement("input");
8204
- toggle.type = "checkbox";
8205
- toggle.className = "c-layer-panel__toggle";
8206
- toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
8207
- if (savedVisibility.has(name)) toggle.checked = savedVisibility.get(name);
8208
- else if (typeof it === "object" && it.visible !== false) toggle.checked = true;
9137
+ } catch (e) { /* keep existing */ }
9138
+ }
9139
+ if (parsed) { parsed.forEach((it) => {
9140
+ const name = typeof it === "string" ? it : (it.name || it.label || "");
9141
+ const caption = (typeof it === "object" && it) ? (it.caption || it.subtitle || "") : "";
9142
+ const item = document.createElement("div");
9143
+ item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
9144
+ const toggle = document.createElement("button");
9145
+ toggle.type = "button";
9146
+ toggle.className = "c-layer-panel__toggle";
9147
+ toggle.setAttribute("part", "visibility-toggle");
9148
+ toggle.setAttribute("aria-label", "Toggle " + (name || "layer"));
9149
+ const isVisible = savedVisibility.has(name) ? savedVisibility.get(name) : (typeof it === "object" && it.visible !== false);
9150
+ toggle.setAttribute("aria-pressed", String(!!isVisible));
9151
+ toggle.checked = !!isVisible;
9152
+ toggle.textContent = isVisible ? "●" : "○";
8209
9153
  item.appendChild(toggle);
8210
9154
  const nm = document.createElement("span");
8211
9155
  nm.className = "c-layer-panel__name";
8212
9156
  nm.textContent = name;
8213
9157
  item.appendChild(nm);
8214
- const opacity = document.createElement("input");
9158
+ if (caption) {
9159
+ const cap = document.createElement("span");
9160
+ cap.className = "c-layer-panel__caption";
9161
+ cap.textContent = caption;
9162
+ item.appendChild(cap);
9163
+ }
9164
+ const opacity = document.createElement("input");
8215
9165
  opacity.type = "range";
8216
9166
  opacity.className = "c-layer-panel__opacity";
8217
9167
  opacity.min = "0";
@@ -8219,10 +9169,48 @@ class ContourLayerPanel extends ContourBase {
8219
9169
  opacity.setAttribute("aria-label", "Opacity of " + (name || "layer"));
8220
9170
  opacity.value = (typeof it === "object" && it.opacity != null) ? it.opacity : "100";
8221
9171
  item.appendChild(opacity);
9172
+ // rename input (hidden by default, toggled via button)
9173
+ if (this.getAttribute("allow-rename") !== "false") {
9174
+ const renameBtn = document.createElement("button");
9175
+ renameBtn.type = "button";
9176
+ renameBtn.className = "c-layer-panel__rename";
9177
+ renameBtn.textContent = "Rename";
9178
+ renameBtn.setAttribute("aria-label", "Rename " + (name || "layer"));
9179
+ item.appendChild(renameBtn);
9180
+ }
9181
+ if (this.getAttribute("allow-duplicate") !== "false") {
9182
+ const dupBtn = document.createElement("button");
9183
+ dupBtn.type = "button";
9184
+ dupBtn.className = "c-layer-panel__duplicate";
9185
+ dupBtn.textContent = "Duplicate";
9186
+ dupBtn.setAttribute("aria-label", "Duplicate " + (name || "layer"));
9187
+ item.appendChild(dupBtn);
9188
+ }
9189
+ if (this.getAttribute("allow-zoom") !== "false") {
9190
+ const zoomBtn = document.createElement("button");
9191
+ zoomBtn.type = "button";
9192
+ zoomBtn.className = "c-layer-panel__zoom";
9193
+ zoomBtn.textContent = "Zoom";
9194
+ zoomBtn.setAttribute("aria-label", "Zoom to " + (name || "layer"));
9195
+ item.appendChild(zoomBtn);
9196
+ }
9197
+ if (this.getAttribute("allow-remove") !== "false") {
9198
+ const removeBtn = document.createElement("button");
9199
+ removeBtn.type = "button";
9200
+ removeBtn.className = "c-layer-panel__remove";
9201
+ removeBtn.textContent = "✕";
9202
+ removeBtn.setAttribute("aria-label", "Remove " + (name || "layer"));
9203
+ item.appendChild(removeBtn);
9204
+ }
9205
+ const projSel = document.createElement("select");
9206
+ projSel.className = "c-layer-panel__projection";
9207
+ projSel.setAttribute("aria-label", "Projection of " + (name || "layer"));
9208
+ ["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
9209
+ item.appendChild(projSel);
8222
9210
  this.appendChild(item);
8223
9211
  });
8224
- } catch (e) { /* keep existing */ }
8225
- } else {
9212
+ }
9213
+ if (!parsed && !authoredLayerItems.length && !items) {
8226
9214
  Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
8227
9215
  renderEmpty(this, "layer-panel");
8228
9216
  }
@@ -8232,21 +9220,83 @@ class ContourLayerPanel extends ContourBase {
8232
9220
  this._wiredLayerPanel = true;
8233
9221
  // The panel's two controls (visibility toggle, opacity range) are rebuilt
8234
9222
  // on every render, so both keep the host-delegated pattern (rule 12).
8235
- this.addEventListener("change", (e) => {
8236
- const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
8237
- if (!item || !this.contains(item)) return;
8238
- const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
8239
- if (e.target.classList.contains("c-layer-panel__toggle")) {
8240
- this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: e.target.checked } }));
8241
- } else if (e.target.classList.contains("c-layer-panel__opacity")) {
8242
- this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
8243
- }
8244
- });
8245
- }
9223
+ this.addEventListener("change", (e) => {
9224
+ const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
9225
+ if (!item || !this.contains(item)) return;
9226
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
9227
+ if (e.target.classList.contains("c-layer-panel__toggle")) {
9228
+ const now = (typeof e.target.checked === "boolean") ? e.target.checked : (e.target.getAttribute("aria-pressed") !== "true");
9229
+ e.target.checked = now;
9230
+ e.target.setAttribute("aria-pressed", String(now));
9231
+ e.target.textContent = now ? "●" : "○";
9232
+ this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
9233
+ } else if (e.target.classList.contains("c-layer-panel__opacity")) {
9234
+ this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
9235
+ } else if (e.target.classList.contains("c-layer-panel__projection")) {
9236
+ this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
9237
+ }
9238
+ });
9239
+ this.addEventListener("click", (e) => {
9240
+ const btn = e.target && e.target.closest ? e.target.closest("button") : null;
9241
+ if (!btn || !this.contains(btn)) return;
9242
+ const item = btn.closest(".c-layer-panel__item");
9243
+ if (btn.classList.contains("c-layer-panel__toggle")) {
9244
+ if (!item) return;
9245
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
9246
+ const now = btn.getAttribute("aria-pressed") !== "true";
9247
+ btn.setAttribute("aria-pressed", String(now));
9248
+ btn.checked = now;
9249
+ btn.textContent = now ? "●" : "○";
9250
+ this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: now } }));
9251
+ return;
9252
+ }
9253
+ if (!item) return;
9254
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
9255
+ if (btn.classList.contains("c-layer-panel__rename")) {
9256
+ const newName = prompt("Rename layer", name);
9257
+ const trimmed = newName ? newName.trim() : "";
9258
+ if (trimmed && trimmed !== name) {
9259
+ const nm = item.querySelector(".c-layer-panel__name");
9260
+ if (nm) nm.textContent = trimmed;
9261
+ this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
9262
+ }
9263
+ } else if (btn.classList.contains("c-layer-panel__duplicate")) {
9264
+ this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
9265
+ } else if (btn.classList.contains("c-layer-panel__zoom")) {
9266
+ this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { name } }));
9267
+ } else if (btn.classList.contains("c-layer-panel__remove")) {
9268
+ this.dispatchEvent(new CustomEvent("contour:layer-remove", { bubbles: true, composed: true, detail: { name } }));
9269
+ }
9270
+ });
9271
+ this.addEventListener("keydown", (e) => {
9272
+ if (e.target && e.target.classList && e.target.classList.contains("c-layer-panel__toggle") && (e.key === "Enter" || e.key === " ")) {
9273
+ e.preventDefault();
9274
+ e.target.click();
9275
+ return;
9276
+ }
9277
+ const item = e.target && e.target.closest ? e.target.closest(".c-layer-panel__item") : null;
9278
+ if (!item || !this.contains(item)) return;
9279
+ if (!(e.altKey) || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
9280
+ e.preventDefault();
9281
+ const items = Array.from(this.querySelectorAll(".c-layer-panel__item"));
9282
+ const idx = items.indexOf(item);
9283
+ if (idx < 0) return;
9284
+ const dir = e.key === "ArrowUp" ? -1 : 1;
9285
+ const newIdx = idx + dir;
9286
+ if (newIdx < 0 || newIdx >= items.length) return;
9287
+ item.classList.add("c-layer-panel__item--dragging");
9288
+ if (dir < 0) this.insertBefore(item, items[newIdx]);
9289
+ else this.insertBefore(items[newIdx], item);
9290
+ item.focus();
9291
+ setTimeout(() => item.classList.remove("c-layer-panel__item--dragging"), 200);
9292
+ const layerIds = Array.from(this.querySelectorAll(".c-layer-panel__item")).map((el) => el.querySelector(".c-layer-panel__name")?.textContent || "");
9293
+ this.dispatchEvent(new CustomEvent("contour:layer-reorder", { bubbles: true, composed: true, detail: { layerIds } }));
9294
+ });
9295
+ }
8246
9296
  }
8247
9297
  define("contour-layer-panel", ContourLayerPanel);
8248
9298
  class ContourTimeSlider extends ContourBase {
8249
- static get observed() { return ["label", "value"]; }
9299
+ static get observed() { return ["label", "value", "loop", "speed"]; }
8250
9300
  static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
8251
9301
  render() {
8252
9302
  this.classList.add("c-time-slider");
@@ -8287,10 +9337,15 @@ class ContourTimeSlider extends ContourBase {
8287
9337
  const track = this.querySelector(".c-time-slider__track");
8288
9338
  if (!track) { stop(); return; }
8289
9339
  const max = Number(track.max) || 100;
8290
- const next = Math.min(max, (Number(track.value) || 0) + 1);
9340
+ const loop = this.hasAttribute("loop");
9341
+ let next = (Number(track.value) || 0) + 1;
9342
+ if (next > max) {
9343
+ if (loop) next = 0;
9344
+ else next = max;
9345
+ }
8291
9346
  track.value = String(next);
8292
9347
  this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: String(next) }, bubbles: true, composed: true }));
8293
- if (next >= max) {
9348
+ if (!loop && next >= max) {
8294
9349
  stop();
8295
9350
  const btn = this.querySelector(".c-time-slider__play");
8296
9351
  if (btn) {
@@ -8311,13 +9366,19 @@ class ContourTimeSlider extends ContourBase {
8311
9366
  if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
8312
9367
  if (playing) {
8313
9368
  stop();
8314
- timer = setInterval(step, 1000);
9369
+ const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
9370
+ const delay = Math.max(100, 1000 / speed);
9371
+ timer = setInterval(step, delay);
8315
9372
  } else {
8316
9373
  stop();
8317
9374
  }
8318
9375
  });
8319
9376
  onDispose(this, stop);
8320
9377
  }
9378
+ disconnectedCallback() {
9379
+ super.disconnectedCallback();
9380
+ this._wiredTimeSlider = false;
9381
+ }
8321
9382
  }
8322
9383
  define("contour-time-slider", ContourTimeSlider);
8323
9384
  class ContourHexbin extends ContourBase {
@@ -8338,9 +9399,18 @@ class ContourHexbin extends ContourBase {
8338
9399
  if (renderStates(this, "hexbin")) return;
8339
9400
  const cells = remoteData(this, "cells");
8340
9401
  const effectiveCells = cells || (this._remoteData && this._remoteData.cells ? JSON.stringify(this._remoteData.cells) : null);
8341
- if (effectiveCells) {
9402
+ // Slotted content support: authored .c-hexbin__cell children take
9403
+ // precedence over the JSON `cells` attribute.
9404
+ const authoredCells = Array.from(this.querySelectorAll(":scope > .c-hexbin__cell"));
9405
+ let parsed = null;
9406
+ if (authoredCells.length) {
9407
+ parsed = authoredCells.map((el) => el.textContent || el.getAttribute("title") || "");
9408
+ authoredCells.forEach((el) => el.remove());
9409
+ } else if (effectiveCells) {
9410
+ try { parsed = JSON.parse(effectiveCells); } catch (e) { parsed = null; }
9411
+ }
9412
+ if (parsed) {
8342
9413
  try {
8343
- const parsed = JSON.parse(effectiveCells);
8344
9414
  Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
8345
9415
  const cols = Math.ceil(Math.sqrt(parsed.length || 1));
8346
9416
  this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
@@ -8356,7 +9426,7 @@ class ContourHexbin extends ContourBase {
8356
9426
  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; });
8357
9427
  tip.setAttribute("hidden", "");
8358
9428
  } catch (e) { /* keep existing */ }
8359
- } else {
9429
+ } else if (!parsed) {
8360
9430
  Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
8361
9431
  renderEmpty(this, "hexbin");
8362
9432
  }
@@ -8386,9 +9456,18 @@ class ContourFlowMap extends ContourBase {
8386
9456
  if (renderStates(this, "flow-map")) return;
8387
9457
  const nodes = remoteData(this, "nodes");
8388
9458
  const effectiveNodes = nodes || (this._remoteData && this._remoteData.nodes ? JSON.stringify(this._remoteData.nodes) : null);
8389
- if (effectiveNodes) {
9459
+ // Slotted content support: authored .c-flow-map__node children take
9460
+ // precedence over the JSON `nodes` attribute.
9461
+ const authoredNodes = Array.from(this.querySelectorAll(":scope > .c-flow-map__node"));
9462
+ let parsed = null;
9463
+ if (authoredNodes.length) {
9464
+ parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("title") || "");
9465
+ authoredNodes.forEach((el) => el.remove());
9466
+ } else if (effectiveNodes) {
9467
+ try { parsed = JSON.parse(effectiveNodes); } catch (e) { parsed = null; }
9468
+ }
9469
+ if (parsed) {
8390
9470
  try {
8391
- const parsed = JSON.parse(effectiveNodes);
8392
9471
  Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
8393
9472
  parsed.forEach((n, i) => {
8394
9473
  const node = document.createElement("span");
@@ -8401,7 +9480,7 @@ class ContourFlowMap extends ContourBase {
8401
9480
  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; });
8402
9481
  tip.setAttribute("hidden", "");
8403
9482
  } catch (e) { /* keep existing */ }
8404
- } else {
9483
+ } else if (!parsed) {
8405
9484
  Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
8406
9485
  renderEmpty(this, "flow-map");
8407
9486
  }
@@ -8439,9 +9518,18 @@ class ContourIsochrone extends ContourBase {
8439
9518
  if (renderStates(this, "isochrone")) return;
8440
9519
  const rings = remoteData(this, "rings");
8441
9520
  const effectiveRings = rings || (this._remoteData && this._remoteData.rings ? JSON.stringify(this._remoteData.rings) : null);
8442
- if (effectiveRings) {
9521
+ // Slotted content support: authored .c-isochrone__ring children take
9522
+ // precedence over the JSON `rings` attribute.
9523
+ const authoredRings = Array.from(this.querySelectorAll(":scope > .c-isochrone__ring"));
9524
+ let parsed = null;
9525
+ if (authoredRings.length) {
9526
+ parsed = authoredRings.map((el) => el.textContent || el.getAttribute("title") || "");
9527
+ authoredRings.forEach((el) => el.remove());
9528
+ } else if (effectiveRings) {
9529
+ try { parsed = JSON.parse(effectiveRings); } catch (e) { parsed = null; }
9530
+ }
9531
+ if (parsed) {
8443
9532
  try {
8444
- const parsed = JSON.parse(effectiveRings);
8445
9533
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
8446
9534
  parsed.forEach((r, i) => {
8447
9535
  const ring = document.createElement("span");
@@ -8453,7 +9541,7 @@ class ContourIsochrone extends ContourBase {
8453
9541
  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; });
8454
9542
  tip.setAttribute("hidden", "");
8455
9543
  } catch (e) { /* keep existing */ }
8456
- } else {
9544
+ } else if (!parsed) {
8457
9545
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
8458
9546
  renderEmpty(this, "isochrone");
8459
9547
  }
@@ -9819,7 +10907,7 @@ class ContourTocFull extends ContourBase {
9819
10907
  }
9820
10908
  define("contour-toc", ContourTocFull);
9821
10909
  class ContourFilterBar extends ContourBase {
9822
- static get observed() { return ["label", "divider", "items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
10910
+ static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
9823
10911
  static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
9824
10912
  render() {
9825
10913
  this.classList.add("c-filter-bar");
@@ -9834,13 +10922,48 @@ class ContourFilterBar extends ContourBase {
9834
10922
  const l = this.querySelector(".c-filter-bar__label");
9835
10923
  if (l) l.remove();
9836
10924
  }
9837
- if (this.hasAttribute("divider")) {
9838
- this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
9839
- } else {
9840
- const d = this.querySelector(".c-filter-bar__divider");
9841
- if (d) d.remove();
9842
- }
9843
- // Render filter pills from items.
10925
+ if (this.hasAttribute("divider")) {
10926
+ this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
10927
+ } else {
10928
+ const d = this.querySelector(".c-filter-bar__divider");
10929
+ if (d) d.remove();
10930
+ }
10931
+ // Text input support
10932
+ if (this.hasAttribute("input") || this.hasAttribute("placeholder")) {
10933
+ let inp = this.querySelector(".c-filter-bar__input");
10934
+ if (!inp) { inp = document.createElement("input"); inp.type = "search"; inp.className = "c-filter-bar__input"; this.appendChild(inp); }
10935
+ const ph = this.getAttribute("placeholder");
10936
+ if (ph) inp.setAttribute("placeholder", ph);
10937
+ } else {
10938
+ const inp = this.querySelector(".c-filter-bar__input");
10939
+ if (inp) inp.remove();
10940
+ }
10941
+ // Mode toolbar
10942
+ const modesAttr = this.getAttribute("modes");
10943
+ let modes = null;
10944
+ if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
10945
+ if (modes || this.hasAttribute("mode")) {
10946
+ let bar = this.querySelector(".c-filter-bar__modes");
10947
+ if (!bar) { bar = document.createElement("div"); bar.className = "c-filter-bar__modes"; this.appendChild(bar); }
10948
+ bar.innerHTML = "";
10949
+ const current = this.getAttribute("mode");
10950
+ const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
10951
+ list.forEach((m) => {
10952
+ const name = typeof m === "string" ? m : (m.label || m.value || m);
10953
+ const val = typeof m === "string" ? m : (m.value || m.label || m);
10954
+ const btn = document.createElement("button");
10955
+ btn.type = "button";
10956
+ btn.className = "c-filter-bar__mode";
10957
+ btn.textContent = name;
10958
+ btn.dataset.mode = val;
10959
+ if (current && current === val) btn.setAttribute("aria-pressed", "true");
10960
+ bar.appendChild(btn);
10961
+ });
10962
+ } else {
10963
+ const bar = this.querySelector(".c-filter-bar__modes");
10964
+ if (bar) bar.remove();
10965
+ }
10966
+ // Render filter pills from items.
9844
10967
  Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
9845
10968
  const items = remoteData(this, "items");
9846
10969
  let parsed = null;
@@ -9864,9 +10987,29 @@ class ContourFilterBar extends ContourBase {
9864
10987
  }
9865
10988
  if (!parsed && !label) renderEmpty(this, "filter-bar");
9866
10989
  }
9867
- enhance() {
9868
- wireRemovable(this);
9869
- }
10990
+ enhance() {
10991
+ wireRemovable(this);
10992
+ if (this._wiredFilterBar) return;
10993
+ this._wiredFilterBar = true;
10994
+ this.addEventListener("click", (e) => {
10995
+ const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
10996
+ if (!btn || !this.contains(btn)) return;
10997
+ const mode = btn.dataset.mode || btn.textContent.trim();
10998
+ Array.from(this.querySelectorAll(".c-filter-bar__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
10999
+ this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
11000
+ });
11001
+ // text input
11002
+ const inp = this.querySelector(".c-filter-bar__input");
11003
+ if (inp && !inp._wiredFilterInput) {
11004
+ inp._wiredFilterInput = true;
11005
+ inp.addEventListener("input", () => {
11006
+ this.dispatchEvent(new CustomEvent("contour:input", { bubbles: true, composed: true, detail: { value: inp.value } }));
11007
+ });
11008
+ inp.addEventListener("change", () => {
11009
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
11010
+ });
11011
+ }
11012
+ }
9870
11013
  }
9871
11014
  define("contour-filter-bar", ContourFilterBar);
9872
11015
  class ContourCommand extends ContourBase {
@@ -11035,8 +12178,8 @@ class ContourStyleSwitcher extends ContourBase {
11035
12178
  define("contour-style-switcher", ContourStyleSwitcher);
11036
12179
 
11037
12180
  class ContourStylePanel extends ContourBase {
11038
- static get observed() { return ["title", "layers"]; }
11039
- static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" } }; }
12181
+ static get observed() { return ["title", "layers", "layer", "single", "classification", "palette", "breaks", "opacity", "n", "colors"]; }
12182
+ static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" }, classification: { attribute: "classification" }, palette: { attribute: "palette" }, breaks: { attribute: "breaks" }, opacity: { attribute: "opacity" } }; }
11040
12183
  render() {
11041
12184
  this.classList.add("c-style-panel");
11042
12185
  const title = this.getAttribute("title");
@@ -11044,13 +12187,69 @@ class ContourStylePanel extends ContourBase {
11044
12187
  const t = this.ensure(".c-style-panel__title", () => { const el = document.createElement("div"); el.className = "c-style-panel__title"; return el; });
11045
12188
  t.textContent = title;
11046
12189
  }
11047
- const layers = this.getAttribute("layers");
12190
+ const singleMode = this.hasAttribute("single") || !!this.getAttribute("layer");
12191
+ if (singleMode) {
12192
+ const body = this.ensure(".c-style-panel__body", () => { const el = document.createElement("div"); el.className = "c-style-panel__body"; return el; });
12193
+ body.innerHTML = "";
12194
+ // classification method selector
12195
+ const clsLabel = document.createElement("label"); clsLabel.textContent = "Classification"; body.appendChild(clsLabel);
12196
+ const clsSel = document.createElement("select"); clsSel.className = "c-style-panel__classification";
12197
+ ["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
12198
+ const cls = this.getAttribute("classification"); if (cls) clsSel.value = cls;
12199
+ body.appendChild(clsSel);
12200
+ // palette picker
12201
+ const pal = document.createElement("input"); pal.type = "text"; pal.className = "c-style-panel__palette"; pal.placeholder = "palette";
12202
+ const palv = this.getAttribute("palette"); if (palv) pal.value = palv;
12203
+ body.appendChild(pal);
12204
+ // n (class count)
12205
+ const nIn = document.createElement("input"); nIn.type = "number"; nIn.className = "c-style-panel__n"; nIn.min = "2"; nIn.max = "12";
12206
+ const nv = this.getAttribute("n"); if (nv) nIn.value = nv; else nIn.value = "5";
12207
+ body.appendChild(nIn);
12208
+ // opacity slider
12209
+ const op = document.createElement("input"); op.type = "range"; op.className = "c-style-panel__opacity"; op.min = "0"; op.max = "100";
12210
+ const ov = this.getAttribute("opacity"); op.value = ov != null ? ov : "100";
12211
+ body.appendChild(op);
12212
+ // breaks editor
12213
+ const breaks = document.createElement("input"); breaks.type = "text"; breaks.className = "c-style-panel__breaks"; breaks.placeholder = "breaks";
12214
+ const bv = this.getAttribute("breaks"); if (bv) breaks.value = bv;
12215
+ body.appendChild(breaks);
12216
+ // color list
12217
+ const colorsAttr = this.getAttribute("colors");
12218
+ let colors = null;
12219
+ if (colorsAttr) { try { colors = JSON.parse(colorsAttr); } catch (e) { colors = colorsAttr.split(",").map((s) => s.trim()); } }
12220
+ if (Array.isArray(colors)) {
12221
+ const list = document.createElement("div"); list.className = "c-style-panel__colors";
12222
+ colors.forEach((c) => {
12223
+ const sw = document.createElement("span"); sw.className = "c-style-panel__color"; sw.style.background = c; list.appendChild(sw);
12224
+ });
12225
+ body.appendChild(list);
12226
+ }
12227
+ return;
12228
+ }
12229
+ const layers = this.getAttribute("layers");
11048
12230
  const body = this.ensure(".c-style-panel__body", () => { const el = document.createElement("div"); el.className = "c-style-panel__body"; return el; });
11049
- if (layers) {
12231
+ // Slotted content support: authored .c-style-panel__row children take
12232
+ // precedence over the JSON `layers` attribute.
12233
+ const authoredRows = Array.from(this.querySelectorAll(":scope > .c-style-panel__row"));
12234
+ let parsed = null;
12235
+ if (authoredRows.length) {
12236
+ parsed = authoredRows.map((row) => ({
12237
+ name: row.querySelector(".c-style-panel__name")?.textContent || "",
12238
+ color: row.querySelector(".c-style-panel__color")?.value,
12239
+ classification: row.querySelector(".c-style-panel__classification")?.value,
12240
+ palette: row.querySelector(".c-style-panel__palette")?.value,
12241
+ breaks: row.querySelector(".c-style-panel__breaks")?.value,
12242
+ opacity: row.querySelector(".c-style-panel__opacity")?.value,
12243
+ }));
12244
+ authoredRows.forEach((row) => row.remove());
12245
+ } else if (layers) {
11050
12246
  try {
11051
- const parsed = JSON.parse(layers);
11052
- body.innerHTML = "";
11053
- parsed.forEach((l) => {
12247
+ parsed = JSON.parse(layers);
12248
+ } catch (e) { parsed = null; }
12249
+ }
12250
+ if (parsed) {
12251
+ body.innerHTML = "";
12252
+ parsed.forEach((l) => {
11054
12253
  const row = document.createElement("div");
11055
12254
  row.className = "c-style-panel__row";
11056
12255
  const name = document.createElement("span");
@@ -11062,11 +12261,63 @@ class ContourStylePanel extends ContourBase {
11062
12261
  input.className = "c-style-panel__color";
11063
12262
  if (typeof l === "object" && l.color) input.value = l.color;
11064
12263
  row.appendChild(input);
12264
+ // classification method selector
12265
+ const clsSel = document.createElement("select");
12266
+ clsSel.className = "c-style-panel__classification";
12267
+ ["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
12268
+ if (typeof l === "object" && l.classification) clsSel.value = l.classification;
12269
+ row.appendChild(clsSel);
12270
+ // palette picker
12271
+ const pal = document.createElement("input");
12272
+ pal.type = "text";
12273
+ pal.className = "c-style-panel__palette";
12274
+ pal.placeholder = "palette";
12275
+ if (typeof l === "object" && l.palette) pal.value = l.palette;
12276
+ row.appendChild(pal);
12277
+ // breaks editor
12278
+ const breaks = document.createElement("input");
12279
+ breaks.type = "text";
12280
+ breaks.className = "c-style-panel__breaks";
12281
+ breaks.placeholder = "breaks";
12282
+ if (typeof l === "object" && l.breaks) breaks.value = (Array.isArray(l.breaks) ? l.breaks.join(",") : l.breaks);
12283
+ row.appendChild(breaks);
12284
+ // opacity control
12285
+ const op = document.createElement("input");
12286
+ op.type = "range";
12287
+ op.className = "c-style-panel__opacity";
12288
+ op.min = "0"; op.max = "100";
12289
+ op.value = (typeof l === "object" && l.opacity != null) ? l.opacity : "100";
12290
+ row.appendChild(op);
11065
12291
  body.appendChild(row);
11066
12292
  });
11067
- } catch (e) { /* keep existing */ }
11068
12293
  }
11069
12294
  }
12295
+ enhance() {
12296
+ if (this._wiredStylePanel) return;
12297
+ this._wiredStylePanel = true;
12298
+ this.addEventListener("change", (e) => {
12299
+ const t = e.target;
12300
+ if (!t || !this.contains(t)) return;
12301
+ const row = t.closest(".c-style-panel__row");
12302
+ const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
12303
+ if (t.classList.contains("c-style-panel__color")) {
12304
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "color" }, bubbles: true, composed: true }));
12305
+ } else if (t.classList.contains("c-style-panel__classification")) {
12306
+ this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value, layer: name }, bubbles: true, composed: true }));
12307
+ } else if (t.classList.contains("c-style-panel__opacity")) {
12308
+ this.dispatchEvent(new CustomEvent("contour:layer-opacity", { detail: { name, opacity: Number(t.value) }, bubbles: true, composed: true }));
12309
+ }
12310
+ });
12311
+ this.addEventListener("input", (e) => {
12312
+ const t = e.target;
12313
+ if (!t || !this.contains(t)) return;
12314
+ if (t.classList.contains("c-style-panel__palette") || t.classList.contains("c-style-panel__breaks")) {
12315
+ const row = t.closest(".c-style-panel__row");
12316
+ const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
12317
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: t.classList.contains("c-style-panel__palette") ? "palette" : "breaks" }, bubbles: true, composed: true }));
12318
+ }
12319
+ });
12320
+ }
11070
12321
  }
11071
12322
  define("contour-style-panel", ContourStylePanel);
11072
12323
 
@@ -12090,11 +13341,30 @@ class ContourTreeGrid extends ContourBase {
12090
13341
  if (ADOPTED && key === ADOPTED_KEY) return ADOPTED;
12091
13342
  ADOPTED_KEY = key;
12092
13343
  ADOPTED = [];
13344
+ // Collect every rule a sheet carries, descending into @imported sheets,
13345
+ // because adoptedStyleSheets cannot hold @import rules (the platform
13346
+ // rejects them) and the imported sheets are not separate top-level entries
13347
+ // in document.styleSheets. Skipping them would hand the shadow root an
13348
+ // empty sheet.
13349
+ const collect = (sheet, out) => {
13350
+ let rules;
13351
+ try { rules = sheet.cssRules; } catch (e) { return; }
13352
+ if (!rules) return;
13353
+ for (const r of rules) {
13354
+ if (r instanceof CSSImportRule) {
13355
+ if (r.styleSheet) collect(r.styleSheet, out);
13356
+ } else {
13357
+ try { out.push(r.cssText); } catch (e) { /* unreadable */ }
13358
+ }
13359
+ }
13360
+ };
12093
13361
  for (const sheet of document.styleSheets) {
12094
13362
  try {
12095
13363
  if (sheet.href && new URL(sheet.href).origin === location.origin) {
13364
+ const collected = [];
13365
+ collect(sheet, collected);
12096
13366
  const built = new CSSStyleSheet();
12097
- built.replaceSync(Array.from(sheet.cssRules, (r) => r.cssText).join("\n"));
13367
+ if (collected.length) built.replaceSync(collected.join("\n"));
12098
13368
  ADOPTED.push(built);
12099
13369
  }
12100
13370
  } catch (e) { /* cross-origin or unreadable */ }
@@ -12320,6 +13590,14 @@ connectedCallback() {
12320
13590
  shadow("contour-shadow-kpi", `<div class="c-kpi" part="kpi"><div class="c-kpi__value" part="value"><slot name="value"></slot></div><div class="c-kpi__label" part="label"><slot name="label"></slot></div><div class="c-kpi__foot" part="foot"><slot name="delta"></slot><slot name="note"></slot></div></div>`);
12321
13591
  shadow("contour-shadow-stat", `<div class="c-stat" part="stat"><div class="c-stat__value" part="value"><slot name="value"></slot></div><div class="c-stat__label" part="label"><slot name="label"></slot></div><div class="c-stat__delta" part="delta"><slot name="delta"></slot></div></div>`);
12322
13592
  shadow("contour-shadow-meter", `<div class="c-meter" part="meter"><span class="c-meter__core" part="core"><span class="c-meter__value" part="value"><slot name="value"></slot></span><span class="c-meter__label" part="label"><slot name="label"></slot></span></span></div>`);
13593
+ shadow("contour-shadow-brownout", `<div class="c-brownout" part="brownout" data-level="0"><slot></slot></div>`);
13594
+ shadow("contour-shadow-widget-state", `<div class="c-widget-state" part="widget-state"><slot></slot></div>`);
13595
+ shadow("contour-shadow-donut", `<div class="c-donut" part="donut"><svg class="c-donut__ring" part="ring" viewBox="0 0 32 32"></svg><div class="c-donut__center" part="center"><slot name="value"></slot></div><div class="c-donut__list" part="list"><slot></slot></div></div>`);
13596
+ shadow("contour-shadow-axis", `<div class="c-axis" part="axis"><slot></slot></div>`);
13597
+ shadow("contour-shadow-brush", `<div class="c-brush" part="brush"><div class="c-brush__selection" part="selection"></div></div>`);
13598
+ shadow("contour-shadow-stacked-bar", `<div class="c-stacked-bar" part="bar"><slot></slot></div>`);
13599
+ shadow("contour-shadow-category", `<div class="c-category" part="category" role="listbox"><slot></slot></div>`);
13600
+ shadow("contour-shadow-gauge", `<div class="c-gauge" part="gauge"><svg class="c-gauge__dial" part="dial" aria-hidden="true" viewBox="0 0 100 100"><path class="c-gauge__track" part="track" d="M 10 90 A 40 40 0 0 1 90 90"></path><g class="c-gauge__zones"></g><line class="c-gauge__needle" part="needle" x1="50" y1="50" x2="50" y2="15"></line><circle class="c-gauge__hub" part="hub" cx="50" cy="50" r="4"></circle></svg><div class="c-gauge__value" part="value"><slot name="value"></slot></div><div class="c-gauge__band" part="band"><slot name="band"></slot></div></div>`);
12323
13601
  shadow("contour-shadow-diff", `<div class="c-diff" part="diff"><div class="c-diff__line c-diff__line--del" part="before"><span class="c-diff__sign">−</span><span><slot name="before"></slot></span></div><div class="c-diff__line c-diff__line--add" part="after"><span class="c-diff__sign">+</span><span><slot name="after"></slot></span></div></div>`);
12324
13602
  shadow("contour-shadow-do-dont", `<div class="c-do-dont" part="do-dont"><div class="c-do-dont__item c-do-dont__item--do" part="do"><slot name="do"></slot></div><div class="c-do-dont__item c-do-dont__item--dont" part="dont"><slot name="dont"></slot></div></div>`);
12325
13603
  shadow("contour-shadow-threshold", `<div class="c-threshold" part="threshold"><span class="c-threshold__fill" part="value"></span><span class="c-threshold__target" part="target"></span></div>`);
@@ -12342,6 +13620,7 @@ connectedCallback() {
12342
13620
  shadow("contour-shadow-table", `<div class="c-table-wrap" part="wrap"><table class="c-table" part="table"><thead><slot name="head"></slot></thead><tbody><slot></slot></tbody></table></div>`);
12343
13621
  shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
12344
13622
  shadow("contour-shadow-bivariate", `<div class="c-bivariate" part="bivariate"><div class="c-bivariate__matrix" part="matrix"><slot></slot></div></div>`);
13623
+ shadow("contour-shadow-bivariate-legend", `<div class="c-bivariate-legend" part="legend"><div class="c-bivariate-legend__matrix" part="matrix"><slot></slot></div></div>`);
12345
13624
  shadow("contour-shadow-expandable", `<details class="c-expandable" part="expandable"><summary class="c-expandable__summary"><slot name="summary"></slot></summary><div class="c-expandable__body" part="body"><slot></slot></div></details>`);
12346
13625
  shadow("contour-shadow-disclosure", `<details class="c-disclosure" part="disclosure"><summary><slot name="summary"></slot></summary><div class="c-disclosure__body" part="body"><slot></slot></div></details>`);
12347
13626
  shadow("contour-shadow-faq", `<div class="c-faq" part="faq"><div class="c-faq__question" part="question"><slot name="question"></slot></div><div class="c-faq__answer" part="answer"><slot name="answer"></slot></div></div>`);