ixia-ui-react 1.8.0 → 2.0.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 (270) hide show
  1. package/README.md +24 -1
  2. package/dist/accordion/index.d.ts +41 -0
  3. package/dist/accordion/index.js +142 -0
  4. package/dist/accordion/index.js.map +1 -0
  5. package/dist/alert/index.d.ts +22 -0
  6. package/dist/alert/index.js +1 -0
  7. package/dist/alert-Dcu9R8CY.js +73 -0
  8. package/dist/alert-Dcu9R8CY.js.map +1 -0
  9. package/dist/alert-dialog/index.d.ts +39 -0
  10. package/dist/alert-dialog/index.js +134 -0
  11. package/dist/alert-dialog/index.js.map +1 -0
  12. package/dist/autocomplete/index.d.ts +2 -0
  13. package/dist/autocomplete/index.js +1 -0
  14. package/dist/autocomplete-BfpWVO1l.js +169 -0
  15. package/dist/autocomplete-BfpWVO1l.js.map +1 -0
  16. package/dist/avatar/index.d.ts +2 -0
  17. package/dist/avatar/index.js +1 -0
  18. package/dist/avatar-Bp4gZh21.js +93 -0
  19. package/dist/avatar-Bp4gZh21.js.map +1 -0
  20. package/dist/badge/index.d.ts +2 -0
  21. package/dist/badge/index.js +1 -0
  22. package/dist/badge-Cl-9WTW-.js +160 -0
  23. package/dist/badge-Cl-9WTW-.js.map +1 -0
  24. package/dist/bento-box/index.d.ts +30 -0
  25. package/dist/bento-box/index.js +103 -0
  26. package/dist/bento-box/index.js.map +1 -0
  27. package/dist/breadcrumb/index.d.ts +18 -0
  28. package/dist/breadcrumb/index.js +58 -0
  29. package/dist/breadcrumb/index.js.map +1 -0
  30. package/dist/button/index.d.ts +3 -0
  31. package/dist/button/index.js +1 -0
  32. package/dist/button-BpUC-R1J.js +307 -0
  33. package/dist/button-BpUC-R1J.js.map +1 -0
  34. package/dist/button-group/index.d.ts +2 -0
  35. package/dist/button-group/index.js +1 -0
  36. package/dist/button-group-7azbqlcO.js +269 -0
  37. package/dist/button-group-7azbqlcO.js.map +1 -0
  38. package/dist/button.types-BFKrBCGd.d.ts +10 -0
  39. package/dist/calendar/index.d.ts +63 -0
  40. package/dist/calendar/index.js +292 -0
  41. package/dist/calendar/index.js.map +1 -0
  42. package/dist/chart/index.d.ts +87 -0
  43. package/dist/chart/index.js +262 -0
  44. package/dist/chart/index.js.map +1 -0
  45. package/dist/checkbox/index.d.ts +2 -0
  46. package/dist/checkbox/index.js +1 -0
  47. package/dist/checkbox-BuUZ1Lly.js +54 -0
  48. package/dist/checkbox-BuUZ1Lly.js.map +1 -0
  49. package/dist/checkbox-group/index.d.ts +6 -0
  50. package/dist/checkbox-group/index.js +17 -0
  51. package/dist/checkbox-group/index.js.map +1 -0
  52. package/dist/cn-BDi0DfT5.js +29 -0
  53. package/dist/cn-BDi0DfT5.js.map +1 -0
  54. package/dist/code-block/index.d.ts +50 -0
  55. package/dist/code-block/index.js +208 -0
  56. package/dist/code-block/index.js.map +1 -0
  57. package/dist/collapsible/index.d.ts +2 -0
  58. package/dist/collapsible/index.js +1 -0
  59. package/dist/collapsible-BVqrh0Q0.js +44 -0
  60. package/dist/collapsible-BVqrh0Q0.js.map +1 -0
  61. package/dist/color-channel-slider/index.d.ts +2 -0
  62. package/dist/color-channel-slider/index.js +1 -0
  63. package/dist/color-channel-slider-h8mUPJ35.js +70 -0
  64. package/dist/color-channel-slider-h8mUPJ35.js.map +1 -0
  65. package/dist/color-picker/index.d.ts +137 -0
  66. package/dist/color-picker/index.js +621 -0
  67. package/dist/color-picker/index.js.map +1 -0
  68. package/dist/combobox/index.d.ts +64 -0
  69. package/dist/combobox/index.js +289 -0
  70. package/dist/combobox/index.js.map +1 -0
  71. package/dist/context-menu/index.d.ts +49 -0
  72. package/dist/context-menu/index.js +166 -0
  73. package/dist/context-menu/index.js.map +1 -0
  74. package/dist/dialog/index.d.ts +36 -0
  75. package/dist/dialog/index.js +119 -0
  76. package/dist/dialog/index.js.map +1 -0
  77. package/dist/drawer/index.d.ts +31 -0
  78. package/dist/drawer/index.js +95 -0
  79. package/dist/drawer/index.js.map +1 -0
  80. package/dist/dropzone/index.d.ts +70 -0
  81. package/dist/dropzone/index.js +479 -0
  82. package/dist/dropzone/index.js.map +1 -0
  83. package/dist/field/index.d.ts +2 -0
  84. package/dist/field/index.js +1 -0
  85. package/dist/field-DTL7eA5y.js +254 -0
  86. package/dist/field-DTL7eA5y.js.map +1 -0
  87. package/dist/form/index.d.ts +220 -0
  88. package/dist/form/index.js +3 -0
  89. package/dist/form-BxMg796f.js +192 -0
  90. package/dist/form-BxMg796f.js.map +1 -0
  91. package/dist/has-single-element-child-DLGI0Dh2.js +12 -0
  92. package/dist/has-single-element-child-DLGI0Dh2.js.map +1 -0
  93. package/dist/hooks/index.d.ts +26 -0
  94. package/dist/hooks/index.js +1 -0
  95. package/dist/hooks-DUm-q_ig.js +68 -0
  96. package/dist/hooks-DUm-q_ig.js.map +1 -0
  97. package/dist/icon/index.d.ts +2 -0
  98. package/dist/icon/index.js +1 -0
  99. package/dist/icon-D3JWfCa2.js +85 -0
  100. package/dist/icon-D3JWfCa2.js.map +1 -0
  101. package/dist/icon-container/index.d.ts +10 -0
  102. package/dist/icon-container/index.js +64 -0
  103. package/dist/icon-container/index.js.map +1 -0
  104. package/dist/index-0ZQzIKoE.d.ts +11 -0
  105. package/dist/index-B3MK1QYh.d.ts +11 -0
  106. package/dist/index-BJVMIPq4.d.ts +54 -0
  107. package/dist/index-BsV-u_jc.d.ts +4 -0
  108. package/dist/index-BygR7cUT.d.ts +22 -0
  109. package/dist/index-BzTOLSgZ.d.ts +9 -0
  110. package/dist/index-C15xiG9O.d.ts +14 -0
  111. package/dist/index-C2zco6-C.d.ts +15 -0
  112. package/dist/index-CIDOd4Z8.d.ts +56 -0
  113. package/dist/index-CQti9gFb.d.ts +49 -0
  114. package/dist/index-CiE-Rqit.d.ts +70 -0
  115. package/dist/index-D1kkOg9k.d.ts +14 -0
  116. package/dist/index-DLfdAked.d.ts +34 -0
  117. package/dist/index-DMaW_XF1.d.ts +24 -0
  118. package/dist/index-Db_QGr6S.d.ts +5 -0
  119. package/dist/index-DdFxZ3Xr.d.ts +22 -0
  120. package/dist/index-DfNHJF0t.d.ts +33 -0
  121. package/dist/index-DyQYoAUf.d.ts +29 -0
  122. package/dist/index-N2CBSUDu.d.ts +14 -0
  123. package/dist/index-PuhTRMce.d.ts +11 -0
  124. package/dist/index-Wb_tILYa.d.ts +24 -0
  125. package/dist/index-bVyqfhJS.d.ts +4 -0
  126. package/dist/index-x4f8gnaI.d.ts +15 -0
  127. package/dist/input/index.d.ts +3 -0
  128. package/dist/input/index.js +1 -0
  129. package/dist/input-Laj6dwtK.js +179 -0
  130. package/dist/input-Laj6dwtK.js.map +1 -0
  131. package/dist/input-group/index.d.ts +2 -0
  132. package/dist/input-group/index.js +1 -0
  133. package/dist/input-group-CgdazGrY.js +111 -0
  134. package/dist/input-group-CgdazGrY.js.map +1 -0
  135. package/dist/input-otp/index.d.ts +13 -0
  136. package/dist/input-otp/index.js +44 -0
  137. package/dist/input-otp/index.js.map +1 -0
  138. package/dist/input.types-816rEVWU.d.ts +20 -0
  139. package/dist/input.types-D0gyoaQv.js +48 -0
  140. package/dist/input.types-D0gyoaQv.js.map +1 -0
  141. package/dist/kbd/index.d.ts +9 -0
  142. package/dist/kbd/index.js +25 -0
  143. package/dist/kbd/index.js.map +1 -0
  144. package/dist/label/index.d.ts +8 -0
  145. package/dist/label/index.js +1 -0
  146. package/dist/label-BgpayDvN.js +27 -0
  147. package/dist/label-BgpayDvN.js.map +1 -0
  148. package/dist/layer-tree/index.d.ts +728 -0
  149. package/dist/layer-tree/index.js +685 -0
  150. package/dist/layer-tree/index.js.map +1 -0
  151. package/dist/map/google/index.d.ts +143 -0
  152. package/dist/map/google/index.js +445 -0
  153. package/dist/map/google/index.js.map +1 -0
  154. package/dist/map/index.d.ts +94 -0
  155. package/dist/map/index.js +208 -0
  156. package/dist/map/index.js.map +1 -0
  157. package/dist/map.context-Dw1D7E8m.js +11 -0
  158. package/dist/map.context-Dw1D7E8m.js.map +1 -0
  159. package/dist/menu/index.d.ts +2 -0
  160. package/dist/menu/index.js +1 -0
  161. package/dist/menu-sf13cnGp.js +173 -0
  162. package/dist/menu-sf13cnGp.js.map +1 -0
  163. package/dist/menu-tone-DWBEHoX2.js +22 -0
  164. package/dist/menu-tone-DWBEHoX2.js.map +1 -0
  165. package/dist/meter/index.d.ts +2 -0
  166. package/dist/meter/index.js +1 -0
  167. package/dist/meter-HD5taq57.js +116 -0
  168. package/dist/meter-HD5taq57.js.map +1 -0
  169. package/dist/nav-bar/index.d.ts +25 -0
  170. package/dist/nav-bar/index.js +133 -0
  171. package/dist/nav-bar/index.js.map +1 -0
  172. package/dist/navigation-menu/index.d.ts +43 -0
  173. package/dist/navigation-menu/index.js +176 -0
  174. package/dist/navigation-menu/index.js.map +1 -0
  175. package/dist/number-field/index.d.ts +14 -0
  176. package/dist/number-field/index.js +116 -0
  177. package/dist/number-field/index.js.map +1 -0
  178. package/dist/popover/index.d.ts +2 -0
  179. package/dist/popover/index.js +1 -0
  180. package/dist/popover-B1s4xXrX.js +114 -0
  181. package/dist/popover-B1s4xXrX.js.map +1 -0
  182. package/dist/preview-card/index.d.ts +13 -0
  183. package/dist/preview-card/index.js +35 -0
  184. package/dist/preview-card/index.js.map +1 -0
  185. package/dist/profile/index.d.ts +21 -0
  186. package/dist/profile/index.js +52 -0
  187. package/dist/profile/index.js.map +1 -0
  188. package/dist/progress/index.d.ts +23 -0
  189. package/dist/progress/index.js +97 -0
  190. package/dist/progress/index.js.map +1 -0
  191. package/dist/radar-ping/index.d.ts +11 -0
  192. package/dist/radar-ping/index.js +49 -0
  193. package/dist/radar-ping/index.js.map +1 -0
  194. package/dist/radio-group/index.d.ts +2 -0
  195. package/dist/radio-group/index.js +1 -0
  196. package/dist/radio-group-Dj43u35Z.js +47 -0
  197. package/dist/radio-group-Dj43u35Z.js.map +1 -0
  198. package/dist/resizeable/index.d.ts +11 -0
  199. package/dist/resizeable/index.js +31 -0
  200. package/dist/resizeable/index.js.map +1 -0
  201. package/dist/scroll-area/index.d.ts +11 -0
  202. package/dist/scroll-area/index.js +51 -0
  203. package/dist/scroll-area/index.js.map +1 -0
  204. package/dist/select/index.d.ts +2 -0
  205. package/dist/select/index.js +1 -0
  206. package/dist/select-DncJXYim.js +159 -0
  207. package/dist/select-DncJXYim.js.map +1 -0
  208. package/dist/separator/index.d.ts +2 -0
  209. package/dist/separator/index.js +1 -0
  210. package/dist/separator-DgIQp1cB.js +97 -0
  211. package/dist/separator-DgIQp1cB.js.map +1 -0
  212. package/dist/sidebar/index.d.ts +80 -0
  213. package/dist/sidebar/index.js +334 -0
  214. package/dist/sidebar/index.js.map +1 -0
  215. package/dist/site-header/index.d.ts +22 -0
  216. package/dist/site-header/index.js +55 -0
  217. package/dist/site-header/index.js.map +1 -0
  218. package/dist/skeleton/index.d.ts +4 -0
  219. package/dist/skeleton/index.js +1 -0
  220. package/dist/skeleton-DSG3FWby.js +13 -0
  221. package/dist/skeleton-DSG3FWby.js.map +1 -0
  222. package/dist/slider/index.d.ts +2 -0
  223. package/dist/slider/index.js +1 -0
  224. package/dist/slider-D_XlV4OW.js +114 -0
  225. package/dist/slider-D_XlV4OW.js.map +1 -0
  226. package/dist/slider-group/index.d.ts +46 -0
  227. package/dist/slider-group/index.js +198 -0
  228. package/dist/slider-group/index.js.map +1 -0
  229. package/dist/styles.css +4 -1
  230. package/dist/switch/index.d.ts +2 -0
  231. package/dist/switch/index.js +1 -0
  232. package/dist/switch-DXHixGHe.js +23 -0
  233. package/dist/switch-DXHixGHe.js.map +1 -0
  234. package/dist/table/index.d.ts +920 -0
  235. package/dist/table/index.js +1544 -0
  236. package/dist/table/index.js.map +1 -0
  237. package/dist/tabs/index.d.ts +2 -0
  238. package/dist/tabs/index.js +1 -0
  239. package/dist/tabs-DTC7coap.js +270 -0
  240. package/dist/tabs-DTC7coap.js.map +1 -0
  241. package/dist/text-area/index.d.ts +2 -0
  242. package/dist/text-area/index.js +1 -0
  243. package/dist/text-area-H6HjKnv_.js +50 -0
  244. package/dist/text-area-H6HjKnv_.js.map +1 -0
  245. package/dist/toast/index.d.ts +65 -0
  246. package/dist/toast/index.js +216 -0
  247. package/dist/toast/index.js.map +1 -0
  248. package/dist/toggle/index.d.ts +2 -0
  249. package/dist/toggle/index.js +1 -0
  250. package/dist/toggle-ZT9thVmz.js +73 -0
  251. package/dist/toggle-ZT9thVmz.js.map +1 -0
  252. package/dist/toggle-group/index.d.ts +10 -0
  253. package/dist/toggle-group/index.js +63 -0
  254. package/dist/toggle-group/index.js.map +1 -0
  255. package/dist/toggle-group-context-CBNZEf1I.js +6 -0
  256. package/dist/toggle-group-context-CBNZEf1I.js.map +1 -0
  257. package/dist/tooltip/index.d.ts +18 -0
  258. package/dist/tooltip/index.js +1 -0
  259. package/dist/tooltip-B6z3tDbW.js +41 -0
  260. package/dist/tooltip-B6z3tDbW.js.map +1 -0
  261. package/dist/trim-text-children-CQRFg2fL.js +33 -0
  262. package/dist/trim-text-children-CQRFg2fL.js.map +1 -0
  263. package/dist/utils/index.d.ts +4 -0
  264. package/dist/utils/index.js +3 -0
  265. package/dist/utils-BI2x7nW5.js +5 -0
  266. package/dist/utils-BI2x7nW5.js.map +1 -0
  267. package/package.json +100 -31
  268. package/dist/index.d.ts +0 -8000
  269. package/dist/index.js +0 -17274
  270. package/dist/index.js.map +0 -1
@@ -0,0 +1,621 @@
1
+ import { t as cn } from "../cn-BDi0DfT5.js";
2
+ import { n as Icon } from "../icon-D3JWfCa2.js";
3
+ import { a as SelectPopup, c as SelectIcon, n as SelectValue, o as SelectList, r as SelectTrigger, s as SelectItem, t as Select } from "../select-DncJXYim.js";
4
+ import { t as ColorChannelSlider } from "../color-channel-slider-h8mUPJ35.js";
5
+ import { i as InputGroupAddon, r as InputGroupInput, t as InputGroup } from "../input-group-CgdazGrY.js";
6
+ import { t as Separator } from "../separator-DgIQp1cB.js";
7
+ import { c as PopoverContent, i as PopoverPanel, n as PopoverTrigger, t as Popover } from "../popover-B1s4xXrX.js";
8
+ import { cva } from "class-variance-authority";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ import React from "react";
11
+ import chroma from "chroma-js";
12
+ // src/components/color-picker/color-picker.types.ts
13
+ const colorPickerVariants = cva("flex flex-col space-y-sm", {
14
+ defaultVariants: { variant: "elevated" },
15
+ variants: { variant: {
16
+ elevated: "rounded-xl bg-surface p-md shadow-2xs",
17
+ ghost: "",
18
+ outline: "rounded-xl border border-border p-md"
19
+ } }
20
+ });
21
+ const colorPickerSwatchVariants = cva("overflow-hidden border border-border hover:cursor-pointer focus:outline-2 focus:outline-offset-2", {
22
+ defaultVariants: { size: "medium" },
23
+ variants: { size: {
24
+ large: "size-lg rounded-lg",
25
+ medium: "size-md rounded-md",
26
+ small: "size-sm rounded-sm"
27
+ } }
28
+ });
29
+ const RGB_CHANNEL_COUNT = 3;
30
+ const DECIMAL_RADIX = 10;
31
+ const VALUE_TYPES = [
32
+ {
33
+ getValue: (color) => color.rgb(),
34
+ label: "RGB",
35
+ parseValue: (value) => {
36
+ const rgbChannels = value.split(",").map((channelText) => parseInt(channelText.trim(), DECIMAL_RADIX));
37
+ if (rgbChannels.length === RGB_CHANNEL_COUNT && rgbChannels.every((channel) => !Number.isNaN(channel))) {
38
+ const [red, green, blue] = rgbChannels;
39
+ return chroma.rgb(red, green, blue);
40
+ }
41
+ },
42
+ value: "rgb"
43
+ },
44
+ {
45
+ getValue: (color) => color.css(),
46
+ label: "CSS",
47
+ parseValue: (value) => {
48
+ try {
49
+ return chroma(value);
50
+ } catch {
51
+ return;
52
+ }
53
+ },
54
+ value: "css"
55
+ },
56
+ {
57
+ getValue: (color) => color.hex("rgb"),
58
+ label: "HEX",
59
+ parseValue: (value) => {
60
+ try {
61
+ return chroma(value);
62
+ } catch {
63
+ return;
64
+ }
65
+ },
66
+ value: "hex"
67
+ },
68
+ {
69
+ getValue: (color) => color.hsl(),
70
+ label: "HSL",
71
+ parseValue: (value) => {
72
+ try {
73
+ return chroma(value);
74
+ } catch {
75
+ return;
76
+ }
77
+ },
78
+ value: "hsl"
79
+ },
80
+ {
81
+ getValue: (color) => color.hsv(),
82
+ label: "HSV",
83
+ parseValue: (value) => {
84
+ try {
85
+ return chroma(value);
86
+ } catch {
87
+ return;
88
+ }
89
+ },
90
+ value: "hsv"
91
+ }
92
+ ];
93
+ // src/components/color-picker/color-picker.tsx
94
+ const MIN_COLOR_CHANNEL = 0;
95
+ const FIRST_VALUE_TYPE_INDEX = 0;
96
+ const ColorPickerContext = React.createContext(void 0);
97
+ const normalizeToColor = (value, fallback) => {
98
+ try {
99
+ if (typeof value === "string") return chroma(value.trim());
100
+ return chroma(value);
101
+ } catch {
102
+ return fallback;
103
+ }
104
+ };
105
+ const getValidChannel = (channel, fallback) => {
106
+ if (channel === void 0 || Number.isNaN(channel)) return fallback;
107
+ return channel;
108
+ };
109
+ const updateColorState = ({ saturation: previousSaturation, ...state }, color) => {
110
+ const [nextHue, nextSaturation, nextValue] = color.hsv();
111
+ let saturation = previousSaturation;
112
+ if (nextValue !== MIN_COLOR_CHANNEL) saturation = getValidChannel(nextSaturation, previousSaturation);
113
+ return {
114
+ ...state,
115
+ alpha: color.alpha(),
116
+ hue: getValidChannel(nextHue, state.hue),
117
+ saturation,
118
+ value: nextValue
119
+ };
120
+ };
121
+ const updateSimpleState = (state, action) => {
122
+ switch (action.type) {
123
+ case "set_hue": return {
124
+ ...state,
125
+ hue: action.hue
126
+ };
127
+ case "set_saturation": return {
128
+ ...state,
129
+ saturation: action.saturation
130
+ };
131
+ case "set_value": return {
132
+ ...state,
133
+ value: action.value
134
+ };
135
+ case "set_saturation_value": return {
136
+ ...state,
137
+ saturation: action.saturation,
138
+ value: action.value
139
+ };
140
+ case "set_alpha": return {
141
+ ...state,
142
+ alpha: action.alpha
143
+ };
144
+ case "set_lightness": return {
145
+ ...state,
146
+ value: action.lightness
147
+ };
148
+ case "set_value_type": return {
149
+ ...state,
150
+ valueType: action.valueType
151
+ };
152
+ default: return state;
153
+ }
154
+ };
155
+ const colorPickerReducer = (state, action) => {
156
+ switch (action.type) {
157
+ case "set_color": return updateColorState(state, action.color);
158
+ case "set_palette": return {
159
+ ...state,
160
+ palette: action.palette
161
+ };
162
+ case "add_palette_color": return {
163
+ ...state,
164
+ palette: [...state.palette, action.color]
165
+ };
166
+ default: return updateSimpleState(state, action);
167
+ }
168
+ };
169
+ function ColorPicker$1({ variant, value: controlledValue, defaultColor, palette: controlledPalette, defaultPalette, onPaletteChange, paletteLimit, defaultValueType, onValueChange, className, ref, ...props }) {
170
+ const [state, dispatch] = React.useReducer(colorPickerReducer, {
171
+ controlledPalette,
172
+ controlledValue,
173
+ defaultColor,
174
+ defaultPalette,
175
+ defaultValueType
176
+ }, ({ controlledValue: initialControlledValue, controlledPalette: initialControlledPalette, defaultColor: initialDefaultColor, defaultPalette: initialDefaultPalette, defaultValueType: initialDefaultValueType }) => {
177
+ const initialColor = normalizeToColor(initialControlledValue ?? initialDefaultColor ?? "#ffffff", chroma("#ffffff")), [initialHue, initialSaturation, initialValue] = initialColor.hsv();
178
+ return {
179
+ alpha: initialColor.alpha(),
180
+ hue: getValidChannel(initialHue, MIN_COLOR_CHANNEL),
181
+ palette: (initialControlledPalette ?? initialDefaultPalette ?? []).map((colorOption) => chroma(colorOption)),
182
+ saturation: getValidChannel(initialSaturation, MIN_COLOR_CHANNEL),
183
+ value: initialValue,
184
+ valueType: VALUE_TYPES.find((typeOption) => typeOption.value === initialDefaultValueType) ?? VALUE_TYPES[FIRST_VALUE_TYPE_INDEX]
185
+ };
186
+ }), { hue: internalHue, saturation: internalSaturation, value: internalValue, alpha: internalAlpha, valueType, palette } = state, color = chroma.hsv(internalHue, internalSaturation, internalValue).alpha(internalAlpha), hue = internalHue, saturation = internalSaturation, value = internalValue, alpha = internalAlpha, lastSyncedColorRef = React.useRef(void 0), lastSyncedPaletteRef = React.useRef(void 0), setColor = (nextColor) => {
187
+ dispatch({
188
+ color: nextColor,
189
+ type: "set_color"
190
+ });
191
+ onValueChange?.(nextColor.hex());
192
+ }, setHue = (nextHue) => {
193
+ dispatch({
194
+ hue: nextHue,
195
+ type: "set_hue"
196
+ });
197
+ onValueChange?.(chroma.hsv(nextHue, saturation, value).alpha(alpha).hex());
198
+ }, setSaturation = (nextSaturation) => {
199
+ dispatch({
200
+ saturation: nextSaturation,
201
+ type: "set_saturation"
202
+ });
203
+ onValueChange?.(chroma.hsv(hue, nextSaturation, value).alpha(alpha).hex());
204
+ }, setValue = (nextValue) => {
205
+ dispatch({
206
+ type: "set_value",
207
+ value: nextValue
208
+ });
209
+ onValueChange?.(chroma.hsv(hue, saturation, nextValue).alpha(alpha).hex());
210
+ }, setSaturationValue = (nextSaturation, nextValue) => {
211
+ dispatch({
212
+ saturation: nextSaturation,
213
+ type: "set_saturation_value",
214
+ value: nextValue
215
+ });
216
+ onValueChange?.(chroma.hsv(hue, nextSaturation, nextValue).alpha(alpha).hex());
217
+ }, setAlpha = (nextAlpha) => setColor(color.alpha(nextAlpha)), setLightness = (nextLightness) => setColor(color.set("hsl.l", nextLightness)), setValueType = (nextValueType) => dispatch({
218
+ type: "set_value_type",
219
+ valueType: nextValueType
220
+ }), setPalette = (nextPalette) => {
221
+ lastSyncedPaletteRef.current = nextPalette.map((paletteColor) => paletteColor.hex("rgba")).join("|");
222
+ dispatch({
223
+ palette: nextPalette,
224
+ type: "set_palette"
225
+ });
226
+ onPaletteChange?.(nextPalette.map((paletteColor) => paletteColor.hex()));
227
+ }, addPaletteColor = (nextColor) => {
228
+ if (paletteLimit && palette.length >= paletteLimit) return;
229
+ const nextPalette = [...palette, nextColor];
230
+ lastSyncedPaletteRef.current = nextPalette.map((paletteColor) => paletteColor.hex("rgba")).join("|");
231
+ dispatch({
232
+ color: nextColor,
233
+ type: "add_palette_color"
234
+ });
235
+ onPaletteChange?.(nextPalette.map((paletteColor) => paletteColor.hex()));
236
+ };
237
+ React.useEffect(() => {
238
+ if (controlledValue === void 0) return;
239
+ const nextColor = normalizeToColor(controlledValue, color), nextKey = nextColor.hex("rgba");
240
+ if (nextKey === lastSyncedColorRef.current) return;
241
+ lastSyncedColorRef.current = nextKey;
242
+ if (nextKey !== color.hex("rgba")) dispatch({
243
+ color: nextColor,
244
+ type: "set_color"
245
+ });
246
+ }, [controlledValue, color]);
247
+ React.useEffect(() => {
248
+ if (controlledPalette === void 0) return;
249
+ const parsedPalette = controlledPalette.map((colorOption) => chroma(colorOption)), nextKey = parsedPalette.map((paletteColor) => paletteColor.hex("rgba")).join("|");
250
+ if (nextKey === lastSyncedPaletteRef.current) return;
251
+ lastSyncedPaletteRef.current = nextKey;
252
+ dispatch({
253
+ palette: parsedPalette,
254
+ type: "set_palette"
255
+ });
256
+ }, [controlledPalette]);
257
+ return /* @__PURE__ */ jsx(ColorPickerContext.Provider, {
258
+ value: {
259
+ addPaletteColor,
260
+ alpha,
261
+ color,
262
+ hue,
263
+ palette,
264
+ paletteLimit,
265
+ saturation,
266
+ setAlpha,
267
+ setColor,
268
+ setHue,
269
+ setLightness,
270
+ setPalette,
271
+ setSaturation,
272
+ setSaturationValue,
273
+ setValue,
274
+ setValueType,
275
+ value,
276
+ valueType
277
+ },
278
+ children: /* @__PURE__ */ jsx("div", {
279
+ className: cn(colorPickerVariants({ variant }), className),
280
+ ref,
281
+ ...props
282
+ })
283
+ });
284
+ }
285
+ function useColorPicker() {
286
+ const context = React.useContext(ColorPickerContext);
287
+ if (!context) throw new Error("useColorPicker must be used within a ColorPicker");
288
+ return context;
289
+ }
290
+ // src/components/color-picker/color-picker-area.tsx
291
+ const PERCENTAGE_SCALE = 100;
292
+ const MIN_NORMALIZED_VALUE = 0;
293
+ const MAX_NORMALIZED_VALUE = 1;
294
+ function ColorPickerArea({ className, ref, ...props }) {
295
+ const { color, hue, saturation, value, setSaturationValue } = useColorPicker(), hueColor = chroma.hsv(hue, MAX_NORMALIZED_VALUE, MAX_NORMALIZED_VALUE).hex(), updateColor = (event) => {
296
+ const bounds = event.currentTarget.getBoundingClientRect(), nextSaturation = Math.min(Math.max((event.clientX - bounds.left) / bounds.width, MIN_NORMALIZED_VALUE), MAX_NORMALIZED_VALUE), nextValue = Math.min(Math.max(MAX_NORMALIZED_VALUE - (event.clientY - bounds.top) / bounds.height, MIN_NORMALIZED_VALUE), MAX_NORMALIZED_VALUE);
297
+ setSaturationValue(nextSaturation, nextValue);
298
+ }, handlePointerDown = (event) => {
299
+ event.currentTarget.setPointerCapture(event.pointerId);
300
+ updateColor(event);
301
+ };
302
+ return /* @__PURE__ */ jsx("div", {
303
+ ...props,
304
+ ref,
305
+ className: cn("relative aspect-square grow touch-none rounded-lg active:cursor-grabbing", className),
306
+ style: {
307
+ background: `
308
+ linear-gradient(to top, black, transparent),
309
+ linear-gradient(to right, white, ${hueColor})
310
+ `,
311
+ ...props.style
312
+ },
313
+ onPointerDown: handlePointerDown,
314
+ onPointerMove: (event) => {
315
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) updateColor(event);
316
+ },
317
+ children: /* @__PURE__ */ jsx("div", {
318
+ className: "pointer-events-none absolute size-md -translate-x-1/2 -translate-y-1/2 rounded-full border-3 border-white",
319
+ style: {
320
+ backgroundColor: color.hex(),
321
+ left: `${saturation * PERCENTAGE_SCALE}%`,
322
+ top: `${(MAX_NORMALIZED_VALUE - value) * PERCENTAGE_SCALE}%`
323
+ }
324
+ })
325
+ });
326
+ }
327
+ // src/components/color-picker/color-picker-group.tsx
328
+ function ColorPickerGroup({ className, ref, ...props }) {
329
+ return /* @__PURE__ */ jsx("div", {
330
+ className: cn("flex flex-col gap-sm", className),
331
+ ref,
332
+ ...props
333
+ });
334
+ }
335
+ // src/components/color-channel-slider/color-channel-slider.utils.ts
336
+ const HSL_SATURATION = 1;
337
+ const HSL_LIGHTNESS = .5;
338
+ const HUE_TRACK_LENGTH = 361;
339
+ const LIGHTNESS_TRACK_LENGTH = 101;
340
+ const TRANSPARENCY_TRACK_LENGTH = 101;
341
+ const TRACK_DIVISIONS = 100;
342
+ const getHueTrack = () => Array.from({ length: HUE_TRACK_LENGTH }, (_value, hue) => chroma.hsl(hue, HSL_SATURATION, HSL_LIGHTNESS).hex());
343
+ const getTransparencyTrack = (baseColor) => Array.from({ length: TRANSPARENCY_TRACK_LENGTH }, (_value, index) => chroma(baseColor).alpha(index / TRACK_DIVISIONS).css());
344
+ const getLightnessTrack = (baseColor) => Array.from({ length: LIGHTNESS_TRACK_LENGTH }, (_value, index) => chroma(baseColor).set("hsl.l", index / TRACK_DIVISIONS).css());
345
+ // src/components/color-picker/color-picker-hue-slider.tsx
346
+ const HUE_VALUE_INDEX = 0;
347
+ function ColorPickerHueSlider({ className, ref, ...props }) {
348
+ const { hue, setHue } = useColorPicker(), handleChange = (value) => {
349
+ if (typeof value === "number") {
350
+ setHue(value);
351
+ return;
352
+ }
353
+ setHue(value[HUE_VALUE_INDEX]);
354
+ };
355
+ return /* @__PURE__ */ jsx(ColorChannelSlider, {
356
+ "aria-label": "Hue",
357
+ ...props,
358
+ min: 0,
359
+ max: 360,
360
+ value: hue,
361
+ onValueChange: handleChange,
362
+ trackStyle: getHueTrack(),
363
+ className: cn("", className),
364
+ ref
365
+ });
366
+ }
367
+ // src/components/color-picker/color-picker-input.tsx
368
+ const TRANSPARENCY_MULTIPLIER = 100;
369
+ function ColorPickerInput({ showPopover = false, showTransparencyField = true, className, children, ref, ...props }) {
370
+ const { color, setColor, valueType } = useColorPicker(), [inputValue, setInputValue] = React.useState(String(valueType.getValue(color))), [transparency, setTransparency] = React.useState(Math.round(color.alpha() * TRANSPARENCY_MULTIPLIER).toString()), [prevColor, setPrevColor] = React.useState(color), [prevValueType, setPrevValueType] = React.useState(valueType), handleValueChange = (value) => {
371
+ setInputValue(value);
372
+ }, handleTransparencyChange = (value) => {
373
+ setTransparency(value);
374
+ }, handleValueBlur = () => {
375
+ const newColor = valueType.parseValue(inputValue);
376
+ if (newColor) setColor(newColor);
377
+ }, handleTransparencyBlur = () => {
378
+ const alpha = parseFloat(transparency);
379
+ if (!Number.isNaN(alpha)) setColor(color.alpha(alpha / TRANSPARENCY_MULTIPLIER));
380
+ }, handleValueKeyDown = (event) => {
381
+ if (event.key === "Enter") handleValueBlur();
382
+ }, handleTransparencyKeyDown = (event) => {
383
+ if (event.key === "Enter") handleTransparencyBlur();
384
+ };
385
+ if (color !== prevColor || valueType !== prevValueType) {
386
+ setPrevColor(color);
387
+ setPrevValueType(valueType);
388
+ setInputValue(String(valueType.getValue(color)));
389
+ setTransparency(Math.round(color.alpha() * TRANSPARENCY_MULTIPLIER).toString());
390
+ }
391
+ return /* @__PURE__ */ jsxs(InputGroup, {
392
+ variant: "secondary",
393
+ className: cn("", className),
394
+ ref,
395
+ ...props,
396
+ children: [
397
+ showPopover && /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(PopoverTrigger, {
398
+ "aria-label": "Open color picker",
399
+ nativeButton: false,
400
+ children: /* @__PURE__ */ jsx(InputGroupAddon, {
401
+ style: { backgroundColor: color.hex() },
402
+ className: "aspect-square h-1/2 rounded-lg hover:cursor-pointer"
403
+ })
404
+ }), /* @__PURE__ */ jsx(PopoverPanel, { children: /* @__PURE__ */ jsx(PopoverContent, {
405
+ className: "flex w-[300px] flex-col gap-sm",
406
+ children
407
+ }) })] }),
408
+ !showPopover && /* @__PURE__ */ jsx(InputGroupAddon, {
409
+ style: { backgroundColor: color.hex() },
410
+ className: "aspect-square size-md rounded-md"
411
+ }),
412
+ /* @__PURE__ */ jsx(InputGroupInput, {
413
+ "aria-label": "Color value",
414
+ onBlur: handleValueBlur,
415
+ onKeyDown: handleValueKeyDown,
416
+ onValueChange: handleValueChange,
417
+ value: inputValue,
418
+ className: "uppercase"
419
+ }),
420
+ showTransparencyField && /* @__PURE__ */ jsxs(Fragment, { children: [
421
+ /* @__PURE__ */ jsx(Separator, {
422
+ orientation: "vertical",
423
+ className: "h-md"
424
+ }),
425
+ /* @__PURE__ */ jsx(InputGroupAddon, { children: /* @__PURE__ */ jsx(Icon, { name: "percent" }) }),
426
+ /* @__PURE__ */ jsx(InputGroupInput, {
427
+ "aria-label": "Transparency percentage",
428
+ type: "number",
429
+ min: 0,
430
+ max: 100,
431
+ value: transparency,
432
+ onValueChange: handleTransparencyChange,
433
+ onBlur: handleTransparencyBlur,
434
+ onKeyDown: handleTransparencyKeyDown,
435
+ className: "w-xl"
436
+ })
437
+ ] })
438
+ ]
439
+ });
440
+ }
441
+ // src/components/color-picker/color-picker-label.tsx
442
+ function ColorPickerLabel({ className, ref, ...props }) {
443
+ return /* @__PURE__ */ jsx("span", {
444
+ className: cn("style-text-default-0", className),
445
+ ref,
446
+ ...props
447
+ });
448
+ }
449
+ // src/components/color-picker/color-picker-lightness-slider.tsx
450
+ const MIN_LIGHTNESS = 0;
451
+ const MAX_LIGHTNESS = 100;
452
+ const LIGHTNESS_SCALE = 100;
453
+ const FIRST_VALUE_INDEX$1 = 0;
454
+ function getSliderValue$1(value) {
455
+ if (typeof value === "number") return value;
456
+ return value[FIRST_VALUE_INDEX$1];
457
+ }
458
+ function ColorPickerLightnessSlider({ className, ref, ...props }) {
459
+ const { color, setColor } = useColorPicker(), lightness = color.get("hsl.l") || MIN_LIGHTNESS, handleChange = (value) => {
460
+ setColor(color.set("hsl.l", getSliderValue$1(value) / LIGHTNESS_SCALE));
461
+ };
462
+ return /* @__PURE__ */ jsx(ColorChannelSlider, {
463
+ "aria-label": "Lightness",
464
+ ...props,
465
+ min: MIN_LIGHTNESS,
466
+ max: MAX_LIGHTNESS,
467
+ value: lightness * LIGHTNESS_SCALE,
468
+ onValueChange: handleChange,
469
+ trackStyle: getLightnessTrack(color.hex()),
470
+ className: cn("", className),
471
+ ref
472
+ });
473
+ }
474
+ // src/components/color-picker/color-picker-palette-add.tsx
475
+ function ColorPickerPaletteAdd({ className, children, ref, ...props }) {
476
+ const { color, addPaletteColor } = useColorPicker(), handleClick = () => {
477
+ addPaletteColor(color);
478
+ };
479
+ return /* @__PURE__ */ jsx("button", {
480
+ type: "button",
481
+ "aria-label": "Add current color to palette",
482
+ onClick: handleClick,
483
+ className: cn("flex size-md items-center justify-center rounded-lg border border-border-strong text-border-strong hover:cursor-pointer [&>svg]:size-xs", className),
484
+ ref,
485
+ ...props,
486
+ children: children ?? /* @__PURE__ */ jsx(Icon, { name: "add" })
487
+ });
488
+ }
489
+ // src/components/color-picker/color-picker-palette-limit.tsx
490
+ function ColorPickerPaletteLimit({ className, children, ref, ...props }) {
491
+ const { palette, paletteLimit } = useColorPicker(), isAtLimit = paletteLimit && palette.length >= paletteLimit;
492
+ return Boolean(paletteLimit) && /* @__PURE__ */ jsxs("span", {
493
+ className: cn("style-text-prose--2 text-on-surface-variant", isAtLimit && "text-error-default", className),
494
+ ref,
495
+ ...props,
496
+ children: [
497
+ children,
498
+ palette.length,
499
+ " / ",
500
+ paletteLimit
501
+ ]
502
+ });
503
+ }
504
+ // src/components/color-picker/color-picker-palette-swatch.tsx
505
+ function ColorPickerPaletteSwatch({ size, color, className, children, ref, ...props }) {
506
+ const { setColor } = useColorPicker(), handleClick = () => {
507
+ setColor(chroma(color));
508
+ };
509
+ return /* @__PURE__ */ jsxs("button", {
510
+ type: "button",
511
+ "aria-label": `Select color ${color}`,
512
+ onClick: handleClick,
513
+ className: cn(colorPickerSwatchVariants({ size }), className),
514
+ ref,
515
+ style: { color },
516
+ ...props,
517
+ children: [children, /* @__PURE__ */ jsx("div", {
518
+ className: "size-full",
519
+ style: { backgroundColor: color }
520
+ })]
521
+ });
522
+ }
523
+ // src/components/color-picker/color-picker-palette-list.tsx
524
+ const DEFAULT_OCCURRENCE = 0;
525
+ const OCCURRENCE_INCREMENT = 1;
526
+ function ColorPickerPaletteList({ className, children, ref, ...props }) {
527
+ const { palette } = useColorPicker(), occurrences = /* @__PURE__ */ new Map();
528
+ return /* @__PURE__ */ jsxs("div", {
529
+ className: cn("flex flex-wrap items-center justify-start gap-2xs", className),
530
+ ref,
531
+ ...props,
532
+ children: [palette.map((color) => {
533
+ const value = color.hex("rgba"), occurrence = occurrences.get(value) ?? DEFAULT_OCCURRENCE;
534
+ occurrences.set(value, occurrence + OCCURRENCE_INCREMENT);
535
+ return /* @__PURE__ */ jsx(ColorPickerPaletteSwatch, {
536
+ color: color.css(),
537
+ size: "medium"
538
+ }, `${value}-${occurrence}`);
539
+ }), children]
540
+ });
541
+ }
542
+ // src/components/color-picker/color-picker-row.tsx
543
+ function ColorPickerRow({ className, ref, ...props }) {
544
+ return /* @__PURE__ */ jsx("div", {
545
+ className: cn("flex items-center justify-between gap-xs", className),
546
+ ref,
547
+ ...props
548
+ });
549
+ }
550
+ // src/components/color-picker/color-picker-transparency-slider.tsx
551
+ const FIRST_VALUE_INDEX = 0;
552
+ const ALPHA_PERCENTAGE_SCALE = 100;
553
+ function getSliderValue(value) {
554
+ if (typeof value === "number") return value;
555
+ return value[FIRST_VALUE_INDEX];
556
+ }
557
+ function ColorPickerTransparencySlider({ className, ref, ...props }) {
558
+ const { color, setColor } = useColorPicker(), alpha = color.alpha(), handleChange = (value) => {
559
+ const nextAlpha = getSliderValue(value);
560
+ setColor(color.alpha(nextAlpha / ALPHA_PERCENTAGE_SCALE));
561
+ };
562
+ return /* @__PURE__ */ jsx(ColorChannelSlider, {
563
+ "aria-label": "Transparency",
564
+ ...props,
565
+ min: 0,
566
+ max: ALPHA_PERCENTAGE_SCALE,
567
+ value: alpha * ALPHA_PERCENTAGE_SCALE,
568
+ onValueChange: handleChange,
569
+ trackStyle: getTransparencyTrack(color.hex()),
570
+ className: cn("", className),
571
+ ref
572
+ });
573
+ }
574
+ // src/components/color-picker/color-picker-value-type.tsx
575
+ const [defaultValueType] = VALUE_TYPES;
576
+ function ColorPickerValueType({ className, children, ref, ...props }) {
577
+ const { valueType, setValueType } = useColorPicker(), handleChange = (value) => {
578
+ setValueType(VALUE_TYPES.find((type) => type.value === value) ?? defaultValueType);
579
+ };
580
+ return /* @__PURE__ */ jsxs(Select, {
581
+ value: valueType.value,
582
+ onValueChange: handleChange,
583
+ children: [/* @__PURE__ */ jsxs(SelectTrigger, {
584
+ "aria-label": "Color value format",
585
+ variant: "secondary",
586
+ className: cn("", className),
587
+ ref,
588
+ ...props,
589
+ children: [
590
+ children,
591
+ /* @__PURE__ */ jsx(SelectValue, { children: (value) => VALUE_TYPES.find((type) => type.value === value)?.label ?? value }),
592
+ /* @__PURE__ */ jsx(SelectIcon, { children: /* @__PURE__ */ jsx(Icon, { name: "chevronsUpDown" }) })
593
+ ]
594
+ }), /* @__PURE__ */ jsx(SelectPopup, {
595
+ sideOffset: 8,
596
+ children: /* @__PURE__ */ jsx(SelectList, { children: VALUE_TYPES.map(({ label, value }) => /* @__PURE__ */ jsx(SelectItem, {
597
+ value,
598
+ children: label
599
+ }, label)) })
600
+ })]
601
+ });
602
+ }
603
+ // src/components/color-picker/index.ts
604
+ const ColorPicker = Object.assign(ColorPicker$1, {
605
+ Area: ColorPickerArea,
606
+ Group: ColorPickerGroup,
607
+ HueSlider: ColorPickerHueSlider,
608
+ Input: ColorPickerInput,
609
+ Label: ColorPickerLabel,
610
+ LightnessSlider: ColorPickerLightnessSlider,
611
+ PaletteAdd: ColorPickerPaletteAdd,
612
+ PaletteLimit: ColorPickerPaletteLimit,
613
+ PaletteList: ColorPickerPaletteList,
614
+ PaletteSwatch: ColorPickerPaletteSwatch,
615
+ Row: ColorPickerRow,
616
+ TransparencySlider: ColorPickerTransparencySlider,
617
+ ValueType: ColorPickerValueType
618
+ });
619
+ export { ColorPicker, ColorPickerArea, ColorPickerGroup, ColorPickerHueSlider, ColorPickerInput, ColorPickerLabel, ColorPickerLightnessSlider, ColorPickerPaletteLimit, ColorPickerPaletteList, ColorPickerPaletteSwatch, ColorPickerRow, ColorPickerTransparencySlider, ColorPickerValueType };
620
+
621
+ //# sourceMappingURL=index.js.map