UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 2.46 kB
import{Box as g,isBox as w}from"@expofp/geometry";import{select as b}from"d3";import{getFpSvgJs as u}from"../../data/fp-payloads";import{floors as x,getLayerSvg as p}from"../../data/svg";import{isPathwayLayer as L}from"../../utils/is-pathway-layer";import{Layer as c,LayerMode as n,LayersMode as m}from"../LayerStore";const h=1e3;function v(r){return r==null||w(r)?r:g.fromMinMax({x:r.x1,y:r.y1},{x:r.x2,y:r.y2})}export function getChildLayers(r,a,d){const f=[];let l=a;return b(p(r)).selectAll(`svg [data-layer="${r.name}"] > [data-layer]`).nodes().filter(o=>o.childNodes.length).forEach(o=>{const e=o.getAttribute("data-layer");let t=new c;t.name=o.getAttribute("data-layer"),t.visible=r.visible,t.description=o.getAttribute("data-layer-description")||e,t.frozen=o.getAttribute("data-layer-isfrozen")==="true",t.rect=r.rect,t.viewbox=r.viewbox,t.mode=n.Unset,t.rootParent=r.rootParent?r.rootParent:r;const i=getChildLayers(t,l,d);l=i.priority+d,t.basePriority=l,i.layers.length&&(t.childLayers=i.layers,f.push(...i.layers)),f.push(t)}),{layers:f,priority:l}}export default function z(r){const{layerStore:a}=r,d=u().__fpLayers;a.mode=u().__fpLayersMode||m.Default;const f=new URLSearchParams(window.location.search).get("layer"),l=(e,t)=>f?t.toLowerCase()===f.toLowerCase():a.mode!==m.Default?e.mode==n.TurnedOn:e.visible;let s=[],o=0;d?d.forEach(e=>{o+=h;let t=new c;t.name=e.name,t.description=e.description,t.frozen=e.frozen,t.visible=l(e,t.shortName),t.rect=v(e.rect),t.viewbox=v(e.viewbox),t.mode=e.mode||n.Unset,t.basePriority=o,t.floorIndex=e.floorIndex,s.push(t)}):b(p()).selectAll("svg > [data-layer]").nodes().filter(e=>e.childNodes.length).forEach(e=>{const t=e.getAttribute("data-layer");if(!t.startsWith("WF")){o+=h;let i=new c;i.name=t,i.visible=!0,i.description=e.getAttribute("data-layer-description")||t,i.frozen=e.getAttribute("data-layer-isfrozen")==="true",i.rect=x.filter(y=>y.name===i.name||y.name===i.description)[0]?.rect,i.mode=n.Unset,i.basePriority=o,s.push(i)}}),a.mode!==m.Default&&s.forEach(e=>{e.mode===n.AlwaysHidden?(e.frozen=!0,e.visible=!1):e.mode===n.AlwaysVisible?e.frozen=e.visible=!0:e.mode===n.TurnedOff?(e.frozen=!1,e.visible=!1):e.mode===n.TurnedOn&&(e.frozen=!1,e.visible=!0)});try{s.forEach(e=>{L(e.name)&&(e.frozen=!1,e.visible=!1,e.pathway=!0)})}catch(e){console.warn(e)}s=s.filter(e=>e.pathway||!e.frozen||e.frozen&&e.visible),a.defaultLayer=s.find(e=>e.name===u().__fpDefaultLayer),a.layers=[...a.layers,...s]}