@vitessce/export-utils 2.0.3 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.mjs → index.js} +346 -2
- package/dist-tsc/export-utils.d.ts +28 -0
- package/dist-tsc/export-utils.d.ts.map +1 -0
- package/dist-tsc/export-utils.js +70 -0
- package/dist-tsc/export-utils.test.d.ts +2 -0
- package/dist-tsc/export-utils.test.d.ts.map +1 -0
- package/dist-tsc/export-utils.test.js +64 -0
- package/dist-tsc/index.d.ts +2 -0
- package/dist-tsc/index.d.ts.map +1 -0
- package/dist-tsc/index.js +1 -1
- package/package.json +13 -4
- package/src/export-utils.test.js +2 -1
- package/src/index.js +1 -1
|
@@ -109,14 +109,33 @@ const ENGINE_MAP = {
|
|
|
109
109
|
WebKit: "WebKit"
|
|
110
110
|
};
|
|
111
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
|
+
*/
|
|
112
118
|
static getFirstMatch(regexp, ua) {
|
|
113
119
|
const match = ua.match(regexp);
|
|
114
120
|
return match && match.length > 0 && match[1] || "";
|
|
115
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
|
+
*/
|
|
116
128
|
static getSecondMatch(regexp, ua) {
|
|
117
129
|
const match = ua.match(regexp);
|
|
118
130
|
return match && match.length > 1 && match[2] || "";
|
|
119
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
|
+
*/
|
|
120
139
|
static matchAndReturnConst(regexp, ua, _const) {
|
|
121
140
|
if (regexp.test(ua)) {
|
|
122
141
|
return _const;
|
|
@@ -149,6 +168,26 @@ class Utils {
|
|
|
149
168
|
return void 0;
|
|
150
169
|
}
|
|
151
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
|
+
*/
|
|
152
191
|
static getMacOSVersionName(version) {
|
|
153
192
|
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
|
|
154
193
|
v.push(0);
|
|
@@ -181,6 +220,30 @@ class Utils {
|
|
|
181
220
|
return void 0;
|
|
182
221
|
}
|
|
183
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Get Android version name
|
|
225
|
+
* 1.5 - Cupcake
|
|
226
|
+
* 1.6 - Donut
|
|
227
|
+
* 2.0 - Eclair
|
|
228
|
+
* 2.1 - Eclair
|
|
229
|
+
* 2.2 - Froyo
|
|
230
|
+
* 2.x - Gingerbread
|
|
231
|
+
* 3.x - Honeycomb
|
|
232
|
+
* 4.0 - Ice Cream Sandwich
|
|
233
|
+
* 4.1 - Jelly Bean
|
|
234
|
+
* 4.4 - KitKat
|
|
235
|
+
* 5.x - Lollipop
|
|
236
|
+
* 6.x - Marshmallow
|
|
237
|
+
* 7.x - Nougat
|
|
238
|
+
* 8.x - Oreo
|
|
239
|
+
* 9.x - Pie
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* getAndroidVersionName("7.0") // 'Nougat'
|
|
243
|
+
*
|
|
244
|
+
* @param {string} version
|
|
245
|
+
* @return {string} versionName
|
|
246
|
+
*/
|
|
184
247
|
static getAndroidVersionName(version) {
|
|
185
248
|
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
|
|
186
249
|
v.push(0);
|
|
@@ -216,9 +279,35 @@ class Utils {
|
|
|
216
279
|
return "Pie";
|
|
217
280
|
return void 0;
|
|
218
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Get version precisions count
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* getVersionPrecision("1.10.3") // 3
|
|
287
|
+
*
|
|
288
|
+
* @param {string} version
|
|
289
|
+
* @return {number}
|
|
290
|
+
*/
|
|
219
291
|
static getVersionPrecision(version) {
|
|
220
292
|
return version.split(".").length;
|
|
221
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Calculate browser version weight
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* compareVersions('1.10.2.1', '1.8.2.1.90') // 1
|
|
299
|
+
* compareVersions('1.010.2.1', '1.09.2.1.90'); // 1
|
|
300
|
+
* compareVersions('1.10.2.1', '1.10.2.1'); // 0
|
|
301
|
+
* compareVersions('1.10.2.1', '1.0800.2'); // -1
|
|
302
|
+
* compareVersions('1.10.2.1', '1.10', true); // 0
|
|
303
|
+
*
|
|
304
|
+
* @param {String} versionA versions versions to compare
|
|
305
|
+
* @param {String} versionB versions versions to compare
|
|
306
|
+
* @param {boolean} [isLoose] enable loose comparison
|
|
307
|
+
* @return {Number} comparison result: -1 when versionA is lower,
|
|
308
|
+
* 1 when versionA is bigger, 0 when both equal
|
|
309
|
+
*/
|
|
310
|
+
/* eslint consistent-return: 1 */
|
|
222
311
|
static compareVersions(versionA, versionB, isLoose = false) {
|
|
223
312
|
const versionAPrecision = Utils.getVersionPrecision(versionA);
|
|
224
313
|
const versionBPrecision = Utils.getVersionPrecision(versionB);
|
|
@@ -248,6 +337,13 @@ class Utils {
|
|
|
248
337
|
}
|
|
249
338
|
return void 0;
|
|
250
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Array::map polyfill
|
|
342
|
+
*
|
|
343
|
+
* @param {Array} arr
|
|
344
|
+
* @param {Function} iterator
|
|
345
|
+
* @return {Array}
|
|
346
|
+
*/
|
|
251
347
|
static map(arr, iterator) {
|
|
252
348
|
const result = [];
|
|
253
349
|
let i;
|
|
@@ -259,6 +355,13 @@ class Utils {
|
|
|
259
355
|
}
|
|
260
356
|
return result;
|
|
261
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Array::find polyfill
|
|
360
|
+
*
|
|
361
|
+
* @param {Array} arr
|
|
362
|
+
* @param {Function} predicate
|
|
363
|
+
* @return {Array}
|
|
364
|
+
*/
|
|
262
365
|
static find(arr, predicate) {
|
|
263
366
|
let i;
|
|
264
367
|
let l;
|
|
@@ -273,6 +376,13 @@ class Utils {
|
|
|
273
376
|
}
|
|
274
377
|
return void 0;
|
|
275
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* Object::assign polyfill
|
|
381
|
+
*
|
|
382
|
+
* @param {Object} obj
|
|
383
|
+
* @param {Object} ...objs
|
|
384
|
+
* @return {Object}
|
|
385
|
+
*/
|
|
276
386
|
static assign(obj, ...assigners) {
|
|
277
387
|
const result = obj;
|
|
278
388
|
let i;
|
|
@@ -291,15 +401,34 @@ class Utils {
|
|
|
291
401
|
}
|
|
292
402
|
return obj;
|
|
293
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Get short version/alias for a browser name
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* getBrowserAlias('Microsoft Edge') // edge
|
|
409
|
+
*
|
|
410
|
+
* @param {string} browserName
|
|
411
|
+
* @return {string}
|
|
412
|
+
*/
|
|
294
413
|
static getBrowserAlias(browserName) {
|
|
295
414
|
return BROWSER_ALIASES_MAP[browserName];
|
|
296
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Get short version/alias for a browser name
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* getBrowserAlias('edge') // Microsoft Edge
|
|
421
|
+
*
|
|
422
|
+
* @param {string} browserAlias
|
|
423
|
+
* @return {string}
|
|
424
|
+
*/
|
|
297
425
|
static getBrowserTypeByAlias(browserAlias) {
|
|
298
426
|
return BROWSER_MAP[browserAlias] || "";
|
|
299
427
|
}
|
|
300
428
|
}
|
|
301
429
|
const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
|
|
302
430
|
const browsersList = [
|
|
431
|
+
/* Googlebot */
|
|
303
432
|
{
|
|
304
433
|
test: [/googlebot/i],
|
|
305
434
|
describe(ua) {
|
|
@@ -313,6 +442,7 @@ const browsersList = [
|
|
|
313
442
|
return browser;
|
|
314
443
|
}
|
|
315
444
|
},
|
|
445
|
+
/* Opera < 13.0 */
|
|
316
446
|
{
|
|
317
447
|
test: [/opera/i],
|
|
318
448
|
describe(ua) {
|
|
@@ -326,6 +456,7 @@ const browsersList = [
|
|
|
326
456
|
return browser;
|
|
327
457
|
}
|
|
328
458
|
},
|
|
459
|
+
/* Opera > 13.0 */
|
|
329
460
|
{
|
|
330
461
|
test: [/opr\/|opios/i],
|
|
331
462
|
describe(ua) {
|
|
@@ -807,6 +938,7 @@ const browsersList = [
|
|
|
807
938
|
return browser;
|
|
808
939
|
}
|
|
809
940
|
},
|
|
941
|
+
/* Android Browser */
|
|
810
942
|
{
|
|
811
943
|
test(parser) {
|
|
812
944
|
const notLikeAndroid = !parser.test(/like android/i);
|
|
@@ -824,6 +956,7 @@ const browsersList = [
|
|
|
824
956
|
return browser;
|
|
825
957
|
}
|
|
826
958
|
},
|
|
959
|
+
/* PlayStation 4 */
|
|
827
960
|
{
|
|
828
961
|
test: [/playstation 4/i],
|
|
829
962
|
describe(ua) {
|
|
@@ -837,6 +970,7 @@ const browsersList = [
|
|
|
837
970
|
return browser;
|
|
838
971
|
}
|
|
839
972
|
},
|
|
973
|
+
/* Safari */
|
|
840
974
|
{
|
|
841
975
|
test: [/safari|applewebkit/i],
|
|
842
976
|
describe(ua) {
|
|
@@ -850,6 +984,7 @@ const browsersList = [
|
|
|
850
984
|
return browser;
|
|
851
985
|
}
|
|
852
986
|
},
|
|
987
|
+
/* Something else */
|
|
853
988
|
{
|
|
854
989
|
test: [/.*/i],
|
|
855
990
|
describe(ua) {
|
|
@@ -865,6 +1000,7 @@ const browsersList = [
|
|
|
865
1000
|
}
|
|
866
1001
|
];
|
|
867
1002
|
const osParsersList = [
|
|
1003
|
+
/* Roku */
|
|
868
1004
|
{
|
|
869
1005
|
test: [/Roku\/DVP/],
|
|
870
1006
|
describe(ua) {
|
|
@@ -875,6 +1011,7 @@ const osParsersList = [
|
|
|
875
1011
|
};
|
|
876
1012
|
}
|
|
877
1013
|
},
|
|
1014
|
+
/* Windows Phone */
|
|
878
1015
|
{
|
|
879
1016
|
test: [/windows phone/i],
|
|
880
1017
|
describe(ua) {
|
|
@@ -885,6 +1022,7 @@ const osParsersList = [
|
|
|
885
1022
|
};
|
|
886
1023
|
}
|
|
887
1024
|
},
|
|
1025
|
+
/* Windows */
|
|
888
1026
|
{
|
|
889
1027
|
test: [/windows /i],
|
|
890
1028
|
describe(ua) {
|
|
@@ -897,6 +1035,7 @@ const osParsersList = [
|
|
|
897
1035
|
};
|
|
898
1036
|
}
|
|
899
1037
|
},
|
|
1038
|
+
/* Firefox on iPad */
|
|
900
1039
|
{
|
|
901
1040
|
test: [/Macintosh(.*?) FxiOS(.*?)\//],
|
|
902
1041
|
describe(ua) {
|
|
@@ -910,6 +1049,7 @@ const osParsersList = [
|
|
|
910
1049
|
return result;
|
|
911
1050
|
}
|
|
912
1051
|
},
|
|
1052
|
+
/* macOS */
|
|
913
1053
|
{
|
|
914
1054
|
test: [/macintosh/i],
|
|
915
1055
|
describe(ua) {
|
|
@@ -925,6 +1065,7 @@ const osParsersList = [
|
|
|
925
1065
|
return os;
|
|
926
1066
|
}
|
|
927
1067
|
},
|
|
1068
|
+
/* iOS */
|
|
928
1069
|
{
|
|
929
1070
|
test: [/(ipod|iphone|ipad)/i],
|
|
930
1071
|
describe(ua) {
|
|
@@ -935,6 +1076,7 @@ const osParsersList = [
|
|
|
935
1076
|
};
|
|
936
1077
|
}
|
|
937
1078
|
},
|
|
1079
|
+
/* Android */
|
|
938
1080
|
{
|
|
939
1081
|
test(parser) {
|
|
940
1082
|
const notLikeAndroid = !parser.test(/like android/i);
|
|
@@ -954,6 +1096,7 @@ const osParsersList = [
|
|
|
954
1096
|
return os;
|
|
955
1097
|
}
|
|
956
1098
|
},
|
|
1099
|
+
/* WebOS */
|
|
957
1100
|
{
|
|
958
1101
|
test: [/(web|hpw)[o0]s/i],
|
|
959
1102
|
describe(ua) {
|
|
@@ -967,6 +1110,7 @@ const osParsersList = [
|
|
|
967
1110
|
return os;
|
|
968
1111
|
}
|
|
969
1112
|
},
|
|
1113
|
+
/* BlackBerry */
|
|
970
1114
|
{
|
|
971
1115
|
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
|
|
972
1116
|
describe(ua) {
|
|
@@ -977,6 +1121,7 @@ const osParsersList = [
|
|
|
977
1121
|
};
|
|
978
1122
|
}
|
|
979
1123
|
},
|
|
1124
|
+
/* Bada */
|
|
980
1125
|
{
|
|
981
1126
|
test: [/bada/i],
|
|
982
1127
|
describe(ua) {
|
|
@@ -987,6 +1132,7 @@ const osParsersList = [
|
|
|
987
1132
|
};
|
|
988
1133
|
}
|
|
989
1134
|
},
|
|
1135
|
+
/* Tizen */
|
|
990
1136
|
{
|
|
991
1137
|
test: [/tizen/i],
|
|
992
1138
|
describe(ua) {
|
|
@@ -997,6 +1143,7 @@ const osParsersList = [
|
|
|
997
1143
|
};
|
|
998
1144
|
}
|
|
999
1145
|
},
|
|
1146
|
+
/* Linux */
|
|
1000
1147
|
{
|
|
1001
1148
|
test: [/linux/i],
|
|
1002
1149
|
describe() {
|
|
@@ -1005,6 +1152,7 @@ const osParsersList = [
|
|
|
1005
1152
|
};
|
|
1006
1153
|
}
|
|
1007
1154
|
},
|
|
1155
|
+
/* Chrome OS */
|
|
1008
1156
|
{
|
|
1009
1157
|
test: [/CrOS/],
|
|
1010
1158
|
describe() {
|
|
@@ -1013,6 +1161,7 @@ const osParsersList = [
|
|
|
1013
1161
|
};
|
|
1014
1162
|
}
|
|
1015
1163
|
},
|
|
1164
|
+
/* Playstation 4 */
|
|
1016
1165
|
{
|
|
1017
1166
|
test: [/PlayStation 4/],
|
|
1018
1167
|
describe(ua) {
|
|
@@ -1025,6 +1174,7 @@ const osParsersList = [
|
|
|
1025
1174
|
}
|
|
1026
1175
|
];
|
|
1027
1176
|
const platformParsersList = [
|
|
1177
|
+
/* Googlebot */
|
|
1028
1178
|
{
|
|
1029
1179
|
test: [/googlebot/i],
|
|
1030
1180
|
describe() {
|
|
@@ -1034,6 +1184,7 @@ const platformParsersList = [
|
|
|
1034
1184
|
};
|
|
1035
1185
|
}
|
|
1036
1186
|
},
|
|
1187
|
+
/* Huawei */
|
|
1037
1188
|
{
|
|
1038
1189
|
test: [/huawei/i],
|
|
1039
1190
|
describe(ua) {
|
|
@@ -1048,6 +1199,7 @@ const platformParsersList = [
|
|
|
1048
1199
|
return platform;
|
|
1049
1200
|
}
|
|
1050
1201
|
},
|
|
1202
|
+
/* Nexus Tablet */
|
|
1051
1203
|
{
|
|
1052
1204
|
test: [/nexus\s*(?:7|8|9|10).*/i],
|
|
1053
1205
|
describe() {
|
|
@@ -1057,6 +1209,7 @@ const platformParsersList = [
|
|
|
1057
1209
|
};
|
|
1058
1210
|
}
|
|
1059
1211
|
},
|
|
1212
|
+
/* iPad */
|
|
1060
1213
|
{
|
|
1061
1214
|
test: [/ipad/i],
|
|
1062
1215
|
describe() {
|
|
@@ -1067,6 +1220,7 @@ const platformParsersList = [
|
|
|
1067
1220
|
};
|
|
1068
1221
|
}
|
|
1069
1222
|
},
|
|
1223
|
+
/* Firefox on iPad */
|
|
1070
1224
|
{
|
|
1071
1225
|
test: [/Macintosh(.*?) FxiOS(.*?)\//],
|
|
1072
1226
|
describe() {
|
|
@@ -1077,6 +1231,7 @@ const platformParsersList = [
|
|
|
1077
1231
|
};
|
|
1078
1232
|
}
|
|
1079
1233
|
},
|
|
1234
|
+
/* Amazon Kindle Fire */
|
|
1080
1235
|
{
|
|
1081
1236
|
test: [/kftt build/i],
|
|
1082
1237
|
describe() {
|
|
@@ -1087,6 +1242,7 @@ const platformParsersList = [
|
|
|
1087
1242
|
};
|
|
1088
1243
|
}
|
|
1089
1244
|
},
|
|
1245
|
+
/* Another Amazon Tablet with Silk */
|
|
1090
1246
|
{
|
|
1091
1247
|
test: [/silk/i],
|
|
1092
1248
|
describe() {
|
|
@@ -1096,6 +1252,7 @@ const platformParsersList = [
|
|
|
1096
1252
|
};
|
|
1097
1253
|
}
|
|
1098
1254
|
},
|
|
1255
|
+
/* Tablet */
|
|
1099
1256
|
{
|
|
1100
1257
|
test: [/tablet(?! pc)/i],
|
|
1101
1258
|
describe() {
|
|
@@ -1104,6 +1261,7 @@ const platformParsersList = [
|
|
|
1104
1261
|
};
|
|
1105
1262
|
}
|
|
1106
1263
|
},
|
|
1264
|
+
/* iPod/iPhone */
|
|
1107
1265
|
{
|
|
1108
1266
|
test(parser) {
|
|
1109
1267
|
const iDevice = parser.test(/ipod|iphone/i);
|
|
@@ -1119,6 +1277,7 @@ const platformParsersList = [
|
|
|
1119
1277
|
};
|
|
1120
1278
|
}
|
|
1121
1279
|
},
|
|
1280
|
+
/* Nexus Mobile */
|
|
1122
1281
|
{
|
|
1123
1282
|
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
|
|
1124
1283
|
describe() {
|
|
@@ -1128,6 +1287,7 @@ const platformParsersList = [
|
|
|
1128
1287
|
};
|
|
1129
1288
|
}
|
|
1130
1289
|
},
|
|
1290
|
+
/* Mobile */
|
|
1131
1291
|
{
|
|
1132
1292
|
test: [/[^-]mobi/i],
|
|
1133
1293
|
describe() {
|
|
@@ -1136,6 +1296,7 @@ const platformParsersList = [
|
|
|
1136
1296
|
};
|
|
1137
1297
|
}
|
|
1138
1298
|
},
|
|
1299
|
+
/* BlackBerry */
|
|
1139
1300
|
{
|
|
1140
1301
|
test(parser) {
|
|
1141
1302
|
return parser.getBrowserName(true) === "blackberry";
|
|
@@ -1147,6 +1308,7 @@ const platformParsersList = [
|
|
|
1147
1308
|
};
|
|
1148
1309
|
}
|
|
1149
1310
|
},
|
|
1311
|
+
/* Bada */
|
|
1150
1312
|
{
|
|
1151
1313
|
test(parser) {
|
|
1152
1314
|
return parser.getBrowserName(true) === "bada";
|
|
@@ -1157,6 +1319,7 @@ const platformParsersList = [
|
|
|
1157
1319
|
};
|
|
1158
1320
|
}
|
|
1159
1321
|
},
|
|
1322
|
+
/* Windows Phone */
|
|
1160
1323
|
{
|
|
1161
1324
|
test(parser) {
|
|
1162
1325
|
return parser.getBrowserName() === "windows phone";
|
|
@@ -1168,6 +1331,7 @@ const platformParsersList = [
|
|
|
1168
1331
|
};
|
|
1169
1332
|
}
|
|
1170
1333
|
},
|
|
1334
|
+
/* Android Tablet */
|
|
1171
1335
|
{
|
|
1172
1336
|
test(parser) {
|
|
1173
1337
|
const osMajorVersion = Number(String(parser.getOSVersion()).split(".")[0]);
|
|
@@ -1179,6 +1343,7 @@ const platformParsersList = [
|
|
|
1179
1343
|
};
|
|
1180
1344
|
}
|
|
1181
1345
|
},
|
|
1346
|
+
/* Android Mobile */
|
|
1182
1347
|
{
|
|
1183
1348
|
test(parser) {
|
|
1184
1349
|
return parser.getOSName(true) === "android";
|
|
@@ -1189,6 +1354,7 @@ const platformParsersList = [
|
|
|
1189
1354
|
};
|
|
1190
1355
|
}
|
|
1191
1356
|
},
|
|
1357
|
+
/* desktop */
|
|
1192
1358
|
{
|
|
1193
1359
|
test(parser) {
|
|
1194
1360
|
return parser.getOSName(true) === "macos";
|
|
@@ -1200,6 +1366,7 @@ const platformParsersList = [
|
|
|
1200
1366
|
};
|
|
1201
1367
|
}
|
|
1202
1368
|
},
|
|
1369
|
+
/* Windows */
|
|
1203
1370
|
{
|
|
1204
1371
|
test(parser) {
|
|
1205
1372
|
return parser.getOSName(true) === "windows";
|
|
@@ -1210,6 +1377,7 @@ const platformParsersList = [
|
|
|
1210
1377
|
};
|
|
1211
1378
|
}
|
|
1212
1379
|
},
|
|
1380
|
+
/* Linux */
|
|
1213
1381
|
{
|
|
1214
1382
|
test(parser) {
|
|
1215
1383
|
return parser.getOSName(true) === "linux";
|
|
@@ -1220,6 +1388,7 @@ const platformParsersList = [
|
|
|
1220
1388
|
};
|
|
1221
1389
|
}
|
|
1222
1390
|
},
|
|
1391
|
+
/* PlayStation 4 */
|
|
1223
1392
|
{
|
|
1224
1393
|
test(parser) {
|
|
1225
1394
|
return parser.getOSName(true) === "playstation 4";
|
|
@@ -1230,6 +1399,7 @@ const platformParsersList = [
|
|
|
1230
1399
|
};
|
|
1231
1400
|
}
|
|
1232
1401
|
},
|
|
1402
|
+
/* Roku */
|
|
1233
1403
|
{
|
|
1234
1404
|
test(parser) {
|
|
1235
1405
|
return parser.getOSName(true) === "roku";
|
|
@@ -1242,6 +1412,7 @@ const platformParsersList = [
|
|
|
1242
1412
|
}
|
|
1243
1413
|
];
|
|
1244
1414
|
const enginesParsersList = [
|
|
1415
|
+
/* EdgeHTML */
|
|
1245
1416
|
{
|
|
1246
1417
|
test(parser) {
|
|
1247
1418
|
return parser.getBrowserName(true) === "microsoft edge";
|
|
@@ -1260,6 +1431,7 @@ const enginesParsersList = [
|
|
|
1260
1431
|
};
|
|
1261
1432
|
}
|
|
1262
1433
|
},
|
|
1434
|
+
/* Trident */
|
|
1263
1435
|
{
|
|
1264
1436
|
test: [/trident/i],
|
|
1265
1437
|
describe(ua) {
|
|
@@ -1273,6 +1445,7 @@ const enginesParsersList = [
|
|
|
1273
1445
|
return engine;
|
|
1274
1446
|
}
|
|
1275
1447
|
},
|
|
1448
|
+
/* Presto */
|
|
1276
1449
|
{
|
|
1277
1450
|
test(parser) {
|
|
1278
1451
|
return parser.test(/presto/i);
|
|
@@ -1288,6 +1461,7 @@ const enginesParsersList = [
|
|
|
1288
1461
|
return engine;
|
|
1289
1462
|
}
|
|
1290
1463
|
},
|
|
1464
|
+
/* Gecko */
|
|
1291
1465
|
{
|
|
1292
1466
|
test(parser) {
|
|
1293
1467
|
const isGecko = parser.test(/gecko/i);
|
|
@@ -1305,6 +1479,7 @@ const enginesParsersList = [
|
|
|
1305
1479
|
return engine;
|
|
1306
1480
|
}
|
|
1307
1481
|
},
|
|
1482
|
+
/* Blink */
|
|
1308
1483
|
{
|
|
1309
1484
|
test: [/(apple)?webkit\/537\.36/i],
|
|
1310
1485
|
describe() {
|
|
@@ -1313,6 +1488,7 @@ const enginesParsersList = [
|
|
|
1313
1488
|
};
|
|
1314
1489
|
}
|
|
1315
1490
|
},
|
|
1491
|
+
/* WebKit */
|
|
1316
1492
|
{
|
|
1317
1493
|
test: [/(apple)?webkit/i],
|
|
1318
1494
|
describe(ua) {
|
|
@@ -1328,6 +1504,18 @@ const enginesParsersList = [
|
|
|
1328
1504
|
}
|
|
1329
1505
|
];
|
|
1330
1506
|
class Parser {
|
|
1507
|
+
/**
|
|
1508
|
+
* Create instance of Parser
|
|
1509
|
+
*
|
|
1510
|
+
* @param {String} UA User-Agent string
|
|
1511
|
+
* @param {Boolean} [skipParsing=false] parser can skip parsing in purpose of performance
|
|
1512
|
+
* improvements if you need to make a more particular parsing
|
|
1513
|
+
* like {@link Parser#parseBrowser} or {@link Parser#parsePlatform}
|
|
1514
|
+
*
|
|
1515
|
+
* @throw {Error} in case of empty UA String
|
|
1516
|
+
*
|
|
1517
|
+
* @constructor
|
|
1518
|
+
*/
|
|
1331
1519
|
constructor(UA, skipParsing = false) {
|
|
1332
1520
|
if (UA === void 0 || UA === null || UA === "") {
|
|
1333
1521
|
throw new Error("UserAgent parameter can't be empty");
|
|
@@ -1338,12 +1526,27 @@ class Parser {
|
|
|
1338
1526
|
this.parse();
|
|
1339
1527
|
}
|
|
1340
1528
|
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Get UserAgent string of current Parser instance
|
|
1531
|
+
* @return {String} User-Agent String of the current <Parser> object
|
|
1532
|
+
*
|
|
1533
|
+
* @public
|
|
1534
|
+
*/
|
|
1341
1535
|
getUA() {
|
|
1342
1536
|
return this._ua;
|
|
1343
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Test a UA string for a regexp
|
|
1540
|
+
* @param {RegExp} regex
|
|
1541
|
+
* @return {Boolean}
|
|
1542
|
+
*/
|
|
1344
1543
|
test(regex) {
|
|
1345
1544
|
return regex.test(this._ua);
|
|
1346
1545
|
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Get parsed browser object
|
|
1548
|
+
* @return {Object}
|
|
1549
|
+
*/
|
|
1347
1550
|
parseBrowser() {
|
|
1348
1551
|
this.parsedResult.browser = {};
|
|
1349
1552
|
const browserDescriptor = Utils.find(browsersList, (_browser) => {
|
|
@@ -1360,27 +1563,60 @@ class Parser {
|
|
|
1360
1563
|
}
|
|
1361
1564
|
return this.parsedResult.browser;
|
|
1362
1565
|
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Get parsed browser object
|
|
1568
|
+
* @return {Object}
|
|
1569
|
+
*
|
|
1570
|
+
* @public
|
|
1571
|
+
*/
|
|
1363
1572
|
getBrowser() {
|
|
1364
1573
|
if (this.parsedResult.browser) {
|
|
1365
1574
|
return this.parsedResult.browser;
|
|
1366
1575
|
}
|
|
1367
1576
|
return this.parseBrowser();
|
|
1368
1577
|
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Get browser's name
|
|
1580
|
+
* @return {String} Browser's name or an empty string
|
|
1581
|
+
*
|
|
1582
|
+
* @public
|
|
1583
|
+
*/
|
|
1369
1584
|
getBrowserName(toLowerCase) {
|
|
1370
1585
|
if (toLowerCase) {
|
|
1371
1586
|
return String(this.getBrowser().name).toLowerCase() || "";
|
|
1372
1587
|
}
|
|
1373
1588
|
return this.getBrowser().name || "";
|
|
1374
1589
|
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Get browser's version
|
|
1592
|
+
* @return {String} version of browser
|
|
1593
|
+
*
|
|
1594
|
+
* @public
|
|
1595
|
+
*/
|
|
1375
1596
|
getBrowserVersion() {
|
|
1376
1597
|
return this.getBrowser().version;
|
|
1377
1598
|
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Get OS
|
|
1601
|
+
* @return {Object}
|
|
1602
|
+
*
|
|
1603
|
+
* @example
|
|
1604
|
+
* this.getOS();
|
|
1605
|
+
* {
|
|
1606
|
+
* name: 'macOS',
|
|
1607
|
+
* version: '10.11.12'
|
|
1608
|
+
* }
|
|
1609
|
+
*/
|
|
1378
1610
|
getOS() {
|
|
1379
1611
|
if (this.parsedResult.os) {
|
|
1380
1612
|
return this.parsedResult.os;
|
|
1381
1613
|
}
|
|
1382
1614
|
return this.parseOS();
|
|
1383
1615
|
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Parse OS and save it to this.parsedResult.os
|
|
1618
|
+
* @return {*|{}}
|
|
1619
|
+
*/
|
|
1384
1620
|
parseOS() {
|
|
1385
1621
|
this.parsedResult.os = {};
|
|
1386
1622
|
const os = Utils.find(osParsersList, (_os) => {
|
|
@@ -1397,6 +1633,11 @@ class Parser {
|
|
|
1397
1633
|
}
|
|
1398
1634
|
return this.parsedResult.os;
|
|
1399
1635
|
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Get OS name
|
|
1638
|
+
* @param {Boolean} [toLowerCase] return lower-cased value
|
|
1639
|
+
* @return {String} name of the OS — macOS, Windows, Linux, etc.
|
|
1640
|
+
*/
|
|
1400
1641
|
getOSName(toLowerCase) {
|
|
1401
1642
|
const { name } = this.getOS();
|
|
1402
1643
|
if (toLowerCase) {
|
|
@@ -1404,15 +1645,28 @@ class Parser {
|
|
|
1404
1645
|
}
|
|
1405
1646
|
return name || "";
|
|
1406
1647
|
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Get OS version
|
|
1650
|
+
* @return {String} full version with dots ('10.11.12', '5.6', etc)
|
|
1651
|
+
*/
|
|
1407
1652
|
getOSVersion() {
|
|
1408
1653
|
return this.getOS().version;
|
|
1409
1654
|
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Get parsed platform
|
|
1657
|
+
* @return {{}}
|
|
1658
|
+
*/
|
|
1410
1659
|
getPlatform() {
|
|
1411
1660
|
if (this.parsedResult.platform) {
|
|
1412
1661
|
return this.parsedResult.platform;
|
|
1413
1662
|
}
|
|
1414
1663
|
return this.parsePlatform();
|
|
1415
1664
|
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Get platform name
|
|
1667
|
+
* @param {Boolean} [toLowerCase=false]
|
|
1668
|
+
* @return {*}
|
|
1669
|
+
*/
|
|
1416
1670
|
getPlatformType(toLowerCase = false) {
|
|
1417
1671
|
const { type } = this.getPlatform();
|
|
1418
1672
|
if (toLowerCase) {
|
|
@@ -1420,6 +1674,10 @@ class Parser {
|
|
|
1420
1674
|
}
|
|
1421
1675
|
return type || "";
|
|
1422
1676
|
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Get parsed platform
|
|
1679
|
+
* @return {{}}
|
|
1680
|
+
*/
|
|
1423
1681
|
parsePlatform() {
|
|
1424
1682
|
this.parsedResult.platform = {};
|
|
1425
1683
|
const platform = Utils.find(platformParsersList, (_platform) => {
|
|
@@ -1436,18 +1694,32 @@ class Parser {
|
|
|
1436
1694
|
}
|
|
1437
1695
|
return this.parsedResult.platform;
|
|
1438
1696
|
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Get parsed engine
|
|
1699
|
+
* @return {{}}
|
|
1700
|
+
*/
|
|
1439
1701
|
getEngine() {
|
|
1440
1702
|
if (this.parsedResult.engine) {
|
|
1441
1703
|
return this.parsedResult.engine;
|
|
1442
1704
|
}
|
|
1443
1705
|
return this.parseEngine();
|
|
1444
1706
|
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Get engines's name
|
|
1709
|
+
* @return {String} Engines's name or an empty string
|
|
1710
|
+
*
|
|
1711
|
+
* @public
|
|
1712
|
+
*/
|
|
1445
1713
|
getEngineName(toLowerCase) {
|
|
1446
1714
|
if (toLowerCase) {
|
|
1447
1715
|
return String(this.getEngine().name).toLowerCase() || "";
|
|
1448
1716
|
}
|
|
1449
1717
|
return this.getEngine().name || "";
|
|
1450
1718
|
}
|
|
1719
|
+
/**
|
|
1720
|
+
* Get parsed platform
|
|
1721
|
+
* @return {{}}
|
|
1722
|
+
*/
|
|
1451
1723
|
parseEngine() {
|
|
1452
1724
|
this.parsedResult.engine = {};
|
|
1453
1725
|
const engine = Utils.find(enginesParsersList, (_engine) => {
|
|
@@ -1464,6 +1736,10 @@ class Parser {
|
|
|
1464
1736
|
}
|
|
1465
1737
|
return this.parsedResult.engine;
|
|
1466
1738
|
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Parse full information about the browser
|
|
1741
|
+
* @returns {Parser}
|
|
1742
|
+
*/
|
|
1467
1743
|
parse() {
|
|
1468
1744
|
this.parseBrowser();
|
|
1469
1745
|
this.parseOS();
|
|
@@ -1471,9 +1747,31 @@ class Parser {
|
|
|
1471
1747
|
this.parseEngine();
|
|
1472
1748
|
return this;
|
|
1473
1749
|
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Get parsed result
|
|
1752
|
+
* @return {ParsedResult}
|
|
1753
|
+
*/
|
|
1474
1754
|
getResult() {
|
|
1475
1755
|
return Utils.assign({}, this.parsedResult);
|
|
1476
1756
|
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Check if parsed browser matches certain conditions
|
|
1759
|
+
*
|
|
1760
|
+
* @param {Object} checkTree It's one or two layered object,
|
|
1761
|
+
* which can include a platform or an OS on the first layer
|
|
1762
|
+
* and should have browsers specs on the bottom-laying layer
|
|
1763
|
+
*
|
|
1764
|
+
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
|
|
1765
|
+
* Returns `undefined` when the browser is no described in the checkTree object.
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* const browser = Bowser.getParser(window.navigator.userAgent);
|
|
1769
|
+
* if (browser.satisfies({chrome: '>118.01.1322' }))
|
|
1770
|
+
* // or with os
|
|
1771
|
+
* if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
|
|
1772
|
+
* // or with platforms
|
|
1773
|
+
* if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
|
|
1774
|
+
*/
|
|
1477
1775
|
satisfies(checkTree) {
|
|
1478
1776
|
const platformsAndOSes = {};
|
|
1479
1777
|
let platformsAndOSCounter = 0;
|
|
@@ -1519,6 +1817,12 @@ class Parser {
|
|
|
1519
1817
|
}
|
|
1520
1818
|
return void 0;
|
|
1521
1819
|
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Check if the browser name equals the passed string
|
|
1822
|
+
* @param browserName The string to compare with the browser name
|
|
1823
|
+
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
|
|
1824
|
+
* @returns {boolean}
|
|
1825
|
+
*/
|
|
1522
1826
|
isBrowser(browserName, includingAlias = false) {
|
|
1523
1827
|
const defaultBrowserName = this.getBrowserName().toLowerCase();
|
|
1524
1828
|
let browserNameLower = browserName.toLowerCase();
|
|
@@ -1568,9 +1872,21 @@ class Parser {
|
|
|
1568
1872
|
isEngine(engineName) {
|
|
1569
1873
|
return this.getEngineName(true) === String(engineName).toLowerCase();
|
|
1570
1874
|
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Is anything? Check if the browser is called "anything",
|
|
1877
|
+
* the OS called "anything" or the platform called "anything"
|
|
1878
|
+
* @param {String} anything
|
|
1879
|
+
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
|
|
1880
|
+
* @returns {Boolean}
|
|
1881
|
+
*/
|
|
1571
1882
|
is(anything, includingAlias = false) {
|
|
1572
1883
|
return this.isBrowser(anything, includingAlias) || this.isOS(anything) || this.isPlatform(anything);
|
|
1573
1884
|
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Check if any of the given values satisfies this.is(anything)
|
|
1887
|
+
* @param {String[]} anythings
|
|
1888
|
+
* @returns {Boolean}
|
|
1889
|
+
*/
|
|
1574
1890
|
some(anythings = []) {
|
|
1575
1891
|
return anythings.some((anything) => this.is(anything));
|
|
1576
1892
|
}
|
|
@@ -1582,12 +1898,34 @@ class Parser {
|
|
|
1582
1898
|
* MIT License | (c) Denis Demchenko 2015-2019
|
|
1583
1899
|
*/
|
|
1584
1900
|
class Bowser {
|
|
1901
|
+
/**
|
|
1902
|
+
* Creates a {@link Parser} instance
|
|
1903
|
+
*
|
|
1904
|
+
* @param {String} UA UserAgent string
|
|
1905
|
+
* @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it
|
|
1906
|
+
* explicitly. Same as `skipParsing` for {@link Parser}.
|
|
1907
|
+
* @returns {Parser}
|
|
1908
|
+
* @throws {Error} when UA is not a String
|
|
1909
|
+
*
|
|
1910
|
+
* @example
|
|
1911
|
+
* const parser = Bowser.getParser(window.navigator.userAgent);
|
|
1912
|
+
* const result = parser.getResult();
|
|
1913
|
+
*/
|
|
1585
1914
|
static getParser(UA, skipParsing = false) {
|
|
1586
1915
|
if (typeof UA !== "string") {
|
|
1587
1916
|
throw new Error("UserAgent should be a string");
|
|
1588
1917
|
}
|
|
1589
1918
|
return new Parser(UA, skipParsing);
|
|
1590
1919
|
}
|
|
1920
|
+
/**
|
|
1921
|
+
* Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately
|
|
1922
|
+
*
|
|
1923
|
+
* @param UA
|
|
1924
|
+
* @return {ParsedResult}
|
|
1925
|
+
*
|
|
1926
|
+
* @example
|
|
1927
|
+
* const result = Bowser.parse(window.navigator.userAgent);
|
|
1928
|
+
*/
|
|
1591
1929
|
static parse(UA) {
|
|
1592
1930
|
return new Parser(UA).getResult();
|
|
1593
1931
|
}
|
|
@@ -1605,6 +1943,7 @@ class Bowser {
|
|
|
1605
1943
|
}
|
|
1606
1944
|
}
|
|
1607
1945
|
var lzString = { exports: {} };
|
|
1946
|
+
lzString.exports;
|
|
1608
1947
|
(function(module) {
|
|
1609
1948
|
var LZString = function() {
|
|
1610
1949
|
var f = String.fromCharCode;
|
|
@@ -1664,6 +2003,7 @@ var lzString = { exports: {} };
|
|
|
1664
2003
|
return compressed.charCodeAt(index) - 32;
|
|
1665
2004
|
});
|
|
1666
2005
|
},
|
|
2006
|
+
//compress into uint8array (UCS-2 big endian format)
|
|
1667
2007
|
compressToUint8Array: function(uncompressed) {
|
|
1668
2008
|
var compressed = LZString2.compress(uncompressed);
|
|
1669
2009
|
var buf = new Uint8Array(compressed.length * 2);
|
|
@@ -1674,6 +2014,7 @@ var lzString = { exports: {} };
|
|
|
1674
2014
|
}
|
|
1675
2015
|
return buf;
|
|
1676
2016
|
},
|
|
2017
|
+
//decompress from uint8array (UCS-2 big endian format)
|
|
1677
2018
|
decompressFromUint8Array: function(compressed) {
|
|
1678
2019
|
if (compressed === null || compressed === void 0) {
|
|
1679
2020
|
return LZString2.decompress(compressed);
|
|
@@ -1689,6 +2030,7 @@ var lzString = { exports: {} };
|
|
|
1689
2030
|
return LZString2.decompress(result.join(""));
|
|
1690
2031
|
}
|
|
1691
2032
|
},
|
|
2033
|
+
//compress into a string that is already URI encoded
|
|
1692
2034
|
compressToEncodedURIComponent: function(input) {
|
|
1693
2035
|
if (input == null)
|
|
1694
2036
|
return "";
|
|
@@ -1696,6 +2038,7 @@ var lzString = { exports: {} };
|
|
|
1696
2038
|
return keyStrUriSafe.charAt(a);
|
|
1697
2039
|
});
|
|
1698
2040
|
},
|
|
2041
|
+
//decompress from an output of compressToEncodedURIComponent
|
|
1699
2042
|
decompressFromEncodedURIComponent: function(input) {
|
|
1700
2043
|
if (input == null)
|
|
1701
2044
|
return "";
|
|
@@ -2056,6 +2399,7 @@ var lzString = { exports: {} };
|
|
|
2056
2399
|
module.exports = LZString;
|
|
2057
2400
|
}
|
|
2058
2401
|
})(lzString);
|
|
2402
|
+
var lzStringExports = lzString.exports;
|
|
2059
2403
|
const CURRENT_VERSION = "0.0.1";
|
|
2060
2404
|
const VITESSCE_CONF_QUERY_STRING = "vitessce_conf";
|
|
2061
2405
|
const VERSION_QUERY_STRING = "vitessce_conf_version";
|
|
@@ -2081,7 +2425,7 @@ function encodeConfInUrl({
|
|
|
2081
2425
|
onOverMaximumUrlLength = () => {
|
|
2082
2426
|
}
|
|
2083
2427
|
}) {
|
|
2084
|
-
const compressedConf =
|
|
2428
|
+
const compressedConf = lzStringExports.compressToEncodedURIComponent(JSON.stringify(conf));
|
|
2085
2429
|
const newParams = `${LENGTH_QUERY_STRING}=${compressedConf.length}&${VERSION_QUERY_STRING}=${CURRENT_VERSION}&${VITESSCE_CONF_QUERY_STRING}=${compressedConf}`;
|
|
2086
2430
|
const browser = sniffBrowser();
|
|
2087
2431
|
const maxLength = MAX_BROWSER_URL_LENGTHS[browser];
|
|
@@ -2102,7 +2446,7 @@ function decodeURLParamsToConf(queryString) {
|
|
|
2102
2446
|
}
|
|
2103
2447
|
const version = params.get(VERSION_QUERY_STRING);
|
|
2104
2448
|
if (version === CURRENT_VERSION) {
|
|
2105
|
-
const conf = JSON.parse(
|
|
2449
|
+
const conf = JSON.parse(lzStringExports.decompressFromEncodedURIComponent(compressedConfString));
|
|
2106
2450
|
return conf;
|
|
2107
2451
|
}
|
|
2108
2452
|
throw new Error("Unrecognized URL Param Version");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode a configuration as url params with a version and an lz-compressed conf.
|
|
3
|
+
* @param {Object} params
|
|
4
|
+
* @param {Object} params.conf Previous scope names.
|
|
5
|
+
* @param {function} params.onOverMaximumUrlLength Callback for when new url
|
|
6
|
+
* is over max length for your browser - takes two arguments: { message, willWorkOn }
|
|
7
|
+
* for the error message and the browsers for which the url will work (optional).
|
|
8
|
+
* @returns {string} The new params like
|
|
9
|
+
* vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl
|
|
10
|
+
*/
|
|
11
|
+
export function encodeConfInUrl({ conf, onOverMaximumUrlLength, }: {
|
|
12
|
+
conf: Object;
|
|
13
|
+
onOverMaximumUrlLength: Function;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* Decode URL params to a Vitessce configuration.
|
|
17
|
+
* The URL params must have version and vitessce_conf params,
|
|
18
|
+
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
19
|
+
* @param {Object} queryString The URL params,
|
|
20
|
+
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
21
|
+
* @returns {string} A vitessce configuration.
|
|
22
|
+
*/
|
|
23
|
+
export function decodeURLParamsToConf(queryString: Object): string;
|
|
24
|
+
export default class CompressedConfLengthError {
|
|
25
|
+
constructor(message: any);
|
|
26
|
+
message: any;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=export-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-utils.d.ts","sourceRoot":"","sources":["../src/export-utils.js"],"names":[],"mappings":"AA4BA;;;;;;;;;GASG;AACH;IAP0B,IAAI,EAAnB,MAAM;IACW,sBAAsB;IAGrC,MAAM,CAoBlB;AAED;;;;;;;GAOG;AACH,mDAJW,MAAM,GAEJ,MAAM,CAelB;AAxDD;IACE,0BAEC;IADC,aAAsB;CAEzB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Bowser from 'bowser';
|
|
2
|
+
import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from 'lz-string';
|
|
3
|
+
const CURRENT_VERSION = '0.0.1';
|
|
4
|
+
const VITESSCE_CONF_QUERY_STRING = 'vitessce_conf';
|
|
5
|
+
const VERSION_QUERY_STRING = 'vitessce_conf_version';
|
|
6
|
+
const LENGTH_QUERY_STRING = 'vitessce_conf_length';
|
|
7
|
+
function sniffBrowser() {
|
|
8
|
+
const { browser } = Bowser.parse(window.navigator.userAgent);
|
|
9
|
+
return browser.name;
|
|
10
|
+
}
|
|
11
|
+
// https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
|
12
|
+
const MAX_BROWSER_URL_LENGTHS = {
|
|
13
|
+
Chrome: 32779,
|
|
14
|
+
'Internet Explorer': 2047,
|
|
15
|
+
Edge: 2047,
|
|
16
|
+
Safari: 65000,
|
|
17
|
+
Firefox: 65000,
|
|
18
|
+
};
|
|
19
|
+
export default class CompressedConfLengthError {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
this.message = message;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Encode a configuration as url params with a version and an lz-compressed conf.
|
|
26
|
+
* @param {Object} params
|
|
27
|
+
* @param {Object} params.conf Previous scope names.
|
|
28
|
+
* @param {function} params.onOverMaximumUrlLength Callback for when new url
|
|
29
|
+
* is over max length for your browser - takes two arguments: { message, willWorkOn }
|
|
30
|
+
* for the error message and the browsers for which the url will work (optional).
|
|
31
|
+
* @returns {string} The new params like
|
|
32
|
+
* vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl
|
|
33
|
+
*/
|
|
34
|
+
export function encodeConfInUrl({ conf, onOverMaximumUrlLength = () => { }, }) {
|
|
35
|
+
const compressedConf = compressToEncodedURIComponent(JSON.stringify(conf));
|
|
36
|
+
const newParams = `${LENGTH_QUERY_STRING}=${compressedConf.length}&${VERSION_QUERY_STRING}=${CURRENT_VERSION}&${VITESSCE_CONF_QUERY_STRING}=${compressedConf}`;
|
|
37
|
+
const browser = sniffBrowser();
|
|
38
|
+
const maxLength = MAX_BROWSER_URL_LENGTHS[browser];
|
|
39
|
+
if (newParams.length > maxLength) {
|
|
40
|
+
const willWorkOn = Object.entries(MAX_BROWSER_URL_LENGTHS)
|
|
41
|
+
.filter(entry => entry[1] > newParams.length)
|
|
42
|
+
.map(entry => entry[0]);
|
|
43
|
+
const message = `Configuration is ${compressedConf.length} characters; max URL for ${browser} is ${maxLength}: it will work on ${willWorkOn.join(', ') || 'no browser'}.`;
|
|
44
|
+
console.error(message);
|
|
45
|
+
onOverMaximumUrlLength({ message, willWorkOn });
|
|
46
|
+
}
|
|
47
|
+
return newParams;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decode URL params to a Vitessce configuration.
|
|
51
|
+
* The URL params must have version and vitessce_conf params,
|
|
52
|
+
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
53
|
+
* @param {Object} queryString The URL params,
|
|
54
|
+
* like vitessce_conf_length=10&vitessce_conf_version=0.0.1&vitessce_conf=fksdfasdfjkl.
|
|
55
|
+
* @returns {string} A vitessce configuration.
|
|
56
|
+
*/
|
|
57
|
+
export function decodeURLParamsToConf(queryString) {
|
|
58
|
+
const params = new URLSearchParams(queryString.replace('#', '&'));
|
|
59
|
+
const compressedConfString = params.get(VITESSCE_CONF_QUERY_STRING);
|
|
60
|
+
const expectedConfLength = Number(params.get(LENGTH_QUERY_STRING));
|
|
61
|
+
if (expectedConfLength !== compressedConfString.length) {
|
|
62
|
+
throw new CompressedConfLengthError(`Compressed conf length (${compressedConfString.length}) != expected (${expectedConfLength}). URL truncated?`);
|
|
63
|
+
}
|
|
64
|
+
const version = params.get(VERSION_QUERY_STRING);
|
|
65
|
+
if (version === CURRENT_VERSION) {
|
|
66
|
+
const conf = JSON.parse(decompressFromEncodedURIComponent(compressedConfString));
|
|
67
|
+
return conf;
|
|
68
|
+
}
|
|
69
|
+
throw new Error('Unrecognized URL Param Version');
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-utils.test.d.ts","sourceRoot":"","sources":["../src/export-utils.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { encodeConfInUrl, decodeURLParamsToConf, } from './export-utils.js';
|
|
3
|
+
const fakeConfig = {
|
|
4
|
+
version: '0.1.0',
|
|
5
|
+
public: false,
|
|
6
|
+
layers: [
|
|
7
|
+
{
|
|
8
|
+
name: 'cells',
|
|
9
|
+
type: 'CELLS',
|
|
10
|
+
fileType: 'cells.json',
|
|
11
|
+
url: 'http://example.com/cells.json',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
name: 'Just scatterplot',
|
|
15
|
+
staticLayout: [
|
|
16
|
+
{
|
|
17
|
+
component: 'scatterplot',
|
|
18
|
+
props: {
|
|
19
|
+
mapping: 't-SNE',
|
|
20
|
+
view: {
|
|
21
|
+
zoom: 0.75,
|
|
22
|
+
target: [0, 0, 0],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
x: 0,
|
|
26
|
+
y: 0,
|
|
27
|
+
w: 12,
|
|
28
|
+
h: 2,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
function makeLongString(length) {
|
|
33
|
+
let result = '';
|
|
34
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
35
|
+
const charactersLength = characters.length;
|
|
36
|
+
// eslint-disable-next-line no-plusplus
|
|
37
|
+
for (let i = 0; i < length; i++) {
|
|
38
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
describe('src/app/export-utils.js', () => {
|
|
43
|
+
describe('encodeConfInUrl', () => {
|
|
44
|
+
it('encodes a view config for a URL', () => {
|
|
45
|
+
const urlParams1 = encodeConfInUrl({ conf: {} });
|
|
46
|
+
expect(urlParams1).toEqual('vitessce_conf_length=5&vitessce_conf_version=0.0.1&vitessce_conf=N4XyA');
|
|
47
|
+
const urlParams2 = encodeConfInUrl({ conf: fakeConfig });
|
|
48
|
+
expect(urlParams2).toEqual('vitessce_conf_length=327&vitessce_conf_version=0.0.1&vitessce_conf=N4IgbgpgTgzglgewHYgFwgAwDoCMWMgA0IADgK4BGANnAMZoBmAhlTBMVUwJ7QxoDaoJEwC2ENCFoQqrIiAAuXEuPQBhAKIAZTQGU5DOFQgAVJSsnTWWAFYxkcslCoSAFvPklUAei8QAHqIkRli0CCJeUjIwNnYoAL4AusTCYhIAUmQw8gAEMLRM7tBBCPJyWQV0mtwIZKWogpJhJMgQSHUgeQXyRVQlciRQCCR8qKAiTCQkcEgA5hLyALQ6AHLqcmBwEADuaKAAXghhaNgA7ACsxPJMUDMQdfwYhI8YCXFxxH7HxFxfIDuoOAATMQXGhAYk4kA');
|
|
49
|
+
});
|
|
50
|
+
it('Calls onOverMaximumUrlLength for conf too long', () => {
|
|
51
|
+
let browsers;
|
|
52
|
+
// eslint-disable-next-line no-return-assign
|
|
53
|
+
const onOverMaximumUrlLength = ({ willWorkOn }) => browsers = willWorkOn;
|
|
54
|
+
encodeConfInUrl({ conf: { foo: makeLongString(69000) }, onOverMaximumUrlLength });
|
|
55
|
+
expect(browsers).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
it('decodes a view config for a URL', () => {
|
|
58
|
+
const viewConfig1 = decodeURLParamsToConf('vitessce_conf_length=5&vitessce_conf_version=0.0.1&vitessce_conf=N4XyA');
|
|
59
|
+
expect(viewConfig1).toEqual({});
|
|
60
|
+
const viewConfig2 = decodeURLParamsToConf('vitessce_conf_length=327&vitessce_conf_version=0.0.1&vitessce_conf=N4IgbgpgTgzglgewHYgFwgAwDoCMWMgA0IADgK4BGANnAMZoBmAhlTBMVUwJ7QxoDaoJEwC2ENCFoQqrIiAAuXEuPQBhAKIAZTQGU5DOFQgAVJSsnTWWAFYxkcslCoSAFvPklUAei8QAHqIkRli0CCJeUjIwNnYoAL4AusTCYhIAUmQw8gAEMLRM7tBBCPJyWQV0mtwIZKWogpJhJMgQSHUgeQXyRVQlciRQCCR8qKAiTCQkcEgA5hLyALQ6AHLqcmBwEADuaKAAXghhaNgA7ACsxPJMUDMQdfwYhI8YCXFxxH7HxFxfIDuoOAATMQXGhAYk4kA');
|
|
61
|
+
expect(viewConfig2).toEqual(fakeConfig);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|
package/dist-tsc/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { encodeConfInUrl, decodeURLParamsToConf, } from './export-utils';
|
|
1
|
+
export { encodeConfInUrl, decodeURLParamsToConf, } from './export-utils.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitessce/export-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"author": "Gehlenborg Lab",
|
|
5
5
|
"homepage": "http://vitessce.io",
|
|
6
6
|
"repository": {
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
"url": "git+https://github.com/vitessce/vitessce.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
12
13
|
"files": [
|
|
14
|
+
"src",
|
|
13
15
|
"dist",
|
|
14
|
-
"
|
|
16
|
+
"dist-tsc"
|
|
15
17
|
],
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"bowser": "^2.11.0",
|
|
@@ -19,6 +21,13 @@
|
|
|
19
21
|
},
|
|
20
22
|
"scripts": {
|
|
21
23
|
"bundle": "pnpm exec vite build -c ../../../scripts/vite.config.js",
|
|
22
|
-
"test": "pnpm exec vitest --run
|
|
24
|
+
"test": "pnpm exec vitest --run"
|
|
25
|
+
},
|
|
26
|
+
"module": "dist/index.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist-tsc/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
}
|
package/src/export-utils.test.js
CHANGED
package/src/index.js
CHANGED