dssoca 0.15.0 → 0.17.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 (44) hide show
  1. package/README.md +19 -0
  2. package/dist/components/Icon.svelte +9 -61
  3. package/dist/components/Icon.svelte.d.ts +4 -47
  4. package/dist/components/LogStream.svelte +2 -2
  5. package/dist/components/MetricTile.svelte +2 -2
  6. package/dist/components/ServiceCard.svelte +2 -2
  7. package/dist/components/Spinner.svelte +7 -34
  8. package/dist/components/Spinner.svelte.d.ts +2 -59
  9. package/dist/components/Tooltip.svelte +151 -15
  10. package/dist/components/Tooltip.svelte.d.ts +11 -1
  11. package/dist/icons.d.ts +54 -0
  12. package/dist/icons.js +56 -0
  13. package/dist/index.d.ts +4 -3
  14. package/dist/index.js +4 -2
  15. package/dist/spinner-frames.d.ts +59 -0
  16. package/dist/spinner-frames.js +15 -0
  17. package/dist/toast-core.d.ts +61 -0
  18. package/dist/toast-core.js +73 -0
  19. package/dist/toast.svelte.d.ts +2 -33
  20. package/dist/toast.svelte.js +3 -66
  21. package/dist/vanilla/accordion.d.ts +2 -0
  22. package/dist/vanilla/accordion.js +57 -0
  23. package/dist/vanilla/delegate.d.ts +16 -0
  24. package/dist/vanilla/delegate.js +33 -0
  25. package/dist/vanilla/fields.d.ts +6 -0
  26. package/dist/vanilla/fields.js +89 -0
  27. package/dist/vanilla/icons.d.ts +17 -0
  28. package/dist/vanilla/icons.js +78 -0
  29. package/dist/vanilla/index.d.ts +16 -0
  30. package/dist/vanilla/index.js +60 -0
  31. package/dist/vanilla/menu.d.ts +3 -0
  32. package/dist/vanilla/menu.js +133 -0
  33. package/dist/vanilla/modal.d.ts +3 -0
  34. package/dist/vanilla/modal.js +42 -0
  35. package/dist/vanilla/segmented.d.ts +2 -0
  36. package/dist/vanilla/segmented.js +62 -0
  37. package/dist/vanilla/switch.d.ts +2 -0
  38. package/dist/vanilla/switch.js +22 -0
  39. package/dist/vanilla/toast.d.ts +37 -0
  40. package/dist/vanilla/toast.js +196 -0
  41. package/dist/vanilla/tooltip.d.ts +3 -0
  42. package/dist/vanilla/tooltip.js +54 -0
  43. package/dist/vanilla.css +4433 -0
  44. package/package.json +14 -5
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Toasts (DS-0148) — framework-free port of `toast.svelte.ts` + Toaster.svelte that renders
3
+ * the exact Toaster DOM directly. Same API names as the Svelte one:
4
+ *
5
+ * toast.success('saved') toast.error('nope', { action: { label, onClick } })
6
+ * toast.loading('…') toast.promise(p, { loading, success, error })
7
+ * toasts.dismiss(id) / clear() / update(id, patch) / max
8
+ *
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.
13
+ */
14
+ import { DEFAULT_TIMEOUT, isSticky, resolveTimeout, normalizeOptions, ToastTimer, } from '../toast-core.js';
15
+ const GLYPH = { success: '✓', error: '✕', info: 'i', loading: '' };
16
+ const LEAVE_FALLBACK_MS = 400;
17
+ const reduceMotion = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
18
+ class VanillaToastStore {
19
+ max = 3;
20
+ #seq = 0;
21
+ #live = [];
22
+ #queue = [];
23
+ #container = null;
24
+ /** Visible toasts (read-only snapshot). */
25
+ get items() {
26
+ return this.#live.map((l) => l.toast);
27
+ }
28
+ get container() {
29
+ if (this.#container?.isConnected)
30
+ return this.#container;
31
+ let el = document.querySelector('.ss-toaster');
32
+ if (!el) {
33
+ el = document.createElement('div');
34
+ el.className = 'ss-toaster';
35
+ el.setAttribute('aria-label', 'Notifications');
36
+ el.dataset.position = 'top-right';
37
+ document.body.appendChild(el);
38
+ }
39
+ this.#container = el;
40
+ return el;
41
+ }
42
+ push(kind, message, opts) {
43
+ const o = normalizeOptions(opts);
44
+ const id = ++this.#seq;
45
+ const t = { id, kind, message, timeout: resolveTimeout(kind, o), action: o?.action };
46
+ if (this.#live.length < this.max)
47
+ this.#show(t);
48
+ else
49
+ this.#queue.push(t);
50
+ return id;
51
+ }
52
+ #show(t) {
53
+ const el = document.createElement('div');
54
+ el.tabIndex = -1;
55
+ this.#render(el, t);
56
+ el.addEventListener('pointerenter', () => this.pause(t.id));
57
+ el.addEventListener('pointerleave', () => this.resume(t.id));
58
+ el.addEventListener('focusin', () => this.pause(t.id));
59
+ el.addEventListener('focusout', () => this.resume(t.id));
60
+ el.addEventListener('keydown', (e) => {
61
+ if (e.key === 'Escape') {
62
+ e.stopPropagation();
63
+ this.dismiss(t.id);
64
+ }
65
+ });
66
+ el.addEventListener('click', (e) => {
67
+ const btn = e.target.closest('button');
68
+ if (!btn)
69
+ return;
70
+ if (btn.classList.contains('x'))
71
+ this.dismiss(t.id);
72
+ else if (btn.classList.contains('action')) {
73
+ const keep = this.#find(t.id)?.toast.action?.onClick() === false;
74
+ if (!keep)
75
+ this.dismiss(t.id);
76
+ }
77
+ });
78
+ this.container.appendChild(el);
79
+ const live = { toast: t, el, timer: null };
80
+ this.#live.push(live);
81
+ this.#arm(live);
82
+ }
83
+ #render(el, t) {
84
+ 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');
87
+ const ic = t.kind === 'loading'
88
+ ? `<span class="ic spinner${reduceMotion() ? ' still' : ''}" aria-hidden="true"></span>`
89
+ : `<span class="ic" aria-hidden="true">${GLYPH[t.kind]}</span>`;
90
+ const action = t.action
91
+ ? `<button class="action" type="button">${escapeHtml(t.action.label)}</button>`
92
+ : '';
93
+ el.innerHTML =
94
+ `${ic}<span class="msg">${escapeHtml(t.message)}</span>${action}` +
95
+ `<button class="x" type="button" aria-label="Dismiss">×</button>`;
96
+ }
97
+ #find(id) {
98
+ return this.#live.find((l) => l.toast.id === id);
99
+ }
100
+ #arm(live) {
101
+ live.timer?.cancel();
102
+ live.timer = isSticky(live.toast.timeout)
103
+ ? null
104
+ : new ToastTimer(live.toast.timeout, () => this.dismiss(live.toast.id));
105
+ }
106
+ update(id, patch) {
107
+ const live = this.#find(id);
108
+ const target = live?.toast ?? this.#queue.find((t) => t.id === id);
109
+ if (!target)
110
+ return false;
111
+ if (patch.kind !== undefined)
112
+ target.kind = patch.kind;
113
+ if (patch.message !== undefined)
114
+ target.message = patch.message;
115
+ if ('action' in patch)
116
+ target.action = patch.action;
117
+ if (patch.timeout !== undefined)
118
+ target.timeout = patch.timeout;
119
+ else if (patch.kind !== undefined)
120
+ target.timeout = DEFAULT_TIMEOUT[patch.kind];
121
+ if (live) {
122
+ this.#render(live.el, live.toast);
123
+ this.#arm(live);
124
+ }
125
+ return true;
126
+ }
127
+ pause(id) {
128
+ this.#find(id)?.timer?.pause();
129
+ }
130
+ resume(id) {
131
+ this.#find(id)?.timer?.resume();
132
+ }
133
+ dismiss(id) {
134
+ const i = this.#live.findIndex((l) => l.toast.id === id);
135
+ if (i !== -1) {
136
+ const [live] = this.#live.splice(i, 1);
137
+ live.timer?.cancel();
138
+ this.#leave(live.el);
139
+ this.#promote();
140
+ return;
141
+ }
142
+ const qi = this.#queue.findIndex((t) => t.id === id);
143
+ if (qi !== -1)
144
+ this.#queue.splice(qi, 1);
145
+ }
146
+ #leave(el) {
147
+ if (reduceMotion()) {
148
+ el.remove();
149
+ return;
150
+ }
151
+ let done = false;
152
+ const finish = () => {
153
+ if (done)
154
+ return;
155
+ done = true;
156
+ el.remove();
157
+ };
158
+ el.classList.add('leaving');
159
+ el.addEventListener('animationend', finish, { once: true });
160
+ setTimeout(finish, LEAVE_FALLBACK_MS);
161
+ }
162
+ #promote() {
163
+ while (this.#live.length < this.max && this.#queue.length > 0)
164
+ this.#show(this.#queue.shift());
165
+ }
166
+ clear() {
167
+ for (const l of this.#live) {
168
+ l.timer?.cancel();
169
+ l.el.remove();
170
+ }
171
+ this.#live = [];
172
+ this.#queue = [];
173
+ }
174
+ }
175
+ function escapeHtml(s) {
176
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
177
+ }
178
+ export const toasts = new VanillaToastStore();
179
+ export const toast = {
180
+ success: (message, opts) => toasts.push('success', message, opts),
181
+ error: (message, opts) => toasts.push('error', message, opts),
182
+ info: (message, opts) => toasts.push('info', message, opts),
183
+ loading: (message, opts) => toasts.push('loading', message, opts),
184
+ /** Push a sticky `loading` toast, then flip it to success/error when the promise settles. */
185
+ promise(p, messages) {
186
+ const id = toasts.push('loading', messages.loading, { timeout: 0 });
187
+ p.then((value) => {
188
+ const msg = typeof messages.success === 'function' ? messages.success(value) : messages.success;
189
+ toasts.update(id, { kind: 'success', message: msg });
190
+ }, (err) => {
191
+ const msg = typeof messages.error === 'function' ? messages.error(err) : messages.error;
192
+ toasts.update(id, { kind: 'error', message: msg });
193
+ });
194
+ return p;
195
+ },
196
+ };
@@ -0,0 +1,3 @@
1
+ export declare function showTooltip(root: HTMLElement): void;
2
+ export declare function hideTooltip(root: HTMLElement): void;
3
+ export declare function installTooltip(): void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Tooltip (DS-0148) — hover/focus reveal over Tooltip.svelte's DOM:
3
+ * `.ss-tooltip[data-placement] > .trigger + .tip[role=tooltip]`. Basic four-way placement
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).
7
+ */
8
+ import { on } from './delegate.js';
9
+ const ROOT = '.ss-tooltip';
10
+ let seq = 0;
11
+ function tipOf(root) {
12
+ return root.querySelector(':scope > .tip');
13
+ }
14
+ export function showTooltip(root) {
15
+ const tip = tipOf(root);
16
+ if (!tip)
17
+ return;
18
+ if (!tip.id)
19
+ tip.id = `ss-tip-${++seq}`;
20
+ tip.hidden = false;
21
+ tip.classList.add('open');
22
+ root.setAttribute('aria-describedby', tip.id);
23
+ }
24
+ export function hideTooltip(root) {
25
+ const tip = tipOf(root);
26
+ if (!tip)
27
+ return;
28
+ tip.hidden = true;
29
+ tip.classList.remove('open');
30
+ root.removeAttribute('aria-describedby');
31
+ }
32
+ export function installTooltip() {
33
+ // mouseenter/leave don't bubble; mouseover/out do — filter by relatedTarget.
34
+ on('mouseover', ROOT, (root, e) => {
35
+ const from = e.relatedTarget;
36
+ if (!from || !root.contains(from))
37
+ showTooltip(root);
38
+ });
39
+ on('mouseout', ROOT, (root, e) => {
40
+ const to = e.relatedTarget;
41
+ if (!to || !root.contains(to))
42
+ hideTooltip(root);
43
+ });
44
+ on('focusin', ROOT, (root) => showTooltip(root));
45
+ on('focusout', ROOT, (root, e) => {
46
+ const to = e.relatedTarget;
47
+ if (!to || !root.contains(to))
48
+ hideTooltip(root);
49
+ });
50
+ on('keydown', ROOT, (root, e) => {
51
+ if (e.key === 'Escape')
52
+ hideTooltip(root);
53
+ });
54
+ }