@thednp/color-picker 2.0.0-alpha1 → 2.0.0-alpha10
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +1 -1
- package/.lgtm.yml +0 -0
- package/.prettierrc.json +0 -0
- package/.stylelintrc.json +0 -0
- package/LICENSE +0 -0
- package/README.md +8 -7
- package/compile.js +6 -3
- package/cypress/e2e/color-palette.cy.ts +0 -0
- package/cypress/e2e/color-picker.cy.ts +58 -69
- package/cypress/fixtures/colorNamesFrench.js +0 -0
- package/cypress/fixtures/componentLabelsFrench.js +0 -0
- package/cypress/fixtures/format.js +0 -0
- package/cypress/fixtures/getMarkup.js +8 -1
- package/cypress/fixtures/getRandomInt.js +0 -0
- package/cypress/fixtures/sampleWebcolors.js +0 -0
- package/cypress/fixtures/testSample.js +0 -0
- package/cypress/plugins/esbuild-istanbul.ts +0 -0
- package/cypress/plugins/tsCompile.ts +0 -0
- package/cypress/support/commands.ts +0 -0
- package/cypress/support/e2e.ts +0 -0
- package/cypress/test.html +0 -0
- package/cypress.config.ts +0 -0
- package/dist/css/color-picker.css +13 -18
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +13 -18
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker.cjs +3 -3
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +42 -24
- package/dist/js/color-picker.js +3 -3
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +408 -421
- package/dist/js/color-picker.mjs.map +1 -1
- package/dts.config.ts +0 -0
- package/package.json +116 -98
- package/src/scss/_variables.scss +0 -0
- package/src/scss/color-picker.rtl.scss +0 -0
- package/src/scss/color-picker.scss +20 -14
- package/src/ts/colorPalette.ts +0 -0
- package/src/ts/index.ts +40 -54
- package/src/ts/interface/ColorNames.ts +20 -0
- package/src/ts/interface/colorPickerLabels.ts +0 -0
- package/src/ts/interface/colorPickerOptions.ts +0 -0
- package/src/ts/interface/paletteOptions.ts +0 -0
- package/src/ts/util/colorNames.ts +0 -0
- package/src/ts/util/colorPickerLabels.ts +0 -0
- package/src/ts/util/getColorControls.ts +0 -0
- package/src/ts/util/getColorForm.ts +0 -0
- package/src/ts/util/getColorMenu.ts +0 -0
- package/src/ts/util/isValidJSON.ts +0 -0
- package/src/ts/util/setMarkup.ts +6 -4
- package/src/ts/util/vHidden.ts +0 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +0 -0
- package/cypress/downloads/downloads.htm +0 -0
- package/cypress/fixtures/getCEMarkup.js +0 -29
package/dist/js/color-picker.mjs
CHANGED
@@ -1,21 +1,5 @@
|
|
1
|
-
const
|
2
|
-
|
3
|
-
[...J[t]].forEach(([s, n]) => {
|
4
|
-
e === s && [...n].forEach(([r, i]) => {
|
5
|
-
r.apply(s, [o]), typeof i == "object" && i.once && Bt(s, t, r, i);
|
6
|
-
});
|
7
|
-
});
|
8
|
-
}, ge = (o, t, e, s) => {
|
9
|
-
J[t] || (J[t] = /* @__PURE__ */ new Map());
|
10
|
-
const n = J[t];
|
11
|
-
n.has(o) || n.set(o, /* @__PURE__ */ new Map());
|
12
|
-
const r = n.get(o), { size: i } = r;
|
13
|
-
r.set(e, s), i || o.addEventListener(t, he, s);
|
14
|
-
}, Bt = (o, t, e, s) => {
|
15
|
-
const n = J[t], r = n && n.get(o), i = r && r.get(e), a = i !== void 0 ? i : s;
|
16
|
-
r && r.has(e) && r.delete(e), n && (!r || !r.size) && n.delete(o), (!n || !n.size) && delete J[t], (!r || !r.size) && o.removeEventListener(t, he, a);
|
17
|
-
}, Gt = "aria-description", Nt = "aria-expanded", Me = "aria-hidden", Pt = "aria-selected", et = "aria-valuenow", ot = "aria-valuetext", Te = "change", Re = "DOMContentLoaded", De = "focusin", Oe = "focusout", Ut = "keydown", Fe = "keyup", Et = "click", Ie = "pointerdown", ue = "pointermove", Ke = "pointerup", Ve = "resize", Be = "scroll", je = "touchmove", j = "ArrowDown", st = "ArrowUp", ht = "ArrowLeft", G = "ArrowRight", qe = "Enter", ze = "Escape", _t = "Space", Ge = "transitionDuration", Ue = "transitionProperty", Y = "tabindex", _e = navigator.userAgentData, mt = _e, { userAgent: We } = navigator, vt = We, Wt = /iPhone|iPad|iPod|Android/i;
|
18
|
-
mt ? mt.brands.some((o) => Wt.test(o.brand)) : Wt.test(vt);
|
1
|
+
const _t = "aria-description", Nt = "aria-expanded", Ee = "aria-hidden", St = "aria-selected", tt = "aria-valuenow", et = "aria-valuetext", Me = "change", Te = "DOMContentLoaded", Re = "focusin", Oe = "focusout", zt = "keydown", De = "keyup", Et = "click", Fe = "pointerdown", ue = "pointermove", Ie = "pointerup", Ke = "resize", Ve = "scroll", Be = "touchmove", j = "ArrowDown", ot = "ArrowUp", ht = "ArrowLeft", U = "ArrowRight", je = "Enter", qe = "Escape", Wt = "Space", Ge = "transitionDuration", Ue = "transitionProperty", X = "tabindex", _e = navigator.userAgentData, mt = _e, { userAgent: ze } = navigator, vt = ze, Jt = /iPhone|iPad|iPod|Android/i;
|
2
|
+
mt ? mt.brands.some((o) => Jt.test(o.brand)) : Jt.test(vt);
|
19
3
|
const Xt = /(iPhone|iPod|iPad)/;
|
20
4
|
mt ? mt.brands.some((o) => Xt.test(o.brand)) : (
|
21
5
|
/* istanbul ignore next */
|
@@ -24,18 +8,18 @@ mt ? mt.brands.some((o) => Xt.test(o.brand)) : (
|
|
24
8
|
vt && vt.includes("Firefox");
|
25
9
|
const { head: kt } = document;
|
26
10
|
["webkitPerspective", "perspective"].some((o) => o in kt.style);
|
27
|
-
const
|
28
|
-
const
|
29
|
-
o.addEventListener(t, e,
|
30
|
-
},
|
31
|
-
const
|
32
|
-
o.removeEventListener(t, e,
|
33
|
-
},
|
34
|
-
const
|
35
|
-
(
|
11
|
+
const Bt = (o, t, e, s) => {
|
12
|
+
const r = s || !1;
|
13
|
+
o.addEventListener(t, e, r);
|
14
|
+
}, jt = (o, t, e, s) => {
|
15
|
+
const r = s || !1;
|
16
|
+
o.removeEventListener(t, e, r);
|
17
|
+
}, We = (o, t, e, s) => {
|
18
|
+
const r = (n) => {
|
19
|
+
(n.target === o || n.currentTarget === o) && (e.apply(o, [n]), jt(o, t, r, s));
|
36
20
|
};
|
37
|
-
|
38
|
-
},
|
21
|
+
Bt(o, t, r, s);
|
22
|
+
}, Je = () => {
|
39
23
|
};
|
40
24
|
(() => {
|
41
25
|
let o = !1;
|
@@ -43,7 +27,7 @@ const Xe = (o, t, e, s) => {
|
|
43
27
|
const t = Object.defineProperty({}, "passive", {
|
44
28
|
get: () => (o = !0, o)
|
45
29
|
});
|
46
|
-
|
30
|
+
We(document, Te, Je, t);
|
47
31
|
} catch {
|
48
32
|
}
|
49
33
|
return o;
|
@@ -51,11 +35,11 @@ const Xe = (o, t, e, s) => {
|
|
51
35
|
["webkitTransform", "transform"].some((o) => o in kt.style);
|
52
36
|
["webkitAnimation", "animation"].some((o) => o in kt.style);
|
53
37
|
["webkitTransition", "transition"].some((o) => o in kt.style);
|
54
|
-
const yt = (o, t) => o.getAttribute(t), m = (o, t, e) => o.setAttribute(t, e),
|
38
|
+
const yt = (o, t) => o.getAttribute(t), m = (o, t, e) => o.setAttribute(t, e), Pt = (o, t) => o.removeAttribute(t), q = (o, ...t) => {
|
55
39
|
o.classList.add(...t);
|
56
|
-
},
|
40
|
+
}, O = (o, ...t) => {
|
57
41
|
o.classList.remove(...t);
|
58
|
-
}, T = (o, t) => o.classList.contains(t),
|
42
|
+
}, T = (o, t) => o.classList.contains(t), qt = (o) => o != null && typeof o == "object" || !1, Y = (o) => qt(o) && typeof o.nodeType == "number" && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some((t) => o.nodeType === t) || !1, at = (o) => Y(o) && o.nodeType === 1 || !1, W = /* @__PURE__ */ new Map(), ct = {
|
59
43
|
data: W,
|
60
44
|
/**
|
61
45
|
* Sets web components data.
|
@@ -97,62 +81,62 @@ const yt = (o, t) => o.getAttribute(t), m = (o, t, e) => o.setAttribute(t, e), S
|
|
97
81
|
const e = ct.getAllFor(t);
|
98
82
|
!e || !at(o) || (e.delete(o), e.size === 0 && W.delete(t));
|
99
83
|
}
|
100
|
-
},
|
84
|
+
}, Xe = (o, t) => ct.get(o, t), B = (o) => typeof o == "string" || !1, Ze = (o) => qt(o) && o.constructor.name === "Window" || !1, be = (o) => Y(o) && o.nodeType === 9 || !1, V = (o) => Ze(o) ? o.document : be(o) ? o : Y(o) ? o.ownerDocument : window.document, K = (o, ...t) => Object.assign(o, ...t), x = (o) => {
|
101
85
|
if (!o)
|
102
86
|
return;
|
103
|
-
if (
|
104
|
-
return
|
87
|
+
if (B(o))
|
88
|
+
return V().createElement(o);
|
105
89
|
const { tagName: t } = o, e = x(t);
|
106
90
|
if (!e)
|
107
91
|
return;
|
108
92
|
const s = { ...o };
|
109
|
-
return delete s.tagName,
|
93
|
+
return delete s.tagName, K(e, s);
|
110
94
|
}, Mt = (o, t) => {
|
111
95
|
if (!o || !t)
|
112
96
|
return;
|
113
|
-
if (
|
114
|
-
return
|
97
|
+
if (B(t))
|
98
|
+
return V().createElementNS(o, t);
|
115
99
|
const { tagName: e } = t, s = Mt(o, e);
|
116
100
|
if (!s)
|
117
101
|
return;
|
118
|
-
const
|
119
|
-
return delete
|
120
|
-
},
|
102
|
+
const r = { ...t };
|
103
|
+
return delete r.tagName, K(s, r);
|
104
|
+
}, Ye = (o, t) => o.dispatchEvent(t), Tt = (o, t) => {
|
121
105
|
const e = getComputedStyle(o), s = t.replace("webkit", "Webkit").replace(/([A-Z])/g, "-$1").toLowerCase();
|
122
106
|
return e.getPropertyValue(s);
|
123
|
-
},
|
107
|
+
}, Qe = (o) => {
|
124
108
|
const t = Tt(o, Ue), e = Tt(o, Ge), s = e.includes("ms") ? (
|
125
109
|
/* istanbul ignore next */
|
126
110
|
1
|
127
|
-
) : 1e3,
|
111
|
+
) : 1e3, r = t && t !== "none" ? parseFloat(e) * s : (
|
128
112
|
/* istanbul ignore next */
|
129
113
|
0
|
130
114
|
);
|
131
|
-
return Number.isNaN(
|
115
|
+
return Number.isNaN(r) ? (
|
132
116
|
/* istanbul ignore next */
|
133
117
|
0
|
134
|
-
) :
|
135
|
-
},
|
136
|
-
const
|
137
|
-
return pt(
|
138
|
-
const b = s && typeof c == "string" && c.includes(s) ? c.replace(s, "").replace(/[A-Z]/g, (u) =>
|
139
|
-
a[b] =
|
140
|
-
}), pt(
|
141
|
-
|
118
|
+
) : r;
|
119
|
+
}, _ = (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), to = (o) => o.toLowerCase(), eo = (o, t, e, s) => {
|
120
|
+
const r = { ...e }, n = { ...o.dataset }, i = { ...t }, a = {}, l = "title";
|
121
|
+
return pt(n).forEach(([c, h]) => {
|
122
|
+
const b = s && typeof c == "string" && c.includes(s) ? c.replace(s, "").replace(/[A-Z]/g, (u) => to(u)) : c;
|
123
|
+
a[b] = Zt(h);
|
124
|
+
}), pt(r).forEach(([c, h]) => {
|
125
|
+
r[c] = Zt(h);
|
142
126
|
}), pt(t).forEach(([c, h]) => {
|
143
|
-
c in
|
127
|
+
c in r ? i[c] = r[c] : c in a ? i[c] = a[c] : i[c] = c === l ? yt(o, l) : h;
|
144
128
|
}), i;
|
145
|
-
},
|
129
|
+
}, Yt = (o) => Object.fromEntries(o), oo = (o) => o.offsetHeight, D = (o, t) => {
|
146
130
|
pt(t).forEach(([e, s]) => {
|
147
|
-
if (s &&
|
131
|
+
if (s && B(e) && e.includes("--"))
|
148
132
|
o.style.setProperty(e, s);
|
149
133
|
else {
|
150
|
-
const
|
151
|
-
|
134
|
+
const r = {};
|
135
|
+
r[e] = s, K(o.style, r);
|
152
136
|
}
|
153
137
|
});
|
154
|
-
},
|
155
|
-
const { width: e, height: s, top:
|
138
|
+
}, so = (o) => qt(o) && o.constructor.name === "Map" || !1, pe = (o) => o.toUpperCase(), gt = (o, t) => {
|
139
|
+
const { width: e, height: s, top: r, right: n, bottom: i, left: a } = o.getBoundingClientRect();
|
156
140
|
let l = 1, c = 1;
|
157
141
|
if (t && at(o)) {
|
158
142
|
const { offsetWidth: h, offsetHeight: b } = o;
|
@@ -167,32 +151,32 @@ const yt = (o, t) => o.getAttribute(t), m = (o, t, e) => o.setAttribute(t, e), S
|
|
167
151
|
return {
|
168
152
|
width: e / l,
|
169
153
|
height: s / c,
|
170
|
-
top:
|
171
|
-
right:
|
154
|
+
top: r / c,
|
155
|
+
right: n / l,
|
172
156
|
bottom: i / c,
|
173
157
|
left: a / l,
|
174
158
|
x: a / l,
|
175
|
-
y:
|
159
|
+
y: r / c
|
176
160
|
};
|
177
|
-
}, Ct = (o) =>
|
178
|
-
let
|
179
|
-
const
|
180
|
-
let e = t ?
|
161
|
+
}, Ct = (o) => V(o).documentElement;
|
162
|
+
let Qt = 0, te = 0;
|
163
|
+
const J = /* @__PURE__ */ new Map(), de = (o, t) => {
|
164
|
+
let e = t ? Qt : te;
|
181
165
|
if (t) {
|
182
|
-
const s = de(o),
|
183
|
-
|
166
|
+
const s = de(o), r = J.get(s) || /* @__PURE__ */ new Map();
|
167
|
+
J.has(s) || J.set(s, r), so(r) && !r.has(t) ? (r.set(t, e), Qt += 1) : e = r.get(t);
|
184
168
|
} else {
|
185
169
|
const s = o.id || o;
|
186
|
-
|
170
|
+
J.has(s) ? e = J.get(s) : (J.set(s, e), te += 1);
|
187
171
|
}
|
188
172
|
return e;
|
189
|
-
},
|
173
|
+
}, ro = (o) => {
|
190
174
|
var t;
|
191
|
-
return o ? be(o) ? o.defaultView :
|
175
|
+
return o ? be(o) ? o.defaultView : Y(o) ? (t = o?.ownerDocument) == null ? void 0 : t.defaultView : o : window;
|
192
176
|
}, Lt = (o) => Array.isArray(o) || !1, fe = (o, t) => o ? o.closest(t) || // break out of `ShadowRoot`
|
193
|
-
fe(o.getRootNode().host, t) : null,
|
177
|
+
fe(o.getRootNode().host, t) : null, z = (o, t) => at(o) ? o : (Y(t) ? t : V()).querySelector(o), st = (o, t) => (t && Y(t) ? t : V()).getElementsByClassName(
|
194
178
|
o
|
195
|
-
),
|
179
|
+
), Gt = ["transparent", "currentColor", "inherit", "revert", "initial"], v = (o) => {
|
196
180
|
const t = Math.floor(o);
|
197
181
|
return o - t < 0.5 ? t : Math.round(o);
|
198
182
|
}, wt = [
|
@@ -1380,7 +1364,7 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1380
1364
|
b: 50
|
1381
1365
|
}
|
1382
1366
|
]
|
1383
|
-
], me = "deg|rad|grad|turn", ve = "[-\\+]?\\d+%?", we = "[-\\+]?\\d*\\.\\d+%?", $e = `[-\\+]?\\d*\\.?\\d+(?:${me})?`, dt = `(?:${we})|(?:${ve})`, Rt = `(?:${dt})|(?:${$e}?)`,
|
1367
|
+
], me = "deg|rad|grad|turn", ve = "[-\\+]?\\d+%?", we = "[-\\+]?\\d*\\.\\d+%?", $e = `[-\\+]?\\d*\\.?\\d+(?:${me})?`, dt = `(?:${we})|(?:${ve})`, Rt = `(?:${dt})|(?:${$e}?)`, no = "(?:[\\s|\\(\\s|\\s\\(\\s]+)?", io = "(?:[\\s|\\)\\s]+)?", ee = "(?:[,|\\s]+)", ao = "(?:[,|\\/\\s]*)?", rt = `${no}(${Rt})${ee}(${dt})${ee}(${dt})${ao}(${dt})?${io}`, I = {
|
1384
1368
|
CSS_UNIT: new RegExp(Rt),
|
1385
1369
|
ANGLES: me,
|
1386
1370
|
CSS_ANGLE: $e,
|
@@ -1396,7 +1380,7 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1396
1380
|
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
1397
1381
|
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
1398
1382
|
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
1399
|
-
}, ke = (o) =>
|
1383
|
+
}, ke = (o) => Gt.includes(o), nt = (o, t) => o !== null && typeof o == "object" && Object.keys(t).every((e) => e in o), ye = (o) => `${o}`.includes(".") && parseFloat(o) === 1, $t = (o) => typeof o == "string" && o.includes("%"), H = (o) => !!I.CSS_UNIT.exec(`${o}`), xe = ["rgb", "hex", "hsl", "hsv", "hwb"], Se = (o) => Gt.includes(o) || ["#", ...xe].some((t) => o.includes(t)) ? !1 : wt.some(([t]) => o === t), R = (o, t) => {
|
1400
1384
|
let e = o;
|
1401
1385
|
if (typeof o == "number" && Math.min(o, 0) === 0 && // round values to 6 decimals Math.round(N * (10 ** 6)) / 10 ** 6
|
1402
1386
|
Math.max(o, 1) === 1)
|
@@ -1404,45 +1388,45 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1404
1388
|
ye(o) && (e = "100%");
|
1405
1389
|
const s = $t(e);
|
1406
1390
|
return e = t === 360 ? parseFloat(e) : Math.min(t, Math.max(0, parseFloat(e))), s && (e = e * t / 100), Math.abs(e - t) < 1e-6 ? 1 : (t === 360 ? e = (e < 0 ? e % t + t : e % t) / t : e = e % t / t, e);
|
1407
|
-
},
|
1391
|
+
}, Ot = (o) => {
|
1408
1392
|
let t = parseFloat(o);
|
1409
1393
|
return (Number.isNaN(t) || t < 0 || t > 1) && (t = 1), t;
|
1410
|
-
}, ut = (o) => Math.min(1, Math.max(0, o)),
|
1394
|
+
}, ut = (o) => Math.min(1, Math.max(0, o)), G = (o) => o.length === 1 ? `0${o}` : String(o), Pe = (o) => {
|
1411
1395
|
const [[, t]] = wt.filter(([e]) => e === o.toLowerCase());
|
1412
1396
|
return t;
|
1413
|
-
}, N = (o) => parseInt(o, 16),
|
1414
|
-
const s = Math.max(o, t, e),
|
1415
|
-
let
|
1416
|
-
const a = (s +
|
1417
|
-
if (s ===
|
1418
|
-
i = 0,
|
1397
|
+
}, N = (o) => parseInt(o, 16), Dt = (o) => N(o) / 255, Ce = (o) => v(o * 255).toString(16), oe = (o, t, e) => {
|
1398
|
+
const s = Math.max(o, t, e), r = Math.min(o, t, e);
|
1399
|
+
let n = 0, i = 0;
|
1400
|
+
const a = (s + r) / 2;
|
1401
|
+
if (s === r)
|
1402
|
+
i = 0, n = 0;
|
1419
1403
|
else {
|
1420
|
-
const l = s -
|
1421
|
-
i = a > 0.5 ? l / (2 - s -
|
1404
|
+
const l = s - r;
|
1405
|
+
i = a > 0.5 ? l / (2 - s - r) : l / (s + r), s === o && (n = (t - e) / l + (t < e ? 6 : 0)), s === t && (n = (e - o) / l + 2), s === e && (n = (o - t) / l + 4), n /= 6;
|
1422
1406
|
}
|
1423
|
-
return { h:
|
1407
|
+
return { h: n, s: i, l: a };
|
1424
1408
|
}, ft = (o, t, e) => {
|
1425
1409
|
let s = e;
|
1426
1410
|
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;
|
1427
1411
|
}, lt = (o, t, e) => {
|
1428
|
-
let s = 0,
|
1412
|
+
let s = 0, r = 0, n = 0;
|
1429
1413
|
if (t === 0)
|
1430
|
-
|
1414
|
+
r = e, n = e, s = e;
|
1431
1415
|
else if (e) {
|
1432
1416
|
const i = e < 0.5 ? e * (1 + t) : e + t - e * t, a = 2 * e - i;
|
1433
|
-
s = ft(a, i, o + 1 / 3),
|
1434
|
-
}
|
1435
|
-
return { r: s, g:
|
1436
|
-
},
|
1437
|
-
let s = 0,
|
1438
|
-
const
|
1439
|
-
if (i ===
|
1440
|
-
return { h: 0, w:
|
1441
|
-
o ===
|
1442
|
-
const l = (
|
1417
|
+
s = ft(a, i, o + 1 / 3), r = ft(a, i, o), n = ft(a, i, o - 1 / 3);
|
1418
|
+
}
|
1419
|
+
return { r: s, g: r, b: n };
|
1420
|
+
}, se = (o, t, e) => {
|
1421
|
+
let s = 0, r = 0;
|
1422
|
+
const n = Math.min(o, t, e), i = Math.max(o, t, e), a = 1 - i;
|
1423
|
+
if (i === n)
|
1424
|
+
return { h: 0, w: n, b: a };
|
1425
|
+
o === n ? (s = t - e, r = 3) : (s = t === n ? e - o : o - t, r = t === n ? 5 : 1);
|
1426
|
+
const l = (r - s / (i - n)) / 6;
|
1443
1427
|
return {
|
1444
1428
|
h: l === 1 ? 0 : l,
|
1445
|
-
w:
|
1429
|
+
w: n,
|
1446
1430
|
b: a
|
1447
1431
|
};
|
1448
1432
|
}, Le = (o, t, e) => {
|
@@ -1450,35 +1434,35 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1450
1434
|
const i = t / (t + e);
|
1451
1435
|
return { r: i, g: i, b: i };
|
1452
1436
|
}
|
1453
|
-
let { r: s, g:
|
1454
|
-
return [s,
|
1455
|
-
},
|
1456
|
-
const s = Math.max(o, t, e),
|
1457
|
-
let
|
1458
|
-
const i = s, a = s -
|
1459
|
-
return s ===
|
1437
|
+
let { r: s, g: r, b: n } = lt(o, 1, 0.5);
|
1438
|
+
return [s, r, n] = [s, r, n].map((i) => i * (1 - t - e) + t), { r: s, g: r, b: n };
|
1439
|
+
}, re = (o, t, e) => {
|
1440
|
+
const s = Math.max(o, t, e), r = Math.min(o, t, e);
|
1441
|
+
let n = 0;
|
1442
|
+
const i = s, a = s - r, l = s === 0 ? 0 : a / s;
|
1443
|
+
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 };
|
1460
1444
|
}, Ft = (o, t, e) => {
|
1461
|
-
const s = o * 6,
|
1445
|
+
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];
|
1462
1446
|
return { r: u, g: d, b: g };
|
1463
|
-
},
|
1464
|
-
const n = [
|
1465
|
-
z(v(o).toString(16)),
|
1466
|
-
z(v(t).toString(16)),
|
1467
|
-
z(v(e).toString(16))
|
1468
|
-
];
|
1469
|
-
return s && 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[0].charAt(0) + n[1].charAt(0) + n[2].charAt(0) : n.join("");
|
1470
|
-
}, At = (o, t, e, s, n) => {
|
1447
|
+
}, ne = (o, t, e, s) => {
|
1471
1448
|
const r = [
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
z(Ce(s))
|
1449
|
+
G(v(o).toString(16)),
|
1450
|
+
G(v(t).toString(16)),
|
1451
|
+
G(v(e).toString(16))
|
1476
1452
|
];
|
1477
|
-
return
|
1453
|
+
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("");
|
1454
|
+
}, At = (o, t, e, s, r) => {
|
1455
|
+
const n = [
|
1456
|
+
G(v(o).toString(16)),
|
1457
|
+
G(v(t).toString(16)),
|
1458
|
+
G(v(e).toString(16)),
|
1459
|
+
G(Ce(s))
|
1460
|
+
];
|
1461
|
+
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("");
|
1478
1462
|
}, Ae = (o) => {
|
1479
1463
|
const t = String(o).trim().toLowerCase();
|
1480
|
-
if (
|
1481
|
-
return Object.assign(
|
1464
|
+
if (Se(t))
|
1465
|
+
return Object.assign(Pe(t), {
|
1482
1466
|
a: 1,
|
1483
1467
|
format: "rgb",
|
1484
1468
|
ok: !0
|
@@ -1492,60 +1476,60 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1492
1476
|
format: "rgb",
|
1493
1477
|
ok: !0
|
1494
1478
|
};
|
1495
|
-
let [, e, s,
|
1496
|
-
return e && s &&
|
1479
|
+
let [, e, s, r, n] = I.rgb.exec(t) || [];
|
1480
|
+
return e && s && r ? {
|
1497
1481
|
r: e,
|
1498
1482
|
g: s,
|
1499
|
-
b:
|
1500
|
-
a:
|
1483
|
+
b: r,
|
1484
|
+
a: n !== void 0 ? n : 1,
|
1501
1485
|
format: "rgb",
|
1502
1486
|
ok: !0
|
1503
|
-
} : ([, e, s,
|
1487
|
+
} : ([, e, s, r, n] = I.hsl.exec(t) || [], e && s && r ? {
|
1504
1488
|
h: e,
|
1505
1489
|
s,
|
1506
|
-
l:
|
1507
|
-
a:
|
1490
|
+
l: r,
|
1491
|
+
a: n !== void 0 ? n : 1,
|
1508
1492
|
format: "hsl",
|
1509
1493
|
ok: !0
|
1510
|
-
} : ([, e, s,
|
1494
|
+
} : ([, e, s, r, n] = I.hsv.exec(t) || [], e && s && r ? {
|
1511
1495
|
h: e,
|
1512
1496
|
s,
|
1513
|
-
v:
|
1514
|
-
a:
|
1497
|
+
v: r,
|
1498
|
+
a: n !== void 0 ? n : 1,
|
1515
1499
|
format: "hsv",
|
1516
1500
|
ok: !0
|
1517
|
-
} : ([, e, s,
|
1501
|
+
} : ([, e, s, r, n] = I.hwb.exec(t) || [], e && s && r ? {
|
1518
1502
|
h: e,
|
1519
1503
|
w: s,
|
1520
|
-
b:
|
1521
|
-
a:
|
1504
|
+
b: r,
|
1505
|
+
a: n !== void 0 ? n : 1,
|
1522
1506
|
format: "hwb",
|
1523
1507
|
ok: !0
|
1524
|
-
} : ([, e, s,
|
1508
|
+
} : ([, e, s, r, n] = I.hex8.exec(t) || [], e && s && r && n ? {
|
1525
1509
|
r: N(e),
|
1526
1510
|
g: N(s),
|
1527
|
-
b: N(
|
1528
|
-
a:
|
1511
|
+
b: N(r),
|
1512
|
+
a: Dt(n),
|
1529
1513
|
format: "hex",
|
1530
1514
|
ok: !0
|
1531
|
-
} : ([, e, s,
|
1515
|
+
} : ([, e, s, r] = I.hex6.exec(t) || [], e && s && r ? {
|
1532
1516
|
r: N(e),
|
1533
1517
|
g: N(s),
|
1534
|
-
b: N(
|
1518
|
+
b: N(r),
|
1535
1519
|
a: 1,
|
1536
1520
|
format: "hex",
|
1537
1521
|
ok: !0
|
1538
|
-
} : ([, e, s,
|
1522
|
+
} : ([, e, s, r, n] = I.hex4.exec(t) || [], e && s && r && n ? {
|
1539
1523
|
r: N(e + e),
|
1540
1524
|
g: N(s + s),
|
1541
|
-
b: N(
|
1542
|
-
a:
|
1525
|
+
b: N(r + r),
|
1526
|
+
a: Dt(n + n),
|
1543
1527
|
format: "hex",
|
1544
1528
|
ok: !0
|
1545
|
-
} : ([, e, s,
|
1529
|
+
} : ([, e, s, r] = I.hex3.exec(t) || [], e && s && r ? {
|
1546
1530
|
r: N(e + e),
|
1547
1531
|
g: N(s + s),
|
1548
|
-
b: N(
|
1532
|
+
b: N(r + r),
|
1549
1533
|
a: 1,
|
1550
1534
|
format: "hex",
|
1551
1535
|
ok: !0
|
@@ -1557,17 +1541,17 @@ fe(o.getRootNode().host, t) : null, _ = (o, t) => at(o) ? o : (Q(t) ? t : K()).q
|
|
1557
1541
|
format: "rgb",
|
1558
1542
|
ok: !o
|
1559
1543
|
})))))));
|
1560
|
-
},
|
1561
|
-
let t = { r: 0, g: 0, b: 0 }, e = o, s = 1,
|
1562
|
-
return (!e || typeof e == "string") && (e = Ae(e), d = e.ok),
|
1544
|
+
}, ie = (o) => {
|
1545
|
+
let t = { r: 0, g: 0, b: 0 }, e = o, s = 1, r, n, i, a, l, c, h, b, u = "rgb", d = !1;
|
1546
|
+
return (!e || typeof e == "string") && (e = Ae(e), d = e.ok), nt(e, t) && H(e.r) && H(e.g) && H(e.b) && ({ r: h, g: b, b: l } = e, [h, b, l] = [h, b, l].map((g) => R(g, $t(g) ? 100 : 255)), t = { r: h, g: b, b: l }, u = "format" in e ? e.format : "rgb"), nt(e, { h: 0, s: 0, v: 0 }) && H(e.h) && H(e.s) && H(e.v) && ({ h: c, s: r, v: n } = e, c = R(c, 360), r = R(r, 100), n = R(n, 100), t = Ft(c, r, n), u = "hsv"), nt(e, { h: 0, s: 0, l: 0 }) && H(e.h) && H(e.s) && H(e.l) && ({ h: c, s: r, l: i } = e, c = R(c, 360), r = R(r, 100), i = R(i, 100), t = lt(c, r, i), u = "hsl"), nt(e, { h: 0, w: 0, b: 0 }) && H(e.h) && H(e.w) && H(e.b) && ({ h: c, w: a, b: l } = e, c = R(c, 360), a = R(a, 100), l = R(l, 100), t = Le(c, a, l), u = "hwb"), H(e.a) && (s = e.a, s = $t(s) || parseFloat(`${s}`) > 1 ? R(s, 100) : s), {
|
1563
1547
|
r: t.r,
|
1564
1548
|
g: t.g,
|
1565
1549
|
b: t.b,
|
1566
|
-
a:
|
1550
|
+
a: Ot(s),
|
1567
1551
|
format: u,
|
1568
1552
|
ok: d
|
1569
1553
|
};
|
1570
|
-
},
|
1554
|
+
}, lo = "1.0.8";
|
1571
1555
|
class y {
|
1572
1556
|
// bring main utilities to front
|
1573
1557
|
static matchers = I;
|
@@ -1575,19 +1559,19 @@ class y {
|
|
1575
1559
|
static isPercentage = $t;
|
1576
1560
|
static isValidCSSUnit = H;
|
1577
1561
|
static isNonColor = ke;
|
1578
|
-
static isColorName =
|
1579
|
-
static isColorType =
|
1580
|
-
static pad2 =
|
1562
|
+
static isColorName = Se;
|
1563
|
+
static isColorType = nt;
|
1564
|
+
static pad2 = G;
|
1581
1565
|
static clamp01 = ut;
|
1582
1566
|
static bound01 = R;
|
1583
|
-
static boundAlpha =
|
1584
|
-
static getRGBFromName =
|
1585
|
-
static convertHexToDecimal =
|
1567
|
+
static boundAlpha = Ot;
|
1568
|
+
static getRGBFromName = Pe;
|
1569
|
+
static convertHexToDecimal = Dt;
|
1586
1570
|
static convertDecimalToHex = Ce;
|
1587
|
-
static rgbToHsl =
|
1588
|
-
static rgbToHex =
|
1589
|
-
static rgbToHsv =
|
1590
|
-
static rgbToHwb =
|
1571
|
+
static rgbToHsl = oe;
|
1572
|
+
static rgbToHex = ne;
|
1573
|
+
static rgbToHsv = re;
|
1574
|
+
static rgbToHwb = se;
|
1591
1575
|
static rgbaToHex = At;
|
1592
1576
|
static hslToRgb = Ft;
|
1593
1577
|
static hsvToRgb = Ft;
|
@@ -1595,11 +1579,11 @@ class y {
|
|
1595
1579
|
static hwbToRgb = Le;
|
1596
1580
|
static parseIntFromHex = N;
|
1597
1581
|
static stringInputToObject = Ae;
|
1598
|
-
static inputToRGB =
|
1582
|
+
static inputToRGB = ie;
|
1599
1583
|
static roundPart = v;
|
1600
1584
|
static webColors = wt;
|
1601
|
-
static nonColors =
|
1602
|
-
static version =
|
1585
|
+
static nonColors = Gt;
|
1586
|
+
static version = lo;
|
1603
1587
|
// main public properties
|
1604
1588
|
r;
|
1605
1589
|
g;
|
@@ -1610,8 +1594,8 @@ class y {
|
|
1610
1594
|
originalInput;
|
1611
1595
|
// main public methods
|
1612
1596
|
constructor(t, e) {
|
1613
|
-
const s = e && xe.includes(e) ? e : "", { r
|
1614
|
-
this.originalInput = t, this.r =
|
1597
|
+
const s = e && xe.includes(e) ? e : "", { r, g: n, b: i, a, ok: l, format: c } = ie(t);
|
1598
|
+
this.originalInput = t, this.r = r, this.g = n, this.b = i, this.a = a, this.ok = l, this.format = s || c;
|
1615
1599
|
}
|
1616
1600
|
/**
|
1617
1601
|
* Checks if the current input value is a valid colour.
|
@@ -1632,8 +1616,8 @@ class y {
|
|
1632
1616
|
*/
|
1633
1617
|
get luminance() {
|
1634
1618
|
const { r: t, g: e, b: s } = this;
|
1635
|
-
let
|
1636
|
-
return t <= 0.03928 ?
|
1619
|
+
let r = 0, n = 0, i = 0;
|
1620
|
+
return t <= 0.03928 ? r = t / 12.92 : r = ((t + 0.055) / 1.055) ** 2.4, e <= 0.03928 ? n = e / 12.92 : n = ((e + 0.055) / 1.055) ** 2.4, s <= 0.03928 ? i = s / 12.92 : i = ((s + 0.055) / 1.055) ** 2.4, 0.2126 * r + 0.7152 * n + 0.0722 * i;
|
1637
1621
|
}
|
1638
1622
|
/**
|
1639
1623
|
* Returns the perceived brightness of the colour.
|
@@ -1646,25 +1630,25 @@ class y {
|
|
1646
1630
|
* Returns the web colour name closest to the current colour.
|
1647
1631
|
*/
|
1648
1632
|
get name() {
|
1649
|
-
const { r: t, g: e, b: s } = this.toRgb(), [
|
1633
|
+
const { r: t, g: e, b: s } = this.toRgb(), [r] = wt.map(([n, i]) => {
|
1650
1634
|
const a = (
|
1651
1635
|
// ((rgb.r - r) ** 2 + (rgb.g - g) ** 2 + (rgb.b - b) ** 2) ** 0.5; // standard
|
1652
1636
|
(((i.r - t) * 0.3) ** 2 + ((i.g - e) * 0.6) ** 2 + ((i.b - s) * 0.1) ** 2) ** 0.5
|
1653
1637
|
);
|
1654
|
-
return [
|
1655
|
-
}).find(([,
|
1656
|
-
return
|
1638
|
+
return [n, a];
|
1639
|
+
}).find(([, n], i, a) => n === Math.min(...a.map(([, l]) => l)));
|
1640
|
+
return r;
|
1657
1641
|
}
|
1658
1642
|
/**
|
1659
1643
|
* Returns the colour as an RGBA object.
|
1660
1644
|
*/
|
1661
1645
|
toRgb() {
|
1662
|
-
let { r: t, g: e, b: s, a:
|
1663
|
-
return [t, e, s] = [t, e, s].map((
|
1646
|
+
let { r: t, g: e, b: s, a: r } = this;
|
1647
|
+
return [t, e, s] = [t, e, s].map((n) => v(n * 255 * 100) / 100), r = v(r * 100) / 100, {
|
1664
1648
|
r: t,
|
1665
1649
|
g: e,
|
1666
1650
|
b: s,
|
1667
|
-
a:
|
1651
|
+
a: r
|
1668
1652
|
};
|
1669
1653
|
}
|
1670
1654
|
/**
|
@@ -1673,8 +1657,8 @@ class y {
|
|
1673
1657
|
* * rgba(255,255,255,0.5)
|
1674
1658
|
*/
|
1675
1659
|
toRgbString() {
|
1676
|
-
const { r: t, g: e, b: s, a:
|
1677
|
-
return
|
1660
|
+
const { r: t, g: e, b: s, a: r } = this.toRgb(), [n, i, a] = [t, e, s].map(v);
|
1661
|
+
return r === 1 ? `rgb(${n}, ${i}, ${a})` : `rgba(${n}, ${i}, ${a}, ${r})`;
|
1678
1662
|
}
|
1679
1663
|
/**
|
1680
1664
|
* Returns the RGBA values concatenated into a CSS4 Module string format.
|
@@ -1682,16 +1666,16 @@ class y {
|
|
1682
1666
|
* * rgb(255 255 255 / 50%)
|
1683
1667
|
*/
|
1684
1668
|
toRgbCSS4String() {
|
1685
|
-
const { r: t, g: e, b: s, a:
|
1686
|
-
return `rgb(${
|
1669
|
+
const { r: t, g: e, b: s, a: r } = this.toRgb(), [n, i, a] = [t, e, s].map(v), l = r === 1 ? "" : ` / ${v(r * 100)}%`;
|
1670
|
+
return `rgb(${n} ${i} ${a}${l})`;
|
1687
1671
|
}
|
1688
1672
|
/**
|
1689
1673
|
* Returns the hexadecimal value of the colour. When the parameter is *true*
|
1690
1674
|
* it will find a 3 characters shorthand of the decimal value.
|
1691
1675
|
*/
|
1692
1676
|
toHex(t) {
|
1693
|
-
const { r: e, g: s, b:
|
1694
|
-
return
|
1677
|
+
const { r: e, g: s, b: r, a: n } = this.toRgb();
|
1678
|
+
return n === 1 ? ne(e, s, r, t) : At(e, s, r, n, t);
|
1695
1679
|
}
|
1696
1680
|
/**
|
1697
1681
|
* Returns the CSS valid hexadecimal vaue of the colour. When the parameter is *true*
|
@@ -1704,8 +1688,8 @@ class y {
|
|
1704
1688
|
* Returns the HEX8 value of the colour.
|
1705
1689
|
*/
|
1706
1690
|
toHex8(t) {
|
1707
|
-
const { r: e, g: s, b:
|
1708
|
-
return At(e, s,
|
1691
|
+
const { r: e, g: s, b: r, a: n } = this.toRgb();
|
1692
|
+
return At(e, s, r, n, t);
|
1709
1693
|
}
|
1710
1694
|
/**
|
1711
1695
|
* Returns the HEX8 value of the colour.
|
@@ -1717,24 +1701,24 @@ class y {
|
|
1717
1701
|
* Returns the colour as a HSVA object.
|
1718
1702
|
*/
|
1719
1703
|
toHsv() {
|
1720
|
-
const { r: t, g: e, b: s, a:
|
1704
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, v: a } = re(t, e, s);
|
1721
1705
|
return {
|
1722
|
-
h:
|
1706
|
+
h: n,
|
1723
1707
|
s: i,
|
1724
1708
|
v: a,
|
1725
|
-
a:
|
1709
|
+
a: r
|
1726
1710
|
};
|
1727
1711
|
}
|
1728
1712
|
/**
|
1729
1713
|
* Returns the colour as an HSLA object.
|
1730
1714
|
*/
|
1731
1715
|
toHsl() {
|
1732
|
-
const { r: t, g: e, b: s, a:
|
1716
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, s: i, l: a } = oe(t, e, s);
|
1733
1717
|
return {
|
1734
|
-
h:
|
1718
|
+
h: n,
|
1735
1719
|
s: i,
|
1736
1720
|
l: a,
|
1737
|
-
a:
|
1721
|
+
a: r
|
1738
1722
|
};
|
1739
1723
|
}
|
1740
1724
|
/**
|
@@ -1743,8 +1727,8 @@ class y {
|
|
1743
1727
|
* * `hsla(150, 100%, 50%, 0.5)`
|
1744
1728
|
*/
|
1745
1729
|
toHslString() {
|
1746
|
-
let { h: t, s: e, l: s, a:
|
1747
|
-
return t = v(t * 360), e = v(e * 100), s = v(s * 100),
|
1730
|
+
let { h: t, s: e, l: s, a: r } = this.toHsl();
|
1731
|
+
return t = v(t * 360), e = v(e * 100), s = v(s * 100), r = v(r * 100) / 100, r === 1 ? `hsl(${t}, ${e}%, ${s}%)` : `hsla(${t}, ${e}%, ${s}%, ${r})`;
|
1748
1732
|
}
|
1749
1733
|
/**
|
1750
1734
|
* Returns the HSLA values concatenated into a CSS4 Module format string.
|
@@ -1752,37 +1736,37 @@ class y {
|
|
1752
1736
|
* * `hsl(150deg 100% 50% / 50%)`
|
1753
1737
|
*/
|
1754
1738
|
toHslCSS4String() {
|
1755
|
-
let { h: t, s: e, l: s, a:
|
1756
|
-
t = v(t * 360), e = v(e * 100), s = v(s * 100),
|
1757
|
-
const
|
1758
|
-
return `hsl(${t}deg ${e}% ${s}%${
|
1739
|
+
let { h: t, s: e, l: s, a: r } = this.toHsl();
|
1740
|
+
t = v(t * 360), e = v(e * 100), s = v(s * 100), r = v(r * 100);
|
1741
|
+
const n = r < 100 ? ` / ${v(r)}%` : "";
|
1742
|
+
return `hsl(${t}deg ${e}% ${s}%${n})`;
|
1759
1743
|
}
|
1760
1744
|
/**
|
1761
1745
|
* Returns the colour as an HWBA object.
|
1762
1746
|
*/
|
1763
1747
|
toHwb() {
|
1764
|
-
const { r: t, g: e, b: s, a:
|
1748
|
+
const { r: t, g: e, b: s, a: r } = this, { h: n, w: i, b: a } = se(t, e, s);
|
1765
1749
|
return {
|
1766
|
-
h:
|
1750
|
+
h: n,
|
1767
1751
|
w: i,
|
1768
1752
|
b: a,
|
1769
|
-
a:
|
1753
|
+
a: r
|
1770
1754
|
};
|
1771
1755
|
}
|
1772
1756
|
/**
|
1773
1757
|
* Returns the HWBA values concatenated into a string.
|
1774
1758
|
*/
|
1775
1759
|
toHwbString() {
|
1776
|
-
let { h: t, w: e, b: s, a:
|
1777
|
-
t = v(t * 360), e = v(e * 100), s = v(s * 100),
|
1778
|
-
const
|
1779
|
-
return `hwb(${t}deg ${e}% ${s}%${
|
1760
|
+
let { h: t, w: e, b: s, a: r } = this.toHwb();
|
1761
|
+
t = v(t * 360), e = v(e * 100), s = v(s * 100), r = v(r * 100);
|
1762
|
+
const n = r < 100 ? ` / ${v(r)}%` : "";
|
1763
|
+
return `hwb(${t}deg ${e}% ${s}%${n})`;
|
1780
1764
|
}
|
1781
1765
|
/**
|
1782
1766
|
* Sets the alpha value of the current colour.
|
1783
1767
|
*/
|
1784
1768
|
setAlpha(t) {
|
1785
|
-
return typeof t != "number" ? this : (this.a =
|
1769
|
+
return typeof t != "number" ? this : (this.a = Ot(t), this);
|
1786
1770
|
}
|
1787
1771
|
/**
|
1788
1772
|
* Saturate the colour with a given amount.
|
@@ -1790,8 +1774,8 @@ class y {
|
|
1790
1774
|
saturate(t) {
|
1791
1775
|
if (typeof t != "number")
|
1792
1776
|
return this;
|
1793
|
-
const { h: e, s, l:
|
1794
|
-
return Object.assign(this, { r, g: i, b: a }), this;
|
1777
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = lt(e, ut(s + t / 100), r);
|
1778
|
+
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1795
1779
|
}
|
1796
1780
|
/**
|
1797
1781
|
* Desaturate the colour with a given amount.
|
@@ -1812,8 +1796,8 @@ class y {
|
|
1812
1796
|
lighten(t) {
|
1813
1797
|
if (typeof t != "number")
|
1814
1798
|
return this;
|
1815
|
-
const { h: e, s, l:
|
1816
|
-
return Object.assign(this, { r, g: i, b: a }), this;
|
1799
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = lt(e, s, ut(r + t / 100));
|
1800
|
+
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1817
1801
|
}
|
1818
1802
|
/**
|
1819
1803
|
* Decrease the colour lightness with a given amount.
|
@@ -1828,8 +1812,8 @@ class y {
|
|
1828
1812
|
spin(t) {
|
1829
1813
|
if (typeof t != "number")
|
1830
1814
|
return this;
|
1831
|
-
const { h: e, s, l:
|
1832
|
-
return Object.assign(this, { r, g: i, b: a }), this;
|
1815
|
+
const { h: e, s, l: r } = this.toHsl(), { r: n, g: i, b: a } = lt(ut((e * 360 + t) % 360 / 360), s, r);
|
1816
|
+
return Object.assign(this, { r: n, g: i, b: a }), this;
|
1833
1817
|
}
|
1834
1818
|
/** Returns a clone of the current `Color` instance. */
|
1835
1819
|
clone() {
|
@@ -1858,36 +1842,36 @@ class It {
|
|
1858
1842
|
* * `args.saturation` Saturation [0, 100]
|
1859
1843
|
*/
|
1860
1844
|
constructor(...t) {
|
1861
|
-
let e = 0, s = 12,
|
1845
|
+
let e = 0, s = 12, r = 10, n = [0.5], i = 100;
|
1862
1846
|
if (t.length === 4)
|
1863
|
-
[e, s,
|
1847
|
+
[e, s, r, i] = t;
|
1864
1848
|
else if (t.length === 3)
|
1865
|
-
[e, s,
|
1866
|
-
else if (t.length === 2 && ([s,
|
1849
|
+
[e, s, r] = t;
|
1850
|
+
else if (t.length === 2 && ([s, r] = t, [s, r].some((g) => g < 1)))
|
1867
1851
|
throw TypeError("ColorPalette: the two minimum arguments must be numbers higher than 0.");
|
1868
|
-
const a = [], l = 360 / s, c = y.roundPart((
|
1852
|
+
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 = [
|
1869
1853
|
[1, 2, 3],
|
1870
1854
|
[4, 5],
|
1871
1855
|
[6, 7],
|
1872
1856
|
[8, 9],
|
1873
1857
|
[10, 11],
|
1874
1858
|
[12, 13]
|
1875
|
-
], u = b.find((g) => g.includes(
|
1859
|
+
], u = b.find((g) => g.includes(r)), d = u ? h[b.indexOf(u)] : 100 / (r + (r % 2 ? 0 : 1)) / 100;
|
1876
1860
|
for (let g = 1; g < c + 1; g += 1)
|
1877
|
-
|
1878
|
-
for (let g = 1; g <
|
1879
|
-
|
1861
|
+
n = [...n, 0.5 + d * g];
|
1862
|
+
for (let g = 1; g < r - c; g += 1)
|
1863
|
+
n = [0.5 - d * g, ...n];
|
1880
1864
|
for (let g = 0; g < s; g += 1) {
|
1881
1865
|
const p = (e + g * l) % 360 / 360;
|
1882
|
-
|
1866
|
+
n.forEach((f) => {
|
1883
1867
|
const w = new y({ h: p, s: 1, l: f });
|
1884
1868
|
a.push(i < 100 ? w.saturate(i - 100) : w);
|
1885
1869
|
});
|
1886
1870
|
}
|
1887
|
-
this.hue = e, this.hueSteps = s, this.lightSteps =
|
1871
|
+
this.hue = e, this.hueSteps = s, this.lightSteps = r, this.saturation = i, this.colors = a;
|
1888
1872
|
}
|
1889
1873
|
}
|
1890
|
-
const
|
1874
|
+
const Kt = {
|
1891
1875
|
pickerLabel: "Colour Picker",
|
1892
1876
|
appearanceLabel: "Colour Appearance",
|
1893
1877
|
valueLabel: "Colour Value",
|
@@ -1905,7 +1889,7 @@ const He = {
|
|
1905
1889
|
redLabel: "Red",
|
1906
1890
|
greenLabel: "Green",
|
1907
1891
|
blueLabel: "Blue"
|
1908
|
-
},
|
1892
|
+
}, it = [
|
1909
1893
|
"white",
|
1910
1894
|
"black",
|
1911
1895
|
"grey",
|
@@ -1923,8 +1907,8 @@ const He = {
|
|
1923
1907
|
"violet",
|
1924
1908
|
"magenta",
|
1925
1909
|
"pink"
|
1926
|
-
],
|
1927
|
-
if (!
|
1910
|
+
], ae = (o) => {
|
1911
|
+
if (!B(o))
|
1928
1912
|
return !1;
|
1929
1913
|
try {
|
1930
1914
|
JSON.parse(o);
|
@@ -1932,13 +1916,13 @@ const He = {
|
|
1932
1916
|
return !1;
|
1933
1917
|
}
|
1934
1918
|
return !0;
|
1935
|
-
}, Vt = "v-hidden",
|
1936
|
-
const { format: t, id: e, componentLabels: s } = o,
|
1919
|
+
}, Vt = "v-hidden", co = (o) => {
|
1920
|
+
const { format: t, id: e, componentLabels: s } = o, r = x({
|
1937
1921
|
tagName: "div",
|
1938
1922
|
className: `color-form ${t}`
|
1939
1923
|
});
|
1940
|
-
let
|
1941
|
-
return t === "rgb" ?
|
1924
|
+
let n = ["hex"];
|
1925
|
+
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) => {
|
1942
1926
|
const [a] = t === "hex" ? ["#"] : pe(i).split(""), l = `color_${t}_${i}_${e}`, c = s[`${i}Label`], h = x({ tagName: "label" });
|
1943
1927
|
m(h, "for", l), h.append(
|
1944
1928
|
x({
|
@@ -1963,15 +1947,15 @@ const He = {
|
|
1963
1947
|
spellcheck: !1
|
1964
1948
|
});
|
1965
1949
|
let u = "100", d = "1";
|
1966
|
-
i !== "alpha" && (t === "rgb" ? (u = "255", d = "1") : i === "hue" && (u = "360", d = "1")),
|
1950
|
+
i !== "alpha" && (t === "rgb" ? (u = "255", d = "1") : i === "hue" && (u = "360", d = "1")), K(b, {
|
1967
1951
|
min: "0",
|
1968
1952
|
max: u,
|
1969
1953
|
step: d
|
1970
|
-
}),
|
1971
|
-
}),
|
1972
|
-
},
|
1973
|
-
const { format: t, componentLabels: e } = o, { hueLabel: s, alphaLabel:
|
1974
|
-
let u = t === "hsl" ? `${s} & ${
|
1954
|
+
}), r.append(h, b);
|
1955
|
+
}), r;
|
1956
|
+
}, ho = (o) => {
|
1957
|
+
const { format: t, componentLabels: e } = o, { hueLabel: s, alphaLabel: r, lightnessLabel: n, saturationLabel: i, whitenessLabel: a, blacknessLabel: l } = e, c = t === "hsl" ? 360 : 100, h = t === "hsl" ? 100 : 360, b = 100;
|
1958
|
+
let u = t === "hsl" ? `${s} & ${n}` : `${n} & ${i}`;
|
1975
1959
|
u = t === "hwb" ? `${a} & ${l}` : u;
|
1976
1960
|
const d = t === "hsl" ? `${i}` : `${s}`, g = x({
|
1977
1961
|
tagName: "div",
|
@@ -1995,12 +1979,12 @@ const He = {
|
|
1995
1979
|
{
|
1996
1980
|
i: 3,
|
1997
1981
|
c: f,
|
1998
|
-
l:
|
1982
|
+
l: r,
|
1999
1983
|
min: 0,
|
2000
1984
|
max: b
|
2001
1985
|
}
|
2002
1986
|
].forEach(($) => {
|
2003
|
-
const { i:
|
1987
|
+
const { i: S, c: L, l: P, min: C, max: M } = $, E = x({
|
2004
1988
|
tagName: "div",
|
2005
1989
|
className: "color-control",
|
2006
1990
|
role: "presentation"
|
@@ -2008,14 +1992,14 @@ const He = {
|
|
2008
1992
|
E.append(
|
2009
1993
|
x({
|
2010
1994
|
tagName: "div",
|
2011
|
-
className: `visual-control visual-control${
|
1995
|
+
className: `visual-control visual-control${S}`
|
2012
1996
|
})
|
2013
1997
|
);
|
2014
1998
|
const A = x({
|
2015
1999
|
tagName: "div",
|
2016
2000
|
className: `${L} knob`,
|
2017
2001
|
ariaLive: "polite",
|
2018
|
-
ariaLabel:
|
2002
|
+
ariaLabel: P,
|
2019
2003
|
role: "slider",
|
2020
2004
|
tabIndex: 0,
|
2021
2005
|
ariaValueMin: `${C}`,
|
@@ -2023,47 +2007,48 @@ const He = {
|
|
2023
2007
|
});
|
2024
2008
|
E.append(A), g.append(E);
|
2025
2009
|
}), g;
|
2026
|
-
},
|
2027
|
-
const { input: s, format:
|
2010
|
+
}, le = (o, t, e) => {
|
2011
|
+
const { input: s, format: r, componentLabels: n } = o, { defaultsLabel: i, presetsLabel: a } = n, l = e === "color-options", c = t instanceof It, 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;
|
2028
2012
|
let f = 2;
|
2029
2013
|
f = p && u > g * 2 ? 3 : f, f = p && u > g * 3 ? 4 : f, f = p && u > g * 4 ? 5 : f;
|
2030
2014
|
const w = f - (u <= g * 3 ? 1 : 2), $ = p && u > w * g;
|
2031
|
-
let
|
2032
|
-
|
2015
|
+
let S = e;
|
2016
|
+
S += $ ? " scrollable" : "", S += p ? " multiline" : "";
|
2033
2017
|
const L = p ? "1px" : "0.25rem";
|
2034
|
-
let
|
2035
|
-
|
2036
|
-
const C = `${w *
|
2018
|
+
let P = p ? 1.75 : 2;
|
2019
|
+
P = g > 5 && p ? 1.5 : P;
|
2020
|
+
const C = `${w * P}rem`, M = `calc(${f} * ${P}rem + ${f - 1} * ${L})`, E = x({
|
2037
2021
|
tagName: "ul",
|
2038
|
-
className:
|
2022
|
+
className: S,
|
2039
2023
|
role: "listbox",
|
2040
2024
|
ariaLabel: h
|
2041
2025
|
});
|
2042
|
-
return $ &&
|
2043
|
-
"--grid-item-size": `${
|
2026
|
+
return $ && D(E, {
|
2027
|
+
"--grid-item-size": `${P}rem`,
|
2044
2028
|
"--grid-fit": `${g}`,
|
2045
2029
|
"--grid-gap": L,
|
2046
2030
|
"--grid-height": C,
|
2047
2031
|
"--grid-hover-height": M
|
2048
2032
|
}), b.forEach((A) => {
|
2049
|
-
let [F,
|
2050
|
-
A instanceof y && (F = A.toHexString(),
|
2051
|
-
const
|
2033
|
+
let [F, Q] = typeof A == "string" ? A.trim().split(":") : [];
|
2034
|
+
A instanceof y && (F = A.toHexString(), Q = F);
|
2035
|
+
const Ut = new y(A instanceof y ? A : F, r).toString() === yt(s, "value"), xt = x({
|
2052
2036
|
tagName: "li",
|
2053
|
-
className: `color-option${
|
2054
|
-
innerText: `${
|
2037
|
+
className: `color-option${Ut ? " active" : ""}`,
|
2038
|
+
innerText: `${Q || F}`,
|
2055
2039
|
tabIndex: 0,
|
2056
2040
|
role: "option",
|
2057
|
-
ariaSelected:
|
2041
|
+
ariaSelected: Ut ? "true" : "false"
|
2058
2042
|
});
|
2059
|
-
m(xt, "data-value", `${F}`), l &&
|
2043
|
+
m(xt, "data-value", `${F}`), l && D(xt, { backgroundColor: F }), E.append(xt);
|
2060
2044
|
}), E;
|
2061
|
-
},
|
2062
|
-
const { input: t, parent: e, format: s, id:
|
2045
|
+
}, go = (o) => {
|
2046
|
+
const { input: t, parent: e, format: s, id: r, componentLabels: n, colorKeywords: i, colorPresets: a } = o, l = yt(t, "value") || "#fff", { nonColors: c } = y, { toggleLabel: h, pickerLabel: b, formatLabel: u, hexLabel: d } = n, g = c.includes(l) ? "#fff" : l;
|
2063
2047
|
o.color = new y(g, s);
|
2064
2048
|
const p = s === "hex" ? d : pe(s), f = x({
|
2065
|
-
id: `picker-btn-${
|
2049
|
+
id: `picker-btn-${r}`,
|
2066
2050
|
tagName: "button",
|
2051
|
+
type: "button",
|
2067
2052
|
className: "picker-toggle btn-appearance",
|
2068
2053
|
ariaExpanded: "false",
|
2069
2054
|
ariaHasPopup: "true"
|
@@ -2079,16 +2064,17 @@ const He = {
|
|
2079
2064
|
tagName: "div",
|
2080
2065
|
className: "color-dropdown picker",
|
2081
2066
|
role: "group",
|
2082
|
-
ariaLabelledBy: `picker-btn-${
|
2083
|
-
}), $ =
|
2084
|
-
if (w.append($,
|
2067
|
+
ariaLabelledBy: `picker-btn-${r}`
|
2068
|
+
}), $ = ho(o), S = co(o);
|
2069
|
+
if (w.append($, S), t.before(f), e.append(w), i || a) {
|
2085
2070
|
const L = x({
|
2086
2071
|
tagName: "div",
|
2087
2072
|
className: "color-dropdown scrollable menu"
|
2088
2073
|
});
|
2089
|
-
a && L.append(
|
2090
|
-
const
|
2074
|
+
a && L.append(le(o, a, "color-options")), i && i.length && L.append(le(o, i, "color-defaults"));
|
2075
|
+
const P = x({
|
2091
2076
|
tagName: "button",
|
2077
|
+
type: "button",
|
2092
2078
|
className: "menu-toggle btn-appearance",
|
2093
2079
|
tabIndex: -1,
|
2094
2080
|
ariaExpanded: "false",
|
@@ -2096,53 +2082,55 @@ const He = {
|
|
2096
2082
|
}), C = encodeURI("http://www.w3.org/2000/svg"), M = Mt(C, {
|
2097
2083
|
tagName: "svg"
|
2098
2084
|
});
|
2099
|
-
m(M, "xmlns", C), m(M, "viewBox", "0 0 512 512"), m(M,
|
2085
|
+
m(M, "xmlns", C), m(M, "viewBox", "0 0 512 512"), m(M, Ee, "true");
|
2100
2086
|
const E = Mt(C, {
|
2101
2087
|
tagName: "path"
|
2102
2088
|
});
|
2103
|
-
m(E, "d", "M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"), m(E, "fill", "#fff"), M.append(E),
|
2089
|
+
m(E, "d", "M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"), m(E, "fill", "#fff"), M.append(E), P.append(
|
2104
2090
|
x({
|
2105
2091
|
tagName: "span",
|
2106
2092
|
className: Vt,
|
2107
2093
|
innerText: `${h}`
|
2108
2094
|
}),
|
2109
2095
|
M
|
2110
|
-
), e.append(
|
2096
|
+
), e.append(P, L);
|
2111
2097
|
}
|
2112
|
-
i && c.includes(l) && (o.value = l), m(t,
|
2113
|
-
},
|
2114
|
-
componentLabels:
|
2115
|
-
colorLabels:
|
2098
|
+
i && c.includes(l) && (o.value = l), m(t, X, "-1");
|
2099
|
+
}, uo = "2.0.0-alpha10", Z = "color-picker", bo = `[data-function="${Z}"]`, ce = `.${Z}`, po = {
|
2100
|
+
componentLabels: Kt,
|
2101
|
+
colorLabels: it,
|
2116
2102
|
format: "rgb",
|
2117
2103
|
colorPresets: !1,
|
2118
2104
|
colorKeywords: !1
|
2119
|
-
}, { roundPart: k, nonColors: bt } = y,
|
2120
|
-
const e = t ?
|
2121
|
-
e(s,
|
2122
|
-
},
|
2123
|
-
const e = t ?
|
2124
|
-
e(o.controls,
|
2125
|
-
},
|
2126
|
-
|
2127
|
-
},
|
2128
|
-
o && ["bottom", "top"].forEach((t) =>
|
2105
|
+
}, { roundPart: k, nonColors: bt } = y, fo = (o) => Xe(o, Z), mo = (o) => new vo(o), he = (o, t) => {
|
2106
|
+
const e = t ? Bt : jt, { input: s, pickerToggle: r, menuToggle: n } = o;
|
2107
|
+
e(s, Re, o.showPicker), e(r, Et, o.togglePicker), n && e(n, Et, o.toggleMenu);
|
2108
|
+
}, He = (o, t) => {
|
2109
|
+
const e = t ? Bt : jt, { input: s, colorMenu: r, parent: n } = o, i = V(s), a = ro(i);
|
2110
|
+
e(o.controls, Fe, o.pointerDown), o.controlKnobs.forEach((l) => e(l, zt, o.handleKnobs)), e(a, Ve, o.handleScroll), e(a, Ke, o.update), [s, ...o.inputs].forEach((l) => e(l, Me, o.changeHandler)), r && (e(r, Et, o.menuClickHandler), e(r, zt, o.menuKeyHandler)), e(i, ue, o.pointerMove), e(i, Ie, o.pointerUp), e(n, Oe, o.handleFocusOut), e(i, De, o.handleDismiss);
|
2111
|
+
}, ge = (o) => {
|
2112
|
+
Ye(o.input, new CustomEvent("colorpicker.change"));
|
2113
|
+
}, Ne = (o) => {
|
2114
|
+
o && ["bottom", "top"].forEach((t) => O(o, t));
|
2129
2115
|
}, Ht = (o, t) => {
|
2130
|
-
const { colorPicker: e, colorMenu: s, menuToggle:
|
2131
|
-
T(i, "open") || q(i, "open"), l && (
|
2116
|
+
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;
|
2117
|
+
T(i, "open") || q(i, "open"), l && (O(l, "show"), Ne(l)), q(t, "bottom"), oo(t), q(t, "show"), a && o.update(), o.isOpen || (He(o, !0), o.updateDropdownPosition(), o.isOpen = !0, m(o.input, X, "0"), r && m(r, X, "0")), m(h, Nt, "true"), c && m(c, Nt, "false");
|
2132
2118
|
};
|
2133
|
-
class
|
2119
|
+
class vo {
|
2134
2120
|
// bring utils to staic
|
2135
2121
|
static Color = y;
|
2136
2122
|
static ColorPalette = It;
|
2137
|
-
static getInstance =
|
2138
|
-
static init =
|
2139
|
-
static selector =
|
2123
|
+
static getInstance = fo;
|
2124
|
+
static init = mo;
|
2125
|
+
static selector = bo;
|
2140
2126
|
// utils important for render
|
2141
2127
|
static roundPart = k;
|
2142
|
-
static setElementStyle =
|
2128
|
+
static setElementStyle = D;
|
2143
2129
|
static setAttribute = m;
|
2144
2130
|
static getBoundingClientRect = gt;
|
2145
|
-
static version =
|
2131
|
+
static version = uo;
|
2132
|
+
static colorNames = it;
|
2133
|
+
static colorPickerLabels = Kt;
|
2146
2134
|
id;
|
2147
2135
|
input;
|
2148
2136
|
color;
|
@@ -2151,7 +2139,7 @@ class ko {
|
|
2151
2139
|
dragElement;
|
2152
2140
|
isOpen = !1;
|
2153
2141
|
controlPositions;
|
2154
|
-
colorLabels =
|
2142
|
+
colorLabels = Yt(it.map((t) => [t, t]));
|
2155
2143
|
colorKeywords;
|
2156
2144
|
colorPresets;
|
2157
2145
|
componentLabels;
|
@@ -2171,43 +2159,41 @@ class ko {
|
|
2171
2159
|
* @param config instance options
|
2172
2160
|
*/
|
2173
2161
|
constructor(t, e) {
|
2174
|
-
const s =
|
2162
|
+
const s = z(t);
|
2175
2163
|
if (typeof t > "u")
|
2176
2164
|
throw new TypeError("ColorPicker target not specified.");
|
2177
|
-
if (
|
2165
|
+
if (B(t) && !s)
|
2178
2166
|
throw new TypeError(`ColorPicker target "${t}" cannot be found.`);
|
2179
2167
|
this.input = s;
|
2180
|
-
const
|
2181
|
-
if (!
|
2168
|
+
const r = fe(s, ce);
|
2169
|
+
if (!r)
|
2182
2170
|
throw new TypeError("ColorPicker requires a specific markup to work.");
|
2183
|
-
this.parent =
|
2171
|
+
this.parent = r, this.id = de(s, Z), this.dragElement = void 0, this.isOpen = !1, this.controlPositions = {
|
2184
2172
|
c1x: 0,
|
2185
2173
|
c1y: 0,
|
2186
2174
|
c2y: 0,
|
2187
2175
|
c3y: 0
|
2188
|
-
}, this.
|
2189
|
-
const { format:
|
2176
|
+
}, this.colorKeywords = !1, this.colorPresets = !1;
|
2177
|
+
const { format: n, componentLabels: i, colorLabels: a, colorKeywords: l, colorPresets: c } = eo(
|
2190
2178
|
s,
|
2191
|
-
|
2179
|
+
po,
|
2192
2180
|
e || {}
|
2193
2181
|
);
|
2194
|
-
let h =
|
2195
|
-
Lt(a) && a.length === 17 ? h = a :
|
2196
|
-
|
2197
|
-
})
|
2198
|
-
const b = V(i) && re(i) ? JSON.parse(i) : i;
|
2199
|
-
if (this.componentLabels = B({ ...He }, b), this.color = new y(s.value || "#fff", r), this.format = r, Lt(l) && l.length ? this.colorKeywords = l : V(l) && l.length && (this.colorKeywords = l.split(",").map((p) => p.trim())), Lt(c) && c.length)
|
2182
|
+
let h = it;
|
2183
|
+
Lt(a) && a.length === 17 ? h = a : B(a) && a.split(",").length === 17 && (h = a.split(",")), K(this.colorLabels, Yt(h.map((p, f) => [it[f], p])));
|
2184
|
+
const b = B(i) && ae(i) ? JSON.parse(i) : i;
|
2185
|
+
if (this.componentLabels = K({ ...Kt }, b), this.color = new y(s.value || "#fff", n), this.format = n, Lt(l) && l.length ? this.colorKeywords = l : B(l) && l.length && (this.colorKeywords = l.split(",").map((p) => p.trim())), Lt(c) && c.length)
|
2200
2186
|
this.colorPresets = c;
|
2201
|
-
else if (c &&
|
2187
|
+
else if (c && ae(c)) {
|
2202
2188
|
const { hue: p, hueSteps: f, lightSteps: w, saturation: $ } = JSON.parse(c);
|
2203
2189
|
this.colorPresets = new It(p, f, w, $);
|
2204
2190
|
} else
|
2205
|
-
|
2206
|
-
|
2207
|
-
const [u, d] =
|
2208
|
-
this.pickerToggle =
|
2209
|
-
const [g] =
|
2210
|
-
this.controls = g, this.controlKnobs = [...
|
2191
|
+
B(c) && (this.colorPresets = c.split(",").map((p) => p.trim()));
|
2192
|
+
go(this);
|
2193
|
+
const [u, d] = st("color-dropdown", r);
|
2194
|
+
this.pickerToggle = z(".picker-toggle", r), this.menuToggle = z(".menu-toggle", r), this.colorPicker = u, this.colorMenu = d, this.inputs = [...st("color-input", r)];
|
2195
|
+
const [g] = st("color-controls", r);
|
2196
|
+
this.controls = g, this.controlKnobs = [...st("knob", g)], this.visuals = [...st("visual-control", g)], this.update(), he(this, !0), ct.set(s, Z, this);
|
2211
2197
|
}
|
2212
2198
|
/** Returns the current colour value */
|
2213
2199
|
get value() {
|
@@ -2265,7 +2251,7 @@ class ko {
|
|
2265
2251
|
}
|
2266
2252
|
/** Returns the colour appearance, usually the closest colour name for the current value. */
|
2267
2253
|
get appearance() {
|
2268
|
-
const { colorLabels: t, hsl: e, hsv: s, format:
|
2254
|
+
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;
|
2269
2255
|
let h = "black";
|
2270
2256
|
if (l === 100 && a === 0)
|
2271
2257
|
h = t.white;
|
@@ -2273,20 +2259,20 @@ class ko {
|
|
2273
2259
|
h = t.black;
|
2274
2260
|
else if (a === 0)
|
2275
2261
|
h = t.grey;
|
2276
|
-
else if (
|
2262
|
+
else if (n < 15 || n >= 345)
|
2277
2263
|
h = t.red;
|
2278
|
-
else if (
|
2264
|
+
else if (n >= 15 && n < 45)
|
2279
2265
|
h = c > 80 && a > 80 ? t.orange : t.brown;
|
2280
|
-
else if (
|
2281
|
-
const b =
|
2266
|
+
else if (n >= 45 && n < 75) {
|
2267
|
+
const b = n > 46 && n < 54 && c < 80 && a > 90, u = n >= 54 && n < 75 && c < 80;
|
2282
2268
|
h = b ? t.gold : t.yellow, h = u ? t.olive : h;
|
2283
2269
|
} else
|
2284
|
-
|
2270
|
+
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);
|
2285
2271
|
return h;
|
2286
2272
|
}
|
2287
2273
|
/** Updates `ColorPicker` visuals. */
|
2288
2274
|
updateVisuals() {
|
2289
|
-
const { controlPositions: t, visuals: e } = this, [s,
|
2275
|
+
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, s: 1, l: 0.5 }).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({
|
2290
2276
|
h: a,
|
2291
2277
|
s: 1,
|
2292
2278
|
l: 0.5,
|
@@ -2296,11 +2282,11 @@ class ko {
|
|
2296
2282
|
rgb(0,255,0) 33.33%, rgb(0,255,255) 50%,
|
2297
2283
|
rgb(0,0,255) 66.67%, rgb(255,0,255) 83.33%,
|
2298
2284
|
rgb(255,0,0) 100%)`;
|
2299
|
-
|
2285
|
+
D(s, {
|
2300
2286
|
background: `linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,${d}) 100%),
|
2301
2287
|
linear-gradient(to right, rgba(255,255,255,${d}) 0%, ${g} 100%),
|
2302
2288
|
${b}`
|
2303
|
-
}),
|
2289
|
+
}), D(r, { background: p }), D(n, {
|
2304
2290
|
background: `linear-gradient(rgba(${l},${c},${h},1) 0%,rgba(${l},${c},${h},0) 100%)`
|
2305
2291
|
});
|
2306
2292
|
}
|
@@ -2310,120 +2296,121 @@ class ko {
|
|
2310
2296
|
* @param e
|
2311
2297
|
* @this {ColorPicker}
|
2312
2298
|
*/
|
2313
|
-
handleFocusOut({ relatedTarget: t }) {
|
2299
|
+
handleFocusOut = ({ relatedTarget: t }) => {
|
2314
2300
|
t && !this.parent.contains(t) && this.hide(!0);
|
2315
|
-
}
|
2301
|
+
};
|
2316
2302
|
/**
|
2317
2303
|
* The `ColorPicker` *keyup* event listener when open.
|
2318
2304
|
*
|
2319
2305
|
* @param e
|
2320
2306
|
* @this {ColorPicker}
|
2321
2307
|
*/
|
2322
|
-
handleDismiss({ code: t }) {
|
2323
|
-
this.isOpen && t ===
|
2324
|
-
}
|
2308
|
+
handleDismiss = ({ code: t }) => {
|
2309
|
+
this.isOpen && t === qe && this.hide();
|
2310
|
+
};
|
2325
2311
|
/**
|
2326
2312
|
* The `ColorPicker` *scroll* event listener when open.
|
2327
2313
|
*
|
2328
2314
|
* @param e
|
2329
|
-
* @this {ColorPicker}
|
2330
2315
|
*/
|
2331
|
-
handleScroll(t) {
|
2332
|
-
const { activeElement: e } =
|
2333
|
-
this.updateDropdownPosition(), ([ue,
|
2334
|
-
}
|
2316
|
+
handleScroll = (t) => {
|
2317
|
+
const { activeElement: e } = V(this.input);
|
2318
|
+
this.updateDropdownPosition(), ([ue, Be].includes(t.type) && this.dragElement || e && this.controlKnobs.includes(e)) && (t.stopPropagation(), t.preventDefault());
|
2319
|
+
};
|
2335
2320
|
/**
|
2336
2321
|
* The `ColorPicker` keyboard event listener for menu navigation.
|
2337
2322
|
*
|
2338
2323
|
* @param e
|
2339
2324
|
*/
|
2340
|
-
menuKeyHandler(t) {
|
2341
|
-
const { target: e, code: s } = t, { previousElementSibling:
|
2342
|
-
[j,
|
2343
|
-
}
|
2325
|
+
menuKeyHandler = (t) => {
|
2326
|
+
const { target: e, code: s } = t, { previousElementSibling: r, nextElementSibling: n, parentElement: i } = e, a = i && T(i, "color-options"), l = i ? [...i.children] : [], c = a && Tt(i, "grid-template-columns").split(" ").length, h = l.indexOf(e), b = h > -1 && c && l[h - c], u = h > -1 && c && l[h + c];
|
2327
|
+
[j, ot, Wt].includes(s) && t.preventDefault(), a ? b && s === ot ? _(b) : u && s === j ? _(u) : r && s === ht ? _(r) : n && s === U && _(n) : r && [ht, ot].includes(s) ? _(r) : n && [U, j].includes(s) && _(n), [je, Wt].includes(s) && this.menuClickHandler(t);
|
2328
|
+
};
|
2344
2329
|
/**
|
2345
2330
|
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
2346
2331
|
*
|
2347
2332
|
* @param e
|
2348
2333
|
* @this {ColorPicker}
|
2349
2334
|
*/
|
2350
|
-
menuClickHandler(t) {
|
2351
|
-
const { target: e } = t, { colorMenu: s } = this,
|
2352
|
-
if (!
|
2335
|
+
menuClickHandler = (t) => {
|
2336
|
+
const { target: e } = t, { colorMenu: s } = this, r = (yt(e, "data-value") || "").trim();
|
2337
|
+
if (!r.length)
|
2353
2338
|
return;
|
2354
|
-
const
|
2355
|
-
let i =
|
2339
|
+
const n = z("li.active", s);
|
2340
|
+
let i = r;
|
2356
2341
|
i = bt.includes(i) ? "white" : i, i = i === "transparent" ? "rgba(0,0,0,0)" : i;
|
2357
2342
|
const { r: a, g: l, b: c, a: h } = new y(i);
|
2358
|
-
|
2343
|
+
K(this.color, {
|
2359
2344
|
r: a,
|
2360
2345
|
g: l,
|
2361
2346
|
b: c,
|
2362
2347
|
a: h
|
2363
|
-
}), this.update(),
|
2364
|
-
}
|
2348
|
+
}), this.update(), n !== e && (n && (O(n, "active"), Pt(n, St)), q(e, "active"), m(e, St, "true"), bt.includes(r) && (this.value = r), ge(this));
|
2349
|
+
};
|
2365
2350
|
/**
|
2366
2351
|
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
2367
2352
|
*
|
2368
2353
|
* @param e
|
2369
2354
|
*/
|
2370
|
-
pointerDown(t) {
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2355
|
+
pointerDown = (t) => {
|
2356
|
+
if (t.button !== 0)
|
2357
|
+
return;
|
2358
|
+
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 = Ct(l), w = s - f.scrollLeft - p.left, $ = r - f.scrollTop - p.top;
|
2359
|
+
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) {
|
2360
|
+
const S = z("li.active", n);
|
2361
|
+
S && (O(S, "active"), Pt(S, St));
|
2375
2362
|
}
|
2376
2363
|
t.preventDefault();
|
2377
|
-
}
|
2364
|
+
};
|
2378
2365
|
/**
|
2379
2366
|
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
2380
2367
|
*
|
2381
2368
|
* @param e
|
2382
2369
|
* @this
|
2383
2370
|
*/
|
2384
|
-
pointerUp({ target: t }) {
|
2385
|
-
const { parent: e } = this, s =
|
2386
|
-
!this.dragElement && (!
|
2387
|
-
}
|
2371
|
+
pointerUp = ({ target: t }) => {
|
2372
|
+
const { parent: e } = this, s = V(e), r = z(`${ce}.open`, s) !== null, n = s.getSelection();
|
2373
|
+
!this.dragElement && (!n || !n.toString().length) && !e.contains(t) && this.hide(r), this.dragElement = void 0;
|
2374
|
+
};
|
2388
2375
|
/**
|
2389
2376
|
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
2390
2377
|
*
|
2391
2378
|
* @param {PointerEvent} e
|
2392
2379
|
*/
|
2393
|
-
pointerMove(t) {
|
2394
|
-
const { dragElement: e, visuals: s } = this, [
|
2380
|
+
pointerMove = (t) => {
|
2381
|
+
const { dragElement: e, visuals: s } = this, [r, n, i] = s, { pageX: a, pageY: l } = t;
|
2395
2382
|
if (!e)
|
2396
2383
|
return;
|
2397
|
-
const c = gt(e), h = Ct(
|
2398
|
-
e ===
|
2399
|
-
}
|
2384
|
+
const c = gt(e), h = Ct(r), b = a - h.scrollLeft - c.left, u = l - h.scrollTop - c.top;
|
2385
|
+
e === r && this.changeControl1(b, u), e === n && this.changeControl2(u), e === i && this.changeAlpha(u);
|
2386
|
+
};
|
2400
2387
|
/**
|
2401
2388
|
* The `ColorPicker` *keydown* event listener for control knobs.
|
2402
2389
|
*
|
2403
2390
|
* @param e
|
2404
2391
|
*/
|
2405
|
-
handleKnobs(t) {
|
2392
|
+
handleKnobs = (t) => {
|
2406
2393
|
const { target: e, code: s } = t;
|
2407
|
-
if (![
|
2394
|
+
if (![ot, j, ht, U].includes(s))
|
2408
2395
|
return;
|
2409
2396
|
t.preventDefault();
|
2410
|
-
const { controlKnobs:
|
2397
|
+
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;
|
2411
2398
|
if (u) {
|
2412
2399
|
let g = 0, p = 0;
|
2413
2400
|
if (e === l) {
|
2414
2401
|
const f = i / 100;
|
2415
|
-
[ht,
|
2402
|
+
[ht, U].includes(s) ? this.controlPositions.c1x += s === U ? f : -f : [ot, j].includes(s) && (this.controlPositions.c1y += s === j ? d : -d), g = this.controlPositions.c1x, p = this.controlPositions.c1y, this.changeControl1(g, p);
|
2416
2403
|
} else
|
2417
|
-
e === c ? (this.controlPositions.c2y += [j,
|
2404
|
+
e === c ? (this.controlPositions.c2y += [j, U].includes(s) ? d : -d, p = this.controlPositions.c2y, this.changeControl2(p)) : e === h && (this.controlPositions.c3y += [j, U].includes(s) ? d : -d, p = this.controlPositions.c3y, this.changeAlpha(p));
|
2418
2405
|
this.handleScroll(t);
|
2419
2406
|
}
|
2420
|
-
}
|
2407
|
+
};
|
2421
2408
|
/** The event listener of the colour form inputs. */
|
2422
|
-
changeHandler() {
|
2409
|
+
changeHandler = () => {
|
2423
2410
|
let t;
|
2424
|
-
const { inputs: e, format: s, value:
|
2425
|
-
if (l ===
|
2426
|
-
l ===
|
2411
|
+
const { inputs: e, format: s, value: r, input: n, controlPositions: i, visuals: a } = 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;
|
2412
|
+
if (l === n || l && e.includes(l)) {
|
2413
|
+
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 = {
|
2427
2414
|
h: u,
|
2428
2415
|
s: d,
|
2429
2416
|
l: g,
|
@@ -2439,15 +2426,15 @@ class ko {
|
|
2439
2426
|
b: g,
|
2440
2427
|
a: w
|
2441
2428
|
};
|
2442
|
-
const { r: $, g:
|
2443
|
-
|
2429
|
+
const { r: $, g: S, b: L, a: P } = new y(t);
|
2430
|
+
K(this.color, {
|
2444
2431
|
r: $,
|
2445
|
-
g:
|
2432
|
+
g: S,
|
2446
2433
|
b: L,
|
2447
|
-
a:
|
2448
|
-
}), this.setControlPositions(), this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals(), l ===
|
2434
|
+
a: P
|
2435
|
+
}), this.setControlPositions(), this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals(), l === n && f && (this.value = r);
|
2449
2436
|
}
|
2450
|
-
}
|
2437
|
+
};
|
2451
2438
|
/**
|
2452
2439
|
* Updates `ColorPicker` first control:
|
2453
2440
|
* * `lightness` and `saturation` for HEX/RGB;
|
@@ -2457,21 +2444,21 @@ class ko {
|
|
2457
2444
|
* @param Y the Y component of the offset
|
2458
2445
|
*/
|
2459
2446
|
changeControl1(t, e) {
|
2460
|
-
let [s,
|
2461
|
-
const { controlPositions:
|
2462
|
-
t > l ? s = l : t >= 0 && (s = t), e > a ?
|
2463
|
-
const c =
|
2447
|
+
let [s, r] = [0, 0];
|
2448
|
+
const { controlPositions: n, visuals: i } = this, { offsetHeight: a, offsetWidth: l } = i[0];
|
2449
|
+
t > l ? s = l : t >= 0 && (s = t), e > a ? r = a : e >= 0 && (r = e);
|
2450
|
+
const c = n.c2y / a, h = s / l, b = 1 - r / a, u = 1 - n.c3y / a, { r: d, g, b: p, a: f } = new y({
|
2464
2451
|
h: c,
|
2465
2452
|
s: h,
|
2466
2453
|
v: b,
|
2467
2454
|
a: u
|
2468
2455
|
});
|
2469
|
-
|
2456
|
+
K(this.color, {
|
2470
2457
|
r: d,
|
2471
2458
|
g,
|
2472
2459
|
b: p,
|
2473
2460
|
a: f
|
2474
|
-
}), this.controlPositions.c1x = s, this.controlPositions.c1y =
|
2461
|
+
}), this.controlPositions.c1x = s, this.controlPositions.c1y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2475
2462
|
}
|
2476
2463
|
/**
|
2477
2464
|
* Updates `ColorPicker` second control:
|
@@ -2481,16 +2468,16 @@ class ko {
|
|
2481
2468
|
* @param Y the Y offset
|
2482
2469
|
*/
|
2483
2470
|
changeControl2(t) {
|
2484
|
-
const { controlPositions: e, visuals: s } = this, { offsetHeight:
|
2471
|
+
const { controlPositions: e, visuals: s } = this, { offsetHeight: r, offsetWidth: n } = s[0];
|
2485
2472
|
let i = 0;
|
2486
|
-
t >
|
2487
|
-
const a = i /
|
2473
|
+
t > r ? i = r : t >= 0 && (i = t);
|
2474
|
+
const a = i / r, l = e.c1x / n, c = 1 - e.c1y / r, h = 1 - e.c3y / r, { r: b, g: u, b: d, a: g } = new y({
|
2488
2475
|
h: a,
|
2489
2476
|
s: l,
|
2490
2477
|
v: c,
|
2491
2478
|
a: h
|
2492
2479
|
});
|
2493
|
-
|
2480
|
+
K(this.color, {
|
2494
2481
|
r: b,
|
2495
2482
|
g: u,
|
2496
2483
|
b: d,
|
@@ -2505,56 +2492,56 @@ class ko {
|
|
2505
2492
|
*/
|
2506
2493
|
changeAlpha(t) {
|
2507
2494
|
const { visuals: e } = this, { offsetHeight: s } = e[0];
|
2508
|
-
let
|
2509
|
-
t > s ?
|
2510
|
-
const
|
2511
|
-
this.color.setAlpha(
|
2495
|
+
let r = 0;
|
2496
|
+
t > s ? r = s : t >= 0 && (r = t);
|
2497
|
+
const n = 1 - r / s;
|
2498
|
+
this.color.setAlpha(n), this.controlPositions.c3y = r, this.updateAppearance(), this.updateInputs(), this.updateControls(), this.updateVisuals();
|
2512
2499
|
}
|
2513
2500
|
/**
|
2514
2501
|
* Updates `ColorPicker` control positions on:
|
2515
2502
|
* * initialization
|
2516
2503
|
* * window resize
|
2517
2504
|
*/
|
2518
|
-
update() {
|
2505
|
+
update = () => {
|
2519
2506
|
this.updateDropdownPosition(), this.updateAppearance(), this.setControlPositions(), this.updateInputs(!0), this.updateControls(), this.updateVisuals();
|
2520
|
-
}
|
2507
|
+
};
|
2521
2508
|
/** Updates the open dropdown position on *scroll* event. */
|
2522
2509
|
updateDropdownPosition() {
|
2523
|
-
const { input: t, colorPicker: e, colorMenu: s } = this,
|
2510
|
+
const { input: t, colorPicker: e, colorMenu: s } = this, r = gt(t), { top: n, bottom: i } = r, { offsetHeight: a } = t, l = Ct(t).clientHeight, h = T(e, "show") ? e : s;
|
2524
2511
|
if (!h)
|
2525
2512
|
return;
|
2526
|
-
const { offsetHeight: b } = h, u = l - i, d =
|
2527
|
-
(T(h, "bottom") || !p) && u < d && g ? (
|
2513
|
+
const { offsetHeight: b } = h, u = l - i, d = n, g = n + b + a > l, p = n - b < 0;
|
2514
|
+
(T(h, "bottom") || !p) && u < d && g ? (O(h, "bottom"), q(h, "top")) : (O(h, "top"), q(h, "bottom"));
|
2528
2515
|
}
|
2529
2516
|
/** Updates control knobs' positions. */
|
2530
2517
|
setControlPositions() {
|
2531
|
-
const { visuals: t, color: e, hsv: s } = this, { offsetHeight:
|
2532
|
-
this.controlPositions.c1x = l *
|
2518
|
+
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;
|
2519
|
+
this.controlPositions.c1x = l * n, this.controlPositions.c1y = (1 - c) * r, this.controlPositions.c2y = a * r, this.controlPositions.c3y = (1 - i) * r;
|
2533
2520
|
}
|
2534
2521
|
/** Update the visual appearance label and control knob labels. */
|
2535
2522
|
updateAppearance() {
|
2536
|
-
const { componentLabels: t, color: e, parent: s, hsv:
|
2523
|
+
const { componentLabels: t, color: e, parent: s, hsv: r, hex: n, format: i, controlKnobs: a } = this, { appearanceLabel: l, hexLabel: c, valueLabel: h } = t;
|
2537
2524
|
let { r: b, g: u, b: d } = e.toRgb();
|
2538
|
-
const [g, p, f] = a, w = k(
|
2539
|
-
let C = `${c} ${
|
2525
|
+
const [g, p, f] = a, w = k(r.h * 360), $ = e.a, S = k(r.s * 100), L = k(r.v * 100), P = this.appearance;
|
2526
|
+
let C = `${c} ${n.split("").join(" ")}`;
|
2540
2527
|
if (i === "hwb") {
|
2541
|
-
const { hwb: A } = this, F = k(A.w * 100),
|
2542
|
-
C = `HWB: ${w}°, ${F}%, ${
|
2528
|
+
const { hwb: A } = this, F = k(A.w * 100), Q = k(A.b * 100);
|
2529
|
+
C = `HWB: ${w}°, ${F}%, ${Q}%`, m(g, et, `${F}% & ${Q}%`), m(g, tt, `${F}`), m(p, _t, `${h}: ${C}. ${l}: ${P}.`), m(p, et, `${w}%`), m(p, tt, `${w}`);
|
2543
2530
|
} else
|
2544
|
-
[b, u, d] = [b, u, d].map(k), C = i === "hsl" ? `HSL: ${w}°, ${
|
2531
|
+
[b, u, d] = [b, u, d].map(k), C = i === "hsl" ? `HSL: ${w}°, ${S}%, ${L}%` : C, C = i === "rgb" ? `RGB: ${b}, ${u}, ${d}` : C, m(g, et, `${L}% & ${S}%`), m(g, tt, `${L}`), m(p, _t, `${h}: ${C}. ${l}: ${P}.`), m(p, et, `${w}°`), m(p, tt, `${w}`);
|
2545
2532
|
const M = k($ * 100);
|
2546
|
-
m(f,
|
2533
|
+
m(f, et, `${M}%`), m(f, tt, `${M}`);
|
2547
2534
|
const E = e.toString();
|
2548
|
-
|
2535
|
+
D(this.input, { backgroundColor: E }), this.isDark ? (T(s, "txt-light") && O(s, "txt-light"), T(s, "txt-dark") || q(s, "txt-dark")) : (T(s, "txt-dark") && O(s, "txt-dark"), T(s, "txt-light") || q(s, "txt-light"));
|
2549
2536
|
}
|
2550
2537
|
/** Updates the control knobs actual positions. */
|
2551
2538
|
updateControls() {
|
2552
2539
|
const { controlKnobs: t, controlPositions: e } = this;
|
2553
|
-
let { c1x: s, c1y:
|
2540
|
+
let { c1x: s, c1y: r, c2y: n, c3y: i } = e;
|
2554
2541
|
const [a, l, c] = t;
|
2555
|
-
[s,
|
2556
|
-
transform: `translate3d(${s - 4}px,${
|
2557
|
-
}),
|
2542
|
+
[s, r, n, i] = [s, r, n, i].map(k), D(a, {
|
2543
|
+
transform: `translate3d(${s - 4}px,${r - 4}px,0)`
|
2544
|
+
}), D(l, { transform: `translate3d(0,${n - 4}px,0)` }), D(c, { transform: `translate3d(0,${i - 4}px,0)` });
|
2558
2545
|
}
|
2559
2546
|
/**
|
2560
2547
|
* Updates all color form inputs.
|
@@ -2562,8 +2549,8 @@ class ko {
|
|
2562
2549
|
* @param isPrevented when `true`, the component original event is prevented
|
2563
2550
|
*/
|
2564
2551
|
updateInputs(t) {
|
2565
|
-
const { value: e, format: s, inputs:
|
2566
|
-
let d =
|
2552
|
+
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);
|
2553
|
+
let d = n.toString();
|
2567
2554
|
if (s === "hex")
|
2568
2555
|
d = this.color.toHexString(!0), a.value = this.hex;
|
2569
2556
|
else if (s === "hsl") {
|
@@ -2576,34 +2563,34 @@ class ko {
|
|
2576
2563
|
let { r: g, g: p, b: f } = this.rgb;
|
2577
2564
|
[g, p, f] = [g, p, f].map(k), d = this.color.toRgbString(), a.value = `${g}`, l.value = `${p}`, c.value = `${f}`, h.value = `${b}`;
|
2578
2565
|
}
|
2579
|
-
this.value = d, !t && d !== e &&
|
2566
|
+
this.value = d, !t && d !== e && ge(this);
|
2580
2567
|
}
|
2581
2568
|
/**
|
2582
2569
|
* Toggle the `ColorPicker` dropdown visibility.
|
2583
2570
|
*
|
2584
2571
|
* @param e
|
2585
2572
|
*/
|
2586
|
-
togglePicker(t) {
|
2573
|
+
togglePicker = (t) => {
|
2587
2574
|
t && t.preventDefault();
|
2588
2575
|
const { colorPicker: e } = this;
|
2589
2576
|
this.isOpen && T(e, "show") ? this.hide(!0) : Ht(this, e);
|
2590
|
-
}
|
2577
|
+
};
|
2591
2578
|
/** Shows the `ColorPicker` dropdown. */
|
2592
|
-
showPicker() {
|
2579
|
+
showPicker = () => {
|
2593
2580
|
const { colorPicker: t } = this;
|
2594
2581
|
["top", "bottom"].some((e) => T(t, e)) || Ht(this, t);
|
2595
|
-
}
|
2582
|
+
};
|
2596
2583
|
/**
|
2597
2584
|
* Toggles the visibility of the `ColorPicker` presets menu.
|
2598
2585
|
*
|
2599
2586
|
* @param e
|
2600
2587
|
* @this {ColorPicker}
|
2601
2588
|
*/
|
2602
|
-
toggleMenu(t) {
|
2589
|
+
toggleMenu = (t) => {
|
2603
2590
|
t && t.preventDefault();
|
2604
2591
|
const { colorMenu: e } = this;
|
2605
2592
|
this.isOpen && T(e, "show") ? this.hide(!0) : Ht(this, e);
|
2606
|
-
}
|
2593
|
+
};
|
2607
2594
|
/**
|
2608
2595
|
* Hides the currently open `ColorPicker` dropdown.
|
2609
2596
|
*
|
@@ -2611,21 +2598,21 @@ class ko {
|
|
2611
2598
|
*/
|
2612
2599
|
hide(t) {
|
2613
2600
|
if (this.isOpen) {
|
2614
|
-
const { pickerToggle: e, menuToggle: s, colorPicker:
|
2615
|
-
this.value = this.color.toString(!0), c && (
|
2616
|
-
|
2617
|
-
}, b)), t ||
|
2601
|
+
const { pickerToggle: e, menuToggle: s, colorPicker: r, colorMenu: n, parent: i, input: a } = this, l = T(r, "show"), c = l ? r : n, h = l ? e : s, b = c && Qe(c);
|
2602
|
+
this.value = this.color.toString(!0), c && (O(c, "show"), m(h, Nt, "false"), setTimeout(() => {
|
2603
|
+
Ne(c), z(".show", i) || (O(i, "open"), He(this), this.isOpen = !1);
|
2604
|
+
}, b)), t || _(e), m(a, X, "-1"), h === s && m(s, X, "-1");
|
2618
2605
|
}
|
2619
2606
|
}
|
2620
2607
|
/** Removes `ColorPicker` from target `<input>`. */
|
2621
2608
|
dispose() {
|
2622
2609
|
const { input: t, parent: e } = this;
|
2623
|
-
this.hide(!0),
|
2610
|
+
this.hide(!0), he(this), [...e.children].forEach((s) => {
|
2624
2611
|
s !== t && s.remove();
|
2625
|
-
}),
|
2612
|
+
}), Pt(t, X), D(t, { backgroundColor: "" }), ["txt-light", "txt-dark"].forEach((s) => O(e, s)), ct.remove(t, Z);
|
2626
2613
|
}
|
2627
2614
|
}
|
2628
2615
|
export {
|
2629
|
-
|
2616
|
+
vo as default
|
2630
2617
|
};
|
2631
2618
|
//# sourceMappingURL=color-picker.mjs.map
|