@szum-tech/design-system 3.12.3 → 3.14.0

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 (94) hide show
  1. package/dist/chunk-4IGU5SVP.js +54 -0
  2. package/dist/{chunk-XJZOANXX.cjs → chunk-6HX7ETL3.cjs} +1 -1
  3. package/dist/chunk-7OD2NBSV.cjs +50 -0
  4. package/dist/chunk-B4M7Q5KX.cjs +25 -0
  5. package/dist/{chunk-S2BCU6WG.cjs → chunk-CAIAZGSW.cjs} +5 -4
  6. package/dist/chunk-EOTQVIA5.js +993 -0
  7. package/dist/chunk-EZCWHR56.cjs +2355 -0
  8. package/dist/chunk-G24PWQKG.js +20 -0
  9. package/dist/chunk-GEDBA3JU.cjs +49 -0
  10. package/dist/chunk-IZU3KULT.js +41 -0
  11. package/dist/{chunk-KQ6QE7BT.cjs → chunk-MNDQXDV4.cjs} +4 -4
  12. package/dist/chunk-N4TYSZSU.cjs +44 -0
  13. package/dist/chunk-OZSNSRLV.cjs +1027 -0
  14. package/dist/{chunk-DL54DIMD.js → chunk-Q2MJKFIE.js} +2 -1
  15. package/dist/chunk-S3ZUFD6U.js +23 -0
  16. package/dist/{chunk-WXZE35FK.js → chunk-VK2FJ65F.js} +1 -1
  17. package/dist/chunk-VL3TPVSB.js +2299 -0
  18. package/dist/chunk-X5O7GP4S.js +48 -0
  19. package/dist/{chunk-E5TYGWGE.js → chunk-XKCLVPUC.js} +1 -1
  20. package/dist/{chunk-XIQUR62A.cjs → chunk-XY3ZNUWR.cjs} +32 -20
  21. package/dist/color-picker.types-GI7dq2Ig.d.cts +42 -0
  22. package/dist/color-picker.types-GI7dq2Ig.d.ts +42 -0
  23. package/dist/components/badge-overflow/index.cjs +3 -2
  24. package/dist/components/badge-overflow/index.js +2 -1
  25. package/dist/components/button/index.cjs +16 -12
  26. package/dist/components/button/index.d.cts +1 -0
  27. package/dist/components/button/index.d.ts +1 -0
  28. package/dist/components/button/index.js +15 -11
  29. package/dist/components/carousel/index.cjs +17 -13
  30. package/dist/components/carousel/index.d.cts +1 -0
  31. package/dist/components/carousel/index.d.ts +1 -0
  32. package/dist/components/carousel/index.js +15 -11
  33. package/dist/components/color-picker/index.cjs +88 -0
  34. package/dist/components/color-picker/index.d.cts +71 -0
  35. package/dist/components/color-picker/index.d.ts +71 -0
  36. package/dist/components/color-picker/index.js +39 -0
  37. package/dist/components/dialog/index.d.cts +1 -0
  38. package/dist/components/dialog/index.d.ts +1 -0
  39. package/dist/components/file-upload/index.cjs +60 -0
  40. package/dist/components/file-upload/index.d.cts +131 -0
  41. package/dist/components/file-upload/index.d.ts +131 -0
  42. package/dist/components/file-upload/index.js +3 -0
  43. package/dist/components/index.cjs +216 -84
  44. package/dist/components/index.d.cts +8 -1
  45. package/dist/components/index.d.ts +8 -1
  46. package/dist/components/index.js +15 -11
  47. package/dist/components/input/index.cjs +2 -2
  48. package/dist/components/input/index.js +1 -1
  49. package/dist/components/item/index.d.cts +1 -0
  50. package/dist/components/item/index.d.ts +1 -0
  51. package/dist/components/masonry/index.cjs +5 -4
  52. package/dist/components/masonry/index.js +3 -2
  53. package/dist/components/popover/index.cjs +35 -0
  54. package/dist/components/popover/index.d.cts +18 -0
  55. package/dist/components/popover/index.d.ts +18 -0
  56. package/dist/components/popover/index.js +2 -0
  57. package/dist/components/select/index.cjs +7 -7
  58. package/dist/components/select/index.d.cts +8 -14
  59. package/dist/components/select/index.d.ts +8 -14
  60. package/dist/components/select/index.js +1 -1
  61. package/dist/components/sheet/index.d.cts +2 -1
  62. package/dist/components/sheet/index.d.ts +2 -1
  63. package/dist/components/stepper/index.cjs +34 -30
  64. package/dist/components/stepper/index.d.cts +1 -0
  65. package/dist/components/stepper/index.d.ts +1 -0
  66. package/dist/components/stepper/index.js +15 -11
  67. package/dist/components/switch/index.cjs +11 -0
  68. package/dist/components/switch/index.d.cts +19 -0
  69. package/dist/components/switch/index.d.ts +19 -0
  70. package/dist/components/switch/index.js +2 -0
  71. package/dist/components/timeline/index.cjs +12 -11
  72. package/dist/components/timeline/index.d.cts +1 -0
  73. package/dist/components/timeline/index.d.ts +1 -0
  74. package/dist/components/timeline/index.js +3 -2
  75. package/dist/components/toaster/index.cjs +17 -13
  76. package/dist/components/toaster/index.js +15 -11
  77. package/dist/components/typing-text/index.d.cts +1 -0
  78. package/dist/components/typing-text/index.d.ts +1 -0
  79. package/dist/components/word-rotate/index.d.cts +1 -0
  80. package/dist/components/word-rotate/index.d.ts +1 -0
  81. package/dist/hooks/index.cjs +17 -8
  82. package/dist/hooks/index.d.cts +15 -4
  83. package/dist/hooks/index.d.ts +15 -4
  84. package/dist/hooks/index.js +2 -1
  85. package/dist/popover-trigger-Cf4PPj0z.d.cts +14 -0
  86. package/dist/popover-trigger-Cf4PPj0z.d.ts +14 -0
  87. package/dist/select-Bf6XQtt-.d.cts +12 -0
  88. package/dist/select-Bf6XQtt-.d.ts +12 -0
  89. package/package.json +1 -1
  90. package/dist/chunk-5AA4IE2T.cjs +0 -27
  91. package/dist/chunk-CP43WJCN.cjs +0 -1065
  92. package/dist/chunk-QTYNFISP.js +0 -1020
  93. package/dist/chunk-SB5UG7OC.js +0 -41
  94. package/dist/chunk-UGSNASZM.js +0 -25
@@ -0,0 +1,2299 @@
1
+ import { Input } from './chunk-S3ZUFD6U.js';
2
+ import { Spinner } from './chunk-P5IUC7HJ.js';
3
+ import { useDirection, useComposedRefs as useComposedRefs$1 } from './chunk-VK2FJ65F.js';
4
+ import { Popover, PopoverTrigger, PopoverContent } from './chunk-IZU3KULT.js';
5
+ import { Select, SelectContent, SelectItem } from './chunk-XKCLVPUC.js';
6
+ import { useComposedRefs } from './chunk-4IGU5SVP.js';
7
+ import { useLazyRef, useAsRef, useIsomorphicLayoutEffect } from './chunk-G24PWQKG.js';
8
+ import { cn } from './chunk-ZD2QRAOX.js';
9
+ import * as React16 from 'react';
10
+ import { Slot as Slot$1 } from '@radix-ui/react-slot';
11
+ import { Direction, Slot, Slider } from 'radix-ui';
12
+ import { jsx, jsxs } from 'react/jsx-runtime';
13
+ import { PipetteIcon, OctagonXIcon, TriangleAlertIcon, InfoIcon, CircleCheckIcon } from 'lucide-react';
14
+ import { cva } from 'class-variance-authority';
15
+ import { Toaster as Toaster$1 } from 'sonner';
16
+ export { toast } from 'sonner';
17
+
18
+ function VisuallyHiddenInput(props) {
19
+ const { control, value, checked, bubbles = true, type = "hidden", style, ...inputProps } = props;
20
+ const isCheckInput = React16.useMemo(() => type === "checkbox" || type === "radio" || type === "switch", [type]);
21
+ const inputRef = React16.useRef(null);
22
+ const prevValueRef = React16.useRef({
23
+ value: isCheckInput ? checked : value,
24
+ previous: isCheckInput ? checked : value
25
+ });
26
+ const prevValue = React16.useMemo(() => {
27
+ const currentValue = isCheckInput ? checked : value;
28
+ if (prevValueRef.current.value !== currentValue) {
29
+ prevValueRef.current.previous = prevValueRef.current.value;
30
+ prevValueRef.current.value = currentValue;
31
+ }
32
+ return prevValueRef.current.previous;
33
+ }, [isCheckInput, value, checked]);
34
+ const [controlSize, setControlSize] = React16.useState({});
35
+ React16.useLayoutEffect(() => {
36
+ if (!control) {
37
+ setControlSize({});
38
+ return;
39
+ }
40
+ setControlSize({
41
+ width: control.offsetWidth,
42
+ height: control.offsetHeight
43
+ });
44
+ if (typeof window === "undefined") return;
45
+ const resizeObserver = new ResizeObserver((entries) => {
46
+ if (!Array.isArray(entries) || !entries.length) return;
47
+ const entry = entries[0];
48
+ if (!entry) return;
49
+ let width;
50
+ let height;
51
+ if ("borderBoxSize" in entry) {
52
+ const borderSizeEntry = entry.borderBoxSize;
53
+ const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
54
+ width = borderSize.inlineSize;
55
+ height = borderSize.blockSize;
56
+ } else {
57
+ width = control.offsetWidth;
58
+ height = control.offsetHeight;
59
+ }
60
+ setControlSize({ width, height });
61
+ });
62
+ resizeObserver.observe(control, { box: "border-box" });
63
+ return () => {
64
+ resizeObserver.disconnect();
65
+ };
66
+ }, [control]);
67
+ React16.useEffect(() => {
68
+ const input = inputRef.current;
69
+ if (!input) return;
70
+ const inputProto = window.HTMLInputElement.prototype;
71
+ const propertyKey = isCheckInput ? "checked" : "value";
72
+ const eventType = isCheckInput ? "click" : "input";
73
+ const currentValue = isCheckInput ? checked : value;
74
+ const serializedCurrentValue = isCheckInput ? checked : typeof value === "object" && value !== null ? JSON.stringify(value) : value;
75
+ const descriptor = Object.getOwnPropertyDescriptor(inputProto, propertyKey);
76
+ const setter = descriptor?.set;
77
+ if (prevValue !== currentValue && setter) {
78
+ const event = new Event(eventType, { bubbles });
79
+ setter.call(input, serializedCurrentValue);
80
+ input.dispatchEvent(event);
81
+ }
82
+ }, [prevValue, value, checked, bubbles, isCheckInput]);
83
+ const composedStyle = React16.useMemo(() => {
84
+ return {
85
+ ...style,
86
+ ...controlSize.width !== void 0 && controlSize.height !== void 0 ? controlSize : {},
87
+ border: 0,
88
+ clip: "rect(0 0 0 0)",
89
+ clipPath: "inset(50%)",
90
+ height: "1px",
91
+ margin: "-1px",
92
+ overflow: "hidden",
93
+ padding: 0,
94
+ position: "absolute",
95
+ whiteSpace: "nowrap",
96
+ width: "1px"
97
+ };
98
+ }, [style, controlSize]);
99
+ return /* @__PURE__ */ jsx(
100
+ "input",
101
+ {
102
+ type,
103
+ ...inputProps,
104
+ ref: inputRef,
105
+ "aria-hidden": isCheckInput,
106
+ tabIndex: -1,
107
+ defaultChecked: isCheckInput ? checked : void 0,
108
+ style: composedStyle
109
+ }
110
+ );
111
+ }
112
+
113
+ // src/components/color-picker/color-picker.constants.ts
114
+ var COLOR_PICKER_ROOT_NAME = "ColorPicker";
115
+ var COLOR_PICKER_IMPL_NAME = "ColorPickerImpl";
116
+ var COLOR_PICKER_TRIGGER_NAME = "ColorPickerTrigger";
117
+ var COLOR_PICKER_CONTENT_NAME = "ColorPickerContent";
118
+ var COLOR_PICKER_AREA_NAME = "ColorPickerArea";
119
+ var COLOR_PICKER_HUE_SLIDER_NAME = "ColorPickerHueSlider";
120
+ var COLOR_PICKER_ALPHA_SLIDER_NAME = "ColorPickerAlphaSlider";
121
+ var COLOR_PICKER_SWATCH_NAME = "ColorPickerSwatch";
122
+ var COLOR_PICKER_EYE_DROPPER_NAME = "ColorPickerEyeDropper";
123
+ var COLOR_PICKER_FORMAT_SELECT_NAME = "ColorPickerFormatSelect";
124
+ var COLOR_PICKER_INPUT_NAME = "ColorPickerInput";
125
+ var COLOR_FORMATS = ["hex", "rgb", "hsl", "hsb"];
126
+ var ColorPickerContext = React16.createContext(null);
127
+ function useColorPickerContext(consumerName) {
128
+ const context = React16.useContext(ColorPickerContext);
129
+ if (!context) {
130
+ throw new Error(`\`${consumerName}\` must be used within \`${COLOR_PICKER_ROOT_NAME}\``);
131
+ }
132
+ return context;
133
+ }
134
+
135
+ // src/components/color-picker/color-picker.utils.ts
136
+ function hexToRgb(hex, alpha) {
137
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
138
+ return result ? {
139
+ r: Number.parseInt(result[1] ?? "0", 16),
140
+ g: Number.parseInt(result[2] ?? "0", 16),
141
+ b: Number.parseInt(result[3] ?? "0", 16),
142
+ a: alpha ?? 1
143
+ } : { r: 0, g: 0, b: 0, a: alpha ?? 1 };
144
+ }
145
+ function rgbToHex(color) {
146
+ const toHex = (n) => {
147
+ const hex = Math.round(n).toString(16);
148
+ return hex.length === 1 ? `0${hex}` : hex;
149
+ };
150
+ return `#${toHex(color.r)}${toHex(color.g)}${toHex(color.b)}`;
151
+ }
152
+ function rgbToHsv(color) {
153
+ const r = color.r / 255;
154
+ const g = color.g / 255;
155
+ const b = color.b / 255;
156
+ const max = Math.max(r, g, b);
157
+ const min = Math.min(r, g, b);
158
+ const diff = max - min;
159
+ let h = 0;
160
+ if (diff !== 0) {
161
+ switch (max) {
162
+ case r:
163
+ h = (g - b) / diff % 6;
164
+ break;
165
+ case g:
166
+ h = (b - r) / diff + 2;
167
+ break;
168
+ case b:
169
+ h = (r - g) / diff + 4;
170
+ break;
171
+ }
172
+ }
173
+ h = Math.round(h * 60);
174
+ if (h < 0) h += 360;
175
+ const s = max === 0 ? 0 : diff / max;
176
+ return {
177
+ h,
178
+ s: Math.round(s * 100),
179
+ v: Math.round(max * 100),
180
+ a: color.a
181
+ };
182
+ }
183
+ function hsvToRgb(hsv) {
184
+ const h = hsv.h / 360;
185
+ const s = hsv.s / 100;
186
+ const v = hsv.v / 100;
187
+ const i = Math.floor(h * 6);
188
+ const f = h * 6 - i;
189
+ const p = v * (1 - s);
190
+ const q = v * (1 - f * s);
191
+ const t = v * (1 - (1 - f) * s);
192
+ let r;
193
+ let g;
194
+ let b;
195
+ switch (i % 6) {
196
+ case 0: {
197
+ r = v;
198
+ g = t;
199
+ b = p;
200
+ break;
201
+ }
202
+ case 1: {
203
+ r = q;
204
+ g = v;
205
+ b = p;
206
+ break;
207
+ }
208
+ case 2: {
209
+ r = p;
210
+ g = v;
211
+ b = t;
212
+ break;
213
+ }
214
+ case 3: {
215
+ r = p;
216
+ g = q;
217
+ b = v;
218
+ break;
219
+ }
220
+ case 4: {
221
+ r = t;
222
+ g = p;
223
+ b = v;
224
+ break;
225
+ }
226
+ case 5: {
227
+ r = v;
228
+ g = p;
229
+ b = q;
230
+ break;
231
+ }
232
+ default: {
233
+ r = 0;
234
+ g = 0;
235
+ b = 0;
236
+ }
237
+ }
238
+ return {
239
+ r: Math.round(r * 255),
240
+ g: Math.round(g * 255),
241
+ b: Math.round(b * 255),
242
+ a: hsv.a
243
+ };
244
+ }
245
+ function rgbToHsl(color) {
246
+ const r = color.r / 255;
247
+ const g = color.g / 255;
248
+ const b = color.b / 255;
249
+ const max = Math.max(r, g, b);
250
+ const min = Math.min(r, g, b);
251
+ const diff = max - min;
252
+ const sum = max + min;
253
+ const l = sum / 2;
254
+ let h = 0;
255
+ let s = 0;
256
+ if (diff !== 0) {
257
+ s = l > 0.5 ? diff / (2 - sum) : diff / sum;
258
+ if (max === r) {
259
+ h = (g - b) / diff + (g < b ? 6 : 0);
260
+ } else if (max === g) {
261
+ h = (b - r) / diff + 2;
262
+ } else if (max === b) {
263
+ h = (r - g) / diff + 4;
264
+ }
265
+ h /= 6;
266
+ }
267
+ return {
268
+ h: Math.round(h * 360),
269
+ s: Math.round(s * 100),
270
+ l: Math.round(l * 100)
271
+ };
272
+ }
273
+ function hslToRgb(hsl, alpha = 1) {
274
+ const h = hsl.h / 360;
275
+ const s = hsl.s / 100;
276
+ const l = hsl.l / 100;
277
+ const c = (1 - Math.abs(2 * l - 1)) * s;
278
+ const x = c * (1 - Math.abs(h * 6 % 2 - 1));
279
+ const m = l - c / 2;
280
+ let r = 0;
281
+ let g = 0;
282
+ let b = 0;
283
+ if (h >= 0 && h < 1 / 6) {
284
+ r = c;
285
+ g = x;
286
+ b = 0;
287
+ } else if (h >= 1 / 6 && h < 2 / 6) {
288
+ r = x;
289
+ g = c;
290
+ b = 0;
291
+ } else if (h >= 2 / 6 && h < 3 / 6) {
292
+ r = 0;
293
+ g = c;
294
+ b = x;
295
+ } else if (h >= 3 / 6 && h < 4 / 6) {
296
+ r = 0;
297
+ g = x;
298
+ b = c;
299
+ } else if (h >= 4 / 6 && h < 5 / 6) {
300
+ r = x;
301
+ g = 0;
302
+ b = c;
303
+ } else if (h >= 5 / 6 && h < 1) {
304
+ r = c;
305
+ g = 0;
306
+ b = x;
307
+ }
308
+ return {
309
+ r: Math.round((r + m) * 255),
310
+ g: Math.round((g + m) * 255),
311
+ b: Math.round((b + m) * 255),
312
+ a: alpha
313
+ };
314
+ }
315
+ function colorToString(color, format = "hex") {
316
+ switch (format) {
317
+ case "hex":
318
+ return rgbToHex(color);
319
+ case "rgb":
320
+ return color.a < 1 ? `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})` : `rgb(${color.r}, ${color.g}, ${color.b})`;
321
+ case "hsl": {
322
+ const hsl = rgbToHsl(color);
323
+ return color.a < 1 ? `hsla(${hsl.h}, ${hsl.s}%, ${hsl.l}%, ${color.a})` : `hsl(${hsl.h}, ${hsl.s}%, ${hsl.l}%)`;
324
+ }
325
+ case "hsb": {
326
+ const hsv = rgbToHsv(color);
327
+ return color.a < 1 ? `hsba(${hsv.h}, ${hsv.s}%, ${hsv.v}%, ${color.a})` : `hsb(${hsv.h}, ${hsv.s}%, ${hsv.v}%)`;
328
+ }
329
+ default:
330
+ return rgbToHex(color);
331
+ }
332
+ }
333
+ function parseColorString(value) {
334
+ const trimmed = value.trim();
335
+ if (trimmed.startsWith("#")) {
336
+ const hexMatch = trimmed.match(/^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$/);
337
+ if (hexMatch) return hexToRgb(trimmed);
338
+ }
339
+ const rgbMatch = trimmed.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);
340
+ if (rgbMatch) {
341
+ return {
342
+ r: Number.parseInt(rgbMatch[1] ?? "0", 10),
343
+ g: Number.parseInt(rgbMatch[2] ?? "0", 10),
344
+ b: Number.parseInt(rgbMatch[3] ?? "0", 10),
345
+ a: rgbMatch[4] ? Number.parseFloat(rgbMatch[4]) : 1
346
+ };
347
+ }
348
+ const hslMatch = trimmed.match(/^hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([\d.]+))?\s*\)$/);
349
+ if (hslMatch) {
350
+ const h = Number.parseInt(hslMatch[1] ?? "0", 10);
351
+ const s = Number.parseInt(hslMatch[2] ?? "0", 10) / 100;
352
+ const l = Number.parseInt(hslMatch[3] ?? "0", 10) / 100;
353
+ const a = hslMatch[4] ? Number.parseFloat(hslMatch[4]) : 1;
354
+ const c = (1 - Math.abs(2 * l - 1)) * s;
355
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
356
+ const m = l - c / 2;
357
+ let r = 0;
358
+ let g = 0;
359
+ let b = 0;
360
+ if (h >= 0 && h < 60) {
361
+ r = c;
362
+ g = x;
363
+ } else if (h >= 60 && h < 120) {
364
+ r = x;
365
+ g = c;
366
+ } else if (h >= 120 && h < 180) {
367
+ g = c;
368
+ b = x;
369
+ } else if (h >= 180 && h < 240) {
370
+ g = x;
371
+ b = c;
372
+ } else if (h >= 240 && h < 300) {
373
+ r = x;
374
+ b = c;
375
+ } else if (h >= 300 && h < 360) {
376
+ r = c;
377
+ b = x;
378
+ }
379
+ return {
380
+ r: Math.round((r + m) * 255),
381
+ g: Math.round((g + m) * 255),
382
+ b: Math.round((b + m) * 255),
383
+ a
384
+ };
385
+ }
386
+ const hsbMatch = trimmed.match(/^hsba?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*([\d.]+))?\s*\)$/);
387
+ if (hsbMatch) {
388
+ const h = Number.parseInt(hsbMatch[1] ?? "0", 10);
389
+ const s = Number.parseInt(hsbMatch[2] ?? "0", 10);
390
+ const v = Number.parseInt(hsbMatch[3] ?? "0", 10);
391
+ const a = hsbMatch[4] ? Number.parseFloat(hsbMatch[4]) : 1;
392
+ return hsvToRgb({ h, s, v, a });
393
+ }
394
+ return null;
395
+ }
396
+
397
+ // src/components/color-picker/color-picker.store.tsx
398
+ var ColorPickerStoreContext = React16.createContext(null);
399
+ function useColorPickerStoreContext(consumerName) {
400
+ const context = React16.useContext(ColorPickerStoreContext);
401
+ if (!context) {
402
+ throw new Error(`\`${consumerName}\` must be used within \`ColorPicker\``);
403
+ }
404
+ return context;
405
+ }
406
+ function useColorPickerStore(selector) {
407
+ const store = useColorPickerStoreContext("useColorPickerStore");
408
+ const getSnapshot = React16.useCallback(() => selector(store.getState()), [store, selector]);
409
+ return React16.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
410
+ }
411
+ function createColorPickerStore(listenersRef, stateRef, propsRef) {
412
+ const store = {
413
+ subscribe: (cb) => {
414
+ listenersRef.current.add(cb);
415
+ return () => listenersRef.current.delete(cb);
416
+ },
417
+ getState: () => stateRef.current,
418
+ setColor: (value) => {
419
+ if (Object.is(stateRef.current.color, value)) return;
420
+ const prevState = { ...stateRef.current };
421
+ stateRef.current.color = value;
422
+ if (propsRef.current.onValueChange) {
423
+ propsRef.current.onValueChange(colorToString(value, prevState.format));
424
+ }
425
+ store.notify();
426
+ },
427
+ setHsv: (value) => {
428
+ if (Object.is(stateRef.current.hsv, value)) return;
429
+ const prevState = { ...stateRef.current };
430
+ stateRef.current.hsv = value;
431
+ if (propsRef.current.onValueChange) {
432
+ propsRef.current.onValueChange(colorToString(hsvToRgb(value), prevState.format));
433
+ }
434
+ store.notify();
435
+ },
436
+ setOpen: (value) => {
437
+ if (Object.is(stateRef.current.open, value)) return;
438
+ stateRef.current.open = value;
439
+ propsRef.current.onOpenChange?.(value);
440
+ store.notify();
441
+ },
442
+ setFormat: (value) => {
443
+ if (Object.is(stateRef.current.format, value)) return;
444
+ stateRef.current.format = value;
445
+ propsRef.current.onFormatChange?.(value);
446
+ store.notify();
447
+ },
448
+ notify: () => {
449
+ for (const cb of listenersRef.current) cb();
450
+ }
451
+ };
452
+ return store;
453
+ }
454
+ function ColorPicker(props) {
455
+ const {
456
+ value: valueProp,
457
+ defaultValue = "#000000",
458
+ onValueChange,
459
+ format: formatProp,
460
+ defaultFormat = "hex",
461
+ onFormatChange,
462
+ defaultOpen,
463
+ open: openProp,
464
+ onOpenChange,
465
+ modal,
466
+ name,
467
+ disabled,
468
+ inline,
469
+ readOnly,
470
+ required,
471
+ ...rootProps
472
+ } = props;
473
+ const listenersRef = useLazyRef(() => /* @__PURE__ */ new Set());
474
+ const stateRef = useLazyRef(() => {
475
+ const colorString = valueProp ?? defaultValue;
476
+ const color = hexToRgb(colorString);
477
+ return {
478
+ color,
479
+ hsv: rgbToHsv(color),
480
+ open: openProp ?? defaultOpen ?? false,
481
+ format: formatProp ?? defaultFormat
482
+ };
483
+ });
484
+ const propsRef = useAsRef({ onValueChange, onOpenChange, onFormatChange });
485
+ const store = React16.useMemo(
486
+ () => createColorPickerStore(listenersRef, stateRef, propsRef),
487
+ [listenersRef, stateRef, propsRef]
488
+ );
489
+ return /* @__PURE__ */ jsx(ColorPickerStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsx(
490
+ ColorPickerImpl,
491
+ {
492
+ ...rootProps,
493
+ value: valueProp,
494
+ defaultOpen,
495
+ open: openProp,
496
+ modal,
497
+ name,
498
+ disabled,
499
+ inline,
500
+ readOnly,
501
+ required
502
+ }
503
+ ) });
504
+ }
505
+ function ColorPickerImpl(props) {
506
+ const {
507
+ value: valueProp,
508
+ dir: dirProp,
509
+ defaultOpen,
510
+ open: openProp,
511
+ modal,
512
+ name,
513
+ ref,
514
+ asChild,
515
+ disabled,
516
+ inline,
517
+ readOnly,
518
+ required,
519
+ ...rootProps
520
+ } = props;
521
+ const store = useColorPickerStoreContext(COLOR_PICKER_IMPL_NAME);
522
+ const dir = Direction.useDirection(dirProp);
523
+ const [formTrigger, setFormTrigger] = React16.useState(null);
524
+ const composedRef = useComposedRefs(ref, (node) => setFormTrigger(node));
525
+ const isFormControl = formTrigger ? !!formTrigger.closest("form") : true;
526
+ useIsomorphicLayoutEffect(() => {
527
+ if (valueProp !== void 0) {
528
+ const currentState = store.getState();
529
+ const color = hexToRgb(valueProp, currentState.color.a);
530
+ store.setColor(color);
531
+ store.setHsv(rgbToHsv(color));
532
+ }
533
+ }, [valueProp]);
534
+ useIsomorphicLayoutEffect(() => {
535
+ if (openProp !== void 0) {
536
+ store.setOpen(openProp);
537
+ }
538
+ }, [openProp]);
539
+ const contextValue = React16.useMemo(
540
+ () => ({ dir, disabled, inline, readOnly, required }),
541
+ [dir, disabled, inline, readOnly, required]
542
+ );
543
+ const value = useColorPickerStore((state) => rgbToHex(state.color));
544
+ const open = useColorPickerStore((state) => state.open);
545
+ const RootPrimitive = asChild ? Slot.Slot : "div";
546
+ if (inline) {
547
+ return /* @__PURE__ */ jsxs(ColorPickerContext.Provider, { value: contextValue, children: [
548
+ /* @__PURE__ */ jsx(RootPrimitive, { "data-slot": "color-picker", ...rootProps, ref: composedRef }),
549
+ isFormControl && /* @__PURE__ */ jsx(
550
+ VisuallyHiddenInput,
551
+ {
552
+ type: "hidden",
553
+ control: formTrigger,
554
+ name,
555
+ value,
556
+ disabled,
557
+ readOnly,
558
+ required
559
+ }
560
+ )
561
+ ] });
562
+ }
563
+ return /* @__PURE__ */ jsx(ColorPickerContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(Popover, { defaultOpen, open, onOpenChange: store.setOpen, modal, children: [
564
+ /* @__PURE__ */ jsx(RootPrimitive, { "data-slot": "color-picker", ...rootProps, ref: composedRef }),
565
+ isFormControl && /* @__PURE__ */ jsx(
566
+ VisuallyHiddenInput,
567
+ {
568
+ type: "hidden",
569
+ control: formTrigger,
570
+ name,
571
+ value,
572
+ disabled,
573
+ readOnly,
574
+ required
575
+ }
576
+ )
577
+ ] }) });
578
+ }
579
+ function ColorPickerTrigger(props) {
580
+ const { asChild, disabled, ...triggerProps } = props;
581
+ const context = useColorPickerContext(COLOR_PICKER_TRIGGER_NAME);
582
+ const isDisabled = disabled || context.disabled;
583
+ const TriggerPrimitive = asChild ? Slot.Slot : Button;
584
+ return /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, disabled: isDisabled, children: /* @__PURE__ */ jsx(TriggerPrimitive, { "data-slot": "color-picker-trigger", ...triggerProps }) });
585
+ }
586
+ function ColorPickerContent(props) {
587
+ const { asChild, className, children, ...popoverContentProps } = props;
588
+ const context = useColorPickerContext(COLOR_PICKER_CONTENT_NAME);
589
+ if (context.inline) {
590
+ const ContentPrimitive = asChild ? Slot.Slot : "div";
591
+ return /* @__PURE__ */ jsx(
592
+ ContentPrimitive,
593
+ {
594
+ "data-slot": "color-picker-content",
595
+ ...popoverContentProps,
596
+ className: cn("flex w-[340px] flex-col gap-4 p-4", className),
597
+ children
598
+ }
599
+ );
600
+ }
601
+ return /* @__PURE__ */ jsx(
602
+ PopoverContent,
603
+ {
604
+ "data-slot": "color-picker-content",
605
+ asChild,
606
+ ...popoverContentProps,
607
+ className: cn("flex w-[340px] flex-col gap-4 p-4", className),
608
+ children
609
+ }
610
+ );
611
+ }
612
+ function ColorPickerArea(props) {
613
+ const {
614
+ asChild,
615
+ onPointerDown: onPointerDownProp,
616
+ onPointerMove: onPointerMoveProp,
617
+ onPointerUp: onPointerUpProp,
618
+ className,
619
+ ref,
620
+ ...areaProps
621
+ } = props;
622
+ const propsRef = useAsRef({
623
+ onPointerDown: onPointerDownProp,
624
+ onPointerMove: onPointerMoveProp,
625
+ onPointerUp: onPointerUpProp
626
+ });
627
+ const context = useColorPickerContext(COLOR_PICKER_AREA_NAME);
628
+ const store = useColorPickerStoreContext(COLOR_PICKER_AREA_NAME);
629
+ const hsv = useColorPickerStore((state) => state.hsv);
630
+ const isDraggingRef = React16.useRef(false);
631
+ const areaRef = React16.useRef(null);
632
+ const composedRef = useComposedRefs(ref, areaRef);
633
+ const updateColorFromPosition = React16.useCallback(
634
+ (clientX, clientY) => {
635
+ if (!areaRef.current) return;
636
+ const rect = areaRef.current.getBoundingClientRect();
637
+ const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
638
+ const y = Math.max(0, Math.min(1, 1 - (clientY - rect.top) / rect.height));
639
+ const newHsv = {
640
+ h: hsv?.h ?? 0,
641
+ s: Math.round(x * 100),
642
+ v: Math.round(y * 100),
643
+ a: hsv?.a ?? 1
644
+ };
645
+ store.setHsv(newHsv);
646
+ store.setColor(hsvToRgb(newHsv));
647
+ },
648
+ [hsv, store]
649
+ );
650
+ const onPointerDown = React16.useCallback(
651
+ (event) => {
652
+ if (context.disabled) return;
653
+ propsRef.current.onPointerDown?.(event);
654
+ if (event.defaultPrevented) return;
655
+ isDraggingRef.current = true;
656
+ areaRef.current?.setPointerCapture(event.pointerId);
657
+ updateColorFromPosition(event.clientX, event.clientY);
658
+ },
659
+ [context.disabled, updateColorFromPosition, propsRef]
660
+ );
661
+ const onPointerMove = React16.useCallback(
662
+ (event) => {
663
+ propsRef.current.onPointerMove?.(event);
664
+ if (event.defaultPrevented) return;
665
+ if (isDraggingRef.current) updateColorFromPosition(event.clientX, event.clientY);
666
+ },
667
+ [updateColorFromPosition, propsRef]
668
+ );
669
+ const onPointerUp = React16.useCallback(
670
+ (event) => {
671
+ propsRef.current.onPointerUp?.(event);
672
+ if (event.defaultPrevented) return;
673
+ isDraggingRef.current = false;
674
+ areaRef.current?.releasePointerCapture(event.pointerId);
675
+ },
676
+ [propsRef]
677
+ );
678
+ const hue = hsv?.h ?? 0;
679
+ const backgroundHue = hsvToRgb({ h: hue, s: 100, v: 100, a: 1 });
680
+ const AreaPrimitive = asChild ? Slot.Slot : "div";
681
+ return /* @__PURE__ */ jsxs(
682
+ AreaPrimitive,
683
+ {
684
+ "data-slot": "color-picker-area",
685
+ ...areaProps,
686
+ className: cn(
687
+ "relative h-40 w-full cursor-crosshair touch-none rounded-sm border",
688
+ context.disabled && "pointer-events-none opacity-50",
689
+ className
690
+ ),
691
+ ref: composedRef,
692
+ onPointerDown,
693
+ onPointerMove,
694
+ onPointerUp,
695
+ children: [
696
+ /* @__PURE__ */ jsxs("div", { className: "absolute inset-0 overflow-hidden rounded-sm", children: [
697
+ /* @__PURE__ */ jsx(
698
+ "div",
699
+ {
700
+ className: "absolute inset-0",
701
+ style: { backgroundColor: `rgb(${backgroundHue.r}, ${backgroundHue.g}, ${backgroundHue.b})` }
702
+ }
703
+ ),
704
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0", style: { background: "linear-gradient(to right, #fff, transparent)" } }),
705
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0", style: { background: "linear-gradient(to bottom, transparent, #000)" } })
706
+ ] }),
707
+ /* @__PURE__ */ jsx(
708
+ "div",
709
+ {
710
+ className: "absolute size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-sm",
711
+ style: { left: `${hsv?.s ?? 0}%`, top: `${100 - (hsv?.v ?? 0)}%` }
712
+ }
713
+ )
714
+ ]
715
+ }
716
+ );
717
+ }
718
+ function ColorPickerHueSlider(props) {
719
+ const { className, ...sliderProps } = props;
720
+ const context = useColorPickerContext(COLOR_PICKER_HUE_SLIDER_NAME);
721
+ const store = useColorPickerStoreContext(COLOR_PICKER_HUE_SLIDER_NAME);
722
+ const hsv = useColorPickerStore((state) => state.hsv);
723
+ const onValueChange = React16.useCallback(
724
+ (values) => {
725
+ const newHsv = { h: values[0] ?? 0, s: hsv?.s ?? 0, v: hsv?.v ?? 0, a: hsv?.a ?? 1 };
726
+ store.setHsv(newHsv);
727
+ store.setColor(hsvToRgb(newHsv));
728
+ },
729
+ [hsv, store]
730
+ );
731
+ return /* @__PURE__ */ jsxs(
732
+ Slider.Root,
733
+ {
734
+ "data-slot": "color-picker-hue-slider",
735
+ ...sliderProps,
736
+ max: 360,
737
+ step: 1,
738
+ className: cn("relative flex w-full touch-none items-center select-none", className),
739
+ value: [hsv?.h ?? 0],
740
+ onValueChange,
741
+ disabled: context.disabled,
742
+ children: [
743
+ /* @__PURE__ */ jsx(Slider.Track, { className: "relative h-3 w-full grow overflow-hidden rounded-full bg-[linear-gradient(to_right,#ff0000_0%,#ffff00_16.66%,#00ff00_33.33%,#00ffff_50%,#0000ff_66.66%,#ff00ff_83.33%,#ff0000_100%)]", children: /* @__PURE__ */ jsx(Slider.Range, { className: "absolute h-full" }) }),
744
+ /* @__PURE__ */ jsx(Slider.Thumb, { className: "border-primary/50 bg-background focus-visible:ring-ring block size-4 rounded-full border shadow transition-colors focus-visible:ring-1 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50" })
745
+ ]
746
+ }
747
+ );
748
+ }
749
+ function ColorPickerAlphaSlider(props) {
750
+ const { className, ...sliderProps } = props;
751
+ const context = useColorPickerContext(COLOR_PICKER_ALPHA_SLIDER_NAME);
752
+ const store = useColorPickerStoreContext(COLOR_PICKER_ALPHA_SLIDER_NAME);
753
+ const color = useColorPickerStore((state) => state.color);
754
+ const hsv = useColorPickerStore((state) => state.hsv);
755
+ const onValueChange = React16.useCallback(
756
+ (values) => {
757
+ const alpha = (values[0] ?? 0) / 100;
758
+ store.setColor({ ...color, a: alpha });
759
+ store.setHsv({ ...hsv, a: alpha });
760
+ },
761
+ [color, hsv, store]
762
+ );
763
+ const gradientColor = `rgb(${color?.r ?? 0}, ${color?.g ?? 0}, ${color?.b ?? 0})`;
764
+ return /* @__PURE__ */ jsxs(
765
+ Slider.Root,
766
+ {
767
+ "data-slot": "color-picker-alpha-slider",
768
+ ...sliderProps,
769
+ max: 100,
770
+ step: 1,
771
+ disabled: context.disabled,
772
+ className: cn("relative flex w-full touch-none items-center select-none", className),
773
+ value: [Math.round((color?.a ?? 1) * 100)],
774
+ onValueChange,
775
+ children: [
776
+ /* @__PURE__ */ jsxs(
777
+ Slider.Track,
778
+ {
779
+ className: "relative h-3 w-full grow overflow-hidden rounded-full",
780
+ style: {
781
+ background: "linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%)",
782
+ backgroundSize: "8px 8px",
783
+ backgroundPosition: "0 0, 0 4px, 4px -4px, -4px 0px"
784
+ },
785
+ children: [
786
+ /* @__PURE__ */ jsx(
787
+ "div",
788
+ {
789
+ className: "absolute inset-0 rounded-full",
790
+ style: { background: `linear-gradient(to right, transparent, ${gradientColor})` }
791
+ }
792
+ ),
793
+ /* @__PURE__ */ jsx(Slider.Range, { className: "absolute h-full" })
794
+ ]
795
+ }
796
+ ),
797
+ /* @__PURE__ */ jsx(Slider.Thumb, { className: "border-primary/50 bg-background focus-visible:ring-ring block size-4 rounded-full border shadow transition-colors focus-visible:ring-1 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50" })
798
+ ]
799
+ }
800
+ );
801
+ }
802
+ function ColorPickerSwatch(props) {
803
+ const { asChild, className, ...swatchProps } = props;
804
+ const context = useColorPickerContext(COLOR_PICKER_SWATCH_NAME);
805
+ const color = useColorPickerStore((state) => state.color);
806
+ const format = useColorPickerStore((state) => state.format);
807
+ const backgroundStyle = React16.useMemo(() => {
808
+ if (!color) {
809
+ return {
810
+ background: "linear-gradient(to bottom right, transparent calc(50% - 1px), hsl(var(--destructive)) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) no-repeat"
811
+ };
812
+ }
813
+ const colorString = `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`;
814
+ if (color.a < 1) {
815
+ return {
816
+ background: `linear-gradient(${colorString}, ${colorString}), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0% 50% / 8px 8px`
817
+ };
818
+ }
819
+ return { backgroundColor: colorString };
820
+ }, [color]);
821
+ const ariaLabel = !color ? "No color selected" : `Current color: ${colorToString(color, format)}`;
822
+ const SwatchPrimitive = asChild ? Slot.Slot : "div";
823
+ return /* @__PURE__ */ jsx(
824
+ SwatchPrimitive,
825
+ {
826
+ role: "img",
827
+ "aria-label": ariaLabel,
828
+ "data-slot": "color-picker-swatch",
829
+ ...swatchProps,
830
+ className: cn("box-border size-8 rounded-sm border shadow-sm", context.disabled && "opacity-50", className),
831
+ style: { ...backgroundStyle, forcedColorAdjust: "none" }
832
+ }
833
+ );
834
+ }
835
+ function ColorPickerEyeDropper(props) {
836
+ const { size: sizeProp, children, disabled, ...buttonProps } = props;
837
+ const context = useColorPickerContext(COLOR_PICKER_EYE_DROPPER_NAME);
838
+ const store = useColorPickerStoreContext(COLOR_PICKER_EYE_DROPPER_NAME);
839
+ const color = useColorPickerStore((state) => state.color);
840
+ const isDisabled = disabled || context.disabled;
841
+ const onEyeDropper = React16.useCallback(async () => {
842
+ if (!window.EyeDropper) return;
843
+ try {
844
+ const eyeDropper = new window.EyeDropper();
845
+ const result = await eyeDropper.open();
846
+ if (result.sRGBHex) {
847
+ const newColor = hexToRgb(result.sRGBHex, color?.a ?? 1);
848
+ store.setColor(newColor);
849
+ store.setHsv(rgbToHsv(newColor));
850
+ }
851
+ } catch (error) {
852
+ console.warn("EyeDropper error:", error);
853
+ }
854
+ }, [color, store]);
855
+ const hasEyeDropper = typeof window !== "undefined" && !!window.EyeDropper;
856
+ if (!hasEyeDropper) return null;
857
+ const size = sizeProp ?? (children ? "default" : "icon");
858
+ return /* @__PURE__ */ jsx(
859
+ Button,
860
+ {
861
+ "data-slot": "color-picker-eye-dropper",
862
+ ...buttonProps,
863
+ variant: "outline",
864
+ size,
865
+ onClick: onEyeDropper,
866
+ disabled: isDisabled,
867
+ children: children ?? /* @__PURE__ */ jsx(PipetteIcon, {})
868
+ }
869
+ );
870
+ }
871
+ function ColorPickerFormatSelect(props) {
872
+ const { size, disabled, className, ...selectProps } = props;
873
+ const context = useColorPickerContext(COLOR_PICKER_FORMAT_SELECT_NAME);
874
+ const store = useColorPickerStoreContext(COLOR_PICKER_FORMAT_SELECT_NAME);
875
+ const isDisabled = disabled || context.disabled;
876
+ const format = useColorPickerStore((state) => state.format);
877
+ const onFormatChange = React16.useCallback(
878
+ (value) => {
879
+ store.setFormat(value);
880
+ },
881
+ [store]
882
+ );
883
+ return /* @__PURE__ */ jsx(
884
+ Select,
885
+ {
886
+ "data-slot": "color-picker-format-select",
887
+ ...selectProps,
888
+ value: format,
889
+ onValueChange: onFormatChange,
890
+ disabled: isDisabled,
891
+ size: size ?? "sm",
892
+ className: cn(className),
893
+ children: /* @__PURE__ */ jsx(SelectContent, { children: COLOR_FORMATS.map((f) => /* @__PURE__ */ jsx(SelectItem, { value: f, children: f.toUpperCase() }, f)) })
894
+ }
895
+ );
896
+ }
897
+ var inputGroupItemVariants = cva(
898
+ "h-8 [-moz-appearance:textfield] focus-visible:z-10 focus-visible:ring-1 [&::-webkit-inner-spin-button]:m-0 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:m-0 [&::-webkit-outer-spin-button]:appearance-none",
899
+ {
900
+ variants: {
901
+ position: {
902
+ first: "rounded-e-none",
903
+ middle: "-ms-px rounded-none border-l-0",
904
+ last: "-ms-px rounded-s-none border-l-0",
905
+ isolated: ""
906
+ }
907
+ },
908
+ defaultVariants: {
909
+ position: "isolated"
910
+ }
911
+ }
912
+ );
913
+ function ColorPickerInput(props) {
914
+ const store = useColorPickerStoreContext(COLOR_PICKER_INPUT_NAME);
915
+ const context = useColorPickerContext(COLOR_PICKER_INPUT_NAME);
916
+ const color = useColorPickerStore((state) => state.color);
917
+ const format = useColorPickerStore((state) => state.format);
918
+ const hsv = useColorPickerStore((state) => state.hsv);
919
+ const onColorChange = React16.useCallback(
920
+ (newColor) => {
921
+ const newHsv = rgbToHsv(newColor);
922
+ store.setColor(newColor);
923
+ store.setHsv(newHsv);
924
+ },
925
+ [store]
926
+ );
927
+ if (format === "hex") {
928
+ return /* @__PURE__ */ jsx(HexInput, { color, onColorChange, context, ...props });
929
+ }
930
+ if (format === "rgb") {
931
+ return /* @__PURE__ */ jsx(RgbInput, { color, onColorChange, context, ...props });
932
+ }
933
+ if (format === "hsl") {
934
+ return /* @__PURE__ */ jsx(HslInput, { color, onColorChange, context, ...props });
935
+ }
936
+ if (format === "hsb") {
937
+ return /* @__PURE__ */ jsx(HsbInput, { hsv, onColorChange, context, ...props });
938
+ }
939
+ }
940
+ function InputGroupItem({ className, position, ...props }) {
941
+ return /* @__PURE__ */ jsx(Input, { "data-slot": "color-picker-input", className: cn(inputGroupItemVariants({ position, className })), ...props });
942
+ }
943
+ function HexInput(props) {
944
+ const { color, onColorChange, context, withoutAlpha, className, ...inputProps } = props;
945
+ const hexValue = rgbToHex(color);
946
+ const alphaValue = Math.round((color?.a ?? 1) * 100);
947
+ const onHexChange = React16.useCallback(
948
+ (event) => {
949
+ const value = event.target.value;
950
+ const parsedColor = parseColorString(value);
951
+ if (parsedColor) {
952
+ onColorChange({ ...parsedColor, a: color?.a ?? 1 });
953
+ }
954
+ },
955
+ [color, onColorChange]
956
+ );
957
+ const onAlphaChange = React16.useCallback(
958
+ (event) => {
959
+ const value = Number.parseInt(event.target.value, 10);
960
+ if (!Number.isNaN(value) && value >= 0 && value <= 100) {
961
+ onColorChange({ ...color, a: value / 100 });
962
+ }
963
+ },
964
+ [color, onColorChange]
965
+ );
966
+ if (withoutAlpha) {
967
+ return /* @__PURE__ */ jsx(
968
+ InputGroupItem,
969
+ {
970
+ "aria-label": "Hex color value",
971
+ position: "isolated",
972
+ ...inputProps,
973
+ placeholder: "#000000",
974
+ className: cn("font-code", className),
975
+ value: hexValue,
976
+ onChange: onHexChange,
977
+ disabled: context.disabled
978
+ }
979
+ );
980
+ }
981
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "color-picker-input-wrapper", className: cn("flex flex-1 items-center", className), children: [
982
+ /* @__PURE__ */ jsx(
983
+ InputGroupItem,
984
+ {
985
+ "aria-label": "Hex color value",
986
+ position: "first",
987
+ ...inputProps,
988
+ placeholder: "#000000",
989
+ className: "font-code flex-1",
990
+ value: hexValue,
991
+ onChange: onHexChange,
992
+ disabled: context.disabled
993
+ }
994
+ ),
995
+ /* @__PURE__ */ jsx(
996
+ InputGroupItem,
997
+ {
998
+ "aria-label": "Alpha transparency percentage",
999
+ position: "last",
1000
+ ...inputProps,
1001
+ placeholder: "100",
1002
+ inputMode: "numeric",
1003
+ pattern: "[0-9]*",
1004
+ min: "0",
1005
+ max: "100",
1006
+ className: "w-14",
1007
+ value: alphaValue,
1008
+ onChange: onAlphaChange,
1009
+ disabled: context.disabled
1010
+ }
1011
+ )
1012
+ ] });
1013
+ }
1014
+ function RgbInput(props) {
1015
+ const { color, onColorChange, context, withoutAlpha, className, ...inputProps } = props;
1016
+ const rValue = Math.round(color?.r ?? 0);
1017
+ const gValue = Math.round(color?.g ?? 0);
1018
+ const bValue = Math.round(color?.b ?? 0);
1019
+ const alphaValue = Math.round((color?.a ?? 1) * 100);
1020
+ const onChannelChange = React16.useCallback(
1021
+ (channel, max, isAlpha = false) => (event) => {
1022
+ const value = Number.parseInt(event.target.value, 10);
1023
+ if (!Number.isNaN(value) && value >= 0 && value <= max) {
1024
+ const newValue = isAlpha ? value / 100 : value;
1025
+ onColorChange({ ...color, [channel]: newValue });
1026
+ }
1027
+ },
1028
+ [color, onColorChange]
1029
+ );
1030
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "color-picker-input-wrapper", className: cn("flex flex-1 items-center", className), children: [
1031
+ /* @__PURE__ */ jsx(
1032
+ InputGroupItem,
1033
+ {
1034
+ "aria-label": "Red color component (0-255)",
1035
+ position: "first",
1036
+ ...inputProps,
1037
+ placeholder: "0",
1038
+ inputMode: "numeric",
1039
+ pattern: "[0-9]*",
1040
+ min: "0",
1041
+ max: "255",
1042
+ className: "w-14",
1043
+ value: rValue,
1044
+ onChange: onChannelChange("r", 255),
1045
+ disabled: context.disabled
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ jsx(
1049
+ InputGroupItem,
1050
+ {
1051
+ "aria-label": "Green color component (0-255)",
1052
+ position: "middle",
1053
+ ...inputProps,
1054
+ placeholder: "0",
1055
+ inputMode: "numeric",
1056
+ pattern: "[0-9]*",
1057
+ min: "0",
1058
+ max: "255",
1059
+ className: "w-14",
1060
+ value: gValue,
1061
+ onChange: onChannelChange("g", 255),
1062
+ disabled: context.disabled
1063
+ }
1064
+ ),
1065
+ /* @__PURE__ */ jsx(
1066
+ InputGroupItem,
1067
+ {
1068
+ "aria-label": "Blue color component (0-255)",
1069
+ position: withoutAlpha ? "last" : "middle",
1070
+ ...inputProps,
1071
+ placeholder: "0",
1072
+ inputMode: "numeric",
1073
+ pattern: "[0-9]*",
1074
+ min: "0",
1075
+ max: "255",
1076
+ className: "w-14",
1077
+ value: bValue,
1078
+ onChange: onChannelChange("b", 255),
1079
+ disabled: context.disabled
1080
+ }
1081
+ ),
1082
+ !withoutAlpha && /* @__PURE__ */ jsx(
1083
+ InputGroupItem,
1084
+ {
1085
+ "aria-label": "Alpha transparency percentage",
1086
+ position: "last",
1087
+ ...inputProps,
1088
+ placeholder: "100",
1089
+ inputMode: "numeric",
1090
+ pattern: "[0-9]*",
1091
+ min: "0",
1092
+ max: "100",
1093
+ className: "w-14",
1094
+ value: alphaValue,
1095
+ onChange: onChannelChange("a", 100, true),
1096
+ disabled: context.disabled
1097
+ }
1098
+ )
1099
+ ] });
1100
+ }
1101
+ function HslInput(props) {
1102
+ const { color, onColorChange, context, withoutAlpha, className, ...inputProps } = props;
1103
+ const hsl = React16.useMemo(() => rgbToHsl(color), [color]);
1104
+ const alphaValue = Math.round((color?.a ?? 1) * 100);
1105
+ const onHslChannelChange = React16.useCallback(
1106
+ (channel, max) => (event) => {
1107
+ const value = Number.parseInt(event.target.value, 10);
1108
+ if (!Number.isNaN(value) && value >= 0 && value <= max) {
1109
+ const newHsl = { ...hsl, [channel]: value };
1110
+ const newColor = hslToRgb(newHsl, color?.a ?? 1);
1111
+ onColorChange(newColor);
1112
+ }
1113
+ },
1114
+ [hsl, color, onColorChange]
1115
+ );
1116
+ const onAlphaChange = React16.useCallback(
1117
+ (event) => {
1118
+ const value = Number.parseInt(event.target.value, 10);
1119
+ if (!Number.isNaN(value) && value >= 0 && value <= 100) {
1120
+ onColorChange({ ...color, a: value / 100 });
1121
+ }
1122
+ },
1123
+ [color, onColorChange]
1124
+ );
1125
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "color-picker-input-wrapper", className: cn("flex items-center", className), children: [
1126
+ /* @__PURE__ */ jsx(
1127
+ InputGroupItem,
1128
+ {
1129
+ "aria-label": "Hue degree (0-360)",
1130
+ position: "first",
1131
+ ...inputProps,
1132
+ placeholder: "0",
1133
+ inputMode: "numeric",
1134
+ pattern: "[0-9]*",
1135
+ min: "0",
1136
+ max: "360",
1137
+ className: "w-14",
1138
+ value: hsl.h,
1139
+ onChange: onHslChannelChange("h", 360),
1140
+ disabled: context.disabled
1141
+ }
1142
+ ),
1143
+ /* @__PURE__ */ jsx(
1144
+ InputGroupItem,
1145
+ {
1146
+ "aria-label": "Saturation percentage (0-100)",
1147
+ position: "middle",
1148
+ ...inputProps,
1149
+ placeholder: "0",
1150
+ inputMode: "numeric",
1151
+ pattern: "[0-9]*",
1152
+ min: "0",
1153
+ max: "100",
1154
+ className: "w-14",
1155
+ value: hsl.s,
1156
+ onChange: onHslChannelChange("s", 100),
1157
+ disabled: context.disabled
1158
+ }
1159
+ ),
1160
+ /* @__PURE__ */ jsx(
1161
+ InputGroupItem,
1162
+ {
1163
+ "aria-label": "Lightness percentage (0-100)",
1164
+ position: withoutAlpha ? "last" : "middle",
1165
+ ...inputProps,
1166
+ placeholder: "0",
1167
+ inputMode: "numeric",
1168
+ pattern: "[0-9]*",
1169
+ min: "0",
1170
+ max: "100",
1171
+ className: "w-14",
1172
+ value: hsl.l,
1173
+ onChange: onHslChannelChange("l", 100),
1174
+ disabled: context.disabled
1175
+ }
1176
+ ),
1177
+ !withoutAlpha && /* @__PURE__ */ jsx(
1178
+ InputGroupItem,
1179
+ {
1180
+ "aria-label": "Alpha transparency percentage",
1181
+ position: "last",
1182
+ ...inputProps,
1183
+ placeholder: "100",
1184
+ inputMode: "numeric",
1185
+ pattern: "[0-9]*",
1186
+ min: "0",
1187
+ max: "100",
1188
+ className: "w-14",
1189
+ value: alphaValue,
1190
+ onChange: onAlphaChange,
1191
+ disabled: context.disabled
1192
+ }
1193
+ )
1194
+ ] });
1195
+ }
1196
+ function HsbInput(props) {
1197
+ const { hsv, onColorChange, context, withoutAlpha, className, ...inputProps } = props;
1198
+ const alphaValue = Math.round((hsv?.a ?? 1) * 100);
1199
+ const onHsvChannelChange = React16.useCallback(
1200
+ (channel, max) => (event) => {
1201
+ const value = Number.parseInt(event.target.value, 10);
1202
+ if (!Number.isNaN(value) && value >= 0 && value <= max) {
1203
+ const newHsv = { ...hsv, [channel]: value };
1204
+ const newColor = hsvToRgb(newHsv);
1205
+ onColorChange(newColor);
1206
+ }
1207
+ },
1208
+ [hsv, onColorChange]
1209
+ );
1210
+ const onAlphaChange = React16.useCallback(
1211
+ (event) => {
1212
+ const value = Number.parseInt(event.target.value, 10);
1213
+ if (!Number.isNaN(value) && value >= 0 && value <= 100) {
1214
+ const currentColor = hsvToRgb(hsv);
1215
+ onColorChange({ ...currentColor, a: value / 100 });
1216
+ }
1217
+ },
1218
+ [hsv, onColorChange]
1219
+ );
1220
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "color-picker-input-wrapper", className: cn("flex items-center", className), children: [
1221
+ /* @__PURE__ */ jsx(
1222
+ InputGroupItem,
1223
+ {
1224
+ "aria-label": "Hue degree (0-360)",
1225
+ position: "first",
1226
+ ...inputProps,
1227
+ placeholder: "0",
1228
+ inputMode: "numeric",
1229
+ pattern: "[0-9]*",
1230
+ min: "0",
1231
+ max: "360",
1232
+ className: "w-14",
1233
+ value: hsv?.h ?? 0,
1234
+ onChange: onHsvChannelChange("h", 360),
1235
+ disabled: context.disabled
1236
+ }
1237
+ ),
1238
+ /* @__PURE__ */ jsx(
1239
+ InputGroupItem,
1240
+ {
1241
+ "aria-label": "Saturation percentage (0-100)",
1242
+ position: "middle",
1243
+ ...inputProps,
1244
+ placeholder: "0",
1245
+ inputMode: "numeric",
1246
+ pattern: "[0-9]*",
1247
+ min: "0",
1248
+ max: "100",
1249
+ className: "w-14",
1250
+ value: hsv?.s ?? 0,
1251
+ onChange: onHsvChannelChange("s", 100),
1252
+ disabled: context.disabled
1253
+ }
1254
+ ),
1255
+ /* @__PURE__ */ jsx(
1256
+ InputGroupItem,
1257
+ {
1258
+ "aria-label": "Brightness percentage (0-100)",
1259
+ position: withoutAlpha ? "last" : "middle",
1260
+ ...inputProps,
1261
+ placeholder: "0",
1262
+ inputMode: "numeric",
1263
+ pattern: "[0-9]*",
1264
+ min: "0",
1265
+ max: "100",
1266
+ className: "w-14",
1267
+ value: hsv?.v ?? 0,
1268
+ onChange: onHsvChannelChange("v", 100),
1269
+ disabled: context.disabled
1270
+ }
1271
+ ),
1272
+ !withoutAlpha && /* @__PURE__ */ jsx(
1273
+ InputGroupItem,
1274
+ {
1275
+ "aria-label": "Alpha transparency percentage",
1276
+ position: "last",
1277
+ ...inputProps,
1278
+ placeholder: "100",
1279
+ inputMode: "numeric",
1280
+ pattern: "[0-9]*",
1281
+ min: "0",
1282
+ max: "100",
1283
+ className: "w-14",
1284
+ value: alphaValue,
1285
+ onChange: onAlphaChange,
1286
+ disabled: context.disabled
1287
+ }
1288
+ )
1289
+ ] });
1290
+ }
1291
+
1292
+ // src/components/stepper/stepper.constants.ts
1293
+ var STEPPER_ROOT_NAME = "Stepper";
1294
+ var STEPPER_NAV_NAME = "StepperNav";
1295
+ var STEPPER_ITEM_NAME = "StepperItem";
1296
+ var STEPPER_TRIGGER_NAME = "StepperTrigger";
1297
+ var STEPPER_INDICATOR_NAME = "StepperIndicator";
1298
+ var STEPPER_TITLE_NAME = "StepperTitle";
1299
+ var STEPPER_DESCRIPTION_NAME = "StepperDescription";
1300
+ var STEPPER_CONTENT_NAME = "StepperContent";
1301
+ var STEPPER_PREV_TRIGGER_NAME = "StepperPrevTrigger";
1302
+ var STEPPER_NEXT_TRIGGER_NAME = "StepperNextTrigger";
1303
+ var STEPPER_ENTRY_FOCUS = "stepperFocusGroup.onEntryFocus";
1304
+ var STEPPER_EVENT_OPTIONS = { bubbles: false, cancelable: true };
1305
+ var STEPPER_ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
1306
+ var STEPPER_MAP_KEY_TO_FOCUS_INTENT = {
1307
+ ArrowLeft: "prev",
1308
+ ArrowUp: "prev",
1309
+ ArrowRight: "next",
1310
+ ArrowDown: "next",
1311
+ PageUp: "first",
1312
+ Home: "first",
1313
+ PageDown: "last",
1314
+ End: "last"
1315
+ };
1316
+
1317
+ // src/components/stepper/stepper.context.tsx
1318
+ var StepperContext = React16.createContext(null);
1319
+ function useStepperContext(consumerName) {
1320
+ const context = React16.useContext(StepperContext);
1321
+ if (!context) {
1322
+ throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ROOT_NAME}\``);
1323
+ }
1324
+ return context;
1325
+ }
1326
+ function createStepperStore(listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate) {
1327
+ const store = {
1328
+ subscribe: (cb) => {
1329
+ if (listenersRef.current) {
1330
+ listenersRef.current.add(cb);
1331
+ return () => listenersRef.current?.delete(cb);
1332
+ }
1333
+ return () => {
1334
+ };
1335
+ },
1336
+ getState: () => stateRef.current ?? {
1337
+ steps: /* @__PURE__ */ new Map(),
1338
+ value: void 0
1339
+ },
1340
+ setState: (key, value) => {
1341
+ const state = stateRef.current;
1342
+ if (!state || Object.is(state[key], value)) return;
1343
+ if (key === "value" && typeof value === "string") {
1344
+ state.value = value;
1345
+ onValueChange?.(value);
1346
+ } else {
1347
+ state[key] = value;
1348
+ }
1349
+ store.notify();
1350
+ },
1351
+ setStateWithValidation: async (value, direction) => {
1352
+ if (!onValidate) {
1353
+ store.setState("value", value);
1354
+ return true;
1355
+ }
1356
+ try {
1357
+ const isValid = await onValidate(value, direction);
1358
+ if (isValid) {
1359
+ store.setState("value", value);
1360
+ }
1361
+ return isValid;
1362
+ } catch {
1363
+ return false;
1364
+ }
1365
+ },
1366
+ hasValidation: () => !!onValidate,
1367
+ addStep: (newStep) => {
1368
+ const state = stateRef.current;
1369
+ if (state) {
1370
+ state.steps = new Map(state.steps);
1371
+ state.steps.set(newStep.value, newStep);
1372
+ onValueAdd?.(newStep.value);
1373
+ store.notify();
1374
+ }
1375
+ },
1376
+ removeStep: (value) => {
1377
+ const state = stateRef.current;
1378
+ if (state) {
1379
+ state.steps = new Map(state.steps);
1380
+ state.steps.delete(value);
1381
+ onValueRemove?.(value);
1382
+ store.notify();
1383
+ }
1384
+ },
1385
+ setStep: ({ value, disabled, loading, completed }) => {
1386
+ const state = stateRef.current;
1387
+ if (state) {
1388
+ const step = state.steps.get(value);
1389
+ if (step) {
1390
+ const updatedStep = { ...step, completed, disabled, loading };
1391
+ state.steps = new Map(state.steps);
1392
+ state.steps.set(value, updatedStep);
1393
+ if (completed !== step.completed) {
1394
+ onValueComplete?.(value, completed);
1395
+ }
1396
+ store.notify();
1397
+ }
1398
+ }
1399
+ },
1400
+ notify: () => {
1401
+ if (listenersRef.current) {
1402
+ for (const cb of listenersRef.current) {
1403
+ cb();
1404
+ }
1405
+ }
1406
+ }
1407
+ };
1408
+ return store;
1409
+ }
1410
+ var StepperStoreContext = React16.createContext(null);
1411
+ function useStepperStoreContext(consumerName) {
1412
+ const context = React16.useContext(StepperStoreContext);
1413
+ if (!context) {
1414
+ throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ROOT_NAME}\``);
1415
+ }
1416
+ return context;
1417
+ }
1418
+ function useStepperStore(selector) {
1419
+ const store = useStepperStoreContext("useStore");
1420
+ const getSnapshot = React16.useCallback(() => selector(store.getState()), [selector, store]);
1421
+ return React16.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
1422
+ }
1423
+ function Stepper({
1424
+ value,
1425
+ defaultValue,
1426
+ onValueChange,
1427
+ onValueComplete,
1428
+ onValueAdd,
1429
+ onValueRemove,
1430
+ onValidate,
1431
+ id: idProp,
1432
+ dir: dirProp,
1433
+ orientation = "horizontal",
1434
+ activationMode = "automatic",
1435
+ asChild,
1436
+ disabled = false,
1437
+ nonInteractive = false,
1438
+ loop = false,
1439
+ className,
1440
+ indicators = {},
1441
+ ...rootProps
1442
+ }) {
1443
+ const id = React16.useId();
1444
+ const rootId = idProp ?? id;
1445
+ const listenersRef = useLazyRef(() => /* @__PURE__ */ new Set());
1446
+ const stateRef = useLazyRef(() => ({
1447
+ steps: /* @__PURE__ */ new Map(),
1448
+ value: value ?? defaultValue
1449
+ }));
1450
+ const store = React16.useMemo(
1451
+ () => createStepperStore(listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate),
1452
+ [listenersRef, stateRef, onValueChange, onValueComplete, onValueAdd, onValueRemove, onValidate]
1453
+ );
1454
+ useIsomorphicLayoutEffect(() => {
1455
+ if (value !== void 0) {
1456
+ store.setState("value", value);
1457
+ }
1458
+ }, [value]);
1459
+ const dir = useDirection(dirProp);
1460
+ const contextValue = React16.useMemo(
1461
+ () => ({
1462
+ id: rootId,
1463
+ dir,
1464
+ orientation,
1465
+ activationMode,
1466
+ disabled,
1467
+ nonInteractive,
1468
+ loop,
1469
+ indicators
1470
+ }),
1471
+ [rootId, dir, orientation, activationMode, disabled, nonInteractive, loop, indicators]
1472
+ );
1473
+ const RootPrimitive = asChild ? Slot$1 : "div";
1474
+ return /* @__PURE__ */ jsx(StepperStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsx(StepperContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
1475
+ RootPrimitive,
1476
+ {
1477
+ id: rootId,
1478
+ "data-disabled": disabled ? "" : void 0,
1479
+ "data-orientation": orientation,
1480
+ "data-slot": "stepper",
1481
+ dir,
1482
+ ...rootProps,
1483
+ className: cn("flex w-full flex-col gap-4 data-[orientation=vertical]:flex-row", className)
1484
+ }
1485
+ ) }) });
1486
+ }
1487
+
1488
+ // src/components/stepper/stepper.types.ts
1489
+ var StepperFocusIntent = {
1490
+ FIRST: "first",
1491
+ LAST: "last",
1492
+ PREV: "prev",
1493
+ NEXT: "next"
1494
+ };
1495
+ var StepperOrientation = {
1496
+ HORIZONTAL: "horizontal",
1497
+ VERTICAL: "vertical"
1498
+ };
1499
+ var StepperNavigationDirection = {
1500
+ NEXT: "next",
1501
+ PREV: "prev"
1502
+ };
1503
+ var StepperActivationMode = {
1504
+ AUTOMATIC: "automatic",
1505
+ MANUAL: "manual"
1506
+ };
1507
+ var StepperDataState = {
1508
+ INACTIVE: "inactive",
1509
+ ACTIVE: "active",
1510
+ COMPLETED: "completed"
1511
+ };
1512
+ var StepperFocusContext = React16.createContext(null);
1513
+ function useStepperFocusContext(consumerName) {
1514
+ const context = React16.useContext(StepperFocusContext);
1515
+ if (!context) {
1516
+ throw new Error(`\`${consumerName}\` must be used within \`FocusProvider\``);
1517
+ }
1518
+ return context;
1519
+ }
1520
+
1521
+ // src/components/stepper/stepper.utils.tsx
1522
+ function focusFirst(candidates, preventScroll = false) {
1523
+ const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
1524
+ for (const candidateRef of candidates) {
1525
+ const candidate = candidateRef.current;
1526
+ if (!candidate) continue;
1527
+ if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
1528
+ candidate.focus({ preventScroll });
1529
+ if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
1530
+ }
1531
+ }
1532
+ function getDataState(value, itemValue, stepState, steps, variant = "item") {
1533
+ const stepKeys = Array.from(steps.keys());
1534
+ const currentIndex = stepKeys.indexOf(itemValue);
1535
+ if (stepState?.completed) {
1536
+ return StepperDataState.COMPLETED;
1537
+ }
1538
+ if (value === itemValue) {
1539
+ return variant === "separator" ? StepperDataState.INACTIVE : StepperDataState.ACTIVE;
1540
+ }
1541
+ if (value) {
1542
+ const activeIndex = stepKeys.indexOf(value);
1543
+ if (activeIndex > currentIndex) {
1544
+ return StepperDataState.COMPLETED;
1545
+ }
1546
+ }
1547
+ return StepperDataState.INACTIVE;
1548
+ }
1549
+ function getId(id, variant, value) {
1550
+ return `${id}-${variant}-${value}`;
1551
+ }
1552
+ function wrapArray(array, startIndex) {
1553
+ return array.map((_, index) => array[(startIndex + index) % array.length]);
1554
+ }
1555
+ function getDirectionAwareKey(key, dir) {
1556
+ if (dir !== "rtl") return key;
1557
+ return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
1558
+ }
1559
+ function getFocusIntent(event, dir, orientation) {
1560
+ const key = getDirectionAwareKey(event.key, dir);
1561
+ if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
1562
+ if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
1563
+ return STEPPER_MAP_KEY_TO_FOCUS_INTENT[key];
1564
+ }
1565
+ function StepperNav({ className, children, asChild, ref, ...listProps }) {
1566
+ const context = useStepperContext(STEPPER_NAV_NAME);
1567
+ const orientation = context.orientation;
1568
+ const currentValue = useStepperStore((state) => state.value);
1569
+ const [tabStopId, setTabStopId] = React16.useState(null);
1570
+ const [isTabbingBackOut, setIsTabbingBackOut] = React16.useState(false);
1571
+ const [focusableItemCount, setFocusableItemCount] = React16.useState(0);
1572
+ const isClickFocusRef = React16.useRef(false);
1573
+ const itemsRef = React16.useRef(/* @__PURE__ */ new Map());
1574
+ const listRef = React16.useRef(null);
1575
+ const composedRef = useComposedRefs$1(ref, listRef);
1576
+ const onItemFocus = React16.useCallback((tabStopId2) => {
1577
+ setTabStopId(tabStopId2);
1578
+ }, []);
1579
+ const onItemShiftTab = React16.useCallback(() => {
1580
+ setIsTabbingBackOut(true);
1581
+ }, []);
1582
+ const onFocusableItemAdd = React16.useCallback(() => {
1583
+ setFocusableItemCount((prevCount) => prevCount + 1);
1584
+ }, []);
1585
+ const onFocusableItemRemove = React16.useCallback(() => {
1586
+ setFocusableItemCount((prevCount) => prevCount - 1);
1587
+ }, []);
1588
+ const onItemRegister = React16.useCallback((item) => {
1589
+ itemsRef.current.set(item.id, item);
1590
+ }, []);
1591
+ const onItemUnregister = React16.useCallback((id) => {
1592
+ itemsRef.current.delete(id);
1593
+ }, []);
1594
+ const getItems = React16.useCallback(() => {
1595
+ return Array.from(itemsRef.current.values()).filter((item) => item.ref.current).sort((a, b) => {
1596
+ const elementA = a.ref.current;
1597
+ const elementB = b.ref.current;
1598
+ if (!elementA || !elementB) return 0;
1599
+ const position = elementA.compareDocumentPosition(elementB);
1600
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
1601
+ return -1;
1602
+ }
1603
+ if (position & Node.DOCUMENT_POSITION_PRECEDING) {
1604
+ return 1;
1605
+ }
1606
+ return 0;
1607
+ });
1608
+ }, []);
1609
+ const onBlur = React16.useCallback(
1610
+ (event) => {
1611
+ listProps.onBlur?.(event);
1612
+ if (event.defaultPrevented) return;
1613
+ setIsTabbingBackOut(false);
1614
+ },
1615
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1616
+ [listProps.onBlur]
1617
+ );
1618
+ const onFocus = React16.useCallback(
1619
+ (event) => {
1620
+ listProps.onFocus?.(event);
1621
+ if (event.defaultPrevented) return;
1622
+ const isKeyboardFocus = !isClickFocusRef.current;
1623
+ if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
1624
+ const entryFocusEvent = new CustomEvent(STEPPER_ENTRY_FOCUS, STEPPER_EVENT_OPTIONS);
1625
+ event.currentTarget.dispatchEvent(entryFocusEvent);
1626
+ if (!entryFocusEvent.defaultPrevented) {
1627
+ const items = Array.from(itemsRef.current.values()).filter((item) => !item.disabled);
1628
+ const selectedItem = currentValue ? items.find((item) => item.value === currentValue) : void 0;
1629
+ const activeItem = items.find((item) => item.active);
1630
+ const currentItem = items.find((item) => item.id === tabStopId);
1631
+ const candidateItems = [selectedItem, activeItem, currentItem, ...items].filter(
1632
+ Boolean
1633
+ );
1634
+ const candidateRefs = candidateItems.map((item) => item.ref);
1635
+ focusFirst(candidateRefs, false);
1636
+ }
1637
+ }
1638
+ isClickFocusRef.current = false;
1639
+ },
1640
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1641
+ [listProps.onFocus, isTabbingBackOut, currentValue, tabStopId]
1642
+ );
1643
+ const onMouseDown = React16.useCallback(
1644
+ (event) => {
1645
+ listProps.onMouseDown?.(event);
1646
+ if (event.defaultPrevented) return;
1647
+ isClickFocusRef.current = true;
1648
+ },
1649
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1650
+ [listProps.onMouseDown]
1651
+ );
1652
+ const focusContextValue = React16.useMemo(
1653
+ () => ({
1654
+ tabStopId,
1655
+ onItemFocus,
1656
+ onItemShiftTab,
1657
+ onFocusableItemAdd,
1658
+ onFocusableItemRemove,
1659
+ onItemRegister,
1660
+ onItemUnregister,
1661
+ getItems
1662
+ }),
1663
+ [
1664
+ tabStopId,
1665
+ onItemFocus,
1666
+ onItemShiftTab,
1667
+ onFocusableItemAdd,
1668
+ onFocusableItemRemove,
1669
+ onItemRegister,
1670
+ onItemUnregister,
1671
+ getItems
1672
+ ]
1673
+ );
1674
+ const StepperNavPrimitive = asChild ? Slot$1 : "nav";
1675
+ return /* @__PURE__ */ jsx(StepperFocusContext.Provider, { value: focusContextValue, children: /* @__PURE__ */ jsx(
1676
+ StepperNavPrimitive,
1677
+ {
1678
+ role: "tablist",
1679
+ "data-slot": "stepper-nav",
1680
+ "aria-orientation": orientation,
1681
+ "data-orientation": orientation,
1682
+ dir: context.dir,
1683
+ tabIndex: isTabbingBackOut || focusableItemCount === 0 ? -1 : 0,
1684
+ ref: composedRef,
1685
+ onBlur,
1686
+ onFocus,
1687
+ onMouseDown,
1688
+ className: cn(
1689
+ "group/stepper-nav inline-flex gap-4",
1690
+ "data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col",
1691
+ className
1692
+ ),
1693
+ ...listProps,
1694
+ children
1695
+ }
1696
+ ) });
1697
+ }
1698
+ var StepperItemContext = React16.createContext(null);
1699
+ function useStepperItemContext(consumerName) {
1700
+ const context = React16.useContext(StepperItemContext);
1701
+ if (!context) {
1702
+ throw new Error(`\`${consumerName}\` must be used within \`${STEPPER_ITEM_NAME}\``);
1703
+ }
1704
+ return context;
1705
+ }
1706
+ function StepperItem({
1707
+ value: itemValue,
1708
+ completed = false,
1709
+ disabled = false,
1710
+ loading = false,
1711
+ asChild,
1712
+ className,
1713
+ children,
1714
+ ...props
1715
+ }) {
1716
+ const { orientation, dir } = useStepperContext(STEPPER_ITEM_NAME);
1717
+ const store = useStepperStoreContext(STEPPER_ITEM_NAME);
1718
+ const value = useStepperStore((state) => state.value);
1719
+ useIsomorphicLayoutEffect(() => {
1720
+ store.addStep({ value: itemValue, completed, disabled, loading });
1721
+ return () => {
1722
+ store.removeStep(itemValue);
1723
+ };
1724
+ }, [itemValue, completed, disabled, loading]);
1725
+ useIsomorphicLayoutEffect(() => {
1726
+ store.setStep({ value: itemValue, completed, disabled, loading });
1727
+ }, [itemValue, completed, disabled, loading]);
1728
+ const stepState = useStepperStore((state) => state.steps.get(itemValue));
1729
+ const steps = useStepperStore((state) => state.steps);
1730
+ const dataState = getDataState(value, itemValue, stepState, steps);
1731
+ const itemContextValue = React16.useMemo(
1732
+ () => ({
1733
+ value: itemValue,
1734
+ stepState
1735
+ }),
1736
+ [itemValue, stepState]
1737
+ );
1738
+ const StepperItemPrimitive = asChild ? Slot$1 : "div";
1739
+ return /* @__PURE__ */ jsx(StepperItemContext.Provider, { value: itemContextValue, children: /* @__PURE__ */ jsxs(
1740
+ StepperItemPrimitive,
1741
+ {
1742
+ "data-disabled": stepState?.disabled ? "" : void 0,
1743
+ "data-orientation": orientation,
1744
+ "data-state": dataState,
1745
+ "data-slot": "stepper-item",
1746
+ dir,
1747
+ className: cn(
1748
+ "group/step flex flex-1 flex-col justify-end data-[disabled]:opacity-50",
1749
+ "",
1750
+ // "group-data-[orientation=horizontal]/stepper-nav:flex-row group-data-[orientation=vertical]/stepper-nav:flex-col",
1751
+ className
1752
+ ),
1753
+ ...props,
1754
+ children: [
1755
+ children,
1756
+ /* @__PURE__ */ jsx(
1757
+ "div",
1758
+ {
1759
+ "data-state": dataState,
1760
+ className: cn(
1761
+ "bg-border h-1 w-full transition-colors duration-500",
1762
+ "data-[state=active]:bg-primary data-[state=completed]:bg-success"
1763
+ )
1764
+ }
1765
+ )
1766
+ ]
1767
+ }
1768
+ ) });
1769
+ }
1770
+ function StepperTrigger({ asChild, disabled, className, ref, ...triggerProps }) {
1771
+ const context = useStepperContext(STEPPER_TRIGGER_NAME);
1772
+ const itemContext = useStepperItemContext(STEPPER_TRIGGER_NAME);
1773
+ const store = useStepperStoreContext(STEPPER_TRIGGER_NAME);
1774
+ const focusContext = useStepperFocusContext(STEPPER_TRIGGER_NAME);
1775
+ const value = useStepperStore((state) => state.value);
1776
+ const itemValue = itemContext.value;
1777
+ const stepState = useStepperStore((state) => state.steps.get(itemValue));
1778
+ const activationMode = context.activationMode;
1779
+ const orientation = context.orientation;
1780
+ const loop = context.loop;
1781
+ const steps = useStepperStore((state) => state.steps);
1782
+ const stepIndex = Array.from(steps.keys()).indexOf(itemValue);
1783
+ const stepPosition = stepIndex + 1;
1784
+ const stepCount = steps.size;
1785
+ const triggerId = getId(context.id, "trigger", itemValue);
1786
+ const contentId = getId(context.id, "content", itemValue);
1787
+ const titleId = getId(context.id, "title", itemValue);
1788
+ const descriptionId = getId(context.id, "description", itemValue);
1789
+ const isDisabled = context.disabled || stepState?.disabled || disabled;
1790
+ const isActive = value === itemValue;
1791
+ const isTabStop = focusContext.tabStopId === triggerId;
1792
+ const dataState = getDataState(value, itemValue, stepState, steps);
1793
+ const triggerRef = React16.useRef(null);
1794
+ const composedRef = useComposedRefs$1(ref, triggerRef);
1795
+ const isArrowKeyPressedRef = React16.useRef(false);
1796
+ const isMouseClickRef = React16.useRef(false);
1797
+ React16.useEffect(() => {
1798
+ function onKeyDown2(event) {
1799
+ if (STEPPER_ARROW_KEYS.includes(event.key)) {
1800
+ isArrowKeyPressedRef.current = true;
1801
+ }
1802
+ }
1803
+ function onKeyUp() {
1804
+ isArrowKeyPressedRef.current = false;
1805
+ }
1806
+ document.addEventListener("keydown", onKeyDown2);
1807
+ document.addEventListener("keyup", onKeyUp);
1808
+ return () => {
1809
+ document.removeEventListener("keydown", onKeyDown2);
1810
+ document.removeEventListener("keyup", onKeyUp);
1811
+ };
1812
+ }, []);
1813
+ useIsomorphicLayoutEffect(() => {
1814
+ focusContext.onItemRegister({
1815
+ id: triggerId,
1816
+ ref: triggerRef,
1817
+ value: itemValue,
1818
+ active: isTabStop,
1819
+ disabled: !!isDisabled
1820
+ });
1821
+ if (!isDisabled) {
1822
+ focusContext.onFocusableItemAdd();
1823
+ }
1824
+ return () => {
1825
+ focusContext.onItemUnregister(triggerId);
1826
+ if (!isDisabled) {
1827
+ focusContext.onFocusableItemRemove();
1828
+ }
1829
+ };
1830
+ }, [focusContext, triggerId, itemValue, isTabStop, isDisabled]);
1831
+ const onClick = React16.useCallback(
1832
+ async (event) => {
1833
+ triggerProps.onClick?.(event);
1834
+ if (event.defaultPrevented) return;
1835
+ if (!isDisabled && !context.nonInteractive) {
1836
+ const currentStepIndex = Array.from(steps.keys()).indexOf(value ?? "");
1837
+ const targetStepIndex = Array.from(steps.keys()).indexOf(itemValue);
1838
+ const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
1839
+ await store.setStateWithValidation(itemValue, direction);
1840
+ }
1841
+ },
1842
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1843
+ [isDisabled, context.nonInteractive, store, itemValue, value, steps, triggerProps.onClick]
1844
+ );
1845
+ const onFocus = React16.useCallback(
1846
+ async (event) => {
1847
+ triggerProps.onFocus?.(event);
1848
+ if (event.defaultPrevented) return;
1849
+ focusContext.onItemFocus(triggerId);
1850
+ const isKeyboardFocus = !isMouseClickRef.current;
1851
+ if (!isActive && !isDisabled && activationMode !== "manual" && !context.nonInteractive && isKeyboardFocus) {
1852
+ const currentStepIndex = Array.from(steps.keys()).indexOf(value || "");
1853
+ const targetStepIndex = Array.from(steps.keys()).indexOf(itemValue);
1854
+ const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
1855
+ await store.setStateWithValidation(itemValue, direction);
1856
+ }
1857
+ isMouseClickRef.current = false;
1858
+ },
1859
+ [
1860
+ triggerProps,
1861
+ focusContext,
1862
+ triggerId,
1863
+ isActive,
1864
+ isDisabled,
1865
+ activationMode,
1866
+ context.nonInteractive,
1867
+ steps,
1868
+ value,
1869
+ itemValue,
1870
+ store
1871
+ ]
1872
+ );
1873
+ const onKeyDown = React16.useCallback(
1874
+ async (event) => {
1875
+ triggerProps.onKeyDown?.(event);
1876
+ if (event.defaultPrevented) return;
1877
+ if (event.key === "Enter" && context.nonInteractive) {
1878
+ event.preventDefault();
1879
+ return;
1880
+ }
1881
+ if ((event.key === "Enter" || event.key === " ") && activationMode === "manual" && !context.nonInteractive) {
1882
+ event.preventDefault();
1883
+ if (!isDisabled && triggerRef.current) {
1884
+ triggerRef.current.click();
1885
+ }
1886
+ return;
1887
+ }
1888
+ if (event.key === "Tab" && event.shiftKey) {
1889
+ focusContext.onItemShiftTab();
1890
+ return;
1891
+ }
1892
+ if (event.target !== event.currentTarget) return;
1893
+ const focusIntent = getFocusIntent(event, context.dir, orientation);
1894
+ if (focusIntent !== void 0) {
1895
+ if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
1896
+ event.preventDefault();
1897
+ const items = focusContext.getItems().filter((item) => !item.disabled);
1898
+ let candidateRefs = items.map((item) => item.ref);
1899
+ if (focusIntent === "last") {
1900
+ candidateRefs.reverse();
1901
+ } else if (focusIntent === "prev" || focusIntent === "next") {
1902
+ if (focusIntent === "prev") candidateRefs.reverse();
1903
+ const currentIndex = candidateRefs.findIndex((ref2) => ref2.current === event.currentTarget);
1904
+ candidateRefs = loop ? wrapArray(candidateRefs, currentIndex + 1) : candidateRefs.slice(currentIndex + 1);
1905
+ }
1906
+ if (store.hasValidation() && candidateRefs.length > 0) {
1907
+ const nextRef = candidateRefs[0];
1908
+ const nextElement = nextRef?.current;
1909
+ const nextItem = items.find((item) => item.ref.current === nextElement);
1910
+ if (nextItem && nextItem.value !== itemValue) {
1911
+ const currentStepIndex = Array.from(steps.keys()).indexOf(value || "");
1912
+ const targetStepIndex = Array.from(steps.keys()).indexOf(nextItem.value);
1913
+ const direction = targetStepIndex > currentStepIndex ? "next" : "prev";
1914
+ if (direction === "next") {
1915
+ const isValid = await store.setStateWithValidation(nextItem.value, direction);
1916
+ if (!isValid) return;
1917
+ } else {
1918
+ store.setState("value", nextItem.value);
1919
+ }
1920
+ queueMicrotask(() => nextElement?.focus());
1921
+ return;
1922
+ }
1923
+ }
1924
+ queueMicrotask(() => focusFirst(candidateRefs));
1925
+ }
1926
+ },
1927
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1928
+ [
1929
+ focusContext,
1930
+ context.nonInteractive,
1931
+ context.dir,
1932
+ activationMode,
1933
+ orientation,
1934
+ loop,
1935
+ isDisabled,
1936
+ triggerProps.onKeyDown,
1937
+ store,
1938
+ itemValue,
1939
+ value,
1940
+ steps
1941
+ ]
1942
+ );
1943
+ const onMouseDown = React16.useCallback(
1944
+ (event) => {
1945
+ triggerProps.onMouseDown?.(event);
1946
+ if (event.defaultPrevented) {
1947
+ return;
1948
+ }
1949
+ isMouseClickRef.current = true;
1950
+ if (isDisabled) {
1951
+ event.preventDefault();
1952
+ } else {
1953
+ focusContext.onItemFocus(triggerId);
1954
+ }
1955
+ },
1956
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1957
+ [focusContext, triggerId, isDisabled, triggerProps.onMouseDown]
1958
+ );
1959
+ const TriggerPrimitive = asChild ? Slot$1 : "button";
1960
+ return /* @__PURE__ */ jsx(
1961
+ TriggerPrimitive,
1962
+ {
1963
+ id: triggerId,
1964
+ role: "tab",
1965
+ type: "button",
1966
+ disabled: isDisabled,
1967
+ tabIndex: isTabStop ? 0 : -1,
1968
+ ref: composedRef,
1969
+ "data-slot": "stepper-trigger",
1970
+ "data-disabled": isDisabled ? "" : void 0,
1971
+ "data-state": dataState,
1972
+ "aria-controls": contentId,
1973
+ "aria-current": isActive ? "step" : void 0,
1974
+ "aria-describedby": `${titleId} ${descriptionId}`,
1975
+ "aria-posinset": stepPosition,
1976
+ "aria-selected": isActive,
1977
+ "aria-setsize": stepCount,
1978
+ className: cn(
1979
+ "inline-flex w-full cursor-pointer items-center gap-3 rounded text-left transition-colors duration-500 outline-none",
1980
+ "disabled:pointer-events-none",
1981
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
1982
+ className
1983
+ ),
1984
+ onClick,
1985
+ onFocus,
1986
+ onKeyDown,
1987
+ onMouseDown,
1988
+ ...triggerProps
1989
+ }
1990
+ );
1991
+ }
1992
+ function StepperIndicator({ className, children, asChild, ref, ...props }) {
1993
+ const { indicators, dir } = useStepperContext(STEPPER_INDICATOR_NAME);
1994
+ const itemContext = useStepperItemContext(STEPPER_INDICATOR_NAME);
1995
+ const value = useStepperStore((state) => state.value);
1996
+ const itemValue = itemContext.value;
1997
+ const stepState = useStepperStore((state) => state.steps.get(itemValue));
1998
+ const steps = useStepperStore((state) => state.steps);
1999
+ const stepPosition = Array.from(steps.keys()).indexOf(itemValue) + 1;
2000
+ const dataState = getDataState(value, itemValue, stepState, steps);
2001
+ const StepperIndicatorPrimitive = asChild ? Slot$1 : "div";
2002
+ return /* @__PURE__ */ jsx(
2003
+ StepperIndicatorPrimitive,
2004
+ {
2005
+ "data-slot": "stepper-indicator",
2006
+ "data-state": dataState,
2007
+ dir,
2008
+ ref,
2009
+ className: cn(
2010
+ "bg-muted border-border text-muted-foreground relative flex size-6 shrink-0 items-center justify-center self-end overflow-hidden rounded-t border-x border-t text-xs transition-colors duration-500",
2011
+ "data-[state=completed]:bg-success/50 data-[state=completed]:border-success data-[state=completed]:text-success-foreground",
2012
+ "data-[state=active]:bg-primary/50 data-[state=active]:border-primary data-[state=active]:text-primary-foreground",
2013
+ className
2014
+ ),
2015
+ ...props,
2016
+ children: /* @__PURE__ */ jsx("div", { className: "absolute", children: typeof children === "function" ? children(dataState) : indicators && (itemContext.stepState?.loading && indicators.loading || dataState === "completed" && indicators.completed || dataState === "active" && indicators.active || dataState === "inactive" && indicators.inactive) ? itemContext.stepState?.loading && indicators.loading || dataState === "completed" && indicators.completed || dataState === "active" && indicators.active || dataState === "inactive" && indicators.inactive : children ? children : stepPosition })
2017
+ }
2018
+ );
2019
+ }
2020
+ function StepperTitle({ className, asChild = false, ...props }) {
2021
+ const context = useStepperContext(STEPPER_TITLE_NAME);
2022
+ const itemContext = useStepperItemContext(STEPPER_TITLE_NAME);
2023
+ const titleId = getId(context.id, "title", itemContext.value);
2024
+ const TitlePrimitive = asChild ? Slot$1 : "h3";
2025
+ return /* @__PURE__ */ jsx(
2026
+ TitlePrimitive,
2027
+ {
2028
+ id: titleId,
2029
+ "data-slot": "stepper-title",
2030
+ dir: context.dir,
2031
+ className: cn("text-sm leading-none font-medium", className),
2032
+ ...props
2033
+ }
2034
+ );
2035
+ }
2036
+ function StepperDescription({ className, asChild, ...props }) {
2037
+ const context = useStepperContext(STEPPER_DESCRIPTION_NAME);
2038
+ const itemContext = useStepperItemContext(STEPPER_DESCRIPTION_NAME);
2039
+ const descriptionId = getId(context.id, "description", itemContext.value);
2040
+ const StepperDescriptionPrimitive = asChild ? Slot$1 : "span";
2041
+ return /* @__PURE__ */ jsx(
2042
+ StepperDescriptionPrimitive,
2043
+ {
2044
+ id: descriptionId,
2045
+ "data-slot": "stepper-description",
2046
+ dir: context.dir,
2047
+ className: cn("text-muted-foreground text-sm", className),
2048
+ ...props
2049
+ }
2050
+ );
2051
+ }
2052
+ function StepperPanel({ children, asChild = false, className, ...props }) {
2053
+ const currentValue = useStepperStore((state) => state.value);
2054
+ const StepperPanelPrimitive = asChild ? Slot$1 : "div";
2055
+ return /* @__PURE__ */ jsx(
2056
+ StepperPanelPrimitive,
2057
+ {
2058
+ "data-slot": "stepper-panel",
2059
+ "data-state": currentValue,
2060
+ className: cn("w-full", className),
2061
+ ...props,
2062
+ children
2063
+ }
2064
+ );
2065
+ }
2066
+ function StepperContent({
2067
+ value: valueProp,
2068
+ asChild = false,
2069
+ forceMount = false,
2070
+ className,
2071
+ ...props
2072
+ }) {
2073
+ const context = useStepperContext(STEPPER_CONTENT_NAME);
2074
+ const value = useStepperStore((state) => state.value);
2075
+ const contentId = getId(context.id, "content", valueProp);
2076
+ const triggerId = getId(context.id, "trigger", valueProp);
2077
+ const isActive = value === valueProp;
2078
+ if (!isActive && !forceMount) {
2079
+ return null;
2080
+ }
2081
+ const ContentPrimitive = asChild ? Slot$1 : "div";
2082
+ return /* @__PURE__ */ jsx(
2083
+ ContentPrimitive,
2084
+ {
2085
+ id: contentId,
2086
+ role: "tabpanel",
2087
+ "data-state": value,
2088
+ "aria-labelledby": triggerId,
2089
+ "data-slot": "stepper-content",
2090
+ dir: context.dir,
2091
+ className: cn("w-full", className, !isActive && forceMount && "hidden"),
2092
+ hidden: !isActive && forceMount,
2093
+ ...props
2094
+ }
2095
+ );
2096
+ }
2097
+ function StepperNextTrigger({ asChild = false, onClick, disabled, ...props }) {
2098
+ const store = useStepperStoreContext(STEPPER_NEXT_TRIGGER_NAME);
2099
+ const value = useStepperStore((state) => state.value);
2100
+ const steps = useStepperStore((state) => state.steps);
2101
+ const stepKeys = Array.from(steps.keys());
2102
+ const currentIndex = value ? stepKeys.indexOf(value) : -1;
2103
+ const isDisabled = disabled || currentIndex >= stepKeys.length - 1;
2104
+ const handleClick = React16.useCallback(
2105
+ async (event) => {
2106
+ onClick?.(event);
2107
+ if (event.defaultPrevented || isDisabled) {
2108
+ return;
2109
+ }
2110
+ const nextIndex = Math.min(currentIndex + 1, stepKeys.length - 1);
2111
+ const nextStepValue = stepKeys[nextIndex];
2112
+ if (nextStepValue) {
2113
+ await store.setStateWithValidation(nextStepValue, "next");
2114
+ }
2115
+ },
2116
+ [onClick, isDisabled, currentIndex, stepKeys, store]
2117
+ );
2118
+ const StepperNextTriggerPrimitive = asChild ? Slot$1 : "button";
2119
+ return /* @__PURE__ */ jsx(
2120
+ StepperNextTriggerPrimitive,
2121
+ {
2122
+ type: "button",
2123
+ "data-slot": "stepper-next-trigger",
2124
+ disabled: isDisabled,
2125
+ onClick: handleClick,
2126
+ ...props
2127
+ }
2128
+ );
2129
+ }
2130
+ function StepperPrevTrigger({ asChild = false, disabled, onClick, ...props }) {
2131
+ const store = useStepperStoreContext(STEPPER_PREV_TRIGGER_NAME);
2132
+ const value = useStepperStore((state) => state.value);
2133
+ const steps = useStepperStore((state) => state.steps);
2134
+ const stepKeys = Array.from(steps.keys());
2135
+ const currentIndex = value ? stepKeys.indexOf(value) : -1;
2136
+ const isDisabled = disabled || currentIndex <= 0;
2137
+ const handleClick = React16.useCallback(
2138
+ async (event) => {
2139
+ onClick?.(event);
2140
+ if (event.defaultPrevented || isDisabled) {
2141
+ return;
2142
+ }
2143
+ const prevIndex = Math.max(currentIndex - 1, 0);
2144
+ const prevStepValue = stepKeys[prevIndex];
2145
+ if (prevStepValue) {
2146
+ store.setState("value", prevStepValue);
2147
+ }
2148
+ },
2149
+ [currentIndex, isDisabled, onClick, stepKeys, store]
2150
+ );
2151
+ const StepperPrevTriggerPrimitive = asChild ? Slot$1 : "button";
2152
+ return /* @__PURE__ */ jsx(
2153
+ StepperPrevTriggerPrimitive,
2154
+ {
2155
+ type: "button",
2156
+ "data-slot": "stepper-prev-trigger",
2157
+ disabled: isDisabled,
2158
+ onClick: handleClick,
2159
+ ...props
2160
+ }
2161
+ );
2162
+ }
2163
+ var Toaster = ({ theme = "system", ...props }) => {
2164
+ return /* @__PURE__ */ jsx(
2165
+ Toaster$1,
2166
+ {
2167
+ className: "group",
2168
+ icons: {
2169
+ success: /* @__PURE__ */ jsx(CircleCheckIcon, { className: "size-4" }),
2170
+ info: /* @__PURE__ */ jsx(InfoIcon, { className: "size-4" }),
2171
+ warning: /* @__PURE__ */ jsx(TriangleAlertIcon, { className: "size-4" }),
2172
+ error: /* @__PURE__ */ jsx(OctagonXIcon, { className: "size-4" }),
2173
+ loading: /* @__PURE__ */ jsx(Spinner, {})
2174
+ },
2175
+ toastOptions: {
2176
+ classNames: {
2177
+ toast: "!bg-popover !text-popover-foreground !border !border-border !rounded",
2178
+ description: "!text-muted-foreground"
2179
+ }
2180
+ },
2181
+ theme,
2182
+ ...props
2183
+ }
2184
+ );
2185
+ };
2186
+ var buttonVariants = cva(
2187
+ [
2188
+ "inline-flex shrink-0 items-center justify-center gap-2 rounded text-sm font-medium whitespace-nowrap transition-all outline-none",
2189
+ "disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
2190
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
2191
+ "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring",
2192
+ "aria-invalid:ring-error/20 dark:aria-invalid:ring-error/40 aria-invalid:border-error"
2193
+ ],
2194
+ {
2195
+ variants: {
2196
+ variant: {
2197
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
2198
+ error: "bg-error hover:bg-error/90 focus-visible:ring-error/20 dark:focus-visible:ring-error/40 dark:bg-error/60 text-white",
2199
+ outline: "bg-background hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50 border shadow-xs",
2200
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
2201
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
2202
+ link: "text-primary underline-offset-4 hover:underline"
2203
+ },
2204
+ size: {
2205
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
2206
+ sm: "h-8 gap-1.5 rounded px-3 has-[>svg]:px-2.5",
2207
+ lg: "h-10 rounded px-6 has-[>svg]:px-4",
2208
+ icon: "size-9",
2209
+ "icon-sm": "size-8",
2210
+ "icon-lg": "size-10"
2211
+ },
2212
+ fullWidth: {
2213
+ true: "w-full"
2214
+ }
2215
+ },
2216
+ defaultVariants: {
2217
+ variant: "default",
2218
+ size: "default",
2219
+ fullWidth: false
2220
+ }
2221
+ }
2222
+ );
2223
+ function Button({
2224
+ asChild = false,
2225
+ variant = "default",
2226
+ disabled = false,
2227
+ fullWidth = false,
2228
+ loadingPosition: loadingPositionProp = "start",
2229
+ children,
2230
+ type = "button",
2231
+ loading = false,
2232
+ size = "default",
2233
+ endIcon,
2234
+ startIcon,
2235
+ className,
2236
+ ...props
2237
+ }) {
2238
+ const Comp = asChild ? Slot$1 : "button";
2239
+ const isDisabled = disabled || loading;
2240
+ const loadingPosition = size?.startsWith("icon") ? "center" : loadingPositionProp;
2241
+ return /* @__PURE__ */ jsx(
2242
+ Comp,
2243
+ {
2244
+ "data-slot": "button",
2245
+ "aria-disabled": isDisabled || void 0,
2246
+ className: cn(buttonVariants({ fullWidth, size, variant }), className),
2247
+ "data-state": loading ? "loading" : void 0,
2248
+ disabled: isDisabled,
2249
+ role: Comp !== "button" ? "button" : void 0,
2250
+ tabIndex: isDisabled ? -1 : 0,
2251
+ type: Comp === "button" ? type : void 0,
2252
+ "data-size": size,
2253
+ "data-variant": variant,
2254
+ ...props,
2255
+ children: /* @__PURE__ */ jsx(
2256
+ ButtonContent,
2257
+ {
2258
+ loading,
2259
+ size,
2260
+ loadingPosition,
2261
+ startIcon,
2262
+ endIcon,
2263
+ asChild,
2264
+ children
2265
+ }
2266
+ )
2267
+ }
2268
+ );
2269
+ }
2270
+ function ButtonContent({
2271
+ children,
2272
+ loading = false,
2273
+ loadingPosition = "start",
2274
+ startIcon,
2275
+ asChild,
2276
+ endIcon,
2277
+ ...props
2278
+ }) {
2279
+ const isStartLoading = loading && loadingPosition === "start";
2280
+ const StartIcon = isStartLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : startIcon || null;
2281
+ const isEndLoading = loading && loadingPosition === "end";
2282
+ const EndIcon = isEndLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : endIcon || null;
2283
+ const isCenterLoading = loading && loadingPosition === "center";
2284
+ return asChild && React16.isValidElement(children) ? React16.cloneElement(
2285
+ children,
2286
+ props,
2287
+ /* @__PURE__ */ jsxs(React16.Fragment, { children: [
2288
+ StartIcon,
2289
+ isCenterLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : React16.isValidElement(children) ? children.props?.children : null,
2290
+ EndIcon
2291
+ ] })
2292
+ ) : /* @__PURE__ */ jsxs(React16.Fragment, { children: [
2293
+ StartIcon,
2294
+ isCenterLoading ? /* @__PURE__ */ jsx(Spinner, { "aria-label": "Loading" }) : children,
2295
+ EndIcon
2296
+ ] });
2297
+ }
2298
+
2299
+ export { Button, ColorPicker, ColorPickerAlphaSlider, ColorPickerArea, ColorPickerContent, ColorPickerEyeDropper, ColorPickerFormatSelect, ColorPickerHueSlider, ColorPickerInput, ColorPickerSwatch, ColorPickerTrigger, Stepper, StepperActivationMode, StepperContent, StepperDataState, StepperDescription, StepperFocusIntent, StepperIndicator, StepperItem, StepperNav, StepperNavigationDirection, StepperNextTrigger, StepperOrientation, StepperPanel, StepperPrevTrigger, StepperTitle, StepperTrigger, Toaster, useColorPickerStore, useStepperContext, useStepperFocusContext, useStepperItemContext };