@easyv/react-components 0.1.0 → 0.2.1

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 (78) hide show
  1. package/dist/BlurInput/index.d.ts +12 -0
  2. package/dist/BlurInput/index.js +58 -0
  3. package/dist/ColorsPicker/ControlBar.d.ts +9 -0
  4. package/dist/ColorsPicker/ControlBar.js +75 -0
  5. package/dist/ColorsPicker/History.d.ts +7 -0
  6. package/dist/ColorsPicker/History.js +53 -0
  7. package/dist/ColorsPicker/HistoryLinear.d.ts +6 -0
  8. package/dist/ColorsPicker/HistoryLinear.js +36 -0
  9. package/dist/ColorsPicker/HistoryPure.d.ts +5 -0
  10. package/dist/ColorsPicker/HistoryPure.js +28 -0
  11. package/dist/ColorsPicker/LinearColorPicker/LinearColorInput.d.ts +8 -0
  12. package/dist/ColorsPicker/LinearColorPicker/LinearColorInput.js +50 -0
  13. package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.d.ts +8 -0
  14. package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.js +89 -0
  15. package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.d.ts +10 -0
  16. package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.js +156 -0
  17. package/dist/ColorsPicker/LinearColorPicker/index.d.ts +2 -0
  18. package/dist/ColorsPicker/LinearColorPicker/index.js +2 -0
  19. package/dist/ColorsPicker/LinearColorPicker/useHistory.d.ts +4 -0
  20. package/dist/ColorsPicker/LinearColorPicker/useHistory.js +32 -0
  21. package/dist/ColorsPicker/MixedColorPicker/ColorTypeTab.d.ts +8 -0
  22. package/dist/ColorsPicker/MixedColorPicker/ColorTypeTab.js +30 -0
  23. package/dist/ColorsPicker/MixedColorPicker/MixedPanel.d.ts +9 -0
  24. package/dist/ColorsPicker/MixedColorPicker/MixedPanel.js +76 -0
  25. package/dist/ColorsPicker/MixedColorPicker/index.d.ts +1 -0
  26. package/dist/ColorsPicker/MixedColorPicker/index.js +1 -0
  27. package/dist/ColorsPicker/Palette.d.ts +8 -0
  28. package/dist/ColorsPicker/Palette.js +43 -0
  29. package/dist/ColorsPicker/Panel.d.ts +7 -0
  30. package/dist/ColorsPicker/Panel.js +258 -0
  31. package/dist/ColorsPicker/PanelContainer.d.ts +6 -0
  32. package/dist/ColorsPicker/PanelContainer.js +8 -0
  33. package/dist/ColorsPicker/PureColorPicker/PureColorInput.d.ts +7 -0
  34. package/dist/ColorsPicker/PureColorPicker/PureColorInput.js +61 -0
  35. package/dist/ColorsPicker/PureColorPicker/PureColorPanel.d.ts +8 -0
  36. package/dist/ColorsPicker/PureColorPicker/PureColorPanel.js +42 -0
  37. package/dist/ColorsPicker/PureColorPicker/index.d.ts +2 -0
  38. package/dist/ColorsPicker/PureColorPicker/index.js +2 -0
  39. package/dist/ColorsPicker/PureColorPicker/useHistory.d.ts +4 -0
  40. package/dist/ColorsPicker/PureColorPicker/useHistory.js +32 -0
  41. package/dist/ColorsPicker/PuresColorPicker/PuresCards.d.ts +10 -0
  42. package/dist/ColorsPicker/PuresColorPicker/PuresCards.js +40 -0
  43. package/dist/ColorsPicker/PuresColorPicker/PuresColorInput.d.ts +7 -0
  44. package/dist/ColorsPicker/PuresColorPicker/PuresColorInput.js +20 -0
  45. package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.d.ts +8 -0
  46. package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.js +90 -0
  47. package/dist/ColorsPicker/PuresColorPicker/index.d.ts +3 -0
  48. package/dist/ColorsPicker/PuresColorPicker/index.js +3 -0
  49. package/dist/ColorsPicker/PuresColorPicker/useHistory.d.ts +5 -0
  50. package/dist/ColorsPicker/PuresColorPicker/useHistory.js +34 -0
  51. package/dist/ColorsPicker/RangeColorPicker/RangeColorInput.d.ts +7 -0
  52. package/dist/ColorsPicker/RangeColorPicker/RangeColorInput.js +19 -0
  53. package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.d.ts +8 -0
  54. package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.js +67 -0
  55. package/dist/ColorsPicker/RangeColorPicker/RangePointBar.d.ts +8 -0
  56. package/dist/ColorsPicker/RangeColorPicker/RangePointBar.js +63 -0
  57. package/dist/ColorsPicker/RangeColorPicker/index.d.ts +2 -0
  58. package/dist/ColorsPicker/RangeColorPicker/index.js +2 -0
  59. package/dist/ColorsPicker/common/Preview.d.ts +11 -0
  60. package/dist/ColorsPicker/common/Preview.js +60 -0
  61. package/dist/ColorsPicker/hooks/useColorsPicker.d.ts +2 -0
  62. package/dist/ColorsPicker/hooks/useColorsPicker.js +106 -0
  63. package/dist/ColorsPicker/hooks/useControlBlock.d.ts +12 -0
  64. package/dist/ColorsPicker/hooks/useControlBlock.js +69 -0
  65. package/dist/ColorsPicker/hooks/useLocalstorageRef.d.ts +3 -0
  66. package/dist/ColorsPicker/hooks/useLocalstorageRef.js +11 -0
  67. package/dist/ColorsPicker/index.d.ts +4 -0
  68. package/dist/ColorsPicker/index.js +199 -0
  69. package/dist/ColorsPicker/interface.d.ts +59 -0
  70. package/dist/ColorsPicker/interface.js +1 -0
  71. package/dist/ColorsPicker/style/index.less +515 -0
  72. package/dist/ColorsPicker/utils.d.ts +29 -0
  73. package/dist/ColorsPicker/utils.js +233 -0
  74. package/dist/global.d.ts +13 -0
  75. package/dist/hooks/index.d.ts +3 -0
  76. package/dist/index.d.ts +2 -0
  77. package/dist/index.js +1 -2
  78. package/package.json +12 -9
@@ -0,0 +1,32 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useRef } from 'react';
8
+ import { useUpdateEffect } from 'ahooks';
9
+ import useLocalstorageRef from "../hooks/useLocalstorageRef";
10
+ export default function useHistory(_ref) {
11
+ var value = _ref.value;
12
+ var _useLocalstorageRef = useLocalstorageRef('usedColors'),
13
+ _useLocalstorageRef2 = _slicedToArray(_useLocalstorageRef, 2),
14
+ usedPureColors = _useLocalstorageRef2[0],
15
+ setUsedPureColors = _useLocalstorageRef2[1];
16
+ var lastValueRef = useRef();
17
+
18
+ // 记录上一次的值
19
+ useUpdateEffect(function () {
20
+ lastValueRef.current = value;
21
+ }, [value]);
22
+ useEffect(function () {
23
+ return function () {
24
+ if (lastValueRef.current) {
25
+ var newColors = [lastValueRef.current].concat(usedPureColors.current || []);
26
+ newColors = Array.from(new Set(newColors)).slice(0, 16);
27
+ setUsedPureColors(newColors);
28
+ }
29
+ };
30
+ }, []);
31
+ return null;
32
+ }
@@ -0,0 +1,10 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface PuresCardsProps {
3
+ active: number;
4
+ value: ColorValueMap['pures'];
5
+ onAdd: () => void;
6
+ onDelete: () => void;
7
+ onSelect: (current: number) => void;
8
+ }
9
+ export default function PuresCards({ active, value, onAdd, onDelete, onSelect, }: PuresCardsProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,40 @@
1
+ import { useKeyPress } from 'ahooks';
2
+ import { PlusOutlined } from '@easyv/react-icons';
3
+ import { classPrefix } from '.';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ export default function PuresCards(_ref) {
7
+ var active = _ref.active,
8
+ value = _ref.value,
9
+ onAdd = _ref.onAdd,
10
+ onDelete = _ref.onDelete,
11
+ onSelect = _ref.onSelect;
12
+ useKeyPress('Backspace', function (e) {
13
+ e.stopImmediatePropagation();
14
+
15
+ // 过滤掉表单的删除
16
+ if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
17
+ return;
18
+ }
19
+ onDelete();
20
+ });
21
+ return /*#__PURE__*/_jsxs("div", {
22
+ className: "".concat(classPrefix, "-cards"),
23
+ children: [value.map(function (d, i) {
24
+ return /*#__PURE__*/_jsx("div", {
25
+ className: "".concat(classPrefix, "-card"),
26
+ onClick: function onClick() {
27
+ return onSelect(i);
28
+ },
29
+ style: {
30
+ backgroundColor: d,
31
+ borderColor: active === i ? '#fff' : 'transparent'
32
+ }
33
+ }, "".concat(d, "_").concat(i));
34
+ }), /*#__PURE__*/_jsx("div", {
35
+ className: "".concat(classPrefix, "-add"),
36
+ onClick: onAdd,
37
+ children: /*#__PURE__*/_jsx(PlusOutlined, {})
38
+ })]
39
+ });
40
+ }
@@ -0,0 +1,7 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface PuresColorInputProps {
3
+ value: ColorValueMap['pures'];
4
+ onTrigger: () => void;
5
+ }
6
+ export default function PuresColorInput({ value, onTrigger, }: PuresColorInputProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,20 @@
1
+ import { classPrefix } from '.';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export default function PuresColorInput(_ref) {
4
+ var value = _ref.value,
5
+ onTrigger = _ref.onTrigger;
6
+ // 拼接多色的分段背景色
7
+ var str = value.map(function (color, i) {
8
+ return "".concat(color, " ").concat(i / value.length * 100, "%, ").concat(color, " ").concat((i + 1) / value.length * 100, "%");
9
+ }).join(', ');
10
+ return /*#__PURE__*/_jsx("div", {
11
+ className: "".concat(classPrefix, "-trigger"),
12
+ onClick: onTrigger,
13
+ children: /*#__PURE__*/_jsx("div", {
14
+ className: "".concat(classPrefix, "-trigger-color"),
15
+ style: {
16
+ backgroundImage: "linear-gradient(to right, ".concat(str, ")")
17
+ }
18
+ })
19
+ });
20
+ }
@@ -0,0 +1,8 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface PuresColorPanelProps {
3
+ value: ColorValueMap['pures'];
4
+ onChange?: (value: ColorValueMap['pures']) => void;
5
+ onChangeComplete?: (value: ColorValueMap['pures']) => void;
6
+ }
7
+ export default function PuresColorPanel({ value, onChange, onChangeComplete, }: PuresColorPanelProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,90 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { useState } from 'react';
12
+ import Panel from "../Panel";
13
+ import History from "../History";
14
+ import PuresCards from "./PuresCards";
15
+ import useHistory from "./useHistory";
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { Fragment as _Fragment } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ export default function PuresColorPanel(_ref) {
20
+ var value = _ref.value,
21
+ onChange = _ref.onChange,
22
+ onChangeComplete = _ref.onChangeComplete;
23
+ var _useState = useState(0),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ currentIndex = _useState2[0],
26
+ setCurrentIndex = _useState2[1];
27
+ var _useState3 = useState(0),
28
+ _useState4 = _slicedToArray(_useState3, 2),
29
+ updateKey = _useState4[0],
30
+ setUpdateKey = _useState4[1];
31
+ useHistory({
32
+ value: value,
33
+ active: currentIndex
34
+ });
35
+ var handleChange = function handleChange(color) {
36
+ var newValue = _toConsumableArray(value);
37
+ newValue[currentIndex] = color;
38
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
39
+ };
40
+ var handleChangeComplete = function handleChangeComplete(color) {
41
+ var newValue = _toConsumableArray(value);
42
+ newValue[currentIndex] = color;
43
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValue);
44
+ };
45
+ var handleAdd = function handleAdd() {
46
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.concat('#000000'));
47
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(value.concat('#000000'));
48
+ setCurrentIndex(value.length);
49
+ setUpdateKey(updateKey + 1);
50
+ };
51
+ var handleDelete = function handleDelete() {
52
+ if (value.length > 1) {
53
+ onChange === null || onChange === void 0 ? void 0 : onChange(value.filter(function (_, index) {
54
+ return index !== currentIndex;
55
+ }));
56
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(value.filter(function (_, index) {
57
+ return index !== currentIndex;
58
+ }));
59
+ setCurrentIndex(currentIndex > 0 ? currentIndex - 1 : 0);
60
+ setUpdateKey(updateKey + 1);
61
+ }
62
+ };
63
+ var handleSelect = function handleSelect(index) {
64
+ setCurrentIndex(index);
65
+ setUpdateKey(updateKey + 1);
66
+ };
67
+ var handleHistorySelect = function handleHistorySelect(val) {
68
+ var newValue = _toConsumableArray(value);
69
+ newValue[currentIndex] = val;
70
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
71
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValue);
72
+ setUpdateKey(updateKey + 1);
73
+ };
74
+ return /*#__PURE__*/_jsxs(_Fragment, {
75
+ children: [/*#__PURE__*/_jsx(PuresCards, {
76
+ active: currentIndex,
77
+ value: value,
78
+ onAdd: handleAdd,
79
+ onDelete: handleDelete,
80
+ onSelect: handleSelect
81
+ }), /*#__PURE__*/_jsx(Panel, {
82
+ color: value[currentIndex],
83
+ onChange: handleChange,
84
+ onChangeComplete: handleChangeComplete
85
+ }, updateKey), /*#__PURE__*/_jsx(History, {
86
+ type: "pure",
87
+ onSelect: handleHistorySelect
88
+ })]
89
+ });
90
+ }
@@ -0,0 +1,3 @@
1
+ export declare const classPrefix = "pures-color-picker";
2
+ export { default as PuresColorInput } from './PuresColorInput';
3
+ export { default as PuresColorPanel } from './PuresColorPanel';
@@ -0,0 +1,3 @@
1
+ export var classPrefix = 'pures-color-picker';
2
+ export { default as PuresColorInput } from "./PuresColorInput";
3
+ export { default as PuresColorPanel } from "./PuresColorPanel";
@@ -0,0 +1,5 @@
1
+ import { ColorValueMap } from '../interface';
2
+ export default function useHistory({ value, active, }: {
3
+ value: ColorValueMap['pures'];
4
+ active: number;
5
+ }): null;
@@ -0,0 +1,34 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useRef } from 'react';
8
+ import { useUpdateEffect } from 'ahooks';
9
+ import useLocalstorageRef from "../hooks/useLocalstorageRef";
10
+ export default function useHistory(_ref) {
11
+ var value = _ref.value,
12
+ active = _ref.active;
13
+ var _useLocalstorageRef = useLocalstorageRef('usedColors'),
14
+ _useLocalstorageRef2 = _slicedToArray(_useLocalstorageRef, 2),
15
+ usedPureColors = _useLocalstorageRef2[0],
16
+ setUsedPureColors = _useLocalstorageRef2[1];
17
+ var lastValueRef = useRef();
18
+
19
+ // 记录上一次的值
20
+ useUpdateEffect(function () {
21
+ lastValueRef.current = value;
22
+ }, [value]);
23
+ useEffect(function () {
24
+ return function () {
25
+ if (lastValueRef.current) {
26
+ var newColors = [lastValueRef.current[active]].concat(usedPureColors.current || []);
27
+ newColors = Array.from(new Set(newColors)).slice(0, 16);
28
+ setUsedPureColors(newColors);
29
+ lastValueRef.current = undefined;
30
+ }
31
+ };
32
+ }, [active]);
33
+ return null;
34
+ }
@@ -0,0 +1,7 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface RangeColorInputProps {
3
+ value: ColorValueMap['range'];
4
+ onTrigger: () => void;
5
+ }
6
+ export default function RangeColorInput({ value, onTrigger, }: RangeColorInputProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,19 @@
1
+ import Preview from "../common/Preview";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export default function RangeColorInput(_ref) {
4
+ var value = _ref.value,
5
+ onTrigger = _ref.onTrigger;
6
+ return /*#__PURE__*/_jsx("div", {
7
+ className: "pure-color-picker-preview",
8
+ style: {
9
+ width: '100%'
10
+ },
11
+ onClick: onTrigger,
12
+ children: /*#__PURE__*/_jsx(Preview, {
13
+ type: "range",
14
+ shape: "square",
15
+ color: value,
16
+ size: '100%'
17
+ })
18
+ });
19
+ }
@@ -0,0 +1,8 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface RangeColorPanelProps {
3
+ value: ColorValueMap['range'];
4
+ onChange?: (value: ColorValueMap['range']) => void;
5
+ onChangeComplete?: (value: ColorValueMap['range']) => void;
6
+ }
7
+ export default function RangeColorPanel({ value, onChange, onChangeComplete, }: RangeColorPanelProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,67 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { useState } from 'react';
12
+ import Panel from "../Panel";
13
+ import History from "../History";
14
+ import RangePointsBar from "./RangePointBar";
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { Fragment as _Fragment } from "react/jsx-runtime";
17
+ import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ export default function RangeColorPanel(_ref) {
19
+ var value = _ref.value,
20
+ onChange = _ref.onChange,
21
+ onChangeComplete = _ref.onChangeComplete;
22
+ var _useState = useState(0),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ currentIndex = _useState2[0],
25
+ setCurrentIndex = _useState2[1];
26
+ var _useState3 = useState(0),
27
+ _useState4 = _slicedToArray(_useState3, 2),
28
+ updateKey = _useState4[0],
29
+ setUpdateKey = _useState4[1];
30
+ var handleChange = function handleChange(newValue, complete) {
31
+ var newValueArray = _toConsumableArray(value);
32
+ newValueArray[currentIndex] = newValue;
33
+ if (complete) {
34
+ onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(newValueArray);
35
+ } else {
36
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValueArray);
37
+ }
38
+ };
39
+ var handleSelect = function handleSelect(val) {
40
+ handleChange(val, true);
41
+ setUpdateKey(function (prev) {
42
+ return prev + 1;
43
+ });
44
+ };
45
+ var handleIndexSelect = function handleIndexSelect(index) {
46
+ setCurrentIndex(index);
47
+ setUpdateKey(function (prev) {
48
+ return prev + 1;
49
+ });
50
+ };
51
+ return /*#__PURE__*/_jsxs(_Fragment, {
52
+ children: [/*#__PURE__*/_jsx(RangePointsBar, {
53
+ active: currentIndex,
54
+ value: value,
55
+ onSelect: handleIndexSelect
56
+ }), /*#__PURE__*/_jsx(Panel, {
57
+ color: value[currentIndex],
58
+ onChange: handleChange,
59
+ onChangeComplete: function onChangeComplete(val) {
60
+ return handleChange(val, true);
61
+ }
62
+ }, updateKey), /*#__PURE__*/_jsx(History, {
63
+ type: "pure",
64
+ onSelect: handleSelect
65
+ })]
66
+ });
67
+ }
@@ -0,0 +1,8 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface RangePointsBarProps {
3
+ active: number;
4
+ value: ColorValueMap['range'];
5
+ onSelect: (current: number) => void;
6
+ }
7
+ export default function RangePointsBar({ active, value, onSelect, }: RangePointsBarProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,63 @@
1
+ import { SwapOutlined } from '@easyv/react-icons';
2
+ import classNames from 'classnames';
3
+ import { getLinearGradientStyle } from "../utils";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ export default function RangePointsBar(_ref) {
7
+ var active = _ref.active,
8
+ value = _ref.value,
9
+ onSelect = _ref.onSelect;
10
+ return /*#__PURE__*/_jsxs("div", {
11
+ className: "colors-picker-linear-points-bar-wrapper",
12
+ children: [/*#__PURE__*/_jsxs("div", {
13
+ className: "colors-picker-linear-points-bar",
14
+ children: [/*#__PURE__*/_jsx("div", {
15
+ className: "colors-picker-points-bar-prev-half",
16
+ style: {
17
+ backgroundColor: value[0]
18
+ }
19
+ }), /*#__PURE__*/_jsx("div", {
20
+ className: "colors-picker-points-bar-next-half",
21
+ style: {
22
+ backgroundColor: value[1]
23
+ }
24
+ }), /*#__PURE__*/_jsx("div", {}), /*#__PURE__*/_jsxs("div", {
25
+ className: "colors-picker-linear-points-bar-color",
26
+ style: getLinearGradientStyle({
27
+ stops: value.map(function (d, i) {
28
+ return {
29
+ offset: i === 0 ? 0 : 100,
30
+ color: d
31
+ };
32
+ }),
33
+ angle: 90,
34
+ opacity: 1
35
+ }),
36
+ children: [/*#__PURE__*/_jsx("div", {
37
+ className: classNames('colors-picker-linear-point', {
38
+ active: active
39
+ }),
40
+ style: {
41
+ left: '0%'
42
+ },
43
+ onClick: function onClick() {
44
+ return onSelect(0);
45
+ }
46
+ }), /*#__PURE__*/_jsx("div", {
47
+ className: classNames('colors-picker-linear-point', {
48
+ active: active
49
+ }),
50
+ style: {
51
+ left: '100%'
52
+ },
53
+ onClick: function onClick() {
54
+ return onSelect(1);
55
+ }
56
+ })]
57
+ })]
58
+ }), /*#__PURE__*/_jsx("div", {
59
+ className: "colors-picker-linear-points-switch",
60
+ children: /*#__PURE__*/_jsx(SwapOutlined, {})
61
+ })]
62
+ });
63
+ }
@@ -0,0 +1,2 @@
1
+ export { default as RangeColorInput } from './RangeColorInput';
2
+ export { default as RangeColorPanel } from './RangeColorPanel';
@@ -0,0 +1,2 @@
1
+ export { default as RangeColorInput } from "./RangeColorInput";
2
+ export { default as RangeColorPanel } from "./RangeColorPanel";
@@ -0,0 +1,11 @@
1
+ import { ColorType, ColorValueMap } from '../interface';
2
+ interface PreviewProps<T extends ColorType> {
3
+ type: T;
4
+ color: ColorValueMap[T];
5
+ size?: number | string;
6
+ shape?: 'circle' | 'square';
7
+ border?: boolean;
8
+ onClick?: () => void;
9
+ }
10
+ export default function Preview<T extends ColorType>({ type, color, size, shape, border, onClick, }: PreviewProps<T>): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,60 @@
1
+ import classNames from 'classnames';
2
+ import { getLinearGradientStyle } from "../utils";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export default function Preview(_ref) {
5
+ var type = _ref.type,
6
+ color = _ref.color,
7
+ _ref$size = _ref.size,
8
+ size = _ref$size === void 0 ? 20 : _ref$size,
9
+ _ref$shape = _ref.shape,
10
+ shape = _ref$shape === void 0 ? 'circle' : _ref$shape,
11
+ border = _ref.border,
12
+ onClick = _ref.onClick;
13
+ // 处理不同类型的背景色
14
+ var getColorStyle = function getColorStyle() {
15
+ switch (type) {
16
+ case 'pure':
17
+ {
18
+ return {
19
+ backgroundColor: color
20
+ };
21
+ }
22
+ case 'linear':
23
+ {
24
+ return getLinearGradientStyle(color);
25
+ }
26
+ case 'range':
27
+ {
28
+ var linearValue = {
29
+ stops: [{
30
+ offset: 0,
31
+ color: color[0]
32
+ }, {
33
+ offset: 100,
34
+ color: color[1]
35
+ }],
36
+ angle: 90,
37
+ opacity: 1
38
+ };
39
+ return getLinearGradientStyle(linearValue);
40
+ }
41
+ default:
42
+ return {};
43
+ }
44
+ };
45
+ return /*#__PURE__*/_jsx("div", {
46
+ className: classNames('colors-picker-preview', "colors-picker-preview-".concat(shape), {
47
+ 'colors-picker-preview-border': border
48
+ }),
49
+ style: {
50
+ width: size,
51
+ height: size,
52
+ cursor: onClick ? 'pointer' : 'default'
53
+ },
54
+ onClick: onClick,
55
+ children: /*#__PURE__*/_jsx("div", {
56
+ className: "colors-picker-preview-color",
57
+ style: getColorStyle()
58
+ })
59
+ });
60
+ }
@@ -0,0 +1,2 @@
1
+ import { ColorsPickerProps, ColorsPickerType } from '../interface';
2
+ export default function useColorsPicker<T extends ColorsPickerType>(props: ColorsPickerProps<T>): ColorsPickerProps<T>;
@@ -0,0 +1,106 @@
1
+ var _excluded = ["type", "value", "onChange"];
2
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ import { useCallback, useEffect, useState } from 'react';
17
+ var defaultValues = {
18
+ pure: '#000000',
19
+ pures: ['#ffffff', '#000000'],
20
+ linear: {
21
+ stops: [{
22
+ color: '#ffffff',
23
+ offset: 0
24
+ }, {
25
+ color: '#000000',
26
+ offset: 100
27
+ }],
28
+ angle: 0,
29
+ opacity: 1
30
+ },
31
+ range: ['#ffffff', '#000000']
32
+ };
33
+ export default function useColorsPicker(props) {
34
+ var _props$type = props.type,
35
+ type = _props$type === void 0 ? 'pure' : _props$type,
36
+ value = props.value,
37
+ onChange = props.onChange,
38
+ rest = _objectWithoutProperties(props, _excluded);
39
+ var _useState = useState(value),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ localValue = _useState2[0],
42
+ setLocalValue = _useState2[1];
43
+ useEffect(function () {
44
+ setLocalValue(value);
45
+ }, [value]);
46
+ var handleChange = useCallback(function (val) {
47
+ setLocalValue(val);
48
+ onChange === null || onChange === void 0 ? void 0 : onChange(val);
49
+ }, [onChange]);
50
+ if (type === 'pure') {
51
+ if (!value || typeof value !== 'string') {
52
+ return _objectSpread(_objectSpread({}, rest), {}, {
53
+ type: type,
54
+ value: defaultValues.pure,
55
+ onChange: handleChange
56
+ });
57
+ }
58
+ } else if (type === 'pures') {
59
+ if (!value || !Array.isArray(value) || value.some(function (d) {
60
+ return typeof d !== 'string';
61
+ })) {
62
+ return _objectSpread(_objectSpread({}, rest), {}, {
63
+ type: type,
64
+ value: defaultValues.pures,
65
+ onChange: handleChange
66
+ });
67
+ }
68
+ } else if (type === 'linear') {
69
+ if (!value || _typeof(value) !== 'object') {
70
+ return _objectSpread(_objectSpread({}, rest), {}, {
71
+ type: type,
72
+ value: defaultValues.linear,
73
+ onChange: handleChange
74
+ });
75
+ }
76
+ } else if (Array.isArray(type)) {
77
+ if (!value || _typeof(value) !== 'object') {
78
+ return _objectSpread(_objectSpread({}, rest), {}, {
79
+ type: type,
80
+ value: type.reduce(function (all, cur) {
81
+ return all[cur] = defaultValues[cur];
82
+ }, {}),
83
+ onChange: handleChange
84
+ });
85
+ } else if (type.some(function (d) {
86
+ return !value[d];
87
+ })) {
88
+ // 检查每个子项的类型
89
+ var newValue = type.reduce(function (all, cur) {
90
+ all[cur] = value[cur] || defaultValues[cur];
91
+ return all;
92
+ }, {
93
+ type: value.type || 'pure'
94
+ });
95
+ return _objectSpread(_objectSpread({}, rest), {}, {
96
+ type: type,
97
+ value: newValue,
98
+ onChange: handleChange
99
+ });
100
+ }
101
+ }
102
+ return _objectSpread(_objectSpread({}, props), {}, {
103
+ value: localValue,
104
+ onChange: handleChange
105
+ });
106
+ }