motion 10.1.3 → 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 (102) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -0
  3. package/dist/main.cjs.js +4 -0
  4. package/dist/main.es.js +2 -0
  5. package/dist/motion.min.js +1 -1
  6. package/dist/motion.umd.js +524 -189
  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 +136 -111
  14. package/dist/targets/dom/animate-style.es.js +139 -114
  15. package/dist/targets/dom/animate.cjs.js +16 -3
  16. package/dist/targets/dom/animate.es.js +17 -4
  17. package/dist/targets/dom/data.cjs.js +4 -2
  18. package/dist/targets/dom/data.es.js +4 -2
  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 +17 -7
  22. package/dist/targets/dom/timeline/index.es.js +18 -8
  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 +7 -2
  32. package/dist/targets/dom/utils/easing.es.js +7 -3
  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} +42 -29
  46. package/dist/targets/js/{animate-number.es.js → NumberAnimation.es.js} +43 -29
  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 +64 -0
  52. package/dist/targets/js/easing/spring/generator.es.js +57 -0
  53. package/dist/targets/js/easing/spring/index.cjs.js +10 -0
  54. package/dist/targets/js/easing/spring/index.es.js +6 -0
  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/{get-function.cjs.js → utils/get-function.cjs.js} +3 -3
  58. package/dist/targets/js/easing/{get-function.es.js → utils/get-function.es.js} +3 -3
  59. package/dist/targets/js/easing/utils/has-reached-target.cjs.js +10 -0
  60. package/dist/targets/js/easing/utils/has-reached-target.es.js +6 -0
  61. package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +34 -0
  62. package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +30 -0
  63. package/dist/targets/react/hooks/use-animation.cjs.js +5 -2
  64. package/dist/targets/react/hooks/use-animation.es.js +5 -2
  65. package/dist/targets/react/utils/keyframes.cjs.js +5 -3
  66. package/dist/targets/react/utils/keyframes.es.js +6 -4
  67. package/dist/utils/is-number.cjs.js +7 -0
  68. package/dist/utils/is-number.es.js +3 -0
  69. package/dist/utils/stagger.cjs.js +3 -2
  70. package/dist/utils/stagger.es.js +3 -2
  71. package/dist/utils/velocity-per-second.cjs.js +15 -0
  72. package/dist/utils/velocity-per-second.es.js +11 -0
  73. package/package.json +8 -14
  74. package/types/index.d.ts +2 -0
  75. package/types/targets/dom/animate-style.d.ts +2 -2
  76. package/types/targets/dom/data.d.ts +1 -7
  77. package/types/targets/dom/style.d.ts +1 -1
  78. package/types/targets/dom/types.d.ts +24 -18
  79. package/types/targets/dom/utils/apply.d.ts +3 -2
  80. package/types/targets/dom/utils/controls.d.ts +3 -3
  81. package/types/targets/dom/utils/easing.d.ts +2 -1
  82. package/types/targets/dom/utils/get-style-name.d.ts +1 -0
  83. package/types/targets/dom/utils/keyframes.d.ts +1 -1
  84. package/types/targets/dom/utils/stop-animation.d.ts +1 -1
  85. package/types/targets/dom/utils/transforms.d.ts +2 -2
  86. package/types/targets/js/{animate-number.d.ts → NumberAnimation.d.ts} +2 -3
  87. package/types/targets/js/easing/glide/generator.d.ts +5 -0
  88. package/types/targets/js/easing/glide/index.d.ts +2 -0
  89. package/types/targets/js/easing/glide/types.d.ts +14 -0
  90. package/types/targets/js/easing/spring/generator.d.ts +6 -0
  91. package/types/targets/js/easing/spring/index.d.ts +2 -0
  92. package/types/targets/js/easing/spring/types.d.ts +10 -0
  93. package/types/targets/js/easing/utils/create-generator-easing.d.ts +3 -0
  94. package/types/targets/js/easing/{get-function.d.ts → utils/get-function.d.ts} +2 -2
  95. package/types/targets/js/easing/utils/has-reached-target.d.ts +1 -0
  96. package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +7 -0
  97. package/types/targets/js/types.d.ts +11 -0
  98. package/types/utils/is-number.d.ts +1 -0
  99. package/types/generators/index.d.ts +0 -2
  100. package/types/generators/spring/create.d.ts +0 -13
  101. package/types/generators/spring/index.d.ts +0 -2
  102. package/types/generators/types.d.ts +0 -7
@@ -0,0 +1,67 @@
1
+ import { pregenerateKeyframes } from './pregenerate-keyframes.es.js';
2
+
3
+ function createGeneratorEasing(createGenerator) {
4
+ const keyframesCache = new WeakMap();
5
+ return (options = {}) => {
6
+ const generatorCache = new Map();
7
+ const getGenerator = (from = 0, to = 100, velocity = 0, isScale = false) => {
8
+ const key = `${from}-${to}-${velocity}-${isScale}`;
9
+ if (!generatorCache.has(key)) {
10
+ generatorCache.set(key, createGenerator(Object.assign({ from,
11
+ to,
12
+ velocity, restSpeed: isScale ? 0.05 : 2, restDistance: isScale ? 0.01 : 0.5 }, options)));
13
+ }
14
+ return generatorCache.get(key);
15
+ };
16
+ const getKeyframes = (generator) => {
17
+ if (!keyframesCache.has(generator)) {
18
+ keyframesCache.set(generator, pregenerateKeyframes(generator));
19
+ }
20
+ return keyframesCache.get(generator);
21
+ };
22
+ return {
23
+ createAnimation: (keyframes, getOrigin, canUseGenerator, name, data) => {
24
+ let settings;
25
+ let generator;
26
+ const numKeyframes = keyframes.length;
27
+ let shouldUseGenerator = canUseGenerator &&
28
+ numKeyframes <= 2 &&
29
+ keyframes.every(isNumberOrNull);
30
+ if (shouldUseGenerator) {
31
+ const prevAnimationState = name && data && data.prevGeneratorState[name];
32
+ const velocity = prevAnimationState &&
33
+ (numKeyframes === 1 ||
34
+ (numKeyframes === 2 && keyframes[0] === null))
35
+ ? prevAnimationState.velocity
36
+ : 0;
37
+ const target = keyframes[numKeyframes - 1];
38
+ const unresolvedOrigin = numKeyframes === 1 ? null : keyframes[0];
39
+ const origin = unresolvedOrigin === null
40
+ ? prevAnimationState
41
+ ? prevAnimationState.value
42
+ : parseFloat(getOrigin())
43
+ : unresolvedOrigin;
44
+ generator = getGenerator(origin, target, velocity, name === null || name === void 0 ? void 0 : name.includes("scale"));
45
+ const keyframesMetadata = getKeyframes(generator);
46
+ settings = Object.assign(Object.assign({}, keyframesMetadata), { easing: "linear" });
47
+ }
48
+ else {
49
+ generator = getGenerator(0, 100);
50
+ const keyframesMetadata = getKeyframes(generator);
51
+ settings = {
52
+ easing: "ease",
53
+ duration: keyframesMetadata.overshootDuration,
54
+ };
55
+ }
56
+ // TODO Add test for this
57
+ if (generator && data && name) {
58
+ data.generators[name] = generator;
59
+ }
60
+ return settings;
61
+ },
62
+ };
63
+ };
64
+ }
65
+ const isNumberOrNull = (value) => typeof value !== "string";
66
+
67
+ export { createGeneratorEasing };
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var cubicBezier = require('./cubic-bezier.cjs.js');
6
- var steps = require('./steps.cjs.js');
7
- var noop = require('../../../utils/noop.cjs.js');
5
+ var cubicBezier = require('../cubic-bezier.cjs.js');
6
+ var steps = require('../steps.cjs.js');
7
+ var noop = require('../../../../utils/noop.cjs.js');
8
8
 
9
9
  const namedEasings = {
10
10
  ease: cubicBezier.cubicBezier(0.25, 0.1, 0.25, 1.0),
@@ -1,6 +1,6 @@
1
- import { cubicBezier } from './cubic-bezier.es.js';
2
- import { steps } from './steps.es.js';
3
- import { noopReturn } from '../../../utils/noop.es.js';
1
+ import { cubicBezier } from '../cubic-bezier.es.js';
2
+ import { steps } from '../steps.es.js';
3
+ import { noopReturn } from '../../../../utils/noop.es.js';
4
4
 
5
5
  const namedEasings = {
6
6
  ease: cubicBezier(0.25, 0.1, 0.25, 1.0),
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function hasReachedTarget(origin, target, current) {
6
+ return ((origin < target && current >= target) ||
7
+ (origin > target && current <= target));
8
+ }
9
+
10
+ exports.hasReachedTarget = hasReachedTarget;
@@ -0,0 +1,6 @@
1
+ function hasReachedTarget(origin, target, current) {
2
+ return ((origin < target && current >= target) ||
3
+ (origin > target && current <= target));
4
+ }
5
+
6
+ export { hasReachedTarget };
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const timeStep = 10;
6
+ const maxDuration = 10000;
7
+ function pregenerateKeyframes(generator) {
8
+ let overshootDuration = undefined;
9
+ let timestamp = timeStep;
10
+ let state = generator.next(0);
11
+ const keyframes = [state.value];
12
+ while (!state.done && timestamp < maxDuration) {
13
+ state = generator.next(timestamp);
14
+ keyframes.push(state.done ? state.target : state.value);
15
+ if (overshootDuration === undefined && state.hasReachedTarget) {
16
+ overshootDuration = timestamp;
17
+ }
18
+ timestamp += timeStep;
19
+ }
20
+ const duration = timestamp - timeStep;
21
+ /**
22
+ * If generating an animation that didn't actually move,
23
+ * generate a second keyframe so we have an origin and target.
24
+ */
25
+ if (keyframes.length === 1)
26
+ keyframes.push(state.value);
27
+ return {
28
+ keyframes,
29
+ duration: duration / 1000,
30
+ overshootDuration: (overshootDuration !== null && overshootDuration !== void 0 ? overshootDuration : duration) / 1000,
31
+ };
32
+ }
33
+
34
+ exports.pregenerateKeyframes = pregenerateKeyframes;
@@ -0,0 +1,30 @@
1
+ const timeStep = 10;
2
+ const maxDuration = 10000;
3
+ function pregenerateKeyframes(generator) {
4
+ let overshootDuration = undefined;
5
+ let timestamp = timeStep;
6
+ let state = generator.next(0);
7
+ const keyframes = [state.value];
8
+ while (!state.done && timestamp < maxDuration) {
9
+ state = generator.next(timestamp);
10
+ keyframes.push(state.done ? state.target : state.value);
11
+ if (overshootDuration === undefined && state.hasReachedTarget) {
12
+ overshootDuration = timestamp;
13
+ }
14
+ timestamp += timeStep;
15
+ }
16
+ const duration = timestamp - timeStep;
17
+ /**
18
+ * If generating an animation that didn't actually move,
19
+ * generate a second keyframe so we have an origin and target.
20
+ */
21
+ if (keyframes.length === 1)
22
+ keyframes.push(state.value);
23
+ return {
24
+ keyframes,
25
+ duration: duration / 1000,
26
+ overshootDuration: (overshootDuration !== null && overshootDuration !== void 0 ? overshootDuration : duration) / 1000,
27
+ };
28
+ }
29
+
30
+ export { pregenerateKeyframes };
@@ -28,11 +28,14 @@ function useAnimation(ref, initial, target, options$1, onStart, onComplete) {
28
28
  });
29
29
  if (Object.keys(targetKeyframe).length && ref.current) {
30
30
  onStart === null || onStart === void 0 ? void 0 : onStart(targetKeyframe);
31
- const animations = [];
31
+ const animationFactories = [];
32
32
  for (const key in targetKeyframe) {
33
33
  const animation = animateStyle.animateStyle(ref.current, key, targetKeyframe[key], options.getOptions(options$1, key));
34
- animation && animations.push(animation);
34
+ animationFactories.push(animation);
35
35
  }
36
+ const animations = animationFactories
37
+ .map((factory) => factory())
38
+ .filter(Boolean);
36
39
  Promise.all(animations.map((animation) => animation.finished))
37
40
  .then(() => onComplete === null || onComplete === void 0 ? void 0 : onComplete(targetKeyframe))
38
41
  .catch(noop.noop);
@@ -24,11 +24,14 @@ function useAnimation(ref, initial, target, options, onStart, onComplete) {
24
24
  });
25
25
  if (Object.keys(targetKeyframe).length && ref.current) {
26
26
  onStart === null || onStart === void 0 ? void 0 : onStart(targetKeyframe);
27
- const animations = [];
27
+ const animationFactories = [];
28
28
  for (const key in targetKeyframe) {
29
29
  const animation = animateStyle(ref.current, key, targetKeyframe[key], getOptions(options, key));
30
- animation && animations.push(animation);
30
+ animationFactories.push(animation);
31
31
  }
32
+ const animations = animationFactories
33
+ .map((factory) => factory())
34
+ .filter(Boolean);
32
35
  Promise.all(animations.map((animation) => animation.finished))
33
36
  .then(() => onComplete === null || onComplete === void 0 ? void 0 : onComplete(targetKeyframe))
34
37
  .catch(noop);
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var isNumber = require('../../../utils/is-number.cjs.js');
5
6
  var transforms = require('../../dom/utils/transforms.cjs.js');
6
7
 
7
8
  function convertKeyframesToStyles(keyframes) {
@@ -20,10 +21,11 @@ function convertKeyframesToStyles(keyframes) {
20
21
  * If this is a number and we have a default value type, convert the number
21
22
  * to this type.
22
23
  */
23
- const definition = transforms.transformPropertyDefinitions.get(key);
24
+ const definition = transforms.transformDefinitions.get(key);
24
25
  if (definition) {
25
- initialKeyframe =
26
- typeof value === "number" ? definition.toDefaultUnit(value) : value;
26
+ initialKeyframe = isNumber.isNumber(value)
27
+ ? definition.toDefaultUnit(value)
28
+ : value;
27
29
  }
28
30
  initialKeyframes[key] = initialKeyframe;
29
31
  }
@@ -1,4 +1,5 @@
1
- import { isTransform, transformAlias, asTransformCssVar, transformPropertyDefinitions, buildTransformTemplate } from '../../dom/utils/transforms.es.js';
1
+ import { isNumber } from '../../../utils/is-number.es.js';
2
+ import { isTransform, transformAlias, asTransformCssVar, transformDefinitions, buildTransformTemplate } from '../../dom/utils/transforms.es.js';
2
3
 
3
4
  function convertKeyframesToStyles(keyframes) {
4
5
  const initialKeyframes = {};
@@ -16,10 +17,11 @@ function convertKeyframesToStyles(keyframes) {
16
17
  * If this is a number and we have a default value type, convert the number
17
18
  * to this type.
18
19
  */
19
- const definition = transformPropertyDefinitions.get(key);
20
+ const definition = transformDefinitions.get(key);
20
21
  if (definition) {
21
- initialKeyframe =
22
- typeof value === "number" ? definition.toDefaultUnit(value) : value;
22
+ initialKeyframe = isNumber(value)
23
+ ? definition.toDefaultUnit(value)
24
+ : value;
23
25
  }
24
26
  initialKeyframes[key] = initialKeyframe;
25
27
  }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isNumber = (value) => typeof value === "number";
6
+
7
+ exports.isNumber = isNumber;
@@ -0,0 +1,3 @@
1
+ const isNumber = (value) => typeof value === "number";
2
+
3
+ export { isNumber };
@@ -2,11 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var getFunction = require('../targets/js/easing/get-function.cjs.js');
5
+ var getFunction = require('../targets/js/easing/utils/get-function.cjs.js');
6
+ var isNumber = require('./is-number.cjs.js');
6
7
 
7
8
  function stagger(duration = 0.1, { start = 0, from = 0, easing } = {}) {
8
9
  return (i, total) => {
9
- const fromIndex = typeof from === "number" ? from : getFromIndex(from, total);
10
+ const fromIndex = isNumber.isNumber(from) ? from : getFromIndex(from, total);
10
11
  const distance = Math.abs(fromIndex - i);
11
12
  let delay = duration * distance;
12
13
  if (easing) {
@@ -1,8 +1,9 @@
1
- import { getEasingFunction } from '../targets/js/easing/get-function.es.js';
1
+ import { getEasingFunction } from '../targets/js/easing/utils/get-function.es.js';
2
+ import { isNumber } from './is-number.es.js';
2
3
 
3
4
  function stagger(duration = 0.1, { start = 0, from = 0, easing } = {}) {
4
5
  return (i, total) => {
5
- const fromIndex = typeof from === "number" ? from : getFromIndex(from, total);
6
+ const fromIndex = isNumber(from) ? from : getFromIndex(from, total);
6
7
  const distance = Math.abs(fromIndex - i);
7
8
  let delay = duration * distance;
8
9
  if (easing) {
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /*
6
+ Convert velocity into velocity per second
7
+
8
+ @param [number]: Unit per frame
9
+ @param [number]: Frame duration in ms
10
+ */
11
+ function velocityPerSecond(velocity, frameDuration) {
12
+ return frameDuration ? velocity * (1000 / frameDuration) : 0;
13
+ }
14
+
15
+ exports.velocityPerSecond = velocityPerSecond;
@@ -0,0 +1,11 @@
1
+ /*
2
+ Convert velocity into velocity per second
3
+
4
+ @param [number]: Unit per frame
5
+ @param [number]: Frame duration in ms
6
+ */
7
+ function velocityPerSecond(velocity, frameDuration) {
8
+ return frameDuration ? velocity * (1000 / frameDuration) : 0;
9
+ }
10
+
11
+ export { velocityPerSecond };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "motion",
3
- "version": "10.1.3",
3
+ "version": "10.3.0",
4
4
  "description": "The Motion library for the web",
5
5
  "author": "Matt Perry",
6
6
  "main": "dist/main.cjs.js",
@@ -70,12 +70,6 @@
70
70
  "@rollup/plugin-commonjs": "^19.0.0",
71
71
  "@rollup/plugin-node-resolve": "^11.2.0",
72
72
  "@rollup/plugin-replace": "^2.4.1",
73
- "@storybook/addon-actions": "^6.2.9",
74
- "@storybook/addon-essentials": "^6.2.9",
75
- "@storybook/addon-links": "^6.2.9",
76
- "@storybook/node-logger": "^6.2.9",
77
- "@storybook/preset-create-react-app": "^3.1.7",
78
- "@storybook/react": "^6.2.9",
79
73
  "@testing-library/dom": "^8.1.0",
80
74
  "@testing-library/jest-dom": "^5.14.1",
81
75
  "@testing-library/react": "^12.0.0",
@@ -102,7 +96,7 @@
102
96
  "ts-loader": "^8.3.0",
103
97
  "typescript": "^4.4.0-beta",
104
98
  "web-animations-js": "^2.3.2",
105
- "webpack": "^4.46.0",
99
+ "webpack": "^5.58.1",
106
100
  "webpack-cli": "^4.8.0"
107
101
  },
108
102
  "husky": {
@@ -128,27 +122,27 @@
128
122
  "bundlesize": [
129
123
  {
130
124
  "path": "./dist/size-animate-dom.js",
131
- "maxSize": "3.2 kB"
125
+ "maxSize": "3.3 kB"
132
126
  },
133
127
  {
134
128
  "path": "./dist/size-animate-style.js",
135
- "maxSize": "2.8 kB"
129
+ "maxSize": "2.9 kB"
136
130
  },
137
131
  {
138
132
  "path": "./dist/size-timeline-dom.js",
139
- "maxSize": "3.95 kB"
133
+ "maxSize": "4.1 kB"
140
134
  },
141
135
  {
142
136
  "path": "./dist/size-spring.js",
143
- "maxSize": "0.6 kB"
137
+ "maxSize": "1 kB"
144
138
  },
145
139
  {
146
140
  "path": "./dist/size-react.js",
147
- "maxSize": "4.4 kB"
141
+ "maxSize": "4.5 kB"
148
142
  },
149
143
  {
150
144
  "path": "./dist/size-webpack-animate.js",
151
- "maxSize": "3.5 kB"
145
+ "maxSize": "3.4 kB"
152
146
  }
153
147
  ]
154
148
  }
package/types/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export { animate } from "./targets/dom/animate.js";
2
2
  export { animateStyle } from "./targets/dom/animate-style.js";
3
3
  export { timeline } from "./targets/dom/timeline/index.js";
4
4
  export { stagger } from "./utils/stagger.js";
5
+ export { spring } from "./targets/js/easing/spring/index.js";
6
+ export { glide } from "./targets/js/easing/glide/index.js";
5
7
  export * from "./targets/dom/types";
@@ -1,2 +1,2 @@
1
- import { AnimationOptions, BasicAnimationControls, ValueKeyframesDefinition } from "./types";
2
- export declare function animateStyle(element: Element, name: string, keyframesDefinition: ValueKeyframesDefinition, options?: AnimationOptions): BasicAnimationControls | undefined;
1
+ import { AnimationFactory, AnimationOptions, ValueKeyframesDefinition } from "./types";
2
+ export declare function animateStyle(element: Element, key: string, keyframesDefinition: ValueKeyframesDefinition, options?: AnimationOptions): AnimationFactory;
@@ -1,8 +1,2 @@
1
- import { BasicAnimationControls } from "./types";
2
- export interface AnimationData {
3
- activeTransforms: string[];
4
- activeAnimations: {
5
- [key: string]: BasicAnimationControls | undefined;
6
- };
7
- }
1
+ import { AnimationData } from "./types";
8
2
  export declare function getAnimationData(element: Element): AnimationData;
@@ -1,3 +1,3 @@
1
1
  export declare const style: {
2
- get: (element: Element, name: string) => any;
2
+ get: (element: Element, name: string) => string | undefined;
3
3
  };
@@ -1,5 +1,18 @@
1
1
  import { OptionResolver } from "../../utils/stagger";
2
+ import { AnimationGenerator, AnimationGeneratorState } from "../js/types";
2
3
  import { NextTime } from "./timeline/types";
4
+ export interface AnimationData {
5
+ transforms: string[];
6
+ animations: {
7
+ [key: string]: BasicAnimationControls | undefined;
8
+ };
9
+ generators: {
10
+ [key: string]: AnimationGenerator | undefined;
11
+ };
12
+ prevGeneratorState: {
13
+ [key: string]: AnimationGeneratorState | undefined;
14
+ };
15
+ }
3
16
  export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
4
17
  export declare type AcceptedElements = Element | Element[] | NodeListOf<Element> | string;
5
18
  export declare type BezierDefinition = [number, number, number, number];
@@ -40,18 +53,18 @@ export declare type VariableKeyframesDefinition = {
40
53
  [key: `--${string}`]: ValueKeyframesDefinition;
41
54
  };
42
55
  export declare type MotionKeyframesDefinition = StyleKeyframesDefinition & VariableKeyframesDefinition;
43
- export declare type Easing = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "steps-start" | "steps-end" | `steps(${number}, ${"start" | "end"})` | BezierDefinition;
44
- export declare type SpringOptions = {
45
- stiffness?: number;
46
- damping?: number;
47
- mass?: number;
48
- velocity?: number;
49
- restSpeed?: number;
50
- restDelta?: number;
56
+ export declare type CustomAnimationSettings = {
57
+ easing: Easing;
58
+ keyframes?: number[];
59
+ duration?: number;
60
+ };
61
+ export declare type CustomEasing = {
62
+ createAnimation: (keyframes: UnresolvedValueKeyframe[], getOrigin: () => string, isTransform: boolean, name?: string, data?: AnimationData) => CustomAnimationSettings;
51
63
  };
64
+ export declare type Easing = "linear" | "ease" | "ease-in" | "ease-out" | "ease-in-out" | "steps-start" | "steps-end" | `steps(${number}, ${"start" | "end"})` | BezierDefinition;
52
65
  export declare type KeyframeOptions = {
53
66
  duration?: number;
54
- easing?: Easing | Easing[];
67
+ easing?: CustomEasing | Easing | Easing[];
55
68
  offset?: number[];
56
69
  };
57
70
  export declare type PlaybackOptions = {
@@ -60,7 +73,7 @@ export declare type PlaybackOptions = {
60
73
  repeat?: number;
61
74
  direction?: "normal" | "reverse" | "alternate" | "alternate-reverse";
62
75
  };
63
- export declare type AnimationOptions = SpringOptions & KeyframeOptions & PlaybackOptions & {
76
+ export declare type AnimationOptions = KeyframeOptions & PlaybackOptions & {
64
77
  allowWebkitAcceleration?: boolean;
65
78
  };
66
79
  export interface AnimationWithCommitStyles extends Animation {
@@ -98,11 +111,4 @@ export interface CssPropertyDefinition {
98
111
  export declare type CssPropertyDefinitionMap = {
99
112
  [key: string]: CssPropertyDefinition;
100
113
  };
101
- export interface PregeneratedAnimation {
102
- keyframes: Array<string | number>;
103
- duration: number;
104
- }
105
- export interface KeyframeGenerator {
106
- isKeyframeGenerator: true;
107
- generate: (keyframes: number[]) => false | PregeneratedAnimation;
108
- }
114
+ export declare type AnimationFactory = () => BasicAnimationControls | undefined;
@@ -1,2 +1,3 @@
1
- export declare const createCssVariableRenderer: (element: Element, name: string) => (latest: string | number) => void;
2
- export declare const createStyleRenderer: (element: Element, name: string) => (latest: string | number) => string | number;
1
+ export declare type RendererFactory = (element: Element, name: string) => (latest: string | number) => void;
2
+ export declare const cssVariableRenderer: RendererFactory;
3
+ export declare const styleRenderer: RendererFactory;
@@ -1,10 +1,10 @@
1
- import { AnimationControls, AnimationWithCommitStyles } from "../types";
1
+ import { AnimationControls, AnimationFactory, AnimationWithCommitStyles } from "../types";
2
2
  interface AnimationState {
3
- duration: number;
4
3
  animations: AnimationWithCommitStyles[];
4
+ duration: number;
5
5
  finished?: Promise<any>;
6
6
  }
7
- export declare const createAnimationControls: (animations: AnimationWithCommitStyles[], duration: number) => AnimationControls;
7
+ export declare const createAnimations: (animationFactory: AnimationFactory[], duration: number) => AnimationControls;
8
8
  export declare const controls: {
9
9
  get: (target: AnimationState, key: string) => number | Promise<any> | (() => void) | undefined;
10
10
  set: (target: AnimationState, key: string, value: number) => boolean;
@@ -1,5 +1,6 @@
1
- import { BezierDefinition, Easing } from "../types";
1
+ import { BezierDefinition, CustomEasing, Easing } from "../types";
2
2
  export declare const isCubicBezier: (easing: Easing | Easing[]) => easing is BezierDefinition;
3
3
  export declare const isEasingList: (easing: Easing | Easing[]) => easing is Easing[];
4
+ export declare const isCustomEasing: (easing: Easing | Easing[] | CustomEasing) => easing is CustomEasing;
4
5
  export declare const convertEasing: (easing: Easing) => string;
5
6
  export declare const cubicBezierAsString: ([a, b, c, d]: BezierDefinition) => string;
@@ -0,0 +1 @@
1
+ export declare function getStyleName(key: string): string;
@@ -1,3 +1,3 @@
1
1
  import { UnresolvedValueKeyframe, ValueKeyframe } from "../types";
2
- export declare function hydrateKeyframes(keyframes: UnresolvedValueKeyframe[], element: Element, name: string): ValueKeyframe[];
2
+ export declare function hydrateKeyframes(keyframes: UnresolvedValueKeyframe[], readInitialValue: () => string | number): ValueKeyframe[];
3
3
  export declare const keyframesList: (keyframes: UnresolvedValueKeyframe | UnresolvedValueKeyframe[]) => UnresolvedValueKeyframe[];
@@ -3,4 +3,4 @@ export interface WithCommitStyles {
3
3
  commitStyles: VoidFunction;
4
4
  cancel: VoidFunction;
5
5
  }
6
- export declare function stopAnimation(animation: BasicAnimationControls): void;
6
+ export declare function stopAnimation(animation?: BasicAnimationControls): void;
@@ -9,7 +9,7 @@ export declare const transformAlias: {
9
9
  y: string;
10
10
  z: string;
11
11
  };
12
- export declare const transformPropertyDefinitions: Map<string, CssPropertyDefinition>;
12
+ export declare const transformDefinitions: Map<string, CssPropertyDefinition>;
13
13
  export declare const asTransformCssVar: (name: string) => string;
14
14
  /**
15
15
  * A function to use with Array.sort to sort transform keys by their default order.
@@ -17,4 +17,4 @@ export declare const asTransformCssVar: (name: string) => string;
17
17
  export declare const compareTransformOrder: (a: string, b: string) => number;
18
18
  export declare const isTransform: (name: string) => boolean;
19
19
  export declare const addTransformToElement: (element: HTMLElement, name: string) => void;
20
- export declare const buildTransformTemplate: (activeTransforms: string[]) => string;
20
+ export declare const buildTransformTemplate: (transforms: string[]) => string;
@@ -1,5 +1,5 @@
1
1
  import { AnimationControls, AnimationOptions } from "../dom/types";
2
- export declare class Animation implements Omit<AnimationControls, "stop" | "duration"> {
2
+ export declare class NumberAnimation implements Omit<AnimationControls, "stop" | "duration"> {
3
3
  private resolve;
4
4
  private reject;
5
5
  private startTime;
@@ -9,7 +9,7 @@ export declare class Animation implements Omit<AnimationControls, "stop" | "dura
9
9
  private t;
10
10
  private cancelT;
11
11
  playState: AnimationPlayState;
12
- constructor(output: (v: number) => void, keyframes: number[], { easing, duration, delay, endDelay, offset, repeat, direction, }: AnimationOptions);
12
+ constructor(output: (v: number) => void, keyframes?: number[], { easing, duration, delay, endDelay, repeat, offset, direction, }?: AnimationOptions);
13
13
  finished: Promise<unknown>;
14
14
  play(): void;
15
15
  pause(): void;
@@ -22,4 +22,3 @@ export declare class Animation implements Omit<AnimationControls, "stop" | "dura
22
22
  get playbackRate(): number;
23
23
  set playbackRate(rate: number);
24
24
  }
25
- export declare function animateNumber(output: (v: number) => void, keyframes?: number[], options?: AnimationOptions): Animation;
@@ -0,0 +1,5 @@
1
+ import { GlideOptions } from "./types";
2
+ import { AnimationGeneratorState } from "../../types";
3
+ export declare const createGlideGenerator: ({ from, velocity, power, decay, bounceDamping, bounceStiffness, changeTarget, min, max, restDistance, restSpeed, }: GlideOptions) => {
4
+ next: (t: number) => AnimationGeneratorState;
5
+ };
@@ -0,0 +1,2 @@
1
+ import { GlideOptions } from "./types";
2
+ export declare const glide: (options?: GlideOptions) => import("../../../..").CustomEasing;
@@ -0,0 +1,14 @@
1
+ export interface GlideOptions {
2
+ power?: number;
3
+ decay?: number;
4
+ changeTarget?: (v: number) => number;
5
+ max?: number;
6
+ min?: number;
7
+ bounceDamping?: number;
8
+ bounceStiffness?: number;
9
+ restSpeed?: number;
10
+ restDistance?: number;
11
+ from?: number;
12
+ to?: number;
13
+ velocity?: number;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { AnimationGenerator } from "../../types";
2
+ import { SpringOptions } from "./types";
3
+ export declare const calcDampingRatio: (stiffness?: number, damping?: number, mass?: number) => number;
4
+ export declare const calcAngularFreq: (undampedFreq: number, dampingRatio: number) => number;
5
+ export declare const createSpringGenerator: ({ stiffness, damping, mass, from, to, velocity, restSpeed, restDistance, }?: SpringOptions) => AnimationGenerator;
6
+ export declare function calcVelocity(resolveValue: (v: number) => number, t: number, current: number): number;
@@ -0,0 +1,2 @@
1
+ import { SpringOptions } from "./types";
2
+ export declare const spring: (options?: SpringOptions) => import("../../../..").CustomEasing;
@@ -0,0 +1,10 @@
1
+ export interface SpringOptions {
2
+ stiffness?: number;
3
+ damping?: number;
4
+ mass?: number;
5
+ restSpeed?: number;
6
+ restDistance?: number;
7
+ from?: number;
8
+ to?: number;
9
+ velocity?: number;
10
+ }
@@ -0,0 +1,3 @@
1
+ import { CustomEasing } from "../../../..";
2
+ import { AnimationGeneratorFactory } from "../../types";
3
+ export declare function createGeneratorEasing<Options extends {} = {}>(createGenerator: AnimationGeneratorFactory<Options>): (options?: Options) => CustomEasing;