UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 1.52 kB
import{select as m}from"d3-selection";import{getLayerSvg as p,gtePathByIndex as g}from"../../../../data/svg";import{meshToShapeDef as h,rectToShapeDef as c}from"../../../../engine/defs";import u from"../../../../store";import{LayersMode as x}from"../../../../store/LayerStore";export const BG_LAYER_NAME="bg",FG_LAYER_NAME="fg";export default async function b(e){let r=[],l=[];const n=[],a=m(p(e)).select(`[data-layer="${e.name}"]`),f=a.selectAll(":scope > *:not([data-tagname='efp-booth']):not(g[data-is-editable='false']) path, :scope > path").nodes(),d=a.selectAll(":scope g[data-layer] > g[data-is-editable='false'] path, :scope > g[data-is-editable='false'] path, :scope > path[data-tagname='ptext']").nodes(),i=u.layerStore.mode!==x.Default?e.rootParent?.name||e.name:"";for(const t of f){const s=+t.getAttribute("data-index");let o;t.tagName==="path"&&s!==-1?o=buildPathDef({color:t.style.fill,index:s},i):t.tagName==="rect"&&(o=c(t)),o&&r.push(o)}for(const t of d){const s=+t.getAttribute("data-index");let o;t.tagName==="path"&&s!==-1?o=buildPathDef({color:t.style.fill,index:s},i):t.tagName==="rect"&&(o=c(t)),o&&l.push(o)}return n.push({name:BG_LAYER_NAME,children:r}),n.push({name:FG_LAYER_NAME,children:l}),Promise.resolve({name:e.name,children:n.filter(t=>t.children.length)})}export function buildPathDef(e,r){if(e.index===-1||Number.isNaN(e.index))return;(!e.color||e.color==="none")&&(e.color="transparent");const l=parseInt(e.index.toString()),n=g(l,r),a=h(n,e.color);return a.unblinking=e.unblinking,a}