dssoca 0.9.0 → 0.10.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.
@@ -0,0 +1,188 @@
1
+ <script lang="ts">
2
+ import type { HTMLInputAttributes } from 'svelte/elements'
3
+ import { resolveComponentSize, type Size } from '../config.js'
4
+
5
+ interface Props {
6
+ label?: string
7
+ id?: string
8
+ name?: string
9
+ /** Bindable ISO date string (`yyyy-mm-dd`). */
10
+ value?: string
11
+ /** Earliest selectable date (ISO `yyyy-mm-dd`); forwarded to the native input. */
12
+ min?: string
13
+ /** Latest selectable date (ISO `yyyy-mm-dd`); forwarded to the native input. */
14
+ max?: string
15
+ required?: boolean
16
+ disabled?: boolean
17
+ /** Native readonly — value visible but not editable; rendered muted. */
18
+ readonly?: boolean
19
+ /** Token size (sm|md|lg); inherits the global size when unset. */
20
+ size?: Size
21
+ /** Marks the field invalid for assistive tech (aria-invalid). */
22
+ invalid?: boolean
23
+ /** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
24
+ describedby?: string
25
+ /** Supplementary helper text rendered under the input. */
26
+ hint?: string
27
+ /** Error text rendered under the input; its presence implies aria-invalid and is announced to AT. */
28
+ error?: string
29
+ onchange?: (e: Event & { currentTarget: HTMLInputElement }) => void
30
+ oninput?: (e: Event & { currentTarget: HTMLInputElement }) => void
31
+ /** Any remaining native input attributes / event handlers are forwarded. */
32
+ [key: string]: unknown
33
+ }
34
+ let {
35
+ label,
36
+ id,
37
+ name,
38
+ value = $bindable(''),
39
+ min,
40
+ max,
41
+ required = false,
42
+ disabled = false,
43
+ readonly = false,
44
+ size,
45
+ invalid,
46
+ describedby,
47
+ hint,
48
+ error,
49
+ onchange,
50
+ oninput,
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('DateField', size))
67
+ </script>
68
+
69
+ <div class="ss-datefield" data-size-variant={resolvedSize} class:invalid={isInvalid} class:disabled>
70
+ {#if label}
71
+ <label class="lbl" for={inputId}>
72
+ {label}
73
+ {#if required}<span class="req" aria-hidden="true">*</span>{/if}
74
+ </label>
75
+ {/if}
76
+
77
+ <div class="control">
78
+ <input
79
+ class="field"
80
+ type="date"
81
+ id={inputId}
82
+ {name}
83
+ bind:value
84
+ {min}
85
+ {max}
86
+ {required}
87
+ {disabled}
88
+ {readonly}
89
+ aria-invalid={isInvalid}
90
+ aria-describedby={describedBy}
91
+ {onchange}
92
+ {oninput}
93
+ {...rest}
94
+ />
95
+ </div>
96
+
97
+ {#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
98
+ {#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
99
+ </div>
100
+
101
+ <style>.ss-datefield {
102
+ display: flex;
103
+ flex-direction: column;
104
+ gap: 6px;
105
+ }
106
+ .ss-datefield .lbl {
107
+ font-family: var(--ss-font-mono);
108
+ font-size: var(--ss-ui-xs);
109
+ color: var(--ss-fg-muted);
110
+ text-transform: uppercase;
111
+ letter-spacing: 0.08em;
112
+ }
113
+ .ss-datefield .lbl .req {
114
+ color: var(--ss-red);
115
+ margin-left: 2px;
116
+ }
117
+ .ss-datefield .control {
118
+ display: flex;
119
+ align-items: center;
120
+ gap: var(--ss-gap-sm);
121
+ background: transparent;
122
+ color: var(--ss-fg);
123
+ border: 1px solid var(--ss-line);
124
+ padding: 0 var(--ss-input-px);
125
+ transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
126
+ }
127
+ .ss-datefield .control:focus-within {
128
+ border-color: var(--ss-primary);
129
+ box-shadow: 0 0 0 3px var(--ss-primary-soft);
130
+ }
131
+ .ss-datefield.invalid .control {
132
+ border-color: var(--ss-red);
133
+ }
134
+ .ss-datefield.invalid .control:focus-within {
135
+ border-color: var(--ss-red);
136
+ box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
137
+ }
138
+ .ss-datefield.disabled .control {
139
+ border-color: var(--ss-line);
140
+ }
141
+ .ss-datefield .msg {
142
+ font-family: var(--ss-font-mono);
143
+ font-size: var(--ss-ui-xs);
144
+ letter-spacing: 0.02em;
145
+ }
146
+ .ss-datefield .msg.hint {
147
+ color: var(--ss-fg-faint);
148
+ }
149
+ .ss-datefield .msg.error {
150
+ color: var(--ss-red);
151
+ }
152
+
153
+ .field {
154
+ font-family: var(--ss-font-body);
155
+ font-size: var(--ss-input-font);
156
+ background: transparent;
157
+ color: var(--ss-fg);
158
+ border: none;
159
+ padding: var(--ss-input-py) 0;
160
+ width: 100%;
161
+ min-width: 0;
162
+ transition: color var(--ss-dur-fast) var(--ss-ease);
163
+ }
164
+ .field:focus {
165
+ outline: none;
166
+ }
167
+ .field[readonly] {
168
+ color: var(--ss-fg-muted);
169
+ cursor: default;
170
+ }
171
+ .field:disabled {
172
+ color: var(--ss-fg-faint);
173
+ cursor: not-allowed;
174
+ -webkit-text-fill-color: var(--ss-fg-faint);
175
+ }
176
+ .field::-webkit-calendar-picker-indicator {
177
+ filter: var(--ss-datefield-indicator-filter, invert(0.7));
178
+ opacity: var(--ss-datefield-indicator-opacity, 0.7);
179
+ cursor: pointer;
180
+ transition: opacity var(--ss-dur-fast) var(--ss-ease);
181
+ }
182
+ .field:hover::-webkit-calendar-picker-indicator {
183
+ opacity: 1;
184
+ }
185
+ .field:disabled::-webkit-calendar-picker-indicator {
186
+ cursor: not-allowed;
187
+ opacity: 0.35;
188
+ }</style>
@@ -0,0 +1,37 @@
1
+ import { type Size } from '../config.js';
2
+ interface Props {
3
+ label?: string;
4
+ id?: string;
5
+ name?: string;
6
+ /** Bindable ISO date string (`yyyy-mm-dd`). */
7
+ value?: string;
8
+ /** Earliest selectable date (ISO `yyyy-mm-dd`); forwarded to the native input. */
9
+ min?: string;
10
+ /** Latest selectable date (ISO `yyyy-mm-dd`); forwarded to the native input. */
11
+ max?: string;
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
+ /** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
21
+ describedby?: string;
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
+ onchange?: (e: Event & {
27
+ currentTarget: HTMLInputElement;
28
+ }) => void;
29
+ oninput?: (e: Event & {
30
+ currentTarget: HTMLInputElement;
31
+ }) => void;
32
+ /** Any remaining native input attributes / event handlers are forwarded. */
33
+ [key: string]: unknown;
34
+ }
35
+ declare const DateField: import("svelte").Component<Props, {}, "value">;
36
+ type DateField = ReturnType<typeof DateField>;
37
+ export default DateField;
@@ -0,0 +1,355 @@
1
+ <script lang="ts">
2
+ import { resolveComponentSize, type Size } from '../config.js'
3
+
4
+ interface Props {
5
+ /** Field label, doubles as part of the drop zone's accessible name. */
6
+ label?: string
7
+ /** Native accept filter (e.g. 'application/json,.json'); also enforced on drop. */
8
+ accept?: string
9
+ /** Allow selecting/dropping more than one file. Default false. */
10
+ multiple?: boolean
11
+ /** Disables pointer + keyboard activation and mutes the chrome. */
12
+ disabled?: boolean
13
+ /** Token size (sm|md|lg); inherits the global size when unset. */
14
+ size?: Size
15
+ /** Supplementary helper text rendered under the zone. */
16
+ hint?: string
17
+ /** Error text rendered under the zone; announced to AT via role="alert". */
18
+ error?: string
19
+ /** Selected files. Bindable. */
20
+ files?: File[]
21
+ /** Fired with the resolved file list whenever the selection changes. */
22
+ onfiles?: (files: File[]) => void
23
+ }
24
+ let {
25
+ label,
26
+ accept,
27
+ multiple = false,
28
+ disabled = false,
29
+ size,
30
+ hint,
31
+ error,
32
+ files = $bindable([]),
33
+ onfiles,
34
+ }: Props = $props()
35
+
36
+ const uid = $props.id()
37
+ const inputId = `${uid}-input`
38
+ const hintId = `${uid}-hint`
39
+ const errorId = `${uid}-error`
40
+
41
+ const describedBy = $derived(
42
+ [error ? errorId : null, hint ? hintId : null].filter(Boolean).join(' ') || undefined,
43
+ )
44
+ const resolvedSize = $derived(resolveComponentSize('FileDrop', size))
45
+
46
+ // The zone's accessible name: explicit label, else a sensible default; hint
47
+ // is folded in for extra context when present.
48
+ const accName = $derived(
49
+ [label || 'Upload files', hint].filter(Boolean).join('. ') || 'Upload files',
50
+ )
51
+
52
+ let inputEl = $state<HTMLInputElement>()
53
+ let dragging = $state(false)
54
+
55
+ /** Human-readable byte size (1 KB = 1024 B). */
56
+ function humanSize(bytes: number): string {
57
+ if (bytes < 1024) return `${bytes} B`
58
+ const units = ['KB', 'MB', 'GB', 'TB']
59
+ let v = bytes / 1024
60
+ let i = 0
61
+ while (v >= 1024 && i < units.length - 1) {
62
+ v /= 1024
63
+ i++
64
+ }
65
+ return `${v.toFixed(v < 10 ? 1 : 0)} ${units[i]}`
66
+ }
67
+
68
+ /** Does a file satisfy the `accept` filter? Empty accept matches everything. */
69
+ function matchesAccept(file: File): boolean {
70
+ if (!accept) return true
71
+ const name = file.name.toLowerCase()
72
+ const type = file.type.toLowerCase()
73
+ return accept
74
+ .split(',')
75
+ .map((t) => t.trim().toLowerCase())
76
+ .filter(Boolean)
77
+ .some((token) => {
78
+ if (token.startsWith('.')) return name.endsWith(token)
79
+ if (token.endsWith('/*')) return type.startsWith(token.slice(0, -1))
80
+ return type === token
81
+ })
82
+ }
83
+
84
+ /** Apply accept/multiple, update state, notify. */
85
+ function applyFiles(list: File[]) {
86
+ if (disabled) return
87
+ let next = list.filter(matchesAccept)
88
+ if (!multiple) next = next.slice(0, 1)
89
+ files = next
90
+ onfiles?.(next)
91
+ }
92
+
93
+ function openPicker() {
94
+ if (disabled) return
95
+ inputEl?.click()
96
+ }
97
+
98
+ function onKeydown(e: KeyboardEvent) {
99
+ if (disabled) return
100
+ if (e.key === 'Enter' || e.key === ' ') {
101
+ e.preventDefault()
102
+ openPicker()
103
+ }
104
+ }
105
+
106
+ function onChange(e: Event & { currentTarget: HTMLInputElement }) {
107
+ applyFiles(Array.from(e.currentTarget.files ?? []))
108
+ }
109
+
110
+ function onDragOver(e: DragEvent) {
111
+ if (disabled) return
112
+ e.preventDefault()
113
+ dragging = true
114
+ }
115
+
116
+ function onDragLeave(e: DragEvent) {
117
+ if (disabled) return
118
+ e.preventDefault()
119
+ dragging = false
120
+ }
121
+
122
+ function onDrop(e: DragEvent) {
123
+ if (disabled) return
124
+ e.preventDefault()
125
+ dragging = false
126
+ applyFiles(Array.from(e.dataTransfer?.files ?? []))
127
+ }
128
+
129
+ function removeAt(index: number) {
130
+ if (disabled) return
131
+ const next = files.filter((_, i) => i !== index)
132
+ files = next
133
+ onfiles?.(next)
134
+ }
135
+
136
+ function clear() {
137
+ if (disabled) return
138
+ files = []
139
+ if (inputEl) inputEl.value = ''
140
+ onfiles?.([])
141
+ }
142
+ </script>
143
+
144
+ <div class="ss-filedrop" data-size-variant={resolvedSize} class:invalid={!!error} class:disabled>
145
+ {#if label}
146
+ <span class="lbl" id={`${uid}-label`}>{label}</span>
147
+ {/if}
148
+
149
+ <input
150
+ bind:this={inputEl}
151
+ class="native"
152
+ id={inputId}
153
+ type="file"
154
+ {accept}
155
+ {multiple}
156
+ {disabled}
157
+ tabindex="-1"
158
+ aria-hidden="true"
159
+ onchange={onChange}
160
+ />
161
+ <div
162
+ class="zone"
163
+ class:dragging
164
+ role="button"
165
+ tabindex={disabled ? -1 : 0}
166
+ aria-label={accName}
167
+ aria-disabled={disabled || undefined}
168
+ aria-describedby={describedBy}
169
+ onclick={openPicker}
170
+ onkeydown={onKeydown}
171
+ ondragover={onDragOver}
172
+ ondragenter={onDragOver}
173
+ ondragleave={onDragLeave}
174
+ ondrop={onDrop}
175
+ >
176
+ <span class="prompt">
177
+ <span class="title">Drop files here</span>
178
+ <span class="sub">or click to browse</span>
179
+ </span>
180
+ </div>
181
+
182
+ {#if files.length}
183
+ <ul class="files">
184
+ {#each files as file, i (file.name + i)}
185
+ <li class="file">
186
+ <span class="name">{file.name}</span>
187
+ <span class="bytes">{humanSize(file.size)}</span>
188
+ <button
189
+ type="button"
190
+ class="remove"
191
+ aria-label={`Remove ${file.name}`}
192
+ {disabled}
193
+ onclick={() => removeAt(i)}>×</button
194
+ >
195
+ </li>
196
+ {/each}
197
+ </ul>
198
+ <button type="button" class="clear" {disabled} onclick={clear}>Clear</button>
199
+ {/if}
200
+
201
+ {#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
202
+ {#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
203
+ </div>
204
+
205
+ <style>.ss-filedrop {
206
+ display: flex;
207
+ flex-direction: column;
208
+ gap: 6px;
209
+ }
210
+ .ss-filedrop .lbl {
211
+ font-family: var(--ss-font-mono);
212
+ font-size: var(--ss-ui-xs);
213
+ color: var(--ss-fg-muted);
214
+ text-transform: uppercase;
215
+ letter-spacing: 0.08em;
216
+ }
217
+ .ss-filedrop .zone {
218
+ position: relative;
219
+ display: flex;
220
+ align-items: center;
221
+ justify-content: center;
222
+ text-align: center;
223
+ min-height: var(--ss-filedrop-min-h, 96px);
224
+ padding: var(--ss-filedrop-py, var(--ss-s-4, 16px)) var(--ss-filedrop-px, var(--ss-s-3, 12px));
225
+ background: transparent;
226
+ color: var(--ss-fg);
227
+ border: 1px dashed var(--ss-line);
228
+ cursor: pointer;
229
+ transition: border-color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease);
230
+ }
231
+ .ss-filedrop .zone:focus-visible {
232
+ outline: 2px solid var(--ss-primary);
233
+ outline-offset: 2px;
234
+ }
235
+ .ss-filedrop .zone.dragging {
236
+ border-color: var(--ss-primary);
237
+ background: var(--ss-primary-soft);
238
+ }
239
+ .ss-filedrop .native {
240
+ position: absolute;
241
+ width: 1px;
242
+ height: 1px;
243
+ padding: 0;
244
+ margin: -1px;
245
+ overflow: hidden;
246
+ clip: rect(0 0 0 0);
247
+ white-space: nowrap;
248
+ border: 0;
249
+ }
250
+ .ss-filedrop .prompt {
251
+ display: flex;
252
+ flex-direction: column;
253
+ gap: var(--ss-gap-sm, 4px);
254
+ pointer-events: none;
255
+ }
256
+ .ss-filedrop .prompt .title {
257
+ font-family: var(--ss-font-body);
258
+ font-size: var(--ss-input-font);
259
+ color: var(--ss-fg);
260
+ }
261
+ .ss-filedrop .prompt .sub {
262
+ font-family: var(--ss-font-mono);
263
+ font-size: var(--ss-ui-xs);
264
+ color: var(--ss-fg-faint);
265
+ }
266
+ .ss-filedrop .files {
267
+ list-style: none;
268
+ margin: 0;
269
+ padding: 0;
270
+ display: flex;
271
+ flex-direction: column;
272
+ gap: var(--ss-gap-sm, 4px);
273
+ }
274
+ .ss-filedrop .file {
275
+ display: flex;
276
+ align-items: center;
277
+ gap: var(--ss-gap-sm, 4px);
278
+ font-family: var(--ss-font-mono);
279
+ font-size: var(--ss-ui-xs);
280
+ color: var(--ss-fg);
281
+ border: 1px solid var(--ss-line);
282
+ padding: var(--ss-filedrop-file-py, 4px) var(--ss-filedrop-file-px, 8px);
283
+ }
284
+ .ss-filedrop .file .name {
285
+ flex: 1 1 auto;
286
+ min-width: 0;
287
+ overflow: hidden;
288
+ text-overflow: ellipsis;
289
+ white-space: nowrap;
290
+ }
291
+ .ss-filedrop .file .bytes {
292
+ flex: none;
293
+ color: var(--ss-fg-faint);
294
+ }
295
+ .ss-filedrop .file .remove {
296
+ flex: none;
297
+ }
298
+ .ss-filedrop .remove,
299
+ .ss-filedrop .clear {
300
+ font-family: var(--ss-font-body);
301
+ background: transparent;
302
+ border: none;
303
+ color: var(--ss-fg-faint);
304
+ padding: 0;
305
+ cursor: pointer;
306
+ line-height: 1;
307
+ transition: color var(--ss-dur-fast) var(--ss-ease);
308
+ }
309
+ .ss-filedrop .remove:hover,
310
+ .ss-filedrop .clear:hover {
311
+ color: var(--ss-fg);
312
+ }
313
+ .ss-filedrop .remove:focus-visible,
314
+ .ss-filedrop .clear:focus-visible {
315
+ outline: 2px solid var(--ss-primary);
316
+ outline-offset: 2px;
317
+ color: var(--ss-fg);
318
+ }
319
+ .ss-filedrop .clear {
320
+ align-self: flex-start;
321
+ font-family: var(--ss-font-mono);
322
+ font-size: var(--ss-ui-xs);
323
+ text-transform: uppercase;
324
+ letter-spacing: 0.08em;
325
+ }
326
+ .ss-filedrop .msg {
327
+ font-family: var(--ss-font-mono);
328
+ font-size: var(--ss-ui-xs);
329
+ letter-spacing: 0.02em;
330
+ }
331
+ .ss-filedrop .msg.hint {
332
+ color: var(--ss-fg-faint);
333
+ }
334
+ .ss-filedrop .msg.error {
335
+ color: var(--ss-red);
336
+ }
337
+ .ss-filedrop.invalid .zone {
338
+ border-color: var(--ss-red);
339
+ }
340
+ .ss-filedrop.invalid .zone:focus-visible {
341
+ outline-color: var(--ss-red);
342
+ }
343
+ .ss-filedrop.disabled .zone {
344
+ cursor: not-allowed;
345
+ color: var(--ss-fg-faint);
346
+ border-color: var(--ss-line);
347
+ }
348
+ .ss-filedrop.disabled .zone .title {
349
+ color: var(--ss-fg-faint);
350
+ }
351
+ .ss-filedrop.disabled .remove,
352
+ .ss-filedrop.disabled .clear {
353
+ cursor: not-allowed;
354
+ color: var(--ss-fg-faint);
355
+ }</style>
@@ -0,0 +1,24 @@
1
+ import { type Size } from '../config.js';
2
+ interface Props {
3
+ /** Field label, doubles as part of the drop zone's accessible name. */
4
+ label?: string;
5
+ /** Native accept filter (e.g. 'application/json,.json'); also enforced on drop. */
6
+ accept?: string;
7
+ /** Allow selecting/dropping more than one file. Default false. */
8
+ multiple?: boolean;
9
+ /** Disables pointer + keyboard activation and mutes the chrome. */
10
+ disabled?: boolean;
11
+ /** Token size (sm|md|lg); inherits the global size when unset. */
12
+ size?: Size;
13
+ /** Supplementary helper text rendered under the zone. */
14
+ hint?: string;
15
+ /** Error text rendered under the zone; announced to AT via role="alert". */
16
+ error?: string;
17
+ /** Selected files. Bindable. */
18
+ files?: File[];
19
+ /** Fired with the resolved file list whenever the selection changes. */
20
+ onfiles?: (files: File[]) => void;
21
+ }
22
+ declare const FileDrop: import("svelte").Component<Props, {}, "files">;
23
+ type FileDrop = ReturnType<typeof FileDrop>;
24
+ export default FileDrop;