@thi.ng/color 5.6.2 → 5.6.4

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/alpha.js +6 -10
  4. package/analog.js +35 -67
  5. package/api/constants.js +128 -156
  6. package/api/gradients.js +0 -1
  7. package/api/names.js +154 -151
  8. package/api/ranges.js +0 -1
  9. package/api/system.js +21 -26
  10. package/api.js +27 -32
  11. package/clamp.js +18 -29
  12. package/closest-hue.js +6 -12
  13. package/color-range.js +159 -228
  14. package/color.js +29 -28
  15. package/contrast.js +7 -17
  16. package/convert.js +19 -40
  17. package/cosine-gradients.js +177 -229
  18. package/css/css.js +27 -53
  19. package/css/parse-css.js +94 -160
  20. package/defcolor.js +97 -108
  21. package/distance.js +96 -187
  22. package/gradients.js +29 -37
  23. package/hcy/hcy-rgb.js +20 -13
  24. package/hcy/hcy.js +9 -11
  25. package/hsi/hsi-rgb.js +32 -30
  26. package/hsi/hsi.js +9 -11
  27. package/hsl/hsl-css.js +9 -10
  28. package/hsl/hsl-hsv.js +12 -9
  29. package/hsl/hsl-rgb.js +14 -6
  30. package/hsl/hsl.js +14 -16
  31. package/hsv/hsv-css.js +4 -1
  32. package/hsv/hsv-hsl.js +11 -8
  33. package/hsv/hsv-rgb.js +14 -6
  34. package/hsv/hsv.js +14 -16
  35. package/hue.js +12 -12
  36. package/int/int-css.js +10 -6
  37. package/int/int-int.js +6 -10
  38. package/int/int-rgb.js +16 -5
  39. package/int/int-srgb.js +22 -4
  40. package/int/int.js +136 -142
  41. package/internal/css.js +16 -12
  42. package/internal/dispatch.js +6 -2
  43. package/internal/ensure.js +18 -16
  44. package/internal/matrix-ops.js +39 -41
  45. package/internal/scale.js +4 -2
  46. package/invert.js +46 -39
  47. package/is-black.js +12 -5
  48. package/is-gamut.js +8 -13
  49. package/is-gray.js +12 -5
  50. package/is-white.js +14 -7
  51. package/lab/lab-css.js +4 -9
  52. package/lab/lab-lab.js +6 -2
  53. package/lab/lab-lch.js +18 -10
  54. package/lab/lab-rgb.js +6 -14
  55. package/lab/lab-xyz.js +16 -20
  56. package/lab/lab50.js +18 -15
  57. package/lab/lab65.js +18 -15
  58. package/lch/lch-css.js +4 -9
  59. package/lch/lch.js +18 -23
  60. package/lighten.js +13 -17
  61. package/linear.js +6 -16
  62. package/luminance-rgb.js +14 -22
  63. package/luminance.js +16 -14
  64. package/max-chroma.js +1340 -227
  65. package/mix.js +34 -82
  66. package/oklab/oklab-css.js +4 -9
  67. package/oklab/oklab-rgb.js +17 -23
  68. package/oklab/oklab-xyz.js +22 -9
  69. package/oklab/oklab.js +19 -22
  70. package/oklch/oklab-oklch.js +10 -11
  71. package/oklch/oklch-css.js +4 -9
  72. package/oklch/oklch-oklab.js +9 -9
  73. package/oklch/oklch.js +14 -20
  74. package/package.json +19 -17
  75. package/rgb/hue-rgb.js +14 -11
  76. package/rgb/kelvin-rgba.js +23 -22
  77. package/rgb/rgb-css.js +4 -1
  78. package/rgb/rgb-hcv.js +14 -15
  79. package/rgb/rgb-hcy.js +10 -14
  80. package/rgb/rgb-hsi.js +13 -8
  81. package/rgb/rgb-hsl.js +8 -5
  82. package/rgb/rgb-hsv.js +7 -4
  83. package/rgb/rgb-lab.js +6 -18
  84. package/rgb/rgb-oklab.js +13 -19
  85. package/rgb/rgb-srgb.js +18 -8
  86. package/rgb/rgb-xyz.js +6 -19
  87. package/rgb/rgb-ycc.js +12 -17
  88. package/rgb/rgb.js +25 -22
  89. package/rotate.js +25 -38
  90. package/sort.js +24 -72
  91. package/srgb/srgb-css.js +9 -9
  92. package/srgb/srgb-int.js +6 -10
  93. package/srgb/srgb-rgb.js +18 -8
  94. package/srgb/srgb.js +16 -13
  95. package/strategies.js +42 -112
  96. package/swatches.js +28 -5
  97. package/tint.js +27 -53
  98. package/transform.js +274 -149
  99. package/variations.js +10 -9
  100. package/xyy/xyy-xyz.js +12 -11
  101. package/xyy/xyy.js +16 -13
  102. package/xyz/wavelength-xyz.js +14 -28
  103. package/xyz/xyz-lab.js +17 -26
  104. package/xyz/xyz-oklab.js +4 -1
  105. package/xyz/xyz-rgb.js +6 -18
  106. package/xyz/xyz-xyy.js +13 -12
  107. package/xyz/xyz-xyz.js +6 -2
  108. package/xyz/xyz50.js +20 -17
  109. package/xyz/xyz65.js +20 -17
  110. package/ycc/ycc-rgb.js +14 -19
  111. package/ycc/ycc.js +12 -9
package/strategies.js CHANGED
@@ -2,121 +2,51 @@ import { clamp, clamp01 } from "@thi.ng/math/interval";
2
2
  import { lch } from "./lch/lch.js";
3
3
  import { rotate } from "./rotate.js";
4
4
  const $ = (src, l = 0, c = 0) => {
5
- src.l = clamp01(src.l + l);
6
- src.c = clamp(src.c + c, 0, 1.312);
7
- return src;
5
+ src.l = clamp01(src.l + l);
6
+ src.c = clamp(src.c + c, 0, 1.312);
7
+ return src;
8
8
  };
9
- /**
10
- * Returns array of `src` color and its complementary color, possibly adjusted
11
- * via optional `deltaL` and `deltaC` args (offsets for L & C channels).
12
- *
13
- * @param src -
14
- * @param deltaL -
15
- * @param deltaC -
16
- */
17
- export const complementaryStrategy = (src, deltaL, deltaC) => [src, $(rotate(lch(), src, 0.5), deltaL, deltaC)];
18
- /**
19
- * Returns array of `src` color and 2 neighboring colors, each ±rotated by
20
- * normalized `theta` and possibly adjusted via optional `deltaL` and `deltaC`
21
- * args (offsets for L & C channels).
22
- *
23
- * @param src -
24
- * @param theta -
25
- * @param deltaL -
26
- * @param deltaC -
27
- */
28
- export const analogStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
29
- src,
30
- $(rotate(lch(), src, -theta), deltaL, deltaC),
31
- $(rotate(lch(), src, theta), deltaL, deltaC),
9
+ const complementaryStrategy = (src, deltaL, deltaC) => [src, $(rotate(lch(), src, 0.5), deltaL, deltaC)];
10
+ const analogStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
11
+ src,
12
+ $(rotate(lch(), src, -theta), deltaL, deltaC),
13
+ $(rotate(lch(), src, theta), deltaL, deltaC)
32
14
  ];
33
- /**
34
- * Similar to {@link splitComplementaryStrategy}. Returns array of `src` color,
35
- * its complementary color and 2 of that colors' neighbors, each ±rotated by
36
- * normalized `theta` and possibly adjusted via optional `deltaL` and `deltaC`
37
- * args (offsets for L & C channels).
38
- *
39
- * @param src -
40
- * @param theta -
41
- * @param deltaL -
42
- * @param deltaC -
43
- */
44
- export const splitAnalogStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
45
- ...splitComplementaryStrategy(src, theta, deltaL, deltaC),
46
- $(rotate(lch(), src, theta), deltaL, deltaC),
15
+ const splitAnalogStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
16
+ ...splitComplementaryStrategy(src, theta, deltaL, deltaC),
17
+ $(rotate(lch(), src, theta), deltaL, deltaC)
47
18
  ];
48
- /**
49
- * Similar to {@link splitAnalogStrategy}. Returns array of `src` color and 2
50
- * neighbors of its complementary color, each ±rotated by normalized `theta`
51
- * (from the complementary hue) and possibly adjusted via optional `deltaL` and
52
- * `deltaC` args (offsets for L & C channels).
53
- *
54
- * @param src -
55
- * @param theta -
56
- * @param deltaL -
57
- * @param deltaC -
58
- */
59
- export const splitComplementaryStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
60
- src,
61
- $(rotate(lch(), src, 0.5 - theta), deltaL, deltaC),
62
- $(rotate(lch(), src, 0.5 + theta), deltaL, deltaC),
19
+ const splitComplementaryStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
20
+ src,
21
+ $(rotate(lch(), src, 0.5 - theta), deltaL, deltaC),
22
+ $(rotate(lch(), src, 0.5 + theta), deltaL, deltaC)
63
23
  ];
64
- /**
65
- * Returns array of 5 colors all sharing same hue and chromacity of given `src`
66
- * color, but with these luminance settings: 0.0, 0.25, 0.5, 0.75, 1.0. Chroma
67
- * can be adjusted via optional `deltaC` offset.
68
- *
69
- * @param src -
70
- * @param deltaC -
71
- */
72
- export const monochromeStrategy = (src, deltaC = 0) => {
73
- let [_, c, h, a] = src;
74
- c = clamp(c + deltaC, 0, 1.312);
75
- return [
76
- lch(0.0, c, h, a),
77
- lch(0.25, c, h, a),
78
- lch(0.5, c, h, a),
79
- lch(0.75, c, h, a),
80
- lch(1, c, h, a),
81
- ];
24
+ const monochromeStrategy = (src, deltaC = 0) => {
25
+ let [_, c, h, a] = src;
26
+ c = clamp(c + deltaC, 0, 1.312);
27
+ return [
28
+ lch(0, c, h, a),
29
+ lch(0.25, c, h, a),
30
+ lch(0.5, c, h, a),
31
+ lch(0.75, c, h, a),
32
+ lch(1, c, h, a)
33
+ ];
82
34
  };
83
- /**
84
- * Version of {@link splitComplementaryStrategy} with an hardcoded `theta` of
85
- * 1/6 to produce 3 colors with hues uniformly distributed on the color wheel
86
- * (possibly adjusted via optional `deltaL` and `deltaC` args, aka offsets for L
87
- * & C channels).
88
- *
89
- * @param src -
90
- * @param deltaL -
91
- * @param deltaC -
92
- */
93
- export const triadicStrategy = (src, deltaL, deltaC) => splitComplementaryStrategy(src, 1 / 6, deltaL, deltaC);
94
- /**
95
- * Returns array of `src` color and 3 other colors whose hues form a rectangle,
96
- * using `theta` to define the angular separation. The hues are at: `src`,
97
- * `src+theta`, `src+1/2` (complementary) and `src+1/2+theta`. Colors are
98
- * possibly adjusted via optional `deltaL` and `deltaC` args (offsets for L & C
99
- * channels).
100
- *
101
- * @param src -
102
- * @param theta -
103
- * @param deltaL -
104
- * @param deltaC -
105
- */
106
- export const tetradicStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
107
- src,
108
- $(rotate(lch(), src, theta), deltaL, deltaC),
109
- $(rotate(lch(), src, 0.5), deltaL, deltaC),
110
- $(rotate(lch(), src, 0.5 + theta), deltaL, deltaC),
35
+ const triadicStrategy = (src, deltaL, deltaC) => splitComplementaryStrategy(src, 1 / 6, deltaL, deltaC);
36
+ const tetradicStrategy = (src, theta = 1 / 12, deltaL, deltaC) => [
37
+ src,
38
+ $(rotate(lch(), src, theta), deltaL, deltaC),
39
+ $(rotate(lch(), src, 0.5), deltaL, deltaC),
40
+ $(rotate(lch(), src, 0.5 + theta), deltaL, deltaC)
111
41
  ];
112
- /**
113
- * Version of {@link tetradicStrategy} with an hardcoded `theta` of 1/4 to
114
- * produce 4 colors with hues uniformly distributed on the color wheel (possibly
115
- * adjusted via optional `deltaL` and `deltaC` args, aka offsets for L & C
116
- * channels).
117
- *
118
- * @param src -
119
- * @param deltaL -
120
- * @param deltaC -
121
- */
122
- export const squareStrategy = (src, deltaL, deltaC) => tetradicStrategy(src, 0.25, deltaL, deltaC);
42
+ const squareStrategy = (src, deltaL, deltaC) => tetradicStrategy(src, 0.25, deltaL, deltaC);
43
+ export {
44
+ analogStrategy,
45
+ complementaryStrategy,
46
+ monochromeStrategy,
47
+ splitAnalogStrategy,
48
+ splitComplementaryStrategy,
49
+ squareStrategy,
50
+ tetradicStrategy,
51
+ triadicStrategy
52
+ };
package/swatches.js CHANGED
@@ -1,5 +1,28 @@
1
- export const swatches = (cols, shapeFn, attribs = {}) => ["g", attribs, ...cols.map(shapeFn)];
2
- export const swatchesH = (cols, w = 5, h = 50, gap = 0, attribs) => swatches(cols, (fill, i) => ["rect", { fill }, [i * (w + gap), 0], w, h], attribs);
3
- export const dotsH = (cols, r = 25, gap = 0, attribs) => swatches(cols, (fill, i) => ["circle", { fill }, [i * (r * 2 + gap), 0], r], attribs);
4
- export const swatchesV = (cols, w = 50, h = 5, gap = 0, attribs = {}) => swatches(cols, (fill, i) => ["rect", { fill }, [0, i * (h + gap)], w, h], attribs);
5
- export const dotsV = (cols, r = 25, gap = 0, attribs) => swatches(cols, (fill, i) => ["circle", { fill }, [0, i * (r * 2 + gap)], r], attribs);
1
+ const swatches = (cols, shapeFn, attribs = {}) => ["g", attribs, ...cols.map(shapeFn)];
2
+ const swatchesH = (cols, w = 5, h = 50, gap = 0, attribs) => swatches(
3
+ cols,
4
+ (fill, i) => ["rect", { fill }, [i * (w + gap), 0], w, h],
5
+ attribs
6
+ );
7
+ const dotsH = (cols, r = 25, gap = 0, attribs) => swatches(
8
+ cols,
9
+ (fill, i) => ["circle", { fill }, [i * (r * 2 + gap), 0], r],
10
+ attribs
11
+ );
12
+ const swatchesV = (cols, w = 50, h = 5, gap = 0, attribs = {}) => swatches(
13
+ cols,
14
+ (fill, i) => ["rect", { fill }, [0, i * (h + gap)], w, h],
15
+ attribs
16
+ );
17
+ const dotsV = (cols, r = 25, gap = 0, attribs) => swatches(
18
+ cols,
19
+ (fill, i) => ["circle", { fill }, [0, i * (r * 2 + gap)], r],
20
+ attribs
21
+ );
22
+ export {
23
+ dotsH,
24
+ dotsV,
25
+ swatches,
26
+ swatchesH,
27
+ swatchesV
28
+ };
package/tint.js CHANGED
@@ -3,56 +3,30 @@ 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
- /**
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" }, {
30
- hsv: (out, src, n, l = 1) => setC4(out || src, src[0], src[1] * (1 - n), mix(src[2], l, n), __ensureAlpha(src[3])),
31
- lch: (out, src, n, l = 1) => setC4(out || src, mix(src[0], l, n), src[1] * (1 - n), src[2], __ensureAlpha(src[3])),
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
- */
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
- */
58
- export const shade = (out, src, n) => tint(out, src, n, 0);
6
+ const tint = defmulti(
7
+ __dispatch1,
8
+ { hcy: "hsv", hsi: "hsv", hsl: "hsv", oklch: "lch" },
9
+ {
10
+ hsv: (out, src, n, l = 1) => setC4(
11
+ out || src,
12
+ src[0],
13
+ src[1] * (1 - n),
14
+ mix(src[2], l, n),
15
+ __ensureAlpha(src[3])
16
+ ),
17
+ lch: (out, src, n, l = 1) => setC4(
18
+ out || src,
19
+ mix(src[0], l, n),
20
+ src[1] * (1 - n),
21
+ src[2],
22
+ __ensureAlpha(src[3])
23
+ )
24
+ }
25
+ );
26
+ const tone = (out, src, n) => tint(out, src, n, 0.5);
27
+ const shade = (out, src, n) => tint(out, src, n, 0);
28
+ export {
29
+ shade,
30
+ tint,
31
+ tone
32
+ };