UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 1.07 kB
import{getLogoUrl as g}from"./getLogoUrl";import{loadImage as u}from"./loadImage";export default function x(e){return Promise.all(e.map(t=>new Promise(async h=>{const l=t.exhibitors?.find(n=>n.logoInBooth&&n.logo)?.logo;if(!l)return h(null);const a=t.rect;let i=await u(g(l));if(i||(i=await u(l)),!i)return h(null);const w=a.w/a.h,r=i.width/i.height;let o=0,s=0,m;if(w>r?(s=a.h*.9,o=s*r):(o=a.w*.9,s=o/r),r>=2&&!t.rotate&&t.rect.h>=t.rect.w*2){let n=a.w*.9,c=n*r;for(;c>a.h-2;)n--,c=n*r;s=n,o=c,m=-90}else m=-t.rotate*180/Math.PI;const d=a.cx-o/2,f=a.cy-s/2;h({name:t.slug,bounds:{x:d,y:f,width:o,height:s,angle:m},htmlImage:i,booth:t})})))}export function loadIcons(e){return Promise.all(e.map(t=>new Promise(async h=>{var l=await u(p(t.getAttribute("xlink:href")||t.getAttribute("href")));h(l?{bounds:{x:t.x.animVal.value,y:t.y.animVal.value,width:t.width.animVal.value,height:t.height.animVal.value,angle:t.transform?.animVal[0]?.angle??0},htmlImage:l,booth:null}:null)})))}function p(e){return!e?.startsWith("data:")&&e?.indexOf("://")===-1?window.__dataUrlBase+e:e}