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

42 lines (33 loc) 1.38 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 separately 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 isMobileReflow = () => isMobile() && innerHeight < 360; const isDesktop = () => isBrowser && !isNarrow(); const isLocalhost = () => location.host.startsWith('localhost') || location.host.startsWith('127.0.0.1'); const env = { isBrowser, isMobile, isMobileReflow, isLocalhost, isDesktop, supportsTouch, }; if (isBrowser) window.addEventListener('resize', () => { app.bus.send('env/resize', { isMobile: env.isMobile(), isMobileReflow: env.isMobileReflow(), }); }); return env; } exports.buildEnv = buildEnv;