@soybeanjs/colord 0.1.1 → 0.2.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/README.md +2 -2
- package/dist/{colord-iJvjkDaN.d.ts → colord-AfN0aSRY.d.ts} +11 -1
- package/dist/{colord-CiL21DdP.js → colord-_3vDrvhI.js} +187 -7
- package/dist/colord.d.ts +1 -1
- package/dist/colord.js +8 -8
- package/dist/{extend-Cjbo01n8.js → extend-1NvzfDMp.js} +1 -1
- package/dist/{extend-BwkxQVzY.d.ts → extend-UYBGWCHH.d.ts} +2 -2
- package/dist/{get-DjkEJgax.js → get-B9GsrsfV.js} +1 -1
- package/dist/{hsv-6f-Avk00.js → hsv-OOAVcaRH.js} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -9
- package/dist/{lab-BXLaTQvQ.js → lab-DRO6J6z8.js} +5 -5
- package/dist/{lab-DklZwOkG.js → lab-NxNRMUqK.js} +12 -12
- package/dist/{manipulate-DJ-cBonL.js → manipulate-DG6jOj5-.js} +3 -3
- package/dist/palette/index.d.ts +9 -3
- package/dist/palette/index.js +305 -14
- package/dist/plugins/a11y.d.ts +2 -2
- package/dist/plugins/a11y.js +3 -3
- package/dist/plugins/cmyk.d.ts +2 -2
- package/dist/plugins/cmyk.js +1 -1
- package/dist/plugins/harmonies.d.ts +1 -1
- package/dist/plugins/hwb.d.ts +2 -2
- package/dist/plugins/hwb.js +2 -2
- package/dist/plugins/lab.d.ts +2 -2
- package/dist/plugins/lab.js +6 -6
- package/dist/plugins/lch.d.ts +2 -2
- package/dist/plugins/lch.js +14 -14
- package/dist/plugins/minify.d.ts +1 -1
- package/dist/plugins/minify.js +1 -1
- package/dist/plugins/mix.d.ts +2 -2
- package/dist/plugins/mix.js +6 -6
- package/dist/plugins/names.d.ts +1 -1
- package/dist/plugins/oklab.d.ts +2 -2
- package/dist/plugins/oklab.js +12 -12
- package/dist/plugins/xyz.d.ts +2 -2
- package/dist/plugins/xyz.js +4 -4
- package/dist/{rgb-BIWjP3hJ.js → rgb-DzRkOBLO.js} +1 -1
- package/dist/{xyz-Czd8MTub.js → xyz-WMIP19rd.js} +7 -7
- package/package.json +1 -1
- package/dist/oklch-sYjVoJRG.js +0 -186
- package/dist/plugins/oklch.d.ts +0 -17
- package/dist/plugins/oklch.js +0 -5
- /package/dist/{types-CV5bTriG.d.ts → types-BP0NSyqd.d.ts} +0 -0
- /package/dist/{utils-BhDL0kto.js → utils-CshL9w1R.js} +0 -0
package/dist/plugins/xyz.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../utils-
|
|
2
|
-
import "../rgb-
|
|
3
|
-
import { i as roundXyz, n as
|
|
1
|
+
import "../utils-CshL9w1R.js";
|
|
2
|
+
import "../rgb-DzRkOBLO.js";
|
|
3
|
+
import { i as roundXyz, n as parseXyzBySource, r as rgbToXyz, t as parseXyz } from "../xyz-WMIP19rd.js";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/xyz.ts
|
|
6
6
|
/**
|
|
@@ -12,7 +12,7 @@ const xyzPlugin = (ColordClass, parsers) => {
|
|
|
12
12
|
ColordClass.prototype.toXyz = function toXyz() {
|
|
13
13
|
return roundXyz(parseXyzBySource(this.getSource()) || rgbToXyz(this.rgb));
|
|
14
14
|
};
|
|
15
|
-
parsers.object.push([
|
|
15
|
+
parsers.object.push([parseXyz, "xyz"]);
|
|
16
16
|
};
|
|
17
17
|
var xyz_default = xyzPlugin;
|
|
18
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "./utils-
|
|
1
|
+
import { i as isPresent, l as round, o as parseAlpha, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
|
|
2
2
|
|
|
3
3
|
//#region src/models/rgb.ts
|
|
4
4
|
const clampRgb = (rgb) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as mul3x3, b as D65, f as M_SRGB_TO_XYZ_D65, i as isPresent, l as round, p as M_XYZ_D65_TO_SRGB, t as clamp, v as ALPHA_PRECISION } from "./utils-
|
|
2
|
-
import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-
|
|
1
|
+
import { a as mul3x3, b as D65, f as M_SRGB_TO_XYZ_D65, i as isPresent, l as round, p as M_XYZ_D65_TO_SRGB, t as clamp, v as ALPHA_PRECISION } from "./utils-CshL9w1R.js";
|
|
2
|
+
import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb } from "./rgb-DzRkOBLO.js";
|
|
3
3
|
|
|
4
4
|
//#region src/models/xyz.ts
|
|
5
5
|
/**
|
|
@@ -61,7 +61,7 @@ const rgbToXyz = (rgb) => {
|
|
|
61
61
|
alpha
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
-
const
|
|
64
|
+
const parseOriginXyz = ({ x, y, z, alpha = 1 }) => {
|
|
65
65
|
if (!isPresent(x) || !isPresent(y) || !isPresent(z)) return null;
|
|
66
66
|
return clampXyz({
|
|
67
67
|
x: Number(x),
|
|
@@ -70,17 +70,17 @@ const parseXyz = ({ x, y, z, alpha = 1 }) => {
|
|
|
70
70
|
alpha: Number(alpha)
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
-
const
|
|
74
|
-
const xyz =
|
|
73
|
+
const parseXyz = (input) => {
|
|
74
|
+
const xyz = parseOriginXyz(input);
|
|
75
75
|
if (!xyz) return null;
|
|
76
76
|
return xyzToRgb(xyz);
|
|
77
77
|
};
|
|
78
78
|
const parseXyzBySource = (source) => {
|
|
79
79
|
if (!source || source.format !== "xyz") return null;
|
|
80
80
|
const { input } = source;
|
|
81
|
-
if (typeof input === "object") return
|
|
81
|
+
if (typeof input === "object") return parseOriginXyz(input);
|
|
82
82
|
return null;
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
//#endregion
|
|
86
|
-
export { xyzToRgb as a, roundXyz as i,
|
|
86
|
+
export { xyzToRgb as a, roundXyz as i, parseXyzBySource as n, rgbToXyz as r, parseXyz as t };
|
package/package.json
CHANGED
package/dist/oklch-sYjVoJRG.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { _ as OKLAB_M2_INV, a as mul3x3, c as parseValueToDecimal, g as OKLAB_M2, h as OKLAB_M1_INV, i as isPresent, l as round, m as OKLAB_M1, n as clampHue, o as parseAlpha, s as parseHue, t as clamp, v as ALPHA_PRECISION } from "./utils-BhDL0kto.js";
|
|
2
|
-
import { n as clampRgb, o as rgbToLinearRgb, r as linearRgbToRgb, t as clampLinearRgb } from "./rgb-BIWjP3hJ.js";
|
|
3
|
-
|
|
4
|
-
//#region src/models/oklch.ts
|
|
5
|
-
const clampOklch = (oklch) => {
|
|
6
|
-
const { l, c, h, alpha } = oklch;
|
|
7
|
-
return {
|
|
8
|
-
l: clamp(l, 0, 1),
|
|
9
|
-
c: clamp(c, 0, .37),
|
|
10
|
-
h: clampHue(h),
|
|
11
|
-
alpha: clamp(alpha)
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
const roundOklch = (oklch) => {
|
|
15
|
-
const { l, c, h, alpha } = oklch;
|
|
16
|
-
return {
|
|
17
|
-
l: round(l, 3),
|
|
18
|
-
c: round(c, 3),
|
|
19
|
-
h: round(h, 3),
|
|
20
|
-
alpha: round(alpha, ALPHA_PRECISION)
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Convert OKLCH to Linear RGB without gamut mapping
|
|
25
|
-
*/
|
|
26
|
-
const oklchToLinearRgb = (oklch) => {
|
|
27
|
-
const { l, c, h, alpha } = oklch;
|
|
28
|
-
const hRad = h * Math.PI / 180;
|
|
29
|
-
const [r, g, b] = mul3x3(OKLAB_M1_INV, mul3x3(OKLAB_M2_INV, [
|
|
30
|
-
l,
|
|
31
|
-
c * Math.cos(hRad),
|
|
32
|
-
c * Math.sin(hRad)
|
|
33
|
-
]).map((v) => v * v * v));
|
|
34
|
-
return {
|
|
35
|
-
r,
|
|
36
|
-
g,
|
|
37
|
-
b,
|
|
38
|
-
alpha
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Check if a linear RGB color is within sRGB gamut
|
|
43
|
-
*/
|
|
44
|
-
const isInGamut = (linearRgb, epsilon = 1e-6) => {
|
|
45
|
-
return linearRgb.r >= -epsilon && linearRgb.r <= 1 + epsilon && linearRgb.g >= -epsilon && linearRgb.g <= 1 + epsilon && linearRgb.b >= -epsilon && linearRgb.b <= 1 + epsilon;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Binary search to find maximum chroma that fits in sRGB gamut
|
|
49
|
-
* @param l - Lightness (0-1)
|
|
50
|
-
* @param h - Hue (0-360)
|
|
51
|
-
* @param alpha - Alpha (0-1)
|
|
52
|
-
* @returns Maximum chroma that fits in sRGB gamut
|
|
53
|
-
*/
|
|
54
|
-
const findGamutChroma = (l, h, alpha) => {
|
|
55
|
-
let min = 0;
|
|
56
|
-
let max = .37;
|
|
57
|
-
const epsilon = 1e-5;
|
|
58
|
-
if (isInGamut(oklchToLinearRgb({
|
|
59
|
-
l,
|
|
60
|
-
c: max,
|
|
61
|
-
h,
|
|
62
|
-
alpha
|
|
63
|
-
}), epsilon)) return max;
|
|
64
|
-
while (max - min > epsilon) {
|
|
65
|
-
const mid = (min + max) / 2;
|
|
66
|
-
if (isInGamut(oklchToLinearRgb({
|
|
67
|
-
l,
|
|
68
|
-
c: mid,
|
|
69
|
-
h,
|
|
70
|
-
alpha
|
|
71
|
-
}), epsilon)) min = mid;
|
|
72
|
-
else max = mid;
|
|
73
|
-
}
|
|
74
|
-
return min;
|
|
75
|
-
};
|
|
76
|
-
const oklchToRgb = (oklch) => {
|
|
77
|
-
const { l, h, alpha } = oklch;
|
|
78
|
-
let linearRgb = oklchToLinearRgb(oklch);
|
|
79
|
-
if (!isInGamut(linearRgb)) linearRgb = oklchToLinearRgb({
|
|
80
|
-
l,
|
|
81
|
-
c: findGamutChroma(l, h, alpha),
|
|
82
|
-
h,
|
|
83
|
-
alpha
|
|
84
|
-
});
|
|
85
|
-
linearRgb = clampLinearRgb(linearRgb);
|
|
86
|
-
return clampRgb(linearRgbToRgb(linearRgb));
|
|
87
|
-
};
|
|
88
|
-
const rgbToOklch = (rgb) => {
|
|
89
|
-
const lRgb = rgbToLinearRgb(rgb);
|
|
90
|
-
const [l, a, b] = mul3x3(OKLAB_M2, mul3x3(OKLAB_M1, [
|
|
91
|
-
lRgb.r,
|
|
92
|
-
lRgb.g,
|
|
93
|
-
lRgb.b
|
|
94
|
-
]).map((v) => Math.cbrt(v)));
|
|
95
|
-
const chroma = Math.sqrt(a * a + b * b);
|
|
96
|
-
let hue;
|
|
97
|
-
if (chroma < 1e-4) hue = 0;
|
|
98
|
-
else {
|
|
99
|
-
hue = Math.atan2(b, a) * (180 / Math.PI);
|
|
100
|
-
if (hue < 0) hue += 360;
|
|
101
|
-
}
|
|
102
|
-
return clampOklch({
|
|
103
|
-
l,
|
|
104
|
-
c: chroma,
|
|
105
|
-
h: hue,
|
|
106
|
-
alpha: rgb.alpha
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
const parseOklch = ({ l, c, h, alpha = 1 }) => {
|
|
110
|
-
if (!isPresent(l) || !isPresent(c) || !isPresent(h)) return null;
|
|
111
|
-
return clampOklch({
|
|
112
|
-
l: Number(l),
|
|
113
|
-
c: Number(c),
|
|
114
|
-
h: Number(h),
|
|
115
|
-
alpha: Number(alpha)
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
const parseOklchToRgb = (input) => {
|
|
119
|
-
const oklch = parseOklch(input);
|
|
120
|
-
if (!oklch) return null;
|
|
121
|
-
return oklchToRgb(oklch);
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Parsing syntax: oklch(L c h [/ alpha])
|
|
125
|
-
* - L: <number|percentage>
|
|
126
|
-
* - c: <number>
|
|
127
|
-
* - h: <number>
|
|
128
|
-
* - alpha: <number|percentage>
|
|
129
|
-
*/
|
|
130
|
-
const oklchMatcher = /^oklch\(\s*([+-]?[\d.]+)%?\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(deg|grad|rad|turn)?(?:\s*\/\s*([+-]?[\d.]+%?))?\s*\)$/i;
|
|
131
|
-
const parseOklchString = (input) => {
|
|
132
|
-
const match = oklchMatcher.exec(input);
|
|
133
|
-
if (!match) return null;
|
|
134
|
-
const [_, l, c, h, unit, alpha] = match;
|
|
135
|
-
return clampOklch({
|
|
136
|
-
l: parseValueToDecimal(l),
|
|
137
|
-
c: Number.parseFloat(c),
|
|
138
|
-
h: parseHue(h, unit),
|
|
139
|
-
alpha: parseAlpha(alpha)
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
const parseOklchStringToRgb = (input) => {
|
|
143
|
-
const oklch = parseOklchString(input);
|
|
144
|
-
if (!oklch) return null;
|
|
145
|
-
return oklchToRgb(oklch);
|
|
146
|
-
};
|
|
147
|
-
const toOklchString = (oklch) => {
|
|
148
|
-
const { l, c, h, alpha } = roundOklch(oklch);
|
|
149
|
-
return alpha < 1 ? `oklch(${l} ${c} ${h} / ${alpha})` : `oklch(${l} ${c} ${h})`;
|
|
150
|
-
};
|
|
151
|
-
const rgbToOklchString = (rgb) => {
|
|
152
|
-
return toOklchString(rgbToOklch(rgb));
|
|
153
|
-
};
|
|
154
|
-
const parseOklchBySource = (source) => {
|
|
155
|
-
if (!source || source.format !== "oklch") return null;
|
|
156
|
-
const { input } = source;
|
|
157
|
-
if (typeof input === "string") return parseOklchString(input);
|
|
158
|
-
if (typeof input === "object") return parseOklch(input);
|
|
159
|
-
return null;
|
|
160
|
-
};
|
|
161
|
-
const toOklchStringBySource = (source) => {
|
|
162
|
-
const oklch = parseOklchBySource(source);
|
|
163
|
-
if (!oklch) return null;
|
|
164
|
-
return toOklchString(oklch);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/plugins/oklch.ts
|
|
169
|
-
/**
|
|
170
|
-
* A plugin adding support for OKLCH colorspace.
|
|
171
|
-
* https://bottosson.github.io/posts/oklab/
|
|
172
|
-
*/
|
|
173
|
-
const oklchPlugin = (ColordClass, parsers) => {
|
|
174
|
-
ColordClass.prototype.toOklch = function toOklch() {
|
|
175
|
-
return roundOklch(parseOklchBySource(this.getSource()) || rgbToOklch(this.rgb));
|
|
176
|
-
};
|
|
177
|
-
ColordClass.prototype.toOklchString = function toOklchString$1() {
|
|
178
|
-
return toOklchStringBySource(this.getSource()) || rgbToOklchString(this.rgb);
|
|
179
|
-
};
|
|
180
|
-
parsers.string.push([parseOklchStringToRgb, "oklch"]);
|
|
181
|
-
parsers.object.push([parseOklchToRgb, "oklch"]);
|
|
182
|
-
};
|
|
183
|
-
var oklch_default = oklchPlugin;
|
|
184
|
-
|
|
185
|
-
//#endregion
|
|
186
|
-
export { oklch_default as n, oklchPlugin as t };
|
package/dist/plugins/oklch.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { p as OklchColor } from "../types-CV5bTriG.js";
|
|
2
|
-
import { t as Plugin } from "../extend-BwkxQVzY.js";
|
|
3
|
-
|
|
4
|
-
//#region src/plugins/oklch.d.ts
|
|
5
|
-
declare module '@soybeanjs/colord' {
|
|
6
|
-
interface Colord {
|
|
7
|
-
toOklch(): OklchColor;
|
|
8
|
-
toOklchString(): string;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A plugin adding support for OKLCH colorspace.
|
|
13
|
-
* https://bottosson.github.io/posts/oklab/
|
|
14
|
-
*/
|
|
15
|
-
declare const oklchPlugin: Plugin;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { oklchPlugin as default, oklchPlugin };
|
package/dist/plugins/oklch.js
DELETED
|
File without changes
|
|
File without changes
|