@expofp/floorplan
Version:
Interactive floor plan library for expos and events
6 lines (5 loc) • 2.59 kB
JavaScript
import{Point as h}from"@expofp/geometry";import{autorun as c,comparer as S,reaction as v,runInAction as E}from"mobx";import{ResizeObserver as b}from"resize-observer";import{applyKioskMode as d}from"../../components/Kiosk/kiosk-mode";import{KIOSK_ENABLE_KEY as w,VISIBILITY_STORAGE_KEY as g}from"../../constants";import x from"../../data";import y from"../../tools/logger";import{isWebGlSupported as k}from"../../utils";import{detectLimitedModeViaImage as z}from"../../utils/detectLimitedModeViaImage";import{isLocalStorageAvailable as f}from"../../utils/localStorage";import u from"../../utils/preview-exhibitor";let n=null;export function bindRootElement(t){const e=window.__efpElement;if(!e)return;const{uiState:l}=t;l.rootElement=e;const o=(s,r)=>E("uiState.screenSize",()=>{l.screenSize=new h(s,r)});o(e.clientWidth,e.clientHeight),n?.disconnect(),n=new b(s=>{s.forEach(r=>{o(r.contentRect.width,r.contentRect.height)})}),n.observe(e)}export default function I(t){const{uiState:e,exhibitorStore:l}=t;if(bindRootElement(t),u){const i=l.exhibitorById.get(u.id);i&&(e.previewExhibitor=i)}const o=typeof matchMedia<"u"?matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`):null;o&&o.addEventListener&&o.addEventListener("change",()=>{e.devicePixelRatio=window.devicePixelRatio});const s=u||!k?"full":"medium";x.isRebooking&&e.list.type==="search"&&!e.list.text&&t.selectExhibitors(),e.desiredOverlaySize=s,c(()=>{(e.searchFocused||e.menu)&&e.overlayPosition!=="left"&&(e.desiredOverlaySize="full")}),c(()=>{e.overlaySize!=="full"&&e.menu&&(e.menu=!1)}),e.wsShown||(e.wsStarted=!0),f&&localStorage.getItem(w)==="1"&&d(e,!0),window.__resett=m;function r(){t.reset()}let a;function m(){!e.kiosk||e.setKioskModeEnabled||(y.log("zzz2","reset timer"),clearTimeout(a),a=setTimeout(r,3e4),e.inIdle=!1)}c(()=>{const i=e.list;i.type==="search"&&(i.text==="kiosk=1"?d(e,!0):i.text==="kiosk=0"&&d(e,!1))}),v(()=>[e.kiosk,e.setKioskModeEnabled],([i,p])=>{i&&!p?m():clearTimeout(a)},{equals:S.structural}),f&&e.setVisibility(JSON.parse(localStorage.getItem(g)??"null")||{}),T(t)}export function destroyUiHandlers(){n&&(n.disconnect(),n=null)}async function T(t){try{if(!await z())return;t.uiState.setGlobalErrorMessage({title:"Unsupported Environment Detected",body:`
This application requires a proper server environment to function correctly.
For full functionality, please ensure the application is served through an HTTP/HTTPS server.
Some features may not work as expected in the current setup.
`.trim()})}catch(e){console.error(e)}}