@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/rgb/rgb-ycc.js CHANGED
@@ -1,6 +1,7 @@
1
- import { dot3, setC4 } from "@thi.ng/vectors";
2
- import { RGB_LUMINANCE_REC709 } from "../api/constants";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { dot3 } from "@thi.ng/vectors/dot";
2
+ import { setC4 } from "@thi.ng/vectors/setc";
3
+ import { RGB_LUMINANCE_REC709 } from "../api/constants.js";
4
+ import { __ensureAlpha } from "../internal/ensure.js";
4
5
  /**
5
6
  * @remarks
6
7
  * https://en.wikipedia.org/wiki/YCbCr#YCbCr
@@ -17,5 +18,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
17
18
  */
18
19
  export const rgbYcc = (out, src, luma = RGB_LUMINANCE_REC709) => {
19
20
  const y = dot3(src, luma);
20
- return setC4(out || src, y, (0.5 * (src[2] - y)) / (1 - luma[2]), (0.5 * (src[0] - y)) / (1 - luma[0]), ensureAlpha(src[3]));
21
+ return setC4(out || src, y, (0.5 * (src[2] - y)) / (1 - luma[2]), (0.5 * (src[0] - y)) / (1 - luma[0]), __ensureAlpha(src[3]));
21
22
  };
package/rgb/rgb.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class RGB implements TypedColor<RGB> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/rgb/rgb.js CHANGED
@@ -1,17 +1,17 @@
1
- import { set4 } from "@thi.ng/vectors";
2
- import { defColor } from "../defcolor";
3
- import { hcyRgb } from "../hcy/hcy-rgb";
4
- import { hsiRgb } from "../hsi/hsi-rgb";
5
- import { hslRgb } from "../hsl/hsl-rgb";
6
- import { hsvRgb } from "../hsv/hsv-rgb";
7
- import { intAbgr32Rgb, intArgb32Rgb } from "../int/int-rgb";
8
- import { lchLab } from "../lab/lab-lch";
9
- import { labRgb, labRgbD65 } from "../lab/lab-rgb";
10
- import { oklabRgb } from "../oklab/oklab-rgb";
11
- import { srgbRgb } from "../srgb/srgb-rgb";
12
- import { xyyXyz } from "../xyy/xyy-xyz";
13
- import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb";
14
- import { yccRgb } from "../ycc/ycc-rgb";
1
+ import { set4 } from "@thi.ng/vectors/set";
2
+ import { defColor } from "../defcolor.js";
3
+ import { hcyRgb } from "../hcy/hcy-rgb.js";
4
+ import { hsiRgb } from "../hsi/hsi-rgb.js";
5
+ import { hslRgb } from "../hsl/hsl-rgb.js";
6
+ import { hsvRgb } from "../hsv/hsv-rgb.js";
7
+ import { intAbgr32Rgb, intArgb32Rgb } from "../int/int-rgb.js";
8
+ import { lchLab } from "../lab/lab-lch.js";
9
+ import { labRgb, labRgbD65 } from "../lab/lab-rgb.js";
10
+ import { oklabRgb } from "../oklab/oklab-rgb.js";
11
+ import { srgbRgb } from "../srgb/srgb-rgb.js";
12
+ import { xyyXyz } from "../xyy/xyy-xyz.js";
13
+ import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb.js";
14
+ import { yccRgb } from "../ycc/ycc-rgb.js";
15
15
  export const rgb = defColor({
16
16
  mode: "rgb",
17
17
  order: ["r", "g", "b", "alpha"],
@@ -33,4 +33,5 @@ export const rgb = defColor({
33
33
  xyz65: xyzRgbD65,
34
34
  ycc: yccRgb,
35
35
  },
36
+ toRgb: set4,
36
37
  });
@@ -1,15 +1,26 @@
1
- import { Fn } from "@thi.ng/api";
2
- import type { ColorDistance, ReadonlyColor, TypedColor } from "../api";
1
+ import type { Fn } from "@thi.ng/api";
2
+ import type { ColorDistance, ReadonlyColor, TypedColor } from "./api.js";
3
3
  export declare const selectChannel: (id: number) => (col: ReadonlyColor) => number;
4
4
  /**
5
- * Takes a `target` color and optional `distance` function. Returns a new
6
- * function which can be used as `key` function for {@link sort} to compute the
7
- * distance metric of a color to the given `target`.
5
+ * Takes a `target` color and optional `distance` function (default:
6
+ * {@link distEucledian3}). Returns a new function which can be used as `key`
7
+ * function for {@link sort} to compute the distance metric of a color to the
8
+ * given `target`.
8
9
  *
9
10
  * @param target
10
11
  * @param dist
11
12
  */
12
13
  export declare const proximity: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
14
+ /**
15
+ * Similar to {@link proximity}, but intended as syntax sugar for {@link ABGR}
16
+ * input colors. The proximity will still be computed using given distance
17
+ * function (default: {@link distEucledian3}) and will be in sRGB space. Hence
18
+ * given `target` color should be provided in the same space too.
19
+ *
20
+ * @param target
21
+ * @param dist
22
+ */
23
+ export declare const proximityABGR32: (target: ReadonlyColor, dist?: ColorDistance) => (col: ReadonlyColor) => number;
13
24
  export declare const sort: (colors: ReadonlyColor[], key: Fn<ReadonlyColor, number>, isReverse?: boolean) => import("@thi.ng/vectors").ReadonlyVec[];
14
25
  /**
15
26
  * Similar to {@link sort}, but only for memory mapped colors (e.g. mapping a
@@ -1,17 +1,31 @@
1
- import { typedArray, typedArrayType } from "@thi.ng/api";
2
- import { quickSort, sortByCachedKey, swap } from "@thi.ng/arrays";
3
- import { compareNumAsc, compareNumDesc } from "@thi.ng/compare";
4
- import { distEucledian3 } from "./distance";
1
+ import { typedArray, typedArrayType } from "@thi.ng/api/typedarray";
2
+ import { quickSort } from "@thi.ng/arrays/quicksort";
3
+ import { sortByCachedKey } from "@thi.ng/arrays/sort-cached";
4
+ import { swap } from "@thi.ng/arrays/swap";
5
+ import { compareNumAsc, compareNumDesc } from "@thi.ng/compare/numeric";
6
+ import { distEucledian3 } from "./distance.js";
7
+ import { intAbgr32Srgb } from "./int/int-srgb.js";
5
8
  export const selectChannel = (id) => (col) => col[id];
6
9
  /**
7
- * Takes a `target` color and optional `distance` function. Returns a new
8
- * function which can be used as `key` function for {@link sort} to compute the
9
- * distance metric of a color to the given `target`.
10
+ * Takes a `target` color and optional `distance` function (default:
11
+ * {@link distEucledian3}). Returns a new function which can be used as `key`
12
+ * function for {@link sort} to compute the distance metric of a color to the
13
+ * given `target`.
10
14
  *
11
15
  * @param target
12
16
  * @param dist
13
17
  */
14
18
  export const proximity = (target, dist = distEucledian3) => (col) => dist(target, col);
19
+ /**
20
+ * Similar to {@link proximity}, but intended as syntax sugar for {@link ABGR}
21
+ * input colors. The proximity will still be computed using given distance
22
+ * function (default: {@link distEucledian3}) and will be in sRGB space. Hence
23
+ * given `target` color should be provided in the same space too.
24
+ *
25
+ * @param target
26
+ * @param dist
27
+ */
28
+ export const proximityABGR32 = (target, dist = distEucledian3) => (col) => dist(target, intAbgr32Srgb([], col[0]));
15
29
  export const sort = (colors, key, isReverse = false) => sortByCachedKey(colors, key, isReverse ? compareNumDesc : compareNumAsc);
16
30
  /**
17
31
  * Similar to {@link sort}, but only for memory mapped colors (e.g. mapping a
@@ -1,3 +1,3 @@
1
- import type { ReadonlyColor } from "../api";
1
+ import type { ReadonlyColor } from "../api.js";
2
2
  export declare const srgbCss: (src: ReadonlyColor) => string;
3
3
  //# sourceMappingURL=srgb-css.d.ts.map
package/srgb/srgb-css.js CHANGED
@@ -1,12 +1,12 @@
1
- import { clamp01 } from "@thi.ng/math";
2
- import { U24 } from "@thi.ng/strings";
3
- import { FF } from "../api/constants";
4
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { U24 } from "@thi.ng/strings/radix";
2
+ import { FF } from "../api/constants.js";
3
+ import { __ensureAlpha } from "../internal/ensure.js";
4
+ import { __scale8bit } from "../internal/scale.js";
5
5
  export const srgbCss = (src) => {
6
- const r = (clamp01(src[0]) * 0xff + 0.5) | 0;
7
- const g = (clamp01(src[1]) * 0xff + 0.5) | 0;
8
- const b = (clamp01(src[2]) * 0xff + 0.5) | 0;
9
- const a = ensureAlpha(src[3]);
6
+ const r = __scale8bit(src[0]);
7
+ const g = __scale8bit(src[1]);
8
+ const b = __scale8bit(src[2]);
9
+ const a = __ensureAlpha(src[3]);
10
10
  // TODO update to `rgb(${r} ${g} ${b}/${FF(a)})` (CSS L4 syntax)
11
11
  return a < 1
12
12
  ? `rgba(${r},${g},${b},${FF(a)})`
@@ -1,4 +1,4 @@
1
- import type { ReadonlyColor } from "../api";
1
+ import type { ReadonlyColor } from "../api.js";
2
2
  export declare const srgbIntArgb32: (src: ReadonlyColor) => number;
3
3
  export declare const srgbIntAbgr32: (src: ReadonlyColor) => number;
4
4
  //# sourceMappingURL=srgb-int.d.ts.map
package/srgb/srgb-int.js CHANGED
@@ -1,11 +1,11 @@
1
- import { clamp01 } from "@thi.ng/math";
2
- import { ensureAlpha } from "../internal/ensure-alpha";
3
- export const srgbIntArgb32 = (src) => (((ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
1
+ import { clamp01 } from "@thi.ng/math/interval";
2
+ import { __ensureAlpha } from "../internal/ensure.js";
3
+ export const srgbIntArgb32 = (src) => (((__ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
4
4
  ((clamp01(src[0]) * 0xff + 0.5) << 16) |
5
5
  ((clamp01(src[1]) * 0xff + 0.5) << 8) |
6
6
  (clamp01(src[2]) * 0xff + 0.5)) >>>
7
7
  0;
8
- export const srgbIntAbgr32 = (src) => (((ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
8
+ export const srgbIntAbgr32 = (src) => (((__ensureAlpha(src[3]) * 0xff + 0.5) << 24) |
9
9
  ((clamp01(src[2]) * 0xff + 0.5) << 16) |
10
10
  ((clamp01(src[1]) * 0xff + 0.5) << 8) |
11
11
  (clamp01(src[0]) * 0xff + 0.5)) >>>
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  /**
3
3
  * Converts sRGB to linear RGB.
4
4
  *
package/srgb/srgb-rgb.js CHANGED
@@ -1,12 +1,12 @@
1
- import { setC4 } from "@thi.ng/vectors";
2
- import { ensureAlpha } from "../internal/ensure-alpha";
3
- import { srgbLinear } from "../ops/linear";
1
+ import { setC4 } from "@thi.ng/vectors/setc";
2
+ import { __ensureAlpha } from "../internal/ensure.js";
3
+ import { srgbLinear } from "../linear.js";
4
4
  /**
5
5
  * Converts sRGB to linear RGB.
6
6
  *
7
7
  * @param out - result
8
8
  * @param src - source color
9
9
  */
10
- export const srgbRgb = (out, src) => setC4(out || src, srgbLinear(src[0]), srgbLinear(src[1]), srgbLinear(src[2]), ensureAlpha(src[3]));
10
+ export const srgbRgb = (out, src) => setC4(out || src, srgbLinear(src[0]), srgbLinear(src[1]), srgbLinear(src[2]), __ensureAlpha(src[3]));
11
11
  const GAMMA = 2.2;
12
- export const srgbRgbApprox = (out, src) => setC4(out || src, src[0] ** GAMMA, src[1] ** GAMMA, src[2] ** GAMMA, ensureAlpha(src[3]));
12
+ export const srgbRgbApprox = (out, src) => setC4(out || src, src[0] ** GAMMA, src[1] ** GAMMA, src[2] ** GAMMA, __ensureAlpha(src[3]));
package/srgb/srgb.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class SRGB implements TypedColor<SRGB> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/srgb/srgb.js CHANGED
@@ -1,10 +1,11 @@
1
- import { defColor } from "../defcolor";
2
- import { hcyRgb } from "../hcy/hcy-rgb";
3
- import { hsiRgb } from "../hsi/hsi-rgb";
4
- import { hslRgb } from "../hsl/hsl-rgb";
5
- import { hsvRgb } from "../hsv/hsv-rgb";
6
- import { intAbgr32Srgb, intArgb32Srgb } from "../int/int-srgb";
7
- import { rgbSrgb } from "../rgb/rgb-srgb";
1
+ import { defColor } from "../defcolor.js";
2
+ import { hcyRgb } from "../hcy/hcy-rgb.js";
3
+ import { hsiRgb } from "../hsi/hsi-rgb.js";
4
+ import { hslRgb } from "../hsl/hsl-rgb.js";
5
+ import { hsvRgb } from "../hsv/hsv-rgb.js";
6
+ import { intAbgr32Srgb, intArgb32Srgb } from "../int/int-srgb.js";
7
+ import { rgbSrgb } from "../rgb/rgb-srgb.js";
8
+ import { srgbRgb } from "./srgb-rgb.js";
8
9
  export const srgb = defColor({
9
10
  mode: "srgb",
10
11
  order: ["r", "g", "b", "alpha"],
@@ -17,4 +18,5 @@ export const srgb = defColor({
17
18
  hsv: hsvRgb,
18
19
  rgb: rgbSrgb,
19
20
  },
21
+ toRgb: srgbRgb,
20
22
  });
@@ -1,5 +1,5 @@
1
1
  import type { Fn2, IObjectOf } from "@thi.ng/api";
2
- import type { ReadonlyColor } from "../api";
2
+ import type { ReadonlyColor } from "./api.js";
3
3
  export declare const swatches: (cols: (ReadonlyColor | string)[], shapeFn: Fn2<ReadonlyColor | string, number, any[]>, attribs?: IObjectOf<any>) => (string | IObjectOf<any>)[];
4
4
  export declare const swatchesH: (cols: (ReadonlyColor | string)[], w?: number, h?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
5
5
  export declare const dotsH: (cols: (ReadonlyColor | string)[], r?: number, gap?: number, attribs?: IObjectOf<any> | undefined) => (string | IObjectOf<any>)[];
File without changes
@@ -1,4 +1,4 @@
1
- import type { ColorMatrix, ReadonlyColor } from "../api";
1
+ import type { ColorMatrix, ReadonlyColor } from "./api.js";
2
2
  /**
3
3
  * Transforms `src` RGBA color with given matrix and stores result in
4
4
  * `out` (writes back to `src` if `out` is `null` or `undefined`).
@@ -1,6 +1,6 @@
1
- import { mix } from "@thi.ng/math";
2
- import { RGB_LUMINANCE_REC709, WHITE } from "../api/constants";
3
- import { mulM45, mulV45 } from "../internal/matrix-ops";
1
+ import { mix } from "@thi.ng/math/mix";
2
+ import { RGB_LUMINANCE_REC709, WHITE } from "./api/constants.js";
3
+ import { __mulM45, __mulV45 } from "./internal/matrix-ops.js";
4
4
  // https://drafts.fxtf.org/filter-effects/#feColorMatrixElement
5
5
  const S0 = 0.072;
6
6
  const S1 = 0.213;
@@ -22,7 +22,7 @@ const S8 = 0.283;
22
22
  * @param src - source color
23
23
  * @param clampOut - true, if result should be clamped to [0..1]
24
24
  */
25
- export const transform = mulV45;
25
+ export const transform = __mulV45;
26
26
  /**
27
27
  * Concatenates given color matrices by pairwise multiplying them in
28
28
  * left-right order. Returns combined result matrix to be used with
@@ -39,7 +39,7 @@ export const transform = mulV45;
39
39
  * @param mat - first matrix
40
40
  * @param xs - other matrices
41
41
  */
42
- export const concat = (mat, ...xs) => xs.reduce(mulM45, mat);
42
+ export const concat = (mat, ...xs) => xs.reduce(__mulM45, mat);
43
43
  // prettier-ignore
44
44
  export const IDENTITY = [
45
45
  1, 0, 0, 0, 0,
package/xyy/xyy-xyz.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  /**
3
3
  * @remarks
4
4
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
package/xyy/xyy-xyz.js CHANGED
@@ -1,6 +1,6 @@
1
- import { safeDiv } from "@thi.ng/math";
2
- import { setC4 } from "@thi.ng/vectors";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { safeDiv } from "@thi.ng/math/safe-div";
2
+ import { setC4 } from "@thi.ng/vectors/setc";
3
+ import { __ensureAlpha } from "../internal/ensure.js";
4
4
  /**
5
5
  * @remarks
6
6
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
@@ -11,5 +11,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
11
11
  */
12
12
  export const xyyXyz = (out, src) => {
13
13
  const { 0: x, 1: y, 2: Y } = src;
14
- return setC4(out || src, safeDiv(Y * x, y), Y, safeDiv(Y * (1 - x - y), y), ensureAlpha(src[3]));
14
+ return setC4(out || src, safeDiv(Y * x, y), Y, safeDiv(Y * (1 - x - y), y), __ensureAlpha(src[3]));
15
15
  };
package/xyy/xyy.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class XYY implements TypedColor<XYY> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/xyy/xyy.js CHANGED
@@ -1,6 +1,8 @@
1
- import { defColor } from "../defcolor";
2
- import { rgbXyzD65 } from "../rgb/rgb-xyz";
3
- import { xyzXyy } from "../xyz/xyz-xyy";
1
+ import { defColor } from "../defcolor.js";
2
+ import { rgbXyzD65 } from "../rgb/rgb-xyz.js";
3
+ import { xyzRgbD65 } from "../xyz/xyz-rgb.js";
4
+ import { xyzXyy } from "../xyz/xyz-xyy.js";
5
+ import { xyyXyz } from "./xyy-xyz.js";
4
6
  export const xyy = defColor({
5
7
  mode: "xyy",
6
8
  channels: {
@@ -13,4 +15,5 @@ export const xyy = defColor({
13
15
  xyz50: xyzXyy,
14
16
  xyz65: xyzXyy,
15
17
  },
18
+ toRgb: [xyyXyz, xyzRgbD65],
16
19
  });
@@ -1,4 +1,4 @@
1
- import { XYZD65 } from "./xyz65";
1
+ import { XYZD65 } from "./xyz65.js";
2
2
  /**
3
3
  * Computes XYZA for given wavelength (in nanometers) and optional alpha channel
4
4
  * (default: 1), writes result into `out` (or a new array if null).
@@ -1,5 +1,5 @@
1
- import { setC4 } from "@thi.ng/vectors";
2
- import { xyzD65 } from "./xyz65";
1
+ import { setC4 } from "@thi.ng/vectors/setc";
2
+ import { xyzD65 } from "./xyz65.js";
3
3
  /**
4
4
  * Computes XYZA for given wavelength (in nanometers) and optional alpha channel
5
5
  * (default: 1), writes result into `out` (or a new array if null).
package/xyz/xyz-lab.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Color, ColorOp, ReadonlyColor } from "../api";
1
+ import type { Color, ColorOp, ReadonlyColor } from "../api.js";
2
2
  /**
3
3
  * Converts XYZ to Lab, using provided reference white point (default:
4
4
  * {@link D50}). Also see {@link xyzLabD65}.
package/xyz/xyz-lab.js CHANGED
@@ -1,6 +1,7 @@
1
- import { setC4 } from "@thi.ng/vectors";
2
- import { D50, D65 } from "../api/constants";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { setC4 } from "@thi.ng/vectors/setc";
2
+ import { D50, D65 } from "../api/constants.js";
3
+ import { __ensureAlpha } from "../internal/ensure.js";
4
+ /** @internal */
4
5
  const transform = (x) => x > 0.00885645 ? Math.cbrt(x) : 7.787037 * x + 16 / 116;
5
6
  /**
6
7
  * Converts XYZ to Lab, using provided reference white point (default:
@@ -18,7 +19,7 @@ export const xyzLab = (out, src, white = D50) => {
18
19
  const x = transform(src[0] / white[0]);
19
20
  const y = transform(src[1] / white[1]);
20
21
  const z = transform(src[2] / white[2]);
21
- return setC4(out || src, 1.16 * y - 0.16, 5.0 * (x - y), 2.0 * (y - z), ensureAlpha(src[3]));
22
+ return setC4(out || src, 1.16 * y - 0.16, 5.0 * (x - y), 2.0 * (y - z), __ensureAlpha(src[3]));
22
23
  };
23
24
  /**
24
25
  * Same as {@link xyzLab}, but hard coded to use {@link D65} white point.
@@ -1,3 +1,3 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  export declare const xyzOklab: ColorOp;
3
3
  //# sourceMappingURL=xyz-oklab.d.ts.map
package/xyz/xyz-oklab.js CHANGED
@@ -1,4 +1,4 @@
1
- import { powN3 } from "@thi.ng/vectors";
2
- import { OKLAB_M1, OKLAB_M2 } from "../api/constants";
3
- import { mulV33 } from "../internal/matrix-ops";
4
- export const xyzOklab = (out, src) => mulV33(null, OKLAB_M2, powN3(null, mulV33(out, OKLAB_M1, src), 1 / 3));
1
+ import { powN3 } from "@thi.ng/vectors/pown";
2
+ import { OKLAB_M1, OKLAB_M2 } from "../api/constants.js";
3
+ import { __mulV33 } from "../internal/matrix-ops.js";
4
+ export const xyzOklab = (out, src) => __mulV33(null, OKLAB_M2, powN3(null, __mulV33(out, OKLAB_M1, src), 1 / 3));
package/xyz/xyz-rgb.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Color, ColorOp, ReadonlyColor } from "../api";
1
+ import type { Color, ColorOp, ReadonlyColor } from "../api.js";
2
2
  /**
3
3
  * Converts CIE XYZ to RGB using provided transformation/whitepoint matrix
4
4
  * (default: {@link XYZ_RGB_D50}).
package/xyz/xyz-rgb.js CHANGED
@@ -1,5 +1,5 @@
1
- import { XYZ_RGB_D50, XYZ_RGB_D65 } from "../api/constants";
2
- import { mulV33 } from "../internal/matrix-ops";
1
+ import { XYZ_RGB_D50, XYZ_RGB_D65 } from "../api/constants.js";
2
+ import { __mulV33 } from "../internal/matrix-ops.js";
3
3
  /**
4
4
  * Converts CIE XYZ to RGB using provided transformation/whitepoint matrix
5
5
  * (default: {@link XYZ_RGB_D50}).
@@ -9,7 +9,7 @@ import { mulV33 } from "../internal/matrix-ops";
9
9
  * @param out - result
10
10
  * @param src - source color
11
11
  */
12
- export const xyzRgb = (out, src, mat = XYZ_RGB_D50) => mulV33(out, mat, src);
12
+ export const xyzRgb = (out, src, mat = XYZ_RGB_D50) => __mulV33(out, mat, src);
13
13
  /**
14
14
  * Same as {@link xyzRgb}, but hard coded to use {@link D65} white point (via
15
15
  * {@link XYZ_RGB_D65} matrix).
package/xyz/xyz-xyy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  /**
3
3
  * @remarks
4
4
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
package/xyz/xyz-xyy.js CHANGED
@@ -1,6 +1,6 @@
1
- import { safeDiv } from "@thi.ng/math";
2
- import { setC4 } from "@thi.ng/vectors";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { safeDiv } from "@thi.ng/math/safe-div";
2
+ import { setC4 } from "@thi.ng/vectors/setc";
3
+ import { __ensureAlpha } from "../internal/ensure.js";
4
4
  /**
5
5
  * @remarks
6
6
  * https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
@@ -12,5 +12,5 @@ import { ensureAlpha } from "../internal/ensure-alpha";
12
12
  export const xyzXyy = (out, src) => {
13
13
  const { 0: x, 1: Y } = src;
14
14
  const sum = x + Y + src[2];
15
- return setC4(out || src, safeDiv(x, sum), safeDiv(Y, sum), Y, ensureAlpha(src[3]));
15
+ return setC4(out || src, safeDiv(x, sum), safeDiv(Y, sum), Y, __ensureAlpha(src[3]));
16
16
  };
package/xyz/xyz-xyz.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  export declare const xyzXyzD65_50: ColorOp;
3
3
  export declare const xyzXyzD50_65: ColorOp;
4
4
  //# sourceMappingURL=xyz-xyz.d.ts.map
package/xyz/xyz-xyz.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BRADFORD_D50_D65, BRADFORD_D65_D50 } from "../api/constants";
2
- import { mulV33 } from "../internal/matrix-ops";
3
- export const xyzXyzD65_50 = (out, src) => mulV33(out, BRADFORD_D65_D50, src);
4
- export const xyzXyzD50_65 = (out, src) => mulV33(out, BRADFORD_D50_D65, src);
1
+ import { BRADFORD_D50_D65, BRADFORD_D65_D50 } from "../api/constants.js";
2
+ import { __mulV33 } from "../internal/matrix-ops.js";
3
+ export const xyzXyzD65_50 = (out, src) => __mulV33(out, BRADFORD_D65_D50, src);
4
+ export const xyzXyzD50_65 = (out, src) => __mulV33(out, BRADFORD_D50_D65, src);
package/xyz/xyz50.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class XYZD50 implements TypedColor<XYZD50> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/xyz/xyz50.js CHANGED
@@ -1,11 +1,12 @@
1
- import { D50 } from "../api/constants";
2
- import { defColor } from "../defcolor";
3
- import { lchLab } from "../lab/lab-lch";
4
- import { labXyz, labXyzD65 } from "../lab/lab-xyz";
5
- import { oklabXyzD65 } from "../oklab/oklab-xyz";
6
- import { rgbXyz } from "../rgb/rgb-xyz";
7
- import { xyyXyz } from "../xyy/xyy-xyz";
8
- import { xyzXyzD65_50 } from "./xyz-xyz";
1
+ import { D50 } from "../api/constants.js";
2
+ import { defColor } from "../defcolor.js";
3
+ import { lchLab } from "../lab/lab-lch.js";
4
+ import { labXyz, labXyzD65 } from "../lab/lab-xyz.js";
5
+ import { oklabXyzD65 } from "../oklab/oklab-xyz.js";
6
+ import { rgbXyz } from "../rgb/rgb-xyz.js";
7
+ import { xyyXyz } from "../xyy/xyy-xyz.js";
8
+ import { xyzRgb } from "./xyz-rgb.js";
9
+ import { xyzXyzD65_50 } from "./xyz-xyz.js";
9
10
  export const xyzD50 = defColor({
10
11
  mode: "xyz50",
11
12
  channels: {
@@ -22,4 +23,5 @@ export const xyzD50 = defColor({
22
23
  oklab: [oklabXyzD65, xyzXyzD65_50],
23
24
  xyy: xyyXyz,
24
25
  },
26
+ toRgb: xyzRgb,
25
27
  });
package/xyz/xyz65.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class XYZD65 implements TypedColor<XYZD65> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/xyz/xyz65.js CHANGED
@@ -1,11 +1,12 @@
1
- import { D65 } from "../api/constants";
2
- import { defColor } from "../defcolor";
3
- import { labLabD50_65 } from "../lab/lab-lab";
4
- import { lchLab } from "../lab/lab-lch";
5
- import { labXyzD65 } from "../lab/lab-xyz";
6
- import { oklabXyzD65 } from "../oklab/oklab-xyz";
7
- import { rgbXyzD65 } from "../rgb/rgb-xyz";
8
- import { xyyXyz } from "../xyy/xyy-xyz";
1
+ import { D65 } from "../api/constants.js";
2
+ import { defColor } from "../defcolor.js";
3
+ import { labLabD50_65 } from "../lab/lab-lab.js";
4
+ import { lchLab } from "../lab/lab-lch.js";
5
+ import { labXyzD65 } from "../lab/lab-xyz.js";
6
+ import { oklabXyzD65 } from "../oklab/oklab-xyz.js";
7
+ import { rgbXyzD65 } from "../rgb/rgb-xyz.js";
8
+ import { xyyXyz } from "../xyy/xyy-xyz.js";
9
+ import { xyzRgbD65 } from "./xyz-rgb.js";
9
10
  export const xyzD65 = defColor({
10
11
  mode: "xyz65",
11
12
  channels: {
@@ -22,4 +23,5 @@ export const xyzD65 = defColor({
22
23
  oklab: oklabXyzD65,
23
24
  xyy: xyyXyz,
24
25
  },
26
+ toRgb: xyzRgbD65,
25
27
  });
package/ycc/ycc-rgb.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Color, ReadonlyColor } from "../api";
1
+ import type { Color, ReadonlyColor } from "../api.js";
2
2
  /**
3
3
  * @remarks
4
4
  * https://en.wikipedia.org/wiki/YCbCr#YCbCr
package/ycc/ycc-rgb.js CHANGED
@@ -1,6 +1,6 @@
1
- import { setC4 } from "@thi.ng/vectors";
2
- import { RGB_LUMINANCE_REC709 } from "../api/constants";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { setC4 } from "@thi.ng/vectors/setc";
2
+ import { RGB_LUMINANCE_REC709 } from "../api/constants.js";
3
+ import { __ensureAlpha } from "../internal/ensure.js";
4
4
  /**
5
5
  * @remarks
6
6
  * https://en.wikipedia.org/wiki/YCbCr#YCbCr
@@ -19,5 +19,5 @@ export const yccRgb = (out, src, luma = RGB_LUMINANCE_REC709) => {
19
19
  const y = src[0];
20
20
  const bb = (2 - 2 * luma[2]) * src[1];
21
21
  const rr = (2 - 2 * luma[0]) * src[2];
22
- return setC4(out || src, y + rr, y - (luma[2] / luma[1]) * bb - (luma[0] / luma[1]) * rr, y + bb, ensureAlpha(src[3]));
22
+ return setC4(out || src, y + rr, y - (luma[2] / luma[1]) * bb - (luma[0] / luma[1]) * rr, y + bb, __ensureAlpha(src[3]));
23
23
  };
package/ycc/ycc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { NumericArray } from "@thi.ng/api";
2
2
  import type { IRandom } from "@thi.ng/random";
3
- import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api";
3
+ import type { Color, ColorFactory, ReadonlyColor, TypedColor } from "../api.js";
4
4
  export declare class YCC implements TypedColor<YCC> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/ycc/ycc.js CHANGED
@@ -1,5 +1,6 @@
1
- import { defColor } from "../defcolor";
2
- import { rgbYcc } from "../rgb/rgb-ycc";
1
+ import { defColor } from "../defcolor.js";
2
+ import { rgbYcc } from "../rgb/rgb-ycc.js";
3
+ import { yccRgb } from "./ycc-rgb.js";
3
4
  export const ycc = defColor({
4
5
  mode: "ycc",
5
6
  channels: {
@@ -8,4 +9,5 @@ export const ycc = defColor({
8
9
  },
9
10
  order: ["y", "cb", "cr", "alpha"],
10
11
  from: { rgb: rgbYcc },
12
+ toRgb: yccRgb,
11
13
  });
@@ -1,2 +0,0 @@
1
- export declare const ensureAlpha: (x: number, def?: number) => number;
2
- //# sourceMappingURL=ensure-alpha.d.ts.map
@@ -1,2 +0,0 @@
1
- import { clamp01 } from "@thi.ng/math";
2
- export const ensureAlpha = (x, def = 1) => x != undefined ? clamp01(x) : def;
@@ -1,3 +0,0 @@
1
- /** @internal */
2
- export declare const ensureArgs: (args: any[]) => any[];
3
- //# sourceMappingURL=ensure-args.d.ts.map