@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 985 B
JavaScript
export const DIM_INTENSITY=.5,VENUE_DIM_INTENSITY=1,DIM_TRANSITION_MS=300,DEFAULT_DIM_EASING="cubic";export function applyVenueDimValue(e,r){const o=e.scene;if(!o)return;const n=o.rootLayer;n.dim!==r&&(n.dim=r,e.update(o.rootLayer))}export function createDimmingAnimator(e,r=300,o=DEFAULT_DIM_EASING){let n=null,t=0,m=0,a=0,l=0;const f=Math.max(r,0);function s(){n===null||typeof cancelAnimationFrame!="function"||(cancelAnimationFrame(n),n=null)}function p(i){s(),t=i,e(t)}function I(i){const c=i-l,u=Math.min(c/f,1),T=A(u,o);if(t=m+(a-m)*T,e(t),u<1){n=requestAnimationFrame(I);return}n=null,t=a,e(t)}return{getValue(){return t},setTarget(i,c={}){const u=i?1:0;if(!(!c.immediate&&u===a&&n===null)){if(a=u,c.immediate||f===0||typeof requestAnimationFrame!="function"){p(a);return}s(),m=t,l=typeof performance>"u"?Date.now():performance.now(),n=requestAnimationFrame(I)}},stop(){s()}}}function A(e,r){return r==="linear"?e:M(e)}function M(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}