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.
- package/README.md +0 -19
- package/dist/main.cjs.js +11 -13
- package/dist/main.es.js +7 -6
- package/dist/motion.min.js +1 -1
- package/dist/motion.umd.js +412 -16
- package/dist/react.cjs.js +7 -2
- package/dist/react.es.js +1 -1
- package/dist/size-index.js +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/react.js +2 -0
- package/lib/react.js.map +1 -0
- package/lib/vue.js +2 -0
- package/lib/vue.js.map +1 -0
- package/package.json +16 -134
- package/react/package.json +1 -1
- package/types/index.d.ts +3 -7
- package/types/index.d.ts.map +1 -0
- package/types/react.d.ts +2 -0
- package/types/react.d.ts.map +1 -0
- package/types/vue.d.ts +2 -0
- package/types/vue.d.ts.map +1 -0
- package/CHANGELOG.md +0 -97
- package/dist/size-animate-dom.js +0 -1
- package/dist/size-animate-style.js +0 -1
- package/dist/size-react.js +0 -1
- package/dist/size-spring.js +0 -1
- package/dist/size-timeline-dom.js +0 -1
- package/dist/size-webpack-animate.js +0 -1
- package/dist/targets/dom/animate-style.cjs.js +0 -182
- package/dist/targets/dom/animate-style.es.js +0 -178
- package/dist/targets/dom/animate.cjs.js +0 -42
- package/dist/targets/dom/animate.es.js +0 -38
- package/dist/targets/dom/data.cjs.js +0 -18
- package/dist/targets/dom/data.es.js +0 -14
- package/dist/targets/dom/style.cjs.js +0 -22
- package/dist/targets/dom/style.es.js +0 -18
- package/dist/targets/dom/timeline/index.cjs.js +0 -174
- package/dist/targets/dom/timeline/index.es.js +0 -169
- package/dist/targets/dom/timeline/utils/calc-time.cjs.js +0 -23
- package/dist/targets/dom/timeline/utils/calc-time.es.js +0 -19
- package/dist/targets/dom/timeline/utils/edit.cjs.js +0 -36
- package/dist/targets/dom/timeline/utils/edit.es.js +0 -31
- package/dist/targets/dom/timeline/utils/sort.cjs.js +0 -14
- package/dist/targets/dom/timeline/utils/sort.es.js +0 -10
- package/dist/targets/dom/utils/apply.cjs.js +0 -9
- package/dist/targets/dom/utils/apply.es.js +0 -4
- package/dist/targets/dom/utils/controls.cjs.js +0 -59
- package/dist/targets/dom/utils/controls.es.js +0 -54
- package/dist/targets/dom/utils/css-var.cjs.js +0 -29
- package/dist/targets/dom/utils/css-var.es.js +0 -23
- package/dist/targets/dom/utils/defaults.cjs.js +0 -13
- package/dist/targets/dom/utils/defaults.es.js +0 -9
- package/dist/targets/dom/utils/easing.cjs.js +0 -18
- package/dist/targets/dom/utils/easing.es.js +0 -10
- package/dist/targets/dom/utils/feature-detection.cjs.js +0 -31
- package/dist/targets/dom/utils/feature-detection.es.js +0 -27
- package/dist/targets/dom/utils/get-style-name.cjs.js +0 -13
- package/dist/targets/dom/utils/get-style-name.es.js +0 -9
- package/dist/targets/dom/utils/keyframes.cjs.js +0 -16
- package/dist/targets/dom/utils/keyframes.es.js +0 -11
- package/dist/targets/dom/utils/options.cjs.js +0 -13
- package/dist/targets/dom/utils/options.es.js +0 -9
- package/dist/targets/dom/utils/resolve-elements.cjs.js +0 -22
- package/dist/targets/dom/utils/resolve-elements.es.js +0 -18
- package/dist/targets/dom/utils/stop-animation.cjs.js +0 -19
- package/dist/targets/dom/utils/stop-animation.es.js +0 -15
- package/dist/targets/dom/utils/time.cjs.js +0 -7
- package/dist/targets/dom/utils/time.es.js +0 -3
- package/dist/targets/dom/utils/transforms.cjs.js +0 -85
- package/dist/targets/dom/utils/transforms.es.js +0 -74
- package/dist/targets/js/NumberAnimation.cjs.js +0 -144
- package/dist/targets/js/NumberAnimation.es.js +0 -140
- package/dist/targets/js/easing/cubic-bezier.cjs.js +0 -57
- package/dist/targets/js/easing/cubic-bezier.es.js +0 -53
- package/dist/targets/js/easing/glide/generator.cjs.js +0 -99
- package/dist/targets/js/easing/glide/generator.es.js +0 -95
- package/dist/targets/js/easing/glide/index.cjs.js +0 -10
- package/dist/targets/js/easing/glide/index.es.js +0 -6
- package/dist/targets/js/easing/spring/generator.cjs.js +0 -64
- package/dist/targets/js/easing/spring/generator.es.js +0 -57
- package/dist/targets/js/easing/spring/index.cjs.js +0 -10
- package/dist/targets/js/easing/spring/index.es.js +0 -6
- package/dist/targets/js/easing/steps.cjs.js +0 -15
- package/dist/targets/js/easing/steps.es.js +0 -11
- package/dist/targets/js/easing/utils/create-generator-easing.cjs.js +0 -71
- package/dist/targets/js/easing/utils/create-generator-easing.es.js +0 -67
- package/dist/targets/js/easing/utils/get-function.cjs.js +0 -37
- package/dist/targets/js/easing/utils/get-function.es.js +0 -33
- package/dist/targets/js/easing/utils/has-reached-target.cjs.js +0 -10
- package/dist/targets/js/easing/utils/has-reached-target.es.js +0 -6
- package/dist/targets/js/easing/utils/pregenerate-keyframes.cjs.js +0 -34
- package/dist/targets/js/easing/utils/pregenerate-keyframes.es.js +0 -30
- package/dist/targets/js/utils/get-easing.cjs.js +0 -14
- package/dist/targets/js/utils/get-easing.es.js +0 -10
- package/dist/targets/js/utils/interpolate.cjs.js +0 -35
- package/dist/targets/js/utils/interpolate.es.js +0 -31
- package/dist/targets/js/utils/offset.cjs.js +0 -22
- package/dist/targets/js/utils/offset.es.js +0 -17
- package/dist/targets/react/animated.cjs.js +0 -126
- package/dist/targets/react/animated.es.js +0 -101
- package/dist/targets/react/context.cjs.js +0 -9
- package/dist/targets/react/context.es.js +0 -5
- package/dist/targets/react/hooks/use-animation.cjs.js +0 -47
- package/dist/targets/react/hooks/use-animation.es.js +0 -43
- package/dist/targets/react/hooks/use-exit.cjs.js +0 -27
- package/dist/targets/react/hooks/use-exit.es.js +0 -23
- package/dist/targets/react/hooks/use-gesture-state.cjs.js +0 -17
- package/dist/targets/react/hooks/use-gesture-state.es.js +0 -13
- package/dist/targets/react/hooks/use-hover.cjs.js +0 -24
- package/dist/targets/react/hooks/use-hover.es.js +0 -20
- package/dist/targets/react/hooks/use-press.cjs.js +0 -25
- package/dist/targets/react/hooks/use-press.es.js +0 -21
- package/dist/targets/react/hooks/use-viewport.cjs.js +0 -37
- package/dist/targets/react/hooks/use-viewport.es.js +0 -33
- package/dist/targets/react/index.cjs.js +0 -17
- package/dist/targets/react/index.es.js +0 -13
- package/dist/targets/react/utils/has-changed.cjs.js +0 -24
- package/dist/targets/react/utils/has-changed.es.js +0 -19
- package/dist/targets/react/utils/keyframes.cjs.js +0 -38
- package/dist/targets/react/utils/keyframes.es.js +0 -34
- package/dist/targets/react/utils/poses.cjs.js +0 -14
- package/dist/targets/react/utils/poses.es.js +0 -10
- package/dist/targets/react/utils/update-target.cjs.js +0 -20
- package/dist/targets/react/utils/update-target.es.js +0 -16
- package/dist/utils/array.cjs.js +0 -14
- package/dist/utils/array.es.js +0 -9
- package/dist/utils/clamp.cjs.js +0 -7
- package/dist/utils/clamp.es.js +0 -3
- package/dist/utils/is-number.cjs.js +0 -7
- package/dist/utils/is-number.es.js +0 -3
- package/dist/utils/mix.cjs.js +0 -28
- package/dist/utils/mix.es.js +0 -24
- package/dist/utils/noop.cjs.js +0 -9
- package/dist/utils/noop.es.js +0 -4
- package/dist/utils/progress.cjs.js +0 -20
- package/dist/utils/progress.es.js +0 -16
- package/dist/utils/stagger.cjs.js +0 -38
- package/dist/utils/stagger.es.js +0 -32
- package/dist/utils/velocity-per-second.cjs.js +0 -15
- package/dist/utils/velocity-per-second.es.js +0 -11
- package/dist/utils/wrap.cjs.js +0 -10
- package/dist/utils/wrap.es.js +0 -6
- package/types/react-entry.d.ts +0 -2
- package/types/targets/dom/animate-style.d.ts +0 -2
- package/types/targets/dom/animate.d.ts +0 -2
- package/types/targets/dom/data.d.ts +0 -2
- package/types/targets/dom/style.d.ts +0 -3
- package/types/targets/dom/timeline/index.d.ts +0 -15
- package/types/targets/dom/timeline/types.d.ts +0 -13
- package/types/targets/dom/timeline/utils/calc-time.d.ts +0 -2
- package/types/targets/dom/timeline/utils/edit.d.ts +0 -4
- package/types/targets/dom/timeline/utils/sort.d.ts +0 -2
- package/types/targets/dom/types.d.ts +0 -114
- package/types/targets/dom/utils/apply.d.ts +0 -3
- package/types/targets/dom/utils/controls.d.ts +0 -12
- package/types/targets/dom/utils/css-var.d.ts +0 -3
- package/types/targets/dom/utils/defaults.d.ts +0 -8
- package/types/targets/dom/utils/easing.d.ts +0 -6
- package/types/targets/dom/utils/feature-detection.d.ts +0 -8
- package/types/targets/dom/utils/get-style-name.d.ts +0 -1
- package/types/targets/dom/utils/keyframes.d.ts +0 -3
- package/types/targets/dom/utils/options.d.ts +0 -2
- package/types/targets/dom/utils/resolve-elements.d.ts +0 -4
- package/types/targets/dom/utils/stop-animation.d.ts +0 -6
- package/types/targets/dom/utils/time.d.ts +0 -1
- package/types/targets/dom/utils/transforms.d.ts +0 -20
- package/types/targets/js/NumberAnimation.d.ts +0 -24
- package/types/targets/js/easing/cubic-bezier.d.ts +0 -1
- package/types/targets/js/easing/glide/generator.d.ts +0 -5
- package/types/targets/js/easing/glide/index.d.ts +0 -2
- package/types/targets/js/easing/glide/types.d.ts +0 -14
- package/types/targets/js/easing/spring/generator.d.ts +0 -6
- package/types/targets/js/easing/spring/index.d.ts +0 -2
- package/types/targets/js/easing/spring/types.d.ts +0 -10
- package/types/targets/js/easing/steps.d.ts +0 -3
- package/types/targets/js/easing/utils/create-generator-easing.d.ts +0 -3
- package/types/targets/js/easing/utils/get-function.d.ts +0 -3
- package/types/targets/js/easing/utils/has-reached-target.d.ts +0 -1
- package/types/targets/js/easing/utils/pregenerate-keyframes.d.ts +0 -7
- package/types/targets/js/types.d.ts +0 -12
- package/types/targets/js/utils/get-easing.d.ts +0 -1
- package/types/targets/js/utils/interpolate.d.ts +0 -2
- package/types/targets/js/utils/offset.d.ts +0 -2
- package/types/targets/react/animated.d.ts +0 -3
- package/types/targets/react/context.d.ts +0 -3
- package/types/targets/react/hooks/use-animation.d.ts +0 -4
- package/types/targets/react/hooks/use-exit.d.ts +0 -3
- package/types/targets/react/hooks/use-gesture-state.d.ts +0 -4
- package/types/targets/react/hooks/use-hover.d.ts +0 -4
- package/types/targets/react/hooks/use-press.d.ts +0 -4
- package/types/targets/react/hooks/use-viewport.d.ts +0 -4
- package/types/targets/react/index.d.ts +0 -2
- package/types/targets/react/types.d.ts +0 -108
- package/types/targets/react/utils/has-changed.d.ts +0 -2
- package/types/targets/react/utils/keyframes.d.ts +0 -3
- package/types/targets/react/utils/poses.d.ts +0 -2
- package/types/targets/react/utils/supported-elements.d.ts +0 -8
- package/types/targets/react/utils/update-target.d.ts +0 -3
- package/types/utils/array.d.ts +0 -2
- package/types/utils/clamp.d.ts +0 -1
- package/types/utils/interpolate.d.ts +0 -0
- package/types/utils/is-number.d.ts +0 -1
- package/types/utils/mix.d.ts +0 -1
- package/types/utils/noop.d.ts +0 -2
- package/types/utils/progress.d.ts +0 -1
- package/types/utils/stagger.d.ts +0 -12
- package/types/utils/value-types.d.ts +0 -0
- package/types/utils/velocity-per-second.d.ts +0 -1
- package/types/utils/wrap.d.ts +0 -1
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var data = require('./data.cjs.js');
|
|
6
|
-
var cssVar = require('./utils/css-var.cjs.js');
|
|
7
|
-
var noop = require('../../utils/noop.cjs.js');
|
|
8
|
-
var time = require('./utils/time.cjs.js');
|
|
9
|
-
var transforms = require('./utils/transforms.cjs.js');
|
|
10
|
-
var easing = require('./utils/easing.cjs.js');
|
|
11
|
-
var featureDetection = require('./utils/feature-detection.cjs.js');
|
|
12
|
-
var apply = require('./utils/apply.cjs.js');
|
|
13
|
-
var NumberAnimation = require('../js/NumberAnimation.cjs.js');
|
|
14
|
-
var keyframes = require('./utils/keyframes.cjs.js');
|
|
15
|
-
var style = require('./style.cjs.js');
|
|
16
|
-
var defaults = require('./utils/defaults.cjs.js');
|
|
17
|
-
var getStyleName = require('./utils/get-style-name.cjs.js');
|
|
18
|
-
var isNumber = require('../../utils/is-number.cjs.js');
|
|
19
|
-
var stopAnimation = require('./utils/stop-animation.cjs.js');
|
|
20
|
-
|
|
21
|
-
function animateStyle(element, key, keyframesDefinition, options = {}) {
|
|
22
|
-
let animation;
|
|
23
|
-
let { duration = defaults.defaults.duration, delay = defaults.defaults.delay, endDelay = defaults.defaults.endDelay, repeat = defaults.defaults.repeat, easing: easing$1 = defaults.defaults.easing, direction, offset, allowWebkitAcceleration = false, } = options;
|
|
24
|
-
const data$1 = data.getAnimationData(element);
|
|
25
|
-
let canAnimateNatively = featureDetection.supports.waapi();
|
|
26
|
-
let render = noop.noop;
|
|
27
|
-
const valueIsTransform = transforms.isTransform(key);
|
|
28
|
-
/**
|
|
29
|
-
* If this is an individual transform, we need to map its
|
|
30
|
-
* key to a CSS variable and update the element's transform style
|
|
31
|
-
*/
|
|
32
|
-
valueIsTransform && transforms.addTransformToElement(element, key);
|
|
33
|
-
const name = getStyleName.getStyleName(key);
|
|
34
|
-
/**
|
|
35
|
-
* Get definition of value, this will be used to convert numerical
|
|
36
|
-
* keyframes into the default value type.
|
|
37
|
-
*/
|
|
38
|
-
const definition = transforms.transformDefinitions.get(name);
|
|
39
|
-
/**
|
|
40
|
-
* Stop the current animation, if any. Because this will trigger
|
|
41
|
-
* commitStyles (DOM writes) and we might later trigger DOM reads,
|
|
42
|
-
* this is fired now and we return a factory function to create
|
|
43
|
-
* the actual animation that can get called in batch,
|
|
44
|
-
*/
|
|
45
|
-
stopAnimation.stopAnimation(data$1.animations[name]);
|
|
46
|
-
/**
|
|
47
|
-
* Batchable factory function containing all DOM reads.
|
|
48
|
-
*/
|
|
49
|
-
return () => {
|
|
50
|
-
const readInitialValue = () => { var _a, _b; return (_b = (_a = style.style.get(element, name)) !== null && _a !== void 0 ? _a : definition === null || definition === void 0 ? void 0 : definition.initialValue) !== null && _b !== void 0 ? _b : 0; };
|
|
51
|
-
/**
|
|
52
|
-
* Replace null values with the previous keyframe value, or read
|
|
53
|
-
* it from the DOM if it's the first keyframe.
|
|
54
|
-
*/
|
|
55
|
-
let keyframes$1 = keyframes.hydrateKeyframes(keyframes.keyframesList(keyframesDefinition), readInitialValue);
|
|
56
|
-
if (easing.isCustomEasing(easing$1)) {
|
|
57
|
-
const custom = easing$1.createAnimation(keyframes$1, readInitialValue, valueIsTransform, name, data$1);
|
|
58
|
-
easing$1 = custom.easing;
|
|
59
|
-
if (custom.keyframes !== undefined)
|
|
60
|
-
keyframes$1 = custom.keyframes;
|
|
61
|
-
if (custom.duration !== undefined)
|
|
62
|
-
duration = custom.duration;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* If this is a CSS variable we need to register it with the browser
|
|
66
|
-
* before it can be animated natively. We also set it with setProperty
|
|
67
|
-
* rather than directly onto the element.style object.
|
|
68
|
-
*/
|
|
69
|
-
if (cssVar.isCssVar(name)) {
|
|
70
|
-
render = apply.cssVariableRenderer(element, name);
|
|
71
|
-
if (featureDetection.supports.cssRegisterProperty()) {
|
|
72
|
-
cssVar.registerCssVariable(name);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
canAnimateNatively = false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
render = apply.styleRenderer(element, name);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* If we can animate this value with WAAPI, do so. Currently this only
|
|
83
|
-
* feature detects CSS.registerProperty but could check WAAPI too.
|
|
84
|
-
*/
|
|
85
|
-
if (canAnimateNatively) {
|
|
86
|
-
/**
|
|
87
|
-
* Convert numbers to default value types. Currently this only supports
|
|
88
|
-
* transforms but it could also support other value types.
|
|
89
|
-
*/
|
|
90
|
-
if (definition) {
|
|
91
|
-
keyframes$1 = keyframes$1.map((value) => isNumber.isNumber(value) ? definition.toDefaultUnit(value) : value);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* If this browser doesn't support partial/implicit keyframes we need to
|
|
95
|
-
* explicitly provide one.
|
|
96
|
-
*/
|
|
97
|
-
if (!featureDetection.supports.partialKeyframes() && keyframes$1.length === 1) {
|
|
98
|
-
keyframes$1.unshift(readInitialValue());
|
|
99
|
-
}
|
|
100
|
-
const animationOptions = {
|
|
101
|
-
delay: time.ms(delay),
|
|
102
|
-
duration: time.ms(duration),
|
|
103
|
-
endDelay: time.ms(endDelay),
|
|
104
|
-
easing: !easing.isEasingList(easing$1) ? easing.convertEasing(easing$1) : undefined,
|
|
105
|
-
direction,
|
|
106
|
-
iterations: repeat + 1,
|
|
107
|
-
fill: "both",
|
|
108
|
-
};
|
|
109
|
-
animation = element.animate({
|
|
110
|
-
[name]: keyframes$1,
|
|
111
|
-
offset,
|
|
112
|
-
easing: easing.isEasingList(easing$1) ? easing$1.map(easing.convertEasing) : undefined,
|
|
113
|
-
}, animationOptions);
|
|
114
|
-
/**
|
|
115
|
-
* Polyfill finished Promise in browsers that don't support it
|
|
116
|
-
*/
|
|
117
|
-
if (!animation.finished) {
|
|
118
|
-
animation.finished = new Promise((resolve, reject) => {
|
|
119
|
-
animation.onfinish = resolve;
|
|
120
|
-
animation.oncancel = reject;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
const target = keyframes$1[keyframes$1.length - 1];
|
|
124
|
-
animation.finished
|
|
125
|
-
.then(() => {
|
|
126
|
-
// Apply styles to target
|
|
127
|
-
render(target);
|
|
128
|
-
// Ensure fill modes don't persist
|
|
129
|
-
animation.cancel();
|
|
130
|
-
})
|
|
131
|
-
.catch(noop.noop);
|
|
132
|
-
/**
|
|
133
|
-
* This forces Webkit to run animations on the main thread by exploiting
|
|
134
|
-
* this condition:
|
|
135
|
-
* https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp?rev=281238#L1099
|
|
136
|
-
*
|
|
137
|
-
* This fixes Webkit's timing bugs, like accelerated animations falling
|
|
138
|
-
* out of sync with main thread animations and massive delays in starting
|
|
139
|
-
* accelerated animations in WKWebView.
|
|
140
|
-
*/
|
|
141
|
-
if (!allowWebkitAcceleration)
|
|
142
|
-
animation.playbackRate = 1.000001;
|
|
143
|
-
/**
|
|
144
|
-
* If we can't animate the value natively then we can fallback to the numbers-only
|
|
145
|
-
* polyfill for transforms. All keyframes must be numerical.
|
|
146
|
-
*/
|
|
147
|
-
}
|
|
148
|
-
else if (valueIsTransform && keyframes$1.every(isNumber.isNumber)) {
|
|
149
|
-
/**
|
|
150
|
-
* If we only have a single keyframe, we need to create an initial keyframe by reading
|
|
151
|
-
* the current value from the DOM.
|
|
152
|
-
*/
|
|
153
|
-
if (keyframes$1.length === 1) {
|
|
154
|
-
keyframes$1.unshift(parseFloat(readInitialValue()));
|
|
155
|
-
}
|
|
156
|
-
if (definition) {
|
|
157
|
-
const applyStyle = render;
|
|
158
|
-
render = (v) => applyStyle(definition.toDefaultUnit(v));
|
|
159
|
-
}
|
|
160
|
-
animation = new NumberAnimation.NumberAnimation(render, keyframes$1, Object.assign(Object.assign({}, options), { duration,
|
|
161
|
-
easing: easing$1 }));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
const target = keyframes$1[keyframes$1.length - 1];
|
|
165
|
-
render(definition && isNumber.isNumber(target)
|
|
166
|
-
? definition.toDefaultUnit(target)
|
|
167
|
-
: target);
|
|
168
|
-
}
|
|
169
|
-
data$1.animations[name] = animation;
|
|
170
|
-
/**
|
|
171
|
-
* When an animation finishes, delete the reference to the previous animation.
|
|
172
|
-
*/
|
|
173
|
-
animation === null || animation === void 0 ? void 0 : animation.finished.then(() => {
|
|
174
|
-
data$1.animations[name] = undefined;
|
|
175
|
-
data$1.generators[name] = undefined;
|
|
176
|
-
data$1.prevGeneratorState[name] = undefined;
|
|
177
|
-
}).catch(noop.noop);
|
|
178
|
-
return animation;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
exports.animateStyle = animateStyle;
|
|
@@ -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 };
|