@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 2.76 kB
JavaScript
import{Rect as C}from"@expofp/geometry";import{update as E}from"@expofp/renderer";import G from"debug";import{reaction as M}from"mobx";import{SEPARATOR as s}from"../../../../constants";import{createImageDef as T}from"../../../../engine/defs";import{flipImageDef as U,isInnerInsideOuter as _,rotateImageDef as z}from"../../../../engine/utils/rotation";import{boothStore as $,layersStore as K,uiState as Z}from"../../../../store";import j from"../../../../tools/settings";import{loadBlobsInBatchesById as q}from"../../../../utils/loadImagesInBatches";import{clearHoveredBooth as F,hoverBooth as J,rememberBoothShapes as Q,selectBooth as V}from"../../pointer";import{createLogoPreparer as X}from"./booth-logos";import Y from"./config-booth-bg";import oo from"./config-booth-bookmark";import eo from"./config-booth-border";import to,{isDirectionsMode as ro}from"./config-booth-labels";import no from"./config-booth-labels-special";import{registerLayerImages as so}from"./layer-images";import{createBoothImg as ao,getImageLayerName as io,mapBoothsLogos as co}from"./loadBoothsImages";const k=G("efp:booth-logos");export const BOOTHS_CHUNK_SIZE=350;export default function lo(D,R){return(h=>{const e=D,g=[],p=[],d=[],u=[],B=[],L=io(e),S={name:L,children:[]};for(const o of h){const i=Y(o)?.getShape();i&&(g.push(...i),Q(o,i));const c=to(o)?.getShape();c&&p.push(...c);const l=no(o)?.getShape();if(l&&d.push(...l),!j.borderless){const t=eo(o)?.getShape();t&&u.push(t)}const m=oo(o)?.getShape();m&&B.push(m)}const x=p.filter(o=>o.lines),O=d.filter(o=>o.lines),P=p.filter(o=>o.source),w=d.filter(o=>o.source);if(!Z.hideLogoInBooth){const o=co(h);so(L,async()=>{const i=await q(o,BOOTHS_CHUNK_SIZE),c=[],l=X(),m=await Promise.all([...i].map(async([t,r])=>{const a=$.boothById.get(t);return[t,a,a?await l(a,r):null]}));for(const[t,r,a]of m){if(!r){k("dropped a logo: no booth has id %s",t);continue}if(!a){k("dropped the logo of booth %s: the image could not be read",t);continue}const{blob:v,aspectRatio:H}=a,{bounds:N}=ao(r,H),n=T(v,N),W=r.borderWidth||$.borderWidth,I=r.rect.expand(-W),A=new C(I.center,I.size,r.rotate);n.onRoll=_(n.bounds,A)?({roll:b})=>z(n,b)?[n]:void 0:({roll:b})=>U(n,b)?[n]:void 0,r.shapes.push(n),c.push(n)}return{layer:S,children:c}})}const f={name:`${e}${s}labelGroup`,children:[{name:`${e}${s}labels`,children:x},{name:`${e}${s}specialLabels`,children:O},{name:`${e}${s}dots`,children:P},{name:`${e}${s}specialDots`,children:w}]};M(()=>K.layersLoaded&&ro(),o=>{f.dim=o?0:void 0,E(f)},{fireImmediately:!0});let y=[];if(h.length){const o=e+s;y=[{name:`${o}boothBackground`,children:g,onPointerMove:J,onPointerOut:F,onClick:V},f,S,{name:`${o}boothsBookmark`,children:B},{name:`${e}${s}boothBorder`,children:u}]}return{name:e,children:y}})(R)}