@lakuna/color 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/names/bang.d.ts +9 -0
- package/dist/names/bang.d.ts.map +1 -0
- package/dist/names/bang.js +481 -0
- package/dist/names/bang.js.map +1 -0
- package/dist/names/cne.d.ts +9 -0
- package/dist/names/cne.d.ts.map +1 -0
- package/dist/names/cne.js +875 -0
- package/dist/names/cne.js.map +1 -0
- package/dist/names/crayola.d.ts +9 -0
- package/dist/names/crayola.d.ts.map +1 -0
- package/dist/names/crayola.js +130 -0
- package/dist/names/crayola.js.map +1 -0
- package/dist/names/getName.d.ts +20 -0
- package/dist/names/getName.d.ts.map +1 -0
- package/dist/names/getName.js +34 -0
- package/dist/names/getName.js.map +1 -0
- package/dist/names/hollasch.d.ts +9 -0
- package/dist/names/hollasch.d.ts.map +1 -0
- package/dist/names/hollasch.js +201 -0
- package/dist/names/hollasch.js.map +1 -0
- package/dist/names/nbs.d.ts +9 -0
- package/dist/names/nbs.d.ts.map +1 -0
- package/dist/names/nbs.js +277 -0
- package/dist/names/nbs.js.map +1 -0
- package/dist/names/ntc.d.ts +9 -0
- package/dist/names/ntc.d.ts.map +1 -0
- package/dist/names/ntc.js +1576 -0
- package/dist/names/ntc.js.map +1 -0
- package/dist/names/resene.d.ts +9 -0
- package/dist/names/resene.d.ts.map +1 -0
- package/dist/names/resene.js +1388 -0
- package/dist/names/resene.js.map +1 -0
- package/dist/names/x11.d.ts +9 -0
- package/dist/names/x11.d.ts.map +1 -0
- package/dist/names/x11.js +465 -0
- package/dist/names/x11.js.map +1 -0
- package/dist/names/xkcd.d.ts +9 -0
- package/dist/names/xkcd.d.ts.map +1 -0
- package/dist/names/xkcd.js +932 -0
- package/dist/names/xkcd.js.map +1 -0
- package/dist/types/Adobe.d.ts +15 -0
- package/dist/types/Adobe.d.ts.map +1 -0
- package/dist/types/Adobe.js +2 -0
- package/dist/types/Adobe.js.map +1 -0
- package/dist/types/Cmy.d.ts +15 -0
- package/dist/types/Cmy.d.ts.map +1 -0
- package/dist/types/Cmy.js +2 -0
- package/dist/types/Cmy.js.map +1 -0
- package/dist/types/Cmyk.d.ts +17 -0
- package/dist/types/Cmyk.d.ts.map +1 -0
- package/dist/types/Cmyk.js +2 -0
- package/dist/types/Cmyk.js.map +1 -0
- package/dist/types/Color.d.ts +6 -0
- package/dist/types/Color.d.ts.map +1 -0
- package/dist/types/Color.js +2 -0
- package/dist/types/Color.js.map +1 -0
- package/dist/types/Hsl.d.ts +15 -0
- package/dist/types/Hsl.d.ts.map +1 -0
- package/dist/types/Hsl.js +2 -0
- package/dist/types/Hsl.js.map +1 -0
- package/dist/types/Hsv.d.ts +15 -0
- package/dist/types/Hsv.d.ts.map +1 -0
- package/dist/types/Hsv.js +2 -0
- package/dist/types/Hsv.js.map +1 -0
- package/dist/types/Hunter.d.ts +15 -0
- package/dist/types/Hunter.d.ts.map +1 -0
- package/dist/types/Hunter.js +2 -0
- package/dist/types/Hunter.js.map +1 -0
- package/dist/types/Lab.d.ts +15 -0
- package/dist/types/Lab.d.ts.map +1 -0
- package/dist/types/Lab.js +2 -0
- package/dist/types/Lab.js.map +1 -0
- package/dist/types/Lch.d.ts +16 -0
- package/dist/types/Lch.d.ts.map +1 -0
- package/dist/types/Lch.js +2 -0
- package/dist/types/Lch.js.map +1 -0
- package/dist/types/Luv.d.ts +15 -0
- package/dist/types/Luv.d.ts.map +1 -0
- package/dist/types/Luv.js +2 -0
- package/dist/types/Luv.js.map +1 -0
- package/dist/types/Rgb.d.ts +15 -0
- package/dist/types/Rgb.d.ts.map +1 -0
- package/dist/types/Rgb.js +2 -0
- package/dist/types/Rgb.js.map +1 -0
- package/dist/types/Xyz.d.ts +15 -0
- package/dist/types/Xyz.d.ts.map +1 -0
- package/dist/types/Xyz.js +2 -0
- package/dist/types/Xyz.js.map +1 -0
- package/dist/types/Yxy.d.ts +15 -0
- package/dist/types/Yxy.d.ts.map +1 -0
- package/dist/types/Yxy.js +2 -0
- package/dist/types/Yxy.js.map +1 -0
- package/dist/utility/StandardIlluminant.d.ts +89 -0
- package/dist/utility/StandardIlluminant.d.ts.map +1 -0
- package/dist/utility/StandardIlluminant.js +90 -0
- package/dist/utility/StandardIlluminant.js.map +1 -0
- package/dist/utility/adobeToXyz.d.ts +10 -0
- package/dist/utility/adobeToXyz.d.ts.map +1 -0
- package/dist/utility/adobeToXyz.js +17 -0
- package/dist/utility/adobeToXyz.js.map +1 -0
- package/dist/utility/cmyToCmyk.d.ts +10 -0
- package/dist/utility/cmyToCmyk.d.ts.map +1 -0
- package/dist/utility/cmyToCmyk.js +19 -0
- package/dist/utility/cmyToCmyk.js.map +1 -0
- package/dist/utility/cmyToRgb.d.ts +10 -0
- package/dist/utility/cmyToRgb.d.ts.map +1 -0
- package/dist/utility/cmyToRgb.js +10 -0
- package/dist/utility/cmyToRgb.js.map +1 -0
- package/dist/utility/cmykToCmy.d.ts +10 -0
- package/dist/utility/cmykToCmy.d.ts.map +1 -0
- package/dist/utility/cmykToCmy.js +16 -0
- package/dist/utility/cmykToCmy.js.map +1 -0
- package/dist/utility/contrast.d.ts +12 -0
- package/dist/utility/contrast.d.ts.map +1 -0
- package/dist/utility/contrast.js +17 -0
- package/dist/utility/contrast.js.map +1 -0
- package/dist/utility/deltaC.d.ts +21 -0
- package/dist/utility/deltaC.d.ts.map +1 -0
- package/dist/utility/deltaC.js +4 -0
- package/dist/utility/deltaC.js.map +1 -0
- package/dist/utility/deltaCmc.d.ts +13 -0
- package/dist/utility/deltaCmc.d.ts.map +1 -0
- package/dist/utility/deltaCmc.js +46 -0
- package/dist/utility/deltaCmc.js.map +1 -0
- package/dist/utility/deltaE00.d.ts +13 -0
- package/dist/utility/deltaE00.d.ts.map +1 -0
- package/dist/utility/deltaE00.js +90 -0
- package/dist/utility/deltaE00.js.map +1 -0
- package/dist/utility/deltaE76.d.ts +21 -0
- package/dist/utility/deltaE76.d.ts.map +1 -0
- package/dist/utility/deltaE76.js +4 -0
- package/dist/utility/deltaE76.js.map +1 -0
- package/dist/utility/deltaE94.d.ts +13 -0
- package/dist/utility/deltaE94.d.ts.map +1 -0
- package/dist/utility/deltaE94.js +29 -0
- package/dist/utility/deltaE94.js.map +1 -0
- package/dist/utility/deltaH.d.ts +21 -0
- package/dist/utility/deltaH.d.ts.map +1 -0
- package/dist/utility/deltaH.js +14 -0
- package/dist/utility/deltaH.js.map +1 -0
- package/dist/utility/getReference.d.ts +9 -0
- package/dist/utility/getReference.d.ts.map +1 -0
- package/dist/utility/getReference.js +92 -0
- package/dist/utility/getReference.js.map +1 -0
- package/dist/utility/hexToRgb.d.ts +9 -0
- package/dist/utility/hexToRgb.d.ts.map +1 -0
- package/dist/utility/hexToRgb.js +10 -0
- package/dist/utility/hexToRgb.js.map +1 -0
- package/dist/utility/hslToRgb.d.ts +10 -0
- package/dist/utility/hslToRgb.d.ts.map +1 -0
- package/dist/utility/hslToRgb.js +46 -0
- package/dist/utility/hslToRgb.js.map +1 -0
- package/dist/utility/hsvToRgb.d.ts +10 -0
- package/dist/utility/hsvToRgb.d.ts.map +1 -0
- package/dist/utility/hsvToRgb.js +34 -0
- package/dist/utility/hsvToRgb.js.map +1 -0
- package/dist/utility/hunterToXyz.d.ts +11 -0
- package/dist/utility/hunterToXyz.d.ts.map +1 -0
- package/dist/utility/hunterToXyz.js +26 -0
- package/dist/utility/hunterToXyz.js.map +1 -0
- package/dist/utility/labToLch.d.ts +11 -0
- package/dist/utility/labToLch.d.ts.map +1 -0
- package/dist/utility/labToLch.js +19 -0
- package/dist/utility/labToLch.js.map +1 -0
- package/dist/utility/labToXyz.d.ts +11 -0
- package/dist/utility/labToXyz.d.ts.map +1 -0
- package/dist/utility/labToXyz.js +23 -0
- package/dist/utility/labToXyz.js.map +1 -0
- package/dist/utility/lchToLab.d.ts +11 -0
- package/dist/utility/lchToLab.d.ts.map +1 -0
- package/dist/utility/lchToLab.js +14 -0
- package/dist/utility/lchToLab.js.map +1 -0
- package/dist/utility/luvToXyz.d.ts +11 -0
- package/dist/utility/luvToXyz.d.ts.map +1 -0
- package/dist/utility/luvToXyz.js +28 -0
- package/dist/utility/luvToXyz.js.map +1 -0
- package/dist/utility/relativeLuminance.d.ts +10 -0
- package/dist/utility/relativeLuminance.d.ts.map +1 -0
- package/dist/utility/relativeLuminance.js +20 -0
- package/dist/utility/relativeLuminance.js.map +1 -0
- package/dist/utility/rgbToCmy.d.ts +10 -0
- package/dist/utility/rgbToCmy.d.ts.map +1 -0
- package/dist/utility/rgbToCmy.js +10 -0
- package/dist/utility/rgbToCmy.js.map +1 -0
- package/dist/utility/rgbToHsl.d.ts +10 -0
- package/dist/utility/rgbToHsl.d.ts.map +1 -0
- package/dist/utility/rgbToHsl.js +32 -0
- package/dist/utility/rgbToHsl.js.map +1 -0
- package/dist/utility/rgbToHsv.d.ts +10 -0
- package/dist/utility/rgbToHsv.d.ts.map +1 -0
- package/dist/utility/rgbToHsv.js +29 -0
- package/dist/utility/rgbToHsv.js.map +1 -0
- package/dist/utility/rgbToXyz.d.ts +10 -0
- package/dist/utility/rgbToXyz.d.ts.map +1 -0
- package/dist/utility/rgbToXyz.js +20 -0
- package/dist/utility/rgbToXyz.js.map +1 -0
- package/dist/utility/xyzToAdobe.d.ts +10 -0
- package/dist/utility/xyzToAdobe.d.ts.map +1 -0
- package/dist/utility/xyzToAdobe.js +17 -0
- package/dist/utility/xyzToAdobe.js.map +1 -0
- package/dist/utility/xyzToHunter.d.ts +11 -0
- package/dist/utility/xyzToHunter.d.ts.map +1 -0
- package/dist/utility/xyzToHunter.js +25 -0
- package/dist/utility/xyzToHunter.js.map +1 -0
- package/dist/utility/xyzToLab.d.ts +11 -0
- package/dist/utility/xyzToLab.d.ts.map +1 -0
- package/dist/utility/xyzToLab.js +21 -0
- package/dist/utility/xyzToLab.js.map +1 -0
- package/dist/utility/xyzToLuv.d.ts +11 -0
- package/dist/utility/xyzToLuv.d.ts.map +1 -0
- package/dist/utility/xyzToLuv.js +30 -0
- package/dist/utility/xyzToLuv.js.map +1 -0
- package/dist/utility/xyzToRgb.d.ts +10 -0
- package/dist/utility/xyzToRgb.d.ts.map +1 -0
- package/dist/utility/xyzToRgb.js +20 -0
- package/dist/utility/xyzToRgb.js.map +1 -0
- package/dist/utility/xyzToYxy.d.ts +10 -0
- package/dist/utility/xyzToYxy.d.ts.map +1 -0
- package/dist/utility/xyzToYxy.js +16 -0
- package/dist/utility/xyzToYxy.js.map +1 -0
- package/dist/utility/yxyToXyz.d.ts +10 -0
- package/dist/utility/yxyToXyz.d.ts.map +1 -0
- package/dist/utility/yxyToXyz.js +16 -0
- package/dist/utility/yxyToXyz.js.map +1 -0
- package/package.json +59 -0
- package/src/index.ts +61 -0
- package/src/names/bang.ts +483 -0
- package/src/names/cne.ts +877 -0
- package/src/names/crayola.ts +132 -0
- package/src/names/getName.ts +51 -0
- package/src/names/hollasch.ts +203 -0
- package/src/names/nbs.ts +279 -0
- package/src/names/ntc.ts +1578 -0
- package/src/names/resene.ts +1390 -0
- package/src/names/x11.ts +467 -0
- package/src/names/xkcd.ts +934 -0
- package/src/types/Adobe.ts +17 -0
- package/src/types/Cmy.ts +17 -0
- package/src/types/Cmyk.ts +20 -0
- package/src/types/Color.ts +5 -0
- package/src/types/Hsl.ts +17 -0
- package/src/types/Hsv.ts +17 -0
- package/src/types/Hunter.ts +17 -0
- package/src/types/Lab.ts +17 -0
- package/src/types/Lch.ts +18 -0
- package/src/types/Luv.ts +17 -0
- package/src/types/Rgb.ts +17 -0
- package/src/types/Xyz.ts +17 -0
- package/src/types/Yxy.ts +17 -0
- package/src/utility/StandardIlluminant.ts +128 -0
- package/src/utility/adobeToXyz.ts +20 -0
- package/src/utility/cmyToCmyk.ts +23 -0
- package/src/utility/cmyToRgb.ts +12 -0
- package/src/utility/cmykToCmy.ts +19 -0
- package/src/utility/contrast.ts +19 -0
- package/src/utility/deltaC.ts +26 -0
- package/src/utility/deltaCmc.ts +59 -0
- package/src/utility/deltaE00.ts +105 -0
- package/src/utility/deltaE76.ts +30 -0
- package/src/utility/deltaE94.ts +41 -0
- package/src/utility/deltaH.ts +39 -0
- package/src/utility/getReference.ts +95 -0
- package/src/utility/hexToRgb.ts +11 -0
- package/src/utility/hslToRgb.ts +53 -0
- package/src/utility/hsvToRgb.ts +44 -0
- package/src/utility/hunterToXyz.ts +33 -0
- package/src/utility/labToLch.ts +24 -0
- package/src/utility/labToXyz.ts +29 -0
- package/src/utility/lchToLab.ts +18 -0
- package/src/utility/luvToXyz.ts +35 -0
- package/src/utility/relativeLuminance.ts +25 -0
- package/src/utility/rgbToCmy.ts +12 -0
- package/src/utility/rgbToHsl.ts +38 -0
- package/src/utility/rgbToHsv.ts +35 -0
- package/src/utility/rgbToXyz.ts +23 -0
- package/src/utility/xyzToAdobe.ts +20 -0
- package/src/utility/xyzToHunter.ts +32 -0
- package/src/utility/xyzToLab.ts +27 -0
- package/src/utility/xyzToLuv.ts +38 -0
- package/src/utility/xyzToRgb.ts +23 -0
- package/src/utility/xyzToYxy.ts +19 -0
- package/src/utility/yxyToXyz.ts +19 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An Adobe RGB (opRGB) representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/Adobe_RGB_color_space | Adobe RGB color space}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Adobe extends Color {
|
|
9
|
+
/** The red channel of this color in the range `[0x00,0xff]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The green channel of this color in the range `[0x00,0xff]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The blue channel of this color in the range `[0x00,0xff]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Cmy.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CMY representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CMYK_color_model | CMYK color model}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Cmy extends Color {
|
|
9
|
+
/** The cyan channel of this color in the range `[0,1]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The magenta channel of this color in the range `[0,1]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The yellow channel of this color in the range `[0,1]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CMYK representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CMYK_color_model | CMYK color model}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Cmyk extends Color {
|
|
9
|
+
/** The cyan channel of this color in the range `[0,1]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The magenta channel of this color in the range `[0,1]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The yellow channel of this color in the range `[0,1]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
|
|
18
|
+
/** The key (black) channel of this color in the range `[0,1]`. */
|
|
19
|
+
3: number;
|
|
20
|
+
}
|
package/src/types/Hsl.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An HSL (HLS) representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/HSL_and_HSV | HSL and HSV}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Hsl extends Color {
|
|
9
|
+
/** The hue channel of this color in the range `[0,1]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The saturation channel of this color in the range `[0,1]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The lightness channel of this color in the range `[0,1]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Hsv.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An HSV (HSB) representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/HSL_and_HSV | HSL and HSV}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Hsv extends Color {
|
|
9
|
+
/** The hue channel of this color in the range `[0,1]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The saturation channel of this color in the range `[0,1]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The value (brightness) channel of this color in the range `[0,1]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Hunter Lab representation of a color. Designed to be computed via simple formulas from CIEXYZ color space, but to be more perceptually uniform. A precursor to CIELAB.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/Hunter_Lab | Hunter Lab}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Hunter extends Color {
|
|
9
|
+
/** The L (lightness) value of this color in the range `[0,100]` (lighter values are whiter). */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The a opponent color axis value of this color. The positive direction represents redness, while the negative direction represents greenness. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The b opponent color axis value of this color. The positive direction represents yellowness, while the negative direction represents blueness. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Lab.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CIELAB (L*a*b*) representation of a color. Intended to be a perceptually uniform space. Derived from CIEXYZ. Colors are defined relative to a standard observer. Compared to CIELUV, CIELAB is considered better for reflective surface colors.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CIELAB_color_space | CIELAB color space}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Lab extends Color {
|
|
9
|
+
/** The L* (perceptual brightness) value of this color in the range `[0,100]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The a* value of this color. Forms a Cartesian coordinate pair with b* to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The b* value of this color. Forms a Cartesian coordinate pair with a* to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Lch.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CIELCh (CIEHLC) representation of a color. Intended to be a perceptually uniform space. Colors are defined relative to a standard observer.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CIELAB_color_space | CIELAB color space}
|
|
6
|
+
* @see {@link https://en.wikipedia.org/wiki/CIELUV | CIELUV}
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export default interface Lch extends Color {
|
|
10
|
+
/** The L* (perceptual brightness) value of this color in the range `[0,100]`. */
|
|
11
|
+
0: number;
|
|
12
|
+
|
|
13
|
+
/** The C* (chroma or relative saturation) value of this color. Forms a polar coordinate pair with h° to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
14
|
+
1: number;
|
|
15
|
+
|
|
16
|
+
/** The h° (hue angle) value of this color. Forms a polar coordinate pair with C* to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
17
|
+
2: number;
|
|
18
|
+
}
|
package/src/types/Luv.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CIELUV (CIE 1976 L*,u*,v*) representation of a color. Intended to be a perceptually uniform space. Derived from CIEXYZ. Colors are defined relative to a standard observer. Compared to CIELAB, CIELUV is considered better for emissive, self-illuminated colors (such as those on a monitor).
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CIELUV | CIELUV}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Luv extends Color {
|
|
9
|
+
/** The L* (perceptual brightness) value of this color in the range `[0,100]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The u* value of this color. Forms a Cartesian coordinate pair with v* to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The v* value of this color. Forms a Cartesian coordinate pair with u* to represent the four unique colors of human vision (red, green, blue, and yellow). */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Rgb.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A standard RGB (sRGB) representation of a color.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/SRGB | sRGB}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Rgb extends Color {
|
|
9
|
+
/** The red channel of this color in the range `[0x00,0xff]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The green channel of this color in the range `[0x00,0xff]`. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The blue channel of this color in the range `[0x00,0xff]`. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Xyz.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CIEXYZ (CIE 1931) representation of a color. Colors are defined relative to a standard observer.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CIE_1931_color_space | CIE 1931 color space}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Xyz extends Color {
|
|
9
|
+
/** The X value of this color. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The Y value of this color. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The Z value of this color. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
package/src/types/Yxy.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Color } from "./Color.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A CIEXYZ (CIE 1931) Yxy representation of a color. Colors are defined relative to a standard observer.
|
|
5
|
+
* @see {@link https://en.wikipedia.org/wiki/CIE_1931_color_space | CIE 1931 color space}
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export default interface Yxy extends Color {
|
|
9
|
+
/** The Y value of this color in the range `[0,100]`. */
|
|
10
|
+
0: number;
|
|
11
|
+
|
|
12
|
+
/** The x value of this color. */
|
|
13
|
+
1: number;
|
|
14
|
+
|
|
15
|
+
/** The y value of this color. */
|
|
16
|
+
2: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A theoretical source of visible light with a published spectral power distribution that is used to provide a basis for comparing colors recorded under different lighting.
|
|
3
|
+
* @see {@link https://en.wikipedia.org/wiki/Standard_illuminant | Standard illuminant}
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
enum StandardIlluminant {
|
|
7
|
+
/** The CIE A standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent average incandescent/tungsten light. */
|
|
8
|
+
A_2,
|
|
9
|
+
|
|
10
|
+
/** The CIE A standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent average incandescent/tungsten light. */
|
|
11
|
+
A_10,
|
|
12
|
+
|
|
13
|
+
/** The CIE B standard illuminant with the standard (CIE 1931; 2°) observer. Formerly used to represent average direct sunlight at noon. */
|
|
14
|
+
B_2,
|
|
15
|
+
|
|
16
|
+
/** The CIE B standard illuminant with the supplementary (CIE 1964; 10°) observer. Formerly used to represent average direct sunlight at noon. */
|
|
17
|
+
B_10,
|
|
18
|
+
|
|
19
|
+
/** The CIE C standard illuminant with the standard (CIE 1931; 2°) observer. Formerly used to represent average daylight. */
|
|
20
|
+
C_2,
|
|
21
|
+
|
|
22
|
+
/** The CIE C standard illuminant with the supplementary (CIE 1964; 10°) observer. Formerly used to represent average daylight. */
|
|
23
|
+
C_10,
|
|
24
|
+
|
|
25
|
+
/** The CIE D50 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent ICC profile PCS. Typically used in the printing industry. */
|
|
26
|
+
D50_2,
|
|
27
|
+
|
|
28
|
+
/** The CIE D50 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent ICC profile PCS. Typically used in the printing industry. */
|
|
29
|
+
D50_10,
|
|
30
|
+
|
|
31
|
+
/** The CIE D55 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent mid-morning daylight. */
|
|
32
|
+
D55_2,
|
|
33
|
+
|
|
34
|
+
/** The CIE D55 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent mid-morning daylight. */
|
|
35
|
+
D55_10,
|
|
36
|
+
|
|
37
|
+
/** The CIE D65 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent daylight. The CIE standard, and the standard for nearly all display colorspaces and working spaces including sRGB and Adobe RGB. */
|
|
38
|
+
D65_2,
|
|
39
|
+
|
|
40
|
+
/** The CIE D65 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent daylight. The CIE standard, and the standard for nearly all display colorspaces and working spaces including sRGB and Adobe RGB. */
|
|
41
|
+
D65_10,
|
|
42
|
+
|
|
43
|
+
/** The CIE D75 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent North sky daylight. */
|
|
44
|
+
D75_2,
|
|
45
|
+
|
|
46
|
+
/** The CIE D75 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent North sky daylight. */
|
|
47
|
+
D75_10,
|
|
48
|
+
|
|
49
|
+
/** The CIE E standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent equal energy lighting. */
|
|
50
|
+
E_2,
|
|
51
|
+
|
|
52
|
+
/** The CIE E standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent equal energy lighting. */
|
|
53
|
+
E_10,
|
|
54
|
+
|
|
55
|
+
/** The CIE F1 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent daylight flourescent lamps. */
|
|
56
|
+
F1_2,
|
|
57
|
+
|
|
58
|
+
/** The CIE F1 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent daylight flourescent lamps. */
|
|
59
|
+
F1_10,
|
|
60
|
+
|
|
61
|
+
/** The CIE F2 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent cool flourescent lamps. */
|
|
62
|
+
F2_2,
|
|
63
|
+
|
|
64
|
+
/** The CIE F2 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent cool flourescent lamps. */
|
|
65
|
+
F2_10,
|
|
66
|
+
|
|
67
|
+
/** The CIE F3 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent white flourescent lamps. */
|
|
68
|
+
F3_2,
|
|
69
|
+
|
|
70
|
+
/** The CIE F3 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent white flourescent lamps. */
|
|
71
|
+
F3_10,
|
|
72
|
+
|
|
73
|
+
/** The CIE F4 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent warm white flourescent lamps. */
|
|
74
|
+
F4_2,
|
|
75
|
+
|
|
76
|
+
/** The CIE F4 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent warm white flourescent lamps. */
|
|
77
|
+
F4_10,
|
|
78
|
+
|
|
79
|
+
/** The CIE F5 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent daylight flourescent lamps. */
|
|
80
|
+
F5_2,
|
|
81
|
+
|
|
82
|
+
/** The CIE F5 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent daylight flourescent lamps. */
|
|
83
|
+
F5_10,
|
|
84
|
+
|
|
85
|
+
/** The CIE F6 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent lite white flourescent lamps. */
|
|
86
|
+
F6_2,
|
|
87
|
+
|
|
88
|
+
/** The CIE F6 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent lite white flourescent lamps. */
|
|
89
|
+
F6_10,
|
|
90
|
+
|
|
91
|
+
/** The CIE F7 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent daylight flourescent lamps (D65 simulator). */
|
|
92
|
+
F7_2,
|
|
93
|
+
|
|
94
|
+
/** The CIE F7 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent daylight flourescent lamps (D65 simulator). */
|
|
95
|
+
F7_10,
|
|
96
|
+
|
|
97
|
+
/** The CIE F8 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent Sylvania F40 flourescent lamps (D50 simulator). */
|
|
98
|
+
F8_2,
|
|
99
|
+
|
|
100
|
+
/** The CIE F8 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent Sylvania F40 flourescent lamps (D50 simulator). */
|
|
101
|
+
F8_10,
|
|
102
|
+
|
|
103
|
+
/** The CIE F9 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent cool white flourescent lamps. */
|
|
104
|
+
F9_2,
|
|
105
|
+
|
|
106
|
+
/** The CIE F9 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent cool white flourescent lamps. */
|
|
107
|
+
F9_10,
|
|
108
|
+
|
|
109
|
+
/** The CIE F10 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent Ultralume 50 and Philips TL85 flourescent lamps. */
|
|
110
|
+
F10_2,
|
|
111
|
+
|
|
112
|
+
/** The CIE F10 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent Ultralume 50 and Philips TL85 flourescent lamps. */
|
|
113
|
+
F10_10,
|
|
114
|
+
|
|
115
|
+
/** The CIE F11 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent Ultralume 40 and Philips TL84 flourescent lamps. */
|
|
116
|
+
F11_2,
|
|
117
|
+
|
|
118
|
+
/** The CIE F11 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent Ultralume 40 and Philips TL84 flourescent lamps. */
|
|
119
|
+
F11_10,
|
|
120
|
+
|
|
121
|
+
/** The CIE F12 standard illuminant with the standard (CIE 1931; 2°) observer. Used to represent Ultralume 30 and Philips TL83 flourescent lamps. */
|
|
122
|
+
F12_2,
|
|
123
|
+
|
|
124
|
+
/** The CIE F12 standard illuminant with the supplementary (CIE 1964; 10°) observer. Used to represent Ultralume 30 and Philips TL83 flourescent lamps. */
|
|
125
|
+
F12_10
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default StandardIlluminant;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type Adobe from "../types/Adobe.js";
|
|
2
|
+
import type Xyz from "../types/Xyz.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given Adobe RGB color to a CIEXYZ color. Based on the EasyRGB pseudo-code.
|
|
6
|
+
* @param color - The Adobe RGB color.
|
|
7
|
+
* @returns A CIEXYZ color.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export default function adobeToXyz(color: Adobe): Xyz {
|
|
11
|
+
const i0 = color[0] ** 2.19921875 * 0.00050991; // `(x / 0xff) ** 2.19921875 * 100`
|
|
12
|
+
const i1 = color[1] ** 2.19921875 * 0.00050991; // `(x / 0xff) ** 2.19921875 * 100`
|
|
13
|
+
const i2 = color[2] ** 2.19921875 * 0.00050991; // `(x / 0xff) ** 2.19921875 * 100`
|
|
14
|
+
|
|
15
|
+
return [
|
|
16
|
+
i0 * 0.57667 + i1 * 0.18555 + i2 * 0.18819,
|
|
17
|
+
i0 * 0.29738 + i1 * 0.62735 + i2 * 0.07527,
|
|
18
|
+
i0 * 0.02703 + i1 * 0.07069 + i2 * 0.9911
|
|
19
|
+
];
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type Cmy from "../types/Cmy.js";
|
|
2
|
+
import type Cmyk from "../types/Cmyk.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given CMY color to a CMYK color. Based on the EasyRGB pseudo-code.
|
|
6
|
+
* @param color - The CMY color.
|
|
7
|
+
* @returns A CMYK color.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export default function cmyToCmyk(color: Cmy): Cmyk {
|
|
11
|
+
// eslint-disable-next-line prefer-destructuring
|
|
12
|
+
const c = color[0];
|
|
13
|
+
// eslint-disable-next-line prefer-destructuring
|
|
14
|
+
const m = color[1];
|
|
15
|
+
// eslint-disable-next-line prefer-destructuring
|
|
16
|
+
const y = color[2];
|
|
17
|
+
|
|
18
|
+
const k = Math.min(c, m, y, 1);
|
|
19
|
+
|
|
20
|
+
return k === 1
|
|
21
|
+
? [0, 0, 0, 1]
|
|
22
|
+
: [(c - k) / (1 - k), (m - k) / (1 - k), (y - k) / (1 - k), k];
|
|
23
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type Cmy from "../types/Cmy.js";
|
|
2
|
+
import type Rgb from "../types/Rgb.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given CMY color to an sRGB color. Based on the EasyRGB pseudo-code.
|
|
6
|
+
* @param color - The CMY color.
|
|
7
|
+
* @returns An sRGB color.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export default function cmyToRgb(color: Cmy): Rgb {
|
|
11
|
+
return [(1 - color[0]) * 0xff, (1 - color[1]) * 0xff, (1 - color[2]) * 0xff];
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type Cmy from "../types/Cmy.js";
|
|
2
|
+
import type Cmyk from "../types/Cmyk.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given CMYK color to a CMY color. Based on the EasyRGB pseudo-code.
|
|
6
|
+
* @param color - The CMYK color
|
|
7
|
+
* @returns A CMY color.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export default function cmykToCmy(color: Cmyk): Cmy {
|
|
11
|
+
// eslint-disable-next-line prefer-destructuring
|
|
12
|
+
const k = color[3];
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
color[0] * (1 - k) + k,
|
|
16
|
+
color[1] * (1 - k) + k,
|
|
17
|
+
color[2] * (1 - k) + k
|
|
18
|
+
];
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type Rgb from "../types/Rgb.js";
|
|
2
|
+
import relativeLuminance from "./relativeLuminance.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the contrast ratio between two sRGB colors. This is useful for ensuring that Web Content Accessibility Guidelines (WCAG) are met. For everything to meet WCAG 2.2 at level AAA, this value should be at least 7.
|
|
6
|
+
* @param color0 - The first sRGB color.
|
|
7
|
+
* @param color1 - The second sRGB color.
|
|
8
|
+
* @returns The contrast ratio between the colors (a value `v` such that the contrast ratio between the colors is `v` to one).
|
|
9
|
+
* @see {@link https://www.w3.org/WAI/GL/wiki/Contrast_ratio | Contrast ratio}
|
|
10
|
+
* @see {@link https://www.w3.org/WAI/standards-guidelines/wcag/ | WCAG 2 Overview}
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export default function contrast(color0: Rgb, color1: Rgb): number {
|
|
14
|
+
// Intermediate values.
|
|
15
|
+
const i0 = relativeLuminance(color0);
|
|
16
|
+
const i1 = relativeLuminance(color1);
|
|
17
|
+
|
|
18
|
+
return i0 > i1 ? (i0 + 0.05) / (i1 + 0.05) : (i1 + 0.05) / (i0 + 0.05);
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type Lab from "../types/Lab.js";
|
|
2
|
+
import type Luv from "../types/Luv.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the ΔC* between two CIELAB values. Based on the EasyRGB pseudocode.
|
|
6
|
+
* @param color0 - The first color.
|
|
7
|
+
* @param color1 - The second color.
|
|
8
|
+
* @returns The difference between the colors.
|
|
9
|
+
* @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export default function deltaC(color0: Lab, color1: Lab): number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the ΔC* between two CIELUV values. Based on the EasyRGB pseudocode.
|
|
16
|
+
* @param color0 - The first color.
|
|
17
|
+
* @param color1 - The second color.
|
|
18
|
+
* @returns The difference between the colors.
|
|
19
|
+
* @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export default function deltaC(color0: Luv, color1: Luv): number;
|
|
23
|
+
|
|
24
|
+
export default function deltaC(color0: Lab | Luv, color1: Lab | Luv): number {
|
|
25
|
+
return Math.hypot(color1[1], color1[2]) - Math.hypot(color0[1], color0[2]);
|
|
26
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type Lab from "../types/Lab.js";
|
|
2
|
+
import type Lch from "../types/Lch.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the ΔCMC between two CIELAB values. Based on the EasyRGB pseudocode.
|
|
6
|
+
* @param color0 - The first color.
|
|
7
|
+
* @param color1 - The second color.
|
|
8
|
+
* @param weight - The CIELCH weights. Defaults to all ones.
|
|
9
|
+
* @returns The difference between the colors.
|
|
10
|
+
* @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export default function deltaCmc(
|
|
14
|
+
color0: Lab,
|
|
15
|
+
color1: Lab,
|
|
16
|
+
weight: Lch = [1, 1, 1]
|
|
17
|
+
): number {
|
|
18
|
+
// eslint-disable-next-line prefer-destructuring
|
|
19
|
+
const l0 = color0[0];
|
|
20
|
+
// eslint-disable-next-line prefer-destructuring
|
|
21
|
+
const a0 = color0[1];
|
|
22
|
+
// eslint-disable-next-line prefer-destructuring
|
|
23
|
+
const b0 = color0[2];
|
|
24
|
+
// eslint-disable-next-line prefer-destructuring
|
|
25
|
+
const a1 = color1[1];
|
|
26
|
+
// eslint-disable-next-line prefer-destructuring
|
|
27
|
+
const b1 = color1[2];
|
|
28
|
+
|
|
29
|
+
const i0 = Math.hypot(a0, b0);
|
|
30
|
+
const i1 = i0 ** 4;
|
|
31
|
+
const i2 = Math.sqrt(i1 / (i1 + 1900));
|
|
32
|
+
const i3 =
|
|
33
|
+
b0 === 0
|
|
34
|
+
? a0 < 0
|
|
35
|
+
? 180
|
|
36
|
+
: 0
|
|
37
|
+
: a0 === 0
|
|
38
|
+
? b0 < 0
|
|
39
|
+
? 270
|
|
40
|
+
: 90
|
|
41
|
+
: Math.atan(b0 / a0) * 57.29577951 + // `180 / Math.PI`
|
|
42
|
+
(a0 > 0 ? (b0 > 0 ? 0 : 360) : 180);
|
|
43
|
+
const i4 = (0.0638 * i0) / (1 + 0.0131 * i0) + 0.638;
|
|
44
|
+
const i5 = Math.hypot(a1, b1) - i0;
|
|
45
|
+
|
|
46
|
+
return Math.hypot(
|
|
47
|
+
(color1[0] - l0) /
|
|
48
|
+
(weight[0] * (l0 < 16 ? 0.511 : (0.040975 * l0) / (1 + 0.01765 * l0))),
|
|
49
|
+
i5 / (weight[1] * i4),
|
|
50
|
+
Math.sqrt((a1 - a0) ** 2 + (b1 - b0) ** 2 - i5 ** 2) /
|
|
51
|
+
((i2 *
|
|
52
|
+
(i3 < 164 || i3 > 345
|
|
53
|
+
? 0.36 + Math.abs(0.4 * Math.cos((35 + i3) * 0.01745329)) // `Math.PI / 180`
|
|
54
|
+
: 0.56 + Math.abs(0.2 * Math.cos((168 + i3) * 0.01745329))) + // `Math.PI / 180`
|
|
55
|
+
1 -
|
|
56
|
+
i2) *
|
|
57
|
+
i4)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type Lab from "../types/Lab.js";
|
|
2
|
+
import type Lch from "../types/Lch.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert CIELAB data to hue data.
|
|
6
|
+
* @param a - An input CIELAB value.
|
|
7
|
+
* @param b - An input CIELAB value.
|
|
8
|
+
* @returns A CIELCh hue (h°) value.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
const cieLabToHue = (a: number, b: number): number =>
|
|
12
|
+
b === 0
|
|
13
|
+
? a < 0
|
|
14
|
+
? 180
|
|
15
|
+
: 0
|
|
16
|
+
: a === 0
|
|
17
|
+
? b < 0
|
|
18
|
+
? 270
|
|
19
|
+
: 90
|
|
20
|
+
: Math.atan(b / a) * 57.29577951 + (a > 0 ? (b > 0 ? 0 : 360) : 180); // `180 / Math.PI`
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Calculates the ΔE* 2000 (also called the CIEDE2000) between two CIELAB values. Based on the EasyRGB pseudocode.
|
|
24
|
+
* @param color0 - The first color.
|
|
25
|
+
* @param color1 - The second color.
|
|
26
|
+
* @param weight - The CIELCH weights. Defaults to all ones.
|
|
27
|
+
* @returns The difference between the colors.
|
|
28
|
+
* @see {@link https://en.wikipedia.org/wiki/Color_difference | Color difference}
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export default function deltaE00(
|
|
32
|
+
color0: Lab,
|
|
33
|
+
color1: Lab,
|
|
34
|
+
weight: Lch = [1, 1, 1]
|
|
35
|
+
): number {
|
|
36
|
+
// eslint-disable-next-line prefer-destructuring
|
|
37
|
+
const l0 = color0[0];
|
|
38
|
+
// eslint-disable-next-line prefer-destructuring
|
|
39
|
+
const a0 = color0[1];
|
|
40
|
+
// eslint-disable-next-line prefer-destructuring
|
|
41
|
+
const b0 = color0[2];
|
|
42
|
+
// eslint-disable-next-line prefer-destructuring
|
|
43
|
+
const l1 = color1[0];
|
|
44
|
+
// eslint-disable-next-line prefer-destructuring
|
|
45
|
+
const a1 = color1[1];
|
|
46
|
+
// eslint-disable-next-line prefer-destructuring
|
|
47
|
+
const b1 = color1[2];
|
|
48
|
+
|
|
49
|
+
const i0 = ((Math.hypot(a0, b0) + Math.hypot(a1, b1)) / 2) ** 7;
|
|
50
|
+
const i1 = 0.5 * (1 - Math.sqrt(i0 / (i0 + 6103515625))); // `25 ** 7
|
|
51
|
+
const i2 = (1 + i1) * a0;
|
|
52
|
+
const i3 = Math.hypot(i2, b0);
|
|
53
|
+
const i4 = cieLabToHue(i2, b0);
|
|
54
|
+
const i5 = (1 + i1) * a1;
|
|
55
|
+
const i6 = Math.hypot(i5, b1);
|
|
56
|
+
const i7 = cieLabToHue(i5, b1);
|
|
57
|
+
const i8 = (i3 + i6) / 2;
|
|
58
|
+
const i9 = i3 * i6;
|
|
59
|
+
const i10 = i4 + i7;
|
|
60
|
+
const i11 =
|
|
61
|
+
i9 === 0
|
|
62
|
+
? i10
|
|
63
|
+
: Math.abs(i4 - i7) > 180
|
|
64
|
+
? i10 < 360
|
|
65
|
+
? (i10 + 360) / 2
|
|
66
|
+
: (i10 - 360) / 2
|
|
67
|
+
: i10 / 2;
|
|
68
|
+
const i12 = (i6 - i3) / (weight[1] * (1 + 0.045 * i8));
|
|
69
|
+
const i13 = i7 - i4;
|
|
70
|
+
const i14 =
|
|
71
|
+
(2 *
|
|
72
|
+
Math.sqrt(i9) *
|
|
73
|
+
Math.sin(
|
|
74
|
+
((i9 === 0
|
|
75
|
+
? 0
|
|
76
|
+
: Math.abs(i13) <= 180
|
|
77
|
+
? i13
|
|
78
|
+
: i13 > 180
|
|
79
|
+
? i13 - 360
|
|
80
|
+
: i13 + 360) /
|
|
81
|
+
2) *
|
|
82
|
+
0.01745329 // `Math.PI / 180`
|
|
83
|
+
)) /
|
|
84
|
+
(weight[2] *
|
|
85
|
+
(1 +
|
|
86
|
+
0.015 *
|
|
87
|
+
i8 *
|
|
88
|
+
(1 -
|
|
89
|
+
0.17 * Math.cos((i11 - 30) * 0.01745329) + // `Math.PI / 180`
|
|
90
|
+
0.24 * Math.cos(2 * i11 * 0.01745329) + // `Math.PI / 180`
|
|
91
|
+
0.32 * Math.cos((3 * i11 + 6) * 0.01745329) - // `Math.PI / 180`
|
|
92
|
+
0.2 * Math.cos((4 * i11 - 63) * 0.01745329)))); // `Math.PI / 180`
|
|
93
|
+
const i15 = i8 ** 7;
|
|
94
|
+
const i16 = ((l0 + l1) / 2 - 50) ** 2;
|
|
95
|
+
|
|
96
|
+
return Math.sqrt(
|
|
97
|
+
((l1 - l0) / (weight[0] * (1 + (0.015 * i16) / Math.sqrt(20 + i16)))) ** 2 +
|
|
98
|
+
i12 ** 2 +
|
|
99
|
+
i14 ** 2 +
|
|
100
|
+
-Math.sin(2 * (30 * Math.exp(-(((i11 - 275) / 25) ** 2))) * 0.01745329) * // `Math.PI / 180`
|
|
101
|
+
(2 * Math.sqrt(i15 / (i15 + 6103515625))) * // `25 ** 7
|
|
102
|
+
i12 *
|
|
103
|
+
i14
|
|
104
|
+
);
|
|
105
|
+
}
|