@chayns-components/color-picker 5.0.0-beta.217
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/LICENSE +21 -0
- package/README.md +40 -0
- package/lib/components/hue-slider/HueSlider.d.ts +13 -0
- package/lib/components/hue-slider/HueSlider.js +70 -0
- package/lib/components/hue-slider/HueSlider.js.map +1 -0
- package/lib/components/hue-slider/HueSlider.styles.d.ts +7 -0
- package/lib/components/hue-slider/HueSlider.styles.js +73 -0
- package/lib/components/hue-slider/HueSlider.styles.js.map +1 -0
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +14 -0
- package/lib/components/index.js.map +1 -0
- package/lib/constants/color.d.ts +4 -0
- package/lib/constants/color.js +69 -0
- package/lib/constants/color.js.map +1 -0
- package/lib/types.d.ts +14 -0
- package/lib/types.js +6 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/color.d.ts +20 -0
- package/lib/utils/color.js +130 -0
- package/lib/utils/color.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Tobit Laboratories AG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>
|
|
3
|
+
<img src="https://raw.githubusercontent.com/TobitSoftware/chayns-components/master/assets/logo.png" width="600px" alt="chayns-components" />
|
|
4
|
+
</h1>
|
|
5
|
+
<p>A set of beautiful React components for developing your own applications with chayns.</p>
|
|
6
|
+
<div>
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/@chayns-components/typewriter.svg?style=for-the-badge" alt="" />
|
|
8
|
+
<img src="https://img.shields.io/npm/v/@chayns-components/typewriter?style=for-the-badge" alt="" />
|
|
9
|
+
<img src="https://img.shields.io/github/license/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
10
|
+
<img src="https://img.shields.io/github/contributors/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
First you need to install the color picker part of the chayns-components.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# NPM
|
|
22
|
+
npm install @chayns-components/color-picker
|
|
23
|
+
|
|
24
|
+
# Yarn
|
|
25
|
+
yarn add @chayns-components/color-picker
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> **Information:** Since the components have now been implemented with the styled-components
|
|
29
|
+
> library, the styles are delivered directly with the components. There is no need to load an extra
|
|
30
|
+
> stylesheet anymore.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
You can use the components in your project as in the following example.
|
|
35
|
+
|
|
36
|
+
```typescript jsx
|
|
37
|
+
import { FileInput } from '@chayns-components/file-input';
|
|
38
|
+
|
|
39
|
+
<FileInput />;
|
|
40
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CSSProperties, FC } from 'react';
|
|
2
|
+
export type HueSliderProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The color that should be selected.
|
|
5
|
+
*/
|
|
6
|
+
color?: CSSProperties['color'];
|
|
7
|
+
/**
|
|
8
|
+
* Function that will be executed when the color is changed.
|
|
9
|
+
*/
|
|
10
|
+
onChange?: (color: CSSProperties['color']) => void;
|
|
11
|
+
};
|
|
12
|
+
declare const HueSlider: FC<HueSliderProps>;
|
|
13
|
+
export default HueSlider;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _colors = require("@chayns/colors");
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _color = require("../../utils/color");
|
|
10
|
+
var _HueSlider = require("./HueSlider.styles");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
+
const HueSlider = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
onChange,
|
|
16
|
+
color = 'rgba(255, 0, 0, 1)'
|
|
17
|
+
} = _ref;
|
|
18
|
+
const [editedValue, setEditedValue] = (0, _react.useState)(0);
|
|
19
|
+
const [hslColor, setHslColor] = (0, _react.useState)('hsl(0, 0, 100)');
|
|
20
|
+
(0, _react.useEffect)(() => {
|
|
21
|
+
if (color) {
|
|
22
|
+
const rgb = (0, _color.splitRgb)(color);
|
|
23
|
+
if (!rgb) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const hsl = (0, _color.convertColorToHsl)(`rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 1)`);
|
|
27
|
+
const match = hsl === null || hsl === void 0 ? void 0 : hsl.toString().match(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/);
|
|
28
|
+
if (!match || !match[1]) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
setHslColor(`hsl(${match[1]}, 100%, 50%)`);
|
|
32
|
+
setEditedValue(parseInt(match[1], 10));
|
|
33
|
+
if (typeof onChange === 'function') {
|
|
34
|
+
onChange(hsl);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [color, onChange]);
|
|
38
|
+
const handleInputChange = (0, _react.useCallback)(event => {
|
|
39
|
+
setEditedValue(Number(event.target.value));
|
|
40
|
+
const percentage = Number(event.target.value) / 360 * 100;
|
|
41
|
+
const hue = percentage / 100 * 360;
|
|
42
|
+
const saturation = 100;
|
|
43
|
+
const lightness = 50;
|
|
44
|
+
const hsl = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
|
|
45
|
+
setHslColor(hsl);
|
|
46
|
+
if (typeof onChange === 'function') {
|
|
47
|
+
const rgb = (0, _colors.hslToRgb255)({
|
|
48
|
+
h: hue,
|
|
49
|
+
s: 1,
|
|
50
|
+
l: 0.5
|
|
51
|
+
});
|
|
52
|
+
if (!rgb) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
onChange(`rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${1})`);
|
|
56
|
+
}
|
|
57
|
+
}, [onChange]);
|
|
58
|
+
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_HueSlider.StyledHueSlider, null, /*#__PURE__*/_react.default.createElement(_HueSlider.StyledHueSliderInput, {
|
|
59
|
+
color: hslColor,
|
|
60
|
+
type: "range",
|
|
61
|
+
min: 0,
|
|
62
|
+
max: 360,
|
|
63
|
+
value: editedValue,
|
|
64
|
+
onChange: handleInputChange
|
|
65
|
+
})), [editedValue, handleInputChange, hslColor]);
|
|
66
|
+
};
|
|
67
|
+
HueSlider.displayName = 'HueSlider';
|
|
68
|
+
var _default = HueSlider;
|
|
69
|
+
exports.default = _default;
|
|
70
|
+
//# sourceMappingURL=HueSlider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HueSlider.js","names":["_colors","require","_react","_interopRequireWildcard","_color","_HueSlider","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","HueSlider","_ref","onChange","color","editedValue","setEditedValue","useState","hslColor","setHslColor","useEffect","rgb","splitRgb","hsl","convertColorToHsl","r","g","b","match","toString","parseInt","handleInputChange","useCallback","event","Number","target","value","percentage","hue","saturation","lightness","hslToRgb255","h","s","l","useMemo","createElement","StyledHueSlider","StyledHueSliderInput","type","min","max","displayName","_default","exports"],"sources":["../../../src/components/hue-slider/HueSlider.tsx"],"sourcesContent":["import { hslToRgb255 } from '@chayns/colors';\nimport React, {\n ChangeEvent,\n CSSProperties,\n FC,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { convertColorToHsl, splitRgb } from '../../utils/color';\nimport { StyledHueSlider, StyledHueSliderInput } from './HueSlider.styles';\n\nexport type HueSliderProps = {\n /**\n * The color that should be selected.\n */\n color?: CSSProperties['color'];\n /**\n * Function that will be executed when the color is changed.\n */\n onChange?: (color: CSSProperties['color']) => void;\n};\n\nconst HueSlider: FC<HueSliderProps> = ({ onChange, color = 'rgba(255, 0, 0, 1)' }) => {\n const [editedValue, setEditedValue] = useState(0);\n const [hslColor, setHslColor] = useState<CSSProperties['color']>('hsl(0, 0, 100)');\n\n useEffect(() => {\n if (color) {\n const rgb = splitRgb(color);\n\n if (!rgb) {\n return;\n }\n\n const hsl = convertColorToHsl(`rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 1)`);\n const match = hsl?.toString().match(/hsl\\((\\d+),\\s*([\\d.]+)%,\\s*([\\d.]+)%\\)/);\n\n if (!match || !match[1]) {\n return;\n }\n\n setHslColor(`hsl(${match[1]}, 100%, 50%)`);\n setEditedValue(parseInt(match[1], 10));\n\n if (typeof onChange === 'function') {\n onChange(hsl);\n }\n }\n }, [color, onChange]);\n\n const handleInputChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setEditedValue(Number(event.target.value));\n\n const percentage = (Number(event.target.value) / 360) * 100;\n const hue = (percentage / 100) * 360;\n const saturation = 100;\n const lightness = 50;\n\n const hsl = `hsl(${hue}, ${saturation}%, ${lightness}%)`;\n setHslColor(hsl);\n\n if (typeof onChange === 'function') {\n const rgb = hslToRgb255({ h: hue, s: 1, l: 0.5 });\n\n if (!rgb) {\n return;\n }\n\n onChange(`rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${1})`);\n }\n },\n [onChange]\n );\n\n return useMemo(\n () => (\n <StyledHueSlider>\n <StyledHueSliderInput\n color={hslColor}\n type=\"range\"\n min={0}\n max={360}\n value={editedValue}\n onChange={handleInputChange}\n />\n </StyledHueSlider>\n ),\n [editedValue, handleInputChange, hslColor]\n );\n};\n\nHueSlider.displayName = 'HueSlider';\n\nexport default HueSlider;\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAA2E,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA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B;EAAkB,CAC/B,CACY,CACpB,EACD,CAAChB,WAAW,EAAEgB,iBAAiB,EAAEb,QAAQ,CAC7C,CAAC;AACL,CAAC;AAEDP,SAAS,CAACyC,WAAW,GAAG,WAAW;AAAC,IAAAC,QAAA,GAErB1C,SAAS;AAAA2C,OAAA,CAAA1D,OAAA,GAAAyD,QAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
export declare const StyledHueSlider: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const StyledHueSliderInput: import("styled-components").StyledComponent<"input", any, {
|
|
4
|
+
color: CSSProperties['color'];
|
|
5
|
+
} & {
|
|
6
|
+
theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
|
|
7
|
+
}, never>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledHueSliderInput = exports.StyledHueSlider = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
const StyledHueSlider = _styledComponents.default.div`
|
|
10
|
+
width: 100%;
|
|
11
|
+
cursor: pointer;
|
|
12
|
+
`;
|
|
13
|
+
exports.StyledHueSlider = StyledHueSlider;
|
|
14
|
+
const StyledHueSliderInput = _styledComponents.default.input`
|
|
15
|
+
width: 100%;
|
|
16
|
+
border-radius: 100px;
|
|
17
|
+
-webkit-appearance: none;
|
|
18
|
+
height: 10px;
|
|
19
|
+
background: linear-gradient(
|
|
20
|
+
to right,
|
|
21
|
+
hsl(0, 100%, 50%),
|
|
22
|
+
hsl(30, 100%, 50%),
|
|
23
|
+
hsl(60, 100%, 50%),
|
|
24
|
+
hsl(90, 100%, 50%),
|
|
25
|
+
hsl(120, 100%, 50%),
|
|
26
|
+
hsl(150, 100%, 50%),
|
|
27
|
+
hsl(180, 100%, 50%),
|
|
28
|
+
hsl(210, 100%, 50%),
|
|
29
|
+
hsl(240, 100%, 50%),
|
|
30
|
+
hsl(270, 100%, 50%),
|
|
31
|
+
hsl(300, 100%, 50%),
|
|
32
|
+
hsl(330, 100%, 50%),
|
|
33
|
+
hsl(360, 100%, 50%)
|
|
34
|
+
);
|
|
35
|
+
outline: none;
|
|
36
|
+
opacity: 0.7;
|
|
37
|
+
-webkit-transition: 0.2s;
|
|
38
|
+
transition: opacity 0.2s;
|
|
39
|
+
|
|
40
|
+
// Slider thumb for chrome
|
|
41
|
+
&::-webkit-slider-thumb {
|
|
42
|
+
-webkit-appearance: none;
|
|
43
|
+
appearance: none;
|
|
44
|
+
width: 20px;
|
|
45
|
+
height: 20px;
|
|
46
|
+
background-color: ${_ref => {
|
|
47
|
+
let {
|
|
48
|
+
color
|
|
49
|
+
} = _ref;
|
|
50
|
+
return color;
|
|
51
|
+
}};
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
border-radius: 50%;
|
|
54
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// slider thumb for firefox
|
|
58
|
+
&::-moz-range-thumb {
|
|
59
|
+
width: 20px;
|
|
60
|
+
height: 20px;
|
|
61
|
+
background-color: ${_ref2 => {
|
|
62
|
+
let {
|
|
63
|
+
color
|
|
64
|
+
} = _ref2;
|
|
65
|
+
return color;
|
|
66
|
+
}};
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
border-radius: 50%;
|
|
69
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
exports.StyledHueSliderInput = StyledHueSliderInput;
|
|
73
|
+
//# sourceMappingURL=HueSlider.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HueSlider.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledHueSlider","styled","div","exports","StyledHueSliderInput","input","_ref","color","_ref2"],"sources":["../../../src/components/hue-slider/HueSlider.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport type { CSSProperties } from 'react';\nimport styled from 'styled-components';\n\nexport const StyledHueSlider = styled.div`\n width: 100%;\n cursor: pointer;\n`;\n\ntype StyledHueSliderInputProps = WithTheme<{\n color: CSSProperties['color'];\n}>;\n\nexport const StyledHueSliderInput = styled.input<StyledHueSliderInputProps>`\n width: 100%;\n border-radius: 100px;\n -webkit-appearance: none;\n height: 10px;\n background: linear-gradient(\n to right,\n hsl(0, 100%, 50%),\n hsl(30, 100%, 50%),\n hsl(60, 100%, 50%),\n hsl(90, 100%, 50%),\n hsl(120, 100%, 50%),\n hsl(150, 100%, 50%),\n hsl(180, 100%, 50%),\n hsl(210, 100%, 50%),\n hsl(240, 100%, 50%),\n hsl(270, 100%, 50%),\n hsl(300, 100%, 50%),\n hsl(330, 100%, 50%),\n hsl(360, 100%, 50%)\n );\n outline: none;\n opacity: 0.7;\n -webkit-transition: 0.2s;\n transition: opacity 0.2s;\n\n // Slider thumb for chrome\n &::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 20px;\n height: 20px;\n background-color: ${({ color }) => color};\n cursor: pointer;\n border-radius: 50%;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);\n }\n\n // slider thumb for firefox\n &::-moz-range-thumb {\n width: 20px;\n height: 20px;\n background-color: ${({ color }) => color};\n cursor: pointer;\n border-radius: 50%;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);\n }\n`;\n"],"mappings":";;;;;;AAEA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEhC,MAAMG,eAAe,GAAGC,yBAAM,CAACC,GAAI;AAC1C;AACA;AACA,CAAC;AAACC,OAAA,CAAAH,eAAA,GAAAA,eAAA;AAMK,MAAMI,oBAAoB,GAAGH,yBAAM,CAACI,KAAiC;AAC5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4BC,IAAA;EAAA,IAAC;IAAEC;EAAM,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK;AAAA,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4BC,KAAA;EAAA,IAAC;IAAED;EAAM,CAAC,GAAAC,KAAA;EAAA,OAAKD,KAAK;AAAA,CAAC;AACjD;AACA;AACA;AACA;AACA,CAAC;AAACJ,OAAA,CAAAC,oBAAA,GAAAA,oBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HueSlider } from './hue-slider/HueSlider';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "HueSlider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _HueSlider.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _HueSlider = _interopRequireDefault(require("./hue-slider/HueSlider"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_HueSlider","_interopRequireDefault","require","obj","__esModule","default"],"sources":["../../src/components/index.ts"],"sourcesContent":["export { default as HueSlider } from './hue-slider/HueSlider';\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8D,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.colorPresents = void 0;
|
|
7
|
+
const colorPresents = [{
|
|
8
|
+
id: 0,
|
|
9
|
+
color: 'rgb(0, 0, 0)'
|
|
10
|
+
}, {
|
|
11
|
+
id: 1,
|
|
12
|
+
color: 'rgb(67, 67, 67)'
|
|
13
|
+
}, {
|
|
14
|
+
id: 2,
|
|
15
|
+
color: 'rgb(102, 102, 102)'
|
|
16
|
+
}, {
|
|
17
|
+
id: 3,
|
|
18
|
+
color: 'rgb(153, 153, 153)'
|
|
19
|
+
}, {
|
|
20
|
+
id: 4,
|
|
21
|
+
color: 'rgb(183, 183, 183)'
|
|
22
|
+
}, {
|
|
23
|
+
id: 5,
|
|
24
|
+
color: 'rgb(204, 204, 204)'
|
|
25
|
+
}, {
|
|
26
|
+
id: 6,
|
|
27
|
+
color: 'rgb(217, 217, 217)'
|
|
28
|
+
}, {
|
|
29
|
+
id: 7,
|
|
30
|
+
color: 'rgb(239, 239, 239)'
|
|
31
|
+
}, {
|
|
32
|
+
id: 8,
|
|
33
|
+
color: 'rgb(243, 243, 243)'
|
|
34
|
+
}, {
|
|
35
|
+
id: 9,
|
|
36
|
+
color: 'rgb(255, 255, 255)'
|
|
37
|
+
}, {
|
|
38
|
+
id: 10,
|
|
39
|
+
color: 'rgb(244, 67, 54)'
|
|
40
|
+
}, {
|
|
41
|
+
id: 11,
|
|
42
|
+
color: 'rgb(255, 152, 0)'
|
|
43
|
+
}, {
|
|
44
|
+
id: 12,
|
|
45
|
+
color: 'rgb(255, 235, 59)'
|
|
46
|
+
}, {
|
|
47
|
+
id: 13,
|
|
48
|
+
color: 'rgb(0, 150, 136)'
|
|
49
|
+
}, {
|
|
50
|
+
id: 14,
|
|
51
|
+
color: 'rgb(121, 85, 72)'
|
|
52
|
+
}, {
|
|
53
|
+
id: 15,
|
|
54
|
+
color: 'rgb(139, 195, 74)'
|
|
55
|
+
}, {
|
|
56
|
+
id: 16,
|
|
57
|
+
color: 'rgb(76, 175, 80)'
|
|
58
|
+
}, {
|
|
59
|
+
id: 17,
|
|
60
|
+
color: 'rgb(156, 39, 176)'
|
|
61
|
+
}, {
|
|
62
|
+
id: 18,
|
|
63
|
+
color: 'rgb(63, 81, 181)'
|
|
64
|
+
}, {
|
|
65
|
+
id: 19,
|
|
66
|
+
color: 'rgb(3, 169, 244)'
|
|
67
|
+
}];
|
|
68
|
+
exports.colorPresents = colorPresents;
|
|
69
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":["colorPresents","id","color","exports"],"sources":["../../src/constants/color.ts"],"sourcesContent":["export const colorPresents = [\n { id: 0, color: 'rgb(0, 0, 0)' },\n { id: 1, color: 'rgb(67, 67, 67)' },\n { id: 2, color: 'rgb(102, 102, 102)' },\n { id: 3, color: 'rgb(153, 153, 153)' },\n { id: 4, color: 'rgb(183, 183, 183)' },\n { id: 5, color: 'rgb(204, 204, 204)' },\n { id: 6, color: 'rgb(217, 217, 217)' },\n { id: 7, color: 'rgb(239, 239, 239)' },\n { id: 8, color: 'rgb(243, 243, 243)' },\n { id: 9, color: 'rgb(255, 255, 255)' },\n { id: 10, color: 'rgb(244, 67, 54)' },\n { id: 11, color: 'rgb(255, 152, 0)' },\n { id: 12, color: 'rgb(255, 235, 59)' },\n { id: 13, color: 'rgb(0, 150, 136)' },\n { id: 14, color: 'rgb(121, 85, 72)' },\n { id: 15, color: 'rgb(139, 195, 74)' },\n { id: 16,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EAAED,EAAE,EAAE,EAAE;EAAEC,KAAK,EAAE;AAAoB,CAAC,EACtC;EAAED,EAAE,EAAE,EAAE;EAAEC,KAAK,EAAE;AAAmB,CAAC,EACrC;EAAED,EAAE,EAAE,EAAE;EAAEC,KAAK,EAAE;AAAmB,CAAC,CACxC;AAACC,OAAA,CAAAH,aAAA,GAAAA,aAAA"}
|
package/lib/types.d.ts
ADDED
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["export interface Coordinates {\n x: number;\n y: number;\n}\n\nexport interface Scale {\n scaleX: number;\n scaleY: number;\n}\n\nexport interface RGB {\n r: number;\n g: number;\n b: number;\n a?: number;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CSSProperties, RefObject } from 'react';
|
|
2
|
+
import type { Coordinates, RGB, Scale } from '../types';
|
|
3
|
+
interface GetColorFromCoordinatesOptions {
|
|
4
|
+
coordinates: Coordinates;
|
|
5
|
+
canvas: RefObject<HTMLCanvasElement>;
|
|
6
|
+
opacity: number;
|
|
7
|
+
scale: Scale;
|
|
8
|
+
}
|
|
9
|
+
export declare const getColorFromCoordinates: ({ coordinates, canvas, opacity, scale, }: GetColorFromCoordinatesOptions) => string | undefined;
|
|
10
|
+
interface GetCoordinatesFromColorOptions {
|
|
11
|
+
color: CSSProperties['color'];
|
|
12
|
+
canvas: RefObject<HTMLCanvasElement>;
|
|
13
|
+
}
|
|
14
|
+
export declare const getCoordinatesFromColor: ({ canvas, color }: GetCoordinatesFromColorOptions) => {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
} | null | undefined;
|
|
18
|
+
export declare const convertColorToHsl: (color: string) => string | undefined;
|
|
19
|
+
export declare const splitRgb: (color: CSSProperties['color']) => null | RGB;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.splitRgb = exports.getCoordinatesFromColor = exports.getColorFromCoordinates = exports.convertColorToHsl = void 0;
|
|
7
|
+
var _colors = require("@chayns/colors");
|
|
8
|
+
const getColorFromCoordinates = _ref => {
|
|
9
|
+
var _canvas$current, _pixels$, _pixels$2, _pixels$3;
|
|
10
|
+
let {
|
|
11
|
+
coordinates,
|
|
12
|
+
canvas,
|
|
13
|
+
opacity,
|
|
14
|
+
scale
|
|
15
|
+
} = _ref;
|
|
16
|
+
if (!canvas.current) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
top,
|
|
21
|
+
left
|
|
22
|
+
} = canvas.current.getBoundingClientRect();
|
|
23
|
+
const x = (coordinates.x - left) * scale.scaleX;
|
|
24
|
+
const y = (coordinates.y - top) * scale.scaleY;
|
|
25
|
+
const ctx = (_canvas$current = canvas.current) === null || _canvas$current === void 0 ? void 0 : _canvas$current.getContext('2d');
|
|
26
|
+
const pixels = ctx === null || ctx === void 0 ? void 0 : ctx.getImageData(x, y, 1, 1).data;
|
|
27
|
+
if (!pixels) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If transparency
|
|
32
|
+
if (pixels[0] === 0 && pixels[1] === 0 && pixels[2] === 0 && pixels[3] === 0) {
|
|
33
|
+
return 'transparent';
|
|
34
|
+
}
|
|
35
|
+
return `rgba(${(_pixels$ = pixels[0]) !== null && _pixels$ !== void 0 ? _pixels$ : 0}, ${(_pixels$2 = pixels[1]) !== null && _pixels$2 !== void 0 ? _pixels$2 : 0}, ${(_pixels$3 = pixels[2]) !== null && _pixels$3 !== void 0 ? _pixels$3 : 0}, ${opacity})`;
|
|
36
|
+
};
|
|
37
|
+
exports.getColorFromCoordinates = getColorFromCoordinates;
|
|
38
|
+
const getCoordinatesFromColor = _ref2 => {
|
|
39
|
+
var _canvas$current2;
|
|
40
|
+
let {
|
|
41
|
+
canvas,
|
|
42
|
+
color
|
|
43
|
+
} = _ref2;
|
|
44
|
+
const ctx = (_canvas$current2 = canvas.current) === null || _canvas$current2 === void 0 ? void 0 : _canvas$current2.getContext('2d');
|
|
45
|
+
if (!ctx || !color) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const {
|
|
49
|
+
data
|
|
50
|
+
} = ctx.getImageData(0, 0, 300, 150); /// get image data
|
|
51
|
+
let x = 0;
|
|
52
|
+
let y = 0;
|
|
53
|
+
const rgb = splitRgb(color);
|
|
54
|
+
if (!rgb) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
console.log('DATA', data);
|
|
58
|
+
console.log('RGBA', rgb);
|
|
59
|
+
|
|
60
|
+
// iterating x/y instead of forward to get position the easy way
|
|
61
|
+
for (; y < 150; y++) {
|
|
62
|
+
// common value for all x
|
|
63
|
+
const p = y * 4 * 300;
|
|
64
|
+
for (x = 0; x < 300; x++) {
|
|
65
|
+
// next pixel (skipping 4 bytes as each pixel is RGBA bytes)
|
|
66
|
+
const px = p + x * 4;
|
|
67
|
+
|
|
68
|
+
// if red component match check the others
|
|
69
|
+
if (data[px] === rgb.r) {
|
|
70
|
+
if (data[px + 1] === rgb.g && data[px + 2] === rgb.b) {
|
|
71
|
+
return {
|
|
72
|
+
x,
|
|
73
|
+
y
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
};
|
|
81
|
+
exports.getCoordinatesFromColor = getCoordinatesFromColor;
|
|
82
|
+
const convertColorToHsl = color => {
|
|
83
|
+
const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
84
|
+
const rgbRegex = /^rgb(a)?\(\s*((25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})\s*,\s*){2}(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})\s*(,\s*\d+(\.\d+)?)?\)$/i;
|
|
85
|
+
const hslRegex = /^hsla?\(\s*((360|3[0-5]\d|[12]\d{2}|[1-9]\d|\d)\s*,\s*){2}(360|3[0-5]\d|[12]\d{2}|[1-9]\d|\d)\s*(,\s*\d+(\.\d+)?)?\)$/i;
|
|
86
|
+
let rgba;
|
|
87
|
+
let hsl;
|
|
88
|
+
const newColor = color.replaceAll('%', '');
|
|
89
|
+
switch (true) {
|
|
90
|
+
case hexRegex.test(newColor):
|
|
91
|
+
hsl = (0, _colors.hexToHsl)(color);
|
|
92
|
+
if (!hsl) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return `hsl(${Math.floor(hsl.h)},100%,50%)`;
|
|
96
|
+
case rgbRegex.test(newColor):
|
|
97
|
+
rgba = color.match(/[\d.]+/g);
|
|
98
|
+
if (!rgba) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
hsl = (0, _colors.rgb255ToHsl)({
|
|
102
|
+
r: Number(rgba[0]),
|
|
103
|
+
g: Number(rgba[1]),
|
|
104
|
+
b: Number(rgba[2])
|
|
105
|
+
});
|
|
106
|
+
if (!hsl) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return `hsl(${Math.floor(hsl.h)},100%,50%)`;
|
|
110
|
+
case hslRegex.test(newColor):
|
|
111
|
+
return color;
|
|
112
|
+
default:
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
exports.convertColorToHsl = convertColorToHsl;
|
|
117
|
+
const splitRgb = color => {
|
|
118
|
+
const rgba = color === null || color === void 0 ? void 0 : color.match(/[\d.]+/g);
|
|
119
|
+
if (!rgba) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
r: Number(rgba[0]),
|
|
124
|
+
g: Number(rgba[1]),
|
|
125
|
+
b: Number(rgba[2]),
|
|
126
|
+
a: Number(rgba[3])
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
exports.splitRgb = splitRgb;
|
|
130
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":["_colors","require","getColorFromCoordinates","_ref","_canvas$current","_pixels$","_pixels$2","_pixels$3","coordinates","canvas","opacity","scale","current","undefined","top","left","getBoundingClientRect","x","scaleX","y","scaleY","ctx","getContext","pixels","getImageData","data","exports","getCoordinatesFromColor","_ref2","_canvas$current2","color","rgb","splitRgb","console","log","p","px","r","g","b","convertColorToHsl","hexRegex","rgbRegex","hslRegex","rgba","hsl","newColor","replaceAll","test","hexToHsl","Math","floor","h","match","rgb255ToHsl","Number","a"],"sources":["../../src/utils/color.ts"],"sourcesContent":["import { hexToHsl, rgb255ToHsl } from '@chayns/colors';\nimport type { HSL, HSLA } from '@chayns/colors/lib/types/hsl';\nimport type { CSSProperties, RefObject } from 'react';\nimport type { Coordinates, RGB, Scale } from '../types';\n\ninterface GetColorFromCoordinatesOptions {\n coordinates: Coordinates;\n canvas: RefObject<HTMLCanvasElement>;\n opacity: number;\n scale: Scale;\n}\n\nexport const getColorFromCoordinates = ({\n coordinates,\n canvas,\n opacity,\n scale,\n}: GetColorFromCoordinatesOptions) => {\n if (!canvas.current) {\n return undefined;\n }\n\n const { top, left } = canvas.current.getBoundingClientRect();\n\n const x = (coordinates.x - left) * scale.scaleX;\n const y = (coordinates.y - top) * scale.scaleY;\n\n const ctx = canvas.current?.getContext('2d');\n const pixels = ctx?.getImageData(x, y, 1, 1).data;\n\n if (!pixels) {\n return undefined;\n }\n\n // If transparency\n if (pixels[0] === 0 && pixels[1] === 0 && pixels[2] === 0 && pixels[3] === 0) {\n return 'transparent';\n }\n\n return `rgba(${pixels[0] ?? 0}, ${pixels[1] ?? 0}, ${pixels[2] ?? 0}, ${opacity})`;\n};\n\ninterface GetCoordinatesFromColorOptions {\n color: CSSProperties['color'];\n canvas: RefObject<HTMLCanvasElement>;\n}\n\nexport const getCoordinatesFromColor = ({ canvas, color }: GetCoordinatesFromColorOptions) => {\n const ctx = canvas.current?.getContext('2d');\n\n if (!ctx || !color) {\n return undefined;\n }\n\n const { data } = ctx.getImageData(0, 0, 300, 150); /// get image data\n let x = 0;\n let y = 0;\n\n const rgb = splitRgb(color);\n\n if (!rgb) {\n return undefined;\n }\n\n console.log('DATA', data);\n\n console.log('RGBA', rgb);\n\n // iterating x/y instead of forward to get position the easy way\n for (; y < 150; y++) {\n // common value for all x\n const p = y * 4 * 300;\n\n for (x = 0; x < 300; x++) {\n // next pixel (skipping 4 bytes as each pixel is RGBA bytes)\n const px = p + x * 4;\n\n // if red component match check the others\n if (data[px] === rgb.r) {\n if (data[px + 1] === rgb.g && data[px + 2] === rgb.b) {\n return { x, y };\n }\n }\n }\n }\n return null;\n};\n\nexport const convertColorToHsl = (color: string) => {\n const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;\n const rgbRegex =\n /^rgb(a)?\\(\\s*((25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\s*,\\s*){2}(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\s*(,\\s*\\d+(\\.\\d+)?)?\\)$/i;\n const hslRegex =\n /^hsla?\\(\\s*((360|3[0-5]\\d|[12]\\d{2}|[1-9]\\d|\\d)\\s*,\\s*){2}(360|3[0-5]\\d|[12]\\d{2}|[1-9]\\d|\\d)\\s*(,\\s*\\d+(\\.\\d+)?)?\\)$/i;\n\n let rgba: string[] | null;\n let hsl: HSL | HSLA | null;\n\n const newColor = color.replaceAll('%', '');\n\n switch (true) {\n case hexRegex.test(newColor):\n hsl = hexToHsl(color);\n\n if (!hsl) {\n return undefined;\n }\n\n return `hsl(${Math.floor(hsl.h)},100%,50%)`;\n case rgbRegex.test(newColor):\n rgba = color.match(/[\\d.]+/g);\n\n if (!rgba) {\n return undefined;\n }\n\n hsl = rgb255ToHsl({\n r: Number(rgba[0]),\n g: Number(rgba[1]),\n b: Number(rgba[2]),\n });\n\n if (!hsl) {\n return undefined;\n }\n\n return `hsl(${Math.floor(hsl.h)},100%,50%)`;\n case hslRegex.test(newColor):\n return color;\n default:\n return undefined;\n }\n};\n\nexport const splitRgb = (color: CSSProperties['color']): null | RGB => {\n const rgba = color?.match(/[\\d.]+/g);\n\n if (!rgba) {\n return null;\n }\n\n return { r: Number(rgba[0]), g: Number(rgba[1]), b: Number(rgba[2]), a: Number(rgba[3]) };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAYO,MAAMC,uBAAuB,GAAGC,IAAA,IAKD;EAAA,IAAAC,eAAA,EAAAC,QAAA,EAAAC,SAAA,EAAAC,SAAA;EAAA,IALE;IACpCC,WAAW;IACXC,MAAM;IACNC,OAAO;IACPC;EAC4B,CAAC,GAAAR,IAAA;EAC7B,IAAI,CAACM,MAAM,CAACG,OAAO,EAAE;IACjB,OAAOC,SAAS;EACpB;EAEA,MAAM;IAAEC,GAAG;IAAEC;EAAK,CAAC,GAAGN,MAAM,CAACG,OAAO,CAACI,qBAAqB,CAAC,CAAC;EAE5D,MAAMC,CAAC,GAAG,CAACT,WAAW,CAACS,CAAC,GAAGF,IAAI,IAAIJ,KAAK,CAACO,MAAM;EAC/C,MAAMC,CAAC,GAAG,CAACX,WAAW,CAACW,CAAC,GAAGL,GAAG,IAAIH,KAAK,CAACS,MAAM;EAE9C,MAAMC,GAAG,IAAAjB,eAAA,GAAGK,MAAM,CAACG,OAAO,cAAAR,eAAA,uBAAdA,eAAA,CAAgBkB,UAAU,CAAC,IAAI,CAAC;EAC5C,MAAMC,MAAM,GAAGF,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEG,YAAY,CAACP,CAAC,EAAEE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAACM,IAAI;EAEjD,IAAI,CAACF,MAAM,EAAE;IACT,OAAOV,SAAS;EACpB;;EAEA;EACA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|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chayns-components/color-picker",
|
|
3
|
+
"version": "5.0.0-beta.217",
|
|
4
|
+
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chayns",
|
|
7
|
+
"react",
|
|
8
|
+
"components"
|
|
9
|
+
],
|
|
10
|
+
"author": "Tobit.Software",
|
|
11
|
+
"homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/color-picker#readme",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"types": "lib/index.d.ts",
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "lib",
|
|
17
|
+
"test": "__tests__"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/TobitSoftware/chayns-components.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "npm run build:js && npm run build:types",
|
|
28
|
+
"build:js": "babel src --out-dir lib --extensions=.ts,.tsx --source-maps --ignore=src/stories",
|
|
29
|
+
"build:types": "tsc",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/TobitSoftware/chayns-components/issues"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@babel/cli": "^7.21.5",
|
|
37
|
+
"@babel/core": "^7.22.1",
|
|
38
|
+
"@babel/preset-env": "^7.22.4",
|
|
39
|
+
"@babel/preset-react": "^7.22.3",
|
|
40
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
41
|
+
"@types/react": "^17.0.60",
|
|
42
|
+
"@types/react-dom": "^17.0.20",
|
|
43
|
+
"@types/styled-components": "^5.1.26",
|
|
44
|
+
"@types/uuid": "^9.0.1",
|
|
45
|
+
"babel-loader": "^8.3.0",
|
|
46
|
+
"lerna": "^6.6.2",
|
|
47
|
+
"react": "^17.0.2",
|
|
48
|
+
"react-dom": "^17.0.2",
|
|
49
|
+
"styled-components": "^5.3.11",
|
|
50
|
+
"typescript": "^4.9.5"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@chayns-components/core": "^5.0.0-beta.217",
|
|
54
|
+
"@chayns/colors": "^2.0.0",
|
|
55
|
+
"clsx": "^1.2.1",
|
|
56
|
+
"framer-motion": "^6.5.1",
|
|
57
|
+
"uuid": "^9.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": ">=16.14.0",
|
|
61
|
+
"react-dom": ">=16.14.0",
|
|
62
|
+
"styled-components": ">=5.0.0"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
},
|
|
67
|
+
"gitHead": "b2000efd734dadf7b5084690838b9a8eedbafb9d"
|
|
68
|
+
}
|