dssoca 0.2.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 (51) hide show
  1. package/README.md +54 -18
  2. package/dist/components/Accordion.svelte +281 -0
  3. package/dist/components/Accordion.svelte.d.ts +47 -0
  4. package/dist/components/Badge.svelte +144 -7
  5. package/dist/components/Badge.svelte.d.ts +31 -2
  6. package/dist/components/BottomNav.svelte +216 -0
  7. package/dist/components/BottomNav.svelte.d.ts +30 -0
  8. package/dist/components/Button.svelte +187 -6
  9. package/dist/components/Button.svelte.d.ts +24 -4
  10. package/dist/components/Card.svelte +203 -8
  11. package/dist/components/Card.svelte.d.ts +21 -1
  12. package/dist/components/EmptyState.svelte +123 -36
  13. package/dist/components/EmptyState.svelte.d.ts +17 -1
  14. package/dist/components/Icon.svelte +191 -12
  15. package/dist/components/Icon.svelte.d.ts +69 -2
  16. package/dist/components/Image.svelte +430 -0
  17. package/dist/components/Image.svelte.d.ts +49 -0
  18. package/dist/components/Input.svelte +206 -18
  19. package/dist/components/Input.svelte.d.ts +29 -0
  20. package/dist/components/Link.svelte +148 -0
  21. package/dist/components/Link.svelte.d.ts +22 -0
  22. package/dist/components/LogStream.svelte +403 -21
  23. package/dist/components/LogStream.svelte.d.ts +37 -6
  24. package/dist/components/Menu.svelte +355 -0
  25. package/dist/components/Menu.svelte.d.ts +46 -0
  26. package/dist/components/MetricTile.svelte +161 -7
  27. package/dist/components/MetricTile.svelte.d.ts +23 -0
  28. package/dist/components/SegmentedControl.svelte +208 -0
  29. package/dist/components/SegmentedControl.svelte.d.ts +30 -0
  30. package/dist/components/ServiceCard.svelte +270 -9
  31. package/dist/components/ServiceCard.svelte.d.ts +16 -1
  32. package/dist/components/Sidebar.svelte +391 -25
  33. package/dist/components/Sidebar.svelte.d.ts +20 -6
  34. package/dist/components/Sparkline.svelte +213 -6
  35. package/dist/components/Sparkline.svelte.d.ts +24 -0
  36. package/dist/components/Toaster.svelte +273 -60
  37. package/dist/components/Toaster.svelte.d.ts +9 -16
  38. package/dist/components/Topbar.svelte +273 -17
  39. package/dist/components/Topbar.svelte.d.ts +23 -0
  40. package/dist/config.d.ts +32 -14
  41. package/dist/config.js +43 -17
  42. package/dist/dssoca.config.d.ts +50 -0
  43. package/dist/dssoca.config.js +45 -0
  44. package/dist/index.d.ts +12 -5
  45. package/dist/index.js +14 -4
  46. package/dist/theme.css +587 -382
  47. package/dist/toast.svelte.d.ts +49 -5
  48. package/dist/toast.svelte.js +165 -9
  49. package/package.json +17 -3
  50. package/dist/components/PassocaMark.svelte +0 -15
  51. package/dist/components/PassocaMark.svelte.d.ts +0 -7
@@ -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.2.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",
@@ -34,6 +34,10 @@
34
34
  "svelte": "^5.0.0"
35
35
  },
36
36
  "devDependencies": {
37
+ "@storybook/addon-a11y": "10.4.2",
38
+ "@storybook/addon-docs": "^10.4.2",
39
+ "@storybook/addon-svelte-csf": "^5.1.2",
40
+ "@storybook/sveltekit": "^10.4.2",
37
41
  "@sveltejs/adapter-auto": "^7.0.1",
38
42
  "@sveltejs/kit": "^2.57.0",
39
43
  "@sveltejs/package": "^2.5.7",
@@ -42,11 +46,14 @@
42
46
  "@testing-library/svelte": "^5.3.1",
43
47
  "jsdom": "^29.1.1",
44
48
  "publint": "^0.3.18",
49
+ "sass": "^1.100.0",
50
+ "storybook": "^10.4.2",
45
51
  "svelte": "^5.55.2",
46
52
  "svelte-check": "^4.4.6",
47
53
  "typescript": "^6.0.2",
48
54
  "vite": "^8.0.7",
49
- "vitest": "^4.1.7"
55
+ "vitest": "^4.1.7",
56
+ "vitest-axe": "^0.1.0"
50
57
  },
51
58
  "keywords": [
52
59
  "svelte",
@@ -60,9 +67,16 @@
60
67
  "dev": "vite dev",
61
68
  "build": "vite build && npm run prepack",
62
69
  "preview": "vite preview",
70
+ "build:css": "sass src/styles/theme.scss dist/theme.css --no-source-map --no-charset --style=expanded",
63
71
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
64
72
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
65
73
  "test": "vitest run",
66
- "test:watch": "vitest"
74
+ "test:watch": "vitest",
75
+ "storybook": "storybook dev -p 6006",
76
+ "build-storybook": "storybook build",
77
+ "docs:dev": "pnpm --filter dssoca-docs dev",
78
+ "docs:build": "pnpm --filter dssoca-docs build",
79
+ "docs:preview": "pnpm --filter dssoca-docs preview",
80
+ "docs:test": "pnpm --filter dssoca-docs test"
67
81
  }
68
82
  }
@@ -1,15 +0,0 @@
1
- <script lang="ts">
2
- interface Props {
3
- size?: number
4
- color?: string
5
- }
6
- let { size = 22, color = 'var(--ss-primary)' }: Props = $props()
7
- </script>
8
-
9
- <svg viewBox="0 0 103 89" width={size} height={size} fill={color}>
10
- <path
11
- fill-rule="evenodd"
12
- clip-rule="evenodd"
13
- d="M51.5 0L0 89H103L51.5 0ZM23.8643 80.151H87.6468L71.6884 52.5724L23.8643 80.151ZM65.5911 42.0354L60.7383 33.649L46.1956 42.0354H65.5911ZM56.14 25.7024L51.5 17.6837L42.2125 33.7339L56.14 25.7024ZM32.0977 51.2138L20.2949 71.6111L55.6656 51.2138H32.0977Z"
14
- />
15
- </svg>
@@ -1,7 +0,0 @@
1
- interface Props {
2
- size?: number;
3
- color?: string;
4
- }
5
- declare const PassocaMark: import("svelte").Component<Props, {}, "">;
6
- type PassocaMark = ReturnType<typeof PassocaMark>;
7
- export default PassocaMark;