web-launch-kit 0.0.7 → 0.0.9

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version$3 = "0.0.7";
5
+ var version$3 = "0.0.9";
6
6
  var packageJSON$3 = {
7
7
  version: version$3};
8
8
 
@@ -1284,7 +1284,7 @@ function createHiddenElement(tagName, focusable) {
1284
1284
  return element;
1285
1285
  }
1286
1286
 
1287
- var version = "0.0.5";
1287
+ var version = "0.0.6";
1288
1288
  var packageJSON = {
1289
1289
  version: version};
1290
1290
 
@@ -1413,6 +1413,27 @@ function expandTag(tag) {
1413
1413
  chain.push(segments.slice(0, i).join('-'));
1414
1414
  return freeze(chain);
1415
1415
  }
1416
+ function maximizeTag(tag) {
1417
+ var parsed = parseTag(tag);
1418
+ if (parsed === null)
1419
+ return null;
1420
+ if (parsed.script !== null && parsed.region !== null)
1421
+ return parsed;
1422
+ var IntlLocale = getIntlLocaleConstructor();
1423
+ if (typeof IntlLocale === 'undefined')
1424
+ return parsed;
1425
+ try {
1426
+ var intlLocale = new IntlLocale(parsed.baseName);
1427
+ if (typeof intlLocale.maximize === 'function') {
1428
+ var reparsed = parseTag(intlLocale.maximize().toString());
1429
+ if (reparsed !== null)
1430
+ return reparsed;
1431
+ }
1432
+ }
1433
+ catch (_) {
1434
+ }
1435
+ return parsed;
1436
+ }
1416
1437
  function toLookupKey(tag) {
1417
1438
  var parsed = parseTag(tag);
1418
1439
  return (parsed === null ? tag : parsed.baseName).toLowerCase();
@@ -1455,6 +1476,11 @@ function resolveDirection(primary) {
1455
1476
  catch (_) {
1456
1477
  }
1457
1478
  }
1479
+ if (primary.script === null) {
1480
+ var maximized = maximizeTag(primary.baseName);
1481
+ if (maximized !== null && maximized.script !== null)
1482
+ return contains(RTL_SCRIPTS, maximized.script);
1483
+ }
1458
1484
  return isRTL(primary);
1459
1485
  }
1460
1486
  var subtags = null;
@@ -1554,6 +1580,9 @@ var LocaleKit = {
1554
1580
  expand: function (tag) {
1555
1581
  return expandTag(tag);
1556
1582
  },
1583
+ maximize: function (tag) {
1584
+ return maximizeTag(tag);
1585
+ },
1557
1586
  lookup: function (supported, fallback) {
1558
1587
  return lookupTag(supported, languages, typeof fallback === 'undefined' ? null : fallback);
1559
1588
  },
@@ -1566,6 +1595,7 @@ var CACHE_PREFIX = 'web-launch-kit:';
1566
1595
  var TRACK_ID = 'track-id';
1567
1596
  var PRODUCT_ID = 'product-id';
1568
1597
  var TRACK_ID_CACHE_TTL = 1000 * 60 * 60;
1598
+ var ALPHA2_REGION_PATTERN$1 = /^[A-Z]{2}$/;
1569
1599
  function toCacheKey(mode, query) {
1570
1600
  return CACHE_PREFIX + mode + ':' + query;
1571
1601
  }
@@ -1698,27 +1728,34 @@ function requestGet(url, async) {
1698
1728
  }
1699
1729
  }
1700
1730
  }
1701
- function resolveGetProductIdURL(packageFamilyName) {
1702
- var locales = LocaleKit.languages;
1703
- var locale = 'en-US';
1704
- var country = 'US';
1705
- for (var i = 0; i < locales.length; i++) {
1706
- var candidate = locales[i];
1707
- if (candidate.indexOf('-') === -1)
1708
- continue;
1709
- var subtags = candidate.split('-');
1710
- for (var j = 1; j < subtags.length; j++) {
1711
- var subtag = subtags[j];
1712
- if (/^[A-Za-z]{2}$/.test(subtag) || /^\d{3}$/.test(subtag)) {
1713
- locale = candidate;
1714
- country = subtag;
1715
- break;
1716
- }
1717
- }
1718
- if (locale === candidate)
1719
- break;
1720
- }
1721
- return 'https://displaycatalog.md.mp.microsoft.com/v7.0/products/lookup?value=' + encodeURIComponent(packageFamilyName) + '&market=' + encodeURIComponent(country) + '&languages=' + encodeURIComponent(locale) + '&alternateId=PackageFamilyName';
1731
+ function resolveMarket(language, country) {
1732
+ var locale = language;
1733
+ var market;
1734
+ if (typeof country !== 'undefined' && ALPHA2_REGION_PATTERN$1.test(country.toUpperCase()))
1735
+ market = country.toUpperCase();
1736
+ if (typeof market === 'undefined') {
1737
+ var source = typeof locale !== 'undefined'
1738
+ ? locale
1739
+ : (LocaleKit.language === null ? undefined : LocaleKit.language);
1740
+ if (typeof source !== 'undefined') {
1741
+ var maximized = LocaleKit.maximize(source);
1742
+ if (maximized !== null && maximized.region !== null && ALPHA2_REGION_PATTERN$1.test(maximized.region))
1743
+ market = maximized.region;
1744
+ }
1745
+ }
1746
+ if (typeof locale === 'undefined' && LocaleKit.language !== null)
1747
+ locale = LocaleKit.language;
1748
+ if (typeof locale === 'undefined')
1749
+ locale = 'en-US';
1750
+ if (typeof market === 'undefined')
1751
+ market = 'US';
1752
+ return [locale, market];
1753
+ }
1754
+ function resolveGetProductIdURL(packageFamilyName, language, country) {
1755
+ var resolved = resolveMarket(language, country);
1756
+ var locale = resolved[0];
1757
+ var market = resolved[1];
1758
+ return 'https://displaycatalog.md.mp.microsoft.com/v7.0/products/lookup?value=' + encodeURIComponent(packageFamilyName) + '&market=' + encodeURIComponent(market) + '&languages=' + encodeURIComponent(locale) + '&alternateId=PackageFamilyName';
1722
1759
  }
1723
1760
  function resolveGetTrackIdURL(bundleId) {
1724
1761
  return 'https://itunes.apple.com/lookup?bundleId=' + encodeURIComponent(bundleId);
@@ -1746,12 +1783,12 @@ function parseGetTrackIdResponse(response) {
1746
1783
  return undefined;
1747
1784
  return '' + result.trackId;
1748
1785
  }
1749
- function getProductId(packageFamilyName) {
1786
+ function getProductId(packageFamilyName, language, country) {
1750
1787
  var cache = idCache.get(PRODUCT_ID, packageFamilyName);
1751
1788
  if (typeof cache !== 'undefined')
1752
1789
  return cache;
1753
1790
  try {
1754
- var productId = parseGetProductIdResponse(requestGet(resolveGetProductIdURL(packageFamilyName)));
1791
+ var productId = parseGetProductIdResponse(requestGet(resolveGetProductIdURL(packageFamilyName, language, country)));
1755
1792
  if (typeof productId === 'undefined')
1756
1793
  return undefined;
1757
1794
  idCache.set(PRODUCT_ID, packageFamilyName, productId);
@@ -1776,12 +1813,12 @@ function getTrackId(bundleId) {
1776
1813
  return undefined;
1777
1814
  }
1778
1815
  }
1779
- function getProductIdAsync(packageFamilyName) {
1816
+ function getProductIdAsync(packageFamilyName, language, country) {
1780
1817
  var cache = idCache.get(PRODUCT_ID, packageFamilyName);
1781
1818
  if (typeof cache !== 'undefined')
1782
1819
  return Promise.resolve(cache);
1783
1820
  try {
1784
- return requestGet(resolveGetProductIdURL(packageFamilyName), true)
1821
+ return requestGet(resolveGetProductIdURL(packageFamilyName, language, country), true)
1785
1822
  .then(parseGetProductIdResponse)
1786
1823
  .then(function (productId) {
1787
1824
  if (typeof productId === 'undefined')
@@ -1896,6 +1933,7 @@ var MACOS_DEFAULT_TIMEOUT = 750;
1896
1933
  var DEFAULT_TIMEOUT = 750;
1897
1934
  var GLOBAL = getGlobal$1();
1898
1935
  var NAVIGATOR = GLOBAL.navigator;
1936
+ var ALPHA2_REGION_PATTERN = /^[A-Z]{2}$/;
1899
1937
  var CLEANUP_INPUT_ELEMENT = null;
1900
1938
  var DEBUG = false;
1901
1939
  var APP_IN_FLIGHT = null;
@@ -2345,6 +2383,8 @@ function resolveOptions(option) {
2345
2383
  var allowScheme;
2346
2384
  var assumeAllowedInApp;
2347
2385
  var timeout;
2386
+ var language;
2387
+ var country;
2348
2388
  var intent;
2349
2389
  var packageName;
2350
2390
  var allowIntent = true;
@@ -2367,6 +2407,8 @@ function resolveOptions(option) {
2367
2407
  allowWebStore = option.android.allowWebStore;
2368
2408
  allowScheme = canOpenScheme(assumeAllowedInApp);
2369
2409
  timeout = option.android.timeout;
2410
+ language = option.android.language;
2411
+ country = option.android.country;
2370
2412
  if (typeof intent !== 'undefined' && (typeof scheme === 'undefined' || typeof packageName === 'undefined' || typeof fallback === 'undefined')) {
2371
2413
  var parsed = parseIntentURL(intent);
2372
2414
  if (typeof parsed.scheme !== 'undefined' && typeof scheme === 'undefined')
@@ -2390,7 +2432,7 @@ function resolveOptions(option) {
2390
2432
  if (allowAppStore && allowScheme)
2391
2433
  resolved.push(['store', createAppStoreURL(packageName, os)]);
2392
2434
  if (allowWebStore)
2393
- resolved.push(['store', createWebStoreURL(packageName, os)]);
2435
+ resolved.push(['store', createWebStoreURL(packageName, os, language, country)]);
2394
2436
  }
2395
2437
  return [resolved, timeout];
2396
2438
  case 'ios':
@@ -2406,6 +2448,8 @@ function resolveOptions(option) {
2406
2448
  allowWebStore = option.ios.allowWebStore;
2407
2449
  allowScheme = canOpenScheme(assumeAllowedInApp);
2408
2450
  timeout = option.ios.timeout;
2451
+ language = option.ios.language;
2452
+ country = option.ios.country;
2409
2453
  if (typeof bundleId !== 'undefined' && typeof trackId === 'undefined')
2410
2454
  trackId = getTrackId(bundleId);
2411
2455
  if (typeof timeout === 'undefined')
@@ -2420,7 +2464,7 @@ function resolveOptions(option) {
2420
2464
  if (allowAppStore && allowScheme)
2421
2465
  resolved.push(['store', createAppStoreURL(trackId, os)]);
2422
2466
  if (allowWebStore)
2423
- resolved.push(['store', createWebStoreURL(trackId, os)]);
2467
+ resolved.push(['store', createWebStoreURL(trackId, os, language, country)]);
2424
2468
  }
2425
2469
  return [resolved, timeout];
2426
2470
  case 'windows':
@@ -2433,8 +2477,10 @@ function resolveOptions(option) {
2433
2477
  allowAppStore = option.windows.allowAppStore;
2434
2478
  allowWebStore = option.windows.allowWebStore;
2435
2479
  timeout = option.windows.timeout;
2480
+ language = option.windows.language;
2481
+ country = option.windows.country;
2436
2482
  if (typeof packageFamilyName !== 'undefined' && typeof productId === 'undefined')
2437
- productId = getProductId(packageFamilyName);
2483
+ productId = getProductId(packageFamilyName, language, country);
2438
2484
  if (typeof timeout === 'undefined')
2439
2485
  timeout = WINDOWS_DEFAULT_TIMEOUT;
2440
2486
  if (typeof scheme !== 'undefined')
@@ -2445,7 +2491,7 @@ function resolveOptions(option) {
2445
2491
  if (allowAppStore)
2446
2492
  resolved.push(['store', createAppStoreURL(productId, os)]);
2447
2493
  if (allowWebStore)
2448
- resolved.push(['store', createWebStoreURL(productId, os)]);
2494
+ resolved.push(['store', createWebStoreURL(productId, os, language, country)]);
2449
2495
  }
2450
2496
  return [resolved, timeout];
2451
2497
  case 'macos':
@@ -2458,6 +2504,8 @@ function resolveOptions(option) {
2458
2504
  allowAppStore = option.macos.allowAppStore;
2459
2505
  allowWebStore = option.macos.allowWebStore;
2460
2506
  timeout = option.macos.timeout;
2507
+ language = option.macos.language;
2508
+ country = option.macos.country;
2461
2509
  if (typeof bundleId !== 'undefined' && typeof trackId === 'undefined')
2462
2510
  trackId = getTrackId(bundleId);
2463
2511
  if (typeof timeout === 'undefined')
@@ -2470,7 +2518,7 @@ function resolveOptions(option) {
2470
2518
  if (allowAppStore)
2471
2519
  resolved.push(['store', createAppStoreURL(trackId, os)]);
2472
2520
  if (allowWebStore)
2473
- resolved.push(['store', createWebStoreURL(trackId, os)]);
2521
+ resolved.push(['store', createWebStoreURL(trackId, os, language, country)]);
2474
2522
  }
2475
2523
  return [resolved, timeout];
2476
2524
  }
@@ -2526,6 +2574,34 @@ function isFullyBlockedInAppBrowser() {
2526
2574
  function isPartnerAppOnly() {
2527
2575
  return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
2528
2576
  }
2577
+ function canOpenXSafari() {
2578
+ if (PlatformKit.os.name !== 'ios')
2579
+ return false;
2580
+ var version = PlatformKit.os.version;
2581
+ if (PlatformKit.compareVersion(version, '15.0') < 0)
2582
+ return false;
2583
+ if (PlatformKit.compareVersion(version, '16.0') >= 0 && PlatformKit.compareVersion(version, '17.0') < 0)
2584
+ return false;
2585
+ var inAppBrowser = PlatformKit.inAppBrowser;
2586
+ if (inAppBrowser === 'facebook' || inAppBrowser === 'instagram')
2587
+ return false;
2588
+ return canOpenScheme();
2589
+ }
2590
+ function isInWebview() {
2591
+ return PlatformKit.inAppBrowser !== null || PlatformKit.webview;
2592
+ }
2593
+ function canEscapeWebview() {
2594
+ if (!isInWebview())
2595
+ return false;
2596
+ var inAppBrowser = PlatformKit.inAppBrowser;
2597
+ if (inAppBrowser === 'kakaotalk' || inAppBrowser === 'line')
2598
+ return true;
2599
+ if (PlatformKit.os.name === 'android')
2600
+ return canOpenIntent();
2601
+ if (PlatformKit.os.name === 'ios')
2602
+ return canOpenXSafari();
2603
+ return false;
2604
+ }
2529
2605
  function canOpenWindowsSetting(version) {
2530
2606
  if (version.length === 0)
2531
2607
  return false;
@@ -2609,19 +2685,87 @@ function createAppStoreURL(id, os) {
2609
2685
  return os;
2610
2686
  }
2611
2687
  }
2612
- function createWebStoreURL(id, os) {
2688
+ function createWebStoreURL(id, os, language, country) {
2689
+ var resolved = resolveCountry(language, country);
2690
+ var countryPath = typeof resolved !== 'undefined' ? resolved.toLowerCase() + '/' : '';
2691
+ var url;
2613
2692
  switch (os) {
2614
2693
  case 'android':
2615
- return 'https://play.google.com/store/apps/details?id=' + id;
2694
+ url = 'https://play.google.com/store/apps/details?id=' + id;
2695
+ if (typeof language !== 'undefined')
2696
+ url = appendURLParameter(url, 'hl=' + escapeURIComponentString(language));
2697
+ if (typeof resolved !== 'undefined')
2698
+ url = appendURLParameter(url, 'gl=' + resolved);
2699
+ break;
2616
2700
  case 'ios':
2617
- return 'https://itunes.apple.com/app/id' + id + '?mt=8';
2701
+ url = 'https://itunes.apple.com/' + countryPath + 'app/id' + id + '?mt=8';
2702
+ if (typeof language !== 'undefined')
2703
+ url = appendURLParameter(url, 'l=' + escapeURIComponentString(language));
2704
+ break;
2618
2705
  case 'windows':
2619
- return 'https://apps.microsoft.com/detail/' + id;
2706
+ url = 'https://apps.microsoft.com/detail/' + id;
2707
+ if (typeof language !== 'undefined')
2708
+ url = appendURLParameter(url, 'hl=' + escapeURIComponentString(language));
2709
+ if (typeof resolved !== 'undefined')
2710
+ url = appendURLParameter(url, 'gl=' + resolved);
2711
+ break;
2620
2712
  case 'macos':
2621
- return 'https://apps.apple.com/app/id' + id + '?mt=12';
2713
+ url = 'https://apps.apple.com/' + countryPath + 'app/id' + id + '?mt=12';
2714
+ if (typeof language !== 'undefined')
2715
+ url = appendURLParameter(url, 'l=' + escapeURIComponentString(language));
2716
+ break;
2622
2717
  default:
2623
2718
  return os;
2624
2719
  }
2720
+ return url;
2721
+ }
2722
+ function extractRegion(tag) {
2723
+ var parts = tag.replace(/_/g, '-').split('-');
2724
+ for (var i = 1; i < parts.length; i++) {
2725
+ if (/^[A-Za-z]{2}$/.test(parts[i]))
2726
+ return parts[i].toUpperCase();
2727
+ }
2728
+ return undefined;
2729
+ }
2730
+ function resolveCountry(language, country) {
2731
+ if (typeof country !== 'undefined' && ALPHA2_REGION_PATTERN.test(country.toUpperCase()))
2732
+ return country.toUpperCase();
2733
+ if (typeof language === 'undefined')
2734
+ return undefined;
2735
+ var region = extractRegion(language);
2736
+ if (typeof region !== 'undefined')
2737
+ return region;
2738
+ if (typeof Intl !== 'undefined' && typeof Intl.Locale === 'function') {
2739
+ try {
2740
+ var locale = new Intl.Locale(language);
2741
+ if (typeof locale.maximize === 'function') {
2742
+ var maximized = locale.maximize();
2743
+ if (typeof maximized !== 'undefined' && maximized !== null && typeof maximized.region === 'string' && ALPHA2_REGION_PATTERN.test(maximized.region.toUpperCase()))
2744
+ return maximized.region.toUpperCase();
2745
+ }
2746
+ }
2747
+ catch (_) {
2748
+ }
2749
+ }
2750
+ return undefined;
2751
+ }
2752
+ function appendURLParameter(url, parameter) {
2753
+ var index = url.indexOf('#');
2754
+ var base = index === -1 ? url : url.substring(0, index);
2755
+ var hash = index === -1 ? '' : url.substring(index);
2756
+ return base + (base.indexOf('?') === -1 ? '?' : '&') + parameter + hash;
2757
+ }
2758
+ function createEscapeWebviewURL(url) {
2759
+ var inAppBrowser = PlatformKit.inAppBrowser;
2760
+ if (inAppBrowser === 'kakaotalk')
2761
+ return 'kakaotalk://web/openExternal?url=' + escapeURIComponentString(url);
2762
+ if (inAppBrowser === 'line')
2763
+ return appendURLParameter(url, 'openExternalBrowser=1');
2764
+ if (PlatformKit.os.name === 'android' && canOpenIntent())
2765
+ return createIntentURL(url, 'com.android.chrome', url);
2766
+ if (PlatformKit.os.name === 'ios' && canOpenXSafari())
2767
+ return 'x-safari-' + url;
2768
+ return undefined;
2625
2769
  }
2626
2770
  function escapeURIComponentString(value) {
2627
2771
  return encodeURIComponent(value)
@@ -2896,6 +3040,9 @@ var LaunchKit = {
2896
3040
  get canOpenSetting() {
2897
3041
  return canOpenSetting();
2898
3042
  },
3043
+ get canEscapeWebview() {
3044
+ return canEscapeWebview();
3045
+ },
2899
3046
  getTrackId: getTrackIdAsync,
2900
3047
  getProductId: getProductIdAsync,
2901
3048
  },
@@ -3163,6 +3310,18 @@ var LaunchKit = {
3163
3310
  return openURLSequential();
3164
3311
  });
3165
3312
  },
3313
+ escapeWebview: function (options) {
3314
+ if (options === void 0) { options = {}; }
3315
+ if (!isInWebview())
3316
+ 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 + '")'));
3317
+ var url = typeof options.url !== 'undefined' ? stripURL(options.url) : getTopmostWindow().location.href;
3318
+ if (!isWebURL(url))
3319
+ return Promise.reject(new Error('Cannot escape the webview: only http(s) URLs can be reopened in an external browser. (url: "' + url + '")'));
3320
+ var escape = createEscapeWebviewURL(url);
3321
+ if (typeof escape === 'undefined')
3322
+ return Promise.reject(new Error('Failed to escape the webview: no escape route is available in the current environment. (userAgent: "' + PlatformKit.userAgent + '")'));
3323
+ return openURL(0, escape, getDefaultTimeout(), isWebURL(escape));
3324
+ },
3166
3325
  };
3167
3326
 
3168
3327
  exports.default = LaunchKit;