@soybeanjs/colord 0.0.4 → 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.
Files changed (38) hide show
  1. package/dist/{colord-C3iU53g-.js → colord-CLzIbIN2.js} +20 -7
  2. package/dist/{colord-xpgrVWRV.d.ts → colord-Dc09uNcG.d.ts} +10 -0
  3. package/dist/colord.d.ts +1 -1
  4. package/dist/colord.js +8 -8
  5. package/dist/{extend-DrPfn2Q1.d.ts → extend-D_jQFvDk.d.ts} +1 -1
  6. package/dist/{get-D0jfz1WU.js → get-SLuYLSG9.js} +1 -1
  7. package/dist/{hsv-BKcGyyrD.js → hsv-OOAVcaRH.js} +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +8 -8
  10. package/dist/lab-9NsKpGel.js +219 -0
  11. package/dist/{manipulate-C3CvrU4m.js → manipulate-DCHNBCkU.js} +3 -3
  12. package/dist/plugins/a11y.d.ts +2 -2
  13. package/dist/plugins/a11y.js +3 -3
  14. package/dist/plugins/cmyk.d.ts +2 -2
  15. package/dist/plugins/cmyk.js +1 -1
  16. package/dist/plugins/harmonies.d.ts +1 -1
  17. package/dist/plugins/hwb.d.ts +2 -2
  18. package/dist/plugins/hwb.js +2 -2
  19. package/dist/plugins/lab.d.ts +6 -2
  20. package/dist/plugins/lab.js +11 -8
  21. package/dist/plugins/lch.d.ts +2 -2
  22. package/dist/plugins/lch.js +99 -25
  23. package/dist/plugins/minify.d.ts +1 -1
  24. package/dist/plugins/minify.js +1 -1
  25. package/dist/plugins/mix.d.ts +2 -2
  26. package/dist/plugins/mix.js +6 -6
  27. package/dist/plugins/names.d.ts +1 -1
  28. package/dist/plugins/oklab.d.ts +2 -2
  29. package/dist/plugins/oklab.js +50 -17
  30. package/dist/plugins/oklch.d.ts +2 -2
  31. package/dist/plugins/oklch.js +93 -24
  32. package/dist/plugins/xyz.d.ts +2 -2
  33. package/dist/plugins/xyz.js +5 -5
  34. package/dist/{rgb-DNYno5F7.js → rgb-BVkoWOmR.js} +8 -9
  35. package/dist/{utils-DajWVr6Z.js → utils-CshL9w1R.js} +18 -1
  36. package/dist/{xyz-CXEZJhV8.js → xyz-DsYRwYO_.js} +22 -9
  37. package/package.json +1 -1
  38. package/dist/lab-B5wAd4fu.js +0 -128
@@ -1,8 +1,8 @@
1
- import { l as round, v as ALPHA_PRECISION } from "./utils-DajWVr6Z.js";
2
- import { a as parseRgbString, c as roundRgb, i as parseRgb, s as rgbToRgbString } from "./rgb-DNYno5F7.js";
3
- import { i as roundHsv, n as parseHsv, r as rgbToHsv } from "./hsv-BKcGyyrD.js";
4
- import { a as saturate, c as rgbToHsl, l as rgbToHslString, n as invert, o as parseHsl, r as lighten, s as parseHslString, t as changeAlpha, u as roundHsl } from "./manipulate-C3CvrU4m.js";
5
- import { t as getBrightness } from "./get-D0jfz1WU.js";
1
+ import { l as round, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
2
+ import { a as parseRgbString, c as roundRgb, i as parseRgb, s as rgbToRgbString } from "./rgb-BVkoWOmR.js";
3
+ import { i as roundHsv, n as parseHsv, r as rgbToHsv } from "./hsv-OOAVcaRH.js";
4
+ import { a as saturate, c as rgbToHsl, l as rgbToHslString, n as invert, o as parseHsl, r as lighten, s as parseHslString, t as changeAlpha, u as roundHsl } from "./manipulate-DCHNBCkU.js";
5
+ import { t as getBrightness } from "./get-SLuYLSG9.js";
6
6
 
7
7
  //#region src/models/hex.ts
8
8
  const hexMatcher = /^#([0-9a-f]{3,8})$/i;
@@ -27,7 +27,7 @@ const parseHex = (hexStr) => {
27
27
  };
28
28
  /** Formats any decimal number (e.g. 128) as a hexadecimal string (e.g. "08") */
29
29
  const format = (number) => {
30
- const hex = number.toString(16);
30
+ const hex = Math.round(number).toString(16);
31
31
  return hex.length < 2 ? `0${hex}` : hex;
32
32
  };
33
33
  /** Converts RGBA object to Hex6 or (if it has alpha channel) Hex8 string */
@@ -92,14 +92,27 @@ const colord = (input) => {
92
92
  var Colord = class {
93
93
  parsed;
94
94
  rgb;
95
+ source;
95
96
  constructor(input) {
96
- this.parsed = parse(input)[0];
97
+ const [rgb, format$1] = parse(input);
98
+ this.parsed = rgb;
97
99
  this.rgb = this.parsed || {
98
100
  r: 0,
99
101
  g: 0,
100
102
  b: 0,
101
103
  alpha: 1
102
104
  };
105
+ if (format$1 && this.parsed) this.source = {
106
+ format: format$1,
107
+ input
108
+ };
109
+ }
110
+ /**
111
+ * Get the original input format if available
112
+ * @internal
113
+ */
114
+ getSource() {
115
+ return this.source;
103
116
  }
104
117
  /**
105
118
  * Returns a boolean indicating whether or not an input has been parsed successfully.
@@ -53,6 +53,10 @@ type AnyColor = string | ObjectColor;
53
53
  type InputObject = Record<string, unknown>;
54
54
  type Format = 'name' | 'hex' | 'rgb' | 'lrgb' | 'hsl' | 'hsv' | 'hwb' | 'xyz' | 'lab' | 'lch' | 'cmyk' | 'oklab' | 'oklch';
55
55
  type Input = string | InputObject;
56
+ interface InputSource {
57
+ format: Format;
58
+ input: Input;
59
+ }
56
60
  type ParseFunction<I extends Input> = (input: I) => RgbColor | null;
57
61
  type Parser<I extends Input> = [ParseFunction<I>, Format];
58
62
  type Parsers = {
@@ -69,7 +73,13 @@ declare const colord: (input: AnyColor | Colord) => Colord;
69
73
  declare class Colord {
70
74
  private readonly parsed;
71
75
  readonly rgb: RgbColor;
76
+ private readonly source?;
72
77
  constructor(input: AnyColor);
78
+ /**
79
+ * Get the original input format if available
80
+ * @internal
81
+ */
82
+ getSource(): InputSource | undefined;
73
83
  /**
74
84
  * Returns a boolean indicating whether or not an input has been parsed successfully.
75
85
  * Note: If parsing is unsuccessful, Colord defaults to black (does not throws an error).
package/dist/colord.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as colord, t as Colord } from "./colord-xpgrVWRV.js";
1
+ import { n as colord, t as Colord } from "./colord-Dc09uNcG.js";
2
2
  export { Colord, colord };
package/dist/colord.js CHANGED
@@ -1,10 +1,10 @@
1
- import "./utils-DajWVr6Z.js";
2
- import "./rgb-DNYno5F7.js";
3
- import { n as colord, t as Colord } from "./colord-C3iU53g-.js";
4
- import "./hsv-BKcGyyrD.js";
5
- import "./manipulate-C3CvrU4m.js";
6
- import "./xyz-CXEZJhV8.js";
7
- import "./lab-B5wAd4fu.js";
8
- import "./get-D0jfz1WU.js";
1
+ import "./utils-CshL9w1R.js";
2
+ import "./rgb-BVkoWOmR.js";
3
+ import { n as colord, t as Colord } from "./colord-CLzIbIN2.js";
4
+ import "./hsv-OOAVcaRH.js";
5
+ import "./manipulate-DCHNBCkU.js";
6
+ import "./xyz-DsYRwYO_.js";
7
+ import "./lab-9NsKpGel.js";
8
+ import "./get-SLuYLSG9.js";
9
9
 
10
10
  export { Colord, colord };
@@ -1,4 +1,4 @@
1
- import { m as Parsers, t as Colord } from "./colord-xpgrVWRV.js";
1
+ import { m as Parsers, t as Colord } from "./colord-Dc09uNcG.js";
2
2
 
3
3
  //#region src/extend.d.ts
4
4
  type Plugin = (ColordClass: typeof Colord, parsers: Parsers) => void;
@@ -1,4 +1,4 @@
1
- import { o as rgbToLinearRgb } from "./rgb-DNYno5F7.js";
1
+ import { o as rgbToLinearRgb } from "./rgb-BVkoWOmR.js";
2
2
 
3
3
  //#region src/shared/get.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { i as isPresent, l as round, n as clampHue, t as clamp, v as ALPHA_PRECISION } from "./utils-DajWVr6Z.js";
1
+ import { i as isPresent, l as round, n as clampHue, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
2
2
 
3
3
  //#region src/models/hsv.ts
4
4
  const clampHsv = (hsv) => ({
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as Format, c as HwbColor, d as LchColor, f as OklabColor, g as XyzColor, h as RgbColor, l as Input, n as colord, o as HslColor, p as OklchColor, r as AnyColor, s as HsvColor, t as Colord, u as LabColor } from "./colord-xpgrVWRV.js";
2
- import { n as extend, t as Plugin } from "./extend-DrPfn2Q1.js";
1
+ import { a as Format, c as HwbColor, d as LchColor, f as OklabColor, g as XyzColor, h as RgbColor, l as Input, n as colord, o as HslColor, p as OklchColor, r as AnyColor, s as HsvColor, t as Colord, u as LabColor } from "./colord-Dc09uNcG.js";
2
+ import { n as extend, t as Plugin } from "./extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/shared/parse.d.ts
5
5
 
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import "./utils-DajWVr6Z.js";
2
- import "./rgb-DNYno5F7.js";
3
- import { a as parsers, i as getFormat, n as colord, r as random, t as Colord } from "./colord-C3iU53g-.js";
4
- import "./hsv-BKcGyyrD.js";
5
- import "./manipulate-C3CvrU4m.js";
6
- import "./xyz-CXEZJhV8.js";
7
- import "./lab-B5wAd4fu.js";
8
- import "./get-D0jfz1WU.js";
1
+ import "./utils-CshL9w1R.js";
2
+ import "./rgb-BVkoWOmR.js";
3
+ import { a as parsers, i as getFormat, n as colord, r as random, t as Colord } from "./colord-CLzIbIN2.js";
4
+ import "./hsv-OOAVcaRH.js";
5
+ import "./manipulate-DCHNBCkU.js";
6
+ import "./xyz-DsYRwYO_.js";
7
+ import "./lab-9NsKpGel.js";
8
+ import "./get-SLuYLSG9.js";
9
9
 
10
10
  //#region src/extend.ts
11
11
  const activePlugins = [];
@@ -0,0 +1,219 @@
1
+ import { a as mul3x3, d as M_D65_TO_D50, i as isPresent, l as round, o as parseAlpha, t as clamp, u as M_D50_TO_D65, v as ALPHA_PRECISION, y as D50 } from "./utils-CshL9w1R.js";
2
+ import { n as clampRgb } from "./rgb-BVkoWOmR.js";
3
+ import { a as xyzToRgb, r as rgbToXyz } from "./xyz-DsYRwYO_.js";
4
+
5
+ //#region src/models/lab.ts
6
+ const EPSILON = 216 / 24389;
7
+ const KAPPA = 24389 / 27;
8
+ /**
9
+ * Clamps LAB axis values as defined in CSS Color Level 4 specs.
10
+ * https://www.w3.org/TR/css-color-4/#specifying-lab-lch
11
+ * Note: a and b can theoretically go beyond [-128, 127], extended to [-160, 160] for wider gamut
12
+ */
13
+ const clampLab = (lab) => {
14
+ const { l, a, b, alpha } = lab;
15
+ return {
16
+ l: clamp(l, 0, 100),
17
+ a: clamp(a, -160, 160),
18
+ b: clamp(b, -160, 160),
19
+ alpha: clamp(alpha)
20
+ };
21
+ };
22
+ const roundLab = (lab) => {
23
+ const { l, a, b, alpha } = lab;
24
+ return {
25
+ l: round(l, 3),
26
+ a: round(a, 3),
27
+ b: round(b, 3),
28
+ alpha: round(alpha, ALPHA_PRECISION)
29
+ };
30
+ };
31
+ /**
32
+ * Performs RGB → CIEXYZ → LAB color conversion
33
+ * https://www.w3.org/TR/css-color-4/#color-conversion-code
34
+ */
35
+ const rgbToLab = (rgb) => {
36
+ const xyzD65 = rgbToXyz(rgb);
37
+ const { alpha } = xyzD65;
38
+ const [x, y, z] = mul3x3(M_D65_TO_D50, [
39
+ xyzD65.x,
40
+ xyzD65.y,
41
+ xyzD65.z
42
+ ]);
43
+ return xyzToLabRaw({
44
+ x,
45
+ y,
46
+ z,
47
+ alpha
48
+ });
49
+ };
50
+ /**
51
+ * Convert LAB to RGB without gamut checking (internal helper)
52
+ */
53
+ const labToRgbDirect = (lab) => {
54
+ const xyzD50 = labToXyzRaw(lab);
55
+ const [x, y, z] = mul3x3(M_D50_TO_D65, [
56
+ xyzD50.x,
57
+ xyzD50.y,
58
+ xyzD50.z
59
+ ]);
60
+ return xyzToRgb({
61
+ x,
62
+ y,
63
+ z,
64
+ alpha: lab.alpha
65
+ });
66
+ };
67
+ /**
68
+ * Check if RGB is within sRGB gamut
69
+ * Note: RGB values are in [0, 255] range
70
+ */
71
+ const isRgbInGamut = (rgb, epsilon = .01) => {
72
+ return rgb.r >= -epsilon && rgb.r <= 255 + epsilon && rgb.g >= -epsilon && rgb.g <= 255 + epsilon && rgb.b >= -epsilon && rgb.b <= 255 + epsilon;
73
+ };
74
+ /**
75
+ * Binary search to find maximum chroma that fits in sRGB gamut for LAB
76
+ * Similar to LCH's findGamutChroma
77
+ * @param l - Lightness (0-100)
78
+ * @param hue - Hue angle in radians (atan2(b, a))
79
+ * @param alpha - Alpha (0-1)
80
+ * @returns Maximum chroma that fits in sRGB gamut
81
+ */
82
+ const findGamutChromaForLab = (l, hue, alpha) => {
83
+ let min = 0;
84
+ let max = 150;
85
+ const epsilon = .01;
86
+ if (isRgbInGamut(labToRgbDirect({
87
+ l,
88
+ a: max * Math.cos(hue),
89
+ b: max * Math.sin(hue),
90
+ alpha
91
+ }))) return max;
92
+ while (max - min > epsilon) {
93
+ const mid = (min + max) / 2;
94
+ if (isRgbInGamut(labToRgbDirect({
95
+ l,
96
+ a: mid * Math.cos(hue),
97
+ b: mid * Math.sin(hue),
98
+ alpha
99
+ }))) min = mid;
100
+ else max = mid;
101
+ }
102
+ return min;
103
+ };
104
+ /**
105
+ * Performs LAB → CIEXYZ → RGB color conversion with gamut mapping
106
+ * https://www.w3.org/TR/css-color-4/#color-conversion-code
107
+ *
108
+ * Similar to LCH, if the color is out of sRGB gamut, reduce chroma
109
+ * while preserving lightness and hue
110
+ */
111
+ const labToRgb = (lab) => {
112
+ const { l, a, b, alpha } = lab;
113
+ let rgb = labToRgbDirect(lab);
114
+ if (!isRgbInGamut(rgb)) {
115
+ if (Math.sqrt(a * a + b * b) > 1e-4) {
116
+ const hue = Math.atan2(b, a);
117
+ const maxChroma = findGamutChromaForLab(l, hue, alpha);
118
+ rgb = labToRgbDirect({
119
+ l,
120
+ a: maxChroma * Math.cos(hue),
121
+ b: maxChroma * Math.sin(hue),
122
+ alpha
123
+ });
124
+ }
125
+ }
126
+ return clampRgb(rgb);
127
+ };
128
+ function xyzToLabRaw(xyz) {
129
+ const { x, y, z, alpha } = xyz;
130
+ const xr = x / D50.x;
131
+ const yr = y / D50.y;
132
+ const zr = z / D50.z;
133
+ const f = (t) => t > EPSILON ? Math.cbrt(t) : (KAPPA * t + 16) / 116;
134
+ const fx = f(xr);
135
+ const fy = f(yr);
136
+ const fz = f(zr);
137
+ return {
138
+ l: 116 * fy - 16,
139
+ a: 500 * (fx - fy),
140
+ b: 200 * (fy - fz),
141
+ alpha
142
+ };
143
+ }
144
+ function labToXyzRaw(lab) {
145
+ const { l, a, b, alpha } = lab;
146
+ const fy = (l + 16) / 116;
147
+ const fx = a / 500 + fy;
148
+ const fz = fy - b / 200;
149
+ const f3 = (t) => t * t * t > EPSILON ? t * t * t : (116 * t - 16) / KAPPA;
150
+ const xr = f3(fx);
151
+ const yr = l > KAPPA * EPSILON ? ((l + 16) / 116) ** 3 : l / KAPPA;
152
+ const zr = f3(fz);
153
+ return {
154
+ x: xr * D50.x,
155
+ y: yr * D50.y,
156
+ z: zr * D50.z,
157
+ alpha
158
+ };
159
+ }
160
+ const parseLab = ({ l, a, b, alpha = 1 }) => {
161
+ if (!isPresent(l) || !isPresent(a) || !isPresent(b)) return null;
162
+ return clampLab({
163
+ l: Number(l),
164
+ a: Number(a),
165
+ b: Number(b),
166
+ alpha: Number(alpha)
167
+ });
168
+ };
169
+ const parseLabToRgb = (input) => {
170
+ const lab = parseLab(input);
171
+ if (!lab) return null;
172
+ return labToRgb(lab);
173
+ };
174
+ /**
175
+ * Parsing syntax: lab(L a b [/ alpha])
176
+ * - L: <number|percentage> [0,100]
177
+ * - a: <number> [-125,125]
178
+ * - b: <number> [-125,125]
179
+ * - alpha: <number|percentage> [0,1]
180
+ */
181
+ const labMatcher = /^lab\(\s*([+-]?[\d.]+)%?\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(?:\s*\/\s*([+-]?[\d.]+%?))?\s*\)$/i;
182
+ const parseLabString = (input) => {
183
+ const match = labMatcher.exec(input);
184
+ if (!match) return null;
185
+ const [_, l, a, b, alpha] = match;
186
+ return clampLab({
187
+ l: Number.parseFloat(l),
188
+ a: Number.parseFloat(a),
189
+ b: Number.parseFloat(b),
190
+ alpha: parseAlpha(alpha)
191
+ });
192
+ };
193
+ const parseLabStringToRgb = (input) => {
194
+ const lab = parseLabString(input);
195
+ if (!lab) return null;
196
+ return labToRgb(lab);
197
+ };
198
+ const toLabString = (lab) => {
199
+ const { l, a, b, alpha } = roundLab(lab);
200
+ return alpha < 1 ? `lab(${l}% ${a} ${b} / ${alpha})` : `lab(${l}% ${a} ${b})`;
201
+ };
202
+ const rgbToLabString = (rgb) => {
203
+ return toLabString(rgbToLab(rgb));
204
+ };
205
+ const parseLabBySource = (source) => {
206
+ if (!source || source.format !== "lab") return null;
207
+ const { input } = source;
208
+ if (typeof input === "string") return parseLabString(input);
209
+ if (typeof input === "object") return parseLab(input);
210
+ return null;
211
+ };
212
+ const toLabStringBySource = (source) => {
213
+ const lab = parseLabBySource(source);
214
+ if (!lab) return null;
215
+ return toLabString(lab);
216
+ };
217
+
218
+ //#endregion
219
+ export { parseLabToRgb as a, roundLab as c, parseLabStringToRgb as i, toLabStringBySource as l, labToRgb as n, rgbToLab as o, parseLabBySource as r, rgbToLabString as s, clampLab as t };
@@ -1,6 +1,6 @@
1
- import { i as isPresent, l as round, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "./utils-DajWVr6Z.js";
2
- import { r as rgbToHsv, t as hsvToRgb } from "./hsv-BKcGyyrD.js";
3
- import { a as rgbToLab, n as labToRgb, t as clampLab } from "./lab-B5wAd4fu.js";
1
+ import { i as isPresent, l as round, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
2
+ import { r as rgbToHsv, t as hsvToRgb } from "./hsv-OOAVcaRH.js";
3
+ import { n as labToRgb, o as rgbToLab, t as clampLab } from "./lab-9NsKpGel.js";
4
4
 
5
5
  //#region src/models/hsl.ts
6
6
  const clampHsl = (hsl) => {
@@ -1,5 +1,5 @@
1
- import { r as AnyColor } from "../colord-xpgrVWRV.js";
2
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { r as AnyColor } from "../colord-Dc09uNcG.js";
2
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/plugins/a11y.d.ts
5
5
  interface ReadabilityOptions {
@@ -1,6 +1,6 @@
1
- import { l as round, r as floor } from "../utils-DajWVr6Z.js";
2
- import "../rgb-DNYno5F7.js";
3
- import { i as getLuminance, n as getContrast } from "../get-D0jfz1WU.js";
1
+ import { l as round, r as floor } from "../utils-CshL9w1R.js";
2
+ import "../rgb-BVkoWOmR.js";
3
+ import { i as getLuminance, n as getContrast } from "../get-SLuYLSG9.js";
4
4
 
5
5
  //#region src/plugins/a11y.ts
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { i as CmykColor } from "../colord-xpgrVWRV.js";
2
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { i as CmykColor } from "../colord-Dc09uNcG.js";
2
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/plugins/cmyk.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -1,4 +1,4 @@
1
- import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "../utils-DajWVr6Z.js";
1
+ import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "../utils-CshL9w1R.js";
2
2
 
3
3
  //#region src/models/cmyk.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
2
2
 
3
3
  //#region src/plugins/harmonies.d.ts
4
4
  type HarmonyType = 'analogous' | 'complementary' | 'double-split-complementary' | 'rectangle' | 'split-complementary' | 'tetradic' | 'triadic';
@@ -1,5 +1,5 @@
1
- import { c as HwbColor } from "../colord-xpgrVWRV.js";
2
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { c as HwbColor } from "../colord-Dc09uNcG.js";
2
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/plugins/hwb.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -1,5 +1,5 @@
1
- import { i as isPresent, l as round, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "../utils-DajWVr6Z.js";
2
- import { r as rgbToHsv, t as hsvToRgb } from "../hsv-BKcGyyrD.js";
1
+ import { i as isPresent, l as round, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "../utils-CshL9w1R.js";
2
+ import { r as rgbToHsv, t as hsvToRgb } from "../hsv-OOAVcaRH.js";
3
3
 
4
4
  //#region src/models/hwb.ts
5
5
  const clampHwb = (hwb) => {
@@ -1,5 +1,5 @@
1
- import { r as AnyColor, u as LabColor } from "../colord-xpgrVWRV.js";
2
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { r as AnyColor, u as LabColor } from "../colord-Dc09uNcG.js";
2
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/plugins/lab.d.ts
5
5
  declare module '@soybeanjs/colord' {
@@ -9,6 +9,10 @@ declare module '@soybeanjs/colord' {
9
9
  * The object always includes `alpha` value [0, 1].
10
10
  */
11
11
  toLab(): LabColor;
12
+ /**
13
+ * Converts a color to CIELAB color space and returns a string.
14
+ */
15
+ toLabString(): string;
12
16
  /**
13
17
  * Calculates the perceived color difference for two colors according to
14
18
  * [Delta E2000](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000).
@@ -1,8 +1,8 @@
1
- import { l as round, t as clamp } from "../utils-DajWVr6Z.js";
2
- import "../rgb-DNYno5F7.js";
3
- import "../xyz-CXEZJhV8.js";
4
- import { a as rgbToLab, i as parseLabString, o as roundLab, r as parseLab } from "../lab-B5wAd4fu.js";
5
- import { r as getDeltaE2000 } from "../get-D0jfz1WU.js";
1
+ import { l as round, t as clamp } from "../utils-CshL9w1R.js";
2
+ import "../rgb-BVkoWOmR.js";
3
+ import "../xyz-DsYRwYO_.js";
4
+ import { a as parseLabToRgb, c as roundLab, i as parseLabStringToRgb, l as toLabStringBySource, o as rgbToLab, r as parseLabBySource, s as rgbToLabString } from "../lab-9NsKpGel.js";
5
+ import { r as getDeltaE2000 } from "../get-SLuYLSG9.js";
6
6
 
7
7
  //#region src/plugins/lab.ts
8
8
  /**
@@ -11,14 +11,17 @@ import { r as getDeltaE2000 } from "../get-D0jfz1WU.js";
11
11
  */
12
12
  const labPlugin = (ColordClass, parsers) => {
13
13
  ColordClass.prototype.toLab = function toLab() {
14
- return roundLab(rgbToLab(this.rgb));
14
+ return roundLab(parseLabBySource(this.getSource()) || rgbToLab(this.rgb));
15
+ };
16
+ ColordClass.prototype.toLabString = function toLabString() {
17
+ return toLabStringBySource(this.getSource()) || rgbToLabString(this.rgb);
15
18
  };
16
19
  ColordClass.prototype.delta = function delta(color = "#FFF") {
17
20
  const compared = color instanceof ColordClass ? color : new ColordClass(color);
18
21
  return clamp(round(getDeltaE2000(this.toLab(), compared.toLab()) / 100, 3));
19
22
  };
20
- parsers.object.push([parseLab, "lab"]);
21
- parsers.string.push([parseLabString, "lab"]);
23
+ parsers.string.push([parseLabStringToRgb, "lab"]);
24
+ parsers.object.push([parseLabToRgb, "lab"]);
22
25
  };
23
26
  var lab_default = labPlugin;
24
27
 
@@ -1,5 +1,5 @@
1
- import { d as LchColor } from "../colord-xpgrVWRV.js";
2
- import { t as Plugin } from "../extend-DrPfn2Q1.js";
1
+ import { d as LchColor } from "../colord-Dc09uNcG.js";
2
+ import { t as Plugin } from "../extend-D_jQFvDk.js";
3
3
 
4
4
  //#region src/plugins/lch.d.ts
5
5
  declare module '@soybeanjs/colord' {