@thi.ng/color 4.1.7 → 5.0.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.
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 +41 -19
  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
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2021-12-13T10:26:00Z
3
+ - **Last updated**: 2022-03-11T12:13:49Z
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.
@@ -9,6 +9,36 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ # [5.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@5.0.0) (2022-03-11)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - rename color matrix fns ([00fdc31](https://github.com/thi-ng/umbrella/commit/00fdc31))
17
+ - BREAKING CHANGE: rename color matrix fns
18
+ - add `Mat` suffix, e.g. `grayscale()` => `grayscaleMat()`
19
+
20
+ #### 🚀 Features
21
+
22
+ - add color theme strategies ([22057e5](https://github.com/thi-ng/umbrella/commit/22057e5))
23
+ - add strategy fns:
24
+ - `complementaryStrategy()`
25
+ - `splitComplementaryStrategy()`
26
+ - `monochromeStrategy()`
27
+ - `triadicStrategy()`
28
+ - `tetradicStrategy()`
29
+ - `squareStrategy()`
30
+ - add variations() generator ([91d760f](https://github.com/thi-ng/umbrella/commit/91d760f))
31
+ - add max chroma LCH fns ([ab4e67a](https://github.com/thi-ng/umbrella/commit/ab4e67a))
32
+ - add/update color ops ([33cb4a1](https://github.com/thi-ng/umbrella/commit/33cb4a1))
33
+ - add `invert()`, `isRgbGamut()`, `lighten()`, `rotate()` ops
34
+ - add `tint()`, `tone()`, `shade()` ops
35
+ - update impls for `isBlack/Gray/White()`
36
+ - add/re-use internal multimethod dispatch fns
37
+ - update ChannelSpec and hue-based modes ([01d93dc](https://github.com/thi-ng/umbrella/commit/01d93dc))
38
+ - add `hue` flag for channel spec
39
+ - update `.clamp()` impl to wrap hue in [0..1] interval
40
+ - add/update LCH conversion paths
41
+
12
42
  ## [4.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/color@4.1.0) (2021-11-17)
13
43
 
14
44
  #### 🚀 Features
package/README.md CHANGED
@@ -571,7 +571,7 @@ concatenation (see `concat()`) for more efficient application.
571
571
 
572
572
  ### Support packages
573
573
 
574
- - [@thi.ng/color-palettes](https://github.com/thi-ng/umbrella/tree/develop/packages/color-palettes) - Collection of 132 image based color palettes
574
+ - [@thi.ng/color-palettes](https://github.com/thi-ng/umbrella/tree/develop/packages/color-palettes) - Collection of 176 image based color palettes
575
575
 
576
576
  ### Related packages
577
577
 
@@ -601,7 +601,7 @@ node --experimental-repl-await
601
601
  > const color = await import("@thi.ng/color");
602
602
  ```
603
603
 
604
- Package sizes (gzipped, pre-treeshake): ESM: 15.02 KB
604
+ Package sizes (gzipped, pre-treeshake): ESM: 17.43 KB
605
605
 
606
606
  ## Dependencies
607
607
 
@@ -659,4 +659,4 @@ If this project contributes to an academic publication, please cite it as:
659
659
 
660
660
  ## License
661
661
 
662
- © 2016 - 2021 Karsten Schmidt // Apache Software License 2.0
662
+ © 2016 - 2022 Karsten Schmidt // Apache Software License 2.0
package/analog.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const defAnalog: FnU3<Fn3<number, number, IRandom, number>, Fn4<C
7
7
  * `delta`. Each channel will be randomized by +/- `delta`, optionally using
8
8
  * provided {@link @thi.ng/random#IRandom} PRNG.
9
9
  */
10
- export declare const analog: import("@thi.ng/defmulti/api").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, number, IRandom | undefined, import("@thi.ng/vectors").Vec>;
10
+ export declare const analog: import("@thi.ng/defmulti").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, number, IRandom | undefined, import("@thi.ng/vectors").Vec>;
11
11
  /**
12
12
  * Similar to {@link analogRGB}. Returns an analog color based on given HSVA
13
13
  * color, with each channel randomly varied by given channel-specific delta
@@ -20,13 +20,13 @@ export declare const analog: import("@thi.ng/defmulti/api").MultiFn4<import("@th
20
20
  * By default (unless `deltaS`, `deltaV`, `deltaA` are provided) only the hue of
21
21
  * the color will be modulated.
22
22
  *
23
- * @param out
24
- * @param src
25
- * @param deltaH
26
- * @param deltaS
27
- * @param deltaV
28
- * @param deltaA
29
- * @param rnd
23
+ * @param out -
24
+ * @param src -
25
+ * @param deltaH -
26
+ * @param deltaS -
27
+ * @param deltaV -
28
+ * @param deltaA -
29
+ * @param rnd -
30
30
  */
31
31
  export declare const analogHsv: (out: Color | null, src: ReadonlyColor, deltaH: number, deltaS?: number, deltaV?: number, deltaA?: number, rnd?: IRandom) => import("@thi.ng/vectors").Vec;
32
32
  /**
@@ -37,13 +37,13 @@ export declare const analogHsv: (out: Color | null, src: ReadonlyColor, deltaH:
37
37
  * @remarks
38
38
  * By default the green and blue channel variance will be the same as `deltaR`.
39
39
  *
40
- * @param out
41
- * @param src
42
- * @param deltaR
43
- * @param deltaG
44
- * @param deltaB
45
- * @param deltaA
46
- * @param rnd
40
+ * @param out -
41
+ * @param src -
42
+ * @param deltaR -
43
+ * @param deltaG -
44
+ * @param deltaB -
45
+ * @param deltaA -
46
+ * @param rnd -
47
47
  */
48
48
  export declare const analogRgb: (out: Color | null, src: ReadonlyColor, deltaR: number, deltaG?: number, deltaB?: number, deltaA?: number, rnd?: IRandom) => import("@thi.ng/vectors").Vec;
49
49
  //# sourceMappingURL=analog.d.ts.map
package/analog.js CHANGED
@@ -3,6 +3,7 @@ import { clamp01 } from "@thi.ng/math/interval";
3
3
  import { fract } from "@thi.ng/math/prec";
4
4
  import { SYSTEM } from "@thi.ng/random/system";
5
5
  import { setC4 } from "@thi.ng/vectors/setc";
6
+ import { __dispatch1 } from "./internal/dispatch.js";
6
7
  import { __ensureAlpha } from "./internal/ensure.js";
7
8
  /** @internal */
8
9
  const analogU = (x, delta, rnd) => delta !== 0 ? x + rnd.norm(delta) : x;
@@ -26,7 +27,7 @@ const analogNUU = defAnalog(analogN, analogU, analogU);
26
27
  * `delta`. Each channel will be randomized by +/- `delta`, optionally using
27
28
  * provided {@link @thi.ng/random#IRandom} PRNG.
28
29
  */
29
- export const analog = defmulti((_, src) => src.mode, {}, {
30
+ export const analog = defmulti(__dispatch1, {}, {
30
31
  hcy: analogHNN,
31
32
  hsi: analogHNN,
32
33
  hsl: analogHNN,
@@ -49,13 +50,13 @@ export const analog = defmulti((_, src) => src.mode, {}, {
49
50
  * By default (unless `deltaS`, `deltaV`, `deltaA` are provided) only the hue of
50
51
  * the color will be modulated.
51
52
  *
52
- * @param out
53
- * @param src
54
- * @param deltaH
55
- * @param deltaS
56
- * @param deltaV
57
- * @param deltaA
58
- * @param rnd
53
+ * @param out -
54
+ * @param src -
55
+ * @param deltaH -
56
+ * @param deltaS -
57
+ * @param deltaV -
58
+ * @param deltaA -
59
+ * @param rnd -
59
60
  */
60
61
  export const analogHsv = (out, src, deltaH, deltaS = 0, deltaV = 0, deltaA = 0, rnd = SYSTEM) => setC4(out || src, analogN(src[0], deltaH, rnd, fract), analogN(src[1], deltaS, rnd), analogN(src[2], deltaV, rnd), analogA(src[3], deltaA, rnd));
61
62
  /**
@@ -66,12 +67,12 @@ export const analogHsv = (out, src, deltaH, deltaS = 0, deltaV = 0, deltaA = 0,
66
67
  * @remarks
67
68
  * By default the green and blue channel variance will be the same as `deltaR`.
68
69
  *
69
- * @param out
70
- * @param src
71
- * @param deltaR
72
- * @param deltaG
73
- * @param deltaB
74
- * @param deltaA
75
- * @param rnd
70
+ * @param out -
71
+ * @param src -
72
+ * @param deltaR -
73
+ * @param deltaG -
74
+ * @param deltaB -
75
+ * @param deltaA -
76
+ * @param rnd -
76
77
  */
77
78
  export const analogRgb = (out, src, deltaR, deltaG = deltaR, deltaB = deltaR, deltaA = 0, rnd = SYSTEM) => setC4(out || src, analogN(src[0], deltaR, rnd), analogN(src[1], deltaG, rnd), analogN(src[2], deltaB, rnd), analogA(src[3], deltaA, rnd));
@@ -131,7 +131,7 @@ export declare let PC: import("@thi.ng/strings").Stringer<number>;
131
131
  * Sets precision for CSS formatted values to `x` significant digits (default:
132
132
  * 3).
133
133
  *
134
- * @param x
134
+ * @param x -
135
135
  */
136
136
  export declare const setPrecision: (x: number) => void;
137
137
  export declare const INV8BIT: number;
package/api/constants.js CHANGED
@@ -157,7 +157,7 @@ export let PC = percent(3);
157
157
  * Sets precision for CSS formatted values to `x` significant digits (default:
158
158
  * 3).
159
159
  *
160
- * @param x
160
+ * @param x -
161
161
  */
162
162
  export const setPrecision = (x) => {
163
163
  FF = float(x);
package/api/system.d.ts CHANGED
@@ -74,7 +74,7 @@ export declare let CSS_SYSTEM_COLORS: SystemColors;
74
74
  /**
75
75
  * Merges {@link CSS_SYSTEM_COLORS} w/ new values.
76
76
  *
77
- * @param cols
77
+ * @param cols -
78
78
  */
79
79
  export declare const setSystemColors: (cols: Partial<SystemColors>) => SystemColors & Partial<SystemColors>;
80
80
  //# sourceMappingURL=system.d.ts.map
package/api/system.js CHANGED
@@ -22,6 +22,6 @@ export let CSS_SYSTEM_COLORS = {
22
22
  /**
23
23
  * Merges {@link CSS_SYSTEM_COLORS} w/ new values.
24
24
  *
25
- * @param cols
25
+ * @param cols -
26
26
  */
27
27
  export const setSystemColors = (cols) => Object.assign(CSS_SYSTEM_COLORS, cols);
package/api.d.ts CHANGED
@@ -29,9 +29,16 @@ export interface IColor {
29
29
  export interface ChannelSpec {
30
30
  /**
31
31
  * Acceptable value range for this channel. Used by {@link TypedColor.clamp}.
32
+ *
32
33
  * @defaultValue [0,1]
33
34
  */
34
35
  range?: Range;
36
+ /**
37
+ * If true, this channel is used to store normalized hue values.
38
+ *
39
+ * @defaultValue false
40
+ */
41
+ hue?: boolean;
35
42
  }
36
43
  export interface ColorSpec<M extends ColorMode, K extends string> {
37
44
  mode: M;
@@ -71,10 +78,10 @@ export interface ColorFactory<T extends TypedColor<any>> {
71
78
  * `buf` is given, the returned color will wrap `buf` from given `index`
72
79
  * (default: 0) and `stride` step size (default: 1).
73
80
  *
74
- * @param rnd
75
- * @param buf
76
- * @param index
77
- * @param stride
81
+ * @param rnd -
82
+ * @param buf -
83
+ * @param index -
84
+ * @param stride -
78
85
  */
79
86
  random(rnd?: IRandom, buf?: NumericArray, index?: number, stride?: number): T;
80
87
  /**
@@ -140,13 +147,13 @@ export interface TypedColor<T> extends IColor, IDeref<Color>, IEqualsDelta<T>, I
140
147
  * color type (usually [0..1] interval). Alpha channel will remain
141
148
  * untouched.
142
149
  *
143
- * @param rnd
150
+ * @param rnd -
144
151
  */
145
152
  randomize(rnd?: IRandom): this;
146
153
  /**
147
154
  * Copies `src` into this color's array.
148
155
  *
149
- * @param src
156
+ * @param src -
150
157
  */
151
158
  set(src: ReadonlyColor): this;
152
159
  /**
package/color-range.d.ts CHANGED
@@ -23,8 +23,8 @@ export declare const COLOR_RANGES: Record<ColorRangePreset, ColorRange>;
23
23
  *
24
24
  * A custom PRNG can be defined via the `rnd` option (default: `Math.random`).
25
25
  *
26
- * @param range
27
- * @param opts
26
+ * @param range -
27
+ * @param opts -
28
28
  */
29
29
  export declare const colorFromRange: (range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<Pick<ColorRangeOpts, "variance" | "eps" | "rnd">> | undefined) => LCH;
30
30
  /**
@@ -32,8 +32,8 @@ export declare const colorFromRange: (range: ColorRange | keyof typeof COLOR_RAN
32
32
  * sequence of random colors based on given range, base color (optional) and
33
33
  * other opts. Use `num` option to limit number of results.
34
34
  *
35
- * @param range
36
- * @param opts
35
+ * @param range -
36
+ * @param opts -
37
37
  */
38
38
  export declare function colorsFromRange(range: ColorRange | keyof typeof COLOR_RANGES, opts?: Partial<ColorRangeOpts>): Generator<LCH, void, unknown>;
39
39
  /**
@@ -61,8 +61,8 @@ export declare function colorsFromRange(range: ColorRange | keyof typeof COLOR_R
61
61
  * )]
62
62
  * ```
63
63
  *
64
- * @param parts
65
- * @param opts
64
+ * @param parts -
65
+ * @param opts -
66
66
  */
67
67
  export declare function colorsFromTheme(parts: (ColorThemePart | ColorThemePartTuple)[], opts?: Partial<Without<ColorRangeOpts, "base">>): Generator<LCH, void, unknown>;
68
68
  //# sourceMappingURL=color-range.d.ts.map
package/color-range.js CHANGED
@@ -116,8 +116,8 @@ const $rnd = (ranges, rnd) => rnd.minmax(...ranges[rnd.int() % ranges.length]);
116
116
  *
117
117
  * A custom PRNG can be defined via the `rnd` option (default: `Math.random`).
118
118
  *
119
- * @param range
120
- * @param opts
119
+ * @param range -
120
+ * @param opts -
121
121
  */
122
122
  export const colorFromRange = (range, opts) => {
123
123
  range = {
@@ -165,8 +165,8 @@ export const colorFromRange = (range, opts) => {
165
165
  * sequence of random colors based on given range, base color (optional) and
166
166
  * other opts. Use `num` option to limit number of results.
167
167
  *
168
- * @param range
169
- * @param opts
168
+ * @param range -
169
+ * @param opts -
170
170
  */
171
171
  export function* colorsFromRange(range, opts = {}) {
172
172
  let num = opts.num != undefined ? opts.num : Infinity;
@@ -241,8 +241,8 @@ const themePartFromString = (part) => ((COLOR_RANGES[part]
241
241
  * )]
242
242
  * ```
243
243
  *
244
- * @param parts
245
- * @param opts
244
+ * @param parts -
245
+ * @param opts -
246
246
  */
247
247
  export function* colorsFromTheme(parts, opts = {}) {
248
248
  let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
package/convert.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare const CONVERSIONS: Partial<Record<ColorMode, Conversions>>;
4
4
  * Registers conversions for given {@link ColorSpec}. Called by
5
5
  * {@link defColor}.
6
6
  *
7
- * @param spec
7
+ * @param spec -
8
8
  *
9
9
  * @internal
10
10
  */
package/convert.js CHANGED
@@ -6,7 +6,7 @@ export const CONVERSIONS = {};
6
6
  * Registers conversions for given {@link ColorSpec}. Called by
7
7
  * {@link defColor}.
8
8
  *
9
- * @param spec
9
+ * @param spec -
10
10
  *
11
11
  * @internal
12
12
  */
@@ -15,8 +15,8 @@ export declare const COSINE_GRADIENTS: Record<CosineGradientPreset, CosGradientS
15
15
  * Computes a single linear RGBA color for given gradient spec and normalized
16
16
  * position `t` (in [0..1] interval).
17
17
  *
18
- * @param spec
19
- * @param t
18
+ * @param spec -
19
+ * @param t -
20
20
  */
21
21
  export declare const cosineColor: (spec: CosGradientSpec, t: number) => Color;
22
22
  /**
@@ -28,9 +28,9 @@ export declare const cosineColor: (spec: CosGradientSpec, t: number) => Color;
28
28
  * For CSS/SVG use cases you could use {@link srgba} as transformation function
29
29
  * to not convert, but reinterpret & wrap raw color values as SRGBA.
30
30
  *
31
- * @param n
32
- * @param spec
33
- * @param tx
31
+ * @param n -
32
+ * @param spec -
33
+ * @param tx -
34
34
  */
35
35
  export declare const cosineGradient: (n: number, spec: CosGradientSpec, tx?: FnU<import("@thi.ng/vectors").Vec, import("@thi.ng/vectors").Vec> | undefined) => Color[];
36
36
  /**
@@ -158,8 +158,8 @@ export const COSINE_GRADIENTS = {
158
158
  * Computes a single linear RGBA color for given gradient spec and normalized
159
159
  * position `t` (in [0..1] interval).
160
160
  *
161
- * @param spec
162
- * @param t
161
+ * @param spec -
162
+ * @param t -
163
163
  */
164
164
  export const cosineColor = (spec, t) => transduce(map(([a, b, c, d]) => clamp01(a + b * Math.cos(TAU * (c * t + d)))), push(),
165
165
  // @ts-ignore
@@ -173,9 +173,9 @@ zip(...spec));
173
173
  * For CSS/SVG use cases you could use {@link srgba} as transformation function
174
174
  * to not convert, but reinterpret & wrap raw color values as SRGBA.
175
175
  *
176
- * @param n
177
- * @param spec
178
- * @param tx
176
+ * @param n -
177
+ * @param spec -
178
+ * @param tx -
179
179
  */
180
180
  export const cosineGradient = (n, spec, tx) => transduce(comp(map(partial(cosineColor, spec)), tx ? map(tx) : noop()), push(), normRange(n - 1));
181
181
  /**
@@ -33,7 +33,7 @@ import { IParsedColor } from "../api.js";
33
33
  * and {@link srgb} for non-linear (gamma encoded) RGB colors (CSS uses sRGB by
34
34
  * default).
35
35
  *
36
- * @param src
36
+ * @param src -
37
37
  */
38
38
  export declare const parseCss: (src: string | IDeref<string>) => IParsedColor;
39
39
  export declare const parseHex: (src: string) => number;
package/css/parse-css.js CHANGED
@@ -43,7 +43,7 @@ import { intArgb32Srgb } from "../int/int-srgb.js";
43
43
  * and {@link srgb} for non-linear (gamma encoded) RGB colors (CSS uses sRGB by
44
44
  * default).
45
45
  *
46
- * @param src
46
+ * @param src -
47
47
  */
48
48
  export const parseCss = (src) => {
49
49
  src = (isString(src) ? src : src.deref()).toLowerCase();
package/defcolor.js CHANGED
@@ -4,6 +4,7 @@ import { isNumber } from "@thi.ng/checks/is-number";
4
4
  import { isString } from "@thi.ng/checks/is-string";
5
5
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
6
6
  import { EPS } from "@thi.ng/math/api";
7
+ import { fract } from "@thi.ng/math/prec";
7
8
  import { vector } from "@thi.ng/strings/vector";
8
9
  import { mapStridedBuffer } from "@thi.ng/vectors/buffer";
9
10
  import { clamp4 } from "@thi.ng/vectors/clamp";
@@ -33,6 +34,7 @@ export const defColor = (spec) => {
33
34
  const minR = set4([], min);
34
35
  const maxR = set4([], max);
35
36
  minR[numChannels - 1] = 1;
37
+ const hueChanID = order.findIndex((id) => !!channels[id].hue);
36
38
  const $Color = class {
37
39
  constructor(buf, offset = 0, stride = 1) {
38
40
  this.offset = offset;
@@ -72,7 +74,9 @@ export const defColor = (spec) => {
72
74
  return set4(this, src);
73
75
  }
74
76
  clamp() {
75
- return clamp4(null, this, min, max);
77
+ hueChanID >= 0 && (this[hueChanID] = fract(this[hueChanID]));
78
+ clamp4(null, this, min, max);
79
+ return this;
76
80
  }
77
81
  eqDelta(o, eps = EPS) {
78
82
  return eqDelta4(this, o, eps);
package/distance.d.ts CHANGED
@@ -4,67 +4,67 @@ import type { ColorDistance } from "./api.js";
4
4
  * Higher order function. Returns {@link ColorDistance} function for given color
5
5
  * channel ID.
6
6
  *
7
- * @param id
7
+ * @param id -
8
8
  */
9
9
  export declare const distChannel: (id: number) => ColorDistance;
10
10
  /**
11
11
  * Computes distance between two HSV colors, i.e. the eucledian distance between
12
12
  * points in a cyclinder.
13
13
  *
14
- * @param a
15
- * @param b
14
+ * @param a -
15
+ * @param b -
16
16
  */
17
17
  export declare const distHsv: ColorDistance;
18
18
  /**
19
19
  * Computes difference in saturation between two HSV colors.
20
20
  *
21
- * @param a
22
- * @param b
21
+ * @param a -
22
+ * @param b -
23
23
  */
24
24
  export declare const distHsvSat: ColorDistance<ReadonlyVec>;
25
25
  /**
26
26
  * Computes difference in brightness between two HSV or two HSL colors.
27
27
  *
28
- * @param a
29
- * @param b
28
+ * @param a -
29
+ * @param b -
30
30
  */
31
31
  export declare const distHsvLuma: ColorDistance<ReadonlyVec>;
32
32
  /**
33
33
  * Computes eucledian distance between two colors. Only the first 3 color
34
34
  * channels will be considered.
35
35
  *
36
- * @param a
37
- * @param b
36
+ * @param a -
37
+ * @param b -
38
38
  */
39
39
  export declare const distEucledian3: ColorDistance;
40
40
  export declare const distEucledian4: ColorDistance;
41
41
  /**
42
42
  * Computes difference in luminance between two RGB colors.
43
43
  *
44
- * @param a
45
- * @param b
44
+ * @param a -
45
+ * @param b -
46
46
  */
47
47
  export declare const distRgbLuma: ColorDistance;
48
48
  export declare const distSrgbLuma: ColorDistance;
49
49
  /**
50
50
  * Computes red difference between two RGB colors.
51
51
  *
52
- * @param a
53
- * @param b
52
+ * @param a -
53
+ * @param b -
54
54
  */
55
55
  export declare const distRgbRed: ColorDistance<ReadonlyVec>;
56
56
  /**
57
57
  * Computes green difference between two RGB colors.
58
58
  *
59
- * @param a
60
- * @param b
59
+ * @param a -
60
+ * @param b -
61
61
  */
62
62
  export declare const distRgbGreen: ColorDistance<ReadonlyVec>;
63
63
  /**
64
64
  * Computes blue difference between two RGB colors.
65
65
  *
66
- * @param a
67
- * @param b
66
+ * @param a -
67
+ * @param b -
68
68
  */
69
69
  export declare const distRgbBlue: ColorDistance<ReadonlyVec>;
70
70
  /**
package/distance.js CHANGED
@@ -10,15 +10,15 @@ const { abs, cos, hypot, sin, sqrt } = Math;
10
10
  * Higher order function. Returns {@link ColorDistance} function for given color
11
11
  * channel ID.
12
12
  *
13
- * @param id
13
+ * @param id -
14
14
  */
15
15
  export const distChannel = (id) => (a, b) => abs(a[id] - b[id]);
16
16
  /**
17
17
  * Computes distance between two HSV colors, i.e. the eucledian distance between
18
18
  * points in a cyclinder.
19
19
  *
20
- * @param a
21
- * @param b
20
+ * @param a -
21
+ * @param b -
22
22
  */
23
23
  export const distHsv = (a, b) => {
24
24
  const aa = cossin(a[0] * TAU, a[1]);
@@ -28,53 +28,53 @@ export const distHsv = (a, b) => {
28
28
  /**
29
29
  * Computes difference in saturation between two HSV colors.
30
30
  *
31
- * @param a
32
- * @param b
31
+ * @param a -
32
+ * @param b -
33
33
  */
34
34
  export const distHsvSat = distChannel(1);
35
35
  /**
36
36
  * Computes difference in brightness between two HSV or two HSL colors.
37
37
  *
38
- * @param a
39
- * @param b
38
+ * @param a -
39
+ * @param b -
40
40
  */
41
41
  export const distHsvLuma = distChannel(2);
42
42
  /**
43
43
  * Computes eucledian distance between two colors. Only the first 3 color
44
44
  * channels will be considered.
45
45
  *
46
- * @param a
47
- * @param b
46
+ * @param a -
47
+ * @param b -
48
48
  */
49
49
  export const distEucledian3 = dist3;
50
50
  export const distEucledian4 = dist4;
51
51
  /**
52
52
  * Computes difference in luminance between two RGB colors.
53
53
  *
54
- * @param a
55
- * @param b
54
+ * @param a -
55
+ * @param b -
56
56
  */
57
57
  export const distRgbLuma = (a, b) => abs(luminanceRgb(a) - luminanceRgb(b));
58
58
  export const distSrgbLuma = (a, b) => abs(luminanceSrgb(a) - luminanceSrgb(b));
59
59
  /**
60
60
  * Computes red difference between two RGB colors.
61
61
  *
62
- * @param a
63
- * @param b
62
+ * @param a -
63
+ * @param b -
64
64
  */
65
65
  export const distRgbRed = distChannel(0);
66
66
  /**
67
67
  * Computes green difference between two RGB colors.
68
68
  *
69
- * @param a
70
- * @param b
69
+ * @param a -
70
+ * @param b -
71
71
  */
72
72
  export const distRgbGreen = distChannel(1);
73
73
  /**
74
74
  * Computes blue difference between two RGB colors.
75
75
  *
76
- * @param a
77
- * @param b
76
+ * @param a -
77
+ * @param b -
78
78
  */
79
79
  export const distRgbBlue = distChannel(1);
80
80
  const H6 = 6 * DEG2RAD;
package/gradients.d.ts CHANGED
@@ -37,7 +37,7 @@ import type { GradientOpts } from "./api/gradients.js";
37
37
  * );
38
38
  * ```
39
39
  *
40
- * @param opts
40
+ * @param opts -
41
41
  */
42
42
  export declare const multiColorGradient: <T extends TypedColor<any>>(opts: GradientOpts<T>) => T[];
43
43
  /**
@@ -48,7 +48,7 @@ export declare const multiColorGradient: <T extends TypedColor<any>>(opts: Gradi
48
48
  * Intended use case for this function: 1D texturemap/tonemap generation, e.g.
49
49
  * for dataviz etc. Also @see {@link cosineGradientBuffer}.
50
50
  *
51
- * @param opts
51
+ * @param opts -
52
52
  * @param buffer - target buffer/array
53
53
  * @param offset - start index (default: 0)
54
54
  * @param cstride - channel stride (default: 1)
package/gradients.js CHANGED
@@ -37,7 +37,7 @@ import { mix as $mix } from "./mix.js";
37
37
  * );
38
38
  * ```
39
39
  *
40
- * @param opts
40
+ * @param opts -
41
41
  */
42
42
  export const multiColorGradient = (opts) => [...gradient(opts)];
43
43
  /**
@@ -48,7 +48,7 @@ export const multiColorGradient = (opts) => [...gradient(opts)];
48
48
  * Intended use case for this function: 1D texturemap/tonemap generation, e.g.
49
49
  * for dataviz etc. Also @see {@link cosineGradientBuffer}.
50
50
  *
51
- * @param opts
51
+ * @param opts -
52
52
  * @param buffer - target buffer/array
53
53
  * @param offset - start index (default: 0)
54
54
  * @param cstride - channel stride (default: 1)