web-launch-kit 0.0.7 → 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.7";
7
+ var version$3 = "0.0.8";
8
8
  var packageJSON$3 = {
9
9
  version: version$3};
10
10
 
@@ -2528,6 +2528,34 @@
2528
2528
  function isPartnerAppOnly() {
2529
2529
  return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
2530
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
+ }
2531
2559
  function canOpenWindowsSetting(version) {
2532
2560
  if (version.length === 0)
2533
2561
  return false;
@@ -2625,6 +2653,24 @@
2625
2653
  return os;
2626
2654
  }
2627
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
+ }
2628
2674
  function escapeURIComponentString(value) {
2629
2675
  return encodeURIComponent(value)
2630
2676
  .replace(/[!'()*]/g, function (char) {
@@ -2898,6 +2944,9 @@
2898
2944
  get canOpenSetting() {
2899
2945
  return canOpenSetting();
2900
2946
  },
2947
+ get canEscapeWebview() {
2948
+ return canEscapeWebview();
2949
+ },
2901
2950
  getTrackId: getTrackIdAsync,
2902
2951
  getProductId: getProductIdAsync,
2903
2952
  },
@@ -3165,6 +3214,18 @@
3165
3214
  return openURLSequential();
3166
3215
  });
3167
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
+ },
3168
3229
  };
3169
3230
 
3170
3231
  exports.default = LaunchKit;