@vitessce/export-utils 2.0.3-beta.0 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,2113 @@
1
+ const BROWSER_ALIASES_MAP = {
2
+ "Amazon Silk": "amazon_silk",
3
+ "Android Browser": "android",
4
+ Bada: "bada",
5
+ BlackBerry: "blackberry",
6
+ Chrome: "chrome",
7
+ Chromium: "chromium",
8
+ Electron: "electron",
9
+ Epiphany: "epiphany",
10
+ Firefox: "firefox",
11
+ Focus: "focus",
12
+ Generic: "generic",
13
+ "Google Search": "google_search",
14
+ Googlebot: "googlebot",
15
+ "Internet Explorer": "ie",
16
+ "K-Meleon": "k_meleon",
17
+ Maxthon: "maxthon",
18
+ "Microsoft Edge": "edge",
19
+ "MZ Browser": "mz",
20
+ "NAVER Whale Browser": "naver",
21
+ Opera: "opera",
22
+ "Opera Coast": "opera_coast",
23
+ PhantomJS: "phantomjs",
24
+ Puffin: "puffin",
25
+ QupZilla: "qupzilla",
26
+ QQ: "qq",
27
+ QQLite: "qqlite",
28
+ Safari: "safari",
29
+ Sailfish: "sailfish",
30
+ "Samsung Internet for Android": "samsung_internet",
31
+ SeaMonkey: "seamonkey",
32
+ Sleipnir: "sleipnir",
33
+ Swing: "swing",
34
+ Tizen: "tizen",
35
+ "UC Browser": "uc",
36
+ Vivaldi: "vivaldi",
37
+ "WebOS Browser": "webos",
38
+ WeChat: "wechat",
39
+ "Yandex Browser": "yandex",
40
+ Roku: "roku"
41
+ };
42
+ const BROWSER_MAP = {
43
+ amazon_silk: "Amazon Silk",
44
+ android: "Android Browser",
45
+ bada: "Bada",
46
+ blackberry: "BlackBerry",
47
+ chrome: "Chrome",
48
+ chromium: "Chromium",
49
+ electron: "Electron",
50
+ epiphany: "Epiphany",
51
+ firefox: "Firefox",
52
+ focus: "Focus",
53
+ generic: "Generic",
54
+ googlebot: "Googlebot",
55
+ google_search: "Google Search",
56
+ ie: "Internet Explorer",
57
+ k_meleon: "K-Meleon",
58
+ maxthon: "Maxthon",
59
+ edge: "Microsoft Edge",
60
+ mz: "MZ Browser",
61
+ naver: "NAVER Whale Browser",
62
+ opera: "Opera",
63
+ opera_coast: "Opera Coast",
64
+ phantomjs: "PhantomJS",
65
+ puffin: "Puffin",
66
+ qupzilla: "QupZilla",
67
+ qq: "QQ Browser",
68
+ qqlite: "QQ Browser Lite",
69
+ safari: "Safari",
70
+ sailfish: "Sailfish",
71
+ samsung_internet: "Samsung Internet for Android",
72
+ seamonkey: "SeaMonkey",
73
+ sleipnir: "Sleipnir",
74
+ swing: "Swing",
75
+ tizen: "Tizen",
76
+ uc: "UC Browser",
77
+ vivaldi: "Vivaldi",
78
+ webos: "WebOS Browser",
79
+ wechat: "WeChat",
80
+ yandex: "Yandex Browser"
81
+ };
82
+ const PLATFORMS_MAP = {
83
+ tablet: "tablet",
84
+ mobile: "mobile",
85
+ desktop: "desktop",
86
+ tv: "tv"
87
+ };
88
+ const OS_MAP = {
89
+ WindowsPhone: "Windows Phone",
90
+ Windows: "Windows",
91
+ MacOS: "macOS",
92
+ iOS: "iOS",
93
+ Android: "Android",
94
+ WebOS: "WebOS",
95
+ BlackBerry: "BlackBerry",
96
+ Bada: "Bada",
97
+ Tizen: "Tizen",
98
+ Linux: "Linux",
99
+ ChromeOS: "Chrome OS",
100
+ PlayStation4: "PlayStation 4",
101
+ Roku: "Roku"
102
+ };
103
+ const ENGINE_MAP = {
104
+ EdgeHTML: "EdgeHTML",
105
+ Blink: "Blink",
106
+ Trident: "Trident",
107
+ Presto: "Presto",
108
+ Gecko: "Gecko",
109
+ WebKit: "WebKit"
110
+ };
111
+ class Utils {
112
+ static getFirstMatch(regexp, ua) {
113
+ const match = ua.match(regexp);
114
+ return match && match.length > 0 && match[1] || "";
115
+ }
116
+ static getSecondMatch(regexp, ua) {
117
+ const match = ua.match(regexp);
118
+ return match && match.length > 1 && match[2] || "";
119
+ }
120
+ static matchAndReturnConst(regexp, ua, _const) {
121
+ if (regexp.test(ua)) {
122
+ return _const;
123
+ }
124
+ return void 0;
125
+ }
126
+ static getWindowsVersionName(version) {
127
+ switch (version) {
128
+ case "NT":
129
+ return "NT";
130
+ case "XP":
131
+ return "XP";
132
+ case "NT 5.0":
133
+ return "2000";
134
+ case "NT 5.1":
135
+ return "XP";
136
+ case "NT 5.2":
137
+ return "2003";
138
+ case "NT 6.0":
139
+ return "Vista";
140
+ case "NT 6.1":
141
+ return "7";
142
+ case "NT 6.2":
143
+ return "8";
144
+ case "NT 6.3":
145
+ return "8.1";
146
+ case "NT 10.0":
147
+ return "10";
148
+ default:
149
+ return void 0;
150
+ }
151
+ }
152
+ static getMacOSVersionName(version) {
153
+ const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
154
+ v.push(0);
155
+ if (v[0] !== 10)
156
+ return void 0;
157
+ switch (v[1]) {
158
+ case 5:
159
+ return "Leopard";
160
+ case 6:
161
+ return "Snow Leopard";
162
+ case 7:
163
+ return "Lion";
164
+ case 8:
165
+ return "Mountain Lion";
166
+ case 9:
167
+ return "Mavericks";
168
+ case 10:
169
+ return "Yosemite";
170
+ case 11:
171
+ return "El Capitan";
172
+ case 12:
173
+ return "Sierra";
174
+ case 13:
175
+ return "High Sierra";
176
+ case 14:
177
+ return "Mojave";
178
+ case 15:
179
+ return "Catalina";
180
+ default:
181
+ return void 0;
182
+ }
183
+ }
184
+ static getAndroidVersionName(version) {
185
+ const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
186
+ v.push(0);
187
+ if (v[0] === 1 && v[1] < 5)
188
+ return void 0;
189
+ if (v[0] === 1 && v[1] < 6)
190
+ return "Cupcake";
191
+ if (v[0] === 1 && v[1] >= 6)
192
+ return "Donut";
193
+ if (v[0] === 2 && v[1] < 2)
194
+ return "Eclair";
195
+ if (v[0] === 2 && v[1] === 2)
196
+ return "Froyo";
197
+ if (v[0] === 2 && v[1] > 2)
198
+ return "Gingerbread";
199
+ if (v[0] === 3)
200
+ return "Honeycomb";
201
+ if (v[0] === 4 && v[1] < 1)
202
+ return "Ice Cream Sandwich";
203
+ if (v[0] === 4 && v[1] < 4)
204
+ return "Jelly Bean";
205
+ if (v[0] === 4 && v[1] >= 4)
206
+ return "KitKat";
207
+ if (v[0] === 5)
208
+ return "Lollipop";
209
+ if (v[0] === 6)
210
+ return "Marshmallow";
211
+ if (v[0] === 7)
212
+ return "Nougat";
213
+ if (v[0] === 8)
214
+ return "Oreo";
215
+ if (v[0] === 9)
216
+ return "Pie";
217
+ return void 0;
218
+ }
219
+ static getVersionPrecision(version) {
220
+ return version.split(".").length;
221
+ }
222
+ static compareVersions(versionA, versionB, isLoose = false) {
223
+ const versionAPrecision = Utils.getVersionPrecision(versionA);
224
+ const versionBPrecision = Utils.getVersionPrecision(versionB);
225
+ let precision = Math.max(versionAPrecision, versionBPrecision);
226
+ let lastPrecision = 0;
227
+ const chunks = Utils.map([versionA, versionB], (version) => {
228
+ const delta = precision - Utils.getVersionPrecision(version);
229
+ const _version = version + new Array(delta + 1).join(".0");
230
+ return Utils.map(_version.split("."), (chunk) => new Array(20 - chunk.length).join("0") + chunk).reverse();
231
+ });
232
+ if (isLoose) {
233
+ lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision);
234
+ }
235
+ precision -= 1;
236
+ while (precision >= lastPrecision) {
237
+ if (chunks[0][precision] > chunks[1][precision]) {
238
+ return 1;
239
+ }
240
+ if (chunks[0][precision] === chunks[1][precision]) {
241
+ if (precision === lastPrecision) {
242
+ return 0;
243
+ }
244
+ precision -= 1;
245
+ } else if (chunks[0][precision] < chunks[1][precision]) {
246
+ return -1;
247
+ }
248
+ }
249
+ return void 0;
250
+ }
251
+ static map(arr, iterator) {
252
+ const result = [];
253
+ let i;
254
+ if (Array.prototype.map) {
255
+ return Array.prototype.map.call(arr, iterator);
256
+ }
257
+ for (i = 0; i < arr.length; i += 1) {
258
+ result.push(iterator(arr[i]));
259
+ }
260
+ return result;
261
+ }
262
+ static find(arr, predicate) {
263
+ let i;
264
+ let l;
265
+ if (Array.prototype.find) {
266
+ return Array.prototype.find.call(arr, predicate);
267
+ }
268
+ for (i = 0, l = arr.length; i < l; i += 1) {
269
+ const value = arr[i];
270
+ if (predicate(value, i)) {
271
+ return value;
272
+ }
273
+ }
274
+ return void 0;
275
+ }
276
+ static assign(obj, ...assigners) {
277
+ const result = obj;
278
+ let i;
279
+ let l;
280
+ if (Object.assign) {
281
+ return Object.assign(obj, ...assigners);
282
+ }
283
+ for (i = 0, l = assigners.length; i < l; i += 1) {
284
+ const assigner = assigners[i];
285
+ if (typeof assigner === "object" && assigner !== null) {
286
+ const keys = Object.keys(assigner);
287
+ keys.forEach((key) => {
288
+ result[key] = assigner[key];
289
+ });
290
+ }
291
+ }
292
+ return obj;
293
+ }
294
+ static getBrowserAlias(browserName) {
295
+ return BROWSER_ALIASES_MAP[browserName];
296
+ }
297
+ static getBrowserTypeByAlias(browserAlias) {
298
+ return BROWSER_MAP[browserAlias] || "";
299
+ }
300
+ }
301
+ const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
302
+ const browsersList = [
303
+ {
304
+ test: [/googlebot/i],
305
+ describe(ua) {
306
+ const browser = {
307
+ name: "Googlebot"
308
+ };
309
+ const version = Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
310
+ if (version) {
311
+ browser.version = version;
312
+ }
313
+ return browser;
314
+ }
315
+ },
316
+ {
317
+ test: [/opera/i],
318
+ describe(ua) {
319
+ const browser = {
320
+ name: "Opera"
321
+ };
322
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua);
323
+ if (version) {
324
+ browser.version = version;
325
+ }
326
+ return browser;
327
+ }
328
+ },
329
+ {
330
+ test: [/opr\/|opios/i],
331
+ describe(ua) {
332
+ const browser = {
333
+ name: "Opera"
334
+ };
335
+ const version = Utils.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
336
+ if (version) {
337
+ browser.version = version;
338
+ }
339
+ return browser;
340
+ }
341
+ },
342
+ {
343
+ test: [/SamsungBrowser/i],
344
+ describe(ua) {
345
+ const browser = {
346
+ name: "Samsung Internet for Android"
347
+ };
348
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
349
+ if (version) {
350
+ browser.version = version;
351
+ }
352
+ return browser;
353
+ }
354
+ },
355
+ {
356
+ test: [/Whale/i],
357
+ describe(ua) {
358
+ const browser = {
359
+ name: "NAVER Whale Browser"
360
+ };
361
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i, ua);
362
+ if (version) {
363
+ browser.version = version;
364
+ }
365
+ return browser;
366
+ }
367
+ },
368
+ {
369
+ test: [/MZBrowser/i],
370
+ describe(ua) {
371
+ const browser = {
372
+ name: "MZ Browser"
373
+ };
374
+ const version = Utils.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
375
+ if (version) {
376
+ browser.version = version;
377
+ }
378
+ return browser;
379
+ }
380
+ },
381
+ {
382
+ test: [/focus/i],
383
+ describe(ua) {
384
+ const browser = {
385
+ name: "Focus"
386
+ };
387
+ const version = Utils.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
388
+ if (version) {
389
+ browser.version = version;
390
+ }
391
+ return browser;
392
+ }
393
+ },
394
+ {
395
+ test: [/swing/i],
396
+ describe(ua) {
397
+ const browser = {
398
+ name: "Swing"
399
+ };
400
+ const version = Utils.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
401
+ if (version) {
402
+ browser.version = version;
403
+ }
404
+ return browser;
405
+ }
406
+ },
407
+ {
408
+ test: [/coast/i],
409
+ describe(ua) {
410
+ const browser = {
411
+ name: "Opera Coast"
412
+ };
413
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua);
414
+ if (version) {
415
+ browser.version = version;
416
+ }
417
+ return browser;
418
+ }
419
+ },
420
+ {
421
+ test: [/opt\/\d+(?:.?_?\d+)+/i],
422
+ describe(ua) {
423
+ const browser = {
424
+ name: "Opera Touch"
425
+ };
426
+ const version = Utils.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
427
+ if (version) {
428
+ browser.version = version;
429
+ }
430
+ return browser;
431
+ }
432
+ },
433
+ {
434
+ test: [/yabrowser/i],
435
+ describe(ua) {
436
+ const browser = {
437
+ name: "Yandex Browser"
438
+ };
439
+ const version = Utils.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
440
+ if (version) {
441
+ browser.version = version;
442
+ }
443
+ return browser;
444
+ }
445
+ },
446
+ {
447
+ test: [/ucbrowser/i],
448
+ describe(ua) {
449
+ const browser = {
450
+ name: "UC Browser"
451
+ };
452
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
453
+ if (version) {
454
+ browser.version = version;
455
+ }
456
+ return browser;
457
+ }
458
+ },
459
+ {
460
+ test: [/Maxthon|mxios/i],
461
+ describe(ua) {
462
+ const browser = {
463
+ name: "Maxthon"
464
+ };
465
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
466
+ if (version) {
467
+ browser.version = version;
468
+ }
469
+ return browser;
470
+ }
471
+ },
472
+ {
473
+ test: [/epiphany/i],
474
+ describe(ua) {
475
+ const browser = {
476
+ name: "Epiphany"
477
+ };
478
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua);
479
+ if (version) {
480
+ browser.version = version;
481
+ }
482
+ return browser;
483
+ }
484
+ },
485
+ {
486
+ test: [/puffin/i],
487
+ describe(ua) {
488
+ const browser = {
489
+ name: "Puffin"
490
+ };
491
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua);
492
+ if (version) {
493
+ browser.version = version;
494
+ }
495
+ return browser;
496
+ }
497
+ },
498
+ {
499
+ test: [/sleipnir/i],
500
+ describe(ua) {
501
+ const browser = {
502
+ name: "Sleipnir"
503
+ };
504
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua);
505
+ if (version) {
506
+ browser.version = version;
507
+ }
508
+ return browser;
509
+ }
510
+ },
511
+ {
512
+ test: [/k-meleon/i],
513
+ describe(ua) {
514
+ const browser = {
515
+ name: "K-Meleon"
516
+ };
517
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua);
518
+ if (version) {
519
+ browser.version = version;
520
+ }
521
+ return browser;
522
+ }
523
+ },
524
+ {
525
+ test: [/micromessenger/i],
526
+ describe(ua) {
527
+ const browser = {
528
+ name: "WeChat"
529
+ };
530
+ const version = Utils.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
531
+ if (version) {
532
+ browser.version = version;
533
+ }
534
+ return browser;
535
+ }
536
+ },
537
+ {
538
+ test: [/qqbrowser/i],
539
+ describe(ua) {
540
+ const browser = {
541
+ name: /qqbrowserlite/i.test(ua) ? "QQ Browser Lite" : "QQ Browser"
542
+ };
543
+ const version = Utils.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
544
+ if (version) {
545
+ browser.version = version;
546
+ }
547
+ return browser;
548
+ }
549
+ },
550
+ {
551
+ test: [/msie|trident/i],
552
+ describe(ua) {
553
+ const browser = {
554
+ name: "Internet Explorer"
555
+ };
556
+ const version = Utils.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua);
557
+ if (version) {
558
+ browser.version = version;
559
+ }
560
+ return browser;
561
+ }
562
+ },
563
+ {
564
+ test: [/\sedg\//i],
565
+ describe(ua) {
566
+ const browser = {
567
+ name: "Microsoft Edge"
568
+ };
569
+ const version = Utils.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i, ua);
570
+ if (version) {
571
+ browser.version = version;
572
+ }
573
+ return browser;
574
+ }
575
+ },
576
+ {
577
+ test: [/edg([ea]|ios)/i],
578
+ describe(ua) {
579
+ const browser = {
580
+ name: "Microsoft Edge"
581
+ };
582
+ const version = Utils.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua);
583
+ if (version) {
584
+ browser.version = version;
585
+ }
586
+ return browser;
587
+ }
588
+ },
589
+ {
590
+ test: [/vivaldi/i],
591
+ describe(ua) {
592
+ const browser = {
593
+ name: "Vivaldi"
594
+ };
595
+ const version = Utils.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua);
596
+ if (version) {
597
+ browser.version = version;
598
+ }
599
+ return browser;
600
+ }
601
+ },
602
+ {
603
+ test: [/seamonkey/i],
604
+ describe(ua) {
605
+ const browser = {
606
+ name: "SeaMonkey"
607
+ };
608
+ const version = Utils.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua);
609
+ if (version) {
610
+ browser.version = version;
611
+ }
612
+ return browser;
613
+ }
614
+ },
615
+ {
616
+ test: [/sailfish/i],
617
+ describe(ua) {
618
+ const browser = {
619
+ name: "Sailfish"
620
+ };
621
+ const version = Utils.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua);
622
+ if (version) {
623
+ browser.version = version;
624
+ }
625
+ return browser;
626
+ }
627
+ },
628
+ {
629
+ test: [/silk/i],
630
+ describe(ua) {
631
+ const browser = {
632
+ name: "Amazon Silk"
633
+ };
634
+ const version = Utils.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua);
635
+ if (version) {
636
+ browser.version = version;
637
+ }
638
+ return browser;
639
+ }
640
+ },
641
+ {
642
+ test: [/phantom/i],
643
+ describe(ua) {
644
+ const browser = {
645
+ name: "PhantomJS"
646
+ };
647
+ const version = Utils.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua);
648
+ if (version) {
649
+ browser.version = version;
650
+ }
651
+ return browser;
652
+ }
653
+ },
654
+ {
655
+ test: [/slimerjs/i],
656
+ describe(ua) {
657
+ const browser = {
658
+ name: "SlimerJS"
659
+ };
660
+ const version = Utils.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua);
661
+ if (version) {
662
+ browser.version = version;
663
+ }
664
+ return browser;
665
+ }
666
+ },
667
+ {
668
+ test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
669
+ describe(ua) {
670
+ const browser = {
671
+ name: "BlackBerry"
672
+ };
673
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua);
674
+ if (version) {
675
+ browser.version = version;
676
+ }
677
+ return browser;
678
+ }
679
+ },
680
+ {
681
+ test: [/(web|hpw)[o0]s/i],
682
+ describe(ua) {
683
+ const browser = {
684
+ name: "WebOS Browser"
685
+ };
686
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i, ua);
687
+ if (version) {
688
+ browser.version = version;
689
+ }
690
+ return browser;
691
+ }
692
+ },
693
+ {
694
+ test: [/bada/i],
695
+ describe(ua) {
696
+ const browser = {
697
+ name: "Bada"
698
+ };
699
+ const version = Utils.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua);
700
+ if (version) {
701
+ browser.version = version;
702
+ }
703
+ return browser;
704
+ }
705
+ },
706
+ {
707
+ test: [/tizen/i],
708
+ describe(ua) {
709
+ const browser = {
710
+ name: "Tizen"
711
+ };
712
+ const version = Utils.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
713
+ if (version) {
714
+ browser.version = version;
715
+ }
716
+ return browser;
717
+ }
718
+ },
719
+ {
720
+ test: [/qupzilla/i],
721
+ describe(ua) {
722
+ const browser = {
723
+ name: "QupZilla"
724
+ };
725
+ const version = Utils.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
726
+ if (version) {
727
+ browser.version = version;
728
+ }
729
+ return browser;
730
+ }
731
+ },
732
+ {
733
+ test: [/firefox|iceweasel|fxios/i],
734
+ describe(ua) {
735
+ const browser = {
736
+ name: "Firefox"
737
+ };
738
+ const version = Utils.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
739
+ if (version) {
740
+ browser.version = version;
741
+ }
742
+ return browser;
743
+ }
744
+ },
745
+ {
746
+ test: [/electron/i],
747
+ describe(ua) {
748
+ const browser = {
749
+ name: "Electron"
750
+ };
751
+ const version = Utils.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i, ua);
752
+ if (version) {
753
+ browser.version = version;
754
+ }
755
+ return browser;
756
+ }
757
+ },
758
+ {
759
+ test: [/MiuiBrowser/i],
760
+ describe(ua) {
761
+ const browser = {
762
+ name: "Miui"
763
+ };
764
+ const version = Utils.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
765
+ if (version) {
766
+ browser.version = version;
767
+ }
768
+ return browser;
769
+ }
770
+ },
771
+ {
772
+ test: [/chromium/i],
773
+ describe(ua) {
774
+ const browser = {
775
+ name: "Chromium"
776
+ };
777
+ const version = Utils.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
778
+ if (version) {
779
+ browser.version = version;
780
+ }
781
+ return browser;
782
+ }
783
+ },
784
+ {
785
+ test: [/chrome|crios|crmo/i],
786
+ describe(ua) {
787
+ const browser = {
788
+ name: "Chrome"
789
+ };
790
+ const version = Utils.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua);
791
+ if (version) {
792
+ browser.version = version;
793
+ }
794
+ return browser;
795
+ }
796
+ },
797
+ {
798
+ test: [/GSA/i],
799
+ describe(ua) {
800
+ const browser = {
801
+ name: "Google Search"
802
+ };
803
+ const version = Utils.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i, ua);
804
+ if (version) {
805
+ browser.version = version;
806
+ }
807
+ return browser;
808
+ }
809
+ },
810
+ {
811
+ test(parser) {
812
+ const notLikeAndroid = !parser.test(/like android/i);
813
+ const butAndroid = parser.test(/android/i);
814
+ return notLikeAndroid && butAndroid;
815
+ },
816
+ describe(ua) {
817
+ const browser = {
818
+ name: "Android Browser"
819
+ };
820
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
821
+ if (version) {
822
+ browser.version = version;
823
+ }
824
+ return browser;
825
+ }
826
+ },
827
+ {
828
+ test: [/playstation 4/i],
829
+ describe(ua) {
830
+ const browser = {
831
+ name: "PlayStation 4"
832
+ };
833
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
834
+ if (version) {
835
+ browser.version = version;
836
+ }
837
+ return browser;
838
+ }
839
+ },
840
+ {
841
+ test: [/safari|applewebkit/i],
842
+ describe(ua) {
843
+ const browser = {
844
+ name: "Safari"
845
+ };
846
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
847
+ if (version) {
848
+ browser.version = version;
849
+ }
850
+ return browser;
851
+ }
852
+ },
853
+ {
854
+ test: [/.*/i],
855
+ describe(ua) {
856
+ const regexpWithoutDeviceSpec = /^(.*)\/(.*) /;
857
+ const regexpWithDeviceSpec = /^(.*)\/(.*)[ \t]\((.*)/;
858
+ const hasDeviceSpec = ua.search("\\(") !== -1;
859
+ const regexp = hasDeviceSpec ? regexpWithDeviceSpec : regexpWithoutDeviceSpec;
860
+ return {
861
+ name: Utils.getFirstMatch(regexp, ua),
862
+ version: Utils.getSecondMatch(regexp, ua)
863
+ };
864
+ }
865
+ }
866
+ ];
867
+ const osParsersList = [
868
+ {
869
+ test: [/Roku\/DVP/],
870
+ describe(ua) {
871
+ const version = Utils.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua);
872
+ return {
873
+ name: OS_MAP.Roku,
874
+ version
875
+ };
876
+ }
877
+ },
878
+ {
879
+ test: [/windows phone/i],
880
+ describe(ua) {
881
+ const version = Utils.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
882
+ return {
883
+ name: OS_MAP.WindowsPhone,
884
+ version
885
+ };
886
+ }
887
+ },
888
+ {
889
+ test: [/windows /i],
890
+ describe(ua) {
891
+ const version = Utils.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
892
+ const versionName = Utils.getWindowsVersionName(version);
893
+ return {
894
+ name: OS_MAP.Windows,
895
+ version,
896
+ versionName
897
+ };
898
+ }
899
+ },
900
+ {
901
+ test: [/Macintosh(.*?) FxiOS(.*?)\//],
902
+ describe(ua) {
903
+ const result = {
904
+ name: OS_MAP.iOS
905
+ };
906
+ const version = Utils.getSecondMatch(/(Version\/)(\d[\d.]+)/, ua);
907
+ if (version) {
908
+ result.version = version;
909
+ }
910
+ return result;
911
+ }
912
+ },
913
+ {
914
+ test: [/macintosh/i],
915
+ describe(ua) {
916
+ const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, ".");
917
+ const versionName = Utils.getMacOSVersionName(version);
918
+ const os = {
919
+ name: OS_MAP.MacOS,
920
+ version
921
+ };
922
+ if (versionName) {
923
+ os.versionName = versionName;
924
+ }
925
+ return os;
926
+ }
927
+ },
928
+ {
929
+ test: [/(ipod|iphone|ipad)/i],
930
+ describe(ua) {
931
+ const version = Utils.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, ".");
932
+ return {
933
+ name: OS_MAP.iOS,
934
+ version
935
+ };
936
+ }
937
+ },
938
+ {
939
+ test(parser) {
940
+ const notLikeAndroid = !parser.test(/like android/i);
941
+ const butAndroid = parser.test(/android/i);
942
+ return notLikeAndroid && butAndroid;
943
+ },
944
+ describe(ua) {
945
+ const version = Utils.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
946
+ const versionName = Utils.getAndroidVersionName(version);
947
+ const os = {
948
+ name: OS_MAP.Android,
949
+ version
950
+ };
951
+ if (versionName) {
952
+ os.versionName = versionName;
953
+ }
954
+ return os;
955
+ }
956
+ },
957
+ {
958
+ test: [/(web|hpw)[o0]s/i],
959
+ describe(ua) {
960
+ const version = Utils.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
961
+ const os = {
962
+ name: OS_MAP.WebOS
963
+ };
964
+ if (version && version.length) {
965
+ os.version = version;
966
+ }
967
+ return os;
968
+ }
969
+ },
970
+ {
971
+ test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
972
+ describe(ua) {
973
+ const version = Utils.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua) || Utils.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua) || Utils.getFirstMatch(/\bbb(\d+)/i, ua);
974
+ return {
975
+ name: OS_MAP.BlackBerry,
976
+ version
977
+ };
978
+ }
979
+ },
980
+ {
981
+ test: [/bada/i],
982
+ describe(ua) {
983
+ const version = Utils.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
984
+ return {
985
+ name: OS_MAP.Bada,
986
+ version
987
+ };
988
+ }
989
+ },
990
+ {
991
+ test: [/tizen/i],
992
+ describe(ua) {
993
+ const version = Utils.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
994
+ return {
995
+ name: OS_MAP.Tizen,
996
+ version
997
+ };
998
+ }
999
+ },
1000
+ {
1001
+ test: [/linux/i],
1002
+ describe() {
1003
+ return {
1004
+ name: OS_MAP.Linux
1005
+ };
1006
+ }
1007
+ },
1008
+ {
1009
+ test: [/CrOS/],
1010
+ describe() {
1011
+ return {
1012
+ name: OS_MAP.ChromeOS
1013
+ };
1014
+ }
1015
+ },
1016
+ {
1017
+ test: [/PlayStation 4/],
1018
+ describe(ua) {
1019
+ const version = Utils.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
1020
+ return {
1021
+ name: OS_MAP.PlayStation4,
1022
+ version
1023
+ };
1024
+ }
1025
+ }
1026
+ ];
1027
+ const platformParsersList = [
1028
+ {
1029
+ test: [/googlebot/i],
1030
+ describe() {
1031
+ return {
1032
+ type: "bot",
1033
+ vendor: "Google"
1034
+ };
1035
+ }
1036
+ },
1037
+ {
1038
+ test: [/huawei/i],
1039
+ describe(ua) {
1040
+ const model = Utils.getFirstMatch(/(can-l01)/i, ua) && "Nova";
1041
+ const platform = {
1042
+ type: PLATFORMS_MAP.mobile,
1043
+ vendor: "Huawei"
1044
+ };
1045
+ if (model) {
1046
+ platform.model = model;
1047
+ }
1048
+ return platform;
1049
+ }
1050
+ },
1051
+ {
1052
+ test: [/nexus\s*(?:7|8|9|10).*/i],
1053
+ describe() {
1054
+ return {
1055
+ type: PLATFORMS_MAP.tablet,
1056
+ vendor: "Nexus"
1057
+ };
1058
+ }
1059
+ },
1060
+ {
1061
+ test: [/ipad/i],
1062
+ describe() {
1063
+ return {
1064
+ type: PLATFORMS_MAP.tablet,
1065
+ vendor: "Apple",
1066
+ model: "iPad"
1067
+ };
1068
+ }
1069
+ },
1070
+ {
1071
+ test: [/Macintosh(.*?) FxiOS(.*?)\//],
1072
+ describe() {
1073
+ return {
1074
+ type: PLATFORMS_MAP.tablet,
1075
+ vendor: "Apple",
1076
+ model: "iPad"
1077
+ };
1078
+ }
1079
+ },
1080
+ {
1081
+ test: [/kftt build/i],
1082
+ describe() {
1083
+ return {
1084
+ type: PLATFORMS_MAP.tablet,
1085
+ vendor: "Amazon",
1086
+ model: "Kindle Fire HD 7"
1087
+ };
1088
+ }
1089
+ },
1090
+ {
1091
+ test: [/silk/i],
1092
+ describe() {
1093
+ return {
1094
+ type: PLATFORMS_MAP.tablet,
1095
+ vendor: "Amazon"
1096
+ };
1097
+ }
1098
+ },
1099
+ {
1100
+ test: [/tablet(?! pc)/i],
1101
+ describe() {
1102
+ return {
1103
+ type: PLATFORMS_MAP.tablet
1104
+ };
1105
+ }
1106
+ },
1107
+ {
1108
+ test(parser) {
1109
+ const iDevice = parser.test(/ipod|iphone/i);
1110
+ const likeIDevice = parser.test(/like (ipod|iphone)/i);
1111
+ return iDevice && !likeIDevice;
1112
+ },
1113
+ describe(ua) {
1114
+ const model = Utils.getFirstMatch(/(ipod|iphone)/i, ua);
1115
+ return {
1116
+ type: PLATFORMS_MAP.mobile,
1117
+ vendor: "Apple",
1118
+ model
1119
+ };
1120
+ }
1121
+ },
1122
+ {
1123
+ test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
1124
+ describe() {
1125
+ return {
1126
+ type: PLATFORMS_MAP.mobile,
1127
+ vendor: "Nexus"
1128
+ };
1129
+ }
1130
+ },
1131
+ {
1132
+ test: [/[^-]mobi/i],
1133
+ describe() {
1134
+ return {
1135
+ type: PLATFORMS_MAP.mobile
1136
+ };
1137
+ }
1138
+ },
1139
+ {
1140
+ test(parser) {
1141
+ return parser.getBrowserName(true) === "blackberry";
1142
+ },
1143
+ describe() {
1144
+ return {
1145
+ type: PLATFORMS_MAP.mobile,
1146
+ vendor: "BlackBerry"
1147
+ };
1148
+ }
1149
+ },
1150
+ {
1151
+ test(parser) {
1152
+ return parser.getBrowserName(true) === "bada";
1153
+ },
1154
+ describe() {
1155
+ return {
1156
+ type: PLATFORMS_MAP.mobile
1157
+ };
1158
+ }
1159
+ },
1160
+ {
1161
+ test(parser) {
1162
+ return parser.getBrowserName() === "windows phone";
1163
+ },
1164
+ describe() {
1165
+ return {
1166
+ type: PLATFORMS_MAP.mobile,
1167
+ vendor: "Microsoft"
1168
+ };
1169
+ }
1170
+ },
1171
+ {
1172
+ test(parser) {
1173
+ const osMajorVersion = Number(String(parser.getOSVersion()).split(".")[0]);
1174
+ return parser.getOSName(true) === "android" && osMajorVersion >= 3;
1175
+ },
1176
+ describe() {
1177
+ return {
1178
+ type: PLATFORMS_MAP.tablet
1179
+ };
1180
+ }
1181
+ },
1182
+ {
1183
+ test(parser) {
1184
+ return parser.getOSName(true) === "android";
1185
+ },
1186
+ describe() {
1187
+ return {
1188
+ type: PLATFORMS_MAP.mobile
1189
+ };
1190
+ }
1191
+ },
1192
+ {
1193
+ test(parser) {
1194
+ return parser.getOSName(true) === "macos";
1195
+ },
1196
+ describe() {
1197
+ return {
1198
+ type: PLATFORMS_MAP.desktop,
1199
+ vendor: "Apple"
1200
+ };
1201
+ }
1202
+ },
1203
+ {
1204
+ test(parser) {
1205
+ return parser.getOSName(true) === "windows";
1206
+ },
1207
+ describe() {
1208
+ return {
1209
+ type: PLATFORMS_MAP.desktop
1210
+ };
1211
+ }
1212
+ },
1213
+ {
1214
+ test(parser) {
1215
+ return parser.getOSName(true) === "linux";
1216
+ },
1217
+ describe() {
1218
+ return {
1219
+ type: PLATFORMS_MAP.desktop
1220
+ };
1221
+ }
1222
+ },
1223
+ {
1224
+ test(parser) {
1225
+ return parser.getOSName(true) === "playstation 4";
1226
+ },
1227
+ describe() {
1228
+ return {
1229
+ type: PLATFORMS_MAP.tv
1230
+ };
1231
+ }
1232
+ },
1233
+ {
1234
+ test(parser) {
1235
+ return parser.getOSName(true) === "roku";
1236
+ },
1237
+ describe() {
1238
+ return {
1239
+ type: PLATFORMS_MAP.tv
1240
+ };
1241
+ }
1242
+ }
1243
+ ];
1244
+ const enginesParsersList = [
1245
+ {
1246
+ test(parser) {
1247
+ return parser.getBrowserName(true) === "microsoft edge";
1248
+ },
1249
+ describe(ua) {
1250
+ const isBlinkBased = /\sedg\//i.test(ua);
1251
+ if (isBlinkBased) {
1252
+ return {
1253
+ name: ENGINE_MAP.Blink
1254
+ };
1255
+ }
1256
+ const version = Utils.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);
1257
+ return {
1258
+ name: ENGINE_MAP.EdgeHTML,
1259
+ version
1260
+ };
1261
+ }
1262
+ },
1263
+ {
1264
+ test: [/trident/i],
1265
+ describe(ua) {
1266
+ const engine = {
1267
+ name: ENGINE_MAP.Trident
1268
+ };
1269
+ const version = Utils.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
1270
+ if (version) {
1271
+ engine.version = version;
1272
+ }
1273
+ return engine;
1274
+ }
1275
+ },
1276
+ {
1277
+ test(parser) {
1278
+ return parser.test(/presto/i);
1279
+ },
1280
+ describe(ua) {
1281
+ const engine = {
1282
+ name: ENGINE_MAP.Presto
1283
+ };
1284
+ const version = Utils.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
1285
+ if (version) {
1286
+ engine.version = version;
1287
+ }
1288
+ return engine;
1289
+ }
1290
+ },
1291
+ {
1292
+ test(parser) {
1293
+ const isGecko = parser.test(/gecko/i);
1294
+ const likeGecko = parser.test(/like gecko/i);
1295
+ return isGecko && !likeGecko;
1296
+ },
1297
+ describe(ua) {
1298
+ const engine = {
1299
+ name: ENGINE_MAP.Gecko
1300
+ };
1301
+ const version = Utils.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
1302
+ if (version) {
1303
+ engine.version = version;
1304
+ }
1305
+ return engine;
1306
+ }
1307
+ },
1308
+ {
1309
+ test: [/(apple)?webkit\/537\.36/i],
1310
+ describe() {
1311
+ return {
1312
+ name: ENGINE_MAP.Blink
1313
+ };
1314
+ }
1315
+ },
1316
+ {
1317
+ test: [/(apple)?webkit/i],
1318
+ describe(ua) {
1319
+ const engine = {
1320
+ name: ENGINE_MAP.WebKit
1321
+ };
1322
+ const version = Utils.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
1323
+ if (version) {
1324
+ engine.version = version;
1325
+ }
1326
+ return engine;
1327
+ }
1328
+ }
1329
+ ];
1330
+ class Parser {
1331
+ constructor(UA, skipParsing = false) {
1332
+ if (UA === void 0 || UA === null || UA === "") {
1333
+ throw new Error("UserAgent parameter can't be empty");
1334
+ }
1335
+ this._ua = UA;
1336
+ this.parsedResult = {};
1337
+ if (skipParsing !== true) {
1338
+ this.parse();
1339
+ }
1340
+ }
1341
+ getUA() {
1342
+ return this._ua;
1343
+ }
1344
+ test(regex) {
1345
+ return regex.test(this._ua);
1346
+ }
1347
+ parseBrowser() {
1348
+ this.parsedResult.browser = {};
1349
+ const browserDescriptor = Utils.find(browsersList, (_browser) => {
1350
+ if (typeof _browser.test === "function") {
1351
+ return _browser.test(this);
1352
+ }
1353
+ if (_browser.test instanceof Array) {
1354
+ return _browser.test.some((condition) => this.test(condition));
1355
+ }
1356
+ throw new Error("Browser's test function is not valid");
1357
+ });
1358
+ if (browserDescriptor) {
1359
+ this.parsedResult.browser = browserDescriptor.describe(this.getUA());
1360
+ }
1361
+ return this.parsedResult.browser;
1362
+ }
1363
+ getBrowser() {
1364
+ if (this.parsedResult.browser) {
1365
+ return this.parsedResult.browser;
1366
+ }
1367
+ return this.parseBrowser();
1368
+ }
1369
+ getBrowserName(toLowerCase) {
1370
+ if (toLowerCase) {
1371
+ return String(this.getBrowser().name).toLowerCase() || "";
1372
+ }
1373
+ return this.getBrowser().name || "";
1374
+ }
1375
+ getBrowserVersion() {
1376
+ return this.getBrowser().version;
1377
+ }
1378
+ getOS() {
1379
+ if (this.parsedResult.os) {
1380
+ return this.parsedResult.os;
1381
+ }
1382
+ return this.parseOS();
1383
+ }
1384
+ parseOS() {
1385
+ this.parsedResult.os = {};
1386
+ const os = Utils.find(osParsersList, (_os) => {
1387
+ if (typeof _os.test === "function") {
1388
+ return _os.test(this);
1389
+ }
1390
+ if (_os.test instanceof Array) {
1391
+ return _os.test.some((condition) => this.test(condition));
1392
+ }
1393
+ throw new Error("Browser's test function is not valid");
1394
+ });
1395
+ if (os) {
1396
+ this.parsedResult.os = os.describe(this.getUA());
1397
+ }
1398
+ return this.parsedResult.os;
1399
+ }
1400
+ getOSName(toLowerCase) {
1401
+ const { name } = this.getOS();
1402
+ if (toLowerCase) {
1403
+ return String(name).toLowerCase() || "";
1404
+ }
1405
+ return name || "";
1406
+ }
1407
+ getOSVersion() {
1408
+ return this.getOS().version;
1409
+ }
1410
+ getPlatform() {
1411
+ if (this.parsedResult.platform) {
1412
+ return this.parsedResult.platform;
1413
+ }
1414
+ return this.parsePlatform();
1415
+ }
1416
+ getPlatformType(toLowerCase = false) {
1417
+ const { type } = this.getPlatform();
1418
+ if (toLowerCase) {
1419
+ return String(type).toLowerCase() || "";
1420
+ }
1421
+ return type || "";
1422
+ }
1423
+ parsePlatform() {
1424
+ this.parsedResult.platform = {};
1425
+ const platform = Utils.find(platformParsersList, (_platform) => {
1426
+ if (typeof _platform.test === "function") {
1427
+ return _platform.test(this);
1428
+ }
1429
+ if (_platform.test instanceof Array) {
1430
+ return _platform.test.some((condition) => this.test(condition));
1431
+ }
1432
+ throw new Error("Browser's test function is not valid");
1433
+ });
1434
+ if (platform) {
1435
+ this.parsedResult.platform = platform.describe(this.getUA());
1436
+ }
1437
+ return this.parsedResult.platform;
1438
+ }
1439
+ getEngine() {
1440
+ if (this.parsedResult.engine) {
1441
+ return this.parsedResult.engine;
1442
+ }
1443
+ return this.parseEngine();
1444
+ }
1445
+ getEngineName(toLowerCase) {
1446
+ if (toLowerCase) {
1447
+ return String(this.getEngine().name).toLowerCase() || "";
1448
+ }
1449
+ return this.getEngine().name || "";
1450
+ }
1451
+ parseEngine() {
1452
+ this.parsedResult.engine = {};
1453
+ const engine = Utils.find(enginesParsersList, (_engine) => {
1454
+ if (typeof _engine.test === "function") {
1455
+ return _engine.test(this);
1456
+ }
1457
+ if (_engine.test instanceof Array) {
1458
+ return _engine.test.some((condition) => this.test(condition));
1459
+ }
1460
+ throw new Error("Browser's test function is not valid");
1461
+ });
1462
+ if (engine) {
1463
+ this.parsedResult.engine = engine.describe(this.getUA());
1464
+ }
1465
+ return this.parsedResult.engine;
1466
+ }
1467
+ parse() {
1468
+ this.parseBrowser();
1469
+ this.parseOS();
1470
+ this.parsePlatform();
1471
+ this.parseEngine();
1472
+ return this;
1473
+ }
1474
+ getResult() {
1475
+ return Utils.assign({}, this.parsedResult);
1476
+ }
1477
+ satisfies(checkTree) {
1478
+ const platformsAndOSes = {};
1479
+ let platformsAndOSCounter = 0;
1480
+ const browsers = {};
1481
+ let browsersCounter = 0;
1482
+ const allDefinitions = Object.keys(checkTree);
1483
+ allDefinitions.forEach((key) => {
1484
+ const currentDefinition = checkTree[key];
1485
+ if (typeof currentDefinition === "string") {
1486
+ browsers[key] = currentDefinition;
1487
+ browsersCounter += 1;
1488
+ } else if (typeof currentDefinition === "object") {
1489
+ platformsAndOSes[key] = currentDefinition;
1490
+ platformsAndOSCounter += 1;
1491
+ }
1492
+ });
1493
+ if (platformsAndOSCounter > 0) {
1494
+ const platformsAndOSNames = Object.keys(platformsAndOSes);
1495
+ const OSMatchingDefinition = Utils.find(platformsAndOSNames, (name) => this.isOS(name));
1496
+ if (OSMatchingDefinition) {
1497
+ const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
1498
+ if (osResult !== void 0) {
1499
+ return osResult;
1500
+ }
1501
+ }
1502
+ const platformMatchingDefinition = Utils.find(
1503
+ platformsAndOSNames,
1504
+ (name) => this.isPlatform(name)
1505
+ );
1506
+ if (platformMatchingDefinition) {
1507
+ const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
1508
+ if (platformResult !== void 0) {
1509
+ return platformResult;
1510
+ }
1511
+ }
1512
+ }
1513
+ if (browsersCounter > 0) {
1514
+ const browserNames = Object.keys(browsers);
1515
+ const matchingDefinition = Utils.find(browserNames, (name) => this.isBrowser(name, true));
1516
+ if (matchingDefinition !== void 0) {
1517
+ return this.compareVersion(browsers[matchingDefinition]);
1518
+ }
1519
+ }
1520
+ return void 0;
1521
+ }
1522
+ isBrowser(browserName, includingAlias = false) {
1523
+ const defaultBrowserName = this.getBrowserName().toLowerCase();
1524
+ let browserNameLower = browserName.toLowerCase();
1525
+ const alias = Utils.getBrowserTypeByAlias(browserNameLower);
1526
+ if (includingAlias && alias) {
1527
+ browserNameLower = alias.toLowerCase();
1528
+ }
1529
+ return browserNameLower === defaultBrowserName;
1530
+ }
1531
+ compareVersion(version) {
1532
+ let expectedResults = [0];
1533
+ let comparableVersion = version;
1534
+ let isLoose = false;
1535
+ const currentBrowserVersion = this.getBrowserVersion();
1536
+ if (typeof currentBrowserVersion !== "string") {
1537
+ return void 0;
1538
+ }
1539
+ if (version[0] === ">" || version[0] === "<") {
1540
+ comparableVersion = version.substr(1);
1541
+ if (version[1] === "=") {
1542
+ isLoose = true;
1543
+ comparableVersion = version.substr(2);
1544
+ } else {
1545
+ expectedResults = [];
1546
+ }
1547
+ if (version[0] === ">") {
1548
+ expectedResults.push(1);
1549
+ } else {
1550
+ expectedResults.push(-1);
1551
+ }
1552
+ } else if (version[0] === "=") {
1553
+ comparableVersion = version.substr(1);
1554
+ } else if (version[0] === "~") {
1555
+ isLoose = true;
1556
+ comparableVersion = version.substr(1);
1557
+ }
1558
+ return expectedResults.indexOf(
1559
+ Utils.compareVersions(currentBrowserVersion, comparableVersion, isLoose)
1560
+ ) > -1;
1561
+ }
1562
+ isOS(osName) {
1563
+ return this.getOSName(true) === String(osName).toLowerCase();
1564
+ }
1565
+ isPlatform(platformType) {
1566
+ return this.getPlatformType(true) === String(platformType).toLowerCase();
1567
+ }
1568
+ isEngine(engineName) {
1569
+ return this.getEngineName(true) === String(engineName).toLowerCase();
1570
+ }
1571
+ is(anything, includingAlias = false) {
1572
+ return this.isBrowser(anything, includingAlias) || this.isOS(anything) || this.isPlatform(anything);
1573
+ }
1574
+ some(anythings = []) {
1575
+ return anythings.some((anything) => this.is(anything));
1576
+ }
1577
+ }
1578
+ /*!
1579
+ * Bowser - a browser detector
1580
+ * https://github.com/lancedikson/bowser
1581
+ * MIT License | (c) Dustin Diaz 2012-2015
1582
+ * MIT License | (c) Denis Demchenko 2015-2019
1583
+ */
1584
+ class Bowser {
1585
+ static getParser(UA, skipParsing = false) {
1586
+ if (typeof UA !== "string") {
1587
+ throw new Error("UserAgent should be a string");
1588
+ }
1589
+ return new Parser(UA, skipParsing);
1590
+ }
1591
+ static parse(UA) {
1592
+ return new Parser(UA).getResult();
1593
+ }
1594
+ static get BROWSER_MAP() {
1595
+ return BROWSER_MAP;
1596
+ }
1597
+ static get ENGINE_MAP() {
1598
+ return ENGINE_MAP;
1599
+ }
1600
+ static get OS_MAP() {
1601
+ return OS_MAP;
1602
+ }
1603
+ static get PLATFORMS_MAP() {
1604
+ return PLATFORMS_MAP;
1605
+ }
1606
+ }
1607
+ var lzString = { exports: {} };
1608
+ (function(module) {
1609
+ var LZString = function() {
1610
+ var f = String.fromCharCode;
1611
+ var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1612
+ var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
1613
+ var baseReverseDic = {};
1614
+ function getBaseValue(alphabet, character) {
1615
+ if (!baseReverseDic[alphabet]) {
1616
+ baseReverseDic[alphabet] = {};
1617
+ for (var i = 0; i < alphabet.length; i++) {
1618
+ baseReverseDic[alphabet][alphabet.charAt(i)] = i;
1619
+ }
1620
+ }
1621
+ return baseReverseDic[alphabet][character];
1622
+ }
1623
+ var LZString2 = {
1624
+ compressToBase64: function(input) {
1625
+ if (input == null)
1626
+ return "";
1627
+ var res = LZString2._compress(input, 6, function(a) {
1628
+ return keyStrBase64.charAt(a);
1629
+ });
1630
+ switch (res.length % 4) {
1631
+ default:
1632
+ case 0:
1633
+ return res;
1634
+ case 1:
1635
+ return res + "===";
1636
+ case 2:
1637
+ return res + "==";
1638
+ case 3:
1639
+ return res + "=";
1640
+ }
1641
+ },
1642
+ decompressFromBase64: function(input) {
1643
+ if (input == null)
1644
+ return "";
1645
+ if (input == "")
1646
+ return null;
1647
+ return LZString2._decompress(input.length, 32, function(index) {
1648
+ return getBaseValue(keyStrBase64, input.charAt(index));
1649
+ });
1650
+ },
1651
+ compressToUTF16: function(input) {
1652
+ if (input == null)
1653
+ return "";
1654
+ return LZString2._compress(input, 15, function(a) {
1655
+ return f(a + 32);
1656
+ }) + " ";
1657
+ },
1658
+ decompressFromUTF16: function(compressed) {
1659
+ if (compressed == null)
1660
+ return "";
1661
+ if (compressed == "")
1662
+ return null;
1663
+ return LZString2._decompress(compressed.length, 16384, function(index) {
1664
+ return compressed.charCodeAt(index) - 32;
1665
+ });
1666
+ },
1667
+ compressToUint8Array: function(uncompressed) {
1668
+ var compressed = LZString2.compress(uncompressed);
1669
+ var buf = new Uint8Array(compressed.length * 2);
1670
+ for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
1671
+ var current_value = compressed.charCodeAt(i);
1672
+ buf[i * 2] = current_value >>> 8;
1673
+ buf[i * 2 + 1] = current_value % 256;
1674
+ }
1675
+ return buf;
1676
+ },
1677
+ decompressFromUint8Array: function(compressed) {
1678
+ if (compressed === null || compressed === void 0) {
1679
+ return LZString2.decompress(compressed);
1680
+ } else {
1681
+ var buf = new Array(compressed.length / 2);
1682
+ for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
1683
+ buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
1684
+ }
1685
+ var result = [];
1686
+ buf.forEach(function(c) {
1687
+ result.push(f(c));
1688
+ });
1689
+ return LZString2.decompress(result.join(""));
1690
+ }
1691
+ },
1692
+ compressToEncodedURIComponent: function(input) {
1693
+ if (input == null)
1694
+ return "";
1695
+ return LZString2._compress(input, 6, function(a) {
1696
+ return keyStrUriSafe.charAt(a);
1697
+ });
1698
+ },
1699
+ decompressFromEncodedURIComponent: function(input) {
1700
+ if (input == null)
1701
+ return "";
1702
+ if (input == "")
1703
+ return null;
1704
+ input = input.replace(/ /g, "+");
1705
+ return LZString2._decompress(input.length, 32, function(index) {
1706
+ return getBaseValue(keyStrUriSafe, input.charAt(index));
1707
+ });
1708
+ },
1709
+ compress: function(uncompressed) {
1710
+ return LZString2._compress(uncompressed, 16, function(a) {
1711
+ return f(a);
1712
+ });
1713
+ },
1714
+ _compress: function(uncompressed, bitsPerChar, getCharFromInt) {
1715
+ if (uncompressed == null)
1716
+ return "";
1717
+ var i, value, context_dictionary = {}, context_dictionaryToCreate = {}, context_c = "", context_wc = "", context_w = "", context_enlargeIn = 2, context_dictSize = 3, context_numBits = 2, context_data = [], context_data_val = 0, context_data_position = 0, ii;
1718
+ for (ii = 0; ii < uncompressed.length; ii += 1) {
1719
+ context_c = uncompressed.charAt(ii);
1720
+ if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
1721
+ context_dictionary[context_c] = context_dictSize++;
1722
+ context_dictionaryToCreate[context_c] = true;
1723
+ }
1724
+ context_wc = context_w + context_c;
1725
+ if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
1726
+ context_w = context_wc;
1727
+ } else {
1728
+ if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
1729
+ if (context_w.charCodeAt(0) < 256) {
1730
+ for (i = 0; i < context_numBits; i++) {
1731
+ context_data_val = context_data_val << 1;
1732
+ if (context_data_position == bitsPerChar - 1) {
1733
+ context_data_position = 0;
1734
+ context_data.push(getCharFromInt(context_data_val));
1735
+ context_data_val = 0;
1736
+ } else {
1737
+ context_data_position++;
1738
+ }
1739
+ }
1740
+ value = context_w.charCodeAt(0);
1741
+ for (i = 0; i < 8; i++) {
1742
+ context_data_val = context_data_val << 1 | value & 1;
1743
+ if (context_data_position == bitsPerChar - 1) {
1744
+ context_data_position = 0;
1745
+ context_data.push(getCharFromInt(context_data_val));
1746
+ context_data_val = 0;
1747
+ } else {
1748
+ context_data_position++;
1749
+ }
1750
+ value = value >> 1;
1751
+ }
1752
+ } else {
1753
+ value = 1;
1754
+ for (i = 0; i < context_numBits; i++) {
1755
+ context_data_val = context_data_val << 1 | value;
1756
+ if (context_data_position == bitsPerChar - 1) {
1757
+ context_data_position = 0;
1758
+ context_data.push(getCharFromInt(context_data_val));
1759
+ context_data_val = 0;
1760
+ } else {
1761
+ context_data_position++;
1762
+ }
1763
+ value = 0;
1764
+ }
1765
+ value = context_w.charCodeAt(0);
1766
+ for (i = 0; i < 16; i++) {
1767
+ context_data_val = context_data_val << 1 | value & 1;
1768
+ if (context_data_position == bitsPerChar - 1) {
1769
+ context_data_position = 0;
1770
+ context_data.push(getCharFromInt(context_data_val));
1771
+ context_data_val = 0;
1772
+ } else {
1773
+ context_data_position++;
1774
+ }
1775
+ value = value >> 1;
1776
+ }
1777
+ }
1778
+ context_enlargeIn--;
1779
+ if (context_enlargeIn == 0) {
1780
+ context_enlargeIn = Math.pow(2, context_numBits);
1781
+ context_numBits++;
1782
+ }
1783
+ delete context_dictionaryToCreate[context_w];
1784
+ } else {
1785
+ value = context_dictionary[context_w];
1786
+ for (i = 0; i < context_numBits; i++) {
1787
+ context_data_val = context_data_val << 1 | value & 1;
1788
+ if (context_data_position == bitsPerChar - 1) {
1789
+ context_data_position = 0;
1790
+ context_data.push(getCharFromInt(context_data_val));
1791
+ context_data_val = 0;
1792
+ } else {
1793
+ context_data_position++;
1794
+ }
1795
+ value = value >> 1;
1796
+ }
1797
+ }
1798
+ context_enlargeIn--;
1799
+ if (context_enlargeIn == 0) {
1800
+ context_enlargeIn = Math.pow(2, context_numBits);
1801
+ context_numBits++;
1802
+ }
1803
+ context_dictionary[context_wc] = context_dictSize++;
1804
+ context_w = String(context_c);
1805
+ }
1806
+ }
1807
+ if (context_w !== "") {
1808
+ if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
1809
+ if (context_w.charCodeAt(0) < 256) {
1810
+ for (i = 0; i < context_numBits; i++) {
1811
+ context_data_val = context_data_val << 1;
1812
+ if (context_data_position == bitsPerChar - 1) {
1813
+ context_data_position = 0;
1814
+ context_data.push(getCharFromInt(context_data_val));
1815
+ context_data_val = 0;
1816
+ } else {
1817
+ context_data_position++;
1818
+ }
1819
+ }
1820
+ value = context_w.charCodeAt(0);
1821
+ for (i = 0; i < 8; i++) {
1822
+ context_data_val = context_data_val << 1 | value & 1;
1823
+ if (context_data_position == bitsPerChar - 1) {
1824
+ context_data_position = 0;
1825
+ context_data.push(getCharFromInt(context_data_val));
1826
+ context_data_val = 0;
1827
+ } else {
1828
+ context_data_position++;
1829
+ }
1830
+ value = value >> 1;
1831
+ }
1832
+ } else {
1833
+ value = 1;
1834
+ for (i = 0; i < context_numBits; i++) {
1835
+ context_data_val = context_data_val << 1 | value;
1836
+ if (context_data_position == bitsPerChar - 1) {
1837
+ context_data_position = 0;
1838
+ context_data.push(getCharFromInt(context_data_val));
1839
+ context_data_val = 0;
1840
+ } else {
1841
+ context_data_position++;
1842
+ }
1843
+ value = 0;
1844
+ }
1845
+ value = context_w.charCodeAt(0);
1846
+ for (i = 0; i < 16; i++) {
1847
+ context_data_val = context_data_val << 1 | value & 1;
1848
+ if (context_data_position == bitsPerChar - 1) {
1849
+ context_data_position = 0;
1850
+ context_data.push(getCharFromInt(context_data_val));
1851
+ context_data_val = 0;
1852
+ } else {
1853
+ context_data_position++;
1854
+ }
1855
+ value = value >> 1;
1856
+ }
1857
+ }
1858
+ context_enlargeIn--;
1859
+ if (context_enlargeIn == 0) {
1860
+ context_enlargeIn = Math.pow(2, context_numBits);
1861
+ context_numBits++;
1862
+ }
1863
+ delete context_dictionaryToCreate[context_w];
1864
+ } else {
1865
+ value = context_dictionary[context_w];
1866
+ for (i = 0; i < context_numBits; i++) {
1867
+ context_data_val = context_data_val << 1 | value & 1;
1868
+ if (context_data_position == bitsPerChar - 1) {
1869
+ context_data_position = 0;
1870
+ context_data.push(getCharFromInt(context_data_val));
1871
+ context_data_val = 0;
1872
+ } else {
1873
+ context_data_position++;
1874
+ }
1875
+ value = value >> 1;
1876
+ }
1877
+ }
1878
+ context_enlargeIn--;
1879
+ if (context_enlargeIn == 0) {
1880
+ context_enlargeIn = Math.pow(2, context_numBits);
1881
+ context_numBits++;
1882
+ }
1883
+ }
1884
+ value = 2;
1885
+ for (i = 0; i < context_numBits; i++) {
1886
+ context_data_val = context_data_val << 1 | value & 1;
1887
+ if (context_data_position == bitsPerChar - 1) {
1888
+ context_data_position = 0;
1889
+ context_data.push(getCharFromInt(context_data_val));
1890
+ context_data_val = 0;
1891
+ } else {
1892
+ context_data_position++;
1893
+ }
1894
+ value = value >> 1;
1895
+ }
1896
+ while (true) {
1897
+ context_data_val = context_data_val << 1;
1898
+ if (context_data_position == bitsPerChar - 1) {
1899
+ context_data.push(getCharFromInt(context_data_val));
1900
+ break;
1901
+ } else
1902
+ context_data_position++;
1903
+ }
1904
+ return context_data.join("");
1905
+ },
1906
+ decompress: function(compressed) {
1907
+ if (compressed == null)
1908
+ return "";
1909
+ if (compressed == "")
1910
+ return null;
1911
+ return LZString2._decompress(compressed.length, 32768, function(index) {
1912
+ return compressed.charCodeAt(index);
1913
+ });
1914
+ },
1915
+ _decompress: function(length, resetValue, getNextValue) {
1916
+ var dictionary = [], enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = { val: getNextValue(0), position: resetValue, index: 1 };
1917
+ for (i = 0; i < 3; i += 1) {
1918
+ dictionary[i] = i;
1919
+ }
1920
+ bits = 0;
1921
+ maxpower = Math.pow(2, 2);
1922
+ power = 1;
1923
+ while (power != maxpower) {
1924
+ resb = data.val & data.position;
1925
+ data.position >>= 1;
1926
+ if (data.position == 0) {
1927
+ data.position = resetValue;
1928
+ data.val = getNextValue(data.index++);
1929
+ }
1930
+ bits |= (resb > 0 ? 1 : 0) * power;
1931
+ power <<= 1;
1932
+ }
1933
+ switch (bits) {
1934
+ case 0:
1935
+ bits = 0;
1936
+ maxpower = Math.pow(2, 8);
1937
+ power = 1;
1938
+ while (power != maxpower) {
1939
+ resb = data.val & data.position;
1940
+ data.position >>= 1;
1941
+ if (data.position == 0) {
1942
+ data.position = resetValue;
1943
+ data.val = getNextValue(data.index++);
1944
+ }
1945
+ bits |= (resb > 0 ? 1 : 0) * power;
1946
+ power <<= 1;
1947
+ }
1948
+ c = f(bits);
1949
+ break;
1950
+ case 1:
1951
+ bits = 0;
1952
+ maxpower = Math.pow(2, 16);
1953
+ power = 1;
1954
+ while (power != maxpower) {
1955
+ resb = data.val & data.position;
1956
+ data.position >>= 1;
1957
+ if (data.position == 0) {
1958
+ data.position = resetValue;
1959
+ data.val = getNextValue(data.index++);
1960
+ }
1961
+ bits |= (resb > 0 ? 1 : 0) * power;
1962
+ power <<= 1;
1963
+ }
1964
+ c = f(bits);
1965
+ break;
1966
+ case 2:
1967
+ return "";
1968
+ }
1969
+ dictionary[3] = c;
1970
+ w = c;
1971
+ result.push(c);
1972
+ while (true) {
1973
+ if (data.index > length) {
1974
+ return "";
1975
+ }
1976
+ bits = 0;
1977
+ maxpower = Math.pow(2, numBits);
1978
+ power = 1;
1979
+ while (power != maxpower) {
1980
+ resb = data.val & data.position;
1981
+ data.position >>= 1;
1982
+ if (data.position == 0) {
1983
+ data.position = resetValue;
1984
+ data.val = getNextValue(data.index++);
1985
+ }
1986
+ bits |= (resb > 0 ? 1 : 0) * power;
1987
+ power <<= 1;
1988
+ }
1989
+ switch (c = bits) {
1990
+ case 0:
1991
+ bits = 0;
1992
+ maxpower = Math.pow(2, 8);
1993
+ power = 1;
1994
+ while (power != maxpower) {
1995
+ resb = data.val & data.position;
1996
+ data.position >>= 1;
1997
+ if (data.position == 0) {
1998
+ data.position = resetValue;
1999
+ data.val = getNextValue(data.index++);
2000
+ }
2001
+ bits |= (resb > 0 ? 1 : 0) * power;
2002
+ power <<= 1;
2003
+ }
2004
+ dictionary[dictSize++] = f(bits);
2005
+ c = dictSize - 1;
2006
+ enlargeIn--;
2007
+ break;
2008
+ case 1:
2009
+ bits = 0;
2010
+ maxpower = Math.pow(2, 16);
2011
+ power = 1;
2012
+ while (power != maxpower) {
2013
+ resb = data.val & data.position;
2014
+ data.position >>= 1;
2015
+ if (data.position == 0) {
2016
+ data.position = resetValue;
2017
+ data.val = getNextValue(data.index++);
2018
+ }
2019
+ bits |= (resb > 0 ? 1 : 0) * power;
2020
+ power <<= 1;
2021
+ }
2022
+ dictionary[dictSize++] = f(bits);
2023
+ c = dictSize - 1;
2024
+ enlargeIn--;
2025
+ break;
2026
+ case 2:
2027
+ return result.join("");
2028
+ }
2029
+ if (enlargeIn == 0) {
2030
+ enlargeIn = Math.pow(2, numBits);
2031
+ numBits++;
2032
+ }
2033
+ if (dictionary[c]) {
2034
+ entry = dictionary[c];
2035
+ } else {
2036
+ if (c === dictSize) {
2037
+ entry = w + w.charAt(0);
2038
+ } else {
2039
+ return null;
2040
+ }
2041
+ }
2042
+ result.push(entry);
2043
+ dictionary[dictSize++] = w + entry.charAt(0);
2044
+ enlargeIn--;
2045
+ w = entry;
2046
+ if (enlargeIn == 0) {
2047
+ enlargeIn = Math.pow(2, numBits);
2048
+ numBits++;
2049
+ }
2050
+ }
2051
+ }
2052
+ };
2053
+ return LZString2;
2054
+ }();
2055
+ if (module != null) {
2056
+ module.exports = LZString;
2057
+ }
2058
+ })(lzString);
2059
+ const CURRENT_VERSION = "0.0.1";
2060
+ const VITESSCE_CONF_QUERY_STRING = "vitessce_conf";
2061
+ const VERSION_QUERY_STRING = "vitessce_conf_version";
2062
+ const LENGTH_QUERY_STRING = "vitessce_conf_length";
2063
+ function sniffBrowser() {
2064
+ const { browser } = Bowser.parse(window.navigator.userAgent);
2065
+ return browser.name;
2066
+ }
2067
+ const MAX_BROWSER_URL_LENGTHS = {
2068
+ Chrome: 32779,
2069
+ "Internet Explorer": 2047,
2070
+ Edge: 2047,
2071
+ Safari: 65e3,
2072
+ Firefox: 65e3
2073
+ };
2074
+ class CompressedConfLengthError {
2075
+ constructor(message) {
2076
+ this.message = message;
2077
+ }
2078
+ }
2079
+ function encodeConfInUrl({
2080
+ conf,
2081
+ onOverMaximumUrlLength = () => {
2082
+ }
2083
+ }) {
2084
+ const compressedConf = lzString.exports.compressToEncodedURIComponent(JSON.stringify(conf));
2085
+ const newParams = `${LENGTH_QUERY_STRING}=${compressedConf.length}&${VERSION_QUERY_STRING}=${CURRENT_VERSION}&${VITESSCE_CONF_QUERY_STRING}=${compressedConf}`;
2086
+ const browser = sniffBrowser();
2087
+ const maxLength = MAX_BROWSER_URL_LENGTHS[browser];
2088
+ if (newParams.length > maxLength) {
2089
+ const willWorkOn = Object.entries(MAX_BROWSER_URL_LENGTHS).filter((entry) => entry[1] > newParams.length).map((entry) => entry[0]);
2090
+ const message = `Configuration is ${compressedConf.length} characters; max URL for ${browser} is ${maxLength}: it will work on ${willWorkOn.join(", ") || "no browser"}.`;
2091
+ console.error(message);
2092
+ onOverMaximumUrlLength({ message, willWorkOn });
2093
+ }
2094
+ return newParams;
2095
+ }
2096
+ function decodeURLParamsToConf(queryString) {
2097
+ const params = new URLSearchParams(queryString.replace("#", "&"));
2098
+ const compressedConfString = params.get(VITESSCE_CONF_QUERY_STRING);
2099
+ const expectedConfLength = Number(params.get(LENGTH_QUERY_STRING));
2100
+ if (expectedConfLength !== compressedConfString.length) {
2101
+ throw new CompressedConfLengthError(`Compressed conf length (${compressedConfString.length}) != expected (${expectedConfLength}). URL truncated?`);
2102
+ }
2103
+ const version = params.get(VERSION_QUERY_STRING);
2104
+ if (version === CURRENT_VERSION) {
2105
+ const conf = JSON.parse(lzString.exports.decompressFromEncodedURIComponent(compressedConfString));
2106
+ return conf;
2107
+ }
2108
+ throw new Error("Unrecognized URL Param Version");
2109
+ }
2110
+ export {
2111
+ decodeURLParamsToConf,
2112
+ encodeConfInUrl
2113
+ };