@easyv/react-components 0.0.50 → 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 (82) 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/Watermark/index.d.ts +2 -0
  75. package/dist/Watermark/index.js +2 -0
  76. package/dist/Watermark/interface.d.ts +1 -0
  77. package/dist/Watermark/interface.js +1 -0
  78. package/dist/global.d.ts +13 -0
  79. package/dist/hooks/index.d.ts +3 -0
  80. package/dist/index.d.ts +4 -0
  81. package/dist/index.js +3 -3
  82. 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('usedLinearColors'),
13
+ _useLocalstorageRef2 = _slicedToArray(_useLocalstorageRef, 2),
14
+ usedLinearColors = _useLocalstorageRef2[0],
15
+ setUsedLinearColors = _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.stops].concat(usedLinearColors.current || []);
26
+ newColors = newColors.slice(0, 16);
27
+ setUsedLinearColors(newColors);
28
+ }
29
+ };
30
+ }, []);
31
+ return null;
32
+ }
@@ -0,0 +1,8 @@
1
+ import { ColorType } from '../interface';
2
+ interface ColorTypeTabProps {
3
+ tabs: ColorType[];
4
+ active: ColorType;
5
+ onChange: (active: ColorType) => void;
6
+ }
7
+ export default function ColorTypeTabs({ tabs, active, onChange, }: ColorTypeTabProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,30 @@
1
+ import classNames from 'classnames';
2
+ import { Tooltip } from '@arco-design/web-react';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ var tooltipsMap = {
5
+ pure: '纯色',
6
+ pures: '多色',
7
+ linear: '渐变'
8
+ };
9
+ export default function ColorTypeTabs(_ref) {
10
+ var tabs = _ref.tabs,
11
+ active = _ref.active,
12
+ onChange = _ref.onChange;
13
+ return /*#__PURE__*/_jsx("div", {
14
+ className: "colors-picker-tabs",
15
+ children: tabs.map(function (d) {
16
+ return /*#__PURE__*/_jsx(Tooltip, {
17
+ content: tooltipsMap[d],
18
+ position: "top",
19
+ children: /*#__PURE__*/_jsx("div", {
20
+ className: classNames("colors-picker-tab colors-picker-tab-".concat(d), {
21
+ active: active === d
22
+ }),
23
+ onClick: function onClick() {
24
+ return onChange(d);
25
+ }
26
+ })
27
+ }, d);
28
+ })
29
+ });
30
+ }
@@ -0,0 +1,8 @@
1
+ import { ColorType, ColorValueObj } from '../interface';
2
+ interface MixedPanelProps {
3
+ type: ColorType[];
4
+ value: ColorValueObj;
5
+ onChange: (value: ColorValueObj) => void;
6
+ }
7
+ export default function MixedPanel({ type, value, onChange }: MixedPanelProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,64 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ 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); }
7
+ import { LinearColorPanel } from "../LinearColorPicker";
8
+ import { PureColorPanel } from "../PureColorPicker";
9
+ import { PuresColorPanel } from "../PuresColorPicker";
10
+ import ColorTypeTabs from "./ColorTypeTab";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export default function MixedPanel(_ref) {
15
+ var type = _ref.type,
16
+ value = _ref.value,
17
+ onChange = _ref.onChange;
18
+ var handleChange = function handleChange(type) {
19
+ return function (newValue) {
20
+ onChange(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
21
+ };
22
+ };
23
+ var handleTypeChange = function handleTypeChange(newType) {
24
+ onChange(_objectSpread(_objectSpread({}, value), {}, {
25
+ type: newType
26
+ }));
27
+ };
28
+ var renderPanel = function renderPanel() {
29
+ switch (value.type) {
30
+ case 'pure':
31
+ {
32
+ return /*#__PURE__*/_jsx(PureColorPanel, {
33
+ value: value['pure'],
34
+ onChange: handleChange('pure')
35
+ });
36
+ }
37
+ case 'pures':
38
+ {
39
+ return /*#__PURE__*/_jsx(PuresColorPanel, {
40
+ value: value['pures'],
41
+ onChange: handleChange('pures')
42
+ });
43
+ }
44
+ case 'linear':
45
+ {
46
+ return /*#__PURE__*/_jsx(LinearColorPanel, {
47
+ value: value['linear'],
48
+ onChange: handleChange('linear')
49
+ });
50
+ }
51
+ default:
52
+ {
53
+ console.error('unknown color picker type');
54
+ }
55
+ }
56
+ };
57
+ return /*#__PURE__*/_jsxs(_Fragment, {
58
+ children: [/*#__PURE__*/_jsx(ColorTypeTabs, {
59
+ tabs: type,
60
+ active: value.type,
61
+ onChange: handleTypeChange
62
+ }), renderPanel()]
63
+ });
64
+ }
@@ -0,0 +1 @@
1
+ export { default as MixedPanel } from './MixedPanel';
@@ -0,0 +1 @@
1
+ export { default as MixedPanel } from "./MixedPanel";
@@ -0,0 +1,7 @@
1
+ import { Color } from './interface';
2
+ interface PaletteProps {
3
+ color: Color;
4
+ onChange: (s: number, v: number) => void;
5
+ }
6
+ export default function Palette({ color, onChange }: PaletteProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,39 @@
1
+ import tinycolor from 'tinycolor2';
2
+ import { useControlBlock } from "./hooks/useControlBlock";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export default function Palette(_ref) {
5
+ var color = _ref.color,
6
+ _onChange = _ref.onChange;
7
+ var _color$hsv = color.hsv,
8
+ h = _color$hsv.h,
9
+ s = _color$hsv.s,
10
+ v = _color$hsv.v;
11
+ var rgbColor = tinycolor({
12
+ h: h,
13
+ s: 1,
14
+ v: 1
15
+ }).toRgbString();
16
+ var _useControlBlock = useControlBlock({
17
+ value: [s, 1 - v],
18
+ onChange: function onChange(value) {
19
+ return _onChange(value[0], 1 - value[1]);
20
+ }
21
+ }),
22
+ blockRef = _useControlBlock.blockRef,
23
+ onMouseDown = _useControlBlock.onMouseDown;
24
+ return /*#__PURE__*/_jsx("div", {
25
+ ref: blockRef,
26
+ className: "colors-picker-palette",
27
+ style: {
28
+ backgroundColor: rgbColor
29
+ },
30
+ onMouseDown: onMouseDown,
31
+ children: /*#__PURE__*/_jsx("div", {
32
+ className: "colors-picker-handler",
33
+ style: {
34
+ top: "".concat((1 - v) * 100, "%"),
35
+ left: "".concat(s * 100, "%")
36
+ }
37
+ })
38
+ });
39
+ }
@@ -0,0 +1,6 @@
1
+ interface PanelProps {
2
+ color: string;
3
+ onChange: (color: string) => void;
4
+ }
5
+ export default function Panel({ color: propsColor, onChange }: PanelProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,224 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ 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); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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); }
10
+ 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; }
11
+ 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; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { useRef, useState } from 'react';
14
+ import tinycolor from 'tinycolor2';
15
+ import Palette from "./Palette";
16
+ import ControlBar from "./ControlBar";
17
+ import BlurInput from "../BlurInput";
18
+ import { getHexValue } from "./utils";
19
+ import Preview from "./common/Preview";
20
+ import { PipetteOutlined } from '@easyv/react-icons';
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { jsxs as _jsxs } from "react/jsx-runtime";
23
+ export default function Panel(_ref) {
24
+ var propsColor = _ref.color,
25
+ onChange = _ref.onChange;
26
+ var _useState = useState(function () {
27
+ return {
28
+ hsv: tinycolor(propsColor).toHsv(),
29
+ alpha: tinycolor(propsColor).getAlpha()
30
+ };
31
+ }),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ color = _useState2[0],
34
+ setColor = _useState2[1];
35
+ var _color$hsv = color.hsv,
36
+ h = _color$hsv.h,
37
+ s = _color$hsv.s,
38
+ v = _color$hsv.v;
39
+ var _tinycolor$toRgb = tinycolor(color.hsv).toRgb(),
40
+ r = _tinycolor$toRgb.r,
41
+ g = _tinycolor$toRgb.g,
42
+ b = _tinycolor$toRgb.b;
43
+ var colorString = tinycolor(color.hsv).setAlpha(color.alpha).toRgbString();
44
+ var hexString = tinycolor(color.hsv).toHexString();
45
+ var hexRef = useRef(null);
46
+ var handleHsvChange = function handleHsvChange(hsv) {
47
+ setColor(_objectSpread(_objectSpread({}, color), {}, {
48
+ hsv: hsv
49
+ }));
50
+ onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
51
+ a: color.alpha
52
+ })).toRgbString());
53
+ };
54
+ var handleAlphaChange = function handleAlphaChange(alpha) {
55
+ setColor(_objectSpread(_objectSpread({}, color), {}, {
56
+ alpha: alpha
57
+ }));
58
+ onChange(tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
59
+ a: alpha
60
+ })).toRgbString());
61
+ };
62
+ var handleHexChange = function handleHexChange(val) {
63
+ var hexVal = getHexValue(val);
64
+ var hsv = tinycolor(hexVal).toHsv();
65
+ var hexString = tinycolor(hsv).toHexString();
66
+ hexRef.current.forceUpdate(hexString.slice(1).toUpperCase());
67
+ setColor(_objectSpread(_objectSpread({}, color), {}, {
68
+ hsv: hsv
69
+ }));
70
+ onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
71
+ a: color.alpha
72
+ })).toRgbString());
73
+ };
74
+ var handleRgbChange = function handleRgbChange(rgb) {
75
+ var hsv = tinycolor(_objectSpread({
76
+ r: r,
77
+ g: g,
78
+ b: b
79
+ }, rgb)).toHsv();
80
+ setColor(_objectSpread(_objectSpread({}, color), {}, {
81
+ hsv: hsv
82
+ }));
83
+ onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
84
+ a: color.alpha
85
+ })).toRgbString());
86
+ };
87
+ var handleColorChange = function handleColorChange(color) {
88
+ setColor({
89
+ hsv: tinycolor(color).toHsv(),
90
+ alpha: 1
91
+ });
92
+ onChange(color);
93
+ };
94
+ return /*#__PURE__*/_jsxs("div", {
95
+ className: "colors-picker-panel",
96
+ children: [/*#__PURE__*/_jsx(Palette, {
97
+ color: color,
98
+ onChange: function onChange(newS, newV) {
99
+ return handleHsvChange({
100
+ h: h,
101
+ s: newS,
102
+ v: newV
103
+ });
104
+ }
105
+ }), /*#__PURE__*/_jsxs("div", {
106
+ className: "colors-picker-control-wrapper",
107
+ children: [window.EyeDropper && /*#__PURE__*/_jsx("div", {
108
+ className: "colors-picker-eye-dropper",
109
+ onClick: function onClick() {
110
+ var eyeDropper = new window.EyeDropper();
111
+ eyeDropper.open().then(function (result) {
112
+ var sRGBHex = result.sRGBHex;
113
+ handleColorChange(sRGBHex);
114
+ });
115
+ },
116
+ children: /*#__PURE__*/_jsx(PipetteOutlined, {})
117
+ }), /*#__PURE__*/_jsxs("div", {
118
+ className: "colors-picker-control-bars",
119
+ children: [/*#__PURE__*/_jsx(ControlBar, {
120
+ type: "hue",
121
+ color: color,
122
+ onChange: function onChange(newH) {
123
+ return handleHsvChange({
124
+ h: newH,
125
+ s: s,
126
+ v: v
127
+ });
128
+ }
129
+ }), /*#__PURE__*/_jsx(ControlBar, {
130
+ type: "alpha",
131
+ color: color,
132
+ onChange: handleAlphaChange
133
+ })]
134
+ }), /*#__PURE__*/_jsx(Preview, {
135
+ type: "pure",
136
+ color: colorString,
137
+ size: 28
138
+ })]
139
+ }), /*#__PURE__*/_jsxs("div", {
140
+ className: "colors-picker-input-wrapper",
141
+ children: [/*#__PURE__*/_jsxs("div", {
142
+ className: "colors-picker-input colors-picker-input-hex",
143
+ children: [/*#__PURE__*/_jsx(BlurInput, {
144
+ size: "small",
145
+ ref: hexRef,
146
+ value: hexString.slice(1).toUpperCase(),
147
+ validate: function validate(val) {
148
+ return /^#?([0-9a-fA-F])+/.test(val);
149
+ },
150
+ onChange: handleHexChange
151
+ }), /*#__PURE__*/_jsx("span", {
152
+ className: "colors-picker-input-label",
153
+ children: "Hex"
154
+ })]
155
+ }), /*#__PURE__*/_jsxs("div", {
156
+ className: "colors-picker-input colors-picker-input-r",
157
+ children: [/*#__PURE__*/_jsx(BlurInput, {
158
+ size: "small",
159
+ value: r.toString(),
160
+ validate: function validate(val) {
161
+ return +val >= 0 && +val <= 255;
162
+ },
163
+ onChange: function onChange(val) {
164
+ return handleRgbChange({
165
+ r: +val
166
+ });
167
+ }
168
+ }), /*#__PURE__*/_jsx("span", {
169
+ className: "colors-picker-input-label",
170
+ children: "R"
171
+ })]
172
+ }), /*#__PURE__*/_jsxs("div", {
173
+ className: "colors-picker-input colors-picker-input-g",
174
+ children: [/*#__PURE__*/_jsx(BlurInput, {
175
+ size: "small",
176
+ value: g.toString(),
177
+ validate: function validate(val) {
178
+ return +val >= 0 && +val <= 255;
179
+ },
180
+ onChange: function onChange(val) {
181
+ return handleRgbChange({
182
+ g: +val
183
+ });
184
+ }
185
+ }), /*#__PURE__*/_jsx("span", {
186
+ className: "colors-picker-input-label",
187
+ children: "G"
188
+ })]
189
+ }), /*#__PURE__*/_jsxs("div", {
190
+ className: "colors-picker-input colors-picker-input-b",
191
+ children: [/*#__PURE__*/_jsx(BlurInput, {
192
+ size: "small",
193
+ value: b.toString(),
194
+ validate: function validate(val) {
195
+ return +val >= 0 && +val <= 255;
196
+ },
197
+ onChange: function onChange(val) {
198
+ return handleRgbChange({
199
+ b: +val
200
+ });
201
+ }
202
+ }), /*#__PURE__*/_jsx("span", {
203
+ className: "colors-picker-input-label",
204
+ children: "B"
205
+ })]
206
+ }), /*#__PURE__*/_jsxs("div", {
207
+ className: "colors-picker-input colors-picker-input-a",
208
+ children: [/*#__PURE__*/_jsx(BlurInput, {
209
+ size: "small",
210
+ value: (color.alpha * 100).toFixed(0),
211
+ validate: function validate(val) {
212
+ return +val >= 0 && +val <= 100;
213
+ },
214
+ onChange: function onChange(val) {
215
+ return handleAlphaChange(+val / 100);
216
+ }
217
+ }), /*#__PURE__*/_jsx("span", {
218
+ className: "colors-picker-input-label",
219
+ children: "A"
220
+ })]
221
+ })]
222
+ })]
223
+ });
224
+ }
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ interface PanelContainerProps {
3
+ children: ReactNode;
4
+ }
5
+ export default function PanelContainer({ children }: PanelContainerProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export default function PanelContainer(_ref) {
3
+ var children = _ref.children;
4
+ return /*#__PURE__*/_jsx("div", {
5
+ className: "colors-picker-panel-container",
6
+ children: children
7
+ });
8
+ }
@@ -0,0 +1,7 @@
1
+ interface PureColorInputProps {
2
+ value: string;
3
+ onTrigger: () => void;
4
+ onChange: (val: string) => void;
5
+ }
6
+ export default function PureColorInput({ value, onChange, onTrigger, }: PureColorInputProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,61 @@
1
+ import { useRef } from 'react';
2
+ import tinycolor from 'tinycolor2';
3
+ import BlurInput from "../../BlurInput";
4
+ import { getHexValue } from "../utils";
5
+ import Preview from "../common/Preview";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+ export default function PureColorInput(_ref) {
9
+ var value = _ref.value,
10
+ onChange = _ref.onChange,
11
+ onTrigger = _ref.onTrigger;
12
+ var hexRef = useRef(null);
13
+ var hexString = tinycolor(value).toHexString();
14
+ var alpha = tinycolor(value).getAlpha();
15
+ var handleHexChange = function handleHexChange(val) {
16
+ var hexVal = getHexValue(val);
17
+ var hsv = tinycolor(hexVal).toHsv();
18
+ var hexString = tinycolor(hsv).toHexString();
19
+ hexRef.current.forceUpdate(hexString.slice(1).toUpperCase());
20
+ var newColor = tinycolor(hexString).setAlpha(alpha).toRgbString();
21
+ onChange(newColor);
22
+ };
23
+ var handleAlphaChange = function handleAlphaChange(val) {
24
+ var newColor = tinycolor(hexString).setAlpha(val).toRgbString();
25
+ onChange(newColor);
26
+ };
27
+ return /*#__PURE__*/_jsxs("div", {
28
+ className: "pure-color-picker",
29
+ children: [/*#__PURE__*/_jsx("div", {
30
+ className: "pure-color-picker-preview",
31
+ onClick: onTrigger,
32
+ children: /*#__PURE__*/_jsx(Preview, {
33
+ type: "pure",
34
+ shape: "square",
35
+ color: value,
36
+ size: 12
37
+ })
38
+ }), /*#__PURE__*/_jsx(BlurInput, {
39
+ className: 'pure-color-picker-hex',
40
+ size: "small",
41
+ ref: hexRef,
42
+ prefix: "#",
43
+ value: hexString.slice(1).toUpperCase(),
44
+ validate: function validate(val) {
45
+ return /^#?([0-9a-fA-F])+/.test(val);
46
+ },
47
+ onChange: handleHexChange
48
+ }), /*#__PURE__*/_jsx(BlurInput, {
49
+ size: "small",
50
+ suffix: "%",
51
+ className: 'pure-color-picker-alpha',
52
+ value: (alpha * 100).toFixed(0),
53
+ validate: function validate(val) {
54
+ return +val >= 0 && +val <= 100;
55
+ },
56
+ onChange: function onChange(val) {
57
+ return handleAlphaChange(+val / 100);
58
+ }
59
+ })]
60
+ });
61
+ }
@@ -0,0 +1,7 @@
1
+ import { ColorValueMap } from '../interface';
2
+ interface PureColorPanelProps {
3
+ value: ColorValueMap['pure'];
4
+ onChange: (value: ColorValueMap['pure']) => void;
5
+ }
6
+ export default function PureColorPanel({ value, onChange, }: PureColorPanelProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,39 @@
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 Panel from "../Panel";
8
+ import History from "../History";
9
+ import { useState } from 'react';
10
+ import useHistory from "./useHistory";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export default function PureColorPanel(_ref) {
15
+ var value = _ref.value,
16
+ onChange = _ref.onChange;
17
+ var _useState = useState(0),
18
+ _useState2 = _slicedToArray(_useState, 2),
19
+ updateKey = _useState2[0],
20
+ setUpdateKey = _useState2[1];
21
+ var handleSelect = function handleSelect(val) {
22
+ onChange(val);
23
+ setUpdateKey(function (prev) {
24
+ return prev + 1;
25
+ });
26
+ };
27
+ useHistory({
28
+ value: value
29
+ });
30
+ return /*#__PURE__*/_jsxs(_Fragment, {
31
+ children: [/*#__PURE__*/_jsx(Panel, {
32
+ color: value,
33
+ onChange: onChange
34
+ }, updateKey), /*#__PURE__*/_jsx(History, {
35
+ type: "pure",
36
+ onSelect: handleSelect
37
+ })]
38
+ });
39
+ }
@@ -0,0 +1,2 @@
1
+ export { default as PureColorInput } from './PureColorInput';
2
+ export { default as PureColorPanel } from './PureColorPanel';
@@ -0,0 +1,2 @@
1
+ export { default as PureColorInput } from "./PureColorInput";
2
+ export { default as PureColorPanel } from "./PureColorPanel";
@@ -0,0 +1,4 @@
1
+ import { ColorValueMap } from '../interface';
2
+ export default function useHistory({ value, }: {
3
+ value: ColorValueMap['pure'];
4
+ }): null;
@@ -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 {};