@thednp/color-picker 2.0.2 → 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 +25 -14
- package/dist/css/color-picker.css +3 -6
- package/dist/css/color-picker.css.map +1 -0
- package/dist/css/color-picker.min.css +1 -2
- package/dist/css/color-picker.min.css.map +1 -0
- package/dist/css/color-picker.rtl.css +3 -6
- package/dist/css/color-picker.rtl.css.map +1 -0
- package/dist/css/color-picker.rtl.min.css +1 -2
- package/dist/css/color-picker.rtl.min.css.map +1 -0
- package/dist/js/color-picker.cjs +2 -2
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +307 -300
- package/dist/js/color-picker.js +2 -2
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +390 -491
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +40 -47
- package/.eslintrc.cjs +0 -199
- package/.lgtm.yml +0 -9
- package/.prettierrc.json +0 -15
- package/.stylelintrc.json +0 -236
- package/compile.cjs +0 -51
- package/dts.config.ts +0 -15
- package/src/scss/_variables.scss +0 -6
- package/src/scss/color-picker.rtl.scss +0 -27
- package/src/scss/color-picker.scss +0 -536
- package/src/ts/colorPalette.ts +0 -89
- package/src/ts/index.ts +0 -1237
- package/src/ts/interface/ColorNames.ts +0 -20
- package/src/ts/interface/colorPickerLabels.ts +0 -20
- package/src/ts/interface/colorPickerOptions.ts +0 -11
- package/src/ts/interface/paletteOptions.ts +0 -6
- package/src/ts/util/colorNames.ts +0 -21
- package/src/ts/util/colorPickerLabels.ts +0 -24
- package/src/ts/util/getColorControls.ts +0 -90
- package/src/ts/util/getColorForm.ts +0 -75
- package/src/ts/util/getColorMenu.ts +0 -83
- package/src/ts/util/isValidJSON.ts +0 -19
- package/src/ts/util/setMarkup.ts +0 -130
- package/src/ts/util/vHidden.ts +0 -2
- package/test/color-palette.test.ts +0 -137
- package/test/color-picker.test.ts +0 -705
- package/test/fixtures/colorNamesFrench.js +0 -3
- package/test/fixtures/componentLabelsFrench.js +0 -21
- package/test/fixtures/format.js +0 -3
- package/test/fixtures/getMarkup.js +0 -36
- package/test/fixtures/getRandomInt.js +0 -6
- package/test/fixtures/sampleWebcolors.js +0 -18
- package/test/fixtures/swipe.ts +0 -33
- package/test/fixtures/testSample.js +0 -8
- package/test/fixtures/write.ts +0 -37
- package/tsconfig.json +0 -47
- package/vite.config.mts +0 -27
- package/vitest.config-ui.ts +0 -26
- package/vitest.config.ts +0 -26
package/dist/js/color-picker.mjs
CHANGED
@@ -1,149 +1,89 @@
|
|
1
|
-
const
|
2
|
-
/* istanbul ignore else @preserve */
|
3
|
-
mt ? mt.brands.some((o) => Xt.test(o.brand)) : Xt.test(vt);
|
4
|
-
const Yt = /(iPhone|iPod|iPad)/;
|
5
|
-
mt ? mt.brands.some((o) => Yt.test(o.brand)) : (
|
6
|
-
/* istanbul ignore next @preserve */
|
7
|
-
Yt.test(vt)
|
8
|
-
);
|
9
|
-
vt && vt.includes("Firefox");
|
10
|
-
const { head: wt } = document;
|
11
|
-
["webkitPerspective", "perspective"].some((o) => o in wt.style);
|
12
|
-
const Bt = (o, t, e, s) => {
|
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) => {
|
13
2
|
const r = s || !1;
|
14
|
-
o.addEventListener(
|
15
|
-
|
3
|
+
o.addEventListener(
|
4
|
+
t,
|
5
|
+
e,
|
6
|
+
r
|
7
|
+
);
|
8
|
+
}, le = (o, t, e, s) => {
|
16
9
|
const r = s || !1;
|
17
|
-
o.removeEventListener(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
Bt(o, t, r, s);
|
24
|
-
}, Xe = () => {
|
25
|
-
};
|
26
|
-
(() => {
|
27
|
-
let o = !1;
|
28
|
-
try {
|
29
|
-
const t = Object.defineProperty({}, "passive", {
|
30
|
-
get: () => (o = !0, o)
|
31
|
-
});
|
32
|
-
Je(document, Re, Xe, t);
|
33
|
-
} catch {
|
34
|
-
}
|
35
|
-
return o;
|
36
|
-
})();
|
37
|
-
["webkitTransform", "transform"].some((o) => o in wt.style);
|
38
|
-
["webkitAnimation", "animation"].some((o) => o in wt.style);
|
39
|
-
["webkitTransition", "transition"].some((o) => o in wt.style);
|
40
|
-
const kt = (o, t) => o.getAttribute(t), v = (o, t, e) => o.setAttribute(t, e), Pt = (o, t) => o.removeAttribute(t), q = (o, ...t) => {
|
10
|
+
o.removeEventListener(
|
11
|
+
t,
|
12
|
+
e,
|
13
|
+
r
|
14
|
+
);
|
15
|
+
}, vt = (o, t) => o.getAttribute(t), v = (o, t, e) => o.setAttribute(t, e), kt = (o, t) => o.removeAttribute(t), j = (o, ...t) => {
|
41
16
|
o.classList.add(...t);
|
42
17
|
}, O = (o, ...t) => {
|
43
18
|
o.classList.remove(...t);
|
44
|
-
}, R = (o, t) => o.classList.contains(t),
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
*
|
49
|
-
* @param element target element
|
50
|
-
* @param component the component's name or a unique key
|
51
|
-
* @param instance the component instance
|
52
|
-
*/
|
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
|
+
(t) => o.nodeType === t
|
21
|
+
) || !1, z = (o) => ct(o) && o.nodeType === 1 || !1, J = /* @__PURE__ */ new Map(), lt = {
|
22
|
+
data: J,
|
53
23
|
set: (o, t, e) => {
|
54
|
-
|
24
|
+
z(o) && (J.has(t) || J.set(t, /* @__PURE__ */ new Map()), J.get(t).set(o, e));
|
55
25
|
},
|
56
|
-
|
57
|
-
* Returns all instances for specified component.
|
58
|
-
*
|
59
|
-
* @param component the component's name or a unique key
|
60
|
-
* @returns all the component instances
|
61
|
-
*/
|
62
|
-
getAllFor: (o) => z.get(o) || null,
|
63
|
-
/**
|
64
|
-
* Returns the instance associated with the target.
|
65
|
-
*
|
66
|
-
* @param element target element
|
67
|
-
* @param component the component's name or a unique key
|
68
|
-
* @returns the instance
|
69
|
-
*/
|
26
|
+
getAllFor: (o) => J.get(o) || null,
|
70
27
|
get: (o, t) => {
|
71
|
-
if (!
|
72
|
-
const e =
|
28
|
+
if (!z(o) || !t) return null;
|
29
|
+
const e = lt.getAllFor(t);
|
73
30
|
return o && e && e.get(o) || null;
|
74
31
|
},
|
75
|
-
/**
|
76
|
-
* Removes web components data.
|
77
|
-
*
|
78
|
-
* @param element target element
|
79
|
-
* @param component the component's name or a unique key
|
80
|
-
*/
|
81
32
|
remove: (o, t) => {
|
82
|
-
const e =
|
83
|
-
!e || !
|
33
|
+
const e = lt.getAllFor(t);
|
34
|
+
!e || !z(o) || (e.delete(o), e.size === 0 && J.delete(t));
|
84
35
|
}
|
85
|
-
},
|
36
|
+
}, je = (o, t) => lt.get(o, t), We = (o) => o?.trim().replace(
|
37
|
+
/(?:^\w|[A-Z]|\b\w)/g,
|
38
|
+
(t, e) => e === 0 ? t.toLowerCase() : t.toUpperCase()
|
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) => {
|
86
40
|
if (!o) return;
|
87
|
-
if (
|
41
|
+
if (W(o))
|
88
42
|
return V().createElement(o);
|
89
43
|
const { tagName: t } = o, e = x(t);
|
90
44
|
if (!e) return;
|
91
45
|
const s = { ...o };
|
92
46
|
return delete s.tagName, K(e, s);
|
93
|
-
},
|
47
|
+
}, Nt = (o, t) => {
|
94
48
|
if (!o || !t) return;
|
95
|
-
if (
|
49
|
+
if (W(t))
|
96
50
|
return V().createElementNS(o, t);
|
97
|
-
const { tagName: e } = t, s =
|
51
|
+
const { tagName: e } = t, s = Nt(o, e);
|
98
52
|
if (!s) return;
|
99
53
|
const r = { ...t };
|
100
54
|
return delete r.tagName, K(s, r);
|
101
|
-
},
|
102
|
-
const
|
103
|
-
return
|
104
|
-
},
|
105
|
-
const t =
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
/* istanbul ignore next */
|
110
|
-
0
|
111
|
-
);
|
112
|
-
return Number.isNaN(r) ? (
|
113
|
-
/* istanbul ignore next */
|
114
|
-
0
|
115
|
-
) : r;
|
116
|
-
}, W = (o, t) => o.focus(t), Zt = (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), eo = (o, t, e, s) => {
|
55
|
+
}, Ge = (o, t) => o.dispatchEvent(t), Ht = (o, t, e) => {
|
56
|
+
const s = getComputedStyle(o, e), r = t.replace("webkit", "Webkit").replace(/([A-Z])/g, "-$1").toLowerCase();
|
57
|
+
return s.getPropertyValue(r);
|
58
|
+
}, Ue = (o) => {
|
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
|
+
return Number.isNaN(r) ? 0 : r;
|
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
|
+
if (!z(o)) return t;
|
117
63
|
const r = { ...e }, n = { ...o.dataset }, i = { ...t }, a = {}, l = "title";
|
118
64
|
return pt(n).forEach(([c, h]) => {
|
119
|
-
const b = c;
|
120
|
-
a[b] =
|
65
|
+
const b = We(c);
|
66
|
+
a[b] = Gt(h);
|
121
67
|
}), pt(r).forEach(([c, h]) => {
|
122
|
-
r[c] =
|
68
|
+
r[c] = Gt(h);
|
123
69
|
}), pt(t).forEach(([c, h]) => {
|
124
|
-
c in r ? i[c] = r[c] : c in a ? i[c] = a[c] : i[c] = c === l ?
|
70
|
+
c in r ? i[c] = r[c] : c in a ? i[c] = a[c] : i[c] = c === l ? vt(o, l) : h;
|
125
71
|
}), i;
|
126
|
-
},
|
72
|
+
}, Ut = (o) => Object.fromEntries(o), ze = (o) => o.offsetHeight, D = (o, t) => {
|
127
73
|
pt(t).forEach(([e, s]) => {
|
128
|
-
if (s &&
|
74
|
+
if (s && W(e) && e.includes("--"))
|
129
75
|
o.style.setProperty(e, s);
|
130
76
|
else {
|
131
77
|
const r = {};
|
132
78
|
r[e] = s, K(o.style, r);
|
133
79
|
}
|
134
80
|
});
|
135
|
-
},
|
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) => {
|
136
82
|
const { width: e, height: s, top: r, right: n, bottom: i, left: a } = o.getBoundingClientRect();
|
137
83
|
let l = 1, c = 1;
|
138
|
-
if (t &&
|
84
|
+
if (t && ge(o)) {
|
139
85
|
const { offsetWidth: h, offsetHeight: b } = o;
|
140
|
-
l = h > 0 ? Math.round(e) / h : (
|
141
|
-
/* istanbul ignore next */
|
142
|
-
1
|
143
|
-
), c = b > 0 ? Math.round(s) / b : (
|
144
|
-
/* istanbul ignore next */
|
145
|
-
1
|
146
|
-
);
|
86
|
+
l = h > 0 ? Math.round(e) / h : 1, c = b > 0 ? Math.round(s) / b : 1;
|
147
87
|
}
|
148
88
|
return {
|
149
89
|
width: e / l,
|
@@ -155,28 +95,30 @@ const kt = (o, t) => o.getAttribute(t), v = (o, t, e) => o.setAttribute(t, e), P
|
|
155
95
|
x: a / l,
|
156
96
|
y: r / c
|
157
97
|
};
|
158
|
-
},
|
159
|
-
let
|
160
|
-
const
|
161
|
-
let e = t ?
|
98
|
+
}, yt = (o) => V(o).documentElement, Xe = (o) => o ? ce(o) ? o.defaultView : ct(o) ? o?.ownerDocument?.defaultView : o : window;
|
99
|
+
let _t = 0, zt = 0;
|
100
|
+
const X = /* @__PURE__ */ new Map(), ue = (o, t) => {
|
101
|
+
let e = t ? _t : zt;
|
162
102
|
if (t) {
|
163
|
-
const s =
|
164
|
-
|
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);
|
165
105
|
} else {
|
166
106
|
const s = o.id || o;
|
167
|
-
|
107
|
+
X.has(s) ? e = X.get(s) : (X.set(s, e), zt += 1);
|
168
108
|
}
|
169
109
|
return e;
|
170
|
-
},
|
171
|
-
var t;
|
172
|
-
return o ? pe(o) ? o.defaultView : Z(o) ? (t = o?.ownerDocument) == null ? void 0 : t.defaultView : o : window;
|
173
|
-
}, Ct = (o) => Array.isArray(o) || !1, me = (o, t) => o ? o.closest(t) || // break out of `ShadowRoot`
|
174
|
-
me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).querySelector(o), st = (o, t) => (t && Z(t) ? t : V()).getElementsByClassName(
|
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(
|
175
111
|
o
|
176
|
-
),
|
112
|
+
), Kt = [
|
113
|
+
"transparent",
|
114
|
+
"currentColor",
|
115
|
+
"inherit",
|
116
|
+
"revert",
|
117
|
+
"initial"
|
118
|
+
], m = (o) => {
|
177
119
|
const t = Math.floor(o);
|
178
120
|
return o - t < 0.5 ? t : Math.round(o);
|
179
|
-
},
|
121
|
+
}, mt = [
|
180
122
|
[
|
181
123
|
"aliceblue",
|
182
124
|
{
|
@@ -1361,13 +1303,13 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1361
1303
|
b: 50
|
1362
1304
|
}
|
1363
1305
|
]
|
1364
|
-
],
|
1365
|
-
CSS_UNIT: new RegExp(
|
1366
|
-
ANGLES:
|
1367
|
-
CSS_ANGLE:
|
1368
|
-
CSS_INTEGER:
|
1369
|
-
CSS_NUMBER:
|
1370
|
-
CSS_UNIT2:
|
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
|
+
CSS_UNIT: new RegExp(Et),
|
1308
|
+
ANGLES: pe,
|
1309
|
+
CSS_ANGLE: me,
|
1310
|
+
CSS_INTEGER: de,
|
1311
|
+
CSS_NUMBER: fe,
|
1312
|
+
CSS_UNIT2: Et,
|
1371
1313
|
PERMISSIVE_MATCH: rt,
|
1372
1314
|
hwb: new RegExp(`hwb${rt}`),
|
1373
1315
|
rgb: new RegExp(`rgb(?:a)?${rt}`),
|
@@ -1377,16 +1319,16 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1377
1319
|
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
1378
1320
|
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
1379
1321
|
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
1380
|
-
},
|
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) => {
|
1381
1323
|
let e = o;
|
1382
|
-
return
|
1383
|
-
},
|
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
|
+
}, Tt = (o) => {
|
1384
1326
|
let t = parseFloat(o);
|
1385
1327
|
return (Number.isNaN(t) || t < 0 || t > 1) && (t = 1), t;
|
1386
|
-
}, ut = (o) => Math.min(1, Math.max(0, o)),
|
1387
|
-
const [[, t]] =
|
1328
|
+
}, ut = (o) => Math.min(1, Math.max(0, o)), q = (o) => o.length === 1 ? `0${o}` : String(o), ye = (o) => {
|
1329
|
+
const [[, t]] = mt.filter(([e]) => e === o.toLowerCase());
|
1388
1330
|
return t;
|
1389
|
-
},
|
1331
|
+
}, H = (o) => parseInt(o, 16), Mt = (o) => H(o) / 255, xe = (o) => m(o * 255).toString(16), Zt = (o, t, e) => {
|
1390
1332
|
const s = Math.max(o, t, e), r = Math.min(o, t, e);
|
1391
1333
|
let n = 0, i = 0;
|
1392
1334
|
const a = (s + r) / 2;
|
@@ -1400,7 +1342,7 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1400
1342
|
}, ft = (o, t, e) => {
|
1401
1343
|
let s = e;
|
1402
1344
|
return s < 0 && (s += 1), s > 1 && (s -= 1), s < 1 / 6 ? o + (t - o) * (6 * s) : s < 1 / 2 ? t : s < 2 / 3 ? o + (t - o) * (2 / 3 - s) * 6 : o;
|
1403
|
-
},
|
1345
|
+
}, at = (o, t, e) => {
|
1404
1346
|
let s = 0, r = 0, n = 0;
|
1405
1347
|
if (t === 0)
|
1406
1348
|
r = e, n = e, s = e;
|
@@ -1409,7 +1351,7 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1409
1351
|
s = ft(a, i, o + 1 / 3), r = ft(a, i, o), n = ft(a, i, o - 1 / 3);
|
1410
1352
|
}
|
1411
1353
|
return { r: s, g: r, b: n };
|
1412
|
-
},
|
1354
|
+
}, Qt = (o, t, e) => {
|
1413
1355
|
let s = 0, r = 0;
|
1414
1356
|
const n = Math.min(o, t, e), i = Math.max(o, t, e), a = 1 - i;
|
1415
1357
|
if (i === n) return { h: 0, w: n, b: a };
|
@@ -1420,45 +1362,45 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1420
1362
|
w: n,
|
1421
1363
|
b: a
|
1422
1364
|
};
|
1423
|
-
},
|
1365
|
+
}, Se = (o, t, e) => {
|
1424
1366
|
if (t + e >= 1) {
|
1425
1367
|
const i = t / (t + e);
|
1426
1368
|
return { r: i, g: i, b: i };
|
1427
1369
|
}
|
1428
|
-
let { r: s, g: r, b: n } =
|
1370
|
+
let { r: s, g: r, b: n } = at(o, 1, 0.5);
|
1429
1371
|
return [s, r, n] = [s, r, n].map((i) => i * (1 - t - e) + t), { r: s, g: r, b: n };
|
1430
|
-
},
|
1372
|
+
}, Yt = (o, t, e) => {
|
1431
1373
|
const s = Math.max(o, t, e), r = Math.min(o, t, e);
|
1432
1374
|
let n = 0;
|
1433
1375
|
const i = s, a = s - r, l = s === 0 ? 0 : a / s;
|
1434
1376
|
return s === r ? n = 0 : (o === s && (n = (t - e) / a + (t < e ? 6 : 0)), t === s && (n = (e - o) / a + 2), e === s && (n = (o - t) / a + 4), n /= 6), { h: n, s: l, v: i };
|
1435
|
-
},
|
1377
|
+
}, Rt = (o, t, e) => {
|
1436
1378
|
const s = o * 6, r = t, n = e, i = Math.floor(s), a = s - i, l = n * (1 - r), c = n * (1 - a * r), h = n * (1 - (1 - a) * r), b = i % 6, u = [n, c, l, l, h, n][b], d = [h, n, n, c, l, l][b], g = [l, l, h, n, n, c][b];
|
1437
1379
|
return { r: u, g: d, b: g };
|
1438
|
-
},
|
1380
|
+
}, St = (o, t, e, s) => {
|
1439
1381
|
const r = [
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1382
|
+
q(m(o).toString(16)),
|
1383
|
+
q(m(t).toString(16)),
|
1384
|
+
q(m(e).toString(16))
|
1443
1385
|
];
|
1444
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("");
|
1445
|
-
},
|
1387
|
+
}, Ct = (o, t, e, s, r) => {
|
1446
1388
|
const n = [
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1389
|
+
q(m(o).toString(16)),
|
1390
|
+
q(m(t).toString(16)),
|
1391
|
+
q(m(e).toString(16)),
|
1392
|
+
q(xe(s))
|
1451
1393
|
];
|
1452
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("");
|
1453
|
-
},
|
1395
|
+
}, Ce = (o) => {
|
1454
1396
|
const t = String(o).trim().toLowerCase();
|
1455
|
-
if (
|
1456
|
-
return Object.assign(
|
1397
|
+
if (ke(t))
|
1398
|
+
return Object.assign(ye(t), {
|
1457
1399
|
a: 1,
|
1458
1400
|
format: "rgb",
|
1459
1401
|
ok: !0
|
1460
1402
|
});
|
1461
|
-
if (
|
1403
|
+
if (ve(t))
|
1462
1404
|
return {
|
1463
1405
|
r: 0,
|
1464
1406
|
g: 0,
|
@@ -1497,30 +1439,30 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1497
1439
|
format: "hwb",
|
1498
1440
|
ok: !0
|
1499
1441
|
} : ([, e, s, r, n] = I.hex8.exec(t) || [], e && s && r && n ? {
|
1500
|
-
r:
|
1501
|
-
g:
|
1502
|
-
b:
|
1503
|
-
a:
|
1442
|
+
r: H(e),
|
1443
|
+
g: H(s),
|
1444
|
+
b: H(r),
|
1445
|
+
a: Mt(n),
|
1504
1446
|
format: "hex",
|
1505
1447
|
ok: !0
|
1506
1448
|
} : ([, e, s, r] = I.hex6.exec(t) || [], e && s && r ? {
|
1507
|
-
r:
|
1508
|
-
g:
|
1509
|
-
b:
|
1449
|
+
r: H(e),
|
1450
|
+
g: H(s),
|
1451
|
+
b: H(r),
|
1510
1452
|
a: 1,
|
1511
1453
|
format: "hex",
|
1512
1454
|
ok: !0
|
1513
1455
|
} : ([, e, s, r, n] = I.hex4.exec(t) || [], e && s && r && n ? {
|
1514
|
-
r:
|
1515
|
-
g:
|
1516
|
-
b:
|
1517
|
-
a:
|
1456
|
+
r: H(e + e),
|
1457
|
+
g: H(s + s),
|
1458
|
+
b: H(r + r),
|
1459
|
+
a: Mt(n + n),
|
1518
1460
|
format: "hex",
|
1519
1461
|
ok: !0
|
1520
1462
|
} : ([, e, s, r] = I.hex3.exec(t) || [], e && s && r ? {
|
1521
|
-
r:
|
1522
|
-
g:
|
1523
|
-
b:
|
1463
|
+
r: H(e + e),
|
1464
|
+
g: H(s + s),
|
1465
|
+
b: H(r + r),
|
1524
1466
|
a: 1,
|
1525
1467
|
format: "hex",
|
1526
1468
|
ok: !0
|
@@ -1532,56 +1474,56 @@ me(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Z(t) ? t : V()).q
|
|
1532
1474
|
format: "rgb",
|
1533
1475
|
ok: !o
|
1534
1476
|
})))))));
|
1535
|
-
},
|
1477
|
+
}, eo = (o, t, e) => ({
|
1536
1478
|
r: E(o, 255),
|
1537
1479
|
g: E(t, 255),
|
1538
1480
|
b: E(e, 255)
|
1539
|
-
}),
|
1481
|
+
}), te = (o) => {
|
1540
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;
|
1541
|
-
if ((!e || typeof e == "string") && (e =
|
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)) {
|
1542
1484
|
if (["format", "ok", "originalInput"].every((g) => g in e))
|
1543
1485
|
return { ...e };
|
1544
|
-
({ r: h, g: b, b: l } = e), t =
|
1486
|
+
({ r: h, g: b, b: l } = e), t = eo(h, b, l), u = "format" in e ? e.format : "rgb";
|
1545
1487
|
}
|
1546
|
-
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), {
|
1547
1489
|
...t,
|
1548
|
-
a:
|
1490
|
+
a: Tt(s),
|
1549
1491
|
format: u,
|
1550
1492
|
ok: d
|
1551
1493
|
};
|
1552
|
-
},
|
1494
|
+
}, oo = "1.0.14";
|
1553
1495
|
class y {
|
1554
1496
|
// bring main utilities to front
|
1555
1497
|
static matchers = I;
|
1556
|
-
static isOnePointZero =
|
1557
|
-
static isPercentage =
|
1558
|
-
static isValidCSSUnit =
|
1559
|
-
static isNonColor =
|
1560
|
-
static isColorName =
|
1498
|
+
static isOnePointZero = we;
|
1499
|
+
static isPercentage = Vt;
|
1500
|
+
static isValidCSSUnit = N;
|
1501
|
+
static isNonColor = ve;
|
1502
|
+
static isColorName = ke;
|
1561
1503
|
static isColorType = nt;
|
1562
|
-
static pad2 =
|
1504
|
+
static pad2 = q;
|
1563
1505
|
static clamp01 = ut;
|
1564
1506
|
static bound01 = E;
|
1565
|
-
static boundAlpha =
|
1566
|
-
static getRGBFromName =
|
1567
|
-
static convertHexToDecimal =
|
1568
|
-
static convertDecimalToHex =
|
1569
|
-
static rgbToHsl =
|
1570
|
-
static rgbToHex =
|
1571
|
-
static rgbToHsv =
|
1572
|
-
static rgbToHwb =
|
1573
|
-
static rgbaToHex =
|
1574
|
-
static hslToRgb =
|
1575
|
-
static hsvToRgb =
|
1507
|
+
static boundAlpha = Tt;
|
1508
|
+
static getRGBFromName = ye;
|
1509
|
+
static convertHexToDecimal = Mt;
|
1510
|
+
static convertDecimalToHex = xe;
|
1511
|
+
static rgbToHsl = Zt;
|
1512
|
+
static rgbToHex = St;
|
1513
|
+
static rgbToHsv = Yt;
|
1514
|
+
static rgbToHwb = Qt;
|
1515
|
+
static rgbaToHex = Ct;
|
1516
|
+
static hslToRgb = Rt;
|
1517
|
+
static hsvToRgb = Rt;
|
1576
1518
|
static hueToRgb = ft;
|
1577
|
-
static hwbToRgb =
|
1578
|
-
static parseIntFromHex =
|
1579
|
-
static stringInputToObject =
|
1580
|
-
static inputToRGB =
|
1519
|
+
static hwbToRgb = Se;
|
1520
|
+
static parseIntFromHex = H;
|
1521
|
+
static stringInputToObject = Ce;
|
1522
|
+
static inputToRGB = te;
|
1581
1523
|
static roundPart = m;
|
1582
|
-
static webColors =
|
1583
|
-
static nonColors =
|
1584
|
-
static version =
|
1524
|
+
static webColors = mt;
|
1525
|
+
static nonColors = Kt;
|
1526
|
+
static version = oo;
|
1585
1527
|
// main public properties
|
1586
1528
|
r;
|
1587
1529
|
g;
|
@@ -1592,7 +1534,7 @@ class y {
|
|
1592
1534
|
originalInput;
|
1593
1535
|
// main public methods
|
1594
1536
|
constructor(t, e) {
|
1595
|
-
const s = e &&
|
1537
|
+
const s = e && $e.includes(e) ? e : "", { r, g: n, b: i, a, ok: l, format: c } = te(t);
|
1596
1538
|
this.originalInput = t, this.r = r, this.g = n, this.b = i, this.a = a, this.ok = l, this.format = s || c;
|
1597
1539
|
}
|
1598
1540
|
/**
|
@@ -1628,7 +1570,7 @@ class y {
|
|
1628
1570
|
* Returns the web colour name closest to the current colour.
|
1629
1571
|
*/
|
1630
1572
|
get name() {
|
1631
|
-
const { r: t, g: e, b: s } = this.toRgb(), [r] =
|
1573
|
+
const { r: t, g: e, b: s } = this.toRgb(), [r] = mt.map(([n, i]) => {
|
1632
1574
|
const a = (
|
1633
1575
|
// ((rgb.r - r) ** 2 + (rgb.g - g) ** 2 + (rgb.b - b) ** 2) ** 0.5; // standard
|
1634
1576
|
(((i.r - t) * 0.3) ** 2 + ((i.g - e) * 0.6) ** 2 + ((i.b - s) * 0.1) ** 2) ** 0.5
|
@@ -1673,7 +1615,7 @@ class y {
|
|
1673
1615
|
*/
|
1674
1616
|
toHex(t) {
|
1675
1617
|
let { r: e, g: s, b: r, a: n } = this;
|
1676
|
-
return [e, s, r] = [e, s, r].map((i) => m(i * 255)), n = m(n * 100) / 100, n === 1 ?
|
1618
|
+
return [e, s, r] = [e, s, r].map((i) => m(i * 255)), n = m(n * 100) / 100, n === 1 ? St(e, s, r, t) : Ct(e, s, r, n, t);
|
1677
1619
|
}
|
1678
1620
|
/**
|
1679
1621
|
* Returns the CSS valid hexadecimal vaue of the colour. When the parameter is *true*
|
@@ -1687,7 +1629,7 @@ class y {
|
|
1687
1629
|
*/
|
1688
1630
|
toHex8(t) {
|
1689
1631
|
let { r: e, g: s, b: r, a: n } = this;
|
1690
|
-
return [e, s, r] = [e, s, r].map((i) => m(i * 255)), n = m(n * 100) / 100, n === 1 ?
|
1632
|
+
return [e, s, r] = [e, s, r].map((i) => m(i * 255)), n = m(n * 100) / 100, n === 1 ? St(e, s, r, t) : Ct(e, s, r, n, t);
|
1691
1633
|
}
|
1692
1634
|
/**
|
1693
1635
|
* Returns the HEX8 value of the colour.
|
@@ -1699,7 +1641,7 @@ class y {
|
|
1699
1641
|
* Returns the colour as a HSVA object.
|
1700
1642
|
*/
|
1701
1643
|
toHsv() {
|
1702
|
-
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, v: a } =
|
1644
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, v: a } = Yt(t, e, s);
|
1703
1645
|
return {
|
1704
1646
|
h: n,
|
1705
1647
|
s: i,
|
@@ -1711,7 +1653,7 @@ class y {
|
|
1711
1653
|
* Returns the colour as an HSLA object.
|
1712
1654
|
*/
|
1713
1655
|
toHsl() {
|
1714
|
-
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, l: a } =
|
1656
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, l: a } = Zt(t, e, s);
|
1715
1657
|
return {
|
1716
1658
|
h: n,
|
1717
1659
|
s: i,
|
@@ -1743,7 +1685,7 @@ class y {
|
|
1743
1685
|
* Returns the colour as an HWBA object.
|
1744
1686
|
*/
|
1745
1687
|
toHwb() {
|
1746
|
-
const { r: t, g: e, b: s, a: r } = this, { h: n, w: i, b: a } =
|
1688
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, w: i, b: a } = Qt(t, e, s);
|
1747
1689
|
return {
|
1748
1690
|
h: n,
|
1749
1691
|
w: i,
|
@@ -1764,14 +1706,14 @@ class y {
|
|
1764
1706
|
* Sets the alpha value of the current colour.
|
1765
1707
|
*/
|
1766
1708
|
setAlpha(t) {
|
1767
|
-
return typeof t != "number" ? this : (this.a =
|
1709
|
+
return typeof t != "number" ? this : (this.a = Tt(t), this);
|
1768
1710
|
}
|
1769
1711
|
/**
|
1770
1712
|
* Saturate the colour with a given amount.
|
1771
1713
|
*/
|
1772
1714
|
saturate(t) {
|
1773
1715
|
if (typeof t != "number") return this;
|
1774
|
-
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } =
|
1716
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = at(e, ut(s + t / 100), r);
|
1775
1717
|
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1776
1718
|
}
|
1777
1719
|
/**
|
@@ -1792,7 +1734,7 @@ class y {
|
|
1792
1734
|
*/
|
1793
1735
|
lighten(t) {
|
1794
1736
|
if (typeof t != "number") return this;
|
1795
|
-
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } =
|
1737
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = at(e, s, ut(r + t / 100));
|
1796
1738
|
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1797
1739
|
}
|
1798
1740
|
/**
|
@@ -1807,7 +1749,11 @@ class y {
|
|
1807
1749
|
*/
|
1808
1750
|
spin(t) {
|
1809
1751
|
if (typeof t != "number") return this;
|
1810
|
-
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } =
|
1752
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = at(
|
1753
|
+
ut((e * 360 + t) % 360 / 360),
|
1754
|
+
s,
|
1755
|
+
r
|
1756
|
+
);
|
1811
1757
|
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1812
1758
|
}
|
1813
1759
|
/** Returns a clone of the current `Color` instance. */
|
@@ -1822,20 +1768,13 @@ class y {
|
|
1822
1768
|
return e === "hex" ? this.toHexString(t) : e === "hsl" ? this.toHslString() : e === "hwb" ? this.toHwbString() : this.toRgbString();
|
1823
1769
|
}
|
1824
1770
|
}
|
1825
|
-
class
|
1771
|
+
class Ot {
|
1826
1772
|
static Color = y;
|
1827
1773
|
hue;
|
1828
1774
|
hueSteps;
|
1829
1775
|
lightSteps;
|
1830
1776
|
saturation;
|
1831
1777
|
colors;
|
1832
|
-
/**
|
1833
|
-
* The `hue` parameter is optional, which would be set to 0.
|
1834
|
-
* * `args.hue` the starting Hue [0, 360]
|
1835
|
-
* * `args.hueSteps` Hue Steps Count [5, 24]
|
1836
|
-
* * `args.lightSteps` Lightness Steps Count [5, 12]
|
1837
|
-
* * `args.saturation` Saturation [0, 100]
|
1838
|
-
*/
|
1839
1778
|
constructor(...t) {
|
1840
1779
|
let e = 0, s = 12, r = 10, n = [0.5], i = 100;
|
1841
1780
|
if (t.length === 4)
|
@@ -1843,7 +1782,9 @@ class It {
|
|
1843
1782
|
else if (t.length === 3)
|
1844
1783
|
[e, s, r] = t;
|
1845
1784
|
else if (t.length === 2 && ([s, r] = t, [s, r].some((g) => g < 1)))
|
1846
|
-
throw TypeError(
|
1785
|
+
throw TypeError(
|
1786
|
+
"ColorPalette: the two minimum arguments must be numbers higher than 0."
|
1787
|
+
);
|
1847
1788
|
const a = [], l = 360 / s, c = y.roundPart((r - (r % 2 ? 1 : 0)) / 2), h = [0.25, 0.2, 0.15, 0.11, 0.09, 0.075], b = [
|
1848
1789
|
[1, 2, 3],
|
1849
1790
|
[4, 5],
|
@@ -1859,14 +1800,16 @@ class It {
|
|
1859
1800
|
for (let g = 0; g < s; g += 1) {
|
1860
1801
|
const p = (e + g * l) % 360;
|
1861
1802
|
n.forEach((f) => {
|
1862
|
-
const
|
1863
|
-
a.push(
|
1803
|
+
const w = new y({ h: p, s: 100, l: f * 100 });
|
1804
|
+
a.push(
|
1805
|
+
i < 100 ? w.saturate(i - 100) : w
|
1806
|
+
);
|
1864
1807
|
});
|
1865
1808
|
}
|
1866
1809
|
this.hue = e, this.hueSteps = s, this.lightSteps = r, this.saturation = i, this.colors = a;
|
1867
1810
|
}
|
1868
1811
|
}
|
1869
|
-
const
|
1812
|
+
const Dt = {
|
1870
1813
|
pickerLabel: "Colour Picker",
|
1871
1814
|
appearanceLabel: "Colour Appearance",
|
1872
1815
|
valueLabel: "Colour Value",
|
@@ -1902,22 +1845,22 @@ const Kt = {
|
|
1902
1845
|
"violet",
|
1903
1846
|
"magenta",
|
1904
1847
|
"pink"
|
1905
|
-
],
|
1906
|
-
if (!
|
1848
|
+
], ee = (o) => {
|
1849
|
+
if (!W(o)) return !1;
|
1907
1850
|
try {
|
1908
1851
|
JSON.parse(o);
|
1909
1852
|
} catch {
|
1910
1853
|
return !1;
|
1911
1854
|
}
|
1912
1855
|
return !0;
|
1913
|
-
},
|
1856
|
+
}, Ft = "v-hidden", so = (o) => {
|
1914
1857
|
const { format: t, id: e, componentLabels: s } = o, r = x({
|
1915
1858
|
tagName: "div",
|
1916
1859
|
className: `color-form ${t}`
|
1917
1860
|
});
|
1918
1861
|
let n = ["hex"];
|
1919
1862
|
return t === "rgb" ? n = ["red", "green", "blue", "alpha"] : t === "hsl" ? n = ["hue", "saturation", "lightness", "alpha"] : t === "hwb" && (n = ["hue", "whiteness", "blackness", "alpha"]), n.forEach((i) => {
|
1920
|
-
const [a] = t === "hex" ? ["#"] :
|
1863
|
+
const [a] = t === "hex" ? ["#"] : he(i).split(""), l = `color_${t}_${i}_${e}`, c = s[`${i}Label`], h = x({ tagName: "label" });
|
1921
1864
|
v(h, "for", l), h.append(
|
1922
1865
|
x({
|
1923
1866
|
tagName: "span",
|
@@ -1926,14 +1869,13 @@ const Kt = {
|
|
1926
1869
|
}),
|
1927
1870
|
x({
|
1928
1871
|
tagName: "span",
|
1929
|
-
className:
|
1872
|
+
className: Ft,
|
1930
1873
|
innerText: c
|
1931
1874
|
})
|
1932
1875
|
);
|
1933
1876
|
const b = x({
|
1934
1877
|
tagName: "input",
|
1935
1878
|
id: l,
|
1936
|
-
// name: cID, - prevent saving the value to a form
|
1937
1879
|
type: t === "hex" ? "text" : "number",
|
1938
1880
|
value: i === "alpha" ? "100" : "0",
|
1939
1881
|
className: `color-input ${i}`,
|
@@ -1947,8 +1889,15 @@ const Kt = {
|
|
1947
1889
|
step: d
|
1948
1890
|
}), r.append(h, b);
|
1949
1891
|
}), r;
|
1950
|
-
},
|
1951
|
-
const { format: t, componentLabels: e } = o, {
|
1892
|
+
}, ro = (o) => {
|
1893
|
+
const { format: t, componentLabels: e } = o, {
|
1894
|
+
hueLabel: s,
|
1895
|
+
alphaLabel: r,
|
1896
|
+
lightnessLabel: n,
|
1897
|
+
saturationLabel: i,
|
1898
|
+
whitenessLabel: a,
|
1899
|
+
blacknessLabel: l
|
1900
|
+
} = e, c = t === "hsl" ? 360 : 100, h = t === "hsl" ? 100 : 360, b = 100;
|
1952
1901
|
let u = t === "hsl" ? `${s} & ${n}` : `${n} & ${i}`;
|
1953
1902
|
u = t === "hwb" ? `${a} & ${l}` : u;
|
1954
1903
|
const d = t === "hsl" ? `${i}` : `${s}`, g = x({
|
@@ -1977,8 +1926,8 @@ const Kt = {
|
|
1977
1926
|
min: 0,
|
1978
1927
|
max: b
|
1979
1928
|
}
|
1980
|
-
].forEach((
|
1981
|
-
const { i:
|
1929
|
+
].forEach(($) => {
|
1930
|
+
const { i: S, c: L, l: C, min: P, max: M } = $, T = x({
|
1982
1931
|
tagName: "div",
|
1983
1932
|
className: "color-control",
|
1984
1933
|
role: "presentation"
|
@@ -1986,60 +1935,68 @@ const Kt = {
|
|
1986
1935
|
T.append(
|
1987
1936
|
x({
|
1988
1937
|
tagName: "div",
|
1989
|
-
className: `visual-control visual-control${
|
1938
|
+
className: `visual-control visual-control${S}`
|
1990
1939
|
})
|
1991
1940
|
);
|
1992
1941
|
const A = x({
|
1993
1942
|
tagName: "div",
|
1994
1943
|
className: `${L} knob`,
|
1995
1944
|
ariaLive: "polite",
|
1996
|
-
ariaLabel:
|
1945
|
+
ariaLabel: C,
|
1997
1946
|
role: "slider",
|
1998
1947
|
tabIndex: 0,
|
1999
|
-
ariaValueMin: `${
|
1948
|
+
ariaValueMin: `${P}`,
|
2000
1949
|
ariaValueMax: `${M}`
|
2001
1950
|
});
|
2002
1951
|
T.append(A), g.append(T);
|
2003
1952
|
}), g;
|
2004
|
-
},
|
2005
|
-
const { input: s, format: r, componentLabels: n } = o, { defaultsLabel: i, presetsLabel: a } = n, l = e === "color-options", c = t instanceof
|
1953
|
+
}, oe = (o, t, e) => {
|
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;
|
2006
1955
|
let f = 2;
|
2007
1956
|
f = p && u > g * 2 ? 3 : f, f = p && u > g * 3 ? 4 : f, f = p && u > g * 4 ? 5 : f;
|
2008
|
-
const
|
2009
|
-
let
|
2010
|
-
|
1957
|
+
const w = f - (u <= g * 3 ? 1 : 2), $ = p && u > w * g;
|
1958
|
+
let S = e;
|
1959
|
+
S += $ ? " scrollable" : "", S += p ? " multiline" : "";
|
2011
1960
|
const L = p ? "1px" : "0.25rem";
|
2012
|
-
let
|
2013
|
-
|
2014
|
-
const
|
1961
|
+
let C = p ? 1.75 : 2;
|
1962
|
+
C = g > 5 && p ? 1.5 : C;
|
1963
|
+
const P = `${w * C}rem`, M = `calc(${f} * ${C}rem + ${f - 1} * ${L})`, T = x({
|
2015
1964
|
tagName: "ul",
|
2016
|
-
className:
|
1965
|
+
className: S,
|
2017
1966
|
role: "listbox",
|
2018
1967
|
ariaLabel: h
|
2019
1968
|
});
|
2020
|
-
return
|
2021
|
-
"--grid-item-size": `${
|
1969
|
+
return $ && D(T, {
|
1970
|
+
"--grid-item-size": `${C}rem`,
|
2022
1971
|
"--grid-fit": `${g}`,
|
2023
1972
|
"--grid-gap": L,
|
2024
|
-
"--grid-height":
|
1973
|
+
"--grid-height": P,
|
2025
1974
|
"--grid-hover-height": M
|
2026
1975
|
}), b.forEach((A) => {
|
2027
|
-
let [F,
|
2028
|
-
A instanceof y && (F = A.toHexString(),
|
2029
|
-
const
|
1976
|
+
let [F, Y] = typeof A == "string" ? A.trim().split(":") : [];
|
1977
|
+
A instanceof y && (F = A.toHexString(), Y = F);
|
1978
|
+
const Bt = new y(A instanceof y ? A : F, r).toString() === vt(s, "value"), wt = x({
|
2030
1979
|
tagName: "li",
|
2031
|
-
className: `color-option${
|
2032
|
-
innerText: `${
|
1980
|
+
className: `color-option${Bt ? " active" : ""}`,
|
1981
|
+
innerText: `${Y || F}`,
|
2033
1982
|
tabIndex: 0,
|
2034
1983
|
role: "option",
|
2035
|
-
ariaSelected:
|
1984
|
+
ariaSelected: Bt ? "true" : "false"
|
2036
1985
|
});
|
2037
|
-
v(
|
1986
|
+
v(wt, "data-value", `${F}`), l && D(wt, { backgroundColor: F }), T.append(wt);
|
2038
1987
|
}), T;
|
2039
|
-
},
|
2040
|
-
const {
|
1988
|
+
}, no = (o) => {
|
1989
|
+
const {
|
1990
|
+
input: t,
|
1991
|
+
parent: e,
|
1992
|
+
format: s,
|
1993
|
+
id: r,
|
1994
|
+
componentLabels: n,
|
1995
|
+
colorKeywords: i,
|
1996
|
+
colorPresets: a
|
1997
|
+
} = o, l = vt(t, "value") || "#fff", { nonColors: c } = y, { toggleLabel: h, pickerLabel: b, formatLabel: u, hexLabel: d } = n, g = c.includes(l) ? "#fff" : l;
|
2041
1998
|
o.color = new y(g, s);
|
2042
|
-
const p = s === "hex" ? d :
|
1999
|
+
const p = s === "hex" ? d : he(s), f = x({
|
2043
2000
|
id: `picker-btn-${r}`,
|
2044
2001
|
tagName: "button",
|
2045
2002
|
type: "button",
|
@@ -2050,81 +2007,89 @@ const Kt = {
|
|
2050
2007
|
f.append(
|
2051
2008
|
x({
|
2052
2009
|
tagName: "span",
|
2053
|
-
className:
|
2010
|
+
className: Ft,
|
2054
2011
|
innerText: `${b}. ${u}: ${p}`
|
2055
2012
|
})
|
2056
2013
|
);
|
2057
|
-
const
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2014
|
+
const w = x(
|
2015
|
+
{
|
2016
|
+
tagName: "div",
|
2017
|
+
className: "color-dropdown picker",
|
2018
|
+
role: "group",
|
2019
|
+
ariaLabelledBy: `picker-btn-${r}`
|
2020
|
+
}
|
2021
|
+
), $ = ro(o), S = so(o);
|
2022
|
+
if (w.append($, S), t.before(f), e.append(w), i || a) {
|
2064
2023
|
const L = x({
|
2065
2024
|
tagName: "div",
|
2066
2025
|
className: "color-dropdown scrollable menu"
|
2067
2026
|
});
|
2068
|
-
a && L.append(
|
2069
|
-
|
2027
|
+
a && L.append(oe(o, a, "color-options")), i && i.length && L.append(
|
2028
|
+
oe(o, i, "color-defaults")
|
2029
|
+
);
|
2030
|
+
const C = x({
|
2070
2031
|
tagName: "button",
|
2071
2032
|
type: "button",
|
2072
2033
|
className: "menu-toggle btn-appearance",
|
2073
2034
|
tabIndex: -1,
|
2074
2035
|
ariaExpanded: "false",
|
2075
2036
|
ariaHasPopup: "true"
|
2076
|
-
}),
|
2037
|
+
}), P = encodeURI("http://www.w3.org/2000/svg"), M = Nt(P, {
|
2077
2038
|
tagName: "svg"
|
2078
2039
|
});
|
2079
|
-
v(M, "xmlns",
|
2080
|
-
const T =
|
2040
|
+
v(M, "xmlns", P), v(M, "viewBox", "0 0 512 512"), v(M, Ae, "true");
|
2041
|
+
const T = Nt(P, {
|
2081
2042
|
tagName: "path"
|
2082
2043
|
});
|
2083
|
-
v(
|
2044
|
+
v(
|
2045
|
+
T,
|
2046
|
+
"d",
|
2047
|
+
"M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"
|
2048
|
+
), v(T, "fill", "#fff"), M.append(T), C.append(
|
2084
2049
|
x({
|
2085
2050
|
tagName: "span",
|
2086
|
-
className:
|
2051
|
+
className: Ft,
|
2087
2052
|
innerText: `${h}`
|
2088
2053
|
}),
|
2089
2054
|
M
|
2090
|
-
), e.append(
|
2055
|
+
), e.append(C, L);
|
2091
2056
|
}
|
2092
|
-
i && c.includes(l) && (o.value = l), v(t,
|
2093
|
-
},
|
2094
|
-
componentLabels:
|
2057
|
+
i && c.includes(l) && (o.value = l), v(t, Z, "-1");
|
2058
|
+
}, io = "2.0.4", Q = "color-picker", ao = `[data-function="${Q}"]`, se = `.${Q}`, lo = {
|
2059
|
+
componentLabels: Dt,
|
2095
2060
|
colorLabels: it,
|
2096
2061
|
format: "rgb",
|
2097
2062
|
colorPresets: !1,
|
2098
2063
|
colorKeywords: !1
|
2099
|
-
}, { roundPart: k, nonColors: bt } = y,
|
2100
|
-
const e = t ?
|
2101
|
-
e(s,
|
2102
|
-
},
|
2103
|
-
const e = t ?
|
2104
|
-
e(o.controls,
|
2105
|
-
|
2106
|
-
|
2107
|
-
},
|
2064
|
+
}, { roundPart: k, nonColors: bt } = y, co = (o) => je(o, Q), ho = (o) => new go(o), re = (o, t) => {
|
2065
|
+
const e = t ? ae : le, { input: s, pickerToggle: r, menuToggle: n } = o;
|
2066
|
+
e(s, He, o.showPicker), e(r, At, o.togglePicker), n && e(n, At, o.toggleMenu);
|
2067
|
+
}, Pe = (o, t) => {
|
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);
|
2072
|
+
}, ne = (o) => {
|
2073
|
+
Ge(o.input, new CustomEvent("colorpicker.change"));
|
2074
|
+
}, Le = (o) => {
|
2108
2075
|
o && ["bottom", "top"].forEach((t) => O(o, t));
|
2109
|
-
},
|
2076
|
+
}, Pt = (o, t) => {
|
2110
2077
|
const { colorPicker: e, colorMenu: s, menuToggle: r, pickerToggle: n, parent: i } = o, a = t === e, l = a ? s : e, c = a ? r : n, h = a ? n : r;
|
2111
|
-
R(i, "open") ||
|
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");
|
2112
2079
|
};
|
2113
|
-
class
|
2114
|
-
// bring utils to staic
|
2080
|
+
class go {
|
2115
2081
|
static Color = y;
|
2116
|
-
static ColorPalette =
|
2117
|
-
static getInstance =
|
2118
|
-
static init =
|
2119
|
-
static selector =
|
2120
|
-
// utils important for render
|
2082
|
+
static ColorPalette = Ot;
|
2083
|
+
static getInstance = co;
|
2084
|
+
static init = ho;
|
2085
|
+
static selector = ao;
|
2121
2086
|
static roundPart = k;
|
2122
2087
|
static setElementStyle = D;
|
2123
2088
|
static setAttribute = v;
|
2124
2089
|
static getBoundingClientRect = gt;
|
2125
|
-
static version =
|
2090
|
+
static version = io;
|
2126
2091
|
static colorNames = it;
|
2127
|
-
static colorPickerLabels =
|
2092
|
+
static colorPickerLabels = Dt;
|
2128
2093
|
id;
|
2129
2094
|
input;
|
2130
2095
|
color;
|
@@ -2133,7 +2098,9 @@ class wo {
|
|
2133
2098
|
dragElement;
|
2134
2099
|
isOpen = !1;
|
2135
2100
|
controlPositions;
|
2136
|
-
colorLabels =
|
2101
|
+
colorLabels = Ut(
|
2102
|
+
it.map((t) => [t, t])
|
2103
|
+
);
|
2137
2104
|
colorKeywords;
|
2138
2105
|
colorPresets;
|
2139
2106
|
componentLabels;
|
@@ -2145,101 +2112,113 @@ class wo {
|
|
2145
2112
|
inputs;
|
2146
2113
|
controlKnobs;
|
2147
2114
|
visuals;
|
2148
|
-
/**
|
2149
|
-
* Returns a new `ColorPicker` instance. The target of this constructor
|
2150
|
-
* must be an `HTMLInputElement`.
|
2151
|
-
*
|
2152
|
-
* @param target the target `<input>` element
|
2153
|
-
* @param config instance options
|
2154
|
-
*/
|
2155
2115
|
constructor(t, e) {
|
2156
2116
|
const s = _(t);
|
2157
|
-
if (typeof t > "u")
|
2158
|
-
|
2117
|
+
if (typeof t > "u")
|
2118
|
+
throw new TypeError("ColorPicker target not specified.");
|
2119
|
+
if (!ge(s))
|
2120
|
+
throw new TypeError(`ColorPicker target "${t}" cannot be found.`);
|
2159
2121
|
this.input = s;
|
2160
|
-
const r =
|
2161
|
-
if (!r)
|
2162
|
-
|
2122
|
+
const r = be(s, se);
|
2123
|
+
if (!r)
|
2124
|
+
throw new TypeError("ColorPicker requires a specific markup to work.");
|
2125
|
+
this.parent = r, this.id = ue(s, Q), this.dragElement = void 0, this.isOpen = !1, this.controlPositions = {
|
2163
2126
|
c1x: 0,
|
2164
2127
|
c1y: 0,
|
2165
2128
|
c2y: 0,
|
2166
2129
|
c3y: 0
|
2167
2130
|
}, this.colorKeywords = !1, this.colorPresets = !1;
|
2168
|
-
const {
|
2131
|
+
const {
|
2132
|
+
format: n,
|
2133
|
+
componentLabels: i,
|
2134
|
+
colorLabels: a,
|
2135
|
+
colorKeywords: l,
|
2136
|
+
colorPresets: c
|
2137
|
+
} = _e(
|
2169
2138
|
s,
|
2170
|
-
|
2139
|
+
lo,
|
2171
2140
|
e || {}
|
2172
2141
|
);
|
2173
2142
|
let h = it;
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2143
|
+
xt(a) && a.length === 17 ? h = a : W(a) && a.split(",").length === 17 && (h = a.split(",")), K(
|
2144
|
+
this.colorLabels,
|
2145
|
+
Ut(
|
2146
|
+
h.map((p, f) => [it[f], p])
|
2147
|
+
)
|
2148
|
+
);
|
2149
|
+
const b = W(i) && ee(i) ? JSON.parse(i) : i;
|
2150
|
+
if (this.componentLabels = K(
|
2151
|
+
{ ...Dt },
|
2152
|
+
b
|
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)
|
2177
2154
|
this.colorPresets = c;
|
2178
|
-
else if (c &&
|
2179
|
-
const { hue: p, hueSteps: f, lightSteps:
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2155
|
+
else if (c && ee(c)) {
|
2156
|
+
const { hue: p, hueSteps: f, lightSteps: w, saturation: $ } = JSON.parse(
|
2157
|
+
c
|
2158
|
+
);
|
2159
|
+
this.colorPresets = new Ot(
|
2160
|
+
p,
|
2161
|
+
f,
|
2162
|
+
w,
|
2163
|
+
$
|
2164
|
+
);
|
2165
|
+
} else W(c) && (this.colorPresets = c.split(",").map((p) => p.trim()));
|
2166
|
+
no(this);
|
2167
|
+
const [u, d] = st(
|
2168
|
+
"color-dropdown",
|
2169
|
+
r
|
2170
|
+
);
|
2171
|
+
this.pickerToggle = _(".picker-toggle", r), this.menuToggle = _(".menu-toggle", r), this.colorPicker = u, this.colorMenu = d, this.inputs = [
|
2172
|
+
...st("color-input", r)
|
2173
|
+
];
|
2174
|
+
const [g] = st(
|
2175
|
+
"color-controls",
|
2176
|
+
r
|
2177
|
+
);
|
2178
|
+
this.controls = g, this.controlKnobs = [
|
2179
|
+
...st("knob", g)
|
2180
|
+
], this.visuals = [
|
2181
|
+
...st("visual-control", g)
|
2182
|
+
], this.update(), re(this, !0), lt.set(s, Q, this);
|
2187
2183
|
}
|
2188
|
-
/** Returns the current colour value */
|
2189
2184
|
get value() {
|
2190
2185
|
return this.input.value;
|
2191
2186
|
}
|
2192
|
-
/**
|
2193
|
-
* Sets a new colour value.
|
2194
|
-
*
|
2195
|
-
* @param {string} v new colour value
|
2196
|
-
*/
|
2197
2187
|
set value(t) {
|
2198
2188
|
this.input.value = t;
|
2199
2189
|
}
|
2200
|
-
/** Check if the colour presets include any non-colour. */
|
2201
2190
|
get hasNonColor() {
|
2202
2191
|
return this.colorKeywords instanceof Array && this.colorKeywords.some((t) => bt.includes(t));
|
2203
2192
|
}
|
2204
|
-
/** Returns hexadecimal value of the current colour. */
|
2205
2193
|
get hex() {
|
2206
2194
|
return this.color.toHex(!0);
|
2207
2195
|
}
|
2208
|
-
/** Returns the current colour value in {h,s,v,a} object format. */
|
2209
2196
|
get hsv() {
|
2210
2197
|
return this.color.toHsv();
|
2211
2198
|
}
|
2212
|
-
/** Returns the current colour value in {h,s,l,a} object format. */
|
2213
2199
|
get hsl() {
|
2214
2200
|
return this.color.toHsl();
|
2215
2201
|
}
|
2216
|
-
/** Returns the current colour value in {h,w,b,a} object format. */
|
2217
2202
|
get hwb() {
|
2218
2203
|
return this.color.toHwb();
|
2219
2204
|
}
|
2220
|
-
/** Returns the current colour value in {r,g,b,a} object format. */
|
2221
2205
|
get rgb() {
|
2222
2206
|
return this.color.toRgb();
|
2223
2207
|
}
|
2224
|
-
/** Returns the current colour brightness. */
|
2225
2208
|
get brightness() {
|
2226
2209
|
return this.color.brightness;
|
2227
2210
|
}
|
2228
|
-
/** Returns the current colour luminance. */
|
2229
2211
|
get luminance() {
|
2230
2212
|
return this.color.luminance;
|
2231
2213
|
}
|
2232
|
-
/** Checks if the current colour requires a light text colour. */
|
2233
2214
|
get isDark() {
|
2234
2215
|
const { color: t, brightness: e } = this;
|
2235
2216
|
return e < 120 && t.a > 0.33;
|
2236
2217
|
}
|
2237
|
-
/** Checks if the current input value is a valid colour. */
|
2238
2218
|
get isValid() {
|
2239
2219
|
const t = this.input.value;
|
2240
2220
|
return t !== "" && new y(t).isValid;
|
2241
2221
|
}
|
2242
|
-
/** Returns the colour appearance, usually the closest colour name for the current value. */
|
2243
2222
|
get appearance() {
|
2244
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;
|
2245
2224
|
let h = "black";
|
@@ -2259,7 +2238,6 @@ class wo {
|
|
2259
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);
|
2260
2239
|
return h;
|
2261
2240
|
}
|
2262
|
-
/** Updates `ColorPicker` visuals. */
|
2263
2241
|
updateVisuals() {
|
2264
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({
|
2265
2243
|
h: a * 360,
|
@@ -2279,50 +2257,25 @@ class wo {
|
|
2279
2257
|
background: `linear-gradient(rgba(${l},${c},${h},1) 0%,rgba(${l},${c},${h},0) 100%)`
|
2280
2258
|
});
|
2281
2259
|
}
|
2282
|
-
/**
|
2283
|
-
* The `ColorPicker` *focusout* event listener when open.
|
2284
|
-
*
|
2285
|
-
* @param e
|
2286
|
-
* @this {ColorPicker}
|
2287
|
-
*/
|
2288
2260
|
handleFocusOut = ({ relatedTarget: t }) => {
|
2289
2261
|
t && !this.parent.contains(t) && this.hide(!0);
|
2290
2262
|
};
|
2291
|
-
/**
|
2292
|
-
* The `ColorPicker` *keyup* event listener when open.
|
2293
|
-
*
|
2294
|
-
* @param e
|
2295
|
-
* @this {ColorPicker}
|
2296
|
-
*/
|
2297
2263
|
handleDismiss = ({ code: t }) => {
|
2298
|
-
this.isOpen && t ===
|
2264
|
+
this.isOpen && t === Ke && this.hide();
|
2299
2265
|
};
|
2300
|
-
/**
|
2301
|
-
* The `ColorPicker` *scroll* event listener when open.
|
2302
|
-
*
|
2303
|
-
* @param e
|
2304
|
-
*/
|
2305
2266
|
handleScroll = (t) => {
|
2306
2267
|
const { activeElement: e } = V(this.input);
|
2307
|
-
this.updateDropdownPosition(), ([
|
2268
|
+
this.updateDropdownPosition(), ([ie, Fe].includes(t.type) && this.dragElement || e && this.controlKnobs.includes(e)) && (t.stopPropagation(), t.preventDefault());
|
2308
2269
|
};
|
2309
|
-
/**
|
2310
|
-
* The `ColorPicker` keyboard event listener for menu navigation.
|
2311
|
-
*
|
2312
|
-
* @param e
|
2313
|
-
*/
|
2314
2270
|
menuKeyHandler = (t) => {
|
2315
|
-
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(
|
2316
|
-
[
|
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);
|
2317
2273
|
};
|
2318
|
-
/**
|
2319
|
-
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
2320
|
-
*
|
2321
|
-
* @param e
|
2322
|
-
* @this {ColorPicker}
|
2323
|
-
*/
|
2324
2274
|
menuClickHandler = (t) => {
|
2325
|
-
const { target: e } = t, { colorMenu: s } = this, r = (
|
2275
|
+
const { target: e } = t, { colorMenu: s } = this, r = (vt(
|
2276
|
+
e,
|
2277
|
+
"data-value"
|
2278
|
+
) || "").trim();
|
2326
2279
|
if (!r.length) return;
|
2327
2280
|
const n = _("li.active", s);
|
2328
2281
|
let i = r;
|
@@ -2333,100 +2286,77 @@ class wo {
|
|
2333
2286
|
g: l,
|
2334
2287
|
b: c,
|
2335
2288
|
a: h
|
2336
|
-
}), this.update(), n !== e && (n && (O(n, "active"),
|
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));
|
2337
2290
|
};
|
2338
|
-
/**
|
2339
|
-
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
2340
|
-
*
|
2341
|
-
* @param e
|
2342
|
-
*/
|
2343
2291
|
pointerDown = (t) => {
|
2344
2292
|
if (t.button !== 0) return;
|
2345
|
-
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 =
|
2346
|
-
if (e === l || e === b ? (this.dragElement = g, this.changeControl1(
|
2347
|
-
const
|
2348
|
-
|
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) {
|
2295
|
+
const S = _("li.active", n);
|
2296
|
+
S && (O(S, "active"), kt(S, $t));
|
2349
2297
|
}
|
2350
2298
|
t.preventDefault();
|
2351
2299
|
};
|
2352
|
-
/**
|
2353
|
-
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
2354
|
-
*
|
2355
|
-
* @param e
|
2356
|
-
* @this
|
2357
|
-
*/
|
2358
2300
|
pointerUp = ({ target: t }) => {
|
2359
|
-
const { parent: e } = this, s = V(e), r = _(`${
|
2301
|
+
const { parent: e } = this, s = V(e), r = _(`${se}.open`, s) !== null, n = s.getSelection();
|
2360
2302
|
!this.dragElement && (!n || !n.toString().length) && !e.contains(t) && this.hide(r), this.dragElement = void 0;
|
2361
2303
|
};
|
2362
|
-
/**
|
2363
|
-
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
2364
|
-
*
|
2365
|
-
* @param {PointerEvent} e
|
2366
|
-
*/
|
2367
2304
|
pointerMove = (t) => {
|
2368
2305
|
const { dragElement: e, visuals: s } = this, [r, n, i] = s, { pageX: a, pageY: l } = t;
|
2369
2306
|
if (!e) return;
|
2370
|
-
const c = gt(e), h =
|
2307
|
+
const c = gt(e), h = yt(r), b = a - h.scrollLeft - c.left, u = l - h.scrollTop - c.top;
|
2371
2308
|
e === r && this.changeControl1(b, u), e === n && this.changeControl2(u), e === i && this.changeAlpha(u);
|
2372
2309
|
};
|
2373
|
-
/**
|
2374
|
-
* The `ColorPicker` *keydown* event listener for control knobs.
|
2375
|
-
*
|
2376
|
-
* @param e
|
2377
|
-
*/
|
2378
2310
|
handleKnobs = (t) => {
|
2379
2311
|
const { target: e, code: s } = t;
|
2380
|
-
if (![ot,
|
2312
|
+
if (![ot, B, ht, G].includes(s)) return;
|
2381
2313
|
t.preventDefault();
|
2382
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;
|
2383
2315
|
if (u) {
|
2384
2316
|
let g = 0, p = 0;
|
2385
2317
|
if (e === l) {
|
2386
2318
|
const f = i / 100;
|
2387
|
-
[ht,
|
2388
|
-
} else e === c ? (this.controlPositions.c2y += [
|
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));
|
2389
2321
|
this.handleScroll(t);
|
2390
2322
|
}
|
2391
2323
|
};
|
2392
|
-
/** The event listener of the colour form inputs. */
|
2393
2324
|
changeHandler = () => {
|
2394
2325
|
let t;
|
2395
|
-
const {
|
2326
|
+
const {
|
2327
|
+
inputs: e,
|
2328
|
+
format: s,
|
2329
|
+
value: r,
|
2330
|
+
input: n,
|
2331
|
+
controlPositions: i,
|
2332
|
+
visuals: a
|
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;
|
2396
2334
|
if (l === n || l && e.includes(l)) {
|
2397
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 = {
|
2398
2336
|
h: u,
|
2399
2337
|
s: d,
|
2400
2338
|
l: g,
|
2401
|
-
a:
|
2339
|
+
a: w
|
2402
2340
|
} : s === "hwb" ? t = {
|
2403
2341
|
h: u,
|
2404
2342
|
w: d,
|
2405
2343
|
b: g,
|
2406
|
-
a:
|
2344
|
+
a: w
|
2407
2345
|
} : t = {
|
2408
2346
|
r: u,
|
2409
2347
|
g: d,
|
2410
2348
|
b: g,
|
2411
|
-
a:
|
2349
|
+
a: w
|
2412
2350
|
};
|
2413
|
-
const { r:
|
2351
|
+
const { r: $, g: S, b: L, a: C } = new y(t);
|
2414
2352
|
K(this.color, {
|
2415
|
-
r:
|
2416
|
-
g:
|
2353
|
+
r: $,
|
2354
|
+
g: S,
|
2417
2355
|
b: L,
|
2418
|
-
a:
|
2356
|
+
a: C
|
2419
2357
|
}), this.setControlPositions(), this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals(), l === n && f && (this.value = r);
|
2420
2358
|
}
|
2421
2359
|
};
|
2422
|
-
/**
|
2423
|
-
* Updates `ColorPicker` first control:
|
2424
|
-
* * `lightness` and `saturation` for HEX/RGB;
|
2425
|
-
* * `lightness` and `hue` for HSL.
|
2426
|
-
*
|
2427
|
-
* @param X the X component of the offset
|
2428
|
-
* @param Y the Y component of the offset
|
2429
|
-
*/
|
2430
2360
|
changeControl1(t, e) {
|
2431
2361
|
let [s, r] = [0, 0];
|
2432
2362
|
const { controlPositions: n, visuals: i } = this, { offsetHeight: a, offsetWidth: l } = i[0];
|
@@ -2444,13 +2374,6 @@ class wo {
|
|
2444
2374
|
a: f
|
2445
2375
|
}), this.controlPositions.c1x = s, this.controlPositions.c1y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2446
2376
|
}
|
2447
|
-
/**
|
2448
|
-
* Updates `ColorPicker` second control:
|
2449
|
-
* * `hue` for HEX/RGB/HWB;
|
2450
|
-
* * `saturation` for HSL.
|
2451
|
-
*
|
2452
|
-
* @param Y the Y offset
|
2453
|
-
*/
|
2454
2377
|
changeControl2(t) {
|
2455
2378
|
const { controlPositions: e, visuals: s } = this, { offsetHeight: r, offsetWidth: n } = s[0];
|
2456
2379
|
let i = 0;
|
@@ -2468,12 +2391,6 @@ class wo {
|
|
2468
2391
|
a: g
|
2469
2392
|
}), this.controlPositions.c2y = i, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2470
2393
|
}
|
2471
|
-
/**
|
2472
|
-
* Updates `ColorPicker` last control,
|
2473
|
-
* the `alpha` channel.
|
2474
|
-
*
|
2475
|
-
* @param Y
|
2476
|
-
*/
|
2477
2394
|
changeAlpha(t) {
|
2478
2395
|
const { visuals: e } = this, { offsetHeight: s } = e[0];
|
2479
2396
|
let r = 0;
|
@@ -2481,43 +2398,42 @@ class wo {
|
|
2481
2398
|
const n = 1 - r / s;
|
2482
2399
|
this.color.setAlpha(n), this.controlPositions.c3y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2483
2400
|
}
|
2484
|
-
/**
|
2485
|
-
* Updates `ColorPicker` control positions on:
|
2486
|
-
* * initialization
|
2487
|
-
* * window resize
|
2488
|
-
*/
|
2489
2401
|
update = () => {
|
2490
2402
|
this.updateDropdownPosition(), this.updateAppearance(), this.setControlPositions(), this.updateInputs(!0), this.updateControls(), this.updateVisuals();
|
2491
2403
|
};
|
2492
|
-
/** Updates the open dropdown position on *scroll* event. */
|
2493
2404
|
updateDropdownPosition() {
|
2494
|
-
const { input: t, colorPicker: e, colorMenu: s } = this, r = gt(t), { top: n, bottom: i } = r, { offsetHeight: a } = t, l =
|
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;
|
2495
2406
|
if (!h) return;
|
2496
2407
|
const { offsetHeight: b } = h, u = l - i, d = n, g = n + b + a > l, p = n - b < 0;
|
2497
|
-
(R(h, "bottom") || !p) && u < d && g ? (O(h, "bottom"),
|
2408
|
+
(R(h, "bottom") || !p) && u < d && g ? (O(h, "bottom"), j(h, "top")) : (O(h, "top"), j(h, "bottom"));
|
2498
2409
|
}
|
2499
|
-
/** Updates control knobs' positions. */
|
2500
2410
|
setControlPositions() {
|
2501
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;
|
2502
2412
|
this.controlPositions.c1x = l * n, this.controlPositions.c1y = (1 - c) * r, this.controlPositions.c2y = a * r, this.controlPositions.c3y = (1 - i) * r;
|
2503
2413
|
}
|
2504
|
-
/** Update the visual appearance label and control knob labels. */
|
2505
2414
|
updateAppearance() {
|
2506
2415
|
const { componentLabels: t, color: e, parent: s, hsv: r, hex: n, format: i, controlKnobs: a } = this, { appearanceLabel: l, hexLabel: c, valueLabel: h } = t;
|
2507
2416
|
let { r: b, g: u, b: d } = e.toRgb();
|
2508
|
-
const [g, p, f] = a,
|
2509
|
-
let
|
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;
|
2418
|
+
let P = `${c} ${n.split("").join(" ")}`;
|
2510
2419
|
if (i === "hwb") {
|
2511
|
-
const { hwb: A } = this, F = k(A.w * 100),
|
2512
|
-
|
2420
|
+
const { hwb: A } = this, F = k(A.w * 100), Y = k(A.b * 100);
|
2421
|
+
P = `HWB: ${w}°, ${F}%, ${Y}%`, v(g, et, `${F}% & ${Y}%`), v(g, tt, `${F}`), v(
|
2422
|
+
p,
|
2423
|
+
jt,
|
2424
|
+
`${h}: ${P}. ${l}: ${C}.`
|
2425
|
+
), v(p, et, `${w}%`), v(p, tt, `${w}`);
|
2513
2426
|
} else
|
2514
|
-
[b, u, d] = [b, u, d].map(k),
|
2515
|
-
|
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(
|
2428
|
+
p,
|
2429
|
+
jt,
|
2430
|
+
`${h}: ${P}. ${l}: ${C}.`
|
2431
|
+
), v(p, et, `${w}°`), v(p, tt, `${w}`);
|
2432
|
+
const M = k($ * 100);
|
2516
2433
|
v(f, et, `${M}%`), v(f, tt, `${M}`);
|
2517
2434
|
const T = e.toString();
|
2518
|
-
D(this.input, { backgroundColor: T }), this.isDark ? (R(s, "txt-light") && O(s, "txt-light"), R(s, "txt-dark") ||
|
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"));
|
2519
2436
|
}
|
2520
|
-
/** Updates the control knobs actual positions. */
|
2521
2437
|
updateControls() {
|
2522
2438
|
const { controlKnobs: t, controlPositions: e } = this;
|
2523
2439
|
let { c1x: s, c1y: r, c2y: n, c3y: i } = e;
|
@@ -2526,11 +2442,6 @@ class wo {
|
|
2526
2442
|
transform: `translate3d(${s - 4}px,${r - 4}px,0)`
|
2527
2443
|
}), D(l, { transform: `translate3d(0,${n - 4}px,0)` }), D(c, { transform: `translate3d(0,${i - 4}px,0)` });
|
2528
2444
|
}
|
2529
|
-
/**
|
2530
|
-
* Updates all color form inputs.
|
2531
|
-
*
|
2532
|
-
* @param isPrevented when `true`, the component original event is prevented
|
2533
|
-
*/
|
2534
2445
|
updateInputs(t) {
|
2535
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);
|
2536
2447
|
let d = n.toString();
|
@@ -2540,62 +2451,50 @@ class wo {
|
|
2540
2451
|
const g = k(i.l * 100), p = k(i.s * 100);
|
2541
2452
|
d = this.color.toHslString(), a.value = `${u}`, l.value = `${p}`, c.value = `${g}`, h.value = `${b}`;
|
2542
2453
|
} else if (s === "hwb") {
|
2543
|
-
const { w: g, b: p } = this.hwb, f = k(g * 100),
|
2544
|
-
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}`;
|
2545
2456
|
} else if (s === "rgb") {
|
2546
2457
|
let { r: g, g: p, b: f } = this.rgb;
|
2547
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}`;
|
2548
2459
|
}
|
2549
|
-
this.value = d, !t && d !== e &&
|
2460
|
+
this.value = d, !t && d !== e && ne(this);
|
2550
2461
|
}
|
2551
|
-
/**
|
2552
|
-
* Toggle the `ColorPicker` dropdown visibility.
|
2553
|
-
*
|
2554
|
-
* @param e
|
2555
|
-
*/
|
2556
2462
|
togglePicker = (t) => {
|
2557
2463
|
t && t.preventDefault();
|
2558
2464
|
const { colorPicker: e } = this;
|
2559
|
-
this.isOpen && R(e, "show") ? this.hide(!0) :
|
2465
|
+
this.isOpen && R(e, "show") ? this.hide(!0) : Pt(this, e);
|
2560
2466
|
};
|
2561
|
-
/** Shows the `ColorPicker` dropdown. */
|
2562
2467
|
showPicker = () => {
|
2563
2468
|
const { colorPicker: t } = this;
|
2564
|
-
["top", "bottom"].some((e) => R(t, e)) ||
|
2469
|
+
["top", "bottom"].some((e) => R(t, e)) || Pt(this, t);
|
2565
2470
|
};
|
2566
|
-
/**
|
2567
|
-
* Toggles the visibility of the `ColorPicker` presets menu.
|
2568
|
-
*
|
2569
|
-
* @param e
|
2570
|
-
* @this {ColorPicker}
|
2571
|
-
*/
|
2572
2471
|
toggleMenu = (t) => {
|
2573
2472
|
t && t.preventDefault();
|
2574
2473
|
const { colorMenu: e } = this;
|
2575
|
-
this.isOpen && R(e, "show") ? this.hide(!0) :
|
2474
|
+
this.isOpen && R(e, "show") ? this.hide(!0) : Pt(this, e);
|
2576
2475
|
};
|
2577
|
-
/**
|
2578
|
-
* Hides the currently open `ColorPicker` dropdown.
|
2579
|
-
*
|
2580
|
-
* @param {boolean=} focusPrevented
|
2581
|
-
*/
|
2582
2476
|
hide(t) {
|
2583
|
-
if (this.isOpen)
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
|
2477
|
+
if (!this.isOpen) return;
|
2478
|
+
const {
|
2479
|
+
pickerToggle: e,
|
2480
|
+
menuToggle: s,
|
2481
|
+
colorPicker: r,
|
2482
|
+
colorMenu: n,
|
2483
|
+
parent: i,
|
2484
|
+
input: a
|
2485
|
+
} = this, l = R(r, "show"), c = l ? r : n, h = l ? e : s, b = c && Ue(c);
|
2486
|
+
this.value = this.color.toString(!0), c && (O(c, "show"), v(h, Lt, "false"), setTimeout(() => {
|
2487
|
+
Le(c), _(".show", i) || (O(i, "open"), Pe(this), this.isOpen = !1);
|
2488
|
+
}, b)), t || U(e), v(a, Z, "-1"), h === s && v(s, Z, "-1");
|
2589
2489
|
}
|
2590
|
-
/** Removes `ColorPicker` from target `<input>`. */
|
2591
2490
|
dispose() {
|
2592
2491
|
const { input: t, parent: e } = this;
|
2593
|
-
this.hide(!0),
|
2492
|
+
this.hide(!0), re(this), [...e.children].forEach((s) => {
|
2594
2493
|
s !== t && s.remove();
|
2595
|
-
}),
|
2494
|
+
}), kt(t, Z), D(t, { backgroundColor: "" }), ["txt-light", "txt-dark"].forEach((s) => O(e, s)), lt.remove(t, Q);
|
2596
2495
|
}
|
2597
2496
|
}
|
2598
2497
|
export {
|
2599
|
-
|
2498
|
+
go as default
|
2600
2499
|
};
|
2601
2500
|
//# sourceMappingURL=color-picker.mjs.map
|