UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 5.16 kB
import{__esDecorate as e,__runInitializers as a}from"tslib";import{action as u,computed as n,observable as l}from"mobx";import c from"../data/tours.json";import D from"../tools/settings";const d=1;let j=(()=>{let o=[],h,f=[],T=[],p,m=[],y=[],_,g=[],S=[],v,E=[],L=[],I,x,A,P,w,b,k,z;return class{static{const r=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;h=[l],p=[l],_=[l],v=[l],I=[u],x=[u],A=[n],P=[n],w=[n],b=[n],k=[u],z=[u],e(this,null,I,{kind:"method",name:"loadTours",static:!1,private:!1,access:{has:t=>"loadTours"in t,get:t=>t.loadTours},metadata:r},null,o),e(this,null,x,{kind:"method",name:"resetTours",static:!1,private:!1,access:{has:t=>"resetTours"in t,get:t=>t.resetTours},metadata:r},null,o),e(this,null,A,{kind:"getter",name:"tourItems",static:!1,private:!1,access:{has:t=>"tourItems"in t,get:t=>t.tourItems},metadata:r},null,o),e(this,null,P,{kind:"getter",name:"currentTour",static:!1,private:!1,access:{has:t=>"currentTour"in t,get:t=>t.currentTour},metadata:r},null,o),e(this,null,w,{kind:"getter",name:"isActive",static:!1,private:!1,access:{has:t=>"isActive"in t,get:t=>t.isActive},metadata:r},null,o),e(this,null,b,{kind:"getter",name:"tourLayers",static:!1,private:!1,access:{has:t=>"tourLayers"in t,get:t=>t.tourLayers},metadata:r},null,o),e(this,null,k,{kind:"method",name:"launchTour",static:!1,private:!1,access:{has:t=>"launchTour"in t,get:t=>t.launchTour},metadata:r},null,o),e(this,null,z,{kind:"method",name:"stopTour",static:!1,private:!1,access:{has:t=>"stopTour"in t,get:t=>t.stopTour},metadata:r},null,o),e(null,null,h,{kind:"field",name:"tours",static:!1,private:!1,access:{has:t=>"tours"in t,get:t=>t.tours,set:(t,s)=>{t.tours=s}},metadata:r},f,T),e(null,null,p,{kind:"field",name:"currentExpo",static:!1,private:!1,access:{has:t=>"currentExpo"in t,get:t=>t.currentExpo,set:(t,s)=>{t.currentExpo=s}},metadata:r},m,y),e(null,null,_,{kind:"field",name:"hasTours",static:!1,private:!1,access:{has:t=>"hasTours"in t,get:t=>t.hasTours,set:(t,s)=>{t.hasTours=s}},metadata:r},g,S),e(null,null,v,{kind:"field",name:"toursLoadError",static:!1,private:!1,access:{has:t=>"toursLoadError"in t,get:t=>t.toursLoadError,set:(t,s)=>{t.toursLoadError=s}},metadata:r},E,L),r&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:r})}rootStore=a(this,o);tours=a(this,f,[]);currentExpo=(a(this,T),a(this,m,""));hasTours=(a(this,y),a(this,g,!1));toursLoadError=(a(this,S),a(this,E,null));constructor(r){a(this,L),this.rootStore=r,this.loadTours()}loadTours(){try{if(this.currentExpo=D.EXPO||"default",this.toursLoadError=null,!this.isValidToursData(c)){this.toursLoadError="Invalid tours data format",this.resetTours();return}const r=c[this.currentExpo]||[];if(!this.validateToursStructure(r)){this.toursLoadError="Invalid tour items structure",this.resetTours();return}this.tours=r,this.hasTours=r.length>0}catch(r){console.error("Error loading tours:",r),this.toursLoadError=r instanceof Error?r.message:"Failed to load tours",this.resetTours()}}resetTours(){this.tours=[],this.hasTours=!1}isValidToursData(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)}validateToursStructure(r){return Array.isArray(r)?r.every(t=>t&&typeof t=="object"&&typeof t.id=="string"&&Array.isArray(t.layers)&&t.layers.length>=d&&(t.points===void 0||Array.isArray(t.points))):!1}get tourItems(){return this.tours}getTourById(r){return this.tours.find(t=>t.id===r)}getToursByPoint(r){return this.tours.filter(t=>t.points?.includes(r))}getToursForExpo(r){return this.isValidToursData(c)?c[r]||[]:[]}get currentTour(){const{list:r}=this.rootStore.uiState;return r.type!=="multi-point-tour"||!this.isMultiPointTourList(r)?null:this.getTourById(r.tourId)||null}isMultiPointTourList(r){return r.type==="multi-point-tour"&&typeof r.tourId=="string"}get isActive(){return this.rootStore.uiState.list.type==="multi-point-tour"}get tourLayers(){const r=this.currentTour;return r?r.layers.map(t=>this.rootStore.layerStore.findLayer(t.floor)).filter(t=>t!=null):[]}getTourLayerInfo(r){const t=this.currentTour;if(t)return t.layers.find(s=>{const i=this.rootStore.layerStore.findLayer(s.floor);return i&&(i.name===r||i.description===r)})}launchTour(r,t,s){const i=this.validateTourForLaunch(r);if(i)return console.warn(`Cannot launch tour: ${i}`),!1;const M=r.layers[0].id,O=r.layers[0].floor;return r.points&&r.points.length>0?this.rootStore.fp.showPathway(M,r.points):this.rootStore.fp.showPathwayOnly(M,O),this.rootStore.uiState.setTourTitle(t),this.rootStore.uiState.setTourDescription(s),this.rootStore.uiState.setIsMultiPointTour(!0),this.rootStore.uiState.setMultiPointTourList(r.id),window.setTimeout(()=>{this.rootStore.showMap()},navigator.userAgent.toLowerCase().indexOf("android")>-1?400:50),!0}validateTourForLaunch(r){return r.layers.length<d?`Tour must have at least ${d} layer`:null}stopTour(){this.rootStore.uiState.setIsMultiPointTour(!1),this.rootStore.uiState.setPathwayOnlyMode(!1);const r=this.rootStore.uiState.list.type;(r==="tours"||r==="multi-point-tour")&&(this.rootStore.uiState.list={type:"search",text:"",focused:!1}),this.rootStore.fp.hidePathways()}}})();export default j;