UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 1.63 kB
import{degToRad as f,radToDeg as p,Rect as d}from"@expofp/geometry";import{update as h}from"@expofp/renderer";import{select as u}from"d3";import{SEPARATOR as g}from"../../../../constants";import{getFpSvgJs as y}from"../../../../data/fp-payloads";import{getLayerSvg as L}from"../../../../data/svg";import{getLogoUrl as A}from"../../../../utils/getLogoUrl";import{boothLogoExhibitor as x}from"./booth-logos";import{invokeLayerImages as T}from"./layer-images";import{MODEL_3D_ATTRIBUTE as R}from"./layer-models";export async function loadLayersImages(){const e=T();await Promise.all(e.map(async t=>{const r=await t;if(!r?.children.length)return;const{layer:o,children:s}=r;o.children.push(...s),h(o)}))}export const getImageLayerName=e=>`${e}${g}images`,getModelLayerName=e=>`${e}${g}models`;export function mapBoothsLogos(e){const t=new Map;for(const r of e){if(!r.rect)continue;const o=x(r)?.logo;o&&t.set(r.id,{preferred:A(o),fallback:o.url})}return t}export function getLayerGraphics(e){const t=u(L(e)).select(`[data-layer="${e.name}"]`),r=((y().__fpVersion??0)>5?t.selectAll(":scope > image, :scope > g:not([data-layer]) image").nodes():t.selectAll(":scope > g[data-is-editable='false'] image").nodes()).filter(Boolean),o=[],s=[];for(const a of r)(a.hasAttribute(R)?s:o).push(a);return{icons:o,models:s}}export function createBoothImg(e,t){const r=e.rect,o=r.size.width,s=r.size.height,a=s?o/s:1;let i,n,c;const l=.9;a>t?(n=s*l,i=n*t):(i=o*l,n=i/t);const m=e.rotate||0;return t>=2&&!m&&s>=o*2?(n=o*l,i=n*t,c=-90):c=p(m),i>o&&(i=o,n=i/t),n>s&&(n=s,i=n*t),{name:e.slug,bounds:new d(r.center,{x:i,y:n},f(c),e.elevation),booth:e}}