@vitessce/export-utils 4.0.0-test.1 → 4.0.0-test.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.js +2697 -0
- package/package.json +2 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,2697 @@
|
|
|
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
|
+
/**
|
|
113
|
+
* Get first matched item for a string
|
|
114
|
+
* @param {RegExp} regexp
|
|
115
|
+
* @param {String} ua
|
|
116
|
+
* @return {Array|{index: number, input: string}|*|boolean|string}
|
|
117
|
+
*/
|
|
118
|
+
static getFirstMatch(regexp, ua) {
|
|
119
|
+
const match = ua.match(regexp);
|
|
120
|
+
return match && match.length > 0 && match[1] || "";
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get second matched item for a string
|
|
124
|
+
* @param regexp
|
|
125
|
+
* @param {String} ua
|
|
126
|
+
* @return {Array|{index: number, input: string}|*|boolean|string}
|
|
127
|
+
*/
|
|
128
|
+
static getSecondMatch(regexp, ua) {
|
|
129
|
+
const match = ua.match(regexp);
|
|
130
|
+
return match && match.length > 1 && match[2] || "";
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Match a regexp and return a constant or undefined
|
|
134
|
+
* @param {RegExp} regexp
|
|
135
|
+
* @param {String} ua
|
|
136
|
+
* @param {*} _const Any const that will be returned if regexp matches the string
|
|
137
|
+
* @return {*}
|
|
138
|
+
*/
|
|
139
|
+
static matchAndReturnConst(regexp, ua, _const) {
|
|
140
|
+
if (regexp.test(ua)) {
|
|
141
|
+
return _const;
|
|
142
|
+
}
|
|
143
|
+
return void 0;
|
|
144
|
+
}
|
|
145
|
+
static getWindowsVersionName(version) {
|
|
146
|
+
switch (version) {
|
|
147
|
+
case "NT":
|
|
148
|
+
return "NT";
|
|
149
|
+
case "XP":
|
|
150
|
+
return "XP";
|
|
151
|
+
case "NT 5.0":
|
|
152
|
+
return "2000";
|
|
153
|
+
case "NT 5.1":
|
|
154
|
+
return "XP";
|
|
155
|
+
case "NT 5.2":
|
|
156
|
+
return "2003";
|
|
157
|
+
case "NT 6.0":
|
|
158
|
+
return "Vista";
|
|
159
|
+
case "NT 6.1":
|
|
160
|
+
return "7";
|
|
161
|
+
case "NT 6.2":
|
|
162
|
+
return "8";
|
|
163
|
+
case "NT 6.3":
|
|
164
|
+
return "8.1";
|
|
165
|
+
case "NT 10.0":
|
|
166
|
+
return "10";
|
|
167
|
+
default:
|
|
168
|
+
return void 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get macOS version name
|
|
173
|
+
* 10.5 - Leopard
|
|
174
|
+
* 10.6 - Snow Leopard
|
|
175
|
+
* 10.7 - Lion
|
|
176
|
+
* 10.8 - Mountain Lion
|
|
177
|
+
* 10.9 - Mavericks
|
|
178
|
+
* 10.10 - Yosemite
|
|
179
|
+
* 10.11 - El Capitan
|
|
180
|
+
* 10.12 - Sierra
|
|
181
|
+
* 10.13 - High Sierra
|
|
182
|
+
* 10.14 - Mojave
|
|
183
|
+
* 10.15 - Catalina
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* getMacOSVersionName("10.14") // 'Mojave'
|
|
187
|
+
*
|
|
188
|
+
* @param {string} version
|
|
189
|
+
* @return {string} versionName
|
|
190
|
+
*/
|
|
191
|
+
static getMacOSVersionName(version) {
|
|
192
|
+
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
|
|
193
|
+
v.push(0);
|
|
194
|
+
if (v[0] !== 10) return void 0;
|
|
195
|
+
switch (v[1]) {
|
|
196
|
+
case 5:
|
|
197
|
+
return "Leopard";
|
|
198
|
+
case 6:
|
|
199
|
+
return "Snow Leopard";
|
|
200
|
+
case 7:
|
|
201
|
+
return "Lion";
|
|
202
|
+
case 8:
|
|
203
|
+
return "Mountain Lion";
|
|
204
|
+
case 9:
|
|
205
|
+
return "Mavericks";
|
|
206
|
+
case 10:
|
|
207
|
+
return "Yosemite";
|
|
208
|
+
case 11:
|
|
209
|
+
return "El Capitan";
|
|
210
|
+
case 12:
|
|
211
|
+
return "Sierra";
|
|
212
|
+
case 13:
|
|
213
|
+
return "High Sierra";
|
|
214
|
+
case 14:
|
|
215
|
+
return "Mojave";
|
|
216
|
+
case 15:
|
|
217
|
+
return "Catalina";
|
|
218
|
+
default:
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get Android version name
|
|
224
|
+
* 1.5 - Cupcake
|
|
225
|
+
* 1.6 - Donut
|
|
226
|
+
* 2.0 - Eclair
|
|
227
|
+
* 2.1 - Eclair
|
|
228
|
+
* 2.2 - Froyo
|
|
229
|
+
* 2.x - Gingerbread
|
|
230
|
+
* 3.x - Honeycomb
|
|
231
|
+
* 4.0 - Ice Cream Sandwich
|
|
232
|
+
* 4.1 - Jelly Bean
|
|
233
|
+
* 4.4 - KitKat
|
|
234
|
+
* 5.x - Lollipop
|
|
235
|
+
* 6.x - Marshmallow
|
|
236
|
+
* 7.x - Nougat
|
|
237
|
+
* 8.x - Oreo
|
|
238
|
+
* 9.x - Pie
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* getAndroidVersionName("7.0") // 'Nougat'
|
|
242
|
+
*
|
|
243
|
+
* @param {string} version
|
|
244
|
+
* @return {string} versionName
|
|
245
|
+
*/
|
|
246
|
+
static getAndroidVersionName(version) {
|
|
247
|
+
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
|
|
248
|
+
v.push(0);
|
|
249
|
+
if (v[0] === 1 && v[1] < 5) return void 0;
|
|
250
|
+
if (v[0] === 1 && v[1] < 6) return "Cupcake";
|
|
251
|
+
if (v[0] === 1 && v[1] >= 6) return "Donut";
|
|
252
|
+
if (v[0] === 2 && v[1] < 2) return "Eclair";
|
|
253
|
+
if (v[0] === 2 && v[1] === 2) return "Froyo";
|
|
254
|
+
if (v[0] === 2 && v[1] > 2) return "Gingerbread";
|
|
255
|
+
if (v[0] === 3) return "Honeycomb";
|
|
256
|
+
if (v[0] === 4 && v[1] < 1) return "Ice Cream Sandwich";
|
|
257
|
+
if (v[0] === 4 && v[1] < 4) return "Jelly Bean";
|
|
258
|
+
if (v[0] === 4 && v[1] >= 4) return "KitKat";
|
|
259
|
+
if (v[0] === 5) return "Lollipop";
|
|
260
|
+
if (v[0] === 6) return "Marshmallow";
|
|
261
|
+
if (v[0] === 7) return "Nougat";
|
|
262
|
+
if (v[0] === 8) return "Oreo";
|
|
263
|
+
if (v[0] === 9) return "Pie";
|
|
264
|
+
return void 0;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get version precisions count
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* getVersionPrecision("1.10.3") // 3
|
|
271
|
+
*
|
|
272
|
+
* @param {string} version
|
|
273
|
+
* @return {number}
|
|
274
|
+
*/
|
|
275
|
+
static getVersionPrecision(version) {
|
|
276
|
+
return version.split(".").length;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Calculate browser version weight
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* compareVersions('1.10.2.1', '1.8.2.1.90') // 1
|
|
283
|
+
* compareVersions('1.010.2.1', '1.09.2.1.90'); // 1
|
|
284
|
+
* compareVersions('1.10.2.1', '1.10.2.1'); // 0
|
|
285
|
+
* compareVersions('1.10.2.1', '1.0800.2'); // -1
|
|
286
|
+
* compareVersions('1.10.2.1', '1.10', true); // 0
|
|
287
|
+
*
|
|
288
|
+
* @param {String} versionA versions versions to compare
|
|
289
|
+
* @param {String} versionB versions versions to compare
|
|
290
|
+
* @param {boolean} [isLoose] enable loose comparison
|
|
291
|
+
* @return {Number} comparison result: -1 when versionA is lower,
|
|
292
|
+
* 1 when versionA is bigger, 0 when both equal
|
|
293
|
+
*/
|
|
294
|
+
/* eslint consistent-return: 1 */
|
|
295
|
+
static compareVersions(versionA, versionB, isLoose = false) {
|
|
296
|
+
const versionAPrecision = Utils.getVersionPrecision(versionA);
|
|
297
|
+
const versionBPrecision = Utils.getVersionPrecision(versionB);
|
|
298
|
+
let precision = Math.max(versionAPrecision, versionBPrecision);
|
|
299
|
+
let lastPrecision = 0;
|
|
300
|
+
const chunks = Utils.map([versionA, versionB], (version) => {
|
|
301
|
+
const delta = precision - Utils.getVersionPrecision(version);
|
|
302
|
+
const _version = version + new Array(delta + 1).join(".0");
|
|
303
|
+
return Utils.map(_version.split("."), (chunk) => new Array(20 - chunk.length).join("0") + chunk).reverse();
|
|
304
|
+
});
|
|
305
|
+
if (isLoose) {
|
|
306
|
+
lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision);
|
|
307
|
+
}
|
|
308
|
+
precision -= 1;
|
|
309
|
+
while (precision >= lastPrecision) {
|
|
310
|
+
if (chunks[0][precision] > chunks[1][precision]) {
|
|
311
|
+
return 1;
|
|
312
|
+
}
|
|
313
|
+
if (chunks[0][precision] === chunks[1][precision]) {
|
|
314
|
+
if (precision === lastPrecision) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
precision -= 1;
|
|
318
|
+
} else if (chunks[0][precision] < chunks[1][precision]) {
|
|
319
|
+
return -1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Array::map polyfill
|
|
326
|
+
*
|
|
327
|
+
* @param {Array} arr
|
|
328
|
+
* @param {Function} iterator
|
|
329
|
+
* @return {Array}
|
|
330
|
+
*/
|
|
331
|
+
static map(arr, iterator) {
|
|
332
|
+
const result = [];
|
|
333
|
+
let i;
|
|
334
|
+
if (Array.prototype.map) {
|
|
335
|
+
return Array.prototype.map.call(arr, iterator);
|
|
336
|
+
}
|
|
337
|
+
for (i = 0; i < arr.length; i += 1) {
|
|
338
|
+
result.push(iterator(arr[i]));
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Array::find polyfill
|
|
344
|
+
*
|
|
345
|
+
* @param {Array} arr
|
|
346
|
+
* @param {Function} predicate
|
|
347
|
+
* @return {Array}
|
|
348
|
+
*/
|
|
349
|
+
static find(arr, predicate) {
|
|
350
|
+
let i;
|
|
351
|
+
let l;
|
|
352
|
+
if (Array.prototype.find) {
|
|
353
|
+
return Array.prototype.find.call(arr, predicate);
|
|
354
|
+
}
|
|
355
|
+
for (i = 0, l = arr.length; i < l; i += 1) {
|
|
356
|
+
const value = arr[i];
|
|
357
|
+
if (predicate(value, i)) {
|
|
358
|
+
return value;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return void 0;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Object::assign polyfill
|
|
365
|
+
*
|
|
366
|
+
* @param {Object} obj
|
|
367
|
+
* @param {Object} ...objs
|
|
368
|
+
* @return {Object}
|
|
369
|
+
*/
|
|
370
|
+
static assign(obj, ...assigners) {
|
|
371
|
+
const result = obj;
|
|
372
|
+
let i;
|
|
373
|
+
let l;
|
|
374
|
+
if (Object.assign) {
|
|
375
|
+
return Object.assign(obj, ...assigners);
|
|
376
|
+
}
|
|
377
|
+
for (i = 0, l = assigners.length; i < l; i += 1) {
|
|
378
|
+
const assigner = assigners[i];
|
|
379
|
+
if (typeof assigner === "object" && assigner !== null) {
|
|
380
|
+
const keys = Object.keys(assigner);
|
|
381
|
+
keys.forEach((key) => {
|
|
382
|
+
result[key] = assigner[key];
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return obj;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get short version/alias for a browser name
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* getBrowserAlias('Microsoft Edge') // edge
|
|
393
|
+
*
|
|
394
|
+
* @param {string} browserName
|
|
395
|
+
* @return {string}
|
|
396
|
+
*/
|
|
397
|
+
static getBrowserAlias(browserName) {
|
|
398
|
+
return BROWSER_ALIASES_MAP[browserName];
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get short version/alias for a browser name
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* getBrowserAlias('edge') // Microsoft Edge
|
|
405
|
+
*
|
|
406
|
+
* @param {string} browserAlias
|
|
407
|
+
* @return {string}
|
|
408
|
+
*/
|
|
409
|
+
static getBrowserTypeByAlias(browserAlias) {
|
|
410
|
+
return BROWSER_MAP[browserAlias] || "";
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
|
|
414
|
+
const browsersList = [
|
|
415
|
+
/* Googlebot */
|
|
416
|
+
{
|
|
417
|
+
test: [/googlebot/i],
|
|
418
|
+
describe(ua) {
|
|
419
|
+
const browser = {
|
|
420
|
+
name: "Googlebot"
|
|
421
|
+
};
|
|
422
|
+
const version = Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
423
|
+
if (version) {
|
|
424
|
+
browser.version = version;
|
|
425
|
+
}
|
|
426
|
+
return browser;
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
/* Opera < 13.0 */
|
|
430
|
+
{
|
|
431
|
+
test: [/opera/i],
|
|
432
|
+
describe(ua) {
|
|
433
|
+
const browser = {
|
|
434
|
+
name: "Opera"
|
|
435
|
+
};
|
|
436
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
437
|
+
if (version) {
|
|
438
|
+
browser.version = version;
|
|
439
|
+
}
|
|
440
|
+
return browser;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
/* Opera > 13.0 */
|
|
444
|
+
{
|
|
445
|
+
test: [/opr\/|opios/i],
|
|
446
|
+
describe(ua) {
|
|
447
|
+
const browser = {
|
|
448
|
+
name: "Opera"
|
|
449
|
+
};
|
|
450
|
+
const version = Utils.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
451
|
+
if (version) {
|
|
452
|
+
browser.version = version;
|
|
453
|
+
}
|
|
454
|
+
return browser;
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
test: [/SamsungBrowser/i],
|
|
459
|
+
describe(ua) {
|
|
460
|
+
const browser = {
|
|
461
|
+
name: "Samsung Internet for Android"
|
|
462
|
+
};
|
|
463
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
464
|
+
if (version) {
|
|
465
|
+
browser.version = version;
|
|
466
|
+
}
|
|
467
|
+
return browser;
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
test: [/Whale/i],
|
|
472
|
+
describe(ua) {
|
|
473
|
+
const browser = {
|
|
474
|
+
name: "NAVER Whale Browser"
|
|
475
|
+
};
|
|
476
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i, ua);
|
|
477
|
+
if (version) {
|
|
478
|
+
browser.version = version;
|
|
479
|
+
}
|
|
480
|
+
return browser;
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
test: [/MZBrowser/i],
|
|
485
|
+
describe(ua) {
|
|
486
|
+
const browser = {
|
|
487
|
+
name: "MZ Browser"
|
|
488
|
+
};
|
|
489
|
+
const version = Utils.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
490
|
+
if (version) {
|
|
491
|
+
browser.version = version;
|
|
492
|
+
}
|
|
493
|
+
return browser;
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
test: [/focus/i],
|
|
498
|
+
describe(ua) {
|
|
499
|
+
const browser = {
|
|
500
|
+
name: "Focus"
|
|
501
|
+
};
|
|
502
|
+
const version = Utils.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
503
|
+
if (version) {
|
|
504
|
+
browser.version = version;
|
|
505
|
+
}
|
|
506
|
+
return browser;
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
test: [/swing/i],
|
|
511
|
+
describe(ua) {
|
|
512
|
+
const browser = {
|
|
513
|
+
name: "Swing"
|
|
514
|
+
};
|
|
515
|
+
const version = Utils.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
516
|
+
if (version) {
|
|
517
|
+
browser.version = version;
|
|
518
|
+
}
|
|
519
|
+
return browser;
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
test: [/coast/i],
|
|
524
|
+
describe(ua) {
|
|
525
|
+
const browser = {
|
|
526
|
+
name: "Opera Coast"
|
|
527
|
+
};
|
|
528
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
529
|
+
if (version) {
|
|
530
|
+
browser.version = version;
|
|
531
|
+
}
|
|
532
|
+
return browser;
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
test: [/opt\/\d+(?:.?_?\d+)+/i],
|
|
537
|
+
describe(ua) {
|
|
538
|
+
const browser = {
|
|
539
|
+
name: "Opera Touch"
|
|
540
|
+
};
|
|
541
|
+
const version = Utils.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
542
|
+
if (version) {
|
|
543
|
+
browser.version = version;
|
|
544
|
+
}
|
|
545
|
+
return browser;
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
test: [/yabrowser/i],
|
|
550
|
+
describe(ua) {
|
|
551
|
+
const browser = {
|
|
552
|
+
name: "Yandex Browser"
|
|
553
|
+
};
|
|
554
|
+
const version = Utils.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
555
|
+
if (version) {
|
|
556
|
+
browser.version = version;
|
|
557
|
+
}
|
|
558
|
+
return browser;
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
test: [/ucbrowser/i],
|
|
563
|
+
describe(ua) {
|
|
564
|
+
const browser = {
|
|
565
|
+
name: "UC Browser"
|
|
566
|
+
};
|
|
567
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
568
|
+
if (version) {
|
|
569
|
+
browser.version = version;
|
|
570
|
+
}
|
|
571
|
+
return browser;
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
test: [/Maxthon|mxios/i],
|
|
576
|
+
describe(ua) {
|
|
577
|
+
const browser = {
|
|
578
|
+
name: "Maxthon"
|
|
579
|
+
};
|
|
580
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
581
|
+
if (version) {
|
|
582
|
+
browser.version = version;
|
|
583
|
+
}
|
|
584
|
+
return browser;
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
test: [/epiphany/i],
|
|
589
|
+
describe(ua) {
|
|
590
|
+
const browser = {
|
|
591
|
+
name: "Epiphany"
|
|
592
|
+
};
|
|
593
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
594
|
+
if (version) {
|
|
595
|
+
browser.version = version;
|
|
596
|
+
}
|
|
597
|
+
return browser;
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
test: [/puffin/i],
|
|
602
|
+
describe(ua) {
|
|
603
|
+
const browser = {
|
|
604
|
+
name: "Puffin"
|
|
605
|
+
};
|
|
606
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
607
|
+
if (version) {
|
|
608
|
+
browser.version = version;
|
|
609
|
+
}
|
|
610
|
+
return browser;
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
test: [/sleipnir/i],
|
|
615
|
+
describe(ua) {
|
|
616
|
+
const browser = {
|
|
617
|
+
name: "Sleipnir"
|
|
618
|
+
};
|
|
619
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
620
|
+
if (version) {
|
|
621
|
+
browser.version = version;
|
|
622
|
+
}
|
|
623
|
+
return browser;
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
test: [/k-meleon/i],
|
|
628
|
+
describe(ua) {
|
|
629
|
+
const browser = {
|
|
630
|
+
name: "K-Meleon"
|
|
631
|
+
};
|
|
632
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
633
|
+
if (version) {
|
|
634
|
+
browser.version = version;
|
|
635
|
+
}
|
|
636
|
+
return browser;
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
test: [/micromessenger/i],
|
|
641
|
+
describe(ua) {
|
|
642
|
+
const browser = {
|
|
643
|
+
name: "WeChat"
|
|
644
|
+
};
|
|
645
|
+
const version = Utils.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
646
|
+
if (version) {
|
|
647
|
+
browser.version = version;
|
|
648
|
+
}
|
|
649
|
+
return browser;
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
test: [/qqbrowser/i],
|
|
654
|
+
describe(ua) {
|
|
655
|
+
const browser = {
|
|
656
|
+
name: /qqbrowserlite/i.test(ua) ? "QQ Browser Lite" : "QQ Browser"
|
|
657
|
+
};
|
|
658
|
+
const version = Utils.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
659
|
+
if (version) {
|
|
660
|
+
browser.version = version;
|
|
661
|
+
}
|
|
662
|
+
return browser;
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
test: [/msie|trident/i],
|
|
667
|
+
describe(ua) {
|
|
668
|
+
const browser = {
|
|
669
|
+
name: "Internet Explorer"
|
|
670
|
+
};
|
|
671
|
+
const version = Utils.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua);
|
|
672
|
+
if (version) {
|
|
673
|
+
browser.version = version;
|
|
674
|
+
}
|
|
675
|
+
return browser;
|
|
676
|
+
}
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
test: [/\sedg\//i],
|
|
680
|
+
describe(ua) {
|
|
681
|
+
const browser = {
|
|
682
|
+
name: "Microsoft Edge"
|
|
683
|
+
};
|
|
684
|
+
const version = Utils.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i, ua);
|
|
685
|
+
if (version) {
|
|
686
|
+
browser.version = version;
|
|
687
|
+
}
|
|
688
|
+
return browser;
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
test: [/edg([ea]|ios)/i],
|
|
693
|
+
describe(ua) {
|
|
694
|
+
const browser = {
|
|
695
|
+
name: "Microsoft Edge"
|
|
696
|
+
};
|
|
697
|
+
const version = Utils.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua);
|
|
698
|
+
if (version) {
|
|
699
|
+
browser.version = version;
|
|
700
|
+
}
|
|
701
|
+
return browser;
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
test: [/vivaldi/i],
|
|
706
|
+
describe(ua) {
|
|
707
|
+
const browser = {
|
|
708
|
+
name: "Vivaldi"
|
|
709
|
+
};
|
|
710
|
+
const version = Utils.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua);
|
|
711
|
+
if (version) {
|
|
712
|
+
browser.version = version;
|
|
713
|
+
}
|
|
714
|
+
return browser;
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
test: [/seamonkey/i],
|
|
719
|
+
describe(ua) {
|
|
720
|
+
const browser = {
|
|
721
|
+
name: "SeaMonkey"
|
|
722
|
+
};
|
|
723
|
+
const version = Utils.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua);
|
|
724
|
+
if (version) {
|
|
725
|
+
browser.version = version;
|
|
726
|
+
}
|
|
727
|
+
return browser;
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
test: [/sailfish/i],
|
|
732
|
+
describe(ua) {
|
|
733
|
+
const browser = {
|
|
734
|
+
name: "Sailfish"
|
|
735
|
+
};
|
|
736
|
+
const version = Utils.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua);
|
|
737
|
+
if (version) {
|
|
738
|
+
browser.version = version;
|
|
739
|
+
}
|
|
740
|
+
return browser;
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
test: [/silk/i],
|
|
745
|
+
describe(ua) {
|
|
746
|
+
const browser = {
|
|
747
|
+
name: "Amazon Silk"
|
|
748
|
+
};
|
|
749
|
+
const version = Utils.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua);
|
|
750
|
+
if (version) {
|
|
751
|
+
browser.version = version;
|
|
752
|
+
}
|
|
753
|
+
return browser;
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
test: [/phantom/i],
|
|
758
|
+
describe(ua) {
|
|
759
|
+
const browser = {
|
|
760
|
+
name: "PhantomJS"
|
|
761
|
+
};
|
|
762
|
+
const version = Utils.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua);
|
|
763
|
+
if (version) {
|
|
764
|
+
browser.version = version;
|
|
765
|
+
}
|
|
766
|
+
return browser;
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
test: [/slimerjs/i],
|
|
771
|
+
describe(ua) {
|
|
772
|
+
const browser = {
|
|
773
|
+
name: "SlimerJS"
|
|
774
|
+
};
|
|
775
|
+
const version = Utils.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua);
|
|
776
|
+
if (version) {
|
|
777
|
+
browser.version = version;
|
|
778
|
+
}
|
|
779
|
+
return browser;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
|
|
784
|
+
describe(ua) {
|
|
785
|
+
const browser = {
|
|
786
|
+
name: "BlackBerry"
|
|
787
|
+
};
|
|
788
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua);
|
|
789
|
+
if (version) {
|
|
790
|
+
browser.version = version;
|
|
791
|
+
}
|
|
792
|
+
return browser;
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
test: [/(web|hpw)[o0]s/i],
|
|
797
|
+
describe(ua) {
|
|
798
|
+
const browser = {
|
|
799
|
+
name: "WebOS Browser"
|
|
800
|
+
};
|
|
801
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i, ua);
|
|
802
|
+
if (version) {
|
|
803
|
+
browser.version = version;
|
|
804
|
+
}
|
|
805
|
+
return browser;
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
test: [/bada/i],
|
|
810
|
+
describe(ua) {
|
|
811
|
+
const browser = {
|
|
812
|
+
name: "Bada"
|
|
813
|
+
};
|
|
814
|
+
const version = Utils.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua);
|
|
815
|
+
if (version) {
|
|
816
|
+
browser.version = version;
|
|
817
|
+
}
|
|
818
|
+
return browser;
|
|
819
|
+
}
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
test: [/tizen/i],
|
|
823
|
+
describe(ua) {
|
|
824
|
+
const browser = {
|
|
825
|
+
name: "Tizen"
|
|
826
|
+
};
|
|
827
|
+
const version = Utils.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
828
|
+
if (version) {
|
|
829
|
+
browser.version = version;
|
|
830
|
+
}
|
|
831
|
+
return browser;
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
test: [/qupzilla/i],
|
|
836
|
+
describe(ua) {
|
|
837
|
+
const browser = {
|
|
838
|
+
name: "QupZilla"
|
|
839
|
+
};
|
|
840
|
+
const version = Utils.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
841
|
+
if (version) {
|
|
842
|
+
browser.version = version;
|
|
843
|
+
}
|
|
844
|
+
return browser;
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
test: [/firefox|iceweasel|fxios/i],
|
|
849
|
+
describe(ua) {
|
|
850
|
+
const browser = {
|
|
851
|
+
name: "Firefox"
|
|
852
|
+
};
|
|
853
|
+
const version = Utils.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
854
|
+
if (version) {
|
|
855
|
+
browser.version = version;
|
|
856
|
+
}
|
|
857
|
+
return browser;
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
test: [/electron/i],
|
|
862
|
+
describe(ua) {
|
|
863
|
+
const browser = {
|
|
864
|
+
name: "Electron"
|
|
865
|
+
};
|
|
866
|
+
const version = Utils.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i, ua);
|
|
867
|
+
if (version) {
|
|
868
|
+
browser.version = version;
|
|
869
|
+
}
|
|
870
|
+
return browser;
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
test: [/MiuiBrowser/i],
|
|
875
|
+
describe(ua) {
|
|
876
|
+
const browser = {
|
|
877
|
+
name: "Miui"
|
|
878
|
+
};
|
|
879
|
+
const version = Utils.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
|
|
880
|
+
if (version) {
|
|
881
|
+
browser.version = version;
|
|
882
|
+
}
|
|
883
|
+
return browser;
|
|
884
|
+
}
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
test: [/chromium/i],
|
|
888
|
+
describe(ua) {
|
|
889
|
+
const browser = {
|
|
890
|
+
name: "Chromium"
|
|
891
|
+
};
|
|
892
|
+
const version = Utils.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
893
|
+
if (version) {
|
|
894
|
+
browser.version = version;
|
|
895
|
+
}
|
|
896
|
+
return browser;
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
test: [/chrome|crios|crmo/i],
|
|
901
|
+
describe(ua) {
|
|
902
|
+
const browser = {
|
|
903
|
+
name: "Chrome"
|
|
904
|
+
};
|
|
905
|
+
const version = Utils.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua);
|
|
906
|
+
if (version) {
|
|
907
|
+
browser.version = version;
|
|
908
|
+
}
|
|
909
|
+
return browser;
|
|
910
|
+
}
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
test: [/GSA/i],
|
|
914
|
+
describe(ua) {
|
|
915
|
+
const browser = {
|
|
916
|
+
name: "Google Search"
|
|
917
|
+
};
|
|
918
|
+
const version = Utils.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i, ua);
|
|
919
|
+
if (version) {
|
|
920
|
+
browser.version = version;
|
|
921
|
+
}
|
|
922
|
+
return browser;
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
/* Android Browser */
|
|
926
|
+
{
|
|
927
|
+
test(parser) {
|
|
928
|
+
const notLikeAndroid = !parser.test(/like android/i);
|
|
929
|
+
const butAndroid = parser.test(/android/i);
|
|
930
|
+
return notLikeAndroid && butAndroid;
|
|
931
|
+
},
|
|
932
|
+
describe(ua) {
|
|
933
|
+
const browser = {
|
|
934
|
+
name: "Android Browser"
|
|
935
|
+
};
|
|
936
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
937
|
+
if (version) {
|
|
938
|
+
browser.version = version;
|
|
939
|
+
}
|
|
940
|
+
return browser;
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
/* PlayStation 4 */
|
|
944
|
+
{
|
|
945
|
+
test: [/playstation 4/i],
|
|
946
|
+
describe(ua) {
|
|
947
|
+
const browser = {
|
|
948
|
+
name: "PlayStation 4"
|
|
949
|
+
};
|
|
950
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
951
|
+
if (version) {
|
|
952
|
+
browser.version = version;
|
|
953
|
+
}
|
|
954
|
+
return browser;
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
/* Safari */
|
|
958
|
+
{
|
|
959
|
+
test: [/safari|applewebkit/i],
|
|
960
|
+
describe(ua) {
|
|
961
|
+
const browser = {
|
|
962
|
+
name: "Safari"
|
|
963
|
+
};
|
|
964
|
+
const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
|
|
965
|
+
if (version) {
|
|
966
|
+
browser.version = version;
|
|
967
|
+
}
|
|
968
|
+
return browser;
|
|
969
|
+
}
|
|
970
|
+
},
|
|
971
|
+
/* Something else */
|
|
972
|
+
{
|
|
973
|
+
test: [/.*/i],
|
|
974
|
+
describe(ua) {
|
|
975
|
+
const regexpWithoutDeviceSpec = /^(.*)\/(.*) /;
|
|
976
|
+
const regexpWithDeviceSpec = /^(.*)\/(.*)[ \t]\((.*)/;
|
|
977
|
+
const hasDeviceSpec = ua.search("\\(") !== -1;
|
|
978
|
+
const regexp = hasDeviceSpec ? regexpWithDeviceSpec : regexpWithoutDeviceSpec;
|
|
979
|
+
return {
|
|
980
|
+
name: Utils.getFirstMatch(regexp, ua),
|
|
981
|
+
version: Utils.getSecondMatch(regexp, ua)
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
];
|
|
986
|
+
const osParsersList = [
|
|
987
|
+
/* Roku */
|
|
988
|
+
{
|
|
989
|
+
test: [/Roku\/DVP/],
|
|
990
|
+
describe(ua) {
|
|
991
|
+
const version = Utils.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua);
|
|
992
|
+
return {
|
|
993
|
+
name: OS_MAP.Roku,
|
|
994
|
+
version
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
},
|
|
998
|
+
/* Windows Phone */
|
|
999
|
+
{
|
|
1000
|
+
test: [/windows phone/i],
|
|
1001
|
+
describe(ua) {
|
|
1002
|
+
const version = Utils.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
|
|
1003
|
+
return {
|
|
1004
|
+
name: OS_MAP.WindowsPhone,
|
|
1005
|
+
version
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
/* Windows */
|
|
1010
|
+
{
|
|
1011
|
+
test: [/windows /i],
|
|
1012
|
+
describe(ua) {
|
|
1013
|
+
const version = Utils.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
|
|
1014
|
+
const versionName = Utils.getWindowsVersionName(version);
|
|
1015
|
+
return {
|
|
1016
|
+
name: OS_MAP.Windows,
|
|
1017
|
+
version,
|
|
1018
|
+
versionName
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
/* Firefox on iPad */
|
|
1023
|
+
{
|
|
1024
|
+
test: [/Macintosh(.*?) FxiOS(.*?)\//],
|
|
1025
|
+
describe(ua) {
|
|
1026
|
+
const result = {
|
|
1027
|
+
name: OS_MAP.iOS
|
|
1028
|
+
};
|
|
1029
|
+
const version = Utils.getSecondMatch(/(Version\/)(\d[\d.]+)/, ua);
|
|
1030
|
+
if (version) {
|
|
1031
|
+
result.version = version;
|
|
1032
|
+
}
|
|
1033
|
+
return result;
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
/* macOS */
|
|
1037
|
+
{
|
|
1038
|
+
test: [/macintosh/i],
|
|
1039
|
+
describe(ua) {
|
|
1040
|
+
const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, ".");
|
|
1041
|
+
const versionName = Utils.getMacOSVersionName(version);
|
|
1042
|
+
const os = {
|
|
1043
|
+
name: OS_MAP.MacOS,
|
|
1044
|
+
version
|
|
1045
|
+
};
|
|
1046
|
+
if (versionName) {
|
|
1047
|
+
os.versionName = versionName;
|
|
1048
|
+
}
|
|
1049
|
+
return os;
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
/* iOS */
|
|
1053
|
+
{
|
|
1054
|
+
test: [/(ipod|iphone|ipad)/i],
|
|
1055
|
+
describe(ua) {
|
|
1056
|
+
const version = Utils.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, ".");
|
|
1057
|
+
return {
|
|
1058
|
+
name: OS_MAP.iOS,
|
|
1059
|
+
version
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
/* Android */
|
|
1064
|
+
{
|
|
1065
|
+
test(parser) {
|
|
1066
|
+
const notLikeAndroid = !parser.test(/like android/i);
|
|
1067
|
+
const butAndroid = parser.test(/android/i);
|
|
1068
|
+
return notLikeAndroid && butAndroid;
|
|
1069
|
+
},
|
|
1070
|
+
describe(ua) {
|
|
1071
|
+
const version = Utils.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
|
|
1072
|
+
const versionName = Utils.getAndroidVersionName(version);
|
|
1073
|
+
const os = {
|
|
1074
|
+
name: OS_MAP.Android,
|
|
1075
|
+
version
|
|
1076
|
+
};
|
|
1077
|
+
if (versionName) {
|
|
1078
|
+
os.versionName = versionName;
|
|
1079
|
+
}
|
|
1080
|
+
return os;
|
|
1081
|
+
}
|
|
1082
|
+
},
|
|
1083
|
+
/* WebOS */
|
|
1084
|
+
{
|
|
1085
|
+
test: [/(web|hpw)[o0]s/i],
|
|
1086
|
+
describe(ua) {
|
|
1087
|
+
const version = Utils.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
|
|
1088
|
+
const os = {
|
|
1089
|
+
name: OS_MAP.WebOS
|
|
1090
|
+
};
|
|
1091
|
+
if (version && version.length) {
|
|
1092
|
+
os.version = version;
|
|
1093
|
+
}
|
|
1094
|
+
return os;
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
/* BlackBerry */
|
|
1098
|
+
{
|
|
1099
|
+
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
|
|
1100
|
+
describe(ua) {
|
|
1101
|
+
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);
|
|
1102
|
+
return {
|
|
1103
|
+
name: OS_MAP.BlackBerry,
|
|
1104
|
+
version
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
/* Bada */
|
|
1109
|
+
{
|
|
1110
|
+
test: [/bada/i],
|
|
1111
|
+
describe(ua) {
|
|
1112
|
+
const version = Utils.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
|
|
1113
|
+
return {
|
|
1114
|
+
name: OS_MAP.Bada,
|
|
1115
|
+
version
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
/* Tizen */
|
|
1120
|
+
{
|
|
1121
|
+
test: [/tizen/i],
|
|
1122
|
+
describe(ua) {
|
|
1123
|
+
const version = Utils.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
|
|
1124
|
+
return {
|
|
1125
|
+
name: OS_MAP.Tizen,
|
|
1126
|
+
version
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
},
|
|
1130
|
+
/* Linux */
|
|
1131
|
+
{
|
|
1132
|
+
test: [/linux/i],
|
|
1133
|
+
describe() {
|
|
1134
|
+
return {
|
|
1135
|
+
name: OS_MAP.Linux
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
},
|
|
1139
|
+
/* Chrome OS */
|
|
1140
|
+
{
|
|
1141
|
+
test: [/CrOS/],
|
|
1142
|
+
describe() {
|
|
1143
|
+
return {
|
|
1144
|
+
name: OS_MAP.ChromeOS
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
/* Playstation 4 */
|
|
1149
|
+
{
|
|
1150
|
+
test: [/PlayStation 4/],
|
|
1151
|
+
describe(ua) {
|
|
1152
|
+
const version = Utils.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
|
|
1153
|
+
return {
|
|
1154
|
+
name: OS_MAP.PlayStation4,
|
|
1155
|
+
version
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
];
|
|
1160
|
+
const platformParsersList = [
|
|
1161
|
+
/* Googlebot */
|
|
1162
|
+
{
|
|
1163
|
+
test: [/googlebot/i],
|
|
1164
|
+
describe() {
|
|
1165
|
+
return {
|
|
1166
|
+
type: "bot",
|
|
1167
|
+
vendor: "Google"
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
},
|
|
1171
|
+
/* Huawei */
|
|
1172
|
+
{
|
|
1173
|
+
test: [/huawei/i],
|
|
1174
|
+
describe(ua) {
|
|
1175
|
+
const model = Utils.getFirstMatch(/(can-l01)/i, ua) && "Nova";
|
|
1176
|
+
const platform = {
|
|
1177
|
+
type: PLATFORMS_MAP.mobile,
|
|
1178
|
+
vendor: "Huawei"
|
|
1179
|
+
};
|
|
1180
|
+
if (model) {
|
|
1181
|
+
platform.model = model;
|
|
1182
|
+
}
|
|
1183
|
+
return platform;
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
/* Nexus Tablet */
|
|
1187
|
+
{
|
|
1188
|
+
test: [/nexus\s*(?:7|8|9|10).*/i],
|
|
1189
|
+
describe() {
|
|
1190
|
+
return {
|
|
1191
|
+
type: PLATFORMS_MAP.tablet,
|
|
1192
|
+
vendor: "Nexus"
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
/* iPad */
|
|
1197
|
+
{
|
|
1198
|
+
test: [/ipad/i],
|
|
1199
|
+
describe() {
|
|
1200
|
+
return {
|
|
1201
|
+
type: PLATFORMS_MAP.tablet,
|
|
1202
|
+
vendor: "Apple",
|
|
1203
|
+
model: "iPad"
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
},
|
|
1207
|
+
/* Firefox on iPad */
|
|
1208
|
+
{
|
|
1209
|
+
test: [/Macintosh(.*?) FxiOS(.*?)\//],
|
|
1210
|
+
describe() {
|
|
1211
|
+
return {
|
|
1212
|
+
type: PLATFORMS_MAP.tablet,
|
|
1213
|
+
vendor: "Apple",
|
|
1214
|
+
model: "iPad"
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
/* Amazon Kindle Fire */
|
|
1219
|
+
{
|
|
1220
|
+
test: [/kftt build/i],
|
|
1221
|
+
describe() {
|
|
1222
|
+
return {
|
|
1223
|
+
type: PLATFORMS_MAP.tablet,
|
|
1224
|
+
vendor: "Amazon",
|
|
1225
|
+
model: "Kindle Fire HD 7"
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
/* Another Amazon Tablet with Silk */
|
|
1230
|
+
{
|
|
1231
|
+
test: [/silk/i],
|
|
1232
|
+
describe() {
|
|
1233
|
+
return {
|
|
1234
|
+
type: PLATFORMS_MAP.tablet,
|
|
1235
|
+
vendor: "Amazon"
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
/* Tablet */
|
|
1240
|
+
{
|
|
1241
|
+
test: [/tablet(?! pc)/i],
|
|
1242
|
+
describe() {
|
|
1243
|
+
return {
|
|
1244
|
+
type: PLATFORMS_MAP.tablet
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
},
|
|
1248
|
+
/* iPod/iPhone */
|
|
1249
|
+
{
|
|
1250
|
+
test(parser) {
|
|
1251
|
+
const iDevice = parser.test(/ipod|iphone/i);
|
|
1252
|
+
const likeIDevice = parser.test(/like (ipod|iphone)/i);
|
|
1253
|
+
return iDevice && !likeIDevice;
|
|
1254
|
+
},
|
|
1255
|
+
describe(ua) {
|
|
1256
|
+
const model = Utils.getFirstMatch(/(ipod|iphone)/i, ua);
|
|
1257
|
+
return {
|
|
1258
|
+
type: PLATFORMS_MAP.mobile,
|
|
1259
|
+
vendor: "Apple",
|
|
1260
|
+
model
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
},
|
|
1264
|
+
/* Nexus Mobile */
|
|
1265
|
+
{
|
|
1266
|
+
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
|
|
1267
|
+
describe() {
|
|
1268
|
+
return {
|
|
1269
|
+
type: PLATFORMS_MAP.mobile,
|
|
1270
|
+
vendor: "Nexus"
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
},
|
|
1274
|
+
/* Mobile */
|
|
1275
|
+
{
|
|
1276
|
+
test: [/[^-]mobi/i],
|
|
1277
|
+
describe() {
|
|
1278
|
+
return {
|
|
1279
|
+
type: PLATFORMS_MAP.mobile
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
},
|
|
1283
|
+
/* BlackBerry */
|
|
1284
|
+
{
|
|
1285
|
+
test(parser) {
|
|
1286
|
+
return parser.getBrowserName(true) === "blackberry";
|
|
1287
|
+
},
|
|
1288
|
+
describe() {
|
|
1289
|
+
return {
|
|
1290
|
+
type: PLATFORMS_MAP.mobile,
|
|
1291
|
+
vendor: "BlackBerry"
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
/* Bada */
|
|
1296
|
+
{
|
|
1297
|
+
test(parser) {
|
|
1298
|
+
return parser.getBrowserName(true) === "bada";
|
|
1299
|
+
},
|
|
1300
|
+
describe() {
|
|
1301
|
+
return {
|
|
1302
|
+
type: PLATFORMS_MAP.mobile
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
/* Windows Phone */
|
|
1307
|
+
{
|
|
1308
|
+
test(parser) {
|
|
1309
|
+
return parser.getBrowserName() === "windows phone";
|
|
1310
|
+
},
|
|
1311
|
+
describe() {
|
|
1312
|
+
return {
|
|
1313
|
+
type: PLATFORMS_MAP.mobile,
|
|
1314
|
+
vendor: "Microsoft"
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
},
|
|
1318
|
+
/* Android Tablet */
|
|
1319
|
+
{
|
|
1320
|
+
test(parser) {
|
|
1321
|
+
const osMajorVersion = Number(String(parser.getOSVersion()).split(".")[0]);
|
|
1322
|
+
return parser.getOSName(true) === "android" && osMajorVersion >= 3;
|
|
1323
|
+
},
|
|
1324
|
+
describe() {
|
|
1325
|
+
return {
|
|
1326
|
+
type: PLATFORMS_MAP.tablet
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
/* Android Mobile */
|
|
1331
|
+
{
|
|
1332
|
+
test(parser) {
|
|
1333
|
+
return parser.getOSName(true) === "android";
|
|
1334
|
+
},
|
|
1335
|
+
describe() {
|
|
1336
|
+
return {
|
|
1337
|
+
type: PLATFORMS_MAP.mobile
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
},
|
|
1341
|
+
/* desktop */
|
|
1342
|
+
{
|
|
1343
|
+
test(parser) {
|
|
1344
|
+
return parser.getOSName(true) === "macos";
|
|
1345
|
+
},
|
|
1346
|
+
describe() {
|
|
1347
|
+
return {
|
|
1348
|
+
type: PLATFORMS_MAP.desktop,
|
|
1349
|
+
vendor: "Apple"
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
},
|
|
1353
|
+
/* Windows */
|
|
1354
|
+
{
|
|
1355
|
+
test(parser) {
|
|
1356
|
+
return parser.getOSName(true) === "windows";
|
|
1357
|
+
},
|
|
1358
|
+
describe() {
|
|
1359
|
+
return {
|
|
1360
|
+
type: PLATFORMS_MAP.desktop
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
},
|
|
1364
|
+
/* Linux */
|
|
1365
|
+
{
|
|
1366
|
+
test(parser) {
|
|
1367
|
+
return parser.getOSName(true) === "linux";
|
|
1368
|
+
},
|
|
1369
|
+
describe() {
|
|
1370
|
+
return {
|
|
1371
|
+
type: PLATFORMS_MAP.desktop
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1375
|
+
/* PlayStation 4 */
|
|
1376
|
+
{
|
|
1377
|
+
test(parser) {
|
|
1378
|
+
return parser.getOSName(true) === "playstation 4";
|
|
1379
|
+
},
|
|
1380
|
+
describe() {
|
|
1381
|
+
return {
|
|
1382
|
+
type: PLATFORMS_MAP.tv
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
/* Roku */
|
|
1387
|
+
{
|
|
1388
|
+
test(parser) {
|
|
1389
|
+
return parser.getOSName(true) === "roku";
|
|
1390
|
+
},
|
|
1391
|
+
describe() {
|
|
1392
|
+
return {
|
|
1393
|
+
type: PLATFORMS_MAP.tv
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
];
|
|
1398
|
+
const enginesParsersList = [
|
|
1399
|
+
/* EdgeHTML */
|
|
1400
|
+
{
|
|
1401
|
+
test(parser) {
|
|
1402
|
+
return parser.getBrowserName(true) === "microsoft edge";
|
|
1403
|
+
},
|
|
1404
|
+
describe(ua) {
|
|
1405
|
+
const isBlinkBased = /\sedg\//i.test(ua);
|
|
1406
|
+
if (isBlinkBased) {
|
|
1407
|
+
return {
|
|
1408
|
+
name: ENGINE_MAP.Blink
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
const version = Utils.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);
|
|
1412
|
+
return {
|
|
1413
|
+
name: ENGINE_MAP.EdgeHTML,
|
|
1414
|
+
version
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
},
|
|
1418
|
+
/* Trident */
|
|
1419
|
+
{
|
|
1420
|
+
test: [/trident/i],
|
|
1421
|
+
describe(ua) {
|
|
1422
|
+
const engine = {
|
|
1423
|
+
name: ENGINE_MAP.Trident
|
|
1424
|
+
};
|
|
1425
|
+
const version = Utils.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
|
|
1426
|
+
if (version) {
|
|
1427
|
+
engine.version = version;
|
|
1428
|
+
}
|
|
1429
|
+
return engine;
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
/* Presto */
|
|
1433
|
+
{
|
|
1434
|
+
test(parser) {
|
|
1435
|
+
return parser.test(/presto/i);
|
|
1436
|
+
},
|
|
1437
|
+
describe(ua) {
|
|
1438
|
+
const engine = {
|
|
1439
|
+
name: ENGINE_MAP.Presto
|
|
1440
|
+
};
|
|
1441
|
+
const version = Utils.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
|
|
1442
|
+
if (version) {
|
|
1443
|
+
engine.version = version;
|
|
1444
|
+
}
|
|
1445
|
+
return engine;
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
/* Gecko */
|
|
1449
|
+
{
|
|
1450
|
+
test(parser) {
|
|
1451
|
+
const isGecko = parser.test(/gecko/i);
|
|
1452
|
+
const likeGecko = parser.test(/like gecko/i);
|
|
1453
|
+
return isGecko && !likeGecko;
|
|
1454
|
+
},
|
|
1455
|
+
describe(ua) {
|
|
1456
|
+
const engine = {
|
|
1457
|
+
name: ENGINE_MAP.Gecko
|
|
1458
|
+
};
|
|
1459
|
+
const version = Utils.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
|
|
1460
|
+
if (version) {
|
|
1461
|
+
engine.version = version;
|
|
1462
|
+
}
|
|
1463
|
+
return engine;
|
|
1464
|
+
}
|
|
1465
|
+
},
|
|
1466
|
+
/* Blink */
|
|
1467
|
+
{
|
|
1468
|
+
test: [/(apple)?webkit\/537\.36/i],
|
|
1469
|
+
describe() {
|
|
1470
|
+
return {
|
|
1471
|
+
name: ENGINE_MAP.Blink
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
},
|
|
1475
|
+
/* WebKit */
|
|
1476
|
+
{
|
|
1477
|
+
test: [/(apple)?webkit/i],
|
|
1478
|
+
describe(ua) {
|
|
1479
|
+
const engine = {
|
|
1480
|
+
name: ENGINE_MAP.WebKit
|
|
1481
|
+
};
|
|
1482
|
+
const version = Utils.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
|
|
1483
|
+
if (version) {
|
|
1484
|
+
engine.version = version;
|
|
1485
|
+
}
|
|
1486
|
+
return engine;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
];
|
|
1490
|
+
class Parser {
|
|
1491
|
+
/**
|
|
1492
|
+
* Create instance of Parser
|
|
1493
|
+
*
|
|
1494
|
+
* @param {String} UA User-Agent string
|
|
1495
|
+
* @param {Boolean} [skipParsing=false] parser can skip parsing in purpose of performance
|
|
1496
|
+
* improvements if you need to make a more particular parsing
|
|
1497
|
+
* like {@link Parser#parseBrowser} or {@link Parser#parsePlatform}
|
|
1498
|
+
*
|
|
1499
|
+
* @throw {Error} in case of empty UA String
|
|
1500
|
+
*
|
|
1501
|
+
* @constructor
|
|
1502
|
+
*/
|
|
1503
|
+
constructor(UA, skipParsing = false) {
|
|
1504
|
+
if (UA === void 0 || UA === null || UA === "") {
|
|
1505
|
+
throw new Error("UserAgent parameter can't be empty");
|
|
1506
|
+
}
|
|
1507
|
+
this._ua = UA;
|
|
1508
|
+
this.parsedResult = {};
|
|
1509
|
+
if (skipParsing !== true) {
|
|
1510
|
+
this.parse();
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Get UserAgent string of current Parser instance
|
|
1515
|
+
* @return {String} User-Agent String of the current <Parser> object
|
|
1516
|
+
*
|
|
1517
|
+
* @public
|
|
1518
|
+
*/
|
|
1519
|
+
getUA() {
|
|
1520
|
+
return this._ua;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Test a UA string for a regexp
|
|
1524
|
+
* @param {RegExp} regex
|
|
1525
|
+
* @return {Boolean}
|
|
1526
|
+
*/
|
|
1527
|
+
test(regex) {
|
|
1528
|
+
return regex.test(this._ua);
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Get parsed browser object
|
|
1532
|
+
* @return {Object}
|
|
1533
|
+
*/
|
|
1534
|
+
parseBrowser() {
|
|
1535
|
+
this.parsedResult.browser = {};
|
|
1536
|
+
const browserDescriptor = Utils.find(browsersList, (_browser) => {
|
|
1537
|
+
if (typeof _browser.test === "function") {
|
|
1538
|
+
return _browser.test(this);
|
|
1539
|
+
}
|
|
1540
|
+
if (_browser.test instanceof Array) {
|
|
1541
|
+
return _browser.test.some((condition) => this.test(condition));
|
|
1542
|
+
}
|
|
1543
|
+
throw new Error("Browser's test function is not valid");
|
|
1544
|
+
});
|
|
1545
|
+
if (browserDescriptor) {
|
|
1546
|
+
this.parsedResult.browser = browserDescriptor.describe(this.getUA());
|
|
1547
|
+
}
|
|
1548
|
+
return this.parsedResult.browser;
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Get parsed browser object
|
|
1552
|
+
* @return {Object}
|
|
1553
|
+
*
|
|
1554
|
+
* @public
|
|
1555
|
+
*/
|
|
1556
|
+
getBrowser() {
|
|
1557
|
+
if (this.parsedResult.browser) {
|
|
1558
|
+
return this.parsedResult.browser;
|
|
1559
|
+
}
|
|
1560
|
+
return this.parseBrowser();
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Get browser's name
|
|
1564
|
+
* @return {String} Browser's name or an empty string
|
|
1565
|
+
*
|
|
1566
|
+
* @public
|
|
1567
|
+
*/
|
|
1568
|
+
getBrowserName(toLowerCase) {
|
|
1569
|
+
if (toLowerCase) {
|
|
1570
|
+
return String(this.getBrowser().name).toLowerCase() || "";
|
|
1571
|
+
}
|
|
1572
|
+
return this.getBrowser().name || "";
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Get browser's version
|
|
1576
|
+
* @return {String} version of browser
|
|
1577
|
+
*
|
|
1578
|
+
* @public
|
|
1579
|
+
*/
|
|
1580
|
+
getBrowserVersion() {
|
|
1581
|
+
return this.getBrowser().version;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Get OS
|
|
1585
|
+
* @return {Object}
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* this.getOS();
|
|
1589
|
+
* {
|
|
1590
|
+
* name: 'macOS',
|
|
1591
|
+
* version: '10.11.12'
|
|
1592
|
+
* }
|
|
1593
|
+
*/
|
|
1594
|
+
getOS() {
|
|
1595
|
+
if (this.parsedResult.os) {
|
|
1596
|
+
return this.parsedResult.os;
|
|
1597
|
+
}
|
|
1598
|
+
return this.parseOS();
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Parse OS and save it to this.parsedResult.os
|
|
1602
|
+
* @return {*|{}}
|
|
1603
|
+
*/
|
|
1604
|
+
parseOS() {
|
|
1605
|
+
this.parsedResult.os = {};
|
|
1606
|
+
const os = Utils.find(osParsersList, (_os) => {
|
|
1607
|
+
if (typeof _os.test === "function") {
|
|
1608
|
+
return _os.test(this);
|
|
1609
|
+
}
|
|
1610
|
+
if (_os.test instanceof Array) {
|
|
1611
|
+
return _os.test.some((condition) => this.test(condition));
|
|
1612
|
+
}
|
|
1613
|
+
throw new Error("Browser's test function is not valid");
|
|
1614
|
+
});
|
|
1615
|
+
if (os) {
|
|
1616
|
+
this.parsedResult.os = os.describe(this.getUA());
|
|
1617
|
+
}
|
|
1618
|
+
return this.parsedResult.os;
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Get OS name
|
|
1622
|
+
* @param {Boolean} [toLowerCase] return lower-cased value
|
|
1623
|
+
* @return {String} name of the OS — macOS, Windows, Linux, etc.
|
|
1624
|
+
*/
|
|
1625
|
+
getOSName(toLowerCase) {
|
|
1626
|
+
const { name } = this.getOS();
|
|
1627
|
+
if (toLowerCase) {
|
|
1628
|
+
return String(name).toLowerCase() || "";
|
|
1629
|
+
}
|
|
1630
|
+
return name || "";
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Get OS version
|
|
1634
|
+
* @return {String} full version with dots ('10.11.12', '5.6', etc)
|
|
1635
|
+
*/
|
|
1636
|
+
getOSVersion() {
|
|
1637
|
+
return this.getOS().version;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Get parsed platform
|
|
1641
|
+
* @return {{}}
|
|
1642
|
+
*/
|
|
1643
|
+
getPlatform() {
|
|
1644
|
+
if (this.parsedResult.platform) {
|
|
1645
|
+
return this.parsedResult.platform;
|
|
1646
|
+
}
|
|
1647
|
+
return this.parsePlatform();
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Get platform name
|
|
1651
|
+
* @param {Boolean} [toLowerCase=false]
|
|
1652
|
+
* @return {*}
|
|
1653
|
+
*/
|
|
1654
|
+
getPlatformType(toLowerCase = false) {
|
|
1655
|
+
const { type } = this.getPlatform();
|
|
1656
|
+
if (toLowerCase) {
|
|
1657
|
+
return String(type).toLowerCase() || "";
|
|
1658
|
+
}
|
|
1659
|
+
return type || "";
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Get parsed platform
|
|
1663
|
+
* @return {{}}
|
|
1664
|
+
*/
|
|
1665
|
+
parsePlatform() {
|
|
1666
|
+
this.parsedResult.platform = {};
|
|
1667
|
+
const platform = Utils.find(platformParsersList, (_platform) => {
|
|
1668
|
+
if (typeof _platform.test === "function") {
|
|
1669
|
+
return _platform.test(this);
|
|
1670
|
+
}
|
|
1671
|
+
if (_platform.test instanceof Array) {
|
|
1672
|
+
return _platform.test.some((condition) => this.test(condition));
|
|
1673
|
+
}
|
|
1674
|
+
throw new Error("Browser's test function is not valid");
|
|
1675
|
+
});
|
|
1676
|
+
if (platform) {
|
|
1677
|
+
this.parsedResult.platform = platform.describe(this.getUA());
|
|
1678
|
+
}
|
|
1679
|
+
return this.parsedResult.platform;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Get parsed engine
|
|
1683
|
+
* @return {{}}
|
|
1684
|
+
*/
|
|
1685
|
+
getEngine() {
|
|
1686
|
+
if (this.parsedResult.engine) {
|
|
1687
|
+
return this.parsedResult.engine;
|
|
1688
|
+
}
|
|
1689
|
+
return this.parseEngine();
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Get engines's name
|
|
1693
|
+
* @return {String} Engines's name or an empty string
|
|
1694
|
+
*
|
|
1695
|
+
* @public
|
|
1696
|
+
*/
|
|
1697
|
+
getEngineName(toLowerCase) {
|
|
1698
|
+
if (toLowerCase) {
|
|
1699
|
+
return String(this.getEngine().name).toLowerCase() || "";
|
|
1700
|
+
}
|
|
1701
|
+
return this.getEngine().name || "";
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Get parsed platform
|
|
1705
|
+
* @return {{}}
|
|
1706
|
+
*/
|
|
1707
|
+
parseEngine() {
|
|
1708
|
+
this.parsedResult.engine = {};
|
|
1709
|
+
const engine = Utils.find(enginesParsersList, (_engine) => {
|
|
1710
|
+
if (typeof _engine.test === "function") {
|
|
1711
|
+
return _engine.test(this);
|
|
1712
|
+
}
|
|
1713
|
+
if (_engine.test instanceof Array) {
|
|
1714
|
+
return _engine.test.some((condition) => this.test(condition));
|
|
1715
|
+
}
|
|
1716
|
+
throw new Error("Browser's test function is not valid");
|
|
1717
|
+
});
|
|
1718
|
+
if (engine) {
|
|
1719
|
+
this.parsedResult.engine = engine.describe(this.getUA());
|
|
1720
|
+
}
|
|
1721
|
+
return this.parsedResult.engine;
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Parse full information about the browser
|
|
1725
|
+
* @returns {Parser}
|
|
1726
|
+
*/
|
|
1727
|
+
parse() {
|
|
1728
|
+
this.parseBrowser();
|
|
1729
|
+
this.parseOS();
|
|
1730
|
+
this.parsePlatform();
|
|
1731
|
+
this.parseEngine();
|
|
1732
|
+
return this;
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Get parsed result
|
|
1736
|
+
* @return {ParsedResult}
|
|
1737
|
+
*/
|
|
1738
|
+
getResult() {
|
|
1739
|
+
return Utils.assign({}, this.parsedResult);
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Check if parsed browser matches certain conditions
|
|
1743
|
+
*
|
|
1744
|
+
* @param {Object} checkTree It's one or two layered object,
|
|
1745
|
+
* which can include a platform or an OS on the first layer
|
|
1746
|
+
* and should have browsers specs on the bottom-laying layer
|
|
1747
|
+
*
|
|
1748
|
+
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
|
|
1749
|
+
* Returns `undefined` when the browser is no described in the checkTree object.
|
|
1750
|
+
*
|
|
1751
|
+
* @example
|
|
1752
|
+
* const browser = Bowser.getParser(window.navigator.userAgent);
|
|
1753
|
+
* if (browser.satisfies({chrome: '>118.01.1322' }))
|
|
1754
|
+
* // or with os
|
|
1755
|
+
* if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
|
|
1756
|
+
* // or with platforms
|
|
1757
|
+
* if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
|
|
1758
|
+
*/
|
|
1759
|
+
satisfies(checkTree) {
|
|
1760
|
+
const platformsAndOSes = {};
|
|
1761
|
+
let platformsAndOSCounter = 0;
|
|
1762
|
+
const browsers = {};
|
|
1763
|
+
let browsersCounter = 0;
|
|
1764
|
+
const allDefinitions = Object.keys(checkTree);
|
|
1765
|
+
allDefinitions.forEach((key) => {
|
|
1766
|
+
const currentDefinition = checkTree[key];
|
|
1767
|
+
if (typeof currentDefinition === "string") {
|
|
1768
|
+
browsers[key] = currentDefinition;
|
|
1769
|
+
browsersCounter += 1;
|
|
1770
|
+
} else if (typeof currentDefinition === "object") {
|
|
1771
|
+
platformsAndOSes[key] = currentDefinition;
|
|
1772
|
+
platformsAndOSCounter += 1;
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
if (platformsAndOSCounter > 0) {
|
|
1776
|
+
const platformsAndOSNames = Object.keys(platformsAndOSes);
|
|
1777
|
+
const OSMatchingDefinition = Utils.find(platformsAndOSNames, (name) => this.isOS(name));
|
|
1778
|
+
if (OSMatchingDefinition) {
|
|
1779
|
+
const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
|
|
1780
|
+
if (osResult !== void 0) {
|
|
1781
|
+
return osResult;
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
const platformMatchingDefinition = Utils.find(
|
|
1785
|
+
platformsAndOSNames,
|
|
1786
|
+
(name) => this.isPlatform(name)
|
|
1787
|
+
);
|
|
1788
|
+
if (platformMatchingDefinition) {
|
|
1789
|
+
const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
|
|
1790
|
+
if (platformResult !== void 0) {
|
|
1791
|
+
return platformResult;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
if (browsersCounter > 0) {
|
|
1796
|
+
const browserNames = Object.keys(browsers);
|
|
1797
|
+
const matchingDefinition = Utils.find(browserNames, (name) => this.isBrowser(name, true));
|
|
1798
|
+
if (matchingDefinition !== void 0) {
|
|
1799
|
+
return this.compareVersion(browsers[matchingDefinition]);
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return void 0;
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Check if the browser name equals the passed string
|
|
1806
|
+
* @param browserName The string to compare with the browser name
|
|
1807
|
+
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
|
|
1808
|
+
* @returns {boolean}
|
|
1809
|
+
*/
|
|
1810
|
+
isBrowser(browserName, includingAlias = false) {
|
|
1811
|
+
const defaultBrowserName = this.getBrowserName().toLowerCase();
|
|
1812
|
+
let browserNameLower = browserName.toLowerCase();
|
|
1813
|
+
const alias = Utils.getBrowserTypeByAlias(browserNameLower);
|
|
1814
|
+
if (includingAlias && alias) {
|
|
1815
|
+
browserNameLower = alias.toLowerCase();
|
|
1816
|
+
}
|
|
1817
|
+
return browserNameLower === defaultBrowserName;
|
|
1818
|
+
}
|
|
1819
|
+
compareVersion(version) {
|
|
1820
|
+
let expectedResults = [0];
|
|
1821
|
+
let comparableVersion = version;
|
|
1822
|
+
let isLoose = false;
|
|
1823
|
+
const currentBrowserVersion = this.getBrowserVersion();
|
|
1824
|
+
if (typeof currentBrowserVersion !== "string") {
|
|
1825
|
+
return void 0;
|
|
1826
|
+
}
|
|
1827
|
+
if (version[0] === ">" || version[0] === "<") {
|
|
1828
|
+
comparableVersion = version.substr(1);
|
|
1829
|
+
if (version[1] === "=") {
|
|
1830
|
+
isLoose = true;
|
|
1831
|
+
comparableVersion = version.substr(2);
|
|
1832
|
+
} else {
|
|
1833
|
+
expectedResults = [];
|
|
1834
|
+
}
|
|
1835
|
+
if (version[0] === ">") {
|
|
1836
|
+
expectedResults.push(1);
|
|
1837
|
+
} else {
|
|
1838
|
+
expectedResults.push(-1);
|
|
1839
|
+
}
|
|
1840
|
+
} else if (version[0] === "=") {
|
|
1841
|
+
comparableVersion = version.substr(1);
|
|
1842
|
+
} else if (version[0] === "~") {
|
|
1843
|
+
isLoose = true;
|
|
1844
|
+
comparableVersion = version.substr(1);
|
|
1845
|
+
}
|
|
1846
|
+
return expectedResults.indexOf(
|
|
1847
|
+
Utils.compareVersions(currentBrowserVersion, comparableVersion, isLoose)
|
|
1848
|
+
) > -1;
|
|
1849
|
+
}
|
|
1850
|
+
isOS(osName) {
|
|
1851
|
+
return this.getOSName(true) === String(osName).toLowerCase();
|
|
1852
|
+
}
|
|
1853
|
+
isPlatform(platformType) {
|
|
1854
|
+
return this.getPlatformType(true) === String(platformType).toLowerCase();
|
|
1855
|
+
}
|
|
1856
|
+
isEngine(engineName) {
|
|
1857
|
+
return this.getEngineName(true) === String(engineName).toLowerCase();
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Is anything? Check if the browser is called "anything",
|
|
1861
|
+
* the OS called "anything" or the platform called "anything"
|
|
1862
|
+
* @param {String} anything
|
|
1863
|
+
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
|
|
1864
|
+
* @returns {Boolean}
|
|
1865
|
+
*/
|
|
1866
|
+
is(anything, includingAlias = false) {
|
|
1867
|
+
return this.isBrowser(anything, includingAlias) || this.isOS(anything) || this.isPlatform(anything);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Check if any of the given values satisfies this.is(anything)
|
|
1871
|
+
* @param {String[]} anythings
|
|
1872
|
+
* @returns {Boolean}
|
|
1873
|
+
*/
|
|
1874
|
+
some(anythings = []) {
|
|
1875
|
+
return anythings.some((anything) => this.is(anything));
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
/*!
|
|
1879
|
+
* Bowser - a browser detector
|
|
1880
|
+
* https://github.com/lancedikson/bowser
|
|
1881
|
+
* MIT License | (c) Dustin Diaz 2012-2015
|
|
1882
|
+
* MIT License | (c) Denis Demchenko 2015-2019
|
|
1883
|
+
*/
|
|
1884
|
+
class Bowser {
|
|
1885
|
+
/**
|
|
1886
|
+
* Creates a {@link Parser} instance
|
|
1887
|
+
*
|
|
1888
|
+
* @param {String} UA UserAgent string
|
|
1889
|
+
* @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it
|
|
1890
|
+
* explicitly. Same as `skipParsing` for {@link Parser}.
|
|
1891
|
+
* @returns {Parser}
|
|
1892
|
+
* @throws {Error} when UA is not a String
|
|
1893
|
+
*
|
|
1894
|
+
* @example
|
|
1895
|
+
* const parser = Bowser.getParser(window.navigator.userAgent);
|
|
1896
|
+
* const result = parser.getResult();
|
|
1897
|
+
*/
|
|
1898
|
+
static getParser(UA, skipParsing = false) {
|
|
1899
|
+
if (typeof UA !== "string") {
|
|
1900
|
+
throw new Error("UserAgent should be a string");
|
|
1901
|
+
}
|
|
1902
|
+
return new Parser(UA, skipParsing);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately
|
|
1906
|
+
*
|
|
1907
|
+
* @param UA
|
|
1908
|
+
* @return {ParsedResult}
|
|
1909
|
+
*
|
|
1910
|
+
* @example
|
|
1911
|
+
* const result = Bowser.parse(window.navigator.userAgent);
|
|
1912
|
+
*/
|
|
1913
|
+
static parse(UA) {
|
|
1914
|
+
return new Parser(UA).getResult();
|
|
1915
|
+
}
|
|
1916
|
+
static get BROWSER_MAP() {
|
|
1917
|
+
return BROWSER_MAP;
|
|
1918
|
+
}
|
|
1919
|
+
static get ENGINE_MAP() {
|
|
1920
|
+
return ENGINE_MAP;
|
|
1921
|
+
}
|
|
1922
|
+
static get OS_MAP() {
|
|
1923
|
+
return OS_MAP;
|
|
1924
|
+
}
|
|
1925
|
+
static get PLATFORMS_MAP() {
|
|
1926
|
+
return PLATFORMS_MAP;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function getDefaultExportFromCjs(x) {
|
|
1930
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
1931
|
+
}
|
|
1932
|
+
var lzString = { exports: {} };
|
|
1933
|
+
var hasRequiredLzString;
|
|
1934
|
+
function requireLzString() {
|
|
1935
|
+
if (hasRequiredLzString) return lzString.exports;
|
|
1936
|
+
hasRequiredLzString = 1;
|
|
1937
|
+
(function(module) {
|
|
1938
|
+
var LZString = function() {
|
|
1939
|
+
var f = String.fromCharCode;
|
|
1940
|
+
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
1941
|
+
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
1942
|
+
var baseReverseDic = {};
|
|
1943
|
+
function getBaseValue(alphabet, character) {
|
|
1944
|
+
if (!baseReverseDic[alphabet]) {
|
|
1945
|
+
baseReverseDic[alphabet] = {};
|
|
1946
|
+
for (var i = 0; i < alphabet.length; i++) {
|
|
1947
|
+
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
return baseReverseDic[alphabet][character];
|
|
1951
|
+
}
|
|
1952
|
+
var LZString2 = {
|
|
1953
|
+
compressToBase64: function(input) {
|
|
1954
|
+
if (input == null) return "";
|
|
1955
|
+
var res = LZString2._compress(input, 6, function(a) {
|
|
1956
|
+
return keyStrBase64.charAt(a);
|
|
1957
|
+
});
|
|
1958
|
+
switch (res.length % 4) {
|
|
1959
|
+
// To produce valid Base64
|
|
1960
|
+
default:
|
|
1961
|
+
// When could this happen ?
|
|
1962
|
+
case 0:
|
|
1963
|
+
return res;
|
|
1964
|
+
case 1:
|
|
1965
|
+
return res + "===";
|
|
1966
|
+
case 2:
|
|
1967
|
+
return res + "==";
|
|
1968
|
+
case 3:
|
|
1969
|
+
return res + "=";
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
decompressFromBase64: function(input) {
|
|
1973
|
+
if (input == null) return "";
|
|
1974
|
+
if (input == "") return null;
|
|
1975
|
+
return LZString2._decompress(input.length, 32, function(index) {
|
|
1976
|
+
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
1977
|
+
});
|
|
1978
|
+
},
|
|
1979
|
+
compressToUTF16: function(input) {
|
|
1980
|
+
if (input == null) return "";
|
|
1981
|
+
return LZString2._compress(input, 15, function(a) {
|
|
1982
|
+
return f(a + 32);
|
|
1983
|
+
}) + " ";
|
|
1984
|
+
},
|
|
1985
|
+
decompressFromUTF16: function(compressed) {
|
|
1986
|
+
if (compressed == null) return "";
|
|
1987
|
+
if (compressed == "") return null;
|
|
1988
|
+
return LZString2._decompress(compressed.length, 16384, function(index) {
|
|
1989
|
+
return compressed.charCodeAt(index) - 32;
|
|
1990
|
+
});
|
|
1991
|
+
},
|
|
1992
|
+
//compress into uint8array (UCS-2 big endian format)
|
|
1993
|
+
compressToUint8Array: function(uncompressed) {
|
|
1994
|
+
var compressed = LZString2.compress(uncompressed);
|
|
1995
|
+
var buf = new Uint8Array(compressed.length * 2);
|
|
1996
|
+
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
1997
|
+
var current_value = compressed.charCodeAt(i);
|
|
1998
|
+
buf[i * 2] = current_value >>> 8;
|
|
1999
|
+
buf[i * 2 + 1] = current_value % 256;
|
|
2000
|
+
}
|
|
2001
|
+
return buf;
|
|
2002
|
+
},
|
|
2003
|
+
//decompress from uint8array (UCS-2 big endian format)
|
|
2004
|
+
decompressFromUint8Array: function(compressed) {
|
|
2005
|
+
if (compressed === null || compressed === void 0) {
|
|
2006
|
+
return LZString2.decompress(compressed);
|
|
2007
|
+
} else {
|
|
2008
|
+
var buf = new Array(compressed.length / 2);
|
|
2009
|
+
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) {
|
|
2010
|
+
buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
|
|
2011
|
+
}
|
|
2012
|
+
var result = [];
|
|
2013
|
+
buf.forEach(function(c) {
|
|
2014
|
+
result.push(f(c));
|
|
2015
|
+
});
|
|
2016
|
+
return LZString2.decompress(result.join(""));
|
|
2017
|
+
}
|
|
2018
|
+
},
|
|
2019
|
+
//compress into a string that is already URI encoded
|
|
2020
|
+
compressToEncodedURIComponent: function(input) {
|
|
2021
|
+
if (input == null) return "";
|
|
2022
|
+
return LZString2._compress(input, 6, function(a) {
|
|
2023
|
+
return keyStrUriSafe.charAt(a);
|
|
2024
|
+
});
|
|
2025
|
+
},
|
|
2026
|
+
//decompress from an output of compressToEncodedURIComponent
|
|
2027
|
+
decompressFromEncodedURIComponent: function(input) {
|
|
2028
|
+
if (input == null) return "";
|
|
2029
|
+
if (input == "") return null;
|
|
2030
|
+
input = input.replace(/ /g, "+");
|
|
2031
|
+
return LZString2._decompress(input.length, 32, function(index) {
|
|
2032
|
+
return getBaseValue(keyStrUriSafe, input.charAt(index));
|
|
2033
|
+
});
|
|
2034
|
+
},
|
|
2035
|
+
compress: function(uncompressed) {
|
|
2036
|
+
return LZString2._compress(uncompressed, 16, function(a) {
|
|
2037
|
+
return f(a);
|
|
2038
|
+
});
|
|
2039
|
+
},
|
|
2040
|
+
_compress: function(uncompressed, bitsPerChar, getCharFromInt) {
|
|
2041
|
+
if (uncompressed == null) return "";
|
|
2042
|
+
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;
|
|
2043
|
+
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
2044
|
+
context_c = uncompressed.charAt(ii);
|
|
2045
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
2046
|
+
context_dictionary[context_c] = context_dictSize++;
|
|
2047
|
+
context_dictionaryToCreate[context_c] = true;
|
|
2048
|
+
}
|
|
2049
|
+
context_wc = context_w + context_c;
|
|
2050
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
|
|
2051
|
+
context_w = context_wc;
|
|
2052
|
+
} else {
|
|
2053
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
2054
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
2055
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2056
|
+
context_data_val = context_data_val << 1;
|
|
2057
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2058
|
+
context_data_position = 0;
|
|
2059
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2060
|
+
context_data_val = 0;
|
|
2061
|
+
} else {
|
|
2062
|
+
context_data_position++;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
value = context_w.charCodeAt(0);
|
|
2066
|
+
for (i = 0; i < 8; i++) {
|
|
2067
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2068
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2069
|
+
context_data_position = 0;
|
|
2070
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2071
|
+
context_data_val = 0;
|
|
2072
|
+
} else {
|
|
2073
|
+
context_data_position++;
|
|
2074
|
+
}
|
|
2075
|
+
value = value >> 1;
|
|
2076
|
+
}
|
|
2077
|
+
} else {
|
|
2078
|
+
value = 1;
|
|
2079
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2080
|
+
context_data_val = context_data_val << 1 | value;
|
|
2081
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2082
|
+
context_data_position = 0;
|
|
2083
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2084
|
+
context_data_val = 0;
|
|
2085
|
+
} else {
|
|
2086
|
+
context_data_position++;
|
|
2087
|
+
}
|
|
2088
|
+
value = 0;
|
|
2089
|
+
}
|
|
2090
|
+
value = context_w.charCodeAt(0);
|
|
2091
|
+
for (i = 0; i < 16; i++) {
|
|
2092
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2093
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2094
|
+
context_data_position = 0;
|
|
2095
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2096
|
+
context_data_val = 0;
|
|
2097
|
+
} else {
|
|
2098
|
+
context_data_position++;
|
|
2099
|
+
}
|
|
2100
|
+
value = value >> 1;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
context_enlargeIn--;
|
|
2104
|
+
if (context_enlargeIn == 0) {
|
|
2105
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2106
|
+
context_numBits++;
|
|
2107
|
+
}
|
|
2108
|
+
delete context_dictionaryToCreate[context_w];
|
|
2109
|
+
} else {
|
|
2110
|
+
value = context_dictionary[context_w];
|
|
2111
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2112
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2113
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2114
|
+
context_data_position = 0;
|
|
2115
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2116
|
+
context_data_val = 0;
|
|
2117
|
+
} else {
|
|
2118
|
+
context_data_position++;
|
|
2119
|
+
}
|
|
2120
|
+
value = value >> 1;
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
context_enlargeIn--;
|
|
2124
|
+
if (context_enlargeIn == 0) {
|
|
2125
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2126
|
+
context_numBits++;
|
|
2127
|
+
}
|
|
2128
|
+
context_dictionary[context_wc] = context_dictSize++;
|
|
2129
|
+
context_w = String(context_c);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
if (context_w !== "") {
|
|
2133
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
2134
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
2135
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2136
|
+
context_data_val = context_data_val << 1;
|
|
2137
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2138
|
+
context_data_position = 0;
|
|
2139
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2140
|
+
context_data_val = 0;
|
|
2141
|
+
} else {
|
|
2142
|
+
context_data_position++;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
value = context_w.charCodeAt(0);
|
|
2146
|
+
for (i = 0; i < 8; i++) {
|
|
2147
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2148
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2149
|
+
context_data_position = 0;
|
|
2150
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2151
|
+
context_data_val = 0;
|
|
2152
|
+
} else {
|
|
2153
|
+
context_data_position++;
|
|
2154
|
+
}
|
|
2155
|
+
value = value >> 1;
|
|
2156
|
+
}
|
|
2157
|
+
} else {
|
|
2158
|
+
value = 1;
|
|
2159
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2160
|
+
context_data_val = context_data_val << 1 | value;
|
|
2161
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2162
|
+
context_data_position = 0;
|
|
2163
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2164
|
+
context_data_val = 0;
|
|
2165
|
+
} else {
|
|
2166
|
+
context_data_position++;
|
|
2167
|
+
}
|
|
2168
|
+
value = 0;
|
|
2169
|
+
}
|
|
2170
|
+
value = context_w.charCodeAt(0);
|
|
2171
|
+
for (i = 0; i < 16; i++) {
|
|
2172
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2173
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2174
|
+
context_data_position = 0;
|
|
2175
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2176
|
+
context_data_val = 0;
|
|
2177
|
+
} else {
|
|
2178
|
+
context_data_position++;
|
|
2179
|
+
}
|
|
2180
|
+
value = value >> 1;
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
context_enlargeIn--;
|
|
2184
|
+
if (context_enlargeIn == 0) {
|
|
2185
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2186
|
+
context_numBits++;
|
|
2187
|
+
}
|
|
2188
|
+
delete context_dictionaryToCreate[context_w];
|
|
2189
|
+
} else {
|
|
2190
|
+
value = context_dictionary[context_w];
|
|
2191
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2192
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2193
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2194
|
+
context_data_position = 0;
|
|
2195
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2196
|
+
context_data_val = 0;
|
|
2197
|
+
} else {
|
|
2198
|
+
context_data_position++;
|
|
2199
|
+
}
|
|
2200
|
+
value = value >> 1;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
context_enlargeIn--;
|
|
2204
|
+
if (context_enlargeIn == 0) {
|
|
2205
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2206
|
+
context_numBits++;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
value = 2;
|
|
2210
|
+
for (i = 0; i < context_numBits; i++) {
|
|
2211
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
2212
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2213
|
+
context_data_position = 0;
|
|
2214
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2215
|
+
context_data_val = 0;
|
|
2216
|
+
} else {
|
|
2217
|
+
context_data_position++;
|
|
2218
|
+
}
|
|
2219
|
+
value = value >> 1;
|
|
2220
|
+
}
|
|
2221
|
+
while (true) {
|
|
2222
|
+
context_data_val = context_data_val << 1;
|
|
2223
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
2224
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
2225
|
+
break;
|
|
2226
|
+
} else context_data_position++;
|
|
2227
|
+
}
|
|
2228
|
+
return context_data.join("");
|
|
2229
|
+
},
|
|
2230
|
+
decompress: function(compressed) {
|
|
2231
|
+
if (compressed == null) return "";
|
|
2232
|
+
if (compressed == "") return null;
|
|
2233
|
+
return LZString2._decompress(compressed.length, 32768, function(index) {
|
|
2234
|
+
return compressed.charCodeAt(index);
|
|
2235
|
+
});
|
|
2236
|
+
},
|
|
2237
|
+
_decompress: function(length, resetValue, getNextValue) {
|
|
2238
|
+
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 };
|
|
2239
|
+
for (i = 0; i < 3; i += 1) {
|
|
2240
|
+
dictionary[i] = i;
|
|
2241
|
+
}
|
|
2242
|
+
bits = 0;
|
|
2243
|
+
maxpower = Math.pow(2, 2);
|
|
2244
|
+
power = 1;
|
|
2245
|
+
while (power != maxpower) {
|
|
2246
|
+
resb = data.val & data.position;
|
|
2247
|
+
data.position >>= 1;
|
|
2248
|
+
if (data.position == 0) {
|
|
2249
|
+
data.position = resetValue;
|
|
2250
|
+
data.val = getNextValue(data.index++);
|
|
2251
|
+
}
|
|
2252
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2253
|
+
power <<= 1;
|
|
2254
|
+
}
|
|
2255
|
+
switch (bits) {
|
|
2256
|
+
case 0:
|
|
2257
|
+
bits = 0;
|
|
2258
|
+
maxpower = Math.pow(2, 8);
|
|
2259
|
+
power = 1;
|
|
2260
|
+
while (power != maxpower) {
|
|
2261
|
+
resb = data.val & data.position;
|
|
2262
|
+
data.position >>= 1;
|
|
2263
|
+
if (data.position == 0) {
|
|
2264
|
+
data.position = resetValue;
|
|
2265
|
+
data.val = getNextValue(data.index++);
|
|
2266
|
+
}
|
|
2267
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2268
|
+
power <<= 1;
|
|
2269
|
+
}
|
|
2270
|
+
c = f(bits);
|
|
2271
|
+
break;
|
|
2272
|
+
case 1:
|
|
2273
|
+
bits = 0;
|
|
2274
|
+
maxpower = Math.pow(2, 16);
|
|
2275
|
+
power = 1;
|
|
2276
|
+
while (power != maxpower) {
|
|
2277
|
+
resb = data.val & data.position;
|
|
2278
|
+
data.position >>= 1;
|
|
2279
|
+
if (data.position == 0) {
|
|
2280
|
+
data.position = resetValue;
|
|
2281
|
+
data.val = getNextValue(data.index++);
|
|
2282
|
+
}
|
|
2283
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2284
|
+
power <<= 1;
|
|
2285
|
+
}
|
|
2286
|
+
c = f(bits);
|
|
2287
|
+
break;
|
|
2288
|
+
case 2:
|
|
2289
|
+
return "";
|
|
2290
|
+
}
|
|
2291
|
+
dictionary[3] = c;
|
|
2292
|
+
w = c;
|
|
2293
|
+
result.push(c);
|
|
2294
|
+
while (true) {
|
|
2295
|
+
if (data.index > length) {
|
|
2296
|
+
return "";
|
|
2297
|
+
}
|
|
2298
|
+
bits = 0;
|
|
2299
|
+
maxpower = Math.pow(2, numBits);
|
|
2300
|
+
power = 1;
|
|
2301
|
+
while (power != maxpower) {
|
|
2302
|
+
resb = data.val & data.position;
|
|
2303
|
+
data.position >>= 1;
|
|
2304
|
+
if (data.position == 0) {
|
|
2305
|
+
data.position = resetValue;
|
|
2306
|
+
data.val = getNextValue(data.index++);
|
|
2307
|
+
}
|
|
2308
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2309
|
+
power <<= 1;
|
|
2310
|
+
}
|
|
2311
|
+
switch (c = bits) {
|
|
2312
|
+
case 0:
|
|
2313
|
+
bits = 0;
|
|
2314
|
+
maxpower = Math.pow(2, 8);
|
|
2315
|
+
power = 1;
|
|
2316
|
+
while (power != maxpower) {
|
|
2317
|
+
resb = data.val & data.position;
|
|
2318
|
+
data.position >>= 1;
|
|
2319
|
+
if (data.position == 0) {
|
|
2320
|
+
data.position = resetValue;
|
|
2321
|
+
data.val = getNextValue(data.index++);
|
|
2322
|
+
}
|
|
2323
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2324
|
+
power <<= 1;
|
|
2325
|
+
}
|
|
2326
|
+
dictionary[dictSize++] = f(bits);
|
|
2327
|
+
c = dictSize - 1;
|
|
2328
|
+
enlargeIn--;
|
|
2329
|
+
break;
|
|
2330
|
+
case 1:
|
|
2331
|
+
bits = 0;
|
|
2332
|
+
maxpower = Math.pow(2, 16);
|
|
2333
|
+
power = 1;
|
|
2334
|
+
while (power != maxpower) {
|
|
2335
|
+
resb = data.val & data.position;
|
|
2336
|
+
data.position >>= 1;
|
|
2337
|
+
if (data.position == 0) {
|
|
2338
|
+
data.position = resetValue;
|
|
2339
|
+
data.val = getNextValue(data.index++);
|
|
2340
|
+
}
|
|
2341
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2342
|
+
power <<= 1;
|
|
2343
|
+
}
|
|
2344
|
+
dictionary[dictSize++] = f(bits);
|
|
2345
|
+
c = dictSize - 1;
|
|
2346
|
+
enlargeIn--;
|
|
2347
|
+
break;
|
|
2348
|
+
case 2:
|
|
2349
|
+
return result.join("");
|
|
2350
|
+
}
|
|
2351
|
+
if (enlargeIn == 0) {
|
|
2352
|
+
enlargeIn = Math.pow(2, numBits);
|
|
2353
|
+
numBits++;
|
|
2354
|
+
}
|
|
2355
|
+
if (dictionary[c]) {
|
|
2356
|
+
entry = dictionary[c];
|
|
2357
|
+
} else {
|
|
2358
|
+
if (c === dictSize) {
|
|
2359
|
+
entry = w + w.charAt(0);
|
|
2360
|
+
} else {
|
|
2361
|
+
return null;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
result.push(entry);
|
|
2365
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
2366
|
+
enlargeIn--;
|
|
2367
|
+
w = entry;
|
|
2368
|
+
if (enlargeIn == 0) {
|
|
2369
|
+
enlargeIn = Math.pow(2, numBits);
|
|
2370
|
+
numBits++;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
return LZString2;
|
|
2376
|
+
}();
|
|
2377
|
+
if (module != null) {
|
|
2378
|
+
module.exports = LZString;
|
|
2379
|
+
} else if (typeof angular !== "undefined" && angular != null) {
|
|
2380
|
+
angular.module("LZString", []).factory("LZString", function() {
|
|
2381
|
+
return LZString;
|
|
2382
|
+
});
|
|
2383
|
+
}
|
|
2384
|
+
})(lzString);
|
|
2385
|
+
return lzString.exports;
|
|
2386
|
+
}
|
|
2387
|
+
var lzStringExports = requireLzString();
|
|
2388
|
+
var loglevel$1 = { exports: {} };
|
|
2389
|
+
var loglevel = loglevel$1.exports;
|
|
2390
|
+
var hasRequiredLoglevel;
|
|
2391
|
+
function requireLoglevel() {
|
|
2392
|
+
if (hasRequiredLoglevel) return loglevel$1.exports;
|
|
2393
|
+
hasRequiredLoglevel = 1;
|
|
2394
|
+
(function(module) {
|
|
2395
|
+
(function(root, definition) {
|
|
2396
|
+
if (module.exports) {
|
|
2397
|
+
module.exports = definition();
|
|
2398
|
+
} else {
|
|
2399
|
+
root.log = definition();
|
|
2400
|
+
}
|
|
2401
|
+
})(loglevel, function() {
|
|
2402
|
+
var noop = function() {
|
|
2403
|
+
};
|
|
2404
|
+
var undefinedType = "undefined";
|
|
2405
|
+
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
2406
|
+
var logMethods = [
|
|
2407
|
+
"trace",
|
|
2408
|
+
"debug",
|
|
2409
|
+
"info",
|
|
2410
|
+
"warn",
|
|
2411
|
+
"error"
|
|
2412
|
+
];
|
|
2413
|
+
var _loggersByName = {};
|
|
2414
|
+
var defaultLogger = null;
|
|
2415
|
+
function bindMethod(obj, methodName) {
|
|
2416
|
+
var method = obj[methodName];
|
|
2417
|
+
if (typeof method.bind === "function") {
|
|
2418
|
+
return method.bind(obj);
|
|
2419
|
+
} else {
|
|
2420
|
+
try {
|
|
2421
|
+
return Function.prototype.bind.call(method, obj);
|
|
2422
|
+
} catch (e) {
|
|
2423
|
+
return function() {
|
|
2424
|
+
return Function.prototype.apply.apply(method, [obj, arguments]);
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
function traceForIE() {
|
|
2430
|
+
if (console.log) {
|
|
2431
|
+
if (console.log.apply) {
|
|
2432
|
+
console.log.apply(console, arguments);
|
|
2433
|
+
} else {
|
|
2434
|
+
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
if (console.trace) console.trace();
|
|
2438
|
+
}
|
|
2439
|
+
function realMethod(methodName) {
|
|
2440
|
+
if (methodName === "debug") {
|
|
2441
|
+
methodName = "log";
|
|
2442
|
+
}
|
|
2443
|
+
if (typeof console === undefinedType) {
|
|
2444
|
+
return false;
|
|
2445
|
+
} else if (methodName === "trace" && isIE) {
|
|
2446
|
+
return traceForIE;
|
|
2447
|
+
} else if (console[methodName] !== void 0) {
|
|
2448
|
+
return bindMethod(console, methodName);
|
|
2449
|
+
} else if (console.log !== void 0) {
|
|
2450
|
+
return bindMethod(console, "log");
|
|
2451
|
+
} else {
|
|
2452
|
+
return noop;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
function replaceLoggingMethods() {
|
|
2456
|
+
var level = this.getLevel();
|
|
2457
|
+
for (var i = 0; i < logMethods.length; i++) {
|
|
2458
|
+
var methodName = logMethods[i];
|
|
2459
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
|
|
2460
|
+
}
|
|
2461
|
+
this.log = this.debug;
|
|
2462
|
+
if (typeof console === undefinedType && level < this.levels.SILENT) {
|
|
2463
|
+
return "No console available for logging";
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
function enableLoggingWhenConsoleArrives(methodName) {
|
|
2467
|
+
return function() {
|
|
2468
|
+
if (typeof console !== undefinedType) {
|
|
2469
|
+
replaceLoggingMethods.call(this);
|
|
2470
|
+
this[methodName].apply(this, arguments);
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
function defaultMethodFactory(methodName, _level, _loggerName) {
|
|
2475
|
+
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
2476
|
+
}
|
|
2477
|
+
function Logger(name, factory) {
|
|
2478
|
+
var self = this;
|
|
2479
|
+
var inheritedLevel;
|
|
2480
|
+
var defaultLevel;
|
|
2481
|
+
var userLevel;
|
|
2482
|
+
var storageKey = "loglevel";
|
|
2483
|
+
if (typeof name === "string") {
|
|
2484
|
+
storageKey += ":" + name;
|
|
2485
|
+
} else if (typeof name === "symbol") {
|
|
2486
|
+
storageKey = void 0;
|
|
2487
|
+
}
|
|
2488
|
+
function persistLevelIfPossible(levelNum) {
|
|
2489
|
+
var levelName = (logMethods[levelNum] || "silent").toUpperCase();
|
|
2490
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
2491
|
+
try {
|
|
2492
|
+
window.localStorage[storageKey] = levelName;
|
|
2493
|
+
return;
|
|
2494
|
+
} catch (ignore) {
|
|
2495
|
+
}
|
|
2496
|
+
try {
|
|
2497
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
2498
|
+
} catch (ignore) {
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
function getPersistedLevel() {
|
|
2502
|
+
var storedLevel;
|
|
2503
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
2504
|
+
try {
|
|
2505
|
+
storedLevel = window.localStorage[storageKey];
|
|
2506
|
+
} catch (ignore) {
|
|
2507
|
+
}
|
|
2508
|
+
if (typeof storedLevel === undefinedType) {
|
|
2509
|
+
try {
|
|
2510
|
+
var cookie = window.document.cookie;
|
|
2511
|
+
var cookieName = encodeURIComponent(storageKey);
|
|
2512
|
+
var location = cookie.indexOf(cookieName + "=");
|
|
2513
|
+
if (location !== -1) {
|
|
2514
|
+
storedLevel = /^([^;]+)/.exec(
|
|
2515
|
+
cookie.slice(location + cookieName.length + 1)
|
|
2516
|
+
)[1];
|
|
2517
|
+
}
|
|
2518
|
+
} catch (ignore) {
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
if (self.levels[storedLevel] === void 0) {
|
|
2522
|
+
storedLevel = void 0;
|
|
2523
|
+
}
|
|
2524
|
+
return storedLevel;
|
|
2525
|
+
}
|
|
2526
|
+
function clearPersistedLevel() {
|
|
2527
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
2528
|
+
try {
|
|
2529
|
+
window.localStorage.removeItem(storageKey);
|
|
2530
|
+
} catch (ignore) {
|
|
2531
|
+
}
|
|
2532
|
+
try {
|
|
2533
|
+
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
2534
|
+
} catch (ignore) {
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
function normalizeLevel(input) {
|
|
2538
|
+
var level = input;
|
|
2539
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== void 0) {
|
|
2540
|
+
level = self.levels[level.toUpperCase()];
|
|
2541
|
+
}
|
|
2542
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
2543
|
+
return level;
|
|
2544
|
+
} else {
|
|
2545
|
+
throw new TypeError("log.setLevel() called with invalid level: " + input);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
self.name = name;
|
|
2549
|
+
self.levels = {
|
|
2550
|
+
"TRACE": 0,
|
|
2551
|
+
"DEBUG": 1,
|
|
2552
|
+
"INFO": 2,
|
|
2553
|
+
"WARN": 3,
|
|
2554
|
+
"ERROR": 4,
|
|
2555
|
+
"SILENT": 5
|
|
2556
|
+
};
|
|
2557
|
+
self.methodFactory = factory || defaultMethodFactory;
|
|
2558
|
+
self.getLevel = function() {
|
|
2559
|
+
if (userLevel != null) {
|
|
2560
|
+
return userLevel;
|
|
2561
|
+
} else if (defaultLevel != null) {
|
|
2562
|
+
return defaultLevel;
|
|
2563
|
+
} else {
|
|
2564
|
+
return inheritedLevel;
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
self.setLevel = function(level, persist) {
|
|
2568
|
+
userLevel = normalizeLevel(level);
|
|
2569
|
+
if (persist !== false) {
|
|
2570
|
+
persistLevelIfPossible(userLevel);
|
|
2571
|
+
}
|
|
2572
|
+
return replaceLoggingMethods.call(self);
|
|
2573
|
+
};
|
|
2574
|
+
self.setDefaultLevel = function(level) {
|
|
2575
|
+
defaultLevel = normalizeLevel(level);
|
|
2576
|
+
if (!getPersistedLevel()) {
|
|
2577
|
+
self.setLevel(level, false);
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
self.resetLevel = function() {
|
|
2581
|
+
userLevel = null;
|
|
2582
|
+
clearPersistedLevel();
|
|
2583
|
+
replaceLoggingMethods.call(self);
|
|
2584
|
+
};
|
|
2585
|
+
self.enableAll = function(persist) {
|
|
2586
|
+
self.setLevel(self.levels.TRACE, persist);
|
|
2587
|
+
};
|
|
2588
|
+
self.disableAll = function(persist) {
|
|
2589
|
+
self.setLevel(self.levels.SILENT, persist);
|
|
2590
|
+
};
|
|
2591
|
+
self.rebuild = function() {
|
|
2592
|
+
if (defaultLogger !== self) {
|
|
2593
|
+
inheritedLevel = normalizeLevel(defaultLogger.getLevel());
|
|
2594
|
+
}
|
|
2595
|
+
replaceLoggingMethods.call(self);
|
|
2596
|
+
if (defaultLogger === self) {
|
|
2597
|
+
for (var childName in _loggersByName) {
|
|
2598
|
+
_loggersByName[childName].rebuild();
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
};
|
|
2602
|
+
inheritedLevel = normalizeLevel(
|
|
2603
|
+
defaultLogger ? defaultLogger.getLevel() : "WARN"
|
|
2604
|
+
);
|
|
2605
|
+
var initialLevel = getPersistedLevel();
|
|
2606
|
+
if (initialLevel != null) {
|
|
2607
|
+
userLevel = normalizeLevel(initialLevel);
|
|
2608
|
+
}
|
|
2609
|
+
replaceLoggingMethods.call(self);
|
|
2610
|
+
}
|
|
2611
|
+
defaultLogger = new Logger();
|
|
2612
|
+
defaultLogger.getLogger = function getLogger(name) {
|
|
2613
|
+
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
2614
|
+
throw new TypeError("You must supply a name when creating a logger.");
|
|
2615
|
+
}
|
|
2616
|
+
var logger = _loggersByName[name];
|
|
2617
|
+
if (!logger) {
|
|
2618
|
+
logger = _loggersByName[name] = new Logger(
|
|
2619
|
+
name,
|
|
2620
|
+
defaultLogger.methodFactory
|
|
2621
|
+
);
|
|
2622
|
+
}
|
|
2623
|
+
return logger;
|
|
2624
|
+
};
|
|
2625
|
+
var _log = typeof window !== undefinedType ? window.log : void 0;
|
|
2626
|
+
defaultLogger.noConflict = function() {
|
|
2627
|
+
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
2628
|
+
window.log = _log;
|
|
2629
|
+
}
|
|
2630
|
+
return defaultLogger;
|
|
2631
|
+
};
|
|
2632
|
+
defaultLogger.getLoggers = function getLoggers() {
|
|
2633
|
+
return _loggersByName;
|
|
2634
|
+
};
|
|
2635
|
+
defaultLogger["default"] = defaultLogger;
|
|
2636
|
+
return defaultLogger;
|
|
2637
|
+
});
|
|
2638
|
+
})(loglevel$1);
|
|
2639
|
+
return loglevel$1.exports;
|
|
2640
|
+
}
|
|
2641
|
+
var loglevelExports = requireLoglevel();
|
|
2642
|
+
const log = /* @__PURE__ */ getDefaultExportFromCjs(loglevelExports);
|
|
2643
|
+
const CURRENT_VERSION = "0.0.1";
|
|
2644
|
+
const VITESSCE_CONF_QUERY_STRING = "vitessce_conf";
|
|
2645
|
+
const VERSION_QUERY_STRING = "vitessce_conf_version";
|
|
2646
|
+
const LENGTH_QUERY_STRING = "vitessce_conf_length";
|
|
2647
|
+
function sniffBrowser() {
|
|
2648
|
+
const { browser } = Bowser.parse(window.navigator.userAgent);
|
|
2649
|
+
return browser.name;
|
|
2650
|
+
}
|
|
2651
|
+
const MAX_BROWSER_URL_LENGTHS = {
|
|
2652
|
+
Chrome: 32779,
|
|
2653
|
+
"Internet Explorer": 2047,
|
|
2654
|
+
Edge: 2047,
|
|
2655
|
+
Safari: 65e3,
|
|
2656
|
+
Firefox: 65e3
|
|
2657
|
+
};
|
|
2658
|
+
class CompressedConfLengthError {
|
|
2659
|
+
constructor(message) {
|
|
2660
|
+
this.message = message;
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
function encodeConfInUrl({
|
|
2664
|
+
conf,
|
|
2665
|
+
onOverMaximumUrlLength = () => {
|
|
2666
|
+
}
|
|
2667
|
+
}) {
|
|
2668
|
+
const compressedConf = lzStringExports.compressToEncodedURIComponent(JSON.stringify(conf));
|
|
2669
|
+
const newParams = `${LENGTH_QUERY_STRING}=${compressedConf.length}&${VERSION_QUERY_STRING}=${CURRENT_VERSION}&${VITESSCE_CONF_QUERY_STRING}=${compressedConf}`;
|
|
2670
|
+
const browser = sniffBrowser();
|
|
2671
|
+
const maxLength = MAX_BROWSER_URL_LENGTHS[browser];
|
|
2672
|
+
if (newParams.length > maxLength) {
|
|
2673
|
+
const willWorkOn = Object.entries(MAX_BROWSER_URL_LENGTHS).filter((entry) => entry[1] > newParams.length).map((entry) => entry[0]);
|
|
2674
|
+
const message = `Configuration is ${compressedConf.length} characters; max URL for ${browser} is ${maxLength}: it will work on ${willWorkOn.join(", ") || "no browser"}.`;
|
|
2675
|
+
log.error(message);
|
|
2676
|
+
onOverMaximumUrlLength({ message, willWorkOn });
|
|
2677
|
+
}
|
|
2678
|
+
return newParams;
|
|
2679
|
+
}
|
|
2680
|
+
function decodeURLParamsToConf(queryString) {
|
|
2681
|
+
const params = new URLSearchParams(queryString.replace("#", "&"));
|
|
2682
|
+
const compressedConfString = params.get(VITESSCE_CONF_QUERY_STRING);
|
|
2683
|
+
const expectedConfLength = Number(params.get(LENGTH_QUERY_STRING));
|
|
2684
|
+
if (expectedConfLength !== compressedConfString.length) {
|
|
2685
|
+
throw new CompressedConfLengthError(`Compressed conf length (${compressedConfString.length}) != expected (${expectedConfLength}). URL truncated?`);
|
|
2686
|
+
}
|
|
2687
|
+
const version = params.get(VERSION_QUERY_STRING);
|
|
2688
|
+
if (version === CURRENT_VERSION) {
|
|
2689
|
+
const conf = JSON.parse(lzStringExports.decompressFromEncodedURIComponent(compressedConfString));
|
|
2690
|
+
return conf;
|
|
2691
|
+
}
|
|
2692
|
+
throw new Error("Unrecognized URL Param Version");
|
|
2693
|
+
}
|
|
2694
|
+
export {
|
|
2695
|
+
decodeURLParamsToConf,
|
|
2696
|
+
encodeConfInUrl
|
|
2697
|
+
};
|