1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.getDevice = getDevice;
|
5 |
|
6 | var _ssrWindow = require("ssr-window");
|
7 |
|
8 | var _getSupport = require("./get-support");
|
9 |
|
10 | var device;
|
11 |
|
12 | function calcDevice(_temp) {
|
13 | var _ref = _temp === void 0 ? {} : _temp,
|
14 | userAgent = _ref.userAgent;
|
15 |
|
16 | var support = (0, _getSupport.getSupport)();
|
17 | var window = (0, _ssrWindow.getWindow)();
|
18 | var platform = window.navigator.platform;
|
19 | var ua = userAgent || window.navigator.userAgent;
|
20 | var device = {
|
21 | ios: false,
|
22 | android: false
|
23 | };
|
24 | var screenWidth = window.screen.width;
|
25 | var screenHeight = window.screen.height;
|
26 | var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
|
27 |
|
28 | var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
|
29 | var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
|
30 | var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
|
31 | var windows = platform === 'Win32';
|
32 | var macos = platform === 'MacIntel';
|
33 |
|
34 | var iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
|
35 |
|
36 | if (!ipad && macos && support.touch && iPadScreens.indexOf(screenWidth + "x" + screenHeight) >= 0) {
|
37 | ipad = ua.match(/(Version)\/([\d.]+)/);
|
38 | if (!ipad) ipad = [0, 1, '13_0_0'];
|
39 | macos = false;
|
40 | }
|
41 |
|
42 |
|
43 | if (android && !windows) {
|
44 | device.os = 'android';
|
45 | device.android = true;
|
46 | }
|
47 |
|
48 | if (ipad || iphone || ipod) {
|
49 | device.os = 'ios';
|
50 | device.ios = true;
|
51 | }
|
52 |
|
53 |
|
54 | return device;
|
55 | }
|
56 |
|
57 | function getDevice(overrides) {
|
58 | if (overrides === void 0) {
|
59 | overrides = {};
|
60 | }
|
61 |
|
62 | if (!device) {
|
63 | device = calcDevice(overrides);
|
64 | }
|
65 |
|
66 | return device;
|
67 | } |
\ | No newline at end of file |