@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
package/dist/gamut.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { ColorType } from './types.js';
2
-
1
+ import { ColorType } from "./types.js";
3
2
  /** Whether the color lies inside the sRGB gamut (checks in linear RGB space, no clamping). */
4
- declare function isInSrgbGamut(color: ColorType): boolean;
5
-
6
- export { isInSrgbGamut };
3
+ export declare function isInSrgbGamut(color: ColorType): boolean;
package/dist/gamut.js CHANGED
@@ -1,37 +1,15 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/gamut.ts
21
- var gamut_exports = {};
22
- __export(gamut_exports, {
23
- isInSrgbGamut: () => isInSrgbGamut
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(gamut_exports);
26
- var import_oklab_math = require("./oklab-math.js");
5
+ const require_oklab_math = require("./oklab-math.js");
6
+ // src/gamut.ts
7
+ /** Whether the color lies inside the sRGB gamut (checks in linear RGB space, no clamping). */
27
8
  function isInSrgbGamut(color) {
28
- const oklab = color.toFormat("oklab");
29
- const L = oklab.getChannelValue("lightness");
30
- const a = oklab.getChannelValue("a");
31
- const b = oklab.getChannelValue("b");
32
- return (0, import_oklab_math.isLinearRgbInSrgbGamut)((0, import_oklab_math.oklabToLinearRgb)(L, a, b));
9
+ const oklab = color.toFormat("oklab");
10
+ const L = oklab.getChannelValue("lightness");
11
+ const a = oklab.getChannelValue("a");
12
+ const b = oklab.getChannelValue("b");
13
+ return require_oklab_math.isLinearRgbInSrgbGamut(require_oklab_math.oklabToLinearRgb(L, a, b));
33
14
  }
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- isInSrgbGamut
37
- });
15
+ exports.isInSrgbGamut = isInSrgbGamut;
package/dist/gamut.mjs CHANGED
@@ -1,14 +1,11 @@
1
- import "./chunk-QZ7TP4HQ.mjs";
2
-
3
- // src/gamut.ts
4
1
  import { isLinearRgbInSrgbGamut, oklabToLinearRgb } from "./oklab-math.mjs";
2
+ // src/gamut.ts
3
+ /** Whether the color lies inside the sRGB gamut (checks in linear RGB space, no clamping). */
5
4
  function isInSrgbGamut(color) {
6
- const oklab = color.toFormat("oklab");
7
- const L = oklab.getChannelValue("lightness");
8
- const a = oklab.getChannelValue("a");
9
- const b = oklab.getChannelValue("b");
10
- return isLinearRgbInSrgbGamut(oklabToLinearRgb(L, a, b));
5
+ const oklab = color.toFormat("oklab");
6
+ const L = oklab.getChannelValue("lightness");
7
+ const a = oklab.getChannelValue("a");
8
+ const b = oklab.getChannelValue("b");
9
+ return isLinearRgbInSrgbGamut(oklabToLinearRgb(L, a, b));
11
10
  }
12
- export {
13
- isInSrgbGamut
14
- };
11
+ export { isInSrgbGamut };
@@ -1,40 +1,37 @@
1
- import { Color } from './color.mjs';
2
- import { ColorStringFormat, ColorFormat, ColorType, ColorChannel, ColorChannelRange } from './types.mjs';
3
-
4
- declare class HSBColor extends Color {
5
- private hue;
6
- private saturation;
7
- private brightness;
8
- private alpha;
9
- constructor(hue: number, saturation: number, brightness: number, alpha: number);
10
- /**
11
- * Create HSBColor from float sRGB values (0-1 range, clamped).
12
- * Higher precision than going through integer RGBColor (0-255).
13
- */
14
- static fromSrgbFloat(r: number, g: number, b: number, alpha: number): HSBColor;
15
- static parse(value: string): HSBColor | void;
16
- toString(format?: ColorStringFormat): string;
17
- toFormat(format: ColorFormat): ColorType;
18
- /**
19
- * Converts a HSB color to HSL.
20
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
21
- * @returns An HSLColor object.
22
- */
23
- private toHSL;
24
- /**
25
- * Converts a HSV color value to RGB.
26
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
27
- * @returns An RGBColor object.
28
- */
29
- private toRGB;
30
- clone(): ColorType;
31
- getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
32
- formatChannelValue(channel: ColorChannel, locale: string): string;
33
- getChannelRange(channel: ColorChannel): ColorChannelRange;
34
- toJSON(): Record<"h" | "s" | "b" | "a", number>;
35
- getFormat(): ColorFormat;
36
- private static colorChannels;
37
- getChannels(): [ColorChannel, ColorChannel, ColorChannel];
38
- }
39
-
40
- export { HSBColor };
1
+ import { Color } from "./color.mjs";
2
+ import { ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from "./types.mjs";
3
+ export declare class HSBColor extends Color {
4
+ private hue;
5
+ private saturation;
6
+ private brightness;
7
+ private alpha;
8
+ constructor(hue: number, saturation: number, brightness: number, alpha: number);
9
+ /**
10
+ * Create HSBColor from float sRGB values (0-1 range, clamped).
11
+ * Higher precision than going through integer RGBColor (0-255).
12
+ */
13
+ static fromSrgbFloat(r: number, g: number, b: number, alpha: number): HSBColor;
14
+ static parse(value: string): HSBColor | void;
15
+ toString(format?: ColorStringFormat): string;
16
+ toFormat(format: ColorFormat): ColorType;
17
+ /**
18
+ * Converts a HSB color to HSL.
19
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
20
+ * @returns An HSLColor object.
21
+ */
22
+ private toHSL;
23
+ /**
24
+ * Converts a HSV color value to RGB.
25
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
26
+ * @returns An RGBColor object.
27
+ */
28
+ private toRGB;
29
+ clone(): ColorType;
30
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
31
+ formatChannelValue(channel: ColorChannel, locale: string): string;
32
+ getChannelRange(channel: ColorChannel): ColorChannelRange;
33
+ toJSON(): Record<"h" | "s" | "b" | "a", number>;
34
+ getFormat(): ColorFormat;
35
+ private static colorChannels;
36
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel];
37
+ }
@@ -1,40 +1,37 @@
1
- import { Color } from './color.js';
2
- import { ColorStringFormat, ColorFormat, ColorType, ColorChannel, ColorChannelRange } from './types.js';
3
-
4
- declare class HSBColor extends Color {
5
- private hue;
6
- private saturation;
7
- private brightness;
8
- private alpha;
9
- constructor(hue: number, saturation: number, brightness: number, alpha: number);
10
- /**
11
- * Create HSBColor from float sRGB values (0-1 range, clamped).
12
- * Higher precision than going through integer RGBColor (0-255).
13
- */
14
- static fromSrgbFloat(r: number, g: number, b: number, alpha: number): HSBColor;
15
- static parse(value: string): HSBColor | void;
16
- toString(format?: ColorStringFormat): string;
17
- toFormat(format: ColorFormat): ColorType;
18
- /**
19
- * Converts a HSB color to HSL.
20
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
21
- * @returns An HSLColor object.
22
- */
23
- private toHSL;
24
- /**
25
- * Converts a HSV color value to RGB.
26
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
27
- * @returns An RGBColor object.
28
- */
29
- private toRGB;
30
- clone(): ColorType;
31
- getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
32
- formatChannelValue(channel: ColorChannel, locale: string): string;
33
- getChannelRange(channel: ColorChannel): ColorChannelRange;
34
- toJSON(): Record<"h" | "s" | "b" | "a", number>;
35
- getFormat(): ColorFormat;
36
- private static colorChannels;
37
- getChannels(): [ColorChannel, ColorChannel, ColorChannel];
38
- }
39
-
40
- export { HSBColor };
1
+ import { Color } from "./color.js";
2
+ import { ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from "./types.js";
3
+ export declare class HSBColor extends Color {
4
+ private hue;
5
+ private saturation;
6
+ private brightness;
7
+ private alpha;
8
+ constructor(hue: number, saturation: number, brightness: number, alpha: number);
9
+ /**
10
+ * Create HSBColor from float sRGB values (0-1 range, clamped).
11
+ * Higher precision than going through integer RGBColor (0-255).
12
+ */
13
+ static fromSrgbFloat(r: number, g: number, b: number, alpha: number): HSBColor;
14
+ static parse(value: string): HSBColor | void;
15
+ toString(format?: ColorStringFormat): string;
16
+ toFormat(format: ColorFormat): ColorType;
17
+ /**
18
+ * Converts a HSB color to HSL.
19
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
20
+ * @returns An HSLColor object.
21
+ */
22
+ private toHSL;
23
+ /**
24
+ * Converts a HSV color value to RGB.
25
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
26
+ * @returns An RGBColor object.
27
+ */
28
+ private toRGB;
29
+ clone(): ColorType;
30
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
31
+ formatChannelValue(channel: ColorChannel, locale: string): string;
32
+ getChannelRange(channel: ColorChannel): ColorChannelRange;
33
+ toJSON(): Record<"h" | "s" | "b" | "a", number>;
34
+ getFormat(): ColorFormat;
35
+ private static colorChannels;
36
+ getChannels(): [ColorChannel, ColorChannel, ColorChannel];
37
+ }
package/dist/hsb-color.js CHANGED
@@ -1,202 +1,166 @@
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/hsb-color.ts
23
- var hsb_color_exports = {};
24
- __export(hsb_color_exports, {
25
- HSBColor: () => HSBColor
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
26
4
  });
27
- module.exports = __toCommonJS(hsb_color_exports);
28
- var import_utils = require("@zag-js/utils");
29
- var import_color = require("./color.js");
30
- var import_hsl_color = require("./hsl-color.js");
31
- var import_rgb_color = require("./rgb-color.js");
32
- 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+)?)\)/;
33
- var _HSBColor = class _HSBColor extends import_color.Color {
34
- constructor(hue, saturation, brightness, alpha) {
35
- super();
36
- __publicField(this, "hue", hue);
37
- __publicField(this, "saturation", saturation);
38
- __publicField(this, "brightness", brightness);
39
- __publicField(this, "alpha", alpha);
40
- }
41
- /**
42
- * Create HSBColor from float sRGB values (0-1 range, clamped).
43
- * Higher precision than going through integer RGBColor (0-255).
44
- */
45
- static fromSrgbFloat(r, g, b, alpha) {
46
- const rc = Math.max(0, Math.min(1, r));
47
- const gc = Math.max(0, Math.min(1, g));
48
- const bc = Math.max(0, Math.min(1, b));
49
- const min = Math.min(rc, gc, bc);
50
- const brightness = Math.max(rc, gc, bc);
51
- const chroma = brightness - min;
52
- const saturation = brightness === 0 ? 0 : chroma / brightness;
53
- let hue = 0;
54
- if (chroma !== 0) {
55
- switch (brightness) {
56
- case rc:
57
- hue = (gc - bc) / chroma + (gc < bc ? 6 : 0);
58
- break;
59
- case gc:
60
- hue = (bc - rc) / chroma + 2;
61
- break;
62
- case bc:
63
- hue = (rc - gc) / chroma + 4;
64
- break;
65
- }
66
- hue /= 6;
67
- }
68
- return new _HSBColor(
69
- (0, import_utils.toFixedNumber)(hue * 360, 4),
70
- (0, import_utils.toFixedNumber)(saturation * 100, 4),
71
- (0, import_utils.toFixedNumber)(brightness * 100, 4),
72
- (0, import_utils.toFixedNumber)(alpha, 4)
73
- );
74
- }
75
- static parse(value) {
76
- let m;
77
- if (m = value.match(HSB_REGEX)) {
78
- const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
79
- return new _HSBColor((0, import_utils.mod)(h, 360), (0, import_utils.clampValue)(s, 0, 100), (0, import_utils.clampValue)(b, 0, 100), (0, import_utils.clampValue)(a ?? 1, 0, 1));
80
- }
81
- }
82
- toString(format = "css") {
83
- switch (format) {
84
- case "css":
85
- return this.toHSL().toString("css");
86
- case "hex":
87
- return this.toRGB().toString("hex");
88
- case "hexa":
89
- return this.toRGB().toString("hexa");
90
- case "hsb":
91
- return `hsb(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.brightness, 2)}%)`;
92
- case "hsba":
93
- return `hsba(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
94
- case "hsl":
95
- return this.toHSL().toString("hsl");
96
- case "rgb":
97
- return this.toRGB().toString("rgb");
98
- default:
99
- return this.toFormat(format).toString(format);
100
- }
101
- }
102
- toFormat(format) {
103
- switch (format) {
104
- case "hsba":
105
- return this;
106
- case "hsla":
107
- return this.toHSL();
108
- case "rgba":
109
- return this.toRGB();
110
- case "oklab":
111
- case "oklch":
112
- return this.toRGB().toFormat(format);
113
- default:
114
- throw new Error("Unsupported color conversion: hsb -> " + format);
115
- }
116
- }
117
- /**
118
- * Converts a HSB color to HSL.
119
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
120
- * @returns An HSLColor object.
121
- */
122
- toHSL() {
123
- let saturation = this.saturation / 100;
124
- let brightness = this.brightness / 100;
125
- let lightness = brightness * (1 - saturation / 2);
126
- saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
127
- return new import_hsl_color.HSLColor(
128
- (0, import_utils.toFixedNumber)(this.hue, 2),
129
- (0, import_utils.toFixedNumber)(saturation * 100, 2),
130
- (0, import_utils.toFixedNumber)(lightness * 100, 2),
131
- (0, import_utils.toFixedNumber)(this.alpha, 2)
132
- );
133
- }
134
- /**
135
- * Converts a HSV color value to RGB.
136
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
137
- * @returns An RGBColor object.
138
- */
139
- toRGB() {
140
- let hue = this.hue;
141
- let saturation = this.saturation / 100;
142
- let brightness = this.brightness / 100;
143
- let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
144
- return new import_rgb_color.RGBColor(
145
- Math.round(fn(5) * 255),
146
- Math.round(fn(3) * 255),
147
- Math.round(fn(1) * 255),
148
- (0, import_utils.toFixedNumber)(this.alpha, 2)
149
- );
150
- }
151
- clone() {
152
- return new _HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
153
- }
154
- getChannelFormatOptions(channel) {
155
- switch (channel) {
156
- case "hue":
157
- return { style: "unit", unit: "degree", unitDisplay: "narrow" };
158
- case "saturation":
159
- case "brightness":
160
- case "alpha":
161
- return { style: "percent" };
162
- default:
163
- throw new Error("Unknown color channel: " + channel);
164
- }
165
- }
166
- formatChannelValue(channel, locale) {
167
- let options = this.getChannelFormatOptions(channel);
168
- let value = this.getChannelValue(channel);
169
- if (channel === "saturation" || channel === "brightness") {
170
- value /= 100;
171
- }
172
- return new Intl.NumberFormat(locale, options).format(value);
173
- }
174
- getChannelRange(channel) {
175
- switch (channel) {
176
- case "hue":
177
- return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
178
- case "saturation":
179
- case "brightness":
180
- return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
181
- case "alpha":
182
- return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
183
- default:
184
- throw new Error("Unknown color channel: " + channel);
185
- }
186
- }
187
- toJSON() {
188
- return { h: this.hue, s: this.saturation, b: this.brightness, a: this.alpha };
189
- }
190
- getFormat() {
191
- return "hsba";
192
- }
193
- getChannels() {
194
- return _HSBColor.colorChannels;
195
- }
5
+ const require_color = require("./color.js");
6
+ const require_hsl_color = require("./hsl-color.js");
7
+ const require_rgb_color = require("./rgb-color.js");
8
+ const require_defineProperty = require("./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js");
9
+ let _zag_js_utils = require("@zag-js/utils");
10
+ // src/hsb-color.ts
11
+ const 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+)?)\)/;
12
+ var HSBColor = class HSBColor extends require_color.Color {
13
+ constructor(hue, saturation, brightness, alpha) {
14
+ super();
15
+ this.hue = hue;
16
+ this.saturation = saturation;
17
+ this.brightness = brightness;
18
+ this.alpha = alpha;
19
+ }
20
+ /**
21
+ * Create HSBColor from float sRGB values (0-1 range, clamped).
22
+ * Higher precision than going through integer RGBColor (0-255).
23
+ */
24
+ static fromSrgbFloat(r, g, b, alpha) {
25
+ const rc = Math.max(0, Math.min(1, r));
26
+ const gc = Math.max(0, Math.min(1, g));
27
+ const bc = Math.max(0, Math.min(1, b));
28
+ const min = Math.min(rc, gc, bc);
29
+ const brightness = Math.max(rc, gc, bc);
30
+ const chroma = brightness - min;
31
+ const saturation = brightness === 0 ? 0 : chroma / brightness;
32
+ let hue = 0;
33
+ if (chroma !== 0) {
34
+ switch (brightness) {
35
+ case rc:
36
+ hue = (gc - bc) / chroma + (gc < bc ? 6 : 0);
37
+ break;
38
+ case gc:
39
+ hue = (bc - rc) / chroma + 2;
40
+ break;
41
+ case bc: hue = (rc - gc) / chroma + 4;
42
+ }
43
+ hue /= 6;
44
+ }
45
+ return new HSBColor((0, _zag_js_utils.toFixedNumber)(hue * 360, 4), (0, _zag_js_utils.toFixedNumber)(saturation * 100, 4), (0, _zag_js_utils.toFixedNumber)(brightness * 100, 4), (0, _zag_js_utils.toFixedNumber)(alpha, 4));
46
+ }
47
+ static parse(value) {
48
+ let m;
49
+ if (m = value.match(HSB_REGEX)) {
50
+ const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
51
+ return new HSBColor((0, _zag_js_utils.mod)(h, 360), (0, _zag_js_utils.clampValue)(s, 0, 100), (0, _zag_js_utils.clampValue)(b, 0, 100), (0, _zag_js_utils.clampValue)(a ?? 1, 0, 1));
52
+ }
53
+ }
54
+ toString(format = "css") {
55
+ switch (format) {
56
+ case "css": return this.toHSL().toString("css");
57
+ case "hex": return this.toRGB().toString("hex");
58
+ case "hexa": return this.toRGB().toString("hexa");
59
+ case "hsb": return `hsb(${this.hue}, ${(0, _zag_js_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, _zag_js_utils.toFixedNumber)(this.brightness, 2)}%)`;
60
+ case "hsba": return `hsba(${this.hue}, ${(0, _zag_js_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, _zag_js_utils.toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
61
+ case "hsl": return this.toHSL().toString("hsl");
62
+ case "rgb": return this.toRGB().toString("rgb");
63
+ default: return this.toFormat(format).toString(format);
64
+ }
65
+ }
66
+ toFormat(format) {
67
+ switch (format) {
68
+ case "hsba": return this;
69
+ case "hsla": return this.toHSL();
70
+ case "rgba": return this.toRGB();
71
+ case "oklab":
72
+ case "oklch": return this.toRGB().toFormat(format);
73
+ default: throw new Error("Unsupported color conversion: hsb -> " + format);
74
+ }
75
+ }
76
+ /**
77
+ * Converts a HSB color to HSL.
78
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
79
+ * @returns An HSLColor object.
80
+ */
81
+ toHSL() {
82
+ let saturation = this.saturation / 100;
83
+ let brightness = this.brightness / 100;
84
+ let lightness = brightness * (1 - saturation / 2);
85
+ saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
86
+ return new require_hsl_color.HSLColor((0, _zag_js_utils.toFixedNumber)(this.hue, 2), (0, _zag_js_utils.toFixedNumber)(saturation * 100, 2), (0, _zag_js_utils.toFixedNumber)(lightness * 100, 2), (0, _zag_js_utils.toFixedNumber)(this.alpha, 2));
87
+ }
88
+ /**
89
+ * Converts a HSV color value to RGB.
90
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
91
+ * @returns An RGBColor object.
92
+ */
93
+ toRGB() {
94
+ let hue = this.hue;
95
+ let saturation = this.saturation / 100;
96
+ let brightness = this.brightness / 100;
97
+ let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
98
+ return new require_rgb_color.RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), (0, _zag_js_utils.toFixedNumber)(this.alpha, 2));
99
+ }
100
+ clone() {
101
+ return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
102
+ }
103
+ getChannelFormatOptions(channel) {
104
+ switch (channel) {
105
+ case "hue": return {
106
+ style: "unit",
107
+ unit: "degree",
108
+ unitDisplay: "narrow"
109
+ };
110
+ case "saturation":
111
+ case "brightness":
112
+ case "alpha": return { style: "percent" };
113
+ default: throw new Error("Unknown color channel: " + channel);
114
+ }
115
+ }
116
+ formatChannelValue(channel, locale) {
117
+ let options = this.getChannelFormatOptions(channel);
118
+ let value = this.getChannelValue(channel);
119
+ if (channel === "saturation" || channel === "brightness") value /= 100;
120
+ return new Intl.NumberFormat(locale, options).format(value);
121
+ }
122
+ getChannelRange(channel) {
123
+ switch (channel) {
124
+ case "hue": return {
125
+ minValue: 0,
126
+ maxValue: 360,
127
+ step: 1,
128
+ pageSize: 15
129
+ };
130
+ case "saturation":
131
+ case "brightness": return {
132
+ minValue: 0,
133
+ maxValue: 100,
134
+ step: 1,
135
+ pageSize: 10
136
+ };
137
+ case "alpha": return {
138
+ minValue: 0,
139
+ maxValue: 1,
140
+ step: .01,
141
+ pageSize: .1
142
+ };
143
+ default: throw new Error("Unknown color channel: " + channel);
144
+ }
145
+ }
146
+ toJSON() {
147
+ return {
148
+ h: this.hue,
149
+ s: this.saturation,
150
+ b: this.brightness,
151
+ a: this.alpha
152
+ };
153
+ }
154
+ getFormat() {
155
+ return "hsba";
156
+ }
157
+ getChannels() {
158
+ return HSBColor.colorChannels;
159
+ }
196
160
  };
197
- __publicField(_HSBColor, "colorChannels", ["hue", "saturation", "brightness"]);
198
- var HSBColor = _HSBColor;
199
- // Annotate the CommonJS export names for ESM import in node:
200
- 0 && (module.exports = {
201
- HSBColor
202
- });
161
+ require_defineProperty.default(HSBColor, "colorChannels", [
162
+ "hue",
163
+ "saturation",
164
+ "brightness"
165
+ ]);
166
+ exports.HSBColor = HSBColor;