@yamada-ui/color-picker 2.0.0-next-20240614140233 → 2.0.0-next-20240615233332

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/dist/alpha-slider.js +14 -25
  2. package/dist/alpha-slider.js.map +1 -1
  3. package/dist/alpha-slider.mjs +2 -2
  4. package/dist/{chunk-OTNMOPLH.mjs → chunk-27BXTC5D.mjs} +4 -4
  5. package/dist/{chunk-C7IY5KVP.mjs → chunk-2K4SHOHA.mjs} +2 -2
  6. package/dist/{chunk-DDHDVGOQ.mjs → chunk-7L64OYDQ.mjs} +2 -2
  7. package/dist/{chunk-UBSVLXYF.mjs → chunk-ABDJB4WV.mjs} +3 -4
  8. package/dist/{chunk-UBSVLXYF.mjs.map → chunk-ABDJB4WV.mjs.map} +1 -1
  9. package/dist/{chunk-KKQ3MOXJ.mjs → chunk-KKUDFHCJ.mjs} +15 -26
  10. package/dist/{chunk-KKQ3MOXJ.mjs.map → chunk-KKUDFHCJ.mjs.map} +1 -1
  11. package/dist/{chunk-HEBLEXJG.mjs → chunk-MPWT2DSW.mjs} +6 -6
  12. package/dist/{chunk-6CYIIW6Z.mjs → chunk-MXH5UN5E.mjs} +2 -2
  13. package/dist/{chunk-X7R6FWCD.mjs → chunk-PCXNTEF4.mjs} +2 -2
  14. package/dist/{chunk-SBN7FEOE.mjs → chunk-PVPQQB6L.mjs} +16 -31
  15. package/dist/{chunk-SBN7FEOE.mjs.map → chunk-PVPQQB6L.mjs.map} +1 -1
  16. package/dist/{chunk-YE3Z2X2L.mjs → chunk-RWVTJOMP.mjs} +4 -4
  17. package/dist/{chunk-5QT7SRA4.mjs → chunk-UZQ2UORY.mjs} +18 -35
  18. package/dist/{chunk-5QT7SRA4.mjs.map → chunk-UZQ2UORY.mjs.map} +1 -1
  19. package/dist/{chunk-R4DLOKLT.mjs → chunk-WRHKYN3W.mjs} +15 -26
  20. package/dist/{chunk-R4DLOKLT.mjs.map → chunk-WRHKYN3W.mjs.map} +1 -1
  21. package/dist/{chunk-NJEVZQVF.mjs → chunk-YPW3ZJM7.mjs} +5 -6
  22. package/dist/{chunk-NJEVZQVF.mjs.map → chunk-YPW3ZJM7.mjs.map} +1 -1
  23. package/dist/{chunk-LHNR2F5V.mjs → chunk-ZHZRZ3XZ.mjs} +2 -2
  24. package/dist/color-picker.js +62 -118
  25. package/dist/color-picker.js.map +1 -1
  26. package/dist/color-picker.mjs +14 -14
  27. package/dist/color-selector-body.js +15 -27
  28. package/dist/color-selector-body.js.map +1 -1
  29. package/dist/color-selector-body.mjs +7 -7
  30. package/dist/color-selector-channels.js +1 -2
  31. package/dist/color-selector-channels.js.map +1 -1
  32. package/dist/color-selector-channels.mjs +2 -2
  33. package/dist/color-selector-eye-dropper.mjs +2 -2
  34. package/dist/color-selector-sliders.js +15 -27
  35. package/dist/color-selector-sliders.js.map +1 -1
  36. package/dist/color-selector-sliders.mjs +5 -5
  37. package/dist/color-selector-swatches.mjs +2 -2
  38. package/dist/color-selector.js +47 -88
  39. package/dist/color-selector.js.map +1 -1
  40. package/dist/color-selector.mjs +12 -12
  41. package/dist/hue-slider.js +14 -25
  42. package/dist/hue-slider.js.map +1 -1
  43. package/dist/hue-slider.mjs +2 -2
  44. package/dist/index.js +62 -118
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +14 -14
  47. package/dist/saturation-slider.js +14 -25
  48. package/dist/saturation-slider.js.map +1 -1
  49. package/dist/saturation-slider.mjs +2 -2
  50. package/dist/use-color-picker.js +15 -30
  51. package/dist/use-color-picker.js.map +1 -1
  52. package/dist/use-color-picker.mjs +1 -1
  53. package/dist/use-color-selector.js +17 -34
  54. package/dist/use-color-selector.js.map +1 -1
  55. package/dist/use-color-selector.mjs +1 -1
  56. package/dist/use-color-slider.js +14 -25
  57. package/dist/use-color-slider.js.map +1 -1
  58. package/dist/use-color-slider.mjs +1 -1
  59. package/dist/use-saturation-slider.js +14 -25
  60. package/dist/use-saturation-slider.js.map +1 -1
  61. package/dist/use-saturation-slider.mjs +1 -1
  62. package/package.json +15 -15
  63. /package/dist/{chunk-OTNMOPLH.mjs.map → chunk-27BXTC5D.mjs.map} +0 -0
  64. /package/dist/{chunk-C7IY5KVP.mjs.map → chunk-2K4SHOHA.mjs.map} +0 -0
  65. /package/dist/{chunk-DDHDVGOQ.mjs.map → chunk-7L64OYDQ.mjs.map} +0 -0
  66. /package/dist/{chunk-HEBLEXJG.mjs.map → chunk-MPWT2DSW.mjs.map} +0 -0
  67. /package/dist/{chunk-6CYIIW6Z.mjs.map → chunk-MXH5UN5E.mjs.map} +0 -0
  68. /package/dist/{chunk-X7R6FWCD.mjs.map → chunk-PCXNTEF4.mjs.map} +0 -0
  69. /package/dist/{chunk-YE3Z2X2L.mjs.map → chunk-RWVTJOMP.mjs.map} +0 -0
  70. /package/dist/{chunk-LHNR2F5V.mjs.map → chunk-ZHZRZ3XZ.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,31 +1,31 @@
1
1
  "use client"
2
2
  import {
3
3
  ColorPicker
4
- } from "./chunk-OTNMOPLH.mjs";
5
- import "./chunk-SBN7FEOE.mjs";
4
+ } from "./chunk-27BXTC5D.mjs";
5
+ import "./chunk-PVPQQB6L.mjs";
6
6
  import {
7
7
  ColorSelector
8
- } from "./chunk-HEBLEXJG.mjs";
8
+ } from "./chunk-MPWT2DSW.mjs";
9
9
  import {
10
10
  SaturationSlider
11
- } from "./chunk-X7R6FWCD.mjs";
12
- import "./chunk-KKQ3MOXJ.mjs";
13
- import "./chunk-YE3Z2X2L.mjs";
14
- import "./chunk-UBSVLXYF.mjs";
15
- import "./chunk-6CYIIW6Z.mjs";
16
- import "./chunk-NJEVZQVF.mjs";
11
+ } from "./chunk-PCXNTEF4.mjs";
12
+ import "./chunk-KKUDFHCJ.mjs";
13
+ import "./chunk-RWVTJOMP.mjs";
14
+ import "./chunk-ABDJB4WV.mjs";
15
+ import "./chunk-MXH5UN5E.mjs";
16
+ import "./chunk-YPW3ZJM7.mjs";
17
17
  import {
18
18
  HueSlider
19
- } from "./chunk-DDHDVGOQ.mjs";
19
+ } from "./chunk-7L64OYDQ.mjs";
20
20
  import {
21
21
  AlphaSlider
22
- } from "./chunk-LHNR2F5V.mjs";
23
- import "./chunk-R4DLOKLT.mjs";
24
- import "./chunk-C7IY5KVP.mjs";
22
+ } from "./chunk-ZHZRZ3XZ.mjs";
23
+ import "./chunk-WRHKYN3W.mjs";
24
+ import "./chunk-2K4SHOHA.mjs";
25
25
  import {
26
26
  ColorSwatch
27
27
  } from "./chunk-WHGFYZII.mjs";
28
- import "./chunk-5QT7SRA4.mjs";
28
+ import "./chunk-UZQ2UORY.mjs";
29
29
  export {
30
30
  AlphaSlider,
31
31
  ColorPicker,
@@ -55,8 +55,7 @@ var useSaturationSlider = ({
55
55
  focusThumbOnChange = true,
56
56
  ...props
57
57
  }) => {
58
- if (!focusThumbOnChange)
59
- props.isReadOnly = true;
58
+ if (!focusThumbOnChange) props.isReadOnly = true;
60
59
  let {
61
60
  id,
62
61
  name,
@@ -104,8 +103,7 @@ var useSaturationSlider = ({
104
103
  const getValueFromPointer = (0, import_react.useCallback)(
105
104
  (ev) => {
106
105
  var _a, _b;
107
- if (!trackRef.current)
108
- return [];
106
+ if (!trackRef.current) return [];
109
107
  const { step: step2 } = latestRef.current;
110
108
  latestRef.current.eventSource = "pointer";
111
109
  const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
@@ -123,25 +121,21 @@ var useSaturationSlider = ({
123
121
  const setValueFromPointer = (ev) => {
124
122
  const { value: value2 } = latestRef.current;
125
123
  const [nextS, nextV] = getValueFromPointer(ev);
126
- if (nextS == null || nextV == null)
127
- return;
124
+ if (nextS == null || nextV == null) return;
128
125
  const [, s2, v2] = value2;
129
- if (nextS !== s2 || nextV !== v2)
130
- setValue(([h2]) => [h2, nextS, nextV]);
126
+ if (nextS !== s2 || nextV !== v2) setValue(([h2]) => [h2, nextS, nextV]);
131
127
  };
132
128
  const focusThumb = (0, import_react.useCallback)(() => {
133
129
  const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
134
- if (focusThumbOnChange2)
135
- setTimeout(() => {
136
- var _a;
137
- return (_a = thumbRef.current) == null ? void 0 : _a.focus();
138
- });
130
+ if (focusThumbOnChange2) setTimeout(() => {
131
+ var _a;
132
+ return (_a = thumbRef.current) == null ? void 0 : _a.focus();
133
+ });
139
134
  }, [latestRef]);
140
135
  const constrain = (0, import_react.useCallback)(
141
136
  ([s2, v2]) => {
142
137
  const { isInteractive: isInteractive2 } = latestRef.current;
143
- if (!isInteractive2)
144
- return;
138
+ if (!isInteractive2) return;
145
139
  s2 = (0, import_utils.clampNumber)(s2, 0, 1);
146
140
  v2 = (0, import_utils.clampNumber)(v2, 0, 1);
147
141
  setValue(([h2]) => [h2, s2, v2]);
@@ -157,8 +151,7 @@ var useSaturationSlider = ({
157
151
  ArrowDown: () => constrain([s, v - step])
158
152
  };
159
153
  const action = actions[ev.key];
160
- if (!action)
161
- return;
154
+ if (!action) return;
162
155
  ev.preventDefault();
163
156
  ev.stopPropagation();
164
157
  action(ev);
@@ -169,8 +162,7 @@ var useSaturationSlider = ({
169
162
  (0, import_use_pan_event.usePanEvent)(containerRef, {
170
163
  onSessionStart: (ev) => {
171
164
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
172
- if (!isInteractive2)
173
- return;
165
+ if (!isInteractive2) return;
174
166
  setDragging(true);
175
167
  focusThumb();
176
168
  setValueFromPointer(ev);
@@ -178,22 +170,19 @@ var useSaturationSlider = ({
178
170
  },
179
171
  onSessionEnd: () => {
180
172
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
181
- if (!isInteractive2)
182
- return;
173
+ if (!isInteractive2) return;
183
174
  setDragging(false);
184
175
  onChangeEnd(value2);
185
176
  },
186
177
  onMove: (ev) => {
187
178
  const { isInteractive: isInteractive2 } = latestRef.current;
188
- if (!isInteractive2)
189
- return;
179
+ if (!isInteractive2) return;
190
180
  setValueFromPointer(ev);
191
181
  }
192
182
  });
193
183
  (0, import_utils.useUpdateEffect)(() => {
194
184
  const { eventSource, value: value2 } = latestRef.current;
195
- if (eventSource === "keyboard")
196
- onChangeEnd(value2);
185
+ if (eventSource === "keyboard") onChangeEnd(value2);
197
186
  }, [value, onChangeEnd]);
198
187
  const getContainerProps = (0, import_react.useCallback)(
199
188
  (props2 = {}, ref = null) => ({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/saturation-slider.tsx","../src/use-saturation-slider.ts"],"sourcesContent":["import {\n ui,\n forwardRef,\n useMultiComponentStyle,\n omitThemeProps,\n} from \"@yamada-ui/core\"\nimport type {\n CSSUIObject,\n HTMLUIProps,\n ThemeProps,\n Token,\n} from \"@yamada-ui/core\"\nimport { cx, replaceObject } from \"@yamada-ui/utils\"\nimport type { UseSaturationSliderProps } from \"./use-saturation-slider\"\nimport { useSaturationSlider } from \"./use-saturation-slider\"\n\ntype SaturationSliderOptions = {\n /**\n * The aspect ratio of the saturation slider.\n *\n * @default '16 / 9'\n */\n ratio?: Token<number>\n /**\n * Props for saturation slider inner element.\n */\n innerProps?: HTMLUIProps<\"div\">\n /**\n * Props for saturation slider input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for saturation slider track element.\n */\n trackProps?: HTMLUIProps<\"div\">\n /**\n * Props for saturation slider thumb element.\n */\n thumbProps?: HTMLUIProps<\"div\">\n}\n\n/**\n * `SaturationSlider` is a component used to allow the user to select a color saturation.\n *\n * @see Docs https://yamada-ui.com/components/forms/saturation-slider\n */\nexport type SaturationSliderProps = ThemeProps<\"SaturationSlider\"> &\n UseSaturationSliderProps &\n SaturationSliderOptions\n\nexport const SaturationSlider = forwardRef<SaturationSliderProps, \"input\">(\n (props, ref) => {\n const [styles, mergedProps] = useMultiComponentStyle(\n \"SaturationSlider\",\n props,\n )\n const {\n className,\n ratio = 16 / 9,\n innerProps,\n inputProps,\n trackProps,\n thumbProps,\n __css,\n ...computedProps\n } = omitThemeProps(mergedProps)\n const {\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n } = useSaturationSlider(computedProps)\n\n const css: CSSUIObject = {\n position: \"relative\",\n _before: {\n content: `\"\"`,\n display: \"block\",\n h: 0,\n pb: replaceObject(ratio, (r) => `${(1 / r) * 100}%`),\n },\n \"& > *\": {\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n bottom: \"0\",\n left: \"0\",\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n w: \"100%\",\n h: \"100%\",\n },\n ...styles.container,\n ...__css,\n }\n\n return (\n <ui.div\n className={cx(\"ui-saturation-slider\", className)}\n __css={css}\n {...getContainerProps()}\n >\n <ui.div\n className={cx(\"ui-saturation-slider__inner\", className)}\n __css={{ ...styles.inner }}\n {...getInnerProps(innerProps)}\n >\n <ui.input {...getInputProps(inputProps, ref)} />\n\n {overlays.map((props, index) => (\n <ui.div\n key={index}\n className=\"ui-saturation-slider__overlay\"\n __css={{\n ...styles.overlay,\n }}\n {...props}\n />\n ))}\n\n <ui.div\n className=\"ui-saturation-slider__track\"\n __css={{\n ...styles.track,\n }}\n {...getTrackProps(trackProps)}\n >\n <ui.div\n className=\"ui-saturation-slider__thumb\"\n __css={{ ...styles.thumb }}\n {...getThumbProps(thumbProps)}\n />\n </ui.div>\n </ui.div>\n </ui.div>\n )\n },\n)\n","import type { CSSUIProps, HTMLUIProps, UIPropGetter } from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n getFormControlProperties,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useLatestRef } from \"@yamada-ui/use-latest-ref\"\nimport { usePanEvent } from \"@yamada-ui/use-pan-event\"\nimport { useSize } from \"@yamada-ui/use-size\"\nimport {\n omitObject,\n dataAttr,\n handlerAll,\n mergeRefs,\n useCallbackRef,\n runIfFunc,\n clampNumber,\n hsvTo,\n roundNumberToStep,\n pickObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\n\nexport type Hsv = [number, number, number]\ntype Overlay = HTMLUIProps<\"div\"> | ((value: Hsv) => HTMLUIProps<\"div\">)\n\nconst defaultOverlays = (withShadow: boolean): Overlay[] => {\n let overlays: Overlay[] = [\n ([h]) => ({\n bg: `hsl(${h}, 100%, 50%)`,\n bgImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\n }),\n ]\n\n if (withShadow)\n overlays = [\n ...overlays,\n {\n boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`,\n },\n ]\n\n return overlays\n}\n\ntype UseSaturationSliderOptions = {\n /**\n * The base `id` to use for the saturation slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The value of the saturation slider.\n */\n value?: Hsv\n /**\n * The initial value of the saturation slider.\n *\n * @default \"[0, 0, 1]\"\n */\n defaultValue?: Hsv\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: Hsv) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Hsv) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Hsv) => void\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * If `false`, the saturation slider handle will not capture focus when value changes.\n *\n * @default true\n */\n focusThumbOnChange?: boolean\n /**\n * The CSS `background` property. Used in `background` of thumb element.\n */\n thumbColor?: CSSUIProps[\"bg\"]\n /**\n * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * The overlay used for the saturation slider.\n */\n overlays?: Overlay[]\n}\n\nexport type UseSaturationSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseSaturationSliderOptions &\n FormControlOptions\n\nexport const useSaturationSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseSaturationSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue = [0, 0, 1],\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n step = 0.01,\n thumbColor,\n required,\n disabled,\n readOnly,\n withShadow = true,\n overlays: overlaysProp = defaultOverlays(withShadow),\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n let [h, s, v] = value\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n const containerRef = useRef<HTMLElement>(null)\n const trackRef = useRef<HTMLElement>(null)\n const thumbRef = useRef<HTMLElement>(null)\n const latestRef = useLatestRef({\n value,\n step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const overlays = useMemo(\n () => overlaysProp.map((propsOrFunc) => runIfFunc(propsOrFunc, [h, s, v])),\n [overlaysProp, h, s, v],\n )\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return []\n\n const { step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { bottom, left, height, width } =\n trackRef.current.getBoundingClientRect()\n const { clientX, clientY } = ev.touches?.[0] ?? ev\n\n let s = clampNumber((clientX - left) / width, 0, 1)\n let v = clampNumber((bottom - clientY) / height, 0, 1)\n\n if (step) {\n s = parseFloat(roundNumberToStep(s, 0, step))\n v = parseFloat(roundNumberToStep(v, 0, step))\n }\n\n return [s, v]\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const [nextS, nextV] = getValueFromPointer(ev)\n\n if (nextS == null || nextV == null) return\n\n const [, s, v] = value\n\n if (nextS !== s || nextV !== v) setValue(([h]) => [h, nextS, nextV])\n }\n\n const focusThumb = useCallback(() => {\n const { focusThumbOnChange } = latestRef.current\n\n if (focusThumbOnChange) setTimeout(() => thumbRef.current?.focus())\n }, [latestRef])\n\n const constrain = useCallback(\n ([s, v]: [number, number]) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue(([h]) => [h, s, v])\n },\n [latestRef, setValue],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => constrain([s + step, v]),\n ArrowUp: () => constrain([s, v + step]),\n ArrowLeft: () => constrain([s - step, v]),\n ArrowDown: () => constrain([s, v - step]),\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n\n action(ev)\n\n latestRef.current.eventSource = \"keyboard\"\n },\n [latestRef, constrain, s, v, step],\n )\n\n usePanEvent(containerRef, {\n onSessionStart: (ev) => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(true)\n focusThumb()\n setValueFromPointer(ev)\n onChangeStart(value)\n },\n onSessionEnd: () => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(false)\n onChangeEnd(value)\n },\n onMove: (ev) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n setValueFromPointer(ev)\n },\n })\n\n useUpdateEffect(() => {\n const { eventSource, value } = latestRef.current\n\n if (eventSource === \"keyboard\") onChangeEnd(value)\n }, [value, onChangeEnd])\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n }),\n [rest],\n )\n\n const getInnerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n ...rest.style,\n padding: `${w / 2}px`,\n }\n\n return {\n ...props,\n ref,\n style,\n }\n },\n [rest, thumbSize],\n )\n\n const getInputProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(rest, formControlProperties),\n ...props,\n id,\n ref,\n type: \"hidden\",\n name,\n value: [h, s, v].toString(),\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, h, s, v],\n )\n\n const getTrackProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(\n rest,\n getFormControlProperties({ omit: [\"aria-readonly\"] }),\n ),\n ...props,\n ref: mergeRefs(ref, trackRef),\n }),\n [rest],\n )\n\n const getThumbProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width, height } = thumbSize ?? { width: 0, height: 0 }\n const x = s * 100\n const y = v * 100\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${x}% - ${width / 2}px)`,\n bottom: `calc(${y}% - ${height / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Saturation and brightness thumb\",\n bg: thumbColor ?? hsvTo([h, s, v])(),\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": s,\n \"aria-valuemin\": 0,\n \"aria-valuemax\": 100,\n \"aria-valuetext\": `saturation ${s}, brightness ${v}`,\n \"data-active\": dataAttr(isDragging && focusThumbOnChange),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onFocus: handlerAll(props.onFocus, rest.onFocus),\n onBlur: handlerAll(props.onBlur, rest.onBlur),\n style,\n }\n },\n [\n h,\n s,\n v,\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n onKeyDown,\n rest,\n thumbSize,\n ],\n )\n\n return {\n value,\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AAOP,IAAAA,gBAAkC;;;ACXlC,0BAKO;AACP,oCAAqC;AACrC,4BAA6B;AAC7B,2BAA4B;AAC5B,sBAAwB;AACxB,mBAYO;AAEP,mBAAuD;AAKvD,IAAM,kBAAkB,CAAC,eAAmC;AAC1D,MAAI,WAAsB;AAAA,IACxB,CAAC,CAAC,CAAC,OAAO;AAAA,MACR,IAAI,OAAO,CAAC;AAAA,MACZ,SACE;AAAA,IACJ;AAAA,EACF;AAEA,MAAI;AACF,eAAW;AAAA,MACT,GAAG;AAAA,MACH;AAAA,QACE,WAAW;AAAA,MACb;AAAA,IACF;AAEF,SAAO;AACT;AAqEO,IAAM,sBAAsB,CAAC;AAAA,EAClC,qBAAqB;AAAA,EACrB,GAAG;AACL,MAAgC;AAC9B,MAAI,CAAC;AAAoB,UAAM,aAAa;AAE5C,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,eAAe,CAAC,GAAG,GAAG,CAAC;AAAA,IACvB,UAAU;AAAA,IACV,eAAe;AAAA,IACf,aAAa;AAAA,IACb,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,UAAU,eAAe,gBAAgB,UAAU;AAAA,IACnD,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAE7B,QAAM,oBAAgB,6BAAe,iBAAiB;AACtD,QAAM,kBAAc,6BAAe,eAAe;AAElD,QAAM,CAAC,OAAO,QAAQ,QAAI,oDAAqB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AA,kBACZ;AAAA,kBACC,GAAG,cAAc,UAAU;AAAA,kBAE5B;AAAA,oBAAC,eAAG;AAAA,oBAAH;AAAA,sBACC,WAAU;AAAA,sBACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,sBACxB,GAAG,cAAc,UAAU;AAAA;AAAA,kBAC9B;AAAA;AAAA,cACF;AAAA;AAAA;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;","names":["import_utils","step","s","v","value","h","focusThumbOnChange","isInteractive","props","props"]}
1
+ {"version":3,"sources":["../src/saturation-slider.tsx","../src/use-saturation-slider.ts"],"sourcesContent":["import {\n ui,\n forwardRef,\n useMultiComponentStyle,\n omitThemeProps,\n} from \"@yamada-ui/core\"\nimport type {\n CSSUIObject,\n HTMLUIProps,\n ThemeProps,\n Token,\n} from \"@yamada-ui/core\"\nimport { cx, replaceObject } from \"@yamada-ui/utils\"\nimport type { UseSaturationSliderProps } from \"./use-saturation-slider\"\nimport { useSaturationSlider } from \"./use-saturation-slider\"\n\ntype SaturationSliderOptions = {\n /**\n * The aspect ratio of the saturation slider.\n *\n * @default '16 / 9'\n */\n ratio?: Token<number>\n /**\n * Props for saturation slider inner element.\n */\n innerProps?: HTMLUIProps<\"div\">\n /**\n * Props for saturation slider input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for saturation slider track element.\n */\n trackProps?: HTMLUIProps<\"div\">\n /**\n * Props for saturation slider thumb element.\n */\n thumbProps?: HTMLUIProps<\"div\">\n}\n\n/**\n * `SaturationSlider` is a component used to allow the user to select a color saturation.\n *\n * @see Docs https://yamada-ui.com/components/forms/saturation-slider\n */\nexport type SaturationSliderProps = ThemeProps<\"SaturationSlider\"> &\n UseSaturationSliderProps &\n SaturationSliderOptions\n\nexport const SaturationSlider = forwardRef<SaturationSliderProps, \"input\">(\n (props, ref) => {\n const [styles, mergedProps] = useMultiComponentStyle(\n \"SaturationSlider\",\n props,\n )\n const {\n className,\n ratio = 16 / 9,\n innerProps,\n inputProps,\n trackProps,\n thumbProps,\n __css,\n ...computedProps\n } = omitThemeProps(mergedProps)\n const {\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n } = useSaturationSlider(computedProps)\n\n const css: CSSUIObject = {\n position: \"relative\",\n _before: {\n content: `\"\"`,\n display: \"block\",\n h: 0,\n pb: replaceObject(ratio, (r) => `${(1 / r) * 100}%`),\n },\n \"& > *\": {\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n bottom: \"0\",\n left: \"0\",\n display: \"flex\",\n justifyContent: \"center\",\n alignItems: \"center\",\n w: \"100%\",\n h: \"100%\",\n },\n ...styles.container,\n ...__css,\n }\n\n return (\n <ui.div\n className={cx(\"ui-saturation-slider\", className)}\n __css={css}\n {...getContainerProps()}\n >\n <ui.div\n className={cx(\"ui-saturation-slider__inner\", className)}\n __css={{ ...styles.inner }}\n {...getInnerProps(innerProps)}\n >\n <ui.input {...getInputProps(inputProps, ref)} />\n\n {overlays.map((props, index) => (\n <ui.div\n key={index}\n className=\"ui-saturation-slider__overlay\"\n __css={{\n ...styles.overlay,\n }}\n {...props}\n />\n ))}\n\n <ui.div\n className=\"ui-saturation-slider__track\"\n __css={{\n ...styles.track,\n }}\n {...getTrackProps(trackProps)}\n >\n <ui.div\n className=\"ui-saturation-slider__thumb\"\n __css={{ ...styles.thumb }}\n {...getThumbProps(thumbProps)}\n />\n </ui.div>\n </ui.div>\n </ui.div>\n )\n },\n)\n","import type { CSSUIProps, HTMLUIProps, UIPropGetter } from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n getFormControlProperties,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useLatestRef } from \"@yamada-ui/use-latest-ref\"\nimport { usePanEvent } from \"@yamada-ui/use-pan-event\"\nimport { useSize } from \"@yamada-ui/use-size\"\nimport {\n omitObject,\n dataAttr,\n handlerAll,\n mergeRefs,\n useCallbackRef,\n runIfFunc,\n clampNumber,\n hsvTo,\n roundNumberToStep,\n pickObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\n\nexport type Hsv = [number, number, number]\ntype Overlay = HTMLUIProps<\"div\"> | ((value: Hsv) => HTMLUIProps<\"div\">)\n\nconst defaultOverlays = (withShadow: boolean): Overlay[] => {\n let overlays: Overlay[] = [\n ([h]) => ({\n bg: `hsl(${h}, 100%, 50%)`,\n bgImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\n }),\n ]\n\n if (withShadow)\n overlays = [\n ...overlays,\n {\n boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`,\n },\n ]\n\n return overlays\n}\n\ntype UseSaturationSliderOptions = {\n /**\n * The base `id` to use for the saturation slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The value of the saturation slider.\n */\n value?: Hsv\n /**\n * The initial value of the saturation slider.\n *\n * @default \"[0, 0, 1]\"\n */\n defaultValue?: Hsv\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: Hsv) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Hsv) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Hsv) => void\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * If `false`, the saturation slider handle will not capture focus when value changes.\n *\n * @default true\n */\n focusThumbOnChange?: boolean\n /**\n * The CSS `background` property. Used in `background` of thumb element.\n */\n thumbColor?: CSSUIProps[\"bg\"]\n /**\n * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * The overlay used for the saturation slider.\n */\n overlays?: Overlay[]\n}\n\nexport type UseSaturationSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseSaturationSliderOptions &\n FormControlOptions\n\nexport const useSaturationSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseSaturationSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue = [0, 0, 1],\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n step = 0.01,\n thumbColor,\n required,\n disabled,\n readOnly,\n withShadow = true,\n overlays: overlaysProp = defaultOverlays(withShadow),\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n let [h, s, v] = value\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n const containerRef = useRef<HTMLElement>(null)\n const trackRef = useRef<HTMLElement>(null)\n const thumbRef = useRef<HTMLElement>(null)\n const latestRef = useLatestRef({\n value,\n step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const overlays = useMemo(\n () => overlaysProp.map((propsOrFunc) => runIfFunc(propsOrFunc, [h, s, v])),\n [overlaysProp, h, s, v],\n )\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return []\n\n const { step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { bottom, left, height, width } =\n trackRef.current.getBoundingClientRect()\n const { clientX, clientY } = ev.touches?.[0] ?? ev\n\n let s = clampNumber((clientX - left) / width, 0, 1)\n let v = clampNumber((bottom - clientY) / height, 0, 1)\n\n if (step) {\n s = parseFloat(roundNumberToStep(s, 0, step))\n v = parseFloat(roundNumberToStep(v, 0, step))\n }\n\n return [s, v]\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const [nextS, nextV] = getValueFromPointer(ev)\n\n if (nextS == null || nextV == null) return\n\n const [, s, v] = value\n\n if (nextS !== s || nextV !== v) setValue(([h]) => [h, nextS, nextV])\n }\n\n const focusThumb = useCallback(() => {\n const { focusThumbOnChange } = latestRef.current\n\n if (focusThumbOnChange) setTimeout(() => thumbRef.current?.focus())\n }, [latestRef])\n\n const constrain = useCallback(\n ([s, v]: [number, number]) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue(([h]) => [h, s, v])\n },\n [latestRef, setValue],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => constrain([s + step, v]),\n ArrowUp: () => constrain([s, v + step]),\n ArrowLeft: () => constrain([s - step, v]),\n ArrowDown: () => constrain([s, v - step]),\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n\n action(ev)\n\n latestRef.current.eventSource = \"keyboard\"\n },\n [latestRef, constrain, s, v, step],\n )\n\n usePanEvent(containerRef, {\n onSessionStart: (ev) => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(true)\n focusThumb()\n setValueFromPointer(ev)\n onChangeStart(value)\n },\n onSessionEnd: () => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(false)\n onChangeEnd(value)\n },\n onMove: (ev) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n setValueFromPointer(ev)\n },\n })\n\n useUpdateEffect(() => {\n const { eventSource, value } = latestRef.current\n\n if (eventSource === \"keyboard\") onChangeEnd(value)\n }, [value, onChangeEnd])\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n }),\n [rest],\n )\n\n const getInnerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n ...rest.style,\n padding: `${w / 2}px`,\n }\n\n return {\n ...props,\n ref,\n style,\n }\n },\n [rest, thumbSize],\n )\n\n const getInputProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(rest, formControlProperties),\n ...props,\n id,\n ref,\n type: \"hidden\",\n name,\n value: [h, s, v].toString(),\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, h, s, v],\n )\n\n const getTrackProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(\n rest,\n getFormControlProperties({ omit: [\"aria-readonly\"] }),\n ),\n ...props,\n ref: mergeRefs(ref, trackRef),\n }),\n [rest],\n )\n\n const getThumbProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width, height } = thumbSize ?? { width: 0, height: 0 }\n const x = s * 100\n const y = v * 100\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${x}% - ${width / 2}px)`,\n bottom: `calc(${y}% - ${height / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Saturation and brightness thumb\",\n bg: thumbColor ?? hsvTo([h, s, v])(),\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": s,\n \"aria-valuemin\": 0,\n \"aria-valuemax\": 100,\n \"aria-valuetext\": `saturation ${s}, brightness ${v}`,\n \"data-active\": dataAttr(isDragging && focusThumbOnChange),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onFocus: handlerAll(props.onFocus, rest.onFocus),\n onBlur: handlerAll(props.onBlur, rest.onBlur),\n style,\n }\n },\n [\n h,\n s,\n v,\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n onKeyDown,\n rest,\n thumbSize,\n ],\n )\n\n return {\n value,\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AAOP,IAAAA,gBAAkC;;;ACXlC,0BAKO;AACP,oCAAqC;AACrC,4BAA6B;AAC7B,2BAA4B;AAC5B,sBAAwB;AACxB,mBAYO;AAEP,mBAAuD;AAKvD,IAAM,kBAAkB,CAAC,eAAmC;AAC1D,MAAI,WAAsB;AAAA,IACxB,CAAC,CAAC,CAAC,OAAO;AAAA,MACR,IAAI,OAAO,CAAC;AAAA,MACZ,SACE;AAAA,IACJ;AAAA,EACF;AAEA,MAAI;AACF,eAAW;AAAA,MACT,GAAG;AAAA,MACH;AAAA,QACE,WAAW;AAAA,MACb;AAAA,IACF;AAEF,SAAO;AACT;AAqEO,IAAM,sBAAsB,CAAC;AAAA,EAClC,qBAAqB;AAAA,EACrB,GAAG;AACL,MAAgC;AAC9B,MAAI,CAAC,mBAAoB,OAAM,aAAa;AAE5C,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,eAAe,CAAC,GAAG,GAAG,CAAC;AAAA,IACvB,UAAU;AAAA,IACV,eAAe;AAAA,IACf,aAAa;AAAA,IACb,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,UAAU,eAAe,gBAAgB,UAAU;AAAA,IACnD,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AA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CACD;AAAA,cAED;AAAA,gBAAC,eAAG;AAAA,gBAAH;AAAA,kBACC,WAAU;AAAA,kBACV,OAAO;AAAA,oBACL,GAAG,OAAO;AAAA,kBACZ;AAAA,kBACC,GAAG,cAAc,UAAU;AAAA,kBAE5B;AAAA,oBAAC,eAAG;AAAA,oBAAH;AAAA,sBACC,WAAU;AAAA,sBACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,sBACxB,GAAG,cAAc,UAAU;AAAA;AAAA,kBAC9B;AAAA;AAAA,cACF;AAAA;AAAA;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;","names":["import_utils","step","s","v","value","h","focusThumbOnChange","isInteractive","props","props"]}
@@ -1,8 +1,8 @@
1
1
  "use client"
2
2
  import {
3
3
  SaturationSlider
4
- } from "./chunk-X7R6FWCD.mjs";
5
- import "./chunk-KKQ3MOXJ.mjs";
4
+ } from "./chunk-PCXNTEF4.mjs";
5
+ import "./chunk-KKUDFHCJ.mjs";
6
6
  export {
7
7
  SaturationSlider
8
8
  };
@@ -108,13 +108,11 @@ var useColorPicker = ({
108
108
  });
109
109
  const isColorSelectorFull = colorSelectorSize === "full";
110
110
  const onOpen = (0, import_react.useCallback)(() => {
111
- if (disabled || readOnly)
112
- return;
111
+ if (disabled || readOnly) return;
113
112
  onInternalOpen();
114
113
  }, [onInternalOpen, disabled, readOnly]);
115
114
  const onClose = (0, import_react.useCallback)(() => {
116
- if (!isOpen)
117
- return;
115
+ if (!isOpen) return;
118
116
  const next = (0, import_utils.convertColor)(value, fallbackValue)(formatRef.current);
119
117
  setValue((prev) => !next || prev === next ? prev : next);
120
118
  setInputValue(formatInput(next != null ? next : ""));
@@ -130,14 +128,12 @@ var useColorPicker = ({
130
128
  fallbackValue
131
129
  ]);
132
130
  const onContainerClick = (0, import_react.useCallback)(() => {
133
- if (isOpen)
134
- return;
131
+ if (isOpen) return;
135
132
  onOpen();
136
133
  }, [isOpen, onOpen]);
137
134
  const onInputFocus = (0, import_react.useCallback)(() => {
138
135
  isInputFocused.current = true;
139
- if (isOpen)
140
- return;
136
+ if (isOpen) return;
141
137
  onOpen();
142
138
  }, [isOpen, onOpen]);
143
139
  const onInputBlur = (0, import_react.useCallback)(() => {
@@ -146,29 +142,23 @@ var useColorPicker = ({
146
142
  const onContainerBlur = (0, import_react.useCallback)(
147
143
  (ev) => {
148
144
  const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
149
- if ((0, import_utils.isContains)(containerRef.current, relatedTarget))
150
- return;
151
- if (!closeOnBlur)
152
- return;
153
- if (isOpen)
154
- onClose();
145
+ if ((0, import_utils.isContains)(containerRef.current, relatedTarget)) return;
146
+ if (!closeOnBlur) return;
147
+ if (isOpen) onClose();
155
148
  },
156
149
  [closeOnBlur, isOpen, onClose]
157
150
  );
158
151
  const onInputKeyDown = (0, import_react.useCallback)(
159
152
  (ev) => {
160
- if (ev.key === " ")
161
- ev.key = ev.code;
162
- if (disabled || readOnly)
163
- return;
153
+ if (ev.key === " ") ev.key = ev.code;
154
+ if (disabled || readOnly) return;
164
155
  const actions = {
165
156
  Space: !isOpen ? onOpen : void 0,
166
157
  Enter: !isOpen ? onOpen : void 0,
167
158
  Escape: closeOnEsc ? onClose : void 0
168
159
  };
169
160
  const action = actions[ev.key];
170
- if (!action)
171
- return;
161
+ if (!action) return;
172
162
  ev.preventDefault();
173
163
  ev.stopPropagation();
174
164
  action();
@@ -187,8 +177,7 @@ var useColorPicker = ({
187
177
  (value2) => {
188
178
  setValue(value2);
189
179
  setTimeout(() => {
190
- if (!isInputFocused.current)
191
- setInputValue(formatInput(value2));
180
+ if (!isInputFocused.current) setInputValue(formatInput(value2));
192
181
  });
193
182
  },
194
183
  [setValue, formatInput]
@@ -200,8 +189,7 @@ var useColorPicker = ({
200
189
  ev.stopPropagation();
201
190
  try {
202
191
  const { sRGBHex } = (_a2 = await onEyeDropperOpen()) != null ? _a2 : {};
203
- if (!sRGBHex)
204
- return;
192
+ if (!sRGBHex) return;
205
193
  onColorSelectorChange(sRGBHex);
206
194
  onChangeEnd == null ? void 0 : onChangeEnd(sRGBHex);
207
195
  } catch {
@@ -215,18 +203,15 @@ var useColorPicker = ({
215
203
  enabled: isOpen && closeOnBlur
216
204
  });
217
205
  (0, import_utils.useUpdateEffect)(() => {
218
- if (!format || !value)
219
- return;
206
+ if (!format || !value) return;
220
207
  formatRef.current = format;
221
208
  const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
222
- if (!nextValue)
223
- return;
209
+ if (!nextValue) return;
224
210
  setInputValue(formatInput(nextValue));
225
211
  setValue(nextValue);
226
212
  }, [format]);
227
213
  (0, import_utils.useUpdateEffect)(() => {
228
- if (isInputFocused.current || !valueProp)
229
- return;
214
+ if (isInputFocused.current || !valueProp) return;
230
215
  setInputValue(formatInput(valueProp));
231
216
  }, [valueProp]);
232
217
  const getPopoverProps = (0, import_react.useCallback)(
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-color-picker.ts"],"sourcesContent":["import { layoutStyleProperties } from \"@yamada-ui/core\"\nimport type {\n UIPropGetter,\n CSSUIObject,\n ThemeProps,\n HTMLUIProps,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { popoverProperties, type PopoverProps } from \"@yamada-ui/popover\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useDisclosure } from \"@yamada-ui/use-disclosure\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport { useOutsideClick } from \"@yamada-ui/use-outside-click\"\nimport type { ColorFormat, Dict } from \"@yamada-ui/utils\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n mergeRefs,\n pickObject,\n splitObject,\n omitObject,\n getEventRelatedTarget,\n isContains,\n convertColor,\n calcFormat,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from \"react\"\nimport { useCallback, useRef, useState } from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { UseColorSelectorBaseProps } from \"./use-color-selector\"\n\ntype ColorSelectorThemeProps = ThemeProps<\"ColorSelector\">\n\ntype ColorPickerContext = { value: string; styles: Record<string, CSSUIObject> }\n\nexport const [ColorPickerProvider, useColorPickerContext] =\n createContext<ColorPickerContext>({\n name: \"ColorPickerContext\",\n errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorPicker />\"`,\n })\n\ntype UseColorPickerOptions = {\n /**\n * The initial value of the color selector.\n */\n defaultColor?: string\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * A callback function to format the input entered.\n */\n formatInput?: (value: string) => string\n /**\n * If `true`, display the result component.\n *\n * @default false\n */\n withResult?: boolean\n /**\n * If `true` display the eye dropper component.\n *\n * @default false\n */\n withColorSelectorEyeDropper?: boolean\n /**\n * If `true`, the color swatch will be closed when value is selected.\n */\n closeOnSelectSwatch?: boolean\n /**\n * Variant for the color selector component.\n */\n colorSelectorVariant?: ColorSelectorThemeProps[\"variant\"]\n /**\n * Size for the color selector component.\n */\n colorSelectorSize?: ColorSelectorThemeProps[\"size\"]\n /**\n * ColorScheme for the color selector component.\n */\n colorSelectorColorScheme?: ColorSelectorThemeProps[\"colorScheme\"]\n /**\n * Props for color selector component.\n */\n colorSelectorProps?: ColorSelectorProps\n}\n\nexport type UseColorPickerProps = Omit<\n HTMLUIProps<\"input\">,\n \"size\" | \"offset\" | \"value\" | \"defaultValue\" | \"onChange\" | \"children\"\n> &\n Omit<UseColorSelectorBaseProps, \"id\" | \"name\"> &\n Omit<\n PopoverProps,\n | \"initialFocusRef\"\n | \"closeOnButton\"\n | \"trigger\"\n | \"autoFocus\"\n | \"restoreFocus\"\n | \"openDelay\"\n | \"closeDelay\"\n | \"children\"\n > &\n Pick<\n ColorSelectorProps,\n | \"withPicker\"\n | \"withChannel\"\n | \"swatchesLabel\"\n | \"swatches\"\n | \"swatchesColumns\"\n > &\n UseColorPickerOptions\n\nexport const useColorPicker = ({\n value: valueProp,\n defaultValue,\n fallbackValue,\n defaultColor,\n onChange: onChangeProp,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n formatInput = (value) => value,\n closeOnBlur = true,\n closeOnEsc = true,\n placement = \"bottom-start\",\n duration = 0.2,\n isOpen: isOpenProp,\n defaultIsOpen,\n onOpen: onOpenProp,\n onClose: onCloseProp,\n allowInput = true,\n closeOnSelectSwatch,\n format,\n swatchesLabel,\n swatches,\n swatchesColumns,\n withPicker,\n withChannel,\n withResult = false,\n withColorSelectorEyeDropper = false,\n colorSelectorVariant,\n colorSelectorSize,\n colorSelectorColorScheme,\n ...rest\n}: UseColorPickerProps) => {\n rest = useFormControlProps(rest)\n\n const { \"aria-readonly\": _ariaReadonly, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n const { disabled, readOnly } = formControlProps\n const [containerProps, inputProps] = splitObject<Dict, string>(\n omitObject(rest, [...popoverProperties]),\n layoutStyleProperties,\n )\n\n const containerRef = useRef<HTMLDivElement>(null)\n const fieldRef = useRef<HTMLInputElement>(null)\n\n const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } =\n useEyeDropper()\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const formatRef = useRef<ColorFormat>(\n format ?? calcFormat(value ?? defaultColor ?? \"\"),\n )\n const isInputFocused = useRef<boolean>(false)\n const [inputValue, setInputValue] = useState<string>(value ?? \"\")\n const {\n isOpen,\n onOpen: onInternalOpen,\n onClose: onInternalClose,\n } = useDisclosure({\n isOpen: isOpenProp,\n defaultIsOpen,\n onOpen: onOpenProp,\n onClose: onCloseProp,\n })\n const isColorSelectorFull = colorSelectorSize === \"full\"\n\n const onOpen = useCallback(() => {\n if (disabled || readOnly) return\n\n onInternalOpen()\n }, [onInternalOpen, disabled, readOnly])\n\n const onClose = useCallback(() => {\n if (!isOpen) return\n\n const next = convertColor(value, fallbackValue)(formatRef.current)\n\n setValue((prev) => (!next || prev === next ? prev : next))\n setInputValue(formatInput(next ?? \"\"))\n\n onInternalClose()\n }, [\n formatRef,\n isOpen,\n setValue,\n onInternalClose,\n value,\n formatInput,\n setInputValue,\n fallbackValue,\n ])\n\n const onContainerClick = useCallback(() => {\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputFocus = useCallback(() => {\n isInputFocused.current = true\n\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputBlur = useCallback(() => {\n isInputFocused.current = false\n }, [])\n\n const onContainerBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n\n if (isContains(containerRef.current, relatedTarget)) return\n\n if (!closeOnBlur) return\n\n if (isOpen) onClose()\n },\n [closeOnBlur, isOpen, onClose],\n )\n\n const onInputKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (ev.key === \" \") ev.key = ev.code\n\n if (disabled || readOnly) return\n\n const actions: Record<string, Function | undefined> = {\n Space: !isOpen ? onOpen : undefined,\n Enter: !isOpen ? onOpen : undefined,\n Escape: closeOnEsc ? onClose : undefined,\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n action()\n },\n [disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n const value = ev.target.value\n\n setInputValue(formatInput(value))\n setValue(value)\n },\n [setInputValue, formatInput, setValue],\n )\n\n const onColorSelectorChange = useCallback(\n (value: string) => {\n setValue(value)\n\n setTimeout(() => {\n if (!isInputFocused.current) setInputValue(formatInput(value))\n })\n },\n [setValue, formatInput],\n )\n\n const onEyeDropperClick = useCallback(\n async (ev: MouseEvent<HTMLButtonElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n try {\n const { sRGBHex } = (await onEyeDropperOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onColorSelectorChange(sRGBHex)\n onChangeEnd?.(sRGBHex)\n } catch {}\n },\n [onEyeDropperOpen, onColorSelectorChange, onChangeEnd],\n )\n\n useOutsideClick({\n ref: containerRef,\n handler: onClose,\n enabled: isOpen && closeOnBlur,\n })\n\n useUpdateEffect(() => {\n if (!format || !value) return\n\n formatRef.current = format\n\n const nextValue = convertColor(value, fallbackValue)(format)\n\n if (!nextValue) return\n\n setInputValue(formatInput(nextValue))\n setValue(nextValue)\n }, [format])\n\n useUpdateEffect(() => {\n if (isInputFocused.current || !valueProp) return\n\n setInputValue(formatInput(valueProp))\n }, [valueProp])\n\n const getPopoverProps = useCallback(\n (props?: PopoverProps): PopoverProps => ({\n matchWidth: isColorSelectorFull,\n ...rest,\n ...props,\n isOpen,\n onOpen,\n onClose,\n placement,\n duration,\n trigger: \"never\",\n closeOnButton: false,\n }),\n [isColorSelectorFull, duration, onClose, onOpen, placement, rest, isOpen],\n )\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(containerRef, ref),\n ...containerProps,\n ...props,\n ...formControlProps,\n onClick: handlerAll(props.onClick, rest.onClick, onContainerClick),\n onBlur: handlerAll(props.onBlur, rest.onBlur, onContainerBlur),\n }),\n [containerProps, formControlProps, onContainerBlur, onContainerClick, rest],\n )\n\n const getFieldProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(fieldRef, ref),\n tabIndex: !allowInput ? -1 : 0,\n ...inputProps,\n ...props,\n style: {\n ...props.style,\n ...(!allowInput ? { pointerEvents: \"none\" } : {}),\n },\n value: inputValue,\n \"data-active\": dataAttr(isOpen),\n \"aria-expanded\": dataAttr(isOpen),\n onFocus: handlerAll(props.onFocus, rest.onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, rest.onKeyDown, onInputKeyDown),\n onChange: handlerAll(props.onChange, onInputChange),\n onBlur: handlerAll(props.onFocus, onInputBlur),\n }),\n [\n allowInput,\n inputProps,\n inputValue,\n isOpen,\n rest,\n onInputFocus,\n onInputKeyDown,\n onInputChange,\n onInputBlur,\n ],\n )\n\n const getEyeDropperProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n disabled,\n \"aria-label\": \"Pick a color\",\n ...props,\n ref,\n style: { ...props.style, pointerEvents: readOnly ? \"none\" : undefined },\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick, readOnly],\n )\n\n const getSelectorProps = useCallback(\n (props?: ColorSelectorProps): ColorSelectorProps => ({\n ...formControlProps,\n ...props,\n value,\n defaultValue: defaultColor,\n fallbackValue,\n onChange: onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick: handlerAll(\n onSwatchClick,\n closeOnSelectSwatch ? onClose : undefined,\n ),\n format: formatRef.current,\n withPicker,\n withChannel,\n withResult,\n withEyeDropper: withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n variant: colorSelectorVariant,\n size: colorSelectorSize,\n colorScheme: colorSelectorColorScheme,\n }),\n [\n formControlProps,\n value,\n fallbackValue,\n defaultColor,\n onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n onClose,\n closeOnSelectSwatch,\n formatRef,\n withPicker,\n withChannel,\n withResult,\n withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n ],\n )\n\n return {\n value,\n eyeDropperSupported,\n allowInput,\n getPopoverProps,\n getContainerProps,\n getFieldProps,\n getSelectorProps,\n getEyeDropperProps,\n }\n}\n\nexport type UseColorPickerReturn = ReturnType<typeof useColorPicker>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsC;AAOtC,0BAGO;AACP,qBAAqD;AACrD,oCAAqC;AACrC,4BAA8B;AAC9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AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","_a"]}
1
+ {"version":3,"sources":["../src/use-color-picker.ts"],"sourcesContent":["import { layoutStyleProperties } from \"@yamada-ui/core\"\nimport type {\n UIPropGetter,\n CSSUIObject,\n ThemeProps,\n HTMLUIProps,\n} from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { popoverProperties, type PopoverProps } from \"@yamada-ui/popover\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useDisclosure } from \"@yamada-ui/use-disclosure\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport { useOutsideClick } from \"@yamada-ui/use-outside-click\"\nimport type { ColorFormat, Dict } from \"@yamada-ui/utils\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n mergeRefs,\n pickObject,\n splitObject,\n omitObject,\n getEventRelatedTarget,\n isContains,\n convertColor,\n calcFormat,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent } from \"react\"\nimport { useCallback, useRef, useState } from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { UseColorSelectorBaseProps } from \"./use-color-selector\"\n\ntype ColorSelectorThemeProps = ThemeProps<\"ColorSelector\">\n\ntype ColorPickerContext = { value: string; styles: Record<string, CSSUIObject> }\n\nexport const [ColorPickerProvider, useColorPickerContext] =\n createContext<ColorPickerContext>({\n name: \"ColorPickerContext\",\n errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorPicker />\"`,\n })\n\ntype UseColorPickerOptions = {\n /**\n * The initial value of the color selector.\n */\n defaultColor?: string\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * A callback function to format the input entered.\n */\n formatInput?: (value: string) => string\n /**\n * If `true`, display the result component.\n *\n * @default false\n */\n withResult?: boolean\n /**\n * If `true` display the eye dropper component.\n *\n * @default false\n */\n withColorSelectorEyeDropper?: boolean\n /**\n * If `true`, the color swatch will be closed when value is selected.\n */\n closeOnSelectSwatch?: boolean\n /**\n * Variant for the color selector component.\n */\n colorSelectorVariant?: ColorSelectorThemeProps[\"variant\"]\n /**\n * Size for the color selector component.\n */\n colorSelectorSize?: ColorSelectorThemeProps[\"size\"]\n /**\n * ColorScheme for the color selector component.\n */\n colorSelectorColorScheme?: ColorSelectorThemeProps[\"colorScheme\"]\n /**\n * Props for color selector component.\n */\n colorSelectorProps?: ColorSelectorProps\n}\n\nexport type UseColorPickerProps = Omit<\n HTMLUIProps<\"input\">,\n \"size\" | \"offset\" | \"value\" | \"defaultValue\" | \"onChange\" | \"children\"\n> &\n Omit<UseColorSelectorBaseProps, \"id\" | \"name\"> &\n Omit<\n PopoverProps,\n | \"initialFocusRef\"\n | \"closeOnButton\"\n | \"trigger\"\n | \"autoFocus\"\n | \"restoreFocus\"\n | \"openDelay\"\n | \"closeDelay\"\n | \"children\"\n > &\n Pick<\n ColorSelectorProps,\n | \"withPicker\"\n | \"withChannel\"\n | \"swatchesLabel\"\n | \"swatches\"\n | \"swatchesColumns\"\n > &\n UseColorPickerOptions\n\nexport const useColorPicker = ({\n value: valueProp,\n defaultValue,\n fallbackValue,\n defaultColor,\n onChange: onChangeProp,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n formatInput = (value) => value,\n closeOnBlur = true,\n closeOnEsc = true,\n placement = \"bottom-start\",\n duration = 0.2,\n isOpen: isOpenProp,\n defaultIsOpen,\n onOpen: onOpenProp,\n onClose: onCloseProp,\n allowInput = true,\n closeOnSelectSwatch,\n format,\n swatchesLabel,\n swatches,\n swatchesColumns,\n withPicker,\n withChannel,\n withResult = false,\n withColorSelectorEyeDropper = false,\n colorSelectorVariant,\n colorSelectorSize,\n colorSelectorColorScheme,\n ...rest\n}: UseColorPickerProps) => {\n rest = useFormControlProps(rest)\n\n const { \"aria-readonly\": _ariaReadonly, ...formControlProps } = pickObject(\n rest,\n formControlProperties,\n )\n const { disabled, readOnly } = formControlProps\n const [containerProps, inputProps] = splitObject<Dict, string>(\n omitObject(rest, [...popoverProperties]),\n layoutStyleProperties,\n )\n\n const containerRef = useRef<HTMLDivElement>(null)\n const fieldRef = useRef<HTMLInputElement>(null)\n\n const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } =\n useEyeDropper()\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const formatRef = useRef<ColorFormat>(\n format ?? calcFormat(value ?? defaultColor ?? \"\"),\n )\n const isInputFocused = useRef<boolean>(false)\n const [inputValue, setInputValue] = useState<string>(value ?? \"\")\n const {\n isOpen,\n onOpen: onInternalOpen,\n onClose: onInternalClose,\n } = useDisclosure({\n isOpen: isOpenProp,\n defaultIsOpen,\n onOpen: onOpenProp,\n onClose: onCloseProp,\n })\n const isColorSelectorFull = colorSelectorSize === \"full\"\n\n const onOpen = useCallback(() => {\n if (disabled || readOnly) return\n\n onInternalOpen()\n }, [onInternalOpen, disabled, readOnly])\n\n const onClose = useCallback(() => {\n if (!isOpen) return\n\n const next = convertColor(value, fallbackValue)(formatRef.current)\n\n setValue((prev) => (!next || prev === next ? prev : next))\n setInputValue(formatInput(next ?? \"\"))\n\n onInternalClose()\n }, [\n formatRef,\n isOpen,\n setValue,\n onInternalClose,\n value,\n formatInput,\n setInputValue,\n fallbackValue,\n ])\n\n const onContainerClick = useCallback(() => {\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputFocus = useCallback(() => {\n isInputFocused.current = true\n\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputBlur = useCallback(() => {\n isInputFocused.current = false\n }, [])\n\n const onContainerBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n\n if (isContains(containerRef.current, relatedTarget)) return\n\n if (!closeOnBlur) return\n\n if (isOpen) onClose()\n },\n [closeOnBlur, isOpen, onClose],\n )\n\n const onInputKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (ev.key === \" \") ev.key = ev.code\n\n if (disabled || readOnly) return\n\n const actions: Record<string, Function | undefined> = {\n Space: !isOpen ? onOpen : undefined,\n Enter: !isOpen ? onOpen : undefined,\n Escape: closeOnEsc ? onClose : undefined,\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n action()\n },\n [disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n const value = ev.target.value\n\n setInputValue(formatInput(value))\n setValue(value)\n },\n [setInputValue, formatInput, setValue],\n )\n\n const onColorSelectorChange = useCallback(\n (value: string) => {\n setValue(value)\n\n setTimeout(() => {\n if (!isInputFocused.current) setInputValue(formatInput(value))\n })\n },\n [setValue, formatInput],\n )\n\n const onEyeDropperClick = useCallback(\n async (ev: MouseEvent<HTMLButtonElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n try {\n const { sRGBHex } = (await onEyeDropperOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onColorSelectorChange(sRGBHex)\n onChangeEnd?.(sRGBHex)\n } catch {}\n },\n [onEyeDropperOpen, onColorSelectorChange, onChangeEnd],\n )\n\n useOutsideClick({\n ref: containerRef,\n handler: onClose,\n enabled: isOpen && closeOnBlur,\n })\n\n useUpdateEffect(() => {\n if (!format || !value) return\n\n formatRef.current = format\n\n const nextValue = convertColor(value, fallbackValue)(format)\n\n if (!nextValue) return\n\n setInputValue(formatInput(nextValue))\n setValue(nextValue)\n }, [format])\n\n useUpdateEffect(() => {\n if (isInputFocused.current || !valueProp) return\n\n setInputValue(formatInput(valueProp))\n }, [valueProp])\n\n const getPopoverProps = useCallback(\n (props?: PopoverProps): PopoverProps => ({\n matchWidth: isColorSelectorFull,\n ...rest,\n ...props,\n isOpen,\n onOpen,\n onClose,\n placement,\n duration,\n trigger: \"never\",\n closeOnButton: false,\n }),\n [isColorSelectorFull, duration, onClose, onOpen, placement, rest, isOpen],\n )\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(containerRef, ref),\n ...containerProps,\n ...props,\n ...formControlProps,\n onClick: handlerAll(props.onClick, rest.onClick, onContainerClick),\n onBlur: handlerAll(props.onBlur, rest.onBlur, onContainerBlur),\n }),\n [containerProps, formControlProps, onContainerBlur, onContainerClick, rest],\n )\n\n const getFieldProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(fieldRef, ref),\n tabIndex: !allowInput ? -1 : 0,\n ...inputProps,\n ...props,\n style: {\n ...props.style,\n ...(!allowInput ? { pointerEvents: \"none\" } : {}),\n },\n value: inputValue,\n \"data-active\": dataAttr(isOpen),\n \"aria-expanded\": dataAttr(isOpen),\n onFocus: handlerAll(props.onFocus, rest.onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, rest.onKeyDown, onInputKeyDown),\n onChange: handlerAll(props.onChange, onInputChange),\n onBlur: handlerAll(props.onFocus, onInputBlur),\n }),\n [\n allowInput,\n inputProps,\n inputValue,\n isOpen,\n rest,\n onInputFocus,\n onInputKeyDown,\n onInputChange,\n onInputBlur,\n ],\n )\n\n const getEyeDropperProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n disabled,\n \"aria-label\": \"Pick a color\",\n ...props,\n ref,\n style: { ...props.style, pointerEvents: readOnly ? \"none\" : undefined },\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick, readOnly],\n )\n\n const getSelectorProps = useCallback(\n (props?: ColorSelectorProps): ColorSelectorProps => ({\n ...formControlProps,\n ...props,\n value,\n defaultValue: defaultColor,\n fallbackValue,\n onChange: onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick: handlerAll(\n onSwatchClick,\n closeOnSelectSwatch ? onClose : undefined,\n ),\n format: formatRef.current,\n withPicker,\n withChannel,\n withResult,\n withEyeDropper: withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n variant: colorSelectorVariant,\n size: colorSelectorSize,\n colorScheme: colorSelectorColorScheme,\n }),\n [\n formControlProps,\n value,\n fallbackValue,\n defaultColor,\n onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n onClose,\n closeOnSelectSwatch,\n formatRef,\n withPicker,\n withChannel,\n withResult,\n withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n ],\n )\n\n return {\n value,\n eyeDropperSupported,\n allowInput,\n getPopoverProps,\n getContainerProps,\n getFieldProps,\n getSelectorProps,\n getEyeDropperProps,\n }\n}\n\nexport type UseColorPickerReturn = ReturnType<typeof useColorPicker>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsC;AAOtC,0BAGO;AACP,qBAAqD;AACrD,oCAAqC;AACrC,4BAA8B;AAC9B,6BAA8B;AAC9B,+BAAgC;AAEhC,mBAaO;AAEP,mBAA8C;AAQvC,IAAM,CAAC,qBAAqB,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AAA,IACf;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","_a"]}
@@ -3,7 +3,7 @@ import {
3
3
  ColorPickerProvider,
4
4
  useColorPicker,
5
5
  useColorPickerContext
6
- } from "./chunk-SBN7FEOE.mjs";
6
+ } from "./chunk-PVPQQB6L.mjs";
7
7
  export {
8
8
  ColorPickerProvider,
9
9
  useColorPicker,
@@ -34,21 +34,16 @@ var import_react = require("react");
34
34
  var convertHsla = (value, fallback) => {
35
35
  var _a;
36
36
  let [h, s, l, a] = (_a = (0, import_utils.parseToHsla)(value, fallback)) != null ? _a : [0, 0, 1, 1];
37
- if (a > 1)
38
- a = 1;
37
+ if (a > 1) a = 1;
39
38
  return { h, s, l, a };
40
39
  };
41
40
  var convertRgba = (value, fallback) => {
42
41
  var _a;
43
42
  let [r, g, b, a] = (_a = (0, import_utils.parseToRgba)(value, fallback)) != null ? _a : [255, 255, 255, 1];
44
- if (r > 255)
45
- r = 255;
46
- if (g > 255)
47
- g = 255;
48
- if (b > 255)
49
- b = 255;
50
- if (a > 1)
51
- a = 1;
43
+ if (r > 255) r = 255;
44
+ if (g > 255) g = 255;
45
+ if (b > 255) b = 255;
46
+ if (a > 1) a = 1;
52
47
  return { r, g, b, a };
53
48
  };
54
49
  var convertHsva = (value, fallback) => {
@@ -168,8 +163,7 @@ var useColorSelector = ({
168
163
  isDraggingRef.current = true;
169
164
  const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
170
165
  const nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
171
- if (nextValue)
172
- onChangeStartRef(nextValue);
166
+ if (nextValue) onChangeStartRef(nextValue);
173
167
  },
174
168
  [formatRef, onChangeStartRef, fallbackValue, parsedValue]
175
169
  );
@@ -186,18 +180,15 @@ var useColorSelector = ({
186
180
  const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
187
181
  nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
188
182
  }
189
- if (nextValue)
190
- onChangeEndRef(nextValue);
183
+ if (nextValue) onChangeEndRef(nextValue);
191
184
  },
192
185
  [formatRef, onChangeEndRef, fallbackValue, parsedValue]
193
186
  );
194
187
  const onChannelChange = (0, import_react.useCallback)(
195
188
  (ev, space) => {
196
189
  let n = Math.floor(parseFloat(ev.target.value));
197
- if (isNaN(n))
198
- n = 0;
199
- if (["s", "l", "a"].includes(space))
200
- n = n / 100;
190
+ if (isNaN(n)) n = 0;
191
+ if (["s", "l", "a"].includes(space)) n = n / 100;
201
192
  let nextValue;
202
193
  if (resolvedValue.startsWith("hsl")) {
203
194
  const { h: h2, s: s2, l, a: a2 } = Object.assign(
@@ -212,8 +203,7 @@ var useColorSelector = ({
212
203
  );
213
204
  nextValue = (0, import_utils.rgbaTo)([r, g, b, a2], fallbackValue)(formatRef.current);
214
205
  }
215
- if (!nextValue)
216
- return;
206
+ if (!nextValue) return;
217
207
  onChange(nextValue);
218
208
  onChangeEnd(nextValue);
219
209
  },
@@ -223,8 +213,7 @@ var useColorSelector = ({
223
213
  var _a;
224
214
  try {
225
215
  const { sRGBHex } = (_a = await onOpen()) != null ? _a : {};
226
- if (!sRGBHex)
227
- return;
216
+ if (!sRGBHex) return;
228
217
  onChange(sRGBHex);
229
218
  onChangeEnd(sRGBHex);
230
219
  } catch {
@@ -232,22 +221,17 @@ var useColorSelector = ({
232
221
  }, [onOpen, onChange, onChangeEnd]);
233
222
  (0, import_utils.useUpdateEffect)(() => {
234
223
  const nextValue = (0, import_utils.hsvTo)([h, s, v, a], fallbackValue)(formatRef.current);
235
- if (nextValue)
236
- setValue(nextValue);
224
+ if (nextValue) setValue(nextValue);
237
225
  }, [h, s, v, a]);
238
226
  (0, import_utils.useUpdateEffect)(() => {
239
- if (isDraggingRef.current)
240
- return;
241
- if (valueProp)
242
- setParsedValue(convertHsva(valueProp, fallbackValue));
227
+ if (isDraggingRef.current) return;
228
+ if (valueProp) setParsedValue(convertHsva(valueProp, fallbackValue));
243
229
  }, [valueProp]);
244
230
  (0, import_utils.useUpdateEffect)(() => {
245
- if (!format || !value)
246
- return;
231
+ if (!format || !value) return;
247
232
  formatRef.current = format;
248
233
  const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
249
- if (nextValue)
250
- setValue(nextValue);
234
+ if (nextValue) setValue(nextValue);
251
235
  }, [format]);
252
236
  const getContainerProps = (props2 = {}, ref = null) => ({
253
237
  ...props2,
@@ -399,8 +383,7 @@ var useColorSelector = ({
399
383
  ref,
400
384
  color,
401
385
  onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
402
- if (!color)
403
- return;
386
+ if (!color) return;
404
387
  onSwatchClick == null ? void 0 : onSwatchClick(color);
405
388
  onChange(color);
406
389
  onChangeEnd(color);