contour-ds 1.9.1 → 1.10.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 (130) hide show
  1. package/README.md +4 -4
  2. package/dist/build-manifest.json +199 -198
  3. package/dist/contour-wc-content.esm.js +1 -1
  4. package/dist/contour-wc-content.esm.min.js +1 -1
  5. package/dist/contour-wc-core.esm.js +712 -45
  6. package/dist/contour-wc-core.esm.min.js +1 -1
  7. package/dist/contour-wc-dashboard.esm.js +595 -89
  8. package/dist/contour-wc-dashboard.esm.min.js +1 -1
  9. package/dist/contour-wc-data.esm.js +466 -69
  10. package/dist/contour-wc-data.esm.min.js +1 -1
  11. package/dist/contour-wc-docs.esm.js +1 -1
  12. package/dist/contour-wc-docs.esm.min.js +1 -1
  13. package/dist/contour-wc-feedback.esm.js +260 -29
  14. package/dist/contour-wc-feedback.esm.min.js +1 -1
  15. package/dist/contour-wc-forms.esm.js +133 -40
  16. package/dist/contour-wc-forms.esm.min.js +1 -1
  17. package/dist/contour-wc-interaction.esm.js +64 -5
  18. package/dist/contour-wc-interaction.esm.min.js +1 -1
  19. package/dist/contour-wc-layout.esm.js +72 -10
  20. package/dist/contour-wc-layout.esm.min.js +1 -1
  21. package/dist/contour-wc-map.esm.js +69 -9
  22. package/dist/contour-wc-map.esm.min.js +1 -1
  23. package/dist/contour-wc-misc.esm.js +1 -1
  24. package/dist/contour-wc-misc.esm.min.js +1 -1
  25. package/dist/contour-wc-navigation.esm.js +136 -20
  26. package/dist/contour-wc-navigation.esm.min.js +1 -1
  27. package/dist/contour-wc-ui.esm.js +505 -80
  28. package/dist/contour-wc-ui.esm.min.js +1 -1
  29. package/dist/contour-wc.esm.js +2538 -319
  30. package/dist/contour-wc.esm.min.js +1 -1
  31. package/dist/contour-wc.js +2538 -319
  32. package/dist/contour-wc.min.js +1 -1
  33. package/dist/contour.code-snippets +44 -0
  34. package/dist/contour.components.json +11713 -126
  35. package/dist/contour.css +1009 -103
  36. package/dist/contour.d.ts +42 -21
  37. package/dist/contour.esm.js +138 -21
  38. package/dist/contour.esm.min.js +1 -1
  39. package/dist/contour.html-data.json +249 -9
  40. package/dist/contour.js +138 -21
  41. package/dist/contour.min.css +1 -1
  42. package/dist/contour.min.js +1 -1
  43. package/dist/contour.react.d.ts +5 -1
  44. package/dist/contour.single.html +2 -2
  45. package/dist/contour.single.min.css +1 -1
  46. package/dist/contour.tokens.json +36 -1
  47. package/dist/contour.vue.d.ts +5 -1
  48. package/dist/contour.web-types.json +241 -9
  49. package/dist/custom-elements.json +1225 -55
  50. package/dist/docs/actions.md +1 -1
  51. package/dist/docs/affordances.md +1 -1
  52. package/dist/docs/apireference.md +1 -1
  53. package/dist/docs/colour.md +1 -1
  54. package/dist/docs/componentindex.md +1 -1
  55. package/dist/docs/data.md +6 -2
  56. package/dist/docs/docs.md +1 -1
  57. package/dist/docs/feedback.md +1 -1
  58. package/dist/docs/field.md +1 -1
  59. package/dist/docs/forms.md +1 -1
  60. package/dist/docs/index.json +7 -7
  61. package/dist/docs/install.md +1 -1
  62. package/dist/docs/landing.md +1 -1
  63. package/dist/docs/mapengine.md +1 -1
  64. package/dist/docs/motion.md +1 -1
  65. package/dist/docs/navigation.md +1 -1
  66. package/dist/docs/overlays.md +1 -1
  67. package/dist/docs/overview.md +1 -1
  68. package/dist/docs/patterns.md +1 -1
  69. package/dist/docs/playground.md +1 -1
  70. package/dist/docs/principles.md +1 -1
  71. package/dist/docs/recipes.md +1 -1
  72. package/dist/docs/space.md +1 -1
  73. package/dist/docs/status.md +1 -1
  74. package/dist/docs/surfaces.md +1 -1
  75. package/dist/docs/theming.md +1 -1
  76. package/dist/docs/type.md +1 -1
  77. package/dist/docs/webcomponents.md +1 -1
  78. package/dist/hljs.css +17 -0
  79. package/dist/map-chrome-contract.json +26 -0
  80. package/dist/map-chrome.mapbox.css +121 -0
  81. package/dist/map-chrome.maplibre.css +121 -0
  82. package/dist/registry/items/contour-core.json +2 -2
  83. package/dist/registry/items/contour-data.json +2 -2
  84. package/dist/registry/items/contour-docs.json +2 -2
  85. package/dist/registry/items/contour-landing.json +2 -2
  86. package/dist/registry/registry.json +8 -8
  87. package/dist/surfaces/contour-core.min.css +1 -1
  88. package/dist/surfaces/contour-data.min.css +1 -1
  89. package/dist/surfaces/contour-docs.min.css +1 -1
  90. package/dist/surfaces/contour-landing.min.css +1 -1
  91. package/dist/wc/behaviours.mjs +11 -3
  92. package/dist/wc/core.mjs +307 -32
  93. package/dist/wc/dashboard.mjs +129 -20
  94. package/dist/wc/data-chart.mjs +169 -21
  95. package/dist/wc/data-export.mjs +150 -29
  96. package/dist/wc/data-gauge.mjs +11 -4
  97. package/dist/wc/data-geo.mjs +1 -1
  98. package/dist/wc/data-legend.mjs +15 -2
  99. package/dist/wc/data-readout.mjs +12 -1
  100. package/dist/wc/data-series.mjs +73 -5
  101. package/dist/wc/data-table.mjs +37 -8
  102. package/dist/wc/feedback.mjs +259 -28
  103. package/dist/wc/forms-controls.mjs +44 -16
  104. package/dist/wc/forms-field.mjs +46 -4
  105. package/dist/wc/forms-groups.mjs +31 -8
  106. package/dist/wc/forms-input.mjs +11 -11
  107. package/dist/wc/index.mjs +1 -1
  108. package/dist/wc/interaction.mjs +63 -4
  109. package/dist/wc/layout.mjs +72 -10
  110. package/dist/wc/map.mjs +68 -8
  111. package/dist/wc/navigation-menu.mjs +43 -9
  112. package/dist/wc/navigation-shell.mjs +39 -6
  113. package/dist/wc/navigation-tree.mjs +53 -4
  114. package/dist/wc/states.mjs +350 -9
  115. package/dist/wc/svg.mjs +43 -0
  116. package/dist/wc/ui-data.mjs +268 -28
  117. package/dist/wc/ui-feedback.mjs +36 -11
  118. package/dist/wc/ui-inputs.mjs +63 -25
  119. package/dist/wc/ui-overlays.mjs +138 -16
  120. package/integrations/ai/v0-prompt.md +1 -1
  121. package/integrations/frameworks/fixtures/authored/sample.jsx +15 -0
  122. package/integrations/frameworks/fixtures/authored/sample.vue +15 -0
  123. package/integrations/frameworks/fixtures/dist/rendered.html +32 -0
  124. package/integrations/libreship/contract.json +1025 -0
  125. package/integrations/native/README.md +24 -4
  126. package/integrations/native/build/android/colors.xml +278 -0
  127. package/integrations/native/build/flutter/contour_tokens.dart +280 -0
  128. package/integrations/native/build/ios/ContourTokens.swift +280 -0
  129. package/integrations/validate-markup.mjs +57 -7
  130. package/package.json +41 -17
@@ -1,4 +1,4 @@
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
4
  define("contour-box", simple(["c-box"]));
@@ -698,7 +698,18 @@ class ContourKpi extends ContourBase {
698
698
  if (variant) this.classList.add("c-kpi--" + variant);
699
699
  if (value) {
700
700
  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"));
701
+ const text = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"), this.getAttribute("unit"));
702
+ // R33-102: cross-fade the value when it changes (not on first render).
703
+ // The node may be recreated per render, so the last value is tracked on
704
+ // the host; each change restarts the one-shot animation.
705
+ const changed = this._kpiLastValue != null && this._kpiLastValue !== text;
706
+ this._kpiLastValue = text;
707
+ v.textContent = text;
708
+ if (changed) {
709
+ v.classList.remove("is-updating");
710
+ void v.offsetWidth;
711
+ v.classList.add("is-updating");
712
+ }
702
713
  } else {
703
714
  const v = this.querySelector(".c-kpi__value");
704
715
  if (v) v.remove();
@@ -954,6 +965,20 @@ class ContourTable extends ContourBase {
954
965
  if (!this.hasAttribute("role")) this.setAttribute("role", "region");
955
966
  // An authored label names the table; "Table" is the fallback.
956
967
  if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("title") || "Table");
968
+ // R34-123: a stable, announced selected-count. The region is visually
969
+ // hidden and polite, so the count is read without shifting the layout;
970
+ // clearing the selection (select-all off) resets it to empty.
971
+ let selStatus = this.querySelector(".c-table__selection-status");
972
+ if (!selStatus) {
973
+ selStatus = document.createElement("span");
974
+ selStatus.className = "c-table__selection-status visually-hidden";
975
+ selStatus.setAttribute("aria-live", "polite");
976
+ this.appendChild(selStatus);
977
+ }
978
+ const selCount = this._selectionControlled
979
+ ? (this._selectedKeys ? this._selectedKeys.size : 0)
980
+ : (this._selectedRows ? this._selectedRows.size : 0);
981
+ selStatus.textContent = selCount ? `${selCount} selected` : "";
957
982
  wireStates(this);
958
983
  loadRemote(this, "rows");
959
984
  if (renderStates(this, "table")) return;
@@ -962,7 +987,7 @@ class ContourTable extends ContourBase {
962
987
  const columns = this.getAttribute("columns");
963
988
  const rows = remoteData(this, "rows");
964
989
  // 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"));
990
+ const authored = Array.from(this.children).filter((n) => !n.classList || (!n.classList.contains("c-table-wrap") && !n.classList.contains("c-table__selection-status")));
966
991
  if (columns && rows && !authored.length) {
967
992
  try {
968
993
  const cols = JSON.parse(columns);
@@ -1173,9 +1198,10 @@ if (isFilter) {
1173
1198
  let windowStart = 0;
1174
1199
  let visibleData = pageData;
1175
1200
  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));
1201
+ // R34-58: the start clamp is the shared virtualRange geometry (the
1202
+ // grid uses the same helper), so the table and grid agree on where a
1203
+ // scroll offset lands; the table keeps its count-based window size.
1204
+ windowStart = virtualRange(wrapScrollTop, rowHeight, (windowSize - overscan) * rowHeight, pageData.length, overscan).start;
1179
1205
  visibleData = pageData.slice(windowStart, windowStart + windowSize + overscan * 2);
1180
1206
  table.setAttribute("aria-rowcount", String(pageData.length + 1));
1181
1207
  // 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 +1248,7 @@ if (isSelect) {
1222
1248
  cb.type = "checkbox";
1223
1249
  cb.className = "c-table__row-select";
1224
1250
  cb.dataset.rowIndex = String(windowStart + ri);
1251
+ cb.setAttribute("aria-label", labelText(this, "select-row", "Select row") + " " + (rowKey ?? (windowStart + ri + 1)));
1225
1252
  // 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
1253
  cb.dataset.contourPreserveKey = rowKey;
1227
1254
  // 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 +1340,13 @@ if (isSelect) {
1313
1340
  }
1314
1341
  }
1315
1342
  // 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.
1343
+ // R34-123: refresh the announced selected-count without a full re-render.
1344
+ _updateSelectionStatus() {
1345
+ const st = this.querySelector(".c-table__selection-status");
1346
+ if (!st) return;
1347
+ const n = this._selectionControlled ? (this._selectedKeys ? this._selectedKeys.size : 0) : (this._selectedRows ? this._selectedRows.size : 0);
1348
+ st.textContent = n ? `${n} selected` : "";
1349
+ }
1316
1350
  _applySelectionToDom() {
1317
1351
  this.querySelectorAll(".c-table__row-select").forEach((cb) => {
1318
1352
  const idx = Number(cb.dataset.rowIndex);
@@ -1345,14 +1379,18 @@ if (isSelect) {
1345
1379
  const handleSort = (th) => {
1346
1380
  const idx = Number(th.dataset.sortIndex);
1347
1381
  if (!Number.isFinite(idx)) return;
1382
+ // R34-122: three-state cycle — ascending → descending → none (reset), so
1383
+ // a reader can clear the sort from the header without a separate control.
1348
1384
  if (this._sortCol === idx) {
1349
- this._sortDir = (this._sortDir === 1) ? -1 : 1;
1385
+ if (this._sortDir === 1) this._sortDir = -1;
1386
+ else { this._sortCol = null; this._sortDir = 1; }
1350
1387
  } else {
1351
1388
  this._sortCol = idx;
1352
1389
  this._sortDir = 1;
1353
1390
  }
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" } } }));
1391
+ const dir = this._sortCol === idx ? (this._sortDir === 1 ? "ascending" : "descending") : "none";
1392
+ this.dispatchEvent(new CustomEvent("contour:sort", { bubbles: true, composed: true, detail: { column: idx, direction: dir } }));
1393
+ this.dispatchEvent(new CustomEvent("contour:filter-change", { bubbles: true, composed: true, detail: { source: "table", filter: { sort: this._sortCol === idx ? idx : null, sortDir: dir } } }));
1356
1394
  this.requestRender();
1357
1395
  };
1358
1396
  this.addEventListener("click", (e) => {
@@ -1445,6 +1483,7 @@ if (isSelect) {
1445
1483
  if (cb.checked) this._selectedRows.add(idx); else this._selectedRows.delete(idx);
1446
1484
  }
1447
1485
  this._applySelectionToDom();
1486
+ this._updateSelectionStatus();
1448
1487
  const rows = Array.from(this._selectedRows);
1449
1488
  const keys = this._selectionKeys();
1450
1489
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows, key, index: idx } }));
@@ -1467,6 +1506,7 @@ if (isSelect) {
1467
1506
  this._selectedRows = new Set(all.checked ? cbs.map((c) => Number(c.dataset.rowIndex)) : []);
1468
1507
  }
1469
1508
  all.indeterminate = false;
1509
+ this._updateSelectionStatus();
1470
1510
  const rows = Array.from(this._selectedRows);
1471
1511
  const keys = this._selectionKeys();
1472
1512
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { rows } }));
@@ -1606,6 +1646,10 @@ class ContourColumnPicker extends ContourBase {
1606
1646
  const STREAM_BUFFER_MAX = 600;
1607
1647
  const capBuffer = (arr, max = STREAM_BUFFER_MAX) => {
1608
1648
  if (!Array.isArray(arr) || arr.length <= max) return arr;
1649
+ // R32-12: a numeric series is reduced with extrema-preserving buckets, so a
1650
+ // short spike survives the 600-point cap instead of being stepped over by a
1651
+ // fixed stride. Non-numeric payloads (histogram bins) keep the stride.
1652
+ if (arr.every((v) => typeof v === "number" && Number.isFinite(v))) return decimateMinMax(arr, max);
1609
1653
  const step = Math.ceil(arr.length / max);
1610
1654
  const out = [];
1611
1655
  for (let i = 0; i < arr.length; i += step) out.push(arr[i]);
@@ -1700,6 +1744,28 @@ class ContourChart extends ContourBase {
1700
1744
  _showsBrush() {
1701
1745
  return this.hasAttribute("brush") || this._rangeOverride !== undefined;
1702
1746
  }
1747
+ // R34-53: nearest-mark hit tolerance. Given a pointer position, return the
1748
+ // closest visible mark within `tol` px — a mark whose box contains the
1749
+ // pointer wins outright (a tall bar's centre is far from a click near its
1750
+ // top), otherwise the nearest mark centre. Unlaid-out boxes (jsdom, a hidden
1751
+ // plot) are skipped so a zero-size rect never captures a tap.
1752
+ _nearestMark(clientX, clientY, tol = 22) {
1753
+ const plot = this.querySelector(".c-chart__plot");
1754
+ if (!plot) return null;
1755
+ const marks = plot.querySelectorAll(".c-chart__bar, .c-chart__point, .c-donut__slice");
1756
+ let best = null;
1757
+ let bestScore = tol;
1758
+ for (const m of marks) {
1759
+ if (m.getAttribute("aria-hidden") === "true") continue;
1760
+ const r = m.getBoundingClientRect();
1761
+ if (!r.width && !r.height) continue;
1762
+ const inside = clientX >= r.left && clientX <= r.right && clientY >= r.top && clientY <= r.bottom;
1763
+ const centre = Math.hypot(clientX - (r.left + r.width / 2), clientY - (r.top + r.height / 2));
1764
+ const score = inside ? 0 : centre;
1765
+ if (score < bestScore) { bestScore = score; best = m; }
1766
+ }
1767
+ return best;
1768
+ }
1703
1769
  get range() {
1704
1770
  const override = this._rangeOverride;
1705
1771
  if (override !== undefined) return override ? override.slice() : null;
@@ -2330,6 +2396,26 @@ svg.setAttribute("role", "group");
2330
2396
  }
2331
2397
  }
2332
2398
  // 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.
2399
+ // R33-103: first-mount staggered reveal. The plot persists across renders
2400
+ // (patchChildren reuses its marks), so the class is added once and cleared
2401
+ // after the stagger — a streaming update that patches new marks in later
2402
+ // never replays it. Reduced-motion collapses the animation (global reset).
2403
+ if (!this._chartRevealed) {
2404
+ const plot = this.querySelector(".c-chart__plot");
2405
+ if (plot && plot.querySelector(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice")) {
2406
+ this._chartRevealed = true;
2407
+ // Per-mark stagger delay is set inline (not in CSS): family-gate
2408
+ // forbids raw ms in an animation-* declaration.
2409
+ plot.querySelectorAll(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice").forEach((mark, i) => {
2410
+ mark.style.animationDelay = (Math.min(i, 11) * 30) + "ms";
2411
+ });
2412
+ plot.classList.add("is-revealing");
2413
+ setTimeout(() => {
2414
+ plot.classList.remove("is-revealing");
2415
+ plot.querySelectorAll(".c-chart__bar, .c-chart__line, .c-chart__point, .c-donut__slice").forEach((mark) => mark.style.removeProperty("animation-delay"));
2416
+ }, 600);
2417
+ }
2418
+ }
2333
2419
  this._applyBrownout();
2334
2420
  }
2335
2421
  enhance() {
@@ -2367,38 +2453,100 @@ svg.setAttribute("role", "group");
2367
2453
  detail: e.detail,
2368
2454
  }));
2369
2455
  });
2370
- // Zoom/pan (F-10 deferred): wheel to zoom, drag to pan, double-click to reset.
2456
+ // Zoom/pan (F-10; R34-52 keyboard/touch/announced contract): wheel or
2457
+ // `+`/`-`/`0` to zoom, drag or arrow keys to pan, double-click or `0` to
2458
+ // reset. Pointer events with capture cover mouse, touch and pen; a
2459
+ // two-pointer pinch zooms around its midpoint and `pointercancel` settles
2460
+ // back without emitting a phantom change. Every committed change is
2461
+ // announced through a polite live region and a `contour:chart-zoom`
2462
+ // event, so a table, a minimap or an AT user follows the same viewport.
2463
+ // `touch-action: pan-y` (CSS) keeps native vertical page scroll while the
2464
+ // plot owns horizontal pan and pinch — the chart never traps the page.
2371
2465
  if (this.hasAttribute("zoomable")) {
2372
2466
  let zoom = 1, panX = 0, panY = 0;
2373
2467
  const plot = this.querySelector(".c-chart__plot");
2374
- const apply = () => {
2468
+ // A zoomable plot is a focusable control with its own instructions; the
2469
+ // marks keep their roving tabindex inside it.
2470
+ if (plot) {
2471
+ plot.classList.add("c-chart__plot--zoomable");
2472
+ if (!plot.hasAttribute("tabindex")) plot.setAttribute("tabindex", "0");
2473
+ if (!plot.hasAttribute("aria-label")) {
2474
+ plot.setAttribute("aria-label", labelText(this, "chart", "Chart") + ", zoomable. Use plus and minus to zoom, arrow keys to pan, 0 to reset.");
2475
+ }
2476
+ }
2477
+ const status = this.ensure("[data-chart-zoom-status]", () => {
2478
+ const el = document.createElement("span");
2479
+ el.className = "visually-hidden";
2480
+ el.setAttribute("data-chart-zoom-status", "");
2481
+ el.setAttribute("role", "status");
2482
+ el.setAttribute("aria-live", "polite");
2483
+ return el;
2484
+ });
2485
+ const apply = (announce = true) => {
2375
2486
  if (!plot) return;
2376
2487
  plot.style.transform = `translate(${panX}px, ${panY}px) scale(${zoom})`;
2377
2488
  plot.style.transformOrigin = "center center";
2489
+ plot.classList.toggle("is-zoomed", zoom !== 1 || panX !== 0 || panY !== 0);
2490
+ if (!announce) return;
2491
+ status.textContent = `Zoom ${Math.round(zoom * 100)} percent`;
2492
+ this.dispatchEvent(new CustomEvent("contour:chart-zoom", { bubbles: true, composed: true, detail: { zoom, panX, panY } }));
2378
2493
  };
2494
+ const zoomBy = (factor) => { zoom = Math.min(5, Math.max(0.5, zoom * factor)); apply(); };
2495
+ const reset = () => { zoom = 1; panX = 0; panY = 0; apply(); };
2379
2496
  this.addEventListener("wheel", (e) => {
2380
2497
  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();
2498
+ zoomBy(e.deltaY < 0 ? 1.1 : 0.9);
2384
2499
  }, { 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";
2500
+ // Pointer pan/pinch with capture; a single pointer pans, a second turns
2501
+ // the gesture into a pinch-zoom around the two-pointer midpoint.
2502
+ const pointers = new Map();
2503
+ let dragging = false, startX = 0, startY = 0, startPanX = 0, startPanY = 0, pinchDist = 0, pinchZoom = 1;
2504
+ 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; };
2505
+ this.addEventListener("pointerdown", (e) => {
2506
+ if (e.pointerType === "mouse" && e.button !== 0) return;
2507
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
2508
+ try { this.setPointerCapture(e.pointerId); } catch (err) { /* capture unsupported */ }
2509
+ if (pointers.size === 1) {
2510
+ dragging = true; startX = e.clientX; startY = e.clientY; startPanX = panX; startPanY = panY;
2511
+ this.style.cursor = "grabbing";
2512
+ } else if (pointers.size === 2) {
2513
+ dragging = false; pinchDist = spread(); pinchZoom = zoom;
2514
+ }
2390
2515
  });
2391
- const onMove = (e) => {
2516
+ this.addEventListener("pointermove", (e) => {
2517
+ if (!pointers.has(e.pointerId)) return;
2518
+ pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
2519
+ if (pointers.size >= 2 && pinchDist) {
2520
+ zoom = Math.min(5, Math.max(0.5, pinchZoom * (spread() / pinchDist)));
2521
+ apply();
2522
+ return;
2523
+ }
2392
2524
  if (!dragging) return;
2393
2525
  panX = startPanX + (e.clientX - startX);
2394
2526
  panY = startPanY + (e.clientY - startY);
2395
- apply();
2527
+ apply(false); // pan is not announced per-pixel; pointerup settles it
2528
+ });
2529
+ const endPointer = (e) => {
2530
+ pointers.delete(e.pointerId);
2531
+ try { this.releasePointerCapture(e.pointerId); } catch (err) { /* ignore */ }
2532
+ if (pointers.size < 2) pinchDist = 0;
2533
+ if (pointers.size === 0) { dragging = false; this.style.cursor = ""; apply(); }
2396
2534
  };
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(); });
2535
+ this.addEventListener("pointerup", endPointer);
2536
+ this.addEventListener("pointercancel", endPointer);
2537
+ this.addEventListener("dblclick", reset);
2538
+ // Keyboard (plot-focused only): +/= zoom in, -/_ zoom out, 0 reset,
2539
+ // arrows pan. Marks keep their own Enter/Space/arrow contract.
2540
+ this.addEventListener("keydown", (e) => {
2541
+ if (e.target !== plot) return;
2542
+ if (e.key === "+" || e.key === "=") { e.preventDefault(); zoomBy(1.1); }
2543
+ else if (e.key === "-" || e.key === "_") { e.preventDefault(); zoomBy(0.9); }
2544
+ else if (e.key === "0") { e.preventDefault(); reset(); }
2545
+ else if (e.key === "ArrowLeft") { e.preventDefault(); panX += 20; apply(); }
2546
+ else if (e.key === "ArrowRight") { e.preventDefault(); panX -= 20; apply(); }
2547
+ else if (e.key === "ArrowUp") { e.preventDefault(); panY += 20; apply(); }
2548
+ else if (e.key === "ArrowDown") { e.preventDefault(); panY -= 20; apply(); }
2549
+ });
2402
2550
  }
2403
2551
  // 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
2552
  let plotRectCache = null;
@@ -2473,6 +2621,17 @@ svg.setAttribute("role", "group");
2473
2621
  const series = parseInt(slice.getAttribute("data-series") || "1", 10);
2474
2622
  const index = parseInt(slice.dataset.index || "0", 10);
2475
2623
  this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index, value: slice.getAttribute("data-title") || slice.getAttribute("title") } }));
2624
+ return;
2625
+ }
2626
+ // R34-53: nearest-mark selection with pointer tolerance. A tap that
2627
+ // lands on the plot between marks — or on a thin bar/point too small
2628
+ // for a 44px coarse target — still selects the closest datum, so
2629
+ // pointer and keyboard share one selection path and one datum.
2630
+ const nearest = this._nearestMark(e.clientX, e.clientY);
2631
+ if (nearest) {
2632
+ const series = parseInt(nearest.getAttribute("data-series") || "1", 10);
2633
+ const index = parseInt(nearest.dataset.index || "0", 10);
2634
+ this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { series, index } }));
2476
2635
  }
2477
2636
  });
2478
2637
  this.addEventListener("keydown", (e) => {
@@ -2834,7 +2993,7 @@ class ContourStreamingChart extends ContourBase {
2834
2993
  // 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
2994
  const sync = () => {
2836
2995
  const seconds = parseFloat(this.getAttribute("interval") || "");
2837
- const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false;
2996
+ const want = Number.isFinite(seconds) && seconds > 0 && !this.hasAttribute("pause") && !this._streamPausedByUser && this._viewVisible !== false && this._tabVisible !== false;
2838
2997
  if (want === this._streamRunning) return;
2839
2998
  this._streamRunning = want;
2840
2999
  if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; }
@@ -2843,7 +3002,11 @@ class ContourStreamingChart extends ContourBase {
2843
3002
  this._streamTimer = setInterval(() => {
2844
3003
  if (!this.isConnected || this.hasAttribute("pause")) return;
2845
3004
  this._streamFrame += 1;
2846
- this.dispatchEvent(new CustomEvent("contour:tick", { detail: { frame: this._streamFrame }, bubbles: true, composed: true }));
3005
+ // R34-54: each tick carries its sequence (frame), emit timestamp and
3006
+ // the expected interval, so a consumer can detect a gap (a missing
3007
+ // tick beyond `interval`) and a stall (no tick for N intervals)
3008
+ // without a second clock.
3009
+ this.dispatchEvent(new CustomEvent("contour:tick", { detail: { frame: this._streamFrame, timestamp: Date.now(), interval: Math.max(1000, seconds * 1000) }, bubbles: true, composed: true }));
2847
3010
  const src = this.getAttribute("src");
2848
3011
  if (src) { remoteInvalidate(src); this.requestRender(); }
2849
3012
  }, Math.max(1000, seconds * 1000));
@@ -2862,7 +3025,12 @@ class ContourStreamingChart extends ContourBase {
2862
3025
  if (this._wiredStream) return;
2863
3026
  this._wiredStream = true;
2864
3027
  this._streamFrame = 0;
2865
- onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } });
3028
+ // R33-72: pause the stream while the tab is hidden (visibilitychange), and
3029
+ // resume when it returns. The document listener is removed on dispose.
3030
+ this._tabVisible = !document.hidden;
3031
+ const onVis = () => { this._tabVisible = !document.hidden; sync(); };
3032
+ document.addEventListener("visibilitychange", onVis);
3033
+ onDispose(this, () => { if (this._streamTimer !== undefined) { clearInterval(this._streamTimer); this._streamTimer = undefined; } document.removeEventListener("visibilitychange", onVis); });
2866
3034
  // Keyboard: Space/Enter toggles pause (BY-08); internal flag prevents re-render re-entry.
2867
3035
  this._streamPausedByUser = false;
2868
3036
  // Delegate pause/play click on host: generated button dies on re-render; host listener survives (rule 12).
@@ -2932,6 +3100,26 @@ class ContourReferenceRule extends ContourBase {
2932
3100
  }
2933
3101
  define("contour-reference-rule", ContourReferenceRule);
2934
3102
 
3103
+ /**
3104
+ * Small Multiples (R33-45): a grid of charts that share axes. Attributes:
3105
+ * `columns` (grid column count) and `label`. Slotted charts are laid out in a
3106
+ * responsive grid; the group is the shared-axis frame, the children are the
3107
+ * individual multiples.
3108
+ */
3109
+ class ContourSmallMultiples extends ContourBase {
3110
+ static get observed() { return ["columns", "label"]; }
3111
+ static get properties() { return { columns: { attribute: "columns", type: Number }, label: { attribute: "label" } }; }
3112
+ render() {
3113
+ this.classList.add("c-small-multiples");
3114
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
3115
+ const label = this.getAttribute("label");
3116
+ if (label) this.setAttribute("aria-label", label); else this.removeAttribute("aria-label");
3117
+ const cols = this.getAttribute("columns");
3118
+ if (cols) this.style.setProperty("--sm-cols", cols); else this.style.removeProperty("--sm-cols");
3119
+ }
3120
+ }
3121
+ define("contour-small-multiples", ContourSmallMultiples);
3122
+
2935
3123
 
2936
3124
 
2937
3125
 
@@ -3377,8 +3565,11 @@ class ContourBrush extends ContourBase {
3377
3565
  const max = () => parseFloat(this.getAttribute("max") || "100");
3378
3566
  const toValue = (clientX) => {
3379
3567
  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());
3568
+ // R34-09: in RTL the logical start is at the right, so the physical
3569
+ // ratio is mirrored — the pointer maps to the same track unit either way.
3570
+ const rtl = (this.ownerDocument.defaultView ? this.ownerDocument.defaultView.getComputedStyle(this).direction : "ltr") === "rtl";
3571
+ const ratio = rtl ? (r.right - clientX) / (r.width || 1) : (clientX - r.left) / (r.width || 1);
3572
+ return min() + Math.max(0, Math.min(1, ratio)) * (max() - min());
3382
3573
  };
3383
3574
  this.addEventListener("pointerdown", (e) => {
3384
3575
  const handle = e.target && e.target.classList && e.target.classList.contains("c-brush__handle") ? e.target : null;
@@ -3453,11 +3644,15 @@ class ContourBrush extends ContourBase {
3453
3644
  return;
3454
3645
  }
3455
3646
  let handled = true;
3456
- if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
3647
+ // R34-09: in RTL the arrow keys follow the logical direction.
3648
+ const rtl = (this.ownerDocument.defaultView ? this.ownerDocument.defaultView.getComputedStyle(this).direction : "ltr") === "rtl";
3649
+ const leftKey = rtl ? "ArrowRight" : "ArrowLeft";
3650
+ const rightKey = rtl ? "ArrowLeft" : "ArrowRight";
3651
+ if (e.key === leftKey || e.key === "ArrowDown") {
3457
3652
  if (which === "start") ns -= step;
3458
3653
  else if (which === "end") ne -= step;
3459
3654
  else { const w = ne - ns; ns -= step; ne = ns + w; }
3460
- } else if (e.key === "ArrowRight" || e.key === "ArrowUp") {
3655
+ } else if (e.key === rightKey || e.key === "ArrowUp") {
3461
3656
  if (which === "start") ns += step;
3462
3657
  else if (which === "end") ne += step;
3463
3658
  else { const w = ne - ns; ne += step; ns = ne - w; }
@@ -3761,7 +3956,10 @@ class ContourDonut extends ContourBase {
3761
3956
  const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3762
3957
  svg.setAttribute("class", "c-donut__ring");
3763
3958
  svg.setAttribute("viewBox", "0 0 32 32");
3764
- svg.setAttribute("role", "img");
3959
+ // The ring holds focusable slice buttons, so it is a group, not an img
3960
+ // (role=img would flatten the buttons out of the tree and nest
3961
+ // interactive controls — axe nested-interactive).
3962
+ svg.setAttribute("role", "group");
3765
3963
  const ringLabel = this.getAttribute("label") || "Donut chart";
3766
3964
  svg.setAttribute("aria-label", ringLabel);
3767
3965
  const slices = donutSlices(values, { cx: 16, cy: 16, r: 15, inner: 9, gap: 0.03 });
@@ -4273,14 +4471,37 @@ define("contour-pivot", ContourPivot);
4273
4471
  * Attributes: `loading`, `error`, `empty`, `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
4274
4472
  */
4275
4473
  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" } }; }
4474
+ static get observed() { return ["loading", "error", "empty", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache", "analysis-state"]; }
4475
+ 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
4476
  render() {
4279
4477
  this.classList.add("c-widget-state");
4280
4478
  wireStates(this);
4281
4479
  loadRemote(this, []);
4282
4480
  if (renderStates(this, "widget-state")) return;
4283
- // if no state, render slotted content (already in DOM)
4481
+ // R34-162: reflect the shared analysis state (loading/stale/partial/
4482
+ // filtered/selected/locked/pinned) as data-analysis-state + a label so a
4483
+ // dashboard shell and assistive tech read one vocabulary, not per-widget
4484
+ // words. Rendered only in the ready branch — the load lifecycle owns the
4485
+ // loading/error/empty chrome above.
4486
+ const as = this.getAttribute("analysis-state");
4487
+ if (as) {
4488
+ const label = setAnalysisState(this, as);
4489
+ let badge = this.querySelector(".c-widget-state__analysis");
4490
+ if (!badge) {
4491
+ badge = document.createElement("span");
4492
+ badge.className = "c-widget-state__analysis visually-hidden";
4493
+ badge.dataset.contourGenerated = "1";
4494
+ this.appendChild(badge);
4495
+ }
4496
+ badge.textContent = label;
4497
+ } else {
4498
+ // No input analysis-state: clear any reflected badge unconditionally.
4499
+ // (Reading `data-analysis-state` here made the class read an attribute
4500
+ // it does not observe, so a post-upgrade change could not re-render.)
4501
+ setAnalysisState(this, null);
4502
+ const badge = this.querySelector(".c-widget-state__analysis");
4503
+ if (badge) badge.remove();
4504
+ }
4284
4505
  }
4285
4506
  enhance() {}
4286
4507
  }
@@ -4620,9 +4841,13 @@ class ContourThreshold extends ContourBase {
4620
4841
  const state = this.getAttribute("state") || (this._remoteData && this._remoteData.state);
4621
4842
  const label = this.getAttribute("label") || (this._remoteData && this._remoteData.label);
4622
4843
  if (!rValue && !target && !label) {
4844
+ // A meter with no value is invalid ARIA (aria-valuenow required); the
4845
+ // empty state is a status, not a meter.
4846
+ this.setAttribute("role", "status");
4623
4847
  renderEmpty(this, "threshold");
4624
4848
  return;
4625
4849
  }
4850
+ if (this.getAttribute("role") === "status") this.setAttribute("role", "meter");
4626
4851
  // R24-34: publish meter value range. fill=value, target=goal (both numbers) → announces real percentage, not bare string.
4627
4852
  // R31-57: clamp aria-valuenow into [0,100] (a value of 150 with max 100 is
4628
4853
  // invalid ARIA and the fill was invisible), and fold the target into the
@@ -4715,6 +4940,44 @@ class ContourMetricsFull extends ContourBase {
4715
4940
  }
4716
4941
  define("contour-metrics", ContourMetricsFull);
4717
4942
 
4943
+ /**
4944
+ * Selection Group (R33-43): a cross-component selection coordinator. Holds the
4945
+ * current selection (`selected`, a comma-separated id list) and broadcasts it to
4946
+ * slotted `[data-selection]` children (as `data-selected`) and to the page (as
4947
+ * `contour:selection`). A child's `contour:select` is adopted and rebroadcast,
4948
+ * so a map, table, chart and KPI stay linked without a global store.
4949
+ */
4950
+ class ContourSelectionGroup extends ContourBase {
4951
+ static get observed() { return ["selected", "mode"]; }
4952
+ static get properties() { return { selected: { attribute: "selected", controlled: true }, mode: { attribute: "mode" } }; }
4953
+ render() {
4954
+ this.classList.add("c-selection-group");
4955
+ if (!this.hasAttribute("role")) this.setAttribute("role", "group");
4956
+ const selected = (this.getAttribute("selected") || "").split(",").map((s) => s.trim()).filter(Boolean);
4957
+ for (const child of this.querySelectorAll("[data-selection]")) {
4958
+ child.setAttribute("data-selected", selected.includes(child.getAttribute("data-selection")) ? "true" : "false");
4959
+ }
4960
+ }
4961
+ enhance() {
4962
+ if (this._wiredSelGroup) return;
4963
+ this._wiredSelGroup = true;
4964
+ this.addEventListener("contour:select", (e) => {
4965
+ const detail = e.detail || {};
4966
+ const value = detail.value != null ? String(detail.value) : (detail.key != null ? String(detail.key) : "");
4967
+ // Reflect the adopted selection onto the children in place. Do NOT write
4968
+ // `selected` back to ourselves: it is an observed attribute, so the write
4969
+ // re-enters render (wc-contract). The page owns `selected`; we emit
4970
+ // `contour:selection` for it to round-trip.
4971
+ const selected = value ? [value] : [];
4972
+ for (const child of this.querySelectorAll("[data-selection]")) {
4973
+ child.setAttribute("data-selected", selected.includes(child.getAttribute("data-selection")) ? "true" : "false");
4974
+ }
4975
+ this.dispatchEvent(new CustomEvent("contour:selection", { bubbles: true, composed: true, detail: { value, mode: this.getAttribute("mode") || "single" } }));
4976
+ });
4977
+ }
4978
+ }
4979
+ define("contour-selection-group", ContourSelectionGroup);
4980
+
4718
4981
 
4719
4982
 
4720
4983
 
@@ -4724,8 +4987,8 @@ class ContourMetricsFull extends ContourBase {
4724
4987
  * 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
4988
  */
4726
4989
  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 } }; }
4990
+ 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"]; }
4991
+ 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
4992
  render() {
4730
4993
  this.classList.add("c-legend");
4731
4994
  const graduated = this.hasAttribute("graduated");
@@ -4947,6 +5210,19 @@ class ContourLegend extends ContourBase {
4947
5210
  const c = this.querySelector(".c-legend__classification");
4948
5211
  if (c) c.remove();
4949
5212
  }
5213
+ // R34-169: value domain + ramp direction. The domain names the mapped
5214
+ // range; `reverse` flips the ramp so a high-is-low scale reads correctly.
5215
+ const domain = this.getAttribute("domain");
5216
+ if (domain) {
5217
+ const d = this.ensure(".c-legend__domain", () => { const el = document.createElement("div"); el.className = "c-legend__domain"; return el; });
5218
+ const parts = domain.split(",");
5219
+ d.textContent = (labelText(this, "domain", "Domain") || "Domain") + ": " + parts.join(" – ");
5220
+ } else {
5221
+ const d = this.querySelector(".c-legend__domain");
5222
+ if (d) d.remove();
5223
+ }
5224
+ if (this.hasAttribute("reverse")) this.classList.add("c-legend--reverse");
5225
+ else this.classList.remove("c-legend--reverse");
4950
5226
  // data table (collapsible)
4951
5227
  const tableAttr = this.getAttribute("table");
4952
5228
  if (tableAttr) {
@@ -5188,7 +5464,7 @@ class ContourMeasure extends ContourBase {
5188
5464
  }
5189
5465
  // unit selector
5190
5466
  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); }
5467
+ 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
5468
  ["m","km","mi","ft"].forEach((u) => {
5193
5469
  if (!sel.querySelector('option[value="' + u + '"]')) { const o = document.createElement("option"); o.value = u; o.textContent = u; sel.appendChild(o); }
5194
5470
  });
@@ -5916,8 +6192,24 @@ class ContourErrorBoundary extends ContourBase {
5916
6192
  define("contour-error-boundary", ContourErrorBoundary);
5917
6193
 
5918
6194
  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" } }; }
6195
+ static get observed() { return ["data", "format", "filename", "label", "scope", "crs", "provenance", "selected"]; }
6196
+ 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" } }; }
6197
+ // R34-164: export intent. `scope` narrows the `data` array to the rows a
6198
+ // consumer means to export — visible / filtered / selected / all (default).
6199
+ // `selected` is a JSON array of row keys (or rows carrying `selected: true`);
6200
+ // `visible`/`filtered` read a per-row flag so a host that already computed the
6201
+ // view can hand the full array and let the export honour the scope.
6202
+ scopeRows(rows, scope) {
6203
+ if (scope === "selected") {
6204
+ let keys = null;
6205
+ const sel = this.getAttribute("selected");
6206
+ 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); } }
6207
+ return rows.filter((r) => (keys ? keys.has(String(r && (r.key ?? r.id ?? ""))) : !!(r && r.selected)));
6208
+ }
6209
+ if (scope === "visible") return rows.filter((r) => r && r.visible !== false);
6210
+ if (scope === "filtered") return rows.filter((r) => r && r.filtered !== true);
6211
+ return rows;
6212
+ }
5921
6213
  render() {
5922
6214
  this.classList.add("c-data-export");
5923
6215
  if (!this.hasAttribute("role")) this.setAttribute("role", "group");
@@ -5952,20 +6244,26 @@ class ContourDataExport extends ContourBase {
5952
6244
  if (!btn || !this.contains(btn)) return;
5953
6245
  const rawFmt = (this.getAttribute("format") || "json").toLowerCase();
5954
6246
  const fmt = (rawFmt === "csv" || rawFmt === "json") ? rawFmt : (console.warn("[contour-data-export] unsupported format:", rawFmt), "json");
6247
+ const scope = (this.getAttribute("scope") || "all").toLowerCase();
5955
6248
  const raw = this.getAttribute("data") || "[]";
6249
+ let allRows = [];
6250
+ let parsed = false;
6251
+ try { const a = JSON.parse(raw); if (Array.isArray(a)) { allRows = a; parsed = true; } } catch (err) { warnBadJson(this, "data", err); }
6252
+ const rows = this.scopeRows(allRows, scope);
6253
+ const count = rows.length;
6254
+ const total = allRows.length;
5956
6255
  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
- }
6256
+ if (parsed && (scope !== "all" || fmt === "csv")) {
6257
+ if (fmt === "csv") {
6258
+ if (rows.length === 0) {
6259
+ text = "";
6260
+ } else {
6261
+ const keys = Object.keys(rows[0]);
6262
+ text = [keys.map(csvCell).join(",")].concat(rows.map((r) => keys.map((k) => csvCell(r[k])).join(","))).join("\r\n");
5967
6263
  }
5968
- } catch (err) { warnBadJson(this, "data", err); }
6264
+ } else {
6265
+ text = JSON.stringify(rows);
6266
+ }
5969
6267
  }
5970
6268
  // R31-49: prepend a UTF-8 BOM to CSV so Excel/Sheets read non-ASCII
5971
6269
  // correctly; revoke the object URL asynchronously so the download has
@@ -5973,23 +6271,44 @@ class ContourDataExport extends ContourBase {
5973
6271
  // it in some engines).
5974
6272
  const blob = new Blob([fmt === "csv" ? "\uFEFF" + text : text], { type: fmt === "csv" ? "text/csv" : "application/json" });
5975
6273
  const url = URL.createObjectURL(blob);
6274
+ const filename = this.getAttribute("filename") || ("export." + fmt);
5976
6275
  const a = document.createElement("a");
5977
6276
  a.href = url;
5978
- a.download = this.getAttribute("filename") || ("export." + fmt);
6277
+ a.download = filename;
5979
6278
  document.body.appendChild(a);
5980
6279
  a.click();
5981
6280
  a.remove();
5982
6281
  setTimeout(() => URL.revokeObjectURL(url), 0);
5983
- this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail: { format: fmt } }));
6282
+ // R34-164: file metadata + intent so a host can report what was written
6283
+ // (scope, count/total for progress, resolved filename, CRS/provenance).
6284
+ const detail = { format: fmt, scope, count, total, filename };
6285
+ const crs = this.getAttribute("crs");
6286
+ if (crs) detail.crs = crs;
6287
+ const provenance = this.getAttribute("provenance");
6288
+ if (provenance) detail.provenance = provenance;
6289
+ this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail }));
5984
6290
  });
5985
6291
  }
5986
6292
  }
5987
6293
  define("contour-data-export", ContourDataExport);
5988
6294
 
5989
6295
  // Query builder: field/operator/value rows with AND/OR connectors, remove button per row, Add rule button; renders from `query` JSON, emits contour:change.
6296
+ /**
6297
+ * Read a rule's value from its type-aware editor (R34-165): a range is two
6298
+ * inputs joined "low,high", a null checkbox is the string "null", everything
6299
+ * else is the single control's value.
6300
+ */
6301
+ function readRuleValue(row) {
6302
+ const low = row.querySelector('.c-query-builder__value[data-part="low"]');
6303
+ const high = row.querySelector('.c-query-builder__value[data-part="high"]');
6304
+ if (low || high) return [low ? low.value : "", high ? high.value : ""].join(",");
6305
+ const nullBox = row.querySelector(".c-query-builder__null");
6306
+ if (nullBox) return nullBox.checked ? "null" : "";
6307
+ return row.querySelector(".c-query-builder__value")?.value || "";
6308
+ }
5990
6309
  class ContourQueryBuilder extends ContourBase {
5991
- static get observed() { return ["query", "fields"]; }
5992
- static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" } }; }
6310
+ static get observed() { return ["query", "fields", "draft"]; }
6311
+ static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" }, draft: { attribute: "draft", type: Boolean } }; }
5993
6312
  // 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
6313
  readRules() {
5995
6314
  const rows = [];
@@ -5998,13 +6317,19 @@ class ContourQueryBuilder extends ContourBase {
5998
6317
  const conns = Array.from(this.querySelectorAll(".c-query-builder__connector__op"));
5999
6318
  nodes.forEach((r, i) => {
6000
6319
  const rule = {
6320
+ // R34-165: stable identity. A rule keeps its `id` across structural edits so a
6321
+ // consumer's optimistic write targets the same rule, not the row that slid into
6322
+ // its index.
6323
+ id: r.dataset.ruleId || ("r" + i),
6001
6324
  field: r.querySelector(".c-query-builder__field")?.value || "",
6002
6325
  op: r.querySelector(".c-query-builder__op")?.value || "=",
6003
- value: r.querySelector(".c-query-builder__value")?.value || "",
6326
+ value: readRuleValue(r),
6004
6327
  };
6005
6328
  if (i > 0 && conns[i - 1]) rule.connector = conns[i - 1].value || "AND";
6006
6329
  const g = r.closest(".c-query-builder__group");
6007
6330
  if (g) rule.group = g._groupName || "";
6331
+ // R34-165: NOT is a per-rule negation, a shape+word toggle (never colour).
6332
+ if (r.querySelector(".c-query-builder__not")?.getAttribute("aria-pressed") === "true") rule.not = true;
6008
6333
  rows.push(rule);
6009
6334
  });
6010
6335
  return rows;
@@ -6021,17 +6346,35 @@ class ContourQueryBuilder extends ContourBase {
6021
6346
  attributeChangedCallback(name, oldValue, newValue) {
6022
6347
  if (name === "query" && this._suppressQueryRender) return;
6023
6348
  super.attributeChangedCallback(name, oldValue, newValue);
6349
+ // R34-165: removing `draft` finalizes the held draft into `query`.
6350
+ if (name === "draft" && oldValue != null && newValue == null && this._draftRows) {
6351
+ this.commitDraft();
6352
+ }
6024
6353
  }
6025
6354
  // Write the model back and say so.
6026
6355
  commit(rows, rerender = true) {
6027
- if (rerender) {
6356
+ // R34-165: draft/commit. In draft mode edits are held locally and announced
6357
+ // with draft:true; the author's `query` attribute is untouched until the
6358
+ // draft is committed (attribute removed or commitDraft() called).
6359
+ const draft = this.hasAttribute("draft");
6360
+ if (draft) {
6361
+ this._draftRows = rows;
6362
+ } else if (rerender) {
6028
6363
  this.setAttribute("query", JSON.stringify(rows));
6029
6364
  } else {
6030
6365
  this._suppressQueryRender = true;
6031
6366
  try { this.setAttribute("query", JSON.stringify(rows)); }
6032
6367
  finally { this._suppressQueryRender = false; }
6033
6368
  }
6034
- this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
6369
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows, draft } }));
6370
+ }
6371
+ // Finalize a draft: write it to `query` and announce draft:false (R34-165).
6372
+ commitDraft() {
6373
+ const rows = this._draftRows || this.readRules();
6374
+ this._draftRows = null;
6375
+ this.removeAttribute("draft");
6376
+ this.setAttribute("query", JSON.stringify(rows));
6377
+ this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows, draft: false } }));
6035
6378
  }
6036
6379
  render() {
6037
6380
  this.classList.add("c-query-builder");
@@ -6040,7 +6383,12 @@ class ContourQueryBuilder extends ContourBase {
6040
6383
  if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
6041
6384
  const query = this.getAttribute("query");
6042
6385
  let rules = [];
6043
- if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
6386
+ // R34-165: in draft mode the rows come from the held draft, not the attr.
6387
+ if (this.hasAttribute("draft") && this._draftRows) {
6388
+ rules = this._draftRows;
6389
+ } else if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
6390
+ // Field metadata (type/options) drives the value editor (R34-165).
6391
+ const fieldMeta = (name) => fieldList.find((f) => (typeof f === "string" ? f : (f.value || f.label || "")) === name) || {};
6044
6392
  const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
6045
6393
  Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector, .c-query-builder__group")).forEach((n) => n.remove());
6046
6394
  let currentGroup = null;
@@ -6096,6 +6444,7 @@ class ContourQueryBuilder extends ContourBase {
6096
6444
  }
6097
6445
  const row = document.createElement("div");
6098
6446
  row.className = "c-query-builder__row";
6447
+ row.dataset.ruleId = rule.id || ("r" + i);
6099
6448
  const field = document.createElement("select");
6100
6449
  field.className = "c-input c-query-builder__field";
6101
6450
  field.setAttribute("aria-label", labelText(this, "field", "Field") + " " + (i + 1));
@@ -6115,13 +6464,53 @@ class ContourQueryBuilder extends ContourBase {
6115
6464
  if (o === rule.op) opt.selected = true;
6116
6465
  op.appendChild(opt);
6117
6466
  });
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));
6467
+ // R34-165: type-aware value editor from field metadata — date picker, enum
6468
+ // select, null checkbox, range (two inputs), text fallback.
6469
+ const meta = fieldMeta(rule.field);
6470
+ const vtype = meta.type || "text";
6471
+ const mkText = (type, value, part) => {
6472
+ const el = document.createElement("input");
6473
+ el.className = "c-input c-query-builder__value";
6474
+ el.type = type;
6475
+ if (part) el.dataset.part = part;
6476
+ el.setAttribute("value", value || "");
6477
+ el.value = value || "";
6478
+ el.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1) + (part ? " " + part : ""));
6479
+ return el;
6480
+ };
6481
+ let val;
6482
+ if (vtype === "enum" && Array.isArray(meta.options) && meta.options.length) {
6483
+ val = document.createElement("select");
6484
+ val.className = "c-input c-query-builder__value";
6485
+ val.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1));
6486
+ meta.options.forEach((o) => {
6487
+ const opt = document.createElement("option");
6488
+ opt.value = typeof o === "string" ? o : (o.value ?? o);
6489
+ opt.textContent = typeof o === "string" ? o : (o.label ?? o.value ?? o);
6490
+ if (opt.value === rule.value) opt.selected = true;
6491
+ val.appendChild(opt);
6492
+ });
6493
+ } else if (vtype === "null") {
6494
+ val = document.createElement("input");
6495
+ val.type = "checkbox";
6496
+ val.className = "c-query-builder__value c-query-builder__null";
6497
+ val.checked = rule.value === "null";
6498
+ val.setAttribute("aria-label", labelText(this, "is-null", "Is null") + " " + (i + 1));
6499
+ } else if (vtype === "range") {
6500
+ const parts = String(rule.value || "").split(",");
6501
+ val = document.createDocumentFragment();
6502
+ val.appendChild(mkText("number", parts[0], "low"));
6503
+ val.appendChild(mkText("number", parts[1], "high"));
6504
+ } else {
6505
+ val = mkText(vtype === "date" ? "date" : "text", rule.value);
6506
+ }
6507
+ // R34-165: NOT is a per-rule negation toggle (shape+word, aria-pressed).
6508
+ const notBtn = document.createElement("button");
6509
+ notBtn.type = "button";
6510
+ notBtn.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__not";
6511
+ notBtn.setAttribute("aria-label", labelText(this, "negate", "Negate") + " " + (i + 1));
6512
+ notBtn.setAttribute("aria-pressed", rule.not ? "true" : "false");
6513
+ notBtn.textContent = "NOT";
6125
6514
  // Reordering (WC5-75): buttons not drag handles (pointer-only), so keyboard can reach same operation.
6126
6515
  const up = document.createElement("button");
6127
6516
  up.type = "button";
@@ -6140,7 +6529,7 @@ class ContourQueryBuilder extends ContourBase {
6140
6529
  remove.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__remove";
6141
6530
  remove.setAttribute("aria-label", labelText(this, "remove-rule", "Remove rule") + " " + (i + 1));
6142
6531
  remove.textContent = "\u00d7";
6143
- row.appendChild(field); row.appendChild(op); row.appendChild(val);
6532
+ row.appendChild(field); row.appendChild(op); row.appendChild(val); row.appendChild(notBtn);
6144
6533
  row.appendChild(up); row.appendChild(down); row.appendChild(remove);
6145
6534
  if (currentGroup) currentGroup.appendChild(row); else list.appendChild(row);
6146
6535
  });
@@ -6167,6 +6556,14 @@ class ContourQueryBuilder extends ContourBase {
6167
6556
  this.addEventListener("click", (e) => {
6168
6557
  const t = e.target;
6169
6558
  if (!(t instanceof Element)) return;
6559
+ // R34-165: NOT toggle flips aria-pressed and commits the negation.
6560
+ const notBtn = t.closest(".c-query-builder__not");
6561
+ if (notBtn) {
6562
+ const next = notBtn.getAttribute("aria-pressed") !== "true";
6563
+ notBtn.setAttribute("aria-pressed", String(next));
6564
+ this.commit(this.readRules(), false);
6565
+ return;
6566
+ }
6170
6567
  if (t.closest(".c-query-builder__add")) {
6171
6568
  const conns = this.readRules().map((r) => r.connector);
6172
6569
  const rows = this.readRules();