@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.8

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 (223) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  4. package/dist/avatar/README.md +52 -0
  5. package/dist/avatar/count/avatar-count.svelte +56 -0
  6. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  8. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  9. package/dist/avatar/group/avatar-group.svelte +65 -0
  10. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  11. package/dist/avatar/group/context.d.ts +15 -0
  12. package/dist/avatar/group/context.js +15 -0
  13. package/dist/avatar/image/avatar-image.svelte +104 -0
  14. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  15. package/dist/avatar/index.d.ts +22 -0
  16. package/dist/avatar/index.js +10 -0
  17. package/dist/avatar/index.parts.d.ts +5 -0
  18. package/dist/avatar/index.parts.js +5 -0
  19. package/dist/avatar/root/avatar-root.svelte +79 -0
  20. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  21. package/dist/avatar/root/context.d.ts +14 -0
  22. package/dist/avatar/root/context.js +15 -0
  23. package/dist/avatar/types.d.ts +84 -0
  24. package/dist/avatar/types.js +1 -0
  25. package/dist/breadcrumbs/README.md +65 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  27. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  28. package/dist/breadcrumbs/index.d.ts +23 -0
  29. package/dist/breadcrumbs/index.js +10 -0
  30. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  31. package/dist/breadcrumbs/index.parts.js +6 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  33. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  35. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  37. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  39. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  40. package/dist/breadcrumbs/root/context.d.ts +19 -0
  41. package/dist/breadcrumbs/root/context.js +15 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  43. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  44. package/dist/breadcrumbs/types.d.ts +80 -0
  45. package/dist/breadcrumbs/types.js +1 -0
  46. package/dist/button/root/button-root.svelte +9 -0
  47. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  48. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  49. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  50. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  51. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  52. package/dist/checkbox-group/README.md +95 -0
  53. package/dist/checkbox-group/index.d.ts +15 -0
  54. package/dist/checkbox-group/index.js +6 -0
  55. package/dist/checkbox-group/index.parts.d.ts +4 -0
  56. package/dist/checkbox-group/index.parts.js +7 -0
  57. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  58. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  59. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  60. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  61. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  62. package/dist/checkbox-group/root/context.svelte.js +251 -0
  63. package/dist/checkbox-group/types.d.ts +57 -0
  64. package/dist/checkbox-group/types.js +1 -0
  65. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  66. package/dist/dialog/root/dialog-root.svelte +15 -2
  67. package/dist/drawer/root/drawer-root.svelte +15 -2
  68. package/dist/index.d.ts +18 -0
  69. package/dist/index.js +17 -0
  70. package/dist/internal/localized-strings.d.ts +48 -0
  71. package/dist/internal/localized-strings.js +48 -0
  72. package/dist/internal/number-precision.d.ts +9 -0
  73. package/dist/internal/number-precision.js +27 -0
  74. package/dist/menu/root/focus-state.d.ts +2 -2
  75. package/dist/menu/root/focus-state.js +8 -32
  76. package/dist/menu/root/menu-state.svelte.js +5 -1
  77. package/dist/numberfield/root/number-utils.js +1 -20
  78. package/dist/popover/root/focus-state.d.ts +2 -2
  79. package/dist/popover/root/focus-state.js +7 -34
  80. package/dist/primitives/contain-wheel.d.ts +9 -0
  81. package/dist/primitives/contain-wheel.js +41 -0
  82. package/dist/primitives/floating.d.ts +6 -0
  83. package/dist/primitives/floating.js +26 -5
  84. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  85. package/dist/primitives/focus-visible.svelte.js +19 -0
  86. package/dist/primitives/index.d.ts +1 -0
  87. package/dist/primitives/index.js +1 -0
  88. package/dist/primitives/input-modality.d.ts +7 -0
  89. package/dist/primitives/input-modality.js +32 -5
  90. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  91. package/dist/primitives/keyboard-navigation.js +2 -1
  92. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  93. package/dist/primitives/trigger-focus-state.js +57 -0
  94. package/dist/progress/README.md +54 -0
  95. package/dist/progress/index.d.ts +21 -0
  96. package/dist/progress/index.js +9 -0
  97. package/dist/progress/index.parts.d.ts +5 -0
  98. package/dist/progress/index.parts.js +5 -0
  99. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  100. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  101. package/dist/progress/label/progress-label.svelte +34 -0
  102. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  103. package/dist/progress/root/context.d.ts +26 -0
  104. package/dist/progress/root/context.js +15 -0
  105. package/dist/progress/root/progress-root.svelte +136 -0
  106. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  107. package/dist/progress/root/progress-utils.d.ts +12 -0
  108. package/dist/progress/root/progress-utils.js +41 -0
  109. package/dist/progress/track/progress-track.svelte +27 -0
  110. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  111. package/dist/progress/types.d.ts +81 -0
  112. package/dist/progress/types.js +1 -0
  113. package/dist/progress/value/progress-value.svelte +36 -0
  114. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  115. package/dist/radio-group/README.md +103 -0
  116. package/dist/radio-group/index.d.ts +18 -0
  117. package/dist/radio-group/index.js +9 -0
  118. package/dist/radio-group/index.parts.d.ts +4 -0
  119. package/dist/radio-group/index.parts.js +4 -0
  120. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  121. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  122. package/dist/radio-group/item/context.d.ts +18 -0
  123. package/dist/radio-group/item/context.js +15 -0
  124. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  125. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  126. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  127. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  128. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  129. package/dist/radio-group/root/context.svelte.js +284 -0
  130. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  131. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  132. package/dist/radio-group/types.d.ts +50 -0
  133. package/dist/radio-group/types.js +1 -0
  134. package/dist/select/README.md +129 -0
  135. package/dist/select/index.d.ts +30 -0
  136. package/dist/select/index.js +16 -0
  137. package/dist/select/index.parts.d.ts +8 -0
  138. package/dist/select/index.parts.js +9 -0
  139. package/dist/select/item/select-item.svelte +68 -0
  140. package/dist/select/item/select-item.svelte.d.ts +10 -0
  141. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  142. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  143. package/dist/select/label/select-label.svelte +46 -0
  144. package/dist/select/label/select-label.svelte.d.ts +4 -0
  145. package/dist/select/list/select-list.svelte +241 -0
  146. package/dist/select/list/select-list.svelte.d.ts +62 -0
  147. package/dist/select/popover/select-popover.svelte +80 -0
  148. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  149. package/dist/select/root/context.d.ts +106 -0
  150. package/dist/select/root/context.js +22 -0
  151. package/dist/select/root/select-root.svelte +544 -0
  152. package/dist/select/root/select-root.svelte.d.ts +25 -0
  153. package/dist/select/trigger/select-trigger.svelte +192 -0
  154. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  155. package/dist/select/types.d.ts +133 -0
  156. package/dist/select/types.js +1 -0
  157. package/dist/select/value/select-value.svelte +61 -0
  158. package/dist/select/value/select-value.svelte.d.ts +4 -0
  159. package/dist/separator/README.md +35 -0
  160. package/dist/separator/index.d.ts +7 -0
  161. package/dist/separator/index.js +3 -0
  162. package/dist/separator/separator.svelte +254 -0
  163. package/dist/separator/separator.svelte.d.ts +45 -0
  164. package/dist/separator/types.d.ts +1 -0
  165. package/dist/separator/types.js +1 -0
  166. package/dist/slider/README.md +61 -0
  167. package/dist/slider/fill/slider-fill.svelte +40 -0
  168. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  169. package/dist/slider/index.d.ts +9 -0
  170. package/dist/slider/index.js +8 -0
  171. package/dist/slider/index.parts.d.ts +6 -0
  172. package/dist/slider/index.parts.js +6 -0
  173. package/dist/slider/label/slider-label.svelte +44 -0
  174. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  175. package/dist/slider/output/slider-output.svelte +46 -0
  176. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  177. package/dist/slider/root/context.d.ts +106 -0
  178. package/dist/slider/root/context.js +15 -0
  179. package/dist/slider/root/slider-root.svelte +545 -0
  180. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  181. package/dist/slider/root/slider-utils.d.ts +57 -0
  182. package/dist/slider/root/slider-utils.js +88 -0
  183. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  184. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  185. package/dist/slider/track/slider-track.svelte +60 -0
  186. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  187. package/dist/slider/types.d.ts +144 -0
  188. package/dist/slider/types.js +1 -0
  189. package/dist/switch/root/switch-root.svelte +9 -0
  190. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  191. package/dist/table/root/table-root.svelte +29 -6
  192. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  193. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  194. package/dist/toggle/root/toggle-root.svelte +28 -0
  195. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  196. package/dist/toggle-group/README.md +6 -4
  197. package/dist/toggle-group/index.d.ts +2 -0
  198. package/dist/toggle-group/index.parts.d.ts +1 -0
  199. package/dist/toggle-group/index.parts.js +4 -0
  200. package/dist/tooltip/README.md +53 -0
  201. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  202. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  203. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  204. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  205. package/dist/tooltip/index.d.ts +8 -0
  206. package/dist/tooltip/index.js +7 -0
  207. package/dist/tooltip/index.parts.d.ts +5 -0
  208. package/dist/tooltip/index.parts.js +5 -0
  209. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  210. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  211. package/dist/tooltip/root/context.d.ts +46 -0
  212. package/dist/tooltip/root/context.js +22 -0
  213. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  214. package/dist/tooltip/root/safe-polygon.js +66 -0
  215. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  216. package/dist/tooltip/root/tooltip-group.js +41 -0
  217. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  218. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  219. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  220. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  221. package/dist/tooltip/types.d.ts +105 -0
  222. package/dist/tooltip/types.js +1 -0
  223. package/package.json +46 -1
@@ -0,0 +1,254 @@
1
+ <script lang="ts">
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import { watchFocusVisible } from '../primitives/focus-visible.svelte';
4
+ import { shouldShowFocusVisible, trackInteractionModality } from '../primitives/input-modality';
5
+ import type { SeparatorOrientation } from './types.js';
6
+
7
+ type SeparatorProps = Omit<
8
+ HTMLAttributes<HTMLDivElement>,
9
+ | 'children'
10
+ | 'class'
11
+ | 'role'
12
+ | 'aria-orientation'
13
+ | 'aria-valuenow'
14
+ | 'aria-valuemin'
15
+ | 'aria-valuemax'
16
+ | 'aria-disabled'
17
+ > & {
18
+ /**
19
+ * The direction of the line. A horizontal separator sits between two blocks, one above the
20
+ * other. A vertical one sits between two items side by side, such as in a toolbar.
21
+ */
22
+ orientation?: SeparatorOrientation;
23
+ /**
24
+ * Makes the separator a visual line only. A screen reader then skips it. Use it for a line
25
+ * that repeats a break the content already makes, such as a border between two sections
26
+ * with headings. Without it, the separator is a `role="separator"` element, which a screen
27
+ * reader reads as a break between two groups of content. A separator with a `value` keeps
28
+ * its role.
29
+ */
30
+ decorative?: boolean;
31
+ /**
32
+ * Makes the separator a window splitter the user moves: the size of the pane before it, as a
33
+ * number between `min` and `max`. Use `bind:value` and give the pane its size from it. The
34
+ * splitter is a tab stop. The arrow keys move it, `Home` and `End` send it to the ends, and
35
+ * `Enter` folds the pane and unfolds it. The pointer drags it along its parent.
36
+ */
37
+ value?: number;
38
+ /** The value with the pane folded. */
39
+ min?: number;
40
+ /** The value with the pane at its largest. */
41
+ max?: number;
42
+ /** The move of one arrow key. */
43
+ step?: number;
44
+ /** The move of one arrow key with `Shift`. */
45
+ largeStep?: number;
46
+ /** Called with the value after each move. */
47
+ onValueChange?: (value: number) => void;
48
+ /** The id of the pane the splitter sizes, for `aria-controls`. */
49
+ 'aria-controls'?: string;
50
+ /** Holds the splitter still. It stays a tab stop, and it says it is disabled. */
51
+ disabled?: boolean;
52
+ /** The CSS class names of the element. */
53
+ class?: string;
54
+ /** The separator element. Use `bind:element` to read it. */
55
+ element?: HTMLDivElement | null;
56
+ };
57
+
58
+ /**
59
+ * Separator — a line between two groups of content.
60
+ *
61
+ * It is a `role="separator"` element, which a screen reader reads as a break, with
62
+ * `aria-orientation` for a vertical line: a separator is horizontal unless it says otherwise.
63
+ * `decorative` takes the role away for a line that repeats a break the content already makes.
64
+ * It has no size of its own: give it a border or a background, and a width or a height.
65
+ *
66
+ * With a `value`, it is a window splitter: a focusable separator with `aria-valuenow` that
67
+ * the arrow keys and the pointer move. The value is a number in `[min, max]`, and the pane
68
+ * before the splitter takes its size from it.
69
+ */
70
+ let {
71
+ orientation = 'horizontal',
72
+ decorative = false,
73
+ value = $bindable(),
74
+ min = 0,
75
+ max = 100,
76
+ step = 1,
77
+ largeStep = 10,
78
+ onValueChange,
79
+ disabled = false,
80
+ class: className = '',
81
+ element = $bindable<HTMLDivElement | null>(null),
82
+ style,
83
+ onkeydown: onKeyDownExternal,
84
+ onpointerdown: onPointerDownExternal,
85
+ onfocus: onFocusExternal,
86
+ onblur: onBlurExternal,
87
+ ...restProps
88
+ }: SeparatorProps = $props();
89
+
90
+ let separatorRef: HTMLDivElement | null = $state(null);
91
+ let focused = $state(false);
92
+ let focusVisible = $state(false);
93
+ let dragging = $state(false);
94
+ // The value before a fold with `Enter`, thus the next `Enter` unfolds to the same place.
95
+ let valueBeforeFold: number | null = null;
96
+
97
+ const movable = $derived(value !== undefined);
98
+ const hasRole = $derived(movable || !decorative);
99
+ const clamped = $derived(value === undefined ? undefined : clamp(value));
100
+
101
+ watchFocusVisible({
102
+ isFocused: () => focused,
103
+ element: () => separatorRef,
104
+ set: (visible) => (focusVisible = visible)
105
+ });
106
+
107
+ $effect(() => {
108
+ element = separatorRef;
109
+ return () => {
110
+ element = null;
111
+ };
112
+ });
113
+
114
+ function clamp(next: number) {
115
+ return Math.min(max, Math.max(min, next));
116
+ }
117
+
118
+ function setValue(next: number) {
119
+ const bounded = clamp(next);
120
+ if (bounded === value) return;
121
+ value = bounded;
122
+ onValueChange?.(bounded);
123
+ }
124
+
125
+ function isRtl() {
126
+ return separatorRef ? getComputedStyle(separatorRef).direction === 'rtl' : false;
127
+ }
128
+
129
+ function handleKeyDown(event: KeyboardEvent & { currentTarget: EventTarget & HTMLDivElement }) {
130
+ onKeyDownExternal?.(event);
131
+ if (event.defaultPrevented || !movable || disabled || clamped === undefined) return;
132
+ // A vertical line splits left from right: the horizontal arrows move it. A horizontal
133
+ // line splits top from bottom: the vertical arrows move it.
134
+ const vertical = orientation === 'vertical';
135
+ const forward = vertical ? 'ArrowRight' : 'ArrowDown';
136
+ const backward = vertical ? 'ArrowLeft' : 'ArrowUp';
137
+ // On a right-to-left page the pane before a vertical line is on the right: the arrows flip.
138
+ const sign = vertical && isRtl() ? -1 : 1;
139
+ const amount = event.shiftKey ? largeStep : step;
140
+ let next: number | null = null;
141
+ if (event.key === forward) next = clamped + amount * sign;
142
+ else if (event.key === backward) next = clamped - amount * sign;
143
+ else if (event.key === 'Home') next = min;
144
+ else if (event.key === 'End') next = max;
145
+ else if (event.key === 'Enter') {
146
+ if (clamped > min) {
147
+ valueBeforeFold = clamped;
148
+ next = min;
149
+ } else {
150
+ next = valueBeforeFold ?? max;
151
+ valueBeforeFold = null;
152
+ }
153
+ }
154
+ if (next === null) return;
155
+ event.preventDefault();
156
+ setValue(next);
157
+ }
158
+
159
+ function handlePointerDown(
160
+ event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
161
+ ) {
162
+ onPointerDownExternal?.(event);
163
+ trackInteractionModality(event, separatorRef);
164
+ focusVisible = false;
165
+ if (event.defaultPrevented || !movable || disabled || clamped === undefined) return;
166
+ if (event.button !== 0) return;
167
+ const node = event.currentTarget;
168
+ const parent = node.parentElement;
169
+ if (!parent) return;
170
+ event.preventDefault();
171
+ node.focus();
172
+ const vertical = orientation === 'vertical';
173
+ const sign = vertical && isRtl() ? -1 : 1;
174
+ const rect = parent.getBoundingClientRect();
175
+ const size = vertical ? rect.width : rect.height;
176
+ if (size <= 0) return;
177
+ const start = vertical ? event.clientX : event.clientY;
178
+ const startValue = clamped;
179
+ const pointerId = event.pointerId;
180
+ // The capture keeps the events on the splitter when the pointer runs ahead of it. The
181
+ // window listeners work without it, thus a pointer the browser does not know is no error.
182
+ try {
183
+ node.setPointerCapture(pointerId);
184
+ } catch {
185
+ // See above.
186
+ }
187
+ dragging = true;
188
+
189
+ const handleMove = (moveEvent: PointerEvent) => {
190
+ if (moveEvent.pointerId !== pointerId) return;
191
+ const position = vertical ? moveEvent.clientX : moveEvent.clientY;
192
+ // The move along the parent, as a share of its size, in the units of the range.
193
+ const delta = ((position - start) * sign * (max - min)) / size;
194
+ setValue(startValue + delta);
195
+ };
196
+ const handleUp = (upEvent: PointerEvent) => {
197
+ if (upEvent.pointerId !== pointerId) return;
198
+ dragging = false;
199
+ if (node.hasPointerCapture(pointerId)) node.releasePointerCapture(pointerId);
200
+ window.removeEventListener('pointermove', handleMove);
201
+ window.removeEventListener('pointerup', handleUp);
202
+ window.removeEventListener('pointercancel', handleUp);
203
+ };
204
+ window.addEventListener('pointermove', handleMove);
205
+ window.addEventListener('pointerup', handleUp);
206
+ window.addEventListener('pointercancel', handleUp);
207
+ }
208
+
209
+ function handleFocus(event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) {
210
+ onFocusExternal?.(event);
211
+ focused = true;
212
+ focusVisible = shouldShowFocusVisible(separatorRef);
213
+ }
214
+
215
+ function handleBlur(event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) {
216
+ onBlurExternal?.(event);
217
+ focused = false;
218
+ focusVisible = false;
219
+ }
220
+
221
+ // The browser must not turn the drag into a scroll before the splitter claims it.
222
+ const inlineStyle = $derived(
223
+ [movable ? 'touch-action: none;' : '', style ?? ''].filter(Boolean).join(' ') || undefined
224
+ );
225
+ </script>
226
+
227
+ <!-- A window splitter is a separator with a tab stop, as the pattern says: the arrow keys move
228
+ it, thus it must take the focus. -->
229
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
230
+ <div
231
+ {...restProps}
232
+ bind:this={separatorRef}
233
+ role={hasRole ? 'separator' : 'none'}
234
+ aria-orientation={hasRole && orientation === 'vertical' ? 'vertical' : undefined}
235
+ aria-valuenow={clamped}
236
+ aria-valuemin={movable ? min : undefined}
237
+ aria-valuemax={movable ? max : undefined}
238
+ aria-disabled={movable && disabled ? 'true' : undefined}
239
+ tabindex={movable ? 0 : undefined}
240
+ class={className}
241
+ style={inlineStyle}
242
+ data-separator-root="true"
243
+ data-orientation={orientation}
244
+ data-decorative={(decorative && !movable) || undefined}
245
+ data-movable={movable || undefined}
246
+ data-disabled={(movable && disabled) || undefined}
247
+ data-dragging={dragging || undefined}
248
+ data-focused={focused || undefined}
249
+ data-focus-visible={focusVisible || undefined}
250
+ onkeydown={handleKeyDown}
251
+ onpointerdown={handlePointerDown}
252
+ onfocus={handleFocus}
253
+ onblur={handleBlur}
254
+ ></div>
@@ -0,0 +1,45 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { SeparatorOrientation } from './types.js';
3
+ type SeparatorProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role' | 'aria-orientation' | 'aria-valuenow' | 'aria-valuemin' | 'aria-valuemax' | 'aria-disabled'> & {
4
+ /**
5
+ * The direction of the line. A horizontal separator sits between two blocks, one above the
6
+ * other. A vertical one sits between two items side by side, such as in a toolbar.
7
+ */
8
+ orientation?: SeparatorOrientation;
9
+ /**
10
+ * Makes the separator a visual line only. A screen reader then skips it. Use it for a line
11
+ * that repeats a break the content already makes, such as a border between two sections
12
+ * with headings. Without it, the separator is a `role="separator"` element, which a screen
13
+ * reader reads as a break between two groups of content. A separator with a `value` keeps
14
+ * its role.
15
+ */
16
+ decorative?: boolean;
17
+ /**
18
+ * Makes the separator a window splitter the user moves: the size of the pane before it, as a
19
+ * number between `min` and `max`. Use `bind:value` and give the pane its size from it. The
20
+ * splitter is a tab stop. The arrow keys move it, `Home` and `End` send it to the ends, and
21
+ * `Enter` folds the pane and unfolds it. The pointer drags it along its parent.
22
+ */
23
+ value?: number;
24
+ /** The value with the pane folded. */
25
+ min?: number;
26
+ /** The value with the pane at its largest. */
27
+ max?: number;
28
+ /** The move of one arrow key. */
29
+ step?: number;
30
+ /** The move of one arrow key with `Shift`. */
31
+ largeStep?: number;
32
+ /** Called with the value after each move. */
33
+ onValueChange?: (value: number) => void;
34
+ /** The id of the pane the splitter sizes, for `aria-controls`. */
35
+ 'aria-controls'?: string;
36
+ /** Holds the splitter still. It stays a tab stop, and it says it is disabled. */
37
+ disabled?: boolean;
38
+ /** The CSS class names of the element. */
39
+ class?: string;
40
+ /** The separator element. Use `bind:element` to read it. */
41
+ element?: HTMLDivElement | null;
42
+ };
43
+ declare const Separator: import("svelte").Component<SeparatorProps, {}, "value" | "element">;
44
+ type Separator = ReturnType<typeof Separator>;
45
+ export default Separator;
@@ -0,0 +1 @@
1
+ export type SeparatorOrientation = 'horizontal' | 'vertical';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ # Slider
2
+
3
+ ## Description
4
+
5
+ `Slider` is a form field with a number, or a range of numbers, on a track. The user moves a thumb with the pointer or with the keyboard. Each thumb holds a native `<input type="range">`, thus a form sends the value and a screen reader reads a native slider.
6
+
7
+ ## Anatomy
8
+
9
+ - `Slider.Root`
10
+ - `Slider.Label`
11
+ - `Slider.Output`
12
+ - `Slider.Track`
13
+ - `Slider.Fill`
14
+ - `Slider.Thumb`
15
+
16
+ ```svelte
17
+ <Slider.Root name="volume">
18
+ <Slider.Label>Volume</Slider.Label>
19
+ <Slider.Output />
20
+ <Slider.Track>
21
+ <Slider.Fill />
22
+ <Slider.Thumb />
23
+ </Slider.Track>
24
+ </Slider.Root>
25
+ ```
26
+
27
+ ## Usage guidelines
28
+
29
+ - Use `bind:value` for the state, or `value` with `onChange` and `controlledValue` to hold it yourself.
30
+ - Give an array for a range, and one `Slider.Thumb` per number.
31
+ - Use `onChangeEnd` for work that must not run on each move of a drag.
32
+ - Give the track a size and the thumb a size. The thumb and the fill are positioned in percent.
33
+ - Give `formatOptions` for the text of the value, and `getValueText` for the text a screen reader reads.
34
+
35
+ ## API reference
36
+
37
+ - `Slider.Root`
38
+ - `value?: number | number[]`
39
+ - `defaultValue?: number | number[]`
40
+ - `controlledValue?: boolean`
41
+ - `onChange?: (value, details) => void`
42
+ - `onChangeEnd?: (value, details) => void`
43
+ - `min?: number`, `max?: number`, `step?: number`, `largeStep?: number`
44
+ - `minStepsBetweenThumbs?: number`
45
+ - `orientation?: 'horizontal' | 'vertical'`
46
+ - `disabled?: boolean`, `readonly?: boolean`, `invalid?: boolean`
47
+ - `name?: string`, `form?: string`
48
+ - `formatOptions?: Intl.NumberFormatOptions`
49
+ - `getValueText?: (value, index) => string`
50
+ - `Slider.Thumb`
51
+ - `index?: number`
52
+ - `name?: string`
53
+ - `aria-label?: string`
54
+
55
+ ## Accessibility
56
+
57
+ - The root is a `role="group"` named by `Slider.Label`, `aria-labelledby` or `aria-label`.
58
+ - Each thumb holds a native `<input type="range">` with `aria-valuenow`, `aria-valuetext`, `aria-orientation` and the name of the field. A range of two thumbs names them "Minimum" and "Maximum" in the locale.
59
+ - The keyboard: the arrows step, `PageUp`, `PageDown` and `Shift+Arrow` move a large step, `Home` and `End` move to the ends. The horizontal arrows follow the text direction.
60
+ - `Slider.Output` is an `<output>` for the native inputs, with `aria-live="off"`.
61
+ - A press on the track puts the focus on the thumb without a focus ring. A key press after it shows the ring.
@@ -0,0 +1,40 @@
1
+ <script lang="ts">
2
+ import { useSliderContext } from '../root/context';
3
+ import type { SliderFillProps } from '../types';
4
+
5
+ /**
6
+ * Slider.Fill — the part of the track between `min` and the thumb, or between the two thumbs
7
+ * of a range.
8
+ *
9
+ * It is positioned in percent of the value: `inset-inline-start` and `width` on a horizontal
10
+ * track, `bottom` and `height` on a vertical one. The logical property follows the direction
11
+ * of the text on its own.
12
+ */
13
+ let { children, class: className = '', style, ...restProps }: SliderFillProps = $props();
14
+
15
+ const ctx = useSliderContext('Slider.Fill');
16
+
17
+ const startPercent = $derived(ctx.values.length > 1 ? ctx.getPercent(ctx.values[0]) : 0);
18
+ const endPercent = $derived(ctx.getPercent(ctx.values[ctx.values.length - 1] ?? ctx.min));
19
+ const sizePercent = $derived(Math.max(0, endPercent - startPercent));
20
+ const positionStyle = $derived(
21
+ ctx.orientation === 'vertical'
22
+ ? `position: absolute; bottom: ${startPercent}%; height: ${sizePercent}%;`
23
+ : `position: absolute; inset-inline-start: ${startPercent}%; width: ${sizePercent}%;`
24
+ );
25
+ const resolvedStyle = $derived(`${positionStyle}${style ? ` ${style}` : ''}`);
26
+ </script>
27
+
28
+ <div
29
+ {...restProps}
30
+ class={className}
31
+ style={resolvedStyle}
32
+ data-slider-fill="true"
33
+ data-orientation={ctx.orientation}
34
+ data-disabled={ctx.isDisabled || undefined}
35
+ data-readonly={ctx.isReadOnly || undefined}
36
+ data-invalid={ctx.isInvalid || undefined}
37
+ data-dragging={ctx.draggingIndex !== null || undefined}
38
+ >
39
+ {@render children?.()}
40
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { SliderFillProps } from '../types';
2
+ declare const SliderFill: import("svelte").Component<SliderFillProps, {}, "">;
3
+ type SliderFill = ReturnType<typeof SliderFill>;
4
+ export default SliderFill;
@@ -0,0 +1,9 @@
1
+ export * as Slider from './index.parts.js';
2
+ export { default as SliderRoot } from './root/slider-root.svelte';
3
+ export { default as SliderLabel } from './label/slider-label.svelte';
4
+ export { default as SliderOutput } from './output/slider-output.svelte';
5
+ export { default as SliderTrack } from './track/slider-track.svelte';
6
+ export { default as SliderFill } from './fill/slider-fill.svelte';
7
+ export { default as SliderThumb } from './thumb/slider-thumb.svelte';
8
+ export type { SliderRootProps, SliderLabelProps, SliderOutputProps, SliderOutputRenderState, SliderTrackProps, SliderFillProps, SliderThumbProps, SliderThumbRenderState, SliderValue, SliderChangeDetails, SliderOrientation } from './types.js';
9
+ export { getSliderContext, setSliderContext, useSliderContext, type SliderChangeReason, type SliderContext } from './root/context.js';
@@ -0,0 +1,8 @@
1
+ export * as Slider from './index.parts.js';
2
+ export { default as SliderRoot } from './root/slider-root.svelte';
3
+ export { default as SliderLabel } from './label/slider-label.svelte';
4
+ export { default as SliderOutput } from './output/slider-output.svelte';
5
+ export { default as SliderTrack } from './track/slider-track.svelte';
6
+ export { default as SliderFill } from './fill/slider-fill.svelte';
7
+ export { default as SliderThumb } from './thumb/slider-thumb.svelte';
8
+ export { getSliderContext, setSliderContext, useSliderContext } from './root/context.js';
@@ -0,0 +1,6 @@
1
+ export { default as Root } from './root/slider-root.svelte';
2
+ export { default as Label } from './label/slider-label.svelte';
3
+ export { default as Output } from './output/slider-output.svelte';
4
+ export { default as Track } from './track/slider-track.svelte';
5
+ export { default as Fill } from './fill/slider-fill.svelte';
6
+ export { default as Thumb } from './thumb/slider-thumb.svelte';
@@ -0,0 +1,6 @@
1
+ export { default as Root } from './root/slider-root.svelte';
2
+ export { default as Label } from './label/slider-label.svelte';
3
+ export { default as Output } from './output/slider-output.svelte';
4
+ export { default as Track } from './track/slider-track.svelte';
5
+ export { default as Fill } from './fill/slider-fill.svelte';
6
+ export { default as Thumb } from './thumb/slider-thumb.svelte';
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { useSliderContext } from '../root/context';
3
+ import type { SliderLabelProps } from '../types';
4
+
5
+ /**
6
+ * Slider.Label — the accessible name of the slider.
7
+ *
8
+ * It registers its id with the root, which gives it to the group element as `aria-labelledby`,
9
+ * and each thumb points at it too. It renders a `<span>` and not a `<label>`, because a
10
+ * `<label>` names one control and a range has more than one thumb. A press on it puts the
11
+ * focus on the first thumb, as a `<label>` would.
12
+ */
13
+ let {
14
+ children,
15
+ class: className = '',
16
+ id: idProp,
17
+ onclick,
18
+ ...restProps
19
+ }: SliderLabelProps = $props();
20
+
21
+ const ctx = useSliderContext('Slider.Label');
22
+ const id = $derived(idProp ?? `${ctx.rootId}-label`);
23
+
24
+ // The returned unregister runs on destroy, and again whenever the id changes.
25
+ $effect(() => ctx.registerLabel(id));
26
+
27
+ function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLSpanElement }) {
28
+ onclick?.(event);
29
+ if (event.defaultPrevented || ctx.isDisabled) return;
30
+ ctx.focusThumb(0, 'pointer');
31
+ }
32
+ </script>
33
+
34
+ <span
35
+ {...restProps}
36
+ {id}
37
+ class={className}
38
+ data-slider-label="true"
39
+ data-orientation={ctx.orientation}
40
+ data-disabled={ctx.isDisabled || undefined}
41
+ onclick={handleClick}
42
+ >
43
+ {@render children?.()}
44
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { SliderLabelProps } from '../types';
2
+ declare const SliderLabel: import("svelte").Component<SliderLabelProps, {}, "">;
3
+ type SliderLabel = ReturnType<typeof SliderLabel>;
4
+ export default SliderLabel;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { readable } from 'svelte/store';
3
+ import { getLocaleContext } from '../../locale-provider/context';
4
+ import { useSliderContext } from '../root/context';
5
+ import type { SliderOutputProps, SliderOutputRenderState } from '../types';
6
+
7
+ /**
8
+ * Slider.Output — the text of the value.
9
+ *
10
+ * It renders an `<output>` that points at the native inputs, with `aria-live="off"`: the
11
+ * thumbs read their own value, and a live region would read it a second time.
12
+ */
13
+ let { children, class: className = '', ...restProps }: SliderOutputProps = $props();
14
+
15
+ const ctx = useSliderContext('Slider.Output');
16
+ const localeStore = getLocaleContext()?.locale ?? readable<string | undefined>(undefined);
17
+
18
+ const texts = $derived(ctx.values.map((value) => ctx.formatValue(value)));
19
+ // A range of two values is one text in the locale, "25–45", and not two texts with a dash
20
+ // written here. More than two values are a list in the locale.
21
+ const text = $derived.by(() => {
22
+ if (texts.length === 1) return texts[0];
23
+ if (texts.length === 2) return ctx.formatRange(ctx.values[0], ctx.values[1]);
24
+ if (typeof Intl.ListFormat === 'function') {
25
+ return new Intl.ListFormat($localeStore, { type: 'unit', style: 'short' }).format(texts);
26
+ }
27
+ return texts.join(', ');
28
+ });
29
+ const renderState = $derived<SliderOutputRenderState>({ values: ctx.values, texts, text });
30
+ </script>
31
+
32
+ <output
33
+ {...restProps}
34
+ for={ctx.thumbInputIds.join(' ')}
35
+ aria-live="off"
36
+ class={className}
37
+ data-slider-output="true"
38
+ data-orientation={ctx.orientation}
39
+ data-disabled={ctx.isDisabled || undefined}
40
+ >
41
+ {#if children}
42
+ {@render children(renderState)}
43
+ {:else}
44
+ {text}
45
+ {/if}
46
+ </output>
@@ -0,0 +1,4 @@
1
+ import type { SliderOutputProps } from '../types';
2
+ declare const SliderOutput: import("svelte").Component<SliderOutputProps, {}, "">;
3
+ type SliderOutput = ReturnType<typeof SliderOutput>;
4
+ export default SliderOutput;
@@ -0,0 +1,106 @@
1
+ export type SliderOrientation = 'horizontal' | 'vertical';
2
+ /** How a value changed. */
3
+ export type SliderChangeReason = 'keyboard' | 'pointer' | 'input' | 'form-reset';
4
+ export type SliderChangeDetails = {
5
+ reason: SliderChangeReason;
6
+ /** The index of the thumb that moved. */
7
+ index: number;
8
+ event?: Event;
9
+ };
10
+ /**
11
+ * Context shared between Slider.Root and its parts.
12
+ */
13
+ export type SliderContext = {
14
+ /** The instance id. Every ARIA id of the parts is made from it. */
15
+ instanceId: string;
16
+ /** The id of the root element. */
17
+ rootId: string;
18
+ /** The id of the `Slider.Label` element, when one is in the DOM. */
19
+ labelId: string | null;
20
+ /** The values, one per thumb, in ascending order. */
21
+ values: number[];
22
+ /** Whether the consumer gave an array: the shape of the value in the reports. */
23
+ isRange: boolean;
24
+ min: number;
25
+ max: number;
26
+ step: number;
27
+ /** The step of PageUp, PageDown and Shift+Arrow. */
28
+ largeStep: number;
29
+ /** The steps that two thumbs keep between them. */
30
+ minStepsBetweenThumbs: number;
31
+ orientation: SliderOrientation;
32
+ isDisabled: boolean;
33
+ isReadOnly: boolean;
34
+ isInvalid: boolean;
35
+ /** The `name` of the native inputs, when a thumb gives none of its own. */
36
+ name: string | undefined;
37
+ /** The `form` of the native inputs. */
38
+ form: string | undefined;
39
+ /** The `aria-label` given to the root. */
40
+ ariaLabel: string | undefined;
41
+ /** The `aria-labelledby` given to the root. */
42
+ ariaLabelledBy: string | undefined;
43
+ /** The `aria-describedby` given to the root. Every thumb carries it. */
44
+ ariaDescribedBy: string | undefined;
45
+ /** The index of the thumb under a pointer drag, or null. */
46
+ draggingIndex: number | null;
47
+ /** The index of the thumb that has the focus, or null. */
48
+ focusedIndex: number | null;
49
+ /** The index of the thumb the user touched last. It draws above the others. */
50
+ activeIndex: number | null;
51
+ /** Whether the focus in the slider must show as keyboard focus. */
52
+ isFocusVisible: boolean;
53
+ /** Whether the root is in a right-to-left context. Read at mount and on each pointer press. */
54
+ isRtl: boolean;
55
+ trackRef: HTMLElement | null;
56
+ setTrackRef: (element: HTMLElement | null) => void;
57
+ /** Registers the id of `Slider.Label`. Returns the unregister function. */
58
+ registerLabel: (id: string) => () => void;
59
+ /**
60
+ * Registers a thumb. Without an index, the thumb takes the next free one, in mount order.
61
+ * Returns the index and the unregister function.
62
+ */
63
+ registerThumb: (options: {
64
+ index?: number;
65
+ inputRef: () => HTMLInputElement | null;
66
+ }) => {
67
+ index: number;
68
+ unregister: () => void;
69
+ };
70
+ /** The id of the native input of a thumb. */
71
+ getThumbInputId: (index: number) => string;
72
+ /** The ids of every native input in the DOM, in index order. */
73
+ thumbInputIds: string[];
74
+ /** The position of a value in the range, from 0 to 100. */
75
+ getPercent: (value: number) => number;
76
+ /** The text of a value, in the locale and the `formatOptions`. */
77
+ formatValue: (value: number) => string;
78
+ /** The text of two values as one range in the locale, "25–45". */
79
+ formatRange: (start: number, end: number) => string;
80
+ /** The `aria-valuetext` of a thumb. */
81
+ getValueText: (value: number, index: number) => string;
82
+ /**
83
+ * Moves one thumb. The value is snapped, clamped, and kept between its neighbors. Returns
84
+ * whether the value changed.
85
+ */
86
+ setValueAt: (index: number, value: number, details: SliderChangeDetails) => boolean;
87
+ /** Moves one thumb by a step, or by the large step. Returns whether the value changed. */
88
+ stepValueAt: (index: number, direction: -1 | 1, options: {
89
+ large?: boolean;
90
+ event?: Event;
91
+ }) => boolean;
92
+ /** Reports the end of a sequence of changes: a key press, a drag. */
93
+ commitValue: (details: SliderChangeDetails) => void;
94
+ /**
95
+ * Starts a pointer drag. Without an index, the press picks the nearest thumb and moves it
96
+ * to the pointer at once. With one, the thumb stays where it is until the pointer moves.
97
+ */
98
+ startDrag: (event: PointerEvent, index?: number) => void;
99
+ /** Puts the focus on a thumb, with the modality of the interaction. */
100
+ focusThumb: (index: number, modality: 'keyboard' | 'pointer') => void;
101
+ setThumbFocus: (index: number, focused: boolean) => void;
102
+ setFocusVisible: (visible: boolean) => void;
103
+ };
104
+ export declare function setSliderContext(ctx: SliderContext): void;
105
+ export declare function getSliderContext(): SliderContext | undefined;
106
+ export declare function useSliderContext(part: string): SliderContext;