67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
"use strict";
|
|
|
|
exports.__esModule = true;
|
|
exports.getDevice = getDevice;
|
|
|
|
var _ssrWindow = require("ssr-window");
|
|
|
|
var _getSupport = require("./get-support");
|
|
|
|
var device;
|
|
|
|
function calcDevice(_temp) {
|
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
userAgent = _ref.userAgent;
|
|
|
|
var support = (0, _getSupport.getSupport)();
|
|
var window = (0, _ssrWindow.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(screenWidth + "x" + 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 (!device) {
|
|
device = calcDevice(overrides);
|
|
}
|
|
|
|
return device;
|
|
} |