shaders 2.2.24 → 2.2.25
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/core/AngularBlur-Dl2gwk68.js +64 -0
- package/dist/core/Ascii-Dha_QpT3.js +286 -0
- package/dist/core/Beam-CTN9Ni43.js +139 -0
- package/dist/core/Blob-CxFDZovO.js +218 -0
- package/dist/core/Blur-Y2FsmFk_.js +77 -0
- package/dist/core/Bulge-Cb-t0xqI.js +132 -0
- package/dist/core/CRTScreen-CtERsenz.js +112 -0
- package/dist/core/ChannelBlur-CvM6GJgZ.js +118 -0
- package/dist/core/Checkerboard-CgB-egNY.js +83 -0
- package/dist/core/ChromaFlow-vRCwhQpN.js +222 -0
- package/dist/core/ChromaticAberration-FTquTQIL.js +88 -0
- package/dist/core/Circle-Daziv5d7.js +67 -0
- package/dist/core/CursorTrail-Bsz9e6Fn.js +145 -0
- package/dist/core/DiffuseBlur-Cj2PtRNd.js +83 -0
- package/dist/core/Dither-D2Nf4p3w.js +66 -0
- package/dist/core/DotGrid-CzOwquo4.js +75 -0
- package/dist/core/Duotone-XuTN9tI7.js +65 -0
- package/dist/core/FilmGrain-D3-nbi12.js +28 -0
- package/dist/core/FloatingParticles-D9Nnu1qg.js +217 -0
- package/dist/core/GlassTiles-CnjCvajI.js +69 -0
- package/dist/core/Glow-BluFc9be.js +75 -0
- package/dist/core/Godrays-ChLh_vGl.js +144 -0
- package/dist/core/Grayscale-DRny75A9.js +20 -0
- package/dist/core/Grid-DgyDa4H1.js +58 -0
- package/dist/core/GridDistortion-BAspCYvp.js +188 -0
- package/dist/core/Group-Dul7PUBl.js +14 -0
- package/dist/core/Halftone-Ifv5F_FT.js +65 -0
- package/dist/core/HueShift-De8ukMWs.js +31 -0
- package/dist/core/ImageTexture-DvYcQgJB.js +143 -0
- package/dist/core/Invert-Fz0NtIJc.js +21 -0
- package/dist/core/LinearBlur-LmhnQoA4.js +62 -0
- package/dist/core/LinearGradient-xbloQjzt.js +133 -0
- package/dist/core/Liquify-DMe1V5-O.js +175 -0
- package/dist/core/Pixelate-Cv8537Pj.js +37 -0
- package/dist/core/PolarCoordinates-DDvDhBE-.js +112 -0
- package/dist/core/Posterize-3m3xkWOz.js +29 -0
- package/dist/core/ProgressiveBlur-EGkevObV.js +121 -0
- package/dist/core/RadialGradient-B7ZZB_VJ.js +71 -0
- package/dist/core/RectangularCoordinates-muWR8mZS.js +101 -0
- package/dist/core/Ripples-8XaZaXQF.js +117 -0
- package/dist/core/Saturation-CYFI1jzN.js +30 -0
- package/dist/core/SimplexNoise-DJUe0wz_.js +99 -0
- package/dist/core/SineWave-Dl3nFO1W.js +120 -0
- package/dist/core/SolidColor-CWGq_Bjq.js +21 -0
- package/dist/core/Spherize-C-jZEUsN.js +128 -0
- package/dist/core/Spiral-BSB_R39p.js +132 -0
- package/dist/core/Strands-0stO5BMy.js +161 -0
- package/dist/core/Stretch-B645paha.js +133 -0
- package/dist/core/Swirl-CVnbawit.js +173 -0
- package/dist/core/TiltShift-0CxNRI6L.js +134 -0
- package/dist/core/Tritone-Daa-I5UD.js +76 -0
- package/dist/core/Twirl-2CJVZEtk.js +96 -0
- package/dist/core/Vibrance-DRtecEvb.js +30 -0
- package/dist/core/WaveDistortion-BscXN2rs.js +173 -0
- package/dist/core/ZoomBlur-CAqK0Kju.js +62 -0
- package/dist/core/colorMixing-BXiTAqJU.js +69 -0
- package/dist/core/edges-Bn_OIa_h.js +26 -0
- package/dist/core/index.js +2257 -1606
- package/dist/core/shaders/AngularBlur/index.js +3 -7
- package/dist/core/shaders/Ascii/index.js +2 -6
- package/dist/core/shaders/Beam/index.js +4 -8
- package/dist/core/shaders/Blob/index.js +5 -9
- package/dist/core/shaders/Blur/index.js +2 -6
- package/dist/core/shaders/Bulge/index.js +4 -8
- package/dist/core/shaders/CRTScreen/index.js +2 -6
- package/dist/core/shaders/ChannelBlur/index.js +2 -6
- package/dist/core/shaders/Checkerboard/index.js +4 -8
- package/dist/core/shaders/ChromaFlow/index.js +3 -7
- package/dist/core/shaders/ChromaticAberration/index.js +3 -7
- package/dist/core/shaders/Circle/index.js +3 -7
- package/dist/core/shaders/CursorTrail/index.js +4 -8
- package/dist/core/shaders/DiffuseBlur/index.js +4 -8
- package/dist/core/shaders/Dither/index.js +3 -7
- package/dist/core/shaders/DotGrid/index.js +3 -7
- package/dist/core/shaders/Duotone/index.js +4 -8
- package/dist/core/shaders/FilmGrain/index.js +2 -6
- package/dist/core/shaders/FloatingParticles/index.js +3 -7
- package/dist/core/shaders/GlassTiles/index.js +2 -6
- package/dist/core/shaders/Glow/index.js +2 -6
- package/dist/core/shaders/Godrays/index.js +3 -7
- package/dist/core/shaders/Grayscale/index.js +2 -8
- package/dist/core/shaders/Grid/index.js +3 -7
- package/dist/core/shaders/GridDistortion/index.js +4 -8
- package/dist/core/shaders/Group/index.js +2 -6
- package/dist/core/shaders/Halftone/index.js +3 -7
- package/dist/core/shaders/HueShift/index.js +2 -8
- package/dist/core/shaders/ImageTexture/index.js +2 -6
- package/dist/core/shaders/Invert/index.js +2 -6
- package/dist/core/shaders/LinearBlur/index.js +3 -7
- package/dist/core/shaders/LinearGradient/index.js +4 -8
- package/dist/core/shaders/Liquify/index.js +4 -8
- package/dist/core/shaders/Pixelate/index.js +2 -6
- package/dist/core/shaders/PolarCoordinates/index.js +4 -8
- package/dist/core/shaders/Posterize/index.js +2 -7
- package/dist/core/shaders/ProgressiveBlur/index.js +3 -7
- package/dist/core/shaders/RadialGradient/index.js +4 -8
- package/dist/core/shaders/RectangularCoordinates/index.js +4 -8
- package/dist/core/shaders/Ripples/index.js +5 -9
- package/dist/core/shaders/Saturation/index.js +2 -8
- package/dist/core/shaders/SimplexNoise/index.js +5 -9
- package/dist/core/shaders/SineWave/index.js +3 -7
- package/dist/core/shaders/SolidColor/index.js +3 -7
- package/dist/core/shaders/Spherize/index.js +3 -7
- package/dist/core/shaders/Spiral/index.js +4 -8
- package/dist/core/shaders/Strands/index.js +4 -8
- package/dist/core/shaders/Stretch/index.js +4 -8
- package/dist/core/shaders/Swirl/index.js +5 -9
- package/dist/core/shaders/TiltShift/index.js +3 -7
- package/dist/core/shaders/Tritone/index.js +4 -8
- package/dist/core/shaders/Twirl/index.js +4 -8
- package/dist/core/shaders/Vibrance/index.js +2 -8
- package/dist/core/shaders/WaveDistortion/index.js +4 -8
- package/dist/core/shaders/ZoomBlur/index.js +3 -7
- package/dist/core/telemetry/index.js +189 -157
- package/dist/core/time-CTJvRUZ4.js +10 -0
- package/dist/core/transformations-DxfQXZWi.js +4715 -0
- package/dist/react/generatePresetCode-CCibXbtZ.js +645 -0
- package/dist/react/index.js +7645 -104827
- package/dist/react/utils/generatePresetCode.js +2 -5
- package/dist/solid/index.js +6670 -102727
- package/dist/solid/utils/generatePresetCode.js +583 -554
- package/dist/svelte/generatePresetCode-CymgoDq_.js +645 -0
- package/dist/svelte/index.js +6175 -102645
- package/dist/svelte/utils/generatePresetCode.js +2 -5
- package/dist/vue/generatePresetCode-CRJmU8iF.js +649 -0
- package/dist/vue/index.js +6929 -103706
- package/dist/vue/utils/generatePresetCode.js +2 -5
- package/package.json +4 -1
- package/dist/core/AngularBlur-ClvtyURQ.js +0 -56
- package/dist/core/Ascii-BT0-K_vw.js +0 -196
- package/dist/core/Beam-BAKql1AP.js +0 -116
- package/dist/core/Blob-CVSxhHJG.js +0 -169
- package/dist/core/Blur-C1TTBHCX.js +0 -64
- package/dist/core/Bulge-DV8tX-cw.js +0 -103
- package/dist/core/CRTScreen-VTJQoOeq.js +0 -91
- package/dist/core/ChannelBlur-BLZ9kBNA.js +0 -89
- package/dist/core/Checkerboard-DQ4Df3vm.js +0 -75
- package/dist/core/ChromaFlow-BggN1_Av.js +0 -134
- package/dist/core/ChromaticAberration-DlTaHNcp.js +0 -82
- package/dist/core/Circle-B9ObWlq5.js +0 -62
- package/dist/core/ColorAdjustment-FeXXpypd.js +0 -14
- package/dist/core/CursorTrail-C7QdUj8O.js +0 -105
- package/dist/core/DiffuseBlur-Mx6LBsqz.js +0 -69
- package/dist/core/Dither-CeIdV_9C.js +0 -61
- package/dist/core/DotGrid-D6xUvYrt.js +0 -61
- package/dist/core/Duotone-C2Pqt2gR.js +0 -66
- package/dist/core/FilmGrain-CJ9n_fgk.js +0 -28
- package/dist/core/FloatingParticles-iGtMs44K.js +0 -160
- package/dist/core/GlassTiles-D_lVyag2.js +0 -52
- package/dist/core/Glow-B0jj-6OC.js +0 -66
- package/dist/core/Godrays-DjLVuZa4.js +0 -105
- package/dist/core/Grayscale-BbsdDa_X.js +0 -21
- package/dist/core/Grid-ByjU-_ua.js +0 -50
- package/dist/core/GridDistortion-C_eIlhkW.js +0 -147
- package/dist/core/Group-CyaDLGpI.js +0 -17
- package/dist/core/Halftone-BvuAe_k-.js +0 -55
- package/dist/core/HueShift-B_qE9c08.js +0 -32
- package/dist/core/ImageTexture-h00TFC1l.js +0 -105
- package/dist/core/Invert-BEDDB0sm.js +0 -20
- package/dist/core/LinearBlur-CLKxuyeT.js +0 -56
- package/dist/core/LinearGradient-BPo8TX_M.js +0 -111
- package/dist/core/Liquify-DGkfeixZ.js +0 -139
- package/dist/core/Pixelate-Bzy_7LnJ.js +0 -38
- package/dist/core/PolarCoordinates-BUumPeTv.js +0 -103
- package/dist/core/Posterize-ggKIJlmm.js +0 -46
- package/dist/core/ProgressiveBlur-D6_6T7SS.js +0 -102
- package/dist/core/RadialGradient-DEY9fRqa.js +0 -71
- package/dist/core/RectangularCoordinates-CZ-cFrCh.js +0 -92
- package/dist/core/Ripples-BwNlcsnV.js +0 -106
- package/dist/core/Saturation-Dl3gCWuZ.js +0 -31
- package/dist/core/SimplexNoise-BhE_WyGt.js +0 -94
- package/dist/core/SineWave-Db_Y0Mcv.js +0 -107
- package/dist/core/SolidColor-CerOp4EQ.js +0 -22
- package/dist/core/Spherize-Dh8E5XwG.js +0 -103
- package/dist/core/Spiral-BvygQEfP.js +0 -115
- package/dist/core/Strands-maaPn4On.js +0 -125
- package/dist/core/Stretch-CnA0-nSz.js +0 -103
- package/dist/core/Swirl-CQBUahTB.js +0 -148
- package/dist/core/TSLBase-Bt7Z4hv_.js +0 -8053
- package/dist/core/TiltShift-qFj0oFzN.js +0 -114
- package/dist/core/Tritone-AiixmTg8.js +0 -75
- package/dist/core/Twirl-ooHQcV89.js +0 -82
- package/dist/core/Vibrance-C2FRlLkK.js +0 -31
- package/dist/core/WaveDistortion-CN8MjKlm.js +0 -132
- package/dist/core/ZoomBlur-CxWGx8PH.js +0 -56
- package/dist/core/colorMixing--dhzx0ch.js +0 -21
- package/dist/core/edges-CDzKsauJ.js +0 -15
- package/dist/core/three.tsl-Btj1hLsf.js +0 -43845
- package/dist/core/time-DbRMw6Jm.js +0 -10
- package/dist/core/transformations-CsrIJXh-.js +0 -3992
- package/dist/react/generatePresetCode-CVj6IV8Y.js +0 -646
- package/dist/svelte/generatePresetCode-CVj6IV8Y.js +0 -646
- package/dist/vue/generatePresetCode-DCaIsDhE.js +0 -652
|
@@ -0,0 +1,4715 @@
|
|
|
1
|
+
import { Vector2, Vector4 } from "three";
|
|
2
|
+
import * as TSL from "three/tsl";
|
|
3
|
+
function multiplyMatrices(A, B) {
|
|
4
|
+
let m$1 = A.length;
|
|
5
|
+
if (!Array.isArray(A[0])) A = [A];
|
|
6
|
+
if (!Array.isArray(B[0])) B = B.map((x) => [x]);
|
|
7
|
+
let p$1 = B[0].length;
|
|
8
|
+
let B_cols = B[0].map((_, i) => B.map((x) => x[i]));
|
|
9
|
+
let product = A.map((row) => B_cols.map((col) => {
|
|
10
|
+
let ret = 0;
|
|
11
|
+
if (!Array.isArray(row)) {
|
|
12
|
+
for (let c$1 of col) ret += row * c$1;
|
|
13
|
+
return ret;
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < row.length; i++) ret += row[i] * (col[i] || 0);
|
|
16
|
+
return ret;
|
|
17
|
+
}));
|
|
18
|
+
if (m$1 === 1) product = product[0];
|
|
19
|
+
if (p$1 === 1) return product.map((x) => x[0]);
|
|
20
|
+
return product;
|
|
21
|
+
}
|
|
22
|
+
function isString(str) {
|
|
23
|
+
return type(str) === "string";
|
|
24
|
+
}
|
|
25
|
+
function type(o) {
|
|
26
|
+
return (Object.prototype.toString.call(o).match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
function serializeNumber(n$2, { precision, unit }) {
|
|
29
|
+
if (isNone(n$2)) return "none";
|
|
30
|
+
return toPrecision(n$2, precision) + (unit ?? "");
|
|
31
|
+
}
|
|
32
|
+
function isNone(n$2) {
|
|
33
|
+
return Number.isNaN(n$2) || n$2 instanceof Number && n$2?.none;
|
|
34
|
+
}
|
|
35
|
+
function skipNone(n$2) {
|
|
36
|
+
return isNone(n$2) ? 0 : n$2;
|
|
37
|
+
}
|
|
38
|
+
function toPrecision(n$2, precision) {
|
|
39
|
+
if (n$2 === 0) return 0;
|
|
40
|
+
let integer = ~~n$2;
|
|
41
|
+
let digits = 0;
|
|
42
|
+
if (integer && precision) digits = ~~Math.log10(Math.abs(integer)) + 1;
|
|
43
|
+
const multiplier = 10 ** (precision - digits);
|
|
44
|
+
return Math.floor(n$2 * multiplier + .5) / multiplier;
|
|
45
|
+
}
|
|
46
|
+
var angleFactor = {
|
|
47
|
+
deg: 1,
|
|
48
|
+
grad: .9,
|
|
49
|
+
rad: 180 / Math.PI,
|
|
50
|
+
turn: 360
|
|
51
|
+
};
|
|
52
|
+
function parseFunction(str) {
|
|
53
|
+
if (!str) return;
|
|
54
|
+
str = str.trim();
|
|
55
|
+
const isFunctionRegex = /^([a-z]+)\((.+?)\)$/i;
|
|
56
|
+
const isNumberRegex = /^-?[\d.]+$/;
|
|
57
|
+
const unitValueRegex = /%|deg|g?rad|turn$/;
|
|
58
|
+
const singleArgument = /\/?\s*(none|[-\w.]+(?:%|deg|g?rad|turn)?)/g;
|
|
59
|
+
let parts = str.match(isFunctionRegex);
|
|
60
|
+
if (parts) {
|
|
61
|
+
let args = [];
|
|
62
|
+
parts[2].replace(singleArgument, ($0, rawArg) => {
|
|
63
|
+
let match = rawArg.match(unitValueRegex);
|
|
64
|
+
let arg = rawArg;
|
|
65
|
+
if (match) {
|
|
66
|
+
let unit = match[0];
|
|
67
|
+
let unitlessArg = arg.slice(0, -unit.length);
|
|
68
|
+
if (unit === "%") {
|
|
69
|
+
arg = /* @__PURE__ */ new Number(unitlessArg / 100);
|
|
70
|
+
arg.type = "<percentage>";
|
|
71
|
+
} else {
|
|
72
|
+
arg = new Number(unitlessArg * angleFactor[unit]);
|
|
73
|
+
arg.type = "<angle>";
|
|
74
|
+
arg.unit = unit;
|
|
75
|
+
}
|
|
76
|
+
} else if (isNumberRegex.test(arg)) {
|
|
77
|
+
arg = new Number(arg);
|
|
78
|
+
arg.type = "<number>";
|
|
79
|
+
} else if (arg === "none") {
|
|
80
|
+
arg = /* @__PURE__ */ new Number(NaN);
|
|
81
|
+
arg.none = true;
|
|
82
|
+
}
|
|
83
|
+
if ($0.startsWith("/")) {
|
|
84
|
+
arg = arg instanceof Number ? arg : new Number(arg);
|
|
85
|
+
arg.alpha = true;
|
|
86
|
+
}
|
|
87
|
+
if (typeof arg === "object" && arg instanceof Number) arg.raw = rawArg;
|
|
88
|
+
args.push(arg);
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
name: parts[1].toLowerCase(),
|
|
92
|
+
rawName: parts[1],
|
|
93
|
+
rawArgs: parts[2],
|
|
94
|
+
args
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function last(arr) {
|
|
99
|
+
return arr[arr.length - 1];
|
|
100
|
+
}
|
|
101
|
+
function interpolate(start, end, p$1) {
|
|
102
|
+
if (isNaN(start)) return end;
|
|
103
|
+
if (isNaN(end)) return start;
|
|
104
|
+
return start + (end - start) * p$1;
|
|
105
|
+
}
|
|
106
|
+
function interpolateInv(start, end, value) {
|
|
107
|
+
return (value - start) / (end - start);
|
|
108
|
+
}
|
|
109
|
+
function mapRange(from, to$1, value) {
|
|
110
|
+
return interpolate(to$1[0], to$1[1], interpolateInv(from[0], from[1], value));
|
|
111
|
+
}
|
|
112
|
+
function parseCoordGrammar(coordGrammars) {
|
|
113
|
+
return coordGrammars.map((coordGrammar$1) => {
|
|
114
|
+
return coordGrammar$1.split("|").map((type$1) => {
|
|
115
|
+
type$1 = type$1.trim();
|
|
116
|
+
let range$1 = type$1.match(/^(<[a-z]+>)\[(-?[.\d]+),\s*(-?[.\d]+)\]?$/);
|
|
117
|
+
if (range$1) {
|
|
118
|
+
let ret = new String(range$1[1]);
|
|
119
|
+
ret.range = [+range$1[2], +range$1[3]];
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
return type$1;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function clamp$1(min$1, val, max$2) {
|
|
127
|
+
return Math.max(Math.min(max$2, val), min$1);
|
|
128
|
+
}
|
|
129
|
+
function copySign(to$1, from) {
|
|
130
|
+
return Math.sign(to$1) === Math.sign(from) ? to$1 : -to$1;
|
|
131
|
+
}
|
|
132
|
+
function spow(base, exp$1) {
|
|
133
|
+
return copySign(Math.abs(base) ** exp$1, base);
|
|
134
|
+
}
|
|
135
|
+
function zdiv(n$2, d$1) {
|
|
136
|
+
return d$1 === 0 ? 0 : n$2 / d$1;
|
|
137
|
+
}
|
|
138
|
+
function bisectLeft(arr, value, lo = 0, hi = arr.length) {
|
|
139
|
+
while (lo < hi) {
|
|
140
|
+
const mid = lo + hi >> 1;
|
|
141
|
+
if (arr[mid] < value) lo = mid + 1;
|
|
142
|
+
else hi = mid;
|
|
143
|
+
}
|
|
144
|
+
return lo;
|
|
145
|
+
}
|
|
146
|
+
var util = /* @__PURE__ */ Object.freeze({
|
|
147
|
+
__proto__: null,
|
|
148
|
+
bisectLeft,
|
|
149
|
+
clamp: clamp$1,
|
|
150
|
+
copySign,
|
|
151
|
+
interpolate,
|
|
152
|
+
interpolateInv,
|
|
153
|
+
isNone,
|
|
154
|
+
isString,
|
|
155
|
+
last,
|
|
156
|
+
mapRange,
|
|
157
|
+
multiplyMatrices,
|
|
158
|
+
parseCoordGrammar,
|
|
159
|
+
parseFunction,
|
|
160
|
+
serializeNumber,
|
|
161
|
+
skipNone,
|
|
162
|
+
spow,
|
|
163
|
+
toPrecision,
|
|
164
|
+
type,
|
|
165
|
+
zdiv
|
|
166
|
+
});
|
|
167
|
+
var Hooks = class {
|
|
168
|
+
add(name, callback, first) {
|
|
169
|
+
if (typeof arguments[0] != "string") {
|
|
170
|
+
for (var name in arguments[0]) this.add(name, arguments[0][name], arguments[1]);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
(Array.isArray(name) ? name : [name]).forEach(function(name$1) {
|
|
174
|
+
this[name$1] = this[name$1] || [];
|
|
175
|
+
if (callback) this[name$1][first ? "unshift" : "push"](callback);
|
|
176
|
+
}, this);
|
|
177
|
+
}
|
|
178
|
+
run(name, env) {
|
|
179
|
+
this[name] = this[name] || [];
|
|
180
|
+
this[name].forEach(function(callback) {
|
|
181
|
+
callback.call(env && env.context ? env.context : env, env);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var hooks = new Hooks();
|
|
186
|
+
var defaults = {
|
|
187
|
+
gamut_mapping: "css",
|
|
188
|
+
precision: 5,
|
|
189
|
+
deltaE: "76",
|
|
190
|
+
verbose: globalThis?.process?.env?.NODE_ENV?.toLowerCase() !== "test",
|
|
191
|
+
warn: function warn(msg) {
|
|
192
|
+
if (this.verbose) globalThis?.console?.warn?.(msg);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var WHITES = {
|
|
196
|
+
D50: [
|
|
197
|
+
.3457 / .3585,
|
|
198
|
+
1,
|
|
199
|
+
.2958 / .3585
|
|
200
|
+
],
|
|
201
|
+
D65: [
|
|
202
|
+
.3127 / .329,
|
|
203
|
+
1,
|
|
204
|
+
.3583 / .329
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
function getWhite(name) {
|
|
208
|
+
if (Array.isArray(name)) return name;
|
|
209
|
+
return WHITES[name];
|
|
210
|
+
}
|
|
211
|
+
function adapt$2(W1, W2, XYZ, options = {}) {
|
|
212
|
+
W1 = getWhite(W1);
|
|
213
|
+
W2 = getWhite(W2);
|
|
214
|
+
if (!W1 || !W2) throw new TypeError(`Missing white point to convert ${!W1 ? "from" : ""}${!W1 && !W2 ? "/" : ""}${!W2 ? "to" : ""}`);
|
|
215
|
+
if (W1 === W2) return XYZ;
|
|
216
|
+
let env = {
|
|
217
|
+
W1,
|
|
218
|
+
W2,
|
|
219
|
+
XYZ,
|
|
220
|
+
options
|
|
221
|
+
};
|
|
222
|
+
hooks.run("chromatic-adaptation-start", env);
|
|
223
|
+
if (!env.M) {
|
|
224
|
+
if (env.W1 === WHITES.D65 && env.W2 === WHITES.D50) env.M = [
|
|
225
|
+
[
|
|
226
|
+
1.0479297925449969,
|
|
227
|
+
.022946870601609652,
|
|
228
|
+
-.05019226628920524
|
|
229
|
+
],
|
|
230
|
+
[
|
|
231
|
+
.02962780877005599,
|
|
232
|
+
.9904344267538799,
|
|
233
|
+
-.017073799063418826
|
|
234
|
+
],
|
|
235
|
+
[
|
|
236
|
+
-.009243040646204504,
|
|
237
|
+
.015055191490298152,
|
|
238
|
+
.7518742814281371
|
|
239
|
+
]
|
|
240
|
+
];
|
|
241
|
+
else if (env.W1 === WHITES.D50 && env.W2 === WHITES.D65) env.M = [
|
|
242
|
+
[
|
|
243
|
+
.955473421488075,
|
|
244
|
+
-.02309845494876471,
|
|
245
|
+
.06325924320057072
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
-.0283697093338637,
|
|
249
|
+
1.0099953980813041,
|
|
250
|
+
.021041441191917323
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
.012314014864481998,
|
|
254
|
+
-.020507649298898964,
|
|
255
|
+
1.330365926242124
|
|
256
|
+
]
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
hooks.run("chromatic-adaptation-end", env);
|
|
260
|
+
if (env.M) return multiplyMatrices(env.M, env.XYZ);
|
|
261
|
+
else throw new TypeError("Only Bradford CAT with white points D50 and D65 supported for now.");
|
|
262
|
+
}
|
|
263
|
+
var noneTypes = new Set([
|
|
264
|
+
"<number>",
|
|
265
|
+
"<percentage>",
|
|
266
|
+
"<angle>"
|
|
267
|
+
]);
|
|
268
|
+
function coerceCoords(space, format, name, coords) {
|
|
269
|
+
return Object.entries(space.coords).map(([id, coordMeta], i) => {
|
|
270
|
+
let coordGrammar$1 = format.coordGrammar[i];
|
|
271
|
+
let arg = coords[i];
|
|
272
|
+
let providedType = arg?.type;
|
|
273
|
+
let type$1;
|
|
274
|
+
if (arg.none) type$1 = coordGrammar$1.find((c$1) => noneTypes.has(c$1));
|
|
275
|
+
else type$1 = coordGrammar$1.find((c$1) => c$1 == providedType);
|
|
276
|
+
if (!type$1) {
|
|
277
|
+
let coordName = coordMeta.name || id;
|
|
278
|
+
throw new TypeError(`${providedType ?? arg.raw} not allowed for ${coordName} in ${name}()`);
|
|
279
|
+
}
|
|
280
|
+
let fromRange = type$1.range;
|
|
281
|
+
if (providedType === "<percentage>") fromRange ||= [0, 1];
|
|
282
|
+
let toRange = coordMeta.range || coordMeta.refRange;
|
|
283
|
+
if (fromRange && toRange) coords[i] = mapRange(fromRange, toRange, coords[i]);
|
|
284
|
+
return type$1;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function parse(str, { meta } = {}) {
|
|
288
|
+
let env = { "str": String(str)?.trim() };
|
|
289
|
+
hooks.run("parse-start", env);
|
|
290
|
+
if (env.color) return env.color;
|
|
291
|
+
env.parsed = parseFunction(env.str);
|
|
292
|
+
if (env.parsed) {
|
|
293
|
+
let name = env.parsed.name;
|
|
294
|
+
if (name === "color") {
|
|
295
|
+
let id = env.parsed.args.shift();
|
|
296
|
+
let alternateId = id.startsWith("--") ? id.substring(2) : `--${id}`;
|
|
297
|
+
let ids = [id, alternateId];
|
|
298
|
+
let alpha = env.parsed.rawArgs.indexOf("/") > 0 ? env.parsed.args.pop() : 1;
|
|
299
|
+
for (let space of ColorSpace.all) {
|
|
300
|
+
let colorSpec = space.getFormat("color");
|
|
301
|
+
if (colorSpec) {
|
|
302
|
+
if (ids.includes(colorSpec.id) || colorSpec.ids?.filter((specId) => ids.includes(specId)).length) {
|
|
303
|
+
const coords = Object.keys(space.coords).map((_, i) => env.parsed.args[i] || 0);
|
|
304
|
+
let types;
|
|
305
|
+
if (colorSpec.coordGrammar) types = coerceCoords(space, colorSpec, "color", coords);
|
|
306
|
+
if (meta) Object.assign(meta, {
|
|
307
|
+
formatId: "color",
|
|
308
|
+
types
|
|
309
|
+
});
|
|
310
|
+
if (colorSpec.id.startsWith("--") && !id.startsWith("--")) defaults.warn(`${space.name} is a non-standard space and not currently supported in the CSS spec. Use prefixed color(${colorSpec.id}) instead of color(${id}).`);
|
|
311
|
+
if (id.startsWith("--") && !colorSpec.id.startsWith("--")) defaults.warn(`${space.name} is a standard space and supported in the CSS spec. Use color(${colorSpec.id}) instead of prefixed color(${id}).`);
|
|
312
|
+
return {
|
|
313
|
+
spaceId: space.id,
|
|
314
|
+
coords,
|
|
315
|
+
alpha
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
let didYouMean = "";
|
|
321
|
+
let registryId = id in ColorSpace.registry ? id : alternateId;
|
|
322
|
+
if (registryId in ColorSpace.registry) {
|
|
323
|
+
let cssId = ColorSpace.registry[registryId].formats?.color?.id;
|
|
324
|
+
if (cssId) didYouMean = `Did you mean color(${cssId})?`;
|
|
325
|
+
}
|
|
326
|
+
throw new TypeError(`Cannot parse color(${id}). ` + (didYouMean || "Missing a plugin?"));
|
|
327
|
+
} else for (let space of ColorSpace.all) {
|
|
328
|
+
let format = space.getFormat(name);
|
|
329
|
+
if (format && format.type === "function") {
|
|
330
|
+
let alpha = 1;
|
|
331
|
+
if (format.lastAlpha || last(env.parsed.args).alpha) alpha = env.parsed.args.pop();
|
|
332
|
+
let coords = env.parsed.args;
|
|
333
|
+
let types;
|
|
334
|
+
if (format.coordGrammar) types = coerceCoords(space, format, name, coords);
|
|
335
|
+
if (meta) Object.assign(meta, {
|
|
336
|
+
formatId: format.name,
|
|
337
|
+
types
|
|
338
|
+
});
|
|
339
|
+
return {
|
|
340
|
+
spaceId: space.id,
|
|
341
|
+
coords,
|
|
342
|
+
alpha
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} else for (let space of ColorSpace.all) for (let formatId in space.formats) {
|
|
347
|
+
let format = space.formats[formatId];
|
|
348
|
+
if (format.type !== "custom") continue;
|
|
349
|
+
if (format.test && !format.test(env.str)) continue;
|
|
350
|
+
let color = format.parse(env.str);
|
|
351
|
+
if (color) {
|
|
352
|
+
color.alpha ??= 1;
|
|
353
|
+
if (meta) meta.formatId = formatId;
|
|
354
|
+
return color;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
throw new TypeError(`Could not parse ${str} as a color. Missing a plugin?`);
|
|
358
|
+
}
|
|
359
|
+
function getColor(color) {
|
|
360
|
+
if (Array.isArray(color)) return color.map(getColor);
|
|
361
|
+
if (!color) throw new TypeError("Empty color reference");
|
|
362
|
+
if (isString(color)) color = parse(color);
|
|
363
|
+
let space = color.space || color.spaceId;
|
|
364
|
+
if (!(space instanceof ColorSpace)) color.space = ColorSpace.get(space);
|
|
365
|
+
if (color.alpha === void 0) color.alpha = 1;
|
|
366
|
+
return color;
|
|
367
|
+
}
|
|
368
|
+
var ε$7 = 75e-6;
|
|
369
|
+
var ColorSpace = class ColorSpace {
|
|
370
|
+
constructor(options) {
|
|
371
|
+
this.id = options.id;
|
|
372
|
+
this.name = options.name;
|
|
373
|
+
this.base = options.base ? ColorSpace.get(options.base) : null;
|
|
374
|
+
this.aliases = options.aliases;
|
|
375
|
+
if (this.base) {
|
|
376
|
+
this.fromBase = options.fromBase;
|
|
377
|
+
this.toBase = options.toBase;
|
|
378
|
+
}
|
|
379
|
+
let coords = options.coords ?? this.base.coords;
|
|
380
|
+
for (let name in coords) if (!("name" in coords[name])) coords[name].name = name;
|
|
381
|
+
this.coords = coords;
|
|
382
|
+
this.white = getWhite(options.white ?? this.base.white ?? "D65");
|
|
383
|
+
this.formats = options.formats ?? {};
|
|
384
|
+
for (let name in this.formats) {
|
|
385
|
+
let format = this.formats[name];
|
|
386
|
+
format.type ||= "function";
|
|
387
|
+
format.name ||= name;
|
|
388
|
+
}
|
|
389
|
+
if (!this.formats.color?.id) this.formats.color = {
|
|
390
|
+
...this.formats.color ?? {},
|
|
391
|
+
id: options.cssId || this.id
|
|
392
|
+
};
|
|
393
|
+
if (options.gamutSpace) this.gamutSpace = options.gamutSpace === "self" ? this : ColorSpace.get(options.gamutSpace);
|
|
394
|
+
else if (this.isPolar) this.gamutSpace = this.base;
|
|
395
|
+
else this.gamutSpace = this;
|
|
396
|
+
if (this.gamutSpace.isUnbounded) this.inGamut = (coords$1, options$1) => {
|
|
397
|
+
return true;
|
|
398
|
+
};
|
|
399
|
+
this.referred = options.referred;
|
|
400
|
+
Object.defineProperty(this, "path", {
|
|
401
|
+
value: getPath(this).reverse(),
|
|
402
|
+
writable: false,
|
|
403
|
+
enumerable: true,
|
|
404
|
+
configurable: true
|
|
405
|
+
});
|
|
406
|
+
hooks.run("colorspace-init-end", this);
|
|
407
|
+
}
|
|
408
|
+
inGamut(coords, { epsilon = ε$7 } = {}) {
|
|
409
|
+
if (!this.equals(this.gamutSpace)) {
|
|
410
|
+
coords = this.to(this.gamutSpace, coords);
|
|
411
|
+
return this.gamutSpace.inGamut(coords, { epsilon });
|
|
412
|
+
}
|
|
413
|
+
let coordMeta = Object.values(this.coords);
|
|
414
|
+
return coords.every((c$1, i) => {
|
|
415
|
+
let meta = coordMeta[i];
|
|
416
|
+
if (meta.type !== "angle" && meta.range) {
|
|
417
|
+
if (Number.isNaN(c$1)) return true;
|
|
418
|
+
let [min$1, max$2] = meta.range;
|
|
419
|
+
return (min$1 === void 0 || c$1 >= min$1 - epsilon) && (max$2 === void 0 || c$1 <= max$2 + epsilon);
|
|
420
|
+
}
|
|
421
|
+
return true;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
get isUnbounded() {
|
|
425
|
+
return Object.values(this.coords).every((coord) => !("range" in coord));
|
|
426
|
+
}
|
|
427
|
+
get cssId() {
|
|
428
|
+
return this.formats?.color?.id || this.id;
|
|
429
|
+
}
|
|
430
|
+
get isPolar() {
|
|
431
|
+
for (let id in this.coords) if (this.coords[id].type === "angle") return true;
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
getFormat(format) {
|
|
435
|
+
if (typeof format === "object") {
|
|
436
|
+
format = processFormat(format, this);
|
|
437
|
+
return format;
|
|
438
|
+
}
|
|
439
|
+
let ret;
|
|
440
|
+
if (format === "default") ret = Object.values(this.formats)[0];
|
|
441
|
+
else ret = this.formats[format];
|
|
442
|
+
if (ret) {
|
|
443
|
+
ret = processFormat(ret, this);
|
|
444
|
+
return ret;
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
equals(space) {
|
|
449
|
+
if (!space) return false;
|
|
450
|
+
return this === space || this.id === space || this.id === space.id;
|
|
451
|
+
}
|
|
452
|
+
to(space, coords) {
|
|
453
|
+
if (arguments.length === 1) {
|
|
454
|
+
const color = getColor(space);
|
|
455
|
+
[space, coords] = [color.space, color.coords];
|
|
456
|
+
}
|
|
457
|
+
space = ColorSpace.get(space);
|
|
458
|
+
if (this.equals(space)) return coords;
|
|
459
|
+
coords = coords.map((c$1) => Number.isNaN(c$1) ? 0 : c$1);
|
|
460
|
+
let myPath = this.path;
|
|
461
|
+
let otherPath = space.path;
|
|
462
|
+
let connectionSpace, connectionSpaceIndex;
|
|
463
|
+
for (let i = 0; i < myPath.length; i++) if (myPath[i].equals(otherPath[i])) {
|
|
464
|
+
connectionSpace = myPath[i];
|
|
465
|
+
connectionSpaceIndex = i;
|
|
466
|
+
} else break;
|
|
467
|
+
if (!connectionSpace) throw new Error(`Cannot convert between color spaces ${this} and ${space}: no connection space was found`);
|
|
468
|
+
for (let i = myPath.length - 1; i > connectionSpaceIndex; i--) coords = myPath[i].toBase(coords);
|
|
469
|
+
for (let i = connectionSpaceIndex + 1; i < otherPath.length; i++) coords = otherPath[i].fromBase(coords);
|
|
470
|
+
return coords;
|
|
471
|
+
}
|
|
472
|
+
from(space, coords) {
|
|
473
|
+
if (arguments.length === 1) {
|
|
474
|
+
const color = getColor(space);
|
|
475
|
+
[space, coords] = [color.space, color.coords];
|
|
476
|
+
}
|
|
477
|
+
space = ColorSpace.get(space);
|
|
478
|
+
return space.to(this, coords);
|
|
479
|
+
}
|
|
480
|
+
toString() {
|
|
481
|
+
return `${this.name} (${this.id})`;
|
|
482
|
+
}
|
|
483
|
+
getMinCoords() {
|
|
484
|
+
let ret = [];
|
|
485
|
+
for (let id in this.coords) {
|
|
486
|
+
let meta = this.coords[id];
|
|
487
|
+
let range$1 = meta.range || meta.refRange;
|
|
488
|
+
ret.push(range$1?.min ?? 0);
|
|
489
|
+
}
|
|
490
|
+
return ret;
|
|
491
|
+
}
|
|
492
|
+
static registry = {};
|
|
493
|
+
static get all() {
|
|
494
|
+
return [...new Set(Object.values(ColorSpace.registry))];
|
|
495
|
+
}
|
|
496
|
+
static register(id, space) {
|
|
497
|
+
if (arguments.length === 1) {
|
|
498
|
+
space = arguments[0];
|
|
499
|
+
id = space.id;
|
|
500
|
+
}
|
|
501
|
+
space = this.get(space);
|
|
502
|
+
if (this.registry[id] && this.registry[id] !== space) throw new Error(`Duplicate color space registration: '${id}'`);
|
|
503
|
+
this.registry[id] = space;
|
|
504
|
+
if (arguments.length === 1 && space.aliases) for (let alias of space.aliases) this.register(alias, space);
|
|
505
|
+
return space;
|
|
506
|
+
}
|
|
507
|
+
static get(space, ...alternatives) {
|
|
508
|
+
if (!space || space instanceof ColorSpace) return space;
|
|
509
|
+
if (type(space) === "string") {
|
|
510
|
+
let ret = ColorSpace.registry[space.toLowerCase()];
|
|
511
|
+
if (!ret) throw new TypeError(`No color space found with id = "${space}"`);
|
|
512
|
+
return ret;
|
|
513
|
+
}
|
|
514
|
+
if (alternatives.length) return ColorSpace.get(...alternatives);
|
|
515
|
+
throw new TypeError(`${space} is not a valid color space`);
|
|
516
|
+
}
|
|
517
|
+
static resolveCoord(ref, workingSpace) {
|
|
518
|
+
let coordType = type(ref);
|
|
519
|
+
let space, coord;
|
|
520
|
+
if (coordType === "string") if (ref.includes(".")) [space, coord] = ref.split(".");
|
|
521
|
+
else [space, coord] = [, ref];
|
|
522
|
+
else if (Array.isArray(ref)) [space, coord] = ref;
|
|
523
|
+
else {
|
|
524
|
+
space = ref.space;
|
|
525
|
+
coord = ref.coordId;
|
|
526
|
+
}
|
|
527
|
+
space = ColorSpace.get(space);
|
|
528
|
+
if (!space) space = workingSpace;
|
|
529
|
+
if (!space) throw new TypeError(`Cannot resolve coordinate reference ${ref}: No color space specified and relative references are not allowed here`);
|
|
530
|
+
coordType = type(coord);
|
|
531
|
+
if (coordType === "number" || coordType === "string" && coord >= 0) {
|
|
532
|
+
let meta = Object.entries(space.coords)[coord];
|
|
533
|
+
if (meta) return {
|
|
534
|
+
space,
|
|
535
|
+
id: meta[0],
|
|
536
|
+
index: coord,
|
|
537
|
+
...meta[1]
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
space = ColorSpace.get(space);
|
|
541
|
+
let normalizedCoord = coord.toLowerCase();
|
|
542
|
+
let i = 0;
|
|
543
|
+
for (let id in space.coords) {
|
|
544
|
+
let meta = space.coords[id];
|
|
545
|
+
if (id.toLowerCase() === normalizedCoord || meta.name?.toLowerCase() === normalizedCoord) return {
|
|
546
|
+
space,
|
|
547
|
+
id,
|
|
548
|
+
index: i,
|
|
549
|
+
...meta
|
|
550
|
+
};
|
|
551
|
+
i++;
|
|
552
|
+
}
|
|
553
|
+
throw new TypeError(`No "${coord}" coordinate found in ${space.name}. Its coordinates are: ${Object.keys(space.coords).join(", ")}`);
|
|
554
|
+
}
|
|
555
|
+
static DEFAULT_FORMAT = {
|
|
556
|
+
type: "functions",
|
|
557
|
+
name: "color"
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
function getPath(space) {
|
|
561
|
+
let ret = [space];
|
|
562
|
+
for (let s = space; s = s.base;) ret.push(s);
|
|
563
|
+
return ret;
|
|
564
|
+
}
|
|
565
|
+
function processFormat(format, { coords } = {}) {
|
|
566
|
+
if (format.coords && !format.coordGrammar) {
|
|
567
|
+
format.type ||= "function";
|
|
568
|
+
format.name ||= "color";
|
|
569
|
+
format.coordGrammar = parseCoordGrammar(format.coords);
|
|
570
|
+
let coordFormats = Object.entries(coords).map(([id, coordMeta], i) => {
|
|
571
|
+
let outputType = format.coordGrammar[i][0];
|
|
572
|
+
let fromRange = coordMeta.range || coordMeta.refRange;
|
|
573
|
+
let toRange = outputType.range, suffix = "";
|
|
574
|
+
if (outputType == "<percentage>") {
|
|
575
|
+
toRange = [0, 100];
|
|
576
|
+
suffix = "%";
|
|
577
|
+
} else if (outputType == "<angle>") suffix = "deg";
|
|
578
|
+
return {
|
|
579
|
+
fromRange,
|
|
580
|
+
toRange,
|
|
581
|
+
suffix
|
|
582
|
+
};
|
|
583
|
+
});
|
|
584
|
+
format.serializeCoords = (coords$1, precision) => {
|
|
585
|
+
return coords$1.map((c$1, i) => {
|
|
586
|
+
let { fromRange, toRange, suffix } = coordFormats[i];
|
|
587
|
+
if (fromRange && toRange) c$1 = mapRange(fromRange, toRange, c$1);
|
|
588
|
+
c$1 = serializeNumber(c$1, {
|
|
589
|
+
precision,
|
|
590
|
+
unit: suffix
|
|
591
|
+
});
|
|
592
|
+
return c$1;
|
|
593
|
+
});
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
return format;
|
|
597
|
+
}
|
|
598
|
+
var xyz_d65 = new ColorSpace({
|
|
599
|
+
id: "xyz-d65",
|
|
600
|
+
name: "XYZ D65",
|
|
601
|
+
coords: {
|
|
602
|
+
x: { name: "X" },
|
|
603
|
+
y: { name: "Y" },
|
|
604
|
+
z: { name: "Z" }
|
|
605
|
+
},
|
|
606
|
+
white: "D65",
|
|
607
|
+
formats: { color: { ids: ["xyz-d65", "xyz"] } },
|
|
608
|
+
aliases: ["xyz"]
|
|
609
|
+
});
|
|
610
|
+
var RGBColorSpace = class extends ColorSpace {
|
|
611
|
+
constructor(options) {
|
|
612
|
+
if (!options.coords) options.coords = {
|
|
613
|
+
r: {
|
|
614
|
+
range: [0, 1],
|
|
615
|
+
name: "Red"
|
|
616
|
+
},
|
|
617
|
+
g: {
|
|
618
|
+
range: [0, 1],
|
|
619
|
+
name: "Green"
|
|
620
|
+
},
|
|
621
|
+
b: {
|
|
622
|
+
range: [0, 1],
|
|
623
|
+
name: "Blue"
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
if (!options.base) options.base = xyz_d65;
|
|
627
|
+
if (options.toXYZ_M && options.fromXYZ_M) {
|
|
628
|
+
options.toBase ??= (rgb) => {
|
|
629
|
+
let xyz = multiplyMatrices(options.toXYZ_M, rgb);
|
|
630
|
+
if (this.white !== this.base.white) xyz = adapt$2(this.white, this.base.white, xyz);
|
|
631
|
+
return xyz;
|
|
632
|
+
};
|
|
633
|
+
options.fromBase ??= (xyz) => {
|
|
634
|
+
xyz = adapt$2(this.base.white, this.white, xyz);
|
|
635
|
+
return multiplyMatrices(options.fromXYZ_M, xyz);
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
options.referred ??= "display";
|
|
639
|
+
super(options);
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
function getAll(color, space) {
|
|
643
|
+
color = getColor(color);
|
|
644
|
+
if (!space || color.space.equals(space)) return color.coords.slice();
|
|
645
|
+
space = ColorSpace.get(space);
|
|
646
|
+
return space.from(color);
|
|
647
|
+
}
|
|
648
|
+
function get(color, prop) {
|
|
649
|
+
color = getColor(color);
|
|
650
|
+
let { space, index } = ColorSpace.resolveCoord(prop, color.space);
|
|
651
|
+
return getAll(color, space)[index];
|
|
652
|
+
}
|
|
653
|
+
function setAll(color, space, coords) {
|
|
654
|
+
color = getColor(color);
|
|
655
|
+
space = ColorSpace.get(space);
|
|
656
|
+
color.coords = space.to(color.space, coords);
|
|
657
|
+
return color;
|
|
658
|
+
}
|
|
659
|
+
setAll.returns = "color";
|
|
660
|
+
function set(color, prop, value) {
|
|
661
|
+
color = getColor(color);
|
|
662
|
+
if (arguments.length === 2 && type(arguments[1]) === "object") {
|
|
663
|
+
let object = arguments[1];
|
|
664
|
+
for (let p$1 in object) set(color, p$1, object[p$1]);
|
|
665
|
+
} else {
|
|
666
|
+
if (typeof value === "function") value = value(get(color, prop));
|
|
667
|
+
let { space, index } = ColorSpace.resolveCoord(prop, color.space);
|
|
668
|
+
let coords = getAll(color, space);
|
|
669
|
+
coords[index] = value;
|
|
670
|
+
setAll(color, space, coords);
|
|
671
|
+
}
|
|
672
|
+
return color;
|
|
673
|
+
}
|
|
674
|
+
set.returns = "color";
|
|
675
|
+
var XYZ_D50 = new ColorSpace({
|
|
676
|
+
id: "xyz-d50",
|
|
677
|
+
name: "XYZ D50",
|
|
678
|
+
white: "D50",
|
|
679
|
+
base: xyz_d65,
|
|
680
|
+
fromBase: (coords) => adapt$2(xyz_d65.white, "D50", coords),
|
|
681
|
+
toBase: (coords) => adapt$2("D50", xyz_d65.white, coords)
|
|
682
|
+
});
|
|
683
|
+
var ε$6 = 216 / 24389;
|
|
684
|
+
var ε3$1 = 24 / 116;
|
|
685
|
+
var κ$4 = 24389 / 27;
|
|
686
|
+
var white$4 = WHITES.D50;
|
|
687
|
+
var lab = new ColorSpace({
|
|
688
|
+
id: "lab",
|
|
689
|
+
name: "Lab",
|
|
690
|
+
coords: {
|
|
691
|
+
l: {
|
|
692
|
+
refRange: [0, 100],
|
|
693
|
+
name: "Lightness"
|
|
694
|
+
},
|
|
695
|
+
a: { refRange: [-125, 125] },
|
|
696
|
+
b: { refRange: [-125, 125] }
|
|
697
|
+
},
|
|
698
|
+
white: white$4,
|
|
699
|
+
base: XYZ_D50,
|
|
700
|
+
fromBase(XYZ) {
|
|
701
|
+
let f = XYZ.map((value, i) => value / white$4[i]).map((value) => value > ε$6 ? Math.cbrt(value) : (κ$4 * value + 16) / 116);
|
|
702
|
+
return [
|
|
703
|
+
116 * f[1] - 16,
|
|
704
|
+
500 * (f[0] - f[1]),
|
|
705
|
+
200 * (f[1] - f[2])
|
|
706
|
+
];
|
|
707
|
+
},
|
|
708
|
+
toBase(Lab) {
|
|
709
|
+
let f = [];
|
|
710
|
+
f[1] = (Lab[0] + 16) / 116;
|
|
711
|
+
f[0] = Lab[1] / 500 + f[1];
|
|
712
|
+
f[2] = f[1] - Lab[2] / 200;
|
|
713
|
+
return [
|
|
714
|
+
f[0] > ε3$1 ? Math.pow(f[0], 3) : (116 * f[0] - 16) / κ$4,
|
|
715
|
+
Lab[0] > 8 ? Math.pow((Lab[0] + 16) / 116, 3) : Lab[0] / κ$4,
|
|
716
|
+
f[2] > ε3$1 ? Math.pow(f[2], 3) : (116 * f[2] - 16) / κ$4
|
|
717
|
+
].map((value, i) => value * white$4[i]);
|
|
718
|
+
},
|
|
719
|
+
formats: { "lab": { coords: [
|
|
720
|
+
"<number> | <percentage>",
|
|
721
|
+
"<number> | <percentage>[-1,1]",
|
|
722
|
+
"<number> | <percentage>[-1,1]"
|
|
723
|
+
] } }
|
|
724
|
+
});
|
|
725
|
+
function constrain(angle) {
|
|
726
|
+
return (angle % 360 + 360) % 360;
|
|
727
|
+
}
|
|
728
|
+
function adjust(arc, angles) {
|
|
729
|
+
if (arc === "raw") return angles;
|
|
730
|
+
let [a1, a2] = angles.map(constrain);
|
|
731
|
+
let angleDiff = a2 - a1;
|
|
732
|
+
if (arc === "increasing") {
|
|
733
|
+
if (angleDiff < 0) a2 += 360;
|
|
734
|
+
} else if (arc === "decreasing") {
|
|
735
|
+
if (angleDiff > 0) a1 += 360;
|
|
736
|
+
} else if (arc === "longer") {
|
|
737
|
+
if (-180 < angleDiff && angleDiff < 180) if (angleDiff > 0) a1 += 360;
|
|
738
|
+
else a2 += 360;
|
|
739
|
+
} else if (arc === "shorter") {
|
|
740
|
+
if (angleDiff > 180) a1 += 360;
|
|
741
|
+
else if (angleDiff < -180) a2 += 360;
|
|
742
|
+
}
|
|
743
|
+
return [a1, a2];
|
|
744
|
+
}
|
|
745
|
+
var lch = new ColorSpace({
|
|
746
|
+
id: "lch",
|
|
747
|
+
name: "LCH",
|
|
748
|
+
coords: {
|
|
749
|
+
l: {
|
|
750
|
+
refRange: [0, 100],
|
|
751
|
+
name: "Lightness"
|
|
752
|
+
},
|
|
753
|
+
c: {
|
|
754
|
+
refRange: [0, 150],
|
|
755
|
+
name: "Chroma"
|
|
756
|
+
},
|
|
757
|
+
h: {
|
|
758
|
+
refRange: [0, 360],
|
|
759
|
+
type: "angle",
|
|
760
|
+
name: "Hue"
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
base: lab,
|
|
764
|
+
fromBase(Lab) {
|
|
765
|
+
let [L, a$1, b$2] = Lab;
|
|
766
|
+
let hue;
|
|
767
|
+
const ε$8 = .02;
|
|
768
|
+
if (Math.abs(a$1) < ε$8 && Math.abs(b$2) < ε$8) hue = NaN;
|
|
769
|
+
else hue = Math.atan2(b$2, a$1) * 180 / Math.PI;
|
|
770
|
+
return [
|
|
771
|
+
L,
|
|
772
|
+
Math.sqrt(a$1 ** 2 + b$2 ** 2),
|
|
773
|
+
constrain(hue)
|
|
774
|
+
];
|
|
775
|
+
},
|
|
776
|
+
toBase(LCH) {
|
|
777
|
+
let [Lightness, Chroma, Hue] = LCH;
|
|
778
|
+
if (Chroma < 0) Chroma = 0;
|
|
779
|
+
if (isNaN(Hue)) Hue = 0;
|
|
780
|
+
return [
|
|
781
|
+
Lightness,
|
|
782
|
+
Chroma * Math.cos(Hue * Math.PI / 180),
|
|
783
|
+
Chroma * Math.sin(Hue * Math.PI / 180)
|
|
784
|
+
];
|
|
785
|
+
},
|
|
786
|
+
formats: { "lch": { coords: [
|
|
787
|
+
"<number> | <percentage>",
|
|
788
|
+
"<number> | <percentage>",
|
|
789
|
+
"<number> | <angle>"
|
|
790
|
+
] } }
|
|
791
|
+
});
|
|
792
|
+
var Gfactor = 25 ** 7;
|
|
793
|
+
var π$1 = Math.PI;
|
|
794
|
+
var r2d = 180 / π$1;
|
|
795
|
+
var d2r$1 = π$1 / 180;
|
|
796
|
+
function pow7(x) {
|
|
797
|
+
const x2 = x * x;
|
|
798
|
+
return x2 * x2 * x2 * x;
|
|
799
|
+
}
|
|
800
|
+
function deltaE2000(color, sample, { kL = 1, kC = 1, kH = 1 } = {}) {
|
|
801
|
+
[color, sample] = getColor([color, sample]);
|
|
802
|
+
let [L1, a1, b1] = lab.from(color);
|
|
803
|
+
let C1 = lch.from(lab, [
|
|
804
|
+
L1,
|
|
805
|
+
a1,
|
|
806
|
+
b1
|
|
807
|
+
])[1];
|
|
808
|
+
let [L2, a2, b2] = lab.from(sample);
|
|
809
|
+
let C2 = lch.from(lab, [
|
|
810
|
+
L2,
|
|
811
|
+
a2,
|
|
812
|
+
b2
|
|
813
|
+
])[1];
|
|
814
|
+
if (C1 < 0) C1 = 0;
|
|
815
|
+
if (C2 < 0) C2 = 0;
|
|
816
|
+
let C7 = pow7((C1 + C2) / 2);
|
|
817
|
+
let G = .5 * (1 - Math.sqrt(C7 / (C7 + Gfactor)));
|
|
818
|
+
let adash1 = (1 + G) * a1;
|
|
819
|
+
let adash2 = (1 + G) * a2;
|
|
820
|
+
let Cdash1 = Math.sqrt(adash1 ** 2 + b1 ** 2);
|
|
821
|
+
let Cdash2 = Math.sqrt(adash2 ** 2 + b2 ** 2);
|
|
822
|
+
let h1 = adash1 === 0 && b1 === 0 ? 0 : Math.atan2(b1, adash1);
|
|
823
|
+
let h2 = adash2 === 0 && b2 === 0 ? 0 : Math.atan2(b2, adash2);
|
|
824
|
+
if (h1 < 0) h1 += 2 * π$1;
|
|
825
|
+
if (h2 < 0) h2 += 2 * π$1;
|
|
826
|
+
h1 *= r2d;
|
|
827
|
+
h2 *= r2d;
|
|
828
|
+
let ΔL = L2 - L1;
|
|
829
|
+
let ΔC = Cdash2 - Cdash1;
|
|
830
|
+
let hdiff = h2 - h1;
|
|
831
|
+
let hsum = h1 + h2;
|
|
832
|
+
let habs = Math.abs(hdiff);
|
|
833
|
+
let Δh;
|
|
834
|
+
if (Cdash1 * Cdash2 === 0) Δh = 0;
|
|
835
|
+
else if (habs <= 180) Δh = hdiff;
|
|
836
|
+
else if (hdiff > 180) Δh = hdiff - 360;
|
|
837
|
+
else if (hdiff < -180) Δh = hdiff + 360;
|
|
838
|
+
else defaults.warn("the unthinkable has happened");
|
|
839
|
+
let ΔH = 2 * Math.sqrt(Cdash2 * Cdash1) * Math.sin(Δh * d2r$1 / 2);
|
|
840
|
+
let Ldash = (L1 + L2) / 2;
|
|
841
|
+
let Cdash = (Cdash1 + Cdash2) / 2;
|
|
842
|
+
let Cdash7 = pow7(Cdash);
|
|
843
|
+
let hdash;
|
|
844
|
+
if (Cdash1 * Cdash2 === 0) hdash = hsum;
|
|
845
|
+
else if (habs <= 180) hdash = hsum / 2;
|
|
846
|
+
else if (hsum < 360) hdash = (hsum + 360) / 2;
|
|
847
|
+
else hdash = (hsum - 360) / 2;
|
|
848
|
+
let lsq = (Ldash - 50) ** 2;
|
|
849
|
+
let SL = 1 + .015 * lsq / Math.sqrt(20 + lsq);
|
|
850
|
+
let SC = 1 + .045 * Cdash;
|
|
851
|
+
let T = 1;
|
|
852
|
+
T -= .17 * Math.cos((hdash - 30) * d2r$1);
|
|
853
|
+
T += .24 * Math.cos(2 * hdash * d2r$1);
|
|
854
|
+
T += .32 * Math.cos((3 * hdash + 6) * d2r$1);
|
|
855
|
+
T -= .2 * Math.cos((4 * hdash - 63) * d2r$1);
|
|
856
|
+
let SH = 1 + .015 * Cdash * T;
|
|
857
|
+
let Δθ = 30 * Math.exp(-1 * ((hdash - 275) / 25) ** 2);
|
|
858
|
+
let RC = 2 * Math.sqrt(Cdash7 / (Cdash7 + Gfactor));
|
|
859
|
+
let RT = -1 * Math.sin(2 * Δθ * d2r$1) * RC;
|
|
860
|
+
let dE = (ΔL / (kL * SL)) ** 2;
|
|
861
|
+
dE += (ΔC / (kC * SC)) ** 2;
|
|
862
|
+
dE += (ΔH / (kH * SH)) ** 2;
|
|
863
|
+
dE += RT * (ΔC / (kC * SC)) * (ΔH / (kH * SH));
|
|
864
|
+
return Math.sqrt(dE);
|
|
865
|
+
}
|
|
866
|
+
var XYZtoLMS_M$1 = [
|
|
867
|
+
[
|
|
868
|
+
.819022437996703,
|
|
869
|
+
.3619062600528904,
|
|
870
|
+
-.1288737815209879
|
|
871
|
+
],
|
|
872
|
+
[
|
|
873
|
+
.0329836539323885,
|
|
874
|
+
.9292868615863434,
|
|
875
|
+
.0361446663506424
|
|
876
|
+
],
|
|
877
|
+
[
|
|
878
|
+
.0481771893596242,
|
|
879
|
+
.2642395317527308,
|
|
880
|
+
.6335478284694309
|
|
881
|
+
]
|
|
882
|
+
];
|
|
883
|
+
var LMStoXYZ_M$1 = [
|
|
884
|
+
[
|
|
885
|
+
1.2268798758459243,
|
|
886
|
+
-.5578149944602171,
|
|
887
|
+
.2813910456659647
|
|
888
|
+
],
|
|
889
|
+
[
|
|
890
|
+
-.0405757452148008,
|
|
891
|
+
1.112286803280317,
|
|
892
|
+
-.0717110580655164
|
|
893
|
+
],
|
|
894
|
+
[
|
|
895
|
+
-.0763729366746601,
|
|
896
|
+
-.4214933324022432,
|
|
897
|
+
1.5869240198367816
|
|
898
|
+
]
|
|
899
|
+
];
|
|
900
|
+
var LMStoLab_M = [
|
|
901
|
+
[
|
|
902
|
+
.210454268309314,
|
|
903
|
+
.7936177747023054,
|
|
904
|
+
-.0040720430116193
|
|
905
|
+
],
|
|
906
|
+
[
|
|
907
|
+
1.9779985324311684,
|
|
908
|
+
-2.42859224204858,
|
|
909
|
+
.450593709617411
|
|
910
|
+
],
|
|
911
|
+
[
|
|
912
|
+
.0259040424655478,
|
|
913
|
+
.7827717124575296,
|
|
914
|
+
-.8086757549230774
|
|
915
|
+
]
|
|
916
|
+
];
|
|
917
|
+
var LabtoLMS_M = [
|
|
918
|
+
[
|
|
919
|
+
1,
|
|
920
|
+
.3963377773761749,
|
|
921
|
+
.2158037573099136
|
|
922
|
+
],
|
|
923
|
+
[
|
|
924
|
+
1,
|
|
925
|
+
-.1055613458156586,
|
|
926
|
+
-.0638541728258133
|
|
927
|
+
],
|
|
928
|
+
[
|
|
929
|
+
1,
|
|
930
|
+
-.0894841775298119,
|
|
931
|
+
-1.2914855480194092
|
|
932
|
+
]
|
|
933
|
+
];
|
|
934
|
+
var OKLab = new ColorSpace({
|
|
935
|
+
id: "oklab",
|
|
936
|
+
name: "Oklab",
|
|
937
|
+
coords: {
|
|
938
|
+
l: {
|
|
939
|
+
refRange: [0, 1],
|
|
940
|
+
name: "Lightness"
|
|
941
|
+
},
|
|
942
|
+
a: { refRange: [-.4, .4] },
|
|
943
|
+
b: { refRange: [-.4, .4] }
|
|
944
|
+
},
|
|
945
|
+
white: "D65",
|
|
946
|
+
base: xyz_d65,
|
|
947
|
+
fromBase(XYZ) {
|
|
948
|
+
return multiplyMatrices(LMStoLab_M, multiplyMatrices(XYZtoLMS_M$1, XYZ).map((val) => Math.cbrt(val)));
|
|
949
|
+
},
|
|
950
|
+
toBase(OKLab$1) {
|
|
951
|
+
return multiplyMatrices(LMStoXYZ_M$1, multiplyMatrices(LabtoLMS_M, OKLab$1).map((val) => val ** 3));
|
|
952
|
+
},
|
|
953
|
+
formats: { "oklab": { coords: [
|
|
954
|
+
"<percentage> | <number>",
|
|
955
|
+
"<number> | <percentage>[-1,1]",
|
|
956
|
+
"<number> | <percentage>[-1,1]"
|
|
957
|
+
] } }
|
|
958
|
+
});
|
|
959
|
+
function deltaEOK(color, sample) {
|
|
960
|
+
[color, sample] = getColor([color, sample]);
|
|
961
|
+
let [L1, a1, b1] = OKLab.from(color);
|
|
962
|
+
let [L2, a2, b2] = OKLab.from(sample);
|
|
963
|
+
let ΔL = L1 - L2;
|
|
964
|
+
let Δa = a1 - a2;
|
|
965
|
+
let Δb = b1 - b2;
|
|
966
|
+
return Math.sqrt(ΔL ** 2 + Δa ** 2 + Δb ** 2);
|
|
967
|
+
}
|
|
968
|
+
var ε$5 = 75e-6;
|
|
969
|
+
function inGamut(color, space, { epsilon = ε$5 } = {}) {
|
|
970
|
+
color = getColor(color);
|
|
971
|
+
if (!space) space = color.space;
|
|
972
|
+
space = ColorSpace.get(space);
|
|
973
|
+
let coords = color.coords;
|
|
974
|
+
if (space !== color.space) coords = space.from(color);
|
|
975
|
+
return space.inGamut(coords, { epsilon });
|
|
976
|
+
}
|
|
977
|
+
function clone(color) {
|
|
978
|
+
return {
|
|
979
|
+
space: color.space,
|
|
980
|
+
coords: color.coords.slice(),
|
|
981
|
+
alpha: color.alpha
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
function distance(color1, color2, space = "lab") {
|
|
985
|
+
space = ColorSpace.get(space);
|
|
986
|
+
let coords1 = space.from(color1);
|
|
987
|
+
let coords2 = space.from(color2);
|
|
988
|
+
return Math.sqrt(coords1.reduce((acc, c1$3, i) => {
|
|
989
|
+
let c2$3 = coords2[i];
|
|
990
|
+
if (isNaN(c1$3) || isNaN(c2$3)) return acc;
|
|
991
|
+
return acc + (c2$3 - c1$3) ** 2;
|
|
992
|
+
}, 0));
|
|
993
|
+
}
|
|
994
|
+
function deltaE76(color, sample) {
|
|
995
|
+
return distance(color, sample, "lab");
|
|
996
|
+
}
|
|
997
|
+
var d2r = Math.PI / 180;
|
|
998
|
+
function deltaECMC(color, sample, { l = 2, c: c$1 = 1 } = {}) {
|
|
999
|
+
[color, sample] = getColor([color, sample]);
|
|
1000
|
+
let [L1, a1, b1] = lab.from(color);
|
|
1001
|
+
let [, C1, H1] = lch.from(lab, [
|
|
1002
|
+
L1,
|
|
1003
|
+
a1,
|
|
1004
|
+
b1
|
|
1005
|
+
]);
|
|
1006
|
+
let [L2, a2, b2] = lab.from(sample);
|
|
1007
|
+
let C2 = lch.from(lab, [
|
|
1008
|
+
L2,
|
|
1009
|
+
a2,
|
|
1010
|
+
b2
|
|
1011
|
+
])[1];
|
|
1012
|
+
if (C1 < 0) C1 = 0;
|
|
1013
|
+
if (C2 < 0) C2 = 0;
|
|
1014
|
+
let ΔL = L1 - L2;
|
|
1015
|
+
let ΔC = C1 - C2;
|
|
1016
|
+
let Δa = a1 - a2;
|
|
1017
|
+
let Δb = b1 - b2;
|
|
1018
|
+
let H2 = Δa ** 2 + Δb ** 2 - ΔC ** 2;
|
|
1019
|
+
let SL = .511;
|
|
1020
|
+
if (L1 >= 16) SL = .040975 * L1 / (1 + .01765 * L1);
|
|
1021
|
+
let SC = .0638 * C1 / (1 + .0131 * C1) + .638;
|
|
1022
|
+
let T;
|
|
1023
|
+
if (Number.isNaN(H1)) H1 = 0;
|
|
1024
|
+
if (H1 >= 164 && H1 <= 345) T = .56 + Math.abs(.2 * Math.cos((H1 + 168) * d2r));
|
|
1025
|
+
else T = .36 + Math.abs(.4 * Math.cos((H1 + 35) * d2r));
|
|
1026
|
+
let C4 = Math.pow(C1, 4);
|
|
1027
|
+
let F = Math.sqrt(C4 / (C4 + 1900));
|
|
1028
|
+
let SH = SC * (F * T + 1 - F);
|
|
1029
|
+
let dE = (ΔL / (l * SL)) ** 2;
|
|
1030
|
+
dE += (ΔC / (c$1 * SC)) ** 2;
|
|
1031
|
+
dE += H2 / SH ** 2;
|
|
1032
|
+
return Math.sqrt(dE);
|
|
1033
|
+
}
|
|
1034
|
+
var Yw$1 = 203;
|
|
1035
|
+
var XYZ_Abs_D65 = new ColorSpace({
|
|
1036
|
+
id: "xyz-abs-d65",
|
|
1037
|
+
cssId: "--xyz-abs-d65",
|
|
1038
|
+
name: "Absolute XYZ D65",
|
|
1039
|
+
coords: {
|
|
1040
|
+
x: {
|
|
1041
|
+
refRange: [0, 9504.7],
|
|
1042
|
+
name: "Xa"
|
|
1043
|
+
},
|
|
1044
|
+
y: {
|
|
1045
|
+
refRange: [0, 1e4],
|
|
1046
|
+
name: "Ya"
|
|
1047
|
+
},
|
|
1048
|
+
z: {
|
|
1049
|
+
refRange: [0, 10888.3],
|
|
1050
|
+
name: "Za"
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
base: xyz_d65,
|
|
1054
|
+
fromBase(XYZ) {
|
|
1055
|
+
return XYZ.map((v) => Math.max(v * Yw$1, 0));
|
|
1056
|
+
},
|
|
1057
|
+
toBase(AbsXYZ) {
|
|
1058
|
+
return AbsXYZ.map((v) => Math.max(v / Yw$1, 0));
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
var b$1 = 1.15;
|
|
1062
|
+
var g = .66;
|
|
1063
|
+
var n$1 = 2610 / 2 ** 14;
|
|
1064
|
+
var ninv$1 = 2 ** 14 / 2610;
|
|
1065
|
+
var c1$2 = 3424 / 2 ** 12;
|
|
1066
|
+
var c2$2 = 2413 / 2 ** 7;
|
|
1067
|
+
var c3$2 = 2392 / 2 ** 7;
|
|
1068
|
+
var p = 1.7 * 2523 / 2 ** 5;
|
|
1069
|
+
var pinv = 2 ** 5 / (1.7 * 2523);
|
|
1070
|
+
var d = -.56;
|
|
1071
|
+
var d0 = 16295499532821565e-27;
|
|
1072
|
+
var XYZtoCone_M = [
|
|
1073
|
+
[
|
|
1074
|
+
.41478972,
|
|
1075
|
+
.579999,
|
|
1076
|
+
.014648
|
|
1077
|
+
],
|
|
1078
|
+
[
|
|
1079
|
+
-.20151,
|
|
1080
|
+
1.120649,
|
|
1081
|
+
.0531008
|
|
1082
|
+
],
|
|
1083
|
+
[
|
|
1084
|
+
-.0166008,
|
|
1085
|
+
.2648,
|
|
1086
|
+
.6684799
|
|
1087
|
+
]
|
|
1088
|
+
];
|
|
1089
|
+
var ConetoXYZ_M = [
|
|
1090
|
+
[
|
|
1091
|
+
1.9242264357876067,
|
|
1092
|
+
-1.0047923125953657,
|
|
1093
|
+
.037651404030618
|
|
1094
|
+
],
|
|
1095
|
+
[
|
|
1096
|
+
.35031676209499907,
|
|
1097
|
+
.7264811939316552,
|
|
1098
|
+
-.06538442294808501
|
|
1099
|
+
],
|
|
1100
|
+
[
|
|
1101
|
+
-.09098281098284752,
|
|
1102
|
+
-.3127282905230739,
|
|
1103
|
+
1.5227665613052603
|
|
1104
|
+
]
|
|
1105
|
+
];
|
|
1106
|
+
var ConetoIab_M = [
|
|
1107
|
+
[
|
|
1108
|
+
.5,
|
|
1109
|
+
.5,
|
|
1110
|
+
0
|
|
1111
|
+
],
|
|
1112
|
+
[
|
|
1113
|
+
3.524,
|
|
1114
|
+
-4.066708,
|
|
1115
|
+
.542708
|
|
1116
|
+
],
|
|
1117
|
+
[
|
|
1118
|
+
.199076,
|
|
1119
|
+
1.096799,
|
|
1120
|
+
-1.295875
|
|
1121
|
+
]
|
|
1122
|
+
];
|
|
1123
|
+
var IabtoCone_M = [
|
|
1124
|
+
[
|
|
1125
|
+
1,
|
|
1126
|
+
.1386050432715393,
|
|
1127
|
+
.05804731615611886
|
|
1128
|
+
],
|
|
1129
|
+
[
|
|
1130
|
+
.9999999999999999,
|
|
1131
|
+
-.1386050432715393,
|
|
1132
|
+
-.05804731615611886
|
|
1133
|
+
],
|
|
1134
|
+
[
|
|
1135
|
+
.9999999999999998,
|
|
1136
|
+
-.09601924202631895,
|
|
1137
|
+
-.8118918960560388
|
|
1138
|
+
]
|
|
1139
|
+
];
|
|
1140
|
+
var Jzazbz = new ColorSpace({
|
|
1141
|
+
id: "jzazbz",
|
|
1142
|
+
name: "Jzazbz",
|
|
1143
|
+
coords: {
|
|
1144
|
+
jz: {
|
|
1145
|
+
refRange: [0, 1],
|
|
1146
|
+
name: "Jz"
|
|
1147
|
+
},
|
|
1148
|
+
az: { refRange: [-.5, .5] },
|
|
1149
|
+
bz: { refRange: [-.5, .5] }
|
|
1150
|
+
},
|
|
1151
|
+
base: XYZ_Abs_D65,
|
|
1152
|
+
fromBase(XYZ) {
|
|
1153
|
+
let [Xa, Ya, Za] = XYZ;
|
|
1154
|
+
let [Iz, az, bz] = multiplyMatrices(ConetoIab_M, multiplyMatrices(XYZtoCone_M, [
|
|
1155
|
+
b$1 * Xa - (b$1 - 1) * Za,
|
|
1156
|
+
g * Ya - (g - 1) * Xa,
|
|
1157
|
+
Za
|
|
1158
|
+
]).map(function(val) {
|
|
1159
|
+
return ((c1$2 + c2$2 * (val / 1e4) ** n$1) / (1 + c3$2 * (val / 1e4) ** n$1)) ** p;
|
|
1160
|
+
}));
|
|
1161
|
+
return [
|
|
1162
|
+
(1 + d) * Iz / (1 + d * Iz) - d0,
|
|
1163
|
+
az,
|
|
1164
|
+
bz
|
|
1165
|
+
];
|
|
1166
|
+
},
|
|
1167
|
+
toBase(Jzazbz$1) {
|
|
1168
|
+
let [Jz, az, bz] = Jzazbz$1;
|
|
1169
|
+
let [Xm, Ym, Za] = multiplyMatrices(ConetoXYZ_M, multiplyMatrices(IabtoCone_M, [
|
|
1170
|
+
(Jz + d0) / (1 + d - d * (Jz + d0)),
|
|
1171
|
+
az,
|
|
1172
|
+
bz
|
|
1173
|
+
]).map(function(val) {
|
|
1174
|
+
return 1e4 * ((c1$2 - val ** pinv) / (c3$2 * val ** pinv - c2$2)) ** ninv$1;
|
|
1175
|
+
}));
|
|
1176
|
+
let Xa = (Xm + (b$1 - 1) * Za) / b$1;
|
|
1177
|
+
return [
|
|
1178
|
+
Xa,
|
|
1179
|
+
(Ym + (g - 1) * Xa) / g,
|
|
1180
|
+
Za
|
|
1181
|
+
];
|
|
1182
|
+
},
|
|
1183
|
+
formats: { "color": { coords: [
|
|
1184
|
+
"<number> | <percentage>",
|
|
1185
|
+
"<number> | <percentage>[-1,1]",
|
|
1186
|
+
"<number> | <percentage>[-1,1]"
|
|
1187
|
+
] } }
|
|
1188
|
+
});
|
|
1189
|
+
var jzczhz = new ColorSpace({
|
|
1190
|
+
id: "jzczhz",
|
|
1191
|
+
name: "JzCzHz",
|
|
1192
|
+
coords: {
|
|
1193
|
+
jz: {
|
|
1194
|
+
refRange: [0, 1],
|
|
1195
|
+
name: "Jz"
|
|
1196
|
+
},
|
|
1197
|
+
cz: {
|
|
1198
|
+
refRange: [0, 1],
|
|
1199
|
+
name: "Chroma"
|
|
1200
|
+
},
|
|
1201
|
+
hz: {
|
|
1202
|
+
refRange: [0, 360],
|
|
1203
|
+
type: "angle",
|
|
1204
|
+
name: "Hue"
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
base: Jzazbz,
|
|
1208
|
+
fromBase(jzazbz) {
|
|
1209
|
+
let [Jz, az, bz] = jzazbz;
|
|
1210
|
+
let hue;
|
|
1211
|
+
const ε$8 = 2e-4;
|
|
1212
|
+
if (Math.abs(az) < ε$8 && Math.abs(bz) < ε$8) hue = NaN;
|
|
1213
|
+
else hue = Math.atan2(bz, az) * 180 / Math.PI;
|
|
1214
|
+
return [
|
|
1215
|
+
Jz,
|
|
1216
|
+
Math.sqrt(az ** 2 + bz ** 2),
|
|
1217
|
+
constrain(hue)
|
|
1218
|
+
];
|
|
1219
|
+
},
|
|
1220
|
+
toBase(jzczhz$1) {
|
|
1221
|
+
return [
|
|
1222
|
+
jzczhz$1[0],
|
|
1223
|
+
jzczhz$1[1] * Math.cos(jzczhz$1[2] * Math.PI / 180),
|
|
1224
|
+
jzczhz$1[1] * Math.sin(jzczhz$1[2] * Math.PI / 180)
|
|
1225
|
+
];
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
function deltaEJz(color, sample) {
|
|
1229
|
+
[color, sample] = getColor([color, sample]);
|
|
1230
|
+
let [Jz1, Cz1, Hz1] = jzczhz.from(color);
|
|
1231
|
+
let [Jz2, Cz2, Hz2] = jzczhz.from(sample);
|
|
1232
|
+
let ΔJ = Jz1 - Jz2;
|
|
1233
|
+
let ΔC = Cz1 - Cz2;
|
|
1234
|
+
if (Number.isNaN(Hz1) && Number.isNaN(Hz2)) {
|
|
1235
|
+
Hz1 = 0;
|
|
1236
|
+
Hz2 = 0;
|
|
1237
|
+
} else if (Number.isNaN(Hz1)) Hz1 = Hz2;
|
|
1238
|
+
else if (Number.isNaN(Hz2)) Hz2 = Hz1;
|
|
1239
|
+
let Δh = Hz1 - Hz2;
|
|
1240
|
+
let ΔH = 2 * Math.sqrt(Cz1 * Cz2) * Math.sin(Δh / 2 * (Math.PI / 180));
|
|
1241
|
+
return Math.sqrt(ΔJ ** 2 + ΔC ** 2 + ΔH ** 2);
|
|
1242
|
+
}
|
|
1243
|
+
var c1$1 = 3424 / 4096;
|
|
1244
|
+
var c2$1 = 2413 / 128;
|
|
1245
|
+
var c3$1 = 2392 / 128;
|
|
1246
|
+
var m1$1 = 2610 / 16384;
|
|
1247
|
+
var m2 = 2523 / 32;
|
|
1248
|
+
var im1 = 16384 / 2610;
|
|
1249
|
+
var im2 = 32 / 2523;
|
|
1250
|
+
var XYZtoLMS_M = [
|
|
1251
|
+
[
|
|
1252
|
+
.3592832590121217,
|
|
1253
|
+
.6976051147779502,
|
|
1254
|
+
-.035891593232029
|
|
1255
|
+
],
|
|
1256
|
+
[
|
|
1257
|
+
-.1920808463704993,
|
|
1258
|
+
1.100476797037432,
|
|
1259
|
+
.0753748658519118
|
|
1260
|
+
],
|
|
1261
|
+
[
|
|
1262
|
+
.0070797844607479,
|
|
1263
|
+
.0748396662186362,
|
|
1264
|
+
.8433265453898765
|
|
1265
|
+
]
|
|
1266
|
+
];
|
|
1267
|
+
var LMStoIPT_M = [
|
|
1268
|
+
[
|
|
1269
|
+
2048 / 4096,
|
|
1270
|
+
2048 / 4096,
|
|
1271
|
+
0
|
|
1272
|
+
],
|
|
1273
|
+
[
|
|
1274
|
+
6610 / 4096,
|
|
1275
|
+
-13613 / 4096,
|
|
1276
|
+
7003 / 4096
|
|
1277
|
+
],
|
|
1278
|
+
[
|
|
1279
|
+
17933 / 4096,
|
|
1280
|
+
-17390 / 4096,
|
|
1281
|
+
-543 / 4096
|
|
1282
|
+
]
|
|
1283
|
+
];
|
|
1284
|
+
var IPTtoLMS_M = [
|
|
1285
|
+
[
|
|
1286
|
+
.9999999999999998,
|
|
1287
|
+
.0086090370379328,
|
|
1288
|
+
.111029625003026
|
|
1289
|
+
],
|
|
1290
|
+
[
|
|
1291
|
+
.9999999999999998,
|
|
1292
|
+
-.0086090370379328,
|
|
1293
|
+
-.1110296250030259
|
|
1294
|
+
],
|
|
1295
|
+
[
|
|
1296
|
+
.9999999999999998,
|
|
1297
|
+
.5600313357106791,
|
|
1298
|
+
-.3206271749873188
|
|
1299
|
+
]
|
|
1300
|
+
];
|
|
1301
|
+
var LMStoXYZ_M = [
|
|
1302
|
+
[
|
|
1303
|
+
2.0701522183894223,
|
|
1304
|
+
-1.3263473389671563,
|
|
1305
|
+
.2066510476294053
|
|
1306
|
+
],
|
|
1307
|
+
[
|
|
1308
|
+
.3647385209748072,
|
|
1309
|
+
.6805660249472273,
|
|
1310
|
+
-.0453045459220347
|
|
1311
|
+
],
|
|
1312
|
+
[
|
|
1313
|
+
-.0497472075358123,
|
|
1314
|
+
-.0492609666966131,
|
|
1315
|
+
1.1880659249923042
|
|
1316
|
+
]
|
|
1317
|
+
];
|
|
1318
|
+
var ictcp = new ColorSpace({
|
|
1319
|
+
id: "ictcp",
|
|
1320
|
+
name: "ICTCP",
|
|
1321
|
+
coords: {
|
|
1322
|
+
i: {
|
|
1323
|
+
refRange: [0, 1],
|
|
1324
|
+
name: "I"
|
|
1325
|
+
},
|
|
1326
|
+
ct: {
|
|
1327
|
+
refRange: [-.5, .5],
|
|
1328
|
+
name: "CT"
|
|
1329
|
+
},
|
|
1330
|
+
cp: {
|
|
1331
|
+
refRange: [-.5, .5],
|
|
1332
|
+
name: "CP"
|
|
1333
|
+
}
|
|
1334
|
+
},
|
|
1335
|
+
base: XYZ_Abs_D65,
|
|
1336
|
+
fromBase(XYZ) {
|
|
1337
|
+
return LMStoICtCp(multiplyMatrices(XYZtoLMS_M, XYZ));
|
|
1338
|
+
},
|
|
1339
|
+
toBase(ICtCp) {
|
|
1340
|
+
return multiplyMatrices(LMStoXYZ_M, ICtCptoLMS(ICtCp));
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
function LMStoICtCp(LMS) {
|
|
1344
|
+
return multiplyMatrices(LMStoIPT_M, LMS.map(function(val) {
|
|
1345
|
+
return ((c1$1 + c2$1 * (val / 1e4) ** m1$1) / (1 + c3$1 * (val / 1e4) ** m1$1)) ** m2;
|
|
1346
|
+
}));
|
|
1347
|
+
}
|
|
1348
|
+
function ICtCptoLMS(ICtCp) {
|
|
1349
|
+
return multiplyMatrices(IPTtoLMS_M, ICtCp).map(function(val) {
|
|
1350
|
+
return 1e4 * (Math.max(val ** im2 - c1$1, 0) / (c2$1 - c3$1 * val ** im2)) ** im1;
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
function deltaEITP(color, sample) {
|
|
1354
|
+
[color, sample] = getColor([color, sample]);
|
|
1355
|
+
let [I1, T1, P1] = ictcp.from(color);
|
|
1356
|
+
let [I2, T2, P2] = ictcp.from(sample);
|
|
1357
|
+
return 720 * Math.sqrt((I1 - I2) ** 2 + .25 * (T1 - T2) ** 2 + (P1 - P2) ** 2);
|
|
1358
|
+
}
|
|
1359
|
+
var white$3 = WHITES.D65;
|
|
1360
|
+
var adaptedCoef = .42;
|
|
1361
|
+
var adaptedCoefInv = 1 / adaptedCoef;
|
|
1362
|
+
var tau = 2 * Math.PI;
|
|
1363
|
+
var cat16 = [
|
|
1364
|
+
[
|
|
1365
|
+
.401288,
|
|
1366
|
+
.650173,
|
|
1367
|
+
-.051461
|
|
1368
|
+
],
|
|
1369
|
+
[
|
|
1370
|
+
-.250268,
|
|
1371
|
+
1.204414,
|
|
1372
|
+
.045854
|
|
1373
|
+
],
|
|
1374
|
+
[
|
|
1375
|
+
-.002079,
|
|
1376
|
+
.048952,
|
|
1377
|
+
.953127
|
|
1378
|
+
]
|
|
1379
|
+
];
|
|
1380
|
+
var cat16Inv = [
|
|
1381
|
+
[
|
|
1382
|
+
1.8620678550872327,
|
|
1383
|
+
-1.0112546305316843,
|
|
1384
|
+
.14918677544445175
|
|
1385
|
+
],
|
|
1386
|
+
[
|
|
1387
|
+
.38752654323613717,
|
|
1388
|
+
.6214474419314753,
|
|
1389
|
+
-.008973985167612518
|
|
1390
|
+
],
|
|
1391
|
+
[
|
|
1392
|
+
-.015841498849333856,
|
|
1393
|
+
-.03412293802851557,
|
|
1394
|
+
1.0499644368778496
|
|
1395
|
+
]
|
|
1396
|
+
];
|
|
1397
|
+
var m1 = [
|
|
1398
|
+
[
|
|
1399
|
+
460,
|
|
1400
|
+
451,
|
|
1401
|
+
288
|
|
1402
|
+
],
|
|
1403
|
+
[
|
|
1404
|
+
460,
|
|
1405
|
+
-891,
|
|
1406
|
+
-261
|
|
1407
|
+
],
|
|
1408
|
+
[
|
|
1409
|
+
460,
|
|
1410
|
+
-220,
|
|
1411
|
+
-6300
|
|
1412
|
+
]
|
|
1413
|
+
];
|
|
1414
|
+
var surroundMap = {
|
|
1415
|
+
dark: [
|
|
1416
|
+
.8,
|
|
1417
|
+
.525,
|
|
1418
|
+
.8
|
|
1419
|
+
],
|
|
1420
|
+
dim: [
|
|
1421
|
+
.9,
|
|
1422
|
+
.59,
|
|
1423
|
+
.9
|
|
1424
|
+
],
|
|
1425
|
+
average: [
|
|
1426
|
+
1,
|
|
1427
|
+
.69,
|
|
1428
|
+
1
|
|
1429
|
+
]
|
|
1430
|
+
};
|
|
1431
|
+
var hueQuadMap = {
|
|
1432
|
+
h: [
|
|
1433
|
+
20.14,
|
|
1434
|
+
90,
|
|
1435
|
+
164.25,
|
|
1436
|
+
237.53,
|
|
1437
|
+
380.14
|
|
1438
|
+
],
|
|
1439
|
+
e: [
|
|
1440
|
+
.8,
|
|
1441
|
+
.7,
|
|
1442
|
+
1,
|
|
1443
|
+
1.2,
|
|
1444
|
+
.8
|
|
1445
|
+
],
|
|
1446
|
+
H: [
|
|
1447
|
+
0,
|
|
1448
|
+
100,
|
|
1449
|
+
200,
|
|
1450
|
+
300,
|
|
1451
|
+
400
|
|
1452
|
+
]
|
|
1453
|
+
};
|
|
1454
|
+
var rad2deg = 180 / Math.PI;
|
|
1455
|
+
var deg2rad$1 = Math.PI / 180;
|
|
1456
|
+
function adapt$1(coords, fl) {
|
|
1457
|
+
return coords.map((c$1) => {
|
|
1458
|
+
const x = spow(fl * Math.abs(c$1) * .01, adaptedCoef);
|
|
1459
|
+
return 400 * copySign(x, c$1) / (x + 27.13);
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
function unadapt(adapted, fl) {
|
|
1463
|
+
const constant = 100 / fl * 27.13 ** adaptedCoefInv;
|
|
1464
|
+
return adapted.map((c$1) => {
|
|
1465
|
+
const cabs = Math.abs(c$1);
|
|
1466
|
+
return copySign(constant * spow(cabs / (400 - cabs), adaptedCoefInv), c$1);
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
function hueQuadrature(h) {
|
|
1470
|
+
let hp = constrain(h);
|
|
1471
|
+
if (hp <= hueQuadMap.h[0]) hp += 360;
|
|
1472
|
+
const i = bisectLeft(hueQuadMap.h, hp) - 1;
|
|
1473
|
+
const [hi, hii] = hueQuadMap.h.slice(i, i + 2);
|
|
1474
|
+
const [ei, eii] = hueQuadMap.e.slice(i, i + 2);
|
|
1475
|
+
const Hi = hueQuadMap.H[i];
|
|
1476
|
+
const t = (hp - hi) / ei;
|
|
1477
|
+
return Hi + 100 * t / (t + (hii - hp) / eii);
|
|
1478
|
+
}
|
|
1479
|
+
function invHueQuadrature(H) {
|
|
1480
|
+
let Hp = (H % 400 + 400) % 400;
|
|
1481
|
+
const i = Math.floor(.01 * Hp);
|
|
1482
|
+
Hp = Hp % 100;
|
|
1483
|
+
const [hi, hii] = hueQuadMap.h.slice(i, i + 2);
|
|
1484
|
+
const [ei, eii] = hueQuadMap.e.slice(i, i + 2);
|
|
1485
|
+
return constrain((Hp * (eii * hi - ei * hii) - 100 * hi * eii) / (Hp * (eii - ei) - 100 * eii));
|
|
1486
|
+
}
|
|
1487
|
+
function environment(refWhite, adaptingLuminance, backgroundLuminance, surround, discounting) {
|
|
1488
|
+
const env = {};
|
|
1489
|
+
env.discounting = discounting;
|
|
1490
|
+
env.refWhite = refWhite;
|
|
1491
|
+
env.surround = surround;
|
|
1492
|
+
const xyzW = refWhite.map((c$1) => {
|
|
1493
|
+
return c$1 * 100;
|
|
1494
|
+
});
|
|
1495
|
+
env.la = adaptingLuminance;
|
|
1496
|
+
env.yb = backgroundLuminance;
|
|
1497
|
+
const yw = xyzW[1];
|
|
1498
|
+
const rgbW = multiplyMatrices(cat16, xyzW);
|
|
1499
|
+
surround = surroundMap[env.surround];
|
|
1500
|
+
const f = surround[0];
|
|
1501
|
+
env.c = surround[1];
|
|
1502
|
+
env.nc = surround[2];
|
|
1503
|
+
const k4 = (1 / (5 * env.la + 1)) ** 4;
|
|
1504
|
+
env.fl = k4 * env.la + .1 * (1 - k4) * (1 - k4) * Math.cbrt(5 * env.la);
|
|
1505
|
+
env.flRoot = env.fl ** .25;
|
|
1506
|
+
env.n = env.yb / yw;
|
|
1507
|
+
env.z = 1.48 + Math.sqrt(env.n);
|
|
1508
|
+
env.nbb = .725 * env.n ** -.2;
|
|
1509
|
+
env.ncb = env.nbb;
|
|
1510
|
+
const d$1 = discounting ? 1 : Math.max(Math.min(f * (1 - 1 / 3.6 * Math.exp((-env.la - 42) / 92)), 1), 0);
|
|
1511
|
+
env.dRgb = rgbW.map((c$1) => {
|
|
1512
|
+
return interpolate(1, yw / c$1, d$1);
|
|
1513
|
+
});
|
|
1514
|
+
env.dRgbInv = env.dRgb.map((c$1) => {
|
|
1515
|
+
return 1 / c$1;
|
|
1516
|
+
});
|
|
1517
|
+
const rgbAW = adapt$1(rgbW.map((c$1, i) => {
|
|
1518
|
+
return c$1 * env.dRgb[i];
|
|
1519
|
+
}), env.fl);
|
|
1520
|
+
env.aW = env.nbb * (2 * rgbAW[0] + rgbAW[1] + .05 * rgbAW[2]);
|
|
1521
|
+
return env;
|
|
1522
|
+
}
|
|
1523
|
+
var viewingConditions$1 = environment(white$3, 64 / Math.PI * .2, 20, "average", false);
|
|
1524
|
+
function fromCam16(cam16$1, env) {
|
|
1525
|
+
if (!(cam16$1.J !== void 0 ^ cam16$1.Q !== void 0)) throw new Error("Conversion requires one and only one: 'J' or 'Q'");
|
|
1526
|
+
if (!(cam16$1.C !== void 0 ^ cam16$1.M !== void 0 ^ cam16$1.s !== void 0)) throw new Error("Conversion requires one and only one: 'C', 'M' or 's'");
|
|
1527
|
+
if (!(cam16$1.h !== void 0 ^ cam16$1.H !== void 0)) throw new Error("Conversion requires one and only one: 'h' or 'H'");
|
|
1528
|
+
if (cam16$1.J === 0 || cam16$1.Q === 0) return [
|
|
1529
|
+
0,
|
|
1530
|
+
0,
|
|
1531
|
+
0
|
|
1532
|
+
];
|
|
1533
|
+
let hRad = 0;
|
|
1534
|
+
if (cam16$1.h !== void 0) hRad = constrain(cam16$1.h) * deg2rad$1;
|
|
1535
|
+
else hRad = invHueQuadrature(cam16$1.H) * deg2rad$1;
|
|
1536
|
+
const cosh = Math.cos(hRad);
|
|
1537
|
+
const sinh = Math.sin(hRad);
|
|
1538
|
+
let Jroot = 0;
|
|
1539
|
+
if (cam16$1.J !== void 0) Jroot = spow(cam16$1.J, 1 / 2) * .1;
|
|
1540
|
+
else if (cam16$1.Q !== void 0) Jroot = .25 * env.c * cam16$1.Q / ((env.aW + 4) * env.flRoot);
|
|
1541
|
+
let alpha = 0;
|
|
1542
|
+
if (cam16$1.C !== void 0) alpha = cam16$1.C / Jroot;
|
|
1543
|
+
else if (cam16$1.M !== void 0) alpha = cam16$1.M / env.flRoot / Jroot;
|
|
1544
|
+
else if (cam16$1.s !== void 0) alpha = 4e-4 * cam16$1.s ** 2 * (env.aW + 4) / env.c;
|
|
1545
|
+
const t = spow(alpha * Math.pow(1.64 - Math.pow(.29, env.n), -.73), 10 / 9);
|
|
1546
|
+
const et = .25 * (Math.cos(hRad + 2) + 3.8);
|
|
1547
|
+
const A = env.aW * spow(Jroot, 2 / env.c / env.z);
|
|
1548
|
+
const p1 = 5e4 / 13 * env.nc * env.ncb * et;
|
|
1549
|
+
const p2 = A / env.nbb;
|
|
1550
|
+
const r = 23 * (p2 + .305) * zdiv(t, 23 * p1 + t * (11 * cosh + 108 * sinh));
|
|
1551
|
+
return multiplyMatrices(cat16Inv, unadapt(multiplyMatrices(m1, [
|
|
1552
|
+
p2,
|
|
1553
|
+
r * cosh,
|
|
1554
|
+
r * sinh
|
|
1555
|
+
]).map((c$1) => {
|
|
1556
|
+
return c$1 * 1 / 1403;
|
|
1557
|
+
}), env.fl).map((c$1, i) => {
|
|
1558
|
+
return c$1 * env.dRgbInv[i];
|
|
1559
|
+
})).map((c$1) => {
|
|
1560
|
+
return c$1 / 100;
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
function toCam16(xyzd65, env) {
|
|
1564
|
+
const rgbA = adapt$1(multiplyMatrices(cat16, xyzd65.map((c$1) => {
|
|
1565
|
+
return c$1 * 100;
|
|
1566
|
+
})).map((c$1, i) => {
|
|
1567
|
+
return c$1 * env.dRgb[i];
|
|
1568
|
+
}), env.fl);
|
|
1569
|
+
const a$1 = rgbA[0] + (-12 * rgbA[1] + rgbA[2]) / 11;
|
|
1570
|
+
const b$2 = (rgbA[0] + rgbA[1] - 2 * rgbA[2]) / 9;
|
|
1571
|
+
const hRad = (Math.atan2(b$2, a$1) % tau + tau) % tau;
|
|
1572
|
+
const et = .25 * (Math.cos(hRad + 2) + 3.8);
|
|
1573
|
+
const alpha = spow(5e4 / 13 * env.nc * env.ncb * zdiv(et * Math.sqrt(a$1 ** 2 + b$2 ** 2), rgbA[0] + rgbA[1] + 1.05 * rgbA[2] + .305), .9) * Math.pow(1.64 - Math.pow(.29, env.n), .73);
|
|
1574
|
+
const Jroot = spow(env.nbb * (2 * rgbA[0] + rgbA[1] + .05 * rgbA[2]) / env.aW, .5 * env.c * env.z);
|
|
1575
|
+
const J = 100 * spow(Jroot, 2);
|
|
1576
|
+
const Q = 4 / env.c * Jroot * (env.aW + 4) * env.flRoot;
|
|
1577
|
+
const C = alpha * Jroot;
|
|
1578
|
+
const M = C * env.flRoot;
|
|
1579
|
+
const h = constrain(hRad * rad2deg);
|
|
1580
|
+
const H = hueQuadrature(h);
|
|
1581
|
+
return {
|
|
1582
|
+
J,
|
|
1583
|
+
C,
|
|
1584
|
+
h,
|
|
1585
|
+
s: 50 * spow(env.c * alpha / (env.aW + 4), 1 / 2),
|
|
1586
|
+
Q,
|
|
1587
|
+
M,
|
|
1588
|
+
H
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
var cam16 = new ColorSpace({
|
|
1592
|
+
id: "cam16-jmh",
|
|
1593
|
+
cssId: "--cam16-jmh",
|
|
1594
|
+
name: "CAM16-JMh",
|
|
1595
|
+
coords: {
|
|
1596
|
+
j: {
|
|
1597
|
+
refRange: [0, 100],
|
|
1598
|
+
name: "J"
|
|
1599
|
+
},
|
|
1600
|
+
m: {
|
|
1601
|
+
refRange: [0, 105],
|
|
1602
|
+
name: "Colorfulness"
|
|
1603
|
+
},
|
|
1604
|
+
h: {
|
|
1605
|
+
refRange: [0, 360],
|
|
1606
|
+
type: "angle",
|
|
1607
|
+
name: "Hue"
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
base: xyz_d65,
|
|
1611
|
+
fromBase(xyz) {
|
|
1612
|
+
const cam16$1 = toCam16(xyz, viewingConditions$1);
|
|
1613
|
+
return [
|
|
1614
|
+
cam16$1.J,
|
|
1615
|
+
cam16$1.M,
|
|
1616
|
+
cam16$1.h
|
|
1617
|
+
];
|
|
1618
|
+
},
|
|
1619
|
+
toBase(cam16$1) {
|
|
1620
|
+
return fromCam16({
|
|
1621
|
+
J: cam16$1[0],
|
|
1622
|
+
M: cam16$1[1],
|
|
1623
|
+
h: cam16$1[2]
|
|
1624
|
+
}, viewingConditions$1);
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
var white$2 = WHITES.D65;
|
|
1628
|
+
var ε$4 = 216 / 24389;
|
|
1629
|
+
var κ$3 = 24389 / 27;
|
|
1630
|
+
function toLstar(y) {
|
|
1631
|
+
return 116 * (y > ε$4 ? Math.cbrt(y) : (κ$3 * y + 16) / 116) - 16;
|
|
1632
|
+
}
|
|
1633
|
+
function fromLstar(lstar) {
|
|
1634
|
+
return lstar > 8 ? Math.pow((lstar + 16) / 116, 3) : lstar / κ$3;
|
|
1635
|
+
}
|
|
1636
|
+
function fromHct(coords, env) {
|
|
1637
|
+
let [h, c$1, t] = coords;
|
|
1638
|
+
let xyz = [];
|
|
1639
|
+
let j = 0;
|
|
1640
|
+
if (t === 0) return [
|
|
1641
|
+
0,
|
|
1642
|
+
0,
|
|
1643
|
+
0
|
|
1644
|
+
];
|
|
1645
|
+
let y = fromLstar(t);
|
|
1646
|
+
if (t > 0) j = .00379058511492914 * t ** 2 + .608983189401032 * t + .9155088574762233;
|
|
1647
|
+
else j = 9514440756550361e-21 * t ** 2 + .08693057439788597 * t - 21.928975842194614;
|
|
1648
|
+
const threshold = 2e-12;
|
|
1649
|
+
const max_attempts = 15;
|
|
1650
|
+
let attempt = 0;
|
|
1651
|
+
let last$1 = Infinity;
|
|
1652
|
+
while (attempt <= max_attempts) {
|
|
1653
|
+
xyz = fromCam16({
|
|
1654
|
+
J: j,
|
|
1655
|
+
C: c$1,
|
|
1656
|
+
h
|
|
1657
|
+
}, env);
|
|
1658
|
+
const delta = Math.abs(xyz[1] - y);
|
|
1659
|
+
if (delta < last$1) {
|
|
1660
|
+
if (delta <= threshold) return xyz;
|
|
1661
|
+
last$1 = delta;
|
|
1662
|
+
}
|
|
1663
|
+
j = j - (xyz[1] - y) * j / (2 * xyz[1]);
|
|
1664
|
+
attempt += 1;
|
|
1665
|
+
}
|
|
1666
|
+
return fromCam16({
|
|
1667
|
+
J: j,
|
|
1668
|
+
C: c$1,
|
|
1669
|
+
h
|
|
1670
|
+
}, env);
|
|
1671
|
+
}
|
|
1672
|
+
function toHct(xyz, env) {
|
|
1673
|
+
const t = toLstar(xyz[1]);
|
|
1674
|
+
if (t === 0) return [
|
|
1675
|
+
0,
|
|
1676
|
+
0,
|
|
1677
|
+
0
|
|
1678
|
+
];
|
|
1679
|
+
const cam16$1 = toCam16(xyz, viewingConditions);
|
|
1680
|
+
return [
|
|
1681
|
+
constrain(cam16$1.h),
|
|
1682
|
+
cam16$1.C,
|
|
1683
|
+
t
|
|
1684
|
+
];
|
|
1685
|
+
}
|
|
1686
|
+
var viewingConditions = environment(white$2, 200 / Math.PI * fromLstar(50), fromLstar(50) * 100, "average", false);
|
|
1687
|
+
var hct = new ColorSpace({
|
|
1688
|
+
id: "hct",
|
|
1689
|
+
name: "HCT",
|
|
1690
|
+
coords: {
|
|
1691
|
+
h: {
|
|
1692
|
+
refRange: [0, 360],
|
|
1693
|
+
type: "angle",
|
|
1694
|
+
name: "Hue"
|
|
1695
|
+
},
|
|
1696
|
+
c: {
|
|
1697
|
+
refRange: [0, 145],
|
|
1698
|
+
name: "Colorfulness"
|
|
1699
|
+
},
|
|
1700
|
+
t: {
|
|
1701
|
+
refRange: [0, 100],
|
|
1702
|
+
name: "Tone"
|
|
1703
|
+
}
|
|
1704
|
+
},
|
|
1705
|
+
base: xyz_d65,
|
|
1706
|
+
fromBase(xyz) {
|
|
1707
|
+
return toHct(xyz);
|
|
1708
|
+
},
|
|
1709
|
+
toBase(hct$1) {
|
|
1710
|
+
return fromHct(hct$1, viewingConditions);
|
|
1711
|
+
},
|
|
1712
|
+
formats: { color: {
|
|
1713
|
+
id: "--hct",
|
|
1714
|
+
coords: [
|
|
1715
|
+
"<number> | <angle>",
|
|
1716
|
+
"<percentage> | <number>",
|
|
1717
|
+
"<percentage> | <number>"
|
|
1718
|
+
]
|
|
1719
|
+
} }
|
|
1720
|
+
});
|
|
1721
|
+
var deg2rad = Math.PI / 180;
|
|
1722
|
+
var ucsCoeff = [
|
|
1723
|
+
1,
|
|
1724
|
+
.007,
|
|
1725
|
+
.0228
|
|
1726
|
+
];
|
|
1727
|
+
function convertUcsAb(coords) {
|
|
1728
|
+
if (coords[1] < 0) coords = hct.fromBase(hct.toBase(coords));
|
|
1729
|
+
const M = Math.log(Math.max(1 + ucsCoeff[2] * coords[1] * viewingConditions.flRoot, 1)) / ucsCoeff[2];
|
|
1730
|
+
const hrad = coords[0] * deg2rad;
|
|
1731
|
+
const a$1 = M * Math.cos(hrad);
|
|
1732
|
+
const b$2 = M * Math.sin(hrad);
|
|
1733
|
+
return [
|
|
1734
|
+
coords[2],
|
|
1735
|
+
a$1,
|
|
1736
|
+
b$2
|
|
1737
|
+
];
|
|
1738
|
+
}
|
|
1739
|
+
function deltaEHCT(color, sample) {
|
|
1740
|
+
[color, sample] = getColor([color, sample]);
|
|
1741
|
+
let [t1, a1, b1] = convertUcsAb(hct.from(color));
|
|
1742
|
+
let [t2, a2, b2] = convertUcsAb(hct.from(sample));
|
|
1743
|
+
return Math.sqrt((t1 - t2) ** 2 + (a1 - a2) ** 2 + (b1 - b2) ** 2);
|
|
1744
|
+
}
|
|
1745
|
+
var deltaEMethods = {
|
|
1746
|
+
deltaE76,
|
|
1747
|
+
deltaECMC,
|
|
1748
|
+
deltaE2000,
|
|
1749
|
+
deltaEJz,
|
|
1750
|
+
deltaEITP,
|
|
1751
|
+
deltaEOK,
|
|
1752
|
+
deltaEHCT
|
|
1753
|
+
};
|
|
1754
|
+
function calcEpsilon(jnd) {
|
|
1755
|
+
const order = !jnd ? 0 : Math.floor(Math.log10(Math.abs(jnd)));
|
|
1756
|
+
return Math.max(parseFloat(`1e${order - 2}`), 1e-6);
|
|
1757
|
+
}
|
|
1758
|
+
var GMAPPRESET = {
|
|
1759
|
+
"hct": {
|
|
1760
|
+
method: "hct.c",
|
|
1761
|
+
jnd: 2,
|
|
1762
|
+
deltaEMethod: "hct",
|
|
1763
|
+
blackWhiteClamp: {}
|
|
1764
|
+
},
|
|
1765
|
+
"hct-tonal": {
|
|
1766
|
+
method: "hct.c",
|
|
1767
|
+
jnd: 0,
|
|
1768
|
+
deltaEMethod: "hct",
|
|
1769
|
+
blackWhiteClamp: {
|
|
1770
|
+
channel: "hct.t",
|
|
1771
|
+
min: 0,
|
|
1772
|
+
max: 100
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1776
|
+
function toGamut(color, { method = defaults.gamut_mapping, space = void 0, deltaEMethod = "", jnd = 2, blackWhiteClamp = {} } = {}) {
|
|
1777
|
+
color = getColor(color);
|
|
1778
|
+
if (isString(arguments[1])) space = arguments[1];
|
|
1779
|
+
else if (!space) space = color.space;
|
|
1780
|
+
space = ColorSpace.get(space);
|
|
1781
|
+
if (inGamut(color, space, { epsilon: 0 })) return color;
|
|
1782
|
+
let spaceColor;
|
|
1783
|
+
if (method === "css") spaceColor = toGamutCSS(color, { space });
|
|
1784
|
+
else {
|
|
1785
|
+
if (method !== "clip" && !inGamut(color, space)) {
|
|
1786
|
+
if (Object.prototype.hasOwnProperty.call(GMAPPRESET, method)) ({method, jnd, deltaEMethod, blackWhiteClamp} = GMAPPRESET[method]);
|
|
1787
|
+
let de = deltaE2000;
|
|
1788
|
+
if (deltaEMethod !== "") {
|
|
1789
|
+
for (let m$1 in deltaEMethods) if ("deltae" + deltaEMethod.toLowerCase() === m$1.toLowerCase()) {
|
|
1790
|
+
de = deltaEMethods[m$1];
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
let clipped = toGamut(to(color, space), {
|
|
1795
|
+
method: "clip",
|
|
1796
|
+
space
|
|
1797
|
+
});
|
|
1798
|
+
if (de(color, clipped) > jnd) {
|
|
1799
|
+
if (Object.keys(blackWhiteClamp).length === 3) {
|
|
1800
|
+
let channelMeta = ColorSpace.resolveCoord(blackWhiteClamp.channel);
|
|
1801
|
+
let channel = get(to(color, channelMeta.space), channelMeta.id);
|
|
1802
|
+
if (isNone(channel)) channel = 0;
|
|
1803
|
+
if (channel >= blackWhiteClamp.max) return to({
|
|
1804
|
+
space: "xyz-d65",
|
|
1805
|
+
coords: WHITES["D65"]
|
|
1806
|
+
}, color.space);
|
|
1807
|
+
else if (channel <= blackWhiteClamp.min) return to({
|
|
1808
|
+
space: "xyz-d65",
|
|
1809
|
+
coords: [
|
|
1810
|
+
0,
|
|
1811
|
+
0,
|
|
1812
|
+
0
|
|
1813
|
+
]
|
|
1814
|
+
}, color.space);
|
|
1815
|
+
}
|
|
1816
|
+
let coordMeta = ColorSpace.resolveCoord(method);
|
|
1817
|
+
let mapSpace = coordMeta.space;
|
|
1818
|
+
let coordId = coordMeta.id;
|
|
1819
|
+
let mappedColor = to(color, mapSpace);
|
|
1820
|
+
mappedColor.coords.forEach((c$1, i) => {
|
|
1821
|
+
if (isNone(c$1)) mappedColor.coords[i] = 0;
|
|
1822
|
+
});
|
|
1823
|
+
let min$1 = (coordMeta.range || coordMeta.refRange)[0];
|
|
1824
|
+
let ε$8 = calcEpsilon(jnd);
|
|
1825
|
+
let low = min$1;
|
|
1826
|
+
let high = get(mappedColor, coordId);
|
|
1827
|
+
while (high - low > ε$8) {
|
|
1828
|
+
let clipped$1 = clone(mappedColor);
|
|
1829
|
+
clipped$1 = toGamut(clipped$1, {
|
|
1830
|
+
space,
|
|
1831
|
+
method: "clip"
|
|
1832
|
+
});
|
|
1833
|
+
if (de(mappedColor, clipped$1) - jnd < ε$8) low = get(mappedColor, coordId);
|
|
1834
|
+
else high = get(mappedColor, coordId);
|
|
1835
|
+
set(mappedColor, coordId, (low + high) / 2);
|
|
1836
|
+
}
|
|
1837
|
+
spaceColor = to(mappedColor, space);
|
|
1838
|
+
} else spaceColor = clipped;
|
|
1839
|
+
} else spaceColor = to(color, space);
|
|
1840
|
+
if (method === "clip" || !inGamut(spaceColor, space, { epsilon: 0 })) {
|
|
1841
|
+
let bounds = Object.values(space.coords).map((c$1) => c$1.range || []);
|
|
1842
|
+
spaceColor.coords = spaceColor.coords.map((c$1, i) => {
|
|
1843
|
+
let [min$1, max$2] = bounds[i];
|
|
1844
|
+
if (min$1 !== void 0) c$1 = Math.max(min$1, c$1);
|
|
1845
|
+
if (max$2 !== void 0) c$1 = Math.min(c$1, max$2);
|
|
1846
|
+
return c$1;
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
if (space !== color.space) spaceColor = to(spaceColor, color.space);
|
|
1851
|
+
color.coords = spaceColor.coords;
|
|
1852
|
+
return color;
|
|
1853
|
+
}
|
|
1854
|
+
toGamut.returns = "color";
|
|
1855
|
+
var COLORS = {
|
|
1856
|
+
WHITE: {
|
|
1857
|
+
space: OKLab,
|
|
1858
|
+
coords: [
|
|
1859
|
+
1,
|
|
1860
|
+
0,
|
|
1861
|
+
0
|
|
1862
|
+
]
|
|
1863
|
+
},
|
|
1864
|
+
BLACK: {
|
|
1865
|
+
space: OKLab,
|
|
1866
|
+
coords: [
|
|
1867
|
+
0,
|
|
1868
|
+
0,
|
|
1869
|
+
0
|
|
1870
|
+
]
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
function toGamutCSS(origin, { space } = {}) {
|
|
1874
|
+
const JND = .02;
|
|
1875
|
+
const ε$8 = 1e-4;
|
|
1876
|
+
origin = getColor(origin);
|
|
1877
|
+
if (!space) space = origin.space;
|
|
1878
|
+
space = ColorSpace.get(space);
|
|
1879
|
+
const oklchSpace = ColorSpace.get("oklch");
|
|
1880
|
+
if (space.isUnbounded) return to(origin, space);
|
|
1881
|
+
const origin_OKLCH = to(origin, oklchSpace);
|
|
1882
|
+
let L = origin_OKLCH.coords[0];
|
|
1883
|
+
if (L >= 1) {
|
|
1884
|
+
const white$5 = to(COLORS.WHITE, space);
|
|
1885
|
+
white$5.alpha = origin.alpha;
|
|
1886
|
+
return to(white$5, space);
|
|
1887
|
+
}
|
|
1888
|
+
if (L <= 0) {
|
|
1889
|
+
const black = to(COLORS.BLACK, space);
|
|
1890
|
+
black.alpha = origin.alpha;
|
|
1891
|
+
return to(black, space);
|
|
1892
|
+
}
|
|
1893
|
+
if (inGamut(origin_OKLCH, space, { epsilon: 0 })) return to(origin_OKLCH, space);
|
|
1894
|
+
function clip(_color) {
|
|
1895
|
+
const destColor = to(_color, space);
|
|
1896
|
+
const spaceCoords = Object.values(space.coords);
|
|
1897
|
+
destColor.coords = destColor.coords.map((coord, index) => {
|
|
1898
|
+
if ("range" in spaceCoords[index]) {
|
|
1899
|
+
const [min$2, max$3] = spaceCoords[index].range;
|
|
1900
|
+
return clamp$1(min$2, coord, max$3);
|
|
1901
|
+
}
|
|
1902
|
+
return coord;
|
|
1903
|
+
});
|
|
1904
|
+
return destColor;
|
|
1905
|
+
}
|
|
1906
|
+
let min$1 = 0;
|
|
1907
|
+
let max$2 = origin_OKLCH.coords[1];
|
|
1908
|
+
let min_inGamut = true;
|
|
1909
|
+
let current = clone(origin_OKLCH);
|
|
1910
|
+
let clipped = clip(current);
|
|
1911
|
+
let E = deltaEOK(clipped, current);
|
|
1912
|
+
if (E < JND) return clipped;
|
|
1913
|
+
while (max$2 - min$1 > ε$8) {
|
|
1914
|
+
const chroma = (min$1 + max$2) / 2;
|
|
1915
|
+
current.coords[1] = chroma;
|
|
1916
|
+
if (min_inGamut && inGamut(current, space, { epsilon: 0 })) min$1 = chroma;
|
|
1917
|
+
else {
|
|
1918
|
+
clipped = clip(current);
|
|
1919
|
+
E = deltaEOK(clipped, current);
|
|
1920
|
+
if (E < JND) if (JND - E < ε$8) break;
|
|
1921
|
+
else {
|
|
1922
|
+
min_inGamut = false;
|
|
1923
|
+
min$1 = chroma;
|
|
1924
|
+
}
|
|
1925
|
+
else max$2 = chroma;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return clipped;
|
|
1929
|
+
}
|
|
1930
|
+
function to(color, space, { inGamut: inGamut$1 } = {}) {
|
|
1931
|
+
color = getColor(color);
|
|
1932
|
+
space = ColorSpace.get(space);
|
|
1933
|
+
let coords = space.from(color);
|
|
1934
|
+
let ret = {
|
|
1935
|
+
space,
|
|
1936
|
+
coords,
|
|
1937
|
+
alpha: color.alpha
|
|
1938
|
+
};
|
|
1939
|
+
if (inGamut$1) ret = toGamut(ret, inGamut$1 === true ? void 0 : inGamut$1);
|
|
1940
|
+
return ret;
|
|
1941
|
+
}
|
|
1942
|
+
to.returns = "color";
|
|
1943
|
+
function serialize(color, { precision = defaults.precision, format = "default", inGamut: inGamut$1 = true,...customOptions } = {}) {
|
|
1944
|
+
let ret;
|
|
1945
|
+
color = getColor(color);
|
|
1946
|
+
let formatId = format;
|
|
1947
|
+
format = color.space.getFormat(format) ?? color.space.getFormat("default") ?? ColorSpace.DEFAULT_FORMAT;
|
|
1948
|
+
let coords = color.coords.slice();
|
|
1949
|
+
inGamut$1 ||= format.toGamut;
|
|
1950
|
+
if (inGamut$1 && !inGamut(color)) coords = toGamut(clone(color), inGamut$1 === true ? void 0 : inGamut$1).coords;
|
|
1951
|
+
if (format.type === "custom") {
|
|
1952
|
+
customOptions.precision = precision;
|
|
1953
|
+
if (format.serialize) ret = format.serialize(coords, color.alpha, customOptions);
|
|
1954
|
+
else throw new TypeError(`format ${formatId} can only be used to parse colors, not for serialization`);
|
|
1955
|
+
} else {
|
|
1956
|
+
let name = format.name || "color";
|
|
1957
|
+
if (format.serializeCoords) coords = format.serializeCoords(coords, precision);
|
|
1958
|
+
else if (precision !== null) coords = coords.map((c$1) => {
|
|
1959
|
+
return serializeNumber(c$1, { precision });
|
|
1960
|
+
});
|
|
1961
|
+
let args = [...coords];
|
|
1962
|
+
if (name === "color") {
|
|
1963
|
+
let cssId = format.id || format.ids?.[0] || color.space.id;
|
|
1964
|
+
args.unshift(cssId);
|
|
1965
|
+
}
|
|
1966
|
+
let alpha = color.alpha;
|
|
1967
|
+
if (precision !== null) alpha = serializeNumber(alpha, { precision });
|
|
1968
|
+
let strAlpha = color.alpha >= 1 || format.noAlpha ? "" : `${format.commas ? "," : " /"} ${alpha}`;
|
|
1969
|
+
ret = `${name}(${args.join(format.commas ? ", " : " ")}${strAlpha})`;
|
|
1970
|
+
}
|
|
1971
|
+
return ret;
|
|
1972
|
+
}
|
|
1973
|
+
var REC2020Linear = new RGBColorSpace({
|
|
1974
|
+
id: "rec2020-linear",
|
|
1975
|
+
cssId: "--rec2020-linear",
|
|
1976
|
+
name: "Linear REC.2020",
|
|
1977
|
+
white: "D65",
|
|
1978
|
+
toXYZ_M: [
|
|
1979
|
+
[
|
|
1980
|
+
.6369580483012914,
|
|
1981
|
+
.14461690358620832,
|
|
1982
|
+
.1688809751641721
|
|
1983
|
+
],
|
|
1984
|
+
[
|
|
1985
|
+
.2627002120112671,
|
|
1986
|
+
.6779980715188708,
|
|
1987
|
+
.05930171646986196
|
|
1988
|
+
],
|
|
1989
|
+
[
|
|
1990
|
+
0,
|
|
1991
|
+
.028072693049087428,
|
|
1992
|
+
1.060985057710791
|
|
1993
|
+
]
|
|
1994
|
+
],
|
|
1995
|
+
fromXYZ_M: [
|
|
1996
|
+
[
|
|
1997
|
+
1.716651187971268,
|
|
1998
|
+
-.355670783776392,
|
|
1999
|
+
-.25336628137366
|
|
2000
|
+
],
|
|
2001
|
+
[
|
|
2002
|
+
-.666684351832489,
|
|
2003
|
+
1.616481236634939,
|
|
2004
|
+
.0157685458139111
|
|
2005
|
+
],
|
|
2006
|
+
[
|
|
2007
|
+
.017639857445311,
|
|
2008
|
+
-.042770613257809,
|
|
2009
|
+
.942103121235474
|
|
2010
|
+
]
|
|
2011
|
+
]
|
|
2012
|
+
});
|
|
2013
|
+
var α = 1.09929682680944;
|
|
2014
|
+
var β = .018053968510807;
|
|
2015
|
+
var REC2020 = new RGBColorSpace({
|
|
2016
|
+
id: "rec2020",
|
|
2017
|
+
name: "REC.2020",
|
|
2018
|
+
base: REC2020Linear,
|
|
2019
|
+
toBase(RGB) {
|
|
2020
|
+
return RGB.map(function(val) {
|
|
2021
|
+
if (val < β * 4.5) return val / 4.5;
|
|
2022
|
+
return Math.pow((val + α - 1) / α, 1 / .45);
|
|
2023
|
+
});
|
|
2024
|
+
},
|
|
2025
|
+
fromBase(RGB) {
|
|
2026
|
+
return RGB.map(function(val) {
|
|
2027
|
+
if (val >= β) return α * Math.pow(val, .45) - (α - 1);
|
|
2028
|
+
return 4.5 * val;
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
var P3Linear = new RGBColorSpace({
|
|
2033
|
+
id: "p3-linear",
|
|
2034
|
+
cssId: "--display-p3-linear",
|
|
2035
|
+
name: "Linear P3",
|
|
2036
|
+
white: "D65",
|
|
2037
|
+
toXYZ_M: [
|
|
2038
|
+
[
|
|
2039
|
+
.4865709486482162,
|
|
2040
|
+
.26566769316909306,
|
|
2041
|
+
.1982172852343625
|
|
2042
|
+
],
|
|
2043
|
+
[
|
|
2044
|
+
.2289745640697488,
|
|
2045
|
+
.6917385218365064,
|
|
2046
|
+
.079286914093745
|
|
2047
|
+
],
|
|
2048
|
+
[
|
|
2049
|
+
0,
|
|
2050
|
+
.04511338185890264,
|
|
2051
|
+
1.043944368900976
|
|
2052
|
+
]
|
|
2053
|
+
],
|
|
2054
|
+
fromXYZ_M: [
|
|
2055
|
+
[
|
|
2056
|
+
2.493496911941425,
|
|
2057
|
+
-.9313836179191239,
|
|
2058
|
+
-.40271078445071684
|
|
2059
|
+
],
|
|
2060
|
+
[
|
|
2061
|
+
-.8294889695615747,
|
|
2062
|
+
1.7626640603183463,
|
|
2063
|
+
.023624685841943577
|
|
2064
|
+
],
|
|
2065
|
+
[
|
|
2066
|
+
.03584583024378447,
|
|
2067
|
+
-.07617238926804182,
|
|
2068
|
+
.9568845240076872
|
|
2069
|
+
]
|
|
2070
|
+
]
|
|
2071
|
+
});
|
|
2072
|
+
var toXYZ_M$3 = [
|
|
2073
|
+
[
|
|
2074
|
+
.41239079926595934,
|
|
2075
|
+
.357584339383878,
|
|
2076
|
+
.1804807884018343
|
|
2077
|
+
],
|
|
2078
|
+
[
|
|
2079
|
+
.21263900587151027,
|
|
2080
|
+
.715168678767756,
|
|
2081
|
+
.07219231536073371
|
|
2082
|
+
],
|
|
2083
|
+
[
|
|
2084
|
+
.01933081871559182,
|
|
2085
|
+
.11919477979462598,
|
|
2086
|
+
.9505321522496607
|
|
2087
|
+
]
|
|
2088
|
+
];
|
|
2089
|
+
var fromXYZ_M$3 = [
|
|
2090
|
+
[
|
|
2091
|
+
3.2409699419045226,
|
|
2092
|
+
-1.537383177570094,
|
|
2093
|
+
-.4986107602930034
|
|
2094
|
+
],
|
|
2095
|
+
[
|
|
2096
|
+
-.9692436362808796,
|
|
2097
|
+
1.8759675015077202,
|
|
2098
|
+
.04155505740717559
|
|
2099
|
+
],
|
|
2100
|
+
[
|
|
2101
|
+
.05563007969699366,
|
|
2102
|
+
-.20397695888897652,
|
|
2103
|
+
1.0569715142428786
|
|
2104
|
+
]
|
|
2105
|
+
];
|
|
2106
|
+
var sRGBLinear = new RGBColorSpace({
|
|
2107
|
+
id: "srgb-linear",
|
|
2108
|
+
name: "Linear sRGB",
|
|
2109
|
+
white: "D65",
|
|
2110
|
+
toXYZ_M: toXYZ_M$3,
|
|
2111
|
+
fromXYZ_M: fromXYZ_M$3
|
|
2112
|
+
});
|
|
2113
|
+
var KEYWORDS = {
|
|
2114
|
+
"aliceblue": [
|
|
2115
|
+
240 / 255,
|
|
2116
|
+
248 / 255,
|
|
2117
|
+
1
|
|
2118
|
+
],
|
|
2119
|
+
"antiquewhite": [
|
|
2120
|
+
250 / 255,
|
|
2121
|
+
235 / 255,
|
|
2122
|
+
215 / 255
|
|
2123
|
+
],
|
|
2124
|
+
"aqua": [
|
|
2125
|
+
0,
|
|
2126
|
+
1,
|
|
2127
|
+
1
|
|
2128
|
+
],
|
|
2129
|
+
"aquamarine": [
|
|
2130
|
+
127 / 255,
|
|
2131
|
+
1,
|
|
2132
|
+
212 / 255
|
|
2133
|
+
],
|
|
2134
|
+
"azure": [
|
|
2135
|
+
240 / 255,
|
|
2136
|
+
1,
|
|
2137
|
+
1
|
|
2138
|
+
],
|
|
2139
|
+
"beige": [
|
|
2140
|
+
245 / 255,
|
|
2141
|
+
245 / 255,
|
|
2142
|
+
220 / 255
|
|
2143
|
+
],
|
|
2144
|
+
"bisque": [
|
|
2145
|
+
1,
|
|
2146
|
+
228 / 255,
|
|
2147
|
+
196 / 255
|
|
2148
|
+
],
|
|
2149
|
+
"black": [
|
|
2150
|
+
0,
|
|
2151
|
+
0,
|
|
2152
|
+
0
|
|
2153
|
+
],
|
|
2154
|
+
"blanchedalmond": [
|
|
2155
|
+
1,
|
|
2156
|
+
235 / 255,
|
|
2157
|
+
205 / 255
|
|
2158
|
+
],
|
|
2159
|
+
"blue": [
|
|
2160
|
+
0,
|
|
2161
|
+
0,
|
|
2162
|
+
1
|
|
2163
|
+
],
|
|
2164
|
+
"blueviolet": [
|
|
2165
|
+
138 / 255,
|
|
2166
|
+
43 / 255,
|
|
2167
|
+
226 / 255
|
|
2168
|
+
],
|
|
2169
|
+
"brown": [
|
|
2170
|
+
165 / 255,
|
|
2171
|
+
42 / 255,
|
|
2172
|
+
42 / 255
|
|
2173
|
+
],
|
|
2174
|
+
"burlywood": [
|
|
2175
|
+
222 / 255,
|
|
2176
|
+
184 / 255,
|
|
2177
|
+
135 / 255
|
|
2178
|
+
],
|
|
2179
|
+
"cadetblue": [
|
|
2180
|
+
95 / 255,
|
|
2181
|
+
158 / 255,
|
|
2182
|
+
160 / 255
|
|
2183
|
+
],
|
|
2184
|
+
"chartreuse": [
|
|
2185
|
+
127 / 255,
|
|
2186
|
+
1,
|
|
2187
|
+
0
|
|
2188
|
+
],
|
|
2189
|
+
"chocolate": [
|
|
2190
|
+
210 / 255,
|
|
2191
|
+
105 / 255,
|
|
2192
|
+
30 / 255
|
|
2193
|
+
],
|
|
2194
|
+
"coral": [
|
|
2195
|
+
1,
|
|
2196
|
+
127 / 255,
|
|
2197
|
+
80 / 255
|
|
2198
|
+
],
|
|
2199
|
+
"cornflowerblue": [
|
|
2200
|
+
100 / 255,
|
|
2201
|
+
149 / 255,
|
|
2202
|
+
237 / 255
|
|
2203
|
+
],
|
|
2204
|
+
"cornsilk": [
|
|
2205
|
+
1,
|
|
2206
|
+
248 / 255,
|
|
2207
|
+
220 / 255
|
|
2208
|
+
],
|
|
2209
|
+
"crimson": [
|
|
2210
|
+
220 / 255,
|
|
2211
|
+
20 / 255,
|
|
2212
|
+
60 / 255
|
|
2213
|
+
],
|
|
2214
|
+
"cyan": [
|
|
2215
|
+
0,
|
|
2216
|
+
1,
|
|
2217
|
+
1
|
|
2218
|
+
],
|
|
2219
|
+
"darkblue": [
|
|
2220
|
+
0,
|
|
2221
|
+
0,
|
|
2222
|
+
139 / 255
|
|
2223
|
+
],
|
|
2224
|
+
"darkcyan": [
|
|
2225
|
+
0,
|
|
2226
|
+
139 / 255,
|
|
2227
|
+
139 / 255
|
|
2228
|
+
],
|
|
2229
|
+
"darkgoldenrod": [
|
|
2230
|
+
184 / 255,
|
|
2231
|
+
134 / 255,
|
|
2232
|
+
11 / 255
|
|
2233
|
+
],
|
|
2234
|
+
"darkgray": [
|
|
2235
|
+
169 / 255,
|
|
2236
|
+
169 / 255,
|
|
2237
|
+
169 / 255
|
|
2238
|
+
],
|
|
2239
|
+
"darkgreen": [
|
|
2240
|
+
0,
|
|
2241
|
+
100 / 255,
|
|
2242
|
+
0
|
|
2243
|
+
],
|
|
2244
|
+
"darkgrey": [
|
|
2245
|
+
169 / 255,
|
|
2246
|
+
169 / 255,
|
|
2247
|
+
169 / 255
|
|
2248
|
+
],
|
|
2249
|
+
"darkkhaki": [
|
|
2250
|
+
189 / 255,
|
|
2251
|
+
183 / 255,
|
|
2252
|
+
107 / 255
|
|
2253
|
+
],
|
|
2254
|
+
"darkmagenta": [
|
|
2255
|
+
139 / 255,
|
|
2256
|
+
0,
|
|
2257
|
+
139 / 255
|
|
2258
|
+
],
|
|
2259
|
+
"darkolivegreen": [
|
|
2260
|
+
85 / 255,
|
|
2261
|
+
107 / 255,
|
|
2262
|
+
47 / 255
|
|
2263
|
+
],
|
|
2264
|
+
"darkorange": [
|
|
2265
|
+
1,
|
|
2266
|
+
140 / 255,
|
|
2267
|
+
0
|
|
2268
|
+
],
|
|
2269
|
+
"darkorchid": [
|
|
2270
|
+
153 / 255,
|
|
2271
|
+
50 / 255,
|
|
2272
|
+
204 / 255
|
|
2273
|
+
],
|
|
2274
|
+
"darkred": [
|
|
2275
|
+
139 / 255,
|
|
2276
|
+
0,
|
|
2277
|
+
0
|
|
2278
|
+
],
|
|
2279
|
+
"darksalmon": [
|
|
2280
|
+
233 / 255,
|
|
2281
|
+
150 / 255,
|
|
2282
|
+
122 / 255
|
|
2283
|
+
],
|
|
2284
|
+
"darkseagreen": [
|
|
2285
|
+
143 / 255,
|
|
2286
|
+
188 / 255,
|
|
2287
|
+
143 / 255
|
|
2288
|
+
],
|
|
2289
|
+
"darkslateblue": [
|
|
2290
|
+
72 / 255,
|
|
2291
|
+
61 / 255,
|
|
2292
|
+
139 / 255
|
|
2293
|
+
],
|
|
2294
|
+
"darkslategray": [
|
|
2295
|
+
47 / 255,
|
|
2296
|
+
79 / 255,
|
|
2297
|
+
79 / 255
|
|
2298
|
+
],
|
|
2299
|
+
"darkslategrey": [
|
|
2300
|
+
47 / 255,
|
|
2301
|
+
79 / 255,
|
|
2302
|
+
79 / 255
|
|
2303
|
+
],
|
|
2304
|
+
"darkturquoise": [
|
|
2305
|
+
0,
|
|
2306
|
+
206 / 255,
|
|
2307
|
+
209 / 255
|
|
2308
|
+
],
|
|
2309
|
+
"darkviolet": [
|
|
2310
|
+
148 / 255,
|
|
2311
|
+
0,
|
|
2312
|
+
211 / 255
|
|
2313
|
+
],
|
|
2314
|
+
"deeppink": [
|
|
2315
|
+
1,
|
|
2316
|
+
20 / 255,
|
|
2317
|
+
147 / 255
|
|
2318
|
+
],
|
|
2319
|
+
"deepskyblue": [
|
|
2320
|
+
0,
|
|
2321
|
+
191 / 255,
|
|
2322
|
+
1
|
|
2323
|
+
],
|
|
2324
|
+
"dimgray": [
|
|
2325
|
+
105 / 255,
|
|
2326
|
+
105 / 255,
|
|
2327
|
+
105 / 255
|
|
2328
|
+
],
|
|
2329
|
+
"dimgrey": [
|
|
2330
|
+
105 / 255,
|
|
2331
|
+
105 / 255,
|
|
2332
|
+
105 / 255
|
|
2333
|
+
],
|
|
2334
|
+
"dodgerblue": [
|
|
2335
|
+
30 / 255,
|
|
2336
|
+
144 / 255,
|
|
2337
|
+
1
|
|
2338
|
+
],
|
|
2339
|
+
"firebrick": [
|
|
2340
|
+
178 / 255,
|
|
2341
|
+
34 / 255,
|
|
2342
|
+
34 / 255
|
|
2343
|
+
],
|
|
2344
|
+
"floralwhite": [
|
|
2345
|
+
1,
|
|
2346
|
+
250 / 255,
|
|
2347
|
+
240 / 255
|
|
2348
|
+
],
|
|
2349
|
+
"forestgreen": [
|
|
2350
|
+
34 / 255,
|
|
2351
|
+
139 / 255,
|
|
2352
|
+
34 / 255
|
|
2353
|
+
],
|
|
2354
|
+
"fuchsia": [
|
|
2355
|
+
1,
|
|
2356
|
+
0,
|
|
2357
|
+
1
|
|
2358
|
+
],
|
|
2359
|
+
"gainsboro": [
|
|
2360
|
+
220 / 255,
|
|
2361
|
+
220 / 255,
|
|
2362
|
+
220 / 255
|
|
2363
|
+
],
|
|
2364
|
+
"ghostwhite": [
|
|
2365
|
+
248 / 255,
|
|
2366
|
+
248 / 255,
|
|
2367
|
+
1
|
|
2368
|
+
],
|
|
2369
|
+
"gold": [
|
|
2370
|
+
1,
|
|
2371
|
+
215 / 255,
|
|
2372
|
+
0
|
|
2373
|
+
],
|
|
2374
|
+
"goldenrod": [
|
|
2375
|
+
218 / 255,
|
|
2376
|
+
165 / 255,
|
|
2377
|
+
32 / 255
|
|
2378
|
+
],
|
|
2379
|
+
"gray": [
|
|
2380
|
+
128 / 255,
|
|
2381
|
+
128 / 255,
|
|
2382
|
+
128 / 255
|
|
2383
|
+
],
|
|
2384
|
+
"green": [
|
|
2385
|
+
0,
|
|
2386
|
+
128 / 255,
|
|
2387
|
+
0
|
|
2388
|
+
],
|
|
2389
|
+
"greenyellow": [
|
|
2390
|
+
173 / 255,
|
|
2391
|
+
1,
|
|
2392
|
+
47 / 255
|
|
2393
|
+
],
|
|
2394
|
+
"grey": [
|
|
2395
|
+
128 / 255,
|
|
2396
|
+
128 / 255,
|
|
2397
|
+
128 / 255
|
|
2398
|
+
],
|
|
2399
|
+
"honeydew": [
|
|
2400
|
+
240 / 255,
|
|
2401
|
+
1,
|
|
2402
|
+
240 / 255
|
|
2403
|
+
],
|
|
2404
|
+
"hotpink": [
|
|
2405
|
+
1,
|
|
2406
|
+
105 / 255,
|
|
2407
|
+
180 / 255
|
|
2408
|
+
],
|
|
2409
|
+
"indianred": [
|
|
2410
|
+
205 / 255,
|
|
2411
|
+
92 / 255,
|
|
2412
|
+
92 / 255
|
|
2413
|
+
],
|
|
2414
|
+
"indigo": [
|
|
2415
|
+
75 / 255,
|
|
2416
|
+
0,
|
|
2417
|
+
130 / 255
|
|
2418
|
+
],
|
|
2419
|
+
"ivory": [
|
|
2420
|
+
1,
|
|
2421
|
+
1,
|
|
2422
|
+
240 / 255
|
|
2423
|
+
],
|
|
2424
|
+
"khaki": [
|
|
2425
|
+
240 / 255,
|
|
2426
|
+
230 / 255,
|
|
2427
|
+
140 / 255
|
|
2428
|
+
],
|
|
2429
|
+
"lavender": [
|
|
2430
|
+
230 / 255,
|
|
2431
|
+
230 / 255,
|
|
2432
|
+
250 / 255
|
|
2433
|
+
],
|
|
2434
|
+
"lavenderblush": [
|
|
2435
|
+
1,
|
|
2436
|
+
240 / 255,
|
|
2437
|
+
245 / 255
|
|
2438
|
+
],
|
|
2439
|
+
"lawngreen": [
|
|
2440
|
+
124 / 255,
|
|
2441
|
+
252 / 255,
|
|
2442
|
+
0
|
|
2443
|
+
],
|
|
2444
|
+
"lemonchiffon": [
|
|
2445
|
+
1,
|
|
2446
|
+
250 / 255,
|
|
2447
|
+
205 / 255
|
|
2448
|
+
],
|
|
2449
|
+
"lightblue": [
|
|
2450
|
+
173 / 255,
|
|
2451
|
+
216 / 255,
|
|
2452
|
+
230 / 255
|
|
2453
|
+
],
|
|
2454
|
+
"lightcoral": [
|
|
2455
|
+
240 / 255,
|
|
2456
|
+
128 / 255,
|
|
2457
|
+
128 / 255
|
|
2458
|
+
],
|
|
2459
|
+
"lightcyan": [
|
|
2460
|
+
224 / 255,
|
|
2461
|
+
1,
|
|
2462
|
+
1
|
|
2463
|
+
],
|
|
2464
|
+
"lightgoldenrodyellow": [
|
|
2465
|
+
250 / 255,
|
|
2466
|
+
250 / 255,
|
|
2467
|
+
210 / 255
|
|
2468
|
+
],
|
|
2469
|
+
"lightgray": [
|
|
2470
|
+
211 / 255,
|
|
2471
|
+
211 / 255,
|
|
2472
|
+
211 / 255
|
|
2473
|
+
],
|
|
2474
|
+
"lightgreen": [
|
|
2475
|
+
144 / 255,
|
|
2476
|
+
238 / 255,
|
|
2477
|
+
144 / 255
|
|
2478
|
+
],
|
|
2479
|
+
"lightgrey": [
|
|
2480
|
+
211 / 255,
|
|
2481
|
+
211 / 255,
|
|
2482
|
+
211 / 255
|
|
2483
|
+
],
|
|
2484
|
+
"lightpink": [
|
|
2485
|
+
1,
|
|
2486
|
+
182 / 255,
|
|
2487
|
+
193 / 255
|
|
2488
|
+
],
|
|
2489
|
+
"lightsalmon": [
|
|
2490
|
+
1,
|
|
2491
|
+
160 / 255,
|
|
2492
|
+
122 / 255
|
|
2493
|
+
],
|
|
2494
|
+
"lightseagreen": [
|
|
2495
|
+
32 / 255,
|
|
2496
|
+
178 / 255,
|
|
2497
|
+
170 / 255
|
|
2498
|
+
],
|
|
2499
|
+
"lightskyblue": [
|
|
2500
|
+
135 / 255,
|
|
2501
|
+
206 / 255,
|
|
2502
|
+
250 / 255
|
|
2503
|
+
],
|
|
2504
|
+
"lightslategray": [
|
|
2505
|
+
119 / 255,
|
|
2506
|
+
136 / 255,
|
|
2507
|
+
153 / 255
|
|
2508
|
+
],
|
|
2509
|
+
"lightslategrey": [
|
|
2510
|
+
119 / 255,
|
|
2511
|
+
136 / 255,
|
|
2512
|
+
153 / 255
|
|
2513
|
+
],
|
|
2514
|
+
"lightsteelblue": [
|
|
2515
|
+
176 / 255,
|
|
2516
|
+
196 / 255,
|
|
2517
|
+
222 / 255
|
|
2518
|
+
],
|
|
2519
|
+
"lightyellow": [
|
|
2520
|
+
1,
|
|
2521
|
+
1,
|
|
2522
|
+
224 / 255
|
|
2523
|
+
],
|
|
2524
|
+
"lime": [
|
|
2525
|
+
0,
|
|
2526
|
+
1,
|
|
2527
|
+
0
|
|
2528
|
+
],
|
|
2529
|
+
"limegreen": [
|
|
2530
|
+
50 / 255,
|
|
2531
|
+
205 / 255,
|
|
2532
|
+
50 / 255
|
|
2533
|
+
],
|
|
2534
|
+
"linen": [
|
|
2535
|
+
250 / 255,
|
|
2536
|
+
240 / 255,
|
|
2537
|
+
230 / 255
|
|
2538
|
+
],
|
|
2539
|
+
"magenta": [
|
|
2540
|
+
1,
|
|
2541
|
+
0,
|
|
2542
|
+
1
|
|
2543
|
+
],
|
|
2544
|
+
"maroon": [
|
|
2545
|
+
128 / 255,
|
|
2546
|
+
0,
|
|
2547
|
+
0
|
|
2548
|
+
],
|
|
2549
|
+
"mediumaquamarine": [
|
|
2550
|
+
102 / 255,
|
|
2551
|
+
205 / 255,
|
|
2552
|
+
170 / 255
|
|
2553
|
+
],
|
|
2554
|
+
"mediumblue": [
|
|
2555
|
+
0,
|
|
2556
|
+
0,
|
|
2557
|
+
205 / 255
|
|
2558
|
+
],
|
|
2559
|
+
"mediumorchid": [
|
|
2560
|
+
186 / 255,
|
|
2561
|
+
85 / 255,
|
|
2562
|
+
211 / 255
|
|
2563
|
+
],
|
|
2564
|
+
"mediumpurple": [
|
|
2565
|
+
147 / 255,
|
|
2566
|
+
112 / 255,
|
|
2567
|
+
219 / 255
|
|
2568
|
+
],
|
|
2569
|
+
"mediumseagreen": [
|
|
2570
|
+
60 / 255,
|
|
2571
|
+
179 / 255,
|
|
2572
|
+
113 / 255
|
|
2573
|
+
],
|
|
2574
|
+
"mediumslateblue": [
|
|
2575
|
+
123 / 255,
|
|
2576
|
+
104 / 255,
|
|
2577
|
+
238 / 255
|
|
2578
|
+
],
|
|
2579
|
+
"mediumspringgreen": [
|
|
2580
|
+
0,
|
|
2581
|
+
250 / 255,
|
|
2582
|
+
154 / 255
|
|
2583
|
+
],
|
|
2584
|
+
"mediumturquoise": [
|
|
2585
|
+
72 / 255,
|
|
2586
|
+
209 / 255,
|
|
2587
|
+
204 / 255
|
|
2588
|
+
],
|
|
2589
|
+
"mediumvioletred": [
|
|
2590
|
+
199 / 255,
|
|
2591
|
+
21 / 255,
|
|
2592
|
+
133 / 255
|
|
2593
|
+
],
|
|
2594
|
+
"midnightblue": [
|
|
2595
|
+
25 / 255,
|
|
2596
|
+
25 / 255,
|
|
2597
|
+
112 / 255
|
|
2598
|
+
],
|
|
2599
|
+
"mintcream": [
|
|
2600
|
+
245 / 255,
|
|
2601
|
+
1,
|
|
2602
|
+
250 / 255
|
|
2603
|
+
],
|
|
2604
|
+
"mistyrose": [
|
|
2605
|
+
1,
|
|
2606
|
+
228 / 255,
|
|
2607
|
+
225 / 255
|
|
2608
|
+
],
|
|
2609
|
+
"moccasin": [
|
|
2610
|
+
1,
|
|
2611
|
+
228 / 255,
|
|
2612
|
+
181 / 255
|
|
2613
|
+
],
|
|
2614
|
+
"navajowhite": [
|
|
2615
|
+
1,
|
|
2616
|
+
222 / 255,
|
|
2617
|
+
173 / 255
|
|
2618
|
+
],
|
|
2619
|
+
"navy": [
|
|
2620
|
+
0,
|
|
2621
|
+
0,
|
|
2622
|
+
128 / 255
|
|
2623
|
+
],
|
|
2624
|
+
"oldlace": [
|
|
2625
|
+
253 / 255,
|
|
2626
|
+
245 / 255,
|
|
2627
|
+
230 / 255
|
|
2628
|
+
],
|
|
2629
|
+
"olive": [
|
|
2630
|
+
128 / 255,
|
|
2631
|
+
128 / 255,
|
|
2632
|
+
0
|
|
2633
|
+
],
|
|
2634
|
+
"olivedrab": [
|
|
2635
|
+
107 / 255,
|
|
2636
|
+
142 / 255,
|
|
2637
|
+
35 / 255
|
|
2638
|
+
],
|
|
2639
|
+
"orange": [
|
|
2640
|
+
1,
|
|
2641
|
+
165 / 255,
|
|
2642
|
+
0
|
|
2643
|
+
],
|
|
2644
|
+
"orangered": [
|
|
2645
|
+
1,
|
|
2646
|
+
69 / 255,
|
|
2647
|
+
0
|
|
2648
|
+
],
|
|
2649
|
+
"orchid": [
|
|
2650
|
+
218 / 255,
|
|
2651
|
+
112 / 255,
|
|
2652
|
+
214 / 255
|
|
2653
|
+
],
|
|
2654
|
+
"palegoldenrod": [
|
|
2655
|
+
238 / 255,
|
|
2656
|
+
232 / 255,
|
|
2657
|
+
170 / 255
|
|
2658
|
+
],
|
|
2659
|
+
"palegreen": [
|
|
2660
|
+
152 / 255,
|
|
2661
|
+
251 / 255,
|
|
2662
|
+
152 / 255
|
|
2663
|
+
],
|
|
2664
|
+
"paleturquoise": [
|
|
2665
|
+
175 / 255,
|
|
2666
|
+
238 / 255,
|
|
2667
|
+
238 / 255
|
|
2668
|
+
],
|
|
2669
|
+
"palevioletred": [
|
|
2670
|
+
219 / 255,
|
|
2671
|
+
112 / 255,
|
|
2672
|
+
147 / 255
|
|
2673
|
+
],
|
|
2674
|
+
"papayawhip": [
|
|
2675
|
+
1,
|
|
2676
|
+
239 / 255,
|
|
2677
|
+
213 / 255
|
|
2678
|
+
],
|
|
2679
|
+
"peachpuff": [
|
|
2680
|
+
1,
|
|
2681
|
+
218 / 255,
|
|
2682
|
+
185 / 255
|
|
2683
|
+
],
|
|
2684
|
+
"peru": [
|
|
2685
|
+
205 / 255,
|
|
2686
|
+
133 / 255,
|
|
2687
|
+
63 / 255
|
|
2688
|
+
],
|
|
2689
|
+
"pink": [
|
|
2690
|
+
1,
|
|
2691
|
+
192 / 255,
|
|
2692
|
+
203 / 255
|
|
2693
|
+
],
|
|
2694
|
+
"plum": [
|
|
2695
|
+
221 / 255,
|
|
2696
|
+
160 / 255,
|
|
2697
|
+
221 / 255
|
|
2698
|
+
],
|
|
2699
|
+
"powderblue": [
|
|
2700
|
+
176 / 255,
|
|
2701
|
+
224 / 255,
|
|
2702
|
+
230 / 255
|
|
2703
|
+
],
|
|
2704
|
+
"purple": [
|
|
2705
|
+
128 / 255,
|
|
2706
|
+
0,
|
|
2707
|
+
128 / 255
|
|
2708
|
+
],
|
|
2709
|
+
"rebeccapurple": [
|
|
2710
|
+
102 / 255,
|
|
2711
|
+
51 / 255,
|
|
2712
|
+
153 / 255
|
|
2713
|
+
],
|
|
2714
|
+
"red": [
|
|
2715
|
+
1,
|
|
2716
|
+
0,
|
|
2717
|
+
0
|
|
2718
|
+
],
|
|
2719
|
+
"rosybrown": [
|
|
2720
|
+
188 / 255,
|
|
2721
|
+
143 / 255,
|
|
2722
|
+
143 / 255
|
|
2723
|
+
],
|
|
2724
|
+
"royalblue": [
|
|
2725
|
+
65 / 255,
|
|
2726
|
+
105 / 255,
|
|
2727
|
+
225 / 255
|
|
2728
|
+
],
|
|
2729
|
+
"saddlebrown": [
|
|
2730
|
+
139 / 255,
|
|
2731
|
+
69 / 255,
|
|
2732
|
+
19 / 255
|
|
2733
|
+
],
|
|
2734
|
+
"salmon": [
|
|
2735
|
+
250 / 255,
|
|
2736
|
+
128 / 255,
|
|
2737
|
+
114 / 255
|
|
2738
|
+
],
|
|
2739
|
+
"sandybrown": [
|
|
2740
|
+
244 / 255,
|
|
2741
|
+
164 / 255,
|
|
2742
|
+
96 / 255
|
|
2743
|
+
],
|
|
2744
|
+
"seagreen": [
|
|
2745
|
+
46 / 255,
|
|
2746
|
+
139 / 255,
|
|
2747
|
+
87 / 255
|
|
2748
|
+
],
|
|
2749
|
+
"seashell": [
|
|
2750
|
+
1,
|
|
2751
|
+
245 / 255,
|
|
2752
|
+
238 / 255
|
|
2753
|
+
],
|
|
2754
|
+
"sienna": [
|
|
2755
|
+
160 / 255,
|
|
2756
|
+
82 / 255,
|
|
2757
|
+
45 / 255
|
|
2758
|
+
],
|
|
2759
|
+
"silver": [
|
|
2760
|
+
192 / 255,
|
|
2761
|
+
192 / 255,
|
|
2762
|
+
192 / 255
|
|
2763
|
+
],
|
|
2764
|
+
"skyblue": [
|
|
2765
|
+
135 / 255,
|
|
2766
|
+
206 / 255,
|
|
2767
|
+
235 / 255
|
|
2768
|
+
],
|
|
2769
|
+
"slateblue": [
|
|
2770
|
+
106 / 255,
|
|
2771
|
+
90 / 255,
|
|
2772
|
+
205 / 255
|
|
2773
|
+
],
|
|
2774
|
+
"slategray": [
|
|
2775
|
+
112 / 255,
|
|
2776
|
+
128 / 255,
|
|
2777
|
+
144 / 255
|
|
2778
|
+
],
|
|
2779
|
+
"slategrey": [
|
|
2780
|
+
112 / 255,
|
|
2781
|
+
128 / 255,
|
|
2782
|
+
144 / 255
|
|
2783
|
+
],
|
|
2784
|
+
"snow": [
|
|
2785
|
+
1,
|
|
2786
|
+
250 / 255,
|
|
2787
|
+
250 / 255
|
|
2788
|
+
],
|
|
2789
|
+
"springgreen": [
|
|
2790
|
+
0,
|
|
2791
|
+
1,
|
|
2792
|
+
127 / 255
|
|
2793
|
+
],
|
|
2794
|
+
"steelblue": [
|
|
2795
|
+
70 / 255,
|
|
2796
|
+
130 / 255,
|
|
2797
|
+
180 / 255
|
|
2798
|
+
],
|
|
2799
|
+
"tan": [
|
|
2800
|
+
210 / 255,
|
|
2801
|
+
180 / 255,
|
|
2802
|
+
140 / 255
|
|
2803
|
+
],
|
|
2804
|
+
"teal": [
|
|
2805
|
+
0,
|
|
2806
|
+
128 / 255,
|
|
2807
|
+
128 / 255
|
|
2808
|
+
],
|
|
2809
|
+
"thistle": [
|
|
2810
|
+
216 / 255,
|
|
2811
|
+
191 / 255,
|
|
2812
|
+
216 / 255
|
|
2813
|
+
],
|
|
2814
|
+
"tomato": [
|
|
2815
|
+
1,
|
|
2816
|
+
99 / 255,
|
|
2817
|
+
71 / 255
|
|
2818
|
+
],
|
|
2819
|
+
"turquoise": [
|
|
2820
|
+
64 / 255,
|
|
2821
|
+
224 / 255,
|
|
2822
|
+
208 / 255
|
|
2823
|
+
],
|
|
2824
|
+
"violet": [
|
|
2825
|
+
238 / 255,
|
|
2826
|
+
130 / 255,
|
|
2827
|
+
238 / 255
|
|
2828
|
+
],
|
|
2829
|
+
"wheat": [
|
|
2830
|
+
245 / 255,
|
|
2831
|
+
222 / 255,
|
|
2832
|
+
179 / 255
|
|
2833
|
+
],
|
|
2834
|
+
"white": [
|
|
2835
|
+
1,
|
|
2836
|
+
1,
|
|
2837
|
+
1
|
|
2838
|
+
],
|
|
2839
|
+
"whitesmoke": [
|
|
2840
|
+
245 / 255,
|
|
2841
|
+
245 / 255,
|
|
2842
|
+
245 / 255
|
|
2843
|
+
],
|
|
2844
|
+
"yellow": [
|
|
2845
|
+
1,
|
|
2846
|
+
1,
|
|
2847
|
+
0
|
|
2848
|
+
],
|
|
2849
|
+
"yellowgreen": [
|
|
2850
|
+
154 / 255,
|
|
2851
|
+
205 / 255,
|
|
2852
|
+
50 / 255
|
|
2853
|
+
]
|
|
2854
|
+
};
|
|
2855
|
+
var coordGrammar = Array(3).fill("<percentage> | <number>[0, 255]");
|
|
2856
|
+
var coordGrammarNumber = Array(3).fill("<number>[0, 255]");
|
|
2857
|
+
var sRGB = new RGBColorSpace({
|
|
2858
|
+
id: "srgb",
|
|
2859
|
+
name: "sRGB",
|
|
2860
|
+
base: sRGBLinear,
|
|
2861
|
+
fromBase: (rgb) => {
|
|
2862
|
+
return rgb.map((val) => {
|
|
2863
|
+
let sign = val < 0 ? -1 : 1;
|
|
2864
|
+
let abs$1 = val * sign;
|
|
2865
|
+
if (abs$1 > .0031308) return sign * (1.055 * abs$1 ** (1 / 2.4) - .055);
|
|
2866
|
+
return 12.92 * val;
|
|
2867
|
+
});
|
|
2868
|
+
},
|
|
2869
|
+
toBase: (rgb) => {
|
|
2870
|
+
return rgb.map((val) => {
|
|
2871
|
+
let sign = val < 0 ? -1 : 1;
|
|
2872
|
+
let abs$1 = val * sign;
|
|
2873
|
+
if (abs$1 <= .04045) return val / 12.92;
|
|
2874
|
+
return sign * ((abs$1 + .055) / 1.055) ** 2.4;
|
|
2875
|
+
});
|
|
2876
|
+
},
|
|
2877
|
+
formats: {
|
|
2878
|
+
"rgb": { coords: coordGrammar },
|
|
2879
|
+
"rgb_number": {
|
|
2880
|
+
name: "rgb",
|
|
2881
|
+
commas: true,
|
|
2882
|
+
coords: coordGrammarNumber,
|
|
2883
|
+
noAlpha: true
|
|
2884
|
+
},
|
|
2885
|
+
"color": {},
|
|
2886
|
+
"rgba": {
|
|
2887
|
+
coords: coordGrammar,
|
|
2888
|
+
commas: true,
|
|
2889
|
+
lastAlpha: true
|
|
2890
|
+
},
|
|
2891
|
+
"rgba_number": {
|
|
2892
|
+
name: "rgba",
|
|
2893
|
+
commas: true,
|
|
2894
|
+
coords: coordGrammarNumber
|
|
2895
|
+
},
|
|
2896
|
+
"hex": {
|
|
2897
|
+
type: "custom",
|
|
2898
|
+
toGamut: true,
|
|
2899
|
+
test: (str) => /^#([a-f0-9]{3,4}){1,2}$/i.test(str),
|
|
2900
|
+
parse(str) {
|
|
2901
|
+
if (str.length <= 5) str = str.replace(/[a-f0-9]/gi, "$&$&");
|
|
2902
|
+
let rgba = [];
|
|
2903
|
+
str.replace(/[a-f0-9]{2}/gi, (component) => {
|
|
2904
|
+
rgba.push(parseInt(component, 16) / 255);
|
|
2905
|
+
});
|
|
2906
|
+
return {
|
|
2907
|
+
spaceId: "srgb",
|
|
2908
|
+
coords: rgba.slice(0, 3),
|
|
2909
|
+
alpha: rgba.slice(3)[0]
|
|
2910
|
+
};
|
|
2911
|
+
},
|
|
2912
|
+
serialize: (coords, alpha, { collapse = true } = {}) => {
|
|
2913
|
+
if (alpha < 1) coords.push(alpha);
|
|
2914
|
+
coords = coords.map((c$1) => Math.round(c$1 * 255));
|
|
2915
|
+
let collapsible = collapse && coords.every((c$1) => c$1 % 17 === 0);
|
|
2916
|
+
return "#" + coords.map((c$1) => {
|
|
2917
|
+
if (collapsible) return (c$1 / 17).toString(16);
|
|
2918
|
+
return c$1.toString(16).padStart(2, "0");
|
|
2919
|
+
}).join("");
|
|
2920
|
+
}
|
|
2921
|
+
},
|
|
2922
|
+
"keyword": {
|
|
2923
|
+
type: "custom",
|
|
2924
|
+
test: (str) => /^[a-z]+$/i.test(str),
|
|
2925
|
+
parse(str) {
|
|
2926
|
+
str = str.toLowerCase();
|
|
2927
|
+
let ret = {
|
|
2928
|
+
spaceId: "srgb",
|
|
2929
|
+
coords: null,
|
|
2930
|
+
alpha: 1
|
|
2931
|
+
};
|
|
2932
|
+
if (str === "transparent") {
|
|
2933
|
+
ret.coords = KEYWORDS.black;
|
|
2934
|
+
ret.alpha = 0;
|
|
2935
|
+
} else ret.coords = KEYWORDS[str];
|
|
2936
|
+
if (ret.coords) return ret;
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
});
|
|
2941
|
+
var P3 = new RGBColorSpace({
|
|
2942
|
+
id: "p3",
|
|
2943
|
+
cssId: "display-p3",
|
|
2944
|
+
name: "P3",
|
|
2945
|
+
base: P3Linear,
|
|
2946
|
+
fromBase: sRGB.fromBase,
|
|
2947
|
+
toBase: sRGB.toBase
|
|
2948
|
+
});
|
|
2949
|
+
defaults.display_space = sRGB;
|
|
2950
|
+
var supportsNone;
|
|
2951
|
+
if (typeof CSS !== "undefined" && CSS.supports) for (let space of [
|
|
2952
|
+
lab,
|
|
2953
|
+
REC2020,
|
|
2954
|
+
P3
|
|
2955
|
+
]) {
|
|
2956
|
+
let str = serialize({
|
|
2957
|
+
space,
|
|
2958
|
+
coords: space.getMinCoords(),
|
|
2959
|
+
alpha: 1
|
|
2960
|
+
});
|
|
2961
|
+
if (CSS.supports("color", str)) {
|
|
2962
|
+
defaults.display_space = space;
|
|
2963
|
+
break;
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
function display(color, { space = defaults.display_space,...options } = {}) {
|
|
2967
|
+
let ret = serialize(color, options);
|
|
2968
|
+
if (typeof CSS === "undefined" || CSS.supports("color", ret) || !defaults.display_space) {
|
|
2969
|
+
ret = new String(ret);
|
|
2970
|
+
ret.color = color;
|
|
2971
|
+
} else {
|
|
2972
|
+
let fallbackColor = color;
|
|
2973
|
+
if (color.coords.some(isNone) || isNone(color.alpha)) {
|
|
2974
|
+
if (!(supportsNone ??= CSS.supports("color", "hsl(none 50% 50%)"))) {
|
|
2975
|
+
fallbackColor = clone(color);
|
|
2976
|
+
fallbackColor.coords = fallbackColor.coords.map(skipNone);
|
|
2977
|
+
fallbackColor.alpha = skipNone(fallbackColor.alpha);
|
|
2978
|
+
ret = serialize(fallbackColor, options);
|
|
2979
|
+
if (CSS.supports("color", ret)) {
|
|
2980
|
+
ret = new String(ret);
|
|
2981
|
+
ret.color = fallbackColor;
|
|
2982
|
+
return ret;
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
fallbackColor = to(fallbackColor, space);
|
|
2987
|
+
ret = new String(serialize(fallbackColor, options));
|
|
2988
|
+
ret.color = fallbackColor;
|
|
2989
|
+
}
|
|
2990
|
+
return ret;
|
|
2991
|
+
}
|
|
2992
|
+
function equals(color1, color2) {
|
|
2993
|
+
color1 = getColor(color1);
|
|
2994
|
+
color2 = getColor(color2);
|
|
2995
|
+
return color1.space === color2.space && color1.alpha === color2.alpha && color1.coords.every((c$1, i) => c$1 === color2.coords[i]);
|
|
2996
|
+
}
|
|
2997
|
+
function getLuminance(color) {
|
|
2998
|
+
return get(color, [xyz_d65, "y"]);
|
|
2999
|
+
}
|
|
3000
|
+
function setLuminance(color, value) {
|
|
3001
|
+
set(color, [xyz_d65, "y"], value);
|
|
3002
|
+
}
|
|
3003
|
+
function register$2(Color$1) {
|
|
3004
|
+
Object.defineProperty(Color$1.prototype, "luminance", {
|
|
3005
|
+
get() {
|
|
3006
|
+
return getLuminance(this);
|
|
3007
|
+
},
|
|
3008
|
+
set(value) {
|
|
3009
|
+
setLuminance(this, value);
|
|
3010
|
+
}
|
|
3011
|
+
});
|
|
3012
|
+
}
|
|
3013
|
+
var luminance = /* @__PURE__ */ Object.freeze({
|
|
3014
|
+
__proto__: null,
|
|
3015
|
+
getLuminance,
|
|
3016
|
+
register: register$2,
|
|
3017
|
+
setLuminance
|
|
3018
|
+
});
|
|
3019
|
+
function contrastWCAG21(color1, color2) {
|
|
3020
|
+
color1 = getColor(color1);
|
|
3021
|
+
color2 = getColor(color2);
|
|
3022
|
+
let Y1 = Math.max(getLuminance(color1), 0);
|
|
3023
|
+
let Y2 = Math.max(getLuminance(color2), 0);
|
|
3024
|
+
if (Y2 > Y1) [Y1, Y2] = [Y2, Y1];
|
|
3025
|
+
return (Y1 + .05) / (Y2 + .05);
|
|
3026
|
+
}
|
|
3027
|
+
var normBG = .56;
|
|
3028
|
+
var normTXT = .57;
|
|
3029
|
+
var revTXT = .62;
|
|
3030
|
+
var revBG = .65;
|
|
3031
|
+
var blkThrs = .022;
|
|
3032
|
+
var blkClmp = 1.414;
|
|
3033
|
+
var loClip = .1;
|
|
3034
|
+
var deltaYmin = 5e-4;
|
|
3035
|
+
var scaleBoW = 1.14;
|
|
3036
|
+
var loBoWoffset = .027;
|
|
3037
|
+
var scaleWoB = 1.14;
|
|
3038
|
+
function fclamp(Y) {
|
|
3039
|
+
if (Y >= blkThrs) return Y;
|
|
3040
|
+
return Y + (blkThrs - Y) ** blkClmp;
|
|
3041
|
+
}
|
|
3042
|
+
function linearize(val) {
|
|
3043
|
+
let sign = val < 0 ? -1 : 1;
|
|
3044
|
+
let abs$1 = Math.abs(val);
|
|
3045
|
+
return sign * Math.pow(abs$1, 2.4);
|
|
3046
|
+
}
|
|
3047
|
+
function contrastAPCA(background, foreground) {
|
|
3048
|
+
foreground = getColor(foreground);
|
|
3049
|
+
background = getColor(background);
|
|
3050
|
+
let S;
|
|
3051
|
+
let C;
|
|
3052
|
+
let Sapc;
|
|
3053
|
+
let R, G, B;
|
|
3054
|
+
foreground = to(foreground, "srgb");
|
|
3055
|
+
[R, G, B] = foreground.coords;
|
|
3056
|
+
let lumTxt = linearize(R) * .2126729 + linearize(G) * .7151522 + linearize(B) * .072175;
|
|
3057
|
+
background = to(background, "srgb");
|
|
3058
|
+
[R, G, B] = background.coords;
|
|
3059
|
+
let lumBg = linearize(R) * .2126729 + linearize(G) * .7151522 + linearize(B) * .072175;
|
|
3060
|
+
let Ytxt = fclamp(lumTxt);
|
|
3061
|
+
let Ybg = fclamp(lumBg);
|
|
3062
|
+
let BoW = Ybg > Ytxt;
|
|
3063
|
+
if (Math.abs(Ybg - Ytxt) < deltaYmin) C = 0;
|
|
3064
|
+
else if (BoW) {
|
|
3065
|
+
S = Ybg ** normBG - Ytxt ** normTXT;
|
|
3066
|
+
C = S * scaleBoW;
|
|
3067
|
+
} else {
|
|
3068
|
+
S = Ybg ** revBG - Ytxt ** revTXT;
|
|
3069
|
+
C = S * scaleWoB;
|
|
3070
|
+
}
|
|
3071
|
+
if (Math.abs(C) < loClip) Sapc = 0;
|
|
3072
|
+
else if (C > 0) Sapc = C - loBoWoffset;
|
|
3073
|
+
else Sapc = C + loBoWoffset;
|
|
3074
|
+
return Sapc * 100;
|
|
3075
|
+
}
|
|
3076
|
+
function contrastMichelson(color1, color2) {
|
|
3077
|
+
color1 = getColor(color1);
|
|
3078
|
+
color2 = getColor(color2);
|
|
3079
|
+
let Y1 = Math.max(getLuminance(color1), 0);
|
|
3080
|
+
let Y2 = Math.max(getLuminance(color2), 0);
|
|
3081
|
+
if (Y2 > Y1) [Y1, Y2] = [Y2, Y1];
|
|
3082
|
+
let denom = Y1 + Y2;
|
|
3083
|
+
return denom === 0 ? 0 : (Y1 - Y2) / denom;
|
|
3084
|
+
}
|
|
3085
|
+
var max$1 = 5e4;
|
|
3086
|
+
function contrastWeber(color1, color2) {
|
|
3087
|
+
color1 = getColor(color1);
|
|
3088
|
+
color2 = getColor(color2);
|
|
3089
|
+
let Y1 = Math.max(getLuminance(color1), 0);
|
|
3090
|
+
let Y2 = Math.max(getLuminance(color2), 0);
|
|
3091
|
+
if (Y2 > Y1) [Y1, Y2] = [Y2, Y1];
|
|
3092
|
+
return Y2 === 0 ? max$1 : (Y1 - Y2) / Y2;
|
|
3093
|
+
}
|
|
3094
|
+
function contrastLstar(color1, color2) {
|
|
3095
|
+
color1 = getColor(color1);
|
|
3096
|
+
color2 = getColor(color2);
|
|
3097
|
+
let L1 = get(color1, [lab, "l"]);
|
|
3098
|
+
let L2 = get(color2, [lab, "l"]);
|
|
3099
|
+
return Math.abs(L1 - L2);
|
|
3100
|
+
}
|
|
3101
|
+
var ε$3 = 216 / 24389;
|
|
3102
|
+
var ε3 = 24 / 116;
|
|
3103
|
+
var κ$2 = 24389 / 27;
|
|
3104
|
+
var white$1 = WHITES.D65;
|
|
3105
|
+
var lab_d65 = new ColorSpace({
|
|
3106
|
+
id: "lab-d65",
|
|
3107
|
+
name: "Lab D65",
|
|
3108
|
+
coords: {
|
|
3109
|
+
l: {
|
|
3110
|
+
refRange: [0, 100],
|
|
3111
|
+
name: "Lightness"
|
|
3112
|
+
},
|
|
3113
|
+
a: { refRange: [-125, 125] },
|
|
3114
|
+
b: { refRange: [-125, 125] }
|
|
3115
|
+
},
|
|
3116
|
+
white: white$1,
|
|
3117
|
+
base: xyz_d65,
|
|
3118
|
+
fromBase(XYZ) {
|
|
3119
|
+
let f = XYZ.map((value, i) => value / white$1[i]).map((value) => value > ε$3 ? Math.cbrt(value) : (κ$2 * value + 16) / 116);
|
|
3120
|
+
return [
|
|
3121
|
+
116 * f[1] - 16,
|
|
3122
|
+
500 * (f[0] - f[1]),
|
|
3123
|
+
200 * (f[1] - f[2])
|
|
3124
|
+
];
|
|
3125
|
+
},
|
|
3126
|
+
toBase(Lab) {
|
|
3127
|
+
let f = [];
|
|
3128
|
+
f[1] = (Lab[0] + 16) / 116;
|
|
3129
|
+
f[0] = Lab[1] / 500 + f[1];
|
|
3130
|
+
f[2] = f[1] - Lab[2] / 200;
|
|
3131
|
+
return [
|
|
3132
|
+
f[0] > ε3 ? Math.pow(f[0], 3) : (116 * f[0] - 16) / κ$2,
|
|
3133
|
+
Lab[0] > 8 ? Math.pow((Lab[0] + 16) / 116, 3) : Lab[0] / κ$2,
|
|
3134
|
+
f[2] > ε3 ? Math.pow(f[2], 3) : (116 * f[2] - 16) / κ$2
|
|
3135
|
+
].map((value, i) => value * white$1[i]);
|
|
3136
|
+
},
|
|
3137
|
+
formats: { "lab-d65": { coords: [
|
|
3138
|
+
"<number> | <percentage>",
|
|
3139
|
+
"<number> | <percentage>[-1,1]",
|
|
3140
|
+
"<number> | <percentage>[-1,1]"
|
|
3141
|
+
] } }
|
|
3142
|
+
});
|
|
3143
|
+
var phi = Math.pow(5, .5) * .5 + .5;
|
|
3144
|
+
function contrastDeltaPhi(color1, color2) {
|
|
3145
|
+
color1 = getColor(color1);
|
|
3146
|
+
color2 = getColor(color2);
|
|
3147
|
+
let Lstr1 = get(color1, [lab_d65, "l"]);
|
|
3148
|
+
let Lstr2 = get(color2, [lab_d65, "l"]);
|
|
3149
|
+
let deltaPhiStar = Math.abs(Math.pow(Lstr1, phi) - Math.pow(Lstr2, phi));
|
|
3150
|
+
let contrast$1 = Math.pow(deltaPhiStar, 1 / phi) * Math.SQRT2 - 40;
|
|
3151
|
+
return contrast$1 < 7.5 ? 0 : contrast$1;
|
|
3152
|
+
}
|
|
3153
|
+
var contrastMethods = /* @__PURE__ */ Object.freeze({
|
|
3154
|
+
__proto__: null,
|
|
3155
|
+
contrastAPCA,
|
|
3156
|
+
contrastDeltaPhi,
|
|
3157
|
+
contrastLstar,
|
|
3158
|
+
contrastMichelson,
|
|
3159
|
+
contrastWCAG21,
|
|
3160
|
+
contrastWeber
|
|
3161
|
+
});
|
|
3162
|
+
function contrast(background, foreground, o = {}) {
|
|
3163
|
+
if (isString(o)) o = { algorithm: o };
|
|
3164
|
+
let { algorithm,...rest } = o;
|
|
3165
|
+
if (!algorithm) {
|
|
3166
|
+
let algorithms = Object.keys(contrastMethods).map((a$1) => a$1.replace(/^contrast/, "")).join(", ");
|
|
3167
|
+
throw new TypeError(`contrast() function needs a contrast algorithm. Please specify one of: ${algorithms}`);
|
|
3168
|
+
}
|
|
3169
|
+
background = getColor(background);
|
|
3170
|
+
foreground = getColor(foreground);
|
|
3171
|
+
for (let a$1 in contrastMethods) if ("contrast" + algorithm.toLowerCase() === a$1.toLowerCase()) return contrastMethods[a$1](background, foreground, rest);
|
|
3172
|
+
throw new TypeError(`Unknown contrast algorithm: ${algorithm}`);
|
|
3173
|
+
}
|
|
3174
|
+
function uv(color) {
|
|
3175
|
+
let [X, Y, Z] = getAll(color, xyz_d65);
|
|
3176
|
+
let denom = X + 15 * Y + 3 * Z;
|
|
3177
|
+
return [4 * X / denom, 9 * Y / denom];
|
|
3178
|
+
}
|
|
3179
|
+
function xy(color) {
|
|
3180
|
+
let [X, Y, Z] = getAll(color, xyz_d65);
|
|
3181
|
+
let sum = X + Y + Z;
|
|
3182
|
+
return [X / sum, Y / sum];
|
|
3183
|
+
}
|
|
3184
|
+
function register$1(Color$1) {
|
|
3185
|
+
Object.defineProperty(Color$1.prototype, "uv", { get() {
|
|
3186
|
+
return uv(this);
|
|
3187
|
+
} });
|
|
3188
|
+
Object.defineProperty(Color$1.prototype, "xy", { get() {
|
|
3189
|
+
return xy(this);
|
|
3190
|
+
} });
|
|
3191
|
+
}
|
|
3192
|
+
var chromaticity = /* @__PURE__ */ Object.freeze({
|
|
3193
|
+
__proto__: null,
|
|
3194
|
+
register: register$1,
|
|
3195
|
+
uv,
|
|
3196
|
+
xy
|
|
3197
|
+
});
|
|
3198
|
+
function deltaE(c1$3, c2$3, o = {}) {
|
|
3199
|
+
if (isString(o)) o = { method: o };
|
|
3200
|
+
let { method = defaults.deltaE,...rest } = o;
|
|
3201
|
+
for (let m$1 in deltaEMethods) if ("deltae" + method.toLowerCase() === m$1.toLowerCase()) return deltaEMethods[m$1](c1$3, c2$3, rest);
|
|
3202
|
+
throw new TypeError(`Unknown deltaE method: ${method}`);
|
|
3203
|
+
}
|
|
3204
|
+
function lighten(color, amount = .25) {
|
|
3205
|
+
return set(color, [ColorSpace.get("oklch", "lch"), "l"], (l) => l * (1 + amount));
|
|
3206
|
+
}
|
|
3207
|
+
function darken(color, amount = .25) {
|
|
3208
|
+
return set(color, [ColorSpace.get("oklch", "lch"), "l"], (l) => l * (1 - amount));
|
|
3209
|
+
}
|
|
3210
|
+
var variations = /* @__PURE__ */ Object.freeze({
|
|
3211
|
+
__proto__: null,
|
|
3212
|
+
darken,
|
|
3213
|
+
lighten
|
|
3214
|
+
});
|
|
3215
|
+
function mix$1(c1$3, c2$3, p$1 = .5, o = {}) {
|
|
3216
|
+
[c1$3, c2$3] = [getColor(c1$3), getColor(c2$3)];
|
|
3217
|
+
if (type(p$1) === "object") [p$1, o] = [.5, p$1];
|
|
3218
|
+
return range(c1$3, c2$3, o)(p$1);
|
|
3219
|
+
}
|
|
3220
|
+
function steps(c1$3, c2$3, options = {}) {
|
|
3221
|
+
let colorRange;
|
|
3222
|
+
if (isRange(c1$3)) {
|
|
3223
|
+
[colorRange, options] = [c1$3, c2$3];
|
|
3224
|
+
[c1$3, c2$3] = colorRange.rangeArgs.colors;
|
|
3225
|
+
}
|
|
3226
|
+
let { maxDeltaE, deltaEMethod, steps: steps$1 = 2, maxSteps = 1e3,...rangeOptions } = options;
|
|
3227
|
+
if (!colorRange) {
|
|
3228
|
+
[c1$3, c2$3] = [getColor(c1$3), getColor(c2$3)];
|
|
3229
|
+
colorRange = range(c1$3, c2$3, rangeOptions);
|
|
3230
|
+
}
|
|
3231
|
+
let totalDelta = deltaE(c1$3, c2$3);
|
|
3232
|
+
let actualSteps = maxDeltaE > 0 ? Math.max(steps$1, Math.ceil(totalDelta / maxDeltaE) + 1) : steps$1;
|
|
3233
|
+
let ret = [];
|
|
3234
|
+
if (maxSteps !== void 0) actualSteps = Math.min(actualSteps, maxSteps);
|
|
3235
|
+
if (actualSteps === 1) ret = [{
|
|
3236
|
+
p: .5,
|
|
3237
|
+
color: colorRange(.5)
|
|
3238
|
+
}];
|
|
3239
|
+
else {
|
|
3240
|
+
let step$1 = 1 / (actualSteps - 1);
|
|
3241
|
+
ret = Array.from({ length: actualSteps }, (_, i) => {
|
|
3242
|
+
let p$1 = i * step$1;
|
|
3243
|
+
return {
|
|
3244
|
+
p: p$1,
|
|
3245
|
+
color: colorRange(p$1)
|
|
3246
|
+
};
|
|
3247
|
+
});
|
|
3248
|
+
}
|
|
3249
|
+
if (maxDeltaE > 0) {
|
|
3250
|
+
let maxDelta = ret.reduce((acc, cur, i) => {
|
|
3251
|
+
if (i === 0) return 0;
|
|
3252
|
+
let ΔΕ = deltaE(cur.color, ret[i - 1].color, deltaEMethod);
|
|
3253
|
+
return Math.max(acc, ΔΕ);
|
|
3254
|
+
}, 0);
|
|
3255
|
+
while (maxDelta > maxDeltaE) {
|
|
3256
|
+
maxDelta = 0;
|
|
3257
|
+
for (let i = 1; i < ret.length && ret.length < maxSteps; i++) {
|
|
3258
|
+
let prev = ret[i - 1];
|
|
3259
|
+
let cur = ret[i];
|
|
3260
|
+
let p$1 = (cur.p + prev.p) / 2;
|
|
3261
|
+
let color = colorRange(p$1);
|
|
3262
|
+
maxDelta = Math.max(maxDelta, deltaE(color, prev.color), deltaE(color, cur.color));
|
|
3263
|
+
ret.splice(i, 0, {
|
|
3264
|
+
p: p$1,
|
|
3265
|
+
color: colorRange(p$1)
|
|
3266
|
+
});
|
|
3267
|
+
i++;
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
ret = ret.map((a$1) => a$1.color);
|
|
3272
|
+
return ret;
|
|
3273
|
+
}
|
|
3274
|
+
function range(color1, color2, options = {}) {
|
|
3275
|
+
if (isRange(color1)) {
|
|
3276
|
+
let [r, options$1] = [color1, color2];
|
|
3277
|
+
return range(...r.rangeArgs.colors, {
|
|
3278
|
+
...r.rangeArgs.options,
|
|
3279
|
+
...options$1
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
let { space, outputSpace, progression, premultiplied } = options;
|
|
3283
|
+
color1 = getColor(color1);
|
|
3284
|
+
color2 = getColor(color2);
|
|
3285
|
+
color1 = clone(color1);
|
|
3286
|
+
color2 = clone(color2);
|
|
3287
|
+
let rangeArgs = {
|
|
3288
|
+
colors: [color1, color2],
|
|
3289
|
+
options
|
|
3290
|
+
};
|
|
3291
|
+
if (space) space = ColorSpace.get(space);
|
|
3292
|
+
else space = ColorSpace.registry[defaults.interpolationSpace] || color1.space;
|
|
3293
|
+
outputSpace = outputSpace ? ColorSpace.get(outputSpace) : space;
|
|
3294
|
+
color1 = to(color1, space);
|
|
3295
|
+
color2 = to(color2, space);
|
|
3296
|
+
color1 = toGamut(color1);
|
|
3297
|
+
color2 = toGamut(color2);
|
|
3298
|
+
if (space.coords.h && space.coords.h.type === "angle") {
|
|
3299
|
+
let arc = options.hue = options.hue || "shorter";
|
|
3300
|
+
let hue = [space, "h"];
|
|
3301
|
+
let [θ1, θ2] = [get(color1, hue), get(color2, hue)];
|
|
3302
|
+
if (isNaN(θ1) && !isNaN(θ2)) θ1 = θ2;
|
|
3303
|
+
else if (isNaN(θ2) && !isNaN(θ1)) θ2 = θ1;
|
|
3304
|
+
[θ1, θ2] = adjust(arc, [θ1, θ2]);
|
|
3305
|
+
set(color1, hue, θ1);
|
|
3306
|
+
set(color2, hue, θ2);
|
|
3307
|
+
}
|
|
3308
|
+
if (premultiplied) {
|
|
3309
|
+
color1.coords = color1.coords.map((c$1) => c$1 * color1.alpha);
|
|
3310
|
+
color2.coords = color2.coords.map((c$1) => c$1 * color2.alpha);
|
|
3311
|
+
}
|
|
3312
|
+
return Object.assign((p$1) => {
|
|
3313
|
+
p$1 = progression ? progression(p$1) : p$1;
|
|
3314
|
+
let coords = color1.coords.map((start, i) => {
|
|
3315
|
+
let end = color2.coords[i];
|
|
3316
|
+
return interpolate(start, end, p$1);
|
|
3317
|
+
});
|
|
3318
|
+
let alpha = interpolate(color1.alpha, color2.alpha, p$1);
|
|
3319
|
+
let ret = {
|
|
3320
|
+
space,
|
|
3321
|
+
coords,
|
|
3322
|
+
alpha
|
|
3323
|
+
};
|
|
3324
|
+
if (premultiplied) ret.coords = ret.coords.map((c$1) => c$1 / alpha);
|
|
3325
|
+
if (outputSpace !== space) ret = to(ret, outputSpace);
|
|
3326
|
+
return ret;
|
|
3327
|
+
}, { rangeArgs });
|
|
3328
|
+
}
|
|
3329
|
+
function isRange(val) {
|
|
3330
|
+
return type(val) === "function" && !!val.rangeArgs;
|
|
3331
|
+
}
|
|
3332
|
+
defaults.interpolationSpace = "lab";
|
|
3333
|
+
function register(Color$1) {
|
|
3334
|
+
Color$1.defineFunction("mix", mix$1, { returns: "color" });
|
|
3335
|
+
Color$1.defineFunction("range", range, { returns: "function<color>" });
|
|
3336
|
+
Color$1.defineFunction("steps", steps, { returns: "array<color>" });
|
|
3337
|
+
}
|
|
3338
|
+
var interpolation = /* @__PURE__ */ Object.freeze({
|
|
3339
|
+
__proto__: null,
|
|
3340
|
+
isRange,
|
|
3341
|
+
mix: mix$1,
|
|
3342
|
+
range,
|
|
3343
|
+
register,
|
|
3344
|
+
steps
|
|
3345
|
+
});
|
|
3346
|
+
var HSL = new ColorSpace({
|
|
3347
|
+
id: "hsl",
|
|
3348
|
+
name: "HSL",
|
|
3349
|
+
coords: {
|
|
3350
|
+
h: {
|
|
3351
|
+
refRange: [0, 360],
|
|
3352
|
+
type: "angle",
|
|
3353
|
+
name: "Hue"
|
|
3354
|
+
},
|
|
3355
|
+
s: {
|
|
3356
|
+
range: [0, 100],
|
|
3357
|
+
name: "Saturation"
|
|
3358
|
+
},
|
|
3359
|
+
l: {
|
|
3360
|
+
range: [0, 100],
|
|
3361
|
+
name: "Lightness"
|
|
3362
|
+
}
|
|
3363
|
+
},
|
|
3364
|
+
base: sRGB,
|
|
3365
|
+
fromBase: (rgb) => {
|
|
3366
|
+
let max$2 = Math.max(...rgb);
|
|
3367
|
+
let min$1 = Math.min(...rgb);
|
|
3368
|
+
let [r, g$1, b$2] = rgb;
|
|
3369
|
+
let [h, s, l] = [
|
|
3370
|
+
NaN,
|
|
3371
|
+
0,
|
|
3372
|
+
(min$1 + max$2) / 2
|
|
3373
|
+
];
|
|
3374
|
+
let d$1 = max$2 - min$1;
|
|
3375
|
+
if (d$1 !== 0) {
|
|
3376
|
+
s = l === 0 || l === 1 ? 0 : (max$2 - l) / Math.min(l, 1 - l);
|
|
3377
|
+
switch (max$2) {
|
|
3378
|
+
case r:
|
|
3379
|
+
h = (g$1 - b$2) / d$1 + (g$1 < b$2 ? 6 : 0);
|
|
3380
|
+
break;
|
|
3381
|
+
case g$1:
|
|
3382
|
+
h = (b$2 - r) / d$1 + 2;
|
|
3383
|
+
break;
|
|
3384
|
+
case b$2: h = (r - g$1) / d$1 + 4;
|
|
3385
|
+
}
|
|
3386
|
+
h = h * 60;
|
|
3387
|
+
}
|
|
3388
|
+
if (s < 0) {
|
|
3389
|
+
h += 180;
|
|
3390
|
+
s = Math.abs(s);
|
|
3391
|
+
}
|
|
3392
|
+
if (h >= 360) h -= 360;
|
|
3393
|
+
return [
|
|
3394
|
+
h,
|
|
3395
|
+
s * 100,
|
|
3396
|
+
l * 100
|
|
3397
|
+
];
|
|
3398
|
+
},
|
|
3399
|
+
toBase: (hsl) => {
|
|
3400
|
+
let [h, s, l] = hsl;
|
|
3401
|
+
h = h % 360;
|
|
3402
|
+
if (h < 0) h += 360;
|
|
3403
|
+
s /= 100;
|
|
3404
|
+
l /= 100;
|
|
3405
|
+
function f(n$2) {
|
|
3406
|
+
let k = (n$2 + h / 30) % 12;
|
|
3407
|
+
let a$1 = s * Math.min(l, 1 - l);
|
|
3408
|
+
return l - a$1 * Math.max(-1, Math.min(k - 3, 9 - k, 1));
|
|
3409
|
+
}
|
|
3410
|
+
return [
|
|
3411
|
+
f(0),
|
|
3412
|
+
f(8),
|
|
3413
|
+
f(4)
|
|
3414
|
+
];
|
|
3415
|
+
},
|
|
3416
|
+
formats: {
|
|
3417
|
+
"hsl": { coords: [
|
|
3418
|
+
"<number> | <angle>",
|
|
3419
|
+
"<percentage>",
|
|
3420
|
+
"<percentage>"
|
|
3421
|
+
] },
|
|
3422
|
+
"hsla": {
|
|
3423
|
+
coords: [
|
|
3424
|
+
"<number> | <angle>",
|
|
3425
|
+
"<percentage>",
|
|
3426
|
+
"<percentage>"
|
|
3427
|
+
],
|
|
3428
|
+
commas: true,
|
|
3429
|
+
lastAlpha: true
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
});
|
|
3433
|
+
var HSV = new ColorSpace({
|
|
3434
|
+
id: "hsv",
|
|
3435
|
+
name: "HSV",
|
|
3436
|
+
coords: {
|
|
3437
|
+
h: {
|
|
3438
|
+
refRange: [0, 360],
|
|
3439
|
+
type: "angle",
|
|
3440
|
+
name: "Hue"
|
|
3441
|
+
},
|
|
3442
|
+
s: {
|
|
3443
|
+
range: [0, 100],
|
|
3444
|
+
name: "Saturation"
|
|
3445
|
+
},
|
|
3446
|
+
v: {
|
|
3447
|
+
range: [0, 100],
|
|
3448
|
+
name: "Value"
|
|
3449
|
+
}
|
|
3450
|
+
},
|
|
3451
|
+
base: HSL,
|
|
3452
|
+
fromBase(hsl) {
|
|
3453
|
+
let [h, s, l] = hsl;
|
|
3454
|
+
s /= 100;
|
|
3455
|
+
l /= 100;
|
|
3456
|
+
let v = l + s * Math.min(l, 1 - l);
|
|
3457
|
+
return [
|
|
3458
|
+
h,
|
|
3459
|
+
v === 0 ? 0 : 200 * (1 - l / v),
|
|
3460
|
+
100 * v
|
|
3461
|
+
];
|
|
3462
|
+
},
|
|
3463
|
+
toBase(hsv) {
|
|
3464
|
+
let [h, s, v] = hsv;
|
|
3465
|
+
s /= 100;
|
|
3466
|
+
v /= 100;
|
|
3467
|
+
let l = v * (1 - s / 2);
|
|
3468
|
+
return [
|
|
3469
|
+
h,
|
|
3470
|
+
l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l) * 100,
|
|
3471
|
+
l * 100
|
|
3472
|
+
];
|
|
3473
|
+
},
|
|
3474
|
+
formats: { color: {
|
|
3475
|
+
id: "--hsv",
|
|
3476
|
+
coords: [
|
|
3477
|
+
"<number> | <angle>",
|
|
3478
|
+
"<percentage> | <number>",
|
|
3479
|
+
"<percentage> | <number>"
|
|
3480
|
+
]
|
|
3481
|
+
} }
|
|
3482
|
+
});
|
|
3483
|
+
var hwb = new ColorSpace({
|
|
3484
|
+
id: "hwb",
|
|
3485
|
+
name: "HWB",
|
|
3486
|
+
coords: {
|
|
3487
|
+
h: {
|
|
3488
|
+
refRange: [0, 360],
|
|
3489
|
+
type: "angle",
|
|
3490
|
+
name: "Hue"
|
|
3491
|
+
},
|
|
3492
|
+
w: {
|
|
3493
|
+
range: [0, 100],
|
|
3494
|
+
name: "Whiteness"
|
|
3495
|
+
},
|
|
3496
|
+
b: {
|
|
3497
|
+
range: [0, 100],
|
|
3498
|
+
name: "Blackness"
|
|
3499
|
+
}
|
|
3500
|
+
},
|
|
3501
|
+
base: HSV,
|
|
3502
|
+
fromBase(hsv) {
|
|
3503
|
+
let [h, s, v] = hsv;
|
|
3504
|
+
return [
|
|
3505
|
+
h,
|
|
3506
|
+
v * (100 - s) / 100,
|
|
3507
|
+
100 - v
|
|
3508
|
+
];
|
|
3509
|
+
},
|
|
3510
|
+
toBase(hwb$1) {
|
|
3511
|
+
let [h, w, b$2] = hwb$1;
|
|
3512
|
+
w /= 100;
|
|
3513
|
+
b$2 /= 100;
|
|
3514
|
+
let sum = w + b$2;
|
|
3515
|
+
if (sum >= 1) return [
|
|
3516
|
+
h,
|
|
3517
|
+
0,
|
|
3518
|
+
w / sum * 100
|
|
3519
|
+
];
|
|
3520
|
+
let v = 1 - b$2;
|
|
3521
|
+
return [
|
|
3522
|
+
h,
|
|
3523
|
+
(v === 0 ? 0 : 1 - w / v) * 100,
|
|
3524
|
+
v * 100
|
|
3525
|
+
];
|
|
3526
|
+
},
|
|
3527
|
+
formats: { "hwb": { coords: [
|
|
3528
|
+
"<number> | <angle>",
|
|
3529
|
+
"<percentage> | <number>",
|
|
3530
|
+
"<percentage> | <number>"
|
|
3531
|
+
] } }
|
|
3532
|
+
});
|
|
3533
|
+
var A98Linear = new RGBColorSpace({
|
|
3534
|
+
id: "a98rgb-linear",
|
|
3535
|
+
cssId: "--a98-rgb-linear",
|
|
3536
|
+
name: "Linear Adobe® 98 RGB compatible",
|
|
3537
|
+
white: "D65",
|
|
3538
|
+
toXYZ_M: [
|
|
3539
|
+
[
|
|
3540
|
+
.5766690429101305,
|
|
3541
|
+
.1855582379065463,
|
|
3542
|
+
.1882286462349947
|
|
3543
|
+
],
|
|
3544
|
+
[
|
|
3545
|
+
.29734497525053605,
|
|
3546
|
+
.6273635662554661,
|
|
3547
|
+
.07529145849399788
|
|
3548
|
+
],
|
|
3549
|
+
[
|
|
3550
|
+
.02703136138641234,
|
|
3551
|
+
.07068885253582723,
|
|
3552
|
+
.9913375368376388
|
|
3553
|
+
]
|
|
3554
|
+
],
|
|
3555
|
+
fromXYZ_M: [
|
|
3556
|
+
[
|
|
3557
|
+
2.0415879038107465,
|
|
3558
|
+
-.5650069742788596,
|
|
3559
|
+
-.34473135077832956
|
|
3560
|
+
],
|
|
3561
|
+
[
|
|
3562
|
+
-.9692436362808795,
|
|
3563
|
+
1.8759675015077202,
|
|
3564
|
+
.04155505740717557
|
|
3565
|
+
],
|
|
3566
|
+
[
|
|
3567
|
+
.013444280632031142,
|
|
3568
|
+
-.11836239223101838,
|
|
3569
|
+
1.0151749943912054
|
|
3570
|
+
]
|
|
3571
|
+
]
|
|
3572
|
+
});
|
|
3573
|
+
var a98rgb = new RGBColorSpace({
|
|
3574
|
+
id: "a98rgb",
|
|
3575
|
+
cssId: "a98-rgb",
|
|
3576
|
+
name: "Adobe® 98 RGB compatible",
|
|
3577
|
+
base: A98Linear,
|
|
3578
|
+
toBase: (RGB) => RGB.map((val) => Math.pow(Math.abs(val), 563 / 256) * Math.sign(val)),
|
|
3579
|
+
fromBase: (RGB) => RGB.map((val) => Math.pow(Math.abs(val), 256 / 563) * Math.sign(val))
|
|
3580
|
+
});
|
|
3581
|
+
var ProPhotoLinear = new RGBColorSpace({
|
|
3582
|
+
id: "prophoto-linear",
|
|
3583
|
+
cssId: "--prophoto-rgb-linear",
|
|
3584
|
+
name: "Linear ProPhoto",
|
|
3585
|
+
white: "D50",
|
|
3586
|
+
base: XYZ_D50,
|
|
3587
|
+
toXYZ_M: [
|
|
3588
|
+
[
|
|
3589
|
+
.7977666449006423,
|
|
3590
|
+
.13518129740053308,
|
|
3591
|
+
.0313477341283922
|
|
3592
|
+
],
|
|
3593
|
+
[
|
|
3594
|
+
.2880748288194013,
|
|
3595
|
+
.711835234241873,
|
|
3596
|
+
8993693872564e-17
|
|
3597
|
+
],
|
|
3598
|
+
[
|
|
3599
|
+
0,
|
|
3600
|
+
0,
|
|
3601
|
+
.8251046025104602
|
|
3602
|
+
]
|
|
3603
|
+
],
|
|
3604
|
+
fromXYZ_M: [
|
|
3605
|
+
[
|
|
3606
|
+
1.3457868816471583,
|
|
3607
|
+
-.25557208737979464,
|
|
3608
|
+
-.05110186497554526
|
|
3609
|
+
],
|
|
3610
|
+
[
|
|
3611
|
+
-.5446307051249019,
|
|
3612
|
+
1.5082477428451468,
|
|
3613
|
+
.02052744743642139
|
|
3614
|
+
],
|
|
3615
|
+
[
|
|
3616
|
+
0,
|
|
3617
|
+
0,
|
|
3618
|
+
1.2119675456389452
|
|
3619
|
+
]
|
|
3620
|
+
]
|
|
3621
|
+
});
|
|
3622
|
+
var Et = 1 / 512;
|
|
3623
|
+
var Et2 = 16 / 512;
|
|
3624
|
+
var prophoto = new RGBColorSpace({
|
|
3625
|
+
id: "prophoto",
|
|
3626
|
+
cssId: "prophoto-rgb",
|
|
3627
|
+
name: "ProPhoto",
|
|
3628
|
+
base: ProPhotoLinear,
|
|
3629
|
+
toBase(RGB) {
|
|
3630
|
+
return RGB.map((v) => v < Et2 ? v / 16 : v ** 1.8);
|
|
3631
|
+
},
|
|
3632
|
+
fromBase(RGB) {
|
|
3633
|
+
return RGB.map((v) => v >= Et ? v ** (1 / 1.8) : 16 * v);
|
|
3634
|
+
}
|
|
3635
|
+
});
|
|
3636
|
+
var oklch = new ColorSpace({
|
|
3637
|
+
id: "oklch",
|
|
3638
|
+
name: "Oklch",
|
|
3639
|
+
coords: {
|
|
3640
|
+
l: {
|
|
3641
|
+
refRange: [0, 1],
|
|
3642
|
+
name: "Lightness"
|
|
3643
|
+
},
|
|
3644
|
+
c: {
|
|
3645
|
+
refRange: [0, .4],
|
|
3646
|
+
name: "Chroma"
|
|
3647
|
+
},
|
|
3648
|
+
h: {
|
|
3649
|
+
refRange: [0, 360],
|
|
3650
|
+
type: "angle",
|
|
3651
|
+
name: "Hue"
|
|
3652
|
+
}
|
|
3653
|
+
},
|
|
3654
|
+
white: "D65",
|
|
3655
|
+
base: OKLab,
|
|
3656
|
+
fromBase(oklab) {
|
|
3657
|
+
let [L, a$1, b$2] = oklab;
|
|
3658
|
+
let h;
|
|
3659
|
+
const ε$8 = 2e-4;
|
|
3660
|
+
if (Math.abs(a$1) < ε$8 && Math.abs(b$2) < ε$8) h = NaN;
|
|
3661
|
+
else h = Math.atan2(b$2, a$1) * 180 / Math.PI;
|
|
3662
|
+
return [
|
|
3663
|
+
L,
|
|
3664
|
+
Math.sqrt(a$1 ** 2 + b$2 ** 2),
|
|
3665
|
+
constrain(h)
|
|
3666
|
+
];
|
|
3667
|
+
},
|
|
3668
|
+
toBase(oklch$1) {
|
|
3669
|
+
let [L, C, h] = oklch$1;
|
|
3670
|
+
let a$1, b$2;
|
|
3671
|
+
if (isNaN(h)) {
|
|
3672
|
+
a$1 = 0;
|
|
3673
|
+
b$2 = 0;
|
|
3674
|
+
} else {
|
|
3675
|
+
a$1 = C * Math.cos(h * Math.PI / 180);
|
|
3676
|
+
b$2 = C * Math.sin(h * Math.PI / 180);
|
|
3677
|
+
}
|
|
3678
|
+
return [
|
|
3679
|
+
L,
|
|
3680
|
+
a$1,
|
|
3681
|
+
b$2
|
|
3682
|
+
];
|
|
3683
|
+
},
|
|
3684
|
+
formats: { "oklch": { coords: [
|
|
3685
|
+
"<percentage> | <number>",
|
|
3686
|
+
"<number> | <percentage>[0,1]",
|
|
3687
|
+
"<number> | <angle>"
|
|
3688
|
+
] } }
|
|
3689
|
+
});
|
|
3690
|
+
var white = WHITES.D65;
|
|
3691
|
+
var ε$2 = 216 / 24389;
|
|
3692
|
+
var κ$1 = 24389 / 27;
|
|
3693
|
+
var [U_PRIME_WHITE, V_PRIME_WHITE] = uv({
|
|
3694
|
+
space: xyz_d65,
|
|
3695
|
+
coords: white
|
|
3696
|
+
});
|
|
3697
|
+
var Luv = new ColorSpace({
|
|
3698
|
+
id: "luv",
|
|
3699
|
+
name: "Luv",
|
|
3700
|
+
coords: {
|
|
3701
|
+
l: {
|
|
3702
|
+
refRange: [0, 100],
|
|
3703
|
+
name: "Lightness"
|
|
3704
|
+
},
|
|
3705
|
+
u: { refRange: [-215, 215] },
|
|
3706
|
+
v: { refRange: [-215, 215] }
|
|
3707
|
+
},
|
|
3708
|
+
white,
|
|
3709
|
+
base: xyz_d65,
|
|
3710
|
+
fromBase(XYZ) {
|
|
3711
|
+
let xyz = [
|
|
3712
|
+
skipNone(XYZ[0]),
|
|
3713
|
+
skipNone(XYZ[1]),
|
|
3714
|
+
skipNone(XYZ[2])
|
|
3715
|
+
];
|
|
3716
|
+
let y = xyz[1];
|
|
3717
|
+
let [up, vp] = uv({
|
|
3718
|
+
space: xyz_d65,
|
|
3719
|
+
coords: xyz
|
|
3720
|
+
});
|
|
3721
|
+
if (!Number.isFinite(up) || !Number.isFinite(vp)) return [
|
|
3722
|
+
0,
|
|
3723
|
+
0,
|
|
3724
|
+
0
|
|
3725
|
+
];
|
|
3726
|
+
let L = y <= ε$2 ? κ$1 * y : 116 * Math.cbrt(y) - 16;
|
|
3727
|
+
return [
|
|
3728
|
+
L,
|
|
3729
|
+
13 * L * (up - U_PRIME_WHITE),
|
|
3730
|
+
13 * L * (vp - V_PRIME_WHITE)
|
|
3731
|
+
];
|
|
3732
|
+
},
|
|
3733
|
+
toBase(Luv$1) {
|
|
3734
|
+
let [L, u, v] = Luv$1;
|
|
3735
|
+
if (L === 0 || isNone(L)) return [
|
|
3736
|
+
0,
|
|
3737
|
+
0,
|
|
3738
|
+
0
|
|
3739
|
+
];
|
|
3740
|
+
u = skipNone(u);
|
|
3741
|
+
v = skipNone(v);
|
|
3742
|
+
let up = u / (13 * L) + U_PRIME_WHITE;
|
|
3743
|
+
let vp = v / (13 * L) + V_PRIME_WHITE;
|
|
3744
|
+
let y = L <= 8 ? L / κ$1 : Math.pow((L + 16) / 116, 3);
|
|
3745
|
+
return [
|
|
3746
|
+
y * (9 * up / (4 * vp)),
|
|
3747
|
+
y,
|
|
3748
|
+
y * ((12 - 3 * up - 20 * vp) / (4 * vp))
|
|
3749
|
+
];
|
|
3750
|
+
},
|
|
3751
|
+
formats: { color: {
|
|
3752
|
+
id: "--luv",
|
|
3753
|
+
coords: [
|
|
3754
|
+
"<number> | <percentage>",
|
|
3755
|
+
"<number> | <percentage>[-1,1]",
|
|
3756
|
+
"<number> | <percentage>[-1,1]"
|
|
3757
|
+
]
|
|
3758
|
+
} }
|
|
3759
|
+
});
|
|
3760
|
+
var LCHuv = new ColorSpace({
|
|
3761
|
+
id: "lchuv",
|
|
3762
|
+
name: "LChuv",
|
|
3763
|
+
coords: {
|
|
3764
|
+
l: {
|
|
3765
|
+
refRange: [0, 100],
|
|
3766
|
+
name: "Lightness"
|
|
3767
|
+
},
|
|
3768
|
+
c: {
|
|
3769
|
+
refRange: [0, 220],
|
|
3770
|
+
name: "Chroma"
|
|
3771
|
+
},
|
|
3772
|
+
h: {
|
|
3773
|
+
refRange: [0, 360],
|
|
3774
|
+
type: "angle",
|
|
3775
|
+
name: "Hue"
|
|
3776
|
+
}
|
|
3777
|
+
},
|
|
3778
|
+
base: Luv,
|
|
3779
|
+
fromBase(Luv$1) {
|
|
3780
|
+
let [L, u, v] = Luv$1;
|
|
3781
|
+
let hue;
|
|
3782
|
+
const ε$8 = .02;
|
|
3783
|
+
if (Math.abs(u) < ε$8 && Math.abs(v) < ε$8) hue = NaN;
|
|
3784
|
+
else hue = Math.atan2(v, u) * 180 / Math.PI;
|
|
3785
|
+
return [
|
|
3786
|
+
L,
|
|
3787
|
+
Math.sqrt(u ** 2 + v ** 2),
|
|
3788
|
+
constrain(hue)
|
|
3789
|
+
];
|
|
3790
|
+
},
|
|
3791
|
+
toBase(LCH) {
|
|
3792
|
+
let [Lightness, Chroma, Hue] = LCH;
|
|
3793
|
+
if (Chroma < 0) Chroma = 0;
|
|
3794
|
+
if (isNaN(Hue)) Hue = 0;
|
|
3795
|
+
return [
|
|
3796
|
+
Lightness,
|
|
3797
|
+
Chroma * Math.cos(Hue * Math.PI / 180),
|
|
3798
|
+
Chroma * Math.sin(Hue * Math.PI / 180)
|
|
3799
|
+
];
|
|
3800
|
+
},
|
|
3801
|
+
formats: { color: {
|
|
3802
|
+
id: "--lchuv",
|
|
3803
|
+
coords: [
|
|
3804
|
+
"<number> | <percentage>",
|
|
3805
|
+
"<number> | <percentage>",
|
|
3806
|
+
"<number> | <angle>"
|
|
3807
|
+
]
|
|
3808
|
+
} }
|
|
3809
|
+
});
|
|
3810
|
+
var ε$1 = 216 / 24389;
|
|
3811
|
+
var κ = 24389 / 27;
|
|
3812
|
+
var m_r0 = fromXYZ_M$3[0][0];
|
|
3813
|
+
var m_r1 = fromXYZ_M$3[0][1];
|
|
3814
|
+
var m_r2 = fromXYZ_M$3[0][2];
|
|
3815
|
+
var m_g0 = fromXYZ_M$3[1][0];
|
|
3816
|
+
var m_g1 = fromXYZ_M$3[1][1];
|
|
3817
|
+
var m_g2 = fromXYZ_M$3[1][2];
|
|
3818
|
+
var m_b0 = fromXYZ_M$3[2][0];
|
|
3819
|
+
var m_b1 = fromXYZ_M$3[2][1];
|
|
3820
|
+
var m_b2 = fromXYZ_M$3[2][2];
|
|
3821
|
+
function distanceFromOriginAngle(slope, intercept, angle) {
|
|
3822
|
+
const d$1 = intercept / (Math.sin(angle) - slope * Math.cos(angle));
|
|
3823
|
+
return d$1 < 0 ? Infinity : d$1;
|
|
3824
|
+
}
|
|
3825
|
+
function calculateBoundingLines(l) {
|
|
3826
|
+
const sub1 = Math.pow(l + 16, 3) / 1560896;
|
|
3827
|
+
const sub2 = sub1 > ε$1 ? sub1 : l / κ;
|
|
3828
|
+
const s1r = sub2 * (284517 * m_r0 - 94839 * m_r2);
|
|
3829
|
+
const s2r = sub2 * (838422 * m_r2 + 769860 * m_r1 + 731718 * m_r0);
|
|
3830
|
+
const s3r = sub2 * (632260 * m_r2 - 126452 * m_r1);
|
|
3831
|
+
const s1g = sub2 * (284517 * m_g0 - 94839 * m_g2);
|
|
3832
|
+
const s2g = sub2 * (838422 * m_g2 + 769860 * m_g1 + 731718 * m_g0);
|
|
3833
|
+
const s3g = sub2 * (632260 * m_g2 - 126452 * m_g1);
|
|
3834
|
+
const s1b = sub2 * (284517 * m_b0 - 94839 * m_b2);
|
|
3835
|
+
const s2b = sub2 * (838422 * m_b2 + 769860 * m_b1 + 731718 * m_b0);
|
|
3836
|
+
const s3b = sub2 * (632260 * m_b2 - 126452 * m_b1);
|
|
3837
|
+
return {
|
|
3838
|
+
r0s: s1r / s3r,
|
|
3839
|
+
r0i: s2r * l / s3r,
|
|
3840
|
+
r1s: s1r / (s3r + 126452),
|
|
3841
|
+
r1i: (s2r - 769860) * l / (s3r + 126452),
|
|
3842
|
+
g0s: s1g / s3g,
|
|
3843
|
+
g0i: s2g * l / s3g,
|
|
3844
|
+
g1s: s1g / (s3g + 126452),
|
|
3845
|
+
g1i: (s2g - 769860) * l / (s3g + 126452),
|
|
3846
|
+
b0s: s1b / s3b,
|
|
3847
|
+
b0i: s2b * l / s3b,
|
|
3848
|
+
b1s: s1b / (s3b + 126452),
|
|
3849
|
+
b1i: (s2b - 769860) * l / (s3b + 126452)
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
function calcMaxChromaHsluv(lines, h) {
|
|
3853
|
+
const hueRad = h / 360 * Math.PI * 2;
|
|
3854
|
+
const r0 = distanceFromOriginAngle(lines.r0s, lines.r0i, hueRad);
|
|
3855
|
+
const r1 = distanceFromOriginAngle(lines.r1s, lines.r1i, hueRad);
|
|
3856
|
+
const g0 = distanceFromOriginAngle(lines.g0s, lines.g0i, hueRad);
|
|
3857
|
+
const g1 = distanceFromOriginAngle(lines.g1s, lines.g1i, hueRad);
|
|
3858
|
+
const b0 = distanceFromOriginAngle(lines.b0s, lines.b0i, hueRad);
|
|
3859
|
+
const b1 = distanceFromOriginAngle(lines.b1s, lines.b1i, hueRad);
|
|
3860
|
+
return Math.min(r0, r1, g0, g1, b0, b1);
|
|
3861
|
+
}
|
|
3862
|
+
var hsluv = new ColorSpace({
|
|
3863
|
+
id: "hsluv",
|
|
3864
|
+
name: "HSLuv",
|
|
3865
|
+
coords: {
|
|
3866
|
+
h: {
|
|
3867
|
+
refRange: [0, 360],
|
|
3868
|
+
type: "angle",
|
|
3869
|
+
name: "Hue"
|
|
3870
|
+
},
|
|
3871
|
+
s: {
|
|
3872
|
+
range: [0, 100],
|
|
3873
|
+
name: "Saturation"
|
|
3874
|
+
},
|
|
3875
|
+
l: {
|
|
3876
|
+
range: [0, 100],
|
|
3877
|
+
name: "Lightness"
|
|
3878
|
+
}
|
|
3879
|
+
},
|
|
3880
|
+
base: LCHuv,
|
|
3881
|
+
gamutSpace: sRGB,
|
|
3882
|
+
fromBase(lch$1) {
|
|
3883
|
+
let [l, c$1, h] = [
|
|
3884
|
+
skipNone(lch$1[0]),
|
|
3885
|
+
skipNone(lch$1[1]),
|
|
3886
|
+
skipNone(lch$1[2])
|
|
3887
|
+
];
|
|
3888
|
+
let s;
|
|
3889
|
+
if (l > 99.9999999) {
|
|
3890
|
+
s = 0;
|
|
3891
|
+
l = 100;
|
|
3892
|
+
} else if (l < 1e-8) {
|
|
3893
|
+
s = 0;
|
|
3894
|
+
l = 0;
|
|
3895
|
+
} else s = c$1 / calcMaxChromaHsluv(calculateBoundingLines(l), h) * 100;
|
|
3896
|
+
return [
|
|
3897
|
+
h,
|
|
3898
|
+
s,
|
|
3899
|
+
l
|
|
3900
|
+
];
|
|
3901
|
+
},
|
|
3902
|
+
toBase(hsl) {
|
|
3903
|
+
let [h, s, l] = [
|
|
3904
|
+
skipNone(hsl[0]),
|
|
3905
|
+
skipNone(hsl[1]),
|
|
3906
|
+
skipNone(hsl[2])
|
|
3907
|
+
];
|
|
3908
|
+
let c$1;
|
|
3909
|
+
if (l > 99.9999999) {
|
|
3910
|
+
l = 100;
|
|
3911
|
+
c$1 = 0;
|
|
3912
|
+
} else if (l < 1e-8) {
|
|
3913
|
+
l = 0;
|
|
3914
|
+
c$1 = 0;
|
|
3915
|
+
} else c$1 = calcMaxChromaHsluv(calculateBoundingLines(l), h) / 100 * s;
|
|
3916
|
+
return [
|
|
3917
|
+
l,
|
|
3918
|
+
c$1,
|
|
3919
|
+
h
|
|
3920
|
+
];
|
|
3921
|
+
},
|
|
3922
|
+
formats: { color: {
|
|
3923
|
+
id: "--hsluv",
|
|
3924
|
+
coords: [
|
|
3925
|
+
"<number> | <angle>",
|
|
3926
|
+
"<percentage> | <number>",
|
|
3927
|
+
"<percentage> | <number>"
|
|
3928
|
+
]
|
|
3929
|
+
} }
|
|
3930
|
+
});
|
|
3931
|
+
fromXYZ_M$3[0][0];
|
|
3932
|
+
fromXYZ_M$3[0][1];
|
|
3933
|
+
fromXYZ_M$3[0][2];
|
|
3934
|
+
fromXYZ_M$3[1][0];
|
|
3935
|
+
fromXYZ_M$3[1][1];
|
|
3936
|
+
fromXYZ_M$3[1][2];
|
|
3937
|
+
fromXYZ_M$3[2][0];
|
|
3938
|
+
fromXYZ_M$3[2][1];
|
|
3939
|
+
fromXYZ_M$3[2][2];
|
|
3940
|
+
function distanceFromOrigin(slope, intercept) {
|
|
3941
|
+
return Math.abs(intercept) / Math.sqrt(Math.pow(slope, 2) + 1);
|
|
3942
|
+
}
|
|
3943
|
+
function calcMaxChromaHpluv(lines) {
|
|
3944
|
+
let r0 = distanceFromOrigin(lines.r0s, lines.r0i);
|
|
3945
|
+
let r1 = distanceFromOrigin(lines.r1s, lines.r1i);
|
|
3946
|
+
let g0 = distanceFromOrigin(lines.g0s, lines.g0i);
|
|
3947
|
+
let g1 = distanceFromOrigin(lines.g1s, lines.g1i);
|
|
3948
|
+
let b0 = distanceFromOrigin(lines.b0s, lines.b0i);
|
|
3949
|
+
let b1 = distanceFromOrigin(lines.b1s, lines.b1i);
|
|
3950
|
+
return Math.min(r0, r1, g0, g1, b0, b1);
|
|
3951
|
+
}
|
|
3952
|
+
var hpluv = new ColorSpace({
|
|
3953
|
+
id: "hpluv",
|
|
3954
|
+
name: "HPLuv",
|
|
3955
|
+
coords: {
|
|
3956
|
+
h: {
|
|
3957
|
+
refRange: [0, 360],
|
|
3958
|
+
type: "angle",
|
|
3959
|
+
name: "Hue"
|
|
3960
|
+
},
|
|
3961
|
+
s: {
|
|
3962
|
+
range: [0, 100],
|
|
3963
|
+
name: "Saturation"
|
|
3964
|
+
},
|
|
3965
|
+
l: {
|
|
3966
|
+
range: [0, 100],
|
|
3967
|
+
name: "Lightness"
|
|
3968
|
+
}
|
|
3969
|
+
},
|
|
3970
|
+
base: LCHuv,
|
|
3971
|
+
gamutSpace: "self",
|
|
3972
|
+
fromBase(lch$1) {
|
|
3973
|
+
let [l, c$1, h] = [
|
|
3974
|
+
skipNone(lch$1[0]),
|
|
3975
|
+
skipNone(lch$1[1]),
|
|
3976
|
+
skipNone(lch$1[2])
|
|
3977
|
+
];
|
|
3978
|
+
let s;
|
|
3979
|
+
if (l > 99.9999999) {
|
|
3980
|
+
s = 0;
|
|
3981
|
+
l = 100;
|
|
3982
|
+
} else if (l < 1e-8) {
|
|
3983
|
+
s = 0;
|
|
3984
|
+
l = 0;
|
|
3985
|
+
} else s = c$1 / calcMaxChromaHpluv(calculateBoundingLines(l)) * 100;
|
|
3986
|
+
return [
|
|
3987
|
+
h,
|
|
3988
|
+
s,
|
|
3989
|
+
l
|
|
3990
|
+
];
|
|
3991
|
+
},
|
|
3992
|
+
toBase(hsl) {
|
|
3993
|
+
let [h, s, l] = [
|
|
3994
|
+
skipNone(hsl[0]),
|
|
3995
|
+
skipNone(hsl[1]),
|
|
3996
|
+
skipNone(hsl[2])
|
|
3997
|
+
];
|
|
3998
|
+
let c$1;
|
|
3999
|
+
if (l > 99.9999999) {
|
|
4000
|
+
l = 100;
|
|
4001
|
+
c$1 = 0;
|
|
4002
|
+
} else if (l < 1e-8) {
|
|
4003
|
+
l = 0;
|
|
4004
|
+
c$1 = 0;
|
|
4005
|
+
} else c$1 = calcMaxChromaHpluv(calculateBoundingLines(l)) / 100 * s;
|
|
4006
|
+
return [
|
|
4007
|
+
l,
|
|
4008
|
+
c$1,
|
|
4009
|
+
h
|
|
4010
|
+
];
|
|
4011
|
+
},
|
|
4012
|
+
formats: { color: {
|
|
4013
|
+
id: "--hpluv",
|
|
4014
|
+
coords: [
|
|
4015
|
+
"<number> | <angle>",
|
|
4016
|
+
"<percentage> | <number>",
|
|
4017
|
+
"<percentage> | <number>"
|
|
4018
|
+
]
|
|
4019
|
+
} }
|
|
4020
|
+
});
|
|
4021
|
+
var Yw = 203;
|
|
4022
|
+
var n = 2610 / 2 ** 14;
|
|
4023
|
+
var ninv = 2 ** 14 / 2610;
|
|
4024
|
+
var m = 2523 / 2 ** 5;
|
|
4025
|
+
var minv = 2 ** 5 / 2523;
|
|
4026
|
+
var c1 = 3424 / 2 ** 12;
|
|
4027
|
+
var c2 = 2413 / 2 ** 7;
|
|
4028
|
+
var c3 = 2392 / 2 ** 7;
|
|
4029
|
+
var rec2100Pq = new RGBColorSpace({
|
|
4030
|
+
id: "rec2100pq",
|
|
4031
|
+
cssId: "rec2100-pq",
|
|
4032
|
+
name: "REC.2100-PQ",
|
|
4033
|
+
base: REC2020Linear,
|
|
4034
|
+
toBase(RGB) {
|
|
4035
|
+
return RGB.map(function(val) {
|
|
4036
|
+
return (Math.max(val ** minv - c1, 0) / (c2 - c3 * val ** minv)) ** ninv * 1e4 / Yw;
|
|
4037
|
+
});
|
|
4038
|
+
},
|
|
4039
|
+
fromBase(RGB) {
|
|
4040
|
+
return RGB.map(function(val) {
|
|
4041
|
+
let x = Math.max(val * Yw / 1e4, 0);
|
|
4042
|
+
return ((c1 + c2 * x ** n) / (1 + c3 * x ** n)) ** m;
|
|
4043
|
+
});
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
var a = .17883277;
|
|
4047
|
+
var b = .28466892;
|
|
4048
|
+
var c = .55991073;
|
|
4049
|
+
var scale = 3.7743;
|
|
4050
|
+
var rec2100Hlg = new RGBColorSpace({
|
|
4051
|
+
id: "rec2100hlg",
|
|
4052
|
+
cssId: "rec2100-hlg",
|
|
4053
|
+
name: "REC.2100-HLG",
|
|
4054
|
+
referred: "scene",
|
|
4055
|
+
base: REC2020Linear,
|
|
4056
|
+
toBase(RGB) {
|
|
4057
|
+
return RGB.map(function(val) {
|
|
4058
|
+
if (val <= .5) return val ** 2 / 3 * scale;
|
|
4059
|
+
return (Math.exp((val - c) / a) + b) / 12 * scale;
|
|
4060
|
+
});
|
|
4061
|
+
},
|
|
4062
|
+
fromBase(RGB) {
|
|
4063
|
+
return RGB.map(function(val) {
|
|
4064
|
+
val /= scale;
|
|
4065
|
+
if (val <= 1 / 12) return Math.sqrt(3 * val);
|
|
4066
|
+
return a * Math.log(12 * val - b) + c;
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4069
|
+
});
|
|
4070
|
+
var CATs = {};
|
|
4071
|
+
hooks.add("chromatic-adaptation-start", (env) => {
|
|
4072
|
+
if (env.options.method) env.M = adapt(env.W1, env.W2, env.options.method);
|
|
4073
|
+
});
|
|
4074
|
+
hooks.add("chromatic-adaptation-end", (env) => {
|
|
4075
|
+
if (!env.M) env.M = adapt(env.W1, env.W2, env.options.method);
|
|
4076
|
+
});
|
|
4077
|
+
function defineCAT({ id, toCone_M, fromCone_M }) {
|
|
4078
|
+
CATs[id] = arguments[0];
|
|
4079
|
+
}
|
|
4080
|
+
function adapt(W1, W2, id = "Bradford") {
|
|
4081
|
+
let method = CATs[id];
|
|
4082
|
+
let [ρs, γs, βs] = multiplyMatrices(method.toCone_M, W1);
|
|
4083
|
+
let [ρd, γd, βd] = multiplyMatrices(method.toCone_M, W2);
|
|
4084
|
+
let scaled_cone_M = multiplyMatrices([
|
|
4085
|
+
[
|
|
4086
|
+
ρd / ρs,
|
|
4087
|
+
0,
|
|
4088
|
+
0
|
|
4089
|
+
],
|
|
4090
|
+
[
|
|
4091
|
+
0,
|
|
4092
|
+
γd / γs,
|
|
4093
|
+
0
|
|
4094
|
+
],
|
|
4095
|
+
[
|
|
4096
|
+
0,
|
|
4097
|
+
0,
|
|
4098
|
+
βd / βs
|
|
4099
|
+
]
|
|
4100
|
+
], method.toCone_M);
|
|
4101
|
+
return multiplyMatrices(method.fromCone_M, scaled_cone_M);
|
|
4102
|
+
}
|
|
4103
|
+
defineCAT({
|
|
4104
|
+
id: "von Kries",
|
|
4105
|
+
toCone_M: [
|
|
4106
|
+
[
|
|
4107
|
+
.40024,
|
|
4108
|
+
.7076,
|
|
4109
|
+
-.08081
|
|
4110
|
+
],
|
|
4111
|
+
[
|
|
4112
|
+
-.2263,
|
|
4113
|
+
1.16532,
|
|
4114
|
+
.0457
|
|
4115
|
+
],
|
|
4116
|
+
[
|
|
4117
|
+
0,
|
|
4118
|
+
0,
|
|
4119
|
+
.91822
|
|
4120
|
+
]
|
|
4121
|
+
],
|
|
4122
|
+
fromCone_M: [
|
|
4123
|
+
[
|
|
4124
|
+
1.8599363874558397,
|
|
4125
|
+
-1.1293816185800916,
|
|
4126
|
+
.21989740959619328
|
|
4127
|
+
],
|
|
4128
|
+
[
|
|
4129
|
+
.3611914362417676,
|
|
4130
|
+
.6388124632850422,
|
|
4131
|
+
-6370596838649899e-21
|
|
4132
|
+
],
|
|
4133
|
+
[
|
|
4134
|
+
0,
|
|
4135
|
+
0,
|
|
4136
|
+
1.0890636230968613
|
|
4137
|
+
]
|
|
4138
|
+
]
|
|
4139
|
+
});
|
|
4140
|
+
defineCAT({
|
|
4141
|
+
id: "Bradford",
|
|
4142
|
+
toCone_M: [
|
|
4143
|
+
[
|
|
4144
|
+
.8951,
|
|
4145
|
+
.2664,
|
|
4146
|
+
-.1614
|
|
4147
|
+
],
|
|
4148
|
+
[
|
|
4149
|
+
-.7502,
|
|
4150
|
+
1.7135,
|
|
4151
|
+
.0367
|
|
4152
|
+
],
|
|
4153
|
+
[
|
|
4154
|
+
.0389,
|
|
4155
|
+
-.0685,
|
|
4156
|
+
1.0296
|
|
4157
|
+
]
|
|
4158
|
+
],
|
|
4159
|
+
fromCone_M: [
|
|
4160
|
+
[
|
|
4161
|
+
.9869929054667121,
|
|
4162
|
+
-.14705425642099013,
|
|
4163
|
+
.15996265166373122
|
|
4164
|
+
],
|
|
4165
|
+
[
|
|
4166
|
+
.4323052697233945,
|
|
4167
|
+
.5183602715367774,
|
|
4168
|
+
.049291228212855594
|
|
4169
|
+
],
|
|
4170
|
+
[
|
|
4171
|
+
-.00852866457517732,
|
|
4172
|
+
.04004282165408486,
|
|
4173
|
+
.96848669578755
|
|
4174
|
+
]
|
|
4175
|
+
]
|
|
4176
|
+
});
|
|
4177
|
+
defineCAT({
|
|
4178
|
+
id: "CAT02",
|
|
4179
|
+
toCone_M: [
|
|
4180
|
+
[
|
|
4181
|
+
.7328,
|
|
4182
|
+
.4296,
|
|
4183
|
+
-.1624
|
|
4184
|
+
],
|
|
4185
|
+
[
|
|
4186
|
+
-.7036,
|
|
4187
|
+
1.6975,
|
|
4188
|
+
.0061
|
|
4189
|
+
],
|
|
4190
|
+
[
|
|
4191
|
+
.003,
|
|
4192
|
+
.0136,
|
|
4193
|
+
.9834
|
|
4194
|
+
]
|
|
4195
|
+
],
|
|
4196
|
+
fromCone_M: [
|
|
4197
|
+
[
|
|
4198
|
+
1.0961238208355142,
|
|
4199
|
+
-.27886900021828726,
|
|
4200
|
+
.18274517938277307
|
|
4201
|
+
],
|
|
4202
|
+
[
|
|
4203
|
+
.4543690419753592,
|
|
4204
|
+
.4735331543074117,
|
|
4205
|
+
.07209780371722911
|
|
4206
|
+
],
|
|
4207
|
+
[
|
|
4208
|
+
-.009627608738429355,
|
|
4209
|
+
-.00569803121611342,
|
|
4210
|
+
1.0153256399545427
|
|
4211
|
+
]
|
|
4212
|
+
]
|
|
4213
|
+
});
|
|
4214
|
+
defineCAT({
|
|
4215
|
+
id: "CAT16",
|
|
4216
|
+
toCone_M: [
|
|
4217
|
+
[
|
|
4218
|
+
.401288,
|
|
4219
|
+
.650173,
|
|
4220
|
+
-.051461
|
|
4221
|
+
],
|
|
4222
|
+
[
|
|
4223
|
+
-.250268,
|
|
4224
|
+
1.204414,
|
|
4225
|
+
.045854
|
|
4226
|
+
],
|
|
4227
|
+
[
|
|
4228
|
+
-.002079,
|
|
4229
|
+
.048952,
|
|
4230
|
+
.953127
|
|
4231
|
+
]
|
|
4232
|
+
],
|
|
4233
|
+
fromCone_M: [
|
|
4234
|
+
[
|
|
4235
|
+
1.862067855087233,
|
|
4236
|
+
-1.0112546305316845,
|
|
4237
|
+
.14918677544445172
|
|
4238
|
+
],
|
|
4239
|
+
[
|
|
4240
|
+
.3875265432361372,
|
|
4241
|
+
.6214474419314753,
|
|
4242
|
+
-.008973985167612521
|
|
4243
|
+
],
|
|
4244
|
+
[
|
|
4245
|
+
-.01584149884933386,
|
|
4246
|
+
-.03412293802851557,
|
|
4247
|
+
1.0499644368778496
|
|
4248
|
+
]
|
|
4249
|
+
]
|
|
4250
|
+
});
|
|
4251
|
+
Object.assign(WHITES, {
|
|
4252
|
+
A: [
|
|
4253
|
+
1.0985,
|
|
4254
|
+
1,
|
|
4255
|
+
.35585
|
|
4256
|
+
],
|
|
4257
|
+
C: [
|
|
4258
|
+
.98074,
|
|
4259
|
+
1,
|
|
4260
|
+
1.18232
|
|
4261
|
+
],
|
|
4262
|
+
D55: [
|
|
4263
|
+
.95682,
|
|
4264
|
+
1,
|
|
4265
|
+
.92149
|
|
4266
|
+
],
|
|
4267
|
+
D75: [
|
|
4268
|
+
.94972,
|
|
4269
|
+
1,
|
|
4270
|
+
1.22638
|
|
4271
|
+
],
|
|
4272
|
+
E: [
|
|
4273
|
+
1,
|
|
4274
|
+
1,
|
|
4275
|
+
1
|
|
4276
|
+
],
|
|
4277
|
+
F2: [
|
|
4278
|
+
.99186,
|
|
4279
|
+
1,
|
|
4280
|
+
.67393
|
|
4281
|
+
],
|
|
4282
|
+
F7: [
|
|
4283
|
+
.95041,
|
|
4284
|
+
1,
|
|
4285
|
+
1.08747
|
|
4286
|
+
],
|
|
4287
|
+
F11: [
|
|
4288
|
+
1.00962,
|
|
4289
|
+
1,
|
|
4290
|
+
.6435
|
|
4291
|
+
]
|
|
4292
|
+
});
|
|
4293
|
+
WHITES.ACES = [
|
|
4294
|
+
.32168 / .33767,
|
|
4295
|
+
1,
|
|
4296
|
+
.34065 / .33767
|
|
4297
|
+
];
|
|
4298
|
+
var ACEScg = new RGBColorSpace({
|
|
4299
|
+
id: "acescg",
|
|
4300
|
+
cssId: "--acescg",
|
|
4301
|
+
name: "ACEScg",
|
|
4302
|
+
coords: {
|
|
4303
|
+
r: {
|
|
4304
|
+
range: [0, 65504],
|
|
4305
|
+
name: "Red"
|
|
4306
|
+
},
|
|
4307
|
+
g: {
|
|
4308
|
+
range: [0, 65504],
|
|
4309
|
+
name: "Green"
|
|
4310
|
+
},
|
|
4311
|
+
b: {
|
|
4312
|
+
range: [0, 65504],
|
|
4313
|
+
name: "Blue"
|
|
4314
|
+
}
|
|
4315
|
+
},
|
|
4316
|
+
referred: "scene",
|
|
4317
|
+
white: WHITES.ACES,
|
|
4318
|
+
toXYZ_M: [
|
|
4319
|
+
[
|
|
4320
|
+
.6624541811085053,
|
|
4321
|
+
.13400420645643313,
|
|
4322
|
+
.1561876870049078
|
|
4323
|
+
],
|
|
4324
|
+
[
|
|
4325
|
+
.27222871678091454,
|
|
4326
|
+
.6740817658111484,
|
|
4327
|
+
.05368951740793705
|
|
4328
|
+
],
|
|
4329
|
+
[
|
|
4330
|
+
-.005574649490394108,
|
|
4331
|
+
.004060733528982826,
|
|
4332
|
+
1.0103391003129971
|
|
4333
|
+
]
|
|
4334
|
+
],
|
|
4335
|
+
fromXYZ_M: [
|
|
4336
|
+
[
|
|
4337
|
+
1.6410233796943257,
|
|
4338
|
+
-.32480329418479,
|
|
4339
|
+
-.23642469523761225
|
|
4340
|
+
],
|
|
4341
|
+
[
|
|
4342
|
+
-.6636628587229829,
|
|
4343
|
+
1.6153315916573379,
|
|
4344
|
+
.016756347685530137
|
|
4345
|
+
],
|
|
4346
|
+
[
|
|
4347
|
+
.011721894328375376,
|
|
4348
|
+
-.008284441996237409,
|
|
4349
|
+
.9883948585390215
|
|
4350
|
+
]
|
|
4351
|
+
]
|
|
4352
|
+
});
|
|
4353
|
+
var ε = 2 ** -16;
|
|
4354
|
+
var ACES_min_nonzero = -.35828683;
|
|
4355
|
+
var ACES_cc_max = (Math.log2(65504) + 9.72) / 17.52;
|
|
4356
|
+
var acescc = new RGBColorSpace({
|
|
4357
|
+
id: "acescc",
|
|
4358
|
+
cssId: "--acescc",
|
|
4359
|
+
name: "ACEScc",
|
|
4360
|
+
coords: {
|
|
4361
|
+
r: {
|
|
4362
|
+
range: [ACES_min_nonzero, ACES_cc_max],
|
|
4363
|
+
name: "Red"
|
|
4364
|
+
},
|
|
4365
|
+
g: {
|
|
4366
|
+
range: [ACES_min_nonzero, ACES_cc_max],
|
|
4367
|
+
name: "Green"
|
|
4368
|
+
},
|
|
4369
|
+
b: {
|
|
4370
|
+
range: [ACES_min_nonzero, ACES_cc_max],
|
|
4371
|
+
name: "Blue"
|
|
4372
|
+
}
|
|
4373
|
+
},
|
|
4374
|
+
referred: "scene",
|
|
4375
|
+
base: ACEScg,
|
|
4376
|
+
toBase(RGB) {
|
|
4377
|
+
const low = -5.279999999999999 / 17.52;
|
|
4378
|
+
return RGB.map(function(val) {
|
|
4379
|
+
if (val <= low) return (2 ** (val * 17.52 - 9.72) - ε) * 2;
|
|
4380
|
+
else if (val < ACES_cc_max) return 2 ** (val * 17.52 - 9.72);
|
|
4381
|
+
else return 65504;
|
|
4382
|
+
});
|
|
4383
|
+
},
|
|
4384
|
+
fromBase(RGB) {
|
|
4385
|
+
return RGB.map(function(val) {
|
|
4386
|
+
if (val <= 0) return (Math.log2(ε) + 9.72) / 17.52;
|
|
4387
|
+
else if (val < ε) return (Math.log2(ε + val * .5) + 9.72) / 17.52;
|
|
4388
|
+
else return (Math.log2(val) + 9.72) / 17.52;
|
|
4389
|
+
});
|
|
4390
|
+
}
|
|
4391
|
+
});
|
|
4392
|
+
var spaces = /* @__PURE__ */ Object.freeze({
|
|
4393
|
+
__proto__: null,
|
|
4394
|
+
A98RGB: a98rgb,
|
|
4395
|
+
A98RGB_Linear: A98Linear,
|
|
4396
|
+
ACEScc: acescc,
|
|
4397
|
+
ACEScg,
|
|
4398
|
+
CAM16_JMh: cam16,
|
|
4399
|
+
HCT: hct,
|
|
4400
|
+
HPLuv: hpluv,
|
|
4401
|
+
HSL,
|
|
4402
|
+
HSLuv: hsluv,
|
|
4403
|
+
HSV,
|
|
4404
|
+
HWB: hwb,
|
|
4405
|
+
ICTCP: ictcp,
|
|
4406
|
+
JzCzHz: jzczhz,
|
|
4407
|
+
Jzazbz,
|
|
4408
|
+
LCH: lch,
|
|
4409
|
+
LCHuv,
|
|
4410
|
+
Lab: lab,
|
|
4411
|
+
Lab_D65: lab_d65,
|
|
4412
|
+
Luv,
|
|
4413
|
+
OKLCH: oklch,
|
|
4414
|
+
OKLab,
|
|
4415
|
+
P3,
|
|
4416
|
+
P3_Linear: P3Linear,
|
|
4417
|
+
ProPhoto: prophoto,
|
|
4418
|
+
ProPhoto_Linear: ProPhotoLinear,
|
|
4419
|
+
REC_2020: REC2020,
|
|
4420
|
+
REC_2020_Linear: REC2020Linear,
|
|
4421
|
+
REC_2100_HLG: rec2100Hlg,
|
|
4422
|
+
REC_2100_PQ: rec2100Pq,
|
|
4423
|
+
XYZ_ABS_D65: XYZ_Abs_D65,
|
|
4424
|
+
XYZ_D50,
|
|
4425
|
+
XYZ_D65: xyz_d65,
|
|
4426
|
+
sRGB,
|
|
4427
|
+
sRGB_Linear: sRGBLinear
|
|
4428
|
+
});
|
|
4429
|
+
var Color = class Color {
|
|
4430
|
+
constructor(...args) {
|
|
4431
|
+
let color;
|
|
4432
|
+
if (args.length === 1) color = getColor(args[0]);
|
|
4433
|
+
let space, coords, alpha;
|
|
4434
|
+
if (color) {
|
|
4435
|
+
space = color.space || color.spaceId;
|
|
4436
|
+
coords = color.coords;
|
|
4437
|
+
alpha = color.alpha;
|
|
4438
|
+
} else [space, coords, alpha] = args;
|
|
4439
|
+
Object.defineProperty(this, "space", {
|
|
4440
|
+
value: ColorSpace.get(space),
|
|
4441
|
+
writable: false,
|
|
4442
|
+
enumerable: true,
|
|
4443
|
+
configurable: true
|
|
4444
|
+
});
|
|
4445
|
+
this.coords = coords ? coords.slice() : [
|
|
4446
|
+
0,
|
|
4447
|
+
0,
|
|
4448
|
+
0
|
|
4449
|
+
];
|
|
4450
|
+
this.alpha = alpha > 1 || alpha === void 0 ? 1 : alpha < 0 ? 0 : alpha;
|
|
4451
|
+
for (let i = 0; i < this.coords.length; i++) if (this.coords[i] === "NaN") this.coords[i] = NaN;
|
|
4452
|
+
for (let id in this.space.coords) Object.defineProperty(this, id, {
|
|
4453
|
+
get: () => this.get(id),
|
|
4454
|
+
set: (value) => this.set(id, value)
|
|
4455
|
+
});
|
|
4456
|
+
}
|
|
4457
|
+
get spaceId() {
|
|
4458
|
+
return this.space.id;
|
|
4459
|
+
}
|
|
4460
|
+
clone() {
|
|
4461
|
+
return new Color(this.space, this.coords, this.alpha);
|
|
4462
|
+
}
|
|
4463
|
+
toJSON() {
|
|
4464
|
+
return {
|
|
4465
|
+
spaceId: this.spaceId,
|
|
4466
|
+
coords: this.coords,
|
|
4467
|
+
alpha: this.alpha
|
|
4468
|
+
};
|
|
4469
|
+
}
|
|
4470
|
+
display(...args) {
|
|
4471
|
+
let ret = display(this, ...args);
|
|
4472
|
+
ret.color = new Color(ret.color);
|
|
4473
|
+
return ret;
|
|
4474
|
+
}
|
|
4475
|
+
static get(color, ...args) {
|
|
4476
|
+
if (color instanceof Color) return color;
|
|
4477
|
+
return new Color(color, ...args);
|
|
4478
|
+
}
|
|
4479
|
+
static defineFunction(name, code, o = code) {
|
|
4480
|
+
let { instance = true, returns } = o;
|
|
4481
|
+
let func = function(...args) {
|
|
4482
|
+
let ret = code(...args);
|
|
4483
|
+
if (returns === "color") ret = Color.get(ret);
|
|
4484
|
+
else if (returns === "function<color>") {
|
|
4485
|
+
let f = ret;
|
|
4486
|
+
ret = function(...args$1) {
|
|
4487
|
+
let ret$1 = f(...args$1);
|
|
4488
|
+
return Color.get(ret$1);
|
|
4489
|
+
};
|
|
4490
|
+
Object.assign(ret, f);
|
|
4491
|
+
} else if (returns === "array<color>") ret = ret.map((c$1) => Color.get(c$1));
|
|
4492
|
+
return ret;
|
|
4493
|
+
};
|
|
4494
|
+
if (!(name in Color)) Color[name] = func;
|
|
4495
|
+
if (instance) Color.prototype[name] = function(...args) {
|
|
4496
|
+
return func(this, ...args);
|
|
4497
|
+
};
|
|
4498
|
+
}
|
|
4499
|
+
static defineFunctions(o) {
|
|
4500
|
+
for (let name in o) Color.defineFunction(name, o[name], o[name]);
|
|
4501
|
+
}
|
|
4502
|
+
static extend(exports) {
|
|
4503
|
+
if (exports.register) exports.register(Color);
|
|
4504
|
+
else for (let name in exports) Color.defineFunction(name, exports[name]);
|
|
4505
|
+
}
|
|
4506
|
+
};
|
|
4507
|
+
Color.defineFunctions({
|
|
4508
|
+
get,
|
|
4509
|
+
getAll,
|
|
4510
|
+
set,
|
|
4511
|
+
setAll,
|
|
4512
|
+
to,
|
|
4513
|
+
equals,
|
|
4514
|
+
inGamut,
|
|
4515
|
+
toGamut,
|
|
4516
|
+
distance,
|
|
4517
|
+
toString: serialize
|
|
4518
|
+
});
|
|
4519
|
+
Object.assign(Color, {
|
|
4520
|
+
util,
|
|
4521
|
+
hooks,
|
|
4522
|
+
WHITES,
|
|
4523
|
+
Space: ColorSpace,
|
|
4524
|
+
spaces: ColorSpace.registry,
|
|
4525
|
+
parse,
|
|
4526
|
+
defaults
|
|
4527
|
+
});
|
|
4528
|
+
for (let key of Object.keys(spaces)) ColorSpace.register(spaces[key]);
|
|
4529
|
+
for (let id in ColorSpace.registry) addSpaceAccessors(id, ColorSpace.registry[id]);
|
|
4530
|
+
hooks.add("colorspace-init-end", (space) => {
|
|
4531
|
+
addSpaceAccessors(space.id, space);
|
|
4532
|
+
space.aliases?.forEach((alias) => {
|
|
4533
|
+
addSpaceAccessors(alias, space);
|
|
4534
|
+
});
|
|
4535
|
+
});
|
|
4536
|
+
function addSpaceAccessors(id, space) {
|
|
4537
|
+
let propId = id.replace(/-/g, "_");
|
|
4538
|
+
Object.defineProperty(Color.prototype, propId, {
|
|
4539
|
+
get() {
|
|
4540
|
+
let ret = this.getAll(id);
|
|
4541
|
+
if (typeof Proxy === "undefined") return ret;
|
|
4542
|
+
return new Proxy(ret, {
|
|
4543
|
+
has: (obj, property) => {
|
|
4544
|
+
try {
|
|
4545
|
+
ColorSpace.resolveCoord([space, property]);
|
|
4546
|
+
return true;
|
|
4547
|
+
} catch (e) {}
|
|
4548
|
+
return Reflect.has(obj, property);
|
|
4549
|
+
},
|
|
4550
|
+
get: (obj, property, receiver) => {
|
|
4551
|
+
if (property && typeof property !== "symbol" && !(property in obj)) {
|
|
4552
|
+
let { index } = ColorSpace.resolveCoord([space, property]);
|
|
4553
|
+
if (index >= 0) return obj[index];
|
|
4554
|
+
}
|
|
4555
|
+
return Reflect.get(obj, property, receiver);
|
|
4556
|
+
},
|
|
4557
|
+
set: (obj, property, value, receiver) => {
|
|
4558
|
+
if (property && typeof property !== "symbol" && !(property in obj) || property >= 0) {
|
|
4559
|
+
let { index } = ColorSpace.resolveCoord([space, property]);
|
|
4560
|
+
if (index >= 0) {
|
|
4561
|
+
obj[index] = value;
|
|
4562
|
+
this.setAll(id, obj);
|
|
4563
|
+
return true;
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4566
|
+
return Reflect.set(obj, property, value, receiver);
|
|
4567
|
+
}
|
|
4568
|
+
});
|
|
4569
|
+
},
|
|
4570
|
+
set(coords) {
|
|
4571
|
+
this.setAll(id, coords);
|
|
4572
|
+
},
|
|
4573
|
+
configurable: true,
|
|
4574
|
+
enumerable: true
|
|
4575
|
+
});
|
|
4576
|
+
}
|
|
4577
|
+
Color.extend(deltaEMethods);
|
|
4578
|
+
Color.extend({ deltaE });
|
|
4579
|
+
Object.assign(Color, { deltaEMethods });
|
|
4580
|
+
Color.extend(variations);
|
|
4581
|
+
Color.extend({ contrast });
|
|
4582
|
+
Color.extend(chromaticity);
|
|
4583
|
+
Color.extend(luminance);
|
|
4584
|
+
Color.extend(interpolation);
|
|
4585
|
+
Color.extend(contrastMethods);
|
|
4586
|
+
var { vec2: vec2$1, vec4: vec4$1 } = TSL;
|
|
4587
|
+
const transformColor = (value) => {
|
|
4588
|
+
const threeColor = new Color(value);
|
|
4589
|
+
const coords = threeColor.to("p3-linear").coords;
|
|
4590
|
+
const r = coords[0], g$1 = coords[1], b$2 = coords[2], a$1 = threeColor.alpha;
|
|
4591
|
+
return {
|
|
4592
|
+
node: vec4$1(r, g$1, b$2, a$1),
|
|
4593
|
+
data: new Vector4(r, g$1, b$2, a$1)
|
|
4594
|
+
};
|
|
4595
|
+
};
|
|
4596
|
+
const transformPosition = (value) => {
|
|
4597
|
+
let x = .5;
|
|
4598
|
+
let y = .5;
|
|
4599
|
+
const parsePositionValue = (val, isVertical = false) => {
|
|
4600
|
+
if (typeof val === "number") return val;
|
|
4601
|
+
const str = val.toLowerCase().trim();
|
|
4602
|
+
if (isVertical) {
|
|
4603
|
+
if (str === "top") return 0;
|
|
4604
|
+
if (str === "bottom") return 1;
|
|
4605
|
+
if (str === "center") return .5;
|
|
4606
|
+
} else {
|
|
4607
|
+
if (str === "left") return 0;
|
|
4608
|
+
if (str === "right") return 1;
|
|
4609
|
+
if (str === "center") return .5;
|
|
4610
|
+
}
|
|
4611
|
+
console.warn(`Invalid position value: ${val}. Defaulting to center.`);
|
|
4612
|
+
return .5;
|
|
4613
|
+
};
|
|
4614
|
+
if (typeof value === "string") {
|
|
4615
|
+
const parts = value.toLowerCase().trim().split(/\s+/);
|
|
4616
|
+
if (parts.includes("left")) x = 0;
|
|
4617
|
+
else if (parts.includes("right")) x = 1;
|
|
4618
|
+
else if (parts.includes("center") || parts.length === 1 && (parts[0] === "top" || parts[0] === "bottom")) x = .5;
|
|
4619
|
+
if (parts.includes("top")) y = 0;
|
|
4620
|
+
else if (parts.includes("bottom")) y = 1;
|
|
4621
|
+
else if (parts.includes("center") || parts.length === 1 && (parts[0] === "left" || parts[0] === "right")) y = .5;
|
|
4622
|
+
if (parts.length === 1 && parts[0] === "center") {
|
|
4623
|
+
x = .5;
|
|
4624
|
+
y = .5;
|
|
4625
|
+
}
|
|
4626
|
+
} else if (typeof value === "object" && value !== null) {
|
|
4627
|
+
x = parsePositionValue(value.x, false);
|
|
4628
|
+
y = parsePositionValue(value.y, true);
|
|
4629
|
+
} else console.warn(`Invalid position value provided: ${value}. Defaulting to center.`);
|
|
4630
|
+
const finalY = 1 - y;
|
|
4631
|
+
return {
|
|
4632
|
+
node: vec2$1(x, finalY),
|
|
4633
|
+
data: new Vector2(x, finalY)
|
|
4634
|
+
};
|
|
4635
|
+
};
|
|
4636
|
+
const transformAngle = (value) => {
|
|
4637
|
+
if (typeof value === "number") return (value % 360 + 360) % 360;
|
|
4638
|
+
const str = value.toLowerCase().trim();
|
|
4639
|
+
switch (str) {
|
|
4640
|
+
case "to right": return 0;
|
|
4641
|
+
case "to bottom": return 90;
|
|
4642
|
+
case "to left": return 180;
|
|
4643
|
+
case "to top": return 270;
|
|
4644
|
+
case "to bottom right":
|
|
4645
|
+
case "to right bottom": return 45;
|
|
4646
|
+
case "to bottom left":
|
|
4647
|
+
case "to left bottom": return 135;
|
|
4648
|
+
case "to top left":
|
|
4649
|
+
case "to left top": return 225;
|
|
4650
|
+
case "to top right":
|
|
4651
|
+
case "to right top": return 315;
|
|
4652
|
+
case "from left": return 0;
|
|
4653
|
+
case "from top": return 90;
|
|
4654
|
+
case "from right": return 180;
|
|
4655
|
+
case "from bottom": return 270;
|
|
4656
|
+
case "from top left": return 45;
|
|
4657
|
+
case "from top right": return 135;
|
|
4658
|
+
case "from bottom right": return 225;
|
|
4659
|
+
case "from bottom left": return 315;
|
|
4660
|
+
default:
|
|
4661
|
+
const numMatch = str.match(/^(-?\d*\.?\d+)(deg|rad|turn)?$/);
|
|
4662
|
+
if (numMatch) {
|
|
4663
|
+
const [, valueStr, unit = "deg"] = numMatch;
|
|
4664
|
+
const numValue = parseFloat(valueStr);
|
|
4665
|
+
switch (unit) {
|
|
4666
|
+
case "deg": return (numValue % 360 + 360) % 360;
|
|
4667
|
+
case "rad": return (numValue * 180 / Math.PI % 360 + 360) % 360;
|
|
4668
|
+
case "turn": return (numValue * 360 % 360 + 360) % 360;
|
|
4669
|
+
default: return (numValue % 360 + 360) % 360;
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
console.warn(`Invalid angle value: ${value}. Defaulting to 0 degrees.`);
|
|
4673
|
+
return 0;
|
|
4674
|
+
}
|
|
4675
|
+
};
|
|
4676
|
+
const transformEdges = (value) => {
|
|
4677
|
+
const mode = {
|
|
4678
|
+
"stretch": 0,
|
|
4679
|
+
"transparent": 1,
|
|
4680
|
+
"mirror": 2,
|
|
4681
|
+
"wrap": 3
|
|
4682
|
+
}[value.toLowerCase()];
|
|
4683
|
+
if (mode === void 0) {
|
|
4684
|
+
console.warn(`Invalid edge mode: ${value}. Defaulting to 'stretch'.`);
|
|
4685
|
+
return 0;
|
|
4686
|
+
}
|
|
4687
|
+
return mode;
|
|
4688
|
+
};
|
|
4689
|
+
const colorSpaceOptions = [
|
|
4690
|
+
{
|
|
4691
|
+
label: "Linear RGB",
|
|
4692
|
+
value: "linear"
|
|
4693
|
+
},
|
|
4694
|
+
{
|
|
4695
|
+
label: "OKLCh",
|
|
4696
|
+
value: "oklch"
|
|
4697
|
+
},
|
|
4698
|
+
{
|
|
4699
|
+
label: "OKLAB",
|
|
4700
|
+
value: "oklab"
|
|
4701
|
+
}
|
|
4702
|
+
];
|
|
4703
|
+
const transformColorSpace = (value) => {
|
|
4704
|
+
const mode = {
|
|
4705
|
+
"linear": 0,
|
|
4706
|
+
"oklch": 1,
|
|
4707
|
+
"oklab": 2
|
|
4708
|
+
}[value.toLowerCase()];
|
|
4709
|
+
if (mode === void 0) {
|
|
4710
|
+
console.warn(`Invalid color space mode: ${value}. Defaulting to 'linear'.`);
|
|
4711
|
+
return 0;
|
|
4712
|
+
}
|
|
4713
|
+
return mode;
|
|
4714
|
+
};
|
|
4715
|
+
export { transformEdges as a, transformColorSpace as i, transformAngle as n, transformPosition as o, transformColor as r, colorSpaceOptions as t };
|