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,17 +1,59 @@
1
- <script lang="ts">
2
- import { tick, untrack } from 'svelte'
1
+ <script module lang="ts">
2
+ /** A single log severity level. */
3
+ export type LogLevel = 'info' | 'warn' | 'err' | 'ok'
4
+
5
+ /** A controlled log line. `id` is optional — when omitted the index is used as the key. */
6
+ export interface LogLine {
7
+ id?: string | number
8
+ /** Timestamp string (e.g. "12:00:01"); rendered verbatim. */
9
+ t?: string
10
+ lvl: LogLevel
11
+ /** Service / source tag (e.g. "[hub]"). */
12
+ svc?: string
13
+ msg: string
14
+ }
3
15
 
4
- interface LogLine { id: number; t: string; lvl: string; svc: string; msg: string }
16
+ const LEVELS: LogLevel[] = ['info', 'warn', 'err', 'ok']
17
+ </script>
18
+
19
+ <script lang="ts">
20
+ import { tick, untrack, type Snippet } from 'svelte'
21
+ import { resolveComponentSize, type Size } from '../config.js'
22
+ import EmptyState from './EmptyState.svelte'
5
23
 
6
24
  interface Props {
7
- live?: boolean
25
+ /** Controlled lines. When provided, the component renders exactly these (capped to `maxLines`). */
26
+ lines?: LogLine[]
27
+ /** Seed lines for the built-in demo stream (only used when `lines` is undefined). */
8
28
  initialLines?: Omit<LogLine, 'id'>[]
29
+ /** Generate a random demo stream. Defaults true ONLY when `lines` is not supplied. */
30
+ demo?: boolean
31
+ /** Back-compat alias for `demo` — drives the built-in ticker. */
32
+ live?: boolean
33
+ /** Max number of lines kept in the buffer (oldest dropped). */
34
+ maxLines?: number
35
+ /** Show the controls toolbar (filters, search, wrap, copy, clear). */
36
+ controls?: boolean
37
+ /** Replace the built-in toolbar entirely. */
38
+ toolbar?: Snippet
39
+ /** Wrap long messages (pre-wrap) vs. horizontal scroll (pre). */
40
+ wrap?: boolean
41
+ /** aria-live politeness for the log region. */
42
+ announce?: 'off' | 'polite' | 'assertive'
43
+ /** Accessible label for the log region. */
44
+ ariaLabel?: string
45
+ /** Show a connecting/loading indicator. */
46
+ loading?: boolean
47
+ /** Custom empty state. */
48
+ empty?: Snippet
49
+ /** Token size (sm|md|lg); inherits the global size when unset. */
50
+ size?: Size
9
51
  }
10
52
 
11
- const TEMPLATES = [
53
+ const TEMPLATES: Omit<LogLine, 'id'>[] = [
12
54
  { lvl: 'info', svc: '[movies-api]', msg: 'GET /movies?status=to_watch — 3 rows · 4ms' },
13
55
  { lvl: 'ok', svc: '[hub]', msg: 'GET /api/auth/session — 8ms' },
14
- { lvl: 'info', svc: '[hub]', msg: 'session refresh — user=rafael' },
56
+ { lvl: 'info', svc: '[hub]', msg: 'session refresh — user=admin' },
15
57
  { lvl: 'warn', svc: '[caddy]', msg: 'tls internal renewing hub.home' },
16
58
  { lvl: 'err', svc: '[tasks-api]', msg: 'EADDRINUSE :3004 — retrying in 2s' },
17
59
  { lvl: 'info', svc: '[notes-api]', msg: 'slow query · 182ms · SELECT * FROM notes' },
@@ -29,33 +71,373 @@
29
71
  return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
30
72
  }
31
73
 
32
- let { live = true, initialLines }: Props = $props()
74
+ let {
75
+ lines,
76
+ initialLines,
77
+ demo,
78
+ live,
79
+ maxLines = 30,
80
+ controls = true,
81
+ toolbar,
82
+ wrap = true,
83
+ announce = 'polite',
84
+ ariaLabel = 'Log output',
85
+ loading = false,
86
+ empty,
87
+ size,
88
+ }: Props = $props()
89
+
90
+ // Controlled mode: `lines` (or empty array) supplied → render those, demo off.
91
+ const controlled = $derived(lines !== undefined)
92
+ // Demo defaults on only when uncontrolled. `live`/`demo` either flips it.
93
+ const demoOn = $derived(!controlled && (demo ?? live ?? true))
33
94
 
95
+ // Internal demo buffer.
34
96
  const seed = untrack(() => initialLines ?? TEMPLATES)
35
97
  let counter = $state(seed.length)
36
- let lines = $state<LogLine[]>(seed.map((t, i) => ({ ...t, t: timeAgo(i * 4), id: i })))
98
+ let demoLines = $state<LogLine[]>(
99
+ seed.map((t, i) => ({ ...t, t: t.t || timeAgo(i * 4), id: i }))
100
+ )
101
+
102
+ // The source of truth, capped to maxLines.
103
+ const allLines = $derived(
104
+ (controlled ? (lines as LogLine[]) : demoLines).slice(-maxLines)
105
+ )
106
+
107
+ // --- toolbar state ---
108
+ let activeLevels = $state<Set<LogLevel>>(new Set(LEVELS))
109
+ let query = $state('')
110
+ let wrapOn = $state(untrack(() => wrap))
111
+ $effect(() => { wrapOn = wrap })
37
112
 
113
+ const visibleLines = $derived(
114
+ allLines.filter((l) => {
115
+ if (!activeLevels.has(l.lvl)) return false
116
+ if (query.trim()) {
117
+ const q = query.toLowerCase()
118
+ const hay = `${l.t ?? ''} ${l.lvl} ${l.svc ?? ''} ${l.msg}`.toLowerCase()
119
+ if (!hay.includes(q)) return false
120
+ }
121
+ return true
122
+ })
123
+ )
124
+
125
+ function toggleLevel(lvl: LogLevel) {
126
+ const next = new Set(activeLevels)
127
+ if (next.has(lvl)) next.delete(lvl)
128
+ else next.add(lvl)
129
+ activeLevels = next
130
+ }
131
+
132
+ async function copyVisible() {
133
+ const text = visibleLines
134
+ .map((l) => `${l.t ?? ''} ${l.lvl.toUpperCase()} ${l.svc ?? ''} ${l.msg}`.trim())
135
+ .join('\n')
136
+ try {
137
+ await navigator.clipboard?.writeText(text)
138
+ } catch {
139
+ /* clipboard unavailable (e.g. insecure context) — no-op */
140
+ }
141
+ }
142
+
143
+ function clear() {
144
+ if (controlled) return
145
+ demoLines = []
146
+ }
147
+
148
+ // --- follow-tail ---
38
149
  let el: HTMLDivElement | undefined
150
+ let following = $state(true)
151
+ const NEAR = 24 // px from bottom considered "at bottom"
152
+
153
+ function atBottom() {
154
+ if (!el) return true
155
+ return el.scrollHeight - el.scrollTop - el.clientHeight <= NEAR
156
+ }
157
+
158
+ function onScroll() {
159
+ following = atBottom()
160
+ }
39
161
 
162
+ async function jumpToBottom() {
163
+ following = true
164
+ await tick()
165
+ if (el) el.scrollTop = el.scrollHeight
166
+ }
167
+
168
+ // Auto-scroll on new content only when following.
169
+ $effect(() => {
170
+ // re-run whenever the visible set changes
171
+ void visibleLines.length
172
+ if (!following) return
173
+ tick().then(() => {
174
+ if (el && untrack(() => following)) el.scrollTop = el.scrollHeight
175
+ })
176
+ })
177
+
178
+ // Demo ticker.
40
179
  $effect(() => {
41
- if (!live) return
42
- const interval = setInterval(async () => {
180
+ if (!demoOn) return
181
+ const interval = setInterval(() => {
43
182
  const pick = TEMPLATES[Math.floor(Math.random() * TEMPLATES.length)]
44
- lines = [...lines.slice(-30), { ...pick, t: nowStr(), id: counter++ }]
45
- await tick()
46
- if (el) el.scrollTop = el.scrollHeight
183
+ demoLines = [...demoLines.slice(-maxLines), { ...pick, t: nowStr(), id: counter++ }]
47
184
  }, 1800)
48
185
  return () => clearInterval(interval)
49
186
  })
187
+
188
+ function keyFor(line: LogLine, i: number) {
189
+ return line.id ?? i
190
+ }
50
191
  </script>
51
192
 
52
- <div class="ss-logs" bind:this={el}>
53
- {#each lines as line (line.id)}
54
- <div class="ln">
55
- <span class="t">{line.t}</span>
56
- <span class="lvl {line.lvl}">{line.lvl.toUpperCase()}</span>
57
- <span class="svc">{line.svc}</span>
58
- <span>{line.msg}</span>
193
+ <div class="ss-logs" data-size-variant={resolveComponentSize('LogStream', size)}>
194
+ {#if controls}
195
+ {#if toolbar}
196
+ <div class="bar">{@render toolbar()}</div>
197
+ {:else}
198
+ <div class="bar">
199
+ <div class="filters" role="group" aria-label="Filter by level">
200
+ {#each LEVELS as lvl (lvl)}
201
+ <button
202
+ type="button"
203
+ class="chip {lvl}"
204
+ aria-pressed={activeLevels.has(lvl)}
205
+ onclick={() => toggleLevel(lvl)}
206
+ >{lvl.toUpperCase()}</button>
207
+ {/each}
208
+ </div>
209
+ <input
210
+ class="search"
211
+ type="text"
212
+ placeholder="Filter…"
213
+ aria-label="Filter log text"
214
+ bind:value={query}
215
+ />
216
+ <button
217
+ type="button"
218
+ class="chip"
219
+ aria-pressed={wrapOn}
220
+ onclick={() => (wrapOn = !wrapOn)}
221
+ >WRAP</button>
222
+ <button type="button" class="chip" onclick={copyVisible}>COPY</button>
223
+ {#if !controlled}
224
+ <button type="button" class="chip" onclick={clear}>CLEAR</button>
225
+ {/if}
226
+ </div>
227
+ {/if}
228
+ {/if}
229
+
230
+ <div class="viewport">
231
+ <div
232
+ class="scroll"
233
+ class:nowrap={!wrapOn}
234
+ bind:this={el}
235
+ onscroll={onScroll}
236
+ role="log"
237
+ aria-label={ariaLabel}
238
+ aria-live={announce}
239
+ aria-busy={loading}
240
+ >
241
+ {#if loading}
242
+ <div class="status" aria-hidden="true">
243
+ <span class="dot"></span> connecting…
244
+ </div>
245
+ {/if}
246
+
247
+ {#if visibleLines.length === 0}
248
+ {#if empty}
249
+ {@render empty()}
250
+ {:else}
251
+ <EmptyState
252
+ title="No log lines"
253
+ message={allLines.length ? 'No lines match the current filters.' : 'Waiting for output…'}
254
+ {size}
255
+ />
256
+ {/if}
257
+ {:else}
258
+ {#each visibleLines as line, i (keyFor(line, i))}
259
+ <div class="ln">
260
+ {#if line.t}<span class="t">{line.t}</span>{/if}
261
+ <span class="lvl {line.lvl}">{line.lvl.toUpperCase()}</span>
262
+ {#if line.svc}<span class="svc">{line.svc}</span>{/if}
263
+ <span class="msg">{line.msg}</span>
264
+ </div>
265
+ {/each}
266
+ {/if}
59
267
  </div>
60
- {/each}
268
+
269
+ {#if !following}
270
+ <button type="button" class="jump" onclick={jumpToBottom}>
271
+ Jump to bottom
272
+ </button>
273
+ {/if}
274
+ </div>
61
275
  </div>
276
+
277
+ <style>.ss-logs {
278
+ font-family: var(--ss-font-mono);
279
+ background: var(--ss-code-bg);
280
+ color: var(--ss-code-fg);
281
+ border: 1px solid var(--ss-line);
282
+ display: flex;
283
+ flex-direction: column;
284
+ }
285
+
286
+ .bar {
287
+ display: flex;
288
+ flex-wrap: wrap;
289
+ align-items: center;
290
+ gap: var(--ss-gap-sm);
291
+ padding: var(--ss-gap-sm) var(--ss-panel-body-px);
292
+ border-bottom: 1px solid var(--ss-line);
293
+ }
294
+
295
+ .filters {
296
+ display: flex;
297
+ gap: var(--ss-gap-sm);
298
+ }
299
+
300
+ .chip {
301
+ font-family: var(--ss-font-mono);
302
+ font-size: var(--ss-ui-sm);
303
+ line-height: 1;
304
+ padding: var(--ss-badge-py) var(--ss-badge-px);
305
+ border: 1px solid var(--ss-line);
306
+ background: transparent;
307
+ color: var(--ss-code-fg);
308
+ cursor: pointer;
309
+ transition: all var(--ss-dur-fast) var(--ss-ease);
310
+ }
311
+ .chip:hover {
312
+ border-color: var(--ss-line-strong);
313
+ }
314
+ .chip[aria-pressed=true] {
315
+ border-color: var(--ss-line-strong);
316
+ }
317
+ .chip[aria-pressed=false] {
318
+ opacity: 0.45;
319
+ }
320
+ .chip.info[aria-pressed=true] {
321
+ color: var(--ss-log-info);
322
+ }
323
+ .chip.warn[aria-pressed=true] {
324
+ color: var(--ss-log-warn);
325
+ }
326
+ .chip.err[aria-pressed=true] {
327
+ color: var(--ss-log-err);
328
+ }
329
+ .chip.ok[aria-pressed=true] {
330
+ color: var(--ss-log-ok);
331
+ }
332
+
333
+ .search {
334
+ flex: 1 1 8ch;
335
+ min-width: 8ch;
336
+ font-family: var(--ss-font-mono);
337
+ font-size: var(--ss-ui-sm);
338
+ padding: var(--ss-badge-py) var(--ss-gap-sm);
339
+ border: 1px solid var(--ss-line);
340
+ background: transparent;
341
+ color: var(--ss-code-fg);
342
+ }
343
+ .search:focus-visible {
344
+ outline: 2px solid var(--ss-primary);
345
+ outline-offset: 1px;
346
+ }
347
+ .search::placeholder {
348
+ color: var(--ss-fg-faint);
349
+ }
350
+
351
+ .viewport {
352
+ position: relative;
353
+ }
354
+
355
+ .scroll {
356
+ font-size: var(--ss-ui-md);
357
+ padding: var(--ss-gap) var(--ss-panel-body-px);
358
+ min-height: 160px;
359
+ max-height: 240px;
360
+ overflow: auto;
361
+ }
362
+ .scroll .ln {
363
+ display: flex;
364
+ gap: var(--ss-gap-sm);
365
+ line-height: 1.45;
366
+ white-space: pre-wrap;
367
+ }
368
+ .scroll.nowrap .ln {
369
+ white-space: pre;
370
+ }
371
+ .scroll .msg {
372
+ white-space: inherit;
373
+ }
374
+ .scroll .t {
375
+ color: var(--ss-fg-faint);
376
+ min-width: 58px;
377
+ flex: none;
378
+ }
379
+ .scroll .lvl {
380
+ min-width: 38px;
381
+ flex: none;
382
+ }
383
+ .scroll .lvl.info {
384
+ color: var(--ss-log-info);
385
+ }
386
+ .scroll .lvl.warn {
387
+ color: var(--ss-log-warn);
388
+ }
389
+ .scroll .lvl.err {
390
+ color: var(--ss-log-err);
391
+ }
392
+ .scroll .lvl.ok {
393
+ color: var(--ss-log-ok);
394
+ }
395
+ .scroll .svc {
396
+ color: var(--ss-code-keyword);
397
+ flex: none;
398
+ }
399
+
400
+ .status {
401
+ display: flex;
402
+ align-items: center;
403
+ gap: var(--ss-gap-sm);
404
+ color: var(--ss-fg-faint);
405
+ font-size: var(--ss-ui-sm);
406
+ padding-bottom: var(--ss-gap-sm);
407
+ }
408
+ .status .dot {
409
+ width: var(--ss-s-2);
410
+ height: var(--ss-s-2);
411
+ background: var(--ss-primary);
412
+ animation: pulse var(--ss-dur-xslow) var(--ss-ease) infinite;
413
+ }
414
+
415
+ @keyframes pulse {
416
+ 0%, 100% {
417
+ opacity: 0.3;
418
+ }
419
+ 50% {
420
+ opacity: 1;
421
+ }
422
+ }
423
+ .jump {
424
+ position: absolute;
425
+ right: var(--ss-gap);
426
+ bottom: var(--ss-gap);
427
+ font-family: var(--ss-font-mono);
428
+ font-size: var(--ss-ui-sm);
429
+ line-height: 1;
430
+ padding: var(--ss-badge-py) var(--ss-badge-px);
431
+ border: 1px solid var(--ss-line-strong);
432
+ background: var(--ss-bg-elev);
433
+ color: var(--ss-fg);
434
+ cursor: pointer;
435
+ box-shadow: var(--ss-shadow-2);
436
+ }
437
+ .jump:hover {
438
+ border-color: var(--ss-primary);
439
+ }
440
+ .jump:focus-visible {
441
+ outline: 2px solid var(--ss-primary);
442
+ outline-offset: 1px;
443
+ }</style>
@@ -1,13 +1,44 @@
1
- interface LogLine {
2
- id: number;
3
- t: string;
4
- lvl: string;
5
- svc: string;
1
+ /** A single log severity level. */
2
+ export type LogLevel = 'info' | 'warn' | 'err' | 'ok';
3
+ /** A controlled log line. `id` is optional — when omitted the index is used as the key. */
4
+ export interface LogLine {
5
+ id?: string | number;
6
+ /** Timestamp string (e.g. "12:00:01"); rendered verbatim. */
7
+ t?: string;
8
+ lvl: LogLevel;
9
+ /** Service / source tag (e.g. "[hub]"). */
10
+ svc?: string;
6
11
  msg: string;
7
12
  }
13
+ import { type Snippet } from 'svelte';
14
+ import { type Size } from '../config.js';
8
15
  interface Props {
9
- live?: boolean;
16
+ /** Controlled lines. When provided, the component renders exactly these (capped to `maxLines`). */
17
+ lines?: LogLine[];
18
+ /** Seed lines for the built-in demo stream (only used when `lines` is undefined). */
10
19
  initialLines?: Omit<LogLine, 'id'>[];
20
+ /** Generate a random demo stream. Defaults true ONLY when `lines` is not supplied. */
21
+ demo?: boolean;
22
+ /** Back-compat alias for `demo` — drives the built-in ticker. */
23
+ live?: boolean;
24
+ /** Max number of lines kept in the buffer (oldest dropped). */
25
+ maxLines?: number;
26
+ /** Show the controls toolbar (filters, search, wrap, copy, clear). */
27
+ controls?: boolean;
28
+ /** Replace the built-in toolbar entirely. */
29
+ toolbar?: Snippet;
30
+ /** Wrap long messages (pre-wrap) vs. horizontal scroll (pre). */
31
+ wrap?: boolean;
32
+ /** aria-live politeness for the log region. */
33
+ announce?: 'off' | 'polite' | 'assertive';
34
+ /** Accessible label for the log region. */
35
+ ariaLabel?: string;
36
+ /** Show a connecting/loading indicator. */
37
+ loading?: boolean;
38
+ /** Custom empty state. */
39
+ empty?: Snippet;
40
+ /** Token size (sm|md|lg); inherits the global size when unset. */
41
+ size?: Size;
11
42
  }
12
43
  declare const LogStream: import("svelte").Component<Props, {}, "">;
13
44
  type LogStream = ReturnType<typeof LogStream>;