@texel/color 1.1.2 → 1.1.4
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 +1 -1
- package/package.json +1 -1
- package/src/gamut.js +4 -2
- package/test/almost-equal.js +0 -15
- package/test/banner.png +0 -0
- package/test/bench-colorjs.js +0 -227
- package/test/bench-culori.js +0 -148
- package/test/bench-node.js +0 -51
- package/test/bench-size.js +0 -12
- package/test/canvas-graph.js +0 -212
- package/test/check-gamut-epsilon.js +0 -136
- package/test/colorjs-fn.js +0 -34
- package/test/example-interpolation.js +0 -107
- package/test/logo.js +0 -112
- package/test/logo.png +0 -0
- package/test/profiles/DisplayP3.icc +0 -0
- package/test/spaces/hsl.js +0 -87
- package/test/spaces/lab.js +0 -60
- package/test/test-colorjs.js +0 -86
- package/test/test-other-spaces.js +0 -115
- package/test/test.js +0 -451
- package/tools/__pycache__/calc_oklab_matrices.cpython-311.pyc +0 -0
- package/tools/calc_oklab_matrices.py +0 -233
- package/tools/print_matrices.py +0 -509
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
convert,
|
|
3
|
-
XYZD50,
|
|
4
|
-
sRGB,
|
|
5
|
-
XYZ,
|
|
6
|
-
ProPhotoRGB,
|
|
7
|
-
OKLCH,
|
|
8
|
-
sRGBLinear,
|
|
9
|
-
} from "../src/index.js";
|
|
10
|
-
import { Lab } from "./spaces/lab.js";
|
|
11
|
-
import { HSL } from "./spaces/hsl.js";
|
|
12
|
-
import test from "tape";
|
|
13
|
-
import Color from "colorjs.io";
|
|
14
|
-
import arrayAlmostEqual from "./almost-equal.js";
|
|
15
|
-
|
|
16
|
-
test("should approximately match colorjs.io CIELAB", async (t) => {
|
|
17
|
-
let input = [0.5, 0.1243, -0.123];
|
|
18
|
-
let inputSpace = OKLCH;
|
|
19
|
-
let outputSpace = Lab;
|
|
20
|
-
let expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
21
|
-
let result = convert(input, inputSpace, outputSpace);
|
|
22
|
-
t.deepEqual(expected, result);
|
|
23
|
-
|
|
24
|
-
inputSpace = XYZD50;
|
|
25
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
26
|
-
result = convert(input, inputSpace, outputSpace);
|
|
27
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
28
|
-
|
|
29
|
-
inputSpace = XYZ;
|
|
30
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
31
|
-
result = convert(input, inputSpace, outputSpace);
|
|
32
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
33
|
-
|
|
34
|
-
inputSpace = sRGB;
|
|
35
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
36
|
-
result = convert(input, inputSpace, outputSpace);
|
|
37
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
38
|
-
|
|
39
|
-
inputSpace = ProPhotoRGB;
|
|
40
|
-
expected = new Color("prophoto", input).to(outputSpace.id).coords;
|
|
41
|
-
result = convert(input, inputSpace, outputSpace);
|
|
42
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
43
|
-
|
|
44
|
-
inputSpace = Lab;
|
|
45
|
-
outputSpace = XYZ;
|
|
46
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
47
|
-
result = convert(input, inputSpace, outputSpace);
|
|
48
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
49
|
-
|
|
50
|
-
outputSpace = XYZD50;
|
|
51
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
52
|
-
result = convert(input, inputSpace, outputSpace);
|
|
53
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
54
|
-
|
|
55
|
-
outputSpace = Lab;
|
|
56
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
57
|
-
result = convert(input, inputSpace, outputSpace);
|
|
58
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
59
|
-
|
|
60
|
-
outputSpace = sRGBLinear;
|
|
61
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
62
|
-
result = convert(input, inputSpace, outputSpace);
|
|
63
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
64
|
-
|
|
65
|
-
outputSpace = sRGB;
|
|
66
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
67
|
-
result = convert(input, inputSpace, outputSpace);
|
|
68
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("should approximately match colorjs.io HSL", async (t) => {
|
|
72
|
-
let input = [30, 50, 50];
|
|
73
|
-
let inputSpace = HSL;
|
|
74
|
-
let outputSpace = OKLCH;
|
|
75
|
-
let expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
76
|
-
let result = convert(input, inputSpace, outputSpace);
|
|
77
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
78
|
-
|
|
79
|
-
outputSpace = XYZD50;
|
|
80
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
81
|
-
result = convert(input, inputSpace, outputSpace);
|
|
82
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
83
|
-
|
|
84
|
-
outputSpace = sRGB;
|
|
85
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
86
|
-
result = convert(input, inputSpace, outputSpace);
|
|
87
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
88
|
-
|
|
89
|
-
outputSpace = sRGBLinear;
|
|
90
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
91
|
-
result = convert(input, inputSpace, outputSpace);
|
|
92
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
93
|
-
|
|
94
|
-
input = [0.5, 0.2, 30];
|
|
95
|
-
inputSpace = OKLCH;
|
|
96
|
-
outputSpace = HSL;
|
|
97
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
98
|
-
result = convert(input, inputSpace, outputSpace);
|
|
99
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
100
|
-
|
|
101
|
-
inputSpace = XYZ;
|
|
102
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
103
|
-
result = convert(input, inputSpace, outputSpace);
|
|
104
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
105
|
-
|
|
106
|
-
inputSpace = sRGB;
|
|
107
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
108
|
-
result = convert(input, inputSpace, outputSpace);
|
|
109
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
110
|
-
|
|
111
|
-
inputSpace = sRGBLinear;
|
|
112
|
-
expected = new Color(inputSpace.id, input).to(outputSpace.id).coords;
|
|
113
|
-
result = convert(input, inputSpace, outputSpace);
|
|
114
|
-
t.deepEqual(arrayAlmostEqual(expected, result), true);
|
|
115
|
-
});
|
package/test/test.js
DELETED
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import test from "tape";
|
|
2
|
-
import Color from "colorjs.io";
|
|
3
|
-
import arrayAlmostEqual from "./almost-equal.js";
|
|
4
|
-
import {
|
|
5
|
-
floatToByte,
|
|
6
|
-
hexToRGB,
|
|
7
|
-
isRGBInGamut,
|
|
8
|
-
RGBToHex,
|
|
9
|
-
linear_sRGB_to_LMS_M,
|
|
10
|
-
LMS_to_linear_sRGB_M,
|
|
11
|
-
LMS_to_XYZ_M,
|
|
12
|
-
XYZ_to_linear_sRGB_M,
|
|
13
|
-
XYZ_to_LMS_M,
|
|
14
|
-
convert,
|
|
15
|
-
OKLab,
|
|
16
|
-
OKLCH,
|
|
17
|
-
sRGB,
|
|
18
|
-
sRGBLinear,
|
|
19
|
-
XYZ,
|
|
20
|
-
OKLab_from,
|
|
21
|
-
OKLab_to,
|
|
22
|
-
transform,
|
|
23
|
-
OKHSL,
|
|
24
|
-
sRGBGamut,
|
|
25
|
-
OKHSV,
|
|
26
|
-
serialize,
|
|
27
|
-
gamutMapOKLCH,
|
|
28
|
-
degToRad,
|
|
29
|
-
OKHSLToOKLab,
|
|
30
|
-
OKHSVToOKLab,
|
|
31
|
-
OKLabToOKHSL,
|
|
32
|
-
OKLabToOKHSV,
|
|
33
|
-
XYZD65ToD50,
|
|
34
|
-
XYZD50ToD65,
|
|
35
|
-
XYZD50,
|
|
36
|
-
ProPhotoRGB,
|
|
37
|
-
ProPhotoRGBLinear,
|
|
38
|
-
findCuspOKLCH,
|
|
39
|
-
LMS_to_OKLab_M,
|
|
40
|
-
DisplayP3,
|
|
41
|
-
A98RGB,
|
|
42
|
-
A98RGBLinear,
|
|
43
|
-
XYZ_to_linear_A98RGB_M,
|
|
44
|
-
DisplayP3Gamut,
|
|
45
|
-
deserialize,
|
|
46
|
-
parse,
|
|
47
|
-
} from "../src/index.js";
|
|
48
|
-
|
|
49
|
-
test("should convert XYZ in different whitepoints", async (t) => {
|
|
50
|
-
const oklab = [0.56, 0.03, -0.1];
|
|
51
|
-
const xyz_d65_input = new Color("oklab", oklab).to("xyz").coords;
|
|
52
|
-
const xyz_d50_output = new Color("xyz", xyz_d65_input).to("xyz-d50").coords;
|
|
53
|
-
|
|
54
|
-
let tmp = [0, 0, 0];
|
|
55
|
-
const out = XYZD65ToD50(xyz_d65_input, tmp);
|
|
56
|
-
t.equal(tmp, out);
|
|
57
|
-
t.deepEqual(out, xyz_d50_output);
|
|
58
|
-
|
|
59
|
-
tmp = [0, 0, 0];
|
|
60
|
-
const out2 = XYZD50ToD65(xyz_d50_output, tmp);
|
|
61
|
-
t.deepEqual(out2, xyz_d65_input);
|
|
62
|
-
t.equal(out2, tmp);
|
|
63
|
-
|
|
64
|
-
t.deepEqual(convert(xyz_d50_output, XYZD50, XYZ), xyz_d65_input);
|
|
65
|
-
t.deepEqual(convert(xyz_d65_input, XYZ, XYZD50), xyz_d50_output);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("should convert", async (t) => {
|
|
69
|
-
const oklab = [0.56, 0.03, -0.1];
|
|
70
|
-
const rgbExpected = new Color("oklab", oklab)
|
|
71
|
-
.to("srgb")
|
|
72
|
-
.coords.map((n) => floatToByte(n));
|
|
73
|
-
|
|
74
|
-
const lrgb = OKLab_to(oklab, LMS_to_linear_sRGB_M);
|
|
75
|
-
const rgb = convert(lrgb, sRGBLinear, sRGB).map((f) => floatToByte(f));
|
|
76
|
-
t.deepEqual(rgb, rgbExpected, "oklab to srgb");
|
|
77
|
-
|
|
78
|
-
const inArray = oklab.slice();
|
|
79
|
-
const outArray = OKLab_to(oklab, LMS_to_linear_sRGB_M, inArray);
|
|
80
|
-
t.equal(inArray, outArray);
|
|
81
|
-
|
|
82
|
-
const oklab2 = OKLab_from(lrgb, linear_sRGB_to_LMS_M);
|
|
83
|
-
t.equals(arrayAlmostEqual(oklab, oklab2), true, "linear srgb to oklab");
|
|
84
|
-
|
|
85
|
-
const xyzExpected = new Color("oklab", oklab).to("xyz").coords;
|
|
86
|
-
const xyz0 = OKLab_to(oklab, LMS_to_XYZ_M);
|
|
87
|
-
t.deepEqual(arrayAlmostEqual(xyzExpected, xyz0), true, "OKLab to XYZ");
|
|
88
|
-
|
|
89
|
-
const oklabResult = OKLab_from(xyzExpected, XYZ_to_LMS_M);
|
|
90
|
-
t.deepEqual(arrayAlmostEqual(oklabResult, oklab), true, "XYZ to OKLab");
|
|
91
|
-
|
|
92
|
-
const xyzToLSRGBExpected = new Color("xyz", xyzExpected).to(
|
|
93
|
-
"srgb-linear"
|
|
94
|
-
).coords;
|
|
95
|
-
const xyzToLSRGB = transform(xyzExpected, XYZ_to_linear_sRGB_M);
|
|
96
|
-
t.deepEqual(
|
|
97
|
-
arrayAlmostEqual(xyzToLSRGB, xyzToLSRGBExpected),
|
|
98
|
-
true,
|
|
99
|
-
"XYZ to sRGB-linear"
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// XYZ to sRGBLinear
|
|
103
|
-
const outTest = [0, 0, 0];
|
|
104
|
-
const outTest2 = convert(xyzExpected, XYZ, sRGBLinear, outTest);
|
|
105
|
-
t.equal(outTest, outTest2, "returns out vec3");
|
|
106
|
-
t.deepEqual(outTest, xyzToLSRGB);
|
|
107
|
-
|
|
108
|
-
t.deepEqual(
|
|
109
|
-
convert(xyzExpected, XYZ, sRGB),
|
|
110
|
-
sRGB.fromBase(xyzToLSRGB),
|
|
111
|
-
"XYZ to sRGB"
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const sRGBL_from_XYZ = new Color("xyz", xyzExpected).to("srgb-linear").coords;
|
|
115
|
-
|
|
116
|
-
t.ok(
|
|
117
|
-
arrayAlmostEqual(convert(xyzExpected, XYZ, sRGBLinear), sRGBL_from_XYZ),
|
|
118
|
-
true,
|
|
119
|
-
"XYZ to sRGBLinear"
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
// from https://bottosson.github.io/posts/oklab/
|
|
123
|
-
const knownPairsXYZToOKLab = [
|
|
124
|
-
[
|
|
125
|
-
[0.95, 1, 1.089],
|
|
126
|
-
[1, 0, 0],
|
|
127
|
-
],
|
|
128
|
-
[
|
|
129
|
-
[1, 0, 0],
|
|
130
|
-
[0.45, 1.236, -0.019],
|
|
131
|
-
],
|
|
132
|
-
[
|
|
133
|
-
[0, 1, 0],
|
|
134
|
-
[0.922, -0.671, 0.263],
|
|
135
|
-
],
|
|
136
|
-
[
|
|
137
|
-
[0, 0, 1],
|
|
138
|
-
[0.153, -1.415, -0.449],
|
|
139
|
-
],
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
for (let [xyz, oklabExpected] of knownPairsXYZToOKLab) {
|
|
143
|
-
const oklabRet = convert(xyz, XYZ, OKLab).map((n) => {
|
|
144
|
-
n = roundToNDecimals(n, 3);
|
|
145
|
-
if (n === -0) n = 0;
|
|
146
|
-
return n;
|
|
147
|
-
});
|
|
148
|
-
t.deepEqual(oklabRet, oklabExpected);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const oklch = [0.5, -0.36, 90];
|
|
152
|
-
t.deepEqual(
|
|
153
|
-
convert(oklch, OKLCH, OKLab),
|
|
154
|
-
new Color("oklch", oklch).to("oklab").coords,
|
|
155
|
-
"handle negative chroma"
|
|
156
|
-
);
|
|
157
|
-
t.equal(
|
|
158
|
-
arrayAlmostEqual(
|
|
159
|
-
convert(oklch, OKLCH, sRGB),
|
|
160
|
-
new Color("oklch", oklch).to("srgb").coords
|
|
161
|
-
),
|
|
162
|
-
true
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("should convert to okhsl", async (t) => {
|
|
167
|
-
const okhsl = [30, 0.5, 0.5];
|
|
168
|
-
const oklab = OKHSLToOKLab(okhsl, sRGBGamut);
|
|
169
|
-
const expectedLABfromOKHSL = [
|
|
170
|
-
0.568838198942395, 0.08553885335853362, 0.049385880012721296,
|
|
171
|
-
];
|
|
172
|
-
t.deepEqual(oklab, expectedLABfromOKHSL);
|
|
173
|
-
const okhslOut = OKLabToOKHSL(expectedLABfromOKHSL, sRGBGamut);
|
|
174
|
-
t.deepEqual(okhslOut, okhsl);
|
|
175
|
-
|
|
176
|
-
const okhsv = okhsl.slice();
|
|
177
|
-
const expectedLABfromOKHSV = [
|
|
178
|
-
0.45178419415172344, 0.0658295198906634, 0.03800669102949832,
|
|
179
|
-
];
|
|
180
|
-
t.deepEqual(OKHSVToOKLab(okhsv, sRGBGamut), expectedLABfromOKHSV);
|
|
181
|
-
t.deepEqual(
|
|
182
|
-
arrayAlmostEqual(OKLabToOKHSV(expectedLABfromOKHSV, sRGBGamut), okhsv),
|
|
183
|
-
true
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
t.deepEqual(convert(okhsl, OKHSL, OKLab), expectedLABfromOKHSL);
|
|
187
|
-
t.deepEqual(convert(okhsv, OKHSV, OKLab), expectedLABfromOKHSV);
|
|
188
|
-
t.deepEqual(
|
|
189
|
-
arrayAlmostEqual(convert(expectedLABfromOKHSV, OKLab, OKHSV), okhsv),
|
|
190
|
-
true
|
|
191
|
-
);
|
|
192
|
-
t.deepEqual(
|
|
193
|
-
arrayAlmostEqual(convert(expectedLABfromOKHSL, OKLab, OKHSL), okhsl),
|
|
194
|
-
true
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("should find cusp", async (t) => {
|
|
199
|
-
const H = 30;
|
|
200
|
-
const hueAngle = degToRad(H);
|
|
201
|
-
|
|
202
|
-
const aNorm = Math.cos(hueAngle);
|
|
203
|
-
const bNorm = Math.sin(hueAngle);
|
|
204
|
-
const out2 = [0, 0];
|
|
205
|
-
const cusp = findCuspOKLCH(aNorm, bNorm, sRGBGamut, out2);
|
|
206
|
-
const hue30sRGBCusp = [0.6322837041534408, 0.2535829789121266];
|
|
207
|
-
|
|
208
|
-
t.equal(out2, cusp);
|
|
209
|
-
t.deepEqual(cusp, hue30sRGBCusp);
|
|
210
|
-
|
|
211
|
-
const cuspP3 = findCuspOKLCH(aNorm, bNorm, DisplayP3Gamut, out2);
|
|
212
|
-
const hue30P3Cusp = [0.6542359095783624, 0.2931937837912358];
|
|
213
|
-
t.equal(out2, cuspP3);
|
|
214
|
-
t.deepEqual(cuspP3, hue30P3Cusp);
|
|
215
|
-
|
|
216
|
-
const l2 = 0.7;
|
|
217
|
-
const c2 = 0.3;
|
|
218
|
-
const newLCH = [l2, c2, H];
|
|
219
|
-
const mapped = gamutMapOKLCH(newLCH, sRGBGamut, OKLCH);
|
|
220
|
-
t.deepEqual(mapped, [0.679529110489262, 0.2093088779230169, 30]);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test("should gamut map", async (t) => {
|
|
224
|
-
const oklch = [0.9, 0.4, 30];
|
|
225
|
-
const rgb = convert(oklch, OKLCH, sRGB);
|
|
226
|
-
t.equals(isRGBInGamut(rgb, 0), false);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test("should serialize", async (t) => {
|
|
230
|
-
t.deepEqual(serialize([0, 0.5, 1], sRGB), "rgb(0, 128, 255)");
|
|
231
|
-
t.deepEqual(serialize([0, 0.5, 1], sRGBLinear), "color(srgb-linear 0 0.5 1)");
|
|
232
|
-
t.deepEqual(serialize([1, 0, 0], OKLCH, sRGB), "rgb(255, 255, 255)");
|
|
233
|
-
t.deepEqual(serialize([1, 0, 0], OKLCH), "oklch(100% 0 0)");
|
|
234
|
-
t.deepEqual(serialize([1, 0, 0], OKLab), "oklab(100% 0 0)");
|
|
235
|
-
t.deepEqual(
|
|
236
|
-
serialize([1, 0, 0, 0.4523], OKLCH, sRGB),
|
|
237
|
-
"rgba(255, 255, 255, 0.4523)"
|
|
238
|
-
);
|
|
239
|
-
t.deepEqual(
|
|
240
|
-
serialize([1, 0, 0, 0.4523], OKLCH, OKLCH),
|
|
241
|
-
"oklch(100% 0 0 / 0.4523)"
|
|
242
|
-
);
|
|
243
|
-
t.deepEqual(serialize([1, 0, 0, 0.4523], OKLCH), "oklch(100% 0 0 / 0.4523)");
|
|
244
|
-
t.deepEqual(
|
|
245
|
-
serialize([1, 0, 0, 0.4523], DisplayP3),
|
|
246
|
-
"color(display-p3 1 0 0 / 0.4523)"
|
|
247
|
-
);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
// not yet finished
|
|
251
|
-
// test("should parse to a color coord", async (t) => {
|
|
252
|
-
// t.deepEqual(parse("rgb(0, 128, 255)", sRGB), [0, 128 / 0xff, 255 / 0xff]);
|
|
253
|
-
// t.deepEqual(parse("rgba(0, 128, 255, .25)", sRGB), [
|
|
254
|
-
// 0,
|
|
255
|
-
// 128 / 0xff,
|
|
256
|
-
// 255 / 0xff,
|
|
257
|
-
// 0.25,
|
|
258
|
-
// ]);
|
|
259
|
-
// let outVec = [0, 0, 0];
|
|
260
|
-
// t.deepEqual(parse("rgba(0, 128, 255, 1)", sRGB), [0, 128 / 0xff, 255 / 0xff]);
|
|
261
|
-
// let out;
|
|
262
|
-
// out = parse("rgba(0, 128, 255, 1)", sRGB, outVec);
|
|
263
|
-
// t.deepEqual(out, [0, 128 / 0xff, 255 / 0xff]);
|
|
264
|
-
// t.equal(out, outVec);
|
|
265
|
-
|
|
266
|
-
// // trims to 3
|
|
267
|
-
// outVec = [0, 0, 0, 0];
|
|
268
|
-
// out = parse("rgba(0, 128, 255, 1)", sRGB, outVec);
|
|
269
|
-
// t.deepEqual(out, [0, 128 / 0xff, 255 / 0xff]);
|
|
270
|
-
// t.equal(out, outVec);
|
|
271
|
-
|
|
272
|
-
// // ensures 4
|
|
273
|
-
// outVec = [0, 0, 0, 0];
|
|
274
|
-
// out = parse("rgba(0, 128, 255, 0.91)", sRGB, outVec);
|
|
275
|
-
// t.deepEqual(out, [0, 128 / 0xff, 255 / 0xff, 0.91]);
|
|
276
|
-
// t.equal(out, outVec);
|
|
277
|
-
|
|
278
|
-
// t.deepEqual(
|
|
279
|
-
// serialize(parse("oklch(1 0 0)", sRGB), sRGB),
|
|
280
|
-
// "rgb(255, 255, 255)"
|
|
281
|
-
// );
|
|
282
|
-
// });
|
|
283
|
-
|
|
284
|
-
test("should deserialize color string information", async (t) => {
|
|
285
|
-
|
|
286
|
-
t.deepEqual(deserialize("rgb(0, 128, 255)"), {
|
|
287
|
-
coords: [0, 128 / 0xff, 255 / 0xff],
|
|
288
|
-
id: "srgb",
|
|
289
|
-
});
|
|
290
|
-
t.deepEqual(deserialize("rgba(0, 128, 255)"), {
|
|
291
|
-
coords: [0, 128 / 0xff, 255 / 0xff],
|
|
292
|
-
id: "srgb",
|
|
293
|
-
});
|
|
294
|
-
t.deepEqual(deserialize("rgba(0, 128, 255, 50%)"), {
|
|
295
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.5],
|
|
296
|
-
id: "srgb",
|
|
297
|
-
});
|
|
298
|
-
t.deepEqual(deserialize("rgb(0, 128, 255, 0.5)"), {
|
|
299
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.5],
|
|
300
|
-
id: "srgb",
|
|
301
|
-
});
|
|
302
|
-
t.deepEqual(deserialize("rgb(0 128 255)"), {
|
|
303
|
-
coords: [0, 128 / 0xff, 255 / 0xff],
|
|
304
|
-
id: "srgb",
|
|
305
|
-
});
|
|
306
|
-
t.deepEqual(deserialize("rgb(0 128 255 / 0.5)"), {
|
|
307
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.5],
|
|
308
|
-
id: "srgb",
|
|
309
|
-
});
|
|
310
|
-
t.deepEqual(deserialize("rgb(0 128 255 / 50%)"), {
|
|
311
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.5],
|
|
312
|
-
id: "srgb",
|
|
313
|
-
});
|
|
314
|
-
t.deepEqual(deserialize("rgb(0 128 255 / 0.35)"), {
|
|
315
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.35],
|
|
316
|
-
id: "srgb",
|
|
317
|
-
});
|
|
318
|
-
t.deepEqual(deserialize("RGBA(0 128 255 / 0.35)"), {
|
|
319
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.35],
|
|
320
|
-
id: "srgb",
|
|
321
|
-
});
|
|
322
|
-
t.deepEqual(deserialize("rgba(0, 128, 255, 0.35)"), {
|
|
323
|
-
coords: [0, 128 / 0xff, 255 / 0xff, 0.35],
|
|
324
|
-
id: "srgb",
|
|
325
|
-
});
|
|
326
|
-
t.deepEqual(deserialize("#ff00cc"), {
|
|
327
|
-
id: "srgb",
|
|
328
|
-
coords: [1, 0, 0.8],
|
|
329
|
-
});
|
|
330
|
-
t.deepEqual(deserialize("#ff00cccc"), {
|
|
331
|
-
id: "srgb",
|
|
332
|
-
coords: [1, 0, 0.8, 0.8],
|
|
333
|
-
});
|
|
334
|
-
t.deepEqual(deserialize("COLOR(sRGB-Linear 0 0.5 1)"), {
|
|
335
|
-
id: "srgb-linear",
|
|
336
|
-
coords: [0, 0.5, 1],
|
|
337
|
-
});
|
|
338
|
-
t.deepEqual(deserialize("COLOR(sRGB-Linear 0 50% 1)"), {
|
|
339
|
-
id: "srgb-linear",
|
|
340
|
-
coords: [0, 0.5, 1],
|
|
341
|
-
});
|
|
342
|
-
t.deepEqual(deserialize("color(srgb-linear 0 0.5 1)"), {
|
|
343
|
-
id: "srgb-linear",
|
|
344
|
-
coords: [0, 0.5, 1],
|
|
345
|
-
});
|
|
346
|
-
t.deepEqual(deserialize("color(srgb-linear 0 0.5 1/0.25)"), {
|
|
347
|
-
id: "srgb-linear",
|
|
348
|
-
coords: [0, 0.5, 1, 0.25],
|
|
349
|
-
});
|
|
350
|
-
t.deepEqual(deserialize("color(srgb-linear 0 0.5 1 / 0.25)"), {
|
|
351
|
-
id: "srgb-linear",
|
|
352
|
-
coords: [0, 0.5, 1, 0.25],
|
|
353
|
-
});
|
|
354
|
-
t.deepEqual(deserialize("oklch(1 0 0)"), {
|
|
355
|
-
id: "oklch",
|
|
356
|
-
coords: [1, 0, 0],
|
|
357
|
-
});
|
|
358
|
-
t.deepEqual(deserialize("oklch(1 0 0/0.25)"), {
|
|
359
|
-
id: "oklch",
|
|
360
|
-
coords: [1, 0, 0, 0.25],
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
test("utils", async (t) => {
|
|
365
|
-
t.deepEqual(RGBToHex([0, 0.5, 1]), "#0080ff");
|
|
366
|
-
t.deepEqual(hexToRGB("#0080ff"), [0, 0.5019607843137255, 1]);
|
|
367
|
-
const tmp = [0, 0, 0];
|
|
368
|
-
hexToRGB("#0080ff", tmp);
|
|
369
|
-
t.deepEqual(tmp, [0, 0.5019607843137255, 1]);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
test("should convert D65 based to D50 based color spaces", async (t) => {
|
|
373
|
-
const rgbin = [0.25, 0.5, 1];
|
|
374
|
-
const xyzD65Input = new Color("srgb", rgbin).to("xyz-d65").coords;
|
|
375
|
-
const xyzD50Input = XYZD65ToD50(xyzD65Input);
|
|
376
|
-
|
|
377
|
-
const prophotoFromXYZD65_expected = new Color("xyz-d65", xyzD65Input).to(
|
|
378
|
-
"prophoto-linear"
|
|
379
|
-
).coords;
|
|
380
|
-
|
|
381
|
-
const ret = convert(xyzD65Input, XYZ, ProPhotoRGBLinear);
|
|
382
|
-
t.deepEqual(ret, prophotoFromXYZD65_expected);
|
|
383
|
-
|
|
384
|
-
const xyzD65 = convert(prophotoFromXYZD65_expected, ProPhotoRGBLinear, XYZ);
|
|
385
|
-
t.deepEqual(arrayAlmostEqual(xyzD65, xyzD65Input), true);
|
|
386
|
-
|
|
387
|
-
const prophoto2 = convert(rgbin, sRGB, ProPhotoRGBLinear);
|
|
388
|
-
const prophotoExpected = new Color("srgb", rgbin).to(
|
|
389
|
-
"prophoto-linear"
|
|
390
|
-
).coords;
|
|
391
|
-
t.deepEqual(arrayAlmostEqual(prophoto2, prophotoExpected), true);
|
|
392
|
-
|
|
393
|
-
const oklabIn = new Color("srgb", rgbin).to("oklab").coords;
|
|
394
|
-
const oklabToProphoto = new Color("oklab", oklabIn).to(
|
|
395
|
-
"prophoto-linear"
|
|
396
|
-
).coords;
|
|
397
|
-
t.deepEqual(
|
|
398
|
-
arrayAlmostEqual(
|
|
399
|
-
convert(oklabIn, OKLab, ProPhotoRGBLinear),
|
|
400
|
-
oklabToProphoto
|
|
401
|
-
),
|
|
402
|
-
true
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
const oklabIn2 = [1, 1, 1];
|
|
406
|
-
const oklabToProphoto2 = new Color("oklab", oklabIn2).to("prophoto").coords;
|
|
407
|
-
|
|
408
|
-
t.deepEqual(
|
|
409
|
-
arrayAlmostEqual(convert(oklabIn2, OKLab, ProPhotoRGB), oklabToProphoto2),
|
|
410
|
-
true
|
|
411
|
-
);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
test("should handle problematic coords", async (t) => {
|
|
415
|
-
const in0 = [0.95, 1, 1.089];
|
|
416
|
-
const out0 = convert(in0, XYZ, OKLab);
|
|
417
|
-
const expected0lab = new Color("xyz", in0).to("oklab").coords;
|
|
418
|
-
t.deepEqual(arrayAlmostEqual(out0, expected0lab), true);
|
|
419
|
-
const inP3 = [0, 0, 1];
|
|
420
|
-
const outXYZ = convert(inP3, DisplayP3, XYZ);
|
|
421
|
-
t.deepEqual(
|
|
422
|
-
arrayAlmostEqual(outXYZ, new Color("p3", inP3).to("xyz").coords),
|
|
423
|
-
true
|
|
424
|
-
);
|
|
425
|
-
const outA98 = convert(outXYZ, XYZ, A98RGBLinear);
|
|
426
|
-
t.deepEqual(
|
|
427
|
-
arrayAlmostEqual(
|
|
428
|
-
outA98,
|
|
429
|
-
new Color("xyz", outXYZ).to("a98rgb-linear").coords
|
|
430
|
-
),
|
|
431
|
-
true
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
// Failing test here, but it appears Colorjs does not match the latest
|
|
435
|
-
// CSS spec (working draft with rational form). Please open a PR/issue if you
|
|
436
|
-
// think you could help, but unless I'm mistaken it seems to be an upstream issue
|
|
437
|
-
const tolerance = 0.0000001;
|
|
438
|
-
t.deepEqual(
|
|
439
|
-
arrayAlmostEqual(
|
|
440
|
-
convert(inP3, DisplayP3, A98RGB),
|
|
441
|
-
new Color("p3", inP3).to("a98rgb").coords,
|
|
442
|
-
tolerance
|
|
443
|
-
),
|
|
444
|
-
true
|
|
445
|
-
);
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
function roundToNDecimals(value, digits) {
|
|
449
|
-
var tenToN = 10 ** digits;
|
|
450
|
-
return Math.round(value * tenToN) / tenToN;
|
|
451
|
-
}
|
|
Binary file
|