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