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.
@@ -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.4";
7
+ var version$3 = "0.0.6";
8
8
  var packageJSON$3 = {
9
9
  version: version$3};
10
10
 
@@ -264,7 +264,7 @@
264
264
  return true;
265
265
  if (/\belectron\//i.test(currentUserAgent))
266
266
  return true;
267
- if (/(?:iphone|ipad|ipod)/i.test(currentUserAgent) && /applewebkit/i.test(currentUserAgent) && /safari/i.test(currentUserAgent) === false)
267
+ if (/iphone|ipad|ipod/i.test(currentUserAgent) && /applewebkit/i.test(currentUserAgent) && /safari/i.test(currentUserAgent) === false)
268
268
  return true;
269
269
  return parseInAppBrowser() !== null;
270
270
  }
@@ -494,7 +494,7 @@
494
494
  return {};
495
495
  }
496
496
 
497
- var version$1 = "0.0.1";
497
+ var version$1 = "0.0.3";
498
498
  var packageJSON$1 = {
499
499
  version: version$1};
500
500
 
@@ -944,8 +944,6 @@
944
944
  var LISTENER_STORE = [];
945
945
  var NOOP = function () {
946
946
  };
947
- // Records live on the target itself, so they are collected with it and lookups only scan
948
- // that target's own listeners. Targets that reject the expando fall back to LISTENER_STORE.
949
947
  var STORE_KEY = '__webEventKitListeners__';
950
948
  function resolveBucket(target, create) {
951
949
  var holder = target;
@@ -1003,9 +1001,6 @@
1003
1001
  if (typeof callback === 'object' && callback !== null && typeof callback.handleEvent === 'function')
1004
1002
  return callback.handleEvent(event);
1005
1003
  }
1006
- // The same Event object is handed to every listener, so any property this kit overrides has
1007
- // to be put back before the next one runs — otherwise a `pointerdown` listener would observe
1008
- // the `touchstart` type and synthetic touches written by a listener registered before it.
1009
1004
  function patchEventProperty(event, property, value, patches) {
1010
1005
  var holder = event;
1011
1006
  var had = false;
@@ -1171,8 +1166,6 @@
1171
1166
  return NOOP;
1172
1167
  var normalized = normalizeListenerOptions(options);
1173
1168
  var existing = findListenerRecord(target, type, callback, normalized.capture);
1174
- // Native `addEventListener` ignores a duplicate registration, so hand back a releaser
1175
- // that does nothing rather than one that would detach the first caller's listener.
1176
1169
  if (typeof existing !== 'undefined')
1177
1170
  return NOOP;
1178
1171
  if (typeof normalized.signal !== 'undefined' && normalized.signal.aborted)
@@ -1202,8 +1195,6 @@
1202
1195
  record.onAbort = function () {
1203
1196
  releaseListenerRecord(record);
1204
1197
  };
1205
- // Engines without listener-options coerce `{once: true}` to capture, which would then
1206
- // fail to match on removal; releaseListenerRecord detaches this anyway.
1207
1198
  record.signal.addEventListener('abort', record.onAbort, false);
1208
1199
  }
1209
1200
  return function () {
@@ -1908,6 +1899,8 @@
1908
1899
  var GLOBAL = getGlobal$1();
1909
1900
  var NAVIGATOR = GLOBAL.navigator;
1910
1901
  var CLEANUP_INPUT_ELEMENT = null;
1902
+ var DEBUG = false;
1903
+ var APP_IN_FLIGHT = null;
1911
1904
  function createTypeGuard(tag) {
1912
1905
  return function (value) {
1913
1906
  return Object.prototype.toString.call(value) === '[object ' + tag + ']';
@@ -2124,7 +2117,8 @@
2124
2117
  };
2125
2118
  }
2126
2119
  }
2127
- function openURL(tried, url, timeout) {
2120
+ function openURL(tried, url, timeout, terminal) {
2121
+ if (terminal === void 0) { terminal = false; }
2128
2122
  var config = resolveFocusEventConfig();
2129
2123
  var top = getTopmostWindow();
2130
2124
  var topDocument = top.document;
@@ -2162,6 +2156,8 @@
2162
2156
  }
2163
2157
  }
2164
2158
  }
2159
+ if (terminal)
2160
+ return;
2165
2161
  try {
2166
2162
  iframe = createHiddenElement('iframe');
2167
2163
  iframe.src = url;
@@ -2180,8 +2176,20 @@
2180
2176
  catch (_) {
2181
2177
  }
2182
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
+ }
2183
2190
  return new Promise(function (resolve, reject) {
2184
- debugger;
2191
+ if (DEBUG)
2192
+ debugger;
2185
2193
  var timeoutId;
2186
2194
  var resolved = false;
2187
2195
  function cleanup() {
@@ -2260,11 +2268,78 @@
2260
2268
  }
2261
2269
  });
2262
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
+ }
2263
2338
  function resolveOptions(option) {
2264
2339
  var resolved = [];
2265
2340
  var os = PlatformKit.os.name;
2266
2341
  if (os === 'unknown')
2267
- throw new Error('Cannot resolve app open options: unsupported or undetected OS. (userAgent: "' + PlatformKit.userAgent + '")');
2342
+ throw createLaunchError('unsupported-os', 'Cannot resolve app open options: unsupported or undetected OS. (userAgent: "' + PlatformKit.userAgent + '")', []);
2268
2343
  var scheme;
2269
2344
  var fallback;
2270
2345
  var allowAppStore;
@@ -2694,7 +2769,7 @@
2694
2769
  done(true);
2695
2770
  else
2696
2771
  done(false);
2697
- }, 1000);
2772
+ }, CANCEL_DELAY);
2698
2773
  }
2699
2774
  function onvisibilitychange() {
2700
2775
  if (!isDocumentHidden())
@@ -2805,6 +2880,12 @@
2805
2880
  var LaunchKit = {
2806
2881
  SettingType: exports.SettingType,
2807
2882
  version: packageJSON$3.version,
2883
+ get debug() {
2884
+ return DEBUG;
2885
+ },
2886
+ set debug(value) {
2887
+ DEBUG = value === true;
2888
+ },
2808
2889
  utils: {
2809
2890
  get canOpenIntent() {
2810
2891
  return canOpenIntent();
@@ -2820,6 +2901,8 @@
2820
2901
  },
2821
2902
  app: function (options) {
2822
2903
  if (options === void 0) { options = {}; }
2904
+ if (APP_IN_FLIGHT !== null)
2905
+ return APP_IN_FLIGHT;
2823
2906
  var resolved;
2824
2907
  try {
2825
2908
  resolved = resolveOptions(options);
@@ -2830,39 +2913,15 @@
2830
2913
  var urls = resolved[0];
2831
2914
  var timeout = resolved[1];
2832
2915
  if (urls.length === 0)
2833
- 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.'));
2834
- return new Promise(function (resolve, reject) {
2835
- var tried = [];
2836
- function openURLSequential(index) {
2837
- if (index === void 0) { index = 0; }
2838
- if (index >= urls.length)
2839
- return reject(new Error('Failed to open the application using all available URLs.\n\n' + 'Attempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
2840
- var entry = urls[index];
2841
- var by = entry[0];
2842
- var url = entry[1];
2843
- if (typeof url === 'string') {
2844
- tried[index] = url;
2845
- return openURL(index, url, timeout)
2846
- .then(function () {
2847
- resolve(by);
2848
- })
2849
- .catch(function () {
2850
- openURLSequential(index + 1);
2851
- });
2852
- }
2853
- else {
2854
- tried[index] = '[function fallback]';
2855
- try {
2856
- url();
2857
- }
2858
- catch (_) {
2859
- return openURLSequential(index + 1);
2860
- }
2861
- resolve(by);
2862
- }
2863
- }
2864
- return openURLSequential();
2865
- });
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;
2866
2925
  },
2867
2926
  telephone: function (options) {
2868
2927
  if (options === void 0) { options = {}; }
@@ -2912,7 +2971,7 @@
2912
2971
  map: function (options) {
2913
2972
  if (options === void 0) { options = {}; }
2914
2973
  var params = [];
2915
- var urls = [];
2974
+ var candidates = [];
2916
2975
  var url = '';
2917
2976
  switch (PlatformKit.os.name) {
2918
2977
  case 'android':
@@ -2930,7 +2989,7 @@
2930
2989
  params.push('z=' + options.zoom);
2931
2990
  if (params.length > 0)
2932
2991
  url = url + '?' + joining(params, undefined, '&');
2933
- urls.push(url);
2992
+ candidates.push(['scheme', url]);
2934
2993
  break;
2935
2994
  case 'ios':
2936
2995
  case 'macos':
@@ -2950,7 +3009,7 @@
2950
3009
  }
2951
3010
  if (typeof options.zoom !== 'undefined')
2952
3011
  params.push('z=' + options.zoom);
2953
- urls.push('maps://?' + joining(params, undefined, '&'));
3012
+ candidates.push(['scheme', 'maps://?' + joining(params, undefined, '&')]);
2954
3013
  break;
2955
3014
  case 'windows':
2956
3015
  if (typeof options.directions !== 'undefined') {
@@ -2966,10 +3025,10 @@
2966
3025
  }
2967
3026
  if (typeof options.zoom !== 'undefined')
2968
3027
  params.push('lvl=' + options.zoom);
2969
- urls.push('bingmaps:?' + joining(params, undefined, '&'));
3028
+ candidates.push(['scheme', 'bingmaps:?' + joining(params, undefined, '&')]);
2970
3029
  }
2971
3030
  if (typeof options.fallback !== 'undefined') {
2972
- urls.push(stripURL(options.fallback));
3031
+ candidates.push(['fallback', stripURL(options.fallback)]);
2973
3032
  }
2974
3033
  else {
2975
3034
  var params_1 = ['api=1'];
@@ -2977,7 +3036,7 @@
2977
3036
  params_1.push('destination=' + encodeMapValue(options.directions.destination));
2978
3037
  if (typeof options.directions.origin !== 'undefined')
2979
3038
  params_1.push('origin=' + encodeMapValue(options.directions.origin));
2980
- urls.push('https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&'));
3039
+ candidates.push(['fallback', 'https://www.google.com/maps/dir/?' + joining(params_1, undefined, '&')]);
2981
3040
  }
2982
3041
  else {
2983
3042
  if (typeof options.coordinate !== 'undefined')
@@ -2986,34 +3045,10 @@
2986
3045
  params_1.push('query=' + escapeURIComponentString(options.query));
2987
3046
  if (typeof options.zoom !== 'undefined')
2988
3047
  params_1.push('zoom=' + options.zoom);
2989
- urls.push('https://www.google.com/maps/search/?' + joining(params_1, undefined, '&'));
3048
+ candidates.push(['fallback', 'https://www.google.com/maps/search/?' + joining(params_1, undefined, '&')]);
2990
3049
  }
2991
3050
  }
2992
- return new Promise(function (resolve, reject) {
2993
- var tried = [];
2994
- function openURLSequential(index) {
2995
- if (index === void 0) { index = 0; }
2996
- if (index >= urls.length)
2997
- return reject(new Error('Failed to open a map using all available URLs.\n\nAttempted URLs:\n' + joining(tried, undefined, '\n↓\n')));
2998
- var url = urls[index];
2999
- if (typeof url === 'string') {
3000
- tried[index] = url;
3001
- return openURL(index, url, getDefaultTimeout())
3002
- .then(function () {
3003
- resolve();
3004
- })
3005
- .catch(function () {
3006
- openURLSequential(index + 1);
3007
- });
3008
- }
3009
- else {
3010
- tried[index] = '[function fallback]';
3011
- url();
3012
- resolve();
3013
- }
3014
- }
3015
- return openURLSequential();
3016
- });
3051
+ return runCandidates(candidates, getDefaultTimeout(), options.onAttempt, 'Failed to open a map.');
3017
3052
  },
3018
3053
  filepicker: function (options) {
3019
3054
  if (options === void 0) { options = {}; }