@sardine/colour 1.0.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/CIEDE2000.d.ts +12 -0
- package/dist/CIEDE2000.js +1 -68
- package/dist/CIEDE2000.js.map +1 -1
- package/dist/RGBdistance.d.ts +2 -0
- package/dist/RGBdistance.js +1 -8
- package/dist/RGBdistance.js.map +1 -1
- package/dist/cjs/CIEDE2000.js +2 -0
- package/dist/cjs/CIEDE2000.js.map +1 -0
- package/dist/cjs/RGBdistance.js +2 -0
- package/dist/cjs/RGBdistance.js.map +1 -0
- package/dist/cjs/converters.js +2 -0
- package/dist/cjs/converters.js.map +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/util/index.js +2 -0
- package/dist/cjs/util/index.js.map +1 -0
- package/dist/converters.d.ts +24 -0
- package/dist/converters.js +1 -55
- package/dist/converters.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +45 -0
- package/dist/util/index.d.ts +38 -0
- package/dist/util/index.js +1 -92
- package/dist/util/index.js.map +1 -1
- package/package.json +19 -12
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/umd/index.js +0 -1
- package/dist/umd/index.js.map +0 -1
- package/dist/umd/index.umd.js +0 -3
- package/dist/umd/index.umd.js.map +0 -1
package/README.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LabColour } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Mesures the colour difference between two colours in the Lab space
|
|
4
|
+
*
|
|
5
|
+
* Math taken from:
|
|
6
|
+
*
|
|
7
|
+
* https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
|
|
8
|
+
* http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
|
|
9
|
+
* @param colour1 First colour to be compared
|
|
10
|
+
* @param colour2 First colour to be compared
|
|
11
|
+
*/
|
|
12
|
+
export declare function ciede2000(colour1: LabColour, colour2: LabColour): number;
|
package/dist/CIEDE2000.js
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* Mesures the colour difference between two colours in the Lab space
|
|
4
|
-
*
|
|
5
|
-
* Math taken from:
|
|
6
|
-
*
|
|
7
|
-
* https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
|
|
8
|
-
* http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
|
|
9
|
-
* @param colour1 First colour to be compared
|
|
10
|
-
* @param colour2 First colour to be compared
|
|
11
|
-
*/ export function ciede2000(colour1, colour2) {
|
|
12
|
-
/**
|
|
13
|
-
* Glossary
|
|
14
|
-
* L - Lightness as defined by L*a*b*
|
|
15
|
-
* a - Describes the green–red opponent colors as defined by L*a*b*
|
|
16
|
-
* b - Describes the blue–yellow opponent colors as defined by L*a*b*
|
|
17
|
-
* C - Chroma as defined by CIE94
|
|
18
|
-
*
|
|
19
|
-
* Math notation
|
|
20
|
-
* _d - Derivative
|
|
21
|
-
* Δ - Difference between values
|
|
22
|
-
* ̅ - Mean value
|
|
23
|
-
*/ /** Lightness for colour 1 */ const L1 = colour1.L;
|
|
24
|
-
/** green–red colour opponent for colour 1 */ const a1 = colour1.a;
|
|
25
|
-
/** blue–yellow colour opponent for colour 1 */ const b1 = colour1.b;
|
|
26
|
-
/** Lightness for colour 2 */ const L2 = colour2.L;
|
|
27
|
-
/** green–red colour opponent for colour 1 */ const a2 = colour2.a;
|
|
28
|
-
/** blue–yellow colour opponent for colour 1 */ const b2 = colour2.b;
|
|
29
|
-
/** Weighting factor for Luminance */ const kL = 1;
|
|
30
|
-
/** Weighting factor for Chroma */ const kC = 1;
|
|
31
|
-
/** Weighting factor for Hue */ const kH = 1;
|
|
32
|
-
/** Chroma for colour 1 */ const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));
|
|
33
|
-
/** Chroma for colour 2 */ const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));
|
|
34
|
-
/** Derivative of the Lightness difference */ const ΔL_d = L2 - L1;
|
|
35
|
-
/** Chroma mean value */ const C̅ = (C1 + C2) / 2;
|
|
36
|
-
const G = 0.5 * (1 - bigSquare(C̅));
|
|
37
|
-
/** Derivative of a1 */ const a1_d = a1 * (1 + G);
|
|
38
|
-
/** Derivative of a2 */ const a2_d = a2 * (1 + G);
|
|
39
|
-
/** Derivative of C1 */ const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));
|
|
40
|
-
/** Derivative of C2 */ const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));
|
|
41
|
-
/** Derivative of Chroma mean */ const C̅_d = (C1_d + C2_d) / 2;
|
|
42
|
-
/** Derivative of the mean difference of Chroma */ const ΔC̅_d = C2_d - C1_d;
|
|
43
|
-
/** Derivative of colour 1 Hue */ const h1_d = hue_d(b1, a1_d);
|
|
44
|
-
/** Derivative of colour 2 Hue */ const h2_d = hue_d(b2, a2_d);
|
|
45
|
-
/** Hue difference */ const Δh_d = deltaHue_d({
|
|
46
|
-
C1,
|
|
47
|
-
C2,
|
|
48
|
-
h1_d,
|
|
49
|
-
h2_d
|
|
50
|
-
});
|
|
51
|
-
const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);
|
|
52
|
-
/** Derivative of mean hue */ const H̅_d = meanHue_d({
|
|
53
|
-
C1,
|
|
54
|
-
C2,
|
|
55
|
-
h1_d,
|
|
56
|
-
h2_d
|
|
57
|
-
});
|
|
58
|
-
/** Lightness Mean value*/ const L̅ = (L1 + L2) / 2;
|
|
59
|
-
/** Compensation for neutral colors (the primed values in the L*C*h differences) */ const T = 1 - 0.17 * Math.cos(toRadians(H̅_d - 30)) + 0.24 * Math.cos(toRadians(2 * H̅_d)) + 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) - 0.2 * Math.cos(toRadians(4 * H̅_d - 63));
|
|
60
|
-
/** Compensation for lightness */ const SL = 1 + 0.015 * Math.pow(L̅ - 50, 2) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));
|
|
61
|
-
/** Compensation for chroma */ const SC = 0.045 * C̅_d + 1;
|
|
62
|
-
/** Compensation for hue */ const SH = 1 + 0.015 * C̅_d * T;
|
|
63
|
-
const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));
|
|
64
|
-
/** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */ const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));
|
|
65
|
-
/** Colour difference */ const ΔE = Math.sqrt(Math.pow(ΔL_d / (kL * SL), 2) + Math.pow(ΔC̅_d / (kC * SC), 2) + Math.pow(ΔH_d / (kH * SH), 2) + RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH)));
|
|
66
|
-
return ΔE;
|
|
67
|
-
}
|
|
68
|
-
|
|
1
|
+
import{bigSquare as a,deltaHue_d as b,hue_d as c,meanHue_d as d,toRadians as e}from"./util/index.js";export function ciede2000(f,g){let h=f.L,i=f.a,j=f.b,k=g.L,l=g.a,m=g.b,n=Math.sqrt(Math.pow(i,2)+Math.pow(j,2)),o=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),p=.5*(1-a((n+o)/2)),q=i*(1+p),r=l*(1+p),s=Math.sqrt(Math.pow(q,2)+Math.pow(j,2)),t=Math.sqrt(Math.pow(r,2)+Math.pow(m,2)),u=(s+t)/2,v=t-s,w=c(j,q),x=c(m,r),y=b({C1:n,C2:o,h1_d:w,h2_d:x}),z=2*Math.sqrt(s*t)*Math.sin(e(y)/2),A=d({C1:n,C2:o,h1_d:w,h2_d:x}),B=(h+k)/2,C=1-.17*Math.cos(e(A-30))+.24*Math.cos(e(2*A))+.32*Math.cos(e(3*A+6))-.2*Math.cos(e(4*A-63)),D=.045*u+1,E=1+.015*u*C,F=-2*a(u)*Math.sin(e(2*(30*Math.exp(-Math.pow((A-275)/25,2)))));return Math.sqrt(Math.pow((k-h)/(1*(1+.015*Math.pow(B-50,2)/Math.sqrt(20+Math.pow(B-50,2)))),2)+Math.pow(v/(1*D),2)+Math.pow(z/(1*E),2)+F*(v/(1*D))*(z/(1*E)))}
|
|
69
2
|
//# sourceMappingURL=CIEDE2000.js.map
|
package/dist/CIEDE2000.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/CIEDE2000.ts"],"sourcesContent":["import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n"],"names":["bigSquare","deltaHue_d","hue_d","meanHue_d","toRadians","ciede2000","colour1","colour2","L1","L","a1","a","b1","b","L2","a2","b2","
|
|
1
|
+
{"version":3,"sources":["../src/CIEDE2000.ts"],"sourcesContent":["import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n"],"names":["bigSquare","deltaHue_d","hue_d","meanHue_d","toRadians","ciede2000","colour1","colour2","L1","L","a1","a","b1","b","L2","a2","b2","C1","Math","sqrt","pow","C2","G","a1_d","a2_d","C1_d","C2_d","C̅_d","ΔC̅_d","h1_d","h2_d","Δh_d","ΔH_d","sin","H̅_d","L̅","T","cos","SC","SH","RT","rotation","exp","ΔL_d","kL","kC","kH"],"mappings":"AAAA,OAASA,SAAS,IAATA,CAAS,CAAEC,UAAU,IAAVA,CAAU,CAAEC,KAAK,IAALA,CAAK,CAAEC,SAAS,IAATA,CAAS,CAAEC,SAAS,IAATA,CAAS,KAAQ,iBAAiB,AAAC,AAarF,QAAO,SAASC,SAAS,CAACC,CAAkB,CAAEC,CAAkB,CAAU,CAexE,IAAMC,CAAE,CAAGF,CAAO,CAACG,CAAC,CAGdC,CAAE,CAAGJ,CAAO,CAACK,CAAC,CAGdC,CAAE,CAAGN,CAAO,CAACO,CAAC,CAGdC,CAAE,CAAGP,CAAO,CAACE,CAAC,CAGdM,CAAE,CAAGR,CAAO,CAACI,CAAC,CAGdK,CAAE,CAAGT,CAAO,CAACM,CAAC,CAYdI,CAAE,CAAGC,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AAC,CAAA,AAGE,CAAC,CAAC,AAhG9C,AA0GrB,QAPWhB,IAAI,CAACC,IAAI,CAClBD,IAAI,CAACE,GAAG,CAACuB,AAnEE7B,CAAAA,CAAE,CAAGN,CAAE,CAAA,CAmEDoC,CAAAA,AAlFR,CAAC,CAmEV,CAAA,CAAC,CAAG,AAAC,IAAK,CAAG1B,IAAI,CAACE,GAAG,CAACe,CAAE,CAAG,EAAE,CAAE,CAAC,CAAC,CAAIjB,IAAI,CAACC,IAAI,CAAC,EAAE,CAAGD,IAAI,CAACE,GAAG,CAACe,CAAE,CAAG,EAAE,CAAE,CAAC,CAAC,CAAC,CAAA,AAejD,CAAA,AAAC,CAAE,CAAC,CAAC,CAC3BjB,IAAI,CAACE,GAAG,CAACQ,CAAK,CAAIiB,CAAAA,AAhFX,CAAC,CAgFeP,CAAE,CAAA,AAAC,CAAE,CAAC,CAAC,CAC9BpB,IAAI,CAACE,GAAG,CAACY,CAAI,CAAIc,CAAAA,AA9EV,CAAC,CA8EcP,CAAE,CAAA,AAAC,CAAE,CAAC,CAAC,CAC7BC,CAAE,CAAIZ,CAAAA,CAAK,CAAIiB,CAAAA,AAlFR,CAAC,CAkFYP,CAAE,CAAA,AAAC,CAAA,CAAKN,CAAAA,CAAI,CAAIc,CAAAA,AA/E7B,CAAC,CA+EiCP,CAAE,CAAA,AAAC,CAAA,AAAC,CAChD,AAES,CACX"}
|
package/dist/RGBdistance.js
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { convertRGBtoLab } from "./converters.js";
|
|
3
|
-
export const RGBdistance = (colour1, colour2)=>{
|
|
4
|
-
const c1 = convertRGBtoLab(colour1);
|
|
5
|
-
const c2 = convertRGBtoLab(colour2);
|
|
6
|
-
return ciede2000(c1, c2);
|
|
7
|
-
};
|
|
8
|
-
|
|
1
|
+
import{ciede2000 as a}from"./CIEDE2000.js";import{convertRGBtoLab as b}from"./converters.js";export const RGBdistance=(c,d)=>{let e=b(c),f=b(d);return a(e,f)}
|
|
9
2
|
//# sourceMappingURL=RGBdistance.js.map
|
package/dist/RGBdistance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/RGBdistance.ts"],"sourcesContent":["import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n"],"names":["ciede2000","convertRGBtoLab","RGBdistance","colour1","colour2","c1","c2"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/RGBdistance.ts"],"sourcesContent":["import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n"],"names":["ciede2000","convertRGBtoLab","RGBdistance","colour1","colour2","c1","c2"],"mappings":"AAAA,OAASA,SAAS,IAATA,CAAS,KAAQ,gBAAgB,AAAC,AAC3C,QAASC,eAAe,IAAfA,CAAe,KAAQ,iBAAiB,AAAC,AAGlD,QAAO,MAAMC,WAAW,CAAG,CAACC,CAAkB,CAAEC,CAAkB,GAAa,CAC7E,IAAMC,CAAE,CAAGJ,CAAe,CAACE,CAAO,CAAC,CAC7BG,CAAE,CAAGL,CAAe,CAACG,CAAO,CAAC,AADC,AAGpC,QAAOJ,CAAS,CAACK,CAAE,CAAEC,CAAE,CAAC,AAAC,CAC1B,AAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"ciede2000",{enumerable:true,get:()=>ciede2000});const _indexJs=require("./util/index.js");function ciede2000(colour1,colour2){const L1=colour1.L;const a1=colour1.a;const b1=colour1.b;const L2=colour2.L;const a2=colour2.a;const b2=colour2.b;const kL=1;const kC=1;const kH=1;const C1=Math.sqrt(Math.pow(a1,2)+Math.pow(b1,2));const C2=Math.sqrt(Math.pow(a2,2)+Math.pow(b2,2));const ΔL_d=L2-L1;const C̅=(C1+C2)/2;const G=.5*(1-(0,_indexJs.bigSquare)(C̅));const a1_d=a1*(1+G);const a2_d=a2*(1+G);const C1_d=Math.sqrt(Math.pow(a1_d,2)+Math.pow(b1,2));const C2_d=Math.sqrt(Math.pow(a2_d,2)+Math.pow(b2,2));const C̅_d=(C1_d+C2_d)/2;const ΔC̅_d=C2_d-C1_d;const h1_d=(0,_indexJs.hue_d)(b1,a1_d);const h2_d=(0,_indexJs.hue_d)(b2,a2_d);const Δh_d=(0,_indexJs.deltaHue_d)({C1,C2,h1_d,h2_d});const ΔH_d=2*Math.sqrt(C1_d*C2_d)*Math.sin((0,_indexJs.toRadians)(Δh_d)/2);const H̅_d=(0,_indexJs.meanHue_d)({C1,C2,h1_d,h2_d});const L̅=(L1+L2)/2;const T=1-.17*Math.cos((0,_indexJs.toRadians)(H̅_d-30))+.24*Math.cos((0,_indexJs.toRadians)(2*H̅_d))+.32*Math.cos((0,_indexJs.toRadians)(3*H̅_d+6))-.2*Math.cos((0,_indexJs.toRadians)(4*H̅_d-63));const SL=1+.015*Math.pow(L̅-50,2)/Math.sqrt(20+Math.pow(L̅-50,2));const SC=.045*C̅_d+1;const SH=1+.015*C̅_d*T;const rotation=30*Math.exp(-Math.pow((H̅_d-275)/25,2));const RT=-2*(0,_indexJs.bigSquare)(C̅_d)*Math.sin((0,_indexJs.toRadians)(rotation*2));const ΔE=Math.sqrt(Math.pow(ΔL_d/(kL*SL),2)+Math.pow(ΔC̅_d/(kC*SC),2)+Math.pow(ΔH_d/(kH*SH),2)+RT*(ΔC̅_d/(kC*SC))*(ΔH_d/(kH*SH)));return ΔE}
|
|
2
|
+
//# sourceMappingURL=CIEDE2000.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/CIEDE2000.ts"],"sourcesContent":["import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n"],"names":["ciede2000","colour1","colour2","L1","L","a1","a","b1","b","L2","a2","b2","kL","kC","kH","C1","Math","sqrt","pow","C2","ΔL_d","C̅","G","bigSquare","a1_d","a2_d","C1_d","C2_d","C̅_d","ΔC̅_d","h1_d","hue_d","h2_d","Δh_d","deltaHue_d","ΔH_d","sin","toRadians","H̅_d","meanHue_d","L̅","T","cos","SL","SC","SH","rotation","exp","RT","ΔE"],"mappings":"AAAA,oGAagBA,WAAS,0BAATA,SAAS,0BAb0C,iBAAiB,CAa7E,UAASA,SAAS,CAACC,OAAkB,CAAEC,OAAkB,CAAU,CAexE,MAAMC,EAAE,CAAGF,OAAO,CAACG,CAAC,AAAC,AAGrB,OAAMC,EAAE,CAAGJ,OAAO,CAACK,CAAC,AAAC,AAGrB,OAAMC,EAAE,CAAGN,OAAO,CAACO,CAAC,AAAC,AAGrB,OAAMC,EAAE,CAAGP,OAAO,CAACE,CAAC,AAAC,AAGrB,OAAMM,EAAE,CAAGR,OAAO,CAACI,CAAC,AAAC,AAGrB,OAAMK,EAAE,CAAGT,OAAO,CAACM,CAAC,AAAC,AAGrB,OAAMI,EAAE,CAAG,CAAC,AAAC,AAGb,OAAMC,EAAE,CAAG,CAAC,AAAC,AAGb,OAAMC,EAAE,CAAG,CAAC,AAAC,AAGb,OAAMC,EAAE,CAAGC,IAAI,CAACC,IAAI,CAACD,IAAI,CAACE,GAAG,CAACb,EAAE,CAAE,CAAC,CAAC,CAAGW,IAAI,CAACE,GAAG,CAACX,EAAE,CAAE,CAAC,CAAC,CAAC,AAAC,AAGxD,OAAMY,EAAE,CAAGH,IAAI,CAACC,IAAI,CAACD,IAAI,CAACE,GAAG,CAACR,EAAE,CAAE,CAAC,CAAC,CAAGM,IAAI,CAACE,GAAG,CAACP,EAAE,CAAE,CAAC,CAAC,CAAC,AAAC,AAGx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,CAAC/B,IAAI,CAACE,GAAG,CAAC,CAACoB,IAAI,CAAG,GAAG,CAAC,CAAG,EAAE,CAAE,CAAC,CAAC,CAAC,AAAC,AAGhE,OAAMU,EAAE,CAAG,CAAC,CAAC,CAAGzB,GAAAA,QAAS,UAAA,EAACK,IAAI,CAAC,CAAGZ,IAAI,CAACoB,GAAG,CAACC,GAAAA,QAAS,UAAA,EAACS,QAAQ,CAAG,CAAC,CAAC,CAAC,AAAC,AAGpE,OAAMG,EAAE,CAAGjC,IAAI,CAACC,IAAI,CAClBD,IAAI,CAACE,GAAG,CAACE,IAAI,CAAG,CAACR,EAAE,CAAG+B,EAAE,CAAC,CAAE,CAAC,CAAC,CAC3B3B,IAAI,CAACE,GAAG,CAACW,KAAK,CAAG,CAAChB,EAAE,CAAG+B,EAAE,CAAC,CAAE,CAAC,CAAC,CAC9B5B,IAAI,CAACE,GAAG,CAACiB,IAAI,CAAG,CAACrB,EAAE,CAAG+B,EAAE,CAAC,CAAE,CAAC,CAAC,CAC7BG,EAAE,CAAG,CAACnB,KAAK,CAAG,CAAChB,EAAE,CAAG+B,EAAE,CAAC,CAAC,CAAG,CAACT,IAAI,CAAG,CAACrB,EAAE,CAAG+B,EAAE,CAAC,CAAC,CAChD,AAAC,AAEF,QAAOI,EAAE,AAAC,CACX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"RGBdistance",{enumerable:true,get:()=>RGBdistance});const _ciede2000Js=require("./CIEDE2000.js");const _convertersJs=require("./converters.js");const RGBdistance=(colour1,colour2)=>{const c1=(0,_convertersJs.convertRGBtoLab)(colour1);const c2=(0,_convertersJs.convertRGBtoLab)(colour2);return(0,_ciede2000Js.ciede2000)(c1,c2)}
|
|
2
|
+
//# sourceMappingURL=RGBdistance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/RGBdistance.ts"],"sourcesContent":["import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n"],"names":["RGBdistance","colour1","colour2","c1","convertRGBtoLab","c2","ciede2000"],"mappings":"AAAA,oGAIaA,aAAW,0BAAXA,WAAW,8BAJE,gBAAgB,8BACV,iBAAiB,CAG1C,OAAMA,WAAW,CAAG,CAACC,OAAkB,CAAEC,OAAkB,GAAa,CAC7E,MAAMC,EAAE,CAAGC,GAAAA,aAAe,gBAAA,EAACH,OAAO,CAAC,AAAC,AACpC,OAAMI,EAAE,CAAGD,GAAAA,aAAe,gBAAA,EAACF,OAAO,CAAC,AAAC,AAEpC,OAAOI,GAAAA,YAAS,UAAA,EAACH,EAAE,CAAEE,EAAE,CAAC,AAAC,CAC1B,AAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{convertRGBtoXYZ:()=>convertRGBtoXYZ,convertXYZtoLab:()=>convertXYZtoLab,convertRGBtoLab:()=>convertRGBtoLab,convertHextoRGB:()=>convertHextoRGB});const _indexJs=require("./util/index.js");function convertRGBtoXYZ(colour){const{R,G,B}=colour;const _R=(0,_indexJs.linearRGB)(R)*100;const _G=(0,_indexJs.linearRGB)(G)*100;const _B=(0,_indexJs.linearRGB)(B)*100;const X=_R*.4124+_G*.3576+_B*.1805;const Y=_R*.2126+_G*.7152+_B*.0722;const Z=_R*.0193+_G*.1192+_B*.9505;return{X,Y,Z}}function convertXYZtoLab(colour){const{X,Y,Z}=colour;const _X=X/95.047;const _Y=Y/100;const _Z=Z/108.883;const fX=(0,_indexJs.constrainLab)(_X);const fY=(0,_indexJs.constrainLab)(_Y);const fZ=(0,_indexJs.constrainLab)(_Z);const L=116*fY-16;const a=500*(fX-fY);const b=200*(fY-fZ);return{L,a,b}}function convertRGBtoLab(colour){const XYZColour=convertRGBtoXYZ(colour);return convertXYZtoLab(XYZColour)}function convertHextoRGB(hex){const hexRegex=/^#[a-fA-F0-9]{6}$/;const hexAlphaRegex=/^#[a-fA-F0-9]{8}$/;const shortHexRegex=/^#[a-fA-F0-9]{3}$/;const shortAlphaHexRegex=/^#[a-fA-F0-9]{4}$/;if(typeof hex!=="string"){throw new Error(`convertHextoRGB expects a string but got a ${typeof hex}`)}if(hex.match(hexRegex)){return{R:parseInt(`${hex[1]}${hex[2]}`,16),G:parseInt(`${hex[3]}${hex[4]}`,16),B:parseInt(`${hex[5]}${hex[6]}`,16)}}if(hex.match(shortHexRegex)){return{R:parseInt(`${hex[1]}${hex[1]}`,16),G:parseInt(`${hex[2]}${hex[2]}`,16),B:parseInt(`${hex[3]}${hex[3]}`,16)}}if(hex.match(hexAlphaRegex)){return{R:parseInt(`${hex[1]}${hex[2]}`,16),G:parseInt(`${hex[3]}${hex[4]}`,16),B:parseInt(`${hex[5]}${hex[6]}`,16),A:parseInt(`${hex[7]}${hex[8]}`,16)/255}}if(hex.match(shortAlphaHexRegex)){return{R:parseInt(`${hex[1]}${hex[1]}`,16),G:parseInt(`${hex[2]}${hex[2]}`,16),B:parseInt(`${hex[3]}${hex[3]}`,16),A:parseInt(`${hex[4]}${hex[4]}`,16)/255}}throw new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${hex}`)}
|
|
2
|
+
//# sourceMappingURL=converters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/converters.ts"],"sourcesContent":["import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n\nexport function convertHextoRGB(hex: string): RGBColour {\n /** Six digit Hexadecimal colour, ie: #12FF21 */\n const hexRegex = /^#[a-fA-F0-9]{6}$/;\n /** Eight digit Hexadecimal colour, ie: #12FF21BE */\n const hexAlphaRegex = /^#[a-fA-F0-9]{8}$/;\n /** Three digit Hexadecimal colour, ie: #FFF */\n const shortHexRegex = /^#[a-fA-F0-9]{3}$/;\n /** Four digit Hexadecimal colour, ie: #FFF4 */\n const shortAlphaHexRegex = /^#[a-fA-F0-9]{4}$/;\n\n if (typeof hex !== \"string\") {\n throw new Error(`convertHextoRGB expects a string but got a ${typeof hex}`);\n }\n\n if (hex.match(hexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[2]}`, 16),\n G: parseInt(`${hex[3]}${hex[4]}`, 16),\n B: parseInt(`${hex[5]}${hex[6]}`, 16),\n };\n }\n\n if (hex.match(shortHexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[1]}`, 16),\n G: parseInt(`${hex[2]}${hex[2]}`, 16),\n B: parseInt(`${hex[3]}${hex[3]}`, 16),\n };\n }\n\n if (hex.match(hexAlphaRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[2]}`, 16),\n G: parseInt(`${hex[3]}${hex[4]}`, 16),\n B: parseInt(`${hex[5]}${hex[6]}`, 16),\n A: parseInt(`${hex[7]}${hex[8]}`, 16) / 255,\n };\n }\n\n if (hex.match(shortAlphaHexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[1]}`, 16),\n G: parseInt(`${hex[2]}${hex[2]}`, 16),\n B: parseInt(`${hex[3]}${hex[3]}`, 16),\n A: parseInt(`${hex[4]}${hex[4]}`, 16) / 255,\n };\n }\n\n throw new Error(\n `convertHextoRGB expects an valid hexadecimal colour value but got ${hex}`\n );\n}\n"],"names":["convertRGBtoXYZ","convertXYZtoLab","convertRGBtoLab","convertHextoRGB","colour","R","G","B","_R","linearRGB","_G","_B","X","Y","Z","_X","_Y","_Z","fX","constrainLab","fY","fZ","L","a","b","XYZColour","hex","hexRegex","hexAlphaRegex","shortHexRegex","shortAlphaHexRegex","Error","match","parseInt","A"],"mappings":"AAAA,2MASgBA,eAAe,KAAfA,eAAe,CAqBfC,eAAe,KAAfA,eAAe,CA0BfC,eAAe,KAAfA,eAAe,CAKfC,eAAe,KAAfA,eAAe,0BA5DS,iBAAiB,CAQlD,UAASH,eAAe,CAACI,MAAiB,CAAa,CAC5D,KAAM,CAAEC,CAAC,CAAEC,CAAC,CAAEC,C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CAAC,CAAC,CAAC,EAAEA,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CACrCpB,CAAC,CAAE2B,QAAQ,CAAC,CAAC,EAAEP,GAAG,CAAC,CAAC,CAAC,CAAC,EAAEA,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CACrCnB,CAAC,CAAE0B,QAAQ,CAAC,CAAC,EAAEP,GAAG,CAAC,CAAC,CAAC,CAAC,EAAEA,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CACrCQ,CAAC,CAAED,QAAQ,CAAC,CAAC,EAAEP,GAAG,CAAC,CAAC,CAAC,CAAC,EAAEA,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAG,GAAG,CAC5C,AAAC,CACH,AAED,MAAM,IAAIK,KAAK,CACb,CAAC,kEAAkE,EAAEL,GAAG,CAAC,CAAC,CAC3E,AAAC,CACH"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{ciede2000:()=>_ciede2000Js.ciede2000,convertHextoRGB:()=>_convertersJs.convertHextoRGB,convertRGBtoLab:()=>_convertersJs.convertRGBtoLab,convertRGBtoXYZ:()=>_convertersJs.convertRGBtoXYZ,convertXYZtoLab:()=>_convertersJs.convertXYZtoLab,RGBdistance:()=>_rgbdistanceJs.RGBdistance});const _ciede2000Js=require("./CIEDE2000.js");const _convertersJs=require("./converters.js");const _rgbdistanceJs=require("./RGBdistance.js")
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { ciede2000 } from \"./CIEDE2000.js\";\nexport {\n convertHextoRGB,\n convertRGBtoLab,\n convertRGBtoXYZ,\n convertXYZtoLab,\n} from \"./converters.js\";\nexport { RGBdistance } from \"./RGBdistance.js\";\n"],"names":["ciede2000","convertHextoRGB","convertRGBtoLab","convertRGBtoXYZ","convertXYZtoLab","RGBdistance"],"mappings":"AAAA,2MAASA,SAAS,KAATA,YAAS,UAAA,CAEhBC,eAAe,KAAfA,aAAe,gBAAA,CACfC,eAAe,KAAfA,aAAe,gBAAA,CACfC,eAAe,KAAfA,aAAe,gBAAA,CACfC,eAAe,KAAfA,aAAe,gBAAA,CAERC,WAAW,KAAXA,cAAW,YAAA,8BAPM,gBAAgB,8BAMnC,iBAAiB,+BACI,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{hue_d:()=>hue_d,deltaHue_d:()=>deltaHue_d,meanHue_d:()=>meanHue_d,toRadians:()=>toRadians,bigSquare:()=>bigSquare,linearRGB:()=>linearRGB,constrainLab:()=>constrainLab});function hue_d(x,y){if(x===0&&y===0){return 0}const angle=Math.atan2(x,y)*(180/Math.PI);if(angle>=0){return angle}return angle+360}function deltaHue_d({C1,C2,h1_d,h2_d}){if(C1*C2===0){return 0}if(Math.abs(h2_d-h1_d)<=180){return h2_d-h1_d}if(h2_d-h1_d>180){return h2_d-h1_d-360}if(h2_d-h1_d< -180){return h2_d-h1_d+360}return 0}function meanHue_d({C1,C2,h1_d,h2_d}){if(C1*C2===0){return h2_d+h1_d}if(Math.abs(h1_d-h2_d)<=180){return(h2_d+h1_d)/2}if(Math.abs(h1_d-h2_d)>180&&h1_d+h2_d<360){return(h2_d+h1_d+360)/2}if(Math.abs(h1_d-h2_d)>180&&h1_d+h2_d>=360){return(h2_d+h1_d-360)/2}return 0}const toRadians=n=>n*(Math.PI/180);const bigSquare=n=>Math.sqrt(Math.pow(n,7)/(Math.pow(n,7)+Math.pow(25,7)));function linearRGB(rgbValue){const rgbRatio=rgbValue/255;let linearValue;if(rgbRatio>.04045){linearValue=Math.pow((rgbRatio+.055)/1.055,2.4)}else{linearValue=rgbRatio/12.92}return linearValue}function constrainLab(n){const delta=6/29;const deltaCube=Math.pow(delta,3);let t;if(n>deltaCube){t=Math.cbrt(n)}else{t=n/(3*Math.pow(delta,2))+4/29}return t}
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/util/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n"],"names":["hue_d","deltaHue_d","meanHue_d","toRadians","bigSquare","linearRGB","constrainLab","x","y","angle","Math","atan2","PI","C1","C2","h1_d","h2_d","abs","n","sqrt","pow","rgbValue","rgbRatio","linearValue","delta","deltaCube","t","cbrt"],"mappings":"AAAA,2MAOgBA,KAAK,KAALA,KAAK,CAiBLC,UAAU,KAAVA,UAAU,CAqBVC,SAAS,KAATA,SAAS,CAqBZC,SAAS,KAATA,SAAS,CAMTC,SAAS,KAATA,SAAS,CAQNC,SAAS,KAATA,SAAS,CAiBTC,YAAY,KAAZA,YAAY,EA1FrB,UAASN,KAAK,CAACO,CAAS,CAAEC,CAAS,CAAU,CAElD,GAAID,CAAC,GAAK,CAAC,EAAIC,CAAC,GAAK,CAAC,CAAE,CACtB,OAAO,CAAC,AAAC,CACV,AAED,MAAMC,KAAK,CAAGC,I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BC,CAAC,CAAGhB,IAAI,CAACiB,IAAI,CAACT,CAAC,CAAC,CACjB,IAAM,CACLQ,CAAC,CAAGR,CAAC,CAAG,CAAC,CAAC,CAAGR,IAAI,CAACU,GAAG,CAACI,KAAK,CAAE,CAAC,CAAC,CAAC,CAAG,CAAC,CAAG,EAAE,CAC1C,AAED,OAAOE,CAAC,AAAC,CACV"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LabColour, RGBColour, XYZColour } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Converts sRGB colour space to XYZ.
|
|
4
|
+
* Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
|
|
5
|
+
* @param {RGBColour} colour sRGB colour
|
|
6
|
+
* @return {XYZColour} XYZ colour
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertRGBtoXYZ(colour: RGBColour): XYZColour;
|
|
9
|
+
/**
|
|
10
|
+
* Converts XYZ colour space to Lab
|
|
11
|
+
* Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]
|
|
12
|
+
* @param colour XYZ colour
|
|
13
|
+
* @return {LabColour} Lab colour
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertXYZtoLab(colour: XYZColour): LabColour;
|
|
16
|
+
/**
|
|
17
|
+
* Indirectly converts RGB to Lab.
|
|
18
|
+
* First converts RGB to XYZ,
|
|
19
|
+
* Then converts XYZ to Lab
|
|
20
|
+
* @param {RGBColour} colour sRGB colour
|
|
21
|
+
* @return {LabColour} Lab colour
|
|
22
|
+
*/
|
|
23
|
+
export declare function convertRGBtoLab(colour: RGBColour): LabColour;
|
|
24
|
+
export declare function convertHextoRGB(hex: string): RGBColour;
|
package/dist/converters.js
CHANGED
|
@@ -1,56 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* Converts sRGB colour space to XYZ.
|
|
4
|
-
* Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation
|
|
5
|
-
* @param {RGBColour} colour sRGB colour
|
|
6
|
-
* @return {XYZColour} XYZ colour
|
|
7
|
-
*/ export function convertRGBtoXYZ(colour) {
|
|
8
|
-
const { R , G , B } = colour;
|
|
9
|
-
const _R = linearRGB(R) * 100;
|
|
10
|
-
const _G = linearRGB(G) * 100;
|
|
11
|
-
const _B = linearRGB(B) * 100;
|
|
12
|
-
// Magic numbers are pre-calculated sRGB D65 constants
|
|
13
|
-
const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;
|
|
14
|
-
const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;
|
|
15
|
-
const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;
|
|
16
|
-
return {
|
|
17
|
-
X,
|
|
18
|
-
Y,
|
|
19
|
-
Z
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Converts XYZ colour space to Lab
|
|
24
|
-
* Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]
|
|
25
|
-
* @param colour XYZ colour
|
|
26
|
-
* @return {LabColour} Lab colour
|
|
27
|
-
*/ export function convertXYZtoLab(colour) {
|
|
28
|
-
const { X , Y , Z } = colour;
|
|
29
|
-
// Magic numbers are normalised for relative luminance from the D65 standard
|
|
30
|
-
const _X = X / 95.047;
|
|
31
|
-
const _Y = Y / 100;
|
|
32
|
-
const _Z = Z / 108.883;
|
|
33
|
-
const fX = constrainLab(_X);
|
|
34
|
-
const fY = constrainLab(_Y);
|
|
35
|
-
const fZ = constrainLab(_Z);
|
|
36
|
-
const L = 116 * fY - 16;
|
|
37
|
-
const a = 500 * (fX - fY);
|
|
38
|
-
const b = 200 * (fY - fZ);
|
|
39
|
-
return {
|
|
40
|
-
L,
|
|
41
|
-
a,
|
|
42
|
-
b
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Indirectly converts RGB to Lab.
|
|
47
|
-
* First converts RGB to XYZ,
|
|
48
|
-
* Then converts XYZ to Lab
|
|
49
|
-
* @param {RGBColour} colour sRGB colour
|
|
50
|
-
* @return {LabColour} Lab colour
|
|
51
|
-
*/ export function convertRGBtoLab(colour) {
|
|
52
|
-
const XYZColour = convertRGBtoXYZ(colour);
|
|
53
|
-
return convertXYZtoLab(XYZColour);
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
import{constrainLab as a,linearRGB as b}from"./util/index.js";export function convertRGBtoXYZ(a){let{R:c,G:d,B:e}=a,f=100*b(c),g=100*b(d),h=100*b(e);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}export function convertXYZtoLab(b){let{X:c,Y:d,Z:e}=b,f=a(c/95.047),g=a(d/100),h=a(e/108.883);return{L:116*g-16,a:500*(f-g),b:200*(g-h)}}export function convertRGBtoLab(a){let b=convertRGBtoXYZ(a);return convertXYZtoLab(b)}export function convertHextoRGB(a){if("string"!=typeof a)throw Error(`convertHextoRGB expects a string but got a ${typeof a}`);if(a.match(/^#[a-fA-F0-9]{6}$/))return{R:parseInt(`${a[1]}${a[2]}`,16),G:parseInt(`${a[3]}${a[4]}`,16),B:parseInt(`${a[5]}${a[6]}`,16)};if(a.match(/^#[a-fA-F0-9]{3}$/))return{R:parseInt(`${a[1]}${a[1]}`,16),G:parseInt(`${a[2]}${a[2]}`,16),B:parseInt(`${a[3]}${a[3]}`,16)};if(a.match(/^#[a-fA-F0-9]{8}$/))return{R:parseInt(`${a[1]}${a[2]}`,16),G:parseInt(`${a[3]}${a[4]}`,16),B:parseInt(`${a[5]}${a[6]}`,16),A:parseInt(`${a[7]}${a[8]}`,16)/255};if(a.match(/^#[a-fA-F0-9]{4}$/))return{R:parseInt(`${a[1]}${a[1]}`,16),G:parseInt(`${a[2]}${a[2]}`,16),B:parseInt(`${a[3]}${a[3]}`,16),A:parseInt(`${a[4]}${a[4]}`,16)/255};throw Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${a}`)}
|
|
56
2
|
//# sourceMappingURL=converters.js.map
|
package/dist/converters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/converters.ts"],"sourcesContent":["import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n"],"names":["constrainLab","linearRGB","convertRGBtoXYZ","colour","R","G","B","_R","_G","_B","X","Y","Z","convertXYZtoLab","
|
|
1
|
+
{"version":3,"sources":["../src/converters.ts"],"sourcesContent":["import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n\nexport function convertHextoRGB(hex: string): RGBColour {\n /** Six digit Hexadecimal colour, ie: #12FF21 */\n const hexRegex = /^#[a-fA-F0-9]{6}$/;\n /** Eight digit Hexadecimal colour, ie: #12FF21BE */\n const hexAlphaRegex = /^#[a-fA-F0-9]{8}$/;\n /** Three digit Hexadecimal colour, ie: #FFF */\n const shortHexRegex = /^#[a-fA-F0-9]{3}$/;\n /** Four digit Hexadecimal colour, ie: #FFF4 */\n const shortAlphaHexRegex = /^#[a-fA-F0-9]{4}$/;\n\n if (typeof hex !== \"string\") {\n throw new Error(`convertHextoRGB expects a string but got a ${typeof hex}`);\n }\n\n if (hex.match(hexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[2]}`, 16),\n G: parseInt(`${hex[3]}${hex[4]}`, 16),\n B: parseInt(`${hex[5]}${hex[6]}`, 16),\n };\n }\n\n if (hex.match(shortHexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[1]}`, 16),\n G: parseInt(`${hex[2]}${hex[2]}`, 16),\n B: parseInt(`${hex[3]}${hex[3]}`, 16),\n };\n }\n\n if (hex.match(hexAlphaRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[2]}`, 16),\n G: parseInt(`${hex[3]}${hex[4]}`, 16),\n B: parseInt(`${hex[5]}${hex[6]}`, 16),\n A: parseInt(`${hex[7]}${hex[8]}`, 16) / 255,\n };\n }\n\n if (hex.match(shortAlphaHexRegex)) {\n return {\n R: parseInt(`${hex[1]}${hex[1]}`, 16),\n G: parseInt(`${hex[2]}${hex[2]}`, 16),\n B: parseInt(`${hex[3]}${hex[3]}`, 16),\n A: parseInt(`${hex[4]}${hex[4]}`, 16) / 255,\n };\n }\n\n throw new Error(\n `convertHextoRGB expects an valid hexadecimal colour value but got ${hex}`\n );\n}\n"],"names":["constrainLab","linearRGB","convertRGBtoXYZ","colour","R","G","B","_R","_G","_B","X","Y","Z","convertXYZtoLab","fX","fY","fZ","L","a","b","convertRGBtoLab","XYZColour","convert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AC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CACrCjB,CAAC,CAAEoB,QAAQ,CAAC,CAAC,EAAEH,CAAG,CAAC,CAAC,CAAC,CAAC,EAAEA,CAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CACrCI,CAAC,CAAED,QAAQ,CAAC,CAAC,EAAEH,CAAG,CAAC,CAAC,CAAC,CAAC,EAAEA,CAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,EAAE,CAAC,CAAG,GAAG,CAC5C,AAAC,AACH,AAED,OAAM,AAAIC,KAAK,CACb,CAAC,kEAAkE,EAAED,CAAG,CAAC,CAAC,CAC3E,AAAC,CACH"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { convertRGBtoXYZ, convertRGBtoLab, convertXYZtoLab } from "./converters.js";
|
|
3
|
-
export { RGBdistance } from "./RGBdistance.js";
|
|
4
|
-
|
|
1
|
+
export{ciede2000}from"./CIEDE2000.js";export{convertHextoRGB,convertRGBtoLab,convertRGBtoXYZ,convertXYZtoLab}from"./converters.js";export{RGBdistance}from"./RGBdistance.js"
|
|
5
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { ciede2000 } from \"./CIEDE2000.js\";\nexport {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { ciede2000 } from \"./CIEDE2000.js\";\nexport {\n convertHextoRGB,\n convertRGBtoLab,\n convertRGBtoXYZ,\n convertXYZtoLab,\n} from \"./converters.js\";\nexport { RGBdistance } from \"./RGBdistance.js\";\n"],"names":["ciede2000","convertHextoRGB","convertRGBtoLab","convertRGBtoXYZ","convertXYZtoLab","RGBdistance"],"mappings":"AAAA,OAASA,SAAS,KAAQ,gBAAgB,AAAC,AAC3C,QACEC,eAAe,CACfC,eAAe,CACfC,eAAe,CACfC,eAAe,KACV,iBAAiB,AAAC,AACzB,QAASC,WAAW,KAAQ,kBAAkB,AAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.
|
|
3
|
+
*/
|
|
4
|
+
export interface RGBColour {
|
|
5
|
+
/** A number between 0 and 255 to describe the Red colour channel */
|
|
6
|
+
R: number;
|
|
7
|
+
/** A number between 0 and 255 to describe the Green colour channel */
|
|
8
|
+
G: number;
|
|
9
|
+
/** A number between 0 and 255 to describe the Blue colour channel */
|
|
10
|
+
B: number;
|
|
11
|
+
/** A optional number between 0 and 1 to describe the Alpha colour channel */
|
|
12
|
+
A?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* L*a*b* space is three-dimensional and covers the entire range of human colour perception
|
|
16
|
+
*/
|
|
17
|
+
export interface LabColour {
|
|
18
|
+
/** A number between 0 and 100 to describe the colour's lightness. (0 - black, 100 - white) */
|
|
19
|
+
L: number;
|
|
20
|
+
/** A number between -128 and 127 to describe the green–red opponent colors, with negative values toward green and positive values toward red */
|
|
21
|
+
a: number;
|
|
22
|
+
/** A number between -128 and 127 to describe blue–yellow opponents, with negative numbers toward blue and positive toward yellow */
|
|
23
|
+
b: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The CIE XYZ colour space is a device independent colour representation
|
|
27
|
+
*/
|
|
28
|
+
export interface XYZColour {
|
|
29
|
+
/** X is a mix of response curves chosen to be nonnegative */
|
|
30
|
+
X: number;
|
|
31
|
+
/** Y as luminance */
|
|
32
|
+
Y: number;
|
|
33
|
+
/** Z is quasi-equal to blue */
|
|
34
|
+
Z: number;
|
|
35
|
+
}
|
|
36
|
+
export interface HueHelper {
|
|
37
|
+
/** Chroma for colour 1 */
|
|
38
|
+
C1: number;
|
|
39
|
+
/** Chroma for colour 2 */
|
|
40
|
+
C2: number;
|
|
41
|
+
/** Derivative of colour 1 Hue */
|
|
42
|
+
h1_d: number;
|
|
43
|
+
/** Derivative of colour 2 Hue */
|
|
44
|
+
h2_d: number;
|
|
45
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HueHelper } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the Hue derivative
|
|
4
|
+
* @param x A numeric expression representing the cartesian x-coordinate.
|
|
5
|
+
* @param y A numeric expression representing the cartesian y-coordinate.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hue_d(x: number, y: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the difference between two Hue derivatives
|
|
10
|
+
* @param HueHelper param
|
|
11
|
+
*/
|
|
12
|
+
export declare function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the mean between two Hue derivatives
|
|
15
|
+
* @param HueHelper param
|
|
16
|
+
*/
|
|
17
|
+
export declare function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a number in degrees to radians
|
|
20
|
+
* @param n Number in degrees to be converted
|
|
21
|
+
*/
|
|
22
|
+
export declare const toRadians: (n: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* Calculates a recurring square root
|
|
25
|
+
* @param n Input number
|
|
26
|
+
*/
|
|
27
|
+
export declare const bigSquare: (n: number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* Normalise black and white colorimetry as specified in IEC 61966-2-1
|
|
30
|
+
* It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1
|
|
31
|
+
* @param n number to be normalised
|
|
32
|
+
*/
|
|
33
|
+
export declare function linearRGB(rgbValue: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* The division of the f function domain into two parts was done to prevent an infinite slope at n = 0
|
|
36
|
+
* @param n Number to be constrained
|
|
37
|
+
*/
|
|
38
|
+
export declare function constrainLab(n: number): number;
|
package/dist/util/index.js
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Calculates the Hue derivative
|
|
3
|
-
* @param x A numeric expression representing the cartesian x-coordinate.
|
|
4
|
-
* @param y A numeric expression representing the cartesian y-coordinate.
|
|
5
|
-
*/ export function hue_d(x, y) {
|
|
6
|
-
// early exit if both values are 0
|
|
7
|
-
if (x === 0 && y === 0) {
|
|
8
|
-
return 0;
|
|
9
|
-
}
|
|
10
|
-
/** The angle in degrees */ const angle = Math.atan2(x, y) * (180 / Math.PI);
|
|
11
|
-
if (angle >= 0) {
|
|
12
|
-
return angle;
|
|
13
|
-
}
|
|
14
|
-
return angle + 360;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Calculates the difference between two Hue derivatives
|
|
18
|
-
* @param HueHelper param
|
|
19
|
-
*/ export function deltaHue_d({ C1 , C2 , h1_d , h2_d }) {
|
|
20
|
-
if (C1 * C2 === 0) {
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
if (Math.abs(h2_d - h1_d) <= 180) {
|
|
24
|
-
return h2_d - h1_d;
|
|
25
|
-
}
|
|
26
|
-
if (h2_d - h1_d > 180) {
|
|
27
|
-
return h2_d - h1_d - 360;
|
|
28
|
-
}
|
|
29
|
-
if (h2_d - h1_d < -180) {
|
|
30
|
-
return h2_d - h1_d + 360;
|
|
31
|
-
}
|
|
32
|
-
// it should never reach this point
|
|
33
|
-
return 0;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Calculates the mean between two Hue derivatives
|
|
37
|
-
* @param HueHelper param
|
|
38
|
-
*/ export function meanHue_d({ C1 , C2 , h1_d , h2_d }) {
|
|
39
|
-
if (C1 * C2 === 0) {
|
|
40
|
-
return h2_d + h1_d;
|
|
41
|
-
}
|
|
42
|
-
if (Math.abs(h1_d - h2_d) <= 180) {
|
|
43
|
-
return (h2_d + h1_d) / 2;
|
|
44
|
-
}
|
|
45
|
-
if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {
|
|
46
|
-
return (h2_d + h1_d + 360) / 2;
|
|
47
|
-
}
|
|
48
|
-
if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {
|
|
49
|
-
return (h2_d + h1_d - 360) / 2;
|
|
50
|
-
}
|
|
51
|
-
// it should never reach this point
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Converts a number in degrees to radians
|
|
56
|
-
* @param n Number in degrees to be converted
|
|
57
|
-
*/ export const toRadians = (n)=>n * (Math.PI / 180)
|
|
58
|
-
;
|
|
59
|
-
/**
|
|
60
|
-
* Calculates a recurring square root
|
|
61
|
-
* @param n Input number
|
|
62
|
-
*/ export const bigSquare = (n)=>Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)))
|
|
63
|
-
;
|
|
64
|
-
/**
|
|
65
|
-
* Normalise black and white colorimetry as specified in IEC 61966-2-1
|
|
66
|
-
* It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1
|
|
67
|
-
* @param n number to be normalised
|
|
68
|
-
*/ export function linearRGB(rgbValue) {
|
|
69
|
-
const rgbRatio = rgbValue / 255;
|
|
70
|
-
let linearValue;
|
|
71
|
-
if (rgbRatio > 0.04045) {
|
|
72
|
-
linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);
|
|
73
|
-
} else {
|
|
74
|
-
linearValue = rgbRatio / 12.92;
|
|
75
|
-
}
|
|
76
|
-
return linearValue;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* The division of the f function domain into two parts was done to prevent an infinite slope at n = 0
|
|
80
|
-
* @param n Number to be constrained
|
|
81
|
-
*/ export function constrainLab(n) {
|
|
82
|
-
const delta = 6 / 29;
|
|
83
|
-
const deltaCube = Math.pow(delta, 3);
|
|
84
|
-
let t;
|
|
85
|
-
if (n > deltaCube) {
|
|
86
|
-
t = Math.cbrt(n);
|
|
87
|
-
} else {
|
|
88
|
-
t = n / (3 * Math.pow(delta, 2)) + 4 / 29;
|
|
89
|
-
}
|
|
90
|
-
return t;
|
|
91
|
-
}
|
|
92
|
-
|
|
1
|
+
export function hue_d(a,b){if(0===a&&0===b)return 0;let c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}export function deltaHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}export function meanHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}export const toRadians=a=>a*(Math.PI/180);export const bigSquare=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));export function linearRGB(a){let b=a/255,c;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}export function constrainLab(a){let b=6/29,c;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}
|
|
93
2
|
//# sourceMappingURL=index.js.map
|
package/dist/util/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n"],"names":["hue_d","x","y","angle","Math","atan2","PI","deltaHue_d","C1","C2","h1_d","h2_d","abs","meanHue_d","toRadians","n","bigSquare","sqrt","pow","linearRGB","rgbValue","rgbRatio","linearValue","constrainLab","delta","
|
|
1
|
+
{"version":3,"sources":["../../src/util/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n"],"names":["hue_d","x","y","angle","Math","atan2","PI","deltaHue_d","C1","C2","h1_d","h2_d","abs","meanHue_d","toRadians","n","bigSquare","sqrt","pow","linearRGB","rgbValue","rgbRatio","linearValue","constrainLab","delta","t","cbrt"],"mappings":"AAOA,OAAO,SAASA,KAAK,CAACC,CAAS,CAAEC,CAAS,CAAU,CAElD,GAAID,AAAM,CAAC,GAAPA,CAAC,EAAUC,AAAM,CAAC,GAAPA,CAAC,AAAM,CACpB,OAAO,CAAC,AAAC,AACV,AAED,KAAMC,CAAK,CAAGC,IAAI,CAACC,KAAK,CAACJ,CAAC,CAAEC,CAAC,CAAC,CAAI,CAAA,GAAG,CAAGE,IAAI,CAACE,EAAE,CAAA,AAAC,AAAC,QACjD,AAAIH,CAAK,EAAI,CAAC,CACLA,CAAK,CAEPA,CAAK,CAAG,GAAG,AADjB,CAEF,AAMD,OAAO,SAASI,UAAU,CAAC,CAAEC,EAAE,CAAFA,CAAE,CAAEC,EAAE,CAAFA,CAAE,CAAEC,IAAI,CAAJA,CAAI,CAAEC,IAAI,CAAJA,CAAI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,MAAMU,SAAS,CAAG,AAACD,CAAS,EACjCX,IAAI,CAACa,IAAI,CAACb,IAAI,CAACc,GAAG,CAACH,CAAC,CAAE,CAAC,CAAC,CAAIX,CAAAA,IAAI,CAACc,GAAG,CAACH,CAAC,CAAE,CAAC,CAAC,CAAGX,UAAe,CAAA,AAAC,CAAC,AAAC,AAOjE,QAAO,SAASe,SAAS,CAACC,CAAgB,CAAE,CAC1C,IAAMC,CAAQ,CAAGD,CAAQ,CAAG,GAAG,CAC3BE,CAAW,AAAQ,AADS,AAShC,QANID,CAAQ,CAAG,MAAO,CACNjB,IAAI,CAACc,GAAG,CAAC,AAACG,CAAAA,CAAQ,CAAG,IAAK,CAAA,CAAI,KAAK,CAAE,GAAG,CAAC,CAEzCA,CAAQ,CAAG,KAAK,AAGb,CACpB,AAMD,OAAO,SAASE,YAAY,CAACR,CAAS,CAAU,CAC9C,IAAMS,CAAK,CAAG,CAAC,CAAG,EAAE,CAEhBC,CAAC,AAAQ,AAFQ,AAUrB,QANIV,CAAC,CAHaX,IAAI,CAACc,GAAG,CAACM,CAAK,CAAE,CAAC,CAAC,AAGnB,CACXpB,IAAI,CAACsB,IAAI,CAACX,CAAC,CAAC,CAEZA,CAAC,CAAI,CAAA,CAAC,CAAGX,IAAI,CAACc,GAAG,CAACM,CAAK,CAAE,CAAC,CAAC,CAAA,CAAI,CAAC,CAAG,EAAE,AAGlC,CACV"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sardine/colour",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "It does things to colours",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"unpkg": "dist/umd/index.umd.js",
|
|
8
8
|
"sideEffects": false,
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"scripts": {
|
|
10
|
-
"build": "rm -rf ./dist && npm run build:
|
|
11
|
-
"build:esm": "npx swc ./src -d ./dist",
|
|
12
|
-
"build:
|
|
13
|
-
"
|
|
14
|
-
"test": "npm run build && c8 ava",
|
|
17
|
+
"build": "rm -rf ./dist && npm run build:esm && npm run build:cjs && npm run types:emit",
|
|
18
|
+
"build:esm": "npx swc --config-file .esm.swcrc ./src -d ./dist",
|
|
19
|
+
"build:cjs": "npx swc --config-file .cjs.swcrc ./src -d ./dist/cjs",
|
|
20
|
+
"test": "rm -rf ./dist && npm run build:esm && c8 ava",
|
|
15
21
|
"types:emit": "npx tsc --declaration --emitDeclarationOnly",
|
|
16
22
|
"types:check": "npx tsc --noEmit",
|
|
17
23
|
"publish:next": "npm run build && npm run types:emit && npm publish --tag next",
|
|
@@ -42,10 +48,11 @@
|
|
|
42
48
|
"node": ">= 14"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@swc/
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
51
|
+
"@changesets/cli": "^2.24.1",
|
|
52
|
+
"@swc/cli": "^0.1.57",
|
|
53
|
+
"@swc/core": "^1.2.219",
|
|
54
|
+
"ava": "^4.3.1",
|
|
55
|
+
"c8": "^7.12.0",
|
|
56
|
+
"typescript": "^4.7.4"
|
|
50
57
|
}
|
|
51
58
|
}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * The RGB colour model represents a broad array of colours by describing the Red, Green and Blue channels.\n */\n export interface RGBColour {\n /** A number between 0 and 255 to describe the Red colour channel */\n R: number;\n /** A number between 0 and 255 to describe the Green colour channel */\n G: number;\n /** A number between 0 and 255 to describe the Blue colour channel */\n B: number;\n /** A optional number between 0 and 1 to describe the Alpha colour channel */\n A?: number;\n }\n \n /**\n * L*a*b* space is three-dimensional and covers the entire range of human colour perception\n */\n export interface LabColour {\n /** A number between 0 and 100 to describe the colour's lightness. (0 - black, 100 - white) */\n L: number;\n /** A number between -128 and 127 to describe the green–red opponent colors, with negative values toward green and positive values toward red */\n a: number;\n /** A number between -128 and 127 to describe blue–yellow opponents, with negative numbers toward blue and positive toward yellow */\n b: number;\n }\n \n /**\n * The CIE XYZ colour space is a device independent colour representation\n */\n export interface XYZColour {\n /** X is a mix of response curves chosen to be nonnegative */\n X: number;\n /** Y as luminance */\n Y: number;\n /** Z is quasi-equal to blue */\n Z: number;\n }\n\n export interface HueHelper {\n /** Chroma for colour 1 */\n C1: number;\n /** Chroma for colour 2 */\n C2: number;\n /** Derivative of colour 1 Hue */\n h1_d: number;\n /** Derivative of colour 2 Hue */\n h2_d: number;\n }"],"names":[],"mappings":"AAAA,EAEG,AAFH;;CAEG,AAFH,EAEG,CACF,MAAM"}
|
package/dist/umd/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function hue_d(a,b){if(0===a&&0===b)return 0;const c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}function deltaHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}function meanHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}const toRadians=a=>a*(Math.PI/180);const bigSquare=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function linearRGB(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function constrainLab(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function ciede2000(f,g){const h=f.L,i=f.a,j=f.b,k=g.L,l=g.a,m=g.b,n=Math.sqrt(Math.pow(i,2)+Math.pow(j,2)),o=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),p=.5*(1-bigSquare((n+o)/2)),q=i*(1+p),r=l*(1+p),s=Math.sqrt(Math.pow(q,2)+Math.pow(j,2)),t=Math.sqrt(Math.pow(r,2)+Math.pow(m,2)),u=(s+t)/2,v=t-s,w=hue_d(j,q),x=hue_d(m,r),y=deltaHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),z=2*Math.sqrt(s*t)*Math.sin(toRadians(y)/2),A=meanHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),B=(h+k)/2,C=1-.17*Math.cos(toRadians(A-30))+.24*Math.cos(toRadians(2*A))+.32*Math.cos(toRadians(3*A+6))-.2*Math.cos(toRadians(4*A-63)),D=.045*u+1,E=1+.015*u*C,F=-2*bigSquare(u)*Math.sin(toRadians(2*(30*Math.exp(-Math.pow((A-275)/25,2)))));return Math.sqrt(Math.pow((k-h)/(1*(1+.015*Math.pow(B-50,2)/Math.sqrt(20+Math.pow(B-50,2)))),2)+Math.pow(v/(1*D),2)+Math.pow(z/(1*E),2)+F*(v/(1*D))*(z/(1*E)))}function convertRGBtoXYZ(a){const{R:c,G:d,B:e}=a,f=100*linearRGB(c),g=100*linearRGB(d),h=100*linearRGB(e);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function convertXYZtoLab(b){const{X:c,Y:d,Z:e}=b,f=constrainLab(c/95.047),g=constrainLab(d/100),h=constrainLab(e/108.883);return{L:116*g-16,a:500*(f-g),b:200*(g-h)}}function convertRGBtoLab(a){const b=convertRGBtoXYZ(a);return convertXYZtoLab(b)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertRGBtoXYZ as convertRGBtoXYZ,convertRGBtoLab as convertRGBtoLab,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}
|
package/dist/umd/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/hugo/colour/src/util/index.ts","/home/hugo/colour/src/CIEDE2000.ts","/home/hugo/colour/src/converters.ts","/home/hugo/colour/src/RGBdistance.ts","/home/hugo/colour/src/index.ts"],"sourcesContent":["import type { HueHelper } from \"../types\";\n\n/**\n * Calculates the Hue derivative\n * @param x A numeric expression representing the cartesian x-coordinate.\n * @param y A numeric expression representing the cartesian y-coordinate.\n */\nexport function hue_d(x: number, y: number): number {\n // early exit if both values are 0\n if (x === 0 && y === 0) {\n return 0;\n }\n /** The angle in degrees */\n const angle = Math.atan2(x, y) * (180 / Math.PI);\n if (angle >= 0) {\n return angle;\n }\n return angle + 360;\n}\n\n/**\n * Calculates the difference between two Hue derivatives\n * @param HueHelper param\n */\nexport function deltaHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return 0;\n }\n if (Math.abs(h2_d - h1_d) <= 180) {\n return h2_d - h1_d;\n }\n if (h2_d - h1_d > 180) {\n return h2_d - h1_d - 360;\n }\n if (h2_d - h1_d < -180) {\n return h2_d - h1_d + 360;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Calculates the mean between two Hue derivatives\n * @param HueHelper param\n */\nexport function meanHue_d({ C1, C2, h1_d, h2_d }: HueHelper): number {\n if (C1 * C2 === 0) {\n return h2_d + h1_d;\n }\n if (Math.abs(h1_d - h2_d) <= 180) {\n return (h2_d + h1_d) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d < 360) {\n return (h2_d + h1_d + 360) / 2;\n }\n if (Math.abs(h1_d - h2_d) > 180 && h1_d + h2_d >= 360) {\n return (h2_d + h1_d - 360) / 2;\n }\n // it should never reach this point\n return 0;\n}\n\n/**\n * Converts a number in degrees to radians\n * @param n Number in degrees to be converted\n */\nexport const toRadians = (n: number): number => n * (Math.PI / 180);\n\n/**\n * Calculates a recurring square root\n * @param n Input number\n */\nexport const bigSquare = (n: number): number =>\n Math.sqrt(Math.pow(n, 7) / (Math.pow(n, 7) + Math.pow(25, 7)));\n\n/**\n * Normalise black and white colorimetry as specified in IEC 61966-2-1\n * It takes a RGB channel in the range [0 - 255] and returns a value between 0 and 1\n * @param n number to be normalised\n */\nexport function linearRGB(rgbValue: number) {\n const rgbRatio = rgbValue / 255;\n let linearValue: number;\n\n if (rgbRatio > 0.04045) {\n linearValue = Math.pow((rgbRatio + 0.055) / 1.055, 2.4);\n } else {\n linearValue = rgbRatio / 12.92;\n }\n\n return linearValue;\n}\n\n/**\n * The division of the f function domain into two parts was done to prevent an infinite slope at n = 0\n * @param n Number to be constrained\n */\nexport function constrainLab(n: number): number {\n const delta = 6 / 29;\n const deltaCube = Math.pow(delta, 3);\n let t: number;\n\n if (n > deltaCube) {\n t = Math.cbrt(n);\n } else {\n t = n / (3 * Math.pow(delta, 2)) + 4 / 29;\n }\n\n return t;\n}\n","import { bigSquare, deltaHue_d, hue_d, meanHue_d, toRadians } from \"./util/index.js\";\nimport type { LabColour } from \"./types\";\n\n/**\n * Mesures the colour difference between two colours in the Lab space\n *\n * Math taken from:\n *\n * https://en.wikipedia.org/wiki/Color_difference#CIEDE2000\n * http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf\n * @param colour1 First colour to be compared\n * @param colour2 First colour to be compared\n */\nexport function ciede2000(colour1: LabColour, colour2: LabColour): number {\n /**\n * Glossary\n * L - Lightness as defined by L*a*b*\n * a - Describes the green–red opponent colors as defined by L*a*b*\n * b - Describes the blue–yellow opponent colors as defined by L*a*b*\n * C - Chroma as defined by CIE94\n *\n * Math notation\n * _d - Derivative\n * Δ - Difference between values\n * ̅ - Mean value\n */\n\n /** Lightness for colour 1 */\n const L1 = colour1.L;\n\n /** green–red colour opponent for colour 1 */\n const a1 = colour1.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b1 = colour1.b;\n\n /** Lightness for colour 2 */\n const L2 = colour2.L;\n\n /** green–red colour opponent for colour 1 */\n const a2 = colour2.a;\n\n /** blue–yellow colour opponent for colour 1 */\n const b2 = colour2.b;\n\n /** Weighting factor for Luminance */\n const kL = 1;\n\n /** Weighting factor for Chroma */\n const kC = 1;\n\n /** Weighting factor for Hue */\n const kH = 1;\n\n /** Chroma for colour 1 */\n const C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2));\n\n /** Chroma for colour 2 */\n const C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2));\n\n /** Derivative of the Lightness difference */\n const ΔL_d = L2 - L1;\n\n /** Chroma mean value */\n const C̅ = (C1 + C2) / 2;\n\n const G = 0.5 * (1 - bigSquare(C̅));\n\n /** Derivative of a1 */\n const a1_d = a1 * (1 + G);\n\n /** Derivative of a2 */\n const a2_d = a2 * (1 + G);\n\n /** Derivative of C1 */\n const C1_d = Math.sqrt(Math.pow(a1_d, 2) + Math.pow(b1, 2));\n\n /** Derivative of C2 */\n const C2_d = Math.sqrt(Math.pow(a2_d, 2) + Math.pow(b2, 2));\n\n /** Derivative of Chroma mean */\n const C̅_d = (C1_d + C2_d) / 2;\n\n /** Derivative of the mean difference of Chroma */\n const ΔC̅_d = C2_d - C1_d;\n\n /** Derivative of colour 1 Hue */\n const h1_d = hue_d(b1, a1_d);\n\n /** Derivative of colour 2 Hue */\n const h2_d = hue_d(b2, a2_d);\n\n /** Hue difference */\n const Δh_d = deltaHue_d({ C1, C2, h1_d, h2_d });\n\n const ΔH_d = 2 * Math.sqrt(C1_d * C2_d) * Math.sin(toRadians(Δh_d) / 2);\n\n /** Derivative of mean hue */\n const H̅_d = meanHue_d({ C1, C2, h1_d, h2_d });\n\n /** Lightness Mean value*/\n const L̅ = (L1 + L2) / 2;\n\n /** Compensation for neutral colors (the primed values in the L*C*h differences) */\n const T =\n 1 -\n 0.17 * Math.cos(toRadians(H̅_d - 30)) +\n 0.24 * Math.cos(toRadians(2 * H̅_d)) +\n 0.32 * Math.cos(toRadians(3 * H̅_d + 6)) -\n 0.2 * Math.cos(toRadians(4 * H̅_d - 63));\n\n /** Compensation for lightness */\n const SL =\n 1 + (0.015 * Math.pow(L̅ - 50, 2)) / Math.sqrt(20 + Math.pow(L̅ - 50, 2));\n\n /** Compensation for chroma */\n const SC = 0.045 * C̅_d + 1;\n\n /** Compensation for hue */\n const SH = 1 + 0.015 * C̅_d * T;\n\n const rotation = 30 * Math.exp(-Math.pow((H̅_d - 275) / 25, 2));\n\n /** A hue rotation term, to deal with the problematic blue region (hue angles in the neighborhood of 275°) */\n const RT = -2 * bigSquare(C̅_d) * Math.sin(toRadians(rotation * 2));\n\n /** Colour difference */\n const ΔE = Math.sqrt(\n Math.pow(ΔL_d / (kL * SL), 2) +\n Math.pow(ΔC̅_d / (kC * SC), 2) +\n Math.pow(ΔH_d / (kH * SH), 2) +\n RT * (ΔC̅_d / (kC * SC)) * (ΔH_d / (kH * SH))\n );\n\n return ΔE;\n}\n","import type { LabColour, RGBColour, XYZColour } from \"./types\";\nimport { constrainLab, linearRGB } from \"./util/index.js\";\n\n/**\n * Converts sRGB colour space to XYZ.\n * Math comes from https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation\n * @param {RGBColour} colour sRGB colour\n * @return {XYZColour} XYZ colour\n */\nexport function convertRGBtoXYZ(colour: RGBColour): XYZColour {\n const { R, G, B } = colour;\n\n const _R = linearRGB(R) * 100;\n const _G = linearRGB(G) * 100;\n const _B = linearRGB(B) * 100;\n\n // Magic numbers are pre-calculated sRGB D65 constants\n const X = _R * 0.4124 + _G * 0.3576 + _B * 0.1805;\n const Y = _R * 0.2126 + _G * 0.7152 + _B * 0.0722;\n const Z = _R * 0.0193 + _G * 0.1192 + _B * 0.9505;\n\n return { X, Y, Z };\n}\n\n/**\n * Converts XYZ colour space to Lab\n * Math comes from https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[11]\n * @param colour XYZ colour\n * @return {LabColour} Lab colour\n */\nexport function convertXYZtoLab(colour: XYZColour): LabColour {\n const { X, Y, Z } = colour;\n\n // Magic numbers are normalised for relative luminance from the D65 standard\n const _X = X / 95.047;\n const _Y = Y / 100;\n const _Z = Z / 108.883;\n\n const fX = constrainLab(_X);\n const fY = constrainLab(_Y);\n const fZ = constrainLab(_Z);\n\n const L = 116 * fY - 16;\n const a = 500 * (fX - fY);\n const b = 200 * (fY - fZ);\n\n return { L, a, b };\n}\n\n/**\n * Indirectly converts RGB to Lab.\n * First converts RGB to XYZ,\n * Then converts XYZ to Lab\n * @param {RGBColour} colour sRGB colour\n * @return {LabColour} Lab colour\n */\nexport function convertRGBtoLab(colour: RGBColour): LabColour {\n const XYZColour = convertRGBtoXYZ(colour);\n return convertXYZtoLab(XYZColour);\n}\n","import { ciede2000 } from \"./CIEDE2000.js\";\nimport { convertRGBtoLab } from \"./converters.js\";\nimport type { RGBColour } from \"./types\";\n\nexport const RGBdistance = (colour1: RGBColour, colour2: RGBColour): number => {\n const c1 = convertRGBtoLab(colour1);\n const c2 = convertRGBtoLab(colour2);\n\n return ciede2000(c1, c2);\n};\n","export { ciede2000 } from \"./CIEDE2000.js\";\nexport {\n convertRGBtoXYZ,\n convertRGBtoLab,\n convertXYZtoLab,\n} from \"./converters.js\";\nexport { RGBdistance } from \"./RGBdistance.js\";\n"],"names":[],"mappings":"SAOgB,KAAK,CAAC,CAAS,CAAE,CAAS,CAAU,CAAC,AAEnD,EAAE,CAAQ,CAAC,GAAP,CAAC,EAAgB,CAAC,GAAP,CAAC,CACd,MAAM,CAAC,CAAC,CAGV,KAAK,CAAC,CAAK,CAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,GAAK,GAAG,CAAG,IAAI,CAAC,EAAE,SAC3C,CAAK,EAAI,CAAC,CACL,CAAK,CAEP,CAAK,CAAG,GAAG,AACpB,CAAC,SAMe,UAAU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(exports);else{var c={exports:{}};b(c.exports),a.index=c.exports}}(this,function(a){"use strict";function b(a,b){if(0===a&&0===b)return 0;const c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}Object.defineProperty(a,"__esModule",{value:!0}),a.RGBdistance=a.convertXYZtoLab=a.convertRGBtoLab=a.convertRGBtoXYZ=a.ciede2000=void 0;const c=a=>a*(Math.PI/180),d=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function e(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function f(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function g(a,e){const f=a.L,g=a.a,h=a.b,i=e.L,j=e.a,k=e.b,l=Math.sqrt(Math.pow(g,2)+Math.pow(h,2)),m=Math.sqrt(Math.pow(j,2)+Math.pow(k,2)),n=.5*(1-d((l+m)/2)),o=g*(1+n),p=j*(1+n),q=Math.sqrt(Math.pow(o,2)+Math.pow(h,2)),r=Math.sqrt(Math.pow(p,2)+Math.pow(k,2)),s=(q+r)/2,t=r-q,u=b(h,o),v=b(k,p),w=function({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}({C1:l,C2:m,h1_d:u,h2_d:v}),x=2*Math.sqrt(q*r)*Math.sin(c(w)/2),y=function({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}({C1:l,C2:m,h1_d:u,h2_d:v}),z=(f+i)/2,A=1-.17*Math.cos(c(y-30))+.24*Math.cos(c(2*y))+.32*Math.cos(c(3*y+6))-.2*Math.cos(c(4*y-63)),B=.045*s+1,C=1+.015*s*A,D=-2*d(s)*Math.sin(c(2*(30*Math.exp(-Math.pow((y-275)/25,2)))));return Math.sqrt(Math.pow((i-f)/(1*(1+.015*Math.pow(z-50,2)/Math.sqrt(20+Math.pow(z-50,2)))),2)+Math.pow(t/(1*B),2)+Math.pow(x/(1*C),2)+D*(t/(1*B))*(x/(1*C)))}function h(a){const{R:b,G:c,B:d}=a,f=100*e(b),g=100*e(c),h=100*e(d);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function i(a){const{X:b,Y:c,Z:d}=a,e=f(b/95.047),g=f(c/100),h=f(d/108.883);return{L:116*g-16,a:500*(e-g),b:200*(g-h)}}function j(a){const b=h(a);return i(b)}a.ciede2000=g,a.convertRGBtoXYZ=h,a.convertRGBtoLab=j,a.convertXYZtoLab=i,a.RGBdistance=(a,b)=>{const c=j(a),d=j(b);return g(c,d)}})
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=index.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"names":[],"mappings":"6NAAS,CAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,wIAAsS,KAAK,CAAC,CAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAQ,CAAS,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,YAAY,CAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CA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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAe,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAe,CAAC,CAAC,CAAC,CAAC,EAAqH,SAAS,CAAtB,CAAS,GAAyC,eAAe,CAAlC,CAAe,GAAuC,eAAe,CAAlC,CAAe,GAAuC,eAAe,CAAlC,CAAe,GAA2C,WAAW,EAA/P,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC","file":"index.umd.js","sourcesContent":["function hue_d(a,b){if(0===a&&0===b)return 0;const c=Math.atan2(a,b)*(180/Math.PI);return c>=0?c:c+360}function deltaHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?0:180>=Math.abs(d-c)?d-c:d-c>180?d-c-360:d-c< -180?d-c+360:0}function meanHue_d({C1:a,C2:b,h1_d:c,h2_d:d}){return a*b==0?d+c:180>=Math.abs(c-d)?(d+c)/2:Math.abs(c-d)>180&&c+d<360?(d+c+360)/2:Math.abs(c-d)>180&&c+d>=360?(d+c-360)/2:0}const toRadians=a=>a*(Math.PI/180);const bigSquare=a=>Math.sqrt(Math.pow(a,7)/(Math.pow(a,7)+6103515625));function linearRGB(a){const b=a/255;return b>.04045?Math.pow((b+.055)/1.055,2.4):b/12.92}function constrainLab(a){const b=6/29;return a>Math.pow(b,3)?Math.cbrt(a):a/(3*Math.pow(b,2))+4/29}function ciede2000(f,g){const h=f.L,i=f.a,j=f.b,k=g.L,l=g.a,m=g.b,n=Math.sqrt(Math.pow(i,2)+Math.pow(j,2)),o=Math.sqrt(Math.pow(l,2)+Math.pow(m,2)),p=.5*(1-bigSquare((n+o)/2)),q=i*(1+p),r=l*(1+p),s=Math.sqrt(Math.pow(q,2)+Math.pow(j,2)),t=Math.sqrt(Math.pow(r,2)+Math.pow(m,2)),u=(s+t)/2,v=t-s,w=hue_d(j,q),x=hue_d(m,r),y=deltaHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),z=2*Math.sqrt(s*t)*Math.sin(toRadians(y)/2),A=meanHue_d({C1:n,C2:o,h1_d:w,h2_d:x}),B=(h+k)/2,C=1-.17*Math.cos(toRadians(A-30))+.24*Math.cos(toRadians(2*A))+.32*Math.cos(toRadians(3*A+6))-.2*Math.cos(toRadians(4*A-63)),D=.045*u+1,E=1+.015*u*C,F=-2*bigSquare(u)*Math.sin(toRadians(2*(30*Math.exp(-Math.pow((A-275)/25,2)))));return Math.sqrt(Math.pow((k-h)/(1*(1+.015*Math.pow(B-50,2)/Math.sqrt(20+Math.pow(B-50,2)))),2)+Math.pow(v/(1*D),2)+Math.pow(z/(1*E),2)+F*(v/(1*D))*(z/(1*E)))}function convertRGBtoXYZ(a){const{R:c,G:d,B:e}=a,f=100*linearRGB(c),g=100*linearRGB(d),h=100*linearRGB(e);return{X:.4124*f+.3576*g+.1805*h,Y:.2126*f+.7152*g+.0722*h,Z:.0193*f+.1192*g+.9505*h}}function convertXYZtoLab(b){const{X:c,Y:d,Z:e}=b,f=constrainLab(c/95.047),g=constrainLab(d/100),h=constrainLab(e/108.883);return{L:116*g-16,a:500*(f-g),b:200*(g-h)}}function convertRGBtoLab(a){const b=convertRGBtoXYZ(a);return convertXYZtoLab(b)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertRGBtoXYZ as convertRGBtoXYZ,convertRGBtoLab as convertRGBtoLab,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}"]}
|