@alulore/kumiko 0.0.0-stage → 0.14.2

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 (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -2
  3. package/dist/badge/badge.css +287 -0
  4. package/dist/badge/badge.d.ts +40 -0
  5. package/dist/badge/badge.js +51 -0
  6. package/dist/badge/index.d.ts +1 -0
  7. package/dist/badge/index.js +1 -0
  8. package/dist/board/board-api.d.ts +147 -0
  9. package/dist/board/board-api.js +139 -0
  10. package/dist/board/board-card-menu.d.ts +17 -0
  11. package/dist/board/board-card-menu.js +53 -0
  12. package/dist/board/board-drag-events.d.ts +12 -0
  13. package/dist/board/board-drag-events.js +86 -0
  14. package/dist/board/board-fold.d.ts +10 -0
  15. package/dist/board/board-fold.js +30 -0
  16. package/dist/board/board-group.d.ts +10 -0
  17. package/dist/board/board-group.js +28 -0
  18. package/dist/board/board-keys.d.ts +16 -0
  19. package/dist/board/board-keys.js +65 -0
  20. package/dist/board/board-locked-rows.d.ts +23 -0
  21. package/dist/board/board-locked-rows.js +77 -0
  22. package/dist/board/board-motion.d.ts +7 -0
  23. package/dist/board/board-motion.js +102 -0
  24. package/dist/board/board-primitive.d.ts +53 -0
  25. package/dist/board/board-primitive.js +66 -0
  26. package/dist/board/board-pull.d.ts +6 -0
  27. package/dist/board/board-pull.js +94 -0
  28. package/dist/board/board-selection.d.ts +42 -0
  29. package/dist/board/board-selection.js +130 -0
  30. package/dist/board/board-slots.d.ts +1003 -0
  31. package/dist/board/board-slots.js +250 -0
  32. package/dist/board/board-types.d.ts +99 -0
  33. package/dist/board/board-types.js +1 -0
  34. package/dist/board/board.css +343 -0
  35. package/dist/board/board.d.ts +290 -0
  36. package/dist/board/board.js +23 -0
  37. package/dist/board/card-menu.d.ts +21 -0
  38. package/dist/board/card-menu.js +79 -0
  39. package/dist/board/cell-key.d.ts +6 -0
  40. package/dist/board/cell-key.js +16 -0
  41. package/dist/board/index.d.ts +6 -0
  42. package/dist/board/index.js +5 -0
  43. package/dist/board/interactive.d.ts +18 -0
  44. package/dist/board/interactive.js +51 -0
  45. package/dist/board/keep-capture.d.ts +16 -0
  46. package/dist/board/keep-capture.js +57 -0
  47. package/dist/board/landing.d.ts +5 -0
  48. package/dist/board/landing.js +10 -0
  49. package/dist/board/press-to-drop.d.ts +9 -0
  50. package/dist/board/press-to-drop.js +28 -0
  51. package/dist/board/refused-home.d.ts +16 -0
  52. package/dist/board/refused-home.js +50 -0
  53. package/dist/board/repeat-gate.d.ts +4 -0
  54. package/dist/board/repeat-gate.js +12 -0
  55. package/dist/board/scrollbar-gutter.d.ts +1 -0
  56. package/dist/board/scrollbar-gutter.js +27 -0
  57. package/dist/board/touch-hold.d.ts +19 -0
  58. package/dist/board/touch-hold.js +103 -0
  59. package/dist/button/button.css +576 -0
  60. package/dist/button/button.d.ts +50 -0
  61. package/dist/button/button.js +70 -0
  62. package/dist/button/index.d.ts +2 -0
  63. package/dist/button/index.js +1 -0
  64. package/dist/checkbox/checkbox-mark.d.ts +8 -0
  65. package/dist/checkbox/checkbox-mark.js +17 -0
  66. package/dist/checkbox/checkbox-marks.d.ts +33 -0
  67. package/dist/checkbox/checkbox-marks.js +30 -0
  68. package/dist/checkbox/checkbox.css +201 -0
  69. package/dist/checkbox/checkbox.d.ts +26 -0
  70. package/dist/checkbox/checkbox.js +11 -0
  71. package/dist/checkbox/index.d.ts +3 -0
  72. package/dist/checkbox/index.js +3 -0
  73. package/dist/chip/chip.css +251 -0
  74. package/dist/chip/chip.d.ts +39 -0
  75. package/dist/chip/chip.js +25 -0
  76. package/dist/chip/index.d.ts +1 -0
  77. package/dist/chip/index.js +1 -0
  78. package/dist/dialog/dialog.css +247 -0
  79. package/dist/dialog/index.d.ts +3 -0
  80. package/dist/dialog/index.js +3 -0
  81. package/dist/hover-card/hover-card.css +149 -0
  82. package/dist/hover-card/hover-card.d.ts +3 -0
  83. package/dist/hover-card/hover-card.js +8 -0
  84. package/dist/hover-card/index.d.ts +2 -0
  85. package/dist/hover-card/index.js +2 -0
  86. package/dist/input/index.d.ts +5 -0
  87. package/dist/input/index.js +5 -0
  88. package/dist/input/input-attributes.d.ts +12 -0
  89. package/dist/input/input-attributes.js +9 -0
  90. package/dist/input/input.css +752 -0
  91. package/dist/input/input.d.ts +28 -0
  92. package/dist/input/input.js +9 -0
  93. package/dist/input/search-input.d.ts +41 -0
  94. package/dist/input/search-input.js +47 -0
  95. package/dist/kbd/index.d.ts +1 -0
  96. package/dist/kbd/index.js +1 -0
  97. package/dist/kbd/kbd.css +77 -0
  98. package/dist/kbd/kbd.d.ts +21 -0
  99. package/dist/kbd/kbd.js +37 -0
  100. package/dist/label/index.d.ts +1 -0
  101. package/dist/label/index.js +1 -0
  102. package/dist/label/label.css +37 -0
  103. package/dist/label/label.d.ts +13 -0
  104. package/dist/label/label.js +10 -0
  105. package/dist/menu/index.d.ts +3 -0
  106. package/dist/menu/index.js +3 -0
  107. package/dist/menu/menu.css +349 -0
  108. package/dist/menu/menu.d.ts +11 -0
  109. package/dist/menu/menu.js +86 -0
  110. package/dist/menu/point-menu.d.ts +26 -0
  111. package/dist/menu/point-menu.js +51 -0
  112. package/dist/motion/flip-math.d.ts +19 -0
  113. package/dist/motion/flip-math.js +33 -0
  114. package/dist/motion/flip.d.ts +40 -0
  115. package/dist/motion/flip.js +203 -0
  116. package/dist/motion/index.d.ts +2 -0
  117. package/dist/motion/index.js +2 -0
  118. package/dist/motion/motion.css +169 -0
  119. package/dist/popover/index.d.ts +1 -0
  120. package/dist/popover/index.js +1 -0
  121. package/dist/popover/popover.css +208 -0
  122. package/dist/progress/index.d.ts +2 -0
  123. package/dist/progress/index.js +2 -0
  124. package/dist/progress/progress.css +390 -0
  125. package/dist/progress/progress.d.ts +36 -0
  126. package/dist/progress/progress.js +107 -0
  127. package/dist/select/index.d.ts +3 -0
  128. package/dist/select/index.js +2 -0
  129. package/dist/select/select-labels.d.ts +6 -0
  130. package/dist/select/select-labels.js +64 -0
  131. package/dist/select/select-search.d.ts +18 -0
  132. package/dist/select/select-search.js +10 -0
  133. package/dist/select/select.css +470 -0
  134. package/dist/select/select.d.ts +44 -0
  135. package/dist/select/select.js +92 -0
  136. package/dist/separator/index.d.ts +2 -0
  137. package/dist/separator/index.js +1 -0
  138. package/dist/separator/separator.css +32 -0
  139. package/dist/separator/separator.d.ts +17 -0
  140. package/dist/separator/separator.js +10 -0
  141. package/dist/slider/index.d.ts +2 -0
  142. package/dist/slider/index.js +2 -0
  143. package/dist/slider/slider-bubble.css +203 -0
  144. package/dist/slider/slider-feel.d.ts +33 -0
  145. package/dist/slider/slider-feel.js +153 -0
  146. package/dist/slider/slider-format.d.ts +13 -0
  147. package/dist/slider/slider-format.js +15 -0
  148. package/dist/slider/slider-marks.d.ts +16 -0
  149. package/dist/slider/slider-marks.js +32 -0
  150. package/dist/slider/slider.css +335 -0
  151. package/dist/slider/slider.d.ts +34 -0
  152. package/dist/slider/slider.js +94 -0
  153. package/dist/smooth-caret/caret-box.d.ts +7 -0
  154. package/dist/smooth-caret/caret-box.js +8 -0
  155. package/dist/smooth-caret/caret-controller.d.ts +7 -0
  156. package/dist/smooth-caret/caret-controller.js +222 -0
  157. package/dist/smooth-caret/caret-geometry.d.ts +11 -0
  158. package/dist/smooth-caret/caret-geometry.js +230 -0
  159. package/dist/smooth-caret/caret-glide.d.ts +13 -0
  160. package/dist/smooth-caret/caret-glide.js +76 -0
  161. package/dist/smooth-caret/caret-host.d.ts +5 -0
  162. package/dist/smooth-caret/caret-host.js +40 -0
  163. package/dist/smooth-caret/index.d.ts +7 -0
  164. package/dist/smooth-caret/index.js +7 -0
  165. package/dist/smooth-caret/remote-carets.d.ts +40 -0
  166. package/dist/smooth-caret/remote-carets.js +130 -0
  167. package/dist/smooth-caret/smooth-caret.css +157 -0
  168. package/dist/smooth-caret/smooth-caret.d.ts +5 -0
  169. package/dist/smooth-caret/smooth-caret.js +9 -0
  170. package/dist/smooth-caret/use-smooth-caret.d.ts +5 -0
  171. package/dist/smooth-caret/use-smooth-caret.js +9 -0
  172. package/dist/switch/index.d.ts +2 -0
  173. package/dist/switch/index.js +2 -0
  174. package/dist/switch/switch-drag.d.ts +21 -0
  175. package/dist/switch/switch-drag.js +23 -0
  176. package/dist/switch/switch-gesture.d.ts +28 -0
  177. package/dist/switch/switch-gesture.js +131 -0
  178. package/dist/switch/switch.css +189 -0
  179. package/dist/switch/switch.d.ts +15 -0
  180. package/dist/switch/switch.js +24 -0
  181. package/dist/textarea/index.d.ts +2 -0
  182. package/dist/textarea/index.js +2 -0
  183. package/dist/textarea/textarea.css +37 -0
  184. package/dist/textarea/textarea.d.ts +35 -0
  185. package/dist/textarea/textarea.js +11 -0
  186. package/dist/toast/index.d.ts +2 -0
  187. package/dist/toast/index.js +2 -0
  188. package/dist/toast/toast.css +293 -0
  189. package/dist/tooltip/index.d.ts +2 -0
  190. package/dist/tooltip/index.js +2 -0
  191. package/dist/tooltip/tooltip.css +143 -0
  192. package/dist/tooltip/tooltip.d.ts +14 -0
  193. package/dist/tooltip/tooltip.js +13 -0
  194. package/package.json +243 -5
@@ -0,0 +1,203 @@
1
+ @import "../motion/motion.css";
2
+
3
+ @layer kumiko {
4
+ :where(:root) {
5
+ --kumiko-slider-bubble-gap: 0.375rem;
6
+ --kumiko-slider-bubble-delay: 700ms;
7
+ --kumiko-slider-bubble-scale: 0.6;
8
+ --kumiko-slider-bubble-touch-lift: 1.75rem;
9
+ --kumiko-slider-bubble-pill-fg: #fff;
10
+ --kumiko-slider-bubble-pill-padding: 0.1875rem 0.75rem;
11
+ --kumiko-slider-bubble-pill-font-size: 0.8125rem;
12
+ --kumiko-slider-bubble-pill-font-weight: 600;
13
+ --kumiko-slider-bubble-pin-fg: #fff;
14
+ --kumiko-slider-bubble-pin-size: 2rem;
15
+ --kumiko-slider-bubble-pin-padding: 0.5rem;
16
+ --kumiko-slider-bubble-pin-font-size: 0.75rem;
17
+ --kumiko-slider-bubble-pin-font-weight: 600;
18
+ --kumiko-slider-bubble-plain-size: 0.9375rem;
19
+ --kumiko-slider-bubble-plain-weight: 700;
20
+ --kumiko-slider-bubble-plain-halo: Canvas;
21
+ }
22
+
23
+ /*
24
+ * The bubble is the thumb's child, centred over it, and grows out of the tip that touches the thumb.
25
+ * Each look sets the colours, the box and the tail through the --_ properties below.
26
+ * It starts at the bubble scale, and at full size where the motion theme has no pop (still, reduced motion), so only its fade remains.
27
+ * The tooltip look reads Tooltip's tokens, and the pill and pin read the slider's fill unless a token names a colour.
28
+ */
29
+ [data-slot="slider-bubble"] {
30
+ --_gap: var(--kumiko-slider-bubble-gap);
31
+ --_lift: 0px;
32
+ --_tail-w: 0px;
33
+ --_tail-h: 0px;
34
+ --_tail-in: 1px;
35
+ --_from: calc(
36
+ 1 - (1 - var(--kumiko-slider-bubble-scale)) *
37
+ min(1, (1 - var(--kumiko-pop-scale)) * 100)
38
+ );
39
+ --_bg: transparent;
40
+ --_fg: inherit;
41
+
42
+ position: absolute;
43
+ inset-block-end: calc(100% + var(--_gap) + var(--_tail-h) + var(--_lift));
44
+ left: 50%;
45
+ box-sizing: border-box;
46
+ background: var(--_bg);
47
+ color: var(--_fg);
48
+ font-variant-numeric: tabular-nums;
49
+ line-height: 1.4;
50
+ white-space: nowrap;
51
+ opacity: 0;
52
+ scale: var(--_from);
53
+ translate: -50% 0;
54
+ transform-origin: 50% calc(100% + var(--_tail-h));
55
+ transition:
56
+ opacity var(--kumiko-fade-duration) var(--kumiko-exit-ease),
57
+ scale var(--kumiko-fade-duration) var(--kumiko-exit-ease);
58
+ pointer-events: none;
59
+ }
60
+
61
+ /* The tail points at the thumb. It starts a little inside the bubble so no seam shows. */
62
+ [data-slot="slider-bubble"]::after {
63
+ content: "";
64
+ position: absolute;
65
+ top: calc(100% - var(--_tail-in));
66
+ left: 50%;
67
+ inline-size: var(--_tail-w);
68
+ block-size: calc(var(--_tail-h) + var(--_tail-in));
69
+ background: var(--_bg);
70
+ clip-path: polygon(0 0, 100% 0, 50% 100%);
71
+ translate: -50% 0;
72
+ }
73
+
74
+ /* A finger covers the thumb, so the bubble sits further from it. */
75
+ [data-slot="slider"][data-touch] [data-slot="slider-bubble"] {
76
+ --_lift: var(--kumiko-slider-bubble-touch-lift);
77
+ }
78
+
79
+ /* Beside the thumb, on the inline end side, with the tail on the edge that faces it. */
80
+ [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-bubble"] {
81
+ inset-block: 50% auto;
82
+ left: auto;
83
+ inset-inline-start: calc(100% + var(--_gap) + var(--_tail-h) + var(--_lift));
84
+ translate: 0 -50%;
85
+ transform-origin: calc(0% - var(--_tail-h)) 50%;
86
+ }
87
+
88
+ [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-bubble"]:dir(rtl) {
89
+ transform-origin: calc(100% + var(--_tail-h)) 50%;
90
+ }
91
+
92
+ [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-bubble"]::after {
93
+ top: 50%;
94
+ left: auto;
95
+ inset-inline-end: calc(100% - var(--_tail-in));
96
+ inline-size: calc(var(--_tail-h) + var(--_tail-in));
97
+ block-size: var(--_tail-w);
98
+ clip-path: polygon(0 50%, 100% 0, 100% 100%);
99
+ translate: 0 -50%;
100
+ }
101
+
102
+ [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-bubble"]:dir(rtl)::after {
103
+ clip-path: polygon(100% 50%, 0 0, 0 100%);
104
+ }
105
+
106
+ /* While its thumb is moved, the bubble grows out of the thumb on the pop tokens, and fades in on the fade tokens. */
107
+ [data-slot="slider-thumb"]:is([data-dragging], [data-adjusting], [data-revealed])
108
+ > [data-slot="slider-bubble"] {
109
+ opacity: 1;
110
+ scale: 1;
111
+ transition:
112
+ opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease),
113
+ scale var(--kumiko-pop-duration) var(--kumiko-pop-ease);
114
+ }
115
+
116
+ /* Tooltip: the same box, colours and arrow as Kumiko's Tooltip. */
117
+ [data-slot="slider"][data-bubble="tooltip"] [data-slot="slider-bubble"] {
118
+ --_tail-h: var(--kumiko-tooltip-arrow-size, 0.5rem);
119
+ --_tail-w: calc(var(--kumiko-tooltip-arrow-size, 0.5rem) * 2);
120
+ --_bg: var(--kumiko-tooltip-bg, CanvasText);
121
+ --_fg: var(--kumiko-tooltip-fg, Canvas);
122
+
123
+ padding: var(--kumiko-tooltip-padding, 0.3rem 0.6rem);
124
+ border-radius: var(--kumiko-tooltip-radius, 0.5rem);
125
+ box-shadow: var(
126
+ --kumiko-tooltip-shadow,
127
+ 0 6px 16px -6px color-mix(in oklab, CanvasText 40%, transparent)
128
+ );
129
+ font-size: var(--kumiko-tooltip-font-size, 0.8125rem);
130
+ font-weight: var(--kumiko-tooltip-font-weight, 500);
131
+ }
132
+
133
+ /* Pill: a round capsule in the fill colour, with a small tail and a shadow tinted like the fill. */
134
+ [data-slot="slider"][data-bubble="pill"] [data-slot="slider-bubble"] {
135
+ --_tail-h: 0.3125rem;
136
+ --_tail-w: 0.625rem;
137
+ --_bg: var(--kumiko-slider-bubble-pill-bg, var(--_fill));
138
+ --_fg: var(--kumiko-slider-bubble-pill-fg);
139
+
140
+ padding: var(--kumiko-slider-bubble-pill-padding);
141
+ border-radius: 999px;
142
+ box-shadow: var(
143
+ --kumiko-slider-bubble-pill-shadow,
144
+ 0 4px 10px -3px color-mix(in oklab, var(--_fill) 60%, transparent)
145
+ );
146
+ font-size: var(--kumiko-slider-bubble-pill-font-size);
147
+ font-weight: var(--kumiko-slider-bubble-pill-font-weight);
148
+ }
149
+
150
+ /* Pin: a teardrop in the fill colour, a circle with a point aimed at the thumb's centre, wider for long values. */
151
+ [data-slot="slider"][data-bubble="pin"] [data-slot="slider-bubble"] {
152
+ --_tail-h: 0.625rem;
153
+ --_tail-w: 1.25rem;
154
+ --_tail-in: 0.25rem;
155
+ --_bg: var(--kumiko-slider-bubble-pin-bg, var(--_fill));
156
+ --_fg: var(--kumiko-slider-bubble-pin-fg);
157
+
158
+ display: grid;
159
+ min-inline-size: var(--kumiko-slider-bubble-pin-size);
160
+ block-size: var(--kumiko-slider-bubble-pin-size);
161
+ padding-inline: var(--kumiko-slider-bubble-pin-padding);
162
+ place-items: center;
163
+ border-radius: 999px;
164
+ box-shadow: var(
165
+ --kumiko-slider-bubble-pin-shadow,
166
+ 0 4px 10px -3px color-mix(in oklab, var(--_fill) 60%, transparent)
167
+ );
168
+ font-size: var(--kumiko-slider-bubble-pin-font-size);
169
+ font-weight: var(--kumiko-slider-bubble-pin-font-weight);
170
+ line-height: 1;
171
+ }
172
+
173
+ /* Plain: no box, only the value in the fill colour, with a faint halo so it stays legible over anything. */
174
+ [data-slot="slider"][data-bubble="plain"] [data-slot="slider-bubble"] {
175
+ --_fg: var(--kumiko-slider-bubble-plain-color, var(--_fill));
176
+
177
+ font-size: var(--kumiko-slider-bubble-plain-size);
178
+ font-weight: var(--kumiko-slider-bubble-plain-weight);
179
+ text-shadow:
180
+ 0 0 2px var(--kumiko-slider-bubble-plain-halo),
181
+ 0 0 5px var(--kumiko-slider-bubble-plain-halo),
182
+ 0 0 8px var(--kumiko-slider-bubble-plain-halo);
183
+ }
184
+
185
+ [data-slot="slider"][data-bubble="plain"] [data-slot="slider-bubble"]::after {
186
+ content: none;
187
+ }
188
+
189
+ /* Forced colours replace the fills, so every look takes the system palette with an edge. */
190
+ @media (forced-colors: active) {
191
+ [data-slot="slider"][data-bubble] [data-slot="slider-bubble"] {
192
+ --_bg: Canvas;
193
+ --_fg: CanvasText;
194
+
195
+ border: 1px solid CanvasText;
196
+ text-shadow: none;
197
+ }
198
+
199
+ [data-slot="slider"][data-bubble] [data-slot="slider-bubble"]::after {
200
+ background: CanvasText;
201
+ }
202
+ }
203
+ }
@@ -0,0 +1,33 @@
1
+ import type { SliderValueChangeReason } from "@ui-sdk/react/slider";
2
+ type Handler<Event> = ((event: Event) => void) | undefined;
3
+ /** Runs the caller's handler first, then Kumiko's, so the caller can still see every event. */
4
+ export declare function alongside<Event>(callers: Handler<Event>, ours: (event: Event) => void): (event: Event) => void;
5
+ export interface SliderFeel {
6
+ /** True while a drag or a held key moves the value, so the thumb and fill follow with no transition. */
7
+ follow: boolean;
8
+ /** The thumb a key is adjusting, for its value bubble. */
9
+ keyed: number | null;
10
+ /** The thumb whose bubble is held on a little after it was moved, so a quick tap still shows it. */
11
+ shown: number | null;
12
+ /** Records why the value changed, and which thumb moved. */
13
+ changed: (reason: SliderValueChangeReason, thumb: number | null | undefined) => void;
14
+ pressed: (event: React.PointerEvent<HTMLElement>) => void;
15
+ /** True from a pointer press until the next key goes down, so the focus ring stays for keyboard use only. */
16
+ pointer: boolean;
17
+ /** True while the last press was a finger, so the bubble lifts out from under it. */
18
+ touch: boolean;
19
+ /** Ends a drag. */
20
+ released: () => void;
21
+ keyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
22
+ keyUp: () => void;
23
+ /** Ends a key and, once focus has left the slider with no press on it, the pointer's hold on the focus ring. */
24
+ blurred: (event: React.FocusEvent<HTMLElement>) => void;
25
+ }
26
+ /**
27
+ * What the slider is doing, which the look needs.
28
+ * Whether the value follows a pointer or key (no transition), or arrives by itself (a glide).
29
+ * Which thumb a key is adjusting, and which thumb's bubble is still on show.
30
+ * The delay is read as the press or key goes down, before ui-sdk moves the value, so the first change already knows it.
31
+ */
32
+ export declare function useSliderFeel(): SliderFeel;
33
+ export {};
@@ -0,0 +1,153 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ /** The reasons a value follows the pointer or the key at once, instead of gliding there. */
3
+ const following = new Set(["drag", "step-key", "accessibility-adjust"]);
4
+ /** The reasons that show the value bubble of the thumb that moved. */
5
+ const revealing = new Set([
6
+ "drag",
7
+ "track-press",
8
+ "step-key",
9
+ "accessibility-adjust"
10
+ ]);
11
+ /** The keys that adjust a thumb, which show the bubble while they are down. */
12
+ const adjusting = new Set([
13
+ "ArrowLeft",
14
+ "ArrowRight",
15
+ "ArrowUp",
16
+ "ArrowDown",
17
+ "PageUp",
18
+ "PageDown",
19
+ "Home",
20
+ "End"
21
+ ]);
22
+ /** Runs the caller's handler first, then Kumiko's, so the caller can still see every event. */
23
+ export function alongside(callers, ours) {
24
+ return (event) => {
25
+ callers?.(event);
26
+ ours(event);
27
+ };
28
+ }
29
+ /** The wait, in milliseconds, that the bubble token gives a slider before its bubble fades out. */
30
+ function bubbleDelay(root) {
31
+ const raw = getComputedStyle(root).getPropertyValue("--kumiko-slider-bubble-delay").trim();
32
+ const amount = Number(raw.replace(/m?s$/u, ""));
33
+ if (Number.isNaN(amount)) {
34
+ return 0;
35
+ }
36
+ return raw.endsWith("ms") ? amount : amount * 1000;
37
+ }
38
+ /** The index of the thumb an event happened in, if it happened in one. */
39
+ function thumbIn(target) {
40
+ const thumb = target instanceof Element ? target.closest('[data-slot="slider-thumb"]') : null;
41
+ return thumb instanceof HTMLElement && thumb.dataset.index !== undefined
42
+ ? Number(thumb.dataset.index)
43
+ : null;
44
+ }
45
+ const isLocked = (root) => Object.hasOwn(root.dataset, "readonly") || Object.hasOwn(root.dataset, "disabled");
46
+ /** Holds a thumb's bubble on for the bubble delay after the last thing done to it, so a tap shows it as long as a drag does. */
47
+ function useBubbleHold() {
48
+ const [shown, setShown] = useState(null);
49
+ const timer = useRef(undefined);
50
+ const held = useRef(null);
51
+ const delay = useRef(0);
52
+ useEffect(() => () => window.clearTimeout(timer.current), []);
53
+ const hold = (index) => {
54
+ window.clearTimeout(timer.current);
55
+ held.current = index;
56
+ setShown(index);
57
+ timer.current = window.setTimeout(() => {
58
+ held.current = null;
59
+ setShown(null);
60
+ }, delay.current);
61
+ };
62
+ const holdAgain = () => {
63
+ if (held.current !== null) {
64
+ hold(held.current);
65
+ }
66
+ };
67
+ return { shown, delay, hold, holdAgain };
68
+ }
69
+ /** Reads the bubble delay, and gives the thumb an event happened in unless the slider is locked. */
70
+ function thumbFor(event, delay) {
71
+ const index = thumbIn(event.target);
72
+ delay.current = bubbleDelay(event.currentTarget);
73
+ return index !== null && !isLocked(event.currentTarget) ? index : null;
74
+ }
75
+ /** Whether the last thing done to the slider was a pointer press, and whether that press was a finger. */
76
+ function usePressKind() {
77
+ const [pointer, setPointer] = useState(false);
78
+ const [touch, setTouch] = useState(false);
79
+ const pressing = useRef(false);
80
+ return {
81
+ pointer,
82
+ touch,
83
+ down: (event) => {
84
+ pressing.current = true;
85
+ setPointer(true);
86
+ setTouch(event.pointerType === "touch");
87
+ },
88
+ up: () => {
89
+ pressing.current = false;
90
+ },
91
+ key: () => setPointer(false),
92
+ left: (event) => {
93
+ if (!pressing.current && !event.currentTarget.contains(event.relatedTarget)) {
94
+ setPointer(false);
95
+ }
96
+ }
97
+ };
98
+ }
99
+ /**
100
+ * What the slider is doing, which the look needs.
101
+ * Whether the value follows a pointer or key (no transition), or arrives by itself (a glide).
102
+ * Which thumb a key is adjusting, and which thumb's bubble is still on show.
103
+ * The delay is read as the press or key goes down, before ui-sdk moves the value, so the first change already knows it.
104
+ */
105
+ export function useSliderFeel() {
106
+ const [follow, setFollow] = useState(false);
107
+ const [keyed, setKeyed] = useState(null);
108
+ const kind = usePressKind();
109
+ const { shown, delay, hold, holdAgain } = useBubbleHold();
110
+ const keyUp = () => {
111
+ setKeyed(null);
112
+ setFollow(false);
113
+ holdAgain();
114
+ };
115
+ return {
116
+ follow,
117
+ keyed,
118
+ shown,
119
+ pointer: kind.pointer,
120
+ touch: kind.touch,
121
+ changed: (reason, thumb) => {
122
+ setFollow(following.has(reason));
123
+ if (revealing.has(reason) && typeof thumb === "number") {
124
+ hold(thumb);
125
+ }
126
+ },
127
+ pressed: (event) => {
128
+ kind.down(event);
129
+ const index = thumbFor(event, delay);
130
+ if (index !== null) {
131
+ hold(index);
132
+ }
133
+ },
134
+ released: () => {
135
+ kind.up();
136
+ setFollow(false);
137
+ holdAgain();
138
+ },
139
+ keyDown: (event) => {
140
+ kind.key();
141
+ const index = thumbFor(event, delay);
142
+ if (adjusting.has(event.key) && index !== null) {
143
+ setKeyed(index);
144
+ hold(index);
145
+ }
146
+ },
147
+ keyUp,
148
+ blurred: (event) => {
149
+ keyUp();
150
+ kind.left(event);
151
+ }
152
+ };
153
+ }
@@ -0,0 +1,13 @@
1
+ import type { NumberFormat } from "@ui-sdk/react/slider";
2
+ export interface ThumbFormat {
3
+ /** The slider's `format` prop. */
4
+ format: NumberFormat | undefined;
5
+ /** The slider's `locale` prop. */
6
+ locale: string | undefined;
7
+ /** The locale of the nearest `lang` ancestor, or the browser's, as ui-sdk reads it once the slider is mounted. */
8
+ pageLocale: string | undefined;
9
+ /** The slider's step, which sets how many decimals show. */
10
+ step: number;
11
+ }
12
+ /** The text a bubble shows for one thumb's value: exactly the `aria-valuetext` ui-sdk puts on that thumb. */
13
+ export declare function formatThumb(value: number, { format, locale, pageLocale, step }: ThumbFormat): string;
@@ -0,0 +1,15 @@
1
+ import { decimalsOf, formatNumber, numberFormatter } from "@ui-sdk/react/number";
2
+ /** The format options ui-sdk gives its thumbs (its `displayOptions` is not public): enough fraction digits for the step, unless the format names its own. */
3
+ function withDecimals(format, step) {
4
+ const options = { ...format };
5
+ if (options.maximumFractionDigits === undefined &&
6
+ options.maximumSignificantDigits === undefined) {
7
+ const decimals = decimalsOf(step) + (options.style === "percent" ? -2 : 0);
8
+ options.maximumFractionDigits = Math.max(options.minimumFractionDigits ?? 0, decimals, numberFormatter(undefined, format).resolvedOptions().maximumFractionDigits ?? 0);
9
+ }
10
+ return options;
11
+ }
12
+ /** The text a bubble shows for one thumb's value: exactly the `aria-valuetext` ui-sdk puts on that thumb. */
13
+ export function formatThumb(value, { format, locale, pageLocale, step }) {
14
+ return formatNumber(value, locale ?? pageLocale ?? "en-US", typeof format === "function" ? format : withDecimals(format, step));
15
+ }
@@ -0,0 +1,16 @@
1
+ /** The most steps a slider can have and still draw a mark at each. Above this no marks are drawn. */
2
+ export declare const maxMarkSteps = 20;
3
+ export interface Mark {
4
+ /** The value the mark stands for. */
5
+ value: number;
6
+ /** Where it sits along the track, from 0 to 100. */
7
+ percent: number;
8
+ }
9
+ /**
10
+ * The marks along a track, one at each step from `min`.
11
+ * A track whose steps do not land on `max` ends at the highest step below it, as the slider does.
12
+ * Nothing is drawn above `maxMarkSteps` steps, or when the step or the range makes no sense.
13
+ */
14
+ export declare function marksFor(min: number, max: number, step: number): Mark[];
15
+ /** True when the fill covers a mark: up to a single thumb, or between a range's first and last thumb. */
16
+ export declare function isPassed(mark: number, values: readonly number[]): boolean;
@@ -0,0 +1,32 @@
1
+ /** The most steps a slider can have and still draw a mark at each. Above this no marks are drawn. */
2
+ export const maxMarkSteps = 20;
3
+ /** Rounds away the tiny errors of decimal steps, so 0.1 times 3 is 0.3. */
4
+ const tidy = (value) => Math.round(value * 1e9) / 1e9;
5
+ /**
6
+ * The marks along a track, one at each step from `min`.
7
+ * A track whose steps do not land on `max` ends at the highest step below it, as the slider does.
8
+ * Nothing is drawn above `maxMarkSteps` steps, or when the step or the range makes no sense.
9
+ */
10
+ export function marksFor(min, max, step) {
11
+ const span = max - min;
12
+ if (!(step > 0) || !(span > 0)) {
13
+ return [];
14
+ }
15
+ const steps = Math.floor(tidy(span / step));
16
+ if (steps > maxMarkSteps) {
17
+ return [];
18
+ }
19
+ return Array.from({ length: steps + 1 }, (_, index) => {
20
+ const value = tidy(min + index * step);
21
+ return { value, percent: tidy(((value - min) / span) * 100) };
22
+ });
23
+ }
24
+ /** True when the fill covers a mark: up to a single thumb, or between a range's first and last thumb. */
25
+ export function isPassed(mark, values) {
26
+ const first = values[0];
27
+ const last = values.at(-1);
28
+ if (first === undefined || last === undefined) {
29
+ return false;
30
+ }
31
+ return values.length > 1 ? mark >= first && mark <= last : mark <= last;
32
+ }