@auaust/jaune 0.0.0 → 0.0.1

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,455 @@
1
+ import { Writable } from 'type-fest';
2
+
3
+ type ColorTypeMap = {
4
+ channels: ColorChannels;
5
+ color: Color;
6
+ hex: Hex;
7
+ named: NamedColor;
8
+ rgb: Rgb;
9
+ };
10
+ /**
11
+ * The known color types.
12
+ *
13
+ * `channels` - An object of each color channel.
14
+ * `color` - A `Color` instance.
15
+ * `hex` - A HEX color string.
16
+ * `named` - A CSS color name.
17
+ * `rgb` - A tuple representing RGB color channels.
18
+ */
19
+ type ColorType = keyof ColorTypeMap;
20
+ /** Represents a color in any of the various supported formats. */
21
+ type ColorValue = ColorTypeMap[ColorType];
22
+ /** A HEX color string. It must start with a hash (#) character followed by 3, 4, 6, or 8 hexadecimal digits. */
23
+ type Hex = `#${string}` | (string & {});
24
+ /**
25
+ * A tuple representing RGB color channels.
26
+ *
27
+ * The first three elements are integers between 0 and 255 representing the red, green, and blue channels, respectively.
28
+ * The fourth element is a number between 0 and 1 representing the alpha channel.
29
+ */
30
+ type Rgb = readonly [r: number, g: number, b: number, a?: number] | readonly number[];
31
+ /**
32
+ * A CSS color name.
33
+ *
34
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
35
+ */
36
+ type NamedColor = keyof typeof namedColorsMap;
37
+ type MaybeNamedColor = NamedColor | (string & {});
38
+ /**
39
+ * An object of each color channel.
40
+ *
41
+ * `r`, `g`, and `b` are integers between 0 and 255 representing the red, green, and blue channels, respectively.
42
+ * `a` is a number between 0 and 1 representing the alpha channel.
43
+ * It may contain metadata about the color and its handling by the color parser.
44
+ */
45
+ type ColorChannels = {
46
+ /**
47
+ * The red channel.
48
+ */
49
+ readonly r: number;
50
+ /**
51
+ * The green channel.
52
+ */
53
+ readonly g: number;
54
+ /**
55
+ * The blue channel.
56
+ */
57
+ readonly b: number;
58
+ /**
59
+ * The alpha channel.
60
+ */
61
+ readonly a?: number;
62
+ /**
63
+ * Whether any of the channels have been transformed by the color parser.
64
+ */
65
+ readonly isTransformed?: boolean;
66
+ /**
67
+ * Whether the color is the fallback color, which is used when the input is invalid.
68
+ */
69
+ readonly isFallback?: boolean;
70
+ };
71
+
72
+ declare function isRgbChannel(value: unknown): value is number;
73
+ declare function toRgbChannel(value: number | undefined | null): number;
74
+ declare function isAlphaChannel(value: unknown): value is number;
75
+ declare function toAlphaChannel(value: number | undefined | null): number;
76
+ declare function isColorChannels(value: unknown): value is ColorChannels;
77
+ /**
78
+ * Formats the input into a readonly object of color channels.
79
+ *
80
+ * It clamps the values to the valid range and sets the alpha channel to 1 if not provided.
81
+ * If the passed `isTransformed` isn't already `true`, it will set it to `true` if any of the values were clamped.
82
+ * If some channels are missing, it will return the fallback color.
83
+ */
84
+ declare function toColorChannels(value: ColorChannels): Required<ColorChannels>;
85
+ declare function toColorChannels(r: number, g: number, b: number, a?: number | null, isTransformed?: boolean, isFallback?: boolean): Required<ColorChannels>;
86
+ declare const fallbackColor: Required<ColorChannels>;
87
+
88
+ /** Returns true if the value is any format of supported color. */
89
+ declare function isColor(value: unknown): value is ColorValue;
90
+ /** Returns the color type of the value, or undefined if it's not a color. */
91
+ declare function type(value: unknown): ColorType | undefined;
92
+ /** Tries to parse the value as a color. If it fails, returns the fallback color. */
93
+ declare function parseColor(value: unknown): ColorChannels;
94
+
95
+ /**
96
+ * Whether the input is a valid HEX color. With or without the alpha channel, and with single or double digits.
97
+ *
98
+ * It may or may not start with a hash character, which will be ignored.
99
+ */
100
+ declare function isHex(value: unknown): value is Hex;
101
+ /**
102
+ * Parses a hex string into an object of color channels.
103
+ *
104
+ * The input must already be a valid HEX color, otherwise the result will be unexpected.
105
+ */
106
+ declare function parseHex(value: Hex): ColorChannels;
107
+ /**
108
+ * Returns the corresponding hex string of a color channels object.
109
+ *
110
+ * If the alpha channel is 1, it will be omitted.
111
+ */
112
+ declare function toHex(channels: ColorChannels): Hex;
113
+
114
+ /**
115
+ * A map of named colors and their HEX values.
116
+ *
117
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/named-color
118
+ */
119
+ declare const namedColorsMap: Readonly<{
120
+ aliceblue: "#f0f8ffff";
121
+ antiquewhite: "#faebd7ff";
122
+ aqua: "#00ffffff";
123
+ aquamarine: "#7fffd4ff";
124
+ azure: "#f0ffffff";
125
+ beige: "#f5f5dcff";
126
+ bisque: "#ffe4c4ff";
127
+ black: "#000000ff";
128
+ blanchedalmond: "#ffebcdff";
129
+ blue: "#0000ffff";
130
+ blueviolet: "#8a2be2ff";
131
+ brown: "#a52a2aff";
132
+ burlywood: "#deb887ff";
133
+ cadetblue: "#5f9ea0ff";
134
+ chartreuse: "#7fff00ff";
135
+ chocolate: "#d2691eff";
136
+ coral: "#ff7f50ff";
137
+ cornflowerblue: "#6495edff";
138
+ cornsilk: "#fff8dcff";
139
+ crimson: "#dc143cff";
140
+ cyan: "#00ffffff";
141
+ darkblue: "#00008bff";
142
+ darkcyan: "#008b8bff";
143
+ darkgoldenrod: "#b8860bff";
144
+ darkgray: "#a9a9a9ff";
145
+ darkgreen: "#006400ff";
146
+ darkgrey: "#a9a9a9ff";
147
+ darkkhaki: "#bdb76bff";
148
+ darkmagenta: "#8b008bff";
149
+ darkolivegreen: "#556b2fff";
150
+ darkorange: "#ff8c00ff";
151
+ darkorchid: "#9932ccff";
152
+ darkred: "#8b0000ff";
153
+ darksalmon: "#e9967aff";
154
+ darkseagreen: "#8fbc8fff";
155
+ darkslateblue: "#483d8bff";
156
+ darkslategray: "#2f4f4fff";
157
+ darkslategrey: "#2f4f4fff";
158
+ darkturquoise: "#00ced1ff";
159
+ darkviolet: "#9400d3ff";
160
+ deeppink: "#ff1493ff";
161
+ deepskyblue: "#00bfffff";
162
+ dimgray: "#696969ff";
163
+ dimgrey: "#696969ff";
164
+ dodgerblue: "#1e90ffff";
165
+ firebrick: "#b22222ff";
166
+ floralwhite: "#fffaf0ff";
167
+ forestgreen: "#228b22ff";
168
+ fuchsia: "#ff00ffff";
169
+ gainsboro: "#dcdcdcff";
170
+ ghostwhite: "#f8f8ffff";
171
+ gold: "#ffd700ff";
172
+ goldenrod: "#daa520ff";
173
+ gray: "#808080ff";
174
+ green: "#008000ff";
175
+ greenyellow: "#adff2fff";
176
+ grey: "#808080ff";
177
+ honeydew: "#f0fff0ff";
178
+ hotpink: "#ff69b4ff";
179
+ indianred: "#cd5c5cff";
180
+ indigo: "#4b0082ff";
181
+ ivory: "#fffff0ff";
182
+ khaki: "#f0e68cff";
183
+ lavender: "#e6e6faff";
184
+ lavenderblush: "#fff0f5ff";
185
+ lawngreen: "#7cfc00ff";
186
+ lemonchiffon: "#fffacdff";
187
+ lightblue: "#add8e6ff";
188
+ lightcoral: "#f08080ff";
189
+ lightcyan: "#e0ffffff";
190
+ lightgoldenrodyellow: "#fafad2ff";
191
+ lightgray: "#d3d3d3ff";
192
+ lightgreen: "#90ee90ff";
193
+ lightgrey: "#d3d3d3ff";
194
+ lightpink: "#ffb6c1ff";
195
+ lightsalmon: "#ffa07aff";
196
+ lightseagreen: "#20b2aaff";
197
+ lightskyblue: "#87cefaff";
198
+ lightslategray: "#778899ff";
199
+ lightslategrey: "#778899ff";
200
+ lightsteelblue: "#b0c4deff";
201
+ lightyellow: "#ffffe0ff";
202
+ lime: "#00ff00ff";
203
+ limegreen: "#32cd32ff";
204
+ linen: "#faf0e6ff";
205
+ magenta: "#ff00ffff";
206
+ maroon: "#800000ff";
207
+ mediumaquamarine: "#66cdaaff";
208
+ mediumblue: "#0000cdff";
209
+ mediumorchid: "#ba55d3ff";
210
+ mediumpurple: "#9370dbff";
211
+ mediumseagreen: "#3cb371ff";
212
+ mediumslateblue: "#7b68eeff";
213
+ mediumspringgreen: "#00fa9aff";
214
+ mediumturquoise: "#48d1ccff";
215
+ mediumvioletred: "#c71585ff";
216
+ midnightblue: "#191970ff";
217
+ mintcream: "#f5fffaff";
218
+ mistyrose: "#ffe4e1ff";
219
+ moccasin: "#ffe4b5ff";
220
+ navajowhite: "#ffdeadff";
221
+ navy: "#000080ff";
222
+ oldlace: "#fdf5e6ff";
223
+ olive: "#808000ff";
224
+ olivedrab: "#6b8e23ff";
225
+ orange: "#ffa500ff";
226
+ orangered: "#ff4500ff";
227
+ orchid: "#da70d6ff";
228
+ palegoldenrod: "#eee8aaff";
229
+ palegreen: "#98fb98ff";
230
+ paleturquoise: "#afeeeeff";
231
+ palevioletred: "#db7093ff";
232
+ papayawhip: "#ffefd5ff";
233
+ peachpuff: "#ffdab9ff";
234
+ peru: "#cd853fff";
235
+ pink: "#ffc0cbff";
236
+ plum: "#dda0ddff";
237
+ powderblue: "#b0e0e6ff";
238
+ purple: "#800080ff";
239
+ rebeccapurple: "#663399ff";
240
+ red: "#ff0000ff";
241
+ rosybrown: "#bc8f8fff";
242
+ royalblue: "#4169e1ff";
243
+ saddlebrown: "#8b4513ff";
244
+ salmon: "#fa8072ff";
245
+ sandybrown: "#f4a460ff";
246
+ seagreen: "#2e8b57ff";
247
+ seashell: "#fff5eeff";
248
+ sienna: "#a0522dff";
249
+ silver: "#c0c0c0ff";
250
+ skyblue: "#87ceebff";
251
+ slateblue: "#6a5acdff";
252
+ slategray: "#708090ff";
253
+ slategrey: "#708090ff";
254
+ snow: "#fffafaff";
255
+ springgreen: "#00ff7fff";
256
+ steelblue: "#4682b4ff";
257
+ tan: "#d2b48cff";
258
+ teal: "#008080ff";
259
+ thistle: "#d8bfd8ff";
260
+ tomato: "#ff6347ff";
261
+ transparent: "#00000000";
262
+ turquoise: "#40e0d0ff";
263
+ violet: "#ee82eeff";
264
+ wheat: "#f5deb3ff";
265
+ white: "#ffffffff";
266
+ whitesmoke: "#f5f5f5ff";
267
+ yellow: "#ffff00ff";
268
+ yellowgreen: "#9acd32ff";
269
+ }>;
270
+ /**
271
+ * Whether the input is a valid named color.
272
+ *
273
+ * The check is case-sensitive.
274
+ */
275
+ declare function isNamedColor(value: unknown): value is NamedColor;
276
+ /**
277
+ * Returns the color channels from a named color. Must be a valid named color, already lowercased.
278
+ *
279
+ * @internal
280
+ */
281
+ declare function namedColorChannels(name: NamedColor): ColorChannels;
282
+ /**
283
+ * Returns the color channels from a named color.
284
+ */
285
+ declare function parseNamedColor(name: MaybeNamedColor): ColorChannels;
286
+ /**
287
+ * Returns the corresponding HEX value of a named color.
288
+ */
289
+ declare function namedColorToHex(name: NamedColor): string;
290
+ declare function namedColorToHex(name: MaybeNamedColor): string | undefined;
291
+ /** Returns the closest named color to the passed color channels. */
292
+ declare function closestNamedColor(channels: ColorChannels): NamedColor;
293
+ /**
294
+ * Returns all the aliases of a named color.
295
+ */
296
+ declare function namedColorAliases(name: NamedColor): readonly NamedColor[];
297
+ /**
298
+ * Returns a boolean indicating whether two named colors are aliases.
299
+ */
300
+ declare function isAliasToNamedColor(name: NamedColor, alias: NamedColor): boolean;
301
+
302
+ /**
303
+ * Whether the input is a valid RGB color.
304
+ */
305
+ declare function isRgb(value: unknown): value is Rgb;
306
+ /**
307
+ * Whether the input could be a valid RGB color.
308
+ * As in, it checks if the input is an array of numbers without validating the values range.
309
+ */
310
+ declare function couldBeRgb(value: unknown): value is Rgb;
311
+ /**
312
+ * Parses a RGB tuple into an object of color channels.
313
+ *
314
+ * The input must already be a valid RGB tuple, otherwise the result will be unexpected.
315
+ */
316
+ declare function parseRgb(value: Rgb): ColorChannels;
317
+ /**
318
+ * Returns the corresponding RGB tuple of a color channels object.
319
+ */
320
+ declare function toRgb(channels: ColorChannels): Rgb;
321
+
322
+ /**
323
+ * Used to privately store the cached channels of a color.
324
+ */
325
+ declare const channels: unique symbol;
326
+ /**
327
+ * Used to privately store the cached data of a color.
328
+ */
329
+ declare const cache: unique symbol;
330
+
331
+ declare class Color {
332
+ protected [channels]: Required<Writable<ColorChannels>>;
333
+ protected [cache]: Map<string | Function, any>;
334
+ constructor(value: ColorChannels);
335
+ static from(value: ColorValue): Color;
336
+ static from(red: number, green: number, blue: number, alpha?: number): Color;
337
+ static fromChannels(channels: ColorChannels): Color;
338
+ static fromRgb(rgb: Rgb): Color;
339
+ static fromHex(hex: string): Color;
340
+ static fromName(name: MaybeNamedColor): Color;
341
+ /**
342
+ * Returns the color type of the passed value, or `undefined` if it's not a color.
343
+ *
344
+ * It is slightly stricter than the logic used to parse colors.
345
+ * It would return false for an array of channels which values are not within the expected range, where `parseColor` would return a color with the invalid values clamped.
346
+ */
347
+ static type: typeof type;
348
+ /** Returns a boolean indicating whether the passed value is a color. */
349
+ static isColor: typeof isColor;
350
+ /** @alias Color#isColor */
351
+ static is: typeof isColor;
352
+ /** Returns a boolean indicating whether the passed value is a HEX color string. */
353
+ static isHex: typeof isHex;
354
+ /** Returns a boolean indicating whether the passed value is a named color. */
355
+ static isNamedColor: typeof isNamedColor;
356
+ /** Returns a boolean indicating whether the passed value is a color channel object. */
357
+ static isColorChannels: typeof isColorChannels;
358
+ /** Returns a boolean indicating whether the passed value is a RGB color tuple. */
359
+ static isRgb: typeof isRgb;
360
+ /** Returns all the aliases of a named color, including the name itself. */
361
+ static namedColorAliases: typeof namedColorAliases;
362
+ /** Returns a boolean whether two named colors are aliases, meaning they have the same HEX value. */
363
+ static isAliasToNamedColor: typeof isAliasToNamedColor;
364
+ /**
365
+ * Returns a new `Color` instance with the same channels as the current one.
366
+ * If you want the clone to have different channels, use the `with` method.
367
+ */
368
+ clone(): Color;
369
+ /** Returns a new `Color` instance with the passed channels overriding the current ones. */
370
+ with(value: Partial<Pick<ColorChannels, "r" | "g" | "b" | "a">>): Color;
371
+ /** Returns a new `Color` instance with the specified red channel. */
372
+ withRed(value: number): Color;
373
+ /** Returns a new `Color` instance with the specified green channel. */
374
+ withGreen(value: number): Color;
375
+ /** Returns a new `Color` instance with the specified blue channel. */
376
+ withBlue(value: number): Color;
377
+ /** Returns a new `Color` instance with the specified alpha channel. */
378
+ withAlpha(value: number): Color;
379
+ private updated;
380
+ set(channel: "r" | "g" | "b" | "a", value: number): this;
381
+ /** The red channel of the color. */
382
+ get red(): number;
383
+ /** @see Color#red */
384
+ get r(): number;
385
+ set red(value: number);
386
+ setRed(value: number): this;
387
+ /** The green channel of the color. */
388
+ get green(): number;
389
+ /** @see Color#green */
390
+ get g(): number;
391
+ set green(value: number);
392
+ setGreen(value: number): this;
393
+ /** The blue channel of the color. */
394
+ get blue(): number;
395
+ /** @see Color#blue */
396
+ get b(): number;
397
+ set blue(value: number);
398
+ setBlue(value: number): this;
399
+ /** The alpha channel of the color. */
400
+ get alpha(): number;
401
+ /** @see Color#alpha */
402
+ get a(): number;
403
+ set alpha(value: number);
404
+ setAlpha(value: number): this;
405
+ /**
406
+ * Whether the color is the fallback color, which is used when the input is invalid.
407
+ * As soon as a color channel is updated, this will always be `false`.
408
+ */
409
+ get isFallback(): boolean;
410
+ /**
411
+ * Whether any of the channels have been transformed by the color parser.
412
+ * As soon as a color channel is updated, this will always be `false`.
413
+ */
414
+ get isTransformed(): boolean;
415
+ /** Helper to cache data until the channels are updated. */
416
+ private memoize;
417
+ /** Checks if the color is fully opaque. */
418
+ get isOpaque(): boolean;
419
+ /** Checks if the color is fully transparent. */
420
+ get isTransparent(): boolean;
421
+ /** Checks if the color is at least partially transparent. */
422
+ get isTranslucent(): boolean;
423
+ /**
424
+ * Returns the closest named color. If aliases exist, which one is returned is not guaranteed.
425
+ * In some cases, calling `namedColorAliases()` on the result might help achieve the desired result.
426
+ */
427
+ get closestNamedColor(): NamedColor;
428
+ /** The relative brightness of the color. */
429
+ get brightness(): number;
430
+ /** Whether the color is considered bright. */
431
+ get isBright(): boolean;
432
+ /** Whether the color is considered dark. */
433
+ get isDark(): boolean;
434
+ /** Whether the color is brighter than the passed threshold or color. */
435
+ isBrighterThan(threshold: Color | number): boolean;
436
+ /** Whether the color is darker than the passed threshold or color. */
437
+ isDarkerThan(threshold: Color | number): boolean;
438
+ /** Returns the relative luminance of the color. */
439
+ get luminance(): number;
440
+ /** Returns the contrast ratio between this color and another. */
441
+ contrast(color: ColorValue): number;
442
+ /** Returns the distance between this color and another. If `alpha` is `true`, the alpha channel is included in the calculation. */
443
+ distance(color: ColorValue, alpha?: boolean): number;
444
+ /** Returns a new color with the grayscale equivalent of the current color, preserving the alpha channel. */
445
+ toGrayscale(): Color;
446
+ toHex(): string;
447
+ toRgb(): Rgb;
448
+ toChannels(): ColorChannels;
449
+ toString(): string;
450
+ valueOf(): string;
451
+ [Symbol.toPrimitive](): string;
452
+ toJSON(): string;
453
+ }
454
+
455
+ export { type ColorType as A, type ColorValue as B, type ColorChannels as C, type Hex as H, type MaybeNamedColor as M, type NamedColor as N, type Rgb as R, isColorChannels as a, isRgbChannel as b, toColorChannels as c, toRgbChannel as d, isColor as e, fallbackColor as f, type as g, isHex as h, isAlphaChannel as i, parseHex as j, toHex as k, closestNamedColor as l, isAliasToNamedColor as m, isNamedColor as n, namedColorAliases as o, parseColor as p, namedColorChannels as q, namedColorsMap as r, namedColorToHex as s, toAlphaChannel as t, parseNamedColor as u, couldBeRgb as v, isRgb as w, parseRgb as x, toRgb as y, Color as z };
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var D=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ie=(e,r)=>{for(var o in r)D(e,o,{get:r[o],enumerable:!0})},le=(e,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let f of ae(r))!se.call(e,f)&&f!==o&&D(e,f,{get:()=>r[f],enumerable:!(n=fe(r,f))||n.enumerable});return e};var me=e=>le(D({},"__esModule",{value:!0}),e);var he={};ie(he,{Color:()=>b});module.exports=me(he);var te=require("@auaust/primitive-kit");var a=require("@auaust/primitive-kit");function g(e){return a.N.is(e)&&a.N.isBetween(e,0,255)}function s(e){return a.N.clamp(a.N.round(e),0,255)}function B(e){return a.N.is(e)&&a.N.isBetween(e,0,1)}function y(e){return a.N.is(e)?a.N.clamp(e,0,1):1}function x(e){return a.O.is(e,!1)&&g(e.r)&&g(e.g)&&g(e.b)&&B(e.a??1)}function i(e,r,o,n,f,m){a.O.is(e,!1)&&({r:e,g:r,b:o,a:n,isTransformed:f,isFallback:m}=e);let h=s(e),V=s(r),L=s(o);if(isNaN(h)||isNaN(V)||isNaN(L))return l;let v=y(n);return a.O.freeze({r:h,g:V,b:L,a:v,isTransformed:!!(f||h!==e||V!==r||L!==o||v!==(n??1)),isFallback:!!m})}var l=i(0,0,0,1,!1,!0);var C=require("@auaust/primitive-kit");var ue=/^[0-9a-f]+$/i;function w(e){if(e=C.S.is(e)&&(e.startsWith("#")?e.slice(1):e),!C.S.isStrict(e))return!1;switch(e.length){case 3:case 4:case 6:case 8:return ue.test(e);default:return!1}}function c(e){e=e.startsWith("#")?e.slice(1):e;let r=e.length<6,o=r?e.length===4:e.length===8,n=parseInt(r?e[0].repeat(2):e.slice(0,2),16),f=parseInt(r?e[1].repeat(2):e.slice(2,4),16),m=parseInt(r?e[2].repeat(2):e.slice(4,6),16),h=o?parseInt(r?e[3].repeat(2):e.slice(6,8),16)/255:1;return i(n,f,m,h)}function F(e){let{r,g:o,b:n,a:f}=e;return"#"+((1<<24)+(s(r)<<16)+(s(o)<<8)+s(n)).toString(16).substring(1)+(C.N.is(f)&&f<1?C.N.round(C.N.max(0,f)*255).toString(16).padStart(2,"0"):"")}var k=require("@auaust/primitive-kit");var q=k.O.freeze({aliceblue:"#f0f8ffff",antiquewhite:"#faebd7ff",aqua:"#00ffffff",aquamarine:"#7fffd4ff",azure:"#f0ffffff",beige:"#f5f5dcff",bisque:"#ffe4c4ff",black:"#000000ff",blanchedalmond:"#ffebcdff",blue:"#0000ffff",blueviolet:"#8a2be2ff",brown:"#a52a2aff",burlywood:"#deb887ff",cadetblue:"#5f9ea0ff",chartreuse:"#7fff00ff",chocolate:"#d2691eff",coral:"#ff7f50ff",cornflowerblue:"#6495edff",cornsilk:"#fff8dcff",crimson:"#dc143cff",cyan:"#00ffffff",darkblue:"#00008bff",darkcyan:"#008b8bff",darkgoldenrod:"#b8860bff",darkgray:"#a9a9a9ff",darkgreen:"#006400ff",darkgrey:"#a9a9a9ff",darkkhaki:"#bdb76bff",darkmagenta:"#8b008bff",darkolivegreen:"#556b2fff",darkorange:"#ff8c00ff",darkorchid:"#9932ccff",darkred:"#8b0000ff",darksalmon:"#e9967aff",darkseagreen:"#8fbc8fff",darkslateblue:"#483d8bff",darkslategray:"#2f4f4fff",darkslategrey:"#2f4f4fff",darkturquoise:"#00ced1ff",darkviolet:"#9400d3ff",deeppink:"#ff1493ff",deepskyblue:"#00bfffff",dimgray:"#696969ff",dimgrey:"#696969ff",dodgerblue:"#1e90ffff",firebrick:"#b22222ff",floralwhite:"#fffaf0ff",forestgreen:"#228b22ff",fuchsia:"#ff00ffff",gainsboro:"#dcdcdcff",ghostwhite:"#f8f8ffff",gold:"#ffd700ff",goldenrod:"#daa520ff",gray:"#808080ff",green:"#008000ff",greenyellow:"#adff2fff",grey:"#808080ff",honeydew:"#f0fff0ff",hotpink:"#ff69b4ff",indianred:"#cd5c5cff",indigo:"#4b0082ff",ivory:"#fffff0ff",khaki:"#f0e68cff",lavender:"#e6e6faff",lavenderblush:"#fff0f5ff",lawngreen:"#7cfc00ff",lemonchiffon:"#fffacdff",lightblue:"#add8e6ff",lightcoral:"#f08080ff",lightcyan:"#e0ffffff",lightgoldenrodyellow:"#fafad2ff",lightgray:"#d3d3d3ff",lightgreen:"#90ee90ff",lightgrey:"#d3d3d3ff",lightpink:"#ffb6c1ff",lightsalmon:"#ffa07aff",lightseagreen:"#20b2aaff",lightskyblue:"#87cefaff",lightslategray:"#778899ff",lightslategrey:"#778899ff",lightsteelblue:"#b0c4deff",lightyellow:"#ffffe0ff",lime:"#00ff00ff",limegreen:"#32cd32ff",linen:"#faf0e6ff",magenta:"#ff00ffff",maroon:"#800000ff",mediumaquamarine:"#66cdaaff",mediumblue:"#0000cdff",mediumorchid:"#ba55d3ff",mediumpurple:"#9370dbff",mediumseagreen:"#3cb371ff",mediumslateblue:"#7b68eeff",mediumspringgreen:"#00fa9aff",mediumturquoise:"#48d1ccff",mediumvioletred:"#c71585ff",midnightblue:"#191970ff",mintcream:"#f5fffaff",mistyrose:"#ffe4e1ff",moccasin:"#ffe4b5ff",navajowhite:"#ffdeadff",navy:"#000080ff",oldlace:"#fdf5e6ff",olive:"#808000ff",olivedrab:"#6b8e23ff",orange:"#ffa500ff",orangered:"#ff4500ff",orchid:"#da70d6ff",palegoldenrod:"#eee8aaff",palegreen:"#98fb98ff",paleturquoise:"#afeeeeff",palevioletred:"#db7093ff",papayawhip:"#ffefd5ff",peachpuff:"#ffdab9ff",peru:"#cd853fff",pink:"#ffc0cbff",plum:"#dda0ddff",powderblue:"#b0e0e6ff",purple:"#800080ff",rebeccapurple:"#663399ff",red:"#ff0000ff",rosybrown:"#bc8f8fff",royalblue:"#4169e1ff",saddlebrown:"#8b4513ff",salmon:"#fa8072ff",sandybrown:"#f4a460ff",seagreen:"#2e8b57ff",seashell:"#fff5eeff",sienna:"#a0522dff",silver:"#c0c0c0ff",skyblue:"#87ceebff",slateblue:"#6a5acdff",slategray:"#708090ff",slategrey:"#708090ff",snow:"#fffafaff",springgreen:"#00ff7fff",steelblue:"#4682b4ff",tan:"#d2b48cff",teal:"#008080ff",thistle:"#d8bfd8ff",tomato:"#ff6347ff",transparent:"#00000000",turquoise:"#40e0d0ff",violet:"#ee82eeff",wheat:"#f5deb3ff",white:"#ffffffff",whitesmoke:"#f5f5f5ff",yellow:"#ffff00ff",yellowgreen:"#9acd32ff"}),ee=new Set(k.O.keys(q)),de={},I={};function u(e){return k.S.is(e)&&ee.has(e.toLowerCase())}function P(e){return de[e]??=c(W(e))}function R(e){return u(e)?P(e.toLowerCase()):l}function W(e){return q[e.toLowerCase()]||void 0}function j(e){let r,o=1/0;for(let n of ee){let f=P(n),m=T(f,e,f.a===1);m<o&&(r=n,o=m)}return r}function z(e){if(e=e.toLowerCase(),!u(e))return[];if(I[e])return I[e];let r=[],o=W(e);for(let[n,f]of k.O.entries(q))f===o&&r.push(n);return I[e]=Object.freeze(r)}function J(e,r){return z(e).includes(r.toLowerCase())}var d=require("@auaust/primitive-kit");function H(e){return d.A.is(e)&&d.N.isBetween(e.length,3,4)&&e.every((r,o)=>o===3?B(r):g(r))}function K(e){return d.A.is(e)&&d.N.isBetween(e.length,3,4)&&e.every(d.N.is)}function A(e){return d.A.is(e)?i(e[0],e[1],e[2],e[3]):l}function $(e){let{r,g:o,b:n,a:f}=e;return Array.from([r,o,n,f],(m,h)=>h===3?y(m):s(m))}var t=Symbol("Color.channels"),N=Symbol("Color.cache");function S(e){return G(e)!==void 0}function G(e){if(e){if(e instanceof b)return"color";if(u(e))return"named";if(w(e))return"hex";if(H(e))return"rgb";if(x(e))return"channels"}}function E(e){return e?e instanceof b?e[t]:x(e)?e:u(e)?R(e):w(e)?c(e):K(e)?A(e):l:l}function T(e,r,o=!1){return Math.sqrt(Math.pow(e.r-r.r,2)+Math.pow(e.g-r.g,2)+Math.pow(e.b-r.b,2)+(o?Math.pow((e.a??1)-(r.a??1),2):0))}var re=require("@auaust/primitive-kit");function oe(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function ne(e){return e<=.04045/12.92?e*12.92:1.055*Math.pow(e,1/2.4)-.055}function p(e){let{r,g:o,b:n}=e;return[r,o,n]=[r,o,n].map(f=>oe(f/255)),r*.2126+o*.7152+n*.0722}function M(e){let r=p(e);return r<=216/24389?r*(24389/27):(Math.pow(r,1/3)*116-16)/100}function Q(e,r=.5){return M(e)>r}function U(e,r=.5){return M(e)<=r}function X(e,r){let[o,n]=re.N.minMax(p(e),p(r));return(n+.05)/(o+.05)}function Y(e){let r=ne(p(e))*255;return i(r,r,r,e.a)}function O(e){return e.a===1||e.a==null}function Z(e){return e.a===0}function _(e){return!O(e)}var b=class e{[t]=void 0;[N]=new Map;constructor(r){this[t]={...i(r)}}static from(r,...o){return te.N.is(r)?new this({r,g:o[0],b:o[1],a:o[2]}):new this(E(r??l))}static fromChannels(r){return new this(r)}static fromRgb(r){return new this(A(r))}static fromHex(r){return new this(c(r))}static fromName(r){return new this(R(r))}static type=G;static isColor=S;static is=S;static isHex=w;static isNamedColor=u;static isColorChannels=x;static isRgb=H;static namedColorAliases=z;static isAliasToNamedColor=J;clone(){return e.fromChannels(this[t])}with(r){return e.fromChannels({...this[t],...r,isFallback:!1,isTransformed:!1})}withRed(r){return this.with({r})}withGreen(r){return this.with({g:r})}withBlue(r){return this.with({b:r})}withAlpha(r){return this.with({a:r})}updated(){return this[N].clear(),this[t].isFallback=!1,this[t].isTransformed=!1,this}set(r,o){return this[t][r]=r==="a"?y(o):s(o),this.updated()}get red(){return this[t].r}get r(){return this[t].r}set red(r){this.setRed(r)}setRed(r){return this.set("r",r)}get green(){return this[t].g}get g(){return this[t].g}set green(r){this.setGreen(r)}setGreen(r){return this.set("g",r)}get blue(){return this[t].b}get b(){return this[t].b}set blue(r){this.setBlue(r)}setBlue(r){return this.set("b",r)}get alpha(){return this[t].a}get a(){return this[t].a}set alpha(r){this.setAlpha(r)}setAlpha(r){return this.set("a",r)}get isFallback(){return this[t].isFallback}get isTransformed(){return this[t].isTransformed}memoize(r,o){let n=o??r;return this[N].has(n)||this[N].set(n,r(this[t])),this[N].get(n)}get isOpaque(){return this.memoize(O)}get isTransparent(){return this.memoize(Z)}get isTranslucent(){return this.memoize(_)}get closestNamedColor(){return this.memoize(j)}get brightness(){return this.memoize(M)}get isBright(){return this.memoize(Q)}get isDark(){return this.memoize(U)}isBrighterThan(r){return this.brightness>(r instanceof e?r.brightness:r)}isDarkerThan(r){return this.brightness<(r instanceof e?r.brightness:r)}get luminance(){return this.memoize(p)}contrast(r){return X(this[t],e.from(r)[t])}distance(r,o=!1){return T(this[t],e.from(r)[t],o)}toGrayscale(){return e.fromChannels(Y(this[t]))}toHex(){return this.memoize(F)}toRgb(){return this.memoize($)}toChannels(){return this.memoize(i)}toString(){return this.toHex()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}toJSON(){return this.toString()}};0&&(module.exports={Color});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/classes/Color.ts","../src/utils/channels.ts","../src/utils/hex.ts","../src/utils/namedColors.ts","../src/utils/rgb.ts","../src/utils/symbols.ts","../src/utils/colors.ts","../src/utils/distance.ts","../src/utils/luminance.ts","../src/utils/opacity.ts"],"sourcesContent":["export { Color } from \"~/classes/Color\";\nexport type {\n ColorChannels,\n ColorType,\n ColorValue,\n Hex,\n MaybeNamedColor,\n NamedColor,\n Rgb,\n} from \"~/types\";\n","import { N } from \"@auaust/primitive-kit\";\nimport type { Writable } from \"type-fest\";\nimport type {\n ColorChannels,\n ColorValue,\n MaybeNamedColor,\n NamedColor,\n Rgb,\n} from \"~\";\nimport {\n brightness,\n closestNamedColor,\n contrast,\n distance,\n fallbackColor,\n grayscale,\n isAliasToNamedColor,\n isBright,\n isColor,\n isColorChannels,\n isDark,\n isHex,\n isNamedColor,\n isOpaque,\n isRgb,\n isTranslucent,\n isTransparent,\n luminance,\n namedColorAliases,\n parseColor,\n parseHex,\n parseNamedColor,\n parseRgb,\n toAlphaChannel,\n toColorChannels,\n toHex,\n toRgb,\n toRgbChannel,\n type,\n} from \"~/utils\";\nimport { cache, channels } from \"~/utils/symbols\";\n\nexport class Color {\n protected [channels]: Required<Writable<ColorChannels>> = undefined!;\n protected [cache]: Map<string | Function, any> = new Map();\n\n constructor(value: ColorChannels) {\n this[channels] = { ...toColorChannels(value) };\n }\n\n static from(value: ColorValue): Color;\n static from(red: number, green: number, blue: number, alpha?: number): Color;\n static from(value: ColorValue | number, ...rest: number[]): Color {\n if (N.is(value)) {\n return new this({ r: value, g: rest[0], b: rest[1], a: rest[2] });\n }\n\n return new this(parseColor(value ?? fallbackColor));\n }\n\n static fromChannels(channels: ColorChannels): Color {\n return new this(channels);\n }\n\n static fromRgb(rgb: Rgb): Color {\n return new this(parseRgb(rgb));\n }\n\n static fromHex(hex: string): Color {\n return new this(parseHex(hex));\n }\n\n static fromName(name: MaybeNamedColor): Color {\n return new this(parseNamedColor(name));\n }\n\n /**\n * Returns the color type of the passed value, or `undefined` if it's not a color.\n *\n * It is slightly stricter than the logic used to parse colors.\n * It would return false for an array of channels which values are not within the expected range, where `parseColor` would return a color with the invalid values clamped.\n */\n static type = type;\n\n /** Returns a boolean indicating whether the passed value is a color. */\n static isColor = isColor;\n\n /** @alias Color#isColor */\n static is = isColor;\n\n /** Returns a boolean indicating whether the passed value is a HEX color string. */\n static isHex = isHex;\n\n /** Returns a boolean indicating whether the passed value is a named color. */\n static isNamedColor = isNamedColor;\n\n /** Returns a boolean indicating whether the passed value is a color channel object. */\n static isColorChannels = isColorChannels;\n\n /** Returns a boolean indicating whether the passed value is a RGB color tuple. */\n static isRgb = isRgb;\n\n /** Returns all the aliases of a named color, including the name itself. */\n static namedColorAliases = namedColorAliases;\n\n /** Returns a boolean whether two named colors are aliases, meaning they have the same HEX value. */\n static isAliasToNamedColor = isAliasToNamedColor;\n\n /**\n * Returns a new `Color` instance with the same channels as the current one.\n * If you want the clone to have different channels, use the `with` method.\n */\n clone(): Color {\n return Color.fromChannels(this[channels]);\n }\n\n /** Returns a new `Color` instance with the passed channels overriding the current ones. */\n with(value: Partial<Pick<ColorChannels, \"r\" | \"g\" | \"b\" | \"a\">>): Color {\n return Color.fromChannels({\n ...this[channels],\n ...value,\n isFallback: false,\n isTransformed: false,\n });\n }\n\n /** Returns a new `Color` instance with the specified red channel. */\n withRed(value: number): Color {\n return this.with({ r: value });\n }\n\n /** Returns a new `Color` instance with the specified green channel. */\n withGreen(value: number): Color {\n return this.with({ g: value });\n }\n\n /** Returns a new `Color` instance with the specified blue channel. */\n withBlue(value: number): Color {\n return this.with({ b: value });\n }\n\n /** Returns a new `Color` instance with the specified alpha channel. */\n withAlpha(value: number): Color {\n return this.with({ a: value });\n }\n\n private updated(): this {\n this[cache].clear();\n this[channels].isFallback = false; // once updated, it's no longer a fallback\n this[channels].isTransformed = false;\n return this;\n }\n\n set(channel: \"r\" | \"g\" | \"b\" | \"a\", value: number): this {\n this[channels][channel] =\n channel === \"a\" ? toAlphaChannel(value) : toRgbChannel(value);\n return this.updated();\n }\n\n /** The red channel of the color. */\n get red(): number {\n return this[channels].r;\n }\n\n /** @see Color#red */\n get r(): number {\n return this[channels].r;\n }\n\n set red(value: number) {\n this.setRed(value);\n }\n\n setRed(value: number): this {\n return this.set(\"r\", value);\n }\n\n /** The green channel of the color. */\n get green(): number {\n return this[channels].g;\n }\n\n /** @see Color#green */\n get g(): number {\n return this[channels].g;\n }\n\n set green(value: number) {\n this.setGreen(value);\n }\n\n setGreen(value: number): this {\n return this.set(\"g\", value);\n }\n\n /** The blue channel of the color. */\n get blue(): number {\n return this[channels].b;\n }\n\n /** @see Color#blue */\n get b(): number {\n return this[channels].b;\n }\n\n set blue(value: number) {\n this.setBlue(value);\n }\n\n setBlue(value: number): this {\n return this.set(\"b\", value);\n }\n\n /** The alpha channel of the color. */\n get alpha(): number {\n return this[channels].a;\n }\n\n /** @see Color#alpha */\n get a(): number {\n return this[channels].a;\n }\n\n set alpha(value: number) {\n this.setAlpha(value);\n }\n\n setAlpha(value: number): this {\n return this.set(\"a\", value);\n }\n\n /**\n * Whether the color is the fallback color, which is used when the input is invalid.\n * As soon as a color channel is updated, this will always be `false`.\n */\n get isFallback(): boolean {\n return this[channels].isFallback;\n }\n\n /**\n * Whether any of the channels have been transformed by the color parser.\n * As soon as a color channel is updated, this will always be `false`.\n */\n get isTransformed(): boolean {\n return this[channels].isTransformed;\n }\n\n /** Helper to cache data until the channels are updated. */\n private memoize<T>(getter: (channels: ColorChannels) => T, key?: string): T {\n // If no key is passed, we use the getter function as the key\n // This means no key is required when the getter is a named function, while allowing to use anonymous functions within getters as well by passing a key\n const cacheKey = key ?? getter;\n\n if (!this[cache].has(cacheKey)) {\n this[cache].set(cacheKey, getter(this[channels]));\n }\n\n return this[cache].get(cacheKey);\n }\n\n /** Checks if the color is fully opaque. */\n get isOpaque(): boolean {\n return this.memoize(isOpaque);\n }\n\n /** Checks if the color is fully transparent. */\n get isTransparent(): boolean {\n return this.memoize(isTransparent);\n }\n\n /** Checks if the color is at least partially transparent. */\n get isTranslucent(): boolean {\n return this.memoize(isTranslucent);\n }\n\n /**\n * Returns the closest named color. If aliases exist, which one is returned is not guaranteed.\n * In some cases, calling `namedColorAliases()` on the result might help achieve the desired result.\n */\n get closestNamedColor(): NamedColor {\n return this.memoize(closestNamedColor);\n }\n\n /** The relative brightness of the color. */\n get brightness(): number {\n return this.memoize(brightness);\n }\n\n /** Whether the color is considered bright. */\n get isBright(): boolean {\n return this.memoize(isBright);\n }\n\n /** Whether the color is considered dark. */\n get isDark(): boolean {\n return this.memoize(isDark);\n }\n\n /** Whether the color is brighter than the passed threshold or color. */\n isBrighterThan(threshold: Color | number): boolean {\n return (\n this.brightness >\n (threshold instanceof Color ? threshold.brightness : threshold)\n );\n }\n\n /** Whether the color is darker than the passed threshold or color. */\n isDarkerThan(threshold: Color | number): boolean {\n return (\n this.brightness <\n (threshold instanceof Color ? threshold.brightness : threshold)\n );\n }\n\n /** Returns the relative luminance of the color. */\n get luminance(): number {\n return this.memoize(luminance);\n }\n\n /** Returns the contrast ratio between this color and another. */\n contrast(color: ColorValue): number {\n return contrast(this[channels], Color.from(color)[channels]);\n }\n\n /** Returns the distance between this color and another. If `alpha` is `true`, the alpha channel is included in the calculation. */\n distance(color: ColorValue, alpha = false): number {\n return distance(this[channels], Color.from(color)[channels], alpha);\n }\n\n /** Returns a new color with the grayscale equivalent of the current color, preserving the alpha channel. */\n toGrayscale(): Color {\n return Color.fromChannels(grayscale(this[channels]));\n }\n\n toHex(): string {\n return this.memoize(toHex);\n }\n\n toRgb(): Rgb {\n return this.memoize(toRgb);\n }\n\n toChannels(): ColorChannels {\n return this.memoize(toColorChannels); // can't return `this[channels]` directly as it's writable, and could cause unexpected behavior\n }\n\n toString(): string {\n return this.toHex();\n }\n\n valueOf(): string {\n return this.toString();\n }\n\n [Symbol.toPrimitive](): string {\n return this.toString();\n }\n\n toJSON(): string {\n return this.toString();\n }\n}\n","import { N, O } from \"@auaust/primitive-kit\";\nimport type { ColorChannels } from \"~/types\";\n\nexport function isRgbChannel(value: unknown): value is number {\n return N.is(value) && N.isBetween(value, 0, 255);\n}\n\nexport function toRgbChannel(value: number | undefined | null): number {\n return N.clamp(N.round(value), 0, 255);\n}\n\nexport function isAlphaChannel(value: unknown): value is number {\n return N.is(value) && N.isBetween(value, 0, 1);\n}\n\nexport function toAlphaChannel(value: number | undefined | null): number {\n return N.is(value) ? N.clamp(value, 0, 1) : 1;\n}\n\nexport function isColorChannels(value: unknown): value is ColorChannels {\n return (\n O.is(value, false) &&\n isRgbChannel(value.r) &&\n isRgbChannel(value.g) &&\n isRgbChannel(value.b) &&\n isAlphaChannel(value.a ?? 1)\n );\n}\n\n/**\n * Formats the input into a readonly object of color channels.\n *\n * It clamps the values to the valid range and sets the alpha channel to 1 if not provided.\n * If the passed `isTransformed` isn't already `true`, it will set it to `true` if any of the values were clamped.\n * If some channels are missing, it will return the fallback color.\n */\nexport function toColorChannels(value: ColorChannels): Required<ColorChannels>;\nexport function toColorChannels(\n r: number,\n g: number,\n b: number,\n a?: number | null,\n isTransformed?: boolean,\n isFallback?: boolean\n): Required<ColorChannels>;\nexport function toColorChannels(\n r: number | ColorChannels,\n g?: number,\n b?: number,\n a?: number | null,\n isTransformed?: boolean,\n isFallback?: boolean\n): Required<ColorChannels> {\n if (O.is(r, false)) {\n ({ r, g, b, a, isTransformed, isFallback } = r);\n }\n\n const finalR = toRgbChannel(r);\n const finalG = toRgbChannel(g);\n const finalB = toRgbChannel(b);\n\n if (isNaN(finalR) || isNaN(finalG) || isNaN(finalB)) {\n return fallbackColor;\n }\n\n const finalA = toAlphaChannel(a);\n\n return O.freeze({\n r: finalR,\n g: finalG,\n b: finalB,\n a: finalA,\n isTransformed: !!(\n isTransformed ||\n finalR !== r ||\n finalG !== g ||\n finalB !== b ||\n finalA !== (a ?? 1)\n ),\n isFallback: !!isFallback,\n });\n}\n\nexport const fallbackColor = toColorChannels(0, 0, 0, 1, false, true);\n","import { N, S } from \"@auaust/primitive-kit\";\nimport type { ColorChannels, Hex } from \"~/types\";\nimport { toColorChannels, toRgbChannel } from \"./channels\";\n\nconst hexadecimalRegex = /^[0-9a-f]+$/i;\n\n/**\n * Whether the input is a valid HEX color. With or without the alpha channel, and with single or double digits.\n *\n * It may or may not start with a hash character, which will be ignored.\n */\nexport function isHex(value: unknown): value is Hex {\n value = S.is(value) && (value.startsWith(\"#\") ? value.slice(1) : value);\n\n if (!S.isStrict(value)) {\n return false;\n }\n\n switch (value.length) {\n case 3: // RGB\n case 4: // RGBA\n case 6: // RRGGBB\n case 8: // RRGGBBAA\n return hexadecimalRegex.test(value);\n default:\n return false;\n }\n}\n\n/**\n * Parses a hex string into an object of color channels.\n *\n * The input must already be a valid HEX color, otherwise the result will be unexpected.\n */\nexport function parseHex(value: Hex): ColorChannels {\n value = value.startsWith(\"#\") ? value.slice(1) : value;\n\n const isShort = value.length < 6;\n const hasAlpha = isShort ? value.length === 4 : value.length === 8;\n\n const r = parseInt(isShort ? value[0].repeat(2) : value.slice(0, 2), 16);\n const g = parseInt(isShort ? value[1].repeat(2) : value.slice(2, 4), 16);\n const b = parseInt(isShort ? value[2].repeat(2) : value.slice(4, 6), 16);\n const a = hasAlpha\n ? parseInt(isShort ? value[3].repeat(2) : value.slice(6, 8), 16) / 255\n : 1;\n\n return toColorChannels(r, g, b, a);\n}\n\n/**\n * Returns the corresponding hex string of a color channels object.\n *\n * If the alpha channel is 1, it will be omitted.\n */\nexport function toHex(channels: ColorChannels): Hex {\n const { r, g, b, a } = channels;\n\n return (\n \"#\" +\n (\n (1 << 24) +\n (toRgbChannel(r) << 16) +\n (toRgbChannel(g) << 8) +\n toRgbChannel(b)\n )\n .toString(16)\n .substring(1) +\n (N.is(a) && a < 1\n ? N.round(N.max(0, a) * 255)\n .toString(16)\n .padStart(2, \"0\")\n : \"\")\n );\n}\n","import { O, S } from \"@auaust/primitive-kit\";\nimport type { ColorChannels, MaybeNamedColor, NamedColor } from \"~/types\";\nimport { distance, fallbackColor, parseHex } from \"~/utils\";\n\n/**\n * A map of named colors and their HEX values.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/named-color\n */\nexport const namedColorsMap = O.freeze({\n aliceblue: \"#f0f8ffff\",\n antiquewhite: \"#faebd7ff\",\n aqua: \"#00ffffff\",\n aquamarine: \"#7fffd4ff\",\n azure: \"#f0ffffff\",\n beige: \"#f5f5dcff\",\n bisque: \"#ffe4c4ff\",\n black: \"#000000ff\",\n blanchedalmond: \"#ffebcdff\",\n blue: \"#0000ffff\",\n blueviolet: \"#8a2be2ff\",\n brown: \"#a52a2aff\",\n burlywood: \"#deb887ff\",\n cadetblue: \"#5f9ea0ff\",\n chartreuse: \"#7fff00ff\",\n chocolate: \"#d2691eff\",\n coral: \"#ff7f50ff\",\n cornflowerblue: \"#6495edff\",\n cornsilk: \"#fff8dcff\",\n crimson: \"#dc143cff\",\n cyan: \"#00ffffff\",\n darkblue: \"#00008bff\",\n darkcyan: \"#008b8bff\",\n darkgoldenrod: \"#b8860bff\",\n darkgray: \"#a9a9a9ff\",\n darkgreen: \"#006400ff\",\n darkgrey: \"#a9a9a9ff\",\n darkkhaki: \"#bdb76bff\",\n darkmagenta: \"#8b008bff\",\n darkolivegreen: \"#556b2fff\",\n darkorange: \"#ff8c00ff\",\n darkorchid: \"#9932ccff\",\n darkred: \"#8b0000ff\",\n darksalmon: \"#e9967aff\",\n darkseagreen: \"#8fbc8fff\",\n darkslateblue: \"#483d8bff\",\n darkslategray: \"#2f4f4fff\",\n darkslategrey: \"#2f4f4fff\",\n darkturquoise: \"#00ced1ff\",\n darkviolet: \"#9400d3ff\",\n deeppink: \"#ff1493ff\",\n deepskyblue: \"#00bfffff\",\n dimgray: \"#696969ff\",\n dimgrey: \"#696969ff\",\n dodgerblue: \"#1e90ffff\",\n firebrick: \"#b22222ff\",\n floralwhite: \"#fffaf0ff\",\n forestgreen: \"#228b22ff\",\n fuchsia: \"#ff00ffff\",\n gainsboro: \"#dcdcdcff\",\n ghostwhite: \"#f8f8ffff\",\n gold: \"#ffd700ff\",\n goldenrod: \"#daa520ff\",\n gray: \"#808080ff\",\n green: \"#008000ff\",\n greenyellow: \"#adff2fff\",\n grey: \"#808080ff\",\n honeydew: \"#f0fff0ff\",\n hotpink: \"#ff69b4ff\",\n indianred: \"#cd5c5cff\",\n indigo: \"#4b0082ff\",\n ivory: \"#fffff0ff\",\n khaki: \"#f0e68cff\",\n lavender: \"#e6e6faff\",\n lavenderblush: \"#fff0f5ff\",\n lawngreen: \"#7cfc00ff\",\n lemonchiffon: \"#fffacdff\",\n lightblue: \"#add8e6ff\",\n lightcoral: \"#f08080ff\",\n lightcyan: \"#e0ffffff\",\n lightgoldenrodyellow: \"#fafad2ff\",\n lightgray: \"#d3d3d3ff\",\n lightgreen: \"#90ee90ff\",\n lightgrey: \"#d3d3d3ff\",\n lightpink: \"#ffb6c1ff\",\n lightsalmon: \"#ffa07aff\",\n lightseagreen: \"#20b2aaff\",\n lightskyblue: \"#87cefaff\",\n lightslategray: \"#778899ff\",\n lightslategrey: \"#778899ff\",\n lightsteelblue: \"#b0c4deff\",\n lightyellow: \"#ffffe0ff\",\n lime: \"#00ff00ff\",\n limegreen: \"#32cd32ff\",\n linen: \"#faf0e6ff\",\n magenta: \"#ff00ffff\",\n maroon: \"#800000ff\",\n mediumaquamarine: \"#66cdaaff\",\n mediumblue: \"#0000cdff\",\n mediumorchid: \"#ba55d3ff\",\n mediumpurple: \"#9370dbff\",\n mediumseagreen: \"#3cb371ff\",\n mediumslateblue: \"#7b68eeff\",\n mediumspringgreen: \"#00fa9aff\",\n mediumturquoise: \"#48d1ccff\",\n mediumvioletred: \"#c71585ff\",\n midnightblue: \"#191970ff\",\n mintcream: \"#f5fffaff\",\n mistyrose: \"#ffe4e1ff\",\n moccasin: \"#ffe4b5ff\",\n navajowhite: \"#ffdeadff\",\n navy: \"#000080ff\",\n oldlace: \"#fdf5e6ff\",\n olive: \"#808000ff\",\n olivedrab: \"#6b8e23ff\",\n orange: \"#ffa500ff\",\n orangered: \"#ff4500ff\",\n orchid: \"#da70d6ff\",\n palegoldenrod: \"#eee8aaff\",\n palegreen: \"#98fb98ff\",\n paleturquoise: \"#afeeeeff\",\n palevioletred: \"#db7093ff\",\n papayawhip: \"#ffefd5ff\",\n peachpuff: \"#ffdab9ff\",\n peru: \"#cd853fff\",\n pink: \"#ffc0cbff\",\n plum: \"#dda0ddff\",\n powderblue: \"#b0e0e6ff\",\n purple: \"#800080ff\",\n rebeccapurple: \"#663399ff\",\n red: \"#ff0000ff\",\n rosybrown: \"#bc8f8fff\",\n royalblue: \"#4169e1ff\",\n saddlebrown: \"#8b4513ff\",\n salmon: \"#fa8072ff\",\n sandybrown: \"#f4a460ff\",\n seagreen: \"#2e8b57ff\",\n seashell: \"#fff5eeff\",\n sienna: \"#a0522dff\",\n silver: \"#c0c0c0ff\",\n skyblue: \"#87ceebff\",\n slateblue: \"#6a5acdff\",\n slategray: \"#708090ff\",\n slategrey: \"#708090ff\",\n snow: \"#fffafaff\",\n springgreen: \"#00ff7fff\",\n steelblue: \"#4682b4ff\",\n tan: \"#d2b48cff\",\n teal: \"#008080ff\",\n thistle: \"#d8bfd8ff\",\n tomato: \"#ff6347ff\",\n transparent: \"#00000000\",\n turquoise: \"#40e0d0ff\",\n violet: \"#ee82eeff\",\n wheat: \"#f5deb3ff\",\n white: \"#ffffffff\",\n whitesmoke: \"#f5f5f5ff\",\n yellow: \"#ffff00ff\",\n yellowgreen: \"#9acd32ff\",\n});\n\nconst namedColors = new Set<NamedColor>(O.keys(namedColorsMap));\n\nconst namedColorsChannelsCache: Partial<Record<NamedColor, ColorChannels>> = {};\n\nconst namedColorsAliasesCache: Partial<\n Record<NamedColor, readonly NamedColor[]>\n> = {};\n\n/**\n * Whether the input is a valid named color.\n *\n * The check is case-sensitive.\n */\nexport function isNamedColor(value: unknown): value is NamedColor {\n return S.is(value) && namedColors.has(<NamedColor>value.toLowerCase());\n}\n\n/**\n * Returns the color channels from a named color. Must be a valid named color, already lowercased.\n *\n * @internal\n */\nexport function namedColorChannels(name: NamedColor): ColorChannels {\n return (namedColorsChannelsCache[name] ??= parseHex(namedColorToHex(name)!));\n}\n\n/**\n * Returns the color channels from a named color.\n */\nexport function parseNamedColor(name: MaybeNamedColor): ColorChannels {\n if (!isNamedColor(name)) {\n return fallbackColor;\n }\n\n return namedColorChannels(<NamedColor>name.toLowerCase());\n}\n\n/**\n * Returns the corresponding HEX value of a named color.\n */\nexport function namedColorToHex(name: NamedColor): string;\nexport function namedColorToHex(name: MaybeNamedColor): string | undefined;\nexport function namedColorToHex(name: MaybeNamedColor): string | undefined {\n return (\n namedColorsMap[<keyof typeof namedColorsMap>name.toLowerCase()] || undefined\n );\n}\n\n/** Returns the closest named color to the passed color channels. */\nexport function closestNamedColor(channels: ColorChannels): NamedColor {\n let closest: NamedColor | undefined;\n let smallestDistance = Infinity;\n\n for (const name of namedColors) {\n const value = namedColorChannels(name);\n const d = distance(\n value,\n channels,\n value.a === 1 // Ignore alpha channel only if it's 1 -> allows to match transparent/black correctly\n );\n\n if (d < smallestDistance) {\n closest = name;\n smallestDistance = d;\n }\n }\n\n return closest!;\n}\n\n/**\n * Returns all the aliases of a named color.\n */\nexport function namedColorAliases(name: NamedColor): readonly NamedColor[] {\n name = <NamedColor>name.toLowerCase();\n\n if (!isNamedColor(name)) {\n return [];\n }\n\n if (namedColorsAliasesCache[name]) {\n return namedColorsAliasesCache[name]!;\n }\n\n const aliases: NamedColor[] = [];\n const targetHex = namedColorToHex(name);\n\n for (const [name, hex] of O.entries(namedColorsMap)) {\n if (hex === targetHex) {\n aliases.push(name);\n }\n }\n\n return (namedColorsAliasesCache[name] = Object.freeze(aliases));\n}\n\n/**\n * Returns a boolean indicating whether two named colors are aliases.\n */\nexport function isAliasToNamedColor(\n name: NamedColor,\n alias: NamedColor\n): boolean {\n return namedColorAliases(name).includes(<NamedColor>alias.toLowerCase());\n}\n","import { A, N } from \"@auaust/primitive-kit\";\nimport type { ColorChannels, Rgb } from \"~/types\";\nimport {\n fallbackColor,\n isAlphaChannel,\n isRgbChannel,\n toAlphaChannel,\n toColorChannels,\n toRgbChannel,\n} from \"./channels\";\n\n/**\n * Whether the input is a valid RGB color.\n */\nexport function isRgb(value: unknown): value is Rgb {\n return (\n A.is(value) &&\n N.isBetween(value.length, 3, 4) &&\n value.every((n, i) => (i === 3 ? isAlphaChannel(n) : isRgbChannel(n)))\n );\n}\n\n/**\n * Whether the input could be a valid RGB color.\n * As in, it checks if the input is an array of numbers without validating the values range.\n */\nexport function couldBeRgb(value: unknown): value is Rgb {\n return A.is(value) && N.isBetween(value.length, 3, 4) && value.every(N.is);\n}\n\n/**\n * Parses a RGB tuple into an object of color channels.\n *\n * The input must already be a valid RGB tuple, otherwise the result will be unexpected.\n */\nexport function parseRgb(value: Rgb): ColorChannels {\n return A.is(value)\n ? toColorChannels(value[0], value[1], value[2], value[3]) // Don't spread to avoid mistakenly forwarding `isTransformed` and `isFallback`\n : fallbackColor;\n}\n\n/**\n * Returns the corresponding RGB tuple of a color channels object.\n */\nexport function toRgb(channels: ColorChannels): Rgb {\n const { r, g, b, a } = channels;\n\n return Array.from([r, g, b, a], (value, i) =>\n i === 3 ? toAlphaChannel(value) : toRgbChannel(value)\n );\n}\n","/**\n * Used to privately store the cached channels of a color.\n */\nexport const channels = Symbol(\"Color.channels\");\n\n/**\n * Used to privately store the cached data of a color.\n */\nexport const cache = Symbol(\"Color.cache\");\n","import { Color } from \"~/classes/Color\";\nimport type { ColorChannels, ColorType, ColorValue } from \"~/types\";\nimport { fallbackColor, isColorChannels } from \"./channels\";\nimport { isHex, parseHex } from \"./hex\";\nimport { isNamedColor, parseNamedColor } from \"./namedColors\";\nimport { couldBeRgb, isRgb, parseRgb } from \"./rgb\";\nimport { channels } from \"./symbols\";\n\n/** Returns true if the value is any format of supported color. */\nexport function isColor(value: unknown): value is ColorValue {\n return type(value) !== undefined;\n}\n\n/** Returns the color type of the value, or undefined if it's not a color. */\nexport function type(value: unknown): ColorType | undefined {\n if (!value) {\n return undefined;\n }\n\n if (value instanceof Color) {\n return \"color\";\n }\n\n if (isNamedColor(value)) {\n return \"named\";\n }\n\n if (isHex(value)) {\n return \"hex\";\n }\n\n if (isRgb(value)) {\n return \"rgb\";\n }\n\n if (isColorChannels(value)) {\n return \"channels\";\n }\n\n return undefined;\n}\n\n/** Tries to parse the value as a color. If it fails, returns the fallback color. */\nexport function parseColor(value: unknown): ColorChannels {\n if (!value) {\n return fallbackColor;\n }\n\n if (value instanceof Color) {\n return value[channels];\n }\n\n if (isColorChannels(value)) {\n return value;\n }\n\n if (isNamedColor(value)) {\n return parseNamedColor(value);\n }\n\n if (isHex(value)) {\n return parseHex(value);\n }\n\n if (couldBeRgb(value)) {\n // It might not be a valid RGB, in which case `parseRgb` is responsible for returning the fallback color\n // In case more color types are added, it might be required to only return the result of `parseRgb` if `isFallback` is false\n return parseRgb(value);\n }\n\n return fallbackColor;\n}\n","import type { ColorChannels } from \"~/types\";\n\n/** Calculate the distance between two colors. It is mostly useful for comparing distances between colors, but the value itself is not very meaningful. */\nexport function distance(\n a: ColorChannels,\n b: ColorChannels,\n alpha = false\n): number {\n return Math.sqrt(\n Math.pow(a.r - b.r, 2) +\n Math.pow(a.g - b.g, 2) +\n Math.pow(a.b - b.b, 2) +\n (alpha ? Math.pow((a.a ?? 1) - (b.a ?? 1), 2) : 0)\n );\n}\n","import { N } from \"@auaust/primitive-kit\";\nimport type { ColorChannels } from \"~/types\";\nimport { toColorChannels } from \"./channels\";\n\n/**\n * Returns the linearized value of a sRGB channel.\n *\n * @see https://stackoverflow.com/a/56678483\n */\nexport function sRGBtoLinear(channel: number) {\n if (channel <= 0.04045) {\n return channel / 12.92;\n }\n\n return Math.pow((channel + 0.055) / 1.055, 2.4);\n}\n\n/**\n * Returns the gamma corrected sRGB value of a linear channel.\n *\n * @see sRGBtoLinear\n */\nexport function linearTosRGB(channel: number) {\n if (channel <= 0.04045 / 12.92) {\n return channel * 12.92;\n }\n\n return 1.055 * Math.pow(channel, 1 / 2.4) - 0.055;\n}\n\n/**\n * Returns the luminance of a color normalized to the range [0, 1].\n *\n * @see https://stackoverflow.com/a/56678483\n * @see https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef\n */\nexport function luminance(channels: ColorChannels) {\n let { r, g, b } = channels;\n\n [r, g, b] = [r, g, b].map((v) => sRGBtoLinear(v / 255));\n\n return r * 0.2126 + g * 0.7152 + b * 0.0722;\n}\n\n/**\n * Returns the perceived brightness of a color normalized to the range [0, 1].\n *\n * @see https://stackoverflow.com/a/56678483\n */\nexport function brightness(channels: ColorChannels): number {\n const l = luminance(channels);\n\n if (l <= 216 / 24389) {\n return l * (24389 / 27);\n }\n\n return (Math.pow(l, 1 / 3) * 116 - 16) / 100;\n}\n\n/** Returns whether the color is bright, as in its brightness is greater than 0.5 or the provided threshold. */\nexport function isBright(channels: ColorChannels, threshold = 0.5): boolean {\n return brightness(channels) > threshold;\n}\n\n/** Returns whether the color is dark, as in its brightness is less than or equal to 0.5 or the provided threshold. */\nexport function isDark(channels: ColorChannels, threshold = 0.5): boolean {\n return brightness(channels) <= threshold;\n}\n\n/**\n * Returns the contrast ratio between two colors.\n *\n * @see https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef\n */\nexport function contrast(channelsA: ColorChannels, channelsB: ColorChannels) {\n const [darkest, brightest] = N.minMax(\n luminance(channelsA),\n luminance(channelsB)\n );\n\n return (brightest + 0.05) / (darkest + 0.05);\n}\n\n/**\n * Returns the grayscale equivalent of a color as a new color channels object.\n */\nexport function grayscale(channels: ColorChannels): ColorChannels {\n // Reverse gamma correction from luminance\n const gray = linearTosRGB(luminance(channels)) * 255;\n\n return toColorChannels(gray, gray, gray, channels.a);\n}\n","import type { ColorChannels } from \"~/types\";\n\n/** Checks if the color is fully opaque. */\nexport function isOpaque(channels: ColorChannels) {\n return channels.a === 1 || channels.a == undefined;\n}\n\n/** Checks if the color is fully transparent. */\nexport function isTransparent(channels: ColorChannels) {\n return channels.a === 0;\n}\n\n/** Checks if the color is at least partially transparent. */\nexport function isTranslucent(channels: ColorChannels) {\n return !isOpaque(channels);\n}\n"],"mappings":"mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,WAAAE,IAAA,eAAAC,GAAAH,ICAA,IAAAI,GAAkB,iCCAlB,IAAAC,EAAqB,iCAGd,SAASC,EAAaC,EAAiC,CAC5D,OAAO,IAAE,GAAGA,CAAK,GAAK,IAAE,UAAUA,EAAO,EAAG,GAAG,CACjD,CAEO,SAASC,EAAaD,EAA0C,CACrE,OAAO,IAAE,MAAM,IAAE,MAAMA,CAAK,EAAG,EAAG,GAAG,CACvC,CAEO,SAASE,EAAeF,EAAiC,CAC9D,OAAO,IAAE,GAAGA,CAAK,GAAK,IAAE,UAAUA,EAAO,EAAG,CAAC,CAC/C,CAEO,SAASG,EAAeH,EAA0C,CACvE,OAAO,IAAE,GAAGA,CAAK,EAAI,IAAE,MAAMA,EAAO,EAAG,CAAC,EAAI,CAC9C,CAEO,SAASI,EAAgBJ,EAAwC,CACtE,OACE,IAAE,GAAGA,EAAO,EAAK,GACjBD,EAAaC,EAAM,CAAC,GACpBD,EAAaC,EAAM,CAAC,GACpBD,EAAaC,EAAM,CAAC,GACpBE,EAAeF,EAAM,GAAK,CAAC,CAE/B,CAkBO,SAASK,EACdC,EACAC,EACAC,EACAC,EACAC,EACAC,EACyB,CACrB,IAAE,GAAGL,EAAG,EAAK,IACd,CAAE,EAAAA,EAAG,EAAAC,EAAG,EAAAC,EAAG,EAAAC,EAAG,cAAAC,EAAe,WAAAC,CAAW,EAAIL,GAG/C,IAAMM,EAASX,EAAaK,CAAC,EACvBO,EAASZ,EAAaM,CAAC,EACvBO,EAASb,EAAaO,CAAC,EAE7B,GAAI,MAAMI,CAAM,GAAK,MAAMC,CAAM,GAAK,M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aA,EAEzD,CAGA,aAAaA,EAAoC,CAC/C,OACE,KAAK,YACJA,aAAqBnC,EAAQmC,EAAU,WAAaA,EAEzD,CAGA,IAAI,WAAoB,CACtB,OAAO,KAAK,QAAQC,CAAS,CAC/B,CAGA,SAASC,EAA2B,CAClC,OAAOC,EAAS,KAAKrC,CAAQ,EAAGD,EAAM,KAAKqC,CAAK,EAAEpC,CAAQ,CAAC,CAC7D,CAGA,SAASoC,EAAmBE,EAAQ,GAAe,CACjD,OAAOC,EAAS,KAAKvC,CAAQ,EAAGD,EAAM,KAAKqC,CAAK,EAAEpC,CAAQ,EAAGsC,CAAK,CACpE,CAGA,aAAqB,CACnB,OAAOvC,EAAM,aAAayC,EAAU,KAAKxC,CAAQ,CAAC,CAAC,CACrD,CAEA,OAAgB,CACd,OAAO,KAAK,QAAQyC,CAAK,CAC3B,CAEA,OAAa,CACX,OAAO,KAAK,QAAQC,CAAK,CAC3B,CAEA,YAA4B,CAC1B,OAAO,KAAK,QAAQvC,CAAe,CACrC,CAEA,UAAmB,CACjB,OAAO,KAAK,MAAM,CACpB,CAEA,SAAkB,CAChB,OAAO,KAAK,SAAS,CACvB,CAEA,CAAC,OAAO,WAAW,GAAY,CAC7B,OAAO,KAAK,SAAS,CACvB,CAEA,QAAiB,CACf,OAAO,KAAK,SAAS,CACvB,CACF","names":["src_exports","__export","Color","__toCommonJS","import_primitive_kit","import_primitive_kit","isRgbChannel","value","toRgbChannel","isAlphaChannel","toAlphaChannel","isColorChannels","toColorChannels","r","g","b","a","isTransformed","isFallback","finalR","finalG","finalB","fallbackColor","finalA","import_primitive_kit","hexadecimalRegex","isHex","value","parseHex","isShort","hasAlpha","r","g","b","a","toColorChannels","toHex","channels","toRgbChannel","import_primitive_kit","namedColorsMap","namedColors","namedColorsChannelsCache","namedColorsAliasesCache","isNamedColor","value","namedColorChannels","name","parseHex","namedColorToHex","parseNamedColor","fallbackColor","closestNamedColor","channels","closest","smallestDistance","d","distance","namedColorAliases","aliases","targetHex","hex","isAliasToNamedColor","alias","import_primitive_kit","isRgb","value","n","i","isAlphaChannel","isRgbChannel","couldBeRgb","parseRgb","toColorChannels","fallbackColor","toRgb","channels","g","b","a","toAlphaChannel","toRgbChannel","channels","cache","isColor","value","type","Color","isNamedColor","isHex","isRgb","isColorChannels","parseColor","channels","parseNamedColor","parseHex","couldBeRgb","parseRgb","fallbackColor","distance","a","b","alpha","import_primitive_kit","sRGBtoLinear","channel","linearTosRGB","luminance","channels","g","b","v","brightness","l","isBright","threshold","isDark","contrast","channelsA","channelsB","darkest","brightest","grayscale","gray","toColorChannels","isOpaque","channels","isTransparent","isTranslucent","Color","_Color","channels","cache","value","toColorChannels","rest","parseColor","fallbackColor","rgb","parseRgb","hex","parseHex","name","parseNamedColor","type","isColor","isHex","isNamedColor","isColorChannels","isRgb","namedColorAliases","isAliasToNamedColor","channel","toAlphaChannel","toRgbChannel","getter","key","cacheKey","isOpaque","isTransparent","isTranslucent","closestNamedColor","brightness","isBright","isDark","threshold","luminance","color","contrast","alpha","distance","grayscale","toHex","toRgb"]}
@@ -0,0 +1,2 @@
1
+ export { z as Color, C as ColorChannels, A as ColorType, B as ColorValue, H as Hex, M as MaybeNamedColor, N as NamedColor, R as Rgb } from './index-C_7oeA7B.cjs';
2
+ import 'type-fest';
@@ -0,0 +1,2 @@
1
+ export { z as Color, C as ColorChannels, A as ColorType, B as ColorValue, H as Hex, M as MaybeNamedColor, N as NamedColor, R as Rgb } from './index-C_7oeA7B.js';
2
+ import 'type-fest';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{N as le}from"@auaust/primitive-kit";import{N as m,O}from"@auaust/primitive-kit";function c(e){return m.is(e)&&m.isBetween(e,0,255)}function a(e){return m.clamp(m.round(e),0,255)}function H(e){return m.is(e)&&m.isBetween(e,0,1)}function b(e){return m.is(e)?m.clamp(e,0,1):1}function p(e){return O.is(e,!1)&&c(e.r)&&c(e.g)&&c(e.b)&&H(e.a??1)}function s(e,r,o,t,f,l){O.is(e,!1)&&({r:e,g:r,b:o,a:t,isTransformed:f,isFallback:l}=e);let d=a(e),S=a(r),G=a(o);if(isNaN(d)||isNaN(S)||isNaN(G))return i;let ee=b(t);return O.freeze({r:d,g:S,b:G,a:ee,isTransformed:!!(f||d!==e||S!==r||G!==o||ee!==(t??1)),isFallback:!!l})}var i=s(0,0,0,1,!1,!0);import{N as V,S as re}from"@auaust/primitive-kit";var fe=/^[0-9a-f]+$/i;function g(e){if(e=re.is(e)&&(e.startsWith("#")?e.slice(1):e),!re.isStrict(e))return!1;switch(e.length){case 3:case 4:case 6:case 8:return fe.test(e);default:return!1}}function h(e){e=e.startsWith("#")?e.slice(1):e;let r=e.length<6,o=r?e.length===4:e.length===8,t=parseInt(r?e[0].repeat(2):e.slice(0,2),16),f=parseInt(r?e[1].repeat(2):e.slice(2,4),16),l=parseInt(r?e[2].repeat(2):e.slice(4,6),16),d=o?parseInt(r?e[3].repeat(2):e.slice(6,8),16)/255:1;return s(t,f,l,d)}function L(e){let{r,g:o,b:t,a:f}=e;return"#"+((1<<24)+(a(r)<<16)+(a(o)<<8)+a(t)).toString(16).substring(1)+(V.is(f)&&f<1?V.round(V.max(0,f)*255).toString(16).padStart(2,"0"):"")}import{O as F,S as ae}from"@auaust/primitive-kit";var A=F.freeze({aliceblue:"#f0f8ffff",antiquewhite:"#faebd7ff",aqua:"#00ffffff",aquamarine:"#7fffd4ff",azure:"#f0ffffff",beige:"#f5f5dcff",bisque:"#ffe4c4ff",black:"#000000ff",blanchedalmond:"#ffebcdff",blue:"#0000ffff",blueviolet:"#8a2be2ff",brown:"#a52a2aff",burlywood:"#deb887ff",cadetblue:"#5f9ea0ff",chartreuse:"#7fff00ff",chocolate:"#d2691eff",coral:"#ff7f50ff",cornflowerblue:"#6495edff",cornsilk:"#fff8dcff",crimson:"#dc143cff",cyan:"#00ffffff",darkblue:"#00008bff",darkcyan:"#008b8bff",darkgoldenrod:"#b8860bff",darkgray:"#a9a9a9ff",darkgreen:"#006400ff",darkgrey:"#a9a9a9ff",darkkhaki:"#bdb76bff",darkmagenta:"#8b008bff",darkolivegreen:"#556b2fff",darkorange:"#ff8c00ff",darkorchid:"#9932ccff",darkred:"#8b0000ff",darksalmon:"#e9967aff",darkseagreen:"#8fbc8fff",darkslateblue:"#483d8bff",darkslategray:"#2f4f4fff",darkslategrey:"#2f4f4fff",darkturquoise:"#00ced1ff",darkviolet:"#9400d3ff",deeppink:"#ff1493ff",deepskyblue:"#00bfffff",dimgray:"#696969ff",dimgrey:"#696969ff",dodgerblue:"#1e90ffff",firebrick:"#b22222ff",floralwhite:"#fffaf0ff",forestgreen:"#228b22ff",fuchsia:"#ff00ffff",gainsboro:"#dcdcdcff",ghostwhite:"#f8f8ffff",gold:"#ffd700ff",goldenrod:"#daa520ff",gray:"#808080ff",green:"#008000ff",greenyellow:"#adff2fff",grey:"#808080ff",honeydew:"#f0fff0ff",hotpink:"#ff69b4ff",indianred:"#cd5c5cff",indigo:"#4b0082ff",ivory:"#fffff0ff",khaki:"#f0e68cff",lavender:"#e6e6faff",lavenderblush:"#fff0f5ff",lawngreen:"#7cfc00ff",lemonchiffon:"#fffacdff",lightblue:"#add8e6ff",lightcoral:"#f08080ff",lightcyan:"#e0ffffff",lightgoldenrodyellow:"#fafad2ff",lightgray:"#d3d3d3ff",lightgreen:"#90ee90ff",lightgrey:"#d3d3d3ff",lightpink:"#ffb6c1ff",lightsalmon:"#ffa07aff",lightseagreen:"#20b2aaff",lightskyblue:"#87cefaff",lightslategray:"#778899ff",lightslategrey:"#778899ff",lightsteelblue:"#b0c4deff",lightyellow:"#ffffe0ff",lime:"#00ff00ff",limegreen:"#32cd32ff",linen:"#faf0e6ff",magenta:"#ff00ffff",maroon:"#800000ff",mediumaquamarine:"#66cdaaff",mediumblue:"#0000cdff",mediumorchid:"#ba55d3ff",mediumpurple:"#9370dbff",mediumseagreen:"#3cb371ff",mediumslateblue:"#7b68eeff",mediumspringgreen:"#00fa9aff",mediumturquoise:"#48d1ccff",mediumvioletred:"#c71585ff",midnightblue:"#191970ff",mintcream:"#f5fffaff",mistyrose:"#ffe4e1ff",moccasin:"#ffe4b5ff",navajowhite:"#ffdeadff",navy:"#000080ff",oldlace:"#fdf5e6ff",olive:"#808000ff",olivedrab:"#6b8e23ff",orange:"#ffa500ff",orangered:"#ff4500ff",orchid:"#da70d6ff",palegoldenrod:"#eee8aaff",palegreen:"#98fb98ff",paleturquoise:"#afeeeeff",palevioletred:"#db7093ff",papayawhip:"#ffefd5ff",peachpuff:"#ffdab9ff",peru:"#cd853fff",pink:"#ffc0cbff",plum:"#dda0ddff",powderblue:"#b0e0e6ff",purple:"#800080ff",rebeccapurple:"#663399ff",red:"#ff0000ff",rosybrown:"#bc8f8fff",royalblue:"#4169e1ff",saddlebrown:"#8b4513ff",salmon:"#fa8072ff",sandybrown:"#f4a460ff",seagreen:"#2e8b57ff",seashell:"#fff5eeff",sienna:"#a0522dff",silver:"#c0c0c0ff",skyblue:"#87ceebff",slateblue:"#6a5acdff",slategray:"#708090ff",slategrey:"#708090ff",snow:"#fffafaff",springgreen:"#00ff7fff",steelblue:"#4682b4ff",tan:"#d2b48cff",teal:"#008080ff",thistle:"#d8bfd8ff",tomato:"#ff6347ff",transparent:"#00000000",turquoise:"#40e0d0ff",violet:"#ee82eeff",wheat:"#f5deb3ff",white:"#ffffffff",whitesmoke:"#f5f5f5ff",yellow:"#ffff00ff",yellowgreen:"#9acd32ff"}),oe=new Set(F.keys(A)),se={},D={};function u(e){return ae.is(e)&&oe.has(e.toLowerCase())}function I(e){return se[e]??=h(P(e))}function w(e){return u(e)?I(e.toLowerCase()):i}function P(e){return A[e.toLowerCase()]||void 0}function W(e){let r,o=1/0;for(let t of oe){let f=I(t),l=k(f,e,f.a===1);l<o&&(r=t,o=l)}return r}function M(e){if(e=e.toLowerCase(),!u(e))return[];if(D[e])return D[e];let r=[],o=P(e);for(let[t,f]of F.entries(A))f===o&&r.push(t);return D[e]=Object.freeze(r)}function j(e,r){return M(e).includes(r.toLowerCase())}import{A as K,N as J}from"@auaust/primitive-kit";function N(e){return K.is(e)&&J.isBetween(e.length,3,4)&&e.every((r,o)=>o===3?H(r):c(r))}function $(e){return K.is(e)&&J.isBetween(e.length,3,4)&&e.every(J.is)}function R(e){return K.is(e)?s(e[0],e[1],e[2],e[3]):i}function E(e){let{r,g:o,b:t,a:f}=e;return Array.from([r,o,t,f],(l,d)=>d===3?b(l):a(l))}var n=Symbol("Color.channels"),y=Symbol("Color.cache");function B(e){return q(e)!==void 0}function q(e){if(e){if(e instanceof x)return"color";if(u(e))return"named";if(g(e))return"hex";if(N(e))return"rgb";if(p(e))return"channels"}}function Q(e){return e?e instanceof x?e[n]:p(e)?e:u(e)?w(e):g(e)?h(e):$(e)?R(e):i:i}function k(e,r,o=!1){return Math.sqrt(Math.pow(e.r-r.r,2)+Math.pow(e.g-r.g,2)+Math.pow(e.b-r.b,2)+(o?Math.pow((e.a??1)-(r.a??1),2):0))}import{N as ie}from"@auaust/primitive-kit";function ne(e){return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function te(e){return e<=.04045/12.92?e*12.92:1.055*Math.pow(e,1/2.4)-.055}function C(e){let{r,g:o,b:t}=e;return[r,o,t]=[r,o,t].map(f=>ne(f/255)),r*.2126+o*.7152+t*.0722}function T(e){let r=C(e);return r<=216/24389?r*(24389/27):(Math.pow(r,1/3)*116-16)/100}function U(e,r=.5){return T(e)>r}function X(e,r=.5){return T(e)<=r}function Y(e,r){let[o,t]=ie.minMax(C(e),C(r));return(t+.05)/(o+.05)}function Z(e){let r=te(C(e))*255;return s(r,r,r,e.a)}function z(e){return e.a===1||e.a==null}function _(e){return e.a===0}function v(e){return!z(e)}var x=class e{[n]=void 0;[y]=new Map;constructor(r){this[n]={...s(r)}}static from(r,...o){return le.is(r)?new this({r,g:o[0],b:o[1],a:o[2]}):new this(Q(r??i))}static fromChannels(r){return new this(r)}static fromRgb(r){return new this(R(r))}static fromHex(r){return new this(h(r))}static fromName(r){return new this(w(r))}static type=q;static isColor=B;static is=B;static isHex=g;static isNamedColor=u;static isColorChannels=p;static isRgb=N;static namedColorAliases=M;static isAliasToNamedColor=j;clone(){return e.fromChannels(this[n])}with(r){return e.fromChannels({...this[n],...r,isFallback:!1,isTransformed:!1})}withRed(r){return this.with({r})}withGreen(r){return this.with({g:r})}withBlue(r){return this.with({b:r})}withAlpha(r){return this.with({a:r})}updated(){return this[y].clear(),this[n].isFallback=!1,this[n].isTransformed=!1,this}set(r,o){return this[n][r]=r==="a"?b(o):a(o),this.updated()}get red(){return this[n].r}get r(){return this[n].r}set red(r){this.setRed(r)}setRed(r){return this.set("r",r)}get green(){return this[n].g}get g(){return this[n].g}set green(r){this.setGreen(r)}setGreen(r){return this.set("g",r)}get blue(){return this[n].b}get b(){return this[n].b}set blue(r){this.setBlue(r)}setBlue(r){return this.set("b",r)}get alpha(){return this[n].a}get a(){return this[n].a}set alpha(r){this.setAlpha(r)}setAlpha(r){return this.set("a",r)}get isFallback(){return this[n].isFallback}get isTransformed(){return this[n].isTransformed}memoize(r,o){let t=o??r;return this[y].has(t)||this[y].set(t,r(this[n])),this[y].get(t)}get isOpaque(){return this.memoize(z)}get isTransparent(){return this.memoize(_)}get isTranslucent(){return this.memoize(v)}get closestNamedColor(){return this.memoize(W)}get brightness(){return this.memoize(T)}get isBright(){return this.memoize(U)}get isDark(){return this.memoize(X)}isBrighterThan(r){return this.brightness>(r instanceof e?r.brightness:r)}isDarkerThan(r){return this.brightness<(r instanceof e?r.brightness:r)}get luminance(){return this.memoize(C)}contrast(r){return Y(this[n],e.from(r)[n])}distance(r,o=!1){return k(this[n],e.from(r)[n],o)}toGrayscale(){return e.fromChannels(Z(this[n]))}toHex(){return this.memoize(L)}toRgb(){return this.memoize(E)}toChannels(){return this.memoize(s)}toString(){return this.toHex()}valueOf(){return this.toString()}[Symbol.toPrimitive](){return this.toString()}toJSON(){return this.toString()}};export{x as Color};
2
+ //# sourceMappingURL=index.js.map