const e={};class t{constructor(){this.subscriptions=[]}add(e){var t,s;return t=this.subscriptions,s=e,-1===t.indexOf(s)&&t.push(s),()=>this.remove(e)}remove(e){!function(e,t){const s=e.indexOf(t);s>-1&&e.splice(s,1)}(this.subscriptions,e)}notify(e,t,s){const i=this.subscriptions.length;if(i)if(1===i)this.subscriptions[0](e,t,s);else for(let n=0;nr=!0,h=s.reduce((e,t)=>(e[t]=function(e){let t=new Set,s=new Set,i=!1,n=!1;const r=new Set;let a={delta:0,timestamp:0,isProcessing:!1};function o(t){r.has(t)&&(s.add(t),e()),t(a)}const h={schedule:(e,n=!1,a=!1)=>{const o=a&&i?t:s;return n&&r.add(e),o.add(e),e},cancel:e=>{s.delete(e),r.delete(e)},process:e=>{if(a=e,i)return void(n=!0);i=!0;const r=t;t=s,s=r,t.forEach(o),t.clear(),i=!1,n&&(n=!1,h.process(e))}};return h}(o),e),{}),{setup:c,read:d,resolveKeyframes:p,preUpdate:u,update:l,preRender:v,render:m,postRender:f}=h,g=()=>{const s=e.useManualTiming,o=s?n.timestamp:performance.now();r=!1,s||(n.delta=a?1e3/60:Math.max(Math.min(o-n.timestamp,40),1)),n.timestamp=o,n.isProcessing=!0,c.process(n),d.process(n),p.process(n),u.process(n),l.process(n),v.process(n),m.process(n),f.process(n),n.isProcessing=!1,r&&i&&(a=!1,t(g))};return{schedule:s.reduce((e,s)=>{const i=h[s];return e[s]=(e,s=!1,o=!1)=>(r||(r=!0,a=!0,n.isProcessing||t(g)),i.schedule(e,s,o)),e},{}),cancel:e=>{for(let t=0;te,!0,n);let a;function o(){a=void 0}const h={now:()=>(void 0===a&&h.set(n.isProcessing||e.useManualTiming?n.timestamp:performance.now()),a),set:e=>{a=e,queueMicrotask(o)}},c={current:void 0};class d{constructor(e,t={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=e=>{const t=h.now();if(this.updatedAt!==t&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(e),this.current!==this.prev&&(this.notifyChange(),this.dependents))for(const e of this.dependents)e.dirty()},this.hasAnimated=!1,this.setCurrent(e),this.owner=t.owner}setCurrent(e){var t;this.current=e,this.updatedAt=h.now(),null===this.canTrackVelocity&&void 0!==e&&(this.canTrackVelocity=(t=this.current,!isNaN(parseFloat(t))))}setPrevFrameValue(e=this.current){this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt}onChange(e){return this.on("change",e)}on(e,s){var i;return"change"===e?this.onChangeSubscribe(s):((i=this.events)[e]||(i[e]=new t)).add(s)}onChangeSubscribe(e){const{events:s}=this;return s.change||this.changeSubscriber?(s.change||(s.change=new t,s.change.add(this.changeSubscriber),this.changeSubscriber=void 0),s.change.add(e)):this.changeSubscriber=e,()=>{this.changeSubscriber===e?this.changeSubscriber=void 0:s.change?.remove(e),this.stopIfUnobserved()}}stopIfUnobserved(){r.read(()=>{this.changeSubscriber||this.events.change?.getSize()||this.stop()})}clearListeners(){this.changeSubscriber=void 0;for(const e in this.events)this.events[e].clear()}attach(e,t){this.passiveEffect=e,this.stopPassiveEffect=t}set(e){this.passiveEffect?this.passiveEffect(e,this.updateAndNotify):this.updateAndNotify(e)}setWithVelocity(e,t,s){this.set(t),this.prev=void 0,this.prevFrameValue=e,this.prevUpdatedAt=this.updatedAt-s}jump(e,t=!0){this.updateAndNotify(e),this.prev=e,this.prevUpdatedAt=this.prevFrameValue=void 0,t&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){this.notifyChange()}notifyChange(){const{current:e,changeSubscriber:t}=this;t?t(e):this.events.change?.notify(e)}addDependent(e){this.dependents||(this.dependents=new Set),this.dependents.add(e)}removeDependent(e){this.dependents&&this.dependents.delete(e)}get(){c.current&&c.current.push(this);const e=this.animation?.liveValue?.();return void 0===e?this.current:e}getCurrent(){return this.current}getPrevious(){return this.prev}getVelocity(){const e=h.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||e-this.updatedAt>30)return 0;const t=Math.min(this.updatedAt-this.prevUpdatedAt,30);return s=parseFloat(this.current)-parseFloat(this.prevFrameValue),(i=t)?s*(1e3/i):0;var s,i}start(e){return this.stop(),new Promise(t=>{this.hasAnimated=!0;let s,i=!1;s=e(()=>{i=!0,this.events.animationComplete?.notify(),this.animation===s&&this.clearAnimation(),t()}),i||(this.animation=s),this.events.animationStart?.notify()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){this.animation=void 0}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function p(e,t){return new d(e,t)}export{d as MotionValue,c as collectMotionValues,p as motionValue}; //# sourceMappingURL=size-rollup-motion-value.js.map