contour-ds 1.1.2 → 1.7.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 (74) hide show
  1. package/README.md +30 -2
  2. package/dist/agent-rules.json +5 -1
  3. package/dist/build-manifest.json +94 -93
  4. package/dist/contour-wc.esm.js +4443 -534
  5. package/dist/contour-wc.esm.min.js +1 -1
  6. package/dist/contour-wc.js +4441 -528
  7. package/dist/contour-wc.min.js +1 -1
  8. package/dist/contour.components.json +4054 -171
  9. package/dist/contour.css +1325 -565
  10. package/dist/contour.d.ts +119 -62
  11. package/dist/contour.esm.js +23 -0
  12. package/dist/contour.esm.min.js +1 -1
  13. package/dist/contour.js +23 -0
  14. package/dist/contour.min.css +1 -1
  15. package/dist/contour.min.js +1 -1
  16. package/dist/contour.tokens.json +47 -2
  17. package/dist/docs/actions.md +6 -2
  18. package/dist/docs/affordances.md +19 -3
  19. package/dist/docs/apireference.md +30 -0
  20. package/dist/docs/colour.md +2 -2
  21. package/dist/docs/componentindex.md +39 -0
  22. package/dist/docs/data.md +38 -3
  23. package/dist/docs/docs.md +6 -2
  24. package/dist/docs/feedback.md +13 -3
  25. package/dist/docs/field.md +7 -2
  26. package/dist/docs/forms.md +35 -3
  27. package/dist/docs/index.json +44 -75
  28. package/dist/docs/install.md +4 -2
  29. package/dist/docs/landing.md +3 -2
  30. package/dist/docs/mapengine.md +9 -3
  31. package/dist/docs/motion.md +5 -2
  32. package/dist/docs/navigation.md +10 -3
  33. package/dist/docs/overlays.md +26 -3
  34. package/dist/docs/overview.md +2 -2
  35. package/dist/docs/patterns.md +38 -3
  36. package/dist/docs/playground.md +5 -2
  37. package/dist/docs/principles.md +2 -2
  38. package/dist/docs/recipes.md +7 -3
  39. package/dist/docs/space.md +2 -2
  40. package/dist/docs/status.md +19 -3
  41. package/dist/docs/surfaces.md +7 -3
  42. package/dist/docs/theming.md +5 -2
  43. package/dist/docs/type.md +2 -2
  44. package/dist/docs/webcomponents.md +26 -7
  45. package/dist/map-chrome.mapbox.css +4 -4
  46. package/dist/map-chrome.maplibre.css +4 -4
  47. package/dist/registry/items/contour-core.json +2 -2
  48. package/dist/registry/items/contour-data.json +2 -2
  49. package/dist/registry/items/contour-docs.json +2 -2
  50. package/dist/registry/items/contour-landing.json +2 -2
  51. package/dist/registry/registry.json +8 -8
  52. package/dist/surfaces/contour-core.min.css +1 -1
  53. package/dist/surfaces/contour-data.min.css +1 -1
  54. package/dist/surfaces/contour-docs.min.css +1 -1
  55. package/dist/surfaces/contour-landing.min.css +1 -1
  56. package/dist/wc/behaviours.mjs +69 -11
  57. package/dist/wc/content.mjs +163 -8
  58. package/dist/wc/core.mjs +177 -36
  59. package/dist/wc/dashboard.mjs +69 -4
  60. package/dist/wc/data.mjs +933 -128
  61. package/dist/wc/docs.mjs +118 -0
  62. package/dist/wc/feedback.mjs +75 -13
  63. package/dist/wc/forms.mjs +371 -34
  64. package/dist/wc/index.mjs +31 -3
  65. package/dist/wc/interaction.mjs +11 -6
  66. package/dist/wc/map.mjs +142 -38
  67. package/dist/wc/misc.mjs +29 -1
  68. package/dist/wc/navigation.mjs +424 -75
  69. package/dist/wc/registration.mjs +8 -4
  70. package/dist/wc/shadow.mjs +29 -12
  71. package/dist/wc/states.mjs +15 -0
  72. package/dist/wc/svg.mjs +10 -0
  73. package/dist/wc/ui.mjs +1767 -129
  74. package/package.json +39 -6
package/dist/wc/data.mjs CHANGED
@@ -1,6 +1,10 @@
1
1
  import { ContourBase, define, onDispose, formatValue, contourId } from './core.mjs';
2
2
  import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport } from './states.mjs';
3
3
  import { donutSlices, barRects, smoothPath, polylinePoints } from './svg.mjs';
4
+ /**
5
+ * Readout: web component wrapper.
6
+ * Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `format`, `locale`.
7
+ */
4
8
  class ContourReadout extends ContourBase {
5
9
  static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "format", "locale"]; }
6
10
  static get properties() { return { rows: { attribute: "rows" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
@@ -25,7 +29,7 @@ class ContourReadout extends ContourBase {
25
29
  const val = document.createElement("span");
26
30
  val.className = "c-readout__value" + (r.primary ? " c-readout__value--primary" : "") + (r.accent ? " c-readout__value--accent" : "") + (r.coord ? " c-readout__value--coord" : "");
27
31
  val.setAttribute("aria-live", "polite");
28
- val.textContent = formatValue(r.value || r[1], this.getAttribute("format"), this.getAttribute("locale"));
32
+ val.textContent = formatValue(r.value || r[1], this.getAttribute("format"), this.getAttribute("locale"), (r.unit !== undefined ? r.unit : this.getAttribute("unit")));
29
33
  row.appendChild(key);
30
34
  row.appendChild(val);
31
35
  if (r.order) {
@@ -43,6 +47,10 @@ class ContourReadout extends ContourBase {
43
47
  }
44
48
  }
45
49
  define("contour-readout", ContourReadout);
50
+ /**
51
+ * Kpi: web component wrapper.
52
+ * Attributes: `value`, `label`, `delta`, `direction`, `note`, `variant`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `thresholds`, `threshold`, `sparkline`, `polarity`.
53
+ */
46
54
  class ContourKpi extends ContourBase {
47
55
  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"]; }
48
56
  static get properties() {
@@ -61,7 +69,7 @@ class ContourKpi extends ContourBase {
61
69
  if (variant) this.classList.add("c-kpi--" + variant);
62
70
  if (value) {
63
71
  const v = this.ensure(".c-kpi__value", () => { const el = document.createElement("div"); el.className = "c-kpi__value"; el.setAttribute("aria-live", "polite"); return el; });
64
- v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
72
+ v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
65
73
  } else {
66
74
  const v = this.querySelector(".c-kpi__value");
67
75
  if (v) v.remove();
@@ -142,7 +150,12 @@ class ContourKpi extends ContourBase {
142
150
  }
143
151
  }
144
152
  define("contour-kpi", ContourKpi);
153
+ /**
154
+ * Table: web component wrapper.
155
+ * Attributes: `columns`, `rows`, `page`, `page-size`, `sort`, `sort-dir`, `virtual`, `empty`, `loading`, `error`, `retry`, `skeleton`, `persist`.
156
+ */
145
157
  class ContourTable extends ContourBase {
158
+ static get updateMode() { return "keyed"; }
146
159
  static get observed() { return ["columns", "rows", "page", "page-size", "sort", "sort-dir", "virtual", "empty", "loading", "error", "retry", "skeleton", "persist"]; }
147
160
  static get properties() { return { columns: { attribute: "columns" }, rows: { attribute: "rows" }, page: { attribute: "page", type: Number }, pageSize: { attribute: "page-size", type: Number } }; }
148
161
  _cellValue(cell) {
@@ -159,6 +172,8 @@ class ContourTable extends ContourBase {
159
172
  return String(av).localeCompare(String(bv), undefined, { numeric: true });
160
173
  }
161
174
  render() {
175
+ this.setAttribute("role", "region");
176
+ this.setAttribute("aria-label", "Table");
162
177
  // The host is not a <table>, so it carries no table rule. The scroller the
163
178
  // reflow contract requires is a real block element inside it.
164
179
  const columns = this.getAttribute("columns");
@@ -440,7 +455,32 @@ class ContourTable extends ContourBase {
440
455
  });
441
456
  const tbody = table.querySelector("tbody");
442
457
  tbody.innerHTML = "";
443
- if (pageData.length === 0) {
458
+ const useVirtual = this.hasAttribute("virtual") && !usePaging && pageData.length > 100;
459
+ const rowHeight = 36;
460
+ const windowSize = 30;
461
+ const overscan = 10;
462
+ let windowStart = 0;
463
+ let visibleData = pageData;
464
+ if (useVirtual) {
465
+ const maxStart = Math.max(0, pageData.length - windowSize);
466
+ windowStart = Math.min(maxStart, Math.max(0, Math.floor(wrap.scrollTop / rowHeight) - overscan));
467
+ visibleData = pageData.slice(windowStart, windowStart + windowSize + overscan * 2);
468
+ table.setAttribute("aria-rowcount", String(pageData.length + 1));
469
+ } else {
470
+ table.removeAttribute("aria-rowcount");
471
+ }
472
+ const addSpacer = (height) => {
473
+ const tr = document.createElement("tr");
474
+ tr.setAttribute("aria-hidden", "true");
475
+ const td = document.createElement("td");
476
+ td.colSpan = cols.length;
477
+ td.style.blockSize = `${height}px`;
478
+ td.style.padding = "0";
479
+ tr.appendChild(td);
480
+ tbody.appendChild(tr);
481
+ };
482
+ if (useVirtual) addSpacer(windowStart * rowHeight);
483
+ if (visibleData.length === 0) {
444
484
  const tr = document.createElement("tr");
445
485
  const td = document.createElement("td");
446
486
  td.colSpan = cols.length;
@@ -450,8 +490,10 @@ class ContourTable extends ContourBase {
450
490
  tr.appendChild(td);
451
491
  tbody.appendChild(tr);
452
492
  } else {
453
- pageData.forEach((row, ri) => {
493
+ visibleData.forEach((row, ri) => {
454
494
  const tr = document.createElement("tr");
495
+ tr.dataset.rowIndex = String(windowStart + ri);
496
+ tr.setAttribute("tabindex", "0");
455
497
  cols.forEach((c, ci) => {
456
498
  const isSelect = (typeof c === "object" && c !== null && c.select);
457
499
  const td = document.createElement("td");
@@ -459,8 +501,8 @@ class ContourTable extends ContourBase {
459
501
  const cb = document.createElement("input");
460
502
  cb.type = "checkbox";
461
503
  cb.className = "c-table__row-select";
462
- cb.dataset.rowIndex = String(ri);
463
- if (this._selectedRows && this._selectedRows.has(ri)) cb.checked = true;
504
+ cb.dataset.rowIndex = String(windowStart + ri);
505
+ if (this._selectedRows && this._selectedRows.has(windowStart + ri)) cb.checked = true;
464
506
  td.appendChild(cb);
465
507
  } else {
466
508
  td.textContent = this._cellValue(row[ci]);
@@ -470,21 +512,17 @@ class ContourTable extends ContourBase {
470
512
  tbody.appendChild(tr);
471
513
  });
472
514
  }
515
+ if (useVirtual) addSpacer(Math.max(0, pageData.length - windowStart - visibleData.length) * rowHeight);
473
516
  if (table.parentNode !== wrap) {
474
517
  wrap.innerHTML = "";
475
518
  wrap.appendChild(table);
476
519
  }
477
520
  if (wrap.parentNode !== this) this.appendChild(wrap);
478
- // Optional virtualization: native content-visibility windowing for
479
- // large datasets, without a JS scroll handler. Opt-in via `virtual`.
521
+ // Optional fixed-row DOM windowing for large datasets. Opt-in via `virtual`.
480
522
  if (this.hasAttribute("virtual")) {
481
523
  wrap.style.maxHeight = wrap.style.maxHeight || "24rem";
482
524
  wrap.style.overflow = "auto";
483
525
  table.classList.add("c-table--virtual");
484
- Array.from(tbody.querySelectorAll("tr")).forEach((tr) => {
485
- tr.style.contentVisibility = "auto";
486
- tr.style.containIntrinsicSize = "auto 2rem";
487
- });
488
526
  } else {
489
527
  wrap.style.maxHeight = "";
490
528
  wrap.style.overflow = "";
@@ -585,6 +623,12 @@ class ContourTable extends ContourBase {
585
623
  this._filters[idx] = inp.value;
586
624
  this.requestRender();
587
625
  });
626
+ this.addEventListener("scroll", (e) => {
627
+ if (!this.hasAttribute("virtual") || !e.target || !e.target.classList || !e.target.classList.contains("c-table-wrap")) return;
628
+ if (this._tableVirtualRaf) return;
629
+ const run = () => { this._tableVirtualRaf = 0; this.requestRender(); };
630
+ this._tableVirtualRaf = typeof requestAnimationFrame === "function" ? requestAnimationFrame(run) : setTimeout(run, 16);
631
+ }, true);
588
632
  // Row selection (F-09): track checked rows and emit contour:select.
589
633
  this._selectedRows = this._selectedRows || new Set();
590
634
  this.addEventListener("change", (e) => {
@@ -604,12 +648,54 @@ class ContourTable extends ContourBase {
604
648
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows: Array.from(this._selectedRows) } }));
605
649
  }
606
650
  });
651
+ // Map-linked table (CARTO-inspired): emit contour:hover on row hover so a
652
+ // consumer can highlight/zoom the corresponding feature on the map.
653
+ // Contour stays engine-agnostic: it only announces the row.
654
+ this.addEventListener("mouseover", (e) => {
655
+ const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
656
+ if (!tr || !this.contains(tr)) return;
657
+ const idx = Number(tr.dataset.rowIndex);
658
+ if (!Number.isFinite(idx)) return;
659
+ if (this._hoveredRow === idx) return;
660
+ this._hoveredRow = idx;
661
+ this.dispatchEvent(new CustomEvent("contour:hover", { bubbles: true, composed: true, detail: { row: idx } }));
662
+ });
663
+ this.addEventListener("mouseout", (e) => {
664
+ const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
665
+ if (!tr || !this.contains(tr)) return;
666
+ const related = e.relatedTarget && e.relatedTarget.closest ? e.relatedTarget.closest("tbody tr") : null;
667
+ if (related === tr) return;
668
+ this._hoveredRow = null;
669
+ this.dispatchEvent(new CustomEvent("contour:leave", { bubbles: true, composed: true, detail: {} }));
670
+ });
671
+ this.addEventListener("keydown", (e) => {
672
+ if (e.key !== "Enter" && e.key !== " ") return;
673
+ const tr = e.target && e.target.closest ? e.target.closest("tbody tr") : null;
674
+ if (!tr || !this.contains(tr)) return;
675
+ e.preventDefault();
676
+ const idx = Number(tr.dataset.rowIndex);
677
+ if (!Number.isFinite(idx)) return;
678
+ this.dispatchEvent(new CustomEvent("contour:activate", { bubbles: true, composed: true, detail: { row: idx } }));
679
+ });
607
680
  }
608
681
  }
609
682
  define("contour-table", ContourTable);
683
+ class ContourDataTable extends ContourTable {
684
+ render() {
685
+ super.render();
686
+ this.classList.add("c-data-table");
687
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Data table");
688
+ }
689
+ }
690
+ define("contour-data-table", ContourDataTable);
691
+ /**
692
+ * Chart: web component wrapper.
693
+ * Attributes: `series`, `axis`, `empty`, `loading`, `error`, `retry`, `skeleton`, `zoomable`, `data-table`, `brush`, `brush-min`, `brush-max`, `brush-start`, `brush-end`.
694
+ */
610
695
  class ContourChart extends ContourBase {
611
- static get observed() { return ["series", "axis", "empty", "loading", "error", "retry", "skeleton", "zoomable"]; }
612
- static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, zoomable: { attribute: "zoomable", type: Boolean } }; }
696
+ static get updateMode() { return "keyed"; }
697
+ static get observed() { return ["series", "axis", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note"]; }
698
+ static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" } }; }
613
699
  render() {
614
700
  this.classList.add("c-chart");
615
701
  if (!this.hasAttribute("role")) this.setAttribute("role", "img");
@@ -689,8 +775,9 @@ class ContourChart extends ContourBase {
689
775
  }
690
776
  const series = this.getAttribute("series");
691
777
  if (series) {
778
+ let parsed = null;
692
779
  try {
693
- const parsed = JSON.parse(series);
780
+ parsed = JSON.parse(series);
694
781
  const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
695
782
  plot.innerHTML = "";
696
783
  // Structured series: an item may carry `values` plus a `type`
@@ -713,6 +800,8 @@ const series = this.getAttribute("series");
713
800
  path.style.setProperty("--c", color);
714
801
  path.setAttribute("d", sl.path);
715
802
  path.setAttribute("title", String(s.values[si]));
803
+ path.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[si]));
804
+ path.setAttribute("role", "img");
716
805
  svg.appendChild(path);
717
806
  });
718
807
  plot.appendChild(svg);
@@ -731,13 +820,48 @@ const series = this.getAttribute("series");
731
820
  rect.setAttribute("width", r.width);
732
821
  rect.setAttribute("height", r.height);
733
822
  rect.setAttribute("title", String(s.values[ri]));
734
- rect.setAttribute("aria-label", String(s.values[ri]));
823
+ rect.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[ri]));
735
824
  rect.setAttribute("tabindex", "0");
736
825
  rect.setAttribute("role", "button");
737
826
  rect.dataset.index = String(ri);
738
827
  svg.appendChild(rect);
739
828
  });
740
829
  plot.appendChild(svg);
830
+ } else if (s.type === "scatter") {
831
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
832
+ svg.setAttribute("viewBox", "0 0 300 120");
833
+ svg.setAttribute("preserveAspectRatio", "none");
834
+ svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
835
+ const pts = (Array.isArray(s.values) ? s.values : []).map((v) => {
836
+ if (Array.isArray(v)) return { x: Number(v[0]) || 0, y: Number(v[1]) || 0 };
837
+ return { x: Number(v && v.x) || 0, y: Number(v && v.y) || 0 };
838
+ });
839
+ const xs = pts.map((p) => p.x);
840
+ const ys = pts.map((p) => p.y);
841
+ const minX = xs.length ? Math.min.apply(null, xs) : 0;
842
+ const maxX = xs.length ? Math.max.apply(null, xs) : 1;
843
+ const minY = ys.length ? Math.min.apply(null, ys) : 0;
844
+ const maxY = ys.length ? Math.max.apply(null, ys) : 1;
845
+ const xRange = (maxX - minX) || 1;
846
+ const yRange = (maxY - minY) || 1;
847
+ pts.forEach((p, pi) => {
848
+ const circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
849
+ circle.setAttribute("class", "c-chart__point");
850
+ circle.setAttribute("data-series", String(i + 1));
851
+ circle.setAttribute("data-index", String(pi));
852
+ circle.style.setProperty("--c", color);
853
+ const cx = ((p.x - minX) / xRange) * 300;
854
+ const cy = 120 - ((p.y - minY) / yRange) * 120;
855
+ circle.setAttribute("cx", cx.toFixed(2));
856
+ circle.setAttribute("cy", cy.toFixed(2));
857
+ circle.setAttribute("r", "3");
858
+ circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
859
+ circle.setAttribute("role", "button");
860
+ circle.setAttribute("title", p.x + ", " + p.y);
861
+ circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + p.x + ", " + p.y);
862
+ svg.appendChild(circle);
863
+ });
864
+ plot.appendChild(svg);
741
865
  } else {
742
866
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
743
867
  svg.setAttribute("viewBox", "0 0 300 120");
@@ -763,7 +887,7 @@ const series = this.getAttribute("series");
763
887
  circle.setAttribute("tabindex", pi === 0 ? "0" : "-1");
764
888
  circle.setAttribute("role", "button");
765
889
  circle.setAttribute("title", String(s.values[pi]));
766
- circle.setAttribute("aria-label", String(s.values[pi]));
890
+ circle.setAttribute("aria-label", "Series " + (i + 1) + ": " + String(s.values[pi]));
767
891
  svg.appendChild(circle);
768
892
  });
769
893
  plot.appendChild(svg);
@@ -789,6 +913,69 @@ const series = this.getAttribute("series");
789
913
  // Styled tooltip element (positioned via --chart-tip-*).
790
914
  const tip = this.ensure(".c-chart__tooltip", () => { const el = document.createElement("div"); el.className = "c-chart__tooltip"; el.setAttribute("role", "tooltip"); el.setAttribute("hidden", ""); return el; });
791
915
  tip.setAttribute("hidden", "");
916
+ // Accessible data-table fallback (R12-18): opt-in via `data-table`
917
+ // attribute. Renders a visually-hidden table of the series values so
918
+ // screen readers and no-JS consumers can read the data behind the
919
+ // graphic. The graphic remains the primary presentation.
920
+ if (this.hasAttribute("data-table")) {
921
+ let table = this.querySelector(".c-chart__data-table");
922
+ if (!table) {
923
+ table = document.createElement("table");
924
+ table.className = "c-chart__data-table visually-hidden";
925
+ this.appendChild(table);
926
+ }
927
+ table.innerHTML = "";
928
+ const thead = document.createElement("thead");
929
+ const hr = document.createElement("tr");
930
+ const h = document.createElement("th");
931
+ h.textContent = "Series";
932
+ hr.appendChild(h);
933
+ const maxLen = parsed.reduce((m, s) => Math.max(m, Array.isArray(s.values) ? s.values.length : (Array.isArray(s) ? s.length : 0)), 0);
934
+ for (let i = 0; i < maxLen; i++) {
935
+ const th = document.createElement("th");
936
+ th.textContent = "Value " + (i + 1);
937
+ hr.appendChild(th);
938
+ }
939
+ thead.appendChild(hr);
940
+ table.appendChild(thead);
941
+ const tbody = document.createElement("tbody");
942
+ parsed.forEach((s, si) => {
943
+ const vals = Array.isArray(s.values) ? s.values : (Array.isArray(s) ? s : []);
944
+ const tr = document.createElement("tr");
945
+ const td0 = document.createElement("td");
946
+ td0.textContent = s.label || ("Series " + (si + 1));
947
+ tr.appendChild(td0);
948
+ for (let i = 0; i < maxLen; i++) {
949
+ const td = document.createElement("td");
950
+ td.textContent = vals[i] != null ? String(vals[i]) : "";
951
+ tr.appendChild(td);
952
+ }
953
+ tbody.appendChild(tr);
954
+ });
955
+ table.appendChild(tbody);
956
+ } else {
957
+ const old = this.querySelector(".c-chart__data-table");
958
+ if (old) old.remove();
959
+ }
960
+ if (this.hasAttribute("brush")) {
961
+ const brush = this.ensure("contour-brush", () => document.createElement("contour-brush"));
962
+ brush.setAttribute("min", this.getAttribute("brush-min") || "0");
963
+ brush.setAttribute("max", this.getAttribute("brush-max") || "100");
964
+ brush.setAttribute("start", this.getAttribute("brush-start") || this.getAttribute("brush-min") || "0");
965
+ brush.setAttribute("end", this.getAttribute("brush-end") || this.getAttribute("brush-max") || "100");
966
+ if (brush.previousElementSibling !== plot) this.appendChild(brush);
967
+ } else {
968
+ const brush = this.querySelector("contour-brush");
969
+ if (brush) brush.remove();
970
+ }
971
+ const note = this.getAttribute("note");
972
+ let noteEl = this.querySelector(".c-chart__note");
973
+ if (note) {
974
+ if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-chart__note"; this.appendChild(noteEl); }
975
+ noteEl.textContent = note;
976
+ } else if (noteEl) {
977
+ noteEl.remove();
978
+ }
792
979
  } else {
793
980
  const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
794
981
  plot.innerHTML = "";
@@ -800,6 +987,14 @@ const series = this.getAttribute("series");
800
987
  empty.style.height = "100%";
801
988
  empty.style.color = "var(--color-text-muted)";
802
989
  plot.appendChild(empty);
990
+ const note = this.getAttribute("note");
991
+ let noteEl2 = this.querySelector(".c-chart__note");
992
+ if (note) {
993
+ if (!noteEl2) { noteEl2 = document.createElement("div"); noteEl2.className = "c-chart__note"; this.appendChild(noteEl2); }
994
+ noteEl2.textContent = note;
995
+ } else if (noteEl2) {
996
+ noteEl2.remove();
997
+ }
803
998
  }
804
999
  }
805
1000
  enhance() {
@@ -820,6 +1015,14 @@ const series = this.getAttribute("series");
820
1015
  }
821
1016
  });
822
1017
  });
1018
+ this.addEventListener("contour:brush-end", (e) => {
1019
+ if (!this.hasAttribute("brush") || !e.target || !e.target.matches("contour-brush")) return;
1020
+ this.dispatchEvent(new CustomEvent("contour:select", {
1021
+ bubbles: true,
1022
+ composed: true,
1023
+ detail: e.detail,
1024
+ }));
1025
+ });
823
1026
  // Zoom/pan (F-10 deferred): wheel to zoom, drag to pan, double-click to reset.
824
1027
  if (this.hasAttribute("zoomable")) {
825
1028
  let zoom = 1, panX = 0, panY = 0;
@@ -841,13 +1044,16 @@ const series = this.getAttribute("series");
841
1044
  dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
842
1045
  this.style.cursor = "grabbing";
843
1046
  });
844
- window.addEventListener("mousemove", (e) => {
1047
+ const onMove = (e) => {
845
1048
  if (!dragging) return;
846
1049
  panX = startPanX + (e.clientX - startX);
847
1050
  panY = startPanY + (e.clientY - startY);
848
1051
  apply();
849
- });
850
- window.addEventListener("mouseup", () => { if (dragging) { dragging = false; this.style.cursor = ""; } });
1052
+ };
1053
+ const onUp = () => { if (dragging) { dragging = false; this.style.cursor = ""; } };
1054
+ window.addEventListener("mousemove", onMove);
1055
+ window.addEventListener("mouseup", onUp);
1056
+ onDispose(this, () => { window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
851
1057
  this.addEventListener("dblclick", () => { zoom = 1; panX = 0; panY = 0; apply(); });
852
1058
  }
853
1059
  // Tooltip: show on hover of a mark.
@@ -978,11 +1184,17 @@ const series = this.getAttribute("series");
978
1184
  }
979
1185
  }
980
1186
  define("contour-chart", ContourChart);
1187
+ /**
1188
+ * Comparison: web component wrapper.
1189
+ * Attributes: `divider`, `value`, `before`, `after`.
1190
+ */
981
1191
  class ContourComparison extends ContourBase {
982
1192
  static get observed() { return ["divider", "value", "before", "after"]; }
983
1193
  static get properties() { return { divider: { attribute: "divider" }, value: { attribute: "value" }, before: { attribute: "before" }, after: { attribute: "after" } }; }
984
1194
  render() {
985
1195
  this.classList.add("c-comparison");
1196
+ this.setAttribute("role", "group");
1197
+ this.setAttribute("aria-label", "Comparison");
986
1198
  if (!this.style.blockSize) this.style.blockSize = "12rem";
987
1199
  this.style.setProperty("--comparison-pos", (this.getAttribute("value") || "50") + "%");
988
1200
  // Ensure two panes exist.
@@ -1033,6 +1245,7 @@ class ContourComparison extends ContourBase {
1033
1245
  setPos(pct);
1034
1246
  };
1035
1247
  const onUp = () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); };
1248
+ onDispose(this, () => { dragging = false; window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
1036
1249
  this.addEventListener("mousedown", (e) => {
1037
1250
  const d = divider();
1038
1251
  if (!d || !d.contains(e.target)) return;
@@ -1051,11 +1264,19 @@ class ContourComparison extends ContourBase {
1051
1264
  }
1052
1265
  }
1053
1266
  define("contour-comparison", ContourComparison);
1267
+ /**
1268
+ * Streaming Chart: web component wrapper.
1269
+ * Attributes: `line`, `dot`, `interval`, `pause`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1270
+ */
1054
1271
  class ContourStreamingChart extends ContourBase {
1272
+ static get updateMode() { return "keyed"; }
1055
1273
  static get observed() { return ["line", "dot", "interval", "pause", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1056
1274
  static get properties() { return { line: { attribute: "line" }, dot: { attribute: "dot" }, interval: { attribute: "interval", type: Number }, pause: { attribute: "pause", type: Boolean }, src: { attribute: "src" } }; }
1057
1275
  render() {
1058
1276
  this.classList.add("c-streaming-chart");
1277
+ this.setAttribute("role", "img");
1278
+ this.setAttribute("aria-label", "Streaming chart");
1279
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
1059
1280
  wireStates(this);
1060
1281
  loadRemote(this, "line");
1061
1282
  if (renderStates(this, "streaming-chart")) return;
@@ -1112,7 +1333,7 @@ class ContourStreamingChart extends ContourBase {
1112
1333
  // own 1 s floor so the two cannot disagree.
1113
1334
  const sync = () => {
1114
1335
  const seconds = parseFloat(this.getAttribute("interval") || "");
1115
- const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && this._viewVisible !== false;
1336
+ const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false;
1116
1337
  if (want === this._streamRunning) return;
1117
1338
  this._streamRunning = want;
1118
1339
  if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; }
@@ -1144,9 +1365,25 @@ class ContourStreamingChart extends ContourBase {
1144
1365
  this._wiredStream = true;
1145
1366
  this._streamFrame = 0;
1146
1367
  onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } });
1368
+ // Keyboard: Space/Enter toggles pause (BY-08 keyboard contract).
1369
+ // Uses an internal flag so the toggle does not re-enter render.
1370
+ this._streamPausedByUser = false;
1371
+ this.addEventListener("keydown", (e) => {
1372
+ if (e.key === " " || e.key === "Enter") {
1373
+ e.preventDefault();
1374
+ this._streamPausedByUser = !this._streamPausedByUser;
1375
+ if (this._streamPausedByUser) this.setAttribute("data-user-paused", "");
1376
+ else this.removeAttribute("data-user-paused");
1377
+ sync();
1378
+ }
1379
+ });
1147
1380
  }
1148
1381
  }
1149
1382
  define("contour-streaming-chart", ContourStreamingChart);
1383
+ /**
1384
+ * Meter: web component wrapper.
1385
+ * Attributes: `value`, `label`, `variant`, `min`, `max`, `low`, `high`, `optimum`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1386
+ */
1150
1387
  class ContourMeter extends ContourBase {
1151
1388
  static get observed() { return ["value", "label", "variant", "min", "max", "low", "high", "optimum", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1152
1389
  static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, variant: { attribute: "variant" }, min: { attribute: "min" }, max: { attribute: "max" }, low: { attribute: "low" }, high: { attribute: "high" }, optimum: { attribute: "optimum" }, src: { attribute: "src" } }; }
@@ -1164,11 +1401,13 @@ class ContourMeter extends ContourBase {
1164
1401
  renderEmpty(this, "meter");
1165
1402
  return;
1166
1403
  }
1167
- if (rValue === null) {
1168
- this.style.removeProperty("--meter-value");
1169
- } else {
1170
- this.style.setProperty("--meter-value", rValue);
1171
- }
1404
+ if (rValue === null) {
1405
+ this.style.removeProperty("--meter-value");
1406
+ } else {
1407
+ const num = parseFloat(rValue);
1408
+ if (Number.isFinite(num)) this.style.setProperty("--meter-value", rValue);
1409
+ else this.style.removeProperty("--meter-value");
1410
+ }
1172
1411
  const core = this.ensure(".c-meter__core", () => { const el = document.createElement("span"); el.className = "c-meter__core"; return el; });
1173
1412
  let val = core.querySelector(".c-meter__value");
1174
1413
  if (!val) { val = document.createElement("span"); val.className = "c-meter__value"; core.appendChild(val); }
@@ -1200,6 +1439,10 @@ class ContourMeter extends ContourBase {
1200
1439
  }
1201
1440
  }
1202
1441
  define("contour-meter", ContourMeter);
1442
+ /**
1443
+ * Delta: web component wrapper.
1444
+ * Attributes: `value`, `direction`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1445
+ */
1203
1446
  class ContourDelta extends ContourBase {
1204
1447
  static get observed() { return ["value", "direction", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1205
1448
  static get properties() { return { value: { attribute: "value" }, direction: { attribute: "direction" }, src: { attribute: "src" } }; }
@@ -1228,6 +1471,10 @@ class ContourDelta extends ContourBase {
1228
1471
  }
1229
1472
  }
1230
1473
  define("contour-delta", ContourDelta);
1474
+ /**
1475
+ * Stat: web component wrapper.
1476
+ * Attributes: `value`, `label`, `delta`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1477
+ */
1231
1478
  class ContourStat extends ContourBase {
1232
1479
  static get observed() { return ["value", "label", "delta", "unit", "format", "locale", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1233
1480
  static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, src: { attribute: "src" } }; }
@@ -1241,7 +1488,7 @@ class ContourStat extends ContourBase {
1241
1488
  const delta = this.getAttribute("delta");
1242
1489
  if (value) {
1243
1490
  const v = this.ensure(".c-stat__value", () => { const el = document.createElement("div"); el.className = "c-stat__value"; el.setAttribute("aria-live", "polite"); return el; });
1244
- v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
1491
+ v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
1245
1492
  } else {
1246
1493
  const v = this.querySelector(".c-stat__value");
1247
1494
  if (v) v.remove();
@@ -1278,6 +1525,10 @@ class ContourStat extends ContourBase {
1278
1525
  }
1279
1526
  }
1280
1527
  define("contour-stat", ContourStat);
1528
+ /**
1529
+ * Gauge: web component wrapper.
1530
+ * Attributes: `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`.
1531
+ */
1281
1532
  class ContourGauge extends ContourBase {
1282
1533
  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"]; }
1283
1534
  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" } }; }
@@ -1295,7 +1546,7 @@ class ContourGauge extends ContourBase {
1295
1546
  const showHeader = this.getAttribute("show-header") !== "false";
1296
1547
  const description = this.getAttribute("description");
1297
1548
  const noDataMessage = this.getAttribute("no-data-message") || "No readings in view";
1298
- const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
1549
+ const brownoutLevel = this.brownoutLevel();
1299
1550
  // empty state
1300
1551
  if (!hasValue) {
1301
1552
  if (heading && showHeader) {
@@ -1329,7 +1580,7 @@ class ContourGauge extends ContourBase {
1329
1580
  }
1330
1581
  }
1331
1582
  // dial (unless brownout >= 3)
1332
- const shedDial = brownoutLevel >= 3;
1583
+ const shedDial = this.shed("dial", 3);
1333
1584
  let dial = this.querySelector(".c-gauge__dial");
1334
1585
  if (shedDial) {
1335
1586
  if (dial) dial.remove();
@@ -1370,17 +1621,18 @@ class ContourGauge extends ContourBase {
1370
1621
  dial.appendChild(z);
1371
1622
  }
1372
1623
  }
1373
- // needle
1374
- const angle = ((num - min) / (max - min || 1)) * 180 - 90;
1624
+ // needle (pivot at dial centre 50,90; 0 -> left, 100 -> right)
1625
+ const ratio = (num - min) / (max - min || 1);
1626
+ const angle = Math.PI * (1 - ratio);
1375
1627
  const needle = document.createElementNS("http://www.w3.org/2000/svg", "line");
1376
1628
  needle.setAttribute("class", "c-gauge__needle needle");
1377
- needle.setAttribute("x1", "50"); needle.setAttribute("y1", "50");
1378
- needle.setAttribute("x2", String(50 + 35 * Math.cos(angle * Math.PI / 180)));
1379
- needle.setAttribute("y2", String(50 + 35 * Math.sin(angle * Math.PI / 180)));
1629
+ needle.setAttribute("x1", "50"); needle.setAttribute("y1", "90");
1630
+ needle.setAttribute("x2", String(50 + 35 * Math.cos(angle)));
1631
+ needle.setAttribute("y2", String(90 - 35 * Math.sin(angle)));
1380
1632
  dial.appendChild(needle);
1381
1633
  const hub = document.createElementNS("http://www.w3.org/2000/svg", "circle");
1382
1634
  hub.setAttribute("class", "c-gauge__hub hub");
1383
- hub.setAttribute("cx", "50"); hub.setAttribute("cy", "50"); hub.setAttribute("r", "4");
1635
+ hub.setAttribute("cx", "50"); hub.setAttribute("cy", "90"); hub.setAttribute("r", "4");
1384
1636
  dial.appendChild(hub);
1385
1637
  }
1386
1638
  // value element (meter)
@@ -1427,11 +1679,17 @@ class ContourGauge extends ContourBase {
1427
1679
  enhance() {}
1428
1680
  }
1429
1681
  define("contour-gauge", ContourGauge);
1682
+ /**
1683
+ * Axis: web component wrapper.
1684
+ * Attributes: `orientation`, `values`, `ticks`, `format`, `locale`, `padding`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1685
+ */
1430
1686
  class ContourAxis extends ContourBase {
1431
1687
  static get observed() { return ["orientation", "values", "ticks", "format", "locale", "padding", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1432
1688
  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" } }; }
1433
1689
  render() {
1434
1690
  this.classList.add("c-axis");
1691
+ this.setAttribute("role", "img");
1692
+ this.setAttribute("aria-label", "Axis");
1435
1693
  const orientation = this.getAttribute("orientation") || "horizontal";
1436
1694
  this.classList.toggle("c-axis--horizontal", orientation === "horizontal");
1437
1695
  this.classList.toggle("c-axis--vertical", orientation === "vertical");
@@ -1472,11 +1730,17 @@ class ContourAxis extends ContourBase {
1472
1730
  enhance() {}
1473
1731
  }
1474
1732
  define("contour-axis", ContourAxis);
1733
+ /**
1734
+ * Brush: web component wrapper.
1735
+ * Attributes: `start`, `end`, `min`, `max`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
1736
+ */
1475
1737
  class ContourBrush extends ContourBase {
1476
1738
  static get observed() { return ["start", "end", "min", "max", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1477
1739
  static get properties() { return { start: { attribute: "start" }, end: { attribute: "end" }, min: { attribute: "min" }, max: { attribute: "max" }, src: { attribute: "src" } }; }
1478
1740
  render() {
1479
1741
  this.classList.add("c-brush");
1742
+ this.setAttribute("role", "group");
1743
+ this.setAttribute("aria-label", "Brush selection");
1480
1744
  wireStates(this);
1481
1745
  loadRemote(this, []);
1482
1746
  if (renderStates(this, "brush")) return;
@@ -1502,20 +1766,87 @@ class ContourBrush extends ContourBase {
1502
1766
  enhance() {
1503
1767
  if (this._wiredBrush) return;
1504
1768
  this._wiredBrush = true;
1769
+ let dragging = null;
1770
+ const min = () => parseFloat(this.getAttribute("min") || "0");
1771
+ const max = () => parseFloat(this.getAttribute("max") || "100");
1772
+ const toValue = (clientX) => {
1773
+ const r = this.getBoundingClientRect();
1774
+ const ratio = Math.max(0, Math.min(1, (clientX - r.left) / (r.width || 1)));
1775
+ return min() + ratio * (max() - min());
1776
+ };
1505
1777
  this.addEventListener("pointerdown", (e) => {
1778
+ const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
1779
+ dragging = handle ? (handle.classList.contains("c-brush__handle--start") ? "start" : "end") : "move";
1780
+ try { this.setPointerCapture(e.pointerId); } catch (err) {}
1506
1781
  this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
1507
1782
  });
1783
+ this.addEventListener("pointermove", (e) => {
1784
+ if (!dragging) return;
1785
+ const v = toValue(e.clientX);
1786
+ const mn = min(), mx = max(), range = mx - mn || 1;
1787
+ const sel = this.querySelector(".c-brush__selection");
1788
+ let ns = parseFloat(this.getAttribute("start") || "0");
1789
+ let ne = parseFloat(this.getAttribute("end") || "100");
1790
+ if (dragging === "start") {
1791
+ ns = Math.min(v, ne);
1792
+ } else if (dragging === "end") {
1793
+ ne = Math.max(v, ns);
1794
+ } else {
1795
+ const width = ne - ns;
1796
+ ns = v - width / 2;
1797
+ ne = v + width / 2;
1798
+ if (ns < mn) { ne += mn - ns; ns = mn; }
1799
+ if (ne > mx) { ns -= ne - mx; ne = mx; }
1800
+ }
1801
+ ns = Math.max(mn, Math.min(mx, ns));
1802
+ ne = Math.max(mn, Math.min(mx, ne));
1803
+ // update DOM directly to avoid re-render during drag
1804
+ if (sel) {
1805
+ sel.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
1806
+ sel.style.inlineSize = (((ne - ns) / range) * 100) + "%";
1807
+ }
1808
+ const sh = this.querySelector(".c-brush__handle--start");
1809
+ const eh = this.querySelector(".c-brush__handle--end");
1810
+ if (sh) sh.style.insetInlineStart = (((ns - mn) / range) * 100) + "%";
1811
+ if (eh) eh.style.insetInlineStart = (((ne - mn) / range) * 100) + "%";
1812
+ // stash pending values
1813
+ this._brushPending = { start: ns, end: ne };
1814
+ this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: ns, end: ne, value: ns } }));
1815
+ });
1508
1816
  this.addEventListener("pointerup", (e) => {
1817
+ if (!dragging) return;
1818
+ dragging = null;
1819
+ const p = this._brushPending;
1820
+ if (p) {
1821
+ this.setAttribute("start", String(p.start));
1822
+ this.setAttribute("end", String(p.end));
1823
+ this._brushPending = null;
1824
+ }
1509
1825
  this.dispatchEvent(new CustomEvent("contour:brush-end", { bubbles: true, composed: true, detail: { value: this.getAttribute("end"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
1826
+ this.dispatchEvent(new CustomEvent("contour:brush", { bubbles: true, composed: true, detail: { start: this.getAttribute("start"), end: this.getAttribute("end"), value: this.getAttribute("end") } }));
1827
+ });
1828
+ // Keyboard: Enter/Space emits brush-start/brush-end (WC-P1-08).
1829
+ if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
1830
+ this.addEventListener("keydown", (e) => {
1831
+ if (e.key === "Enter" || e.key === " ") {
1832
+ e.preventDefault();
1833
+ this.dispatchEvent(new CustomEvent("contour:brush-start", { bubbles: true, composed: true, detail: { value: this.getAttribute("start"), start: this.getAttribute("start"), end: this.getAttribute("end") } }));
1834
+ }
1510
1835
  });
1511
1836
  }
1512
1837
  }
1513
1838
  define("contour-brush", ContourBrush);
1839
+ /**
1840
+ * Stacked Bar: web component wrapper.
1841
+ * Attributes: `segments`, `values`, `colors`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `normalize`.
1842
+ */
1514
1843
  class ContourStackedBar extends ContourBase {
1515
1844
  static get observed() { return ["segments", "values", "colors", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "normalize"]; }
1516
1845
  static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, normalize: { attribute: "normalize" } }; }
1517
1846
  render() {
1518
1847
  this.classList.add("c-stacked-bar");
1848
+ this.setAttribute("role", "img");
1849
+ this.setAttribute("aria-label", "Stacked bar");
1519
1850
  wireStates(this);
1520
1851
  loadRemote(this, ["segments", "values"]);
1521
1852
  if (renderStates(this, "stacked-bar")) return;
@@ -1528,7 +1859,7 @@ class ContourStackedBar extends ContourBase {
1528
1859
  segments = authoredSegments.map((el) => ({
1529
1860
  label: el.getAttribute("title") || el.textContent || "",
1530
1861
  value: parseFloat(el.style.inlineSize) || 0,
1531
- color: el.style.background || undefined,
1862
+ color: (el.dataset && el.dataset.color) || el.style.background || undefined,
1532
1863
  }));
1533
1864
  authoredSegments.forEach((el) => el.remove());
1534
1865
  } else {
@@ -1545,6 +1876,7 @@ class ContourStackedBar extends ContourBase {
1545
1876
  el.className = "c-stacked-bar__segment";
1546
1877
  el.style.inlineSize = ((v / denom) * 100) + "%";
1547
1878
  el.style.background = (typeof seg === "object" && seg.color) ? seg.color : "var(--chart-" + ((i % 8) + 1) + ")";
1879
+ el.dataset.color = (typeof seg === "object" && seg.color) ? seg.color : el.style.background;
1548
1880
  el.setAttribute("title", (typeof seg === "object" ? (seg.label || "") : "") + " " + v);
1549
1881
  this.appendChild(el);
1550
1882
  });
@@ -1553,12 +1885,17 @@ class ContourStackedBar extends ContourBase {
1553
1885
  enhance() {}
1554
1886
  }
1555
1887
  define("contour-stacked-bar", ContourStackedBar);
1888
+ /**
1889
+ * Category: web component wrapper.
1890
+ * Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `search`.
1891
+ */
1556
1892
  class ContourCategory extends ContourBase {
1557
- static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search"]; }
1558
- static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" } }; }
1893
+ static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "search", "note", "limit", "sort"]; }
1894
+ static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, search: { attribute: "search" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" } }; }
1559
1895
  render() {
1560
1896
  this.classList.add("c-category");
1561
1897
  this.setAttribute("role", "listbox");
1898
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Category");
1562
1899
  wireStates(this);
1563
1900
  loadRemote(this, ["items"]);
1564
1901
  if (renderStates(this, "category")) return;
@@ -1577,6 +1914,20 @@ class ContourCategory extends ContourBase {
1577
1914
  const iAttr = this.getAttribute("items");
1578
1915
  if (iAttr) { try { items = JSON.parse(iAttr); } catch (e) { items = []; } }
1579
1916
  }
1917
+ // Top-N + sort (CARTO-inspired): optional `limit` and `sort` attributes.
1918
+ const sort = this.getAttribute("sort") || "value-desc";
1919
+ items.sort((a, b) => {
1920
+ const va = (typeof a === "object") ? (a.value || 0) : (Number(a) || 0);
1921
+ const vb = (typeof b === "object") ? (b.value || 0) : (Number(b) || 0);
1922
+ const la = (typeof a === "object") ? (a.label || a.name || "") : String(a);
1923
+ const lb = (typeof b === "object") ? (b.label || b.name || "") : String(b);
1924
+ if (sort === "value-asc") return va - vb;
1925
+ if (sort === "alpha-asc") return String(la).localeCompare(String(lb));
1926
+ if (sort === "alpha-desc") return String(lb).localeCompare(String(la));
1927
+ return vb - va; // value-desc (default)
1928
+ });
1929
+ const limit = parseInt(this.getAttribute("limit") || "0", 10);
1930
+ if (limit > 0) items = items.slice(0, limit);
1580
1931
  const max = items.reduce((m, it) => Math.max(m, (typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
1581
1932
  items.forEach((it, idx) => {
1582
1933
  const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
@@ -1585,6 +1936,7 @@ class ContourCategory extends ContourBase {
1585
1936
  item.className = "c-category__item";
1586
1937
  item.setAttribute("role", "option");
1587
1938
  item.setAttribute("aria-selected", "false");
1939
+ item.setAttribute("tabindex", idx === 0 ? "0" : "-1");
1588
1940
  const lbl = document.createElement("span");
1589
1941
  lbl.className = "c-category__label";
1590
1942
  lbl.textContent = label;
@@ -1603,15 +1955,66 @@ class ContourCategory extends ContourBase {
1603
1955
  this.appendChild(item);
1604
1956
  });
1605
1957
  if (!items.length) renderEmpty(this, "category");
1958
+ const note = this.getAttribute("note");
1959
+ let noteEl = this.querySelector(".c-category__note");
1960
+ if (note) {
1961
+ if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-category__note"; this.appendChild(noteEl); }
1962
+ noteEl.textContent = note;
1963
+ } else if (noteEl) {
1964
+ noteEl.remove();
1965
+ }
1966
+ }
1967
+ enhance() {
1968
+ if (this._wiredCategory) return;
1969
+ this._wiredCategory = true;
1970
+ const items = () => Array.from(this.querySelectorAll(".c-category__item"));
1971
+ const showTip = (e) => {};
1972
+ this.addEventListener("click", (e) => {
1973
+ const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
1974
+ if (!item || !this.contains(item)) return;
1975
+ const all = items();
1976
+ const idx = all.indexOf(item);
1977
+ all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
1978
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
1979
+ });
1980
+ this.addEventListener("keydown", (e) => {
1981
+ const item = e.target && e.target.closest ? e.target.closest(".c-category__item") : null;
1982
+ if (!item || !this.contains(item)) return;
1983
+ const all = items();
1984
+ const idx = all.indexOf(item);
1985
+ if (e.key === "Enter" || e.key === " ") {
1986
+ e.preventDefault();
1987
+ all.forEach((o, i) => o.setAttribute("aria-selected", i === idx ? "true" : "false"));
1988
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, label: item.querySelector(".c-category__label") ? item.querySelector(".c-category__label").textContent : item.textContent.trim() } }));
1989
+ return;
1990
+ }
1991
+ let next = -1;
1992
+ const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
1993
+ if (e.key === "ArrowDown") next = Math.min(idx + 1, all.length - 1);
1994
+ else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
1995
+ else if (e.key === "ArrowRight") next = rtl ? Math.max(idx - 1, 0) : Math.min(idx + 1, all.length - 1);
1996
+ else if (e.key === "ArrowLeft") next = rtl ? Math.min(idx + 1, all.length - 1) : Math.max(idx - 1, 0);
1997
+ else if (e.key === "Home") next = 0;
1998
+ else if (e.key === "End") next = all.length - 1;
1999
+ if (next < 0 || next === idx) return;
2000
+ e.preventDefault();
2001
+ all.forEach((c, i) => c.setAttribute("tabindex", i === next ? "0" : "-1"));
2002
+ try { all[next].focus(); } catch (err) {}
2003
+ });
1606
2004
  }
1607
- enhance() {}
1608
2005
  }
1609
2006
  define("contour-category", ContourCategory);
2007
+ /**
2008
+ * Donut: web component wrapper.
2009
+ * Attributes: `value`, `values`, `items`, `label`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `brownout`, `brownout-level`.
2010
+ */
1610
2011
  class ContourDonut extends ContourBase {
1611
- static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level"]; }
1612
- static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" } }; }
2012
+ static get observed() { return ["value", "values", "items", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "brownout", "brownout-level", "note"]; }
2013
+ static get properties() { return { value: { attribute: "value" }, values: { attribute: "values" }, items: { attribute: "items" }, label: { attribute: "label" }, src: { attribute: "src" }, note: { attribute: "note" } }; }
1613
2014
  render() {
1614
2015
  this.classList.add("c-donut");
2016
+ this.setAttribute("role", "img");
2017
+ this.setAttribute("aria-label", "Donut chart");
1615
2018
  wireStates(this);
1616
2019
  loadRemote(this, ["items", "values"]);
1617
2020
  if (renderStates(this, "donut")) return;
@@ -1627,7 +2030,7 @@ class ContourDonut extends ContourBase {
1627
2030
  const lbl = el.querySelector("span:last-child");
1628
2031
  const text = lbl ? lbl.textContent : el.textContent;
1629
2032
  const match = text.match(/—\s*(\d+(?:\.\d+)?)$/);
1630
- items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? sw.style.background : undefined });
2033
+ items.push({ label: text.replace(/—\s*\d+(?:\.\d+)?$/, "").trim(), value: match ? Number(match[1]) : 0, color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background : undefined });
1631
2034
  });
1632
2035
  // remove authored items from DOM (they will be regenerated below)
1633
2036
  authoredItems.forEach((el) => el.remove());
@@ -1637,8 +2040,8 @@ class ContourDonut extends ContourBase {
1637
2040
  }
1638
2041
  const values = items.map((it) => (typeof it === "object" ? (it.value || 0) : Number(it) || 0));
1639
2042
  const total = values.reduce((a, b) => a + b, 0) || 1;
1640
- const brownoutLevel = parseInt(this.getAttribute("brownout-level") || this.getAttribute("brownout") || "0", 10) || 0;
1641
- const shedRing = brownoutLevel >= 3;
2043
+ const brownoutLevel = this.brownoutLevel();
2044
+ const shedRing = this.shed("ring", 3);
1642
2045
  if (!shedRing) {
1643
2046
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1644
2047
  svg.setAttribute("class", "c-donut__ring");
@@ -1679,6 +2082,7 @@ class ContourDonut extends ContourBase {
1679
2082
  const sw = document.createElement("span");
1680
2083
  sw.className = "c-donut__swatch";
1681
2084
  sw.style.background = (typeof it === "object" && it.color) ? it.color : "var(--chart-" + ((i % 8) + 1) + ")";
2085
+ if (sw.style.background) sw.dataset.color = (typeof it === "object" && it.color) ? it.color : sw.style.background;
1682
2086
  row.appendChild(sw);
1683
2087
  const lbl = document.createElement("span");
1684
2088
  lbl.textContent = (typeof it === "object" ? (it.label || "") : String(it)) + " — " + values[i];
@@ -1687,15 +2091,29 @@ class ContourDonut extends ContourBase {
1687
2091
  });
1688
2092
  this.appendChild(list);
1689
2093
  if (!items.length) renderEmpty(this, "donut");
2094
+ const note = this.getAttribute("note");
2095
+ let noteEl = this.querySelector(".c-donut__note");
2096
+ if (note) {
2097
+ if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-donut__note"; this.appendChild(noteEl); }
2098
+ noteEl.textContent = note;
2099
+ } else if (noteEl) {
2100
+ noteEl.remove();
2101
+ }
1690
2102
  }
1691
2103
  enhance() {}
1692
2104
  }
1693
2105
  define("contour-donut", ContourDonut);
2106
+ /**
2107
+ * Time Series: web component wrapper.
2108
+ * Attributes: `values`, `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `annotations`.
2109
+ */
1694
2110
  class ContourTimeSeries extends ContourBase {
1695
- static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations"]; }
1696
- static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" } }; }
2111
+ static get observed() { return ["values", "points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "annotations", "note", "style"]; }
2112
+ static get properties() { return { values: { attribute: "values" }, points: { attribute: "points" }, src: { attribute: "src" }, annotations: { attribute: "annotations" }, note: { attribute: "note" }, style: { attribute: "style" } }; }
1697
2113
  render() {
1698
2114
  this.classList.add("c-time-series");
2115
+ this.setAttribute("role", "img");
2116
+ this.setAttribute("aria-label", "Time series");
1699
2117
  wireStates(this);
1700
2118
  loadRemote(this, ["values", "points"]);
1701
2119
  if (renderStates(this, "time-series")) return;
@@ -1704,66 +2122,280 @@ class ContourTimeSeries extends ContourBase {
1704
2122
  const vAttr = this.getAttribute("values");
1705
2123
  if (vAttr) { try { values = JSON.parse(vAttr); } catch (e) { values = vAttr.split(",").map(Number); } }
1706
2124
  const max = Math.max(...values, 1);
2125
+ const min = Math.min(...values, 0);
2126
+ const style = this.getAttribute("style") || "bar";
1707
2127
  const plot = document.createElement("div");
1708
2128
  plot.className = "c-time-series__plot";
1709
2129
  plot.setAttribute("part", "plot");
1710
- values.forEach((v) => {
1711
- const bar = document.createElement("div");
1712
- bar.className = "c-time-series__bar";
1713
- bar.style.blockSize = ((v / max) * 100) + "%";
1714
- bar.setAttribute("title", String(v));
1715
- plot.appendChild(bar);
1716
- });
2130
+ if (style === "line") {
2131
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2132
+ svg.setAttribute("viewBox", "0 0 300 120");
2133
+ svg.setAttribute("preserveAspectRatio", "none");
2134
+ svg.style.cssText = "position: absolute; inset: 0; width: 100%; height: 100%";
2135
+ const range = (max - min) || 1;
2136
+ const n = values.length || 1;
2137
+ const pts = values.map((v, i) => {
2138
+ const x = (i / Math.max(1, n - 1)) * 300;
2139
+ const y = 120 - ((v - min) / range) * 120;
2140
+ return x.toFixed(2) + "," + y.toFixed(2);
2141
+ }).join(" ");
2142
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
2143
+ path.setAttribute("class", "c-time-series__line");
2144
+ path.setAttribute("d", "M " + pts.replace(/ /g, " L "));
2145
+ path.style.stroke = "var(--chart-1)";
2146
+ path.style.fill = "none";
2147
+ path.style.strokeWidth = "2";
2148
+ svg.appendChild(path);
2149
+ // point markers
2150
+ values.forEach((v, i) => {
2151
+ const x = (i / Math.max(1, n - 1)) * 300;
2152
+ const y = 120 - ((v - min) / range) * 120;
2153
+ const c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
2154
+ c.setAttribute("class", "c-time-series__point");
2155
+ c.setAttribute("cx", x.toFixed(2));
2156
+ c.setAttribute("cy", y.toFixed(2));
2157
+ c.setAttribute("r", "3");
2158
+ c.setAttribute("tabindex", i === 0 ? "0" : "-1");
2159
+ c.setAttribute("role", "button");
2160
+ c.setAttribute("title", String(v));
2161
+ c.setAttribute("aria-label", "Value " + v);
2162
+ svg.appendChild(c);
2163
+ });
2164
+ plot.appendChild(svg);
2165
+ } else {
2166
+ values.forEach((v, i) => {
2167
+ const bar = document.createElement("div");
2168
+ bar.className = "c-time-series__bar";
2169
+ bar.style.blockSize = ((v / max) * 100) + "%";
2170
+ bar.setAttribute("title", String(v));
2171
+ bar.setAttribute("role", "img");
2172
+ bar.setAttribute("aria-label", "Value " + v);
2173
+ bar.setAttribute("tabindex", i === 0 ? "0" : "-1");
2174
+ plot.appendChild(bar);
2175
+ });
2176
+ }
1717
2177
  this.appendChild(plot);
1718
2178
  if (!values.length) renderEmpty(this, "time-series");
2179
+ const note = this.getAttribute("note");
2180
+ let noteEl = this.querySelector(".c-time-series__note");
2181
+ if (note) {
2182
+ if (!noteEl) { noteEl = document.createElement("div"); noteEl.className = "c-time-series__note"; this.appendChild(noteEl); }
2183
+ noteEl.textContent = note;
2184
+ } else if (noteEl) {
2185
+ noteEl.remove();
2186
+ }
2187
+ }
2188
+ enhance() {
2189
+ if (this._wiredTimeSeries) return;
2190
+ this._wiredTimeSeries = true;
2191
+ const bars = () => Array.from(this.querySelectorAll(".c-time-series__bar"));
2192
+ this.addEventListener("click", (e) => {
2193
+ const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
2194
+ if (!bar || !this.contains(bar)) return;
2195
+ const idx = bars().indexOf(bar);
2196
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: bar.getAttribute("title") } }));
2197
+ });
2198
+ this.addEventListener("keydown", (e) => {
2199
+ const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
2200
+ if (!bar || !this.contains(bar)) return;
2201
+ const all = bars();
2202
+ const idx = all.indexOf(bar);
2203
+ if (e.key === "Enter" || e.key === " ") {
2204
+ e.preventDefault();
2205
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx, value: bar.getAttribute("title") } }));
2206
+ return;
2207
+ }
2208
+ let next = -1;
2209
+ if (e.key === "ArrowRight" || e.key === "ArrowDown") next = Math.min(idx + 1, all.length - 1);
2210
+ else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = Math.max(idx - 1, 0);
2211
+ else if (e.key === "Home") next = 0;
2212
+ else if (e.key === "End") next = all.length - 1;
2213
+ if (next < 0 || next === idx) return;
2214
+ e.preventDefault();
2215
+ all.forEach((b, i) => b.setAttribute("tabindex", i === next ? "0" : "-1"));
2216
+ try { all[next].focus(); } catch (err) {}
2217
+ });
2218
+ // focus tooltip
2219
+ this.addEventListener("focusin", (e) => {
2220
+ const bar = e.target && e.target.closest ? e.target.closest(".c-time-series__bar") : null;
2221
+ if (bar && this.contains(bar)) {
2222
+ const tip = this.querySelector(".c-time-series__tooltip");
2223
+ if (tip) { tip.textContent = bar.getAttribute("title"); tip.removeAttribute("hidden"); }
2224
+ }
2225
+ });
2226
+ this.addEventListener("focusout", (e) => {
2227
+ const tip = this.querySelector(".c-time-series__tooltip");
2228
+ if (tip && !this.contains(e.relatedTarget)) tip.setAttribute("hidden", "");
2229
+ });
1719
2230
  }
1720
- enhance() {}
1721
2231
  }
1722
2232
  define("contour-time-series", ContourTimeSeries);
2233
+ /**
2234
+ * Pivot: web component wrapper.
2235
+ * Attributes: `rows`, `columns`, `values`, `data`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2236
+ */
1723
2237
  class ContourPivot extends ContourBase {
1724
2238
  static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1725
- static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" } }; }
2239
+ static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, src: { attribute: "src" }, filter: { attribute: "filter" }, aggregate: { attribute: "aggregate" } }; }
2240
+ _aggregateFn(name) {
2241
+ const n = (name || "sum").toLowerCase();
2242
+ if (n === "avg" || n === "average" || n === "mean") return (vals) => vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : 0;
2243
+ if (n === "count") return (vals) => vals.length;
2244
+ if (n === "min") return (vals) => vals.length ? Math.min(...vals) : 0;
2245
+ if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
2246
+ return (vals) => vals.reduce((a,b)=>a+b,0);
2247
+ }
1726
2248
  render() {
1727
2249
  this.classList.add("c-pivot");
1728
2250
  wireStates(this);
1729
2251
  loadRemote(this, ["data"]);
1730
2252
  if (renderStates(this, "pivot")) return;
1731
- Array.from(this.querySelectorAll("table")).forEach((n) => n.remove());
2253
+ Array.from(this.querySelectorAll("table, .c-pivot__toolbar")).forEach((n) => n.remove());
1732
2254
  let data = [];
1733
2255
  const dAttr = this.getAttribute("data");
1734
2256
  if (dAttr) { try { data = JSON.parse(dAttr); } catch (e) { data = []; } }
1735
- const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",") : [];
1736
- const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",") : [];
2257
+ const rows = this.getAttribute("rows") ? this.getAttribute("rows").split(",").map((s)=>s.trim()).filter(Boolean) : [];
2258
+ const cols = this.getAttribute("columns") ? this.getAttribute("columns").split(",").map((s)=>s.trim()).filter(Boolean) : [];
2259
+ const aggName = this.getAttribute("aggregate") || "sum";
2260
+ const aggFn = this._aggregateFn(aggName);
2261
+ const filterQ = (this.getAttribute("filter") || "").toLowerCase().trim();
2262
+ // Toolbar: filter input + aggregate selector.
2263
+ const toolbar = document.createElement("div");
2264
+ toolbar.className = "c-pivot__toolbar";
2265
+ toolbar.style.display = "flex";
2266
+ toolbar.style.gap = "0.5rem";
2267
+ toolbar.style.marginBlockEnd = "0.5rem";
2268
+ const filterInput = document.createElement("input");
2269
+ filterInput.type = "search";
2270
+ filterInput.className = "c-input c-pivot__filter";
2271
+ filterInput.placeholder = "Filter…";
2272
+ filterInput.value = this.getAttribute("filter") || "";
2273
+ filterInput.setAttribute("aria-label", "Filter pivot");
2274
+ const aggSelect = document.createElement("select");
2275
+ aggSelect.className = "c-select c-pivot__aggregate";
2276
+ aggSelect.setAttribute("aria-label", "Aggregation");
2277
+ ["sum","avg","count","min","max"].forEach((a) => {
2278
+ const opt = document.createElement("option");
2279
+ opt.value = a; opt.textContent = a;
2280
+ if (a === aggName) opt.selected = true;
2281
+ aggSelect.appendChild(opt);
2282
+ });
2283
+ toolbar.appendChild(filterInput);
2284
+ toolbar.appendChild(aggSelect);
2285
+ this.appendChild(toolbar);
2286
+ // Filter rows/cols.
2287
+ let visibleRows = rows;
2288
+ let visibleCols = cols;
2289
+ if (filterQ) {
2290
+ visibleRows = rows.filter((r) => r.toLowerCase().includes(filterQ) || data.some((d) => d.row === r && String(d.value).toLowerCase().includes(filterQ)));
2291
+ visibleCols = cols.filter((c) => c.toLowerCase().includes(filterQ) || data.some((d) => d.col === c && String(d.value).toLowerCase().includes(filterQ)));
2292
+ if (!visibleRows.length) visibleRows = rows;
2293
+ if (!visibleCols.length) visibleCols = cols;
2294
+ }
1737
2295
  const table = document.createElement("table");
2296
+ table.setAttribute("role", "grid");
2297
+ table.setAttribute("aria-rowcount", String(visibleRows.length + 1));
2298
+ table.setAttribute("aria-colcount", String(visibleCols.length + 1));
1738
2299
  const thead = document.createElement("thead");
1739
2300
  const hr = document.createElement("tr");
1740
2301
  const corner = document.createElement("th");
1741
2302
  corner.textContent = "";
2303
+ corner.setAttribute("role", "columnheader");
2304
+ corner.setAttribute("aria-label", "Row");
1742
2305
  hr.appendChild(corner);
1743
- cols.forEach((c) => { const th = document.createElement("th"); th.textContent = c.trim(); hr.appendChild(th); });
2306
+ visibleCols.forEach((c) => { const th = document.createElement("th"); th.textContent = c; th.setAttribute("role", "columnheader"); th.setAttribute("tabindex", "0"); hr.appendChild(th); });
1744
2307
  thead.appendChild(hr);
1745
2308
  table.appendChild(thead);
1746
2309
  const tbody = document.createElement("tbody");
1747
- rows.forEach((r) => {
2310
+ visibleRows.forEach((r) => {
1748
2311
  const tr = document.createElement("tr");
2312
+ tr.setAttribute("role", "row");
1749
2313
  const th = document.createElement("th");
1750
- th.textContent = r.trim();
2314
+ th.textContent = r;
2315
+ th.setAttribute("role", "rowheader");
2316
+ th.setAttribute("tabindex", "0");
1751
2317
  tr.appendChild(th);
1752
- cols.forEach((c) => {
2318
+ visibleCols.forEach((c) => {
1753
2319
  const td = document.createElement("td");
1754
- const cell = data.find((d) => d.row === r.trim() && d.col === c.trim());
1755
- td.textContent = cell ? String(cell.value) : "";
2320
+ td.setAttribute("role", "gridcell");
2321
+ td.setAttribute("tabindex", "0");
2322
+ const cellData = data.filter((d) => d.row === r && d.col === c);
2323
+ const vals = cellData.map((d) => Number(d.value)).filter((n) => Number.isFinite(n));
2324
+ if (cellData.length && vals.length === cellData.length && vals.length) {
2325
+ const v = aggFn(vals);
2326
+ td.textContent = Number.isInteger(v) ? String(v) : v.toFixed(2);
2327
+ } else if (cellData.length) {
2328
+ td.textContent = cellData.map((d) => d.value).join(", ");
2329
+ } else {
2330
+ td.textContent = "";
2331
+ }
2332
+ if (!td.textContent.trim()) td.setAttribute("aria-label", "Empty");
1756
2333
  tr.appendChild(td);
1757
2334
  });
1758
2335
  tbody.appendChild(tr);
1759
2336
  });
1760
2337
  table.appendChild(tbody);
1761
2338
  this.appendChild(table);
1762
- if (!data.length && !rows.length) renderEmpty(this, "pivot");
2339
+ if (!data.length && !rows.length && !cols.length) renderEmpty(this, "pivot");
2340
+ }
2341
+ enhance() {
2342
+ if (this._wiredPivot) return;
2343
+ this._wiredPivot = true;
2344
+ this.addEventListener("click", (e) => {
2345
+ const th = e.target && e.target.closest ? e.target.closest("th") : null;
2346
+ const td = e.target && e.target.closest ? e.target.closest("td") : null;
2347
+ const filterInput = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
2348
+ const aggSelect = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
2349
+ if (filterInput) return;
2350
+ if (aggSelect) return;
2351
+ if (th && this.contains(th) && th.parentElement && th.parentElement.parentElement && th.parentElement.parentElement.tagName === "THEAD") {
2352
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: th.textContent.trim() } }));
2353
+ return;
2354
+ }
2355
+ if (td && this.contains(td)) {
2356
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { value: td.textContent } }));
2357
+ }
2358
+ });
2359
+ this.addEventListener("input", (e) => {
2360
+ const fi = e.target && e.target.closest ? e.target.closest(".c-pivot__filter") : null;
2361
+ if (fi && this.contains(fi)) {
2362
+ this.setAttribute("filter", fi.value);
2363
+ this.render();
2364
+ this.dispatchEvent(new CustomEvent("contour:filter", { bubbles: true, composed: true, detail: { query: fi.value } }));
2365
+ }
2366
+ });
2367
+ this.addEventListener("change", (e) => {
2368
+ const as = e.target && e.target.closest ? e.target.closest(".c-pivot__aggregate") : null;
2369
+ if (as && this.contains(as)) {
2370
+ this.setAttribute("aggregate", as.value);
2371
+ this.render();
2372
+ this.dispatchEvent(new CustomEvent("contour:aggregate", { bubbles: true, composed: true, detail: { aggregate: as.value } }));
2373
+ }
2374
+ });
2375
+ this.addEventListener("keydown", (e) => {
2376
+ const cell = e.target && e.target.closest ? e.target.closest("th, td") : null;
2377
+ if (!cell || !this.contains(cell)) return;
2378
+ const table = this.querySelector("table");
2379
+ if (!table) return;
2380
+ const rows = Array.from(table.querySelectorAll("tr"));
2381
+ const ri = rows.indexOf(cell.parentElement);
2382
+ const ci = Array.from(cell.parentElement.children).indexOf(cell);
2383
+ let target = null;
2384
+ if (e.key === "ArrowRight") target = cell.parentElement.children[ci + 1];
2385
+ else if (e.key === "ArrowLeft") target = cell.parentElement.children[ci - 1];
2386
+ else if (e.key === "ArrowDown") target = rows[ri + 1] && rows[ri + 1].children[ci];
2387
+ else if (e.key === "ArrowUp") target = rows[ri - 1] && rows[ri - 1].children[ci];
2388
+ else if (e.key === "Home") target = cell.parentElement.children[0];
2389
+ else if (e.key === "End") target = cell.parentElement.children[cell.parentElement.children.length - 1];
2390
+ if (target) { e.preventDefault(); try { target.focus(); } catch (err) {} }
2391
+ });
1763
2392
  }
1764
- enhance() {}
1765
2393
  }
1766
2394
  define("contour-pivot", ContourPivot);
2395
+ /**
2396
+ * Widget State: web component wrapper.
2397
+ * Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2398
+ */
1767
2399
  class ContourWidgetState extends ContourBase {
1768
2400
  static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1769
2401
  static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
@@ -1777,6 +2409,10 @@ class ContourWidgetState extends ContourBase {
1777
2409
  enhance() {}
1778
2410
  }
1779
2411
  define("contour-widget-state", ContourWidgetState);
2412
+ /**
2413
+ * Brownout: web component wrapper.
2414
+ * Attributes: `level`.
2415
+ */
1780
2416
  class ContourBrownout extends ContourBase {
1781
2417
  static get observed() { return ["level"]; }
1782
2418
  static get properties() { return { level: { attribute: "level" } }; }
@@ -1789,6 +2425,10 @@ class ContourBrownout extends ContourBase {
1789
2425
  enhance() {}
1790
2426
  }
1791
2427
  define("contour-brownout", ContourBrownout);
2428
+ /**
2429
+ * Instrument: web component wrapper.
2430
+ * Attributes: `rows`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2431
+ */
1792
2432
  class ContourInstrument extends ContourBase {
1793
2433
  static get observed() { return ["rows", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
1794
2434
  static get properties() { return { rows: { attribute: "rows" }, src: { attribute: "src" } }; }
@@ -1822,11 +2462,17 @@ class ContourInstrument extends ContourBase {
1822
2462
  }
1823
2463
  }
1824
2464
  define("contour-instrument", ContourInstrument);
2465
+ /**
2466
+ * Bivariate: web component wrapper.
2467
+ * Attributes: `size`, `axis-x`, `axis-y`, `colors`, `selected`.
2468
+ */
1825
2469
  class ContourBivariate extends ContourBase {
1826
2470
  static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
1827
2471
  static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
1828
2472
  render() {
1829
2473
  this.classList.add("c-bivariate");
2474
+ this.setAttribute("role", "group");
2475
+ this.setAttribute("aria-label", "Bivariate legend");
1830
2476
  const size = Math.min(12, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
1831
2477
  const matrix = this.ensure(".c-bivariate__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate__matrix"; return el; });
1832
2478
  matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
@@ -1848,7 +2494,7 @@ class ContourBivariate extends ContourBase {
1848
2494
  // Palette runs from bottom-left (low/low) to top-right (high/high):
1849
2495
  // reverse the row order so the first palette row sits at the bottom.
1850
2496
  const srcIndex = (size - 1 - r) * size + c;
1851
- if (colors[srcIndex]) cell.style.background = colors[srcIndex];
2497
+ if (colors[srcIndex]) { cell.style.background = colors[srcIndex]; cell.dataset.color = colors[srcIndex]; }
1852
2498
  matrix.appendChild(cell);
1853
2499
  }
1854
2500
  }
@@ -1926,60 +2572,19 @@ class ContourBivariate extends ContourBase {
1926
2572
  }
1927
2573
  }
1928
2574
  define("contour-bivariate", ContourBivariate);
1929
- class ContourBivariateLegend extends ContourBase {
2575
+ class ContourBivariateLegend extends ContourBivariate {
1930
2576
  static get observed() { return ["size", "axis-x", "axis-y", "colors", "selected"]; }
1931
2577
  static get properties() { return { size: { attribute: "size" }, axisX: { attribute: "axis-x" }, axisY: { attribute: "axis-y" }, colors: { attribute: "colors" }, selected: { attribute: "selected" } }; }
1932
2578
  render() {
2579
+ super.render();
1933
2580
  this.classList.add("c-bivariate-legend");
1934
- const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
1935
- const matrix = this.ensure(".c-bivariate-legend__matrix", () => { const el = document.createElement("div"); el.className = "c-bivariate-legend__matrix"; return el; });
1936
- matrix.style.gridTemplateColumns = `repeat(${size}, 1fr)`;
1937
- // Slotted content support: authored cells win over the generated grid.
1938
- const authored = Array.from(matrix.children).filter((n) => n.classList && n.classList.contains("c-bivariate-legend__cell"));
1939
- if (!authored.length) {
1940
- matrix.innerHTML = "";
1941
- let colors = [];
1942
- const cAttr = this.getAttribute("colors");
1943
- if (cAttr) { try { colors = JSON.parse(cAttr); } catch (e) { colors = []; } }
1944
- for (let i = 0; i < size * size; i++) {
1945
- const cell = document.createElement("div");
1946
- cell.className = "c-bivariate-legend__cell";
1947
- cell.setAttribute("role", "button");
1948
- cell.setAttribute("tabindex", "0");
1949
- const x = i % size;
1950
- const y = Math.floor(i / size);
1951
- cell.setAttribute("aria-label", "Cell " + x + "," + y);
1952
- if (colors[i]) cell.style.background = colors[i];
1953
- else cell.style.background = "var(--chart-" + ((i % 8) + 1) + ")";
1954
- matrix.appendChild(cell);
1955
- }
1956
- // aria-live
1957
- let live = this.querySelector(".c-bivariate-legend__live");
1958
- if (!live) { live = document.createElement("div"); live.className = "c-bivariate-legend__live"; live.setAttribute("aria-live", "polite"); live.style.position = "absolute"; live.style.width = "1px"; live.style.height = "1px"; live.style.overflow = "hidden"; live.style.clip = "rect(0,0,0,0)"; this.appendChild(live); }
1959
- }
1960
- const axisX = this.getAttribute("axis-x");
1961
- const ax = this.querySelector(".c-bivariate-legend__axis--x");
1962
- if (axisX) {
1963
- 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; });
1964
- el.textContent = axisX;
1965
- } else if (ax) {
1966
- ax.remove();
1967
- }
1968
- const axisY = this.getAttribute("axis-y");
1969
- const ay = this.querySelector(".c-bivariate-legend__axis--y");
1970
- if (axisY) {
1971
- 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; });
1972
- el.textContent = axisY;
1973
- } else if (ay) {
1974
- ay.remove();
1975
- }
1976
2581
  }
1977
2582
  enhance() {
1978
2583
  if (this._wiredBivLegend) return;
1979
2584
  this._wiredBivLegend = true;
1980
2585
  const selectCell = (cell) => {
1981
- const matrix = this.querySelector(".c-bivariate-legend__matrix");
1982
- const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate-legend__cell") : []);
2586
+ const matrix = this.querySelector(".c-bivariate__matrix");
2587
+ const cells = Array.from(matrix ? matrix.querySelectorAll(".c-bivariate__cell") : []);
1983
2588
  const idx = cells.indexOf(cell);
1984
2589
  if (idx < 0) return;
1985
2590
  const size = Math.min(8, Math.max(1, parseInt(this.getAttribute("size") || "3", 10) || 3));
@@ -1994,11 +2599,11 @@ class ContourBivariateLegend extends ContourBase {
1994
2599
  this.dispatchEvent(new CustomEvent("contour:select", { detail: { row, col }, bubbles: true, composed: true }));
1995
2600
  };
1996
2601
  this.addEventListener("click", (e) => {
1997
- const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
2602
+ const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
1998
2603
  if (cell && this.contains(cell)) selectCell(cell);
1999
2604
  });
2000
2605
  this.addEventListener("keydown", (e) => {
2001
- const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate-legend__cell") : null;
2606
+ const cell = e.target && e.target.closest ? e.target.closest(".c-bivariate__cell") : null;
2002
2607
  if (!cell || !this.contains(cell)) return;
2003
2608
  if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectCell(cell); }
2004
2609
  });
@@ -2006,6 +2611,10 @@ class ContourBivariateLegend extends ContourBase {
2006
2611
  clear() { this.removeAttribute("selected"); this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true })); }
2007
2612
  }
2008
2613
  define("contour-bivariate-legend", ContourBivariateLegend);
2614
+ /**
2615
+ * Survey: web component wrapper.
2616
+ * Attributes: `date`, `instrument`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2617
+ */
2009
2618
  class ContourSurvey extends ContourBase {
2010
2619
  static get observed() { return ["date", "instrument", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2011
2620
  static get properties() { return { date: { attribute: "date" }, instrument: { attribute: "instrument" }, src: { attribute: "src" } }; }
@@ -2043,6 +2652,10 @@ class ContourSurvey extends ContourBase {
2043
2652
  }
2044
2653
  }
2045
2654
  define("contour-survey", ContourSurvey);
2655
+ /**
2656
+ * Threshold: web component wrapper.
2657
+ * Attributes: `label`, `norm`, `state`, `value`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2658
+ */
2046
2659
  class ContourThreshold extends ContourBase {
2047
2660
  static get observed() { return ["label", "norm", "state", "value", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2048
2661
  static get properties() { return { label: { attribute: "label" }, norm: { attribute: "norm" }, state: { attribute: "state" }, value: { attribute: "value" }, src: { attribute: "src" } }; }
@@ -2080,6 +2693,10 @@ class ContourThreshold extends ContourBase {
2080
2693
  }
2081
2694
  }
2082
2695
  define("contour-threshold", ContourThreshold);
2696
+ /**
2697
+ * Metrics Full: web component wrapper.
2698
+ * Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
2699
+ */
2083
2700
  class ContourMetricsFull extends ContourBase {
2084
2701
  static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2085
2702
  static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
@@ -2114,6 +2731,10 @@ class ContourMetricsFull extends ContourBase {
2114
2731
  enhance() { wireStates(this); }
2115
2732
  }
2116
2733
  define("contour-metrics", ContourMetricsFull);
2734
+ /**
2735
+ * Legend: web component wrapper.
2736
+ * Attributes: `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`.
2737
+ */
2117
2738
  class ContourLegend extends ContourBase {
2118
2739
  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"]; }
2119
2740
  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" } }; }
@@ -2126,7 +2747,18 @@ class ContourLegend extends ContourBase {
2126
2747
  // aria-pressed, and the sheet's existing `.c-legend--interactive` rules
2127
2748
  // (hover, dim when pressed=false) apply.
2128
2749
  const selectable = this.hasAttribute("selectable");
2129
- const items = remoteData(this, "items");
2750
+ // Slotted content support: authored .c-legend__item children take
2751
+ // precedence over the JSON `items` attribute.
2752
+ const authoredLegendItems = Array.from(this.querySelectorAll(":scope > .c-legend__item"));
2753
+ let items = remoteData(this, "items");
2754
+ if (authoredLegendItems.length) {
2755
+ items = JSON.stringify(authoredLegendItems.map((el) => {
2756
+ const sw = el.querySelector(".c-legend__swatch");
2757
+ const lbl = el.querySelector(".c-legend__label") || el;
2758
+ return { label: lbl ? lbl.textContent.trim() : el.textContent.trim(), color: sw ? (sw.dataset && sw.dataset.color) || sw.style.background || undefined : undefined };
2759
+ }));
2760
+ authoredLegendItems.forEach((el) => el.remove());
2761
+ }
2130
2762
  const title = this.getAttribute("title");
2131
2763
  if (title) {
2132
2764
  const t = this.ensure(".c-legend__title", () => { const el = document.createElement("div"); el.className = "c-legend__title"; return el; });
@@ -2138,26 +2770,27 @@ class ContourLegend extends ContourBase {
2138
2770
  if (items) {
2139
2771
  try {
2140
2772
  const parsed = JSON.parse(items);
2141
- const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; el.setAttribute("role", "listbox"); return el; });
2773
+ const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
2142
2774
  list.setAttribute("role", "listbox");
2143
2775
  if (title) list.setAttribute("aria-label", title);
2144
2776
  list.innerHTML = "";
2145
2777
  parsed.forEach((it) => {
2146
2778
  const label = typeof it === "string" ? it : (it.label || String(it));
2147
2779
  const key = typeof it === "string" ? it : (it.key || it.label || String(it));
2148
- const item = document.createElement(selectable ? "button" : "div");
2780
+ const item = document.createElement("div");
2149
2781
  item.className = "c-legend__item";
2150
- item.setAttribute("role", "option");
2151
- item.setAttribute("aria-selected", "false");
2152
2782
  item.setAttribute("tabindex", "-1");
2153
2783
  if (selectable) {
2154
- item.type = "button";
2155
- item.setAttribute("aria-pressed", "true");
2784
+ item.setAttribute("role", "option");
2785
+ item.setAttribute("aria-selected", "true");
2156
2786
  item.dataset.key = key;
2787
+ } else {
2788
+ item.setAttribute("role", "option");
2789
+ item.setAttribute("aria-selected", "false");
2157
2790
  }
2158
2791
  const sw = document.createElement("span");
2159
2792
  sw.className = "c-legend__swatch";
2160
- if (it && it.color) sw.style.background = it.color;
2793
+ if (it && it.color) { sw.style.background = it.color; sw.dataset.color = it.color; }
2161
2794
  item.appendChild(sw);
2162
2795
  // geometry glyph
2163
2796
  const glyphShape = (it && (it.shape || it.marker || it.glyph)) || this.getAttribute("glyphs");
@@ -2230,6 +2863,7 @@ class ContourLegend extends ContourBase {
2230
2863
  const glyph = document.createElement("span");
2231
2864
  glyph.className = "glyph";
2232
2865
  glyph.style.background = ndColor;
2866
+ glyph.dataset.color = ndColor;
2233
2867
  nd.prepend(glyph);
2234
2868
  } else {
2235
2869
  const nd = this.querySelector(".c-legend__no-data");
@@ -2366,11 +3000,10 @@ class ContourLegend extends ContourBase {
2366
3000
  this.addEventListener("click", (e) => {
2367
3001
  const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
2368
3002
  if (!btn || !this.contains(btn)) return;
2369
- const pressed = btn.getAttribute("aria-pressed") !== "true";
2370
- btn.setAttribute("aria-pressed", String(pressed));
2371
- btn.setAttribute("aria-selected", String(pressed));
3003
+ const selected = btn.getAttribute("aria-selected") !== "true";
3004
+ btn.setAttribute("aria-selected", String(selected));
2372
3005
  this.dispatchEvent(new CustomEvent("contour:legend-toggle", {
2373
- detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed },
3006
+ detail: { label: btn.textContent.trim(), key: btn.dataset.key || btn.textContent.trim(), pressed: selected },
2374
3007
  bubbles: true,
2375
3008
  composed: true,
2376
3009
  }));
@@ -2412,7 +3045,7 @@ class ContourLegend extends ContourBase {
2412
3045
  if (items.length > 4) { e.preventDefault(); const last = items[items.length-1]; last.focus(); items.forEach((o)=>o.setAttribute("tabindex", o===last?"0":"-1")); }
2413
3046
  } else if (e.key === "Escape") {
2414
3047
  // clear selection
2415
- items.forEach((o) => o.setAttribute("aria-selected", "false"));
3048
+ items.forEach((o) => { if (o.getAttribute("role") === "option") o.setAttribute("aria-selected", "false"); else o.setAttribute("aria-pressed", "false"); });
2416
3049
  this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true }));
2417
3050
  } else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
2418
3051
  // type-ahead
@@ -2439,11 +3072,17 @@ class ContourLegend extends ContourBase {
2439
3072
  }
2440
3073
  }
2441
3074
  define("contour-legend", ContourLegend);
3075
+ /**
3076
+ * Measure: web component wrapper.
3077
+ * Attributes: `label`, `value`, `point`, `line`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3078
+ */
2442
3079
  class ContourMeasure extends ContourBase {
2443
3080
  static get observed() { return ["label", "value", "point", "line", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2444
3081
  static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, point: { attribute: "point" }, line: { attribute: "line" }, src: { attribute: "src" } }; }
2445
3082
  render() {
2446
3083
  this.classList.add("c-measure");
3084
+ this.setAttribute("role", "group");
3085
+ this.setAttribute("aria-label", "Measure");
2447
3086
  wireStates(this);
2448
3087
  loadRemote(this, ["label", "value", "point", "line"]);
2449
3088
  if (renderStates(this, "measure")) return;
@@ -2495,13 +3134,28 @@ class ContourMeasure extends ContourBase {
2495
3134
  if (ln) ln.remove();
2496
3135
  }
2497
3136
  }
3137
+ enhance() {
3138
+ if (this._wiredMeasure) return;
3139
+ this._wiredMeasure = true;
3140
+ this.addEventListener("change", (e) => {
3141
+ const sel = e.target && e.target.closest ? e.target.closest(".c-measure__unit-select") : null;
3142
+ if (sel && this.contains(sel)) {
3143
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { unit: sel.value } }));
3144
+ }
3145
+ });
3146
+ }
2498
3147
  }
2499
3148
  define("contour-measure", ContourMeasure);
3149
+ /**
3150
+ * Timeline: web component wrapper.
3151
+ * Attributes: `items`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3152
+ */
2500
3153
  class ContourTimeline extends ContourBase {
2501
3154
  static get observed() { return ["items", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2502
3155
  static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" } }; }
2503
3156
  render() {
2504
3157
  this.classList.add("c-timeline");
3158
+ this.setAttribute("role", "list");
2505
3159
  wireStates(this);
2506
3160
  loadRemote(this, "items");
2507
3161
  if (renderStates(this, "timeline")) return;
@@ -2514,6 +3168,8 @@ class ContourTimeline extends ContourBase {
2514
3168
  parsed.forEach((it) => {
2515
3169
  const item = document.createElement("div");
2516
3170
  item.className = "c-timeline__item";
3171
+ item.setAttribute("role", "listitem");
3172
+ item.setAttribute("tabindex", "-1");
2517
3173
  if (it.time) {
2518
3174
  const t = document.createElement("time");
2519
3175
  t.className = "c-timeline__time";
@@ -2542,15 +3198,49 @@ class ContourTimeline extends ContourBase {
2542
3198
  enhance() {
2543
3199
  if (this._wiredTimeline) return;
2544
3200
  this._wiredTimeline = true;
3201
+ const items = Array.from(this.querySelectorAll(".c-timeline__item"));
3202
+ items.forEach((it, i) => it.setAttribute("tabindex", i === 0 ? "0" : "-1"));
3203
+ this.addEventListener("click", (e) => {
3204
+ const item = e.target && e.target.closest ? e.target.closest(".c-timeline__item") : null;
3205
+ if (!item || !this.contains(item)) return;
3206
+ const items = Array.from(this.querySelectorAll(".c-timeline__item"));
3207
+ const idx = items.indexOf(item);
3208
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
3209
+ });
3210
+ this.addEventListener("keydown", (e) => {
3211
+ const items = Array.from(this.querySelectorAll(".c-timeline__item"));
3212
+ if (!items.length) return;
3213
+ const active = this.querySelector(".c-timeline__item:focus") || items[0];
3214
+ const idx = items.indexOf(active);
3215
+ let next = -1;
3216
+ if (e.key === "ArrowDown") next = Math.min(idx + 1, items.length - 1);
3217
+ else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
3218
+ else if (e.key === "Home") next = 0;
3219
+ else if (e.key === "End") next = items.length - 1;
3220
+ else if (e.key === "Enter" || e.key === " ") {
3221
+ e.preventDefault();
3222
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { index: idx } }));
3223
+ return;
3224
+ }
3225
+ if (next < 0 || next === idx) return;
3226
+ e.preventDefault();
3227
+ items.forEach((it, i) => it.setAttribute("tabindex", i === next ? "0" : "-1"));
3228
+ try { items[next].focus(); } catch (err) {}
3229
+ });
2545
3230
  }
2546
3231
  }
2547
3232
  define("contour-timeline", ContourTimeline);
3233
+ /**
3234
+ * Heatmap: web component wrapper.
3235
+ * Attributes: `cells`, `count`, `legend`, `empty`, `loading`, `values`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3236
+ */
2548
3237
  class ContourHeatmap extends ContourBase {
2549
3238
  static get observed() { return ["cells", "count", "legend", "empty", "loading", "values", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2550
3239
  static get properties() { return { cells: { attribute: "cells" }, count: { attribute: "count" }, legend: { attribute: "legend" }, src: { attribute: "src" } }; }
2551
3240
  render() {
2552
3241
  this.classList.add("c-heatmap");
2553
3242
  if (!this.hasAttribute("role")) this.setAttribute("role", "grid");
3243
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Heatmap");
2554
3244
  wireStates(this);
2555
3245
  loadRemote(this, "cells");
2556
3246
  if (renderStates(this, "heatmap")) return;
@@ -2673,11 +3363,17 @@ class ContourHeatmap extends ContourBase {
2673
3363
  }
2674
3364
  }
2675
3365
  define("contour-heatmap", ContourHeatmap);
3366
+ /**
3367
+ * Compare: web component wrapper.
3368
+ * Attributes: `no`, `text`, `yes`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3369
+ */
2676
3370
  class ContourCompare extends ContourBase {
2677
3371
  static get observed() { return ["no", "text", "yes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2678
3372
  static get properties() { return { no: { attribute: "no" }, text: { attribute: "text" }, yes: { attribute: "yes" }, src: { attribute: "src" } }; }
2679
3373
  render() {
2680
3374
  this.classList.add("c-compare");
3375
+ this.setAttribute("role", "group");
3376
+ this.setAttribute("aria-label", "Comparison");
2681
3377
  this.style.padding = "var(--space-md)";
2682
3378
  wireStates(this);
2683
3379
  loadRemote(this, ["no", "text", "yes"]);
@@ -2710,6 +3406,10 @@ class ContourCompare extends ContourBase {
2710
3406
  }
2711
3407
  }
2712
3408
  define("contour-compare", ContourCompare);
3409
+ /**
3410
+ * Sparkline: web component wrapper.
3411
+ * Attributes: `points`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3412
+ */
2713
3413
  class ContourSparkline extends ContourBase {
2714
3414
  static get observed() { return ["points", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2715
3415
  static get properties() { return { points: { attribute: "points" }, src: { attribute: "src" } }; }
@@ -2821,11 +3521,18 @@ class ContourSparkline extends ContourBase {
2821
3521
  }
2822
3522
  }
2823
3523
  define("contour-sparkline", ContourSparkline);
3524
+ /**
3525
+ * Chart Grid: web component wrapper.
3526
+ * Attributes: `title`, `series`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
3527
+ */
2824
3528
  class ContourChartGrid extends ContourBase {
3529
+ static get updateMode() { return "keyed"; }
2825
3530
  static get observed() { return ["title", "series", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
2826
3531
  static get properties() { return { title: { attribute: "title" }, series: { attribute: "series" }, src: { attribute: "src" } }; }
2827
3532
  render() {
2828
3533
  this.classList.add("c-chart-grid");
3534
+ this.setAttribute("role", "group");
3535
+ this.setAttribute("aria-label", "Chart grid");
2829
3536
  wireStates(this);
2830
3537
  loadRemote(this, "series");
2831
3538
  if (renderStates(this, "chart-grid")) return;
@@ -2839,11 +3546,17 @@ class ContourChartGrid extends ContourBase {
2839
3546
  }
2840
3547
  }
2841
3548
  define("contour-chart-grid", ContourChartGrid);
3549
+ /**
3550
+ * Contour Plot: web component wrapper.
3551
+ * Attributes: `axis`, `label`.
3552
+ */
2842
3553
  class ContourContourPlot extends ContourBase {
2843
3554
  static get observed() { return ["axis", "label"]; }
2844
3555
  static get properties() { return { axis: { attribute: "axis" }, label: { attribute: "label" } }; }
2845
3556
  render() {
2846
3557
  this.classList.add("c-contour-plot");
3558
+ this.setAttribute("role", "img");
3559
+ this.setAttribute("aria-label", "Contour plot");
2847
3560
  const axis = this.getAttribute("axis");
2848
3561
  if (axis) {
2849
3562
  let svg = this.querySelector("svg");
@@ -2879,4 +3592,96 @@ class ContourContourPlot extends ContourBase {
2879
3592
  }
2880
3593
  }
2881
3594
  }
2882
- define("contour-contour-plot", ContourContourPlot);
3595
+ /**
3596
+ * Error Boundary: web component wrapper.
3597
+ * Attributes: `fallback`, `error`.
3598
+ */
3599
+ class ContourErrorBoundary extends ContourBase {
3600
+ static get observed() { return ["fallback", "error"]; }
3601
+ static get properties() { return { fallback: { attribute: "fallback" }, error: { attribute: "error" } }; }
3602
+ render() {
3603
+ this.classList.add("c-error-boundary");
3604
+ this.setAttribute("role", "region");
3605
+ this.setAttribute("aria-live", "polite");
3606
+ const err = this.getAttribute("error");
3607
+ if (err) {
3608
+ this.dataset.state = "error";
3609
+ // Hide authored children, show fallback.
3610
+ Array.from(this.children).forEach((c) => { if (!c.hasAttribute("data-fallback")) c.style.display = "none"; });
3611
+ let fb = this.querySelector("[data-fallback]");
3612
+ if (!fb) {
3613
+ fb = document.createElement("div");
3614
+ fb.className = "c-error-boundary__fallback";
3615
+ fb.dataset.fallback = "";
3616
+ fb.textContent = this.getAttribute("fallback") || "Something went wrong.";
3617
+ this.appendChild(fb);
3618
+ } else {
3619
+ fb.textContent = this.getAttribute("fallback") || fb.textContent || "Something went wrong.";
3620
+ }
3621
+ } else {
3622
+ this.dataset.state = "ready";
3623
+ Array.from(this.children).forEach((c) => { c.style.display = ""; });
3624
+ const fb = this.querySelector("[data-fallback]");
3625
+ if (fb) fb.remove();
3626
+ }
3627
+ }
3628
+ enhance() {
3629
+ if (this._wiredErrorBoundary) return;
3630
+ this._wiredErrorBoundary = true;
3631
+ // Catch errors thrown by descendants during render/event handling.
3632
+ this.addEventListener("error", (e) => {
3633
+ e.stopPropagation();
3634
+ const msg = (e && e.error && e.error.message) ? e.error.message : (e && e.message) ? e.message : "Unknown error";
3635
+ this.setAttribute("error", msg);
3636
+ }, true);
3637
+ }
3638
+ }
3639
+ define("contour-error-boundary", ContourErrorBoundary);
3640
+
3641
+ class ContourDataExport extends ContourBase {
3642
+ static get observed() { return ["data", "format", "filename", "label"]; }
3643
+ static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" } }; }
3644
+ render() {
3645
+ this.classList.add("c-data-export");
3646
+ const fmt = (this.getAttribute("format") || "json").toLowerCase();
3647
+ const btn = this.ensure(".c-data-export__btn", () => {
3648
+ const b = document.createElement("button");
3649
+ b.className = "c-data-export__btn";
3650
+ b.type = "button";
3651
+ return b;
3652
+ });
3653
+ btn.textContent = this.getAttribute("label") || ("Export " + fmt.toUpperCase());
3654
+ if (btn.parentNode !== this) this.appendChild(btn);
3655
+ }
3656
+ enhance() {
3657
+ if (this._wiredDataExport) return;
3658
+ this._wiredDataExport = true;
3659
+ this.addEventListener("click", (e) => {
3660
+ const btn = e.target && e.target.closest ? e.target.closest(".c-data-export__btn") : null;
3661
+ if (!btn || !this.contains(btn)) return;
3662
+ const fmt = (this.getAttribute("format") || "json").toLowerCase();
3663
+ const raw = this.getAttribute("data") || "[]";
3664
+ let text = raw;
3665
+ if (fmt === "csv") {
3666
+ try {
3667
+ const arr = JSON.parse(raw);
3668
+ if (Array.isArray(arr) && arr.length) {
3669
+ const keys = Object.keys(arr[0]);
3670
+ text = [keys.join(",")].concat(arr.map((r) => keys.map((k) => JSON.stringify(r[k] ?? "")).join(","))).join("\n");
3671
+ }
3672
+ } catch (e) {}
3673
+ }
3674
+ const blob = new Blob([text], { type: fmt === "csv" ? "text/csv" : "application/json" });
3675
+ const url = URL.createObjectURL(blob);
3676
+ const a = document.createElement("a");
3677
+ a.href = url;
3678
+ a.download = this.getAttribute("filename") || ("export." + fmt);
3679
+ document.body.appendChild(a);
3680
+ a.click();
3681
+ a.remove();
3682
+ URL.revokeObjectURL(url);
3683
+ this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail: { format: fmt } }));
3684
+ });
3685
+ }
3686
+ }
3687
+ define("contour-data-export", ContourDataExport);