@codefast/ui 0.3.11 → 0.3.12-canary.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 (246) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +4 -0
  3. package/dist/components/accordion.d.ts +11 -29
  4. package/dist/components/accordion.d.ts.map +1 -0
  5. package/dist/components/accordion.js +10 -37
  6. package/dist/components/alert-dialog.d.ts +25 -60
  7. package/dist/components/alert-dialog.d.ts.map +1 -0
  8. package/dist/components/alert-dialog.js +16 -69
  9. package/dist/components/alert.d.ts +16 -27
  10. package/dist/components/alert.d.ts.map +1 -0
  11. package/dist/components/alert.js +22 -30
  12. package/dist/components/aspect-ratio.d.ts +5 -8
  13. package/dist/components/aspect-ratio.d.ts.map +1 -0
  14. package/dist/components/aspect-ratio.js +5 -7
  15. package/dist/components/avatar.d.ts +7 -17
  16. package/dist/components/avatar.d.ts.map +1 -0
  17. package/dist/components/avatar.js +7 -18
  18. package/dist/components/badge.d.ts +15 -21
  19. package/dist/components/badge.d.ts.map +1 -0
  20. package/dist/components/badge.js +23 -20
  21. package/dist/components/breadcrumb.d.ts +13 -35
  22. package/dist/components/breadcrumb.d.ts.map +1 -0
  23. package/dist/components/breadcrumb.js +13 -49
  24. package/dist/components/button-group.d.ts +15 -29
  25. package/dist/components/button-group.d.ts.map +1 -0
  26. package/dist/components/button-group.js +22 -27
  27. package/dist/components/button.d.ts +26 -35
  28. package/dist/components/button.d.ts.map +1 -0
  29. package/dist/components/button.js +43 -51
  30. package/dist/components/calendar.d.ts +10 -24
  31. package/dist/components/calendar.d.ts.map +1 -0
  32. package/dist/components/calendar.js +75 -92
  33. package/dist/components/card.d.ts +11 -34
  34. package/dist/components/card.d.ts.map +1 -0
  35. package/dist/components/card.js +11 -39
  36. package/dist/components/carousel.d.ts +25 -55
  37. package/dist/components/carousel.d.ts.map +1 -0
  38. package/dist/components/carousel.js +82 -114
  39. package/dist/components/chart.d.ts +37 -72
  40. package/dist/components/chart.d.ts.map +1 -0
  41. package/dist/components/chart.js +161 -150
  42. package/dist/components/checkbox-cards.d.ts +9 -15
  43. package/dist/components/checkbox-cards.d.ts.map +1 -0
  44. package/dist/components/checkbox-cards.js +8 -22
  45. package/dist/components/checkbox-group.d.ts +9 -16
  46. package/dist/components/checkbox-group.d.ts.map +1 -0
  47. package/dist/components/checkbox-group.js +7 -19
  48. package/dist/components/checkbox.d.ts +5 -9
  49. package/dist/components/checkbox.d.ts.map +1 -0
  50. package/dist/components/checkbox.js +6 -14
  51. package/dist/components/collapsible.d.ts +7 -14
  52. package/dist/components/collapsible.d.ts.map +1 -0
  53. package/dist/components/collapsible.js +7 -15
  54. package/dist/components/command.d.ts +24 -55
  55. package/dist/components/command.d.ts.map +1 -0
  56. package/dist/components/command.js +18 -69
  57. package/dist/components/context-menu.d.ts +23 -72
  58. package/dist/components/context-menu.d.ts.map +1 -0
  59. package/dist/components/context-menu.js +21 -89
  60. package/dist/components/dialog.d.ts +23 -53
  61. package/dist/components/dialog.d.ts.map +1 -0
  62. package/dist/components/dialog.js +20 -72
  63. package/dist/components/drawer.d.ts +29 -60
  64. package/dist/components/drawer.d.ts.map +1 -0
  65. package/dist/components/drawer.js +16 -58
  66. package/dist/components/dropdown-menu.d.ts +23 -73
  67. package/dist/components/dropdown-menu.d.ts.map +1 -0
  68. package/dist/components/dropdown-menu.js +21 -96
  69. package/dist/components/empty.d.ts +16 -37
  70. package/dist/components/empty.d.ts.map +1 -0
  71. package/dist/components/empty.js +24 -44
  72. package/dist/components/field.d.ts +26 -63
  73. package/dist/components/field.d.ts.map +1 -0
  74. package/dist/components/field.js +46 -89
  75. package/dist/components/form.d.ts +16 -37
  76. package/dist/components/form.d.ts.map +1 -0
  77. package/dist/components/form.js +50 -66
  78. package/dist/components/hover-card.d.ts +8 -21
  79. package/dist/components/hover-card.d.ts.map +1 -0
  80. package/dist/components/hover-card.js +8 -23
  81. package/dist/components/input-group.d.ts +29 -53
  82. package/dist/components/input-group.d.ts.map +1 -0
  83. package/dist/components/input-group.js +59 -66
  84. package/dist/components/input-number.d.ts +8 -28
  85. package/dist/components/input-number.d.ts.map +1 -0
  86. package/dist/components/input-number.js +14 -55
  87. package/dist/components/input-otp.d.ts +11 -24
  88. package/dist/components/input-otp.d.ts.map +1 -0
  89. package/dist/components/input-otp.js +13 -34
  90. package/dist/components/input-password.d.ts +6 -12
  91. package/dist/components/input-password.d.ts.map +1 -0
  92. package/dist/components/input-password.js +10 -31
  93. package/dist/components/input-search.d.ts +9 -18
  94. package/dist/components/input-search.d.ts.map +1 -0
  95. package/dist/components/input-search.js +16 -44
  96. package/dist/components/input.d.ts +5 -10
  97. package/dist/components/input.d.ts.map +1 -0
  98. package/dist/components/input.js +5 -9
  99. package/dist/components/item.d.ts +33 -69
  100. package/dist/components/item.d.ts.map +1 -0
  101. package/dist/components/item.js +47 -90
  102. package/dist/components/kbd.d.ts +6 -13
  103. package/dist/components/kbd.d.ts.map +1 -0
  104. package/dist/components/kbd.js +6 -13
  105. package/dist/components/label.d.ts +5 -9
  106. package/dist/components/label.d.ts.map +1 -0
  107. package/dist/components/label.js +5 -8
  108. package/dist/components/menubar.d.ts +24 -80
  109. package/dist/components/menubar.d.ts.map +1 -0
  110. package/dist/components/menubar.js +23 -99
  111. package/dist/components/native-select.d.ts +7 -16
  112. package/dist/components/native-select.d.ts.map +1 -0
  113. package/dist/components/native-select.js +7 -25
  114. package/dist/components/navigation-menu.d.ts +13 -36
  115. package/dist/components/navigation-menu.d.ts.map +1 -0
  116. package/dist/components/navigation-menu.js +25 -61
  117. package/dist/components/pagination.d.ts +15 -35
  118. package/dist/components/pagination.d.ts.map +1 -0
  119. package/dist/components/pagination.js +13 -55
  120. package/dist/components/popover.d.ts +9 -24
  121. package/dist/components/popover.d.ts.map +1 -0
  122. package/dist/components/popover.js +9 -27
  123. package/dist/components/progress-circle.d.ts +89 -106
  124. package/dist/components/progress-circle.d.ts.map +1 -0
  125. package/dist/components/progress-circle.js +70 -103
  126. package/dist/components/progress.d.ts +5 -10
  127. package/dist/components/progress.d.ts.map +1 -0
  128. package/dist/components/progress.js +7 -13
  129. package/dist/components/radio-cards.d.ts +5 -10
  130. package/dist/components/radio-cards.d.ts.map +1 -0
  131. package/dist/components/radio-cards.js +7 -21
  132. package/dist/components/radio-group.d.ts +6 -13
  133. package/dist/components/radio-group.d.ts.map +1 -0
  134. package/dist/components/radio-group.js +6 -17
  135. package/dist/components/radio.d.ts +6 -12
  136. package/dist/components/radio.d.ts.map +1 -0
  137. package/dist/components/radio.js +5 -10
  138. package/dist/components/resizable.d.ts +8 -18
  139. package/dist/components/resizable.d.ts.map +1 -0
  140. package/dist/components/resizable.js +7 -21
  141. package/dist/components/scroll-area.d.ts +21 -33
  142. package/dist/components/scroll-area.d.ts.map +1 -0
  143. package/dist/components/scroll-area.js +64 -84
  144. package/dist/components/select.d.ts +17 -50
  145. package/dist/components/select.d.ts.map +1 -0
  146. package/dist/components/select.js +26 -78
  147. package/dist/components/separator.d.ts +20 -29
  148. package/dist/components/separator.d.ts.map +1 -0
  149. package/dist/components/separator.js +27 -36
  150. package/dist/components/sheet.d.ts +30 -62
  151. package/dist/components/sheet.d.ts.map +1 -0
  152. package/dist/components/sheet.js +36 -80
  153. package/dist/components/sidebar.d.ts +67 -160
  154. package/dist/components/sidebar.d.ts.map +1 -0
  155. package/dist/components/sidebar.js +166 -301
  156. package/dist/components/skeleton.d.ts +5 -9
  157. package/dist/components/skeleton.d.ts.map +1 -0
  158. package/dist/components/skeleton.js +5 -8
  159. package/dist/components/slider.d.ts +5 -13
  160. package/dist/components/slider.d.ts.map +1 -0
  161. package/dist/components/slider.js +12 -34
  162. package/dist/components/sonner.d.ts +8 -10
  163. package/dist/components/sonner.d.ts.map +1 -0
  164. package/dist/components/sonner.js +13 -16
  165. package/dist/components/spinner.d.ts +6 -12
  166. package/dist/components/spinner.d.ts.map +1 -0
  167. package/dist/components/spinner.js +20 -33
  168. package/dist/components/switch.d.ts +5 -9
  169. package/dist/components/switch.d.ts.map +1 -0
  170. package/dist/components/switch.js +5 -12
  171. package/dist/components/table.d.ts +12 -37
  172. package/dist/components/table.d.ts.map +1 -0
  173. package/dist/components/table.js +12 -47
  174. package/dist/components/tabs.d.ts +8 -21
  175. package/dist/components/tabs.d.ts.map +1 -0
  176. package/dist/components/tabs.js +8 -23
  177. package/dist/components/textarea.d.ts +5 -9
  178. package/dist/components/textarea.d.ts.map +1 -0
  179. package/dist/components/textarea.js +5 -8
  180. package/dist/components/toggle-group.d.ts +10 -24
  181. package/dist/components/toggle-group.d.ts.map +1 -0
  182. package/dist/components/toggle-group.js +20 -38
  183. package/dist/components/toggle.d.ts +18 -25
  184. package/dist/components/toggle.d.ts.map +1 -0
  185. package/dist/components/toggle.js +24 -29
  186. package/dist/components/tooltip.d.ts +9 -24
  187. package/dist/components/tooltip.d.ts.map +1 -0
  188. package/dist/components/tooltip.js +9 -28
  189. package/dist/hooks/use-animated-value.d.ts +2 -4
  190. package/dist/hooks/use-animated-value.d.ts.map +1 -0
  191. package/dist/hooks/use-animated-value.js +67 -58
  192. package/dist/hooks/use-copy-to-clipboard.d.ts +6 -11
  193. package/dist/hooks/use-copy-to-clipboard.d.ts.map +1 -0
  194. package/dist/hooks/use-copy-to-clipboard.js +42 -39
  195. package/dist/hooks/use-is-mobile.d.ts +2 -4
  196. package/dist/hooks/use-is-mobile.d.ts.map +1 -0
  197. package/dist/hooks/use-is-mobile.js +20 -23
  198. package/dist/hooks/use-media-query.d.ts +2 -4
  199. package/dist/hooks/use-media-query.d.ts.map +1 -0
  200. package/dist/hooks/use-media-query.js +49 -46
  201. package/dist/hooks/use-mutation-observer.d.ts +3 -6
  202. package/dist/hooks/use-mutation-observer.d.ts.map +1 -0
  203. package/dist/hooks/use-mutation-observer.js +33 -34
  204. package/dist/hooks/use-pagination.d.ts +15 -22
  205. package/dist/hooks/use-pagination.d.ts.map +1 -0
  206. package/dist/hooks/use-pagination.js +99 -99
  207. package/dist/index.d.ts +131 -69
  208. package/dist/index.d.ts.map +1 -0
  209. package/dist/index.js +68 -69
  210. package/dist/primitives/checkbox-group.d.ts +84 -105
  211. package/dist/primitives/checkbox-group.d.ts.map +1 -0
  212. package/dist/primitives/checkbox-group.js +91 -105
  213. package/dist/primitives/input-number.d.ts +41 -51
  214. package/dist/primitives/input-number.d.ts.map +1 -0
  215. package/dist/primitives/input-number.js +417 -473
  216. package/dist/primitives/input.d.ts +43 -48
  217. package/dist/primitives/input.d.ts.map +1 -0
  218. package/dist/primitives/input.js +67 -66
  219. package/dist/primitives/progress-circle.d.ts +49 -79
  220. package/dist/primitives/progress-circle.d.ts.map +1 -0
  221. package/dist/primitives/progress-circle.js +134 -149
  222. package/package.json +17 -10
  223. package/{dist → src}/css/preset.css +1 -1
  224. /package/{dist → src}/css/amber.css +0 -0
  225. /package/{dist → src}/css/blue.css +0 -0
  226. /package/{dist → src}/css/cyan.css +0 -0
  227. /package/{dist → src}/css/emerald.css +0 -0
  228. /package/{dist → src}/css/fuchsia.css +0 -0
  229. /package/{dist → src}/css/gray.css +0 -0
  230. /package/{dist → src}/css/green.css +0 -0
  231. /package/{dist → src}/css/indigo.css +0 -0
  232. /package/{dist → src}/css/lime.css +0 -0
  233. /package/{dist → src}/css/neutral.css +0 -0
  234. /package/{dist → src}/css/orange.css +0 -0
  235. /package/{dist → src}/css/pink.css +0 -0
  236. /package/{dist → src}/css/purple.css +0 -0
  237. /package/{dist → src}/css/red.css +0 -0
  238. /package/{dist → src}/css/rose.css +0 -0
  239. /package/{dist → src}/css/sky.css +0 -0
  240. /package/{dist → src}/css/slate.css +0 -0
  241. /package/{dist → src}/css/stone.css +0 -0
  242. /package/{dist → src}/css/style.css +0 -0
  243. /package/{dist → src}/css/teal.css +0 -0
  244. /package/{dist → src}/css/violet.css +0 -0
  245. /package/{dist → src}/css/yellow.css +0 -0
  246. /package/{dist → src}/css/zinc.css +0 -0
@@ -1,514 +1,458 @@
1
- import { Field as InputField, Input, createInputScope } from "./input.js";
2
- import { jsx } from "react/jsx-runtime";
3
- import { useCallback, useEffect, useMemo, useRef } from "react";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { composeEventHandlers } from "@radix-ui/primitive";
4
3
  import { createContextScope } from "@radix-ui/react-context";
5
4
  import { useControllableState } from "@radix-ui/react-use-controllable-state";
6
- import { composeEventHandlers } from "@radix-ui/primitive";
7
- //#region src/primitives/input-number.tsx
5
+ import { useCallback, useEffect, useMemo, useRef } from "react";
6
+ import * as InputPrimitive from "#primitives/input";
7
+ import { createInputScope } from "#primitives/input";
8
+ /* -----------------------------------------------------------------------------
9
+ * Context: InputNumber
10
+ * -------------------------------------------------------------------------- */
8
11
  /**
9
- * The name of the InputNumber component constant.
10
- */
12
+ * The name of the InputNumber component constant.
13
+ */
11
14
  const NUMBER_INPUT_NAME = "InputNumber";
12
- const [createInputNumberContext, createInputNumberScope] = createContextScope(NUMBER_INPUT_NAME, [createInputScope]);
15
+ const [createInputNumberContext, createInputNumberScope] = createContextScope(NUMBER_INPUT_NAME, [
16
+ createInputScope,
17
+ ]);
13
18
  const useInputScope = createInputScope();
14
19
  const [InputNumberContextProvider, useInputNumberContext] = createInputNumberContext(NUMBER_INPUT_NAME);
15
20
  function InputNumber(numberInputProps) {
16
- const { __scopeInputNumber, ariaDecrementLabel, ariaIncrementLabel, defaultValue, formatOptions = {
17
- minimumFractionDigits: 0,
18
- style: "decimal"
19
- }, id, locale, max, min, onChange, step = 1, value: valueProperty, ...props } = numberInputProps;
20
- /** Scope for the input component */
21
- const inputScope = useInputScope(__scopeInputNumber);
22
- /** Reference to the input element */
23
- const inputRef = useRef(null);
24
- /** Controlled or uncontrolled value state */
25
- const [value, setValue] = useControllableState({
26
- defaultProp: defaultValue,
27
- onChange,
28
- prop: valueProperty
29
- });
30
- /** Separators used for number formatting based on locale */
31
- const { decimalSeparator, thousandSeparator } = useMemo(() => getNumberFormatSeparators(locale), [locale]);
32
- /**
33
- * Formats a number value into a string representation
34
- * @param inputValue - The number to format
35
- * @returns A formatted string representation of the number
36
- */
37
- const formatValue = useCallback((inputValue) => {
38
- if (inputValue === void 0 || Number.isNaN(inputValue)) return "";
39
- return new Intl.NumberFormat(locale, formatOptions).format(inputValue);
40
- }, [formatOptions, locale]);
41
- /**
42
- * Parses a string or number input into a normalized number value
43
- * @param inputValue - The value to parse
44
- * @returns The parsed number value, clamped between min and max
45
- */
46
- const parseValue = useCallback((inputValue) => {
47
- if (typeof inputValue === "number") return clamp(inputValue, min, max);
48
- if (typeof inputValue !== "string") return NaN;
49
- const cleanedValue = inputValue.trim().replaceAll(/[^\d.,\-()]/g, "");
50
- if (cleanedValue === "") return NaN;
51
- const normalizedValue = normalizeInputValue(cleanedValue, thousandSeparator, decimalSeparator);
52
- let parsedValue = Number.parseFloat(normalizedValue);
53
- if (formatOptions.style === "percent") parsedValue /= 100;
54
- return Number.isNaN(parsedValue) ? 0 : clamp(parsedValue, min, max);
55
- }, [
56
- decimalSeparator,
57
- formatOptions.style,
58
- max,
59
- min,
60
- thousandSeparator
61
- ]);
62
- /**
63
- * Changes the current value based on a provided operation
64
- * @param operation - Function that takes the current value and returns a new value
65
- */
66
- const changeNumberValue = useCallback((operation) => {
67
- const inputElement = inputRef.current;
68
- if (!inputElement || props.disabled || props.readOnly) return;
69
- const newValue = clamp(operation(parseValue(inputElement.value) || 0), min, max);
70
- inputElement.value = formatValue(newValue);
71
- setValue(newValue);
72
- }, [
73
- props.disabled,
74
- formatValue,
75
- max,
76
- min,
77
- parseValue,
78
- props.readOnly,
79
- setValue
80
- ]);
81
- /**
82
- * Increments the current value by the step amount
83
- */
84
- const handleIncrement = useCallback(() => {
85
- changeNumberValue((number) => number + step);
86
- }, [changeNumberValue, step]);
87
- /**
88
- * Decrements the current value by the step amount
89
- */
90
- const handleDecrement = useCallback(() => {
91
- changeNumberValue((number) => number - step);
92
- }, [changeNumberValue, step]);
93
- /**
94
- * Sets the value to the maximum allowed
95
- */
96
- const handleIncrementToMax = useCallback(() => {
97
- changeNumberValue((number) => max ?? number + step);
98
- }, [
99
- changeNumberValue,
100
- max,
101
- step
102
- ]);
103
- /**
104
- * Sets the value to the minimum allowed
105
- */
106
- const handleDecrementToMin = useCallback(() => {
107
- changeNumberValue((number) => min ?? number - step);
108
- }, [
109
- changeNumberValue,
110
- min,
111
- step
112
- ]);
113
- return /* @__PURE__ */ jsx(InputNumberContextProvider, {
114
- ariaDecrementLabel,
115
- ariaIncrementLabel,
116
- defaultValue,
117
- disabled: props.disabled,
118
- formatOptions,
119
- formatValue,
120
- id,
121
- inputRef,
122
- max,
123
- min,
124
- parseValue,
125
- readOnly: props.readOnly,
126
- scope: __scopeInputNumber,
127
- value,
128
- onChange: setValue,
129
- onDecrement: handleDecrement,
130
- onDecrementToMin: handleDecrementToMin,
131
- onIncrement: handleIncrement,
132
- onIncrementToMax: handleIncrementToMax,
133
- children: /* @__PURE__ */ jsx(Input, {
134
- ...inputScope,
135
- ...props
136
- })
137
- });
21
+ const { __scopeInputNumber, ariaDecrementLabel, ariaIncrementLabel, defaultValue, formatOptions = { minimumFractionDigits: 0, style: "decimal" }, id, locale, max, min, onChange, step = 1, value: valueProperty, ...props } = numberInputProps;
22
+ /** Scope for the input component */
23
+ const inputScope = useInputScope(__scopeInputNumber);
24
+ /** Reference to the input element */
25
+ const inputRef = useRef(null);
26
+ /** Controlled or uncontrolled value state */
27
+ const [value, setValue] = useControllableState({
28
+ defaultProp: defaultValue,
29
+ onChange,
30
+ prop: valueProperty,
31
+ });
32
+ /** Separators used for number formatting based on locale */
33
+ const { decimalSeparator, thousandSeparator } = useMemo(() => getNumberFormatSeparators(locale), [locale]);
34
+ /**
35
+ * Formats a number value into a string representation
36
+ * @param inputValue - The number to format
37
+ * @returns A formatted string representation of the number
38
+ */
39
+ const formatValue = useCallback((inputValue) => {
40
+ if (inputValue === undefined || Number.isNaN(inputValue)) {
41
+ return "";
42
+ }
43
+ return new Intl.NumberFormat(locale, formatOptions).format(inputValue);
44
+ }, [formatOptions, locale]);
45
+ /**
46
+ * Parses a string or number input into a normalized number value
47
+ * @param inputValue - The value to parse
48
+ * @returns The parsed number value, clamped between min and max
49
+ */
50
+ const parseValue = useCallback((inputValue) => {
51
+ if (typeof inputValue === "number") {
52
+ return clamp(inputValue, min, max);
53
+ }
54
+ if (typeof inputValue !== "string") {
55
+ return Number.NaN;
56
+ }
57
+ const cleanedValue = inputValue.trim().replaceAll(/[^\d.,\-()]/g, "");
58
+ if (cleanedValue === "") {
59
+ return Number.NaN;
60
+ }
61
+ const normalizedValue = normalizeInputValue(cleanedValue, thousandSeparator, decimalSeparator);
62
+ let parsedValue = Number.parseFloat(normalizedValue);
63
+ if (formatOptions.style === "percent") {
64
+ parsedValue /= 100;
65
+ }
66
+ return Number.isNaN(parsedValue) ? 0 : clamp(parsedValue, min, max);
67
+ }, [decimalSeparator, formatOptions.style, max, min, thousandSeparator]);
68
+ /**
69
+ * Changes the current value based on a provided operation
70
+ * @param operation - Function that takes the current value and returns a new value
71
+ */
72
+ const changeNumberValue = useCallback((operation) => {
73
+ const inputElement = inputRef.current;
74
+ if (!inputElement || props.disabled || props.readOnly) {
75
+ return;
76
+ }
77
+ const currentValue = parseValue(inputElement.value) || 0;
78
+ const newValue = clamp(operation(currentValue), min, max);
79
+ inputElement.value = formatValue(newValue);
80
+ setValue(newValue);
81
+ }, [props.disabled, formatValue, max, min, parseValue, props.readOnly, setValue]);
82
+ /**
83
+ * Increments the current value by the step amount
84
+ */
85
+ const handleIncrement = useCallback(() => {
86
+ changeNumberValue((number) => number + step);
87
+ }, [changeNumberValue, step]);
88
+ /**
89
+ * Decrements the current value by the step amount
90
+ */
91
+ const handleDecrement = useCallback(() => {
92
+ changeNumberValue((number) => number - step);
93
+ }, [changeNumberValue, step]);
94
+ /**
95
+ * Sets the value to the maximum allowed
96
+ */
97
+ const handleIncrementToMax = useCallback(() => {
98
+ changeNumberValue((number) => max ?? number + step);
99
+ }, [changeNumberValue, max, step]);
100
+ /**
101
+ * Sets the value to the minimum allowed
102
+ */
103
+ const handleDecrementToMin = useCallback(() => {
104
+ changeNumberValue((number) => min ?? number - step);
105
+ }, [changeNumberValue, min, step]);
106
+ return (_jsx(InputNumberContextProvider, { ariaDecrementLabel: ariaDecrementLabel, ariaIncrementLabel: ariaIncrementLabel, defaultValue: defaultValue, disabled: props.disabled, formatOptions: formatOptions, formatValue: formatValue, id: id, inputRef: inputRef, max: max, min: min, parseValue: parseValue, readOnly: props.readOnly, scope: __scopeInputNumber, value: value, onChange: setValue, onDecrement: handleDecrement, onDecrementToMin: handleDecrementToMin, onIncrement: handleIncrement, onIncrementToMax: handleIncrementToMax, children: _jsx(InputPrimitive.Root, { ...inputScope, ...props }) }));
138
107
  }
108
+ /* -----------------------------------------------------------------------------
109
+ * Component: InputNumberField
110
+ * -------------------------------------------------------------------------- */
139
111
  /**
140
- * The name of the InputNumberField component constant.
141
- */
112
+ * The name of the InputNumberField component constant.
113
+ */
142
114
  const NUMBER_INPUT_FIELD_NAME = "InputNumberField";
143
115
  function InputNumberField({ __scopeInputNumber, onBlur, onKeyDown, ...props }) {
144
- const inputScope = useInputScope(__scopeInputNumber);
145
- const { defaultValue, disabled, formatValue, id, inputRef, max, min, onChange, onDecrement, onDecrementToMin, onIncrement, onIncrementToMax, parseValue, readOnly, step, value } = useInputNumberContext(NUMBER_INPUT_FIELD_NAME, __scopeInputNumber);
146
- /**
147
- * Handles the blur event to format the value of the input.
148
- *
149
- * @param event - The blur event triggered when the input loses focus.
150
- */
151
- const handleBlur = useCallback((event) => {
152
- const numericValue = parseValue(event.target.value);
153
- const formattedValue = formatValue(numericValue);
154
- if (formattedValue !== event.target.value) event.target.value = formattedValue;
155
- onChange(numericValue);
156
- }, [
157
- formatValue,
158
- onChange,
159
- parseValue
160
- ]);
161
- /**
162
- * Handles keydown events to increment, decrement, or perform other actions.
163
- *
164
- * @param event - The keyboard event triggered by key presses.
165
- */
166
- const handleKeyDown = useCallback((event) => {
167
- switch (event.key) {
168
- case "ArrowUp":
169
- onIncrement();
170
- event.preventDefault();
171
- break;
172
- case "PageUp":
173
- onIncrementToMax();
174
- event.preventDefault();
175
- break;
176
- case "ArrowDown":
177
- onDecrement();
178
- event.preventDefault();
179
- break;
180
- case "PageDown":
181
- onDecrementToMin();
182
- event.preventDefault();
183
- break;
184
- default: break;
185
- }
186
- }, [
187
- onIncrement,
188
- onIncrementToMax,
189
- onDecrement,
190
- onDecrementToMin
191
- ]);
192
- /**
193
- * Prevents invalid keyboard input for the numeric input field.
194
- *
195
- * @param event - The keyboard event to handle.
196
- */
197
- const handleKeyDownPrevent = useCallback((event) => {
198
- switch (event.key) {
199
- case "ArrowUp":
200
- case "ArrowDown":
201
- case "ArrowLeft":
202
- case "ArrowRight":
203
- case "PageUp":
204
- case "PageDown":
205
- case "Tab":
206
- case "Escape":
207
- case "Enter":
208
- case "Backspace":
209
- case "Delete":
210
- case "Home":
211
- case "End":
212
- case ".":
213
- case ",":
214
- case "-":
215
- case "%": return;
216
- default:
217
- if (isNumberKey(event.key) || isModifierKey(event) || isFunctionKey(event.key)) return;
218
- event.preventDefault();
219
- }
220
- }, []);
221
- /**
222
- * Handles the Enter key to format the value of the input.
223
- *
224
- * @param event - The keyboard event triggered by pressing Enter.
225
- */
226
- const handleKeyDownEnter = useCallback((event) => {
227
- const inputElement = inputRef.current;
228
- if (event.key !== "Enter" || !inputElement) return;
229
- const numericValue = parseValue(inputElement.value);
230
- const formattedValue = formatValue(numericValue);
231
- if (formattedValue !== inputElement.value) inputElement.value = formattedValue;
232
- onChange(numericValue);
233
- }, [
234
- formatValue,
235
- inputRef,
236
- onChange,
237
- parseValue
238
- ]);
239
- /**
240
- * Creates a combined keydown event handler that processes keyboard events in sequence.
241
- *
242
- * The handler chain executes in the following order:
243
- * 1. User-provided onKeyDown handler (if any)
244
- * 2. handleKeyDownPrevent - Prevents non-numeric input
245
- * 3. handleKeyDown - Handles arrow keys and page up/down for value adjustments
246
- * 4. handleKeyDownEnter - Handles Enter key press to format and update the value
247
- *
248
- * @returns A composed event handler function for the onKeyDown event
249
- */
250
- const combinedKeyDownHandler = useCallback((event) => {
251
- composeEventHandlers(onKeyDown, chain(handleKeyDownPrevent, handleKeyDown, handleKeyDownEnter))(event);
252
- }, [
253
- onKeyDown,
254
- handleKeyDown,
255
- handleKeyDownEnter,
256
- handleKeyDownPrevent
257
- ]);
258
- /**
259
- * Adds a listener to handle wheel events for incrementing or decrementing the value.
260
- */
261
- useEffect(() => {
262
- const handleWheel = (event) => {
263
- const inputElement = inputRef.current;
264
- if (!inputElement || disabled || readOnly || document.activeElement !== inputElement) return;
265
- event.preventDefault();
266
- if (event.deltaY > 0) onIncrement();
267
- else onDecrement();
268
- };
269
- const inputElement = inputRef.current;
270
- inputElement?.addEventListener("wheel", handleWheel);
271
- return () => {
272
- inputElement?.removeEventListener("wheel", handleWheel);
273
- };
274
- }, [
275
- onIncrement,
276
- onDecrement,
277
- inputRef,
278
- disabled,
279
- readOnly
280
- ]);
281
- /**
282
- * Updates the input field's value when it changes in the context.
283
- */
284
- useEffect(() => {
285
- const inputElement = inputRef.current;
286
- if (inputElement && inputElement !== document.activeElement) inputElement.value = formatValue(value);
287
- }, [
288
- formatValue,
289
- inputRef,
290
- value
291
- ]);
292
- /**
293
- * Adds a listener to handle form reset events by clearing the input value.
294
- */
295
- useEffect(() => {
296
- const inputElement = inputRef.current;
297
- if (!inputElement) return;
298
- const handleReset = () => {
299
- onChange(parseValue(defaultValue));
300
- };
301
- const form = inputElement.form;
302
- form?.addEventListener("reset", handleReset);
303
- return () => {
304
- form?.removeEventListener("reset", handleReset);
305
- };
306
- }, [
307
- defaultValue,
308
- inputRef,
309
- onChange,
310
- parseValue
311
- ]);
312
- return /* @__PURE__ */ jsx(InputField, {
313
- ref: inputRef,
314
- defaultValue: formatValue(value),
315
- disabled,
316
- id,
317
- inputMode: "decimal",
318
- max,
319
- min,
320
- readOnly,
321
- step,
322
- onBlur: composeEventHandlers(onBlur, handleBlur),
323
- onKeyDown: combinedKeyDownHandler,
324
- ...inputScope,
325
- ...props
326
- });
116
+ // Retrieve input number context and input scope
117
+ const inputScope = useInputScope(__scopeInputNumber);
118
+ const { defaultValue, disabled, formatValue, id, inputRef, max, min, onChange, onDecrement, onDecrementToMin, onIncrement, onIncrementToMax, parseValue, readOnly, step, value, } = useInputNumberContext(NUMBER_INPUT_FIELD_NAME, __scopeInputNumber);
119
+ /**
120
+ * Handles the blur event to format the value of the input.
121
+ *
122
+ * @param event - The blur event triggered when the input loses focus.
123
+ */
124
+ const handleBlur = useCallback((event) => {
125
+ const numericValue = parseValue(event.target.value);
126
+ const formattedValue = formatValue(numericValue);
127
+ if (formattedValue !== event.target.value) {
128
+ event.target.value = formattedValue;
129
+ }
130
+ onChange(numericValue);
131
+ }, [formatValue, onChange, parseValue]);
132
+ /**
133
+ * Handles keydown events to increment, decrement, or perform other actions.
134
+ *
135
+ * @param event - The keyboard event triggered by key presses.
136
+ */
137
+ const handleKeyDown = useCallback((event) => {
138
+ switch (event.key) {
139
+ case "ArrowUp": {
140
+ onIncrement();
141
+ event.preventDefault();
142
+ break;
143
+ }
144
+ case "PageUp": {
145
+ onIncrementToMax();
146
+ event.preventDefault();
147
+ break;
148
+ }
149
+ case "ArrowDown": {
150
+ onDecrement();
151
+ event.preventDefault();
152
+ break;
153
+ }
154
+ case "PageDown": {
155
+ onDecrementToMin();
156
+ event.preventDefault();
157
+ break;
158
+ }
159
+ default: {
160
+ break;
161
+ }
162
+ }
163
+ }, [onIncrement, onIncrementToMax, onDecrement, onDecrementToMin]);
164
+ /**
165
+ * Prevents invalid keyboard input for the numeric input field.
166
+ *
167
+ * @param event - The keyboard event to handle.
168
+ */
169
+ const handleKeyDownPrevent = useCallback((event) => {
170
+ switch (event.key) {
171
+ case "ArrowUp":
172
+ case "ArrowDown":
173
+ case "ArrowLeft":
174
+ case "ArrowRight":
175
+ case "PageUp":
176
+ case "PageDown":
177
+ case "Tab":
178
+ case "Escape":
179
+ case "Enter":
180
+ case "Backspace":
181
+ case "Delete":
182
+ case "Home":
183
+ case "End":
184
+ case ".":
185
+ case ",":
186
+ case "-":
187
+ case "%": {
188
+ return;
189
+ }
190
+ default: {
191
+ if (isNumberKey(event.key) || isModifierKey(event) || isFunctionKey(event.key)) {
192
+ return;
193
+ }
194
+ event.preventDefault();
195
+ }
196
+ }
197
+ }, []);
198
+ /**
199
+ * Handles the Enter key to format the value of the input.
200
+ *
201
+ * @param event - The keyboard event triggered by pressing Enter.
202
+ */
203
+ const handleKeyDownEnter = useCallback((event) => {
204
+ const inputElement = inputRef.current;
205
+ if (event.key !== "Enter" || !inputElement) {
206
+ return;
207
+ }
208
+ const numericValue = parseValue(inputElement.value);
209
+ const formattedValue = formatValue(numericValue);
210
+ if (formattedValue !== inputElement.value) {
211
+ inputElement.value = formattedValue;
212
+ }
213
+ onChange(numericValue);
214
+ }, [formatValue, inputRef, onChange, parseValue]);
215
+ /**
216
+ * Creates a combined keydown event handler that processes keyboard events in sequence.
217
+ *
218
+ * The handler chain executes in the following order:
219
+ * 1. User-provided onKeyDown handler (if any)
220
+ * 2. handleKeyDownPrevent - Prevents non-numeric input
221
+ * 3. handleKeyDown - Handles arrow keys and page up/down for value adjustments
222
+ * 4. handleKeyDownEnter - Handles Enter key press to format and update the value
223
+ *
224
+ * @returns A composed event handler function for the onKeyDown event
225
+ */
226
+ const combinedKeyDownHandler = useCallback((event) => {
227
+ composeEventHandlers(onKeyDown, chain(handleKeyDownPrevent, handleKeyDown, handleKeyDownEnter))(event);
228
+ }, [onKeyDown, handleKeyDown, handleKeyDownEnter, handleKeyDownPrevent]);
229
+ /**
230
+ * Adds a listener to handle wheel events for incrementing or decrementing the value.
231
+ */
232
+ useEffect(() => {
233
+ const handleWheel = (event) => {
234
+ const inputElement = inputRef.current;
235
+ if (!inputElement || disabled || readOnly || document.activeElement !== inputElement) {
236
+ return;
237
+ }
238
+ event.preventDefault();
239
+ if (event.deltaY > 0) {
240
+ onIncrement();
241
+ }
242
+ else {
243
+ onDecrement();
244
+ }
245
+ };
246
+ const inputElement = inputRef.current;
247
+ inputElement?.addEventListener("wheel", handleWheel);
248
+ return () => {
249
+ inputElement?.removeEventListener("wheel", handleWheel);
250
+ };
251
+ }, [onIncrement, onDecrement, inputRef, disabled, readOnly]);
252
+ /**
253
+ * Updates the input field's value when it changes in the context.
254
+ */
255
+ useEffect(() => {
256
+ const inputElement = inputRef.current;
257
+ if (inputElement && inputElement !== document.activeElement) {
258
+ inputElement.value = formatValue(value);
259
+ }
260
+ }, [formatValue, inputRef, value]);
261
+ /**
262
+ * Adds a listener to handle form reset events by clearing the input value.
263
+ */
264
+ useEffect(() => {
265
+ const inputElement = inputRef.current;
266
+ if (!inputElement) {
267
+ return;
268
+ }
269
+ const handleReset = () => {
270
+ onChange(parseValue(defaultValue));
271
+ };
272
+ const form = inputElement.form;
273
+ form?.addEventListener("reset", handleReset);
274
+ return () => {
275
+ form?.removeEventListener("reset", handleReset);
276
+ };
277
+ }, [defaultValue, inputRef, onChange, parseValue]);
278
+ return (_jsx(InputPrimitive.Field, { ref: inputRef, defaultValue: formatValue(value), disabled: disabled, id: id, inputMode: "decimal", max: max, min: min, readOnly: readOnly, step: step, onBlur: composeEventHandlers(onBlur, handleBlur), onKeyDown: combinedKeyDownHandler, ...inputScope, ...props }));
327
279
  }
280
+ /* -----------------------------------------------------------------------------
281
+ * Component: NumberStepperButton
282
+ * -------------------------------------------------------------------------- */
328
283
  /**
329
- * The name of the NumberStepperButton component constant.
330
- */
284
+ * The name of the NumberStepperButton component constant.
285
+ */
331
286
  const NUMBER_STEPPER_BUTTON_NAME = "NumberStepperButton";
332
287
  function NumberStepperButton({ __scopeInputNumber, operation, ...props }) {
333
- const { ariaDecrementLabel, ariaIncrementLabel, disabled, id, max, min, onDecrement, onIncrement, value } = useInputNumberContext(NUMBER_STEPPER_BUTTON_NAME, __scopeInputNumber);
334
- const isDisabled = useMemo(() => {
335
- return (disabled ?? (min !== void 0 && value !== void 0 && value <= min)) || max !== void 0 && value !== void 0 && value >= max;
336
- }, [
337
- min,
338
- max,
339
- value,
340
- disabled
341
- ]);
342
- /**
343
- * Ref to store a timeout ID for managing repeated button actions.
344
- */
345
- const timeoutIdRef = useRef(null);
346
- /**
347
- * Starts a repeated action at a regular interval.
348
- * The action begins immediately and then continues with a delay.
349
- *
350
- * @param callback - The callback function to execute repeatedly.
351
- */
352
- const startActionInterval = useCallback((callback) => {
353
- const interval = 100;
354
- const repeatAction = () => {
355
- callback();
356
- timeoutIdRef.current = setTimeout(repeatAction, interval);
357
- };
358
- callback();
359
- timeoutIdRef.current = setTimeout(repeatAction, interval * 2);
360
- }, []);
361
- /**
362
- * Clears any ongoing action intervals.
363
- */
364
- const clearActionInterval = useCallback(() => {
365
- if (timeoutIdRef.current) {
366
- clearTimeout(timeoutIdRef.current);
367
- timeoutIdRef.current = null;
368
- }
369
- }, []);
370
- /**
371
- * Handles pointer down events and triggers the appropriate action
372
- * (`increment` or `decrement`).
373
- */
374
- const handlePointerDown = useCallback(() => {
375
- startActionInterval(operation === "increment" ? onIncrement : onDecrement);
376
- }, [
377
- onDecrement,
378
- onIncrement,
379
- operation,
380
- startActionInterval
381
- ]);
382
- /**
383
- * Prevents the context menu from displaying when the button is right-clicked.
384
- *
385
- * @param event - The mouse event triggered by the right-click.
386
- */
387
- const handleContextMenu = useCallback((event) => {
388
- event.preventDefault();
389
- }, []);
390
- /**
391
- * Handles keyboard events to support activation of the button using
392
- * keyboard navigation (Enter or Space).
393
- *
394
- * @param event - The keyboard event with the triggered key.
395
- */
396
- const handleKeyDown = useCallback((event) => {
397
- if (event.key === "Enter" || event.key === " ") {
398
- event.preventDefault();
399
- (operation === "increment" ? onIncrement : onDecrement)();
400
- }
401
- }, [
402
- onDecrement,
403
- onIncrement,
404
- operation
405
- ]);
406
- return /* @__PURE__ */ jsx("button", {
407
- "aria-controls": id,
408
- "aria-label": operation === "increment" ? ariaIncrementLabel : ariaDecrementLabel,
409
- "aria-live": "polite",
410
- disabled: isDisabled,
411
- type: "button",
412
- onContextMenu: handleContextMenu,
413
- onKeyDown: handleKeyDown,
414
- onPointerCancel: clearActionInterval,
415
- onPointerDown: handlePointerDown,
416
- onPointerLeave: clearActionInterval,
417
- onPointerUp: clearActionInterval,
418
- ...props
419
- });
288
+ // Destructures relevant context values for the button functionality.
289
+ const { ariaDecrementLabel, ariaIncrementLabel, disabled, id, max, min, onDecrement, onIncrement, value, } = useInputNumberContext(NUMBER_STEPPER_BUTTON_NAME, __scopeInputNumber);
290
+ const isDisabled = useMemo(() => {
291
+ const atMin = min !== undefined && value !== undefined && value <= min;
292
+ const atMax = max !== undefined && value !== undefined && value >= max;
293
+ return (disabled ?? atMin) || atMax;
294
+ }, [min, max, value, disabled]);
295
+ /**
296
+ * Ref to store a timeout ID for managing repeated button actions.
297
+ */
298
+ const timeoutIdRef = useRef(null);
299
+ /**
300
+ * Starts a repeated action at a regular interval.
301
+ * The action begins immediately and then continues with a delay.
302
+ *
303
+ * @param callback - The callback function to execute repeatedly.
304
+ */
305
+ const startActionInterval = useCallback((callback) => {
306
+ // Time between repeated actions (in milliseconds).
307
+ const interval = 100;
308
+ // Function to perform the action and set the next interval.
309
+ const repeatAction = () => {
310
+ callback();
311
+ timeoutIdRef.current = setTimeout(repeatAction, interval);
312
+ };
313
+ callback();
314
+ timeoutIdRef.current = setTimeout(repeatAction, interval * 2);
315
+ }, []);
316
+ /**
317
+ * Clears any ongoing action intervals.
318
+ */
319
+ const clearActionInterval = useCallback(() => {
320
+ if (timeoutIdRef.current) {
321
+ clearTimeout(timeoutIdRef.current);
322
+ timeoutIdRef.current = null;
323
+ }
324
+ }, []);
325
+ /**
326
+ * Handles pointer down events and triggers the appropriate action
327
+ * (`increment` or `decrement`).
328
+ */
329
+ const handlePointerDown = useCallback(() => {
330
+ const action = operation === "increment" ? onIncrement : onDecrement;
331
+ startActionInterval(action);
332
+ }, [onDecrement, onIncrement, operation, startActionInterval]);
333
+ /**
334
+ * Prevents the context menu from displaying when the button is right-clicked.
335
+ *
336
+ * @param event - The mouse event triggered by the right-click.
337
+ */
338
+ const handleContextMenu = useCallback((event) => {
339
+ event.preventDefault();
340
+ }, []);
341
+ /**
342
+ * Handles keyboard events to support activation of the button using
343
+ * keyboard navigation (Enter or Space).
344
+ *
345
+ * @param event - The keyboard event with the triggered key.
346
+ */
347
+ const handleKeyDown = useCallback((event) => {
348
+ if (event.key === "Enter" || event.key === " ") {
349
+ event.preventDefault();
350
+ const action = operation === "increment" ? onIncrement : onDecrement;
351
+ action();
352
+ }
353
+ }, [onDecrement, onIncrement, operation]);
354
+ return (_jsx("button", { "aria-controls": id, "aria-label": operation === "increment" ? ariaIncrementLabel : ariaDecrementLabel, "aria-live": "polite", disabled: isDisabled, type: "button", onContextMenu: handleContextMenu, onKeyDown: handleKeyDown, onPointerCancel: clearActionInterval, onPointerDown: handlePointerDown, onPointerLeave: clearActionInterval, onPointerUp: clearActionInterval, ...props }));
420
355
  }
421
356
  function InputNumberIncrementButton(props) {
422
- return /* @__PURE__ */ jsx(NumberStepperButton, {
423
- operation: "increment",
424
- ...props
425
- });
357
+ return _jsx(NumberStepperButton, { operation: "increment", ...props });
426
358
  }
427
359
  function InputNumberDecrementButton(props) {
428
- return /* @__PURE__ */ jsx(NumberStepperButton, {
429
- operation: "decrement",
430
- ...props
431
- });
360
+ return _jsx(NumberStepperButton, { operation: "decrement", ...props });
432
361
  }
362
+ /* -----------------------------------------------------------------------------
363
+ * Utility Functions
364
+ * -------------------------------------------------------------------------- */
433
365
  /**
434
- * Chains multiple callbacks into a single function
435
- *
436
- * @param callbacks - Array of callback functions that will be executed in order
437
- * @returns A single function that executes all callbacks
438
- */
366
+ * Chains multiple callbacks into a single function
367
+ *
368
+ * @param callbacks - Array of callback functions that will be executed in order
369
+ * @returns A single function that executes all callbacks
370
+ */
439
371
  function chain(...callbacks) {
440
- return (...args) => {
441
- for (const callback of callbacks) callback(...args);
442
- };
372
+ return (...args) => {
373
+ for (const callback of callbacks) {
374
+ callback(...args);
375
+ }
376
+ };
443
377
  }
444
378
  /**
445
- * Extracts decimal and a thousand separators from a given locale's number format
446
- *
447
- * @param locale - The locale string to use for number formatting (e.g., 'en-US', 'de-DE')
448
- * @returns Object containing decimal and a thousand separators
449
- */
379
+ * Extracts decimal and a thousand separators from a given locale's number format
380
+ *
381
+ * @param locale - The locale string to use for number formatting (e.g., 'en-US', 'de-DE')
382
+ * @returns Object containing decimal and a thousand separators
383
+ */
450
384
  function getNumberFormatSeparators(locale) {
451
- const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
452
- let thousandSeparator = "";
453
- let decimalSeparator = "";
454
- for (const part of parts) {
455
- if (part.type === "group") thousandSeparator = part.value;
456
- if (part.type === "decimal") decimalSeparator = part.value;
457
- if (thousandSeparator && decimalSeparator) break;
458
- }
459
- return {
460
- decimalSeparator,
461
- thousandSeparator
462
- };
385
+ const numberFormat = new Intl.NumberFormat(locale);
386
+ const parts = numberFormat.formatToParts(12_345.6);
387
+ let thousandSeparator = "";
388
+ let decimalSeparator = "";
389
+ for (const part of parts) {
390
+ if (part.type === "group") {
391
+ thousandSeparator = part.value;
392
+ }
393
+ if (part.type === "decimal") {
394
+ decimalSeparator = part.value;
395
+ }
396
+ // Stop early if you've found enough.
397
+ if (thousandSeparator && decimalSeparator) {
398
+ break;
399
+ }
400
+ }
401
+ return { decimalSeparator, thousandSeparator };
463
402
  }
464
403
  /**
465
- * Normalizes an input value by removing formatting characters
466
- *
467
- * @param value - The input string to normalize
468
- * @param thousandSeparator - The thousand-separator character to remove
469
- * @param decimalSeparator - The decimal separator to convert to standard dot notation
470
- * @returns Normalized string value ready for numeric conversion
471
- */
404
+ * Normalizes an input value by removing formatting characters
405
+ *
406
+ * @param value - The input string to normalize
407
+ * @param thousandSeparator - The thousand-separator character to remove
408
+ * @param decimalSeparator - The decimal separator to convert to standard dot notation
409
+ * @returns Normalized string value ready for numeric conversion
410
+ */
472
411
  function normalizeInputValue(value, thousandSeparator, decimalSeparator) {
473
- return value.replaceAll(new RegExp(`\\${thousandSeparator}`, "g"), "").replace(new RegExp(`\\${decimalSeparator}`), ".").replaceAll(/[()]/g, "-");
412
+ return value
413
+ .replaceAll(new RegExp(`\\${thousandSeparator}`, "g"), "")
414
+ .replace(new RegExp(`\\${decimalSeparator}`), ".")
415
+ .replaceAll(/[()]/g, "-");
474
416
  }
475
417
  /**
476
- * Checks if a keyboard event includes modifier keys (Ctrl, Alt, Meta, Shift)
477
- *
478
- * @param event - The keyboard event to check
479
- * @returns True if any modifier key is pressed
480
- */
418
+ * Checks if a keyboard event includes modifier keys (Ctrl, Alt, Meta, Shift)
419
+ *
420
+ * @param event - The keyboard event to check
421
+ * @returns True if any modifier key is pressed
422
+ */
481
423
  function isModifierKey(event) {
482
- return event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
424
+ return event.ctrlKey || event.altKey || event.metaKey || event.shiftKey;
483
425
  }
484
426
  /**
485
- * Determines if a key is a function key (F1-F12)
486
- *
487
- * @param key - The key name to check
488
- * @returns True if the key is a function key
489
- */
427
+ * Determines if a key is a function key (F1-F12)
428
+ *
429
+ * @param key - The key name to check
430
+ * @returns True if the key is a function key
431
+ */
490
432
  function isFunctionKey(key) {
491
- return key.startsWith("F") && key.length > 1;
433
+ return key.startsWith("F") && key.length > 1;
492
434
  }
493
435
  /**
494
- * Checks if a key represents a number (0-9)
495
- *
496
- * @param key - The key name to check
497
- * @returns True if the key represents a number
498
- */
436
+ * Checks if a key represents a number (0-9)
437
+ *
438
+ * @param key - The key name to check
439
+ * @returns True if the key represents a number
440
+ */
499
441
  function isNumberKey(key) {
500
- return !Number.isNaN(Number(key));
442
+ return !Number.isNaN(Number(key));
501
443
  }
502
444
  /**
503
- * Clamps a numeric value between a minimum and maximum
504
- *
505
- * @param value - The value to clamp
506
- * @param min - The minimum allowed value (defaults to \-Infinity)
507
- * @param max - The maximum allowed value (defaults to Infinity)
508
- * @returns The clamped value
509
- */
445
+ * Clamps a numeric value between a minimum and maximum
446
+ *
447
+ * @param value - The value to clamp
448
+ * @param min - The minimum allowed value (defaults to \-Infinity)
449
+ * @param max - The maximum allowed value (defaults to Infinity)
450
+ * @returns The clamped value
451
+ */
510
452
  function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
511
- return Math.min(Math.max(value, min), max);
453
+ return Math.min(Math.max(value, min), max);
512
454
  }
513
- //#endregion
514
- export { InputNumberDecrementButton as DecrementButton, InputNumberDecrementButton, InputNumberField as Field, InputNumberField, InputNumberIncrementButton as IncrementButton, InputNumberIncrementButton, InputNumber, InputNumber as Root, createInputNumberScope };
455
+ /* -----------------------------------------------------------------------------
456
+ * Exports
457
+ * -------------------------------------------------------------------------- */
458
+ export { createInputNumberScope, InputNumberDecrementButton as DecrementButton, InputNumberField as Field, InputNumberIncrementButton as IncrementButton, InputNumber, InputNumberDecrementButton, InputNumberField, InputNumberIncrementButton, InputNumber as Root, };