@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.
- package/dist/BlurInput/index.d.ts +12 -0
- package/dist/BlurInput/index.js +58 -0
- package/dist/ColorsPicker/ControlBar.d.ts +9 -0
- package/dist/ColorsPicker/ControlBar.js +75 -0
- package/dist/ColorsPicker/History.d.ts +7 -0
- package/dist/ColorsPicker/History.js +53 -0
- package/dist/ColorsPicker/HistoryLinear.d.ts +6 -0
- package/dist/ColorsPicker/HistoryLinear.js +36 -0
- package/dist/ColorsPicker/HistoryPure.d.ts +5 -0
- package/dist/ColorsPicker/HistoryPure.js +28 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearColorInput.d.ts +8 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearColorInput.js +50 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.d.ts +8 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearColorPanel.js +89 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.d.ts +10 -0
- package/dist/ColorsPicker/LinearColorPicker/LinearPointsBar.js +156 -0
- package/dist/ColorsPicker/LinearColorPicker/index.d.ts +2 -0
- package/dist/ColorsPicker/LinearColorPicker/index.js +2 -0
- package/dist/ColorsPicker/LinearColorPicker/useHistory.d.ts +4 -0
- package/dist/ColorsPicker/LinearColorPicker/useHistory.js +32 -0
- package/dist/ColorsPicker/MixedColorPicker/ColorTypeTab.d.ts +8 -0
- package/dist/ColorsPicker/MixedColorPicker/ColorTypeTab.js +30 -0
- package/dist/ColorsPicker/MixedColorPicker/MixedPanel.d.ts +9 -0
- package/dist/ColorsPicker/MixedColorPicker/MixedPanel.js +76 -0
- package/dist/ColorsPicker/MixedColorPicker/index.d.ts +1 -0
- package/dist/ColorsPicker/MixedColorPicker/index.js +1 -0
- package/dist/ColorsPicker/Palette.d.ts +8 -0
- package/dist/ColorsPicker/Palette.js +43 -0
- package/dist/ColorsPicker/Panel.d.ts +7 -0
- package/dist/ColorsPicker/Panel.js +258 -0
- package/dist/ColorsPicker/PanelContainer.d.ts +6 -0
- package/dist/ColorsPicker/PanelContainer.js +8 -0
- package/dist/ColorsPicker/PureColorPicker/PureColorInput.d.ts +7 -0
- package/dist/ColorsPicker/PureColorPicker/PureColorInput.js +61 -0
- package/dist/ColorsPicker/PureColorPicker/PureColorPanel.d.ts +8 -0
- package/dist/ColorsPicker/PureColorPicker/PureColorPanel.js +42 -0
- package/dist/ColorsPicker/PureColorPicker/index.d.ts +2 -0
- package/dist/ColorsPicker/PureColorPicker/index.js +2 -0
- package/dist/ColorsPicker/PureColorPicker/useHistory.d.ts +4 -0
- package/dist/ColorsPicker/PureColorPicker/useHistory.js +32 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresCards.d.ts +10 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresCards.js +40 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresColorInput.d.ts +7 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresColorInput.js +20 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.d.ts +8 -0
- package/dist/ColorsPicker/PuresColorPicker/PuresColorPanel.js +90 -0
- package/dist/ColorsPicker/PuresColorPicker/index.d.ts +3 -0
- package/dist/ColorsPicker/PuresColorPicker/index.js +3 -0
- package/dist/ColorsPicker/PuresColorPicker/useHistory.d.ts +5 -0
- package/dist/ColorsPicker/PuresColorPicker/useHistory.js +34 -0
- package/dist/ColorsPicker/RangeColorPicker/RangeColorInput.d.ts +7 -0
- package/dist/ColorsPicker/RangeColorPicker/RangeColorInput.js +19 -0
- package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.d.ts +8 -0
- package/dist/ColorsPicker/RangeColorPicker/RangeColorPanel.js +67 -0
- package/dist/ColorsPicker/RangeColorPicker/RangePointBar.d.ts +8 -0
- package/dist/ColorsPicker/RangeColorPicker/RangePointBar.js +63 -0
- package/dist/ColorsPicker/RangeColorPicker/index.d.ts +2 -0
- package/dist/ColorsPicker/RangeColorPicker/index.js +2 -0
- package/dist/ColorsPicker/common/Preview.d.ts +11 -0
- package/dist/ColorsPicker/common/Preview.js +60 -0
- package/dist/ColorsPicker/hooks/useColorsPicker.d.ts +2 -0
- package/dist/ColorsPicker/hooks/useColorsPicker.js +106 -0
- package/dist/ColorsPicker/hooks/useControlBlock.d.ts +12 -0
- package/dist/ColorsPicker/hooks/useControlBlock.js +69 -0
- package/dist/ColorsPicker/hooks/useLocalstorageRef.d.ts +3 -0
- package/dist/ColorsPicker/hooks/useLocalstorageRef.js +11 -0
- package/dist/ColorsPicker/index.d.ts +4 -0
- package/dist/ColorsPicker/index.js +199 -0
- package/dist/ColorsPicker/interface.d.ts +59 -0
- package/dist/ColorsPicker/interface.js +1 -0
- package/dist/ColorsPicker/style/index.less +515 -0
- package/dist/ColorsPicker/utils.d.ts +29 -0
- package/dist/ColorsPicker/utils.js +233 -0
- package/dist/global.d.ts +13 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -2
- 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,9 @@
|
|
|
1
|
+
import { ColorType, ColorValueObj } from '../interface';
|
|
2
|
+
interface MixedPanelProps {
|
|
3
|
+
type: ColorType[];
|
|
4
|
+
value: ColorValueObj;
|
|
5
|
+
onChange?: (value: ColorValueObj) => void;
|
|
6
|
+
onChangeComplete?: (value: ColorValueObj) => void;
|
|
7
|
+
}
|
|
8
|
+
export default function MixedPanel({ type, value, onChange, onChangeComplete, }: MixedPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
19
|
+
var handleChange = function handleChange(type) {
|
|
20
|
+
return function (newValue) {
|
|
21
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
var handleChangeComplete = function handleChangeComplete(type) {
|
|
25
|
+
return function (newValue) {
|
|
26
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(_objectSpread(_objectSpread({}, value), {}, _defineProperty({}, type, newValue)));
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var handleTypeChange = function handleTypeChange(newType) {
|
|
30
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_objectSpread(_objectSpread({}, value), {}, {
|
|
31
|
+
type: newType
|
|
32
|
+
}));
|
|
33
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(_objectSpread(_objectSpread({}, value), {}, {
|
|
34
|
+
type: newType
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
var renderPanel = function renderPanel() {
|
|
38
|
+
switch (value.type) {
|
|
39
|
+
case 'pure':
|
|
40
|
+
{
|
|
41
|
+
return /*#__PURE__*/_jsx(PureColorPanel, {
|
|
42
|
+
value: value['pure'],
|
|
43
|
+
onChange: handleChange('pure'),
|
|
44
|
+
onChangeComplete: handleChangeComplete('pure')
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
case 'pures':
|
|
48
|
+
{
|
|
49
|
+
return /*#__PURE__*/_jsx(PuresColorPanel, {
|
|
50
|
+
value: value['pures'],
|
|
51
|
+
onChange: handleChange('pures'),
|
|
52
|
+
onChangeComplete: handleChangeComplete('pures')
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
case 'linear':
|
|
56
|
+
{
|
|
57
|
+
return /*#__PURE__*/_jsx(LinearColorPanel, {
|
|
58
|
+
value: value['linear'],
|
|
59
|
+
onChange: handleChange('linear'),
|
|
60
|
+
onChangeComplete: handleChangeComplete('linear')
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
{
|
|
65
|
+
console.error('unknown color picker type');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
70
|
+
children: [/*#__PURE__*/_jsx(ColorTypeTabs, {
|
|
71
|
+
tabs: type,
|
|
72
|
+
active: value.type,
|
|
73
|
+
onChange: handleTypeChange
|
|
74
|
+
}), renderPanel()]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MixedPanel } from './MixedPanel';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MixedPanel } from "./MixedPanel";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Color } from './interface';
|
|
2
|
+
interface PaletteProps {
|
|
3
|
+
color: Color;
|
|
4
|
+
onChange?: (s: number, v: number) => void;
|
|
5
|
+
onChangeComplete?: (s: number, v: number) => void;
|
|
6
|
+
}
|
|
7
|
+
export default function Palette({ color, onChange, onChangeComplete, }: PaletteProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
_onChangeComplete = _ref.onChangeComplete;
|
|
8
|
+
var _color$hsv = color.hsv,
|
|
9
|
+
h = _color$hsv.h,
|
|
10
|
+
s = _color$hsv.s,
|
|
11
|
+
v = _color$hsv.v;
|
|
12
|
+
var rgbColor = tinycolor({
|
|
13
|
+
h: h,
|
|
14
|
+
s: 1,
|
|
15
|
+
v: 1
|
|
16
|
+
}).toRgbString();
|
|
17
|
+
var _useControlBlock = useControlBlock({
|
|
18
|
+
value: [s, 1 - v],
|
|
19
|
+
onChange: function onChange(value) {
|
|
20
|
+
return _onChange === null || _onChange === void 0 ? void 0 : _onChange(value[0], 1 - value[1]);
|
|
21
|
+
},
|
|
22
|
+
onChangeComplete: function onChangeComplete(value) {
|
|
23
|
+
return _onChangeComplete === null || _onChangeComplete === void 0 ? void 0 : _onChangeComplete(value[0], 1 - value[1]);
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
26
|
+
blockRef = _useControlBlock.blockRef,
|
|
27
|
+
onMouseDown = _useControlBlock.onMouseDown;
|
|
28
|
+
return /*#__PURE__*/_jsx("div", {
|
|
29
|
+
ref: blockRef,
|
|
30
|
+
className: "colors-picker-palette",
|
|
31
|
+
style: {
|
|
32
|
+
backgroundColor: rgbColor
|
|
33
|
+
},
|
|
34
|
+
onMouseDown: onMouseDown,
|
|
35
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
36
|
+
className: "colors-picker-handler",
|
|
37
|
+
style: {
|
|
38
|
+
top: "".concat((1 - v) * 100, "%"),
|
|
39
|
+
left: "".concat(s * 100, "%")
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface PanelProps {
|
|
2
|
+
color: string;
|
|
3
|
+
onChange?: (color: string) => void;
|
|
4
|
+
onChangeComplete?: (color: string) => void;
|
|
5
|
+
}
|
|
6
|
+
export default function Panel({ color: propsColor, onChange, onChangeComplete, }: PanelProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
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
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
27
|
+
var _useState = useState(function () {
|
|
28
|
+
return {
|
|
29
|
+
hsv: tinycolor(propsColor).toHsv(),
|
|
30
|
+
alpha: tinycolor(propsColor).getAlpha()
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
color = _useState2[0],
|
|
35
|
+
setColor = _useState2[1];
|
|
36
|
+
var _color$hsv = color.hsv,
|
|
37
|
+
h = _color$hsv.h,
|
|
38
|
+
s = _color$hsv.s,
|
|
39
|
+
v = _color$hsv.v;
|
|
40
|
+
var _tinycolor$toRgb = tinycolor(color.hsv).toRgb(),
|
|
41
|
+
r = _tinycolor$toRgb.r,
|
|
42
|
+
g = _tinycolor$toRgb.g,
|
|
43
|
+
b = _tinycolor$toRgb.b;
|
|
44
|
+
var colorString = tinycolor(color.hsv).setAlpha(color.alpha).toRgbString();
|
|
45
|
+
var hexString = tinycolor(color.hsv).toHexString();
|
|
46
|
+
var hexRef = useRef(null);
|
|
47
|
+
var handleHsvChange = function handleHsvChange(hsv, complete) {
|
|
48
|
+
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
49
|
+
hsv: hsv
|
|
50
|
+
}));
|
|
51
|
+
if (complete) {
|
|
52
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
53
|
+
a: color.alpha
|
|
54
|
+
})).toRgbString());
|
|
55
|
+
} else {
|
|
56
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
57
|
+
a: color.alpha
|
|
58
|
+
})).toRgbString());
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var handleAlphaChange = function handleAlphaChange(alpha, complete) {
|
|
62
|
+
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
63
|
+
alpha: alpha
|
|
64
|
+
}));
|
|
65
|
+
if (complete) {
|
|
66
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
|
|
67
|
+
a: alpha
|
|
68
|
+
})).toRgbString());
|
|
69
|
+
} else {
|
|
70
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(tinycolor(_objectSpread(_objectSpread({}, color.hsv), {}, {
|
|
71
|
+
a: alpha
|
|
72
|
+
})).toRgbString());
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var handleHexChange = function handleHexChange(val) {
|
|
76
|
+
var hexVal = getHexValue(val);
|
|
77
|
+
var hsv = tinycolor(hexVal).toHsv();
|
|
78
|
+
var hexString = tinycolor(hsv).toHexString();
|
|
79
|
+
hexRef.current.forceUpdate(hexString.slice(1).toUpperCase());
|
|
80
|
+
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
81
|
+
hsv: hsv
|
|
82
|
+
}));
|
|
83
|
+
onChangeWithComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
84
|
+
a: color.alpha
|
|
85
|
+
})).toRgbString());
|
|
86
|
+
};
|
|
87
|
+
var handleRgbChange = function handleRgbChange(rgb) {
|
|
88
|
+
var hsv = tinycolor(_objectSpread({
|
|
89
|
+
r: r,
|
|
90
|
+
g: g,
|
|
91
|
+
b: b
|
|
92
|
+
}, rgb)).toHsv();
|
|
93
|
+
setColor(_objectSpread(_objectSpread({}, color), {}, {
|
|
94
|
+
hsv: hsv
|
|
95
|
+
}));
|
|
96
|
+
onChangeWithComplete(tinycolor(_objectSpread(_objectSpread({}, hsv), {}, {
|
|
97
|
+
a: color.alpha
|
|
98
|
+
})).toRgbString());
|
|
99
|
+
};
|
|
100
|
+
var handleColorChange = function handleColorChange(color) {
|
|
101
|
+
setColor({
|
|
102
|
+
hsv: tinycolor(color).toHsv(),
|
|
103
|
+
alpha: 1
|
|
104
|
+
});
|
|
105
|
+
onChangeWithComplete(color);
|
|
106
|
+
};
|
|
107
|
+
var onChangeWithComplete = function onChangeWithComplete(color) {
|
|
108
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(color);
|
|
109
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(color);
|
|
110
|
+
};
|
|
111
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
112
|
+
className: "colors-picker-panel",
|
|
113
|
+
children: [/*#__PURE__*/_jsx(Palette, {
|
|
114
|
+
color: color,
|
|
115
|
+
onChange: function onChange(newS, newV) {
|
|
116
|
+
return handleHsvChange({
|
|
117
|
+
h: h,
|
|
118
|
+
s: newS,
|
|
119
|
+
v: newV
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
onChangeComplete: function onChangeComplete(newS, newV) {
|
|
123
|
+
return handleHsvChange({
|
|
124
|
+
h: h,
|
|
125
|
+
s: newS,
|
|
126
|
+
v: newV
|
|
127
|
+
}, true);
|
|
128
|
+
}
|
|
129
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
130
|
+
className: "colors-picker-control-wrapper",
|
|
131
|
+
children: [window.EyeDropper && /*#__PURE__*/_jsx("div", {
|
|
132
|
+
className: "colors-picker-eye-dropper",
|
|
133
|
+
onClick: function onClick() {
|
|
134
|
+
var eyeDropper = new window.EyeDropper();
|
|
135
|
+
eyeDropper.open().then(function (result) {
|
|
136
|
+
var sRGBHex = result.sRGBHex;
|
|
137
|
+
handleColorChange(sRGBHex);
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
children: /*#__PURE__*/_jsx(PipetteOutlined, {})
|
|
141
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
142
|
+
className: "colors-picker-control-bars",
|
|
143
|
+
children: [/*#__PURE__*/_jsx(ControlBar, {
|
|
144
|
+
type: "hue",
|
|
145
|
+
color: color,
|
|
146
|
+
onChange: function onChange(newH) {
|
|
147
|
+
return handleHsvChange({
|
|
148
|
+
h: newH,
|
|
149
|
+
s: s,
|
|
150
|
+
v: v
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
onChangeComplete: function onChangeComplete(newH) {
|
|
154
|
+
return handleHsvChange({
|
|
155
|
+
h: newH,
|
|
156
|
+
s: s,
|
|
157
|
+
v: v
|
|
158
|
+
}, true);
|
|
159
|
+
}
|
|
160
|
+
}), /*#__PURE__*/_jsx(ControlBar, {
|
|
161
|
+
type: "alpha",
|
|
162
|
+
color: color,
|
|
163
|
+
onChange: handleAlphaChange,
|
|
164
|
+
onChangeComplete: function onChangeComplete(val) {
|
|
165
|
+
return handleAlphaChange(val, true);
|
|
166
|
+
}
|
|
167
|
+
})]
|
|
168
|
+
}), /*#__PURE__*/_jsx(Preview, {
|
|
169
|
+
type: "pure",
|
|
170
|
+
color: colorString,
|
|
171
|
+
size: 28
|
|
172
|
+
})]
|
|
173
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
174
|
+
className: "colors-picker-input-wrapper",
|
|
175
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
176
|
+
className: "colors-picker-input colors-picker-input-hex",
|
|
177
|
+
children: [/*#__PURE__*/_jsx(BlurInput, {
|
|
178
|
+
size: "small",
|
|
179
|
+
ref: hexRef,
|
|
180
|
+
value: hexString.slice(1).toUpperCase(),
|
|
181
|
+
validate: function validate(val) {
|
|
182
|
+
return /^#?([0-9a-fA-F])+/.test(val);
|
|
183
|
+
},
|
|
184
|
+
onChange: handleHexChange
|
|
185
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
186
|
+
className: "colors-picker-input-label",
|
|
187
|
+
children: "Hex"
|
|
188
|
+
})]
|
|
189
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
190
|
+
className: "colors-picker-input colors-picker-input-r",
|
|
191
|
+
children: [/*#__PURE__*/_jsx(BlurInput, {
|
|
192
|
+
size: "small",
|
|
193
|
+
value: r.toString(),
|
|
194
|
+
validate: function validate(val) {
|
|
195
|
+
return +val >= 0 && +val <= 255;
|
|
196
|
+
},
|
|
197
|
+
onChange: function onChange(val) {
|
|
198
|
+
return handleRgbChange({
|
|
199
|
+
r: +val
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
203
|
+
className: "colors-picker-input-label",
|
|
204
|
+
children: "R"
|
|
205
|
+
})]
|
|
206
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
207
|
+
className: "colors-picker-input colors-picker-input-g",
|
|
208
|
+
children: [/*#__PURE__*/_jsx(BlurInput, {
|
|
209
|
+
size: "small",
|
|
210
|
+
value: g.toString(),
|
|
211
|
+
validate: function validate(val) {
|
|
212
|
+
return +val >= 0 && +val <= 255;
|
|
213
|
+
},
|
|
214
|
+
onChange: function onChange(val) {
|
|
215
|
+
return handleRgbChange({
|
|
216
|
+
g: +val
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
220
|
+
className: "colors-picker-input-label",
|
|
221
|
+
children: "G"
|
|
222
|
+
})]
|
|
223
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
224
|
+
className: "colors-picker-input colors-picker-input-b",
|
|
225
|
+
children: [/*#__PURE__*/_jsx(BlurInput, {
|
|
226
|
+
size: "small",
|
|
227
|
+
value: b.toString(),
|
|
228
|
+
validate: function validate(val) {
|
|
229
|
+
return +val >= 0 && +val <= 255;
|
|
230
|
+
},
|
|
231
|
+
onChange: function onChange(val) {
|
|
232
|
+
return handleRgbChange({
|
|
233
|
+
b: +val
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
237
|
+
className: "colors-picker-input-label",
|
|
238
|
+
children: "B"
|
|
239
|
+
})]
|
|
240
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
241
|
+
className: "colors-picker-input colors-picker-input-a",
|
|
242
|
+
children: [/*#__PURE__*/_jsx(BlurInput, {
|
|
243
|
+
size: "small",
|
|
244
|
+
value: (color.alpha * 100).toFixed(0),
|
|
245
|
+
validate: function validate(val) {
|
|
246
|
+
return +val >= 0 && +val <= 100;
|
|
247
|
+
},
|
|
248
|
+
onChange: function onChange(val) {
|
|
249
|
+
return handleAlphaChange(+val / 100, true);
|
|
250
|
+
}
|
|
251
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
252
|
+
className: "colors-picker-input-label",
|
|
253
|
+
children: "A"
|
|
254
|
+
})]
|
|
255
|
+
})]
|
|
256
|
+
})]
|
|
257
|
+
});
|
|
258
|
+
}
|
|
@@ -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 === null || onChange === void 0 ? void 0 : onChange(newColor);
|
|
22
|
+
};
|
|
23
|
+
var handleAlphaChange = function handleAlphaChange(val) {
|
|
24
|
+
var newColor = tinycolor(hexString).setAlpha(val).toRgbString();
|
|
25
|
+
onChange === null || onChange === void 0 ? void 0 : 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,8 @@
|
|
|
1
|
+
import { ColorValueMap } from '../interface';
|
|
2
|
+
interface PureColorPanelProps {
|
|
3
|
+
value: ColorValueMap['pure'];
|
|
4
|
+
onChange?: (value: ColorValueMap['pure']) => void;
|
|
5
|
+
onChangeComplete?: (value: ColorValueMap['pure']) => void;
|
|
6
|
+
}
|
|
7
|
+
export default function PureColorPanel({ value, onChange, onChangeComplete, }: PureColorPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
onChangeComplete = _ref.onChangeComplete;
|
|
18
|
+
var _useState = useState(0),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
updateKey = _useState2[0],
|
|
21
|
+
setUpdateKey = _useState2[1];
|
|
22
|
+
var handleSelect = function handleSelect(val) {
|
|
23
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(val);
|
|
24
|
+
onChangeComplete === null || onChangeComplete === void 0 ? void 0 : onChangeComplete(val);
|
|
25
|
+
setUpdateKey(function (prev) {
|
|
26
|
+
return prev + 1;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
useHistory({
|
|
30
|
+
value: value
|
|
31
|
+
});
|
|
32
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
33
|
+
children: [/*#__PURE__*/_jsx(Panel, {
|
|
34
|
+
color: value,
|
|
35
|
+
onChange: onChange,
|
|
36
|
+
onChangeComplete: onChangeComplete
|
|
37
|
+
}, updateKey), /*#__PURE__*/_jsx(History, {
|
|
38
|
+
type: "pure",
|
|
39
|
+
onSelect: handleSelect
|
|
40
|
+
})]
|
|
41
|
+
});
|
|
42
|
+
}
|