@zag-js/color-utils 1.41.0 → 2.0.0-next.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/area-gradient.js +5 -0
- package/dist/area-gradient.mjs +7 -1
- package/dist/color-format-gradient.d.mts +23 -1
- package/dist/color-format-gradient.d.ts +23 -1
- package/dist/color-format-gradient.js +33 -0
- package/dist/color-format-gradient.mjs +31 -0
- package/dist/gamut.d.mts +6 -0
- package/dist/gamut.d.ts +6 -0
- package/dist/gamut.js +37 -0
- package/dist/gamut.mjs +14 -0
- package/dist/hsb-color.d.mts +5 -0
- package/dist/hsb-color.d.ts +5 -0
- package/dist/hsb-color.js +37 -0
- package/dist/hsb-color.mjs +37 -0
- package/dist/hsl-color.js +3 -0
- package/dist/hsl-color.mjs +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +25 -2
- package/dist/index.mjs +22 -1
- package/dist/oklab-color.d.mts +64 -0
- package/dist/oklab-color.d.ts +64 -0
- package/dist/oklab-color.js +396 -0
- package/dist/oklab-color.mjs +370 -0
- package/dist/oklab-math.d.mts +47 -0
- package/dist/oklab-math.d.ts +47 -0
- package/dist/oklab-math.js +167 -0
- package/dist/oklab-math.mjs +133 -0
- package/dist/parse-color.js +2 -1
- package/dist/parse-color.mjs +2 -1
- package/dist/rgb-color.js +9 -0
- package/dist/rgb-color.mjs +9 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
package/dist/area-gradient.js
CHANGED
|
@@ -74,6 +74,11 @@ function getColorAreaGradient(color, options) {
|
|
|
74
74
|
break;
|
|
75
75
|
}
|
|
76
76
|
case "lightness": {
|
|
77
|
+
if (color.getFormat() === "oklab") {
|
|
78
|
+
dir = xChannel === "b";
|
|
79
|
+
background = (0, import_color_format_gradient.generateOKLAB_AB)(orientation, dir, zValue);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
77
82
|
dir = xChannel === "hue";
|
|
78
83
|
background = (0, import_color_format_gradient.generateHSL_L)(orientation, dir, zValue);
|
|
79
84
|
break;
|
package/dist/area-gradient.mjs
CHANGED
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
generateHSL_S,
|
|
11
11
|
generateHSB_S,
|
|
12
12
|
generateHSB_B,
|
|
13
|
-
generateHSL_L
|
|
13
|
+
generateHSL_L,
|
|
14
|
+
generateOKLAB_AB
|
|
14
15
|
} from "./color-format-gradient.mjs";
|
|
15
16
|
function getColorAreaGradient(color, options) {
|
|
16
17
|
const { xChannel, yChannel, dir: dirProp = "ltr" } = options;
|
|
@@ -62,6 +63,11 @@ function getColorAreaGradient(color, options) {
|
|
|
62
63
|
break;
|
|
63
64
|
}
|
|
64
65
|
case "lightness": {
|
|
66
|
+
if (color.getFormat() === "oklab") {
|
|
67
|
+
dir = xChannel === "b";
|
|
68
|
+
background = generateOKLAB_AB(orientation, dir, zValue);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
65
71
|
dir = xChannel === "hue";
|
|
66
72
|
background = generateHSL_L(orientation, dir, zValue);
|
|
67
73
|
break;
|
|
@@ -64,5 +64,27 @@ declare const generateHSB_B: (orientation: [string, string], dir: boolean, alpha
|
|
|
64
64
|
background: string;
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
+
/** oklab: x = a, y = b, z = lightness (fixed L) */
|
|
68
|
+
declare const generateOKLAB_AB: (orientation: [string, string], dir: boolean, L: number) => {
|
|
69
|
+
areaStyles: {
|
|
70
|
+
background: string;
|
|
71
|
+
};
|
|
72
|
+
areaGradientStyles: {
|
|
73
|
+
background: string;
|
|
74
|
+
maskImage: string;
|
|
75
|
+
WebkitMaskImage: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** oklch: x = lightness, y = chroma, z = hue (fixed H) */
|
|
79
|
+
declare const generateOKLCH_LC: (orientation: [string, string], dir: boolean, H: number) => {
|
|
80
|
+
areaStyles: {
|
|
81
|
+
background: string;
|
|
82
|
+
};
|
|
83
|
+
areaGradientStyles: {
|
|
84
|
+
background: string;
|
|
85
|
+
maskImage: string;
|
|
86
|
+
WebkitMaskImage: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
67
89
|
|
|
68
|
-
export { generateHSB_B, generateHSB_H, generateHSB_S, generateHSL_H, generateHSL_L, generateHSL_S, generateRGB_B, generateRGB_G, generateRGB_R };
|
|
90
|
+
export { generateHSB_B, generateHSB_H, generateHSB_S, generateHSL_H, generateHSL_L, generateHSL_S, generateOKLAB_AB, generateOKLCH_LC, generateRGB_B, generateRGB_G, generateRGB_R };
|
|
@@ -64,5 +64,27 @@ declare const generateHSB_B: (orientation: [string, string], dir: boolean, alpha
|
|
|
64
64
|
background: string;
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
+
/** oklab: x = a, y = b, z = lightness (fixed L) */
|
|
68
|
+
declare const generateOKLAB_AB: (orientation: [string, string], dir: boolean, L: number) => {
|
|
69
|
+
areaStyles: {
|
|
70
|
+
background: string;
|
|
71
|
+
};
|
|
72
|
+
areaGradientStyles: {
|
|
73
|
+
background: string;
|
|
74
|
+
maskImage: string;
|
|
75
|
+
WebkitMaskImage: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** oklch: x = lightness, y = chroma, z = hue (fixed H) */
|
|
79
|
+
declare const generateOKLCH_LC: (orientation: [string, string], dir: boolean, H: number) => {
|
|
80
|
+
areaStyles: {
|
|
81
|
+
background: string;
|
|
82
|
+
};
|
|
83
|
+
areaGradientStyles: {
|
|
84
|
+
background: string;
|
|
85
|
+
maskImage: string;
|
|
86
|
+
WebkitMaskImage: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
67
89
|
|
|
68
|
-
export { generateHSB_B, generateHSB_H, generateHSB_S, generateHSL_H, generateHSL_L, generateHSL_S, generateRGB_B, generateRGB_G, generateRGB_R };
|
|
90
|
+
export { generateHSB_B, generateHSB_H, generateHSB_S, generateHSL_H, generateHSL_L, generateHSL_S, generateOKLAB_AB, generateOKLCH_LC, generateRGB_B, generateRGB_G, generateRGB_R };
|
|
@@ -26,6 +26,8 @@ __export(color_format_gradient_exports, {
|
|
|
26
26
|
generateHSL_H: () => generateHSL_H,
|
|
27
27
|
generateHSL_L: () => generateHSL_L,
|
|
28
28
|
generateHSL_S: () => generateHSL_S,
|
|
29
|
+
generateOKLAB_AB: () => generateOKLAB_AB,
|
|
30
|
+
generateOKLCH_LC: () => generateOKLCH_LC,
|
|
29
31
|
generateRGB_B: () => generateRGB_B,
|
|
30
32
|
generateRGB_G: () => generateRGB_G,
|
|
31
33
|
generateRGB_R: () => generateRGB_R
|
|
@@ -150,6 +152,35 @@ var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
|
150
152
|
};
|
|
151
153
|
return result;
|
|
152
154
|
};
|
|
155
|
+
var generateOKLAB_AB = (orientation, dir, L) => {
|
|
156
|
+
const l = L === 0 ? "none" : `${(L * 100).toFixed(2)}%`;
|
|
157
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, black, transparent)`;
|
|
158
|
+
const result = {
|
|
159
|
+
areaStyles: {
|
|
160
|
+
background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% 100%), oklab(${l} 100% 100%))`
|
|
161
|
+
},
|
|
162
|
+
areaGradientStyles: {
|
|
163
|
+
background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% -100%), oklab(${l} 100% -100%))`,
|
|
164
|
+
maskImage,
|
|
165
|
+
WebkitMaskImage: maskImage
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
return result;
|
|
169
|
+
};
|
|
170
|
+
var generateOKLCH_LC = (orientation, dir, H) => {
|
|
171
|
+
const maskImage = `linear-gradient(to ${orientation[Number(dir)]}, transparent, black)`;
|
|
172
|
+
const result = {
|
|
173
|
+
areaStyles: {
|
|
174
|
+
background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.001 ${H}), oklch(1 0.001 ${H}))`
|
|
175
|
+
},
|
|
176
|
+
areaGradientStyles: {
|
|
177
|
+
background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.5 ${H}), oklch(1 0.5 ${H}))`,
|
|
178
|
+
maskImage,
|
|
179
|
+
WebkitMaskImage: maskImage
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
153
184
|
// Annotate the CommonJS export names for ESM import in node:
|
|
154
185
|
0 && (module.exports = {
|
|
155
186
|
generateHSB_B,
|
|
@@ -158,6 +189,8 @@ var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
|
158
189
|
generateHSL_H,
|
|
159
190
|
generateHSL_L,
|
|
160
191
|
generateHSL_S,
|
|
192
|
+
generateOKLAB_AB,
|
|
193
|
+
generateOKLCH_LC,
|
|
161
194
|
generateRGB_B,
|
|
162
195
|
generateRGB_G,
|
|
163
196
|
generateRGB_R
|
|
@@ -120,6 +120,35 @@ var generateHSB_B = (orientation, dir, alphaValue) => {
|
|
|
120
120
|
};
|
|
121
121
|
return result;
|
|
122
122
|
};
|
|
123
|
+
var generateOKLAB_AB = (orientation, dir, L) => {
|
|
124
|
+
const l = L === 0 ? "none" : `${(L * 100).toFixed(2)}%`;
|
|
125
|
+
const maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, black, transparent)`;
|
|
126
|
+
const result = {
|
|
127
|
+
areaStyles: {
|
|
128
|
+
background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% 100%), oklab(${l} 100% 100%))`
|
|
129
|
+
},
|
|
130
|
+
areaGradientStyles: {
|
|
131
|
+
background: `linear-gradient(to ${orientation[Number(dir)]} in oklab, oklab(${l} -100% -100%), oklab(${l} 100% -100%))`,
|
|
132
|
+
maskImage,
|
|
133
|
+
WebkitMaskImage: maskImage
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
var generateOKLCH_LC = (orientation, dir, H) => {
|
|
139
|
+
const maskImage = `linear-gradient(to ${orientation[Number(dir)]}, transparent, black)`;
|
|
140
|
+
const result = {
|
|
141
|
+
areaStyles: {
|
|
142
|
+
background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.001 ${H}), oklch(1 0.001 ${H}))`
|
|
143
|
+
},
|
|
144
|
+
areaGradientStyles: {
|
|
145
|
+
background: `linear-gradient(to ${orientation[Number(!dir)]} in oklch, oklch(0 0.5 ${H}), oklch(1 0.5 ${H}))`,
|
|
146
|
+
maskImage,
|
|
147
|
+
WebkitMaskImage: maskImage
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
123
152
|
export {
|
|
124
153
|
generateHSB_B,
|
|
125
154
|
generateHSB_H,
|
|
@@ -127,6 +156,8 @@ export {
|
|
|
127
156
|
generateHSL_H,
|
|
128
157
|
generateHSL_L,
|
|
129
158
|
generateHSL_S,
|
|
159
|
+
generateOKLAB_AB,
|
|
160
|
+
generateOKLCH_LC,
|
|
130
161
|
generateRGB_B,
|
|
131
162
|
generateRGB_G,
|
|
132
163
|
generateRGB_R
|
package/dist/gamut.d.mts
ADDED
package/dist/gamut.d.ts
ADDED
package/dist/gamut.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(gamut_exports);
|
|
26
|
+
var import_oklab_math = require("./oklab-math.js");
|
|
27
|
+
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));
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
isInSrgbGamut
|
|
37
|
+
});
|
package/dist/gamut.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./chunk-QZ7TP4HQ.mjs";
|
|
2
|
+
|
|
3
|
+
// src/gamut.ts
|
|
4
|
+
import { isLinearRgbInSrgbGamut, oklabToLinearRgb } from "./oklab-math.mjs";
|
|
5
|
+
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));
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
isInSrgbGamut
|
|
14
|
+
};
|
package/dist/hsb-color.d.mts
CHANGED
|
@@ -7,6 +7,11 @@ declare class HSBColor extends Color {
|
|
|
7
7
|
private brightness;
|
|
8
8
|
private alpha;
|
|
9
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;
|
|
10
15
|
static parse(value: string): HSBColor | void;
|
|
11
16
|
toString(format?: ColorStringFormat): string;
|
|
12
17
|
toFormat(format: ColorFormat): ColorType;
|
package/dist/hsb-color.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ declare class HSBColor extends Color {
|
|
|
7
7
|
private brightness;
|
|
8
8
|
private alpha;
|
|
9
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;
|
|
10
15
|
static parse(value: string): HSBColor | void;
|
|
11
16
|
toString(format?: ColorStringFormat): string;
|
|
12
17
|
toFormat(format: ColorFormat): ColorType;
|
package/dist/hsb-color.js
CHANGED
|
@@ -38,6 +38,40 @@ var _HSBColor = class _HSBColor extends import_color.Color {
|
|
|
38
38
|
__publicField(this, "brightness", brightness);
|
|
39
39
|
__publicField(this, "alpha", alpha);
|
|
40
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
|
+
}
|
|
41
75
|
static parse(value) {
|
|
42
76
|
let m;
|
|
43
77
|
if (m = value.match(HSB_REGEX)) {
|
|
@@ -73,6 +107,9 @@ var _HSBColor = class _HSBColor extends import_color.Color {
|
|
|
73
107
|
return this.toHSL();
|
|
74
108
|
case "rgba":
|
|
75
109
|
return this.toRGB();
|
|
110
|
+
case "oklab":
|
|
111
|
+
case "oklch":
|
|
112
|
+
return this.toRGB().toFormat(format);
|
|
76
113
|
default:
|
|
77
114
|
throw new Error("Unsupported color conversion: hsb -> " + format);
|
|
78
115
|
}
|
package/dist/hsb-color.mjs
CHANGED
|
@@ -16,6 +16,40 @@ var _HSBColor = class _HSBColor extends Color {
|
|
|
16
16
|
__publicField(this, "brightness", brightness);
|
|
17
17
|
__publicField(this, "alpha", alpha);
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Create HSBColor from float sRGB values (0-1 range, clamped).
|
|
21
|
+
* Higher precision than going through integer RGBColor (0-255).
|
|
22
|
+
*/
|
|
23
|
+
static fromSrgbFloat(r, g, b, alpha) {
|
|
24
|
+
const rc = Math.max(0, Math.min(1, r));
|
|
25
|
+
const gc = Math.max(0, Math.min(1, g));
|
|
26
|
+
const bc = Math.max(0, Math.min(1, b));
|
|
27
|
+
const min = Math.min(rc, gc, bc);
|
|
28
|
+
const brightness = Math.max(rc, gc, bc);
|
|
29
|
+
const chroma = brightness - min;
|
|
30
|
+
const saturation = brightness === 0 ? 0 : chroma / brightness;
|
|
31
|
+
let hue = 0;
|
|
32
|
+
if (chroma !== 0) {
|
|
33
|
+
switch (brightness) {
|
|
34
|
+
case rc:
|
|
35
|
+
hue = (gc - bc) / chroma + (gc < bc ? 6 : 0);
|
|
36
|
+
break;
|
|
37
|
+
case gc:
|
|
38
|
+
hue = (bc - rc) / chroma + 2;
|
|
39
|
+
break;
|
|
40
|
+
case bc:
|
|
41
|
+
hue = (rc - gc) / chroma + 4;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
hue /= 6;
|
|
45
|
+
}
|
|
46
|
+
return new _HSBColor(
|
|
47
|
+
toFixedNumber(hue * 360, 4),
|
|
48
|
+
toFixedNumber(saturation * 100, 4),
|
|
49
|
+
toFixedNumber(brightness * 100, 4),
|
|
50
|
+
toFixedNumber(alpha, 4)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
19
53
|
static parse(value) {
|
|
20
54
|
let m;
|
|
21
55
|
if (m = value.match(HSB_REGEX)) {
|
|
@@ -51,6 +85,9 @@ var _HSBColor = class _HSBColor extends Color {
|
|
|
51
85
|
return this.toHSL();
|
|
52
86
|
case "rgba":
|
|
53
87
|
return this.toRGB();
|
|
88
|
+
case "oklab":
|
|
89
|
+
case "oklch":
|
|
90
|
+
return this.toRGB().toFormat(format);
|
|
54
91
|
default:
|
|
55
92
|
throw new Error("Unsupported color conversion: hsb -> " + format);
|
|
56
93
|
}
|
package/dist/hsl-color.js
CHANGED
|
@@ -73,6 +73,9 @@ var _HSLColor = class _HSLColor extends import_color.Color {
|
|
|
73
73
|
return this.toHSB();
|
|
74
74
|
case "rgba":
|
|
75
75
|
return this.toRGB();
|
|
76
|
+
case "oklab":
|
|
77
|
+
case "oklch":
|
|
78
|
+
return this.toRGB().toFormat(format);
|
|
76
79
|
default:
|
|
77
80
|
throw new Error("Unsupported color conversion: hsl -> " + format);
|
|
78
81
|
}
|
package/dist/hsl-color.mjs
CHANGED
|
@@ -50,6 +50,9 @@ var _HSLColor = class _HSLColor extends Color {
|
|
|
50
50
|
return this.toHSB();
|
|
51
51
|
case "rgba":
|
|
52
52
|
return this.toRGB();
|
|
53
|
+
case "oklab":
|
|
54
|
+
case "oklch":
|
|
55
|
+
return this.toRGB().toFormat(format);
|
|
53
56
|
default:
|
|
54
57
|
throw new Error("Unsupported color conversion: hsl -> " + format);
|
|
55
58
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { getColorAreaGradient } from './area-gradient.mjs';
|
|
2
2
|
export { Color } from './color.mjs';
|
|
3
|
+
export { isDisplayP3HsvInSrgbGamut, isLinearRgbInSrgbGamut, linearRgbToOklab, oklabToLinearRgb, oklabToOklch, oklchToOklab, srgbToLinearRgb } from './oklab-math.mjs';
|
|
4
|
+
export { isInSrgbGamut } from './gamut.mjs';
|
|
5
|
+
export { OklabColor, OklchColor } from './oklab-color.mjs';
|
|
3
6
|
export { normalizeColor, parseColor } from './parse-color.mjs';
|
|
4
7
|
export { ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from './types.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { getColorAreaGradient } from './area-gradient.js';
|
|
2
2
|
export { Color } from './color.js';
|
|
3
|
+
export { isDisplayP3HsvInSrgbGamut, isLinearRgbInSrgbGamut, linearRgbToOklab, oklabToLinearRgb, oklabToOklch, oklchToOklab, srgbToLinearRgb } from './oklab-math.js';
|
|
4
|
+
export { isInSrgbGamut } from './gamut.js';
|
|
5
|
+
export { OklabColor, OklchColor } from './oklab-color.js';
|
|
3
6
|
export { normalizeColor, parseColor } from './parse-color.js';
|
|
4
7
|
export { ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorStringFormat, ColorType } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -21,18 +21,41 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
Color: () => import_color.Color,
|
|
24
|
+
OklabColor: () => import_oklab_color.OklabColor,
|
|
25
|
+
OklchColor: () => import_oklab_color.OklchColor,
|
|
24
26
|
getColorAreaGradient: () => import_area_gradient.getColorAreaGradient,
|
|
27
|
+
isDisplayP3HsvInSrgbGamut: () => import_oklab_math.isDisplayP3HsvInSrgbGamut,
|
|
28
|
+
isInSrgbGamut: () => import_gamut.isInSrgbGamut,
|
|
29
|
+
isLinearRgbInSrgbGamut: () => import_oklab_math.isLinearRgbInSrgbGamut,
|
|
30
|
+
linearRgbToOklab: () => import_oklab_math.linearRgbToOklab,
|
|
25
31
|
normalizeColor: () => import_parse_color.normalizeColor,
|
|
26
|
-
|
|
32
|
+
oklabToLinearRgb: () => import_oklab_math.oklabToLinearRgb,
|
|
33
|
+
oklabToOklch: () => import_oklab_math.oklabToOklch,
|
|
34
|
+
oklchToOklab: () => import_oklab_math.oklchToOklab,
|
|
35
|
+
parseColor: () => import_parse_color.parseColor,
|
|
36
|
+
srgbToLinearRgb: () => import_oklab_math.srgbToLinearRgb
|
|
27
37
|
});
|
|
28
38
|
module.exports = __toCommonJS(index_exports);
|
|
29
39
|
var import_area_gradient = require("./area-gradient.js");
|
|
30
40
|
var import_color = require("./color.js");
|
|
41
|
+
var import_oklab_math = require("./oklab-math.js");
|
|
42
|
+
var import_gamut = require("./gamut.js");
|
|
43
|
+
var import_oklab_color = require("./oklab-color.js");
|
|
31
44
|
var import_parse_color = require("./parse-color.js");
|
|
32
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
46
|
0 && (module.exports = {
|
|
34
47
|
Color,
|
|
48
|
+
OklabColor,
|
|
49
|
+
OklchColor,
|
|
35
50
|
getColorAreaGradient,
|
|
51
|
+
isDisplayP3HsvInSrgbGamut,
|
|
52
|
+
isInSrgbGamut,
|
|
53
|
+
isLinearRgbInSrgbGamut,
|
|
54
|
+
linearRgbToOklab,
|
|
36
55
|
normalizeColor,
|
|
37
|
-
|
|
56
|
+
oklabToLinearRgb,
|
|
57
|
+
oklabToOklch,
|
|
58
|
+
oklchToOklab,
|
|
59
|
+
parseColor,
|
|
60
|
+
srgbToLinearRgb
|
|
38
61
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,31 @@ import "./chunk-QZ7TP4HQ.mjs";
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { getColorAreaGradient } from "./area-gradient.mjs";
|
|
5
5
|
import { Color } from "./color.mjs";
|
|
6
|
+
import {
|
|
7
|
+
isDisplayP3HsvInSrgbGamut,
|
|
8
|
+
isLinearRgbInSrgbGamut,
|
|
9
|
+
linearRgbToOklab,
|
|
10
|
+
oklabToLinearRgb,
|
|
11
|
+
oklabToOklch,
|
|
12
|
+
oklchToOklab,
|
|
13
|
+
srgbToLinearRgb
|
|
14
|
+
} from "./oklab-math.mjs";
|
|
15
|
+
import { isInSrgbGamut } from "./gamut.mjs";
|
|
16
|
+
import { OklabColor, OklchColor } from "./oklab-color.mjs";
|
|
6
17
|
import { normalizeColor, parseColor } from "./parse-color.mjs";
|
|
7
18
|
export {
|
|
8
19
|
Color,
|
|
20
|
+
OklabColor,
|
|
21
|
+
OklchColor,
|
|
9
22
|
getColorAreaGradient,
|
|
23
|
+
isDisplayP3HsvInSrgbGamut,
|
|
24
|
+
isInSrgbGamut,
|
|
25
|
+
isLinearRgbInSrgbGamut,
|
|
26
|
+
linearRgbToOklab,
|
|
10
27
|
normalizeColor,
|
|
11
|
-
|
|
28
|
+
oklabToLinearRgb,
|
|
29
|
+
oklabToOklch,
|
|
30
|
+
oklchToOklab,
|
|
31
|
+
parseColor,
|
|
32
|
+
srgbToLinearRgb
|
|
12
33
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Color } from './color.mjs';
|
|
2
|
+
import { ColorStringFormat, ColorFormat, ColorType, ColorChannel, ColorChannelRange } from './types.mjs';
|
|
3
|
+
|
|
4
|
+
/** Parse `oklab(L a b)` / `oklab(L a b / alpha)` body (inside parentheses). */
|
|
5
|
+
declare function parseOklabParams(inner: string): {
|
|
6
|
+
L: number;
|
|
7
|
+
a: number;
|
|
8
|
+
b: number;
|
|
9
|
+
alpha: number;
|
|
10
|
+
} | void;
|
|
11
|
+
declare class OklabColor extends Color {
|
|
12
|
+
private lightness;
|
|
13
|
+
private a;
|
|
14
|
+
private b;
|
|
15
|
+
private alpha;
|
|
16
|
+
constructor(lightness: number, a: number, b: number, alpha: number);
|
|
17
|
+
static parse(value: string): OklabColor | void;
|
|
18
|
+
toString(format?: ColorStringFormat): string;
|
|
19
|
+
toFormat(format: ColorFormat): ColorType;
|
|
20
|
+
private toRgb;
|
|
21
|
+
private toOklch;
|
|
22
|
+
clone(): ColorType;
|
|
23
|
+
getChannelValue(channel: ColorChannel): number;
|
|
24
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
25
|
+
formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
26
|
+
private getChannelFormatOptions;
|
|
27
|
+
getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
28
|
+
toJSON(): Record<string, number>;
|
|
29
|
+
getFormat(): ColorFormat;
|
|
30
|
+
private static colorChannels;
|
|
31
|
+
getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
32
|
+
isEqual(color: ColorType): boolean;
|
|
33
|
+
}
|
|
34
|
+
declare function parseOklchParams(inner: string): {
|
|
35
|
+
L: number;
|
|
36
|
+
C: number;
|
|
37
|
+
H: number;
|
|
38
|
+
alpha: number;
|
|
39
|
+
} | void;
|
|
40
|
+
declare class OklchColor extends Color {
|
|
41
|
+
private lightness;
|
|
42
|
+
private hue;
|
|
43
|
+
private chroma;
|
|
44
|
+
private alpha;
|
|
45
|
+
constructor(lightness: number, hue: number, chroma: number, alpha: number);
|
|
46
|
+
static parse(value: string): OklchColor | void;
|
|
47
|
+
toString(format?: ColorStringFormat): string;
|
|
48
|
+
toFormat(format: ColorFormat): ColorType;
|
|
49
|
+
private toOklab;
|
|
50
|
+
private toRgb;
|
|
51
|
+
clone(): ColorType;
|
|
52
|
+
getChannelValue(channel: ColorChannel): number;
|
|
53
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
54
|
+
formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
55
|
+
private getChannelFormatOptions;
|
|
56
|
+
getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
57
|
+
toJSON(): Record<string, number>;
|
|
58
|
+
getFormat(): ColorFormat;
|
|
59
|
+
private static colorChannels;
|
|
60
|
+
getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
61
|
+
isEqual(color: ColorType): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { OklabColor, OklchColor, parseOklabParams, parseOklchParams };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Color } from './color.js';
|
|
2
|
+
import { ColorStringFormat, ColorFormat, ColorType, ColorChannel, ColorChannelRange } from './types.js';
|
|
3
|
+
|
|
4
|
+
/** Parse `oklab(L a b)` / `oklab(L a b / alpha)` body (inside parentheses). */
|
|
5
|
+
declare function parseOklabParams(inner: string): {
|
|
6
|
+
L: number;
|
|
7
|
+
a: number;
|
|
8
|
+
b: number;
|
|
9
|
+
alpha: number;
|
|
10
|
+
} | void;
|
|
11
|
+
declare class OklabColor extends Color {
|
|
12
|
+
private lightness;
|
|
13
|
+
private a;
|
|
14
|
+
private b;
|
|
15
|
+
private alpha;
|
|
16
|
+
constructor(lightness: number, a: number, b: number, alpha: number);
|
|
17
|
+
static parse(value: string): OklabColor | void;
|
|
18
|
+
toString(format?: ColorStringFormat): string;
|
|
19
|
+
toFormat(format: ColorFormat): ColorType;
|
|
20
|
+
private toRgb;
|
|
21
|
+
private toOklch;
|
|
22
|
+
clone(): ColorType;
|
|
23
|
+
getChannelValue(channel: ColorChannel): number;
|
|
24
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
25
|
+
formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
26
|
+
private getChannelFormatOptions;
|
|
27
|
+
getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
28
|
+
toJSON(): Record<string, number>;
|
|
29
|
+
getFormat(): ColorFormat;
|
|
30
|
+
private static colorChannels;
|
|
31
|
+
getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
32
|
+
isEqual(color: ColorType): boolean;
|
|
33
|
+
}
|
|
34
|
+
declare function parseOklchParams(inner: string): {
|
|
35
|
+
L: number;
|
|
36
|
+
C: number;
|
|
37
|
+
H: number;
|
|
38
|
+
alpha: number;
|
|
39
|
+
} | void;
|
|
40
|
+
declare class OklchColor extends Color {
|
|
41
|
+
private lightness;
|
|
42
|
+
private hue;
|
|
43
|
+
private chroma;
|
|
44
|
+
private alpha;
|
|
45
|
+
constructor(lightness: number, hue: number, chroma: number, alpha: number);
|
|
46
|
+
static parse(value: string): OklchColor | void;
|
|
47
|
+
toString(format?: ColorStringFormat): string;
|
|
48
|
+
toFormat(format: ColorFormat): ColorType;
|
|
49
|
+
private toOklab;
|
|
50
|
+
private toRgb;
|
|
51
|
+
clone(): ColorType;
|
|
52
|
+
getChannelValue(channel: ColorChannel): number;
|
|
53
|
+
withChannelValue(channel: ColorChannel, value: number): ColorType;
|
|
54
|
+
formatChannelValue(channel: ColorChannel, locale: string): string;
|
|
55
|
+
private getChannelFormatOptions;
|
|
56
|
+
getChannelRange(channel: ColorChannel): ColorChannelRange;
|
|
57
|
+
toJSON(): Record<string, number>;
|
|
58
|
+
getFormat(): ColorFormat;
|
|
59
|
+
private static colorChannels;
|
|
60
|
+
getChannels(): [ColorChannel, ColorChannel, ColorChannel];
|
|
61
|
+
isEqual(color: ColorType): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { OklabColor, OklchColor, parseOklabParams, parseOklchParams };
|