web-launch-kit 0.0.6 → 0.0.8

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.6";
7
+ var version$3 = "0.0.8";
8
8
  var packageJSON$3 = {
9
9
  version: version$3};
10
10
 
@@ -2349,6 +2349,7 @@
2349
2349
  var timeout;
2350
2350
  var intent;
2351
2351
  var packageName;
2352
+ var allowIntent = true;
2352
2353
  var bundleId;
2353
2354
  var trackId;
2354
2355
  var universal;
@@ -2358,6 +2359,7 @@
2358
2359
  case 'android':
2359
2360
  if (typeof option.android === 'undefined')
2360
2361
  return [[], 0];
2362
+ allowIntent = option.android.allowIntent !== false;
2361
2363
  intent = stripURL(option.android.intent);
2362
2364
  scheme = stripURL(option.android.scheme);
2363
2365
  fallback = stripURL(option.android.fallback);
@@ -2376,11 +2378,11 @@
2376
2378
  if (typeof parsed.fallback !== 'undefined' && typeof fallback === 'undefined')
2377
2379
  fallback = parsed.fallback;
2378
2380
  }
2379
- if (typeof scheme !== 'undefined' && typeof intent === 'undefined')
2381
+ if (allowIntent && typeof scheme !== 'undefined' && typeof intent === 'undefined')
2380
2382
  intent = createIntentURL(scheme, packageName, fallback);
2381
2383
  if (typeof timeout === 'undefined')
2382
2384
  timeout = ANDROID_DEFAULT_TIMEOUT;
2383
- if (typeof intent !== 'undefined' && canOpenIntent())
2385
+ if (allowIntent && typeof intent !== 'undefined' && canOpenIntent())
2384
2386
  resolved.push(['intent', intent]);
2385
2387
  if (typeof scheme !== 'undefined' && allowScheme)
2386
2388
  resolved.push(['scheme', scheme]);
@@ -2526,6 +2528,34 @@
2526
2528
  function isPartnerAppOnly() {
2527
2529
  return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
2528
2530
  }
2531
+ function canOpenXSafari() {
2532
+ if (PlatformKit.os.name !== 'ios')
2533
+ return false;
2534
+ var version = PlatformKit.os.version;
2535
+ if (PlatformKit.compareVersion(version, '15.0') < 0)
2536
+ return false;
2537
+ if (PlatformKit.compareVersion(version, '16.0') >= 0 && PlatformKit.compareVersion(version, '17.0') < 0)
2538
+ return false;
2539
+ var inAppBrowser = PlatformKit.inAppBrowser;
2540
+ if (inAppBrowser === 'facebook' || inAppBrowser === 'instagram')
2541
+ return false;
2542
+ return canOpenScheme();
2543
+ }
2544
+ function isInWebview() {
2545
+ return PlatformKit.inAppBrowser !== null || PlatformKit.webview;
2546
+ }
2547
+ function canEscapeWebview() {
2548
+ if (!isInWebview())
2549
+ return false;
2550
+ var inAppBrowser = PlatformKit.inAppBrowser;
2551
+ if (inAppBrowser === 'kakaotalk' || inAppBrowser === 'line')
2552
+ return true;
2553
+ if (PlatformKit.os.name === 'android')
2554
+ return canOpenIntent();
2555
+ if (PlatformKit.os.name === 'ios')
2556
+ return canOpenXSafari();
2557
+ return false;
2558
+ }
2529
2559
  function canOpenWindowsSetting(version) {
2530
2560
  if (version.length === 0)
2531
2561
  return false;
@@ -2623,6 +2653,24 @@
2623
2653
  return os;
2624
2654
  }
2625
2655
  }
2656
+ function appendURLParameter(url, parameter) {
2657
+ var index = url.indexOf('#');
2658
+ var base = index === -1 ? url : url.substring(0, index);
2659
+ var hash = index === -1 ? '' : url.substring(index);
2660
+ return base + (base.indexOf('?') === -1 ? '?' : '&') + parameter + hash;
2661
+ }
2662
+ function createEscapeWebviewURL(url) {
2663
+ var inAppBrowser = PlatformKit.inAppBrowser;
2664
+ if (inAppBrowser === 'kakaotalk')
2665
+ return 'kakaotalk://web/openExternal?url=' + escapeURIComponentString(url);
2666
+ if (inAppBrowser === 'line')
2667
+ return appendURLParameter(url, 'openExternalBrowser=1');
2668
+ if (PlatformKit.os.name === 'android' && canOpenIntent())
2669
+ return createIntentURL(url, 'com.android.chrome', url);
2670
+ if (PlatformKit.os.name === 'ios' && canOpenXSafari())
2671
+ return 'x-safari-' + url;
2672
+ return undefined;
2673
+ }
2626
2674
  function escapeURIComponentString(value) {
2627
2675
  return encodeURIComponent(value)
2628
2676
  .replace(/[!'()*]/g, function (char) {
@@ -2896,6 +2944,9 @@
2896
2944
  get canOpenSetting() {
2897
2945
  return canOpenSetting();
2898
2946
  },
2947
+ get canEscapeWebview() {
2948
+ return canEscapeWebview();
2949
+ },
2899
2950
  getTrackId: getTrackIdAsync,
2900
2951
  getProductId: getProductIdAsync,
2901
2952
  },
@@ -3163,6 +3214,18 @@
3163
3214
  return openURLSequential();
3164
3215
  });
3165
3216
  },
3217
+ escapeWebview: function (options) {
3218
+ if (options === void 0) { options = {}; }
3219
+ if (!isInWebview())
3220
+ return Promise.reject(new Error('Escaping the webview is not needed: the current environment is not an in-app browser or webview. (userAgent: "' + PlatformKit.userAgent + '")'));
3221
+ var url = typeof options.url !== 'undefined' ? stripURL(options.url) : getTopmostWindow().location.href;
3222
+ if (!isWebURL(url))
3223
+ return Promise.reject(new Error('Cannot escape the webview: only http(s) URLs can be reopened in an external browser. (url: "' + url + '")'));
3224
+ var escape = createEscapeWebviewURL(url);
3225
+ if (typeof escape === 'undefined')
3226
+ return Promise.reject(new Error('Failed to escape the webview: no escape route is available in the current environment. (userAgent: "' + PlatformKit.userAgent + '")'));
3227
+ return openURL(0, escape, getDefaultTimeout(), isWebURL(escape));
3228
+ },
3166
3229
  };
3167
3230
 
3168
3231
  exports.default = LaunchKit;