@c2n/color-select 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1344 @@
1
+ import { LitElement, html, nothing, unsafeCSS } from "lit";
2
+ import { customElement, property, query, state } from "lit/decorators.js";
3
+ import "@c2n/overlay";
4
+ import "@c2n/color-area";
5
+ import "@c2n/select";
6
+ import "@c2n/text-field";
7
+ import "@c2n/color-slider";
8
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/util.js
9
+ /**
10
+ * Take input from [0, n] and return it as [0, 1]
11
+ * @hidden
12
+ */
13
+ function bound01(n, max) {
14
+ if (isOnePointZero(n)) n = "100%";
15
+ const isPercent = isPercentage(n);
16
+ n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n)));
17
+ if (isPercent) n = parseInt(String(n * max), 10) / 100;
18
+ if (Math.abs(n - max) < 1e-6) return 1;
19
+ if (max === 360) n = (n < 0 ? n % max + max : n % max) / parseFloat(String(max));
20
+ else n = n % max / parseFloat(String(max));
21
+ return n;
22
+ }
23
+ /**
24
+ * Force a number between 0 and 1
25
+ * @hidden
26
+ */
27
+ function clamp01(val) {
28
+ return Math.min(1, Math.max(0, val));
29
+ }
30
+ /**
31
+ * Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
32
+ * <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
33
+ * @hidden
34
+ */
35
+ function isOnePointZero(n) {
36
+ return typeof n === "string" && n.indexOf(".") !== -1 && parseFloat(n) === 1;
37
+ }
38
+ /**
39
+ * Check to see if string passed in is a percentage
40
+ * @hidden
41
+ */
42
+ function isPercentage(n) {
43
+ return typeof n === "string" && n.indexOf("%") !== -1;
44
+ }
45
+ /**
46
+ * Return a valid alpha value [0,1] with all invalid values being set to 1
47
+ * @hidden
48
+ */
49
+ function boundAlpha(a) {
50
+ a = parseFloat(a);
51
+ if (isNaN(a) || a < 0 || a > 1) a = 1;
52
+ return a;
53
+ }
54
+ /**
55
+ * Replace a decimal with it's percentage value
56
+ * @hidden
57
+ */
58
+ function convertToPercentage(n) {
59
+ if (Number(n) <= 1) return `${Number(n) * 100}%`;
60
+ return n;
61
+ }
62
+ /**
63
+ * Force a hex value to have 2 characters
64
+ * @hidden
65
+ */
66
+ function pad2(c) {
67
+ return c.length === 1 ? "0" + c : String(c);
68
+ }
69
+ //#endregion
70
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/conversion.js
71
+ /**
72
+ * Handle bounds / percentage checking to conform to CSS color spec
73
+ * <http://www.w3.org/TR/css3-color/>
74
+ * *Assumes:* r, g, b in [0, 255] or [0, 1]
75
+ * *Returns:* { r, g, b } in [0, 255]
76
+ */
77
+ function rgbToRgb(r, g, b) {
78
+ return {
79
+ r: bound01(r, 255) * 255,
80
+ g: bound01(g, 255) * 255,
81
+ b: bound01(b, 255) * 255
82
+ };
83
+ }
84
+ /**
85
+ * Converts an RGB color value to HSL.
86
+ * *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
87
+ * *Returns:* { h, s, l } in [0,1]
88
+ */
89
+ function rgbToHsl(r, g, b) {
90
+ r = bound01(r, 255);
91
+ g = bound01(g, 255);
92
+ b = bound01(b, 255);
93
+ const max = Math.max(r, g, b);
94
+ const min = Math.min(r, g, b);
95
+ let h = 0;
96
+ let s = 0;
97
+ const l = (max + min) / 2;
98
+ if (max === min) {
99
+ s = 0;
100
+ h = 0;
101
+ } else {
102
+ const d = max - min;
103
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
104
+ switch (max) {
105
+ case r:
106
+ h = (g - b) / d + (g < b ? 6 : 0);
107
+ break;
108
+ case g:
109
+ h = (b - r) / d + 2;
110
+ break;
111
+ case b: h = (r - g) / d + 4;
112
+ }
113
+ h /= 6;
114
+ }
115
+ return {
116
+ h,
117
+ s,
118
+ l
119
+ };
120
+ }
121
+ function hue2rgb(p, q, t) {
122
+ if (t < 0) t += 1;
123
+ if (t > 1) t -= 1;
124
+ if (t < 1 / 6) return p + (q - p) * (6 * t);
125
+ if (t < 1 / 2) return q;
126
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
127
+ return p;
128
+ }
129
+ /**
130
+ * Converts an HSL color value to RGB.
131
+ *
132
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
133
+ * *Returns:* { r, g, b } in the set [0, 255]
134
+ */
135
+ function hslToRgb(h, s, l) {
136
+ let r;
137
+ let g;
138
+ let b;
139
+ h = bound01(h, 360);
140
+ s = bound01(s, 100);
141
+ l = bound01(l, 100);
142
+ if (s === 0) {
143
+ g = l;
144
+ b = l;
145
+ r = l;
146
+ } else {
147
+ const q = l < .5 ? l * (1 + s) : l + s - l * s;
148
+ const p = 2 * l - q;
149
+ r = hue2rgb(p, q, h + 1 / 3);
150
+ g = hue2rgb(p, q, h);
151
+ b = hue2rgb(p, q, h - 1 / 3);
152
+ }
153
+ return {
154
+ r: r * 255,
155
+ g: g * 255,
156
+ b: b * 255
157
+ };
158
+ }
159
+ /**
160
+ * Converts an RGB color value to HSV
161
+ *
162
+ * *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
163
+ * *Returns:* { h, s, v } in [0,1]
164
+ */
165
+ function rgbToHsv(r, g, b) {
166
+ r = bound01(r, 255);
167
+ g = bound01(g, 255);
168
+ b = bound01(b, 255);
169
+ const max = Math.max(r, g, b);
170
+ const min = Math.min(r, g, b);
171
+ let h = 0;
172
+ const v = max;
173
+ const d = max - min;
174
+ const s = max === 0 ? 0 : d / max;
175
+ if (max === min) h = 0;
176
+ else {
177
+ switch (max) {
178
+ case r:
179
+ h = (g - b) / d + (g < b ? 6 : 0);
180
+ break;
181
+ case g:
182
+ h = (b - r) / d + 2;
183
+ break;
184
+ case b: h = (r - g) / d + 4;
185
+ }
186
+ h /= 6;
187
+ }
188
+ return {
189
+ h,
190
+ s,
191
+ v
192
+ };
193
+ }
194
+ /**
195
+ * Converts an HSV color value to RGB.
196
+ *
197
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
198
+ * *Returns:* { r, g, b } in the set [0, 255]
199
+ */
200
+ function hsvToRgb(h, s, v) {
201
+ h = bound01(h, 360) * 6;
202
+ s = bound01(s, 100);
203
+ v = bound01(v, 100);
204
+ const i = Math.floor(h);
205
+ const f = h - i;
206
+ const p = v * (1 - s);
207
+ const q = v * (1 - f * s);
208
+ const t = v * (1 - (1 - f) * s);
209
+ const mod = i % 6;
210
+ const r = [
211
+ v,
212
+ q,
213
+ p,
214
+ p,
215
+ t,
216
+ v
217
+ ][mod];
218
+ const g = [
219
+ t,
220
+ v,
221
+ v,
222
+ q,
223
+ p,
224
+ p
225
+ ][mod];
226
+ const b = [
227
+ p,
228
+ p,
229
+ t,
230
+ v,
231
+ v,
232
+ q
233
+ ][mod];
234
+ return {
235
+ r: r * 255,
236
+ g: g * 255,
237
+ b: b * 255
238
+ };
239
+ }
240
+ /**
241
+ * Converts an RGB color to hex
242
+ *
243
+ * *Assumes:* r, g, and b are contained in the set [0, 255]
244
+ * *Returns:* a 3 or 6 character hex
245
+ */
246
+ function rgbToHex(r, g, b, allow3Char) {
247
+ const hex = [
248
+ pad2(Math.round(r).toString(16)),
249
+ pad2(Math.round(g).toString(16)),
250
+ pad2(Math.round(b).toString(16))
251
+ ];
252
+ if (allow3Char && hex[0].startsWith(hex[0].charAt(1)) && hex[1].startsWith(hex[1].charAt(1)) && hex[2].startsWith(hex[2].charAt(1))) return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
253
+ return hex.join("");
254
+ }
255
+ /**
256
+ * Converts an RGBA color plus alpha transparency to hex
257
+ *
258
+ * *Assumes:* r, g, b are contained in the set [0, 255] and a in [0, 1]
259
+ * *Returns:* a 4 or 8 character rgba hex
260
+ */
261
+ function rgbaToHex(r, g, b, a, allow4Char) {
262
+ const hex = [
263
+ pad2(Math.round(r).toString(16)),
264
+ pad2(Math.round(g).toString(16)),
265
+ pad2(Math.round(b).toString(16)),
266
+ pad2(convertDecimalToHex(a))
267
+ ];
268
+ if (allow4Char && hex[0].startsWith(hex[0].charAt(1)) && hex[1].startsWith(hex[1].charAt(1)) && hex[2].startsWith(hex[2].charAt(1)) && hex[3].startsWith(hex[3].charAt(1))) return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
269
+ return hex.join("");
270
+ }
271
+ /**
272
+ * Converts CMYK to RBG
273
+ * Assumes c, m, y, k are in the set [0, 100]
274
+ */
275
+ function cmykToRgb(c, m, y, k) {
276
+ const cConv = c / 100;
277
+ const mConv = m / 100;
278
+ const yConv = y / 100;
279
+ const kConv = k / 100;
280
+ return {
281
+ r: 255 * (1 - cConv) * (1 - kConv),
282
+ g: 255 * (1 - mConv) * (1 - kConv),
283
+ b: 255 * (1 - yConv) * (1 - kConv)
284
+ };
285
+ }
286
+ function rgbToCmyk(r, g, b) {
287
+ let c = 1 - r / 255;
288
+ let m = 1 - g / 255;
289
+ let y = 1 - b / 255;
290
+ let k = Math.min(c, m, y);
291
+ if (k === 1) {
292
+ c = 0;
293
+ m = 0;
294
+ y = 0;
295
+ } else {
296
+ c = (c - k) / (1 - k) * 100;
297
+ m = (m - k) / (1 - k) * 100;
298
+ y = (y - k) / (1 - k) * 100;
299
+ }
300
+ k *= 100;
301
+ return {
302
+ c: Math.round(c),
303
+ m: Math.round(m),
304
+ y: Math.round(y),
305
+ k: Math.round(k)
306
+ };
307
+ }
308
+ /** Converts a decimal to a hex value */
309
+ function convertDecimalToHex(d) {
310
+ return Math.round(parseFloat(d) * 255).toString(16);
311
+ }
312
+ /** Converts a hex value to a decimal */
313
+ function convertHexToDecimal(h) {
314
+ return parseIntFromHex(h) / 255;
315
+ }
316
+ /** Parse a base-16 hex value into a base-10 integer */
317
+ function parseIntFromHex(val) {
318
+ return parseInt(val, 16);
319
+ }
320
+ function numberInputToObject(color) {
321
+ return {
322
+ r: color >> 16,
323
+ g: (color & 65280) >> 8,
324
+ b: color & 255
325
+ };
326
+ }
327
+ //#endregion
328
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/css-color-names.js
329
+ /**
330
+ * @hidden
331
+ */
332
+ var names = {
333
+ aliceblue: "#f0f8ff",
334
+ antiquewhite: "#faebd7",
335
+ aqua: "#00ffff",
336
+ aquamarine: "#7fffd4",
337
+ azure: "#f0ffff",
338
+ beige: "#f5f5dc",
339
+ bisque: "#ffe4c4",
340
+ black: "#000000",
341
+ blanchedalmond: "#ffebcd",
342
+ blue: "#0000ff",
343
+ blueviolet: "#8a2be2",
344
+ brown: "#a52a2a",
345
+ burlywood: "#deb887",
346
+ cadetblue: "#5f9ea0",
347
+ chartreuse: "#7fff00",
348
+ chocolate: "#d2691e",
349
+ coral: "#ff7f50",
350
+ cornflowerblue: "#6495ed",
351
+ cornsilk: "#fff8dc",
352
+ crimson: "#dc143c",
353
+ cyan: "#00ffff",
354
+ darkblue: "#00008b",
355
+ darkcyan: "#008b8b",
356
+ darkgoldenrod: "#b8860b",
357
+ darkgray: "#a9a9a9",
358
+ darkgreen: "#006400",
359
+ darkgrey: "#a9a9a9",
360
+ darkkhaki: "#bdb76b",
361
+ darkmagenta: "#8b008b",
362
+ darkolivegreen: "#556b2f",
363
+ darkorange: "#ff8c00",
364
+ darkorchid: "#9932cc",
365
+ darkred: "#8b0000",
366
+ darksalmon: "#e9967a",
367
+ darkseagreen: "#8fbc8f",
368
+ darkslateblue: "#483d8b",
369
+ darkslategray: "#2f4f4f",
370
+ darkslategrey: "#2f4f4f",
371
+ darkturquoise: "#00ced1",
372
+ darkviolet: "#9400d3",
373
+ deeppink: "#ff1493",
374
+ deepskyblue: "#00bfff",
375
+ dimgray: "#696969",
376
+ dimgrey: "#696969",
377
+ dodgerblue: "#1e90ff",
378
+ firebrick: "#b22222",
379
+ floralwhite: "#fffaf0",
380
+ forestgreen: "#228b22",
381
+ fuchsia: "#ff00ff",
382
+ gainsboro: "#dcdcdc",
383
+ ghostwhite: "#f8f8ff",
384
+ goldenrod: "#daa520",
385
+ gold: "#ffd700",
386
+ gray: "#808080",
387
+ green: "#008000",
388
+ greenyellow: "#adff2f",
389
+ grey: "#808080",
390
+ honeydew: "#f0fff0",
391
+ hotpink: "#ff69b4",
392
+ indianred: "#cd5c5c",
393
+ indigo: "#4b0082",
394
+ ivory: "#fffff0",
395
+ khaki: "#f0e68c",
396
+ lavenderblush: "#fff0f5",
397
+ lavender: "#e6e6fa",
398
+ lawngreen: "#7cfc00",
399
+ lemonchiffon: "#fffacd",
400
+ lightblue: "#add8e6",
401
+ lightcoral: "#f08080",
402
+ lightcyan: "#e0ffff",
403
+ lightgoldenrodyellow: "#fafad2",
404
+ lightgray: "#d3d3d3",
405
+ lightgreen: "#90ee90",
406
+ lightgrey: "#d3d3d3",
407
+ lightpink: "#ffb6c1",
408
+ lightsalmon: "#ffa07a",
409
+ lightseagreen: "#20b2aa",
410
+ lightskyblue: "#87cefa",
411
+ lightslategray: "#778899",
412
+ lightslategrey: "#778899",
413
+ lightsteelblue: "#b0c4de",
414
+ lightyellow: "#ffffe0",
415
+ lime: "#00ff00",
416
+ limegreen: "#32cd32",
417
+ linen: "#faf0e6",
418
+ magenta: "#ff00ff",
419
+ maroon: "#800000",
420
+ mediumaquamarine: "#66cdaa",
421
+ mediumblue: "#0000cd",
422
+ mediumorchid: "#ba55d3",
423
+ mediumpurple: "#9370db",
424
+ mediumseagreen: "#3cb371",
425
+ mediumslateblue: "#7b68ee",
426
+ mediumspringgreen: "#00fa9a",
427
+ mediumturquoise: "#48d1cc",
428
+ mediumvioletred: "#c71585",
429
+ midnightblue: "#191970",
430
+ mintcream: "#f5fffa",
431
+ mistyrose: "#ffe4e1",
432
+ moccasin: "#ffe4b5",
433
+ navajowhite: "#ffdead",
434
+ navy: "#000080",
435
+ oldlace: "#fdf5e6",
436
+ olive: "#808000",
437
+ olivedrab: "#6b8e23",
438
+ orange: "#ffa500",
439
+ orangered: "#ff4500",
440
+ orchid: "#da70d6",
441
+ palegoldenrod: "#eee8aa",
442
+ palegreen: "#98fb98",
443
+ paleturquoise: "#afeeee",
444
+ palevioletred: "#db7093",
445
+ papayawhip: "#ffefd5",
446
+ peachpuff: "#ffdab9",
447
+ peru: "#cd853f",
448
+ pink: "#ffc0cb",
449
+ plum: "#dda0dd",
450
+ powderblue: "#b0e0e6",
451
+ purple: "#800080",
452
+ rebeccapurple: "#663399",
453
+ red: "#ff0000",
454
+ rosybrown: "#bc8f8f",
455
+ royalblue: "#4169e1",
456
+ saddlebrown: "#8b4513",
457
+ salmon: "#fa8072",
458
+ sandybrown: "#f4a460",
459
+ seagreen: "#2e8b57",
460
+ seashell: "#fff5ee",
461
+ sienna: "#a0522d",
462
+ silver: "#c0c0c0",
463
+ skyblue: "#87ceeb",
464
+ slateblue: "#6a5acd",
465
+ slategray: "#708090",
466
+ slategrey: "#708090",
467
+ snow: "#fffafa",
468
+ springgreen: "#00ff7f",
469
+ steelblue: "#4682b4",
470
+ tan: "#d2b48c",
471
+ teal: "#008080",
472
+ thistle: "#d8bfd8",
473
+ tomato: "#ff6347",
474
+ turquoise: "#40e0d0",
475
+ violet: "#ee82ee",
476
+ wheat: "#f5deb3",
477
+ white: "#ffffff",
478
+ whitesmoke: "#f5f5f5",
479
+ yellow: "#ffff00",
480
+ yellowgreen: "#9acd32"
481
+ };
482
+ //#endregion
483
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/format-input.js
484
+ /**
485
+ * Given a string or object, convert that input to RGB
486
+ *
487
+ * Possible string inputs:
488
+ * ```
489
+ * "red"
490
+ * "#f00" or "f00"
491
+ * "#ff0000" or "ff0000"
492
+ * "#ff000000" or "ff000000"
493
+ * "rgb 255 0 0" or "rgb (255, 0, 0)"
494
+ * "rgb 1.0 0 0" or "rgb (1, 0, 0)"
495
+ * "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
496
+ * "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
497
+ * "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
498
+ * "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
499
+ * "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
500
+ * "cmyk(0, 20, 0, 0)" or "cmyk 0 20 0 0"
501
+ * ```
502
+ */
503
+ function inputToRGB(color) {
504
+ let rgb = {
505
+ r: 0,
506
+ g: 0,
507
+ b: 0
508
+ };
509
+ let a = 1;
510
+ let s = null;
511
+ let v = null;
512
+ let l = null;
513
+ let ok = false;
514
+ let format = false;
515
+ if (typeof color === "string") color = stringInputToObject(color);
516
+ if (typeof color === "object") {
517
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
518
+ rgb = rgbToRgb(color.r, color.g, color.b);
519
+ ok = true;
520
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
521
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
522
+ s = convertToPercentage(color.s);
523
+ v = convertToPercentage(color.v);
524
+ rgb = hsvToRgb(color.h, s, v);
525
+ ok = true;
526
+ format = "hsv";
527
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
528
+ s = convertToPercentage(color.s);
529
+ l = convertToPercentage(color.l);
530
+ rgb = hslToRgb(color.h, s, l);
531
+ ok = true;
532
+ format = "hsl";
533
+ } else if (isValidCSSUnit(color.c) && isValidCSSUnit(color.m) && isValidCSSUnit(color.y) && isValidCSSUnit(color.k)) {
534
+ rgb = cmykToRgb(color.c, color.m, color.y, color.k);
535
+ ok = true;
536
+ format = "cmyk";
537
+ }
538
+ if (Object.prototype.hasOwnProperty.call(color, "a")) a = color.a;
539
+ }
540
+ a = boundAlpha(a);
541
+ return {
542
+ ok,
543
+ format: color.format || format,
544
+ r: Math.min(255, Math.max(rgb.r, 0)),
545
+ g: Math.min(255, Math.max(rgb.g, 0)),
546
+ b: Math.min(255, Math.max(rgb.b, 0)),
547
+ a
548
+ };
549
+ }
550
+ var CSS_UNIT = "(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)";
551
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
552
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
553
+ var matchers = {
554
+ CSS_UNIT: new RegExp(CSS_UNIT),
555
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
556
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
557
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
558
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
559
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
560
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
561
+ cmyk: new RegExp("cmyk" + PERMISSIVE_MATCH4),
562
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
563
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
564
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
565
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
566
+ };
567
+ /**
568
+ * Permissive string parsing. Take in a number of formats, and output an object
569
+ * based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` or `{c, m, y, k}` or `{c, m, y, k, a}`
570
+ */
571
+ function stringInputToObject(color) {
572
+ color = color.trim().toLowerCase();
573
+ if (color.length === 0) return false;
574
+ let named = false;
575
+ if (names[color]) {
576
+ color = names[color];
577
+ named = true;
578
+ } else if (color === "transparent") return {
579
+ r: 0,
580
+ g: 0,
581
+ b: 0,
582
+ a: 0,
583
+ format: "name"
584
+ };
585
+ let match = matchers.rgb.exec(color);
586
+ if (match) return {
587
+ r: match[1],
588
+ g: match[2],
589
+ b: match[3]
590
+ };
591
+ match = matchers.rgba.exec(color);
592
+ if (match) return {
593
+ r: match[1],
594
+ g: match[2],
595
+ b: match[3],
596
+ a: match[4]
597
+ };
598
+ match = matchers.hsl.exec(color);
599
+ if (match) return {
600
+ h: match[1],
601
+ s: match[2],
602
+ l: match[3]
603
+ };
604
+ match = matchers.hsla.exec(color);
605
+ if (match) return {
606
+ h: match[1],
607
+ s: match[2],
608
+ l: match[3],
609
+ a: match[4]
610
+ };
611
+ match = matchers.hsv.exec(color);
612
+ if (match) return {
613
+ h: match[1],
614
+ s: match[2],
615
+ v: match[3]
616
+ };
617
+ match = matchers.hsva.exec(color);
618
+ if (match) return {
619
+ h: match[1],
620
+ s: match[2],
621
+ v: match[3],
622
+ a: match[4]
623
+ };
624
+ match = matchers.cmyk.exec(color);
625
+ if (match) return {
626
+ c: match[1],
627
+ m: match[2],
628
+ y: match[3],
629
+ k: match[4]
630
+ };
631
+ match = matchers.hex8.exec(color);
632
+ if (match) return {
633
+ r: parseIntFromHex(match[1]),
634
+ g: parseIntFromHex(match[2]),
635
+ b: parseIntFromHex(match[3]),
636
+ a: convertHexToDecimal(match[4]),
637
+ format: named ? "name" : "hex8"
638
+ };
639
+ match = matchers.hex6.exec(color);
640
+ if (match) return {
641
+ r: parseIntFromHex(match[1]),
642
+ g: parseIntFromHex(match[2]),
643
+ b: parseIntFromHex(match[3]),
644
+ format: named ? "name" : "hex"
645
+ };
646
+ match = matchers.hex4.exec(color);
647
+ if (match) return {
648
+ r: parseIntFromHex(match[1] + match[1]),
649
+ g: parseIntFromHex(match[2] + match[2]),
650
+ b: parseIntFromHex(match[3] + match[3]),
651
+ a: convertHexToDecimal(match[4] + match[4]),
652
+ format: named ? "name" : "hex8"
653
+ };
654
+ match = matchers.hex3.exec(color);
655
+ if (match) return {
656
+ r: parseIntFromHex(match[1] + match[1]),
657
+ g: parseIntFromHex(match[2] + match[2]),
658
+ b: parseIntFromHex(match[3] + match[3]),
659
+ format: named ? "name" : "hex"
660
+ };
661
+ return false;
662
+ }
663
+ /**
664
+ * Check to see if it looks like a CSS unit
665
+ * (see `matchers` above for definition).
666
+ */
667
+ function isValidCSSUnit(color) {
668
+ if (typeof color === "number") return !Number.isNaN(color);
669
+ return matchers.CSS_UNIT.test(color);
670
+ }
671
+ //#endregion
672
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/index.js
673
+ var TinyColor = class TinyColor {
674
+ constructor(color = "", opts = {}) {
675
+ if (color instanceof TinyColor) return color;
676
+ if (typeof color === "number") color = numberInputToObject(color);
677
+ this.originalInput = color;
678
+ const rgb = inputToRGB(color);
679
+ this.originalInput = color;
680
+ this.r = rgb.r;
681
+ this.g = rgb.g;
682
+ this.b = rgb.b;
683
+ this.a = rgb.a;
684
+ this.roundA = Math.round(100 * this.a) / 100;
685
+ this.format = opts.format ?? rgb.format;
686
+ this.gradientType = opts.gradientType;
687
+ if (this.r < 1) this.r = Math.round(this.r);
688
+ if (this.g < 1) this.g = Math.round(this.g);
689
+ if (this.b < 1) this.b = Math.round(this.b);
690
+ this.isValid = rgb.ok;
691
+ }
692
+ isDark() {
693
+ return this.getBrightness() < 128;
694
+ }
695
+ isLight() {
696
+ return !this.isDark();
697
+ }
698
+ /**
699
+ * Returns the perceived brightness of the color, from 0-255.
700
+ */
701
+ getBrightness() {
702
+ const rgb = this.toRgb();
703
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
704
+ }
705
+ /**
706
+ * Returns the perceived luminance of a color, from 0-1.
707
+ */
708
+ getLuminance() {
709
+ const rgb = this.toRgb();
710
+ let R;
711
+ let G;
712
+ let B;
713
+ const RsRGB = rgb.r / 255;
714
+ const GsRGB = rgb.g / 255;
715
+ const BsRGB = rgb.b / 255;
716
+ if (RsRGB <= .03928) R = RsRGB / 12.92;
717
+ else R = Math.pow((RsRGB + .055) / 1.055, 2.4);
718
+ if (GsRGB <= .03928) G = GsRGB / 12.92;
719
+ else G = Math.pow((GsRGB + .055) / 1.055, 2.4);
720
+ if (BsRGB <= .03928) B = BsRGB / 12.92;
721
+ else B = Math.pow((BsRGB + .055) / 1.055, 2.4);
722
+ return .2126 * R + .7152 * G + .0722 * B;
723
+ }
724
+ /**
725
+ * Returns the alpha value of a color, from 0-1.
726
+ */
727
+ getAlpha() {
728
+ return this.a;
729
+ }
730
+ /**
731
+ * Sets the alpha value on the current color.
732
+ *
733
+ * @param alpha - The new alpha value. The accepted range is 0-1.
734
+ */
735
+ setAlpha(alpha) {
736
+ this.a = boundAlpha(alpha);
737
+ this.roundA = Math.round(100 * this.a) / 100;
738
+ return this;
739
+ }
740
+ /**
741
+ * Returns whether the color is monochrome.
742
+ */
743
+ isMonochrome() {
744
+ const { s } = this.toHsl();
745
+ return s === 0;
746
+ }
747
+ /**
748
+ * Returns the object as a HSVA object.
749
+ */
750
+ toHsv() {
751
+ const hsv = rgbToHsv(this.r, this.g, this.b);
752
+ return {
753
+ h: hsv.h * 360,
754
+ s: hsv.s,
755
+ v: hsv.v,
756
+ a: this.a
757
+ };
758
+ }
759
+ /**
760
+ * Returns the hsva values interpolated into a string with the following format:
761
+ * "hsva(xxx, xxx, xxx, xx)".
762
+ */
763
+ toHsvString() {
764
+ const hsv = rgbToHsv(this.r, this.g, this.b);
765
+ const h = Math.round(hsv.h * 360);
766
+ const s = Math.round(hsv.s * 100);
767
+ const v = Math.round(hsv.v * 100);
768
+ return this.a === 1 ? `hsv(${h}, ${s}%, ${v}%)` : `hsva(${h}, ${s}%, ${v}%, ${this.roundA})`;
769
+ }
770
+ /**
771
+ * Returns the object as a HSLA object.
772
+ */
773
+ toHsl() {
774
+ const hsl = rgbToHsl(this.r, this.g, this.b);
775
+ return {
776
+ h: hsl.h * 360,
777
+ s: hsl.s,
778
+ l: hsl.l,
779
+ a: this.a
780
+ };
781
+ }
782
+ /**
783
+ * Returns the hsla values interpolated into a string with the following format:
784
+ * "hsla(xxx, xxx, xxx, xx)".
785
+ */
786
+ toHslString() {
787
+ const hsl = rgbToHsl(this.r, this.g, this.b);
788
+ const h = Math.round(hsl.h * 360);
789
+ const s = Math.round(hsl.s * 100);
790
+ const l = Math.round(hsl.l * 100);
791
+ return this.a === 1 ? `hsl(${h}, ${s}%, ${l}%)` : `hsla(${h}, ${s}%, ${l}%, ${this.roundA})`;
792
+ }
793
+ /**
794
+ * Returns the hex value of the color.
795
+ * @param allow3Char will shorten hex value to 3 char if possible
796
+ */
797
+ toHex(allow3Char = false) {
798
+ return rgbToHex(this.r, this.g, this.b, allow3Char);
799
+ }
800
+ /**
801
+ * Returns the hex value of the color -with a # prefixed.
802
+ * @param allow3Char will shorten hex value to 3 char if possible
803
+ */
804
+ toHexString(allow3Char = false) {
805
+ return "#" + this.toHex(allow3Char);
806
+ }
807
+ /**
808
+ * Returns the hex 8 value of the color.
809
+ * @param allow4Char will shorten hex value to 4 char if possible
810
+ */
811
+ toHex8(allow4Char = false) {
812
+ return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
813
+ }
814
+ /**
815
+ * Returns the hex 8 value of the color -with a # prefixed.
816
+ * @param allow4Char will shorten hex value to 4 char if possible
817
+ */
818
+ toHex8String(allow4Char = false) {
819
+ return "#" + this.toHex8(allow4Char);
820
+ }
821
+ /**
822
+ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
823
+ * @param allowShortChar will shorten hex value to 3 or 4 char if possible
824
+ */
825
+ toHexShortString(allowShortChar = false) {
826
+ return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar);
827
+ }
828
+ /**
829
+ * Returns the object as a RGBA object.
830
+ */
831
+ toRgb() {
832
+ return {
833
+ r: Math.round(this.r),
834
+ g: Math.round(this.g),
835
+ b: Math.round(this.b),
836
+ a: this.a
837
+ };
838
+ }
839
+ /**
840
+ * Returns the RGBA values interpolated into a string with the following format:
841
+ * "RGBA(xxx, xxx, xxx, xx)".
842
+ */
843
+ toRgbString() {
844
+ const r = Math.round(this.r);
845
+ const g = Math.round(this.g);
846
+ const b = Math.round(this.b);
847
+ return this.a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${this.roundA})`;
848
+ }
849
+ /**
850
+ * Returns the object as a RGBA object.
851
+ */
852
+ toPercentageRgb() {
853
+ const fmt = (x) => `${Math.round(bound01(x, 255) * 100)}%`;
854
+ return {
855
+ r: fmt(this.r),
856
+ g: fmt(this.g),
857
+ b: fmt(this.b),
858
+ a: this.a
859
+ };
860
+ }
861
+ /**
862
+ * Returns the RGBA relative values interpolated into a string
863
+ */
864
+ toPercentageRgbString() {
865
+ const rnd = (x) => Math.round(bound01(x, 255) * 100);
866
+ return this.a === 1 ? `rgb(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%)` : `rgba(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%, ${this.roundA})`;
867
+ }
868
+ toCmyk() {
869
+ return { ...rgbToCmyk(this.r, this.g, this.b) };
870
+ }
871
+ toCmykString() {
872
+ const { c, m, y, k } = rgbToCmyk(this.r, this.g, this.b);
873
+ return `cmyk(${c}, ${m}, ${y}, ${k})`;
874
+ }
875
+ /**
876
+ * The 'real' name of the color -if there is one.
877
+ */
878
+ toName() {
879
+ if (this.a === 0) return "transparent";
880
+ if (this.a < 1) return false;
881
+ const hex = "#" + rgbToHex(this.r, this.g, this.b, false);
882
+ for (const [key, value] of Object.entries(names)) if (hex === value) return key;
883
+ return false;
884
+ }
885
+ toString(format) {
886
+ const formatSet = Boolean(format);
887
+ format = format ?? this.format;
888
+ let formattedString = false;
889
+ const hasAlpha = this.a < 1 && this.a >= 0;
890
+ if (!formatSet && hasAlpha && (format.startsWith("hex") || format === "name")) {
891
+ if (format === "name" && this.a === 0) return this.toName();
892
+ return this.toRgbString();
893
+ }
894
+ if (format === "rgb") formattedString = this.toRgbString();
895
+ if (format === "prgb") formattedString = this.toPercentageRgbString();
896
+ if (format === "hex" || format === "hex6") formattedString = this.toHexString();
897
+ if (format === "hex3") formattedString = this.toHexString(true);
898
+ if (format === "hex4") formattedString = this.toHex8String(true);
899
+ if (format === "hex8") formattedString = this.toHex8String();
900
+ if (format === "name") formattedString = this.toName();
901
+ if (format === "hsl") formattedString = this.toHslString();
902
+ if (format === "hsv") formattedString = this.toHsvString();
903
+ if (format === "cmyk") formattedString = this.toCmykString();
904
+ return formattedString || this.toHexString();
905
+ }
906
+ toNumber() {
907
+ return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b);
908
+ }
909
+ clone() {
910
+ return new TinyColor(this.toString());
911
+ }
912
+ /**
913
+ * Lighten the color a given amount. Providing 100 will always return white.
914
+ * @param amount - valid between 1-100
915
+ */
916
+ lighten(amount = 10) {
917
+ const hsl = this.toHsl();
918
+ hsl.l += amount / 100;
919
+ hsl.l = clamp01(hsl.l);
920
+ return new TinyColor(hsl);
921
+ }
922
+ /**
923
+ * Brighten the color a given amount, from 0 to 100.
924
+ * @param amount - valid between 1-100
925
+ */
926
+ brighten(amount = 10) {
927
+ const rgb = this.toRgb();
928
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
929
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
930
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
931
+ return new TinyColor(rgb);
932
+ }
933
+ /**
934
+ * Darken the color a given amount, from 0 to 100.
935
+ * Providing 100 will always return black.
936
+ * @param amount - valid between 1-100
937
+ */
938
+ darken(amount = 10) {
939
+ const hsl = this.toHsl();
940
+ hsl.l -= amount / 100;
941
+ hsl.l = clamp01(hsl.l);
942
+ return new TinyColor(hsl);
943
+ }
944
+ /**
945
+ * Mix the color with pure white, from 0 to 100.
946
+ * Providing 0 will do nothing, providing 100 will always return white.
947
+ * @param amount - valid between 1-100
948
+ */
949
+ tint(amount = 10) {
950
+ return this.mix("white", amount);
951
+ }
952
+ /**
953
+ * Mix the color with pure black, from 0 to 100.
954
+ * Providing 0 will do nothing, providing 100 will always return black.
955
+ * @param amount - valid between 1-100
956
+ */
957
+ shade(amount = 10) {
958
+ return this.mix("black", amount);
959
+ }
960
+ /**
961
+ * Desaturate the color a given amount, from 0 to 100.
962
+ * Providing 100 will is the same as calling greyscale
963
+ * @param amount - valid between 1-100
964
+ */
965
+ desaturate(amount = 10) {
966
+ const hsl = this.toHsl();
967
+ hsl.s -= amount / 100;
968
+ hsl.s = clamp01(hsl.s);
969
+ return new TinyColor(hsl);
970
+ }
971
+ /**
972
+ * Saturate the color a given amount, from 0 to 100.
973
+ * @param amount - valid between 1-100
974
+ */
975
+ saturate(amount = 10) {
976
+ const hsl = this.toHsl();
977
+ hsl.s += amount / 100;
978
+ hsl.s = clamp01(hsl.s);
979
+ return new TinyColor(hsl);
980
+ }
981
+ /**
982
+ * Completely desaturates a color into greyscale.
983
+ * Same as calling `desaturate(100)`
984
+ */
985
+ greyscale() {
986
+ return this.desaturate(100);
987
+ }
988
+ /**
989
+ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
990
+ * Values outside of this range will be wrapped into this range.
991
+ */
992
+ spin(amount) {
993
+ const hsl = this.toHsl();
994
+ const hue = (hsl.h + amount) % 360;
995
+ hsl.h = hue < 0 ? 360 + hue : hue;
996
+ return new TinyColor(hsl);
997
+ }
998
+ /**
999
+ * Mix the current color a given amount with another color, from 0 to 100.
1000
+ * 0 means no mixing (return current color).
1001
+ */
1002
+ mix(color, amount = 50) {
1003
+ const rgb1 = this.toRgb();
1004
+ const rgb2 = new TinyColor(color).toRgb();
1005
+ const p = amount / 100;
1006
+ const rgba = {
1007
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
1008
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
1009
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
1010
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
1011
+ };
1012
+ return new TinyColor(rgba);
1013
+ }
1014
+ analogous(results = 6, slices = 30) {
1015
+ const hsl = this.toHsl();
1016
+ const part = 360 / slices;
1017
+ const ret = [this];
1018
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
1019
+ hsl.h = (hsl.h + part) % 360;
1020
+ ret.push(new TinyColor(hsl));
1021
+ }
1022
+ return ret;
1023
+ }
1024
+ /**
1025
+ * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
1026
+ */
1027
+ complement() {
1028
+ const hsl = this.toHsl();
1029
+ hsl.h = (hsl.h + 180) % 360;
1030
+ return new TinyColor(hsl);
1031
+ }
1032
+ monochromatic(results = 6) {
1033
+ const hsv = this.toHsv();
1034
+ const { h } = hsv;
1035
+ const { s } = hsv;
1036
+ let { v } = hsv;
1037
+ const res = [];
1038
+ const modification = 1 / results;
1039
+ while (results--) {
1040
+ res.push(new TinyColor({
1041
+ h,
1042
+ s,
1043
+ v
1044
+ }));
1045
+ v = (v + modification) % 1;
1046
+ }
1047
+ return res;
1048
+ }
1049
+ splitcomplement() {
1050
+ const hsl = this.toHsl();
1051
+ const { h } = hsl;
1052
+ return [
1053
+ this,
1054
+ new TinyColor({
1055
+ h: (h + 72) % 360,
1056
+ s: hsl.s,
1057
+ l: hsl.l
1058
+ }),
1059
+ new TinyColor({
1060
+ h: (h + 216) % 360,
1061
+ s: hsl.s,
1062
+ l: hsl.l
1063
+ })
1064
+ ];
1065
+ }
1066
+ /**
1067
+ * Compute how the color would appear on a background
1068
+ */
1069
+ onBackground(background) {
1070
+ const fg = this.toRgb();
1071
+ const bg = new TinyColor(background).toRgb();
1072
+ const alpha = fg.a + bg.a * (1 - fg.a);
1073
+ return new TinyColor({
1074
+ r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / alpha,
1075
+ g: (fg.g * fg.a + bg.g * bg.a * (1 - fg.a)) / alpha,
1076
+ b: (fg.b * fg.a + bg.b * bg.a * (1 - fg.a)) / alpha,
1077
+ a: alpha
1078
+ });
1079
+ }
1080
+ /**
1081
+ * Alias for `polyad(3)`
1082
+ */
1083
+ triad() {
1084
+ return this.polyad(3);
1085
+ }
1086
+ /**
1087
+ * Alias for `polyad(4)`
1088
+ */
1089
+ tetrad() {
1090
+ return this.polyad(4);
1091
+ }
1092
+ /**
1093
+ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
1094
+ * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
1095
+ */
1096
+ polyad(n) {
1097
+ const hsl = this.toHsl();
1098
+ const { h } = hsl;
1099
+ const result = [this];
1100
+ const increment = 360 / n;
1101
+ for (let i = 1; i < n; i++) result.push(new TinyColor({
1102
+ h: (h + i * increment) % 360,
1103
+ s: hsl.s,
1104
+ l: hsl.l
1105
+ }));
1106
+ return result;
1107
+ }
1108
+ /**
1109
+ * compare color vs current color
1110
+ */
1111
+ equals(color) {
1112
+ const comparedColor = new TinyColor(color);
1113
+ /**
1114
+ * RGB and CMYK do not have the same color gamut, so a CMYK conversion will never be 100%.
1115
+ * This means we need to compare CMYK to CMYK to ensure accuracy of the equals function.
1116
+ */
1117
+ if (this.format === "cmyk" || comparedColor.format === "cmyk") return this.toCmykString() === comparedColor.toCmykString();
1118
+ return this.toRgbString() === comparedColor.toRgbString();
1119
+ }
1120
+ };
1121
+ //#endregion
1122
+ //#region src/color-select.scss?inline
1123
+ var color_select_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n --c2-list-item--font-size: 10px;\n --c2-select__button--font-size: 10px;\n --c2-select__button__suffix-icon--width: 12px;\n --c2-select__button__suffix-icon--height: 12px;\n --c2-select__button--padding: 8px 8px 8px 8px;\n --c2-select__button__hover--background: transparent;\n --c2-select__button--background: transparent;\n --c2-select__button--border-top: 1px solid transparent;\n --c2-select__button--border-right: 1px solid transparent;\n --c2-select__button--border-bottom: 1px solid transparent;\n --c2-select__button--border-left: 1px solid transparent;\n --c2-text-field--border-top: 1px solid transparent;\n --c2-text-field--border-right: 1px solid transparent;\n --c2-text-field--border-bottom: 1px solid transparent;\n --c2-text-field--border-left: 1px solid transparent;\n --c2-text-field__focus--border-top: 1px solid rgb(2, 101, 220);\n --c2-text-field__focus--border-right: 1px solid rgb(2, 101, 220);\n --c2-text-field__focus--border-bottom: 1px solid rgb(2, 101, 220);\n --c2-text-field__focus--border-left: 1px solid rgb(2, 101, 220);\n --c2-text-field--font-size: 10px;\n --c2-text-field--padding-top: 8px;\n --c2-text-field--padding-right: 2px;\n --c2-text-field--padding-bottom: 8px;\n --c2-text-field--padding-left: 2px;\n --c2-text-field--background: transparent;\n}\n\n.c2-color-select {\n display: contents;\n}\n.c2-color-select .presentation {\n width: var(--c2-color-select--width,16px);\n height: var(--c2-color-select--height,16px);\n border-top-left-radius: var(--c2-color-select--border-top-left-radius,1px);\n border-top-right-radius: var(--c2-color-select--border-top-right-radius,1px);\n border-bottom-left-radius: var(--c2-color-select--border-bottom-left-radius,1px);\n border-bottom-right-radius: var(--c2-color-select--border-bottom-right-radius,1px);\n display: flex;\n align-items: stretch;\n position: relative;\n background: none;\n border-top: var(--c2-color-select--border-top);\n border-right: var(--c2-color-select--border-right);\n border-bottom: var(--c2-color-select--border-bottom);\n border-left: var(--c2-color-select--border-left);\n padding: 0;\n margin: 0;\n cursor: inherit;\n}\n.c2-color-select .presentation .presentation-hue {\n flex: 1;\n border-radius: inherit;\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n}\n.c2-color-select .presentation .presentation-color {\n flex: 1;\n border-radius: inherit;\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n z-index: 1;\n}\n.c2-color-select .presentation .presentation-color-background {\n border-radius: inherit;\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n position: absolute;\n left: 50%;\n top: 0;\n width: 50%;\n height: 100%;\n z-index: 0;\n background: url(data:image/svg+xml;utf8,%3Csvg%20width%3D%226%22%20height%3D%226%22%20viewBox%3D%220%200%206%206%22%20fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M0%200H3V3H0V0Z%22%20fill%3D%22%23E1E1E1%22/%3E%3Cpath%20d%3D%22M3%200H6V3H3V0Z%22%20fill%3D%22white%22/%3E%3Cpath%20d%3D%22M3%203H6V6H3V3Z%22%20fill%3D%22%23E1E1E1%22/%3E%3Cpath%20d%3D%22M0%203H3V6H0V3Z%22%20fill%3D%22white%22/%3E%3C/svg%3E%0A);\n}\n.c2-color-select #menu-overlay {\n --c2-overlay--offset-x: calc(7px - var(--c2-color-area__color-handle--size, 12px));\n transition: none;\n}\n\n.popover {\n --c2-overlay--offset-x: 0px;\n --c2-color-area--border-top-left-radius: var(--c2-color-select__popover--border-top-left-radius,4px);\n --c2-color-area--border-top-right-radius: var(--c2-color-select__popover--border-top-right-radius,4px);\n --c2-color-area--border-bottom-left-radius: 0px;\n --c2-color-area--border-bottom-right-radius: 0px;\n padding: calc(var(--c2-color-area__color-handle--size, 12px) - 7px);\n position: relative;\n overflow: hidden;\n}\n.popover .popover-container {\n display: flex;\n flex-direction: column;\n padding: 0;\n margin: 0;\n gap: var(--c2-color-select__popover--gap,16px);\n background-color: var(--c2-color-select__popover--background-color,rgb(253, 253, 253));\n border-top: var(--c2-color-select__popover--border-top,1px solid rgb(177, 177, 177));\n border-right: var(--c2-color-select__popover--border-right,1px solid rgb(177, 177, 177));\n border-bottom: var(--c2-color-select__popover--border-bottom,1px solid rgb(177, 177, 177));\n border-left: var(--c2-color-select__popover--border-left,1px solid rgb(177, 177, 177));\n border-top-left-radius: var(--c2-color-select__popover--border-top-left-radius,4px);\n border-top-right-radius: var(--c2-color-select__popover--border-top-right-radius,4px);\n border-bottom-left-radius: var(--c2-color-select__popover--border-bottom-left-radius,4px);\n border-bottom-right-radius: var(--c2-color-select__popover--border-bottom-right-radius,4px);\n width: var(--c2-color-area--width, 240px);\n}\n.popover .popover-container .color-area {\n position: absolute;\n top: 0;\n left: 0;\n}\n.popover .popover-container .color-area-placeholder {\n height: var(--c2-color-area--height, 240px);\n}\n.popover .popover-container .color-config {\n display: grid;\n grid-template-columns: fit-content(var(--c2-color-select__color__sample--size,48px)), 1fr;\n grid-auto-flow: column;\n place-items: center;\n padding-left: var(--c2-color-select__popover--padding-left,8px);\n padding-right: var(--c2-color-select__popover--padding-right,8px);\n padding-top: var(--c2-color-select__popover--padding-top,0px);\n}\n.popover .popover-container .color-config .color-sample {\n width: var(--c2-color-select__color__sample--size,48px);\n height: var(--c2-color-select__color__sample--size,48px);\n border-radius: var(--c2-color-select__color__sample--border-radius,4px);\n border-top: var(--c2-color-select__color__sample--border-top,1px solid rgb(177, 177, 177));\n border-right: var(--c2-color-select__color__sample--border-right,1px solid rgb(177, 177, 177));\n border-bottom: var(--c2-color-select__color__sample--border-bottom,1px solid rgb(177, 177, 177));\n border-left: var(--c2-color-select__color__sample--border-left,1px solid rgb(177, 177, 177));\n grid-column: 1/2;\n grid-row: 1/3;\n background-color: red;\n}\n.popover .popover-container .color-config .alpha-input {\n --c2-color-slider__color-handle--background-color: transparent;\n}\n.popover .popover-container .color-input-container {\n display: flex;\n align-items: center;\n gap: 4px;\n padding-left: var(--c2-color-select__popover--padding-left,8px);\n padding-right: var(--c2-color-select__popover--padding-right,8px);\n padding-bottom: var(--c2-color-select__popover--padding-bottom,8px);\n}\n.popover .popover-container .color-input-container .color-input-group {\n display: flex;\n align-items: center;\n}\n.popover .popover-container .color-input-container .color-input-group:hover {\n --c2-text-field--border-top: 1px solid rgb(177, 177, 177);\n --c2-text-field--border-right: 1px solid rgb(177, 177, 177);\n --c2-text-field--border-bottom: 1px solid rgb(177, 177, 177);\n --c2-text-field--border-left: 1px solid rgb(177, 177, 177);\n}\n.popover .popover-container .color-input-container .color-input-group .number-input {\n flex-grow: 1;\n flex-shrink: 1;\n flex-basis: 25%;\n}\n.popover .popover-container .color-input-container .color-input-group .text-input {\n flex-grow: 1;\n flex-shrink: 1;\n flex-basis: 75%;\n}\n.popover .popover-container .color-input-container .color-input-group c2-text-field + c2-text-field {\n --c2-text-field--border-top-left-radius: 0px;\n --c2-text-field--border-bottom-left-radius: 0px;\n}\n.popover .popover-container .color-input-container .color-input-group c2-text-field:has(+ c2-text-field) {\n --c2-text-field--border-right: none;\n --c2-text-field__focus--border-right: none;\n --c2-text-field--border-top-right-radius: 0px;\n --c2-text-field--border-bottom-right-radius: 0px;\n}\n.popover .popover-container .color-input-container .color-input-group c2-text-field.focus-within + c2-text-field {\n --c2-text-field--border-left: var(--c2-text-field__focus--border-left, 1px solid rgb(2, 101, 220));\n}";
1124
+ //#endregion
1125
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
1126
+ function __decorate(decorators, target, key, desc) {
1127
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1128
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1129
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1130
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1131
+ }
1132
+ //#endregion
1133
+ //#region src/color-select.ts
1134
+ var ColorSelect = class ColorSelect extends LitElement {
1135
+ constructor(..._args) {
1136
+ super(..._args);
1137
+ this.placement = "bottom-start";
1138
+ this._color = "#000000";
1139
+ this.hue = 0;
1140
+ this.saturation = 0;
1141
+ this.value = 0;
1142
+ this.alpha = 1;
1143
+ this.inputType = "HEX";
1144
+ this.open = false;
1145
+ }
1146
+ static {
1147
+ this.styles = unsafeCSS(color_select_default);
1148
+ }
1149
+ get color() {
1150
+ return this._color;
1151
+ }
1152
+ set color(value) {
1153
+ if (this._color != value) {
1154
+ this._color = value;
1155
+ this.extractHsvaFromColor();
1156
+ }
1157
+ }
1158
+ get tinyColor() {
1159
+ return new TinyColor({
1160
+ h: this.hue,
1161
+ s: this.saturation,
1162
+ v: this.value,
1163
+ a: this.alpha
1164
+ });
1165
+ }
1166
+ renderInput() {
1167
+ if (this.inputType == "HEX") return html`<c2-text-field class="text-input" .value=${this.tinyColor.toHexString()} @change=${this.handleHexInputChange}></c2-text-field>
1168
+ <c2-text-field class="number-input" .value=${this.toPercentage(this.alpha, true)} @change=${this.handleAlphaInputChange}> </c2-text-field> `;
1169
+ else if (this.inputType == "RGB") {
1170
+ const rgb = this.tinyColor.toRgb();
1171
+ return html`<c2-text-field class="number-input" id="r" .value=${rgb.r} @change=${this.handleRgbInputChange}></c2-text-field>
1172
+ <c2-text-field class="number-input" id="g" .value=${rgb.g} @change=${this.handleRgbInputChange}></c2-text-field>
1173
+ <c2-text-field class="number-input" id="b" .value=${rgb.b} @change=${this.handleRgbInputChange}></c2-text-field>
1174
+ <c2-text-field class="number-input" .value=${this.toPercentage(this.alpha, true)} @change=${this.handleAlphaInputChange}> </c2-text-field> `;
1175
+ }
1176
+ return html`<c2-text-field class="number-input" .value=${Math.round(this.hue)} @change=${this.handleHueInputChange}></c2-text-field>
1177
+ <c2-text-field class="number-input" .value=${this.toPercentage(this.saturation)} @change=${this.handleSaturationInputChange}></c2-text-field>
1178
+ <c2-text-field class="number-input" .value="${this.toPercentage(this.value)}" @change=${this.handleLightnessInputChange}></c2-text-field>
1179
+ <c2-text-field class="number-input" .value=${this.toPercentage(this.alpha, true)} @change=${this.handleAlphaInputChange}></c2-text-field> `;
1180
+ }
1181
+ toPercentage(value, showSuffix = false) {
1182
+ return showSuffix ? `${Math.round(value * 100).toFixed()}%` : `${Math.round(value * 100).toFixed()}`;
1183
+ }
1184
+ handleRgbInputChange(event) {
1185
+ const value = Number(event.target.value);
1186
+ const id = event.target.id;
1187
+ if (value >= 0 && value <= 255) {
1188
+ const rgb = this.tinyColor.toRgb();
1189
+ rgb[id] = value;
1190
+ const { h, s, v } = new TinyColor(rgb).toHsv();
1191
+ this.hue = h;
1192
+ this.saturation = s;
1193
+ this.value = v;
1194
+ this.dispatchChangeEvent();
1195
+ }
1196
+ }
1197
+ updateColor() {
1198
+ this._color = this.tinyColor.toRgbString();
1199
+ this.setAttribute("color", this._color);
1200
+ }
1201
+ handleHueInputChange(event) {
1202
+ const value = Number(event.target.value);
1203
+ if (value >= 0 && value <= 360) {
1204
+ this.hue = value;
1205
+ this.dispatchChangeEvent();
1206
+ }
1207
+ }
1208
+ handleSaturationInputChange(event) {
1209
+ const value = Number(event.target.value);
1210
+ if (value >= 0 && value <= 100) {
1211
+ this.saturation = value / 100;
1212
+ this.dispatchChangeEvent();
1213
+ }
1214
+ }
1215
+ handleLightnessInputChange(event) {
1216
+ const value = Number(event.target.value);
1217
+ if (value >= 0 && value <= 100) {
1218
+ this.value = value / 100;
1219
+ this.dispatchChangeEvent();
1220
+ }
1221
+ }
1222
+ handleHexInputChange(event) {
1223
+ const value = event.target.value;
1224
+ const tinyColor = new TinyColor(value);
1225
+ if (tinyColor.isValid) {
1226
+ const { h, s, v } = tinyColor.toHsv();
1227
+ this.hue = h;
1228
+ this.saturation = s;
1229
+ this.value = v;
1230
+ this.dispatchChangeEvent();
1231
+ }
1232
+ }
1233
+ handleAlphaInputChange(event) {
1234
+ const value = Number(event.target.value.replace("%", ""));
1235
+ if (!isNaN(value) && value >= 0 && value <= 100) {
1236
+ this.alpha = value / 100;
1237
+ this.dispatchChangeEvent();
1238
+ }
1239
+ }
1240
+ handleInputTypeChange(event) {
1241
+ this.inputType = event.detail.value[0];
1242
+ }
1243
+ handleHueSliderChange(event) {
1244
+ this.hue = event.target.value;
1245
+ this.dispatchChangeEvent();
1246
+ }
1247
+ handleAlphaSliderChange(event) {
1248
+ this.alpha = event.target.value / 100;
1249
+ this.dispatchChangeEvent();
1250
+ }
1251
+ extractHsvaFromColor() {
1252
+ const { h, s, v, a } = new TinyColor(this.color).toHsv();
1253
+ this.hue = h;
1254
+ this.saturation = s;
1255
+ this.value = v;
1256
+ this.alpha = a;
1257
+ }
1258
+ handleColorAreaChange(event) {
1259
+ const { h, s, v } = event.detail;
1260
+ this.hue = h;
1261
+ this.saturation = s;
1262
+ this.value = v;
1263
+ this.dispatchChangeEvent();
1264
+ }
1265
+ handleOverlayToggle(event) {
1266
+ const toggleEvent = event;
1267
+ this.open = toggleEvent.newState == "open";
1268
+ }
1269
+ dispatchChangeEvent() {
1270
+ this.updateColor();
1271
+ this.dispatchEvent(new CustomEvent("change", {
1272
+ cancelable: true,
1273
+ bubbles: true,
1274
+ detail: {
1275
+ h: this.hue,
1276
+ s: this.saturation,
1277
+ v: this.value,
1278
+ a: this.alpha
1279
+ }
1280
+ }));
1281
+ }
1282
+ render() {
1283
+ const colorWithOutAlpha = this.tinyColor.clone();
1284
+ colorWithOutAlpha.setAlpha(1);
1285
+ return html`
1286
+ <div class="c2-color-select">
1287
+ <button class="presentation" popovertarget="menu-overlay">
1288
+ <div class="presentation-color-background"></div>
1289
+ <div class="presentation-hue" style=${`background-color: ${colorWithOutAlpha.toHexString()}`}></div>
1290
+ <div class="presentation-color" style=${`background-color: ${this.tinyColor.toString("rgb")}`}></div>
1291
+ </button>
1292
+ <c2-overlay id="menu-overlay" disabled-cross-axis popover @toggle=${this.handleOverlayToggle} .placement=${this.placement}>
1293
+ ${this.open ? html` <div class="popover">
1294
+ <div class="popover-container">
1295
+ <c2-color-area
1296
+ class="color-area"
1297
+ .hue=${this.hue}
1298
+ .saturation=${this.saturation}
1299
+ .value=${this.value}
1300
+ @change=${this.handleColorAreaChange}
1301
+ >
1302
+ </c2-color-area>
1303
+ <div class="color-area-placeholder"></div>
1304
+ <div class="color-config">
1305
+ <div class="color-sample" style="background-color: ${this.tinyColor.toRgbString()}"></div>
1306
+ <c2-color-slider @input=${this.handleHueSliderChange} .value=${this.hue}></c2-color-slider>
1307
+ <c2-color-slider class="alpha-input" @input=${this.handleAlphaSliderChange} min="0" max="100" .value=${this.alpha * 100}>
1308
+ <div
1309
+ style="background-image: url(data:image/svg+xml;utf8,%3Csvg%20width%3D%226%22%20height%3D%226%22%20viewBox%3D%220%200%206%206%22%20fill%3D%22none%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%3Cpath%20d%3D%22M0%200H3V3H0V0Z%22%20fill%3D%22%23E1E1E1%22/%3E%3Cpath%20d%3D%22M3%200H6V3H3V0Z%22%20fill%3D%22white%22/%3E%3Cpath%20d%3D%22M3%203H6V6H3V3Z%22%20fill%3D%22%23E1E1E1%22/%3E%3Cpath%20d%3D%22M0%203H3V6H0V3Z%22%20fill%3D%22white%22/%3E%3C/svg%3E%0A),
1310
+ linear-gradient(to right, rgba(255 255 255) 0%, ${colorWithOutAlpha.toRgbString()} 100%);
1311
+ background-blend-mode: multiply;"
1312
+ ></div>
1313
+ </c2-color-slider>
1314
+ </div>
1315
+ <div class="color-input-container">
1316
+ <c2-select value=${this.inputType} required @selection-change=${this.handleInputTypeChange}>
1317
+ <c2-list-item value="HEX">HEX</c2-list-item>
1318
+ <c2-list-item value="RGB">RGB</c2-list-item>
1319
+ <c2-list-item value="HSL">HSL</c2-list-item>
1320
+ </c2-select>
1321
+ <div class="color-input-group">${this.renderInput()}</div>
1322
+ </div>
1323
+ </div>
1324
+ </div>` : nothing}
1325
+ </c2-overlay>
1326
+ </div>
1327
+ `;
1328
+ }
1329
+ };
1330
+ __decorate([property({
1331
+ type: String,
1332
+ reflect: true
1333
+ })], ColorSelect.prototype, "placement", void 0);
1334
+ __decorate([property({ reflect: true })], ColorSelect.prototype, "color", null);
1335
+ __decorate([state()], ColorSelect.prototype, "hue", void 0);
1336
+ __decorate([state()], ColorSelect.prototype, "saturation", void 0);
1337
+ __decorate([state()], ColorSelect.prototype, "value", void 0);
1338
+ __decorate([state()], ColorSelect.prototype, "alpha", void 0);
1339
+ __decorate([state()], ColorSelect.prototype, "inputType", void 0);
1340
+ __decorate([state()], ColorSelect.prototype, "open", void 0);
1341
+ __decorate([query(".color-area")], ColorSelect.prototype, "colorArea", void 0);
1342
+ ColorSelect = __decorate([customElement("c2-color-select")], ColorSelect);
1343
+ //#endregion
1344
+ export { ColorSelect };