@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,535 @@
1
+ <script>
2
+ /**
3
+ * One month of days to pick from: the grid inside DatePicker and DateRangePicker (use those; this is their part).
4
+ * Days are ISO strings ('2026-11-18'), see lib/dates.js. Weeks start on the user's locale's first day.
5
+ *
6
+ * <Calendar bind:month bind:focus selected={[value]} onpick={(day) => (value = day)} label="Start date" />
7
+ *
8
+ * month (bindable): any day in the month shown. focus (bindable): the day that holds the keyboard focus.
9
+ * selected: the chosen days. range: [from, to] to tint the days between (a range picker), or null. The range is
10
+ * drawn as one bar per week (Linear's timeline bars): its ends solid, the days between tinted with the brand colour
11
+ * blending out of each end, strongest beside it. pending: the range is still being chosen, its second end following
12
+ * the pointer: only its selected end is solid, and the rest is a proposal, a dashed outline and a tint fading in from
13
+ * that end towards the other (Linear's bar tails).
14
+ * min, max: the first and last day that can be picked; others show but can't be picked.
15
+ * allowed: the only days that can be picked (within min and max), or null for every day.
16
+ * onpick(day). onpoint(day): the day under the pointer or focus, for a range picker's preview.
17
+ * autofocus: take the focus (on `focus`) when it appears. label: names the grid with the month.
18
+ * The previous / next arrows stop at the first and last page holding a day that can be picked.
19
+ * Keyboard, as the ARIA date picker grid: arrows move a day or a week, Home / End to the week's ends, PageUp /
20
+ * PageDown a month (with Shift a year), Enter or Space picks. Moving past the month turns the page.
21
+ * The month and the year in the head are buttons: they swap the grid for the twelve months, or a page of twelve
22
+ * years (picking a year then shows its months, picking a month its days). There, arrows move a cell or a row,
23
+ * PageUp / PageDown a year (or a page of years), Enter or Space picks, Esc goes back to the days.
24
+ */
25
+ import { tick } from 'svelte'
26
+ import Button from '../Button.svelte'
27
+ import DashOutline from '../DashOutline.svelte'
28
+ import { tooltip } from '../../lib/tooltip.js'
29
+ import { addDays, addMonths, monthGrid, monthOf, formatMonth, parse, speakDay, weekdayNames, within, today, compare } from '../../lib/dates.js'
30
+
31
+ /**
32
+ * @typedef {object} Props
33
+ * @property {string} month bindable
34
+ * @property {string} focus bindable
35
+ * @property {string[]} [selected]
36
+ * @property {[string, string] | null} [range]
37
+ * @property {boolean} [pending]
38
+ * @property {string | null} [min]
39
+ * @property {string | null} [max]
40
+ * @property {string[] | null} [allowed]
41
+ * @property {(day: string) => void} onpick
42
+ * @property {(day: string) => void} [onpoint]
43
+ * @property {boolean} [autofocus]
44
+ * @property {string} [label]
45
+ */
46
+ /** @type {Props} */
47
+ let {
48
+ month = $bindable(),
49
+ focus = $bindable(),
50
+ selected = [],
51
+ range = null,
52
+ pending = false,
53
+ min = null,
54
+ max = null,
55
+ allowed = null,
56
+ onpick,
57
+ onpoint,
58
+ autofocus = false,
59
+ label = '',
60
+ } = $props()
61
+
62
+ const uid = $props.id()
63
+ const now = today()
64
+ const weeks = $derived(monthGrid(month))
65
+ const names = $derived(weekdayNames(weeks[0]))
66
+ const span = $derived(range ? range.toSorted(compare) : null)
67
+ /** Days since the epoch, for counting the days in a range. @param {string} day */
68
+ const dayNumber = (day) => Date.parse(day) / 864e5
69
+ /** While pending: whether the solid (selected) end is the range's first day, so the tail runs forward. */
70
+ const fromStart = $derived(!!span && selected.includes(span[0]))
71
+ /** A range's end shown solid: both ends, or while pending only the selected one. @param {string} day */
72
+ const isEnd = (day) => !!span && (pending ? selected.includes(day) && (day === span[0] || day === span[1]) : day === span[0] || day === span[1])
73
+ /**
74
+ * How strong the brand tint is at a point t of the range (0 its first day, 1 its last), in percent: strongest beside
75
+ * the solid ends and easing off in the middle; while pending, fading in from the solid end towards the pointer.
76
+ * @param {number} t
77
+ */
78
+ const strength = (t) => (pending ? 20 * (fromStart ? t : 1 - t) : 24 - 32 * Math.min(t, 1 - t))
79
+ /** @param {number} p */
80
+ const mix = (p) => `color-mix(in srgb, var(--brand) ${Math.round(p * 10) / 10}%, transparent)`
81
+ /**
82
+ * A day's piece of the tint: a gradient from where the day before left off to where the day after picks up, so the
83
+ * pieces read as one blend along the range, week after week.
84
+ * @param {string} day
85
+ */
86
+ /**
87
+ * Where a pending day's slice of the dashed outline falls: the outline is the whole of this week's bar (from the
88
+ * range's start or the week's first day to its end or the week's last), and the day shows its own part of it, so the
89
+ * dashes run on unbroken from day to day.
90
+ * @param {string} day @param {number} col @param {number} days in the week
91
+ */
92
+ function slice(day, col, days) {
93
+ if (!span) return ''
94
+ const before = Math.min(col, dayNumber(day) - dayNumber(span[0]))
95
+ const after = Math.min(days - 1 - col, dayNumber(span[1]) - dayNumber(day))
96
+ return `--dash-x: calc(var(--day) * ${-before}); --dash-width: calc(var(--day) * ${before + after + 1}); --dash-radius: var(--r)`
97
+ }
98
+
99
+ function tint(day) {
100
+ if (!span) return undefined
101
+ const length = Math.max(1, dayNumber(span[1]) - dayNumber(span[0]))
102
+ const at = dayNumber(day) - dayNumber(span[0])
103
+ const clamp = (/** @type {number} */ t) => Math.min(1, Math.max(0, t))
104
+ return `linear-gradient(to right, ${mix(strength(clamp((at - 0.5) / length)))}, ${mix(strength(clamp((at + 0.5) / length)))})`
105
+ }
106
+ /** The allowed days within min and max, or null when every day in them is. */
107
+ const open = $derived(allowed ? allowed.filter((day) => within(day, min, max)) : null)
108
+ const openSet = $derived(open ? new Set(open) : null)
109
+ /** @param {string} day */
110
+ const can = (day) => (openSet ? openSet.has(day) : within(day, min, max))
111
+ /** @type {HTMLTableElement | undefined} */
112
+ let table = $state()
113
+ /** @type {HTMLDivElement | undefined} */
114
+ let root = $state()
115
+
116
+ /** What the grid shows: the month's days, the year's months, or a page of twelve years. */
117
+ /** @type {'days' | 'months' | 'years'} */
118
+ let view = $state('days')
119
+ /** The first year on the years page. */
120
+ let yearsFrom = $state(0)
121
+
122
+ /** @param {string} day */
123
+ const yearOf = (day) => Number(day.slice(0, 4))
124
+ /** 0 January … 11 December. @param {string} day */
125
+ const monthIndex = (day) => Number(day.slice(5, 7)) - 1
126
+ const utc = { timeZone: 'UTC' }
127
+ const monthNames = Array.from({ length: 12 }, (_m, i) => ({
128
+ short: new Intl.DateTimeFormat(undefined, { ...utc, month: 'short' }).format(Date.UTC(2026, i, 1)),
129
+ long: new Intl.DateTimeFormat(undefined, { ...utc, month: 'long' }).format(Date.UTC(2026, i, 1)),
130
+ }))
131
+ /** The month and the year as the head shows them, in the locale's order ('November', '2026'). */
132
+ const headParts = $derived(
133
+ new Intl.DateTimeFormat(undefined, { ...utc, month: 'long', year: 'numeric' })
134
+ .formatToParts(parse(month) ?? undefined)
135
+ .filter((part) => part.type === 'month' || part.type === 'year'),
136
+ )
137
+ const years = $derived(Array.from({ length: 12 }, (_y, i) => yearsFrom + i))
138
+
139
+ /** The focus day moved into month m (0–11) of year y, keeping its day where that month has it. @param {number} y @param {number} m */
140
+ const dayIn = (y, m) => addMonths(focus, (y - yearOf(focus)) * 12 + m - monthIndex(focus))
141
+ /** Whether any day of month m (0–11) of year y can be picked. @param {number} y @param {number} m */
142
+ function monthOpen(y, m) {
143
+ const first = `${y}-${String(m + 1).padStart(2, '0')}-01`
144
+ if (open) return open.some((day) => day.startsWith(first.slice(0, 8)))
145
+ return !(max && first > max) && !(min && addDays(addMonths(first, 1), -1) < min)
146
+ }
147
+ /** @param {number} y */
148
+ const yearOpen = (y) => (open ? open.some((day) => day.startsWith(`${y}-`)) : true) && !(max && `${y}-01-01` > max) && !(min && `${y}-12-31` < min)
149
+
150
+ /** Switches the grid and puts the focus on its focus cell. @param {'days' | 'months' | 'years'} next */
151
+ async function showView(next) {
152
+ if (next !== 'days') {
153
+ // The focus day may sit in a neighbouring month's overflow; bring it into the shown one.
154
+ focus = dayIn(yearOf(month), monthIndex(month))
155
+ month = monthOf(focus)
156
+ }
157
+ if (next === 'years') yearsFrom = yearOf(focus) - 4
158
+ view = next
159
+ await tick()
160
+ root?.querySelector('[tabindex="0"]')?.focus()
161
+ }
162
+
163
+ /** @param {number} m */
164
+ function pickMonth(m) {
165
+ if (!monthOpen(yearOf(month), m)) return
166
+ focus = dayIn(yearOf(month), m)
167
+ month = monthOf(focus)
168
+ void showView('days')
169
+ }
170
+ /** @param {number} y */
171
+ function pickYear(y) {
172
+ if (!yearOpen(y)) return
173
+ focus = dayIn(y, monthIndex(focus))
174
+ month = monthOf(focus)
175
+ void showView('months')
176
+ }
177
+
178
+ /** Moves the focus in the months or years grid (n months), paging the years along. @param {number} n */
179
+ async function moveCell(n) {
180
+ focus = addMonths(focus, n)
181
+ month = monthOf(focus)
182
+ const y = yearOf(focus)
183
+ if (view === 'years' && (y < yearsFrom || y >= yearsFrom + 12)) yearsFrom += Math.floor((y - yearsFrom) / 12) * 12
184
+ await tick()
185
+ root?.querySelector('[tabindex="0"]')?.focus()
186
+ }
187
+
188
+ /** @param {KeyboardEvent} e */
189
+ function onCellKey(e) {
190
+ if (e.key === 'Escape') {
191
+ e.preventDefault()
192
+ e.stopPropagation()
193
+ void showView('days')
194
+ return
195
+ }
196
+ const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -3, ArrowDown: 3, PageUp: -12, PageDown: 12 }[e.key]
197
+ if (!step) return
198
+ e.preventDefault()
199
+ void moveCell(view === 'years' ? step * 12 : step)
200
+ }
201
+
202
+ /** Moves the focus to a day, turning the page when it lies in another month. @param {string} day */
203
+ async function moveTo(day) {
204
+ focus = day
205
+ if (monthOf(day) !== monthOf(month)) month = monthOf(day)
206
+ onpoint?.(day)
207
+ await tick()
208
+ table?.querySelector(`[data-day="${day}"]`)?.focus()
209
+ }
210
+
211
+ /** The arrow buttons turn the page (a month, a year or twelve years) and keep the focus; the focus day moves with them. */
212
+ /** @param {number} n */
213
+ async function turn(n) {
214
+ if (!canTurn(n)) return
215
+ const months = view === 'days' ? n : view === 'months' ? n * 12 : n * 144
216
+ focus = addMonths(focus, months)
217
+ month = monthOf(focus)
218
+ if (view === 'years') yearsFrom += n * 12
219
+ // Reaching the limit disables the pressed arrow, which drops the focus; hand it to the other one.
220
+ if (!canTurn(n)) {
221
+ await tick()
222
+ root?.querySelector(`[data-turn="${-n}"]`)?.focus()
223
+ }
224
+ }
225
+ /** Whether the page before (-1) or after (1) holds a day that can be picked. @param {number} n */
226
+ function canTurn(n) {
227
+ if (view === 'years') return yearOpen(n < 0 ? yearsFrom - 1 : yearsFrom + 12)
228
+ if (view === 'months') return yearOpen(yearOf(month) + n)
229
+ const next = addMonths(monthOf(month), n)
230
+ return monthOpen(yearOf(next), monthIndex(next))
231
+ }
232
+ const turnLabel = $derived({ days: 'month', months: 'year', years: 'years' }[view])
233
+
234
+ /** @param {KeyboardEvent} e */
235
+ function onkeydown(e) {
236
+ const row = weeks.find((week) => week.includes(focus)) ?? weeks[0]
237
+ const next = {
238
+ ArrowLeft: () => addDays(focus, -1),
239
+ ArrowRight: () => addDays(focus, 1),
240
+ ArrowUp: () => addDays(focus, -7),
241
+ ArrowDown: () => addDays(focus, 7),
242
+ Home: () => row[0],
243
+ End: () => row[6],
244
+ PageUp: () => addMonths(focus, e.shiftKey ? -12 : -1),
245
+ PageDown: () => addMonths(focus, e.shiftKey ? 12 : 1),
246
+ }[e.key]
247
+ if (next) {
248
+ e.preventDefault()
249
+ void moveTo(next())
250
+ } else if (e.key === 'Enter' || e.key === ' ') {
251
+ e.preventDefault()
252
+ pick(focus)
253
+ }
254
+ }
255
+
256
+ /** @param {string} day */
257
+ function pick(day) {
258
+ if (!can(day)) return
259
+ focus = day
260
+ onpick(day)
261
+ }
262
+
263
+ /** Attachment: takes the focus when the calendar appears, if asked to. @param {HTMLTableElement} node */
264
+ function takeFocus(node) {
265
+ if (autofocus) void tick().then(() => node.querySelector('[tabindex="0"]')?.focus())
266
+ }
267
+ </script>
268
+
269
+ <div bind:this={root} class="calendar">
270
+ <span id="{uid}-label" class="sr-only">{label}</span>
271
+ <span id="{uid}-month" class="sr-only" aria-live="polite">{view === 'years' ? `${yearsFrom} – ${yearsFrom + 11}` : view === 'months' ? yearOf(month) : formatMonth(month)}</span>
272
+ <div class="head">
273
+ <Button iconOnly icon="caretLeft" label="Previous {turnLabel}" data-turn="-1" disabled={!canTurn(-1)} onclick={() => turn(-1)} />
274
+ <span class="title">
275
+ {#if view === 'years'}
276
+ <span class="range">{yearsFrom} – {yearsFrom + 11}</span>
277
+ {:else}
278
+ {#each headParts as part (part.type)}
279
+ {#if part.type === 'month' && view === 'days'}
280
+ <button type="button" class="pick" {@attach tooltip('Choose month')} onclick={() => showView('months')}>{part.value}</button>
281
+ {:else if part.type === 'year'}
282
+ <button type="button" class="pick" {@attach tooltip('Choose year')} onclick={() => showView('years')}>{part.value}</button>
283
+ {/if}
284
+ {/each}
285
+ {/if}
286
+ </span>
287
+ <Button iconOnly icon="caretRight" label="Next {turnLabel}" data-turn="1" disabled={!canTurn(1)} onclick={() => turn(1)} />
288
+ </div>
289
+ {#if view === 'months'}
290
+ <!-- The keys are its buttons' (arrows move between them, Esc goes back to the days). -->
291
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
292
+ <div class="cells" role="group" aria-labelledby="{uid}-label {uid}-month" onkeydown={onCellKey}>
293
+ {#each monthNames as name, m (m)}
294
+ <button
295
+ type="button"
296
+ class="cell"
297
+ class:chosen={m === monthIndex(month)}
298
+ tabindex={m === monthIndex(focus) ? 0 : -1}
299
+ aria-label="{name.long} {yearOf(month)}"
300
+ aria-current={m === monthIndex(month) ? 'true' : undefined}
301
+ aria-disabled={monthOpen(yearOf(month), m) ? undefined : 'true'}
302
+ onclick={() => pickMonth(m)}>{name.short}</button
303
+ >
304
+ {/each}
305
+ </div>
306
+ {:else if view === 'years'}
307
+ <!-- The keys are its buttons' (arrows move between them, Esc goes back to the days). -->
308
+ <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
309
+ <div class="cells" role="group" aria-labelledby="{uid}-label {uid}-month" onkeydown={onCellKey}>
310
+ {#each years as y (y)}
311
+ <button
312
+ type="button"
313
+ class="cell data"
314
+ class:chosen={y === yearOf(month)}
315
+ tabindex={y === yearOf(focus) ? 0 : -1}
316
+ aria-current={y === yearOf(month) ? 'true' : undefined}
317
+ aria-disabled={yearOpen(y) ? undefined : 'true'}
318
+ onclick={() => pickYear(y)}>{y}</button
319
+ >
320
+ {/each}
321
+ </div>
322
+ {:else}
323
+ <table bind:this={table} role="grid" aria-labelledby="{uid}-label {uid}-month" {onkeydown} {@attach takeFocus}>
324
+ <thead>
325
+ <tr>
326
+ {#each names as name, i (i)}<th scope="col" abbr={name.long}>{name.short}</th>{/each}
327
+ </tr>
328
+ </thead>
329
+ <tbody>
330
+ {#each weeks as week (week[0])}
331
+ <tr>
332
+ {#each week as day, col (day)}
333
+ {@const inMonth = monthOf(day) === monthOf(month)}
334
+ {@const chosen = selected.includes(day)}
335
+ {@const inRange = !!span && day >= span[0] && day <= span[1]}
336
+ {@const edge = isEnd(day)}
337
+ {@const between = inRange && !edge}
338
+ <td role="gridcell" aria-selected={chosen || inRange}>
339
+ <button
340
+ type="button"
341
+ data-day={day}
342
+ class="day"
343
+ class:outside={!inMonth}
344
+ class:chosen={chosen || edge}
345
+ class:between
346
+ class:bar-start={inRange && (day === span?.[0] || col === 0)}
347
+ class:bar-end={inRange && (day === span?.[1] || col === week.length - 1)}
348
+ style:--tint={between ? tint(day) : undefined}
349
+ tabindex={day === focus ? 0 : -1}
350
+ aria-label={speakDay(day)}
351
+ aria-current={day === now ? 'date' : undefined}
352
+ aria-disabled={can(day) ? undefined : 'true'}
353
+ onclick={() => pick(day)}
354
+ onpointerenter={() => onpoint?.(day)}
355
+ onfocus={() => onpoint?.(day)}
356
+ >{Number(day.slice(8))}{#if pending && between}<DashOutline style={slice(day, col, week.length)} />{/if}</button
357
+ >
358
+ </td>
359
+ {/each}
360
+ </tr>
361
+ {/each}
362
+ </tbody>
363
+ </table>
364
+ {/if}
365
+ </div>
366
+
367
+ <style>
368
+ /* A picker: its headings and day names are chrome, not text to copy (base.css). */
369
+ .calendar {
370
+ user-select: none;
371
+ -webkit-user-select: none;
372
+ /* A day's width: the cells sit edge to edge, so a range's outline slices (slice()) line up by it. */
373
+ --day: 32px;
374
+ display: grid;
375
+ gap: var(--space-2);
376
+ width: max-content;
377
+ }
378
+ .head {
379
+ display: flex;
380
+ align-items: center;
381
+ justify-content: space-between;
382
+ gap: var(--space-2);
383
+ }
384
+ .title {
385
+ display: flex;
386
+ align-items: center;
387
+ gap: 2px;
388
+ font-weight: var(--w-semibold);
389
+ color: var(--fg);
390
+ }
391
+ .range {
392
+ font-family: var(--font-data);
393
+ font-variant-numeric: tabular-nums;
394
+ }
395
+ .pick {
396
+ min-height: 24px;
397
+ padding: 0 var(--space-1);
398
+ border: 0;
399
+ border-radius: var(--r);
400
+ background: none;
401
+ color: inherit;
402
+ font: inherit;
403
+ transition: background-color var(--dur-fast) var(--ease-out);
404
+ }
405
+ .pick:hover {
406
+ background: var(--control-3);
407
+ }
408
+ .pick:focus-visible,
409
+ .cell:focus-visible {
410
+ outline: 2px solid var(--accent);
411
+ outline-offset: -2px;
412
+ }
413
+ /* Twelve months or years, in the width of the day grid (7 × 32px). */
414
+ .cells {
415
+ display: grid;
416
+ grid-template-columns: repeat(3, 1fr);
417
+ gap: 2px;
418
+ width: 224px;
419
+ }
420
+ .cell {
421
+ min-height: 40px;
422
+ padding: 0;
423
+ border: 0;
424
+ border-radius: var(--r);
425
+ background: none;
426
+ color: var(--fg);
427
+ font: var(--w-medium) 12px var(--font-body);
428
+ transition: background-color var(--dur-fast) var(--ease-out);
429
+ }
430
+ .cell.data {
431
+ font-family: var(--font-data);
432
+ font-variant-numeric: tabular-nums;
433
+ }
434
+ .cell:hover:not([aria-disabled='true']) {
435
+ background: var(--control-3);
436
+ }
437
+ .cell[aria-disabled='true'] {
438
+ color: var(--faint);
439
+ text-decoration: line-through;
440
+ cursor: default;
441
+ }
442
+ table {
443
+ border-collapse: collapse;
444
+ }
445
+ th {
446
+ width: 32px;
447
+ height: 24px;
448
+ font-size: 11px;
449
+ font-weight: var(--w-medium);
450
+ color: var(--muted);
451
+ }
452
+ td {
453
+ padding: 1px 0;
454
+ }
455
+ .day {
456
+ display: grid;
457
+ place-items: center;
458
+ width: var(--day);
459
+ height: 30px;
460
+ padding: 0;
461
+ border: 0;
462
+ border-radius: var(--r);
463
+ background: none;
464
+ color: var(--fg);
465
+ font: var(--w-medium) 12px var(--font-data);
466
+ font-variant-numeric: tabular-nums;
467
+ transition: background-color var(--dur-fast) var(--ease-out);
468
+ }
469
+ .day:hover:not([aria-disabled='true']) {
470
+ background: var(--control-3);
471
+ }
472
+ .outside {
473
+ color: var(--faint);
474
+ }
475
+ [aria-current='date'] {
476
+ box-shadow: inset 0 0 0 1px var(--accent-line);
477
+ }
478
+ /* A range: one bar per week, rounded only where it starts or ends (the range's ends, the week's ends). Between its
479
+ ends, each day's piece of the blended tint (--tint, from tint()); the day under the pointer lights up on top. */
480
+ .day {
481
+ position: relative;
482
+ }
483
+ .between {
484
+ border-radius: 0;
485
+ background: var(--tint);
486
+ color: var(--fg);
487
+ }
488
+ .between:hover:not([aria-disabled='true']) {
489
+ background:
490
+ linear-gradient(var(--control-3), var(--control-3)),
491
+ var(--tint);
492
+ }
493
+ .bar-start {
494
+ border-start-end-radius: 0;
495
+ border-end-end-radius: 0;
496
+ }
497
+ .bar-end {
498
+ border-start-start-radius: 0;
499
+ border-end-start-radius: 0;
500
+ }
501
+ .between.bar-start,
502
+ .chosen.bar-start {
503
+ border-start-start-radius: var(--r);
504
+ border-end-start-radius: var(--r);
505
+ }
506
+ .between.bar-end,
507
+ .chosen.bar-end {
508
+ border-start-end-radius: var(--r);
509
+ border-end-end-radius: var(--r);
510
+ }
511
+ .chosen,
512
+ .chosen:hover:not([aria-disabled='true']) {
513
+ background: var(--brand);
514
+ color: var(--accent-ink);
515
+ }
516
+ .day[aria-disabled='true'] {
517
+ color: var(--faint);
518
+ text-decoration: line-through;
519
+ cursor: default;
520
+ }
521
+ .day:focus-visible {
522
+ outline: 2px solid var(--accent);
523
+ outline-offset: -2px;
524
+ }
525
+ @media (forced-colors: active) {
526
+ .chosen {
527
+ background: Highlight;
528
+ color: HighlightText;
529
+ }
530
+ .between {
531
+ outline: 1px solid Highlight;
532
+ outline-offset: -1px;
533
+ }
534
+ }
535
+ </style>
@@ -0,0 +1,45 @@
1
+ export default Calendar;
2
+ type Calendar = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props>): void;
5
+ };
6
+ declare const Calendar: import("svelte").Component<{
7
+ /**
8
+ * bindable
9
+ */
10
+ month: string;
11
+ /**
12
+ * bindable
13
+ */
14
+ focus: string;
15
+ selected?: string[] | undefined;
16
+ range?: [string, string] | null | undefined;
17
+ pending?: boolean | undefined;
18
+ min?: string | null | undefined;
19
+ max?: string | null | undefined;
20
+ allowed?: string[] | null | undefined;
21
+ onpick: (day: string) => void;
22
+ onpoint?: ((day: string) => void) | undefined;
23
+ autofocus?: boolean | undefined;
24
+ label?: string | undefined;
25
+ }, {}, "focus" | "month">;
26
+ type Props = {
27
+ /**
28
+ * bindable
29
+ */
30
+ month: string;
31
+ /**
32
+ * bindable
33
+ */
34
+ focus: string;
35
+ selected?: string[] | undefined;
36
+ range?: [string, string] | null | undefined;
37
+ pending?: boolean | undefined;
38
+ min?: string | null | undefined;
39
+ max?: string | null | undefined;
40
+ allowed?: string[] | null | undefined;
41
+ onpick: (day: string) => void;
42
+ onpoint?: ((day: string) => void) | undefined;
43
+ autofocus?: boolean | undefined;
44
+ label?: string | undefined;
45
+ };