9 lines
5.6 KiB
JavaScript
9 lines
5.6 KiB
JavaScript
import{$t as e,Gn as t,In as n,Ln as r,On as i,Qt as a,Un as o,Xn as s,cr as c,hn as l,pn as u,qn as d,ur as f,xn as p,zn as m}from"./D6Ym2dQP.js";import{_ as h,a as g,c as _,d as v,f as y,g as b,h as x,l as S,m as C,o as w,p as T,u as E,v as D}from"./Dd1GE-gU.js";var O=new Set,k=({timestamp:e})=>{O.forEach(t=>t.tick(e))},A=class extends v{constructor(e){super(),this.state=`idle`,this.startTime=0,this.currentTime=0,this.started=!1,this.hasNextTarget=!1,this.nextTarget=0,this.stop=()=>{this.state!==`idle`&&(this.teardown(),this.options.onStop?.())},this.options=e,this.factory=e.type,this.generator=this.factory(e);let{driver:t}=e;t&&(this.driver=t(e=>this.tick(e))),this.startTime=this.now(),this.state=`running`,this.driver?this.driver.start():(O.size||h.update(k,!0),O.add(this))}setTarget(e,t){this.nextTarget=e,this.nextVelocity=t,this.hasNextTarget=!0}retarget(e,t){let{options:n,generator:r}=this;n.keyframes=e,n.velocity=t,this.startTime=this.now(),this.currentTime=0,r.retarget?r.retarget(e,t):this.generator=this.factory(n)}tick(e){let{options:t,hasNextTarget:n}=this,{delay:r=0,onUpdate:i,onPlay:a}=t;this.started||(this.startTime=y(this.startTime,e));let o=Math.round(e-this.startTime)-r,s=this.currentTime=Math.max(0,o),c=this.generator.next(s),l=o<0?t.keyframes[0]:c.value;if(n){this.hasNextTarget=!1;let{keyframes:e}=t;e[0]=l,e[1]=this.nextTarget,this.retarget(e,this.nextVelocity??this.getGeneratorVelocity())}(n||!this.started)&&(this.started=!0,a?.()),this.state===`running`&&(i?.(l),c.done&&o>=0&&!n&&!this.hasNextTarget&&this.state===`running`&&(this.notifyFinished(),this.teardown(),this.state=`finished`,t.onComplete?.()))}getGeneratorVelocity(){return C(this.generator,this.currentTime,this.options.velocity)}now(){return this.driver?this.driver.now():D.now()}teardown(){this.state=`idle`,this.driver?this.driver.stop():(O.delete(this),O.size||b(k))}};function j(e,t,n){let r=e.get(),i=null,a,o=typeof r==`string`?r.replace(/[\d.-]/g,``):void 0,s=e=>a(o?e+o:e),c=()=>e.events.animationStart?.notify(),l=()=>{i&&=(i.stop(),null),e.animation=void 0};if(e.attach((t,r)=>{a=r;let o=_(t);if(i?.state===`running`){i.setTarget(o,n.velocity);return}let u=_(e.get()),d=i?i.getGeneratorVelocity():e.getVelocity();if(l(),u===o)return;let f=i=new A({keyframes:[u,o],velocity:d,restDelta:.001,restSpeed:.01,...n,onUpdate:s,onPlay:c});e.animation=f,f.then(()=>{i===f&&(i=null,e.animation=void 0,e.events.animationComplete?.notify())})},l),S(t)){let r=n.skipInitialAnimation===!0,i=t=>{r?(r=!1,e.jump(M(t,o),!1)):e.set(M(t,o))},a=t.on(`change`,i),s=t.get();_(s)-_(e.get())&&i(s);let c=e.on(`destroy`,a);return()=>{a(),c(),l()}}return l}function M(e,t){return t?e+t:e}function N(e,t,n={}){let r={type:`spring`,...n};return T(r),r.type=r.type||x,j(e,t,r)}var P=0;function F(e){let t=new Map;function n(t){if(e.props.mode!==`popLayout`)return;let n=t.el,r=n.offsetParent,i=r instanceof HTMLElement&&r.offsetWidth||0,a={height:n.offsetHeight||0,width:n.offsetWidth||0,top:n.offsetTop,left:n.offsetLeft,right:0};a.right=i-a.width-a.left;let o=e.props.anchorX===`left`?`left: ${a.left}px`:`right: ${a.right}px`,s=`pop-${P++}`;n.dataset.motionPopId=s;let c=n.ownerDocument,l=c.createElement(`style`),u=e.getNonce();u&&(l.nonce=u),t.popStyle=l,c.head.appendChild(l),l.sheet&&l.sheet.insertRule(`
|
|
[data-motion-pop-id="${s}"] {
|
|
position: absolute !important;
|
|
width: ${a.width}px !important;
|
|
height: ${a.height}px !important;
|
|
top: ${a.top}px !important;
|
|
${o} !important;
|
|
}
|
|
`)}function r(e){let t=e.popStyle;t&&(e.popStyle=void 0,h.render(()=>{t.parentNode?.removeChild(t)}))}function i(e,r,i,a=[]){let s={el:e,states:r,handlers:a,done:i,aborted:!1};t.set(e,s),n(s);let c=r.map(e=>e.getFeature(`exit`)?.exit()??Promise.resolve());for(let e of a)c.push(Promise.resolve(e.onExit()));Promise.all(c).then(()=>{s.aborted||o(s)})}function a(e){let n=t.get(e);n&&(n.aborted=!0,t.delete(e),r(n),n.handlers.forEach(e=>e.onEnter?.()))}function o(n){t.delete(n.el),r(n),n.states.forEach(e=>{e.getSnapshot(!1)}),n.done(),n.el.isConnected||n.states.forEach(e=>{e.unmount()}),e.onAllComplete()}function s(){t.forEach(e=>{e.states.forEach(e=>{e.unmount()})}),t.clear()}return{track:i,abort:a,dispose:s}}function I(e){let t=w(),i=F({props:e,getNonce:()=>t.value.nonce,onAllComplete:()=>e.onExitComplete?.()}),a=new Set,o=new Set,s=!1;g({get initial(){return s?void 0:e.initial},get custom(){return e.custom},register:e=>a.add(e),unregister:e=>a.delete(e),registerHandler:e=>o.add(e),unregisterHandler:e=>o.delete(e)}),n(()=>{s=!0});function c(e){let t=[];for(let n of a){let r=n.element;r&&(r===e||e.contains(r))&&t.push(n)}return t}function l(e){let t=[];for(let n of o){let r=n.element();r&&(r===e||e.contains(r))&&t.push(n)}return t}function u(e,t){i.abort(e),c(e).forEach(e=>{e.getFeature(`exit`)?.reenter()}),t()}function d(t,n){let r=t,a=c(r),o=l(r);a.length===0&&o.length===0?(n(),e.onExitComplete?.()):i.track(r,a,n,o)}return r(()=>{i.dispose()}),{enter:u,exit:d}}var L=p({name:`AnimatePresence`,inheritAttrs:!0,__name:`AnimatePresence`,props:{mode:{default:`sync`},initial:{type:Boolean,default:!0},as:{},custom:{},onExitComplete:{},anchorX:{default:`left`}},setup(n){let r=n,{enter:c,exit:d}=I(r),p=u(()=>r.mode===`wait`?{mode:r.mode===`wait`?`out-in`:void 0}:{tag:r.as});return(r,u)=>(m(),l(t(n.mode===`wait`?a:e),i(p.value,{appear:``,css:!1,onLeave:f(d),onEnter:f(c)}),{default:s(()=>[o(r.$slots,`default`)]),_:3},16,[`onLeave`,`onEnter`]))}});function R(e,t={}){let n=E(S(e)?e.get():e);return d(()=>c(t),(r,i,a)=>{let o=N(n,e,{type:`spring`,...c(t)});a(()=>{o?.()})},{immediate:!0}),n}var z=globalThis.setInterval;export{R as n,L as r,z as t}; |