@thi.ng/color 5.4.0 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/oklch/oklab-oklch.d.ts +3 -0
- package/oklch/oklab-oklch.js +15 -0
- package/oklch/oklch-css.d.ts +11 -0
- package/oklch/oklch-css.js +10 -0
- package/oklch/oklch-oklab.d.ts +11 -0
- package/oklch/oklch-oklab.js +13 -0
- package/oklch/oklch.d.ts +37 -0
- package/oklch/oklch.js +26 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { atan2Abs } from "@thi.ng/math/angle";
|
|
2
|
+
import { INV_TAU } from "@thi.ng/math/api";
|
|
3
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
4
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
5
|
+
export const oklabOklch = (out, src) => setC4(out || src, src[0], Math.hypot(src[1], src[2]), atan2Abs(src[2], src[1]) * INV_TAU, __ensureAlpha(src[3]));
|
|
6
|
+
/*
|
|
7
|
+
export function OKLab_to_OKLCH(OKLab: Color): Color {
|
|
8
|
+
const hue = Math.atan2(OKLab[2], OKLab[1]) * 180 / Math.PI;
|
|
9
|
+
return [
|
|
10
|
+
OKLab[0], // L is still L
|
|
11
|
+
Math.sqrt(OKLab[1] ** 2 + OKLab[2] ** 2), // Chroma
|
|
12
|
+
hue >= 0 ? hue : hue + 360, // Hue, in degrees [0 to 360)
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReadonlyColor } from "../api.js";
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Only supported in CSS Color Level 4 onwards
|
|
5
|
+
* - https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
6
|
+
* - https://test.csswg.org/harness/results/css-color-4_dev/grouped/ (test reports)
|
|
7
|
+
*
|
|
8
|
+
* @param src -
|
|
9
|
+
*/
|
|
10
|
+
export declare const oklchCss: (src: ReadonlyColor) => string;
|
|
11
|
+
//# sourceMappingURL=oklch-css.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { __lchCss } from "../internal/css.js";
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Only supported in CSS Color Level 4 onwards
|
|
5
|
+
* - https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
6
|
+
* - https://test.csswg.org/harness/results/css-color-4_dev/grouped/ (test reports)
|
|
7
|
+
*
|
|
8
|
+
* @param src -
|
|
9
|
+
*/
|
|
10
|
+
export const oklchCss = (src) => __lchCss("oklch", src, 1);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ColorOp } from "../api.js";
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Reference:
|
|
5
|
+
* - https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
|
|
6
|
+
*
|
|
7
|
+
* @param out
|
|
8
|
+
* @param src
|
|
9
|
+
*/
|
|
10
|
+
export declare const oklchOklab: ColorOp;
|
|
11
|
+
//# sourceMappingURL=oklch-oklab.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cossin } from "@thi.ng/math/angle";
|
|
2
|
+
import { TAU } from "@thi.ng/math/api";
|
|
3
|
+
import { setC4 } from "@thi.ng/vectors/setc";
|
|
4
|
+
import { __ensureAlpha } from "../internal/ensure.js";
|
|
5
|
+
/**
|
|
6
|
+
* @remarks
|
|
7
|
+
* Reference:
|
|
8
|
+
* - https://github.com/w3c/csswg-drafts/blob/main/css-color-4/conversions.js
|
|
9
|
+
*
|
|
10
|
+
* @param out
|
|
11
|
+
* @param src
|
|
12
|
+
*/
|
|
13
|
+
export const oklchOklab = (out, src) => setC4(out || src, src[0], ...cossin(src[2] * TAU, src[1]), __ensureAlpha(src[3]));
|
package/oklch/oklch.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { NumericArray } from "@thi.ng/api";
|
|
2
|
+
import type { IRandom } from "@thi.ng/random";
|
|
3
|
+
import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
|
|
4
|
+
export declare class Oklch implements TypedColor<Oklch> {
|
|
5
|
+
buf: NumericArray;
|
|
6
|
+
offset: number;
|
|
7
|
+
stride: number;
|
|
8
|
+
l: number;
|
|
9
|
+
c: number;
|
|
10
|
+
h: number;
|
|
11
|
+
alpha: number;
|
|
12
|
+
[id: number]: number;
|
|
13
|
+
readonly mode: "oklch";
|
|
14
|
+
readonly length: 4;
|
|
15
|
+
readonly range: [ReadonlyColor, ReadonlyColor];
|
|
16
|
+
[Symbol.iterator](): Iterator<number, any, undefined>;
|
|
17
|
+
clamp(): this;
|
|
18
|
+
copy(): Oklch;
|
|
19
|
+
copyView(): Oklch;
|
|
20
|
+
deref(): Color;
|
|
21
|
+
empty(): Oklch;
|
|
22
|
+
eqDelta(o: Oklch, eps?: number): boolean;
|
|
23
|
+
randomize(rnd?: IRandom): this;
|
|
24
|
+
set(src: ReadonlyColor): this;
|
|
25
|
+
toJSON(): number[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Oklch color type aka polar version of {@link oklab}.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Note: As with other hue-based color modes in this package, the hue is stored
|
|
32
|
+
* normalized (in [0..1] interval) and NOT as degrees.
|
|
33
|
+
*
|
|
34
|
+
* Reference: https://bottosson.github.io/posts/oklab/
|
|
35
|
+
*/
|
|
36
|
+
export declare const oklch: ColorFactory<Oklch>;
|
|
37
|
+
//# sourceMappingURL=oklch.d.ts.map
|
package/oklch/oklch.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defColor } from "../defcolor.js";
|
|
2
|
+
import { oklabRgb } from "../oklab/oklab-rgb.js";
|
|
3
|
+
import { rgbOklab } from "../rgb/rgb-oklab.js";
|
|
4
|
+
import { oklabOklch } from "./oklab-oklch.js";
|
|
5
|
+
import { oklchOklab } from "./oklch-oklab.js";
|
|
6
|
+
/**
|
|
7
|
+
* Oklch color type aka polar version of {@link oklab}.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Note: As with other hue-based color modes in this package, the hue is stored
|
|
11
|
+
* normalized (in [0..1] interval) and NOT as degrees.
|
|
12
|
+
*
|
|
13
|
+
* Reference: https://bottosson.github.io/posts/oklab/
|
|
14
|
+
*/
|
|
15
|
+
export const oklch = defColor({
|
|
16
|
+
mode: "oklch",
|
|
17
|
+
channels: {
|
|
18
|
+
c: { range: [0, 0.3225] },
|
|
19
|
+
},
|
|
20
|
+
order: ["l", "c", "h", "alpha"],
|
|
21
|
+
from: {
|
|
22
|
+
oklab: oklabOklch,
|
|
23
|
+
rgb: (out, src) => oklabOklch(null, rgbOklab(out, src)),
|
|
24
|
+
},
|
|
25
|
+
toRgb: [oklchOklab, oklabRgb],
|
|
26
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
"lab",
|
|
119
119
|
"lch",
|
|
120
120
|
"oklab",
|
|
121
|
+
"oklch",
|
|
121
122
|
"rgb",
|
|
122
123
|
"srgb",
|
|
123
124
|
"xyy",
|
|
@@ -444,5 +445,5 @@
|
|
|
444
445
|
"vectors"
|
|
445
446
|
]
|
|
446
447
|
},
|
|
447
|
-
"gitHead": "
|
|
448
|
+
"gitHead": "f2df4bbd52e8e78e9e7499d73f974f9a2f70f017\n"
|
|
448
449
|
}
|