UNPKG

@animech-public/playcanvas

Version:
44 lines (42 loc) 2.04 kB
var _ref, _ref2, _ref3; const detectPassiveEvents = () => { let result = false; try { const opts = Object.defineProperty({}, 'passive', { get: function () { result = true; return false; } }); window.addEventListener('testpassive', null, opts); window.removeEventListener('testpassive', null, opts); } catch (e) {} return result; }; const ua = typeof navigator !== 'undefined' ? navigator.userAgent : ''; const environment = typeof window !== 'undefined' ? 'browser' : typeof global !== 'undefined' ? 'node' : 'worker'; const platformName = /android/i.test(ua) ? 'android' : /ip(?:[ao]d|hone)/i.test(ua) ? 'ios' : /windows/i.test(ua) ? 'windows' : /mac os/i.test(ua) ? 'osx' : /linux/i.test(ua) ? 'linux' : /cros/i.test(ua) ? 'cros' : null; const browserName = environment !== 'browser' ? null : /Chrome\/|Chromium\/|Edg.*\//.test(ua) ? 'chrome' : /Safari\//.test(ua) ? 'safari' : /Firefox\//.test(ua) ? 'firefox' : 'other'; const xbox = /xbox/i.test(ua); const touch = environment === 'browser' && ('ontouchstart' in window || 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0); const gamepads = environment === 'browser' && (!!navigator.getGamepads || !!navigator.webkitGetGamepads); const workers = typeof Worker !== 'undefined'; const passiveEvents = detectPassiveEvents(); const platform = { name: platformName, environment: environment, global: (_ref = (_ref2 = (_ref3 = typeof globalThis !== 'undefined' && globalThis) != null ? _ref3 : environment === 'browser' && window) != null ? _ref2 : environment === 'node' && global) != null ? _ref : environment === 'worker' && self, browser: environment === 'browser', worker: environment === 'worker', desktop: ['windows', 'osx', 'linux', 'cros'].includes(platformName), mobile: ['android', 'ios'].includes(platformName), ios: platformName === 'ios', android: platformName === 'android', xbox: xbox, gamepads: gamepads, touch: touch, workers: workers, passiveEvents: passiveEvents, browserName: browserName }; export { platform };