motion-dom 12.24.11 → 12.26.2
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/dist/cjs/index.js +6197 -1833
- package/dist/es/animation/animate/single-value.mjs +11 -0
- package/dist/es/animation/interfaces/motion-value.mjs +102 -0
- package/dist/es/animation/interfaces/visual-element-target.mjs +85 -0
- package/dist/es/animation/interfaces/visual-element-variant.mjs +59 -0
- package/dist/es/animation/interfaces/visual-element.mjs +26 -0
- package/dist/es/animation/optimized-appear/data-id.mjs +6 -0
- package/dist/es/animation/optimized-appear/get-appear-id.mjs +7 -0
- package/dist/es/animation/utils/calc-child-stagger.mjs +15 -0
- package/dist/es/animation/utils/default-transitions.mjs +40 -0
- package/dist/es/animation/utils/get-final-keyframe.mjs +12 -0
- package/dist/es/animation/utils/is-transition-defined.mjs +10 -0
- package/dist/es/events/add-dom-event.mjs +6 -0
- package/dist/es/index.mjs +71 -0
- package/dist/es/projection/animation/mix-values.mjs +66 -0
- package/dist/es/projection/geometry/conversion.mjs +33 -0
- package/dist/es/projection/geometry/copy.mjs +31 -0
- package/dist/es/projection/geometry/delta-apply.mjs +119 -0
- package/dist/es/projection/geometry/delta-calc.mjs +52 -0
- package/dist/es/projection/geometry/delta-remove.mjs +54 -0
- package/dist/es/projection/geometry/models.mjs +17 -0
- package/dist/es/projection/geometry/utils.mjs +31 -0
- package/dist/es/projection/node/DocumentProjectionNode.mjs +13 -0
- package/dist/es/projection/node/HTMLProjectionNode.mjs +27 -0
- package/dist/es/projection/node/create-projection-node.mjs +1628 -0
- package/dist/es/projection/node/group.mjs +24 -0
- package/dist/es/projection/node/state.mjs +19 -0
- package/dist/es/projection/shared/stack.mjs +100 -0
- package/dist/es/projection/styles/scale-border-radius.mjs +41 -0
- package/dist/es/projection/styles/scale-box-shadow.mjs +35 -0
- package/dist/es/projection/styles/scale-correction.mjs +30 -0
- package/dist/es/projection/styles/transform.mjs +49 -0
- package/dist/es/projection/utils/compare-by-depth.mjs +3 -0
- package/dist/es/projection/utils/each-axis.mjs +5 -0
- package/dist/es/projection/utils/flat-tree.mjs +24 -0
- package/dist/es/projection/utils/has-transform.mjs +26 -0
- package/dist/es/projection/utils/measure.mjs +17 -0
- package/dist/es/render/Feature.mjs +14 -0
- package/dist/es/render/VisualElement.mjs +510 -0
- package/dist/es/render/dom/DOMVisualElement.mjs +42 -0
- package/dist/es/render/html/HTMLVisualElement.mjs +44 -0
- package/dist/es/render/html/utils/build-styles.mjs +65 -0
- package/dist/es/render/html/utils/build-transform.mjs +62 -0
- package/dist/es/render/html/utils/render.mjs +17 -0
- package/dist/es/render/html/utils/scrape-motion-values.mjs +21 -0
- package/dist/es/render/object/ObjectVisualElement.mjs +41 -0
- package/dist/es/render/store.mjs +3 -0
- package/dist/es/render/svg/SVGVisualElement.mjs +45 -0
- package/dist/es/render/svg/utils/build-attrs.mjs +72 -0
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +30 -0
- package/dist/es/render/svg/utils/is-svg-tag.mjs +3 -0
- package/dist/es/render/svg/utils/path.mjs +32 -0
- package/dist/es/render/svg/utils/render.mjs +12 -0
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +19 -0
- package/dist/es/render/utils/animation-state.mjs +364 -0
- package/dist/es/render/utils/get-variant-context.mjs +32 -0
- package/dist/es/render/utils/is-animation-controls.mjs +7 -0
- package/dist/es/render/utils/is-controlling-variants.mjs +13 -0
- package/dist/es/render/utils/is-forced-motion-value.mjs +12 -0
- package/dist/es/render/utils/is-keyframes-target.mjs +5 -0
- package/dist/es/render/utils/is-variant-label.mjs +8 -0
- package/dist/es/render/utils/motion-values.mjs +55 -0
- package/dist/es/render/utils/reduced-motion/index.mjs +19 -0
- package/dist/es/render/utils/reduced-motion/state.mjs +5 -0
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +8 -0
- package/dist/es/render/utils/resolve-variants.mjs +36 -0
- package/dist/es/render/utils/setters.mjs +31 -0
- package/dist/es/render/utils/shallow-compare.mjs +14 -0
- package/dist/es/render/utils/variant-props.mjs +12 -0
- package/dist/es/utils/delay.mjs +24 -0
- package/dist/es/value/utils/resolve-motion-value.mjs +10 -0
- package/dist/es/value/will-change/add-will-change.mjs +20 -0
- package/dist/es/value/will-change/is.mjs +7 -0
- package/dist/index.d.ts +3853 -2136
- package/dist/motion-dom.dev.js +6197 -1833
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { animateMotionValue } from '../interfaces/motion-value.mjs';
|
|
2
|
+
import { motionValue } from '../../value/index.mjs';
|
|
3
|
+
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
4
|
+
|
|
5
|
+
function animateSingleValue(value, keyframes, options) {
|
|
6
|
+
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
7
|
+
motionValue$1.start(animateMotionValue("", motionValue$1, keyframes, options));
|
|
8
|
+
return motionValue$1.animation;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { animateSingleValue };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { secondsToMilliseconds, MotionGlobalConfig } from 'motion-utils';
|
|
2
|
+
import { AsyncMotionValueAnimation } from '../AsyncMotionValueAnimation.mjs';
|
|
3
|
+
import { JSAnimation } from '../JSAnimation.mjs';
|
|
4
|
+
import { getValueTransition } from '../utils/get-value-transition.mjs';
|
|
5
|
+
import { makeAnimationInstant } from '../utils/make-animation-instant.mjs';
|
|
6
|
+
import { getDefaultTransition } from '../utils/default-transitions.mjs';
|
|
7
|
+
import { getFinalKeyframe } from '../utils/get-final-keyframe.mjs';
|
|
8
|
+
import { isTransitionDefined } from '../utils/is-transition-defined.mjs';
|
|
9
|
+
import { frame } from '../../frameloop/frame.mjs';
|
|
10
|
+
|
|
11
|
+
const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
|
|
12
|
+
const valueTransition = getValueTransition(transition, name) || {};
|
|
13
|
+
/**
|
|
14
|
+
* Most transition values are currently completely overwritten by value-specific
|
|
15
|
+
* transitions. In the future it'd be nicer to blend these transitions. But for now
|
|
16
|
+
* delay actually does inherit from the root transition if not value-specific.
|
|
17
|
+
*/
|
|
18
|
+
const delay = valueTransition.delay || transition.delay || 0;
|
|
19
|
+
/**
|
|
20
|
+
* Elapsed isn't a public transition option but can be passed through from
|
|
21
|
+
* optimized appear effects in milliseconds.
|
|
22
|
+
*/
|
|
23
|
+
let { elapsed = 0 } = transition;
|
|
24
|
+
elapsed = elapsed - secondsToMilliseconds(delay);
|
|
25
|
+
const options = {
|
|
26
|
+
keyframes: Array.isArray(target) ? target : [null, target],
|
|
27
|
+
ease: "easeOut",
|
|
28
|
+
velocity: value.getVelocity(),
|
|
29
|
+
...valueTransition,
|
|
30
|
+
delay: -elapsed,
|
|
31
|
+
onUpdate: (v) => {
|
|
32
|
+
value.set(v);
|
|
33
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
34
|
+
},
|
|
35
|
+
onComplete: () => {
|
|
36
|
+
onComplete();
|
|
37
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
38
|
+
},
|
|
39
|
+
name,
|
|
40
|
+
motionValue: value,
|
|
41
|
+
element: isHandoff ? undefined : element,
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* If there's no transition defined for this value, we can generate
|
|
45
|
+
* unique transition settings for this value.
|
|
46
|
+
*/
|
|
47
|
+
if (!isTransitionDefined(valueTransition)) {
|
|
48
|
+
Object.assign(options, getDefaultTransition(name, options));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Both WAAPI and our internal animation functions use durations
|
|
52
|
+
* as defined by milliseconds, while our external API defines them
|
|
53
|
+
* as seconds.
|
|
54
|
+
*/
|
|
55
|
+
options.duration && (options.duration = secondsToMilliseconds(options.duration));
|
|
56
|
+
options.repeatDelay && (options.repeatDelay = secondsToMilliseconds(options.repeatDelay));
|
|
57
|
+
/**
|
|
58
|
+
* Support deprecated way to set initial value. Prefer keyframe syntax.
|
|
59
|
+
*/
|
|
60
|
+
if (options.from !== undefined) {
|
|
61
|
+
options.keyframes[0] = options.from;
|
|
62
|
+
}
|
|
63
|
+
let shouldSkip = false;
|
|
64
|
+
if (options.type === false ||
|
|
65
|
+
(options.duration === 0 && !options.repeatDelay)) {
|
|
66
|
+
makeAnimationInstant(options);
|
|
67
|
+
if (options.delay === 0) {
|
|
68
|
+
shouldSkip = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (MotionGlobalConfig.instantAnimations ||
|
|
72
|
+
MotionGlobalConfig.skipAnimations) {
|
|
73
|
+
shouldSkip = true;
|
|
74
|
+
makeAnimationInstant(options);
|
|
75
|
+
options.delay = 0;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* If the transition type or easing has been explicitly set by the user
|
|
79
|
+
* then we don't want to allow flattening the animation.
|
|
80
|
+
*/
|
|
81
|
+
options.allowFlatten = !valueTransition.type && !valueTransition.ease;
|
|
82
|
+
/**
|
|
83
|
+
* If we can or must skip creating the animation, and apply only
|
|
84
|
+
* the final keyframe, do so. We also check once keyframes are resolved but
|
|
85
|
+
* this early check prevents the need to create an animation at all.
|
|
86
|
+
*/
|
|
87
|
+
if (shouldSkip && !isHandoff && value.get() !== undefined) {
|
|
88
|
+
const finalKeyframe = getFinalKeyframe(options.keyframes, valueTransition);
|
|
89
|
+
if (finalKeyframe !== undefined) {
|
|
90
|
+
frame.update(() => {
|
|
91
|
+
options.onUpdate(finalKeyframe);
|
|
92
|
+
options.onComplete();
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return valueTransition.isSync
|
|
98
|
+
? new JSAnimation(options)
|
|
99
|
+
: new AsyncMotionValueAnimation(options);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { animateMotionValue };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { getValueTransition } from '../utils/get-value-transition.mjs';
|
|
2
|
+
import { positionalKeys } from '../../render/utils/keys-position.mjs';
|
|
3
|
+
import { setTarget } from '../../render/utils/setters.mjs';
|
|
4
|
+
import { addValueToWillChange } from '../../value/will-change/add-will-change.mjs';
|
|
5
|
+
import { getOptimisedAppearId } from '../optimized-appear/get-appear-id.mjs';
|
|
6
|
+
import { animateMotionValue } from './motion-value.mjs';
|
|
7
|
+
import { frame } from '../../frameloop/frame.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Decide whether we should block this animation. Previously, we achieved this
|
|
11
|
+
* just by checking whether the key was listed in protectedKeys, but this
|
|
12
|
+
* posed problems if an animation was triggered by afterChildren and protectedKeys
|
|
13
|
+
* had been set to true in the meantime.
|
|
14
|
+
*/
|
|
15
|
+
function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
|
|
16
|
+
const shouldBlock = protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true;
|
|
17
|
+
needsAnimating[key] = false;
|
|
18
|
+
return shouldBlock;
|
|
19
|
+
}
|
|
20
|
+
function animateTarget(visualElement, targetAndTransition, { delay = 0, transitionOverride, type } = {}) {
|
|
21
|
+
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = targetAndTransition;
|
|
22
|
+
if (transitionOverride)
|
|
23
|
+
transition = transitionOverride;
|
|
24
|
+
const animations = [];
|
|
25
|
+
const animationTypeState = type &&
|
|
26
|
+
visualElement.animationState &&
|
|
27
|
+
visualElement.animationState.getState()[type];
|
|
28
|
+
for (const key in target) {
|
|
29
|
+
const value = visualElement.getValue(key, visualElement.latestValues[key] ?? null);
|
|
30
|
+
const valueTarget = target[key];
|
|
31
|
+
if (valueTarget === undefined ||
|
|
32
|
+
(animationTypeState &&
|
|
33
|
+
shouldBlockAnimation(animationTypeState, key))) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const valueTransition = {
|
|
37
|
+
delay,
|
|
38
|
+
...getValueTransition(transition || {}, key),
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* If the value is already at the defined target, skip the animation.
|
|
42
|
+
*/
|
|
43
|
+
const currentValue = value.get();
|
|
44
|
+
if (currentValue !== undefined &&
|
|
45
|
+
!value.isAnimating &&
|
|
46
|
+
!Array.isArray(valueTarget) &&
|
|
47
|
+
valueTarget === currentValue &&
|
|
48
|
+
!valueTransition.velocity) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* If this is the first time a value is being animated, check
|
|
53
|
+
* to see if we're handling off from an existing animation.
|
|
54
|
+
*/
|
|
55
|
+
let isHandoff = false;
|
|
56
|
+
if (window.MotionHandoffAnimation) {
|
|
57
|
+
const appearId = getOptimisedAppearId(visualElement);
|
|
58
|
+
if (appearId) {
|
|
59
|
+
const startTime = window.MotionHandoffAnimation(appearId, key, frame);
|
|
60
|
+
if (startTime !== null) {
|
|
61
|
+
valueTransition.startTime = startTime;
|
|
62
|
+
isHandoff = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
addValueToWillChange(visualElement, key);
|
|
67
|
+
value.start(animateMotionValue(key, value, valueTarget, visualElement.shouldReduceMotion && positionalKeys.has(key)
|
|
68
|
+
? { type: false }
|
|
69
|
+
: valueTransition, visualElement, isHandoff));
|
|
70
|
+
const animation = value.animation;
|
|
71
|
+
if (animation) {
|
|
72
|
+
animations.push(animation);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (transitionEnd) {
|
|
76
|
+
Promise.all(animations).then(() => {
|
|
77
|
+
frame.update(() => {
|
|
78
|
+
transitionEnd && setTarget(visualElement, transitionEnd);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return animations;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { animateTarget };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { resolveVariant } from '../../render/utils/resolve-dynamic-variants.mjs';
|
|
2
|
+
import { calcChildStagger } from '../utils/calc-child-stagger.mjs';
|
|
3
|
+
import { animateTarget } from './visual-element-target.mjs';
|
|
4
|
+
|
|
5
|
+
function animateVariant(visualElement, variant, options = {}) {
|
|
6
|
+
const resolved = resolveVariant(visualElement, variant, options.type === "exit"
|
|
7
|
+
? visualElement.presenceContext?.custom
|
|
8
|
+
: undefined);
|
|
9
|
+
let { transition = visualElement.getDefaultTransition() || {} } = resolved || {};
|
|
10
|
+
if (options.transitionOverride) {
|
|
11
|
+
transition = options.transitionOverride;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* If we have a variant, create a callback that runs it as an animation.
|
|
15
|
+
* Otherwise, we resolve a Promise immediately for a composable no-op.
|
|
16
|
+
*/
|
|
17
|
+
const getAnimation = resolved
|
|
18
|
+
? () => Promise.all(animateTarget(visualElement, resolved, options))
|
|
19
|
+
: () => Promise.resolve();
|
|
20
|
+
/**
|
|
21
|
+
* If we have children, create a callback that runs all their animations.
|
|
22
|
+
* Otherwise, we resolve a Promise immediately for a composable no-op.
|
|
23
|
+
*/
|
|
24
|
+
const getChildAnimations = visualElement.variantChildren && visualElement.variantChildren.size
|
|
25
|
+
? (forwardDelay = 0) => {
|
|
26
|
+
const { delayChildren = 0, staggerChildren, staggerDirection, } = transition;
|
|
27
|
+
return animateChildren(visualElement, variant, forwardDelay, delayChildren, staggerChildren, staggerDirection, options);
|
|
28
|
+
}
|
|
29
|
+
: () => Promise.resolve();
|
|
30
|
+
/**
|
|
31
|
+
* If the transition explicitly defines a "when" option, we need to resolve either
|
|
32
|
+
* this animation or all children animations before playing the other.
|
|
33
|
+
*/
|
|
34
|
+
const { when } = transition;
|
|
35
|
+
if (when) {
|
|
36
|
+
const [first, last] = when === "beforeChildren"
|
|
37
|
+
? [getAnimation, getChildAnimations]
|
|
38
|
+
: [getChildAnimations, getAnimation];
|
|
39
|
+
return first().then(() => last());
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return Promise.all([getAnimation(), getChildAnimations(options.delay)]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function animateChildren(visualElement, variant, delay = 0, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
|
|
46
|
+
const animations = [];
|
|
47
|
+
for (const child of visualElement.variantChildren) {
|
|
48
|
+
child.notify("AnimationStart", variant);
|
|
49
|
+
animations.push(animateVariant(child, variant, {
|
|
50
|
+
...options,
|
|
51
|
+
delay: delay +
|
|
52
|
+
(typeof delayChildren === "function" ? 0 : delayChildren) +
|
|
53
|
+
calcChildStagger(visualElement.variantChildren, child, delayChildren, staggerChildren, staggerDirection),
|
|
54
|
+
}).then(() => child.notify("AnimationComplete", variant)));
|
|
55
|
+
}
|
|
56
|
+
return Promise.all(animations);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { animateVariant };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { resolveVariant } from '../../render/utils/resolve-dynamic-variants.mjs';
|
|
2
|
+
import { animateTarget } from './visual-element-target.mjs';
|
|
3
|
+
import { animateVariant } from './visual-element-variant.mjs';
|
|
4
|
+
|
|
5
|
+
function animateVisualElement(visualElement, definition, options = {}) {
|
|
6
|
+
visualElement.notify("AnimationStart", definition);
|
|
7
|
+
let animation;
|
|
8
|
+
if (Array.isArray(definition)) {
|
|
9
|
+
const animations = definition.map((variant) => animateVariant(visualElement, variant, options));
|
|
10
|
+
animation = Promise.all(animations);
|
|
11
|
+
}
|
|
12
|
+
else if (typeof definition === "string") {
|
|
13
|
+
animation = animateVariant(visualElement, definition, options);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const resolvedDefinition = typeof definition === "function"
|
|
17
|
+
? resolveVariant(visualElement, definition, options.custom)
|
|
18
|
+
: definition;
|
|
19
|
+
animation = Promise.all(animateTarget(visualElement, resolvedDefinition, options));
|
|
20
|
+
}
|
|
21
|
+
return animation.then(() => {
|
|
22
|
+
visualElement.notify("AnimationComplete", definition);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { animateVisualElement };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { camelToDash } from '../../render/dom/utils/camel-to-dash.mjs';
|
|
2
|
+
|
|
3
|
+
const optimizedAppearDataId = "framerAppearId";
|
|
4
|
+
const optimizedAppearDataAttribute = "data-" + camelToDash(optimizedAppearDataId);
|
|
5
|
+
|
|
6
|
+
export { optimizedAppearDataAttribute, optimizedAppearDataId };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function calcChildStagger(children, child, delayChildren, staggerChildren = 0, staggerDirection = 1) {
|
|
2
|
+
const index = Array.from(children)
|
|
3
|
+
.sort((a, b) => a.sortNodePosition(b))
|
|
4
|
+
.indexOf(child);
|
|
5
|
+
const numChildren = children.size;
|
|
6
|
+
const maxStaggerDuration = (numChildren - 1) * staggerChildren;
|
|
7
|
+
const delayIsFunction = typeof delayChildren === "function";
|
|
8
|
+
return delayIsFunction
|
|
9
|
+
? delayChildren(index, numChildren)
|
|
10
|
+
: staggerDirection === 1
|
|
11
|
+
? index * staggerChildren
|
|
12
|
+
: maxStaggerDuration - index * staggerChildren;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { calcChildStagger };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { transformProps } from '../../render/utils/keys-transform.mjs';
|
|
2
|
+
|
|
3
|
+
const underDampedSpring = {
|
|
4
|
+
type: "spring",
|
|
5
|
+
stiffness: 500,
|
|
6
|
+
damping: 25,
|
|
7
|
+
restSpeed: 10,
|
|
8
|
+
};
|
|
9
|
+
const criticallyDampedSpring = (target) => ({
|
|
10
|
+
type: "spring",
|
|
11
|
+
stiffness: 550,
|
|
12
|
+
damping: target === 0 ? 2 * Math.sqrt(550) : 30,
|
|
13
|
+
restSpeed: 10,
|
|
14
|
+
});
|
|
15
|
+
const keyframesTransition = {
|
|
16
|
+
type: "keyframes",
|
|
17
|
+
duration: 0.8,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Default easing curve is a slightly shallower version of
|
|
21
|
+
* the default browser easing curve.
|
|
22
|
+
*/
|
|
23
|
+
const ease = {
|
|
24
|
+
type: "keyframes",
|
|
25
|
+
ease: [0.25, 0.1, 0.35, 1],
|
|
26
|
+
duration: 0.3,
|
|
27
|
+
};
|
|
28
|
+
const getDefaultTransition = (valueKey, { keyframes }) => {
|
|
29
|
+
if (keyframes.length > 2) {
|
|
30
|
+
return keyframesTransition;
|
|
31
|
+
}
|
|
32
|
+
else if (transformProps.has(valueKey)) {
|
|
33
|
+
return valueKey.startsWith("scale")
|
|
34
|
+
? criticallyDampedSpring(keyframes[1])
|
|
35
|
+
: underDampedSpring;
|
|
36
|
+
}
|
|
37
|
+
return ease;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { getDefaultTransition };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const isNotNull = (value) => value !== null;
|
|
2
|
+
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
3
|
+
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
4
|
+
const index = repeat && repeatType !== "loop" && repeat % 2 === 1
|
|
5
|
+
? 0
|
|
6
|
+
: resolvedKeyframes.length - 1;
|
|
7
|
+
return !index || finalKeyframe === undefined
|
|
8
|
+
? resolvedKeyframes[index]
|
|
9
|
+
: finalKeyframe;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { getFinalKeyframe };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decide whether a transition is defined on a given Transition.
|
|
3
|
+
* This filters out orchestration options and returns true
|
|
4
|
+
* if any options are left.
|
|
5
|
+
*/
|
|
6
|
+
function isTransitionDefined({ when, delay: _delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, elapsed, ...transition }) {
|
|
7
|
+
return !!Object.keys(transition).length;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { isTransitionDefined };
|
package/dist/es/index.mjs
CHANGED
|
@@ -10,6 +10,16 @@ export { getVariableValue, parseCSSVariable } from './animation/utils/css-variab
|
|
|
10
10
|
export { getValueTransition } from './animation/utils/get-value-transition.mjs';
|
|
11
11
|
export { containsCSSVariable, isCSSVariableName, isCSSVariableToken } from './animation/utils/is-css-variable.mjs';
|
|
12
12
|
export { makeAnimationInstant } from './animation/utils/make-animation-instant.mjs';
|
|
13
|
+
export { getDefaultTransition } from './animation/utils/default-transitions.mjs';
|
|
14
|
+
export { isTransitionDefined } from './animation/utils/is-transition-defined.mjs';
|
|
15
|
+
export { getFinalKeyframe } from './animation/utils/get-final-keyframe.mjs';
|
|
16
|
+
export { calcChildStagger } from './animation/utils/calc-child-stagger.mjs';
|
|
17
|
+
export { animateMotionValue } from './animation/interfaces/motion-value.mjs';
|
|
18
|
+
export { animateTarget } from './animation/interfaces/visual-element-target.mjs';
|
|
19
|
+
export { animateVariant } from './animation/interfaces/visual-element-variant.mjs';
|
|
20
|
+
export { animateVisualElement } from './animation/interfaces/visual-element.mjs';
|
|
21
|
+
export { optimizedAppearDataAttribute, optimizedAppearDataId } from './animation/optimized-appear/data-id.mjs';
|
|
22
|
+
export { getOptimisedAppearId } from './animation/optimized-appear/get-appear-id.mjs';
|
|
13
23
|
export { inertia } from './animation/generators/inertia.mjs';
|
|
14
24
|
export { defaultEasing, keyframes } from './animation/generators/keyframes.mjs';
|
|
15
25
|
export { spring } from './animation/generators/spring/index.mjs';
|
|
@@ -52,6 +62,7 @@ export { getComputedStyle } from './render/dom/style-computed.mjs';
|
|
|
52
62
|
export { setStyle } from './render/dom/style-set.mjs';
|
|
53
63
|
export { positionalKeys } from './render/utils/keys-position.mjs';
|
|
54
64
|
export { transformPropOrder, transformProps } from './render/utils/keys-transform.mjs';
|
|
65
|
+
export { isKeyframesTarget } from './render/utils/is-keyframes-target.mjs';
|
|
55
66
|
export { resize } from './resize/index.mjs';
|
|
56
67
|
export { observeTimeline } from './scroll/observe.mjs';
|
|
57
68
|
export { recordStats } from './stats/index.mjs';
|
|
@@ -94,8 +105,68 @@ export { getAnimatableNone } from './value/types/utils/animatable-none.mjs';
|
|
|
94
105
|
export { findValueType } from './value/types/utils/find.mjs';
|
|
95
106
|
export { getValueAsType } from './value/types/utils/get-as-type.mjs';
|
|
96
107
|
export { isMotionValue } from './value/utils/is-motion-value.mjs';
|
|
108
|
+
export { isWillChangeMotionValue } from './value/will-change/is.mjs';
|
|
109
|
+
export { addValueToWillChange } from './value/will-change/add-will-change.mjs';
|
|
97
110
|
export { ViewTransitionBuilder, animateView } from './view/index.mjs';
|
|
98
111
|
export { getViewAnimationLayerInfo } from './view/utils/get-layer-info.mjs';
|
|
99
112
|
export { getViewAnimations } from './view/utils/get-view-animations.mjs';
|
|
113
|
+
export { VisualElement, getFeatureDefinitions, setFeatureDefinitions } from './render/VisualElement.mjs';
|
|
114
|
+
export { Feature } from './render/Feature.mjs';
|
|
115
|
+
export { DOMVisualElement } from './render/dom/DOMVisualElement.mjs';
|
|
116
|
+
export { HTMLVisualElement } from './render/html/HTMLVisualElement.mjs';
|
|
117
|
+
export { SVGVisualElement } from './render/svg/SVGVisualElement.mjs';
|
|
118
|
+
export { ObjectVisualElement } from './render/object/ObjectVisualElement.mjs';
|
|
119
|
+
export { visualElementStore } from './render/store.mjs';
|
|
120
|
+
export { checkVariantsDidChange, createAnimationState } from './render/utils/animation-state.mjs';
|
|
121
|
+
export { isVariantLabel } from './render/utils/is-variant-label.mjs';
|
|
122
|
+
export { isControllingVariants, isVariantNode } from './render/utils/is-controlling-variants.mjs';
|
|
123
|
+
export { getVariantContext } from './render/utils/get-variant-context.mjs';
|
|
124
|
+
export { resolveVariantFromProps } from './render/utils/resolve-variants.mjs';
|
|
125
|
+
export { resolveVariant } from './render/utils/resolve-dynamic-variants.mjs';
|
|
126
|
+
export { updateMotionValuesFromProps } from './render/utils/motion-values.mjs';
|
|
127
|
+
export { variantPriorityOrder, variantProps } from './render/utils/variant-props.mjs';
|
|
128
|
+
export { isAnimationControls } from './render/utils/is-animation-controls.mjs';
|
|
129
|
+
export { isForcedMotionValue } from './render/utils/is-forced-motion-value.mjs';
|
|
130
|
+
export { setTarget } from './render/utils/setters.mjs';
|
|
131
|
+
export { initPrefersReducedMotion } from './render/utils/reduced-motion/index.mjs';
|
|
132
|
+
export { createAxis, createAxisDelta, createBox, createDelta } from './projection/geometry/models.mjs';
|
|
133
|
+
export { calcAxisDelta, calcBoxDelta, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, isNear } from './projection/geometry/delta-calc.mjs';
|
|
134
|
+
export { applyAxisDelta, applyBoxDelta, applyPointDelta, applyTreeDeltas, scalePoint, transformAxis, transformBox, translateAxis } from './projection/geometry/delta-apply.mjs';
|
|
135
|
+
export { removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta } from './projection/geometry/delta-remove.mjs';
|
|
136
|
+
export { copyAxisDeltaInto, copyAxisInto, copyBoxInto } from './projection/geometry/copy.mjs';
|
|
137
|
+
export { convertBoundingBoxToBox, convertBoxToBoundingBox, transformBoxPoints } from './projection/geometry/conversion.mjs';
|
|
138
|
+
export { aspectRatio, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, isDeltaZero } from './projection/geometry/utils.mjs';
|
|
139
|
+
export { has2DTranslate, hasScale, hasTransform } from './projection/utils/has-transform.mjs';
|
|
140
|
+
export { measurePageBox, measureViewportBox } from './projection/utils/measure.mjs';
|
|
141
|
+
export { eachAxis } from './projection/utils/each-axis.mjs';
|
|
142
|
+
export { correctBorderRadius, pixelsToPercent } from './projection/styles/scale-border-radius.mjs';
|
|
143
|
+
export { correctBoxShadow } from './projection/styles/scale-box-shadow.mjs';
|
|
144
|
+
export { buildProjectionTransform } from './projection/styles/transform.mjs';
|
|
145
|
+
export { mixValues } from './projection/animation/mix-values.mjs';
|
|
146
|
+
export { delay, delayInSeconds } from './utils/delay.mjs';
|
|
147
|
+
export { addDomEvent } from './events/add-dom-event.mjs';
|
|
148
|
+
export { resolveMotionValue } from './value/utils/resolve-motion-value.mjs';
|
|
149
|
+
export { animateSingleValue } from './animation/animate/single-value.mjs';
|
|
150
|
+
export { FlatTree } from './projection/utils/flat-tree.mjs';
|
|
151
|
+
export { compareByDepth } from './projection/utils/compare-by-depth.mjs';
|
|
152
|
+
export { cleanDirtyNodes, createProjectionNode, propagateDirtyNodes } from './projection/node/create-projection-node.mjs';
|
|
153
|
+
export { HTMLProjectionNode, rootProjectionNode } from './projection/node/HTMLProjectionNode.mjs';
|
|
154
|
+
export { DocumentProjectionNode } from './projection/node/DocumentProjectionNode.mjs';
|
|
155
|
+
export { globalProjectionState } from './projection/node/state.mjs';
|
|
156
|
+
export { nodeGroup } from './projection/node/group.mjs';
|
|
157
|
+
export { NodeStack } from './projection/shared/stack.mjs';
|
|
158
|
+
export { buildHTMLStyles } from './render/html/utils/build-styles.mjs';
|
|
159
|
+
export { buildTransform } from './render/html/utils/build-transform.mjs';
|
|
160
|
+
export { renderHTML } from './render/html/utils/render.mjs';
|
|
161
|
+
export { scrapeMotionValuesFromProps as scrapeHTMLMotionValuesFromProps } from './render/html/utils/scrape-motion-values.mjs';
|
|
162
|
+
export { buildSVGAttrs } from './render/svg/utils/build-attrs.mjs';
|
|
163
|
+
export { renderSVG } from './render/svg/utils/render.mjs';
|
|
164
|
+
export { buildSVGPath } from './render/svg/utils/path.mjs';
|
|
165
|
+
export { camelCaseAttributes } from './render/svg/utils/camel-case-attrs.mjs';
|
|
166
|
+
export { isSVGTag } from './render/svg/utils/is-svg-tag.mjs';
|
|
167
|
+
export { scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps } from './render/svg/utils/scrape-motion-values.mjs';
|
|
168
|
+
export { camelToDash } from './render/dom/utils/camel-to-dash.mjs';
|
|
100
169
|
export { cancelSync, sync } from './frameloop/index-legacy.mjs';
|
|
170
|
+
export { addScaleCorrector, scaleCorrectors } from './projection/styles/scale-correction.mjs';
|
|
171
|
+
export { hasReducedMotionListener, prefersReducedMotion } from './render/utils/reduced-motion/state.mjs';
|
|
101
172
|
export { cancelFrame, frame, frameData, frameSteps } from './frameloop/frame.mjs';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { mixNumber } from '../../utils/mix/number.mjs';
|
|
2
|
+
import { percent, px } from '../../value/types/numbers/units.mjs';
|
|
3
|
+
import { progress, circOut, noop } from 'motion-utils';
|
|
4
|
+
|
|
5
|
+
const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
|
|
6
|
+
const numBorders = borders.length;
|
|
7
|
+
const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
|
|
8
|
+
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
9
|
+
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
10
|
+
if (shouldCrossfadeOpacity) {
|
|
11
|
+
target.opacity = mixNumber(0, lead.opacity ?? 1, easeCrossfadeIn(progress));
|
|
12
|
+
target.opacityExit = mixNumber(follow.opacity ?? 1, 0, easeCrossfadeOut(progress));
|
|
13
|
+
}
|
|
14
|
+
else if (isOnlyMember) {
|
|
15
|
+
target.opacity = mixNumber(follow.opacity ?? 1, lead.opacity ?? 1, progress);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mix border radius
|
|
19
|
+
*/
|
|
20
|
+
for (let i = 0; i < numBorders; i++) {
|
|
21
|
+
const borderLabel = `border${borders[i]}Radius`;
|
|
22
|
+
let followRadius = getRadius(follow, borderLabel);
|
|
23
|
+
let leadRadius = getRadius(lead, borderLabel);
|
|
24
|
+
if (followRadius === undefined && leadRadius === undefined)
|
|
25
|
+
continue;
|
|
26
|
+
followRadius || (followRadius = 0);
|
|
27
|
+
leadRadius || (leadRadius = 0);
|
|
28
|
+
const canMix = followRadius === 0 ||
|
|
29
|
+
leadRadius === 0 ||
|
|
30
|
+
isPx(followRadius) === isPx(leadRadius);
|
|
31
|
+
if (canMix) {
|
|
32
|
+
target[borderLabel] = Math.max(mixNumber(asNumber(followRadius), asNumber(leadRadius), progress), 0);
|
|
33
|
+
if (percent.test(leadRadius) || percent.test(followRadius)) {
|
|
34
|
+
target[borderLabel] += "%";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
target[borderLabel] = leadRadius;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Mix rotation
|
|
43
|
+
*/
|
|
44
|
+
if (follow.rotate || lead.rotate) {
|
|
45
|
+
target.rotate = mixNumber(follow.rotate || 0, lead.rotate || 0, progress);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function getRadius(values, radiusName) {
|
|
49
|
+
return values[radiusName] !== undefined
|
|
50
|
+
? values[radiusName]
|
|
51
|
+
: values.borderRadius;
|
|
52
|
+
}
|
|
53
|
+
const easeCrossfadeIn = /*@__PURE__*/ compress(0, 0.5, circOut);
|
|
54
|
+
const easeCrossfadeOut = /*@__PURE__*/ compress(0.5, 0.95, noop);
|
|
55
|
+
function compress(min, max, easing) {
|
|
56
|
+
return (p) => {
|
|
57
|
+
// Could replace ifs with clamp
|
|
58
|
+
if (p < min)
|
|
59
|
+
return 0;
|
|
60
|
+
if (p > max)
|
|
61
|
+
return 1;
|
|
62
|
+
return easing(progress(min, max, p));
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { mixValues };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounding boxes tend to be defined as top, left, right, bottom. For various operations
|
|
3
|
+
* it's easier to consider each axis individually. This function returns a bounding box
|
|
4
|
+
* as a map of single-axis min/max values.
|
|
5
|
+
*/
|
|
6
|
+
function convertBoundingBoxToBox({ top, left, right, bottom, }) {
|
|
7
|
+
return {
|
|
8
|
+
x: { min: left, max: right },
|
|
9
|
+
y: { min: top, max: bottom },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function convertBoxToBoundingBox({ x, y }) {
|
|
13
|
+
return { top: y.min, right: x.max, bottom: y.max, left: x.min };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Applies a TransformPoint function to a bounding box. TransformPoint is usually a function
|
|
17
|
+
* provided by Framer to allow measured points to be corrected for device scaling. This is used
|
|
18
|
+
* when measuring DOM elements and DOM event points.
|
|
19
|
+
*/
|
|
20
|
+
function transformBoxPoints(point, transformPoint) {
|
|
21
|
+
if (!transformPoint)
|
|
22
|
+
return point;
|
|
23
|
+
const topLeft = transformPoint({ x: point.left, y: point.top });
|
|
24
|
+
const bottomRight = transformPoint({ x: point.right, y: point.bottom });
|
|
25
|
+
return {
|
|
26
|
+
top: topLeft.y,
|
|
27
|
+
left: topLeft.x,
|
|
28
|
+
bottom: bottomRight.y,
|
|
29
|
+
right: bottomRight.x,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { convertBoundingBoxToBox, convertBoxToBoundingBox, transformBoxPoints };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reset an axis to the provided origin box.
|
|
3
|
+
*
|
|
4
|
+
* This is a mutative operation.
|
|
5
|
+
*/
|
|
6
|
+
function copyAxisInto(axis, originAxis) {
|
|
7
|
+
axis.min = originAxis.min;
|
|
8
|
+
axis.max = originAxis.max;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reset a box to the provided origin box.
|
|
12
|
+
*
|
|
13
|
+
* This is a mutative operation.
|
|
14
|
+
*/
|
|
15
|
+
function copyBoxInto(box, originBox) {
|
|
16
|
+
copyAxisInto(box.x, originBox.x);
|
|
17
|
+
copyAxisInto(box.y, originBox.y);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reset a delta to the provided origin box.
|
|
21
|
+
*
|
|
22
|
+
* This is a mutative operation.
|
|
23
|
+
*/
|
|
24
|
+
function copyAxisDeltaInto(delta, originDelta) {
|
|
25
|
+
delta.translate = originDelta.translate;
|
|
26
|
+
delta.scale = originDelta.scale;
|
|
27
|
+
delta.originPoint = originDelta.originPoint;
|
|
28
|
+
delta.origin = originDelta.origin;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { copyAxisDeltaInto, copyAxisInto, copyBoxInto };
|