motion 10.3.1 → 10.5.0-alpha.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 (210) hide show
  1. package/README.md +0 -19
  2. package/dist/main.cjs.js +11 -13
  3. package/dist/main.es.js +7 -6
  4. package/dist/motion.min.js +1 -1
  5. package/dist/motion.umd.js +236 -19
  6. package/dist/react.cjs.js +7 -2
  7. package/dist/react.es.js +1 -1
  8. package/dist/size-index.js +1 -0
  9. package/lib/index.js +5 -0
  10. package/lib/index.js.map +1 -0
  11. package/lib/react.js +2 -0
  12. package/lib/react.js.map +1 -0
  13. package/lib/vue.js +2 -0
  14. package/lib/vue.js.map +1 -0
  15. package/package.json +8 -136
  16. package/react/package.json +1 -1
  17. package/types/index.d.ts +3 -7
  18. package/types/index.d.ts.map +1 -0
  19. package/types/react.d.ts +2 -0
  20. package/types/react.d.ts.map +1 -0
  21. package/types/vue.d.ts +2 -0
  22. package/types/vue.d.ts.map +1 -0
  23. package/CHANGELOG.md +0 -91
  24. package/dist/size-animate-dom.js +0 -1
  25. package/dist/size-animate-style.js +0 -1
  26. package/dist/size-react.js +0 -1
  27. package/dist/size-spring.js +0 -1
  28. package/dist/size-timeline-dom.js +0 -1
  29. package/dist/size-webpack-animate.js +0 -1
  30. package/dist/targets/dom/animate-style.cjs.js +0 -182
  31. package/dist/targets/dom/animate-style.es.js +0 -178
  32. package/dist/targets/dom/animate.cjs.js +0 -42
  33. package/dist/targets/dom/animate.es.js +0 -38
  34. package/dist/targets/dom/data.cjs.js +0 -18
  35. package/dist/targets/dom/data.es.js +0 -14
  36. package/dist/targets/dom/style.cjs.js +0 -22
  37. package/dist/targets/dom/style.es.js +0 -18
  38. package/dist/targets/dom/timeline/index.cjs.js +0 -174
  39. package/dist/targets/dom/timeline/index.es.js +0 -169
  40. package/dist/targets/dom/timeline/utils/calc-time.cjs.js +0 -23
  41. package/dist/targets/dom/timeline/utils/calc-time.es.js +0 -19
  42. package/dist/targets/dom/timeline/utils/edit.cjs.js +0 -36
  43. package/dist/targets/dom/timeline/utils/edit.es.js +0 -31
  44. package/dist/targets/dom/timeline/utils/sort.cjs.js +0 -14
  45. package/dist/targets/dom/timeline/utils/sort.es.js +0 -10
  46. package/dist/targets/dom/utils/apply.cjs.js +0 -9
  47. package/dist/targets/dom/utils/apply.es.js +0 -4
  48. package/dist/targets/dom/utils/controls.cjs.js +0 -59
  49. package/dist/targets/dom/utils/controls.es.js +0 -54
  50. package/dist/targets/dom/utils/css-var.cjs.js +0 -29
  51. package/dist/targets/dom/utils/css-var.es.js +0 -23
  52. package/dist/targets/dom/utils/defaults.cjs.js +0 -13
  53. package/dist/targets/dom/utils/defaults.es.js +0 -9
  54. package/dist/targets/dom/utils/easing.cjs.js +0 -18
  55. package/dist/targets/dom/utils/easing.es.js +0 -10
  56. package/dist/targets/dom/utils/feature-detection.cjs.js +0 -31
  57. package/dist/targets/dom/utils/feature-detection.es.js +0 -27
  58. package/dist/targets/dom/utils/get-style-name.cjs.js +0 -13
  59. package/dist/targets/dom/utils/get-style-name.es.js +0 -9
  60. package/dist/targets/dom/utils/keyframes.cjs.js +0 -16
  61. package/dist/targets/dom/utils/keyframes.es.js +0 -11
  62. package/dist/targets/dom/utils/options.cjs.js +0 -13
  63. package/dist/targets/dom/utils/options.es.js +0 -9
  64. package/dist/targets/dom/utils/resolve-elements.cjs.js +0 -22
  65. package/dist/targets/dom/utils/resolve-elements.es.js +0 -18
  66. package/dist/targets/dom/utils/stop-animation.cjs.js +0 -19
  67. package/dist/targets/dom/utils/stop-animation.es.js +0 -15
  68. package/dist/targets/dom/utils/time.cjs.js +0 -7
  69. package/dist/targets/dom/utils/time.es.js +0 -3
  70. package/dist/targets/dom/utils/transforms.cjs.js +0 -85
  71. package/dist/targets/dom/utils/transforms.es.js +0 -74
  72. package/dist/targets/js/NumberAnimation.cjs.js +0 -144
  73. package/dist/targets/js/NumberAnimation.es.js +0 -140
  74. package/dist/targets/js/easing/cubic-bezier.cjs.js +0 -57
  75. package/dist/targets/js/easing/cubic-bezier.es.js +0 -53
  76. package/dist/targets/js/easing/glide/generator.cjs.js +0 -99
  77. package/dist/targets/js/easing/glide/generator.es.js +0 -95
  78. package/dist/targets/js/easing/glide/index.cjs.js +0 -10
  79. package/dist/targets/js/easing/glide/index.es.js +0 -6
  80. package/dist/targets/js/easing/spring/generator.cjs.js +0 -64
  81. package/dist/targets/js/easing/spring/generator.es.js +0 -57
  82. package/dist/targets/js/easing/spring/index.cjs.js +0 -10
  83. package/dist/targets/js/easing/spring/index.es.js +0 -6
  84. package/dist/targets/js/easing/steps.cjs.js +0 -15
  85. package/dist/targets/js/easing/steps.es.js +0 -11
  86. package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +0 -71
  87. package/dist/targets/js/easing/utils/create-generator-easing.es.js +0 -67
  88. package/dist/targets/js/easing/utils/get-function.cjs.js +0 -37
  89. package/dist/targets/js/easing/utils/get-function.es.js +0 -33
  90. package/dist/targets/js/easing/utils/has-reached-target.cjs.js +0 -10
  91. package/dist/targets/js/easing/utils/has-reached-target.es.js +0 -6
  92. package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +0 -34
  93. package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +0 -30
  94. package/dist/targets/js/utils/get-easing.cjs.js +0 -14
  95. package/dist/targets/js/utils/get-easing.es.js +0 -10
  96. package/dist/targets/js/utils/interpolate.cjs.js +0 -35
  97. package/dist/targets/js/utils/interpolate.es.js +0 -31
  98. package/dist/targets/js/utils/offset.cjs.js +0 -22
  99. package/dist/targets/js/utils/offset.es.js +0 -17
  100. package/dist/targets/react/animated.cjs.js +0 -126
  101. package/dist/targets/react/animated.es.js +0 -101
  102. package/dist/targets/react/context.cjs.js +0 -9
  103. package/dist/targets/react/context.es.js +0 -5
  104. package/dist/targets/react/hooks/use-animation.cjs.js +0 -47
  105. package/dist/targets/react/hooks/use-animation.es.js +0 -43
  106. package/dist/targets/react/hooks/use-exit.cjs.js +0 -27
  107. package/dist/targets/react/hooks/use-exit.es.js +0 -23
  108. package/dist/targets/react/hooks/use-gesture-state.cjs.js +0 -17
  109. package/dist/targets/react/hooks/use-gesture-state.es.js +0 -13
  110. package/dist/targets/react/hooks/use-hover.cjs.js +0 -24
  111. package/dist/targets/react/hooks/use-hover.es.js +0 -20
  112. package/dist/targets/react/hooks/use-press.cjs.js +0 -25
  113. package/dist/targets/react/hooks/use-press.es.js +0 -21
  114. package/dist/targets/react/hooks/use-viewport.cjs.js +0 -37
  115. package/dist/targets/react/hooks/use-viewport.es.js +0 -33
  116. package/dist/targets/react/index.cjs.js +0 -17
  117. package/dist/targets/react/index.es.js +0 -13
  118. package/dist/targets/react/utils/has-changed.cjs.js +0 -24
  119. package/dist/targets/react/utils/has-changed.es.js +0 -19
  120. package/dist/targets/react/utils/keyframes.cjs.js +0 -38
  121. package/dist/targets/react/utils/keyframes.es.js +0 -34
  122. package/dist/targets/react/utils/poses.cjs.js +0 -14
  123. package/dist/targets/react/utils/poses.es.js +0 -10
  124. package/dist/targets/react/utils/update-target.cjs.js +0 -20
  125. package/dist/targets/react/utils/update-target.es.js +0 -16
  126. package/dist/utils/array.cjs.js +0 -14
  127. package/dist/utils/array.es.js +0 -9
  128. package/dist/utils/clamp.cjs.js +0 -7
  129. package/dist/utils/clamp.es.js +0 -3
  130. package/dist/utils/is-number.cjs.js +0 -7
  131. package/dist/utils/is-number.es.js +0 -3
  132. package/dist/utils/mix.cjs.js +0 -28
  133. package/dist/utils/mix.es.js +0 -24
  134. package/dist/utils/noop.cjs.js +0 -9
  135. package/dist/utils/noop.es.js +0 -4
  136. package/dist/utils/progress.cjs.js +0 -20
  137. package/dist/utils/progress.es.js +0 -16
  138. package/dist/utils/stagger.cjs.js +0 -38
  139. package/dist/utils/stagger.es.js +0 -32
  140. package/dist/utils/velocity-per-second.cjs.js +0 -15
  141. package/dist/utils/velocity-per-second.es.js +0 -11
  142. package/dist/utils/wrap.cjs.js +0 -10
  143. package/dist/utils/wrap.es.js +0 -6
  144. package/types/react-entry.d.ts +0 -2
  145. package/types/targets/dom/animate-style.d.ts +0 -2
  146. package/types/targets/dom/animate.d.ts +0 -2
  147. package/types/targets/dom/data.d.ts +0 -2
  148. package/types/targets/dom/style.d.ts +0 -3
  149. package/types/targets/dom/timeline/index.d.ts +0 -15
  150. package/types/targets/dom/timeline/types.d.ts +0 -13
  151. package/types/targets/dom/timeline/utils/calc-time.d.ts +0 -2
  152. package/types/targets/dom/timeline/utils/edit.d.ts +0 -4
  153. package/types/targets/dom/timeline/utils/sort.d.ts +0 -2
  154. package/types/targets/dom/types.d.ts +0 -114
  155. package/types/targets/dom/utils/apply.d.ts +0 -3
  156. package/types/targets/dom/utils/controls.d.ts +0 -12
  157. package/types/targets/dom/utils/css-var.d.ts +0 -3
  158. package/types/targets/dom/utils/defaults.d.ts +0 -8
  159. package/types/targets/dom/utils/easing.d.ts +0 -6
  160. package/types/targets/dom/utils/feature-detection.d.ts +0 -8
  161. package/types/targets/dom/utils/get-style-name.d.ts +0 -1
  162. package/types/targets/dom/utils/keyframes.d.ts +0 -3
  163. package/types/targets/dom/utils/options.d.ts +0 -2
  164. package/types/targets/dom/utils/resolve-elements.d.ts +0 -4
  165. package/types/targets/dom/utils/stop-animation.d.ts +0 -6
  166. package/types/targets/dom/utils/time.d.ts +0 -1
  167. package/types/targets/dom/utils/transforms.d.ts +0 -20
  168. package/types/targets/js/NumberAnimation.d.ts +0 -24
  169. package/types/targets/js/easing/cubic-bezier.d.ts +0 -1
  170. package/types/targets/js/easing/glide/generator.d.ts +0 -5
  171. package/types/targets/js/easing/glide/index.d.ts +0 -2
  172. package/types/targets/js/easing/glide/types.d.ts +0 -14
  173. package/types/targets/js/easing/spring/generator.d.ts +0 -6
  174. package/types/targets/js/easing/spring/index.d.ts +0 -2
  175. package/types/targets/js/easing/spring/types.d.ts +0 -10
  176. package/types/targets/js/easing/steps.d.ts +0 -3
  177. package/types/targets/js/easing/utils/create-generator-easing.d.ts +0 -3
  178. package/types/targets/js/easing/utils/get-function.d.ts +0 -3
  179. package/types/targets/js/easing/utils/has-reached-target.d.ts +0 -1
  180. package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +0 -7
  181. package/types/targets/js/types.d.ts +0 -12
  182. package/types/targets/js/utils/get-easing.d.ts +0 -1
  183. package/types/targets/js/utils/interpolate.d.ts +0 -2
  184. package/types/targets/js/utils/offset.d.ts +0 -2
  185. package/types/targets/react/animated.d.ts +0 -3
  186. package/types/targets/react/context.d.ts +0 -3
  187. package/types/targets/react/hooks/use-animation.d.ts +0 -4
  188. package/types/targets/react/hooks/use-exit.d.ts +0 -3
  189. package/types/targets/react/hooks/use-gesture-state.d.ts +0 -4
  190. package/types/targets/react/hooks/use-hover.d.ts +0 -4
  191. package/types/targets/react/hooks/use-press.d.ts +0 -4
  192. package/types/targets/react/hooks/use-viewport.d.ts +0 -4
  193. package/types/targets/react/index.d.ts +0 -2
  194. package/types/targets/react/types.d.ts +0 -108
  195. package/types/targets/react/utils/has-changed.d.ts +0 -2
  196. package/types/targets/react/utils/keyframes.d.ts +0 -3
  197. package/types/targets/react/utils/poses.d.ts +0 -2
  198. package/types/targets/react/utils/supported-elements.d.ts +0 -8
  199. package/types/targets/react/utils/update-target.d.ts +0 -3
  200. package/types/utils/array.d.ts +0 -2
  201. package/types/utils/clamp.d.ts +0 -1
  202. package/types/utils/interpolate.d.ts +0 -0
  203. package/types/utils/is-number.d.ts +0 -1
  204. package/types/utils/mix.d.ts +0 -1
  205. package/types/utils/noop.d.ts +0 -2
  206. package/types/utils/progress.d.ts +0 -1
  207. package/types/utils/stagger.d.ts +0 -12
  208. package/types/utils/value-types.d.ts +0 -0
  209. package/types/utils/velocity-per-second.d.ts +0 -1
  210. package/types/utils/wrap.d.ts +0 -1
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var array = require('../../../utils/array.cjs.js');
6
- var noop = require('../../../utils/noop.cjs.js');
7
- var data = require('../data.cjs.js');
8
-
9
- /**
10
- * A list of all transformable axes. We'll use this list to generated a version
11
- * of each axes for each transform.
12
- */
13
- const axes = ["", "X", "Y", "Z"];
14
- /**
15
- * An ordered array of each transformable value. By default, transform values
16
- * will be sorted to this order.
17
- */
18
- const order = ["translate", "scale", "rotate", "skew"];
19
- const transformAlias = {
20
- x: "translateX",
21
- y: "translateY",
22
- z: "translateZ",
23
- };
24
- const rotation = {
25
- syntax: "<angle>",
26
- initialValue: "0deg",
27
- toDefaultUnit: (v) => v + "deg",
28
- };
29
- const baseTransformProperties = {
30
- translate: {
31
- syntax: "<length-percentage>",
32
- initialValue: "0px",
33
- toDefaultUnit: (v) => v + "px",
34
- },
35
- rotate: rotation,
36
- scale: {
37
- syntax: "<number>",
38
- initialValue: 1,
39
- toDefaultUnit: noop.noopReturn,
40
- },
41
- skew: rotation,
42
- };
43
- const transformDefinitions = new Map();
44
- const asTransformCssVar = (name) => `--motion-${name}`;
45
- /**
46
- * Generate a list of every possible transform key
47
- */
48
- const transforms = ["x", "y", "z"];
49
- order.forEach((name) => {
50
- axes.forEach((axis) => {
51
- transforms.push(name + axis);
52
- transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
53
- });
54
- });
55
- /**
56
- * A function to use with Array.sort to sort transform keys by their default order.
57
- */
58
- const compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.indexOf(b);
59
- /**
60
- * Provide a quick way to check if a string is the name of a transform
61
- */
62
- const transformLookup = new Set(transforms);
63
- const isTransform = (name) => transformLookup.has(name);
64
- const addTransformToElement = (element, name) => {
65
- // Map x to translateX etc
66
- if (transformAlias[name])
67
- name = transformAlias[name];
68
- const { transforms } = data.getAnimationData(element);
69
- array.addUniqueItem(transforms, name);
70
- element.style.transform = buildTransformTemplate(transforms);
71
- };
72
- const buildTransformTemplate = (transforms) => transforms
73
- .sort(compareTransformOrder)
74
- .reduce(transformListToString, "")
75
- .trim();
76
- const transformListToString = (template, name) => `${template} ${name}(var(${asTransformCssVar(name)}))`;
77
-
78
- exports.addTransformToElement = addTransformToElement;
79
- exports.asTransformCssVar = asTransformCssVar;
80
- exports.axes = axes;
81
- exports.buildTransformTemplate = buildTransformTemplate;
82
- exports.compareTransformOrder = compareTransformOrder;
83
- exports.isTransform = isTransform;
84
- exports.transformAlias = transformAlias;
85
- exports.transformDefinitions = transformDefinitions;
@@ -1,74 +0,0 @@
1
- import { addUniqueItem } from '../../../utils/array.es.js';
2
- import { noopReturn } from '../../../utils/noop.es.js';
3
- import { getAnimationData } from '../data.es.js';
4
-
5
- /**
6
- * A list of all transformable axes. We'll use this list to generated a version
7
- * of each axes for each transform.
8
- */
9
- const axes = ["", "X", "Y", "Z"];
10
- /**
11
- * An ordered array of each transformable value. By default, transform values
12
- * will be sorted to this order.
13
- */
14
- const order = ["translate", "scale", "rotate", "skew"];
15
- const transformAlias = {
16
- x: "translateX",
17
- y: "translateY",
18
- z: "translateZ",
19
- };
20
- const rotation = {
21
- syntax: "<angle>",
22
- initialValue: "0deg",
23
- toDefaultUnit: (v) => v + "deg",
24
- };
25
- const baseTransformProperties = {
26
- translate: {
27
- syntax: "<length-percentage>",
28
- initialValue: "0px",
29
- toDefaultUnit: (v) => v + "px",
30
- },
31
- rotate: rotation,
32
- scale: {
33
- syntax: "<number>",
34
- initialValue: 1,
35
- toDefaultUnit: noopReturn,
36
- },
37
- skew: rotation,
38
- };
39
- const transformDefinitions = new Map();
40
- const asTransformCssVar = (name) => `--motion-${name}`;
41
- /**
42
- * Generate a list of every possible transform key
43
- */
44
- const transforms = ["x", "y", "z"];
45
- order.forEach((name) => {
46
- axes.forEach((axis) => {
47
- transforms.push(name + axis);
48
- transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
49
- });
50
- });
51
- /**
52
- * A function to use with Array.sort to sort transform keys by their default order.
53
- */
54
- const compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.indexOf(b);
55
- /**
56
- * Provide a quick way to check if a string is the name of a transform
57
- */
58
- const transformLookup = new Set(transforms);
59
- const isTransform = (name) => transformLookup.has(name);
60
- const addTransformToElement = (element, name) => {
61
- // Map x to translateX etc
62
- if (transformAlias[name])
63
- name = transformAlias[name];
64
- const { transforms } = getAnimationData(element);
65
- addUniqueItem(transforms, name);
66
- element.style.transform = buildTransformTemplate(transforms);
67
- };
68
- const buildTransformTemplate = (transforms) => transforms
69
- .sort(compareTransformOrder)
70
- .reduce(transformListToString, "")
71
- .trim();
72
- const transformListToString = (template, name) => `${template} ${name}(var(${asTransformCssVar(name)}))`;
73
-
74
- export { addTransformToElement, asTransformCssVar, axes, buildTransformTemplate, compareTransformOrder, isTransform, transformAlias, transformDefinitions };
@@ -1,144 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var defaults = require('../dom/utils/defaults.cjs.js');
6
- var easing = require('../dom/utils/easing.cjs.js');
7
- var getFunction = require('./easing/utils/get-function.cjs.js');
8
- var interpolate = require('./utils/interpolate.cjs.js');
9
-
10
- class NumberAnimation {
11
- constructor(output, keyframes = [0, 1], { easing: easing$1 = defaults.defaults.easing, duration = defaults.defaults.duration, delay = defaults.defaults.delay, endDelay = defaults.defaults.endDelay, repeat = defaults.defaults.repeat, offset, direction = "normal", } = {}) {
12
- this.startTime = 0;
13
- this.rate = 1;
14
- this.t = 0;
15
- this.cancelT = 0;
16
- this.playState = "idle";
17
- this.finished = new Promise((resolve, reject) => {
18
- this.resolve = resolve;
19
- this.reject = reject;
20
- });
21
- const totalDuration = duration * (repeat + 1);
22
- /**
23
- * We don't currently support custom easing (spring, glide etc) in NumberAnimation
24
- * (although this is completely possible), so this will have been hydrated by
25
- * animateStyle.
26
- */
27
- if (easing.isCustomEasing(easing$1))
28
- easing$1 = "ease";
29
- const interpolate$1 = interpolate.slowInterpolateNumbers(keyframes, offset, easing.isEasingList(easing$1)
30
- ? easing$1.map(getFunction.getEasingFunction)
31
- : getFunction.getEasingFunction(easing$1));
32
- this.tick = (timestamp) => {
33
- if (this.pauseTime)
34
- timestamp = this.pauseTime;
35
- let t = (timestamp - this.startTime) * this.rate;
36
- this.t = t;
37
- // Convert to seconds
38
- t /= 1000;
39
- // Rebase on delay
40
- t = Math.max(t - delay, 0);
41
- /**
42
- * If this animation has finished, set the current time
43
- * to the total duration.
44
- */
45
- if (this.playState === "finished")
46
- t = totalDuration;
47
- /**
48
- * Get the current progress (0-1) of the animation. If t is >
49
- * than duration we'll get values like 2.5 (midway through the
50
- * third iteration)
51
- */
52
- const progress = t / duration;
53
- // TODO progress += iterationStart
54
- /**
55
- * Get the current iteration (0 indexed). For instance the floor of
56
- * 2.5 is 2.
57
- */
58
- let currentIteration = Math.floor(progress);
59
- /**
60
- * Get the current progress of the iteration by taking the remainder
61
- * so 2.5 is 0.5 through iteration 2
62
- */
63
- let iterationProgress = progress % 1.0;
64
- if (!iterationProgress && progress >= 1) {
65
- iterationProgress = 1;
66
- }
67
- /**
68
- * If iteration progress is 1 we count that as the end
69
- * of the previous iteration.
70
- */
71
- iterationProgress === 1 && currentIteration--;
72
- /**
73
- * Reverse progress if we're not running in "normal" direction
74
- */
75
- const iterationIsOdd = currentIteration % 2;
76
- if (direction === "reverse" ||
77
- (direction === "alternate" && iterationIsOdd) ||
78
- (direction === "alternate-reverse" && !iterationIsOdd)) {
79
- iterationProgress = 1 - iterationProgress;
80
- }
81
- const latest = interpolate$1(t >= totalDuration ? 1 : Math.min(iterationProgress, 1));
82
- output(latest);
83
- const isAnimationFinished = this.playState === "finished" || t >= totalDuration + endDelay;
84
- if (isAnimationFinished) {
85
- this.playState = "finished";
86
- this.resolve(latest);
87
- }
88
- else if (this.playState !== "idle") {
89
- requestAnimationFrame(this.tick);
90
- }
91
- };
92
- this.play();
93
- }
94
- play() {
95
- const now = performance.now();
96
- this.playState = "running";
97
- if (this.pauseTime) {
98
- this.startTime = now - (this.pauseTime - this.startTime);
99
- }
100
- else if (!this.startTime) {
101
- this.startTime = now;
102
- }
103
- this.pauseTime = undefined;
104
- requestAnimationFrame(this.tick);
105
- }
106
- pause() {
107
- this.playState = "paused";
108
- this.pauseTime = performance.now();
109
- }
110
- finish() {
111
- this.playState = "finished";
112
- this.tick(0);
113
- }
114
- cancel() {
115
- this.playState = "idle";
116
- this.tick(this.cancelT);
117
- this.reject(false);
118
- }
119
- reverse() {
120
- this.rate *= -1;
121
- }
122
- commitStyles() {
123
- this.cancelT = this.t;
124
- }
125
- get currentTime() {
126
- return this.t;
127
- }
128
- set currentTime(t) {
129
- if (this.pauseTime || this.rate === 0) {
130
- this.pauseTime = t;
131
- }
132
- else {
133
- this.startTime = performance.now() - t / this.rate;
134
- }
135
- }
136
- get playbackRate() {
137
- return this.rate;
138
- }
139
- set playbackRate(rate) {
140
- this.rate = rate;
141
- }
142
- }
143
-
144
- exports.NumberAnimation = NumberAnimation;
@@ -1,140 +0,0 @@
1
- import { defaults } from '../dom/utils/defaults.es.js';
2
- import { isCustomEasing, isEasingList } from '../dom/utils/easing.es.js';
3
- import { getEasingFunction } from './easing/utils/get-function.es.js';
4
- import { slowInterpolateNumbers } from './utils/interpolate.es.js';
5
-
6
- class NumberAnimation {
7
- constructor(output, keyframes = [0, 1], { easing = defaults.easing, duration = defaults.duration, delay = defaults.delay, endDelay = defaults.endDelay, repeat = defaults.repeat, offset, direction = "normal", } = {}) {
8
- this.startTime = 0;
9
- this.rate = 1;
10
- this.t = 0;
11
- this.cancelT = 0;
12
- this.playState = "idle";
13
- this.finished = new Promise((resolve, reject) => {
14
- this.resolve = resolve;
15
- this.reject = reject;
16
- });
17
- const totalDuration = duration * (repeat + 1);
18
- /**
19
- * We don't currently support custom easing (spring, glide etc) in NumberAnimation
20
- * (although this is completely possible), so this will have been hydrated by
21
- * animateStyle.
22
- */
23
- if (isCustomEasing(easing))
24
- easing = "ease";
25
- const interpolate = slowInterpolateNumbers(keyframes, offset, isEasingList(easing)
26
- ? easing.map(getEasingFunction)
27
- : getEasingFunction(easing));
28
- this.tick = (timestamp) => {
29
- if (this.pauseTime)
30
- timestamp = this.pauseTime;
31
- let t = (timestamp - this.startTime) * this.rate;
32
- this.t = t;
33
- // Convert to seconds
34
- t /= 1000;
35
- // Rebase on delay
36
- t = Math.max(t - delay, 0);
37
- /**
38
- * If this animation has finished, set the current time
39
- * to the total duration.
40
- */
41
- if (this.playState === "finished")
42
- t = totalDuration;
43
- /**
44
- * Get the current progress (0-1) of the animation. If t is >
45
- * than duration we'll get values like 2.5 (midway through the
46
- * third iteration)
47
- */
48
- const progress = t / duration;
49
- // TODO progress += iterationStart
50
- /**
51
- * Get the current iteration (0 indexed). For instance the floor of
52
- * 2.5 is 2.
53
- */
54
- let currentIteration = Math.floor(progress);
55
- /**
56
- * Get the current progress of the iteration by taking the remainder
57
- * so 2.5 is 0.5 through iteration 2
58
- */
59
- let iterationProgress = progress % 1.0;
60
- if (!iterationProgress && progress >= 1) {
61
- iterationProgress = 1;
62
- }
63
- /**
64
- * If iteration progress is 1 we count that as the end
65
- * of the previous iteration.
66
- */
67
- iterationProgress === 1 && currentIteration--;
68
- /**
69
- * Reverse progress if we're not running in "normal" direction
70
- */
71
- const iterationIsOdd = currentIteration % 2;
72
- if (direction === "reverse" ||
73
- (direction === "alternate" && iterationIsOdd) ||
74
- (direction === "alternate-reverse" && !iterationIsOdd)) {
75
- iterationProgress = 1 - iterationProgress;
76
- }
77
- const latest = interpolate(t >= totalDuration ? 1 : Math.min(iterationProgress, 1));
78
- output(latest);
79
- const isAnimationFinished = this.playState === "finished" || t >= totalDuration + endDelay;
80
- if (isAnimationFinished) {
81
- this.playState = "finished";
82
- this.resolve(latest);
83
- }
84
- else if (this.playState !== "idle") {
85
- requestAnimationFrame(this.tick);
86
- }
87
- };
88
- this.play();
89
- }
90
- play() {
91
- const now = performance.now();
92
- this.playState = "running";
93
- if (this.pauseTime) {
94
- this.startTime = now - (this.pauseTime - this.startTime);
95
- }
96
- else if (!this.startTime) {
97
- this.startTime = now;
98
- }
99
- this.pauseTime = undefined;
100
- requestAnimationFrame(this.tick);
101
- }
102
- pause() {
103
- this.playState = "paused";
104
- this.pauseTime = performance.now();
105
- }
106
- finish() {
107
- this.playState = "finished";
108
- this.tick(0);
109
- }
110
- cancel() {
111
- this.playState = "idle";
112
- this.tick(this.cancelT);
113
- this.reject(false);
114
- }
115
- reverse() {
116
- this.rate *= -1;
117
- }
118
- commitStyles() {
119
- this.cancelT = this.t;
120
- }
121
- get currentTime() {
122
- return this.t;
123
- }
124
- set currentTime(t) {
125
- if (this.pauseTime || this.rate === 0) {
126
- this.pauseTime = t;
127
- }
128
- else {
129
- this.startTime = performance.now() - t / this.rate;
130
- }
131
- }
132
- get playbackRate() {
133
- return this.rate;
134
- }
135
- set playbackRate(rate) {
136
- this.rate = rate;
137
- }
138
- }
139
-
140
- export { NumberAnimation };
@@ -1,57 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var noop = require('../../../utils/noop.cjs.js');
6
-
7
- /*
8
- Bezier function generator
9
-
10
- This has been modified from Gaëtan Renaudeau's BezierEasing
11
- https://github.com/gre/bezier-easing/blob/master/src/index.js
12
- https://github.com/gre/bezier-easing/blob/master/LICENSE
13
-
14
- I've removed the newtonRaphsonIterate algo because in benchmarking it
15
- wasn't noticiably faster than binarySubdivision, indeed removing it
16
- usually improved times, depending on the curve.
17
-
18
- I also removed the lookup table, as for the added bundle size and loop we're
19
- only cutting ~4 or so subdivision iterations. I bumped the max iterations up
20
- to 12 to compensate and this still tended to be faster for no perceivable
21
- loss in accuracy.
22
-
23
- Usage
24
- const easeOut = cubicBezier(.17,.67,.83,.67);
25
- const x = easeOut(0.5); // returns 0.627...
26
- */
27
- // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
28
- const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) * t;
29
- const subdivisionPrecision = 0.0000001;
30
- const subdivisionMaxIterations = 12;
31
- function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
32
- let currentX;
33
- let currentT;
34
- let i = 0;
35
- do {
36
- currentT = lowerBound + (upperBound - lowerBound) / 2.0;
37
- currentX = calcBezier(currentT, mX1, mX2) - x;
38
- if (currentX > 0.0) {
39
- upperBound = currentT;
40
- }
41
- else {
42
- lowerBound = currentT;
43
- }
44
- } while (Math.abs(currentX) > subdivisionPrecision &&
45
- ++i < subdivisionMaxIterations);
46
- return currentT;
47
- }
48
- function cubicBezier(mX1, mY1, mX2, mY2) {
49
- // If this is a linear gradient, return linear easing
50
- if (mX1 === mY1 && mX2 === mY2)
51
- return noop.noopReturn;
52
- const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
53
- // If animation is at start/end, return t without easing
54
- return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
55
- }
56
-
57
- exports.cubicBezier = cubicBezier;
@@ -1,53 +0,0 @@
1
- import { noopReturn } from '../../../utils/noop.es.js';
2
-
3
- /*
4
- Bezier function generator
5
-
6
- This has been modified from Gaëtan Renaudeau's BezierEasing
7
- https://github.com/gre/bezier-easing/blob/master/src/index.js
8
- https://github.com/gre/bezier-easing/blob/master/LICENSE
9
-
10
- I've removed the newtonRaphsonIterate algo because in benchmarking it
11
- wasn't noticiably faster than binarySubdivision, indeed removing it
12
- usually improved times, depending on the curve.
13
-
14
- I also removed the lookup table, as for the added bundle size and loop we're
15
- only cutting ~4 or so subdivision iterations. I bumped the max iterations up
16
- to 12 to compensate and this still tended to be faster for no perceivable
17
- loss in accuracy.
18
-
19
- Usage
20
- const easeOut = cubicBezier(.17,.67,.83,.67);
21
- const x = easeOut(0.5); // returns 0.627...
22
- */
23
- // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
24
- const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) * t;
25
- const subdivisionPrecision = 0.0000001;
26
- const subdivisionMaxIterations = 12;
27
- function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
28
- let currentX;
29
- let currentT;
30
- let i = 0;
31
- do {
32
- currentT = lowerBound + (upperBound - lowerBound) / 2.0;
33
- currentX = calcBezier(currentT, mX1, mX2) - x;
34
- if (currentX > 0.0) {
35
- upperBound = currentT;
36
- }
37
- else {
38
- lowerBound = currentT;
39
- }
40
- } while (Math.abs(currentX) > subdivisionPrecision &&
41
- ++i < subdivisionMaxIterations);
42
- return currentT;
43
- }
44
- function cubicBezier(mX1, mY1, mX2, mY2) {
45
- // If this is a linear gradient, return linear easing
46
- if (mX1 === mY1 && mX2 === mY2)
47
- return noopReturn;
48
- const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
49
- // If animation is at start/end, return t without easing
50
- return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
51
- }
52
-
53
- export { cubicBezier };
@@ -1,99 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var generator = require('../spring/generator.cjs.js');
6
- var time = require('../../../dom/utils/time.cjs.js');
7
-
8
- const createGlideGenerator = ({ from = 0, velocity = 0.0, power = 0.8, decay = 0.325, bounceDamping, bounceStiffness, changeTarget, min, max, restDistance = 0.5, restSpeed, }) => {
9
- decay = time.ms(decay);
10
- const state = {
11
- value: from,
12
- target: from,
13
- velocity,
14
- hasReachedTarget: false,
15
- done: false,
16
- };
17
- const isOutOfBounds = (v) => (min !== undefined && v < min) || (max !== undefined && v > max);
18
- const nearestBoundary = (v) => {
19
- if (min === undefined)
20
- return max;
21
- if (max === undefined)
22
- return min;
23
- return Math.abs(min - v) < Math.abs(max - v) ? min : max;
24
- };
25
- let amplitude = power * velocity;
26
- const ideal = from + amplitude;
27
- const target = changeTarget === undefined ? ideal : changeTarget(ideal);
28
- state.target = target;
29
- /**
30
- * If the target has changed we need to re-calculate the amplitude, otherwise
31
- * the animation will start from the wrong position.
32
- */
33
- if (target !== ideal)
34
- amplitude = target - from;
35
- const calcDelta = (t) => -amplitude * Math.exp(-t / decay);
36
- const calcLatest = (t) => target + calcDelta(t);
37
- const applyFriction = (t) => {
38
- const delta = calcDelta(t);
39
- const latest = calcLatest(t);
40
- state.done = Math.abs(delta) <= restDistance;
41
- state.value = state.done ? target : latest;
42
- state.velocity =
43
- t === 0 ? velocity : generator.calcVelocity(calcLatest, t, state.value);
44
- };
45
- /**
46
- * Ideally this would resolve for t in a stateless way, we could
47
- * do that by always precalculating the animation but as we know
48
- * this will be done anyway we can assume that spring will
49
- * be discovered during that.
50
- */
51
- let timeReachedBoundary;
52
- let spring;
53
- const checkCatchBoundary = (t) => {
54
- if (!isOutOfBounds(state.value))
55
- return;
56
- timeReachedBoundary = t;
57
- spring = generator.createSpringGenerator({
58
- from: state.value,
59
- to: nearestBoundary(state.value),
60
- velocity: state.velocity,
61
- damping: bounceDamping,
62
- stiffness: bounceStiffness,
63
- restDistance,
64
- restSpeed,
65
- });
66
- };
67
- checkCatchBoundary(0);
68
- return {
69
- next: (t) => {
70
- /**
71
- * We need to resolve the friction to figure out if we need a
72
- * spring but we don't want to do this twice per frame. So here
73
- * we flag if we updated for this frame and later if we did
74
- * we can skip doing it again.
75
- */
76
- let hasUpdatedFrame = false;
77
- if (!spring && timeReachedBoundary === undefined) {
78
- hasUpdatedFrame = true;
79
- applyFriction(t);
80
- checkCatchBoundary(t);
81
- }
82
- /**
83
- * If we have a spring and the provided t is beyond the moment the friction
84
- * animation crossed the min/max boundary, use the spring.
85
- */
86
- if (timeReachedBoundary !== undefined && t > timeReachedBoundary) {
87
- state.hasReachedTarget = true;
88
- return spring.next(t - timeReachedBoundary);
89
- }
90
- else {
91
- state.hasReachedTarget = false;
92
- !hasUpdatedFrame && applyFriction(t);
93
- return state;
94
- }
95
- },
96
- };
97
- };
98
-
99
- exports.createGlideGenerator = createGlideGenerator;