UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

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