@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 2.46 kB
JavaScript
import*as a from"d3-selection";import{STRING_META_DELIMITER as u}from"../constants";import w from"../core/Rect";import _ from"../tools/logger";import b from"../tools/settings";import{extractMetaFromString as v}from"../utils/extractMetaFromString";import A from".";const r=new Map;function g(t,n=""){if(r.has(n))return r.get(n);const s=new DOMParser().parseFromString(t,"image/svg+xml").documentElement;s.firstChild.tagName==="parsererror"&&_.error("Parsed svg with error: ",l);const e=new Map;return a.select(s).selectAll("style").each(function(){const i=this.textContent,x=/\.([a-z0-9.]+)\s*{[^}]*fill\s*:\s*([^};]+);[^}]*}/gi;let h;for(;(h=x.exec(i))!==null;){const P=h[1],M=h[2];e.set(P,M)}}),a.select(s).selectAll("*[class]").each(function(){const i=this;i.style.fill=e.get(i.className.baseVal)}),S(s),r.set(n,s),s}let l=g(window.__fp);const m=window.__viewbox,d=a.select(l).select("rect#VIEWBOX").node(),p=l.viewBox.baseVal,c=w.fromXywh(p.x,p.y,p.width,p.height);let f;m?(f=w.fromXywh(m.x,m.y,m.width,m.height),d?.remove()):d?(f=w.fromSvgRectElement(d),d.remove()):f=c.withPadding(-c.w*.05,-c.h*.05),a.select(l).attr("width",c.w),a.select(l).attr("height",c.h),_.log("svgArea",f,"svgViewBox",c),b.wayfinding=!!(!A.hideDirections&&window.__wfData);let E=window.__fpLayersMode?a.select(l).selectAll("[data-floor]").nodes().map(t=>(t.remove(),{name:t.dataset.floor,rect:w.fromSvgRectElement(t)})).sort():[];export{f as svgArea,c as svgViewBox,E as floors};export function getTrianglesFromFpPaths(t,n){const o=gtePathByIndex(t,n);for(const e of o.positions)e[1]=Math.abs(e[1]),e.length=2;const s=[];for(const e of o.cells)s.push([o.positions[e[0]],o.positions[e[1]],o.positions[e[2]]]);return s}export let gtePathByIndex=(t,n="")=>{try{return window[`__fpPaths${n}`][t]}catch{return window.__fpPaths[t]}},getLayerSvg=(t="")=>typeof t=="string"?r.has(t)?r.get(t):window[`__fp${t}`]?g(window[`__fp${t}`],t):r.get(""):t.rootParent?r.has(t.rootParent.name)?r.get(t.rootParent.name):window[`__fp${t.rootParent.name}`]?g(window[`__fp${t.rootParent.name}`],t.rootParent.name):r.get(""):window[`__fp${t.name}`]?g(window[`__fp${t.name}`],t.name):r.get("");function S(t){a.select(t).selectAll("[id], [data-name]").each(function(){const n=this;let o={};const s=n.getAttribute("data-name");if(s&&s.includes(u)){const{meta:i}=v(s);o={...o,...i}}const e=n.getAttribute("id");if(e&&e.includes(u)){const{meta:i}=v(e);o={...o,...i}}n.setAttribute("data-meta",JSON.stringify(o))})}