contour-ds 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/build-manifest.json +44 -44
  3. package/dist/contour-wc.esm.js +1012 -67
  4. package/dist/contour-wc.esm.min.js +1 -1
  5. package/dist/contour-wc.js +1012 -67
  6. package/dist/contour-wc.min.js +1 -1
  7. package/dist/contour.components.json +403 -16
  8. package/dist/contour.css +328 -10
  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 +1 -1
  42. package/dist/registry/items/contour-data.json +2 -2
  43. package/dist/registry/items/contour-docs.json +1 -1
  44. package/dist/registry/items/contour-landing.json +2 -2
  45. package/dist/registry/registry.json +6 -6
  46. package/dist/surfaces/contour-data.min.css +1 -1
  47. package/dist/surfaces/contour-landing.min.css +1 -1
  48. package/dist/wc/core.mjs +13 -5
  49. package/dist/wc/data.mjs +687 -26
  50. package/dist/wc/index.mjs +1 -1
  51. package/dist/wc/interaction.mjs +3 -2
  52. package/dist/wc/map.mjs +189 -27
  53. package/dist/wc/shadow.mjs +29 -1
  54. package/dist/wc/svg.mjs +16 -1
  55. package/dist/wc/ui.mjs +77 -8
  56. 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,10 @@ 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 },
101
109
  "contour:layer-toggle": { payload: ["name"], composed: true },
102
110
  "contour:layer-visibility": { payload: ["name", "visible"], composed: true },
103
111
  "contour:legend-toggle": { payload: ["label", "key", "layers", "pressed"], composed: true },
@@ -167,12 +175,12 @@ function sanitizeHtml(input) {
167
175
  // role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
168
176
  // Adding one of those back to this list makes that component recurse.
169
177
  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",
178
+ "accept", "action", "actions", "after", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
179
+ "cells", "checked", "chrome", "closable", "colors", "content", "controls", "copyable", "count", "current", "data", "date", "delta", "description", "glyphs", "demo", "density", "desc", "dir", "direction", "disabled", "dismissible", "divider", "do", "dont", "dot",
180
+ "empty", "error", "exclusive", "format", "heading", "hint", "href", "icon", "illustration", "index", "instrument", "interval", "items", "key", "layers", "level",
181
+ "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
182
  "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",
183
+ "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",
176
184
  "state", "steps", "subtitle", "summary", "src", "tabs", "tag", "text", "ticks", "title", "type", "unit",
177
185
  "variant", "values", "viewport", "yes", "zoomable", "x", "y",
178
186
  ];
@@ -1099,6 +1107,22 @@ function scaleBarTicks(value, segments) {
1099
1107
  }
1100
1108
  return out;
1101
1109
  }
1110
+ // Marker shape encoding utility (G-13)
1111
+ const MARKER_SHAPES = ["circle", "square", "triangle", "diamond", "star"];
1112
+ function markerStyles(shape) {
1113
+ const map = {
1114
+ circle: "border-radius:50%",
1115
+ square: "border-radius:0",
1116
+ triangle: "clip-path:polygon(50% 0%,0% 100%,100% 100%)",
1117
+ diamond: "transform:rotate(45deg)",
1118
+ star: "clip-path:polygon(50% 0%,61% 35%,98% 35%,68% 57%,79% 91%,50% 70%,21% 91%,32% 57%,2% 35%,39% 35%)",
1119
+ };
1120
+ return map[shape] || "";
1121
+ }
1122
+ function assignMarkers(items) {
1123
+ return (items || []).map((it, i) => ({ ...it, marker: MARKER_SHAPES[i % MARKER_SHAPES.length] }));
1124
+ }
1125
+
1102
1126
  /* ============================================================================
1103
1127
  CONTOUR — shared behaviour
1104
1128
  ----------------------------------------------------------------------------
@@ -3731,9 +3755,9 @@ class ContourReadout extends ContourBase {
3731
3755
  }
3732
3756
  define("contour-readout", ContourReadout);
3733
3757
  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"]; }
3758
+ 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
3759
  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" } };
3760
+ 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
3761
  }
3738
3762
  render() {
3739
3763
  this.classList.add("c-kpi");
@@ -3794,6 +3818,30 @@ class ContourKpi extends ContourBase {
3794
3818
  if (u) u.remove();
3795
3819
  }
3796
3820
  }
3821
+ // threshold badge
3822
+ const threshold = this.getAttribute("threshold") || this.getAttribute("thresholds");
3823
+ if (threshold) {
3824
+ const f = this.ensure(".c-kpi__foot", () => { const el = document.createElement("div"); el.className = "c-kpi__foot"; return el; });
3825
+ let badge = f.querySelector(".c-kpi__threshold-badge");
3826
+ if (!badge) { badge = document.createElement("span"); badge.className = "c-kpi__threshold-badge"; f.appendChild(badge); }
3827
+ badge.textContent = threshold;
3828
+ badge.setAttribute("part", "threshold-badge");
3829
+ } else {
3830
+ const b = this.querySelector(".c-kpi__threshold-badge");
3831
+ if (b) b.remove();
3832
+ }
3833
+ // remove orphaned foot container when no children remain
3834
+ const foot = this.querySelector(".c-kpi__foot");
3835
+ if (foot && !foot.querySelector(".c-delta, .c-kpi__note, .c-kpi__threshold-badge")) foot.remove();
3836
+ // sparkline canvas
3837
+ const spark = this.getAttribute("sparkline");
3838
+ if (spark) {
3839
+ let canvas = this.querySelector(".c-kpi__sparkline-canvas");
3840
+ if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-kpi__sparkline-canvas"; canvas.setAttribute("part", "sparkline-canvas"); this.appendChild(canvas); }
3841
+ } else {
3842
+ const c = this.querySelector(".c-kpi__sparkline-canvas");
3843
+ if (c) c.remove();
3844
+ }
3797
3845
  if (!value && !label) {
3798
3846
  renderEmpty(this, "kpi");
3799
3847
  }
@@ -4637,24 +4685,32 @@ const series = this.getAttribute("series");
4637
4685
  }
4638
4686
  define("contour-chart", ContourChart);
4639
4687
  class ContourComparison extends ContourBase {
4640
- static get observed() { return ["divider", "value"]; }
4641
- static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" } }; }
4688
+ static get observed() { return ["divider", "value", "before", "after"]; }
4689
+ static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
4642
4690
  render() {
4643
4691
  this.classList.add("c-comparison");
4644
- this.style.blockSize = "12rem";
4692
+ if (!this.style.blockSize) this.style.blockSize = "12rem";
4645
4693
  this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
4646
4694
  // Ensure two panes exist.
4695
+ const beforeLabel = this.getAttribute("before") || "Before";
4696
+ const afterLabel = this.getAttribute("after") || "After";
4647
4697
  if (!this.querySelector(".c-comparison__pane--before")) {
4648
4698
  const p = document.createElement("div");
4649
4699
  p.className = "c-comparison__pane c-comparison__pane--before";
4650
- p.textContent = "Before";
4700
+ p.textContent = beforeLabel;
4651
4701
  this.appendChild(p);
4702
+ } else {
4703
+ const p = this.querySelector(".c-comparison__pane--before");
4704
+ if (p) p.textContent = beforeLabel;
4652
4705
  }
4653
4706
  if (!this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)")) {
4654
4707
  const p = document.createElement("div");
4655
4708
  p.className = "c-comparison__pane";
4656
- p.textContent = "After";
4709
+ p.textContent = afterLabel;
4657
4710
  this.appendChild(p);
4711
+ } else {
4712
+ const p = this.querySelector(".c-comparison__pane:not(.c-comparison__pane--before)");
4713
+ if (p) p.textContent = afterLabel;
4658
4714
  }
4659
4715
  const divider = this.getAttribute("divider");
4660
4716
  if (divider !== null) {
@@ -4928,6 +4984,517 @@ class ContourStat extends ContourBase {
4928
4984
  }
4929
4985
  }
4930
4986
  define("contour-stat", ContourStat);
4987
+ class ContourGauge extends ContourBase {
4988
+ 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"]; }
4989
+ 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" } }; }
4990
+ render() {
4991
+ this.classList.add("c-gauge");
4992
+ wireStates(this);
4993
+ loadRemote(this, ["value"]);
4994
+ if (renderStates(this, "gauge")) return;
4995
+ const rawValue = this.getAttribute("value");
4996
+ const num = parseFloat(rawValue);
4997
+ const hasValue = rawValue !== null && rawValue !== "" && Number.isFinite(num);
4998
+ const min = parseFloat(this.getAttribute("min") || "0");
4999
+ const max = parseFloat(this.getAttribute("max") || "100");
5000
+ const heading = this.getAttribute("heading");
5001
+ const showHeader = this.getAttribute("show-header") !== "false";
5002
+ const description = this.getAttribute("description");
5003
+ const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
5004
+ const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
5005
+ // empty state
5006
+ if (!hasValue) {
5007
+ if (heading && showHeader) {
5008
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; return el; });
5009
+ t.textContent = heading;
5010
+ }
5011
+ const empty = this.ensure(".c-gauge__empty", () => { const el = document.createElement("div"); el.className = "c-gauge__empty"; el.setAttribute("part", "empty"); return el; });
5012
+ empty.textContent = noDataMessage;
5013
+ // remove dial/value/band if present
5014
+ [".c-gauge__dial", ".c-gauge__value", ".c-gauge__band"].forEach((sel) => { const n = this.querySelector(sel); if (n) n.remove(); });
5015
+ return;
5016
+ }
5017
+ // heading
5018
+ if (heading && showHeader) {
5019
+ const t = this.ensure(".c-gauge__title", () => { const el = document.createElement("div"); el.className = "c-gauge__title"; el.setAttribute("part", "title"); return el; });
5020
+ t.textContent = heading;
5021
+ } else {
5022
+ const t = this.querySelector(".c-gauge__title"); if (t) t.remove();
5023
+ }
5024
+ // thresholds
5025
+ let thresholds = [];
5026
+ const tAttr = this.getAttribute("thresholds");
5027
+ if (tAttr) { try { thresholds = JSON.parse(tAttr); } catch (e) { thresholds = []; } }
5028
+ // band determination
5029
+ let band = null;
5030
+ if (thresholds && thresholds.length) {
5031
+ // thresholds sorted ascending by value
5032
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
5033
+ for (let i = sorted.length - 1; i >= 0; i--) {
5034
+ if (num >= (sorted[i].value || 0)) { band = sorted[i]; break; }
5035
+ }
5036
+ }
5037
+ // dial (unless brownout >= 3)
5038
+ const shedDial = brownoutLevel >= 3;
5039
+ let dial = this.querySelector(".c-gauge__dial");
5040
+ if (shedDial) {
5041
+ if (dial) dial.remove();
5042
+ } else {
5043
+ if (!dial) {
5044
+ dial = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5045
+ dial.setAttribute("class", "c-gauge__dial");
5046
+ dial.setAttribute("part", "dial");
5047
+ dial.setAttribute("aria-hidden", "true");
5048
+ dial.setAttribute("viewBox", "0 0 100 100");
5049
+ this.appendChild(dial);
5050
+ }
5051
+ // rebuild dial content
5052
+ dial.innerHTML = "";
5053
+ // track arc (semicircle)
5054
+ const track = document.createElementNS("http://www.w3.org/2000/svg", "path");
5055
+ track.setAttribute("class", "c-gauge__track");
5056
+ track.setAttribute("d", "M 10 90 A 40 40 0 0 1 90 90");
5057
+ dial.appendChild(track);
5058
+ // zones: each threshold defines a band from its value to the next
5059
+ // threshold's value (or max), drawn as an arc along the track so the
5060
+ // bands no longer stack on top of one another.
5061
+ if (thresholds && thresholds.length) {
5062
+ const sorted = [...thresholds].sort((a, b) => (a.value || 0) - (b.value || 0));
5063
+ const toPoint = (v) => {
5064
+ const pos = (1 - (v - min) / (max - min || 1)) * Math.PI;
5065
+ return { x: 50 + 40 * Math.cos(pos), y: 90 - 40 * Math.sin(pos) };
5066
+ };
5067
+ for (let i = 0; i < sorted.length; i++) {
5068
+ const v1 = sorted[i].value || 0;
5069
+ const v2 = (i + 1 < sorted.length) ? (sorted[i + 1].value || max) : max;
5070
+ const p1 = toPoint(v1);
5071
+ const p2 = toPoint(v2);
5072
+ const z = document.createElementNS("http://www.w3.org/2000/svg", "path");
5073
+ z.setAttribute("class", "c-gauge__zone");
5074
+ z.setAttribute("stroke", sorted[i].color || "var(--color-primary)");
5075
+ 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));
5076
+ dial.appendChild(z);
5077
+ }
5078
+ }
5079
+ // needle
5080
+ const angle = ((num - min) / (max - min || 1)) * 180 - 90;
5081
+ const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
5082
+ needle.setAttribute("class", "c-gauge__needle needle");
5083
+ needle.setAttribute("x1", "50"); needle.setAttribute("y1", "50");
5084
+ needle.setAttribute("x2", String(50 + 35 * Math.cos(angle * Math.PI / 180)));
5085
+ needle.setAttribute("y2", String(50 + 35 * Math.sin(angle * Math.PI / 180)));
5086
+ dial.appendChild(needle);
5087
+ const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5088
+ hub.setAttribute("class", "c-gauge__hub hub");
5089
+ hub.setAttribute("cx", "50"); hub.setAttribute("cy", "50"); hub.setAttribute("r", "4");
5090
+ dial.appendChild(hub);
5091
+ }
5092
+ // value element (meter)
5093
+ const valueEl = this.ensure(".c-gauge__value", () => { const el = document.createElement("div"); el.className = "c-gauge__value"; el.setAttribute("part", "value"); return el; });
5094
+ valueEl.textContent = formatValue(String(num), this.getAttribute("format"), this.getAttribute("locale")) + (this.getAttribute("unit") ? " " + this.getAttribute("unit") : "");
5095
+ valueEl.setAttribute("role", "meter");
5096
+ valueEl.setAttribute("aria-valuenow", String(num));
5097
+ valueEl.setAttribute("aria-valuemin", String(min));
5098
+ valueEl.setAttribute("aria-valuemax", String(max));
5099
+ if (heading) {
5100
+ // labelledby
5101
+ if (!valueEl.id) valueEl.id = contourId("gauge-value");
5102
+ }
5103
+ if (band) {
5104
+ valueEl.setAttribute("aria-valuetext", num + ", " + (band.label || (">= " + band.value)));
5105
+ } else {
5106
+ valueEl.setAttribute("aria-valuetext", String(num));
5107
+ }
5108
+ // aria-labelledby / aria-label
5109
+ const titleEl = this.querySelector(".c-gauge__title");
5110
+ if (titleEl) {
5111
+ if (!titleEl.id) titleEl.id = contourId("gauge-title");
5112
+ valueEl.setAttribute("aria-labelledby", titleEl.id);
5113
+ valueEl.removeAttribute("aria-label");
5114
+ } else {
5115
+ valueEl.removeAttribute("aria-labelledby");
5116
+ if (heading) valueEl.setAttribute("aria-label", heading);
5117
+ }
5118
+ // band word
5119
+ const bandEl = this.querySelector(".c-gauge__band");
5120
+ if (band) {
5121
+ const b = this.ensure(".c-gauge__band", () => { const el = document.createElement("div"); el.className = "c-gauge__band"; el.setAttribute("part", "band"); return el; });
5122
+ b.textContent = band.label || (">= " + band.value);
5123
+ } else {
5124
+ if (bandEl) bandEl.remove();
5125
+ }
5126
+ // description
5127
+ if (description) {
5128
+ let d = this.querySelector(".c-gauge__desc");
5129
+ if (!d) { d = document.createElement("div"); d.className = "c-gauge__desc"; this.appendChild(d); }
5130
+ d.textContent = description;
5131
+ }
5132
+ }
5133
+ enhance() {}
5134
+ }
5135
+ define("contour-gauge", ContourGauge);
5136
+ class ContourAxis extends ContourBase {
5137
+ static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5138
+ 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" } }; }
5139
+ render() {
5140
+ this.classList.add("c-axis");
5141
+ const orientation = this.getAttribute("orientation") || "horizontal";
5142
+ this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
5143
+ this.classList.toggle("c-axis--vertical", orientation === "vertical");
5144
+ if (orientation === "horizontal") this.setAttribute("part", "axis-x");
5145
+ else this.setAttribute("part", "axis-y");
5146
+ wireStates(this);
5147
+ loadRemote(this, ["values"]);
5148
+ if (renderStates(this, "axis")) return;
5149
+ // parse values
5150
+ let values = [];
5151
+ const vAttr = this.getAttribute("values");
5152
+ if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map((x) => x.trim()); } }
5153
+ const ticks = parseInt(this.getAttribute("ticks") || "0", 10) || values.length;
5154
+ // Slotted content support: authored .c-axis__tick children take
5155
+ // precedence over the JSON `values` attribute.
5156
+ const authoredTicks = Array.from(this.querySelectorAll(":scope > .c-axis__tick"));
5157
+ if (authoredTicks.length) {
5158
+ // keep authored ticks, just ensure labels are formatted
5159
+ authoredTicks.forEach((tick) => {
5160
+ const label = tick.querySelector(".c-axis__label");
5161
+ if (label && !label.textContent) label.textContent = tick.textContent;
5162
+ });
5163
+ } else {
5164
+ // clear
5165
+ Array.from(this.querySelectorAll(".c-axis__tick")).forEach((n) => n.remove());
5166
+ const list = values.length ? values : Array.from({ length: ticks }, (_, i) => i);
5167
+ list.forEach((v) => {
5168
+ const tick = document.createElement("span");
5169
+ tick.className = "c-axis__tick";
5170
+ const label = document.createElement("span");
5171
+ label.className = "c-axis__label";
5172
+ label.textContent = formatValue(String(v), this.getAttribute("format"), this.getAttribute("locale"));
5173
+ tick.appendChild(label);
5174
+ this.appendChild(tick);
5175
+ });
5176
+ }
5177
+ }
5178
+ enhance() {}
5179
+ }
5180
+ define("contour-axis", ContourAxis);
5181
+ class ContourBrush extends ContourBase {
5182
+ static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5183
+ static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
5184
+ render() {
5185
+ this.classList.add("c-brush");
5186
+ wireStates(this);
5187
+ loadRemote(this, []);
5188
+ if (renderStates(this, "brush")) return;
5189
+ let sel = this.querySelector(".c-brush__selection");
5190
+ if (!sel) { sel = document.createElement("div"); sel.className = "c-brush__selection"; this.appendChild(sel); }
5191
+ const start = parseFloat(this.getAttribute("start") || "0");
5192
+ const end = parseFloat(this.getAttribute("end") || "100");
5193
+ const min = parseFloat(this.getAttribute("min") || "0");
5194
+ const max = parseFloat(this.getAttribute("max") || "100");
5195
+ const range = max - min || 1;
5196
+ const left = ((start - min) / range) * 100;
5197
+ const width = ((end - start) / range) * 100;
5198
+ sel.style.insetInlineStart = left + "%";
5199
+ sel.style.inlineSize = width + "%";
5200
+ // handles
5201
+ ["start","end"].forEach((h) => {
5202
+ let handle = this.querySelector(".c-brush__handle--" + h);
5203
+ if (!handle) { handle = document.createElement("div"); handle.className = "c-brush__handle c-brush__handle--" + h; this.appendChild(handle); }
5204
+ const val = h === "start" ? start : end;
5205
+ handle.style.insetInlineStart = (((val - min) / range) * 100) + "%";
5206
+ });
5207
+ }
5208
+ enhance() {
5209
+ if (this._wiredBrush) return;
5210
+ this._wiredBrush = true;
5211
+ this.addEventListener("pointerdown", (e) => {
5212
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
5213
+ });
5214
+ this.addEventListener("pointerup", (e) => {
5215
+ this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
5216
+ });
5217
+ }
5218
+ }
5219
+ define("contour-brush", ContourBrush);
5220
+ class ContourStackedBar extends ContourBase {
5221
+ static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
5222
+ static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
5223
+ render() {
5224
+ this.classList.add("c-stacked-bar");
5225
+ wireStates(this);
5226
+ loadRemote(this, ["segments", "values"]);
5227
+ if (renderStates(this, "stacked-bar")) return;
5228
+ Array.from(this.querySelectorAll(".c-stacked-bar__segment")).forEach((n) => n.remove());
5229
+ // Slotted content support: authored .c-stacked-bar__segment children take
5230
+ // precedence over the JSON `segments` attribute.
5231
+ const authoredSegments = Array.from(this.querySelectorAll(":scope > .c-stacked-bar__segment"));
5232
+ let segments = [];
5233
+ if (authoredSegments.length) {
5234
+ segments = authoredSegments.map((el) => ({
5235
+ label: el.getAttribute("title") || el.textContent || "",
5236
+ value: parseFloat(el.style.inlineSize) || 0,
5237
+ color: el.style.background || undefined,
5238
+ }));
5239
+ authoredSegments.forEach((el) => el.remove());
5240
+ } else {
5241
+ const sAttr = this.getAttribute("segments");
5242
+ if (sAttr) { try { segments = JSON.parse(sAttr); } catch (e) { segments = []; } }
5243
+ }
5244
+ const values = segments.map((seg) => (typeof seg === "object" ? (seg.value || 0) : Number(seg) || 0));
5245
+ const total = values.reduce((a, b) => a + b, 0) || 1;
5246
+ const normalize = this.hasAttribute("normalize");
5247
+ const denom = normalize ? total : (parseFloat(this.getAttribute("max") || String(total)) || total);
5248
+ segments.forEach((seg, i) => {
5249
+ const v = values[i];
5250
+ const el = document.createElement("div");
5251
+ el.className = "c-stacked-bar__segment";
5252
+ el.style.inlineSize = ((v / denom) * 100) + "%";
5253
+ el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
5254
+ el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
5255
+ this.appendChild(el);
5256
+ });
5257
+ if (!segments.length) renderEmpty(this, "stacked-bar");
5258
+ }
5259
+ enhance() {}
5260
+ }
5261
+ define("contour-stacked-bar", ContourStackedBar);
5262
+ class ContourCategory extends ContourBase {
5263
+ static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
5264
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
5265
+ render() {
5266
+ this.classList.add("c-category");
5267
+ this.setAttribute("role", "listbox");
5268
+ wireStates(this);
5269
+ loadRemote(this, ["items"]);
5270
+ if (renderStates(this, "category")) return;
5271
+ Array.from(this.querySelectorAll(".c-category__item")).forEach((n) => n.remove());
5272
+ // Slotted content support: authored .c-category__item children take
5273
+ // precedence over the JSON `items` attribute.
5274
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-category__item"));
5275
+ let items = [];
5276
+ if (authoredItems.length) {
5277
+ authoredItems.forEach((el) => {
5278
+ const lbl = el.querySelector(".c-category__label");
5279
+ items.push({ label: lbl ? lbl.textContent : el.textContent, value: 0 });
5280
+ });
5281
+ authoredItems.forEach((el) => el.remove());
5282
+ } else {
5283
+ const iAttr = this.getAttribute("items");
5284
+ if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
5285
+ }
5286
+ const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
5287
+ items.forEach((it, idx) => {
5288
+ const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
5289
+ const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
5290
+ const item = document.createElement("div");
5291
+ item.className = "c-category__item";
5292
+ item.setAttribute("role", "option");
5293
+ item.setAttribute("aria-selected", "false");
5294
+ const lbl = document.createElement("span");
5295
+ lbl.className = "c-category__label";
5296
+ lbl.textContent = label;
5297
+ const barWrap = document.createElement("div");
5298
+ barWrap.style.flex = "1";
5299
+ const bar = document.createElement("div");
5300
+ bar.className = "c-category__bar";
5301
+ bar.style.inlineSize = ((value / max) * 100) + "%";
5302
+ barWrap.appendChild(bar);
5303
+ const val = document.createElement("span");
5304
+ val.className = "c-category__value";
5305
+ val.textContent = String(value);
5306
+ item.appendChild(lbl);
5307
+ item.appendChild(barWrap);
5308
+ item.appendChild(val);
5309
+ this.appendChild(item);
5310
+ });
5311
+ if (!items.length) renderEmpty(this, "category");
5312
+ }
5313
+ enhance() {}
5314
+ }
5315
+ define("contour-category", ContourCategory);
5316
+ class ContourDonut extends ContourBase {
5317
+ static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
5318
+ static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
5319
+ render() {
5320
+ this.classList.add("c-donut");
5321
+ wireStates(this);
5322
+ loadRemote(this, ["items", "values"]);
5323
+ if (renderStates(this, "donut")) return;
5324
+ Array.from(this.querySelectorAll(".c-donut__ring, .c-donut__center, .c-donut__list, .c-donut__empty")).forEach((n) => n.remove());
5325
+ // Slotted content support: authored .c-donut__item children take precedence
5326
+ // over the JSON `items` attribute, so consumers can compose legend rows
5327
+ // by hand instead of serialising them into an attribute.
5328
+ const authoredItems = Array.from(this.querySelectorAll(":scope > .c-donut__item"));
5329
+ let items = [];
5330
+ if (authoredItems.length) {
5331
+ authoredItems.forEach((el) => {
5332
+ const sw = el.querySelector(".c-donut__swatch");
5333
+ const lbl = el.querySelector("span:last-child");
5334
+ const text = lbl ? lbl.textContent : el.textContent;
5335
+ const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
5336
+ items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? sw.style.background : undefined });
5337
+ });
5338
+ // remove authored items from DOM (they will be regenerated below)
5339
+ authoredItems.forEach((el) => el.remove());
5340
+ } else {
5341
+ const iAttr = this.getAttribute("items");
5342
+ if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
5343
+ }
5344
+ const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
5345
+ const total = values.reduce((a, b) => a + b, 0) || 1;
5346
+ const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
5347
+ const shedRing = brownoutLevel >= 3;
5348
+ if (!shedRing) {
5349
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5350
+ svg.setAttribute("class", "c-donut__ring");
5351
+ svg.setAttribute("viewBox", "0 0 32 32");
5352
+ let offset = 0;
5353
+ items.forEach((it, i) => {
5354
+ const v = values[i];
5355
+ const pct = v / total;
5356
+ const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5357
+ circle.setAttribute("cx", "16"); circle.setAttribute("cy", "16"); circle.setAttribute("r", "12");
5358
+ circle.setAttribute("fill", "none");
5359
+ circle.setAttribute("stroke", (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")");
5360
+ circle.setAttribute("stroke-width", "6");
5361
+ const circ = 2 * Math.PI * 12;
5362
+ circle.setAttribute("stroke-dasharray", (pct * circ) + " " + (circ - pct * circ));
5363
+ circle.setAttribute("stroke-dashoffset", String(-offset * circ));
5364
+ circle.setAttribute("transform", "rotate(-90 16 16)");
5365
+ svg.appendChild(circle);
5366
+ offset += pct;
5367
+ });
5368
+ // center hole
5369
+ const hole = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5370
+ hole.setAttribute("cx", "16"); hole.setAttribute("cy", "16"); hole.setAttribute("r", "9");
5371
+ hole.setAttribute("fill", "var(--color-surface-0)");
5372
+ svg.appendChild(hole);
5373
+ this.appendChild(svg);
5374
+ }
5375
+ const center = document.createElement("div");
5376
+ center.className = "c-donut__center";
5377
+ center.textContent = this.getAttribute("value") || String(total);
5378
+ this.appendChild(center);
5379
+ // text list
5380
+ const list = document.createElement("div");
5381
+ list.className = "c-donut__list";
5382
+ items.forEach((it, i) => {
5383
+ const row = document.createElement("div");
5384
+ row.className = "c-donut__item";
5385
+ const sw = document.createElement("span");
5386
+ sw.className = "c-donut__swatch";
5387
+ sw.style.background = (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")";
5388
+ row.appendChild(sw);
5389
+ const lbl = document.createElement("span");
5390
+ lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
5391
+ row.appendChild(lbl);
5392
+ list.appendChild(row);
5393
+ });
5394
+ this.appendChild(list);
5395
+ if (!items.length) renderEmpty(this, "donut");
5396
+ }
5397
+ enhance() {}
5398
+ }
5399
+ define("contour-donut", ContourDonut);
5400
+ class ContourTimeSeries extends ContourBase {
5401
+ static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
5402
+ static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
5403
+ render() {
5404
+ this.classList.add("c-time-series");
5405
+ wireStates(this);
5406
+ loadRemote(this, ["values", "points"]);
5407
+ if (renderStates(this, "time-series")) return;
5408
+ Array.from(this.querySelectorAll(".c-time-series__plot, .c-time-series__axis")).forEach((n) => n.remove());
5409
+ let values = [];
5410
+ const vAttr = this.getAttribute("values");
5411
+ if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
5412
+ const max = Math.max(...values, 1);
5413
+ const plot = document.createElement("div");
5414
+ plot.className = "c-time-series__plot";
5415
+ plot.setAttribute("part", "plot");
5416
+ values.forEach((v) => {
5417
+ const bar = document.createElement("div");
5418
+ bar.className = "c-time-series__bar";
5419
+ bar.style.blockSize = ((v / max) * 100) + "%";
5420
+ bar.setAttribute("title", String(v));
5421
+ plot.appendChild(bar);
5422
+ });
5423
+ this.appendChild(plot);
5424
+ if (!values.length) renderEmpty(this, "time-series");
5425
+ }
5426
+ enhance() {}
5427
+ }
5428
+ define("contour-time-series", ContourTimeSeries);
5429
+ class ContourPivot extends ContourBase {
5430
+ static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5431
+ static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
5432
+ render() {
5433
+ this.classList.add("c-pivot");
5434
+ wireStates(this);
5435
+ loadRemote(this, ["data"]);
5436
+ if (renderStates(this, "pivot")) return;
5437
+ Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
5438
+ let data = [];
5439
+ const dAttr = this.getAttribute("data");
5440
+ if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
5441
+ const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
5442
+ const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
5443
+ const table = document.createElement("table");
5444
+ const thead = document.createElement("thead");
5445
+ const hr = document.createElement("tr");
5446
+ const corner = document.createElement("th");
5447
+ corner.textContent = "";
5448
+ hr.appendChild(corner);
5449
+ cols.forEach((c) => { const th = document.createElement("th"); th.textContent = c.trim(); hr.appendChild(th); });
5450
+ thead.appendChild(hr);
5451
+ table.appendChild(thead);
5452
+ const tbody = document.createElement("tbody");
5453
+ rows.forEach((r) => {
5454
+ const tr = document.createElement("tr");
5455
+ const th = document.createElement("th");
5456
+ th.textContent = r.trim();
5457
+ tr.appendChild(th);
5458
+ cols.forEach((c) => {
5459
+ const td = document.createElement("td");
5460
+ const cell = data.find((d) => d.row === r.trim() && d.col === c.trim());
5461
+ td.textContent = cell ? String(cell.value) : "";
5462
+ tr.appendChild(td);
5463
+ });
5464
+ tbody.appendChild(tr);
5465
+ });
5466
+ table.appendChild(tbody);
5467
+ this.appendChild(table);
5468
+ if (!data.length && !rows.length) renderEmpty(this, "pivot");
5469
+ }
5470
+ enhance() {}
5471
+ }
5472
+ define("contour-pivot", ContourPivot);
5473
+ class ContourWidgetState extends ContourBase {
5474
+ static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5475
+ static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
5476
+ render() {
5477
+ this.classList.add("c-widget-state");
5478
+ wireStates(this);
5479
+ loadRemote(this, []);
5480
+ if (renderStates(this, "widget-state")) return;
5481
+ // if no state, render slotted content (already in DOM)
5482
+ }
5483
+ enhance() {}
5484
+ }
5485
+ define("contour-widget-state", ContourWidgetState);
5486
+ class ContourBrownout extends ContourBase {
5487
+ static get observed() { return ["level"]; }
5488
+ static get properties() { return { level: { attribute: "level" } }; }
5489
+ render() {
5490
+ this.classList.add("c-brownout");
5491
+ const level = this.getAttribute("level") || "0";
5492
+ this.dataset.level = level;
5493
+ this.setAttribute("data-level", level);
5494
+ }
5495
+ enhance() {}
5496
+ }
5497
+ define("contour-brownout", ContourBrownout);
4931
5498
  class ContourInstrument extends ContourBase {
4932
5499
  static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
4933
5500
  static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
@@ -4962,21 +5529,31 @@ class ContourInstrument extends ContourBase {
4962
5529
  }
4963
5530
  define("contour-instrument", ContourInstrument);
4964
5531
  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" } }; }
5532
+ static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
5533
+ static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
4967
5534
  render() {
4968
5535
  this.classList.add("c-bivariate");
4969
5536
  const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
4970
5537
  const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
4971
5538
  matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
5539
+ matrix.style.gridTemplateRows = `repeat(${size}, 1fr)`;
4972
5540
  // Slot composition: authored cells win over the generated grid.
4973
5541
  const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate__cell"));
4974
5542
  if (!authored.length) {
4975
5543
  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);
5544
+ let colors = [];
5545
+ const cAttr = this.getAttribute("colors");
5546
+ if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
5547
+ for (let r = 0; r < size; r++) {
5548
+ for (let c = 0; c < size; c++) {
5549
+ const cell = document.createElement("div");
5550
+ cell.className = "c-bivariate__cell";
5551
+ // Palette runs from bottom-left (low/low) to top-right (high/high):
5552
+ // reverse the row order so the first palette row sits at the bottom.
5553
+ const srcIndex = (size - 1 - r) * size + c;
5554
+ if (colors[srcIndex]) cell.style.background = colors[srcIndex];
5555
+ matrix.appendChild(cell);
5556
+ }
4980
5557
  }
4981
5558
  }
4982
5559
  const axisX = this.getAttribute("axis-x");
@@ -4998,6 +5575,49 @@ class ContourBivariate extends ContourBase {
4998
5575
  }
4999
5576
  }
5000
5577
  define("contour-bivariate", ContourBivariate);
5578
+ class ContourBivariateLegend extends ContourBase {
5579
+ static get observed() { return ["size", "axis-x", "axis-y", "colors"]; }
5580
+ static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" } }; }
5581
+ render() {
5582
+ this.classList.add("c-bivariate-legend");
5583
+ const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
5584
+ const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
5585
+ matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
5586
+ // Slotted content support: authored cells win over the generated grid.
5587
+ const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
5588
+ if (!authored.length) {
5589
+ matrix.innerHTML = "";
5590
+ let colors = [];
5591
+ const cAttr = this.getAttribute("colors");
5592
+ if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
5593
+ for (let i = 0; i < size * size; i++) {
5594
+ const cell = document.createElement("div");
5595
+ cell.className = "c-bivariate-legend__cell";
5596
+ if (colors[i]) cell.style.background = colors[i];
5597
+ else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
5598
+ matrix.appendChild(cell);
5599
+ }
5600
+ }
5601
+ const axisX = this.getAttribute("axis-x");
5602
+ const ax = this.querySelector(".c-bivariate-legend__axis--x");
5603
+ if (axisX) {
5604
+ 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; });
5605
+ el.textContent = axisX;
5606
+ } else if (ax) {
5607
+ ax.remove();
5608
+ }
5609
+ const axisY = this.getAttribute("axis-y");
5610
+ const ay = this.querySelector(".c-bivariate-legend__axis--y");
5611
+ if (axisY) {
5612
+ 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; });
5613
+ el.textContent = axisY;
5614
+ } else if (ay) {
5615
+ ay.remove();
5616
+ }
5617
+ }
5618
+ enhance() {}
5619
+ }
5620
+ define("contour-bivariate-legend", ContourBivariateLegend);
5001
5621
  class ContourSurvey extends ContourBase {
5002
5622
  static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
5003
5623
  static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
@@ -5107,7 +5727,7 @@ class ContourMetricsFull extends ContourBase {
5107
5727
  }
5108
5728
  define("contour-metrics", ContourMetricsFull);
5109
5729
  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"]; }
5730
+ 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"]; }
5111
5731
  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
5732
  render() {
5113
5733
  this.classList.add("c-legend");
@@ -5146,6 +5766,22 @@ class ContourLegend extends ContourBase {
5146
5766
  sw.className = "c-legend__swatch";
5147
5767
  if (it && it.color) sw.style.background = it.color;
5148
5768
  item.appendChild(sw);
5769
+ // geometry glyph
5770
+ const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
5771
+ if (glyphShape) {
5772
+ const g = document.createElement("span");
5773
+ g.className = "c-legend__glyph";
5774
+ g.setAttribute("part", "glyph");
5775
+ g.textContent = glyphShape === "circle" ? "●" : glyphShape === "square" ? "■" : glyphShape === "triangle" ? "▲" : glyphShape === "diamond" ? "◆" : glyphShape === "star" ? "★" : String(glyphShape);
5776
+ item.appendChild(g);
5777
+ }
5778
+ // threshold break marker
5779
+ if (it && it.break != null) {
5780
+ const b = document.createElement("span");
5781
+ b.className = "c-legend__break";
5782
+ b.textContent = String(it.break);
5783
+ item.appendChild(b);
5784
+ }
5149
5785
  const lbl = document.createElement("span");
5150
5786
  lbl.textContent = label;
5151
5787
  item.appendChild(lbl);
@@ -5196,10 +5832,6 @@ class ContourLegend extends ContourBase {
5196
5832
  enhance() {
5197
5833
  if (this._wiredLegend) return;
5198
5834
  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
5835
  this.addEventListener("click", (e) => {
5204
5836
  const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
5205
5837
  if (!btn || !this.contains(btn)) return;
@@ -5210,6 +5842,44 @@ class ContourLegend extends ContourBase {
5210
5842
  bubbles: true,
5211
5843
  composed: true,
5212
5844
  }));
5845
+ this.dispatchEvent(new CustomEvent("contour:select", {
5846
+ detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), value: btn.dataset.key || btn.textContent.trim() },
5847
+ bubbles: true,
5848
+ composed: true,
5849
+ }));
5850
+ });
5851
+ // emit style-resolved once on enhance
5852
+ try {
5853
+ let parsed = null;
5854
+ try { parsed = JSON.parse(this.getAttribute("items") || "null"); } catch (e) { parsed = this.getAttribute("items"); }
5855
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: this.getAttribute("items"), items: parsed }, bubbles: true, composed: true }));
5856
+ } catch (e) {}
5857
+ // break-change delegated
5858
+ this.addEventListener("change", (e) => {
5859
+ const t = e.target;
5860
+ if (t && t.classList && t.classList.contains("c-legend__break-input")) {
5861
+ this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value }, bubbles: true, composed: true }));
5862
+ }
5863
+ });
5864
+ // keyboard nav (listbox)
5865
+ this.addEventListener("keydown", (e) => {
5866
+ const items = Array.from(this.querySelectorAll(".c-legend__item"));
5867
+ if (!items.length) return;
5868
+ const idx = items.indexOf(document.activeElement);
5869
+ if (e.key === "ArrowDown" || e.key === "ArrowRight") {
5870
+ e.preventDefault();
5871
+ const next = items[(idx + 1) % items.length];
5872
+ if (next) next.focus();
5873
+ } else if (e.key === "ArrowUp" || e.key === "ArrowLeft") {
5874
+ e.preventDefault();
5875
+ const prev = items[(idx - 1 + items.length) % items.length];
5876
+ if (prev) prev.focus();
5877
+ } else if (e.key === "Enter" || e.key === " ") {
5878
+ e.preventDefault();
5879
+ if (document.activeElement && document.activeElement.classList.contains("c-legend__item")) {
5880
+ document.activeElement.click();
5881
+ }
5882
+ }
5213
5883
  });
5214
5884
  }
5215
5885
  }
@@ -5244,6 +5914,12 @@ class ContourMeasure extends ContourBase {
5244
5914
  const r = this.querySelector(".c-measure__readout");
5245
5915
  if (r) r.remove();
5246
5916
  }
5917
+ // unit selector
5918
+ let sel = this.querySelector(".c-measure__unit-select");
5919
+ if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; this.appendChild(sel); }
5920
+ ["m","km","mi","ft"].forEach((u) => {
5921
+ if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
5922
+ });
5247
5923
  if (rPoint) {
5248
5924
  const p = this.ensure(".c-measure__point", () => { const el = document.createElement("span"); el.className = "c-measure__point"; return el; });
5249
5925
  p.textContent = rPoint;
@@ -5323,12 +5999,20 @@ class ContourHeatmap extends ContourBase {
5323
5999
  wireStates(this);
5324
6000
  loadRemote(this, "cells");
5325
6001
  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) {
6002
+ // Slotted content support: authored .c-heatmap__cell children take
6003
+ // precedence over the generated grid.
6004
+ const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
6005
+ if (authoredCells.length) {
6006
+ const cols = Math.ceil(Math.sqrt(authoredCells.length));
6007
+ this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
6008
+ this.style.inlineSize = "16rem";
6009
+ } else {
6010
+ Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
6011
+ const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
6012
+ const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
6013
+ this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
6014
+ this.style.inlineSize = "16rem";
6015
+ if (count > 0) {
5332
6016
  let values = [];
5333
6017
  try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
5334
6018
  for (let i = 0; i < count; i++) {
@@ -5342,9 +6026,10 @@ class ContourHeatmap extends ContourBase {
5342
6026
  }
5343
6027
  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
6028
  tip.setAttribute("hidden", "");
5345
- } else {
6029
+ } else if (!authoredCells.length) {
5346
6030
  renderEmpty(this, "heatmap");
5347
6031
  }
6032
+ }
5348
6033
  if (this.hasAttribute("legend")) {
5349
6034
  const leg = this.ensure(".c-heatmap__legend", () => {
5350
6035
  const el = document.createElement("div");
@@ -7749,7 +8434,7 @@ class ContourResizable extends ContourBase {
7749
8434
  this.appendChild(handle);
7750
8435
  this.appendChild(p2);
7751
8436
  }
7752
- const v = this.getAttribute("value");
8437
+ const v = this._splitValue || this.getAttribute("value");
7753
8438
  if (v) {
7754
8439
  const p1 = this.querySelector(".c-resizable__pane");
7755
8440
  if (p1) p1.style.flex = `0 0 ${v}%`;
@@ -7770,7 +8455,7 @@ class ContourResizable extends ContourBase {
7770
8455
  const frac = span > 0 ? Math.min(0.9, Math.max(0.1, pos / span)) : 0.5;
7771
8456
  const p1 = this.querySelector(".c-resizable__pane");
7772
8457
  if (p1) p1.style.flex = `0 0 ${Math.round(frac * 100)}%`;
7773
- this.setAttribute("value", String(Math.round(frac * 100)));
8458
+ this._splitValue = String(Math.round(frac * 100));
7774
8459
  };
7775
8460
  this.addEventListener("pointerdown", (e) => {
7776
8461
  const handle = this.querySelector(".c-resize-handle");
@@ -7787,6 +8472,7 @@ class ContourResizable extends ContourBase {
7787
8472
  const stopResize = (e) => {
7788
8473
  if (!this._resizing) return;
7789
8474
  this._resizing = false;
8475
+ if (this._splitValue) { this.setAttribute("value", this._splitValue); this._splitValue = null; }
7790
8476
  const handle = this.querySelector(".c-resize-handle");
7791
8477
  if (handle) {
7792
8478
  handle.classList.remove("c-resize-handle--dragging");
@@ -8145,6 +8831,22 @@ class ContourMinimap extends ContourBase {
8145
8831
  if (v) v.remove();
8146
8832
  }
8147
8833
  }
8834
+ enhance() {
8835
+ if (this._wiredMinimap) return;
8836
+ this._wiredMinimap = true;
8837
+ let dragging = false;
8838
+ this.addEventListener("pointerdown", (e) => {
8839
+ const vp = this.querySelector(".c-minimap__viewport");
8840
+ if (!vp || !vp.contains(e.target)) return;
8841
+ dragging = true;
8842
+ try { vp.setPointerCapture(e.pointerId); } catch (err) {}
8843
+ });
8844
+ this.addEventListener("pointermove", (e) => {
8845
+ if (!dragging) return;
8846
+ this.dispatchEvent(new CustomEvent("contour:move", { detail: { direction: "drag" }, bubbles: true, composed: true }));
8847
+ });
8848
+ this.addEventListener("pointerup", () => { dragging = false; });
8849
+ }
8148
8850
  }
8149
8851
  define("contour-minimap", ContourMinimap);
8150
8852
  class ContourCoordinate extends ContourBase {
@@ -8160,8 +8862,57 @@ class ContourCoordinate extends ContourBase {
8160
8862
  renderEmpty(this, "coordinate");
8161
8863
  return;
8162
8864
  }
8865
+ const format = this.getAttribute("format") || "decimal";
8866
+ let text = String(value);
8867
+ if (format === "dms") {
8868
+ // simple DMS conversion assuming decimal degrees "lat,lon"
8869
+ const parts = String(value).split(/[,\s]+/).map(Number);
8870
+ if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
8871
+ const toDMS = (d) => {
8872
+ const deg = Math.floor(Math.abs(d));
8873
+ const min = Math.floor((Math.abs(d) - deg) * 60);
8874
+ const sec = (((Math.abs(d) - deg) * 60) - min) * 60;
8875
+ return deg + "°" + min + "'" + sec.toFixed(1) + '"' + (d < 0 ? "S" : "N");
8876
+ };
8877
+ text = toDMS(parts[0]) + " " + toDMS(parts[1]);
8878
+ }
8879
+ } else if (format === "web-mercator") {
8880
+ const parts = String(value).split(/[,\s]+/).map(Number);
8881
+ if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
8882
+ const x = parts[1] * 20037508.34 / 180;
8883
+ const y = Math.log(Math.tan((90 + parts[0]) * Math.PI / 360)) / (Math.PI / 180) * 20037508.34 / 180;
8884
+ text = x.toFixed(2) + ", " + y.toFixed(2);
8885
+ }
8886
+ } else {
8887
+ text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
8888
+ }
8163
8889
  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"));
8890
+ span.textContent = text;
8891
+ // copy button
8892
+ let btn = this.querySelector(".c-coordinate__copy");
8893
+ 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); }
8894
+ btn.onclick = () => {
8895
+ try {
8896
+ if (navigator.clipboard && navigator.clipboard.writeText) {
8897
+ navigator.clipboard.writeText(text).catch(() => { fallbackCopy(text); });
8898
+ } else {
8899
+ fallbackCopy(text);
8900
+ }
8901
+ } catch (e) { fallbackCopy(text); }
8902
+ this.dispatchEvent(new CustomEvent("contour:copy", { detail: { text }, bubbles: true, composed: true }));
8903
+ };
8904
+ function fallbackCopy(t) {
8905
+ try {
8906
+ const ta = document.createElement("textarea");
8907
+ ta.value = t;
8908
+ ta.style.position = "fixed";
8909
+ ta.style.opacity = "0";
8910
+ document.body.appendChild(ta);
8911
+ ta.select();
8912
+ document.execCommand("copy");
8913
+ document.body.removeChild(ta);
8914
+ } catch (e) {}
8915
+ }
8165
8916
  }
8166
8917
  }
8167
8918
  define("contour-coordinate", ContourCoordinate);
@@ -8182,19 +8933,32 @@ class ContourLayerPanel extends ContourBase {
8182
8933
  const l = this.querySelector(".c-layer-panel__label");
8183
8934
  if (l) l.remove();
8184
8935
  }
8185
- if (items) {
8936
+ // Slotted content support: authored .c-layer-panel__item children take
8937
+ // precedence over the JSON `items` attribute.
8938
+ const authoredLayerItems = Array.from(this.querySelectorAll(":scope > .c-layer-panel__item"));
8939
+ // Preserve user-toggled visibility across re-renders (B3-09): a src
8940
+ // reload must not re-check a layer the user un-checked.
8941
+ const savedVisibility = new Map();
8942
+ this.querySelectorAll(".c-layer-panel__item").forEach((el) => {
8943
+ const nm = el.querySelector(".c-layer-panel__name");
8944
+ const tg = el.querySelector(".c-layer-panel__toggle");
8945
+ if (nm && tg) savedVisibility.set(nm.textContent, tg.checked);
8946
+ });
8947
+ let parsed = null;
8948
+ if (authoredLayerItems.length) {
8949
+ parsed = authoredLayerItems.map((el) => {
8950
+ const nm = el.querySelector(".c-layer-panel__name");
8951
+ const tg = el.querySelector(".c-layer-panel__toggle");
8952
+ return { name: nm ? nm.textContent : "", visible: tg ? tg.checked : true };
8953
+ });
8954
+ authoredLayerItems.forEach((el) => el.remove());
8955
+ } else if (items) {
8186
8956
  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
- });
8957
+ parsed = JSON.parse(items);
8196
8958
  Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
8197
- parsed.forEach((it) => {
8959
+ } catch (e) { /* keep existing */ }
8960
+ }
8961
+ if (parsed) { parsed.forEach((it) => {
8198
8962
  const name = typeof it === "string" ? it : (it.name || it.label || "");
8199
8963
  const item = document.createElement("div");
8200
8964
  item.className = "c-layer-panel__item" + (it.dragging ? " c-layer-panel__item--dragging" : "");
@@ -8217,10 +8981,34 @@ class ContourLayerPanel extends ContourBase {
8217
8981
  opacity.setAttribute("aria-label", "Opacity of " + (name || "layer"));
8218
8982
  opacity.value = (typeof it === "object" && it.opacity != null) ? it.opacity : "100";
8219
8983
  item.appendChild(opacity);
8984
+ // rename input (hidden by default, toggled via button)
8985
+ const renameBtn = document.createElement("button");
8986
+ renameBtn.type = "button";
8987
+ renameBtn.className = "c-layer-panel__rename";
8988
+ renameBtn.textContent = "Rename";
8989
+ renameBtn.setAttribute("aria-label", "Rename " + (name || "layer"));
8990
+ item.appendChild(renameBtn);
8991
+ const dupBtn = document.createElement("button");
8992
+ dupBtn.type = "button";
8993
+ dupBtn.className = "c-layer-panel__duplicate";
8994
+ dupBtn.textContent = "Duplicate";
8995
+ dupBtn.setAttribute("aria-label", "Duplicate " + (name || "layer"));
8996
+ item.appendChild(dupBtn);
8997
+ const zoomBtn = document.createElement("button");
8998
+ zoomBtn.type = "button";
8999
+ zoomBtn.className = "c-layer-panel__zoom";
9000
+ zoomBtn.textContent = "Zoom";
9001
+ zoomBtn.setAttribute("aria-label", "Zoom to " + (name || "layer"));
9002
+ item.appendChild(zoomBtn);
9003
+ const projSel = document.createElement("select");
9004
+ projSel.className = "c-layer-panel__projection";
9005
+ projSel.setAttribute("aria-label", "Projection of " + (name || "layer"));
9006
+ ["EPSG:4326","EPSG:3857"].forEach((p) => { const o = document.createElement("option"); o.value = p; o.textContent = p; projSel.appendChild(o); });
9007
+ item.appendChild(projSel);
8220
9008
  this.appendChild(item);
8221
9009
  });
8222
- } catch (e) { /* keep existing */ }
8223
- } else {
9010
+ }
9011
+ if (!parsed && !authoredLayerItems.length && !items) {
8224
9012
  Array.from(this.querySelectorAll(".c-layer-panel__item")).forEach((el) => el.remove());
8225
9013
  renderEmpty(this, "layer-panel");
8226
9014
  }
@@ -8238,13 +9026,35 @@ class ContourLayerPanel extends ContourBase {
8238
9026
  this.dispatchEvent(new CustomEvent("contour:layer-visibility", { bubbles: true, composed: true, detail: { name, visible: e.target.checked } }));
8239
9027
  } else if (e.target.classList.contains("c-layer-panel__opacity")) {
8240
9028
  this.dispatchEvent(new CustomEvent("contour:layer-opacity", { bubbles: true, composed: true, detail: { name, opacity: Number(e.target.value) } }));
9029
+ } else if (e.target.classList.contains("c-layer-panel__projection")) {
9030
+ this.dispatchEvent(new CustomEvent("contour:layer-projection", { bubbles: true, composed: true, detail: { name, projection: e.target.value } }));
9031
+ }
9032
+ });
9033
+ this.addEventListener("click", (e) => {
9034
+ const btn = e.target && e.target.closest ? e.target.closest("button") : null;
9035
+ if (!btn || !this.contains(btn)) return;
9036
+ const item = btn.closest(".c-layer-panel__item");
9037
+ if (!item) return;
9038
+ const name = item.querySelector(".c-layer-panel__name")?.textContent || "";
9039
+ if (btn.classList.contains("c-layer-panel__rename")) {
9040
+ const newName = prompt("Rename layer", name);
9041
+ const trimmed = newName ? newName.trim() : "";
9042
+ if (trimmed && trimmed !== name) {
9043
+ const nm = item.querySelector(".c-layer-panel__name");
9044
+ if (nm) nm.textContent = trimmed;
9045
+ this.dispatchEvent(new CustomEvent("contour:layer-rename", { bubbles: true, composed: true, detail: { name, newName: trimmed } }));
9046
+ }
9047
+ } else if (btn.classList.contains("c-layer-panel__duplicate")) {
9048
+ this.dispatchEvent(new CustomEvent("contour:layer-duplicate", { bubbles: true, composed: true, detail: { name } }));
9049
+ } else if (btn.classList.contains("c-layer-panel__zoom")) {
9050
+ this.dispatchEvent(new CustomEvent("contour:layer-zoom", { bubbles: true, composed: true, detail: { name } }));
8241
9051
  }
8242
9052
  });
8243
9053
  }
8244
9054
  }
8245
9055
  define("contour-layer-panel", ContourLayerPanel);
8246
9056
  class ContourTimeSlider extends ContourBase {
8247
- static get observed() { return ["label", "value"]; }
9057
+ static get observed() { return ["label", "value", "loop", "speed"]; }
8248
9058
  static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
8249
9059
  render() {
8250
9060
  this.classList.add("c-time-slider");
@@ -8285,10 +9095,15 @@ class ContourTimeSlider extends ContourBase {
8285
9095
  const track = this.querySelector(".c-time-slider__track");
8286
9096
  if (!track) { stop(); return; }
8287
9097
  const max = Number(track.max) || 100;
8288
- const next = Math.min(max, (Number(track.value) || 0) + 1);
9098
+ const loop = this.hasAttribute("loop");
9099
+ let next = (Number(track.value) || 0) + 1;
9100
+ if (next > max) {
9101
+ if (loop) next = 0;
9102
+ else next = max;
9103
+ }
8289
9104
  track.value = String(next);
8290
9105
  this.dispatchEvent(new CustomEvent("contour:time-change", { detail: { value: String(next) }, bubbles: true, composed: true }));
8291
- if (next >= max) {
9106
+ if (!loop && next >= max) {
8292
9107
  stop();
8293
9108
  const btn = this.querySelector(".c-time-slider__play");
8294
9109
  if (btn) {
@@ -8309,13 +9124,19 @@ class ContourTimeSlider extends ContourBase {
8309
9124
  if (use) use.setAttribute("href", playing ? "#i-pause" : "#i-play");
8310
9125
  if (playing) {
8311
9126
  stop();
8312
- timer = setInterval(step, 1000);
9127
+ const speed = parseFloat(this.getAttribute("speed") || "1") || 1;
9128
+ const delay = Math.max(100, 1000 / speed);
9129
+ timer = setInterval(step, delay);
8313
9130
  } else {
8314
9131
  stop();
8315
9132
  }
8316
9133
  });
8317
9134
  onDispose(this, stop);
8318
9135
  }
9136
+ disconnectedCallback() {
9137
+ super.disconnectedCallback();
9138
+ this._wiredTimeSlider = false;
9139
+ }
8319
9140
  }
8320
9141
  define("contour-time-slider", ContourTimeSlider);
8321
9142
  class ContourHexbin extends ContourBase {
@@ -8336,9 +9157,18 @@ class ContourHexbin extends ContourBase {
8336
9157
  if (renderStates(this, "hexbin")) return;
8337
9158
  const cells = remoteData(this, "cells");
8338
9159
  const effectiveCells = cells || (this._remoteData && this._remoteData.cells ? JSON.stringify(this._remoteData.cells) : null);
8339
- if (effectiveCells) {
9160
+ // Slotted content support: authored .c-hexbin__cell children take
9161
+ // precedence over the JSON `cells` attribute.
9162
+ const authoredCells = Array.from(this.querySelectorAll(":scope > .c-hexbin__cell"));
9163
+ let parsed = null;
9164
+ if (authoredCells.length) {
9165
+ parsed = authoredCells.map((el) => el.textContent || el.getAttribute("title") || "");
9166
+ authoredCells.forEach((el) => el.remove());
9167
+ } else if (effectiveCells) {
9168
+ try { parsed = JSON.parse(effectiveCells); } catch (e) { parsed = null; }
9169
+ }
9170
+ if (parsed) {
8340
9171
  try {
8341
- const parsed = JSON.parse(effectiveCells);
8342
9172
  Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
8343
9173
  const cols = Math.ceil(Math.sqrt(parsed.length || 1));
8344
9174
  this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
@@ -8354,7 +9184,7 @@ class ContourHexbin extends ContourBase {
8354
9184
  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
9185
  tip.setAttribute("hidden", "");
8356
9186
  } catch (e) { /* keep existing */ }
8357
- } else {
9187
+ } else if (!parsed) {
8358
9188
  Array.from(this.querySelectorAll(".c-hexbin__cell")).forEach((n) => n.remove());
8359
9189
  renderEmpty(this, "hexbin");
8360
9190
  }
@@ -8384,9 +9214,18 @@ class ContourFlowMap extends ContourBase {
8384
9214
  if (renderStates(this, "flow-map")) return;
8385
9215
  const nodes = remoteData(this, "nodes");
8386
9216
  const effectiveNodes = nodes || (this._remoteData && this._remoteData.nodes ? JSON.stringify(this._remoteData.nodes) : null);
8387
- if (effectiveNodes) {
9217
+ // Slotted content support: authored .c-flow-map__node children take
9218
+ // precedence over the JSON `nodes` attribute.
9219
+ const authoredNodes = Array.from(this.querySelectorAll(":scope > .c-flow-map__node"));
9220
+ let parsed = null;
9221
+ if (authoredNodes.length) {
9222
+ parsed = authoredNodes.map((el) => el.textContent || el.getAttribute("title") || "");
9223
+ authoredNodes.forEach((el) => el.remove());
9224
+ } else if (effectiveNodes) {
9225
+ try { parsed = JSON.parse(effectiveNodes); } catch (e) { parsed = null; }
9226
+ }
9227
+ if (parsed) {
8388
9228
  try {
8389
- const parsed = JSON.parse(effectiveNodes);
8390
9229
  Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
8391
9230
  parsed.forEach((n, i) => {
8392
9231
  const node = document.createElement("span");
@@ -8399,7 +9238,7 @@ class ContourFlowMap extends ContourBase {
8399
9238
  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
9239
  tip.setAttribute("hidden", "");
8401
9240
  } catch (e) { /* keep existing */ }
8402
- } else {
9241
+ } else if (!parsed) {
8403
9242
  Array.from(this.querySelectorAll(".c-flow-map__node")).forEach((n) => n.remove());
8404
9243
  renderEmpty(this, "flow-map");
8405
9244
  }
@@ -8437,9 +9276,18 @@ class ContourIsochrone extends ContourBase {
8437
9276
  if (renderStates(this, "isochrone")) return;
8438
9277
  const rings = remoteData(this, "rings");
8439
9278
  const effectiveRings = rings || (this._remoteData && this._remoteData.rings ? JSON.stringify(this._remoteData.rings) : null);
8440
- if (effectiveRings) {
9279
+ // Slotted content support: authored .c-isochrone__ring children take
9280
+ // precedence over the JSON `rings` attribute.
9281
+ const authoredRings = Array.from(this.querySelectorAll(":scope > .c-isochrone__ring"));
9282
+ let parsed = null;
9283
+ if (authoredRings.length) {
9284
+ parsed = authoredRings.map((el) => el.textContent || el.getAttribute("title") || "");
9285
+ authoredRings.forEach((el) => el.remove());
9286
+ } else if (effectiveRings) {
9287
+ try { parsed = JSON.parse(effectiveRings); } catch (e) { parsed = null; }
9288
+ }
9289
+ if (parsed) {
8441
9290
  try {
8442
- const parsed = JSON.parse(effectiveRings);
8443
9291
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
8444
9292
  parsed.forEach((r, i) => {
8445
9293
  const ring = document.createElement("span");
@@ -8451,7 +9299,7 @@ class ContourIsochrone extends ContourBase {
8451
9299
  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
9300
  tip.setAttribute("hidden", "");
8453
9301
  } catch (e) { /* keep existing */ }
8454
- } else {
9302
+ } else if (!parsed) {
8455
9303
  Array.from(this.querySelectorAll(".c-isochrone__ring")).forEach((n) => n.remove());
8456
9304
  renderEmpty(this, "isochrone");
8457
9305
  }
@@ -11033,8 +11881,8 @@ class ContourStyleSwitcher extends ContourBase {
11033
11881
  define("contour-style-switcher", ContourStyleSwitcher);
11034
11882
 
11035
11883
  class ContourStylePanel extends ContourBase {
11036
- static get observed() { return ["title", "layers"]; }
11037
- static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" } }; }
11884
+ static get observed() { return ["title", "layers", "classification", "palette", "breaks", "opacity"]; }
11885
+ static get properties() { return { title: { attribute: "title" }, layers: { attribute: "layers" }, classification: { attribute: "classification" }, palette: { attribute: "palette" }, breaks: { attribute: "breaks" }, opacity: { attribute: "opacity" } }; }
11038
11886
  render() {
11039
11887
  this.classList.add("c-style-panel");
11040
11888
  const title = this.getAttribute("title");
@@ -11044,11 +11892,28 @@ class ContourStylePanel extends ContourBase {
11044
11892
  }
11045
11893
  const layers = this.getAttribute("layers");
11046
11894
  const body = this.ensure(".c-style-panel__body", () => { const el = document.createElement("div"); el.className = "c-style-panel__body"; return el; });
11047
- if (layers) {
11895
+ // Slotted content support: authored .c-style-panel__row children take
11896
+ // precedence over the JSON `layers` attribute.
11897
+ const authoredRows = Array.from(this.querySelectorAll(":scope > .c-style-panel__row"));
11898
+ let parsed = null;
11899
+ if (authoredRows.length) {
11900
+ parsed = authoredRows.map((row) => ({
11901
+ name: row.querySelector(".c-style-panel__name")?.textContent || "",
11902
+ color: row.querySelector(".c-style-panel__color")?.value,
11903
+ classification: row.querySelector(".c-style-panel__classification")?.value,
11904
+ palette: row.querySelector(".c-style-panel__palette")?.value,
11905
+ breaks: row.querySelector(".c-style-panel__breaks")?.value,
11906
+ opacity: row.querySelector(".c-style-panel__opacity")?.value,
11907
+ }));
11908
+ authoredRows.forEach((row) => row.remove());
11909
+ } else if (layers) {
11048
11910
  try {
11049
- const parsed = JSON.parse(layers);
11050
- body.innerHTML = "";
11051
- parsed.forEach((l) => {
11911
+ parsed = JSON.parse(layers);
11912
+ } catch (e) { parsed = null; }
11913
+ }
11914
+ if (parsed) {
11915
+ body.innerHTML = "";
11916
+ parsed.forEach((l) => {
11052
11917
  const row = document.createElement("div");
11053
11918
  row.className = "c-style-panel__row";
11054
11919
  const name = document.createElement("span");
@@ -11060,11 +11925,63 @@ class ContourStylePanel extends ContourBase {
11060
11925
  input.className = "c-style-panel__color";
11061
11926
  if (typeof l === "object" && l.color) input.value = l.color;
11062
11927
  row.appendChild(input);
11928
+ // classification method selector
11929
+ const clsSel = document.createElement("select");
11930
+ clsSel.className = "c-style-panel__classification";
11931
+ ["equal","quantile","jenks","manual"].forEach((m) => { const o = document.createElement("option"); o.value = m; o.textContent = m; clsSel.appendChild(o); });
11932
+ if (typeof l === "object" && l.classification) clsSel.value = l.classification;
11933
+ row.appendChild(clsSel);
11934
+ // palette picker
11935
+ const pal = document.createElement("input");
11936
+ pal.type = "text";
11937
+ pal.className = "c-style-panel__palette";
11938
+ pal.placeholder = "palette";
11939
+ if (typeof l === "object" && l.palette) pal.value = l.palette;
11940
+ row.appendChild(pal);
11941
+ // breaks editor
11942
+ const breaks = document.createElement("input");
11943
+ breaks.type = "text";
11944
+ breaks.className = "c-style-panel__breaks";
11945
+ breaks.placeholder = "breaks";
11946
+ if (typeof l === "object" && l.breaks) breaks.value = (Array.isArray(l.breaks) ? l.breaks.join(",") : l.breaks);
11947
+ row.appendChild(breaks);
11948
+ // opacity control
11949
+ const op = document.createElement("input");
11950
+ op.type = "range";
11951
+ op.className = "c-style-panel__opacity";
11952
+ op.min = "0"; op.max = "100";
11953
+ op.value = (typeof l === "object" && l.opacity != null) ? l.opacity : "100";
11954
+ row.appendChild(op);
11063
11955
  body.appendChild(row);
11064
11956
  });
11065
- } catch (e) { /* keep existing */ }
11066
11957
  }
11067
11958
  }
11959
+ enhance() {
11960
+ if (this._wiredStylePanel) return;
11961
+ this._wiredStylePanel = true;
11962
+ this.addEventListener("change", (e) => {
11963
+ const t = e.target;
11964
+ if (!t || !this.contains(t)) return;
11965
+ const row = t.closest(".c-style-panel__row");
11966
+ const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
11967
+ if (t.classList.contains("c-style-panel__color")) {
11968
+ this.dispatchEvent(new CustomEvent("contour:style-resolved", { detail: { value: t.value, layer: name, property: "color" }, bubbles: true, composed: true }));
11969
+ } else if (t.classList.contains("c-style-panel__classification")) {
11970
+ this.dispatchEvent(new CustomEvent("contour:break-change", { detail: { value: t.value, layer: name }, bubbles: true, composed: true }));
11971
+ } else if (t.classList.contains("c-style-panel__opacity")) {
11972
+ this.dispatchEvent(new CustomEvent("contour:layer-opacity", { detail: { name, opacity: Number(t.value) }, bubbles: true, composed: true }));
11973
+ }
11974
+ });
11975
+ this.addEventListener("input", (e) => {
11976
+ const t = e.target;
11977
+ if (!t || !this.contains(t)) return;
11978
+ if (t.classList.contains("c-style-panel__palette") || t.classList.contains("c-style-panel__breaks")) {
11979
+ const row = t.closest(".c-style-panel__row");
11980
+ const name = row ? (row.querySelector(".c-style-panel__name")?.textContent || "") : "";
11981
+ 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 }));
11982
+ }
11983
+ });
11984
+ }
11068
11985
  }
11069
11986
  define("contour-style-panel", ContourStylePanel);
11070
11987
 
@@ -12088,11 +13005,30 @@ class ContourTreeGrid extends ContourBase {
12088
13005
  if (ADOPTED && key === ADOPTED_KEY) return ADOPTED;
12089
13006
  ADOPTED_KEY = key;
12090
13007
  ADOPTED = [];
13008
+ // Collect every rule a sheet carries, descending into @imported sheets,
13009
+ // because adoptedStyleSheets cannot hold @import rules (the platform
13010
+ // rejects them) and the imported sheets are not separate top-level entries
13011
+ // in document.styleSheets. Skipping them would hand the shadow root an
13012
+ // empty sheet.
13013
+ const collect = (sheet, out) => {
13014
+ let rules;
13015
+ try { rules = sheet.cssRules; } catch (e) { return; }
13016
+ if (!rules) return;
13017
+ for (const r of rules) {
13018
+ if (r instanceof CSSImportRule) {
13019
+ if (r.styleSheet) collect(r.styleSheet, out);
13020
+ } else {
13021
+ try { out.push(r.cssText); } catch (e) { /* unreadable */ }
13022
+ }
13023
+ }
13024
+ };
12091
13025
  for (const sheet of document.styleSheets) {
12092
13026
  try {
12093
13027
  if (sheet.href && new URL(sheet.href).origin === location.origin) {
13028
+ const collected = [];
13029
+ collect(sheet, collected);
12094
13030
  const built = new CSSStyleSheet();
12095
- built.replaceSync(Array.from(sheet.cssRules, (r) => r.cssText).join("\n"));
13031
+ if (collected.length) built.replaceSync(collected.join("\n"));
12096
13032
  ADOPTED.push(built);
12097
13033
  }
12098
13034
  } catch (e) { /* cross-origin or unreadable */ }
@@ -12318,6 +13254,14 @@ connectedCallback() {
12318
13254
  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
13255
  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
13256
  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>`);
13257
+ shadow("contour-shadow-brownout", `<div class="c-brownout" part="brownout" data-level="0"><slot></slot></div>`);
13258
+ shadow("contour-shadow-widget-state", `<div class="c-widget-state" part="widget-state"><slot></slot></div>`);
13259
+ 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>`);
13260
+ shadow("contour-shadow-axis", `<div class="c-axis" part="axis"><slot></slot></div>`);
13261
+ shadow("contour-shadow-brush", `<div class="c-brush" part="brush"><div class="c-brush__selection" part="selection"></div></div>`);
13262
+ shadow("contour-shadow-stacked-bar", `<div class="c-stacked-bar" part="bar"><slot></slot></div>`);
13263
+ shadow("contour-shadow-category", `<div class="c-category" part="category" role="listbox"><slot></slot></div>`);
13264
+ 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
13265
  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
13266
  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
13267
  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 +13284,7 @@ connectedCallback() {
12340
13284
  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
13285
  shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
12342
13286
  shadow("contour-shadow-bivariate", `<div class="c-bivariate" part="bivariate"><div class="c-bivariate__matrix" part="matrix"><slot></slot></div></div>`);
13287
+ 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
13288
  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
13289
  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
13290
  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>`);