UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 1.79 kB
import{degToRad as f,radToDeg as d,Rect as h}from"@expofp/geometry";import{select as u}from"d3";import{SEPARATOR as y}from"../../../../constants";import{getFpSvgJs as R}from"../../../../data/fp-payloads";import{getLayerSvg as x}from"../../../../data/svg";import{flipImageDef as I,isInnerInsideOuter as w}from"../../../../renderer";import{rotateImageDef as A}from"../../../../renderer/engine-core/utils/rotation";import{getLogoUrl as L}from"../../../../utils/getLogoUrl";export async function loadLayersImages(e){const a=e.layerImagesRegistry.invoke();await Promise.all(a.map(async s=>{const n=await s;if(!n)return;const{layer:r,children:c}=n;if(c.length){const i=[];for(let o=0;o<c.length;o++){const{shape:t,parentRect:g}=c[o],l=w(t.bounds,g);if(!r.name.includes("Pathway_")){const m=l?"image-rotate":"image-flip";e.onRoll(`${m}-${r.name}-${o}`,l?p=>A(t,p):p=>I(t,p))}i.push(t)}r.children.push(...i),e.update(r)}}))}export const getImageLayerName=e=>`${e}${y}images`;export function mapBoothsLogos(e){return new Map(e.map(a=>{const s=a.rect&&a.exhibitors.find(n=>n.logoInBooth&&n.logo);return s?[a.id,{preferred:L(s.logo),fallback:s.logo.url}]:null}).filter(Boolean))}export function getLayerIcons(e){const a=u(x(e)).select(`[data-layer="${e.name}"]`);return(R().__fpVersion>5?a.selectAll(":scope > image, :scope > g:not([data-layer]) image").nodes():a.selectAll(":scope > g[data-is-editable='false'] image").nodes()).filter(Boolean)}export function createBoothImg(e,a){const s=e.rect,n=s.size.width,r=s.size.height,c=r?n/r:1,i=a.height?a.width/a.height:1;let o,t,g;const l=.9;c>i?(t=r*l,o=t*i):(o=n*l,t=o/i);const m=e.rotate||0;return i>=2&&!m&&r>=n*2?(t=n*l,o=t*i,g=-90):g=d(m),o>n&&(o=n,t=o/i),t>r&&(t=r,o=t*i),{name:e.slug,bounds:new h(s.center,{x:o,y:t},f(g)),htmlImage:a,booth:e}}