@zag-js/color-utils 1.34.1 → 1.35.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.
Files changed (42) hide show
  1. package/dist/area-gradient.d.mts +15 -0
  2. package/dist/area-gradient.d.ts +15 -0
  3. package/dist/area-gradient.js +87 -0
  4. package/dist/area-gradient.mjs +74 -0
  5. package/dist/chunk-QZ7TP4HQ.mjs +7 -0
  6. package/dist/color-format-gradient.d.mts +68 -0
  7. package/dist/color-format-gradient.d.ts +68 -0
  8. package/dist/color-format-gradient.js +164 -0
  9. package/dist/color-format-gradient.mjs +133 -0
  10. package/dist/color.d.mts +23 -0
  11. package/dist/color.d.ts +23 -0
  12. package/dist/color.js +87 -0
  13. package/dist/color.mjs +64 -0
  14. package/dist/hsb-color.d.mts +35 -0
  15. package/dist/hsb-color.d.ts +35 -0
  16. package/dist/hsb-color.js +165 -0
  17. package/dist/hsb-color.mjs +142 -0
  18. package/dist/hsl-color.d.mts +36 -0
  19. package/dist/hsl-color.d.ts +36 -0
  20. package/dist/hsl-color.js +167 -0
  21. package/dist/hsl-color.mjs +143 -0
  22. package/dist/index.d.mts +4 -121
  23. package/dist/index.d.ts +4 -121
  24. package/dist/index.js +37 -721
  25. package/dist/index.mjs +11 -716
  26. package/dist/native-color.d.mts +3 -0
  27. package/dist/native-color.d.ts +3 -0
  28. package/dist/native-color.js +41 -0
  29. package/dist/native-color.mjs +18 -0
  30. package/dist/parse-color.d.mts +6 -0
  31. package/dist/parse-color.d.ts +6 -0
  32. package/dist/parse-color.js +50 -0
  33. package/dist/parse-color.mjs +26 -0
  34. package/dist/rgb-color.d.mts +36 -0
  35. package/dist/rgb-color.d.ts +36 -0
  36. package/dist/rgb-color.js +213 -0
  37. package/dist/rgb-color.mjs +190 -0
  38. package/dist/types.d.mts +87 -0
  39. package/dist/types.d.ts +87 -0
  40. package/dist/types.js +18 -0
  41. package/dist/types.mjs +0 -0
  42. package/package.json +2 -2
@@ -0,0 +1,167 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/hsl-color.ts
23
+ var hsl_color_exports = {};
24
+ __export(hsl_color_exports, {
25
+ HSLColor: () => HSLColor,
26
+ HSL_REGEX: () => HSL_REGEX
27
+ });
28
+ module.exports = __toCommonJS(hsl_color_exports);
29
+ var import_utils = require("@zag-js/utils");
30
+ var import_color = require("./color.cjs");
31
+ var import_hsb_color = require("./hsb-color.cjs");
32
+ var import_rgb_color = require("./rgb-color.cjs");
33
+ 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+)?)\)/;
34
+ var _HSLColor = class _HSLColor extends import_color.Color {
35
+ constructor(hue, saturation, lightness, alpha) {
36
+ super();
37
+ this.hue = hue;
38
+ this.saturation = saturation;
39
+ this.lightness = lightness;
40
+ this.alpha = alpha;
41
+ }
42
+ static parse(value) {
43
+ let m;
44
+ if (m = value.match(HSL_REGEX)) {
45
+ const [h, s, l, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
46
+ return new _HSLColor((0, import_utils.mod)(h, 360), (0, import_utils.clampValue)(s, 0, 100), (0, import_utils.clampValue)(l, 0, 100), (0, import_utils.clampValue)(a ?? 1, 0, 1));
47
+ }
48
+ }
49
+ toString(format = "css") {
50
+ switch (format) {
51
+ case "hex":
52
+ return this.toRGB().toString("hex");
53
+ case "hexa":
54
+ return this.toRGB().toString("hexa");
55
+ case "hsl":
56
+ return `hsl(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.lightness, 2)}%)`;
57
+ case "css":
58
+ case "hsla":
59
+ return `hsla(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.lightness, 2)}%, ${this.alpha})`;
60
+ case "hsb":
61
+ return this.toHSB().toString("hsb");
62
+ case "rgb":
63
+ return this.toRGB().toString("rgb");
64
+ default:
65
+ return this.toFormat(format).toString(format);
66
+ }
67
+ }
68
+ toFormat(format) {
69
+ switch (format) {
70
+ case "hsla":
71
+ return this;
72
+ case "hsba":
73
+ return this.toHSB();
74
+ case "rgba":
75
+ return this.toRGB();
76
+ default:
77
+ throw new Error("Unsupported color conversion: hsl -> " + format);
78
+ }
79
+ }
80
+ /**
81
+ * Converts a HSL color to HSB.
82
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
83
+ * @returns An HSBColor object.
84
+ */
85
+ toHSB() {
86
+ let saturation = this.saturation / 100;
87
+ let lightness = this.lightness / 100;
88
+ let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
89
+ saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
90
+ return new import_hsb_color.HSBColor(
91
+ (0, import_utils.toFixedNumber)(this.hue, 2),
92
+ (0, import_utils.toFixedNumber)(saturation * 100, 2),
93
+ (0, import_utils.toFixedNumber)(brightness * 100, 2),
94
+ (0, import_utils.toFixedNumber)(this.alpha, 2)
95
+ );
96
+ }
97
+ /**
98
+ * Converts a HSL color to RGB.
99
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
100
+ * @returns An RGBColor object.
101
+ */
102
+ toRGB() {
103
+ let hue = this.hue;
104
+ let saturation = this.saturation / 100;
105
+ let lightness = this.lightness / 100;
106
+ let a = saturation * Math.min(lightness, 1 - lightness);
107
+ let fn = (n, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
108
+ return new import_rgb_color.RGBColor(
109
+ Math.round(fn(0) * 255),
110
+ Math.round(fn(8) * 255),
111
+ Math.round(fn(4) * 255),
112
+ (0, import_utils.toFixedNumber)(this.alpha, 2)
113
+ );
114
+ }
115
+ clone() {
116
+ return new _HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
117
+ }
118
+ getChannelFormatOptions(channel) {
119
+ switch (channel) {
120
+ case "hue":
121
+ return { style: "unit", unit: "degree", unitDisplay: "narrow" };
122
+ case "saturation":
123
+ case "lightness":
124
+ case "alpha":
125
+ return { style: "percent" };
126
+ default:
127
+ throw new Error("Unknown color channel: " + channel);
128
+ }
129
+ }
130
+ formatChannelValue(channel, locale) {
131
+ let options = this.getChannelFormatOptions(channel);
132
+ let value = this.getChannelValue(channel);
133
+ if (channel === "saturation" || channel === "lightness") {
134
+ value /= 100;
135
+ }
136
+ return new Intl.NumberFormat(locale, options).format(value);
137
+ }
138
+ getChannelRange(channel) {
139
+ switch (channel) {
140
+ case "hue":
141
+ return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
142
+ case "saturation":
143
+ case "lightness":
144
+ return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
145
+ case "alpha":
146
+ return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
147
+ default:
148
+ throw new Error("Unknown color channel: " + channel);
149
+ }
150
+ }
151
+ toJSON() {
152
+ return { h: this.hue, s: this.saturation, l: this.lightness, a: this.alpha };
153
+ }
154
+ getFormat() {
155
+ return "hsla";
156
+ }
157
+ getChannels() {
158
+ return _HSLColor.colorChannels;
159
+ }
160
+ };
161
+ __publicField(_HSLColor, "colorChannels", ["hue", "saturation", "lightness"]);
162
+ var HSLColor = _HSLColor;
163
+ // Annotate the CommonJS export names for ESM import in node:
164
+ 0 && (module.exports = {
165
+ HSLColor,
166
+ HSL_REGEX
167
+ });
@@ -0,0 +1,143 @@
1
+ import {
2
+ __publicField
3
+ } from "./chunk-QZ7TP4HQ.mjs";
4
+
5
+ // src/hsl-color.ts
6
+ import { clampValue, mod, toFixedNumber } from "@zag-js/utils";
7
+ import { Color } from "./color.mjs";
8
+ import { HSBColor } from "./hsb-color.mjs";
9
+ import { RGBColor } from "./rgb-color.mjs";
10
+ 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+)?)\)/;
11
+ var _HSLColor = class _HSLColor extends Color {
12
+ constructor(hue, saturation, lightness, alpha) {
13
+ super();
14
+ this.hue = hue;
15
+ this.saturation = saturation;
16
+ this.lightness = lightness;
17
+ this.alpha = alpha;
18
+ }
19
+ static parse(value) {
20
+ let m;
21
+ if (m = value.match(HSL_REGEX)) {
22
+ const [h, s, l, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
23
+ return new _HSLColor(mod(h, 360), clampValue(s, 0, 100), clampValue(l, 0, 100), clampValue(a ?? 1, 0, 1));
24
+ }
25
+ }
26
+ toString(format = "css") {
27
+ switch (format) {
28
+ case "hex":
29
+ return this.toRGB().toString("hex");
30
+ case "hexa":
31
+ return this.toRGB().toString("hexa");
32
+ case "hsl":
33
+ return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`;
34
+ case "css":
35
+ case "hsla":
36
+ return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;
37
+ case "hsb":
38
+ return this.toHSB().toString("hsb");
39
+ case "rgb":
40
+ return this.toRGB().toString("rgb");
41
+ default:
42
+ return this.toFormat(format).toString(format);
43
+ }
44
+ }
45
+ toFormat(format) {
46
+ switch (format) {
47
+ case "hsla":
48
+ return this;
49
+ case "hsba":
50
+ return this.toHSB();
51
+ case "rgba":
52
+ return this.toRGB();
53
+ default:
54
+ throw new Error("Unsupported color conversion: hsl -> " + format);
55
+ }
56
+ }
57
+ /**
58
+ * Converts a HSL color to HSB.
59
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.
60
+ * @returns An HSBColor object.
61
+ */
62
+ toHSB() {
63
+ let saturation = this.saturation / 100;
64
+ let lightness = this.lightness / 100;
65
+ let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);
66
+ saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);
67
+ return new HSBColor(
68
+ toFixedNumber(this.hue, 2),
69
+ toFixedNumber(saturation * 100, 2),
70
+ toFixedNumber(brightness * 100, 2),
71
+ toFixedNumber(this.alpha, 2)
72
+ );
73
+ }
74
+ /**
75
+ * Converts a HSL color to RGB.
76
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.
77
+ * @returns An RGBColor object.
78
+ */
79
+ toRGB() {
80
+ let hue = this.hue;
81
+ let saturation = this.saturation / 100;
82
+ let lightness = this.lightness / 100;
83
+ let a = saturation * Math.min(lightness, 1 - lightness);
84
+ let fn = (n, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
85
+ return new RGBColor(
86
+ Math.round(fn(0) * 255),
87
+ Math.round(fn(8) * 255),
88
+ Math.round(fn(4) * 255),
89
+ toFixedNumber(this.alpha, 2)
90
+ );
91
+ }
92
+ clone() {
93
+ return new _HSLColor(this.hue, this.saturation, this.lightness, this.alpha);
94
+ }
95
+ getChannelFormatOptions(channel) {
96
+ switch (channel) {
97
+ case "hue":
98
+ return { style: "unit", unit: "degree", unitDisplay: "narrow" };
99
+ case "saturation":
100
+ case "lightness":
101
+ case "alpha":
102
+ return { style: "percent" };
103
+ default:
104
+ throw new Error("Unknown color channel: " + channel);
105
+ }
106
+ }
107
+ formatChannelValue(channel, locale) {
108
+ let options = this.getChannelFormatOptions(channel);
109
+ let value = this.getChannelValue(channel);
110
+ if (channel === "saturation" || channel === "lightness") {
111
+ value /= 100;
112
+ }
113
+ return new Intl.NumberFormat(locale, options).format(value);
114
+ }
115
+ getChannelRange(channel) {
116
+ switch (channel) {
117
+ case "hue":
118
+ return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
119
+ case "saturation":
120
+ case "lightness":
121
+ return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
122
+ case "alpha":
123
+ return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
124
+ default:
125
+ throw new Error("Unknown color channel: " + channel);
126
+ }
127
+ }
128
+ toJSON() {
129
+ return { h: this.hue, s: this.saturation, l: this.lightness, a: this.alpha };
130
+ }
131
+ getFormat() {
132
+ return "hsla";
133
+ }
134
+ getChannels() {
135
+ return _HSLColor.colorChannels;
136
+ }
137
+ };
138
+ __publicField(_HSLColor, "colorChannels", ["hue", "saturation", "lightness"]);
139
+ var HSLColor = _HSLColor;
140
+ export {
141
+ HSLColor,
142
+ HSL_REGEX
143
+ };
package/dist/index.d.mts CHANGED
@@ -1,121 +1,4 @@
1
- type ColorHexFormat = "hex" | "hexa";
2
- type ColorFormat = "rgba" | "hsla" | "hsba";
3
- type ColorStringFormat = ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css";
4
- type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha";
5
- interface Color2DAxes {
6
- xChannel: ColorChannel;
7
- yChannel: ColorChannel;
8
- }
9
- interface ColorAxes extends Color2DAxes {
10
- zChannel: ColorChannel;
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;
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
- declare abstract class Color implements ColorType {
88
- abstract toFormat(format: ColorFormat): ColorType;
89
- abstract toJSON(): Record<string, number>;
90
- abstract toString(format?: ColorStringFormat): string;
91
- abstract clone(): ColorType;
92
- abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
93
- abstract getFormat(): ColorFormat;
94
- abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
95
- abstract formatChannelValue(channel: ColorChannel, locale: string): string;
96
- toHexInt(): number;
97
- getChannelValue(channel: ColorChannel): number;
98
- getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
99
- getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
100
- withChannelValue(channel: ColorChannel, value: number): ColorType;
101
- getColorAxes(xyChannels: Color2DAxes): ColorAxes;
102
- incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
103
- decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
104
- isEqual(color: ColorType): boolean;
105
- }
106
-
107
- interface GradientOptions {
108
- xChannel: ColorChannel;
109
- yChannel: ColorChannel;
110
- dir?: "rtl" | "ltr" | undefined;
111
- }
112
- interface GradientStyles {
113
- areaStyles: Record<string, string>;
114
- areaGradientStyles: Record<string, string>;
115
- }
116
- declare function getColorAreaGradient(color: Color, options: GradientOptions): GradientStyles;
117
-
118
- declare const parseColor: (value: string) => ColorType;
119
- declare const normalizeColor: (v: string | ColorType) => ColorType;
120
-
121
- export { Color, type ColorAxes, type ColorChannel, type ColorChannelRange, type ColorFormat, type ColorStringFormat, type ColorType, getColorAreaGradient, normalizeColor, parseColor };
1
+ export { getColorAreaGradient } from './area-gradient.mjs';
2
+ export { Color } from './color.mjs';
3
+ export { normalizeColor, parseColor } from './parse-color.mjs';
4
+ export { ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from './types.mjs';
package/dist/index.d.ts CHANGED
@@ -1,121 +1,4 @@
1
- type ColorHexFormat = "hex" | "hexa";
2
- type ColorFormat = "rgba" | "hsla" | "hsba";
3
- type ColorStringFormat = ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css";
4
- type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha";
5
- interface Color2DAxes {
6
- xChannel: ColorChannel;
7
- yChannel: ColorChannel;
8
- }
9
- interface ColorAxes extends Color2DAxes {
10
- zChannel: ColorChannel;
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;
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
- declare abstract class Color implements ColorType {
88
- abstract toFormat(format: ColorFormat): ColorType;
89
- abstract toJSON(): Record<string, number>;
90
- abstract toString(format?: ColorStringFormat): string;
91
- abstract clone(): ColorType;
92
- abstract getChannelRange(channel: ColorChannel): ColorChannelRange;
93
- abstract getFormat(): ColorFormat;
94
- abstract getChannels(): [ColorChannel, ColorChannel, ColorChannel];
95
- abstract formatChannelValue(channel: ColorChannel, locale: string): string;
96
- toHexInt(): number;
97
- getChannelValue(channel: ColorChannel): number;
98
- getChannelValuePercent(channel: ColorChannel, valueToCheck?: number): number;
99
- getChannelPercentValue(channel: ColorChannel, percentToCheck: number): number;
100
- withChannelValue(channel: ColorChannel, value: number): ColorType;
101
- getColorAxes(xyChannels: Color2DAxes): ColorAxes;
102
- incrementChannel(channel: ColorChannel, stepSize: number): ColorType;
103
- decrementChannel(channel: ColorChannel, stepSize: number): ColorType;
104
- isEqual(color: ColorType): boolean;
105
- }
106
-
107
- interface GradientOptions {
108
- xChannel: ColorChannel;
109
- yChannel: ColorChannel;
110
- dir?: "rtl" | "ltr" | undefined;
111
- }
112
- interface GradientStyles {
113
- areaStyles: Record<string, string>;
114
- areaGradientStyles: Record<string, string>;
115
- }
116
- declare function getColorAreaGradient(color: Color, options: GradientOptions): GradientStyles;
117
-
118
- declare const parseColor: (value: string) => ColorType;
119
- declare const normalizeColor: (v: string | ColorType) => ColorType;
120
-
121
- export { Color, type ColorAxes, type ColorChannel, type ColorChannelRange, type ColorFormat, type ColorStringFormat, type ColorType, getColorAreaGradient, normalizeColor, parseColor };
1
+ export { getColorAreaGradient } from './area-gradient.js';
2
+ export { Color } from './color.js';
3
+ export { normalizeColor, parseColor } from './parse-color.js';
4
+ export { ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from './types.js';