UNPKG

atriusmaps-node-sdk

Version:

This project provides an API to Atrius Personal Wayfinder maps within a Node environment. See the README.md for more information

35 lines (26 loc) 1.22 kB
'use strict'; function buildEnv (app) { const desktopViewMinWidth = app.config.desktopViewMinWidth || 0; // default to desktop view for all sizes const isBrowser = typeof window !== 'undefined'; // supportsTouch doesn't mean user PREFERS touch - touch laptops exist const supportsTouch = isBrowser && ('ontouchstart' in window || navigator.maxTouchPoints > 0); // I'd like to move from a single dimension (isMobile vs isDesktop) to a more // nuanced approach seperately considering narrow, touch, mobile (meaning moves // around), etc. Our UI is generally based on the narrow width of the map // container, so lets continue using that for isMobile for now... const isNarrow = () => isBrowser && innerWidth < desktopViewMinWidth; const isMobile = () => isNarrow(); const isDesktop = () => isBrowser && !isNarrow(); const isLocalhost = () => location.host.startsWith('localhost') || location.host.startsWith('127.0.0.1'); const env = { isBrowser, isMobile, isLocalhost, isDesktop, supportsTouch }; if (isBrowser) window.addEventListener('resize', () => app.bus.send('env/resize', { isMobile: env.isMobile() })); return env } exports.buildEnv = buildEnv;