intl-tel-input 25.10.6 → 25.10.8

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.
Files changed (35) hide show
  1. package/README.md +5 -5
  2. package/angular/README.md +1 -1
  3. package/angular/build/IntlTelInput.js +415 -316
  4. package/angular/build/IntlTelInputWithUtils.js +466 -338
  5. package/angular/build/types/intl-tel-input/angular.d.ts +2 -1
  6. package/angular/build/types/intl-tel-input/angularWithUtils.d.ts +2 -1
  7. package/angular/build/types/intl-tel-input/data.d.ts +3 -1
  8. package/angular/build/types/intl-tel-input/i18n/types.d.ts +2 -245
  9. package/angular/build/types/intl-tel-input.d.ts +17 -87
  10. package/angular/build/types/modules/core/options.d.ts +3 -0
  11. package/angular/build/types/modules/data/country-data.d.ts +12 -0
  12. package/angular/build/types/modules/data/nanp-regionless.d.ts +2 -0
  13. package/angular/build/types/modules/format/caret.d.ts +1 -0
  14. package/angular/build/types/modules/format/formatting.d.ts +3 -0
  15. package/angular/build/types/modules/types/public-api.d.ts +79 -0
  16. package/angular/build/types/modules/utils/dom.d.ts +1 -0
  17. package/angular/build/types/modules/utils/string.d.ts +2 -0
  18. package/build/js/data.js +3 -2
  19. package/build/js/data.min.js +2 -2
  20. package/build/js/intlTelInput.d.ts +100 -292
  21. package/build/js/intlTelInput.js +461 -357
  22. package/build/js/intlTelInput.min.js +13 -13
  23. package/build/js/intlTelInputWithUtils.js +512 -379
  24. package/build/js/intlTelInputWithUtils.min.js +13 -13
  25. package/build/js/utils.js +18 -15
  26. package/package.json +1 -1
  27. package/react/README.md +1 -1
  28. package/react/build/IntlTelInput.cjs +460 -356
  29. package/react/build/IntlTelInput.d.ts +104 -294
  30. package/react/build/IntlTelInput.js +460 -356
  31. package/react/build/IntlTelInputWithUtils.cjs +511 -378
  32. package/react/build/IntlTelInputWithUtils.js +511 -378
  33. package/vue/README.md +1 -1
  34. package/vue/build/IntlTelInput.mjs +506 -452
  35. package/vue/build/IntlTelInputWithUtils.mjs +1096 -1013
@@ -1606,11 +1606,7 @@ var interface_default = interfaceTranslations;
1606
1606
  var allTranslations = { ...countries_default, ...interface_default };
1607
1607
  var en_default = allTranslations;
1608
1608
 
1609
- // src/js/intl-tel-input.ts
1610
- for (const c of data_default) {
1611
- c.name = en_default[c.iso2];
1612
- }
1613
- var id = 0;
1609
+ // src/js/modules/core/options.ts
1614
1610
  var mq = (q) => {
1615
1611
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(q).matches;
1616
1612
  };
@@ -1676,6 +1672,181 @@ var defaults = {
1676
1672
  //* The number type to enforce during validation.
1677
1673
  validationNumberTypes: ["MOBILE"]
1678
1674
  };
1675
+ function applyOptionSideEffects(o) {
1676
+ if (o.useFullscreenPopup) {
1677
+ o.fixDropdownWidth = false;
1678
+ }
1679
+ if (o.onlyCountries.length === 1) {
1680
+ o.initialCountry = o.onlyCountries[0];
1681
+ }
1682
+ if (o.separateDialCode) {
1683
+ o.nationalMode = false;
1684
+ }
1685
+ if (o.allowDropdown && !o.showFlags && !o.separateDialCode) {
1686
+ o.nationalMode = false;
1687
+ }
1688
+ if (o.useFullscreenPopup && !o.dropdownContainer) {
1689
+ o.dropdownContainer = document.body;
1690
+ }
1691
+ o.i18n = { ...en_default, ...o.i18n };
1692
+ }
1693
+
1694
+ // src/js/modules/utils/string.ts
1695
+ var getNumeric = (s) => s.replace(/\D/g, "");
1696
+ var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1697
+
1698
+ // src/js/modules/utils/dom.ts
1699
+ var createEl = (tagName, attrs, container) => {
1700
+ const el = document.createElement(tagName);
1701
+ if (attrs) {
1702
+ Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1703
+ }
1704
+ if (container) {
1705
+ container.appendChild(el);
1706
+ }
1707
+ return el;
1708
+ };
1709
+
1710
+ // src/js/modules/data/country-data.ts
1711
+ function processAllCountries(options) {
1712
+ const { onlyCountries, excludeCountries } = options;
1713
+ if (onlyCountries.length) {
1714
+ const lowerCaseOnlyCountries = onlyCountries.map((country) => country.toLowerCase());
1715
+ return data_default.filter((country) => lowerCaseOnlyCountries.includes(country.iso2));
1716
+ } else if (excludeCountries.length) {
1717
+ const lowerCaseExcludeCountries = excludeCountries.map((country) => country.toLowerCase());
1718
+ return data_default.filter((country) => !lowerCaseExcludeCountries.includes(country.iso2));
1719
+ }
1720
+ return data_default;
1721
+ }
1722
+ function translateCountryNames(countries, options) {
1723
+ for (const c of countries) {
1724
+ const iso2 = c.iso2.toLowerCase();
1725
+ if (options.i18n[iso2]) {
1726
+ c.name = options.i18n[iso2];
1727
+ }
1728
+ }
1729
+ }
1730
+ function processDialCodes(countries, options) {
1731
+ const dialCodes = /* @__PURE__ */ new Set();
1732
+ let dialCodeMaxLen = 0;
1733
+ const dialCodeToIso2Map = {};
1734
+ const _addToDialCodeMap = (iso2, dialCode, priority) => {
1735
+ if (!iso2 || !dialCode) {
1736
+ return;
1737
+ }
1738
+ if (dialCode.length > dialCodeMaxLen) {
1739
+ dialCodeMaxLen = dialCode.length;
1740
+ }
1741
+ if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1742
+ dialCodeToIso2Map[dialCode] = [];
1743
+ }
1744
+ const iso2List = dialCodeToIso2Map[dialCode];
1745
+ if (iso2List.includes(iso2)) {
1746
+ return;
1747
+ }
1748
+ const index = priority !== void 0 ? priority : iso2List.length;
1749
+ iso2List[index] = iso2;
1750
+ };
1751
+ for (const c of countries) {
1752
+ if (!dialCodes.has(c.dialCode)) {
1753
+ dialCodes.add(c.dialCode);
1754
+ }
1755
+ _addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1756
+ }
1757
+ if (options.onlyCountries.length || options.excludeCountries.length) {
1758
+ dialCodes.forEach((dialCode) => {
1759
+ dialCodeToIso2Map[dialCode] = dialCodeToIso2Map[dialCode].filter(Boolean);
1760
+ });
1761
+ }
1762
+ for (const c of countries) {
1763
+ if (c.areaCodes) {
1764
+ const rootIso2Code = dialCodeToIso2Map[c.dialCode][0];
1765
+ for (const areaCode of c.areaCodes) {
1766
+ for (let k = 1; k < areaCode.length; k++) {
1767
+ const partialAreaCode = areaCode.substring(0, k);
1768
+ const partialDialCode = c.dialCode + partialAreaCode;
1769
+ _addToDialCodeMap(rootIso2Code, partialDialCode);
1770
+ _addToDialCodeMap(c.iso2, partialDialCode);
1771
+ }
1772
+ _addToDialCodeMap(c.iso2, c.dialCode + areaCode);
1773
+ }
1774
+ }
1775
+ }
1776
+ return { dialCodes, dialCodeMaxLen, dialCodeToIso2Map };
1777
+ }
1778
+ function sortCountries(countries, options) {
1779
+ if (options.countryOrder) {
1780
+ options.countryOrder = options.countryOrder.map((iso2) => iso2.toLowerCase());
1781
+ }
1782
+ countries.sort((a, b) => {
1783
+ const { countryOrder } = options;
1784
+ if (countryOrder) {
1785
+ const aIndex = countryOrder.indexOf(a.iso2);
1786
+ const bIndex = countryOrder.indexOf(b.iso2);
1787
+ const aIndexExists = aIndex > -1;
1788
+ const bIndexExists = bIndex > -1;
1789
+ if (aIndexExists || bIndexExists) {
1790
+ if (aIndexExists && bIndexExists) {
1791
+ return aIndex - bIndex;
1792
+ }
1793
+ return aIndexExists ? -1 : 1;
1794
+ }
1795
+ }
1796
+ return a.name.localeCompare(b.name);
1797
+ });
1798
+ }
1799
+ function cacheSearchTokens(countries) {
1800
+ for (const c of countries) {
1801
+ c.normalisedName = normaliseString(c.name);
1802
+ c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1803
+ c.dialCodePlus = `+${c.dialCode}`;
1804
+ }
1805
+ }
1806
+
1807
+ // src/js/modules/format/formatting.ts
1808
+ function beforeSetNumber(fullNumber, dialCode, separateDialCode, selectedCountryData) {
1809
+ let number = fullNumber;
1810
+ if (separateDialCode) {
1811
+ if (dialCode) {
1812
+ dialCode = `+${selectedCountryData.dialCode}`;
1813
+ const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
1814
+ number = number.substring(start);
1815
+ }
1816
+ }
1817
+ return number;
1818
+ }
1819
+ function formatNumberAsYouType(fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) {
1820
+ const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData.iso2) : fullNumber;
1821
+ const { dialCode } = selectedCountryData;
1822
+ if (separateDialCode && telInputValue.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
1823
+ const afterDialCode = result.split(`+${dialCode}`)[1] || "";
1824
+ return afterDialCode.trim();
1825
+ }
1826
+ return result;
1827
+ }
1828
+
1829
+ // src/js/modules/format/caret.ts
1830
+ function translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
1831
+ if (prevCaretPos === 0 && !isDeleteForwards) {
1832
+ return 0;
1833
+ }
1834
+ let relevantCharCount = 0;
1835
+ for (let i = 0; i < formattedValue.length; i++) {
1836
+ if (/[+0-9]/.test(formattedValue[i])) {
1837
+ relevantCharCount++;
1838
+ }
1839
+ if (relevantCharCount === relevantChars && !isDeleteForwards) {
1840
+ return i + 1;
1841
+ }
1842
+ if (isDeleteForwards && relevantCharCount === relevantChars + 1) {
1843
+ return i;
1844
+ }
1845
+ }
1846
+ return formattedValue.length;
1847
+ }
1848
+
1849
+ // src/js/modules/data/nanp-regionless.ts
1679
1850
  var regionlessNanpNumbers = [
1680
1851
  "800",
1681
1852
  "822",
@@ -1695,8 +1866,6 @@ var regionlessNanpNumbers = [
1695
1866
  "888",
1696
1867
  "889"
1697
1868
  ];
1698
- var getNumeric = (s) => s.replace(/\D/g, "");
1699
- var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1700
1869
  var isRegionlessNanp = (number) => {
1701
1870
  const numeric = getNumeric(number);
1702
1871
  if (numeric.charAt(0) === "1") {
@@ -1705,34 +1874,14 @@ var isRegionlessNanp = (number) => {
1705
1874
  }
1706
1875
  return false;
1707
1876
  };
1708
- var translateCursorPosition = (relevantChars, formattedValue, prevCaretPos, isDeleteForwards) => {
1709
- if (prevCaretPos === 0 && !isDeleteForwards) {
1710
- return 0;
1711
- }
1712
- let count = 0;
1713
- for (let i = 0; i < formattedValue.length; i++) {
1714
- if (/[+0-9]/.test(formattedValue[i])) {
1715
- count++;
1716
- }
1717
- if (count === relevantChars && !isDeleteForwards) {
1718
- return i + 1;
1719
- }
1720
- if (isDeleteForwards && count === relevantChars + 1) {
1721
- return i;
1722
- }
1723
- }
1724
- return formattedValue.length;
1725
- };
1726
- var createEl = (tagName, attrs, container) => {
1727
- const el = document.createElement(tagName);
1728
- if (attrs) {
1729
- Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1730
- }
1731
- if (container) {
1732
- container.appendChild(el);
1733
- }
1734
- return el;
1735
- };
1877
+
1878
+ // src/js/intl-tel-input.ts
1879
+ for (const c of data_default) {
1880
+ c.name = en_default[c.iso2];
1881
+ }
1882
+ var id = 0;
1883
+ var iso2Set = new Set(data_default.map((c) => c.iso2));
1884
+ var isIso2 = (val) => iso2Set.has(val);
1736
1885
  var forEachInstance = (method, ...args) => {
1737
1886
  const { instances } = intlTelInput;
1738
1887
  Object.values(instances).forEach((instance) => instance[method](...args));
@@ -1752,23 +1901,7 @@ var Iti = class _Iti {
1752
1901
  this.options = Object.assign({}, defaults, customOptions);
1753
1902
  this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1754
1903
  }
1755
- //* Can't be private as it's called from intlTelInput convenience wrapper.
1756
- _init() {
1757
- if (this.options.useFullscreenPopup) {
1758
- this.options.fixDropdownWidth = false;
1759
- }
1760
- if (this.options.onlyCountries.length === 1) {
1761
- this.options.initialCountry = this.options.onlyCountries[0];
1762
- }
1763
- if (this.options.separateDialCode) {
1764
- this.options.nationalMode = false;
1765
- }
1766
- if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
1767
- this.options.nationalMode = false;
1768
- }
1769
- if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
1770
- this.options.dropdownContainer = document.body;
1771
- }
1904
+ _detectEnvironmentAndLayout() {
1772
1905
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1773
1906
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1774
1907
  this.telInput.dir = "ltr";
@@ -1781,7 +1914,8 @@ var Iti = class _Iti {
1781
1914
  this.originalPaddingLeft = this.telInput.style.paddingLeft;
1782
1915
  }
1783
1916
  }
1784
- this.options.i18n = { ...en_default, ...this.options.i18n };
1917
+ }
1918
+ _createInitPromises() {
1785
1919
  const autoCountryPromise = new Promise((resolve, reject) => {
1786
1920
  this.resolveAutoCountryPromise = resolve;
1787
1921
  this.rejectAutoCountryPromise = reject;
@@ -1791,6 +1925,12 @@ var Iti = class _Iti {
1791
1925
  this.rejectUtilsScriptPromise = reject;
1792
1926
  });
1793
1927
  this.promise = Promise.all([autoCountryPromise, utilsScriptPromise]);
1928
+ }
1929
+ //* Can't be private as it's called from intlTelInput convenience wrapper.
1930
+ _init() {
1931
+ applyOptionSideEffects(this.options);
1932
+ this._detectEnvironmentAndLayout();
1933
+ this._createInitPromises();
1794
1934
  this.selectedCountryData = {};
1795
1935
  this._processCountryData();
1796
1936
  this._generateMarkup();
@@ -1803,139 +1943,37 @@ var Iti = class _Iti {
1803
1943
  //********************
1804
1944
  //* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
1805
1945
  _processCountryData() {
1806
- this._processAllCountries();
1807
- this._processDialCodes();
1808
- this._translateCountryNames();
1809
- this._sortCountries();
1946
+ this.countries = processAllCountries(this.options);
1947
+ const dialRes = processDialCodes(this.countries, this.options);
1948
+ this.dialCodes = dialRes.dialCodes;
1949
+ this.dialCodeMaxLen = dialRes.dialCodeMaxLen;
1950
+ this.dialCodeToIso2Map = dialRes.dialCodeToIso2Map;
1951
+ translateCountryNames(this.countries, this.options);
1952
+ sortCountries(this.countries, this.options);
1810
1953
  this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
1811
- this._cacheSearchTokens();
1812
- }
1813
- //* Precompute and cache country search tokens to speed up filtering
1814
- _cacheSearchTokens() {
1815
- for (const c of this.countries) {
1816
- c.normalisedName = normaliseString(c.name);
1817
- c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1818
- c.dialCodePlus = `+${c.dialCode}`;
1819
- }
1820
- }
1821
- //* Sort countries by countryOrder option (if present), then name.
1822
- _sortCountries() {
1823
- if (this.options.countryOrder) {
1824
- this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
1825
- }
1826
- this.countries.sort((a, b) => {
1827
- const { countryOrder } = this.options;
1828
- if (countryOrder) {
1829
- const aIndex = countryOrder.indexOf(a.iso2);
1830
- const bIndex = countryOrder.indexOf(b.iso2);
1831
- const aIndexExists = aIndex > -1;
1832
- const bIndexExists = bIndex > -1;
1833
- if (aIndexExists || bIndexExists) {
1834
- if (aIndexExists && bIndexExists) {
1835
- return aIndex - bIndex;
1836
- }
1837
- return aIndexExists ? -1 : 1;
1838
- }
1839
- }
1840
- return a.name.localeCompare(b.name);
1841
- });
1842
- }
1843
- //* Add a dial code to this.dialCodeToIso2Map.
1844
- _addToDialCodeMap(iso2, dialCode, priority) {
1845
- if (!iso2 || !dialCode) {
1846
- return;
1847
- }
1848
- if (dialCode.length > this.dialCodeMaxLen) {
1849
- this.dialCodeMaxLen = dialCode.length;
1850
- }
1851
- if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1852
- this.dialCodeToIso2Map[dialCode] = [];
1853
- }
1854
- const iso2List = this.dialCodeToIso2Map[dialCode];
1855
- if (iso2List.includes(iso2)) {
1856
- return;
1857
- }
1858
- const index = priority !== void 0 ? priority : iso2List.length;
1859
- iso2List[index] = iso2;
1860
- }
1861
- //* Process onlyCountries or excludeCountries array if present.
1862
- _processAllCountries() {
1863
- const { onlyCountries, excludeCountries } = this.options;
1864
- if (onlyCountries.length) {
1865
- const lowerCaseOnlyCountries = onlyCountries.map(
1866
- (country) => country.toLowerCase()
1867
- );
1868
- this.countries = data_default.filter(
1869
- (country) => lowerCaseOnlyCountries.includes(country.iso2)
1870
- );
1871
- } else if (excludeCountries.length) {
1872
- const lowerCaseExcludeCountries = excludeCountries.map(
1873
- (country) => country.toLowerCase()
1874
- );
1875
- this.countries = data_default.filter(
1876
- (country) => !lowerCaseExcludeCountries.includes(country.iso2)
1877
- );
1878
- } else {
1879
- this.countries = data_default;
1880
- }
1881
- }
1882
- //* Translate Countries by object literal provided on config.
1883
- _translateCountryNames() {
1884
- for (const c of this.countries) {
1885
- const iso2 = c.iso2.toLowerCase();
1886
- if (this.options.i18n.hasOwnProperty(iso2)) {
1887
- c.name = this.options.i18n[iso2];
1888
- }
1889
- }
1890
- }
1891
- //* Generate this.dialCodes and this.dialCodeToIso2Map.
1892
- _processDialCodes() {
1893
- this.dialCodes = /* @__PURE__ */ new Set();
1894
- this.dialCodeMaxLen = 0;
1895
- this.dialCodeToIso2Map = {};
1896
- for (const c of this.countries) {
1897
- if (!this.dialCodes.has(c.dialCode)) {
1898
- this.dialCodes.add(c.dialCode);
1899
- }
1900
- this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1901
- }
1902
- if (this.options.onlyCountries.length || this.options.excludeCountries.length) {
1903
- this.dialCodes.forEach((dialCode) => {
1904
- this.dialCodeToIso2Map[dialCode] = this.dialCodeToIso2Map[dialCode].filter(Boolean);
1905
- });
1906
- }
1907
- for (const c of this.countries) {
1908
- if (c.areaCodes) {
1909
- const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1910
- for (const areaCode of c.areaCodes) {
1911
- for (let k = 1; k < areaCode.length; k++) {
1912
- const partialAreaCode = areaCode.substring(0, k);
1913
- const partialDialCode = c.dialCode + partialAreaCode;
1914
- this._addToDialCodeMap(rootIso2Code, partialDialCode);
1915
- this._addToDialCodeMap(c.iso2, partialDialCode);
1916
- }
1917
- this._addToDialCodeMap(c.iso2, c.dialCode + areaCode);
1918
- }
1919
- }
1920
- }
1954
+ cacheSearchTokens(this.countries);
1921
1955
  }
1922
1956
  //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
1923
1957
  _generateMarkup() {
1958
+ this._prepareTelInput();
1959
+ const wrapper = this._createWrapperAndInsert();
1960
+ this._maybeBuildCountryContainer(wrapper);
1961
+ wrapper.appendChild(this.telInput);
1962
+ this._maybeUpdateInputPaddingAndReveal();
1963
+ this._maybeBuildHiddenInputs(wrapper);
1964
+ }
1965
+ _prepareTelInput() {
1924
1966
  this.telInput.classList.add("iti__tel-input");
1925
1967
  if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1926
1968
  this.telInput.setAttribute("autocomplete", "off");
1927
1969
  }
1970
+ }
1971
+ _createWrapperAndInsert() {
1928
1972
  const {
1929
1973
  allowDropdown,
1930
- separateDialCode,
1931
1974
  showFlags,
1932
1975
  containerClass,
1933
- hiddenInput,
1934
- dropdownContainer,
1935
- fixDropdownWidth,
1936
- useFullscreenPopup,
1937
- countrySearch,
1938
- i18n
1976
+ useFullscreenPopup
1939
1977
  } = this.options;
1940
1978
  const parentClasses = _Iti._buildClassNames({
1941
1979
  "iti": true,
@@ -1946,6 +1984,14 @@ var Iti = class _Iti {
1946
1984
  });
1947
1985
  const wrapper = createEl("div", { class: parentClasses });
1948
1986
  this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
1987
+ return wrapper;
1988
+ }
1989
+ _maybeBuildCountryContainer(wrapper) {
1990
+ const {
1991
+ allowDropdown,
1992
+ separateDialCode,
1993
+ showFlags
1994
+ } = this.options;
1949
1995
  if (allowDropdown || showFlags || separateDialCode) {
1950
1996
  this.countryContainer = createEl(
1951
1997
  "div",
@@ -2006,119 +2052,138 @@ var Iti = class _Iti {
2006
2052
  );
2007
2053
  }
2008
2054
  if (allowDropdown) {
2009
- const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
2010
- this.dropdownContent = createEl("div", {
2011
- id: `iti-${this.id}__dropdown-content`,
2012
- class: `iti__dropdown-content iti__hide ${extraClasses}`,
2013
- role: "dialog",
2014
- "aria-modal": "true"
2015
- });
2016
- if (countrySearch) {
2017
- const searchWrapper = createEl(
2018
- "div",
2019
- { class: "iti__search-input-wrapper" },
2020
- this.dropdownContent
2021
- );
2022
- this.searchIcon = createEl(
2023
- "span",
2024
- {
2025
- class: "iti__search-icon",
2026
- "aria-hidden": "true"
2027
- },
2028
- searchWrapper
2029
- );
2030
- this.searchIcon.innerHTML = `
2031
- <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
2032
- <circle cx="11" cy="11" r="7" />
2033
- <line x1="21" y1="21" x2="16.65" y2="16.65" />
2034
- </svg>`;
2035
- this.searchInput = createEl(
2036
- "input",
2037
- {
2038
- id: `iti-${this.id}__search-input`,
2039
- // Chrome says inputs need either a name or an id
2040
- type: "search",
2041
- class: "iti__search-input",
2042
- placeholder: i18n.searchPlaceholder,
2043
- // 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
2044
- role: "combobox",
2045
- "aria-expanded": "true",
2046
- "aria-label": i18n.searchPlaceholder,
2047
- "aria-controls": `iti-${this.id}__country-listbox`,
2048
- "aria-autocomplete": "list",
2049
- "autocomplete": "off"
2050
- },
2051
- searchWrapper
2052
- );
2053
- this.searchClearButton = createEl(
2054
- "button",
2055
- {
2056
- type: "button",
2057
- class: "iti__search-clear iti__hide",
2058
- "aria-label": i18n.clearSearchAriaLabel,
2059
- tabindex: "-1"
2060
- },
2061
- searchWrapper
2062
- );
2063
- const maskId = `iti-${this.id}-clear-mask`;
2064
- this.searchClearButton.innerHTML = `
2065
- <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
2066
- <mask id="${maskId}" maskUnits="userSpaceOnUse">
2067
- <rect width="16" height="16" fill="white" />
2068
- <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" />
2069
- </mask>
2070
- <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${maskId})" />
2071
- </svg>`;
2072
- this.searchResultsA11yText = createEl(
2073
- "span",
2074
- { class: "iti__a11y-text" },
2075
- this.dropdownContent
2076
- );
2077
- this.searchNoResults = createEl(
2078
- "div",
2079
- {
2080
- class: "iti__no-results iti__hide",
2081
- "aria-hidden": "true"
2082
- // all a11y messaging happens in this.searchResultsA11yText
2083
- },
2084
- this.dropdownContent
2085
- );
2086
- this.searchNoResults.textContent = i18n.zeroSearchResults;
2087
- }
2088
- this.countryList = createEl(
2089
- "ul",
2090
- {
2091
- class: "iti__country-list",
2092
- id: `iti-${this.id}__country-listbox`,
2093
- role: "listbox",
2094
- "aria-label": i18n.countryListAriaLabel
2095
- },
2096
- this.dropdownContent
2097
- );
2098
- this._appendListItems();
2099
- if (countrySearch) {
2100
- this._updateSearchResultsA11yText();
2101
- }
2102
- if (dropdownContainer) {
2103
- const dropdownClasses = _Iti._buildClassNames({
2104
- "iti": true,
2105
- "iti--container": true,
2106
- "iti--fullscreen-popup": useFullscreenPopup,
2107
- "iti--inline-dropdown": !useFullscreenPopup,
2108
- [containerClass]: Boolean(containerClass)
2109
- });
2110
- this.dropdown = createEl("div", { class: dropdownClasses });
2111
- this.dropdown.appendChild(this.dropdownContent);
2112
- } else {
2113
- this.countryContainer.appendChild(this.dropdownContent);
2114
- }
2055
+ this._buildDropdownContent();
2115
2056
  }
2116
2057
  }
2117
- wrapper.appendChild(this.telInput);
2058
+ }
2059
+ _buildDropdownContent() {
2060
+ const {
2061
+ fixDropdownWidth,
2062
+ useFullscreenPopup,
2063
+ countrySearch,
2064
+ i18n,
2065
+ dropdownContainer,
2066
+ containerClass
2067
+ } = this.options;
2068
+ const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
2069
+ this.dropdownContent = createEl("div", {
2070
+ id: `iti-${this.id}__dropdown-content`,
2071
+ class: `iti__dropdown-content iti__hide ${extraClasses}`,
2072
+ role: "dialog",
2073
+ "aria-modal": "true"
2074
+ });
2075
+ if (countrySearch) {
2076
+ this._buildSearchUI();
2077
+ }
2078
+ this.countryList = createEl(
2079
+ "ul",
2080
+ {
2081
+ class: "iti__country-list",
2082
+ id: `iti-${this.id}__country-listbox`,
2083
+ role: "listbox",
2084
+ "aria-label": i18n.countryListAriaLabel
2085
+ },
2086
+ this.dropdownContent
2087
+ );
2088
+ this._appendListItems();
2089
+ if (countrySearch) {
2090
+ this._updateSearchResultsA11yText();
2091
+ }
2092
+ if (dropdownContainer) {
2093
+ const dropdownClasses = _Iti._buildClassNames({
2094
+ "iti": true,
2095
+ "iti--container": true,
2096
+ "iti--fullscreen-popup": useFullscreenPopup,
2097
+ "iti--inline-dropdown": !useFullscreenPopup,
2098
+ [containerClass]: Boolean(containerClass)
2099
+ });
2100
+ this.dropdown = createEl("div", { class: dropdownClasses });
2101
+ this.dropdown.appendChild(this.dropdownContent);
2102
+ } else {
2103
+ this.countryContainer.appendChild(this.dropdownContent);
2104
+ }
2105
+ }
2106
+ _buildSearchUI() {
2107
+ const { i18n } = this.options;
2108
+ const searchWrapper = createEl(
2109
+ "div",
2110
+ { class: "iti__search-input-wrapper" },
2111
+ this.dropdownContent
2112
+ );
2113
+ this.searchIcon = createEl(
2114
+ "span",
2115
+ {
2116
+ class: "iti__search-icon",
2117
+ "aria-hidden": "true"
2118
+ },
2119
+ searchWrapper
2120
+ );
2121
+ this.searchIcon.innerHTML = `
2122
+ <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
2123
+ <circle cx="11" cy="11" r="7" />
2124
+ <line x1="21" y1="21" x2="16.65" y2="16.65" />
2125
+ </svg>`;
2126
+ this.searchInput = createEl(
2127
+ "input",
2128
+ {
2129
+ id: `iti-${this.id}__search-input`,
2130
+ // Chrome says inputs need either a name or an id
2131
+ type: "search",
2132
+ class: "iti__search-input",
2133
+ placeholder: i18n.searchPlaceholder,
2134
+ // 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
2135
+ role: "combobox",
2136
+ "aria-expanded": "true",
2137
+ "aria-label": i18n.searchPlaceholder,
2138
+ "aria-controls": `iti-${this.id}__country-listbox`,
2139
+ "aria-autocomplete": "list",
2140
+ "autocomplete": "off"
2141
+ },
2142
+ searchWrapper
2143
+ );
2144
+ this.searchClearButton = createEl(
2145
+ "button",
2146
+ {
2147
+ type: "button",
2148
+ class: "iti__search-clear iti__hide",
2149
+ "aria-label": i18n.clearSearchAriaLabel,
2150
+ tabindex: "-1"
2151
+ },
2152
+ searchWrapper
2153
+ );
2154
+ const maskId = `iti-${this.id}-clear-mask`;
2155
+ this.searchClearButton.innerHTML = `
2156
+ <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
2157
+ <mask id="${maskId}" maskUnits="userSpaceOnUse">
2158
+ <rect width="16" height="16" fill="white" />
2159
+ <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" />
2160
+ </mask>
2161
+ <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${maskId})" />
2162
+ </svg>`;
2163
+ this.searchResultsA11yText = createEl(
2164
+ "span",
2165
+ { class: "iti__a11y-text" },
2166
+ this.dropdownContent
2167
+ );
2168
+ this.searchNoResults = createEl(
2169
+ "div",
2170
+ {
2171
+ class: "iti__no-results iti__hide",
2172
+ "aria-hidden": "true"
2173
+ // all a11y messaging happens in this.searchResultsA11yText
2174
+ },
2175
+ this.dropdownContent
2176
+ );
2177
+ this.searchNoResults.textContent = i18n.zeroSearchResults;
2178
+ }
2179
+ _maybeUpdateInputPaddingAndReveal() {
2118
2180
  if (this.countryContainer) {
2119
2181
  this._updateInputPadding();
2120
2182
  this.countryContainer.classList.remove("iti__v-hide");
2121
2183
  }
2184
+ }
2185
+ _maybeBuildHiddenInputs(wrapper) {
2186
+ const { hiddenInput } = this.options;
2122
2187
  if (hiddenInput) {
2123
2188
  const telInputName = this.telInput.getAttribute("name") || "";
2124
2189
  const names = hiddenInput(telInputName);
@@ -2192,14 +2257,13 @@ var Iti = class _Iti {
2192
2257
  this._updateCountryFromNumber(val);
2193
2258
  } else if (!isAutoCountry || overrideAutoCountry) {
2194
2259
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
2195
- const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
2196
- if (isValidInitialCountry) {
2260
+ if (isIso2(lowerInitialCountry)) {
2197
2261
  this._setCountry(lowerInitialCountry);
2198
2262
  } else {
2199
2263
  if (dialCode && isRegionlessNanpNumber) {
2200
2264
  this._setCountry("us");
2201
2265
  } else {
2202
- this._setCountry();
2266
+ this._setCountry("");
2203
2267
  }
2204
2268
  }
2205
2269
  }
@@ -2302,8 +2366,7 @@ var Iti = class _Iti {
2302
2366
  this.options.geoIpLookup(
2303
2367
  (iso2 = "") => {
2304
2368
  const iso2Lower = iso2.toLowerCase();
2305
- const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
2306
- if (isValidIso2) {
2369
+ if (isIso2(iso2Lower)) {
2307
2370
  intlTelInput.autoCountry = iso2Lower;
2308
2371
  setTimeout(() => forEachInstance("handleAutoCountry"));
2309
2372
  } else {
@@ -2326,6 +2389,11 @@ var Iti = class _Iti {
2326
2389
  }
2327
2390
  //* Initialize the tel input listeners.
2328
2391
  _initTelInputListeners() {
2392
+ this._bindInputListener();
2393
+ this._maybeBindKeydownListener();
2394
+ this._maybeBindPasteListener();
2395
+ }
2396
+ _bindInputListener() {
2329
2397
  const { strictMode, formatAsYouType, separateDialCode, allowDropdown, countrySearch } = this.options;
2330
2398
  let userOverrideFormatting = false;
2331
2399
  if (/\p{L}/u.test(this.telInput.value)) {
@@ -2356,13 +2424,23 @@ var Iti = class _Iti {
2356
2424
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2357
2425
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2358
2426
  const isDeleteForwards = e?.inputType === "deleteContentForward";
2359
- const formattedValue = this._formatNumberAsYouType();
2427
+ const fullNumber = this._getFullNumber();
2428
+ const formattedValue = formatNumberAsYouType(
2429
+ fullNumber,
2430
+ this.telInput.value,
2431
+ intlTelInput.utils,
2432
+ this.selectedCountryData,
2433
+ this.options.separateDialCode
2434
+ );
2360
2435
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2361
2436
  this.telInput.value = formattedValue;
2362
2437
  this.telInput.setSelectionRange(newCaretPos, newCaretPos);
2363
2438
  }
2364
2439
  };
2365
2440
  this.telInput.addEventListener("input", this._handleInputEvent);
2441
+ }
2442
+ _maybeBindKeydownListener() {
2443
+ const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.options;
2366
2444
  if (strictMode || separateDialCode) {
2367
2445
  this._handleKeydownEvent = (e) => {
2368
2446
  if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
@@ -2392,6 +2470,48 @@ var Iti = class _Iti {
2392
2470
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2393
2471
  }
2394
2472
  }
2473
+ _maybeBindPasteListener() {
2474
+ if (this.options.strictMode) {
2475
+ this._handlePasteEvent = (e) => {
2476
+ e.preventDefault();
2477
+ const input = this.telInput;
2478
+ const selStart = input.selectionStart;
2479
+ const selEnd = input.selectionEnd;
2480
+ const before = input.value.slice(0, selStart);
2481
+ const after = input.value.slice(selEnd);
2482
+ const iso2 = this.selectedCountryData.iso2;
2483
+ const pasted = e.clipboardData.getData("text");
2484
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2485
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2486
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2487
+ const hasLeadingPlus = allowedChars.startsWith("+");
2488
+ const numerics = allowedChars.replace(/\+/g, "");
2489
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2490
+ let newVal = before + sanitised + after;
2491
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
2492
+ while (coreNumber.length === 0 && newVal.length > 0) {
2493
+ newVal = newVal.slice(0, -1);
2494
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
2495
+ }
2496
+ if (!coreNumber) {
2497
+ return;
2498
+ }
2499
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2500
+ if (input.selectionEnd === input.value.length) {
2501
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2502
+ newVal = newVal.slice(0, newVal.length - trimLength);
2503
+ } else {
2504
+ return;
2505
+ }
2506
+ }
2507
+ input.value = newVal;
2508
+ const caretPos = selStart + sanitised.length;
2509
+ input.setSelectionRange(caretPos, caretPos);
2510
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2511
+ };
2512
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2513
+ }
2514
+ }
2395
2515
  //* Adhere to the input's maxlength attr.
2396
2516
  _cap(number) {
2397
2517
  const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
@@ -2545,43 +2665,14 @@ var Iti = class _Iti {
2545
2665
  }
2546
2666
  //* Country search enabled: Filter the countries according to the search query.
2547
2667
  _filterCountries(query) {
2548
- let noCountriesAddedYet = true;
2549
2668
  this.countryList.innerHTML = "";
2550
- const normalisedQuery = normaliseString(query);
2551
2669
  let matchedCountries;
2552
2670
  if (query === "") {
2553
2671
  matchedCountries = this.countries;
2554
2672
  } else {
2555
- const iso2Matches = [];
2556
- const nameStartWith = [];
2557
- const nameContains = [];
2558
- const dialCodeMatches = [];
2559
- const dialCodeContains = [];
2560
- const initialsMatches = [];
2561
- for (const c of this.countries) {
2562
- if (c.iso2 === normalisedQuery) {
2563
- iso2Matches.push(c);
2564
- } else if (c.normalisedName.startsWith(normalisedQuery)) {
2565
- nameStartWith.push(c);
2566
- } else if (c.normalisedName.includes(normalisedQuery)) {
2567
- nameContains.push(c);
2568
- } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2569
- dialCodeMatches.push(c);
2570
- } else if (c.dialCodePlus.includes(normalisedQuery)) {
2571
- dialCodeContains.push(c);
2572
- } else if (c.initials.includes(normalisedQuery)) {
2573
- initialsMatches.push(c);
2574
- }
2575
- }
2576
- matchedCountries = [
2577
- ...iso2Matches.sort((a, b) => a.priority - b.priority),
2578
- ...nameStartWith.sort((a, b) => a.priority - b.priority),
2579
- ...nameContains.sort((a, b) => a.priority - b.priority),
2580
- ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2581
- ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2582
- ...initialsMatches.sort((a, b) => a.priority - b.priority)
2583
- ];
2673
+ matchedCountries = this._getMatchedCountries(query);
2584
2674
  }
2675
+ let noCountriesAddedYet = true;
2585
2676
  for (const c of matchedCountries) {
2586
2677
  const listItem = c.nodeById[this.id];
2587
2678
  if (listItem) {
@@ -2603,6 +2694,38 @@ var Iti = class _Iti {
2603
2694
  this.countryList.scrollTop = 0;
2604
2695
  this._updateSearchResultsA11yText();
2605
2696
  }
2697
+ _getMatchedCountries(query) {
2698
+ const normalisedQuery = normaliseString(query);
2699
+ const iso2Matches = [];
2700
+ const nameStartWith = [];
2701
+ const nameContains = [];
2702
+ const dialCodeMatches = [];
2703
+ const dialCodeContains = [];
2704
+ const initialsMatches = [];
2705
+ for (const c of this.countries) {
2706
+ if (c.iso2 === normalisedQuery) {
2707
+ iso2Matches.push(c);
2708
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2709
+ nameStartWith.push(c);
2710
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2711
+ nameContains.push(c);
2712
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2713
+ dialCodeMatches.push(c);
2714
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2715
+ dialCodeContains.push(c);
2716
+ } else if (c.initials.includes(normalisedQuery)) {
2717
+ initialsMatches.push(c);
2718
+ }
2719
+ }
2720
+ return [
2721
+ ...iso2Matches.sort((a, b) => a.priority - b.priority),
2722
+ ...nameStartWith.sort((a, b) => a.priority - b.priority),
2723
+ ...nameContains.sort((a, b) => a.priority - b.priority),
2724
+ ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2725
+ ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2726
+ ...initialsMatches.sort((a, b) => a.priority - b.priority)
2727
+ ];
2728
+ }
2606
2729
  //* Update search results text (for a11y).
2607
2730
  _updateSearchResultsA11yText() {
2608
2731
  const { i18n } = this.options;
@@ -2733,24 +2856,12 @@ var Iti = class _Iti {
2733
2856
  this.highlightedItem.focus();
2734
2857
  }
2735
2858
  }
2736
- //* Find the country data for the given iso2 code
2737
- //* 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
2738
- _getCountryData(iso2, allowFail) {
2739
- const country = this.countryByIso2.get(iso2);
2740
- if (country) {
2741
- return country;
2742
- }
2743
- if (allowFail) {
2744
- return null;
2745
- }
2746
- throw new Error(`No country data for '${iso2}'`);
2747
- }
2748
2859
  //* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
2749
2860
  //* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
2750
2861
  _setCountry(iso2) {
2751
2862
  const { separateDialCode, showFlags, i18n } = this.options;
2752
2863
  const prevIso2 = this.selectedCountryData.iso2 || "";
2753
- this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) || {} : {};
2864
+ this.selectedCountryData = iso2 ? this.countryByIso2.get(iso2) : {};
2754
2865
  if (this.selectedCountryData.iso2) {
2755
2866
  this.defaultCountry = this.selectedCountryData.iso2;
2756
2867
  }
@@ -2869,11 +2980,11 @@ var Iti = class _Iti {
2869
2980
  }
2870
2981
  //* Called when the user selects a list item from the dropdown.
2871
2982
  _selectListItem(listItem) {
2872
- const countryChanged = this._setCountry(
2873
- listItem.getAttribute("data-country-code")
2874
- );
2983
+ const iso2 = listItem.getAttribute("data-country-code");
2984
+ const countryChanged = this._setCountry(iso2);
2875
2985
  this._closeDropdown();
2876
- this._updateDialCode(listItem.getAttribute("data-dial-code"));
2986
+ const dialCode = listItem.getAttribute("data-dial-code");
2987
+ this._updateDialCode(dialCode);
2877
2988
  if (this.options.formatOnDisplay) {
2878
2989
  this._updateValFromNumber(this.telInput.value);
2879
2990
  }
@@ -2996,32 +3107,19 @@ var Iti = class _Iti {
2996
3107
  }
2997
3108
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
2998
3109
  _beforeSetNumber(fullNumber) {
2999
- let number = fullNumber;
3000
- if (this.options.separateDialCode) {
3001
- let dialCode = this._getDialCode(number);
3002
- if (dialCode) {
3003
- dialCode = `+${this.selectedCountryData.dialCode}`;
3004
- const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3005
- number = number.substring(start);
3006
- }
3007
- }
3110
+ const dialCode = this._getDialCode(fullNumber);
3111
+ const number = beforeSetNumber(
3112
+ fullNumber,
3113
+ dialCode,
3114
+ this.options.separateDialCode,
3115
+ this.selectedCountryData
3116
+ );
3008
3117
  return this._cap(number);
3009
3118
  }
3010
3119
  //* Trigger the 'countrychange' event.
3011
3120
  _triggerCountryChange() {
3012
3121
  this._trigger("countrychange");
3013
3122
  }
3014
- //* Format the number as the user types.
3015
- _formatNumberAsYouType() {
3016
- const val = this._getFullNumber();
3017
- const result = intlTelInput.utils ? intlTelInput.utils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
3018
- const { dialCode } = this.selectedCountryData;
3019
- if (this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
3020
- const afterDialCode = result.split(`+${dialCode}`)[1] || "";
3021
- return afterDialCode.trim();
3022
- }
3023
- return result;
3024
- }
3025
3123
  //**************************
3026
3124
  //* SECRET PUBLIC METHODS
3027
3125
  //**************************
@@ -3079,6 +3177,9 @@ var Iti = class _Iti {
3079
3177
  if (this._handleKeydownEvent) {
3080
3178
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3081
3179
  }
3180
+ if (this._handlePasteEvent) {
3181
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3182
+ }
3082
3183
  this.telInput.removeAttribute("data-intl-tel-input-id");
3083
3184
  if (separateDialCode) {
3084
3185
  if (this.isRTL) {
@@ -3170,6 +3271,9 @@ var Iti = class _Iti {
3170
3271
  //* Update the selected country, and update the input val accordingly.
3171
3272
  setCountry(iso2) {
3172
3273
  const iso2Lower = iso2?.toLowerCase();
3274
+ if (!isIso2(iso2Lower)) {
3275
+ throw new Error(`Invalid country code: '${iso2Lower}'`);
3276
+ }
3173
3277
  const currentCountry = this.selectedCountryData.iso2;
3174
3278
  const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
3175
3279
  if (isCountryChange) {
@@ -3257,7 +3361,7 @@ var intlTelInput = Object.assign(
3257
3361
  attachUtils,
3258
3362
  startedLoadingUtilsScript: false,
3259
3363
  startedLoadingAutoCountry: false,
3260
- version: "25.10.6"
3364
+ version: "25.10.8"
3261
3365
  }
3262
3366
  );
3263
3367
  var intl_tel_input_default = intlTelInput;