framer-motion
Version:
A simple and powerful JavaScript animation library
3 lines (2 loc) • 7.75 kB
JavaScript
let t=()=>{};function e(t){let e;return()=>(void 0===e&&(e=t()),e)}"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&(t=(t,e,i)=>{if(!t)throw new Error(function(t,e){return e?`${t}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${e}`:t}(e,i))});const i=t=>t,n=t=>1e3*t,s=t=>t/1e3,a=t=>null!==t;class o{constructor(){this.updateFinished()}get finished(){return this._finished}updateFinished(){this._finished=new Promise(t=>{this.resolve=t})}notifyFinished(){this.resolve()}then(t,e){return this.finished.then(t,e)}}function r(t){for(let e=1;e<t.length;e++)t[e]??(t[e]=t[e-1])}const l=t=>t.startsWith("--");const u=e(()=>void 0!==window.ScrollTimeline),h={};function d(t,i){const n=e(t);return()=>h[i]??n()}const m=d(()=>{try{document.createElement("div").animate({opacity:0},{easing:"linear(0, 1)"})}catch(t){return!1}return!0},"linearEasing"),c=([t,e,i,n])=>`cubic-bezier(${t}, ${e}, ${i}, ${n})`,p={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:c([0,.65,.55,1]),circOut:c([.55,0,1,.45]),backIn:c([.31,.01,.66,-.59]),backOut:c([.33,1.53,.69,.99])};function f(t,e){return t?"function"==typeof t?m()?((t,e,i=10)=>{let n="";const s=Math.max(Math.round(e/i),2);for(let e=0;e<s;e++)n+=Math.round(1e4*t(e/(s-1)))/1e4+", ";return`linear(${n.substring(0,n.length-2)})`})(t,e):"ease-out":(t=>Array.isArray(t)&&"number"==typeof t[0])(t)?c(t):Array.isArray(t)?t.map(t=>f(t,e)||p.easeOut):p[t]:void 0}class g extends o{constructor(e){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!e)return;const{element:i,name:n,keyframes:s,pseudoElement:o,allowFlatten:r=!1,finalKeyframe:u,onComplete:h}=e;this.isPseudoElement=Boolean(o),this.allowFlatten=r,this.options=e,t("string"!=typeof e.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const d=function({type:t,...e}){return function(t){return"function"==typeof t&&"applyToOptions"in t}(t)&&m()?t.applyToOptions(e):(e.duration??(e.duration=300),e.ease??(e.ease="easeOut"),e)}(e);this.animation=function(t,e,i,{delay:n=0,duration:s=300,repeat:a=0,repeatType:o="loop",ease:r="easeOut",times:l}={},u){const h={[e]:i};l&&(h.offset=l);const d=f(r,s);Array.isArray(d)&&(h.easing=d);const m={delay:n,duration:s,easing:Array.isArray(d)?"linear":d,fill:"both",iterations:a+1,direction:"reverse"===o?"alternate":"normal"};return u&&(m.pseudoElement=u),t.animate(h,m)}(i,n,s,d,o),!1===d.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!o){const t=function(t,{repeat:e,repeatType:i="loop"},n,s=1){const o=t.filter(a),r=s<0||e&&"loop"!==i&&e%2==1?0:o.length-1;return r&&void 0!==n?n:o[r]}(s,this.options,u,this.speed);this.updateMotionValue?this.updateMotionValue(t):function(t,e,i){l(e)?t.style.setProperty(e,i):t.style[e]=i}(i,n,t),this.animation.cancel()}h?.(),this.notifyFinished()}}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(t){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:t}=this;"idle"!==t&&"finished"!==t&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){this.isPseudoElement||this.animation.commitStyles?.()}get duration(){const t=this.animation.effect?.getComputedTiming?.().duration||0;return s(Number(t))}get iterationDuration(){const{delay:t=0}=this.options||{};return this.duration+s(t)}get time(){return s(Number(this.animation.currentTime)||0)}set time(t){this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=n(t)}get speed(){return this.animation.playbackRate}set speed(t){t<0&&(this.finishedTime=null),this.animation.playbackRate=t}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(t){this.manualStartTime=this.animation.startTime=t}attachTimeline({timeline:t,observe:e}){return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,t&&u()?(this.animation.timeline=t,i):e(this)}}class y{constructor(t){this.stop=()=>this.runAll("stop"),this.animations=t.filter(Boolean)}get finished(){return Promise.all(this.animations.map(t=>t.finished))}getAll(t){return this.animations[0][t]}setAll(t,e){for(let i=0;i<this.animations.length;i++)this.animations[i][t]=e}attachTimeline(t){const e=this.animations.map(e=>e.attachTimeline(t));return()=>{e.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 state(){return this.getAll("state")}get startTime(){return this.getAll("startTime")}get duration(){return T(this.animations,"duration")}get iterationDuration(){return T(this.animations,"iterationDuration")}runAll(t){this.animations.forEach(e=>e[t]())}play(){this.runAll("play")}pause(){this.runAll("pause")}cancel(){this.runAll("cancel")}complete(){this.runAll("complete")}}function T(t,e){let i=0;for(let n=0;n<t.length;n++){const s=t[n][e];null!==s&&s>i&&(i=s)}return i}class b extends y{then(t,e){return this.finished.finally(t).then(()=>{})}}const A=new WeakMap,S=(t,e="")=>`${t}:${e}`;function E(t){const e=A.get(t)||new Map;return A.set(t,e),e}function k(t,e){return t?.[e]??t?.default??t}const v=new Set(["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderRadius","radius","borderTopLeftRadius","borderTopRightRadius","borderBottomRightRadius","borderBottomLeftRadius","width","maxWidth","height","maxHeight","top","right","bottom","left","inset","insetBlock","insetBlockStart","insetBlockEnd","insetInline","insetInlineStart","insetInlineEnd","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingBlock","paddingBlockStart","paddingBlockEnd","paddingInline","paddingInlineStart","paddingInlineEnd","margin","marginTop","marginRight","marginBottom","marginLeft","marginBlock","marginBlockStart","marginBlockEnd","marginInline","marginInlineStart","marginInlineEnd","backgroundPositionX","backgroundPositionY"]);function w(t,e){for(let i=0;i<t.length;i++)"number"==typeof t[i]&&v.has(e)&&(t[i]=t[i]+"px")}function B(t,e){const i=window.getComputedStyle(t);return l(e)?i.getPropertyValue(e):i[e]}function I(e,i,s,a){const o=function(t,e){if(t instanceof EventTarget)return[t];if("string"==typeof t){let i=document;e&&(i=e.current);const n=i.querySelectorAll(t);return n?Array.from(n):[]}return Array.from(t)}(e,a),l=o.length;t(Boolean(l),"No valid elements provided.","no-valid-elements");const u=[];for(let t=0;t<l;t++){const e=o[t],a={...s};"function"==typeof a.delay&&(a.delay=a.delay(t,l));for(const t in i){let s=i[t];Array.isArray(s)||(s=[s]);const o={...k(a,t)};o.duration&&(o.duration=n(o.duration)),o.delay&&(o.delay=n(o.delay));const r=E(e),l=S(t,o.pseudoElement||""),h=r.get(l);h&&h.stop(),u.push({map:r,key:l,unresolvedKeyframes:s,options:{...o,element:e,name:t,allowFlatten:!a.type&&!a.ease}})}}for(let t=0;t<u.length;t++){const{unresolvedKeyframes:e,options:i}=u[t],{element:n,name:s,pseudoElement:a}=i;a||null!==e[0]||(e[0]=B(n,s)),r(e),w(e,s),!a&&e.length<2&&e.unshift(B(n,s)),i.keyframes=e}const h=[];for(let t=0;t<u.length;t++){const{map:e,key:i,options:n}=u[t],s=new g(n);e.set(i,s),s.finished.finally(()=>e.delete(i)),h.push(s)}return h}const R=t=>function(e,i,n){return new b(I(e,i,n,t))},F=R();export{F as animateMini,R as createScopedWaapiAnimate};
//# sourceMappingURL=size-rollup-waapi-animate.js.map