@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
@@ -46,21 +46,16 @@ var import_react = require("react");
46
46
  var convertHsla = (value, fallback) => {
47
47
  var _a;
48
48
  let [h, s, l, a] = (_a = (0, import_utils.parseToHsla)(value, fallback)) != null ? _a : [0, 0, 1, 1];
49
- if (a > 1)
50
- a = 1;
49
+ if (a > 1) a = 1;
51
50
  return { h, s, l, a };
52
51
  };
53
52
  var convertRgba = (value, fallback) => {
54
53
  var _a;
55
54
  let [r, g, b, a] = (_a = (0, import_utils.parseToRgba)(value, fallback)) != null ? _a : [255, 255, 255, 1];
56
- if (r > 255)
57
- r = 255;
58
- if (g > 255)
59
- g = 255;
60
- if (b > 255)
61
- b = 255;
62
- if (a > 1)
63
- a = 1;
55
+ if (r > 255) r = 255;
56
+ if (g > 255) g = 255;
57
+ if (b > 255) b = 255;
58
+ if (a > 1) a = 1;
64
59
  return { r, g, b, a };
65
60
  };
66
61
  var convertHsva = (value, fallback) => {
@@ -180,8 +175,7 @@ var useColorSelector = ({
180
175
  isDraggingRef.current = true;
181
176
  const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
182
177
  const nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
183
- if (nextValue)
184
- onChangeStartRef(nextValue);
178
+ if (nextValue) onChangeStartRef(nextValue);
185
179
  },
186
180
  [formatRef, onChangeStartRef, fallbackValue, parsedValue]
187
181
  );
@@ -198,18 +192,15 @@ var useColorSelector = ({
198
192
  const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
199
193
  nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
200
194
  }
201
- if (nextValue)
202
- onChangeEndRef(nextValue);
195
+ if (nextValue) onChangeEndRef(nextValue);
203
196
  },
204
197
  [formatRef, onChangeEndRef, fallbackValue, parsedValue]
205
198
  );
206
199
  const onChannelChange = (0, import_react.useCallback)(
207
200
  (ev, space) => {
208
201
  let n = Math.floor(parseFloat(ev.target.value));
209
- if (isNaN(n))
210
- n = 0;
211
- if (["s", "l", "a"].includes(space))
212
- n = n / 100;
202
+ if (isNaN(n)) n = 0;
203
+ if (["s", "l", "a"].includes(space)) n = n / 100;
213
204
  let nextValue;
214
205
  if (resolvedValue.startsWith("hsl")) {
215
206
  const { h: h2, s: s2, l, a: a2 } = Object.assign(
@@ -224,8 +215,7 @@ var useColorSelector = ({
224
215
  );
225
216
  nextValue = (0, import_utils.rgbaTo)([r, g, b, a2], fallbackValue)(formatRef.current);
226
217
  }
227
- if (!nextValue)
228
- return;
218
+ if (!nextValue) return;
229
219
  onChange(nextValue);
230
220
  onChangeEnd(nextValue);
231
221
  },
@@ -235,8 +225,7 @@ var useColorSelector = ({
235
225
  var _a;
236
226
  try {
237
227
  const { sRGBHex } = (_a = await onOpen()) != null ? _a : {};
238
- if (!sRGBHex)
239
- return;
228
+ if (!sRGBHex) return;
240
229
  onChange(sRGBHex);
241
230
  onChangeEnd(sRGBHex);
242
231
  } catch {
@@ -244,22 +233,17 @@ var useColorSelector = ({
244
233
  }, [onOpen, onChange, onChangeEnd]);
245
234
  (0, import_utils.useUpdateEffect)(() => {
246
235
  const nextValue = (0, import_utils.hsvTo)([h, s, v, a], fallbackValue)(formatRef.current);
247
- if (nextValue)
248
- setValue(nextValue);
236
+ if (nextValue) setValue(nextValue);
249
237
  }, [h, s, v, a]);
250
238
  (0, import_utils.useUpdateEffect)(() => {
251
- if (isDraggingRef.current)
252
- return;
253
- if (valueProp)
254
- setParsedValue(convertHsva(valueProp, fallbackValue));
239
+ if (isDraggingRef.current) return;
240
+ if (valueProp) setParsedValue(convertHsva(valueProp, fallbackValue));
255
241
  }, [valueProp]);
256
242
  (0, import_utils.useUpdateEffect)(() => {
257
- if (!format || !value)
258
- return;
243
+ if (!format || !value) return;
259
244
  formatRef.current = format;
260
245
  const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
261
- if (nextValue)
262
- setValue(nextValue);
246
+ if (nextValue) setValue(nextValue);
263
247
  }, [format]);
264
248
  const getContainerProps = (props2 = {}, ref = null) => ({
265
249
  ...props2,
@@ -411,8 +395,7 @@ var useColorSelector = ({
411
395
  ref,
412
396
  color,
413
397
  onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
414
- if (!color)
415
- return;
398
+ if (!color) return;
416
399
  onSwatchClick == null ? void 0 : onSwatchClick(color);
417
400
  onChange(color);
418
401
  onChangeEnd(color);
@@ -500,8 +483,7 @@ var useColorSlider = ({
500
483
  focusThumbOnChange = true,
501
484
  ...props
502
485
  }) => {
503
- if (!focusThumbOnChange)
504
- props.isReadOnly = true;
486
+ if (!focusThumbOnChange) props.isReadOnly = true;
505
487
  let {
506
488
  id,
507
489
  name,
@@ -548,16 +530,14 @@ var useColorSlider = ({
548
530
  const getValueFromPointer = (0, import_react2.useCallback)(
549
531
  (ev) => {
550
532
  var _a, _b;
551
- if (!trackRef.current)
552
- return;
533
+ if (!trackRef.current) return;
553
534
  const { min: min2, max: max2, step: step2 } = latestRef.current;
554
535
  latestRef.current.eventSource = "pointer";
555
536
  const { left, width } = trackRef.current.getBoundingClientRect();
556
537
  const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
557
538
  let percent = (clientX - left) / width;
558
539
  let nextValue = (0, import_utils3.percentToValue)(percent, min2, max2);
559
- if (step2)
560
- nextValue = parseFloat((0, import_utils3.roundNumberToStep)(nextValue, min2, step2));
540
+ if (step2) nextValue = parseFloat((0, import_utils3.roundNumberToStep)(nextValue, min2, step2));
561
541
  nextValue = (0, import_utils3.clampNumber)(nextValue, min2, max2);
562
542
  return nextValue;
563
543
  },
@@ -566,22 +546,19 @@ var useColorSlider = ({
566
546
  const setValueFromPointer = (ev) => {
567
547
  const { value: value2 } = latestRef.current;
568
548
  const nextValue = getValueFromPointer(ev);
569
- if (nextValue != null && nextValue !== value2)
570
- setValue(nextValue);
549
+ if (nextValue != null && nextValue !== value2) setValue(nextValue);
571
550
  };
572
551
  const focusThumb = (0, import_react2.useCallback)(() => {
573
552
  const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
574
- if (focusThumbOnChange2)
575
- setTimeout(() => {
576
- var _a;
577
- return (_a = thumbRef.current) == null ? void 0 : _a.focus();
578
- });
553
+ if (focusThumbOnChange2) setTimeout(() => {
554
+ var _a;
555
+ return (_a = thumbRef.current) == null ? void 0 : _a.focus();
556
+ });
579
557
  }, [latestRef]);
580
558
  const constrain = (0, import_react2.useCallback)(
581
559
  (value2) => {
582
560
  const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
583
- if (!isInteractive2)
584
- return;
561
+ if (!isInteractive2) return;
585
562
  value2 = parseFloat((0, import_utils3.roundNumberToStep)(value2, min2, oneStep));
586
563
  value2 = (0, import_utils3.clampNumber)(value2, min2, max2);
587
564
  setValue(value2);
@@ -610,8 +587,7 @@ var useColorSlider = ({
610
587
  End: () => constrain(max2)
611
588
  };
612
589
  const action = actions[ev.key];
613
- if (!action)
614
- return;
590
+ if (!action) return;
615
591
  ev.preventDefault();
616
592
  ev.stopPropagation();
617
593
  action(ev);
@@ -622,8 +598,7 @@ var useColorSlider = ({
622
598
  (0, import_use_pan_event.usePanEvent)(containerRef, {
623
599
  onSessionStart: (ev) => {
624
600
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
625
- if (!isInteractive2)
626
- return;
601
+ if (!isInteractive2) return;
627
602
  setDragging(true);
628
603
  focusThumb();
629
604
  setValueFromPointer(ev);
@@ -631,22 +606,19 @@ var useColorSlider = ({
631
606
  },
632
607
  onSessionEnd: () => {
633
608
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
634
- if (!isInteractive2)
635
- return;
609
+ if (!isInteractive2) return;
636
610
  setDragging(false);
637
611
  onChangeEnd(value2);
638
612
  },
639
613
  onMove: (ev) => {
640
614
  const { isInteractive: isInteractive2 } = latestRef.current;
641
- if (!isInteractive2)
642
- return;
615
+ if (!isInteractive2) return;
643
616
  setValueFromPointer(ev);
644
617
  }
645
618
  });
646
619
  (0, import_utils3.useUpdateEffect)(() => {
647
620
  const { eventSource, value: value2 } = latestRef.current;
648
- if (eventSource === "keyboard")
649
- onChangeEnd(value2);
621
+ if (eventSource === "keyboard") onChangeEnd(value2);
650
622
  }, [value, onChangeEnd]);
651
623
  const getContainerProps = (0, import_react2.useCallback)(
652
624
  (props2 = {}, ref = null) => {
@@ -942,8 +914,7 @@ var ColorSelectorSliders = (0, import_core4.forwardRef)(
942
914
  ...rest
943
915
  }, ref) => {
944
916
  let { size, withAlpha, getHueSliderProps, getAlphaSliderProps, styles } = useColorSelectorContext();
945
- if (size === "full")
946
- size = "lg";
917
+ if (size === "full") size = "lg";
947
918
  const css = {
948
919
  ...styles.sliders
949
920
  };
@@ -1139,8 +1110,7 @@ var ColorSelectorChannels = (0, import_core7.forwardRef)(({ className, channelPr
1139
1110
  var ColorSelectorChannel = (0, import_core7.forwardRef)(({ className, channelLabel, ...rest }, ref) => {
1140
1111
  const id = (0, import_react3.useId)();
1141
1112
  let { size, disabled, readOnly, styles } = useColorSelectorContext();
1142
- if (size === "full")
1143
- size = "lg";
1113
+ if (size === "full") size = "lg";
1144
1114
  const css = { ...styles.channel };
1145
1115
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core7.ui.div, { className: (0, import_utils9.cx)("ui-color-selector__channel", className), children: [
1146
1116
  channelLabel ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -1247,8 +1217,7 @@ var useSaturationSlider = ({
1247
1217
  focusThumbOnChange = true,
1248
1218
  ...props
1249
1219
  }) => {
1250
- if (!focusThumbOnChange)
1251
- props.isReadOnly = true;
1220
+ if (!focusThumbOnChange) props.isReadOnly = true;
1252
1221
  let {
1253
1222
  id,
1254
1223
  name,
@@ -1296,8 +1265,7 @@ var useSaturationSlider = ({
1296
1265
  const getValueFromPointer = (0, import_react4.useCallback)(
1297
1266
  (ev) => {
1298
1267
  var _a, _b;
1299
- if (!trackRef.current)
1300
- return [];
1268
+ if (!trackRef.current) return [];
1301
1269
  const { step: step2 } = latestRef.current;
1302
1270
  latestRef.current.eventSource = "pointer";
1303
1271
  const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
@@ -1315,25 +1283,21 @@ var useSaturationSlider = ({
1315
1283
  const setValueFromPointer = (ev) => {
1316
1284
  const { value: value2 } = latestRef.current;
1317
1285
  const [nextS, nextV] = getValueFromPointer(ev);
1318
- if (nextS == null || nextV == null)
1319
- return;
1286
+ if (nextS == null || nextV == null) return;
1320
1287
  const [, s2, v2] = value2;
1321
- if (nextS !== s2 || nextV !== v2)
1322
- setValue(([h2]) => [h2, nextS, nextV]);
1288
+ if (nextS !== s2 || nextV !== v2) setValue(([h2]) => [h2, nextS, nextV]);
1323
1289
  };
1324
1290
  const focusThumb = (0, import_react4.useCallback)(() => {
1325
1291
  const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
1326
- if (focusThumbOnChange2)
1327
- setTimeout(() => {
1328
- var _a;
1329
- return (_a = thumbRef.current) == null ? void 0 : _a.focus();
1330
- });
1292
+ if (focusThumbOnChange2) setTimeout(() => {
1293
+ var _a;
1294
+ return (_a = thumbRef.current) == null ? void 0 : _a.focus();
1295
+ });
1331
1296
  }, [latestRef]);
1332
1297
  const constrain = (0, import_react4.useCallback)(
1333
1298
  ([s2, v2]) => {
1334
1299
  const { isInteractive: isInteractive2 } = latestRef.current;
1335
- if (!isInteractive2)
1336
- return;
1300
+ if (!isInteractive2) return;
1337
1301
  s2 = (0, import_utils11.clampNumber)(s2, 0, 1);
1338
1302
  v2 = (0, import_utils11.clampNumber)(v2, 0, 1);
1339
1303
  setValue(([h2]) => [h2, s2, v2]);
@@ -1349,8 +1313,7 @@ var useSaturationSlider = ({
1349
1313
  ArrowDown: () => constrain([s, v - step])
1350
1314
  };
1351
1315
  const action = actions[ev.key];
1352
- if (!action)
1353
- return;
1316
+ if (!action) return;
1354
1317
  ev.preventDefault();
1355
1318
  ev.stopPropagation();
1356
1319
  action(ev);
@@ -1361,8 +1324,7 @@ var useSaturationSlider = ({
1361
1324
  (0, import_use_pan_event2.usePanEvent)(containerRef, {
1362
1325
  onSessionStart: (ev) => {
1363
1326
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
1364
- if (!isInteractive2)
1365
- return;
1327
+ if (!isInteractive2) return;
1366
1328
  setDragging(true);
1367
1329
  focusThumb();
1368
1330
  setValueFromPointer(ev);
@@ -1370,22 +1332,19 @@ var useSaturationSlider = ({
1370
1332
  },
1371
1333
  onSessionEnd: () => {
1372
1334
  const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
1373
- if (!isInteractive2)
1374
- return;
1335
+ if (!isInteractive2) return;
1375
1336
  setDragging(false);
1376
1337
  onChangeEnd(value2);
1377
1338
  },
1378
1339
  onMove: (ev) => {
1379
1340
  const { isInteractive: isInteractive2 } = latestRef.current;
1380
- if (!isInteractive2)
1381
- return;
1341
+ if (!isInteractive2) return;
1382
1342
  setValueFromPointer(ev);
1383
1343
  }
1384
1344
  });
1385
1345
  (0, import_utils11.useUpdateEffect)(() => {
1386
1346
  const { eventSource, value: value2 } = latestRef.current;
1387
- if (eventSource === "keyboard")
1388
- onChangeEnd(value2);
1347
+ if (eventSource === "keyboard") onChangeEnd(value2);
1389
1348
  }, [value, onChangeEnd]);
1390
1349
  const getContainerProps = (0, import_react4.useCallback)(
1391
1350
  (props2 = {}, ref = null) => ({