web-launch-kit 0.0.4 → 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 +53 -4
- package/README.md +54 -4
- package/dist/index.d.ts +17 -2
- package/dist/launch-kit.cjs +116 -81
- 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 +116 -81
- package/dist/launch-kit.mjs.map +1 -1
- package/dist/launch-kit.umd.js +116 -81
- 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 +2 -2
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
|
|
|
@@ -258,7 +258,7 @@ function parseWebview() {
|
|
|
258
258
|
return true;
|
|
259
259
|
if (/\belectron\//i.test(currentUserAgent))
|
|
260
260
|
return true;
|
|
261
|
-
if (/
|
|
261
|
+
if (/iphone|ipad|ipod/i.test(currentUserAgent) && /applewebkit/i.test(currentUserAgent) && /safari/i.test(currentUserAgent) === false)
|
|
262
262
|
return true;
|
|
263
263
|
return parseInAppBrowser() !== null;
|
|
264
264
|
}
|
|
@@ -488,7 +488,7 @@ function getGlobal$2() {
|
|
|
488
488
|
return {};
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
var version$1 = "0.0.
|
|
491
|
+
var version$1 = "0.0.3";
|
|
492
492
|
var packageJSON$1 = {
|
|
493
493
|
version: version$1};
|
|
494
494
|
|
|
@@ -938,8 +938,6 @@ var GLOBAL$4 = getGlobal$2();
|
|
|
938
938
|
var LISTENER_STORE = [];
|
|
939
939
|
var NOOP = function () {
|
|
940
940
|
};
|
|
941
|
-
// Records live on the target itself, so they are collected with it and lookups only scan
|
|
942
|
-
// that target's own listeners. Targets that reject the expando fall back to LISTENER_STORE.
|
|
943
941
|
var STORE_KEY = '__webEventKitListeners__';
|
|
944
942
|
function resolveBucket(target, create) {
|
|
945
943
|
var holder = target;
|
|
@@ -997,9 +995,6 @@ function invokeCallback(callback, target, event) {
|
|
|
997
995
|
if (typeof callback === 'object' && callback !== null && typeof callback.handleEvent === 'function')
|
|
998
996
|
return callback.handleEvent(event);
|
|
999
997
|
}
|
|
1000
|
-
// The same Event object is handed to every listener, so any property this kit overrides has
|
|
1001
|
-
// to be put back before the next one runs — otherwise a `pointerdown` listener would observe
|
|
1002
|
-
// the `touchstart` type and synthetic touches written by a listener registered before it.
|
|
1003
998
|
function patchEventProperty(event, property, value, patches) {
|
|
1004
999
|
var holder = event;
|
|
1005
1000
|
var had = false;
|
|
@@ -1165,8 +1160,6 @@ var EventKit = {
|
|
|
1165
1160
|
return NOOP;
|
|
1166
1161
|
var normalized = normalizeListenerOptions(options);
|
|
1167
1162
|
var existing = findListenerRecord(target, type, callback, normalized.capture);
|
|
1168
|
-
// Native `addEventListener` ignores a duplicate registration, so hand back a releaser
|
|
1169
|
-
// that does nothing rather than one that would detach the first caller's listener.
|
|
1170
1163
|
if (typeof existing !== 'undefined')
|
|
1171
1164
|
return NOOP;
|
|
1172
1165
|
if (typeof normalized.signal !== 'undefined' && normalized.signal.aborted)
|
|
@@ -1196,8 +1189,6 @@ var EventKit = {
|
|
|
1196
1189
|
record.onAbort = function () {
|
|
1197
1190
|
releaseListenerRecord(record);
|
|
1198
1191
|
};
|
|
1199
|
-
// Engines without listener-options coerce `{once: true}` to capture, which would then
|
|
1200
|
-
// fail to match on removal; releaseListenerRecord detaches this anyway.
|
|
1201
1192
|
record.signal.addEventListener('abort', record.onAbort, false);
|
|
1202
1193
|
}
|
|
1203
1194
|
return function () {
|
|
@@ -1902,6 +1893,8 @@ var DEFAULT_TIMEOUT = 750;
|
|
|
1902
1893
|
var GLOBAL = getGlobal$1();
|
|
1903
1894
|
var NAVIGATOR = GLOBAL.navigator;
|
|
1904
1895
|
var CLEANUP_INPUT_ELEMENT = null;
|
|
1896
|
+
var DEBUG = false;
|
|
1897
|
+
var APP_IN_FLIGHT = null;
|
|
1905
1898
|
function createTypeGuard(tag) {
|
|
1906
1899
|
return function (value) {
|
|
1907
1900
|
return Object.prototype.toString.call(value) === '[object ' + tag + ']';
|
|
@@ -2118,7 +2111,8 @@ function resolveFocusEventConfig() {
|
|
|
2118
2111
|
};
|
|
2119
2112
|
}
|
|
2120
2113
|
}
|
|
2121
|
-
function openURL(tried, url, timeout) {
|
|
2114
|
+
function openURL(tried, url, timeout, terminal) {
|
|
2115
|
+
if (terminal === void 0) { terminal = false; }
|
|
2122
2116
|
var config = resolveFocusEventConfig();
|
|
2123
2117
|
var top = getTopmostWindow();
|
|
2124
2118
|
var topDocument = top.document;
|
|
@@ -2156,6 +2150,8 @@ function openURL(tried, url, timeout) {
|
|
|
2156
2150
|
}
|
|
2157
2151
|
}
|
|
2158
2152
|
}
|
|
2153
|
+
if (terminal)
|
|
2154
|
+
return;
|
|
2159
2155
|
try {
|
|
2160
2156
|
iframe = createHiddenElement('iframe');
|
|
2161
2157
|
iframe.src = url;
|
|
@@ -2174,8 +2170,20 @@ function openURL(tried, url, timeout) {
|
|
|
2174
2170
|
catch (_) {
|
|
2175
2171
|
}
|
|
2176
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
|
+
}
|
|
2177
2184
|
return new Promise(function (resolve, reject) {
|
|
2178
|
-
|
|
2185
|
+
if (DEBUG)
|
|
2186
|
+
debugger;
|
|
2179
2187
|
var timeoutId;
|
|
2180
2188
|
var resolved = false;
|
|
2181
2189
|
function cleanup() {
|
|
@@ -2254,11 +2262,78 @@ function openURL(tried, url, timeout) {
|
|
|
2254
2262
|
}
|
|
2255
2263
|
});
|
|
2256
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
|
+
}
|
|
2257
2332
|
function resolveOptions(option) {
|
|
2258
2333
|
var resolved = [];
|
|
2259
2334
|
var os = PlatformKit.os.name;
|
|
2260
2335
|
if (os === 'unknown')
|
|
2261
|
-
throw
|
|
2336
|
+
throw createLaunchError('unsupported-os', 'Cannot resolve app open options: unsupported or undetected OS. (userAgent: "' + PlatformKit.userAgent + '")', []);
|
|
2262
2337
|
var scheme;
|
|
2263
2338
|
var fallback;
|
|
2264
2339
|
var allowAppStore;
|
|
@@ -2688,7 +2763,7 @@ function resolveFile(module) {
|
|
|
2688
2763
|
done(true);
|
|
2689
2764
|
else
|
|
2690
2765
|
done(false);
|
|
2691
|
-
},
|
|
2766
|
+
}, CANCEL_DELAY);
|
|
2692
2767
|
}
|
|
2693
2768
|
function onvisibilitychange() {
|
|
2694
2769
|
if (!isDocumentHidden())
|
|
@@ -2799,6 +2874,12 @@ function walk(directory, basePath) {
|
|
|
2799
2874
|
var LaunchKit = {
|
|
2800
2875
|
SettingType: SettingType,
|
|
2801
2876
|
version: packageJSON$3.version,
|
|
2877
|
+
get debug() {
|
|
2878
|
+
return DEBUG;
|
|
2879
|
+
},
|
|
2880
|
+
set debug(value) {
|
|
2881
|
+
DEBUG = value === true;
|
|
2882
|
+
},
|
|
2802
2883
|
utils: {
|
|
2803
2884
|
get canOpenIntent() {
|
|
2804
2885
|
return canOpenIntent();
|
|
@@ -2814,6 +2895,8 @@ var LaunchKit = {
|
|
|
2814
2895
|
},
|
|
2815
2896
|
app: function (options) {
|
|
2816
2897
|
if (options === void 0) { options = {}; }
|
|
2898
|
+
if (APP_IN_FLIGHT !== null)
|
|
2899
|
+
return APP_IN_FLIGHT;
|
|
2817
2900
|
var resolved;
|
|
2818
2901
|
try {
|
|
2819
2902
|
resolved = resolveOptions(options);
|
|
@@ -2824,39 +2907,15 @@ var LaunchKit = {
|
|
|
2824
2907
|
var urls = resolved[0];
|
|
2825
2908
|
var timeout = resolved[1];
|
|
2826
2909
|
if (urls.length === 0)
|
|
2827
|
-
return Promise.reject(
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
var url = entry[1];
|
|
2837
|
-
if (typeof url === 'string') {
|
|
2838
|
-
tried[index] = url;
|
|
2839
|
-
return openURL(index, url, timeout)
|
|
2840
|
-
.then(function () {
|
|
2841
|
-
resolve(by);
|
|
2842
|
-
})
|
|
2843
|
-
.catch(function () {
|
|
2844
|
-
openURLSequential(index + 1);
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
else {
|
|
2848
|
-
tried[index] = '[function fallback]';
|
|
2849
|
-
try {
|
|
2850
|
-
url();
|
|
2851
|
-
}
|
|
2852
|
-
catch (_) {
|
|
2853
|
-
return openURLSequential(index + 1);
|
|
2854
|
-
}
|
|
2855
|
-
resolve(by);
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
|
-
return openURLSequential();
|
|
2859
|
-
});
|
|
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;
|
|
2860
2919
|
},
|
|
2861
2920
|
telephone: function (options) {
|
|
2862
2921
|
if (options === void 0) { options = {}; }
|
|
@@ -2906,7 +2965,7 @@ var LaunchKit = {
|
|
|
2906
2965
|
map: function (options) {
|
|
2907
2966
|
if (options === void 0) { options = {}; }
|
|
2908
2967
|
var params = [];
|
|
2909
|
-
var
|
|
2968
|
+
var candidates = [];
|
|
2910
2969
|
var url = '';
|
|
2911
2970
|
switch (PlatformKit.os.name) {
|
|
2912
2971
|
case 'android':
|
|
@@ -2924,7 +2983,7 @@ var LaunchKit = {
|
|
|
2924
2983
|
params.push('z=' + options.zoom);
|
|
2925
2984
|
if (params.length > 0)
|
|
2926
2985
|
url = url + '?' + joining(params, undefined, '&');
|
|
2927
|
-
|
|
2986
|
+
candidates.push(['scheme', url]);
|
|
2928
2987
|
break;
|
|
2929
2988
|
case 'ios':
|
|
2930
2989
|
case 'macos':
|
|
@@ -2944,7 +3003,7 @@ var LaunchKit = {
|
|
|
2944
3003
|
}
|
|
2945
3004
|
if (typeof options.zoom !== 'undefined')
|
|
2946
3005
|
params.push('z=' + options.zoom);
|
|
2947
|
-
|
|
3006
|
+
candidates.push(['scheme', 'maps://?' + joining(params, undefined, '&')]);
|
|
2948
3007
|
break;
|
|
2949
3008
|
case 'windows':
|
|
2950
3009
|
if (typeof options.directions !== 'undefined') {
|
|
@@ -2960,10 +3019,10 @@ var LaunchKit = {
|
|
|
2960
3019
|
}
|
|
2961
3020
|
if (typeof options.zoom !== 'undefined')
|
|
2962
3021
|
params.push('lvl=' + options.zoom);
|
|
2963
|
-
|
|
3022
|
+
candidates.push(['scheme', 'bingmaps:?' + joining(params, undefined, '&')]);
|
|
2964
3023
|
}
|
|
2965
3024
|
if (typeof options.fallback !== 'undefined') {
|
|
2966
|
-
|
|
3025
|
+
candidates.push(['fallback', stripURL(options.fallback)]);
|
|
2967
3026
|
}
|
|
2968
3027
|
else {
|
|
2969
3028
|
var params_1 = ['api=1'];
|
|
@@ -2971,7 +3030,7 @@ var LaunchKit = {
|
|
|
2971
3030
|
params_1.push('destination=' + encodeMapValue(options.directions.destination));
|
|
2972
3031
|
if (typeof options.directions.origin !== 'undefined')
|
|
2973
3032
|
params_1.push('origin=' + encodeMapValue(options.directions.origin));
|
|
2974
|
-
|
|
3033
|
+
candidates.push(['fallback', 'https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&')]);
|
|
2975
3034
|
}
|
|
2976
3035
|
else {
|
|
2977
3036
|
if (typeof options.coordinate !== 'undefined')
|
|
@@ -2980,34 +3039,10 @@ var LaunchKit = {
|
|
|
2980
3039
|
params_1.push('query=' + escapeURIComponentString(options.query));
|
|
2981
3040
|
if (typeof options.zoom !== 'undefined')
|
|
2982
3041
|
params_1.push('zoom=' + options.zoom);
|
|
2983
|
-
|
|
3042
|
+
candidates.push(['fallback', 'https://www.google.com/maps/search/?' + joining(params_1, undefined, '&')]);
|
|
2984
3043
|
}
|
|
2985
3044
|
}
|
|
2986
|
-
return
|
|
2987
|
-
var tried = [];
|
|
2988
|
-
function openURLSequential(index) {
|
|
2989
|
-
if (index === void 0) { index = 0; }
|
|
2990
|
-
if (index >= urls.length)
|
|
2991
|
-
return reject(new Error('Failed to open a map using all available URLs.\n\nAttempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
|
|
2992
|
-
var url = urls[index];
|
|
2993
|
-
if (typeof url === 'string') {
|
|
2994
|
-
tried[index] = url;
|
|
2995
|
-
return openURL(index, url, getDefaultTimeout())
|
|
2996
|
-
.then(function () {
|
|
2997
|
-
resolve();
|
|
2998
|
-
})
|
|
2999
|
-
.catch(function () {
|
|
3000
|
-
openURLSequential(index + 1);
|
|
3001
|
-
});
|
|
3002
|
-
}
|
|
3003
|
-
else {
|
|
3004
|
-
tried[index] = '[function fallback]';
|
|
3005
|
-
url();
|
|
3006
|
-
resolve();
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
return openURLSequential();
|
|
3010
|
-
});
|
|
3045
|
+
return runCandidates(candidates, getDefaultTimeout(), options.onAttempt, 'Failed to open a map.');
|
|
3011
3046
|
},
|
|
3012
3047
|
filepicker: function (options) {
|
|
3013
3048
|
if (options === void 0) { options = {}; }
|