@thi.ng/color 3.2.6 → 4.0.3
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/CHANGELOG.md +162 -230
- package/README.md +31 -15
- package/{ops/alpha.d.ts → alpha.d.ts} +1 -1
- package/{ops/alpha.js → alpha.js} +1 -1
- package/{ops/analog.d.ts → analog.d.ts} +3 -3
- package/{ops/analog.js → analog.js} +10 -10
- package/api/constants.js +18 -73
- package/api/gradients.d.ts +1 -1
- package/api/ranges.d.ts +2 -2
- package/api.d.ts +7 -2
- package/{ops/clamp.d.ts → clamp.d.ts} +1 -1
- package/{ops/clamp.js → clamp.js} +6 -5
- package/{ops/closest-hue.d.ts → closest-hue.d.ts} +1 -1
- package/{ops/closest-hue.js → closest-hue.js} +1 -1
- package/{ops/color-range.d.ts → color-range.d.ts} +2 -2
- package/{ops/color-range.js → color-range.js} +25 -18
- package/color.d.ts +1 -1
- package/color.js +16 -16
- package/convert.d.ts +1 -1
- package/convert.js +4 -4
- package/{ops/cosine-gradients.d.ts → cosine-gradients.d.ts} +2 -2
- package/{ops/cosine-gradients.js → cosine-gradients.js} +13 -5
- package/css/css.d.ts +1 -1
- package/css/css.js +12 -11
- package/css/parse-css.d.ts +1 -1
- package/css/parse-css.js +12 -9
- package/defcolor.d.ts +1 -1
- package/defcolor.js +24 -11
- package/{ops/distance.d.ts → distance.d.ts} +2 -2
- package/{ops/distance.js → distance.js} +7 -5
- package/{ops/gradients.d.ts → gradients.d.ts} +2 -2
- package/{ops/gradients.js → gradients.js} +3 -3
- package/hcy/hcy-rgb.d.ts +1 -1
- package/hcy/hcy-rgb.js +6 -6
- package/hcy/hcy.d.ts +1 -1
- package/hcy/hcy.js +4 -2
- package/hsi/hsi-rgb.d.ts +1 -1
- package/hsi/hsi-rgb.js +2 -2
- package/hsi/hsi.d.ts +1 -1
- package/hsi/hsi.js +4 -2
- package/hsl/hsl-css.d.ts +1 -1
- package/hsl/hsl-css.js +5 -4
- package/hsl/hsl-hsv.d.ts +1 -1
- package/hsl/hsl-hsv.js +1 -1
- package/hsl/hsl-rgb.d.ts +1 -1
- package/hsl/hsl-rgb.js +5 -5
- package/hsl/hsl.d.ts +1 -1
- package/hsl/hsl.js +5 -3
- package/hsv/hsv-css.d.ts +1 -1
- package/hsv/hsv-css.js +2 -2
- package/hsv/hsv-hsl.d.ts +1 -1
- package/hsv/hsv-hsl.js +1 -1
- package/hsv/hsv-rgb.d.ts +1 -1
- package/hsv/hsv-rgb.js +3 -3
- package/hsv/hsv.d.ts +1 -1
- package/hsv/hsv.js +5 -3
- package/index.d.ts +87 -87
- package/index.js +87 -87
- package/int/int-css.js +2 -2
- package/int/int-int.js +1 -1
- package/int/int-rgb.d.ts +1 -1
- package/int/int-rgb.js +2 -2
- package/int/int-srgb.d.ts +1 -1
- package/int/int-srgb.js +2 -2
- package/int/int.d.ts +24 -11
- package/int/int.js +59 -19
- package/internal/ensure.d.ts +5 -0
- package/internal/{ensure-args.js → ensure.js} +4 -1
- package/internal/matrix-ops.d.ts +8 -5
- package/internal/matrix-ops.js +12 -8
- package/internal/scale.d.ts +3 -0
- package/internal/scale.js +2 -0
- package/{ops/invert.d.ts → invert.d.ts} +1 -1
- package/{ops/invert.js → invert.js} +3 -2
- package/is-black.d.ts +3 -0
- package/{ops/is-black.js → is-black.js} +5 -6
- package/is-gray.d.ts +3 -0
- package/{ops/is-gray.js → is-gray.js} +6 -7
- package/is-white.d.ts +3 -0
- package/{ops/is-white.js → is-white.js} +5 -6
- package/lab/lab-css.d.ts +1 -1
- package/lab/lab-css.js +4 -4
- package/lab/lab-lab.d.ts +1 -1
- package/lab/lab-lab.js +3 -3
- package/lab/lab-lch.d.ts +1 -1
- package/lab/lab-lch.js +6 -5
- package/lab/lab-rgb.d.ts +1 -1
- package/lab/lab-rgb.js +2 -2
- package/lab/lab-xyz.d.ts +1 -1
- package/lab/lab-xyz.js +4 -4
- package/lab/lab50.d.ts +1 -1
- package/lab/lab50.js +8 -6
- package/lab/lab65.d.ts +1 -1
- package/lab/lab65.js +8 -6
- package/lch/lch-css.d.ts +1 -1
- package/lch/lch-css.js +5 -4
- package/lch/lch.d.ts +1 -1
- package/lch/lch.js +8 -6
- package/{ops/linear.d.ts → linear.d.ts} +0 -0
- package/{ops/linear.js → linear.js} +0 -0
- package/{ops/luminance-rgb.d.ts → luminance-rgb.d.ts} +1 -1
- package/{ops/luminance-rgb.js → luminance-rgb.js} +2 -2
- package/{ops/luminance.d.ts → luminance.d.ts} +2 -3
- package/{ops/luminance.js → luminance.js} +5 -10
- package/{ops/mix.d.ts → mix.d.ts} +2 -2
- package/{ops/mix.js → mix.js} +7 -6
- package/oklab/oklab-rgb.d.ts +1 -1
- package/oklab/oklab-rgb.js +4 -11
- package/oklab/oklab-xyz.d.ts +1 -1
- package/oklab/oklab-xyz.js +9 -21
- package/oklab/oklab.d.ts +1 -1
- package/oklab/oklab.js +8 -6
- package/package.json +323 -52
- package/rgb/hue-rgb.d.ts +1 -1
- package/rgb/hue-rgb.js +3 -2
- package/rgb/kelvin-rgba.d.ts +1 -1
- package/rgb/kelvin-rgba.js +3 -3
- package/rgb/rgb-css.d.ts +1 -1
- package/rgb/rgb-css.js +2 -2
- package/rgb/rgb-hcv.d.ts +1 -1
- package/rgb/rgb-hcv.js +4 -3
- package/rgb/rgb-hcy.d.ts +1 -1
- package/rgb/rgb-hcy.js +4 -4
- package/rgb/rgb-hsi.d.ts +1 -1
- package/rgb/rgb-hsi.js +4 -3
- package/rgb/rgb-hsl.d.ts +1 -1
- package/rgb/rgb-hsl.js +2 -2
- package/rgb/rgb-hsv.d.ts +1 -1
- package/rgb/rgb-hsv.js +2 -2
- package/rgb/rgb-lab.d.ts +1 -1
- package/rgb/rgb-lab.js +2 -2
- package/rgb/rgb-oklab.d.ts +1 -1
- package/rgb/rgb-oklab.js +6 -13
- package/rgb/rgb-srgb.d.ts +1 -1
- package/rgb/rgb-srgb.js +5 -5
- package/rgb/rgb-xyz.d.ts +1 -1
- package/rgb/rgb-xyz.js +4 -4
- package/rgb/rgb-ycc.d.ts +1 -1
- package/rgb/rgb-ycc.js +5 -4
- package/rgb/rgb.d.ts +1 -1
- package/rgb/rgb.js +15 -14
- package/{ops/sort.d.ts → sort.d.ts} +16 -5
- package/{ops/sort.js → sort.js} +21 -7
- package/srgb/srgb-css.d.ts +1 -1
- package/srgb/srgb-css.js +8 -8
- package/srgb/srgb-int.d.ts +1 -1
- package/srgb/srgb-int.js +4 -4
- package/srgb/srgb-rgb.d.ts +1 -1
- package/srgb/srgb-rgb.js +5 -5
- package/srgb/srgb.d.ts +1 -1
- package/srgb/srgb.js +9 -7
- package/{ops/swatches.d.ts → swatches.d.ts} +1 -1
- package/{ops/swatches.js → swatches.js} +0 -0
- package/{ops/transform.d.ts → transform.d.ts} +1 -1
- package/{ops/transform.js → transform.js} +5 -5
- package/xyy/xyy-xyz.d.ts +1 -1
- package/xyy/xyy-xyz.js +4 -4
- package/xyy/xyy.d.ts +1 -1
- package/xyy/xyy.js +6 -3
- package/xyz/wavelength-xyz.d.ts +1 -1
- package/xyz/wavelength-xyz.js +2 -2
- package/xyz/xyz-lab.d.ts +1 -1
- package/xyz/xyz-lab.js +5 -4
- package/xyz/xyz-oklab.d.ts +1 -1
- package/xyz/xyz-oklab.js +4 -4
- package/xyz/xyz-rgb.d.ts +1 -1
- package/xyz/xyz-rgb.js +3 -3
- package/xyz/xyz-xyy.d.ts +1 -1
- package/xyz/xyz-xyy.js +4 -4
- package/xyz/xyz-xyz.d.ts +1 -1
- package/xyz/xyz-xyz.js +4 -4
- package/xyz/xyz50.d.ts +1 -1
- package/xyz/xyz50.js +10 -8
- package/xyz/xyz65.d.ts +1 -1
- package/xyz/xyz65.js +10 -8
- package/ycc/ycc-rgb.d.ts +1 -1
- package/ycc/ycc-rgb.js +4 -4
- package/ycc/ycc.d.ts +1 -1
- package/ycc/ycc.js +4 -2
- package/internal/ensure-alpha.d.ts +0 -2
- package/internal/ensure-alpha.js +0 -2
- package/internal/ensure-args.d.ts +0 -3
- package/lib/index.js +0 -2236
- package/lib/index.js.map +0 -1
- package/lib/index.umd.js +0 -1
- package/lib/index.umd.js.map +0 -1
- package/ops/is-black.d.ts +0 -3
- package/ops/is-gray.d.ts +0 -3
- package/ops/is-white.d.ts +0 -3
package/lab/lab-lab.d.ts
CHANGED
package/lab/lab-lab.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { xyzLab, xyzLabD65 } from "../xyz/xyz-lab";
|
|
2
|
-
import { xyzXyzD50_65, xyzXyzD65_50 } from "../xyz/xyz-xyz";
|
|
3
|
-
import { labXyz, labXyzD65 } from "./lab-xyz";
|
|
1
|
+
import { xyzLab, xyzLabD65 } from "../xyz/xyz-lab.js";
|
|
2
|
+
import { xyzXyzD50_65, xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
|
|
3
|
+
import { labXyz, labXyzD65 } from "./lab-xyz.js";
|
|
4
4
|
export const labLabD50_65 = (out, src) => xyzLabD65(out, xyzXyzD50_65(out, labXyz(out, src)));
|
|
5
5
|
export const labLabD65_50 = (out, src) => xyzLab(out, xyzXyzD65_50(out, labXyzD65(out, src)));
|
package/lab/lab-lch.d.ts
CHANGED
package/lab/lab-lch.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { atan2Abs
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { atan2Abs } from "@thi.ng/math/angle";
|
|
2
|
+
import { INV_TAU, TAU } from "@thi.ng/math/api";
|
|
3
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
4
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
5
|
export const labLch = (out, src) => {
|
|
5
6
|
const { 1: a, 2: b } = src;
|
|
6
|
-
return setC4(out || src, src[0], Math.hypot(a, b), a === 0 && b === 0 ? 0 : atan2Abs(b, a) * INV_TAU,
|
|
7
|
+
return setC4(out || src, src[0], Math.hypot(a, b), a === 0 && b === 0 ? 0 : atan2Abs(b, a) * INV_TAU, __ensureAlpha(src[3]));
|
|
7
8
|
};
|
|
8
9
|
export const lchLab = (out, src) => {
|
|
9
10
|
let { 1: c, 2: h } = src;
|
|
10
11
|
h *= TAU;
|
|
11
|
-
const a =
|
|
12
|
+
const a = __ensureAlpha(src[3]);
|
|
12
13
|
return c > 0
|
|
13
14
|
? setC4(out || src, src[0], Math.cos(h) * c, Math.sin(h) * c, a)
|
|
14
15
|
: setC4(out || src, src[0], 0, 0, a);
|
package/lab/lab-rgb.d.ts
CHANGED
package/lab/lab-rgb.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { labXyz, labXyzD65 } from "./lab-xyz";
|
|
2
|
-
import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb";
|
|
1
|
+
import { labXyz, labXyzD65 } from "./lab-xyz.js";
|
|
2
|
+
import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb.js";
|
|
3
3
|
/**
|
|
4
4
|
* Converts Lab to linear RGB (via XYZ) using {@link D50} white point.
|
|
5
5
|
*
|
package/lab/lab-xyz.d.ts
CHANGED
package/lab/lab-xyz.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
2
|
-
import { D50, D65 } from "../api/constants";
|
|
3
|
-
import {
|
|
1
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
|
+
import { D50, D65 } from "../api/constants.js";
|
|
3
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
4
|
const transform = (x) => {
|
|
5
5
|
const y = x ** 3;
|
|
6
6
|
return y > 0.008856 ? y : (x - 16 / 116) / 7.787;
|
|
@@ -15,7 +15,7 @@ const transform = (x) => {
|
|
|
15
15
|
*/
|
|
16
16
|
export const labXyz = (out, src, white = D50) => {
|
|
17
17
|
const y = (src[0] + 0.16) / 1.16;
|
|
18
|
-
return setC4(out || src, transform(src[1] / 5.0 + y) * white[0], transform(y) * white[1], transform(y - src[2] / 2.0) * white[2],
|
|
18
|
+
return setC4(out || src, transform(src[1] / 5.0 + y) * white[0], transform(y) * white[1], transform(y - src[2] / 2.0) * white[2], __ensureAlpha(src[3]));
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Same as {@link labXyz}, but using hardcoded {@link D65} white point.
|
package/lab/lab50.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NumericArray } from "@thi.ng/api";
|
|
2
2
|
import type { IRandom } from "@thi.ng/random";
|
|
3
|
-
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
|
|
3
|
+
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
|
|
4
4
|
export declare class LabD50 implements TypedColor<LabD50> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/lab/lab50.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { rgbLab } from "../rgb/rgb-lab";
|
|
3
|
-
import { xyzLab } from "../xyz/xyz-lab";
|
|
4
|
-
import { xyzXyzD65_50 } from "../xyz/xyz-xyz";
|
|
5
|
-
import { labLabD65_50 } from "./lab-lab";
|
|
6
|
-
import { lchLab } from "./lab-lch";
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { rgbLab } from "../rgb/rgb-lab.js";
|
|
3
|
+
import { xyzLab } from "../xyz/xyz-lab.js";
|
|
4
|
+
import { xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
|
|
5
|
+
import { labLabD65_50 } from "./lab-lab.js";
|
|
6
|
+
import { lchLab } from "./lab-lch.js";
|
|
7
|
+
import { labRgb } from "./lab-rgb.js";
|
|
7
8
|
export const labD50 = defColor({
|
|
8
9
|
mode: "lab50",
|
|
9
10
|
channels: {
|
|
@@ -18,4 +19,5 @@ export const labD50 = defColor({
|
|
|
18
19
|
xyz50: xyzLab,
|
|
19
20
|
xyz65: [xyzXyzD65_50, xyzLab],
|
|
20
21
|
},
|
|
22
|
+
toRgb: labRgb,
|
|
21
23
|
});
|
package/lab/lab65.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NumericArray } from "@thi.ng/api";
|
|
2
2
|
import type { IRandom } from "@thi.ng/random";
|
|
3
|
-
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
|
|
3
|
+
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
|
|
4
4
|
export declare class LabD65 implements TypedColor<LabD65> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/lab/lab65.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { rgbLabD65 } from "../rgb/rgb-lab";
|
|
3
|
-
import { xyzLabD65 } from "../xyz/xyz-lab";
|
|
4
|
-
import { xyzXyzD50_65 } from "../xyz/xyz-xyz";
|
|
5
|
-
import { labLabD50_65 } from "./lab-lab";
|
|
6
|
-
import { lchLab } from "./lab-lch";
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { rgbLabD65 } from "../rgb/rgb-lab.js";
|
|
3
|
+
import { xyzLabD65 } from "../xyz/xyz-lab.js";
|
|
4
|
+
import { xyzXyzD50_65 } from "../xyz/xyz-xyz.js";
|
|
5
|
+
import { labLabD50_65 } from "./lab-lab.js";
|
|
6
|
+
import { lchLab } from "./lab-lch.js";
|
|
7
|
+
import { labRgbD65 } from "./lab-rgb.js";
|
|
7
8
|
export const labD65 = defColor({
|
|
8
9
|
mode: "lab65",
|
|
9
10
|
channels: {
|
|
@@ -18,4 +19,5 @@ export const labD65 = defColor({
|
|
|
18
19
|
xyz50: [xyzXyzD50_65, xyzLabD65],
|
|
19
20
|
xyz65: xyzLabD65,
|
|
20
21
|
},
|
|
22
|
+
toRgb: labRgbD65,
|
|
21
23
|
});
|
package/lch/lch-css.d.ts
CHANGED
package/lch/lch-css.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { clamp0
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { clamp0 } from "@thi.ng/math/interval";
|
|
2
|
+
import { fract } from "@thi.ng/math/prec";
|
|
3
|
+
import { FF, PC } from "../api/constants.js";
|
|
4
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
5
|
/**
|
|
5
6
|
* @remarks
|
|
6
7
|
* Only supported in CSS Color Level 4 onwards
|
|
@@ -13,6 +14,6 @@ export const lchCss = (src) => {
|
|
|
13
14
|
const l = PC(clamp0(src[0]));
|
|
14
15
|
const c = FF(clamp0(src[1]) * 100);
|
|
15
16
|
const h = FF(fract(src[2]) * 360);
|
|
16
|
-
const a =
|
|
17
|
+
const a = __ensureAlpha(src[3]);
|
|
17
18
|
return `lch(${l} ${c} ${h}` + (a < 1 ? `/${FF(a)})` : ")");
|
|
18
19
|
};
|
package/lch/lch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NumericArray } from "@thi.ng/api";
|
|
2
2
|
import type { IRandom } from "@thi.ng/random";
|
|
3
|
-
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
|
|
3
|
+
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
|
|
4
4
|
export declare class LCH implements TypedColor<LCH> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/lch/lch.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { labLabD65_50 } from "../lab/lab-lab";
|
|
3
|
-
import { labLch } from "../lab/lab-lch";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { labLabD65_50 } from "../lab/lab-lab.js";
|
|
3
|
+
import { labLch, lchLab } from "../lab/lab-lch.js";
|
|
4
|
+
import { labRgb } from "../lab/lab-rgb.js";
|
|
5
|
+
import { rgbLab } from "../rgb/rgb-lab.js";
|
|
6
|
+
import { xyzLab } from "../xyz/xyz-lab.js";
|
|
7
|
+
import { xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
|
|
7
8
|
/**
|
|
8
9
|
* Luminance Chroma Hue (conversions assume {@link D50} white point, as per CSS
|
|
9
10
|
* spec).
|
|
@@ -21,4 +22,5 @@ export const lch = defColor({
|
|
|
21
22
|
xyz50: [xyzLab, labLch],
|
|
22
23
|
xyz65: [xyzXyzD65_50, xyzLab, labLch],
|
|
23
24
|
},
|
|
25
|
+
toRgb: [lchLab, labRgb],
|
|
24
26
|
});
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dot3 } from "@thi.ng/vectors";
|
|
2
|
-
import { RGB_LUMINANCE_REC709, RGB_LUMINANCE_REC601 } from "
|
|
1
|
+
import { dot3 } from "@thi.ng/vectors/dot";
|
|
2
|
+
import { RGB_LUMINANCE_REC709, RGB_LUMINANCE_REC601 } from "./api/constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* Computes RGB luminance, optionally using provided weights (by default:
|
|
5
5
|
* {@link RGB_LUMINANCE_REC709}).
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { MaybeColor } from "../api";
|
|
1
|
+
import type { MaybeColor } from "./api.js";
|
|
3
2
|
/**
|
|
4
3
|
* Multi-method to compute relative luminance from any supported input color
|
|
5
4
|
* format.
|
|
@@ -10,5 +9,5 @@ import type { MaybeColor } from "../api";
|
|
|
10
9
|
* unless a direct implementation is available, colors will first be converted
|
|
11
10
|
* to linear RGB.
|
|
12
11
|
*/
|
|
13
|
-
export declare const luminance: MultiFn1<MaybeColor, number>;
|
|
12
|
+
export declare const luminance: import("@thi.ng/defmulti/api").MultiFn1<MaybeColor, number>;
|
|
14
13
|
//# sourceMappingURL=luminance.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DEFAULT, defmulti } from "@thi.ng/defmulti";
|
|
2
|
-
import { rgb } from "
|
|
3
|
-
import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "./luminance-rgb";
|
|
1
|
+
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { rgb } from "./rgb/rgb.js";
|
|
3
|
+
import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "./luminance-rgb.js";
|
|
4
4
|
/**
|
|
5
5
|
* Multi-method to compute relative luminance from any supported input color
|
|
6
6
|
* format.
|
|
@@ -11,8 +11,7 @@ import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "
|
|
|
11
11
|
* unless a direct implementation is available, colors will first be converted
|
|
12
12
|
* to linear RGB.
|
|
13
13
|
*/
|
|
14
|
-
export const luminance = defmulti((col) => col.mode
|
|
15
|
-
luminance.addAll({
|
|
14
|
+
export const luminance = defmulti((col) => col.mode, { lch: "lab", oklab: "lab", ycc: "lab", xyy: "hcy" }, {
|
|
16
15
|
argb32: luminanceArgb32,
|
|
17
16
|
abgr32: luminanceAbgr32,
|
|
18
17
|
hcy: (x) => x[2],
|
|
@@ -20,9 +19,5 @@ luminance.addAll({
|
|
|
20
19
|
rgb: luminanceRgb,
|
|
21
20
|
srgb: luminanceSrgb,
|
|
22
21
|
xyz: (x) => x[1],
|
|
22
|
+
[DEFAULT]: (x) => luminanceRgb(rgb(x)),
|
|
23
23
|
});
|
|
24
|
-
luminance.isa("lch", "lab");
|
|
25
|
-
luminance.isa("oklab", "lab");
|
|
26
|
-
luminance.isa("ycc", "lab");
|
|
27
|
-
luminance.isa("xyy", "hcy");
|
|
28
|
-
luminance.add(DEFAULT, (x) => luminanceRgb(rgb(x)));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FnN3, FnU4 } from "@thi.ng/api";
|
|
2
|
-
import type { ColorMixFn, TypedColor } from "
|
|
2
|
+
import type { ColorMixFn, TypedColor } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
|
|
5
5
|
* returns new {@link ColorMixFn}.
|
|
@@ -67,5 +67,5 @@ export declare const mixNNNN: ColorMixFn;
|
|
|
67
67
|
* @param b -
|
|
68
68
|
* @param t -
|
|
69
69
|
*/
|
|
70
|
-
export declare const mix: import("@thi.ng/defmulti").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
|
|
70
|
+
export declare const mix: import("@thi.ng/defmulti/api").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
|
|
71
71
|
//# sourceMappingURL=mix.d.ts.map
|
package/{ops/mix.js → mix.js}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { DEFAULT, defmulti } from "@thi.ng/defmulti";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { mix as $mix } from "@thi.ng/math/mix";
|
|
3
|
+
import { fract } from "@thi.ng/math/prec";
|
|
4
|
+
import { mixN4 } from "@thi.ng/vectors/mixn";
|
|
5
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
4
6
|
/**
|
|
5
7
|
* HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
|
|
6
8
|
* returns new {@link ColorMixFn}.
|
|
@@ -79,12 +81,11 @@ export const mixNNNN = mixN4;
|
|
|
79
81
|
* @param b -
|
|
80
82
|
* @param t -
|
|
81
83
|
*/
|
|
82
|
-
export const mix = defmulti((_, a) => a.mode
|
|
83
|
-
mix.add(DEFAULT, mixN4);
|
|
84
|
-
mix.addAll({
|
|
84
|
+
export const mix = defmulti((_, a) => a.mode, {}, {
|
|
85
85
|
hcy: mixHNNN,
|
|
86
86
|
hsi: mixHNNN,
|
|
87
87
|
hsl: mixHNNN,
|
|
88
88
|
hsv: mixHNNN,
|
|
89
89
|
lch: mixNNHN,
|
|
90
|
+
[DEFAULT]: mixN4,
|
|
90
91
|
});
|
package/oklab/oklab-rgb.d.ts
CHANGED
package/oklab/oklab-rgb.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __mulV33 } from "../internal/matrix-ops.js";
|
|
2
2
|
const LMS_CONE = [
|
|
3
|
-
4.0767245293,
|
|
4
|
-
-1.
|
|
5
|
-
-0.0041119885,
|
|
6
|
-
-3.3072168827,
|
|
7
|
-
2.6093323231,
|
|
8
|
-
-0.7034763098,
|
|
9
|
-
0.2307590544,
|
|
10
|
-
-0.341134429,
|
|
11
|
-
1.7068625689,
|
|
3
|
+
4.0767245293, -1.2681437731, -0.0041119885, -3.3072168827, 2.6093323231,
|
|
4
|
+
-0.7034763098, 0.2307590544, -0.341134429, 1.7068625689,
|
|
12
5
|
];
|
|
13
6
|
/**
|
|
14
7
|
* @remarks
|
|
@@ -17,7 +10,7 @@ const LMS_CONE = [
|
|
|
17
10
|
* @param out
|
|
18
11
|
* @param src
|
|
19
12
|
*/
|
|
20
|
-
export const oklabRgb = (out, { 0: l, 1: a, 2: b, 3: alpha }) =>
|
|
13
|
+
export const oklabRgb = (out, { 0: l, 1: a, 2: b, 3: alpha }) => __mulV33(out, LMS_CONE, [
|
|
21
14
|
(l + 0.3963377774 * a + 0.2158037573 * b) ** 3,
|
|
22
15
|
(l - 0.1055613458 * a - 0.0638541728 * b) ** 3,
|
|
23
16
|
(l - 0.0894841775 * a - 1.291485548 * b) ** 3,
|
package/oklab/oklab-xyz.d.ts
CHANGED
package/oklab/oklab-xyz.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import { powN3 } from "@thi.ng/vectors";
|
|
2
|
-
import {
|
|
1
|
+
import { powN3 } from "@thi.ng/vectors/pown";
|
|
2
|
+
import { __mulV33 } from "../internal/matrix-ops.js";
|
|
3
3
|
// inverted version of OKLAB_M1
|
|
4
4
|
const M1I = [
|
|
5
|
-
1.2270138511035211,
|
|
6
|
-
-0.
|
|
7
|
-
-0.
|
|
8
|
-
-0.5577999806518222,
|
|
9
|
-
1.1122568696168302,
|
|
10
|
-
-0.4214819784180127,
|
|
11
|
-
0.28125614896646783,
|
|
12
|
-
-0.07167667866560119,
|
|
13
|
-
1.586163220440795,
|
|
5
|
+
1.2270138511035211, -0.04058017842328059, -0.0763812845057069,
|
|
6
|
+
-0.5577999806518222, 1.1122568696168302, -0.4214819784180127,
|
|
7
|
+
0.28125614896646783, -0.07167667866560119, 1.586163220440795,
|
|
14
8
|
];
|
|
15
9
|
// inverted version of OKLAB_M2
|
|
16
10
|
const M2I = [
|
|
17
|
-
0.9999999984505198,
|
|
18
|
-
|
|
19
|
-
1.
|
|
20
|
-
0.3963377921737678,
|
|
21
|
-
-0.10556134232365633,
|
|
22
|
-
-0.08948418209496575,
|
|
23
|
-
0.21580375806075877,
|
|
24
|
-
-0.06385417477170588,
|
|
25
|
-
-1.2914855378640917,
|
|
11
|
+
0.9999999984505198, 1.0000000088817607, 1.0000000546724108,
|
|
12
|
+
0.3963377921737678, -0.10556134232365633, -0.08948418209496575,
|
|
13
|
+
0.21580375806075877, -0.06385417477170588, -1.2914855378640917,
|
|
26
14
|
];
|
|
27
|
-
export const oklabXyzD65 = (out, src) =>
|
|
15
|
+
export const oklabXyzD65 = (out, src) => __mulV33(null, M1I, powN3(null, __mulV33(out, M2I, src), 3));
|
package/oklab/oklab.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NumericArray } from "@thi.ng/api";
|
|
2
2
|
import type { IRandom } from "@thi.ng/random";
|
|
3
|
-
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
|
|
3
|
+
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
|
|
4
4
|
export declare class Oklab implements TypedColor<Oklab> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/oklab/oklab.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { lchLab } from "../lab/lab-lch";
|
|
3
|
-
import { labXyz, labXyzD65 } from "../lab/lab-xyz";
|
|
4
|
-
import { rgbOklab } from "../rgb/rgb-oklab";
|
|
5
|
-
import { xyzOklab } from "../xyz/xyz-oklab";
|
|
6
|
-
import { xyzXyzD50_65 } from "../xyz/xyz-xyz";
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { lchLab } from "../lab/lab-lch.js";
|
|
3
|
+
import { labXyz, labXyzD65 } from "../lab/lab-xyz.js";
|
|
4
|
+
import { rgbOklab } from "../rgb/rgb-oklab.js";
|
|
5
|
+
import { xyzOklab } from "../xyz/xyz-oklab.js";
|
|
6
|
+
import { xyzXyzD50_65 } from "../xyz/xyz-xyz.js";
|
|
7
|
+
import { oklabRgb } from "./oklab-rgb.js";
|
|
7
8
|
/**
|
|
8
9
|
* Oklab color type. Conversions assume {@link D65} white point).
|
|
9
10
|
*
|
|
@@ -25,4 +26,5 @@ export const oklab = defColor({
|
|
|
25
26
|
xyz50: [xyzXyzD50_65, xyzOklab],
|
|
26
27
|
xyz65: xyzOklab,
|
|
27
28
|
},
|
|
29
|
+
toRgb: oklabRgb,
|
|
28
30
|
});
|