forked from duskload/react-device-detect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
841 lines (733 loc) · 24.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var React__default = _interopDefault(React);
var UAParser = require('ua-parser-js/dist/ua-parser.min');
var UA = new UAParser();
var browser = UA.getBrowser();
var cpu = UA.getCPU();
var device = UA.getDevice();
var engine = UA.getEngine();
var os = UA.getOS();
var ua = UA.getUA();
var setDefaults = function setDefaults(p) {
var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'none';
return p ? p : d;
};
var getNavigatorInstance = function getNavigatorInstance() {
if (typeof window !== 'undefined') {
if (window.navigator || navigator) {
return window.navigator || navigator;
}
}
return false;
};
var isIOS13Check = function isIOS13Check(type) {
var nav = getNavigatorInstance();
return nav && nav.platform && (nav.platform.indexOf(type) !== -1 || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 && !window.MSStream);
};
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
var DEVICE_TYPES = {
MOBILE: 'mobile',
TABLET: 'tablet',
SMART_TV: 'smarttv',
CONSOLE: 'console',
WEARABLE: 'wearable',
BROWSER: undefined
};
var BROWSER_TYPES = {
CHROME: 'Chrome',
FIREFOX: "Firefox",
OPERA: "Opera",
YANDEX: "Yandex",
SAFARI: "Safari",
INTERNET_EXPLORER: "Internet Explorer",
EDGE: "Edge",
CHROMIUM: "Chromium",
IE: 'IE',
MOBILE_SAFARI: "Mobile Safari",
EDGE_CHROMIUM: "Edge Chromium"
};
var OS_TYPES = {
IOS: 'iOS',
ANDROID: "Android",
WINDOWS_PHONE: "Windows Phone",
WINDOWS: 'Windows',
MAC_OS: 'Mac OS'
};
var initialData = {
isMobile: false,
isTablet: false,
isBrowser: false,
isSmartTV: false,
isConsole: false,
isWearable: false
};
var checkType = function checkType(type) {
switch (type) {
case DEVICE_TYPES.MOBILE:
return {
isMobile: true
};
case DEVICE_TYPES.TABLET:
return {
isTablet: true
};
case DEVICE_TYPES.SMART_TV:
return {
isSmartTV: true
};
case DEVICE_TYPES.CONSOLE:
return {
isConsole: true
};
case DEVICE_TYPES.WEARABLE:
return {
isWearable: true
};
case DEVICE_TYPES.BROWSER:
return {
isBrowser: true
};
default:
return initialData;
}
};
var broPayload = function broPayload(isBrowser, browser, engine, os, ua) {
return {
isBrowser: isBrowser,
browserMajorVersion: setDefaults(browser.major),
browserFullVersion: setDefaults(browser.version),
browserName: setDefaults(browser.name),
engineName: setDefaults(engine.name),
engineVersion: setDefaults(engine.version),
osName: setDefaults(os.name),
osVersion: setDefaults(os.version),
userAgent: setDefaults(ua)
};
};
var mobilePayload = function mobilePayload(type, device, os, ua) {
return _objectSpread2(_objectSpread2({}, type), {}, {
vendor: setDefaults(device.vendor),
model: setDefaults(device.model),
os: setDefaults(os.name),
osVersion: setDefaults(os.version),
ua: setDefaults(ua)
});
};
var stvPayload = function stvPayload(isSmartTV, engine, os, ua) {
return {
isSmartTV: isSmartTV,
engineName: setDefaults(engine.name),
engineVersion: setDefaults(engine.version),
osName: setDefaults(os.name),
osVersion: setDefaults(os.version),
userAgent: setDefaults(ua)
};
};
var consolePayload = function consolePayload(isConsole, engine, os, ua) {
return {
isConsole: isConsole,
engineName: setDefaults(engine.name),
engineVersion: setDefaults(engine.version),
osName: setDefaults(os.name),
osVersion: setDefaults(os.version),
userAgent: setDefaults(ua)
};
};
var wearPayload = function wearPayload(isWearable, engine, os, ua) {
return {
isWearable: isWearable,
engineName: setDefaults(engine.name),
engineVersion: setDefaults(engine.version),
osName: setDefaults(os.name),
osVersion: setDefaults(os.version),
userAgent: setDefaults(ua)
};
};
var type = checkType(device.type);
function deviceDetect() {
var isBrowser = type.isBrowser,
isMobile = type.isMobile,
isTablet = type.isTablet,
isSmartTV = type.isSmartTV,
isConsole = type.isConsole,
isWearable = type.isWearable;
if (isBrowser) {
return broPayload(isBrowser, browser, engine, os, ua);
}
if (isSmartTV) {
return stvPayload(isSmartTV, engine, os, ua);
}
if (isConsole) {
return consolePayload(isConsole, engine, os, ua);
}
if (isMobile) {
return mobilePayload(type, device, os, ua);
}
if (isTablet) {
return mobilePayload(type, device, os, ua);
}
if (isWearable) {
return wearPayload(isWearable, engine, os, ua);
}
}
var isMobileType = function isMobileType() {
return device.type === DEVICE_TYPES.MOBILE;
};
var isTabletType = function isTabletType() {
return device.type === DEVICE_TYPES.TABLET;
};
var isMobileAndTabletType = function isMobileAndTabletType() {
switch (device.type) {
case DEVICE_TYPES.MOBILE:
case DEVICE_TYPES.TABLET:
return true;
default:
return false;
}
};
var isEdgeChromiumType = function isEdgeChromiumType() {
if (os.name === OS_TYPES.WINDOWS && os.version === '10') {
return typeof ua === 'string' && ua.indexOf('Edg/') !== -1;
}
return false;
};
var isSmartTVType = function isSmartTVType() {
return device.type === DEVICE_TYPES.SMART_TV;
};
var isBrowserType = function isBrowserType() {
return device.type === DEVICE_TYPES.BROWSER;
};
var isWearableType = function isWearableType() {
return device.type === DEVICE_TYPES.WEARABLE;
};
var isConsoleType = function isConsoleType() {
return device.type === DEVICE_TYPES.CONSOLE;
};
var isAndroidType = function isAndroidType() {
return os.name === OS_TYPES.ANDROID;
};
var isWindowsType = function isWindowsType() {
return os.name === OS_TYPES.WINDOWS;
};
var isMacOsType = function isMacOsType() {
return os.name === OS_TYPES.MAC_OS;
};
var isWinPhoneType = function isWinPhoneType() {
return os.name === OS_TYPES.WINDOWS_PHONE;
};
var isIOSType = function isIOSType() {
return os.name === OS_TYPES.IOS;
};
var isChromeType = function isChromeType() {
return browser.name === BROWSER_TYPES.CHROME;
};
var isFirefoxType = function isFirefoxType() {
return browser.name === BROWSER_TYPES.FIREFOX;
};
var isChromiumType = function isChromiumType() {
return browser.name === BROWSER_TYPES.CHROMIUM;
};
var isEdgeType = function isEdgeType() {
return browser.name === BROWSER_TYPES.EDGE;
};
var isYandexType = function isYandexType() {
return browser.name === BROWSER_TYPES.YANDEX;
};
var isSafariType = function isSafariType() {
return browser.name === BROWSER_TYPES.SAFARI || browser.name === BROWSER_TYPES.MOBILE_SAFARI;
};
var isMobileSafariType = function isMobileSafariType() {
return browser.name === BROWSER_TYPES.MOBILE_SAFARI;
};
var isOperaType = function isOperaType() {
return browser.name === BROWSER_TYPES.OPERA;
};
var isIEType = function isIEType() {
return browser.name === BROWSER_TYPES.INTERNET_EXPLORER || browser.name === BROWSER_TYPES.IE;
};
var isElectronType = function isElectronType() {
var nav = getNavigatorInstance();
var ua = nav && nav.userAgent.toLowerCase();
return typeof ua === 'string' ? /electron/.test(ua) : false;
};
var getIOS13 = function getIOS13() {
var nav = getNavigatorInstance();
return nav && (/iPad|iPhone|iPod/.test(nav.platform) || nav.platform === 'MacIntel' && nav.maxTouchPoints > 1) && !window.MSStream;
};
var getIPad13 = function getIPad13() {
return isIOS13Check('iPad');
};
var getIphone13 = function getIphone13() {
return isIOS13Check('iPhone');
};
var getIPod13 = function getIPod13() {
return isIOS13Check('iPod');
};
var getBrowserFullVersion = function getBrowserFullVersion() {
return setDefaults(browser.version);
};
var getBrowserVersion = function getBrowserVersion() {
return setDefaults(browser.major);
};
var getOsVersion = function getOsVersion() {
return setDefaults(os.version);
};
var getOsName = function getOsName() {
return setDefaults(os.name);
};
var getBrowserName = function getBrowserName() {
return setDefaults(browser.name);
};
var getMobileVendor = function getMobileVendor() {
return setDefaults(device.vendor);
};
var getMobileModel = function getMobileModel() {
return setDefaults(device.model);
};
var getEngineName = function getEngineName() {
return setDefaults(engine.name);
};
var getEngineVersion = function getEngineVersion() {
return setDefaults(engine.version);
};
var getUseragent = function getUseragent() {
return setDefaults(ua);
};
var getDeviceType = function getDeviceType() {
return setDefaults(device.type, 'browser');
};
var isSmartTV = isSmartTVType();
var isConsole = isConsoleType();
var isWearable = isWearableType();
var isMobileSafari = isMobileSafariType() || getIPad13();
var isChromium = isChromiumType();
var isMobile = isMobileAndTabletType() || getIPad13();
var isMobileOnly = isMobileType();
var isTablet = isTabletType() || getIPad13();
var isBrowser = isBrowserType();
var isAndroid = isAndroidType();
var isWinPhone = isWinPhoneType();
var isIOS = isIOSType() || getIPad13();
var isChrome = isChromeType();
var isFirefox = isFirefoxType();
var isSafari = isSafariType();
var isOpera = isOperaType();
var isIE = isIEType();
var osVersion = getOsVersion();
var osName = getOsName();
var fullBrowserVersion = getBrowserFullVersion();
var browserVersion = getBrowserVersion();
var browserName = getBrowserName();
var mobileVendor = getMobileVendor();
var mobileModel = getMobileModel();
var engineName = getEngineName();
var engineVersion = getEngineVersion();
var getUA = getUseragent();
var isEdge = isEdgeType() || isEdgeChromiumType();
var isYandex = isYandexType();
var deviceType = getDeviceType();
var isIOS13 = getIOS13();
var isIPad13 = getIPad13();
var isIPhone13 = getIphone13();
var isIPod13 = getIPod13();
var isElectron = isElectronType();
var isEdgeChromium = isEdgeChromiumType();
var isLegacyEdge = isEdgeType();
var isWindows = isWindowsType();
var isMacOs = isMacOsType();
var AndroidView = function AndroidView(_ref) {
var renderWithFragment = _ref.renderWithFragment,
children = _ref.children,
viewClassName = _ref.viewClassName,
style = _ref.style;
return isAndroid ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var BrowserView = function BrowserView(_ref2) {
var renderWithFragment = _ref2.renderWithFragment,
children = _ref2.children,
viewClassName = _ref2.viewClassName,
style = _ref2.style;
return isBrowser ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var IEView = function IEView(_ref3) {
var renderWithFragment = _ref3.renderWithFragment,
children = _ref3.children,
viewClassName = _ref3.viewClassName,
style = _ref3.style;
return isIE ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var IOSView = function IOSView(_ref4) {
var renderWithFragment = _ref4.renderWithFragment,
children = _ref4.children,
viewClassName = _ref4.viewClassName,
style = _ref4.style;
return isIOS ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var MobileView = function MobileView(_ref5) {
var renderWithFragment = _ref5.renderWithFragment,
children = _ref5.children,
viewClassName = _ref5.viewClassName,
style = _ref5.style;
return isMobile ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var TabletView = function TabletView(_ref6) {
var renderWithFragment = _ref6.renderWithFragment,
children = _ref6.children,
viewClassName = _ref6.viewClassName,
style = _ref6.style;
return isTablet ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var WinPhoneView = function WinPhoneView(_ref7) {
var renderWithFragment = _ref7.renderWithFragment,
children = _ref7.children,
viewClassName = _ref7.viewClassName,
style = _ref7.style;
return isWinPhone ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var MobileOnlyView = function MobileOnlyView(_ref8) {
var renderWithFragment = _ref8.renderWithFragment,
children = _ref8.children,
viewClassName = _ref8.viewClassName,
style = _ref8.style;
return isMobileOnly ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var SmartTVView = function SmartTVView(_ref9) {
var renderWithFragment = _ref9.renderWithFragment,
children = _ref9.children,
viewClassName = _ref9.viewClassName,
style = _ref9.style;
return isSmartTV ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var ConsoleView = function ConsoleView(_ref10) {
var renderWithFragment = _ref10.renderWithFragment,
children = _ref10.children,
viewClassName = _ref10.viewClassName,
style = _ref10.style;
return isConsole ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var WearableView = function WearableView(_ref11) {
var renderWithFragment = _ref11.renderWithFragment,
children = _ref11.children,
viewClassName = _ref11.viewClassName,
style = _ref11.style;
return isWearable ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
var CustomView = function CustomView(_ref12) {
var renderWithFragment = _ref12.renderWithFragment,
children = _ref12.children,
viewClassName = _ref12.viewClassName,
style = _ref12.style,
condition = _ref12.condition;
return condition ? renderWithFragment ? /*#__PURE__*/React__default.createElement(React.Fragment, null, children) : /*#__PURE__*/React__default.createElement("div", {
className: viewClassName,
style: style
}, children) : null;
};
function withOrientationChange(WrappedComponent) {
return /*#__PURE__*/function (_React$Component) {
_inherits(_class, _React$Component);
var _super = _createSuper(_class);
function _class(props) {
var _this;
_classCallCheck(this, _class);
_this = _super.call(this, props);
_this.isEventListenerAdded = false;
_this.handleOrientationChange = _this.handleOrientationChange.bind(_assertThisInitialized(_this));
_this.onOrientationChange = _this.onOrientationChange.bind(_assertThisInitialized(_this));
_this.onPageLoad = _this.onPageLoad.bind(_assertThisInitialized(_this));
_this.state = {
isLandscape: false,
isPortrait: false
};
return _this;
}
_createClass(_class, [{
key: "handleOrientationChange",
value: function handleOrientationChange() {
if (!this.isEventListenerAdded) {
this.isEventListenerAdded = true;
}
var orientation = window.innerWidth > window.innerHeight ? 90 : 0;
this.setState({
isPortrait: orientation === 0,
isLandscape: orientation === 90
});
}
}, {
key: "onOrientationChange",
value: function onOrientationChange() {
this.handleOrientationChange();
}
}, {
key: "onPageLoad",
value: function onPageLoad() {
this.handleOrientationChange();
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined && isMobile) {
if (!this.isEventListenerAdded) {
this.handleOrientationChange();
window.addEventListener("load", this.onPageLoad, false);
} else {
window.removeEventListener("load", this.onPageLoad, false);
}
window.addEventListener("resize", this.onOrientationChange, false);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
window.removeEventListener("resize", this.onOrientationChange, false);
}
}, {
key: "render",
value: function render() {
return /*#__PURE__*/React__default.createElement(WrappedComponent, _extends({}, this.props, {
isLandscape: this.state.isLandscape,
isPortrait: this.state.isPortrait
}));
}
}]);
return _class;
}(React__default.Component);
}
exports.AndroidView = AndroidView;
exports.BrowserView = BrowserView;
exports.ConsoleView = ConsoleView;
exports.CustomView = CustomView;
exports.IEView = IEView;
exports.IOSView = IOSView;
exports.MobileOnlyView = MobileOnlyView;
exports.MobileView = MobileView;
exports.SmartTVView = SmartTVView;
exports.TabletView = TabletView;
exports.WearableView = WearableView;
exports.WinPhoneView = WinPhoneView;
exports.browserName = browserName;
exports.browserVersion = browserVersion;
exports.deviceDetect = deviceDetect;
exports.deviceType = deviceType;
exports.engineName = engineName;
exports.engineVersion = engineVersion;
exports.fullBrowserVersion = fullBrowserVersion;
exports.getUA = getUA;
exports.isAndroid = isAndroid;
exports.isBrowser = isBrowser;
exports.isChrome = isChrome;
exports.isChromium = isChromium;
exports.isConsole = isConsole;
exports.isEdge = isEdge;
exports.isEdgeChromium = isEdgeChromium;
exports.isElectron = isElectron;
exports.isFirefox = isFirefox;
exports.isIE = isIE;
exports.isIOS = isIOS;
exports.isIOS13 = isIOS13;
exports.isIPad13 = isIPad13;
exports.isIPhone13 = isIPhone13;
exports.isIPod13 = isIPod13;
exports.isLegacyEdge = isLegacyEdge;
exports.isMacOs = isMacOs;
exports.isMobile = isMobile;
exports.isMobileOnly = isMobileOnly;
exports.isMobileSafari = isMobileSafari;
exports.isOpera = isOpera;
exports.isSafari = isSafari;
exports.isSmartTV = isSmartTV;
exports.isTablet = isTablet;
exports.isWearable = isWearable;
exports.isWinPhone = isWinPhone;
exports.isWindows = isWindows;
exports.isYandex = isYandex;
exports.mobileModel = mobileModel;
exports.mobileVendor = mobileVendor;
exports.osName = osName;
exports.osVersion = osVersion;
exports.withOrientationChange = withOrientationChange;