@thi.ng/color 3.2.6 → 4.0.3

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 (189) hide show
  1. package/CHANGELOG.md +162 -230
  2. package/README.md +31 -15
  3. package/{ops/alpha.d.ts → alpha.d.ts} +1 -1
  4. package/{ops/alpha.js → alpha.js} +1 -1
  5. package/{ops/analog.d.ts → analog.d.ts} +3 -3
  6. package/{ops/analog.js → analog.js} +10 -10
  7. package/api/constants.js +18 -73
  8. package/api/gradients.d.ts +1 -1
  9. package/api/ranges.d.ts +2 -2
  10. package/api.d.ts +7 -2
  11. package/{ops/clamp.d.ts → clamp.d.ts} +1 -1
  12. package/{ops/clamp.js → clamp.js} +6 -5
  13. package/{ops/closest-hue.d.ts → closest-hue.d.ts} +1 -1
  14. package/{ops/closest-hue.js → closest-hue.js} +1 -1
  15. package/{ops/color-range.d.ts → color-range.d.ts} +2 -2
  16. package/{ops/color-range.js → color-range.js} +25 -18
  17. package/color.d.ts +1 -1
  18. package/color.js +16 -16
  19. package/convert.d.ts +1 -1
  20. package/convert.js +4 -4
  21. package/{ops/cosine-gradients.d.ts → cosine-gradients.d.ts} +2 -2
  22. package/{ops/cosine-gradients.js → cosine-gradients.js} +13 -5
  23. package/css/css.d.ts +1 -1
  24. package/css/css.js +12 -11
  25. package/css/parse-css.d.ts +1 -1
  26. package/css/parse-css.js +12 -9
  27. package/defcolor.d.ts +1 -1
  28. package/defcolor.js +24 -11
  29. package/{ops/distance.d.ts → distance.d.ts} +2 -2
  30. package/{ops/distance.js → distance.js} +7 -5
  31. package/{ops/gradients.d.ts → gradients.d.ts} +2 -2
  32. package/{ops/gradients.js → gradients.js} +3 -3
  33. package/hcy/hcy-rgb.d.ts +1 -1
  34. package/hcy/hcy-rgb.js +6 -6
  35. package/hcy/hcy.d.ts +1 -1
  36. package/hcy/hcy.js +4 -2
  37. package/hsi/hsi-rgb.d.ts +1 -1
  38. package/hsi/hsi-rgb.js +2 -2
  39. package/hsi/hsi.d.ts +1 -1
  40. package/hsi/hsi.js +4 -2
  41. package/hsl/hsl-css.d.ts +1 -1
  42. package/hsl/hsl-css.js +5 -4
  43. package/hsl/hsl-hsv.d.ts +1 -1
  44. package/hsl/hsl-hsv.js +1 -1
  45. package/hsl/hsl-rgb.d.ts +1 -1
  46. package/hsl/hsl-rgb.js +5 -5
  47. package/hsl/hsl.d.ts +1 -1
  48. package/hsl/hsl.js +5 -3
  49. package/hsv/hsv-css.d.ts +1 -1
  50. package/hsv/hsv-css.js +2 -2
  51. package/hsv/hsv-hsl.d.ts +1 -1
  52. package/hsv/hsv-hsl.js +1 -1
  53. package/hsv/hsv-rgb.d.ts +1 -1
  54. package/hsv/hsv-rgb.js +3 -3
  55. package/hsv/hsv.d.ts +1 -1
  56. package/hsv/hsv.js +5 -3
  57. package/index.d.ts +87 -87
  58. package/index.js +87 -87
  59. package/int/int-css.js +2 -2
  60. package/int/int-int.js +1 -1
  61. package/int/int-rgb.d.ts +1 -1
  62. package/int/int-rgb.js +2 -2
  63. package/int/int-srgb.d.ts +1 -1
  64. package/int/int-srgb.js +2 -2
  65. package/int/int.d.ts +24 -11
  66. package/int/int.js +59 -19
  67. package/internal/ensure.d.ts +5 -0
  68. package/internal/{ensure-args.js → ensure.js} +4 -1
  69. package/internal/matrix-ops.d.ts +8 -5
  70. package/internal/matrix-ops.js +12 -8
  71. package/internal/scale.d.ts +3 -0
  72. package/internal/scale.js +2 -0
  73. package/{ops/invert.d.ts → invert.d.ts} +1 -1
  74. package/{ops/invert.js → invert.js} +3 -2
  75. package/is-black.d.ts +3 -0
  76. package/{ops/is-black.js → is-black.js} +5 -6
  77. package/is-gray.d.ts +3 -0
  78. package/{ops/is-gray.js → is-gray.js} +6 -7
  79. package/is-white.d.ts +3 -0
  80. package/{ops/is-white.js → is-white.js} +5 -6
  81. package/lab/lab-css.d.ts +1 -1
  82. package/lab/lab-css.js +4 -4
  83. package/lab/lab-lab.d.ts +1 -1
  84. package/lab/lab-lab.js +3 -3
  85. package/lab/lab-lch.d.ts +1 -1
  86. package/lab/lab-lch.js +6 -5
  87. package/lab/lab-rgb.d.ts +1 -1
  88. package/lab/lab-rgb.js +2 -2
  89. package/lab/lab-xyz.d.ts +1 -1
  90. package/lab/lab-xyz.js +4 -4
  91. package/lab/lab50.d.ts +1 -1
  92. package/lab/lab50.js +8 -6
  93. package/lab/lab65.d.ts +1 -1
  94. package/lab/lab65.js +8 -6
  95. package/lch/lch-css.d.ts +1 -1
  96. package/lch/lch-css.js +5 -4
  97. package/lch/lch.d.ts +1 -1
  98. package/lch/lch.js +8 -6
  99. package/{ops/linear.d.ts → linear.d.ts} +0 -0
  100. package/{ops/linear.js → linear.js} +0 -0
  101. package/{ops/luminance-rgb.d.ts → luminance-rgb.d.ts} +1 -1
  102. package/{ops/luminance-rgb.js → luminance-rgb.js} +2 -2
  103. package/{ops/luminance.d.ts → luminance.d.ts} +2 -3
  104. package/{ops/luminance.js → luminance.js} +5 -10
  105. package/{ops/mix.d.ts → mix.d.ts} +2 -2
  106. package/{ops/mix.js → mix.js} +7 -6
  107. package/oklab/oklab-rgb.d.ts +1 -1
  108. package/oklab/oklab-rgb.js +4 -11
  109. package/oklab/oklab-xyz.d.ts +1 -1
  110. package/oklab/oklab-xyz.js +9 -21
  111. package/oklab/oklab.d.ts +1 -1
  112. package/oklab/oklab.js +8 -6
  113. package/package.json +323 -52
  114. package/rgb/hue-rgb.d.ts +1 -1
  115. package/rgb/hue-rgb.js +3 -2
  116. package/rgb/kelvin-rgba.d.ts +1 -1
  117. package/rgb/kelvin-rgba.js +3 -3
  118. package/rgb/rgb-css.d.ts +1 -1
  119. package/rgb/rgb-css.js +2 -2
  120. package/rgb/rgb-hcv.d.ts +1 -1
  121. package/rgb/rgb-hcv.js +4 -3
  122. package/rgb/rgb-hcy.d.ts +1 -1
  123. package/rgb/rgb-hcy.js +4 -4
  124. package/rgb/rgb-hsi.d.ts +1 -1
  125. package/rgb/rgb-hsi.js +4 -3
  126. package/rgb/rgb-hsl.d.ts +1 -1
  127. package/rgb/rgb-hsl.js +2 -2
  128. package/rgb/rgb-hsv.d.ts +1 -1
  129. package/rgb/rgb-hsv.js +2 -2
  130. package/rgb/rgb-lab.d.ts +1 -1
  131. package/rgb/rgb-lab.js +2 -2
  132. package/rgb/rgb-oklab.d.ts +1 -1
  133. package/rgb/rgb-oklab.js +6 -13
  134. package/rgb/rgb-srgb.d.ts +1 -1
  135. package/rgb/rgb-srgb.js +5 -5
  136. package/rgb/rgb-xyz.d.ts +1 -1
  137. package/rgb/rgb-xyz.js +4 -4
  138. package/rgb/rgb-ycc.d.ts +1 -1
  139. package/rgb/rgb-ycc.js +5 -4
  140. package/rgb/rgb.d.ts +1 -1
  141. package/rgb/rgb.js +15 -14
  142. package/{ops/sort.d.ts → sort.d.ts} +16 -5
  143. package/{ops/sort.js → sort.js} +21 -7
  144. package/srgb/srgb-css.d.ts +1 -1
  145. package/srgb/srgb-css.js +8 -8
  146. package/srgb/srgb-int.d.ts +1 -1
  147. package/srgb/srgb-int.js +4 -4
  148. package/srgb/srgb-rgb.d.ts +1 -1
  149. package/srgb/srgb-rgb.js +5 -5
  150. package/srgb/srgb.d.ts +1 -1
  151. package/srgb/srgb.js +9 -7
  152. package/{ops/swatches.d.ts → swatches.d.ts} +1 -1
  153. package/{ops/swatches.js → swatches.js} +0 -0
  154. package/{ops/transform.d.ts → transform.d.ts} +1 -1
  155. package/{ops/transform.js → transform.js} +5 -5
  156. package/xyy/xyy-xyz.d.ts +1 -1
  157. package/xyy/xyy-xyz.js +4 -4
  158. package/xyy/xyy.d.ts +1 -1
  159. package/xyy/xyy.js +6 -3
  160. package/xyz/wavelength-xyz.d.ts +1 -1
  161. package/xyz/wavelength-xyz.js +2 -2
  162. package/xyz/xyz-lab.d.ts +1 -1
  163. package/xyz/xyz-lab.js +5 -4
  164. package/xyz/xyz-oklab.d.ts +1 -1
  165. package/xyz/xyz-oklab.js +4 -4
  166. package/xyz/xyz-rgb.d.ts +1 -1
  167. package/xyz/xyz-rgb.js +3 -3
  168. package/xyz/xyz-xyy.d.ts +1 -1
  169. package/xyz/xyz-xyy.js +4 -4
  170. package/xyz/xyz-xyz.d.ts +1 -1
  171. package/xyz/xyz-xyz.js +4 -4
  172. package/xyz/xyz50.d.ts +1 -1
  173. package/xyz/xyz50.js +10 -8
  174. package/xyz/xyz65.d.ts +1 -1
  175. package/xyz/xyz65.js +10 -8
  176. package/ycc/ycc-rgb.d.ts +1 -1
  177. package/ycc/ycc-rgb.js +4 -4
  178. package/ycc/ycc.d.ts +1 -1
  179. package/ycc/ycc.js +4 -2
  180. package/internal/ensure-alpha.d.ts +0 -2
  181. package/internal/ensure-alpha.js +0 -2
  182. package/internal/ensure-args.d.ts +0 -3
  183. package/lib/index.js +0 -2236
  184. package/lib/index.js.map +0 -1
  185. package/lib/index.umd.js +0 -1
  186. package/lib/index.umd.js.map +0 -1
  187. package/ops/is-black.d.ts +0 -3
  188. package/ops/is-gray.d.ts +0 -3
  189. package/ops/is-white.d.ts +0 -3
package/README.md CHANGED
@@ -23,6 +23,7 @@ For the Clojure version, please visit: [thi.ng/color-clj](https://thi.ng/color-c
23
23
  - [Cosine gradients](#cosine-gradients)
24
24
  - [RGB color transformations](#rgb-color-transformations)
25
25
  - [Status](#status)
26
+ - [Support packages](#support-packages)
26
27
  - [Related packages](#related-packages)
27
28
  - [Installation](#installation)
28
29
  - [Dependencies](#dependencies)
@@ -138,9 +139,9 @@ css(rgb(labD50("#ff0")))
138
139
  ```
139
140
 
140
141
  Additionally, colors can be created from black body temperatures
141
- ([`kelvinRgb()`](https://github.com/thi-ng/umbrella/blob/develop/packages/color/src/rgb/kelvin-rgba.ts))
142
+ ([`kelvinRgb()`](https://docs.thi.ng/umbrella/color/modules.html#kelvinRgb))
142
143
  or wavelengths
143
- ([`wavelengthXyz()`](https://github.com/thi-ng/umbrella/blob/develop/packages/color/src/xyz/wavelength-xyz.ts)).
144
+ ([`wavelengthXyz()`](https://docs.thi.ng/umbrella/color/modules.html#wavelengthXyz)).
144
145
 
145
146
  ![kelvinRgb() result swatches](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/color/blackbody.svg)
146
147
 
@@ -568,6 +569,10 @@ concatenation (see `concat()`) for more efficient application.
568
569
 
569
570
  [Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Bcolor%5D+in%3Atitle)
570
571
 
572
+ ### Support packages
573
+
574
+ - [@thi.ng/color-palettes](https://github.com/thi-ng/umbrella/tree/develop/packages/color-palettes) - Collection of 100 image based color palettes
575
+
571
576
  ### Related packages
572
577
 
573
578
  - [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel) - Typedarray integer & float pixel buffers w/ customizable formats, blitting, dithering, convolution
@@ -579,15 +584,24 @@ concatenation (see `concat()`) for more efficient application.
579
584
  yarn add @thi.ng/color
580
585
  ```
581
586
 
587
+ ES module import:
588
+
582
589
  ```html
583
- // ES module
584
- <script type="module" src="https://unpkg.com/@thi.ng/color?module" crossorigin></script>
590
+ <script type="module" src="https://cdn.skypack.dev/@thi.ng/color"></script>
591
+ ```
592
+
593
+ [Skypack documentation](https://docs.skypack.dev/)
594
+
595
+ For Node.js REPL:
596
+
597
+ ```text
598
+ # with flag only for < v16
599
+ node --experimental-repl-await
585
600
 
586
- // UMD
587
- <script src="https://unpkg.com/@thi.ng/color/lib/index.umd.js" crossorigin></script>
601
+ > const color = await import("@thi.ng/color");
588
602
  ```
589
603
 
590
- Package sizes (gzipped, pre-treeshake): ESM: 13.74 KB / CJS: 14.41 KB / UMD: 13.48 KB
604
+ Package sizes (gzipped, pre-treeshake): ESM: 14.19 KB
591
605
 
592
606
  ## Dependencies
593
607
 
@@ -613,14 +627,16 @@ directory are using this package.
613
627
 
614
628
  A selection:
615
629
 
616
- | Screenshot | Description | Live demo | Source |
617
- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------- |
618
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/color-themes.png" width="240"/> | Probabilistic color theme generator | [Demo](https://demo.thi.ng/umbrella/color-themes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/color-themes) |
619
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-heatmap.png" width="240"/> | Heatmap visualization of this mono-repo's commits | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/commit-heatmap) |
620
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/dominant-colors.png" width="240"/> | Color palette generation via dominant color extraction from uploaded images | [Demo](https://demo.thi.ng/umbrella/dominant-colors/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/dominant-colors) |
621
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/grid-iterators.png" width="240"/> | Visualization of different grid iterator strategies | [Demo](https://demo.thi.ng/umbrella/grid-iterators/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/grid-iterators) |
622
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-sorting.png" width="240"/> | Interactive pixel sorting tool using thi.ng/color & thi.ng/pixel | [Demo](https://demo.thi.ng/umbrella/pixel-sorting/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-sorting) |
623
- | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-workers.jpg" width="240"/> | Fork-join worker-based raymarch renderer | [Demo](https://demo.thi.ng/umbrella/shader-ast-workers/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-workers) |
630
+ | Screenshot | Description | Live demo | Source |
631
+ |:-------------------------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------|:---------------------------------------------------------|:--------------------------------------------------------------------------------------|
632
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/color-themes.png" width="240"/> | Probabilistic color theme generator | [Demo](https://demo.thi.ng/umbrella/color-themes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/color-themes) |
633
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-heatmap.png" width="240"/> | Heatmap visualization of this mono-repo's commits | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/commit-heatmap) |
634
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/dominant-colors.png" width="240"/> | Color palette generation via dominant color extraction from uploaded images | [Demo](https://demo.thi.ng/umbrella/dominant-colors/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/dominant-colors) |
635
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/grid-iterators.png" width="240"/> | Visualization of different grid iterator strategies | [Demo](https://demo.thi.ng/umbrella/grid-iterators/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/grid-iterators) |
636
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/hdom-canvas/hdom-canvas-shapes-results.png" width="240"/> | Various hdom-canvas shape drawing examples & SVG conversion / export | [Demo](https://demo.thi.ng/umbrella/hdom-canvas-shapes/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/hdom-canvas-shapes) |
637
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-indexed.jpg" width="240"/> | Image dithering and remapping using indexed palettes | [Demo](https://demo.thi.ng/umbrella/pixel-indexed/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-indexed) |
638
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/pixel-sorting.png" width="240"/> | Interactive pixel sorting tool using thi.ng/color & thi.ng/pixel | [Demo](https://demo.thi.ng/umbrella/pixel-sorting/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/pixel-sorting) |
639
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-workers.jpg" width="240"/> | Fork-join worker-based raymarch renderer | [Demo](https://demo.thi.ng/umbrella/shader-ast-workers/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-workers) |
624
640
 
625
641
  ## API
626
642
 
@@ -1,4 +1,4 @@
1
- import type { Color, ReadonlyColor } from "../api";
1
+ import type { Color, ReadonlyColor } from "./api.js";
2
2
  export declare const alpha: (src: ReadonlyColor) => number;
3
3
  export declare const setAlpha: (out: Color | null, src: ReadonlyColor, alpha: number) => import("@thi.ng/vectors").Vec;
4
4
  //# sourceMappingURL=alpha.d.ts.map
@@ -1,3 +1,3 @@
1
- import { setC4 } from "@thi.ng/vectors";
1
+ import { setC4 } from "@thi.ng/vectors/setc";
2
2
  export const alpha = (src) => src[3] !== undefined ? src[3] : 1;
3
3
  export const setAlpha = (out, src, alpha) => setC4(out || src, src[0], src[1], src[2], alpha);
@@ -1,13 +1,13 @@
1
1
  import type { Fn3, Fn4, FnU3 } from "@thi.ng/api";
2
- import { IRandom } from "@thi.ng/random";
3
- import type { Color, ReadonlyColor, TypedColor } from "../api";
2
+ import type { IRandom } from "@thi.ng/random";
3
+ import type { Color, ReadonlyColor, TypedColor } from "./api.js";
4
4
  export declare const defAnalog: FnU3<Fn3<number, number, IRandom, number>, Fn4<Color | null, TypedColor<any>, number, IRandom | undefined, Color>>;
5
5
  /**
6
6
  * Returns a random analog color based on given `src` color and variance
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").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/api").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
@@ -1,8 +1,9 @@
1
- import { DEFAULT, defmulti } from "@thi.ng/defmulti";
2
- import { clamp01, fract } from "@thi.ng/math";
3
- import { SYSTEM } from "@thi.ng/random";
4
- import { setC4 } from "@thi.ng/vectors";
5
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { clamp01 } from "@thi.ng/math/interval";
3
+ import { fract } from "@thi.ng/math/prec";
4
+ import { SYSTEM } from "@thi.ng/random/system";
5
+ import { setC4 } from "@thi.ng/vectors/setc";
6
+ import { __ensureAlpha } from "./internal/ensure.js";
6
7
  /** @internal */
7
8
  const analogU = (x, delta, rnd) => delta !== 0 ? x + rnd.norm(delta) : x;
8
9
  /** @internal */
@@ -12,8 +13,8 @@ const analogH = (x, delta, rnd) => analogN(x, delta, rnd, fract);
12
13
  /** @internal */
13
14
  const analogA = (a, delta, rnd) => delta !== 0
14
15
  ? clamp01((a !== undefined ? a : 1) + rnd.norm(delta))
15
- : ensureAlpha(a);
16
- export const defAnalog = (x, y, z) => (out, src, delta, rnd = SYSTEM) => setC4(out || src, x(src[0], delta, rnd), y(src[1], delta, rnd), z(src[2], delta, rnd), ensureAlpha(src[3]));
16
+ : __ensureAlpha(a);
17
+ export const defAnalog = (x, y, z) => (out, src, delta, rnd = SYSTEM) => setC4(out || src, x(src[0], delta, rnd), y(src[1], delta, rnd), z(src[2], delta, rnd), __ensureAlpha(src[3]));
17
18
  /** @internal */
18
19
  const analogHNN = defAnalog(analogH, analogN, analogN);
19
20
  /** @internal */
@@ -25,9 +26,7 @@ const analogNUU = defAnalog(analogN, analogU, analogU);
25
26
  * `delta`. Each channel will be randomized by +/- `delta`, optionally using
26
27
  * provided {@link @thi.ng/random#IRandom} PRNG.
27
28
  */
28
- export const analog = defmulti((_, src) => src.mode);
29
- analog.add(DEFAULT, analogNNN);
30
- analog.addAll({
29
+ export const analog = defmulti((_, src) => src.mode, {}, {
31
30
  hcy: analogHNN,
32
31
  hsi: analogHNN,
33
32
  hsl: analogHNN,
@@ -36,6 +35,7 @@ analog.addAll({
36
35
  lab65: analogNUU,
37
36
  lch: defAnalog(analogN, analogN, analogH),
38
37
  ycc: analogNUU,
38
+ [DEFAULT]: analogNNN,
39
39
  });
40
40
  /**
41
41
  * Similar to {@link analogRGB}. Returns an analog color based on given HSVA
package/api/constants.js CHANGED
@@ -1,4 +1,5 @@
1
- import { float, percent } from "@thi.ng/strings";
1
+ import { float } from "@thi.ng/strings/float";
2
+ import { percent } from "@thi.ng/strings/percent";
2
3
  /**
3
4
  * RGB black
4
5
  */
@@ -63,15 +64,8 @@ export const RGB_LUMINANCE_REC2020 = [0.2627, 0.678, 0.0593];
63
64
  * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
64
65
  */
65
66
  export const RGB_XYZ_D50 = [
66
- 0.4360747,
67
- 0.2225045,
68
- 0.0139322,
69
- 0.3850649,
70
- 0.7168786,
71
- 0.0971045,
72
- 0.1430804,
73
- 0.0606169,
74
- 0.7141733,
67
+ 0.4360747, 0.2225045, 0.0139322, 0.3850649, 0.7168786, 0.0971045, 0.1430804,
68
+ 0.0606169, 0.7141733,
75
69
  ];
76
70
  /**
77
71
  * XYZ D50 to sRGB conversion matrix
@@ -81,15 +75,8 @@ export const RGB_XYZ_D50 = [
81
75
  * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
82
76
  */
83
77
  export const XYZ_RGB_D50 = [
84
- 3.1338561,
85
- -0.9787684,
86
- 0.0719453,
87
- -1.6168667,
88
- 1.9161415,
89
- -0.2289914,
90
- -0.4906146,
91
- 0.033454,
92
- 1.4052427,
78
+ 3.1338561, -0.9787684, 0.0719453, -1.6168667, 1.9161415, -0.2289914,
79
+ -0.4906146, 0.033454, 1.4052427,
93
80
  ];
94
81
  /**
95
82
  * sRGB to XYZ D65 conversion matrix
@@ -99,15 +86,8 @@ export const XYZ_RGB_D50 = [
99
86
  * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
100
87
  */
101
88
  export const RGB_XYZ_D65 = [
102
- 0.4124564,
103
- 0.2126729,
104
- 0.0193339,
105
- 0.3575761,
106
- 0.7151522,
107
- 0.119192,
108
- 0.1804375,
109
- 0.072175,
110
- 0.9503041,
89
+ 0.4124564, 0.2126729, 0.0193339, 0.3575761, 0.7151522, 0.119192, 0.1804375,
90
+ 0.072175, 0.9503041,
111
91
  ];
112
92
  /**
113
93
  * XYZ D65 to sRGB conversion matrix
@@ -117,15 +97,8 @@ export const RGB_XYZ_D65 = [
117
97
  * http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
118
98
  */
119
99
  export const XYZ_RGB_D65 = [
120
- 3.2404542,
121
- -0.969266,
122
- 0.0556434,
123
- -1.5371385,
124
- 1.8760108,
125
- -0.2040259,
126
- -0.4985314,
127
- 0.041556,
128
- 1.0572252,
100
+ 3.2404542, -0.969266, 0.0556434, -1.5371385, 1.8760108, -0.2040259,
101
+ -0.4985314, 0.041556, 1.0572252,
129
102
  ];
130
103
  /**
131
104
  * D50 -> D65 chromatic adaptation matrix. Inverse of {@link BRADFORD_D65_D50}.
@@ -135,15 +108,8 @@ export const XYZ_RGB_D65 = [
135
108
  * http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
136
109
  */
137
110
  export const BRADFORD_D50_D65 = [
138
- 0.9555766,
139
- -0.0282895,
140
- 0.0122982,
141
- -0.0230393,
142
- 1.0099416,
143
- -0.020483,
144
- 0.0631636,
145
- 0.0210077,
146
- 1.3299098,
111
+ 0.9555766, -0.0282895, 0.0122982, -0.0230393, 1.0099416, -0.020483,
112
+ 0.0631636, 0.0210077, 1.3299098,
147
113
  ];
148
114
  /**
149
115
  * D65 -> D50 chromatic adaptation matrix. Inverse of {@link BRADFORD_D50_D65}.
@@ -153,15 +119,8 @@ export const BRADFORD_D50_D65 = [
153
119
  * http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
154
120
  */
155
121
  export const BRADFORD_D65_D50 = [
156
- 1.0478112,
157
- 0.0295424,
158
- -0.0092345,
159
- 0.0228866,
160
- 0.9904844,
161
- 0.0150436,
162
- -0.050127,
163
- -0.0170491,
164
- 0.7521316,
122
+ 1.0478112, 0.0295424, -0.0092345, 0.0228866, 0.9904844, 0.0150436,
123
+ -0.050127, -0.0170491, 0.7521316,
165
124
  ];
166
125
  /**
167
126
  * CIE Standard Illuminant D50
@@ -175,26 +134,12 @@ export const D50 = [0.96422, 1, 0.82521];
175
134
  */
176
135
  export const D65 = [0.95047, 1, 1.08883];
177
136
  export const OKLAB_M1 = [
178
- 0.8189330101,
179
- 0.0329845436,
180
- 0.0482003018,
181
- 0.3618667424,
182
- 0.9293118715,
183
- 0.2643662691,
184
- -0.1288597137,
185
- 0.0361456387,
186
- 0.633851707,
137
+ 0.8189330101, 0.0329845436, 0.0482003018, 0.3618667424, 0.9293118715,
138
+ 0.2643662691, -0.1288597137, 0.0361456387, 0.633851707,
187
139
  ];
188
140
  export const OKLAB_M2 = [
189
- 0.2104542553,
190
- 1.9779984951,
191
- 0.0259040371,
192
- 0.793617785,
193
- -2.428592205,
194
- 0.7827717662,
195
- -0.0040720468,
196
- 0.4505937099,
197
- -0.808675766,
141
+ 0.2104542553, 1.9779984951, 0.0259040371, 0.793617785, -2.428592205,
142
+ 0.7827717662, -0.0040720468, 0.4505937099, -0.808675766,
198
143
  ];
199
144
  /**
200
145
  * Float value formatter
@@ -1,5 +1,5 @@
1
1
  import type { FnN, FnU, Tuple } from "@thi.ng/api";
2
- import type { Color, ColorMixFn, ReadonlyColor } from "../api";
2
+ import type { Color, ColorMixFn, ReadonlyColor } from "../api.js";
3
3
  export declare type CosineGradientPreset = "blue-cyan" | "blue-magenta-orange" | "blue-white-red" | "cyan-magenta" | "green-blue-orange" | "green-cyan" | "green-magenta" | "green-red" | "heat1" | "magenta-green" | "orange-blue" | "orange-magenta-blue" | "purple-orange-cyan" | "rainbow1" | "rainbow2" | "rainbow3" | "rainbow4" | "red-blue" | "yellow-green-blue" | "yellow-magenta-cyan" | "yellow-purple-magenta" | "yellow-red";
4
4
  export declare type CosineCoeffs = Tuple<number, 4>;
5
5
  export declare type CosGradientSpec = Tuple<CosineCoeffs, 4>;
package/api/ranges.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Range } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { ReadonlyColor } from "../api";
4
- import type { CSSColorName } from "./names";
3
+ import type { ReadonlyColor } from "../api.js";
4
+ import type { CSSColorName } from "./names.js";
5
5
  export declare type ColorRangePreset = "light" | "dark" | "bright" | "weak" | "neutral" | "fresh" | "soft" | "hard" | "warm" | "cool" | "intense";
6
6
  export interface ColorRange {
7
7
  /**
package/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { FnU2, IDeref, NumericArray, Range, Tuple } from "@thi.ng/api";
1
+ import type { FnU2, IDeref, IEqualsDelta, NumericArray, Range, Tuple } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
3
  import type { IVector, ReadonlyVec, Vec } from "@thi.ng/vectors";
4
4
  export declare type Color = Vec;
@@ -52,6 +52,11 @@ export interface ColorSpec<M extends ColorMode, K extends string> {
52
52
  from: Partial<Record<ColorMode, ColorOp | Tuple<ColorOp, 2 | 3 | 4>>> & {
53
53
  rgb: ColorOp;
54
54
  };
55
+ /**
56
+ * Mandatory conversion to RGB mode. Used as fallback solution if no other
57
+ * direct conversion path is defined (e.g. for CSS formatting).
58
+ */
59
+ toRgb: ColorOp | Tuple<ColorOp, 2 | 3 | 4>;
55
60
  }
56
61
  export declare type Conversions = Partial<Record<ColorMode, ColorOp>> & {
57
62
  rgb: ColorOp;
@@ -98,7 +103,7 @@ export interface ColorFactory<T extends TypedColor<any>> {
98
103
  export interface TypedColorConstructor<T extends TypedColor<any>> {
99
104
  new (buf?: NumericArray, offset?: number, stride?: number): T;
100
105
  }
101
- export interface TypedColor<T> extends IColor, IDeref<Color>, IVector<T> {
106
+ export interface TypedColor<T> extends IColor, IDeref<Color>, IEqualsDelta<T>, IVector<T>, Iterable<number> {
102
107
  /**
103
108
  * Backing array / memory
104
109
  */
@@ -1,4 +1,4 @@
1
- import type { Color, ReadonlyColor } from "../api";
1
+ import type { Color, ReadonlyColor } from "./api.js";
2
2
  /**
3
3
  * Clamps all color channels to [0,1] interval and calls `ensureAlpha`
4
4
  * to ensure alpha channel is defined (if missing sets it to `alpha`,
@@ -1,6 +1,7 @@
1
- import { clamp01, fract } from "@thi.ng/math";
2
- import { setC4 } from "@thi.ng/vectors";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { clamp01 } from "@thi.ng/math/interval";
2
+ import { fract } from "@thi.ng/math/prec";
3
+ import { setC4 } from "@thi.ng/vectors/setc";
4
+ import { __ensureAlpha } from "./internal/ensure.js";
4
5
  /**
5
6
  * Clamps all color channels to [0,1] interval and calls `ensureAlpha`
6
7
  * to ensure alpha channel is defined (if missing sets it to `alpha`,
@@ -10,7 +11,7 @@ import { ensureAlpha } from "../internal/ensure-alpha";
10
11
  * @param src - source color
11
12
  * @param alpha - alpha value
12
13
  */
13
- export const clamp = (out, src, alpha = 1) => setC4(out || src, clamp01(src[0]), clamp01(src[1]), clamp01(src[2]), ensureAlpha(src[3], alpha));
14
+ export const clamp = (out, src, alpha = 1) => setC4(out || src, clamp01(src[0]), clamp01(src[1]), clamp01(src[2]), __ensureAlpha(src[3], alpha));
14
15
  /**
15
16
  * Similar to {@link clamp}, but calls `ensureHue` to fold (instead of
16
17
  * clamping) the hue into [0,1] interval.
@@ -19,4 +20,4 @@ export const clamp = (out, src, alpha = 1) => setC4(out || src, clamp01(src[0]),
19
20
  * @param src - source color
20
21
  * @param alpha - alpha value
21
22
  */
22
- export const clampH = (out, src, alpha = 1) => setC4(out || src, fract(src[0]), clamp01(src[1]), clamp01(src[2]), ensureAlpha(src[3], alpha));
23
+ export const clampH = (out, src, alpha = 1) => setC4(out || src, fract(src[0]), clamp01(src[1]), clamp01(src[2]), __ensureAlpha(src[3], alpha));
@@ -1,4 +1,4 @@
1
- import type { Hue } from "../api";
1
+ import type { Hue } from "./api.js";
2
2
  /**
3
3
  * Returns the {@link Hue} constant of the closest of 12 defined hues.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { fract } from "@thi.ng/math";
1
+ import { fract } from "@thi.ng/math/prec";
2
2
  /**
3
3
  * Returns the {@link Hue} constant of the closest of 12 defined hues.
4
4
  *
@@ -1,6 +1,6 @@
1
1
  import type { Without } from "@thi.ng/api";
2
- import type { ColorRange, ColorRangeOpts, ColorRangePreset, ColorThemePart, ColorThemePartTuple } from "../api/ranges";
3
- import { LCH } from "../lch/lch";
2
+ import type { ColorRange, ColorRangeOpts, ColorRangePreset, ColorThemePart, ColorThemePartTuple } from "./api/ranges.js";
3
+ import { LCH } from "./lch/lch.js";
4
4
  /**
5
5
  * Preset {@link ColorRange}s for use with {@link colorsFromRange},
6
6
  * {@link colorsFromTheme} etc.
@@ -1,15 +1,19 @@
1
- import { peek } from "@thi.ng/arrays";
2
- import { isArray, isNumber, isString } from "@thi.ng/checks";
3
- import { illegalArgs } from "@thi.ng/errors";
4
- import { fract } from "@thi.ng/math";
5
- import { coin, SYSTEM, weightedRandom } from "@thi.ng/random";
6
- import { parseCss } from "../css/parse-css";
7
- import { ensureAlpha } from "../internal/ensure-alpha";
8
- import { lch } from "../lch/lch";
9
- import { analog } from "./analog";
10
- import { isBlack } from "./is-black";
11
- import { isGray } from "./is-gray";
12
- import { isWhite } from "./is-white";
1
+ import { peek } from "@thi.ng/arrays/peek";
2
+ import { isArray } from "@thi.ng/checks/is-array";
3
+ import { isNumber } from "@thi.ng/checks/is-number";
4
+ import { isString } from "@thi.ng/checks/is-string";
5
+ import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
6
+ import { fract } from "@thi.ng/math/prec";
7
+ import { coin } from "@thi.ng/random/coin";
8
+ import { SYSTEM } from "@thi.ng/random/system";
9
+ import { weightedRandom } from "@thi.ng/random/weighted-random";
10
+ import { parseCss } from "./css/parse-css.js";
11
+ import { __ensureAlpha } from "./internal/ensure.js";
12
+ import { lch } from "./lch/lch.js";
13
+ import { analog } from "./analog.js";
14
+ import { isBlack } from "./is-black.js";
15
+ import { isGray } from "./is-gray.js";
16
+ import { isWhite } from "./is-white.js";
13
17
  /**
14
18
  * Preset {@link ColorRange}s for use with {@link colorsFromRange},
15
19
  * {@link colorsFromTheme} etc.
@@ -116,8 +120,11 @@ const $rnd = (ranges, rnd) => rnd.minmax(...ranges[rnd.int() % ranges.length]);
116
120
  * @param opts
117
121
  */
118
122
  export const colorFromRange = (range, opts) => {
119
- range = Object.assign(Object.assign({}, DEFAULT_RANGE), (isString(range) ? COLOR_RANGES[range] : range));
120
- const { base, variance, rnd, eps } = Object.assign(Object.assign({}, DEFAULT_OPTS), opts);
123
+ range = {
124
+ ...DEFAULT_RANGE,
125
+ ...(isString(range) ? COLOR_RANGES[range] : range),
126
+ };
127
+ const { base, variance, rnd, eps } = { ...DEFAULT_OPTS, ...opts };
121
128
  let h;
122
129
  let c;
123
130
  let l;
@@ -125,7 +132,7 @@ export const colorFromRange = (range, opts) => {
125
132
  if (base) {
126
133
  const col = lch(base);
127
134
  h = col[2];
128
- a = ensureAlpha(col[3]);
135
+ a = __ensureAlpha(col[3]);
129
136
  if (isBlack(col, eps)) {
130
137
  c = 0;
131
138
  l = $rnd(range.b, rnd);
@@ -176,13 +183,13 @@ const compileThemePart = (part, opts) => {
176
183
  spec = themePartFromString(part);
177
184
  }
178
185
  else {
179
- spec = Object.assign({}, part);
186
+ spec = { ...part };
180
187
  spec.weight == null && (spec.weight = 1);
181
188
  }
182
189
  isString(spec.range) && (spec.range = COLOR_RANGES[spec.range]);
183
190
  isString(spec.base) && (spec.base = lch(parseCss(spec.base)));
184
191
  if (spec.base !== undefined) {
185
- opts = Object.assign(Object.assign({}, opts), { base: spec.base });
192
+ opts = { ...opts, base: spec.base };
186
193
  }
187
194
  return { spec, opts };
188
195
  };
@@ -238,7 +245,7 @@ const themePartFromString = (part) => ((COLOR_RANGES[part]
238
245
  * @param opts
239
246
  */
240
247
  export function* colorsFromTheme(parts, opts = {}) {
241
- let { num, variance, rnd } = Object.assign(Object.assign({}, DEFAULT_OPTS), opts);
248
+ let { num, variance, rnd } = { ...DEFAULT_OPTS, ...opts };
242
249
  const theme = parts.map((p) => compileThemePart(p, opts));
243
250
  const choice = weightedRandom(theme, theme.map((x) => x.spec.weight), rnd);
244
251
  while (--num >= 0) {
package/color.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Color, ColorMode, ParsedColor, TypedColor } from "./api";
1
+ import type { Color, ColorMode, ParsedColor, TypedColor } from "./api.js";
2
2
  export declare function color(src: ParsedColor, buf?: Color, idx?: number, stride?: number): TypedColor<any>;
3
3
  export declare function color(mode: ColorMode, buf: Color, idx?: number, stride?: number): TypedColor<any>;
4
4
  //# sourceMappingURL=color.d.ts.map
package/color.js CHANGED
@@ -1,19 +1,19 @@
1
- import { isString } from "@thi.ng/checks";
2
- import { hcy } from "./hcy/hcy";
3
- import { hsi } from "./hsi/hsi";
4
- import { hsl } from "./hsl/hsl";
5
- import { hsv } from "./hsv/hsv";
6
- import { argb32, abgr32 } from "./int/int";
7
- import { labD50 } from "./lab/lab50";
8
- import { labD65 } from "./lab/lab65";
9
- import { lch } from "./lch/lch";
10
- import { oklab } from "./oklab/oklab";
11
- import { rgb } from "./rgb/rgb";
12
- import { srgb } from "./srgb/srgb";
13
- import { xyy } from "./xyy/xyy";
14
- import { xyzD50 } from "./xyz/xyz50";
15
- import { xyzD65 } from "./xyz/xyz65";
16
- import { ycc } from "./ycc/ycc";
1
+ import { isString } from "@thi.ng/checks/is-string";
2
+ import { hcy } from "./hcy/hcy.js";
3
+ import { hsi } from "./hsi/hsi.js";
4
+ import { hsl } from "./hsl/hsl.js";
5
+ import { hsv } from "./hsv/hsv.js";
6
+ import { argb32, abgr32 } from "./int/int.js";
7
+ import { labD50 } from "./lab/lab50.js";
8
+ import { labD65 } from "./lab/lab65.js";
9
+ import { lch } from "./lch/lch.js";
10
+ import { oklab } from "./oklab/oklab.js";
11
+ import { rgb } from "./rgb/rgb.js";
12
+ import { srgb } from "./srgb/srgb.js";
13
+ import { xyy } from "./xyy/xyy.js";
14
+ import { xyzD50 } from "./xyz/xyz50.js";
15
+ import { xyzD65 } from "./xyz/xyz65.js";
16
+ import { ycc } from "./ycc/ycc.js";
17
17
  const FACTORIES = {
18
18
  argb32,
19
19
  abgr32,
package/convert.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColorMode, ColorSpec, Conversions, ReadonlyColor } from "./api";
1
+ import type { ColorMode, ColorSpec, Conversions, ReadonlyColor } from "./api.js";
2
2
  export declare const CONVERSIONS: Partial<Record<ColorMode, Conversions>>;
3
3
  /**
4
4
  * Registers conversions for given {@link ColorSpec}. Called by
package/convert.js CHANGED
@@ -1,6 +1,6 @@
1
- import { assert } from "@thi.ng/api";
2
- import { isArray } from "@thi.ng/checks";
3
- import { unsupported } from "@thi.ng/errors";
1
+ import { isArray } from "@thi.ng/checks/is-array";
2
+ import { assert } from "@thi.ng/errors/assert";
3
+ import { unsupported } from "@thi.ng/errors/unsupported";
4
4
  export const CONVERSIONS = {};
5
5
  /**
6
6
  * Registers conversions for given {@link ColorSpec}. Called by
@@ -23,7 +23,7 @@ export const defConversions = (mode, spec) => {
23
23
  : (out, src) => d(out, c(out, b(out, a(out, src))));
24
24
  }
25
25
  }
26
- CONVERSIONS[mode] = spec;
26
+ CONVERSIONS[mode] = { ...CONVERSIONS[mode], ...spec };
27
27
  };
28
28
  export const convert = (res, src, destMode, srcMode) => {
29
29
  const spec = CONVERSIONS[destMode];
@@ -1,6 +1,6 @@
1
1
  import type { FnU, FnU2, NumericArray } from "@thi.ng/api";
2
- import type { Color, ReadonlyColor } from "../api";
3
- import type { CosGradientSpec, CosineGradientOpts, CosineGradientPreset } from "../api/gradients";
2
+ import type { Color, ReadonlyColor } from "./api.js";
3
+ import type { CosGradientSpec, CosineGradientOpts, CosineGradientPreset } from "./api/gradients.js";
4
4
  /**
5
5
  * Preset cosine gradient definitions. See previews at:
6
6
  * https://github.com/thi-ng/umbrella/tree/develop/packages/color#cosine-gradients
@@ -1,8 +1,16 @@
1
- import { partial } from "@thi.ng/compose";
2
- import { clamp01, TAU } from "@thi.ng/math";
3
- import { comp, map, noop, normRange, push, transduce, tween, zip, } from "@thi.ng/transducers";
4
- import { setS4 } from "@thi.ng/vectors";
5
- import { clamp } from "./clamp";
1
+ import { partial } from "@thi.ng/compose/partial";
2
+ import { TAU } from "@thi.ng/math/api";
3
+ import { clamp01 } from "@thi.ng/math/interval";
4
+ import { comp } from "@thi.ng/transducers/comp";
5
+ import { map } from "@thi.ng/transducers/map";
6
+ import { noop } from "@thi.ng/transducers/noop";
7
+ import { normRange } from "@thi.ng/transducers/norm-range";
8
+ import { push } from "@thi.ng/transducers/push";
9
+ import { transduce } from "@thi.ng/transducers/transduce";
10
+ import { tween } from "@thi.ng/transducers/tween";
11
+ import { zip } from "@thi.ng/transducers/zip";
12
+ import { setS4 } from "@thi.ng/vectors/sets";
13
+ import { clamp } from "./clamp.js";
6
14
  /**
7
15
  * Preset cosine gradient definitions. See previews at:
8
16
  * https://github.com/thi-ng/umbrella/tree/develop/packages/color#cosine-gradients
package/css/css.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IParsedColor, MaybeColor } from "../api";
1
+ import type { IParsedColor, MaybeColor } from "../api.js";
2
2
  /**
3
3
  * Takes a color in one of the following formats and tries to convert it
4
4
  * to a CSS string: