dssoca 0.17.0 → 0.20.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 (81) hide show
  1. package/README.md +9 -6
  2. package/dist/chart-nav.d.ts +13 -0
  3. package/dist/chart-nav.js +35 -0
  4. package/dist/components/Accordion.svelte +7 -2
  5. package/dist/components/Badge.svelte +12 -7
  6. package/dist/components/Badge.svelte.d.ts +2 -1
  7. package/dist/components/BottomNav.svelte +4 -0
  8. package/dist/components/BoxPlot.svelte +33 -7
  9. package/dist/components/BumpChart.svelte +68 -26
  10. package/dist/components/Button.svelte +23 -1
  11. package/dist/components/Button.svelte.d.ts +5 -1
  12. package/dist/components/Card.svelte +48 -15
  13. package/dist/components/Card.svelte.d.ts +10 -1
  14. package/dist/components/Chart.svelte +169 -32
  15. package/dist/components/Chart.svelte.d.ts +13 -1
  16. package/dist/components/DateField.svelte +1 -1
  17. package/dist/components/FileDrop.svelte +81 -14
  18. package/dist/components/FileDrop.svelte.d.ts +6 -0
  19. package/dist/components/Heatmap.svelte +128 -50
  20. package/dist/components/Heatmap.svelte.d.ts +2 -1
  21. package/dist/components/Icon.svelte +12 -3
  22. package/dist/components/Icon.svelte.d.ts +4 -0
  23. package/dist/components/Input.svelte +6 -3
  24. package/dist/components/Kbd.svelte +17 -1
  25. package/dist/components/Kbd.svelte.d.ts +9 -0
  26. package/dist/components/Link.svelte +25 -14
  27. package/dist/components/LogStream.svelte +34 -9
  28. package/dist/components/Menu.svelte +12 -8
  29. package/dist/components/Menu.svelte.d.ts +2 -2
  30. package/dist/components/MetricTile.svelte +16 -2
  31. package/dist/components/MetricTile.svelte.d.ts +6 -0
  32. package/dist/components/Modal.svelte +47 -7
  33. package/dist/components/Modal.svelte.d.ts +11 -3
  34. package/dist/components/NumberField.svelte +33 -10
  35. package/dist/components/Pagination.svelte +7 -4
  36. package/dist/components/ScatterPlot.svelte +44 -7
  37. package/dist/components/SearchPalette.svelte +102 -23
  38. package/dist/components/SearchPalette.svelte.d.ts +5 -0
  39. package/dist/components/SegmentedControl.svelte +14 -5
  40. package/dist/components/Select.svelte +3 -4
  41. package/dist/components/ServiceCard.svelte +108 -68
  42. package/dist/components/ServiceCard.svelte.d.ts +8 -3
  43. package/dist/components/ShortcutsHelp.svelte +3 -2
  44. package/dist/components/Sidebar.svelte +84 -59
  45. package/dist/components/Sidebar.svelte.d.ts +5 -0
  46. package/dist/components/Switch.svelte +4 -8
  47. package/dist/components/Table.svelte +20 -13
  48. package/dist/components/Table.svelte.d.ts +6 -2
  49. package/dist/components/Textarea.svelte +1 -1
  50. package/dist/components/TierList.svelte +598 -0
  51. package/dist/components/TierList.svelte.d.ts +37 -0
  52. package/dist/components/Toaster.svelte +144 -21
  53. package/dist/components/Tooltip.svelte +101 -13
  54. package/dist/components/Tooltip.svelte.d.ts +1 -1
  55. package/dist/components/Topbar.svelte +39 -16
  56. package/dist/dssoca.config.d.ts +1 -1
  57. package/dist/dssoca.config.js +1 -0
  58. package/dist/icons.d.ts +20 -2
  59. package/dist/icons.js +43 -3
  60. package/dist/index.d.ts +3 -1
  61. package/dist/index.js +4 -1
  62. package/dist/theme.css +25 -27
  63. package/dist/tierlist-core.d.ts +97 -0
  64. package/dist/tierlist-core.js +206 -0
  65. package/dist/tokens.css +25 -0
  66. package/dist/vanilla/accordion.js +7 -3
  67. package/dist/vanilla/fields.js +19 -6
  68. package/dist/vanilla/index.d.ts +2 -1
  69. package/dist/vanilla/index.js +7 -4
  70. package/dist/vanilla/menu.js +12 -1
  71. package/dist/vanilla/modal.d.ts +4 -0
  72. package/dist/vanilla/modal.js +57 -2
  73. package/dist/vanilla/segmented.js +13 -4
  74. package/dist/vanilla/tierlist.d.ts +8 -0
  75. package/dist/vanilla/tierlist.js +300 -0
  76. package/dist/vanilla/toast.d.ts +11 -3
  77. package/dist/vanilla/toast.js +125 -10
  78. package/dist/vanilla/tooltip.d.ts +5 -1
  79. package/dist/vanilla/tooltip.js +57 -10
  80. package/dist/vanilla.css +581 -158
  81. package/package.json +4 -1
@@ -7,13 +7,21 @@
7
7
  * toasts.dismiss(id) / clear() / update(id, patch) / max
8
8
  *
9
9
  * The stack lives in the first `.ss-toaster` on the page (author it to choose `data-position`
10
- * / size) or in one auto-created under `<body>`. Hover/focus pause the timer, Escape and the
11
- * × button dismiss, exit runs the `.leaving` CSS animation from vanilla.css. Swipe-to-dismiss
12
- * is not ported.
10
+ * / size) or in one auto-created under `<body>`. Hover/focus pause the timer (it resumes only
11
+ * once the pointer has left AND focus is outside the toast), Escape and the × button dismiss,
12
+ * exit runs the `.leaving` CSS animation from vanilla.css. Dismissing the focused toast moves
13
+ * focus to a neighbouring toast, or back to where it came from. Swipe-to-dismiss is not ported.
14
+ *
15
+ * Announcements go through two persistent, visually hidden live regions inside the container
16
+ * (`.live[role=status]` polite, `.live[role=alert]` assertive — the same DOM Toaster.svelte
17
+ * renders; author them in the markup or they are added on DOM ready / first use). Each visible
18
+ * toast mirrors its message into one of them; the toasts themselves carry no live role.
13
19
  */
14
20
  import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, ToastTimer, } from '../toast-core.js';
15
21
  const GLYPH = { success: '✓', error: '✕', info: 'i', loading: '' };
16
22
  const LEAVE_FALLBACK_MS = 400;
23
+ /** Screen readers need a moment to register a fresh live region before it changes. */
24
+ const LIVE_READY_MS = 100;
17
25
  const reduceMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
18
26
  class VanillaToastStore {
19
27
  max = 3;
@@ -21,6 +29,11 @@ class VanillaToastStore {
21
29
  #live = [];
22
30
  #queue = [];
23
31
  #container = null;
32
+ #polite = null;
33
+ #assertive = null;
34
+ /** When the current live regions were created (content inserted earlier may be skipped). */
35
+ #liveSince = 0;
36
+ #returnFocus = null;
24
37
  /** Visible toasts (read-only snapshot). */
25
38
  get items() {
26
39
  return this.#live.map((l) => l.toast);
@@ -32,13 +45,65 @@ class VanillaToastStore {
32
45
  if (!el) {
33
46
  el = document.createElement('div');
34
47
  el.className = 'ss-toaster';
48
+ el.setAttribute('role', 'region');
35
49
  el.setAttribute('aria-label', 'Notifications');
36
50
  el.dataset.position = 'top-right';
37
51
  document.body.appendChild(el);
38
52
  }
39
53
  this.#container = el;
54
+ el.addEventListener('focusin', (e) => {
55
+ const from = e.relatedTarget;
56
+ if (from && !el.contains(from))
57
+ this.#returnFocus = from;
58
+ });
59
+ this.#ensureLive(el);
40
60
  return el;
41
61
  }
62
+ /** Make sure the container holds both persistent live regions (adds any that are missing). */
63
+ #ensureLive(el) {
64
+ const find = (role) => Array.from(el.children).find((c) => c.classList.contains('live') && c.getAttribute('role') === role) ?? null;
65
+ let polite = find('status');
66
+ let assertive = find('alert');
67
+ this.#liveSince = !polite || !assertive ? Date.now() : 0;
68
+ if (!polite) {
69
+ polite = document.createElement('div');
70
+ polite.className = 'live';
71
+ polite.setAttribute('role', 'status');
72
+ polite.setAttribute('aria-live', 'polite');
73
+ el.prepend(polite);
74
+ }
75
+ if (!assertive) {
76
+ assertive = document.createElement('div');
77
+ assertive.className = 'live';
78
+ assertive.setAttribute('role', 'alert');
79
+ assertive.setAttribute('aria-live', 'assertive');
80
+ polite.after(assertive);
81
+ }
82
+ this.#polite = polite;
83
+ this.#assertive = assertive;
84
+ }
85
+ /** Prepare the live regions of an author-placed container ahead of the first toast. */
86
+ prepare() {
87
+ if (document.querySelector('.ss-toaster'))
88
+ void this.container;
89
+ }
90
+ /** Write a toast's message into the live region matching its kind. */
91
+ #announce(live) {
92
+ const region = live.toast.kind === 'error' ? this.#assertive : this.#polite;
93
+ const text = live.toast.message;
94
+ const write = () => {
95
+ if (!this.#live.includes(live))
96
+ return;
97
+ if (live.say.parentElement !== region)
98
+ region.appendChild(live.say);
99
+ live.say.textContent = text;
100
+ };
101
+ const wait = this.#liveSince + LIVE_READY_MS - Date.now();
102
+ if (wait > 0)
103
+ setTimeout(write, wait);
104
+ else
105
+ write();
106
+ }
42
107
  push(kind, message, opts) {
43
108
  const o = normalizeOptions(opts);
44
109
  const id = ++this.#seq;
@@ -53,10 +118,28 @@ class VanillaToastStore {
53
118
  const el = document.createElement('div');
54
119
  el.tabIndex = -1;
55
120
  this.#render(el, t);
56
- el.addEventListener('pointerenter', () => this.pause(t.id));
57
- el.addEventListener('pointerleave', () => this.resume(t.id));
121
+ const live = {
122
+ toast: t,
123
+ el,
124
+ say: document.createElement('p'),
125
+ timer: null,
126
+ hovered: false,
127
+ };
128
+ el.addEventListener('pointerenter', () => {
129
+ live.hovered = true;
130
+ this.pause(t.id);
131
+ });
132
+ el.addEventListener('pointerleave', () => {
133
+ live.hovered = false;
134
+ if (!el.contains(document.activeElement))
135
+ this.resume(t.id);
136
+ });
58
137
  el.addEventListener('focusin', () => this.pause(t.id));
59
- el.addEventListener('focusout', () => this.resume(t.id));
138
+ el.addEventListener('focusout', (e) => {
139
+ if (el.contains(e.relatedTarget) || live.hovered)
140
+ return;
141
+ this.resume(t.id);
142
+ });
60
143
  el.addEventListener('keydown', (e) => {
61
144
  if (e.key === 'Escape') {
62
145
  e.stopPropagation();
@@ -76,14 +159,16 @@ class VanillaToastStore {
76
159
  }
77
160
  });
78
161
  this.container.appendChild(el);
79
- const live = { toast: t, el, timer: null };
80
162
  this.#live.push(live);
163
+ this.#announce(live);
81
164
  this.#arm(live);
82
165
  }
83
166
  #render(el, t) {
84
167
  el.className = `ss-toast ${t.kind}`;
85
- el.setAttribute('role', t.kind === 'error' ? 'alert' : 'status');
86
- el.setAttribute('aria-live', t.kind === 'error' ? 'assertive' : 'polite');
168
+ // A focusable group named by its message (focus can land on the toast itself).
169
+ const msgId = `ss-toast-msg-${t.id}`;
170
+ el.setAttribute('role', 'group');
171
+ el.setAttribute('aria-labelledby', msgId);
87
172
  const ic = t.kind === 'loading'
88
173
  ? `<span class="ic spinner${reduceMotion() ? ' still' : ''}" aria-hidden="true"></span>`
89
174
  : `<span class="ic" aria-hidden="true">${GLYPH[t.kind]}</span>`;
@@ -91,7 +176,7 @@ class VanillaToastStore {
91
176
  ? `<button class="action" type="button">${escapeHtml(t.action.label)}</button>`
92
177
  : '';
93
178
  el.innerHTML =
94
- `${ic}<span class="msg">${escapeHtml(t.message)}</span>${action}` +
179
+ `${ic}<span class="msg" id="${msgId}">${escapeHtml(t.message)}</span>${action}` +
95
180
  `<button class="x" type="button" aria-label="Dismiss">×</button>`;
96
181
  }
97
182
  #find(id) {
@@ -119,7 +204,12 @@ class VanillaToastStore {
119
204
  else if (patch.kind !== undefined)
120
205
  target.timeout = DEFAULT_TIMEOUT[patch.kind];
121
206
  if (live) {
207
+ // Re-rendering replaces the toast's buttons; keep focus inside it.
208
+ const hadFocus = live.el.contains(document.activeElement);
122
209
  this.#render(live.el, live.toast);
210
+ if (hadFocus && !live.el.contains(document.activeElement))
211
+ live.el.focus();
212
+ this.#announce(live);
123
213
  this.#arm(live);
124
214
  }
125
215
  return true;
@@ -133,8 +223,11 @@ class VanillaToastStore {
133
223
  dismiss(id) {
134
224
  const i = this.#live.findIndex((l) => l.toast.id === id);
135
225
  if (i !== -1) {
226
+ if (holdsFocus(this.#live[i]))
227
+ this.#moveFocusFrom(i);
136
228
  const [live] = this.#live.splice(i, 1);
137
229
  live.timer?.cancel();
230
+ live.say.remove();
138
231
  this.#leave(live.el);
139
232
  this.#promote();
140
233
  return;
@@ -143,6 +236,16 @@ class VanillaToastStore {
143
236
  if (qi !== -1)
144
237
  this.#queue.splice(qi, 1);
145
238
  }
239
+ /** Move focus off the toast at `i` (about to be removed): next toast, previous, or origin. */
240
+ #moveFocusFrom(i) {
241
+ const next = this.#live[i + 1] ?? this.#live[i - 1];
242
+ if (next)
243
+ next.el.focus();
244
+ else if (this.#returnFocus?.isConnected) {
245
+ this.#returnFocus.focus();
246
+ this.#returnFocus = null;
247
+ }
248
+ }
146
249
  #leave(el) {
147
250
  if (reduceMotion()) {
148
251
  el.remove();
@@ -166,16 +269,28 @@ class VanillaToastStore {
166
269
  clear() {
167
270
  for (const l of this.#live) {
168
271
  l.timer?.cancel();
272
+ l.say.remove();
169
273
  l.el.remove();
170
274
  }
171
275
  this.#live = [];
172
276
  this.#queue = [];
173
277
  }
174
278
  }
279
+ const holdsFocus = (l) => l.el.contains(document.activeElement);
175
280
  function escapeHtml(s) {
176
281
  return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
177
282
  }
178
283
  export const toasts = new VanillaToastStore();
284
+ // Give an author-placed `.ss-toaster` its live regions as soon as the DOM is ready, so they exist
285
+ // well before the first toast writes into them.
286
+ if (typeof document !== 'undefined') {
287
+ if (document.readyState === 'loading') {
288
+ document.addEventListener('DOMContentLoaded', () => toasts.prepare(), { once: true });
289
+ }
290
+ else {
291
+ toasts.prepare();
292
+ }
293
+ }
179
294
  export const toast = {
180
295
  success: (message, opts) => toasts.push('success', message, opts),
181
296
  error: (message, opts) => toasts.push('error', message, opts),
@@ -1,3 +1,7 @@
1
- export declare function showTooltip(root: HTMLElement): void;
1
+ /**
2
+ * Open `root`'s tip. `from` is the element that triggered it (the focused element on
3
+ * focusin); `aria-describedby` goes on that element when it sits inside `.trigger`.
4
+ */
5
+ export declare function showTooltip(root: HTMLElement, from?: EventTarget | null): void;
2
6
  export declare function hideTooltip(root: HTMLElement): void;
3
7
  export declare function installTooltip(): void;
@@ -2,16 +2,50 @@
2
2
  * Tooltip (DS-0148) — hover/focus reveal over Tooltip.svelte's DOM:
3
3
  * `.ss-tooltip[data-placement] > .trigger + .tip[role=tooltip]`. Basic four-way placement
4
4
  * only: the pre-rendered `data-placement` is honoured as-is (no collision engine). Escape
5
- * hides. While open the wrapper carries `aria-describedby` → the tip (an id is generated when
6
- * the markup has none).
5
+ * hides any open tip wherever focus is (WCAG 1.4.13). While open the focusable trigger inside
6
+ * `.trigger` (not the wrapper) carries `aria-describedby` → the tip (an id is generated when
7
+ * the markup has none); the token is added alongside any description the trigger already has
8
+ * (DS-0163).
7
9
  */
8
- import { on } from './delegate.js';
10
+ import { on, all } from './delegate.js';
9
11
  const ROOT = '.ss-tooltip';
12
+ const FOCUSABLE = 'a[href], button, input, select, textarea, summary, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
10
13
  let seq = 0;
14
+ /** Element currently described by each open tooltip's tip. */
15
+ const described = new WeakMap();
11
16
  function tipOf(root) {
12
17
  return root.querySelector(':scope > .tip');
13
18
  }
14
- export function showTooltip(root) {
19
+ /** The focused trigger element, else the first focusable in `.trigger`, else its first element. */
20
+ function describedTarget(root, from) {
21
+ const trigger = root.querySelector(':scope > .trigger');
22
+ if (!trigger)
23
+ return root;
24
+ if (from instanceof HTMLElement && from !== trigger && trigger.contains(from))
25
+ return from;
26
+ return (trigger.querySelector(FOCUSABLE) ??
27
+ trigger.firstElementChild ??
28
+ trigger);
29
+ }
30
+ function ids(el) {
31
+ return (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
32
+ }
33
+ function undescribe(root, tipId) {
34
+ const el = described.get(root);
35
+ described.delete(root);
36
+ if (!el)
37
+ return;
38
+ const rest = ids(el).filter((id) => id !== tipId);
39
+ if (rest.length)
40
+ el.setAttribute('aria-describedby', rest.join(' '));
41
+ else
42
+ el.removeAttribute('aria-describedby');
43
+ }
44
+ /**
45
+ * Open `root`'s tip. `from` is the element that triggered it (the focused element on
46
+ * focusin); `aria-describedby` goes on that element when it sits inside `.trigger`.
47
+ */
48
+ export function showTooltip(root, from) {
15
49
  const tip = tipOf(root);
16
50
  if (!tip)
17
51
  return;
@@ -19,7 +53,14 @@ export function showTooltip(root) {
19
53
  tip.id = `ss-tip-${++seq}`;
20
54
  tip.hidden = false;
21
55
  tip.classList.add('open');
22
- root.setAttribute('aria-describedby', tip.id);
56
+ const target = describedTarget(root, from);
57
+ if (described.get(root) !== target) {
58
+ undescribe(root, tip.id);
59
+ const cur = ids(target);
60
+ if (!cur.includes(tip.id))
61
+ target.setAttribute('aria-describedby', [...cur, tip.id].join(' '));
62
+ described.set(root, target);
63
+ }
23
64
  }
24
65
  export function hideTooltip(root) {
25
66
  const tip = tipOf(root);
@@ -27,7 +68,7 @@ export function hideTooltip(root) {
27
68
  return;
28
69
  tip.hidden = true;
29
70
  tip.classList.remove('open');
30
- root.removeAttribute('aria-describedby');
71
+ undescribe(root, tip.id);
31
72
  }
32
73
  export function installTooltip() {
33
74
  // mouseenter/leave don't bubble; mouseover/out do — filter by relatedTarget.
@@ -41,14 +82,20 @@ export function installTooltip() {
41
82
  if (!to || !root.contains(to))
42
83
  hideTooltip(root);
43
84
  });
44
- on('focusin', ROOT, (root) => showTooltip(root));
85
+ on('focusin', ROOT, (root, e) => showTooltip(root, e.target));
45
86
  on('focusout', ROOT, (root, e) => {
46
87
  const to = e.relatedTarget;
47
88
  if (!to || !root.contains(to))
48
89
  hideTooltip(root);
49
90
  });
50
- on('keydown', ROOT, (root, e) => {
51
- if (e.key === 'Escape')
52
- hideTooltip(root);
91
+ // Document-level Escape: a tip opened by hover closes even when focus is elsewhere.
92
+ document.addEventListener('keydown', (e) => {
93
+ if (e.key !== 'Escape')
94
+ return;
95
+ for (const tip of all(document, `${ROOT} > .tip.open`)) {
96
+ const root = tip.parentElement;
97
+ if (root)
98
+ hideTooltip(root);
99
+ }
53
100
  });
54
101
  }