@zag-js/color-utils 1.47.0 → 1.48.0

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 (50) 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 +53 -84
  12. package/dist/area-gradient.mjs +49 -71
  13. package/dist/color-format-gradient.d.mts +58 -60
  14. package/dist/color-format-gradient.d.ts +58 -60
  15. package/dist/color-format-gradient.js +93 -154
  16. package/dist/color-format-gradient.mjs +81 -123
  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/hsb-color.d.mts +32 -35
  22. package/dist/hsb-color.d.ts +32 -35
  23. package/dist/hsb-color.js +135 -163
  24. package/dist/hsb-color.mjs +129 -138
  25. package/dist/hsl-color.d.mts +33 -36
  26. package/dist/hsl-color.d.ts +33 -36
  27. package/dist/hsl-color.js +137 -165
  28. package/dist/hsl-color.mjs +130 -139
  29. package/dist/index.d.mts +5 -4
  30. package/dist/index.d.ts +5 -4
  31. package/dist/index.js +10 -37
  32. package/dist/index.mjs +1 -9
  33. package/dist/native-color.d.mts +1 -3
  34. package/dist/native-color.d.ts +1 -3
  35. package/dist/native-color.js +16 -39
  36. package/dist/native-color.mjs +12 -16
  37. package/dist/parse-color.d.mts +3 -6
  38. package/dist/parse-color.d.ts +3 -6
  39. package/dist/parse-color.js +21 -47
  40. package/dist/parse-color.mjs +13 -20
  41. package/dist/rgb-color.d.mts +33 -36
  42. package/dist/rgb-color.d.ts +33 -36
  43. package/dist/rgb-color.js +174 -211
  44. package/dist/rgb-color.mjs +168 -186
  45. package/dist/types.d.mts +82 -84
  46. package/dist/types.d.ts +82 -84
  47. package/dist/types.js +4 -18
  48. package/dist/types.mjs +1 -0
  49. package/package.json +4 -4
  50. package/dist/chunk-QZ7TP4HQ.mjs +0 -7
package/dist/hsb-color.js CHANGED
@@ -1,165 +1,137 @@
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
- static parse(value) {
42
- let m;
43
- if (m = value.match(HSB_REGEX)) {
44
- const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
45
- 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));
46
- }
47
- }
48
- toString(format = "css") {
49
- switch (format) {
50
- case "css":
51
- return this.toHSL().toString("css");
52
- case "hex":
53
- return this.toRGB().toString("hex");
54
- case "hexa":
55
- return this.toRGB().toString("hexa");
56
- case "hsb":
57
- return `hsb(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.brightness, 2)}%)`;
58
- case "hsba":
59
- return `hsba(${this.hue}, ${(0, import_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, import_utils.toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
60
- case "hsl":
61
- return this.toHSL().toString("hsl");
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 "hsba":
71
- return this;
72
- case "hsla":
73
- return this.toHSL();
74
- case "rgba":
75
- return this.toRGB();
76
- default:
77
- throw new Error("Unsupported color conversion: hsb -> " + format);
78
- }
79
- }
80
- /**
81
- * Converts a HSB color to HSL.
82
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
83
- * @returns An HSLColor object.
84
- */
85
- toHSL() {
86
- let saturation = this.saturation / 100;
87
- let brightness = this.brightness / 100;
88
- let lightness = brightness * (1 - saturation / 2);
89
- saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
90
- return new import_hsl_color.HSLColor(
91
- (0, import_utils.toFixedNumber)(this.hue, 2),
92
- (0, import_utils.toFixedNumber)(saturation * 100, 2),
93
- (0, import_utils.toFixedNumber)(lightness * 100, 2),
94
- (0, import_utils.toFixedNumber)(this.alpha, 2)
95
- );
96
- }
97
- /**
98
- * Converts a HSV color value to RGB.
99
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
100
- * @returns An RGBColor object.
101
- */
102
- toRGB() {
103
- let hue = this.hue;
104
- let saturation = this.saturation / 100;
105
- let brightness = this.brightness / 100;
106
- let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
107
- return new import_rgb_color.RGBColor(
108
- Math.round(fn(5) * 255),
109
- Math.round(fn(3) * 255),
110
- Math.round(fn(1) * 255),
111
- (0, import_utils.toFixedNumber)(this.alpha, 2)
112
- );
113
- }
114
- clone() {
115
- return new _HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
116
- }
117
- getChannelFormatOptions(channel) {
118
- switch (channel) {
119
- case "hue":
120
- return { style: "unit", unit: "degree", unitDisplay: "narrow" };
121
- case "saturation":
122
- case "brightness":
123
- case "alpha":
124
- return { style: "percent" };
125
- default:
126
- throw new Error("Unknown color channel: " + channel);
127
- }
128
- }
129
- formatChannelValue(channel, locale) {
130
- let options = this.getChannelFormatOptions(channel);
131
- let value = this.getChannelValue(channel);
132
- if (channel === "saturation" || channel === "brightness") {
133
- value /= 100;
134
- }
135
- return new Intl.NumberFormat(locale, options).format(value);
136
- }
137
- getChannelRange(channel) {
138
- switch (channel) {
139
- case "hue":
140
- return { minValue: 0, maxValue: 360, step: 1, pageSize: 15 };
141
- case "saturation":
142
- case "brightness":
143
- return { minValue: 0, maxValue: 100, step: 1, pageSize: 10 };
144
- case "alpha":
145
- return { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 };
146
- default:
147
- throw new Error("Unknown color channel: " + channel);
148
- }
149
- }
150
- toJSON() {
151
- return { h: this.hue, s: this.saturation, b: this.brightness, a: this.alpha };
152
- }
153
- getFormat() {
154
- return "hsba";
155
- }
156
- getChannels() {
157
- return _HSBColor.colorChannels;
158
- }
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
+ static parse(value) {
21
+ let m;
22
+ if (m = value.match(HSB_REGEX)) {
23
+ const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
24
+ 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));
25
+ }
26
+ }
27
+ toString(format = "css") {
28
+ switch (format) {
29
+ case "css": return this.toHSL().toString("css");
30
+ case "hex": return this.toRGB().toString("hex");
31
+ case "hexa": return this.toRGB().toString("hexa");
32
+ case "hsb": return `hsb(${this.hue}, ${(0, _zag_js_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, _zag_js_utils.toFixedNumber)(this.brightness, 2)}%)`;
33
+ case "hsba": return `hsba(${this.hue}, ${(0, _zag_js_utils.toFixedNumber)(this.saturation, 2)}%, ${(0, _zag_js_utils.toFixedNumber)(this.brightness, 2)}%, ${this.alpha})`;
34
+ case "hsl": return this.toHSL().toString("hsl");
35
+ case "rgb": return this.toRGB().toString("rgb");
36
+ default: return this.toFormat(format).toString(format);
37
+ }
38
+ }
39
+ toFormat(format) {
40
+ switch (format) {
41
+ case "hsba": return this;
42
+ case "hsla": return this.toHSL();
43
+ case "rgba": return this.toRGB();
44
+ default: throw new Error("Unsupported color conversion: hsb -> " + format);
45
+ }
46
+ }
47
+ /**
48
+ * Converts a HSB color to HSL.
49
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
50
+ * @returns An HSLColor object.
51
+ */
52
+ toHSL() {
53
+ let saturation = this.saturation / 100;
54
+ let brightness = this.brightness / 100;
55
+ let lightness = brightness * (1 - saturation / 2);
56
+ saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
57
+ 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));
58
+ }
59
+ /**
60
+ * Converts a HSV color value to RGB.
61
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
62
+ * @returns An RGBColor object.
63
+ */
64
+ toRGB() {
65
+ let hue = this.hue;
66
+ let saturation = this.saturation / 100;
67
+ let brightness = this.brightness / 100;
68
+ let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
69
+ 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));
70
+ }
71
+ clone() {
72
+ return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
73
+ }
74
+ getChannelFormatOptions(channel) {
75
+ switch (channel) {
76
+ case "hue": return {
77
+ style: "unit",
78
+ unit: "degree",
79
+ unitDisplay: "narrow"
80
+ };
81
+ case "saturation":
82
+ case "brightness":
83
+ case "alpha": return { style: "percent" };
84
+ default: throw new Error("Unknown color channel: " + channel);
85
+ }
86
+ }
87
+ formatChannelValue(channel, locale) {
88
+ let options = this.getChannelFormatOptions(channel);
89
+ let value = this.getChannelValue(channel);
90
+ if (channel === "saturation" || channel === "brightness") value /= 100;
91
+ return new Intl.NumberFormat(locale, options).format(value);
92
+ }
93
+ getChannelRange(channel) {
94
+ switch (channel) {
95
+ case "hue": return {
96
+ minValue: 0,
97
+ maxValue: 360,
98
+ step: 1,
99
+ pageSize: 15
100
+ };
101
+ case "saturation":
102
+ case "brightness": return {
103
+ minValue: 0,
104
+ maxValue: 100,
105
+ step: 1,
106
+ pageSize: 10
107
+ };
108
+ case "alpha": return {
109
+ minValue: 0,
110
+ maxValue: 1,
111
+ step: .01,
112
+ pageSize: .1
113
+ };
114
+ default: throw new Error("Unknown color channel: " + channel);
115
+ }
116
+ }
117
+ toJSON() {
118
+ return {
119
+ h: this.hue,
120
+ s: this.saturation,
121
+ b: this.brightness,
122
+ a: this.alpha
123
+ };
124
+ }
125
+ getFormat() {
126
+ return "hsba";
127
+ }
128
+ getChannels() {
129
+ return HSBColor.colorChannels;
130
+ }
159
131
  };
160
- __publicField(_HSBColor, "colorChannels", ["hue", "saturation", "brightness"]);
161
- var HSBColor = _HSBColor;
162
- // Annotate the CommonJS export names for ESM import in node:
163
- 0 && (module.exports = {
164
- HSBColor
165
- });
132
+ require_defineProperty.default(HSBColor, "colorChannels", [
133
+ "hue",
134
+ "saturation",
135
+ "brightness"
136
+ ]);
137
+ exports.HSBColor = HSBColor;
@@ -1,142 +1,133 @@
1
- import {
2
- __publicField
3
- } from "./chunk-QZ7TP4HQ.mjs";
4
-
5
- // src/hsb-color.ts
6
- import { clampValue, mod, toFixedNumber } from "@zag-js/utils";
7
1
  import { Color } from "./color.mjs";
8
2
  import { HSLColor } from "./hsl-color.mjs";
9
3
  import { RGBColor } from "./rgb-color.mjs";
10
- 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+)?)\)/;
11
- var _HSBColor = class _HSBColor extends Color {
12
- constructor(hue, saturation, brightness, alpha) {
13
- super();
14
- __publicField(this, "hue", hue);
15
- __publicField(this, "saturation", saturation);
16
- __publicField(this, "brightness", brightness);
17
- __publicField(this, "alpha", alpha);
18
- }
19
- static parse(value) {
20
- let m;
21
- if (m = value.match(HSB_REGEX)) {
22
- const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
23
- return new _HSBColor(mod(h, 360), clampValue(s, 0, 100), clampValue(b, 0, 100), clampValue(a ?? 1, 0, 1));
24
- }
25
- }
26
- toString(format = "css") {
27
- switch (format) {
28
- case "css":
29
- return this.toHSL().toString("css");
30
- case "hex":
31
- return this.toRGB().toString("hex");
32
- case "hexa":
33
- return this.toRGB().toString("hexa");
34
- case "hsb":
35
- return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;
36
- case "hsba":
37
- return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
38
- case "hsl":
39
- return this.toHSL().toString("hsl");
40
- case "rgb":
41
- return this.toRGB().toString("rgb");
42
- default:
43
- return this.toFormat(format).toString(format);
44
- }
45
- }
46
- toFormat(format) {
47
- switch (format) {
48
- case "hsba":
49
- return this;
50
- case "hsla":
51
- return this.toHSL();
52
- case "rgba":
53
- return this.toRGB();
54
- default:
55
- throw new Error("Unsupported color conversion: hsb -> " + format);
56
- }
57
- }
58
- /**
59
- * Converts a HSB color to HSL.
60
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
61
- * @returns An HSLColor object.
62
- */
63
- toHSL() {
64
- let saturation = this.saturation / 100;
65
- let brightness = this.brightness / 100;
66
- let lightness = brightness * (1 - saturation / 2);
67
- saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
68
- return new HSLColor(
69
- toFixedNumber(this.hue, 2),
70
- toFixedNumber(saturation * 100, 2),
71
- toFixedNumber(lightness * 100, 2),
72
- toFixedNumber(this.alpha, 2)
73
- );
74
- }
75
- /**
76
- * Converts a HSV color value to RGB.
77
- * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
78
- * @returns An RGBColor object.
79
- */
80
- toRGB() {
81
- let hue = this.hue;
82
- let saturation = this.saturation / 100;
83
- let brightness = this.brightness / 100;
84
- let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
85
- return new RGBColor(
86
- Math.round(fn(5) * 255),
87
- Math.round(fn(3) * 255),
88
- Math.round(fn(1) * 255),
89
- toFixedNumber(this.alpha, 2)
90
- );
91
- }
92
- clone() {
93
- return new _HSBColor(this.hue, this.saturation, this.brightness, 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 "brightness":
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 === "brightness") {
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 "brightness":
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, b: this.brightness, a: this.alpha };
130
- }
131
- getFormat() {
132
- return "hsba";
133
- }
134
- getChannels() {
135
- return _HSBColor.colorChannels;
136
- }
137
- };
138
- __publicField(_HSBColor, "colorChannels", ["hue", "saturation", "brightness"]);
139
- var HSBColor = _HSBColor;
140
- export {
141
- HSBColor
4
+ import _defineProperty from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.mjs";
5
+ import { clampValue, mod, toFixedNumber } from "@zag-js/utils";
6
+ // src/hsb-color.ts
7
+ 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+)?)\)/;
8
+ var HSBColor = class HSBColor extends Color {
9
+ constructor(hue, saturation, brightness, alpha) {
10
+ super();
11
+ this.hue = hue;
12
+ this.saturation = saturation;
13
+ this.brightness = brightness;
14
+ this.alpha = alpha;
15
+ }
16
+ static parse(value) {
17
+ let m;
18
+ if (m = value.match(HSB_REGEX)) {
19
+ const [h, s, b, a] = (m[1] ?? m[2]).split(",").map((n) => Number(n.trim().replace("%", "")));
20
+ return new HSBColor(mod(h, 360), clampValue(s, 0, 100), clampValue(b, 0, 100), clampValue(a ?? 1, 0, 1));
21
+ }
22
+ }
23
+ toString(format = "css") {
24
+ switch (format) {
25
+ case "css": return this.toHSL().toString("css");
26
+ case "hex": return this.toRGB().toString("hex");
27
+ case "hexa": return this.toRGB().toString("hexa");
28
+ case "hsb": return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;
29
+ case "hsba": return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;
30
+ case "hsl": return this.toHSL().toString("hsl");
31
+ case "rgb": return this.toRGB().toString("rgb");
32
+ default: return this.toFormat(format).toString(format);
33
+ }
34
+ }
35
+ toFormat(format) {
36
+ switch (format) {
37
+ case "hsba": return this;
38
+ case "hsla": return this.toHSL();
39
+ case "rgba": return this.toRGB();
40
+ default: throw new Error("Unsupported color conversion: hsb -> " + format);
41
+ }
42
+ }
43
+ /**
44
+ * Converts a HSB color to HSL.
45
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.
46
+ * @returns An HSLColor object.
47
+ */
48
+ toHSL() {
49
+ let saturation = this.saturation / 100;
50
+ let brightness = this.brightness / 100;
51
+ let lightness = brightness * (1 - saturation / 2);
52
+ saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);
53
+ return new HSLColor(toFixedNumber(this.hue, 2), toFixedNumber(saturation * 100, 2), toFixedNumber(lightness * 100, 2), toFixedNumber(this.alpha, 2));
54
+ }
55
+ /**
56
+ * Converts a HSV color value to RGB.
57
+ * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.
58
+ * @returns An RGBColor object.
59
+ */
60
+ toRGB() {
61
+ let hue = this.hue;
62
+ let saturation = this.saturation / 100;
63
+ let brightness = this.brightness / 100;
64
+ let fn = (n, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);
65
+ return new RGBColor(Math.round(fn(5) * 255), Math.round(fn(3) * 255), Math.round(fn(1) * 255), toFixedNumber(this.alpha, 2));
66
+ }
67
+ clone() {
68
+ return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);
69
+ }
70
+ getChannelFormatOptions(channel) {
71
+ switch (channel) {
72
+ case "hue": return {
73
+ style: "unit",
74
+ unit: "degree",
75
+ unitDisplay: "narrow"
76
+ };
77
+ case "saturation":
78
+ case "brightness":
79
+ case "alpha": return { style: "percent" };
80
+ default: throw new Error("Unknown color channel: " + channel);
81
+ }
82
+ }
83
+ formatChannelValue(channel, locale) {
84
+ let options = this.getChannelFormatOptions(channel);
85
+ let value = this.getChannelValue(channel);
86
+ if (channel === "saturation" || channel === "brightness") value /= 100;
87
+ return new Intl.NumberFormat(locale, options).format(value);
88
+ }
89
+ getChannelRange(channel) {
90
+ switch (channel) {
91
+ case "hue": return {
92
+ minValue: 0,
93
+ maxValue: 360,
94
+ step: 1,
95
+ pageSize: 15
96
+ };
97
+ case "saturation":
98
+ case "brightness": return {
99
+ minValue: 0,
100
+ maxValue: 100,
101
+ step: 1,
102
+ pageSize: 10
103
+ };
104
+ case "alpha": return {
105
+ minValue: 0,
106
+ maxValue: 1,
107
+ step: .01,
108
+ pageSize: .1
109
+ };
110
+ default: throw new Error("Unknown color channel: " + channel);
111
+ }
112
+ }
113
+ toJSON() {
114
+ return {
115
+ h: this.hue,
116
+ s: this.saturation,
117
+ b: this.brightness,
118
+ a: this.alpha
119
+ };
120
+ }
121
+ getFormat() {
122
+ return "hsba";
123
+ }
124
+ getChannels() {
125
+ return HSBColor.colorChannels;
126
+ }
142
127
  };
128
+ _defineProperty(HSBColor, "colorChannels", [
129
+ "hue",
130
+ "saturation",
131
+ "brightness"
132
+ ]);
133
+ export { HSBColor };