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
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v25.10.6
2
+ * International Telephone Input v25.10.8
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -1647,11 +1647,7 @@ var factoryOutput = (() => {
1647
1647
  var allTranslations = { ...countries_default, ...interface_default };
1648
1648
  var en_default = allTranslations;
1649
1649
 
1650
- // src/js/intl-tel-input.ts
1651
- for (const c of data_default) {
1652
- c.name = en_default[c.iso2];
1653
- }
1654
- var id = 0;
1650
+ // src/js/modules/core/options.ts
1655
1651
  var mq = (q) => {
1656
1652
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(q).matches;
1657
1653
  };
@@ -1717,6 +1713,181 @@ var factoryOutput = (() => {
1717
1713
  //* The number type to enforce during validation.
1718
1714
  validationNumberTypes: ["MOBILE"]
1719
1715
  };
1716
+ function applyOptionSideEffects(o) {
1717
+ if (o.useFullscreenPopup) {
1718
+ o.fixDropdownWidth = false;
1719
+ }
1720
+ if (o.onlyCountries.length === 1) {
1721
+ o.initialCountry = o.onlyCountries[0];
1722
+ }
1723
+ if (o.separateDialCode) {
1724
+ o.nationalMode = false;
1725
+ }
1726
+ if (o.allowDropdown && !o.showFlags && !o.separateDialCode) {
1727
+ o.nationalMode = false;
1728
+ }
1729
+ if (o.useFullscreenPopup && !o.dropdownContainer) {
1730
+ o.dropdownContainer = document.body;
1731
+ }
1732
+ o.i18n = { ...en_default, ...o.i18n };
1733
+ }
1734
+
1735
+ // src/js/modules/utils/string.ts
1736
+ var getNumeric = (s) => s.replace(/\D/g, "");
1737
+ var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1738
+
1739
+ // src/js/modules/utils/dom.ts
1740
+ var createEl = (tagName, attrs, container) => {
1741
+ const el = document.createElement(tagName);
1742
+ if (attrs) {
1743
+ Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1744
+ }
1745
+ if (container) {
1746
+ container.appendChild(el);
1747
+ }
1748
+ return el;
1749
+ };
1750
+
1751
+ // src/js/modules/data/country-data.ts
1752
+ function processAllCountries(options) {
1753
+ const { onlyCountries, excludeCountries } = options;
1754
+ if (onlyCountries.length) {
1755
+ const lowerCaseOnlyCountries = onlyCountries.map((country) => country.toLowerCase());
1756
+ return data_default.filter((country) => lowerCaseOnlyCountries.includes(country.iso2));
1757
+ } else if (excludeCountries.length) {
1758
+ const lowerCaseExcludeCountries = excludeCountries.map((country) => country.toLowerCase());
1759
+ return data_default.filter((country) => !lowerCaseExcludeCountries.includes(country.iso2));
1760
+ }
1761
+ return data_default;
1762
+ }
1763
+ function translateCountryNames(countries, options) {
1764
+ for (const c of countries) {
1765
+ const iso2 = c.iso2.toLowerCase();
1766
+ if (options.i18n[iso2]) {
1767
+ c.name = options.i18n[iso2];
1768
+ }
1769
+ }
1770
+ }
1771
+ function processDialCodes(countries, options) {
1772
+ const dialCodes = /* @__PURE__ */ new Set();
1773
+ let dialCodeMaxLen = 0;
1774
+ const dialCodeToIso2Map = {};
1775
+ const _addToDialCodeMap = (iso2, dialCode, priority) => {
1776
+ if (!iso2 || !dialCode) {
1777
+ return;
1778
+ }
1779
+ if (dialCode.length > dialCodeMaxLen) {
1780
+ dialCodeMaxLen = dialCode.length;
1781
+ }
1782
+ if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1783
+ dialCodeToIso2Map[dialCode] = [];
1784
+ }
1785
+ const iso2List = dialCodeToIso2Map[dialCode];
1786
+ if (iso2List.includes(iso2)) {
1787
+ return;
1788
+ }
1789
+ const index = priority !== void 0 ? priority : iso2List.length;
1790
+ iso2List[index] = iso2;
1791
+ };
1792
+ for (const c of countries) {
1793
+ if (!dialCodes.has(c.dialCode)) {
1794
+ dialCodes.add(c.dialCode);
1795
+ }
1796
+ _addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1797
+ }
1798
+ if (options.onlyCountries.length || options.excludeCountries.length) {
1799
+ dialCodes.forEach((dialCode) => {
1800
+ dialCodeToIso2Map[dialCode] = dialCodeToIso2Map[dialCode].filter(Boolean);
1801
+ });
1802
+ }
1803
+ for (const c of countries) {
1804
+ if (c.areaCodes) {
1805
+ const rootIso2Code = dialCodeToIso2Map[c.dialCode][0];
1806
+ for (const areaCode of c.areaCodes) {
1807
+ for (let k = 1; k < areaCode.length; k++) {
1808
+ const partialAreaCode = areaCode.substring(0, k);
1809
+ const partialDialCode = c.dialCode + partialAreaCode;
1810
+ _addToDialCodeMap(rootIso2Code, partialDialCode);
1811
+ _addToDialCodeMap(c.iso2, partialDialCode);
1812
+ }
1813
+ _addToDialCodeMap(c.iso2, c.dialCode + areaCode);
1814
+ }
1815
+ }
1816
+ }
1817
+ return { dialCodes, dialCodeMaxLen, dialCodeToIso2Map };
1818
+ }
1819
+ function sortCountries(countries, options) {
1820
+ if (options.countryOrder) {
1821
+ options.countryOrder = options.countryOrder.map((iso2) => iso2.toLowerCase());
1822
+ }
1823
+ countries.sort((a, b) => {
1824
+ const { countryOrder } = options;
1825
+ if (countryOrder) {
1826
+ const aIndex = countryOrder.indexOf(a.iso2);
1827
+ const bIndex = countryOrder.indexOf(b.iso2);
1828
+ const aIndexExists = aIndex > -1;
1829
+ const bIndexExists = bIndex > -1;
1830
+ if (aIndexExists || bIndexExists) {
1831
+ if (aIndexExists && bIndexExists) {
1832
+ return aIndex - bIndex;
1833
+ }
1834
+ return aIndexExists ? -1 : 1;
1835
+ }
1836
+ }
1837
+ return a.name.localeCompare(b.name);
1838
+ });
1839
+ }
1840
+ function cacheSearchTokens(countries) {
1841
+ for (const c of countries) {
1842
+ c.normalisedName = normaliseString(c.name);
1843
+ c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1844
+ c.dialCodePlus = `+${c.dialCode}`;
1845
+ }
1846
+ }
1847
+
1848
+ // src/js/modules/format/formatting.ts
1849
+ function beforeSetNumber(fullNumber, dialCode, separateDialCode, selectedCountryData) {
1850
+ let number = fullNumber;
1851
+ if (separateDialCode) {
1852
+ if (dialCode) {
1853
+ dialCode = `+${selectedCountryData.dialCode}`;
1854
+ const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
1855
+ number = number.substring(start);
1856
+ }
1857
+ }
1858
+ return number;
1859
+ }
1860
+ function formatNumberAsYouType(fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) {
1861
+ const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData.iso2) : fullNumber;
1862
+ const { dialCode } = selectedCountryData;
1863
+ if (separateDialCode && telInputValue.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
1864
+ const afterDialCode = result.split(`+${dialCode}`)[1] || "";
1865
+ return afterDialCode.trim();
1866
+ }
1867
+ return result;
1868
+ }
1869
+
1870
+ // src/js/modules/format/caret.ts
1871
+ function translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
1872
+ if (prevCaretPos === 0 && !isDeleteForwards) {
1873
+ return 0;
1874
+ }
1875
+ let relevantCharCount = 0;
1876
+ for (let i = 0; i < formattedValue.length; i++) {
1877
+ if (/[+0-9]/.test(formattedValue[i])) {
1878
+ relevantCharCount++;
1879
+ }
1880
+ if (relevantCharCount === relevantChars && !isDeleteForwards) {
1881
+ return i + 1;
1882
+ }
1883
+ if (isDeleteForwards && relevantCharCount === relevantChars + 1) {
1884
+ return i;
1885
+ }
1886
+ }
1887
+ return formattedValue.length;
1888
+ }
1889
+
1890
+ // src/js/modules/data/nanp-regionless.ts
1720
1891
  var regionlessNanpNumbers = [
1721
1892
  "800",
1722
1893
  "822",
@@ -1736,8 +1907,6 @@ var factoryOutput = (() => {
1736
1907
  "888",
1737
1908
  "889"
1738
1909
  ];
1739
- var getNumeric = (s) => s.replace(/\D/g, "");
1740
- var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1741
1910
  var isRegionlessNanp = (number) => {
1742
1911
  const numeric = getNumeric(number);
1743
1912
  if (numeric.charAt(0) === "1") {
@@ -1746,34 +1915,14 @@ var factoryOutput = (() => {
1746
1915
  }
1747
1916
  return false;
1748
1917
  };
1749
- var translateCursorPosition = (relevantChars, formattedValue, prevCaretPos, isDeleteForwards) => {
1750
- if (prevCaretPos === 0 && !isDeleteForwards) {
1751
- return 0;
1752
- }
1753
- let count = 0;
1754
- for (let i = 0; i < formattedValue.length; i++) {
1755
- if (/[+0-9]/.test(formattedValue[i])) {
1756
- count++;
1757
- }
1758
- if (count === relevantChars && !isDeleteForwards) {
1759
- return i + 1;
1760
- }
1761
- if (isDeleteForwards && count === relevantChars + 1) {
1762
- return i;
1763
- }
1764
- }
1765
- return formattedValue.length;
1766
- };
1767
- var createEl = (tagName, attrs, container) => {
1768
- const el = document.createElement(tagName);
1769
- if (attrs) {
1770
- Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1771
- }
1772
- if (container) {
1773
- container.appendChild(el);
1774
- }
1775
- return el;
1776
- };
1918
+
1919
+ // src/js/intl-tel-input.ts
1920
+ for (const c of data_default) {
1921
+ c.name = en_default[c.iso2];
1922
+ }
1923
+ var id = 0;
1924
+ var iso2Set = new Set(data_default.map((c) => c.iso2));
1925
+ var isIso2 = (val) => iso2Set.has(val);
1777
1926
  var forEachInstance = (method, ...args) => {
1778
1927
  const { instances } = intlTelInput;
1779
1928
  Object.values(instances).forEach((instance) => instance[method](...args));
@@ -1793,23 +1942,7 @@ var factoryOutput = (() => {
1793
1942
  this.options = Object.assign({}, defaults, customOptions);
1794
1943
  this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1795
1944
  }
1796
- //* Can't be private as it's called from intlTelInput convenience wrapper.
1797
- _init() {
1798
- if (this.options.useFullscreenPopup) {
1799
- this.options.fixDropdownWidth = false;
1800
- }
1801
- if (this.options.onlyCountries.length === 1) {
1802
- this.options.initialCountry = this.options.onlyCountries[0];
1803
- }
1804
- if (this.options.separateDialCode) {
1805
- this.options.nationalMode = false;
1806
- }
1807
- if (this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode) {
1808
- this.options.nationalMode = false;
1809
- }
1810
- if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
1811
- this.options.dropdownContainer = document.body;
1812
- }
1945
+ _detectEnvironmentAndLayout() {
1813
1946
  this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
1814
1947
  this.isRTL = !!this.telInput.closest("[dir=rtl]");
1815
1948
  this.telInput.dir = "ltr";
@@ -1822,7 +1955,8 @@ var factoryOutput = (() => {
1822
1955
  this.originalPaddingLeft = this.telInput.style.paddingLeft;
1823
1956
  }
1824
1957
  }
1825
- this.options.i18n = { ...en_default, ...this.options.i18n };
1958
+ }
1959
+ _createInitPromises() {
1826
1960
  const autoCountryPromise = new Promise((resolve, reject) => {
1827
1961
  this.resolveAutoCountryPromise = resolve;
1828
1962
  this.rejectAutoCountryPromise = reject;
@@ -1832,6 +1966,12 @@ var factoryOutput = (() => {
1832
1966
  this.rejectUtilsScriptPromise = reject;
1833
1967
  });
1834
1968
  this.promise = Promise.all([autoCountryPromise, utilsScriptPromise]);
1969
+ }
1970
+ //* Can't be private as it's called from intlTelInput convenience wrapper.
1971
+ _init() {
1972
+ applyOptionSideEffects(this.options);
1973
+ this._detectEnvironmentAndLayout();
1974
+ this._createInitPromises();
1835
1975
  this.selectedCountryData = {};
1836
1976
  this._processCountryData();
1837
1977
  this._generateMarkup();
@@ -1844,139 +1984,37 @@ var factoryOutput = (() => {
1844
1984
  //********************
1845
1985
  //* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
1846
1986
  _processCountryData() {
1847
- this._processAllCountries();
1848
- this._processDialCodes();
1849
- this._translateCountryNames();
1850
- this._sortCountries();
1987
+ this.countries = processAllCountries(this.options);
1988
+ const dialRes = processDialCodes(this.countries, this.options);
1989
+ this.dialCodes = dialRes.dialCodes;
1990
+ this.dialCodeMaxLen = dialRes.dialCodeMaxLen;
1991
+ this.dialCodeToIso2Map = dialRes.dialCodeToIso2Map;
1992
+ translateCountryNames(this.countries, this.options);
1993
+ sortCountries(this.countries, this.options);
1851
1994
  this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
1852
- this._cacheSearchTokens();
1853
- }
1854
- //* Precompute and cache country search tokens to speed up filtering
1855
- _cacheSearchTokens() {
1856
- for (const c of this.countries) {
1857
- c.normalisedName = normaliseString(c.name);
1858
- c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
1859
- c.dialCodePlus = `+${c.dialCode}`;
1860
- }
1861
- }
1862
- //* Sort countries by countryOrder option (if present), then name.
1863
- _sortCountries() {
1864
- if (this.options.countryOrder) {
1865
- this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
1866
- }
1867
- this.countries.sort((a, b) => {
1868
- const { countryOrder } = this.options;
1869
- if (countryOrder) {
1870
- const aIndex = countryOrder.indexOf(a.iso2);
1871
- const bIndex = countryOrder.indexOf(b.iso2);
1872
- const aIndexExists = aIndex > -1;
1873
- const bIndexExists = bIndex > -1;
1874
- if (aIndexExists || bIndexExists) {
1875
- if (aIndexExists && bIndexExists) {
1876
- return aIndex - bIndex;
1877
- }
1878
- return aIndexExists ? -1 : 1;
1879
- }
1880
- }
1881
- return a.name.localeCompare(b.name);
1882
- });
1883
- }
1884
- //* Add a dial code to this.dialCodeToIso2Map.
1885
- _addToDialCodeMap(iso2, dialCode, priority) {
1886
- if (!iso2 || !dialCode) {
1887
- return;
1888
- }
1889
- if (dialCode.length > this.dialCodeMaxLen) {
1890
- this.dialCodeMaxLen = dialCode.length;
1891
- }
1892
- if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1893
- this.dialCodeToIso2Map[dialCode] = [];
1894
- }
1895
- const iso2List = this.dialCodeToIso2Map[dialCode];
1896
- if (iso2List.includes(iso2)) {
1897
- return;
1898
- }
1899
- const index = priority !== void 0 ? priority : iso2List.length;
1900
- iso2List[index] = iso2;
1901
- }
1902
- //* Process onlyCountries or excludeCountries array if present.
1903
- _processAllCountries() {
1904
- const { onlyCountries, excludeCountries } = this.options;
1905
- if (onlyCountries.length) {
1906
- const lowerCaseOnlyCountries = onlyCountries.map(
1907
- (country) => country.toLowerCase()
1908
- );
1909
- this.countries = data_default.filter(
1910
- (country) => lowerCaseOnlyCountries.includes(country.iso2)
1911
- );
1912
- } else if (excludeCountries.length) {
1913
- const lowerCaseExcludeCountries = excludeCountries.map(
1914
- (country) => country.toLowerCase()
1915
- );
1916
- this.countries = data_default.filter(
1917
- (country) => !lowerCaseExcludeCountries.includes(country.iso2)
1918
- );
1919
- } else {
1920
- this.countries = data_default;
1921
- }
1922
- }
1923
- //* Translate Countries by object literal provided on config.
1924
- _translateCountryNames() {
1925
- for (const c of this.countries) {
1926
- const iso2 = c.iso2.toLowerCase();
1927
- if (this.options.i18n.hasOwnProperty(iso2)) {
1928
- c.name = this.options.i18n[iso2];
1929
- }
1930
- }
1931
- }
1932
- //* Generate this.dialCodes and this.dialCodeToIso2Map.
1933
- _processDialCodes() {
1934
- this.dialCodes = /* @__PURE__ */ new Set();
1935
- this.dialCodeMaxLen = 0;
1936
- this.dialCodeToIso2Map = {};
1937
- for (const c of this.countries) {
1938
- if (!this.dialCodes.has(c.dialCode)) {
1939
- this.dialCodes.add(c.dialCode);
1940
- }
1941
- this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1942
- }
1943
- if (this.options.onlyCountries.length || this.options.excludeCountries.length) {
1944
- this.dialCodes.forEach((dialCode) => {
1945
- this.dialCodeToIso2Map[dialCode] = this.dialCodeToIso2Map[dialCode].filter(Boolean);
1946
- });
1947
- }
1948
- for (const c of this.countries) {
1949
- if (c.areaCodes) {
1950
- const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1951
- for (const areaCode of c.areaCodes) {
1952
- for (let k = 1; k < areaCode.length; k++) {
1953
- const partialAreaCode = areaCode.substring(0, k);
1954
- const partialDialCode = c.dialCode + partialAreaCode;
1955
- this._addToDialCodeMap(rootIso2Code, partialDialCode);
1956
- this._addToDialCodeMap(c.iso2, partialDialCode);
1957
- }
1958
- this._addToDialCodeMap(c.iso2, c.dialCode + areaCode);
1959
- }
1960
- }
1961
- }
1995
+ cacheSearchTokens(this.countries);
1962
1996
  }
1963
1997
  //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
1964
1998
  _generateMarkup() {
1999
+ this._prepareTelInput();
2000
+ const wrapper = this._createWrapperAndInsert();
2001
+ this._maybeBuildCountryContainer(wrapper);
2002
+ wrapper.appendChild(this.telInput);
2003
+ this._maybeUpdateInputPaddingAndReveal();
2004
+ this._maybeBuildHiddenInputs(wrapper);
2005
+ }
2006
+ _prepareTelInput() {
1965
2007
  this.telInput.classList.add("iti__tel-input");
1966
2008
  if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1967
2009
  this.telInput.setAttribute("autocomplete", "off");
1968
2010
  }
2011
+ }
2012
+ _createWrapperAndInsert() {
1969
2013
  const {
1970
2014
  allowDropdown,
1971
- separateDialCode,
1972
2015
  showFlags,
1973
2016
  containerClass,
1974
- hiddenInput,
1975
- dropdownContainer,
1976
- fixDropdownWidth,
1977
- useFullscreenPopup,
1978
- countrySearch,
1979
- i18n
2017
+ useFullscreenPopup
1980
2018
  } = this.options;
1981
2019
  const parentClasses = _Iti._buildClassNames({
1982
2020
  "iti": true,
@@ -1987,6 +2025,14 @@ var factoryOutput = (() => {
1987
2025
  });
1988
2026
  const wrapper = createEl("div", { class: parentClasses });
1989
2027
  this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
2028
+ return wrapper;
2029
+ }
2030
+ _maybeBuildCountryContainer(wrapper) {
2031
+ const {
2032
+ allowDropdown,
2033
+ separateDialCode,
2034
+ showFlags
2035
+ } = this.options;
1990
2036
  if (allowDropdown || showFlags || separateDialCode) {
1991
2037
  this.countryContainer = createEl(
1992
2038
  "div",
@@ -2047,119 +2093,138 @@ var factoryOutput = (() => {
2047
2093
  );
2048
2094
  }
2049
2095
  if (allowDropdown) {
2050
- const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
2051
- this.dropdownContent = createEl("div", {
2052
- id: `iti-${this.id}__dropdown-content`,
2053
- class: `iti__dropdown-content iti__hide ${extraClasses}`,
2054
- role: "dialog",
2055
- "aria-modal": "true"
2056
- });
2057
- if (countrySearch) {
2058
- const searchWrapper = createEl(
2059
- "div",
2060
- { class: "iti__search-input-wrapper" },
2061
- this.dropdownContent
2062
- );
2063
- this.searchIcon = createEl(
2064
- "span",
2065
- {
2066
- class: "iti__search-icon",
2067
- "aria-hidden": "true"
2068
- },
2069
- searchWrapper
2070
- );
2071
- this.searchIcon.innerHTML = `
2072
- <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
2073
- <circle cx="11" cy="11" r="7" />
2074
- <line x1="21" y1="21" x2="16.65" y2="16.65" />
2075
- </svg>`;
2076
- this.searchInput = createEl(
2077
- "input",
2078
- {
2079
- id: `iti-${this.id}__search-input`,
2080
- // Chrome says inputs need either a name or an id
2081
- type: "search",
2082
- class: "iti__search-input",
2083
- placeholder: i18n.searchPlaceholder,
2084
- // 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
2085
- role: "combobox",
2086
- "aria-expanded": "true",
2087
- "aria-label": i18n.searchPlaceholder,
2088
- "aria-controls": `iti-${this.id}__country-listbox`,
2089
- "aria-autocomplete": "list",
2090
- "autocomplete": "off"
2091
- },
2092
- searchWrapper
2093
- );
2094
- this.searchClearButton = createEl(
2095
- "button",
2096
- {
2097
- type: "button",
2098
- class: "iti__search-clear iti__hide",
2099
- "aria-label": i18n.clearSearchAriaLabel,
2100
- tabindex: "-1"
2101
- },
2102
- searchWrapper
2103
- );
2104
- const maskId = `iti-${this.id}-clear-mask`;
2105
- this.searchClearButton.innerHTML = `
2106
- <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
2107
- <mask id="${maskId}" maskUnits="userSpaceOnUse">
2108
- <rect width="16" height="16" fill="white" />
2109
- <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" />
2110
- </mask>
2111
- <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${maskId})" />
2112
- </svg>`;
2113
- this.searchResultsA11yText = createEl(
2114
- "span",
2115
- { class: "iti__a11y-text" },
2116
- this.dropdownContent
2117
- );
2118
- this.searchNoResults = createEl(
2119
- "div",
2120
- {
2121
- class: "iti__no-results iti__hide",
2122
- "aria-hidden": "true"
2123
- // all a11y messaging happens in this.searchResultsA11yText
2124
- },
2125
- this.dropdownContent
2126
- );
2127
- this.searchNoResults.textContent = i18n.zeroSearchResults;
2128
- }
2129
- this.countryList = createEl(
2130
- "ul",
2131
- {
2132
- class: "iti__country-list",
2133
- id: `iti-${this.id}__country-listbox`,
2134
- role: "listbox",
2135
- "aria-label": i18n.countryListAriaLabel
2136
- },
2137
- this.dropdownContent
2138
- );
2139
- this._appendListItems();
2140
- if (countrySearch) {
2141
- this._updateSearchResultsA11yText();
2142
- }
2143
- if (dropdownContainer) {
2144
- const dropdownClasses = _Iti._buildClassNames({
2145
- "iti": true,
2146
- "iti--container": true,
2147
- "iti--fullscreen-popup": useFullscreenPopup,
2148
- "iti--inline-dropdown": !useFullscreenPopup,
2149
- [containerClass]: Boolean(containerClass)
2150
- });
2151
- this.dropdown = createEl("div", { class: dropdownClasses });
2152
- this.dropdown.appendChild(this.dropdownContent);
2153
- } else {
2154
- this.countryContainer.appendChild(this.dropdownContent);
2155
- }
2096
+ this._buildDropdownContent();
2156
2097
  }
2157
2098
  }
2158
- wrapper.appendChild(this.telInput);
2099
+ }
2100
+ _buildDropdownContent() {
2101
+ const {
2102
+ fixDropdownWidth,
2103
+ useFullscreenPopup,
2104
+ countrySearch,
2105
+ i18n,
2106
+ dropdownContainer,
2107
+ containerClass
2108
+ } = this.options;
2109
+ const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
2110
+ this.dropdownContent = createEl("div", {
2111
+ id: `iti-${this.id}__dropdown-content`,
2112
+ class: `iti__dropdown-content iti__hide ${extraClasses}`,
2113
+ role: "dialog",
2114
+ "aria-modal": "true"
2115
+ });
2116
+ if (countrySearch) {
2117
+ this._buildSearchUI();
2118
+ }
2119
+ this.countryList = createEl(
2120
+ "ul",
2121
+ {
2122
+ class: "iti__country-list",
2123
+ id: `iti-${this.id}__country-listbox`,
2124
+ role: "listbox",
2125
+ "aria-label": i18n.countryListAriaLabel
2126
+ },
2127
+ this.dropdownContent
2128
+ );
2129
+ this._appendListItems();
2130
+ if (countrySearch) {
2131
+ this._updateSearchResultsA11yText();
2132
+ }
2133
+ if (dropdownContainer) {
2134
+ const dropdownClasses = _Iti._buildClassNames({
2135
+ "iti": true,
2136
+ "iti--container": true,
2137
+ "iti--fullscreen-popup": useFullscreenPopup,
2138
+ "iti--inline-dropdown": !useFullscreenPopup,
2139
+ [containerClass]: Boolean(containerClass)
2140
+ });
2141
+ this.dropdown = createEl("div", { class: dropdownClasses });
2142
+ this.dropdown.appendChild(this.dropdownContent);
2143
+ } else {
2144
+ this.countryContainer.appendChild(this.dropdownContent);
2145
+ }
2146
+ }
2147
+ _buildSearchUI() {
2148
+ const { i18n } = this.options;
2149
+ const searchWrapper = createEl(
2150
+ "div",
2151
+ { class: "iti__search-input-wrapper" },
2152
+ this.dropdownContent
2153
+ );
2154
+ this.searchIcon = createEl(
2155
+ "span",
2156
+ {
2157
+ class: "iti__search-icon",
2158
+ "aria-hidden": "true"
2159
+ },
2160
+ searchWrapper
2161
+ );
2162
+ this.searchIcon.innerHTML = `
2163
+ <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
2164
+ <circle cx="11" cy="11" r="7" />
2165
+ <line x1="21" y1="21" x2="16.65" y2="16.65" />
2166
+ </svg>`;
2167
+ this.searchInput = createEl(
2168
+ "input",
2169
+ {
2170
+ id: `iti-${this.id}__search-input`,
2171
+ // Chrome says inputs need either a name or an id
2172
+ type: "search",
2173
+ class: "iti__search-input",
2174
+ placeholder: i18n.searchPlaceholder,
2175
+ // 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
2176
+ role: "combobox",
2177
+ "aria-expanded": "true",
2178
+ "aria-label": i18n.searchPlaceholder,
2179
+ "aria-controls": `iti-${this.id}__country-listbox`,
2180
+ "aria-autocomplete": "list",
2181
+ "autocomplete": "off"
2182
+ },
2183
+ searchWrapper
2184
+ );
2185
+ this.searchClearButton = createEl(
2186
+ "button",
2187
+ {
2188
+ type: "button",
2189
+ class: "iti__search-clear iti__hide",
2190
+ "aria-label": i18n.clearSearchAriaLabel,
2191
+ tabindex: "-1"
2192
+ },
2193
+ searchWrapper
2194
+ );
2195
+ const maskId = `iti-${this.id}-clear-mask`;
2196
+ this.searchClearButton.innerHTML = `
2197
+ <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
2198
+ <mask id="${maskId}" maskUnits="userSpaceOnUse">
2199
+ <rect width="16" height="16" fill="white" />
2200
+ <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" />
2201
+ </mask>
2202
+ <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${maskId})" />
2203
+ </svg>`;
2204
+ this.searchResultsA11yText = createEl(
2205
+ "span",
2206
+ { class: "iti__a11y-text" },
2207
+ this.dropdownContent
2208
+ );
2209
+ this.searchNoResults = createEl(
2210
+ "div",
2211
+ {
2212
+ class: "iti__no-results iti__hide",
2213
+ "aria-hidden": "true"
2214
+ // all a11y messaging happens in this.searchResultsA11yText
2215
+ },
2216
+ this.dropdownContent
2217
+ );
2218
+ this.searchNoResults.textContent = i18n.zeroSearchResults;
2219
+ }
2220
+ _maybeUpdateInputPaddingAndReveal() {
2159
2221
  if (this.countryContainer) {
2160
2222
  this._updateInputPadding();
2161
2223
  this.countryContainer.classList.remove("iti__v-hide");
2162
2224
  }
2225
+ }
2226
+ _maybeBuildHiddenInputs(wrapper) {
2227
+ const { hiddenInput } = this.options;
2163
2228
  if (hiddenInput) {
2164
2229
  const telInputName = this.telInput.getAttribute("name") || "";
2165
2230
  const names = hiddenInput(telInputName);
@@ -2233,14 +2298,13 @@ var factoryOutput = (() => {
2233
2298
  this._updateCountryFromNumber(val);
2234
2299
  } else if (!isAutoCountry || overrideAutoCountry) {
2235
2300
  const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
2236
- const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
2237
- if (isValidInitialCountry) {
2301
+ if (isIso2(lowerInitialCountry)) {
2238
2302
  this._setCountry(lowerInitialCountry);
2239
2303
  } else {
2240
2304
  if (dialCode && isRegionlessNanpNumber) {
2241
2305
  this._setCountry("us");
2242
2306
  } else {
2243
- this._setCountry();
2307
+ this._setCountry("");
2244
2308
  }
2245
2309
  }
2246
2310
  }
@@ -2343,8 +2407,7 @@ var factoryOutput = (() => {
2343
2407
  this.options.geoIpLookup(
2344
2408
  (iso2 = "") => {
2345
2409
  const iso2Lower = iso2.toLowerCase();
2346
- const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
2347
- if (isValidIso2) {
2410
+ if (isIso2(iso2Lower)) {
2348
2411
  intlTelInput.autoCountry = iso2Lower;
2349
2412
  setTimeout(() => forEachInstance("handleAutoCountry"));
2350
2413
  } else {
@@ -2367,6 +2430,11 @@ var factoryOutput = (() => {
2367
2430
  }
2368
2431
  //* Initialize the tel input listeners.
2369
2432
  _initTelInputListeners() {
2433
+ this._bindInputListener();
2434
+ this._maybeBindKeydownListener();
2435
+ this._maybeBindPasteListener();
2436
+ }
2437
+ _bindInputListener() {
2370
2438
  const { strictMode, formatAsYouType, separateDialCode, allowDropdown, countrySearch } = this.options;
2371
2439
  let userOverrideFormatting = false;
2372
2440
  if (/\p{L}/u.test(this.telInput.value)) {
@@ -2397,13 +2465,23 @@ var factoryOutput = (() => {
2397
2465
  const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2398
2466
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2399
2467
  const isDeleteForwards = e?.inputType === "deleteContentForward";
2400
- const formattedValue = this._formatNumberAsYouType();
2468
+ const fullNumber = this._getFullNumber();
2469
+ const formattedValue = formatNumberAsYouType(
2470
+ fullNumber,
2471
+ this.telInput.value,
2472
+ intlTelInput.utils,
2473
+ this.selectedCountryData,
2474
+ this.options.separateDialCode
2475
+ );
2401
2476
  const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2402
2477
  this.telInput.value = formattedValue;
2403
2478
  this.telInput.setSelectionRange(newCaretPos, newCaretPos);
2404
2479
  }
2405
2480
  };
2406
2481
  this.telInput.addEventListener("input", this._handleInputEvent);
2482
+ }
2483
+ _maybeBindKeydownListener() {
2484
+ const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.options;
2407
2485
  if (strictMode || separateDialCode) {
2408
2486
  this._handleKeydownEvent = (e) => {
2409
2487
  if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
@@ -2433,6 +2511,48 @@ var factoryOutput = (() => {
2433
2511
  this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2434
2512
  }
2435
2513
  }
2514
+ _maybeBindPasteListener() {
2515
+ if (this.options.strictMode) {
2516
+ this._handlePasteEvent = (e) => {
2517
+ e.preventDefault();
2518
+ const input = this.telInput;
2519
+ const selStart = input.selectionStart;
2520
+ const selEnd = input.selectionEnd;
2521
+ const before = input.value.slice(0, selStart);
2522
+ const after = input.value.slice(selEnd);
2523
+ const iso2 = this.selectedCountryData.iso2;
2524
+ const pasted = e.clipboardData.getData("text");
2525
+ const initialCharSelected = selStart === 0 && selEnd > 0;
2526
+ const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
2527
+ const allowedChars = pasted.replace(/[^0-9+]/g, "");
2528
+ const hasLeadingPlus = allowedChars.startsWith("+");
2529
+ const numerics = allowedChars.replace(/\+/g, "");
2530
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
2531
+ let newVal = before + sanitised + after;
2532
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
2533
+ while (coreNumber.length === 0 && newVal.length > 0) {
2534
+ newVal = newVal.slice(0, -1);
2535
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
2536
+ }
2537
+ if (!coreNumber) {
2538
+ return;
2539
+ }
2540
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
2541
+ if (input.selectionEnd === input.value.length) {
2542
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
2543
+ newVal = newVal.slice(0, newVal.length - trimLength);
2544
+ } else {
2545
+ return;
2546
+ }
2547
+ }
2548
+ input.value = newVal;
2549
+ const caretPos = selStart + sanitised.length;
2550
+ input.setSelectionRange(caretPos, caretPos);
2551
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
2552
+ };
2553
+ this.telInput.addEventListener("paste", this._handlePasteEvent);
2554
+ }
2555
+ }
2436
2556
  //* Adhere to the input's maxlength attr.
2437
2557
  _cap(number) {
2438
2558
  const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
@@ -2586,43 +2706,14 @@ var factoryOutput = (() => {
2586
2706
  }
2587
2707
  //* Country search enabled: Filter the countries according to the search query.
2588
2708
  _filterCountries(query) {
2589
- let noCountriesAddedYet = true;
2590
2709
  this.countryList.innerHTML = "";
2591
- const normalisedQuery = normaliseString(query);
2592
2710
  let matchedCountries;
2593
2711
  if (query === "") {
2594
2712
  matchedCountries = this.countries;
2595
2713
  } else {
2596
- const iso2Matches = [];
2597
- const nameStartWith = [];
2598
- const nameContains = [];
2599
- const dialCodeMatches = [];
2600
- const dialCodeContains = [];
2601
- const initialsMatches = [];
2602
- for (const c of this.countries) {
2603
- if (c.iso2 === normalisedQuery) {
2604
- iso2Matches.push(c);
2605
- } else if (c.normalisedName.startsWith(normalisedQuery)) {
2606
- nameStartWith.push(c);
2607
- } else if (c.normalisedName.includes(normalisedQuery)) {
2608
- nameContains.push(c);
2609
- } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2610
- dialCodeMatches.push(c);
2611
- } else if (c.dialCodePlus.includes(normalisedQuery)) {
2612
- dialCodeContains.push(c);
2613
- } else if (c.initials.includes(normalisedQuery)) {
2614
- initialsMatches.push(c);
2615
- }
2616
- }
2617
- matchedCountries = [
2618
- ...iso2Matches.sort((a, b) => a.priority - b.priority),
2619
- ...nameStartWith.sort((a, b) => a.priority - b.priority),
2620
- ...nameContains.sort((a, b) => a.priority - b.priority),
2621
- ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2622
- ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2623
- ...initialsMatches.sort((a, b) => a.priority - b.priority)
2624
- ];
2714
+ matchedCountries = this._getMatchedCountries(query);
2625
2715
  }
2716
+ let noCountriesAddedYet = true;
2626
2717
  for (const c of matchedCountries) {
2627
2718
  const listItem = c.nodeById[this.id];
2628
2719
  if (listItem) {
@@ -2644,6 +2735,38 @@ var factoryOutput = (() => {
2644
2735
  this.countryList.scrollTop = 0;
2645
2736
  this._updateSearchResultsA11yText();
2646
2737
  }
2738
+ _getMatchedCountries(query) {
2739
+ const normalisedQuery = normaliseString(query);
2740
+ const iso2Matches = [];
2741
+ const nameStartWith = [];
2742
+ const nameContains = [];
2743
+ const dialCodeMatches = [];
2744
+ const dialCodeContains = [];
2745
+ const initialsMatches = [];
2746
+ for (const c of this.countries) {
2747
+ if (c.iso2 === normalisedQuery) {
2748
+ iso2Matches.push(c);
2749
+ } else if (c.normalisedName.startsWith(normalisedQuery)) {
2750
+ nameStartWith.push(c);
2751
+ } else if (c.normalisedName.includes(normalisedQuery)) {
2752
+ nameContains.push(c);
2753
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2754
+ dialCodeMatches.push(c);
2755
+ } else if (c.dialCodePlus.includes(normalisedQuery)) {
2756
+ dialCodeContains.push(c);
2757
+ } else if (c.initials.includes(normalisedQuery)) {
2758
+ initialsMatches.push(c);
2759
+ }
2760
+ }
2761
+ return [
2762
+ ...iso2Matches.sort((a, b) => a.priority - b.priority),
2763
+ ...nameStartWith.sort((a, b) => a.priority - b.priority),
2764
+ ...nameContains.sort((a, b) => a.priority - b.priority),
2765
+ ...dialCodeMatches.sort((a, b) => a.priority - b.priority),
2766
+ ...dialCodeContains.sort((a, b) => a.priority - b.priority),
2767
+ ...initialsMatches.sort((a, b) => a.priority - b.priority)
2768
+ ];
2769
+ }
2647
2770
  //* Update search results text (for a11y).
2648
2771
  _updateSearchResultsA11yText() {
2649
2772
  const { i18n } = this.options;
@@ -2774,24 +2897,12 @@ var factoryOutput = (() => {
2774
2897
  this.highlightedItem.focus();
2775
2898
  }
2776
2899
  }
2777
- //* Find the country data for the given iso2 code
2778
- //* 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
2779
- _getCountryData(iso2, allowFail) {
2780
- const country = this.countryByIso2.get(iso2);
2781
- if (country) {
2782
- return country;
2783
- }
2784
- if (allowFail) {
2785
- return null;
2786
- }
2787
- throw new Error(`No country data for '${iso2}'`);
2788
- }
2789
2900
  //* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
2790
2901
  //* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
2791
2902
  _setCountry(iso2) {
2792
2903
  const { separateDialCode, showFlags, i18n } = this.options;
2793
2904
  const prevIso2 = this.selectedCountryData.iso2 || "";
2794
- this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) || {} : {};
2905
+ this.selectedCountryData = iso2 ? this.countryByIso2.get(iso2) : {};
2795
2906
  if (this.selectedCountryData.iso2) {
2796
2907
  this.defaultCountry = this.selectedCountryData.iso2;
2797
2908
  }
@@ -2910,11 +3021,11 @@ var factoryOutput = (() => {
2910
3021
  }
2911
3022
  //* Called when the user selects a list item from the dropdown.
2912
3023
  _selectListItem(listItem) {
2913
- const countryChanged = this._setCountry(
2914
- listItem.getAttribute("data-country-code")
2915
- );
3024
+ const iso2 = listItem.getAttribute("data-country-code");
3025
+ const countryChanged = this._setCountry(iso2);
2916
3026
  this._closeDropdown();
2917
- this._updateDialCode(listItem.getAttribute("data-dial-code"));
3027
+ const dialCode = listItem.getAttribute("data-dial-code");
3028
+ this._updateDialCode(dialCode);
2918
3029
  if (this.options.formatOnDisplay) {
2919
3030
  this._updateValFromNumber(this.telInput.value);
2920
3031
  }
@@ -3037,32 +3148,19 @@ var factoryOutput = (() => {
3037
3148
  }
3038
3149
  //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
3039
3150
  _beforeSetNumber(fullNumber) {
3040
- let number = fullNumber;
3041
- if (this.options.separateDialCode) {
3042
- let dialCode = this._getDialCode(number);
3043
- if (dialCode) {
3044
- dialCode = `+${this.selectedCountryData.dialCode}`;
3045
- const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3046
- number = number.substring(start);
3047
- }
3048
- }
3151
+ const dialCode = this._getDialCode(fullNumber);
3152
+ const number = beforeSetNumber(
3153
+ fullNumber,
3154
+ dialCode,
3155
+ this.options.separateDialCode,
3156
+ this.selectedCountryData
3157
+ );
3049
3158
  return this._cap(number);
3050
3159
  }
3051
3160
  //* Trigger the 'countrychange' event.
3052
3161
  _triggerCountryChange() {
3053
3162
  this._trigger("countrychange");
3054
3163
  }
3055
- //* Format the number as the user types.
3056
- _formatNumberAsYouType() {
3057
- const val = this._getFullNumber();
3058
- const result = intlTelInput.utils ? intlTelInput.utils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
3059
- const { dialCode } = this.selectedCountryData;
3060
- if (this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
3061
- const afterDialCode = result.split(`+${dialCode}`)[1] || "";
3062
- return afterDialCode.trim();
3063
- }
3064
- return result;
3065
- }
3066
3164
  //**************************
3067
3165
  //* SECRET PUBLIC METHODS
3068
3166
  //**************************
@@ -3120,6 +3218,9 @@ var factoryOutput = (() => {
3120
3218
  if (this._handleKeydownEvent) {
3121
3219
  this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
3122
3220
  }
3221
+ if (this._handlePasteEvent) {
3222
+ this.telInput.removeEventListener("paste", this._handlePasteEvent);
3223
+ }
3123
3224
  this.telInput.removeAttribute("data-intl-tel-input-id");
3124
3225
  if (separateDialCode) {
3125
3226
  if (this.isRTL) {
@@ -3211,6 +3312,9 @@ var factoryOutput = (() => {
3211
3312
  //* Update the selected country, and update the input val accordingly.
3212
3313
  setCountry(iso2) {
3213
3314
  const iso2Lower = iso2?.toLowerCase();
3315
+ if (!isIso2(iso2Lower)) {
3316
+ throw new Error(`Invalid country code: '${iso2Lower}'`);
3317
+ }
3214
3318
  const currentCountry = this.selectedCountryData.iso2;
3215
3319
  const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
3216
3320
  if (isCountryChange) {
@@ -3298,7 +3402,7 @@ var factoryOutput = (() => {
3298
3402
  attachUtils,
3299
3403
  startedLoadingUtilsScript: false,
3300
3404
  startedLoadingAutoCountry: false,
3301
- version: "25.10.6"
3405
+ version: "25.10.8"
3302
3406
  }
3303
3407
  );
3304
3408
  var intl_tel_input_default = intlTelInput;