contour-ds 1.9.1 → 1.11.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 (134) hide show
  1. package/README.md +4 -4
  2. package/dist/agent-map-wiring.json +2 -1
  3. package/dist/build-manifest.json +208 -207
  4. package/dist/contour-wc-content.esm.js +6 -1
  5. package/dist/contour-wc-content.esm.min.js +1 -1
  6. package/dist/contour-wc-core.esm.js +712 -45
  7. package/dist/contour-wc-core.esm.min.js +1 -1
  8. package/dist/contour-wc-dashboard.esm.js +691 -93
  9. package/dist/contour-wc-dashboard.esm.min.js +1 -1
  10. package/dist/contour-wc-data.esm.js +562 -73
  11. package/dist/contour-wc-data.esm.min.js +1 -1
  12. package/dist/contour-wc-docs.esm.js +6 -1
  13. package/dist/contour-wc-docs.esm.min.js +1 -1
  14. package/dist/contour-wc-feedback.esm.js +265 -29
  15. package/dist/contour-wc-feedback.esm.min.js +1 -1
  16. package/dist/contour-wc-forms.esm.js +138 -40
  17. package/dist/contour-wc-forms.esm.min.js +1 -1
  18. package/dist/contour-wc-interaction.esm.js +69 -5
  19. package/dist/contour-wc-interaction.esm.min.js +1 -1
  20. package/dist/contour-wc-layout.esm.js +77 -10
  21. package/dist/contour-wc-layout.esm.min.js +1 -1
  22. package/dist/contour-wc-map.esm.js +146 -13
  23. package/dist/contour-wc-map.esm.min.js +1 -1
  24. package/dist/contour-wc-misc.esm.js +6 -1
  25. package/dist/contour-wc-misc.esm.min.js +1 -1
  26. package/dist/contour-wc-navigation.esm.js +141 -20
  27. package/dist/contour-wc-navigation.esm.min.js +1 -1
  28. package/dist/contour-wc-ui.esm.js +585 -87
  29. package/dist/contour-wc-ui.esm.min.js +1 -1
  30. package/dist/contour-wc.esm.js +2781 -334
  31. package/dist/contour-wc.esm.min.js +1 -1
  32. package/dist/contour-wc.js +2781 -334
  33. package/dist/contour-wc.min.js +1 -1
  34. package/dist/contour.code-snippets +45 -1
  35. package/dist/contour.components.json +11832 -133
  36. package/dist/contour.css +1096 -103
  37. package/dist/contour.d.ts +91 -69
  38. package/dist/contour.esm.js +138 -21
  39. package/dist/contour.esm.min.js +1 -1
  40. package/dist/contour.html-data.json +275 -11
  41. package/dist/contour.js +138 -21
  42. package/dist/contour.min.css +1 -1
  43. package/dist/contour.min.js +1 -1
  44. package/dist/contour.react.d.ts +5 -1
  45. package/dist/contour.single.html +2 -2
  46. package/dist/contour.single.min.css +1 -1
  47. package/dist/contour.tokens.json +36 -1
  48. package/dist/contour.vue.d.ts +5 -1
  49. package/dist/contour.web-types.json +267 -11
  50. package/dist/custom-elements.json +1334 -56
  51. package/dist/docs/actions.md +1 -1
  52. package/dist/docs/affordances.md +1 -1
  53. package/dist/docs/apireference.md +1 -1
  54. package/dist/docs/colour.md +1 -1
  55. package/dist/docs/componentindex.md +1 -1
  56. package/dist/docs/data.md +8 -2
  57. package/dist/docs/docs.md +1 -1
  58. package/dist/docs/feedback.md +1 -1
  59. package/dist/docs/field.md +1 -3
  60. package/dist/docs/forms.md +1 -1
  61. package/dist/docs/index.json +7 -7
  62. package/dist/docs/install.md +1 -1
  63. package/dist/docs/landing.md +1 -1
  64. package/dist/docs/mapengine.md +1 -1
  65. package/dist/docs/motion.md +1 -1
  66. package/dist/docs/navigation.md +1 -1
  67. package/dist/docs/overlays.md +1 -1
  68. package/dist/docs/overview.md +1 -1
  69. package/dist/docs/patterns.md +1 -1
  70. package/dist/docs/playground.md +1 -1
  71. package/dist/docs/principles.md +1 -1
  72. package/dist/docs/recipes.md +1 -1
  73. package/dist/docs/space.md +1 -1
  74. package/dist/docs/status.md +1 -1
  75. package/dist/docs/surfaces.md +1 -1
  76. package/dist/docs/theming.md +1 -1
  77. package/dist/docs/type.md +1 -1
  78. package/dist/docs/webcomponents.md +1 -1
  79. package/dist/hljs.css +17 -0
  80. package/dist/map-chrome-contract.json +26 -0
  81. package/dist/map-chrome.mapbox.css +121 -0
  82. package/dist/map-chrome.maplibre.css +121 -0
  83. package/dist/registry/items/contour-core.json +2 -2
  84. package/dist/registry/items/contour-data.json +2 -2
  85. package/dist/registry/items/contour-docs.json +2 -2
  86. package/dist/registry/items/contour-landing.json +2 -2
  87. package/dist/registry/registry.json +8 -8
  88. package/dist/surfaces/contour-core.min.css +1 -1
  89. package/dist/surfaces/contour-data.min.css +1 -1
  90. package/dist/surfaces/contour-docs.min.css +1 -1
  91. package/dist/surfaces/contour-landing.min.css +1 -1
  92. package/dist/wc/behaviours.mjs +11 -3
  93. package/dist/wc/core.mjs +307 -32
  94. package/dist/wc/dashboard.mjs +129 -20
  95. package/dist/wc/data-chart.mjs +174 -21
  96. package/dist/wc/data-export.mjs +150 -29
  97. package/dist/wc/data-gauge.mjs +60 -8
  98. package/dist/wc/data-geo.mjs +1 -1
  99. package/dist/wc/data-legend.mjs +15 -2
  100. package/dist/wc/data-readout.mjs +12 -1
  101. package/dist/wc/data-series.mjs +73 -5
  102. package/dist/wc/data-table.mjs +37 -8
  103. package/dist/wc/feedback.mjs +259 -28
  104. package/dist/wc/forms-controls.mjs +44 -16
  105. package/dist/wc/forms-field.mjs +46 -4
  106. package/dist/wc/forms-groups.mjs +31 -8
  107. package/dist/wc/forms-input.mjs +11 -11
  108. package/dist/wc/glyph.mjs +37 -0
  109. package/dist/wc/index.mjs +1 -1
  110. package/dist/wc/interaction.mjs +63 -4
  111. package/dist/wc/layout.mjs +72 -10
  112. package/dist/wc/map.mjs +140 -12
  113. package/dist/wc/navigation-menu.mjs +43 -9
  114. package/dist/wc/navigation-shell.mjs +39 -6
  115. package/dist/wc/navigation-tree.mjs +53 -4
  116. package/dist/wc/registration.mjs +5 -0
  117. package/dist/wc/states.mjs +350 -9
  118. package/dist/wc/svg.mjs +43 -0
  119. package/dist/wc/ui-atoms.mjs +28 -7
  120. package/dist/wc/ui-data.mjs +315 -28
  121. package/dist/wc/ui-feedback.mjs +36 -11
  122. package/dist/wc/ui-inputs.mjs +63 -25
  123. package/dist/wc/ui-overlays.mjs +138 -16
  124. package/integrations/ai/v0-prompt.md +1 -1
  125. package/integrations/frameworks/fixtures/authored/sample.jsx +15 -0
  126. package/integrations/frameworks/fixtures/authored/sample.vue +15 -0
  127. package/integrations/frameworks/fixtures/dist/rendered.html +32 -0
  128. package/integrations/libreship/contract.json +1027 -0
  129. package/integrations/native/README.md +24 -4
  130. package/integrations/native/build/android/colors.xml +278 -0
  131. package/integrations/native/build/flutter/contour_tokens.dart +280 -0
  132. package/integrations/native/build/ios/ContourTokens.swift +280 -0
  133. package/integrations/validate-markup.mjs +57 -7
  134. package/package.json +43 -17
@@ -1,6 +1,11 @@
1
- import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERVED, REGISTERED, applyLabel, bearing, clampLat, contourId, cssLength, define, flagOn, flagOnValue, formatValue, haversine, headingTag, iconMarkup, isRtl, labelText, levelFromAttributes, mercatorResolution, navKey, normaliseLng, onDispose, safeColor, safeHref, sanitizeHtml, setHTML, simple, statusIcon, supportsUntilFound, unwrapBounds, warnBadJson, wcEmitOverlay, withBrownout, MARKER_SHAPES, arcPath, assignMarkers, barRects, compassNeedle, contourPaths, donutSlices, isMissing, marchingSquares, markerStyles, niceTicks, polylinePoints, scaleBarTicks, smoothPath, modalContain, wcReset, wireCombobox, wireCopy, wireMenu, wirePagination, wireRemovable, wireSegmented, wireTabs, wireTree, STATE_FALLBACK, loadRemote, parseArrayAttr, remoteData, remoteInvalidate, remoteRefresh, remoteVisible, renderEmpty, renderStates, stateLabel, watchViewport, wireStates } from "./contour-wc-core.esm.js";
1
+ import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERVED, REGISTERED, applyLabel, bearing, clampLat, contourId, cssLength, define, flagOn, flagOnValue, formatValue, haversine, headingTag, iconMarkup, isRtl, labelText, levelFromAttributes, mercatorResolution, navKey, normaliseLng, onDispose, safeColor, safeHref, sanitizeHtml, setHTML, simple, statusIcon, supportsUntilFound, unwrapBounds, warnBadJson, wcEmitOverlay, withBrownout, PROPERTY_FIELDS, normalizeProperty, propertyDescriptor, propertyTypeOf, contourDiagnosticsEnabled, setContourDiagnostics, MARKER_SHAPES, arcPath, assignMarkers, barRects, compassNeedle, contourPaths, donutSlices, isMissing, marchingSquares, markerStyles, niceTicks, polylinePoints, scaleBarTicks, smoothPath, modalContain, wcReset, wireCombobox, wireCopy, wireMenu, wirePagination, wireRemovable, wireSegmented, wireTabs, wireTree, STATE_FALLBACK, loadRemote, parseArrayAttr, remoteData, remoteInvalidate, remoteRefresh, remoteVisible, renderEmpty, renderStates, stateLabel, virtualRange, watchViewport, wireStates } from "./contour-wc-core.esm.js";
2
2
 
3
3
  // ---- Registration: class-only wrappers run last (define() skips claimed names) ----
4
+ // Layout atoms. Each is the element form of a layout primitive and is inert
5
+ // by design: no data attribute, no state, no events — the `c-*` class is the
6
+ // whole contract, and tools/check-layout.mjs pins the closed set. A
7
+ // `contour-cluster` is not a data component missing a payload; reach for a
8
+ // mark component (chart, legend, table) when the region carries data.
4
9
  define("contour-box", simple(["c-box"]));
5
10
  define("contour-cluster", simple(["c-cluster"]));
6
11
  define("contour-container", simple(["c-container"]));
@@ -698,7 +703,18 @@ class ContourKpi extends ContourBase {
698
703
  if (variant) this.classList.add("c-kpi--" + variant);
699
704
  if (value) {
700
705
  const v = this.ensure(".c-kpi__value", () => { const el = document.createElement("div"); el.className = "c-kpi__value"; el.setAttribute("aria-live", "polite"); return el; });
701
- v.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
706
+ const text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
707
+ // R33-102: cross-fade the value when it changes (not on first render).
708
+ // The node may be recreated per render, so the last value is tracked on
709
+ // the host; each change restarts the one-shot animation.
710
+ const changed = this._kpiLastValue != null && this._kpiLastValue !== text;
711
+ this._kpiLastValue = text;
712
+ v.textContent = text;
713
+ if (changed) {
714
+ v.classList.remove("is-updating");
715
+ void v.offsetWidth;
716
+ v.classList.add("is-updating");
717
+ }
702
718
  } else {
703
719
  const v = this.querySelector(".c-kpi__value");
704
720
  if (v) v.remove();
@@ -954,6 +970,20 @@ class ContourTable extends ContourBase {
954
970
  if (!this.hasAttribute("role")) this.setAttribute("role", "region");
955
971
  // An authored label names the table; "Table" is the fallback.
956
972
  if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Table");
973
+ // R34-123: a stable, announced selected-count. The region is visually
974
+ // hidden and polite, so the count is read without shifting the layout;
975
+ // clearing the selection (select-all off) resets it to empty.
976
+ let selStatus = this.querySelector(".c-table__selection-status");
977
+ if (!selStatus) {
978
+ selStatus = document.createElement("span");
979
+ selStatus.className = "c-table__selection-status visually-hidden";
980
+ selStatus.setAttribute("aria-live", "polite");
981
+ this.appendChild(selStatus);
982
+ }
983
+ const selCount = this._selectionControlled
984
+ ? (this._selectedKeys ? this._selectedKeys.size : 0)
985
+ : (this._selectedRows ? this._selectedRows.size : 0);
986
+ selStatus.textContent = selCount ? `${selCount} selected` : "";
957
987
  wireStates(this);
958
988
  loadRemote(this, "rows");
959
989
  if (renderStates(this, "table")) return;
@@ -962,7 +992,7 @@ class ContourTable extends ContourBase {
962
992
  const columns = this.getAttribute("columns");
963
993
  const rows = remoteData(this, "rows");
964
994
  // Slot composition: an authored table wins over the JSON attributes.
965
- const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-table-wrap"));
995
+ const authored = Array.from(this.children).filter((n) => !n.classList || (!n.classList.contains("c-table-wrap") && !n.classList.contains("c-table__selection-status")));
966
996
  if (columns && rows && !authored.length) {
967
997
  try {
968
998
  const cols = JSON.parse(columns);
@@ -1173,9 +1203,10 @@ if (isFilter) {
1173
1203
  let windowStart = 0;
1174
1204
  let visibleData = pageData;
1175
1205
  if (useVirtual) {
1176
- const maxStart = Math.max(0, pageData.length - windowSize);
1177
- // Compute from wrapScrollTop, not wrap.scrollTop: clearing the body above already clamped the live scrollTop to 0, so reading it here would always yield windowStart 0 and the table would snap back to the first row on every scroll frame (DW-5).
1178
- windowStart = Math.min(maxStart, Math.max(0, Math.floor(wrapScrollTop / rowHeight) - overscan));
1206
+ // R34-58: the start clamp is the shared virtualRange geometry (the
1207
+ // grid uses the same helper), so the table and grid agree on where a
1208
+ // scroll offset lands; the table keeps its count-based window size.
1209
+ windowStart = virtualRange(wrapScrollTop, rowHeight, (windowSize - overscan) * rowHeight, pageData.length, overscan).start;
1179
1210
  visibleData = pageData.slice(windowStart, windowStart + windowSize + overscan * 2);
1180
1211
  table.setAttribute("aria-rowcount", String(pageData.length + 1));
1181
1212
  // Record which window is on screen so the scroll handler can tell a scroll that moves the window from one that does not.
@@ -1222,6 +1253,7 @@ if (isSelect) {
1222
1253
  cb.type = "checkbox";
1223
1254
  cb.className = "c-table__row-select";
1224
1255
  cb.dataset.rowIndex = String(windowStart + ri);
1256
+ cb.setAttribute("aria-label", labelText(this, "select-row", "Select row") + " " + (rowKey ?? (windowStart + ri + 1)));
1225
1257
  // The base class preserves form-control state across a re-render; UNKEYED checkboxes restore by position, which would paint the pre-sort checked positions onto the new row order (and a virtual window's onto different rows). The preserve key makes that restoration identity-based: a row's checked state follows its datum, and a row newly scrolled into the window keeps the state render gave it.
1226
1258
  cb.dataset.contourPreserveKey = rowKey;
1227
1259
  // Controlled mode checks by KEY (survives sort/filter/window moves); legacy mode keeps the positional contract. The checkbox's checked state is the ARIA reflection — a plain <table> row must not carry aria-selected (grid-only state).
@@ -1313,6 +1345,13 @@ if (isSelect) {
1313
1345
  }
1314
1346
  }
1315
1347
  // R25-04: re-assert the selection AFTER the base's form-control restore. That restore preserves user-typed state across a re-render and runs after render(); for a CONTROLLED selection the store-driven state is the truth, so the rendered checks are re-applied here — enhance() runs last on both the connect and the re-render path. Idempotent and window-sized; the select-all box keeps the base's own restoration.
1348
+ // R34-123: refresh the announced selected-count without a full re-render.
1349
+ _updateSelectionStatus() {
1350
+ const st = this.querySelector(".c-table__selection-status");
1351
+ if (!st) return;
1352
+ const n = this._selectionControlled ? (this._selectedKeys ? this._selectedKeys.size : 0) : (this._selectedRows ? this._selectedRows.size : 0);
1353
+ st.textContent = n ? `${n} selected` : "";
1354
+ }
1316
1355
  _applySelectionToDom() {
1317
1356
  this.querySelectorAll(".c-table__row-select").forEach((cb) => {
1318
1357
  const idx = Number(cb.dataset.rowIndex);
@@ -1345,14 +1384,18 @@ if (isSelect) {
1345
1384
  const handleSort = (th) => {
1346
1385
  const idx = Number(th.dataset.sortIndex);
1347
1386
  if (!Number.isFinite(idx)) return;
1387
+ // R34-122: three-state cycle — ascending → descending → none (reset), so
1388
+ // a reader can clear the sort from the header without a separate control.
1348
1389
  if (this._sortCol === idx) {
1349
- this._sortDir = (this._sortDir === 1) ? -1 : 1;
1390
+ if (this._sortDir === 1) this._sortDir = -1;
1391
+ else { this._sortCol = null; this._sortDir = 1; }
1350
1392
  } else {
1351
1393
  this._sortCol = idx;
1352
1394
  this._sortDir = 1;
1353
1395
  }
1354
- this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: this._sortDir === 1 ? "ascending" : "descending" } }));
1355
- this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: idx, sortDir: this._sortDir === 1 ? "ascending" : "descending" } } }));
1396
+ const dir = this._sortCol === idx ? (this._sortDir === 1 ? "ascending" : "descending") : "none";
1397
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: dir } }));
1398
+ this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: this._sortCol === idx ? idx : null, sortDir: dir } } }));
1356
1399
  this.requestRender();
1357
1400
  };
1358
1401
  this.addEventListener("click", (e) => {
@@ -1445,6 +1488,7 @@ if (isSelect) {
1445
1488
  if (cb.checked) this._selectedRows.add(idx); else this._selectedRows.delete(idx);
1446
1489
  }
1447
1490
  this._applySelectionToDom();
1491
+ this._updateSelectionStatus();
1448
1492
  const rows = Array.from(this._selectedRows);
1449
1493
  const keys = this._selectionKeys();
1450
1494
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows, key, index: idx } }));
@@ -1467,6 +1511,7 @@ if (isSelect) {
1467
1511
  this._selectedRows = new Set(all.checked ? cbs.map((c) => Number(c.dataset.rowIndex)) : []);
1468
1512
  }
1469
1513
  all.indeterminate = false;
1514
+ this._updateSelectionStatus();
1470
1515
  const rows = Array.from(this._selectedRows);
1471
1516
  const keys = this._selectionKeys();
1472
1517
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows } }));
@@ -1606,6 +1651,10 @@ class ContourColumnPicker extends ContourBase {
1606
1651
  const STREAM_BUFFER_MAX = 600;
1607
1652
  const capBuffer = (arr, max = STREAM_BUFFER_MAX) => {
1608
1653
  if (!Array.isArray(arr) || arr.length <= max) return arr;
1654
+ // R32-12: a numeric series is reduced with extrema-preserving buckets, so a
1655
+ // short spike survives the 600-point cap instead of being stepped over by a
1656
+ // fixed stride. Non-numeric payloads (histogram bins) keep the stride.
1657
+ if (arr.every((v) => typeof v === "number" && Number.isFinite(v))) return decimateMinMax(arr, max);
1609
1658
  const step = Math.ceil(arr.length / max);
1610
1659
  const out = [];
1611
1660
  for (let i = 0; i < arr.length; i += step) out.push(arr[i]);
@@ -1700,6 +1749,28 @@ class ContourChart extends ContourBase {
1700
1749
  _showsBrush() {
1701
1750
  return this.hasAttribute("brush") || this._rangeOverride !== undefined;
1702
1751
  }
1752
+ // R34-53: nearest-mark hit tolerance. Given a pointer position, return the
1753
+ // closest visible mark within `tol` px — a mark whose box contains the
1754
+ // pointer wins outright (a tall bar's centre is far from a click near its
1755
+ // top), otherwise the nearest mark centre. Unlaid-out boxes (jsdom, a hidden
1756
+ // plot) are skipped so a zero-size rect never captures a tap.
1757
+ _nearestMark(clientX, clientY, tol = 22) {
1758
+ const plot = this.querySelector(".c-chart__plot");
1759
+ if (!plot) return null;
1760
+ const marks = plot.querySelectorAll(".c-chart__bar, .c-chart__point, .c-donut__slice");
1761
+ let best = null;
1762
+ let bestScore = tol;
1763
+ for (const m of marks) {
1764
+ if (m.getAttribute("aria-hidden") === "true") continue;
1765
+ const r = m.getBoundingClientRect();
1766
+ if (!r.width && !r.height) continue;
1767
+ const inside = clientX >= r.left && clientX <= r.right && clientY >= r.top && clientY <= r.bottom;
1768
+ const centre = Math.hypot(clientX - (r.left + r.width / 2), clientY - (r.top + r.height / 2));
1769
+ const score = inside ? 0 : centre;
1770
+ if (score < bestScore) { bestScore = score; best = m; }
1771
+ }
1772
+ return best;
1773
+ }
1703
1774
  get range() {
1704
1775
  const override = this._rangeOverride;
1705
1776
  if (override !== undefined) return override ? override.slice() : null;
@@ -2330,6 +2401,26 @@ svg.setAttribute("role", "group");
2330
2401
  }
2331
2402
  }
2332
2403
  // R25-03: gridlines/axis/note/brush shed last, over whatever the branches above built. The loading/error/skeleton returns are state chrome, not data chrome, and deliberately skip the shed table.
2404
+ // R33-103: first-mount staggered reveal. The plot persists across renders
2405
+ // (patchChildren reuses its marks), so the class is added once and cleared
2406
+ // after the stagger — a streaming update that patches new marks in later
2407
+ // never replays it. Reduced-motion collapses the animation (global reset).
2408
+ if (!this._chartRevealed) {
2409
+ const plot = this.querySelector(".c-chart__plot");
2410
+ if (plot && plot.querySelector(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice")) {
2411
+ this._chartRevealed = true;
2412
+ // Per-mark stagger delay is set inline (not in CSS): family-gate
2413
+ // forbids raw ms in an animation-* declaration.
2414
+ plot.querySelectorAll(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice").forEach((mark, i) => {
2415
+ mark.style.animationDelay = (Math.min(i, 11) * 30) + "ms";
2416
+ });
2417
+ plot.classList.add("is-revealing");
2418
+ setTimeout(() => {
2419
+ plot.classList.remove("is-revealing");
2420
+ plot.querySelectorAll(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice").forEach((mark) => mark.style.removeProperty("animation-delay"));
2421
+ }, 600);
2422
+ }
2423
+ }
2333
2424
  this._applyBrownout();
2334
2425
  }
2335
2426
  enhance() {
@@ -2367,38 +2458,100 @@ svg.setAttribute("role", "group");
2367
2458
  detail: e.detail,
2368
2459
  }));
2369
2460
  });
2370
- // Zoom/pan (F-10 deferred): wheel to zoom, drag to pan, double-click to reset.
2461
+ // Zoom/pan (F-10; R34-52 keyboard/touch/announced contract): wheel or
2462
+ // `+`/`-`/`0` to zoom, drag or arrow keys to pan, double-click or `0` to
2463
+ // reset. Pointer events with capture cover mouse, touch and pen; a
2464
+ // two-pointer pinch zooms around its midpoint and `pointercancel` settles
2465
+ // back without emitting a phantom change. Every committed change is
2466
+ // announced through a polite live region and a `contour:chart-zoom`
2467
+ // event, so a table, a minimap or an AT user follows the same viewport.
2468
+ // `touch-action: pan-y` (CSS) keeps native vertical page scroll while the
2469
+ // plot owns horizontal pan and pinch — the chart never traps the page.
2371
2470
  if (this.hasAttribute("zoomable")) {
2372
2471
  let zoom = 1, panX = 0, panY = 0;
2373
2472
  const plot = this.querySelector(".c-chart__plot");
2374
- const apply = () => {
2473
+ // A zoomable plot is a focusable control with its own instructions; the
2474
+ // marks keep their roving tabindex inside it.
2475
+ if (plot) {
2476
+ plot.classList.add("c-chart__plot--zoomable");
2477
+ if (!plot.hasAttribute("tabindex")) plot.setAttribute("tabindex", "0");
2478
+ if (!plot.hasAttribute("aria-label")) {
2479
+ plot.setAttribute("aria-label", labelText(this, "chart", "Chart") + ", zoomable. Use plus and minus to zoom, arrow keys to pan, 0 to reset.");
2480
+ }
2481
+ }
2482
+ const status = this.ensure("[data-chart-zoom-status]", () => {
2483
+ const el = document.createElement("span");
2484
+ el.className = "visually-hidden";
2485
+ el.setAttribute("data-chart-zoom-status", "");
2486
+ el.setAttribute("role", "status");
2487
+ el.setAttribute("aria-live", "polite");
2488
+ return el;
2489
+ });
2490
+ const apply = (announce = true) => {
2375
2491
  if (!plot) return;
2376
2492
  plot.style.transform = `translate(${panX}px, ${panY}px) scale(${zoom})`;
2377
2493
  plot.style.transformOrigin = "center center";
2494
+ plot.classList.toggle("is-zoomed", zoom !== 1 || panX !== 0 || panY !== 0);
2495
+ if (!announce) return;
2496
+ status.textContent = `Zoom ${Math.round(zoom * 100)} percent`;
2497
+ this.dispatchEvent(new CustomEvent("contour:chart-zoom", { bubbles: true, composed: true, detail: { zoom, panX, panY } }));
2378
2498
  };
2499
+ const zoomBy = (factor) => { zoom = Math.min(5, Math.max(0.5, zoom * factor)); apply(); };
2500
+ const reset = () => { zoom = 1; panX = 0; panY = 0; apply(); };
2379
2501
  this.addEventListener("wheel", (e) => {
2380
2502
  e.preventDefault();
2381
- const factor = e.deltaY < 0 ? 1.1 : 0.9;
2382
- zoom = Math.min(5, Math.max(0.5, zoom * factor));
2383
- apply();
2503
+ zoomBy(e.deltaY < 0 ? 1.1 : 0.9);
2384
2504
  }, { passive: false });
2385
- let dragging = false, startX = 0, startY = 0, startPanX = 0, startPanY = 0;
2386
- this.addEventListener("mousedown", (e) => {
2387
- if (e.button !== 0) return;
2388
- dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
2389
- this.style.cursor = "grabbing";
2505
+ // Pointer pan/pinch with capture; a single pointer pans, a second turns
2506
+ // the gesture into a pinch-zoom around the two-pointer midpoint.
2507
+ const pointers = new Map();
2508
+ let dragging = false, startX = 0, startY = 0, startPanX = 0, startPanY = 0, pinchDist = 0, pinchZoom = 1;
2509
+ const spread = () => { const p = [...pointers.values()]; return p.length >= 2 ? Math.hypot(p[0].x - p[1].x, p[0].y - p[1].y) : 0; };
2510
+ this.addEventListener("pointerdown", (e) => {
2511
+ if (e.pointerType === "mouse" && e.button !== 0) return;
2512
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
2513
+ try { this.setPointerCapture(e.pointerId); } catch (err) { /* capture unsupported */ }
2514
+ if (pointers.size === 1) {
2515
+ dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
2516
+ this.style.cursor = "grabbing";
2517
+ } else if (pointers.size === 2) {
2518
+ dragging = false; pinchDist = spread(); pinchZoom = zoom;
2519
+ }
2390
2520
  });
2391
- const onMove = (e) => {
2521
+ this.addEventListener("pointermove", (e) => {
2522
+ if (!pointers.has(e.pointerId)) return;
2523
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
2524
+ if (pointers.size >= 2 && pinchDist) {
2525
+ zoom = Math.min(5, Math.max(0.5, pinchZoom * (spread() / pinchDist)));
2526
+ apply();
2527
+ return;
2528
+ }
2392
2529
  if (!dragging) return;
2393
2530
  panX = startPanX + (e.clientX - startX);
2394
2531
  panY = startPanY + (e.clientY - startY);
2395
- apply();
2532
+ apply(false); // pan is not announced per-pixel; pointerup settles it
2533
+ });
2534
+ const endPointer = (e) => {
2535
+ pointers.delete(e.pointerId);
2536
+ try { this.releasePointerCapture(e.pointerId); } catch (err) { /* ignore */ }
2537
+ if (pointers.size < 2) pinchDist = 0;
2538
+ if (pointers.size === 0) { dragging = false; this.style.cursor = ""; apply(); }
2396
2539
  };
2397
- const onUp = () => { if (dragging) { dragging = false; this.style.cursor = ""; } };
2398
- window.addEventListener("mousemove", onMove);
2399
- window.addEventListener("mouseup", onUp);
2400
- onDispose(this, () => { window.removeEventListener("mousemove", onMove); window.removeEventListener("mouseup", onUp); });
2401
- this.addEventListener("dblclick", () => { zoom = 1; panX = 0; panY = 0; apply(); });
2540
+ this.addEventListener("pointerup", endPointer);
2541
+ this.addEventListener("pointercancel", endPointer);
2542
+ this.addEventListener("dblclick", reset);
2543
+ // Keyboard (plot-focused only): +/= zoom in, -/_ zoom out, 0 reset,
2544
+ // arrows pan. Marks keep their own Enter/Space/arrow contract.
2545
+ this.addEventListener("keydown", (e) => {
2546
+ if (e.target !== plot) return;
2547
+ if (e.key === "+" || e.key === "=") { e.preventDefault(); zoomBy(1.1); }
2548
+ else if (e.key === "-" || e.key === "_") { e.preventDefault(); zoomBy(0.9); }
2549
+ else if (e.key === "0") { e.preventDefault(); reset(); }
2550
+ else if (e.key === "ArrowLeft") { e.preventDefault(); panX += 20; apply(); }
2551
+ else if (e.key === "ArrowRight") { e.preventDefault(); panX -= 20; apply(); }
2552
+ else if (e.key === "ArrowUp") { e.preventDefault(); panY += 20; apply(); }
2553
+ else if (e.key === "ArrowDown") { e.preventDefault(); panY -= 20; apply(); }
2554
+ });
2402
2555
  }
2403
2556
  // Tooltip: show on hover of a mark. Cache the plot rect across mousemove events: it only changes on resize/scroll, so re-measuring on every pixel is wasted layout work (B3-22). A ResizeObserver invalidates the cache; scroll invalidates via the same observer-less fallback (recompute).
2404
2557
  let plotRectCache = null;
@@ -2473,6 +2626,17 @@ svg.setAttribute("role", "group");
2473
2626
  const series = parseInt(slice.getAttribute("data-series") || "1", 10);
2474
2627
  const index = parseInt(slice.dataset.index || "0", 10);
2475
2628
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index, value: slice.getAttribute("data-title") || slice.getAttribute("title") } }));
2629
+ return;
2630
+ }
2631
+ // R34-53: nearest-mark selection with pointer tolerance. A tap that
2632
+ // lands on the plot between marks — or on a thin bar/point too small
2633
+ // for a 44px coarse target — still selects the closest datum, so
2634
+ // pointer and keyboard share one selection path and one datum.
2635
+ const nearest = this._nearestMark(e.clientX, e.clientY);
2636
+ if (nearest) {
2637
+ const series = parseInt(nearest.getAttribute("data-series") || "1", 10);
2638
+ const index = parseInt(nearest.dataset.index || "0", 10);
2639
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
2476
2640
  }
2477
2641
  });
2478
2642
  this.addEventListener("keydown", (e) => {
@@ -2834,7 +2998,7 @@ class ContourStreamingChart extends ContourBase {
2834
2998
  // Stream cadence (BY-40). The layer had no timer at all — the literal gap the row names — so the chart gets its own `interval` loop rather than a second clock inside the loader. Each tick emits contour:tick and, when a src is present, re-validates through the loader's own cache path (remoteInvalidate + requestRender — the two steps the loader's refresh tick performs), so the shared cache and abort semantics stay the loader's. The loader's `refresh` attribute is NOT written here: an attribute a component writes to itself must never be observed, or the write re-enters render (measured by the gate). `pause` stops the loop; `interval` growth is clamped to the loader's own 1 s floor so the two cannot disagree.
2835
2999
  const sync = () => {
2836
3000
  const seconds = parseFloat(this.getAttribute("interval") || "");
2837
- const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false;
3001
+ const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false && this._tabVisible !== false;
2838
3002
  if (want === this._streamRunning) return;
2839
3003
  this._streamRunning = want;
2840
3004
  if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; }
@@ -2843,7 +3007,11 @@ class ContourStreamingChart extends ContourBase {
2843
3007
  this._streamTimer = setInterval(() => {
2844
3008
  if (!this.isConnected || this.hasAttribute("pause")) return;
2845
3009
  this._streamFrame += 1;
2846
- this.dispatchEvent(new CustomEvent("contour:tick", { detail: { frame: this._streamFrame }, bubbles: true, composed: true }));
3010
+ // R34-54: each tick carries its sequence (frame), emit timestamp and
3011
+ // the expected interval, so a consumer can detect a gap (a missing
3012
+ // tick beyond `interval`) and a stall (no tick for N intervals)
3013
+ // without a second clock.
3014
+ this.dispatchEvent(new CustomEvent("contour:tick", { detail: { frame: this._streamFrame, timestamp: Date.now(), interval: Math.max(1000, seconds * 1000) }, bubbles: true, composed: true }));
2847
3015
  const src = this.getAttribute("src");
2848
3016
  if (src) { remoteInvalidate(src); this.requestRender(); }
2849
3017
  }, Math.max(1000, seconds * 1000));
@@ -2862,7 +3030,12 @@ class ContourStreamingChart extends ContourBase {
2862
3030
  if (this._wiredStream) return;
2863
3031
  this._wiredStream = true;
2864
3032
  this._streamFrame = 0;
2865
- onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } });
3033
+ // R33-72: pause the stream while the tab is hidden (visibilitychange), and
3034
+ // resume when it returns. The document listener is removed on dispose.
3035
+ this._tabVisible = !document.hidden;
3036
+ const onVis = () => { this._tabVisible = !document.hidden; sync(); };
3037
+ document.addEventListener("visibilitychange", onVis);
3038
+ onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } document.removeEventListener("visibilitychange", onVis); });
2866
3039
  // Keyboard: Space/Enter toggles pause (BY-08); internal flag prevents re-render re-entry.
2867
3040
  this._streamPausedByUser = false;
2868
3041
  // Delegate pause/play click on host: generated button dies on re-render; host listener survives (rule 12).
@@ -2932,6 +3105,31 @@ class ContourReferenceRule extends ContourBase {
2932
3105
  }
2933
3106
  define("contour-reference-rule", ContourReferenceRule);
2934
3107
 
3108
+ /**
3109
+ * Small Multiples (R33-45): a grid of charts that share axes. Attributes:
3110
+ * `columns` (grid column count) and `label`. Slotted charts are laid out in a
3111
+ * responsive grid; the group is the shared-axis frame, the children are the
3112
+ * individual multiples.
3113
+ *
3114
+ * The data contract is "children supply the marks": there is deliberately no
3115
+ * `multiples[]` attribute. Each child owns its data and its encoding, so the
3116
+ * frame cannot become a second source of truth for either. A child that selects
3117
+ * bubbles `contour:select` through this group, so a page listens once.
3118
+ */
3119
+ class ContourSmallMultiples extends ContourBase {
3120
+ static get observed() { return ["columns", "label"]; }
3121
+ static get properties() { return { columns: { attribute: "columns", type: Number }, label: { attribute: "label" } }; }
3122
+ render() {
3123
+ this.classList.add("c-small-multiples");
3124
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
3125
+ const label = this.getAttribute("label");
3126
+ if (label) this.setAttribute("aria-label", label); else this.removeAttribute("aria-label");
3127
+ const cols = this.getAttribute("columns");
3128
+ if (cols) this.style.setProperty("--sm-cols", cols); else this.style.removeProperty("--sm-cols");
3129
+ }
3130
+ }
3131
+ define("contour-small-multiples", ContourSmallMultiples);
3132
+
2935
3133
 
2936
3134
 
2937
3135
 
@@ -3377,8 +3575,11 @@ class ContourBrush extends ContourBase {
3377
3575
  const max = () => parseFloat(this.getAttribute("max") || "100");
3378
3576
  const toValue = (clientX) => {
3379
3577
  const r = this.getBoundingClientRect();
3380
- const ratio = Math.max(0, Math.min(1, (clientX - r.left) / (r.width || 1)));
3381
- return min() + ratio * (max() - min());
3578
+ // R34-09: in RTL the logical start is at the right, so the physical
3579
+ // ratio is mirrored — the pointer maps to the same track unit either way.
3580
+ const rtl = (this.ownerDocument.defaultView ? this.ownerDocument.defaultView.getComputedStyle(this).direction : "ltr") === "rtl";
3581
+ const ratio = rtl ? (r.right - clientX) / (r.width || 1) : (clientX - r.left) / (r.width || 1);
3582
+ return min() + Math.max(0, Math.min(1, ratio)) * (max() - min());
3382
3583
  };
3383
3584
  this.addEventListener("pointerdown", (e) => {
3384
3585
  const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
@@ -3453,11 +3654,15 @@ class ContourBrush extends ContourBase {
3453
3654
  return;
3454
3655
  }
3455
3656
  let handled = true;
3456
- if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
3657
+ // R34-09: in RTL the arrow keys follow the logical direction.
3658
+ const rtl = (this.ownerDocument.defaultView ? this.ownerDocument.defaultView.getComputedStyle(this).direction : "ltr") === "rtl";
3659
+ const leftKey = rtl ? "ArrowRight" : "ArrowLeft";
3660
+ const rightKey = rtl ? "ArrowLeft" : "ArrowRight";
3661
+ if (e.key === leftKey || e.key === "ArrowDown") {
3457
3662
  if (which === "start") ns -= step;
3458
3663
  else if (which === "end") ne -= step;
3459
3664
  else { const w = ne - ns; ns -= step; ne = ns + w; }
3460
- } else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
3665
+ } else if (e.key === rightKey || e.key === "ArrowUp") {
3461
3666
  if (which === "start") ns += step;
3462
3667
  else if (which === "end") ne += step;
3463
3668
  else { const w = ne - ns; ne += step; ns = ne - w; }
@@ -3498,8 +3703,9 @@ class ContourStackedBar extends ContourBase {
3498
3703
  static get properties() { return { segments: { attribute: "segments" }, values: { attribute: "values" }, colors: { attribute: "colors" }, src: { attribute: "src" }, max: { attribute: "max" } }; }
3499
3704
  render() {
3500
3705
  this.classList.add("c-stacked-bar");
3501
- // The bar carries a listbox of selectable segments; role=img would make
3502
- // every one of them presentational. A named group exposes them.
3706
+ // The segments are selectable marks, not decoration: role=img would make
3707
+ // them presentational, so a named group holds focusable buttons and
3708
+ // `enhance()` emits `contour:select` (same contract as time-series).
3503
3709
  if (!this.hasAttribute("role")) this.setAttribute("role", "group");
3504
3710
  if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "stacked-bar", "Stacked bar"));
3505
3711
  wireStates(this);
@@ -3538,7 +3744,11 @@ class ContourStackedBar extends ContourBase {
3538
3744
  el.dataset.color = (typeof seg === "object" && seg.color) ? seg.color : el.style.background;
3539
3745
  const label = typeof seg === "object" ? (seg.label || "") : "";
3540
3746
  el.setAttribute("data-title", label + " " + v);
3541
- el.setAttribute("role", "img");
3747
+ el.dataset.index = String(i);
3748
+ el.dataset.value = String(v);
3749
+ el.dataset.label = label;
3750
+ el.setAttribute("role", "button");
3751
+ el.setAttribute("tabindex", "-1");
3542
3752
  el.setAttribute("aria-label", (label ? label + ": " : "") + v);
3543
3753
  return el;
3544
3754
  };
@@ -3564,8 +3774,48 @@ class ContourStackedBar extends ContourBase {
3564
3774
  this.appendChild(track);
3565
3775
  }
3566
3776
  if (!segments.length) renderEmpty(this, "stacked-bar");
3777
+ // Roving entry point: one tab stop for the stack, arrows move within it.
3778
+ const marks = this.querySelectorAll(".c-stacked-bar__segment");
3779
+ marks.forEach((el, i) => el.setAttribute("tabindex", i === 0 ? "0" : "-1"));
3780
+ }
3781
+ enhance() {
3782
+ if (this._wiredStackedBar) return;
3783
+ this._wiredStackedBar = true;
3784
+ const marks = () => Array.from(this.querySelectorAll(".c-stacked-bar__segment"));
3785
+ const emit = (mark) => {
3786
+ this.dispatchEvent(new CustomEvent("contour:select", {
3787
+ bubbles: true,
3788
+ composed: true,
3789
+ detail: {
3790
+ index: Number(mark.dataset.index || "0"),
3791
+ key: mark.dataset.label || String(mark.dataset.index || "0"),
3792
+ label: mark.dataset.label || "",
3793
+ value: Number(mark.dataset.value || "0"),
3794
+ },
3795
+ }));
3796
+ };
3797
+ this.addEventListener("click", (e) => {
3798
+ const mark = e.target && e.target.closest ? e.target.closest(".c-stacked-bar__segment") : null;
3799
+ if (!mark || !this.contains(mark)) return;
3800
+ emit(mark);
3801
+ });
3802
+ this.addEventListener("keydown", (e) => {
3803
+ const mark = e.target && e.target.closest ? e.target.closest(".c-stacked-bar__segment") : null;
3804
+ if (!mark || !this.contains(mark)) return;
3805
+ if (e.key === "Enter" || e.key === " ") {
3806
+ e.preventDefault();
3807
+ emit(mark);
3808
+ return;
3809
+ }
3810
+ const all = marks();
3811
+ navKey(e, all, {
3812
+ wrap: false,
3813
+ homeEnd: true,
3814
+ rtl: isRtl(this),
3815
+ onNavigate: (i) => all.forEach((m, j) => m.setAttribute("tabindex", j === i ? "0" : "-1")),
3816
+ });
3817
+ });
3567
3818
  }
3568
- enhance() {}
3569
3819
  }
3570
3820
  define("contour-stacked-bar", ContourStackedBar);
3571
3821
  /**
@@ -3761,7 +4011,10 @@ class ContourDonut extends ContourBase {
3761
4011
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3762
4012
  svg.setAttribute("class", "c-donut__ring");
3763
4013
  svg.setAttribute("viewBox", "0 0 32 32");
3764
- svg.setAttribute("role", "img");
4014
+ // The ring holds focusable slice buttons, so it is a group, not an img
4015
+ // (role=img would flatten the buttons out of the tree and nest
4016
+ // interactive controls — axe nested-interactive).
4017
+ svg.setAttribute("role", "group");
3765
4018
  const ringLabel = this.getAttribute("label") || "Donut chart";
3766
4019
  svg.setAttribute("aria-label", ringLabel);
3767
4020
  const slices = donutSlices(values, { cx: 16, cy: 16, r: 15, inner: 9, gap: 0.03 });
@@ -4273,14 +4526,37 @@ define("contour-pivot", ContourPivot);
4273
4526
  * Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
4274
4527
  */
4275
4528
  class ContourWidgetState extends ContourBase {
4276
- static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache"]; }
4277
- static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" } }; }
4529
+ static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache", "analysis-state"]; }
4530
+ static get properties() { return { loading: { attribute: "loading" }, error: { attribute: "error" }, empty: { attribute: "empty" }, retry: { attribute: "retry" }, src: { attribute: "src" }, "analysis-state": { attribute: "analysis-state" } }; }
4278
4531
  render() {
4279
4532
  this.classList.add("c-widget-state");
4280
4533
  wireStates(this);
4281
4534
  loadRemote(this, []);
4282
4535
  if (renderStates(this, "widget-state")) return;
4283
- // if no state, render slotted content (already in DOM)
4536
+ // R34-162: reflect the shared analysis state (loading/stale/partial/
4537
+ // filtered/selected/locked/pinned) as data-analysis-state + a label so a
4538
+ // dashboard shell and assistive tech read one vocabulary, not per-widget
4539
+ // words. Rendered only in the ready branch — the load lifecycle owns the
4540
+ // loading/error/empty chrome above.
4541
+ const as = this.getAttribute("analysis-state");
4542
+ if (as) {
4543
+ const label = setAnalysisState(this, as);
4544
+ let badge = this.querySelector(".c-widget-state__analysis");
4545
+ if (!badge) {
4546
+ badge = document.createElement("span");
4547
+ badge.className = "c-widget-state__analysis visually-hidden";
4548
+ badge.dataset.contourGenerated = "1";
4549
+ this.appendChild(badge);
4550
+ }
4551
+ badge.textContent = label;
4552
+ } else {
4553
+ // No input analysis-state: clear any reflected badge unconditionally.
4554
+ // (Reading `data-analysis-state` here made the class read an attribute
4555
+ // it does not observe, so a post-upgrade change could not re-render.)
4556
+ setAnalysisState(this, null);
4557
+ const badge = this.querySelector(".c-widget-state__analysis");
4558
+ if (badge) badge.remove();
4559
+ }
4284
4560
  }
4285
4561
  enhance() {}
4286
4562
  }
@@ -4620,9 +4896,13 @@ class ContourThreshold extends ContourBase {
4620
4896
  const state = this.getAttribute("state") || (this._remoteData && this._remoteData.state);
4621
4897
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
4622
4898
  if (!rValue && !target && !label) {
4899
+ // A meter with no value is invalid ARIA (aria-valuenow required); the
4900
+ // empty state is a status, not a meter.
4901
+ this.setAttribute("role", "status");
4623
4902
  renderEmpty(this, "threshold");
4624
4903
  return;
4625
4904
  }
4905
+ if (this.getAttribute("role") === "status") this.setAttribute("role", "meter");
4626
4906
  // R24-34: publish meter value range. fill=value, target=goal (both numbers) → announces real percentage, not bare string.
4627
4907
  // R31-57: clamp aria-valuenow into [0,100] (a value of 150 with max 100 is
4628
4908
  // invalid ARIA and the fill was invisible), and fold the target into the
@@ -4715,6 +4995,44 @@ class ContourMetricsFull extends ContourBase {
4715
4995
  }
4716
4996
  define("contour-metrics", ContourMetricsFull);
4717
4997
 
4998
+ /**
4999
+ * Selection Group (R33-43): a cross-component selection coordinator. Holds the
5000
+ * current selection (`selected`, a comma-separated id list) and broadcasts it to
5001
+ * slotted `[data-selection]` children (as `data-selected`) and to the page (as
5002
+ * `contour:selection`). A child's `contour:select` is adopted and rebroadcast,
5003
+ * so a map, table, chart and KPI stay linked without a global store.
5004
+ */
5005
+ class ContourSelectionGroup extends ContourBase {
5006
+ static get observed() { return ["selected", "mode"]; }
5007
+ static get properties() { return { selected: { attribute: "selected", controlled: true }, mode: { attribute: "mode" } }; }
5008
+ render() {
5009
+ this.classList.add("c-selection-group");
5010
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
5011
+ const selected = (this.getAttribute("selected") || "").split(",").map((s) => s.trim()).filter(Boolean);
5012
+ for (const child of this.querySelectorAll("[data-selection]")) {
5013
+ child.setAttribute("data-selected", selected.includes(child.getAttribute("data-selection")) ? "true" : "false");
5014
+ }
5015
+ }
5016
+ enhance() {
5017
+ if (this._wiredSelGroup) return;
5018
+ this._wiredSelGroup = true;
5019
+ this.addEventListener("contour:select", (e) => {
5020
+ const detail = e.detail || {};
5021
+ const value = detail.value != null ? String(detail.value) : (detail.key != null ? String(detail.key) : "");
5022
+ // Reflect the adopted selection onto the children in place. Do NOT write
5023
+ // `selected` back to ourselves: it is an observed attribute, so the write
5024
+ // re-enters render (wc-contract). The page owns `selected`; we emit
5025
+ // `contour:selection` for it to round-trip.
5026
+ const selected = value ? [value] : [];
5027
+ for (const child of this.querySelectorAll("[data-selection]")) {
5028
+ child.setAttribute("data-selected", selected.includes(child.getAttribute("data-selection")) ? "true" : "false");
5029
+ }
5030
+ this.dispatchEvent(new CustomEvent("contour:selection", { bubbles: true, composed: true, detail: { value, mode: this.getAttribute("mode") || "single" } }));
5031
+ });
5032
+ }
5033
+ }
5034
+ define("contour-selection-group", ContourSelectionGroup);
5035
+
4718
5036
 
4719
5037
 
4720
5038
 
@@ -4724,8 +5042,8 @@ class ContourMetricsFull extends ContourBase {
4724
5042
  * 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`.
4725
5043
  */
4726
5044
  class ContourLegend extends ContourBase {
4727
- 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"]; }
4728
- 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 } }; }
5045
+ 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"]; }
5046
+ 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 } }; }
4729
5047
  render() {
4730
5048
  this.classList.add("c-legend");
4731
5049
  const graduated = this.hasAttribute("graduated");
@@ -4947,6 +5265,19 @@ class ContourLegend extends ContourBase {
4947
5265
  const c = this.querySelector(".c-legend__classification");
4948
5266
  if (c) c.remove();
4949
5267
  }
5268
+ // R34-169: value domain + ramp direction. The domain names the mapped
5269
+ // range; `reverse` flips the ramp so a high-is-low scale reads correctly.
5270
+ const domain = this.getAttribute("domain");
5271
+ if (domain) {
5272
+ const d = this.ensure(".c-legend__domain", () => { const el = document.createElement("div"); el.className = "c-legend__domain"; return el; });
5273
+ const parts = domain.split(",");
5274
+ d.textContent = (labelText(this, "domain", "Domain") || "Domain") + ": " + parts.join(" – ");
5275
+ } else {
5276
+ const d = this.querySelector(".c-legend__domain");
5277
+ if (d) d.remove();
5278
+ }
5279
+ if (this.hasAttribute("reverse")) this.classList.add("c-legend--reverse");
5280
+ else this.classList.remove("c-legend--reverse");
4950
5281
  // data table (collapsible)
4951
5282
  const tableAttr = this.getAttribute("table");
4952
5283
  if (tableAttr) {
@@ -5188,7 +5519,7 @@ class ContourMeasure extends ContourBase {
5188
5519
  }
5189
5520
  // unit selector
5190
5521
  let sel = this.querySelector(".c-measure__unit-select");
5191
- if (!sel) { sel = document.createElement("select"); sel.className = "c-measure__unit-select"; sel.setAttribute("aria-label", labelText(this, "unit", "Unit")); sel.setAttribute("data-contour-label", "true"); this.appendChild(sel); }
5522
+ 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); }
5192
5523
  ["m","km","mi","ft"].forEach((u) => {
5193
5524
  if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
5194
5525
  });
@@ -5916,8 +6247,24 @@ class ContourErrorBoundary extends ContourBase {
5916
6247
  define("contour-error-boundary", ContourErrorBoundary);
5917
6248
 
5918
6249
  class ContourDataExport extends ContourBase {
5919
- static get observed() { return ["data", "format", "filename", "label"]; }
5920
- static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" } }; }
6250
+ static get observed() { return ["data", "format", "filename", "label", "scope", "crs", "provenance", "selected"]; }
6251
+ static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" }, scope: { attribute: "scope" }, crs: { attribute: "crs" }, provenance: { attribute: "provenance" }, selected: { attribute: "selected" } }; }
6252
+ // R34-164: export intent. `scope` narrows the `data` array to the rows a
6253
+ // consumer means to export — visible / filtered / selected / all (default).
6254
+ // `selected` is a JSON array of row keys (or rows carrying `selected: true`);
6255
+ // `visible`/`filtered` read a per-row flag so a host that already computed the
6256
+ // view can hand the full array and let the export honour the scope.
6257
+ scopeRows(rows, scope) {
6258
+ if (scope === "selected") {
6259
+ let keys = null;
6260
+ const sel = this.getAttribute("selected");
6261
+ if (sel) { try { const a = JSON.parse(sel); if (Array.isArray(a)) keys = new Set(a.map((k) => String(k))); } catch (e) { warnBadJson(this, "selected", e); } }
6262
+ return rows.filter((r) => (keys ? keys.has(String(r && (r.key ?? r.id ?? ""))) : !!(r && r.selected)));
6263
+ }
6264
+ if (scope === "visible") return rows.filter((r) => r && r.visible !== false);
6265
+ if (scope === "filtered") return rows.filter((r) => r && r.filtered !== true);
6266
+ return rows;
6267
+ }
5921
6268
  render() {
5922
6269
  this.classList.add("c-data-export");
5923
6270
  if (!this.hasAttribute("role")) this.setAttribute("role", "group");
@@ -5952,20 +6299,26 @@ class ContourDataExport extends ContourBase {
5952
6299
  if (!btn || !this.contains(btn)) return;
5953
6300
  const rawFmt = (this.getAttribute("format") || "json").toLowerCase();
5954
6301
  const fmt = (rawFmt === "csv" || rawFmt === "json") ? rawFmt : (console.warn("[contour-data-export] unsupported format:", rawFmt), "json");
6302
+ const scope = (this.getAttribute("scope") || "all").toLowerCase();
5955
6303
  const raw = this.getAttribute("data") || "[]";
6304
+ let allRows = [];
6305
+ let parsed = false;
6306
+ try { const a = JSON.parse(raw); if (Array.isArray(a)) { allRows = a; parsed = true; } } catch (err) { warnBadJson(this, "data", err); }
6307
+ const rows = this.scopeRows(allRows, scope);
6308
+ const count = rows.length;
6309
+ const total = allRows.length;
5956
6310
  let text = raw;
5957
- if (fmt === "csv") {
5958
- try {
5959
- const arr = JSON.parse(raw);
5960
- if (Array.isArray(arr)) {
5961
- if (arr.length === 0) {
5962
- text = "";
5963
- } else {
5964
- const keys = Object.keys(arr[0]);
5965
- text = [keys.map(csvCell).join(",")].concat(arr.map((r) => keys.map((k) => csvCell(r[k])).join(","))).join("\r\n");
5966
- }
6311
+ if (parsed && (scope !== "all" || fmt === "csv")) {
6312
+ if (fmt === "csv") {
6313
+ if (rows.length === 0) {
6314
+ text = "";
6315
+ } else {
6316
+ const keys = Object.keys(rows[0]);
6317
+ text = [keys.map(csvCell).join(",")].concat(rows.map((r) => keys.map((k) => csvCell(r[k])).join(","))).join("\r\n");
5967
6318
  }
5968
- } catch (err) { warnBadJson(this, "data", err); }
6319
+ } else {
6320
+ text = JSON.stringify(rows);
6321
+ }
5969
6322
  }
5970
6323
  // R31-49: prepend a UTF-8 BOM to CSV so Excel/Sheets read non-ASCII
5971
6324
  // correctly; revoke the object URL asynchronously so the download has
@@ -5973,23 +6326,44 @@ class ContourDataExport extends ContourBase {
5973
6326
  // it in some engines).
5974
6327
  const blob = new Blob([fmt === "csv" ? "\uFEFF" + text : text], { type: fmt === "csv" ? "text/csv" : "application/json" });
5975
6328
  const url = URL.createObjectURL(blob);
6329
+ const filename = this.getAttribute("filename") || ("export." + fmt);
5976
6330
  const a = document.createElement("a");
5977
6331
  a.href = url;
5978
- a.download = this.getAttribute("filename") || ("export." + fmt);
6332
+ a.download = filename;
5979
6333
  document.body.appendChild(a);
5980
6334
  a.click();
5981
6335
  a.remove();
5982
6336
  setTimeout(() => URL.revokeObjectURL(url), 0);
5983
- this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail: { format: fmt } }));
6337
+ // R34-164: file metadata + intent so a host can report what was written
6338
+ // (scope, count/total for progress, resolved filename, CRS/provenance).
6339
+ const detail = { format: fmt, scope, count, total, filename };
6340
+ const crs = this.getAttribute("crs");
6341
+ if (crs) detail.crs = crs;
6342
+ const provenance = this.getAttribute("provenance");
6343
+ if (provenance) detail.provenance = provenance;
6344
+ this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail }));
5984
6345
  });
5985
6346
  }
5986
6347
  }
5987
6348
  define("contour-data-export", ContourDataExport);
5988
6349
 
5989
6350
  // Query builder: field/operator/value rows with AND/OR connectors, remove button per row, Add rule button; renders from `query` JSON, emits contour:change.
6351
+ /**
6352
+ * Read a rule's value from its type-aware editor (R34-165): a range is two
6353
+ * inputs joined "low,high", a null checkbox is the string "null", everything
6354
+ * else is the single control's value.
6355
+ */
6356
+ function readRuleValue(row) {
6357
+ const low = row.querySelector('.c-query-builder__value[data-part="low"]');
6358
+ const high = row.querySelector('.c-query-builder__value[data-part="high"]');
6359
+ if (low || high) return [low ? low.value : "", high ? high.value : ""].join(",");
6360
+ const nullBox = row.querySelector(".c-query-builder__null");
6361
+ if (nullBox) return nullBox.checked ? "null" : "";
6362
+ return row.querySelector(".c-query-builder__value")?.value || "";
6363
+ }
5990
6364
  class ContourQueryBuilder extends ContourBase {
5991
- static get observed() { return ["query", "fields"]; }
5992
- static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" } }; }
6365
+ static get observed() { return ["query", "fields", "draft"]; }
6366
+ static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" }, draft: { attribute: "draft", type: Boolean } }; }
5993
6367
  // Single reader for whole component: add/remove/move/group-edit all need same DOM→query projection; three copies had drifted (connector never read, AND/OR edits silently dropped).
5994
6368
  readRules() {
5995
6369
  const rows = [];
@@ -5998,13 +6372,19 @@ class ContourQueryBuilder extends ContourBase {
5998
6372
  const conns = Array.from(this.querySelectorAll(".c-query-builder__connector__op"));
5999
6373
  nodes.forEach((r, i) => {
6000
6374
  const rule = {
6375
+ // R34-165: stable identity. A rule keeps its `id` across structural edits so a
6376
+ // consumer's optimistic write targets the same rule, not the row that slid into
6377
+ // its index.
6378
+ id: r.dataset.ruleId || ("r" + i),
6001
6379
  field: r.querySelector(".c-query-builder__field")?.value || "",
6002
6380
  op: r.querySelector(".c-query-builder__op")?.value || "=",
6003
- value: r.querySelector(".c-query-builder__value")?.value || "",
6381
+ value: readRuleValue(r),
6004
6382
  };
6005
6383
  if (i > 0 && conns[i - 1]) rule.connector = conns[i - 1].value || "AND";
6006
6384
  const g = r.closest(".c-query-builder__group");
6007
6385
  if (g) rule.group = g._groupName || "";
6386
+ // R34-165: NOT is a per-rule negation, a shape+word toggle (never colour).
6387
+ if (r.querySelector(".c-query-builder__not")?.getAttribute("aria-pressed") === "true") rule.not = true;
6008
6388
  rows.push(rule);
6009
6389
  });
6010
6390
  return rows;
@@ -6021,17 +6401,35 @@ class ContourQueryBuilder extends ContourBase {
6021
6401
  attributeChangedCallback(name, oldValue, newValue) {
6022
6402
  if (name === "query" && this._suppressQueryRender) return;
6023
6403
  super.attributeChangedCallback(name, oldValue, newValue);
6404
+ // R34-165: removing `draft` finalizes the held draft into `query`.
6405
+ if (name === "draft" && oldValue != null && newValue == null && this._draftRows) {
6406
+ this.commitDraft();
6407
+ }
6024
6408
  }
6025
6409
  // Write the model back and say so.
6026
6410
  commit(rows, rerender = true) {
6027
- if (rerender) {
6411
+ // R34-165: draft/commit. In draft mode edits are held locally and announced
6412
+ // with draft:true; the author's `query` attribute is untouched until the
6413
+ // draft is committed (attribute removed or commitDraft() called).
6414
+ const draft = this.hasAttribute("draft");
6415
+ if (draft) {
6416
+ this._draftRows = rows;
6417
+ } else if (rerender) {
6028
6418
  this.setAttribute("query", JSON.stringify(rows));
6029
6419
  } else {
6030
6420
  this._suppressQueryRender = true;
6031
6421
  try { this.setAttribute("query", JSON.stringify(rows)); }
6032
6422
  finally { this._suppressQueryRender = false; }
6033
6423
  }
6034
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
6424
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows, draft } }));
6425
+ }
6426
+ // Finalize a draft: write it to `query` and announce draft:false (R34-165).
6427
+ commitDraft() {
6428
+ const rows = this._draftRows || this.readRules();
6429
+ this._draftRows = null;
6430
+ this.removeAttribute("draft");
6431
+ this.setAttribute("query", JSON.stringify(rows));
6432
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows, draft: false } }));
6035
6433
  }
6036
6434
  render() {
6037
6435
  this.classList.add("c-query-builder");
@@ -6040,7 +6438,12 @@ class ContourQueryBuilder extends ContourBase {
6040
6438
  if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
6041
6439
  const query = this.getAttribute("query");
6042
6440
  let rules = [];
6043
- if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
6441
+ // R34-165: in draft mode the rows come from the held draft, not the attr.
6442
+ if (this.hasAttribute("draft") && this._draftRows) {
6443
+ rules = this._draftRows;
6444
+ } else if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
6445
+ // Field metadata (type/options) drives the value editor (R34-165).
6446
+ const fieldMeta = (name) => fieldList.find((f) => (typeof f === "string" ? f : (f.value || f.label || "")) === name) || {};
6044
6447
  const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
6045
6448
  Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector, .c-query-builder__group")).forEach((n) => n.remove());
6046
6449
  let currentGroup = null;
@@ -6096,6 +6499,7 @@ class ContourQueryBuilder extends ContourBase {
6096
6499
  }
6097
6500
  const row = document.createElement("div");
6098
6501
  row.className = "c-query-builder__row";
6502
+ row.dataset.ruleId = rule.id || ("r" + i);
6099
6503
  const field = document.createElement("select");
6100
6504
  field.className = "c-input c-query-builder__field";
6101
6505
  field.setAttribute("aria-label", labelText(this, "field", "Field") + " " + (i + 1));
@@ -6115,13 +6519,53 @@ class ContourQueryBuilder extends ContourBase {
6115
6519
  if (o === rule.op) opt.selected = true;
6116
6520
  op.appendChild(opt);
6117
6521
  });
6118
- const val = document.createElement("input");
6119
- val.className = "c-input c-query-builder__value";
6120
- val.type = "text";
6121
- // Value attr is identity for base class restore; without it, control matched by index which shifts after structural edits (DW-4).
6122
- val.setAttribute("value", rule.value || "");
6123
- val.value = rule.value || "";
6124
- val.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1));
6522
+ // R34-165: type-aware value editor from field metadata — date picker, enum
6523
+ // select, null checkbox, range (two inputs), text fallback.
6524
+ const meta = fieldMeta(rule.field);
6525
+ const vtype = meta.type || "text";
6526
+ const mkText = (type, value, part) => {
6527
+ const el = document.createElement("input");
6528
+ el.className = "c-input c-query-builder__value";
6529
+ el.type = type;
6530
+ if (part) el.dataset.part = part;
6531
+ el.setAttribute("value", value || "");
6532
+ el.value = value || "";
6533
+ el.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1) + (part ? " " + part : ""));
6534
+ return el;
6535
+ };
6536
+ let val;
6537
+ if (vtype === "enum" && Array.isArray(meta.options) && meta.options.length) {
6538
+ val = document.createElement("select");
6539
+ val.className = "c-input c-query-builder__value";
6540
+ val.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1));
6541
+ meta.options.forEach((o) => {
6542
+ const opt = document.createElement("option");
6543
+ opt.value = typeof o === "string" ? o : (o.value ?? o);
6544
+ opt.textContent = typeof o === "string" ? o : (o.label ?? o.value ?? o);
6545
+ if (opt.value === rule.value) opt.selected = true;
6546
+ val.appendChild(opt);
6547
+ });
6548
+ } else if (vtype === "null") {
6549
+ val = document.createElement("input");
6550
+ val.type = "checkbox";
6551
+ val.className = "c-query-builder__value c-query-builder__null";
6552
+ val.checked = rule.value === "null";
6553
+ val.setAttribute("aria-label", labelText(this, "is-null", "Is null") + " " + (i + 1));
6554
+ } else if (vtype === "range") {
6555
+ const parts = String(rule.value || "").split(",");
6556
+ val = document.createDocumentFragment();
6557
+ val.appendChild(mkText("number", parts[0], "low"));
6558
+ val.appendChild(mkText("number", parts[1], "high"));
6559
+ } else {
6560
+ val = mkText(vtype === "date" ? "date" : "text", rule.value);
6561
+ }
6562
+ // R34-165: NOT is a per-rule negation toggle (shape+word, aria-pressed).
6563
+ const notBtn = document.createElement("button");
6564
+ notBtn.type = "button";
6565
+ notBtn.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__not";
6566
+ notBtn.setAttribute("aria-label", labelText(this, "negate", "Negate") + " " + (i + 1));
6567
+ notBtn.setAttribute("aria-pressed", rule.not ? "true" : "false");
6568
+ notBtn.textContent = "NOT";
6125
6569
  // Reordering (WC5-75): buttons not drag handles (pointer-only), so keyboard can reach same operation.
6126
6570
  const up = document.createElement("button");
6127
6571
  up.type = "button";
@@ -6140,7 +6584,7 @@ class ContourQueryBuilder extends ContourBase {
6140
6584
  remove.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__remove";
6141
6585
  remove.setAttribute("aria-label", labelText(this, "remove-rule", "Remove rule") + " " + (i + 1));
6142
6586
  remove.textContent = "\u00d7";
6143
- row.appendChild(field); row.appendChild(op); row.appendChild(val);
6587
+ row.appendChild(field); row.appendChild(op); row.appendChild(val); row.appendChild(notBtn);
6144
6588
  row.appendChild(up); row.appendChild(down); row.appendChild(remove);
6145
6589
  if (currentGroup) currentGroup.appendChild(row); else list.appendChild(row);
6146
6590
  });
@@ -6167,6 +6611,14 @@ class ContourQueryBuilder extends ContourBase {
6167
6611
  this.addEventListener("click", (e) => {
6168
6612
  const t = e.target;
6169
6613
  if (!(t instanceof Element)) return;
6614
+ // R34-165: NOT toggle flips aria-pressed and commits the negation.
6615
+ const notBtn = t.closest(".c-query-builder__not");
6616
+ if (notBtn) {
6617
+ const next = notBtn.getAttribute("aria-pressed") !== "true";
6618
+ notBtn.setAttribute("aria-pressed", String(next));
6619
+ this.commit(this.readRules(), false);
6620
+ return;
6621
+ }
6170
6622
  if (t.closest(".c-query-builder__add")) {
6171
6623
  const conns = this.readRules().map((r) => r.connector);
6172
6624
  const rows = this.readRules();
@@ -6570,3 +7022,40 @@ export function paintPurityRing(ctx, {
6570
7022
  ctx.fill();
6571
7023
  }
6572
7024
  }
7025
+
7026
+ /**
7027
+ * Paint a purity ring into an `ImageData` buffer for sprite atlases.
7028
+ *
7029
+ * A MapLibre `addImage()` / sprite sheet wants pixels, not a live 2D context.
7030
+ * This allocates a canvas (an `OffscreenCanvas` in a worker, else a detached
7031
+ * `<canvas>`), paints the SAME ring `paintPurityRing` draws, and returns its
7032
+ * ImageData. Pass `opts.canvas` to reuse an atlas tile.
7033
+ *
7034
+ * It is the Contour visual, not every visual a consumer may already have: this
7035
+ * ring is a stroked track plus a stroked arc, whereas Libreship's atlas painter
7036
+ * draws a filled wedge. Migrating a wedge atlas therefore still needs that
7037
+ * painter or a deliberate visual change — the entry point removes the context
7038
+ * plumbing, not the design difference (LIBRESHIP.md §9.2).
7039
+ *
7040
+ * @param {object} [opts] same options as `paintPurityRing`, plus `canvas`.
7041
+ * @returns {ImageData}
7042
+ */
7043
+ export function paintPurityRingPixels(opts = {}) {
7044
+ const size = Number(opts.size) || 32;
7045
+ let canvas = opts.canvas;
7046
+ if (!canvas) {
7047
+ if (typeof OffscreenCanvas !== "undefined") {
7048
+ canvas = new OffscreenCanvas(size, size);
7049
+ } else if (typeof document !== "undefined") {
7050
+ canvas = document.createElement("canvas");
7051
+ canvas.width = size;
7052
+ canvas.height = size;
7053
+ } else {
7054
+ throw new Error("paintPurityRingPixels: no OffscreenCanvas or document — pass opts.canvas");
7055
+ }
7056
+ }
7057
+ const ctx = canvas.getContext("2d");
7058
+ if (!ctx) throw new Error("paintPurityRingPixels: canvas.getContext('2d') returned null");
7059
+ paintPurityRing(ctx, { ...opts, size });
7060
+ return ctx.getImageData(0, 0, size, size);
7061
+ }