intl-tel-input 27.3.0 → 28.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/css/intlTelInput-no-assets.css +2 -2
  2. package/dist/css/intlTelInput.css +3 -3
  3. package/dist/js/data.d.ts +1 -4
  4. package/dist/js/data.js +3 -9
  5. package/dist/js/data.min.js +2 -2
  6. package/dist/js/data.mjs +2 -8
  7. package/dist/js/i18n.d.ts +1 -1592
  8. package/dist/js/intlTelInput.d.ts +62 -49
  9. package/dist/js/intlTelInput.js +221 -182
  10. package/dist/js/intlTelInput.min.js +6 -6
  11. package/dist/js/intlTelInput.mjs +219 -180
  12. package/dist/js/intlTelInputWithUtils.js +622 -568
  13. package/dist/js/intlTelInputWithUtils.min.js +6 -6
  14. package/dist/js/intlTelInputWithUtils.mjs +620 -566
  15. package/dist/js/utils.js +56 -55
  16. package/package.json +14 -181
  17. package/CHANGELOG.md +0 -33
  18. package/angular/README.md +0 -13
  19. package/angular/dist/IntlTelInput.d.ts +0 -110
  20. package/angular/dist/IntlTelInput.js +0 -5096
  21. package/angular/dist/IntlTelInputWithUtils.d.ts +0 -3
  22. package/angular/dist/IntlTelInputWithUtils.js +0 -11435
  23. package/react/README.md +0 -13
  24. package/react/dist/IntlTelInput.d.ts +0 -25
  25. package/react/dist/IntlTelInput.js +0 -4788
  26. package/react/dist/IntlTelInputWithUtils.d.ts +0 -4
  27. package/react/dist/IntlTelInputWithUtils.js +0 -11127
  28. package/svelte/README.md +0 -14
  29. package/svelte/src/IntlTelInput.svelte +0 -233
  30. package/svelte/src/IntlTelInput.svelte.d.ts +0 -36
  31. package/svelte/src/IntlTelInputWithUtils.svelte +0 -24
  32. package/vue/README.md +0 -14
  33. package/vue/dist/IntlTelInput-jw1tkqdD.js +0 -2657
  34. package/vue/dist/IntlTelInput.js +0 -5
  35. package/vue/dist/IntlTelInput.vue.d.ts +0 -43
  36. package/vue/dist/IntlTelInputWithUtils.js +0 -49403
  37. package/vue/dist/index.d.ts +0 -4
  38. package/vue/dist/indexWithUtils.d.ts +0 -3
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v27.3.0
2
+ * International Telephone Input v28.0.0
3
3
  * git+https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -23,14 +23,17 @@ var _factory = (() => {
23
23
  };
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
 
26
- // src/js/intlTelInput.ts
26
+ // packages/core/src/js/intlTelInput.ts
27
27
  var intlTelInput_exports = {};
28
28
  __export(intlTelInput_exports, {
29
29
  Iti: () => Iti,
30
+ NUMBER_FORMAT: () => NUMBER_FORMAT,
31
+ NUMBER_TYPE: () => NUMBER_TYPE,
32
+ VALIDATION_ERROR: () => VALIDATION_ERROR,
30
33
  default: () => intlTelInput_default
31
34
  });
32
35
 
33
- // src/js/data.ts
36
+ // packages/core/src/js/data.ts
34
37
  var rawCountryData = [
35
38
  [
36
39
  "af",
@@ -1775,20 +1778,14 @@ var _factory = (() => {
1775
1778
  dialCode: c[1],
1776
1779
  priority: c[2] || 0,
1777
1780
  areaCodes: c[3] || null,
1778
- nationalPrefix: c[4] || null,
1779
- normalisedName: "",
1780
- // populated in the plugin
1781
- initials: "",
1782
- // populated in the plugin
1783
- dialCodePlus: ""
1784
- // populated in the plugin
1781
+ nationalPrefix: c[4] || null
1785
1782
  });
1786
1783
  }
1787
1784
  var iso2Set = new Set(allCountries.map((c) => c.iso2));
1788
1785
  var isIso2 = (val) => iso2Set.has(val);
1789
1786
  var data_default = allCountries;
1790
1787
 
1791
- // src/js/constants.ts
1788
+ // packages/core/src/js/constants.ts
1792
1789
  var EVENTS = {
1793
1790
  OPEN_COUNTRY_DROPDOWN: "open:countrydropdown",
1794
1791
  CLOSE_COUNTRY_DROPDOWN: "close:countrydropdown",
@@ -1834,10 +1831,6 @@ var _factory = (() => {
1834
1831
  HIDDEN_SEARCH_RESET_MS: 1e3,
1835
1832
  NEXT_TICK: 0
1836
1833
  };
1837
- var SENTINELS = {
1838
- UNKNOWN_NUMBER_TYPE: -99,
1839
- UNKNOWN_VALIDATION_ERROR: -99
1840
- };
1841
1834
  var LAYOUT = {
1842
1835
  NARROW_VIEWPORT_WIDTH: 500,
1843
1836
  // keep in sync with .iti__country-list CSS media query
@@ -1879,6 +1872,12 @@ var _factory = (() => {
1879
1872
  var INITIAL_COUNTRY = {
1880
1873
  AUTO: "auto"
1881
1874
  };
1875
+ var NUMBER_FORMATS = [
1876
+ "E164",
1877
+ "INTERNATIONAL",
1878
+ "NATIONAL",
1879
+ "RFC3966"
1880
+ ];
1882
1881
  var NUMBER_TYPES = [
1883
1882
  "FIXED_LINE",
1884
1883
  "MOBILE",
@@ -1893,11 +1892,21 @@ var _factory = (() => {
1893
1892
  "VOICEMAIL",
1894
1893
  "UNKNOWN"
1895
1894
  ];
1896
- var NUMBER_TYPE_SET = new Set(NUMBER_TYPES);
1895
+ var VALIDATION_ERRORS = [
1896
+ "IS_POSSIBLE",
1897
+ "INVALID_COUNTRY_CODE",
1898
+ "TOO_SHORT",
1899
+ "TOO_LONG",
1900
+ "IS_POSSIBLE_LOCAL_ONLY",
1901
+ "INVALID_LENGTH"
1902
+ ];
1903
+ var toEnumObject = (arr) => Object.fromEntries(arr.map((v) => [v, v]));
1904
+ var NUMBER_FORMAT = toEnumObject(NUMBER_FORMATS);
1905
+ var NUMBER_TYPE = toEnumObject(NUMBER_TYPES);
1906
+ var VALIDATION_ERROR = toEnumObject(VALIDATION_ERRORS);
1897
1907
  var DATA_KEYS = {
1898
- // e.g. <li data-country-code="us"> for country items in dropdown
1899
- // in the future, the value should be changed to "iso2", but this is a breaking change for another day
1900
- ISO2: "countryCode",
1908
+ // e.g. <li data-iso2="us"> for country items in dropdown
1909
+ ISO2: "iso2",
1901
1910
  DIAL_CODE: "dialCode",
1902
1911
  // e.g. <input data-intl-tel-input-id="0"> on the input element
1903
1912
  INSTANCE_ID: "intlTelInputId"
@@ -1914,7 +1923,7 @@ var _factory = (() => {
1914
1923
  MODAL: "aria-modal"
1915
1924
  };
1916
1925
 
1917
- // src/js/i18n/en.ts
1926
+ // packages/core/src/js/i18n/en.ts
1918
1927
  var interfaceTranslations = {
1919
1928
  selectedCountryAriaLabel: "Change country for phone number, currently selected ${countryName} (${dialCode})",
1920
1929
  noCountrySelected: "Select country for phone number",
@@ -1934,7 +1943,7 @@ var _factory = (() => {
1934
1943
  };
1935
1944
  var en_default = interfaceTranslations;
1936
1945
 
1937
- // src/js/core/options.ts
1946
+ // packages/core/src/js/core/options.ts
1938
1947
  var mediaQuery = (q) => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(q).matches;
1939
1948
  var isNarrowViewport = () => mediaQuery(`(max-width: ${LAYOUT.NARROW_VIEWPORT_WIDTH}px)`);
1940
1949
  var computeDefaultUseFullscreenPopup = () => {
@@ -1949,7 +1958,7 @@ var _factory = (() => {
1949
1958
  //* Whether or not to allow the dropdown.
1950
1959
  allowDropdown: true,
1951
1960
  //* The number type to enforce during validation.
1952
- allowedNumberTypes: ["MOBILE", "FIXED_LINE"],
1961
+ allowedNumberTypes: [NUMBER_TYPE.MOBILE, NUMBER_TYPE.FIXED_LINE],
1953
1962
  //* Whether or not to allow extensions after the main number.
1954
1963
  allowNumberExtensions: false,
1955
1964
  // Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
@@ -1960,6 +1969,8 @@ var _factory = (() => {
1960
1969
  containerClass: "",
1961
1970
  //* Locale for localising country names via Intl.DisplayNames.
1962
1971
  countryNameLocale: "en",
1972
+ //* Override individual country names by iso2 code.
1973
+ countryNameOverrides: {},
1963
1974
  //* The order of the countries in the dropdown. Defaults to alphabetical.
1964
1975
  countryOrder: null,
1965
1976
  //* Add a country search input at the top of the dropdown.
@@ -1993,17 +2004,17 @@ var _factory = (() => {
1993
2004
  //* Display only these countries.
1994
2005
  onlyCountries: null,
1995
2006
  //* Number type to use for placeholders.
1996
- placeholderNumberType: "MOBILE",
2007
+ placeholderNumberType: NUMBER_TYPE.MOBILE,
1997
2008
  //* Add custom classes to the search input element.
1998
2009
  searchInputClass: "",
1999
2010
  //* Display the international dial code next to the selected flag.
2000
- separateDialCode: false,
2011
+ separateDialCode: true,
2001
2012
  //* When strictMode rejects a key (etc), play a short feedback animation
2002
- strictRejectAnimation: false,
2013
+ strictRejectAnimation: true,
2003
2014
  //* Show flags - for both the selected country, and in the country dropdown
2004
2015
  showFlags: true,
2005
2016
  //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
2006
- strictMode: false,
2017
+ strictMode: true,
2007
2018
  //* Use full screen popup instead of dropdown for country list.
2008
2019
  useFullscreenPopup: computeDefaultUseFullscreenPopup()
2009
2020
  };
@@ -2147,6 +2158,13 @@ var _factory = (() => {
2147
2158
  }
2148
2159
  validatedOptions[key] = value;
2149
2160
  break;
2161
+ case "countryNameOverrides":
2162
+ if (value && !isPlainObject(value)) {
2163
+ warnOption("countryNameOverrides", "an object", value);
2164
+ break;
2165
+ }
2166
+ validatedOptions[key] = value;
2167
+ break;
2150
2168
  case "initialCountry": {
2151
2169
  if (typeof value !== "string") {
2152
2170
  warnOption("initialCountry", "a string", value);
@@ -2165,8 +2183,8 @@ var _factory = (() => {
2165
2183
  break;
2166
2184
  }
2167
2185
  case "placeholderNumberType":
2168
- if (typeof value !== "string" || !NUMBER_TYPE_SET.has(value)) {
2169
- const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
2186
+ if (typeof value !== "string" || !NUMBER_TYPES.includes(value)) {
2187
+ const validTypes = NUMBER_TYPES.join(", ");
2170
2188
  warnOption("placeholderNumberType", `one of ${validTypes}`, value);
2171
2189
  break;
2172
2190
  }
@@ -2184,8 +2202,8 @@ var _factory = (() => {
2184
2202
  }
2185
2203
  let allValid = true;
2186
2204
  for (const v of value) {
2187
- if (typeof v !== "string" || !NUMBER_TYPE_SET.has(v)) {
2188
- const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
2205
+ if (typeof v !== "string" || !NUMBER_TYPES.includes(v)) {
2206
+ const validTypes = NUMBER_TYPES.join(", ");
2189
2207
  warnOption(
2190
2208
  "allowedNumberTypes",
2191
2209
  `an array of valid number types (${validTypes})`,
@@ -2247,11 +2265,11 @@ var _factory = (() => {
2247
2265
  o.i18n = { ...en_default, ...o.i18n };
2248
2266
  };
2249
2267
 
2250
- // src/js/helpers/string.ts
2268
+ // packages/core/src/js/helpers/string.ts
2251
2269
  var getNumeric = (s) => s.replace(/\D/g, "");
2252
2270
  var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
2253
2271
 
2254
- // src/js/helpers/dom.ts
2272
+ // packages/core/src/js/helpers/dom.ts
2255
2273
  var buildClassNames = (flags) => Object.keys(flags).filter((k) => Boolean(flags[k])).join(" ");
2256
2274
  var createEl = (tagName, attrs, container) => {
2257
2275
  const el = document.createElement(tagName);
@@ -2266,7 +2284,7 @@ var _factory = (() => {
2266
2284
  return el;
2267
2285
  };
2268
2286
 
2269
- // src/js/core/icons.ts
2287
+ // packages/core/src/js/core/icons.ts
2270
2288
  var buildSearchIcon = () => `
2271
2289
  <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" ${ARIA.HIDDEN}="true">
2272
2290
  <circle cx="11" cy="11" r="7" />
@@ -2293,8 +2311,21 @@ var _factory = (() => {
2293
2311
  <path d="m261 428-2-2-22-21a40 40 0 0 0-32-11h-1a37 37 0 0 0-18 8l-1 1-4 2-2 2-5 4c-9-3-36-31-47-44s-32-45-34-55l3-2a151 151 0 0 0 11-9v-1a39 39 0 0 0 5-48l-3-3-11-19-3-4-5-7h-1l-3-3-4-3-5-2a35 35 0 0 0-16-3h-5c-4 1-14 5-24 11l-4 2-4 3-4 2c-9 8-17 17-18 27a380 380 0 0 0 212 259h3c12 0 25-10 36-21l10-12 6-11a39 39 0 0 0-8-40"/>
2294
2312
  </svg>`;
2295
2313
 
2296
- // src/js/core/countrySearch.ts
2297
- var getMatchedCountries = (countries, query) => {
2314
+ // packages/core/src/js/core/countrySearch.ts
2315
+ var buildSearchTokens = (countries) => {
2316
+ const tokens = /* @__PURE__ */ new Map();
2317
+ for (const c of countries) {
2318
+ const normalisedName = normaliseString(c.name);
2319
+ const initials = normalisedName.split(/[^a-z]/).map((word) => word[0]).join("");
2320
+ tokens.set(c.iso2, {
2321
+ normalisedName,
2322
+ initials,
2323
+ dialCodePlus: `+${c.dialCode}`
2324
+ });
2325
+ }
2326
+ return tokens;
2327
+ };
2328
+ var getMatchedCountries = (countries, searchTokens, query) => {
2298
2329
  const normalisedQuery = normaliseString(query);
2299
2330
  const iso2Matches = [];
2300
2331
  const nameStartsWith = [];
@@ -2303,17 +2334,18 @@ var _factory = (() => {
2303
2334
  const dialCodeContains = [];
2304
2335
  const initialsMatches = [];
2305
2336
  for (const c of countries) {
2337
+ const t = searchTokens.get(c.iso2);
2306
2338
  if (c.iso2 === normalisedQuery) {
2307
2339
  iso2Matches.push(c);
2308
- } else if (c.normalisedName.startsWith(normalisedQuery)) {
2340
+ } else if (t.normalisedName.startsWith(normalisedQuery)) {
2309
2341
  nameStartsWith.push(c);
2310
- } else if (c.normalisedName.includes(normalisedQuery)) {
2342
+ } else if (t.normalisedName.includes(normalisedQuery)) {
2311
2343
  nameContains.push(c);
2312
- } else if (normalisedQuery === c.dialCode || normalisedQuery === c.dialCodePlus) {
2344
+ } else if (normalisedQuery === c.dialCode || normalisedQuery === t.dialCodePlus) {
2313
2345
  dialCodeMatches.push(c);
2314
- } else if (c.dialCodePlus.includes(normalisedQuery)) {
2346
+ } else if (t.dialCodePlus.includes(normalisedQuery)) {
2315
2347
  dialCodeContains.push(c);
2316
- } else if (c.initials.includes(normalisedQuery)) {
2348
+ } else if (t.initials.includes(normalisedQuery)) {
2317
2349
  initialsMatches.push(c);
2318
2350
  }
2319
2351
  }
@@ -2328,17 +2360,76 @@ var _factory = (() => {
2328
2360
  ...initialsMatches
2329
2361
  ];
2330
2362
  };
2331
- var findFirstCountryStartingWith = (countries, query) => {
2363
+ var findFirstCountryStartingWith = (countries, searchTokens, query) => {
2332
2364
  const normalisedQuery = normaliseString(query);
2333
2365
  for (const c of countries) {
2334
- if (c.normalisedName.startsWith(normalisedQuery)) {
2366
+ const { normalisedName } = searchTokens.get(c.iso2);
2367
+ if (normalisedName.startsWith(normalisedQuery)) {
2335
2368
  return c;
2336
2369
  }
2337
2370
  }
2338
2371
  return null;
2339
2372
  };
2340
2373
 
2341
- // src/js/core/ui.ts
2374
+ // packages/core/src/js/core/numerals.ts
2375
+ var Numerals = class _Numerals {
2376
+ #userNumeralSet;
2377
+ //* Stateless conversion of any Arabic-Indic / Persian digits to ASCII 0-9.
2378
+ //* Use this when you need to normalise digits without affecting any instance's tracked numeral set (e.g. for the country-search query).
2379
+ static toAscii(str) {
2380
+ if (!str) {
2381
+ return "";
2382
+ }
2383
+ return str.replace(
2384
+ /[٠-٩]/g,
2385
+ (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - 1632))
2386
+ ).replace(
2387
+ /[۰-۹]/g,
2388
+ (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - 1776))
2389
+ );
2390
+ }
2391
+ constructor(initialValue) {
2392
+ if (initialValue) {
2393
+ this.#updateNumeralSet(initialValue);
2394
+ }
2395
+ }
2396
+ // If any Arabic-Indic digits, then label it as that set. Same for Persian. Otherwise assume ASCII.
2397
+ #updateNumeralSet(str) {
2398
+ if (/[٠-٩]/.test(str)) {
2399
+ this.#userNumeralSet = "arabic-indic";
2400
+ } else if (/[۰-۹]/.test(str)) {
2401
+ this.#userNumeralSet = "persian";
2402
+ } else {
2403
+ this.#userNumeralSet = "ascii";
2404
+ }
2405
+ }
2406
+ // Denormalise ASCII 0-9 to the user's numeral set. If not yet known, return as-is.
2407
+ // NOTE: normalise is always called before this, so it should be impossible for the numeral set to be unknown at this point.
2408
+ denormalise(str) {
2409
+ if (!this.#userNumeralSet || this.#userNumeralSet === "ascii") {
2410
+ return str;
2411
+ }
2412
+ const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
2413
+ return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
2414
+ }
2415
+ // Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9.
2416
+ // Tracks the user's numeral set as a side effect so denormalise can mirror it back.
2417
+ normalise(str) {
2418
+ if (!str) {
2419
+ return "";
2420
+ }
2421
+ this.#updateNumeralSet(str);
2422
+ if (this.#userNumeralSet === "ascii") {
2423
+ return str;
2424
+ }
2425
+ return _Numerals.toAscii(str);
2426
+ }
2427
+ isAscii() {
2428
+ return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
2429
+ }
2430
+ };
2431
+
2432
+ // packages/core/src/js/core/ui.ts
2342
2433
  var UI = class _UI {
2343
2434
  // private
2344
2435
  #options;
@@ -2346,6 +2437,7 @@ var _factory = (() => {
2346
2437
  #isRTL;
2347
2438
  #originalPaddingLeft = "";
2348
2439
  #countries;
2440
+ #searchTokens;
2349
2441
  #searchDebounceTimer = null;
2350
2442
  #inlineDropdownHeight;
2351
2443
  #countryContainerEl;
@@ -2391,8 +2483,9 @@ var _factory = (() => {
2391
2483
  }
2392
2484
  }
2393
2485
  //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
2394
- buildMarkup(countries) {
2486
+ buildMarkup(countries, searchTokens) {
2395
2487
  this.#countries = countries;
2488
+ this.#searchTokens = searchTokens;
2396
2489
  this.telInputEl.classList.add("iti__tel-input");
2397
2490
  if (!this.telInputEl.hasAttribute("type")) {
2398
2491
  this.telInputEl.setAttribute("type", "tel");
@@ -2760,7 +2853,12 @@ var _factory = (() => {
2760
2853
  if (query === "") {
2761
2854
  matchedCountries = this.#countries;
2762
2855
  } else {
2763
- matchedCountries = getMatchedCountries(this.#countries, query);
2856
+ const normalisedQuery = Numerals.toAscii(query);
2857
+ matchedCountries = getMatchedCountries(
2858
+ this.#countries,
2859
+ this.#searchTokens,
2860
+ normalisedQuery
2861
+ );
2764
2862
  }
2765
2863
  this.#showFilteredCountries(matchedCountries);
2766
2864
  }
@@ -3055,7 +3153,11 @@ var _factory = (() => {
3055
3153
  }
3056
3154
  //* Hidden search (countrySearch disabled): jump to the first list item whose name starts with the query.
3057
3155
  #searchForCountry(query) {
3058
- const match = findFirstCountryStartingWith(this.#countries, query);
3156
+ const match = findFirstCountryStartingWith(
3157
+ this.#countries,
3158
+ this.#searchTokens,
3159
+ query
3160
+ );
3059
3161
  if (match) {
3060
3162
  const listItem = this.#listItemByIso2.get(match.iso2);
3061
3163
  this.#highlightListItem(listItem);
@@ -3080,7 +3182,7 @@ var _factory = (() => {
3080
3182
  }
3081
3183
  if (iso2 && !this.#selectedListItemEl) {
3082
3184
  const newListItem = this.#countryListEl.querySelector(
3083
- `[data-country-code="${iso2}"]`
3185
+ `[data-iso2="${iso2}"]`
3084
3186
  );
3085
3187
  if (newListItem) {
3086
3188
  newListItem.setAttribute(ARIA.SELECTED, "true");
@@ -3268,7 +3370,7 @@ var _factory = (() => {
3268
3370
  }
3269
3371
  };
3270
3372
 
3271
- // src/js/data/country-data.ts
3373
+ // packages/core/src/js/data/country-data.ts
3272
3374
  var processAllCountries = (options) => {
3273
3375
  const { onlyCountries, excludeCountries } = options;
3274
3376
  if (onlyCountries?.length) {
@@ -3283,7 +3385,7 @@ var _factory = (() => {
3283
3385
  return [...data_default];
3284
3386
  };
3285
3387
  var generateCountryNames = (countries, options) => {
3286
- const { countryNameLocale, i18n } = options;
3388
+ const { countryNameLocale, countryNameOverrides } = options;
3287
3389
  let displayNames;
3288
3390
  try {
3289
3391
  const hasDisplayNames = typeof Intl !== "undefined" && typeof Intl.DisplayNames === "function";
@@ -3299,7 +3401,7 @@ var _factory = (() => {
3299
3401
  displayNames = null;
3300
3402
  }
3301
3403
  for (const c of countries) {
3302
- c.name = i18n[c.iso2] || displayNames?.of(c.iso2.toUpperCase()) || "";
3404
+ c.name = countryNameOverrides[c.iso2] || displayNames?.of(c.iso2.toUpperCase()) || "";
3303
3405
  }
3304
3406
  };
3305
3407
  var processDialCodes = (countries) => {
@@ -3367,15 +3469,8 @@ var _factory = (() => {
3367
3469
  return a.name.localeCompare(b.name);
3368
3470
  });
3369
3471
  };
3370
- var cacheSearchTokens = (countries) => {
3371
- for (const c of countries) {
3372
- c.normalisedName = normaliseString(c.name);
3373
- c.initials = c.normalisedName.split(/[^a-z]/).map((word) => word[0]).join("");
3374
- c.dialCodePlus = `+${c.dialCode}`;
3375
- }
3376
- };
3377
3472
 
3378
- // src/js/data/intl-regionless.ts
3473
+ // packages/core/src/js/data/intl-regionless.ts
3379
3474
  var regionlessDialCodes = /* @__PURE__ */ new Set([
3380
3475
  "800",
3381
3476
  "808",
@@ -3391,7 +3486,7 @@ var _factory = (() => {
3391
3486
  return number.startsWith("+") && regionlessDialCodes.has(dialCode);
3392
3487
  };
3393
3488
 
3394
- // src/js/format/formatting.ts
3489
+ // packages/core/src/js/format/formatting.ts
3395
3490
  var stripSeparateDialCode = (fullNumber, hasValidDialCode, separateDialCode, selectedCountryData) => {
3396
3491
  if (!separateDialCode || !hasValidDialCode) {
3397
3492
  return fullNumber;
@@ -3410,7 +3505,7 @@ var _factory = (() => {
3410
3505
  return result;
3411
3506
  };
3412
3507
 
3413
- // src/js/format/caret.ts
3508
+ // packages/core/src/js/format/caret.ts
3414
3509
  var computeNewCaretPosition = (relevantChars, formattedValue, prevCaretPos, isDeleteForwards) => {
3415
3510
  if (prevCaretPos === 0 && !isDeleteForwards) {
3416
3511
  return 0;
@@ -3430,7 +3525,7 @@ var _factory = (() => {
3430
3525
  return formattedValue.length;
3431
3526
  };
3432
3527
 
3433
- // src/js/data/nanp-regionless.ts
3528
+ // packages/core/src/js/data/nanp-regionless.ts
3434
3529
  var regionlessNanpAreaCodes = /* @__PURE__ */ new Set([
3435
3530
  "800",
3436
3531
  "822",
@@ -3459,55 +3554,7 @@ var _factory = (() => {
3459
3554
  return false;
3460
3555
  };
3461
3556
 
3462
- // src/js/core/numerals.ts
3463
- var Numerals = class {
3464
- #userNumeralSet;
3465
- constructor(initialValue) {
3466
- if (initialValue) {
3467
- this.#updateNumeralSet(initialValue);
3468
- }
3469
- }
3470
- // If any Arabic-Indic digits, then label it as that set. Same for Persian. Otherwise assume ASCII.
3471
- #updateNumeralSet(str) {
3472
- if (/[\u0660-\u0669]/.test(str)) {
3473
- this.#userNumeralSet = "arabic-indic";
3474
- } else if (/[\u06F0-\u06F9]/.test(str)) {
3475
- this.#userNumeralSet = "persian";
3476
- } else {
3477
- this.#userNumeralSet = "ascii";
3478
- }
3479
- }
3480
- // Denormalise ASCII 0-9 to the user's numeral set. If not yet known, return as-is.
3481
- // NOTE: normalise is always called before this, so it should be impossible for the numeral set to be unknown at this point.
3482
- denormalise(str) {
3483
- if (!this.#userNumeralSet || this.#userNumeralSet === "ascii") {
3484
- return str;
3485
- }
3486
- const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
3487
- return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
3488
- }
3489
- // Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
3490
- normalise(str) {
3491
- if (!str) {
3492
- return "";
3493
- }
3494
- this.#updateNumeralSet(str);
3495
- if (this.#userNumeralSet === "ascii") {
3496
- return str;
3497
- }
3498
- const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
3499
- const regex = this.#userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
3500
- return str.replace(
3501
- regex,
3502
- (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base))
3503
- );
3504
- }
3505
- isAscii() {
3506
- return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
3507
- }
3508
- };
3509
-
3510
- // src/js/intlTelInput.ts
3557
+ // packages/core/src/js/intlTelInput.ts
3511
3558
  var nextId = 0;
3512
3559
  var ensureUtils = (methodName) => {
3513
3560
  if (!intlTelInput.utils) {
@@ -3541,6 +3588,7 @@ var _factory = (() => {
3541
3588
  #dialCodeToIso2Map;
3542
3589
  #dialCodes;
3543
3590
  #countryByIso2;
3591
+ #searchTokens;
3544
3592
  #selectedCountry = null;
3545
3593
  #maxCoreNumberLength = null;
3546
3594
  #fallbackCountryIso2;
@@ -3597,7 +3645,7 @@ var _factory = (() => {
3597
3645
  #init() {
3598
3646
  this.#abortController = new AbortController();
3599
3647
  this.#processCountryData();
3600
- this.#ui.buildMarkup(this.#countries);
3648
+ this.#ui.buildMarkup(this.#countries, this.#searchTokens);
3601
3649
  this.#setInitialState();
3602
3650
  this.#initListeners();
3603
3651
  this.#startAsyncLoads();
@@ -3612,7 +3660,7 @@ var _factory = (() => {
3612
3660
  #processCountryData() {
3613
3661
  generateCountryNames(this.#countries, this.#options);
3614
3662
  sortCountries(this.#countries, this.#options);
3615
- cacheSearchTokens(this.#countries);
3663
+ this.#searchTokens = buildSearchTokens(this.#countries);
3616
3664
  }
3617
3665
  //* Set the initial state of the input value and the selected country by:
3618
3666
  //* 1. Extracting a dial code from the given number
@@ -3673,7 +3721,7 @@ var _factory = (() => {
3673
3721
  if (this.#utilsDeferred) {
3674
3722
  const { loadUtils } = this.#options;
3675
3723
  const doAttachUtils = () => {
3676
- intlTelInput.attachUtils(loadUtils)?.catch(() => {
3724
+ intlTelInput.attachUtils(loadUtils).catch(() => {
3677
3725
  });
3678
3726
  };
3679
3727
  if (intlTelInput.documentReady()) {
@@ -3693,7 +3741,7 @@ var _factory = (() => {
3693
3741
  }
3694
3742
  }
3695
3743
  //* Perform the geo ip lookup.
3696
- #loadAutoCountry() {
3744
+ async #loadAutoCountry() {
3697
3745
  if (intlTelInput.autoCountry) {
3698
3746
  this.#handleAutoCountryLoaded();
3699
3747
  return;
@@ -3704,19 +3752,18 @@ var _factory = (() => {
3704
3752
  }
3705
3753
  intlTelInput.startedLoadingAutoCountry = true;
3706
3754
  if (typeof this.#options.geoIpLookup === "function") {
3707
- const successCallback = (iso2 = "") => {
3708
- const iso2Lower = iso2.toLowerCase();
3709
- if (isIso2(iso2Lower)) {
3710
- intlTelInput.autoCountry = iso2Lower;
3711
- setTimeout(() => _Iti.forEachInstance("handleAutoCountryLoaded"));
3712
- } else {
3755
+ try {
3756
+ const iso2 = await this.#options.geoIpLookup();
3757
+ const iso2Lower = typeof iso2 === "string" ? iso2.toLowerCase() : "";
3758
+ if (!isIso2(iso2Lower)) {
3713
3759
  _Iti.forEachInstance("handleAutoCountryFailure");
3760
+ return;
3714
3761
  }
3715
- };
3716
- const failureCallback = () => {
3762
+ intlTelInput.autoCountry = iso2Lower;
3763
+ setTimeout(() => _Iti.forEachInstance("handleAutoCountryLoaded"));
3764
+ } catch {
3717
3765
  _Iti.forEachInstance("handleAutoCountryFailure");
3718
- };
3719
- this.#options.geoIpLookup(successCallback, failureCallback);
3766
+ }
3720
3767
  }
3721
3768
  }
3722
3769
  #openDropdownWithPlus() {
@@ -3735,7 +3782,7 @@ var _factory = (() => {
3735
3782
  #bindAllTelInputListeners() {
3736
3783
  this.#bindInputListener();
3737
3784
  this.#bindKeydownListener();
3738
- this.#bindPasteListener();
3785
+ this.#bindStrictPasteListener();
3739
3786
  }
3740
3787
  //* Android workaround for handling plus when separateDialCode enabled (as impossible to handle with keydown/keyup, for which e.key always returns "Unidentified", see https://stackoverflow.com/q/59584061/217866)
3741
3788
  #handleAndroidPlusKey(inputValue) {
@@ -3903,15 +3950,16 @@ var _factory = (() => {
3903
3950
  e.preventDefault();
3904
3951
  }
3905
3952
  };
3906
- #bindPasteListener() {
3953
+ #bindStrictPasteListener() {
3907
3954
  if (!this.#options.strictMode) {
3908
3955
  return;
3909
3956
  }
3910
- this.#ui.telInputEl.addEventListener("paste", this.#handlePasteEvent, {
3957
+ this.#ui.telInputEl.addEventListener("paste", this.#handleStrictPasteEvent, {
3911
3958
  signal: this.#abortController.signal
3912
3959
  });
3913
3960
  }
3914
- #handlePasteEvent = (e) => {
3961
+ // Handle paste events when strictMode is enabled by sanitising the pasted content before it's inserted into the input, and rejecting it entirely if it would result in an invalid number
3962
+ #handleStrictPasteEvent = (e) => {
3915
3963
  e.preventDefault();
3916
3964
  const input = this.#ui.telInputEl;
3917
3965
  const selStart = input.selectionStart;
@@ -3930,6 +3978,15 @@ var _factory = (() => {
3930
3978
  const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3931
3979
  let newValue = before + sanitised + after;
3932
3980
  let rejectReason = sanitised !== pasted ? "invalid" : null;
3981
+ if (newValue.length > 30) {
3982
+ this.#playStrictRejectAnimation();
3983
+ this.#dispatchEvent(EVENTS.STRICT_REJECT, {
3984
+ source: "paste",
3985
+ rejectedInput: pastedRaw,
3986
+ reason: "max-length"
3987
+ });
3988
+ return;
3989
+ }
3933
3990
  if (newValue.length > 5 && intlTelInput.utils) {
3934
3991
  let coreNumber = intlTelInput.utils.getCoreNumber(newValue, iso2);
3935
3992
  while (coreNumber.length === 0 && newValue.length > 0) {
@@ -4021,8 +4078,7 @@ var _factory = (() => {
4021
4078
  if (formatOnDisplay && intlTelInput.utils && this.#selectedCountry) {
4022
4079
  const isRegionless = hasRegionlessDialCode(fullNumber);
4023
4080
  const useNational = nationalMode && !isRegionless || !number.startsWith("+") && !separateDialCode;
4024
- const { NATIONAL, INTERNATIONAL } = intlTelInput.utils.numberFormat;
4025
- const format = useNational ? NATIONAL : INTERNATIONAL;
4081
+ const format = useNational ? NUMBER_FORMAT.NATIONAL : NUMBER_FORMAT.INTERNATIONAL;
4026
4082
  number = intlTelInput.utils.formatNumber(
4027
4083
  number,
4028
4084
  this.#selectedCountry?.iso2,
@@ -4142,11 +4198,10 @@ var _factory = (() => {
4142
4198
  this.#maxCoreNumberLength = null;
4143
4199
  return;
4144
4200
  }
4145
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
4146
4201
  let exampleNumber = intlTelInput.utils.getExampleNumber(
4147
4202
  iso2,
4148
4203
  false,
4149
- numberType,
4204
+ placeholderNumberType,
4150
4205
  true
4151
4206
  );
4152
4207
  let validNumber = exampleNumber;
@@ -4176,11 +4231,10 @@ var _factory = (() => {
4176
4231
  if (!intlTelInput.utils || !shouldSetPlaceholder) {
4177
4232
  return;
4178
4233
  }
4179
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
4180
4234
  let placeholder = this.#selectedCountry ? intlTelInput.utils.getExampleNumber(
4181
4235
  this.#selectedCountry.iso2,
4182
4236
  nationalMode,
4183
- numberType
4237
+ placeholderNumberType
4184
4238
  ) : "";
4185
4239
  placeholder = this.#prepareNumberForInput(placeholder);
4186
4240
  if (typeof customPlaceholder === "function") {
@@ -4290,19 +4344,9 @@ var _factory = (() => {
4290
4344
  );
4291
4345
  return this.#truncateToMaxLength(number);
4292
4346
  }
4293
- //* Return only the public-facing subset of the selected country data.
4294
- #getPublicCountryData() {
4295
- const d = this.#selectedCountry;
4296
- if (!d) {
4297
- return null;
4298
- }
4299
- const { iso2, dialCode, name } = d;
4300
- return { iso2, dialCode, name };
4301
- }
4302
4347
  //* Dispatch the 'countrychange' event.
4303
4348
  #dispatchCountryChangeEvent() {
4304
- const countryData = this.#getPublicCountryData();
4305
- this.#dispatchEvent(EVENTS.COUNTRY_CHANGE, countryData);
4349
+ this.#dispatchEvent(EVENTS.COUNTRY_CHANGE, this.#selectedCountry ?? null);
4306
4350
  }
4307
4351
  //**************************
4308
4352
  //* INTERNAL METHODS
@@ -4393,7 +4437,7 @@ var _factory = (() => {
4393
4437
  this.#selectedCountry?.iso2
4394
4438
  );
4395
4439
  }
4396
- //* Format the number to the given format.
4440
+ //* Format the number to the given format (defaults to "E164").
4397
4441
  getNumber(format) {
4398
4442
  if (!this.#isActive) {
4399
4443
  return "";
@@ -4408,10 +4452,10 @@ var _factory = (() => {
4408
4452
  );
4409
4453
  return this.#numerals.denormalise(formattedNumber);
4410
4454
  }
4411
- //* Get the type of the entered number e.g. landline/mobile.
4455
+ //* Get the type of the entered number e.g. "FIXED_LINE" / "MOBILE", or null if it can't be determined / instance is destroyed.
4412
4456
  getNumberType() {
4413
4457
  if (!this.#isActive) {
4414
- return SENTINELS.UNKNOWN_NUMBER_TYPE;
4458
+ return null;
4415
4459
  }
4416
4460
  ensureUtils("getNumberType");
4417
4461
  return intlTelInput.utils.getNumberType(
@@ -4421,12 +4465,12 @@ var _factory = (() => {
4421
4465
  }
4422
4466
  //* Get the country data for the currently selected country.
4423
4467
  getSelectedCountryData() {
4424
- return this.#getPublicCountryData();
4468
+ return this.#selectedCountry ?? null;
4425
4469
  }
4426
- //* Get the validation error.
4470
+ //* Get the validation error e.g. "TOO_SHORT" / "TOO_LONG", or null if it can't be determined / instance is destroyed.
4427
4471
  getValidationError() {
4428
4472
  if (!this.#isActive) {
4429
- return SENTINELS.UNKNOWN_VALIDATION_ERROR;
4473
+ return null;
4430
4474
  }
4431
4475
  ensureUtils("getValidationError");
4432
4476
  const iso2 = this.#selectedCountry?.iso2;
@@ -4575,39 +4619,31 @@ var _factory = (() => {
4575
4619
  });
4576
4620
  }
4577
4621
  };
4578
- var attachUtils = (source) => {
4579
- if (!intlTelInput.utils && !intlTelInput.startedLoadingUtils) {
4580
- let loadCall;
4581
- if (typeof source === "function") {
4582
- try {
4583
- loadCall = Promise.resolve(source());
4584
- } catch (error) {
4585
- return Promise.reject(error);
4586
- }
4587
- } else {
4588
- return Promise.reject(
4589
- new TypeError(
4590
- `The argument passed to attachUtils must be a function that returns a promise for the utils module, not ${typeof source}`
4591
- )
4622
+ var attachUtils = async (source) => {
4623
+ if (intlTelInput.utils || intlTelInput.startedLoadingUtils) {
4624
+ return null;
4625
+ }
4626
+ if (typeof source !== "function") {
4627
+ throw new TypeError(
4628
+ `The argument passed to attachUtils must be a function that returns a promise for the utils module, not ${typeof source}`
4629
+ );
4630
+ }
4631
+ intlTelInput.startedLoadingUtils = true;
4632
+ try {
4633
+ const module = await source();
4634
+ const utils = module?.default;
4635
+ if (!utils || typeof utils !== "object") {
4636
+ throw new TypeError(
4637
+ "The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
4592
4638
  );
4593
4639
  }
4594
- intlTelInput.startedLoadingUtils = true;
4595
- return loadCall.then((module) => {
4596
- const utils = module?.default;
4597
- if (!utils || typeof utils !== "object") {
4598
- throw new TypeError(
4599
- "The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
4600
- );
4601
- }
4602
- intlTelInput.utils = utils;
4603
- Iti.forEachInstance("handleUtilsLoaded");
4604
- return true;
4605
- }).catch((error) => {
4606
- Iti.forEachInstance("handleUtilsFailure", error);
4607
- throw error;
4608
- });
4640
+ intlTelInput.utils = utils;
4641
+ Iti.forEachInstance("handleUtilsLoaded");
4642
+ return true;
4643
+ } catch (error) {
4644
+ Iti.forEachInstance("handleUtilsFailure", error);
4645
+ throw error;
4609
4646
  }
4610
- return null;
4611
4647
  };
4612
4648
  var intlTelInput = Object.assign(
4613
4649
  (input, options) => {
@@ -4632,7 +4668,10 @@ var _factory = (() => {
4632
4668
  attachUtils,
4633
4669
  startedLoadingUtils: false,
4634
4670
  startedLoadingAutoCountry: false,
4635
- version: "27.3.0"
4671
+ version: "28.0.0",
4672
+ NUMBER_FORMAT,
4673
+ NUMBER_TYPE,
4674
+ VALIDATION_ERROR
4636
4675
  }
4637
4676
  );
4638
4677
  var intlTelInput_default = intlTelInput;