intl-tel-input 25.5.2 → 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;
@@ -1790,6 +1797,16 @@ var Iti = class {
1790
1797
  this._processDialCodes();
1791
1798
  this._translateCountryNames();
1792
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
+ }
1793
1810
  }
1794
1811
  //* Sort countries by countryOrder option (if present), then name.
1795
1812
  _sortCountries() {
@@ -1821,13 +1838,12 @@ var Iti = class {
1821
1838
  if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1822
1839
  this.dialCodeToIso2Map[dialCode] = [];
1823
1840
  }
1824
- for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
1825
- if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
1826
- return;
1827
- }
1841
+ const iso2List = this.dialCodeToIso2Map[dialCode];
1842
+ if (iso2List.includes(iso2)) {
1843
+ return;
1828
1844
  }
1829
- const index = priority !== void 0 ? priority : this.dialCodeToIso2Map[dialCode].length;
1830
- this.dialCodeToIso2Map[dialCode][index] = iso2;
1845
+ const index = priority !== void 0 ? priority : iso2List.length;
1846
+ iso2List[index] = iso2;
1831
1847
  }
1832
1848
  //* Process onlyCountries or excludeCountries array if present.
1833
1849
  _processAllCountries() {
@@ -1852,33 +1868,30 @@ var Iti = class {
1852
1868
  }
1853
1869
  //* Translate Countries by object literal provided on config.
1854
1870
  _translateCountryNames() {
1855
- for (let i = 0; i < this.countries.length; i++) {
1856
- const iso2 = this.countries[i].iso2.toLowerCase();
1871
+ for (const c of this.countries) {
1872
+ const iso2 = c.iso2.toLowerCase();
1857
1873
  if (this.options.i18n.hasOwnProperty(iso2)) {
1858
- this.countries[i].name = this.options.i18n[iso2];
1874
+ c.name = this.options.i18n[iso2];
1859
1875
  }
1860
1876
  }
1861
1877
  }
1862
1878
  //* Generate this.dialCodes and this.dialCodeToIso2Map.
1863
1879
  _processDialCodes() {
1864
- this.dialCodes = {};
1880
+ this.dialCodes = /* @__PURE__ */ new Set();
1865
1881
  this.dialCodeMaxLen = 0;
1866
1882
  this.dialCodeToIso2Map = {};
1867
- for (let i = 0; i < this.countries.length; i++) {
1868
- const c = this.countries[i];
1869
- if (!this.dialCodes[c.dialCode]) {
1870
- 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);
1871
1886
  }
1872
1887
  this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1873
1888
  }
1874
- for (let i = 0; i < this.countries.length; i++) {
1875
- const c = this.countries[i];
1889
+ for (const c of this.countries) {
1876
1890
  if (c.areaCodes) {
1877
1891
  const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1878
- for (let j = 0; j < c.areaCodes.length; j++) {
1879
- const areaCode = c.areaCodes[j];
1892
+ for (const areaCode of c.areaCodes) {
1880
1893
  for (let k = 1; k < areaCode.length; k++) {
1881
- const partialAreaCode = areaCode.substr(0, k);
1894
+ const partialAreaCode = areaCode.substring(0, k);
1882
1895
  const partialDialCode = c.dialCode + partialAreaCode;
1883
1896
  this._addToDialCodeMap(rootIso2Code, partialDialCode);
1884
1897
  this._addToDialCodeMap(c.iso2, partialDialCode);
@@ -2313,7 +2326,7 @@ var Iti = class {
2313
2326
  //* Adhere to the input's maxlength attr.
2314
2327
  _cap(number) {
2315
2328
  const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
2316
- return max && number.length > max ? number.substr(0, max) : number;
2329
+ return max && number.length > max ? number.substring(0, max) : number;
2317
2330
  }
2318
2331
  //* Trigger a custom event on the input.
2319
2332
  _trigger(name, detailProps = {}) {
@@ -2443,9 +2456,8 @@ var Iti = class {
2443
2456
  }
2444
2457
  //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
2445
2458
  _searchForCountry(query) {
2446
- for (let i = 0; i < this.countries.length; i++) {
2447
- const c = this.countries[i];
2448
- 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;
2449
2461
  if (startsWith) {
2450
2462
  const listItem = c.nodeById[this.id];
2451
2463
  this._highlightListItem(listItem, false);
@@ -2466,23 +2478,20 @@ var Iti = class {
2466
2478
  const dialCodeMatches = [];
2467
2479
  const dialCodeContains = [];
2468
2480
  const initialsMatches = [];
2469
- for (let i = 0; i < this.countries.length; i++) {
2470
- const c = this.countries[i];
2471
- const normalisedCountryName = normaliseString(c.name);
2472
- const countryInitials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
2481
+ for (const c of this.countries) {
2473
2482
  if (isReset || queryLength === 0) {
2474
2483
  nameContains.push(c);
2475
- } else if (c.iso2.toLowerCase() === normalisedQuery) {
2484
+ } else if (c.iso2 === normalisedQuery) {
2476
2485
  iso2Matches.push(c);
2477
- } else if (normalisedCountryName.startsWith(normalisedQuery)) {
2486
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2478
2487
  nameStartWith.push(c);
2479
- } else if (normalisedCountryName.includes(normalisedQuery)) {
2488
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2480
2489
  nameContains.push(c);
2481
- } else if (normalisedQuery === c.dialCode || normalisedQuery === `+${c.dialCode}`) {
2490
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2482
2491
  dialCodeMatches.push(c);
2483
- } else if (`+${c.dialCode}`.includes(normalisedQuery)) {
2492
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2484
2493
  dialCodeContains.push(c);
2485
- } else if (countryInitials.includes(normalisedQuery)) {
2494
+ } else if (c.initials.includes(normalisedQuery)) {
2486
2495
  initialsMatches.push(c);
2487
2496
  }
2488
2497
  }
@@ -2602,9 +2611,9 @@ var Iti = class {
2602
2611
  const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && !hasAreaCodesButNoneMatched;
2603
2612
  const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2604
2613
  if (!isRegionlessNanpNumber && !alreadySelected) {
2605
- for (let j = 0; j < iso2Codes.length; j++) {
2606
- if (iso2Codes[j]) {
2607
- return iso2Codes[j];
2614
+ for (const iso2 of iso2Codes) {
2615
+ if (iso2) {
2616
+ return iso2;
2608
2617
  }
2609
2618
  }
2610
2619
  }
@@ -2637,12 +2646,11 @@ var Iti = class {
2637
2646
  }
2638
2647
  }
2639
2648
  //* Find the country data for the given iso2 code
2640
- //* 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
2641
2650
  _getCountryData(iso2, allowFail) {
2642
- for (let i = 0; i < this.countries.length; i++) {
2643
- if (this.countries[i].iso2 === iso2) {
2644
- return this.countries[i];
2645
- }
2651
+ const country = this.countryByIso2.get(iso2);
2652
+ if (country) {
2653
+ return country;
2646
2654
  }
2647
2655
  if (allowFail) {
2648
2656
  return null;
@@ -2873,11 +2881,11 @@ var Iti = class {
2873
2881
  numericChars += c;
2874
2882
  if (includeAreaCode) {
2875
2883
  if (this.dialCodeToIso2Map[numericChars]) {
2876
- dialCode = number.substr(0, i + 1);
2884
+ dialCode = number.substring(0, i + 1);
2877
2885
  }
2878
2886
  } else {
2879
- if (this.dialCodes[numericChars]) {
2880
- dialCode = number.substr(0, i + 1);
2887
+ if (this.dialCodes.has(numericChars)) {
2888
+ dialCode = number.substring(0, i + 1);
2881
2889
  break;
2882
2890
  }
2883
2891
  }
@@ -2910,7 +2918,7 @@ var Iti = class {
2910
2918
  if (dialCode) {
2911
2919
  dialCode = `+${this.selectedCountryData.dialCode}`;
2912
2920
  const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2913
- number = number.substr(start);
2921
+ number = number.substring(start);
2914
2922
  }
2915
2923
  }
2916
2924
  return this._cap(number);
@@ -3044,38 +3052,32 @@ var Iti = class {
3044
3052
  }
3045
3053
  return -99;
3046
3054
  }
3047
- //* Validate the input val
3055
+ //* Validate the input val (with precise=false)
3048
3056
  isValidNumber() {
3049
- if (!this.selectedCountryData.iso2) {
3050
- return false;
3051
- }
3052
- const val = this._getFullNumber();
3053
- const alphaCharPosition = val.search(/\p{L}/u);
3054
- if (alphaCharPosition > -1) {
3055
- const beforeAlphaChar = val.substring(0, alphaCharPosition);
3056
- const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
3057
- const isValid = this._utilsIsPossibleNumber(val);
3058
- return beforeAlphaIsValid && isValid;
3059
- }
3060
- 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);
3061
3062
  }
3062
3063
  _utilsIsPossibleNumber(val) {
3063
3064
  return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
3064
3065
  }
3065
- //* Validate the input val (precise)
3066
- isValidNumberPrecise() {
3066
+ //* Shared internal validation logic to handle alpha character extension rules.
3067
+ _validateNumber(precise) {
3067
3068
  if (!this.selectedCountryData.iso2) {
3068
3069
  return false;
3069
3070
  }
3070
3071
  const val = this._getFullNumber();
3071
3072
  const alphaCharPosition = val.search(/\p{L}/u);
3073
+ const testValidity = (s) => precise ? this._utilsIsValidNumber(s) : this._utilsIsPossibleNumber(s);
3072
3074
  if (alphaCharPosition > -1) {
3073
3075
  const beforeAlphaChar = val.substring(0, alphaCharPosition);
3074
- const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
3075
- const isValid = this._utilsIsValidNumber(val);
3076
+ const beforeAlphaIsValid = testValidity(beforeAlphaChar);
3077
+ const isValid = testValidity(val);
3076
3078
  return beforeAlphaIsValid && isValid;
3077
3079
  }
3078
- return this._utilsIsValidNumber(val);
3080
+ return testValidity(val);
3079
3081
  }
3080
3082
  _utilsIsValidNumber(val) {
3081
3083
  return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
@@ -3167,7 +3169,7 @@ var intlTelInput = Object.assign(
3167
3169
  attachUtils,
3168
3170
  startedLoadingUtilsScript: false,
3169
3171
  startedLoadingAutoCountry: false,
3170
- version: "25.5.2"
3172
+ version: "25.7.0"
3171
3173
  }
3172
3174
  );
3173
3175
  var intl_tel_input_default = intlTelInput;