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