intl-tel-input 25.8.6 → 25.10.1

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,4 +1,4 @@
1
- import { mergeModels as k, useModel as M, ref as N, onMounted as E, watch as B, onUnmounted as R, withDirectives as F, createElementBlock as V, openBlock as z, mergeProps as O, vModelText as $ } from "vue";
1
+ import { mergeModels as A, useModel as M, ref as D, onMounted as E, watch as B, onUnmounted as R, withDirectives as F, createElementBlock as V, openBlock as z, mergeProps as O, vModelText as $ } from "vue";
2
2
  const j = [
3
3
  [
4
4
  "af",
@@ -1594,13 +1594,15 @@ const U = {
1594
1594
  for (const u of w)
1595
1595
  u.name = T[u.iso2];
1596
1596
  let K = 0;
1597
- const D = (u) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(u).matches, W = () => {
1597
+ const N = (u) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(u).matches, W = () => {
1598
1598
  if (typeof navigator < "u" && typeof window < "u") {
1599
- const u = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), t = D("(max-width: 500px)"), e = D("(max-height: 600px)"), i = D("(pointer: coarse)");
1599
+ const u = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), t = N("(max-width: 500px)"), e = N("(max-height: 600px)"), i = N("(pointer: coarse)");
1600
1600
  return u || t || i && e;
1601
1601
  }
1602
1602
  return !1;
1603
1603
  }, x = {
1604
+ // Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
1605
+ allowPhonewords: !1,
1604
1606
  //* Whether or not to allow the dropdown.
1605
1607
  allowDropdown: !0,
1606
1608
  //* Add a placeholder in the input with an example number for the selected country.
@@ -1667,7 +1669,7 @@ const D = (u) => typeof window < "u" && typeof window.matchMedia == "function" &
1667
1669
  "887",
1668
1670
  "888",
1669
1671
  "889"
1670
- ], v = (u) => u.replace(/\D/g, ""), A = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), P = (u) => {
1672
+ ], v = (u) => u.replace(/\D/g, ""), k = (u = "") => u.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), P = (u) => {
1671
1673
  const t = v(u);
1672
1674
  if (t.charAt(0) === "1") {
1673
1675
  const e = t.substring(1, 4);
@@ -1685,7 +1687,7 @@ const D = (u) => typeof window < "u" && typeof window.matchMedia == "function" &
1685
1687
  return n;
1686
1688
  }
1687
1689
  return t.length;
1688
- }, m = (u, t, e) => {
1690
+ }, y = (u, t, e) => {
1689
1691
  const i = document.createElement(u);
1690
1692
  return t && Object.entries(t).forEach(([s, n]) => i.setAttribute(s, n)), e && e.appendChild(i), i;
1691
1693
  }, I = (u, ...t) => {
@@ -1725,7 +1727,7 @@ class L {
1725
1727
  //* Precompute and cache country search tokens to speed up filtering
1726
1728
  _cacheSearchTokens() {
1727
1729
  for (const t of this.countries)
1728
- t.normalisedName = A(t.name), t.initials = t.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((e) => e[0]).join("").toLowerCase(), t.dialCodePlus = `+${t.dialCode}`;
1730
+ t.normalisedName = k(t.name), t.initials = t.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((e) => e[0]).join("").toLowerCase(), t.dialCodePlus = `+${t.dialCode}`;
1729
1731
  }
1730
1732
  //* Sort countries by countryOrder option (if present), then name.
1731
1733
  _sortCountries() {
@@ -1813,13 +1815,14 @@ class L {
1813
1815
  "iti--show-flags": i,
1814
1816
  "iti--inline-dropdown": !d,
1815
1817
  [s]: !!s
1816
- }), y = m("div", { class: p });
1817
- if ((a = this.telInput.parentNode) == null || a.insertBefore(y, this.telInput), t || i || e) {
1818
- this.countryContainer = m(
1818
+ }), m = y("div", { class: p });
1819
+ if ((a = this.telInput.parentNode) == null || a.insertBefore(m, this.telInput), t || i || e) {
1820
+ this.countryContainer = y(
1819
1821
  "div",
1820
- { class: "iti__country-container" },
1821
- y
1822
- ), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", t ? (this.selectedCountry = m(
1822
+ // visibly hidden until we measure it's width to set the input padding correctly
1823
+ { class: "iti__country-container iti__v-hide" },
1824
+ m
1825
+ ), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", t ? (this.selectedCountry = y(
1823
1826
  "button",
1824
1827
  {
1825
1828
  type: "button",
@@ -1830,42 +1833,42 @@ class L {
1830
1833
  "aria-controls": `iti-${this.id}__dropdown-content`
1831
1834
  },
1832
1835
  this.countryContainer
1833
- ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = m(
1836
+ ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = y(
1834
1837
  "div",
1835
1838
  { class: "iti__selected-country" },
1836
1839
  this.countryContainer
1837
1840
  );
1838
- const _ = m(
1841
+ const _ = y(
1839
1842
  "div",
1840
1843
  { class: "iti__selected-country-primary" },
1841
1844
  this.selectedCountry
1842
1845
  );
1843
- if (this.selectedCountryInner = m(
1846
+ if (this.selectedCountryInner = y(
1844
1847
  "div",
1845
1848
  { class: "iti__flag" },
1846
1849
  _
1847
- ), t && (this.dropdownArrow = m(
1850
+ ), t && (this.dropdownArrow = y(
1848
1851
  "div",
1849
1852
  { class: "iti__arrow", "aria-hidden": "true" },
1850
1853
  _
1851
- )), e && (this.selectedDialCode = m(
1854
+ )), e && (this.selectedDialCode = y(
1852
1855
  "div",
1853
1856
  { class: "iti__selected-dial-code", dir: "ltr" },
1854
1857
  this.selectedCountry
1855
1858
  )), t) {
1856
1859
  const b = o ? "" : "iti--flexible-dropdown-width";
1857
- if (this.dropdownContent = m("div", {
1860
+ if (this.dropdownContent = y("div", {
1858
1861
  id: `iti-${this.id}__dropdown-content`,
1859
1862
  class: `iti__dropdown-content iti__hide ${b}`,
1860
1863
  role: "dialog",
1861
1864
  "aria-modal": "true"
1862
1865
  }), C) {
1863
- const f = m(
1866
+ const f = y(
1864
1867
  "div",
1865
1868
  { class: "iti__search-input-wrapper" },
1866
1869
  this.dropdownContent
1867
1870
  );
1868
- this.searchIcon = m(
1871
+ this.searchIcon = y(
1869
1872
  "span",
1870
1873
  {
1871
1874
  class: "iti__search-icon",
@@ -1876,7 +1879,7 @@ class L {
1876
1879
  <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true">
1877
1880
  <circle cx="11" cy="11" r="7" />
1878
1881
  <line x1="21" y1="21" x2="16.65" y2="16.65" />
1879
- </svg>`, this.searchInput = m(
1882
+ </svg>`, this.searchInput = y(
1880
1883
  "input",
1881
1884
  {
1882
1885
  id: `iti-${this.id}__search-input`,
@@ -1893,7 +1896,7 @@ class L {
1893
1896
  autocomplete: "off"
1894
1897
  },
1895
1898
  f
1896
- ), this.searchClearButton = m(
1899
+ ), this.searchClearButton = y(
1897
1900
  "button",
1898
1901
  {
1899
1902
  type: "button",
@@ -1911,11 +1914,11 @@ class L {
1911
1914
  <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" />
1912
1915
  </mask>
1913
1916
  <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${S})" />
1914
- </svg>`, this.searchResultsA11yText = m(
1917
+ </svg>`, this.searchResultsA11yText = y(
1915
1918
  "span",
1916
1919
  { class: "iti__a11y-text" },
1917
1920
  this.dropdownContent
1918
- ), this.searchNoResults = m(
1921
+ ), this.searchNoResults = y(
1919
1922
  "div",
1920
1923
  {
1921
1924
  class: "iti__no-results iti__hide",
@@ -1925,7 +1928,7 @@ class L {
1925
1928
  this.dropdownContent
1926
1929
  ), this.searchNoResults.textContent = c.zeroSearchResults;
1927
1930
  }
1928
- if (this.countryList = m(
1931
+ if (this.countryList = y(
1929
1932
  "ul",
1930
1933
  {
1931
1934
  class: "iti__country-list",
@@ -1942,33 +1945,33 @@ class L {
1942
1945
  "iti--inline-dropdown": !d,
1943
1946
  [s]: !!s
1944
1947
  });
1945
- this.dropdown = m("div", { class: f }), this.dropdown.appendChild(this.dropdownContent);
1948
+ this.dropdown = y("div", { class: f }), this.dropdown.appendChild(this.dropdownContent);
1946
1949
  } else
1947
1950
  this.countryContainer.appendChild(this.dropdownContent);
1948
1951
  }
1949
1952
  }
1950
- if (y.appendChild(this.telInput), this._updateInputPadding(), n) {
1953
+ if (m.appendChild(this.telInput), this.countryContainer && (this._updateInputPadding(), this.countryContainer.classList.remove("iti__v-hide")), n) {
1951
1954
  const _ = this.telInput.getAttribute("name") || "", b = n(_);
1952
1955
  if (b.phone) {
1953
1956
  const f = (h = this.telInput.form) == null ? void 0 : h.querySelector(`input[name="${b.phone}"]`);
1954
- f ? this.hiddenInput = f : (this.hiddenInput = m("input", {
1957
+ f ? this.hiddenInput = f : (this.hiddenInput = y("input", {
1955
1958
  type: "hidden",
1956
1959
  name: b.phone
1957
- }), y.appendChild(this.hiddenInput));
1960
+ }), m.appendChild(this.hiddenInput));
1958
1961
  }
1959
1962
  if (b.country) {
1960
1963
  const f = (g = this.telInput.form) == null ? void 0 : g.querySelector(`input[name="${b.country}"]`);
1961
- f ? this.hiddenInputCountry = f : (this.hiddenInputCountry = m("input", {
1964
+ f ? this.hiddenInputCountry = f : (this.hiddenInputCountry = y("input", {
1962
1965
  type: "hidden",
1963
1966
  name: b.country
1964
- }), y.appendChild(this.hiddenInputCountry));
1967
+ }), m.appendChild(this.hiddenInputCountry));
1965
1968
  }
1966
1969
  }
1967
1970
  }
1968
1971
  //* For each country: add a country list item <li> to the countryList <ul> container.
1969
1972
  _appendListItems() {
1970
1973
  for (let t = 0; t < this.countries.length; t++) {
1971
- const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s = m(
1974
+ const e = this.countries[t], i = t === 0 ? "iti__highlight" : "", s = y(
1972
1975
  "li",
1973
1976
  {
1974
1977
  id: `iti-${this.id}__item-${e.iso2}`,
@@ -2058,8 +2061,8 @@ class L {
2058
2061
  let r = !1;
2059
2062
  new RegExp("\\p{L}", "u").test(this.telInput.value) && (r = !0), this._handleInputEvent = (o) => {
2060
2063
  if (this.isAndroid && (o == null ? void 0 : o.data) === "+" && i && s && n) {
2061
- const p = this.telInput.selectionStart || 0, y = this.telInput.value.substring(0, p - 1), a = this.telInput.value.substring(p);
2062
- this.telInput.value = y + a, this._openDropdownWithPlus();
2064
+ const p = this.telInput.selectionStart || 0, m = this.telInput.value.substring(0, p - 1), a = this.telInput.value.substring(p);
2065
+ this.telInput.value = m + a, this._openDropdownWithPlus();
2063
2066
  return;
2064
2067
  }
2065
2068
  this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
@@ -2077,8 +2080,8 @@ class L {
2077
2080
  return;
2078
2081
  }
2079
2082
  if (t) {
2080
- const d = this.telInput.value, c = !(d.charAt(0) === "+") && this.telInput.selectionStart === 0 && o.key === "+", p = /^[0-9]$/.test(o.key), y = i ? p : c || p, a = d.slice(0, this.telInput.selectionStart) + o.key + d.slice(this.telInput.selectionEnd), h = this._getFullNumber(a), g = l.utils.getCoreNumber(h, this.selectedCountryData.iso2), _ = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength, f = this._getNewCountryFromNumber(h) !== null;
2081
- (!y || _ && !f && !c) && o.preventDefault();
2083
+ const d = this.telInput.value, c = !(d.charAt(0) === "+") && this.telInput.selectionStart === 0 && o.key === "+", p = /^[0-9]$/.test(o.key), m = i ? p : c || p, a = d.slice(0, this.telInput.selectionStart) + o.key + d.slice(this.telInput.selectionEnd), h = this._getFullNumber(a), g = l.utils.getCoreNumber(h, this.selectedCountryData.iso2), _ = this.maxCoreNumberLength && g.length > this.maxCoreNumberLength, f = this._getNewCountryFromNumber(h) !== null;
2084
+ (!m || _ && !f && !c) && o.preventDefault();
2082
2085
  }
2083
2086
  }
2084
2087
  }, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
@@ -2167,10 +2170,10 @@ class L {
2167
2170
  _filterCountries(t, e = !1) {
2168
2171
  let i = !0;
2169
2172
  this.countryList.innerHTML = "";
2170
- const s = A(t), n = s.length, r = [], o = [], d = [], C = [], c = [], p = [];
2173
+ const s = k(t), n = s.length, r = [], o = [], d = [], C = [], c = [], p = [];
2171
2174
  for (const a of this.countries)
2172
2175
  e || n === 0 ? d.push(a) : a.iso2 === s ? r.push(a) : a.normalisedName.startsWith(s) ? o.push(a) : a.normalisedName.includes(s) ? d.push(a) : s === a.dialCode || s === a.dialCodePlus ? C.push(a) : a.dialCodePlus.includes(s) ? c.push(a) : a.initials.includes(s) && p.push(a);
2173
- const y = [
2176
+ const m = [
2174
2177
  ...r.sort((a, h) => a.priority - h.priority),
2175
2178
  ...o.sort((a, h) => a.priority - h.priority),
2176
2179
  ...d.sort((a, h) => a.priority - h.priority),
@@ -2178,7 +2181,7 @@ class L {
2178
2181
  ...c.sort((a, h) => a.priority - h.priority),
2179
2182
  ...p.sort((a, h) => a.priority - h.priority)
2180
2183
  ];
2181
- for (const a of y) {
2184
+ for (const a of m) {
2182
2185
  const h = a.nodeById[this.id];
2183
2186
  h && (this.countryList.appendChild(h), i && (this._highlightListItem(h, !1), i = !1));
2184
2187
  }
@@ -2296,8 +2299,8 @@ class L {
2296
2299
  //* Update the input padding to make space for the selected country/dial code.
2297
2300
  _updateInputPadding() {
2298
2301
  if (this.selectedCountry) {
2299
- const e = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth()) + 6;
2300
- this.showSelectedCountryOnLeft ? this.telInput.style.paddingLeft = `${e}px` : this.telInput.style.paddingRight = `${e}px`;
2302
+ const t = this.options.separateDialCode ? 78 : 42, i = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || t) + 6;
2303
+ this.showSelectedCountryOnLeft ? this.telInput.style.paddingLeft = `${i}px` : this.telInput.style.paddingRight = `${i}px`;
2301
2304
  }
2302
2305
  }
2303
2306
  //* Update the maximum valid number length for the currently selected country.
@@ -2319,20 +2322,26 @@ class L {
2319
2322
  } else
2320
2323
  this.maxCoreNumberLength = null;
2321
2324
  }
2322
- //* When the input is in a hidden container during initialisation, we must inject some markup
2323
- //* into the end of the DOM to calculate the correct offsetWidth.
2324
- //* NOTE: this is only used when separateDialCode is enabled, so countryContainer and selectedCountry
2325
- //* will definitely exist.
2325
+ //* When input is in a hidden container during init, we cannot calculate the selected country width.
2326
+ //* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
2327
+ //* To get the right styling to apply, all we need is a shallow clone of the container,
2328
+ //* and then to inject a deep clone of the selectedCountry element.
2326
2329
  _getHiddenSelectedCountryWidth() {
2327
2330
  if (this.telInput.parentNode) {
2328
- const t = this.telInput.parentNode.cloneNode(!1);
2329
- t.style.visibility = "hidden", document.body.appendChild(t);
2330
- const e = this.countryContainer.cloneNode();
2331
- t.appendChild(e);
2332
- const i = this.selectedCountry.cloneNode(!0);
2331
+ let t;
2332
+ try {
2333
+ t = window.top.document.body;
2334
+ } catch {
2335
+ t = document.body;
2336
+ }
2337
+ const e = this.telInput.parentNode.cloneNode(!1);
2338
+ e.style.visibility = "hidden", t.appendChild(e);
2339
+ const i = this.countryContainer.cloneNode();
2333
2340
  e.appendChild(i);
2334
- const s = i.offsetWidth;
2335
- return document.body.removeChild(t), s;
2341
+ const s = this.selectedCountry.cloneNode(!0);
2342
+ i.appendChild(s);
2343
+ const n = s.offsetWidth;
2344
+ return t.removeChild(e), n;
2336
2345
  }
2337
2346
  return 0;
2338
2347
  }
@@ -2530,12 +2539,12 @@ class L {
2530
2539
  _validateNumber(t) {
2531
2540
  if (!this.selectedCountryData.iso2)
2532
2541
  return !1;
2533
- const e = this._getFullNumber(), i = e.search(new RegExp("\\p{L}", "u")), s = (n) => t ? this._utilsIsValidNumber(n) : this._utilsIsPossibleNumber(n);
2534
- if (i > -1) {
2535
- const n = e.substring(0, i), r = s(n), o = s(e);
2536
- return r && o;
2542
+ const e = (r) => t ? this._utilsIsValidNumber(r) : this._utilsIsPossibleNumber(r), i = this._getFullNumber(), s = i.search(new RegExp("\\p{L}", "u"));
2543
+ if (s > -1 && !this.options.allowPhonewords) {
2544
+ const r = i.substring(0, s), o = e(r), d = e(i);
2545
+ return o && d;
2537
2546
  }
2538
- return s(e);
2547
+ return e(i);
2539
2548
  }
2540
2549
  _utilsIsValidNumber(t) {
2541
2550
  return l.utils ? l.utils.isValidNumber(t, this.selectedCountryData.iso2, this.options.validationNumberTypes) : null;
@@ -2600,11 +2609,11 @@ const Y = (u) => {
2600
2609
  attachUtils: Y,
2601
2610
  startedLoadingUtilsScript: !1,
2602
2611
  startedLoadingAutoCountry: !1,
2603
- version: "25.8.6"
2612
+ version: "25.10.1"
2604
2613
  }
2605
2614
  ), Z = {
2606
2615
  __name: "IntlTelInput",
2607
- props: /* @__PURE__ */ k({
2616
+ props: /* @__PURE__ */ A({
2608
2617
  disabled: {
2609
2618
  type: Boolean,
2610
2619
  default: !1
@@ -2628,14 +2637,14 @@ const Y = (u) => {
2628
2637
  },
2629
2638
  modelModifiers: {}
2630
2639
  }),
2631
- emits: /* @__PURE__ */ k([
2640
+ emits: /* @__PURE__ */ A([
2632
2641
  "changeNumber",
2633
2642
  "changeCountry",
2634
2643
  "changeValidity",
2635
2644
  "changeErrorCode"
2636
2645
  ], ["update:modelValue"]),
2637
2646
  setup(u, { expose: t, emit: e }) {
2638
- const i = M(u, "modelValue"), s = u, n = e, r = N(), o = N(), d = N(!1), C = () => o.value ? s.options.strictMode ? o.value.isValidNumberPrecise() : o.value.isValidNumber() : null, c = () => {
2647
+ const i = M(u, "modelValue"), s = u, n = e, r = D(), o = D(), d = D(!1), C = () => o.value ? s.options.strictMode ? o.value.isValidNumberPrecise() : o.value.isValidNumber() : null, c = () => {
2639
2648
  let a = C();
2640
2649
  d.value !== a && (d.value = a, n("changeValidity", !!a), n(
2641
2650
  "changeErrorCode",
@@ -2644,7 +2653,7 @@ const Y = (u) => {
2644
2653
  }, p = () => {
2645
2654
  var a;
2646
2655
  n("changeNumber", ((a = o.value) == null ? void 0 : a.getNumber()) ?? ""), c();
2647
- }, y = () => {
2656
+ }, m = () => {
2648
2657
  var a;
2649
2658
  n("changeCountry", ((a = o.value) == null ? void 0 : a.getSelectedCountryData().iso2) ?? ""), p(), c();
2650
2659
  };
@@ -2664,7 +2673,7 @@ const Y = (u) => {
2664
2673
  ref: r,
2665
2674
  "onUpdate:modelValue": h[0] || (h[0] = (g) => i.value = g),
2666
2675
  type: "tel",
2667
- onCountrychange: y,
2676
+ onCountrychange: m,
2668
2677
  onInput: p
2669
2678
  }, u.inputProps), null, 16)), [
2670
2679
  [