motion 10.3.2 → 10.5.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/README.md +0 -19
  2. package/dist/main.cjs.js +11 -13
  3. package/dist/main.es.js +7 -6
  4. package/dist/motion.min.js +1 -1
  5. package/dist/motion.umd.js +412 -16
  6. package/dist/react.cjs.js +7 -2
  7. package/dist/react.es.js +1 -1
  8. package/dist/size-index.js +1 -0
  9. package/lib/index.js +5 -0
  10. package/lib/index.js.map +1 -0
  11. package/lib/react.js +2 -0
  12. package/lib/react.js.map +1 -0
  13. package/lib/vue.js +2 -0
  14. package/lib/vue.js.map +1 -0
  15. package/package.json +16 -134
  16. package/react/package.json +1 -1
  17. package/types/index.d.ts +3 -7
  18. package/types/index.d.ts.map +1 -0
  19. package/types/react.d.ts +2 -0
  20. package/types/react.d.ts.map +1 -0
  21. package/types/vue.d.ts +2 -0
  22. package/types/vue.d.ts.map +1 -0
  23. package/CHANGELOG.md +0 -97
  24. package/dist/size-animate-dom.js +0 -1
  25. package/dist/size-animate-style.js +0 -1
  26. package/dist/size-react.js +0 -1
  27. package/dist/size-spring.js +0 -1
  28. package/dist/size-timeline-dom.js +0 -1
  29. package/dist/size-webpack-animate.js +0 -1
  30. package/dist/targets/dom/animate-style.cjs.js +0 -182
  31. package/dist/targets/dom/animate-style.es.js +0 -178
  32. package/dist/targets/dom/animate.cjs.js +0 -42
  33. package/dist/targets/dom/animate.es.js +0 -38
  34. package/dist/targets/dom/data.cjs.js +0 -18
  35. package/dist/targets/dom/data.es.js +0 -14
  36. package/dist/targets/dom/style.cjs.js +0 -22
  37. package/dist/targets/dom/style.es.js +0 -18
  38. package/dist/targets/dom/timeline/index.cjs.js +0 -174
  39. package/dist/targets/dom/timeline/index.es.js +0 -169
  40. package/dist/targets/dom/timeline/utils/calc-time.cjs.js +0 -23
  41. package/dist/targets/dom/timeline/utils/calc-time.es.js +0 -19
  42. package/dist/targets/dom/timeline/utils/edit.cjs.js +0 -36
  43. package/dist/targets/dom/timeline/utils/edit.es.js +0 -31
  44. package/dist/targets/dom/timeline/utils/sort.cjs.js +0 -14
  45. package/dist/targets/dom/timeline/utils/sort.es.js +0 -10
  46. package/dist/targets/dom/utils/apply.cjs.js +0 -9
  47. package/dist/targets/dom/utils/apply.es.js +0 -4
  48. package/dist/targets/dom/utils/controls.cjs.js +0 -59
  49. package/dist/targets/dom/utils/controls.es.js +0 -54
  50. package/dist/targets/dom/utils/css-var.cjs.js +0 -29
  51. package/dist/targets/dom/utils/css-var.es.js +0 -23
  52. package/dist/targets/dom/utils/defaults.cjs.js +0 -13
  53. package/dist/targets/dom/utils/defaults.es.js +0 -9
  54. package/dist/targets/dom/utils/easing.cjs.js +0 -18
  55. package/dist/targets/dom/utils/easing.es.js +0 -10
  56. package/dist/targets/dom/utils/feature-detection.cjs.js +0 -31
  57. package/dist/targets/dom/utils/feature-detection.es.js +0 -27
  58. package/dist/targets/dom/utils/get-style-name.cjs.js +0 -13
  59. package/dist/targets/dom/utils/get-style-name.es.js +0 -9
  60. package/dist/targets/dom/utils/keyframes.cjs.js +0 -16
  61. package/dist/targets/dom/utils/keyframes.es.js +0 -11
  62. package/dist/targets/dom/utils/options.cjs.js +0 -13
  63. package/dist/targets/dom/utils/options.es.js +0 -9
  64. package/dist/targets/dom/utils/resolve-elements.cjs.js +0 -22
  65. package/dist/targets/dom/utils/resolve-elements.es.js +0 -18
  66. package/dist/targets/dom/utils/stop-animation.cjs.js +0 -19
  67. package/dist/targets/dom/utils/stop-animation.es.js +0 -15
  68. package/dist/targets/dom/utils/time.cjs.js +0 -7
  69. package/dist/targets/dom/utils/time.es.js +0 -3
  70. package/dist/targets/dom/utils/transforms.cjs.js +0 -85
  71. package/dist/targets/dom/utils/transforms.es.js +0 -74
  72. package/dist/targets/js/NumberAnimation.cjs.js +0 -144
  73. package/dist/targets/js/NumberAnimation.es.js +0 -140
  74. package/dist/targets/js/easing/cubic-bezier.cjs.js +0 -57
  75. package/dist/targets/js/easing/cubic-bezier.es.js +0 -53
  76. package/dist/targets/js/easing/glide/generator.cjs.js +0 -99
  77. package/dist/targets/js/easing/glide/generator.es.js +0 -95
  78. package/dist/targets/js/easing/glide/index.cjs.js +0 -10
  79. package/dist/targets/js/easing/glide/index.es.js +0 -6
  80. package/dist/targets/js/easing/spring/generator.cjs.js +0 -64
  81. package/dist/targets/js/easing/spring/generator.es.js +0 -57
  82. package/dist/targets/js/easing/spring/index.cjs.js +0 -10
  83. package/dist/targets/js/easing/spring/index.es.js +0 -6
  84. package/dist/targets/js/easing/steps.cjs.js +0 -15
  85. package/dist/targets/js/easing/steps.es.js +0 -11
  86. package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +0 -71
  87. package/dist/targets/js/easing/utils/create-generator-easing.es.js +0 -67
  88. package/dist/targets/js/easing/utils/get-function.cjs.js +0 -37
  89. package/dist/targets/js/easing/utils/get-function.es.js +0 -33
  90. package/dist/targets/js/easing/utils/has-reached-target.cjs.js +0 -10
  91. package/dist/targets/js/easing/utils/has-reached-target.es.js +0 -6
  92. package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +0 -34
  93. package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +0 -30
  94. package/dist/targets/js/utils/get-easing.cjs.js +0 -14
  95. package/dist/targets/js/utils/get-easing.es.js +0 -10
  96. package/dist/targets/js/utils/interpolate.cjs.js +0 -35
  97. package/dist/targets/js/utils/interpolate.es.js +0 -31
  98. package/dist/targets/js/utils/offset.cjs.js +0 -22
  99. package/dist/targets/js/utils/offset.es.js +0 -17
  100. package/dist/targets/react/animated.cjs.js +0 -126
  101. package/dist/targets/react/animated.es.js +0 -101
  102. package/dist/targets/react/context.cjs.js +0 -9
  103. package/dist/targets/react/context.es.js +0 -5
  104. package/dist/targets/react/hooks/use-animation.cjs.js +0 -47
  105. package/dist/targets/react/hooks/use-animation.es.js +0 -43
  106. package/dist/targets/react/hooks/use-exit.cjs.js +0 -27
  107. package/dist/targets/react/hooks/use-exit.es.js +0 -23
  108. package/dist/targets/react/hooks/use-gesture-state.cjs.js +0 -17
  109. package/dist/targets/react/hooks/use-gesture-state.es.js +0 -13
  110. package/dist/targets/react/hooks/use-hover.cjs.js +0 -24
  111. package/dist/targets/react/hooks/use-hover.es.js +0 -20
  112. package/dist/targets/react/hooks/use-press.cjs.js +0 -25
  113. package/dist/targets/react/hooks/use-press.es.js +0 -21
  114. package/dist/targets/react/hooks/use-viewport.cjs.js +0 -37
  115. package/dist/targets/react/hooks/use-viewport.es.js +0 -33
  116. package/dist/targets/react/index.cjs.js +0 -17
  117. package/dist/targets/react/index.es.js +0 -13
  118. package/dist/targets/react/utils/has-changed.cjs.js +0 -24
  119. package/dist/targets/react/utils/has-changed.es.js +0 -19
  120. package/dist/targets/react/utils/keyframes.cjs.js +0 -38
  121. package/dist/targets/react/utils/keyframes.es.js +0 -34
  122. package/dist/targets/react/utils/poses.cjs.js +0 -14
  123. package/dist/targets/react/utils/poses.es.js +0 -10
  124. package/dist/targets/react/utils/update-target.cjs.js +0 -20
  125. package/dist/targets/react/utils/update-target.es.js +0 -16
  126. package/dist/utils/array.cjs.js +0 -14
  127. package/dist/utils/array.es.js +0 -9
  128. package/dist/utils/clamp.cjs.js +0 -7
  129. package/dist/utils/clamp.es.js +0 -3
  130. package/dist/utils/is-number.cjs.js +0 -7
  131. package/dist/utils/is-number.es.js +0 -3
  132. package/dist/utils/mix.cjs.js +0 -28
  133. package/dist/utils/mix.es.js +0 -24
  134. package/dist/utils/noop.cjs.js +0 -9
  135. package/dist/utils/noop.es.js +0 -4
  136. package/dist/utils/progress.cjs.js +0 -20
  137. package/dist/utils/progress.es.js +0 -16
  138. package/dist/utils/stagger.cjs.js +0 -38
  139. package/dist/utils/stagger.es.js +0 -32
  140. package/dist/utils/velocity-per-second.cjs.js +0 -15
  141. package/dist/utils/velocity-per-second.es.js +0 -11
  142. package/dist/utils/wrap.cjs.js +0 -10
  143. package/dist/utils/wrap.es.js +0 -6
  144. package/types/react-entry.d.ts +0 -2
  145. package/types/targets/dom/animate-style.d.ts +0 -2
  146. package/types/targets/dom/animate.d.ts +0 -2
  147. package/types/targets/dom/data.d.ts +0 -2
  148. package/types/targets/dom/style.d.ts +0 -3
  149. package/types/targets/dom/timeline/index.d.ts +0 -15
  150. package/types/targets/dom/timeline/types.d.ts +0 -13
  151. package/types/targets/dom/timeline/utils/calc-time.d.ts +0 -2
  152. package/types/targets/dom/timeline/utils/edit.d.ts +0 -4
  153. package/types/targets/dom/timeline/utils/sort.d.ts +0 -2
  154. package/types/targets/dom/types.d.ts +0 -114
  155. package/types/targets/dom/utils/apply.d.ts +0 -3
  156. package/types/targets/dom/utils/controls.d.ts +0 -12
  157. package/types/targets/dom/utils/css-var.d.ts +0 -3
  158. package/types/targets/dom/utils/defaults.d.ts +0 -8
  159. package/types/targets/dom/utils/easing.d.ts +0 -6
  160. package/types/targets/dom/utils/feature-detection.d.ts +0 -8
  161. package/types/targets/dom/utils/get-style-name.d.ts +0 -1
  162. package/types/targets/dom/utils/keyframes.d.ts +0 -3
  163. package/types/targets/dom/utils/options.d.ts +0 -2
  164. package/types/targets/dom/utils/resolve-elements.d.ts +0 -4
  165. package/types/targets/dom/utils/stop-animation.d.ts +0 -6
  166. package/types/targets/dom/utils/time.d.ts +0 -1
  167. package/types/targets/dom/utils/transforms.d.ts +0 -20
  168. package/types/targets/js/NumberAnimation.d.ts +0 -24
  169. package/types/targets/js/easing/cubic-bezier.d.ts +0 -1
  170. package/types/targets/js/easing/glide/generator.d.ts +0 -5
  171. package/types/targets/js/easing/glide/index.d.ts +0 -2
  172. package/types/targets/js/easing/glide/types.d.ts +0 -14
  173. package/types/targets/js/easing/spring/generator.d.ts +0 -6
  174. package/types/targets/js/easing/spring/index.d.ts +0 -2
  175. package/types/targets/js/easing/spring/types.d.ts +0 -10
  176. package/types/targets/js/easing/steps.d.ts +0 -3
  177. package/types/targets/js/easing/utils/create-generator-easing.d.ts +0 -3
  178. package/types/targets/js/easing/utils/get-function.d.ts +0 -3
  179. package/types/targets/js/easing/utils/has-reached-target.d.ts +0 -1
  180. package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +0 -7
  181. package/types/targets/js/types.d.ts +0 -12
  182. package/types/targets/js/utils/get-easing.d.ts +0 -1
  183. package/types/targets/js/utils/interpolate.d.ts +0 -2
  184. package/types/targets/js/utils/offset.d.ts +0 -2
  185. package/types/targets/react/animated.d.ts +0 -3
  186. package/types/targets/react/context.d.ts +0 -3
  187. package/types/targets/react/hooks/use-animation.d.ts +0 -4
  188. package/types/targets/react/hooks/use-exit.d.ts +0 -3
  189. package/types/targets/react/hooks/use-gesture-state.d.ts +0 -4
  190. package/types/targets/react/hooks/use-hover.d.ts +0 -4
  191. package/types/targets/react/hooks/use-press.d.ts +0 -4
  192. package/types/targets/react/hooks/use-viewport.d.ts +0 -4
  193. package/types/targets/react/index.d.ts +0 -2
  194. package/types/targets/react/types.d.ts +0 -108
  195. package/types/targets/react/utils/has-changed.d.ts +0 -2
  196. package/types/targets/react/utils/keyframes.d.ts +0 -3
  197. package/types/targets/react/utils/poses.d.ts +0 -2
  198. package/types/targets/react/utils/supported-elements.d.ts +0 -8
  199. package/types/targets/react/utils/update-target.d.ts +0 -3
  200. package/types/utils/array.d.ts +0 -2
  201. package/types/utils/clamp.d.ts +0 -1
  202. package/types/utils/interpolate.d.ts +0 -0
  203. package/types/utils/is-number.d.ts +0 -1
  204. package/types/utils/mix.d.ts +0 -1
  205. package/types/utils/noop.d.ts +0 -2
  206. package/types/utils/progress.d.ts +0 -1
  207. package/types/utils/stagger.d.ts +0 -12
  208. package/types/utils/value-types.d.ts +0 -0
  209. package/types/utils/velocity-per-second.d.ts +0 -1
  210. package/types/utils/wrap.d.ts +0 -1
@@ -1,174 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var tslib = require('tslib');
6
- var progress = require('../../../utils/progress.cjs.js');
7
- var stagger = require('../../../utils/stagger.cjs.js');
8
- var offset = require('../../js/utils/offset.cjs.js');
9
- var animateStyle = require('../animate-style.cjs.js');
10
- var controls = require('../utils/controls.cjs.js');
11
- var defaults = require('../utils/defaults.cjs.js');
12
- var keyframes = require('../utils/keyframes.cjs.js');
13
- var options = require('../utils/options.cjs.js');
14
- var resolveElements = require('../utils/resolve-elements.cjs.js');
15
- var calcTime = require('./utils/calc-time.cjs.js');
16
- var edit = require('./utils/edit.cjs.js');
17
- var sort = require('./utils/sort.cjs.js');
18
-
19
- function timeline(definition, options = {}) {
20
- var _a, _b;
21
- const animationDefinitions = createAnimationsFromTimeline(definition, options);
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,
29
- // Get the duration from the first animation definition
30
- (_b = (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration) !== null && _b !== void 0 ? _b : defaults.defaults.duration);
31
- }
32
- function createAnimationsFromTimeline(definition, _a = {}) {
33
- var { defaultOptions = {} } = _a, timelineOptions = tslib.__rest(_a, ["defaultOptions"]);
34
- const animationDefinitions = [];
35
- const elementSequences = new Map();
36
- const elementCache = {};
37
- const timeLabels = new Map();
38
- let prevTime = 0;
39
- let currentTime = 0;
40
- let totalDuration = 0;
41
- /**
42
- * Build the timeline by mapping over the definition array and converting
43
- * the definitions into keyframes and offsets with absolute time values.
44
- * These will later get converted into relative offsets in a second pass.
45
- */
46
- for (let i = 0; i < definition.length; i++) {
47
- const [elementDefinition, keyframes$1, options$1 = {}] = definition[i];
48
- /**
49
- * If a relative or absolute time value has been specified we need to resolve
50
- * it in relation to the currentTime.
51
- */
52
- if (options$1.at !== undefined) {
53
- currentTime = calcTime.calcNextTime(currentTime, options$1.at, prevTime, timeLabels);
54
- }
55
- /**
56
- * Keep track of the maximum duration in this definition. This will be
57
- * applied to currentTime once the definition has been parsed.
58
- */
59
- let maxDuration = 0;
60
- /**
61
- * Find all the elements specified in the definition and parse value
62
- * keyframes from their timeline definitions.
63
- */
64
- const elements = resolveElements.resolveElements(elementDefinition, elementCache);
65
- const numElements = elements.length;
66
- for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
67
- const element = elements[elementIndex];
68
- const elementSequence = getElementSequence(element, elementSequences);
69
- for (const key in keyframes$1) {
70
- const valueSequence = getValueSequence(key, elementSequence);
71
- const valueKeyframes = keyframes.keyframesList(keyframes$1[key]);
72
- const valueOptions = options.getOptions(options$1, key);
73
- let { duration = defaultOptions.duration || defaults.defaults.duration, easing = defaultOptions.easing || defaults.defaults.easing, } = valueOptions;
74
- const delay = stagger.resolveOption(options$1.delay, elementIndex, numElements) || 0;
75
- const startTime = currentTime + delay;
76
- const targetTime = startTime + duration;
77
- /**
78
- *
79
- */
80
- let { offset: offset$1 = offset.defaultOffset(valueKeyframes.length) } = valueOptions;
81
- /**
82
- * If there's only one offset of 0, fill in a second with length 1
83
- *
84
- * TODO: Ensure there's a test that covers this removal
85
- */
86
- if (offset$1.length === 1 && offset$1[0] === 0) {
87
- offset$1[1] = 1;
88
- }
89
- /**
90
- * Fill out if offset if fewer offsets than keyframes
91
- */
92
- const remainder = length - valueKeyframes.length;
93
- remainder > 0 && offset.fillOffset(offset$1, remainder);
94
- /**
95
- * If only one value has been set, ie [1], push a null to the start of
96
- * the keyframe array. This will let us mark a keyframe at this point
97
- * that will later be hydrated with the previous value.
98
- */
99
- valueKeyframes.length === 1 && valueKeyframes.unshift(null);
100
- /**
101
- * Add keyframes, mapping offsets to absolute time.
102
- */
103
- edit.addKeyframes(valueSequence, valueKeyframes, easing, offset$1, startTime, targetTime);
104
- maxDuration = Math.max(delay + duration, maxDuration);
105
- totalDuration = Math.max(targetTime, totalDuration);
106
- }
107
- }
108
- prevTime = currentTime;
109
- currentTime += maxDuration;
110
- }
111
- /**
112
- * For every element and value combination create a new animation.
113
- */
114
- elementSequences.forEach((valueSequences, element) => {
115
- for (const key in valueSequences) {
116
- const valueSequence = valueSequences[key];
117
- /**
118
- * Arrange all the keyframes in ascending time order.
119
- */
120
- valueSequence.sort(sort.compareByTime);
121
- const keyframes = [];
122
- const valueOffset = [];
123
- const valueEasing = [];
124
- /**
125
- * For each keyframe, translate absolute times into
126
- * relative offsets based on the total duration of the timeline.
127
- */
128
- for (let i = 0; i < valueSequence.length; i++) {
129
- const { at, value, easing } = valueSequence[i];
130
- keyframes.push(value);
131
- valueOffset.push(progress.progress(0, totalDuration, at));
132
- valueEasing.push(easing || defaults.defaults.easing);
133
- }
134
- /**
135
- * If the first keyframe doesn't land on offset: 0
136
- * provide one by duplicating the initial keyframe. This ensures
137
- * it snaps to the first keyframe when the animation starts.
138
- */
139
- if (valueOffset[0] !== 0) {
140
- valueOffset.unshift(0);
141
- keyframes.unshift(keyframes[0]);
142
- valueEasing.unshift("linear");
143
- }
144
- /**
145
- * If the last keyframe doesn't land on offset: 1
146
- * provide one with a null wildcard value. This will ensure it
147
- * stays static until the end of the animation.
148
- */
149
- if (valueOffset[valueOffset.length - 1] !== 1) {
150
- valueOffset.push(1);
151
- keyframes.push(null);
152
- }
153
- animationDefinitions.push([
154
- element,
155
- key,
156
- keyframes,
157
- Object.assign(Object.assign(Object.assign({}, defaultOptions), { duration: totalDuration, easing: valueEasing, offset: valueOffset }), timelineOptions),
158
- ]);
159
- }
160
- });
161
- return animationDefinitions;
162
- }
163
- function getElementSequence(element, sequences) {
164
- !sequences.has(element) && sequences.set(element, {});
165
- return sequences.get(element);
166
- }
167
- function getValueSequence(name, sequences) {
168
- if (!sequences[name])
169
- sequences[name] = [];
170
- return sequences[name];
171
- }
172
-
173
- exports.createAnimationsFromTimeline = createAnimationsFromTimeline;
174
- exports.timeline = timeline;
@@ -1,169 +0,0 @@
1
- import { __rest } from 'tslib';
2
- import { progress } from '../../../utils/progress.es.js';
3
- import { resolveOption } from '../../../utils/stagger.es.js';
4
- import { defaultOffset, fillOffset } from '../../js/utils/offset.es.js';
5
- import { animateStyle } from '../animate-style.es.js';
6
- import { createAnimations } from '../utils/controls.es.js';
7
- import { defaults } from '../utils/defaults.es.js';
8
- import { keyframesList } from '../utils/keyframes.es.js';
9
- import { getOptions } from '../utils/options.es.js';
10
- import { resolveElements } from '../utils/resolve-elements.es.js';
11
- import { calcNextTime } from './utils/calc-time.es.js';
12
- import { addKeyframes } from './utils/edit.es.js';
13
- import { compareByTime } from './utils/sort.es.js';
14
-
15
- function timeline(definition, options = {}) {
16
- var _a, _b;
17
- const animationDefinitions = createAnimationsFromTimeline(definition, options);
18
- /**
19
- * Create and start animations
20
- */
21
- const animationFactories = animationDefinitions
22
- .map((definition) => animateStyle(...definition))
23
- .filter(Boolean);
24
- return createAnimations(animationFactories,
25
- // Get the duration from the first animation definition
26
- (_b = (_a = animationDefinitions[0]) === null || _a === void 0 ? void 0 : _a[3].duration) !== null && _b !== void 0 ? _b : defaults.duration);
27
- }
28
- function createAnimationsFromTimeline(definition, _a = {}) {
29
- var { defaultOptions = {} } = _a, timelineOptions = __rest(_a, ["defaultOptions"]);
30
- const animationDefinitions = [];
31
- const elementSequences = new Map();
32
- const elementCache = {};
33
- const timeLabels = new Map();
34
- let prevTime = 0;
35
- let currentTime = 0;
36
- let totalDuration = 0;
37
- /**
38
- * Build the timeline by mapping over the definition array and converting
39
- * the definitions into keyframes and offsets with absolute time values.
40
- * These will later get converted into relative offsets in a second pass.
41
- */
42
- for (let i = 0; i < definition.length; i++) {
43
- const [elementDefinition, keyframes, options = {}] = definition[i];
44
- /**
45
- * If a relative or absolute time value has been specified we need to resolve
46
- * it in relation to the currentTime.
47
- */
48
- if (options.at !== undefined) {
49
- currentTime = calcNextTime(currentTime, options.at, prevTime, timeLabels);
50
- }
51
- /**
52
- * Keep track of the maximum duration in this definition. This will be
53
- * applied to currentTime once the definition has been parsed.
54
- */
55
- let maxDuration = 0;
56
- /**
57
- * Find all the elements specified in the definition and parse value
58
- * keyframes from their timeline definitions.
59
- */
60
- const elements = resolveElements(elementDefinition, elementCache);
61
- const numElements = elements.length;
62
- for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
63
- const element = elements[elementIndex];
64
- const elementSequence = getElementSequence(element, elementSequences);
65
- for (const key in keyframes) {
66
- const valueSequence = getValueSequence(key, elementSequence);
67
- const valueKeyframes = keyframesList(keyframes[key]);
68
- const valueOptions = getOptions(options, key);
69
- let { duration = defaultOptions.duration || defaults.duration, easing = defaultOptions.easing || defaults.easing, } = valueOptions;
70
- const delay = resolveOption(options.delay, elementIndex, numElements) || 0;
71
- const startTime = currentTime + delay;
72
- const targetTime = startTime + duration;
73
- /**
74
- *
75
- */
76
- let { offset = defaultOffset(valueKeyframes.length) } = valueOptions;
77
- /**
78
- * If there's only one offset of 0, fill in a second with length 1
79
- *
80
- * TODO: Ensure there's a test that covers this removal
81
- */
82
- if (offset.length === 1 && offset[0] === 0) {
83
- offset[1] = 1;
84
- }
85
- /**
86
- * Fill out if offset if fewer offsets than keyframes
87
- */
88
- const remainder = length - valueKeyframes.length;
89
- remainder > 0 && fillOffset(offset, remainder);
90
- /**
91
- * If only one value has been set, ie [1], push a null to the start of
92
- * the keyframe array. This will let us mark a keyframe at this point
93
- * that will later be hydrated with the previous value.
94
- */
95
- valueKeyframes.length === 1 && valueKeyframes.unshift(null);
96
- /**
97
- * Add keyframes, mapping offsets to absolute time.
98
- */
99
- addKeyframes(valueSequence, valueKeyframes, easing, offset, startTime, targetTime);
100
- maxDuration = Math.max(delay + duration, maxDuration);
101
- totalDuration = Math.max(targetTime, totalDuration);
102
- }
103
- }
104
- prevTime = currentTime;
105
- currentTime += maxDuration;
106
- }
107
- /**
108
- * For every element and value combination create a new animation.
109
- */
110
- elementSequences.forEach((valueSequences, element) => {
111
- for (const key in valueSequences) {
112
- const valueSequence = valueSequences[key];
113
- /**
114
- * Arrange all the keyframes in ascending time order.
115
- */
116
- valueSequence.sort(compareByTime);
117
- const keyframes = [];
118
- const valueOffset = [];
119
- const valueEasing = [];
120
- /**
121
- * For each keyframe, translate absolute times into
122
- * relative offsets based on the total duration of the timeline.
123
- */
124
- for (let i = 0; i < valueSequence.length; i++) {
125
- const { at, value, easing } = valueSequence[i];
126
- keyframes.push(value);
127
- valueOffset.push(progress(0, totalDuration, at));
128
- valueEasing.push(easing || defaults.easing);
129
- }
130
- /**
131
- * If the first keyframe doesn't land on offset: 0
132
- * provide one by duplicating the initial keyframe. This ensures
133
- * it snaps to the first keyframe when the animation starts.
134
- */
135
- if (valueOffset[0] !== 0) {
136
- valueOffset.unshift(0);
137
- keyframes.unshift(keyframes[0]);
138
- valueEasing.unshift("linear");
139
- }
140
- /**
141
- * If the last keyframe doesn't land on offset: 1
142
- * provide one with a null wildcard value. This will ensure it
143
- * stays static until the end of the animation.
144
- */
145
- if (valueOffset[valueOffset.length - 1] !== 1) {
146
- valueOffset.push(1);
147
- keyframes.push(null);
148
- }
149
- animationDefinitions.push([
150
- element,
151
- key,
152
- keyframes,
153
- Object.assign(Object.assign(Object.assign({}, defaultOptions), { duration: totalDuration, easing: valueEasing, offset: valueOffset }), timelineOptions),
154
- ]);
155
- }
156
- });
157
- return animationDefinitions;
158
- }
159
- function getElementSequence(element, sequences) {
160
- !sequences.has(element) && sequences.set(element, {});
161
- return sequences.get(element);
162
- }
163
- function getValueSequence(name, sequences) {
164
- if (!sequences[name])
165
- sequences[name] = [];
166
- return sequences[name];
167
- }
168
-
169
- export { createAnimationsFromTimeline, timeline };
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var isNumber = require('../../../../utils/is-number.cjs.js');
6
-
7
- function calcNextTime(current, next, prev, labels) {
8
- var _a;
9
- if (isNumber.isNumber(next)) {
10
- return next;
11
- }
12
- else if (next.startsWith("-") || next.startsWith("+")) {
13
- return Math.max(0, current + parseFloat(next));
14
- }
15
- else if (next === "<") {
16
- return prev;
17
- }
18
- else {
19
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
20
- }
21
- }
22
-
23
- exports.calcNextTime = calcNextTime;
@@ -1,19 +0,0 @@
1
- import { isNumber } from '../../../../utils/is-number.es.js';
2
-
3
- function calcNextTime(current, next, prev, labels) {
4
- var _a;
5
- if (isNumber(next)) {
6
- return next;
7
- }
8
- else if (next.startsWith("-") || next.startsWith("+")) {
9
- return Math.max(0, current + parseFloat(next));
10
- }
11
- else if (next === "<") {
12
- return prev;
13
- }
14
- else {
15
- return (_a = labels.get(next)) !== null && _a !== void 0 ? _a : current;
16
- }
17
- }
18
-
19
- export { calcNextTime };
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var mix = require('../../../../utils/mix.cjs.js');
6
- var array = require('../../../../utils/array.cjs.js');
7
- var getEasing = require('../../../js/utils/get-easing.cjs.js');
8
-
9
- function eraseKeyframes(sequence, startTime, endTime) {
10
- for (let i = 0; i < sequence.length; i++) {
11
- const keyframe = sequence[i];
12
- if (keyframe.at > startTime && keyframe.at < endTime) {
13
- array.removeItem(sequence, keyframe);
14
- // If we remove this item we have to push the pointer back one
15
- i--;
16
- }
17
- }
18
- }
19
- function addKeyframes(sequence, keyframes, easing, offset, startTime, endTime) {
20
- /**
21
- * Erase every existing value between currentTime and targetTime,
22
- * this will essentially splice this timeline into any currently
23
- * defined ones.
24
- */
25
- eraseKeyframes(sequence, startTime, endTime);
26
- for (let i = 0; i < keyframes.length; i++) {
27
- sequence.push({
28
- value: keyframes[i],
29
- at: mix.mix(startTime, endTime, offset[i]),
30
- easing: getEasing.getEasingForSegment(easing, i),
31
- });
32
- }
33
- }
34
-
35
- exports.addKeyframes = addKeyframes;
36
- exports.eraseKeyframes = eraseKeyframes;
@@ -1,31 +0,0 @@
1
- import { mix } from '../../../../utils/mix.es.js';
2
- import { removeItem } from '../../../../utils/array.es.js';
3
- import { getEasingForSegment } from '../../../js/utils/get-easing.es.js';
4
-
5
- function eraseKeyframes(sequence, startTime, endTime) {
6
- for (let i = 0; i < sequence.length; i++) {
7
- const keyframe = sequence[i];
8
- if (keyframe.at > startTime && keyframe.at < endTime) {
9
- removeItem(sequence, keyframe);
10
- // If we remove this item we have to push the pointer back one
11
- i--;
12
- }
13
- }
14
- }
15
- function addKeyframes(sequence, keyframes, easing, offset, startTime, endTime) {
16
- /**
17
- * Erase every existing value between currentTime and targetTime,
18
- * this will essentially splice this timeline into any currently
19
- * defined ones.
20
- */
21
- eraseKeyframes(sequence, startTime, endTime);
22
- for (let i = 0; i < keyframes.length; i++) {
23
- sequence.push({
24
- value: keyframes[i],
25
- at: mix(startTime, endTime, offset[i]),
26
- easing: getEasingForSegment(easing, i),
27
- });
28
- }
29
- }
30
-
31
- export { addKeyframes, eraseKeyframes };
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function compareByTime(a, b) {
6
- if (a.at === b.at) {
7
- return a.value === null ? 1 : -1;
8
- }
9
- else {
10
- return a.at - b.at;
11
- }
12
- }
13
-
14
- exports.compareByTime = compareByTime;
@@ -1,10 +0,0 @@
1
- function compareByTime(a, b) {
2
- if (a.at === b.at) {
3
- return a.value === null ? 1 : -1;
4
- }
5
- else {
6
- return a.at - b.at;
7
- }
8
- }
9
-
10
- export { compareByTime };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const cssVariableRenderer = (element, name) => (latest) => element.style.setProperty(name, latest);
6
- const styleRenderer = (element, name) => (latest) => (element.style[name] = latest);
7
-
8
- exports.cssVariableRenderer = cssVariableRenderer;
9
- exports.styleRenderer = styleRenderer;
@@ -1,4 +0,0 @@
1
- const cssVariableRenderer = (element, name) => (latest) => element.style.setProperty(name, latest);
2
- const styleRenderer = (element, name) => (latest) => (element.style[name] = latest);
3
-
4
- export { cssVariableRenderer, styleRenderer };
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var noop = require('../../../utils/noop.cjs.js');
6
- var stopAnimation = require('./stop-animation.cjs.js');
7
- var time = require('./time.cjs.js');
8
-
9
- const createAnimation = (factory) => factory();
10
- const createAnimations = (animationFactory, duration) => new Proxy({
11
- animations: animationFactory.map(createAnimation).filter(Boolean),
12
- duration,
13
- }, controls);
14
- /**
15
- * TODO:
16
- * Currently this returns the first animation, ideally it would return
17
- * the first active animation.
18
- */
19
- const getActiveAnimation = (state) => state.animations[0];
20
- const controls = {
21
- get: (target, key) => {
22
- var _a, _b;
23
- switch (key) {
24
- case "duration":
25
- return target.duration;
26
- case "currentTime":
27
- let time = ((_a = getActiveAnimation(target)) === null || _a === void 0 ? void 0 : _a[key]) || 0;
28
- return time ? time / 1000 : 0;
29
- case "playbackRate":
30
- return (_b = getActiveAnimation(target)) === null || _b === void 0 ? void 0 : _b[key];
31
- case "finished":
32
- if (!target.finished) {
33
- target.finished = Promise.all(target.animations.map(selectFinished)).catch(noop.noop);
34
- }
35
- return target.finished;
36
- case "stop":
37
- return () => target.animations.forEach(stopAnimation.stopAnimation);
38
- default:
39
- return () => target.animations.forEach((animation) => animation[key]());
40
- }
41
- },
42
- set: (target, key, value) => {
43
- switch (key) {
44
- case "currentTime":
45
- value = time.ms(value);
46
- case "currentTime":
47
- case "playbackRate":
48
- for (let i = 0; i < target.animations.length; i++) {
49
- target.animations[i][key] = value;
50
- }
51
- return true;
52
- }
53
- return false;
54
- },
55
- };
56
- const selectFinished = (animation) => animation.finished;
57
-
58
- exports.controls = controls;
59
- exports.createAnimations = createAnimations;
@@ -1,54 +0,0 @@
1
- import { noop } from '../../../utils/noop.es.js';
2
- import { stopAnimation } from './stop-animation.es.js';
3
- import { ms } from './time.es.js';
4
-
5
- const createAnimation = (factory) => factory();
6
- const createAnimations = (animationFactory, duration) => new Proxy({
7
- animations: animationFactory.map(createAnimation).filter(Boolean),
8
- duration,
9
- }, controls);
10
- /**
11
- * TODO:
12
- * Currently this returns the first animation, ideally it would return
13
- * the first active animation.
14
- */
15
- const getActiveAnimation = (state) => state.animations[0];
16
- const controls = {
17
- get: (target, key) => {
18
- var _a, _b;
19
- switch (key) {
20
- case "duration":
21
- return target.duration;
22
- case "currentTime":
23
- let time = ((_a = getActiveAnimation(target)) === null || _a === void 0 ? void 0 : _a[key]) || 0;
24
- return time ? time / 1000 : 0;
25
- case "playbackRate":
26
- return (_b = getActiveAnimation(target)) === null || _b === void 0 ? void 0 : _b[key];
27
- case "finished":
28
- if (!target.finished) {
29
- target.finished = Promise.all(target.animations.map(selectFinished)).catch(noop);
30
- }
31
- return target.finished;
32
- case "stop":
33
- return () => target.animations.forEach(stopAnimation);
34
- default:
35
- return () => target.animations.forEach((animation) => animation[key]());
36
- }
37
- },
38
- set: (target, key, value) => {
39
- switch (key) {
40
- case "currentTime":
41
- value = ms(value);
42
- case "currentTime":
43
- case "playbackRate":
44
- for (let i = 0; i < target.animations.length; i++) {
45
- target.animations[i][key] = value;
46
- }
47
- return true;
48
- }
49
- return false;
50
- },
51
- };
52
- const selectFinished = (animation) => animation.finished;
53
-
54
- export { controls, createAnimations };
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transforms = require('./transforms.cjs.js');
6
-
7
- const isCssVar = (name) => name.startsWith("--");
8
- const registeredProperties = new Set();
9
- function registerCssVariable(name) {
10
- if (registeredProperties.has(name))
11
- return;
12
- registeredProperties.add(name);
13
- try {
14
- const { syntax, initialValue } = transforms.transformDefinitions.has(name)
15
- ? transforms.transformDefinitions.get(name)
16
- : {};
17
- CSS.registerProperty({
18
- name,
19
- inherits: false,
20
- syntax,
21
- initialValue,
22
- });
23
- }
24
- catch (e) { }
25
- }
26
-
27
- exports.isCssVar = isCssVar;
28
- exports.registerCssVariable = registerCssVariable;
29
- exports.registeredProperties = registeredProperties;
@@ -1,23 +0,0 @@
1
- import { transformDefinitions } from './transforms.es.js';
2
-
3
- const isCssVar = (name) => name.startsWith("--");
4
- const registeredProperties = new Set();
5
- function registerCssVariable(name) {
6
- if (registeredProperties.has(name))
7
- return;
8
- registeredProperties.add(name);
9
- try {
10
- const { syntax, initialValue } = transformDefinitions.has(name)
11
- ? transformDefinitions.get(name)
12
- : {};
13
- CSS.registerProperty({
14
- name,
15
- inherits: false,
16
- syntax,
17
- initialValue,
18
- });
19
- }
20
- catch (e) { }
21
- }
22
-
23
- export { isCssVar, registerCssVariable, registeredProperties };