3 lines
8.0 KiB
JavaScript
3 lines
8.0 KiB
JavaScript
|
|
const t=["transformPerspective","x","y","z","translateX","translateY","translateZ","scale","scaleX","scaleY","rotate","rotateX","rotateY","rotateZ","skew","skewX","skewY"],e=(()=>new Set(t))();const s={};class n{constructor(){this.subscriptions=[]}add(t){var e,s;return e=this.subscriptions,s=t,-1===e.indexOf(s)&&e.push(s),()=>function(t,e){const s=t.indexOf(e);s>-1&&t.splice(s,1)}(this.subscriptions,t)}notify(t,e,s){const n=this.subscriptions.length;if(n)if(1===n)this.subscriptions[0](t,e,s);else for(let i=0;i<n;i++){const n=this.subscriptions[i];n&&n(t,e,s)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}}const i=["setup","read","resolveKeyframes","preUpdate","update","preRender","render","postRender"];function r(t,e){let n=!1,r=!0;const a={delta:0,timestamp:0,isProcessing:!1},o=()=>n=!0,c=i.reduce((t,e)=>(t[e]=function(t){let e=new Set,s=new Set,n=!1,i=!1;const r=new WeakSet;let a={delta:0,timestamp:0,isProcessing:!1};function o(e){r.has(e)&&(c.schedule(e),t()),e(a)}const c={schedule:(t,i=!1,a=!1)=>{const o=a&&n?e:s;return i&&r.add(t),o.add(t),t},cancel:t=>{s.delete(t),r.delete(t)},process:t=>{if(a=t,n)return void(i=!0);n=!0;const r=e;e=s,s=r,e.forEach(o),e.clear(),n=!1,i&&(i=!1,c.process(t))}};return c}(o),t),{}),{setup:d,read:h,resolveKeyframes:l,preUpdate:p,update:u,preRender:f,render:m,postRender:g}=c,v=()=>{const i=s.useManualTiming,o=i?a.timestamp:performance.now();n=!1,i||(a.delta=r?1e3/60:Math.max(Math.min(o-a.timestamp,40),1)),a.timestamp=o,a.isProcessing=!0,d.process(a),h.process(a),l.process(a),p.process(a),u.process(a),f.process(a),m.process(a),g.process(a),a.isProcessing=!1,n&&e&&(r=!1,t(v))};return{schedule:i.reduce((e,s)=>{const i=c[s];return e[s]=(e,s=!1,o=!1)=>(n||(n=!0,r=!0,a.isProcessing||t(v)),i.schedule(e,s,o)),e},{}),cancel:t=>{for(let e=0;e<i.length;e++)c[i[e]].cancel(t)},state:a,steps:c}}const{schedule:a,cancel:o,state:c}=r("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:t=>t,!0);let d;function h(){d=void 0}const l={now:()=>(void 0===d&&l.set(c.isProcessing||s.useManualTiming?c.timestamp:performance.now()),d),set:t=>{d=t,queueMicrotask(h)}};class p{constructor(t,e={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=t=>{const e=l.now();if(this.updatedAt!==e&&this.setPrevFrameValue(),this.prev=this.current,this.setCurrent(t),this.current!==this.prev&&(this.events.change?.notify(this.current),this.dependents))for(const t of this.dependents)t.dirty()},this.hasAnimated=!1,this.setCurrent(t),this.owner=e.owner}setCurrent(t){var e;this.current=t,this.updatedAt=l.now(),null===this.canTrackVelocity&&void 0!==t&&(this.canTrackVelocity=(e=this.current,!isNaN(parseFloat(e))))}setPrevFrameValue(t=this.current){this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt}onChange(t){return this.on("change",t)}on(t,e){this.events[t]||(this.events[t]=new n);const s=this.events[t].add(e);return"change"===t?()=>{s(),a.read(()=>{this.events.change.getSize()||this.stop()})}:s}clearListeners(){for(const t in this.events)this.events[t].clear()}attach(t,e){this.passiveEffect=t,this.stopPassiveEffect=e}set(t){this.passiveEffect?this.passiveEffect(t,this.updateAndNotify):this.updateAndNotify(t)}setWithVelocity(t,e,s){this.set(e),this.prev=void 0,this.prevFrameValue=t,this.prevUpdatedAt=this.updatedAt-s}jump(t,e=!0){this.updateAndNotify(t),this.prev=t,this.prevUpdatedAt=this.prevFrameValue=void 0,e&&this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}dirty(){this.events.change?.notify(this.current)}addDependent(t){this.dependents||(this.dependents=new Set),this.dependents.add(t)}removeDependent(t){this.dependents&&this.dependents.delete(t)}get(){return this.current}getPrevious(){return this.prev}getVelocity(){const t=l.now();if(!this.canTrackVelocity||void 0===this.prevFrameValue||t-this.updatedAt>30)return 0;const e=Math.min(this.updatedAt-this.prevUpdatedAt,30);return s=parseFloat(this.current)-parseFloat(this.prevFrameValue),(n=e)?s*(1e3/n):0;var s,n}start(t){return this.stop(),new Promise(e=>{this.hasAnimated=!0,this.animation=t(e),this.events.animat
|
||
|
|
//# sourceMappingURL=size-rollup-style-effect.js.map
|