@zag-js/color-utils 2.0.0-next.2 → 2.0.0-next.4

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 (62) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs +11 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.mjs +13 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.mjs +8 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +15 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.mjs +10 -0
  9. package/dist/area-gradient.d.mts +9 -11
  10. package/dist/area-gradient.d.ts +9 -11
  11. package/dist/area-gradient.js +58 -89
  12. package/dist/area-gradient.mjs +54 -77
  13. package/dist/color-format-gradient.d.mts +76 -78
  14. package/dist/color-format-gradient.d.ts +76 -78
  15. package/dist/color-format-gradient.js +118 -185
  16. package/dist/color-format-gradient.mjs +104 -152
  17. package/dist/color.d.mts +20 -23
  18. package/dist/color.d.ts +20 -23
  19. package/dist/color.js +57 -83
  20. package/dist/color.mjs +53 -60
  21. package/dist/gamut.d.mts +2 -5
  22. package/dist/gamut.d.ts +2 -5
  23. package/dist/gamut.js +12 -34
  24. package/dist/gamut.mjs +8 -11
  25. package/dist/hsb-color.d.mts +37 -40
  26. package/dist/hsb-color.d.ts +37 -40
  27. package/dist/hsb-color.js +164 -200
  28. package/dist/hsb-color.mjs +158 -175
  29. package/dist/hsl-color.d.mts +33 -36
  30. package/dist/hsl-color.d.ts +33 -36
  31. package/dist/hsl-color.js +139 -168
  32. package/dist/hsl-color.mjs +132 -142
  33. package/dist/index.d.mts +8 -7
  34. package/dist/index.d.ts +8 -7
  35. package/dist/index.js +23 -60
  36. package/dist/index.mjs +2 -28
  37. package/dist/native-color.d.mts +1 -3
  38. package/dist/native-color.d.ts +1 -3
  39. package/dist/native-color.js +16 -39
  40. package/dist/native-color.mjs +12 -16
  41. package/dist/oklab-color.d.mts +57 -60
  42. package/dist/oklab-color.d.ts +57 -60
  43. package/dist/oklab-color.js +363 -379
  44. package/dist/oklab-color.mjs +353 -350
  45. package/dist/oklab-math.d.mts +26 -28
  46. package/dist/oklab-math.d.ts +26 -28
  47. package/dist/oklab-math.js +123 -142
  48. package/dist/oklab-math.mjs +108 -108
  49. package/dist/parse-color.d.mts +3 -6
  50. package/dist/parse-color.d.ts +3 -6
  51. package/dist/parse-color.js +22 -48
  52. package/dist/parse-color.mjs +13 -20
  53. package/dist/rgb-color.d.mts +33 -36
  54. package/dist/rgb-color.d.ts +33 -36
  55. package/dist/rgb-color.js +182 -220
  56. package/dist/rgb-color.mjs +174 -193
  57. package/dist/types.d.mts +82 -84
  58. package/dist/types.d.ts +82 -84
  59. package/dist/types.js +4 -18
  60. package/dist/types.mjs +1 -0
  61. package/package.json +3 -3
  62. package/dist/chunk-QZ7TP4HQ.mjs +0 -7
@@ -1,199 +1,180 @@
1
- import {
2
- __publicField
3
- } from "./chunk-QZ7TP4HQ.mjs";
4
-
5
- // src/rgb-color.ts
6
- import { clampValue, toFixedNumber } from "@zag-js/utils";
7
1
  import { Color } from "./color.mjs";
8
2
  import { HSBColor } from "./hsb-color.mjs";
9
3
  import { HSLColor } from "./hsl-color.mjs";
10
4
  import { linearRgbToOklab, srgbToLinearRgb } from "./oklab-math.mjs";
11
5
  import { OklabColor } from "./oklab-color.mjs";
12
- var HEX_COLOR_REGEX = /^#[\da-f]+$/i;
13
- var RGB_COLOR_REGEX = /^rgba?\((.*)\)$/;
14
- var HEX_STARTING_REGEX = /[^#]/gi;
15
- var _RGBColor = class _RGBColor extends Color {
16
- constructor(red, green, blue, alpha) {
17
- super();
18
- __publicField(this, "red", red);
19
- __publicField(this, "green", green);
20
- __publicField(this, "blue", blue);
21
- __publicField(this, "alpha", alpha);
22
- }
23
- static parse(value) {
24
- let colors = [];
25
- if (HEX_COLOR_REGEX.test(value) && [4, 5, 7, 9].includes(value.length)) {
26
- const values = (value.length < 6 ? value.replace(HEX_STARTING_REGEX, "$&$&") : value).slice(1).split("");
27
- while (values.length > 0) {
28
- colors.push(parseInt(values.splice(0, 2).join(""), 16));
29
- }
30
- colors[3] = colors[3] !== void 0 ? colors[3] / 255 : void 0;
31
- }
32
- const match = value.match(RGB_COLOR_REGEX);
33
- if (match?.[1]) {
34
- colors = match[1].split(",").map((value2) => Number(value2.trim())).map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1));
35
- }
36
- return colors.length < 3 ? void 0 : new _RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);
37
- }
38
- toString(format = "css") {
39
- switch (format) {
40
- case "hex":
41
- return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
42
- case "hexa":
43
- 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();
44
- case "rgb":
45
- return `rgb(${this.red}, ${this.green}, ${this.blue})`;
46
- case "css":
47
- case "rgba":
48
- return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
49
- case "hsl":
50
- return this.toHSL().toString("hsl");
51
- case "hsb":
52
- return this.toHSB().toString("hsb");
53
- default:
54
- return this.toFormat(format).toString(format);
55
- }
56
- }
57
- toFormat(format) {
58
- switch (format) {
59
- case "rgba":
60
- return this;
61
- case "hsba":
62
- return this.toHSB();
63
- case "hsla":
64
- return this.toHSL();
65
- case "oklab": {
66
- const lin = srgbToLinearRgb(this.red, this.green, this.blue);
67
- const { L, a, b } = linearRgbToOklab(lin);
68
- return new OklabColor(L, a, b, toFixedNumber(this.alpha, 4));
69
- }
70
- case "oklch":
71
- return this.toFormat("oklab").toFormat("oklch");
72
- default:
73
- throw new Error("Unsupported color conversion: rgb -> " + format);
74
- }
75
- }
76
- toHexInt() {
77
- return this.red << 16 | this.green << 8 | this.blue;
78
- }
79
- /**
80
- * Converts an RGB color value to HSB.
81
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
82
- * @returns An HSBColor object.
83
- */
84
- toHSB() {
85
- const red = this.red / 255;
86
- const green = this.green / 255;
87
- const blue = this.blue / 255;
88
- const min = Math.min(red, green, blue);
89
- const brightness = Math.max(red, green, blue);
90
- const chroma = brightness - min;
91
- const saturation = brightness === 0 ? 0 : chroma / brightness;
92
- let hue = 0;
93
- if (chroma !== 0) {
94
- switch (brightness) {
95
- case red:
96
- hue = (green - blue) / chroma + (green < blue ? 6 : 0);
97
- break;
98
- case green:
99
- hue = (blue - red) / chroma + 2;
100
- break;
101
- case blue:
102
- hue = (red - green) / chroma + 4;
103
- break;
104
- }
105
- hue /= 6;
106
- }
107
- return new HSBColor(
108
- toFixedNumber(hue * 360, 2),
109
- toFixedNumber(saturation * 100, 2),
110
- toFixedNumber(brightness * 100, 2),
111
- toFixedNumber(this.alpha, 2)
112
- );
113
- }
114
- /**
115
- * Converts an RGB color value to HSL.
116
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
117
- * @returns An HSLColor object.
118
- */
119
- toHSL() {
120
- const red = this.red / 255;
121
- const green = this.green / 255;
122
- const blue = this.blue / 255;
123
- const min = Math.min(red, green, blue);
124
- const max = Math.max(red, green, blue);
125
- const lightness = (max + min) / 2;
126
- const chroma = max - min;
127
- let hue = -1;
128
- let saturation = -1;
129
- if (chroma === 0) {
130
- hue = saturation = 0;
131
- } else {
132
- saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min);
133
- switch (max) {
134
- case red:
135
- hue = (green - blue) / chroma + (green < blue ? 6 : 0);
136
- break;
137
- case green:
138
- hue = (blue - red) / chroma + 2;
139
- break;
140
- case blue:
141
- hue = (red - green) / chroma + 4;
142
- break;
143
- }
144
- hue /= 6;
145
- }
146
- return new HSLColor(
147
- toFixedNumber(hue * 360, 2),
148
- toFixedNumber(saturation * 100, 2),
149
- toFixedNumber(lightness * 100, 2),
150
- toFixedNumber(this.alpha, 2)
151
- );
152
- }
153
- clone() {
154
- return new _RGBColor(this.red, this.green, this.blue, this.alpha);
155
- }
156
- getChannelFormatOptions(channel) {
157
- switch (channel) {
158
- case "red":
159
- case "green":
160
- case "blue":
161
- return { style: "decimal" };
162
- case "alpha":
163
- return { style: "percent" };
164
- default:
165
- throw new Error("Unknown color channel: " + channel);
166
- }
167
- }
168
- formatChannelValue(channel, locale) {
169
- let options = this.getChannelFormatOptions(channel);
170
- let value = this.getChannelValue(channel);
171
- return new Intl.NumberFormat(locale, options).format(value);
172
- }
173
- getChannelRange(channel) {
174
- switch (channel) {
175
- case "red":
176
- case "green":
177
- case "blue":
178
- return { minValue: 0, maxValue: 255, step: 1, pageSize: 17 };
179
- case "alpha":
180
- return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
181
- default:
182
- throw new Error("Unknown color channel: " + channel);
183
- }
184
- }
185
- toJSON() {
186
- return { r: this.red, g: this.green, b: this.blue, a: this.alpha };
187
- }
188
- getFormat() {
189
- return "rgba";
190
- }
191
- getChannels() {
192
- return _RGBColor.colorChannels;
193
- }
194
- };
195
- __publicField(_RGBColor, "colorChannels", ["red", "green", "blue"]);
196
- var RGBColor = _RGBColor;
197
- export {
198
- RGBColor
6
+ import _defineProperty from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs";
7
+ import { clampValue, toFixedNumber } from "@zag-js/utils";
8
+ // src/rgb-color.ts
9
+ const HEX_COLOR_REGEX = /^#[\da-f]+$/i;
10
+ const RGB_COLOR_REGEX = /^rgba?\((.*)\)$/;
11
+ const HEX_STARTING_REGEX = /[^#]/gi;
12
+ var RGBColor = class RGBColor extends Color {
13
+ constructor(red, green, blue, alpha) {
14
+ super();
15
+ this.red = red;
16
+ this.green = green;
17
+ this.blue = blue;
18
+ this.alpha = alpha;
19
+ }
20
+ static parse(value) {
21
+ let colors = [];
22
+ if (HEX_COLOR_REGEX.test(value) && [
23
+ 4,
24
+ 5,
25
+ 7,
26
+ 9
27
+ ].includes(value.length)) {
28
+ const values = (value.length < 6 ? value.replace(HEX_STARTING_REGEX, "$&$&") : value).slice(1).split("");
29
+ while (values.length > 0) colors.push(parseInt(values.splice(0, 2).join(""), 16));
30
+ colors[3] = colors[3] !== void 0 ? colors[3] / 255 : void 0;
31
+ }
32
+ const match = value.match(RGB_COLOR_REGEX);
33
+ if (match?.[1]) colors = match[1].split(",").map((value) => Number(value.trim())).map((num, i) => clampValue(num, 0, i < 3 ? 255 : 1));
34
+ return colors.length < 3 ? void 0 : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);
35
+ }
36
+ toString(format = "css") {
37
+ switch (format) {
38
+ case "hex": return "#" + (this.red.toString(16).padStart(2, "0") + this.green.toString(16).padStart(2, "0") + this.blue.toString(16).padStart(2, "0")).toUpperCase();
39
+ case "hexa": 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();
40
+ case "rgb": return `rgb(${this.red}, ${this.green}, ${this.blue})`;
41
+ case "css":
42
+ case "rgba": return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
43
+ case "hsl": return this.toHSL().toString("hsl");
44
+ case "hsb": return this.toHSB().toString("hsb");
45
+ default: return this.toFormat(format).toString(format);
46
+ }
47
+ }
48
+ toFormat(format) {
49
+ switch (format) {
50
+ case "rgba": return this;
51
+ case "hsba": return this.toHSB();
52
+ case "hsla": return this.toHSL();
53
+ case "oklab": {
54
+ const lin = srgbToLinearRgb(this.red, this.green, this.blue);
55
+ const { L, a, b } = linearRgbToOklab(lin);
56
+ return new OklabColor(L, a, b, toFixedNumber(this.alpha, 4));
57
+ }
58
+ case "oklch": return this.toFormat("oklab").toFormat("oklch");
59
+ default: throw new Error("Unsupported color conversion: rgb -> " + format);
60
+ }
61
+ }
62
+ toHexInt() {
63
+ return this.red << 16 | this.green << 8 | this.blue;
64
+ }
65
+ /**
66
+ * Converts an RGB color value to HSB.
67
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
68
+ * @returns An HSBColor object.
69
+ */
70
+ toHSB() {
71
+ const red = this.red / 255;
72
+ const green = this.green / 255;
73
+ const blue = this.blue / 255;
74
+ const min = Math.min(red, green, blue);
75
+ const brightness = Math.max(red, green, blue);
76
+ const chroma = brightness - min;
77
+ const saturation = brightness === 0 ? 0 : chroma / brightness;
78
+ let hue = 0;
79
+ if (chroma !== 0) {
80
+ switch (brightness) {
81
+ case red:
82
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
83
+ break;
84
+ case green:
85
+ hue = (blue - red) / chroma + 2;
86
+ break;
87
+ case blue: hue = (red - green) / chroma + 4;
88
+ }
89
+ hue /= 6;
90
+ }
91
+ return new HSBColor(toFixedNumber(hue * 360, 2), toFixedNumber(saturation * 100, 2), toFixedNumber(brightness * 100, 2), toFixedNumber(this.alpha, 2));
92
+ }
93
+ /**
94
+ * Converts an RGB color value to HSL.
95
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.
96
+ * @returns An HSLColor object.
97
+ */
98
+ toHSL() {
99
+ const red = this.red / 255;
100
+ const green = this.green / 255;
101
+ const blue = this.blue / 255;
102
+ const min = Math.min(red, green, blue);
103
+ const max = Math.max(red, green, blue);
104
+ const lightness = (max + min) / 2;
105
+ const chroma = max - min;
106
+ let hue = -1;
107
+ let saturation = -1;
108
+ if (chroma === 0) hue = saturation = 0;
109
+ else {
110
+ saturation = chroma / (lightness < .5 ? max + min : 2 - max - min);
111
+ switch (max) {
112
+ case red:
113
+ hue = (green - blue) / chroma + (green < blue ? 6 : 0);
114
+ break;
115
+ case green:
116
+ hue = (blue - red) / chroma + 2;
117
+ break;
118
+ case blue: hue = (red - green) / chroma + 4;
119
+ }
120
+ hue /= 6;
121
+ }
122
+ return new HSLColor(toFixedNumber(hue * 360, 2), toFixedNumber(saturation * 100, 2), toFixedNumber(lightness * 100, 2), toFixedNumber(this.alpha, 2));
123
+ }
124
+ clone() {
125
+ return new RGBColor(this.red, this.green, this.blue, this.alpha);
126
+ }
127
+ getChannelFormatOptions(channel) {
128
+ switch (channel) {
129
+ case "red":
130
+ case "green":
131
+ case "blue": return { style: "decimal" };
132
+ case "alpha": return { style: "percent" };
133
+ default: throw new Error("Unknown color channel: " + channel);
134
+ }
135
+ }
136
+ formatChannelValue(channel, locale) {
137
+ let options = this.getChannelFormatOptions(channel);
138
+ let value = this.getChannelValue(channel);
139
+ return new Intl.NumberFormat(locale, options).format(value);
140
+ }
141
+ getChannelRange(channel) {
142
+ switch (channel) {
143
+ case "red":
144
+ case "green":
145
+ case "blue": return {
146
+ minValue: 0,
147
+ maxValue: 255,
148
+ step: 1,
149
+ pageSize: 17
150
+ };
151
+ case "alpha": return {
152
+ minValue: 0,
153
+ maxValue: 1,
154
+ step: .01,
155
+ pageSize: .1
156
+ };
157
+ default: throw new Error("Unknown color channel: " + channel);
158
+ }
159
+ }
160
+ toJSON() {
161
+ return {
162
+ r: this.red,
163
+ g: this.green,
164
+ b: this.blue,
165
+ a: this.alpha
166
+ };
167
+ }
168
+ getFormat() {
169
+ return "rgba";
170
+ }
171
+ getChannels() {
172
+ return RGBColor.colorChannels;
173
+ }
199
174
  };
175
+ _defineProperty(RGBColor, "colorChannels", [
176
+ "red",
177
+ "green",
178
+ "blue"
179
+ ]);
180
+ export { RGBColor };
package/dist/types.d.mts CHANGED
@@ -1,87 +1,85 @@
1
- type ColorHexFormat = "hex" | "hexa";
2
- type ColorFormat = "rgba" | "hsla" | "hsba" | "oklab" | "oklch";
3
- type ColorStringFormat = ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css";
4
- type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "a" | "b" | "chroma" | "alpha";
5
- interface Color2DAxes {
6
- xChannel: ColorChannel;
7
- yChannel: ColorChannel;
1
+ export type ColorHexFormat = "hex" | "hexa";
2
+ export type ColorFormat = "rgba" | "hsla" | "hsba" | "oklab" | "oklch";
3
+ export type ColorStringFormat = ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css";
4
+ export type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "a" | "b" | "chroma" | "alpha";
5
+ export interface Color2DAxes {
6
+ xChannel: ColorChannel;
7
+ yChannel: ColorChannel;
8
8
  }
9
- interface ColorAxes extends Color2DAxes {
10
- zChannel: ColorChannel;
9
+ export interface ColorAxes extends Color2DAxes {
10
+ zChannel: ColorChannel;
11
11
  }
12
- interface ColorChannelRange {
13
- /** The minimum value of the color channel. */
14
- minValue: number;
15
- /** The maximum value of the color channel. */
16
- maxValue: number;
17
- /** The step value of the color channel, used when incrementing and decrementing. */
18
- step: number;
19
- /** The page step value of the color channel, used when incrementing and decrementing. */
20
- pageSize: number;
12
+ export interface ColorChannelRange {
13
+ /** The minimum value of the color channel. */
14
+ minValue: number;
15
+ /** The maximum value of the color channel. */
16
+ maxValue: number;
17
+ /** The step value of the color channel, used when incrementing and decrementing. */
18
+ step: number;
19
+ /** The page step value of the color channel, used when incrementing and decrementing. */
20
+ pageSize: number;
21
21
  }
22
- interface ColorType {
23
- /** Converts the color to the given color format, and returns a new Color object. */
24
- toFormat(format: ColorFormat): ColorType;
25
- /** Converts the color to a JSON object. */
26
- toJSON(): Record<string, number>;
27
- /** Converts the color to a string in the given format. Defaults to CSS format. */
28
- toString(format?: ColorStringFormat): string;
29
- /** Converts the color to hex, and returns an integer representation. */
30
- toHexInt(): number;
31
- /**
32
- * Returns the numeric value for a given channel.
33
- * Throws an error if the channel is unsupported in the current color format.
34
- */
35
- getChannelValue(channel: ColorChannel): number;
36
- /**
37
- * Sets the numeric value for a given channel, and returns a new Color object.
38
- * Throws an error if the channel is unsupported in the current color format.
39
- */
40
- withChannelValue(channel: ColorChannel, value: number): ColorType;
41
- /**
42
- * Returns the formatted value for a given channel.
43
- */
44
- formatChannelValue(channel: ColorChannel, locale: string): string;
45
- /**
46
- * Returns the minimum, maximum, and step values for a given channel.
47
- */
48
- getChannelRange(channel: ColorChannel): ColorChannelRange;
49
- /**
50
- * Returns the color space, 'rgb', 'hsb' or 'hsl', for the current color.
51
- */
52
- getFormat(): ColorFormat;
53
- /**
54
- * Returns the color space axes, xChannel, yChannel, zChannel.
55
- */
56
- getColorAxes(xyChannels: Color2DAxes): ColorAxes;
57
- /**
58
- * Returns an array of the color channels within the current color space space.
59
- */
60
- getChannels(): [ColorChannel, ColorChannel, ColorChannel];
61
- /**
62
- * Returns a new Color object with the same values as the current color.
63
- */
64
- clone(): ColorType;
65
- /**
66
- * Whether the color is equal to another color.
67
- */
68
- isEqual(color: ColorType): boolean;
69
- /**
70
- * Increments the color channel by the given step size, and returns a new Color object.
71
- */
72
- incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
73
- /**
74
- * Decrements the color channel by the given step size, and returns a new Color object.
75
- */
76
- decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
77
- /**
78
- * Returns the color channel value as a percentage of the channel range.
79
- */
80
- getChannelValuePercent(channel: ColorChannel, value?: number): number;
81
- /**
82
- * Returns the color channel value for a given percentage of the channel range.
83
- */
84
- getChannelPercentValue(channel: ColorChannel, percent: number): number;
85
- }
86
-
87
- export type { Color2DAxes, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorHexFormat, ColorStringFormat, ColorType };
22
+ export interface ColorType {
23
+ /** Converts the color to the given color format, and returns a new Color object. */
24
+ toFormat(format: ColorFormat): ColorType;
25
+ /** Converts the color to a JSON object. */
26
+ toJSON(): Record<string, number>;
27
+ /** Converts the color to a string in the given format. Defaults to CSS format. */
28
+ toString(format?: ColorStringFormat): string;
29
+ /** Converts the color to hex, and returns an integer representation. */
30
+ toHexInt(): number;
31
+ /**
32
+ * Returns the numeric value for a given channel.
33
+ * Throws an error if the channel is unsupported in the current color format.
34
+ */
35
+ getChannelValue(channel: ColorChannel): number;
36
+ /**
37
+ * Sets the numeric value for a given channel, and returns a new Color object.
38
+ * Throws an error if the channel is unsupported in the current color format.
39
+ */
40
+ withChannelValue(channel: ColorChannel, value: number): ColorType;
41
+ /**
42
+ * Returns the formatted value for a given channel.
43
+ */
44
+ formatChannelValue(channel: ColorChannel, locale: string): string;
45
+ /**
46
+ * Returns the minimum, maximum, and step values for a given channel.
47
+ */
48
+ getChannelRange(channel: ColorChannel): ColorChannelRange;
49
+ /**
50
+ * Returns the color space, 'rgb', 'hsb' or 'hsl', for the current color.
51
+ */
52
+ getFormat(): ColorFormat;
53
+ /**
54
+ * Returns the color space axes, xChannel, yChannel, zChannel.
55
+ */
56
+ getColorAxes(xyChannels: Color2DAxes): ColorAxes;
57
+ /**
58
+ * Returns an array of the color channels within the current color space space.
59
+ */
60
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel];
61
+ /**
62
+ * Returns a new Color object with the same values as the current color.
63
+ */
64
+ clone(): ColorType;
65
+ /**
66
+ * Whether the color is equal to another color.
67
+ */
68
+ isEqual(color: ColorType): boolean;
69
+ /**
70
+ * Increments the color channel by the given step size, and returns a new Color object.
71
+ */
72
+ incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
73
+ /**
74
+ * Decrements the color channel by the given step size, and returns a new Color object.
75
+ */
76
+ decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
77
+ /**
78
+ * Returns the color channel value as a percentage of the channel range.
79
+ */
80
+ getChannelValuePercent(channel: ColorChannel, value?: number): number;
81
+ /**
82
+ * Returns the color channel value for a given percentage of the channel range.
83
+ */
84
+ getChannelPercentValue(channel: ColorChannel, percent: number): number;
85
+ }