@thi.ng/color 5.3.3 → 5.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/color",
3
- "version": "5.3.3",
3
+ "version": "5.4.0",
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",
@@ -32,23 +32,25 @@
32
32
  "doc:stats": "tools:module-stats",
33
33
  "pub": "yarn npm publish --access public",
34
34
  "test": "testament test",
35
+ "tool:limits": "tools:node-esm tools/limits.ts",
35
36
  "tool:maxchroma": "tools:node-esm tools/max-chroma.ts",
37
+ "tool:strategies": "tools:node-esm tools/strategies.ts",
36
38
  "tool:swatches": "tools:node-esm tools/index.ts"
37
39
  },
38
40
  "dependencies": {
39
- "@thi.ng/api": "^8.7.2",
40
- "@thi.ng/arrays": "^2.5.5",
41
- "@thi.ng/binary": "^3.3.19",
41
+ "@thi.ng/api": "^8.7.3",
42
+ "@thi.ng/arrays": "^2.5.6",
43
+ "@thi.ng/binary": "^3.3.20",
42
44
  "@thi.ng/checks": "^3.3.9",
43
- "@thi.ng/compare": "^2.1.25",
44
- "@thi.ng/compose": "^2.1.27",
45
- "@thi.ng/defmulti": "^2.1.30",
46
- "@thi.ng/errors": "^2.2.11",
47
- "@thi.ng/math": "^5.4.3",
48
- "@thi.ng/random": "^3.3.25",
49
- "@thi.ng/strings": "^3.4.0",
50
- "@thi.ng/transducers": "^8.3.34",
51
- "@thi.ng/vectors": "^7.6.4"
45
+ "@thi.ng/compare": "^2.1.26",
46
+ "@thi.ng/compose": "^2.1.28",
47
+ "@thi.ng/defmulti": "^2.1.31",
48
+ "@thi.ng/errors": "^2.2.12",
49
+ "@thi.ng/math": "^5.4.4",
50
+ "@thi.ng/random": "^3.3.26",
51
+ "@thi.ng/strings": "^3.4.1",
52
+ "@thi.ng/transducers": "^8.3.35",
53
+ "@thi.ng/vectors": "^7.6.5"
52
54
  },
53
55
  "devDependencies": {
54
56
  "@microsoft/api-extractor": "^7.34.2",
@@ -300,6 +302,9 @@
300
302
  "./mix": {
301
303
  "default": "./mix.js"
302
304
  },
305
+ "./oklab/oklab-css": {
306
+ "default": "./oklab/oklab-css.js"
307
+ },
303
308
  "./oklab/oklab-rgb": {
304
309
  "default": "./oklab/oklab-rgb.js"
305
310
  },
@@ -309,6 +314,18 @@
309
314
  "./oklab/oklab": {
310
315
  "default": "./oklab/oklab.js"
311
316
  },
317
+ "./oklch/oklab-oklch": {
318
+ "default": "./oklch/oklab-oklch.js"
319
+ },
320
+ "./oklch/oklch-css": {
321
+ "default": "./oklch/oklch-css.js"
322
+ },
323
+ "./oklch/oklch-oklab": {
324
+ "default": "./oklch/oklch-oklab.js"
325
+ },
326
+ "./oklch/oklch": {
327
+ "default": "./oklch/oklch.js"
328
+ },
312
329
  "./rgb/hue-rgb": {
313
330
  "default": "./rgb/hue-rgb.js"
314
331
  },
@@ -427,5 +444,5 @@
427
444
  "vectors"
428
445
  ]
429
446
  },
430
- "gitHead": "060a3a69281094df70be0e4f326a0ac3bbc3dd1d\n"
447
+ "gitHead": "a2915dee637c1b8cd2e11a78a23bd035e4f750e7\n"
431
448
  }
package/rgb/rgb-oklab.js CHANGED
@@ -1,9 +1,18 @@
1
1
  import { powN3 } from "@thi.ng/vectors/pown";
2
2
  import { OKLAB_M2 } from "../api/constants.js";
3
3
  import { __mulV33 } from "../internal/matrix-ops.js";
4
+ /**
5
+ * @remarks
6
+ * Reference:
7
+ * - https://bottosson.github.io/posts/oklab/#converting-from-linear-srgb-to-oklab
8
+ *
9
+ * @internal
10
+ */
11
+ // prettier-ignore
4
12
  const CONE_LMS = [
5
- 0.412165612, 0.211859107, 0.0883097947, 0.536275208, 0.6807189584,
6
- 0.2818474174, 0.0514575653, 0.107406579, 0.6302613616,
13
+ 0.4122214708, 0.2119034982, 0.0883024619,
14
+ 0.5363325363, 0.6806995451, 0.2817188376,
15
+ 0.0514459929, 0.1073969566, 0.6299787005,
7
16
  ];
8
17
  /**
9
18
  * @remarks
package/rotate.d.ts CHANGED
@@ -1,4 +1,37 @@
1
1
  import type { Color, TypedColor } from "./api.js";
2
+ /**
3
+ * Color rotation. Rotates hue by given `theta` and writes result color into
4
+ * `out`.
5
+ *
6
+ * @remarks
7
+ * If `out` is null, the resulting will be written back into `src`.
8
+ *
9
+ * As with all hue-based color modes in this package, the hue is stored
10
+ * normalized (in [0..1] interval) and NOT as degrees. The same goes for the
11
+ * rotation angle `theta`.
12
+ *
13
+ * Only supported for hue based color modes:
14
+ *
15
+ * - hcy
16
+ * - hsi
17
+ * - hsl
18
+ * - hsv
19
+ * - lch
20
+ * - oklch
21
+ *
22
+ * @param out
23
+ * @param src
24
+ * @param theta
25
+ */
2
26
  export declare const rotate: import("@thi.ng/defmulti").MultiFn3<import("@thi.ng/vectors").Vec | null, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
27
+ /**
28
+ * Syntax sugar for {@link rotate} with 180 degree rotation.
29
+ *
30
+ * @remarks
31
+ * If `out` is null, the resulting color will be written back into `src`.
32
+ *
33
+ * @param out
34
+ * @param src
35
+ */
3
36
  export declare const complementary: (out: Color | null, src: TypedColor<any>) => import("@thi.ng/vectors").Vec;
4
37
  //# sourceMappingURL=rotate.d.ts.map
package/rotate.js CHANGED
@@ -3,8 +3,41 @@ import { fract } from "@thi.ng/math/prec";
3
3
  import { setC4 } from "@thi.ng/vectors/setc";
4
4
  import { __dispatch1 } from "./internal/dispatch.js";
5
5
  import { __ensureAlpha } from "./internal/ensure.js";
6
- export const rotate = defmulti(__dispatch1, { hsv: "hsl", hsi: "hsl", hcy: "hsl" }, {
6
+ /**
7
+ * Color rotation. Rotates hue by given `theta` and writes result color into
8
+ * `out`.
9
+ *
10
+ * @remarks
11
+ * If `out` is null, the resulting will be written back into `src`.
12
+ *
13
+ * As with all hue-based color modes in this package, the hue is stored
14
+ * normalized (in [0..1] interval) and NOT as degrees. The same goes for the
15
+ * rotation angle `theta`.
16
+ *
17
+ * Only supported for hue based color modes:
18
+ *
19
+ * - hcy
20
+ * - hsi
21
+ * - hsl
22
+ * - hsv
23
+ * - lch
24
+ * - oklch
25
+ *
26
+ * @param out
27
+ * @param src
28
+ * @param theta
29
+ */
30
+ export const rotate = defmulti(__dispatch1, { hcy: "hsl", hsi: "hsl", hsv: "hsl", oklch: "lch" }, {
7
31
  hsl: (out, src, theta) => setC4(out || src, fract(src[0] + theta), src[1], src[2], __ensureAlpha(src[3])),
8
32
  lch: (out, src, theta) => setC4(out || src, src[0], src[1], fract(src[2] + theta), __ensureAlpha(src[3])),
9
33
  });
34
+ /**
35
+ * Syntax sugar for {@link rotate} with 180 degree rotation.
36
+ *
37
+ * @remarks
38
+ * If `out` is null, the resulting color will be written back into `src`.
39
+ *
40
+ * @param out
41
+ * @param src
42
+ */
10
43
  export const complementary = (out, src) => rotate(out, src, 0.5);
package/tint.d.ts CHANGED
@@ -1,6 +1,53 @@
1
1
  import type { MultiFn3O } from "@thi.ng/defmulti";
2
2
  import type { Color, TypedColor } from "./api.js";
3
+ /**
4
+ * Creates a tinted version of given `src` color and writes result into `out`.
5
+ * The color is interpolated towards given `target` grayscale level (default: 1
6
+ * aka white).
7
+ *
8
+ * @remarks
9
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
10
+ *
11
+ * If `out` is null, the resulting color will be written back into `src`.
12
+ *
13
+ * Only supported for the following color modes:
14
+ *
15
+ * - hcy
16
+ * - hsi
17
+ * - hsv
18
+ * - lch
19
+ * - oklch
20
+ *
21
+ * @param out
22
+ * @param src
23
+ * @param amount
24
+ * @param target
25
+ */
3
26
  export declare const tint: MultiFn3O<Color | null, TypedColor<any>, number, number, Color>;
27
+ /**
28
+ * Version of {@link tint} with medium gray as target.
29
+ *
30
+ * @remarks
31
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
32
+ *
33
+ * If `out` is null, the resulting color will be written back into `src`.
34
+ *
35
+ * @param out
36
+ * @param src
37
+ * @param n
38
+ */
4
39
  export declare const tone: (out: Color | null, src: TypedColor<any>, n: number) => import("@thi.ng/vectors").Vec;
40
+ /**
41
+ * Version of {@link tint} with black as target.
42
+ *
43
+ * @remarks
44
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
45
+ *
46
+ * If `out` is null, the resulting color will be written back into `src`.
47
+ *
48
+ * @param out
49
+ * @param src
50
+ * @param n
51
+ */
5
52
  export declare const shade: (out: Color | null, src: TypedColor<any>, n: number) => import("@thi.ng/vectors").Vec;
6
53
  //# sourceMappingURL=tint.d.ts.map
package/tint.js CHANGED
@@ -3,9 +3,56 @@ import { mix } from "@thi.ng/math/mix";
3
3
  import { setC4 } from "@thi.ng/vectors";
4
4
  import { __dispatch1 } from "./internal/dispatch.js";
5
5
  import { __ensureAlpha } from "./internal/ensure.js";
6
- export const tint = defmulti(__dispatch1, { hcy: "hsv", hsi: "hsv", hsl: "hsv" }, {
6
+ /**
7
+ * Creates a tinted version of given `src` color and writes result into `out`.
8
+ * The color is interpolated towards given `target` grayscale level (default: 1
9
+ * aka white).
10
+ *
11
+ * @remarks
12
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
13
+ *
14
+ * If `out` is null, the resulting color will be written back into `src`.
15
+ *
16
+ * Only supported for the following color modes:
17
+ *
18
+ * - hcy
19
+ * - hsi
20
+ * - hsv
21
+ * - lch
22
+ * - oklch
23
+ *
24
+ * @param out
25
+ * @param src
26
+ * @param amount
27
+ * @param target
28
+ */
29
+ export const tint = defmulti(__dispatch1, { hcy: "hsv", hsi: "hsv", hsl: "hsv", oklch: "lch" }, {
7
30
  hsv: (out, src, n, l = 1) => setC4(out || src, src[0], src[1] * (1 - n), mix(src[2], l, n), __ensureAlpha(src[3])),
8
31
  lch: (out, src, n, l = 1) => setC4(out || src, mix(src[0], l, n), src[1] * (1 - n), src[2], __ensureAlpha(src[3])),
9
32
  });
33
+ /**
34
+ * Version of {@link tint} with medium gray as target.
35
+ *
36
+ * @remarks
37
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
38
+ *
39
+ * If `out` is null, the resulting color will be written back into `src`.
40
+ *
41
+ * @param out
42
+ * @param src
43
+ * @param n
44
+ */
10
45
  export const tone = (out, src, n) => tint(out, src, n, 0.5);
46
+ /**
47
+ * Version of {@link tint} with black as target.
48
+ *
49
+ * @remarks
50
+ * Reference: https://www.handprint.com/HP/WCL/color3.html#stt
51
+ *
52
+ * If `out` is null, the resulting color will be written back into `src`.
53
+ *
54
+ * @param out
55
+ * @param src
56
+ * @param n
57
+ */
11
58
  export const shade = (out, src, n) => tint(out, src, n, 0);