UNPKG

infinity-forge

Version:
68 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDevice = getDevice; var window_1 = require("../ssr-window/window.js"); var get_support_1 = require("./get-support.js"); var deviceCached; function calcDevice(_a) { var _b = _a === void 0 ? {} : _a, userAgent = _b.userAgent; var support = (0, get_support_1.getSupport)(); var window = (0, window_1.getWindow)(); var platform = window.navigator.platform; var ua = userAgent || window.navigator.userAgent; var device = { ios: false, android: false, }; var screenWidth = window.screen.width; var screenHeight = window.screen.height; var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line var ipad = ua.match(/(iPad).*OS\s([\d_]+)/); var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/); var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/); var windows = platform === 'Win32'; var macos = platform === 'MacIntel'; // iPadOs 13 fix var iPadScreens = [ '1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810', ]; if (!ipad && macos && support.touch && iPadScreens.indexOf("".concat(screenWidth, "x").concat(screenHeight)) >= 0) { ipad = ua.match(/(Version)\/([\d.]+)/); if (!ipad) ipad = [0, 1, '13_0_0']; macos = false; } // Android if (android && !windows) { device.os = 'android'; device.android = true; } if (ipad || iphone || ipod) { device.os = 'ios'; device.ios = true; } // Export object return device; } function getDevice(overrides) { if (overrides === void 0) { overrides = {}; } if (!deviceCached) { deviceCached = calcDevice(overrides); } return deviceCached; } //# sourceMappingURL=get-device.js.map