1 | import {
|
2 | drag
|
3 | } from "./chunk.OP5OBLMF.js";
|
4 | import {
|
5 | clamp
|
6 | } from "./chunk.43G6GBOK.js";
|
7 | import {
|
8 | i as i2
|
9 | } from "./chunk.2N4FHWVW.js";
|
10 | import {
|
11 | color_picker_styles_default
|
12 | } from "./chunk.RYPXSMWJ.js";
|
13 | import {
|
14 | l as l2
|
15 | } from "./chunk.R5Z37LZL.js";
|
16 | import {
|
17 | defaultValue
|
18 | } from "./chunk.XM2NSF2I.js";
|
19 | import {
|
20 | FormSubmitController
|
21 | } from "./chunk.67FQMIF5.js";
|
22 | import {
|
23 | LocalizeController
|
24 | } from "./chunk.6WMYSCDC.js";
|
25 | import {
|
26 | o
|
27 | } from "./chunk.IAELDRGJ.js";
|
28 | import {
|
29 | l
|
30 | } from "./chunk.7MO772SN.js";
|
31 | import {
|
32 | watch
|
33 | } from "./chunk.W6MGCO4G.js";
|
34 | import {
|
35 | emit
|
36 | } from "./chunk.UY5AQKHP.js";
|
37 | import {
|
38 | e,
|
39 | i,
|
40 | n,
|
41 | t
|
42 | } from "./chunk.VKNZYXSO.js";
|
43 | import {
|
44 | $,
|
45 | s
|
46 | } from "./chunk.WWAD5WF4.js";
|
47 | import {
|
48 | __commonJS,
|
49 | __decorateClass,
|
50 | __toESM
|
51 | } from "./chunk.K2NRSETB.js";
|
52 |
|
53 |
|
54 | var require_color_name = __commonJS({
|
55 | "node_modules/color-name/index.js"(exports, module) {
|
56 | "use strict";
|
57 | module.exports = {
|
58 | "aliceblue": [240, 248, 255],
|
59 | "antiquewhite": [250, 235, 215],
|
60 | "aqua": [0, 255, 255],
|
61 | "aquamarine": [127, 255, 212],
|
62 | "azure": [240, 255, 255],
|
63 | "beige": [245, 245, 220],
|
64 | "bisque": [255, 228, 196],
|
65 | "black": [0, 0, 0],
|
66 | "blanchedalmond": [255, 235, 205],
|
67 | "blue": [0, 0, 255],
|
68 | "blueviolet": [138, 43, 226],
|
69 | "brown": [165, 42, 42],
|
70 | "burlywood": [222, 184, 135],
|
71 | "cadetblue": [95, 158, 160],
|
72 | "chartreuse": [127, 255, 0],
|
73 | "chocolate": [210, 105, 30],
|
74 | "coral": [255, 127, 80],
|
75 | "cornflowerblue": [100, 149, 237],
|
76 | "cornsilk": [255, 248, 220],
|
77 | "crimson": [220, 20, 60],
|
78 | "cyan": [0, 255, 255],
|
79 | "darkblue": [0, 0, 139],
|
80 | "darkcyan": [0, 139, 139],
|
81 | "darkgoldenrod": [184, 134, 11],
|
82 | "darkgray": [169, 169, 169],
|
83 | "darkgreen": [0, 100, 0],
|
84 | "darkgrey": [169, 169, 169],
|
85 | "darkkhaki": [189, 183, 107],
|
86 | "darkmagenta": [139, 0, 139],
|
87 | "darkolivegreen": [85, 107, 47],
|
88 | "darkorange": [255, 140, 0],
|
89 | "darkorchid": [153, 50, 204],
|
90 | "darkred": [139, 0, 0],
|
91 | "darksalmon": [233, 150, 122],
|
92 | "darkseagreen": [143, 188, 143],
|
93 | "darkslateblue": [72, 61, 139],
|
94 | "darkslategray": [47, 79, 79],
|
95 | "darkslategrey": [47, 79, 79],
|
96 | "darkturquoise": [0, 206, 209],
|
97 | "darkviolet": [148, 0, 211],
|
98 | "deeppink": [255, 20, 147],
|
99 | "deepskyblue": [0, 191, 255],
|
100 | "dimgray": [105, 105, 105],
|
101 | "dimgrey": [105, 105, 105],
|
102 | "dodgerblue": [30, 144, 255],
|
103 | "firebrick": [178, 34, 34],
|
104 | "floralwhite": [255, 250, 240],
|
105 | "forestgreen": [34, 139, 34],
|
106 | "fuchsia": [255, 0, 255],
|
107 | "gainsboro": [220, 220, 220],
|
108 | "ghostwhite": [248, 248, 255],
|
109 | "gold": [255, 215, 0],
|
110 | "goldenrod": [218, 165, 32],
|
111 | "gray": [128, 128, 128],
|
112 | "green": [0, 128, 0],
|
113 | "greenyellow": [173, 255, 47],
|
114 | "grey": [128, 128, 128],
|
115 | "honeydew": [240, 255, 240],
|
116 | "hotpink": [255, 105, 180],
|
117 | "indianred": [205, 92, 92],
|
118 | "indigo": [75, 0, 130],
|
119 | "ivory": [255, 255, 240],
|
120 | "khaki": [240, 230, 140],
|
121 | "lavender": [230, 230, 250],
|
122 | "lavenderblush": [255, 240, 245],
|
123 | "lawngreen": [124, 252, 0],
|
124 | "lemonchiffon": [255, 250, 205],
|
125 | "lightblue": [173, 216, 230],
|
126 | "lightcoral": [240, 128, 128],
|
127 | "lightcyan": [224, 255, 255],
|
128 | "lightgoldenrodyellow": [250, 250, 210],
|
129 | "lightgray": [211, 211, 211],
|
130 | "lightgreen": [144, 238, 144],
|
131 | "lightgrey": [211, 211, 211],
|
132 | "lightpink": [255, 182, 193],
|
133 | "lightsalmon": [255, 160, 122],
|
134 | "lightseagreen": [32, 178, 170],
|
135 | "lightskyblue": [135, 206, 250],
|
136 | "lightslategray": [119, 136, 153],
|
137 | "lightslategrey": [119, 136, 153],
|
138 | "lightsteelblue": [176, 196, 222],
|
139 | "lightyellow": [255, 255, 224],
|
140 | "lime": [0, 255, 0],
|
141 | "limegreen": [50, 205, 50],
|
142 | "linen": [250, 240, 230],
|
143 | "magenta": [255, 0, 255],
|
144 | "maroon": [128, 0, 0],
|
145 | "mediumaquamarine": [102, 205, 170],
|
146 | "mediumblue": [0, 0, 205],
|
147 | "mediumorchid": [186, 85, 211],
|
148 | "mediumpurple": [147, 112, 219],
|
149 | "mediumseagreen": [60, 179, 113],
|
150 | "mediumslateblue": [123, 104, 238],
|
151 | "mediumspringgreen": [0, 250, 154],
|
152 | "mediumturquoise": [72, 209, 204],
|
153 | "mediumvioletred": [199, 21, 133],
|
154 | "midnightblue": [25, 25, 112],
|
155 | "mintcream": [245, 255, 250],
|
156 | "mistyrose": [255, 228, 225],
|
157 | "moccasin": [255, 228, 181],
|
158 | "navajowhite": [255, 222, 173],
|
159 | "navy": [0, 0, 128],
|
160 | "oldlace": [253, 245, 230],
|
161 | "olive": [128, 128, 0],
|
162 | "olivedrab": [107, 142, 35],
|
163 | "orange": [255, 165, 0],
|
164 | "orangered": [255, 69, 0],
|
165 | "orchid": [218, 112, 214],
|
166 | "palegoldenrod": [238, 232, 170],
|
167 | "palegreen": [152, 251, 152],
|
168 | "paleturquoise": [175, 238, 238],
|
169 | "palevioletred": [219, 112, 147],
|
170 | "papayawhip": [255, 239, 213],
|
171 | "peachpuff": [255, 218, 185],
|
172 | "peru": [205, 133, 63],
|
173 | "pink": [255, 192, 203],
|
174 | "plum": [221, 160, 221],
|
175 | "powderblue": [176, 224, 230],
|
176 | "purple": [128, 0, 128],
|
177 | "rebeccapurple": [102, 51, 153],
|
178 | "red": [255, 0, 0],
|
179 | "rosybrown": [188, 143, 143],
|
180 | "royalblue": [65, 105, 225],
|
181 | "saddlebrown": [139, 69, 19],
|
182 | "salmon": [250, 128, 114],
|
183 | "sandybrown": [244, 164, 96],
|
184 | "seagreen": [46, 139, 87],
|
185 | "seashell": [255, 245, 238],
|
186 | "sienna": [160, 82, 45],
|
187 | "silver": [192, 192, 192],
|
188 | "skyblue": [135, 206, 235],
|
189 | "slateblue": [106, 90, 205],
|
190 | "slategray": [112, 128, 144],
|
191 | "slategrey": [112, 128, 144],
|
192 | "snow": [255, 250, 250],
|
193 | "springgreen": [0, 255, 127],
|
194 | "steelblue": [70, 130, 180],
|
195 | "tan": [210, 180, 140],
|
196 | "teal": [0, 128, 128],
|
197 | "thistle": [216, 191, 216],
|
198 | "tomato": [255, 99, 71],
|
199 | "turquoise": [64, 224, 208],
|
200 | "violet": [238, 130, 238],
|
201 | "wheat": [245, 222, 179],
|
202 | "white": [255, 255, 255],
|
203 | "whitesmoke": [245, 245, 245],
|
204 | "yellow": [255, 255, 0],
|
205 | "yellowgreen": [154, 205, 50]
|
206 | };
|
207 | }
|
208 | });
|
209 |
|
210 |
|
211 | var require_is_arrayish = __commonJS({
|
212 | "node_modules/simple-swizzle/node_modules/is-arrayish/index.js"(exports, module) {
|
213 | module.exports = function isArrayish(obj) {
|
214 | if (!obj || typeof obj === "string") {
|
215 | return false;
|
216 | }
|
217 | return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && (obj.splice instanceof Function || Object.getOwnPropertyDescriptor(obj, obj.length - 1) && obj.constructor.name !== "String");
|
218 | };
|
219 | }
|
220 | });
|
221 |
|
222 |
|
223 | var require_simple_swizzle = __commonJS({
|
224 | "node_modules/simple-swizzle/index.js"(exports, module) {
|
225 | "use strict";
|
226 | var isArrayish = require_is_arrayish();
|
227 | var concat = Array.prototype.concat;
|
228 | var slice = Array.prototype.slice;
|
229 | var swizzle = module.exports = function swizzle2(args) {
|
230 | var results = [];
|
231 | for (var i3 = 0, len = args.length; i3 < len; i3++) {
|
232 | var arg = args[i3];
|
233 | if (isArrayish(arg)) {
|
234 | results = concat.call(results, slice.call(arg));
|
235 | } else {
|
236 | results.push(arg);
|
237 | }
|
238 | }
|
239 | return results;
|
240 | };
|
241 | swizzle.wrap = function(fn) {
|
242 | return function() {
|
243 | return fn(swizzle(arguments));
|
244 | };
|
245 | };
|
246 | }
|
247 | });
|
248 |
|
249 |
|
250 | var require_color_string = __commonJS({
|
251 | "node_modules/color-string/index.js"(exports, module) {
|
252 | var colorNames = require_color_name();
|
253 | var swizzle = require_simple_swizzle();
|
254 | var hasOwnProperty = Object.hasOwnProperty;
|
255 | var reverseNames = {};
|
256 | for (name in colorNames) {
|
257 | if (hasOwnProperty.call(colorNames, name)) {
|
258 | reverseNames[colorNames[name]] = name;
|
259 | }
|
260 | }
|
261 | var name;
|
262 | var cs = module.exports = {
|
263 | to: {},
|
264 | get: {}
|
265 | };
|
266 | cs.get = function(string) {
|
267 | var prefix = string.substring(0, 3).toLowerCase();
|
268 | var val;
|
269 | var model;
|
270 | switch (prefix) {
|
271 | case "hsl":
|
272 | val = cs.get.hsl(string);
|
273 | model = "hsl";
|
274 | break;
|
275 | case "hwb":
|
276 | val = cs.get.hwb(string);
|
277 | model = "hwb";
|
278 | break;
|
279 | default:
|
280 | val = cs.get.rgb(string);
|
281 | model = "rgb";
|
282 | break;
|
283 | }
|
284 | if (!val) {
|
285 | return null;
|
286 | }
|
287 | return { model, value: val };
|
288 | };
|
289 | cs.get.rgb = function(string) {
|
290 | if (!string) {
|
291 | return null;
|
292 | }
|
293 | var abbr = /^#([a-f0-9]{3,4})$/i;
|
294 | var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
295 | var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
296 | var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
297 | var keyword = /^(\w+)$/;
|
298 | var rgb = [0, 0, 0, 1];
|
299 | var match;
|
300 | var i3;
|
301 | var hexAlpha;
|
302 | if (match = string.match(hex)) {
|
303 | hexAlpha = match[2];
|
304 | match = match[1];
|
305 | for (i3 = 0; i3 < 3; i3++) {
|
306 | var i22 = i3 * 2;
|
307 | rgb[i3] = parseInt(match.slice(i22, i22 + 2), 16);
|
308 | }
|
309 | if (hexAlpha) {
|
310 | rgb[3] = parseInt(hexAlpha, 16) / 255;
|
311 | }
|
312 | } else if (match = string.match(abbr)) {
|
313 | match = match[1];
|
314 | hexAlpha = match[3];
|
315 | for (i3 = 0; i3 < 3; i3++) {
|
316 | rgb[i3] = parseInt(match[i3] + match[i3], 16);
|
317 | }
|
318 | if (hexAlpha) {
|
319 | rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
320 | }
|
321 | } else if (match = string.match(rgba)) {
|
322 | for (i3 = 0; i3 < 3; i3++) {
|
323 | rgb[i3] = parseInt(match[i3 + 1], 0);
|
324 | }
|
325 | if (match[4]) {
|
326 | if (match[5]) {
|
327 | rgb[3] = parseFloat(match[4]) * 0.01;
|
328 | } else {
|
329 | rgb[3] = parseFloat(match[4]);
|
330 | }
|
331 | }
|
332 | } else if (match = string.match(per)) {
|
333 | for (i3 = 0; i3 < 3; i3++) {
|
334 | rgb[i3] = Math.round(parseFloat(match[i3 + 1]) * 2.55);
|
335 | }
|
336 | if (match[4]) {
|
337 | if (match[5]) {
|
338 | rgb[3] = parseFloat(match[4]) * 0.01;
|
339 | } else {
|
340 | rgb[3] = parseFloat(match[4]);
|
341 | }
|
342 | }
|
343 | } else if (match = string.match(keyword)) {
|
344 | if (match[1] === "transparent") {
|
345 | return [0, 0, 0, 0];
|
346 | }
|
347 | if (!hasOwnProperty.call(colorNames, match[1])) {
|
348 | return null;
|
349 | }
|
350 | rgb = colorNames[match[1]];
|
351 | rgb[3] = 1;
|
352 | return rgb;
|
353 | } else {
|
354 | return null;
|
355 | }
|
356 | for (i3 = 0; i3 < 3; i3++) {
|
357 | rgb[i3] = clamp2(rgb[i3], 0, 255);
|
358 | }
|
359 | rgb[3] = clamp2(rgb[3], 0, 1);
|
360 | return rgb;
|
361 | };
|
362 | cs.get.hsl = function(string) {
|
363 | if (!string) {
|
364 | return null;
|
365 | }
|
366 | var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
367 | var match = string.match(hsl);
|
368 | if (match) {
|
369 | var alpha = parseFloat(match[4]);
|
370 | var h = (parseFloat(match[1]) % 360 + 360) % 360;
|
371 | var s2 = clamp2(parseFloat(match[2]), 0, 100);
|
372 | var l3 = clamp2(parseFloat(match[3]), 0, 100);
|
373 | var a = clamp2(isNaN(alpha) ? 1 : alpha, 0, 1);
|
374 | return [h, s2, l3, a];
|
375 | }
|
376 | return null;
|
377 | };
|
378 | cs.get.hwb = function(string) {
|
379 | if (!string) {
|
380 | return null;
|
381 | }
|
382 | var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
383 | var match = string.match(hwb);
|
384 | if (match) {
|
385 | var alpha = parseFloat(match[4]);
|
386 | var h = (parseFloat(match[1]) % 360 + 360) % 360;
|
387 | var w = clamp2(parseFloat(match[2]), 0, 100);
|
388 | var b = clamp2(parseFloat(match[3]), 0, 100);
|
389 | var a = clamp2(isNaN(alpha) ? 1 : alpha, 0, 1);
|
390 | return [h, w, b, a];
|
391 | }
|
392 | return null;
|
393 | };
|
394 | cs.to.hex = function() {
|
395 | var rgba = swizzle(arguments);
|
396 | return "#" + hexDouble(rgba[0]) + hexDouble(rgba[1]) + hexDouble(rgba[2]) + (rgba[3] < 1 ? hexDouble(Math.round(rgba[3] * 255)) : "");
|
397 | };
|
398 | cs.to.rgb = function() {
|
399 | var rgba = swizzle(arguments);
|
400 | return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ")" : "rgba(" + Math.round(rgba[0]) + ", " + Math.round(rgba[1]) + ", " + Math.round(rgba[2]) + ", " + rgba[3] + ")";
|
401 | };
|
402 | cs.to.rgb.percent = function() {
|
403 | var rgba = swizzle(arguments);
|
404 | var r = Math.round(rgba[0] / 255 * 100);
|
405 | var g = Math.round(rgba[1] / 255 * 100);
|
406 | var b = Math.round(rgba[2] / 255 * 100);
|
407 | return rgba.length < 4 || rgba[3] === 1 ? "rgb(" + r + "%, " + g + "%, " + b + "%)" : "rgba(" + r + "%, " + g + "%, " + b + "%, " + rgba[3] + ")";
|
408 | };
|
409 | cs.to.hsl = function() {
|
410 | var hsla = swizzle(arguments);
|
411 | return hsla.length < 4 || hsla[3] === 1 ? "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)" : "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
|
412 | };
|
413 | cs.to.hwb = function() {
|
414 | var hwba = swizzle(arguments);
|
415 | var a = "";
|
416 | if (hwba.length >= 4 && hwba[3] !== 1) {
|
417 | a = ", " + hwba[3];
|
418 | }
|
419 | return "hwb(" + hwba[0] + ", " + hwba[1] + "%, " + hwba[2] + "%" + a + ")";
|
420 | };
|
421 | cs.to.keyword = function(rgb) {
|
422 | return reverseNames[rgb.slice(0, 3)];
|
423 | };
|
424 | function clamp2(num, min, max) {
|
425 | return Math.min(Math.max(min, num), max);
|
426 | }
|
427 | function hexDouble(num) {
|
428 | var str = Math.round(num).toString(16).toUpperCase();
|
429 | return str.length < 2 ? "0" + str : str;
|
430 | }
|
431 | }
|
432 | });
|
433 |
|
434 |
|
435 | var require_conversions = __commonJS({
|
436 | "node_modules/color-convert/conversions.js"(exports, module) {
|
437 | var cssKeywords = require_color_name();
|
438 | var reverseKeywords = {};
|
439 | for (const key of Object.keys(cssKeywords)) {
|
440 | reverseKeywords[cssKeywords[key]] = key;
|
441 | }
|
442 | var convert = {
|
443 | rgb: { channels: 3, labels: "rgb" },
|
444 | hsl: { channels: 3, labels: "hsl" },
|
445 | hsv: { channels: 3, labels: "hsv" },
|
446 | hwb: { channels: 3, labels: "hwb" },
|
447 | cmyk: { channels: 4, labels: "cmyk" },
|
448 | xyz: { channels: 3, labels: "xyz" },
|
449 | lab: { channels: 3, labels: "lab" },
|
450 | lch: { channels: 3, labels: "lch" },
|
451 | hex: { channels: 1, labels: ["hex"] },
|
452 | keyword: { channels: 1, labels: ["keyword"] },
|
453 | ansi16: { channels: 1, labels: ["ansi16"] },
|
454 | ansi256: { channels: 1, labels: ["ansi256"] },
|
455 | hcg: { channels: 3, labels: ["h", "c", "g"] },
|
456 | apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
457 | gray: { channels: 1, labels: ["gray"] }
|
458 | };
|
459 | module.exports = convert;
|
460 | for (const model of Object.keys(convert)) {
|
461 | if (!("channels" in convert[model])) {
|
462 | throw new Error("missing channels property: " + model);
|
463 | }
|
464 | if (!("labels" in convert[model])) {
|
465 | throw new Error("missing channel labels property: " + model);
|
466 | }
|
467 | if (convert[model].labels.length !== convert[model].channels) {
|
468 | throw new Error("channel and label counts mismatch: " + model);
|
469 | }
|
470 | const { channels, labels } = convert[model];
|
471 | delete convert[model].channels;
|
472 | delete convert[model].labels;
|
473 | Object.defineProperty(convert[model], "channels", { value: channels });
|
474 | Object.defineProperty(convert[model], "labels", { value: labels });
|
475 | }
|
476 | convert.rgb.hsl = function(rgb) {
|
477 | const r = rgb[0] / 255;
|
478 | const g = rgb[1] / 255;
|
479 | const b = rgb[2] / 255;
|
480 | const min = Math.min(r, g, b);
|
481 | const max = Math.max(r, g, b);
|
482 | const delta = max - min;
|
483 | let h;
|
484 | let s2;
|
485 | if (max === min) {
|
486 | h = 0;
|
487 | } else if (r === max) {
|
488 | h = (g - b) / delta;
|
489 | } else if (g === max) {
|
490 | h = 2 + (b - r) / delta;
|
491 | } else if (b === max) {
|
492 | h = 4 + (r - g) / delta;
|
493 | }
|
494 | h = Math.min(h * 60, 360);
|
495 | if (h < 0) {
|
496 | h += 360;
|
497 | }
|
498 | const l3 = (min + max) / 2;
|
499 | if (max === min) {
|
500 | s2 = 0;
|
501 | } else if (l3 <= 0.5) {
|
502 | s2 = delta / (max + min);
|
503 | } else {
|
504 | s2 = delta / (2 - max - min);
|
505 | }
|
506 | return [h, s2 * 100, l3 * 100];
|
507 | };
|
508 | convert.rgb.hsv = function(rgb) {
|
509 | let rdif;
|
510 | let gdif;
|
511 | let bdif;
|
512 | let h;
|
513 | let s2;
|
514 | const r = rgb[0] / 255;
|
515 | const g = rgb[1] / 255;
|
516 | const b = rgb[2] / 255;
|
517 | const v = Math.max(r, g, b);
|
518 | const diff = v - Math.min(r, g, b);
|
519 | const diffc = function(c) {
|
520 | return (v - c) / 6 / diff + 1 / 2;
|
521 | };
|
522 | if (diff === 0) {
|
523 | h = 0;
|
524 | s2 = 0;
|
525 | } else {
|
526 | s2 = diff / v;
|
527 | rdif = diffc(r);
|
528 | gdif = diffc(g);
|
529 | bdif = diffc(b);
|
530 | if (r === v) {
|
531 | h = bdif - gdif;
|
532 | } else if (g === v) {
|
533 | h = 1 / 3 + rdif - bdif;
|
534 | } else if (b === v) {
|
535 | h = 2 / 3 + gdif - rdif;
|
536 | }
|
537 | if (h < 0) {
|
538 | h += 1;
|
539 | } else if (h > 1) {
|
540 | h -= 1;
|
541 | }
|
542 | }
|
543 | return [
|
544 | h * 360,
|
545 | s2 * 100,
|
546 | v * 100
|
547 | ];
|
548 | };
|
549 | convert.rgb.hwb = function(rgb) {
|
550 | const r = rgb[0];
|
551 | const g = rgb[1];
|
552 | let b = rgb[2];
|
553 | const h = convert.rgb.hsl(rgb)[0];
|
554 | const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
555 | b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
556 | return [h, w * 100, b * 100];
|
557 | };
|
558 | convert.rgb.cmyk = function(rgb) {
|
559 | const r = rgb[0] / 255;
|
560 | const g = rgb[1] / 255;
|
561 | const b = rgb[2] / 255;
|
562 | const k = Math.min(1 - r, 1 - g, 1 - b);
|
563 | const c = (1 - r - k) / (1 - k) || 0;
|
564 | const m = (1 - g - k) / (1 - k) || 0;
|
565 | const y = (1 - b - k) / (1 - k) || 0;
|
566 | return [c * 100, m * 100, y * 100, k * 100];
|
567 | };
|
568 | function comparativeDistance(x, y) {
|
569 | return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
570 | }
|
571 | convert.rgb.keyword = function(rgb) {
|
572 | const reversed = reverseKeywords[rgb];
|
573 | if (reversed) {
|
574 | return reversed;
|
575 | }
|
576 | let currentClosestDistance = Infinity;
|
577 | let currentClosestKeyword;
|
578 | for (const keyword of Object.keys(cssKeywords)) {
|
579 | const value = cssKeywords[keyword];
|
580 | const distance = comparativeDistance(rgb, value);
|
581 | if (distance < currentClosestDistance) {
|
582 | currentClosestDistance = distance;
|
583 | currentClosestKeyword = keyword;
|
584 | }
|
585 | }
|
586 | return currentClosestKeyword;
|
587 | };
|
588 | convert.keyword.rgb = function(keyword) {
|
589 | return cssKeywords[keyword];
|
590 | };
|
591 | convert.rgb.xyz = function(rgb) {
|
592 | let r = rgb[0] / 255;
|
593 | let g = rgb[1] / 255;
|
594 | let b = rgb[2] / 255;
|
595 | r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
596 | g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
597 | b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
598 | const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
599 | const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
600 | const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
601 | return [x * 100, y * 100, z * 100];
|
602 | };
|
603 | convert.rgb.lab = function(rgb) {
|
604 | const xyz = convert.rgb.xyz(rgb);
|
605 | let x = xyz[0];
|
606 | let y = xyz[1];
|
607 | let z = xyz[2];
|
608 | x /= 95.047;
|
609 | y /= 100;
|
610 | z /= 108.883;
|
611 | x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
612 | y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
613 | z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
614 | const l3 = 116 * y - 16;
|
615 | const a = 500 * (x - y);
|
616 | const b = 200 * (y - z);
|
617 | return [l3, a, b];
|
618 | };
|
619 | convert.hsl.rgb = function(hsl) {
|
620 | const h = hsl[0] / 360;
|
621 | const s2 = hsl[1] / 100;
|
622 | const l3 = hsl[2] / 100;
|
623 | let t2;
|
624 | let t3;
|
625 | let val;
|
626 | if (s2 === 0) {
|
627 | val = l3 * 255;
|
628 | return [val, val, val];
|
629 | }
|
630 | if (l3 < 0.5) {
|
631 | t2 = l3 * (1 + s2);
|
632 | } else {
|
633 | t2 = l3 + s2 - l3 * s2;
|
634 | }
|
635 | const t1 = 2 * l3 - t2;
|
636 | const rgb = [0, 0, 0];
|
637 | for (let i3 = 0; i3 < 3; i3++) {
|
638 | t3 = h + 1 / 3 * -(i3 - 1);
|
639 | if (t3 < 0) {
|
640 | t3++;
|
641 | }
|
642 | if (t3 > 1) {
|
643 | t3--;
|
644 | }
|
645 | if (6 * t3 < 1) {
|
646 | val = t1 + (t2 - t1) * 6 * t3;
|
647 | } else if (2 * t3 < 1) {
|
648 | val = t2;
|
649 | } else if (3 * t3 < 2) {
|
650 | val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
651 | } else {
|
652 | val = t1;
|
653 | }
|
654 | rgb[i3] = val * 255;
|
655 | }
|
656 | return rgb;
|
657 | };
|
658 | convert.hsl.hsv = function(hsl) {
|
659 | const h = hsl[0];
|
660 | let s2 = hsl[1] / 100;
|
661 | let l3 = hsl[2] / 100;
|
662 | let smin = s2;
|
663 | const lmin = Math.max(l3, 0.01);
|
664 | l3 *= 2;
|
665 | s2 *= l3 <= 1 ? l3 : 2 - l3;
|
666 | smin *= lmin <= 1 ? lmin : 2 - lmin;
|
667 | const v = (l3 + s2) / 2;
|
668 | const sv = l3 === 0 ? 2 * smin / (lmin + smin) : 2 * s2 / (l3 + s2);
|
669 | return [h, sv * 100, v * 100];
|
670 | };
|
671 | convert.hsv.rgb = function(hsv) {
|
672 | const h = hsv[0] / 60;
|
673 | const s2 = hsv[1] / 100;
|
674 | let v = hsv[2] / 100;
|
675 | const hi = Math.floor(h) % 6;
|
676 | const f = h - Math.floor(h);
|
677 | const p = 255 * v * (1 - s2);
|
678 | const q = 255 * v * (1 - s2 * f);
|
679 | const t2 = 255 * v * (1 - s2 * (1 - f));
|
680 | v *= 255;
|
681 | switch (hi) {
|
682 | case 0:
|
683 | return [v, t2, p];
|
684 | case 1:
|
685 | return [q, v, p];
|
686 | case 2:
|
687 | return [p, v, t2];
|
688 | case 3:
|
689 | return [p, q, v];
|
690 | case 4:
|
691 | return [t2, p, v];
|
692 | case 5:
|
693 | return [v, p, q];
|
694 | }
|
695 | };
|
696 | convert.hsv.hsl = function(hsv) {
|
697 | const h = hsv[0];
|
698 | const s2 = hsv[1] / 100;
|
699 | const v = hsv[2] / 100;
|
700 | const vmin = Math.max(v, 0.01);
|
701 | let sl;
|
702 | let l3;
|
703 | l3 = (2 - s2) * v;
|
704 | const lmin = (2 - s2) * vmin;
|
705 | sl = s2 * vmin;
|
706 | sl /= lmin <= 1 ? lmin : 2 - lmin;
|
707 | sl = sl || 0;
|
708 | l3 /= 2;
|
709 | return [h, sl * 100, l3 * 100];
|
710 | };
|
711 | convert.hwb.rgb = function(hwb) {
|
712 | const h = hwb[0] / 360;
|
713 | let wh = hwb[1] / 100;
|
714 | let bl = hwb[2] / 100;
|
715 | const ratio = wh + bl;
|
716 | let f;
|
717 | if (ratio > 1) {
|
718 | wh /= ratio;
|
719 | bl /= ratio;
|
720 | }
|
721 | const i3 = Math.floor(6 * h);
|
722 | const v = 1 - bl;
|
723 | f = 6 * h - i3;
|
724 | if ((i3 & 1) !== 0) {
|
725 | f = 1 - f;
|
726 | }
|
727 | const n2 = wh + f * (v - wh);
|
728 | let r;
|
729 | let g;
|
730 | let b;
|
731 | switch (i3) {
|
732 | default:
|
733 | case 6:
|
734 | case 0:
|
735 | r = v;
|
736 | g = n2;
|
737 | b = wh;
|
738 | break;
|
739 | case 1:
|
740 | r = n2;
|
741 | g = v;
|
742 | b = wh;
|
743 | break;
|
744 | case 2:
|
745 | r = wh;
|
746 | g = v;
|
747 | b = n2;
|
748 | break;
|
749 | case 3:
|
750 | r = wh;
|
751 | g = n2;
|
752 | b = v;
|
753 | break;
|
754 | case 4:
|
755 | r = n2;
|
756 | g = wh;
|
757 | b = v;
|
758 | break;
|
759 | case 5:
|
760 | r = v;
|
761 | g = wh;
|
762 | b = n2;
|
763 | break;
|
764 | }
|
765 | return [r * 255, g * 255, b * 255];
|
766 | };
|
767 | convert.cmyk.rgb = function(cmyk) {
|
768 | const c = cmyk[0] / 100;
|
769 | const m = cmyk[1] / 100;
|
770 | const y = cmyk[2] / 100;
|
771 | const k = cmyk[3] / 100;
|
772 | const r = 1 - Math.min(1, c * (1 - k) + k);
|
773 | const g = 1 - Math.min(1, m * (1 - k) + k);
|
774 | const b = 1 - Math.min(1, y * (1 - k) + k);
|
775 | return [r * 255, g * 255, b * 255];
|
776 | };
|
777 | convert.xyz.rgb = function(xyz) {
|
778 | const x = xyz[0] / 100;
|
779 | const y = xyz[1] / 100;
|
780 | const z = xyz[2] / 100;
|
781 | let r;
|
782 | let g;
|
783 | let b;
|
784 | r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
785 | g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
786 | b = x * 0.0557 + y * -0.204 + z * 1.057;
|
787 | r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
788 | g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
789 | b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
790 | r = Math.min(Math.max(0, r), 1);
|
791 | g = Math.min(Math.max(0, g), 1);
|
792 | b = Math.min(Math.max(0, b), 1);
|
793 | return [r * 255, g * 255, b * 255];
|
794 | };
|
795 | convert.xyz.lab = function(xyz) {
|
796 | let x = xyz[0];
|
797 | let y = xyz[1];
|
798 | let z = xyz[2];
|
799 | x /= 95.047;
|
800 | y /= 100;
|
801 | z /= 108.883;
|
802 | x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
803 | y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
804 | z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
805 | const l3 = 116 * y - 16;
|
806 | const a = 500 * (x - y);
|
807 | const b = 200 * (y - z);
|
808 | return [l3, a, b];
|
809 | };
|
810 | convert.lab.xyz = function(lab) {
|
811 | const l3 = lab[0];
|
812 | const a = lab[1];
|
813 | const b = lab[2];
|
814 | let x;
|
815 | let y;
|
816 | let z;
|
817 | y = (l3 + 16) / 116;
|
818 | x = a / 500 + y;
|
819 | z = y - b / 200;
|
820 | const y2 = y ** 3;
|
821 | const x2 = x ** 3;
|
822 | const z2 = z ** 3;
|
823 | y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
|
824 | x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
|
825 | z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
|
826 | x *= 95.047;
|
827 | y *= 100;
|
828 | z *= 108.883;
|
829 | return [x, y, z];
|
830 | };
|
831 | convert.lab.lch = function(lab) {
|
832 | const l3 = lab[0];
|
833 | const a = lab[1];
|
834 | const b = lab[2];
|
835 | let h;
|
836 | const hr = Math.atan2(b, a);
|
837 | h = hr * 360 / 2 / Math.PI;
|
838 | if (h < 0) {
|
839 | h += 360;
|
840 | }
|
841 | const c = Math.sqrt(a * a + b * b);
|
842 | return [l3, c, h];
|
843 | };
|
844 | convert.lch.lab = function(lch) {
|
845 | const l3 = lch[0];
|
846 | const c = lch[1];
|
847 | const h = lch[2];
|
848 | const hr = h / 360 * 2 * Math.PI;
|
849 | const a = c * Math.cos(hr);
|
850 | const b = c * Math.sin(hr);
|
851 | return [l3, a, b];
|
852 | };
|
853 | convert.rgb.ansi16 = function(args, saturation = null) {
|
854 | const [r, g, b] = args;
|
855 | let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
856 | value = Math.round(value / 50);
|
857 | if (value === 0) {
|
858 | return 30;
|
859 | }
|
860 | let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
861 | if (value === 2) {
|
862 | ansi += 60;
|
863 | }
|
864 | return ansi;
|
865 | };
|
866 | convert.hsv.ansi16 = function(args) {
|
867 | return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
868 | };
|
869 | convert.rgb.ansi256 = function(args) {
|
870 | const r = args[0];
|
871 | const g = args[1];
|
872 | const b = args[2];
|
873 | if (r === g && g === b) {
|
874 | if (r < 8) {
|
875 | return 16;
|
876 | }
|
877 | if (r > 248) {
|
878 | return 231;
|
879 | }
|
880 | return Math.round((r - 8) / 247 * 24) + 232;
|
881 | }
|
882 | const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
883 | return ansi;
|
884 | };
|
885 | convert.ansi16.rgb = function(args) {
|
886 | let color = args % 10;
|
887 | if (color === 0 || color === 7) {
|
888 | if (args > 50) {
|
889 | color += 3.5;
|
890 | }
|
891 | color = color / 10.5 * 255;
|
892 | return [color, color, color];
|
893 | }
|
894 | const mult = (~~(args > 50) + 1) * 0.5;
|
895 | const r = (color & 1) * mult * 255;
|
896 | const g = (color >> 1 & 1) * mult * 255;
|
897 | const b = (color >> 2 & 1) * mult * 255;
|
898 | return [r, g, b];
|
899 | };
|
900 | convert.ansi256.rgb = function(args) {
|
901 | if (args >= 232) {
|
902 | const c = (args - 232) * 10 + 8;
|
903 | return [c, c, c];
|
904 | }
|
905 | args -= 16;
|
906 | let rem;
|
907 | const r = Math.floor(args / 36) / 5 * 255;
|
908 | const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
909 | const b = rem % 6 / 5 * 255;
|
910 | return [r, g, b];
|
911 | };
|
912 | convert.rgb.hex = function(args) {
|
913 | const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
914 | const string = integer.toString(16).toUpperCase();
|
915 | return "000000".substring(string.length) + string;
|
916 | };
|
917 | convert.hex.rgb = function(args) {
|
918 | const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
919 | if (!match) {
|
920 | return [0, 0, 0];
|
921 | }
|
922 | let colorString = match[0];
|
923 | if (match[0].length === 3) {
|
924 | colorString = colorString.split("").map((char) => {
|
925 | return char + char;
|
926 | }).join("");
|
927 | }
|
928 | const integer = parseInt(colorString, 16);
|
929 | const r = integer >> 16 & 255;
|
930 | const g = integer >> 8 & 255;
|
931 | const b = integer & 255;
|
932 | return [r, g, b];
|
933 | };
|
934 | convert.rgb.hcg = function(rgb) {
|
935 | const r = rgb[0] / 255;
|
936 | const g = rgb[1] / 255;
|
937 | const b = rgb[2] / 255;
|
938 | const max = Math.max(Math.max(r, g), b);
|
939 | const min = Math.min(Math.min(r, g), b);
|
940 | const chroma = max - min;
|
941 | let grayscale;
|
942 | let hue;
|
943 | if (chroma < 1) {
|
944 | grayscale = min / (1 - chroma);
|
945 | } else {
|
946 | grayscale = 0;
|
947 | }
|
948 | if (chroma <= 0) {
|
949 | hue = 0;
|
950 | } else if (max === r) {
|
951 | hue = (g - b) / chroma % 6;
|
952 | } else if (max === g) {
|
953 | hue = 2 + (b - r) / chroma;
|
954 | } else {
|
955 | hue = 4 + (r - g) / chroma;
|
956 | }
|
957 | hue /= 6;
|
958 | hue %= 1;
|
959 | return [hue * 360, chroma * 100, grayscale * 100];
|
960 | };
|
961 | convert.hsl.hcg = function(hsl) {
|
962 | const s2 = hsl[1] / 100;
|
963 | const l3 = hsl[2] / 100;
|
964 | const c = l3 < 0.5 ? 2 * s2 * l3 : 2 * s2 * (1 - l3);
|
965 | let f = 0;
|
966 | if (c < 1) {
|
967 | f = (l3 - 0.5 * c) / (1 - c);
|
968 | }
|
969 | return [hsl[0], c * 100, f * 100];
|
970 | };
|
971 | convert.hsv.hcg = function(hsv) {
|
972 | const s2 = hsv[1] / 100;
|
973 | const v = hsv[2] / 100;
|
974 | const c = s2 * v;
|
975 | let f = 0;
|
976 | if (c < 1) {
|
977 | f = (v - c) / (1 - c);
|
978 | }
|
979 | return [hsv[0], c * 100, f * 100];
|
980 | };
|
981 | convert.hcg.rgb = function(hcg) {
|
982 | const h = hcg[0] / 360;
|
983 | const c = hcg[1] / 100;
|
984 | const g = hcg[2] / 100;
|
985 | if (c === 0) {
|
986 | return [g * 255, g * 255, g * 255];
|
987 | }
|
988 | const pure = [0, 0, 0];
|
989 | const hi = h % 1 * 6;
|
990 | const v = hi % 1;
|
991 | const w = 1 - v;
|
992 | let mg = 0;
|
993 | switch (Math.floor(hi)) {
|
994 | case 0:
|
995 | pure[0] = 1;
|
996 | pure[1] = v;
|
997 | pure[2] = 0;
|
998 | break;
|
999 | case 1:
|
1000 | pure[0] = w;
|
1001 | pure[1] = 1;
|
1002 | pure[2] = 0;
|
1003 | break;
|
1004 | case 2:
|
1005 | pure[0] = 0;
|
1006 | pure[1] = 1;
|
1007 | pure[2] = v;
|
1008 | break;
|
1009 | case 3:
|
1010 | pure[0] = 0;
|
1011 | pure[1] = w;
|
1012 | pure[2] = 1;
|
1013 | break;
|
1014 | case 4:
|
1015 | pure[0] = v;
|
1016 | pure[1] = 0;
|
1017 | pure[2] = 1;
|
1018 | break;
|
1019 | default:
|
1020 | pure[0] = 1;
|
1021 | pure[1] = 0;
|
1022 | pure[2] = w;
|
1023 | }
|
1024 | mg = (1 - c) * g;
|
1025 | return [
|
1026 | (c * pure[0] + mg) * 255,
|
1027 | (c * pure[1] + mg) * 255,
|
1028 | (c * pure[2] + mg) * 255
|
1029 | ];
|
1030 | };
|
1031 | convert.hcg.hsv = function(hcg) {
|
1032 | const c = hcg[1] / 100;
|
1033 | const g = hcg[2] / 100;
|
1034 | const v = c + g * (1 - c);
|
1035 | let f = 0;
|
1036 | if (v > 0) {
|
1037 | f = c / v;
|
1038 | }
|
1039 | return [hcg[0], f * 100, v * 100];
|
1040 | };
|
1041 | convert.hcg.hsl = function(hcg) {
|
1042 | const c = hcg[1] / 100;
|
1043 | const g = hcg[2] / 100;
|
1044 | const l3 = g * (1 - c) + 0.5 * c;
|
1045 | let s2 = 0;
|
1046 | if (l3 > 0 && l3 < 0.5) {
|
1047 | s2 = c / (2 * l3);
|
1048 | } else if (l3 >= 0.5 && l3 < 1) {
|
1049 | s2 = c / (2 * (1 - l3));
|
1050 | }
|
1051 | return [hcg[0], s2 * 100, l3 * 100];
|
1052 | };
|
1053 | convert.hcg.hwb = function(hcg) {
|
1054 | const c = hcg[1] / 100;
|
1055 | const g = hcg[2] / 100;
|
1056 | const v = c + g * (1 - c);
|
1057 | return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
1058 | };
|
1059 | convert.hwb.hcg = function(hwb) {
|
1060 | const w = hwb[1] / 100;
|
1061 | const b = hwb[2] / 100;
|
1062 | const v = 1 - b;
|
1063 | const c = v - w;
|
1064 | let g = 0;
|
1065 | if (c < 1) {
|
1066 | g = (v - c) / (1 - c);
|
1067 | }
|
1068 | return [hwb[0], c * 100, g * 100];
|
1069 | };
|
1070 | convert.apple.rgb = function(apple) {
|
1071 | return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
1072 | };
|
1073 | convert.rgb.apple = function(rgb) {
|
1074 | return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
1075 | };
|
1076 | convert.gray.rgb = function(args) {
|
1077 | return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
1078 | };
|
1079 | convert.gray.hsl = function(args) {
|
1080 | return [0, 0, args[0]];
|
1081 | };
|
1082 | convert.gray.hsv = convert.gray.hsl;
|
1083 | convert.gray.hwb = function(gray) {
|
1084 | return [0, 100, gray[0]];
|
1085 | };
|
1086 | convert.gray.cmyk = function(gray) {
|
1087 | return [0, 0, 0, gray[0]];
|
1088 | };
|
1089 | convert.gray.lab = function(gray) {
|
1090 | return [gray[0], 0, 0];
|
1091 | };
|
1092 | convert.gray.hex = function(gray) {
|
1093 | const val = Math.round(gray[0] / 100 * 255) & 255;
|
1094 | const integer = (val << 16) + (val << 8) + val;
|
1095 | const string = integer.toString(16).toUpperCase();
|
1096 | return "000000".substring(string.length) + string;
|
1097 | };
|
1098 | convert.rgb.gray = function(rgb) {
|
1099 | const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
1100 | return [val / 255 * 100];
|
1101 | };
|
1102 | }
|
1103 | });
|
1104 |
|
1105 |
|
1106 | var require_route = __commonJS({
|
1107 | "node_modules/color-convert/route.js"(exports, module) {
|
1108 | var conversions = require_conversions();
|
1109 | function buildGraph() {
|
1110 | const graph = {};
|
1111 | const models = Object.keys(conversions);
|
1112 | for (let len = models.length, i3 = 0; i3 < len; i3++) {
|
1113 | graph[models[i3]] = {
|
1114 | distance: -1,
|
1115 | parent: null
|
1116 | };
|
1117 | }
|
1118 | return graph;
|
1119 | }
|
1120 | function deriveBFS(fromModel) {
|
1121 | const graph = buildGraph();
|
1122 | const queue = [fromModel];
|
1123 | graph[fromModel].distance = 0;
|
1124 | while (queue.length) {
|
1125 | const current = queue.pop();
|
1126 | const adjacents = Object.keys(conversions[current]);
|
1127 | for (let len = adjacents.length, i3 = 0; i3 < len; i3++) {
|
1128 | const adjacent = adjacents[i3];
|
1129 | const node = graph[adjacent];
|
1130 | if (node.distance === -1) {
|
1131 | node.distance = graph[current].distance + 1;
|
1132 | node.parent = current;
|
1133 | queue.unshift(adjacent);
|
1134 | }
|
1135 | }
|
1136 | }
|
1137 | return graph;
|
1138 | }
|
1139 | function link(from, to) {
|
1140 | return function(args) {
|
1141 | return to(from(args));
|
1142 | };
|
1143 | }
|
1144 | function wrapConversion(toModel, graph) {
|
1145 | const path = [graph[toModel].parent, toModel];
|
1146 | let fn = conversions[graph[toModel].parent][toModel];
|
1147 | let cur = graph[toModel].parent;
|
1148 | while (graph[cur].parent) {
|
1149 | path.unshift(graph[cur].parent);
|
1150 | fn = link(conversions[graph[cur].parent][cur], fn);
|
1151 | cur = graph[cur].parent;
|
1152 | }
|
1153 | fn.conversion = path;
|
1154 | return fn;
|
1155 | }
|
1156 | module.exports = function(fromModel) {
|
1157 | const graph = deriveBFS(fromModel);
|
1158 | const conversion = {};
|
1159 | const models = Object.keys(graph);
|
1160 | for (let len = models.length, i3 = 0; i3 < len; i3++) {
|
1161 | const toModel = models[i3];
|
1162 | const node = graph[toModel];
|
1163 | if (node.parent === null) {
|
1164 | continue;
|
1165 | }
|
1166 | conversion[toModel] = wrapConversion(toModel, graph);
|
1167 | }
|
1168 | return conversion;
|
1169 | };
|
1170 | }
|
1171 | });
|
1172 |
|
1173 |
|
1174 | var require_color_convert = __commonJS({
|
1175 | "node_modules/color-convert/index.js"(exports, module) {
|
1176 | var conversions = require_conversions();
|
1177 | var route = require_route();
|
1178 | var convert = {};
|
1179 | var models = Object.keys(conversions);
|
1180 | function wrapRaw(fn) {
|
1181 | const wrappedFn = function(...args) {
|
1182 | const arg0 = args[0];
|
1183 | if (arg0 === void 0 || arg0 === null) {
|
1184 | return arg0;
|
1185 | }
|
1186 | if (arg0.length > 1) {
|
1187 | args = arg0;
|
1188 | }
|
1189 | return fn(args);
|
1190 | };
|
1191 | if ("conversion" in fn) {
|
1192 | wrappedFn.conversion = fn.conversion;
|
1193 | }
|
1194 | return wrappedFn;
|
1195 | }
|
1196 | function wrapRounded(fn) {
|
1197 | const wrappedFn = function(...args) {
|
1198 | const arg0 = args[0];
|
1199 | if (arg0 === void 0 || arg0 === null) {
|
1200 | return arg0;
|
1201 | }
|
1202 | if (arg0.length > 1) {
|
1203 | args = arg0;
|
1204 | }
|
1205 | const result = fn(args);
|
1206 | if (typeof result === "object") {
|
1207 | for (let len = result.length, i3 = 0; i3 < len; i3++) {
|
1208 | result[i3] = Math.round(result[i3]);
|
1209 | }
|
1210 | }
|
1211 | return result;
|
1212 | };
|
1213 | if ("conversion" in fn) {
|
1214 | wrappedFn.conversion = fn.conversion;
|
1215 | }
|
1216 | return wrappedFn;
|
1217 | }
|
1218 | models.forEach((fromModel) => {
|
1219 | convert[fromModel] = {};
|
1220 | Object.defineProperty(convert[fromModel], "channels", { value: conversions[fromModel].channels });
|
1221 | Object.defineProperty(convert[fromModel], "labels", { value: conversions[fromModel].labels });
|
1222 | const routes = route(fromModel);
|
1223 | const routeModels = Object.keys(routes);
|
1224 | routeModels.forEach((toModel) => {
|
1225 | const fn = routes[toModel];
|
1226 | convert[fromModel][toModel] = wrapRounded(fn);
|
1227 | convert[fromModel][toModel].raw = wrapRaw(fn);
|
1228 | });
|
1229 | });
|
1230 | module.exports = convert;
|
1231 | }
|
1232 | });
|
1233 |
|
1234 |
|
1235 | var require_color = __commonJS({
|
1236 | "node_modules/color/index.js"(exports, module) {
|
1237 | var colorString = require_color_string();
|
1238 | var convert = require_color_convert();
|
1239 | var _slice = [].slice;
|
1240 | var skippedModels = [
|
1241 | "keyword",
|
1242 | "gray",
|
1243 | "hex"
|
1244 | ];
|
1245 | var hashedModelKeys = {};
|
1246 | for (const model of Object.keys(convert)) {
|
1247 | hashedModelKeys[_slice.call(convert[model].labels).sort().join("")] = model;
|
1248 | }
|
1249 | var limiters = {};
|
1250 | function Color2(object, model) {
|
1251 | if (!(this instanceof Color2)) {
|
1252 | return new Color2(object, model);
|
1253 | }
|
1254 | if (model && model in skippedModels) {
|
1255 | model = null;
|
1256 | }
|
1257 | if (model && !(model in convert)) {
|
1258 | throw new Error("Unknown model: " + model);
|
1259 | }
|
1260 | let i3;
|
1261 | let channels;
|
1262 | if (object == null) {
|
1263 | this.model = "rgb";
|
1264 | this.color = [0, 0, 0];
|
1265 | this.valpha = 1;
|
1266 | } else if (object instanceof Color2) {
|
1267 | this.model = object.model;
|
1268 | this.color = object.color.slice();
|
1269 | this.valpha = object.valpha;
|
1270 | } else if (typeof object === "string") {
|
1271 | const result = colorString.get(object);
|
1272 | if (result === null) {
|
1273 | throw new Error("Unable to parse color from string: " + object);
|
1274 | }
|
1275 | this.model = result.model;
|
1276 | channels = convert[this.model].channels;
|
1277 | this.color = result.value.slice(0, channels);
|
1278 | this.valpha = typeof result.value[channels] === "number" ? result.value[channels] : 1;
|
1279 | } else if (object.length > 0) {
|
1280 | this.model = model || "rgb";
|
1281 | channels = convert[this.model].channels;
|
1282 | const newArray = _slice.call(object, 0, channels);
|
1283 | this.color = zeroArray(newArray, channels);
|
1284 | this.valpha = typeof object[channels] === "number" ? object[channels] : 1;
|
1285 | } else if (typeof object === "number") {
|
1286 | this.model = "rgb";
|
1287 | this.color = [
|
1288 | object >> 16 & 255,
|
1289 | object >> 8 & 255,
|
1290 | object & 255
|
1291 | ];
|
1292 | this.valpha = 1;
|
1293 | } else {
|
1294 | this.valpha = 1;
|
1295 | const keys = Object.keys(object);
|
1296 | if ("alpha" in object) {
|
1297 | keys.splice(keys.indexOf("alpha"), 1);
|
1298 | this.valpha = typeof object.alpha === "number" ? object.alpha : 0;
|
1299 | }
|
1300 | const hashedKeys = keys.sort().join("");
|
1301 | if (!(hashedKeys in hashedModelKeys)) {
|
1302 | throw new Error("Unable to parse color from object: " + JSON.stringify(object));
|
1303 | }
|
1304 | this.model = hashedModelKeys[hashedKeys];
|
1305 | const labels = convert[this.model].labels;
|
1306 | const color = [];
|
1307 | for (i3 = 0; i3 < labels.length; i3++) {
|
1308 | color.push(object[labels[i3]]);
|
1309 | }
|
1310 | this.color = zeroArray(color);
|
1311 | }
|
1312 | if (limiters[this.model]) {
|
1313 | channels = convert[this.model].channels;
|
1314 | for (i3 = 0; i3 < channels; i3++) {
|
1315 | const limit = limiters[this.model][i3];
|
1316 | if (limit) {
|
1317 | this.color[i3] = limit(this.color[i3]);
|
1318 | }
|
1319 | }
|
1320 | }
|
1321 | this.valpha = Math.max(0, Math.min(1, this.valpha));
|
1322 | if (Object.freeze) {
|
1323 | Object.freeze(this);
|
1324 | }
|
1325 | }
|
1326 | Color2.prototype = {
|
1327 | toString() {
|
1328 | return this.string();
|
1329 | },
|
1330 | toJSON() {
|
1331 | return this[this.model]();
|
1332 | },
|
1333 | string(places) {
|
1334 | let self = this.model in colorString.to ? this : this.rgb();
|
1335 | self = self.round(typeof places === "number" ? places : 1);
|
1336 | const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
|
1337 | return colorString.to[self.model](args);
|
1338 | },
|
1339 | percentString(places) {
|
1340 | const self = this.rgb().round(typeof places === "number" ? places : 1);
|
1341 | const args = self.valpha === 1 ? self.color : self.color.concat(this.valpha);
|
1342 | return colorString.to.rgb.percent(args);
|
1343 | },
|
1344 | array() {
|
1345 | return this.valpha === 1 ? this.color.slice() : this.color.concat(this.valpha);
|
1346 | },
|
1347 | object() {
|
1348 | const result = {};
|
1349 | const channels = convert[this.model].channels;
|
1350 | const labels = convert[this.model].labels;
|
1351 | for (let i3 = 0; i3 < channels; i3++) {
|
1352 | result[labels[i3]] = this.color[i3];
|
1353 | }
|
1354 | if (this.valpha !== 1) {
|
1355 | result.alpha = this.valpha;
|
1356 | }
|
1357 | return result;
|
1358 | },
|
1359 | unitArray() {
|
1360 | const rgb = this.rgb().color;
|
1361 | rgb[0] /= 255;
|
1362 | rgb[1] /= 255;
|
1363 | rgb[2] /= 255;
|
1364 | if (this.valpha !== 1) {
|
1365 | rgb.push(this.valpha);
|
1366 | }
|
1367 | return rgb;
|
1368 | },
|
1369 | unitObject() {
|
1370 | const rgb = this.rgb().object();
|
1371 | rgb.r /= 255;
|
1372 | rgb.g /= 255;
|
1373 | rgb.b /= 255;
|
1374 | if (this.valpha !== 1) {
|
1375 | rgb.alpha = this.valpha;
|
1376 | }
|
1377 | return rgb;
|
1378 | },
|
1379 | round(places) {
|
1380 | places = Math.max(places || 0, 0);
|
1381 | return new Color2(this.color.map(roundToPlace(places)).concat(this.valpha), this.model);
|
1382 | },
|
1383 | alpha(value) {
|
1384 | if (arguments.length > 0) {
|
1385 | return new Color2(this.color.concat(Math.max(0, Math.min(1, value))), this.model);
|
1386 | }
|
1387 | return this.valpha;
|
1388 | },
|
1389 | red: getset("rgb", 0, maxfn(255)),
|
1390 | green: getset("rgb", 1, maxfn(255)),
|
1391 | blue: getset("rgb", 2, maxfn(255)),
|
1392 | hue: getset(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, (value) => (value % 360 + 360) % 360),
|
1393 | saturationl: getset("hsl", 1, maxfn(100)),
|
1394 | lightness: getset("hsl", 2, maxfn(100)),
|
1395 | saturationv: getset("hsv", 1, maxfn(100)),
|
1396 | value: getset("hsv", 2, maxfn(100)),
|
1397 | chroma: getset("hcg", 1, maxfn(100)),
|
1398 | gray: getset("hcg", 2, maxfn(100)),
|
1399 | white: getset("hwb", 1, maxfn(100)),
|
1400 | wblack: getset("hwb", 2, maxfn(100)),
|
1401 | cyan: getset("cmyk", 0, maxfn(100)),
|
1402 | magenta: getset("cmyk", 1, maxfn(100)),
|
1403 | yellow: getset("cmyk", 2, maxfn(100)),
|
1404 | black: getset("cmyk", 3, maxfn(100)),
|
1405 | x: getset("xyz", 0, maxfn(100)),
|
1406 | y: getset("xyz", 1, maxfn(100)),
|
1407 | z: getset("xyz", 2, maxfn(100)),
|
1408 | l: getset("lab", 0, maxfn(100)),
|
1409 | a: getset("lab", 1),
|
1410 | b: getset("lab", 2),
|
1411 | keyword(value) {
|
1412 | if (arguments.length > 0) {
|
1413 | return new Color2(value);
|
1414 | }
|
1415 | return convert[this.model].keyword(this.color);
|
1416 | },
|
1417 | hex(value) {
|
1418 | if (arguments.length > 0) {
|
1419 | return new Color2(value);
|
1420 | }
|
1421 | return colorString.to.hex(this.rgb().round().color);
|
1422 | },
|
1423 | hexa(value) {
|
1424 | if (arguments.length > 0) {
|
1425 | return new Color2(value);
|
1426 | }
|
1427 | const rgbArray = this.rgb().round().color;
|
1428 | let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
|
1429 | if (alphaHex.length === 1) {
|
1430 | alphaHex = "0" + alphaHex;
|
1431 | }
|
1432 | return colorString.to.hex(rgbArray) + alphaHex;
|
1433 | },
|
1434 | rgbNumber() {
|
1435 | const rgb = this.rgb().color;
|
1436 | return (rgb[0] & 255) << 16 | (rgb[1] & 255) << 8 | rgb[2] & 255;
|
1437 | },
|
1438 | luminosity() {
|
1439 | const rgb = this.rgb().color;
|
1440 | const lum = [];
|
1441 | for (const [i3, element] of rgb.entries()) {
|
1442 | const chan = element / 255;
|
1443 | lum[i3] = chan <= 0.03928 ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
|
1444 | }
|
1445 | return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
|
1446 | },
|
1447 | contrast(color2) {
|
1448 | const lum1 = this.luminosity();
|
1449 | const lum2 = color2.luminosity();
|
1450 | if (lum1 > lum2) {
|
1451 | return (lum1 + 0.05) / (lum2 + 0.05);
|
1452 | }
|
1453 | return (lum2 + 0.05) / (lum1 + 0.05);
|
1454 | },
|
1455 | level(color2) {
|
1456 | const contrastRatio = this.contrast(color2);
|
1457 | if (contrastRatio >= 7.1) {
|
1458 | return "AAA";
|
1459 | }
|
1460 | return contrastRatio >= 4.5 ? "AA" : "";
|
1461 | },
|
1462 | isDark() {
|
1463 | const rgb = this.rgb().color;
|
1464 | const yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1e3;
|
1465 | return yiq < 128;
|
1466 | },
|
1467 | isLight() {
|
1468 | return !this.isDark();
|
1469 | },
|
1470 | negate() {
|
1471 | const rgb = this.rgb();
|
1472 | for (let i3 = 0; i3 < 3; i3++) {
|
1473 | rgb.color[i3] = 255 - rgb.color[i3];
|
1474 | }
|
1475 | return rgb;
|
1476 | },
|
1477 | lighten(ratio) {
|
1478 | const hsl = this.hsl();
|
1479 | hsl.color[2] += hsl.color[2] * ratio;
|
1480 | return hsl;
|
1481 | },
|
1482 | darken(ratio) {
|
1483 | const hsl = this.hsl();
|
1484 | hsl.color[2] -= hsl.color[2] * ratio;
|
1485 | return hsl;
|
1486 | },
|
1487 | saturate(ratio) {
|
1488 | const hsl = this.hsl();
|
1489 | hsl.color[1] += hsl.color[1] * ratio;
|
1490 | return hsl;
|
1491 | },
|
1492 | desaturate(ratio) {
|
1493 | const hsl = this.hsl();
|
1494 | hsl.color[1] -= hsl.color[1] * ratio;
|
1495 | return hsl;
|
1496 | },
|
1497 | whiten(ratio) {
|
1498 | const hwb = this.hwb();
|
1499 | hwb.color[1] += hwb.color[1] * ratio;
|
1500 | return hwb;
|
1501 | },
|
1502 | blacken(ratio) {
|
1503 | const hwb = this.hwb();
|
1504 | hwb.color[2] += hwb.color[2] * ratio;
|
1505 | return hwb;
|
1506 | },
|
1507 | grayscale() {
|
1508 | const rgb = this.rgb().color;
|
1509 | const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
|
1510 | return Color2.rgb(value, value, value);
|
1511 | },
|
1512 | fade(ratio) {
|
1513 | return this.alpha(this.valpha - this.valpha * ratio);
|
1514 | },
|
1515 | opaquer(ratio) {
|
1516 | return this.alpha(this.valpha + this.valpha * ratio);
|
1517 | },
|
1518 | rotate(degrees) {
|
1519 | const hsl = this.hsl();
|
1520 | let hue = hsl.color[0];
|
1521 | hue = (hue + degrees) % 360;
|
1522 | hue = hue < 0 ? 360 + hue : hue;
|
1523 | hsl.color[0] = hue;
|
1524 | return hsl;
|
1525 | },
|
1526 | mix(mixinColor, weight) {
|
1527 | if (!mixinColor || !mixinColor.rgb) {
|
1528 | throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
|
1529 | }
|
1530 | const color1 = mixinColor.rgb();
|
1531 | const color2 = this.rgb();
|
1532 | const p = weight === void 0 ? 0.5 : weight;
|
1533 | const w = 2 * p - 1;
|
1534 | const a = color1.alpha() - color2.alpha();
|
1535 | const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2;
|
1536 | const w2 = 1 - w1;
|
1537 | return Color2.rgb(w1 * color1.red() + w2 * color2.red(), w1 * color1.green() + w2 * color2.green(), w1 * color1.blue() + w2 * color2.blue(), color1.alpha() * p + color2.alpha() * (1 - p));
|
1538 | }
|
1539 | };
|
1540 | for (const model of Object.keys(convert)) {
|
1541 | if (skippedModels.includes(model)) {
|
1542 | continue;
|
1543 | }
|
1544 | const channels = convert[model].channels;
|
1545 | Color2.prototype[model] = function() {
|
1546 | if (this.model === model) {
|
1547 | return new Color2(this);
|
1548 | }
|
1549 | if (arguments.length > 0) {
|
1550 | return new Color2(arguments, model);
|
1551 | }
|
1552 | const newAlpha = typeof arguments[channels] === "number" ? channels : this.valpha;
|
1553 | return new Color2(assertArray(convert[this.model][model].raw(this.color)).concat(newAlpha), model);
|
1554 | };
|
1555 | Color2[model] = function(color) {
|
1556 | if (typeof color === "number") {
|
1557 | color = zeroArray(_slice.call(arguments), channels);
|
1558 | }
|
1559 | return new Color2(color, model);
|
1560 | };
|
1561 | }
|
1562 | function roundTo(number, places) {
|
1563 | return Number(number.toFixed(places));
|
1564 | }
|
1565 | function roundToPlace(places) {
|
1566 | return function(number) {
|
1567 | return roundTo(number, places);
|
1568 | };
|
1569 | }
|
1570 | function getset(model, channel, modifier) {
|
1571 | model = Array.isArray(model) ? model : [model];
|
1572 | for (const m of model) {
|
1573 | (limiters[m] || (limiters[m] = []))[channel] = modifier;
|
1574 | }
|
1575 | model = model[0];
|
1576 | return function(value) {
|
1577 | let result;
|
1578 | if (arguments.length > 0) {
|
1579 | if (modifier) {
|
1580 | value = modifier(value);
|
1581 | }
|
1582 | result = this[model]();
|
1583 | result.color[channel] = value;
|
1584 | return result;
|
1585 | }
|
1586 | result = this[model]().color[channel];
|
1587 | if (modifier) {
|
1588 | result = modifier(result);
|
1589 | }
|
1590 | return result;
|
1591 | };
|
1592 | }
|
1593 | function maxfn(max) {
|
1594 | return function(v) {
|
1595 | return Math.max(0, Math.min(max, v));
|
1596 | };
|
1597 | }
|
1598 | function assertArray(value) {
|
1599 | return Array.isArray(value) ? value : [value];
|
1600 | }
|
1601 | function zeroArray(array, length) {
|
1602 | for (let i3 = 0; i3 < length; i3++) {
|
1603 | if (typeof array[i3] !== "number") {
|
1604 | array[i3] = 0;
|
1605 | }
|
1606 | }
|
1607 | return array;
|
1608 | }
|
1609 | module.exports = Color2;
|
1610 | }
|
1611 | });
|
1612 |
|
1613 |
|
1614 | var import_color = __toESM(require_color(), 1);
|
1615 | var hasEyeDropper = "EyeDropper" in window;
|
1616 | var SlColorPicker = class extends s {
|
1617 | constructor() {
|
1618 | super(...arguments);
|
1619 | this.formSubmitController = new FormSubmitController(this);
|
1620 | this.isSafeValue = false;
|
1621 | this.localize = new LocalizeController(this);
|
1622 | this.isDraggingGridHandle = false;
|
1623 | this.isEmpty = false;
|
1624 | this.inputValue = "";
|
1625 | this.hue = 0;
|
1626 | this.saturation = 100;
|
1627 | this.lightness = 100;
|
1628 | this.brightness = 100;
|
1629 | this.alpha = 100;
|
1630 | this.value = "";
|
1631 | this.defaultValue = "";
|
1632 | this.label = "";
|
1633 | this.format = "hex";
|
1634 | this.inline = false;
|
1635 | this.size = "medium";
|
1636 | this.noFormatToggle = false;
|
1637 | this.name = "";
|
1638 | this.disabled = false;
|
1639 | this.invalid = false;
|
1640 | this.hoist = false;
|
1641 | this.opacity = false;
|
1642 | this.uppercase = false;
|
1643 | this.swatches = [
|
1644 | "#d0021b",
|
1645 | "#f5a623",
|
1646 | "#f8e71c",
|
1647 | "#8b572a",
|
1648 | "#7ed321",
|
1649 | "#417505",
|
1650 | "#bd10e0",
|
1651 | "#9013fe",
|
1652 | "#4a90e2",
|
1653 | "#50e3c2",
|
1654 | "#b8e986",
|
1655 | "#000",
|
1656 | "#444",
|
1657 | "#888",
|
1658 | "#ccc",
|
1659 | "#fff"
|
1660 | ];
|
1661 | }
|
1662 | connectedCallback() {
|
1663 | super.connectedCallback();
|
1664 | if (this.value) {
|
1665 | this.setColor(this.value);
|
1666 | this.inputValue = this.value;
|
1667 | this.lastValueEmitted = this.value;
|
1668 | this.syncValues();
|
1669 | } else {
|
1670 | this.isEmpty = true;
|
1671 | this.inputValue = "";
|
1672 | this.lastValueEmitted = "";
|
1673 | }
|
1674 | }
|
1675 | getFormattedValue(format = "hex") {
|
1676 | const currentColor = this.parseColor(`hsla(${this.hue}, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`);
|
1677 | if (currentColor === null) {
|
1678 | return "";
|
1679 | }
|
1680 | switch (format) {
|
1681 | case "hex":
|
1682 | return currentColor.hex;
|
1683 | case "hexa":
|
1684 | return currentColor.hexa;
|
1685 | case "rgb":
|
1686 | return currentColor.rgb.string;
|
1687 | case "rgba":
|
1688 | return currentColor.rgba.string;
|
1689 | case "hsl":
|
1690 | return currentColor.hsl.string;
|
1691 | case "hsla":
|
1692 | return currentColor.hsla.string;
|
1693 | default:
|
1694 | return "";
|
1695 | }
|
1696 | }
|
1697 | getBrightness(lightness) {
|
1698 | return clamp(-1 * (200 * lightness / (this.saturation - 200)), 0, 100);
|
1699 | }
|
1700 | getLightness(brightness) {
|
1701 | return clamp((200 - this.saturation) * brightness / 100 * 5 / 10, 0, 100);
|
1702 | }
|
1703 | reportValidity() {
|
1704 | if (!this.inline && this.input.invalid) {
|
1705 | return new Promise((resolve) => {
|
1706 | this.dropdown.addEventListener("sl-after-show", () => {
|
1707 | this.input.reportValidity();
|
1708 | resolve();
|
1709 | }, { once: true });
|
1710 | this.dropdown.show();
|
1711 | });
|
1712 | }
|
1713 | return this.input.reportValidity();
|
1714 | }
|
1715 | setCustomValidity(message) {
|
1716 | this.input.setCustomValidity(message);
|
1717 | this.invalid = this.input.invalid;
|
1718 | }
|
1719 | handleCopy() {
|
1720 | this.input.select();
|
1721 | document.execCommand("copy");
|
1722 | this.previewButton.focus();
|
1723 | this.previewButton.classList.add("color-picker__preview-color--copied");
|
1724 | this.previewButton.addEventListener("animationend", () => {
|
1725 | this.previewButton.classList.remove("color-picker__preview-color--copied");
|
1726 | });
|
1727 | }
|
1728 | handleFormatToggle() {
|
1729 | const formats = ["hex", "rgb", "hsl"];
|
1730 | const nextIndex = (formats.indexOf(this.format) + 1) % formats.length;
|
1731 | this.format = formats[nextIndex];
|
1732 | }
|
1733 | handleAlphaDrag(event) {
|
1734 | const container = this.shadowRoot.querySelector(".color-picker__slider.color-picker__alpha");
|
1735 | const handle = container.querySelector(".color-picker__slider-handle");
|
1736 | const { width } = container.getBoundingClientRect();
|
1737 | handle.focus();
|
1738 | event.preventDefault();
|
1739 | drag(container, {
|
1740 | onMove: (x) => {
|
1741 | this.alpha = clamp(x / width * 100, 0, 100);
|
1742 | this.syncValues();
|
1743 | },
|
1744 | initialEvent: event
|
1745 | });
|
1746 | }
|
1747 | handleHueDrag(event) {
|
1748 | const container = this.shadowRoot.querySelector(".color-picker__slider.color-picker__hue");
|
1749 | const handle = container.querySelector(".color-picker__slider-handle");
|
1750 | const { width } = container.getBoundingClientRect();
|
1751 | handle.focus();
|
1752 | event.preventDefault();
|
1753 | drag(container, {
|
1754 | onMove: (x) => {
|
1755 | this.hue = clamp(x / width * 360, 0, 360);
|
1756 | this.syncValues();
|
1757 | },
|
1758 | initialEvent: event
|
1759 | });
|
1760 | }
|
1761 | handleGridDrag(event) {
|
1762 | const grid = this.shadowRoot.querySelector(".color-picker__grid");
|
1763 | const handle = grid.querySelector(".color-picker__grid-handle");
|
1764 | const { width, height } = grid.getBoundingClientRect();
|
1765 | handle.focus();
|
1766 | event.preventDefault();
|
1767 | this.isDraggingGridHandle = true;
|
1768 | drag(grid, {
|
1769 | onMove: (x, y) => {
|
1770 | this.saturation = clamp(x / width * 100, 0, 100);
|
1771 | this.brightness = clamp(100 - y / height * 100, 0, 100);
|
1772 | this.lightness = this.getLightness(this.brightness);
|
1773 | this.syncValues();
|
1774 | },
|
1775 | onStop: () => this.isDraggingGridHandle = false,
|
1776 | initialEvent: event
|
1777 | });
|
1778 | }
|
1779 | handleAlphaKeyDown(event) {
|
1780 | const increment = event.shiftKey ? 10 : 1;
|
1781 | if (event.key === "ArrowLeft") {
|
1782 | event.preventDefault();
|
1783 | this.alpha = clamp(this.alpha - increment, 0, 100);
|
1784 | this.syncValues();
|
1785 | }
|
1786 | if (event.key === "ArrowRight") {
|
1787 | event.preventDefault();
|
1788 | this.alpha = clamp(this.alpha + increment, 0, 100);
|
1789 | this.syncValues();
|
1790 | }
|
1791 | if (event.key === "Home") {
|
1792 | event.preventDefault();
|
1793 | this.alpha = 0;
|
1794 | this.syncValues();
|
1795 | }
|
1796 | if (event.key === "End") {
|
1797 | event.preventDefault();
|
1798 | this.alpha = 100;
|
1799 | this.syncValues();
|
1800 | }
|
1801 | }
|
1802 | handleHueKeyDown(event) {
|
1803 | const increment = event.shiftKey ? 10 : 1;
|
1804 | if (event.key === "ArrowLeft") {
|
1805 | event.preventDefault();
|
1806 | this.hue = clamp(this.hue - increment, 0, 360);
|
1807 | this.syncValues();
|
1808 | }
|
1809 | if (event.key === "ArrowRight") {
|
1810 | event.preventDefault();
|
1811 | this.hue = clamp(this.hue + increment, 0, 360);
|
1812 | this.syncValues();
|
1813 | }
|
1814 | if (event.key === "Home") {
|
1815 | event.preventDefault();
|
1816 | this.hue = 0;
|
1817 | this.syncValues();
|
1818 | }
|
1819 | if (event.key === "End") {
|
1820 | event.preventDefault();
|
1821 | this.hue = 360;
|
1822 | this.syncValues();
|
1823 | }
|
1824 | }
|
1825 | handleGridKeyDown(event) {
|
1826 | const increment = event.shiftKey ? 10 : 1;
|
1827 | if (event.key === "ArrowLeft") {
|
1828 | event.preventDefault();
|
1829 | this.saturation = clamp(this.saturation - increment, 0, 100);
|
1830 | this.syncValues();
|
1831 | }
|
1832 | if (event.key === "ArrowRight") {
|
1833 | event.preventDefault();
|
1834 | this.saturation = clamp(this.saturation + increment, 0, 100);
|
1835 | this.syncValues();
|
1836 | }
|
1837 | if (event.key === "ArrowUp") {
|
1838 | event.preventDefault();
|
1839 | this.brightness = clamp(this.brightness + increment, 0, 100);
|
1840 | this.lightness = this.getLightness(this.brightness);
|
1841 | this.syncValues();
|
1842 | }
|
1843 | if (event.key === "ArrowDown") {
|
1844 | event.preventDefault();
|
1845 | this.brightness = clamp(this.brightness - increment, 0, 100);
|
1846 | this.lightness = this.getLightness(this.brightness);
|
1847 | this.syncValues();
|
1848 | }
|
1849 | }
|
1850 | handleInputChange(event) {
|
1851 | const target = event.target;
|
1852 | if (this.input.value) {
|
1853 | this.setColor(target.value);
|
1854 | target.value = this.value;
|
1855 | } else {
|
1856 | this.value = "";
|
1857 | }
|
1858 | event.stopPropagation();
|
1859 | }
|
1860 | handleInputKeyDown(event) {
|
1861 | if (event.key === "Enter") {
|
1862 | if (this.input.value) {
|
1863 | this.setColor(this.input.value);
|
1864 | this.input.value = this.value;
|
1865 | setTimeout(() => this.input.select());
|
1866 | } else {
|
1867 | this.hue = 0;
|
1868 | }
|
1869 | }
|
1870 | }
|
1871 | normalizeColorString(colorString) {
|
1872 | if (/rgba?/i.test(colorString)) {
|
1873 | const rgba = colorString.replace(/[^\d.%]/g, " ").split(" ").map((val) => val.trim()).filter((val) => val.length);
|
1874 | if (rgba.length < 4) {
|
1875 | rgba[3] = "1";
|
1876 | }
|
1877 | if (rgba[3].indexOf("%") > -1) {
|
1878 | rgba[3] = (parseFloat(rgba[3].replace(/%/g, "")) / 100).toString();
|
1879 | }
|
1880 | return `rgba(${rgba[0]}, ${rgba[1]}, ${rgba[2]}, ${rgba[3]})`;
|
1881 | }
|
1882 | if (/hsla?/i.test(colorString)) {
|
1883 | const hsla = colorString.replace(/[^\d.%]/g, " ").split(" ").map((val) => val.trim()).filter((val) => val.length);
|
1884 | if (hsla.length < 4) {
|
1885 | hsla[3] = "1";
|
1886 | }
|
1887 | if (hsla[3].indexOf("%") > -1) {
|
1888 | hsla[3] = (parseFloat(hsla[3].replace(/%/g, "")) / 100).toString();
|
1889 | }
|
1890 | return `hsla(${hsla[0]}, ${hsla[1]}, ${hsla[2]}, ${hsla[3]})`;
|
1891 | }
|
1892 | if (/^[0-9a-f]+$/i.test(colorString)) {
|
1893 | return `#${colorString}`;
|
1894 | }
|
1895 | return colorString;
|
1896 | }
|
1897 | parseColor(colorString) {
|
1898 | let parsed;
|
1899 | colorString = this.normalizeColorString(colorString);
|
1900 | try {
|
1901 | parsed = (0, import_color.default)(colorString);
|
1902 | } catch (e2) {
|
1903 | return null;
|
1904 | }
|
1905 | const hslColor = parsed.hsl();
|
1906 | const hsl = {
|
1907 | h: hslColor.hue(),
|
1908 | s: hslColor.saturationl(),
|
1909 | l: hslColor.lightness(),
|
1910 | a: hslColor.alpha()
|
1911 | };
|
1912 | const rgbColor = parsed.rgb();
|
1913 | const rgb = {
|
1914 | r: rgbColor.red(),
|
1915 | g: rgbColor.green(),
|
1916 | b: rgbColor.blue(),
|
1917 | a: rgbColor.alpha()
|
1918 | };
|
1919 | const hex = {
|
1920 | r: toHex(rgb.r),
|
1921 | g: toHex(rgb.g),
|
1922 | b: toHex(rgb.b),
|
1923 | a: toHex(rgb.a * 255)
|
1924 | };
|
1925 | return {
|
1926 | hsl: {
|
1927 | h: hsl.h,
|
1928 | s: hsl.s,
|
1929 | l: hsl.l,
|
1930 | string: this.setLetterCase(`hsl(${Math.round(hsl.h)}, ${Math.round(hsl.s)}%, ${Math.round(hsl.l)}%)`)
|
1931 | },
|
1932 | hsla: {
|
1933 | h: hsl.h,
|
1934 | s: hsl.s,
|
1935 | l: hsl.l,
|
1936 | a: hsl.a,
|
1937 | string: this.setLetterCase(`hsla(${Math.round(hsl.h)}, ${Math.round(hsl.s)}%, ${Math.round(hsl.l)}%, ${hsl.a.toFixed(2).toString()})`)
|
1938 | },
|
1939 | rgb: {
|
1940 | r: rgb.r,
|
1941 | g: rgb.g,
|
1942 | b: rgb.b,
|
1943 | string: this.setLetterCase(`rgb(${Math.round(rgb.r)}, ${Math.round(rgb.g)}, ${Math.round(rgb.b)})`)
|
1944 | },
|
1945 | rgba: {
|
1946 | r: rgb.r,
|
1947 | g: rgb.g,
|
1948 | b: rgb.b,
|
1949 | a: rgb.a,
|
1950 | string: this.setLetterCase(`rgba(${Math.round(rgb.r)}, ${Math.round(rgb.g)}, ${Math.round(rgb.b)}, ${rgb.a.toFixed(2).toString()})`)
|
1951 | },
|
1952 | hex: this.setLetterCase(`#${hex.r}${hex.g}${hex.b}`),
|
1953 | hexa: this.setLetterCase(`#${hex.r}${hex.g}${hex.b}${hex.a}`)
|
1954 | };
|
1955 | }
|
1956 | setColor(colorString) {
|
1957 | const newColor = this.parseColor(colorString);
|
1958 | if (newColor === null) {
|
1959 | return false;
|
1960 | }
|
1961 | this.hue = newColor.hsla.h;
|
1962 | this.saturation = newColor.hsla.s;
|
1963 | this.lightness = newColor.hsla.l;
|
1964 | this.brightness = this.getBrightness(newColor.hsla.l);
|
1965 | this.alpha = this.opacity ? newColor.hsla.a * 100 : 100;
|
1966 | this.syncValues();
|
1967 | return true;
|
1968 | }
|
1969 | setLetterCase(string) {
|
1970 | if (typeof string !== "string") {
|
1971 | return "";
|
1972 | }
|
1973 | return this.uppercase ? string.toUpperCase() : string.toLowerCase();
|
1974 | }
|
1975 | async syncValues() {
|
1976 | const currentColor = this.parseColor(`hsla(${this.hue}, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`);
|
1977 | if (currentColor === null) {
|
1978 | return;
|
1979 | }
|
1980 | if (this.format === "hsl") {
|
1981 | this.inputValue = this.opacity ? currentColor.hsla.string : currentColor.hsl.string;
|
1982 | } else if (this.format === "rgb") {
|
1983 | this.inputValue = this.opacity ? currentColor.rgba.string : currentColor.rgb.string;
|
1984 | } else {
|
1985 | this.inputValue = this.opacity ? currentColor.hexa : currentColor.hex;
|
1986 | }
|
1987 | this.isSafeValue = true;
|
1988 | this.value = this.inputValue;
|
1989 | await this.updateComplete;
|
1990 | this.isSafeValue = false;
|
1991 | }
|
1992 | handleAfterHide() {
|
1993 | this.previewButton.classList.remove("color-picker__preview-color--copied");
|
1994 | }
|
1995 | handleEyeDropper() {
|
1996 | if (!hasEyeDropper) {
|
1997 | return;
|
1998 | }
|
1999 | const eyeDropper = new EyeDropper();
|
2000 | eyeDropper.open().then((colorSelectionResult) => this.setColor(colorSelectionResult.sRGBHex)).catch(() => {
|
2001 | });
|
2002 | }
|
2003 | handleFormatChange() {
|
2004 | this.syncValues();
|
2005 | }
|
2006 | handleOpacityChange() {
|
2007 | this.alpha = 100;
|
2008 | }
|
2009 | handleValueChange(oldValue, newValue) {
|
2010 | this.isEmpty = !newValue;
|
2011 | if (!newValue) {
|
2012 | this.hue = 0;
|
2013 | this.saturation = 100;
|
2014 | this.brightness = 100;
|
2015 | this.lightness = this.getLightness(this.brightness);
|
2016 | this.alpha = 100;
|
2017 | }
|
2018 | if (!this.isSafeValue && oldValue !== void 0) {
|
2019 | const newColor = this.parseColor(newValue);
|
2020 | if (newColor !== null) {
|
2021 | this.inputValue = this.value;
|
2022 | this.hue = newColor.hsla.h;
|
2023 | this.saturation = newColor.hsla.s;
|
2024 | this.lightness = newColor.hsla.l;
|
2025 | this.brightness = this.getBrightness(newColor.hsla.l);
|
2026 | this.alpha = newColor.hsla.a * 100;
|
2027 | } else {
|
2028 | this.inputValue = oldValue;
|
2029 | }
|
2030 | }
|
2031 | if (this.value !== this.lastValueEmitted) {
|
2032 | emit(this, "sl-change");
|
2033 | this.lastValueEmitted = this.value;
|
2034 | }
|
2035 | }
|
2036 | render() {
|
2037 | const gridHandleX = this.saturation;
|
2038 | const gridHandleY = 100 - this.brightness;
|
2039 | const colorPicker = $`
|
2040 | <div
|
2041 | part="base"
|
2042 | class=${o({
|
2043 | "color-picker": true,
|
2044 | "color-picker--inline": this.inline,
|
2045 | "color-picker--disabled": this.disabled
|
2046 | })}
|
2047 | aria-disabled=${this.disabled ? "true" : "false"}
|
2048 | aria-labelledby="label"
|
2049 | tabindex=${this.inline ? "0" : "-1"}
|
2050 | >
|
2051 | ${this.inline ? $`
|
2052 | <sl-visually-hidden id="label">
|
2053 | <slot name="label">${this.label}</slot>
|
2054 | </sl-visually-hidden>
|
2055 | ` : null}
|
2056 |
|
2057 | <div
|
2058 | part="grid"
|
2059 | class="color-picker__grid"
|
2060 | style=${i2({ backgroundColor: `hsl(${this.hue}deg, 100%, 50%)` })}
|
2061 | @mousedown=${this.handleGridDrag}
|
2062 | @touchstart=${this.handleGridDrag}
|
2063 | >
|
2064 | <span
|
2065 | part="grid-handle"
|
2066 | class=${o({
|
2067 | "color-picker__grid-handle": true,
|
2068 | "color-picker__grid-handle--dragging": this.isDraggingGridHandle
|
2069 | })}
|
2070 | style=${i2({
|
2071 | top: `${gridHandleY}%`,
|
2072 | left: `${gridHandleX}%`,
|
2073 | backgroundColor: `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`
|
2074 | })}
|
2075 | role="application"
|
2076 | aria-label="HSL"
|
2077 | tabindex=${l(this.disabled ? void 0 : "0")}
|
2078 | @keydown=${this.handleGridKeyDown}
|
2079 | ></span>
|
2080 | </div>
|
2081 |
|
2082 | <div class="color-picker__controls">
|
2083 | <div class="color-picker__sliders">
|
2084 | <div
|
2085 | part="slider hue-slider"
|
2086 | class="color-picker__hue color-picker__slider"
|
2087 | @mousedown=${this.handleHueDrag}
|
2088 | @touchstart=${this.handleHueDrag}
|
2089 | >
|
2090 | <span
|
2091 | part="slider-handle"
|
2092 | class="color-picker__slider-handle"
|
2093 | style=${i2({
|
2094 | left: `${this.hue === 0 ? 0 : 100 / (360 / this.hue)}%`
|
2095 | })}
|
2096 | role="slider"
|
2097 | aria-label="hue"
|
2098 | aria-orientation="horizontal"
|
2099 | aria-valuemin="0"
|
2100 | aria-valuemax="360"
|
2101 | aria-valuenow=${`${Math.round(this.hue)}`}
|
2102 | tabindex=${l(this.disabled ? void 0 : "0")}
|
2103 | @keydown=${this.handleHueKeyDown}
|
2104 | ></span>
|
2105 | </div>
|
2106 |
|
2107 | ${this.opacity ? $`
|
2108 | <div
|
2109 | part="slider opacity-slider"
|
2110 | class="color-picker__alpha color-picker__slider color-picker__transparent-bg"
|
2111 | @mousedown="${this.handleAlphaDrag}"
|
2112 | @touchstart="${this.handleAlphaDrag}"
|
2113 | >
|
2114 | <div
|
2115 | class="color-picker__alpha-gradient"
|
2116 | style=${i2({
|
2117 | backgroundImage: `linear-gradient(
|
2118 | to right,
|
2119 | hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, 0%) 0%,
|
2120 | hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%) 100%
|
2121 | )`
|
2122 | })}
|
2123 | ></div>
|
2124 | <span
|
2125 | part="slider-handle"
|
2126 | class="color-picker__slider-handle"
|
2127 | style=${i2({
|
2128 | left: `${this.alpha}%`
|
2129 | })}
|
2130 | role="slider"
|
2131 | aria-label="alpha"
|
2132 | aria-orientation="horizontal"
|
2133 | aria-valuemin="0"
|
2134 | aria-valuemax="100"
|
2135 | aria-valuenow=${Math.round(this.alpha)}
|
2136 | tabindex=${l(this.disabled ? void 0 : "0")}
|
2137 | @keydown=${this.handleAlphaKeyDown}
|
2138 | ></span>
|
2139 | </div>
|
2140 | ` : ""}
|
2141 | </div>
|
2142 |
|
2143 | <button
|
2144 | type="button"
|
2145 | part="preview"
|
2146 | class="color-picker__preview color-picker__transparent-bg"
|
2147 | aria-label=${this.localize.term("copy")}
|
2148 | style=${i2({
|
2149 | "--preview-color": `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
|
2150 | })}
|
2151 | @click=${this.handleCopy}
|
2152 | ></button>
|
2153 | </div>
|
2154 |
|
2155 | <div class="color-picker__user-input" aria-live="polite">
|
2156 | <sl-input
|
2157 | part="input"
|
2158 | type="text"
|
2159 | name=${this.name}
|
2160 | autocomplete="off"
|
2161 | autocorrect="off"
|
2162 | autocapitalize="off"
|
2163 | spellcheck="false"
|
2164 | .value=${l2(this.isEmpty ? "" : this.inputValue)}
|
2165 | ?disabled=${this.disabled}
|
2166 | aria-label=${this.localize.term("currentValue")}
|
2167 | @keydown=${this.handleInputKeyDown}
|
2168 | @sl-change=${this.handleInputChange}
|
2169 | ></sl-input>
|
2170 |
|
2171 | <sl-button-group>
|
2172 | ${!this.noFormatToggle ? $`
|
2173 | <sl-button
|
2174 | part="format-button"
|
2175 | aria-label=${this.localize.term("toggleColorFormat")}
|
2176 | exportparts="
|
2177 | base:format-button__base,
|
2178 | prefix:format-button__prefix,
|
2179 | label:format-button__label,
|
2180 | suffix:format-button__suffix,
|
2181 | caret:format-button__caret
|
2182 | "
|
2183 | @click=${this.handleFormatToggle}
|
2184 | >
|
2185 | ${this.setLetterCase(this.format)}
|
2186 | </sl-button>
|
2187 | ` : ""}
|
2188 | ${hasEyeDropper ? $`
|
2189 | <sl-button
|
2190 | part="eye-dropper-button"
|
2191 | exportparts="
|
2192 | base:eye-dropper-button__base,
|
2193 | prefix:eye-dropper-button__prefix,
|
2194 | label:eye-dropper-button__label,
|
2195 | suffix:eye-dropper-button__suffix,
|
2196 | caret:eye-dropper-button__caret
|
2197 | "
|
2198 | @click=${this.handleEyeDropper}
|
2199 | >
|
2200 | <sl-icon
|
2201 | library="system"
|
2202 | name="eyedropper"
|
2203 | label=${this.localize.term("selectAColorFromTheScreen")}
|
2204 | ></sl-icon>
|
2205 | </sl-button>
|
2206 | ` : ""}
|
2207 | </sl-button-group>
|
2208 | </div>
|
2209 |
|
2210 | ${this.swatches.length > 0 ? $`
|
2211 | <div part="swatches" class="color-picker__swatches">
|
2212 | ${this.swatches.map((swatch) => {
|
2213 | return $`
|
2214 | <div
|
2215 | part="swatch"
|
2216 | class="color-picker__swatch color-picker__transparent-bg"
|
2217 | tabindex=${l(this.disabled ? void 0 : "0")}
|
2218 | role="button"
|
2219 | aria-label=${swatch}
|
2220 | @click=${() => !this.disabled && this.setColor(swatch)}
|
2221 | @keydown=${(event) => !this.disabled && event.key === "Enter" && this.setColor(swatch)}
|
2222 | >
|
2223 | <div class="color-picker__swatch-color" style=${i2({ backgroundColor: swatch })}></div>
|
2224 | </div>
|
2225 | `;
|
2226 | })}
|
2227 | </div>
|
2228 | ` : ""}
|
2229 | </div>
|
2230 | `;
|
2231 | if (this.inline) {
|
2232 | return colorPicker;
|
2233 | }
|
2234 | return $`
|
2235 | <sl-dropdown
|
2236 | class="color-dropdown"
|
2237 | aria-disabled=${this.disabled ? "true" : "false"}
|
2238 | .containing-element=${this}
|
2239 | ?disabled=${this.disabled}
|
2240 | ?hoist=${this.hoist}
|
2241 | @sl-after-hide=${this.handleAfterHide}
|
2242 | >
|
2243 | <button
|
2244 | part="trigger"
|
2245 | slot="trigger"
|
2246 | class=${o({
|
2247 | "color-dropdown__trigger": true,
|
2248 | "color-dropdown__trigger--disabled": this.disabled,
|
2249 | "color-dropdown__trigger--small": this.size === "small",
|
2250 | "color-dropdown__trigger--medium": this.size === "medium",
|
2251 | "color-dropdown__trigger--large": this.size === "large",
|
2252 | "color-dropdown__trigger--empty": this.isEmpty,
|
2253 | "color-picker__transparent-bg": true
|
2254 | })}
|
2255 | style=${i2({
|
2256 | color: `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${this.alpha / 100})`
|
2257 | })}
|
2258 | type="button"
|
2259 | >
|
2260 | <sl-visually-hidden>
|
2261 | <slot name="label">${this.label}</slot>
|
2262 | </sl-visually-hidden>
|
2263 | </button>
|
2264 | ${colorPicker}
|
2265 | </sl-dropdown>
|
2266 | `;
|
2267 | }
|
2268 | };
|
2269 | SlColorPicker.styles = color_picker_styles_default;
|
2270 | __decorateClass([
|
2271 | i('[part="input"]')
|
2272 | ], SlColorPicker.prototype, "input", 2);
|
2273 | __decorateClass([
|
2274 | i('[part="preview"]')
|
2275 | ], SlColorPicker.prototype, "previewButton", 2);
|
2276 | __decorateClass([
|
2277 | i(".color-dropdown")
|
2278 | ], SlColorPicker.prototype, "dropdown", 2);
|
2279 | __decorateClass([
|
2280 | t()
|
2281 | ], SlColorPicker.prototype, "isDraggingGridHandle", 2);
|
2282 | __decorateClass([
|
2283 | t()
|
2284 | ], SlColorPicker.prototype, "isEmpty", 2);
|
2285 | __decorateClass([
|
2286 | t()
|
2287 | ], SlColorPicker.prototype, "inputValue", 2);
|
2288 | __decorateClass([
|
2289 | t()
|
2290 | ], SlColorPicker.prototype, "hue", 2);
|
2291 | __decorateClass([
|
2292 | t()
|
2293 | ], SlColorPicker.prototype, "saturation", 2);
|
2294 | __decorateClass([
|
2295 | t()
|
2296 | ], SlColorPicker.prototype, "lightness", 2);
|
2297 | __decorateClass([
|
2298 | t()
|
2299 | ], SlColorPicker.prototype, "brightness", 2);
|
2300 | __decorateClass([
|
2301 | t()
|
2302 | ], SlColorPicker.prototype, "alpha", 2);
|
2303 | __decorateClass([
|
2304 | e()
|
2305 | ], SlColorPicker.prototype, "value", 2);
|
2306 | __decorateClass([
|
2307 | defaultValue()
|
2308 | ], SlColorPicker.prototype, "defaultValue", 2);
|
2309 | __decorateClass([
|
2310 | e()
|
2311 | ], SlColorPicker.prototype, "label", 2);
|
2312 | __decorateClass([
|
2313 | e()
|
2314 | ], SlColorPicker.prototype, "format", 2);
|
2315 | __decorateClass([
|
2316 | e({ type: Boolean, reflect: true })
|
2317 | ], SlColorPicker.prototype, "inline", 2);
|
2318 | __decorateClass([
|
2319 | e()
|
2320 | ], SlColorPicker.prototype, "size", 2);
|
2321 | __decorateClass([
|
2322 | e({ attribute: "no-format-toggle", type: Boolean })
|
2323 | ], SlColorPicker.prototype, "noFormatToggle", 2);
|
2324 | __decorateClass([
|
2325 | e()
|
2326 | ], SlColorPicker.prototype, "name", 2);
|
2327 | __decorateClass([
|
2328 | e({ type: Boolean, reflect: true })
|
2329 | ], SlColorPicker.prototype, "disabled", 2);
|
2330 | __decorateClass([
|
2331 | e({ type: Boolean, reflect: true })
|
2332 | ], SlColorPicker.prototype, "invalid", 2);
|
2333 | __decorateClass([
|
2334 | e({ type: Boolean })
|
2335 | ], SlColorPicker.prototype, "hoist", 2);
|
2336 | __decorateClass([
|
2337 | e({ type: Boolean })
|
2338 | ], SlColorPicker.prototype, "opacity", 2);
|
2339 | __decorateClass([
|
2340 | e({ type: Boolean })
|
2341 | ], SlColorPicker.prototype, "uppercase", 2);
|
2342 | __decorateClass([
|
2343 | e({ attribute: false })
|
2344 | ], SlColorPicker.prototype, "swatches", 2);
|
2345 | __decorateClass([
|
2346 | e()
|
2347 | ], SlColorPicker.prototype, "lang", 2);
|
2348 | __decorateClass([
|
2349 | watch("format", { waitUntilFirstUpdate: true })
|
2350 | ], SlColorPicker.prototype, "handleFormatChange", 1);
|
2351 | __decorateClass([
|
2352 | watch("opacity")
|
2353 | ], SlColorPicker.prototype, "handleOpacityChange", 1);
|
2354 | __decorateClass([
|
2355 | watch("value")
|
2356 | ], SlColorPicker.prototype, "handleValueChange", 1);
|
2357 | SlColorPicker = __decorateClass([
|
2358 | n("sl-color-picker")
|
2359 | ], SlColorPicker);
|
2360 | function toHex(value) {
|
2361 | const hex = Math.round(value).toString(16);
|
2362 | return hex.length === 1 ? `0${hex}` : hex;
|
2363 | }
|
2364 |
|
2365 | export {
|
2366 | SlColorPicker
|
2367 | };
|
2368 |
|
\ | No newline at end of file |