3 lines
8.2 KiB
JavaScript
3 lines
8.2 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"],r={value:null,addProjectionMetrics:null};function a(t,e){let n=!1,a=!0;const o={delta:0,timestamp:0,isProcessing:!1},c=()=>n=!0,d=i.reduce((t,e)=>(t[e]=function(t,e){let s=new Set,n=new Set,i=!1,a=!1;const o=new WeakSet;let c={delta:0,timestamp:0,isProcessing:!1},d=0;function l(e){o.has(e)&&(h.schedule(e),t()),d++,e(c)}const h={schedule:(t,e=!1,r=!1)=>{const a=r&&i?s:n;return e&&o.add(t),a.has(t)||a.add(t),t},cancel:t=>{n.delete(t),o.delete(t)},process:t=>{c=t,i?a=!0:(i=!0,[s,n]=[n,s],s.forEach(l),e&&r.value&&r.value.frameloop[e].push(d),d=0,s.clear(),i=!1,a&&(a=!1,h.process(t)))}};return h}(c,e),t),{}),{setup:l,read:h,resolveKeyframes:p,preUpdate:u,update:f,preRender:m,render:g,postRender:v}=d,y=()=>{const i=s.useManualTiming?o.timestamp:performance.now();n=!1,s.useManualTiming||(o.delta=a?1e3/60:Math.max(Math.min(i-o.timestamp,40),1)),o.timestamp=i,o.isProcessing=!0,l.process(o),h.process(o),p.process(o),u.process(o),f.process(o),m.process(o),g.process(o),v.process(o),o.isProcessing=!1,n&&e&&(a=!1,t(y))};return{schedule:i.reduce((e,s)=>{const i=d[s];return e[s]=(e,s=!1,r=!1)=>(n||(n=!0,a=!0,o.isProcessing||t(y)),i.schedule(e,s,r)),e},{}),cancel:t=>{for(let e=0;e<i.length;e++)d[i[e]].cancel(t)},state:o,steps:d}}const{schedule:o,cancel:c,state:d,steps:l}=a("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:t=>t,!0);let h;function p(){h=void 0}const u={now:()=>(void 0===h&&u.set(d.isProcessing||s.useManualTiming?d.timestamp:performance.now()),h),set:t=>{h=t,queueMicrotask(p)}};class f{constructor(t,e={}){this.canTrackVelocity=null,this.events={},this.updateAndNotify=t=>{const e=u.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=u.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(),o.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=u.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.animationStart&&this.events.animationStart.notify()}).then(()=>{this.events.animationComplete&&this.events.animationComplete.notify(),this.clearAnimation()})}stop(){this.animation&&(this.animation.stop(),this.events.animationCancel&&this.events.animationCancel.notify()),this.clearAnimation()}isAnimating(){return!!this.animation}clearAnimation(){delete this.animation}destroy(){this.dependents?.clear(),this.events.destroy?.notify(),this.clearListeners(),this.stop(),this.stopPassiveEffect&&this.stopPassiveEffect()}}function m(t){return(e,s)=>{const n=function(t){if(null==t)return[];if(t instanceof EventTarget)return[t];if("string"==typeof t){const e=document.querySelectorAll(t);return e?Array.from(e):[]}return Array.from(t).filter(t=>null!=t)}(e),i=[];for(const e of n){const n=t(e,s);i.push(n)}return()=>{for(const t of i)t()}}}const g={test:t=>"number"==typeof t,parse:parseFloat,transform:t=>t},v={...g,transform:t=>((t,e,s)=>s>e?e:s<t?t:s)(0,1,t)},y={...g,default:1},w={...g,transform:Math.round},b=t=>({test:e=>"string"==typeof e&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}),k=b("deg"),A=b("%"),P=b("px"),S=(()=>({...A,parse:t=>A.parse(t)/100,transform:t=>A.transform(100*t)}))(),R={borderWidth:P,borderTopWidth:P,borderRightWidth:P,borderBottomWidth:P,borderLeftWidth:P,borderRadius:P,borderTopLeftRadius:P,borderTopRightRadius:P,borderBottomRightRadius:P,borderBottomLeftRadius:P,width:P,maxWidth:P,height:P,maxHeight:P,top:P,right:P,bottom:P,left:P,inset:P,insetBlock:P,insetBlockStart:P,insetBlockEnd:P,insetInline:P,insetInlineStart:P,insetInlineEnd:P,padding:P,paddingTop:P,paddingRight:P,paddingBottom:P,paddingLeft:P,paddingBlock:P,paddingBlockStart:P,paddingBlockEnd:P,paddingInline:P,paddingInlineStart:P,paddingInlineEnd:P,margin:P,marginTop:P,marginRight:P,marginBottom:P,marginLeft:P,marginBlock:P,marginBlockStart:P,marginBlockEnd:P,marginInline:P,marginInlineStart:P,marginInlineEnd:P,fontSize:P,backgroundPositionX:P,backgroundPositionY:P,...{rotate:k,rotateX:k,rotateY:k,rotateZ:k,scale:y,scaleX:y,scaleY:y,scaleZ:y,skew:k,skewX:k,skewY:k,distance:P,translateX:P,translateY:P,translateZ:P,x:P,y:P,z:P,perspective:P,transformPerspective:P,opacity:v,originX:S,originY:S,originZ:P},zIndex:w,fillOpacity:v,strokeOpacity:v,numOctaves:w};class B{constructor(){this.latest={},this.values=new Map}set(t,e,s,n,i=!0){const r=this.values.get(t);r&&r.onRemove();const a=()=>{const n=e.get();this.latest[t]=i?((t,e)=>e&&"number"==typeof t?e.transform(t):t)(n,R[t]):n,s&&o.render(s)};a();const d=e.on("change",a);n&&e.addDependent(n);const l=()=>{d(),s&&c(s),this.values.delete(t),n&&e.removeDependent(n)};return this.values.set(t,{value:e,onRemove:l}),l}get(t){return this.values.get(t)?.value}destroy(){for(const t of this.values.values())t.onRemove()}}function E(t){const e=new WeakMap,s=[];return(n,i)=>{const r=e.get(n)??new B;e.set(n,r);for(const e in i){const a=i[e],o=t(n,r,e,a);s.push(o)}return()=>{for(const t of s)t()}}}const F={x:"translateX",y:"translateY",z:"translateZ",transformPerspective:"perspective"};const x=new Set(["originX","originY","originZ"]),T=(s,n,i,r)=>{let a,o;return e.has(i)?(n.get("transform")||(function(t){return"object"==typeof(e=t)&&null!==e&&"offsetHeight"in t;var e}(s)||n.get("transformBox")||T(s,n,"transformBox",new f("fill-box")),n.set("transform",new f("none"),()=>{s.style.transform=function(e){let s="",n=!0;for(let i=0;i<t.length;i++){const r=t[i],a=e.latest[r];if(void 0===a)continue;let o=!0;if("number"==typeof a)o=a===(r.startsWith("scale")?1:0);else{const t=parseFloat(a);o=r.startsWith("scale")?1===t:0===t}o||(n=!1,s+=`${F[r]||r}(${e.latest[r]}) `)}return n?"none":s.trim()}(n)})),o=n.get("transform")):x.has(i)?(n.get("transformOrigin")||n.set("transformOrigin",new f(""),()=>{const t=n.latest.originX??"50%",e=n.latest.originY??"50%",i=n.latest.originZ??0;s.style.transformOrigin=`${t} ${e} ${i}`}),o=n.get("transformOrigin")):a=i.startsWith("--")?()=>{s.style.setProperty(i,n.latest[i])}:()=>{s.style[i]=n.latest[i]},n.set(i,r,a,o)},V=m(E(T));export{T as addStyleValue,V as styleEffect};
|
|
//# sourceMappingURL=size-rollup-style-effect.js.map
|