@thednp/color-picker 2.0.3 → 2.0.4
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/README.md +3 -3
- package/dist/js/color-picker.cjs +2 -2
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.js +2 -2
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +129 -267
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +22 -21
package/dist/js/color-picker.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const jt = "aria-description", Lt = "aria-expanded", Ae = "aria-hidden",
|
1
|
+
const jt = "aria-description", Lt = "aria-expanded", Ae = "aria-hidden", $t = "aria-selected", tt = "aria-valuenow", et = "aria-valuetext", Ne = "change", He = "focusin", Ee = "focusout", Wt = "keydown", Te = "keyup", At = "click", Me = "pointerdown", ie = "pointermove", Re = "pointerup", Oe = "resize", De = "scroll", Fe = "touchmove", B = "ArrowDown", ot = "ArrowUp", ht = "ArrowLeft", G = "ArrowRight", Ie = "Enter", Ke = "Escape", qt = "Space", Ve = "transitionDuration", Be = "transitionProperty", Z = "tabindex", ae = (o, t, e, s) => {
|
2
2
|
const r = s || !1;
|
3
3
|
o.addEventListener(
|
4
4
|
t,
|
@@ -18,12 +18,12 @@ const jt = "aria-description", Lt = "aria-expanded", Ae = "aria-hidden", wt = "a
|
|
18
18
|
o.classList.remove(...t);
|
19
19
|
}, R = (o, t) => o.classList.contains(t), It = (o) => o != null && typeof o == "object" || !1, ct = (o) => It(o) && typeof o.nodeType == "number" && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some(
|
20
20
|
(t) => o.nodeType === t
|
21
|
-
) || !1, z = (o) => ct(o) && o.nodeType === 1 || !1,
|
22
|
-
data:
|
21
|
+
) || !1, z = (o) => ct(o) && o.nodeType === 1 || !1, J = /* @__PURE__ */ new Map(), lt = {
|
22
|
+
data: J,
|
23
23
|
set: (o, t, e) => {
|
24
|
-
z(o) && (
|
24
|
+
z(o) && (J.has(t) || J.set(t, /* @__PURE__ */ new Map()), J.get(t).set(o, e));
|
25
25
|
},
|
26
|
-
getAllFor: (o) =>
|
26
|
+
getAllFor: (o) => J.get(o) || null,
|
27
27
|
get: (o, t) => {
|
28
28
|
if (!z(o) || !t) return null;
|
29
29
|
const e = lt.getAllFor(t);
|
@@ -31,54 +31,54 @@ const jt = "aria-description", Lt = "aria-expanded", Ae = "aria-hidden", wt = "a
|
|
31
31
|
},
|
32
32
|
remove: (o, t) => {
|
33
33
|
const e = lt.getAllFor(t);
|
34
|
-
!e || !z(o) || (e.delete(o), e.size === 0 &&
|
34
|
+
!e || !z(o) || (e.delete(o), e.size === 0 && J.delete(t));
|
35
35
|
}
|
36
|
-
}, je = (o, t) => lt.get(o, t),
|
36
|
+
}, je = (o, t) => lt.get(o, t), We = (o) => o?.trim().replace(
|
37
37
|
/(?:^\w|[A-Z]|\b\w)/g,
|
38
38
|
(t, e) => e === 0 ? t.toLowerCase() : t.toUpperCase()
|
39
|
-
).replace(/\s+/g, ""),
|
39
|
+
).replace(/\s+/g, ""), W = (o) => typeof o == "string" || !1, qe = (o) => It(o) && o.constructor.name === "Window" || !1, ce = (o) => ct(o) && o.nodeType === 9 || !1, V = (o) => ce(o) ? o : ct(o) ? o.ownerDocument : qe(o) ? o.document : globalThis.document, K = (o, ...t) => Object.assign(o, ...t), x = (o) => {
|
40
40
|
if (!o) return;
|
41
|
-
if (
|
42
|
-
return
|
41
|
+
if (W(o))
|
42
|
+
return V().createElement(o);
|
43
43
|
const { tagName: t } = o, e = x(t);
|
44
44
|
if (!e) return;
|
45
45
|
const s = { ...o };
|
46
|
-
return delete s.tagName,
|
47
|
-
},
|
46
|
+
return delete s.tagName, K(e, s);
|
47
|
+
}, Nt = (o, t) => {
|
48
48
|
if (!o || !t) return;
|
49
|
-
if (
|
50
|
-
return
|
51
|
-
const { tagName: e } = t, s =
|
49
|
+
if (W(t))
|
50
|
+
return V().createElementNS(o, t);
|
51
|
+
const { tagName: e } = t, s = Nt(o, e);
|
52
52
|
if (!s) return;
|
53
53
|
const r = { ...t };
|
54
|
-
return delete r.tagName,
|
55
|
-
},
|
54
|
+
return delete r.tagName, K(s, r);
|
55
|
+
}, Ge = (o, t) => o.dispatchEvent(t), Ht = (o, t, e) => {
|
56
56
|
const s = getComputedStyle(o, e), r = t.replace("webkit", "Webkit").replace(/([A-Z])/g, "-$1").toLowerCase();
|
57
57
|
return s.getPropertyValue(r);
|
58
58
|
}, Ue = (o) => {
|
59
|
-
const t =
|
59
|
+
const t = Ht(o, Be), e = Ht(o, Ve), s = e.includes("ms") ? 1 : 1e3, r = t && t !== "none" ? parseFloat(e) * s : 0;
|
60
60
|
return Number.isNaN(r) ? 0 : r;
|
61
|
-
}, U = (o, t) => o.focus(t),
|
61
|
+
}, U = (o, t) => o.focus(t), Gt = (o) => ["true", !0].includes(o) ? !0 : ["false", !1].includes(o) ? !1 : ["null", "", null, void 0].includes(o) ? null : o !== "" && !Number.isNaN(+o) ? +o : o, pt = (o) => Object.entries(o), _e = (o, t, e, s) => {
|
62
62
|
if (!z(o)) return t;
|
63
63
|
const r = { ...e }, n = { ...o.dataset }, i = { ...t }, a = {}, l = "title";
|
64
64
|
return pt(n).forEach(([c, h]) => {
|
65
|
-
const b =
|
66
|
-
a[b] =
|
65
|
+
const b = We(c);
|
66
|
+
a[b] = Gt(h);
|
67
67
|
}), pt(r).forEach(([c, h]) => {
|
68
|
-
r[c] =
|
68
|
+
r[c] = Gt(h);
|
69
69
|
}), pt(t).forEach(([c, h]) => {
|
70
70
|
c in r ? i[c] = r[c] : c in a ? i[c] = a[c] : i[c] = c === l ? vt(o, l) : h;
|
71
71
|
}), i;
|
72
72
|
}, Ut = (o) => Object.fromEntries(o), ze = (o) => o.offsetHeight, D = (o, t) => {
|
73
73
|
pt(t).forEach(([e, s]) => {
|
74
|
-
if (s &&
|
74
|
+
if (s && W(e) && e.includes("--"))
|
75
75
|
o.style.setProperty(e, s);
|
76
76
|
else {
|
77
77
|
const r = {};
|
78
|
-
r[e] = s,
|
78
|
+
r[e] = s, K(o.style, r);
|
79
79
|
}
|
80
80
|
});
|
81
|
-
},
|
81
|
+
}, Je = (o) => It(o) && o.constructor.name === "Map" || !1, he = (o) => o.toUpperCase(), ge = (o) => z(o) && "offsetWidth" in o || !1, gt = (o, t) => {
|
82
82
|
const { width: e, height: s, top: r, right: n, bottom: i, left: a } = o.getBoundingClientRect();
|
83
83
|
let l = 1, c = 1;
|
84
84
|
if (t && ge(o)) {
|
@@ -95,21 +95,21 @@ const jt = "aria-description", Lt = "aria-expanded", Ae = "aria-hidden", wt = "a
|
|
95
95
|
x: a / l,
|
96
96
|
y: r / c
|
97
97
|
};
|
98
|
-
}, yt = (o) =>
|
98
|
+
}, yt = (o) => V(o).documentElement, Xe = (o) => o ? ce(o) ? o.defaultView : ct(o) ? o?.ownerDocument?.defaultView : o : window;
|
99
99
|
let _t = 0, zt = 0;
|
100
|
-
const
|
100
|
+
const X = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
101
101
|
let e = t ? _t : zt;
|
102
102
|
if (t) {
|
103
|
-
const s = ue(o), r =
|
104
|
-
|
103
|
+
const s = ue(o), r = X.get(s) || /* @__PURE__ */ new Map();
|
104
|
+
X.has(s) || X.set(s, r), Je(r) && !r.has(t) ? (r.set(t, e), _t += 1) : e = r.get(t);
|
105
105
|
} else {
|
106
106
|
const s = o.id || o;
|
107
|
-
|
107
|
+
X.has(s) ? e = X.get(s) : (X.set(s, e), zt += 1);
|
108
108
|
}
|
109
109
|
return e;
|
110
|
-
}, xt = (o) => Array.isArray(o) || !1, be = (o, t) => !o || !t ? null : o.closest(t) || be(o.getRootNode().host, t) || null, _ = (o, t) => z(o) ? o : (z(t) ? t :
|
110
|
+
}, xt = (o) => Array.isArray(o) || !1, be = (o, t) => !o || !t ? null : o.closest(t) || be(o.getRootNode().host, t) || null, _ = (o, t) => z(o) ? o : (z(t) ? t : V()).querySelector(o), st = (o, t) => (t && ct(t) ? t : V()).getElementsByClassName(
|
111
111
|
o
|
112
|
-
),
|
112
|
+
), Kt = [
|
113
113
|
"transparent",
|
114
114
|
"currentColor",
|
115
115
|
"inherit",
|
@@ -1303,7 +1303,7 @@ const J = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
|
1303
1303
|
b: 50
|
1304
1304
|
}
|
1305
1305
|
]
|
1306
|
-
], pe = "deg|rad|grad|turn", de = "[-\\+]?\\d+%?", fe = "[-\\+]?\\d*\\.\\d+%?", me = `[-\\+]?\\d*\\.?\\d+(?:${pe})?`, dt = `(?:${fe})|(?:${de})`, Et = `(?:${dt})|(?:${me}?)`, Ze = "(?:[\\s|\\(\\s|\\s\\(\\s]+)?", Qe = "(?:[\\s|\\)\\s]+)?",
|
1306
|
+
], pe = "deg|rad|grad|turn", de = "[-\\+]?\\d+%?", fe = "[-\\+]?\\d*\\.\\d+%?", me = `[-\\+]?\\d*\\.?\\d+(?:${pe})?`, dt = `(?:${fe})|(?:${de})`, Et = `(?:${dt})|(?:${me}?)`, Ze = "(?:[\\s|\\(\\s|\\s\\(\\s]+)?", Qe = "(?:[\\s|\\)\\s]+)?", Jt = "(?:[,|\\s]+)", Ye = "(?:[,|\\/\\s]*)?", rt = `${Ze}(${Et})${Jt}(${dt})${Jt}(${dt})${Ye}(${dt})?${Qe}`, I = {
|
1307
1307
|
CSS_UNIT: new RegExp(Et),
|
1308
1308
|
ANGLES: pe,
|
1309
1309
|
CSS_ANGLE: me,
|
@@ -1319,16 +1319,16 @@ const J = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
|
1319
1319
|
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
1320
1320
|
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
1321
1321
|
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
1322
|
-
}, ve = (o) =>
|
1322
|
+
}, ve = (o) => Kt.includes(o), nt = (o, t) => o !== null && typeof o == "object" && Object.keys(t).every((e) => e in o), we = (o) => `${o}`.includes(".") && parseFloat(o) === 1, Vt = (o) => typeof o == "string" && o.includes("%"), N = (o) => !!I.CSS_UNIT.exec(`${o}`), $e = ["rgb", "hex", "hsl", "hsv", "hwb"], ke = (o) => Kt.includes(o) || ["#", ...$e].some((t) => o.includes(t)) ? !1 : mt.some(([t]) => o === t), Xt = 1e-6, to = (o, t) => Math.abs(o * t - t) < Xt ? 1 : o < Xt ? 0 : o, E = (o, t) => {
|
1323
1323
|
let e = o;
|
1324
|
-
return
|
1324
|
+
return we(o) && (e = "100%"), Vt(e) ? Number.parseFloat(e) / 100 : (e = typeof e != "number" ? Number.parseFloat(e) : e, t === 360 ? e = (e < 0 ? e % t + t : e > 360 ? e % t : e) / t : (e = Math.min(t, Math.max(0, e)), e = e / t), to(e, t));
|
1325
1325
|
}, Tt = (o) => {
|
1326
1326
|
let t = parseFloat(o);
|
1327
1327
|
return (Number.isNaN(t) || t < 0 || t > 1) && (t = 1), t;
|
1328
|
-
}, ut = (o) => Math.min(1, Math.max(0, o)),
|
1328
|
+
}, ut = (o) => Math.min(1, Math.max(0, o)), q = (o) => o.length === 1 ? `0${o}` : String(o), ye = (o) => {
|
1329
1329
|
const [[, t]] = mt.filter(([e]) => e === o.toLowerCase());
|
1330
1330
|
return t;
|
1331
|
-
},
|
1331
|
+
}, H = (o) => parseInt(o, 16), Mt = (o) => H(o) / 255, xe = (o) => m(o * 255).toString(16), Zt = (o, t, e) => {
|
1332
1332
|
const s = Math.max(o, t, e), r = Math.min(o, t, e);
|
1333
1333
|
let n = 0, i = 0;
|
1334
1334
|
const a = (s + r) / 2;
|
@@ -1379,17 +1379,17 @@ const J = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
|
1379
1379
|
return { r: u, g: d, b: g };
|
1380
1380
|
}, St = (o, t, e, s) => {
|
1381
1381
|
const r = [
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1382
|
+
q(m(o).toString(16)),
|
1383
|
+
q(m(t).toString(16)),
|
1384
|
+
q(m(e).toString(16))
|
1385
1385
|
];
|
1386
1386
|
return s && r[0].charAt(0) === r[0].charAt(1) && r[1].charAt(0) === r[1].charAt(1) && r[2].charAt(0) === r[2].charAt(1) ? r[0].charAt(0) + r[1].charAt(0) + r[2].charAt(0) : r.join("");
|
1387
1387
|
}, Ct = (o, t, e, s, r) => {
|
1388
1388
|
const n = [
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1389
|
+
q(m(o).toString(16)),
|
1390
|
+
q(m(t).toString(16)),
|
1391
|
+
q(m(e).toString(16)),
|
1392
|
+
q(xe(s))
|
1393
1393
|
];
|
1394
1394
|
return r && n[0].charAt(0) === n[0].charAt(1) && n[1].charAt(0) === n[1].charAt(1) && n[2].charAt(0) === n[2].charAt(1) && n[3].charAt(0) === n[3].charAt(1) ? n[0].charAt(0) + n[1].charAt(0) + n[2].charAt(0) + n[3].charAt(0) : n.join("");
|
1395
1395
|
}, Ce = (o) => {
|
@@ -1439,30 +1439,30 @@ const J = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
|
1439
1439
|
format: "hwb",
|
1440
1440
|
ok: !0
|
1441
1441
|
} : ([, e, s, r, n] = I.hex8.exec(t) || [], e && s && r && n ? {
|
1442
|
-
r:
|
1443
|
-
g:
|
1444
|
-
b:
|
1442
|
+
r: H(e),
|
1443
|
+
g: H(s),
|
1444
|
+
b: H(r),
|
1445
1445
|
a: Mt(n),
|
1446
1446
|
format: "hex",
|
1447
1447
|
ok: !0
|
1448
1448
|
} : ([, e, s, r] = I.hex6.exec(t) || [], e && s && r ? {
|
1449
|
-
r:
|
1450
|
-
g:
|
1451
|
-
b:
|
1449
|
+
r: H(e),
|
1450
|
+
g: H(s),
|
1451
|
+
b: H(r),
|
1452
1452
|
a: 1,
|
1453
1453
|
format: "hex",
|
1454
1454
|
ok: !0
|
1455
1455
|
} : ([, e, s, r, n] = I.hex4.exec(t) || [], e && s && r && n ? {
|
1456
|
-
r:
|
1457
|
-
g:
|
1458
|
-
b:
|
1456
|
+
r: H(e + e),
|
1457
|
+
g: H(s + s),
|
1458
|
+
b: H(r + r),
|
1459
1459
|
a: Mt(n + n),
|
1460
1460
|
format: "hex",
|
1461
1461
|
ok: !0
|
1462
1462
|
} : ([, e, s, r] = I.hex3.exec(t) || [], e && s && r ? {
|
1463
|
-
r:
|
1464
|
-
g:
|
1465
|
-
b:
|
1463
|
+
r: H(e + e),
|
1464
|
+
g: H(s + s),
|
1465
|
+
b: H(r + r),
|
1466
1466
|
a: 1,
|
1467
1467
|
format: "hex",
|
1468
1468
|
ok: !0
|
@@ -1480,28 +1480,28 @@ const J = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
|
1480
1480
|
b: E(e, 255)
|
1481
1481
|
}), te = (o) => {
|
1482
1482
|
let t = { r: 0, g: 0, b: 0 }, e = o, s = 1, r, n, i, a, l, c, h, b, u = "rgb", d = !1;
|
1483
|
-
if ((!e || typeof e == "string") && (e = Ce(e), d = e.ok || d), nt(e, t) &&
|
1483
|
+
if ((!e || typeof e == "string") && (e = Ce(e), d = e.ok || d), nt(e, t) && N(e.r) && N(e.g) && N(e.b)) {
|
1484
1484
|
if (["format", "ok", "originalInput"].every((g) => g in e))
|
1485
1485
|
return { ...e };
|
1486
1486
|
({ r: h, g: b, b: l } = e), t = eo(h, b, l), u = "format" in e ? e.format : "rgb";
|
1487
1487
|
}
|
1488
|
-
return nt(e, { h: 0, s: 0, v: 0 }) &&
|
1488
|
+
return nt(e, { h: 0, s: 0, v: 0 }) && N(e.h) && N(e.s) && N(e.v) && ({ h: c, s: r, v: n } = e, c = E(c, 360), r = E(r, 100), n = E(n, 100), t = Rt(c, r, n), u = "hsv"), nt(e, { h: 0, s: 0, l: 0 }) && N(e.h) && N(e.s) && N(e.l) && ({ h: c, s: r, l: i } = e, c = E(c, 360), r = E(r, 100), i = E(i, 100), t = at(c, r, i), u = "hsl"), nt(e, { h: 0, w: 0, b: 0 }) && N(e.h) && N(e.w) && N(e.b) && ({ h: c, w: a, b: l } = e, c = E(c, 360), a = E(a, 100), l = E(l, 100), t = Se(c, a, l), u = "hwb"), N(e.a) && (s = e.a, s = Vt(s) || parseFloat(`${s}`) > 1 ? E(s, 100) : s), {
|
1489
1489
|
...t,
|
1490
1490
|
a: Tt(s),
|
1491
1491
|
format: u,
|
1492
1492
|
ok: d
|
1493
1493
|
};
|
1494
|
-
}, oo = "1.0.
|
1494
|
+
}, oo = "1.0.14";
|
1495
1495
|
class y {
|
1496
1496
|
// bring main utilities to front
|
1497
1497
|
static matchers = I;
|
1498
|
-
static isOnePointZero =
|
1499
|
-
static isPercentage =
|
1500
|
-
static isValidCSSUnit =
|
1498
|
+
static isOnePointZero = we;
|
1499
|
+
static isPercentage = Vt;
|
1500
|
+
static isValidCSSUnit = N;
|
1501
1501
|
static isNonColor = ve;
|
1502
1502
|
static isColorName = ke;
|
1503
1503
|
static isColorType = nt;
|
1504
|
-
static pad2 =
|
1504
|
+
static pad2 = q;
|
1505
1505
|
static clamp01 = ut;
|
1506
1506
|
static bound01 = E;
|
1507
1507
|
static boundAlpha = Tt;
|
@@ -1517,12 +1517,12 @@ class y {
|
|
1517
1517
|
static hsvToRgb = Rt;
|
1518
1518
|
static hueToRgb = ft;
|
1519
1519
|
static hwbToRgb = Se;
|
1520
|
-
static parseIntFromHex =
|
1520
|
+
static parseIntFromHex = H;
|
1521
1521
|
static stringInputToObject = Ce;
|
1522
1522
|
static inputToRGB = te;
|
1523
1523
|
static roundPart = m;
|
1524
1524
|
static webColors = mt;
|
1525
|
-
static nonColors =
|
1525
|
+
static nonColors = Kt;
|
1526
1526
|
static version = oo;
|
1527
1527
|
// main public properties
|
1528
1528
|
r;
|
@@ -1534,7 +1534,7 @@ class y {
|
|
1534
1534
|
originalInput;
|
1535
1535
|
// main public methods
|
1536
1536
|
constructor(t, e) {
|
1537
|
-
const s = e &&
|
1537
|
+
const s = e && $e.includes(e) ? e : "", { r, g: n, b: i, a, ok: l, format: c } = te(t);
|
1538
1538
|
this.originalInput = t, this.r = r, this.g = n, this.b = i, this.a = a, this.ok = l, this.format = s || c;
|
1539
1539
|
}
|
1540
1540
|
/**
|
@@ -1775,13 +1775,6 @@ class Ot {
|
|
1775
1775
|
lightSteps;
|
1776
1776
|
saturation;
|
1777
1777
|
colors;
|
1778
|
-
/**
|
1779
|
-
* The `hue` parameter is optional, which would be set to 0.
|
1780
|
-
* * `args.hue` the starting Hue [0, 360]
|
1781
|
-
* * `args.hueSteps` Hue Steps Count [5, 24]
|
1782
|
-
* * `args.lightSteps` Lightness Steps Count [5, 12]
|
1783
|
-
* * `args.saturation` Saturation [0, 100]
|
1784
|
-
*/
|
1785
1778
|
constructor(...t) {
|
1786
1779
|
let e = 0, s = 12, r = 10, n = [0.5], i = 100;
|
1787
1780
|
if (t.length === 4)
|
@@ -1807,9 +1800,9 @@ class Ot {
|
|
1807
1800
|
for (let g = 0; g < s; g += 1) {
|
1808
1801
|
const p = (e + g * l) % 360;
|
1809
1802
|
n.forEach((f) => {
|
1810
|
-
const
|
1803
|
+
const w = new y({ h: p, s: 100, l: f * 100 });
|
1811
1804
|
a.push(
|
1812
|
-
i < 100 ?
|
1805
|
+
i < 100 ? w.saturate(i - 100) : w
|
1813
1806
|
);
|
1814
1807
|
});
|
1815
1808
|
}
|
@@ -1853,7 +1846,7 @@ const Dt = {
|
|
1853
1846
|
"magenta",
|
1854
1847
|
"pink"
|
1855
1848
|
], ee = (o) => {
|
1856
|
-
if (!
|
1849
|
+
if (!W(o)) return !1;
|
1857
1850
|
try {
|
1858
1851
|
JSON.parse(o);
|
1859
1852
|
} catch {
|
@@ -1883,7 +1876,6 @@ const Dt = {
|
|
1883
1876
|
const b = x({
|
1884
1877
|
tagName: "input",
|
1885
1878
|
id: l,
|
1886
|
-
// name: cID, - prevent saving the value to a form
|
1887
1879
|
type: t === "hex" ? "text" : "number",
|
1888
1880
|
value: i === "alpha" ? "100" : "0",
|
1889
1881
|
className: `color-input ${i}`,
|
@@ -1891,7 +1883,7 @@ const Dt = {
|
|
1891
1883
|
spellcheck: !1
|
1892
1884
|
});
|
1893
1885
|
let u = "100", d = "1";
|
1894
|
-
i !== "alpha" && (t === "rgb" ? (u = "255", d = "1") : i === "hue" && (u = "360", d = "1")),
|
1886
|
+
i !== "alpha" && (t === "rgb" ? (u = "255", d = "1") : i === "hue" && (u = "360", d = "1")), K(b, {
|
1895
1887
|
min: "0",
|
1896
1888
|
max: u,
|
1897
1889
|
step: d
|
@@ -1934,8 +1926,8 @@ const Dt = {
|
|
1934
1926
|
min: 0,
|
1935
1927
|
max: b
|
1936
1928
|
}
|
1937
|
-
].forEach((
|
1938
|
-
const { i: S, c: L, l: C, min: P, max: M } =
|
1929
|
+
].forEach(($) => {
|
1930
|
+
const { i: S, c: L, l: C, min: P, max: M } = $, T = x({
|
1939
1931
|
tagName: "div",
|
1940
1932
|
className: "color-control",
|
1941
1933
|
role: "presentation"
|
@@ -1962,19 +1954,19 @@ const Dt = {
|
|
1962
1954
|
const { input: s, format: r, componentLabels: n } = o, { defaultsLabel: i, presetsLabel: a } = n, l = e === "color-options", c = t instanceof Ot, h = l ? a : i, b = c ? t.colors : t, u = b.length, { lightSteps: d } = c ? t : { lightSteps: null }, g = d || [9, 10].find((A) => u >= A * 2 && !(u % A)) || 5, p = l && u > g;
|
1963
1955
|
let f = 2;
|
1964
1956
|
f = p && u > g * 2 ? 3 : f, f = p && u > g * 3 ? 4 : f, f = p && u > g * 4 ? 5 : f;
|
1965
|
-
const
|
1957
|
+
const w = f - (u <= g * 3 ? 1 : 2), $ = p && u > w * g;
|
1966
1958
|
let S = e;
|
1967
|
-
S +=
|
1959
|
+
S += $ ? " scrollable" : "", S += p ? " multiline" : "";
|
1968
1960
|
const L = p ? "1px" : "0.25rem";
|
1969
1961
|
let C = p ? 1.75 : 2;
|
1970
1962
|
C = g > 5 && p ? 1.5 : C;
|
1971
|
-
const P = `${
|
1963
|
+
const P = `${w * C}rem`, M = `calc(${f} * ${C}rem + ${f - 1} * ${L})`, T = x({
|
1972
1964
|
tagName: "ul",
|
1973
1965
|
className: S,
|
1974
1966
|
role: "listbox",
|
1975
1967
|
ariaLabel: h
|
1976
1968
|
});
|
1977
|
-
return
|
1969
|
+
return $ && D(T, {
|
1978
1970
|
"--grid-item-size": `${C}rem`,
|
1979
1971
|
"--grid-fit": `${g}`,
|
1980
1972
|
"--grid-gap": L,
|
@@ -1983,7 +1975,7 @@ const Dt = {
|
|
1983
1975
|
}), b.forEach((A) => {
|
1984
1976
|
let [F, Y] = typeof A == "string" ? A.trim().split(":") : [];
|
1985
1977
|
A instanceof y && (F = A.toHexString(), Y = F);
|
1986
|
-
const Bt = new y(A instanceof y ? A : F, r).toString() === vt(s, "value"),
|
1978
|
+
const Bt = new y(A instanceof y ? A : F, r).toString() === vt(s, "value"), wt = x({
|
1987
1979
|
tagName: "li",
|
1988
1980
|
className: `color-option${Bt ? " active" : ""}`,
|
1989
1981
|
innerText: `${Y || F}`,
|
@@ -1991,7 +1983,7 @@ const Dt = {
|
|
1991
1983
|
role: "option",
|
1992
1984
|
ariaSelected: Bt ? "true" : "false"
|
1993
1985
|
});
|
1994
|
-
v(
|
1986
|
+
v(wt, "data-value", `${F}`), l && D(wt, { backgroundColor: F }), T.append(wt);
|
1995
1987
|
}), T;
|
1996
1988
|
}, no = (o) => {
|
1997
1989
|
const {
|
@@ -2019,15 +2011,15 @@ const Dt = {
|
|
2019
2011
|
innerText: `${b}. ${u}: ${p}`
|
2020
2012
|
})
|
2021
2013
|
);
|
2022
|
-
const
|
2014
|
+
const w = x(
|
2023
2015
|
{
|
2024
2016
|
tagName: "div",
|
2025
2017
|
className: "color-dropdown picker",
|
2026
2018
|
role: "group",
|
2027
2019
|
ariaLabelledBy: `picker-btn-${r}`
|
2028
2020
|
}
|
2029
|
-
),
|
2030
|
-
if (
|
2021
|
+
), $ = ro(o), S = so(o);
|
2022
|
+
if (w.append($, S), t.before(f), e.append(w), i || a) {
|
2031
2023
|
const L = x({
|
2032
2024
|
tagName: "div",
|
2033
2025
|
className: "color-dropdown scrollable menu"
|
@@ -2042,11 +2034,11 @@ const Dt = {
|
|
2042
2034
|
tabIndex: -1,
|
2043
2035
|
ariaExpanded: "false",
|
2044
2036
|
ariaHasPopup: "true"
|
2045
|
-
}), P = encodeURI("http://www.w3.org/2000/svg"), M =
|
2037
|
+
}), P = encodeURI("http://www.w3.org/2000/svg"), M = Nt(P, {
|
2046
2038
|
tagName: "svg"
|
2047
2039
|
});
|
2048
2040
|
v(M, "xmlns", P), v(M, "viewBox", "0 0 512 512"), v(M, Ae, "true");
|
2049
|
-
const T =
|
2041
|
+
const T = Nt(P, {
|
2050
2042
|
tagName: "path"
|
2051
2043
|
});
|
2052
2044
|
v(
|
@@ -2063,7 +2055,7 @@ const Dt = {
|
|
2063
2055
|
), e.append(C, L);
|
2064
2056
|
}
|
2065
2057
|
i && c.includes(l) && (o.value = l), v(t, Z, "-1");
|
2066
|
-
}, io = "2.0.
|
2058
|
+
}, io = "2.0.4", Q = "color-picker", ao = `[data-function="${Q}"]`, se = `.${Q}`, lo = {
|
2067
2059
|
componentLabels: Dt,
|
2068
2060
|
colorLabels: it,
|
2069
2061
|
format: "rgb",
|
@@ -2071,14 +2063,14 @@ const Dt = {
|
|
2071
2063
|
colorKeywords: !1
|
2072
2064
|
}, { roundPart: k, nonColors: bt } = y, co = (o) => je(o, Q), ho = (o) => new go(o), re = (o, t) => {
|
2073
2065
|
const e = t ? ae : le, { input: s, pickerToggle: r, menuToggle: n } = o;
|
2074
|
-
e(s,
|
2066
|
+
e(s, He, o.showPicker), e(r, At, o.togglePicker), n && e(n, At, o.toggleMenu);
|
2075
2067
|
}, Pe = (o, t) => {
|
2076
|
-
const e = t ? ae : le, { input: s, colorMenu: r, parent: n } = o, i =
|
2077
|
-
e(o.controls, Me, o.pointerDown), o.controlKnobs.forEach((l) => e(l,
|
2078
|
-
(l) => e(l,
|
2079
|
-
), r && (e(r, At, o.menuClickHandler), e(r,
|
2068
|
+
const e = t ? ae : le, { input: s, colorMenu: r, parent: n } = o, i = V(s), a = Xe(i);
|
2069
|
+
e(o.controls, Me, o.pointerDown), o.controlKnobs.forEach((l) => e(l, Wt, o.handleKnobs)), e(a, De, o.handleScroll), e(a, Oe, o.update), [s, ...o.inputs].forEach(
|
2070
|
+
(l) => e(l, Ne, o.changeHandler)
|
2071
|
+
), r && (e(r, At, o.menuClickHandler), e(r, Wt, o.menuKeyHandler)), e(i, ie, o.pointerMove), e(i, Re, o.pointerUp), e(n, Ee, o.handleFocusOut), e(i, Te, o.handleDismiss);
|
2080
2072
|
}, ne = (o) => {
|
2081
|
-
|
2073
|
+
Ge(o.input, new CustomEvent("colorpicker.change"));
|
2082
2074
|
}, Le = (o) => {
|
2083
2075
|
o && ["bottom", "top"].forEach((t) => O(o, t));
|
2084
2076
|
}, Pt = (o, t) => {
|
@@ -2086,13 +2078,11 @@ const Dt = {
|
|
2086
2078
|
R(i, "open") || j(i, "open"), l && (O(l, "show"), Le(l)), j(t, "bottom"), ze(t), j(t, "show"), a && o.update(), o.isOpen || (Pe(o, !0), o.updateDropdownPosition(), o.isOpen = !0, v(o.input, Z, "0"), r && v(r, Z, "0")), v(h, Lt, "true"), c && v(c, Lt, "false");
|
2087
2079
|
};
|
2088
2080
|
class go {
|
2089
|
-
// bring utils to staic
|
2090
2081
|
static Color = y;
|
2091
2082
|
static ColorPalette = Ot;
|
2092
2083
|
static getInstance = co;
|
2093
2084
|
static init = ho;
|
2094
2085
|
static selector = ao;
|
2095
|
-
// utils important for render
|
2096
2086
|
static roundPart = k;
|
2097
2087
|
static setElementStyle = D;
|
2098
2088
|
static setAttribute = v;
|
@@ -2122,13 +2112,6 @@ class go {
|
|
2122
2112
|
inputs;
|
2123
2113
|
controlKnobs;
|
2124
2114
|
visuals;
|
2125
|
-
/**
|
2126
|
-
* Returns a new `ColorPicker` instance. The target of this constructor
|
2127
|
-
* must be an `HTMLInputElement`.
|
2128
|
-
*
|
2129
|
-
* @param target the target `<input>` element
|
2130
|
-
* @param config instance options
|
2131
|
-
*/
|
2132
2115
|
constructor(t, e) {
|
2133
2116
|
const s = _(t);
|
2134
2117
|
if (typeof t > "u")
|
@@ -2157,29 +2140,29 @@ class go {
|
|
2157
2140
|
e || {}
|
2158
2141
|
);
|
2159
2142
|
let h = it;
|
2160
|
-
xt(a) && a.length === 17 ? h = a :
|
2143
|
+
xt(a) && a.length === 17 ? h = a : W(a) && a.split(",").length === 17 && (h = a.split(",")), K(
|
2161
2144
|
this.colorLabels,
|
2162
2145
|
Ut(
|
2163
2146
|
h.map((p, f) => [it[f], p])
|
2164
2147
|
)
|
2165
2148
|
);
|
2166
|
-
const b =
|
2167
|
-
if (this.componentLabels =
|
2149
|
+
const b = W(i) && ee(i) ? JSON.parse(i) : i;
|
2150
|
+
if (this.componentLabels = K(
|
2168
2151
|
{ ...Dt },
|
2169
2152
|
b
|
2170
|
-
), this.color = new y(s.value || "#fff", n), this.format = n, xt(l) && l.length ? this.colorKeywords = l :
|
2153
|
+
), this.color = new y(s.value || "#fff", n), this.format = n, xt(l) && l.length ? this.colorKeywords = l : W(l) && l.length && (this.colorKeywords = l.split(",").map((p) => p.trim())), xt(c) && c.length)
|
2171
2154
|
this.colorPresets = c;
|
2172
2155
|
else if (c && ee(c)) {
|
2173
|
-
const { hue: p, hueSteps: f, lightSteps:
|
2156
|
+
const { hue: p, hueSteps: f, lightSteps: w, saturation: $ } = JSON.parse(
|
2174
2157
|
c
|
2175
2158
|
);
|
2176
2159
|
this.colorPresets = new Ot(
|
2177
2160
|
p,
|
2178
2161
|
f,
|
2179
|
-
|
2180
|
-
|
2162
|
+
w,
|
2163
|
+
$
|
2181
2164
|
);
|
2182
|
-
} else
|
2165
|
+
} else W(c) && (this.colorPresets = c.split(",").map((p) => p.trim()));
|
2183
2166
|
no(this);
|
2184
2167
|
const [u, d] = st(
|
2185
2168
|
"color-dropdown",
|
@@ -2198,61 +2181,44 @@ class go {
|
|
2198
2181
|
...st("visual-control", g)
|
2199
2182
|
], this.update(), re(this, !0), lt.set(s, Q, this);
|
2200
2183
|
}
|
2201
|
-
/** Returns the current colour value */
|
2202
2184
|
get value() {
|
2203
2185
|
return this.input.value;
|
2204
2186
|
}
|
2205
|
-
/**
|
2206
|
-
* Sets a new colour value.
|
2207
|
-
*
|
2208
|
-
* @param {string} v new colour value
|
2209
|
-
*/
|
2210
2187
|
set value(t) {
|
2211
2188
|
this.input.value = t;
|
2212
2189
|
}
|
2213
|
-
/** Check if the colour presets include any non-colour. */
|
2214
2190
|
get hasNonColor() {
|
2215
2191
|
return this.colorKeywords instanceof Array && this.colorKeywords.some((t) => bt.includes(t));
|
2216
2192
|
}
|
2217
|
-
/** Returns hexadecimal value of the current colour. */
|
2218
2193
|
get hex() {
|
2219
2194
|
return this.color.toHex(!0);
|
2220
2195
|
}
|
2221
|
-
/** Returns the current colour value in {h,s,v,a} object format. */
|
2222
2196
|
get hsv() {
|
2223
2197
|
return this.color.toHsv();
|
2224
2198
|
}
|
2225
|
-
/** Returns the current colour value in {h,s,l,a} object format. */
|
2226
2199
|
get hsl() {
|
2227
2200
|
return this.color.toHsl();
|
2228
2201
|
}
|
2229
|
-
/** Returns the current colour value in {h,w,b,a} object format. */
|
2230
2202
|
get hwb() {
|
2231
2203
|
return this.color.toHwb();
|
2232
2204
|
}
|
2233
|
-
/** Returns the current colour value in {r,g,b,a} object format. */
|
2234
2205
|
get rgb() {
|
2235
2206
|
return this.color.toRgb();
|
2236
2207
|
}
|
2237
|
-
/** Returns the current colour brightness. */
|
2238
2208
|
get brightness() {
|
2239
2209
|
return this.color.brightness;
|
2240
2210
|
}
|
2241
|
-
/** Returns the current colour luminance. */
|
2242
2211
|
get luminance() {
|
2243
2212
|
return this.color.luminance;
|
2244
2213
|
}
|
2245
|
-
/** Checks if the current colour requires a light text colour. */
|
2246
2214
|
get isDark() {
|
2247
2215
|
const { color: t, brightness: e } = this;
|
2248
2216
|
return e < 120 && t.a > 0.33;
|
2249
2217
|
}
|
2250
|
-
/** Checks if the current input value is a valid colour. */
|
2251
2218
|
get isValid() {
|
2252
2219
|
const t = this.input.value;
|
2253
2220
|
return t !== "" && new y(t).isValid;
|
2254
2221
|
}
|
2255
|
-
/** Returns the colour appearance, usually the closest colour name for the current value. */
|
2256
2222
|
get appearance() {
|
2257
2223
|
const { colorLabels: t, hsl: e, hsv: s, format: r } = this, n = k(e.h * 360), i = r === "hsl" ? e.s : s.s, a = k(i * 100), l = k(e.l * 100), c = s.v * 100;
|
2258
2224
|
let h = "black";
|
@@ -2272,7 +2238,6 @@ class go {
|
|
2272
2238
|
} else n >= 75 && n < 155 ? h = c < 68 ? t.green : t.lime : n >= 155 && n < 175 ? h = t.teal : n >= 175 && n < 195 ? h = t.cyan : n >= 195 && n < 255 ? h = t.blue : n >= 255 && n < 270 ? h = t.violet : n >= 270 && n < 295 ? h = t.magenta : n >= 295 && n < 345 && (h = t.pink);
|
2273
2239
|
return h;
|
2274
2240
|
}
|
2275
|
-
/** Updates `ColorPicker` visuals. */
|
2276
2241
|
updateVisuals() {
|
2277
2242
|
const { controlPositions: t, visuals: e } = this, [s, r, n] = e, { offsetHeight: i } = s, a = t.c2y / i, { r: l, g: c, b: h } = new y({ h: a * 360, s: 100, l: 50 }).toRgb(), b = "linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)", u = 1 - t.c3y / i, d = k(u * 100) / 100, g = new y({
|
2278
2243
|
h: a * 360,
|
@@ -2292,48 +2257,20 @@ class go {
|
|
2292
2257
|
background: `linear-gradient(rgba(${l},${c},${h},1) 0%,rgba(${l},${c},${h},0) 100%)`
|
2293
2258
|
});
|
2294
2259
|
}
|
2295
|
-
/**
|
2296
|
-
* The `ColorPicker` *focusout* event listener when open.
|
2297
|
-
*
|
2298
|
-
* @param e
|
2299
|
-
* @this {ColorPicker}
|
2300
|
-
*/
|
2301
2260
|
handleFocusOut = ({ relatedTarget: t }) => {
|
2302
2261
|
t && !this.parent.contains(t) && this.hide(!0);
|
2303
2262
|
};
|
2304
|
-
/**
|
2305
|
-
* The `ColorPicker` *keyup* event listener when open.
|
2306
|
-
*
|
2307
|
-
* @param e
|
2308
|
-
* @this {ColorPicker}
|
2309
|
-
*/
|
2310
2263
|
handleDismiss = ({ code: t }) => {
|
2311
|
-
this.isOpen && t ===
|
2264
|
+
this.isOpen && t === Ke && this.hide();
|
2312
2265
|
};
|
2313
|
-
/**
|
2314
|
-
* The `ColorPicker` *scroll* event listener when open.
|
2315
|
-
*
|
2316
|
-
* @param e
|
2317
|
-
*/
|
2318
2266
|
handleScroll = (t) => {
|
2319
|
-
const { activeElement: e } =
|
2267
|
+
const { activeElement: e } = V(this.input);
|
2320
2268
|
this.updateDropdownPosition(), ([ie, Fe].includes(t.type) && this.dragElement || e && this.controlKnobs.includes(e)) && (t.stopPropagation(), t.preventDefault());
|
2321
2269
|
};
|
2322
|
-
/**
|
2323
|
-
* The `ColorPicker` keyboard event listener for menu navigation.
|
2324
|
-
*
|
2325
|
-
* @param e
|
2326
|
-
*/
|
2327
2270
|
menuKeyHandler = (t) => {
|
2328
|
-
const { target: e, code: s } = t, { previousElementSibling: r, nextElementSibling: n, parentElement: i } = e, a = i && R(i, "color-options"), l = i ? [...i.children] : [], c = a && Number(
|
2329
|
-
[B, ot,
|
2271
|
+
const { target: e, code: s } = t, { previousElementSibling: r, nextElementSibling: n, parentElement: i } = e, a = i && R(i, "color-options"), l = i ? [...i.children] : [], c = a && Number(Ht(i, "--grid-fit")), h = l.indexOf(e), b = h > -1 && c && l[h - c], u = h > -1 && c && l[h + c];
|
2272
|
+
[B, ot, qt].includes(s) && t.preventDefault(), a ? b && s === ot ? U(b) : u && s === B ? U(u) : r && s === ht ? U(r) : n && s === G && U(n) : r && [ht, ot].includes(s) ? U(r) : n && [G, B].includes(s) && U(n), [Ie, qt].includes(s) && this.menuClickHandler(t);
|
2330
2273
|
};
|
2331
|
-
/**
|
2332
|
-
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
2333
|
-
*
|
2334
|
-
* @param e
|
2335
|
-
* @this {ColorPicker}
|
2336
|
-
*/
|
2337
2274
|
menuClickHandler = (t) => {
|
2338
2275
|
const { target: e } = t, { colorMenu: s } = this, r = (vt(
|
2339
2276
|
e,
|
@@ -2344,68 +2281,46 @@ class go {
|
|
2344
2281
|
let i = r;
|
2345
2282
|
i = bt.includes(i) ? "white" : i, i = i === "transparent" ? "rgba(0,0,0,0)" : i;
|
2346
2283
|
const { r: a, g: l, b: c, a: h } = new y(i);
|
2347
|
-
|
2284
|
+
K(this.color, {
|
2348
2285
|
r: a,
|
2349
2286
|
g: l,
|
2350
2287
|
b: c,
|
2351
2288
|
a: h
|
2352
|
-
}), this.update(), n !== e && (n && (O(n, "active"), kt(n,
|
2289
|
+
}), this.update(), n !== e && (n && (O(n, "active"), kt(n, $t)), j(e, "active"), v(e, $t, "true"), bt.includes(r) && (this.value = r), ne(this));
|
2353
2290
|
};
|
2354
|
-
/**
|
2355
|
-
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
2356
|
-
*
|
2357
|
-
* @param e
|
2358
|
-
*/
|
2359
2291
|
pointerDown = (t) => {
|
2360
2292
|
if (t.button !== 0) return;
|
2361
|
-
const { target: e, pageX: s, pageY: r } = t, { colorMenu: n, visuals: i, controlKnobs: a } = this, [l, c, h] = i, [b, u, d] = a, g = a.includes(e) ? e.previousElementSibling : e, p = gt(g), f = yt(l),
|
2362
|
-
if (e === l || e === b ? (this.dragElement = g, this.changeControl1(
|
2293
|
+
const { target: e, pageX: s, pageY: r } = t, { colorMenu: n, visuals: i, controlKnobs: a } = this, [l, c, h] = i, [b, u, d] = a, g = a.includes(e) ? e.previousElementSibling : e, p = gt(g), f = yt(l), w = s - f.scrollLeft - p.left, $ = r - f.scrollTop - p.top;
|
2294
|
+
if (e === l || e === b ? (this.dragElement = g, this.changeControl1(w, $)) : e === c || e === u ? (this.dragElement = g, this.changeControl2($)) : (e === h || e === d) && (this.dragElement = g, this.changeAlpha($)), n) {
|
2363
2295
|
const S = _("li.active", n);
|
2364
|
-
S && (O(S, "active"), kt(S,
|
2296
|
+
S && (O(S, "active"), kt(S, $t));
|
2365
2297
|
}
|
2366
2298
|
t.preventDefault();
|
2367
2299
|
};
|
2368
|
-
/**
|
2369
|
-
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
2370
|
-
*
|
2371
|
-
* @param e
|
2372
|
-
* @this
|
2373
|
-
*/
|
2374
2300
|
pointerUp = ({ target: t }) => {
|
2375
|
-
const { parent: e } = this, s =
|
2301
|
+
const { parent: e } = this, s = V(e), r = _(`${se}.open`, s) !== null, n = s.getSelection();
|
2376
2302
|
!this.dragElement && (!n || !n.toString().length) && !e.contains(t) && this.hide(r), this.dragElement = void 0;
|
2377
2303
|
};
|
2378
|
-
/**
|
2379
|
-
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
2380
|
-
*
|
2381
|
-
* @param {PointerEvent} e
|
2382
|
-
*/
|
2383
2304
|
pointerMove = (t) => {
|
2384
2305
|
const { dragElement: e, visuals: s } = this, [r, n, i] = s, { pageX: a, pageY: l } = t;
|
2385
2306
|
if (!e) return;
|
2386
2307
|
const c = gt(e), h = yt(r), b = a - h.scrollLeft - c.left, u = l - h.scrollTop - c.top;
|
2387
2308
|
e === r && this.changeControl1(b, u), e === n && this.changeControl2(u), e === i && this.changeAlpha(u);
|
2388
2309
|
};
|
2389
|
-
/**
|
2390
|
-
* The `ColorPicker` *keydown* event listener for control knobs.
|
2391
|
-
*
|
2392
|
-
* @param e
|
2393
|
-
*/
|
2394
2310
|
handleKnobs = (t) => {
|
2395
2311
|
const { target: e, code: s } = t;
|
2396
|
-
if (![ot, B, ht,
|
2312
|
+
if (![ot, B, ht, G].includes(s)) return;
|
2397
2313
|
t.preventDefault();
|
2398
|
-
const { controlKnobs: r, visuals: n } = this, { offsetWidth: i, offsetHeight: a } = n[0], [l, c, h] = r, { activeElement: b } =
|
2314
|
+
const { controlKnobs: r, visuals: n } = this, { offsetWidth: i, offsetHeight: a } = n[0], [l, c, h] = r, { activeElement: b } = V(l), u = r.find((g) => g === b), d = a / 360;
|
2399
2315
|
if (u) {
|
2400
2316
|
let g = 0, p = 0;
|
2401
2317
|
if (e === l) {
|
2402
2318
|
const f = i / 100;
|
2403
|
-
[ht,
|
2404
|
-
} else e === c ? (this.controlPositions.c2y += [B,
|
2319
|
+
[ht, G].includes(s) ? this.controlPositions.c1x += s === G ? f : -f : [ot, B].includes(s) && (this.controlPositions.c1y += s === B ? d : -d), g = this.controlPositions.c1x, p = this.controlPositions.c1y, this.changeControl1(g, p);
|
2320
|
+
} else e === c ? (this.controlPositions.c2y += [B, G].includes(s) ? d : -d, p = this.controlPositions.c2y, this.changeControl2(p)) : e === h && (this.controlPositions.c3y += [B, G].includes(s) ? d : -d, p = this.controlPositions.c3y, this.changeAlpha(p));
|
2405
2321
|
this.handleScroll(t);
|
2406
2322
|
}
|
2407
2323
|
};
|
2408
|
-
/** The event listener of the colour form inputs. */
|
2409
2324
|
changeHandler = () => {
|
2410
2325
|
let t;
|
2411
2326
|
const {
|
@@ -2415,41 +2330,33 @@ class go {
|
|
2415
2330
|
input: n,
|
2416
2331
|
controlPositions: i,
|
2417
2332
|
visuals: a
|
2418
|
-
} = this, { activeElement: l } =
|
2333
|
+
} = this, { activeElement: l } = V(n), { offsetHeight: c } = a[0], [h, , , b] = e, [u, d, g, p] = s === "rgb" ? e.map(($) => parseFloat($.value) / ($ === b ? 100 : 1)) : e.map(($) => parseFloat($.value) / ($ !== h ? 100 : 360)), f = this.hasNonColor && bt.includes(r), w = b ? p : 1 - i.c3y / c;
|
2419
2334
|
if (l === n || l && e.includes(l)) {
|
2420
2335
|
l === n ? f ? t = r === "transparent" ? "rgba(0,0,0,0)" : "rgb(0,0,0)" : t = r : s === "hex" ? t = h.value : s === "hsl" ? t = {
|
2421
2336
|
h: u,
|
2422
2337
|
s: d,
|
2423
2338
|
l: g,
|
2424
|
-
a:
|
2339
|
+
a: w
|
2425
2340
|
} : s === "hwb" ? t = {
|
2426
2341
|
h: u,
|
2427
2342
|
w: d,
|
2428
2343
|
b: g,
|
2429
|
-
a:
|
2344
|
+
a: w
|
2430
2345
|
} : t = {
|
2431
2346
|
r: u,
|
2432
2347
|
g: d,
|
2433
2348
|
b: g,
|
2434
|
-
a:
|
2349
|
+
a: w
|
2435
2350
|
};
|
2436
|
-
const { r:
|
2437
|
-
|
2438
|
-
r:
|
2351
|
+
const { r: $, g: S, b: L, a: C } = new y(t);
|
2352
|
+
K(this.color, {
|
2353
|
+
r: $,
|
2439
2354
|
g: S,
|
2440
2355
|
b: L,
|
2441
2356
|
a: C
|
2442
2357
|
}), this.setControlPositions(), this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals(), l === n && f && (this.value = r);
|
2443
2358
|
}
|
2444
2359
|
};
|
2445
|
-
/**
|
2446
|
-
* Updates `ColorPicker` first control:
|
2447
|
-
* * `lightness` and `saturation` for HEX/RGB;
|
2448
|
-
* * `lightness` and `hue` for HSL.
|
2449
|
-
*
|
2450
|
-
* @param X the X component of the offset
|
2451
|
-
* @param Y the Y component of the offset
|
2452
|
-
*/
|
2453
2360
|
changeControl1(t, e) {
|
2454
2361
|
let [s, r] = [0, 0];
|
2455
2362
|
const { controlPositions: n, visuals: i } = this, { offsetHeight: a, offsetWidth: l } = i[0];
|
@@ -2460,20 +2367,13 @@ class go {
|
|
2460
2367
|
v: b * 100,
|
2461
2368
|
a: u
|
2462
2369
|
});
|
2463
|
-
|
2370
|
+
K(this.color, {
|
2464
2371
|
r: d,
|
2465
2372
|
g,
|
2466
2373
|
b: p,
|
2467
2374
|
a: f
|
2468
2375
|
}), this.controlPositions.c1x = s, this.controlPositions.c1y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2469
2376
|
}
|
2470
|
-
/**
|
2471
|
-
* Updates `ColorPicker` second control:
|
2472
|
-
* * `hue` for HEX/RGB/HWB;
|
2473
|
-
* * `saturation` for HSL.
|
2474
|
-
*
|
2475
|
-
* @param Y the Y offset
|
2476
|
-
*/
|
2477
2377
|
changeControl2(t) {
|
2478
2378
|
const { controlPositions: e, visuals: s } = this, { offsetHeight: r, offsetWidth: n } = s[0];
|
2479
2379
|
let i = 0;
|
@@ -2484,19 +2384,13 @@ class go {
|
|
2484
2384
|
v: c * 100,
|
2485
2385
|
a: h
|
2486
2386
|
});
|
2487
|
-
|
2387
|
+
K(this.color, {
|
2488
2388
|
r: b,
|
2489
2389
|
g: u,
|
2490
2390
|
b: d,
|
2491
2391
|
a: g
|
2492
2392
|
}), this.controlPositions.c2y = i, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2493
2393
|
}
|
2494
|
-
/**
|
2495
|
-
* Updates `ColorPicker` last control,
|
2496
|
-
* the `alpha` channel.
|
2497
|
-
*
|
2498
|
-
* @param Y
|
2499
|
-
*/
|
2500
2394
|
changeAlpha(t) {
|
2501
2395
|
const { visuals: e } = this, { offsetHeight: s } = e[0];
|
2502
2396
|
let r = 0;
|
@@ -2504,51 +2398,42 @@ class go {
|
|
2504
2398
|
const n = 1 - r / s;
|
2505
2399
|
this.color.setAlpha(n), this.controlPositions.c3y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2506
2400
|
}
|
2507
|
-
/**
|
2508
|
-
* Updates `ColorPicker` control positions on:
|
2509
|
-
* * initialization
|
2510
|
-
* * window resize
|
2511
|
-
*/
|
2512
2401
|
update = () => {
|
2513
2402
|
this.updateDropdownPosition(), this.updateAppearance(), this.setControlPositions(), this.updateInputs(!0), this.updateControls(), this.updateVisuals();
|
2514
2403
|
};
|
2515
|
-
/** Updates the open dropdown position on *scroll* event. */
|
2516
2404
|
updateDropdownPosition() {
|
2517
2405
|
const { input: t, colorPicker: e, colorMenu: s } = this, r = gt(t), { top: n, bottom: i } = r, { offsetHeight: a } = t, l = yt(t).clientHeight, h = R(e, "show") ? e : s;
|
2518
2406
|
if (!h) return;
|
2519
2407
|
const { offsetHeight: b } = h, u = l - i, d = n, g = n + b + a > l, p = n - b < 0;
|
2520
2408
|
(R(h, "bottom") || !p) && u < d && g ? (O(h, "bottom"), j(h, "top")) : (O(h, "top"), j(h, "bottom"));
|
2521
2409
|
}
|
2522
|
-
/** Updates control knobs' positions. */
|
2523
2410
|
setControlPositions() {
|
2524
2411
|
const { visuals: t, color: e, hsv: s } = this, { offsetHeight: r, offsetWidth: n } = t[0], i = e.a, a = s.h, l = s.s, c = s.v;
|
2525
2412
|
this.controlPositions.c1x = l * n, this.controlPositions.c1y = (1 - c) * r, this.controlPositions.c2y = a * r, this.controlPositions.c3y = (1 - i) * r;
|
2526
2413
|
}
|
2527
|
-
/** Update the visual appearance label and control knob labels. */
|
2528
2414
|
updateAppearance() {
|
2529
2415
|
const { componentLabels: t, color: e, parent: s, hsv: r, hex: n, format: i, controlKnobs: a } = this, { appearanceLabel: l, hexLabel: c, valueLabel: h } = t;
|
2530
2416
|
let { r: b, g: u, b: d } = e.toRgb();
|
2531
|
-
const [g, p, f] = a,
|
2417
|
+
const [g, p, f] = a, w = k(r.h * 360), $ = e.a, S = k(r.s * 100), L = k(r.v * 100), C = this.appearance;
|
2532
2418
|
let P = `${c} ${n.split("").join(" ")}`;
|
2533
2419
|
if (i === "hwb") {
|
2534
2420
|
const { hwb: A } = this, F = k(A.w * 100), Y = k(A.b * 100);
|
2535
|
-
P = `HWB: ${
|
2421
|
+
P = `HWB: ${w}°, ${F}%, ${Y}%`, v(g, et, `${F}% & ${Y}%`), v(g, tt, `${F}`), v(
|
2536
2422
|
p,
|
2537
2423
|
jt,
|
2538
2424
|
`${h}: ${P}. ${l}: ${C}.`
|
2539
|
-
), v(p, et, `${
|
2425
|
+
), v(p, et, `${w}%`), v(p, tt, `${w}`);
|
2540
2426
|
} else
|
2541
|
-
[b, u, d] = [b, u, d].map(k), P = i === "hsl" ? `HSL: ${
|
2427
|
+
[b, u, d] = [b, u, d].map(k), P = i === "hsl" ? `HSL: ${w}°, ${S}%, ${L}%` : P, P = i === "rgb" ? `RGB: ${b}, ${u}, ${d}` : P, v(g, et, `${L}% & ${S}%`), v(g, tt, `${L}`), v(
|
2542
2428
|
p,
|
2543
2429
|
jt,
|
2544
2430
|
`${h}: ${P}. ${l}: ${C}.`
|
2545
|
-
), v(p, et, `${
|
2546
|
-
const M = k(
|
2431
|
+
), v(p, et, `${w}°`), v(p, tt, `${w}`);
|
2432
|
+
const M = k($ * 100);
|
2547
2433
|
v(f, et, `${M}%`), v(f, tt, `${M}`);
|
2548
2434
|
const T = e.toString();
|
2549
2435
|
D(this.input, { backgroundColor: T }), this.isDark ? (R(s, "txt-light") && O(s, "txt-light"), R(s, "txt-dark") || j(s, "txt-dark")) : (R(s, "txt-dark") && O(s, "txt-dark"), R(s, "txt-light") || j(s, "txt-light"));
|
2550
2436
|
}
|
2551
|
-
/** Updates the control knobs actual positions. */
|
2552
2437
|
updateControls() {
|
2553
2438
|
const { controlKnobs: t, controlPositions: e } = this;
|
2554
2439
|
let { c1x: s, c1y: r, c2y: n, c3y: i } = e;
|
@@ -2557,11 +2442,6 @@ class go {
|
|
2557
2442
|
transform: `translate3d(${s - 4}px,${r - 4}px,0)`
|
2558
2443
|
}), D(l, { transform: `translate3d(0,${n - 4}px,0)` }), D(c, { transform: `translate3d(0,${i - 4}px,0)` });
|
2559
2444
|
}
|
2560
|
-
/**
|
2561
|
-
* Updates all color form inputs.
|
2562
|
-
*
|
2563
|
-
* @param isPrevented when `true`, the component original event is prevented
|
2564
|
-
*/
|
2565
2445
|
updateInputs(t) {
|
2566
2446
|
const { value: e, format: s, inputs: r, color: n, hsl: i } = this, [a, l, c, h] = r, b = k(n.a * 100), u = k(i.h * 360);
|
2567
2447
|
let d = n.toString();
|
@@ -2571,45 +2451,28 @@ class go {
|
|
2571
2451
|
const g = k(i.l * 100), p = k(i.s * 100);
|
2572
2452
|
d = this.color.toHslString(), a.value = `${u}`, l.value = `${p}`, c.value = `${g}`, h.value = `${b}`;
|
2573
2453
|
} else if (s === "hwb") {
|
2574
|
-
const { w: g, b: p } = this.hwb, f = k(g * 100),
|
2575
|
-
d = this.color.toHwbString(), a.value = `${u}`, l.value = `${f}`, c.value = `${
|
2454
|
+
const { w: g, b: p } = this.hwb, f = k(g * 100), w = k(p * 100);
|
2455
|
+
d = this.color.toHwbString(), a.value = `${u}`, l.value = `${f}`, c.value = `${w}`, h.value = `${b}`;
|
2576
2456
|
} else if (s === "rgb") {
|
2577
2457
|
let { r: g, g: p, b: f } = this.rgb;
|
2578
2458
|
[g, p, f] = [g, p, f].map(k), d = this.color.toRgbString(), a.value = `${g}`, l.value = `${p}`, c.value = `${f}`, h.value = `${b}`;
|
2579
2459
|
}
|
2580
2460
|
this.value = d, !t && d !== e && ne(this);
|
2581
2461
|
}
|
2582
|
-
/**
|
2583
|
-
* Toggle the `ColorPicker` dropdown visibility.
|
2584
|
-
*
|
2585
|
-
* @param e
|
2586
|
-
*/
|
2587
2462
|
togglePicker = (t) => {
|
2588
2463
|
t && t.preventDefault();
|
2589
2464
|
const { colorPicker: e } = this;
|
2590
2465
|
this.isOpen && R(e, "show") ? this.hide(!0) : Pt(this, e);
|
2591
2466
|
};
|
2592
|
-
/** Shows the `ColorPicker` dropdown. */
|
2593
2467
|
showPicker = () => {
|
2594
2468
|
const { colorPicker: t } = this;
|
2595
2469
|
["top", "bottom"].some((e) => R(t, e)) || Pt(this, t);
|
2596
2470
|
};
|
2597
|
-
/**
|
2598
|
-
* Toggles the visibility of the `ColorPicker` presets menu.
|
2599
|
-
*
|
2600
|
-
* @param e
|
2601
|
-
* @this {ColorPicker}
|
2602
|
-
*/
|
2603
2471
|
toggleMenu = (t) => {
|
2604
2472
|
t && t.preventDefault();
|
2605
2473
|
const { colorMenu: e } = this;
|
2606
2474
|
this.isOpen && R(e, "show") ? this.hide(!0) : Pt(this, e);
|
2607
2475
|
};
|
2608
|
-
/**
|
2609
|
-
* Hides the currently open `ColorPicker` dropdown.
|
2610
|
-
*
|
2611
|
-
* @param {boolean=} focusPrevented
|
2612
|
-
*/
|
2613
2476
|
hide(t) {
|
2614
2477
|
if (!this.isOpen) return;
|
2615
2478
|
const {
|
@@ -2624,7 +2487,6 @@ class go {
|
|
2624
2487
|
Le(c), _(".show", i) || (O(i, "open"), Pe(this), this.isOpen = !1);
|
2625
2488
|
}, b)), t || U(e), v(a, Z, "-1"), h === s && v(s, Z, "-1");
|
2626
2489
|
}
|
2627
|
-
/** Removes `ColorPicker` from target `<input>`. */
|
2628
2490
|
dispose() {
|
2629
2491
|
const { input: t, parent: e } = this;
|
2630
2492
|
this.hide(!0), re(this), [...e.children].forEach((s) => {
|