UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

49 lines (48 loc) 1.53 kB
import { getWindow } from "../../../ssr-window/ssr-window.esm.mjs"; import { getSupport } from "./get-support.mjs"; var device; function calcDevice(_temp) { var _ref = _temp === void 0 ? {} : _temp, userAgent = _ref.userAgent; var support = getSupport(); var window = getWindow(); var platform = window.navigator.platform; var ua = userAgent || window.navigator.userAgent; var device2 = { ios: false, android: false }; var screenWidth = window.screen.width; var screenHeight = window.screen.height; var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); 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"; var iPadScreens = ["1024x1366", "1366x1024", "834x1194", "1194x834", "834x1112", "1112x834", "768x1024", "1024x768"]; 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; } if (android && !windows) { device2.os = "android"; device2.android = true; } if (ipad || iphone || ipod) { device2.os = "ios"; device2.ios = true; } return device2; } function getDevice(overrides) { if (overrides === void 0) { overrides = {}; } if (!device) { device = calcDevice(overrides); } return device; } export { getDevice };