dssoca 0.5.0 → 0.8.2

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 (46) hide show
  1. package/dist/components/Accordion.svelte +281 -0
  2. package/dist/components/Accordion.svelte.d.ts +47 -0
  3. package/dist/components/Badge.svelte +115 -18
  4. package/dist/components/Badge.svelte.d.ts +28 -2
  5. package/dist/components/BottomNav.svelte +216 -0
  6. package/dist/components/BottomNav.svelte.d.ts +30 -0
  7. package/dist/components/Button.svelte +147 -10
  8. package/dist/components/Button.svelte.d.ts +21 -4
  9. package/dist/components/Card.svelte +167 -8
  10. package/dist/components/Card.svelte.d.ts +16 -1
  11. package/dist/components/EmptyState.svelte +85 -9
  12. package/dist/components/EmptyState.svelte.d.ts +14 -3
  13. package/dist/components/Icon.svelte +179 -13
  14. package/dist/components/Icon.svelte.d.ts +63 -2
  15. package/dist/components/Image.svelte +430 -0
  16. package/dist/components/Image.svelte.d.ts +49 -0
  17. package/dist/components/Input.svelte +174 -39
  18. package/dist/components/Input.svelte.d.ts +22 -0
  19. package/dist/components/Link.svelte +148 -0
  20. package/dist/components/Link.svelte.d.ts +22 -0
  21. package/dist/components/LogStream.svelte +378 -37
  22. package/dist/components/LogStream.svelte.d.ts +35 -7
  23. package/dist/components/Menu.svelte +355 -0
  24. package/dist/components/Menu.svelte.d.ts +46 -0
  25. package/dist/components/MetricTile.svelte +124 -12
  26. package/dist/components/MetricTile.svelte.d.ts +20 -0
  27. package/dist/components/SegmentedControl.svelte +208 -0
  28. package/dist/components/SegmentedControl.svelte.d.ts +30 -0
  29. package/dist/components/ServiceCard.svelte +222 -26
  30. package/dist/components/ServiceCard.svelte.d.ts +13 -1
  31. package/dist/components/Sidebar.svelte +340 -29
  32. package/dist/components/Sidebar.svelte.d.ts +18 -7
  33. package/dist/components/Sparkline.svelte +196 -13
  34. package/dist/components/Sparkline.svelte.d.ts +20 -1
  35. package/dist/components/Toaster.svelte +193 -12
  36. package/dist/components/Toaster.svelte.d.ts +3 -0
  37. package/dist/components/Topbar.svelte +152 -21
  38. package/dist/components/Topbar.svelte.d.ts +20 -0
  39. package/dist/dssoca.config.d.ts +1 -1
  40. package/dist/dssoca.config.js +6 -0
  41. package/dist/index.d.ts +10 -3
  42. package/dist/index.js +12 -2
  43. package/dist/theme.css +242 -0
  44. package/dist/toast.svelte.d.ts +49 -5
  45. package/dist/toast.svelte.js +165 -9
  46. package/package.json +1 -1
package/dist/theme.css CHANGED
@@ -18,6 +18,7 @@
18
18
  /* surfaces */
19
19
  --ss-bg: #100f10;
20
20
  --ss-bg-elev: #1e1e1e;
21
+ --ss-bg-elev-hover: #262626; /* slightly raised surface for hovered cards/rows */
21
22
  --ss-bg-inset: rgba(7, 6, 7, 0);
22
23
  --ss-line: rgba(255, 255, 255, 0.12);
23
24
  --ss-line-strong: rgba(255, 255, 255, 0.22);
@@ -42,6 +43,19 @@
42
43
  --ss-blue: #9aa4ff;
43
44
  --ss-cyan: #66d9ef;
44
45
  --ss-purple: #b98cff;
46
+ --ss-red-rgb: 255, 92, 92; /* soft invalid focus ring (DS-0033) */
47
+ /* destructive + sentiment — danger/success alias the status red / brand green;
48
+ hover deepens danger, -soft washes back the opt-in emphasis chip, on-danger is
49
+ the readable label on the bright red. Used by Button (DS-0032), Sparkline trend
50
+ (DS-0035) and MetricTile sentiment (DS-0037). */
51
+ --ss-danger: var(--ss-red);
52
+ --ss-danger-hover: #ff7a7a;
53
+ --ss-danger-soft: rgba(255, 92, 92, 0.18);
54
+ --ss-fg-on-danger: #100f10;
55
+ --ss-success: var(--ss-primary);
56
+ --ss-success-soft: var(--ss-primary-soft);
57
+ /* skeleton — neutral wash for loading bars (DS-0037) */
58
+ --ss-skeleton: rgba(255, 255, 255, 0.10);
45
59
  /* code */
46
60
  --ss-code-bg: #011627;
47
61
  --ss-code-fg: #d6deeb;
@@ -50,8 +64,28 @@
50
64
  --ss-code-keyword: #c792ea;
51
65
  --ss-code-func: #82aaff;
52
66
  --ss-code-comment: #637777;
67
+ /* log-level accents — theme-correct on the code surface */
68
+ --ss-log-info: var(--ss-code-func);
69
+ --ss-log-warn: var(--ss-yellow);
70
+ --ss-log-err: var(--ss-red);
71
+ --ss-log-ok: var(--ss-code-string);
53
72
  --ss-selection-bg: var(--ss-primary);
54
73
  --ss-selection-fg: var(--ss-fg-on-primary);
74
+ /* badge tones — theme-tracked fills/borders so light mode is correct
75
+ (DS-0031). fg uses the matching status token; bg/border are translucent
76
+ washes tuned for the dark surfaces. */
77
+ --ss-badge-up-bg: rgba(102, 239, 115, 0.12);
78
+ --ss-badge-up-border: rgba(102, 239, 115, 0.40);
79
+ --ss-badge-deg-bg: rgba(224, 195, 106, 0.12);
80
+ --ss-badge-deg-border: rgba(224, 195, 106, 0.40);
81
+ --ss-badge-down-bg: rgba(255, 92, 92, 0.12);
82
+ --ss-badge-down-border: rgba(255, 92, 92, 0.40);
83
+ --ss-badge-maint-bg: rgba(154, 164, 255, 0.12);
84
+ --ss-badge-maint-border: rgba(154, 164, 255, 0.40);
85
+ --ss-badge-info-bg: rgba(102, 217, 239, 0.12);
86
+ --ss-badge-info-border: rgba(102, 217, 239, 0.40);
87
+ --ss-badge-neutral-bg: rgba(255, 255, 255, 0.06);
88
+ --ss-badge-neutral-border: var(--ss-line);
55
89
  }
56
90
 
57
91
  [data-theme=light] {
@@ -59,6 +93,7 @@
59
93
  Not blinding-bright; lines are stronger so square borders stay legible. */
60
94
  --ss-bg: #f0f0f0;
61
95
  --ss-bg-elev: #ffffff;
96
+ --ss-bg-elev-hover: #f4f4f4; /* slightly raised surface for hovered cards/rows */
62
97
  --ss-bg-inset: rgba(0, 0, 0, 0);
63
98
  --ss-line: rgba(0, 0, 0, 0.16);
64
99
  --ss-line-strong: rgba(0, 0, 0, 0.30);
@@ -85,6 +120,17 @@
85
120
  --ss-blue: #2f3bd6;
86
121
  --ss-cyan: #0b6e7d;
87
122
  --ss-purple: #6a35c9;
123
+ --ss-red-rgb: 198, 40, 40; /* soft invalid focus ring (DS-0033) */
124
+ /* destructive + sentiment — the deep light-mode red carries a white label at AA;
125
+ success/-soft track the light brand green (DS-0032/0035/0037) */
126
+ --ss-danger: var(--ss-red);
127
+ --ss-danger-hover: #a91f1f;
128
+ --ss-danger-soft: rgba(198, 40, 40, 0.12);
129
+ --ss-fg-on-danger: #ffffff;
130
+ --ss-success: var(--ss-primary);
131
+ --ss-success-soft: var(--ss-primary-soft);
132
+ /* skeleton — neutral wash for loading bars (DS-0037) */
133
+ --ss-skeleton: rgba(0, 0, 0, 0.10);
88
134
  /* code — a light syntax palette (the dark Night-Owl set is unreadable here) */
89
135
  --ss-code-bg: #f5f5f5;
90
136
  --ss-code-fg: #24292e;
@@ -93,6 +139,26 @@
93
139
  --ss-code-keyword: #c5221f;
94
140
  --ss-code-func: #6639ba;
95
141
  --ss-code-comment: #6a737d;
142
+ /* badge tones — deeper washes/borders so the fills read on the light page
143
+ (the dark-mode neon washes wash out on #f0f0f0). fg tracks the darkened
144
+ light-mode status tokens already defined above. */
145
+ --ss-badge-up-bg: rgba(21, 127, 59, 0.10);
146
+ --ss-badge-up-border: rgba(21, 127, 59, 0.35);
147
+ --ss-badge-deg-bg: rgba(138, 109, 26, 0.10);
148
+ --ss-badge-deg-border: rgba(138, 109, 26, 0.35);
149
+ --ss-badge-down-bg: rgba(198, 40, 40, 0.10);
150
+ --ss-badge-down-border: rgba(198, 40, 40, 0.35);
151
+ --ss-badge-maint-bg: rgba(47, 59, 214, 0.10);
152
+ --ss-badge-maint-border: rgba(47, 59, 214, 0.35);
153
+ --ss-badge-info-bg: rgba(11, 110, 125, 0.10);
154
+ --ss-badge-info-border: rgba(11, 110, 125, 0.35);
155
+ --ss-badge-neutral-bg: rgba(0, 0, 0, 0.05);
156
+ --ss-badge-neutral-border: var(--ss-line);
157
+ /* log-level accents — darkened code/status values for AA on the light code surface */
158
+ --ss-log-info: var(--ss-code-func);
159
+ --ss-log-warn: var(--ss-yellow);
160
+ --ss-log-err: var(--ss-red);
161
+ --ss-log-ok: var(--ss-code-string);
96
162
  }
97
163
 
98
164
  :root {
@@ -135,6 +201,8 @@
135
201
  --ss-dur: 250ms;
136
202
  --ss-dur-slow: 350ms;
137
203
  --ss-dur-xslow: 650ms;
204
+ /* Icon spin (loader) — one full 360° turn; disabled under reduced motion. */
205
+ --ss-icon-spin-dur: 900ms;
138
206
  }
139
207
 
140
208
  :root,
@@ -162,6 +230,8 @@
162
230
  --ss-row-px: 14px;
163
231
  --ss-badge-py: 5px;
164
232
  --ss-badge-px: 12px;
233
+ --ss-badge-dot: 5px;
234
+ --ss-badge-gap: 6px;
165
235
  --ss-gap: 14px;
166
236
  --ss-gap-sm: 10px;
167
237
  --ss-block-gap: 28px;
@@ -169,6 +239,22 @@
169
239
  --ss-shell-top-h: 48px;
170
240
  --ss-main-py: 28px;
171
241
  --ss-main-px: 36px;
242
+ /* Sidebar component — expanded/rail widths + per-item badge padding (DS-0039) */
243
+ --ss-side-w: 220px;
244
+ --ss-side-w-rail: 56px;
245
+ --ss-side-badge-py: 2px;
246
+ --ss-side-badge-px: 6px;
247
+ /* toast (DS-0041) — icon box + swipe-dismiss threshold */
248
+ --ss-toast-ic: 18px;
249
+ --ss-toast-swipe: 72px;
250
+ /* empty-state visual + width (rescales with the size axis) */
251
+ --ss-empty-glyph: 40px;
252
+ --ss-empty-glyph-compact: 28px;
253
+ --ss-empty-max-w: 420px;
254
+ /* sparkline (DS-0035) */
255
+ --ss-spark-h: 18px;
256
+ --ss-spark-bar-w: 3px;
257
+ --ss-spark-gap: 1px;
172
258
  }
173
259
 
174
260
  [data-size-variant=sm] {
@@ -195,6 +281,8 @@
195
281
  --ss-row-px: 10px;
196
282
  --ss-badge-py: 3px;
197
283
  --ss-badge-px: 8px;
284
+ --ss-badge-dot: 4px;
285
+ --ss-badge-gap: 5px;
198
286
  --ss-gap: 8px;
199
287
  --ss-gap-sm: 6px;
200
288
  --ss-block-gap: 16px;
@@ -202,6 +290,22 @@
202
290
  --ss-shell-top-h: 36px;
203
291
  --ss-main-py: 16px;
204
292
  --ss-main-px: 20px;
293
+ /* Sidebar component (DS-0039) */
294
+ --ss-side-w: 180px;
295
+ --ss-side-w-rail: 44px;
296
+ --ss-side-badge-py: 1px;
297
+ --ss-side-badge-px: 5px;
298
+ /* toast (DS-0041) */
299
+ --ss-toast-ic: 15px;
300
+ --ss-toast-swipe: 60px;
301
+ /* empty-state visual + width */
302
+ --ss-empty-glyph: 32px;
303
+ --ss-empty-glyph-compact: 22px;
304
+ --ss-empty-max-w: 360px;
305
+ /* sparkline (DS-0035) */
306
+ --ss-spark-h: 14px;
307
+ --ss-spark-bar-w: 2px;
308
+ --ss-spark-gap: 1px;
205
309
  }
206
310
 
207
311
  [data-size-variant=lg] {
@@ -228,6 +332,8 @@
228
332
  --ss-row-px: 18px;
229
333
  --ss-badge-py: 7px;
230
334
  --ss-badge-px: 16px;
335
+ --ss-badge-dot: 6px;
336
+ --ss-badge-gap: 7px;
231
337
  --ss-gap: 18px;
232
338
  --ss-gap-sm: 13px;
233
339
  --ss-block-gap: 36px;
@@ -235,6 +341,22 @@
235
341
  --ss-shell-top-h: 56px;
236
342
  --ss-main-py: 36px;
237
343
  --ss-main-px: 48px;
344
+ /* Sidebar component (DS-0039) */
345
+ --ss-side-w: 260px;
346
+ --ss-side-w-rail: 64px;
347
+ --ss-side-badge-py: 3px;
348
+ --ss-side-badge-px: 8px;
349
+ /* toast (DS-0041) */
350
+ --ss-toast-ic: 22px;
351
+ --ss-toast-swipe: 88px;
352
+ /* empty-state visual + width */
353
+ --ss-empty-glyph: 52px;
354
+ --ss-empty-glyph-compact: 36px;
355
+ --ss-empty-max-w: 480px;
356
+ /* sparkline (DS-0035) */
357
+ --ss-spark-h: 26px;
358
+ --ss-spark-bar-w: 4px;
359
+ --ss-spark-gap: 2px;
238
360
  }
239
361
 
240
362
  @media (prefers-reduced-motion: reduce) {
@@ -245,6 +367,126 @@
245
367
  --ss-dur-xslow: 0ms;
246
368
  }
247
369
  }
370
+ :root {
371
+ --ss-menu-pad: 4px;
372
+ --ss-menu-item-py: 8px;
373
+ --ss-menu-item-px: 12px;
374
+ --ss-menu-item-gap: 10px;
375
+ --ss-menu-min-w: 180px;
376
+ --ss-menu-offset: 6px;
377
+ }
378
+
379
+ [data-size-variant=sm] {
380
+ --ss-menu-pad: 3px;
381
+ --ss-menu-item-py: 5px;
382
+ --ss-menu-item-px: 9px;
383
+ --ss-menu-item-gap: 8px;
384
+ --ss-menu-min-w: 150px;
385
+ --ss-menu-offset: 5px;
386
+ }
387
+
388
+ [data-size-variant=lg] {
389
+ --ss-menu-pad: 6px;
390
+ --ss-menu-item-py: 11px;
391
+ --ss-menu-item-px: 16px;
392
+ --ss-menu-item-gap: 12px;
393
+ --ss-menu-min-w: 220px;
394
+ --ss-menu-offset: 8px;
395
+ }
396
+
397
+ [data-size-variant=md],
398
+ :root {
399
+ --ss-acc-head-py: var(--ss-row-py);
400
+ --ss-acc-head-px: var(--ss-row-px);
401
+ --ss-acc-body-py: var(--ss-s-3);
402
+ --ss-acc-body-px: var(--ss-row-px);
403
+ --ss-acc-chevron: 9px;
404
+ --ss-acc-gap: var(--ss-s-3);
405
+ }
406
+
407
+ [data-size-variant=sm] {
408
+ --ss-acc-head-py: var(--ss-s-1);
409
+ --ss-acc-head-px: var(--ss-s-2);
410
+ --ss-acc-body-py: var(--ss-s-2);
411
+ --ss-acc-body-px: var(--ss-s-2);
412
+ --ss-acc-chevron: 7px;
413
+ --ss-acc-gap: var(--ss-s-2);
414
+ }
415
+
416
+ [data-size-variant=lg] {
417
+ --ss-acc-head-py: var(--ss-s-3);
418
+ --ss-acc-head-px: var(--ss-s-4);
419
+ --ss-acc-body-py: var(--ss-s-4);
420
+ --ss-acc-body-px: var(--ss-s-4);
421
+ --ss-acc-chevron: 11px;
422
+ --ss-acc-gap: var(--ss-s-4);
423
+ }
424
+
425
+ :root,
426
+ [data-size-variant=md] {
427
+ --ss-seg-font: var(--ss-ui-md);
428
+ --ss-seg-py: 7px;
429
+ --ss-seg-px: 14px;
430
+ --ss-seg-gap: var(--ss-gap-sm);
431
+ }
432
+
433
+ [data-size-variant=sm] {
434
+ --ss-seg-font: var(--ss-ui-sm);
435
+ --ss-seg-py: 4px;
436
+ --ss-seg-px: 9px;
437
+ --ss-seg-gap: 6px;
438
+ }
439
+
440
+ [data-size-variant=lg] {
441
+ --ss-seg-font: var(--ss-ui-lg);
442
+ --ss-seg-py: 10px;
443
+ --ss-seg-px: 20px;
444
+ --ss-seg-gap: 12px;
445
+ }
446
+
447
+ :root {
448
+ --ss-bottom-nav-h: var(--ss-shell-top-h, 48px);
449
+ --ss-bottom-nav-px: var(--ss-s-2, 8px);
450
+ --ss-bottom-nav-tab-py: var(--ss-s-1, 4px);
451
+ --ss-bottom-nav-gap: 4px;
452
+ --ss-bottom-nav-label-fs: var(--ss-ui-xs, 11px);
453
+ }
454
+
455
+ :root {
456
+ --ss-image-frame-bg: var(--ss-bg-elev);
457
+ --ss-image-shimmer: rgba(255, 255, 255, 0.06);
458
+ --ss-image-shimmer-dur: var(--ss-dur-xslow);
459
+ --ss-image-focus-w: 2px;
460
+ --ss-image-caption-gap: var(--ss-s-2);
461
+ --ss-image-backdrop: rgba(0, 0, 0, 0.82);
462
+ --ss-image-lightbox-z: 1000;
463
+ --ss-image-lightbox-pad: var(--ss-s-8);
464
+ }
465
+
466
+ [data-theme=light] {
467
+ --ss-image-shimmer: rgba(255, 255, 255, 0.5);
468
+ --ss-image-backdrop: rgba(0, 0, 0, 0.66);
469
+ }
470
+
471
+ [data-size-variant=md],
472
+ :root {
473
+ --ss-image-glyph: 28px;
474
+ --ss-image-fallback-min: 120px;
475
+ --ss-image-close: 36px;
476
+ }
477
+
478
+ [data-size-variant=sm] {
479
+ --ss-image-glyph: 22px;
480
+ --ss-image-fallback-min: 96px;
481
+ --ss-image-close: 30px;
482
+ }
483
+
484
+ [data-size-variant=lg] {
485
+ --ss-image-glyph: 36px;
486
+ --ss-image-fallback-min: 160px;
487
+ --ss-image-close: 44px;
488
+ }
489
+
248
490
  html {
249
491
  font-family: var(--ss-font-body);
250
492
  font-size: clamp(16px, 1vw + 12px, 20px);
@@ -1,25 +1,69 @@
1
- export type ToastKind = 'success' | 'error' | 'info';
1
+ export type ToastKind = 'success' | 'error' | 'info' | 'loading';
2
+ /** An optional inline action rendered as a button inside the toast. */
3
+ export interface ToastAction {
4
+ label: string;
5
+ /**
6
+ * Invoked on click. Return `false` to keep the toast open (e.g. an async
7
+ * action that wants to swap itself for a result toast); any other return
8
+ * value dismisses the toast.
9
+ */
10
+ onClick: () => void | false;
11
+ }
2
12
  export interface Toast {
3
13
  id: number;
4
14
  kind: ToastKind;
5
15
  message: string;
16
+ /** Effective auto-dismiss duration in ms; <= 0 / Infinity means sticky. */
17
+ timeout: number;
18
+ action?: ToastAction;
19
+ }
20
+ /** Fields a caller may set when pushing; the store fills in the rest. */
21
+ export interface ToastOptions {
22
+ timeout?: number;
23
+ action?: ToastAction;
6
24
  }
25
+ /** A subset of a toast a caller may patch in-place via `update`. */
26
+ export type ToastPatch = Partial<Pick<Toast, 'kind' | 'message' | 'timeout' | 'action'>>;
7
27
  /**
8
28
  * Module-singleton toast store (Svelte 5 runes). One instance is shared by
9
29
  * every consumer of the package, so `toast.success(...)` from anywhere shows
10
30
  * in the single <Toaster /> mounted at the app root.
31
+ *
32
+ * Visible toasts are capped at `max`; overflow waits in a private queue and is
33
+ * promoted (FIFO) whenever a visible slot frees up on dismiss.
11
34
  */
12
35
  declare class ToastStore {
13
36
  #private;
37
+ /** The currently VISIBLE toasts (capped at `max`). */
14
38
  items: Toast[];
15
- push(kind: ToastKind, message: string, timeout?: number): number;
39
+ /** Visible-stack cap; extra pushes queue until a slot frees. */
40
+ max: number;
41
+ push(kind: ToastKind, message: string, opts?: ToastOptions | number): number;
42
+ /** Patch a live (or queued) toast in place; re-arms its timer. Returns success. */
43
+ update(id: number, patch: ToastPatch): boolean;
44
+ /** Pause a visible toast's auto-dismiss timer (hover/focus). */
45
+ pause(id: number): void;
46
+ /** Resume a paused timer (pointer/focus leave). */
47
+ resume(id: number): void;
16
48
  dismiss(id: number): void;
17
49
  clear(): void;
18
50
  }
19
51
  export declare const toasts: ToastStore;
52
+ /** Options for `toast.promise`. */
53
+ export interface PromiseMessages<T> {
54
+ loading: string;
55
+ success: string | ((value: T) => string);
56
+ error: string | ((err: unknown) => string);
57
+ }
20
58
  export declare const toast: {
21
- success: (message: string, timeout?: number) => number;
22
- error: (message: string, timeout?: number) => number;
23
- info: (message: string, timeout?: number) => number;
59
+ success: (message: string, opts?: ToastOptions | number) => number;
60
+ error: (message: string, opts?: ToastOptions | number) => number;
61
+ info: (message: string, opts?: ToastOptions | number) => number;
62
+ loading: (message: string, opts?: ToastOptions | number) => number;
63
+ /**
64
+ * Push a sticky `loading` toast, then update it to success/error when the
65
+ * promise settles. Returns the same promise so callers can keep chaining.
66
+ */
67
+ promise<T>(p: Promise<T>, messages: PromiseMessages<T>): Promise<T>;
24
68
  };
25
69
  export {};
@@ -1,32 +1,188 @@
1
- const DEFAULT_TIMEOUT = 4000;
1
+ /** Default auto-dismiss per kind. Errors linger; loading is sticky. */
2
+ const DEFAULT_TIMEOUT = {
3
+ success: 4000,
4
+ info: 4000,
5
+ error: 7000,
6
+ loading: 0 // sticky until updated/dismissed
7
+ };
8
+ /** Toasts carrying an action default to sticky so the action stays reachable. */
9
+ const ACTION_TIMEOUT = 0;
10
+ /** Treat <= 0 or non-finite as sticky (never auto-dismiss). */
11
+ function isSticky(timeout) {
12
+ return !(timeout > 0) || !Number.isFinite(timeout);
13
+ }
14
+ const hasWindow = typeof window !== 'undefined';
15
+ /**
16
+ * Per-toast auto-dismiss controller. Tracks remaining time so the timer can be
17
+ * paused (on hover/focus) and resumed without losing or resetting the budget.
18
+ */
19
+ class ToastTimer {
20
+ #fire;
21
+ #remaining;
22
+ #startedAt = 0;
23
+ #handle = null;
24
+ constructor(timeout, fire) {
25
+ this.#fire = fire;
26
+ this.#remaining = timeout;
27
+ this.resume();
28
+ }
29
+ get sticky() {
30
+ return isSticky(this.#remaining);
31
+ }
32
+ resume() {
33
+ if (this.#handle !== null || this.sticky || !hasWindow)
34
+ return;
35
+ this.#startedAt = Date.now();
36
+ this.#handle = setTimeout(this.#fire, this.#remaining);
37
+ }
38
+ pause() {
39
+ if (this.#handle === null)
40
+ return;
41
+ clearTimeout(this.#handle);
42
+ this.#handle = null;
43
+ this.#remaining -= Date.now() - this.#startedAt;
44
+ }
45
+ /** Re-arm with a fresh budget (used by `update`). */
46
+ reset(timeout) {
47
+ this.cancel();
48
+ this.#remaining = timeout;
49
+ this.resume();
50
+ }
51
+ cancel() {
52
+ if (this.#handle !== null)
53
+ clearTimeout(this.#handle);
54
+ this.#handle = null;
55
+ }
56
+ }
2
57
  /**
3
58
  * Module-singleton toast store (Svelte 5 runes). One instance is shared by
4
59
  * every consumer of the package, so `toast.success(...)` from anywhere shows
5
60
  * in the single <Toaster /> mounted at the app root.
61
+ *
62
+ * Visible toasts are capped at `max`; overflow waits in a private queue and is
63
+ * promoted (FIFO) whenever a visible slot frees up on dismiss.
6
64
  */
7
65
  class ToastStore {
66
+ /** The currently VISIBLE toasts (capped at `max`). */
8
67
  items = $state([]);
68
+ /** Visible-stack cap; extra pushes queue until a slot frees. */
69
+ max = $state(3);
9
70
  #seq = 0;
10
- push(kind, message, timeout = DEFAULT_TIMEOUT) {
71
+ #queue = [];
72
+ #timers = new Map();
73
+ #resolveTimeout(kind, opts) {
74
+ if (opts?.timeout !== undefined)
75
+ return opts.timeout;
76
+ if (opts?.action)
77
+ return ACTION_TIMEOUT;
78
+ return DEFAULT_TIMEOUT[kind];
79
+ }
80
+ push(kind, message, opts) {
81
+ // Back-compat: the old signature accepted a bare `timeout` number.
82
+ const o = typeof opts === 'number' ? { timeout: opts } : opts;
11
83
  const id = ++this.#seq;
12
- this.items.push({ id, kind, message });
13
- if (timeout > 0 && typeof window !== 'undefined') {
14
- setTimeout(() => this.dismiss(id), timeout);
84
+ const toast = {
85
+ id,
86
+ kind,
87
+ message,
88
+ timeout: this.#resolveTimeout(kind, o),
89
+ action: o?.action
90
+ };
91
+ if (this.items.length < this.max) {
92
+ this.#show(toast);
93
+ }
94
+ else {
95
+ this.#queue.push(toast);
15
96
  }
16
97
  return id;
17
98
  }
99
+ #show(toast) {
100
+ this.items.push(toast);
101
+ this.#arm(toast);
102
+ }
103
+ #arm(toast) {
104
+ this.#timers.get(toast.id)?.cancel();
105
+ if (isSticky(toast.timeout)) {
106
+ this.#timers.delete(toast.id);
107
+ return;
108
+ }
109
+ this.#timers.set(toast.id, new ToastTimer(toast.timeout, () => this.dismiss(toast.id)));
110
+ }
111
+ /** Patch a live (or queued) toast in place; re-arms its timer. Returns success. */
112
+ update(id, patch) {
113
+ const live = this.items.find((t) => t.id === id);
114
+ const target = live ?? this.#queue.find((t) => t.id === id);
115
+ if (!target)
116
+ return false;
117
+ if (patch.kind !== undefined)
118
+ target.kind = patch.kind;
119
+ if (patch.message !== undefined)
120
+ target.message = patch.message;
121
+ if ('action' in patch)
122
+ target.action = patch.action;
123
+ if (patch.timeout !== undefined)
124
+ target.timeout = patch.timeout;
125
+ else if (patch.kind !== undefined)
126
+ target.timeout = DEFAULT_TIMEOUT[patch.kind];
127
+ if (live)
128
+ this.#arm(live);
129
+ return true;
130
+ }
131
+ /** Pause a visible toast's auto-dismiss timer (hover/focus). */
132
+ pause(id) {
133
+ this.#timers.get(id)?.pause();
134
+ }
135
+ /** Resume a paused timer (pointer/focus leave). */
136
+ resume(id) {
137
+ this.#timers.get(id)?.resume();
138
+ }
18
139
  dismiss(id) {
140
+ this.#timers.get(id)?.cancel();
141
+ this.#timers.delete(id);
19
142
  const i = this.items.findIndex((t) => t.id === id);
20
- if (i !== -1)
143
+ if (i !== -1) {
21
144
  this.items.splice(i, 1);
145
+ this.#promote();
146
+ return;
147
+ }
148
+ // Might still be waiting in the queue.
149
+ const qi = this.#queue.findIndex((t) => t.id === id);
150
+ if (qi !== -1)
151
+ this.#queue.splice(qi, 1);
152
+ }
153
+ /** Promote the next queued toast into a freed visible slot. */
154
+ #promote() {
155
+ while (this.items.length < this.max && this.#queue.length > 0) {
156
+ this.#show(this.#queue.shift());
157
+ }
22
158
  }
23
159
  clear() {
160
+ for (const t of this.#timers.values())
161
+ t.cancel();
162
+ this.#timers.clear();
163
+ this.#queue = [];
24
164
  this.items = [];
25
165
  }
26
166
  }
27
167
  export const toasts = new ToastStore();
28
168
  export const toast = {
29
- success: (message, timeout) => toasts.push('success', message, timeout),
30
- error: (message, timeout) => toasts.push('error', message, timeout),
31
- info: (message, timeout) => toasts.push('info', message, timeout)
169
+ success: (message, opts) => toasts.push('success', message, opts),
170
+ error: (message, opts) => toasts.push('error', message, opts),
171
+ info: (message, opts) => toasts.push('info', message, opts),
172
+ loading: (message, opts) => toasts.push('loading', message, opts),
173
+ /**
174
+ * Push a sticky `loading` toast, then update it to success/error when the
175
+ * promise settles. Returns the same promise so callers can keep chaining.
176
+ */
177
+ promise(p, messages) {
178
+ const id = toasts.push('loading', messages.loading, { timeout: 0 });
179
+ p.then((value) => {
180
+ const msg = typeof messages.success === 'function' ? messages.success(value) : messages.success;
181
+ toasts.update(id, { kind: 'success', message: msg });
182
+ }, (err) => {
183
+ const msg = typeof messages.error === 'function' ? messages.error(err) : messages.error;
184
+ toasts.update(id, { kind: 'error', message: msg });
185
+ });
186
+ return p;
187
+ }
32
188
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dssoca",
3
- "version": "0.5.0",
3
+ "version": "0.8.2",
4
4
  "description": "Svelte 5 design system — signal green on near-black, monospace-forward, zero border-radius; configured along two axes (color: dark/light, density: comfy/compact).",
5
5
  "license": "MIT",
6
6
  "author": "Rafael Passoca",