@elcrm/form 0.0.82 → 0.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/styles/Color.module.css +1 -1
- package/dist/assets/styles/Field.module.css +1 -1
- package/dist/assets/styles/Form.module.css +1 -1
- package/dist/assets/styles/Select.module.css +1 -1
- package/dist/core/Field.js +1 -1
- package/dist/fields/Color.js +189 -185
- package/dist/fields/Date.js +145 -140
- package/dist/fields/Password.js +5 -17
- package/dist/fields/Select.js +47 -43
- package/dist/fields/Time.js +107 -104
- package/dist/index.js +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/overlayZ.d.ts +7 -0
- package/dist/overlayZ.js +21 -0
- package/dist/package.js +1 -1
- package/dist/style.css +4 -4
- package/dist/styles/Color.module.js +23 -23
- package/dist/styles/Field.module.js +72 -72
- package/dist/styles/Form.module.js +8 -8
- package/dist/styles/Select.module.js +5 -5
- package/package.json +1 -1
package/dist/fields/Color.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import e from "../styles/Field.module.js";
|
|
2
2
|
import t from "../core/Field.js";
|
|
3
3
|
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
-
import r from "../
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import { acquireOverlayZIndex as r, releaseOverlayZIndex as i } from "../overlayZ.js";
|
|
5
|
+
import a from "../styles/Color.module.js";
|
|
6
|
+
import o from "react";
|
|
7
|
+
import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
8
|
+
import { createPortal as u } from "react-dom";
|
|
8
9
|
//#region src/lib/fields/Color.tsx
|
|
9
|
-
var
|
|
10
|
-
function
|
|
10
|
+
var d = /* @__PURE__ */ "#FF2D55.#FF3B30.#FF453A.#FF6961.#FF8A80.#C11F3E.#AF52DE.#BF5AF2.#DA8FFF.#5856D6.#5E5CE6.#7D7AFF.#007AFF.#0A84FF.#409CFF.#64D2FF.#70D7FF.#5AC8FA.#32ADE6.#64D2FF.#40C8E0.#00C7BE.#63E6E2.#66D4CF.#34C759.#30D158.#30DB5B.#4CD964.#6DE6A0.#8EEDB3.#A8E10C.#B5F200.#D0FF00.#E4FF66.#F2FF99.#C6FF00.#FFCC00.#FFD60A.#FFEA00.#FFE066.#FFF3A3.#FFEB3B.#FF9500.#FF9F0A.#FFB340.#FFB340.#FFD580.#FF8C00.#A2845E.#AC8E68.#C4A484.#8E8E93.#636366.#48484A.#3A3A3C.#2C2C2E.#1C1C1E".split(".");
|
|
11
|
+
function f(e, t, n) {
|
|
11
12
|
return Math.min(n, Math.max(t, e));
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
-
return Math.round(
|
|
14
|
+
function p(e) {
|
|
15
|
+
return Math.round(f(e, 0, 255)).toString(16).padStart(2, "0").toUpperCase();
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function m(e, t, n) {
|
|
17
18
|
let r = (e % 360 + 360) % 360, i = n * t, a = i * (1 - Math.abs(r / 60 % 2 - 1)), o = n - i, s = 0, c = 0, l = 0;
|
|
18
19
|
return r < 60 ? [s, c, l] = [
|
|
19
20
|
i,
|
|
@@ -45,7 +46,7 @@ function f(e, t, n) {
|
|
|
45
46
|
b: (l + o) * 255
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
+
function h(e, t, n) {
|
|
49
50
|
let r = e / 255, i = t / 255, a = n / 255, o = Math.max(r, i, a), s = o - Math.min(r, i, a), c = 0;
|
|
50
51
|
s !== 0 && (c = o === r ? (i - a) / s % 6 : o === i ? (a - r) / s + 2 : (r - i) / s + 4, c *= 60, c < 0 && (c += 360));
|
|
51
52
|
let l = o === 0 ? 0 : s / o;
|
|
@@ -55,7 +56,7 @@ function p(e, t, n) {
|
|
|
55
56
|
v: o
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
+
function g(e) {
|
|
59
60
|
if (typeof e != "string") return null;
|
|
60
61
|
let t = e.trim();
|
|
61
62
|
if (!t || (t[0] === "#" && (t = t.slice(1)), ![
|
|
@@ -66,99 +67,99 @@ function m(e) {
|
|
|
66
67
|
].includes(t.length)) || !/^[0-9a-fA-F]+$/.test(t)) return null;
|
|
67
68
|
let n = 0, r = 0, i = 0, a = 1;
|
|
68
69
|
return t.length === 3 || t.length === 4 ? (n = parseInt(t[0] + t[0], 16), r = parseInt(t[1] + t[1], 16), i = parseInt(t[2] + t[2], 16), t.length === 4 && (a = parseInt(t[3] + t[3], 16) / 255)) : (n = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16), t.length === 8 && (a = parseInt(t.slice(6, 8), 16) / 255)), {
|
|
69
|
-
...
|
|
70
|
+
...h(n, r, i),
|
|
70
71
|
a
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
function
|
|
74
|
-
let { r: n, g: r, b: i } =
|
|
75
|
-
return !t || e.a >= .999 ? a : `${a}${
|
|
74
|
+
function _(e, t) {
|
|
75
|
+
let { r: n, g: r, b: i } = m(e.h, e.s, e.v), a = `#${p(n)}${p(r)}${p(i)}`;
|
|
76
|
+
return !t || e.a >= .999 ? a : `${a}${p(e.a * 255)}`;
|
|
76
77
|
}
|
|
77
|
-
function
|
|
78
|
-
let { r: t, g: n, b: r } =
|
|
78
|
+
function v(e) {
|
|
79
|
+
let { r: t, g: n, b: r } = m(e.h, e.s, e.v), i = Math.round(t), a = Math.round(n), o = Math.round(r);
|
|
79
80
|
return e.a >= .999 ? `rgb(${i}, ${a}, ${o})` : `rgba(${i}, ${a}, ${o}, ${Number(e.a.toFixed(3))})`;
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
let { r: t, g: n, b: r } =
|
|
82
|
+
function y(e) {
|
|
83
|
+
let { r: t, g: n, b: r } = m(e, 1, 1);
|
|
83
84
|
return `rgb(${Math.round(t)},${Math.round(n)},${Math.round(r)})`;
|
|
84
85
|
}
|
|
85
|
-
function
|
|
86
|
-
let t =
|
|
87
|
-
return t ?
|
|
86
|
+
function b(e) {
|
|
87
|
+
let t = g(e);
|
|
88
|
+
return t ? _(t, t.a < .999) : e.toUpperCase();
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
+
function x(e) {
|
|
90
91
|
return e == null ? !0 : typeof e == "string" ? e.trim() === "" : !1;
|
|
91
92
|
}
|
|
92
|
-
function
|
|
93
|
+
function S(e) {
|
|
93
94
|
if (!(e instanceof HTMLElement)) return !1;
|
|
94
95
|
let t = e.tagName;
|
|
95
96
|
return t === "INPUT" || t === "TEXTAREA" || t === "SELECT" ? !0 : !!e.isContentEditable;
|
|
96
97
|
}
|
|
97
|
-
function
|
|
98
|
+
function C(e) {
|
|
98
99
|
let t = (e || "").trim();
|
|
99
100
|
if (!t) return null;
|
|
100
|
-
let n =
|
|
101
|
+
let n = g(t) ?? g(t[0] === "#" ? t : `#${t.replace(/^#/, "")}`);
|
|
101
102
|
if (n) return n;
|
|
102
103
|
let r = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*([\d.]+))?\s*\)$/i.exec(t);
|
|
103
104
|
if (r) {
|
|
104
|
-
let e =
|
|
105
|
+
let e = f(Number(r[1]), 0, 255), t = f(Number(r[2]), 0, 255), n = f(Number(r[3]), 0, 255), i = r[4] === void 0 ? 1 : f(Number(r[4]), 0, 1);
|
|
105
106
|
return {
|
|
106
|
-
...
|
|
107
|
+
...h(e, t, n),
|
|
107
108
|
a: i
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
return null;
|
|
111
112
|
}
|
|
112
|
-
function
|
|
113
|
+
function w() {
|
|
113
114
|
return typeof window < "u" && "EyeDropper" in window;
|
|
114
115
|
}
|
|
115
|
-
var
|
|
116
|
+
var T = {
|
|
116
117
|
h: 0,
|
|
117
118
|
s: 1,
|
|
118
119
|
v: .76,
|
|
119
120
|
a: 1
|
|
120
121
|
};
|
|
121
|
-
function
|
|
122
|
-
let { value: M } = n(
|
|
123
|
-
|
|
124
|
-
let e =
|
|
125
|
-
e && (z(e), V(
|
|
122
|
+
function E({ value: r = "", form: i, onValue: f, onBlur: p, name: m = "", placeholder: h = "#000000", label: v = "", error: y = "", hidden: b = !1, disabled: w = !1, className: E = "", after: O = "", before: k = "", colors: A, alpha: j = !0 }) {
|
|
123
|
+
let { value: M } = n(i, m, r), N = typeof M == "string" ? M : M == null ? "" : String(M), [P, F] = o.useState(!1), [I, L] = o.useState(null), [R, z] = o.useState(() => g(N) ?? { ...T }), [B, V] = o.useState(() => _(g(N) ?? T, j)), H = A?.length ? A : d, U = g(N), W = U ?? (x(N) ? g(h) : null), G = U ? _(U, j) : "", K = W ? _(W, j) : "transparent";
|
|
124
|
+
o.useEffect(() => {
|
|
125
|
+
let e = g(N);
|
|
126
|
+
e && (z(e), V(_(e, j)));
|
|
126
127
|
}, [N, j]);
|
|
127
|
-
let q =
|
|
128
|
-
let n =
|
|
128
|
+
let q = o.useCallback((e, t) => {
|
|
129
|
+
let n = _(e, j), r = {
|
|
129
130
|
value: n,
|
|
130
|
-
name:
|
|
131
|
+
name: m || ""
|
|
131
132
|
};
|
|
132
|
-
|
|
133
|
+
i && m && (t === "live" ? i.onValue(r) : i.setValue(r)), f && f !== i?.onValue && f(r), V(n);
|
|
133
134
|
}, [
|
|
134
135
|
j,
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
i,
|
|
137
|
+
m,
|
|
137
138
|
f
|
|
138
139
|
]), J = (e) => {
|
|
139
|
-
if (
|
|
140
|
-
let t =
|
|
141
|
-
z(t), V(
|
|
140
|
+
if (w) return;
|
|
141
|
+
let t = g(N) ?? { ...R };
|
|
142
|
+
z(t), V(_(t, j)), L(e.getBoundingClientRect()), F(!0);
|
|
142
143
|
}, Y = () => {
|
|
143
144
|
F(!1), p?.({
|
|
144
|
-
value:
|
|
145
|
-
name:
|
|
145
|
+
value: _(R, j),
|
|
146
|
+
name: m || ""
|
|
146
147
|
});
|
|
147
148
|
};
|
|
148
|
-
|
|
149
|
-
if (!P ||
|
|
149
|
+
o.useEffect(() => {
|
|
150
|
+
if (!P || w) return;
|
|
150
151
|
let e = "", t = (t) => {
|
|
151
|
-
let n =
|
|
152
|
+
let n = C(t);
|
|
152
153
|
if (!n) return !1;
|
|
153
154
|
let r = {
|
|
154
155
|
...n,
|
|
155
156
|
a: j ? n.a : 1
|
|
156
|
-
}, i =
|
|
157
|
+
}, i = _(r, j);
|
|
157
158
|
return i === e ? !0 : (e = i, z(r), q(r, "commit"), !0);
|
|
158
159
|
}, n = (e) => {
|
|
159
|
-
|
|
160
|
+
S(e.target) || t(e.clipboardData?.getData("text/plain") ?? "") && (e.preventDefault(), e.stopPropagation());
|
|
160
161
|
}, r = (e) => {
|
|
161
|
-
(e.ctrlKey || e.metaKey) && (e.key !== "v" && e.key !== "V" ||
|
|
162
|
+
(e.ctrlKey || e.metaKey) && (e.key !== "v" && e.key !== "V" || S(e.target) || navigator.clipboard?.readText && (e.preventDefault(), navigator.clipboard.readText().then((e) => {
|
|
162
163
|
t(e);
|
|
163
164
|
})));
|
|
164
165
|
};
|
|
@@ -167,12 +168,12 @@ function w({ value: u = "", form: d, onValue: f, onBlur: p, name: g = "", placeh
|
|
|
167
168
|
};
|
|
168
169
|
}, [
|
|
169
170
|
P,
|
|
170
|
-
|
|
171
|
+
w,
|
|
171
172
|
j,
|
|
172
173
|
q
|
|
173
174
|
]);
|
|
174
175
|
let X = (e) => {
|
|
175
|
-
if (!
|
|
176
|
+
if (!w) {
|
|
176
177
|
if (!P && (e.key === "Enter" || e.key === " " || e.key === "ArrowDown")) {
|
|
177
178
|
e.preventDefault(), J(e.currentTarget);
|
|
178
179
|
return;
|
|
@@ -180,44 +181,44 @@ function w({ value: u = "", form: d, onValue: f, onBlur: p, name: g = "", placeh
|
|
|
180
181
|
P && e.key === "Escape" && (e.preventDefault(), Y());
|
|
181
182
|
}
|
|
182
183
|
};
|
|
183
|
-
return
|
|
184
|
+
return b && x(N) ? null : /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ l(t, {
|
|
184
185
|
type: "color",
|
|
185
186
|
label: v,
|
|
186
|
-
error:
|
|
187
|
-
element_blok: { className: [
|
|
187
|
+
error: y,
|
|
188
|
+
element_blok: { className: [E || ""] },
|
|
188
189
|
element_input: {
|
|
189
190
|
className: [e.w],
|
|
190
|
-
props: { "data-disabled":
|
|
191
|
+
props: { "data-disabled": w ? "true" : void 0 }
|
|
191
192
|
},
|
|
192
193
|
children: [
|
|
193
|
-
k ? /* @__PURE__ */
|
|
194
|
+
k ? /* @__PURE__ */ c("span", {
|
|
194
195
|
className: e.affix,
|
|
195
196
|
children: k
|
|
196
197
|
}) : null,
|
|
197
|
-
/* @__PURE__ */
|
|
198
|
-
className:
|
|
198
|
+
/* @__PURE__ */ l("div", {
|
|
199
|
+
className: a.trigger,
|
|
199
200
|
role: "combobox",
|
|
200
|
-
tabIndex:
|
|
201
|
+
tabIndex: w ? -1 : 0,
|
|
201
202
|
"aria-expanded": P,
|
|
202
203
|
"aria-haspopup": "dialog",
|
|
203
|
-
"aria-disabled":
|
|
204
|
+
"aria-disabled": w,
|
|
204
205
|
"aria-label": v || "Цвет",
|
|
205
206
|
onClick: (e) => J(e.currentTarget),
|
|
206
207
|
onKeyDown: X,
|
|
207
|
-
children: [/* @__PURE__ */
|
|
208
|
-
className:
|
|
208
|
+
children: [/* @__PURE__ */ c("span", {
|
|
209
|
+
className: a.preview,
|
|
209
210
|
style: { "--preview-color": K }
|
|
210
|
-
}), /* @__PURE__ */
|
|
211
|
-
className: [
|
|
212
|
-
children: G ||
|
|
211
|
+
}), /* @__PURE__ */ c("span", {
|
|
212
|
+
className: [a.hexText, G ? "" : a.placeholder].filter(Boolean).join(" "),
|
|
213
|
+
children: G || h
|
|
213
214
|
})]
|
|
214
215
|
}),
|
|
215
|
-
O ? /* @__PURE__ */
|
|
216
|
+
O ? /* @__PURE__ */ c("span", {
|
|
216
217
|
className: e.affix,
|
|
217
218
|
children: O
|
|
218
219
|
}) : null
|
|
219
220
|
]
|
|
220
|
-
}), P &&
|
|
221
|
+
}), P && u(/* @__PURE__ */ c(D, {
|
|
221
222
|
parent: I || void 0,
|
|
222
223
|
hsva: R,
|
|
223
224
|
setHsva: z,
|
|
@@ -230,132 +231,135 @@ function w({ value: u = "", form: d, onValue: f, onBlur: p, name: g = "", placeh
|
|
|
230
231
|
onClose: Y
|
|
231
232
|
}), document.body)] });
|
|
232
233
|
}
|
|
233
|
-
|
|
234
|
-
function
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
E.displayName = "ColorField";
|
|
235
|
+
function D({ parent: e, hsva: t, setHsva: n, hexDraft: u, setHexDraft: d, alpha: p, palette: m, onLive: h, onCommit: y, onClose: x }) {
|
|
236
|
+
let [S] = o.useState(() => r());
|
|
237
|
+
if (o.useEffect(() => () => i(S), [S]), !e) return null;
|
|
238
|
+
let C = p ? 340 : 300, T = window.innerHeight - e.bottom < C + 8 ? Math.max(8, e.top - C - 8) : Math.min(window.innerHeight - C - 8, e.bottom + 8), E = Math.min(Math.max(8, e.left), window.innerWidth - 260 - 8), D = v({
|
|
237
239
|
...t,
|
|
238
240
|
a: 1
|
|
239
|
-
}),
|
|
240
|
-
n(e), t === "live" ?
|
|
241
|
-
},
|
|
242
|
-
let e =
|
|
241
|
+
}), j = b(_(t, p)), N = (e, t) => {
|
|
242
|
+
n(e), t === "live" ? h(e) : y(e);
|
|
243
|
+
}, P = () => {
|
|
244
|
+
let e = g(u);
|
|
243
245
|
if (!e) {
|
|
244
|
-
|
|
246
|
+
d(_(t, p));
|
|
245
247
|
return;
|
|
246
248
|
}
|
|
247
|
-
|
|
248
|
-
},
|
|
249
|
-
let n = e.replace(/[^\d]/g, ""), r =
|
|
250
|
-
|
|
249
|
+
N(e, "commit");
|
|
250
|
+
}, F = (e) => {
|
|
251
|
+
let n = e.replace(/[^\d]/g, ""), r = f(Number(n || 0), 0, 100);
|
|
252
|
+
N({
|
|
251
253
|
...t,
|
|
252
254
|
a: r / 100
|
|
253
255
|
}, "commit");
|
|
254
|
-
},
|
|
255
|
-
if (
|
|
256
|
-
let e = window.EyeDropper, n =
|
|
257
|
-
n &&
|
|
256
|
+
}, I = async () => {
|
|
257
|
+
if (w()) try {
|
|
258
|
+
let e = window.EyeDropper, n = g((await new e().open()).sRGBHex);
|
|
259
|
+
n && N({
|
|
258
260
|
...n,
|
|
259
261
|
a: t.a
|
|
260
262
|
}, "commit");
|
|
261
263
|
} catch {}
|
|
262
264
|
};
|
|
263
|
-
return /* @__PURE__ */ s
|
|
264
|
-
className:
|
|
265
|
-
|
|
265
|
+
return /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("div", {
|
|
266
|
+
className: a.o,
|
|
267
|
+
style: { zIndex: S },
|
|
268
|
+
onClick: x,
|
|
266
269
|
"aria-hidden": !0
|
|
267
|
-
}), /* @__PURE__ */
|
|
268
|
-
className:
|
|
270
|
+
}), /* @__PURE__ */ l("div", {
|
|
271
|
+
className: a.panel,
|
|
269
272
|
role: "dialog",
|
|
270
273
|
"aria-label": "Выбор цвета",
|
|
271
274
|
style: {
|
|
272
|
-
top:
|
|
273
|
-
left:
|
|
274
|
-
width: 260
|
|
275
|
+
top: T,
|
|
276
|
+
left: E,
|
|
277
|
+
width: 260,
|
|
278
|
+
zIndex: S + 1
|
|
275
279
|
},
|
|
276
280
|
children: [
|
|
277
|
-
/* @__PURE__ */
|
|
281
|
+
/* @__PURE__ */ c(O, {
|
|
278
282
|
hsva: t,
|
|
279
|
-
onChange: (e, n, r) =>
|
|
283
|
+
onChange: (e, n, r) => N({
|
|
280
284
|
...t,
|
|
281
285
|
s: e,
|
|
282
286
|
v: n
|
|
283
287
|
}, r)
|
|
284
288
|
}),
|
|
285
|
-
/* @__PURE__ */
|
|
286
|
-
className:
|
|
287
|
-
children: [
|
|
289
|
+
/* @__PURE__ */ l("div", {
|
|
290
|
+
className: a.slidersRow,
|
|
291
|
+
children: [w() ? /* @__PURE__ */ c("button", {
|
|
288
292
|
type: "button",
|
|
289
|
-
className:
|
|
293
|
+
className: a.eyedropper,
|
|
290
294
|
"aria-label": "Пипетка",
|
|
291
|
-
onClick:
|
|
292
|
-
children: /* @__PURE__ */
|
|
293
|
-
}) : null, /* @__PURE__ */
|
|
294
|
-
className:
|
|
295
|
-
children: [/* @__PURE__ */
|
|
295
|
+
onClick: I,
|
|
296
|
+
children: /* @__PURE__ */ c(M, {})
|
|
297
|
+
}) : null, /* @__PURE__ */ l("div", {
|
|
298
|
+
className: a.sliders,
|
|
299
|
+
children: [/* @__PURE__ */ c(k, {
|
|
296
300
|
h: t.h,
|
|
297
|
-
onChange: (e, n) =>
|
|
301
|
+
onChange: (e, n) => N({
|
|
298
302
|
...t,
|
|
299
303
|
h: e
|
|
300
304
|
}, n)
|
|
301
|
-
}),
|
|
305
|
+
}), p ? /* @__PURE__ */ c(A, {
|
|
302
306
|
a: t.a,
|
|
303
|
-
color:
|
|
304
|
-
onChange: (e, n) =>
|
|
307
|
+
color: D,
|
|
308
|
+
onChange: (e, n) => N({
|
|
305
309
|
...t,
|
|
306
310
|
a: e
|
|
307
311
|
}, n)
|
|
308
312
|
}) : null]
|
|
309
313
|
})]
|
|
310
314
|
}),
|
|
311
|
-
/* @__PURE__ */
|
|
312
|
-
className:
|
|
315
|
+
/* @__PURE__ */ l("div", {
|
|
316
|
+
className: a.inputs,
|
|
313
317
|
children: [
|
|
314
|
-
/* @__PURE__ */
|
|
315
|
-
className:
|
|
318
|
+
/* @__PURE__ */ c("span", {
|
|
319
|
+
className: a.format,
|
|
316
320
|
children: "Hex"
|
|
317
321
|
}),
|
|
318
|
-
/* @__PURE__ */
|
|
319
|
-
className:
|
|
320
|
-
value:
|
|
322
|
+
/* @__PURE__ */ c("input", {
|
|
323
|
+
className: a.input,
|
|
324
|
+
value: u.replace(/^#/, ""),
|
|
321
325
|
spellCheck: !1,
|
|
322
326
|
"aria-label": "Hex",
|
|
323
327
|
onChange: (e) => {
|
|
324
328
|
let t = e.target.value.replace(/[^0-9a-fA-F]/g, "");
|
|
325
|
-
|
|
329
|
+
d(t ? `#${t}` : "");
|
|
326
330
|
},
|
|
327
|
-
onBlur:
|
|
331
|
+
onBlur: P,
|
|
328
332
|
onKeyDown: (e) => {
|
|
329
333
|
e.key === "Enter" && (e.preventDefault(), e.target.blur());
|
|
330
334
|
}
|
|
331
335
|
}),
|
|
332
|
-
|
|
333
|
-
className: `${
|
|
336
|
+
p ? /* @__PURE__ */ c("input", {
|
|
337
|
+
className: `${a.input} ${a.inputAlpha}`,
|
|
334
338
|
value: `${Math.round(t.a * 100)} %`,
|
|
335
339
|
"aria-label": "Прозрачность",
|
|
336
|
-
onChange: (e) =>
|
|
340
|
+
onChange: (e) => F(e.target.value),
|
|
337
341
|
onFocus: (e) => e.target.select()
|
|
338
342
|
}) : null
|
|
339
343
|
]
|
|
340
344
|
}),
|
|
341
|
-
/* @__PURE__ */
|
|
342
|
-
className:
|
|
345
|
+
/* @__PURE__ */ c("div", {
|
|
346
|
+
className: a.palette,
|
|
343
347
|
role: "listbox",
|
|
344
348
|
"aria-label": "Палитра",
|
|
345
|
-
children:
|
|
346
|
-
let t =
|
|
347
|
-
return /* @__PURE__ */
|
|
349
|
+
children: m.map((e) => {
|
|
350
|
+
let t = b(e) === j;
|
|
351
|
+
return /* @__PURE__ */ c("button", {
|
|
348
352
|
type: "button",
|
|
349
353
|
role: "option",
|
|
350
354
|
"aria-checked": t,
|
|
351
355
|
"aria-label": e,
|
|
352
|
-
className:
|
|
356
|
+
className: a.swatchBtn,
|
|
353
357
|
style: { "--swatch": e },
|
|
354
358
|
onClick: () => {
|
|
355
|
-
let t =
|
|
356
|
-
t &&
|
|
359
|
+
let t = g(e);
|
|
360
|
+
t && N({
|
|
357
361
|
...t,
|
|
358
|
-
a:
|
|
362
|
+
a: p ? t.a : 1
|
|
359
363
|
}, "commit");
|
|
360
364
|
}
|
|
361
365
|
}, e);
|
|
@@ -364,10 +368,10 @@ function T({ parent: e, hsva: t, setHsva: n, hexDraft: i, setHexDraft: c, alpha:
|
|
|
364
368
|
]
|
|
365
369
|
})] });
|
|
366
370
|
}
|
|
367
|
-
function
|
|
368
|
-
let n =
|
|
369
|
-
|
|
370
|
-
let
|
|
371
|
+
function O({ hsva: e, onChange: t }) {
|
|
372
|
+
let n = o.useRef(null), r = o.useRef(!1), i = o.useRef(t);
|
|
373
|
+
i.current = t;
|
|
374
|
+
let s = (t, r) => {
|
|
371
375
|
let i = n.current;
|
|
372
376
|
if (!i) return {
|
|
373
377
|
s: e.s,
|
|
@@ -375,42 +379,42 @@ function E({ hsva: e, onChange: t }) {
|
|
|
375
379
|
};
|
|
376
380
|
let a = i.getBoundingClientRect();
|
|
377
381
|
return {
|
|
378
|
-
s:
|
|
379
|
-
v:
|
|
382
|
+
s: f((t - a.left) / a.width, 0, 1),
|
|
383
|
+
v: f(1 - (r - a.top) / a.height, 0, 1)
|
|
380
384
|
};
|
|
381
385
|
};
|
|
382
|
-
return
|
|
386
|
+
return o.useEffect(() => {
|
|
383
387
|
let e = (e) => {
|
|
384
|
-
if (!
|
|
385
|
-
let { s: t, v: n } =
|
|
386
|
-
|
|
388
|
+
if (!r.current) return;
|
|
389
|
+
let { s: t, v: n } = s(e.clientX, e.clientY);
|
|
390
|
+
i.current(t, n, "live");
|
|
387
391
|
}, t = (e) => {
|
|
388
|
-
if (!
|
|
389
|
-
|
|
390
|
-
let { s: t, v: n } =
|
|
391
|
-
|
|
392
|
+
if (!r.current) return;
|
|
393
|
+
r.current = !1;
|
|
394
|
+
let { s: t, v: n } = s(e.clientX, e.clientY);
|
|
395
|
+
i.current(t, n, "commit");
|
|
392
396
|
};
|
|
393
397
|
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", t), () => {
|
|
394
398
|
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", t);
|
|
395
399
|
};
|
|
396
|
-
}, []), /* @__PURE__ */
|
|
400
|
+
}, []), /* @__PURE__ */ l("div", {
|
|
397
401
|
ref: n,
|
|
398
|
-
className:
|
|
399
|
-
style: { background:
|
|
402
|
+
className: a.sv,
|
|
403
|
+
style: { background: y(e.h) },
|
|
400
404
|
onPointerDown: (e) => {
|
|
401
|
-
|
|
402
|
-
let { s: t, v: n } =
|
|
403
|
-
|
|
405
|
+
r.current = !0;
|
|
406
|
+
let { s: t, v: n } = s(e.clientX, e.clientY);
|
|
407
|
+
i.current(t, n, "live");
|
|
404
408
|
},
|
|
405
409
|
children: [
|
|
406
|
-
/* @__PURE__ */
|
|
407
|
-
/* @__PURE__ */
|
|
408
|
-
/* @__PURE__ */
|
|
409
|
-
className:
|
|
410
|
+
/* @__PURE__ */ c("div", { className: a.svWhite }),
|
|
411
|
+
/* @__PURE__ */ c("div", { className: a.svBlack }),
|
|
412
|
+
/* @__PURE__ */ c("div", {
|
|
413
|
+
className: a.handle,
|
|
410
414
|
style: {
|
|
411
415
|
left: `${e.s * 100}%`,
|
|
412
416
|
top: `${(1 - e.v) * 100}%`,
|
|
413
|
-
background:
|
|
417
|
+
background: v({
|
|
414
418
|
...e,
|
|
415
419
|
a: 1
|
|
416
420
|
})
|
|
@@ -419,57 +423,57 @@ function E({ hsva: e, onChange: t }) {
|
|
|
419
423
|
]
|
|
420
424
|
});
|
|
421
425
|
}
|
|
422
|
-
function
|
|
423
|
-
return /* @__PURE__ */
|
|
424
|
-
className: `${
|
|
426
|
+
function k({ h: e, onChange: t }) {
|
|
427
|
+
return /* @__PURE__ */ c(j, {
|
|
428
|
+
className: `${a.slider} ${a.sliderHue}`,
|
|
425
429
|
ratio: e / 360,
|
|
426
430
|
onRatio: (e, n) => t(e * 360, n),
|
|
427
|
-
handleColor:
|
|
431
|
+
handleColor: y(e)
|
|
428
432
|
});
|
|
429
433
|
}
|
|
430
|
-
function
|
|
431
|
-
return /* @__PURE__ */
|
|
432
|
-
className: `${
|
|
434
|
+
function A({ a: e, color: t, onChange: n }) {
|
|
435
|
+
return /* @__PURE__ */ c(j, {
|
|
436
|
+
className: `${a.slider} ${a.sliderAlpha}`,
|
|
433
437
|
style: { "--alpha-color": t },
|
|
434
438
|
ratio: e,
|
|
435
439
|
onRatio: n,
|
|
436
440
|
handleColor: t
|
|
437
441
|
});
|
|
438
442
|
}
|
|
439
|
-
function
|
|
440
|
-
let
|
|
441
|
-
let n =
|
|
443
|
+
function j({ className: e, style: t, ratio: n, onRatio: r, handleColor: i }) {
|
|
444
|
+
let s = o.useRef(null), l = o.useRef(!1), u = (e, t) => {
|
|
445
|
+
let n = s.current;
|
|
442
446
|
if (!n) return;
|
|
443
|
-
let
|
|
444
|
-
|
|
447
|
+
let i = n.getBoundingClientRect();
|
|
448
|
+
r(f((e - i.left) / i.width, 0, 1), t);
|
|
445
449
|
};
|
|
446
|
-
return
|
|
450
|
+
return o.useEffect(() => {
|
|
447
451
|
let e = (e) => {
|
|
448
|
-
l.current &&
|
|
452
|
+
l.current && u(e.clientX, "live");
|
|
449
453
|
}, t = (e) => {
|
|
450
|
-
l.current && (l.current = !1,
|
|
454
|
+
l.current && (l.current = !1, u(e.clientX, "commit"));
|
|
451
455
|
};
|
|
452
456
|
return window.addEventListener("pointermove", e), window.addEventListener("pointerup", t), () => {
|
|
453
457
|
window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", t);
|
|
454
458
|
};
|
|
455
|
-
}, [
|
|
456
|
-
ref:
|
|
459
|
+
}, [r]), /* @__PURE__ */ c("div", {
|
|
460
|
+
ref: s,
|
|
457
461
|
className: e,
|
|
458
462
|
style: t,
|
|
459
463
|
onPointerDown: (e) => {
|
|
460
|
-
l.current = !0,
|
|
464
|
+
l.current = !0, u(e.clientX, "live");
|
|
461
465
|
},
|
|
462
|
-
children: /* @__PURE__ */
|
|
463
|
-
className:
|
|
466
|
+
children: /* @__PURE__ */ c("div", {
|
|
467
|
+
className: a.sliderHandle,
|
|
464
468
|
style: {
|
|
465
|
-
left: `${
|
|
466
|
-
background:
|
|
469
|
+
left: `${f(n, 0, 1) * 100}%`,
|
|
470
|
+
background: i
|
|
467
471
|
}
|
|
468
472
|
})
|
|
469
473
|
});
|
|
470
474
|
}
|
|
471
|
-
function
|
|
472
|
-
return /* @__PURE__ */
|
|
475
|
+
function M() {
|
|
476
|
+
return /* @__PURE__ */ l("svg", {
|
|
473
477
|
width: "16",
|
|
474
478
|
height: "16",
|
|
475
479
|
viewBox: "0 0 24 24",
|
|
@@ -480,12 +484,12 @@ function A() {
|
|
|
480
484
|
strokeLinejoin: "round",
|
|
481
485
|
"aria-hidden": !0,
|
|
482
486
|
children: [
|
|
483
|
-
/* @__PURE__ */
|
|
484
|
-
/* @__PURE__ */
|
|
485
|
-
/* @__PURE__ */
|
|
486
|
-
/* @__PURE__ */
|
|
487
|
+
/* @__PURE__ */ c("path", { d: "m2 22 1-1h3l9-9" }),
|
|
488
|
+
/* @__PURE__ */ c("path", { d: "M3 21v-3l9-9" }),
|
|
489
|
+
/* @__PURE__ */ c("path", { d: "m15 5 3 3" }),
|
|
490
|
+
/* @__PURE__ */ c("path", { d: "M17.5 2.5a2.12 2.12 0 0 1 3 3L12 14l-4 1 1-4Z" })
|
|
487
491
|
]
|
|
488
492
|
});
|
|
489
493
|
}
|
|
490
494
|
//#endregion
|
|
491
|
-
export {
|
|
495
|
+
export { d as DEFAULT_COLOR_PALETTE, E as default };
|