UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

6 lines (5 loc) 2.38 kB
import{autorun as s,reaction as h,runInAction as v}from"mobx";import{ResizeObserver as g}from"resize-observer";import{KIOSK_ENABLE_KEY as l,VISIBILITY_STORAGE_KEY as k}from"../../constants";import w from"../../core/Size";import E from"../../data";import y from"../../tools/logger";import{isWebGlSupported as x}from"../../utils";import{detectLimitedModeViaImage as b}from"../../utils/detectLimitedModeViaImage";import{isLocalStorageAvailable as a}from"../../utils/localStorage";import c from"../../utils/preview-exhibitor";let o;export default function z(i){const{uiState:e,exhibitorStore:u,searchStore:T}=i;e.rootElement=window.__efpElement,f(e.rootElement.clientWidth,e.rootElement.clientHeight),o=new g(t=>{t.forEach(r=>{f(r.contentRect.width,r.contentRect.height)})}),o.observe(e.rootElement),c&&(e.previewExhibitor=u.exhibitorById.get(c.id));const n=typeof matchMedia<"u"?matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`):null;n&&n.addEventListener&&n.addEventListener("change",()=>{e.devicePixelRatio=window.devicePixelRatio});const p=c||!x?"full":"medium";E.isRebooking&&e.list.type==="search"&&!e.list.text&&i.selectExhibitors(),e.desiredOverlaySize=p,s(()=>{(e.searchFocused||e.menu)&&e.overlayPosition!=="left"&&(e.desiredOverlaySize="full")}),s(()=>{e.overlaySize!=="full"&&e.menu&&(e.menu=!1)}),e.wsShown||(e.wsStarted=!0),e.kiosk=a&&localStorage.getItem(l)==="1",window.__resett=d;function S(){i.reset()}var m;function d(){e.kiosk&&(y.log("zzz2","reset timer"),clearTimeout(m),m=setTimeout(S,3e4),e.inIdle=!1)}s(()=>{const t=e.list;t.type==="search"&&(t.text==="kkiosk"?e.kiosk=!0:t.text==="nokkiosk"&&(e.kiosk=!1))}),h(()=>e.kiosk,t=>{a&&(t?(localStorage.setItem(l,"1"),d()):localStorage.setItem(l,"0"))}),a&&e.setVisibility(JSON.parse(localStorage.getItem(k))||{});function f(t,r){v("uiState.screenSize",()=>{e.screenSize=new w(t,r)})}I(i)}export function destroyUiHandlers(){o&&(o.disconnect(),o=null)}async function I(i){try{if(!await b())return;i.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)}}