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.
@@ -1,4 +1,4 @@
1
- var version$3 = "0.0.7";
1
+ var version$3 = "0.0.8";
2
2
  var packageJSON$3 = {
3
3
  version: version$3};
4
4
 
@@ -2522,6 +2522,34 @@ function isFullyBlockedInAppBrowser() {
2522
2522
  function isPartnerAppOnly() {
2523
2523
  return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
2524
2524
  }
2525
+ function canOpenXSafari() {
2526
+ if (PlatformKit.os.name !== 'ios')
2527
+ return false;
2528
+ var version = PlatformKit.os.version;
2529
+ if (PlatformKit.compareVersion(version, '15.0') < 0)
2530
+ return false;
2531
+ if (PlatformKit.compareVersion(version, '16.0') >= 0 && PlatformKit.compareVersion(version, '17.0') < 0)
2532
+ return false;
2533
+ var inAppBrowser = PlatformKit.inAppBrowser;
2534
+ if (inAppBrowser === 'facebook' || inAppBrowser === 'instagram')
2535
+ return false;
2536
+ return canOpenScheme();
2537
+ }
2538
+ function isInWebview() {
2539
+ return PlatformKit.inAppBrowser !== null || PlatformKit.webview;
2540
+ }
2541
+ function canEscapeWebview() {
2542
+ if (!isInWebview())
2543
+ return false;
2544
+ var inAppBrowser = PlatformKit.inAppBrowser;
2545
+ if (inAppBrowser === 'kakaotalk' || inAppBrowser === 'line')
2546
+ return true;
2547
+ if (PlatformKit.os.name === 'android')
2548
+ return canOpenIntent();
2549
+ if (PlatformKit.os.name === 'ios')
2550
+ return canOpenXSafari();
2551
+ return false;
2552
+ }
2525
2553
  function canOpenWindowsSetting(version) {
2526
2554
  if (version.length === 0)
2527
2555
  return false;
@@ -2619,6 +2647,24 @@ function createWebStoreURL(id, os) {
2619
2647
  return os;
2620
2648
  }
2621
2649
  }
2650
+ function appendURLParameter(url, parameter) {
2651
+ var index = url.indexOf('#');
2652
+ var base = index === -1 ? url : url.substring(0, index);
2653
+ var hash = index === -1 ? '' : url.substring(index);
2654
+ return base + (base.indexOf('?') === -1 ? '?' : '&') + parameter + hash;
2655
+ }
2656
+ function createEscapeWebviewURL(url) {
2657
+ var inAppBrowser = PlatformKit.inAppBrowser;
2658
+ if (inAppBrowser === 'kakaotalk')
2659
+ return 'kakaotalk://web/openExternal?url=' + escapeURIComponentString(url);
2660
+ if (inAppBrowser === 'line')
2661
+ return appendURLParameter(url, 'openExternalBrowser=1');
2662
+ if (PlatformKit.os.name === 'android' && canOpenIntent())
2663
+ return createIntentURL(url, 'com.android.chrome', url);
2664
+ if (PlatformKit.os.name === 'ios' && canOpenXSafari())
2665
+ return 'x-safari-' + url;
2666
+ return undefined;
2667
+ }
2622
2668
  function escapeURIComponentString(value) {
2623
2669
  return encodeURIComponent(value)
2624
2670
  .replace(/[!'()*]/g, function (char) {
@@ -2892,6 +2938,9 @@ var LaunchKit = {
2892
2938
  get canOpenSetting() {
2893
2939
  return canOpenSetting();
2894
2940
  },
2941
+ get canEscapeWebview() {
2942
+ return canEscapeWebview();
2943
+ },
2895
2944
  getTrackId: getTrackIdAsync,
2896
2945
  getProductId: getProductIdAsync,
2897
2946
  },
@@ -3159,6 +3208,18 @@ var LaunchKit = {
3159
3208
  return openURLSequential();
3160
3209
  });
3161
3210
  },
3211
+ escapeWebview: function (options) {
3212
+ if (options === void 0) { options = {}; }
3213
+ if (!isInWebview())
3214
+ 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 + '")'));
3215
+ var url = typeof options.url !== 'undefined' ? stripURL(options.url) : getTopmostWindow().location.href;
3216
+ if (!isWebURL(url))
3217
+ return Promise.reject(new Error('Cannot escape the webview: only http(s) URLs can be reopened in an external browser. (url: "' + url + '")'));
3218
+ var escape = createEscapeWebviewURL(url);
3219
+ if (typeof escape === 'undefined')
3220
+ return Promise.reject(new Error('Failed to escape the webview: no escape route is available in the current environment. (userAgent: "' + PlatformKit.userAgent + '")'));
3221
+ return openURL(0, escape, getDefaultTimeout(), isWebURL(escape));
3222
+ },
3162
3223
  };
3163
3224
 
3164
3225
  export { SettingType, LaunchKit as default };