web-launch-kit 0.0.5 → 0.0.6
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.ko.md +34 -4
- package/README.md +35 -4
- package/dist/index.d.ts +15 -2
- package/dist/launch-kit.cjs +105 -69
- 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 +105 -69
- package/dist/launch-kit.mjs.map +1 -1
- package/dist/launch-kit.umd.js +105 -69
- 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 +1 -1
package/dist/launch-kit.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version$3 = "0.0.
|
|
1
|
+
var version$3 = "0.0.6";
|
|
2
2
|
var packageJSON$3 = {
|
|
3
3
|
version: version$3};
|
|
4
4
|
|
|
@@ -1894,6 +1894,7 @@ var GLOBAL = getGlobal$1();
|
|
|
1894
1894
|
var NAVIGATOR = GLOBAL.navigator;
|
|
1895
1895
|
var CLEANUP_INPUT_ELEMENT = null;
|
|
1896
1896
|
var DEBUG = false;
|
|
1897
|
+
var APP_IN_FLIGHT = null;
|
|
1897
1898
|
function createTypeGuard(tag) {
|
|
1898
1899
|
return function (value) {
|
|
1899
1900
|
return Object.prototype.toString.call(value) === '[object ' + tag + ']';
|
|
@@ -2110,7 +2111,8 @@ function resolveFocusEventConfig() {
|
|
|
2110
2111
|
};
|
|
2111
2112
|
}
|
|
2112
2113
|
}
|
|
2113
|
-
function openURL(tried, url, timeout) {
|
|
2114
|
+
function openURL(tried, url, timeout, terminal) {
|
|
2115
|
+
if (terminal === void 0) { terminal = false; }
|
|
2114
2116
|
var config = resolveFocusEventConfig();
|
|
2115
2117
|
var top = getTopmostWindow();
|
|
2116
2118
|
var topDocument = top.document;
|
|
@@ -2148,6 +2150,8 @@ function openURL(tried, url, timeout) {
|
|
|
2148
2150
|
}
|
|
2149
2151
|
}
|
|
2150
2152
|
}
|
|
2153
|
+
if (terminal)
|
|
2154
|
+
return;
|
|
2151
2155
|
try {
|
|
2152
2156
|
iframe = createHiddenElement('iframe');
|
|
2153
2157
|
iframe.src = url;
|
|
@@ -2166,6 +2170,17 @@ function openURL(tried, url, timeout) {
|
|
|
2166
2170
|
catch (_) {
|
|
2167
2171
|
}
|
|
2168
2172
|
}
|
|
2173
|
+
if (terminal) {
|
|
2174
|
+
return new Promise(function (resolve, reject) {
|
|
2175
|
+
try {
|
|
2176
|
+
open();
|
|
2177
|
+
resolve();
|
|
2178
|
+
}
|
|
2179
|
+
catch (_) {
|
|
2180
|
+
reject();
|
|
2181
|
+
}
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2169
2184
|
return new Promise(function (resolve, reject) {
|
|
2170
2185
|
if (DEBUG)
|
|
2171
2186
|
debugger;
|
|
@@ -2247,11 +2262,78 @@ function openURL(tried, url, timeout) {
|
|
|
2247
2262
|
}
|
|
2248
2263
|
});
|
|
2249
2264
|
}
|
|
2265
|
+
var FUNCTION_FALLBACK_LABEL = '[function fallback]';
|
|
2266
|
+
var CANCEL_DELAY = 1000;
|
|
2267
|
+
function createLaunchError(code, message, attempted) {
|
|
2268
|
+
var error = new Error(message);
|
|
2269
|
+
var holder = error;
|
|
2270
|
+
holder['code'] = code;
|
|
2271
|
+
holder['attempted'] = attempted;
|
|
2272
|
+
return error;
|
|
2273
|
+
}
|
|
2274
|
+
function isWebURL(url) {
|
|
2275
|
+
return /^https?:\/\//i.test(url);
|
|
2276
|
+
}
|
|
2277
|
+
function isTerminalCandidate(by, url) {
|
|
2278
|
+
return (by === 'fallback' || by === 'store') && isWebURL(url);
|
|
2279
|
+
}
|
|
2280
|
+
function notifyAttempt(onAttempt, attempt) {
|
|
2281
|
+
if (typeof onAttempt !== 'function')
|
|
2282
|
+
return;
|
|
2283
|
+
try {
|
|
2284
|
+
onAttempt(attempt);
|
|
2285
|
+
}
|
|
2286
|
+
catch (_) {
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
function describeAttempts(attempted) {
|
|
2290
|
+
var routes = [];
|
|
2291
|
+
for (var i = 0; i < attempted.length; i++)
|
|
2292
|
+
routes.push(attempted[i].by);
|
|
2293
|
+
return ' ' + attempted.length + ' candidate(s) attempted (' + joining(routes, undefined, ' \u2b62 ') + '). Read error.attempted for the URLs.';
|
|
2294
|
+
}
|
|
2295
|
+
function runCandidates(candidates, timeout, onAttempt, failure) {
|
|
2296
|
+
return new Promise(function (resolve, reject) {
|
|
2297
|
+
var attempted = [];
|
|
2298
|
+
var total = candidates.length;
|
|
2299
|
+
function step(index) {
|
|
2300
|
+
if (index >= total)
|
|
2301
|
+
return reject(createLaunchError('all-failed', failure + describeAttempts(attempted), attempted));
|
|
2302
|
+
var by = candidates[index][0];
|
|
2303
|
+
var url = candidates[index][1];
|
|
2304
|
+
var attempt = {
|
|
2305
|
+
by: by,
|
|
2306
|
+
url: typeof url === 'string' ? url : FUNCTION_FALLBACK_LABEL,
|
|
2307
|
+
index: index,
|
|
2308
|
+
total: total,
|
|
2309
|
+
};
|
|
2310
|
+
attempted.push(attempt);
|
|
2311
|
+
notifyAttempt(onAttempt, attempt);
|
|
2312
|
+
if (typeof url !== 'string') {
|
|
2313
|
+
try {
|
|
2314
|
+
url();
|
|
2315
|
+
}
|
|
2316
|
+
catch (_) {
|
|
2317
|
+
return step(index + 1);
|
|
2318
|
+
}
|
|
2319
|
+
return resolve(by);
|
|
2320
|
+
}
|
|
2321
|
+
openURL(index, url, timeout, isTerminalCandidate(by, url))
|
|
2322
|
+
.then(function () {
|
|
2323
|
+
resolve(by);
|
|
2324
|
+
})
|
|
2325
|
+
.catch(function () {
|
|
2326
|
+
step(index + 1);
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
step(0);
|
|
2330
|
+
});
|
|
2331
|
+
}
|
|
2250
2332
|
function resolveOptions(option) {
|
|
2251
2333
|
var resolved = [];
|
|
2252
2334
|
var os = PlatformKit.os.name;
|
|
2253
2335
|
if (os === 'unknown')
|
|
2254
|
-
throw
|
|
2336
|
+
throw createLaunchError('unsupported-os', 'Cannot resolve app open options: unsupported or undetected OS. (userAgent: "' + PlatformKit.userAgent + '")', []);
|
|
2255
2337
|
var scheme;
|
|
2256
2338
|
var fallback;
|
|
2257
2339
|
var allowAppStore;
|
|
@@ -2681,7 +2763,7 @@ function resolveFile(module) {
|
|
|
2681
2763
|
done(true);
|
|
2682
2764
|
else
|
|
2683
2765
|
done(false);
|
|
2684
|
-
},
|
|
2766
|
+
}, CANCEL_DELAY);
|
|
2685
2767
|
}
|
|
2686
2768
|
function onvisibilitychange() {
|
|
2687
2769
|
if (!isDocumentHidden())
|
|
@@ -2813,6 +2895,8 @@ var LaunchKit = {
|
|
|
2813
2895
|
},
|
|
2814
2896
|
app: function (options) {
|
|
2815
2897
|
if (options === void 0) { options = {}; }
|
|
2898
|
+
if (APP_IN_FLIGHT !== null)
|
|
2899
|
+
return APP_IN_FLIGHT;
|
|
2816
2900
|
var resolved;
|
|
2817
2901
|
try {
|
|
2818
2902
|
resolved = resolveOptions(options);
|
|
@@ -2823,39 +2907,15 @@ var LaunchKit = {
|
|
|
2823
2907
|
var urls = resolved[0];
|
|
2824
2908
|
var timeout = resolved[1];
|
|
2825
2909
|
if (urls.length === 0)
|
|
2826
|
-
return Promise.reject(
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
var url = entry[1];
|
|
2836
|
-
if (typeof url === 'string') {
|
|
2837
|
-
tried[index] = url;
|
|
2838
|
-
return openURL(index, url, timeout)
|
|
2839
|
-
.then(function () {
|
|
2840
|
-
resolve(by);
|
|
2841
|
-
})
|
|
2842
|
-
.catch(function () {
|
|
2843
|
-
openURLSequential(index + 1);
|
|
2844
|
-
});
|
|
2845
|
-
}
|
|
2846
|
-
else {
|
|
2847
|
-
tried[index] = '[function fallback]';
|
|
2848
|
-
try {
|
|
2849
|
-
url();
|
|
2850
|
-
}
|
|
2851
|
-
catch (_) {
|
|
2852
|
-
return openURLSequential(index + 1);
|
|
2853
|
-
}
|
|
2854
|
-
resolve(by);
|
|
2855
|
-
}
|
|
2856
|
-
}
|
|
2857
|
-
return openURLSequential();
|
|
2858
|
-
});
|
|
2910
|
+
return Promise.reject(createLaunchError('no-candidates', '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.', []));
|
|
2911
|
+
var attempt = runCandidates(urls, timeout, options.onAttempt, 'Failed to open the application.');
|
|
2912
|
+
function release() {
|
|
2913
|
+
if (APP_IN_FLIGHT === attempt)
|
|
2914
|
+
APP_IN_FLIGHT = null;
|
|
2915
|
+
}
|
|
2916
|
+
APP_IN_FLIGHT = attempt;
|
|
2917
|
+
attempt.then(release, release);
|
|
2918
|
+
return attempt;
|
|
2859
2919
|
},
|
|
2860
2920
|
telephone: function (options) {
|
|
2861
2921
|
if (options === void 0) { options = {}; }
|
|
@@ -2905,7 +2965,7 @@ var LaunchKit = {
|
|
|
2905
2965
|
map: function (options) {
|
|
2906
2966
|
if (options === void 0) { options = {}; }
|
|
2907
2967
|
var params = [];
|
|
2908
|
-
var
|
|
2968
|
+
var candidates = [];
|
|
2909
2969
|
var url = '';
|
|
2910
2970
|
switch (PlatformKit.os.name) {
|
|
2911
2971
|
case 'android':
|
|
@@ -2923,7 +2983,7 @@ var LaunchKit = {
|
|
|
2923
2983
|
params.push('z=' + options.zoom);
|
|
2924
2984
|
if (params.length > 0)
|
|
2925
2985
|
url = url + '?' + joining(params, undefined, '&');
|
|
2926
|
-
|
|
2986
|
+
candidates.push(['scheme', url]);
|
|
2927
2987
|
break;
|
|
2928
2988
|
case 'ios':
|
|
2929
2989
|
case 'macos':
|
|
@@ -2943,7 +3003,7 @@ var LaunchKit = {
|
|
|
2943
3003
|
}
|
|
2944
3004
|
if (typeof options.zoom !== 'undefined')
|
|
2945
3005
|
params.push('z=' + options.zoom);
|
|
2946
|
-
|
|
3006
|
+
candidates.push(['scheme', 'maps://?' + joining(params, undefined, '&')]);
|
|
2947
3007
|
break;
|
|
2948
3008
|
case 'windows':
|
|
2949
3009
|
if (typeof options.directions !== 'undefined') {
|
|
@@ -2959,10 +3019,10 @@ var LaunchKit = {
|
|
|
2959
3019
|
}
|
|
2960
3020
|
if (typeof options.zoom !== 'undefined')
|
|
2961
3021
|
params.push('lvl=' + options.zoom);
|
|
2962
|
-
|
|
3022
|
+
candidates.push(['scheme', 'bingmaps:?' + joining(params, undefined, '&')]);
|
|
2963
3023
|
}
|
|
2964
3024
|
if (typeof options.fallback !== 'undefined') {
|
|
2965
|
-
|
|
3025
|
+
candidates.push(['fallback', stripURL(options.fallback)]);
|
|
2966
3026
|
}
|
|
2967
3027
|
else {
|
|
2968
3028
|
var params_1 = ['api=1'];
|
|
@@ -2970,7 +3030,7 @@ var LaunchKit = {
|
|
|
2970
3030
|
params_1.push('destination=' + encodeMapValue(options.directions.destination));
|
|
2971
3031
|
if (typeof options.directions.origin !== 'undefined')
|
|
2972
3032
|
params_1.push('origin=' + encodeMapValue(options.directions.origin));
|
|
2973
|
-
|
|
3033
|
+
candidates.push(['fallback', 'https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&')]);
|
|
2974
3034
|
}
|
|
2975
3035
|
else {
|
|
2976
3036
|
if (typeof options.coordinate !== 'undefined')
|
|
@@ -2979,34 +3039,10 @@ var LaunchKit = {
|
|
|
2979
3039
|
params_1.push('query=' + escapeURIComponentString(options.query));
|
|
2980
3040
|
if (typeof options.zoom !== 'undefined')
|
|
2981
3041
|
params_1.push('zoom=' + options.zoom);
|
|
2982
|
-
|
|
3042
|
+
candidates.push(['fallback', 'https://www.google.com/maps/search/?' + joining(params_1, undefined, '&')]);
|
|
2983
3043
|
}
|
|
2984
3044
|
}
|
|
2985
|
-
return
|
|
2986
|
-
var tried = [];
|
|
2987
|
-
function openURLSequential(index) {
|
|
2988
|
-
if (index === void 0) { index = 0; }
|
|
2989
|
-
if (index >= urls.length)
|
|
2990
|
-
return reject(new Error('Failed to open a map using all available URLs.\n\nAttempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
|
|
2991
|
-
var url = urls[index];
|
|
2992
|
-
if (typeof url === 'string') {
|
|
2993
|
-
tried[index] = url;
|
|
2994
|
-
return openURL(index, url, getDefaultTimeout())
|
|
2995
|
-
.then(function () {
|
|
2996
|
-
resolve();
|
|
2997
|
-
})
|
|
2998
|
-
.catch(function () {
|
|
2999
|
-
openURLSequential(index + 1);
|
|
3000
|
-
});
|
|
3001
|
-
}
|
|
3002
|
-
else {
|
|
3003
|
-
tried[index] = '[function fallback]';
|
|
3004
|
-
url();
|
|
3005
|
-
resolve();
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
return openURLSequential();
|
|
3009
|
-
});
|
|
3045
|
+
return runCandidates(candidates, getDefaultTimeout(), options.onAttempt, 'Failed to open a map.');
|
|
3010
3046
|
},
|
|
3011
3047
|
filepicker: function (options) {
|
|
3012
3048
|
if (options === void 0) { options = {}; }
|