motion 10.2.1 → 10.3.0

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 (90) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -0
  3. package/dist/main.cjs.js +2 -0
  4. package/dist/main.es.js +1 -0
  5. package/dist/motion.min.js +1 -1
  6. package/dist/motion.umd.js +426 -280
  7. package/dist/size-animate-dom.js +1 -1
  8. package/dist/size-animate-style.js +1 -1
  9. package/dist/size-react.js +1 -1
  10. package/dist/size-spring.js +1 -1
  11. package/dist/size-timeline-dom.js +1 -1
  12. package/dist/size-webpack-animate.js +1 -1
  13. package/dist/targets/dom/animate-style.cjs.js +135 -134
  14. package/dist/targets/dom/animate-style.es.js +137 -136
  15. package/dist/targets/dom/animate.cjs.js +15 -4
  16. package/dist/targets/dom/animate.es.js +16 -5
  17. package/dist/targets/dom/data.cjs.js +4 -3
  18. package/dist/targets/dom/data.es.js +4 -3
  19. package/dist/targets/dom/style.cjs.js +1 -1
  20. package/dist/targets/dom/style.es.js +2 -2
  21. package/dist/targets/dom/timeline/index.cjs.js +7 -6
  22. package/dist/targets/dom/timeline/index.es.js +8 -7
  23. package/dist/targets/dom/timeline/utils/calc-time.cjs.js +3 -1
  24. package/dist/targets/dom/timeline/utils/calc-time.es.js +3 -1
  25. package/dist/targets/dom/utils/apply.cjs.js +4 -8
  26. package/dist/targets/dom/utils/apply.es.js +3 -7
  27. package/dist/targets/dom/utils/controls.cjs.js +6 -2
  28. package/dist/targets/dom/utils/controls.es.js +6 -2
  29. package/dist/targets/dom/utils/css-var.cjs.js +2 -2
  30. package/dist/targets/dom/utils/css-var.es.js +3 -3
  31. package/dist/targets/dom/utils/easing.cjs.js +4 -2
  32. package/dist/targets/dom/utils/easing.es.js +4 -2
  33. package/dist/targets/dom/utils/feature-detection.cjs.js +4 -4
  34. package/dist/targets/dom/utils/feature-detection.es.js +4 -4
  35. package/dist/targets/dom/utils/get-style-name.cjs.js +13 -0
  36. package/dist/targets/dom/utils/get-style-name.es.js +9 -0
  37. package/dist/targets/dom/utils/keyframes.cjs.js +2 -4
  38. package/dist/targets/dom/utils/keyframes.es.js +2 -4
  39. package/dist/targets/dom/utils/options.cjs.js +1 -1
  40. package/dist/targets/dom/utils/options.es.js +1 -1
  41. package/dist/targets/dom/utils/stop-animation.cjs.js +2 -0
  42. package/dist/targets/dom/utils/stop-animation.es.js +2 -0
  43. package/dist/targets/dom/utils/transforms.cjs.js +10 -7
  44. package/dist/targets/dom/utils/transforms.es.js +10 -7
  45. package/dist/targets/js/{animate-number.cjs.js → NumberAnimation.cjs.js} +40 -29
  46. package/dist/targets/js/{animate-number.es.js → NumberAnimation.es.js} +40 -28
  47. package/dist/targets/js/easing/glide/generator.cjs.js +99 -0
  48. package/dist/targets/js/easing/glide/generator.es.js +95 -0
  49. package/dist/targets/js/easing/glide/index.cjs.js +10 -0
  50. package/dist/targets/js/easing/glide/index.es.js +6 -0
  51. package/dist/targets/js/easing/spring/generator.cjs.js +9 -4
  52. package/dist/targets/js/easing/spring/generator.es.js +9 -5
  53. package/dist/targets/js/easing/spring/index.cjs.js +2 -62
  54. package/dist/targets/js/easing/spring/index.es.js +2 -62
  55. package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +71 -0
  56. package/dist/targets/js/easing/utils/create-generator-easing.es.js +67 -0
  57. package/dist/targets/js/easing/utils/has-reached-target.cjs.js +10 -0
  58. package/dist/targets/js/easing/utils/has-reached-target.es.js +6 -0
  59. package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +13 -10
  60. package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +13 -10
  61. package/dist/targets/react/hooks/use-animation.cjs.js +5 -2
  62. package/dist/targets/react/hooks/use-animation.es.js +5 -2
  63. package/dist/targets/react/utils/keyframes.cjs.js +5 -3
  64. package/dist/targets/react/utils/keyframes.es.js +6 -4
  65. package/dist/utils/is-number.cjs.js +7 -0
  66. package/dist/utils/is-number.es.js +3 -0
  67. package/dist/utils/stagger.cjs.js +2 -1
  68. package/dist/utils/stagger.es.js +2 -1
  69. package/package.json +4 -10
  70. package/types/index.d.ts +1 -0
  71. package/types/targets/dom/animate-style.d.ts +2 -2
  72. package/types/targets/dom/style.d.ts +1 -1
  73. package/types/targets/dom/types.d.ts +8 -4
  74. package/types/targets/dom/utils/apply.d.ts +3 -2
  75. package/types/targets/dom/utils/controls.d.ts +3 -3
  76. package/types/targets/dom/utils/get-style-name.d.ts +1 -0
  77. package/types/targets/dom/utils/keyframes.d.ts +1 -1
  78. package/types/targets/dom/utils/stop-animation.d.ts +1 -1
  79. package/types/targets/dom/utils/transforms.d.ts +2 -2
  80. package/types/targets/js/{animate-number.d.ts → NumberAnimation.d.ts} +2 -3
  81. package/types/targets/js/easing/glide/generator.d.ts +5 -0
  82. package/types/targets/js/easing/glide/index.d.ts +2 -0
  83. package/types/targets/js/easing/glide/types.d.ts +14 -0
  84. package/types/targets/js/easing/spring/generator.d.ts +1 -0
  85. package/types/targets/js/easing/spring/index.d.ts +1 -2
  86. package/types/targets/js/easing/utils/create-generator-easing.d.ts +3 -0
  87. package/types/targets/js/easing/utils/has-reached-target.d.ts +1 -0
  88. package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +1 -1
  89. package/types/targets/js/types.d.ts +3 -0
  90. package/types/utils/is-number.d.ts +1 -0
@@ -1,26 +1,37 @@
1
1
  import { animateStyle } from './animate-style.es.js';
2
2
  import { getOptions } from './utils/options.es.js';
3
3
  import { resolveElements } from './utils/resolve-elements.es.js';
4
- import { createAnimationControls } from './utils/controls.es.js';
4
+ import { createAnimations } from './utils/controls.es.js';
5
5
  import { resolveOption } from '../../utils/stagger.es.js';
6
6
  import { defaults } from './utils/defaults.es.js';
7
7
 
8
8
  function animate(elements, keyframes, options = {}) {
9
9
  var _a;
10
10
  elements = resolveElements(elements);
11
- const animations = [];
12
11
  const numElements = elements.length;
12
+ /**
13
+ * Create and start new animations
14
+ */
15
+ const animationFactories = [];
13
16
  for (let i = 0; i < numElements; i++) {
14
17
  const element = elements[i];
15
18
  for (const key in keyframes) {
16
19
  const valueOptions = getOptions(options, key);
17
20
  valueOptions.delay = resolveOption(valueOptions.delay, i, numElements);
18
21
  const animation = animateStyle(element, key, keyframes[key], valueOptions);
19
- animation && animations.push(animation);
22
+ animationFactories.push(animation);
20
23
  }
21
24
  }
22
- return createAnimationControls(animations,
23
- // TODO: Remove this in case duration is dynamically generated
25
+ return createAnimations(animationFactories,
26
+ /**
27
+ * TODO:
28
+ * If easing is set to spring or glide, duration will be dynamically
29
+ * generated. Ideally we would dynamically generate this from
30
+ * animation.effect.getComputedTiming().duration but this isn't
31
+ * supported in iOS13 or our number polyfill. Perhaps it's possible
32
+ * to Proxy animations returned from animateStyle that has duration
33
+ * as a getter.
34
+ */
24
35
  (_a = options.duration) !== null && _a !== void 0 ? _a : defaults.duration);
25
36
  }
26
37
 
@@ -6,9 +6,10 @@ const data = new WeakMap();
6
6
  function getAnimationData(element) {
7
7
  if (!data.has(element)) {
8
8
  data.set(element, {
9
- activeTransforms: [],
10
- activeAnimations: {},
11
- activeGenerators: {},
9
+ transforms: [],
10
+ animations: {},
11
+ generators: {},
12
+ prevGeneratorState: {},
12
13
  });
13
14
  }
14
15
  return data.get(element);
@@ -2,9 +2,10 @@ const data = new WeakMap();
2
2
  function getAnimationData(element) {
3
3
  if (!data.has(element)) {
4
4
  data.set(element, {
5
- activeTransforms: [],
6
- activeAnimations: {},
7
- activeGenerators: {},
5
+ transforms: [],
6
+ animations: {},
7
+ generators: {},
8
+ prevGeneratorState: {},
8
9
  });
9
10
  }
10
11
  return data.get(element);
@@ -11,7 +11,7 @@ const style = {
11
11
  ? element.style.getPropertyValue(name)
12
12
  : getComputedStyle(element)[name];
13
13
  if (!value && value !== 0) {
14
- const definition = transforms.transformPropertyDefinitions.get(name);
14
+ const definition = transforms.transformDefinitions.get(name);
15
15
  if (definition)
16
16
  value = definition.initialValue;
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { isCssVar } from './utils/css-var.es.js';
2
- import { transformPropertyDefinitions } from './utils/transforms.es.js';
2
+ import { transformDefinitions } from './utils/transforms.es.js';
3
3
 
4
4
  const style = {
5
5
  get: (element, name) => {
@@ -7,7 +7,7 @@ const style = {
7
7
  ? element.style.getPropertyValue(name)
8
8
  : getComputedStyle(element)[name];
9
9
  if (!value && value !== 0) {
10
- const definition = transformPropertyDefinitions.get(name);
10
+ const definition = transformDefinitions.get(name);
11
11
  if (definition)
12
12
  value = definition.initialValue;
13
13
  }
@@ -18,13 +18,14 @@ var sort = require('./utils/sort.cjs.js');
18
18
 
19
19
  function timeline(definition, options = {}) {
20
20
  var _a, _b;
21
- const animations = [];
22
21
  const animationDefinitions = createAnimationsFromTimeline(definition, options);
23
- for (let i = 0; i < animationDefinitions.length; i++) {
24
- const animation = animateStyle.animateStyle(...animationDefinitions[i]);
25
- animation && animations.push(animation);
26
- }
27
- return controls.createAnimationControls(animations,
22
+ /**
23
+ * Create and start animations
24
+ */
25
+ const animationFactories = animationDefinitions
26
+ .map((definition) => animateStyle.animateStyle(...definition))
27
+ .filter(Boolean);
28
+ return controls.createAnimations(animationFactories,
28
29
  // Get the duration from the first animation definition
29
30
  (_b = (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration) !== null && _b !== void 0 ? _b : defaults.defaults.duration);
30
31
  }
@@ -3,7 +3,7 @@ import { progress } from '../../../utils/progress.es.js';
3
3
  import { resolveOption } from '../../../utils/stagger.es.js';
4
4
  import { defaultOffset, fillOffset } from '../../js/utils/offset.es.js';
5
5
  import { animateStyle } from '../animate-style.es.js';
6
- import { createAnimationControls } from '../utils/controls.es.js';
6
+ import { createAnimations } from '../utils/controls.es.js';
7
7
  import { defaults } from '../utils/defaults.es.js';
8
8
  import { keyframesList } from '../utils/keyframes.es.js';
9
9
  import { getOptions } from '../utils/options.es.js';
@@ -14,13 +14,14 @@ import { compareByTime } from './utils/sort.es.js';
14
14
 
15
15
  function timeline(definition, options = {}) {
16
16
  var _a, _b;
17
- const animations = [];
18
17
  const animationDefinitions = createAnimationsFromTimeline(definition, options);
19
- for (let i = 0; i < animationDefinitions.length; i++) {
20
- const animation = animateStyle(...animationDefinitions[i]);
21
- animation && animations.push(animation);
22
- }
23
- return createAnimationControls(animations,
18
+ /**
19
+ * Create and start animations
20
+ */
21
+ const animationFactories = animationDefinitions
22
+ .map((definition) => animateStyle(...definition))
23
+ .filter(Boolean);
24
+ return createAnimations(animationFactories,
24
25
  // Get the duration from the first animation definition
25
26
  (_b = (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration) !== null && _b !== void 0 ? _b : defaults.duration);
26
27
  }
@@ -2,9 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var isNumber = require('../../../../utils/is-number.cjs.js');
6
+
5
7
  function calcNextTime(current, next, prev, labels) {
6
8
  var _a;
7
- if (typeof next === "number") {
9
+ if (isNumber.isNumber(next)) {
8
10
  return next;
9
11
  }
10
12
  else if (next.startsWith("-") || next.startsWith("+")) {
@@ -1,6 +1,8 @@
1
+ import { isNumber } from '../../../../utils/is-number.es.js';
2
+
1
3
  function calcNextTime(current, next, prev, labels) {
2
4
  var _a;
3
- if (typeof next === "number") {
5
+ if (isNumber(next)) {
4
6
  return next;
5
7
  }
6
8
  else if (next.startsWith("-") || next.startsWith("+")) {
@@ -2,12 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const createCssVariableRenderer = (element, name) => {
6
- return (latest) => element.style.setProperty(name, latest);
7
- };
8
- const createStyleRenderer = (element, name) => {
9
- return (latest) => (element.style[name] = latest);
10
- };
5
+ const cssVariableRenderer = (element, name) => (latest) => element.style.setProperty(name, latest);
6
+ const styleRenderer = (element, name) => (latest) => (element.style[name] = latest);
11
7
 
12
- exports.createCssVariableRenderer = createCssVariableRenderer;
13
- exports.createStyleRenderer = createStyleRenderer;
8
+ exports.cssVariableRenderer = cssVariableRenderer;
9
+ exports.styleRenderer = styleRenderer;
@@ -1,8 +1,4 @@
1
- const createCssVariableRenderer = (element, name) => {
2
- return (latest) => element.style.setProperty(name, latest);
3
- };
4
- const createStyleRenderer = (element, name) => {
5
- return (latest) => (element.style[name] = latest);
6
- };
1
+ const cssVariableRenderer = (element, name) => (latest) => element.style.setProperty(name, latest);
2
+ const styleRenderer = (element, name) => (latest) => (element.style[name] = latest);
7
3
 
8
- export { createCssVariableRenderer, createStyleRenderer };
4
+ export { cssVariableRenderer, styleRenderer };
@@ -6,7 +6,11 @@ var noop = require('../../../utils/noop.cjs.js');
6
6
  var stopAnimation = require('./stop-animation.cjs.js');
7
7
  var time = require('./time.cjs.js');
8
8
 
9
- const createAnimationControls = (animations, duration) => new Proxy({ animations, duration }, controls);
9
+ const createAnimation = (factory) => factory();
10
+ const createAnimations = (animationFactory, duration) => new Proxy({
11
+ animations: animationFactory.map(createAnimation).filter(Boolean),
12
+ duration,
13
+ }, controls);
10
14
  /**
11
15
  * TODO:
12
16
  * Currently this returns the first animation, ideally it would return
@@ -52,4 +56,4 @@ const controls = {
52
56
  const selectFinished = (animation) => animation.finished;
53
57
 
54
58
  exports.controls = controls;
55
- exports.createAnimationControls = createAnimationControls;
59
+ exports.createAnimations = createAnimations;
@@ -2,7 +2,11 @@ import { noop } from '../../../utils/noop.es.js';
2
2
  import { stopAnimation } from './stop-animation.es.js';
3
3
  import { ms } from './time.es.js';
4
4
 
5
- const createAnimationControls = (animations, duration) => new Proxy({ animations, duration }, controls);
5
+ const createAnimation = (factory) => factory();
6
+ const createAnimations = (animationFactory, duration) => new Proxy({
7
+ animations: animationFactory.map(createAnimation).filter(Boolean),
8
+ duration,
9
+ }, controls);
6
10
  /**
7
11
  * TODO:
8
12
  * Currently this returns the first animation, ideally it would return
@@ -47,4 +51,4 @@ const controls = {
47
51
  };
48
52
  const selectFinished = (animation) => animation.finished;
49
53
 
50
- export { controls, createAnimationControls };
54
+ export { controls, createAnimations };
@@ -11,8 +11,8 @@ function registerCssVariable(name) {
11
11
  return;
12
12
  registeredProperties.add(name);
13
13
  try {
14
- const { syntax, initialValue } = transforms.transformPropertyDefinitions.has(name)
15
- ? transforms.transformPropertyDefinitions.get(name)
14
+ const { syntax, initialValue } = transforms.transformDefinitions.has(name)
15
+ ? transforms.transformDefinitions.get(name)
16
16
  : {};
17
17
  CSS.registerProperty({
18
18
  name,
@@ -1,4 +1,4 @@
1
- import { transformPropertyDefinitions } from './transforms.es.js';
1
+ import { transformDefinitions } from './transforms.es.js';
2
2
 
3
3
  const isCssVar = (name) => name.startsWith("--");
4
4
  const registeredProperties = new Set();
@@ -7,8 +7,8 @@ function registerCssVariable(name) {
7
7
  return;
8
8
  registeredProperties.add(name);
9
9
  try {
10
- const { syntax, initialValue } = transformPropertyDefinitions.has(name)
11
- ? transformPropertyDefinitions.get(name)
10
+ const { syntax, initialValue } = transformDefinitions.has(name)
11
+ ? transformDefinitions.get(name)
12
12
  : {};
13
13
  CSS.registerProperty({
14
14
  name,
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const isCubicBezier = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
6
- const isEasingList = (easing) => Array.isArray(easing) && typeof easing[0] !== "number";
5
+ var isNumber = require('../../../utils/is-number.cjs.js');
6
+
7
+ const isCubicBezier = (easing) => Array.isArray(easing) && isNumber.isNumber(easing[0]);
8
+ const isEasingList = (easing) => Array.isArray(easing) && !isNumber.isNumber(easing[0]);
7
9
  const isCustomEasing = (easing) => typeof easing === "object" &&
8
10
  Boolean(easing.createAnimation);
9
11
  const convertEasing = (easing) => isCubicBezier(easing) ? cubicBezierAsString(easing) : easing;
@@ -1,5 +1,7 @@
1
- const isCubicBezier = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
2
- const isEasingList = (easing) => Array.isArray(easing) && typeof easing[0] !== "number";
1
+ import { isNumber } from '../../../utils/is-number.es.js';
2
+
3
+ const isCubicBezier = (easing) => Array.isArray(easing) && isNumber(easing[0]);
4
+ const isEasingList = (easing) => Array.isArray(easing) && !isNumber(easing[0]);
3
5
  const isCustomEasing = (easing) => typeof easing === "object" &&
4
6
  Boolean(easing.createAnimation);
5
7
  const convertEasing = (easing) => isCubicBezier(easing) ? cubicBezierAsString(easing) : easing;
@@ -19,13 +19,13 @@ const featureTests = {
19
19
  finished: () => Boolean(testAnimation({ opacity: [0, 1] }).finished),
20
20
  };
21
21
  const results = {};
22
- const supports = Object.keys(featureTests).reduce((acc, key) => {
23
- acc[key] = () => {
22
+ const supports = {};
23
+ for (const key in featureTests) {
24
+ supports[key] = () => {
24
25
  if (results[key] === undefined)
25
26
  results[key] = featureTests[key]();
26
27
  return results[key];
27
28
  };
28
- return acc;
29
- }, {});
29
+ }
30
30
 
31
31
  exports.supports = supports;
@@ -15,13 +15,13 @@ const featureTests = {
15
15
  finished: () => Boolean(testAnimation({ opacity: [0, 1] }).finished),
16
16
  };
17
17
  const results = {};
18
- const supports = Object.keys(featureTests).reduce((acc, key) => {
19
- acc[key] = () => {
18
+ const supports = {};
19
+ for (const key in featureTests) {
20
+ supports[key] = () => {
20
21
  if (results[key] === undefined)
21
22
  results[key] = featureTests[key]();
22
23
  return results[key];
23
24
  };
24
- return acc;
25
- }, {});
25
+ }
26
26
 
27
27
  export { supports };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var transforms = require('./transforms.cjs.js');
6
+
7
+ function getStyleName(key) {
8
+ if (transforms.transformAlias[key])
9
+ key = transforms.transformAlias[key];
10
+ return transforms.isTransform(key) ? transforms.asTransformCssVar(key) : key;
11
+ }
12
+
13
+ exports.getStyleName = getStyleName;
@@ -0,0 +1,9 @@
1
+ import { isTransform, asTransformCssVar, transformAlias } from './transforms.es.js';
2
+
3
+ function getStyleName(key) {
4
+ if (transformAlias[key])
5
+ key = transformAlias[key];
6
+ return isTransform(key) ? asTransformCssVar(key) : key;
7
+ }
8
+
9
+ export { getStyleName };
@@ -2,12 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var style = require('../style.cjs.js');
6
-
7
- function hydrateKeyframes(keyframes, element, name) {
5
+ function hydrateKeyframes(keyframes, readInitialValue) {
8
6
  for (let i = 0; i < keyframes.length; i++) {
9
7
  if (keyframes[i] === null) {
10
- keyframes[i] = i ? keyframes[i - 1] : style.style.get(element, name);
8
+ keyframes[i] = i ? keyframes[i - 1] : readInitialValue();
11
9
  }
12
10
  }
13
11
  return keyframes;
@@ -1,9 +1,7 @@
1
- import { style } from '../style.es.js';
2
-
3
- function hydrateKeyframes(keyframes, element, name) {
1
+ function hydrateKeyframes(keyframes, readInitialValue) {
4
2
  for (let i = 0; i < keyframes.length; i++) {
5
3
  if (keyframes[i] === null) {
6
- keyframes[i] = i ? keyframes[i - 1] : style.get(element, name);
4
+ keyframes[i] = i ? keyframes[i - 1] : readInitialValue();
7
5
  }
8
6
  }
9
7
  return keyframes;
@@ -2,6 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const getOptions = (options, key) => options[key] ? Object.assign(Object.assign({}, options), options[key]) : Object.assign({}, options);
5
+ const getOptions = (options, key) => options[key] ? Object.assign(Object.assign({}, options), options[key]) : options;
6
6
 
7
7
  exports.getOptions = getOptions;
@@ -1,3 +1,3 @@
1
- const getOptions = (options, key) => options[key] ? Object.assign(Object.assign({}, options), options[key]) : Object.assign({}, options);
1
+ const getOptions = (options, key) => options[key] ? Object.assign(Object.assign({}, options), options[key]) : options;
2
2
 
3
3
  export { getOptions };
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function stopAnimation(animation) {
6
+ if (!animation)
7
+ return;
6
8
  // Suppress error thrown by WAAPI
7
9
  try {
8
10
  /**
@@ -1,4 +1,6 @@
1
1
  function stopAnimation(animation) {
2
+ if (!animation)
3
+ return;
2
4
  // Suppress error thrown by WAAPI
3
5
  try {
4
6
  /**
@@ -40,7 +40,7 @@ const baseTransformProperties = {
40
40
  },
41
41
  skew: rotation,
42
42
  };
43
- const transformPropertyDefinitions = new Map();
43
+ const transformDefinitions = new Map();
44
44
  const asTransformCssVar = (name) => `--motion-${name}`;
45
45
  /**
46
46
  * Generate a list of every possible transform key
@@ -49,7 +49,7 @@ const transforms = ["x", "y", "z"];
49
49
  order.forEach((name) => {
50
50
  axes.forEach((axis) => {
51
51
  transforms.push(name + axis);
52
- transformPropertyDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
52
+ transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
53
53
  });
54
54
  });
55
55
  /**
@@ -62,11 +62,14 @@ const compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.index
62
62
  const transformLookup = new Set(transforms);
63
63
  const isTransform = (name) => transformLookup.has(name);
64
64
  const addTransformToElement = (element, name) => {
65
- const { activeTransforms } = data.getAnimationData(element);
66
- array.addUniqueItem(activeTransforms, name);
67
- element.style.transform = buildTransformTemplate(activeTransforms);
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);
68
71
  };
69
- const buildTransformTemplate = (activeTransforms) => activeTransforms
72
+ const buildTransformTemplate = (transforms) => transforms
70
73
  .sort(compareTransformOrder)
71
74
  .reduce(transformListToString, "")
72
75
  .trim();
@@ -79,4 +82,4 @@ exports.buildTransformTemplate = buildTransformTemplate;
79
82
  exports.compareTransformOrder = compareTransformOrder;
80
83
  exports.isTransform = isTransform;
81
84
  exports.transformAlias = transformAlias;
82
- exports.transformPropertyDefinitions = transformPropertyDefinitions;
85
+ exports.transformDefinitions = transformDefinitions;
@@ -36,7 +36,7 @@ const baseTransformProperties = {
36
36
  },
37
37
  skew: rotation,
38
38
  };
39
- const transformPropertyDefinitions = new Map();
39
+ const transformDefinitions = new Map();
40
40
  const asTransformCssVar = (name) => `--motion-${name}`;
41
41
  /**
42
42
  * Generate a list of every possible transform key
@@ -45,7 +45,7 @@ const transforms = ["x", "y", "z"];
45
45
  order.forEach((name) => {
46
46
  axes.forEach((axis) => {
47
47
  transforms.push(name + axis);
48
- transformPropertyDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
48
+ transformDefinitions.set(asTransformCssVar(name + axis), baseTransformProperties[name]);
49
49
  });
50
50
  });
51
51
  /**
@@ -58,14 +58,17 @@ const compareTransformOrder = (a, b) => transforms.indexOf(a) - transforms.index
58
58
  const transformLookup = new Set(transforms);
59
59
  const isTransform = (name) => transformLookup.has(name);
60
60
  const addTransformToElement = (element, name) => {
61
- const { activeTransforms } = getAnimationData(element);
62
- addUniqueItem(activeTransforms, name);
63
- element.style.transform = buildTransformTemplate(activeTransforms);
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);
64
67
  };
65
- const buildTransformTemplate = (activeTransforms) => activeTransforms
68
+ const buildTransformTemplate = (transforms) => transforms
66
69
  .sort(compareTransformOrder)
67
70
  .reduce(transformListToString, "")
68
71
  .trim();
69
72
  const transformListToString = (template, name) => `${template} ${name}(var(${asTransformCssVar(name)}))`;
70
73
 
71
- export { addTransformToElement, asTransformCssVar, axes, buildTransformTemplate, compareTransformOrder, isTransform, transformAlias, transformPropertyDefinitions };
74
+ export { addTransformToElement, asTransformCssVar, axes, buildTransformTemplate, compareTransformOrder, isTransform, transformAlias, transformDefinitions };
@@ -7,8 +7,8 @@ var easing = require('../dom/utils/easing.cjs.js');
7
7
  var getFunction = require('./easing/utils/get-function.cjs.js');
8
8
  var interpolate = require('./utils/interpolate.cjs.js');
9
9
 
10
- class Animation {
11
- constructor(output, keyframes, { 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", }) {
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
12
  this.startTime = 0;
13
13
  this.rate = 1;
14
14
  this.t = 0;
@@ -19,54 +19,69 @@ class Animation {
19
19
  this.reject = reject;
20
20
  });
21
21
  const totalDuration = duration * (repeat + 1);
22
- // TODO: This isn't currently supported but keeps TypeScript happy
23
- if (easing.isCustomEasing(easing$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))
24
28
  easing$1 = "ease";
25
- }
26
29
  const interpolate$1 = interpolate.slowInterpolateNumbers(keyframes, offset, easing.isEasingList(easing$1)
27
30
  ? easing$1.map(getFunction.getEasingFunction)
28
31
  : getFunction.getEasingFunction(easing$1));
29
32
  this.tick = (timestamp) => {
30
- if (this.playState === "finished") {
31
- const latest = interpolate$1(1);
32
- output(latest);
33
- this.resolve(latest);
34
- return;
35
- }
36
- if (this.pauseTime) {
33
+ if (this.pauseTime)
37
34
  timestamp = this.pauseTime;
38
- }
39
35
  let t = (timestamp - this.startTime) * this.rate;
40
36
  this.t = t;
41
37
  // Convert to seconds
42
38
  t /= 1000;
43
39
  // Rebase on delay
44
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
+ */
45
52
  const progress = t / duration;
46
53
  // TODO progress += iterationStart
54
+ /**
55
+ * Get the current iteration (0 indexed). For instance the floor of
56
+ * 2.5 is 2.
57
+ */
47
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
+ */
48
63
  let iterationProgress = progress % 1.0;
49
64
  if (!iterationProgress && progress >= 1) {
50
65
  iterationProgress = 1;
51
66
  }
52
- if (iterationProgress === 1) {
53
- currentIteration--;
54
- }
55
- // Reverse progress
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
+ */
56
75
  const iterationIsOdd = currentIteration % 2;
57
76
  if (direction === "reverse" ||
58
77
  (direction === "alternate" && iterationIsOdd) ||
59
78
  (direction === "alternate-reverse" && !iterationIsOdd)) {
60
79
  iterationProgress = 1 - iterationProgress;
61
80
  }
62
- const interpolationIsFinished = t >= totalDuration;
63
- const interpolationProgress = interpolationIsFinished
64
- ? 1
65
- : Math.min(iterationProgress, 1);
66
- const latest = interpolate$1(interpolationProgress);
81
+ const latest = interpolate$1(t >= totalDuration ? 1 : Math.min(iterationProgress, 1));
67
82
  output(latest);
68
- const isFinished = t >= totalDuration + endDelay;
69
- if (isFinished) {
83
+ const isAnimationFinished = this.playState === "finished" || t >= totalDuration + endDelay;
84
+ if (isAnimationFinished) {
70
85
  this.playState = "finished";
71
86
  this.resolve(latest);
72
87
  }
@@ -125,9 +140,5 @@ class Animation {
125
140
  this.rate = rate;
126
141
  }
127
142
  }
128
- function animateNumber(output, keyframes = [0, 1], options = {}) {
129
- return new Animation(output, keyframes, options);
130
- }
131
143
 
132
- exports.Animation = Animation;
133
- exports.animateNumber = animateNumber;
144
+ exports.NumberAnimation = NumberAnimation;