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