@c2n/color-area 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nguyen Thai Vinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Color-Area
2
+
3
+ // TODO
@@ -0,0 +1,1243 @@
1
+ import { LitElement, html, unsafeCSS } from "lit";
2
+ import { customElement, property, query } from "lit/decorators.js";
3
+ //#region src/color-area.scss?inline
4
+ var color_area_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n}\n\n.c2-color-area {\n display: block;\n position: relative;\n padding: calc(var(--c2-color-area__color-handle--size,12px) - 6px);\n width: fit-content;\n height: fit-content;\n}\n.c2-color-area .gradient {\n width: 100%;\n height: 100%;\n width: var(--c2-color-area--width,240px);\n height: var(--c2-color-area--height,240px);\n border-top-left-radius: var(--c2-color-area--border-top-left-radius);\n border-top-right-radius: var(--c2-color-area--border-top-right-radius);\n border-bottom-left-radius: var(--c2-color-area--border-bottom-left-radius);\n border-bottom-right-radius: var(--c2-color-area--border-bottom-right-radius);\n}\n.c2-color-area .color-handle {\n position: absolute;\n pointer-events: none;\n box-sizing: border-box;\n width: var(--c2-color-area__color-handle--size,12px);\n height: var(--c2-color-area__color-handle--size,12px);\n border-radius: 50%;\n top: 0;\n left: 0;\n border: 2px solid white;\n background: transparent;\n box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 0px 0.6px;\n cursor: inherit;\n}";
5
+ //#endregion
6
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/util.js
7
+ /**
8
+ * Take input from [0, n] and return it as [0, 1]
9
+ * @hidden
10
+ */
11
+ function bound01(n, max) {
12
+ if (isOnePointZero(n)) n = "100%";
13
+ const isPercent = isPercentage(n);
14
+ n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n)));
15
+ if (isPercent) n = parseInt(String(n * max), 10) / 100;
16
+ if (Math.abs(n - max) < 1e-6) return 1;
17
+ if (max === 360) n = (n < 0 ? n % max + max : n % max) / parseFloat(String(max));
18
+ else n = n % max / parseFloat(String(max));
19
+ return n;
20
+ }
21
+ /**
22
+ * Force a number between 0 and 1
23
+ * @hidden
24
+ */
25
+ function clamp01(val) {
26
+ return Math.min(1, Math.max(0, val));
27
+ }
28
+ /**
29
+ * Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
30
+ * <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
31
+ * @hidden
32
+ */
33
+ function isOnePointZero(n) {
34
+ return typeof n === "string" && n.indexOf(".") !== -1 && parseFloat(n) === 1;
35
+ }
36
+ /**
37
+ * Check to see if string passed in is a percentage
38
+ * @hidden
39
+ */
40
+ function isPercentage(n) {
41
+ return typeof n === "string" && n.indexOf("%") !== -1;
42
+ }
43
+ /**
44
+ * Return a valid alpha value [0,1] with all invalid values being set to 1
45
+ * @hidden
46
+ */
47
+ function boundAlpha(a) {
48
+ a = parseFloat(a);
49
+ if (isNaN(a) || a < 0 || a > 1) a = 1;
50
+ return a;
51
+ }
52
+ /**
53
+ * Replace a decimal with it's percentage value
54
+ * @hidden
55
+ */
56
+ function convertToPercentage(n) {
57
+ if (Number(n) <= 1) return `${Number(n) * 100}%`;
58
+ return n;
59
+ }
60
+ /**
61
+ * Force a hex value to have 2 characters
62
+ * @hidden
63
+ */
64
+ function pad2(c) {
65
+ return c.length === 1 ? "0" + c : String(c);
66
+ }
67
+ //#endregion
68
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/conversion.js
69
+ /**
70
+ * Handle bounds / percentage checking to conform to CSS color spec
71
+ * <http://www.w3.org/TR/css3-color/>
72
+ * *Assumes:* r, g, b in [0, 255] or [0, 1]
73
+ * *Returns:* { r, g, b } in [0, 255]
74
+ */
75
+ function rgbToRgb(r, g, b) {
76
+ return {
77
+ r: bound01(r, 255) * 255,
78
+ g: bound01(g, 255) * 255,
79
+ b: bound01(b, 255) * 255
80
+ };
81
+ }
82
+ /**
83
+ * Converts an RGB color value to HSL.
84
+ * *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
85
+ * *Returns:* { h, s, l } in [0,1]
86
+ */
87
+ function rgbToHsl(r, g, b) {
88
+ r = bound01(r, 255);
89
+ g = bound01(g, 255);
90
+ b = bound01(b, 255);
91
+ const max = Math.max(r, g, b);
92
+ const min = Math.min(r, g, b);
93
+ let h = 0;
94
+ let s = 0;
95
+ const l = (max + min) / 2;
96
+ if (max === min) {
97
+ s = 0;
98
+ h = 0;
99
+ } else {
100
+ const d = max - min;
101
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
102
+ switch (max) {
103
+ case r:
104
+ h = (g - b) / d + (g < b ? 6 : 0);
105
+ break;
106
+ case g:
107
+ h = (b - r) / d + 2;
108
+ break;
109
+ case b: h = (r - g) / d + 4;
110
+ }
111
+ h /= 6;
112
+ }
113
+ return {
114
+ h,
115
+ s,
116
+ l
117
+ };
118
+ }
119
+ function hue2rgb(p, q, t) {
120
+ if (t < 0) t += 1;
121
+ if (t > 1) t -= 1;
122
+ if (t < 1 / 6) return p + (q - p) * (6 * t);
123
+ if (t < 1 / 2) return q;
124
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
125
+ return p;
126
+ }
127
+ /**
128
+ * Converts an HSL color value to RGB.
129
+ *
130
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
131
+ * *Returns:* { r, g, b } in the set [0, 255]
132
+ */
133
+ function hslToRgb(h, s, l) {
134
+ let r;
135
+ let g;
136
+ let b;
137
+ h = bound01(h, 360);
138
+ s = bound01(s, 100);
139
+ l = bound01(l, 100);
140
+ if (s === 0) {
141
+ g = l;
142
+ b = l;
143
+ r = l;
144
+ } else {
145
+ const q = l < .5 ? l * (1 + s) : l + s - l * s;
146
+ const p = 2 * l - q;
147
+ r = hue2rgb(p, q, h + 1 / 3);
148
+ g = hue2rgb(p, q, h);
149
+ b = hue2rgb(p, q, h - 1 / 3);
150
+ }
151
+ return {
152
+ r: r * 255,
153
+ g: g * 255,
154
+ b: b * 255
155
+ };
156
+ }
157
+ /**
158
+ * Converts an RGB color value to HSV
159
+ *
160
+ * *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
161
+ * *Returns:* { h, s, v } in [0,1]
162
+ */
163
+ function rgbToHsv(r, g, b) {
164
+ r = bound01(r, 255);
165
+ g = bound01(g, 255);
166
+ b = bound01(b, 255);
167
+ const max = Math.max(r, g, b);
168
+ const min = Math.min(r, g, b);
169
+ let h = 0;
170
+ const v = max;
171
+ const d = max - min;
172
+ const s = max === 0 ? 0 : d / max;
173
+ if (max === min) h = 0;
174
+ else {
175
+ switch (max) {
176
+ case r:
177
+ h = (g - b) / d + (g < b ? 6 : 0);
178
+ break;
179
+ case g:
180
+ h = (b - r) / d + 2;
181
+ break;
182
+ case b: h = (r - g) / d + 4;
183
+ }
184
+ h /= 6;
185
+ }
186
+ return {
187
+ h,
188
+ s,
189
+ v
190
+ };
191
+ }
192
+ /**
193
+ * Converts an HSV color value to RGB.
194
+ *
195
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
196
+ * *Returns:* { r, g, b } in the set [0, 255]
197
+ */
198
+ function hsvToRgb(h, s, v) {
199
+ h = bound01(h, 360) * 6;
200
+ s = bound01(s, 100);
201
+ v = bound01(v, 100);
202
+ const i = Math.floor(h);
203
+ const f = h - i;
204
+ const p = v * (1 - s);
205
+ const q = v * (1 - f * s);
206
+ const t = v * (1 - (1 - f) * s);
207
+ const mod = i % 6;
208
+ const r = [
209
+ v,
210
+ q,
211
+ p,
212
+ p,
213
+ t,
214
+ v
215
+ ][mod];
216
+ const g = [
217
+ t,
218
+ v,
219
+ v,
220
+ q,
221
+ p,
222
+ p
223
+ ][mod];
224
+ const b = [
225
+ p,
226
+ p,
227
+ t,
228
+ v,
229
+ v,
230
+ q
231
+ ][mod];
232
+ return {
233
+ r: r * 255,
234
+ g: g * 255,
235
+ b: b * 255
236
+ };
237
+ }
238
+ /**
239
+ * Converts an RGB color to hex
240
+ *
241
+ * *Assumes:* r, g, and b are contained in the set [0, 255]
242
+ * *Returns:* a 3 or 6 character hex
243
+ */
244
+ function rgbToHex(r, g, b, allow3Char) {
245
+ const hex = [
246
+ pad2(Math.round(r).toString(16)),
247
+ pad2(Math.round(g).toString(16)),
248
+ pad2(Math.round(b).toString(16))
249
+ ];
250
+ 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);
251
+ return hex.join("");
252
+ }
253
+ /**
254
+ * Converts an RGBA color plus alpha transparency to hex
255
+ *
256
+ * *Assumes:* r, g, b are contained in the set [0, 255] and a in [0, 1]
257
+ * *Returns:* a 4 or 8 character rgba hex
258
+ */
259
+ function rgbaToHex(r, g, b, a, allow4Char) {
260
+ const hex = [
261
+ pad2(Math.round(r).toString(16)),
262
+ pad2(Math.round(g).toString(16)),
263
+ pad2(Math.round(b).toString(16)),
264
+ pad2(convertDecimalToHex(a))
265
+ ];
266
+ 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);
267
+ return hex.join("");
268
+ }
269
+ /**
270
+ * Converts CMYK to RBG
271
+ * Assumes c, m, y, k are in the set [0, 100]
272
+ */
273
+ function cmykToRgb(c, m, y, k) {
274
+ const cConv = c / 100;
275
+ const mConv = m / 100;
276
+ const yConv = y / 100;
277
+ const kConv = k / 100;
278
+ return {
279
+ r: 255 * (1 - cConv) * (1 - kConv),
280
+ g: 255 * (1 - mConv) * (1 - kConv),
281
+ b: 255 * (1 - yConv) * (1 - kConv)
282
+ };
283
+ }
284
+ function rgbToCmyk(r, g, b) {
285
+ let c = 1 - r / 255;
286
+ let m = 1 - g / 255;
287
+ let y = 1 - b / 255;
288
+ let k = Math.min(c, m, y);
289
+ if (k === 1) {
290
+ c = 0;
291
+ m = 0;
292
+ y = 0;
293
+ } else {
294
+ c = (c - k) / (1 - k) * 100;
295
+ m = (m - k) / (1 - k) * 100;
296
+ y = (y - k) / (1 - k) * 100;
297
+ }
298
+ k *= 100;
299
+ return {
300
+ c: Math.round(c),
301
+ m: Math.round(m),
302
+ y: Math.round(y),
303
+ k: Math.round(k)
304
+ };
305
+ }
306
+ /** Converts a decimal to a hex value */
307
+ function convertDecimalToHex(d) {
308
+ return Math.round(parseFloat(d) * 255).toString(16);
309
+ }
310
+ /** Converts a hex value to a decimal */
311
+ function convertHexToDecimal(h) {
312
+ return parseIntFromHex(h) / 255;
313
+ }
314
+ /** Parse a base-16 hex value into a base-10 integer */
315
+ function parseIntFromHex(val) {
316
+ return parseInt(val, 16);
317
+ }
318
+ function numberInputToObject(color) {
319
+ return {
320
+ r: color >> 16,
321
+ g: (color & 65280) >> 8,
322
+ b: color & 255
323
+ };
324
+ }
325
+ //#endregion
326
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/css-color-names.js
327
+ /**
328
+ * @hidden
329
+ */
330
+ var names = {
331
+ aliceblue: "#f0f8ff",
332
+ antiquewhite: "#faebd7",
333
+ aqua: "#00ffff",
334
+ aquamarine: "#7fffd4",
335
+ azure: "#f0ffff",
336
+ beige: "#f5f5dc",
337
+ bisque: "#ffe4c4",
338
+ black: "#000000",
339
+ blanchedalmond: "#ffebcd",
340
+ blue: "#0000ff",
341
+ blueviolet: "#8a2be2",
342
+ brown: "#a52a2a",
343
+ burlywood: "#deb887",
344
+ cadetblue: "#5f9ea0",
345
+ chartreuse: "#7fff00",
346
+ chocolate: "#d2691e",
347
+ coral: "#ff7f50",
348
+ cornflowerblue: "#6495ed",
349
+ cornsilk: "#fff8dc",
350
+ crimson: "#dc143c",
351
+ cyan: "#00ffff",
352
+ darkblue: "#00008b",
353
+ darkcyan: "#008b8b",
354
+ darkgoldenrod: "#b8860b",
355
+ darkgray: "#a9a9a9",
356
+ darkgreen: "#006400",
357
+ darkgrey: "#a9a9a9",
358
+ darkkhaki: "#bdb76b",
359
+ darkmagenta: "#8b008b",
360
+ darkolivegreen: "#556b2f",
361
+ darkorange: "#ff8c00",
362
+ darkorchid: "#9932cc",
363
+ darkred: "#8b0000",
364
+ darksalmon: "#e9967a",
365
+ darkseagreen: "#8fbc8f",
366
+ darkslateblue: "#483d8b",
367
+ darkslategray: "#2f4f4f",
368
+ darkslategrey: "#2f4f4f",
369
+ darkturquoise: "#00ced1",
370
+ darkviolet: "#9400d3",
371
+ deeppink: "#ff1493",
372
+ deepskyblue: "#00bfff",
373
+ dimgray: "#696969",
374
+ dimgrey: "#696969",
375
+ dodgerblue: "#1e90ff",
376
+ firebrick: "#b22222",
377
+ floralwhite: "#fffaf0",
378
+ forestgreen: "#228b22",
379
+ fuchsia: "#ff00ff",
380
+ gainsboro: "#dcdcdc",
381
+ ghostwhite: "#f8f8ff",
382
+ goldenrod: "#daa520",
383
+ gold: "#ffd700",
384
+ gray: "#808080",
385
+ green: "#008000",
386
+ greenyellow: "#adff2f",
387
+ grey: "#808080",
388
+ honeydew: "#f0fff0",
389
+ hotpink: "#ff69b4",
390
+ indianred: "#cd5c5c",
391
+ indigo: "#4b0082",
392
+ ivory: "#fffff0",
393
+ khaki: "#f0e68c",
394
+ lavenderblush: "#fff0f5",
395
+ lavender: "#e6e6fa",
396
+ lawngreen: "#7cfc00",
397
+ lemonchiffon: "#fffacd",
398
+ lightblue: "#add8e6",
399
+ lightcoral: "#f08080",
400
+ lightcyan: "#e0ffff",
401
+ lightgoldenrodyellow: "#fafad2",
402
+ lightgray: "#d3d3d3",
403
+ lightgreen: "#90ee90",
404
+ lightgrey: "#d3d3d3",
405
+ lightpink: "#ffb6c1",
406
+ lightsalmon: "#ffa07a",
407
+ lightseagreen: "#20b2aa",
408
+ lightskyblue: "#87cefa",
409
+ lightslategray: "#778899",
410
+ lightslategrey: "#778899",
411
+ lightsteelblue: "#b0c4de",
412
+ lightyellow: "#ffffe0",
413
+ lime: "#00ff00",
414
+ limegreen: "#32cd32",
415
+ linen: "#faf0e6",
416
+ magenta: "#ff00ff",
417
+ maroon: "#800000",
418
+ mediumaquamarine: "#66cdaa",
419
+ mediumblue: "#0000cd",
420
+ mediumorchid: "#ba55d3",
421
+ mediumpurple: "#9370db",
422
+ mediumseagreen: "#3cb371",
423
+ mediumslateblue: "#7b68ee",
424
+ mediumspringgreen: "#00fa9a",
425
+ mediumturquoise: "#48d1cc",
426
+ mediumvioletred: "#c71585",
427
+ midnightblue: "#191970",
428
+ mintcream: "#f5fffa",
429
+ mistyrose: "#ffe4e1",
430
+ moccasin: "#ffe4b5",
431
+ navajowhite: "#ffdead",
432
+ navy: "#000080",
433
+ oldlace: "#fdf5e6",
434
+ olive: "#808000",
435
+ olivedrab: "#6b8e23",
436
+ orange: "#ffa500",
437
+ orangered: "#ff4500",
438
+ orchid: "#da70d6",
439
+ palegoldenrod: "#eee8aa",
440
+ palegreen: "#98fb98",
441
+ paleturquoise: "#afeeee",
442
+ palevioletred: "#db7093",
443
+ papayawhip: "#ffefd5",
444
+ peachpuff: "#ffdab9",
445
+ peru: "#cd853f",
446
+ pink: "#ffc0cb",
447
+ plum: "#dda0dd",
448
+ powderblue: "#b0e0e6",
449
+ purple: "#800080",
450
+ rebeccapurple: "#663399",
451
+ red: "#ff0000",
452
+ rosybrown: "#bc8f8f",
453
+ royalblue: "#4169e1",
454
+ saddlebrown: "#8b4513",
455
+ salmon: "#fa8072",
456
+ sandybrown: "#f4a460",
457
+ seagreen: "#2e8b57",
458
+ seashell: "#fff5ee",
459
+ sienna: "#a0522d",
460
+ silver: "#c0c0c0",
461
+ skyblue: "#87ceeb",
462
+ slateblue: "#6a5acd",
463
+ slategray: "#708090",
464
+ slategrey: "#708090",
465
+ snow: "#fffafa",
466
+ springgreen: "#00ff7f",
467
+ steelblue: "#4682b4",
468
+ tan: "#d2b48c",
469
+ teal: "#008080",
470
+ thistle: "#d8bfd8",
471
+ tomato: "#ff6347",
472
+ turquoise: "#40e0d0",
473
+ violet: "#ee82ee",
474
+ wheat: "#f5deb3",
475
+ white: "#ffffff",
476
+ whitesmoke: "#f5f5f5",
477
+ yellow: "#ffff00",
478
+ yellowgreen: "#9acd32"
479
+ };
480
+ //#endregion
481
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/format-input.js
482
+ /**
483
+ * Given a string or object, convert that input to RGB
484
+ *
485
+ * Possible string inputs:
486
+ * ```
487
+ * "red"
488
+ * "#f00" or "f00"
489
+ * "#ff0000" or "ff0000"
490
+ * "#ff000000" or "ff000000"
491
+ * "rgb 255 0 0" or "rgb (255, 0, 0)"
492
+ * "rgb 1.0 0 0" or "rgb (1, 0, 0)"
493
+ * "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
494
+ * "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
495
+ * "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
496
+ * "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
497
+ * "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
498
+ * "cmyk(0, 20, 0, 0)" or "cmyk 0 20 0 0"
499
+ * ```
500
+ */
501
+ function inputToRGB(color) {
502
+ let rgb = {
503
+ r: 0,
504
+ g: 0,
505
+ b: 0
506
+ };
507
+ let a = 1;
508
+ let s = null;
509
+ let v = null;
510
+ let l = null;
511
+ let ok = false;
512
+ let format = false;
513
+ if (typeof color === "string") color = stringInputToObject(color);
514
+ if (typeof color === "object") {
515
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
516
+ rgb = rgbToRgb(color.r, color.g, color.b);
517
+ ok = true;
518
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
519
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
520
+ s = convertToPercentage(color.s);
521
+ v = convertToPercentage(color.v);
522
+ rgb = hsvToRgb(color.h, s, v);
523
+ ok = true;
524
+ format = "hsv";
525
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
526
+ s = convertToPercentage(color.s);
527
+ l = convertToPercentage(color.l);
528
+ rgb = hslToRgb(color.h, s, l);
529
+ ok = true;
530
+ format = "hsl";
531
+ } else if (isValidCSSUnit(color.c) && isValidCSSUnit(color.m) && isValidCSSUnit(color.y) && isValidCSSUnit(color.k)) {
532
+ rgb = cmykToRgb(color.c, color.m, color.y, color.k);
533
+ ok = true;
534
+ format = "cmyk";
535
+ }
536
+ if (Object.prototype.hasOwnProperty.call(color, "a")) a = color.a;
537
+ }
538
+ a = boundAlpha(a);
539
+ return {
540
+ ok,
541
+ format: color.format || format,
542
+ r: Math.min(255, Math.max(rgb.r, 0)),
543
+ g: Math.min(255, Math.max(rgb.g, 0)),
544
+ b: Math.min(255, Math.max(rgb.b, 0)),
545
+ a
546
+ };
547
+ }
548
+ var CSS_UNIT = "(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)";
549
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
550
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
551
+ var matchers = {
552
+ CSS_UNIT: new RegExp(CSS_UNIT),
553
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
554
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
555
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
556
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
557
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
558
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
559
+ cmyk: new RegExp("cmyk" + PERMISSIVE_MATCH4),
560
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
561
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
562
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
563
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
564
+ };
565
+ /**
566
+ * Permissive string parsing. Take in a number of formats, and output an object
567
+ * 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}`
568
+ */
569
+ function stringInputToObject(color) {
570
+ color = color.trim().toLowerCase();
571
+ if (color.length === 0) return false;
572
+ let named = false;
573
+ if (names[color]) {
574
+ color = names[color];
575
+ named = true;
576
+ } else if (color === "transparent") return {
577
+ r: 0,
578
+ g: 0,
579
+ b: 0,
580
+ a: 0,
581
+ format: "name"
582
+ };
583
+ let match = matchers.rgb.exec(color);
584
+ if (match) return {
585
+ r: match[1],
586
+ g: match[2],
587
+ b: match[3]
588
+ };
589
+ match = matchers.rgba.exec(color);
590
+ if (match) return {
591
+ r: match[1],
592
+ g: match[2],
593
+ b: match[3],
594
+ a: match[4]
595
+ };
596
+ match = matchers.hsl.exec(color);
597
+ if (match) return {
598
+ h: match[1],
599
+ s: match[2],
600
+ l: match[3]
601
+ };
602
+ match = matchers.hsla.exec(color);
603
+ if (match) return {
604
+ h: match[1],
605
+ s: match[2],
606
+ l: match[3],
607
+ a: match[4]
608
+ };
609
+ match = matchers.hsv.exec(color);
610
+ if (match) return {
611
+ h: match[1],
612
+ s: match[2],
613
+ v: match[3]
614
+ };
615
+ match = matchers.hsva.exec(color);
616
+ if (match) return {
617
+ h: match[1],
618
+ s: match[2],
619
+ v: match[3],
620
+ a: match[4]
621
+ };
622
+ match = matchers.cmyk.exec(color);
623
+ if (match) return {
624
+ c: match[1],
625
+ m: match[2],
626
+ y: match[3],
627
+ k: match[4]
628
+ };
629
+ match = matchers.hex8.exec(color);
630
+ if (match) return {
631
+ r: parseIntFromHex(match[1]),
632
+ g: parseIntFromHex(match[2]),
633
+ b: parseIntFromHex(match[3]),
634
+ a: convertHexToDecimal(match[4]),
635
+ format: named ? "name" : "hex8"
636
+ };
637
+ match = matchers.hex6.exec(color);
638
+ if (match) return {
639
+ r: parseIntFromHex(match[1]),
640
+ g: parseIntFromHex(match[2]),
641
+ b: parseIntFromHex(match[3]),
642
+ format: named ? "name" : "hex"
643
+ };
644
+ match = matchers.hex4.exec(color);
645
+ if (match) return {
646
+ r: parseIntFromHex(match[1] + match[1]),
647
+ g: parseIntFromHex(match[2] + match[2]),
648
+ b: parseIntFromHex(match[3] + match[3]),
649
+ a: convertHexToDecimal(match[4] + match[4]),
650
+ format: named ? "name" : "hex8"
651
+ };
652
+ match = matchers.hex3.exec(color);
653
+ if (match) return {
654
+ r: parseIntFromHex(match[1] + match[1]),
655
+ g: parseIntFromHex(match[2] + match[2]),
656
+ b: parseIntFromHex(match[3] + match[3]),
657
+ format: named ? "name" : "hex"
658
+ };
659
+ return false;
660
+ }
661
+ /**
662
+ * Check to see if it looks like a CSS unit
663
+ * (see `matchers` above for definition).
664
+ */
665
+ function isValidCSSUnit(color) {
666
+ if (typeof color === "number") return !Number.isNaN(color);
667
+ return matchers.CSS_UNIT.test(color);
668
+ }
669
+ //#endregion
670
+ //#region ../../../node_modules/@ctrl/tinycolor/dist/module/index.js
671
+ var TinyColor = class TinyColor {
672
+ constructor(color = "", opts = {}) {
673
+ if (color instanceof TinyColor) return color;
674
+ if (typeof color === "number") color = numberInputToObject(color);
675
+ this.originalInput = color;
676
+ const rgb = inputToRGB(color);
677
+ this.originalInput = color;
678
+ this.r = rgb.r;
679
+ this.g = rgb.g;
680
+ this.b = rgb.b;
681
+ this.a = rgb.a;
682
+ this.roundA = Math.round(100 * this.a) / 100;
683
+ this.format = opts.format ?? rgb.format;
684
+ this.gradientType = opts.gradientType;
685
+ if (this.r < 1) this.r = Math.round(this.r);
686
+ if (this.g < 1) this.g = Math.round(this.g);
687
+ if (this.b < 1) this.b = Math.round(this.b);
688
+ this.isValid = rgb.ok;
689
+ }
690
+ isDark() {
691
+ return this.getBrightness() < 128;
692
+ }
693
+ isLight() {
694
+ return !this.isDark();
695
+ }
696
+ /**
697
+ * Returns the perceived brightness of the color, from 0-255.
698
+ */
699
+ getBrightness() {
700
+ const rgb = this.toRgb();
701
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
702
+ }
703
+ /**
704
+ * Returns the perceived luminance of a color, from 0-1.
705
+ */
706
+ getLuminance() {
707
+ const rgb = this.toRgb();
708
+ let R;
709
+ let G;
710
+ let B;
711
+ const RsRGB = rgb.r / 255;
712
+ const GsRGB = rgb.g / 255;
713
+ const BsRGB = rgb.b / 255;
714
+ if (RsRGB <= .03928) R = RsRGB / 12.92;
715
+ else R = Math.pow((RsRGB + .055) / 1.055, 2.4);
716
+ if (GsRGB <= .03928) G = GsRGB / 12.92;
717
+ else G = Math.pow((GsRGB + .055) / 1.055, 2.4);
718
+ if (BsRGB <= .03928) B = BsRGB / 12.92;
719
+ else B = Math.pow((BsRGB + .055) / 1.055, 2.4);
720
+ return .2126 * R + .7152 * G + .0722 * B;
721
+ }
722
+ /**
723
+ * Returns the alpha value of a color, from 0-1.
724
+ */
725
+ getAlpha() {
726
+ return this.a;
727
+ }
728
+ /**
729
+ * Sets the alpha value on the current color.
730
+ *
731
+ * @param alpha - The new alpha value. The accepted range is 0-1.
732
+ */
733
+ setAlpha(alpha) {
734
+ this.a = boundAlpha(alpha);
735
+ this.roundA = Math.round(100 * this.a) / 100;
736
+ return this;
737
+ }
738
+ /**
739
+ * Returns whether the color is monochrome.
740
+ */
741
+ isMonochrome() {
742
+ const { s } = this.toHsl();
743
+ return s === 0;
744
+ }
745
+ /**
746
+ * Returns the object as a HSVA object.
747
+ */
748
+ toHsv() {
749
+ const hsv = rgbToHsv(this.r, this.g, this.b);
750
+ return {
751
+ h: hsv.h * 360,
752
+ s: hsv.s,
753
+ v: hsv.v,
754
+ a: this.a
755
+ };
756
+ }
757
+ /**
758
+ * Returns the hsva values interpolated into a string with the following format:
759
+ * "hsva(xxx, xxx, xxx, xx)".
760
+ */
761
+ toHsvString() {
762
+ const hsv = rgbToHsv(this.r, this.g, this.b);
763
+ const h = Math.round(hsv.h * 360);
764
+ const s = Math.round(hsv.s * 100);
765
+ const v = Math.round(hsv.v * 100);
766
+ return this.a === 1 ? `hsv(${h}, ${s}%, ${v}%)` : `hsva(${h}, ${s}%, ${v}%, ${this.roundA})`;
767
+ }
768
+ /**
769
+ * Returns the object as a HSLA object.
770
+ */
771
+ toHsl() {
772
+ const hsl = rgbToHsl(this.r, this.g, this.b);
773
+ return {
774
+ h: hsl.h * 360,
775
+ s: hsl.s,
776
+ l: hsl.l,
777
+ a: this.a
778
+ };
779
+ }
780
+ /**
781
+ * Returns the hsla values interpolated into a string with the following format:
782
+ * "hsla(xxx, xxx, xxx, xx)".
783
+ */
784
+ toHslString() {
785
+ const hsl = rgbToHsl(this.r, this.g, this.b);
786
+ const h = Math.round(hsl.h * 360);
787
+ const s = Math.round(hsl.s * 100);
788
+ const l = Math.round(hsl.l * 100);
789
+ return this.a === 1 ? `hsl(${h}, ${s}%, ${l}%)` : `hsla(${h}, ${s}%, ${l}%, ${this.roundA})`;
790
+ }
791
+ /**
792
+ * Returns the hex value of the color.
793
+ * @param allow3Char will shorten hex value to 3 char if possible
794
+ */
795
+ toHex(allow3Char = false) {
796
+ return rgbToHex(this.r, this.g, this.b, allow3Char);
797
+ }
798
+ /**
799
+ * Returns the hex value of the color -with a # prefixed.
800
+ * @param allow3Char will shorten hex value to 3 char if possible
801
+ */
802
+ toHexString(allow3Char = false) {
803
+ return "#" + this.toHex(allow3Char);
804
+ }
805
+ /**
806
+ * Returns the hex 8 value of the color.
807
+ * @param allow4Char will shorten hex value to 4 char if possible
808
+ */
809
+ toHex8(allow4Char = false) {
810
+ return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char);
811
+ }
812
+ /**
813
+ * Returns the hex 8 value of the color -with a # prefixed.
814
+ * @param allow4Char will shorten hex value to 4 char if possible
815
+ */
816
+ toHex8String(allow4Char = false) {
817
+ return "#" + this.toHex8(allow4Char);
818
+ }
819
+ /**
820
+ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
821
+ * @param allowShortChar will shorten hex value to 3 or 4 char if possible
822
+ */
823
+ toHexShortString(allowShortChar = false) {
824
+ return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar);
825
+ }
826
+ /**
827
+ * Returns the object as a RGBA object.
828
+ */
829
+ toRgb() {
830
+ return {
831
+ r: Math.round(this.r),
832
+ g: Math.round(this.g),
833
+ b: Math.round(this.b),
834
+ a: this.a
835
+ };
836
+ }
837
+ /**
838
+ * Returns the RGBA values interpolated into a string with the following format:
839
+ * "RGBA(xxx, xxx, xxx, xx)".
840
+ */
841
+ toRgbString() {
842
+ const r = Math.round(this.r);
843
+ const g = Math.round(this.g);
844
+ const b = Math.round(this.b);
845
+ return this.a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${this.roundA})`;
846
+ }
847
+ /**
848
+ * Returns the object as a RGBA object.
849
+ */
850
+ toPercentageRgb() {
851
+ const fmt = (x) => `${Math.round(bound01(x, 255) * 100)}%`;
852
+ return {
853
+ r: fmt(this.r),
854
+ g: fmt(this.g),
855
+ b: fmt(this.b),
856
+ a: this.a
857
+ };
858
+ }
859
+ /**
860
+ * Returns the RGBA relative values interpolated into a string
861
+ */
862
+ toPercentageRgbString() {
863
+ const rnd = (x) => Math.round(bound01(x, 255) * 100);
864
+ 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})`;
865
+ }
866
+ toCmyk() {
867
+ return { ...rgbToCmyk(this.r, this.g, this.b) };
868
+ }
869
+ toCmykString() {
870
+ const { c, m, y, k } = rgbToCmyk(this.r, this.g, this.b);
871
+ return `cmyk(${c}, ${m}, ${y}, ${k})`;
872
+ }
873
+ /**
874
+ * The 'real' name of the color -if there is one.
875
+ */
876
+ toName() {
877
+ if (this.a === 0) return "transparent";
878
+ if (this.a < 1) return false;
879
+ const hex = "#" + rgbToHex(this.r, this.g, this.b, false);
880
+ for (const [key, value] of Object.entries(names)) if (hex === value) return key;
881
+ return false;
882
+ }
883
+ toString(format) {
884
+ const formatSet = Boolean(format);
885
+ format = format ?? this.format;
886
+ let formattedString = false;
887
+ const hasAlpha = this.a < 1 && this.a >= 0;
888
+ if (!formatSet && hasAlpha && (format.startsWith("hex") || format === "name")) {
889
+ if (format === "name" && this.a === 0) return this.toName();
890
+ return this.toRgbString();
891
+ }
892
+ if (format === "rgb") formattedString = this.toRgbString();
893
+ if (format === "prgb") formattedString = this.toPercentageRgbString();
894
+ if (format === "hex" || format === "hex6") formattedString = this.toHexString();
895
+ if (format === "hex3") formattedString = this.toHexString(true);
896
+ if (format === "hex4") formattedString = this.toHex8String(true);
897
+ if (format === "hex8") formattedString = this.toHex8String();
898
+ if (format === "name") formattedString = this.toName();
899
+ if (format === "hsl") formattedString = this.toHslString();
900
+ if (format === "hsv") formattedString = this.toHsvString();
901
+ if (format === "cmyk") formattedString = this.toCmykString();
902
+ return formattedString || this.toHexString();
903
+ }
904
+ toNumber() {
905
+ return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b);
906
+ }
907
+ clone() {
908
+ return new TinyColor(this.toString());
909
+ }
910
+ /**
911
+ * Lighten the color a given amount. Providing 100 will always return white.
912
+ * @param amount - valid between 1-100
913
+ */
914
+ lighten(amount = 10) {
915
+ const hsl = this.toHsl();
916
+ hsl.l += amount / 100;
917
+ hsl.l = clamp01(hsl.l);
918
+ return new TinyColor(hsl);
919
+ }
920
+ /**
921
+ * Brighten the color a given amount, from 0 to 100.
922
+ * @param amount - valid between 1-100
923
+ */
924
+ brighten(amount = 10) {
925
+ const rgb = this.toRgb();
926
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
927
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
928
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
929
+ return new TinyColor(rgb);
930
+ }
931
+ /**
932
+ * Darken the color a given amount, from 0 to 100.
933
+ * Providing 100 will always return black.
934
+ * @param amount - valid between 1-100
935
+ */
936
+ darken(amount = 10) {
937
+ const hsl = this.toHsl();
938
+ hsl.l -= amount / 100;
939
+ hsl.l = clamp01(hsl.l);
940
+ return new TinyColor(hsl);
941
+ }
942
+ /**
943
+ * Mix the color with pure white, from 0 to 100.
944
+ * Providing 0 will do nothing, providing 100 will always return white.
945
+ * @param amount - valid between 1-100
946
+ */
947
+ tint(amount = 10) {
948
+ return this.mix("white", amount);
949
+ }
950
+ /**
951
+ * Mix the color with pure black, from 0 to 100.
952
+ * Providing 0 will do nothing, providing 100 will always return black.
953
+ * @param amount - valid between 1-100
954
+ */
955
+ shade(amount = 10) {
956
+ return this.mix("black", amount);
957
+ }
958
+ /**
959
+ * Desaturate the color a given amount, from 0 to 100.
960
+ * Providing 100 will is the same as calling greyscale
961
+ * @param amount - valid between 1-100
962
+ */
963
+ desaturate(amount = 10) {
964
+ const hsl = this.toHsl();
965
+ hsl.s -= amount / 100;
966
+ hsl.s = clamp01(hsl.s);
967
+ return new TinyColor(hsl);
968
+ }
969
+ /**
970
+ * Saturate the color a given amount, from 0 to 100.
971
+ * @param amount - valid between 1-100
972
+ */
973
+ saturate(amount = 10) {
974
+ const hsl = this.toHsl();
975
+ hsl.s += amount / 100;
976
+ hsl.s = clamp01(hsl.s);
977
+ return new TinyColor(hsl);
978
+ }
979
+ /**
980
+ * Completely desaturates a color into greyscale.
981
+ * Same as calling `desaturate(100)`
982
+ */
983
+ greyscale() {
984
+ return this.desaturate(100);
985
+ }
986
+ /**
987
+ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
988
+ * Values outside of this range will be wrapped into this range.
989
+ */
990
+ spin(amount) {
991
+ const hsl = this.toHsl();
992
+ const hue = (hsl.h + amount) % 360;
993
+ hsl.h = hue < 0 ? 360 + hue : hue;
994
+ return new TinyColor(hsl);
995
+ }
996
+ /**
997
+ * Mix the current color a given amount with another color, from 0 to 100.
998
+ * 0 means no mixing (return current color).
999
+ */
1000
+ mix(color, amount = 50) {
1001
+ const rgb1 = this.toRgb();
1002
+ const rgb2 = new TinyColor(color).toRgb();
1003
+ const p = amount / 100;
1004
+ const rgba = {
1005
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
1006
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
1007
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
1008
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
1009
+ };
1010
+ return new TinyColor(rgba);
1011
+ }
1012
+ analogous(results = 6, slices = 30) {
1013
+ const hsl = this.toHsl();
1014
+ const part = 360 / slices;
1015
+ const ret = [this];
1016
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
1017
+ hsl.h = (hsl.h + part) % 360;
1018
+ ret.push(new TinyColor(hsl));
1019
+ }
1020
+ return ret;
1021
+ }
1022
+ /**
1023
+ * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
1024
+ */
1025
+ complement() {
1026
+ const hsl = this.toHsl();
1027
+ hsl.h = (hsl.h + 180) % 360;
1028
+ return new TinyColor(hsl);
1029
+ }
1030
+ monochromatic(results = 6) {
1031
+ const hsv = this.toHsv();
1032
+ const { h } = hsv;
1033
+ const { s } = hsv;
1034
+ let { v } = hsv;
1035
+ const res = [];
1036
+ const modification = 1 / results;
1037
+ while (results--) {
1038
+ res.push(new TinyColor({
1039
+ h,
1040
+ s,
1041
+ v
1042
+ }));
1043
+ v = (v + modification) % 1;
1044
+ }
1045
+ return res;
1046
+ }
1047
+ splitcomplement() {
1048
+ const hsl = this.toHsl();
1049
+ const { h } = hsl;
1050
+ return [
1051
+ this,
1052
+ new TinyColor({
1053
+ h: (h + 72) % 360,
1054
+ s: hsl.s,
1055
+ l: hsl.l
1056
+ }),
1057
+ new TinyColor({
1058
+ h: (h + 216) % 360,
1059
+ s: hsl.s,
1060
+ l: hsl.l
1061
+ })
1062
+ ];
1063
+ }
1064
+ /**
1065
+ * Compute how the color would appear on a background
1066
+ */
1067
+ onBackground(background) {
1068
+ const fg = this.toRgb();
1069
+ const bg = new TinyColor(background).toRgb();
1070
+ const alpha = fg.a + bg.a * (1 - fg.a);
1071
+ return new TinyColor({
1072
+ r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / alpha,
1073
+ g: (fg.g * fg.a + bg.g * bg.a * (1 - fg.a)) / alpha,
1074
+ b: (fg.b * fg.a + bg.b * bg.a * (1 - fg.a)) / alpha,
1075
+ a: alpha
1076
+ });
1077
+ }
1078
+ /**
1079
+ * Alias for `polyad(3)`
1080
+ */
1081
+ triad() {
1082
+ return this.polyad(3);
1083
+ }
1084
+ /**
1085
+ * Alias for `polyad(4)`
1086
+ */
1087
+ tetrad() {
1088
+ return this.polyad(4);
1089
+ }
1090
+ /**
1091
+ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
1092
+ * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
1093
+ */
1094
+ polyad(n) {
1095
+ const hsl = this.toHsl();
1096
+ const { h } = hsl;
1097
+ const result = [this];
1098
+ const increment = 360 / n;
1099
+ for (let i = 1; i < n; i++) result.push(new TinyColor({
1100
+ h: (h + i * increment) % 360,
1101
+ s: hsl.s,
1102
+ l: hsl.l
1103
+ }));
1104
+ return result;
1105
+ }
1106
+ /**
1107
+ * compare color vs current color
1108
+ */
1109
+ equals(color) {
1110
+ const comparedColor = new TinyColor(color);
1111
+ /**
1112
+ * RGB and CMYK do not have the same color gamut, so a CMYK conversion will never be 100%.
1113
+ * This means we need to compare CMYK to CMYK to ensure accuracy of the equals function.
1114
+ */
1115
+ if (this.format === "cmyk" || comparedColor.format === "cmyk") return this.toCmykString() === comparedColor.toCmykString();
1116
+ return this.toRgbString() === comparedColor.toRgbString();
1117
+ }
1118
+ };
1119
+ //#endregion
1120
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
1121
+ function __decorate(decorators, target, key, desc) {
1122
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1123
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1124
+ 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;
1125
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1126
+ }
1127
+ //#endregion
1128
+ //#region src/color-area.ts
1129
+ var ColorArea = class ColorArea extends LitElement {
1130
+ constructor(..._args) {
1131
+ super(..._args);
1132
+ this.hue = 0;
1133
+ this.saturation = 1;
1134
+ this.value = 1;
1135
+ this.currentMousePosition = {
1136
+ x: 0,
1137
+ y: 0
1138
+ };
1139
+ this.handleMouseMove = async (event) => {
1140
+ this.currentMousePosition = this.getPointerPosition(event);
1141
+ this.convertPositionToHslValues(this.currentMousePosition);
1142
+ this.dispatchChangeColor();
1143
+ };
1144
+ this.handleMouseUp = () => {
1145
+ document.removeEventListener("pointermove", this.handleMouseMove);
1146
+ document.removeEventListener("pointerup", this.handleMouseUp);
1147
+ document.removeEventListener("pointercancel", this.handleMouseUp);
1148
+ this.rootElementsRect = void 0;
1149
+ };
1150
+ }
1151
+ static {
1152
+ this.styles = unsafeCSS(color_area_default);
1153
+ }
1154
+ get tinyColor() {
1155
+ return new TinyColor({
1156
+ h: this.hue,
1157
+ s: this.saturation,
1158
+ v: this.value
1159
+ });
1160
+ }
1161
+ convertPositionToHslValues(position) {
1162
+ if (!this.rootElement) return;
1163
+ if (!this.rootElementsRect) this.rootElementsRect = this.rootElement.getBoundingClientRect();
1164
+ this.saturation = position.x / this.rootElementsRect.width;
1165
+ this.value = 1 - position.y / this.rootElementsRect.height;
1166
+ }
1167
+ convertValueToPosition() {
1168
+ if (!this.rootElementsRect) this.rootElementsRect = this.rootElement.getBoundingClientRect();
1169
+ this.currentMousePosition = {
1170
+ x: this.saturation * this.rootElementsRect.width,
1171
+ y: (1 - this.value) * this.rootElementsRect.height
1172
+ };
1173
+ }
1174
+ handleAreaPointerdown(event) {
1175
+ if (event.button !== 0) return;
1176
+ this.rootElementsRect = this.rootElement.getBoundingClientRect();
1177
+ this.colorHandleRect = this.colorHandle.getBoundingClientRect();
1178
+ this.currentMousePosition = this.getPointerPosition(event);
1179
+ this.convertPositionToHslValues(this.currentMousePosition);
1180
+ document.addEventListener("pointermove", this.handleMouseMove, { passive: true });
1181
+ document.addEventListener("pointerup", this.handleMouseUp, { passive: true });
1182
+ document.addEventListener("pointercancel", this.handleMouseUp);
1183
+ this.dispatchChangeColor();
1184
+ }
1185
+ getPointerPosition(event) {
1186
+ let x = event.clientX - this.rootElementsRect.left;
1187
+ let y = event.clientY - this.rootElementsRect.top;
1188
+ x = Math.max(0, Math.min(x, this.rootElementsRect.width));
1189
+ y = Math.max(0, Math.min(y, this.rootElementsRect.height));
1190
+ return {
1191
+ x,
1192
+ y
1193
+ };
1194
+ }
1195
+ updateColorHandlePosition() {
1196
+ if (!this.colorHandle) return;
1197
+ if (!this.colorHandleRect) this.colorHandleRect = this.colorHandle.getBoundingClientRect();
1198
+ const handleWidth = this.colorHandleRect.width;
1199
+ const handleHeight = this.colorHandleRect.height;
1200
+ let x = this.currentMousePosition.x - handleWidth / 2;
1201
+ let y = this.currentMousePosition.y - handleHeight / 2;
1202
+ x = Math.max(0, Math.min(x, this.rootElementsRect.width - handleWidth));
1203
+ y = Math.max(0, Math.min(y, this.rootElementsRect.height - handleHeight));
1204
+ this.colorHandle.style.setProperty("transform", `translate3d(${x}px, ${y}px, 0)`);
1205
+ this.colorHandle.style.setProperty("background-color", this.tinyColor.toRgbString());
1206
+ }
1207
+ updated(_changedProperties) {
1208
+ super.updated(_changedProperties);
1209
+ this.convertValueToPosition();
1210
+ this.updateColorHandlePosition();
1211
+ }
1212
+ dispatchChangeColor() {
1213
+ this.dispatchEvent(new CustomEvent("change", {
1214
+ bubbles: true,
1215
+ cancelable: true,
1216
+ detail: {
1217
+ h: this.hue,
1218
+ s: this.saturation,
1219
+ v: this.value
1220
+ }
1221
+ }));
1222
+ }
1223
+ render() {
1224
+ return html`<div class="c2-color-area">
1225
+ <div
1226
+ @pointerdown=${this.handleAreaPointerdown}
1227
+ class="gradient"
1228
+ style="background:
1229
+ linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),
1230
+ linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);"
1231
+ ></div>
1232
+ <div class="color-handle"></div>
1233
+ </div> `;
1234
+ }
1235
+ };
1236
+ __decorate([property({ type: Number })], ColorArea.prototype, "hue", void 0);
1237
+ __decorate([property({ type: Number })], ColorArea.prototype, "saturation", void 0);
1238
+ __decorate([property({ type: Number })], ColorArea.prototype, "value", void 0);
1239
+ __decorate([query(".color-handle", true)], ColorArea.prototype, "colorHandle", void 0);
1240
+ __decorate([query(".c2-color-area", true)], ColorArea.prototype, "rootElement", void 0);
1241
+ ColorArea = __decorate([customElement("c2-color-area")], ColorArea);
1242
+ //#endregion
1243
+ export { ColorArea };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@c2n/color-area",
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "main": "dist/color-area.js",
6
+ "exports": {
7
+ ".": {
8
+ "default": "./dist/color-area.js",
9
+ "types": "./types/src/color-area.d.ts"
10
+ },
11
+ "./custom-elements.json": "./custom-elements.json"
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "types"
16
+ ],
17
+ "keywords": [
18
+ "color-area",
19
+ "web component",
20
+ "lit"
21
+ ],
22
+ "author": "code2nguyen@gmail.com",
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org",
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/code2nguyen/web-components.git"
30
+ },
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "build": "wireit",
34
+ "type-check": "wireit"
35
+ },
36
+ "wireit": {
37
+ "type-check": {
38
+ "dependencies": [
39
+ "../../core:build"
40
+ ],
41
+ "command": "tsc -p tsconfig.lib.json --composite false"
42
+ },
43
+ "build": {
44
+ "dependencies": [
45
+ "type-check"
46
+ ],
47
+ "command": "vite build"
48
+ }
49
+ },
50
+ "dependencies": {
51
+ "@c2n/core": "0.0.6",
52
+ "@ctrl/tinycolor": "4.2.0",
53
+ "lit": "3.3.3"
54
+ },
55
+ "devDependencies": {
56
+ "@c2n/config": "*"
57
+ },
58
+ "customElements": "custom-elements.json",
59
+ "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
60
+ }
@@ -0,0 +1,51 @@
1
+ import { LitElement, type PropertyValueMap } from 'lit';
2
+ import { TinyColor } from '@ctrl/tinycolor';
3
+ export interface Point {
4
+ x: number;
5
+ y: number;
6
+ }
7
+ /**
8
+ * @tag c2-color-area
9
+ *
10
+ * @event {CustomEvent} change
11
+ *
12
+ * @cssproperty {pixel} [--c2-color-area--width=240px]
13
+ * @cssproperty {pixel} [--c2-color-area--height=240px]
14
+ * @cssproperty {pixel} [--c2-color-area__color-handle--size=12px]
15
+ *
16
+ * @cssproperty {border-radius} --c2-color-area--border-top-left-radius
17
+ * @cssproperty {border-radius} --c2-color-area--border-top-right-radius
18
+ * @cssproperty {border-radius} --c2-color-area--border-bottom-left-radius
19
+ * @cssproperty {border-radius} --c2-color-area--border-bottom-right-radius
20
+ */
21
+ export declare class ColorArea extends LitElement {
22
+ static styles: import("lit").CSSResult;
23
+ hue: number;
24
+ saturation: number;
25
+ value: number;
26
+ get tinyColor(): TinyColor;
27
+ colorHandle?: HTMLElement;
28
+ rootElement?: HTMLElement;
29
+ currentMousePosition: Point;
30
+ private rootElementsRect?;
31
+ private colorHandleRect?;
32
+ convertPositionToHslValues(position: Point): void;
33
+ private convertValueToPosition;
34
+ private handleAreaPointerdown;
35
+ handleMouseMove: (event: PointerEvent) => Promise<void>;
36
+ getPointerPosition(event: PointerEvent): {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ handleMouseUp: () => void;
41
+ private updateColorHandlePosition;
42
+ protected updated(_changedProperties: PropertyValueMap<this>): void;
43
+ dispatchChangeColor(): void;
44
+ render(): import("lit-html").TemplateResult<1>;
45
+ }
46
+ declare global {
47
+ interface HTMLElementTagNameMap {
48
+ 'c2-color-area': ColorArea;
49
+ }
50
+ }
51
+ //# sourceMappingURL=color-area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-area.d.ts","sourceRoot":"","sources":["../../src/color-area.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAGxE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;;;;;;;;;GAaG;AACH,qBACa,SAAU,SAAQ,UAAU;IACvC,OAAgB,MAAM,0BAAoB;IAEd,GAAG,SAAI;IACP,UAAU,SAAI;IACd,KAAK,SAAI;IAErC,IAAW,SAAS,IAAI,SAAS,CAEhC;IAE6B,WAAW,CAAC,EAAE,WAAW,CAAA;IACxB,WAAW,CAAC,EAAE,WAAW,CAAA;IAExD,oBAAoB,EAAE,KAAK,CAAiB;IAE5C,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAClC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC,0BAA0B,CAAC,QAAQ,EAAE,KAAK;IAW1C,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAgB7B,eAAe,GAAU,OAAO,YAAY,mBAI3C;IAED,kBAAkB,CAAC,KAAK,EAAE,YAAY;;;;IAQtC,aAAa,aAKZ;IAED,OAAO,CAAC,yBAAyB;cAed,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IAM5E,mBAAmB;IAaV,MAAM;CAYhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,eAAe,EAAE,SAAS,CAAA;KAC3B;CACF"}