@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/lab/lab-lab.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 labLabD50_65: ColorOp;
3
3
  export declare const labLabD65_50: ColorOp;
4
4
  //# sourceMappingURL=lab-lab.d.ts.map
package/lab/lab-lab.js CHANGED
@@ -1,5 +1,5 @@
1
- import { xyzLab, xyzLabD65 } from "../xyz/xyz-lab";
2
- import { xyzXyzD50_65, xyzXyzD65_50 } from "../xyz/xyz-xyz";
3
- import { labXyz, labXyzD65 } from "./lab-xyz";
1
+ import { xyzLab, xyzLabD65 } from "../xyz/xyz-lab.js";
2
+ import { xyzXyzD50_65, xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
3
+ import { labXyz, labXyzD65 } from "./lab-xyz.js";
4
4
  export const labLabD50_65 = (out, src) => xyzLabD65(out, xyzXyzD50_65(out, labXyz(out, src)));
5
5
  export const labLabD65_50 = (out, src) => xyzLab(out, xyzXyzD65_50(out, labXyzD65(out, src)));
package/lab/lab-lch.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 labLch: ColorOp;
3
3
  export declare const lchLab: ColorOp;
4
4
  //# sourceMappingURL=lab-lch.d.ts.map
package/lab/lab-lch.js CHANGED
@@ -1,14 +1,15 @@
1
- import { atan2Abs, INV_TAU, TAU } from "@thi.ng/math";
2
- import { setC4 } from "@thi.ng/vectors";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { atan2Abs } from "@thi.ng/math/angle";
2
+ import { INV_TAU, TAU } from "@thi.ng/math/api";
3
+ import { setC4 } from "@thi.ng/vectors/setc";
4
+ import { __ensureAlpha } from "../internal/ensure.js";
4
5
  export const labLch = (out, src) => {
5
6
  const { 1: a, 2: b } = src;
6
- return setC4(out || src, src[0], Math.hypot(a, b), a === 0 && b === 0 ? 0 : atan2Abs(b, a) * INV_TAU, ensureAlpha(src[3]));
7
+ return setC4(out || src, src[0], Math.hypot(a, b), a === 0 && b === 0 ? 0 : atan2Abs(b, a) * INV_TAU, __ensureAlpha(src[3]));
7
8
  };
8
9
  export const lchLab = (out, src) => {
9
10
  let { 1: c, 2: h } = src;
10
11
  h *= TAU;
11
- const a = ensureAlpha(src[3]);
12
+ const a = __ensureAlpha(src[3]);
12
13
  return c > 0
13
14
  ? setC4(out || src, src[0], Math.cos(h) * c, Math.sin(h) * c, a)
14
15
  : setC4(out || src, src[0], 0, 0, a);
package/lab/lab-rgb.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  /**
3
3
  * Converts Lab to linear RGB (via XYZ) using {@link D50} white point.
4
4
  *
package/lab/lab-rgb.js CHANGED
@@ -1,5 +1,5 @@
1
- import { labXyz, labXyzD65 } from "./lab-xyz";
2
- import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb";
1
+ import { labXyz, labXyzD65 } from "./lab-xyz.js";
2
+ import { xyzRgb, xyzRgbD65 } from "../xyz/xyz-rgb.js";
3
3
  /**
4
4
  * Converts Lab to linear RGB (via XYZ) using {@link D50} white point.
5
5
  *
package/lab/lab-xyz.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 Lab to XYZ using provided white point (default: {@link D50}). Also
4
4
  * see {@link labXyzD65}.
package/lab/lab-xyz.js CHANGED
@@ -1,6 +1,6 @@
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
4
  const transform = (x) => {
5
5
  const y = x ** 3;
6
6
  return y > 0.008856 ? y : (x - 16 / 116) / 7.787;
@@ -15,7 +15,7 @@ const transform = (x) => {
15
15
  */
16
16
  export const labXyz = (out, src, white = D50) => {
17
17
  const y = (src[0] + 0.16) / 1.16;
18
- return setC4(out || src, transform(src[1] / 5.0 + y) * white[0], transform(y) * white[1], transform(y - src[2] / 2.0) * white[2], ensureAlpha(src[3]));
18
+ return setC4(out || src, transform(src[1] / 5.0 + y) * white[0], transform(y) * white[1], transform(y - src[2] / 2.0) * white[2], __ensureAlpha(src[3]));
19
19
  };
20
20
  /**
21
21
  * Same as {@link labXyz}, but using hardcoded {@link D65} white point.
package/lab/lab50.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 LabD50 implements TypedColor<LabD50> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/lab/lab50.js CHANGED
@@ -1,9 +1,10 @@
1
- import { defColor } from "../defcolor";
2
- import { rgbLab } from "../rgb/rgb-lab";
3
- import { xyzLab } from "../xyz/xyz-lab";
4
- import { xyzXyzD65_50 } from "../xyz/xyz-xyz";
5
- import { labLabD65_50 } from "./lab-lab";
6
- import { lchLab } from "./lab-lch";
1
+ import { defColor } from "../defcolor.js";
2
+ import { rgbLab } from "../rgb/rgb-lab.js";
3
+ import { xyzLab } from "../xyz/xyz-lab.js";
4
+ import { xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
5
+ import { labLabD65_50 } from "./lab-lab.js";
6
+ import { lchLab } from "./lab-lch.js";
7
+ import { labRgb } from "./lab-rgb.js";
7
8
  export const labD50 = defColor({
8
9
  mode: "lab50",
9
10
  channels: {
@@ -18,4 +19,5 @@ export const labD50 = defColor({
18
19
  xyz50: xyzLab,
19
20
  xyz65: [xyzXyzD65_50, xyzLab],
20
21
  },
22
+ toRgb: labRgb,
21
23
  });
package/lab/lab65.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 LabD65 implements TypedColor<LabD65> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/lab/lab65.js CHANGED
@@ -1,9 +1,10 @@
1
- import { defColor } from "../defcolor";
2
- import { rgbLabD65 } from "../rgb/rgb-lab";
3
- import { xyzLabD65 } from "../xyz/xyz-lab";
4
- import { xyzXyzD50_65 } from "../xyz/xyz-xyz";
5
- import { labLabD50_65 } from "./lab-lab";
6
- import { lchLab } from "./lab-lch";
1
+ import { defColor } from "../defcolor.js";
2
+ import { rgbLabD65 } from "../rgb/rgb-lab.js";
3
+ import { xyzLabD65 } from "../xyz/xyz-lab.js";
4
+ import { xyzXyzD50_65 } from "../xyz/xyz-xyz.js";
5
+ import { labLabD50_65 } from "./lab-lab.js";
6
+ import { lchLab } from "./lab-lch.js";
7
+ import { labRgbD65 } from "./lab-rgb.js";
7
8
  export const labD65 = defColor({
8
9
  mode: "lab65",
9
10
  channels: {
@@ -18,4 +19,5 @@ export const labD65 = defColor({
18
19
  xyz50: [xyzXyzD50_65, xyzLabD65],
19
20
  xyz65: xyzLabD65,
20
21
  },
22
+ toRgb: labRgbD65,
21
23
  });
package/lch/lch-css.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ReadonlyColor } from "../api";
1
+ import type { ReadonlyColor } from "../api.js";
2
2
  /**
3
3
  * @remarks
4
4
  * Only supported in CSS Color Level 4 onwards
package/lch/lch-css.js CHANGED
@@ -1,6 +1,7 @@
1
- import { clamp0, fract } from "@thi.ng/math";
2
- import { FF, PC } from "../api/constants";
3
- import { ensureAlpha } from "../internal/ensure-alpha";
1
+ import { clamp0 } from "@thi.ng/math/interval";
2
+ import { fract } from "@thi.ng/math/prec";
3
+ import { FF, PC } from "../api/constants.js";
4
+ import { __ensureAlpha } from "../internal/ensure.js";
4
5
  /**
5
6
  * @remarks
6
7
  * Only supported in CSS Color Level 4 onwards
@@ -13,6 +14,6 @@ export const lchCss = (src) => {
13
14
  const l = PC(clamp0(src[0]));
14
15
  const c = FF(clamp0(src[1]) * 100);
15
16
  const h = FF(fract(src[2]) * 360);
16
- const a = ensureAlpha(src[3]);
17
+ const a = __ensureAlpha(src[3]);
17
18
  return `lch(${l} ${c} ${h}` + (a < 1 ? `/${FF(a)})` : ")");
18
19
  };
package/lch/lch.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 LCH implements TypedColor<LCH> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/lch/lch.js CHANGED
@@ -1,9 +1,10 @@
1
- import { defColor } from "../defcolor";
2
- import { labLabD65_50 } from "../lab/lab-lab";
3
- import { labLch } from "../lab/lab-lch";
4
- import { rgbLab } from "../rgb/rgb-lab";
5
- import { xyzLab } from "../xyz/xyz-lab";
6
- import { xyzXyzD65_50 } from "../xyz/xyz-xyz";
1
+ import { defColor } from "../defcolor.js";
2
+ import { labLabD65_50 } from "../lab/lab-lab.js";
3
+ import { labLch, lchLab } from "../lab/lab-lch.js";
4
+ import { labRgb } from "../lab/lab-rgb.js";
5
+ import { rgbLab } from "../rgb/rgb-lab.js";
6
+ import { xyzLab } from "../xyz/xyz-lab.js";
7
+ import { xyzXyzD65_50 } from "../xyz/xyz-xyz.js";
7
8
  /**
8
9
  * Luminance Chroma Hue (conversions assume {@link D50} white point, as per CSS
9
10
  * spec).
@@ -21,4 +22,5 @@ export const lch = defColor({
21
22
  xyz50: [xyzLab, labLch],
22
23
  xyz65: [xyzXyzD65_50, xyzLab, labLch],
23
24
  },
25
+ toRgb: [lchLab, labRgb],
24
26
  });
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import type { ReadonlyColor } from "../api";
1
+ import type { ReadonlyColor } from "./api.js";
2
2
  /**
3
3
  * Computes RGB luminance, optionally using provided weights (by default:
4
4
  * {@link RGB_LUMINANCE_REC709}).
@@ -1,5 +1,5 @@
1
- import { dot3 } from "@thi.ng/vectors";
2
- import { RGB_LUMINANCE_REC709, RGB_LUMINANCE_REC601 } from "../api/constants";
1
+ import { dot3 } from "@thi.ng/vectors/dot";
2
+ import { RGB_LUMINANCE_REC709, RGB_LUMINANCE_REC601 } from "./api/constants.js";
3
3
  /**
4
4
  * Computes RGB luminance, optionally using provided weights (by default:
5
5
  * {@link RGB_LUMINANCE_REC709}).
@@ -1,5 +1,4 @@
1
- import { MultiFn1 } from "@thi.ng/defmulti";
2
- import type { MaybeColor } from "../api";
1
+ import type { MaybeColor } from "./api.js";
3
2
  /**
4
3
  * Multi-method to compute relative luminance from any supported input color
5
4
  * format.
@@ -10,5 +9,5 @@ import type { MaybeColor } from "../api";
10
9
  * unless a direct implementation is available, colors will first be converted
11
10
  * to linear RGB.
12
11
  */
13
- export declare const luminance: MultiFn1<MaybeColor, number>;
12
+ export declare const luminance: import("@thi.ng/defmulti/api").MultiFn1<MaybeColor, number>;
14
13
  //# sourceMappingURL=luminance.d.ts.map
@@ -1,6 +1,6 @@
1
- import { DEFAULT, defmulti } from "@thi.ng/defmulti";
2
- import { rgb } from "../rgb/rgb";
3
- import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "./luminance-rgb";
1
+ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { rgb } from "./rgb/rgb.js";
3
+ import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "./luminance-rgb.js";
4
4
  /**
5
5
  * Multi-method to compute relative luminance from any supported input color
6
6
  * format.
@@ -11,8 +11,7 @@ import { luminanceAbgr32, luminanceArgb32, luminanceRgb, luminanceSrgb, } from "
11
11
  * unless a direct implementation is available, colors will first be converted
12
12
  * to linear RGB.
13
13
  */
14
- export const luminance = defmulti((col) => col.mode);
15
- luminance.addAll({
14
+ export const luminance = defmulti((col) => col.mode, { lch: "lab", oklab: "lab", ycc: "lab", xyy: "hcy" }, {
16
15
  argb32: luminanceArgb32,
17
16
  abgr32: luminanceAbgr32,
18
17
  hcy: (x) => x[2],
@@ -20,9 +19,5 @@ luminance.addAll({
20
19
  rgb: luminanceRgb,
21
20
  srgb: luminanceSrgb,
22
21
  xyz: (x) => x[1],
22
+ [DEFAULT]: (x) => luminanceRgb(rgb(x)),
23
23
  });
24
- luminance.isa("lch", "lab");
25
- luminance.isa("oklab", "lab");
26
- luminance.isa("ycc", "lab");
27
- luminance.isa("xyy", "hcy");
28
- luminance.add(DEFAULT, (x) => luminanceRgb(rgb(x)));
@@ -1,5 +1,5 @@
1
1
  import type { FnN3, FnU4 } from "@thi.ng/api";
2
- import type { ColorMixFn, TypedColor } from "../api";
2
+ import type { ColorMixFn, TypedColor } from "./api.js";
3
3
  /**
4
4
  * HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
5
5
  * returns new {@link ColorMixFn}.
@@ -67,5 +67,5 @@ export declare const mixNNNN: ColorMixFn;
67
67
  * @param b -
68
68
  * @param t -
69
69
  */
70
- export declare const mix: import("@thi.ng/defmulti").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
70
+ export declare const mix: import("@thi.ng/defmulti/api").MultiFn4<import("@thi.ng/vectors").Vec | null, TypedColor<any>, TypedColor<any>, number, import("@thi.ng/vectors").Vec>;
71
71
  //# sourceMappingURL=mix.d.ts.map
@@ -1,6 +1,8 @@
1
- import { DEFAULT, defmulti } from "@thi.ng/defmulti";
2
- import { fract, mix as $mix } from "@thi.ng/math";
3
- import { mixN4, setC4 } from "@thi.ng/vectors";
1
+ import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { mix as $mix } from "@thi.ng/math/mix";
3
+ import { fract } from "@thi.ng/math/prec";
4
+ import { mixN4 } from "@thi.ng/vectors/mixn";
5
+ import { setC4 } from "@thi.ng/vectors/setc";
4
6
  /**
5
7
  * HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
6
8
  * returns new {@link ColorMixFn}.
@@ -79,12 +81,11 @@ export const mixNNNN = mixN4;
79
81
  * @param b -
80
82
  * @param t -
81
83
  */
82
- export const mix = defmulti((_, a) => a.mode);
83
- mix.add(DEFAULT, mixN4);
84
- mix.addAll({
84
+ export const mix = defmulti((_, a) => a.mode, {}, {
85
85
  hcy: mixHNNN,
86
86
  hsi: mixHNNN,
87
87
  hsl: mixHNNN,
88
88
  hsv: mixHNNN,
89
89
  lch: mixNNHN,
90
+ [DEFAULT]: mixN4,
90
91
  });
@@ -1,4 +1,4 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  /**
3
3
  * @remarks
4
4
  * Reference: https://bottosson.github.io/posts/oklab/
@@ -1,14 +1,7 @@
1
- import { mulV33 } from "../internal/matrix-ops";
1
+ import { __mulV33 } from "../internal/matrix-ops.js";
2
2
  const LMS_CONE = [
3
- 4.0767245293,
4
- -1.2681437731,
5
- -0.0041119885,
6
- -3.3072168827,
7
- 2.6093323231,
8
- -0.7034763098,
9
- 0.2307590544,
10
- -0.341134429,
11
- 1.7068625689,
3
+ 4.0767245293, -1.2681437731, -0.0041119885, -3.3072168827, 2.6093323231,
4
+ -0.7034763098, 0.2307590544, -0.341134429, 1.7068625689,
12
5
  ];
13
6
  /**
14
7
  * @remarks
@@ -17,7 +10,7 @@ const LMS_CONE = [
17
10
  * @param out
18
11
  * @param src
19
12
  */
20
- export const oklabRgb = (out, { 0: l, 1: a, 2: b, 3: alpha }) => mulV33(out, LMS_CONE, [
13
+ export const oklabRgb = (out, { 0: l, 1: a, 2: b, 3: alpha }) => __mulV33(out, LMS_CONE, [
21
14
  (l + 0.3963377774 * a + 0.2158037573 * b) ** 3,
22
15
  (l - 0.1055613458 * a - 0.0638541728 * b) ** 3,
23
16
  (l - 0.0894841775 * a - 1.291485548 * b) ** 3,
@@ -1,3 +1,3 @@
1
- import type { ColorOp } from "../api";
1
+ import type { ColorOp } from "../api.js";
2
2
  export declare const oklabXyzD65: ColorOp;
3
3
  //# sourceMappingURL=oklab-xyz.d.ts.map
@@ -1,27 +1,15 @@
1
- import { powN3 } from "@thi.ng/vectors";
2
- import { mulV33 } from "../internal/matrix-ops";
1
+ import { powN3 } from "@thi.ng/vectors/pown";
2
+ import { __mulV33 } from "../internal/matrix-ops.js";
3
3
  // inverted version of OKLAB_M1
4
4
  const M1I = [
5
- 1.2270138511035211,
6
- -0.04058017842328059,
7
- -0.0763812845057069,
8
- -0.5577999806518222,
9
- 1.1122568696168302,
10
- -0.4214819784180127,
11
- 0.28125614896646783,
12
- -0.07167667866560119,
13
- 1.586163220440795,
5
+ 1.2270138511035211, -0.04058017842328059, -0.0763812845057069,
6
+ -0.5577999806518222, 1.1122568696168302, -0.4214819784180127,
7
+ 0.28125614896646783, -0.07167667866560119, 1.586163220440795,
14
8
  ];
15
9
  // inverted version of OKLAB_M2
16
10
  const M2I = [
17
- 0.9999999984505198,
18
- 1.0000000088817607,
19
- 1.0000000546724108,
20
- 0.3963377921737678,
21
- -0.10556134232365633,
22
- -0.08948418209496575,
23
- 0.21580375806075877,
24
- -0.06385417477170588,
25
- -1.2914855378640917,
11
+ 0.9999999984505198, 1.0000000088817607, 1.0000000546724108,
12
+ 0.3963377921737678, -0.10556134232365633, -0.08948418209496575,
13
+ 0.21580375806075877, -0.06385417477170588, -1.2914855378640917,
26
14
  ];
27
- export const oklabXyzD65 = (out, src) => mulV33(null, M1I, powN3(null, mulV33(out, M2I, src), 3));
15
+ export const oklabXyzD65 = (out, src) => __mulV33(null, M1I, powN3(null, __mulV33(out, M2I, src), 3));
package/oklab/oklab.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 Oklab implements TypedColor<Oklab> {
5
5
  buf: NumericArray;
6
6
  offset: number;
package/oklab/oklab.js CHANGED
@@ -1,9 +1,10 @@
1
- import { defColor } from "../defcolor";
2
- import { lchLab } from "../lab/lab-lch";
3
- import { labXyz, labXyzD65 } from "../lab/lab-xyz";
4
- import { rgbOklab } from "../rgb/rgb-oklab";
5
- import { xyzOklab } from "../xyz/xyz-oklab";
6
- import { xyzXyzD50_65 } from "../xyz/xyz-xyz";
1
+ import { defColor } from "../defcolor.js";
2
+ import { lchLab } from "../lab/lab-lch.js";
3
+ import { labXyz, labXyzD65 } from "../lab/lab-xyz.js";
4
+ import { rgbOklab } from "../rgb/rgb-oklab.js";
5
+ import { xyzOklab } from "../xyz/xyz-oklab.js";
6
+ import { xyzXyzD50_65 } from "../xyz/xyz-xyz.js";
7
+ import { oklabRgb } from "./oklab-rgb.js";
7
8
  /**
8
9
  * Oklab color type. Conversions assume {@link D65} white point).
9
10
  *
@@ -25,4 +26,5 @@ export const oklab = defColor({
25
26
  xyz50: [xyzXyzD50_65, xyzOklab],
26
27
  xyz65: xyzOklab,
27
28
  },
29
+ toRgb: oklabRgb,
28
30
  });