@ruckc/truss-chart 1.51.0 → 1.52.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.
@@ -296,9 +296,9 @@
296
296
  <style>
297
297
  .fillwrap { height: 100%; min-height: 0; overflow: hidden; }
298
298
  svg { display: block; overflow: visible; }
299
- .grid { stroke: var(--tr-outline-variant); stroke-opacity: 0.6; }
299
+ .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); }
300
300
  .grid[data-zero='true'] { stroke-opacity: 1; }
301
- .tick { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
301
+ .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
302
302
  .val { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
303
303
  .bar { outline: none; transition: filter var(--tr-dur-fast) var(--tr-ease); }
304
304
  .bar.act { cursor: pointer; }
@@ -15,6 +15,7 @@
15
15
  <script lang="ts">
16
16
  import type { Snippet } from 'svelte';
17
17
  import { cssvars } from './cssvars.js';
18
+ import { scrollFocus } from './scrollfocus.js';
18
19
  import SsrStyle from './SsrStyle.svelte';
19
20
  const uid = $props.id();
20
21
  import type { LegendItem } from './types.js';
@@ -69,12 +70,12 @@
69
70
  {/if}
70
71
 
71
72
  <div class="body" bind:clientWidth={width}>
72
- {#if showTable}<div class="tbl">{@render table()}</div>{:else}{@render plot(width)}{/if}
73
+ {#if showTable}<div class="tbl" {@attach scrollFocus(() => ({ label: labels.table }))}>{@render table()}</div>{:else}{@render plot(width)}{/if}
73
74
  </div>
74
75
  </figure>
75
76
 
76
77
  <style>
77
- .rdc { margin: 0; padding: 12px 12px 8px; background: var(--tr-surface-container-low); border: 1px solid var(--tr-outline-variant); border-radius: var(--tr-radius-md); color: var(--tr-on-surface); font-family: var(--tr-font-sans); }
78
+ .rdc { margin: 0; padding: 12px 12px 8px; background: var(--tr-card-bg, var(--tr-surface-container-low)); border: 1px solid var(--tr-card-border-color, var(--tr-outline-variant)); border-radius: var(--tr-radius-card, var(--tr-radius-md)); box-shadow: var(--tr-card-shadow, none); color: var(--tr-on-surface); font-family: var(--tr-font-sans); }
78
79
  figcaption { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
79
80
  .title { font-weight: 700; }
80
81
  .sub { font-size: var(--tr-text-sm); color: var(--tr-on-surface-variant); }
@@ -84,9 +85,10 @@
84
85
  .legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 6px; padding: 0; list-style: none; }
85
86
  .legend button { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px; border: 0; border-radius: var(--tr-radius-sm); background: none; color: var(--tr-on-surface-variant); font: var(--tr-text-sm) var(--tr-font-sans); cursor: pointer; }
86
87
  .legend button[aria-pressed='false'] { opacity: 0.45; text-decoration: line-through; }
87
- .key { width: 10px; height: 10px; border-radius: 2px; }
88
+ .key { width: 10px; height: 10px; border-radius: var(--tr-chart-key-radius, 2px); }
88
89
  .body { position: relative; }
89
90
  .tbl { max-height: 320px; overflow: auto; }
91
+ .tbl:focus-visible { outline: none; box-shadow: inset var(--tr-focus-ring); }
90
92
  .tbl :global(table) { width: 100%; border-collapse: collapse; font-size: var(--tr-text-sm); font-variant-numeric: tabular-nums; }
91
93
  .tbl :global(th), .tbl :global(td) { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--tr-outline-variant); }
92
94
  .tbl :global(th:first-child), .tbl :global(td:first-child) { text-align: left; }
@@ -249,10 +249,10 @@
249
249
  schedule();
250
250
  return () => { cancelAnimationFrame(raf); raf = 0; };
251
251
  });
252
- // colours come from CSS custom properties, so follow theme switches (explicit data-theme or the OS preference)
252
+ // colours come from CSS custom properties, so follow theme switches (explicit data-theme, a data-truss-theme theme, or the OS preference)
253
253
  $effect(() => {
254
254
  const mo = new MutationObserver(schedule);
255
- mo.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'class'] });
255
+ mo.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-truss-theme', 'class'] });
256
256
  // the default theme follows the OS, which changes without touching any attribute
257
257
  const os = matchMedia('(prefers-color-scheme: dark)');
258
258
  os.addEventListener('change', schedule);
@@ -229,8 +229,8 @@
229
229
  .fillwrap { height: 100%; min-height: 0; overflow: hidden; }
230
230
  svg { display: block; outline: none; overflow: visible; }
231
231
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
232
- .grid { stroke: var(--tr-outline-variant); stroke-opacity: 0.6; }
233
- .tick { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
232
+ .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); }
233
+ .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
234
234
  .bar { transition: opacity var(--tr-dur-fast) var(--tr-ease), filter var(--tr-dur-fast) var(--tr-ease); }
235
235
  .bar[data-hover='true'] { filter: brightness(1.12) saturate(1.1); }
236
236
  .bar[data-dim='true'] { opacity: 0.3; }
@@ -361,8 +361,8 @@
361
361
  svg { display: block; outline: none; overflow: visible; }
362
362
  svg.act { cursor: pointer; }
363
363
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
364
- .grid { stroke: var(--tr-outline-variant); stroke-opacity: 0.6; stroke-width: 1; }
365
- .tick { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
364
+ .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); stroke-width: 1; }
365
+ .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
366
366
  .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
367
367
  .area { fill-opacity: 0.14; }
368
368
  .area.stack { fill-opacity: 0.55; }
@@ -237,8 +237,8 @@
237
237
  svg { display: block; outline: none; overflow: visible; }
238
238
  svg.act { cursor: pointer; }
239
239
  svg:focus-visible { border-radius: var(--tr-radius-sm); box-shadow: var(--tr-focus-ring); }
240
- .grid { stroke: var(--tr-outline-variant); stroke-opacity: 0.6; stroke-width: 1; }
241
- .tick { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
240
+ .grid { stroke: var(--tr-chart-grid-color, var(--tr-outline-variant)); stroke-opacity: var(--tr-chart-grid-opacity, 0.6); stroke-dasharray: var(--tr-chart-grid-dash, none); stroke-width: 1; }
241
+ .tick { fill: var(--tr-chart-tick-color, var(--tr-on-surface-variant)); font-size: var(--tr-text-xs); font-variant-numeric: tabular-nums; }
242
242
  .axis { fill: var(--tr-on-surface-variant); font-size: var(--tr-text-sm); font-weight: 600; }
243
243
  .pt { fill-opacity: 0.85; stroke: var(--tr-surface-container-low); stroke-width: 2; }
244
244
  .pt.on { fill-opacity: 1; }
@@ -102,7 +102,7 @@
102
102
  .tile.sm .value { font-size: var(--trc-stat-value-size, var(--tr-text-xl)); }
103
103
  .label { color: var(--tr-on-surface-variant); font-size: var(--tr-text-sm); font-weight: 600; }
104
104
  .row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
105
- .value { font-size: var(--trc-stat-value-size, 28px); font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
105
+ .value { font-size: var(--trc-stat-value-size, 28px); font-family: var(--tr-font-display, inherit); font-weight: var(--tr-display-weight, 700); font-variation-settings: var(--tr-display-axes, normal); line-height: 1.2; font-variant-numeric: tabular-nums; }
106
106
  .delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--tr-text-sm); font-variant-numeric: tabular-nums; }
107
107
  .delta.good { color: var(--tr-success); }
108
108
  .delta.bad { color: var(--tr-danger); }
@@ -0,0 +1,18 @@
1
+ import type { Attachment } from 'svelte/attachments';
2
+ /**
3
+ * @internal Makes a scroll container reachable by keyboard while (and only while) it scrolls and has nothing of its own to Tab to (axe `scrollable-region-focusable`, #269).
4
+ *
5
+ * A keyboard user can scroll a region only when it, or something inside it, can take focus. So while the content overflows and holds no tabbable control, the element gets
6
+ * `tabindex="0"`, `role="region"` and an accessible name, and a focus ring from its component's CSS (`:focus-visible`). With a tabbable control inside, the control is the tab stop
7
+ * (focusing it scrolls it into view, and axe accepts that), and an extra stop on the container would only make Tab slower. When nothing overflows there is no tab stop at all.
8
+ * Re-measured when the element or its children resize and when its content changes. It writes nothing on the server (attachments run in the browser), so the markup carries no
9
+ * tab stop until it has been measured and there is no hydration mismatch.
10
+ *
11
+ * `get` supplies the name: `labelledby` (an element id, preferred) or `label` (text). Without either, the role is left off (a nameless region is noise) and only the tab stop is added.
12
+ * `role: false` keeps the element's own role (`main`). Attributes the app set itself (`tabindex` other than `-1`, `role`, `aria-label`, `aria-labelledby`) are never overwritten.
13
+ */
14
+ export declare function scrollFocus(get?: () => {
15
+ labelledby?: string;
16
+ label?: string;
17
+ role?: boolean;
18
+ }): Attachment<HTMLElement>;
@@ -0,0 +1,92 @@
1
+ /** Elements a keyboard user can Tab to on their own. A `tabindex="-1"` element is only focusable by script, so it does not count. */
2
+ const TABBABLE = 'a[href],area[href],button,input:not([type="hidden"]),select,textarea,summary,iframe,audio[controls],video[controls],[contenteditable]:not([contenteditable="false"]),[tabindex]';
3
+ function tabbableWithin(el) {
4
+ for (const c of el.querySelectorAll(TABBABLE)) {
5
+ const t = c.getAttribute('tabindex');
6
+ if (t !== null && Number(t) < 0)
7
+ continue;
8
+ if (c.matches(':disabled') || c.closest('[hidden],[inert]') || c.getClientRects().length === 0)
9
+ continue;
10
+ return true;
11
+ }
12
+ return false;
13
+ }
14
+ /** Whether `el` scrolls right now: it clips its overflow (`auto`/`scroll`) and its content is larger than its box. */
15
+ function scrolls(el) {
16
+ const cs = getComputedStyle(el);
17
+ return (/auto|scroll/.test(cs.overflowY) && el.scrollHeight > el.clientHeight + 1) || (/auto|scroll/.test(cs.overflowX) && el.scrollWidth > el.clientWidth + 1);
18
+ }
19
+ /**
20
+ * @internal Makes a scroll container reachable by keyboard while (and only while) it scrolls and has nothing of its own to Tab to (axe `scrollable-region-focusable`, #269).
21
+ *
22
+ * A keyboard user can scroll a region only when it, or something inside it, can take focus. So while the content overflows and holds no tabbable control, the element gets
23
+ * `tabindex="0"`, `role="region"` and an accessible name, and a focus ring from its component's CSS (`:focus-visible`). With a tabbable control inside, the control is the tab stop
24
+ * (focusing it scrolls it into view, and axe accepts that), and an extra stop on the container would only make Tab slower. When nothing overflows there is no tab stop at all.
25
+ * Re-measured when the element or its children resize and when its content changes. It writes nothing on the server (attachments run in the browser), so the markup carries no
26
+ * tab stop until it has been measured and there is no hydration mismatch.
27
+ *
28
+ * `get` supplies the name: `labelledby` (an element id, preferred) or `label` (text). Without either, the role is left off (a nameless region is noise) and only the tab stop is added.
29
+ * `role: false` keeps the element's own role (`main`). Attributes the app set itself (`tabindex` other than `-1`, `role`, `aria-label`, `aria-labelledby`) are never overwritten.
30
+ */
31
+ export function scrollFocus(get) {
32
+ return (el) => {
33
+ let added = [];
34
+ let restore; // a programmatic-only `tabindex="-1"` (Shell's `main`) is replaced while the tab stop is on
35
+ let queued = false;
36
+ const clear = () => {
37
+ for (const a of added)
38
+ el.removeAttribute(a);
39
+ added = [];
40
+ if (restore !== undefined) {
41
+ el.setAttribute('tabindex', restore);
42
+ restore = undefined;
43
+ }
44
+ };
45
+ const set = (name, value) => { if (!el.hasAttribute(name)) {
46
+ el.setAttribute(name, value);
47
+ added.push(name);
48
+ } };
49
+ const measure = () => {
50
+ queued = false;
51
+ const on = scrolls(el) && !tabbableWithin(el);
52
+ if (!on) {
53
+ clear();
54
+ return;
55
+ }
56
+ if (added.length)
57
+ return;
58
+ const { labelledby, label, role = true } = get?.() ?? {};
59
+ const named = !!(labelledby || label) && !el.hasAttribute('aria-label') && !el.hasAttribute('aria-labelledby');
60
+ if (el.getAttribute('tabindex') === '-1') {
61
+ restore = '-1';
62
+ el.removeAttribute('tabindex');
63
+ }
64
+ set('tabindex', '0');
65
+ if (role && (named || el.hasAttribute('aria-label') || el.hasAttribute('aria-labelledby')))
66
+ set('role', 'region');
67
+ if (named) {
68
+ if (labelledby)
69
+ set('aria-labelledby', labelledby);
70
+ else
71
+ set('aria-label', label);
72
+ }
73
+ };
74
+ // coalesce bursts (a virtual list scrolling, many nodes added) into one measurement per microtask
75
+ const schedule = () => { if (!queued) {
76
+ queued = true;
77
+ queueMicrotask(measure);
78
+ } };
79
+ const ro = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);
80
+ const watchKids = () => { if (ro) {
81
+ ro.disconnect();
82
+ ro.observe(el);
83
+ for (const k of el.children)
84
+ ro.observe(k);
85
+ } };
86
+ const mo = new MutationObserver(() => { watchKids(); schedule(); });
87
+ mo.observe(el, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['tabindex', 'disabled', 'hidden', 'inert', 'href'] });
88
+ watchKids();
89
+ measure();
90
+ return () => { ro?.disconnect(); mo.disconnect(); clear(); };
91
+ };
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruckc/truss-chart",
3
- "version": "1.51.0",
3
+ "version": "1.52.0",
4
4
  "description": "Zero-dependency SVG charts for Truss UI",
5
5
  "type": "module",
6
6
  "license": "MIT",