@thi.ng/color 4.1.7 → 5.0.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +3 -3
  3. package/analog.d.ts +15 -15
  4. package/analog.js +16 -15
  5. package/api/constants.d.ts +1 -1
  6. package/api/constants.js +1 -1
  7. package/api/system.d.ts +1 -1
  8. package/api/system.js +1 -1
  9. package/api.d.ts +13 -6
  10. package/color-range.d.ts +6 -6
  11. package/color-range.js +6 -6
  12. package/convert.d.ts +1 -1
  13. package/convert.js +1 -1
  14. package/cosine-gradients.d.ts +5 -5
  15. package/cosine-gradients.js +5 -5
  16. package/css/parse-css.d.ts +1 -1
  17. package/css/parse-css.js +1 -1
  18. package/defcolor.js +5 -1
  19. package/distance.d.ts +17 -17
  20. package/distance.js +17 -17
  21. package/gradients.d.ts +2 -2
  22. package/gradients.js +2 -2
  23. package/hcy/hcy.js +5 -1
  24. package/hsi/hsi.js +5 -1
  25. package/hsl/hsl.js +10 -1
  26. package/hsv/hsv.js +10 -1
  27. package/index.d.ts +8 -0
  28. package/index.js +8 -0
  29. package/int/int-int.d.ts +1 -1
  30. package/int/int-int.js +1 -1
  31. package/internal/dispatch.d.ts +4 -0
  32. package/internal/dispatch.js +2 -0
  33. package/invert.d.ts +8 -1
  34. package/invert.js +34 -1
  35. package/is-black.d.ts +1 -1
  36. package/is-black.js +10 -7
  37. package/is-gamut.d.ts +9 -0
  38. package/is-gamut.js +16 -0
  39. package/is-gray.d.ts +1 -1
  40. package/is-gray.js +10 -8
  41. package/is-white.d.ts +1 -1
  42. package/is-white.js +9 -6
  43. package/lab/lab-css.d.ts +1 -1
  44. package/lab/lab-css.js +1 -1
  45. package/lab/lab-rgb.d.ts +4 -4
  46. package/lab/lab-rgb.js +4 -4
  47. package/lab/lab-xyz.d.ts +5 -5
  48. package/lab/lab-xyz.js +5 -5
  49. package/lch/lch-css.d.ts +1 -1
  50. package/lch/lch-css.js +1 -1
  51. package/lch/lch.js +1 -0
  52. package/lighten.d.ts +11 -0
  53. package/lighten.js +21 -0
  54. package/luminance-rgb.d.ts +2 -2
  55. package/luminance-rgb.js +2 -2
  56. package/luminance.d.ts +2 -2
  57. package/luminance.js +3 -2
  58. package/max-chroma.d.ts +8 -0
  59. package/max-chroma.js +240 -0
  60. package/mix.d.ts +8 -8
  61. package/mix.js +9 -8
  62. package/oklab/oklab-rgb.d.ts +2 -2
  63. package/oklab/oklab-rgb.js +2 -2
  64. package/package.json +131 -109
  65. package/rgb/rgb-lab.d.ts +4 -4
  66. package/rgb/rgb-lab.js +4 -4
  67. package/rgb/rgb-oklab.d.ts +2 -2
  68. package/rgb/rgb-oklab.js +2 -2
  69. package/rgb/rgb-xyz.d.ts +2 -2
  70. package/rgb/rgb-xyz.js +2 -2
  71. package/rgb/rgb-ycc.d.ts +3 -3
  72. package/rgb/rgb-ycc.js +3 -3
  73. package/rotate.d.ts +4 -0
  74. package/rotate.js +10 -0
  75. package/sort.d.ts +7 -7
  76. package/sort.js +7 -7
  77. package/strategies.d.ts +90 -0
  78. package/strategies.js +122 -0
  79. package/tint.d.ts +6 -0
  80. package/tint.js +11 -0
  81. package/transform.d.ts +11 -11
  82. package/transform.js +11 -11
  83. package/variations.d.ts +29 -0
  84. package/variations.js +14 -0
  85. package/xyy/xyy-xyz.d.ts +2 -2
  86. package/xyy/xyy-xyz.js +2 -2
  87. package/xyz/wavelength-xyz.d.ts +3 -3
  88. package/xyz/wavelength-xyz.js +3 -3
  89. package/xyz/xyz-lab.d.ts +5 -5
  90. package/xyz/xyz-lab.js +5 -5
  91. package/xyz/xyz-rgb.d.ts +2 -2
  92. package/xyz/xyz-rgb.js +2 -2
  93. package/xyz/xyz-xyy.d.ts +2 -2
  94. package/xyz/xyz-xyy.js +2 -2
  95. package/ycc/ycc-rgb.d.ts +3 -3
  96. package/ycc/ycc-rgb.js +3 -3
@@ -0,0 +1,90 @@
1
+ import { LCH } from "./lch/lch.js";
2
+ /**
3
+ * Returns array of `src` color and its complementary color, possibly adjusted
4
+ * via optional `deltaL` and `deltaC` args (offsets for L & C channels).
5
+ *
6
+ * @param src -
7
+ * @param deltaL -
8
+ * @param deltaC -
9
+ */
10
+ export declare const complementaryStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
11
+ /**
12
+ * Returns array of `src` color and 2 neighboring colors, each ±rotated by
13
+ * normalized `theta` and possibly adjusted via optional `deltaL` and `deltaC`
14
+ * args (offsets for L & C channels).
15
+ *
16
+ * @param src -
17
+ * @param theta -
18
+ * @param deltaL -
19
+ * @param deltaC -
20
+ */
21
+ export declare const analogStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
22
+ /**
23
+ * Similar to {@link splitComplementaryStrategy}. Returns array of `src` color,
24
+ * its complementary color and 2 of that colors' neighbors, each ±rotated by
25
+ * normalized `theta` and possibly adjusted via optional `deltaL` and `deltaC`
26
+ * args (offsets for L & C channels).
27
+ *
28
+ * @param src -
29
+ * @param theta -
30
+ * @param deltaL -
31
+ * @param deltaC -
32
+ */
33
+ export declare const splitAnalogStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
34
+ /**
35
+ * Similar to {@link splitAnalogStrategy}. Returns array of `src` color and 2
36
+ * neighbors of its complementary color, each ±rotated by normalized `theta`
37
+ * (from the complementary hue) and possibly adjusted via optional `deltaL` and
38
+ * `deltaC` args (offsets for L & C channels).
39
+ *
40
+ * @param src -
41
+ * @param theta -
42
+ * @param deltaL -
43
+ * @param deltaC -
44
+ */
45
+ export declare const splitComplementaryStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
46
+ /**
47
+ * Returns array of 5 colors all sharing same hue and chromacity of given `src`
48
+ * color, but with these luminance settings: 0.0, 0.25, 0.5, 0.75, 1.0. Chroma
49
+ * can be adjusted via optional `deltaC` offset.
50
+ *
51
+ * @param src -
52
+ * @param deltaC -
53
+ */
54
+ export declare const monochromeStrategy: (src: LCH, deltaC?: number) => LCH[];
55
+ /**
56
+ * Version of {@link splitComplementaryStrategy} with an hardcoded `theta` of
57
+ * 1/6 to produce 3 colors with hues uniformly distributed on the color wheel
58
+ * (possibly adjusted via optional `deltaL` and `deltaC` args, aka offsets for L
59
+ * & C channels).
60
+ *
61
+ * @param src -
62
+ * @param deltaL -
63
+ * @param deltaC -
64
+ */
65
+ export declare const triadicStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
66
+ /**
67
+ * Returns array of `src` color and 3 other colors whose hues form a rectangle,
68
+ * using `theta` to define the angular separation. The hues are at: `src`,
69
+ * `src+theta`, `src+1/2` (complementary) and `src+1/2+theta`. Colors are
70
+ * possibly adjusted via optional `deltaL` and `deltaC` args (offsets for L & C
71
+ * channels).
72
+ *
73
+ * @param src -
74
+ * @param theta -
75
+ * @param deltaL -
76
+ * @param deltaC -
77
+ */
78
+ export declare const tetradicStrategy: (src: LCH, theta?: number, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
79
+ /**
80
+ * Version of {@link tetradicStrategy} with an hardcoded `theta` of 1/4 to
81
+ * produce 4 colors with hues uniformly distributed on the color wheel (possibly
82
+ * adjusted via optional `deltaL` and `deltaC` args, aka offsets for L & C
83
+ * channels).
84
+ *
85
+ * @param src -
86
+ * @param deltaL -
87
+ * @param deltaC -
88
+ */
89
+ export declare const squareStrategy: (src: LCH, deltaL?: number | undefined, deltaC?: number | undefined) => LCH[];
90
+ //# sourceMappingURL=strategies.d.ts.map
package/strategies.js ADDED
@@ -0,0 +1,122 @@
1
+ import { clamp, clamp01 } from "@thi.ng/math/interval";
2
+ import { lch } from "./lch/lch.js";
3
+ import { rotate } from "./rotate.js";
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;
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),
32
+ ];
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),
47
+ ];
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),
63
+ ];
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
+ ];
82
+ };
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),
111
+ ];
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);
package/tint.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { MultiFn3O } from "@thi.ng/defmulti";
2
+ import type { Color, TypedColor } from "./api.js";
3
+ export declare const tint: MultiFn3O<Color | null, TypedColor<any>, number, number, Color>;
4
+ export declare const tone: (out: Color | null, src: TypedColor<any>, n: number) => import("@thi.ng/vectors").Vec;
5
+ export declare const shade: (out: Color | null, src: TypedColor<any>, n: number) => import("@thi.ng/vectors").Vec;
6
+ //# sourceMappingURL=tint.d.ts.map
package/tint.js ADDED
@@ -0,0 +1,11 @@
1
+ import { defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { mix } from "@thi.ng/math/mix";
3
+ import { setC4 } from "@thi.ng/vectors";
4
+ import { __dispatch1 } from "./internal/dispatch.js";
5
+ import { __ensureAlpha } from "./internal/ensure.js";
6
+ export const tint = defmulti(__dispatch1, { hcy: "hsv", hsi: "hsv", hsl: "hsv" }, {
7
+ hsv: (out, src, n, l = 1) => setC4(out || src, src[0], src[1] * (1 - n), mix(src[2], l, n), __ensureAlpha(src[3])),
8
+ lch: (out, src, n, l = 1) => setC4(out || src, mix(src[0], l, n), src[1] * (1 - n), src[2], __ensureAlpha(src[3])),
9
+ });
10
+ export const tone = (out, src, n) => tint(out, src, n, 0.5);
11
+ export const shade = (out, src, n) => tint(out, src, n, 0);
package/transform.d.ts CHANGED
@@ -36,7 +36,7 @@ export declare const IDENTITY: ColorMatrix;
36
36
  *
37
37
  * @param src - source color
38
38
  */
39
- export declare const subtract: (src?: ReadonlyColor) => ColorMatrix;
39
+ export declare const subtractMat: (src?: ReadonlyColor) => ColorMatrix;
40
40
  /**
41
41
  * Returns a transformation matrix which adds the given constant offset
42
42
  * `x` to RGB channels. Does NOT modify alpha channel.
@@ -46,14 +46,14 @@ export declare const subtract: (src?: ReadonlyColor) => ColorMatrix;
46
46
  *
47
47
  * @param x - brightness offset
48
48
  */
49
- export declare const brightness: (x: number) => ColorMatrix;
50
- export declare const contrast: (x: number, o?: number) => ColorMatrix;
51
- export declare const exposure: (x: number) => ColorMatrix;
52
- export declare const saturation: (x: number) => ColorMatrix;
53
- export declare const hueRotate: (theta: number) => ColorMatrix;
54
- export declare const temperature: (x: number) => ColorMatrix;
55
- export declare const sepia: (x?: number) => ColorMatrix;
56
- export declare const tint: (x: number) => ColorMatrix;
49
+ export declare const brightnessMat: (x: number) => ColorMatrix;
50
+ export declare const contrastMat: (x: number, o?: number) => ColorMatrix;
51
+ export declare const exposureMat: (x: number) => ColorMatrix;
52
+ export declare const saturationMat: (x: number) => ColorMatrix;
53
+ export declare const hueRotateMat: (theta: number) => ColorMatrix;
54
+ export declare const temperatureMat: (x: number) => ColorMatrix;
55
+ export declare const sepiaMat: (x?: number) => ColorMatrix;
56
+ export declare const tintMat: (x: number) => ColorMatrix;
57
57
  /**
58
58
  * Returns transformation matrix which computes luminance of user color
59
59
  * (optionally with custom coefficients). Does NOT modify alpha channel.
@@ -64,7 +64,7 @@ export declare const tint: (x: number) => ColorMatrix;
64
64
  * @param coeffs - luminance coefficients
65
65
  * @param offset - brightness offset
66
66
  */
67
- export declare const grayscale: ([r, g, b]?: number[], offset?: number) => ColorMatrix;
67
+ export declare const grayscaleMat: ([r, g, b]?: number[], offset?: number) => ColorMatrix;
68
68
  /**
69
69
  * Returns transformation matrix which computes luminance of user color
70
70
  * (optionally with custom coefficients), uses result as alpha channel
@@ -75,5 +75,5 @@ export declare const grayscale: ([r, g, b]?: number[], offset?: number) => Color
75
75
  *
76
76
  * @param coeffs - luminance coefficients
77
77
  */
78
- export declare const luminanceAlpha: ([r, g, b]?: number[]) => ColorMatrix;
78
+ export declare const luminanceAlphaMat: ([r, g, b]?: number[]) => ColorMatrix;
79
79
  //# sourceMappingURL=transform.d.ts.map
package/transform.js CHANGED
@@ -55,7 +55,7 @@ export const IDENTITY = [
55
55
  * @param src - source color
56
56
  */
57
57
  // prettier-ignore
58
- export const subtract = (src = WHITE) => [
58
+ export const subtractMat = (src = WHITE) => [
59
59
  -1, 0, 0, 0, src[0],
60
60
  0, -1, 0, 0, src[1],
61
61
  0, 0, -1, 0, src[2],
@@ -71,35 +71,35 @@ export const subtract = (src = WHITE) => [
71
71
  * @param x - brightness offset
72
72
  */
73
73
  // prettier-ignore
74
- export const brightness = (x) => [
74
+ export const brightnessMat = (x) => [
75
75
  1, 0, 0, 0, x,
76
76
  0, 1, 0, 0, x,
77
77
  0, 0, 1, 0, x,
78
78
  0, 0, 0, 1, 0
79
79
  ];
80
80
  // prettier-ignore
81
- export const contrast = (x, o = 0.5 * (1 - x)) => [
81
+ export const contrastMat = (x, o = 0.5 * (1 - x)) => [
82
82
  x, 0, 0, 0, o,
83
83
  0, x, 0, 0, o,
84
84
  0, 0, x, 0, o,
85
85
  0, 0, 0, 1, 0
86
86
  ];
87
87
  // prettier-ignore
88
- export const exposure = (x) => [
88
+ export const exposureMat = (x) => [
89
89
  x, 0, 0, 0, 0,
90
90
  0, x, 0, 0, 0,
91
91
  0, 0, x, 0, 0,
92
92
  0, 0, 0, 1, 0
93
93
  ];
94
94
  // prettier-ignore
95
- export const saturation = (x) => [
95
+ export const saturationMat = (x) => [
96
96
  S1 + S4 * x, S3 - S3 * x, S0 - S0 * x, 0, 0,
97
97
  S1 - S1 * x, S3 + S2 * x, S0 - S0 * x, 0, 0,
98
98
  S1 - S1 * x, S3 - S3 * x, S0 + S5 * x, 0, 0,
99
99
  0, 0, 0, 1, 0
100
100
  ];
101
101
  // prettier-ignore
102
- export const hueRotate = (theta) => {
102
+ export const hueRotateMat = (theta) => {
103
103
  const s = Math.sin(theta);
104
104
  const c = Math.cos(theta);
105
105
  return [
@@ -110,21 +110,21 @@ export const hueRotate = (theta) => {
110
110
  ];
111
111
  };
112
112
  // prettier-ignore
113
- export const temperature = (x) => [
113
+ export const temperatureMat = (x) => [
114
114
  1 + x, 0, 0, 0, 0,
115
115
  0, 1, 0, 0, 0,
116
116
  0, 0, 1 - x, 0, 0,
117
117
  0, 0, 0, 1, 0
118
118
  ];
119
119
  // prettier-ignore
120
- export const sepia = (x = 1) => [
120
+ export const sepiaMat = (x = 1) => [
121
121
  mix(1, 0.393, x), 0.769 * x, 0.189 * x, 0, 0,
122
122
  0.349 * x, mix(1, 0.686, x), 0.168 * x, 0, 0,
123
123
  0.272 * x, 0.534 * x, mix(1, 0.131, x), 0, 0,
124
124
  0, 0, 0, 1, 0
125
125
  ];
126
126
  // prettier-ignore
127
- export const tint = (x) => [
127
+ export const tintMat = (x) => [
128
128
  1 + x, 0, 0, 0, 0,
129
129
  0, 1, 0, 0, 0,
130
130
  0, 0, 1 + x, 0, 0,
@@ -141,7 +141,7 @@ export const tint = (x) => [
141
141
  * @param offset - brightness offset
142
142
  */
143
143
  // prettier-ignore
144
- export const grayscale = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0) => [
144
+ export const grayscaleMat = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0) => [
145
145
  r, g, b, 0, offset,
146
146
  r, g, b, 0, offset,
147
147
  r, g, b, 0, offset,
@@ -158,7 +158,7 @@ export const grayscale = ([r, g, b] = RGB_LUMINANCE_REC709, offset = 0) => [
158
158
  * @param coeffs - luminance coefficients
159
159
  */
160
160
  // prettier-ignore
161
- export const luminanceAlpha = ([r, g, b] = RGB_LUMINANCE_REC709) => [
161
+ export const luminanceAlphaMat = ([r, g, b] = RGB_LUMINANCE_REC709) => [
162
162
  0, 0, 0, 0, 0,
163
163
  0, 0, 0, 0, 0,
164
164
  0, 0, 0, 0, 0,
@@ -0,0 +1,29 @@
1
+ import type { IRandom } from "@thi.ng/random";
2
+ import type { TypedColor } from "./api.js";
3
+ export interface VariationOpts {
4
+ /**
5
+ * Max. number of color variations to produce.
6
+ *
7
+ * @defaultValue Infinity
8
+ */
9
+ num: number;
10
+ /**
11
+ * Weights (given in same order as colors) for randomly selecting colors. By
12
+ * default colors will be chosen with uniform distribution.
13
+ */
14
+ weights: number[];
15
+ /**
16
+ * Normalized tolerance value for randomizing channel values
17
+ *
18
+ * @defaultValue 0.05
19
+ */
20
+ delta: number;
21
+ /**
22
+ * PRNG instance to use.
23
+ *
24
+ * @defaultValue SYSTEM (aka `Math.random()`)
25
+ */
26
+ rnd: IRandom;
27
+ }
28
+ export declare function variations<T extends TypedColor<any>>(src: T[], opts?: Partial<VariationOpts>): Generator<T, void, unknown>;
29
+ //# sourceMappingURL=variations.d.ts.map
package/variations.js ADDED
@@ -0,0 +1,14 @@
1
+ import { pickRandom } from "@thi.ng/random/pick-random";
2
+ import { SYSTEM } from "@thi.ng/random/system";
3
+ import { weightedRandom } from "@thi.ng/random/weighted-random";
4
+ import { analog } from "./analog.js";
5
+ export function* variations(src, opts) {
6
+ opts = { rnd: SYSTEM, delta: 0.05, num: Infinity, ...opts };
7
+ const pick = opts.weights
8
+ ? weightedRandom(src, opts.weights, opts.rnd)
9
+ : () => pickRandom(src, opts.rnd);
10
+ for (let i = opts.num; i-- > 0;) {
11
+ const col = pick();
12
+ yield analog(col.empty(), col, opts.delta, opts.rnd);
13
+ }
14
+ }
package/xyy/xyy-xyz.d.ts CHANGED
@@ -4,8 +4,8 @@ import type { ColorOp } from "../api.js";
4
4
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
5
5
  * https://gamedev.stackexchange.com/a/70049
6
6
  *
7
- * @param out
8
- * @param src
7
+ * @param out -
8
+ * @param src -
9
9
  */
10
10
  export declare const xyyXyz: ColorOp;
11
11
  //# sourceMappingURL=xyy-xyz.d.ts.map
package/xyy/xyy-xyz.js CHANGED
@@ -6,8 +6,8 @@ import { __ensureAlpha } from "../internal/ensure.js";
6
6
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
7
7
  * https://gamedev.stackexchange.com/a/70049
8
8
  *
9
- * @param out
10
- * @param src
9
+ * @param out -
10
+ * @param src -
11
11
  */
12
12
  export const xyyXyz = (out, src) => {
13
13
  const { 0: x, 1: y, 2: Y } = src;
@@ -14,9 +14,9 @@ import { XYZD65 } from "./xyz65.js";
14
14
  * - 570 => yellow
15
15
  * - 610 => red
16
16
  *
17
- * @param out
18
- * @param lambda
19
- * @param alpha
17
+ * @param out -
18
+ * @param lambda -
19
+ * @param alpha -
20
20
  */
21
21
  export declare const wavelengthXyz: (out: XYZD65 | null, lambda: number, alpha?: number) => XYZD65;
22
22
  //# sourceMappingURL=wavelength-xyz.d.ts.map
@@ -15,9 +15,9 @@ import { xyzD65 } from "./xyz65.js";
15
15
  * - 570 => yellow
16
16
  * - 610 => red
17
17
  *
18
- * @param out
19
- * @param lambda
20
- * @param alpha
18
+ * @param out -
19
+ * @param lambda -
20
+ * @param alpha -
21
21
  */
22
22
  export const wavelengthXyz = (out, lambda, alpha = 1) => {
23
23
  lambda *= 10;
package/xyz/xyz-lab.d.ts CHANGED
@@ -7,16 +7,16 @@ import type { Color, ColorOp, ReadonlyColor } from "../api.js";
7
7
  * Important: We're using a normalized Lab space w/ all three coordinates
8
8
  * divided by 100 (normalized to 100% luminance).
9
9
  *
10
- * @param out
11
- * @param src
12
- * @param white
10
+ * @param out -
11
+ * @param src -
12
+ * @param white -
13
13
  */
14
14
  export declare const xyzLab: (out: Color | null, src: ReadonlyColor, white?: number[]) => import("@thi.ng/vectors").Vec;
15
15
  /**
16
16
  * Same as {@link xyzLab}, but hard coded to use {@link D65} white point.
17
17
  *
18
- * @param out
19
- * @param src
18
+ * @param out -
19
+ * @param src -
20
20
  */
21
21
  export declare const xyzLabD65: ColorOp;
22
22
  //# sourceMappingURL=xyz-lab.d.ts.map
package/xyz/xyz-lab.js CHANGED
@@ -11,9 +11,9 @@ const transform = (x) => x > 0.00885645 ? Math.cbrt(x) : 7.787037 * x + 16 / 116
11
11
  * Important: We're using a normalized Lab space w/ all three coordinates
12
12
  * divided by 100 (normalized to 100% luminance).
13
13
  *
14
- * @param out
15
- * @param src
16
- * @param white
14
+ * @param out -
15
+ * @param src -
16
+ * @param white -
17
17
  */
18
18
  export const xyzLab = (out, src, white = D50) => {
19
19
  const x = transform(src[0] / white[0]);
@@ -24,7 +24,7 @@ export const xyzLab = (out, src, white = D50) => {
24
24
  /**
25
25
  * Same as {@link xyzLab}, but hard coded to use {@link D65} white point.
26
26
  *
27
- * @param out
28
- * @param src
27
+ * @param out -
28
+ * @param src -
29
29
  */
30
30
  export const xyzLabD65 = (out, src) => xyzLab(out, src, D65);
package/xyz/xyz-rgb.d.ts CHANGED
@@ -13,8 +13,8 @@ export declare const xyzRgb: (out: Color | null, src: ReadonlyColor, mat?: numbe
13
13
  * Same as {@link xyzRgb}, but hard coded to use {@link D65} white point (via
14
14
  * {@link XYZ_RGB_D65} matrix).
15
15
  *
16
- * @param out
17
- * @param src
16
+ * @param out -
17
+ * @param src -
18
18
  */
19
19
  export declare const xyzRgbD65: ColorOp;
20
20
  //# sourceMappingURL=xyz-rgb.d.ts.map
package/xyz/xyz-rgb.js CHANGED
@@ -14,7 +14,7 @@ export const xyzRgb = (out, src, mat = XYZ_RGB_D50) => __mulV33(out, mat, src);
14
14
  * Same as {@link xyzRgb}, but hard coded to use {@link D65} white point (via
15
15
  * {@link XYZ_RGB_D65} matrix).
16
16
  *
17
- * @param out
18
- * @param src
17
+ * @param out -
18
+ * @param src -
19
19
  */
20
20
  export const xyzRgbD65 = (out, src) => xyzRgb(out, src, XYZ_RGB_D65);
package/xyz/xyz-xyy.d.ts CHANGED
@@ -4,8 +4,8 @@ import type { ColorOp } from "../api.js";
4
4
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
5
5
  * https://gamedev.stackexchange.com/a/70049
6
6
  *
7
- * @param out
8
- * @param src
7
+ * @param out -
8
+ * @param src -
9
9
  */
10
10
  export declare const xyzXyy: ColorOp;
11
11
  //# sourceMappingURL=xyz-xyy.d.ts.map
package/xyz/xyz-xyy.js CHANGED
@@ -6,8 +6,8 @@ import { __ensureAlpha } from "../internal/ensure.js";
6
6
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
7
7
  * https://gamedev.stackexchange.com/a/70049
8
8
  *
9
- * @param out
10
- * @param src
9
+ * @param out -
10
+ * @param src -
11
11
  */
12
12
  export const xyzXyy = (out, src) => {
13
13
  const { 0: x, 1: Y } = src;
package/ycc/ycc-rgb.d.ts CHANGED
@@ -9,9 +9,9 @@ import type { Color, ReadonlyColor } from "../api.js";
9
9
  * - https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion
10
10
  * - https://en.wikipedia.org/wiki/Rec._709
11
11
  *
12
- * @param out
13
- * @param src
14
- * @param luma
12
+ * @param out -
13
+ * @param src -
14
+ * @param luma -
15
15
  */
16
16
  export declare const yccRgb: (out: Color | null, src: ReadonlyColor, luma?: number[]) => import("@thi.ng/vectors").Vec;
17
17
  //# sourceMappingURL=ycc-rgb.d.ts.map
package/ycc/ycc-rgb.js CHANGED
@@ -11,9 +11,9 @@ import { __ensureAlpha } from "../internal/ensure.js";
11
11
  * - https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.709_conversion
12
12
  * - https://en.wikipedia.org/wiki/Rec._709
13
13
  *
14
- * @param out
15
- * @param src
16
- * @param luma
14
+ * @param out -
15
+ * @param src -
16
+ * @param luma -
17
17
  */
18
18
  export const yccRgb = (out, src, luma = RGB_LUMINANCE_REC709) => {
19
19
  const y = src[0];