@easyv/react-components 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +8 -0
  4. package/dist/ColorsPicker/ControlBar.js +67 -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 +7 -0
  14. package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.js +77 -0
  15. package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.d.ts +9 -0
  16. package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.js +140 -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 +8 -0
  24. package/dist/ColorsPicker/MixedColorPicker/MixedPanel.js +64 -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 +7 -0
  28. package/dist/ColorsPicker/Palette.js +39 -0
  29. package/dist/ColorsPicker/Panel.d.ts +6 -0
  30. package/dist/ColorsPicker/Panel.js +224 -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 +7 -0
  36. package/dist/ColorsPicker/PureColorPicker/PureColorPanel.js +39 -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 +7 -0
  46. package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.js +78 -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 +7 -0
  54. package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.js +59 -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 +25 -0
  62. package/dist/ColorsPicker/hooks/useColorsPicker.js +78 -0
  63. package/dist/ColorsPicker/hooks/useControlBlock.d.ts +11 -0
  64. package/dist/ColorsPicker/hooks/useControlBlock.js +61 -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 +182 -0
  69. package/dist/ColorsPicker/interface.d.ts +58 -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,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,7 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface PuresColorPanelProps {
3
+ value: ColorValueMap['pures'];
4
+ onChange: (value: ColorValueMap['pures']) => void;
5
+ }
6
+ export default function PuresColorPanel({ value, onChange, }: PuresColorPanelProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,78 @@
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
+ 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
+ useHistory({
31
+ value: value,
32
+ active: currentIndex
33
+ });
34
+ var handleChange = function handleChange(color) {
35
+ var newValue = _toConsumableArray(value);
36
+ newValue[currentIndex] = color;
37
+ onChange(newValue);
38
+ };
39
+ var handleAdd = function handleAdd() {
40
+ onChange(value.concat('#000000'));
41
+ setCurrentIndex(value.length);
42
+ setUpdateKey(updateKey + 1);
43
+ };
44
+ var handleDelete = function handleDelete() {
45
+ if (value.length > 1) {
46
+ onChange(value.filter(function (_, index) {
47
+ return index !== currentIndex;
48
+ }));
49
+ setCurrentIndex(currentIndex > 0 ? currentIndex - 1 : 0);
50
+ setUpdateKey(updateKey + 1);
51
+ }
52
+ };
53
+ var handleSelect = function handleSelect(index) {
54
+ setCurrentIndex(index);
55
+ setUpdateKey(updateKey + 1);
56
+ };
57
+ var handleHistorySelect = function handleHistorySelect(val) {
58
+ var newValue = _toConsumableArray(value);
59
+ newValue[currentIndex] = val;
60
+ onChange(newValue);
61
+ setUpdateKey(updateKey + 1);
62
+ };
63
+ return /*#__PURE__*/_jsxs(_Fragment, {
64
+ children: [/*#__PURE__*/_jsx(PuresCards, {
65
+ active: currentIndex,
66
+ value: value,
67
+ onAdd: handleAdd,
68
+ onDelete: handleDelete,
69
+ onSelect: handleSelect
70
+ }), /*#__PURE__*/_jsx(Panel, {
71
+ color: value[currentIndex],
72
+ onChange: handleChange
73
+ }, updateKey), /*#__PURE__*/_jsx(History, {
74
+ type: "pure",
75
+ onSelect: handleHistorySelect
76
+ })]
77
+ });
78
+ }
@@ -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,7 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface RangeColorPanelProps {
3
+ value: ColorValueMap['range'];
4
+ onChange: (value: ColorValueMap['range']) => void;
5
+ }
6
+ export default function RangeColorPanel({ value, onChange, }: RangeColorPanelProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,59 @@
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
+ var _useState = useState(0),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ currentIndex = _useState2[0],
24
+ setCurrentIndex = _useState2[1];
25
+ var _useState3 = useState(0),
26
+ _useState4 = _slicedToArray(_useState3, 2),
27
+ updateKey = _useState4[0],
28
+ setUpdateKey = _useState4[1];
29
+ var handleChange = function handleChange(newValue) {
30
+ var newValueArray = _toConsumableArray(value);
31
+ newValueArray[currentIndex] = newValue;
32
+ onChange(newValueArray);
33
+ setUpdateKey(function (prev) {
34
+ return prev + 1;
35
+ });
36
+ };
37
+ var handleSelect = function handleSelect(val) {
38
+ handleChange(val);
39
+ };
40
+ var handleIndexSelect = function handleIndexSelect(index) {
41
+ setCurrentIndex(index);
42
+ setUpdateKey(function (prev) {
43
+ return prev + 1;
44
+ });
45
+ };
46
+ return /*#__PURE__*/_jsxs(_Fragment, {
47
+ children: [/*#__PURE__*/_jsx(RangePointsBar, {
48
+ active: currentIndex,
49
+ value: value,
50
+ onSelect: handleIndexSelect
51
+ }), /*#__PURE__*/_jsx(Panel, {
52
+ color: value[currentIndex],
53
+ onChange: handleChange
54
+ }, updateKey), /*#__PURE__*/_jsx(History, {
55
+ type: "pure",
56
+ onSelect: handleSelect
57
+ })]
58
+ });
59
+ }
@@ -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,25 @@
1
+ import { ColorValueObj, ColorsPickerProps, ColorsPickerType } from '../interface';
2
+ export default function useColorsPicker<T extends ColorsPickerType>(props: ColorsPickerProps<T>): ColorsPickerProps<T> | {
3
+ type: string | T;
4
+ value: string;
5
+ onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
6
+ } | {
7
+ type: T;
8
+ value: string[];
9
+ onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
10
+ } | {
11
+ type: T;
12
+ value: {
13
+ stops: {
14
+ color: string;
15
+ offset: number;
16
+ }[];
17
+ angle: number;
18
+ opacity: number;
19
+ };
20
+ onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
21
+ } | {
22
+ type: T & any[];
23
+ value: {};
24
+ onChange: (value: T extends import("../interface").ColorType ? import("../interface").ColorValueMap[T] : ColorValueObj) => void;
25
+ };
@@ -0,0 +1,78 @@
1
+ var _excluded = ["type", "value"];
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 _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; }
9
+ 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; }
10
+ var defaultValues = {
11
+ pure: '#000000',
12
+ pures: ['#ffffff', '#000000'],
13
+ linear: {
14
+ stops: [{
15
+ color: '#ffffff',
16
+ offset: 0
17
+ }, {
18
+ color: '#000000',
19
+ offset: 100
20
+ }],
21
+ angle: 0,
22
+ opacity: 1
23
+ }
24
+ };
25
+ export default function useColorsPicker(props) {
26
+ var _props$type = props.type,
27
+ type = _props$type === void 0 ? 'pure' : _props$type,
28
+ value = props.value,
29
+ rest = _objectWithoutProperties(props, _excluded);
30
+ if (type === 'pure') {
31
+ if (!value || typeof value !== 'string') {
32
+ return _objectSpread(_objectSpread({}, rest), {}, {
33
+ type: type,
34
+ value: defaultValues.pure
35
+ });
36
+ }
37
+ } else if (type === 'pures') {
38
+ if (!value || !Array.isArray(value) || value.some(function (d) {
39
+ return typeof d !== 'string';
40
+ })) {
41
+ return _objectSpread(_objectSpread({}, rest), {}, {
42
+ type: type,
43
+ value: defaultValues.pures
44
+ });
45
+ }
46
+ } else if (type === 'linear') {
47
+ if (!value || _typeof(value) !== 'object') {
48
+ return _objectSpread(_objectSpread({}, rest), {}, {
49
+ type: type,
50
+ value: defaultValues.linear
51
+ });
52
+ }
53
+ } else if (Array.isArray(type)) {
54
+ if (!value || _typeof(value) !== 'object') {
55
+ return _objectSpread(_objectSpread({}, rest), {}, {
56
+ type: type,
57
+ value: type.reduce(function (all, cur) {
58
+ return all[cur] = defaultValues[cur];
59
+ }, {})
60
+ });
61
+ } else if (type.some(function (d) {
62
+ return !value[d];
63
+ })) {
64
+ // 检查每个子项的类型
65
+ var newValue = type.reduce(function (all, cur) {
66
+ all[cur] = value[cur] || defaultValues[cur];
67
+ return all;
68
+ }, {
69
+ type: value.type || 'pure'
70
+ });
71
+ return _objectSpread(_objectSpread({}, rest), {}, {
72
+ type: type,
73
+ value: newValue
74
+ });
75
+ }
76
+ }
77
+ return props;
78
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ interface UsePaletteControlProps {
3
+ value: [number, number];
4
+ onChange?: (value: [number, number], e: MouseEvent | React.MouseEvent, mousedownChange?: boolean) => void;
5
+ }
6
+ export declare function useControlBlock({ value, onChange }: UsePaletteControlProps): {
7
+ active: boolean;
8
+ blockRef: React.RefObject<HTMLDivElement>;
9
+ onMouseDown: (ev: React.MouseEvent) => void;
10
+ };
11
+ export {};
@@ -0,0 +1,61 @@
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 { useRef, useState } from 'react';
8
+ export function useControlBlock(_ref) {
9
+ var value = _ref.value,
10
+ onChange = _ref.onChange;
11
+ var _useState = useState(false),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ active = _useState2[0],
14
+ setActive = _useState2[1];
15
+ var blockRef = useRef(null);
16
+ var getPercentNumber = function getPercentNumber(value, max) {
17
+ if (value < 0) {
18
+ return 0;
19
+ }
20
+ if (value > max) {
21
+ return 1;
22
+ }
23
+ return value / max;
24
+ };
25
+ var setCurrentPosition = function setCurrentPosition(ev, mousedownChange) {
26
+ var clientX = ev.clientX,
27
+ clientY = ev.clientY;
28
+ var rect = blockRef.current.getBoundingClientRect();
29
+ var newValue = [getPercentNumber(clientX - rect.x, rect.width), getPercentNumber(clientY - rect.y, rect.height)];
30
+ if (newValue[0] !== value[0] || newValue[1] !== value[1]) {
31
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ev, mousedownChange);
32
+ }
33
+ };
34
+ function onMouseMove(ev) {
35
+ ev.preventDefault();
36
+ if (ev.buttons > 0) {
37
+ setCurrentPosition(ev);
38
+ } else {
39
+ removeListener();
40
+ }
41
+ }
42
+ var removeListener = function removeListener() {
43
+ setActive(false);
44
+ window.removeEventListener('mousemove', onMouseMove);
45
+ window.removeEventListener('mouseup', removeListener);
46
+ window.removeEventListener('contextmenu', removeListener);
47
+ };
48
+ var onMouseDown = function onMouseDown(ev) {
49
+ ev.stopPropagation();
50
+ setActive(true);
51
+ setCurrentPosition(ev, true);
52
+ window.addEventListener('mousemove', onMouseMove);
53
+ window.addEventListener('mouseup', removeListener);
54
+ window.addEventListener('contextmenu', removeListener);
55
+ };
56
+ return {
57
+ active: active,
58
+ blockRef: blockRef,
59
+ onMouseDown: onMouseDown
60
+ };
61
+ }
@@ -0,0 +1,3 @@
1
+ export default function useLocalstorageRef<T>(name: string): [{
2
+ current: T | undefined;
3
+ }, (value: T) => void];