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.
@@ -1,4 +1,4 @@
1
- var version$3 = "0.0.7";
1
+ var version$3 = "0.0.9";
2
2
  var packageJSON$3 = {
3
3
  version: version$3};
4
4
 
@@ -1280,7 +1280,7 @@ function createHiddenElement(tagName, focusable) {
1280
1280
  return element;
1281
1281
  }
1282
1282
 
1283
- var version = "0.0.5";
1283
+ var version = "0.0.6";
1284
1284
  var packageJSON = {
1285
1285
  version: version};
1286
1286
 
@@ -1409,6 +1409,27 @@ function expandTag(tag) {
1409
1409
  chain.push(segments.slice(0, i).join('-'));
1410
1410
  return freeze(chain);
1411
1411
  }
1412
+ function maximizeTag(tag) {
1413
+ var parsed = parseTag(tag);
1414
+ if (parsed === null)
1415
+ return null;
1416
+ if (parsed.script !== null && parsed.region !== null)
1417
+ return parsed;
1418
+ var IntlLocale = getIntlLocaleConstructor();
1419
+ if (typeof IntlLocale === 'undefined')
1420
+ return parsed;
1421
+ try {
1422
+ var intlLocale = new IntlLocale(parsed.baseName);
1423
+ if (typeof intlLocale.maximize === 'function') {
1424
+ var reparsed = parseTag(intlLocale.maximize().toString());
1425
+ if (reparsed !== null)
1426
+ return reparsed;
1427
+ }
1428
+ }
1429
+ catch (_) {
1430
+ }
1431
+ return parsed;
1432
+ }
1412
1433
  function toLookupKey(tag) {
1413
1434
  var parsed = parseTag(tag);
1414
1435
  return (parsed === null ? tag : parsed.baseName).toLowerCase();
@@ -1451,6 +1472,11 @@ function resolveDirection(primary) {
1451
1472
  catch (_) {
1452
1473
  }
1453
1474
  }
1475
+ if (primary.script === null) {
1476
+ var maximized = maximizeTag(primary.baseName);
1477
+ if (maximized !== null && maximized.script !== null)
1478
+ return contains(RTL_SCRIPTS, maximized.script);
1479
+ }
1454
1480
  return isRTL(primary);
1455
1481
  }
1456
1482
  var subtags = null;
@@ -1550,6 +1576,9 @@ var LocaleKit = {
1550
1576
  expand: function (tag) {
1551
1577
  return expandTag(tag);
1552
1578
  },
1579
+ maximize: function (tag) {
1580
+ return maximizeTag(tag);
1581
+ },
1553
1582
  lookup: function (supported, fallback) {
1554
1583
  return lookupTag(supported, languages, typeof fallback === 'undefined' ? null : fallback);
1555
1584
  },
@@ -1562,6 +1591,7 @@ var CACHE_PREFIX = 'web-launch-kit:';
1562
1591
  var TRACK_ID = 'track-id';
1563
1592
  var PRODUCT_ID = 'product-id';
1564
1593
  var TRACK_ID_CACHE_TTL = 1000 * 60 * 60;
1594
+ var ALPHA2_REGION_PATTERN$1 = /^[A-Z]{2}$/;
1565
1595
  function toCacheKey(mode, query) {
1566
1596
  return CACHE_PREFIX + mode + ':' + query;
1567
1597
  }
@@ -1694,27 +1724,34 @@ function requestGet(url, async) {
1694
1724
  }
1695
1725
  }
1696
1726
  }
1697
- function resolveGetProductIdURL(packageFamilyName) {
1698
- var locales = LocaleKit.languages;
1699
- var locale = 'en-US';
1700
- var country = 'US';
1701
- for (var i = 0; i < locales.length; i++) {
1702
- var candidate = locales[i];
1703
- if (candidate.indexOf('-') === -1)
1704
- continue;
1705
- var subtags = candidate.split('-');
1706
- for (var j = 1; j < subtags.length; j++) {
1707
- var subtag = subtags[j];
1708
- if (/^[A-Za-z]{2}$/.test(subtag) || /^\d{3}$/.test(subtag)) {
1709
- locale = candidate;
1710
- country = subtag;
1711
- break;
1712
- }
1713
- }
1714
- if (locale === candidate)
1715
- break;
1716
- }
1717
- return 'https://displaycatalog.md.mp.microsoft.com/v7.0/products/lookup?value=' + encodeURIComponent(packageFamilyName) + '&market=' + encodeURIComponent(country) + '&languages=' + encodeURIComponent(locale) + '&alternateId=PackageFamilyName';
1727
+ function resolveMarket(language, country) {
1728
+ var locale = language;
1729
+ var market;
1730
+ if (typeof country !== 'undefined' && ALPHA2_REGION_PATTERN$1.test(country.toUpperCase()))
1731
+ market = country.toUpperCase();
1732
+ if (typeof market === 'undefined') {
1733
+ var source = typeof locale !== 'undefined'
1734
+ ? locale
1735
+ : (LocaleKit.language === null ? undefined : LocaleKit.language);
1736
+ if (typeof source !== 'undefined') {
1737
+ var maximized = LocaleKit.maximize(source);
1738
+ if (maximized !== null && maximized.region !== null && ALPHA2_REGION_PATTERN$1.test(maximized.region))
1739
+ market = maximized.region;
1740
+ }
1741
+ }
1742
+ if (typeof locale === 'undefined' && LocaleKit.language !== null)
1743
+ locale = LocaleKit.language;
1744
+ if (typeof locale === 'undefined')
1745
+ locale = 'en-US';
1746
+ if (typeof market === 'undefined')
1747
+ market = 'US';
1748
+ return [locale, market];
1749
+ }
1750
+ function resolveGetProductIdURL(packageFamilyName, language, country) {
1751
+ var resolved = resolveMarket(language, country);
1752
+ var locale = resolved[0];
1753
+ var market = resolved[1];
1754
+ return 'https://displaycatalog.md.mp.microsoft.com/v7.0/products/lookup?value=' + encodeURIComponent(packageFamilyName) + '&market=' + encodeURIComponent(market) + '&languages=' + encodeURIComponent(locale) + '&alternateId=PackageFamilyName';
1718
1755
  }
1719
1756
  function resolveGetTrackIdURL(bundleId) {
1720
1757
  return 'https://itunes.apple.com/lookup?bundleId=' + encodeURIComponent(bundleId);
@@ -1742,12 +1779,12 @@ function parseGetTrackIdResponse(response) {
1742
1779
  return undefined;
1743
1780
  return '' + result.trackId;
1744
1781
  }
1745
- function getProductId(packageFamilyName) {
1782
+ function getProductId(packageFamilyName, language, country) {
1746
1783
  var cache = idCache.get(PRODUCT_ID, packageFamilyName);
1747
1784
  if (typeof cache !== 'undefined')
1748
1785
  return cache;
1749
1786
  try {
1750
- var productId = parseGetProductIdResponse(requestGet(resolveGetProductIdURL(packageFamilyName)));
1787
+ var productId = parseGetProductIdResponse(requestGet(resolveGetProductIdURL(packageFamilyName, language, country)));
1751
1788
  if (typeof productId === 'undefined')
1752
1789
  return undefined;
1753
1790
  idCache.set(PRODUCT_ID, packageFamilyName, productId);
@@ -1772,12 +1809,12 @@ function getTrackId(bundleId) {
1772
1809
  return undefined;
1773
1810
  }
1774
1811
  }
1775
- function getProductIdAsync(packageFamilyName) {
1812
+ function getProductIdAsync(packageFamilyName, language, country) {
1776
1813
  var cache = idCache.get(PRODUCT_ID, packageFamilyName);
1777
1814
  if (typeof cache !== 'undefined')
1778
1815
  return Promise.resolve(cache);
1779
1816
  try {
1780
- return requestGet(resolveGetProductIdURL(packageFamilyName), true)
1817
+ return requestGet(resolveGetProductIdURL(packageFamilyName, language, country), true)
1781
1818
  .then(parseGetProductIdResponse)
1782
1819
  .then(function (productId) {
1783
1820
  if (typeof productId === 'undefined')
@@ -1892,6 +1929,7 @@ var MACOS_DEFAULT_TIMEOUT = 750;
1892
1929
  var DEFAULT_TIMEOUT = 750;
1893
1930
  var GLOBAL = getGlobal$1();
1894
1931
  var NAVIGATOR = GLOBAL.navigator;
1932
+ var ALPHA2_REGION_PATTERN = /^[A-Z]{2}$/;
1895
1933
  var CLEANUP_INPUT_ELEMENT = null;
1896
1934
  var DEBUG = false;
1897
1935
  var APP_IN_FLIGHT = null;
@@ -2341,6 +2379,8 @@ function resolveOptions(option) {
2341
2379
  var allowScheme;
2342
2380
  var assumeAllowedInApp;
2343
2381
  var timeout;
2382
+ var language;
2383
+ var country;
2344
2384
  var intent;
2345
2385
  var packageName;
2346
2386
  var allowIntent = true;
@@ -2363,6 +2403,8 @@ function resolveOptions(option) {
2363
2403
  allowWebStore = option.android.allowWebStore;
2364
2404
  allowScheme = canOpenScheme(assumeAllowedInApp);
2365
2405
  timeout = option.android.timeout;
2406
+ language = option.android.language;
2407
+ country = option.android.country;
2366
2408
  if (typeof intent !== 'undefined' && (typeof scheme === 'undefined' || typeof packageName === 'undefined' || typeof fallback === 'undefined')) {
2367
2409
  var parsed = parseIntentURL(intent);
2368
2410
  if (typeof parsed.scheme !== 'undefined' && typeof scheme === 'undefined')
@@ -2386,7 +2428,7 @@ function resolveOptions(option) {
2386
2428
  if (allowAppStore && allowScheme)
2387
2429
  resolved.push(['store', createAppStoreURL(packageName, os)]);
2388
2430
  if (allowWebStore)
2389
- resolved.push(['store', createWebStoreURL(packageName, os)]);
2431
+ resolved.push(['store', createWebStoreURL(packageName, os, language, country)]);
2390
2432
  }
2391
2433
  return [resolved, timeout];
2392
2434
  case 'ios':
@@ -2402,6 +2444,8 @@ function resolveOptions(option) {
2402
2444
  allowWebStore = option.ios.allowWebStore;
2403
2445
  allowScheme = canOpenScheme(assumeAllowedInApp);
2404
2446
  timeout = option.ios.timeout;
2447
+ language = option.ios.language;
2448
+ country = option.ios.country;
2405
2449
  if (typeof bundleId !== 'undefined' && typeof trackId === 'undefined')
2406
2450
  trackId = getTrackId(bundleId);
2407
2451
  if (typeof timeout === 'undefined')
@@ -2416,7 +2460,7 @@ function resolveOptions(option) {
2416
2460
  if (allowAppStore && allowScheme)
2417
2461
  resolved.push(['store', createAppStoreURL(trackId, os)]);
2418
2462
  if (allowWebStore)
2419
- resolved.push(['store', createWebStoreURL(trackId, os)]);
2463
+ resolved.push(['store', createWebStoreURL(trackId, os, language, country)]);
2420
2464
  }
2421
2465
  return [resolved, timeout];
2422
2466
  case 'windows':
@@ -2429,8 +2473,10 @@ function resolveOptions(option) {
2429
2473
  allowAppStore = option.windows.allowAppStore;
2430
2474
  allowWebStore = option.windows.allowWebStore;
2431
2475
  timeout = option.windows.timeout;
2476
+ language = option.windows.language;
2477
+ country = option.windows.country;
2432
2478
  if (typeof packageFamilyName !== 'undefined' && typeof productId === 'undefined')
2433
- productId = getProductId(packageFamilyName);
2479
+ productId = getProductId(packageFamilyName, language, country);
2434
2480
  if (typeof timeout === 'undefined')
2435
2481
  timeout = WINDOWS_DEFAULT_TIMEOUT;
2436
2482
  if (typeof scheme !== 'undefined')
@@ -2441,7 +2487,7 @@ function resolveOptions(option) {
2441
2487
  if (allowAppStore)
2442
2488
  resolved.push(['store', createAppStoreURL(productId, os)]);
2443
2489
  if (allowWebStore)
2444
- resolved.push(['store', createWebStoreURL(productId, os)]);
2490
+ resolved.push(['store', createWebStoreURL(productId, os, language, country)]);
2445
2491
  }
2446
2492
  return [resolved, timeout];
2447
2493
  case 'macos':
@@ -2454,6 +2500,8 @@ function resolveOptions(option) {
2454
2500
  allowAppStore = option.macos.allowAppStore;
2455
2501
  allowWebStore = option.macos.allowWebStore;
2456
2502
  timeout = option.macos.timeout;
2503
+ language = option.macos.language;
2504
+ country = option.macos.country;
2457
2505
  if (typeof bundleId !== 'undefined' && typeof trackId === 'undefined')
2458
2506
  trackId = getTrackId(bundleId);
2459
2507
  if (typeof timeout === 'undefined')
@@ -2466,7 +2514,7 @@ function resolveOptions(option) {
2466
2514
  if (allowAppStore)
2467
2515
  resolved.push(['store', createAppStoreURL(trackId, os)]);
2468
2516
  if (allowWebStore)
2469
- resolved.push(['store', createWebStoreURL(trackId, os)]);
2517
+ resolved.push(['store', createWebStoreURL(trackId, os, language, country)]);
2470
2518
  }
2471
2519
  return [resolved, timeout];
2472
2520
  }
@@ -2522,6 +2570,34 @@ function isFullyBlockedInAppBrowser() {
2522
2570
  function isPartnerAppOnly() {
2523
2571
  return /weibo.*weibo__[\d.]+/i.test(PlatformKit.userAgent);
2524
2572
  }
2573
+ function canOpenXSafari() {
2574
+ if (PlatformKit.os.name !== 'ios')
2575
+ return false;
2576
+ var version = PlatformKit.os.version;
2577
+ if (PlatformKit.compareVersion(version, '15.0') < 0)
2578
+ return false;
2579
+ if (PlatformKit.compareVersion(version, '16.0') >= 0 && PlatformKit.compareVersion(version, '17.0') < 0)
2580
+ return false;
2581
+ var inAppBrowser = PlatformKit.inAppBrowser;
2582
+ if (inAppBrowser === 'facebook' || inAppBrowser === 'instagram')
2583
+ return false;
2584
+ return canOpenScheme();
2585
+ }
2586
+ function isInWebview() {
2587
+ return PlatformKit.inAppBrowser !== null || PlatformKit.webview;
2588
+ }
2589
+ function canEscapeWebview() {
2590
+ if (!isInWebview())
2591
+ return false;
2592
+ var inAppBrowser = PlatformKit.inAppBrowser;
2593
+ if (inAppBrowser === 'kakaotalk' || inAppBrowser === 'line')
2594
+ return true;
2595
+ if (PlatformKit.os.name === 'android')
2596
+ return canOpenIntent();
2597
+ if (PlatformKit.os.name === 'ios')
2598
+ return canOpenXSafari();
2599
+ return false;
2600
+ }
2525
2601
  function canOpenWindowsSetting(version) {
2526
2602
  if (version.length === 0)
2527
2603
  return false;
@@ -2605,19 +2681,87 @@ function createAppStoreURL(id, os) {
2605
2681
  return os;
2606
2682
  }
2607
2683
  }
2608
- function createWebStoreURL(id, os) {
2684
+ function createWebStoreURL(id, os, language, country) {
2685
+ var resolved = resolveCountry(language, country);
2686
+ var countryPath = typeof resolved !== 'undefined' ? resolved.toLowerCase() + '/' : '';
2687
+ var url;
2609
2688
  switch (os) {
2610
2689
  case 'android':
2611
- return 'https://play.google.com/store/apps/details?id=' + id;
2690
+ url = 'https://play.google.com/store/apps/details?id=' + id;
2691
+ if (typeof language !== 'undefined')
2692
+ url = appendURLParameter(url, 'hl=' + escapeURIComponentString(language));
2693
+ if (typeof resolved !== 'undefined')
2694
+ url = appendURLParameter(url, 'gl=' + resolved);
2695
+ break;
2612
2696
  case 'ios':
2613
- return 'https://itunes.apple.com/app/id' + id + '?mt=8';
2697
+ url = 'https://itunes.apple.com/' + countryPath + 'app/id' + id + '?mt=8';
2698
+ if (typeof language !== 'undefined')
2699
+ url = appendURLParameter(url, 'l=' + escapeURIComponentString(language));
2700
+ break;
2614
2701
  case 'windows':
2615
- return 'https://apps.microsoft.com/detail/' + id;
2702
+ url = 'https://apps.microsoft.com/detail/' + id;
2703
+ if (typeof language !== 'undefined')
2704
+ url = appendURLParameter(url, 'hl=' + escapeURIComponentString(language));
2705
+ if (typeof resolved !== 'undefined')
2706
+ url = appendURLParameter(url, 'gl=' + resolved);
2707
+ break;
2616
2708
  case 'macos':
2617
- return 'https://apps.apple.com/app/id' + id + '?mt=12';
2709
+ url = 'https://apps.apple.com/' + countryPath + 'app/id' + id + '?mt=12';
2710
+ if (typeof language !== 'undefined')
2711
+ url = appendURLParameter(url, 'l=' + escapeURIComponentString(language));
2712
+ break;
2618
2713
  default:
2619
2714
  return os;
2620
2715
  }
2716
+ return url;
2717
+ }
2718
+ function extractRegion(tag) {
2719
+ var parts = tag.replace(/_/g, '-').split('-');
2720
+ for (var i = 1; i < parts.length; i++) {
2721
+ if (/^[A-Za-z]{2}$/.test(parts[i]))
2722
+ return parts[i].toUpperCase();
2723
+ }
2724
+ return undefined;
2725
+ }
2726
+ function resolveCountry(language, country) {
2727
+ if (typeof country !== 'undefined' && ALPHA2_REGION_PATTERN.test(country.toUpperCase()))
2728
+ return country.toUpperCase();
2729
+ if (typeof language === 'undefined')
2730
+ return undefined;
2731
+ var region = extractRegion(language);
2732
+ if (typeof region !== 'undefined')
2733
+ return region;
2734
+ if (typeof Intl !== 'undefined' && typeof Intl.Locale === 'function') {
2735
+ try {
2736
+ var locale = new Intl.Locale(language);
2737
+ if (typeof locale.maximize === 'function') {
2738
+ var maximized = locale.maximize();
2739
+ if (typeof maximized !== 'undefined' && maximized !== null && typeof maximized.region === 'string' && ALPHA2_REGION_PATTERN.test(maximized.region.toUpperCase()))
2740
+ return maximized.region.toUpperCase();
2741
+ }
2742
+ }
2743
+ catch (_) {
2744
+ }
2745
+ }
2746
+ return undefined;
2747
+ }
2748
+ function appendURLParameter(url, parameter) {
2749
+ var index = url.indexOf('#');
2750
+ var base = index === -1 ? url : url.substring(0, index);
2751
+ var hash = index === -1 ? '' : url.substring(index);
2752
+ return base + (base.indexOf('?') === -1 ? '?' : '&') + parameter + hash;
2753
+ }
2754
+ function createEscapeWebviewURL(url) {
2755
+ var inAppBrowser = PlatformKit.inAppBrowser;
2756
+ if (inAppBrowser === 'kakaotalk')
2757
+ return 'kakaotalk://web/openExternal?url=' + escapeURIComponentString(url);
2758
+ if (inAppBrowser === 'line')
2759
+ return appendURLParameter(url, 'openExternalBrowser=1');
2760
+ if (PlatformKit.os.name === 'android' && canOpenIntent())
2761
+ return createIntentURL(url, 'com.android.chrome', url);
2762
+ if (PlatformKit.os.name === 'ios' && canOpenXSafari())
2763
+ return 'x-safari-' + url;
2764
+ return undefined;
2621
2765
  }
2622
2766
  function escapeURIComponentString(value) {
2623
2767
  return encodeURIComponent(value)
@@ -2892,6 +3036,9 @@ var LaunchKit = {
2892
3036
  get canOpenSetting() {
2893
3037
  return canOpenSetting();
2894
3038
  },
3039
+ get canEscapeWebview() {
3040
+ return canEscapeWebview();
3041
+ },
2895
3042
  getTrackId: getTrackIdAsync,
2896
3043
  getProductId: getProductIdAsync,
2897
3044
  },
@@ -3159,6 +3306,18 @@ var LaunchKit = {
3159
3306
  return openURLSequential();
3160
3307
  });
3161
3308
  },
3309
+ escapeWebview: function (options) {
3310
+ if (options === void 0) { options = {}; }
3311
+ if (!isInWebview())
3312
+ 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 + '")'));
3313
+ var url = typeof options.url !== 'undefined' ? stripURL(options.url) : getTopmostWindow().location.href;
3314
+ if (!isWebURL(url))
3315
+ return Promise.reject(new Error('Cannot escape the webview: only http(s) URLs can be reopened in an external browser. (url: "' + url + '")'));
3316
+ var escape = createEscapeWebviewURL(url);
3317
+ if (typeof escape === 'undefined')
3318
+ return Promise.reject(new Error('Failed to escape the webview: no escape route is available in the current environment. (userAgent: "' + PlatformKit.userAgent + '")'));
3319
+ return openURL(0, escape, getDefaultTimeout(), isWebURL(escape));
3320
+ },
3162
3321
  };
3163
3322
 
3164
3323
  export { SettingType, LaunchKit as default };