@xerios/design-system 0.0.0-stage → 0.1.1

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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -2
  3. package/dist/components/AnchorHeading.svelte +79 -0
  4. package/dist/components/AnchorHeading.svelte.d.ts +28 -0
  5. package/dist/components/Breadcrumbs.svelte +216 -0
  6. package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
  7. package/dist/components/Button.svelte +185 -0
  8. package/dist/components/Button.svelte.d.ts +70 -0
  9. package/dist/components/Canvas.svelte +248 -0
  10. package/dist/components/Canvas.svelte.d.ts +91 -0
  11. package/dist/components/Collapsible.svelte +139 -0
  12. package/dist/components/Collapsible.svelte.d.ts +52 -0
  13. package/dist/components/CollapsibleAdvanced.svelte +174 -0
  14. package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
  15. package/dist/components/DashOutline.svelte +47 -0
  16. package/dist/components/DashOutline.svelte.d.ts +6 -0
  17. package/dist/components/Dialogs.svelte +123 -0
  18. package/dist/components/Dialogs.svelte.d.ts +6 -0
  19. package/dist/components/Drawer.svelte +231 -0
  20. package/dist/components/Drawer.svelte.d.ts +62 -0
  21. package/dist/components/ErrorMessage.svelte +140 -0
  22. package/dist/components/ErrorMessage.svelte.d.ts +41 -0
  23. package/dist/components/Icon.svelte +94 -0
  24. package/dist/components/Icon.svelte.d.ts +33 -0
  25. package/dist/components/InfoTip.svelte +183 -0
  26. package/dist/components/InfoTip.svelte.d.ts +28 -0
  27. package/dist/components/Md.svelte +28 -0
  28. package/dist/components/Md.svelte.d.ts +11 -0
  29. package/dist/components/Modal.svelte +91 -0
  30. package/dist/components/Modal.svelte.d.ts +41 -0
  31. package/dist/components/Notice.svelte +50 -0
  32. package/dist/components/Notice.svelte.d.ts +30 -0
  33. package/dist/components/Popover.svelte +212 -0
  34. package/dist/components/Popover.svelte.d.ts +70 -0
  35. package/dist/components/Shimmer.svelte +27 -0
  36. package/dist/components/Shimmer.svelte.d.ts +22 -0
  37. package/dist/components/Splitter.svelte +152 -0
  38. package/dist/components/Splitter.svelte.d.ts +41 -0
  39. package/dist/components/Table.svelte +448 -0
  40. package/dist/components/Table.svelte.d.ts +268 -0
  41. package/dist/components/Toast.svelte +273 -0
  42. package/dist/components/Toast.svelte.d.ts +31 -0
  43. package/dist/components/Tooltip.svelte +97 -0
  44. package/dist/components/Tooltip.svelte.d.ts +19 -0
  45. package/dist/components/WorkingBorder.svelte +105 -0
  46. package/dist/components/WorkingBorder.svelte.d.ts +26 -0
  47. package/dist/components/empty/Empty.svelte +55 -0
  48. package/dist/components/empty/Empty.svelte.d.ts +39 -0
  49. package/dist/components/empty/EmptyError.svelte +47 -0
  50. package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
  51. package/dist/components/empty/index.d.ts +18 -0
  52. package/dist/components/empty/index.js +10 -0
  53. package/dist/components/filters/DateFilter.svelte +59 -0
  54. package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
  55. package/dist/components/filters/FilterBar.svelte +401 -0
  56. package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
  57. package/dist/components/filters/FilterChip.svelte +235 -0
  58. package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
  59. package/dist/components/filters/OptionList.svelte +352 -0
  60. package/dist/components/filters/OptionList.svelte.d.ts +91 -0
  61. package/dist/components/filters/Panel.svelte +123 -0
  62. package/dist/components/filters/Panel.svelte.d.ts +25 -0
  63. package/dist/components/filters/index.d.ts +288 -0
  64. package/dist/components/filters/index.js +12 -0
  65. package/dist/components/icons.d.ts +54 -0
  66. package/dist/components/icons.js +58 -0
  67. package/dist/components/inputs/ButtonGroup.svelte +110 -0
  68. package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
  69. package/dist/components/inputs/Calendar.svelte +535 -0
  70. package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
  71. package/dist/components/inputs/DateField.svelte +247 -0
  72. package/dist/components/inputs/DateField.svelte.d.ts +74 -0
  73. package/dist/components/inputs/DateInput.svelte +118 -0
  74. package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
  75. package/dist/components/inputs/DatePicker.svelte +102 -0
  76. package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
  77. package/dist/components/inputs/DateRangePicker.svelte +208 -0
  78. package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
  79. package/dist/components/inputs/DateRangeSelect.svelte +548 -0
  80. package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
  81. package/dist/components/inputs/FieldLabel.svelte +43 -0
  82. package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
  83. package/dist/components/inputs/ListSearch.svelte +142 -0
  84. package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
  85. package/dist/components/inputs/RadioGroup.svelte +151 -0
  86. package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
  87. package/dist/components/inputs/RangeShortcuts.svelte +90 -0
  88. package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
  89. package/dist/components/inputs/RangeSlider.svelte +225 -0
  90. package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
  91. package/dist/components/inputs/SearchField.svelte +24 -0
  92. package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
  93. package/dist/components/inputs/Segmented.svelte +79 -0
  94. package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
  95. package/dist/components/inputs/Select.svelte +552 -0
  96. package/dist/components/inputs/Select.svelte.d.ts +100 -0
  97. package/dist/components/inputs/Slider.svelte +177 -0
  98. package/dist/components/inputs/Slider.svelte.d.ts +33 -0
  99. package/dist/components/inputs/SliderTicks.svelte +62 -0
  100. package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
  101. package/dist/components/inputs/Switch.svelte +120 -0
  102. package/dist/components/inputs/Switch.svelte.d.ts +31 -0
  103. package/dist/components/inputs/TagInput.svelte +296 -0
  104. package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
  105. package/dist/components/inputs/TextArea.svelte +86 -0
  106. package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
  107. package/dist/components/inputs/TextField.svelte +170 -0
  108. package/dist/components/inputs/TextField.svelte.d.ts +80 -0
  109. package/dist/components/menu/ContextMenu.svelte +25 -0
  110. package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
  111. package/dist/components/menu/MenuButton.svelte +46 -0
  112. package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
  113. package/dist/components/menu/MenuList.svelte +319 -0
  114. package/dist/components/menu/MenuList.svelte.d.ts +30 -0
  115. package/dist/components/metadata/Metadata.svelte +38 -0
  116. package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
  117. package/dist/components/metadata/MetadataRow.svelte +84 -0
  118. package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
  119. package/dist/components/metadata/index.d.ts +8 -0
  120. package/dist/components/metadata/index.js +13 -0
  121. package/dist/components/side-menu/SideMenu.svelte +138 -0
  122. package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
  123. package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
  124. package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
  125. package/dist/components/side-menu/SideMenuItem.svelte +221 -0
  126. package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
  127. package/dist/components/side-menu/context.d.ts +1 -0
  128. package/dist/components/side-menu/context.js +3 -0
  129. package/dist/components/side-menu/index.d.ts +62 -0
  130. package/dist/components/side-menu/index.js +15 -0
  131. package/dist/components/tiles/Tile.svelte +419 -0
  132. package/dist/components/tiles/Tile.svelte.d.ts +58 -0
  133. package/dist/components/tiles/TileGroup.svelte +135 -0
  134. package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
  135. package/dist/components/tiles/context.d.ts +35 -0
  136. package/dist/components/tiles/context.js +14 -0
  137. package/dist/components/tiles/index.d.ts +6 -0
  138. package/dist/components/tiles/index.js +13 -0
  139. package/dist/components/upload/FileCard.svelte +301 -0
  140. package/dist/components/upload/FileCard.svelte.d.ts +127 -0
  141. package/dist/components/upload/Thumb.svelte +274 -0
  142. package/dist/components/upload/Thumb.svelte.d.ts +101 -0
  143. package/dist/components/upload/UploadFile.svelte +123 -0
  144. package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
  145. package/dist/components/upload/UploadFiles.svelte +177 -0
  146. package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
  147. package/dist/components/upload/UploadFolder.svelte +153 -0
  148. package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
  149. package/dist/components/upload/UploadImage.svelte +137 -0
  150. package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
  151. package/dist/components/upload/UploadImages.svelte +172 -0
  152. package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
  153. package/dist/components/upload/UploadZone.svelte +130 -0
  154. package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
  155. package/dist/components/upload/common.d.ts +31 -0
  156. package/dist/components/upload/common.js +103 -0
  157. package/dist/components/upload/context.d.ts +18 -0
  158. package/dist/components/upload/context.js +10 -0
  159. package/dist/components/upload/index.d.ts +16 -0
  160. package/dist/components/upload/index.js +18 -0
  161. package/dist/css/atoms.css +899 -0
  162. package/dist/css/base.css +334 -0
  163. package/dist/css/effects.css +430 -0
  164. package/dist/css/index.css +10 -0
  165. package/dist/css/tokens.css +296 -0
  166. package/dist/fonts.d.ts +1 -0
  167. package/dist/fonts.js +7 -0
  168. package/dist/index.d.ts +68 -0
  169. package/dist/index.js +77 -0
  170. package/dist/lib/announce.d.ts +8 -0
  171. package/dist/lib/announce.js +48 -0
  172. package/dist/lib/controls.d.ts +10 -0
  173. package/dist/lib/controls.js +42 -0
  174. package/dist/lib/dates.d.ts +104 -0
  175. package/dist/lib/dates.js +235 -0
  176. package/dist/lib/dialogs.svelte.d.ts +8 -0
  177. package/dist/lib/dialogs.svelte.js +45 -0
  178. package/dist/lib/dom.d.ts +34 -0
  179. package/dist/lib/dom.js +90 -0
  180. package/dist/lib/field-errors.svelte.d.ts +40 -0
  181. package/dist/lib/field-errors.svelte.js +89 -0
  182. package/dist/lib/files.d.ts +74 -0
  183. package/dist/lib/files.js +215 -0
  184. package/dist/lib/inline-md.d.ts +1 -0
  185. package/dist/lib/inline-md.js +36 -0
  186. package/dist/lib/invalid.d.ts +4 -0
  187. package/dist/lib/invalid.js +35 -0
  188. package/dist/lib/list-search.d.ts +9 -0
  189. package/dist/lib/list-search.js +27 -0
  190. package/dist/lib/menu.svelte.d.ts +39 -0
  191. package/dist/lib/menu.svelte.js +98 -0
  192. package/dist/lib/morph.svelte.d.ts +17 -0
  193. package/dist/lib/morph.svelte.js +46 -0
  194. package/dist/lib/motion.d.ts +115 -0
  195. package/dist/lib/motion.js +174 -0
  196. package/dist/lib/observe.d.ts +36 -0
  197. package/dist/lib/observe.js +142 -0
  198. package/dist/lib/reveal.d.ts +7 -0
  199. package/dist/lib/reveal.js +28 -0
  200. package/dist/lib/roving.d.ts +16 -0
  201. package/dist/lib/roving.js +35 -0
  202. package/dist/lib/runs.d.ts +18 -0
  203. package/dist/lib/runs.js +25 -0
  204. package/dist/lib/scroll-fade.d.ts +4 -0
  205. package/dist/lib/scroll-fade.js +71 -0
  206. package/dist/lib/spotlight.d.ts +4 -0
  207. package/dist/lib/spotlight.js +109 -0
  208. package/dist/lib/ticks.d.ts +12 -0
  209. package/dist/lib/ticks.js +24 -0
  210. package/dist/lib/tooltip.d.ts +4 -0
  211. package/dist/lib/tooltip.js +110 -0
  212. package/dist/lib/validity.d.ts +16 -0
  213. package/dist/lib/validity.js +36 -0
  214. package/package.json +69 -3
@@ -0,0 +1,104 @@
1
+ /** @param {string | null | undefined} iso @returns {Date | null} */
2
+ export function parse(iso: string | null | undefined): Date | null;
3
+ /** Today where the user is, as an ISO day. */
4
+ export function today(): string;
5
+ /** @param {string} day @param {number} n */
6
+ export function addDays(day: string, n: number): string;
7
+ /** The same day n months on, or the month's last day when it has fewer (31 Jan + 1 month = 28 Feb). @param {string} day @param {number} n */
8
+ export function addMonths(day: string, n: number): string;
9
+ /** The first day of the week where the user is: 1 Monday (the default) … 7 Sunday, as Intl reports it. */
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[][];
14
+ /** The day of `days` nearest before (or on) `day`, else the first after it; null when `days` is empty.
15
+ * @param {string} day @param {string[]} days */
16
+ export function nearest(day: string, days: string[]): string | null;
17
+ /**
18
+ * Ready-made spans for DateRangePicker, ending today: [{ label, range() }], range() giving [from, to].
19
+ * @returns {{ label: string, range: () => [string, string] }[]}
20
+ */
21
+ export function rangeShortcuts(): {
22
+ label: string;
23
+ range: () => [string, string];
24
+ }[];
25
+ /**
26
+ * Ready-made spans for DateRangeSelect, over its dates (oldest first): [{ label, range(dates) }], range giving
27
+ * [from, to], or null when the dates don't have it. "This month" goes by the local day (dayOf).
28
+ * @returns {{ label: string, range: (dates: string[]) => [string, string] | null }[]}
29
+ */
30
+ export function dateListShortcuts(): {
31
+ label: string;
32
+ range: (dates: string[]) => [string, string] | null;
33
+ }[];
34
+ /**
35
+ * A day relative to today, from an id such as '-3d' (3 days ago), '-2w' (2 weeks ago), '-1m' (a month ago) or '+1d'
36
+ * (tomorrow); an ISO day is returned as it is; null for anything else. What a date filter stores when it means "3 days
37
+ * ago" rather than a fixed day, so the filter stays true to its label as the days pass.
38
+ * @param {string} id
39
+ * @returns {string | null}
40
+ */
41
+ export function relativeDay(id: string): string | null;
42
+ /**
43
+ * Ready-made relative days for a date filter (FilterBar): [{ value, label }], value an id for relativeDay.
44
+ * @returns {{ value: string, label: string }[]}
45
+ */
46
+ export function datePresets(): {
47
+ value: string;
48
+ label: string;
49
+ }[];
50
+ /** The ISO day a value falls on where the user is: a day as it is, an ISO moment ('2026-11-18T23:30:00Z') by the
51
+ * local clock. @param {string} value */
52
+ export function dayOf(value: string): string;
53
+ /** A day as DD/MM/YYYY ('18/11/2026') or, for an ISO moment, with the time where the user is ('18/11/2026 15:30').
54
+ * time: false leaves a moment's time out; year: false leaves the year out ('18/11').
55
+ * @param {string} value @param {{ time?: boolean, year?: boolean }} [show] */
56
+ export function formatWhen(value: string, { time, year }?: {
57
+ time?: boolean;
58
+ year?: boolean;
59
+ }): string;
60
+ /**
61
+ * Splits days or moments, in their order (either way), into a run per month, wherever the month or the year differs
62
+ * from the date before: [{ key: '2026-11', label, items: [{ item, index }] }]. label: the month in full, with the
63
+ * year unless it is this year ('November', 'December 2025'). Moments go by their local day (dayOf).
64
+ * @param {string[]} values
65
+ */
66
+ export function monthRuns(values: string[]): {
67
+ key: string;
68
+ items: {
69
+ item: string;
70
+ index: number;
71
+ }[];
72
+ label: string;
73
+ }[];
74
+ /**
75
+ * How dates are typed: day, month, year with slashes ('18/11/2026'), whatever the locale (its order differs between
76
+ * countries, so 11/12 would read two ways), and a placeholder spelling it out ('DD/MM/YYYY').
77
+ * @returns {{ order: ('day' | 'month' | 'year')[], sep: string, placeholder: string }}
78
+ */
79
+ export function inputFormat(): {
80
+ order: ("day" | "month" | "year")[];
81
+ sep: string;
82
+ placeholder: string;
83
+ };
84
+ /** A day as it is typed, DD/MM/YYYY ('18/11/2026'). @param {string} day */
85
+ export function formatInput(day: string): string;
86
+ /**
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.
89
+ * @param {string} text
90
+ */
91
+ export function parseInput(text: string): string | null;
92
+ export function iso(date: Date): string;
93
+ export function monthOf(day: string): string;
94
+ export function weekday(day: string): number;
95
+ export function compare(a: string, b: string): 0 | 1 | -1;
96
+ export function within(day: string, min: string | null | undefined, max: string | null | undefined): boolean;
97
+ export function clamp(day: string, min: string | null | undefined, max: string | null | undefined): string;
98
+ export function formatDay(day: string): string;
99
+ export function speakDay(day: string): string;
100
+ export function formatMonth(day: string): string;
101
+ export function weekdayNames(week: string[]): {
102
+ short: string;
103
+ long: string;
104
+ }[];
@@ -0,0 +1,235 @@
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
+ // All arithmetic runs in UTC; nothing here reads the local clock except today().
3
+
4
+ import { runs } from './runs.js'
5
+
6
+ /** @param {string | null | undefined} iso @returns {Date | null} */
7
+ export function parse(iso) {
8
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso ?? '')
9
+ if (!m) return null
10
+ const date = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3]))
11
+ // 2026-02-31 is not a day.
12
+ return date.getUTCMonth() === +m[2] - 1 ? date : null
13
+ }
14
+
15
+ /** @param {Date} date */
16
+ export const iso = (date) => date.toISOString().slice(0, 10)
17
+
18
+ /** Today where the user is, as an ISO day. */
19
+ export function today() {
20
+ const now = new Date()
21
+ return iso(new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate())))
22
+ }
23
+
24
+ /** @param {string} day @param {number} n */
25
+ export function addDays(day, n) {
26
+ const date = /** @type {Date} */ (parse(day))
27
+ date.setUTCDate(date.getUTCDate() + n)
28
+ return iso(date)
29
+ }
30
+
31
+ /** The same day n months on, or the month's last day when it has fewer (31 Jan + 1 month = 28 Feb). @param {string} day @param {number} n */
32
+ export function addMonths(day, n) {
33
+ const date = /** @type {Date} */ (parse(day))
34
+ const target = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + n, 1))
35
+ const last = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate()
36
+ target.setUTCDate(Math.min(date.getUTCDate(), last))
37
+ return iso(target)
38
+ }
39
+
40
+ /** The first of the day's month. @param {string} day */
41
+ export const monthOf = (day) => `${day.slice(0, 7)}-01`
42
+
43
+ /** 0 Sunday … 6 Saturday. @param {string} day */
44
+ export const weekday = (day) => /** @type {Date} */ (parse(day)).getUTCDay()
45
+
46
+ /** The first day of the week where the user is: 1 Monday (the default) … 7 Sunday, as Intl reports it. */
47
+ export function firstDayOfWeek() {
48
+ try {
49
+ const locale = /** @type {any} */ (new Intl.Locale(navigator.language))
50
+ const info = locale.getWeekInfo?.() ?? locale.weekInfo
51
+ return info?.firstDay ?? 1
52
+ } catch {
53
+ return 1
54
+ }
55
+ }
56
+
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) {
60
+ const first = monthOf(month)
61
+ const start = ((firstDayOfWeek() % 7) + 7) % 7 // Intl's 7 (Sunday) is getUTCDay's 0
62
+ const lead = (weekday(first) - start + 7) % 7
63
+ const from = addDays(first, -lead)
64
+ return Array.from({ length: 6 }, (_week, w) => Array.from({ length: 7 }, (_day, d) => addDays(from, w * 7 + d)))
65
+ }
66
+
67
+ /** @param {string} a @param {string} b */
68
+ export const compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0)
69
+
70
+ /** @param {string} day @param {string | null | undefined} min @param {string | null | undefined} max */
71
+ export const within = (day, min, max) => (!min || day >= min) && (!max || day <= max)
72
+
73
+ /** @param {string} day @param {string | null | undefined} min @param {string | null | undefined} max */
74
+ export const clamp = (day, min, max) => (min && day < min ? min : max && day > max ? max : day)
75
+
76
+ /** The day of `days` nearest before (or on) `day`, else the first after it; null when `days` is empty.
77
+ * @param {string} day @param {string[]} days */
78
+ export function nearest(day, days) {
79
+ const sorted = days.toSorted(compare)
80
+ return sorted.findLast((d) => d <= day) ?? sorted[0] ?? null
81
+ }
82
+
83
+ /**
84
+ * Ready-made spans for DateRangePicker, ending today: [{ label, range() }], range() giving [from, to].
85
+ * @returns {{ label: string, range: () => [string, string] }[]}
86
+ */
87
+ export function rangeShortcuts() {
88
+ const now = today()
89
+ /** The last n days, today included. @param {number} n @returns {[string, string]} */
90
+ const last = (n) => [addDays(now, 1 - n), now]
91
+ return [
92
+ { label: 'Last 7 days', range: () => last(7) },
93
+ { label: 'Last 30 days', range: () => last(30) },
94
+ { label: 'Last 60 days', range: () => last(60) },
95
+ { label: 'Last 90 days', range: () => last(90) },
96
+ { label: 'This year', range: () => [`${now.slice(0, 4)}-01-01`, now] },
97
+ ]
98
+ }
99
+
100
+ /** From the first to the last of some dates (sorted), or null for none. @param {string[]} dates @returns {[string, string] | null} */
101
+ const span = (dates) => (dates.length ? [dates[0], /** @type {string} */ (dates.at(-1))] : null)
102
+
103
+ /**
104
+ * Ready-made spans for DateRangeSelect, over its dates (oldest first): [{ label, range(dates) }], range giving
105
+ * [from, to], or null when the dates don't have it. "This month" goes by the local day (dayOf).
106
+ * @returns {{ label: string, range: (dates: string[]) => [string, string] | null }[]}
107
+ */
108
+ export function dateListShortcuts() {
109
+ const month = today().slice(0, 7)
110
+ return [
111
+ { label: 'Most recent', range: (dates) => span(dates.slice(-1)) },
112
+ { label: 'Last 3', range: (dates) => (dates.length >= 3 ? span(dates.slice(-3)) : null) },
113
+ { label: 'This month', range: (dates) => span(dates.filter((d) => dayOf(d).startsWith(month))) },
114
+ ]
115
+ }
116
+
117
+ /**
118
+ * A day relative to today, from an id such as '-3d' (3 days ago), '-2w' (2 weeks ago), '-1m' (a month ago) or '+1d'
119
+ * (tomorrow); an ISO day is returned as it is; null for anything else. What a date filter stores when it means "3 days
120
+ * ago" rather than a fixed day, so the filter stays true to its label as the days pass.
121
+ * @param {string} id
122
+ * @returns {string | null}
123
+ */
124
+ export function relativeDay(id) {
125
+ if (parse(id)) return id
126
+ const m = /^([+-]\d+)([dwm])$/.exec(id ?? '')
127
+ if (!m) return null
128
+ const n = Number(m[1])
129
+ return m[2] === 'm' ? addMonths(today(), n) : addDays(today(), m[2] === 'w' ? n * 7 : n)
130
+ }
131
+
132
+ /**
133
+ * Ready-made relative days for a date filter (FilterBar): [{ value, label }], value an id for relativeDay.
134
+ * @returns {{ value: string, label: string }[]}
135
+ */
136
+ export function datePresets() {
137
+ return [
138
+ { value: '-1d', label: '1 day ago' },
139
+ { value: '-3d', label: '3 days ago' },
140
+ { value: '-1w', label: '1 week ago' },
141
+ { value: '-2w', label: '2 weeks ago' },
142
+ { value: '-1m', label: '1 month ago' },
143
+ { value: '-3m', label: '3 months ago' },
144
+ ]
145
+ }
146
+
147
+ const utc = { timeZone: 'UTC' }
148
+ /** '18 Nov 2026' in the user's language. @param {string} day */
149
+ export const formatDay = (day) => new Intl.DateTimeFormat(undefined, { ...utc, dateStyle: 'medium' }).format(parse(day) ?? undefined)
150
+ /** 'Wednesday 18 November 2026', for screen readers. @param {string} day */
151
+ export const speakDay = (day) => new Intl.DateTimeFormat(undefined, { ...utc, dateStyle: 'full' }).format(parse(day) ?? undefined)
152
+ /** @param {number} n */
153
+ const pad = (n) => String(n).padStart(2, '0')
154
+ /** The ISO day a value falls on where the user is: a day as it is, an ISO moment ('2026-11-18T23:30:00Z') by the
155
+ * local clock. @param {string} value */
156
+ export function dayOf(value) {
157
+ const date = value.length > 10 ? new Date(value) : null
158
+ if (!date || Number.isNaN(date.getTime())) return value.slice(0, 10)
159
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
160
+ }
161
+ /** A day as DD/MM/YYYY ('18/11/2026') or, for an ISO moment, with the time where the user is ('18/11/2026 15:30').
162
+ * time: false leaves a moment's time out; year: false leaves the year out ('18/11').
163
+ * @param {string} value @param {{ time?: boolean, year?: boolean }} [show] */
164
+ export function formatWhen(value, { time = true, year = true } = {}) {
165
+ const day = dayOf(value)
166
+ const text = `${day.slice(8, 10)}/${day.slice(5, 7)}${year ? `/${day.slice(0, 4)}` : ''}`
167
+ const date = value.length > 10 && time ? new Date(value) : null
168
+ return date && !Number.isNaN(date.getTime()) ? `${text} ${pad(date.getHours())}:${pad(date.getMinutes())}` : text
169
+ }
170
+ /**
171
+ * Splits days or moments, in their order (either way), into a run per month, wherever the month or the year differs
172
+ * from the date before: [{ key: '2026-11', label, items: [{ item, index }] }]. label: the month in full, with the
173
+ * year unless it is this year ('November', 'December 2025'). Moments go by their local day (dayOf).
174
+ * @param {string[]} values
175
+ */
176
+ export function monthRuns(values) {
177
+ const year = today().slice(0, 4)
178
+ return runs(values, (value) => dayOf(value).slice(0, 7)).map(({ key, items }) => ({
179
+ key,
180
+ items,
181
+ label: key.startsWith(year)
182
+ ? new Intl.DateTimeFormat(undefined, { ...utc, month: 'long' }).format(parse(`${key}-01`) ?? undefined)
183
+ : formatMonth(`${key}-01`),
184
+ }))
185
+ }
186
+ /** 'November 2026'. @param {string} day */
187
+ export const formatMonth = (day) => new Intl.DateTimeFormat(undefined, { ...utc, month: 'long', year: 'numeric' }).format(parse(day) ?? undefined)
188
+ /** Short and long weekday names for a week row of days. @param {string[]} week */
189
+ export const weekdayNames = (week) =>
190
+ week.map((day) => ({
191
+ short: new Intl.DateTimeFormat(undefined, { ...utc, weekday: 'narrow' }).format(parse(day) ?? undefined),
192
+ long: new Intl.DateTimeFormat(undefined, { ...utc, weekday: 'long' }).format(parse(day) ?? undefined),
193
+ }))
194
+
195
+ /**
196
+ * How dates are typed: day, month, year with slashes ('18/11/2026'), whatever the locale (its order differs between
197
+ * countries, so 11/12 would read two ways), and a placeholder spelling it out ('DD/MM/YYYY').
198
+ * @returns {{ order: ('day' | 'month' | 'year')[], sep: string, placeholder: string }}
199
+ */
200
+ export function inputFormat() {
201
+ return { order: ['day', 'month', 'year'], sep: '/', placeholder: 'DD/MM/YYYY' }
202
+ }
203
+
204
+ /** A day as it is typed, DD/MM/YYYY ('18/11/2026'). @param {string} day */
205
+ export function formatInput(day) {
206
+ const date = parse(day)
207
+ if (!date) return ''
208
+ const { order, sep } = inputFormat()
209
+ const value = { day: String(date.getUTCDate()).padStart(2, '0'), month: String(date.getUTCMonth() + 1).padStart(2, '0'), year: String(date.getUTCFullYear()) }
210
+ return order.map((part) => value[part]).join(sep)
211
+ }
212
+
213
+ /**
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.
216
+ * @param {string} text
217
+ */
218
+ export function parseInput(text) {
219
+ const typed = text.trim()
220
+ 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
224
+ }
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
235
+ }
@@ -0,0 +1,8 @@
1
+ /** Called by <Dialogs /> when the dialog has closed: settles the request and brings on the next. */
2
+ export function answer(result: any): void;
3
+ export namespace dialogs {
4
+ let current: null;
5
+ }
6
+ export function alertDialog(options: any): Promise<any>;
7
+ export function confirmDialog(options: any): Promise<any>;
8
+ export function promptDialog(options: any): Promise<any>;
@@ -0,0 +1,45 @@
1
+ // Promise-based stand-ins for window.alert, confirm and prompt, drawn in the design system's own modal dialog by
2
+ // <Dialogs /> (mount it once, at the root). They open above any dialog already showing, so a form underneath keeps
3
+ // its state. One shows at a time; the next waits its turn.
4
+ //
5
+ // await alertDialog({ title: 'Upload failed', body: 'The file is over 50 MB.' })
6
+ // if (await confirmDialog({ title: 'Discard changes?', confirmLabel: 'Discard', danger: true })) close()
7
+ // const name = await promptDialog({ title: 'Rename', label: 'Name', value: old, validate: (v) => (v ? '' : 'Enter a name') })
8
+ //
9
+ // A bare string is taken as the title. Esc and a backdrop click answer like the cancel button: alert resolves
10
+ // undefined, confirm false, prompt null.
11
+ //
12
+ // Options, all kinds: title, body (a paragraph under it).
13
+ // alert: okLabel ('OK').
14
+ // confirm: confirmLabel ('OK'), cancelLabel ('Cancel'), danger (red confirm button; the focus starts on cancel).
15
+ // prompt: label (the field's), value, placeholder, confirmLabel ('OK'), cancelLabel ('Cancel'),
16
+ // validate(value) → message or '' (checked on confirm only, never while typing).
17
+
18
+ /** The request on screen, if any. Read by <Dialogs />. */
19
+ export const dialogs = $state({ current: null })
20
+
21
+ const waiting = []
22
+ let seq = 0
23
+
24
+ function open(kind, options) {
25
+ const settings = typeof options === 'string' ? { title: options } : { ...options }
26
+ return new Promise((resolve) => {
27
+ waiting.push({ ...settings, kind, id: ++seq, resolve })
28
+ if (!dialogs.current) dialogs.current = waiting.shift()
29
+ })
30
+ }
31
+
32
+ /** Called by <Dialogs /> when the dialog has closed: settles the request and brings on the next. */
33
+ export function answer(result) {
34
+ const done = dialogs.current
35
+ if (!done) return
36
+ dialogs.current = waiting.shift() ?? null
37
+ done.resolve(result)
38
+ }
39
+
40
+ /** Resolves once dismissed. */
41
+ export const alertDialog = (options) => open('alert', options)
42
+ /** Resolves true when confirmed, false otherwise. */
43
+ export const confirmDialog = (options) => open('confirm', options)
44
+ /** Resolves the entered text, or null when cancelled. */
45
+ export const promptDialog = (options) => open('prompt', options)
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Handlers for a modal <dialog> (spread them onto it) that close it on a backdrop click, but only when the press both
3
+ * started and ended on the backdrop: dragging a text selection or an input's caret out of the dialog doesn't close it.
4
+ * The backdrop is told apart by where the pointer is, not only by the event's target: the dialog is the target for its
5
+ * own padding and gaps too, so a press there would otherwise count as outside.
6
+ */
7
+ export function backdropClose(close: any): {
8
+ onpointerdown: (e: any) => boolean;
9
+ onclick: (e: any) => void;
10
+ };
11
+ /**
12
+ * Handlers for a modal <dialog> whose Esc must go through `request` (to ask about unsaved work first) instead of
13
+ * closing it. Spread them next to backdropClose. Esc is taken at keydown, before the browser turns it into a close
14
+ * request: Chrome lets a page cancel that only once per user activation, and Esc is not one, so a quick second Esc
15
+ * would close the dialog regardless. Other close requests (a back gesture) still arrive as `cancel` and are held
16
+ * there, as far as the browser allows. An Esc a control inside has already handled (preventDefault) is left alone.
17
+ */
18
+ export function closeRequests(request: any): {
19
+ onkeydown: (e: any) => void;
20
+ oncancel: (e: any) => void;
21
+ };
22
+ /**
23
+ * True while the key belongs to an input method (IME) composition: Enter there confirms the composed text and Esc
24
+ * cancels it, so a field's own Enter, Esc or Backspace handling must leave the key alone. keyCode 229 covers Safari,
25
+ * which delivers compositionend before the confirming Enter (WebKit bug 165004), so isComposing is already false.
26
+ *
27
+ * function onkeydown(e) { if (composing(e)) return; if (e.key === 'Enter') … }
28
+ *
29
+ * @param {KeyboardEvent} e
30
+ */
31
+ export function composing(e: KeyboardEvent): boolean;
32
+ export function portal(node: any): () => any;
33
+ export function topLayer(from: any): (node: any) => () => any;
34
+ export function portalNear(from: any): (node: any) => () => any;
@@ -0,0 +1,90 @@
1
+ /** Small DOM helpers shared by floating and modal components. */
2
+
3
+ /** Attachment: moves the node to <body>, so scrolling, clipping or sticky ancestors can't clip or cover it. */
4
+ export const portal = (node) => {
5
+ document.body.appendChild(node)
6
+ return () => node.remove()
7
+ }
8
+
9
+ /**
10
+ * Attachment: shows a floating node in the top layer (Popover API), so it draws above modal dialogs and their backdrop,
11
+ * which no z-index can. It goes into the <dialog> around `from` if there is one (everything outside a modal dialog is
12
+ * inert, so it couldn't be pointed at, clicked or selected there), else <body>. The top layer stacks in the order things
13
+ * are shown: a layer that must sit above one shown after it has to be shown again (re-created). base.css resets the
14
+ * popover's default box on [data-top-layer]; give the node position: fixed and place it as usual.
15
+ */
16
+ export const topLayer = (from) => (node) => {
17
+ node.setAttribute('popover', 'manual')
18
+ node.setAttribute('data-top-layer', '')
19
+ ;(from?.closest('dialog') ?? document.body).appendChild(node)
20
+ node.showPopover?.()
21
+ return () => node.remove()
22
+ }
23
+
24
+ /**
25
+ * Attachment: like portal, but moves the node into the nearest [data-layer-root] ancestor of `from` (else <body>).
26
+ * Use it for layers that must stack against siblings inside an isolated container (the app shell isolates its header
27
+ * and view card, so a scrim on <body> would cover the header and the panel it opened).
28
+ */
29
+ export const portalNear = (from) => (node) => {
30
+ ;(from?.closest('[data-layer-root]') ?? document.body).appendChild(node)
31
+ return () => node.remove()
32
+ }
33
+
34
+ /** @param {MouseEvent} e */
35
+ const onBackdrop = (e) => {
36
+ if (e.target !== e.currentTarget) return false
37
+ const r = /** @type {Element} */ (e.currentTarget).getBoundingClientRect()
38
+ return e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom
39
+ }
40
+
41
+ /**
42
+ * Handlers for a modal <dialog> (spread them onto it) that close it on a backdrop click, but only when the press both
43
+ * started and ended on the backdrop: dragging a text selection or an input's caret out of the dialog doesn't close it.
44
+ * The backdrop is told apart by where the pointer is, not only by the event's target: the dialog is the target for its
45
+ * own padding and gaps too, so a press there would otherwise count as outside.
46
+ */
47
+ export function backdropClose(close) {
48
+ let downOnBackdrop = false
49
+ return {
50
+ onpointerdown: (e) => (downOnBackdrop = onBackdrop(e)),
51
+ onclick: (e) => {
52
+ if (downOnBackdrop && onBackdrop(e)) close()
53
+ downOnBackdrop = false
54
+ },
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Handlers for a modal <dialog> whose Esc must go through `request` (to ask about unsaved work first) instead of
60
+ * closing it. Spread them next to backdropClose. Esc is taken at keydown, before the browser turns it into a close
61
+ * request: Chrome lets a page cancel that only once per user activation, and Esc is not one, so a quick second Esc
62
+ * would close the dialog regardless. Other close requests (a back gesture) still arrive as `cancel` and are held
63
+ * there, as far as the browser allows. An Esc a control inside has already handled (preventDefault) is left alone.
64
+ */
65
+ export function closeRequests(request) {
66
+ return {
67
+ onkeydown: (e) => {
68
+ if (e.key !== 'Escape' || e.defaultPrevented || composing(e)) return
69
+ e.preventDefault()
70
+ request()
71
+ },
72
+ oncancel: (e) => {
73
+ e.preventDefault()
74
+ request()
75
+ },
76
+ }
77
+ }
78
+
79
+ /**
80
+ * True while the key belongs to an input method (IME) composition: Enter there confirms the composed text and Esc
81
+ * cancels it, so a field's own Enter, Esc or Backspace handling must leave the key alone. keyCode 229 covers Safari,
82
+ * which delivers compositionend before the confirming Enter (WebKit bug 165004), so isComposing is already false.
83
+ *
84
+ * function onkeydown(e) { if (composing(e)) return; if (e.key === 'Enter') … }
85
+ *
86
+ * @param {KeyboardEvent} e
87
+ */
88
+ export function composing(e) {
89
+ return e.isComposing || e.keyCode === 229
90
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The error messages of a form, field by field, with submit-first timing built in: nothing is checked until the
3
+ * form is validated (its submit or action button). After that a field is checked again when it is left, and its
4
+ * message goes as soon as it is edited. Leaving an untouched field never shows an error. Name each field once:
5
+ *
6
+ * const form = fieldErrors(() => validate(values)); // validate returns { [field]: message } for what failed
7
+ *
8
+ * <TextField bind:value={values.name} id="name" label="Name" {...form.field('name')} />
9
+ * <div {@attach form.group('address')}> …several controls sharing one check… </div>
10
+ *
11
+ * if (!form.validate()) return; // on submit: checks everything, false if anything failed
12
+ *
13
+ * field(key): props to spread on a TextField or TextArea: its `error`, plus the blur and input handlers.
14
+ * group(key): attachment for an element wrapping several controls; checks `key` when the focus leaves the
15
+ * element, clears it on any input inside. Show the messages with `error={form.errors.key}` or ErrorMessage.
16
+ * errors: the current messages (reactive). check(key) / clear(key): one field by hand, for controls that are
17
+ * not inputs. validate(): every field. set(errors): messages from elsewhere, e.g. the server. reset(): none.
18
+ *
19
+ * With a typed `validate`, the keys are checked: a misspelt field name is a type error.
20
+ *
21
+ * @template {object} E
22
+ * @param {() => E} validate
23
+ */
24
+ export function fieldErrors<E extends object>(validate: () => E): {
25
+ readonly errors: E;
26
+ check: (key: keyof E & string) => void;
27
+ clear: (key: keyof E & string) => void;
28
+ validate(): boolean;
29
+ /** @param {E | null | undefined} next */
30
+ set(next: E | null | undefined): void;
31
+ reset(): void;
32
+ /** @param {Key} key */
33
+ field(key: keyof E & string): {
34
+ error: E[keyof E & string];
35
+ onblur: () => void;
36
+ oninput: () => void;
37
+ };
38
+ /** @param {Key} key */
39
+ group(key: keyof E & string): (node: HTMLElement) => () => void;
40
+ };
@@ -0,0 +1,89 @@
1
+ import { announce, cancelAnnouncement } from './announce.js'
2
+
3
+ /**
4
+ * The error messages of a form, field by field, with submit-first timing built in: nothing is checked until the
5
+ * form is validated (its submit or action button). After that a field is checked again when it is left, and its
6
+ * message goes as soon as it is edited. Leaving an untouched field never shows an error. Name each field once:
7
+ *
8
+ * const form = fieldErrors(() => validate(values)); // validate returns { [field]: message } for what failed
9
+ *
10
+ * <TextField bind:value={values.name} id="name" label="Name" {...form.field('name')} />
11
+ * <div {@attach form.group('address')}> …several controls sharing one check… </div>
12
+ *
13
+ * if (!form.validate()) return; // on submit: checks everything, false if anything failed
14
+ *
15
+ * field(key): props to spread on a TextField or TextArea: its `error`, plus the blur and input handlers.
16
+ * group(key): attachment for an element wrapping several controls; checks `key` when the focus leaves the
17
+ * element, clears it on any input inside. Show the messages with `error={form.errors.key}` or ErrorMessage.
18
+ * errors: the current messages (reactive). check(key) / clear(key): one field by hand, for controls that are
19
+ * not inputs. validate(): every field. set(errors): messages from elsewhere, e.g. the server. reset(): none.
20
+ *
21
+ * With a typed `validate`, the keys are checked: a misspelt field name is a type error.
22
+ *
23
+ * @template {object} E
24
+ * @param {() => E} validate
25
+ */
26
+ export function fieldErrors(validate) {
27
+ /** @typedef {keyof E & string} Key */
28
+ let errors = $state(/** @type {E} */ ({}))
29
+ // Whether validate() has run since the last reset: only then does leaving a field check it.
30
+ let validated = false
31
+
32
+ /** @param {Key} key */
33
+ function check(key) {
34
+ if (!validated) return
35
+ const found = validate()[key]
36
+ // A message that appears as the field is left is read out (after a pause, so it follows the next field's name).
37
+ if (found && found !== errors[key]) announce(String(found))
38
+ if (found) errors[key] = found
39
+ else delete errors[key]
40
+ }
41
+ /** @param {Key} key */
42
+ function clear(key) {
43
+ if (errors[key]) cancelAnnouncement()
44
+ delete errors[key]
45
+ }
46
+
47
+ return {
48
+ get errors() {
49
+ return errors
50
+ },
51
+ check,
52
+ clear,
53
+ validate() {
54
+ validated = true
55
+ errors = validate()
56
+ return Object.keys(errors).length === 0
57
+ },
58
+ /** @param {E | null | undefined} next */
59
+ set(next) {
60
+ errors = next ?? /** @type {E} */ ({})
61
+ },
62
+ reset() {
63
+ validated = false
64
+ errors = /** @type {E} */ ({})
65
+ },
66
+ /** @param {Key} key */
67
+ field(key) {
68
+ return { error: errors[key], onblur: () => check(key), oninput: () => clear(key) }
69
+ },
70
+ /** @param {Key} key */
71
+ group(key) {
72
+ /** @param {HTMLElement} node */
73
+ return (node) => {
74
+ /** @param {FocusEvent} event */
75
+ const left = (event) => {
76
+ if (event.relatedTarget instanceof Node && node.contains(event.relatedTarget)) return
77
+ check(key)
78
+ }
79
+ const edited = () => clear(key)
80
+ node.addEventListener('focusout', left)
81
+ node.addEventListener('input', edited)
82
+ return () => {
83
+ node.removeEventListener('focusout', left)
84
+ node.removeEventListener('input', edited)
85
+ }
86
+ }
87
+ },
88
+ }
89
+ }