react-color-palette-wheel 0.0.1 → 0.0.3
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 +44 -62
- package/dist/react-color-palette-wheel.es.js +277 -535
- package/dist/react-color-palette-wheel.umd.js +1 -6
- package/package.json +25 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Milles Dyson Schroeder
|
|
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
CHANGED
|
@@ -1,73 +1,55 @@
|
|
|
1
|
-
# React
|
|
1
|
+
# 🎨 React Color Palette Wheel
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A professional, lightweight, and fully typed color wheel component for React. Inspired by tools like Adobe Color, this library allows color selection based on **Chromatic Harmonies** (Triad, Complementary, Analogous, etc.) with geometric precision.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
## ✨ Highlights
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
* **Ultra Lightweight:** Only **~16.4kB** (packed).
|
|
12
|
+
* **Mathematical Harmonies:** Precise algorithms for complex color schemes.
|
|
13
|
+
* **TypeScript:** Native type definitions (`.d.ts`) included.
|
|
14
|
+
* **Performance:** Optimized Canvas rendering.
|
|
15
|
+
* **Zero Config:** Works out of the box with sensible defaults.
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
## 📦 Installation
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm install react-color-palette-wheel
|
|
21
|
+
# or
|
|
22
|
+
yarn add react-color-palette-wheel
|
|
15
23
|
|
|
16
|
-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
export default defineConfig([
|
|
20
|
-
globalIgnores(['dist']),
|
|
21
|
-
{
|
|
22
|
-
files: ['**/*.{ts,tsx}'],
|
|
23
|
-
extends: [
|
|
24
|
-
// Other configs...
|
|
25
|
-
|
|
26
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
-
tseslint.configs.recommendedTypeChecked,
|
|
28
|
-
// Alternatively, use this for stricter rules
|
|
29
|
-
tseslint.configs.strictTypeChecked,
|
|
30
|
-
// Optionally, add this for stylistic rules
|
|
31
|
-
tseslint.configs.stylisticTypeChecked,
|
|
32
|
-
|
|
33
|
-
// Other configs...
|
|
34
|
-
],
|
|
35
|
-
languageOptions: {
|
|
36
|
-
parserOptions: {
|
|
37
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
-
tsconfigRootDir: import.meta.dirname,
|
|
39
|
-
},
|
|
40
|
-
// other options...
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
])
|
|
44
24
|
```
|
|
45
25
|
|
|
46
|
-
|
|
26
|
+
## 🚀 Basic Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { useState } from 'react';
|
|
30
|
+
import { ColorWheel, HarmonyType, CursorData } from 'react-color-palette-wheel';
|
|
31
|
+
|
|
32
|
+
function App() {
|
|
33
|
+
const [colors, setColors] = useState<CursorData[]>([]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div>
|
|
37
|
+
<h1>Harmony Selector</h1>
|
|
38
|
+
|
|
39
|
+
<ColorWheel
|
|
40
|
+
radius={250} // Wheel radius (Total diameter: 500px)
|
|
41
|
+
harmony={HarmonyType.Triad} // Harmony type (e.g., Triad)
|
|
42
|
+
onChange={setColors} // Callback with selected colors
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
## 🛠️ Build Details
|
|
50
|
+
* **Formats:** ESM (.es.js) and UMD (.umd.js).
|
|
51
|
+
* **Size:** ~16kB (Minified + Gzipped).
|
|
52
|
+
* **Typing:** Full TypeScript support.
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
files: ['**/*.{ts,tsx}'],
|
|
57
|
-
extends: [
|
|
58
|
-
// Other configs...
|
|
59
|
-
// Enable lint rules for React
|
|
60
|
-
reactX.configs['recommended-typescript'],
|
|
61
|
-
// Enable lint rules for React DOM
|
|
62
|
-
reactDom.configs.recommended,
|
|
63
|
-
],
|
|
64
|
-
languageOptions: {
|
|
65
|
-
parserOptions: {
|
|
66
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
-
tsconfigRootDir: import.meta.dirname,
|
|
68
|
-
},
|
|
69
|
-
// other options...
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
])
|
|
73
|
-
```
|
|
54
|
+
## 📄 License
|
|
55
|
+
MIT
|
|
@@ -1,408 +1,150 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return e(n(u));
|
|
67
|
-
} catch {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
function t(n) {
|
|
73
|
-
return "" + n;
|
|
74
|
-
}
|
|
75
|
-
function r(n) {
|
|
76
|
-
try {
|
|
77
|
-
t(n);
|
|
78
|
-
var u = !1;
|
|
79
|
-
} catch {
|
|
80
|
-
u = !0;
|
|
81
|
-
}
|
|
82
|
-
if (u) {
|
|
83
|
-
u = console;
|
|
84
|
-
var b = u.error, g = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
|
|
85
|
-
return b.call(
|
|
86
|
-
u,
|
|
87
|
-
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
-
g
|
|
89
|
-
), t(n);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function o(n) {
|
|
93
|
-
if (n === y) return "<>";
|
|
94
|
-
if (typeof n == "object" && n !== null && n.$$typeof === O)
|
|
95
|
-
return "<...>";
|
|
96
|
-
try {
|
|
97
|
-
var u = e(n);
|
|
98
|
-
return u ? "<" + u + ">" : "<...>";
|
|
99
|
-
} catch {
|
|
100
|
-
return "<...>";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function a() {
|
|
104
|
-
var n = F.A;
|
|
105
|
-
return n === null ? null : n.getOwner();
|
|
106
|
-
}
|
|
107
|
-
function s() {
|
|
108
|
-
return Error("react-stack-top-frame");
|
|
109
|
-
}
|
|
110
|
-
function i(n) {
|
|
111
|
-
if (D.call(n, "key")) {
|
|
112
|
-
var u = Object.getOwnPropertyDescriptor(n, "key").get;
|
|
113
|
-
if (u && u.isReactWarning) return !1;
|
|
114
|
-
}
|
|
115
|
-
return n.key !== void 0;
|
|
116
|
-
}
|
|
117
|
-
function d(n, u) {
|
|
118
|
-
function b() {
|
|
119
|
-
ne || (ne = !0, console.error(
|
|
120
|
-
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
121
|
-
u
|
|
122
|
-
));
|
|
123
|
-
}
|
|
124
|
-
b.isReactWarning = !0, Object.defineProperty(n, "key", {
|
|
125
|
-
get: b,
|
|
126
|
-
configurable: !0
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function _() {
|
|
130
|
-
var n = e(this.type);
|
|
131
|
-
return oe[n] || (oe[n] = !0, console.error(
|
|
132
|
-
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
133
|
-
)), n = this.props.ref, n !== void 0 ? n : null;
|
|
134
|
-
}
|
|
135
|
-
function m(n, u, b, g, z, B) {
|
|
136
|
-
var v = b.ref;
|
|
137
|
-
return n = {
|
|
138
|
-
$$typeof: f,
|
|
139
|
-
type: n,
|
|
140
|
-
key: u,
|
|
141
|
-
props: b,
|
|
142
|
-
_owner: g
|
|
143
|
-
}, (v !== void 0 ? v : null) !== null ? Object.defineProperty(n, "ref", {
|
|
144
|
-
enumerable: !1,
|
|
145
|
-
get: _
|
|
146
|
-
}) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
|
|
147
|
-
configurable: !1,
|
|
148
|
-
enumerable: !1,
|
|
149
|
-
writable: !0,
|
|
150
|
-
value: 0
|
|
151
|
-
}), Object.defineProperty(n, "_debugInfo", {
|
|
152
|
-
configurable: !1,
|
|
153
|
-
enumerable: !1,
|
|
154
|
-
writable: !0,
|
|
155
|
-
value: null
|
|
156
|
-
}), Object.defineProperty(n, "_debugStack", {
|
|
157
|
-
configurable: !1,
|
|
158
|
-
enumerable: !1,
|
|
159
|
-
writable: !0,
|
|
160
|
-
value: z
|
|
161
|
-
}), Object.defineProperty(n, "_debugTask", {
|
|
162
|
-
configurable: !1,
|
|
163
|
-
enumerable: !1,
|
|
164
|
-
writable: !0,
|
|
165
|
-
value: B
|
|
166
|
-
}), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
|
|
167
|
-
}
|
|
168
|
-
function h(n, u, b, g, z, B) {
|
|
169
|
-
var v = u.children;
|
|
170
|
-
if (v !== void 0)
|
|
171
|
-
if (g)
|
|
172
|
-
if (L(v)) {
|
|
173
|
-
for (g = 0; g < v.length; g++)
|
|
174
|
-
N(v[g]);
|
|
175
|
-
Object.freeze && Object.freeze(v);
|
|
176
|
-
} else
|
|
177
|
-
console.error(
|
|
178
|
-
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
-
);
|
|
180
|
-
else N(v);
|
|
181
|
-
if (D.call(u, "key")) {
|
|
182
|
-
v = e(n);
|
|
183
|
-
var I = Object.keys(u).filter(function(we) {
|
|
184
|
-
return we !== "key";
|
|
185
|
-
});
|
|
186
|
-
g = 0 < I.length ? "{key: someKey, " + I.join(": ..., ") + ": ...}" : "{key: someKey}", ie[v + g] || (I = 0 < I.length ? "{" + I.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
-
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
-
let props = %s;
|
|
189
|
-
<%s {...props} />
|
|
190
|
-
React keys must be passed directly to JSX without using spread:
|
|
191
|
-
let props = %s;
|
|
192
|
-
<%s key={someKey} {...props} />`,
|
|
193
|
-
g,
|
|
194
|
-
v,
|
|
195
|
-
I,
|
|
196
|
-
v
|
|
197
|
-
), ie[v + g] = !0);
|
|
198
|
-
}
|
|
199
|
-
if (v = null, b !== void 0 && (r(b), v = "" + b), i(u) && (r(u.key), v = "" + u.key), "key" in u) {
|
|
200
|
-
b = {};
|
|
201
|
-
for (var Z in u)
|
|
202
|
-
Z !== "key" && (b[Z] = u[Z]);
|
|
203
|
-
} else b = u;
|
|
204
|
-
return v && d(
|
|
205
|
-
b,
|
|
206
|
-
typeof n == "function" ? n.displayName || n.name || "Unknown" : n
|
|
207
|
-
), m(
|
|
208
|
-
n,
|
|
209
|
-
v,
|
|
210
|
-
b,
|
|
211
|
-
a(),
|
|
212
|
-
z,
|
|
213
|
-
B
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
function N(n) {
|
|
217
|
-
c(n) ? n._store && (n._store.validated = 1) : typeof n == "object" && n !== null && n.$$typeof === O && (n._payload.status === "fulfilled" ? c(n._payload.value) && n._payload.value._store && (n._payload.value._store.validated = 1) : n._store && (n._store.validated = 1));
|
|
218
|
-
}
|
|
219
|
-
function c(n) {
|
|
220
|
-
return typeof n == "object" && n !== null && n.$$typeof === f;
|
|
221
|
-
}
|
|
222
|
-
var l = Se, f = /* @__PURE__ */ Symbol.for("react.transitional.element"), p = /* @__PURE__ */ Symbol.for("react.portal"), y = /* @__PURE__ */ Symbol.for("react.fragment"), x = /* @__PURE__ */ Symbol.for("react.strict_mode"), P = /* @__PURE__ */ Symbol.for("react.profiler"), j = /* @__PURE__ */ Symbol.for("react.consumer"), k = /* @__PURE__ */ Symbol.for("react.context"), R = /* @__PURE__ */ Symbol.for("react.forward_ref"), V = /* @__PURE__ */ Symbol.for("react.suspense"), q = /* @__PURE__ */ Symbol.for("react.suspense_list"), A = /* @__PURE__ */ Symbol.for("react.memo"), O = /* @__PURE__ */ Symbol.for("react.lazy"), H = /* @__PURE__ */ Symbol.for("react.activity"), G = /* @__PURE__ */ Symbol.for("react.client.reference"), F = l.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, L = Array.isArray, J = console.createTask ? console.createTask : function() {
|
|
223
|
-
return null;
|
|
224
|
-
};
|
|
225
|
-
l = {
|
|
226
|
-
react_stack_bottom_frame: function(n) {
|
|
227
|
-
return n();
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
var ne, oe = {}, ae = l.react_stack_bottom_frame.bind(
|
|
231
|
-
l,
|
|
232
|
-
s
|
|
233
|
-
)(), se = J(o(s)), ie = {};
|
|
234
|
-
Y.Fragment = y, Y.jsx = function(n, u, b) {
|
|
235
|
-
var g = 1e4 > F.recentlyCreatedOwnerStacks++;
|
|
236
|
-
return h(
|
|
237
|
-
n,
|
|
238
|
-
u,
|
|
239
|
-
b,
|
|
240
|
-
!1,
|
|
241
|
-
g ? Error("react-stack-top-frame") : ae,
|
|
242
|
-
g ? J(o(n)) : se
|
|
243
|
-
);
|
|
244
|
-
}, Y.jsxs = function(n, u, b) {
|
|
245
|
-
var g = 1e4 > F.recentlyCreatedOwnerStacks++;
|
|
246
|
-
return h(
|
|
247
|
-
n,
|
|
248
|
-
u,
|
|
249
|
-
b,
|
|
250
|
-
!0,
|
|
251
|
-
g ? Error("react-stack-top-frame") : ae,
|
|
252
|
-
g ? J(o(n)) : se
|
|
253
|
-
);
|
|
254
|
-
};
|
|
255
|
-
})()), Y;
|
|
256
|
-
}
|
|
257
|
-
var fe;
|
|
258
|
-
function Te() {
|
|
259
|
-
return fe || (fe = 1, process.env.NODE_ENV === "production" ? X.exports = Ce() : X.exports = ke()), X.exports;
|
|
260
|
-
}
|
|
261
|
-
var M = Te(), Ae = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, T = function(e) {
|
|
262
|
-
return typeof e == "string" ? e.length > 0 : typeof e == "number";
|
|
263
|
-
}, E = function(e, t, r) {
|
|
264
|
-
return t === void 0 && (t = 0), r === void 0 && (r = Math.pow(10, t)), Math.round(r * e) / r + 0;
|
|
265
|
-
}, S = function(e, t, r) {
|
|
266
|
-
return t === void 0 && (t = 0), r === void 0 && (r = 1), e > r ? r : e > t ? e : t;
|
|
267
|
-
}, Ee = function(e) {
|
|
268
|
-
return (e = isFinite(e) ? e % 360 : 0) > 0 ? e : e + 360;
|
|
269
|
-
}, de = function(e) {
|
|
270
|
-
return { r: S(e.r, 0, 255), g: S(e.g, 0, 255), b: S(e.b, 0, 255), a: S(e.a) };
|
|
271
|
-
}, ee = function(e) {
|
|
272
|
-
return { r: E(e.r), g: E(e.g), b: E(e.b), a: E(e.a, 3) };
|
|
273
|
-
}, Me = /^#([0-9a-f]{3,8})$/i, U = function(e) {
|
|
274
|
-
var t = e.toString(16);
|
|
275
|
-
return t.length < 2 ? "0" + t : t;
|
|
276
|
-
}, _e = function(e) {
|
|
277
|
-
var t = e.r, r = e.g, o = e.b, a = e.a, s = Math.max(t, r, o), i = s - Math.min(t, r, o), d = i ? s === t ? (r - o) / i : s === r ? 2 + (o - t) / i : 4 + (t - r) / i : 0;
|
|
278
|
-
return { h: 60 * (d < 0 ? d + 6 : d), s: s ? i / s * 100 : 0, v: s / 255 * 100, a };
|
|
279
|
-
}, Pe = function(e) {
|
|
280
|
-
var t = e.h, r = e.s, o = e.v, a = e.a;
|
|
281
|
-
t = t / 360 * 6, r /= 100, o /= 100;
|
|
282
|
-
var s = Math.floor(t), i = o * (1 - r), d = o * (1 - (t - s) * r), _ = o * (1 - (1 - t + s) * r), m = s % 6;
|
|
283
|
-
return { r: 255 * [o, d, i, i, _, o][m], g: 255 * [_, o, o, d, i, i][m], b: 255 * [i, i, _, o, o, d][m], a };
|
|
284
|
-
}, pe = function(e) {
|
|
285
|
-
return { h: Ee(e.h), s: S(e.s, 0, 100), l: S(e.l, 0, 100), a: S(e.a) };
|
|
286
|
-
}, he = function(e) {
|
|
287
|
-
return { h: E(e.h), s: E(e.s), l: E(e.l), a: E(e.a, 3) };
|
|
288
|
-
}, be = function(e) {
|
|
289
|
-
return Pe((r = (t = e).s, { h: t.h, s: (r *= ((o = t.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * r / (o + r) * 100 : 0, v: o + r, a: t.a }));
|
|
290
|
-
var t, r, o;
|
|
291
|
-
}, W = function(e) {
|
|
292
|
-
return { h: (t = _e(e)).h, s: (a = (200 - (r = t.s)) * (o = t.v) / 100) > 0 && a < 200 ? r * o / 100 / (a <= 100 ? a : 200 - a) * 100 : 0, l: a / 2, a: t.a };
|
|
293
|
-
var t, r, o, a;
|
|
294
|
-
}, Ne = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, je = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Oe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, Fe = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ge = { string: [[function(e) {
|
|
295
|
-
var t = Me.exec(e);
|
|
296
|
-
return t ? (e = t[1]).length <= 4 ? { r: parseInt(e[0] + e[0], 16), g: parseInt(e[1] + e[1], 16), b: parseInt(e[2] + e[2], 16), a: e.length === 4 ? E(parseInt(e[3] + e[3], 16) / 255, 2) : 1 } : e.length === 6 || e.length === 8 ? { r: parseInt(e.substr(0, 2), 16), g: parseInt(e.substr(2, 2), 16), b: parseInt(e.substr(4, 2), 16), a: e.length === 8 ? E(parseInt(e.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
297
|
-
}, "hex"], [function(e) {
|
|
298
|
-
var t = Oe.exec(e) || Fe.exec(e);
|
|
299
|
-
return t ? t[2] !== t[4] || t[4] !== t[6] ? null : de({ r: Number(t[1]) / (t[2] ? 100 / 255 : 1), g: Number(t[3]) / (t[4] ? 100 / 255 : 1), b: Number(t[5]) / (t[6] ? 100 / 255 : 1), a: t[7] === void 0 ? 1 : Number(t[7]) / (t[8] ? 100 : 1) }) : null;
|
|
300
|
-
}, "rgb"], [function(e) {
|
|
301
|
-
var t = Ne.exec(e) || je.exec(e);
|
|
302
|
-
if (!t) return null;
|
|
303
|
-
var r, o, a = pe({ h: (r = t[1], o = t[2], o === void 0 && (o = "deg"), Number(r) * (Ae[o] || 1)), s: Number(t[3]), l: Number(t[4]), a: t[5] === void 0 ? 1 : Number(t[5]) / (t[6] ? 100 : 1) });
|
|
304
|
-
return be(a);
|
|
305
|
-
}, "hsl"]], object: [[function(e) {
|
|
306
|
-
var t = e.r, r = e.g, o = e.b, a = e.a, s = a === void 0 ? 1 : a;
|
|
307
|
-
return T(t) && T(r) && T(o) ? de({ r: Number(t), g: Number(r), b: Number(o), a: Number(s) }) : null;
|
|
308
|
-
}, "rgb"], [function(e) {
|
|
309
|
-
var t = e.h, r = e.s, o = e.l, a = e.a, s = a === void 0 ? 1 : a;
|
|
310
|
-
if (!T(t) || !T(r) || !T(o)) return null;
|
|
311
|
-
var i = pe({ h: Number(t), s: Number(r), l: Number(o), a: Number(s) });
|
|
312
|
-
return be(i);
|
|
313
|
-
}, "hsl"], [function(e) {
|
|
314
|
-
var t = e.h, r = e.s, o = e.v, a = e.a, s = a === void 0 ? 1 : a;
|
|
315
|
-
if (!T(t) || !T(r) || !T(o)) return null;
|
|
316
|
-
var i = (function(d) {
|
|
317
|
-
return { h: Ee(d.h), s: S(d.s, 0, 100), v: S(d.v, 0, 100), a: S(d.a) };
|
|
318
|
-
})({ h: Number(t), s: Number(r), v: Number(o), a: Number(s) });
|
|
319
|
-
return Pe(i);
|
|
320
|
-
}, "hsv"]] }, ve = function(e, t) {
|
|
321
|
-
for (var r = 0; r < t.length; r++) {
|
|
322
|
-
var o = t[r][0](e);
|
|
323
|
-
if (o) return [o, t[r][1]];
|
|
1
|
+
import { jsx as S, jsxs as rt } from "react/jsx-runtime";
|
|
2
|
+
import { useState as Z, useRef as k, useCallback as A, useEffect as G } from "react";
|
|
3
|
+
var at = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, w = function(t) {
|
|
4
|
+
return typeof t == "string" ? t.length > 0 : typeof t == "number";
|
|
5
|
+
}, d = function(t, n, e) {
|
|
6
|
+
return n === void 0 && (n = 0), e === void 0 && (e = Math.pow(10, n)), Math.round(e * t) / e + 0;
|
|
7
|
+
}, M = function(t, n, e) {
|
|
8
|
+
return n === void 0 && (n = 0), e === void 0 && (e = 1), t > e ? e : t > n ? t : n;
|
|
9
|
+
}, U = function(t) {
|
|
10
|
+
return (t = isFinite(t) ? t % 360 : 0) > 0 ? t : t + 360;
|
|
11
|
+
}, L = function(t) {
|
|
12
|
+
return { r: M(t.r, 0, 255), g: M(t.g, 0, 255), b: M(t.b, 0, 255), a: M(t.a) };
|
|
13
|
+
}, H = function(t) {
|
|
14
|
+
return { r: d(t.r), g: d(t.g), b: d(t.b), a: d(t.a, 3) };
|
|
15
|
+
}, st = /^#([0-9a-f]{3,8})$/i, D = function(t) {
|
|
16
|
+
var n = t.toString(16);
|
|
17
|
+
return n.length < 2 ? "0" + n : n;
|
|
18
|
+
}, tt = function(t) {
|
|
19
|
+
var n = t.r, e = t.g, o = t.b, r = t.a, a = Math.max(n, e, o), s = a - Math.min(n, e, o), f = s ? a === n ? (e - o) / s : a === e ? 2 + (o - n) / s : 4 + (n - e) / s : 0;
|
|
20
|
+
return { h: 60 * (f < 0 ? f + 6 : f), s: a ? s / a * 100 : 0, v: a / 255 * 100, a: r };
|
|
21
|
+
}, nt = function(t) {
|
|
22
|
+
var n = t.h, e = t.s, o = t.v, r = t.a;
|
|
23
|
+
n = n / 360 * 6, e /= 100, o /= 100;
|
|
24
|
+
var a = Math.floor(n), s = o * (1 - e), f = o * (1 - (n - a) * e), m = o * (1 - (1 - n + a) * e), p = a % 6;
|
|
25
|
+
return { r: 255 * [o, f, s, s, m, o][p], g: 255 * [m, o, o, f, s, s][p], b: 255 * [s, s, m, o, o, f][p], a: r };
|
|
26
|
+
}, B = function(t) {
|
|
27
|
+
return { h: U(t.h), s: M(t.s, 0, 100), l: M(t.l, 0, 100), a: M(t.a) };
|
|
28
|
+
}, O = function(t) {
|
|
29
|
+
return { h: d(t.h), s: d(t.s), l: d(t.l), a: d(t.a, 3) };
|
|
30
|
+
}, T = function(t) {
|
|
31
|
+
return nt((e = (n = t).s, { h: n.h, s: (e *= ((o = n.l) < 50 ? o : 100 - o) / 100) > 0 ? 2 * e / (o + e) * 100 : 0, v: o + e, a: n.a }));
|
|
32
|
+
var n, e, o;
|
|
33
|
+
}, I = function(t) {
|
|
34
|
+
return { h: (n = tt(t)).h, s: (r = (200 - (e = n.s)) * (o = n.v) / 100) > 0 && r < 200 ? e * o / 100 / (r <= 100 ? r : 200 - r) * 100 : 0, l: r / 2, a: n.a };
|
|
35
|
+
var n, e, o, r;
|
|
36
|
+
}, it = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, lt = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ct = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, ut = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i, V = { string: [[function(t) {
|
|
37
|
+
var n = st.exec(t);
|
|
38
|
+
return n ? (t = n[1]).length <= 4 ? { r: parseInt(t[0] + t[0], 16), g: parseInt(t[1] + t[1], 16), b: parseInt(t[2] + t[2], 16), a: t.length === 4 ? d(parseInt(t[3] + t[3], 16) / 255, 2) : 1 } : t.length === 6 || t.length === 8 ? { r: parseInt(t.substr(0, 2), 16), g: parseInt(t.substr(2, 2), 16), b: parseInt(t.substr(4, 2), 16), a: t.length === 8 ? d(parseInt(t.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
|
|
39
|
+
}, "hex"], [function(t) {
|
|
40
|
+
var n = ct.exec(t) || ut.exec(t);
|
|
41
|
+
return n ? n[2] !== n[4] || n[4] !== n[6] ? null : L({ r: Number(n[1]) / (n[2] ? 100 / 255 : 1), g: Number(n[3]) / (n[4] ? 100 / 255 : 1), b: Number(n[5]) / (n[6] ? 100 / 255 : 1), a: n[7] === void 0 ? 1 : Number(n[7]) / (n[8] ? 100 : 1) }) : null;
|
|
42
|
+
}, "rgb"], [function(t) {
|
|
43
|
+
var n = it.exec(t) || lt.exec(t);
|
|
44
|
+
if (!n) return null;
|
|
45
|
+
var e, o, r = B({ h: (e = n[1], o = n[2], o === void 0 && (o = "deg"), Number(e) * (at[o] || 1)), s: Number(n[3]), l: Number(n[4]), a: n[5] === void 0 ? 1 : Number(n[5]) / (n[6] ? 100 : 1) });
|
|
46
|
+
return T(r);
|
|
47
|
+
}, "hsl"]], object: [[function(t) {
|
|
48
|
+
var n = t.r, e = t.g, o = t.b, r = t.a, a = r === void 0 ? 1 : r;
|
|
49
|
+
return w(n) && w(e) && w(o) ? L({ r: Number(n), g: Number(e), b: Number(o), a: Number(a) }) : null;
|
|
50
|
+
}, "rgb"], [function(t) {
|
|
51
|
+
var n = t.h, e = t.s, o = t.l, r = t.a, a = r === void 0 ? 1 : r;
|
|
52
|
+
if (!w(n) || !w(e) || !w(o)) return null;
|
|
53
|
+
var s = B({ h: Number(n), s: Number(e), l: Number(o), a: Number(a) });
|
|
54
|
+
return T(s);
|
|
55
|
+
}, "hsl"], [function(t) {
|
|
56
|
+
var n = t.h, e = t.s, o = t.v, r = t.a, a = r === void 0 ? 1 : r;
|
|
57
|
+
if (!w(n) || !w(e) || !w(o)) return null;
|
|
58
|
+
var s = (function(f) {
|
|
59
|
+
return { h: U(f.h), s: M(f.s, 0, 100), v: M(f.v, 0, 100), a: M(f.a) };
|
|
60
|
+
})({ h: Number(n), s: Number(e), v: Number(o), a: Number(a) });
|
|
61
|
+
return nt(s);
|
|
62
|
+
}, "hsv"]] }, _ = function(t, n) {
|
|
63
|
+
for (var e = 0; e < n.length; e++) {
|
|
64
|
+
var o = n[e][0](t);
|
|
65
|
+
if (o) return [o, n[e][1]];
|
|
324
66
|
}
|
|
325
67
|
return [null, void 0];
|
|
326
|
-
},
|
|
327
|
-
return typeof
|
|
328
|
-
},
|
|
329
|
-
var
|
|
330
|
-
return { h:
|
|
331
|
-
},
|
|
332
|
-
return (299 *
|
|
333
|
-
},
|
|
334
|
-
var
|
|
335
|
-
return { h:
|
|
336
|
-
},
|
|
337
|
-
function
|
|
338
|
-
this.parsed =
|
|
68
|
+
}, ft = function(t) {
|
|
69
|
+
return typeof t == "string" ? _(t.trim(), V.string) : typeof t == "object" && t !== null ? _(t, V.object) : [null, void 0];
|
|
70
|
+
}, $ = function(t, n) {
|
|
71
|
+
var e = I(t);
|
|
72
|
+
return { h: e.h, s: M(e.s + 100 * n, 0, 100), l: e.l, a: e.a };
|
|
73
|
+
}, j = function(t) {
|
|
74
|
+
return (299 * t.r + 587 * t.g + 114 * t.b) / 1e3 / 255;
|
|
75
|
+
}, J = function(t, n) {
|
|
76
|
+
var e = I(t);
|
|
77
|
+
return { h: e.h, s: e.s, l: M(e.l + 100 * n, 0, 100), a: e.a };
|
|
78
|
+
}, K = (function() {
|
|
79
|
+
function t(n) {
|
|
80
|
+
this.parsed = ft(n)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
|
|
339
81
|
}
|
|
340
|
-
return
|
|
82
|
+
return t.prototype.isValid = function() {
|
|
341
83
|
return this.parsed !== null;
|
|
342
|
-
},
|
|
343
|
-
return
|
|
344
|
-
},
|
|
345
|
-
return
|
|
346
|
-
},
|
|
347
|
-
return
|
|
348
|
-
},
|
|
349
|
-
return
|
|
350
|
-
var
|
|
351
|
-
},
|
|
352
|
-
return
|
|
353
|
-
},
|
|
354
|
-
return
|
|
355
|
-
var
|
|
356
|
-
},
|
|
357
|
-
return
|
|
358
|
-
},
|
|
359
|
-
return
|
|
360
|
-
var
|
|
361
|
-
},
|
|
362
|
-
return
|
|
363
|
-
var
|
|
364
|
-
},
|
|
365
|
-
return C({ r: 255 - (
|
|
366
|
-
var
|
|
367
|
-
},
|
|
368
|
-
return
|
|
369
|
-
},
|
|
370
|
-
return
|
|
371
|
-
},
|
|
372
|
-
return C(
|
|
373
|
-
},
|
|
374
|
-
return
|
|
375
|
-
},
|
|
376
|
-
return
|
|
377
|
-
},
|
|
378
|
-
return
|
|
379
|
-
},
|
|
380
|
-
return typeof
|
|
381
|
-
var
|
|
382
|
-
},
|
|
383
|
-
var
|
|
384
|
-
return typeof
|
|
385
|
-
},
|
|
386
|
-
return this.toHex() === C(
|
|
387
|
-
},
|
|
388
|
-
})(), C = function(
|
|
389
|
-
return
|
|
84
|
+
}, t.prototype.brightness = function() {
|
|
85
|
+
return d(j(this.rgba), 2);
|
|
86
|
+
}, t.prototype.isDark = function() {
|
|
87
|
+
return j(this.rgba) < 0.5;
|
|
88
|
+
}, t.prototype.isLight = function() {
|
|
89
|
+
return j(this.rgba) >= 0.5;
|
|
90
|
+
}, t.prototype.toHex = function() {
|
|
91
|
+
return n = H(this.rgba), e = n.r, o = n.g, r = n.b, s = (a = n.a) < 1 ? D(d(255 * a)) : "", "#" + D(e) + D(o) + D(r) + s;
|
|
92
|
+
var n, e, o, r, a, s;
|
|
93
|
+
}, t.prototype.toRgb = function() {
|
|
94
|
+
return H(this.rgba);
|
|
95
|
+
}, t.prototype.toRgbString = function() {
|
|
96
|
+
return n = H(this.rgba), e = n.r, o = n.g, r = n.b, (a = n.a) < 1 ? "rgba(" + e + ", " + o + ", " + r + ", " + a + ")" : "rgb(" + e + ", " + o + ", " + r + ")";
|
|
97
|
+
var n, e, o, r, a;
|
|
98
|
+
}, t.prototype.toHsl = function() {
|
|
99
|
+
return O(I(this.rgba));
|
|
100
|
+
}, t.prototype.toHslString = function() {
|
|
101
|
+
return n = O(I(this.rgba)), e = n.h, o = n.s, r = n.l, (a = n.a) < 1 ? "hsla(" + e + ", " + o + "%, " + r + "%, " + a + ")" : "hsl(" + e + ", " + o + "%, " + r + "%)";
|
|
102
|
+
var n, e, o, r, a;
|
|
103
|
+
}, t.prototype.toHsv = function() {
|
|
104
|
+
return n = tt(this.rgba), { h: d(n.h), s: d(n.s), v: d(n.v), a: d(n.a, 3) };
|
|
105
|
+
var n;
|
|
106
|
+
}, t.prototype.invert = function() {
|
|
107
|
+
return C({ r: 255 - (n = this.rgba).r, g: 255 - n.g, b: 255 - n.b, a: n.a });
|
|
108
|
+
var n;
|
|
109
|
+
}, t.prototype.saturate = function(n) {
|
|
110
|
+
return n === void 0 && (n = 0.1), C($(this.rgba, n));
|
|
111
|
+
}, t.prototype.desaturate = function(n) {
|
|
112
|
+
return n === void 0 && (n = 0.1), C($(this.rgba, -n));
|
|
113
|
+
}, t.prototype.grayscale = function() {
|
|
114
|
+
return C($(this.rgba, -1));
|
|
115
|
+
}, t.prototype.lighten = function(n) {
|
|
116
|
+
return n === void 0 && (n = 0.1), C(J(this.rgba, n));
|
|
117
|
+
}, t.prototype.darken = function(n) {
|
|
118
|
+
return n === void 0 && (n = 0.1), C(J(this.rgba, -n));
|
|
119
|
+
}, t.prototype.rotate = function(n) {
|
|
120
|
+
return n === void 0 && (n = 15), this.hue(this.hue() + n);
|
|
121
|
+
}, t.prototype.alpha = function(n) {
|
|
122
|
+
return typeof n == "number" ? C({ r: (e = this.rgba).r, g: e.g, b: e.b, a: n }) : d(this.rgba.a, 3);
|
|
123
|
+
var e;
|
|
124
|
+
}, t.prototype.hue = function(n) {
|
|
125
|
+
var e = I(this.rgba);
|
|
126
|
+
return typeof n == "number" ? C({ h: n, s: e.s, l: e.l, a: e.a }) : d(e.h);
|
|
127
|
+
}, t.prototype.isEqual = function(n) {
|
|
128
|
+
return this.toHex() === C(n).toHex();
|
|
129
|
+
}, t;
|
|
130
|
+
})(), C = function(t) {
|
|
131
|
+
return t instanceof K ? t : new K(t);
|
|
390
132
|
};
|
|
391
|
-
const
|
|
392
|
-
hexColor:
|
|
393
|
-
cursorPos:
|
|
394
|
-
onPointerDown:
|
|
133
|
+
const ht = ({
|
|
134
|
+
hexColor: t,
|
|
135
|
+
cursorPos: n,
|
|
136
|
+
onPointerDown: e,
|
|
395
137
|
onPointerMove: o,
|
|
396
|
-
onPointerUp:
|
|
138
|
+
onPointerUp: r
|
|
397
139
|
}) => {
|
|
398
|
-
const [
|
|
399
|
-
|
|
400
|
-
}, _ = (h) => {
|
|
401
|
-
s && o(h);
|
|
140
|
+
const [a, s] = Z(!1), f = (h) => {
|
|
141
|
+
s(!0), e(h), h.currentTarget.setPointerCapture(h.pointerId);
|
|
402
142
|
}, m = (h) => {
|
|
403
|
-
|
|
143
|
+
a && o(h);
|
|
144
|
+
}, p = (h) => {
|
|
145
|
+
s(!1), r(h), h.currentTarget.releasePointerCapture(h.pointerId);
|
|
404
146
|
};
|
|
405
|
-
return /* @__PURE__ */
|
|
147
|
+
return /* @__PURE__ */ S(
|
|
406
148
|
"div",
|
|
407
149
|
{
|
|
408
150
|
style: {
|
|
@@ -412,21 +154,21 @@ const De = ({
|
|
|
412
154
|
borderRadius: "50%",
|
|
413
155
|
border: "2px solid white",
|
|
414
156
|
boxShadow: "0 2px 4px rgba(0,0,0,0.3)",
|
|
415
|
-
backgroundColor:
|
|
157
|
+
backgroundColor: t,
|
|
416
158
|
left: "50%",
|
|
417
159
|
top: "50%",
|
|
418
|
-
transform: `translate(calc(-50% + ${
|
|
160
|
+
transform: `translate(calc(-50% + ${n.x}px), calc(-50% + ${n.y}px))`,
|
|
419
161
|
pointerEvents: "auto",
|
|
420
|
-
cursor:
|
|
162
|
+
cursor: a ? "grabbing" : "grab",
|
|
421
163
|
willChange: "transform",
|
|
422
164
|
zIndex: 10
|
|
423
165
|
},
|
|
424
|
-
onPointerDown:
|
|
425
|
-
onPointerMove:
|
|
426
|
-
onPointerUp:
|
|
166
|
+
onPointerDown: f,
|
|
167
|
+
onPointerMove: m,
|
|
168
|
+
onPointerUp: p
|
|
427
169
|
}
|
|
428
170
|
);
|
|
429
|
-
},
|
|
171
|
+
}, x = {
|
|
430
172
|
/** Custom color selection without predefined harmony */
|
|
431
173
|
Custom: "Custom",
|
|
432
174
|
/** Colors adjacent to each other on the color wheel */
|
|
@@ -443,165 +185,165 @@ const De = ({
|
|
|
443
185
|
Square: "Square",
|
|
444
186
|
/** A combination of complementary and analogous colors */
|
|
445
187
|
Compound: "Compound"
|
|
446
|
-
},
|
|
447
|
-
const
|
|
448
|
-
let
|
|
449
|
-
switch (
|
|
450
|
-
case
|
|
451
|
-
|
|
188
|
+
}, Q = (t, n, e, o) => {
|
|
189
|
+
const r = Math.atan2(n, t), a = Math.sqrt(t * t + n * n);
|
|
190
|
+
let s = [];
|
|
191
|
+
switch (e) {
|
|
192
|
+
case x.Analogous:
|
|
193
|
+
s = [0, -30, 30, -60, 60];
|
|
452
194
|
break;
|
|
453
|
-
case
|
|
454
|
-
|
|
195
|
+
case x.Monochromatic:
|
|
196
|
+
s = [0];
|
|
455
197
|
break;
|
|
456
|
-
case
|
|
457
|
-
|
|
198
|
+
case x.Triad:
|
|
199
|
+
s = [0, 120, 240];
|
|
458
200
|
break;
|
|
459
|
-
case
|
|
460
|
-
|
|
201
|
+
case x.Complementary:
|
|
202
|
+
s = [0, 180];
|
|
461
203
|
break;
|
|
462
|
-
case
|
|
463
|
-
|
|
204
|
+
case x.SplitComplementary:
|
|
205
|
+
s = [0, 150, 210];
|
|
464
206
|
break;
|
|
465
|
-
case
|
|
466
|
-
|
|
207
|
+
case x.Square:
|
|
208
|
+
s = [0, 90, 180, 270];
|
|
467
209
|
break;
|
|
468
|
-
case
|
|
469
|
-
|
|
210
|
+
case x.Compound:
|
|
211
|
+
s = [0, 180, 30, 210, 60];
|
|
470
212
|
break;
|
|
471
|
-
case
|
|
213
|
+
case x.Custom:
|
|
472
214
|
default:
|
|
473
215
|
return null;
|
|
474
216
|
}
|
|
475
|
-
const
|
|
217
|
+
const f = s.length, m = 0.25, p = [];
|
|
476
218
|
for (let h = 0; h < o; h++) {
|
|
477
|
-
const
|
|
478
|
-
let
|
|
479
|
-
|
|
480
|
-
x: Math.cos(
|
|
481
|
-
y: Math.sin(
|
|
219
|
+
const R = Math.floor(h / f), l = h % f, i = s[l], c = r + i * Math.PI / 180;
|
|
220
|
+
let u = a;
|
|
221
|
+
e === x.Monochromatic ? (u = a * (1 - h * 0.15), u < 0 && (u = 0)) : (u = a * (1 - R * m), u < 0 && (u = 0)), p.push({
|
|
222
|
+
x: Math.cos(c) * u,
|
|
223
|
+
y: Math.sin(c) * u
|
|
482
224
|
});
|
|
483
225
|
}
|
|
484
|
-
return
|
|
485
|
-
},
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
},
|
|
491
|
-
const o = Math.sqrt(
|
|
492
|
-
if (o >
|
|
493
|
-
const
|
|
494
|
-
return { x:
|
|
226
|
+
return p;
|
|
227
|
+
}, dt = (t, n) => {
|
|
228
|
+
const e = n, o = n, r = t.createConicGradient(Math.PI * 1.5, e, o);
|
|
229
|
+
r.addColorStop(0, "#FFFF00"), r.addColorStop(0.19, "#FF0000"), r.addColorStop(0.36, "#FF00FF"), r.addColorStop(0.5, "#0000FF"), r.addColorStop(0.64, "#00FFFF"), r.addColorStop(0.78, "#00FF00"), r.addColorStop(1, "#FFFF00"), t.fillStyle = r, t.beginPath(), t.arc(e, o, n, 0, Math.PI * 2), t.fill();
|
|
230
|
+
const a = t.createRadialGradient(e, o, 0, e, o, n);
|
|
231
|
+
a.addColorStop(0, "#ffffff"), a.addColorStop(0.2, "rgba(255, 255, 255, 0.8)"), a.addColorStop(0.6, "rgba(255, 255, 255, 0.2)"), a.addColorStop(1, "rgba(255, 255, 255, 0)"), t.fillStyle = a, t.beginPath(), t.arc(e, o, n, 0, Math.PI * 2), t.fill();
|
|
232
|
+
}, pt = (t, n, e) => {
|
|
233
|
+
const o = Math.sqrt(t * t + n * n), r = e - 1;
|
|
234
|
+
if (o > r) {
|
|
235
|
+
const a = r / o;
|
|
236
|
+
return { x: t * a, y: n * a };
|
|
495
237
|
}
|
|
496
|
-
return { x:
|
|
497
|
-
},
|
|
498
|
-
radius:
|
|
499
|
-
onChange:
|
|
500
|
-
quantityOfColors:
|
|
501
|
-
harmony: o =
|
|
238
|
+
return { x: t, y: n };
|
|
239
|
+
}, vt = ({
|
|
240
|
+
radius: t = 150,
|
|
241
|
+
onChange: n,
|
|
242
|
+
quantityOfColors: e = 5,
|
|
243
|
+
harmony: o = x.Monochromatic
|
|
502
244
|
}) => {
|
|
503
|
-
const
|
|
504
|
-
const
|
|
505
|
-
if (!
|
|
506
|
-
const
|
|
507
|
-
if (!
|
|
508
|
-
const
|
|
509
|
-
return C({ r:
|
|
510
|
-
}, [
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
if (!c) return;
|
|
514
|
-
const l = c.getContext("2d", { willReadFrequently: !0 });
|
|
245
|
+
const r = k(null), a = k(null), [s, f] = Z([]), m = k([]), p = A((l, i) => {
|
|
246
|
+
const c = r.current;
|
|
247
|
+
if (!c) return "#ffffff";
|
|
248
|
+
const u = c.getContext("2d");
|
|
249
|
+
if (!u) return "#ffffff";
|
|
250
|
+
const v = window.devicePixelRatio || 1, g = l + t, y = i + t, N = Math.floor(g * v), P = Math.floor(y * v), b = u.getImageData(N, P, 1, 1).data;
|
|
251
|
+
return C({ r: b[0], g: b[1], b: b[2], a: b[3] / 255 }).toHex();
|
|
252
|
+
}, [t]);
|
|
253
|
+
G(() => {
|
|
254
|
+
const l = r.current;
|
|
515
255
|
if (!l) return;
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
256
|
+
const i = l.getContext("2d", { willReadFrequently: !0 });
|
|
257
|
+
if (!i) return;
|
|
258
|
+
const c = window.devicePixelRatio || 1, u = t * 2;
|
|
259
|
+
l.width = u * c, l.height = u * c, l.style.width = `${u}px`, l.style.height = `${u}px`, i.scale(c, c), dt(i, t);
|
|
260
|
+
}, [t]), G(() => {
|
|
261
|
+
let l;
|
|
262
|
+
if (s.length > 0) {
|
|
263
|
+
const i = s[0];
|
|
264
|
+
l = Q(i.x, i.y, o, e);
|
|
523
265
|
}
|
|
524
|
-
if (!
|
|
525
|
-
const
|
|
526
|
-
o !==
|
|
527
|
-
const
|
|
528
|
-
return { x: Math.cos(
|
|
266
|
+
if (!l) {
|
|
267
|
+
const i = t * 0.5;
|
|
268
|
+
o !== x.Custom ? l = Q(i, 0, o, e) : l = Array.from({ length: e }).map((u, v) => {
|
|
269
|
+
const g = v / e * 2 * Math.PI;
|
|
270
|
+
return { x: Math.cos(g) * t * 0.6, y: Math.sin(g) * t * 0.6 };
|
|
529
271
|
});
|
|
530
272
|
}
|
|
531
|
-
if (
|
|
532
|
-
const
|
|
533
|
-
id:
|
|
534
|
-
x:
|
|
535
|
-
y:
|
|
536
|
-
color:
|
|
273
|
+
if (l) {
|
|
274
|
+
const i = l.map((c, u) => ({
|
|
275
|
+
id: u,
|
|
276
|
+
x: c.x,
|
|
277
|
+
y: c.y,
|
|
278
|
+
color: p(c.x, c.y)
|
|
537
279
|
}));
|
|
538
|
-
if (
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const
|
|
280
|
+
if (i.length > 0 && o !== x.Custom) {
|
|
281
|
+
const c = Math.atan2(i[0].y, i[0].x), u = Math.sqrt(i[0].x * i[0].x + i[0].y * i[0].y);
|
|
282
|
+
m.current = i.map((v) => {
|
|
283
|
+
const g = Math.atan2(v.y, v.x), y = Math.sqrt(v.x * v.x + v.y * v.y);
|
|
542
284
|
return {
|
|
543
|
-
angleOffset:
|
|
544
|
-
distanceRatio:
|
|
285
|
+
angleOffset: g - c,
|
|
286
|
+
distanceRatio: u > 0 ? y / u : 1
|
|
545
287
|
};
|
|
546
288
|
});
|
|
547
289
|
}
|
|
548
|
-
|
|
290
|
+
f(i), n && n(i);
|
|
549
291
|
}
|
|
550
|
-
}, [o,
|
|
551
|
-
const h =
|
|
552
|
-
(
|
|
553
|
-
const
|
|
554
|
-
if (!
|
|
555
|
-
const
|
|
556
|
-
let
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
const
|
|
560
|
-
|
|
292
|
+
}, [o, e, p]);
|
|
293
|
+
const h = A(
|
|
294
|
+
(l, i, c) => {
|
|
295
|
+
const u = a.current;
|
|
296
|
+
if (!u) return;
|
|
297
|
+
const v = u.getBoundingClientRect();
|
|
298
|
+
let g = l - v.left - t, y = i - v.top - t;
|
|
299
|
+
const N = pt(g, y, t);
|
|
300
|
+
if (g = N.x, y = N.y, o === x.Custom) {
|
|
301
|
+
const P = p(g, y), b = [...s];
|
|
302
|
+
b[c] = { ...b[c], x: g, y, color: P }, f(b), n && n(b);
|
|
561
303
|
return;
|
|
562
304
|
}
|
|
563
|
-
if (
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
566
|
-
return { ...
|
|
567
|
-
const
|
|
305
|
+
if (m.current.length > 0 && m.current[c]) {
|
|
306
|
+
const P = Math.atan2(y, g), b = m.current[c], et = P - b.angleOffset, q = s.map((F, Y) => {
|
|
307
|
+
if (Y === c)
|
|
308
|
+
return { ...F, x: g, y, color: p(g, y) };
|
|
309
|
+
const X = Math.sqrt(F.x * F.x + F.y * F.y), ot = m.current[Y], E = et + ot.angleOffset, W = Math.cos(E) * X, z = Math.sin(E) * X;
|
|
568
310
|
return {
|
|
569
|
-
...
|
|
570
|
-
x:
|
|
571
|
-
y:
|
|
572
|
-
color:
|
|
311
|
+
...F,
|
|
312
|
+
x: W,
|
|
313
|
+
y: z,
|
|
314
|
+
color: p(W, z)
|
|
573
315
|
};
|
|
574
316
|
});
|
|
575
|
-
|
|
317
|
+
f(q), n && n(q);
|
|
576
318
|
} else {
|
|
577
|
-
const
|
|
578
|
-
|
|
319
|
+
const P = p(g, y), b = [...s];
|
|
320
|
+
b[c] = { ...b[c], x: g, y, color: P }, f(b), n && n(b);
|
|
579
321
|
}
|
|
580
322
|
},
|
|
581
|
-
[
|
|
582
|
-
),
|
|
583
|
-
onPointerDown: (
|
|
584
|
-
h(
|
|
323
|
+
[t, p, n, s, o]
|
|
324
|
+
), R = A((l) => ({
|
|
325
|
+
onPointerDown: (i) => {
|
|
326
|
+
h(i.clientX, i.clientY, l);
|
|
585
327
|
},
|
|
586
|
-
onPointerMove: (
|
|
587
|
-
h(
|
|
328
|
+
onPointerMove: (i) => {
|
|
329
|
+
h(i.clientX, i.clientY, l);
|
|
588
330
|
},
|
|
589
331
|
onPointerUp: () => {
|
|
590
332
|
}
|
|
591
333
|
}), [h]);
|
|
592
|
-
return /* @__PURE__ */
|
|
334
|
+
return /* @__PURE__ */ S("div", { style: { display: "flex", flexDirection: "column", alignItems: "center", gap: 20 }, children: /* @__PURE__ */ rt(
|
|
593
335
|
"div",
|
|
594
336
|
{
|
|
595
|
-
ref:
|
|
337
|
+
ref: a,
|
|
596
338
|
style: {
|
|
597
|
-
width:
|
|
598
|
-
height:
|
|
339
|
+
width: t * 2,
|
|
340
|
+
height: t * 2,
|
|
599
341
|
position: "relative",
|
|
600
342
|
touchAction: "none"
|
|
601
343
|
},
|
|
602
344
|
children: [
|
|
603
|
-
/* @__PURE__ */
|
|
604
|
-
/* @__PURE__ */
|
|
345
|
+
/* @__PURE__ */ S("canvas", { ref: r, style: { borderRadius: "50%", display: "block" } }),
|
|
346
|
+
/* @__PURE__ */ S(
|
|
605
347
|
"svg",
|
|
606
348
|
{
|
|
607
349
|
style: {
|
|
@@ -613,33 +355,33 @@ const De = ({
|
|
|
613
355
|
pointerEvents: "none",
|
|
614
356
|
zIndex: 1
|
|
615
357
|
},
|
|
616
|
-
children:
|
|
358
|
+
children: s.map((l) => /* @__PURE__ */ S(
|
|
617
359
|
"line",
|
|
618
360
|
{
|
|
619
|
-
x1:
|
|
620
|
-
y1:
|
|
621
|
-
x2:
|
|
622
|
-
y2:
|
|
361
|
+
x1: t,
|
|
362
|
+
y1: t,
|
|
363
|
+
x2: t + l.x,
|
|
364
|
+
y2: t + l.y,
|
|
623
365
|
stroke: "white",
|
|
624
366
|
strokeWidth: "2",
|
|
625
367
|
style: { filter: "drop-shadow(0px 1px 1px rgba(0,0,0,0.3))" }
|
|
626
368
|
},
|
|
627
|
-
|
|
369
|
+
l.id
|
|
628
370
|
))
|
|
629
371
|
}
|
|
630
372
|
),
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
return /* @__PURE__ */
|
|
634
|
-
|
|
373
|
+
s.map((l, i) => {
|
|
374
|
+
const c = R(i);
|
|
375
|
+
return /* @__PURE__ */ S(
|
|
376
|
+
ht,
|
|
635
377
|
{
|
|
636
|
-
cursorPos: { x:
|
|
637
|
-
hexColor:
|
|
638
|
-
onPointerDown:
|
|
639
|
-
onPointerMove:
|
|
640
|
-
onPointerUp:
|
|
378
|
+
cursorPos: { x: l.x, y: l.y },
|
|
379
|
+
hexColor: l.color,
|
|
380
|
+
onPointerDown: c.onPointerDown,
|
|
381
|
+
onPointerMove: c.onPointerMove,
|
|
382
|
+
onPointerUp: c.onPointerUp
|
|
641
383
|
},
|
|
642
|
-
|
|
384
|
+
l.id
|
|
643
385
|
);
|
|
644
386
|
})
|
|
645
387
|
]
|
|
@@ -647,6 +389,6 @@ const De = ({
|
|
|
647
389
|
) });
|
|
648
390
|
};
|
|
649
391
|
export {
|
|
650
|
-
|
|
651
|
-
|
|
392
|
+
vt as ColorWheel,
|
|
393
|
+
x as HarmonyType
|
|
652
394
|
};
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
(function(A,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],_):(A=typeof globalThis<"u"?globalThis:A||self,_(A.ReactColorPaletteWheel={},A.React))})(this,(function(A,_){"use strict";var X={exports:{}},W={};var ne;function _e(){if(ne)return W;ne=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(o,a,s){var i=null;if(s!==void 0&&(i=""+s),a.key!==void 0&&(i=""+a.key),"key"in a){s={};for(var d in a)d!=="key"&&(s[d]=a[d])}else s=a;return a=s.ref,{$$typeof:e,type:o,key:i,ref:a!==void 0?a:null,props:s}}return W.Fragment=t,W.jsx=r,W.jsxs=r,W}var H={};var oe;function Pe(){return oe||(oe=1,process.env.NODE_ENV!=="production"&&(function(){function e(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===K?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case R:return"Fragment";case w:return"Profiler";case x:return"StrictMode";case Q:return"Suspense";case V:return"SuspenseList";case G:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case p:return"Portal";case M:return n.displayName||"Context";case F:return(n._context.displayName||"Context")+".Consumer";case E:var u=n.render;return n=n.displayName,n||(n=u.displayName||u.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case N:return u=n.displayName||null,u!==null?u:e(n.type)||"Memo";case I:u=n._payload,n=n._init;try{return e(n(u))}catch{}}return null}function t(n){return""+n}function r(n){try{t(n);var u=!1}catch{u=!0}if(u){u=console;var b=u.error,g=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return b.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",g),t(n)}}function o(n){if(n===R)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===I)return"<...>";try{var u=e(n);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function a(){var n=D.A;return n===null?null:n.getOwner()}function s(){return Error("react-stack-top-frame")}function i(n){if(z.call(n,"key")){var u=Object.getOwnPropertyDescriptor(n,"key").get;if(u&&u.isReactWarning)return!1}return n.key!==void 0}function d(n,u){function b(){me||(me=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}b.isReactWarning=!0,Object.defineProperty(n,"key",{get:b,configurable:!0})}function P(){var n=e(this.type);return ye[n]||(ye[n]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),n=this.props.ref,n!==void 0?n:null}function y(n,u,b,g,$,te){var v=b.ref;return n={$$typeof:f,type:n,key:u,props:b,_owner:g},(v!==void 0?v:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:P}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:$}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:te}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function h(n,u,b,g,$,te){var v=u.children;if(v!==void 0)if(g)if(J(v)){for(g=0;g<v.length;g++)O(v[g]);Object.freeze&&Object.freeze(v)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else O(v);if(z.call(u,"key")){v=e(n);var Y=Object.keys(u).filter(function(De){return De!=="key"});g=0<Y.length?"{key: someKey, "+Y.join(": ..., ")+": ...}":"{key: someKey}",Ee[v+g]||(Y=0<Y.length?"{"+Y.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
-
let props = %s;
|
|
3
|
-
<%s {...props} />
|
|
4
|
-
React keys must be passed directly to JSX without using spread:
|
|
5
|
-
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,g,v,Y,v),Ee[v+g]=!0)}if(v=null,b!==void 0&&(r(b),v=""+b),i(u)&&(r(u.key),v=""+u.key),"key"in u){b={};for(var re in u)re!=="key"&&(b[re]=u[re])}else b=u;return v&&d(b,typeof n=="function"?n.displayName||n.name||"Unknown":n),y(n,v,b,a(),$,te)}function O(n){c(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===I&&(n._payload.status==="fulfilled"?c(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function c(n){return typeof n=="object"&&n!==null&&n.$$typeof===f}var l=_,f=Symbol.for("react.transitional.element"),p=Symbol.for("react.portal"),R=Symbol.for("react.fragment"),x=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),F=Symbol.for("react.consumer"),M=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),Q=Symbol.for("react.suspense"),V=Symbol.for("react.suspense_list"),N=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),K=Symbol.for("react.client.reference"),D=l.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=Object.prototype.hasOwnProperty,J=Array.isArray,ee=console.createTask?console.createTask:function(){return null};l={react_stack_bottom_frame:function(n){return n()}};var me,ye={},Re=l.react_stack_bottom_frame.bind(l,s)(),xe=ee(o(s)),Ee={};H.Fragment=R,H.jsx=function(n,u,b){var g=1e4>D.recentlyCreatedOwnerStacks++;return h(n,u,b,!1,g?Error("react-stack-top-frame"):Re,g?ee(o(n)):xe)},H.jsxs=function(n,u,b){var g=1e4>D.recentlyCreatedOwnerStacks++;return h(n,u,b,!0,g?Error("react-stack-top-frame"):Re,g?ee(o(n)):xe)}})()),H}var ae;function we(){return ae||(ae=1,process.env.NODE_ENV==="production"?X.exports=_e():X.exports=Pe()),X.exports}var j=we(),Se={grad:.9,turn:360,rad:360/(2*Math.PI)},k=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},m=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=Math.pow(10,t)),Math.round(r*e)/r+0},C=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),e>r?r:e>t?e:t},se=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},ie=function(e){return{r:C(e.r,0,255),g:C(e.g,0,255),b:C(e.b,0,255),a:C(e.a)}},q=function(e){return{r:m(e.r),g:m(e.g),b:m(e.b),a:m(e.a,3)}},Ce=/^#([0-9a-f]{3,8})$/i,U=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},le=function(e){var t=e.r,r=e.g,o=e.b,a=e.a,s=Math.max(t,r,o),i=s-Math.min(t,r,o),d=i?s===t?(r-o)/i:s===r?2+(o-t)/i:4+(t-r)/i:0;return{h:60*(d<0?d+6:d),s:s?i/s*100:0,v:s/255*100,a}},ue=function(e){var t=e.h,r=e.s,o=e.v,a=e.a;t=t/360*6,r/=100,o/=100;var s=Math.floor(t),i=o*(1-r),d=o*(1-(t-s)*r),P=o*(1-(1-t+s)*r),y=s%6;return{r:255*[o,d,i,i,P,o][y],g:255*[P,o,o,d,i,i][y],b:255*[i,i,P,o,o,d][y],a}},ce=function(e){return{h:se(e.h),s:C(e.s,0,100),l:C(e.l,0,100),a:C(e.a)}},fe=function(e){return{h:m(e.h),s:m(e.s),l:m(e.l),a:m(e.a,3)}},de=function(e){return ue((r=(t=e).s,{h:t.h,s:(r*=((o=t.l)<50?o:100-o)/100)>0?2*r/(o+r)*100:0,v:o+r,a:t.a}));var t,r,o},L=function(e){return{h:(t=le(e)).h,s:(a=(200-(r=t.s))*(o=t.v)/100)>0&&a<200?r*o/100/(a<=100?a:200-a)*100:0,l:a/2,a:t.a};var t,r,o,a},Te=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ke=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Me=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Ae=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,pe={string:[[function(e){var t=Ce.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?m(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?m(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=Me.exec(e)||Ae.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:ie({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=Te.exec(e)||ke.exec(e);if(!t)return null;var r,o,a=ce({h:(r=t[1],o=t[2],o===void 0&&(o="deg"),Number(r)*(Se[o]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return de(a)},"hsl"]],object:[[function(e){var t=e.r,r=e.g,o=e.b,a=e.a,s=a===void 0?1:a;return k(t)&&k(r)&&k(o)?ie({r:Number(t),g:Number(r),b:Number(o),a:Number(s)}):null},"rgb"],[function(e){var t=e.h,r=e.s,o=e.l,a=e.a,s=a===void 0?1:a;if(!k(t)||!k(r)||!k(o))return null;var i=ce({h:Number(t),s:Number(r),l:Number(o),a:Number(s)});return de(i)},"hsl"],[function(e){var t=e.h,r=e.s,o=e.v,a=e.a,s=a===void 0?1:a;if(!k(t)||!k(r)||!k(o))return null;var i=(function(d){return{h:se(d.h),s:C(d.s,0,100),v:C(d.v,0,100),a:C(d.a)}})({h:Number(t),s:Number(r),v:Number(o),a:Number(s)});return ue(i)},"hsv"]]},he=function(e,t){for(var r=0;r<t.length;r++){var o=t[r][0](e);if(o)return[o,t[r][1]]}return[null,void 0]},Ne=function(e){return typeof e=="string"?he(e.trim(),pe.string):typeof e=="object"&&e!==null?he(e,pe.object):[null,void 0]},B=function(e,t){var r=L(e);return{h:r.h,s:C(r.s+100*t,0,100),l:r.l,a:r.a}},Z=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},be=function(e,t){var r=L(e);return{h:r.h,s:r.s,l:C(r.l+100*t,0,100),a:r.a}},ge=(function(){function e(t){this.parsed=Ne(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return m(Z(this.rgba),2)},e.prototype.isDark=function(){return Z(this.rgba)<.5},e.prototype.isLight=function(){return Z(this.rgba)>=.5},e.prototype.toHex=function(){return t=q(this.rgba),r=t.r,o=t.g,a=t.b,i=(s=t.a)<1?U(m(255*s)):"","#"+U(r)+U(o)+U(a)+i;var t,r,o,a,s,i},e.prototype.toRgb=function(){return q(this.rgba)},e.prototype.toRgbString=function(){return t=q(this.rgba),r=t.r,o=t.g,a=t.b,(s=t.a)<1?"rgba("+r+", "+o+", "+a+", "+s+")":"rgb("+r+", "+o+", "+a+")";var t,r,o,a,s},e.prototype.toHsl=function(){return fe(L(this.rgba))},e.prototype.toHslString=function(){return t=fe(L(this.rgba)),r=t.h,o=t.s,a=t.l,(s=t.a)<1?"hsla("+r+", "+o+"%, "+a+"%, "+s+")":"hsl("+r+", "+o+"%, "+a+"%)";var t,r,o,a,s},e.prototype.toHsv=function(){return t=le(this.rgba),{h:m(t.h),s:m(t.s),v:m(t.v),a:m(t.a,3)};var t},e.prototype.invert=function(){return T({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),T(B(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),T(B(this.rgba,-t))},e.prototype.grayscale=function(){return T(B(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),T(be(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),T(be(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?T({r:(r=this.rgba).r,g:r.g,b:r.b,a:t}):m(this.rgba.a,3);var r},e.prototype.hue=function(t){var r=L(this.rgba);return typeof t=="number"?T({h:t,s:r.s,l:r.l,a:r.a}):m(r.h)},e.prototype.isEqual=function(t){return this.toHex()===T(t).toHex()},e})(),T=function(e){return e instanceof ge?e:new ge(e)};const je=({hexColor:e,cursorPos:t,onPointerDown:r,onPointerMove:o,onPointerUp:a})=>{const[s,i]=_.useState(!1),d=h=>{i(!0),r(h),h.currentTarget.setPointerCapture(h.pointerId)},P=h=>{s&&o(h)},y=h=>{i(!1),a(h),h.currentTarget.releasePointerCapture(h.pointerId)};return j.jsx("div",{style:{position:"absolute",width:24,height:24,borderRadius:"50%",border:"2px solid white",boxShadow:"0 2px 4px rgba(0,0,0,0.3)",backgroundColor:e,left:"50%",top:"50%",transform:`translate(calc(-50% + ${t.x}px), calc(-50% + ${t.y}px))`,pointerEvents:"auto",cursor:s?"grabbing":"grab",willChange:"transform",zIndex:10},onPointerDown:d,onPointerMove:P,onPointerUp:y})},S={Custom:"Custom",Analogous:"Analogous",Monochromatic:"Monochromatic",Triad:"Triad",Complementary:"Complementary",SplitComplementary:"SplitComplementary",Square:"Square",Compound:"Compound"},ve=(e,t,r,o)=>{const a=Math.atan2(t,e),s=Math.sqrt(e*e+t*t);let i=[];switch(r){case S.Analogous:i=[0,-30,30,-60,60];break;case S.Monochromatic:i=[0];break;case S.Triad:i=[0,120,240];break;case S.Complementary:i=[0,180];break;case S.SplitComplementary:i=[0,150,210];break;case S.Square:i=[0,90,180,270];break;case S.Compound:i=[0,180,30,210,60];break;case S.Custom:default:return null}const d=i.length,P=.25,y=[];for(let h=0;h<o;h++){const O=Math.floor(h/d),c=h%d,l=i[c],f=a+l*Math.PI/180;let p=s;r===S.Monochromatic?(p=s*(1-h*.15),p<0&&(p=0)):(p=s*(1-O*P),p<0&&(p=0)),y.push({x:Math.cos(f)*p,y:Math.sin(f)*p})}return y},Oe=(e,t)=>{const r=t,o=t,a=e.createConicGradient(Math.PI*1.5,r,o);a.addColorStop(0,"#FFFF00"),a.addColorStop(.19,"#FF0000"),a.addColorStop(.36,"#FF00FF"),a.addColorStop(.5,"#0000FF"),a.addColorStop(.64,"#00FFFF"),a.addColorStop(.78,"#00FF00"),a.addColorStop(1,"#FFFF00"),e.fillStyle=a,e.beginPath(),e.arc(r,o,t,0,Math.PI*2),e.fill();const s=e.createRadialGradient(r,o,0,r,o,t);s.addColorStop(0,"#ffffff"),s.addColorStop(.2,"rgba(255, 255, 255, 0.8)"),s.addColorStop(.6,"rgba(255, 255, 255, 0.2)"),s.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=s,e.beginPath(),e.arc(r,o,t,0,Math.PI*2),e.fill()},Fe=(e,t,r)=>{const o=Math.sqrt(e*e+t*t),a=r-1;if(o>a){const s=a/o;return{x:e*s,y:t*s}}return{x:e,y:t}},Ie=({radius:e=150,onChange:t,quantityOfColors:r=5,harmony:o=S.Monochromatic})=>{const a=_.useRef(null),s=_.useRef(null),[i,d]=_.useState([]),P=_.useRef([]),y=_.useCallback((c,l)=>{const f=a.current;if(!f)return"#ffffff";const p=f.getContext("2d");if(!p)return"#ffffff";const R=window.devicePixelRatio||1,x=c+e,w=l+e,F=Math.floor(x*R),M=Math.floor(w*R),E=p.getImageData(F,M,1,1).data;return T({r:E[0],g:E[1],b:E[2],a:E[3]/255}).toHex()},[e]);_.useEffect(()=>{const c=a.current;if(!c)return;const l=c.getContext("2d",{willReadFrequently:!0});if(!l)return;const f=window.devicePixelRatio||1,p=e*2;c.width=p*f,c.height=p*f,c.style.width=`${p}px`,c.style.height=`${p}px`,l.scale(f,f),Oe(l,e)},[e]),_.useEffect(()=>{let c;if(i.length>0){const l=i[0];c=ve(l.x,l.y,o,r)}if(!c){const l=e*.5;o!==S.Custom?c=ve(l,0,o,r):c=Array.from({length:r}).map((p,R)=>{const x=R/r*2*Math.PI;return{x:Math.cos(x)*e*.6,y:Math.sin(x)*e*.6}})}if(c){const l=c.map((f,p)=>({id:p,x:f.x,y:f.y,color:y(f.x,f.y)}));if(l.length>0&&o!==S.Custom){const f=Math.atan2(l[0].y,l[0].x),p=Math.sqrt(l[0].x*l[0].x+l[0].y*l[0].y);P.current=l.map(R=>{const x=Math.atan2(R.y,R.x),w=Math.sqrt(R.x*R.x+R.y*R.y);return{angleOffset:x-f,distanceRatio:p>0?w/p:1}})}d(l),t&&t(l)}},[o,r,y]);const h=_.useCallback((c,l,f)=>{const p=s.current;if(!p)return;const R=p.getBoundingClientRect();let x=c-R.left-e,w=l-R.top-e;const F=Fe(x,w,e);if(x=F.x,w=F.y,o===S.Custom){const M=y(x,w),E=[...i];E[f]={...E[f],x,y:w,color:M},d(E),t&&t(E);return}if(P.current.length>0&&P.current[f]){const M=Math.atan2(w,x),E=P.current[f],Q=M-E.angleOffset,V=i.map((N,I)=>{if(I===f)return{...N,x,y:w,color:y(x,w)};const G=Math.sqrt(N.x*N.x+N.y*N.y),K=P.current[I],D=Q+K.angleOffset,z=Math.cos(D)*G,J=Math.sin(D)*G;return{...N,x:z,y:J,color:y(z,J)}});d(V),t&&t(V)}else{const M=y(x,w),E=[...i];E[f]={...E[f],x,y:w,color:M},d(E),t&&t(E)}},[e,y,t,i,o]),O=_.useCallback(c=>({onPointerDown:l=>{h(l.clientX,l.clientY,c)},onPointerMove:l=>{h(l.clientX,l.clientY,c)},onPointerUp:()=>{}}),[h]);return j.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:20},children:j.jsxs("div",{ref:s,style:{width:e*2,height:e*2,position:"relative",touchAction:"none"},children:[j.jsx("canvas",{ref:a,style:{borderRadius:"50%",display:"block"}}),j.jsx("svg",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1},children:i.map(c=>j.jsx("line",{x1:e,y1:e,x2:e+c.x,y2:e+c.y,stroke:"white",strokeWidth:"2",style:{filter:"drop-shadow(0px 1px 1px rgba(0,0,0,0.3))"}},c.id))}),i.map((c,l)=>{const f=O(l);return j.jsx(je,{cursorPos:{x:c.x,y:c.y},hexColor:c.color,onPointerDown:f.onPointerDown,onPointerMove:f.onPointerMove,onPointerUp:f.onPointerUp},c.id)})]})})};A.ColorWheel=Ie,A.HarmonyType=S,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(S,M){typeof exports=="object"&&typeof module<"u"?M(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],M):(S=typeof globalThis<"u"?globalThis:S||self,M(S.ReactColorPaletteWheel={},S.jsxRuntime,S.React))})(this,(function(S,M,P){"use strict";var tt={grad:.9,turn:360,rad:360/(2*Math.PI)},F=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},d=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n+0},C=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t>e?t:e},q=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},W=function(t){return{r:C(t.r,0,255),g:C(t.g,0,255),b:C(t.b,0,255),a:C(t.a)}},A=function(t){return{r:d(t.r),g:d(t.g),b:d(t.b),a:d(t.a,3)}},et=/^#([0-9a-f]{3,8})$/i,k=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Y=function(t){var e=t.r,n=t.g,o=t.b,r=t.a,a=Math.max(e,n,o),s=a-Math.min(e,n,o),f=s?a===e?(n-o)/s:a===n?2+(o-e)/s:4+(e-n)/s:0;return{h:60*(f<0?f+6:f),s:a?s/a*100:0,v:a/255*100,a:r}},E=function(t){var e=t.h,n=t.s,o=t.v,r=t.a;e=e/360*6,n/=100,o/=100;var a=Math.floor(e),s=o*(1-n),f=o*(1-(e-a)*n),m=o*(1-(1-e+a)*n),p=a%6;return{r:255*[o,f,s,s,m,o][p],g:255*[m,o,o,f,s,s][p],b:255*[s,s,m,o,o,f][p],a:r}},T=function(t){return{h:q(t.h),s:C(t.s,0,100),l:C(t.l,0,100),a:C(t.a)}},X=function(t){return{h:d(t.h),s:d(t.s),l:d(t.l),a:d(t.a,3)}},z=function(t){return E((n=(e=t).s,{h:e.h,s:(n*=((o=e.l)<50?o:100-o)/100)>0?2*n/(o+n)*100:0,v:o+n,a:e.a}));var e,n,o},D=function(t){return{h:(e=Y(t)).h,s:(r=(200-(n=e.s))*(o=e.v)/100)>0&&r<200?n*o/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,n,o,r},nt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ot=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,rt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,at=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,G={string:[[function(t){var e=et.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?d(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?d(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=rt.exec(t)||at.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:W({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=nt.exec(t)||ot.exec(t);if(!e)return null;var n,o,r=T({h:(n=e[1],o=e[2],o===void 0&&(o="deg"),Number(n)*(tt[o]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return z(r)},"hsl"]],object:[[function(t){var e=t.r,n=t.g,o=t.b,r=t.a,a=r===void 0?1:r;return F(e)&&F(n)&&F(o)?W({r:Number(e),g:Number(n),b:Number(o),a:Number(a)}):null},"rgb"],[function(t){var e=t.h,n=t.s,o=t.l,r=t.a,a=r===void 0?1:r;if(!F(e)||!F(n)||!F(o))return null;var s=T({h:Number(e),s:Number(n),l:Number(o),a:Number(a)});return z(s)},"hsl"],[function(t){var e=t.h,n=t.s,o=t.v,r=t.a,a=r===void 0?1:r;if(!F(e)||!F(n)||!F(o))return null;var s=(function(f){return{h:q(f.h),s:C(f.s,0,100),v:C(f.v,0,100),a:C(f.a)}})({h:Number(e),s:Number(n),v:Number(o),a:Number(a)});return E(s)},"hsv"]]},L=function(t,e){for(var n=0;n<e.length;n++){var o=e[n][0](t);if(o)return[o,e[n][1]]}return[null,void 0]},st=function(t){return typeof t=="string"?L(t.trim(),G.string):typeof t=="object"&&t!==null?L(t,G.object):[null,void 0]},H=function(t,e){var n=D(t);return{h:n.h,s:C(n.s+100*e,0,100),l:n.l,a:n.a}},j=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},O=function(t,e){var n=D(t);return{h:n.h,s:n.s,l:C(n.l+100*e,0,100),a:n.a}},B=(function(){function t(e){this.parsed=st(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return d(j(this.rgba),2)},t.prototype.isDark=function(){return j(this.rgba)<.5},t.prototype.isLight=function(){return j(this.rgba)>=.5},t.prototype.toHex=function(){return e=A(this.rgba),n=e.r,o=e.g,r=e.b,s=(a=e.a)<1?k(d(255*a)):"","#"+k(n)+k(o)+k(r)+s;var e,n,o,r,a,s},t.prototype.toRgb=function(){return A(this.rgba)},t.prototype.toRgbString=function(){return e=A(this.rgba),n=e.r,o=e.g,r=e.b,(a=e.a)<1?"rgba("+n+", "+o+", "+r+", "+a+")":"rgb("+n+", "+o+", "+r+")";var e,n,o,r,a},t.prototype.toHsl=function(){return X(D(this.rgba))},t.prototype.toHslString=function(){return e=X(D(this.rgba)),n=e.h,o=e.s,r=e.l,(a=e.a)<1?"hsla("+n+", "+o+"%, "+r+"%, "+a+")":"hsl("+n+", "+o+"%, "+r+"%)";var e,n,o,r,a},t.prototype.toHsv=function(){return e=Y(this.rgba),{h:d(e.h),s:d(e.s),v:d(e.v),a:d(e.a,3)};var e},t.prototype.invert=function(){return w({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),w(H(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),w(H(this.rgba,-e))},t.prototype.grayscale=function(){return w(H(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),w(O(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),w(O(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?w({r:(n=this.rgba).r,g:n.g,b:n.b,a:e}):d(this.rgba.a,3);var n},t.prototype.hue=function(e){var n=D(this.rgba);return typeof e=="number"?w({h:e,s:n.s,l:n.l,a:n.a}):d(n.h)},t.prototype.isEqual=function(e){return this.toHex()===w(e).toHex()},t})(),w=function(t){return t instanceof B?t:new B(t)};const it=({hexColor:t,cursorPos:e,onPointerDown:n,onPointerMove:o,onPointerUp:r})=>{const[a,s]=P.useState(!1),f=h=>{s(!0),n(h),h.currentTarget.setPointerCapture(h.pointerId)},m=h=>{a&&o(h)},p=h=>{s(!1),r(h),h.currentTarget.releasePointerCapture(h.pointerId)};return M.jsx("div",{style:{position:"absolute",width:24,height:24,borderRadius:"50%",border:"2px solid white",boxShadow:"0 2px 4px rgba(0,0,0,0.3)",backgroundColor:t,left:"50%",top:"50%",transform:`translate(calc(-50% + ${e.x}px), calc(-50% + ${e.y}px))`,pointerEvents:"auto",cursor:a?"grabbing":"grab",willChange:"transform",zIndex:10},onPointerDown:f,onPointerMove:m,onPointerUp:p})},v={Custom:"Custom",Analogous:"Analogous",Monochromatic:"Monochromatic",Triad:"Triad",Complementary:"Complementary",SplitComplementary:"SplitComplementary",Square:"Square",Compound:"Compound"},V=(t,e,n,o)=>{const r=Math.atan2(e,t),a=Math.sqrt(t*t+e*e);let s=[];switch(n){case v.Analogous:s=[0,-30,30,-60,60];break;case v.Monochromatic:s=[0];break;case v.Triad:s=[0,120,240];break;case v.Complementary:s=[0,180];break;case v.SplitComplementary:s=[0,150,210];break;case v.Square:s=[0,90,180,270];break;case v.Compound:s=[0,180,30,210,60];break;case v.Custom:default:return null}const f=s.length,m=.25,p=[];for(let h=0;h<o;h++){const $=Math.floor(h/f),l=h%f,i=s[l],u=r+i*Math.PI/180;let c=a;n===v.Monochromatic?(c=a*(1-h*.15),c<0&&(c=0)):(c=a*(1-$*m),c<0&&(c=0)),p.push({x:Math.cos(u)*c,y:Math.sin(u)*c})}return p},lt=(t,e)=>{const n=e,o=e,r=t.createConicGradient(Math.PI*1.5,n,o);r.addColorStop(0,"#FFFF00"),r.addColorStop(.19,"#FF0000"),r.addColorStop(.36,"#FF00FF"),r.addColorStop(.5,"#0000FF"),r.addColorStop(.64,"#00FFFF"),r.addColorStop(.78,"#00FF00"),r.addColorStop(1,"#FFFF00"),t.fillStyle=r,t.beginPath(),t.arc(n,o,e,0,Math.PI*2),t.fill();const a=t.createRadialGradient(n,o,0,n,o,e);a.addColorStop(0,"#ffffff"),a.addColorStop(.2,"rgba(255, 255, 255, 0.8)"),a.addColorStop(.6,"rgba(255, 255, 255, 0.2)"),a.addColorStop(1,"rgba(255, 255, 255, 0)"),t.fillStyle=a,t.beginPath(),t.arc(n,o,e,0,Math.PI*2),t.fill()},ut=(t,e,n)=>{const o=Math.sqrt(t*t+e*e),r=n-1;if(o>r){const a=r/o;return{x:t*a,y:e*a}}return{x:t,y:e}},ct=({radius:t=150,onChange:e,quantityOfColors:n=5,harmony:o=v.Monochromatic})=>{const r=P.useRef(null),a=P.useRef(null),[s,f]=P.useState([]),m=P.useRef([]),p=P.useCallback((l,i)=>{const u=r.current;if(!u)return"#ffffff";const c=u.getContext("2d");if(!c)return"#ffffff";const y=window.devicePixelRatio||1,g=l+t,x=i+t,R=Math.floor(g*y),I=Math.floor(x*y),b=c.getImageData(R,I,1,1).data;return w({r:b[0],g:b[1],b:b[2],a:b[3]/255}).toHex()},[t]);P.useEffect(()=>{const l=r.current;if(!l)return;const i=l.getContext("2d",{willReadFrequently:!0});if(!i)return;const u=window.devicePixelRatio||1,c=t*2;l.width=c*u,l.height=c*u,l.style.width=`${c}px`,l.style.height=`${c}px`,i.scale(u,u),lt(i,t)},[t]),P.useEffect(()=>{let l;if(s.length>0){const i=s[0];l=V(i.x,i.y,o,n)}if(!l){const i=t*.5;o!==v.Custom?l=V(i,0,o,n):l=Array.from({length:n}).map((c,y)=>{const g=y/n*2*Math.PI;return{x:Math.cos(g)*t*.6,y:Math.sin(g)*t*.6}})}if(l){const i=l.map((u,c)=>({id:c,x:u.x,y:u.y,color:p(u.x,u.y)}));if(i.length>0&&o!==v.Custom){const u=Math.atan2(i[0].y,i[0].x),c=Math.sqrt(i[0].x*i[0].x+i[0].y*i[0].y);m.current=i.map(y=>{const g=Math.atan2(y.y,y.x),x=Math.sqrt(y.x*y.x+y.y*y.y);return{angleOffset:g-u,distanceRatio:c>0?x/c:1}})}f(i),e&&e(i)}},[o,n,p]);const h=P.useCallback((l,i,u)=>{const c=a.current;if(!c)return;const y=c.getBoundingClientRect();let g=l-y.left-t,x=i-y.top-t;const R=ut(g,x,t);if(g=R.x,x=R.y,o===v.Custom){const I=p(g,x),b=[...s];b[u]={...b[u],x:g,y:x,color:I},f(b),e&&e(b);return}if(m.current.length>0&&m.current[u]){const I=Math.atan2(x,g),b=m.current[u],ft=I-b.angleOffset,_=s.map((N,J)=>{if(J===u)return{...N,x:g,y:x,color:p(g,x)};const K=Math.sqrt(N.x*N.x+N.y*N.y),ht=m.current[J],Q=ft+ht.angleOffset,Z=Math.cos(Q)*K,U=Math.sin(Q)*K;return{...N,x:Z,y:U,color:p(Z,U)}});f(_),e&&e(_)}else{const I=p(g,x),b=[...s];b[u]={...b[u],x:g,y:x,color:I},f(b),e&&e(b)}},[t,p,e,s,o]),$=P.useCallback(l=>({onPointerDown:i=>{h(i.clientX,i.clientY,l)},onPointerMove:i=>{h(i.clientX,i.clientY,l)},onPointerUp:()=>{}}),[h]);return M.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:20},children:M.jsxs("div",{ref:a,style:{width:t*2,height:t*2,position:"relative",touchAction:"none"},children:[M.jsx("canvas",{ref:r,style:{borderRadius:"50%",display:"block"}}),M.jsx("svg",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1},children:s.map(l=>M.jsx("line",{x1:t,y1:t,x2:t+l.x,y2:t+l.y,stroke:"white",strokeWidth:"2",style:{filter:"drop-shadow(0px 1px 1px rgba(0,0,0,0.3))"}},l.id))}),s.map((l,i)=>{const u=$(i);return M.jsx(it,{cursorPos:{x:l.x,y:l.y},hexColor:l.color,onPointerDown:u.onPointerDown,onPointerMove:u.onPointerMove,onPointerUp:u.onPointerUp},l.id)})]})})};S.ColorWheel=ct,S.HarmonyType=v,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-color-palette-wheel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/MillesDyson/color-palette-generator.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/MillesDyson/color-palette-generator",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/MillesDyson/color-palette-generator/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"react",
|
|
16
|
+
"color",
|
|
17
|
+
"palette",
|
|
18
|
+
"wheel",
|
|
19
|
+
"color-palette",
|
|
20
|
+
"color-palette-generator"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Milles Dyson",
|
|
24
|
+
"email": "millesdyson@gmail.com",
|
|
25
|
+
"url": "https://github.com/MillesDyson"
|
|
26
|
+
},
|
|
5
27
|
"scripts": {
|
|
6
28
|
"dev": "vite",
|
|
7
29
|
"build": "tsc -b && vite build",
|
|
@@ -40,7 +62,7 @@
|
|
|
40
62
|
"react-dom": "^19.2.0"
|
|
41
63
|
},
|
|
42
64
|
"peerDependencies": {
|
|
43
|
-
"react": ">=
|
|
44
|
-
"react-dom": ">=
|
|
65
|
+
"react": ">=16.8.0",
|
|
66
|
+
"react-dom": ">=16.8.0"
|
|
45
67
|
}
|
|
46
68
|
}
|