dssoca 0.9.0 → 0.11.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 (35) hide show
  1. package/dist/components/Avatar.svelte +119 -0
  2. package/dist/components/Avatar.svelte.d.ts +18 -0
  3. package/dist/components/BoxPlot.svelte +427 -0
  4. package/dist/components/BoxPlot.svelte.d.ts +36 -0
  5. package/dist/components/BumpChart.svelte +351 -0
  6. package/dist/components/BumpChart.svelte.d.ts +32 -0
  7. package/dist/components/Chart.svelte +527 -0
  8. package/dist/components/Chart.svelte.d.ts +42 -0
  9. package/dist/components/DateField.svelte +188 -0
  10. package/dist/components/DateField.svelte.d.ts +37 -0
  11. package/dist/components/FileDrop.svelte +355 -0
  12. package/dist/components/FileDrop.svelte.d.ts +24 -0
  13. package/dist/components/Heatmap.svelte +333 -0
  14. package/dist/components/Heatmap.svelte.d.ts +30 -0
  15. package/dist/components/Modal.svelte +223 -0
  16. package/dist/components/Modal.svelte.d.ts +29 -0
  17. package/dist/components/NumberField.svelte +260 -0
  18. package/dist/components/NumberField.svelte.d.ts +35 -0
  19. package/dist/components/Pagination.svelte +193 -0
  20. package/dist/components/Pagination.svelte.d.ts +22 -0
  21. package/dist/components/ScatterPlot.svelte +401 -0
  22. package/dist/components/ScatterPlot.svelte.d.ts +55 -0
  23. package/dist/components/Select.svelte +224 -0
  24. package/dist/components/Select.svelte.d.ts +42 -0
  25. package/dist/components/Switch.svelte +144 -0
  26. package/dist/components/Switch.svelte.d.ts +22 -0
  27. package/dist/components/Table.svelte +267 -0
  28. package/dist/components/Table.svelte.d.ts +52 -0
  29. package/dist/components/Tooltip.svelte +162 -0
  30. package/dist/components/Tooltip.svelte.d.ts +17 -0
  31. package/dist/dssoca.config.d.ts +1 -1
  32. package/dist/dssoca.config.js +11 -0
  33. package/dist/index.d.ts +16 -0
  34. package/dist/index.js +17 -0
  35. package/package.json +9 -1
@@ -0,0 +1,260 @@
1
+ <script lang="ts">
2
+ import { resolveComponentSize, type Size } from '../config.js'
3
+
4
+ interface Props {
5
+ label?: string
6
+ id?: string
7
+ name?: string
8
+ /** Bindable current value; `null` when the input is empty. */
9
+ value?: number | null
10
+ min?: number
11
+ max?: number
12
+ /** Increment/decrement step for the steppers (and native arrows). */
13
+ step?: number
14
+ required?: boolean
15
+ disabled?: boolean
16
+ /** Native readonly — value visible but not editable; rendered muted. */
17
+ readonly?: boolean
18
+ /** Token size (sm|md|lg); inherits the global size when unset. */
19
+ size?: Size
20
+ /** Marks the field invalid for assistive tech (aria-invalid). */
21
+ invalid?: boolean
22
+ /** Supplementary helper text rendered under the input. */
23
+ hint?: string
24
+ /** Error text rendered under the input; its presence implies aria-invalid and is announced to AT. */
25
+ error?: string
26
+ /** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
27
+ describedby?: string
28
+ placeholder?: string
29
+ onchange?: (e: Event & { currentTarget: HTMLInputElement }) => void
30
+ /** Any remaining native input attributes / event handlers are forwarded. */
31
+ [key: string]: unknown
32
+ }
33
+ let {
34
+ label,
35
+ id,
36
+ name,
37
+ value = $bindable(null),
38
+ min,
39
+ max,
40
+ step = 1,
41
+ required = false,
42
+ disabled = false,
43
+ readonly = false,
44
+ size,
45
+ invalid,
46
+ hint,
47
+ error,
48
+ describedby,
49
+ placeholder = '',
50
+ onchange,
51
+ ...rest
52
+ }: Props = $props()
53
+
54
+ // Guarantee a label↔input association even when no `id` is passed.
55
+ const uid = $props.id()
56
+ const inputId = $derived(id ?? uid)
57
+ const hintId = $derived(`${inputId}-hint`)
58
+ const errorId = $derived(`${inputId}-error`)
59
+
60
+ // error wins, then hint, then any caller-supplied describedby — order matters for AT.
61
+ const describedBy = $derived(
62
+ [error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
63
+ undefined,
64
+ )
65
+ const isInvalid = $derived(invalid || Boolean(error) || undefined)
66
+ const resolvedSize = $derived(resolveComponentSize('NumberField', size))
67
+
68
+ // Steppers are inert at the bounds (and when the field can't be edited).
69
+ const atMin = $derived(value != null && min != null && value <= min)
70
+ const atMax = $derived(value != null && max != null && value >= max)
71
+ const decDisabled = $derived(disabled || readonly || atMin)
72
+ const incDisabled = $derived(disabled || readonly || atMax)
73
+
74
+ function clamp(n: number): number {
75
+ if (min != null && n < min) return min
76
+ if (max != null && n > max) return max
77
+ return n
78
+ }
79
+
80
+ function onInput(e: Event & { currentTarget: HTMLInputElement }) {
81
+ const raw = e.currentTarget.value
82
+ value = raw === '' ? null : e.currentTarget.valueAsNumber
83
+ if (value != null && Number.isNaN(value)) value = null
84
+ }
85
+
86
+ function nudge(dir: 1 | -1) {
87
+ const base = value ?? (dir > 0 ? (min ?? 0) : (max ?? 0))
88
+ value = clamp(base + dir * step)
89
+ }
90
+ </script>
91
+
92
+ <div
93
+ class="ss-numberfield"
94
+ data-size-variant={resolvedSize}
95
+ class:invalid={isInvalid}
96
+ class:disabled
97
+ >
98
+ {#if label}
99
+ <label class="lbl" for={inputId}>
100
+ {label}
101
+ {#if required}<span class="req" aria-hidden="true">*</span>{/if}
102
+ </label>
103
+ {/if}
104
+
105
+ <div class="control">
106
+ <button
107
+ type="button"
108
+ class="step dec"
109
+ aria-label="Decrease"
110
+ disabled={decDisabled}
111
+ onclick={() => nudge(-1)}
112
+ >
113
+ −
114
+ </button>
115
+ <input
116
+ class="ss-input"
117
+ id={inputId}
118
+ {name}
119
+ type="number"
120
+ inputmode="decimal"
121
+ value={value ?? ''}
122
+ {min}
123
+ {max}
124
+ {step}
125
+ {placeholder}
126
+ {required}
127
+ {disabled}
128
+ {readonly}
129
+ aria-invalid={isInvalid}
130
+ aria-describedby={describedBy}
131
+ oninput={onInput}
132
+ {onchange}
133
+ {...rest}
134
+ />
135
+ <button
136
+ type="button"
137
+ class="step inc"
138
+ aria-label="Increase"
139
+ disabled={incDisabled}
140
+ onclick={() => nudge(1)}
141
+ >
142
+ +
143
+ </button>
144
+ </div>
145
+
146
+ {#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
147
+ {#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
148
+ </div>
149
+
150
+ <style>.ss-numberfield {
151
+ display: flex;
152
+ flex-direction: column;
153
+ gap: 6px;
154
+ }
155
+ .ss-numberfield .lbl {
156
+ font-family: var(--ss-font-mono);
157
+ font-size: var(--ss-ui-xs);
158
+ color: var(--ss-fg-muted);
159
+ text-transform: uppercase;
160
+ letter-spacing: 0.08em;
161
+ }
162
+ .ss-numberfield .lbl .req {
163
+ color: var(--ss-red);
164
+ margin-left: 2px;
165
+ }
166
+ .ss-numberfield .control {
167
+ display: flex;
168
+ align-items: stretch;
169
+ background: transparent;
170
+ color: var(--ss-fg);
171
+ border: 1px solid var(--ss-line);
172
+ transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
173
+ }
174
+ .ss-numberfield .control:focus-within {
175
+ border-color: var(--ss-primary);
176
+ box-shadow: 0 0 0 3px var(--ss-primary-soft);
177
+ }
178
+ .ss-numberfield.invalid .control {
179
+ border-color: var(--ss-red);
180
+ }
181
+ .ss-numberfield.invalid .control:focus-within {
182
+ border-color: var(--ss-red);
183
+ box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
184
+ }
185
+ .ss-numberfield.disabled .control {
186
+ border-color: var(--ss-line);
187
+ }
188
+ .ss-numberfield .step {
189
+ display: inline-flex;
190
+ align-items: center;
191
+ justify-content: center;
192
+ flex: none;
193
+ width: var(--ss-numberfield-step-w, 2.25em);
194
+ font-family: var(--ss-font-mono);
195
+ font-size: var(--ss-input-font);
196
+ line-height: 1;
197
+ background: transparent;
198
+ border: none;
199
+ color: var(--ss-fg-muted);
200
+ cursor: pointer;
201
+ transition: color var(--ss-dur-fast) var(--ss-ease);
202
+ }
203
+ .ss-numberfield .step:hover:not(:disabled) {
204
+ color: var(--ss-fg);
205
+ }
206
+ .ss-numberfield .step:focus-visible {
207
+ outline: none;
208
+ color: var(--ss-fg);
209
+ box-shadow: 0 0 0 2px var(--ss-primary-soft);
210
+ }
211
+ .ss-numberfield .step:disabled {
212
+ color: var(--ss-fg-faint);
213
+ cursor: not-allowed;
214
+ }
215
+ .ss-numberfield .msg {
216
+ font-family: var(--ss-font-mono);
217
+ font-size: var(--ss-ui-xs);
218
+ letter-spacing: 0.02em;
219
+ }
220
+ .ss-numberfield .msg.hint {
221
+ color: var(--ss-fg-faint);
222
+ }
223
+ .ss-numberfield .msg.error {
224
+ color: var(--ss-red);
225
+ }
226
+
227
+ .ss-input {
228
+ font-family: var(--ss-font-mono);
229
+ font-size: var(--ss-input-font);
230
+ background: transparent;
231
+ color: var(--ss-fg);
232
+ border: none;
233
+ padding: var(--ss-input-py) var(--ss-input-px);
234
+ width: 100%;
235
+ min-width: 0;
236
+ text-align: center;
237
+ transition: color var(--ss-dur-fast) var(--ss-ease);
238
+ -moz-appearance: textfield;
239
+ appearance: textfield;
240
+ }
241
+ .ss-input::-webkit-outer-spin-button, .ss-input::-webkit-inner-spin-button {
242
+ -webkit-appearance: none;
243
+ margin: 0;
244
+ }
245
+ .ss-input:focus {
246
+ outline: none;
247
+ }
248
+ .ss-input::placeholder {
249
+ font-style: italic;
250
+ color: var(--ss-fg-faint);
251
+ }
252
+ .ss-input[readonly] {
253
+ color: var(--ss-fg-muted);
254
+ cursor: default;
255
+ }
256
+ .ss-input:disabled {
257
+ color: var(--ss-fg-faint);
258
+ cursor: not-allowed;
259
+ -webkit-text-fill-color: var(--ss-fg-faint);
260
+ }</style>
@@ -0,0 +1,35 @@
1
+ import { type Size } from '../config.js';
2
+ interface Props {
3
+ label?: string;
4
+ id?: string;
5
+ name?: string;
6
+ /** Bindable current value; `null` when the input is empty. */
7
+ value?: number | null;
8
+ min?: number;
9
+ max?: number;
10
+ /** Increment/decrement step for the steppers (and native arrows). */
11
+ step?: number;
12
+ required?: boolean;
13
+ disabled?: boolean;
14
+ /** Native readonly — value visible but not editable; rendered muted. */
15
+ readonly?: boolean;
16
+ /** Token size (sm|md|lg); inherits the global size when unset. */
17
+ size?: Size;
18
+ /** Marks the field invalid for assistive tech (aria-invalid). */
19
+ invalid?: boolean;
20
+ /** Supplementary helper text rendered under the input. */
21
+ hint?: string;
22
+ /** Error text rendered under the input; its presence implies aria-invalid and is announced to AT. */
23
+ error?: string;
24
+ /** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
25
+ describedby?: string;
26
+ placeholder?: string;
27
+ onchange?: (e: Event & {
28
+ currentTarget: HTMLInputElement;
29
+ }) => void;
30
+ /** Any remaining native input attributes / event handlers are forwarded. */
31
+ [key: string]: unknown;
32
+ }
33
+ declare const NumberField: import("svelte").Component<Props, {}, "value">;
34
+ type NumberField = ReturnType<typeof NumberField>;
35
+ export default NumberField;
@@ -0,0 +1,193 @@
1
+ <script lang="ts">
2
+ // ─────────────────────────────────────────────────────────────────────────
3
+ // Pagination — DS-0100. A windowed page navigator: a Prev button, a list of
4
+ // page-number buttons (first, last, and ±siblingCount around the current one,
5
+ // with `…` ellipses bridging the gaps), and a Next button. Bindable 1-based
6
+ // `page`, zero radius, mono numerals, `--ss-line` hairlines, size-token
7
+ // density. The current page is `aria-current="page"`, visually active and
8
+ // inert (re-clicking it never re-fires). WCAG 2.2 AA.
9
+ // ─────────────────────────────────────────────────────────────────────────
10
+ import { resolveComponentSize, type Size } from '../config.js'
11
+
12
+ interface Props {
13
+ /** Current page, 1-based (bindable). */
14
+ page?: number
15
+ /** Total item count — used with `pageSize` to derive the page count. */
16
+ total?: number
17
+ /** Explicit page count; overrides the `total`/`pageSize` computation. */
18
+ pageCount?: number
19
+ /** Items per page when deriving the count from `total`. Default 10. */
20
+ pageSize?: number
21
+ /** Page-number buttons to show on each side of the current page. Default 1. */
22
+ siblingCount?: number
23
+ /** Disable the whole control: every button is inert. */
24
+ disabled?: boolean
25
+ /** Token size (sm|md|lg); inherits the global size when unset. */
26
+ size?: Size
27
+ /** Fired when the page changes (after `page` updates). */
28
+ onchange?: (page: number) => void
29
+ }
30
+
31
+ let {
32
+ page = $bindable(1),
33
+ total,
34
+ pageCount,
35
+ pageSize = 10,
36
+ siblingCount = 1,
37
+ disabled = false,
38
+ size,
39
+ onchange,
40
+ }: Props = $props()
41
+
42
+ // Total number of pages — explicit `pageCount` wins, else derived from the
43
+ // item count. Always at least 1 so the control never renders empty.
44
+ const pages = $derived(pageCount ?? Math.max(1, Math.ceil((total ?? 0) / pageSize)))
45
+
46
+ // Clamp the active page into [1, pages] for all rendering/decisions.
47
+ const current = $derived(Math.min(Math.max(1, page), pages))
48
+
49
+ type Slot = number | 'gap-start' | 'gap-end'
50
+
51
+ // Windowed list of slots: first page, last page, the sibling window around
52
+ // the current page, and an ellipsis marker wherever a run of pages is hidden.
53
+ const slots = $derived.by<Slot[]>(() => {
54
+ const start = Math.max(2, current - siblingCount)
55
+ const end = Math.min(pages - 1, current + siblingCount)
56
+ const out: Slot[] = [1]
57
+ // A single hidden page is cheaper to show than an ellipsis — only collapse
58
+ // a run into `…` when it hides more than one page.
59
+ if (start > 3) out.push('gap-start')
60
+ else if (start === 3) out.push(2)
61
+ for (let p = start; p <= end; p++) out.push(p)
62
+ if (end < pages - 2) out.push('gap-end')
63
+ else if (end === pages - 2) out.push(pages - 1)
64
+ if (pages > 1) out.push(pages)
65
+ return out
66
+ })
67
+
68
+ const atFirst = $derived(current <= 1)
69
+ const atLast = $derived(current >= pages)
70
+
71
+ function go(target: number) {
72
+ const next = Math.min(Math.max(1, target), pages)
73
+ if (disabled || next === current) return
74
+ page = next
75
+ onchange?.(next)
76
+ }
77
+
78
+ const sizeAttr = $derived(resolveComponentSize('Pagination', size))
79
+ </script>
80
+
81
+ <nav
82
+ class="ss-pagination"
83
+ aria-label="Pagination"
84
+ data-size-variant={sizeAttr}
85
+ data-disabled={disabled ? 'true' : undefined}
86
+ >
87
+ <button
88
+ type="button"
89
+ class="page nav-btn"
90
+ aria-label="Previous page"
91
+ disabled={disabled || atFirst}
92
+ onclick={() => go(current - 1)}
93
+ >
94
+ <span aria-hidden="true">‹</span>
95
+ </button>
96
+
97
+ {#each slots as slot (slot)}
98
+ {#if slot === 'gap-start' || slot === 'gap-end'}
99
+ <span class="ellipsis" aria-hidden="true">…</span>
100
+ {:else}
101
+ {@const isCurrent = slot === current}
102
+ <button
103
+ type="button"
104
+ class="page"
105
+ class:active={isCurrent}
106
+ aria-current={isCurrent ? 'page' : undefined}
107
+ aria-label={`Page ${slot}`}
108
+ {disabled}
109
+ onclick={() => go(slot)}
110
+ >
111
+ {slot}
112
+ </button>
113
+ {/if}
114
+ {/each}
115
+
116
+ <button
117
+ type="button"
118
+ class="page nav-btn"
119
+ aria-label="Next page"
120
+ disabled={disabled || atLast}
121
+ onclick={() => go(current + 1)}
122
+ >
123
+ <span aria-hidden="true">›</span>
124
+ </button>
125
+ </nav>
126
+
127
+ <style>.ss-pagination {
128
+ display: inline-flex;
129
+ align-items: center;
130
+ gap: 0;
131
+ border: 1px solid var(--ss-line);
132
+ background: var(--ss-bg);
133
+ width: max-content;
134
+ max-width: 100%;
135
+ }
136
+ .ss-pagination .page {
137
+ display: inline-flex;
138
+ align-items: center;
139
+ justify-content: center;
140
+ min-width: var(--ss-pagination-min, 2.25em);
141
+ font: 500 var(--ss-pagination-font, 0.875rem)/1 var(--ss-font-mono);
142
+ color: var(--ss-fg-muted);
143
+ background: transparent;
144
+ border: 0;
145
+ border-left: 1px solid var(--ss-line);
146
+ padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
147
+ cursor: pointer;
148
+ white-space: nowrap;
149
+ transition: color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease);
150
+ }
151
+ .ss-pagination .page:first-child {
152
+ border-left: 0;
153
+ }
154
+ .ss-pagination .page:hover:not(.active):not(:disabled) {
155
+ color: var(--ss-fg);
156
+ background: var(--ss-hover);
157
+ }
158
+ .ss-pagination .page.active {
159
+ color: var(--ss-fg-on-primary);
160
+ background: var(--ss-primary);
161
+ cursor: default;
162
+ }
163
+ .ss-pagination .page:focus-visible {
164
+ outline: none;
165
+ box-shadow: inset 0 0 0 2px var(--ss-primary-soft);
166
+ z-index: 1;
167
+ }
168
+ .ss-pagination .page.active:focus-visible {
169
+ box-shadow: inset 0 0 0 2px var(--ss-bg);
170
+ }
171
+ .ss-pagination .page:disabled {
172
+ cursor: not-allowed;
173
+ opacity: 0.45;
174
+ }
175
+ .ss-pagination .page.active:disabled {
176
+ opacity: 1;
177
+ cursor: default;
178
+ }
179
+ .ss-pagination .nav-btn {
180
+ font-size: var(--ss-pagination-nav-font, 1rem);
181
+ }
182
+ .ss-pagination .ellipsis {
183
+ display: inline-flex;
184
+ align-items: center;
185
+ justify-content: center;
186
+ min-width: var(--ss-pagination-min, 2.25em);
187
+ padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
188
+ border-left: 1px solid var(--ss-line);
189
+ color: var(--ss-fg-muted);
190
+ font-family: var(--ss-font-mono);
191
+ line-height: 1;
192
+ user-select: none;
193
+ }</style>
@@ -0,0 +1,22 @@
1
+ import { type Size } from '../config.js';
2
+ interface Props {
3
+ /** Current page, 1-based (bindable). */
4
+ page?: number;
5
+ /** Total item count — used with `pageSize` to derive the page count. */
6
+ total?: number;
7
+ /** Explicit page count; overrides the `total`/`pageSize` computation. */
8
+ pageCount?: number;
9
+ /** Items per page when deriving the count from `total`. Default 10. */
10
+ pageSize?: number;
11
+ /** Page-number buttons to show on each side of the current page. Default 1. */
12
+ siblingCount?: number;
13
+ /** Disable the whole control: every button is inert. */
14
+ disabled?: boolean;
15
+ /** Token size (sm|md|lg); inherits the global size when unset. */
16
+ size?: Size;
17
+ /** Fired when the page changes (after `page` updates). */
18
+ onchange?: (page: number) => void;
19
+ }
20
+ declare const Pagination: import("svelte").Component<Props, {}, "page">;
21
+ type Pagination = ReturnType<typeof Pagination>;
22
+ export default Pagination;