contour-ds 1.8.1 → 1.9.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 (147) hide show
  1. package/README.md +227 -378
  2. package/dist/agent-cookbook.json +960 -0
  3. package/dist/agent-examples.json +65 -0
  4. package/dist/agent-map-wiring.json +152 -0
  5. package/dist/build-manifest.json +320 -179
  6. package/dist/contour-wc-content.esm.js +479 -3665
  7. package/dist/contour-wc-content.esm.min.js +1 -1
  8. package/dist/contour-wc-core.esm.js +3724 -0
  9. package/dist/contour-wc-core.esm.min.js +1 -0
  10. package/dist/contour-wc-dashboard.esm.js +2713 -4381
  11. package/dist/contour-wc-dashboard.esm.min.js +1 -1
  12. package/dist/contour-wc-data.esm.js +2658 -4346
  13. package/dist/contour-wc-data.esm.min.js +1 -1
  14. package/dist/contour-wc-docs.esm.js +218 -3547
  15. package/dist/contour-wc-docs.esm.min.js +1 -1
  16. package/dist/contour-wc-feedback.esm.js +483 -3658
  17. package/dist/contour-wc-feedback.esm.min.js +1 -1
  18. package/dist/contour-wc-forms.esm.js +503 -3754
  19. package/dist/contour-wc-forms.esm.min.js +1 -1
  20. package/dist/contour-wc-interaction.esm.js +379 -3616
  21. package/dist/contour-wc-interaction.esm.min.js +1 -1
  22. package/dist/contour-wc-layout.esm.js +234 -3563
  23. package/dist/contour-wc-layout.esm.min.js +1 -1
  24. package/dist/contour-wc-map.esm.js +949 -3743
  25. package/dist/contour-wc-map.esm.min.js +1 -1
  26. package/dist/contour-wc-misc.esm.js +237 -3556
  27. package/dist/contour-wc-misc.esm.min.js +1 -1
  28. package/dist/contour-wc-navigation.esm.js +2235 -5237
  29. package/dist/contour-wc-navigation.esm.min.js +1 -1
  30. package/dist/contour-wc-ui.esm.js +4638 -7128
  31. package/dist/contour-wc-ui.esm.min.js +1 -1
  32. package/dist/contour-wc.esm.js +11971 -7727
  33. package/dist/contour-wc.esm.min.js +1 -1
  34. package/dist/contour-wc.js +11971 -7727
  35. package/dist/contour-wc.min.js +1 -1
  36. package/dist/contour.a11y.json +402 -0
  37. package/dist/contour.code-snippets +96 -74
  38. package/dist/contour.components.json +2591 -741
  39. package/dist/contour.css +2624 -1888
  40. package/dist/contour.d.ts +421 -228
  41. package/dist/contour.esm.js +433 -18
  42. package/dist/contour.esm.min.js +1 -1
  43. package/dist/contour.html-data.json +1231 -199
  44. package/dist/contour.js +433 -18
  45. package/dist/contour.min.css +1 -1
  46. package/dist/contour.min.js +1 -1
  47. package/dist/contour.react.d.ts +100 -98
  48. package/dist/contour.single.html +2 -2
  49. package/dist/contour.single.min.css +1 -1
  50. package/dist/contour.themes.json +56 -12
  51. package/dist/contour.tokens.json +482 -255
  52. package/dist/contour.vue.d.ts +100 -98
  53. package/dist/contour.web-types.json +1226 -226
  54. package/dist/custom-elements.json +7649 -2237
  55. package/dist/docs/actions.md +15 -6
  56. package/dist/docs/affordances.md +18 -96
  57. package/dist/docs/apireference.md +9 -5
  58. package/dist/docs/colour.md +10 -4
  59. package/dist/docs/componentindex.md +9 -26
  60. package/dist/docs/data.md +36 -60
  61. package/dist/docs/docs.md +10 -12
  62. package/dist/docs/feedback.md +30 -12
  63. package/dist/docs/field.md +28 -13
  64. package/dist/docs/forms.md +35 -19
  65. package/dist/docs/index.json +63 -56
  66. package/dist/docs/install.md +12 -7
  67. package/dist/docs/landing.md +7 -4
  68. package/dist/docs/mapengine.md +18 -13
  69. package/dist/docs/motion.md +12 -6
  70. package/dist/docs/navigation.md +31 -7
  71. package/dist/docs/overlays.md +32 -25
  72. package/dist/docs/overview.md +3 -2
  73. package/dist/docs/patterns.md +19 -9
  74. package/dist/docs/playground.md +9 -22
  75. package/dist/docs/principles.md +8 -6
  76. package/dist/docs/recipes.md +113 -14
  77. package/dist/docs/space.md +10 -6
  78. package/dist/docs/status.md +12 -25
  79. package/dist/docs/surfaces.md +17 -22
  80. package/dist/docs/theming.md +18 -32
  81. package/dist/docs/type.md +12 -5
  82. package/dist/docs/webcomponents.md +66 -38
  83. package/dist/hljs.css +1 -20
  84. package/dist/map-chrome.mapbox.css +68 -92
  85. package/dist/map-chrome.maplibre.css +68 -92
  86. package/dist/registry/items/contour-core.json +2 -2
  87. package/dist/registry/items/contour-data.json +2 -2
  88. package/dist/registry/items/contour-docs.json +2 -2
  89. package/dist/registry/items/contour-landing.json +2 -2
  90. package/dist/registry/registry.json +8 -8
  91. package/dist/surfaces/contour-core.min.css +1 -1
  92. package/dist/surfaces/contour-data.min.css +1 -1
  93. package/dist/surfaces/contour-docs.min.css +1 -1
  94. package/dist/surfaces/contour-landing.min.css +1 -1
  95. package/dist/svg/icons.svg +367 -0
  96. package/dist/wc/behaviours.mjs +190 -148
  97. package/dist/wc/content.mjs +273 -129
  98. package/dist/wc/core.mjs +598 -395
  99. package/dist/wc/dashboard.mjs +64 -44
  100. package/dist/wc/data-chart.mjs +1333 -0
  101. package/dist/wc/data-export.mjs +391 -0
  102. package/dist/wc/data-gauge.mjs +779 -0
  103. package/dist/wc/data-geo.mjs +696 -0
  104. package/dist/wc/data-glyphs.mjs +133 -0
  105. package/dist/wc/data-legend.mjs +431 -0
  106. package/dist/wc/data-readout.mjs +227 -0
  107. package/dist/wc/data-series.mjs +1004 -0
  108. package/dist/wc/data-table.mjs +751 -0
  109. package/dist/wc/data.mjs +15 -4322
  110. package/dist/wc/docs.mjs +12 -11
  111. package/dist/wc/feedback.mjs +277 -122
  112. package/dist/wc/forms-controls.mjs +635 -0
  113. package/dist/wc/forms-field.mjs +547 -0
  114. package/dist/wc/forms-groups.mjs +347 -0
  115. package/dist/wc/forms-input.mjs +292 -0
  116. package/dist/wc/forms.mjs +10 -1751
  117. package/dist/wc/glyph.mjs +204 -0
  118. package/dist/wc/index.mjs +11 -9
  119. package/dist/wc/interaction.mjs +173 -80
  120. package/dist/wc/layout.mjs +28 -27
  121. package/dist/wc/map.mjs +743 -207
  122. package/dist/wc/misc.mjs +31 -20
  123. package/dist/wc/navigation-menu.mjs +735 -0
  124. package/dist/wc/navigation-shell.mjs +495 -0
  125. package/dist/wc/navigation-tree.mjs +995 -0
  126. package/dist/wc/navigation.mjs +9 -1905
  127. package/dist/wc/registration.mjs +1 -8
  128. package/dist/wc/shadow.mjs +206 -110
  129. package/dist/wc/states.mjs +54 -75
  130. package/dist/wc/svg.mjs +118 -47
  131. package/dist/wc/ui-atoms.mjs +608 -0
  132. package/dist/wc/ui-data.mjs +1404 -0
  133. package/dist/wc/ui-feedback.mjs +419 -0
  134. package/dist/wc/ui-inputs.mjs +1570 -0
  135. package/dist/wc/ui-menus.mjs +307 -0
  136. package/dist/wc/ui-overlays.mjs +1605 -0
  137. package/integrations/README.md +23 -5
  138. package/integrations/ai/CLAUDE.md +3 -0
  139. package/integrations/ai/COPILOT.md +14 -0
  140. package/integrations/ai/GEMINI.md +14 -0
  141. package/integrations/ai/WINDSURF.md +14 -0
  142. package/integrations/ai/v0-prompt.md +13 -1
  143. package/integrations/native/README.md +0 -3
  144. package/integrations/tailwind/contour-theme.css +66 -7
  145. package/integrations/validate-markup.mjs +172 -0
  146. package/package.json +77 -42
  147. package/dist/wc/ui.mjs +0 -5072
@@ -24,6 +24,64 @@
24
24
 
25
25
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)");
26
26
 
27
+ /* Anchor landing correction.
28
+ ----------------------------------------------------------------------------
29
+ A same-page anchor scrolls to where the target sits *now*. On a long page
30
+ with `content-visibility: auto` subtrees (specimens, cards, tables) — and
31
+ while web components, maps and fonts are still upgrading — the page keeps
32
+ growing, so the target slides away from the offset the browser is animating
33
+ toward and the browser never retargets mid-flight. The jump lands short, and
34
+ only a second click, measured against the now-settled layout, gets closer.
35
+ This pins the target to the root's `scroll-padding-block-start` offset for a
36
+ short window, re-correcting every frame while late layout keeps moving it.
37
+ Generic: it names no component, only the target element and the root's own
38
+ `scroll-padding-block-start`. */
39
+ let anchorGen = 0;
40
+ const anchorOffset = () => {
41
+ const v = parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop);
42
+ return Number.isFinite(v) ? v : 0;
43
+ };
44
+ const correctAnchor = (el, gen) => {
45
+ // Pin, don't snap: the page keeps growing for a moment after the scroll
46
+ // (web-component upgrades, map mounts, font swap, content-visibility
47
+ // hydration), so a single correction is undone by the next reflow. Hold the
48
+ // target at the offset for a short window instead. Starting immediately also
49
+ // overrides the root's `scroll-behavior: smooth` on the first frame — a
50
+ // smooth scroll over a long page drifts too far for one correction to catch.
51
+ const root = document.documentElement;
52
+ const prevAnchor = root.style.overflowAnchor;
53
+ root.style.overflowAnchor = "none"; // stop anchoring undoing each correction
54
+ const until = performance.now() + 2500;
55
+ let first = true;
56
+ const tick = () => {
57
+ if (gen !== anchorGen) {
58
+ root.style.overflowAnchor = prevAnchor;
59
+ return;
60
+ }
61
+ const delta = el.getBoundingClientRect().top - anchorOffset();
62
+ // After the first correction, a large delta means the reader has scrolled
63
+ // well away from the target — pinning would yank them back, the bug not
64
+ // the fix. The first tick always corrects: that is the landing itself.
65
+ if (!first && Math.abs(delta) > window.innerHeight * 3) {
66
+ root.style.overflowAnchor = prevAnchor;
67
+ return;
68
+ }
69
+ first = false;
70
+ if (Math.abs(delta) > 2) {
71
+ // "instant", not "auto": the root sets `scroll-behavior: smooth`, and
72
+ // "auto" would re-run the very animation that landed short.
73
+ window.scrollTo({ top: window.scrollY + delta, behavior: "instant" });
74
+ }
75
+ if (performance.now() < until) setTimeout(tick, 16);
76
+ else root.style.overflowAnchor = prevAnchor;
77
+ };
78
+ tick();
79
+ };
80
+ const settleAnchor = (el) => {
81
+ if (!el) return;
82
+ correctAnchor(el, ++anchorGen);
83
+ };
84
+
27
85
  /* Jump to an element and keep the address bar in step, without stacking up
28
86
  history entries for a single jump. Hoisted to top level so the public
29
87
  API (window.Contour.scrollTo) can reach it. */
@@ -36,8 +94,27 @@
36
94
  behavior: reducedMotion.matches ? "auto" : "smooth",
37
95
  block: "start",
38
96
  });
97
+ settleAnchor(el);
39
98
  };
40
99
 
100
+ /* Native same-page anchors (the guide's side rail, any consumer's in-page
101
+ links) scroll by the browser's default action, not through goTo. Let that
102
+ happen, then correct the landing the same way. Capture phase so the target
103
+ is known before the default scroll starts; never preventDefault. */
104
+ document.addEventListener(
105
+ "click",
106
+ (event) => {
107
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
108
+ const a = event.target.closest && event.target.closest('a[href^="#"]');
109
+ if (!a) return;
110
+ const id = a.getAttribute("href").slice(1);
111
+ if (!id) return;
112
+ const target = document.getElementById(id);
113
+ if (target) settleAnchor(target);
114
+ },
115
+ true,
116
+ );
117
+
41
118
  /* ---------------------------------------------------------------------
42
119
  1. Colour scheme
43
120
  The <meta name="color-scheme"> element is the single source of truth.
@@ -186,8 +263,9 @@
186
263
  activate(next);
187
264
  });
188
265
  });
189
- // Initialise: hide non-default panels (progressive enhancement).
190
- if (tabs[0]) activate(tabs[0], false);
266
+ // Initialise: honor author-marked selection or default to first tab.
267
+ const initialTab = tabs.find((t) => t.getAttribute("aria-selected") === "true") || tabs[0];
268
+ if (initialTab) activate(initialTab, false);
191
269
  });
192
270
 
193
271
  /* ---------------------------------------------------------------------
@@ -199,7 +277,7 @@
199
277
  option.addEventListener("click", () => {
200
278
  options.forEach((o) => o.setAttribute("aria-pressed", String(o === option)));
201
279
  group.dispatchEvent(
202
- new CustomEvent("contour:change", { detail: { value: option.dataset.value } }),
280
+ new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: option.dataset.value } }),
203
281
  );
204
282
  });
205
283
  });
@@ -248,6 +326,76 @@
248
326
  if (use) use.setAttribute('href', playing ? '#i-pause' : '#i-play');
249
327
  });
250
328
  });
329
+ $$('.c-time-slider__loop').forEach((btn) => {
330
+ btn.addEventListener('click', () => {
331
+ const pressed = btn.getAttribute('aria-pressed') === 'true';
332
+ btn.setAttribute('aria-pressed', String(!pressed));
333
+ });
334
+ });
335
+
336
+ /* ---------------------------------------------------------------------
337
+ 4c. Comparison — draggable before/after divider
338
+ --------------------------------------------------------------------- */
339
+ $$('.c-comparison__divider').forEach((divider) => {
340
+ const container = divider.closest('.c-comparison');
341
+ if (!container) return;
342
+ const setPos = (clientX) => {
343
+ const rect = container.getBoundingClientRect();
344
+ if (!rect.width) return;
345
+ const pct = Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100));
346
+ container.style.setProperty('--comparison-pos', pct + '%');
347
+ };
348
+ divider.addEventListener('pointerdown', (e) => {
349
+ e.preventDefault();
350
+ divider.setPointerCapture(e.pointerId);
351
+ setPos(e.clientX);
352
+ });
353
+ divider.addEventListener('pointermove', (e) => {
354
+ if (divider.hasPointerCapture(e.pointerId)) setPos(e.clientX);
355
+ });
356
+ const release = (e) => {
357
+ if (divider.hasPointerCapture(e.pointerId)) divider.releasePointerCapture(e.pointerId);
358
+ };
359
+ divider.addEventListener('pointerup', release);
360
+ divider.addEventListener('pointercancel', release);
361
+ });
362
+
363
+ /* ---------------------------------------------------------------------
364
+ 4d. Brush — draggable range selection
365
+ --------------------------------------------------------------------- */
366
+ $$('.c-brush').forEach((brush) => {
367
+ const handles = brush.querySelectorAll('.c-brush__handle');
368
+ const selection = brush.querySelector('.c-brush__selection');
369
+ if (handles.length < 2 || !selection) return;
370
+ const range = brush.parentElement.querySelector('.c-brush__range');
371
+ const setPos = (handle, pct) => {
372
+ pct = Math.max(0, Math.min(100, pct));
373
+ handle.style.insetInlineStart = pct + '%';
374
+ const a = parseFloat(handles[0].style.insetInlineStart) || 0;
375
+ const b = parseFloat(handles[1].style.insetInlineStart) || 100;
376
+ const lo = Math.min(a, b), hi = Math.max(a, b);
377
+ selection.style.insetInlineStart = lo + '%';
378
+ selection.style.inlineSize = (hi - lo) + '%';
379
+ if (range) range.textContent = `${Math.round(lo)} – ${Math.round(hi)} · ${Math.round(hi - lo)}% of the range`;
380
+ };
381
+ handles.forEach((handle) => {
382
+ handle.addEventListener('pointerdown', (e) => {
383
+ e.preventDefault();
384
+ handle.setPointerCapture(e.pointerId);
385
+ });
386
+ handle.addEventListener('pointermove', (e) => {
387
+ if (!handle.hasPointerCapture(e.pointerId)) return;
388
+ const rect = brush.getBoundingClientRect();
389
+ if (!rect.width) return;
390
+ setPos(handle, ((e.clientX - rect.left) / rect.width) * 100);
391
+ });
392
+ const release = (e) => {
393
+ if (handle.hasPointerCapture(e.pointerId)) handle.releasePointerCapture(e.pointerId);
394
+ };
395
+ handle.addEventListener('pointerup', release);
396
+ handle.addEventListener('pointercancel', release);
397
+ });
398
+ });
251
399
 
252
400
  /* ---------------------------------------------------------------------
253
401
  5. Section spy — highlights the current section in the spec rail
@@ -321,7 +469,29 @@
321
469
 
322
470
  const selector = trigger.dataset.copy;
323
471
  const source = selector ? $(selector) : trigger.previousElementSibling;
324
- const text = source?.textContent?.trim() ?? "";
472
+ // A numbered code block splits its source into .c-code__line rows, each
473
+ // carrying an aria-hidden .c-code__line-number ruler. textContent would copy
474
+ // the ruler too ("1npm install …2pnpm add …"), so the claim "the copy action
475
+ // writes the code alone" was false (R26-26). Copy the code alone: one line
476
+ // per row, ruler removed. This is scoped to .c-code__line-number — it does
477
+ // NOT strip aria-hidden content generally, and blocks without .c-code__line
478
+ // rows keep the plain textContent path unchanged.
479
+ let text = "";
480
+ if (source) {
481
+ const lines = source.querySelectorAll(".c-code__line");
482
+ if (lines.length) {
483
+ text = Array.from(lines)
484
+ .map((line) => {
485
+ const clone = line.cloneNode(true);
486
+ clone.querySelectorAll(".c-code__line-number").forEach((n) => n.remove());
487
+ return clone.textContent;
488
+ })
489
+ .join("\n")
490
+ .trim();
491
+ } else {
492
+ text = source.textContent?.trim() ?? "";
493
+ }
494
+ }
325
495
  if (!text) return;
326
496
 
327
497
  const ok = await copyText(text);
@@ -381,6 +551,7 @@
381
551
  host.append(toast);
382
552
 
383
553
  requestAnimationFrame(() => {
554
+ if (reducedMotion.matches) return;
384
555
  toast.animate(
385
556
  [
386
557
  { opacity: 0, transform: "translateY(0.75rem) scale(0.98)" },
@@ -391,6 +562,10 @@
391
562
  });
392
563
 
393
564
  setTimeout(() => {
565
+ if (reducedMotion.matches) {
566
+ toast.remove();
567
+ return;
568
+ }
394
569
  toast.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 200 }).onfinish = () =>
395
570
  toast.remove();
396
571
  }, 3200);
@@ -525,6 +700,75 @@
525
700
  });
526
701
  });
527
702
 
703
+ /* ---------------------------------------------------------------------
704
+ 11c. Menu — roving focus + arrow keys for the light-DOM pattern
705
+ --------------------------------------------------------------------- */
706
+ // A role="menu" whose items no keyboard can reach is a menu only a mouse
707
+ // can read (R28-19). Mirror wireMenu: one tab stop, ArrowUp/Down wrap,
708
+ // Home/End, Enter/Space activates, a printable character jumps to the first
709
+ // item that starts with it. Skip menus inside hosts that wire their own
710
+ // (contour-menu, contour-dropdown, contour-split-button) — double-binding
711
+ // would move focus twice per keypress.
712
+ $$(".c-menu").forEach((menu) => {
713
+ if (menu.closest("contour-menu, contour-dropdown, contour-split-button")) return;
714
+ const SEL = "[role='menuitem'], [role='menuitemcheckbox'], [role='menuitemradio']";
715
+ const all = () => $$(SEL, menu);
716
+ const enabled = () => all().filter((it) => it.getAttribute("aria-disabled") !== "true");
717
+ if (!all().length) return;
718
+ const rove = (keep) => {
719
+ all().forEach((it) => it.setAttribute("tabindex", it === keep ? "0" : "-1"));
720
+ };
721
+ // The author's own tabindex="0" wins, then the first enabled item.
722
+ const authored = all().find((it) => it.getAttribute("tabindex") === "0");
723
+ rove(authored || enabled()[0] || all()[0]);
724
+
725
+ menu.addEventListener("focusin", (e) => {
726
+ const it = e.target.closest(SEL);
727
+ if (it && menu.contains(it)) rove(it);
728
+ });
729
+
730
+ menu.addEventListener("click", (e) => {
731
+ const it = e.target.closest(SEL);
732
+ if (!it || !menu.contains(it) || it.getAttribute("aria-disabled") === "true") return;
733
+ const role = it.getAttribute("role");
734
+ const detail = { index: all().indexOf(it), label: it.textContent.trim() };
735
+ if (role === "menuitemcheckbox" || role === "menuitemradio") {
736
+ const checked = it.getAttribute("aria-checked") === "true";
737
+ it.setAttribute("aria-checked", String(!checked));
738
+ detail.checked = !checked;
739
+ }
740
+ it.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, detail }));
741
+ });
742
+
743
+ menu.addEventListener("keydown", (e) => {
744
+ const its = enabled();
745
+ const idx = its.indexOf(e.target);
746
+ if (idx < 0) return;
747
+ const move = (next) => {
748
+ if (!next) return;
749
+ e.preventDefault();
750
+ // Own the key: a page-level handler (a tour, a shortcut layer) must
751
+ // not also act on an arrow the menu already consumed.
752
+ e.stopPropagation();
753
+ next.focus();
754
+ rove(next);
755
+ };
756
+ if (e.key === "ArrowDown") move(its[(idx + 1) % its.length]);
757
+ else if (e.key === "ArrowUp") move(its[(idx - 1 + its.length) % its.length]);
758
+ else if (e.key === "Home") move(its[0]);
759
+ else if (e.key === "End") move(its[its.length - 1]);
760
+ else if (e.key === "Enter" || e.key === " ") {
761
+ e.preventDefault();
762
+ e.stopPropagation();
763
+ its[idx].click();
764
+ } else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
765
+ const ch = e.key.toLowerCase();
766
+ const match = its.find((it) => it.textContent.trim().toLowerCase().startsWith(ch));
767
+ if (match) move(match);
768
+ }
769
+ });
770
+ });
771
+
528
772
  /* ---------------------------------------------------------------------
529
773
  12. Alerts — dismiss
530
774
  --------------------------------------------------------------------- */
@@ -569,6 +813,10 @@
569
813
  const field = $("[data-command-field]", palette);
570
814
  const list = $("[data-command-list]", palette);
571
815
  const empty = $("[data-command-empty]", palette);
816
+ // The palette starts closed. Static markup may ship aria-expanded="true"
817
+ // (the guide's does); correct the state before the first open so the
818
+ // combobox never announces an expanded list that is not there (GC-09).
819
+ field?.setAttribute("aria-expanded", "false");
572
820
  const supportsPopover = typeof palette.showPopover === "function";
573
821
  let index = [];
574
822
  let filtered = [];
@@ -617,11 +865,34 @@
617
865
  a.dataset.commandHint || "",
618
866
  a.dataset.commandIcon || "i-file",
619
867
  () => {
620
- location.hash = a.getAttribute("href");
868
+ // Scroll through goTo(), the same path Sections entries use: a
869
+ // bare location.hash assignment is a silent no-op when the hash
870
+ // already equals the target — no hashchange, no scroll (GC-08).
871
+ const href = a.getAttribute("href");
872
+ const target = href.startsWith("#")
873
+ ? document.getElementById(href.slice(1))
874
+ : null;
875
+ if (target) goTo(target);
876
+ else location.hash = href;
621
877
  },
622
878
  );
623
879
  });
624
880
 
881
+ // Components: a page marks its searchable specimens with
882
+ // data-command-component (the guide marks every specimen head). The
883
+ // palette promises "Search components, sections and actions"; without
884
+ // this block the promise was false — kpi/button/dialog matched nothing
885
+ // (R28-16). The title is the component's name, the hint its selector.
886
+ $$("[data-command-component]").forEach((el) => {
887
+ push(
888
+ "Components",
889
+ el.dataset.commandComponent,
890
+ el.dataset.commandHint || "",
891
+ el.dataset.commandIcon || "i-grid",
892
+ () => goTo(el),
893
+ );
894
+ });
895
+
625
896
  // Sections of the current document, however they are marked up.
626
897
  $$("main section[id]").forEach((section) => {
627
898
  const heading =
@@ -792,6 +1063,15 @@
792
1063
  field.value = "";
793
1064
  render();
794
1065
  field.setAttribute("aria-expanded", "true");
1066
+ // A page may have modalised around an open disclosure and inerted the
1067
+ // palette's subtree. A top-layer popover still shows while inert, but
1068
+ // it cannot take focus — a visible, dead palette (GC-03). Release the
1069
+ // palette's own ancestor chain. A closed popover is display:none, so
1070
+ // leaving the chain released cannot leak focus or clicks back into the
1071
+ // page once the palette closes again.
1072
+ for (let el = palette; el && el !== document.body; el = el.parentElement) {
1073
+ if (el.inert) el.inert = false;
1074
+ }
795
1075
  if (supportsPopover) palette.showPopover();
796
1076
  else palette.classList.add("is-open");
797
1077
  requestAnimationFrame(() => field.focus());
@@ -833,6 +1113,12 @@
833
1113
  field.value = "";
834
1114
  render();
835
1115
  } else {
1116
+ // Own the key: the page behind may have its own Escape contract
1117
+ // (an open snippet disclosure). Closing the palette must not also
1118
+ // dismiss the layer underneath — guide.js yields Escape to the
1119
+ // palette while it is open, and this keeps that yield true.
1120
+ event.preventDefault();
1121
+ event.stopPropagation();
836
1122
  close();
837
1123
  }
838
1124
  }
@@ -1088,7 +1374,15 @@
1088
1374
  --------------------------------------------------------------------- */
1089
1375
  // Colour-vision preview producer (T-134).
1090
1376
  $$("[data-cvd-toggle]").forEach((group) => {
1091
- const scope = document.getElementById("data") || document.documentElement;
1377
+ // The preview is document-wide by default (R26-64). The producer used to be
1378
+ // hard-wired to the guide's #data section — nine sections from where the
1379
+ // control sits — so it previewed only those charts and nothing beside the
1380
+ // reader. A named data-cvd-scope narrows it; otherwise every chart and
1381
+ // datamark in the document is previewed, so the effect is not remote-only.
1382
+ // The system script must not hard-code a guide section id.
1383
+ const scope =
1384
+ (group.dataset.cvdScope && document.getElementById(group.dataset.cvdScope)) ||
1385
+ document.documentElement;
1092
1386
  const targets = () => $$(".u-cvd-target, .c-chart, .c-datamark", scope);
1093
1387
  $$("button", group).forEach((btn) => {
1094
1388
  btn.addEventListener("click", () => {
@@ -1135,14 +1429,26 @@
1135
1429
  // "auto" is the default and is taken off rather than written, which leaves
1136
1430
  // the media query in charge until the reader overrides it.
1137
1431
  $$("[data-motion-toggle]").forEach((group) => {
1432
+ // A reader pause is a PAGE-level mechanism (WCAG 2.2.2, R26-63): it must
1433
+ // reach every animation on the page, not only the demo region a toggle
1434
+ // happens to sit beside. A page's own infinite motion can live outside any
1435
+ // demo scope, so a toggle confined to `data-motion-scope` would pause the
1436
+ // demo and leave that motion running. The attribute therefore lands on the
1437
+ // document root, which the `[data-motion] *` descendant rules in
1438
+ // utilities.css pause wholesale (pseudo-elements included). A named
1439
+ // `data-motion-scope` still receives it, so a scoped demo's own element
1440
+ // carries the attribute for inspection, but the pause is never confined to
1441
+ // that scope.
1138
1442
  const scope =
1139
- (group.dataset.motionScope && document.getElementById(group.dataset.motionScope)) ||
1140
- document.documentElement;
1443
+ (group.dataset.motionScope && document.getElementById(group.dataset.motionScope)) || null;
1444
+ const targets = scope ? [document.documentElement, scope] : [document.documentElement];
1141
1445
  $$("button", group).forEach((btn) => {
1142
1446
  btn.addEventListener("click", () => {
1143
1447
  const value = btn.dataset.motionValue || "auto";
1144
- if (value === "auto") scope.removeAttribute("data-motion");
1145
- else scope.setAttribute("data-motion", value);
1448
+ targets.forEach((el) => {
1449
+ if (value === "auto") el.removeAttribute("data-motion");
1450
+ else el.setAttribute("data-motion", value);
1451
+ });
1146
1452
  $$("button", group).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
1147
1453
  });
1148
1454
  });
@@ -1369,21 +1675,128 @@
1369
1675
  });
1370
1676
 
1371
1677
  /* ---------------------------------------------------------------------
1372
- 22. Tree view — expand/collapse
1678
+ 22. Tree view — expand/collapse + the tree keyboard pattern
1373
1679
  --------------------------------------------------------------------- */
1374
- $$(".c-tree__toggle").forEach((toggle) => {
1375
- toggle.addEventListener("click", (e) => {
1376
- e.stopPropagation();
1377
- const expanded = toggle.getAttribute("aria-expanded") === "true";
1378
- toggle.setAttribute("aria-expanded", String(!expanded));
1379
- const row = toggle.closest(".c-tree__row");
1680
+ // Delegate on the row so a click on the label toggles too, not only the
1681
+ // twisty — the same contract wireTree gives the web component. Skip
1682
+ // contour-tree hosts: they wire their own rows (double-binding would toggle
1683
+ // twice and cancel out).
1684
+ //
1685
+ // Roving tabindex + arrow keys mirror wireTree (R28-19): a role="tree"
1686
+ // whose items no keyboard can reach is a tree only a mouse can read. One
1687
+ // tab stop, never none and never N; a collapsed branch's hidden children
1688
+ // hold no stop, because a stop on a hidden node is a stop the reader never
1689
+ // arrives at.
1690
+ $$(".c-tree").forEach((tree) => {
1691
+ if (tree.closest("contour-tree")) return;
1692
+ const SEL = ".c-tree__toggle, .c-tree__leaf";
1693
+ const stops = () => $$(SEL, tree).filter((el) => !el.closest(".c-tree__children[hidden]"));
1694
+ const rove = (keep) => {
1695
+ $$(SEL, tree).forEach((el) => el.setAttribute("tabindex", el === keep ? "0" : "-1"));
1696
+ };
1697
+ const refresh = () => {
1698
+ const visible = stops();
1699
+ const keep =
1700
+ visible.find((el) => el.getAttribute("tabindex") === "0") ||
1701
+ visible.find((el) => el === document.activeElement) ||
1702
+ visible[0];
1703
+ if (keep) rove(keep);
1704
+ };
1705
+ const toggle = (btn) => {
1706
+ const expanded = btn.getAttribute("aria-expanded") === "true";
1707
+ btn.setAttribute("aria-expanded", String(!expanded));
1708
+ const row = btn.closest(".c-tree__row");
1380
1709
  if (row) row.setAttribute("aria-expanded", String(!expanded));
1381
- const children = toggle.closest(".c-tree__node")?.querySelector(":scope > .c-tree__children");
1710
+ const node = btn.closest(".c-tree__node");
1711
+ // The node is the role="treeitem" element — its aria-expanded is the
1712
+ // state assistive tech reads, so it must move with the toggle.
1713
+ if (node) node.setAttribute("aria-expanded", String(!expanded));
1714
+ const children = node?.querySelector(":scope > .c-tree__children");
1382
1715
  if (children) {
1383
1716
  if (expanded) children.setAttribute("hidden", "");
1384
1717
  else children.removeAttribute("hidden");
1385
1718
  }
1719
+ // Opening a branch must not leave a second stop behind, and collapsing
1720
+ // one must demote every stop that just became hidden.
1721
+ refresh();
1722
+ };
1723
+
1724
+ $$(".c-tree__row", tree).forEach((row) => {
1725
+ row.addEventListener("click", (e) => {
1726
+ const btn = row.querySelector(":scope > .c-tree__toggle");
1727
+ if (!btn) return;
1728
+ e.stopPropagation();
1729
+ toggle(btn);
1730
+ });
1731
+ });
1732
+
1733
+ // Roving the tab stop with focus, so the tree is one Tab and not N.
1734
+ tree.addEventListener("focusin", (e) => {
1735
+ const el = e.target.closest(SEL);
1736
+ if (el && tree.contains(el)) rove(el);
1737
+ });
1738
+
1739
+ tree.addEventListener("keydown", (e) => {
1740
+ const el = e.target.closest(SEL);
1741
+ if (!el || !tree.contains(el)) return;
1742
+ const items = stops();
1743
+ const idx = items.indexOf(el);
1744
+ const branch = el.classList.contains("c-tree__toggle") ? el : null;
1745
+ const move = (next) => {
1746
+ if (!next) return;
1747
+ e.preventDefault();
1748
+ // Own the key: a page-level handler (a tour, a shortcut layer) must
1749
+ // not also act on an arrow the tree already consumed.
1750
+ e.stopPropagation();
1751
+ next.focus();
1752
+ rove(next);
1753
+ };
1754
+ if (e.key === "ArrowDown") move(items[idx + 1]);
1755
+ else if (e.key === "ArrowUp") move(items[idx - 1]);
1756
+ else if (e.key === "Home") move(items[0]);
1757
+ else if (e.key === "End") move(items[items.length - 1]);
1758
+ else if (e.key === "ArrowRight") {
1759
+ // Right opens a closed branch; on an open branch or a leaf it walks
1760
+ // to the next visible item — the pair a tree reader expects.
1761
+ if (branch && branch.getAttribute("aria-expanded") === "false") {
1762
+ e.preventDefault();
1763
+ e.stopPropagation();
1764
+ toggle(branch);
1765
+ rove(branch);
1766
+ } else move(items[idx + 1]);
1767
+ } else if (e.key === "ArrowLeft") {
1768
+ // Left closes an open branch; otherwise it climbs to the parent.
1769
+ if (branch && branch.getAttribute("aria-expanded") === "true") {
1770
+ e.preventDefault();
1771
+ e.stopPropagation();
1772
+ toggle(branch);
1773
+ rove(branch);
1774
+ } else {
1775
+ const parent = el.closest(".c-tree__children");
1776
+ const owner = parent ? parent.closest(".c-tree__node") : null;
1777
+ move(owner ? owner.querySelector(":scope > .c-tree__row > .c-tree__toggle") : null);
1778
+ }
1779
+ } else if ((e.key === "Enter" || e.key === " ") && branch && branch.tagName !== "BUTTON") {
1780
+ // A <button> twisty fires its native click on Enter/Space, which the
1781
+ // row handler above already turns into a toggle — do not double-fire.
1782
+ e.preventDefault();
1783
+ e.stopPropagation();
1784
+ toggle(branch);
1785
+ rove(branch);
1786
+ }
1386
1787
  });
1788
+
1789
+ // The ARIA shape wireTree applies: level is derived from the nesting of
1790
+ // .c-tree__children, so the tree announces its depth, not just its items.
1791
+ $$(".c-tree__node", tree).forEach((node) => {
1792
+ let level = 1;
1793
+ for (let p = node.parentElement; p && p !== tree; p = p.parentElement) {
1794
+ if (p.classList.contains("c-tree__children")) level++;
1795
+ }
1796
+ node.setAttribute("aria-level", String(level));
1797
+ });
1798
+
1799
+ refresh();
1387
1800
  });
1388
1801
 
1389
1802
  /* ---------------------------------------------------------------------
@@ -1658,6 +2071,8 @@
1658
2071
  toast: showToast,
1659
2072
  /** Apply a color scheme ("light" or "dark"). */
1660
2073
  setScheme: applyScheme,
2074
+ /** Alias for setScheme, for consumers that think in themes. */
2075
+ setTheme: applyScheme,
1661
2076
  /** Scroll to an element by id or element reference. */
1662
2077
  scrollTo: (id) => {
1663
2078
  const el = typeof id === "string" ? document.getElementById(id) : id;