intl-tel-input 25.5.2 → 25.8.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,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v25.5.2
2
+ * International Telephone Input v25.8.0
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -1365,18 +1365,18 @@ var factoryOutput = (() => {
1365
1365
  ]
1366
1366
  ];
1367
1367
  var allCountries = [];
1368
- for (let i = 0; i < rawCountryData.length; i++) {
1369
- const c = rawCountryData[i];
1370
- allCountries[i] = {
1368
+ for (const c of rawCountryData) {
1369
+ allCountries.push({
1371
1370
  name: "",
1372
- // this is now populated in the plugin
1371
+ // populated in the plugin
1373
1372
  iso2: c[0],
1374
1373
  dialCode: c[1],
1375
1374
  priority: c[2] || 0,
1376
1375
  areaCodes: c[3] || null,
1377
1376
  nodeById: {},
1377
+ // populated by the plugin
1378
1378
  nationalPrefix: c[4] || null
1379
- };
1379
+ });
1380
1380
  }
1381
1381
  var data_default = allCountries;
1382
1382
 
@@ -1633,6 +1633,7 @@ var factoryOutput = (() => {
1633
1633
  noCountrySelected: "No country selected",
1634
1634
  countryListAriaLabel: "List of countries",
1635
1635
  searchPlaceholder: "Search",
1636
+ clearSearchAriaLabel: "Clear search",
1636
1637
  zeroSearchResults: "No results found",
1637
1638
  oneSearchResult: "1 result found",
1638
1639
  multipleSearchResults: "${count} results found",
@@ -1647,10 +1648,23 @@ var factoryOutput = (() => {
1647
1648
  var en_default = allTranslations;
1648
1649
 
1649
1650
  // src/js/intl-tel-input.ts
1650
- for (let i = 0; i < data_default.length; i++) {
1651
- data_default[i].name = en_default[data_default[i].iso2];
1651
+ for (const c of data_default) {
1652
+ c.name = en_default[c.iso2];
1652
1653
  }
1653
1654
  var id = 0;
1655
+ var mq = (q) => {
1656
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(q).matches;
1657
+ };
1658
+ var computeDefaultUseFullscreenPopup = () => {
1659
+ if (typeof navigator !== "undefined" && typeof window !== "undefined") {
1660
+ const isMobileUserAgent = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1661
+ const isNarrowViewport = mq("(max-width: 500px)");
1662
+ const isShortViewport = mq("(max-height: 600px)");
1663
+ const isCoarsePointer = mq("(pointer: coarse)");
1664
+ return isMobileUserAgent || isNarrowViewport || isCoarsePointer && isShortViewport;
1665
+ }
1666
+ return false;
1667
+ };
1654
1668
  var defaults = {
1655
1669
  //* Whether or not to allow the dropdown.
1656
1670
  allowDropdown: true,
@@ -1697,13 +1711,7 @@ var factoryOutput = (() => {
1697
1711
  //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
1698
1712
  strictMode: false,
1699
1713
  //* Use full screen popup instead of dropdown for country list.
1700
- useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? (
1701
- //* We cannot just test screen size as some smartphones/website meta tags will report desktop resolutions.
1702
- //* Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1703
- /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1704
- navigator.userAgent
1705
- ) || window.innerWidth <= 500
1706
- ) : false,
1714
+ useFullscreenPopup: computeDefaultUseFullscreenPopup(),
1707
1715
  //* The number type to enforce during validation.
1708
1716
  validationNumberTypes: ["MOBILE"]
1709
1717
  };
@@ -1731,7 +1739,7 @@ var factoryOutput = (() => {
1731
1739
  var isRegionlessNanp = (number) => {
1732
1740
  const numeric = getNumeric(number);
1733
1741
  if (numeric.charAt(0) === "1") {
1734
- const areaCode = numeric.substr(1, 3);
1742
+ const areaCode = numeric.substring(1, 4);
1735
1743
  return regionlessNanpNumbers.includes(areaCode);
1736
1744
  }
1737
1745
  return false;
@@ -1754,8 +1762,8 @@ var factoryOutput = (() => {
1754
1762
  }
1755
1763
  return formattedValue.length;
1756
1764
  };
1757
- var createEl = (name, attrs, container) => {
1758
- const el = document.createElement(name);
1765
+ var createEl = (tagName, attrs, container) => {
1766
+ const el = document.createElement(tagName);
1759
1767
  if (attrs) {
1760
1768
  Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1761
1769
  }
@@ -1768,7 +1776,14 @@ var factoryOutput = (() => {
1768
1776
  const { instances } = intlTelInput;
1769
1777
  Object.values(instances).forEach((instance) => instance[method](...args));
1770
1778
  };
1771
- var Iti = class {
1779
+ var Iti = class _Iti {
1780
+ /**
1781
+ * Build a space-delimited class string from an object map of className -> truthy/falsey.
1782
+ * Only keys with truthy values are included.
1783
+ */
1784
+ static _buildClassNames(flags) {
1785
+ return Object.keys(flags).filter((k) => Boolean(flags[k])).join(" ");
1786
+ }
1772
1787
  constructor(input, customOptions = {}) {
1773
1788
  this.id = id++;
1774
1789
  this.telInput = input;
@@ -1831,6 +1846,16 @@ var factoryOutput = (() => {
1831
1846
  this._processDialCodes();
1832
1847
  this._translateCountryNames();
1833
1848
  this._sortCountries();
1849
+ this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
1850
+ this._cacheSearchTokens();
1851
+ }
1852
+ //* Precompute and cache country search tokens to speed up filtering
1853
+ _cacheSearchTokens() {
1854
+ for (const c of this.countries) {
1855
+ c.normalisedName = normaliseString(c.name);
1856
+ c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1857
+ c.dialCodePlus = `+${c.dialCode}`;
1858
+ }
1834
1859
  }
1835
1860
  //* Sort countries by countryOrder option (if present), then name.
1836
1861
  _sortCountries() {
@@ -1862,13 +1887,12 @@ var factoryOutput = (() => {
1862
1887
  if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1863
1888
  this.dialCodeToIso2Map[dialCode] = [];
1864
1889
  }
1865
- for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
1866
- if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
1867
- return;
1868
- }
1890
+ const iso2List = this.dialCodeToIso2Map[dialCode];
1891
+ if (iso2List.includes(iso2)) {
1892
+ return;
1869
1893
  }
1870
- const index = priority !== void 0 ? priority : this.dialCodeToIso2Map[dialCode].length;
1871
- this.dialCodeToIso2Map[dialCode][index] = iso2;
1894
+ const index = priority !== void 0 ? priority : iso2List.length;
1895
+ iso2List[index] = iso2;
1872
1896
  }
1873
1897
  //* Process onlyCountries or excludeCountries array if present.
1874
1898
  _processAllCountries() {
@@ -1893,33 +1917,30 @@ var factoryOutput = (() => {
1893
1917
  }
1894
1918
  //* Translate Countries by object literal provided on config.
1895
1919
  _translateCountryNames() {
1896
- for (let i = 0; i < this.countries.length; i++) {
1897
- const iso2 = this.countries[i].iso2.toLowerCase();
1920
+ for (const c of this.countries) {
1921
+ const iso2 = c.iso2.toLowerCase();
1898
1922
  if (this.options.i18n.hasOwnProperty(iso2)) {
1899
- this.countries[i].name = this.options.i18n[iso2];
1923
+ c.name = this.options.i18n[iso2];
1900
1924
  }
1901
1925
  }
1902
1926
  }
1903
1927
  //* Generate this.dialCodes and this.dialCodeToIso2Map.
1904
1928
  _processDialCodes() {
1905
- this.dialCodes = {};
1929
+ this.dialCodes = /* @__PURE__ */ new Set();
1906
1930
  this.dialCodeMaxLen = 0;
1907
1931
  this.dialCodeToIso2Map = {};
1908
- for (let i = 0; i < this.countries.length; i++) {
1909
- const c = this.countries[i];
1910
- if (!this.dialCodes[c.dialCode]) {
1911
- this.dialCodes[c.dialCode] = true;
1932
+ for (const c of this.countries) {
1933
+ if (!this.dialCodes.has(c.dialCode)) {
1934
+ this.dialCodes.add(c.dialCode);
1912
1935
  }
1913
1936
  this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1914
1937
  }
1915
- for (let i = 0; i < this.countries.length; i++) {
1916
- const c = this.countries[i];
1938
+ for (const c of this.countries) {
1917
1939
  if (c.areaCodes) {
1918
1940
  const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1919
- for (let j = 0; j < c.areaCodes.length; j++) {
1920
- const areaCode = c.areaCodes[j];
1941
+ for (const areaCode of c.areaCodes) {
1921
1942
  for (let k = 1; k < areaCode.length; k++) {
1922
- const partialAreaCode = areaCode.substr(0, k);
1943
+ const partialAreaCode = areaCode.substring(0, k);
1923
1944
  const partialDialCode = c.dialCode + partialAreaCode;
1924
1945
  this._addToDialCodeMap(rootIso2Code, partialDialCode);
1925
1946
  this._addToDialCodeMap(c.iso2, partialDialCode);
@@ -1947,20 +1968,14 @@ var factoryOutput = (() => {
1947
1968
  countrySearch,
1948
1969
  i18n
1949
1970
  } = this.options;
1950
- let parentClass = "iti";
1951
- if (allowDropdown) {
1952
- parentClass += " iti--allow-dropdown";
1953
- }
1954
- if (showFlags) {
1955
- parentClass += " iti--show-flags";
1956
- }
1957
- if (containerClass) {
1958
- parentClass += ` ${containerClass}`;
1959
- }
1960
- if (!useFullscreenPopup) {
1961
- parentClass += " iti--inline-dropdown";
1962
- }
1963
- const wrapper = createEl("div", { class: parentClass });
1971
+ const parentClasses = _Iti._buildClassNames({
1972
+ "iti": true,
1973
+ "iti--allow-dropdown": allowDropdown,
1974
+ "iti--show-flags": showFlags,
1975
+ "iti--inline-dropdown": !useFullscreenPopup,
1976
+ [containerClass]: Boolean(containerClass)
1977
+ });
1978
+ const wrapper = createEl("div", { class: parentClasses });
1964
1979
  this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
1965
1980
  if (allowDropdown || showFlags || separateDialCode) {
1966
1981
  this.countryContainer = createEl(
@@ -1981,9 +1996,8 @@ var factoryOutput = (() => {
1981
1996
  class: "iti__selected-country",
1982
1997
  "aria-expanded": "false",
1983
1998
  "aria-label": this.options.i18n.selectedCountryAriaLabel,
1984
- "aria-haspopup": "true",
1985
- "aria-controls": `iti-${this.id}__dropdown-content`,
1986
- "role": "combobox"
1999
+ "aria-haspopup": "dialog",
2000
+ "aria-controls": `iti-${this.id}__dropdown-content`
1987
2001
  },
1988
2002
  this.countryContainer
1989
2003
  );
@@ -2022,15 +2036,38 @@ var factoryOutput = (() => {
2022
2036
  const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
2023
2037
  this.dropdownContent = createEl("div", {
2024
2038
  id: `iti-${this.id}__dropdown-content`,
2025
- class: `iti__dropdown-content iti__hide ${extraClasses}`
2039
+ class: `iti__dropdown-content iti__hide ${extraClasses}`,
2040
+ role: "dialog",
2041
+ "aria-modal": "true"
2026
2042
  });
2027
2043
  if (countrySearch) {
2044
+ const searchWrapper = createEl(
2045
+ "div",
2046
+ { class: "iti__search-input-wrapper" },
2047
+ this.dropdownContent
2048
+ );
2049
+ this.searchIcon = createEl(
2050
+ "span",
2051
+ {
2052
+ class: "iti__search-icon",
2053
+ "aria-hidden": "true"
2054
+ },
2055
+ searchWrapper
2056
+ );
2057
+ this.searchIcon.innerHTML = `
2058
+ <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
2059
+ <circle cx="11" cy="11" r="7" />
2060
+ <line x1="21" y1="21" x2="16.65" y2="16.65" />
2061
+ </svg>`;
2028
2062
  this.searchInput = createEl(
2029
2063
  "input",
2030
2064
  {
2031
- type: "text",
2065
+ id: `iti-${this.id}__search-input`,
2066
+ // Chrome says inputs need either a name or an id
2067
+ type: "search",
2032
2068
  class: "iti__search-input",
2033
2069
  placeholder: i18n.searchPlaceholder,
2070
+ // role=combobox + aria-autocomplete=list + aria-activedescendant allows maintaining focus on the search input while allowing users to navigate search results with up/down keyboard keys
2034
2071
  role: "combobox",
2035
2072
  "aria-expanded": "true",
2036
2073
  "aria-label": i18n.searchPlaceholder,
@@ -2038,13 +2075,42 @@ var factoryOutput = (() => {
2038
2075
  "aria-autocomplete": "list",
2039
2076
  "autocomplete": "off"
2040
2077
  },
2041
- this.dropdownContent
2078
+ searchWrapper
2079
+ );
2080
+ this.searchClearButton = createEl(
2081
+ "button",
2082
+ {
2083
+ type: "button",
2084
+ class: "iti__search-clear iti__hide",
2085
+ "aria-label": i18n.clearSearchAriaLabel,
2086
+ tabindex: "-1"
2087
+ },
2088
+ searchWrapper
2042
2089
  );
2090
+ const maskId = `iti-${this.id}-clear-mask`;
2091
+ this.searchClearButton.innerHTML = `
2092
+ <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
2093
+ <mask id="${maskId}" maskUnits="userSpaceOnUse">
2094
+ <rect width="16" height="16" fill="white" />
2095
+ <path d="M5.2 5.2 L10.8 10.8 M10.8 5.2 L5.2 10.8" stroke="black" stroke-linecap="round" class="iti__search-clear-x" />
2096
+ </mask>
2097
+ <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${maskId})" />
2098
+ </svg>`;
2043
2099
  this.searchResultsA11yText = createEl(
2044
2100
  "span",
2045
2101
  { class: "iti__a11y-text" },
2046
2102
  this.dropdownContent
2047
2103
  );
2104
+ this.searchNoResults = createEl(
2105
+ "div",
2106
+ {
2107
+ class: "iti__no-results iti__hide",
2108
+ "aria-hidden": "true"
2109
+ // all a11y messaging happens in this.searchResultsA11yText
2110
+ },
2111
+ this.dropdownContent
2112
+ );
2113
+ this.searchNoResults.textContent = i18n.zeroSearchResults;
2048
2114
  }
2049
2115
  this.countryList = createEl(
2050
2116
  "ul",
@@ -2058,18 +2124,16 @@ var factoryOutput = (() => {
2058
2124
  );
2059
2125
  this._appendListItems();
2060
2126
  if (countrySearch) {
2061
- this._updateSearchResultsText();
2127
+ this._updateSearchResultsA11yText();
2062
2128
  }
2063
2129
  if (dropdownContainer) {
2064
- let dropdownClasses = "iti iti--container";
2065
- if (containerClass) {
2066
- dropdownClasses += ` ${containerClass}`;
2067
- }
2068
- if (useFullscreenPopup) {
2069
- dropdownClasses += " iti--fullscreen-popup";
2070
- } else {
2071
- dropdownClasses += " iti--inline-dropdown";
2072
- }
2130
+ const dropdownClasses = _Iti._buildClassNames({
2131
+ "iti": true,
2132
+ "iti--container": true,
2133
+ "iti--fullscreen-popup": useFullscreenPopup,
2134
+ "iti--inline-dropdown": !useFullscreenPopup,
2135
+ [containerClass]: Boolean(containerClass)
2136
+ });
2073
2137
  this.dropdown = createEl("div", { class: dropdownClasses });
2074
2138
  this.dropdown.appendChild(this.dropdownContent);
2075
2139
  } else {
@@ -2354,7 +2418,7 @@ var factoryOutput = (() => {
2354
2418
  //* Adhere to the input's maxlength attr.
2355
2419
  _cap(number) {
2356
2420
  const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
2357
- return max && number.length > max ? number.substr(0, max) : number;
2421
+ return max && number.length > max ? number.substring(0, max) : number;
2358
2422
  }
2359
2423
  //* Trigger a custom event on the input.
2360
2424
  _trigger(name, detailProps = {}) {
@@ -2467,6 +2531,11 @@ var factoryOutput = (() => {
2467
2531
  } else {
2468
2532
  this._filterCountries("", true);
2469
2533
  }
2534
+ if (this.searchInput.value) {
2535
+ this.searchClearButton.classList.remove("iti__hide");
2536
+ } else {
2537
+ this.searchClearButton.classList.add("iti__hide");
2538
+ }
2470
2539
  };
2471
2540
  let keyupTimer = null;
2472
2541
  this._handleSearchChange = () => {
@@ -2479,14 +2548,20 @@ var factoryOutput = (() => {
2479
2548
  }, 100);
2480
2549
  };
2481
2550
  this.searchInput.addEventListener("input", this._handleSearchChange);
2551
+ this._handleSearchClear = (e) => {
2552
+ e.stopPropagation();
2553
+ this.searchInput.value = "";
2554
+ this.searchInput.focus();
2555
+ doFilter();
2556
+ };
2557
+ this.searchClearButton.addEventListener("click", this._handleSearchClear);
2482
2558
  this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2483
2559
  }
2484
2560
  }
2485
2561
  //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
2486
2562
  _searchForCountry(query) {
2487
- for (let i = 0; i < this.countries.length; i++) {
2488
- const c = this.countries[i];
2489
- const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
2563
+ for (const c of this.countries) {
2564
+ const startsWith = c.name.substring(0, query.length).toLowerCase() === query;
2490
2565
  if (startsWith) {
2491
2566
  const listItem = c.nodeById[this.id];
2492
2567
  this._highlightListItem(listItem, false);
@@ -2507,23 +2582,20 @@ var factoryOutput = (() => {
2507
2582
  const dialCodeMatches = [];
2508
2583
  const dialCodeContains = [];
2509
2584
  const initialsMatches = [];
2510
- for (let i = 0; i < this.countries.length; i++) {
2511
- const c = this.countries[i];
2512
- const normalisedCountryName = normaliseString(c.name);
2513
- const countryInitials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
2585
+ for (const c of this.countries) {
2514
2586
  if (isReset || queryLength === 0) {
2515
2587
  nameContains.push(c);
2516
- } else if (c.iso2.toLowerCase() === normalisedQuery) {
2588
+ } else if (c.iso2 === normalisedQuery) {
2517
2589
  iso2Matches.push(c);
2518
- } else if (normalisedCountryName.startsWith(normalisedQuery)) {
2590
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2519
2591
  nameStartWith.push(c);
2520
- } else if (normalisedCountryName.includes(normalisedQuery)) {
2592
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2521
2593
  nameContains.push(c);
2522
- } else if (normalisedQuery === c.dialCode || normalisedQuery === `+${c.dialCode}`) {
2594
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2523
2595
  dialCodeMatches.push(c);
2524
- } else if (`+${c.dialCode}`.includes(normalisedQuery)) {
2596
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2525
2597
  dialCodeContains.push(c);
2526
- } else if (countryInitials.includes(normalisedQuery)) {
2598
+ } else if (c.initials.includes(normalisedQuery)) {
2527
2599
  initialsMatches.push(c);
2528
2600
  }
2529
2601
  }
@@ -2547,12 +2619,17 @@ var factoryOutput = (() => {
2547
2619
  }
2548
2620
  if (noCountriesAddedYet) {
2549
2621
  this._highlightListItem(null, false);
2622
+ if (this.searchNoResults) {
2623
+ this.searchNoResults.classList.remove("iti__hide");
2624
+ }
2625
+ } else if (this.searchNoResults) {
2626
+ this.searchNoResults.classList.add("iti__hide");
2550
2627
  }
2551
2628
  this.countryList.scrollTop = 0;
2552
- this._updateSearchResultsText();
2629
+ this._updateSearchResultsA11yText();
2553
2630
  }
2554
2631
  //* Update search results text (for a11y).
2555
- _updateSearchResultsText() {
2632
+ _updateSearchResultsA11yText() {
2556
2633
  const { i18n } = this.options;
2557
2634
  const count = this.countryList.childElementCount;
2558
2635
  let searchText;
@@ -2643,9 +2720,9 @@ var factoryOutput = (() => {
2643
2720
  const alreadySelected = selectedIso2 && iso2Codes.includes(selectedIso2) && !hasAreaCodesButNoneMatched;
2644
2721
  const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2645
2722
  if (!isRegionlessNanpNumber && !alreadySelected) {
2646
- for (let j = 0; j < iso2Codes.length; j++) {
2647
- if (iso2Codes[j]) {
2648
- return iso2Codes[j];
2723
+ for (const iso2 of iso2Codes) {
2724
+ if (iso2) {
2725
+ return iso2;
2649
2726
  }
2650
2727
  }
2651
2728
  }
@@ -2667,9 +2744,8 @@ var factoryOutput = (() => {
2667
2744
  if (this.highlightedItem) {
2668
2745
  this.highlightedItem.classList.add("iti__highlight");
2669
2746
  this.highlightedItem.setAttribute("aria-selected", "true");
2670
- const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2671
- this.selectedCountry.setAttribute("aria-activedescendant", activeDescendant);
2672
2747
  if (this.options.countrySearch) {
2748
+ const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2673
2749
  this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
2674
2750
  }
2675
2751
  }
@@ -2678,12 +2754,11 @@ var factoryOutput = (() => {
2678
2754
  }
2679
2755
  }
2680
2756
  //* Find the country data for the given iso2 code
2681
- //* the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
2757
+ //* 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
2682
2758
  _getCountryData(iso2, allowFail) {
2683
- for (let i = 0; i < this.countries.length; i++) {
2684
- if (this.countries[i].iso2 === iso2) {
2685
- return this.countries[i];
2686
- }
2759
+ const country = this.countryByIso2.get(iso2);
2760
+ if (country) {
2761
+ return country;
2687
2762
  }
2688
2763
  if (allowFail) {
2689
2764
  return null;
@@ -2834,7 +2909,6 @@ var factoryOutput = (() => {
2834
2909
  _closeDropdown() {
2835
2910
  this.dropdownContent.classList.add("iti__hide");
2836
2911
  this.selectedCountry.setAttribute("aria-expanded", "false");
2837
- this.selectedCountry.removeAttribute("aria-activedescendant");
2838
2912
  if (this.highlightedItem) {
2839
2913
  this.highlightedItem.setAttribute("aria-selected", "false");
2840
2914
  }
@@ -2842,9 +2916,9 @@ var factoryOutput = (() => {
2842
2916
  this.searchInput.removeAttribute("aria-activedescendant");
2843
2917
  }
2844
2918
  this.dropdownArrow.classList.remove("iti__arrow--up");
2845
- document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2846
2919
  if (this.options.countrySearch) {
2847
2920
  this.searchInput.removeEventListener("input", this._handleSearchChange);
2921
+ this.searchClearButton.removeEventListener("click", this._handleSearchClear);
2848
2922
  }
2849
2923
  document.documentElement.removeEventListener(
2850
2924
  "click",
@@ -2914,11 +2988,11 @@ var factoryOutput = (() => {
2914
2988
  numericChars += c;
2915
2989
  if (includeAreaCode) {
2916
2990
  if (this.dialCodeToIso2Map[numericChars]) {
2917
- dialCode = number.substr(0, i + 1);
2991
+ dialCode = number.substring(0, i + 1);
2918
2992
  }
2919
2993
  } else {
2920
- if (this.dialCodes[numericChars]) {
2921
- dialCode = number.substr(0, i + 1);
2994
+ if (this.dialCodes.has(numericChars)) {
2995
+ dialCode = number.substring(0, i + 1);
2922
2996
  break;
2923
2997
  }
2924
2998
  }
@@ -2951,7 +3025,7 @@ var factoryOutput = (() => {
2951
3025
  if (dialCode) {
2952
3026
  dialCode = `+${this.selectedCountryData.dialCode}`;
2953
3027
  const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2954
- number = number.substr(start);
3028
+ number = number.substring(start);
2955
3029
  }
2956
3030
  }
2957
3031
  return this._cap(number);
@@ -3085,38 +3159,32 @@ var factoryOutput = (() => {
3085
3159
  }
3086
3160
  return -99;
3087
3161
  }
3088
- //* Validate the input val
3162
+ //* Validate the input val (with precise=false)
3089
3163
  isValidNumber() {
3090
- if (!this.selectedCountryData.iso2) {
3091
- return false;
3092
- }
3093
- const val = this._getFullNumber();
3094
- const alphaCharPosition = val.search(/\p{L}/u);
3095
- if (alphaCharPosition > -1) {
3096
- const beforeAlphaChar = val.substring(0, alphaCharPosition);
3097
- const beforeAlphaIsValid = this._utilsIsPossibleNumber(beforeAlphaChar);
3098
- const isValid = this._utilsIsPossibleNumber(val);
3099
- return beforeAlphaIsValid && isValid;
3100
- }
3101
- return this._utilsIsPossibleNumber(val);
3164
+ return this._validateNumber(false);
3165
+ }
3166
+ //* Validate the input val (with precise=true)
3167
+ isValidNumberPrecise() {
3168
+ return this._validateNumber(true);
3102
3169
  }
3103
3170
  _utilsIsPossibleNumber(val) {
3104
3171
  return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
3105
3172
  }
3106
- //* Validate the input val (precise)
3107
- isValidNumberPrecise() {
3173
+ //* Shared internal validation logic to handle alpha character extension rules.
3174
+ _validateNumber(precise) {
3108
3175
  if (!this.selectedCountryData.iso2) {
3109
3176
  return false;
3110
3177
  }
3111
3178
  const val = this._getFullNumber();
3112
3179
  const alphaCharPosition = val.search(/\p{L}/u);
3180
+ const testValidity = (s) => precise ? this._utilsIsValidNumber(s) : this._utilsIsPossibleNumber(s);
3113
3181
  if (alphaCharPosition > -1) {
3114
3182
  const beforeAlphaChar = val.substring(0, alphaCharPosition);
3115
- const beforeAlphaIsValid = this._utilsIsValidNumber(beforeAlphaChar);
3116
- const isValid = this._utilsIsValidNumber(val);
3183
+ const beforeAlphaIsValid = testValidity(beforeAlphaChar);
3184
+ const isValid = testValidity(val);
3117
3185
  return beforeAlphaIsValid && isValid;
3118
3186
  }
3119
- return this._utilsIsValidNumber(val);
3187
+ return testValidity(val);
3120
3188
  }
3121
3189
  _utilsIsValidNumber(val) {
3122
3190
  return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
@@ -3208,7 +3276,7 @@ var factoryOutput = (() => {
3208
3276
  attachUtils,
3209
3277
  startedLoadingUtilsScript: false,
3210
3278
  startedLoadingAutoCountry: false,
3211
- version: "25.5.2"
3279
+ version: "25.8.0"
3212
3280
  }
3213
3281
  );
3214
3282
  var intl_tel_input_default = intlTelInput;