@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/rgb/rgb-ycc.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { dot3
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { dot3 } from "@thi.ng/vectors/dot";
|
|
2
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
3
|
+
import { RGB_LUMINANCE_REC709 } from "../api/constants.js";
|
|
4
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
5
|
/**
|
|
5
6
|
* @remarks
|
|
6
7
|
* https://en.wikipedia.org/wiki/YCbCr#YCbCr
|
|
@@ -17,5 +18,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
|
|
|
17
18
|
*/
|
|
18
19
|
export const rgbYcc = (out, src, luma = RGB_LUMINANCE_REC709) => {
|
|
19
20
|
const y = dot3(src, luma);
|
|
20
|
-
return setC4(out || src, y, (0.5 * (src[2] - y)) / (1 - luma[2]), (0.5 * (src[0] - y)) / (1 - luma[0]),
|
|
21
|
+
return setC4(out || src, y, (0.5 * (src[2] - y)) / (1 - luma[2]), (0.5 * (src[0] - y)) / (1 - luma[0]), __ensureAlpha(src[3]));
|
|
21
22
|
};
|
package/rgb/rgb.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 RGB implements TypedColor<RGB> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/rgb/rgb.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { set4 } from "@thi.ng/vectors";
|
|
2
|
-
import { defColor } from "../defcolor";
|
|
3
|
-
import { hcyRgb } from "../hcy/hcy-rgb";
|
|
4
|
-
import { hsiRgb } from "../hsi/hsi-rgb";
|
|
5
|
-
import { hslRgb } from "../hsl/hsl-rgb";
|
|
6
|
-
import { hsvRgb } from "../hsv/hsv-rgb";
|
|
7
|
-
import { intAbgr32Rgb, intArgb32Rgb } from "../int/int-rgb";
|
|
8
|
-
import { lchLab } from "../lab/lab-lch";
|
|
9
|
-
import { labRgb, labRgbD65 } from "../lab/lab-rgb";
|
|
10
|
-
import { oklabRgb } from "../oklab/oklab-rgb";
|
|
11
|
-
import { srgbRgb } from "../srgb/srgb-rgb";
|
|
12
|
-
import { xyyXyz } from "../xyy/xyy-xyz";
|
|
13
|
-
import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb";
|
|
14
|
-
import { yccRgb } from "../ycc/ycc-rgb";
|
|
1
|
+
import { set4 } from "@thi.ng/vectors/set";
|
|
2
|
+
import { defColor } from "../defcolor.js";
|
|
3
|
+
import { hcyRgb } from "../hcy/hcy-rgb.js";
|
|
4
|
+
import { hsiRgb } from "../hsi/hsi-rgb.js";
|
|
5
|
+
import { hslRgb } from "../hsl/hsl-rgb.js";
|
|
6
|
+
import { hsvRgb } from "../hsv/hsv-rgb.js";
|
|
7
|
+
import { intAbgr32Rgb, intArgb32Rgb } from "../int/int-rgb.js";
|
|
8
|
+
import { lchLab } from "../lab/lab-lch.js";
|
|
9
|
+
import { labRgb, labRgbD65 } from "../lab/lab-rgb.js";
|
|
10
|
+
import { oklabRgb } from "../oklab/oklab-rgb.js";
|
|
11
|
+
import { srgbRgb } from "../srgb/srgb-rgb.js";
|
|
12
|
+
import { xyyXyz } from "../xyy/xyy-xyz.js";
|
|
13
|
+
import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb.js";
|
|
14
|
+
import { yccRgb } from "../ycc/ycc-rgb.js";
|
|
15
15
|
export const rgb = defColor({
|
|
16
16
|
mode: "rgb",
|
|
17
17
|
order: ["r", "g", "b", "alpha"],
|
|
@@ -33,4 +33,5 @@ export const rgb = defColor({
|
|
|
33
33
|
xyz65: xyzRgbD65,
|
|
34
34
|
ycc: yccRgb,
|
|
35
35
|
},
|
|
36
|
+
toRgb: set4,
|
|
36
37
|
});
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { Fn } from "@thi.ng/api";
|
|
2
|
-
import type { ColorDistance, ReadonlyColor, TypedColor } from "
|
|
1
|
+
import type { Fn } from "@thi.ng/api";
|
|
2
|
+
import type { ColorDistance, ReadonlyColor, TypedColor } from "./api.js";
|
|
3
3
|
export declare const selectChannel: (id: number) => (col: ReadonlyColor) => number;
|
|
4
4
|
/**
|
|
5
|
-
* Takes a `target` color and optional `distance` function
|
|
6
|
-
* function which can be used as `key`
|
|
7
|
-
* distance metric of a color to the
|
|
5
|
+
* Takes a `target` color and optional `distance` function (default:
|
|
6
|
+
* {@link distEucledian3}). Returns a new function which can be used as `key`
|
|
7
|
+
* function for {@link sort} to compute the distance metric of a color to the
|
|
8
|
+
* given `target`.
|
|
8
9
|
*
|
|
9
10
|
* @param target
|
|
10
11
|
* @param dist
|
|
11
12
|
*/
|
|
12
13
|
export declare const proximity: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Similar to {@link proximity}, but intended as syntax sugar for {@link ABGR}
|
|
16
|
+
* input colors. The proximity will still be computed using given distance
|
|
17
|
+
* function (default: {@link distEucledian3}) and will be in sRGB space. Hence
|
|
18
|
+
* given `target` color should be provided in the same space too.
|
|
19
|
+
*
|
|
20
|
+
* @param target
|
|
21
|
+
* @param dist
|
|
22
|
+
*/
|
|
23
|
+
export declare const proximityABGR32: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
|
|
13
24
|
export declare const sort: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => import("@thi.ng/vectors").ReadonlyVec[];
|
|
14
25
|
/**
|
|
15
26
|
* Similar to {@link sort}, but only for memory mapped colors (e.g. mapping a
|
package/{ops/sort.js → sort.js}
RENAMED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import { typedArray, typedArrayType } from "@thi.ng/api";
|
|
2
|
-
import { quickSort
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { typedArray, typedArrayType } from "@thi.ng/api/typedarray";
|
|
2
|
+
import { quickSort } from "@thi.ng/arrays/quicksort";
|
|
3
|
+
import { sortByCachedKey } from "@thi.ng/arrays/sort-cached";
|
|
4
|
+
import { swap } from "@thi.ng/arrays/swap";
|
|
5
|
+
import { compareNumAsc, compareNumDesc } from "@thi.ng/compare/numeric";
|
|
6
|
+
import { distEucledian3 } from "./distance.js";
|
|
7
|
+
import { intAbgr32Srgb } from "./int/int-srgb.js";
|
|
5
8
|
export const selectChannel = (id) => (col) => col[id];
|
|
6
9
|
/**
|
|
7
|
-
* Takes a `target` color and optional `distance` function
|
|
8
|
-
* function which can be used as `key`
|
|
9
|
-
* distance metric of a color to the
|
|
10
|
+
* Takes a `target` color and optional `distance` function (default:
|
|
11
|
+
* {@link distEucledian3}). Returns a new function which can be used as `key`
|
|
12
|
+
* function for {@link sort} to compute the distance metric of a color to the
|
|
13
|
+
* given `target`.
|
|
10
14
|
*
|
|
11
15
|
* @param target
|
|
12
16
|
* @param dist
|
|
13
17
|
*/
|
|
14
18
|
export const proximity = (target, dist = distEucledian3) => (col) => dist(target, col);
|
|
19
|
+
/**
|
|
20
|
+
* Similar to {@link proximity}, but intended as syntax sugar for {@link ABGR}
|
|
21
|
+
* input colors. The proximity will still be computed using given distance
|
|
22
|
+
* function (default: {@link distEucledian3}) and will be in sRGB space. Hence
|
|
23
|
+
* given `target` color should be provided in the same space too.
|
|
24
|
+
*
|
|
25
|
+
* @param target
|
|
26
|
+
* @param dist
|
|
27
|
+
*/
|
|
28
|
+
export const proximityABGR32 = (target, dist = distEucledian3) => (col) => dist(target, intAbgr32Srgb([], col[0]));
|
|
15
29
|
export const sort = (colors, key, isReverse = false) => sortByCachedKey(colors, key, isReverse ? compareNumDesc : compareNumAsc);
|
|
16
30
|
/**
|
|
17
31
|
* Similar to {@link sort}, but only for memory mapped colors (e.g. mapping a
|
package/srgb/srgb-css.d.ts
CHANGED
package/srgb/srgb-css.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { U24 } from "@thi.ng/strings/radix";
|
|
2
|
+
import { FF } from "../api/constants.js";
|
|
3
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
|
+
import { __scale8bit } from "../internal/scale.js";
|
|
5
5
|
export const srgbCss = (src) => {
|
|
6
|
-
const r = (
|
|
7
|
-
const g = (
|
|
8
|
-
const b = (
|
|
9
|
-
const a =
|
|
6
|
+
const r = __scale8bit(src[0]);
|
|
7
|
+
const g = __scale8bit(src[1]);
|
|
8
|
+
const b = __scale8bit(src[2]);
|
|
9
|
+
const a = __ensureAlpha(src[3]);
|
|
10
10
|
// TODO update to `rgb(${r} ${g} ${b}/${FF(a)})` (CSS L4 syntax)
|
|
11
11
|
return a < 1
|
|
12
12
|
? `rgba(${r},${g},${b},${FF(a)})`
|
package/srgb/srgb-int.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReadonlyColor } from "../api";
|
|
1
|
+
import type { ReadonlyColor } from "../api.js";
|
|
2
2
|
export declare const srgbIntArgb32: (src: ReadonlyColor) => number;
|
|
3
3
|
export declare const srgbIntAbgr32: (src: ReadonlyColor) => number;
|
|
4
4
|
//# sourceMappingURL=srgb-int.d.ts.map
|
package/srgb/srgb-int.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { clamp01 } from "@thi.ng/math";
|
|
2
|
-
import {
|
|
3
|
-
export const srgbIntArgb32 = (src) => (((
|
|
1
|
+
import { clamp01 } from "@thi.ng/math/interval";
|
|
2
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
3
|
+
export const srgbIntArgb32 = (src) => (((__ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
|
|
4
4
|
((clamp01(src[0]) * 0xff + 0.5) << 16) |
|
|
5
5
|
((clamp01(src[1]) * 0xff + 0.5) << 8) |
|
|
6
6
|
(clamp01(src[2]) * 0xff + 0.5)) >>>
|
|
7
7
|
0;
|
|
8
|
-
export const srgbIntAbgr32 = (src) => (((
|
|
8
|
+
export const srgbIntAbgr32 = (src) => (((__ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
|
|
9
9
|
((clamp01(src[2]) * 0xff + 0.5) << 16) |
|
|
10
10
|
((clamp01(src[1]) * 0xff + 0.5) << 8) |
|
|
11
11
|
(clamp01(src[0]) * 0xff + 0.5)) >>>
|
package/srgb/srgb-rgb.d.ts
CHANGED
package/srgb/srgb-rgb.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
2
|
-
import {
|
|
3
|
-
import { srgbLinear } from "../
|
|
1
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
3
|
+
import { srgbLinear } from "../linear.js";
|
|
4
4
|
/**
|
|
5
5
|
* Converts sRGB to linear RGB.
|
|
6
6
|
*
|
|
7
7
|
* @param out - result
|
|
8
8
|
* @param src - source color
|
|
9
9
|
*/
|
|
10
|
-
export const srgbRgb = (out, src) => setC4(out || src, srgbLinear(src[0]), srgbLinear(src[1]), srgbLinear(src[2]),
|
|
10
|
+
export const srgbRgb = (out, src) => setC4(out || src, srgbLinear(src[0]), srgbLinear(src[1]), srgbLinear(src[2]), __ensureAlpha(src[3]));
|
|
11
11
|
const GAMMA = 2.2;
|
|
12
|
-
export const srgbRgbApprox = (out, src) => setC4(out || src, src[0] ** GAMMA, src[1] ** GAMMA, src[2] ** GAMMA,
|
|
12
|
+
export const srgbRgbApprox = (out, src) => setC4(out || src, src[0] ** GAMMA, src[1] ** GAMMA, src[2] ** GAMMA, __ensureAlpha(src[3]));
|
package/srgb/srgb.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 SRGB implements TypedColor<SRGB> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/srgb/srgb.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { hcyRgb } from "../hcy/hcy-rgb";
|
|
3
|
-
import { hsiRgb } from "../hsi/hsi-rgb";
|
|
4
|
-
import { hslRgb } from "../hsl/hsl-rgb";
|
|
5
|
-
import { hsvRgb } from "../hsv/hsv-rgb";
|
|
6
|
-
import { intAbgr32Srgb, intArgb32Srgb } from "../int/int-srgb";
|
|
7
|
-
import { rgbSrgb } from "../rgb/rgb-srgb";
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { hcyRgb } from "../hcy/hcy-rgb.js";
|
|
3
|
+
import { hsiRgb } from "../hsi/hsi-rgb.js";
|
|
4
|
+
import { hslRgb } from "../hsl/hsl-rgb.js";
|
|
5
|
+
import { hsvRgb } from "../hsv/hsv-rgb.js";
|
|
6
|
+
import { intAbgr32Srgb, intArgb32Srgb } from "../int/int-srgb.js";
|
|
7
|
+
import { rgbSrgb } from "../rgb/rgb-srgb.js";
|
|
8
|
+
import { srgbRgb } from "./srgb-rgb.js";
|
|
8
9
|
export const srgb = defColor({
|
|
9
10
|
mode: "srgb",
|
|
10
11
|
order: ["r", "g", "b", "alpha"],
|
|
@@ -17,4 +18,5 @@ export const srgb = defColor({
|
|
|
17
18
|
hsv: hsvRgb,
|
|
18
19
|
rgb: rgbSrgb,
|
|
19
20
|
},
|
|
21
|
+
toRgb: srgbRgb,
|
|
20
22
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fn2, IObjectOf } from "@thi.ng/api";
|
|
2
|
-
import type { ReadonlyColor } from "
|
|
2
|
+
import type { ReadonlyColor } from "./api.js";
|
|
3
3
|
export declare const swatches: (cols: (ReadonlyColor | string)[], shapeFn: Fn2<ReadonlyColor | string, number, any[]>, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
|
|
4
4
|
export declare const swatchesH: (cols: (ReadonlyColor | string)[], w?: number, h?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
|
|
5
5
|
export declare const dotsH: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { mix } from "@thi.ng/math";
|
|
2
|
-
import { RGB_LUMINANCE_REC709, WHITE } from "
|
|
3
|
-
import {
|
|
1
|
+
import { mix } from "@thi.ng/math/mix";
|
|
2
|
+
import { RGB_LUMINANCE_REC709, WHITE } from "./api/constants.js";
|
|
3
|
+
import { __mulM45, __mulV45 } from "./internal/matrix-ops.js";
|
|
4
4
|
// https://drafts.fxtf.org/filter-effects/#feColorMatrixElement
|
|
5
5
|
const S0 = 0.072;
|
|
6
6
|
const S1 = 0.213;
|
|
@@ -22,7 +22,7 @@ const S8 = 0.283;
|
|
|
22
22
|
* @param src - source color
|
|
23
23
|
* @param clampOut - true, if result should be clamped to [0..1]
|
|
24
24
|
*/
|
|
25
|
-
export const transform =
|
|
25
|
+
export const transform = __mulV45;
|
|
26
26
|
/**
|
|
27
27
|
* Concatenates given color matrices by pairwise multiplying them in
|
|
28
28
|
* left-right order. Returns combined result matrix to be used with
|
|
@@ -39,7 +39,7 @@ export const transform = mulV45;
|
|
|
39
39
|
* @param mat - first matrix
|
|
40
40
|
* @param xs - other matrices
|
|
41
41
|
*/
|
|
42
|
-
export const concat = (mat, ...xs) => xs.reduce(
|
|
42
|
+
export const concat = (mat, ...xs) => xs.reduce(__mulM45, mat);
|
|
43
43
|
// prettier-ignore
|
|
44
44
|
export const IDENTITY = [
|
|
45
45
|
1, 0, 0, 0, 0,
|
package/xyy/xyy-xyz.d.ts
CHANGED
package/xyy/xyy-xyz.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { safeDiv } from "@thi.ng/math";
|
|
2
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
3
|
-
import {
|
|
1
|
+
import { safeDiv } from "@thi.ng/math/safe-div";
|
|
2
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
3
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
|
|
@@ -11,5 +11,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
|
|
|
11
11
|
*/
|
|
12
12
|
export const xyyXyz = (out, src) => {
|
|
13
13
|
const { 0: x, 1: y, 2: Y } = src;
|
|
14
|
-
return setC4(out || src, safeDiv(Y * x, y), Y, safeDiv(Y * (1 - x - y), y),
|
|
14
|
+
return setC4(out || src, safeDiv(Y * x, y), Y, safeDiv(Y * (1 - x - y), y), __ensureAlpha(src[3]));
|
|
15
15
|
};
|
package/xyy/xyy.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 XYY implements TypedColor<XYY> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/xyy/xyy.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { rgbXyzD65 } from "../rgb/rgb-xyz";
|
|
3
|
-
import {
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { rgbXyzD65 } from "../rgb/rgb-xyz.js";
|
|
3
|
+
import { xyzRgbD65 } from "../xyz/xyz-rgb.js";
|
|
4
|
+
import { xyzXyy } from "../xyz/xyz-xyy.js";
|
|
5
|
+
import { xyyXyz } from "./xyy-xyz.js";
|
|
4
6
|
export const xyy = defColor({
|
|
5
7
|
mode: "xyy",
|
|
6
8
|
channels: {
|
|
@@ -13,4 +15,5 @@ export const xyy = defColor({
|
|
|
13
15
|
xyz50: xyzXyy,
|
|
14
16
|
xyz65: xyzXyy,
|
|
15
17
|
},
|
|
18
|
+
toRgb: [xyyXyz, xyzRgbD65],
|
|
16
19
|
});
|
package/xyz/wavelength-xyz.d.ts
CHANGED
package/xyz/wavelength-xyz.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
2
|
-
import { xyzD65 } from "./xyz65";
|
|
1
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
|
+
import { xyzD65 } from "./xyz65.js";
|
|
3
3
|
/**
|
|
4
4
|
* Computes XYZA for given wavelength (in nanometers) and optional alpha channel
|
|
5
5
|
* (default: 1), writes result into `out` (or a new array if null).
|
package/xyz/xyz-lab.d.ts
CHANGED
package/xyz/xyz-lab.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
/** @internal */
|
|
4
5
|
const transform = (x) => x > 0.00885645 ? Math.cbrt(x) : 7.787037 * x + 16 / 116;
|
|
5
6
|
/**
|
|
6
7
|
* Converts XYZ to Lab, using provided reference white point (default:
|
|
@@ -18,7 +19,7 @@ export const xyzLab = (out, src, white = D50) => {
|
|
|
18
19
|
const x = transform(src[0] / white[0]);
|
|
19
20
|
const y = transform(src[1] / white[1]);
|
|
20
21
|
const z = transform(src[2] / white[2]);
|
|
21
|
-
return setC4(out || src, 1.16 * y - 0.16, 5.0 * (x - y), 2.0 * (y - z),
|
|
22
|
+
return setC4(out || src, 1.16 * y - 0.16, 5.0 * (x - y), 2.0 * (y - z), __ensureAlpha(src[3]));
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Same as {@link xyzLab}, but hard coded to use {@link D65} white point.
|
package/xyz/xyz-oklab.d.ts
CHANGED
package/xyz/xyz-oklab.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { powN3 } from "@thi.ng/vectors";
|
|
2
|
-
import { OKLAB_M1, OKLAB_M2 } from "../api/constants";
|
|
3
|
-
import {
|
|
4
|
-
export const xyzOklab = (out, src) =>
|
|
1
|
+
import { powN3 } from "@thi.ng/vectors/pown";
|
|
2
|
+
import { OKLAB_M1, OKLAB_M2 } from "../api/constants.js";
|
|
3
|
+
import { __mulV33 } from "../internal/matrix-ops.js";
|
|
4
|
+
export const xyzOklab = (out, src) => __mulV33(null, OKLAB_M2, powN3(null, __mulV33(out, OKLAB_M1, src), 1 / 3));
|
package/xyz/xyz-rgb.d.ts
CHANGED
package/xyz/xyz-rgb.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { XYZ_RGB_D50, XYZ_RGB_D65 } from "../api/constants";
|
|
2
|
-
import {
|
|
1
|
+
import { XYZ_RGB_D50, XYZ_RGB_D65 } from "../api/constants.js";
|
|
2
|
+
import { __mulV33 } from "../internal/matrix-ops.js";
|
|
3
3
|
/**
|
|
4
4
|
* Converts CIE XYZ to RGB using provided transformation/whitepoint matrix
|
|
5
5
|
* (default: {@link XYZ_RGB_D50}).
|
|
@@ -9,7 +9,7 @@ import { mulV33 } from "../internal/matrix-ops";
|
|
|
9
9
|
* @param out - result
|
|
10
10
|
* @param src - source color
|
|
11
11
|
*/
|
|
12
|
-
export const xyzRgb = (out, src, mat = XYZ_RGB_D50) =>
|
|
12
|
+
export const xyzRgb = (out, src, mat = XYZ_RGB_D50) => __mulV33(out, mat, src);
|
|
13
13
|
/**
|
|
14
14
|
* Same as {@link xyzRgb}, but hard coded to use {@link D65} white point (via
|
|
15
15
|
* {@link XYZ_RGB_D65} matrix).
|
package/xyz/xyz-xyy.d.ts
CHANGED
package/xyz/xyz-xyy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { safeDiv } from "@thi.ng/math";
|
|
2
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
3
|
-
import {
|
|
1
|
+
import { safeDiv } from "@thi.ng/math/safe-div";
|
|
2
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
3
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
|
|
@@ -12,5 +12,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
|
|
|
12
12
|
export const xyzXyy = (out, src) => {
|
|
13
13
|
const { 0: x, 1: Y } = src;
|
|
14
14
|
const sum = x + Y + src[2];
|
|
15
|
-
return setC4(out || src, safeDiv(x, sum), safeDiv(Y, sum), Y,
|
|
15
|
+
return setC4(out || src, safeDiv(x, sum), safeDiv(Y, sum), Y, __ensureAlpha(src[3]));
|
|
16
16
|
};
|
package/xyz/xyz-xyz.d.ts
CHANGED
package/xyz/xyz-xyz.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BRADFORD_D50_D65, BRADFORD_D65_D50 } from "../api/constants";
|
|
2
|
-
import {
|
|
3
|
-
export const xyzXyzD65_50 = (out, src) =>
|
|
4
|
-
export const xyzXyzD50_65 = (out, src) =>
|
|
1
|
+
import { BRADFORD_D50_D65, BRADFORD_D65_D50 } from "../api/constants.js";
|
|
2
|
+
import { __mulV33 } from "../internal/matrix-ops.js";
|
|
3
|
+
export const xyzXyzD65_50 = (out, src) => __mulV33(out, BRADFORD_D65_D50, src);
|
|
4
|
+
export const xyzXyzD50_65 = (out, src) => __mulV33(out, BRADFORD_D50_D65, src);
|
package/xyz/xyz50.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 XYZD50 implements TypedColor<XYZD50> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/xyz/xyz50.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { D50 } from "../api/constants";
|
|
2
|
-
import { defColor } from "../defcolor";
|
|
3
|
-
import { lchLab } from "../lab/lab-lch";
|
|
4
|
-
import { labXyz, labXyzD65 } from "../lab/lab-xyz";
|
|
5
|
-
import { oklabXyzD65 } from "../oklab/oklab-xyz";
|
|
6
|
-
import { rgbXyz } from "../rgb/rgb-xyz";
|
|
7
|
-
import { xyyXyz } from "../xyy/xyy-xyz";
|
|
8
|
-
import {
|
|
1
|
+
import { D50 } from "../api/constants.js";
|
|
2
|
+
import { defColor } from "../defcolor.js";
|
|
3
|
+
import { lchLab } from "../lab/lab-lch.js";
|
|
4
|
+
import { labXyz, labXyzD65 } from "../lab/lab-xyz.js";
|
|
5
|
+
import { oklabXyzD65 } from "../oklab/oklab-xyz.js";
|
|
6
|
+
import { rgbXyz } from "../rgb/rgb-xyz.js";
|
|
7
|
+
import { xyyXyz } from "../xyy/xyy-xyz.js";
|
|
8
|
+
import { xyzRgb } from "./xyz-rgb.js";
|
|
9
|
+
import { xyzXyzD65_50 } from "./xyz-xyz.js";
|
|
9
10
|
export const xyzD50 = defColor({
|
|
10
11
|
mode: "xyz50",
|
|
11
12
|
channels: {
|
|
@@ -22,4 +23,5 @@ export const xyzD50 = defColor({
|
|
|
22
23
|
oklab: [oklabXyzD65, xyzXyzD65_50],
|
|
23
24
|
xyy: xyyXyz,
|
|
24
25
|
},
|
|
26
|
+
toRgb: xyzRgb,
|
|
25
27
|
});
|
package/xyz/xyz65.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 XYZD65 implements TypedColor<XYZD65> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/xyz/xyz65.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { D65 } from "../api/constants";
|
|
2
|
-
import { defColor } from "../defcolor";
|
|
3
|
-
import { labLabD50_65 } from "../lab/lab-lab";
|
|
4
|
-
import { lchLab } from "../lab/lab-lch";
|
|
5
|
-
import { labXyzD65 } from "../lab/lab-xyz";
|
|
6
|
-
import { oklabXyzD65 } from "../oklab/oklab-xyz";
|
|
7
|
-
import { rgbXyzD65 } from "../rgb/rgb-xyz";
|
|
8
|
-
import { xyyXyz } from "../xyy/xyy-xyz";
|
|
1
|
+
import { D65 } from "../api/constants.js";
|
|
2
|
+
import { defColor } from "../defcolor.js";
|
|
3
|
+
import { labLabD50_65 } from "../lab/lab-lab.js";
|
|
4
|
+
import { lchLab } from "../lab/lab-lch.js";
|
|
5
|
+
import { labXyzD65 } from "../lab/lab-xyz.js";
|
|
6
|
+
import { oklabXyzD65 } from "../oklab/oklab-xyz.js";
|
|
7
|
+
import { rgbXyzD65 } from "../rgb/rgb-xyz.js";
|
|
8
|
+
import { xyyXyz } from "../xyy/xyy-xyz.js";
|
|
9
|
+
import { xyzRgbD65 } from "./xyz-rgb.js";
|
|
9
10
|
export const xyzD65 = defColor({
|
|
10
11
|
mode: "xyz65",
|
|
11
12
|
channels: {
|
|
@@ -22,4 +23,5 @@ export const xyzD65 = defColor({
|
|
|
22
23
|
oklab: oklabXyzD65,
|
|
23
24
|
xyy: xyyXyz,
|
|
24
25
|
},
|
|
26
|
+
toRgb: xyzRgbD65,
|
|
25
27
|
});
|
package/ycc/ycc-rgb.d.ts
CHANGED
package/ycc/ycc-rgb.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { setC4 } from "@thi.ng/vectors";
|
|
2
|
-
import { RGB_LUMINANCE_REC709 } from "../api/constants";
|
|
3
|
-
import {
|
|
1
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
2
|
+
import { RGB_LUMINANCE_REC709 } from "../api/constants.js";
|
|
3
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
6
|
* https://en.wikipedia.org/wiki/YCbCr#YCbCr
|
|
@@ -19,5 +19,5 @@ export const yccRgb = (out, src, luma = RGB_LUMINANCE_REC709) => {
|
|
|
19
19
|
const y = src[0];
|
|
20
20
|
const bb = (2 - 2 * luma[2]) * src[1];
|
|
21
21
|
const rr = (2 - 2 * luma[0]) * src[2];
|
|
22
|
-
return setC4(out || src, y + rr, y - (luma[2] / luma[1]) * bb - (luma[0] / luma[1]) * rr, y + bb,
|
|
22
|
+
return setC4(out || src, y + rr, y - (luma[2] / luma[1]) * bb - (luma[0] / luma[1]) * rr, y + bb, __ensureAlpha(src[3]));
|
|
23
23
|
};
|
package/ycc/ycc.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 YCC implements TypedColor<YCC> {
|
|
5
5
|
buf: NumericArray;
|
|
6
6
|
offset: number;
|
package/ycc/ycc.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { defColor } from "../defcolor";
|
|
2
|
-
import { rgbYcc } from "../rgb/rgb-ycc";
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { rgbYcc } from "../rgb/rgb-ycc.js";
|
|
3
|
+
import { yccRgb } from "./ycc-rgb.js";
|
|
3
4
|
export const ycc = defColor({
|
|
4
5
|
mode: "ycc",
|
|
5
6
|
channels: {
|
|
@@ -8,4 +9,5 @@ export const ycc = defColor({
|
|
|
8
9
|
},
|
|
9
10
|
order: ["y", "cb", "cr", "alpha"],
|
|
10
11
|
from: { rgb: rgbYcc },
|
|
12
|
+
toRgb: yccRgb,
|
|
11
13
|
});
|
package/internal/ensure-alpha.js
DELETED