@woosh/meep-engine 2.100.0 → 2.100.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/build/meep.cjs +574 -19
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +574 -19
  4. package/package.json +1 -1
  5. package/src/core/color/Color.d.ts.map +1 -1
  6. package/src/core/color/Color.js +39 -8
  7. package/src/core/color/oklab/Okhsv.spec.d.ts +2 -0
  8. package/src/core/color/oklab/Okhsv.spec.d.ts.map +1 -0
  9. package/src/core/color/oklab/Okhsv.spec.js +17 -0
  10. package/src/core/color/oklab/XYZ.spec.js +2 -2
  11. package/src/core/color/oklab/compute_max_saturation.d.ts +11 -0
  12. package/src/core/color/oklab/compute_max_saturation.d.ts.map +1 -0
  13. package/src/core/color/oklab/compute_max_saturation.js +84 -0
  14. package/src/core/color/oklab/find_cusp.d.ts +10 -0
  15. package/src/core/color/oklab/find_cusp.d.ts.map +1 -0
  16. package/src/core/color/oklab/find_cusp.js +27 -0
  17. package/src/core/color/oklab/find_gamut_intersection.d.ts +15 -0
  18. package/src/core/color/oklab/find_gamut_intersection.d.ts.map +1 -0
  19. package/src/core/color/oklab/find_gamut_intersection.js +101 -0
  20. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts +9 -0
  21. package/src/core/color/oklab/linear_srgb_to_okhsv.d.ts.map +1 -0
  22. package/src/core/color/oklab/linear_srgb_to_okhsv.js +74 -0
  23. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts +9 -0
  24. package/src/core/color/oklab/linear_srgb_to_oklab.d.ts.map +1 -0
  25. package/src/core/color/oklab/linear_srgb_to_oklab.js +20 -0
  26. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts +9 -0
  27. package/src/core/color/oklab/okhsv_to_linear_srgb.d.ts.map +1 -0
  28. package/src/core/color/oklab/okhsv_to_linear_srgb.js +59 -0
  29. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts +10 -0
  30. package/src/core/color/oklab/oklab_to_linear_srgb.d.ts.map +1 -0
  31. package/src/core/color/oklab/oklab_to_linear_srgb.js +21 -0
  32. package/src/core/color/oklab/oklab_to_xyz.d.ts +5 -2
  33. package/src/core/color/oklab/oklab_to_xyz.d.ts.map +1 -1
  34. package/src/core/color/oklab/oklab_to_xyz.js +5 -5
  35. package/src/core/color/oklab/oklab_to_xyz.spec.js +4 -4
  36. package/src/core/color/oklab/toe.d.ts +13 -0
  37. package/src/core/color/oklab/toe.d.ts.map +1 -0
  38. package/src/core/color/oklab/toe.js +22 -0
  39. package/src/core/color/oklab/xyz_to_oklab.d.ts +5 -2
  40. package/src/core/color/oklab/xyz_to_oklab.d.ts.map +1 -1
  41. package/src/core/color/oklab/xyz_to_oklab.js +5 -5
  42. package/src/core/color/oklab/xyz_to_oklab.spec.js +4 -4
  43. package/src/engine/animation/async/prototypeAsyncAnimation.d.ts +2 -0
  44. package/src/engine/animation/async/prototypeAsyncAnimation.d.ts.map +1 -0
  45. package/src/engine/animation/async/prototypeAsyncAnimation.js +344 -0
  46. package/src/engine/asset/AssetManager.d.ts.map +1 -1
  47. package/src/engine/asset/AssetManager.js +17 -0
  48. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  49. package/src/engine/asset/loaders/ArrayBufferLoader.js +22 -2
  50. package/src/engine/ecs/Entity.d.ts.map +1 -1
  51. package/src/engine/ecs/Entity.js +1 -0
  52. package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
  53. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +3 -3
  54. package/src/engine/input/ecs/systems/InputControllerSystem.d.ts.map +1 -1
  55. package/src/engine/input/ecs/systems/InputControllerSystem.js +4 -8
  56. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts +46 -0
  57. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.d.ts.map +1 -0
  58. package/src/engine/intelligence/behavior/util/RandomDelayBehavior.js +85 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../../../src/core/color/Color.js"],"names":[],"mappings":"AAeA;;GAEG;AACH;IAwiBI;;;;;;OAMG;IACH,kBALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,KAAK,CAIjB;IAED;;;;;;OAMG;IACH,kBALW,MAAM,KACN,MAAM,KACN,MAAM,GACL,KAAK,CAQhB;IAGD;;;;OAIG;IACH,kBAHW,MAAM,GACL,KAAK,CAQhB;IAED;;;;OAIG;IACH,kCAHW,KAAK,UACL,KAAK,QAIf;IAED;;;;OAIG;IACH,kCAHW,KAAK,UACL,KAAK,QAIf;IA/lBD;;;;;;OAMG;IACH,gBALW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAkChB;IA/BG;;;;OAIG;IACH,GAFU,MAAM,CAEN;IACV;;;;OAIG;IACH,GAFU,MAAM,CAEN;IACV;;;;OAIG;IACH,GAFU,MAAM,CAEN;IAEV;;;;OAIG;IACH,GAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,oBAFU,OAAO,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,CAAC,CAE5C;IAWjC;;;OAGG;IACH,mBAEC;IAdD;;;OAGG;IACH,gBAEC;IAkBD;;;OAGG;IACH,mBAEC;IAdD;;;OAGG;IACH,gBAEC;IAkBD;;;OAGG;IACH,mBAEC;IAdD;;;OAGG;IACH,gBAEC;IAkBD;;;OAGG;IACH,mBAEC;IAdD;;;OAGG;IACH,gBAEC;IAUD;;;OAGG;IACH,qBAEC;IAED;;;;;OAKG;IACH,UAJW,MAAM,KACN,MAAM,KACN,MAAM,QAKhB;IAED;;;OAGG;IACH,QAFW,MAAM,QAIhB;IAED;;;;;;OAMG;IACH,OALW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAwBhB;IAED;;;;;OAKG;IACH,UAJW,MAAM,KACN,MAAM,KACN,MAAM,QAsBhB;IAED;;;;;OAKG;IACH,UAJW,MAAM,KACN,MAAM,KACN,MAAM,QAqDhB;IAED;;;;;;;OAOG;IACH,UALW,MAAM,KACN,MAAM,KACN,MAAM,QAyDhB;IAED;;;;;OAKG;IACH,UAJW,MAAM,KACN,MAAM,KACN,MAAM,QA6ChB;IAED;;;OAGG;IACH,oBAFY,MAAM,CAIjB;IAED;;;;MAEC;IAED;;;OAGG;IACH,UAFa,MAAM,CAKlB;IAED;;;OAGG;IACH,gBAFW,MAAM,QAUhB;IAED;;;;OAIG;IACH,SAFa,MAAM,CAQlB;IAED;;;OAGG;IACH,mBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,cAFW,KAAK,WAOf;IAED;;;OAGG;IACH,YAFW,KAAK,QAKf;IAED;;;OAGG;IACH,SAFa,KAAK,CAQjB;IAED;;;OAGG;IACH,QAFa,MAAM,CAIlB;IAED;;;;;aAGC;IAED;;;;;MAOC;IAWD;;;;OAIG;IACH,0BAHW,MAAM,EAAE,sBACR,MAAM,QAOhB;IAED;;;OAGG;IACH,2CAKC;IAED;;;OAGG;IACH,6CAQC;IAED;;;;OAIG;IACH,WAHW,MAAM,GACJ,IAAI,CAYhB;IAED;;;;;OAKG;IACH,cAJW,KAAK,KACL,KAAK,KACL,MAAM,QAOhB;IA1ED,sDAOC;CA8HJ;;aAIS,SAAS,KAAK,CAAC;eAMf,SAAS,KAAK,CAAC;cAMf,SAAS,KAAK,CAAC;gBAMf,SAAS,KAAK,CAAC;cAMf,SAAS,KAAK,CAAC;iBAMf,SAAS,KAAK,CAAC;eAMf,SAAS,KAAK,CAAC;eAMf,SAAS,KAAK,CAAC;qBAMf,SAAS,KAAK,CAAC;;mBArqBN,4BAA4B"}
1
+ {"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../../../src/core/color/Color.js"],"names":[],"mappings":"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"}
@@ -1,5 +1,6 @@
1
1
  import { assert } from "../assert.js";
2
2
  import { float2uint8 } from "../binary/float2uint8.js";
3
+ import { uint82float } from "../binary/uint82float.js";
3
4
  import Signal from "../events/signal/Signal.js";
4
5
  import { clamp01 } from "../math/clamp01.js";
5
6
  import { lerp } from "../math/lerp.js";
@@ -14,14 +15,15 @@ import { linear_to_sRGB } from "./sRGB/linear_to_sRGB.js";
14
15
  import { sRGB_to_linear } from "./sRGB/sRGB_to_linear.js";
15
16
 
16
17
  /**
18
+ * @extends {Array.<number>}
17
19
  * @class
18
20
  */
19
21
  export class Color {
20
22
  /**
21
23
  *
22
- * @param {number} r value from 0 to 1
23
- * @param {number} g value from 0 to 1
24
- * @param {number} b value from 0 to 1
24
+ * @param {number} [r] Red from 0 to 1
25
+ * @param {number} [g] Green from 0 to 1
26
+ * @param {number} [b] Blue from 0 to 1
25
27
  * @param {number} [a] value from 0 to 1 Alpha channel (transparency)
26
28
  */
27
29
  constructor(r = 0, g = 0, b = 0, a = 1) {
@@ -141,6 +143,20 @@ export class Color {
141
143
  this.set(r, g, b, this.a);
142
144
  }
143
145
 
146
+ /**
147
+ *
148
+ * @param {number} r
149
+ * @param {number} g
150
+ * @param {number} b
151
+ */
152
+ setRGBUint8(r, g, b) {
153
+ this.setRGB(
154
+ uint82float(r),
155
+ uint82float(g),
156
+ uint82float(b),
157
+ )
158
+ }
159
+
144
160
  /**
145
161
  * set alpha
146
162
  * @param {number} a
@@ -167,11 +183,28 @@ export class Color {
167
183
  assert.notNaN(b, 'b');
168
184
  assert.notNaN(a, 'a');
169
185
 
186
+ assert.isFiniteNumber(r, 'r');
187
+ assert.isFiniteNumber(g, 'g');
188
+ assert.isFiniteNumber(b, 'b');
189
+ assert.isFiniteNumber(a, 'a');
190
+
191
+ // remember old values
170
192
  const _r = this.r;
171
193
  const _g = this.g;
172
194
  const _b = this.b;
173
195
  const _a = this.a;
174
196
 
197
+ if (
198
+ _r === r
199
+ && _g === g
200
+ && _b === b
201
+ && _a === a
202
+ ) {
203
+ // no change
204
+ return;
205
+ }
206
+
207
+ // set new values
175
208
  this.r = r;
176
209
  this.g = g;
177
210
  this.b = b;
@@ -414,7 +447,7 @@ export class Color {
414
447
  const g = (value >> 8) & 0xFF;
415
448
  const b = (value) & 0xFF;
416
449
 
417
- this.setRGB(r / 255, g / 255, b / 255);
450
+ this.setRGBUint8(r, g, b);
418
451
  }
419
452
 
420
453
  /**
@@ -479,8 +512,7 @@ export class Color {
479
512
  }
480
513
 
481
514
  fromJSON({ r, g, b, a = 1 }) {
482
- this.setRGB(r, g, b);
483
- this.a = a;
515
+ this.set(r, g, b, a);
484
516
  }
485
517
 
486
518
  toJSON() {
@@ -534,8 +566,7 @@ export class Color {
534
566
  const b = buffer.readFloat32();
535
567
  const a = buffer.readFloat32();
536
568
 
537
- this.setRGB(r, g, b);
538
- this.a = a;
569
+ this.set(r, g, b, a);
539
570
  }
540
571
 
541
572
  /**
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Okhsv.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Okhsv.spec.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/Okhsv.spec.js"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { linear_srgb_to_okhsv } from "./linear_srgb_to_okhsv.js";
2
+ import { okhsv_to_linear_srgb } from "./okhsv_to_linear_srgb.js";
3
+
4
+ test("to/from consistency", () => {
5
+
6
+ const out = [];
7
+
8
+ const sample = [0.123, 0.345, 0.457];
9
+
10
+ okhsv_to_linear_srgb(out, ...sample);
11
+
12
+ linear_srgb_to_okhsv(out, ...out);
13
+
14
+ expect(out[0]).toBeCloseTo(sample[0]);
15
+ expect(out[1]).toBeCloseTo(sample[1]);
16
+ expect(out[2]).toBeCloseTo(sample[2]);
17
+ });
@@ -7,9 +7,9 @@ test("to/from consistency", () => {
7
7
 
8
8
  const sample = [0.123, 0.345, 0.457];
9
9
 
10
- oklab_to_xyz(sample, out);
10
+ oklab_to_xyz(out, ...sample);
11
11
 
12
- xyz_to_oklab(out, out);
12
+ xyz_to_oklab(out, ...out);
13
13
 
14
14
  expect(out[0]).toBeCloseTo(sample[0]);
15
15
  expect(out[1]).toBeCloseTo(sample[1]);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Finds the maximum saturation possible for a given hue that fits in sRGB
3
+ * Saturation here is defined as S = C/L
4
+ * a and b must be normalized so a^2 + b^2 == 1
5
+ * @copyright "Company Named Limited" 2023
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @returns {number}
9
+ */
10
+ export function compute_max_saturation(a: number, b: number): number;
11
+ //# sourceMappingURL=compute_max_saturation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute_max_saturation.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/compute_max_saturation.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,0CAJW,MAAM,KACN,MAAM,GACJ,MAAM,CA4ElB"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Finds the maximum saturation possible for a given hue that fits in sRGB
3
+ * Saturation here is defined as S = C/L
4
+ * a and b must be normalized so a^2 + b^2 == 1
5
+ * @copyright "Company Named Limited" 2023
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @returns {number}
9
+ */
10
+ export function compute_max_saturation(a, b) {
11
+ // Max saturation will be when one of r, g or b goes below zero.
12
+
13
+ // Select different coefficients depending on which component goes below zero first
14
+ let k0, k1, k2, k3, k4, wl, wm, ws;
15
+
16
+ if (-1.88170328 * a - 0.80936493 * b > 1) {
17
+ // Red component
18
+ k0 = +1.19086277;
19
+ k1 = +1.76576728;
20
+ k2 = +0.59662641;
21
+ k3 = +0.75515197;
22
+ k4 = +0.56771245;
23
+ wl = +4.0767416621;
24
+ wm = -3.3077115913;
25
+ ws = +0.2309699292;
26
+ } else if (1.81444104 * a - 1.19445276 * b > 1) {
27
+ // Green component
28
+ k0 = +0.73956515;
29
+ k1 = -0.45954404;
30
+ k2 = +0.08285427;
31
+ k3 = +0.12541070;
32
+ k4 = +0.14503204;
33
+ wl = -1.2684380046;
34
+ wm = +2.6097574011;
35
+ ws = -0.3413193965;
36
+ } else {
37
+ // Blue component
38
+ k0 = +1.35733652;
39
+ k1 = -0.00915799;
40
+ k2 = -1.15130210;
41
+ k3 = -0.50559606;
42
+ k4 = +0.00692167;
43
+ wl = -0.0041960863;
44
+ wm = -0.7034186147;
45
+ ws = +1.7076147010;
46
+ }
47
+
48
+ // Approximate max saturation using a polynomial:
49
+ let S = k0 + k1 * a + k2 * b + k3 * a * a + k4 * a * b;
50
+
51
+ // Do one step of Halley's method to get closer
52
+ // this gives an error less than 10e6, except for some blue hues where the dS/dh is close to infinite
53
+ // this should be sufficient for most applications, otherwise do two/three steps
54
+
55
+ const k_l = +0.3963377774 * a + 0.2158037573 * b;
56
+ const k_m = -0.1055613458 * a - 0.0638541728 * b;
57
+ const k_s = -0.0894841775 * a - 1.2914855480 * b;
58
+
59
+ {
60
+ const l_ = 1. + S * k_l;
61
+ const m_ = 1. + S * k_m;
62
+ const s_ = 1. + S * k_s;
63
+
64
+ const l = l_ * l_ * l_;
65
+ const m = m_ * m_ * m_;
66
+ const s = s_ * s_ * s_;
67
+
68
+ const l_dS = 3. * k_l * l_ * l_;
69
+ const m_dS = 3. * k_m * m_ * m_;
70
+ const s_dS = 3. * k_s * s_ * s_;
71
+
72
+ const l_dS2 = 6. * k_l * k_l * l_;
73
+ const m_dS2 = 6. * k_m * k_m * m_;
74
+ const s_dS2 = 6. * k_s * k_s * s_;
75
+
76
+ const f = wl * l + wm * m + ws * s;
77
+ const f1 = wl * l_dS + wm * m_dS + ws * s_dS;
78
+ const f2 = wl * l_dS2 + wm * m_dS2 + ws * s_dS2;
79
+
80
+ S = S - f * f1 / (f1 * f1 - 0.5 * f * f2);
81
+ }
82
+
83
+ return S;
84
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * finds L_cusp and C_cusp for a given hue
3
+ * a and b must be normalized so a^2 + b^2 == 1
4
+ * @copyright "Company Named Limited" 2023
5
+ * @param {number[]} output [L, C]
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function find_cusp(output: number[], a: number, b: number): void;
10
+ //# sourceMappingURL=find_cusp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find_cusp.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/find_cusp.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,kCAJW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,QAahB"}
@@ -0,0 +1,27 @@
1
+ import { max3 } from "../../math/max3.js";
2
+ import { compute_max_saturation } from "./compute_max_saturation.js";
3
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
4
+
5
+ const rgb_at_max = [0, 0, 0];
6
+
7
+
8
+ /**
9
+ * finds L_cusp and C_cusp for a given hue
10
+ * a and b must be normalized so a^2 + b^2 == 1
11
+ * @copyright "Company Named Limited" 2023
12
+ * @param {number[]} output [L, C]
13
+ * @param {number} a
14
+ * @param {number} b
15
+ */
16
+ export function find_cusp(output, a, b) {
17
+ // First, find the maximum saturation (saturation S = C/L)
18
+ const S_cusp = compute_max_saturation(a, b);
19
+
20
+ // Convert to linear sRGB to find the first point where at least one of r,g or b >= 1:
21
+ oklab_to_linear_srgb(rgb_at_max, 1, S_cusp * a, S_cusp * b);
22
+ const L_cusp = Math.cbrt(1. / max3(rgb_at_max[0], rgb_at_max[1], rgb_at_max[2]));
23
+ const C_cusp = L_cusp * S_cusp;
24
+
25
+ output[0] = L_cusp;
26
+ output[1] = C_cusp;
27
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Finds intersection of the line defined by
3
+ * L = L0 * (1 - t) + t * L1;
4
+ * C = t * C1;
5
+ * a and b must be normalized so a^2 + b^2 == 1
6
+ * @copyright "Company Named Limited" 2023
7
+ * @param {number} a
8
+ * @param {number} b
9
+ * @param {number} L1
10
+ * @param {number} C1
11
+ * @param {number} L0
12
+ * @returns {number}
13
+ */
14
+ export function find_gamut_intersection(a: number, b: number, L1: number, C1: number, L0: number): number;
15
+ //# sourceMappingURL=find_gamut_intersection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find_gamut_intersection.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/find_gamut_intersection.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,2CAPW,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACJ,MAAM,CAoFlB"}
@@ -0,0 +1,101 @@
1
+ import { min3 } from "../../math/min3.js";
2
+ import { find_cusp } from "./find_cusp.js";
3
+
4
+ const cusp = [0, 0];
5
+
6
+ /**
7
+ * Finds intersection of the line defined by
8
+ * L = L0 * (1 - t) + t * L1;
9
+ * C = t * C1;
10
+ * a and b must be normalized so a^2 + b^2 == 1
11
+ * @copyright "Company Named Limited" 2023
12
+ * @param {number} a
13
+ * @param {number} b
14
+ * @param {number} L1
15
+ * @param {number} C1
16
+ * @param {number} L0
17
+ * @returns {number}
18
+ */
19
+ export function find_gamut_intersection(a, b, L1, C1, L0) {
20
+ // Find the cusp of the gamut triangle
21
+ find_cusp(cusp, a, b);
22
+
23
+ // Find the intersection for upper and lower half seprately
24
+ let t;
25
+ if (((L1 - L0) * cusp[1] - (cusp[0] - L0) * C1) <= 0.) {
26
+ // Lower half
27
+
28
+ t = cusp[1] * L0 / (C1 * cusp[0] + cusp[1] * (L0 - L1));
29
+ } else {
30
+ // Upper half
31
+
32
+ // First intersect with triangle
33
+ t = cusp[1] * (L0 - 1.) / (C1 * (cusp[0] - 1.) + cusp[1] * (L0 - L1));
34
+
35
+ // Then one step of Halley's method
36
+ {
37
+ const dL = L1 - L0;
38
+ const dC = C1;
39
+
40
+ const k_l = +0.3963377774 * a + 0.2158037573 * b;
41
+ const k_m = -0.1055613458 * a - 0.0638541728 * b;
42
+ const k_s = -0.0894841775 * a - 1.2914855480 * b;
43
+
44
+ const l_dt = dL + dC * k_l;
45
+ const m_dt = dL + dC * k_m;
46
+ const s_dt = dL + dC * k_s;
47
+
48
+
49
+ // If higher accuracy is required, 2 or 3 iterations of the following block can be used:
50
+ {
51
+ const L = L0 * (1 - t) + t * L1;
52
+ const C = t * C1;
53
+
54
+ const l_ = L + C * k_l;
55
+ const m_ = L + C * k_m;
56
+ const s_ = L + C * k_s;
57
+
58
+ const l = l_ * l_ * l_;
59
+ const m = m_ * m_ * m_;
60
+ const s = s_ * s_ * s_;
61
+
62
+ const ldt = 3 * l_dt * l_ * l_;
63
+ const mdt = 3 * m_dt * m_ * m_;
64
+ const sdt = 3 * s_dt * s_ * s_;
65
+
66
+ const ldt2 = 6 * l_dt * l_dt * l_;
67
+ const mdt2 = 6 * m_dt * m_dt * m_;
68
+ const sdt2 = 6 * s_dt * s_dt * s_;
69
+
70
+ const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s - 1;
71
+ const r1 = 4.0767416621 * ldt - 3.3077115913 * mdt + 0.2309699292 * sdt;
72
+ const r2 = 4.0767416621 * ldt2 - 3.3077115913 * mdt2 + 0.2309699292 * sdt2;
73
+
74
+ const u_r = r1 / (r1 * r1 - 0.5 * r * r2);
75
+ let t_r = -r * u_r;
76
+
77
+ const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s - 1;
78
+ const g1 = -1.2684380046 * ldt + 2.6097574011 * mdt - 0.3413193965 * sdt;
79
+ const g2 = -1.2684380046 * ldt2 + 2.6097574011 * mdt2 - 0.3413193965 * sdt2;
80
+
81
+ const u_g = g1 / (g1 * g1 - 0.5 * g * g2);
82
+ let t_g = -g * u_g;
83
+
84
+ const b = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s - 1;
85
+ const b1 = -0.0041960863 * ldt - 0.7034186147 * mdt + 1.7076147010 * sdt;
86
+ const b2 = -0.0041960863 * ldt2 - 0.7034186147 * mdt2 + 1.7076147010 * sdt2;
87
+
88
+ const u_b = b1 / (b1 * b1 - 0.5 * b * b2);
89
+ let t_b = -b * u_b;
90
+
91
+ t_r = u_r >= 0 ? t_r : Number.MAX_VALUE;
92
+ t_g = u_g >= 0 ? t_g : Number.MAX_VALUE;
93
+ t_b = u_b >= 0 ? t_b : Number.MAX_VALUE;
94
+
95
+ t += min3(t_r, t_g, t_b);
96
+ }
97
+ }
98
+ }
99
+
100
+ return t;
101
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_okhsv(output: number[], r: number, g: number, b: number): void;
9
+ //# sourceMappingURL=linear_srgb_to_okhsv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear_srgb_to_okhsv.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/linear_srgb_to_okhsv.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAkDhB"}
@@ -0,0 +1,74 @@
1
+ import { find_cusp } from "./find_cusp.js";
2
+ import { linear_srgb_to_oklab } from "./linear_srgb_to_oklab.js";
3
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
4
+ import { toe, toe_inv } from "./toe.js";
5
+
6
+ const Lab = [0, 0, 0];
7
+
8
+ /**
9
+ *
10
+ * @type {number[]}
11
+ */
12
+ const cusp = [0, 0];
13
+ /**
14
+ *
15
+ * @type {number[]}
16
+ */
17
+ const rgb_scale = [0, 0, 0];
18
+
19
+ /**
20
+ *
21
+ * @param {number[]} output
22
+ * @param {number} r
23
+ * @param {number} g
24
+ * @param {number} b
25
+ */
26
+ export function linear_srgb_to_okhsv(output, r, g, b) {
27
+
28
+ linear_srgb_to_oklab(Lab, r, g, b)
29
+
30
+ let C = Math.sqrt(Lab[1] * Lab[1] + Lab[2] * Lab[2]);
31
+ const a_ = Lab[1] / C;
32
+ const b_ = Lab[2] / C;
33
+
34
+ let L = Lab[0];
35
+ const h = 0.5 + 0.5 * Math.atan2(-Lab[2], -Lab[1]) / Math.PI;
36
+
37
+ find_cusp(cusp, a_, b_);
38
+
39
+ const S_max = cusp[1] / cusp[0];
40
+ const T_max = cusp[1] / (1 - cusp[0]);
41
+
42
+ const S_0 = 0.5;
43
+ const k = 1 - S_0 / S_max;
44
+
45
+ // first we find L_v, C_v, L_vt and C_vt
46
+
47
+ const t = T_max / (C + L * T_max);
48
+ const L_v = t * L;
49
+ const C_v = t * C;
50
+
51
+ const L_vt = toe_inv(L_v);
52
+ const C_vt = C_v * L_vt / L_v;
53
+
54
+ // we can then use these to invert the step that compensates for the toe and the curved top part of the triangle:
55
+
56
+ oklab_to_linear_srgb(rgb_scale, L_vt, a_ * C_vt, b_ * C_vt);
57
+
58
+ const scale_L = Math.cbrt(1. / Math.max(rgb_scale[0], rgb_scale[1], rgb_scale[2], 0));
59
+
60
+ L = L / scale_L;
61
+ C = C / scale_L;
62
+
63
+ C = C * toe(L) / L;
64
+ L = toe(L);
65
+
66
+ // we can now compute v and s:
67
+
68
+ const v = L / L_v;
69
+ const s = (S_0 + T_max) * C_v / ((T_max * S_0) + T_max * k * C_v);
70
+
71
+ output[0] = h;
72
+ output[1] = s;
73
+ output[2] = v;
74
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_oklab(output: number[], r: number, g: number, b: number): void;
9
+ //# sourceMappingURL=linear_srgb_to_oklab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear_srgb_to_oklab.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/linear_srgb_to_oklab.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAchB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ *
3
+ * @param {number[]} output
4
+ * @param {number} r
5
+ * @param {number} g
6
+ * @param {number} b
7
+ */
8
+ export function linear_srgb_to_oklab(output, r, g, b) {
9
+ const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
10
+ const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
11
+ const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
12
+
13
+ const l_ = Math.cbrt(l);
14
+ const m_ = Math.cbrt(m);
15
+ const s_ = Math.cbrt(s);
16
+
17
+ output[0] = 0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_;
18
+ output[1] = 1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_;
19
+ output[2] = 0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_;
20
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @copyright "Company Named Limited" 2023
3
+ * @param {number[]} output
4
+ * @param {number} h
5
+ * @param {number} s
6
+ * @param {number} v
7
+ */
8
+ export function okhsv_to_linear_srgb(output: number[], h: number, s: number, v: number): void;
9
+ //# sourceMappingURL=okhsv_to_linear_srgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"okhsv_to_linear_srgb.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/okhsv_to_linear_srgb.js"],"names":[],"mappings":"AAeA;;;;;;GAMG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAsChB"}
@@ -0,0 +1,59 @@
1
+ import { find_cusp } from "./find_cusp.js";
2
+ import { oklab_to_linear_srgb } from "./oklab_to_linear_srgb.js";
3
+ import { toe_inv } from "./toe.js";
4
+
5
+ /**
6
+ *
7
+ * @type {number[]}
8
+ */
9
+ const cusp = [0, 0];
10
+ /**
11
+ *
12
+ * @type {number[]}
13
+ */
14
+ const rgb_scale = [0, 0, 0];
15
+
16
+ /**
17
+ * @copyright "Company Named Limited" 2023
18
+ * @param {number[]} output
19
+ * @param {number} h
20
+ * @param {number} s
21
+ * @param {number} v
22
+ */
23
+ export function okhsv_to_linear_srgb(output, h, s, v) {
24
+
25
+ const a_ = Math.cos(2 * Math.PI * h);
26
+ const b_ = Math.sin(2 * Math.PI * h);
27
+
28
+ find_cusp(cusp, a_, b_);
29
+
30
+ const S_max = cusp[1] / cusp[0];
31
+ const T_max = cusp[1] / (1 - cusp[0]);
32
+ const S_0 = 0.5;
33
+ const k = 1 - S_0 / S_max;
34
+
35
+ // first we compute L and V as if the gamut is a perfect triangle:
36
+
37
+ // L, C when v==1:
38
+ const L_v = 1 - s * S_0 / (S_0 + T_max - T_max * k * s);
39
+ const C_v = s * T_max * S_0 / (S_0 + T_max - T_max * k * s);
40
+
41
+ let L = v * L_v;
42
+ let C = v * C_v;
43
+
44
+ // then we compensate for both toe and the curved top part of the triangle:
45
+ const L_vt = toe_inv(L_v);
46
+ const C_vt = C_v * L_vt / L_v;
47
+
48
+ const L_new = toe_inv(L);
49
+ C = C * L_new / L;
50
+ L = L_new;
51
+
52
+ oklab_to_linear_srgb(rgb_scale, L_vt, a_ * C_vt, b_ * C_vt);
53
+ const scale_L = Math.cbrt(1. / Math.max(rgb_scale[0], rgb_scale[1], rgb_scale[2], 0));
54
+
55
+ L = L * scale_L;
56
+ C = C * scale_L;
57
+
58
+ oklab_to_linear_srgb(output, L, C * a_, C * b_);
59
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @copyright "Company Named Limited" 2023
4
+ * @param {number[]} output
5
+ * @param {number} L
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function oklab_to_linear_srgb(output: number[], L: number, a: number, b: number): void;
10
+ //# sourceMappingURL=oklab_to_linear_srgb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oklab_to_linear_srgb.d.ts","sourceRoot":"","sources":["../../../../../src/core/color/oklab/oklab_to_linear_srgb.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,6CALW,MAAM,EAAE,KACR,MAAM,KACN,MAAM,KACN,MAAM,QAchB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @copyright "Company Named Limited" 2023
4
+ * @param {number[]} output
5
+ * @param {number} L
6
+ * @param {number} a
7
+ * @param {number} b
8
+ */
9
+ export function oklab_to_linear_srgb(output, L, a, b) {
10
+ const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
11
+ const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
12
+ const s_ = L - 0.0894841775 * a - 1.2914855480 * b;
13
+
14
+ const l = l_ * l_ * l_;
15
+ const m = m_ * m_ * m_;
16
+ const s = s_ * s_ * s_;
17
+
18
+ output[0] = +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
19
+ output[1] = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
20
+ output[2] = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s;
21
+ }
@@ -2,8 +2,11 @@
2
2
  *
3
3
  * Converts Oklab color space to CIE XYZ.
4
4
  * Oklab as defined by Björn Ottosson
5
- * @param {number[]} input Oklab
5
+ * @copyright "Company Named Limited" 2023
6
6
  * @param {number[]} output XYZ
7
+ * @param {number} L
8
+ * @param {number} a
9
+ * @param {number} b
7
10
  */
8
- export function oklab_to_xyz(input: number[], output: number[]): void;
11
+ export function oklab_to_xyz(output: number[], L: number, a: number, b: number): void;
9
12
  //# sourceMappingURL=oklab_to_xyz.d.ts.map