framer-motion 12.4.10 → 12.4.12
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/client.js +1 -1
- package/dist/cjs/{create-C1YMxw9b.js → create-Da6xW2BP.js} +25 -37
- package/dist/cjs/dom-mini.js +2 -0
- package/dist/cjs/dom.js +12 -3
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/mini.js +2 -0
- package/dist/dom-mini.js +1 -1
- package/dist/dom.js +1 -1
- package/dist/es/animation/animators/BaseAnimation.mjs +2 -0
- package/dist/es/animation/animators/waapi/animate-elements.mjs +2 -0
- package/dist/es/animation/interfaces/motion-value.mjs +6 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +2 -0
- package/dist/es/gestures/pan/PanSession.mjs +9 -35
- package/dist/es/gestures/pan/index.mjs +2 -0
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/utils/get-context-window.mjs +6 -0
- package/dist/es/value/index.mjs +1 -1
- package/dist/framer-motion.dev.js +30 -40
- package/dist/framer-motion.js +1 -1
- package/dist/mini.js +1 -1
- package/dist/size-rollup-animate.js +1 -0
- package/dist/size-rollup-dom-animation-assets.js +1 -0
- package/dist/size-rollup-dom-animation-m.js +1 -0
- package/dist/size-rollup-dom-animation.js +1 -0
- package/dist/size-rollup-dom-max-assets.js +1 -0
- package/dist/size-rollup-dom-max.js +1 -0
- package/dist/size-rollup-m.js +1 -0
- package/dist/size-rollup-motion.js +1 -0
- package/dist/size-rollup-scroll.js +1 -0
- package/dist/size-rollup-waapi-animate.js +1 -0
- package/package.json +10 -10
package/dist/cjs/client.js
CHANGED
|
@@ -410,7 +410,7 @@ class MotionValue {
|
|
|
410
410
|
* This will be replaced by the build step with the latest version number.
|
|
411
411
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
412
412
|
*/
|
|
413
|
-
this.version = "12.4.
|
|
413
|
+
this.version = "12.4.12";
|
|
414
414
|
/**
|
|
415
415
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
416
416
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -1836,6 +1836,8 @@ class BaseAnimation {
|
|
|
1836
1836
|
return this.currentFinishedPromise.then(resolve, reject);
|
|
1837
1837
|
}
|
|
1838
1838
|
flatten() {
|
|
1839
|
+
if (!this.options.allowFlatten)
|
|
1840
|
+
return;
|
|
1839
1841
|
this.options.type = "keyframes";
|
|
1840
1842
|
this.options.ease = "linear";
|
|
1841
1843
|
}
|
|
@@ -3400,7 +3402,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3400
3402
|
};
|
|
3401
3403
|
/**
|
|
3402
3404
|
* If there's no transition defined for this value, we can generate
|
|
3403
|
-
*
|
|
3405
|
+
* unique transition settings for this value.
|
|
3404
3406
|
*/
|
|
3405
3407
|
if (!isTransitionDefined(valueTransition)) {
|
|
3406
3408
|
options = {
|
|
@@ -3436,6 +3438,11 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3436
3438
|
options.duration = 0;
|
|
3437
3439
|
options.delay = 0;
|
|
3438
3440
|
}
|
|
3441
|
+
/**
|
|
3442
|
+
* If the transition type or easing has been explicitly set by the user
|
|
3443
|
+
* then we don't want to allow flattening the animation.
|
|
3444
|
+
*/
|
|
3445
|
+
options.allowFlatten = !valueTransition.type && !valueTransition.ease;
|
|
3439
3446
|
/**
|
|
3440
3447
|
* If we can or must skip creating the animation, and apply only
|
|
3441
3448
|
* the final keyframe, do so. We also check once keyframes are resolved but
|
|
@@ -4570,7 +4577,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4570
4577
|
* and warn against mismatches.
|
|
4571
4578
|
*/
|
|
4572
4579
|
if (process.env.NODE_ENV === "development") {
|
|
4573
|
-
warnOnce(nextValue.version === "12.4.
|
|
4580
|
+
warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
|
|
4574
4581
|
}
|
|
4575
4582
|
}
|
|
4576
4583
|
else if (isMotionValue(prevValue)) {
|
|
@@ -7760,6 +7767,11 @@ function loadFeatures(features) {
|
|
|
7760
7767
|
}
|
|
7761
7768
|
}
|
|
7762
7769
|
|
|
7770
|
+
// Fixes https://github.com/motiondivision/motion/issues/2270
|
|
7771
|
+
const getContextWindow = ({ current }) => {
|
|
7772
|
+
return current ? current.ownerDocument.defaultView : null;
|
|
7773
|
+
};
|
|
7774
|
+
|
|
7763
7775
|
function isRefObject(ref) {
|
|
7764
7776
|
return (ref &&
|
|
7765
7777
|
typeof ref === "object" &&
|
|
@@ -7770,7 +7782,7 @@ function isRefObject(ref) {
|
|
|
7770
7782
|
* @internal
|
|
7771
7783
|
*/
|
|
7772
7784
|
class PanSession {
|
|
7773
|
-
constructor(event, handlers, { transformPagePoint, dragSnapToOrigin = false } = {}) {
|
|
7785
|
+
constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
|
|
7774
7786
|
/**
|
|
7775
7787
|
* @internal
|
|
7776
7788
|
*/
|
|
@@ -7787,6 +7799,10 @@ class PanSession {
|
|
|
7787
7799
|
* @internal
|
|
7788
7800
|
*/
|
|
7789
7801
|
this.handlers = {};
|
|
7802
|
+
/**
|
|
7803
|
+
* @internal
|
|
7804
|
+
*/
|
|
7805
|
+
this.contextWindow = window;
|
|
7790
7806
|
this.updatePoint = () => {
|
|
7791
7807
|
if (!(this.lastMoveEvent && this.lastMoveEventInfo))
|
|
7792
7808
|
return;
|
|
@@ -7809,32 +7825,19 @@ class PanSession {
|
|
|
7809
7825
|
onMove && onMove(this.lastMoveEvent, info);
|
|
7810
7826
|
};
|
|
7811
7827
|
this.handlePointerMove = (event, info) => {
|
|
7812
|
-
this.index = getElementIndex(event.currentTarget);
|
|
7813
|
-
if (event.target instanceof Element &&
|
|
7814
|
-
event.target.hasPointerCapture &&
|
|
7815
|
-
event.pointerId !== undefined) {
|
|
7816
|
-
try {
|
|
7817
|
-
if (!event.target.hasPointerCapture(event.pointerId)) {
|
|
7818
|
-
return;
|
|
7819
|
-
}
|
|
7820
|
-
}
|
|
7821
|
-
catch (e) { }
|
|
7822
|
-
}
|
|
7823
7828
|
this.lastMoveEvent = event;
|
|
7824
7829
|
this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
|
7825
7830
|
// Throttle mouse move event to once per frame
|
|
7826
7831
|
frame.update(this.updatePoint, true);
|
|
7827
7832
|
};
|
|
7828
7833
|
this.handlePointerUp = (event, info) => {
|
|
7829
|
-
motionDom.capturePointer(event, "release");
|
|
7830
7834
|
this.end();
|
|
7831
7835
|
const { onEnd, onSessionEnd, resumeAnimation } = this.handlers;
|
|
7832
7836
|
if (this.dragSnapToOrigin)
|
|
7833
7837
|
resumeAnimation && resumeAnimation();
|
|
7834
7838
|
if (!(this.lastMoveEvent && this.lastMoveEventInfo))
|
|
7835
7839
|
return;
|
|
7836
|
-
const panInfo = getPanInfo(event.type === "pointercancel"
|
|
7837
|
-
event.type === "lostpointercapture"
|
|
7840
|
+
const panInfo = getPanInfo(event.type === "pointercancel"
|
|
7838
7841
|
? this.lastMoveEventInfo
|
|
7839
7842
|
: transformPoint(info, this.transformPagePoint), this.history);
|
|
7840
7843
|
if (this.startEvent && onEnd) {
|
|
@@ -7848,6 +7851,7 @@ class PanSession {
|
|
|
7848
7851
|
this.dragSnapToOrigin = dragSnapToOrigin;
|
|
7849
7852
|
this.handlers = handlers;
|
|
7850
7853
|
this.transformPagePoint = transformPagePoint;
|
|
7854
|
+
this.contextWindow = contextWindow || window;
|
|
7851
7855
|
const info = extractEventInfo(event);
|
|
7852
7856
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
7853
7857
|
const { point } = initialInfo;
|
|
@@ -7856,20 +7860,7 @@ class PanSession {
|
|
|
7856
7860
|
const { onSessionStart } = handlers;
|
|
7857
7861
|
onSessionStart &&
|
|
7858
7862
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
7859
|
-
|
|
7860
|
-
this.removeListeners = pipe(addPointerEvent(event.currentTarget, "pointermove", this.handlePointerMove), addPointerEvent(event.currentTarget, "pointerup", this.handlePointerUp), addPointerEvent(event.currentTarget, "pointercancel", this.handlePointerUp), addPointerEvent(event.currentTarget, "lostpointercapture", (lostPointerEvent, lostPointerInfo) => {
|
|
7861
|
-
const index = getElementIndex(lostPointerEvent.currentTarget);
|
|
7862
|
-
/**
|
|
7863
|
-
* If the pointer has lost capture because it's moved in the DOM
|
|
7864
|
-
* then we need to re-capture it.
|
|
7865
|
-
*/
|
|
7866
|
-
if (index !== this.index) {
|
|
7867
|
-
motionDom.capturePointer(lostPointerEvent, "set");
|
|
7868
|
-
}
|
|
7869
|
-
else {
|
|
7870
|
-
this.handlePointerUp(lostPointerEvent, lostPointerInfo);
|
|
7871
|
-
}
|
|
7872
|
-
}));
|
|
7863
|
+
this.removeListeners = pipe(addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove), addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp), addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp));
|
|
7873
7864
|
}
|
|
7874
7865
|
updateHandlers(handlers) {
|
|
7875
7866
|
this.handlers = handlers;
|
|
@@ -7933,11 +7924,6 @@ function getVelocity(history, timeDelta) {
|
|
|
7933
7924
|
}
|
|
7934
7925
|
return currentVelocity;
|
|
7935
7926
|
}
|
|
7936
|
-
function getElementIndex(element) {
|
|
7937
|
-
if (!element.parentNode)
|
|
7938
|
-
return -1;
|
|
7939
|
-
return Array.from(element.parentNode.children).indexOf(element);
|
|
7940
|
-
}
|
|
7941
7927
|
|
|
7942
7928
|
/**
|
|
7943
7929
|
* Apply constraints to a point. These constraints are both physical along an
|
|
@@ -8194,6 +8180,7 @@ class VisualElementDragControls {
|
|
|
8194
8180
|
}, {
|
|
8195
8181
|
transformPagePoint: this.visualElement.getTransformPagePoint(),
|
|
8196
8182
|
dragSnapToOrigin,
|
|
8183
|
+
contextWindow: getContextWindow(this.visualElement),
|
|
8197
8184
|
});
|
|
8198
8185
|
}
|
|
8199
8186
|
stop(event, info) {
|
|
@@ -8559,6 +8546,7 @@ class PanGesture extends Feature {
|
|
|
8559
8546
|
onPointerDown(pointerDownEvent) {
|
|
8560
8547
|
this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
|
|
8561
8548
|
transformPagePoint: this.node.getTransformPagePoint(),
|
|
8549
|
+
contextWindow: getContextWindow(this.node),
|
|
8562
8550
|
});
|
|
8563
8551
|
}
|
|
8564
8552
|
createPanHandlers() {
|
package/dist/cjs/dom-mini.js
CHANGED
|
@@ -619,6 +619,8 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
619
619
|
? motionUtils.secondsToMilliseconds(valueOptions.duration)
|
|
620
620
|
: valueOptions.duration;
|
|
621
621
|
valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay || 0);
|
|
622
|
+
valueOptions.allowFlatten =
|
|
623
|
+
!elementTransition.type && !elementTransition.ease;
|
|
622
624
|
animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
|
|
623
625
|
}
|
|
624
626
|
}
|
package/dist/cjs/dom.js
CHANGED
|
@@ -1011,7 +1011,7 @@ class MotionValue {
|
|
|
1011
1011
|
* This will be replaced by the build step with the latest version number.
|
|
1012
1012
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1013
1013
|
*/
|
|
1014
|
-
this.version = "12.4.
|
|
1014
|
+
this.version = "12.4.12";
|
|
1015
1015
|
/**
|
|
1016
1016
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
1017
1017
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -2460,6 +2460,8 @@ class BaseAnimation {
|
|
|
2460
2460
|
return this.currentFinishedPromise.then(resolve, reject);
|
|
2461
2461
|
}
|
|
2462
2462
|
flatten() {
|
|
2463
|
+
if (!this.options.allowFlatten)
|
|
2464
|
+
return;
|
|
2463
2465
|
this.options.type = "keyframes";
|
|
2464
2466
|
this.options.ease = "linear";
|
|
2465
2467
|
}
|
|
@@ -3707,7 +3709,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3707
3709
|
};
|
|
3708
3710
|
/**
|
|
3709
3711
|
* If there's no transition defined for this value, we can generate
|
|
3710
|
-
*
|
|
3712
|
+
* unique transition settings for this value.
|
|
3711
3713
|
*/
|
|
3712
3714
|
if (!isTransitionDefined(valueTransition)) {
|
|
3713
3715
|
options = {
|
|
@@ -3737,6 +3739,11 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
3737
3739
|
shouldSkip = true;
|
|
3738
3740
|
}
|
|
3739
3741
|
}
|
|
3742
|
+
/**
|
|
3743
|
+
* If the transition type or easing has been explicitly set by the user
|
|
3744
|
+
* then we don't want to allow flattening the animation.
|
|
3745
|
+
*/
|
|
3746
|
+
options.allowFlatten = !valueTransition.type && !valueTransition.ease;
|
|
3740
3747
|
/**
|
|
3741
3748
|
* If we can or must skip creating the animation, and apply only
|
|
3742
3749
|
* the final keyframe, do so. We also check once keyframes are resolved but
|
|
@@ -3947,7 +3954,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3947
3954
|
* and warn against mismatches.
|
|
3948
3955
|
*/
|
|
3949
3956
|
if (process.env.NODE_ENV === "development") {
|
|
3950
|
-
warnOnce(nextValue.version === "12.4.
|
|
3957
|
+
warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
|
|
3951
3958
|
}
|
|
3952
3959
|
}
|
|
3953
3960
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5211,6 +5218,8 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
5211
5218
|
? motionUtils.secondsToMilliseconds(valueOptions.duration)
|
|
5212
5219
|
: valueOptions.duration;
|
|
5213
5220
|
valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay || 0);
|
|
5221
|
+
valueOptions.allowFlatten =
|
|
5222
|
+
!elementTransition.type && !elementTransition.ease;
|
|
5214
5223
|
animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
|
|
5215
5224
|
}
|
|
5216
5225
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var create = require('./create-
|
|
7
|
+
var create = require('./create-Da6xW2BP.js');
|
|
8
8
|
var motionUtils = require('motion-utils');
|
|
9
9
|
var motionDom = require('motion-dom');
|
|
10
10
|
|
|
@@ -1017,6 +1017,8 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
1017
1017
|
? motionUtils.secondsToMilliseconds(valueOptions.duration)
|
|
1018
1018
|
: valueOptions.duration;
|
|
1019
1019
|
valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay || 0);
|
|
1020
|
+
valueOptions.allowFlatten =
|
|
1021
|
+
!elementTransition.type && !elementTransition.ease;
|
|
1020
1022
|
animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
|
|
1021
1023
|
}
|
|
1022
1024
|
}
|
package/dist/cjs/mini.js
CHANGED
|
@@ -246,6 +246,8 @@ function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
|
246
246
|
? motionUtils.secondsToMilliseconds(valueOptions.duration)
|
|
247
247
|
: valueOptions.duration;
|
|
248
248
|
valueOptions.delay = motionUtils.secondsToMilliseconds(valueOptions.delay || 0);
|
|
249
|
+
valueOptions.allowFlatten =
|
|
250
|
+
!elementTransition.type && !elementTransition.ease;
|
|
249
251
|
animations.push(new NativeAnimation(element, valueName, valueKeyframes, valueOptions));
|
|
250
252
|
}
|
|
251
253
|
}
|
package/dist/dom-mini.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";const e=t=>t;let n=e;function i(t){let e;return()=>(void 0===e&&(e=t()),e)}const a=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},s=t=>1e3*t,o=t=>t/1e3,r=i(()=>void 0!==window.ScrollTimeline);class u extends class{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>"finished"in t?t.finished:t))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const n=this.animations.map(n=>r()&&n.attachTimeline?n.attachTimeline(t):"function"==typeof e?e(n):void 0);return()=>{n.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}{then(t,e){return Promise.all(this.animations).then(t).catch(e)}}function l(t,e=100,n){const i=n({...t,keyframes:[0,e]}),a=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}(i),2e4);return{type:"keyframes",ease:t=>i.next(a*t).value/e,duration:o(a)}}function c(t){return"function"==typeof t}const h={linearEasing:void 0};function f(t,e){const n=i(t);return()=>{var t;return null!==(t=h[e])&&void 0!==t?t:n()}}const m=f(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),d=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,p={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:d([0,.65,.55,1]),circOut:d([.55,0,1,.45]),backIn:d([.31,.01,.66,-.59]),backOut:d([.33,1.53,.69,.99])};function y(t,e){return t?"function"==typeof t&&m()?((t,e,n=10)=>{let i="";const s=Math.max(Math.round(e/n),2);for(let e=0;e<s;e++)i+=t(a(0,s-1,e))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?d(t):Array.isArray(t)?t.map(t=>y(t,e)||p.easeOut):p[t]:void 0}function g(t,e,n){var i;if(t instanceof EventTarget)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const s=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return s?Array.from(s):[]}return Array.from(t)}function v(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const A=(t,e,n)=>t+(e-t)*n;function b(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const s=a(0,e,i);t.push(A(n,1,s))}}function T(t){const e=[0];return b(e,t.length-1),e}function x(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?g(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function P(t,e,n){return t*(e+1)}function w(t,e,n,i){var a;return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(a=i.get(e))&&void 0!==a?a:t}function k(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function M(t,e,n,i,a,s){!function(t,e,n){for(let i=0;i<t.length;i++){const a=t[i];a.at>e&&a.at<n&&(k(t,a),i--)}}(t,a,s);for(let o=0;o<e.length;o++)t.push({value:e[o],at:A(a,s,i[o]),easing:v(n,o)})}function O(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function R(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function W(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function E(t,e){return e[t]||(e[t]=[]),e[t]}function F(t){return Array.isArray(t)?t:[t]}function B(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const S=t=>"number"==typeof t,$=t=>t.every(S);const I=(t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}))("px"),L={borderWidth:I,borderTopWidth:I,borderRightWidth:I,borderBottomWidth:I,borderLeftWidth:I,borderRadius:I,radius:I,borderTopLeftRadius:I,borderTopRightRadius:I,borderBottomRightRadius:I,borderBottomLeftRadius:I,width:I,maxWidth:I,height:I,maxHeight:I,top:I,right:I,bottom:I,left:I,padding:I,paddingTop:I,paddingRight:I,paddingBottom:I,paddingLeft:I,margin:I,marginTop:I,marginRight:I,marginBottom:I,marginLeft:I,backgroundPositionX:I,backgroundPositionY:I},V=t=>null!==t;function j(t,e,n){t.style.setProperty(e,n)}function q(t,e,n){t.style[e]=n}const C=i(()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0}),N=i(()=>Object.hasOwnProperty.call(Element.prototype,"animate")),z=new WeakMap;function D(t){const e=z.get(t)||new Map;return z.set(t,e),z.get(t)}class H extends class{constructor(t){this.animation=t}get duration(){var t,e,n;const i=(null===(e=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===e?void 0:e.getComputedTiming().duration)||(null===(n=this.options)||void 0===n?void 0:n.duration)||300;return o(Number(i))}get time(){var t;return this.animation?o((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=s(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var t;this.animation&&(null===(t=this.animation.effect)||void 0===t||t.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&function(t,e){t.timeline=e,t.onfinish=null}(this.animation,t),e}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}{constructor(t,e,i,a){const o=e.startsWith("--");n("string"!=typeof a.type);const r=D(t).get(e);r&&r.stop();if(Array.isArray(i)||(i=[i]),function(t,e,n){for(let i=0;i<e.length;i++)null===e[i]&&(e[i]=0===i?n():e[i-1]),"number"==typeof e[i]&&L[t]&&(e[i]=L[t].transform(e[i]));!C()&&e.length<2&&e.unshift(n())}(e,i,()=>e.startsWith("--")?t.style.getPropertyValue(e):window.getComputedStyle(t)[e]),c(a.type)){const t=l(a,100,a.type);a.ease=m()?t.ease:"easeOut",a.duration=s(t.duration),a.type="keyframes"}else a.ease=a.ease||"easeOut";const u=()=>{this.setValue(t,e,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(V),s=e&&"loop"!==n&&e%2==1?0:a.length-1;return s&&void 0!==i?i:a[s]}(i,a)),this.cancel(),this.resolveFinishedPromise()},h=()=>{this.setValue=o?j:q,this.options=a,this.updateFinishedPromise(),this.removeAnimation=()=>{const n=z.get(t);n&&n.delete(e)}};N()?(super(function(t,e,n,{delay:i=0,duration:a=300,repeat:s=0,repeatType:o="loop",ease:r="easeInOut",times:u}={}){const l={[e]:n};u&&(l.offset=u);const c=y(r,a);return Array.isArray(c)&&(l.easing=c),t.animate(l,{delay:i,duration:a,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:s+1,direction:"reverse"===o?"alternate":"normal"})}(t,e,i,a)),h(),!1===a.autoplay&&this.animation.pause(),this.animation.onfinish=u,D(t).set(e,this)):(super(),h(),u())}then(t,e){return this.currentFinishedPromise.then(t,e)}updateFinishedPromise(){this.currentFinishedPromise=new Promise(t=>{this.resolveFinishedPromise=t})}play(){"finished"===this.state&&this.updateFinishedPromise(),super.play()}cancel(){this.removeAnimation(),super.cancel()}}function X(t,e,n,i){const a=g(t,i),o=a.length,r=[];for(let t=0;t<o;t++){const i=a[t],c={...n};"function"==typeof c.delay&&(c.delay=c.delay(t,o));for(const t in e){const n=e[t],a={...(u=c,l=t,u?u[l]||u.default||u:void 0)};a.duration=a.duration?s(a.duration):a.duration,a.delay=s(a.delay||0),r.push(new H(i,t,n,a))}}var u,l;return r}const Y=(t=>function(e,n,i){return new u(X(e,n,i,t))})();t.animate=Y,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,o){const r=e.duration||.3,u=new Map,h=new Map,f={},m=new Map;let d=0,p=0,y=0;for(let n=0;n<t.length;n++){const a=t[n];if("string"==typeof a){m.set(a,p);continue}if(!Array.isArray(a)){m.set(a.name,w(p,a.at,d,m));continue}let[u,A,k={}]=a;void 0!==k.at&&(p=w(p,k.at,d,m));let R=0;const S=(t,n,i,a=0,u=0)=>{const h=F(t),{delay:f=0,times:m=T(h),type:d="keyframes",repeat:g,repeatType:A,repeatDelay:x=0,...w}=n;let{ease:k=e.ease||"easeOut",duration:W}=n;const E="function"==typeof f?f(a,u):f,B=h.length,S=c(d)?d:null==o?void 0:o[d];if(B<=2&&S){let t=100;if(2===B&&$(h)){const e=h[1]-h[0];t=Math.abs(e)}const e={...w};void 0!==W&&(e.duration=s(W));const n=l(e,t,S);k=n.ease,W=n.duration}null!=W||(W=r);const I=p+E;1===m.length&&0===m[0]&&(m[1]=1);const L=m.length-h.length;if(L>0&&b(m,L),1===h.length&&h.unshift(null),g){W=P(W,g);const t=[...h],e=[...m];k=Array.isArray(k)?[...k]:[k];const n=[...k];for(let i=0;i<g;i++){h.push(...t);for(let a=0;a<t.length;a++)m.push(e[a]+(i+1)),k.push(0===a?"linear":v(n,a-1))}O(m,g)}const V=I+W;M(i,h,k,m,I,V),R=Math.max(E+W,R),y=Math.max(V,y)};if(g=u,Boolean(g&&g.getVelocity)){S(A,k,E("default",W(u,h)))}else{const t=x(u,A,i,f),e=t.length;for(let n=0;n<e;n++){A=A,k=k;const i=W(t[n],h);for(const t in A)S(A[t],B(k,t),E(t,i),n,e)}}d=p,p+=R}var g;return h.forEach((t,i)=>{for(const s in t){const o=t[s];o.sort(R);const r=[],l=[],c=[];for(let t=0;t<o.length;t++){const{at:e,value:n,easing:i}=o[t];r.push(n),l.push(a(0,y,e)),c.push(i||"easeOut")}0!==l[0]&&(l.unshift(0),r.unshift(r[0]),c.unshift("easeInOut")),1!==l[l.length-1]&&(l.push(1),r.push(null)),u.has(i)||u.set(i,{keyframes:{},transition:{}});const h=u.get(i);h.keyframes[s]=r,h.transition[s]={...e,duration:y,ease:c,times:l,...n}}}),u}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...X(i,t,e))}),new u(n)}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Motion={})}(this,(function(t){"use strict";const e=t=>t;let n=e;function i(t){let e;return()=>(void 0===e&&(e=t()),e)}const a=(t,e,n)=>{const i=e-t;return 0===i?1:(n-t)/i},o=t=>1e3*t,s=t=>t/1e3,r=i(()=>void 0!==window.ScrollTimeline);class l extends class{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>"finished"in t?t.finished:t))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let n=0;n<this.animations.length;n++)this.animations[n][t]=e}attachTimeline(t,e){const n=this.animations.map(n=>r()&&n.attachTimeline?n.attachTimeline(t):"function"==typeof e?e(n):void 0);return()=>{n.forEach((t,e)=>{t&&t(),this.animations[e].stop()})}}get time(){return this.getAll("time")}set time(t){this.setAll("time",t)}get speed(){return this.getAll("speed")}set speed(t){this.setAll("speed",t)}get startTime(){return this.getAll("startTime")}get duration(){let t=0;for(let e=0;e<this.animations.length;e++)t=Math.max(t,this.animations[e].duration);return t}runAll(t){this.animations.forEach(e=>e[t]())}flatten(){this.runAll("flatten")}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}{then(t,e){return Promise.all(this.animations).then(t).catch(e)}}function u(t,e=100,n){const i=n({...t,keyframes:[0,e]}),a=Math.min(function(t){let e=0,n=t.next(e);for(;!n.done&&e<2e4;)e+=50,n=t.next(e);return e>=2e4?1/0:e}(i),2e4);return{type:"keyframes",ease:t=>i.next(a*t).value/e,duration:s(a)}}function c(t){return"function"==typeof t}const h={linearEasing:void 0};function f(t,e){const n=i(t);return()=>{var t;return null!==(t=h[e])&&void 0!==t?t:n()}}const m=f(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),d=([t,e,n,i])=>`cubic-bezier(${t}, ${e}, ${n}, ${i})`,p={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:d([0,.65,.55,1]),circOut:d([.55,0,1,.45]),backIn:d([.31,.01,.66,-.59]),backOut:d([.33,1.53,.69,.99])};function y(t,e){return t?"function"==typeof t&&m()?((t,e,n=10)=>{let i="";const o=Math.max(Math.round(e/n),2);for(let e=0;e<o;e++)i+=t(a(0,o-1,e))+", ";return`linear(${i.substring(0,i.length-2)})`})(t,e):(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?d(t):Array.isArray(t)?t.map(t=>y(t,e)||p.easeOut):p[t]:void 0}function g(t,e,n){var i;if(t instanceof EventTarget)return[t];if("string"==typeof t){let a=document;e&&(a=e.current);const o=null!==(i=null==n?void 0:n[t])&&void 0!==i?i:a.querySelectorAll(t);return o?Array.from(o):[]}return Array.from(t)}function v(t,e){return n=t,Array.isArray(n)&&"number"!=typeof n[0]?t[((t,e,n)=>{const i=e-t;return((n-t)%i+i)%i+t})(0,t.length,e)]:t;var n}const A=(t,e,n)=>t+(e-t)*n;function b(t,e){const n=t[t.length-1];for(let i=1;i<=e;i++){const o=a(0,e,i);t.push(A(n,1,o))}}function T(t){const e=[0];return b(e,t.length-1),e}function w(t,e,n,i){return"string"==typeof t&&function(t){return"object"==typeof t&&!Array.isArray(t)}(e)?g(t,n,i):t instanceof NodeList?Array.from(t):Array.isArray(t)?t:[t]}function x(t,e,n){return t*(e+1)}function P(t,e,n,i){var a;return"number"==typeof e?e:e.startsWith("-")||e.startsWith("+")?Math.max(0,t+parseFloat(e)):"<"===e?n:null!==(a=i.get(e))&&void 0!==a?a:t}function k(t,e){const n=t.indexOf(e);n>-1&&t.splice(n,1)}function M(t,e,n,i,a,o){!function(t,e,n){for(let i=0;i<t.length;i++){const a=t[i];a.at>e&&a.at<n&&(k(t,a),i--)}}(t,a,o);for(let s=0;s<e.length;s++)t.push({value:e[s],at:A(a,o,i[s]),easing:v(n,s)})}function O(t,e){for(let n=0;n<t.length;n++)t[n]=t[n]/(e+1)}function R(t,e){return t.at===e.at?null===t.value?1:null===e.value?-1:0:t.at-e.at}function W(t,e){return!e.has(t)&&e.set(t,{}),e.get(t)}function F(t,e){return e[t]||(e[t]=[]),e[t]}function E(t){return Array.isArray(t)?t:[t]}function B(t,e){return t&&t[e]?{...t,...t[e]}:{...t}}const S=t=>"number"==typeof t,$=t=>t.every(S);const I=(t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}))("px"),L={borderWidth:I,borderTopWidth:I,borderRightWidth:I,borderBottomWidth:I,borderLeftWidth:I,borderRadius:I,radius:I,borderTopLeftRadius:I,borderTopRightRadius:I,borderBottomRightRadius:I,borderBottomLeftRadius:I,width:I,maxWidth:I,height:I,maxHeight:I,top:I,right:I,bottom:I,left:I,padding:I,paddingTop:I,paddingRight:I,paddingBottom:I,paddingLeft:I,margin:I,marginTop:I,marginRight:I,marginBottom:I,marginLeft:I,backgroundPositionX:I,backgroundPositionY:I},V=t=>null!==t;function j(t,e,n){t.style.setProperty(e,n)}function q(t,e,n){t.style[e]=n}const C=i(()=>{try{document.createElement("div").animate({opacity:[1]})}catch(t){return!1}return!0}),N=i(()=>Object.hasOwnProperty.call(Element.prototype,"animate")),z=new WeakMap;function D(t){const e=z.get(t)||new Map;return z.set(t,e),z.get(t)}class H extends class{constructor(t){this.animation=t}get duration(){var t,e,n;const i=(null===(e=null===(t=this.animation)||void 0===t?void 0:t.effect)||void 0===e?void 0:e.getComputedTiming().duration)||(null===(n=this.options)||void 0===n?void 0:n.duration)||300;return s(Number(i))}get time(){var t;return this.animation?s((null===(t=this.animation)||void 0===t?void 0:t.currentTime)||0):0}set time(t){this.animation&&(this.animation.currentTime=o(t))}get speed(){return this.animation?this.animation.playbackRate:1}set speed(t){this.animation&&(this.animation.playbackRate=t)}get state(){return this.animation?this.animation.playState:"finished"}get startTime(){return this.animation?this.animation.startTime:null}get finished(){return this.animation?this.animation.finished:Promise.resolve()}play(){this.animation&&this.animation.play()}pause(){this.animation&&this.animation.pause()}stop(){this.animation&&"idle"!==this.state&&"finished"!==this.state&&(this.animation.commitStyles&&this.animation.commitStyles(),this.cancel())}flatten(){var t,e;this.animation&&(null===(t=this.options)||void 0===t?void 0:t.allowFlatten)&&(null===(e=this.animation.effect)||void 0===e||e.updateTiming({easing:"linear"}))}attachTimeline(t){return this.animation&&function(t,e){t.timeline=e,t.onfinish=null}(this.animation,t),e}complete(){this.animation&&this.animation.finish()}cancel(){try{this.animation&&this.animation.cancel()}catch(t){}}}{constructor(t,e,i,a){const s=e.startsWith("--");n("string"!=typeof a.type);const r=D(t).get(e);r&&r.stop();if(Array.isArray(i)||(i=[i]),function(t,e,n){for(let i=0;i<e.length;i++)null===e[i]&&(e[i]=0===i?n():e[i-1]),"number"==typeof e[i]&&L[t]&&(e[i]=L[t].transform(e[i]));!C()&&e.length<2&&e.unshift(n())}(e,i,()=>e.startsWith("--")?t.style.getPropertyValue(e):window.getComputedStyle(t)[e]),c(a.type)){const t=u(a,100,a.type);a.ease=m()?t.ease:"easeOut",a.duration=o(t.duration),a.type="keyframes"}else a.ease=a.ease||"easeOut";const l=()=>{this.setValue(t,e,function(t,{repeat:e,repeatType:n="loop"},i){const a=t.filter(V),o=e&&"loop"!==n&&e%2==1?0:a.length-1;return o&&void 0!==i?i:a[o]}(i,a)),this.cancel(),this.resolveFinishedPromise()},h=()=>{this.setValue=s?j:q,this.options=a,this.updateFinishedPromise(),this.removeAnimation=()=>{const n=z.get(t);n&&n.delete(e)}};N()?(super(function(t,e,n,{delay:i=0,duration:a=300,repeat:o=0,repeatType:s="loop",ease:r="easeInOut",times:l}={}){const u={[e]:n};l&&(u.offset=l);const c=y(r,a);return Array.isArray(c)&&(u.easing=c),t.animate(u,{delay:i,duration:a,easing:Array.isArray(c)?"linear":c,fill:"both",iterations:o+1,direction:"reverse"===s?"alternate":"normal"})}(t,e,i,a)),h(),!1===a.autoplay&&this.animation.pause(),this.animation.onfinish=l,D(t).set(e,this)):(super(),h(),l())}then(t,e){return this.currentFinishedPromise.then(t,e)}updateFinishedPromise(){this.currentFinishedPromise=new Promise(t=>{this.resolveFinishedPromise=t})}play(){"finished"===this.state&&this.updateFinishedPromise(),super.play()}cancel(){this.removeAnimation(),super.cancel()}}function X(t,e,n,i){const a=g(t,i),s=a.length,r=[];for(let t=0;t<s;t++){const i=a[t],c={...n};"function"==typeof c.delay&&(c.delay=c.delay(t,s));for(const t in e){const n=e[t],a={...(l=c,u=t,l?l[u]||l.default||l:void 0)};a.duration=a.duration?o(a.duration):a.duration,a.delay=o(a.delay||0),a.allowFlatten=!c.type&&!c.ease,r.push(new H(i,t,n,a))}}var l,u;return r}const Y=(t=>function(e,n,i){return new l(X(e,n,i,t))})();t.animate=Y,t.animateSequence=function(t,e){const n=[];return function(t,{defaultTransition:e={},...n}={},i,s){const r=e.duration||.3,l=new Map,h=new Map,f={},m=new Map;let d=0,p=0,y=0;for(let n=0;n<t.length;n++){const a=t[n];if("string"==typeof a){m.set(a,p);continue}if(!Array.isArray(a)){m.set(a.name,P(p,a.at,d,m));continue}let[l,A,k={}]=a;void 0!==k.at&&(p=P(p,k.at,d,m));let R=0;const S=(t,n,i,a=0,l=0)=>{const h=E(t),{delay:f=0,times:m=T(h),type:d="keyframes",repeat:g,repeatType:A,repeatDelay:w=0,...P}=n;let{ease:k=e.ease||"easeOut",duration:W}=n;const F="function"==typeof f?f(a,l):f,B=h.length,S=c(d)?d:null==s?void 0:s[d];if(B<=2&&S){let t=100;if(2===B&&$(h)){const e=h[1]-h[0];t=Math.abs(e)}const e={...P};void 0!==W&&(e.duration=o(W));const n=u(e,t,S);k=n.ease,W=n.duration}null!=W||(W=r);const I=p+F;1===m.length&&0===m[0]&&(m[1]=1);const L=m.length-h.length;if(L>0&&b(m,L),1===h.length&&h.unshift(null),g){W=x(W,g);const t=[...h],e=[...m];k=Array.isArray(k)?[...k]:[k];const n=[...k];for(let i=0;i<g;i++){h.push(...t);for(let a=0;a<t.length;a++)m.push(e[a]+(i+1)),k.push(0===a?"linear":v(n,a-1))}O(m,g)}const V=I+W;M(i,h,k,m,I,V),R=Math.max(F+W,R),y=Math.max(V,y)};if(g=l,Boolean(g&&g.getVelocity)){S(A,k,F("default",W(l,h)))}else{const t=w(l,A,i,f),e=t.length;for(let n=0;n<e;n++){A=A,k=k;const i=W(t[n],h);for(const t in A)S(A[t],B(k,t),F(t,i),n,e)}}d=p,p+=R}var g;return h.forEach((t,i)=>{for(const o in t){const s=t[o];s.sort(R);const r=[],u=[],c=[];for(let t=0;t<s.length;t++){const{at:e,value:n,easing:i}=s[t];r.push(n),u.push(a(0,y,e)),c.push(i||"easeOut")}0!==u[0]&&(u.unshift(0),r.unshift(r[0]),c.unshift("easeInOut")),1!==u[u.length-1]&&(u.push(1),r.push(null)),l.has(i)||l.set(i,{keyframes:{},transition:{}});const h=l.get(i);h.keyframes[o]=r,h.transition[o]={...e,duration:y,ease:c,times:u,...n}}}),l}(t,e).forEach(({keyframes:t,transition:e},i)=>{n.push(...X(i,t,e))}),new l(n)}}));
|