@thi.ng/color 5.4.0 → 5.4.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-03-02T18:09:03Z
3
+ - **Last updated**: 2023-03-02T19:20:16Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -0,0 +1,3 @@
1
+ import type { ColorOp } from "../api.js";
2
+ export declare const oklabOklch: ColorOp;
3
+ //# sourceMappingURL=oklab-oklch.d.ts.map
@@ -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]));
@@ -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.0",
3
+ "version": "5.4.2",
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",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@thi.ng/api": "^8.7.3",
42
- "@thi.ng/arrays": "^2.5.6",
42
+ "@thi.ng/arrays": "^2.5.7",
43
43
  "@thi.ng/binary": "^3.3.20",
44
44
  "@thi.ng/checks": "^3.3.9",
45
45
  "@thi.ng/compare": "^2.1.26",
@@ -49,8 +49,8 @@
49
49
  "@thi.ng/math": "^5.4.4",
50
50
  "@thi.ng/random": "^3.3.26",
51
51
  "@thi.ng/strings": "^3.4.1",
52
- "@thi.ng/transducers": "^8.3.35",
53
- "@thi.ng/vectors": "^7.6.5"
52
+ "@thi.ng/transducers": "^8.3.36",
53
+ "@thi.ng/vectors": "^7.6.6"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@microsoft/api-extractor": "^7.34.2",
@@ -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": "a2915dee637c1b8cd2e11a78a23bd035e4f750e7\n"
448
+ "gitHead": "8342900eedc77bb09edb8c544804578b71f8acc6\n"
448
449
  }