motion 10.4.0 → 10.5.0-alpha.1

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 (203) 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 +8 -1292
  6. package/dist/size-index.js +1 -0
  7. package/lib/index.js +5 -0
  8. package/lib/index.js.map +1 -0
  9. package/package.json +5 -138
  10. package/types/index.d.ts +3 -7
  11. package/types/index.d.ts.map +1 -0
  12. package/CHANGELOG.md +0 -103
  13. package/LICENSE +0 -21
  14. package/dist/react.cjs.js +0 -9
  15. package/dist/react.es.js +0 -1
  16. package/dist/size-animate-dom.js +0 -1
  17. package/dist/size-animate-style.js +0 -1
  18. package/dist/size-react.js +0 -1
  19. package/dist/size-spring.js +0 -1
  20. package/dist/size-timeline-dom.js +0 -1
  21. package/dist/size-webpack-animate.js +0 -1
  22. package/dist/targets/dom/animate-style.cjs.js +0 -182
  23. package/dist/targets/dom/animate-style.es.js +0 -178
  24. package/dist/targets/dom/animate.cjs.js +0 -42
  25. package/dist/targets/dom/animate.es.js +0 -38
  26. package/dist/targets/dom/data.cjs.js +0 -18
  27. package/dist/targets/dom/data.es.js +0 -14
  28. package/dist/targets/dom/style.cjs.js +0 -22
  29. package/dist/targets/dom/style.es.js +0 -18
  30. package/dist/targets/dom/timeline/index.cjs.js +0 -190
  31. package/dist/targets/dom/timeline/index.es.js +0 -185
  32. package/dist/targets/dom/timeline/utils/calc-time.cjs.js +0 -23
  33. package/dist/targets/dom/timeline/utils/calc-time.es.js +0 -19
  34. package/dist/targets/dom/timeline/utils/edit.cjs.js +0 -36
  35. package/dist/targets/dom/timeline/utils/edit.es.js +0 -31
  36. package/dist/targets/dom/timeline/utils/sort.cjs.js +0 -14
  37. package/dist/targets/dom/timeline/utils/sort.es.js +0 -10
  38. package/dist/targets/dom/utils/apply.cjs.js +0 -9
  39. package/dist/targets/dom/utils/apply.es.js +0 -4
  40. package/dist/targets/dom/utils/controls.cjs.js +0 -59
  41. package/dist/targets/dom/utils/controls.es.js +0 -54
  42. package/dist/targets/dom/utils/css-var.cjs.js +0 -29
  43. package/dist/targets/dom/utils/css-var.es.js +0 -23
  44. package/dist/targets/dom/utils/defaults.cjs.js +0 -13
  45. package/dist/targets/dom/utils/defaults.es.js +0 -9
  46. package/dist/targets/dom/utils/easing.cjs.js +0 -18
  47. package/dist/targets/dom/utils/easing.es.js +0 -10
  48. package/dist/targets/dom/utils/feature-detection.cjs.js +0 -31
  49. package/dist/targets/dom/utils/feature-detection.es.js +0 -27
  50. package/dist/targets/dom/utils/get-style-name.cjs.js +0 -13
  51. package/dist/targets/dom/utils/get-style-name.es.js +0 -9
  52. package/dist/targets/dom/utils/keyframes.cjs.js +0 -16
  53. package/dist/targets/dom/utils/keyframes.es.js +0 -11
  54. package/dist/targets/dom/utils/options.cjs.js +0 -13
  55. package/dist/targets/dom/utils/options.es.js +0 -9
  56. package/dist/targets/dom/utils/resolve-elements.cjs.js +0 -22
  57. package/dist/targets/dom/utils/resolve-elements.es.js +0 -18
  58. package/dist/targets/dom/utils/stop-animation.cjs.js +0 -19
  59. package/dist/targets/dom/utils/stop-animation.es.js +0 -15
  60. package/dist/targets/dom/utils/time.cjs.js +0 -7
  61. package/dist/targets/dom/utils/time.es.js +0 -3
  62. package/dist/targets/dom/utils/transforms.cjs.js +0 -85
  63. package/dist/targets/dom/utils/transforms.es.js +0 -74
  64. package/dist/targets/js/NumberAnimation.cjs.js +0 -144
  65. package/dist/targets/js/NumberAnimation.es.js +0 -140
  66. package/dist/targets/js/easing/cubic-bezier.cjs.js +0 -57
  67. package/dist/targets/js/easing/cubic-bezier.es.js +0 -53
  68. package/dist/targets/js/easing/glide/generator.cjs.js +0 -99
  69. package/dist/targets/js/easing/glide/generator.es.js +0 -95
  70. package/dist/targets/js/easing/glide/index.cjs.js +0 -10
  71. package/dist/targets/js/easing/glide/index.es.js +0 -6
  72. package/dist/targets/js/easing/spring/generator.cjs.js +0 -64
  73. package/dist/targets/js/easing/spring/generator.es.js +0 -57
  74. package/dist/targets/js/easing/spring/index.cjs.js +0 -10
  75. package/dist/targets/js/easing/spring/index.es.js +0 -6
  76. package/dist/targets/js/easing/steps.cjs.js +0 -15
  77. package/dist/targets/js/easing/steps.es.js +0 -11
  78. package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +0 -71
  79. package/dist/targets/js/easing/utils/create-generator-easing.es.js +0 -67
  80. package/dist/targets/js/easing/utils/get-function.cjs.js +0 -37
  81. package/dist/targets/js/easing/utils/get-function.es.js +0 -33
  82. package/dist/targets/js/easing/utils/has-reached-target.cjs.js +0 -10
  83. package/dist/targets/js/easing/utils/has-reached-target.es.js +0 -6
  84. package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +0 -34
  85. package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +0 -30
  86. package/dist/targets/js/utils/get-easing.cjs.js +0 -14
  87. package/dist/targets/js/utils/get-easing.es.js +0 -10
  88. package/dist/targets/js/utils/interpolate.cjs.js +0 -35
  89. package/dist/targets/js/utils/interpolate.es.js +0 -31
  90. package/dist/targets/js/utils/offset.cjs.js +0 -22
  91. package/dist/targets/js/utils/offset.es.js +0 -17
  92. package/dist/targets/react/animated.cjs.js +0 -126
  93. package/dist/targets/react/animated.es.js +0 -101
  94. package/dist/targets/react/context.cjs.js +0 -9
  95. package/dist/targets/react/context.es.js +0 -5
  96. package/dist/targets/react/hooks/use-animation.cjs.js +0 -47
  97. package/dist/targets/react/hooks/use-animation.es.js +0 -43
  98. package/dist/targets/react/hooks/use-exit.cjs.js +0 -27
  99. package/dist/targets/react/hooks/use-exit.es.js +0 -23
  100. package/dist/targets/react/hooks/use-gesture-state.cjs.js +0 -17
  101. package/dist/targets/react/hooks/use-gesture-state.es.js +0 -13
  102. package/dist/targets/react/hooks/use-hover.cjs.js +0 -24
  103. package/dist/targets/react/hooks/use-hover.es.js +0 -20
  104. package/dist/targets/react/hooks/use-press.cjs.js +0 -25
  105. package/dist/targets/react/hooks/use-press.es.js +0 -21
  106. package/dist/targets/react/hooks/use-viewport.cjs.js +0 -37
  107. package/dist/targets/react/hooks/use-viewport.es.js +0 -33
  108. package/dist/targets/react/index.cjs.js +0 -17
  109. package/dist/targets/react/index.es.js +0 -13
  110. package/dist/targets/react/utils/has-changed.cjs.js +0 -24
  111. package/dist/targets/react/utils/has-changed.es.js +0 -19
  112. package/dist/targets/react/utils/keyframes.cjs.js +0 -38
  113. package/dist/targets/react/utils/keyframes.es.js +0 -34
  114. package/dist/targets/react/utils/poses.cjs.js +0 -14
  115. package/dist/targets/react/utils/poses.es.js +0 -10
  116. package/dist/targets/react/utils/update-target.cjs.js +0 -20
  117. package/dist/targets/react/utils/update-target.es.js +0 -16
  118. package/dist/utils/array.cjs.js +0 -14
  119. package/dist/utils/array.es.js +0 -9
  120. package/dist/utils/clamp.cjs.js +0 -7
  121. package/dist/utils/clamp.es.js +0 -3
  122. package/dist/utils/is-number.cjs.js +0 -7
  123. package/dist/utils/is-number.es.js +0 -3
  124. package/dist/utils/mix.cjs.js +0 -28
  125. package/dist/utils/mix.es.js +0 -24
  126. package/dist/utils/noop.cjs.js +0 -9
  127. package/dist/utils/noop.es.js +0 -4
  128. package/dist/utils/progress.cjs.js +0 -20
  129. package/dist/utils/progress.es.js +0 -16
  130. package/dist/utils/stagger.cjs.js +0 -38
  131. package/dist/utils/stagger.es.js +0 -32
  132. package/dist/utils/velocity-per-second.cjs.js +0 -15
  133. package/dist/utils/velocity-per-second.es.js +0 -11
  134. package/dist/utils/wrap.cjs.js +0 -10
  135. package/dist/utils/wrap.es.js +0 -6
  136. package/react/package.json +0 -6
  137. package/types/react-entry.d.ts +0 -2
  138. package/types/targets/dom/animate-style.d.ts +0 -2
  139. package/types/targets/dom/animate.d.ts +0 -2
  140. package/types/targets/dom/data.d.ts +0 -2
  141. package/types/targets/dom/style.d.ts +0 -3
  142. package/types/targets/dom/timeline/index.d.ts +0 -15
  143. package/types/targets/dom/timeline/types.d.ts +0 -13
  144. package/types/targets/dom/timeline/utils/calc-time.d.ts +0 -2
  145. package/types/targets/dom/timeline/utils/edit.d.ts +0 -4
  146. package/types/targets/dom/timeline/utils/sort.d.ts +0 -2
  147. package/types/targets/dom/types.d.ts +0 -114
  148. package/types/targets/dom/utils/apply.d.ts +0 -3
  149. package/types/targets/dom/utils/controls.d.ts +0 -12
  150. package/types/targets/dom/utils/css-var.d.ts +0 -3
  151. package/types/targets/dom/utils/defaults.d.ts +0 -8
  152. package/types/targets/dom/utils/easing.d.ts +0 -6
  153. package/types/targets/dom/utils/feature-detection.d.ts +0 -8
  154. package/types/targets/dom/utils/get-style-name.d.ts +0 -1
  155. package/types/targets/dom/utils/keyframes.d.ts +0 -3
  156. package/types/targets/dom/utils/options.d.ts +0 -2
  157. package/types/targets/dom/utils/resolve-elements.d.ts +0 -4
  158. package/types/targets/dom/utils/stop-animation.d.ts +0 -6
  159. package/types/targets/dom/utils/time.d.ts +0 -1
  160. package/types/targets/dom/utils/transforms.d.ts +0 -20
  161. package/types/targets/js/NumberAnimation.d.ts +0 -24
  162. package/types/targets/js/easing/cubic-bezier.d.ts +0 -1
  163. package/types/targets/js/easing/glide/generator.d.ts +0 -5
  164. package/types/targets/js/easing/glide/index.d.ts +0 -2
  165. package/types/targets/js/easing/glide/types.d.ts +0 -14
  166. package/types/targets/js/easing/spring/generator.d.ts +0 -6
  167. package/types/targets/js/easing/spring/index.d.ts +0 -2
  168. package/types/targets/js/easing/spring/types.d.ts +0 -10
  169. package/types/targets/js/easing/steps.d.ts +0 -3
  170. package/types/targets/js/easing/utils/create-generator-easing.d.ts +0 -3
  171. package/types/targets/js/easing/utils/get-function.d.ts +0 -3
  172. package/types/targets/js/easing/utils/has-reached-target.d.ts +0 -1
  173. package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +0 -7
  174. package/types/targets/js/types.d.ts +0 -12
  175. package/types/targets/js/utils/get-easing.d.ts +0 -1
  176. package/types/targets/js/utils/interpolate.d.ts +0 -2
  177. package/types/targets/js/utils/offset.d.ts +0 -2
  178. package/types/targets/react/animated.d.ts +0 -3
  179. package/types/targets/react/context.d.ts +0 -3
  180. package/types/targets/react/hooks/use-animation.d.ts +0 -4
  181. package/types/targets/react/hooks/use-exit.d.ts +0 -3
  182. package/types/targets/react/hooks/use-gesture-state.d.ts +0 -4
  183. package/types/targets/react/hooks/use-hover.d.ts +0 -4
  184. package/types/targets/react/hooks/use-press.d.ts +0 -4
  185. package/types/targets/react/hooks/use-viewport.d.ts +0 -4
  186. package/types/targets/react/index.d.ts +0 -2
  187. package/types/targets/react/types.d.ts +0 -108
  188. package/types/targets/react/utils/has-changed.d.ts +0 -2
  189. package/types/targets/react/utils/keyframes.d.ts +0 -3
  190. package/types/targets/react/utils/poses.d.ts +0 -2
  191. package/types/targets/react/utils/supported-elements.d.ts +0 -8
  192. package/types/targets/react/utils/update-target.d.ts +0 -3
  193. package/types/utils/array.d.ts +0 -2
  194. package/types/utils/clamp.d.ts +0 -1
  195. package/types/utils/interpolate.d.ts +0 -0
  196. package/types/utils/is-number.d.ts +0 -1
  197. package/types/utils/mix.d.ts +0 -1
  198. package/types/utils/noop.d.ts +0 -2
  199. package/types/utils/progress.d.ts +0 -1
  200. package/types/utils/stagger.d.ts +0 -12
  201. package/types/utils/value-types.d.ts +0 -0
  202. package/types/utils/velocity-per-second.d.ts +0 -1
  203. package/types/utils/wrap.d.ts +0 -1
@@ -1,178 +0,0 @@
1
- import { getAnimationData } from './data.es.js';
2
- import { isCssVar, registerCssVariable } from './utils/css-var.es.js';
3
- import { noop } from '../../utils/noop.es.js';
4
- import { ms } from './utils/time.es.js';
5
- import { isTransform, addTransformToElement, transformDefinitions } from './utils/transforms.es.js';
6
- import { isCustomEasing, isEasingList, convertEasing } from './utils/easing.es.js';
7
- import { supports } from './utils/feature-detection.es.js';
8
- import { cssVariableRenderer, styleRenderer } from './utils/apply.es.js';
9
- import { NumberAnimation } from '../js/NumberAnimation.es.js';
10
- import { hydrateKeyframes, keyframesList } from './utils/keyframes.es.js';
11
- import { style } from './style.es.js';
12
- import { defaults } from './utils/defaults.es.js';
13
- import { getStyleName } from './utils/get-style-name.es.js';
14
- import { isNumber } from '../../utils/is-number.es.js';
15
- import { stopAnimation } from './utils/stop-animation.es.js';
16
-
17
- function animateStyle(element, key, keyframesDefinition, options = {}) {
18
- let animation;
19
- let { duration = defaults.duration, delay = defaults.delay, endDelay = defaults.endDelay, repeat = defaults.repeat, easing = defaults.easing, direction, offset, allowWebkitAcceleration = false, } = options;
20
- const data = getAnimationData(element);
21
- let canAnimateNatively = supports.waapi();
22
- let render = noop;
23
- const valueIsTransform = isTransform(key);
24
- /**
25
- * If this is an individual transform, we need to map its
26
- * key to a CSS variable and update the element's transform style
27
- */
28
- valueIsTransform && addTransformToElement(element, key);
29
- const name = getStyleName(key);
30
- /**
31
- * Get definition of value, this will be used to convert numerical
32
- * keyframes into the default value type.
33
- */
34
- const definition = transformDefinitions.get(name);
35
- /**
36
- * Stop the current animation, if any. Because this will trigger
37
- * commitStyles (DOM writes) and we might later trigger DOM reads,
38
- * this is fired now and we return a factory function to create
39
- * the actual animation that can get called in batch,
40
- */
41
- stopAnimation(data.animations[name]);
42
- /**
43
- * Batchable factory function containing all DOM reads.
44
- */
45
- return () => {
46
- const readInitialValue = () => { var _a, _b; return (_b = (_a = style.get(element, name)) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.initialValue) !== null && _b !== void 0 ? _b : 0; };
47
- /**
48
- * Replace null values with the previous keyframe value, or read
49
- * it from the DOM if it's the first keyframe.
50
- */
51
- let keyframes = hydrateKeyframes(keyframesList(keyframesDefinition), readInitialValue);
52
- if (isCustomEasing(easing)) {
53
- const custom = easing.createAnimation(keyframes, readInitialValue, valueIsTransform, name, data);
54
- easing = custom.easing;
55
- if (custom.keyframes !== undefined)
56
- keyframes = custom.keyframes;
57
- if (custom.duration !== undefined)
58
- duration = custom.duration;
59
- }
60
- /**
61
- * If this is a CSS variable we need to register it with the browser
62
- * before it can be animated natively. We also set it with setProperty
63
- * rather than directly onto the element.style object.
64
- */
65
- if (isCssVar(name)) {
66
- render = cssVariableRenderer(element, name);
67
- if (supports.cssRegisterProperty()) {
68
- registerCssVariable(name);
69
- }
70
- else {
71
- canAnimateNatively = false;
72
- }
73
- }
74
- else {
75
- render = styleRenderer(element, name);
76
- }
77
- /**
78
- * If we can animate this value with WAAPI, do so. Currently this only
79
- * feature detects CSS.registerProperty but could check WAAPI too.
80
- */
81
- if (canAnimateNatively) {
82
- /**
83
- * Convert numbers to default value types. Currently this only supports
84
- * transforms but it could also support other value types.
85
- */
86
- if (definition) {
87
- keyframes = keyframes.map((value) => isNumber(value) ? definition.toDefaultUnit(value) : value);
88
- }
89
- /**
90
- * If this browser doesn't support partial/implicit keyframes we need to
91
- * explicitly provide one.
92
- */
93
- if (!supports.partialKeyframes() && keyframes.length === 1) {
94
- keyframes.unshift(readInitialValue());
95
- }
96
- const animationOptions = {
97
- delay: ms(delay),
98
- duration: ms(duration),
99
- endDelay: ms(endDelay),
100
- easing: !isEasingList(easing) ? convertEasing(easing) : undefined,
101
- direction,
102
- iterations: repeat + 1,
103
- fill: "both",
104
- };
105
- animation = element.animate({
106
- [name]: keyframes,
107
- offset,
108
- easing: isEasingList(easing) ? easing.map(convertEasing) : undefined,
109
- }, animationOptions);
110
- /**
111
- * Polyfill finished Promise in browsers that don't support it
112
- */
113
- if (!animation.finished) {
114
- animation.finished = new Promise((resolve, reject) => {
115
- animation.onfinish = resolve;
116
- animation.oncancel = reject;
117
- });
118
- }
119
- const target = keyframes[keyframes.length - 1];
120
- animation.finished
121
- .then(() => {
122
- // Apply styles to target
123
- render(target);
124
- // Ensure fill modes don't persist
125
- animation.cancel();
126
- })
127
- .catch(noop);
128
- /**
129
- * This forces Webkit to run animations on the main thread by exploiting
130
- * this condition:
131
- * https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp?rev=281238#L1099
132
- *
133
- * This fixes Webkit's timing bugs, like accelerated animations falling
134
- * out of sync with main thread animations and massive delays in starting
135
- * accelerated animations in WKWebView.
136
- */
137
- if (!allowWebkitAcceleration)
138
- animation.playbackRate = 1.000001;
139
- /**
140
- * If we can't animate the value natively then we can fallback to the numbers-only
141
- * polyfill for transforms. All keyframes must be numerical.
142
- */
143
- }
144
- else if (valueIsTransform && keyframes.every(isNumber)) {
145
- /**
146
- * If we only have a single keyframe, we need to create an initial keyframe by reading
147
- * the current value from the DOM.
148
- */
149
- if (keyframes.length === 1) {
150
- keyframes.unshift(parseFloat(readInitialValue()));
151
- }
152
- if (definition) {
153
- const applyStyle = render;
154
- render = (v) => applyStyle(definition.toDefaultUnit(v));
155
- }
156
- animation = new NumberAnimation(render, keyframes, Object.assign(Object.assign({}, options), { duration,
157
- easing }));
158
- }
159
- else {
160
- const target = keyframes[keyframes.length - 1];
161
- render(definition && isNumber(target)
162
- ? definition.toDefaultUnit(target)
163
- : target);
164
- }
165
- data.animations[name] = animation;
166
- /**
167
- * When an animation finishes, delete the reference to the previous animation.
168
- */
169
- animation === null || animation === void 0 ? void 0 : animation.finished.then(() => {
170
- data.animations[name] = undefined;
171
- data.generators[name] = undefined;
172
- data.prevGeneratorState[name] = undefined;
173
- }).catch(noop);
174
- return animation;
175
- };
176
- }
177
-
178
- export { animateStyle };
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var animateStyle = require('./animate-style.cjs.js');
6
- var options = require('./utils/options.cjs.js');
7
- var resolveElements = require('./utils/resolve-elements.cjs.js');
8
- var controls = require('./utils/controls.cjs.js');
9
- var stagger = require('../../utils/stagger.cjs.js');
10
- var defaults = require('./utils/defaults.cjs.js');
11
-
12
- function animate(elements, keyframes, options$1 = {}) {
13
- var _a;
14
- elements = resolveElements.resolveElements(elements);
15
- const numElements = elements.length;
16
- /**
17
- * Create and start new animations
18
- */
19
- const animationFactories = [];
20
- for (let i = 0; i < numElements; i++) {
21
- const element = elements[i];
22
- for (const key in keyframes) {
23
- const valueOptions = options.getOptions(options$1, key);
24
- valueOptions.delay = stagger.resolveOption(valueOptions.delay, i, numElements);
25
- const animation = animateStyle.animateStyle(element, key, keyframes[key], valueOptions);
26
- animationFactories.push(animation);
27
- }
28
- }
29
- return controls.createAnimations(animationFactories,
30
- /**
31
- * TODO:
32
- * If easing is set to spring or glide, duration will be dynamically
33
- * generated. Ideally we would dynamically generate this from
34
- * animation.effect.getComputedTiming().duration but this isn't
35
- * supported in iOS13 or our number polyfill. Perhaps it's possible
36
- * to Proxy animations returned from animateStyle that has duration
37
- * as a getter.
38
- */
39
- (_a = options$1.duration) !== null && _a !== void 0 ? _a : defaults.defaults.duration);
40
- }
41
-
42
- exports.animate = animate;
@@ -1,38 +0,0 @@
1
- import { animateStyle } from './animate-style.es.js';
2
- import { getOptions } from './utils/options.es.js';
3
- import { resolveElements } from './utils/resolve-elements.es.js';
4
- import { createAnimations } from './utils/controls.es.js';
5
- import { resolveOption } from '../../utils/stagger.es.js';
6
- import { defaults } from './utils/defaults.es.js';
7
-
8
- function animate(elements, keyframes, options = {}) {
9
- var _a;
10
- elements = resolveElements(elements);
11
- const numElements = elements.length;
12
- /**
13
- * Create and start new animations
14
- */
15
- const animationFactories = [];
16
- for (let i = 0; i < numElements; i++) {
17
- const element = elements[i];
18
- for (const key in keyframes) {
19
- const valueOptions = getOptions(options, key);
20
- valueOptions.delay = resolveOption(valueOptions.delay, i, numElements);
21
- const animation = animateStyle(element, key, keyframes[key], valueOptions);
22
- animationFactories.push(animation);
23
- }
24
- }
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
- */
35
- (_a = options.duration) !== null && _a !== void 0 ? _a : defaults.duration);
36
- }
37
-
38
- export { animate };
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const data = new WeakMap();
6
- function getAnimationData(element) {
7
- if (!data.has(element)) {
8
- data.set(element, {
9
- transforms: [],
10
- animations: {},
11
- generators: {},
12
- prevGeneratorState: {},
13
- });
14
- }
15
- return data.get(element);
16
- }
17
-
18
- exports.getAnimationData = getAnimationData;
@@ -1,14 +0,0 @@
1
- const data = new WeakMap();
2
- function getAnimationData(element) {
3
- if (!data.has(element)) {
4
- data.set(element, {
5
- transforms: [],
6
- animations: {},
7
- generators: {},
8
- prevGeneratorState: {},
9
- });
10
- }
11
- return data.get(element);
12
- }
13
-
14
- export { getAnimationData };
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var cssVar = require('./utils/css-var.cjs.js');
6
- var transforms = require('./utils/transforms.cjs.js');
7
-
8
- const style = {
9
- get: (element, name) => {
10
- let value = cssVar.isCssVar(name)
11
- ? element.style.getPropertyValue(name)
12
- : getComputedStyle(element)[name];
13
- if (!value && value !== 0) {
14
- const definition = transforms.transformDefinitions.get(name);
15
- if (definition)
16
- value = definition.initialValue;
17
- }
18
- return value;
19
- },
20
- };
21
-
22
- exports.style = style;
@@ -1,18 +0,0 @@
1
- import { isCssVar } from './utils/css-var.es.js';
2
- import { transformDefinitions } from './utils/transforms.es.js';
3
-
4
- const style = {
5
- get: (element, name) => {
6
- let value = isCssVar(name)
7
- ? element.style.getPropertyValue(name)
8
- : getComputedStyle(element)[name];
9
- if (!value && value !== 0) {
10
- const definition = transformDefinitions.get(name);
11
- if (definition)
12
- value = definition.initialValue;
13
- }
14
- return value;
15
- },
16
- };
17
-
18
- export { style };
@@ -1,190 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var tslib = require('tslib');
6
- var heyListen = require('hey-listen');
7
- var progress = require('../../../utils/progress.cjs.js');
8
- var stagger = require('../../../utils/stagger.cjs.js');
9
- var offset = require('../../js/utils/offset.cjs.js');
10
- var animateStyle = require('../animate-style.cjs.js');
11
- var controls = require('../utils/controls.cjs.js');
12
- var defaults = require('../utils/defaults.cjs.js');
13
- var easing = require('../utils/easing.cjs.js');
14
- var keyframes = require('../utils/keyframes.cjs.js');
15
- var options = require('../utils/options.cjs.js');
16
- var resolveElements = require('../utils/resolve-elements.cjs.js');
17
- var transforms = require('../utils/transforms.cjs.js');
18
- var calcTime = require('./utils/calc-time.cjs.js');
19
- var edit = require('./utils/edit.cjs.js');
20
- var sort = require('./utils/sort.cjs.js');
21
-
22
- function timeline(definition, options = {}) {
23
- var _a, _b;
24
- const animationDefinitions = createAnimationsFromTimeline(definition, options);
25
- /**
26
- * Create and start animations
27
- */
28
- const animationFactories = animationDefinitions
29
- .map((definition) => animateStyle.animateStyle(...definition))
30
- .filter(Boolean);
31
- return controls.createAnimations(animationFactories,
32
- // Get the duration from the first animation definition
33
- (_b = (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration) !== null && _b !== void 0 ? _b : defaults.defaults.duration);
34
- }
35
- function createAnimationsFromTimeline(definition, _a = {}) {
36
- var { defaultOptions = {} } = _a, timelineOptions = tslib.__rest(_a, ["defaultOptions"]);
37
- const animationDefinitions = [];
38
- const elementSequences = new Map();
39
- const elementCache = {};
40
- const timeLabels = new Map();
41
- let prevTime = 0;
42
- let currentTime = 0;
43
- let totalDuration = 0;
44
- /**
45
- * Build the timeline by mapping over the definition array and converting
46
- * the definitions into keyframes and offsets with absolute time values.
47
- * These will later get converted into relative offsets in a second pass.
48
- */
49
- for (let i = 0; i < definition.length; i++) {
50
- const [elementDefinition, keyframes$1, options$1 = {}] = definition[i];
51
- /**
52
- * If a relative or absolute time value has been specified we need to resolve
53
- * it in relation to the currentTime.
54
- */
55
- if (options$1.at !== undefined) {
56
- currentTime = calcTime.calcNextTime(currentTime, options$1.at, prevTime, timeLabels);
57
- }
58
- /**
59
- * Keep track of the maximum duration in this definition. This will be
60
- * applied to currentTime once the definition has been parsed.
61
- */
62
- let maxDuration = 0;
63
- /**
64
- * Find all the elements specified in the definition and parse value
65
- * keyframes from their timeline definitions.
66
- */
67
- const elements = resolveElements.resolveElements(elementDefinition, elementCache);
68
- const numElements = elements.length;
69
- for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
70
- const element = elements[elementIndex];
71
- const elementSequence = getElementSequence(element, elementSequences);
72
- for (const key in keyframes$1) {
73
- const valueSequence = getValueSequence(key, elementSequence);
74
- let valueKeyframes = keyframes.keyframesList(keyframes$1[key]);
75
- const valueOptions = options.getOptions(options$1, key);
76
- let { duration = defaultOptions.duration || defaults.defaults.duration, easing: easing$1 = defaultOptions.easing || defaults.defaults.easing, } = valueOptions;
77
- if (easing.isCustomEasing(easing$1)) {
78
- const valueIsTransform = transforms.isTransform(key);
79
- heyListen.invariant(valueKeyframes.length === 2 || !valueIsTransform, "spring must be provided 2 keyframes within timeline");
80
- const custom = easing$1.createAnimation(valueKeyframes,
81
- // TODO We currently only support explicit keyframes
82
- // so this doesn't currently read from the DOM
83
- () => "0", valueIsTransform);
84
- easing$1 = custom.easing;
85
- if (custom.keyframes !== undefined)
86
- valueKeyframes = custom.keyframes;
87
- if (custom.duration !== undefined)
88
- duration = custom.duration;
89
- }
90
- const delay = stagger.resolveOption(options$1.delay, elementIndex, numElements) || 0;
91
- const startTime = currentTime + delay;
92
- const targetTime = startTime + duration;
93
- /**
94
- *
95
- */
96
- let { offset: offset$1 = offset.defaultOffset(valueKeyframes.length) } = valueOptions;
97
- /**
98
- * If there's only one offset of 0, fill in a second with length 1
99
- *
100
- * TODO: Ensure there's a test that covers this removal
101
- */
102
- if (offset$1.length === 1 && offset$1[0] === 0) {
103
- offset$1[1] = 1;
104
- }
105
- /**
106
- * Fill out if offset if fewer offsets than keyframes
107
- */
108
- const remainder = length - valueKeyframes.length;
109
- remainder > 0 && offset.fillOffset(offset$1, remainder);
110
- /**
111
- * If only one value has been set, ie [1], push a null to the start of
112
- * the keyframe array. This will let us mark a keyframe at this point
113
- * that will later be hydrated with the previous value.
114
- */
115
- valueKeyframes.length === 1 && valueKeyframes.unshift(null);
116
- /**
117
- * Add keyframes, mapping offsets to absolute time.
118
- */
119
- edit.addKeyframes(valueSequence, valueKeyframes, easing$1, offset$1, startTime, targetTime);
120
- maxDuration = Math.max(delay + duration, maxDuration);
121
- totalDuration = Math.max(targetTime, totalDuration);
122
- }
123
- }
124
- prevTime = currentTime;
125
- currentTime += maxDuration;
126
- }
127
- /**
128
- * For every element and value combination create a new animation.
129
- */
130
- elementSequences.forEach((valueSequences, element) => {
131
- for (const key in valueSequences) {
132
- const valueSequence = valueSequences[key];
133
- /**
134
- * Arrange all the keyframes in ascending time order.
135
- */
136
- valueSequence.sort(sort.compareByTime);
137
- const keyframes = [];
138
- const valueOffset = [];
139
- const valueEasing = [];
140
- /**
141
- * For each keyframe, translate absolute times into
142
- * relative offsets based on the total duration of the timeline.
143
- */
144
- for (let i = 0; i < valueSequence.length; i++) {
145
- const { at, value, easing } = valueSequence[i];
146
- keyframes.push(value);
147
- valueOffset.push(progress.progress(0, totalDuration, at));
148
- valueEasing.push(easing || defaults.defaults.easing);
149
- }
150
- /**
151
- * If the first keyframe doesn't land on offset: 0
152
- * provide one by duplicating the initial keyframe. This ensures
153
- * it snaps to the first keyframe when the animation starts.
154
- */
155
- if (valueOffset[0] !== 0) {
156
- valueOffset.unshift(0);
157
- keyframes.unshift(keyframes[0]);
158
- valueEasing.unshift("linear");
159
- }
160
- /**
161
- * If the last keyframe doesn't land on offset: 1
162
- * provide one with a null wildcard value. This will ensure it
163
- * stays static until the end of the animation.
164
- */
165
- if (valueOffset[valueOffset.length - 1] !== 1) {
166
- valueOffset.push(1);
167
- keyframes.push(null);
168
- }
169
- animationDefinitions.push([
170
- element,
171
- key,
172
- keyframes,
173
- Object.assign(Object.assign(Object.assign({}, defaultOptions), { duration: totalDuration, easing: valueEasing, offset: valueOffset }), timelineOptions),
174
- ]);
175
- }
176
- });
177
- return animationDefinitions;
178
- }
179
- function getElementSequence(element, sequences) {
180
- !sequences.has(element) && sequences.set(element, {});
181
- return sequences.get(element);
182
- }
183
- function getValueSequence(name, sequences) {
184
- if (!sequences[name])
185
- sequences[name] = [];
186
- return sequences[name];
187
- }
188
-
189
- exports.createAnimationsFromTimeline = createAnimationsFromTimeline;
190
- exports.timeline = timeline;