intl-tel-input 25.5.1 → 25.7.0

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,12 +1,17 @@
1
1
  declare module "intl-tel-input/data" {
2
2
  export type Country = {
3
- name: string;
4
3
  iso2: string;
5
4
  dialCode: string;
6
5
  priority: number;
7
6
  areaCodes: string[] | null;
8
- nodeById: object;
9
7
  nationalPrefix: string | null;
8
+ name: string;
9
+ nodeById: {
10
+ [instanceId: number]: HTMLElement;
11
+ };
12
+ normalisedName?: string;
13
+ initials?: string;
14
+ dialCodePlus?: string;
10
15
  };
11
16
  const allCountries: Country[];
12
17
  export default allCountries;
@@ -383,6 +388,7 @@ declare module "intl-tel-input" {
383
388
  private dialCodeMaxLen;
384
389
  private dialCodeToIso2Map;
385
390
  private dialCodes;
391
+ private countryByIso2;
386
392
  private countryContainer;
387
393
  private selectedCountry;
388
394
  private selectedCountryInner;
@@ -420,6 +426,7 @@ declare module "intl-tel-input" {
420
426
  constructor(input: HTMLInputElement, customOptions?: SomeOptions);
421
427
  _init(): void;
422
428
  private _processCountryData;
429
+ private _cacheSearchTokens;
423
430
  private _sortCountries;
424
431
  private _addToDialCodeMap;
425
432
  private _processAllCountries;
@@ -475,8 +482,9 @@ declare module "intl-tel-input" {
475
482
  getSelectedCountryData(): SelectedCountryData;
476
483
  getValidationError(): number;
477
484
  isValidNumber(): boolean | null;
478
- private _utilsIsPossibleNumber;
479
485
  isValidNumberPrecise(): boolean | null;
486
+ private _utilsIsPossibleNumber;
487
+ private _validateNumber;
480
488
  private _utilsIsValidNumber;
481
489
  setCountry(iso2: string): void;
482
490
  setNumber(number: string): void;
@@ -1324,18 +1324,18 @@ var rawCountryData = [
1324
1324
  ]
1325
1325
  ];
1326
1326
  var allCountries = [];
1327
- for (let i = 0; i < rawCountryData.length; i++) {
1328
- const c = rawCountryData[i];
1329
- allCountries[i] = {
1327
+ for (const c of rawCountryData) {
1328
+ allCountries.push({
1330
1329
  name: "",
1331
- // this is now populated in the plugin
1330
+ // populated in the plugin
1332
1331
  iso2: c[0],
1333
1332
  dialCode: c[1],
1334
1333
  priority: c[2] || 0,
1335
1334
  areaCodes: c[3] || null,
1336
1335
  nodeById: {},
1336
+ // populated by the plugin
1337
1337
  nationalPrefix: c[4] || null
1338
- };
1338
+ });
1339
1339
  }
1340
1340
  var data_default = allCountries;
1341
1341
 
@@ -1606,10 +1606,23 @@ var allTranslations = { ...countries_default, ...interface_default };
1606
1606
  var en_default = allTranslations;
1607
1607
 
1608
1608
  // src/js/intl-tel-input.ts
1609
- for (let i = 0; i < data_default.length; i++) {
1610
- data_default[i].name = en_default[data_default[i].iso2];
1609
+ for (const c of data_default) {
1610
+ c.name = en_default[c.iso2];
1611
1611
  }
1612
1612
  var id = 0;
1613
+ var mq = (q) => {
1614
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(q).matches;
1615
+ };
1616
+ var computeDefaultUseFullscreenPopup = () => {
1617
+ if (typeof navigator !== "undefined" && typeof window !== "undefined") {
1618
+ const isMobileUserAgent = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1619
+ const isNarrowViewport = mq("(max-width: 500px)");
1620
+ const isShortViewport = mq("(max-height: 600px)");
1621
+ const isCoarsePointer = mq("(pointer: coarse)");
1622
+ return isMobileUserAgent || isNarrowViewport || isCoarsePointer && isShortViewport;
1623
+ }
1624
+ return false;
1625
+ };
1613
1626
  var defaults = {
1614
1627
  //* Whether or not to allow the dropdown.
1615
1628
  allowDropdown: true,
@@ -1656,13 +1669,7 @@ var defaults = {
1656
1669
  //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
1657
1670
  strictMode: false,
1658
1671
  //* Use full screen popup instead of dropdown for country list.
1659
- useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? (
1660
- //* We cannot just test screen size as some smartphones/website meta tags will report desktop resolutions.
1661
- //* Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1662
- /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1663
- navigator.userAgent
1664
- ) || window.innerWidth <= 500
1665
- ) : false,
1672
+ useFullscreenPopup: computeDefaultUseFullscreenPopup(),
1666
1673
  //* The number type to enforce during validation.
1667
1674
  validationNumberTypes: ["MOBILE"]
1668
1675
  };
@@ -1690,7 +1697,7 @@ var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g,
1690
1697
  var isRegionlessNanp = (number) => {
1691
1698
  const numeric = getNumeric(number);
1692
1699
  if (numeric.charAt(0) === "1") {
1693
- const areaCode = numeric.substr(1, 3);
1700
+ const areaCode = numeric.substring(1, 4);
1694
1701
  return regionlessNanpNumbers.includes(areaCode);
1695
1702
  }
1696
1703
  return false;
@@ -1754,6 +1761,7 @@ var Iti = class {
1754
1761
  }
1755
1762
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1756
1763
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1764
+ this.telInput.dir = "ltr";
1757
1765
  const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
1758
1766
  this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
1759
1767
  if (this.options.separateDialCode) {
@@ -1789,6 +1797,16 @@ var Iti = class {
1789
1797
  this._processDialCodes();
1790
1798
  this._translateCountryNames();
1791
1799
  this._sortCountries();
1800
+ this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
1801
+ this._cacheSearchTokens();
1802
+ }
1803
+ //* Precompute and cache country search tokens to speed up filtering
1804
+ _cacheSearchTokens() {
1805
+ for (const c of this.countries) {
1806
+ c.normalisedName = normaliseString(c.name);
1807
+ c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1808
+ c.dialCodePlus = `+${c.dialCode}`;
1809
+ }
1792
1810
  }
1793
1811
  //* Sort countries by countryOrder option (if present), then name.
1794
1812
  _sortCountries() {
@@ -1820,13 +1838,12 @@ var Iti = class {
1820
1838
  if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1821
1839
  this.dialCodeToIso2Map[dialCode] = [];
1822
1840
  }
1823
- for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
1824
- if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
1825
- return;
1826
- }
1841
+ const iso2List = this.dialCodeToIso2Map[dialCode];
1842
+ if (iso2List.includes(iso2)) {
1843
+ return;
1827
1844
  }
1828
- const index = priority !== void 0 ? priority : this.dialCodeToIso2Map[dialCode].length;
1829
- this.dialCodeToIso2Map[dialCode][index] = iso2;
1845
+ const index = priority !== void 0 ? priority : iso2List.length;
1846
+ iso2List[index] = iso2;
1830
1847
  }
1831
1848
  //* Process onlyCountries or excludeCountries array if present.
1832
1849
  _processAllCountries() {
@@ -1851,33 +1868,30 @@ var Iti = class {
1851
1868
  }
1852
1869
  //* Translate Countries by object literal provided on config.
1853
1870
  _translateCountryNames() {
1854
- for (let i = 0; i < this.countries.length; i++) {
1855
- const iso2 = this.countries[i].iso2.toLowerCase();
1871
+ for (const c of this.countries) {
1872
+ const iso2 = c.iso2.toLowerCase();
1856
1873
  if (this.options.i18n.hasOwnProperty(iso2)) {
1857
- this.countries[i].name = this.options.i18n[iso2];
1874
+ c.name = this.options.i18n[iso2];
1858
1875
  }
1859
1876
  }
1860
1877
  }
1861
1878
  //* Generate this.dialCodes and this.dialCodeToIso2Map.
1862
1879
  _processDialCodes() {
1863
- this.dialCodes = {};
1880
+ this.dialCodes = /* @__PURE__ */ new Set();
1864
1881
  this.dialCodeMaxLen = 0;
1865
1882
  this.dialCodeToIso2Map = {};
1866
- for (let i = 0; i < this.countries.length; i++) {
1867
- const c = this.countries[i];
1868
- if (!this.dialCodes[c.dialCode]) {
1869
- this.dialCodes[c.dialCode] = true;
1883
+ for (const c of this.countries) {
1884
+ if (!this.dialCodes.has(c.dialCode)) {
1885
+ this.dialCodes.add(c.dialCode);
1870
1886
  }
1871
1887
  this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1872
1888
  }
1873
- for (let i = 0; i < this.countries.length; i++) {
1874
- const c = this.countries[i];
1889
+ for (const c of this.countries) {
1875
1890
  if (c.areaCodes) {
1876
1891
  const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1877
- for (let j = 0; j < c.areaCodes.length; j++) {
1878
- const areaCode = c.areaCodes[j];
1892
+ for (const areaCode of c.areaCodes) {
1879
1893
  for (let k = 1; k < areaCode.length; k++) {
1880
- const partialAreaCode = areaCode.substr(0, k);
1894
+ const partialAreaCode = areaCode.substring(0, k);
1881
1895
  const partialDialCode = c.dialCode + partialAreaCode;
1882
1896
  this._addToDialCodeMap(rootIso2Code, partialDialCode);
1883
1897
  this._addToDialCodeMap(c.iso2, partialDialCode);
@@ -1972,7 +1986,7 @@ var Iti = class {
1972
1986
  if (separateDialCode) {
1973
1987
  this.selectedDialCode = createEl(
1974
1988
  "div",
1975
- { class: "iti__selected-dial-code", "aria-hidden": "true" },
1989
+ { class: "iti__selected-dial-code", "aria-hidden": "true", dir: "ltr" },
1976
1990
  this.selectedCountry
1977
1991
  );
1978
1992
  }
@@ -2090,7 +2104,7 @@ var Iti = class {
2090
2104
  content += `<div class='iti__flag iti__${c.iso2}'></div>`;
2091
2105
  }
2092
2106
  content += `<span class='iti__country-name'>${c.name}</span>`;
2093
- content += `<span class='iti__dial-code'>+${c.dialCode}</span>`;
2107
+ content += `<span class='iti__dial-code' dir='ltr'>+${c.dialCode}</span>`;
2094
2108
  listItem.insertAdjacentHTML("beforeend", content);
2095
2109
  }
2096
2110
  }
@@ -2312,7 +2326,7 @@ var Iti = class {
2312
2326
  //* Adhere to the input's maxlength attr.
2313
2327
  _cap(number) {
2314
2328
  const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
2315
- return max && number.length > max ? number.substr(0, max) : number;
2329
+ return max && number.length > max ? number.substring(0, max) : number;
2316
2330
  }
2317
2331
  //* Trigger a custom event on the input.
2318
2332
  _trigger(name, detailProps = {}) {
@@ -2442,9 +2456,8 @@ var Iti = class {
2442
2456
  }
2443
2457
  //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
2444
2458
  _searchForCountry(query) {
2445
- for (let i = 0; i < this.countries.length; i++) {
2446
- const c = this.countries[i];
2447
- const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
2459
+ for (const c of this.countries) {
2460
+ const startsWith = c.name.substring(0, query.length).toLowerCase() === query;
2448
2461
  if (startsWith) {
2449
2462
  const listItem = c.nodeById[this.id];
2450
2463
  this._highlightListItem(listItem, false);
@@ -2465,23 +2478,20 @@ var Iti = class {
2465
2478
  const dialCodeMatches = [];
2466
2479
  const dialCodeContains = [];
2467
2480
  const initialsMatches = [];
2468
- for (let i = 0; i < this.countries.length; i++) {
2469
- const c = this.countries[i];
2470
- const normalisedCountryName = normaliseString(c.name);
2471
- const countryInitials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
2481
+ for (const c of this.countries) {
2472
2482
  if (isReset || queryLength === 0) {
2473
2483
  nameContains.push(c);
2474
- } else if (c.iso2.toLowerCase() === normalisedQuery) {
2484
+ } else if (c.iso2 === normalisedQuery) {
2475
2485
  iso2Matches.push(c);
2476
- } else if (normalisedCountryName.startsWith(normalisedQuery)) {
2486
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2477
2487
  nameStartWith.push(c);
2478
- } else if (normalisedCountryName.includes(normalisedQuery)) {
2488
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2479
2489
  nameContains.push(c);
2480
- } else if (normalisedQuery === c.dialCode || normalisedQuery === `+${c.dialCode}`) {
2490
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2481
2491
  dialCodeMatches.push(c);
2482
- } else if (`+${c.dialCode}`.includes(normalisedQuery)) {
2492
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2483
2493
  dialCodeContains.push(c);
2484
- } else if (countryInitials.includes(normalisedQuery)) {
2494
+ } else if (c.initials.includes(normalisedQuery)) {
2485
2495
  initialsMatches.push(c);
2486
2496
  }
2487
2497
  }
@@ -2601,9 +2611,9 @@ var Iti = class {
2601
2611
  const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && !hasAreaCodesButNoneMatched;
2602
2612
  const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2603
2613
  if (!isRegionlessNanpNumber && !alreadySelected) {
2604
- for (let j = 0; j < iso2Codes.length; j++) {
2605
- if (iso2Codes[j]) {
2606
- return iso2Codes[j];
2614
+ for (const iso2 of iso2Codes) {
2615
+ if (iso2) {
2616
+ return iso2;
2607
2617
  }
2608
2618
  }
2609
2619
  }
@@ -2636,12 +2646,11 @@ var Iti = class {
2636
2646
  }
2637
2647
  }
2638
2648
  //* Find the country data for the given iso2 code
2639
- //* the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
2649
+ //* the allowFail option is only used during init() for the initialCountry option, and for the iso2 returned from geoIpLookup - in these 2 cases we don't want to error out
2640
2650
  _getCountryData(iso2, allowFail) {
2641
- for (let i = 0; i < this.countries.length; i++) {
2642
- if (this.countries[i].iso2 === iso2) {
2643
- return this.countries[i];
2644
- }
2651
+ const country = this.countryByIso2.get(iso2);
2652
+ if (country) {
2653
+ return country;
2645
2654
  }
2646
2655
  if (allowFail) {
2647
2656
  return null;
@@ -2872,11 +2881,11 @@ var Iti = class {
2872
2881
  numericChars += c;
2873
2882
  if (includeAreaCode) {
2874
2883
  if (this.dialCodeToIso2Map[numericChars]) {
2875
- dialCode = number.substr(0, i + 1);
2884
+ dialCode = number.substring(0, i + 1);
2876
2885
  }
2877
2886
  } else {
2878
- if (this.dialCodes[numericChars]) {
2879
- dialCode = number.substr(0, i + 1);
2887
+ if (this.dialCodes.has(numericChars)) {
2888
+ dialCode = number.substring(0, i + 1);
2880
2889
  break;
2881
2890
  }
2882
2891
  }
@@ -2909,7 +2918,7 @@ var Iti = class {
2909
2918
  if (dialCode) {
2910
2919
  dialCode = `+${this.selectedCountryData.dialCode}`;
2911
2920
  const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2912
- number = number.substr(start);
2921
+ number = number.substring(start);
2913
2922
  }
2914
2923
  }
2915
2924
  return this._cap(number);
@@ -3043,38 +3052,32 @@ var Iti = class {
3043
3052
  }
3044
3053
  return -99;
3045
3054
  }
3046
- //* Validate the input val
3055
+ //* Validate the input val (with precise=false)
3047
3056
  isValidNumber() {
3048
- if (!this.selectedCountryData.iso2) {
3049
- return false;
3050
- }
3051
- const val = this._getFullNumber();
3052
- const alphaCharPosition = val.search(/\p{L}/u);
3053
- if (alphaCharPosition > -1) {
3054
- const beforeAlphaChar = val.substring(0, alphaCharPosition);
3055
- const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
3056
- const isValid = this._utilsIsPossibleNumber(val);
3057
- return beforeAlphaIsValid && isValid;
3058
- }
3059
- return this._utilsIsPossibleNumber(val);
3057
+ return this._validateNumber(false);
3058
+ }
3059
+ //* Validate the input val (with precise=true)
3060
+ isValidNumberPrecise() {
3061
+ return this._validateNumber(true);
3060
3062
  }
3061
3063
  _utilsIsPossibleNumber(val) {
3062
3064
  return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
3063
3065
  }
3064
- //* Validate the input val (precise)
3065
- isValidNumberPrecise() {
3066
+ //* Shared internal validation logic to handle alpha character extension rules.
3067
+ _validateNumber(precise) {
3066
3068
  if (!this.selectedCountryData.iso2) {
3067
3069
  return false;
3068
3070
  }
3069
3071
  const val = this._getFullNumber();
3070
3072
  const alphaCharPosition = val.search(/\p{L}/u);
3073
+ const testValidity = (s) => precise ? this._utilsIsValidNumber(s) : this._utilsIsPossibleNumber(s);
3071
3074
  if (alphaCharPosition > -1) {
3072
3075
  const beforeAlphaChar = val.substring(0, alphaCharPosition);
3073
- const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
3074
- const isValid = this._utilsIsValidNumber(val);
3076
+ const beforeAlphaIsValid = testValidity(beforeAlphaChar);
3077
+ const isValid = testValidity(val);
3075
3078
  return beforeAlphaIsValid && isValid;
3076
3079
  }
3077
- return this._utilsIsValidNumber(val);
3080
+ return testValidity(val);
3078
3081
  }
3079
3082
  _utilsIsValidNumber(val) {
3080
3083
  return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
@@ -3166,7 +3169,7 @@ var intlTelInput = Object.assign(
3166
3169
  attachUtils,
3167
3170
  startedLoadingUtilsScript: false,
3168
3171
  startedLoadingAutoCountry: false,
3169
- version: "25.5.1"
3172
+ version: "25.7.0"
3170
3173
  }
3171
3174
  );
3172
3175
  var intl_tel_input_default = intlTelInput;