contour-ds 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/build-manifest.json +111 -111
  2. package/dist/contour-wc-content.esm.js +8 -1
  3. package/dist/contour-wc-content.esm.min.js +1 -1
  4. package/dist/contour-wc-core.esm.js +17 -8
  5. package/dist/contour-wc-core.esm.min.js +1 -1
  6. package/dist/contour-wc-dashboard.esm.js +438 -45
  7. package/dist/contour-wc-dashboard.esm.min.js +1 -1
  8. package/dist/contour-wc-data.esm.js +438 -45
  9. package/dist/contour-wc-data.esm.min.js +1 -1
  10. package/dist/contour-wc-docs.esm.js +4 -0
  11. package/dist/contour-wc-feedback.esm.js +69 -12
  12. package/dist/contour-wc-feedback.esm.min.js +1 -1
  13. package/dist/contour-wc-forms.esm.js +58 -4
  14. package/dist/contour-wc-forms.esm.min.js +1 -1
  15. package/dist/contour-wc-interaction.esm.js +13 -0
  16. package/dist/contour-wc-interaction.esm.min.js +1 -1
  17. package/dist/contour-wc-layout.esm.js +4 -0
  18. package/dist/contour-wc-map.esm.js +4 -0
  19. package/dist/contour-wc-misc.esm.js +4 -0
  20. package/dist/contour-wc-navigation.esm.js +60 -26
  21. package/dist/contour-wc-navigation.esm.min.js +1 -1
  22. package/dist/contour-wc-ui.esm.js +355 -27
  23. package/dist/contour-wc-ui.esm.min.js +1 -1
  24. package/dist/contour-wc.esm.js +994 -123
  25. package/dist/contour-wc.esm.min.js +1 -1
  26. package/dist/contour-wc.js +994 -123
  27. package/dist/contour-wc.min.js +1 -1
  28. package/dist/contour.code-snippets +4 -4
  29. package/dist/contour.components.json +327 -24
  30. package/dist/contour.css +196 -4
  31. package/dist/contour.d.ts +19 -15
  32. package/dist/contour.html-data.json +145 -3
  33. package/dist/contour.min.css +1 -1
  34. package/dist/contour.react.d.ts +2 -2
  35. package/dist/contour.single.html +1 -1
  36. package/dist/contour.single.min.css +1 -1
  37. package/dist/contour.vue.d.ts +2 -2
  38. package/dist/contour.web-types.json +145 -4
  39. package/dist/custom-elements.json +595 -2
  40. package/dist/docs/actions.md +1 -1
  41. package/dist/docs/affordances.md +1 -1
  42. package/dist/docs/apireference.md +1 -1
  43. package/dist/docs/colour.md +1 -1
  44. package/dist/docs/componentindex.md +1 -1
  45. package/dist/docs/data.md +1 -1
  46. package/dist/docs/docs.md +1 -1
  47. package/dist/docs/feedback.md +1 -1
  48. package/dist/docs/field.md +1 -1
  49. package/dist/docs/forms.md +1 -1
  50. package/dist/docs/index.json +2 -2
  51. package/dist/docs/install.md +1 -1
  52. package/dist/docs/landing.md +1 -1
  53. package/dist/docs/mapengine.md +1 -1
  54. package/dist/docs/motion.md +1 -1
  55. package/dist/docs/navigation.md +1 -1
  56. package/dist/docs/overlays.md +1 -1
  57. package/dist/docs/overview.md +1 -1
  58. package/dist/docs/patterns.md +1 -1
  59. package/dist/docs/playground.md +1 -1
  60. package/dist/docs/principles.md +1 -1
  61. package/dist/docs/recipes.md +1 -1
  62. package/dist/docs/space.md +1 -1
  63. package/dist/docs/status.md +1 -1
  64. package/dist/docs/surfaces.md +1 -1
  65. package/dist/docs/theming.md +1 -1
  66. package/dist/docs/type.md +1 -1
  67. package/dist/docs/webcomponents.md +1 -1
  68. package/dist/registry/items/contour-core.json +2 -2
  69. package/dist/registry/items/contour-data.json +2 -2
  70. package/dist/registry/items/contour-docs.json +2 -2
  71. package/dist/registry/items/contour-landing.json +2 -2
  72. package/dist/registry/registry.json +8 -8
  73. package/dist/surfaces/contour-core.min.css +1 -1
  74. package/dist/surfaces/contour-data.min.css +1 -1
  75. package/dist/surfaces/contour-docs.min.css +1 -1
  76. package/dist/surfaces/contour-landing.min.css +1 -1
  77. package/dist/wc/behaviours.mjs +13 -7
  78. package/dist/wc/content.mjs +4 -1
  79. package/dist/wc/core.mjs +3 -0
  80. package/dist/wc/data-chart.mjs +202 -14
  81. package/dist/wc/data-export.mjs +43 -5
  82. package/dist/wc/data-gauge.mjs +17 -3
  83. package/dist/wc/data-geo.mjs +26 -11
  84. package/dist/wc/data-legend.mjs +49 -4
  85. package/dist/wc/data-readout.mjs +8 -3
  86. package/dist/wc/data-series.mjs +78 -2
  87. package/dist/wc/data-table.mjs +13 -5
  88. package/dist/wc/feedback.mjs +65 -12
  89. package/dist/wc/forms-controls.mjs +38 -2
  90. package/dist/wc/forms-input.mjs +16 -2
  91. package/dist/wc/index.mjs +1 -1
  92. package/dist/wc/interaction.mjs +9 -0
  93. package/dist/wc/navigation-menu.mjs +51 -23
  94. package/dist/wc/navigation-tree.mjs +5 -3
  95. package/dist/wc/shadow.mjs +4 -0
  96. package/dist/wc/ui-atoms.mjs +134 -3
  97. package/dist/wc/ui-data.mjs +71 -4
  98. package/dist/wc/ui-feedback.mjs +8 -1
  99. package/dist/wc/ui-overlays.mjs +138 -19
  100. package/integrations/libreship/contract.json +20 -2
  101. package/package.json +1 -1
@@ -438,6 +438,10 @@ import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERV
438
438
  // Shadow tabs are a styling shell: panels are authored by the consumer
439
439
  shadow("contour-shadow-tabs", `<div class="c-tabs" part="tabs"><div class="c-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-tabs__panels" role="presentation"><slot></slot></div></div>`);
440
440
  shadow("contour-shadow-breadcrumb", `<nav class="c-breadcrumb" part="breadcrumb" aria-label="Breadcrumb"><ol><slot></slot></ol></nav>`);
441
+ // U-17: contour-shadow-menu is a shadow-styled shell with role="menu"; the
442
+ // consumer slots `role="menuitem"` children. It has no open/focus state of its
443
+ // own — pair it with contour-context-menu (which owns open/Escape/focus
444
+ // return) or drive focus with the standard menu keyboard contract.
441
445
  shadow("contour-shadow-menu", `<div class="c-menu" part="menu" role="menu"><slot></slot></div>`);
442
446
  shadow("contour-shadow-combobox", `<div class="c-combobox" part="combobox"><input class="c-combobox__input" part="input" type="text" /><ul class="c-combobox__list" part="list" hidden><slot></slot></ul></div>`);
443
447
  shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
@@ -686,9 +690,9 @@ define("contour-readout", ContourReadout);
686
690
  * Attributes: `value`, `label`, `delta`, `direction`, `note`, `variant`, `unit`, `format`, `locale`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`, `thresholds`, `threshold`, `sparkline`, `polarity`.
687
691
  */
688
692
  class ContourKpi extends ContourBase {
689
- 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", "cache-key", "no-cache"]; }
693
+ 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", "delta-tone", "cache-key", "no-cache"]; }
690
694
  static get properties() {
691
- return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, direction: { attribute: "direction" }, note: { attribute: "note" }, variant: { attribute: "variant" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, thresholds: { attribute: "thresholds" }, threshold: { attribute: "threshold" }, sparkline: { attribute: "sparkline" }, polarity: { attribute: "polarity" } };
695
+ return { value: { attribute: "value" }, label: { attribute: "label" }, delta: { attribute: "delta" }, direction: { attribute: "direction" }, note: { attribute: "note" }, variant: { attribute: "variant" }, unit: { attribute: "unit" }, format: { attribute: "format" }, locale: { attribute: "locale" }, thresholds: { attribute: "thresholds" }, threshold: { attribute: "threshold" }, sparkline: { attribute: "sparkline" }, polarity: { attribute: "polarity" }, "delta-tone": { attribute: "delta-tone" } };
692
696
  }
693
697
  render() {
694
698
  this.classList.add("c-kpi");
@@ -735,8 +739,13 @@ class ContourKpi extends ContourBase {
735
739
  if (!d.parentNode) f.insertBefore(d, f.firstChild);
736
740
  const dir = this.getAttribute("direction") || "up";
737
741
  const polarity = this.getAttribute("polarity") || "neutral";
742
+ // U-28: `delta-tone` is an explicit override (good/bad/neutral); with
743
+ // out it, `polarity` derives the tone from the direction.
744
+ const explicitTone = (this.getAttribute("delta-tone") || "").toLowerCase();
738
745
  let tone = "neutral";
739
- if (polarity === "good" || polarity === "up-good" || polarity === "auto") {
746
+ if (explicitTone === "good" || explicitTone === "bad" || explicitTone === "neutral") {
747
+ tone = explicitTone;
748
+ } else if (polarity === "good" || polarity === "up-good" || polarity === "auto") {
740
749
  tone = (dir === "up") ? "good" : (dir === "down" ? "bad" : "neutral");
741
750
  } else if (polarity === "bad" || polarity === "down-good") {
742
751
  tone = (dir === "up") ? "bad" : (dir === "down" ? "good" : "neutral");
@@ -1609,6 +1618,11 @@ class ContourDataTable extends ContourTable {
1609
1618
  class ContourColumnPicker extends ContourBase {
1610
1619
  static get observed() { return ["columns", "label"]; }
1611
1620
  static get properties() { return { columns: { attribute: "columns" }, label: { attribute: "label" } }; }
1621
+ // Contract (U-13): `columns` is a JSON array. Each item is either a string
1622
+ // (the column key) or an object `{ key?, value?, name?, label?, checked? }`.
1623
+ // The checkbox `data-column` (and the `contour:column-toggle` detail) always
1624
+ // carries a STRING key — `key ?? value ?? name ?? label` — never the object
1625
+ // stringified to "[object Object]". `checked`/`visible` default to true.
1612
1626
  render() {
1613
1627
  this.classList.add("c-column-picker");
1614
1628
  const btn = this.ensure(".c-column-picker__trigger", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-column-picker__trigger"; return b; });
@@ -1619,16 +1633,19 @@ class ContourColumnPicker extends ContourBase {
1619
1633
  try { const p = JSON.parse(this.getAttribute("columns") || "[]"); if (Array.isArray(p)) cols = p; } catch (e) { /* empty */ }
1620
1634
  panel.innerHTML = "";
1621
1635
  cols.forEach((c) => {
1622
- const name = typeof c === "string" ? c : (c.label || c.name || c);
1623
- const val = typeof c === "string" ? c : (c.value || c.name || c);
1636
+ const isStr = typeof c === "string";
1637
+ const name = isStr ? c : (c.label || c.name || c.key || c.value || "");
1638
+ // U-13: a string key, never "[object Object]".
1639
+ let key = isStr ? c : (c.key != null ? c.key : (c.value != null ? c.value : (c.name != null ? c.name : name)));
1640
+ key = String(key);
1624
1641
  const item = document.createElement("label");
1625
1642
  item.className = "c-column-picker__item";
1626
1643
  const cb = document.createElement("input");
1627
1644
  cb.type = "checkbox";
1628
- cb.checked = true;
1629
- cb.dataset.column = val;
1645
+ cb.checked = isStr ? true : (c.checked != null ? !!c.checked : (c.visible != null ? !!c.visible : true));
1646
+ cb.dataset.column = key;
1630
1647
  item.appendChild(cb);
1631
- item.appendChild(document.createTextNode(" " + name));
1648
+ item.appendChild(document.createTextNode(" " + (name || key)));
1632
1649
  panel.appendChild(item);
1633
1650
  });
1634
1651
  }
@@ -1706,6 +1723,10 @@ const normalizeChartBin = (bin) => {
1706
1723
  const out = { x0, x1, count };
1707
1724
  const normalized = Number(bin.normalized);
1708
1725
  if (Number.isFinite(normalized)) out.normalized = normalized;
1726
+ // U-1: a bin may carry its own colour (a value-range ramp). safeColor guards
1727
+ // injection; an invalid colour is dropped rather than rendered as a raw string.
1728
+ const color = safeColor(bin.color);
1729
+ if (color) out.color = color;
1709
1730
  return out;
1710
1731
  };
1711
1732
 
@@ -1726,8 +1747,15 @@ const normalizeChartBin = (bin) => {
1726
1747
  */
1727
1748
  class ContourChart extends ContourBase {
1728
1749
  static get updateMode() { return "keyed"; }
1729
- static get observed() { return ["series", "axis", "color", "label", "legend", "brownout", "brownout-level", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "bucket-count", "limit-values", "title", "cache-key", "dir", "src"]; }
1730
- static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, label: { attribute: "label" }, legend: { attribute: "legend" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
1750
+ static get observed() { return ["series", "axis", "color", "colors", "label", "legend", "brownout", "brownout-level", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "annotations", "mean-marker", "median-marker", "bin-labels", "bucket-count", "limit-values", "title", "cache-key", "dir", "src"]; }
1751
+ static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, colors: { attribute: "colors" }, label: { attribute: "label" }, legend: { attribute: "legend" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, annotations: { attribute: "annotations" }, "mean-marker": { attribute: "mean-marker", type: Boolean }, "median-marker": { attribute: "median-marker", type: Boolean }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
1752
+ // U-4: JS formatters. The `axis` attribute is JSON, so a consumer cannot pass a
1753
+ // function through it. These properties accept a function directly: `format`
1754
+ // formats a value-axis tick, `tooltipFormat` builds a mark's tooltip text.
1755
+ set format(fn) { this._jsFormat = typeof fn === "function" ? fn : null; this.requestRender(); }
1756
+ get format() { return this._jsFormat || null; }
1757
+ set tooltipFormat(fn) { this._jsTooltipFormat = typeof fn === "function" ? fn : null; this.requestRender(); }
1758
+ get tooltipFormat() { return this._jsTooltipFormat || null; }
1731
1759
  // Bindable histogram contract (R18-68): consumer drives via bins/backgroundData/range (JS props, not attrs); push re-renders, read returns drawn bins.
1732
1760
  get bins() {
1733
1761
  const pushed = this._pushedBins;
@@ -1862,6 +1890,50 @@ class ContourChart extends ContourBase {
1862
1890
  return Number.isFinite(min) && Number.isFinite(max) ? [min, max] : null;
1863
1891
  } catch (e) { return null; }
1864
1892
  }
1893
+ // U-2/U-3: paint mean/median reference markers and value annotations as
1894
+ // absolutely-positioned overlays on the plot. `frac` is the 0..1 position
1895
+ // across the plot's x-domain. The marks are decorative (aria-hidden): the
1896
+ // authoritative values live in the chart's data table.
1897
+ _renderChartMarkers(markers) {
1898
+ const plot = this._plot || this.querySelector(".c-chart__plot");
1899
+ if (!plot) return;
1900
+ Array.from(plot.querySelectorAll(".c-chart__marker, .c-chart__annotation")).forEach((n) => n.remove());
1901
+ if (!Array.isArray(markers) || !markers.length) return;
1902
+ markers.forEach((m) => {
1903
+ if (!m || !Number.isFinite(m.frac)) return;
1904
+ const el = document.createElement("div");
1905
+ el.className = m.kind === "annotation" ? "c-chart__annotation" : "c-chart__marker";
1906
+ el.style.left = (Math.max(0, Math.min(1, m.frac)) * 100).toFixed(3) + "%";
1907
+ if (m.kind && m.kind !== "annotation") el.dataset.kind = m.kind;
1908
+ if (m.label) {
1909
+ const lab = document.createElement("span");
1910
+ lab.className = "c-chart__marker-label";
1911
+ lab.textContent = m.label;
1912
+ el.appendChild(lab);
1913
+ }
1914
+ el.setAttribute("aria-hidden", "true");
1915
+ plot.appendChild(el);
1916
+ });
1917
+ }
1918
+ // U-19: direct per-bin labels. Positioned like the reference markers (a
1919
+ // fraction of the plot's width/height), decorative for AT because the data
1920
+ // table carries the authoritative values.
1921
+ _renderBinLabels(labels) {
1922
+ const plot = this._plot || this.querySelector(".c-chart__plot");
1923
+ if (!plot) return;
1924
+ Array.from(plot.querySelectorAll(".c-chart__bin-label")).forEach((n) => n.remove());
1925
+ if (!Array.isArray(labels) || !labels.length) return;
1926
+ labels.forEach((l) => {
1927
+ if (!l || !Number.isFinite(l.x) || !Number.isFinite(l.y)) return;
1928
+ const el = document.createElement("span");
1929
+ el.className = "c-chart__bin-label";
1930
+ el.style.left = (Math.max(0, Math.min(1, l.x)) * 100).toFixed(3) + "%";
1931
+ el.style.top = (Math.max(0, Math.min(1, l.y)) * 100).toFixed(3) + "%";
1932
+ el.textContent = l.text;
1933
+ el.setAttribute("aria-hidden", "true");
1934
+ plot.appendChild(el);
1935
+ });
1936
+ }
1865
1937
  _renderValueAxis() {
1866
1938
  const ax = this.querySelector(".c-chart__axis");
1867
1939
  if (!ax) return;
@@ -1879,7 +1951,7 @@ class ContourChart extends ContourBase {
1879
1951
  this.classList.add("c-chart--value-axis");
1880
1952
  ax.className = "c-chart__axis c-chart__axis--y";
1881
1953
  const ticks = (y && y.ticks) || niceTicks(domain[0], domain[1], 5);
1882
- const format = (y && y.format) || ((v) => String(v));
1954
+ const format = this._jsFormat || (y && y.format) || ((v) => String(v));
1883
1955
  ax.textContent = "";
1884
1956
  // Per-axis titles: y.label titles value axis; category label (top-level
1885
1957
  // or x.label) rides its own row under the plot.
@@ -2035,12 +2107,26 @@ class ContourChart extends ContourBase {
2035
2107
  series = JSON.stringify([{ type: "histogram", bins: this._pushedBins }]);
2036
2108
  }
2037
2109
  if (series) {
2038
- const parsed = parseArrayAttr(this, "series", warnBadJson);
2039
- if (parsed.length === 0) { renderEmpty(this, "chart"); return; }
2110
+ // U-6: parse the LOCAL `series` (attribute or the bins-alone fallback
2111
+ // built above), not the attribute again — re-reading the attribute made
2112
+ // a pushed-bins histogram inert because there is no `series` attribute.
2113
+ let parsed;
2114
+ try { parsed = JSON.parse(series); } catch (e) { warnBadJson(this, "series", e); parsed = []; }
2115
+ if (!Array.isArray(parsed)) parsed = [];
2116
+ if (parsed.length === 0) { renderEmpty(this, "chart"); return; }
2117
+ // U-4: keep the drawn series so a JS tooltipFormat can read a mark's datum.
2118
+ this._chartSeries = parsed;
2040
2119
  const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
2041
2120
  // R24-88: keep the plot alive across renders so patchChildren can reuse its marks instead of the base dropping and rebuilding them.
2042
2121
  this.keepNode(plot);
2043
- const frag = document.createDocumentFragment();
2122
+ const frag = document.createDocumentFragment();
2123
+ // U-2/U-3: mean/median reference markers and value annotations are
2124
+ // collected while the histogram renders, then painted over the plot
2125
+ // after patchChildren (which only manages the SVG marks in `frag`).
2126
+ const pendingMarkers = [];
2127
+ // U-19: direct per-bin labels for a histogram, rendered as positioned
2128
+ // overlays after the plot is patched (like the reference markers).
2129
+ const pendingBinLabels = [];
2044
2130
  // Structured series: an item may carry `values` plus a `type` ("donut" | "histogram" | "line") instead of a pre-computed `d` path, or carry pre-binned `bins` instead of raw `values`. The helpers in svg.mjs turn those into geometry so a consumer does not have to hand-compute arc or bar math.
2045
2131
  const hasStructured = parsed.some((s) => s && (Array.isArray(s.values) || Array.isArray(s.bins)));
2046
2132
  if (hasStructured) {
@@ -2124,6 +2210,14 @@ svg.setAttribute("role", "group");
2124
2210
  bins = buckets.map((count, bi) => ({ x0: min + bi * width, x1: min + (bi + 1) * width, count }));
2125
2211
  }
2126
2212
  if (bins) plotVals = bins.map((b) => b.count);
2213
+ // U-1: a histogram may colour by value range. A `colors` array
2214
+ // (chart-level, or per-series `s.colors`) aligns to bins; a bin's
2215
+ // own `color` wins over the array. Each entry is safeColor-guarded.
2216
+ let binColorList = null;
2217
+ const colorsAttr = this.getAttribute("colors");
2218
+ const rawColors = colorsAttr ? (() => { try { return JSON.parse(colorsAttr); } catch (e) { return null; } })()
2219
+ : (Array.isArray(s.colors) ? s.colors : null);
2220
+ if (Array.isArray(rawColors)) binColorList = rawColors.map((c) => safeColor(c)).filter(Boolean);
2127
2221
  // Raw values with no bucket count have no boundaries to publish: those bars are counts at index positions, not a distribution over a domain, so `bins` stays empty and the consumer is told there is nothing to map a range onto.
2128
2222
  this._renderedBins = bins ? bins.slice() : [];
2129
2223
  const pushedBackground = this._pushedBackground && this._pushedBackground.length ? this._pushedBackground : null;
@@ -2154,12 +2248,16 @@ svg.setAttribute("role", "group");
2154
2248
  svg.appendChild(rect);
2155
2249
  });
2156
2250
  }
2157
- barRects(plotVals, backgroundVals.length ? { max: sharedMax } : undefined).forEach((r, ri) => {
2251
+ const foregroundRects = barRects(plotVals, backgroundVals.length ? { max: sharedMax } : undefined);
2252
+ foregroundRects.forEach((r, ri) => {
2158
2253
  if (r.missing) return; // R31-50: missing is not a zero bar
2159
2254
  const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
2160
2255
  rect.setAttribute("class", "c-chart__bar");
2161
2256
  rect.setAttribute("data-series", String(i + 1));
2162
- rect.style.setProperty("--c", color);
2257
+ // U-1: per-bin colour — bin.color, then the aligned colors
2258
+ // array, then the series colour.
2259
+ const binColor = (bins && bins[ri] && bins[ri].color) || (binColorList && binColorList[ri]) || color;
2260
+ rect.style.setProperty("--c", binColor);
2163
2261
  rect.setAttribute("x", r.x);
2164
2262
  rect.setAttribute("y", r.y);
2165
2263
  rect.setAttribute("width", r.width);
@@ -2172,8 +2270,50 @@ svg.setAttribute("role", "group");
2172
2270
  rect.dataset.index = String(ri);
2173
2271
  svg.appendChild(rect);
2174
2272
  });
2273
+ // U-19: direct per-bin labels — the count rides above each bar.
2274
+ if (flagOn(this, "bin-labels")) {
2275
+ foregroundRects.forEach((r, ri) => {
2276
+ if (r.missing) return;
2277
+ const val = bins ? bins[ri].count : (Array.isArray(s.values) ? s.values[ri] : ri);
2278
+ if (isMissing(val)) return;
2279
+ pendingBinLabels.push({ x: (r.x + r.width / 2) / 300, y: r.y / 120, text: formatValue(val) });
2280
+ });
2281
+ }
2175
2282
  frag.appendChild(svg);
2176
- } else if (s.type === "scatter") {
2283
+ // U-2/U-3: position mean/median markers and annotations on the
2284
+ // histogram's own x-domain (bins[0].x0 .. bins[last].x1), which
2285
+ // is the same domain the bars are laid out over.
2286
+ if (bins && bins.length) {
2287
+ const dMin = Number(bins[0].x0);
2288
+ const dMax = Number(bins[bins.length - 1].x1);
2289
+ const dSpan = (dMax - dMin) || 1;
2290
+ const toFrac = (v) => (v - dMin) / dSpan;
2291
+ const totalCount = bins.reduce((a, b) => a + (Number(b.count) || 0), 0);
2292
+ if (flagOn(this, "mean-marker") && totalCount > 0) {
2293
+ let sum = 0;
2294
+ bins.forEach((b) => { const mid = (Number(b.x0) + Number(b.x1)) / 2; sum += mid * (Number(b.count) || 0); });
2295
+ const mean = sum / totalCount;
2296
+ pendingMarkers.push({ frac: toFrac(mean), label: labelText(this, "mean", "mean") + " " + formatValue(mean), kind: "mean" });
2297
+ }
2298
+ if (flagOn(this, "median-marker") && totalCount > 0) {
2299
+ let acc = 0, median = dMin;
2300
+ const half = totalCount / 2;
2301
+ for (const b of bins) { acc += (Number(b.count) || 0); if (acc >= half) { median = (Number(b.x0) + Number(b.x1)) / 2; break; } }
2302
+ pendingMarkers.push({ frac: toFrac(median), label: labelText(this, "median", "median") + " " + formatValue(median), kind: "median" });
2303
+ }
2304
+ let anns = Array.isArray(s.annotations) ? s.annotations : null;
2305
+ const annAttr = this.getAttribute("annotations");
2306
+ if (!anns && annAttr) { try { const p = JSON.parse(annAttr); if (Array.isArray(p)) anns = p; } catch (e) {} }
2307
+ if (Array.isArray(anns)) {
2308
+ anns.forEach((a) => {
2309
+ const v = Number(a && a.value != null ? a.value : a);
2310
+ if (!Number.isFinite(v)) return;
2311
+ const label = a && typeof a === "object" ? (a.label != null ? String(a.label) : formatValue(v)) : formatValue(v);
2312
+ pendingMarkers.push({ frac: toFrac(v), label, kind: "annotation" });
2313
+ });
2314
+ }
2315
+ }
2316
+ } else if (s.type === "scatter") {
2177
2317
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2178
2318
  svg.setAttribute("viewBox", "0 0 300 120");
2179
2319
  svg.setAttribute("preserveAspectRatio", "none");
@@ -2286,6 +2426,10 @@ svg.setAttribute("role", "group");
2286
2426
  frag.appendChild(svg);
2287
2427
  }
2288
2428
  patchChildren(plot, frag);
2429
+ // U-2/U-3: paint mean/median markers and annotations over the plot.
2430
+ this._renderChartMarkers(pendingMarkers);
2431
+ // U-19: paint the histogram's direct per-bin labels over the bars.
2432
+ this._renderBinLabels(pendingBinLabels);
2289
2433
  // Styled tooltip element (positioned via --chart-tip-*). R25-03: shed at level ≥2. The hover/focus handlers re-query the tip per event and no-op when absent, so removing it is safe.
2290
2434
  if (this.shed("tooltip", 2)) {
2291
2435
  const oldTip = this.querySelector(".c-chart__tooltip");
@@ -2301,7 +2445,12 @@ svg.setAttribute("role", "group");
2301
2445
  const dataTableRaw = (this.getAttribute("data-table") || "").trim().toLowerCase();
2302
2446
  const dataTableOff = dataTableRaw === "none" || dataTableRaw === "off" || dataTableRaw === "false" || dataTableRaw === "0";
2303
2447
  const hasTabularValues = parsed.some((s) => Array.isArray(s && s.values) && s.values.length);
2304
- if (!dataTableOff && hasTabularValues) {
2448
+ // U-5: a bins-driven histogram has no series `values`, but its drawn
2449
+ // distribution is still tabular data — render it as a range/count table
2450
+ // so the accessible fallback exists for a pushed-bins chart too.
2451
+ const drawnBins = this._renderedBins || [];
2452
+ const hasBinsTable = !hasTabularValues && drawnBins.length > 0;
2453
+ if (!dataTableOff && (hasTabularValues || hasBinsTable)) {
2305
2454
  let table = this.querySelector(".c-chart__data-table");
2306
2455
  if (!table) {
2307
2456
  table = document.createElement("table");
@@ -2314,6 +2463,33 @@ svg.setAttribute("role", "group");
2314
2463
  const cap = document.createElement("caption");
2315
2464
  cap.textContent = title;
2316
2465
  table.appendChild(cap);
2466
+ if (hasBinsTable) {
2467
+ const bThead = document.createElement("thead");
2468
+ const bhr = document.createElement("tr");
2469
+ const bh1 = document.createElement("th");
2470
+ bh1.setAttribute("scope", "col");
2471
+ bh1.textContent = labelText(this, "range", "Range");
2472
+ bhr.appendChild(bh1);
2473
+ const bh2 = document.createElement("th");
2474
+ bh2.setAttribute("scope", "col");
2475
+ bh2.textContent = labelText(this, "count", "Count");
2476
+ bhr.appendChild(bh2);
2477
+ bThead.appendChild(bhr);
2478
+ table.appendChild(bThead);
2479
+ const bBody = document.createElement("tbody");
2480
+ drawnBins.forEach((b) => {
2481
+ const tr = document.createElement("tr");
2482
+ const td0 = document.createElement("th");
2483
+ td0.setAttribute("scope", "row");
2484
+ td0.textContent = formatValue(b.x0) + "–" + formatValue(b.x1);
2485
+ tr.appendChild(td0);
2486
+ const td1 = document.createElement("td");
2487
+ td1.textContent = isMissing(b.count) ? "" : String(b.count);
2488
+ tr.appendChild(td1);
2489
+ bBody.appendChild(tr);
2490
+ });
2491
+ table.appendChild(bBody);
2492
+ } else {
2317
2493
  const thead = document.createElement("thead");
2318
2494
  const hr = document.createElement("tr");
2319
2495
  const h = document.createElement("th");
@@ -2346,6 +2522,7 @@ svg.setAttribute("role", "group");
2346
2522
  tbody.appendChild(tr);
2347
2523
  });
2348
2524
  table.appendChild(tbody);
2525
+ }
2349
2526
  } else {
2350
2527
  const old = this.querySelector(".c-chart__data-table");
2351
2528
  if (old) old.remove();
@@ -2562,9 +2739,33 @@ svg.setAttribute("role", "group");
2562
2739
  const tip = this.querySelector(".c-chart__tooltip");
2563
2740
  if (!plot || !tip) return;
2564
2741
  const mark = e.target && e.target.closest ? e.target.closest(".c-chart__bar, .c-chart__point, .c-chart__line, .c-donut__slice") : null;
2565
- if (!mark || !plot.contains(mark)) { tip.setAttribute("hidden", ""); return; }
2742
+ if (!mark || !plot.contains(mark)) { tip.setAttribute("hidden", ""); this._lastHoverKey = null; return; }
2566
2743
  const title = mark.getAttribute("data-title") || mark.getAttribute("title");
2567
- if (title) tip.textContent = title;
2744
+ // U-19: emit a bin-hover detail event when the hovered bar changes, so a
2745
+ // consumer can mirror a histogram highlight/tooltip without scraping the
2746
+ // light DOM on every pointer move. Bars only (points/lines/donut skip it).
2747
+ if (mark.classList.contains("c-chart__bar")) {
2748
+ const idxAttr = mark.getAttribute("data-index");
2749
+ const idx = idxAttr != null ? Number(idxAttr) : null;
2750
+ const si = Number(mark.getAttribute("data-series")) || 1;
2751
+ const hkey = si + ":" + (idxAttr != null ? idxAttr : "");
2752
+ if (this._lastHoverKey !== hkey) {
2753
+ this._lastHoverKey = hkey;
2754
+ const bin = idx != null && this._renderedBins ? (this._renderedBins[idx] || null) : null;
2755
+ const val = bin ? bin.count : (title != null ? title : null);
2756
+ this.dispatchEvent(new CustomEvent("contour:bin-hover", { bubbles: true, composed: true, detail: { index: idx, series: si, value: val, bin } }));
2757
+ }
2758
+ }
2759
+ // U-4: a JS `tooltipFormat` builds the tip text from the mark's datum.
2760
+ if (this._jsTooltipFormat) {
2761
+ try {
2762
+ const idx = mark.getAttribute("data-index");
2763
+ const seriesObj = this._chartSeries ? this._chartSeries[(Number(mark.getAttribute("data-series")) || 1) - 1] : null;
2764
+ const value = seriesObj && Array.isArray(seriesObj.values) && idx !== null && idx !== undefined ? seriesObj.values[Number(idx)] : title;
2765
+ const out = this._jsTooltipFormat({ series: mark.getAttribute("data-series"), index: idx != null ? Number(idx) : null, value, title });
2766
+ if (title || out != null) tip.textContent = out == null ? title : String(out);
2767
+ } catch (e) { if (title) tip.textContent = title; }
2768
+ } else if (title) tip.textContent = title;
2568
2769
  if (!plotRectCache) {
2569
2770
  plotRectCache = plot.getBoundingClientRect();
2570
2771
  if (!plotRectObserver && typeof ResizeObserver === "function") {
@@ -2583,6 +2784,10 @@ svg.setAttribute("role", "group");
2583
2784
  const hideTip = () => {
2584
2785
  const tip = this.querySelector(".c-chart__tooltip");
2585
2786
  if (tip) tip.setAttribute("hidden", "");
2787
+ if (this._lastHoverKey != null) {
2788
+ this._lastHoverKey = null;
2789
+ this.dispatchEvent(new CustomEvent("contour:bin-hover", { bubbles: true, composed: true, detail: { index: null, series: null, value: null, bin: null } }));
2790
+ }
2586
2791
  };
2587
2792
  // Host-delegated so the handlers survive re-renders (rule 12).
2588
2793
  this.addEventListener("mousemove", showTip);
@@ -3898,8 +4103,8 @@ define("contour-stacked-bar", ContourStackedBar);
3898
4103
  * it is not a reflected property.
3899
4104
  */
3900
4105
  class ContourCategory extends ContourBase {
3901
- static get observed() { return ["items", "search", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "limit", "sort", "format", "locale", "unit", "cache-key", "no-cache"]; }
3902
- static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" } }; }
4106
+ static get observed() { return ["items", "search", "selected", "aria-label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "note", "limit", "sort", "format", "locale", "unit", "cache-key", "no-cache"]; }
4107
+ static get properties() { return { items: { attribute: "items" }, selected: { attribute: "selected" }, src: { attribute: "src" }, note: { attribute: "note" }, limit: { attribute: "limit" }, sort: { attribute: "sort" }, format: { attribute: "format" }, locale: { attribute: "locale" }, unit: { attribute: "unit" } }; }
3903
4108
  render() {
3904
4109
  this.classList.add("c-category");
3905
4110
  this.setAttribute("role", "listbox");
@@ -3940,13 +4145,27 @@ class ContourCategory extends ContourBase {
3940
4145
  // produces a positive-width bar (a negative inline-size is invalid CSS
3941
4146
  // and rendered nothing) and the sign is carried by the formatted value.
3942
4147
  const max = items.reduce((m, it) => Math.max(m, Math.abs(typeof it === "object" ? (it.value || 0) : Number(it) || 0)), 0) || 1;
4148
+ // U-24: controlled selected values (JSON array or comma list), matched by
4149
+ // label or value. The host owns selection; a click still emits contour:select.
4150
+ const selectedRaw = this.getAttribute("selected");
4151
+ let selectedSet = new Set();
4152
+ if (selectedRaw) {
4153
+ try { const p = JSON.parse(selectedRaw); selectedSet = new Set((Array.isArray(p) ? p : [selectedRaw]).map(String)); }
4154
+ catch (e) { selectedSet = new Set(selectedRaw.split(",").map((s) => s.trim()).filter(Boolean)); }
4155
+ }
3943
4156
  items.forEach((it, idx) => {
3944
4157
  const value = (typeof it === "object") ? (it.value || 0) : (Number(it) || 0);
3945
4158
  const label = (typeof it === "object") ? (it.label || it.name || "") : String(it);
3946
4159
  const item = document.createElement("div");
3947
4160
  item.className = "c-category__item";
3948
4161
  item.setAttribute("role", "option");
3949
- item.setAttribute("aria-selected", "false");
4162
+ const itemKey = typeof it === "object" ? String(it.key != null ? it.key : (it.label || it.name || "")) : String(it);
4163
+ const isSelected = selectedSet.has(itemKey) || selectedSet.has(String(value)) || selectedSet.has(String(label));
4164
+ item.setAttribute("aria-selected", isSelected ? "true" : "false");
4165
+ if (isSelected) item.classList.add("is-selected");
4166
+ // U-24: the option's accessible name carries the label and its value,
4167
+ // so a screen reader hears "Road: 1,204" rather than a bare bar.
4168
+ item.setAttribute("aria-label", String(label) + ": " + formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit")));
3950
4169
  item.setAttribute("tabindex", idx === 0 ? "0" : "-1");
3951
4170
  const lbl = document.createElement("span");
3952
4171
  lbl.className = "c-category__label";
@@ -4390,8 +4609,8 @@ define("contour-time-series", ContourTimeSeries);
4390
4609
  * Attributes: `rows`, `columns`, `values`, `data`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
4391
4610
  */
4392
4611
  class ContourPivot extends ContourBase {
4393
- static get observed() { return ["rows", "columns", "values", "data", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "filter", "aggregate", "cache-key", "no-cache"]; }
4394
- 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" } }; }
4612
+ static get observed() { return ["rows", "columns", "values", "data", "label", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "filter", "aggregate", "cache-key", "no-cache"]; }
4613
+ static get properties() { return { rows: { attribute: "rows" }, columns: { attribute: "columns" }, values: { attribute: "values" }, data: { attribute: "data" }, label: { attribute: "label" }, src: { attribute: "src" }, filter: { attribute: "filter" }, aggregate: { attribute: "aggregate" } }; }
4395
4614
  _aggregateFn(name) {
4396
4615
  const n = (name || "sum").toLowerCase();
4397
4616
  if (n === "avg" || n === "average" || n === "mean") return (vals) => vals.length ? vals.reduce((a,b)=>a+b,0)/vals.length : 0;
@@ -4400,8 +4619,63 @@ class ContourPivot extends ContourBase {
4400
4619
  if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
4401
4620
  return (vals) => vals.reduce((a,b)=>a+b,0);
4402
4621
  }
4622
+ // U-10: focus snapshot/restore. The pivot rebuilds its whole table (and
4623
+ // toolbar) on every render, which drops focus to <body>; capture the focused
4624
+ // cell (or the filter input) and restore it to the same place afterwards.
4625
+ _pivotCaptureFocus() {
4626
+ // The base drops the focused node before render() runs; use the last cell
4627
+ // (or the filter input) the user focused, recorded by focusin in enhance().
4628
+ if (this._pivotFocus) return this._pivotFocus;
4629
+ const el = document.activeElement;
4630
+ if (!el || !this.contains(el)) return null;
4631
+ if (el.classList && el.classList.contains("c-pivot__filter")) return { kind: "filter" };
4632
+ const cell = el.closest ? el.closest("th, td") : null;
4633
+ if (!cell || !this.contains(cell)) return null;
4634
+ const tr = cell.parentElement;
4635
+ if (!tr) return null;
4636
+ const rowHeader = tr.querySelector ? tr.querySelector("th[role='rowheader']") : null;
4637
+ return {
4638
+ kind: "cell",
4639
+ row: rowHeader ? rowHeader.textContent : (tr.dataset ? tr.dataset.row : undefined),
4640
+ col: Array.from(tr.children).indexOf(cell),
4641
+ isHeader: !!(cell.closest && cell.closest("thead")),
4642
+ };
4643
+ }
4644
+ _pivotRestoreFocus(snap) {
4645
+ if (!snap) return;
4646
+ // Deferred so it runs after the base class's generic focus preservation
4647
+ // (U-10): the pivot rebuilds its whole table, so the base would otherwise
4648
+ // land focus on whatever focusable sits at the old index.
4649
+ queueMicrotask(() => {
4650
+ if (!this.isConnected) return;
4651
+ const active = document.activeElement;
4652
+ if (active && active !== this && active !== document.body && !this.contains(active)) return;
4653
+ if (snap.kind === "filter") {
4654
+ const f = this.querySelector(".c-pivot__filter");
4655
+ if (f) { try { f.focus(); } catch (e) {} }
4656
+ return;
4657
+ }
4658
+ const table = this.querySelector("table");
4659
+ if (!table) return;
4660
+ let cell = null;
4661
+ if (snap.isHeader) {
4662
+ const hr = table.querySelector("thead tr");
4663
+ if (hr) cell = hr.children[snap.col] || null;
4664
+ } else {
4665
+ const rowHeader = snap.row != null ? Array.from(table.querySelectorAll("th[role='rowheader']")).find((th) => th.textContent === snap.row) : null;
4666
+ const tr = rowHeader ? rowHeader.parentElement : null;
4667
+ if (tr && tr.children[snap.col]) cell = tr.children[snap.col];
4668
+ }
4669
+ if (cell) {
4670
+ table.querySelectorAll('[tabindex="0"]').forEach((c) => c.setAttribute("tabindex", "-1"));
4671
+ cell.setAttribute("tabindex", "0");
4672
+ try { cell.focus(); } catch (e) {}
4673
+ }
4674
+ });
4675
+ }
4403
4676
  render() {
4404
4677
  this.classList.add("c-pivot");
4678
+ const focusSnap = this._pivotCaptureFocus();
4405
4679
  wireStates(this);
4406
4680
  loadRemote(this, ["data"]);
4407
4681
  if (renderStates(this, "pivot")) return;
@@ -4469,6 +4743,8 @@ class ContourPivot extends ContourBase {
4469
4743
  const table = document.createElement("table");
4470
4744
  table.className = "c-table c-pivot__table";
4471
4745
  table.setAttribute("role", "grid");
4746
+ // U-27: the generated table region carries an accessible name.
4747
+ table.setAttribute("aria-label", this.getAttribute("label") || labelText(this, "pivot", "Pivot table"));
4472
4748
  table.setAttribute("aria-rowcount", String(visibleRows.length + 1));
4473
4749
  table.setAttribute("aria-colcount", String(visibleCols.length + 1));
4474
4750
  const thead = document.createElement("thead");
@@ -4523,10 +4799,29 @@ class ContourPivot extends ContourBase {
4523
4799
  table.appendChild(tbody);
4524
4800
  wrap.appendChild(table);
4525
4801
  this.appendChild(wrap);
4802
+ // U-10: restore focus to the same cell (or the filter input) after rebuild.
4803
+ this._pivotRestoreFocus(focusSnap);
4526
4804
  }
4527
4805
  enhance() {
4528
4806
  if (this._wiredPivot) return;
4529
4807
  this._wiredPivot = true;
4808
+ // U-10: remember the last focused cell / filter input across a re-render.
4809
+ this.addEventListener("focusin", (e) => {
4810
+ const t = e.target;
4811
+ if (!t || !this.contains(t)) return;
4812
+ if (t.classList && t.classList.contains("c-pivot__filter")) { this._pivotFocus = { kind: "filter" }; return; }
4813
+ const cell = t.closest ? t.closest("th, td") : null;
4814
+ if (!cell || !this.contains(cell)) return;
4815
+ const tr = cell.parentElement;
4816
+ if (!tr) return;
4817
+ const rowHeader = tr.querySelector ? tr.querySelector("th[role='rowheader']") : null;
4818
+ this._pivotFocus = {
4819
+ kind: "cell",
4820
+ row: rowHeader ? rowHeader.textContent : (tr.dataset ? tr.dataset.row : undefined),
4821
+ col: Array.from(tr.children).indexOf(cell),
4822
+ isHeader: !!(cell.closest && cell.closest("thead")),
4823
+ };
4824
+ });
4530
4825
  this.addEventListener("click", (e) => {
4531
4826
  const th = e.target && e.target.closest ? e.target.closest("th") : null;
4532
4827
  const td = e.target && e.target.closest ? e.target.closest("td") : null;
@@ -5114,8 +5409,8 @@ class ContourSelectionGroup extends ContourBase {
5114
5409
  * 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`.
5115
5410
  */
5116
5411
  class ContourLegend extends ContourBase {
5117
- static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "brownout", "brownout-level", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "no-data-label", "size", "table", "classification", "audit", "continuous", "ends", "caption", "graduated", "cache-key", "no-cache", "domain", "reverse"]; }
5118
- 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" }, graduated: { attribute: "graduated", type: Boolean }, domain: { attribute: "domain" }, reverse: { attribute: "reverse", type: Boolean } }; }
5412
+ static get observed() { return ["title", "ramp", "scale", "items", "method", "norm", "selectable", "selected", "collapsible", "collapsed", "brownout", "brownout-level", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "glyphs", "thresholds", "breaks", "no-data-color", "no-data-label", "size", "table", "classification", "audit", "continuous", "ends", "caption", "graduated", "cache-key", "no-cache", "domain", "reverse"]; }
5413
+ 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 }, selected: { attribute: "selected" }, collapsible: { attribute: "collapsible", type: Boolean }, collapsed: { attribute: "collapsed", type: Boolean }, src: { attribute: "src" }, graduated: { attribute: "graduated", type: Boolean }, domain: { attribute: "domain" }, reverse: { attribute: "reverse", type: Boolean } }; }
5119
5414
  render() {
5120
5415
  this.classList.add("c-legend");
5121
5416
  const graduated = this.hasAttribute("graduated");
@@ -5161,18 +5456,31 @@ class ContourLegend extends ContourBase {
5161
5456
  const list = this.ensure(".c-legend__items", () => { const el = document.createElement("div"); el.className = "c-legend__items"; return el; });
5162
5457
  if (this.hasAttribute("selectable")) {
5163
5458
  list.setAttribute("role", "group");
5459
+ list.setAttribute("aria-label", this.getAttribute("aria-label") || title || labelText(this, "legend-items", "Legend items"));
5164
5460
  } else {
5165
- // Host already has role="list"; inner container should be generic
5461
+ // Host already has role="list"; the inner container must stay generic.
5462
+ // Naming it would make it an accessible child that is not a listitem
5463
+ // (axe aria-required-children), so the name belongs on the host list.
5166
5464
  list.removeAttribute("role");
5465
+ list.removeAttribute("aria-label");
5466
+ if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", title || labelText(this, "legend-items", "Legend items"));
5167
5467
  }
5168
- if (title) list.setAttribute("aria-label", title);
5169
5468
  list.innerHTML = "";
5469
+ // U-23: controlled selected keys (JSON array or comma list) highlight
5470
+ // matching items via `is-selected` + aria-current.
5471
+ const selectedRaw = this.getAttribute("selected");
5472
+ let selectedSet = new Set();
5473
+ if (selectedRaw) {
5474
+ try { const p = JSON.parse(selectedRaw); selectedSet = new Set((Array.isArray(p) ? p : [selectedRaw]).map(String)); }
5475
+ catch (e) { selectedSet = new Set(selectedRaw.split(",").map((s) => s.trim()).filter(Boolean)); }
5476
+ }
5170
5477
  parsed.forEach((it) => {
5171
5478
  const label = typeof it === "string" ? it : (it.label || String(it));
5172
5479
  const key = typeof it === "string" ? it : (it.key || it.label || String(it));
5173
5480
  const item = document.createElement("div");
5174
5481
  item.className = "c-legend__item";
5175
5482
  item.setAttribute("tabindex", "-1");
5483
+ if (selectedSet.has(String(key))) { item.classList.add("is-selected"); item.setAttribute("aria-current", "true"); }
5176
5484
  if (selectable) {
5177
5485
  item.setAttribute("role", "button");
5178
5486
  // Restore pressed state from host's set so re-render doesn't reset items to pressed=true; set tracks UNPRESSED keys.
@@ -5184,6 +5492,8 @@ class ContourLegend extends ContourBase {
5184
5492
  // aria-selected is not valid on role="listitem"; omit for non-selectable legends
5185
5493
  }
5186
5494
  const sw = document.createElement("span");
5495
+ // U-23: the swatch is decorative; the item's label is its name.
5496
+ sw.setAttribute("aria-hidden", "true");
5187
5497
  if (graduated) {
5188
5498
  sw.className = "c-legend__swatch c-legend__swatch--graduated";
5189
5499
  const gSize = it && it.size != null ? it.size : (it && it.value != null ? it.value : 1);
@@ -5239,6 +5549,22 @@ class ContourLegend extends ContourBase {
5239
5549
  }
5240
5550
  list.appendChild(item);
5241
5551
  });
5552
+ // U-23: collapsible contract — a toggle button controls the list; the
5553
+ // `collapsed` attribute is the controlled state, so the host owns it.
5554
+ if (this.hasAttribute("collapsible")) {
5555
+ if (!list.id) list.id = contourId("legend-items");
5556
+ const toggle = this.ensure(".c-legend__toggle", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-legend__toggle"; el.type = "button"; return el; });
5557
+ const collapsed = this._legendCollapsed != null ? this._legendCollapsed : this.hasAttribute("collapsed");
5558
+ toggle.textContent = collapsed ? labelText(this, "show-legend", "Show legend") : labelText(this, "hide-legend", "Hide legend");
5559
+ toggle.setAttribute("aria-expanded", String(!collapsed));
5560
+ toggle.setAttribute("aria-controls", list.id);
5561
+ list.hidden = collapsed;
5562
+ if (toggle.parentNode !== this) this.insertBefore(toggle, list);
5563
+ } else {
5564
+ const toggle = this.querySelector(".c-legend__toggle");
5565
+ if (toggle) toggle.remove();
5566
+ list.hidden = false;
5567
+ }
5242
5568
  } catch (e) { warnBadJson(this, "attribute", e); }
5243
5569
  } else {
5244
5570
  const list = this.querySelector(".c-legend__items");
@@ -5398,6 +5724,9 @@ class ContourLegend extends ContourBase {
5398
5724
  const ramp = this.getAttribute("ramp");
5399
5725
  if (ramp) {
5400
5726
  const r = this.ensure(".c-legend__ramp", () => { const el = document.createElement("div"); el.className = "c-legend__ramp"; return el; });
5727
+ // U-23: the ramp is a named scale, not an unlabelled div.
5728
+ r.setAttribute("role", "group");
5729
+ r.setAttribute("aria-label", this.getAttribute("aria-label") || this.getAttribute("title") || labelText(this, "legend-ramp", "Legend scale"));
5401
5730
  r.style.background = safeColor(ramp);
5402
5731
  // ramp routing: equal-width segments with break labels
5403
5732
  const breaksAttr = this.getAttribute("breaks");
@@ -5446,6 +5775,17 @@ class ContourLegend extends ContourBase {
5446
5775
  if (this._wiredLegend) return;
5447
5776
  this._wiredLegend = true;
5448
5777
  this.addEventListener("click", (e) => {
5778
+ // U-23: the collapsible toggle owns the `collapsed` attribute.
5779
+ const toggleBtn = e.target && e.target.closest ? e.target.closest(".c-legend__toggle") : null;
5780
+ if (toggleBtn && this.contains(toggleBtn)) {
5781
+ e.preventDefault();
5782
+ // U-23: toggle internal state and re-render. Writing the observed
5783
+ // `collapsed` attribute here would re-enter the render (wc-contract).
5784
+ const now = this._legendCollapsed != null ? this._legendCollapsed : this.hasAttribute("collapsed");
5785
+ this._legendCollapsed = !now;
5786
+ this.requestRender();
5787
+ return;
5788
+ }
5449
5789
  // Read selectable PER-CLICK (not captured in enhance): handler uses current value if attribute added/removed later (LS-5 behavioral break).
5450
5790
  if (!this.hasAttribute("selectable")) return;
5451
5791
  const btn = e.target && e.target.closest ? e.target.closest(".c-legend__item") : null;
@@ -5558,8 +5898,8 @@ define("contour-legend", ContourLegend);
5558
5898
  * Attributes: `label`, `value`, `point`, `line`, `empty`, `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
5559
5899
  */
5560
5900
  class ContourMeasure extends ContourBase {
5561
- static get observed() { return ["label", "value", "point", "line", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
5562
- static get properties() { return { label: { attribute: "label" }, value: { attribute: "value" }, point: { attribute: "point" }, line: { attribute: "line" }, unit: { attribute: "unit" }, src: { attribute: "src" } }; }
5901
+ static get observed() { return ["label", "unit-label", "value", "point", "line", "unit", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
5902
+ static get properties() { return { label: { attribute: "label" }, "unit-label": { attribute: "unit-label" }, value: { attribute: "value" }, point: { attribute: "point" }, line: { attribute: "line" }, unit: { attribute: "unit" }, src: { attribute: "src" } }; }
5563
5903
  render() {
5564
5904
  this.classList.add("c-measure");
5565
5905
  this.setAttribute("role", "group");
@@ -5591,7 +5931,9 @@ class ContourMeasure extends ContourBase {
5591
5931
  }
5592
5932
  // unit selector
5593
5933
  let sel = this.querySelector(".c-measure__unit-select");
5594
- if (!sel) { sel = document.createElement("select"); sel.className = "c-select c-measure__unit-select"; sel.setAttribute("aria-label", labelText(this, "unit", "Unit")); sel.setAttribute("data-contour-label", "true"); this.appendChild(sel); }
5934
+ if (!sel) { sel = document.createElement("select"); sel.className = "c-select c-measure__unit-select"; sel.setAttribute("data-contour-label", "true"); this.appendChild(sel); }
5935
+ // U-29: the unit select accepts an explicit accessible name.
5936
+ sel.setAttribute("aria-label", this.getAttribute("unit-label") || labelText(this, "unit", "Unit"));
5595
5937
  ["m","km","mi","ft"].forEach((u) => {
5596
5938
  if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
5597
5939
  });
@@ -5705,11 +6047,19 @@ class ContourTimeline extends ContourBase {
5705
6047
  define("contour-timeline", ContourTimeline);
5706
6048
  /**
5707
6049
  * Heatmap: web component wrapper.
5708
- * Attributes: `cells`, `count`, `legend`, `empty`, `loading`, `values`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
6050
+ * Attributes: `cells`, `count`, `columns`, `values`, `legend`, `empty`,
6051
+ * `loading`, `error`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
6052
+ *
6053
+ * Cell geometry is arbitrary: `columns` sets the row width (rows = ceil(cells /
6054
+ * columns)); without it the grid is as square as possible. `cells`/`count`
6055
+ * defaults to the length of `values`, so a flat value list defines the shape.
6056
+ * Large data is bounded by a documented **cell budget of 200**: beyond it the
6057
+ * render is sampled to the first 200 cells and `contour:cap` reports
6058
+ * `{ series: 1, total, shown }` so a consumer knows the grid was truncated.
5709
6059
  */
5710
6060
  class ContourHeatmap extends ContourBase {
5711
- static get observed() { return ["cells", "count", "legend", "brownout", "brownout-level", "empty", "loading", "values", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "dir", "no-cache"]; }
5712
- static get properties() { return { cells: { attribute: "cells" }, count: { attribute: "count" }, legend: { attribute: "legend" }, src: { attribute: "src" } }; }
6061
+ static get observed() { return ["cells", "count", "columns", "legend", "brownout", "brownout-level", "empty", "loading", "values", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "dir", "no-cache"]; }
6062
+ static get properties() { return { cells: { attribute: "cells" }, count: { attribute: "count" }, columns: { attribute: "columns" }, legend: { attribute: "legend" }, src: { attribute: "src" } }; }
5713
6063
  render() {
5714
6064
  this.classList.add("c-heatmap");
5715
6065
  if (!this.hasAttribute("role")) this.setAttribute("role", "grid");
@@ -5721,7 +6071,7 @@ class ContourHeatmap extends ContourBase {
5721
6071
  // precedence over the generated grid.
5722
6072
  const authoredCells = Array.from(this.querySelectorAll(":scope > .c-heatmap__cell"));
5723
6073
  if (authoredCells.length) {
5724
- const cols = Math.ceil(Math.sqrt(authoredCells.length));
6074
+ const cols = Math.max(1, parseInt(this.getAttribute("columns") || "0", 10) || Math.ceil(Math.sqrt(authoredCells.length)));
5725
6075
  this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
5726
6076
  this.style.inlineSize = "16rem";
5727
6077
  // Wrap authored cells in rows so gridcells have a required row parent
@@ -5737,13 +6087,18 @@ class ContourHeatmap extends ContourBase {
5737
6087
  });
5738
6088
  } else {
5739
6089
  Array.from(this.querySelectorAll(".c-heatmap__cell")).forEach((n) => n.remove());
5740
- const count = Math.min(200, Math.max(0, parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0));
5741
- const cols = count > 0 ? Math.ceil(Math.sqrt(count)) : 1;
6090
+ let values = [];
6091
+ try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
6092
+ if (!Array.isArray(values)) values = [];
6093
+ const HEATMAP_CELL_CAP = 200;
6094
+ const declaredCount = parseInt(this.getAttribute("cells") || this.getAttribute("count") || "0", 10) || 0;
6095
+ const requested = declaredCount > 0 ? declaredCount : values.length;
6096
+ const count = Math.min(HEATMAP_CELL_CAP, Math.max(0, requested));
6097
+ const cols = count > 0 ? Math.max(1, parseInt(this.getAttribute("columns") || "0", 10) || Math.ceil(Math.sqrt(count))) : 1;
5742
6098
  this.style.gridTemplateColumns = "repeat(" + cols + ", 1fr)";
5743
6099
  this.style.inlineSize = "16rem";
6100
+ if (requested > HEATMAP_CELL_CAP) this.dispatchEvent(new CustomEvent("contour:cap", { bubbles: true, composed: true, detail: { series: 1, total: requested, shown: HEATMAP_CELL_CAP } }));
5744
6101
  if (count > 0) {
5745
- let values = [];
5746
- try { values = JSON.parse(this.getAttribute("values") || "[]"); } catch (e) { values = []; }
5747
6102
  // Value→colour (DC-2): cells were all `--color-surface-1` (white boxes); now normalised to --chart-seq-1..7 ramp via --c; non-numeric falls back to empty surface.
5748
6103
  const nums = values.map((v) => {
5749
6104
  const n = Number(v);
@@ -6433,6 +6788,26 @@ function readRuleValue(row) {
6433
6788
  if (nullBox) return nullBox.checked ? "null" : "";
6434
6789
  return row.querySelector(".c-query-builder__value")?.value || "";
6435
6790
  }
6791
+ /**
6792
+ * Query builder: a controlled rule editor. Emits `contour:change` with
6793
+ * `{ query, draft }`.
6794
+ *
6795
+ * Contract (U-13) — all three inputs are JSON **attribute strings**:
6796
+ * - `fields`: an array of column definitions. Each item is a string, or an
6797
+ * object `{ value?, key?, label?, name?, type?, options? }`. `type` is one of
6798
+ * `text | number | date | enum | null | range` and selects the value editor;
6799
+ * `enum` requires `options` (array of strings or `{ value, label }`). A map
6800
+ * object (`{ "<key>": <meta> }`) is also accepted and normalised to the array
6801
+ * form. A non-array, non-map value degrades to an empty field list rather than
6802
+ * throwing (which used to surface as "Component failed to render").
6803
+ * - `query`: an array of rule objects `{ id?, field, op, value, connector?,
6804
+ * group?, not? }` (`op` ∈ `= != > < contains`; `connector` ∈ `AND OR` on every
6805
+ * rule after the first; `group` groups consecutive rules; `not` negates). An
6806
+ * object with a `rules` array is also accepted.
6807
+ * - `draft`: boolean. While present, edits are held locally and announced with
6808
+ * `draft:true`; removing it (or `commitDraft()`) finalises the draft into
6809
+ * `query` and announces `draft:false`.
6810
+ */
6436
6811
  class ContourQueryBuilder extends ContourBase {
6437
6812
  static get observed() { return ["query", "fields", "draft"]; }
6438
6813
  static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" }, draft: { attribute: "draft", type: Boolean } }; }
@@ -6506,16 +6881,34 @@ class ContourQueryBuilder extends ContourBase {
6506
6881
  render() {
6507
6882
  this.classList.add("c-query-builder");
6508
6883
  const fields = this.getAttribute("fields");
6884
+ // U-13: accept an array of strings/objects OR a `{ key: meta }` map; never
6885
+ // throw on an unexpected shape (that surfaced as "Component failed to
6886
+ // render"). A field item's key is `value ?? key ?? label ?? name`.
6887
+ const fieldKey = (f) => (typeof f === "string" ? f : (f.value ?? f.key ?? f.label ?? f.name ?? ""));
6888
+ const fieldLabel = (f) => (typeof f === "string" ? f : (f.label ?? f.name ?? f.value ?? f.key ?? ""));
6509
6889
  let fieldList = [];
6510
- if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
6890
+ if (fields) {
6891
+ try {
6892
+ const p = JSON.parse(fields);
6893
+ if (Array.isArray(p)) fieldList = p;
6894
+ else if (p && typeof p === "object") fieldList = Object.keys(p).map((k) => (p[k] && typeof p[k] === "object" ? { value: k, ...p[k] } : k));
6895
+ } catch (e) { fieldList = []; }
6896
+ }
6511
6897
  const query = this.getAttribute("query");
6512
6898
  let rules = [];
6513
6899
  // R34-165: in draft mode the rows come from the held draft, not the attr.
6514
6900
  if (this.hasAttribute("draft") && this._draftRows) {
6515
6901
  rules = this._draftRows;
6516
- } else if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
6902
+ } else if (query) {
6903
+ try {
6904
+ const p = JSON.parse(query);
6905
+ // U-13: an array of rules, or an object carrying a `rules` array.
6906
+ if (Array.isArray(p)) rules = p;
6907
+ else if (p && Array.isArray(p.rules)) rules = p.rules;
6908
+ } catch (e) { rules = []; }
6909
+ }
6517
6910
  // Field metadata (type/options) drives the value editor (R34-165).
6518
- const fieldMeta = (name) => fieldList.find((f) => (typeof f === "string" ? f : (f.value || f.label || "")) === name) || {};
6911
+ const fieldMeta = (name) => fieldList.find((f) => fieldKey(f) === name) || {};
6519
6912
  const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
6520
6913
  Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector, .c-query-builder__group")).forEach((n) => n.remove());
6521
6914
  let currentGroup = null;
@@ -6577,8 +6970,8 @@ class ContourQueryBuilder extends ContourBase {
6577
6970
  field.setAttribute("aria-label", labelText(this, "field", "Field") + " " + (i + 1));
6578
6971
  fieldList.forEach((f) => {
6579
6972
  const opt = document.createElement("option");
6580
- opt.value = typeof f === "string" ? f : (f.value || f.label || "");
6581
- opt.textContent = typeof f === "string" ? f : (f.label || f.value || "");
6973
+ opt.value = fieldKey(f);
6974
+ opt.textContent = fieldLabel(f);
6582
6975
  if (opt.value === rule.field) opt.selected = true;
6583
6976
  field.appendChild(opt);
6584
6977
  });