@xerios/design-system 0.1.1 → 0.1.3

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 (47) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +12 -8
  3. package/dist/components/Button.svelte +0 -7
  4. package/dist/components/Button.svelte.d.ts +1 -13
  5. package/dist/components/CollapsibleAdvanced.svelte +1 -1
  6. package/dist/components/Dialogs.svelte +12 -0
  7. package/dist/components/WorkingBorder.svelte +10 -8
  8. package/dist/components/empty/EmptyError.svelte +61 -12
  9. package/dist/components/empty/EmptyError.svelte.d.ts +2 -1
  10. package/dist/components/filters/FilterChip.svelte +2 -2
  11. package/dist/components/filters/OptionList.svelte +29 -13
  12. package/dist/components/filters/Panel.svelte +1 -1
  13. package/dist/components/icons.d.ts +3 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/inputs/ButtonGroup.svelte +4 -1
  16. package/dist/components/inputs/Calendar.svelte +232 -172
  17. package/dist/components/inputs/Calendar.svelte.d.ts +2 -0
  18. package/dist/components/inputs/DateField.svelte +209 -92
  19. package/dist/components/inputs/DateField.svelte.d.ts +16 -10
  20. package/dist/components/inputs/DateInput.svelte +22 -9
  21. package/dist/components/inputs/DateInput.svelte.d.ts +3 -0
  22. package/dist/components/inputs/DatePicker.svelte +63 -38
  23. package/dist/components/inputs/DatePicker.svelte.d.ts +5 -2
  24. package/dist/components/inputs/DateRangePicker.svelte +69 -39
  25. package/dist/components/inputs/DateRangePicker.svelte.d.ts +5 -2
  26. package/dist/components/inputs/DateRangeSelect.svelte +26 -25
  27. package/dist/components/inputs/RadioGroup.svelte +3 -1
  28. package/dist/components/inputs/Segmented.svelte +4 -1
  29. package/dist/components/inputs/Select.svelte +18 -8
  30. package/dist/components/inputs/TextArea.svelte +1 -1
  31. package/dist/components/scroll/ScrollButton.svelte +260 -0
  32. package/dist/components/scroll/ScrollButton.svelte.d.ts +61 -0
  33. package/dist/components/scroll/ScrollMore.svelte +57 -0
  34. package/dist/components/scroll/ScrollMore.svelte.d.ts +28 -0
  35. package/dist/components/scroll/ScrollToTop.svelte +57 -0
  36. package/dist/components/scroll/ScrollToTop.svelte.d.ts +22 -0
  37. package/dist/css/atoms.css +13 -9
  38. package/dist/css/base.css +1 -2
  39. package/dist/css/effects.css +259 -16
  40. package/dist/css/tokens.css +99 -72
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.js +3 -0
  43. package/dist/lib/dates.d.ts +38 -5
  44. package/dist/lib/dates.js +88 -19
  45. package/dist/lib/edge-glow.d.ts +11 -0
  46. package/dist/lib/edge-glow.js +251 -0
  47. package/package.json +5 -3
@@ -8,9 +8,12 @@ export function addDays(day: string, n: number): string;
8
8
  export function addMonths(day: string, n: number): string;
9
9
  /** The first day of the week where the user is: 1 Monday (the default) … 7 Sunday, as Intl reports it. */
10
10
  export function firstDayOfWeek(): any;
11
- /** The weeks to draw for a month: 6 rows of 7 ISO days, starting on the locale's first day of the week.
12
- * @param {string} month any day in it */
13
- export function monthGrid(month: string): string[][];
11
+ /** The days of the weekend where the user is, 1 Monday … 7 Sunday, as Intl reports it (default Saturday and Sunday). */
12
+ export function weekendDays(): number[];
13
+ /** The weeks to draw for a month: 6 rows of 7 ISO days, starting on weekStart (1 Monday … 7 Sunday; by default the
14
+ * locale's first day of the week).
15
+ * @param {string} month any day in it @param {number} [weekStart] */
16
+ export function monthGrid(month: string, weekStart?: number): string[][];
14
17
  /** The day of `days` nearest before (or on) `day`, else the first after it; null when `days` is empty.
15
18
  * @param {string} day @param {string[]} days */
16
19
  export function nearest(day: string, days: string[]): string | null;
@@ -57,6 +60,34 @@ export function formatWhen(value: string, { time, year }?: {
57
60
  time?: boolean;
58
61
  year?: boolean;
59
62
  }): string;
63
+ /**
64
+ * A day or moment for reading, with the month's short name: '18 Nov', '18 Nov 2025' (the year only when it isn't this
65
+ * year), '18 Nov 15:30' for a moment (its time where the user is). time: false leaves a moment's time out; year: true or
66
+ * false forces the year in or out.
67
+ * @param {string} value @param {{ time?: boolean, year?: boolean }} [show]
68
+ */
69
+ export function formatShort(value: string, { time, year }?: {
70
+ time?: boolean;
71
+ year?: boolean;
72
+ }): string;
73
+ /**
74
+ * A span of days or moments for reading, as short as it can be said, the month by its short name and what both ends
75
+ * share written once:
76
+ * '18 Nov' one day
77
+ * '3–18 Nov' one month
78
+ * '28 Oct – 3 Nov' one year
79
+ * '28 Dec 2025 – 3 Jan 2026' across years
80
+ * '14:30–16:00 18 Nov' one day, two times
81
+ * '17 Nov 14:30 – 18 Nov 09:00' times on different days
82
+ * The year shows once, at the end, when both ends are in the same year but not this one; on both when they differ.
83
+ * time(value): whether to show that end's time (moments only); by default every moment's. year: true shows the year
84
+ * even when it is this one ('3–18 Nov 2026'). One end empty: 'From 3 Nov', 'Until 18 Nov'; both: ''.
85
+ * @param {string} from @param {string} to @param {{ time?: (value: string) => boolean, year?: boolean }} [show]
86
+ */
87
+ export function formatSpan(from: string, to: string, { time, year }?: {
88
+ time?: (value: string) => boolean;
89
+ year?: boolean;
90
+ }): string;
60
91
  /**
61
92
  * Splits days or moments, in their order (either way), into a run per month, wherever the month or the year differs
62
93
  * from the date before: [{ key: '2026-11', label, items: [{ item, index }] }]. label: the month in full, with the
@@ -84,8 +115,10 @@ export function inputFormat(): {
84
115
  /** A day as it is typed, DD/MM/YYYY ('18/11/2026'). @param {string} day */
85
116
  export function formatInput(day: string): string;
86
117
  /**
87
- * Reads a typed date: ISO ('2026-11-18'), or three numbers as day, month, year with any separators ('18/11/2026',
88
- * '18.11.26', '18 11 2026'). A two-digit year is this century. Returns the ISO day, or null if it isn't a real date.
118
+ * Reads a typed date with any-date-parser: numbers day first, whatever the locale ('18/11/2026', '18.11.26',
119
+ * '18 11 2026', '18/11' for this year), ISO ('2026-11-18'), month names ('18 Nov 2026', 'November 18', in English or
120
+ * the user's language) and words ('today', 'tomorrow', '3 days ago'). A missing year is this year. Returns the ISO
121
+ * day, or null if it isn't a real date.
89
122
  * @param {string} text
90
123
  */
91
124
  export function parseInput(text: string): string | null;
package/dist/lib/dates.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // Calendar dates for the pickers, as ISO strings ('2026-11-18'): a day, not an instant, so no time zone can move it.
2
2
  // All arithmetic runs in UTC; nothing here reads the local clock except today().
3
3
 
4
+ import { attempt } from 'any-date-parser'
4
5
  import { runs } from './runs.js'
5
6
 
6
7
  /** @param {string | null | undefined} iso @returns {Date | null} */
@@ -54,11 +55,23 @@ export function firstDayOfWeek() {
54
55
  }
55
56
  }
56
57
 
57
- /** The weeks to draw for a month: 6 rows of 7 ISO days, starting on the locale's first day of the week.
58
- * @param {string} month any day in it */
59
- export function monthGrid(month) {
58
+ /** The days of the weekend where the user is, 1 Monday … 7 Sunday, as Intl reports it (default Saturday and Sunday). */
59
+ export function weekendDays() {
60
+ try {
61
+ const locale = /** @type {any} */ (new Intl.Locale(navigator.language))
62
+ const info = locale.getWeekInfo?.() ?? locale.weekInfo
63
+ return /** @type {number[]} */ (info?.weekend ?? [6, 7])
64
+ } catch {
65
+ return [6, 7]
66
+ }
67
+ }
68
+
69
+ /** The weeks to draw for a month: 6 rows of 7 ISO days, starting on weekStart (1 Monday … 7 Sunday; by default the
70
+ * locale's first day of the week).
71
+ * @param {string} month any day in it @param {number} [weekStart] */
72
+ export function monthGrid(month, weekStart = firstDayOfWeek()) {
60
73
  const first = monthOf(month)
61
- const start = ((firstDayOfWeek() % 7) + 7) % 7 // Intl's 7 (Sunday) is getUTCDay's 0
74
+ const start = ((weekStart % 7) + 7) % 7 // Intl's 7 (Sunday) is getUTCDay's 0
62
75
  const lead = (weekday(first) - start + 7) % 7
63
76
  const from = addDays(first, -lead)
64
77
  return Array.from({ length: 6 }, (_week, w) => Array.from({ length: 7 }, (_day, d) => addDays(from, w * 7 + d)))
@@ -167,6 +180,63 @@ export function formatWhen(value, { time = true, year = true } = {}) {
167
180
  const date = value.length > 10 && time ? new Date(value) : null
168
181
  return date && !Number.isNaN(date.getTime()) ? `${text} ${pad(date.getHours())}:${pad(date.getMinutes())}` : text
169
182
  }
183
+ /** Whether a value is an ISO moment (with a time) rather than a day. @param {string} value */
184
+ const isMoment = (value) => value.length > 10 && !Number.isNaN(new Date(value).getTime())
185
+ /** A moment's time where the user is ('15:30'). @param {string} value */
186
+ const timeOf = (value) => {
187
+ const date = new Date(value)
188
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}`
189
+ }
190
+ /** The month's short name in the user's language ('Nov'). @param {string} day */
191
+ const shortMonth = (day) => new Intl.DateTimeFormat(undefined, { ...utc, month: 'short' }).format(parse(monthOf(day)) ?? undefined)
192
+ /** '3 Nov', from an ISO day. @param {string} day */
193
+ const dayMonth = (day) => `${Number(day.slice(8, 10))} ${shortMonth(day)}`
194
+
195
+ /**
196
+ * A day or moment for reading, with the month's short name: '18 Nov', '18 Nov 2025' (the year only when it isn't this
197
+ * year), '18 Nov 15:30' for a moment (its time where the user is). time: false leaves a moment's time out; year: true or
198
+ * false forces the year in or out.
199
+ * @param {string} value @param {{ time?: boolean, year?: boolean }} [show]
200
+ */
201
+ export function formatShort(value, { time = true, year } = {}) {
202
+ const day = dayOf(value)
203
+ const withYear = year ?? day.slice(0, 4) !== today().slice(0, 4)
204
+ const text = `${dayMonth(day)}${withYear ? ` ${day.slice(0, 4)}` : ''}`
205
+ return time && isMoment(value) ? `${text} ${timeOf(value)}` : text
206
+ }
207
+
208
+ /**
209
+ * A span of days or moments for reading, as short as it can be said, the month by its short name and what both ends
210
+ * share written once:
211
+ * '18 Nov' one day
212
+ * '3–18 Nov' one month
213
+ * '28 Oct – 3 Nov' one year
214
+ * '28 Dec 2025 – 3 Jan 2026' across years
215
+ * '14:30–16:00 18 Nov' one day, two times
216
+ * '17 Nov 14:30 – 18 Nov 09:00' times on different days
217
+ * The year shows once, at the end, when both ends are in the same year but not this one; on both when they differ.
218
+ * time(value): whether to show that end's time (moments only); by default every moment's. year: true shows the year
219
+ * even when it is this one ('3–18 Nov 2026'). One end empty: 'From 3 Nov', 'Until 18 Nov'; both: ''.
220
+ * @param {string} from @param {string} to @param {{ time?: (value: string) => boolean, year?: boolean }} [show]
221
+ */
222
+ export function formatSpan(from, to, { time = () => true, year = false } = {}) {
223
+ if (!from || !to) return from ? `From ${formatShort(from, { year: year || undefined })}` : to ? `Until ${formatShort(to, { year: year || undefined })}` : ''
224
+ const [a, b] = [dayOf(from), dayOf(to)]
225
+ const [yearA, yearB] = [a.slice(0, 4), b.slice(0, 4)]
226
+ const yearAtEnd = year || yearA !== yearB || yearB !== today().slice(0, 4)
227
+ const end = yearAtEnd ? ` ${yearB}` : ''
228
+ const [timeA, timeB] = [isMoment(from) && time(from), isMoment(to) && time(to)]
229
+ if (a === b) {
230
+ if (timeA && timeB && timeOf(from) !== timeOf(to)) return `${timeOf(from)}–${timeOf(to)} ${dayMonth(b)}${end}`
231
+ return `${dayMonth(b)}${end}${timeA || timeB ? ` ${timeOf(timeA ? from : to)}` : ''}`
232
+ }
233
+ const first = formatShort(from, { time: timeA, year: yearA !== yearB })
234
+ const last = formatShort(to, { time: timeB, year: yearAtEnd })
235
+ if (timeA || timeB || yearA !== yearB) return `${first} – ${last}`
236
+ if (a.slice(5, 7) === b.slice(5, 7)) return `${Number(a.slice(8, 10))}–${last}`
237
+ return `${first} – ${last}`
238
+ }
239
+
170
240
  /**
171
241
  * Splits days or moments, in their order (either way), into a run per month, wherever the month or the year differs
172
242
  * from the date before: [{ key: '2026-11', label, items: [{ item, index }] }]. label: the month in full, with the
@@ -211,25 +281,24 @@ export function formatInput(day) {
211
281
  }
212
282
 
213
283
  /**
214
- * Reads a typed date: ISO ('2026-11-18'), or three numbers as day, month, year with any separators ('18/11/2026',
215
- * '18.11.26', '18 11 2026'). A two-digit year is this century. Returns the ISO day, or null if it isn't a real date.
284
+ * Reads a typed date with any-date-parser: numbers day first, whatever the locale ('18/11/2026', '18.11.26',
285
+ * '18 11 2026', '18/11' for this year), ISO ('2026-11-18'), month names ('18 Nov 2026', 'November 18', in English or
286
+ * the user's language) and words ('today', 'tomorrow', '3 days ago'). A missing year is this year. Returns the ISO
287
+ * day, or null if it isn't a real date.
216
288
  * @param {string} text
217
289
  */
218
290
  export function parseInput(text) {
219
291
  const typed = text.trim()
220
292
  if (!typed) return null
221
- if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(typed)) {
222
- const [y, m, d] = typed.split('-')
223
- return parse(`${y}-${m.padStart(2, '0')}-${d.padStart(2, '0')}`) ? `${y}-${m.padStart(2, '0')}-${d.padStart(2, '0')}` : null
293
+ // en-GB reads numbers day first, as the placeholder asks; the user's own locale then catches month names in their
294
+ // language.
295
+ const locales = new Set(['en-GB', ...(typeof navigator === 'undefined' ? [] : [navigator.language])])
296
+ for (const locale of locales) {
297
+ const got = attempt(typed, locale)
298
+ if (got.invalid || !got.day || !got.month) continue
299
+ const year = got.year ?? Number(today().slice(0, 4))
300
+ const day = `${String(year).padStart(4, '0')}-${pad(got.month)}-${pad(got.day)}`
301
+ return parse(day) ? day : null
224
302
  }
225
- const numbers = typed.split(/\D+/).filter(Boolean)
226
- if (numbers.length !== 3) return null
227
- const { order } = inputFormat()
228
- /** @type {Record<string, string>} */
229
- const got = Object.fromEntries(order.map((part, i) => [part, numbers[i]]))
230
- let year = got.year
231
- if (year.length <= 2) year = String(2000 + Number(year))
232
- if (year.length !== 4) return null
233
- const day = `${year}-${got.month.padStart(2, '0')}-${got.day.padStart(2, '0')}`
234
- return parse(day) ? day : null
303
+ return null
235
304
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @param {HTMLElement | Window | string} area
3
+ * @param {{ side?: Side, duration?: number, announce?: string }} [opts]
4
+ * @returns {() => void} stop: fades it out
5
+ */
6
+ export function edgeGlow(area: HTMLElement | Window | string, { side, duration, announce }?: {
7
+ side?: Side;
8
+ duration?: number;
9
+ announce?: string;
10
+ }): () => void;
11
+ export type Side = "below" | "above";
@@ -0,0 +1,251 @@
1
+ // New-content glow: a soft metallic glow on a scroll area's bottom or top edge, with ripples spreading out of it, to say
2
+ // something new arrived past it (a message below, newer items above). Louder than scrollFade's quiet "there's more", and only for a while.
3
+ // Styles live in css/effects.css (.edge-glow). Call it right after adding the content, as spotlight() is called:
4
+ //
5
+ // messages.push(message)
6
+ // edgeGlow(list) // glows below for 3s, or until scrolled to the bottom
7
+ // edgeGlow('feed', { side: 'above', announce: '3 new items above' })
8
+ // const stop = edgeGlow(window, { duration: Infinity }) // held until scrolled to the end, or stop()
9
+ //
10
+ // area: the scroll area: an element, its id, or window (the page). side: 'below' (default) | 'above'.
11
+ // duration: how long the ripples keep coming, in ms (default 3000); Infinity keeps them until the edge is reached or
12
+ // stop() is called. The line on the edge lasts as long as they do; the glow on the edge fades well before, after
13
+ // --edge-glow-hold (default 1200ms).
14
+ // announce: text for screen readers (the polite live region, lib/announce.js); the glow itself is decorative.
15
+ //
16
+ // It waits a tick for the new content to be drawn, then does nothing if the area is already at that edge (the new
17
+ // content is in view). Otherwise it ends early once the area is scrolled to that edge. Ending, the glow on the edge
18
+ // fades (if it hasn't yet), no new ripples start, the rings under way spread out to their end, and the line on the edge
19
+ // fades out as they do.
20
+ // Calling it again for the same area and side while it shows keeps the one glow, lights the edge again and starts its
21
+ // time again. Returns stop(), which ends it that way.
22
+ //
23
+ // The glow is an overlay in the top layer (inside the open dialog that holds the area, so it shows over it), laid over
24
+ // the area's visible box, so the area's own mask (scrollFade) doesn't fade it, and it never adds to the content. Under
25
+ // reduced motion there are no ripples: a still glow on the edge comes and goes.
26
+
27
+ import { tick } from 'svelte'
28
+ import { observeSize } from './observe.js'
29
+ import { announce as say } from './announce.js'
30
+
31
+ /** @typedef {'below' | 'above'} Side */
32
+ /** How many ripples it lays: they take turns, each a third of a ring's spread after the last (css/effects.css). */
33
+ const RINGS = 3
34
+
35
+ /** Live glows, by area and side, so a second call refreshes the first. @type {WeakMap<HTMLElement | Window, Map<Side, { refresh: () => void, stop: () => void }>>} */
36
+ const live = new WeakMap()
37
+
38
+ const reduced = () => typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
39
+ /** The longest an ending can take (the edge's fade, 700ms, or a ring's spread, 2400ms, in css/effects.css), with room. */
40
+ const ENDING = 3000
41
+
42
+ /** A node's CSS animations by name. @param {Element} node @param {string} name */
43
+ const animations = (node, name, subtree = false) =>
44
+ node.getAnimations({ subtree }).filter((a) => /** @type {CSSAnimation} */ (a).animationName === name)
45
+
46
+ /** @param {HTMLElement | Window | string} area */
47
+ function resolve(area) {
48
+ const el = typeof area === 'string' ? document.getElementById(area) : area
49
+ if (!el) return null
50
+ if (el === document.body || el === document.documentElement || el === document.scrollingElement) return window
51
+ return el
52
+ }
53
+
54
+ /**
55
+ * @param {HTMLElement | Window | string} area
56
+ * @param {{ side?: Side, duration?: number, announce?: string }} [opts]
57
+ * @returns {() => void} stop: fades it out
58
+ */
59
+ export function edgeGlow(area, { side = 'below', duration = 3000, announce } = {}) {
60
+ let cancelled = false
61
+ /** @type {() => void} */
62
+ let stopNow = () => {
63
+ cancelled = true
64
+ }
65
+ const stop = () => stopNow()
66
+
67
+ tick().then(() => {
68
+ if (cancelled) return
69
+ const scroller = resolve(area)
70
+ if (!scroller) return
71
+ if (announce) say(announce)
72
+
73
+ const existing = live.get(scroller)?.get(side)
74
+ if (existing) {
75
+ existing.refresh()
76
+ stopNow = existing.stop
77
+ return
78
+ }
79
+ stopNow = show(scroller, side, duration)
80
+ })
81
+ return stop
82
+ }
83
+
84
+ /**
85
+ * Lays the overlay and keeps it on the area's edge. Returns its stop.
86
+ * @param {HTMLElement | Window} scroller
87
+ * @param {Side} side
88
+ * @param {number} duration
89
+ */
90
+ function show(scroller, side, duration) {
91
+ const win = scroller === window
92
+ const box = win ? document.documentElement : /** @type {HTMLElement} */ (scroller)
93
+
94
+ /** Whether the area is at the edge the glow is about, so what arrived there is in view. */
95
+ const atEdge = () => {
96
+ const top = win ? window.scrollY : box.scrollTop
97
+ return side === 'below' ? box.scrollHeight - box.clientHeight - top <= 1 : top <= 1
98
+ }
99
+ if (atEdge()) return () => {}
100
+
101
+ const el = document.createElement('span')
102
+ el.className = `edge-glow ${side}`
103
+ // The glow on the edge (the bloom is its pseudo-element), which fades first; the ripples and the line on the edge (the
104
+ // overlay's own pseudo-element) outlast it.
105
+ const main = document.createElement('span')
106
+ main.className = 'edge-glow-main'
107
+ const waves = document.createElement('span')
108
+ waves.className = 'edge-glow-waves'
109
+ waves.style.setProperty('--n', String(RINGS))
110
+ for (let i = 0; i < RINGS; i++) {
111
+ const wave = document.createElement('span')
112
+ wave.className = 'edge-glow-wave'
113
+ wave.style.setProperty('--i', String(i))
114
+ waves.append(wave)
115
+ }
116
+ el.append(main, waves)
117
+ el.setAttribute('aria-hidden', 'true')
118
+ el.setAttribute('popover', 'manual')
119
+ el.setAttribute('data-top-layer', '')
120
+ if (!win) {
121
+ // Its reach and hold, if the area sets them (the overlay isn't inside it, so doesn't inherit them), and its corners.
122
+ const cs = getComputedStyle(box)
123
+ for (const prop of ['--edge-glow-size', '--edge-glow-hold']) {
124
+ const value = cs.getPropertyValue(prop).trim()
125
+ if (value) el.style.setProperty(prop, value)
126
+ }
127
+ el.style.borderRadius = cs.borderRadius
128
+ }
129
+ const host = (win ? null : box.closest('dialog[open]')) ?? document.body
130
+ host.append(el)
131
+ el.showPopover?.()
132
+
133
+ // The area's visible box, inside its border and clear of its scrollbars.
134
+ const place = () => {
135
+ if (win) {
136
+ Object.assign(el.style, { top: '0px', left: '0px', width: `${box.clientWidth}px`, height: `${window.innerHeight}px` })
137
+ return
138
+ }
139
+ const r = box.getBoundingClientRect()
140
+ Object.assign(el.style, {
141
+ top: `${r.top + box.clientTop}px`,
142
+ left: `${r.left + box.clientLeft}px`,
143
+ width: `${box.clientWidth}px`,
144
+ height: `${box.clientHeight}px`,
145
+ })
146
+ }
147
+ let frame = 0
148
+ const schedule = () => {
149
+ frame ||= requestAnimationFrame(() => {
150
+ frame = 0
151
+ place()
152
+ })
153
+ }
154
+ const scrolled = () => {
155
+ if (atEdge()) leave()
156
+ }
157
+ place()
158
+
159
+ // Any scroll can move the area (the page, a panel around it); its own also checks whether the edge was reached.
160
+ document.addEventListener('scroll', schedule, { capture: true, passive: true })
161
+ scroller.addEventListener('scroll', scrolled, { passive: true })
162
+ window.addEventListener('resize', schedule)
163
+ const unsize = win ? () => {} : observeSize(box, schedule)
164
+
165
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
166
+ let timer
167
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
168
+ let fallback
169
+ /** Set while it ends, and changed by a refresh, so an ending it interrupted doesn't remove it. */
170
+ let ending = 0
171
+ /** The edge's fade, its hold, and the ripples, kept from the first ending: a cancelled animation leaves the element's list. */
172
+ /** @type {Animation | undefined} */
173
+ let fade
174
+ let hold = 0
175
+ /** @type {Animation[]} */
176
+ let rings = []
177
+ const arm = () => {
178
+ clearTimeout(timer)
179
+ if (Number.isFinite(duration)) timer = setTimeout(leave, duration)
180
+ }
181
+
182
+ function remove() {
183
+ clearTimeout(timer)
184
+ clearTimeout(fallback)
185
+ cancelAnimationFrame(frame)
186
+ document.removeEventListener('scroll', schedule, { capture: true })
187
+ scroller.removeEventListener('scroll', scrolled)
188
+ window.removeEventListener('resize', schedule)
189
+ unsize()
190
+ el.remove()
191
+ const sides = live.get(scroller)
192
+ sides?.delete(side)
193
+ if (sides?.size === 0) live.delete(scroller)
194
+ }
195
+ function leave() {
196
+ if (ending || !el.isConnected) return
197
+ clearTimeout(timer)
198
+ if (!fade) {
199
+ fade = animations(main, 'edge-glow-out')[0]
200
+ hold = Number(fade?.effect?.getTiming().delay) || 0
201
+ rings = animations(el, 'edge-glow-ripple', true)
202
+ }
203
+ // Reduced motion: nothing runs, so there is nothing to finish.
204
+ if (reduced() || (!fade && !rings.length)) return remove()
205
+ const token = (ending = performance.now())
206
+
207
+ // The glow on the edge fades from now, if it is still holding.
208
+ const at = Number(fade?.currentTime) || 0
209
+ if (fade && at < hold) fade.effect?.updateTiming({ delay: at })
210
+ // Each ring spreading finishes its spread; the ones still waiting to start don't. The line fades over the time the
211
+ // last one has left, so it goes out with it.
212
+ let left = 0
213
+ for (const ring of rings) {
214
+ const timing = ring.effect?.getComputedTiming()
215
+ if (!timing || timing.currentIteration == null || Number(timing.localTime) < Number(timing.delay)) ring.cancel()
216
+ else {
217
+ ring.effect?.updateTiming({ iterations: timing.currentIteration + 1 })
218
+ const after = ring.effect?.getComputedTiming()
219
+ left = Math.max(left, Number(after?.endTime) - Number(after?.localTime) || 0)
220
+ }
221
+ }
222
+ el.style.setProperty('--edge-glow-line-out', `${Math.max(300, Math.round(left))}ms`)
223
+ el.setAttribute('data-ending', '')
224
+ const end = () => {
225
+ if (ending === token) remove()
226
+ }
227
+ Promise.all([fade, ...rings].map((a) => a?.finished.catch(() => {}))).then(end)
228
+ fallback = setTimeout(end, ENDING)
229
+ }
230
+ /** Lights the edge again and keeps the ripples coming, from the start of its time. */
231
+ function refresh() {
232
+ ending = 0
233
+ clearTimeout(fallback)
234
+ el.removeAttribute('data-ending')
235
+ if (fade) {
236
+ fade.effect?.updateTiming({ delay: hold })
237
+ fade.currentTime = 0
238
+ fade.play()
239
+ }
240
+ for (const ring of rings) {
241
+ ring.effect?.updateTiming({ iterations: Infinity })
242
+ if (ring.playState !== 'running') ring.play()
243
+ }
244
+ arm()
245
+ }
246
+
247
+ if (!live.has(scroller)) live.set(scroller, new Map())
248
+ live.get(scroller)?.set(side, { refresh, stop: leave })
249
+ arm()
250
+ return leave
251
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xerios/design-system",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Linear-style design system for Svelte 5: theme tokens, global CSS and generic components",
5
5
  "keywords": [
6
6
  "svelte",
@@ -19,7 +19,8 @@
19
19
  "bugs": "https://github.com/Xerios/design-system/issues",
20
20
  "type": "module",
21
21
  "files": [
22
- "dist"
22
+ "dist",
23
+ "CHANGELOG.md"
23
24
  ],
24
25
  "sideEffects": [
25
26
  "./dist/fonts.js",
@@ -51,7 +52,8 @@
51
52
  },
52
53
  "dependencies": {
53
54
  "@fontsource-variable/inter": "^5.3.0",
54
- "@fontsource-variable/jetbrains-mono": "^5.3.0"
55
+ "@fontsource-variable/jetbrains-mono": "^5.3.0",
56
+ "any-date-parser": "^2.2.4"
55
57
  },
56
58
  "peerDependencies": {
57
59
  "svelte": "^5.29.0"