web-launch-kit 0.0.1 → 0.0.2
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/README.md +55 -43
- package/dist/index.d.ts +15 -1
- package/dist/launch-kit.cjs +169 -14
- package/dist/launch-kit.cjs.map +1 -1
- package/dist/launch-kit.min.cjs +1 -1
- package/dist/launch-kit.min.cjs.map +1 -1
- package/dist/launch-kit.min.mjs +1 -1
- package/dist/launch-kit.min.mjs.map +1 -1
- package/dist/launch-kit.mjs +169 -14
- package/dist/launch-kit.mjs.map +1 -1
- package/dist/launch-kit.umd.js +169 -14
- package/dist/launch-kit.umd.js.map +1 -1
- package/dist/launch-kit.umd.min.js +1 -1
- package/dist/launch-kit.umd.min.js.map +1 -1
- package/package.json +7 -2
package/dist/launch-kit.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version$1 = "0.0.
|
|
1
|
+
var version$1 = "0.0.2";
|
|
2
2
|
var packageJSON$1 = {
|
|
3
3
|
version: version$1};
|
|
4
4
|
|
|
@@ -936,7 +936,7 @@ var ANDROID_DEFAULT_TIMEOUT = 1000;
|
|
|
936
936
|
var IOS_DEFAULT_TIMEOUT = 2000;
|
|
937
937
|
var WINDOWS_DEFAULT_TIMEOUT = 750;
|
|
938
938
|
var MACOS_DEFAULT_TIMEOUT = 750;
|
|
939
|
-
var
|
|
939
|
+
var DEFAULT_TIMEOUT = 750;
|
|
940
940
|
var NAVIGATOR = globalThis.navigator;
|
|
941
941
|
var CLEANUP_INPUT_ELEMENT = null;
|
|
942
942
|
function createTypeGuard(tag) {
|
|
@@ -970,7 +970,7 @@ function getDefaultTimeout() {
|
|
|
970
970
|
case 'macos':
|
|
971
971
|
return MACOS_DEFAULT_TIMEOUT;
|
|
972
972
|
default:
|
|
973
|
-
return
|
|
973
|
+
return DEFAULT_TIMEOUT;
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
976
|
function isDocumentHidden() {
|
|
@@ -1076,7 +1076,7 @@ function restoreFocus() {
|
|
|
1076
1076
|
return hasFocus(topDocument);
|
|
1077
1077
|
}
|
|
1078
1078
|
function stripURL(value) {
|
|
1079
|
-
return
|
|
1079
|
+
return isURL(value) ? value.toString() : value;
|
|
1080
1080
|
}
|
|
1081
1081
|
function resolveFocusEventConfig() {
|
|
1082
1082
|
var top = getTopmostWindow();
|
|
@@ -1290,6 +1290,8 @@ function resolveOptions(option) {
|
|
|
1290
1290
|
var fallback;
|
|
1291
1291
|
var allowAppStore;
|
|
1292
1292
|
var allowWebStore;
|
|
1293
|
+
var allowScheme;
|
|
1294
|
+
var assumeAllowedInApp;
|
|
1293
1295
|
var timeout;
|
|
1294
1296
|
var intent;
|
|
1295
1297
|
var packageName;
|
|
@@ -1306,8 +1308,10 @@ function resolveOptions(option) {
|
|
|
1306
1308
|
scheme = stripURL(option.android.scheme);
|
|
1307
1309
|
fallback = stripURL(option.android.fallback);
|
|
1308
1310
|
packageName = option.android.packageName;
|
|
1311
|
+
assumeAllowedInApp = option.android.assumeAllowedInApp === true;
|
|
1309
1312
|
allowAppStore = option.android.allowAppStore;
|
|
1310
1313
|
allowWebStore = option.android.allowWebStore;
|
|
1314
|
+
allowScheme = canOpenScheme(assumeAllowedInApp);
|
|
1311
1315
|
timeout = option.android.timeout;
|
|
1312
1316
|
if (typeof intent !== 'undefined' && (typeof scheme === 'undefined' || typeof packageName === 'undefined' || typeof fallback === 'undefined')) {
|
|
1313
1317
|
var parsed = parseIntentURL(intent);
|
|
@@ -1324,12 +1328,12 @@ function resolveOptions(option) {
|
|
|
1324
1328
|
timeout = ANDROID_DEFAULT_TIMEOUT;
|
|
1325
1329
|
if (typeof intent !== 'undefined' && canOpenIntent())
|
|
1326
1330
|
resolved.push(['intent', intent]);
|
|
1327
|
-
if (typeof scheme !== 'undefined')
|
|
1331
|
+
if (typeof scheme !== 'undefined' && allowScheme)
|
|
1328
1332
|
resolved.push(['scheme', scheme]);
|
|
1329
1333
|
if (typeof fallback !== 'undefined')
|
|
1330
1334
|
resolved.push(['fallback', fallback]);
|
|
1331
1335
|
if (typeof packageName !== 'undefined') {
|
|
1332
|
-
if (allowAppStore)
|
|
1336
|
+
if (allowAppStore && allowScheme)
|
|
1333
1337
|
resolved.push(['store', createAppStoreURL(packageName, os)]);
|
|
1334
1338
|
if (allowWebStore)
|
|
1335
1339
|
resolved.push(['store', createWebStoreURL(packageName, os)]);
|
|
@@ -1343,21 +1347,23 @@ function resolveOptions(option) {
|
|
|
1343
1347
|
fallback = stripURL(option.ios.fallback);
|
|
1344
1348
|
bundleId = option.ios.bundleId;
|
|
1345
1349
|
trackId = option.ios.trackId;
|
|
1350
|
+
assumeAllowedInApp = option.ios.assumeAllowedInApp === true;
|
|
1346
1351
|
allowAppStore = option.ios.allowAppStore;
|
|
1347
1352
|
allowWebStore = option.ios.allowWebStore;
|
|
1353
|
+
allowScheme = canOpenScheme(assumeAllowedInApp);
|
|
1348
1354
|
timeout = option.ios.timeout;
|
|
1349
1355
|
if (typeof bundleId !== 'undefined' && typeof trackId === 'undefined')
|
|
1350
1356
|
trackId = getTrackId(bundleId);
|
|
1351
1357
|
if (typeof timeout === 'undefined')
|
|
1352
1358
|
timeout = IOS_DEFAULT_TIMEOUT;
|
|
1353
|
-
if (typeof universal !== 'undefined' && canOpenUniversal())
|
|
1359
|
+
if (typeof universal !== 'undefined' && canOpenUniversal(assumeAllowedInApp))
|
|
1354
1360
|
resolved.push(['universal', universal]);
|
|
1355
|
-
if (typeof scheme !== 'undefined')
|
|
1361
|
+
if (typeof scheme !== 'undefined' && allowScheme)
|
|
1356
1362
|
resolved.push(['scheme', scheme]);
|
|
1357
1363
|
if (typeof fallback !== 'undefined')
|
|
1358
1364
|
resolved.push(['fallback', fallback]);
|
|
1359
1365
|
if (typeof trackId !== 'undefined') {
|
|
1360
|
-
if (allowAppStore)
|
|
1366
|
+
if (allowAppStore && allowScheme)
|
|
1361
1367
|
resolved.push(['store', createAppStoreURL(trackId, os)]);
|
|
1362
1368
|
if (allowWebStore)
|
|
1363
1369
|
resolved.push(['store', createWebStoreURL(trackId, os)]);
|
|
@@ -1430,10 +1436,41 @@ function canOpenIntent() {
|
|
|
1430
1436
|
return false;
|
|
1431
1437
|
if (browser === 'opera' && PlatformKit.compareVersion(version, '14.0') < 0)
|
|
1432
1438
|
return false;
|
|
1433
|
-
|
|
1439
|
+
if (isFullyBlockedInAppBrowser() || isPartnerAppOnly())
|
|
1440
|
+
return false;
|
|
1441
|
+
return !(/(?:fban\/fbios|fb_iab\/fb4a)(?!.+fbav)|;fbav\/[\w.]+;/i.test(PlatformKit.userAgent) || /instagram[\/ ][-\w.]+/i.test(PlatformKit.userAgent) || /musical_ly(?:.+app_?version\/|_)[\w.]+/i.test(PlatformKit.userAgent) || /ultralite app_version\/[\w.]+/i.test(PlatformKit.userAgent));
|
|
1442
|
+
}
|
|
1443
|
+
function canOpenUniversal(assumeAllowedInApp) {
|
|
1444
|
+
if (assumeAllowedInApp === void 0) { assumeAllowedInApp = false; }
|
|
1445
|
+
if (PlatformKit.os.name !== 'ios' || PlatformKit.compareVersion(PlatformKit.os.version, '9.0') < 0)
|
|
1446
|
+
return false;
|
|
1447
|
+
if (isPartnerAppOnly() && !assumeAllowedInApp)
|
|
1448
|
+
return false;
|
|
1449
|
+
var userAgent = PlatformKit.userAgent;
|
|
1450
|
+
var wechat = userAgent.match(/micromessenger\/(\d+(?:\.\d+)*)/i);
|
|
1451
|
+
if (wechat !== null && PlatformKit.compareVersion(wechat[1], '7.0.5') < 0)
|
|
1452
|
+
return false;
|
|
1453
|
+
if (/ qq\/[\d.]+/i.test(userAgent) || /m?qqbrowser\/[\d.]+/i.test(userAgent) || /ucbrowser\/[\d.]+/i.test(userAgent))
|
|
1454
|
+
return false;
|
|
1455
|
+
return !/qzone\/.*_qz_[\d.]+/i.test(userAgent);
|
|
1456
|
+
}
|
|
1457
|
+
function canOpenScheme(assumeAllowedInApp) {
|
|
1458
|
+
if (assumeAllowedInApp === void 0) { assumeAllowedInApp = false; }
|
|
1459
|
+
var os = PlatformKit.os.name;
|
|
1460
|
+
if (os === 'android')
|
|
1461
|
+
return !isFullyBlockedInAppBrowser() && (!isPartnerAppOnly() || assumeAllowedInApp);
|
|
1462
|
+
if (os === 'ios')
|
|
1463
|
+
return !/micromessenger\/[\w.]+/i.test(PlatformKit.userAgent) && (!isPartnerAppOnly() || assumeAllowedInApp);
|
|
1464
|
+
return true;
|
|
1465
|
+
}
|
|
1466
|
+
function isFullyBlockedInAppBrowser() {
|
|
1467
|
+
if (PlatformKit.os.name !== 'android')
|
|
1468
|
+
return false;
|
|
1469
|
+
var userAgent = PlatformKit.userAgent;
|
|
1470
|
+
return /micromessenger\/[\w.]+/i.test(userAgent) || / qq\/[\d.]+/i.test(userAgent) || /qzone\/.*_qz_[\d.]+/i.test(userAgent) || /baiduboxapp\/[\d.]+/i.test(userAgent);
|
|
1434
1471
|
}
|
|
1435
|
-
function
|
|
1436
|
-
return
|
|
1472
|
+
function isPartnerAppOnly() {
|
|
1473
|
+
return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
|
|
1437
1474
|
}
|
|
1438
1475
|
function canOpenSetting() {
|
|
1439
1476
|
var os = PlatformKit.os.name;
|
|
@@ -1540,6 +1577,18 @@ function escapeURIComponentMailAddressString(value) {
|
|
|
1540
1577
|
function encodeMailBody(value) {
|
|
1541
1578
|
return escapeURIComponentString(value.replace(/\r\n|\n|\r/g, '\r\n'));
|
|
1542
1579
|
}
|
|
1580
|
+
function encodeMapValue(value) {
|
|
1581
|
+
if (isArray(value))
|
|
1582
|
+
return value[0] + ',' + value[1];
|
|
1583
|
+
return escapeURIComponentString(value);
|
|
1584
|
+
}
|
|
1585
|
+
function encodeBingRoutePoint(value) {
|
|
1586
|
+
if (typeof value === 'undefined')
|
|
1587
|
+
return '';
|
|
1588
|
+
if (isArray(value))
|
|
1589
|
+
return 'pos.' + value[0] + '_' + value[1];
|
|
1590
|
+
return escapeURIComponentString(value);
|
|
1591
|
+
}
|
|
1543
1592
|
function toArray(value) {
|
|
1544
1593
|
return typeof value === 'undefined' ? [] : typeof value === 'string' ? [value] : value;
|
|
1545
1594
|
}
|
|
@@ -1786,12 +1835,12 @@ var LaunchKit = {
|
|
|
1786
1835
|
catch (error) {
|
|
1787
1836
|
return Promise.reject(error);
|
|
1788
1837
|
}
|
|
1789
|
-
var tried = [];
|
|
1790
1838
|
var urls = resolved[0];
|
|
1791
1839
|
var timeout = resolved[1];
|
|
1792
1840
|
if (urls.length === 0)
|
|
1793
1841
|
return Promise.reject(new Error('No openable URL candidates were resolved for the current OS ("' + PlatformKit.os.name + '"). Provide at least one of: scheme, intent, universal, fallback, or store id for this platform.'));
|
|
1794
1842
|
return new Promise(function (resolve, reject) {
|
|
1843
|
+
var tried = [];
|
|
1795
1844
|
function openURLSequential(index) {
|
|
1796
1845
|
if (index === void 0) { index = 0; }
|
|
1797
1846
|
if (index >= urls.length)
|
|
@@ -1863,6 +1912,112 @@ var LaunchKit = {
|
|
|
1863
1912
|
url += '?' + joining(params, undefined, '&');
|
|
1864
1913
|
return openURL(0, url, getDefaultTimeout());
|
|
1865
1914
|
},
|
|
1915
|
+
map: function (options) {
|
|
1916
|
+
if (options === void 0) { options = {}; }
|
|
1917
|
+
var params = [];
|
|
1918
|
+
var urls = [];
|
|
1919
|
+
var url = '';
|
|
1920
|
+
switch (PlatformKit.os.name) {
|
|
1921
|
+
case 'android':
|
|
1922
|
+
if (typeof options.coordinate !== 'undefined') {
|
|
1923
|
+
url = 'geo:' + options.coordinate[0] + ',' + options.coordinate[1];
|
|
1924
|
+
}
|
|
1925
|
+
else if (typeof options.query !== 'undefined') {
|
|
1926
|
+
url = 'geo:0,0';
|
|
1927
|
+
params.push('q=' + escapeURIComponentString(options.query));
|
|
1928
|
+
}
|
|
1929
|
+
else {
|
|
1930
|
+
url = 'geo:0,0';
|
|
1931
|
+
}
|
|
1932
|
+
if (typeof options.zoom !== 'undefined')
|
|
1933
|
+
params.push('z=' + options.zoom);
|
|
1934
|
+
if (params.length > 0)
|
|
1935
|
+
url = url + '?' + joining(params, undefined, '&');
|
|
1936
|
+
urls.push(url);
|
|
1937
|
+
break;
|
|
1938
|
+
case 'ios':
|
|
1939
|
+
case 'macos':
|
|
1940
|
+
if (typeof options.directions !== 'undefined') {
|
|
1941
|
+
if (typeof options.directions.destination !== 'undefined')
|
|
1942
|
+
params.push('daddr=' + encodeMapValue(options.directions.destination));
|
|
1943
|
+
if (typeof options.directions.origin !== 'undefined')
|
|
1944
|
+
params.push('saddr=' + encodeMapValue(options.directions.origin));
|
|
1945
|
+
}
|
|
1946
|
+
else if (typeof options.coordinate !== 'undefined') {
|
|
1947
|
+
params.push('ll=' + options.coordinate[0] + ',' + options.coordinate[1]);
|
|
1948
|
+
if (typeof options.label !== 'undefined')
|
|
1949
|
+
params.push('q=' + escapeURIComponentString(options.label));
|
|
1950
|
+
}
|
|
1951
|
+
else if (typeof options.query !== 'undefined') {
|
|
1952
|
+
params.push('q=' + escapeURIComponentString(options.query));
|
|
1953
|
+
}
|
|
1954
|
+
if (typeof options.zoom !== 'undefined')
|
|
1955
|
+
params.push('z=' + options.zoom);
|
|
1956
|
+
urls.push('maps://?' + joining(params, undefined, '&'));
|
|
1957
|
+
break;
|
|
1958
|
+
case 'windows':
|
|
1959
|
+
if (typeof options.directions !== 'undefined') {
|
|
1960
|
+
params.push('rtp=' + encodeBingRoutePoint(options.directions.origin) + '~' + encodeBingRoutePoint(options.directions.destination));
|
|
1961
|
+
}
|
|
1962
|
+
else if (typeof options.coordinate !== 'undefined') {
|
|
1963
|
+
params.push('cp=' + options.coordinate[0] + '~' + options.coordinate[1]);
|
|
1964
|
+
if (typeof options.label !== 'undefined')
|
|
1965
|
+
params.push('q=' + escapeURIComponentString(options.label));
|
|
1966
|
+
}
|
|
1967
|
+
else if (typeof options.query !== 'undefined') {
|
|
1968
|
+
params.push('where=' + escapeURIComponentString(options.query));
|
|
1969
|
+
}
|
|
1970
|
+
if (typeof options.zoom !== 'undefined')
|
|
1971
|
+
params.push('lvl=' + options.zoom);
|
|
1972
|
+
urls.push('bingmaps:?' + joining(params, undefined, '&'));
|
|
1973
|
+
}
|
|
1974
|
+
if (typeof options.fallback !== 'undefined') {
|
|
1975
|
+
urls.push(stripURL(options.fallback));
|
|
1976
|
+
}
|
|
1977
|
+
else {
|
|
1978
|
+
var params_1 = ['api=1'];
|
|
1979
|
+
if (typeof options.directions !== 'undefined') {
|
|
1980
|
+
params_1.push('destination=' + encodeMapValue(options.directions.destination));
|
|
1981
|
+
if (typeof options.directions.origin !== 'undefined')
|
|
1982
|
+
params_1.push('origin=' + encodeMapValue(options.directions.origin));
|
|
1983
|
+
urls.push('https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&'));
|
|
1984
|
+
}
|
|
1985
|
+
else {
|
|
1986
|
+
if (typeof options.coordinate !== 'undefined')
|
|
1987
|
+
params_1.push('query=' + options.coordinate[0] + ',' + options.coordinate[1]);
|
|
1988
|
+
else if (typeof options.query !== 'undefined')
|
|
1989
|
+
params_1.push('query=' + escapeURIComponentString(options.query));
|
|
1990
|
+
if (typeof options.zoom !== 'undefined')
|
|
1991
|
+
params_1.push('zoom=' + options.zoom);
|
|
1992
|
+
urls.push('https://www.google.com/maps/search/?' + joining(params_1, undefined, '&'));
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
return new Promise(function (resolve, reject) {
|
|
1996
|
+
var tried = [];
|
|
1997
|
+
function openURLSequential(index) {
|
|
1998
|
+
if (index === void 0) { index = 0; }
|
|
1999
|
+
if (index >= urls.length)
|
|
2000
|
+
return reject(new Error('Failed to open a map using all available URLs.\n\nAttempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
|
|
2001
|
+
var url = urls[index];
|
|
2002
|
+
if (typeof url === 'string') {
|
|
2003
|
+
tried[index] = url;
|
|
2004
|
+
return openURL(index, url, getDefaultTimeout())
|
|
2005
|
+
.then(function () {
|
|
2006
|
+
resolve();
|
|
2007
|
+
})
|
|
2008
|
+
.catch(function () {
|
|
2009
|
+
openURLSequential(index + 1);
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
else {
|
|
2013
|
+
tried[index] = '[function fallback]';
|
|
2014
|
+
url();
|
|
2015
|
+
resolve();
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
return openURLSequential();
|
|
2019
|
+
});
|
|
2020
|
+
},
|
|
1866
2021
|
filepicker: function (options) {
|
|
1867
2022
|
if (options === void 0) { options = {}; }
|
|
1868
2023
|
var module;
|
|
@@ -1965,7 +2120,7 @@ var LaunchKit = {
|
|
|
1965
2120
|
if (index === void 0) { index = 0; }
|
|
1966
2121
|
if (index >= urls.length)
|
|
1967
2122
|
return reject(new Error('Failed to open the "' + type + '" settings pane using all available URLs.\n\nAttempted URLs:\n' + joining(urls, undefined, '\n↓\n')));
|
|
1968
|
-
return openURL(index, urls[index],
|
|
2123
|
+
return openURL(index, urls[index], DEFAULT_TIMEOUT)
|
|
1969
2124
|
.then(function () {
|
|
1970
2125
|
resolve();
|
|
1971
2126
|
})
|