@voryx/color 1.0.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/Color.d.ts +47 -0
- package/dist/Color.d.ts.map +1 -0
- package/dist/Color.js +551 -0
- package/dist/encode.d.ts +9 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/encode.js +60 -0
- package/dist/gamut/inGamut.d.ts +6 -0
- package/dist/gamut/inGamut.d.ts.map +1 -0
- package/dist/gamut/inGamut.js +25 -0
- package/dist/gamut/map.d.ts +8 -0
- package/dist/gamut/map.d.ts.map +1 -0
- package/dist/gamut/map.js +70 -0
- package/dist/gamut/types.d.ts +2 -0
- package/dist/gamut/types.d.ts.map +1 -0
- package/dist/gamut/types.js +0 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/misc.d.ts +24 -0
- package/dist/misc.d.ts.map +1 -0
- package/dist/misc.js +38 -0
- package/dist/spaces/HSL.d.ts +9 -0
- package/dist/spaces/HSL.d.ts.map +1 -0
- package/dist/spaces/HSL.js +69 -0
- package/dist/spaces/LMS.d.ts +7 -0
- package/dist/spaces/LMS.d.ts.map +1 -0
- package/dist/spaces/LMS.js +0 -0
- package/dist/spaces/OKLAB.d.ts +9 -0
- package/dist/spaces/OKLAB.d.ts.map +1 -0
- package/dist/spaces/OKLAB.js +62 -0
- package/dist/spaces/OKLCH.d.ts +9 -0
- package/dist/spaces/OKLCH.d.ts.map +1 -0
- package/dist/spaces/OKLCH.js +35 -0
- package/dist/spaces/P3.d.ts +12 -0
- package/dist/spaces/P3.d.ts.map +1 -0
- package/dist/spaces/P3.js +58 -0
- package/dist/spaces/RGB.d.ts +9 -0
- package/dist/spaces/RGB.d.ts.map +1 -0
- package/dist/spaces/RGB.js +21 -0
- package/dist/spaces/SRGB.d.ts +11 -0
- package/dist/spaces/SRGB.d.ts.map +1 -0
- package/dist/spaces/SRGB.js +63 -0
- package/dist/spaces/types.d.ts +6 -0
- package/dist/spaces/types.d.ts.map +1 -0
- package/dist/spaces/types.js +0 -0
- package/dist/transforms.d.ts +13 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +25 -0
- package/package.json +36 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SRGB } from "../spaces/SRGB.js";
|
|
2
|
+
import { P3 } from "../spaces/P3.js";
|
|
3
|
+
function isRGBInGamut(rgb, epsilon = 1e-7) {
|
|
4
|
+
return rgb[0] >= -epsilon && rgb[0] <= 1 + epsilon && rgb[1] >= -epsilon && rgb[1] <= 1 + epsilon && rgb[2] >= -epsilon && rgb[2] <= 1 + epsilon;
|
|
5
|
+
}
|
|
6
|
+
function lmsToGamutRGB(lms, gamut) {
|
|
7
|
+
switch(gamut){
|
|
8
|
+
case 'srgb':
|
|
9
|
+
return SRGB.fromLMS(lms);
|
|
10
|
+
case 'p3':
|
|
11
|
+
return P3.fromLMS(lms);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function gamutRGBToLMS(rgb, gamut) {
|
|
15
|
+
switch(gamut){
|
|
16
|
+
case 'srgb':
|
|
17
|
+
return SRGB.toLMS(rgb);
|
|
18
|
+
case 'p3':
|
|
19
|
+
return P3.toLMS(rgb);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function inGamut(lms, gamut, epsilon) {
|
|
23
|
+
return isRGBInGamut(lmsToGamutRGB(lms, gamut), epsilon);
|
|
24
|
+
}
|
|
25
|
+
export { gamutRGBToLMS, inGamut, isRGBInGamut, lmsToGamutRGB };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RGBGamut } from './types';
|
|
2
|
+
export declare const JND = 0.02;
|
|
3
|
+
export declare const EPSILON = 0.0001;
|
|
4
|
+
export declare function mapToGamut(lms: [number, number, number, number], gamut: RGBGamut, options?: {
|
|
5
|
+
jnd?: number;
|
|
6
|
+
epsilon?: number;
|
|
7
|
+
}): [number, number, number, number];
|
|
8
|
+
//# sourceMappingURL=map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/gamut/map.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvC,eAAO,MAAM,GAAG,OAAO,CAAA;AACvB,eAAO,MAAM,OAAO,SAAS,CAAA;AA+B7B,wBAAgB,UAAU,CACxB,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACrC,KAAK,EAAE,QAAQ,EACf,OAAO,GAAE;IACP,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACZ,GACL,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CA0JlC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { OKLCH } from "../spaces/OKLCH.js";
|
|
2
|
+
import { OKLAB } from "../spaces/OKLAB.js";
|
|
3
|
+
import { gamutRGBToLMS, inGamut, lmsToGamutRGB } from "./inGamut.js";
|
|
4
|
+
import { clamp01 } from "../misc.js";
|
|
5
|
+
const JND = 0.02;
|
|
6
|
+
const EPSILON = 0.0001;
|
|
7
|
+
function deltaEOK(a, b) {
|
|
8
|
+
const dl = a[0] - b[0];
|
|
9
|
+
const da = a[1] - b[1];
|
|
10
|
+
const db = a[2] - b[2];
|
|
11
|
+
return Math.sqrt(dl * dl + da * da + db * db);
|
|
12
|
+
}
|
|
13
|
+
function clippedLMS(lms, gamut) {
|
|
14
|
+
const rgb = lmsToGamutRGB(lms, gamut);
|
|
15
|
+
return gamutRGBToLMS([
|
|
16
|
+
clamp01(rgb[0]),
|
|
17
|
+
clamp01(rgb[1]),
|
|
18
|
+
clamp01(rgb[2]),
|
|
19
|
+
rgb[3]
|
|
20
|
+
], gamut);
|
|
21
|
+
}
|
|
22
|
+
function mapToGamut(lms, gamut, options = {}) {
|
|
23
|
+
const { jnd = JND, epsilon = EPSILON } = options;
|
|
24
|
+
const origin = OKLCH.fromLMS(lms);
|
|
25
|
+
if (origin[0] >= 1) return OKLAB.toLMS([
|
|
26
|
+
1,
|
|
27
|
+
0,
|
|
28
|
+
0,
|
|
29
|
+
1
|
|
30
|
+
]);
|
|
31
|
+
if (origin[0] <= 0) return OKLAB.toLMS([
|
|
32
|
+
0,
|
|
33
|
+
0,
|
|
34
|
+
0,
|
|
35
|
+
1
|
|
36
|
+
]);
|
|
37
|
+
if (inGamut(lms, gamut, epsilon)) return lms;
|
|
38
|
+
let clipped = clippedLMS(lms, gamut);
|
|
39
|
+
let delta = deltaEOK(OKLAB.fromLMS(lms), OKLAB.fromLMS(clipped));
|
|
40
|
+
if (delta < jnd) return clipped;
|
|
41
|
+
let min = 0;
|
|
42
|
+
let max = origin[1];
|
|
43
|
+
let minInGamut = true;
|
|
44
|
+
let current = [
|
|
45
|
+
...origin
|
|
46
|
+
];
|
|
47
|
+
while(max - min > epsilon){
|
|
48
|
+
const chroma = (min + max) / 2;
|
|
49
|
+
current = [
|
|
50
|
+
origin[0],
|
|
51
|
+
chroma,
|
|
52
|
+
origin[2],
|
|
53
|
+
origin[3]
|
|
54
|
+
];
|
|
55
|
+
const currentLMS = OKLCH.toLMS(current);
|
|
56
|
+
if (minInGamut && inGamut(currentLMS, gamut)) {
|
|
57
|
+
min = chroma;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
clipped = clippedLMS(currentLMS, gamut);
|
|
61
|
+
delta = deltaEOK(OKLAB.fromLMS(currentLMS), OKLAB.fromLMS(clipped));
|
|
62
|
+
if (delta < jnd) {
|
|
63
|
+
if (jnd - delta < epsilon) return clipped;
|
|
64
|
+
minInGamut = false;
|
|
65
|
+
min = chroma;
|
|
66
|
+
} else max = chroma;
|
|
67
|
+
}
|
|
68
|
+
return clipped;
|
|
69
|
+
}
|
|
70
|
+
export { EPSILON, JND, mapToGamut };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/gamut/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA"}
|
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './Color';
|
|
2
|
+
export type { ColorSpace } from './spaces/types';
|
|
3
|
+
export type { SRGBComponents } from './spaces/SRGB';
|
|
4
|
+
export type { RGBComponents } from './spaces/RGB';
|
|
5
|
+
export type { P3Components } from './spaces/P3';
|
|
6
|
+
export type { OKLABComponents } from './spaces/OKLAB';
|
|
7
|
+
export type { OKLCHComponents } from './spaces/OKLCH';
|
|
8
|
+
export type { HSLComponents } from './spaces/HSL';
|
|
9
|
+
export type { LMSComponents } from './spaces/LMS';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAA;AACvB,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Color.js";
|
package/dist/misc.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Matrix3x3 = [
|
|
2
|
+
[
|
|
3
|
+
number,
|
|
4
|
+
number,
|
|
5
|
+
number
|
|
6
|
+
],
|
|
7
|
+
[
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number
|
|
16
|
+
]
|
|
17
|
+
];
|
|
18
|
+
export declare function multiplyMatrix3x3Vector3(matrix: Matrix3x3, vector: [number, number, number]): [number, number, number];
|
|
19
|
+
export declare function multiplyMatrixWithAlpha(matrix: Matrix3x3, components: [number, number, number, number]): [number, number, number, number];
|
|
20
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
21
|
+
export declare function clamp01(value: number): number;
|
|
22
|
+
export declare function roundToPrecision(value: number, precision: number): number;
|
|
23
|
+
export declare function normalizeAngle(x: number): number;
|
|
24
|
+
//# sourceMappingURL=misc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG;IACtB;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;KAAC;IACxB;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;KAAC;IACxB;QAAC,MAAM;QAAE,MAAM;QAAE,MAAM;KAAC;CACzB,CAAA;AAED,wBAAgB,wBAAwB,CAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAKvH;AAED,wBAAgB,uBAAuB,CAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAG1I;AAED,wBAAgB,KAAK,CAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,OAAO,CAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,gBAAgB,CAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG1E;AAED,wBAAgB,cAAc,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGjD"}
|
package/dist/misc.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function multiplyMatrix3x3Vector3(matrix, vector) {
|
|
2
|
+
const x = matrix[0][0] * vector[0] + matrix[0][1] * vector[1] + matrix[0][2] * vector[2];
|
|
3
|
+
const y = matrix[1][0] * vector[0] + matrix[1][1] * vector[1] + matrix[1][2] * vector[2];
|
|
4
|
+
const z = matrix[2][0] * vector[0] + matrix[2][1] * vector[1] + matrix[2][2] * vector[2];
|
|
5
|
+
return [
|
|
6
|
+
x,
|
|
7
|
+
y,
|
|
8
|
+
z
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
function multiplyMatrixWithAlpha(matrix, components) {
|
|
12
|
+
const result = multiplyMatrix3x3Vector3(matrix, [
|
|
13
|
+
components[0],
|
|
14
|
+
components[1],
|
|
15
|
+
components[2]
|
|
16
|
+
]);
|
|
17
|
+
return [
|
|
18
|
+
result[0],
|
|
19
|
+
result[1],
|
|
20
|
+
result[2],
|
|
21
|
+
components[3]
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
function clamp(value, min, max) {
|
|
25
|
+
return Math.min(Math.max(value, min), max);
|
|
26
|
+
}
|
|
27
|
+
function clamp01(value) {
|
|
28
|
+
return clamp(value, 0, 1);
|
|
29
|
+
}
|
|
30
|
+
function roundToPrecision(value, precision) {
|
|
31
|
+
const factor = Math.pow(10, precision);
|
|
32
|
+
return Math.round(value * factor) / factor;
|
|
33
|
+
}
|
|
34
|
+
function normalizeAngle(x) {
|
|
35
|
+
const result = x % 360;
|
|
36
|
+
return result < 0 ? result + 360 : result;
|
|
37
|
+
}
|
|
38
|
+
export { clamp, clamp01, multiplyMatrix3x3Vector3, multiplyMatrixWithAlpha, normalizeAngle, roundToPrecision };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HSL.d.ts","sourceRoot":"","sources":["../../src/spaces/HSL.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG/C,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,GAAG,EAAE,gBAoBjB,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SRGB } from "./SRGB.js";
|
|
2
|
+
const HSL = {
|
|
3
|
+
toLMS (components) {
|
|
4
|
+
const comps = hsl_to_rgb([
|
|
5
|
+
components[0],
|
|
6
|
+
components[1],
|
|
7
|
+
components[2],
|
|
8
|
+
components[3] ?? 1
|
|
9
|
+
]);
|
|
10
|
+
return SRGB.toLMS([
|
|
11
|
+
comps[0],
|
|
12
|
+
comps[1],
|
|
13
|
+
comps[2],
|
|
14
|
+
comps[3]
|
|
15
|
+
]);
|
|
16
|
+
},
|
|
17
|
+
fromLMS (components) {
|
|
18
|
+
const rgb = SRGB.fromLMS(components);
|
|
19
|
+
return rgb_to_hsl([
|
|
20
|
+
rgb[0],
|
|
21
|
+
rgb[1],
|
|
22
|
+
rgb[2],
|
|
23
|
+
rgb[3]
|
|
24
|
+
], true);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function hsl_to_rgb([h, s, l, alpha]) {
|
|
28
|
+
let sat = 0.01 * s;
|
|
29
|
+
let light = 0.01 * l;
|
|
30
|
+
let a = sat * Math.min(light, 1.0 - light);
|
|
31
|
+
let f = (n)=>{
|
|
32
|
+
let x = n + 1.0 / 30.0 * h;
|
|
33
|
+
let k = x - 12.0 * Math.floor(1.0 / 12.0 * x);
|
|
34
|
+
return light - a * Math.max(Math.min(k - 3.0, 9.0 - k, 1.0), -1);
|
|
35
|
+
};
|
|
36
|
+
return [
|
|
37
|
+
f(0),
|
|
38
|
+
f(8),
|
|
39
|
+
f(4),
|
|
40
|
+
alpha
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
function rgb_to_hsl([r, g, b, a], hue_hack) {
|
|
44
|
+
let max = Math.max(r, g, b);
|
|
45
|
+
let min = Math.min(r, g, b);
|
|
46
|
+
let hue = 0.0;
|
|
47
|
+
let sat = 0.0;
|
|
48
|
+
const light = 0.5 * (min + max);
|
|
49
|
+
const d = max - min;
|
|
50
|
+
const EPSILON = 1e-6;
|
|
51
|
+
if (d > EPSILON) {
|
|
52
|
+
const denom = Math.min(light, 1.0 - light);
|
|
53
|
+
if (Math.abs(denom) > EPSILON) sat = (max - light) / denom;
|
|
54
|
+
hue = max === r ? (g - b) / d : max === g ? (b - r) / d + 2.0 : (r - g) / d + 4.0;
|
|
55
|
+
hue *= 60.0;
|
|
56
|
+
if (hue_hack && sat < 0.0) {
|
|
57
|
+
hue += 180.0;
|
|
58
|
+
sat = Math.abs(sat);
|
|
59
|
+
}
|
|
60
|
+
hue -= 360.0 * Math.floor(1.0 / 360.0 * hue);
|
|
61
|
+
}
|
|
62
|
+
return [
|
|
63
|
+
hue,
|
|
64
|
+
100.0 * sat,
|
|
65
|
+
100.0 * light,
|
|
66
|
+
a
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
export { HSL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LMS.d.ts","sourceRoot":"","sources":["../../src/spaces/LMS.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OKLAB.d.ts","sourceRoot":"","sources":["../../src/spaces/OKLAB.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAiB/C,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,KAAK,EAAE,gBAoBnB,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CubeRoot } from "../transforms.js";
|
|
2
|
+
import { multiplyMatrixWithAlpha } from "../misc.js";
|
|
3
|
+
const OKLAB_MATRIX = [
|
|
4
|
+
[
|
|
5
|
+
0.2104542553,
|
|
6
|
+
0.793617785,
|
|
7
|
+
-0.0040720468
|
|
8
|
+
],
|
|
9
|
+
[
|
|
10
|
+
1.9779984951,
|
|
11
|
+
-2.428592205,
|
|
12
|
+
0.4505937099
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
0.0259040371,
|
|
16
|
+
0.7827717662,
|
|
17
|
+
-0.808675766
|
|
18
|
+
]
|
|
19
|
+
];
|
|
20
|
+
const OKLAB_INVERSE_MATRIX = [
|
|
21
|
+
[
|
|
22
|
+
1.0,
|
|
23
|
+
0.3963377774,
|
|
24
|
+
0.2158037580607588
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
1.0,
|
|
28
|
+
-0.1055613458,
|
|
29
|
+
-0.06385417477170591
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
1.0,
|
|
33
|
+
-0.0894841775,
|
|
34
|
+
-1.291485548
|
|
35
|
+
]
|
|
36
|
+
];
|
|
37
|
+
const OKLAB = {
|
|
38
|
+
toLMS (components) {
|
|
39
|
+
const lmsVector = multiplyMatrixWithAlpha(OKLAB_INVERSE_MATRIX, components);
|
|
40
|
+
return [
|
|
41
|
+
CubeRoot.inverse(lmsVector[0]),
|
|
42
|
+
CubeRoot.inverse(lmsVector[1]),
|
|
43
|
+
CubeRoot.inverse(lmsVector[2]),
|
|
44
|
+
components[3]
|
|
45
|
+
];
|
|
46
|
+
},
|
|
47
|
+
fromLMS (components) {
|
|
48
|
+
const labVector = multiplyMatrixWithAlpha(OKLAB_MATRIX, [
|
|
49
|
+
CubeRoot.op(components[0]),
|
|
50
|
+
CubeRoot.op(components[1]),
|
|
51
|
+
CubeRoot.op(components[2]),
|
|
52
|
+
components[3]
|
|
53
|
+
]);
|
|
54
|
+
return [
|
|
55
|
+
labVector[0],
|
|
56
|
+
labVector[1],
|
|
57
|
+
labVector[2],
|
|
58
|
+
labVector[3]
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export { OKLAB };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OKLCH.d.ts","sourceRoot":"","sources":["../../src/spaces/OKLCH.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG/C,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,KAAK,EAAE,gBA0BnB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OKLAB } from "./OKLAB.js";
|
|
2
|
+
const OKLCH = {
|
|
3
|
+
toLMS (components) {
|
|
4
|
+
const l = components[0];
|
|
5
|
+
const c = components[1];
|
|
6
|
+
const h = components[2];
|
|
7
|
+
const a = c * Math.cos(h * Math.PI / 180);
|
|
8
|
+
const b = c * Math.sin(h * Math.PI / 180);
|
|
9
|
+
return OKLAB.toLMS([
|
|
10
|
+
l,
|
|
11
|
+
a,
|
|
12
|
+
b,
|
|
13
|
+
components[3]
|
|
14
|
+
]);
|
|
15
|
+
},
|
|
16
|
+
fromLMS (components) {
|
|
17
|
+
const labComponents = OKLAB.fromLMS(components);
|
|
18
|
+
const l = labComponents[0];
|
|
19
|
+
const a = labComponents[1];
|
|
20
|
+
const b = labComponents[2];
|
|
21
|
+
const c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
|
|
22
|
+
const h = normalizeAngle(180 * Math.atan2(b, a) / Math.PI);
|
|
23
|
+
return [
|
|
24
|
+
l,
|
|
25
|
+
c,
|
|
26
|
+
h,
|
|
27
|
+
labComponents[3]
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function normalizeAngle(x) {
|
|
32
|
+
const result = x % 360;
|
|
33
|
+
return result < 0 ? result + 360 : result;
|
|
34
|
+
}
|
|
35
|
+
export { OKLCH };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ColorSpaceHelper } from './types';
|
|
2
|
+
import { type Matrix3x3 } from '../misc';
|
|
3
|
+
export declare const P3_MATRIX: Matrix3x3;
|
|
4
|
+
export declare const P3_INVERSE_MATRIX: Matrix3x3;
|
|
5
|
+
export interface P3Components {
|
|
6
|
+
p3Red: number;
|
|
7
|
+
green: number;
|
|
8
|
+
blue: number;
|
|
9
|
+
alpha: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const P3: ColorSpaceHelper;
|
|
12
|
+
//# sourceMappingURL=P3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"P3.d.ts","sourceRoot":"","sources":["../../src/spaces/P3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,SAAS,CAAA;AAIjE,eAAO,MAAM,SAAS,EAAE,SAIvB,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,SAI/B,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,EAAE,EAAE,gBAsBhB,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { multiplyMatrixWithAlpha } from "../misc.js";
|
|
2
|
+
import { GammaCorrection } from "../transforms.js";
|
|
3
|
+
import { linearRGBToLMS, lmsToLinearRGB } from "./SRGB.js";
|
|
4
|
+
const P3_MATRIX = [
|
|
5
|
+
[
|
|
6
|
+
0.8224621,
|
|
7
|
+
0.1775379,
|
|
8
|
+
0.0
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
0.0331941,
|
|
12
|
+
0.9668059,
|
|
13
|
+
0.0
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
0.0170827,
|
|
17
|
+
0.0723974,
|
|
18
|
+
0.9105199
|
|
19
|
+
]
|
|
20
|
+
];
|
|
21
|
+
const P3_INVERSE_MATRIX = [
|
|
22
|
+
[
|
|
23
|
+
1.2249401,
|
|
24
|
+
-0.2249401,
|
|
25
|
+
0.0
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
-0.0420569,
|
|
29
|
+
1.0420569,
|
|
30
|
+
0.0
|
|
31
|
+
],
|
|
32
|
+
[
|
|
33
|
+
-0.019637,
|
|
34
|
+
-0.0786365,
|
|
35
|
+
1.0982735
|
|
36
|
+
]
|
|
37
|
+
];
|
|
38
|
+
const P3 = {
|
|
39
|
+
toLMS (components) {
|
|
40
|
+
const linearP3 = [
|
|
41
|
+
GammaCorrection.inverse(components[0]),
|
|
42
|
+
GammaCorrection.inverse(components[1]),
|
|
43
|
+
GammaCorrection.inverse(components[2]),
|
|
44
|
+
components[3] ?? 1
|
|
45
|
+
];
|
|
46
|
+
return linearRGBToLMS(multiplyMatrixWithAlpha(P3_INVERSE_MATRIX, linearP3));
|
|
47
|
+
},
|
|
48
|
+
fromLMS (components) {
|
|
49
|
+
const linearP3 = multiplyMatrixWithAlpha(P3_MATRIX, lmsToLinearRGB(components));
|
|
50
|
+
return [
|
|
51
|
+
GammaCorrection.op(linearP3[0]),
|
|
52
|
+
GammaCorrection.op(linearP3[1]),
|
|
53
|
+
GammaCorrection.op(linearP3[2]),
|
|
54
|
+
linearP3[3]
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export { P3, P3_INVERSE_MATRIX, P3_MATRIX };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RGB.d.ts","sourceRoot":"","sources":["../../src/spaces/RGB.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG/C,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,GAAG,EAAE,gBAmBjB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SRGB } from "./SRGB.js";
|
|
2
|
+
const RGB = {
|
|
3
|
+
toLMS (components) {
|
|
4
|
+
return SRGB.toLMS([
|
|
5
|
+
components[0] / 255,
|
|
6
|
+
components[1] / 255,
|
|
7
|
+
components[2] / 255,
|
|
8
|
+
components[3] ?? 1
|
|
9
|
+
]);
|
|
10
|
+
},
|
|
11
|
+
fromLMS (components) {
|
|
12
|
+
const rgb = SRGB.fromLMS(components);
|
|
13
|
+
return [
|
|
14
|
+
Math.round(25500 * rgb[0]) / 100,
|
|
15
|
+
Math.round(25500 * rgb[1]) / 100,
|
|
16
|
+
Math.round(25500 * rgb[2]) / 100,
|
|
17
|
+
rgb[3]
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export { RGB };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ColorSpaceHelper } from './types';
|
|
2
|
+
export declare function linearRGBToLMS(components: [number, number, number, number]): [number, number, number, number];
|
|
3
|
+
export declare function lmsToLinearRGB(components: [number, number, number, number]): [number, number, number, number];
|
|
4
|
+
export interface SRGBComponents {
|
|
5
|
+
sRed: number;
|
|
6
|
+
green: number;
|
|
7
|
+
blue: number;
|
|
8
|
+
alpha: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const SRGB: ColorSpaceHelper;
|
|
11
|
+
//# sourceMappingURL=SRGB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SRGB.d.ts","sourceRoot":"","sources":["../../src/spaces/SRGB.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAgB/C,wBAAgB,cAAc,CAAE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAE9G;AAED,wBAAgB,cAAc,CAAE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAE9G;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,IAAI,EAAE,gBAsBlB,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { GammaCorrection } from "../transforms.js";
|
|
2
|
+
import { multiplyMatrixWithAlpha } from "../misc.js";
|
|
3
|
+
const SRGB_TO_LMS_MATRIX = [
|
|
4
|
+
[
|
|
5
|
+
0.412165612,
|
|
6
|
+
0.536275208,
|
|
7
|
+
0.0514575653
|
|
8
|
+
],
|
|
9
|
+
[
|
|
10
|
+
0.211859107,
|
|
11
|
+
0.680718957,
|
|
12
|
+
0.107406579
|
|
13
|
+
],
|
|
14
|
+
[
|
|
15
|
+
0.0883097947,
|
|
16
|
+
0.281847417,
|
|
17
|
+
0.629990385
|
|
18
|
+
]
|
|
19
|
+
];
|
|
20
|
+
const LMS_TO_SRGB_MATRIX = [
|
|
21
|
+
[
|
|
22
|
+
4.0767416621,
|
|
23
|
+
-3.3077115913,
|
|
24
|
+
0.2309699292
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
-1.2684380046,
|
|
28
|
+
2.6097574011,
|
|
29
|
+
-0.3413193965
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
-0.0041960863,
|
|
33
|
+
-0.7034186147,
|
|
34
|
+
1.707614701
|
|
35
|
+
]
|
|
36
|
+
];
|
|
37
|
+
function linearRGBToLMS(components) {
|
|
38
|
+
return multiplyMatrixWithAlpha(SRGB_TO_LMS_MATRIX, components);
|
|
39
|
+
}
|
|
40
|
+
function lmsToLinearRGB(components) {
|
|
41
|
+
return multiplyMatrixWithAlpha(LMS_TO_SRGB_MATRIX, components);
|
|
42
|
+
}
|
|
43
|
+
const SRGB = {
|
|
44
|
+
toLMS (components) {
|
|
45
|
+
const linearRGB = [
|
|
46
|
+
GammaCorrection.inverse(components[0]),
|
|
47
|
+
GammaCorrection.inverse(components[1]),
|
|
48
|
+
GammaCorrection.inverse(components[2]),
|
|
49
|
+
components[3]
|
|
50
|
+
];
|
|
51
|
+
return linearRGBToLMS(linearRGB);
|
|
52
|
+
},
|
|
53
|
+
fromLMS (components) {
|
|
54
|
+
const linearRGB = lmsToLinearRGB(components);
|
|
55
|
+
return [
|
|
56
|
+
GammaCorrection.op(linearRGB[0]),
|
|
57
|
+
GammaCorrection.op(linearRGB[1]),
|
|
58
|
+
GammaCorrection.op(linearRGB[2]),
|
|
59
|
+
linearRGB[3]
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export { SRGB, linearRGBToLMS, lmsToLinearRGB };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type ColorSpace = 'srgb' | 'p3' | 'oklab' | 'oklch' | 'lms' | 'hsl' | 'rgb';
|
|
2
|
+
export interface ColorSpaceHelper {
|
|
3
|
+
toLMS(components: number[]): [number, number, number, number];
|
|
4
|
+
fromLMS(components: [number, number, number, number]): number[];
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/spaces/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;AAElF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAE,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9D,OAAO,CAAE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAAA;CACjE"}
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare abstract class TransformFn {
|
|
2
|
+
static op(_x: number): number;
|
|
3
|
+
static inverse(_x: number): number;
|
|
4
|
+
}
|
|
5
|
+
export declare class GammaCorrection extends TransformFn {
|
|
6
|
+
static op(x: number): number;
|
|
7
|
+
static inverse(x: number): number;
|
|
8
|
+
}
|
|
9
|
+
export declare class CubeRoot extends TransformFn {
|
|
10
|
+
static op(x: number): number;
|
|
11
|
+
static inverse(x: number): number;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=transforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAEA,8BAAsB,WAAW;IAC/B,MAAM,CAAC,EAAE,CAAE,EAAE,EAAE,MAAM,GAAG,MAAM;IAI9B,MAAM,CAAC,OAAO,CAAE,EAAE,EAAE,MAAM,GAAG,MAAM;CAGpC;AAED,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,MAAM,CAAC,EAAE,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAK7B,MAAM,CAAC,OAAO,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM;CAInC;AAED,qBAAa,QAAS,SAAQ,WAAW;IACvC,MAAM,CAAC,EAAE,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM;IAK7B,MAAM,CAAC,OAAO,CAAE,CAAC,EAAE,MAAM,GAAG,MAAM;CAInC"}
|