@soybeanjs/colord 0.0.5 → 0.0.7
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/{colord-CRhmzs7Q.js → colord-CLzIbIN2.js} +20 -7
- package/dist/{colord-xpgrVWRV.d.ts → colord-Dc09uNcG.d.ts} +10 -0
- package/dist/colord.d.ts +1 -1
- package/dist/colord.js +8 -8
- package/dist/{extend-DrPfn2Q1.d.ts → extend-D_jQFvDk.d.ts} +1 -1
- package/dist/{get-DgoyZnms.js → get-SLuYLSG9.js} +1 -1
- package/dist/{hsv-BKcGyyrD.js → hsv-OOAVcaRH.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/lab-9NsKpGel.js +219 -0
- package/dist/{manipulate-BTO-DFUg.js → manipulate-DCHNBCkU.js} +3 -3
- 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 +6 -2
- package/dist/plugins/lab.js +11 -8
- package/dist/plugins/lch.d.ts +2 -2
- package/dist/plugins/lch.js +99 -25
- 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 +50 -17
- package/dist/plugins/oklch.d.ts +2 -2
- package/dist/plugins/oklch.js +93 -24
- package/dist/plugins/xyz.d.ts +2 -2
- package/dist/plugins/xyz.js +5 -5
- package/dist/{rgb-D5MxNcO5.js → rgb-BVkoWOmR.js} +4 -4
- package/dist/{utils-DajWVr6Z.js → utils-CshL9w1R.js} +18 -1
- package/dist/{xyz-D2aynO-Z.js → xyz-DsYRwYO_.js} +22 -9
- package/package.json +1 -13
- package/dist/lab-Cb1l0T-U.js +0 -128
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soybeanjs/colord",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "A tiny yet powerful tool for high-performance color manipulations and conversions",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Soybean",
|
|
@@ -37,25 +37,13 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"cli-progress": "3.12.0",
|
|
42
|
-
"consola": "3.4.2",
|
|
43
|
-
"dayjs": "1.11.19",
|
|
44
|
-
"execa": "9.6.1",
|
|
45
|
-
"kolorist": "1.8.0",
|
|
46
|
-
"ofetch": "1.5.1"
|
|
47
|
-
},
|
|
48
40
|
"devDependencies": {
|
|
49
41
|
"@soybeanjs/cli": "1.4.4",
|
|
50
42
|
"@soybeanjs/eslint-config": "1.7.5",
|
|
51
|
-
"@types/cli-progress": "3.11.6",
|
|
52
43
|
"@types/node": "25.0.8",
|
|
53
|
-
"@types/tinycolor2": "^1.4.6",
|
|
54
|
-
"colord": "^2.9.3",
|
|
55
44
|
"eslint": "9.39.2",
|
|
56
45
|
"lint-staged": "16.2.7",
|
|
57
46
|
"simple-git-hooks": "2.13.1",
|
|
58
|
-
"tinycolor2": "^1.6.0",
|
|
59
47
|
"tsdown": "0.19.0",
|
|
60
48
|
"tsx": "4.21.0",
|
|
61
49
|
"typescript": "5.9.3"
|
package/dist/lab-Cb1l0T-U.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { a as mul3x3, d as M_D65_TO_D50, i as isPresent, l as round, o as parseAlpha, t as clamp, u as M_D50_TO_D65, v as ALPHA_PRECISION, y as D50 } from "./utils-DajWVr6Z.js";
|
|
2
|
-
import { i as xyzToRgb, n as rgbToXyz } from "./xyz-D2aynO-Z.js";
|
|
3
|
-
|
|
4
|
-
//#region src/models/lab.ts
|
|
5
|
-
const EPSILON = 216 / 24389;
|
|
6
|
-
const KAPPA = 24389 / 27;
|
|
7
|
-
/**
|
|
8
|
-
* Clamps LAB axis values as defined in CSS Color Level 4 specs.
|
|
9
|
-
* https://www.w3.org/TR/css-color-4/#specifying-lab-lch
|
|
10
|
-
*/
|
|
11
|
-
const clampLab = (lab) => {
|
|
12
|
-
const { l, a, b, alpha } = lab;
|
|
13
|
-
return {
|
|
14
|
-
l: clamp(l, 0, 100),
|
|
15
|
-
a: clamp(a, -128, 127),
|
|
16
|
-
b: clamp(b, -128, 127),
|
|
17
|
-
alpha: clamp(alpha)
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const roundLab = (lab) => {
|
|
21
|
-
const { l, a, b, alpha } = lab;
|
|
22
|
-
return {
|
|
23
|
-
l: round(l, 3),
|
|
24
|
-
a: round(a, 3),
|
|
25
|
-
b: round(b, 3),
|
|
26
|
-
alpha: round(alpha, ALPHA_PRECISION)
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Performs RGB → CIEXYZ → LAB color conversion
|
|
31
|
-
* https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
32
|
-
*/
|
|
33
|
-
const rgbToLab = (rgb) => {
|
|
34
|
-
const xyzD65 = rgbToXyz(rgb);
|
|
35
|
-
const { alpha } = xyzD65;
|
|
36
|
-
const [x, y, z] = mul3x3(M_D65_TO_D50, [
|
|
37
|
-
xyzD65.x,
|
|
38
|
-
xyzD65.y,
|
|
39
|
-
xyzD65.z
|
|
40
|
-
]);
|
|
41
|
-
return xyzToLabRaw({
|
|
42
|
-
x,
|
|
43
|
-
y,
|
|
44
|
-
z,
|
|
45
|
-
alpha
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Performs LAB → CIEXYZ → RGB color conversion
|
|
50
|
-
* https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
51
|
-
*/
|
|
52
|
-
const labToRgb = (lab) => {
|
|
53
|
-
const xyzD50 = labToXyzRaw(lab);
|
|
54
|
-
const [x, y, z] = mul3x3(M_D50_TO_D65, [
|
|
55
|
-
xyzD50.x,
|
|
56
|
-
xyzD50.y,
|
|
57
|
-
xyzD50.z
|
|
58
|
-
]);
|
|
59
|
-
return xyzToRgb({
|
|
60
|
-
x,
|
|
61
|
-
y,
|
|
62
|
-
z,
|
|
63
|
-
alpha: lab.alpha
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
function xyzToLabRaw(xyz) {
|
|
67
|
-
const { x, y, z, alpha } = xyz;
|
|
68
|
-
const xr = x / D50.x;
|
|
69
|
-
const yr = y / D50.y;
|
|
70
|
-
const zr = z / D50.z;
|
|
71
|
-
const f = (t) => t > EPSILON ? Math.cbrt(t) : (KAPPA * t + 16) / 116;
|
|
72
|
-
const fx = f(xr);
|
|
73
|
-
const fy = f(yr);
|
|
74
|
-
const fz = f(zr);
|
|
75
|
-
return {
|
|
76
|
-
l: 116 * fy - 16,
|
|
77
|
-
a: 500 * (fx - fy),
|
|
78
|
-
b: 200 * (fy - fz),
|
|
79
|
-
alpha
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function labToXyzRaw(lab) {
|
|
83
|
-
const { l, a, b, alpha } = lab;
|
|
84
|
-
const fy = (l + 16) / 116;
|
|
85
|
-
const fx = a / 500 + fy;
|
|
86
|
-
const fz = fy - b / 200;
|
|
87
|
-
const f3 = (t) => t * t * t > EPSILON ? t * t * t : (116 * t - 16) / KAPPA;
|
|
88
|
-
const xr = f3(fx);
|
|
89
|
-
const yr = l > KAPPA * EPSILON ? ((l + 16) / 116) ** 3 : l / KAPPA;
|
|
90
|
-
const zr = f3(fz);
|
|
91
|
-
return {
|
|
92
|
-
x: xr * D50.x,
|
|
93
|
-
y: yr * D50.y,
|
|
94
|
-
z: zr * D50.z,
|
|
95
|
-
alpha
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const parseLab = ({ l, a, b, alpha = 1 }) => {
|
|
99
|
-
if (!isPresent(l) || !isPresent(a) || !isPresent(b)) return null;
|
|
100
|
-
return labToRgb(clampLab({
|
|
101
|
-
l: Number(l),
|
|
102
|
-
a: Number(a),
|
|
103
|
-
b: Number(b),
|
|
104
|
-
alpha: Number(alpha)
|
|
105
|
-
}));
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Parsing syntax: oklab(L a b [/ alpha])
|
|
109
|
-
* - L: <number|percentage> [0,100]
|
|
110
|
-
* - a: <number> [-125,125]
|
|
111
|
-
* - b: <number> [-125,125]
|
|
112
|
-
* - alpha: <number|percentage> [0,1]
|
|
113
|
-
*/
|
|
114
|
-
const labMatcher = /^lab\(\s*([+-]?[\d.]+)%?\s+([+-]?[\d.]+)\s+([+-]?[\d.]+)(?:\s*\/\s*([+-]?[\d.]+%?))?\s*\)$/i;
|
|
115
|
-
const parseLabString = (input) => {
|
|
116
|
-
const match = labMatcher.exec(input);
|
|
117
|
-
if (!match) return null;
|
|
118
|
-
const [_, l, a, b, alpha] = match;
|
|
119
|
-
return labToRgb(clampLab({
|
|
120
|
-
l: Number.parseFloat(l),
|
|
121
|
-
a: Number.parseFloat(a),
|
|
122
|
-
b: Number.parseFloat(b),
|
|
123
|
-
alpha: parseAlpha(alpha)
|
|
124
|
-
}));
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
export { rgbToLab as a, parseLabString as i, labToRgb as n, roundLab as o, parseLab as r, clampLab as t };
|