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.umd.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.LaunchKit = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
var version$3 = "0.0.
|
|
7
|
+
var version$3 = "0.0.6";
|
|
8
8
|
var packageJSON$3 = {
|
|
9
9
|
version: version$3};
|
|
10
10
|
|
|
@@ -1900,6 +1900,7 @@
|
|
|
1900
1900
|
var NAVIGATOR = GLOBAL.navigator;
|
|
1901
1901
|
var CLEANUP_INPUT_ELEMENT = null;
|
|
1902
1902
|
var DEBUG = false;
|
|
1903
|
+
var APP_IN_FLIGHT = null;
|
|
1903
1904
|
function createTypeGuard(tag) {
|
|
1904
1905
|
return function (value) {
|
|
1905
1906
|
return Object.prototype.toString.call(value) === '[object ' + tag + ']';
|
|
@@ -2116,7 +2117,8 @@
|
|
|
2116
2117
|
};
|
|
2117
2118
|
}
|
|
2118
2119
|
}
|
|
2119
|
-
function openURL(tried, url, timeout) {
|
|
2120
|
+
function openURL(tried, url, timeout, terminal) {
|
|
2121
|
+
if (terminal === void 0) { terminal = false; }
|
|
2120
2122
|
var config = resolveFocusEventConfig();
|
|
2121
2123
|
var top = getTopmostWindow();
|
|
2122
2124
|
var topDocument = top.document;
|
|
@@ -2154,6 +2156,8 @@
|
|
|
2154
2156
|
}
|
|
2155
2157
|
}
|
|
2156
2158
|
}
|
|
2159
|
+
if (terminal)
|
|
2160
|
+
return;
|
|
2157
2161
|
try {
|
|
2158
2162
|
iframe = createHiddenElement('iframe');
|
|
2159
2163
|
iframe.src = url;
|
|
@@ -2172,6 +2176,17 @@
|
|
|
2172
2176
|
catch (_) {
|
|
2173
2177
|
}
|
|
2174
2178
|
}
|
|
2179
|
+
if (terminal) {
|
|
2180
|
+
return new Promise(function (resolve, reject) {
|
|
2181
|
+
try {
|
|
2182
|
+
open();
|
|
2183
|
+
resolve();
|
|
2184
|
+
}
|
|
2185
|
+
catch (_) {
|
|
2186
|
+
reject();
|
|
2187
|
+
}
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2175
2190
|
return new Promise(function (resolve, reject) {
|
|
2176
2191
|
if (DEBUG)
|
|
2177
2192
|
debugger;
|
|
@@ -2253,11 +2268,78 @@
|
|
|
2253
2268
|
}
|
|
2254
2269
|
});
|
|
2255
2270
|
}
|
|
2271
|
+
var FUNCTION_FALLBACK_LABEL = '[function fallback]';
|
|
2272
|
+
var CANCEL_DELAY = 1000;
|
|
2273
|
+
function createLaunchError(code, message, attempted) {
|
|
2274
|
+
var error = new Error(message);
|
|
2275
|
+
var holder = error;
|
|
2276
|
+
holder['code'] = code;
|
|
2277
|
+
holder['attempted'] = attempted;
|
|
2278
|
+
return error;
|
|
2279
|
+
}
|
|
2280
|
+
function isWebURL(url) {
|
|
2281
|
+
return /^https?:\/\//i.test(url);
|
|
2282
|
+
}
|
|
2283
|
+
function isTerminalCandidate(by, url) {
|
|
2284
|
+
return (by === 'fallback' || by === 'store') && isWebURL(url);
|
|
2285
|
+
}
|
|
2286
|
+
function notifyAttempt(onAttempt, attempt) {
|
|
2287
|
+
if (typeof onAttempt !== 'function')
|
|
2288
|
+
return;
|
|
2289
|
+
try {
|
|
2290
|
+
onAttempt(attempt);
|
|
2291
|
+
}
|
|
2292
|
+
catch (_) {
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
function describeAttempts(attempted) {
|
|
2296
|
+
var routes = [];
|
|
2297
|
+
for (var i = 0; i < attempted.length; i++)
|
|
2298
|
+
routes.push(attempted[i].by);
|
|
2299
|
+
return ' ' + attempted.length + ' candidate(s) attempted (' + joining(routes, undefined, ' \u2b62 ') + '). Read error.attempted for the URLs.';
|
|
2300
|
+
}
|
|
2301
|
+
function runCandidates(candidates, timeout, onAttempt, failure) {
|
|
2302
|
+
return new Promise(function (resolve, reject) {
|
|
2303
|
+
var attempted = [];
|
|
2304
|
+
var total = candidates.length;
|
|
2305
|
+
function step(index) {
|
|
2306
|
+
if (index >= total)
|
|
2307
|
+
return reject(createLaunchError('all-failed', failure + describeAttempts(attempted), attempted));
|
|
2308
|
+
var by = candidates[index][0];
|
|
2309
|
+
var url = candidates[index][1];
|
|
2310
|
+
var attempt = {
|
|
2311
|
+
by: by,
|
|
2312
|
+
url: typeof url === 'string' ? url : FUNCTION_FALLBACK_LABEL,
|
|
2313
|
+
index: index,
|
|
2314
|
+
total: total,
|
|
2315
|
+
};
|
|
2316
|
+
attempted.push(attempt);
|
|
2317
|
+
notifyAttempt(onAttempt, attempt);
|
|
2318
|
+
if (typeof url !== 'string') {
|
|
2319
|
+
try {
|
|
2320
|
+
url();
|
|
2321
|
+
}
|
|
2322
|
+
catch (_) {
|
|
2323
|
+
return step(index + 1);
|
|
2324
|
+
}
|
|
2325
|
+
return resolve(by);
|
|
2326
|
+
}
|
|
2327
|
+
openURL(index, url, timeout, isTerminalCandidate(by, url))
|
|
2328
|
+
.then(function () {
|
|
2329
|
+
resolve(by);
|
|
2330
|
+
})
|
|
2331
|
+
.catch(function () {
|
|
2332
|
+
step(index + 1);
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
step(0);
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2256
2338
|
function resolveOptions(option) {
|
|
2257
2339
|
var resolved = [];
|
|
2258
2340
|
var os = PlatformKit.os.name;
|
|
2259
2341
|
if (os === 'unknown')
|
|
2260
|
-
throw
|
|
2342
|
+
throw createLaunchError('unsupported-os', 'Cannot resolve app open options: unsupported or undetected OS. (userAgent: "' + PlatformKit.userAgent + '")', []);
|
|
2261
2343
|
var scheme;
|
|
2262
2344
|
var fallback;
|
|
2263
2345
|
var allowAppStore;
|
|
@@ -2687,7 +2769,7 @@
|
|
|
2687
2769
|
done(true);
|
|
2688
2770
|
else
|
|
2689
2771
|
done(false);
|
|
2690
|
-
},
|
|
2772
|
+
}, CANCEL_DELAY);
|
|
2691
2773
|
}
|
|
2692
2774
|
function onvisibilitychange() {
|
|
2693
2775
|
if (!isDocumentHidden())
|
|
@@ -2819,6 +2901,8 @@
|
|
|
2819
2901
|
},
|
|
2820
2902
|
app: function (options) {
|
|
2821
2903
|
if (options === void 0) { options = {}; }
|
|
2904
|
+
if (APP_IN_FLIGHT !== null)
|
|
2905
|
+
return APP_IN_FLIGHT;
|
|
2822
2906
|
var resolved;
|
|
2823
2907
|
try {
|
|
2824
2908
|
resolved = resolveOptions(options);
|
|
@@ -2829,39 +2913,15 @@
|
|
|
2829
2913
|
var urls = resolved[0];
|
|
2830
2914
|
var timeout = resolved[1];
|
|
2831
2915
|
if (urls.length === 0)
|
|
2832
|
-
return Promise.reject(
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
var url = entry[1];
|
|
2842
|
-
if (typeof url === 'string') {
|
|
2843
|
-
tried[index] = url;
|
|
2844
|
-
return openURL(index, url, timeout)
|
|
2845
|
-
.then(function () {
|
|
2846
|
-
resolve(by);
|
|
2847
|
-
})
|
|
2848
|
-
.catch(function () {
|
|
2849
|
-
openURLSequential(index + 1);
|
|
2850
|
-
});
|
|
2851
|
-
}
|
|
2852
|
-
else {
|
|
2853
|
-
tried[index] = '[function fallback]';
|
|
2854
|
-
try {
|
|
2855
|
-
url();
|
|
2856
|
-
}
|
|
2857
|
-
catch (_) {
|
|
2858
|
-
return openURLSequential(index + 1);
|
|
2859
|
-
}
|
|
2860
|
-
resolve(by);
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
return openURLSequential();
|
|
2864
|
-
});
|
|
2916
|
+
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.', []));
|
|
2917
|
+
var attempt = runCandidates(urls, timeout, options.onAttempt, 'Failed to open the application.');
|
|
2918
|
+
function release() {
|
|
2919
|
+
if (APP_IN_FLIGHT === attempt)
|
|
2920
|
+
APP_IN_FLIGHT = null;
|
|
2921
|
+
}
|
|
2922
|
+
APP_IN_FLIGHT = attempt;
|
|
2923
|
+
attempt.then(release, release);
|
|
2924
|
+
return attempt;
|
|
2865
2925
|
},
|
|
2866
2926
|
telephone: function (options) {
|
|
2867
2927
|
if (options === void 0) { options = {}; }
|
|
@@ -2911,7 +2971,7 @@
|
|
|
2911
2971
|
map: function (options) {
|
|
2912
2972
|
if (options === void 0) { options = {}; }
|
|
2913
2973
|
var params = [];
|
|
2914
|
-
var
|
|
2974
|
+
var candidates = [];
|
|
2915
2975
|
var url = '';
|
|
2916
2976
|
switch (PlatformKit.os.name) {
|
|
2917
2977
|
case 'android':
|
|
@@ -2929,7 +2989,7 @@
|
|
|
2929
2989
|
params.push('z=' + options.zoom);
|
|
2930
2990
|
if (params.length > 0)
|
|
2931
2991
|
url = url + '?' + joining(params, undefined, '&');
|
|
2932
|
-
|
|
2992
|
+
candidates.push(['scheme', url]);
|
|
2933
2993
|
break;
|
|
2934
2994
|
case 'ios':
|
|
2935
2995
|
case 'macos':
|
|
@@ -2949,7 +3009,7 @@
|
|
|
2949
3009
|
}
|
|
2950
3010
|
if (typeof options.zoom !== 'undefined')
|
|
2951
3011
|
params.push('z=' + options.zoom);
|
|
2952
|
-
|
|
3012
|
+
candidates.push(['scheme', 'maps://?' + joining(params, undefined, '&')]);
|
|
2953
3013
|
break;
|
|
2954
3014
|
case 'windows':
|
|
2955
3015
|
if (typeof options.directions !== 'undefined') {
|
|
@@ -2965,10 +3025,10 @@
|
|
|
2965
3025
|
}
|
|
2966
3026
|
if (typeof options.zoom !== 'undefined')
|
|
2967
3027
|
params.push('lvl=' + options.zoom);
|
|
2968
|
-
|
|
3028
|
+
candidates.push(['scheme', 'bingmaps:?' + joining(params, undefined, '&')]);
|
|
2969
3029
|
}
|
|
2970
3030
|
if (typeof options.fallback !== 'undefined') {
|
|
2971
|
-
|
|
3031
|
+
candidates.push(['fallback', stripURL(options.fallback)]);
|
|
2972
3032
|
}
|
|
2973
3033
|
else {
|
|
2974
3034
|
var params_1 = ['api=1'];
|
|
@@ -2976,7 +3036,7 @@
|
|
|
2976
3036
|
params_1.push('destination=' + encodeMapValue(options.directions.destination));
|
|
2977
3037
|
if (typeof options.directions.origin !== 'undefined')
|
|
2978
3038
|
params_1.push('origin=' + encodeMapValue(options.directions.origin));
|
|
2979
|
-
|
|
3039
|
+
candidates.push(['fallback', 'https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&')]);
|
|
2980
3040
|
}
|
|
2981
3041
|
else {
|
|
2982
3042
|
if (typeof options.coordinate !== 'undefined')
|
|
@@ -2985,34 +3045,10 @@
|
|
|
2985
3045
|
params_1.push('query=' + escapeURIComponentString(options.query));
|
|
2986
3046
|
if (typeof options.zoom !== 'undefined')
|
|
2987
3047
|
params_1.push('zoom=' + options.zoom);
|
|
2988
|
-
|
|
3048
|
+
candidates.push(['fallback', 'https://www.google.com/maps/search/?' + joining(params_1, undefined, '&')]);
|
|
2989
3049
|
}
|
|
2990
3050
|
}
|
|
2991
|
-
return
|
|
2992
|
-
var tried = [];
|
|
2993
|
-
function openURLSequential(index) {
|
|
2994
|
-
if (index === void 0) { index = 0; }
|
|
2995
|
-
if (index >= urls.length)
|
|
2996
|
-
return reject(new Error('Failed to open a map using all available URLs.\n\nAttempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
|
|
2997
|
-
var url = urls[index];
|
|
2998
|
-
if (typeof url === 'string') {
|
|
2999
|
-
tried[index] = url;
|
|
3000
|
-
return openURL(index, url, getDefaultTimeout())
|
|
3001
|
-
.then(function () {
|
|
3002
|
-
resolve();
|
|
3003
|
-
})
|
|
3004
|
-
.catch(function () {
|
|
3005
|
-
openURLSequential(index + 1);
|
|
3006
|
-
});
|
|
3007
|
-
}
|
|
3008
|
-
else {
|
|
3009
|
-
tried[index] = '[function fallback]';
|
|
3010
|
-
url();
|
|
3011
|
-
resolve();
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
return openURLSequential();
|
|
3015
|
-
});
|
|
3051
|
+
return runCandidates(candidates, getDefaultTimeout(), options.onAttempt, 'Failed to open a map.');
|
|
3016
3052
|
},
|
|
3017
3053
|
filepicker: function (options) {
|
|
3018
3054
|
if (options === void 0) { options = {}; }
|