@sardine/colour 1.1.0 → 1.1.1

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.
@@ -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;
@@ -0,0 +1,2 @@
1
+ import type { RGBColour } from "./types";
2
+ export declare const RGBdistance: (colour1: RGBColour, colour2: RGBColour) => number;
@@ -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;
@@ -52,5 +52,45 @@ import { constrainLab, linearRGB } from "./util/index.js";
52
52
  const XYZColour = convertRGBtoXYZ(colour);
53
53
  return convertXYZtoLab(XYZColour);
54
54
  }
55
+ export function convertHextoRGB(hex) {
56
+ /** Six digit Hexadecimal colour, ie: #12FF21 */ const hexRegex = /^#[a-fA-F0-9]{6}$/;
57
+ /** Eight digit Hexadecimal colour, ie: #12FF21BE */ const hexAlphaRegex = /^#[a-fA-F0-9]{8}$/;
58
+ /** Three digit Hexadecimal colour, ie: #FFF */ const shortHexRegex = /^#[a-fA-F0-9]{3}$/;
59
+ /** Four digit Hexadecimal colour, ie: #FFF4 */ const shortAlphaHexRegex = /^#[a-fA-F0-9]{4}$/;
60
+ if (typeof hex !== "string") {
61
+ throw new Error(`convertHextoRGB expects a string but got a ${typeof hex}`);
62
+ }
63
+ if (hex.match(hexRegex)) {
64
+ return {
65
+ R: parseInt(`${hex[1]}${hex[2]}`, 16),
66
+ G: parseInt(`${hex[3]}${hex[4]}`, 16),
67
+ B: parseInt(`${hex[5]}${hex[6]}`, 16)
68
+ };
69
+ }
70
+ if (hex.match(shortHexRegex)) {
71
+ return {
72
+ R: parseInt(`${hex[1]}${hex[1]}`, 16),
73
+ G: parseInt(`${hex[2]}${hex[2]}`, 16),
74
+ B: parseInt(`${hex[3]}${hex[3]}`, 16)
75
+ };
76
+ }
77
+ if (hex.match(hexAlphaRegex)) {
78
+ return {
79
+ R: parseInt(`${hex[1]}${hex[2]}`, 16),
80
+ G: parseInt(`${hex[3]}${hex[4]}`, 16),
81
+ B: parseInt(`${hex[5]}${hex[6]}`, 16),
82
+ A: parseInt(`${hex[7]}${hex[8]}`, 16) / 255
83
+ };
84
+ }
85
+ if (hex.match(shortAlphaHexRegex)) {
86
+ return {
87
+ R: parseInt(`${hex[1]}${hex[1]}`, 16),
88
+ G: parseInt(`${hex[2]}${hex[2]}`, 16),
89
+ B: parseInt(`${hex[3]}${hex[3]}`, 16),
90
+ A: parseInt(`${hex[4]}${hex[4]}`, 16) / 255
91
+ };
92
+ }
93
+ throw new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${hex}`);
94
+ }
55
95
 
56
96
  //# sourceMappingURL=converters.js.map
@@ -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","col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C,GAAG,GAAG;IAClB,KAAK,CAACK,EAAE,GAAGJ,CAAC,GAAG,OAAO;IAEtB,KAAK,CAACK,EAAE,GAAGjB,YAAY,CAACc,EAAE;IAC1B,KAAK,CAACI,EAAE,GAAGlB,YAAY,CAACe,EAAE;IAC1B,KAAK,CAACI,EAAE,GAAGnB,YAAY,CAACgB,EAAE;IAE1B,KAAK,CAACI,CAAC,GAAG,GAAG,GAAGF,EAAE,GAAG,EAAE;IACvB,KAAK,CAACG,CAAC,GAAG,GAAG,IAAIJ,EAAE,GAAGC,EAAE;IACxB,KAAK,CAACI,CAAC,GAAG,GAAG,IAAIJ,EAAE,GAAGC,EAAE;IAExB,MAAM,CAAC,CAAC;QAACC,CAAC;QAAEC,CAAC;QAAEC,CAAC;IAAC,CAAC;AACpB,CAAC;AAED,EAMG,AANH;;;;;;CAMG,AANH,EAMG,CACH,MAAM,UAAUC,eAAe,CAACpB,MAAiB,EAAa,CAAC;IAC7D,KAAK,CAACqB,SAAS,GAAGtB,eAAe,CAACC,MAAM;IACxC,MAAM,CAACU,eAAe,CAACW,SAAS;AAClC,CAAC"}
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","_X","_Y","_Z","fX","fY","fZ","L","a","b","convertRGBtoLab","XYZColour","convertHextoRGB","hex","hexRegex","hexAlphaRegex","shortHexRegex","shortAlphaHexRegex","Error","match","parseInt","A"],"mappings":"AACA,MAAM,GAAGA,YAAY,EAAEC,SAAS,QAAQ,CAAiB;AAEzD,EAKG,AALH;;;;;CAKG,AALH,EAKG,CACH,MAAM,UAAUC,eAAe,CAACC,MAAiB,EAAa,CAAC;IAC7D,KAAK,CAAC,CAAC,CAACC,CAAC,GAAEC,CAAC,GAAEC,CAAC,EAAC,CAAC,GAAGH,MAAM;IAE1B,KAAK,CAACI,EAAE,GAAGN,SAAS,CAACG,CAAC,IAAI,GAAG;IAC7B,KAAK,CAACI,EAAE,GAAGP,SAAS,CAACI,CAAC,IAAI,GAAG;IAC7B,KAAK,CAACI,EAAE,GAAGR,SAAS,CAACK,CAAC,IAAI,GAAG;IAE7B,EAAsD,AAAtD,oDAAsD;IACtD,KAAK,CAACI,CAAC,GAAGH,EAAE,GAAG,MAAM,GAAGC,EAAE,GAAG,MAAM,GAAGC,EAAE,GAAG,MAAM;IAC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GBdistance } from "./RGBdistance.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ciede2000 } from "./CIEDE2000.js";
2
- export { convertRGBtoXYZ, convertRGBtoLab, convertXYZtoLab } from "./converters.js";
2
+ export { convertHextoRGB, convertRGBtoLab, convertRGBtoXYZ, convertXYZtoLab } from "./converters.js";
3
3
  export { RGBdistance } from "./RGBdistance.js";
4
4
 
5
5
  //# 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 convertRGBtoXYZ,\n convertRGBtoLab,\n convertXYZtoLab,\n} from \"./converters.js\";\nexport { RGBdistance } from \"./RGBdistance.js\";\n"],"names":["ciede2000","convertRGBtoXYZ","convertRGBtoLab","convertXYZtoLab","RGBdistance"],"mappings":"AAAA,MAAM,GAAGA,SAAS,QAAQ,CAAgB;AAC1C,MAAM,GACJC,eAAe,EACfC,eAAe,EACfC,eAAe,QACV,CAAiB;AACxB,MAAM,GAAGC,WAAW,QAAQ,CAAkB"}
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,MAAM,GAAGA,SAAS,QAAQ,CAAgB;AAC1C,MAAM,GACJC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,eAAe,QACV,CAAiB;AACxB,MAAM,GAAGC,WAAW,QAAQ,CAAkB"}
@@ -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
+ }
package/dist/umd/index.js CHANGED
@@ -1 +1 @@
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}
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)}function convertHextoRGB(a){if("string"!=typeof a)throw new 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 new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${a}`)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertHextoRGB as convertHextoRGB,convertRGBtoLab as convertRGBtoLab,convertRGBtoXYZ as convertRGBtoXYZ,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}
@@ -1 +1 @@
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,KA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EjB,MAAM,gBAAG,WAAW"}
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\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","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 convertHextoRGB,\n convertRGBtoLab,\n convertRGBtoXYZ,\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,CAAC,CAAC,AAAC,EAAE,CAAF,CAAE,CAAE,EAAE,CAAF,CAAE,CAAE,IAAI,CAAJ,CAAI,CAAE,IAAI,CAAJ,CAAI,AAAY,CAAC,CAAU,CAAC,OACjE,CAAE,CAAG,CAAE,EAAK,CAAC,CACR,CAAC,CAEmB,GAAG,EAA5B,IAAI,CAAC,GAAG,CAAC,CAAI,CAAG,C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AO,EAElC,MAAM,WAAW,CAAE,CAAE,CAAE,CACzB,CAAC,CCTD,MAAM,cAAG,SAAS,EAClB,MAAM,oBACJ,eAAe,oBACf,eAAe,oBACf,eAAe,oBACf,eAAe,EAEjB,MAAM,gBAAG,WAAW"}
@@ -1,3 +1,3 @@
1
- !function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(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)}})
1
+ !function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(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.convertRGBtoXYZ=a.convertRGBtoLab=a.convertHextoRGB=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.convertHextoRGB=function(a){if("string"!=typeof a)throw new 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 new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${a}`)},a.convertRGBtoLab=j,a.convertRGBtoXYZ=h,a.convertXYZtoLab=i,a.RGBdistance=(a,b)=>{const c=j(a),d=j(b);return g(c,d)}})
2
2
 
3
3
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
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,E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AAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAe,CAAC,CAAC,CAAC,CAAC,KAAK,AAAyF,CAAxF,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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}"]}
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,0JAAsS,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,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CA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: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)}function convertHextoRGB(a){if(\"string\"!=typeof a)throw new 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 new Error(`convertHextoRGB expects an valid hexadecimal colour value but got ${a}`)}const RGBdistance=(c,d)=>{const e=convertRGBtoLab(c),f=convertRGBtoLab(d);return ciede2000(e,f)};export{ciede2000 as ciede2000};export{convertHextoRGB as convertHextoRGB,convertRGBtoLab as convertRGBtoLab,convertRGBtoXYZ as convertRGBtoXYZ,convertXYZtoLab as convertXYZtoLab};export{RGBdistance as RGBdistance}"]}
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sardine/colour",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "It does things to colours",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",