@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 975 B
JavaScript
import{useCallback as p,useEffect as s,useRef as o}from"react";import T,{uiState as I}from"../../store";import{applyVenueDimValue as M,createDimmingAnimator as l,DIM_INTENSITY as D,VENUE_DIM_INTENSITY as V}from"../../utils/dimming";import{useReaction as d}from"../../utils/mobx";import{applyMapDimValue as f}from"./utils/map-helpers";export function getMapDimTarget(){return I.dimmed&&!T.poiMarkerStore.dimSuppressed}export function useDimming(a,m){const i=o(m);s(()=>{i.current=m},[m]);const e=o(null),n=o(null),c=p(t=>{const r=getMapDimTarget();e.current?.setTarget(r,t),n.current?.setTarget(r,t)},[]);s(()=>{const t=l(u=>{f(a.current,u*D)}),r=l(u=>{M(i.current,u*V)});return e.current=t,n.current=r,()=>{t.stop(),r.stop(),e.current=null,n.current=null}},[a]),d(()=>getMapDimTarget(),()=>c());const g=p(t=>{const r=e.current?.getValue()??(getMapDimTarget()?1:0);f(t,r*D)},[]);return{mapDimAnimatorRef:e,venueDimAnimatorRef:n,applyDimmingTarget:c,handleMapDimLayerReady:g}}