@zag-js/color-utils 0.10.2 → 0.10.3
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/dist/color.d.ts +2 -5
- package/dist/color.js +7 -30
- package/dist/color.mjs +31 -7
- package/dist/hsb-color.d.ts +3 -6
- package/dist/hsb-color.js +22 -351
- package/dist/hsb-color.mjs +107 -9
- package/dist/hsl-color.d.ts +4 -7
- package/dist/hsl-color.js +23 -353
- package/dist/hsl-color.mjs +107 -11
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -455
- package/dist/index.mjs +2 -15
- package/dist/parse-color.d.ts +3 -6
- package/dist/parse-color.js +9 -442
- package/dist/parse-color.mjs +20 -12
- package/dist/rgb-color.d.ts +3 -6
- package/dist/rgb-color.js +23 -297
- package/dist/rgb-color.mjs +162 -9
- package/dist/types.d.ts +5 -7
- package/dist/utils.d.ts +3 -5
- package/dist/utils.js +7 -32
- package/dist/utils.mjs +11 -11
- package/package.json +2 -7
- package/dist/chunk-7VB2GGWQ.mjs +0 -382
- package/dist/chunk-NHABU752.mjs +0 -10
- package/dist/chunk-NSR5W5ST.mjs +0 -34
- package/dist/chunk-TXOVH6IE.mjs +0 -16
- package/dist/chunk-WWI4IDFU.mjs +0 -26
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -0
package/dist/chunk-7VB2GGWQ.mjs
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Color
|
|
3
|
-
} from "./chunk-NSR5W5ST.mjs";
|
|
4
|
-
import {
|
|
5
|
-
clampValue,
|
|
6
|
-
mod,
|
|
7
|
-
toFixedNumber
|
|
8
|
-
} from "./chunk-TXOVH6IE.mjs";
|
|
9
|
-
import {
|
|
10
|
-
__publicField
|
|
11
|
-
} from "./chunk-NHABU752.mjs";
|
|
12
|
-
|
|
13
|
-
// src/hsl-color.ts
|
|
14
|
-
var HSL_REGEX = /hsl\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsla\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
|
|
15
|
-
var _HSLColor = class extends Color {
|
|
16
|
-
constructor(hue, saturation, lightness, alpha) {
|
|
17
|
-
super();
|
|
18
|
-
this.hue = hue;
|
|
19
|
-
this.saturation = saturation;
|
|
20
|
-
this.lightness = lightness;
|
|
21
|
-
this.alpha = alpha;
|
|
22
|
-
}
|
|
23
|
-
static parse(value) {
|
|
24
|
-
let m;
|
|
25
|
-
if (m = value.match(HSL_REGEX)) {
|
|
26
|
-
const [h, s, l, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
|
|
27
|
-
return new _HSLColor(mod(h, 360), clampValue(s, 0, 100), clampValue(l, 0, 100), clampValue(a ?? 1, 0, 1));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
toString(format) {
|
|
31
|
-
switch (format) {
|
|
32
|
-
case "hex":
|
|
33
|
-
return this.toRGB().toString("hex");
|
|
34
|
-
case "hexa":
|
|
35
|
-
return this.toRGB().toString("hexa");
|
|
36
|
-
case "hsl":
|
|
37
|
-
return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`;
|
|
38
|
-
case "css":
|
|
39
|
-
case "hsla":
|
|
40
|
-
return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;
|
|
41
|
-
default:
|
|
42
|
-
return this.toFormat(format).toString(format);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
toFormat(format) {
|
|
46
|
-
switch (format) {
|
|
47
|
-
case "hsl":
|
|
48
|
-
case "hsla":
|
|
49
|
-
return this;
|
|
50
|
-
case "hsb":
|
|
51
|
-
case "hsba":
|
|
52
|
-
return this.toHSB();
|
|
53
|
-
case "rgb":
|
|
54
|
-
case "rgba":
|
|
55
|
-
return this.toRGB();
|
|
56
|
-
default:
|
|
57
|
-
throw new Error("Unsupported color conversion: hsl -> " + format);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Converts a HSL color to HSB.
|
|
62
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
|
|
63
|
-
* @returns An HSBColor object.
|
|
64
|
-
*/
|
|
65
|
-
toHSB() {
|
|
66
|
-
let saturation = this.saturation / 100;
|
|
67
|
-
let lightness = this.lightness / 100;
|
|
68
|
-
let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
|
|
69
|
-
saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
|
|
70
|
-
return new HSBColor(
|
|
71
|
-
toFixedNumber(this.hue, 2),
|
|
72
|
-
toFixedNumber(saturation * 100, 2),
|
|
73
|
-
toFixedNumber(brightness * 100, 2),
|
|
74
|
-
this.alpha
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts a HSL color to RGB.
|
|
79
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
|
|
80
|
-
* @returns An RGBColor object.
|
|
81
|
-
*/
|
|
82
|
-
toRGB() {
|
|
83
|
-
let hue = this.hue;
|
|
84
|
-
let saturation = this.saturation / 100;
|
|
85
|
-
let lightness = this.lightness / 100;
|
|
86
|
-
let a = saturation * Math.min(lightness, 1 - lightness);
|
|
87
|
-
let fn = (n, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
88
|
-
return new RGBColor(Math.round(fn(0) * 255), Math.round(fn(8) * 255), Math.round(fn(4) * 255), this.alpha);
|
|
89
|
-
}
|
|
90
|
-
clone() {
|
|
91
|
-
return new _HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
|
|
92
|
-
}
|
|
93
|
-
getChannelRange(channel) {
|
|
94
|
-
switch (channel) {
|
|
95
|
-
case "hue":
|
|
96
|
-
return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
|
|
97
|
-
case "saturation":
|
|
98
|
-
case "lightness":
|
|
99
|
-
return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
|
|
100
|
-
case "alpha":
|
|
101
|
-
return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
|
|
102
|
-
default:
|
|
103
|
-
throw new Error("Unknown color channel: " + channel);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
getColorSpace() {
|
|
107
|
-
return "hsl";
|
|
108
|
-
}
|
|
109
|
-
getColorChannels() {
|
|
110
|
-
return _HSLColor.colorChannels;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var HSLColor = _HSLColor;
|
|
114
|
-
__publicField(HSLColor, "colorChannels", ["hue", "saturation", "lightness"]);
|
|
115
|
-
|
|
116
|
-
// src/hsb-color.ts
|
|
117
|
-
var HSB_REGEX = /hsb\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%)\)|hsba\(([-+]?\d+(?:.\d+)?\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d+(?:.\d+)?%\s*,\s*[-+]?\d(.\d+)?)\)/;
|
|
118
|
-
var _HSBColor = class extends Color {
|
|
119
|
-
constructor(hue, saturation, brightness, alpha) {
|
|
120
|
-
super();
|
|
121
|
-
this.hue = hue;
|
|
122
|
-
this.saturation = saturation;
|
|
123
|
-
this.brightness = brightness;
|
|
124
|
-
this.alpha = alpha;
|
|
125
|
-
}
|
|
126
|
-
static parse(value) {
|
|
127
|
-
let m;
|
|
128
|
-
if (m = value.match(HSB_REGEX)) {
|
|
129
|
-
const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
|
|
130
|
-
return new _HSBColor(mod(h, 360), clampValue(s, 0, 100), clampValue(b, 0, 100), clampValue(a ?? 1, 0, 1));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
toString(format) {
|
|
134
|
-
switch (format) {
|
|
135
|
-
case "css":
|
|
136
|
-
return this.toHSL().toString("css");
|
|
137
|
-
case "hex":
|
|
138
|
-
return this.toRGB().toString("hex");
|
|
139
|
-
case "hexa":
|
|
140
|
-
return this.toRGB().toString("hexa");
|
|
141
|
-
case "hsb":
|
|
142
|
-
return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;
|
|
143
|
-
case "hsba":
|
|
144
|
-
return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
|
|
145
|
-
default:
|
|
146
|
-
return this.toFormat(format).toString(format);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
toFormat(format) {
|
|
150
|
-
switch (format) {
|
|
151
|
-
case "hsb":
|
|
152
|
-
case "hsba":
|
|
153
|
-
return this;
|
|
154
|
-
case "hsl":
|
|
155
|
-
case "hsla":
|
|
156
|
-
return this.toHSL();
|
|
157
|
-
case "rgb":
|
|
158
|
-
case "rgba":
|
|
159
|
-
return this.toRGB();
|
|
160
|
-
default:
|
|
161
|
-
throw new Error("Unsupported color conversion: hsb -> " + format);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Converts a HSB color to HSL.
|
|
166
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
|
|
167
|
-
* @returns An HSLColor object.
|
|
168
|
-
*/
|
|
169
|
-
toHSL() {
|
|
170
|
-
let saturation = this.saturation / 100;
|
|
171
|
-
let brightness = this.brightness / 100;
|
|
172
|
-
let lightness = brightness * (1 - saturation / 2);
|
|
173
|
-
saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
|
|
174
|
-
return new HSLColor(
|
|
175
|
-
toFixedNumber(this.hue, 2),
|
|
176
|
-
toFixedNumber(saturation * 100, 2),
|
|
177
|
-
toFixedNumber(lightness * 100, 2),
|
|
178
|
-
this.alpha
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Converts a HSV color value to RGB.
|
|
183
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
|
|
184
|
-
* @returns An RGBColor object.
|
|
185
|
-
*/
|
|
186
|
-
toRGB() {
|
|
187
|
-
let hue = this.hue;
|
|
188
|
-
let saturation = this.saturation / 100;
|
|
189
|
-
let brightness = this.brightness / 100;
|
|
190
|
-
let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
|
|
191
|
-
return new RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), this.alpha);
|
|
192
|
-
}
|
|
193
|
-
clone() {
|
|
194
|
-
return new _HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
|
|
195
|
-
}
|
|
196
|
-
getChannelRange(channel) {
|
|
197
|
-
switch (channel) {
|
|
198
|
-
case "hue":
|
|
199
|
-
return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
|
|
200
|
-
case "saturation":
|
|
201
|
-
case "brightness":
|
|
202
|
-
return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
|
|
203
|
-
case "alpha":
|
|
204
|
-
return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
|
|
205
|
-
default:
|
|
206
|
-
throw new Error("Unknown color channel: " + channel);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
getColorSpace() {
|
|
210
|
-
return "hsb";
|
|
211
|
-
}
|
|
212
|
-
getColorChannels() {
|
|
213
|
-
return _HSBColor.colorChannels;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
var HSBColor = _HSBColor;
|
|
217
|
-
__publicField(HSBColor, "colorChannels", ["hue", "saturation", "brightness"]);
|
|
218
|
-
|
|
219
|
-
// src/rgb-color.ts
|
|
220
|
-
var _RGBColor = class extends Color {
|
|
221
|
-
constructor(red, green, blue, alpha) {
|
|
222
|
-
super();
|
|
223
|
-
this.red = red;
|
|
224
|
-
this.green = green;
|
|
225
|
-
this.blue = blue;
|
|
226
|
-
this.alpha = alpha;
|
|
227
|
-
}
|
|
228
|
-
static parse(value) {
|
|
229
|
-
let colors = [];
|
|
230
|
-
if (/^#[\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {
|
|
231
|
-
const values = (value.length < 6 ? value.replace(/[^#]/gi, "$&$&") : value).slice(1).split("");
|
|
232
|
-
while (values.length > 0) {
|
|
233
|
-
colors.push(parseInt(values.splice(0, 2).join(""), 16));
|
|
234
|
-
}
|
|
235
|
-
colors[3] = colors[3] !== void 0 ? colors[3] / 255 : void 0;
|
|
236
|
-
}
|
|
237
|
-
const match = value.match(/^rgba?\((.*)\)$/);
|
|
238
|
-
if (match?.[1]) {
|
|
239
|
-
colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1));
|
|
240
|
-
}
|
|
241
|
-
return colors.length < 3 ? void 0 : new _RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);
|
|
242
|
-
}
|
|
243
|
-
toString(format) {
|
|
244
|
-
switch (format) {
|
|
245
|
-
case "hex":
|
|
246
|
-
return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
|
|
247
|
-
case "hexa":
|
|
248
|
-
return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0") + Math.round(this.alpha * 255).toString(16).padStart(2, "0")).toUpperCase();
|
|
249
|
-
case "rgb":
|
|
250
|
-
return `rgb(${this.red}, ${this.green}, ${this.blue})`;
|
|
251
|
-
case "css":
|
|
252
|
-
case "rgba":
|
|
253
|
-
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
|
|
254
|
-
default:
|
|
255
|
-
return this.toFormat(format).toString(format);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
toFormat(format) {
|
|
259
|
-
switch (format) {
|
|
260
|
-
case "hex":
|
|
261
|
-
case "hexa":
|
|
262
|
-
case "rgb":
|
|
263
|
-
case "rgba":
|
|
264
|
-
return this;
|
|
265
|
-
case "hsb":
|
|
266
|
-
case "hsba":
|
|
267
|
-
return this.toHSB();
|
|
268
|
-
case "hsl":
|
|
269
|
-
case "hsla":
|
|
270
|
-
return this.toHSL();
|
|
271
|
-
default:
|
|
272
|
-
throw new Error("Unsupported color conversion: rgb -> " + format);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
toHexInt() {
|
|
276
|
-
return this.red << 16 | this.green << 8 | this.blue;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Converts an RGB color value to HSB.
|
|
280
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
|
|
281
|
-
* @returns An HSBColor object.
|
|
282
|
-
*/
|
|
283
|
-
toHSB() {
|
|
284
|
-
const red = this.red / 255;
|
|
285
|
-
const green = this.green / 255;
|
|
286
|
-
const blue = this.blue / 255;
|
|
287
|
-
const min = Math.min(red, green, blue);
|
|
288
|
-
const brightness = Math.max(red, green, blue);
|
|
289
|
-
const chroma = brightness - min;
|
|
290
|
-
const saturation = brightness === 0 ? 0 : chroma / brightness;
|
|
291
|
-
let hue = 0;
|
|
292
|
-
if (chroma !== 0) {
|
|
293
|
-
switch (brightness) {
|
|
294
|
-
case red:
|
|
295
|
-
hue = (green - blue) / chroma + (green < blue ? 6 : 0);
|
|
296
|
-
break;
|
|
297
|
-
case green:
|
|
298
|
-
hue = (blue - red) / chroma + 2;
|
|
299
|
-
break;
|
|
300
|
-
case blue:
|
|
301
|
-
hue = (red - green) / chroma + 4;
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
hue /= 6;
|
|
305
|
-
}
|
|
306
|
-
return new HSBColor(
|
|
307
|
-
toFixedNumber(hue * 360, 2),
|
|
308
|
-
toFixedNumber(saturation * 100, 2),
|
|
309
|
-
toFixedNumber(brightness * 100, 2),
|
|
310
|
-
this.alpha
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Converts an RGB color value to HSL.
|
|
315
|
-
* Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
|
|
316
|
-
* @returns An HSLColor object.
|
|
317
|
-
*/
|
|
318
|
-
toHSL() {
|
|
319
|
-
const red = this.red / 255;
|
|
320
|
-
const green = this.green / 255;
|
|
321
|
-
const blue = this.blue / 255;
|
|
322
|
-
const min = Math.min(red, green, blue);
|
|
323
|
-
const max = Math.max(red, green, blue);
|
|
324
|
-
const lightness = (max + min) / 2;
|
|
325
|
-
const chroma = max - min;
|
|
326
|
-
let hue = -1;
|
|
327
|
-
let saturation = -1;
|
|
328
|
-
if (chroma === 0) {
|
|
329
|
-
hue = saturation = 0;
|
|
330
|
-
} else {
|
|
331
|
-
saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min);
|
|
332
|
-
switch (max) {
|
|
333
|
-
case red:
|
|
334
|
-
hue = (green - blue) / chroma + (green < blue ? 6 : 0);
|
|
335
|
-
break;
|
|
336
|
-
case green:
|
|
337
|
-
hue = (blue - red) / chroma + 2;
|
|
338
|
-
break;
|
|
339
|
-
case blue:
|
|
340
|
-
hue = (red - green) / chroma + 4;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
hue /= 6;
|
|
344
|
-
}
|
|
345
|
-
return new HSLColor(
|
|
346
|
-
toFixedNumber(hue * 360, 2),
|
|
347
|
-
toFixedNumber(saturation * 100, 2),
|
|
348
|
-
toFixedNumber(lightness * 100, 2),
|
|
349
|
-
this.alpha
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
clone() {
|
|
353
|
-
return new _RGBColor(this.red, this.green, this.blue, this.alpha);
|
|
354
|
-
}
|
|
355
|
-
getChannelRange(channel) {
|
|
356
|
-
switch (channel) {
|
|
357
|
-
case "red":
|
|
358
|
-
case "green":
|
|
359
|
-
case "blue":
|
|
360
|
-
return { minValue: 0, maxValue: 255, step: 1, pageSize: 17 };
|
|
361
|
-
case "alpha":
|
|
362
|
-
return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
|
|
363
|
-
default:
|
|
364
|
-
throw new Error("Unknown color channel: " + channel);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
getColorSpace() {
|
|
368
|
-
return "rgb";
|
|
369
|
-
}
|
|
370
|
-
getColorChannels() {
|
|
371
|
-
return _RGBColor.colorChannels;
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
var RGBColor = _RGBColor;
|
|
375
|
-
__publicField(RGBColor, "colorChannels", ["red", "green", "blue"]);
|
|
376
|
-
|
|
377
|
-
export {
|
|
378
|
-
RGBColor,
|
|
379
|
-
HSL_REGEX,
|
|
380
|
-
HSLColor,
|
|
381
|
-
HSBColor
|
|
382
|
-
};
|
package/dist/chunk-NHABU752.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
__publicField
|
|
10
|
-
};
|
package/dist/chunk-NSR5W5ST.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// src/color.ts
|
|
2
|
-
var Color = class {
|
|
3
|
-
toHexInt() {
|
|
4
|
-
return this.toFormat("rgb").toHexInt();
|
|
5
|
-
}
|
|
6
|
-
getChannelValue(channel) {
|
|
7
|
-
if (channel in this) {
|
|
8
|
-
return this[channel];
|
|
9
|
-
}
|
|
10
|
-
throw new Error("Unsupported color channel: " + channel);
|
|
11
|
-
}
|
|
12
|
-
withChannelValue(channel, value) {
|
|
13
|
-
if (channel in this) {
|
|
14
|
-
let clone = this.clone();
|
|
15
|
-
clone[channel] = value;
|
|
16
|
-
return clone;
|
|
17
|
-
}
|
|
18
|
-
throw new Error("Unsupported color channel: " + channel);
|
|
19
|
-
}
|
|
20
|
-
getColorSpaceAxes(xyChannels) {
|
|
21
|
-
let { xChannel, yChannel } = xyChannels;
|
|
22
|
-
let xCh = xChannel || this.getColorChannels().find((c) => c !== yChannel);
|
|
23
|
-
let yCh = yChannel || this.getColorChannels().find((c) => c !== xCh);
|
|
24
|
-
let zCh = this.getColorChannels().find((c) => c !== xCh && c !== yCh);
|
|
25
|
-
return { xChannel: xCh, yChannel: yCh, zChannel: zCh };
|
|
26
|
-
}
|
|
27
|
-
isEqual(color) {
|
|
28
|
-
return this.toHexInt() === color.toHexInt();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
Color
|
|
34
|
-
};
|
package/dist/chunk-TXOVH6IE.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
function mod(n, m) {
|
|
3
|
-
return (n % m + m) % m;
|
|
4
|
-
}
|
|
5
|
-
function toFixedNumber(num, digits) {
|
|
6
|
-
return Math.round(Math.pow(10, digits) * num) / Math.pow(10, digits);
|
|
7
|
-
}
|
|
8
|
-
function clampValue(value, min, max) {
|
|
9
|
-
return Math.min(Math.max(value, min), max);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
mod,
|
|
14
|
-
toFixedNumber,
|
|
15
|
-
clampValue
|
|
16
|
-
};
|
package/dist/chunk-WWI4IDFU.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HSBColor,
|
|
3
|
-
HSLColor,
|
|
4
|
-
RGBColor
|
|
5
|
-
} from "./chunk-7VB2GGWQ.mjs";
|
|
6
|
-
|
|
7
|
-
// src/parse-color.ts
|
|
8
|
-
function parseColor(value) {
|
|
9
|
-
let result = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value);
|
|
10
|
-
if (!result) {
|
|
11
|
-
throw new Error("Invalid color value: " + value);
|
|
12
|
-
}
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
function normalizeColor(v) {
|
|
16
|
-
if (typeof v === "string") {
|
|
17
|
-
return parseColor(v);
|
|
18
|
-
} else {
|
|
19
|
-
return v;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
parseColor,
|
|
25
|
-
normalizeColor
|
|
26
|
-
};
|
package/dist/types.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
package/dist/types.mjs
DELETED
|
File without changes
|