@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 7.29 kB
JavaScript
import{getConfig as C}from"@expofp/config";import{PREVIEW_MODE_ATTRIBUTE as M}from"./constants";import{toInternalSettings as T}from"./internal-settings.js";import{disposePlan as A}from"./plan-lifecycle.js";import d from"./tools/base-runtime-url";import{loadCss as S,loadFont as p}from"./tools/loaders";import _ from"./tools/logger";import{resetGlobalVariables as V}from"./tools/reset";import{initSentry as H}from"./tools/sentry";import{parkRegisteredStyles as z}from"./tools/style-registry.js";import{heatmapEnabled as G}from"./utils/heatmap-enabled";import{initI18n as N}from"./utils/i18n";import Y from"./utils/is-debug";import Q from"./utils/is-localhost";import x from"./utils/is-webview";import{loadCustomCss as W}from"./utils/loadCustomCss";import{loadIcons as K}from"./utils/loadIcons";import E from"./utils/use-shadow";function e(){throw new Error("FloorPlan not ready")}export const DESTROYED_BEFORE_READY="FloorPlan destroyed before it finished loading";export default class ${get ready(){return this._ready}get previewMode(){return C().previewMode||this.element.hasAttribute(M)}get allowConsent(){return this.consent==="ask"?void 0:this.consent==="granted"}getInternalSettings(){return T(C())}selectBooth(t){e()}selectExhibitor(t){e()}selectRoute(t,s){e()}getOptimizedRoutes(t){e()}selectCurrentPosition(t,s,a){e()}setBookmarks(t){e()}setEntitiesBookmarks(t){e()}setEntitiesVisited(t){e()}setMarkers(t){e()}updateLayerVisibility(t,s){e()}getCenterCoordinates(){e()}applyParameters(t){e()}exhibitorsList(){e()}boothsList(){e()}categoriesList(){e()}selectCategory(t){e()}select(t){e()}showList(t){e()}showSessions(t){e()}selectTour(t){e()}openPlanner(t){e()}startBuildRoute(){e()}getVisibility(){e()}setVisibility(t){e()}findLocation(){e()}zoomIn(){e()}zoomOut(){e()}zoomTo(t,s){e()}switchView(){e()}setCamera(t){e()}getCamera(){e()}fitBounds(){e()}getBounds(t){e()}getBoothRect(t){e()}convertToGeo(t,s){e()}getGeoConfig(){e()}destroy(){if(!this.destroyed){this.destroyed=!0,this.rejectReady(new Error(DESTROYED_BEFORE_READY));try{this.releaseResources()}finally{A()}}}unstable_destroy(){this.destroy()}releaseResources(){for(window.removeEventListener("__efpStyleLoad",this.efpStyleLoadHandler),z();this.element.firstChild;)this.element.removeChild(this.element.firstChild);delete this.element.__expofp,V()}highlightExhibitors(t){e()}highlightBooths(t){e()}onCurrentPositionChanged(t){e()}search(t){e()}getFloors(){e()}onFloorActivated(t){e()}activateFloor(t){e()}showPathway(t,s){e()}showPathwayOnly(t,s){e()}hidePathways(){e()}showSearch(){e()}changeLanguage(t){e()}isGpsTrackingEnabled(){e()}setGpsTrackingEnabled(t){e()}deselectCurrentPosition(){e()}deselectRoute(){e()}reset(){e()}selectAccessibleRoute(t){e()}constructor(t,s){this.resolveReady=()=>{},this.rejectReady=()=>{},this.icons=new Map,this.enableRotation=!0,this.alwaysShowSidebar=!1,this.destroyed=!1;const a=C();this.noOverlay=!!a.noOverlay,this.offHistory=!!a.offHistory,this.ignoreQuery=a.ignoreQuery,this.consent=a.consent,this.consent==="ask"&&(x?this.consent="granted":Q&&!Y&&(this.consent="denied")),this.onBoothClick=t.onBoothClick,this.onBookmarkClick=t.onBookmarkClick,this.onVisitedClick=t.onVisitedClick,this.onCategoryClick=t.onCategoryClick,this.onDetails=t.onDetails,this.onExhibitorCustomButtonClick=t.onExhibitorCustomButtonClick,this.onGetCoordsClick=t.onGetCoordsClick,this.onMarkerClick=t.onMarkerClick,this.onFpConfigured=t.onFpConfigured,this.onDirection=t.onDirection,this.onInit=t.onInit,this.onCurrentPositionChanged=t.onCurrentPositionChanged,this.onFloorActivated=t.onFloorActivated,this.onLeaveEvent=t.onLeaveEvent,this.viewerMode=!!a.viewerMode,this.disableRuntimeAlerts=a.disableRuntimeAlerts,this.maplibre=a.maplibre,window.__efpMaplibre=a.maplibre,this._ready=new Promise((c,i)=>{this.resolveReady=c,this.rejectReady=i}),this._ready.catch(()=>{}),this.element=s;const R=s;if(R.__expofp)throw new Error("Element already in use");R.__expofp=this;const g=a.expo;H({eventId:g||"",isWebview:x}),this.eventId=g,window.__efpEvent=g,window.__efpElement=s;const w=document.createElement("div");w.style.height="100%",w.style.width="100%",s.appendChild(w);let n;if(E){n=w.attachShadow({mode:"open"});const c=n,i=document;c.createElement=(...r)=>i.createElement(...r),c.createElementNS=(...r)=>i.createElementNS(...r),c.createTextNode=(...r)=>i.createTextNode(...r)}else n=w;const y=document.createElement("div");y.style.height="100%",y.style.width="100%",n.appendChild(y),E&&Object.defineProperty(y,"ownerDocument",{value:n}),window.__efpShadowDOMStyleParent=E?n:void 0,this.renderTarget=y,_.log("Instantiating ExpoFP floorplan",s,g);let k=0;this.efpStyleLoadHandler=function(c){const i=window.__efpStyleElements??[];for(;k<i.length;){const r=i[k];n.appendChild(r),k++}},window.addEventListener("__efpStyleLoad",this.efpStyleLoadHandler),this.efpStyleLoadHandler();const h=this;(async function(){const i=C();if(await N(),h.destroyed)return;const r=new URLSearchParams(window.location.search);let m,f;if(i?.trackerUrl)try{m=new URL(i.trackerUrl),f=m.searchParams.get("expoId")}catch(o){console.error(o)}const I=async o=>{if(!m||!f)return Promise.reject(new Error("trackerUrl or expoId is missing"));const l=new URL(o.dataUrl,m.origin),u=await fetch(l.toString(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({expoId:f,token:decodeURIComponent(r.get("t")??"")})});let b=[];u.ok&&(b=(await u.json()).map(o.dataMapper)),window.__heatmapDataYah={yah:b}},v=i?.heatmap??{},L=G(v)||r.get("heatmap")==="true",O=v.variant==="yah"||r.get("type")==="yah",U=v.kiosk===!0||r.get("subtype")==="kiosk";if(L)try{if(O)U?await I({dataUrl:"/api/kiosks/list/viewer",dataMapper:o=>({...o,id:o.key,name:`Kiosk ${o.key}`})}):await I({dataUrl:"/api/v1/you-are-here/qr-code/list/viewer",dataMapper:(o,l)=>({...o,name:`QR Code #${l+1}`})});else{if(!m||!f)throw new Error("trackerUrl or expoId is missing");const o=new URL("/api/fp-stats/get",m.origin);o.searchParams.set("expoId",f),o.searchParams.set("type","booview"),o.searchParams.set("t",decodeURIComponent(r.get("t")??""));const l=new URL("api/fp-stats/get",m.origin);l.searchParams.set("expoId",f),l.searchParams.set("type","exview"),l.searchParams.set("t",decodeURIComponent(r.get("t")??""));const[u,b]=await Promise.all([fetch(o.toString()),fetch(l.toString())]),[P,F]=await Promise.all([u.json(),b.json()]);window.__heatmapData={booths:P,exhibitors:F}}}catch(o){console.error("Heatmap: Initialization error",o)}const B=[S(d+"vendor/sanitize-css/sanitize.css",n),S(d+"vendor/perfect-scrollbar/css/perfect-scrollbar.css",n),p("Oswald",d+"fonts/oswald-v17-cyrillic_latin-300.woff",{weight:300}),p("Oswald",d+"fonts/oswald-v17-cyrillic_latin-500.woff",{weight:500}),p("Inter",d+"fonts/inter-400.woff2",{weight:400}),p("Inter",d+"fonts/inter-500.woff2",{weight:500}),p("Inter",d+"fonts/inter-600.woff2",{weight:600}),p("efp-symbols",d+"fonts/efp-symbols.woff",{weight:400}),W(i,n),K(h.icons)];if(await Promise.all(B),h.destroyed)return;h.enableRotation=i?.enableRotation??!1,h.alwaysShowSidebar=i?.alwaysShowSidebar??!1,_.log("Data loaded");const{createLivePlan:D}=await import("./store/create-live-plan.js"),{default:j}=await import("./floorplan.ready.js");if(h.destroyed)return;D(),Object.setPrototypeOf(h,j.prototype).init()})()}}