@thi.ng/shader-ast-stdlib 0.16.8 → 0.16.10

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 (84) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/api.js +0 -1
  4. package/color/aces-film.js +12 -10
  5. package/color/levels.js +80 -66
  6. package/color/linear-srgb.js +11 -21
  7. package/color/luminance.js +4 -6
  8. package/color/porter-duff.js +51 -55
  9. package/color/rgbe.js +13 -15
  10. package/fog/exp.js +5 -9
  11. package/fog/exp2.js +6 -12
  12. package/fog/linear.js +5 -11
  13. package/isec/point.js +19 -13
  14. package/light/lambert.js +8 -29
  15. package/light/trilight.js +17 -15
  16. package/math/additive.js +27 -32
  17. package/math/cartesian.js +21 -24
  18. package/math/clamp.js +7 -19
  19. package/math/cross2.js +7 -19
  20. package/math/dist-chebyshev.js +8 -3
  21. package/math/dist-manhattan.js +8 -3
  22. package/math/easing.js +325 -88
  23. package/math/fit.js +17 -65
  24. package/math/interval.js +23 -24
  25. package/math/magsq.js +8 -3
  26. package/math/maxcomp.js +8 -18
  27. package/math/mincomp.js +8 -18
  28. package/math/mix-cubic.js +32 -10
  29. package/math/mix-quadratic.js +27 -8
  30. package/math/orthogonal.js +15 -21
  31. package/math/osc.js +28 -39
  32. package/math/polar.js +12 -21
  33. package/math/sincos.js +6 -12
  34. package/math/smoother-step.js +26 -24
  35. package/matrix/convert.js +19 -8
  36. package/matrix/lookat.js +20 -18
  37. package/matrix/mvp.js +4 -10
  38. package/matrix/normal.js +4 -8
  39. package/matrix/rotation.js +131 -47
  40. package/noise/curl3.js +30 -18
  41. package/noise/hash.js +126 -197
  42. package/noise/permute.js +11 -5
  43. package/noise/simplex2.js +87 -41
  44. package/noise/simplex3.js +168 -75
  45. package/noise/voronoi2.js +67 -50
  46. package/noise/worley2.js +70 -58
  47. package/package.json +8 -6
  48. package/raymarch/ao.js +25 -24
  49. package/raymarch/direction.js +16 -9
  50. package/raymarch/normal.js +10 -16
  51. package/raymarch/point-at.js +4 -11
  52. package/raymarch/scene.js +35 -44
  53. package/screen/uv.js +23 -30
  54. package/sdf/annular.js +4 -7
  55. package/sdf/arc.js +20 -19
  56. package/sdf/bezier.js +93 -57
  57. package/sdf/box-rounded.js +14 -18
  58. package/sdf/box.js +16 -24
  59. package/sdf/cross.js +23 -44
  60. package/sdf/cylinder.js +9 -14
  61. package/sdf/hex.js +22 -19
  62. package/sdf/isec.js +4 -8
  63. package/sdf/line.js +14 -29
  64. package/sdf/mirror.js +17 -13
  65. package/sdf/plane.js +8 -18
  66. package/sdf/polygon.js +51 -29
  67. package/sdf/polyhedra.js +78 -43
  68. package/sdf/polyline.js +30 -7
  69. package/sdf/repeat-polar.js +13 -17
  70. package/sdf/repeat.js +7 -15
  71. package/sdf/round.js +4 -10
  72. package/sdf/smooth-isec.js +14 -17
  73. package/sdf/smooth-sub.js +14 -17
  74. package/sdf/smooth-union.js +14 -17
  75. package/sdf/sphere.js +8 -16
  76. package/sdf/sub.js +4 -8
  77. package/sdf/torus.js +5 -10
  78. package/sdf/tri.js +30 -20
  79. package/sdf/union.js +7 -18
  80. package/tex/blur.js +53 -70
  81. package/tex/index-coord.js +6 -16
  82. package/tex/index-uv.js +30 -20
  83. package/tex/read-index.js +10 -32
  84. package/viz/function.js +70 -68
package/math/additive.js CHANGED
@@ -6,36 +6,31 @@ import { gensym } from "@thi.ng/shader-ast/ast/idgen";
6
6
  import { FLOAT0, FLOAT05, float } from "@thi.ng/shader-ast/ast/lit";
7
7
  import { add, inc, lt, mul } from "@thi.ng/shader-ast/ast/ops";
8
8
  import { sym } from "@thi.ng/shader-ast/ast/sym";
9
- /**
10
- * Higher order function. Takes an AST type ID, a single-arg scalar
11
- * function `fn`, number of octaves (default: 4) and an optional
12
- * function name. Returns a new function which computes the summed value
13
- * of `fn` over the given number octaves and accepts 3 args:
14
- *
15
- * - position (float)
16
- * - octave shift (float)
17
- * - octave decay (usually 0.5)
18
- *
19
- * For each octave `i` [0..oct), the function is (in principle)
20
- * evaluated as:
21
- *
22
- * n += decay / exp2(i) * fn(pos * exp2(i) + i * shift)
23
- *
24
- * @param fn -
25
- * @param oct -
26
- * @param name -
27
- */
28
- export const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn(F, name, [[type], [type], F], (pos, shift, decay) => {
29
- let n;
30
- let amp;
31
- return [
32
- (n = sym(FLOAT0)),
33
- (amp = sym(FLOAT05)),
34
- forLoop(sym(FLOAT0), (i) => lt(i, float(oct)), inc, (i) => [
35
- assign(n, add(n, mul(amp, fn(add(pos, mul(i, shift)))))),
36
- assign(amp, mul(amp, decay)),
37
- assign(pos, mul(pos, 2)),
38
- ]),
39
- ret(n),
40
- ];
9
+ const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn(F, name, [[type], [type], F], (pos, shift, decay) => {
10
+ let n;
11
+ let amp;
12
+ return [
13
+ n = sym(FLOAT0),
14
+ amp = sym(FLOAT05),
15
+ forLoop(
16
+ sym(FLOAT0),
17
+ (i) => lt(i, float(oct)),
18
+ inc,
19
+ (i) => [
20
+ assign(
21
+ n,
22
+ add(
23
+ n,
24
+ mul(amp, fn(add(pos, mul(i, shift))))
25
+ )
26
+ ),
27
+ assign(amp, mul(amp, decay)),
28
+ assign(pos, mul(pos, 2))
29
+ ]
30
+ ),
31
+ ret(n)
32
+ ];
41
33
  });
34
+ export {
35
+ additive
36
+ };
package/math/cartesian.js CHANGED
@@ -5,28 +5,25 @@ import { mul } from "@thi.ng/shader-ast/ast/ops";
5
5
  import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
6
6
  import { sym } from "@thi.ng/shader-ast/ast/sym";
7
7
  import { cossin } from "./sincos.js";
8
- /**
9
- * Converts 2D polar vector `v`, i.e. `[r,θ]` (angle in radians) to
10
- * cartesian coordinates. See {@link polar2} for reverse operation.
11
- *
12
- * @param v -
13
- */
14
- export const cartesian2 = (v) => mul(cossin($y(v)), $x(v));
15
- /**
16
- * Converts 3D polar/spherical vector `v`, i.e. `[r,θ,ϕ]` (angles in
17
- * radians) to cartesian coordinates. See {@link polar3} for reverse
18
- * operation.
19
- *
20
- * @param v -
21
- */
22
- export const cartesian3 = defn(V3, "cartesian3", [V3], (v) => {
23
- let r;
24
- let t;
25
- let p;
26
- return [
27
- (r = sym($x(v))),
28
- (t = sym(cossin($y(v)))),
29
- (p = sym(cossin($z(v)))),
30
- ret(vec3(mul(mul(r, $x(t)), $x(p)), mul(mul(r, $x(t)), $y(p)), mul(r, $y(t)))),
31
- ];
8
+ const cartesian2 = (v) => mul(cossin($y(v)), $x(v));
9
+ const cartesian3 = defn(V3, "cartesian3", [V3], (v) => {
10
+ let r;
11
+ let t;
12
+ let p;
13
+ return [
14
+ r = sym($x(v)),
15
+ t = sym(cossin($y(v))),
16
+ p = sym(cossin($z(v))),
17
+ ret(
18
+ vec3(
19
+ mul(mul(r, $x(t)), $x(p)),
20
+ mul(mul(r, $x(t)), $y(p)),
21
+ mul(r, $y(t))
22
+ )
23
+ )
24
+ ];
32
25
  });
26
+ export {
27
+ cartesian2,
28
+ cartesian3
29
+ };
package/math/clamp.js CHANGED
@@ -1,22 +1,10 @@
1
1
  import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
2
2
  import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
3
3
  import { clamp } from "@thi.ng/shader-ast/builtin/math";
4
- const __clamp = (min, max) => (x) => x.type === F
5
- ? clamp(x, float(min), float(max))
6
- : x.type === V2
7
- ? clamp(x, vec2(min), vec2(max))
8
- : x.type === V3
9
- ? clamp(x, vec3(min), vec3(max))
10
- : clamp(x, vec4(min), vec4(max));
11
- /**
12
- * Inline function, expands to equivalent of `clamp(x, 0, 1)`.
13
- *
14
- * @param x -
15
- */
16
- export const clamp01 = __clamp(0, 1);
17
- /**
18
- * Inline function, expands to equivalent of `clamp(x, -1, 1)`.
19
- *
20
- * @param x -
21
- */
22
- export const clamp11 = __clamp(-1, 1);
4
+ const __clamp = (min, max) => (x) => x.type === F ? clamp(x, float(min), float(max)) : x.type === V2 ? clamp(x, vec2(min), vec2(max)) : x.type === V3 ? clamp(x, vec3(min), vec3(max)) : clamp(x, vec4(min), vec4(max));
5
+ const clamp01 = __clamp(0, 1);
6
+ const clamp11 = __clamp(-1, 1);
7
+ export {
8
+ clamp01,
9
+ clamp11
10
+ };
package/math/cross2.js CHANGED
@@ -2,23 +2,11 @@ import { F, V2 } from "@thi.ng/shader-ast/api/types";
2
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
3
  import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
4
4
  import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
5
- /**
6
- * Computes 2D "cross product" of given vectors. Also see
7
- * {@link crossC2}.
8
- *
9
- * @param a -
10
- * @param b -
11
- */
12
- export const cross2 = defn(F, "cross2", [V2, V2], (a, b) => [
13
- ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b)))),
5
+ const cross2 = defn(F, "cross2", [V2, V2], (a, b) => [
6
+ ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b))))
14
7
  ]);
15
- /**
16
- * Inline function. Computes 2D cross product of given individual
17
- * components: ax * by - ay * bx
18
- *
19
- * @param ax -
20
- * @param ay -
21
- * @param bx -
22
- * @param by -
23
- */
24
- export const crossC2 = (ax, ay, bx, by) => sub(mul(ax, by), mul(ay, bx));
8
+ const crossC2 = (ax, ay, bx, by) => sub(mul(ax, by), mul(ay, bx));
9
+ export {
10
+ cross2,
11
+ crossC2
12
+ };
@@ -1,6 +1,11 @@
1
1
  import { sub } from "@thi.ng/shader-ast/ast/ops";
2
2
  import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
3
3
  import { abs, max } from "@thi.ng/shader-ast/builtin/math";
4
- export const distChebyshev2 = (a, b) => max(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
5
- export const distChebyshev3 = (a, b) => max(distChebyshev2(a, b), abs(sub($z(a), $z(b))));
6
- export const distChebyshev4 = (a, b) => max(distChebyshev2(a, b), distChebyshev2($(a, "zw"), $(b, "zw")));
4
+ const distChebyshev2 = (a, b) => max(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
5
+ const distChebyshev3 = (a, b) => max(distChebyshev2(a, b), abs(sub($z(a), $z(b))));
6
+ const distChebyshev4 = (a, b) => max(distChebyshev2(a, b), distChebyshev2($(a, "zw"), $(b, "zw")));
7
+ export {
8
+ distChebyshev2,
9
+ distChebyshev3,
10
+ distChebyshev4
11
+ };
@@ -1,6 +1,11 @@
1
1
  import { add, sub } from "@thi.ng/shader-ast/ast/ops";
2
2
  import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
3
3
  import { abs } from "@thi.ng/shader-ast/builtin/math";
4
- export const distManhattan2 = (a, b) => add(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
5
- export const distManhattan3 = (a, b) => add(distManhattan2(a, b), abs(sub($z(a), $z(b))));
6
- export const distManhattan4 = (a, b) => add(distManhattan2(a, b), distManhattan2($(a, "zw"), $(b, "zw")));
4
+ const distManhattan2 = (a, b) => add(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
5
+ const distManhattan3 = (a, b) => add(distManhattan2(a, b), abs(sub($z(a), $z(b))));
6
+ const distManhattan4 = (a, b) => add(distManhattan2(a, b), distManhattan2($(a, "zw"), $(b, "zw")));
7
+ export {
8
+ distManhattan2,
9
+ distManhattan3,
10
+ distManhattan4
11
+ };
package/math/easing.js CHANGED
@@ -1,117 +1,354 @@
1
1
  import { F } from "@thi.ng/shader-ast/api/types";
2
2
  import { ifThen, ternary } from "@thi.ng/shader-ast/ast/controlflow";
3
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
4
- import { FLOAT0, FLOAT05, FLOAT1, FLOAT2, HALF_PI, PI, TAU, float, } from "@thi.ng/shader-ast/ast/lit";
5
- import { add, div, eq, gte, lt, lte, madd, mul, neg, reciprocal, sub, } from "@thi.ng/shader-ast/ast/ops";
4
+ import {
5
+ FLOAT0,
6
+ FLOAT05,
7
+ FLOAT1,
8
+ FLOAT2,
9
+ HALF_PI,
10
+ PI,
11
+ TAU,
12
+ float
13
+ } from "@thi.ng/shader-ast/ast/lit";
14
+ import {
15
+ add,
16
+ div,
17
+ eq,
18
+ gte,
19
+ lt,
20
+ lte,
21
+ madd,
22
+ mul,
23
+ neg,
24
+ reciprocal,
25
+ sub
26
+ } from "@thi.ng/shader-ast/ast/ops";
6
27
  import { cos, exp2, pow, sin, sqrt } from "@thi.ng/shader-ast/builtin/math";
7
- /**
8
- * Higher order helper function to wrap a given easing function body as proper
9
- * shader-ast function.
10
- *
11
- * @param body
12
- */
13
- export const defEasing = (body) => defn(F, null, [F], body);
14
- export const easeInSine = defEasing((x) => [
15
- ret(sub(FLOAT1, cos(mul(x, HALF_PI)))),
28
+ const defEasing = (body) => defn(F, null, [F], body);
29
+ const easeInSine = defEasing((x) => [
30
+ ret(sub(FLOAT1, cos(mul(x, HALF_PI))))
16
31
  ]);
17
- export const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
18
- export const easeInOutSine = defEasing((x) => [
19
- ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2)),
32
+ const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
33
+ const easeInOutSine = defEasing((x) => [
34
+ ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2))
20
35
  ]);
21
- export const easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
22
- export const easeOutQuad = defEasing((x) => [
23
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2))),
36
+ const easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
37
+ const easeOutQuad = defEasing((x) => [
38
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2)))
24
39
  ]);
25
- export const easeInOutQuad = defEasing((x) => [
26
- ret(ternary(lt(x, FLOAT05), mul(FLOAT2, pow(x, FLOAT2)), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2)))),
40
+ const easeInOutQuad = defEasing((x) => [
41
+ ret(
42
+ ternary(
43
+ lt(x, FLOAT05),
44
+ mul(FLOAT2, pow(x, FLOAT2)),
45
+ sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2))
46
+ )
47
+ )
27
48
  ]);
28
- export const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
29
- export const easeOutCubic = defEasing((x) => [
30
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3)))),
49
+ const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
50
+ const easeOutCubic = defEasing((x) => [
51
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3))))
31
52
  ]);
32
- export const easeInOutCubic = defEasing((x) => [
33
- ret(ternary(lt(x, FLOAT05), mul(float(4), pow(x, float(3))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)))),
53
+ const easeInOutCubic = defEasing((x) => [
54
+ ret(
55
+ ternary(
56
+ lt(x, FLOAT05),
57
+ mul(float(4), pow(x, float(3))),
58
+ sub(
59
+ FLOAT1,
60
+ div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)
61
+ )
62
+ )
63
+ )
34
64
  ]);
35
- export const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
36
- export const easeOutQuart = defEasing((x) => [
37
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4)))),
65
+ const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
66
+ const easeOutQuart = defEasing((x) => [
67
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4))))
38
68
  ]);
39
- export const easeInOutQuart = defEasing((x) => [
40
- ret(ternary(lt(x, FLOAT05), mul(float(8), pow(x, float(4))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)))),
69
+ const easeInOutQuart = defEasing((x) => [
70
+ ret(
71
+ ternary(
72
+ lt(x, FLOAT05),
73
+ mul(float(8), pow(x, float(4))),
74
+ sub(
75
+ FLOAT1,
76
+ div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)
77
+ )
78
+ )
79
+ )
41
80
  ]);
42
- export const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
43
- export const easeOutQuint = defEasing((x) => [
44
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5)))),
81
+ const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
82
+ const easeOutQuint = defEasing((x) => [
83
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5))))
45
84
  ]);
46
- export const easeInOutQuint = defEasing((x) => [
47
- ret(ternary(lt(x, FLOAT05), mul(float(16), pow(x, float(5))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)))),
85
+ const easeInOutQuint = defEasing((x) => [
86
+ ret(
87
+ ternary(
88
+ lt(x, FLOAT05),
89
+ mul(float(16), pow(x, float(5))),
90
+ sub(
91
+ FLOAT1,
92
+ div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)
93
+ )
94
+ )
95
+ )
48
96
  ]);
49
- export const easeInExpo = defEasing((x) => [
50
- ret(ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))),
97
+ const easeInExpo = defEasing((x) => [
98
+ ret(
99
+ ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))
100
+ )
51
101
  ]);
52
- export const easeOutExpo = defEasing((x) => [
53
- ret(ternary(eq(x, FLOAT1), FLOAT1, sub(FLOAT1, exp2(mul(neg(float(10)), x))))),
102
+ const easeOutExpo = defEasing((x) => [
103
+ ret(
104
+ ternary(
105
+ eq(x, FLOAT1),
106
+ FLOAT1,
107
+ sub(FLOAT1, exp2(mul(neg(float(10)), x)))
108
+ )
109
+ )
54
110
  ]);
55
- export const easeInOutExpo = defEasing((x) => [
56
- ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(exp2(sub(mul(float(20), x), float(10))), FLOAT2), div(sub(FLOAT2, exp2(madd(neg(float(20)), x, float(10)))), FLOAT2))))),
111
+ const easeInOutExpo = defEasing((x) => [
112
+ ret(
113
+ ternary(
114
+ eq(x, FLOAT0),
115
+ FLOAT0,
116
+ ternary(
117
+ eq(x, FLOAT1),
118
+ FLOAT1,
119
+ ternary(
120
+ lt(x, FLOAT05),
121
+ div(exp2(sub(mul(float(20), x), float(10))), FLOAT2),
122
+ div(
123
+ sub(FLOAT2, exp2(madd(neg(float(20)), x, float(10)))),
124
+ FLOAT2
125
+ )
126
+ )
127
+ )
128
+ )
129
+ )
57
130
  ]);
58
- export const easeInCirc = defEasing((x) => [
59
- ret(sub(FLOAT1, sqrt(sub(FLOAT1, pow(x, FLOAT2))))),
131
+ const easeInCirc = defEasing((x) => [
132
+ ret(sub(FLOAT1, sqrt(sub(FLOAT1, pow(x, FLOAT2)))))
60
133
  ]);
61
- export const easeOutCirc = defEasing((x) => [
62
- ret(sqrt(sub(FLOAT1, pow(sub(x, FLOAT1), FLOAT2)))),
134
+ const easeOutCirc = defEasing((x) => [
135
+ ret(sqrt(sub(FLOAT1, pow(sub(x, FLOAT1), FLOAT2))))
63
136
  ]);
64
- export const easeInOutCirc = defEasing((x) => [
65
- ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, sqrt(sub(FLOAT1, pow(mul(FLOAT2, x), FLOAT2)))), FLOAT2), div(add(sqrt(sub(FLOAT1, pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2))), FLOAT1), FLOAT2))),
137
+ const easeInOutCirc = defEasing((x) => [
138
+ ret(
139
+ ternary(
140
+ lt(x, FLOAT05),
141
+ div(
142
+ sub(FLOAT1, sqrt(sub(FLOAT1, pow(mul(FLOAT2, x), FLOAT2)))),
143
+ FLOAT2
144
+ ),
145
+ div(
146
+ add(
147
+ sqrt(
148
+ sub(FLOAT1, pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2))
149
+ ),
150
+ FLOAT1
151
+ ),
152
+ FLOAT2
153
+ )
154
+ )
155
+ )
66
156
  ]);
67
- export const easeInBack = defEasing((x) => {
68
- const c1 = 1.70158;
69
- const c3 = c1 + 1;
70
- return [ret(sub(mul(c3, pow(x, float(3))), mul(c1, pow(x, FLOAT2))))];
157
+ const easeInBack = defEasing((x) => {
158
+ const c1 = 1.70158;
159
+ const c3 = c1 + 1;
160
+ return [ret(sub(mul(c3, pow(x, float(3))), mul(c1, pow(x, FLOAT2))))];
71
161
  });
72
- export const easeOutBack = defEasing((x) => {
73
- const c1 = 1.70158;
74
- const c3 = c1 + 1;
75
- return [
76
- ret(add(madd(float(c3), pow(sub(x, FLOAT1), float(3)), FLOAT1), mul(c1, pow(sub(x, FLOAT1), FLOAT2)))),
77
- ];
162
+ const easeOutBack = defEasing((x) => {
163
+ const c1 = 1.70158;
164
+ const c3 = c1 + 1;
165
+ return [
166
+ ret(
167
+ add(
168
+ madd(float(c3), pow(sub(x, FLOAT1), float(3)), FLOAT1),
169
+ mul(c1, pow(sub(x, FLOAT1), FLOAT2))
170
+ )
171
+ )
172
+ ];
78
173
  });
79
- export const easeInOutBack = defEasing((x) => {
80
- const c1 = 1.70158;
81
- const c2 = c1 * 1.525;
82
- return [
83
- ret(ternary(lt(x, FLOAT05), div(mul(pow(mul(FLOAT2, x), FLOAT2), sub(mul(mul(add(c2, FLOAT1), FLOAT2), x), c2)), FLOAT2), div(add(mul(pow(sub(mul(FLOAT2, x), FLOAT2), FLOAT2), add(mul(add(c2, FLOAT1), sub(mul(x, FLOAT2), FLOAT2)), c2)), FLOAT2), FLOAT2))),
84
- ];
174
+ const easeInOutBack = defEasing((x) => {
175
+ const c1 = 1.70158;
176
+ const c2 = c1 * 1.525;
177
+ return [
178
+ ret(
179
+ ternary(
180
+ lt(x, FLOAT05),
181
+ div(
182
+ mul(
183
+ pow(mul(FLOAT2, x), FLOAT2),
184
+ sub(mul(mul(add(c2, FLOAT1), FLOAT2), x), c2)
185
+ ),
186
+ FLOAT2
187
+ ),
188
+ div(
189
+ add(
190
+ mul(
191
+ pow(sub(mul(FLOAT2, x), FLOAT2), FLOAT2),
192
+ add(
193
+ mul(
194
+ add(c2, FLOAT1),
195
+ sub(mul(x, FLOAT2), FLOAT2)
196
+ ),
197
+ c2
198
+ )
199
+ ),
200
+ FLOAT2
201
+ ),
202
+ FLOAT2
203
+ )
204
+ )
205
+ )
206
+ ];
85
207
  });
86
- export const easeInElastic = defEasing((x) => [
87
- ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, mul(neg(exp2(sub(mul(10, x), 10))), sin(mul(sub(mul(x, 10), 10.75), div(TAU, 3))))))),
208
+ const easeInElastic = defEasing((x) => [
209
+ ret(
210
+ ternary(
211
+ eq(x, FLOAT0),
212
+ FLOAT0,
213
+ ternary(
214
+ eq(x, FLOAT1),
215
+ FLOAT1,
216
+ mul(
217
+ neg(exp2(sub(mul(10, x), 10))),
218
+ sin(mul(sub(mul(x, 10), 10.75), div(TAU, 3)))
219
+ )
220
+ )
221
+ )
222
+ )
88
223
  ]);
89
- export const easeOutElastic = defEasing((x) => [
90
- ret(ternary(lte(x, FLOAT0), FLOAT0, ternary(gte(x, FLOAT1), FLOAT1, madd(exp2(mul(-10, x)), sin(mul(sub(mul(x, 10), 0.75), div(TAU, 3))), FLOAT1)))),
224
+ const easeOutElastic = defEasing((x) => [
225
+ ret(
226
+ ternary(
227
+ lte(x, FLOAT0),
228
+ FLOAT0,
229
+ ternary(
230
+ gte(x, FLOAT1),
231
+ FLOAT1,
232
+ madd(
233
+ exp2(mul(-10, x)),
234
+ sin(mul(sub(mul(x, 10), 0.75), div(TAU, 3))),
235
+ FLOAT1
236
+ )
237
+ )
238
+ )
239
+ )
91
240
  ]);
92
- export const easeInOutElastic = defEasing((x) => {
93
- const c5 = div(TAU, 4.5);
94
- return [
95
- ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(neg(mul(exp2(sub(mul(20, x), 10)), sin(mul(sub(mul(20, x), 11.125), c5)))), FLOAT2), add(div(mul(exp2(madd(neg(float(20)), x, float(10))), sin(mul(sub(mul(20, x), 11.125), c5))), FLOAT2), FLOAT1))))),
96
- ];
241
+ const easeInOutElastic = defEasing((x) => {
242
+ const c5 = div(TAU, 4.5);
243
+ return [
244
+ ret(
245
+ ternary(
246
+ eq(x, FLOAT0),
247
+ FLOAT0,
248
+ ternary(
249
+ eq(x, FLOAT1),
250
+ FLOAT1,
251
+ ternary(
252
+ lt(x, FLOAT05),
253
+ div(
254
+ neg(
255
+ mul(
256
+ exp2(sub(mul(20, x), 10)),
257
+ sin(mul(sub(mul(20, x), 11.125), c5))
258
+ )
259
+ ),
260
+ FLOAT2
261
+ ),
262
+ add(
263
+ div(
264
+ mul(
265
+ exp2(madd(neg(float(20)), x, float(10))),
266
+ sin(mul(sub(mul(20, x), 11.125), c5))
267
+ ),
268
+ FLOAT2
269
+ ),
270
+ FLOAT1
271
+ )
272
+ )
273
+ )
274
+ )
275
+ )
276
+ ];
97
277
  });
98
- export const easeOutBounce = defEasing((x) => {
99
- const n1 = 7.5625;
100
- const d1 = float(2.75);
101
- return [
102
- ifThen(lt(x, reciprocal(d1)), [ret(mul(n1, pow(x, FLOAT2)))]),
103
- ifThen(lt(x, div(FLOAT2, d1)), [
104
- ret(add(mul(mul(n1, sub(x, div(1.5, d1))), sub(x, div(1.5, d1))), 0.75)),
105
- ]),
106
- ifThen(lt(x, div(2.5, d1)), [
107
- ret(add(mul(mul(n1, sub(x, div(2.25, d1))), sub(x, div(2.25, d1))), 0.9375)),
108
- ]),
109
- ret(add(mul(mul(n1, sub(x, div(2.625, d1))), sub(x, div(2.625, d1))), 0.984375)),
110
- ];
278
+ const easeOutBounce = defEasing((x) => {
279
+ const n1 = 7.5625;
280
+ const d1 = float(2.75);
281
+ return [
282
+ ifThen(lt(x, reciprocal(d1)), [ret(mul(n1, pow(x, FLOAT2)))]),
283
+ ifThen(lt(x, div(FLOAT2, d1)), [
284
+ ret(
285
+ add(
286
+ mul(mul(n1, sub(x, div(1.5, d1))), sub(x, div(1.5, d1))),
287
+ 0.75
288
+ )
289
+ )
290
+ ]),
291
+ ifThen(lt(x, div(2.5, d1)), [
292
+ ret(
293
+ add(
294
+ mul(mul(n1, sub(x, div(2.25, d1))), sub(x, div(2.25, d1))),
295
+ 0.9375
296
+ )
297
+ )
298
+ ]),
299
+ ret(
300
+ add(
301
+ mul(mul(n1, sub(x, div(2.625, d1))), sub(x, div(2.625, d1))),
302
+ 0.984375
303
+ )
304
+ )
305
+ ];
111
306
  });
112
- export const easeInBounce = defEasing((x) => [
113
- ret(sub(FLOAT1, easeOutBounce(sub(FLOAT1, x)))),
307
+ const easeInBounce = defEasing((x) => [
308
+ ret(sub(FLOAT1, easeOutBounce(sub(FLOAT1, x))))
114
309
  ]);
115
- export const easeInOutBounce = defEasing((x) => [
116
- ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, easeOutBounce(sub(FLOAT1, mul(FLOAT2, x)))), FLOAT2), div(add(FLOAT1, easeOutBounce(sub(mul(FLOAT2, x), FLOAT1))), FLOAT2))),
310
+ const easeInOutBounce = defEasing((x) => [
311
+ ret(
312
+ ternary(
313
+ lt(x, FLOAT05),
314
+ div(
315
+ sub(FLOAT1, easeOutBounce(sub(FLOAT1, mul(FLOAT2, x)))),
316
+ FLOAT2
317
+ ),
318
+ div(add(FLOAT1, easeOutBounce(sub(mul(FLOAT2, x), FLOAT1))), FLOAT2)
319
+ )
320
+ )
117
321
  ]);
322
+ export {
323
+ defEasing,
324
+ easeInBack,
325
+ easeInBounce,
326
+ easeInCirc,
327
+ easeInCubic,
328
+ easeInElastic,
329
+ easeInExpo,
330
+ easeInOutBack,
331
+ easeInOutBounce,
332
+ easeInOutCirc,
333
+ easeInOutCubic,
334
+ easeInOutElastic,
335
+ easeInOutExpo,
336
+ easeInOutQuad,
337
+ easeInOutQuart,
338
+ easeInOutQuint,
339
+ easeInOutSine,
340
+ easeInQuad,
341
+ easeInQuart,
342
+ easeInQuint,
343
+ easeInSine,
344
+ easeOutBack,
345
+ easeOutBounce,
346
+ easeOutCirc,
347
+ easeOutCubic,
348
+ easeOutElastic,
349
+ easeOutExpo,
350
+ easeOutQuad,
351
+ easeOutQuart,
352
+ easeOutQuint,
353
+ easeOutSine
354
+ };