intl-tel-input 27.0.0 → 27.0.2

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.
@@ -269,7 +269,63 @@ var rawCountryData = [
269
269
  // Canada
270
270
  "1",
271
271
  1,
272
- ["204", "226", "236", "249", "250", "257", "263", "289", "306", "343", "354", "365", "367", "368", "382", "403", "416", "418", "428", "431", "437", "438", "450", "468", "474", "506", "514", "519", "548", "579", "581", "584", "587", "604", "613", "639", "647", "672", "683", "705", "709", "742", "753", "778", "780", "782", "807", "819", "825", "867", "873", "879", "902", "905", "942"],
272
+ [
273
+ "204",
274
+ "226",
275
+ "236",
276
+ "249",
277
+ "250",
278
+ "257",
279
+ "263",
280
+ "289",
281
+ "306",
282
+ "343",
283
+ "354",
284
+ "365",
285
+ "367",
286
+ "368",
287
+ "382",
288
+ "403",
289
+ "416",
290
+ "418",
291
+ "428",
292
+ "431",
293
+ "437",
294
+ "438",
295
+ "450",
296
+ "468",
297
+ "474",
298
+ "506",
299
+ "514",
300
+ "519",
301
+ "548",
302
+ "579",
303
+ "581",
304
+ "584",
305
+ "587",
306
+ "604",
307
+ "613",
308
+ "639",
309
+ "647",
310
+ "672",
311
+ "683",
312
+ "705",
313
+ "709",
314
+ "742",
315
+ "753",
316
+ "778",
317
+ "780",
318
+ "782",
319
+ "807",
320
+ "819",
321
+ "825",
322
+ "867",
323
+ "873",
324
+ "879",
325
+ "902",
326
+ "905",
327
+ "942"
328
+ ],
273
329
  "1"
274
330
  ],
275
331
  [
@@ -1922,9 +1978,10 @@ var warn = (message) => {
1922
1978
  console.warn(`[intl-tel-input] ${message}`);
1923
1979
  };
1924
1980
  var warnOption = (optionName, expectedType, actualValue) => {
1925
- warn(`Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`);
1981
+ warn(
1982
+ `Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`
1983
+ );
1926
1984
  };
1927
- var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
1928
1985
  var validateIso2Array = (key, value) => {
1929
1986
  const expectedType = "an array of ISO2 country code strings";
1930
1987
  if (!Array.isArray(value)) {
@@ -1957,7 +2014,7 @@ var validateOptions = (customOptions) => {
1957
2014
  }
1958
2015
  const validatedOptions = {};
1959
2016
  for (const [key, value] of Object.entries(customOptions)) {
1960
- if (!hasOwn(defaults, key)) {
2017
+ if (!Object.hasOwn(defaults, key)) {
1961
2018
  warn(`Unknown option '${key}'. Ignoring.`);
1962
2019
  continue;
1963
2020
  }
@@ -2051,8 +2108,12 @@ var validateOptions = (customOptions) => {
2051
2108
  break;
2052
2109
  }
2053
2110
  const lower = value.toLowerCase();
2054
- if (lower && (lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower))) {
2055
- warnOption("initialCountry", "a valid ISO2 country code or 'auto'", value);
2111
+ if (lower && lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower)) {
2112
+ warnOption(
2113
+ "initialCountry",
2114
+ "a valid ISO2 country code or 'auto'",
2115
+ value
2116
+ );
2056
2117
  break;
2057
2118
  }
2058
2119
  validatedOptions[key] = value;
@@ -2069,14 +2130,22 @@ var validateOptions = (customOptions) => {
2069
2130
  case "allowedNumberTypes":
2070
2131
  if (value !== null) {
2071
2132
  if (!Array.isArray(value)) {
2072
- warnOption("allowedNumberTypes", "an array of number types or null", value);
2133
+ warnOption(
2134
+ "allowedNumberTypes",
2135
+ "an array of number types or null",
2136
+ value
2137
+ );
2073
2138
  break;
2074
2139
  }
2075
2140
  let allValid = true;
2076
2141
  for (const v of value) {
2077
2142
  if (typeof v !== "string" || !NUMBER_TYPE_SET.has(v)) {
2078
2143
  const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
2079
- warnOption("allowedNumberTypes", `an array of valid number types (${validTypes})`, v);
2144
+ warnOption(
2145
+ "allowedNumberTypes",
2146
+ `an array of valid number types (${validTypes})`,
2147
+ v
2148
+ );
2080
2149
  allValid = false;
2081
2150
  break;
2082
2151
  }
@@ -2233,6 +2302,7 @@ var UI = class _UI {
2233
2302
  #searchResultsA11yText;
2234
2303
  #dropdownForContainer;
2235
2304
  #selectedItem = null;
2305
+ #viewportHandler = null;
2236
2306
  // public
2237
2307
  telInput;
2238
2308
  countryContainer;
@@ -2283,16 +2353,12 @@ var UI = class _UI {
2283
2353
  const wrapper = this.#createWrapperAndInsert();
2284
2354
  this.#maybeBuildCountryContainer(wrapper);
2285
2355
  wrapper.appendChild(this.telInput);
2356
+ this.#maybeEnsureDropdownWidthSet();
2286
2357
  this.#maybeUpdateInputPaddingAndReveal();
2287
2358
  this.#maybeBuildHiddenInputs(wrapper);
2288
2359
  }
2289
2360
  #createWrapperAndInsert() {
2290
- const {
2291
- allowDropdown,
2292
- showFlags,
2293
- containerClass,
2294
- useFullscreenPopup
2295
- } = this.#options;
2361
+ const { allowDropdown, showFlags, containerClass, useFullscreenPopup } = this.#options;
2296
2362
  const parentClasses = buildClassNames({
2297
2363
  iti: true,
2298
2364
  "iti--allow-dropdown": allowDropdown,
@@ -2309,72 +2375,74 @@ var UI = class _UI {
2309
2375
  }
2310
2376
  #maybeBuildCountryContainer(wrapper) {
2311
2377
  const { allowDropdown, separateDialCode, showFlags } = this.#options;
2312
- if (allowDropdown || showFlags || separateDialCode) {
2313
- this.countryContainer = createEl(
2314
- "div",
2315
- // visibly hidden until we measure it's width to set the input padding correctly
2316
- { class: `iti__country-container ${CLASSES.V_HIDE}` },
2317
- wrapper
2378
+ if (!allowDropdown && !showFlags && !separateDialCode) {
2379
+ return;
2380
+ }
2381
+ this.countryContainer = createEl(
2382
+ "div",
2383
+ // visibly hidden until we measure its width to set the input padding correctly
2384
+ { class: `iti__country-container ${CLASSES.V_HIDE}` },
2385
+ wrapper
2386
+ );
2387
+ if (allowDropdown) {
2388
+ this.selectedCountry = createEl(
2389
+ "button",
2390
+ {
2391
+ type: "button",
2392
+ class: "iti__selected-country",
2393
+ [ARIA.EXPANDED]: "false",
2394
+ [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2395
+ [ARIA.HASPOPUP]: "dialog",
2396
+ [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2397
+ },
2398
+ this.countryContainer
2318
2399
  );
2319
- if (allowDropdown) {
2320
- this.selectedCountry = createEl(
2321
- "button",
2322
- {
2323
- type: "button",
2324
- class: "iti__selected-country",
2325
- [ARIA.EXPANDED]: "false",
2326
- [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2327
- [ARIA.HASPOPUP]: "dialog",
2328
- [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2329
- },
2330
- this.countryContainer
2331
- );
2332
- if (this.telInput.disabled) {
2333
- this.selectedCountry.setAttribute("disabled", "true");
2334
- }
2335
- } else {
2336
- this.selectedCountry = createEl(
2337
- "div",
2338
- { class: "iti__selected-country" },
2339
- this.countryContainer
2340
- );
2400
+ if (this.telInput.disabled) {
2401
+ this.selectedCountry.setAttribute("disabled", "true");
2341
2402
  }
2342
- const selectedCountryPrimary = createEl(
2403
+ } else {
2404
+ this.selectedCountry = createEl(
2343
2405
  "div",
2344
- { class: "iti__selected-country-primary" },
2345
- this.selectedCountry
2406
+ { class: "iti__selected-country" },
2407
+ this.countryContainer
2346
2408
  );
2347
- this.selectedCountryInner = createEl(
2409
+ }
2410
+ const selectedCountryPrimary = createEl(
2411
+ "div",
2412
+ { class: "iti__selected-country-primary" },
2413
+ this.selectedCountry
2414
+ );
2415
+ this.selectedCountryInner = createEl(
2416
+ "div",
2417
+ { class: CLASSES.FLAG },
2418
+ selectedCountryPrimary
2419
+ );
2420
+ if (allowDropdown) {
2421
+ this.#dropdownArrow = createEl(
2348
2422
  "div",
2349
- { class: CLASSES.FLAG },
2423
+ { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2350
2424
  selectedCountryPrimary
2351
2425
  );
2352
- if (allowDropdown) {
2353
- this.#dropdownArrow = createEl(
2354
- "div",
2355
- { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2356
- selectedCountryPrimary
2357
- );
2358
- }
2359
- if (separateDialCode) {
2360
- this.#selectedDialCode = createEl(
2361
- "div",
2362
- { class: "iti__selected-dial-code" },
2363
- this.selectedCountry
2364
- );
2365
- }
2366
- if (allowDropdown) {
2367
- this.#buildDropdownContent();
2368
- }
2426
+ }
2427
+ if (separateDialCode) {
2428
+ this.#selectedDialCode = createEl(
2429
+ "div",
2430
+ { class: "iti__selected-dial-code" },
2431
+ this.selectedCountry
2432
+ );
2433
+ }
2434
+ if (allowDropdown) {
2435
+ this.#buildDropdownContent();
2369
2436
  }
2370
2437
  }
2371
2438
  #maybeEnsureDropdownWidthSet() {
2372
- const { fixDropdownWidth } = this.#options;
2373
- if (fixDropdownWidth && !this.#dropdownContent.style.width) {
2374
- const inputWidth = this.telInput.offsetWidth;
2375
- if (inputWidth > 0) {
2376
- this.#dropdownContent.style.width = `${inputWidth}px`;
2377
- }
2439
+ const { fixDropdownWidth, allowDropdown } = this.#options;
2440
+ if (!allowDropdown || !fixDropdownWidth || this.#dropdownContent.style.width) {
2441
+ return;
2442
+ }
2443
+ const inputWidth = this.telInput.offsetWidth;
2444
+ if (inputWidth > 0) {
2445
+ this.#dropdownContent.style.width = `${inputWidth}px`;
2378
2446
  }
2379
2447
  }
2380
2448
  #buildDropdownContent() {
@@ -2414,7 +2482,6 @@ var UI = class _UI {
2414
2482
  this.#updateSearchResultsA11yText();
2415
2483
  }
2416
2484
  if (!useFullscreenPopup) {
2417
- this.#maybeEnsureDropdownWidthSet();
2418
2485
  this.#inlineDropdownHeight = this.#getHiddenInlineDropdownHeight();
2419
2486
  if (countrySearch) {
2420
2487
  this.#dropdownContent.style.height = `${this.#inlineDropdownHeight}px`;
@@ -2496,43 +2563,45 @@ var UI = class _UI {
2496
2563
  this.#searchNoResults.textContent = i18n.searchEmptyState ?? null;
2497
2564
  }
2498
2565
  #maybeUpdateInputPaddingAndReveal() {
2499
- if (this.countryContainer) {
2500
- this.#updateInputPadding();
2501
- this.countryContainer.classList.remove(CLASSES.V_HIDE);
2566
+ if (!this.countryContainer) {
2567
+ return;
2502
2568
  }
2569
+ this.#updateInputPadding();
2570
+ this.countryContainer.classList.remove(CLASSES.V_HIDE);
2503
2571
  }
2504
2572
  #maybeBuildHiddenInputs(wrapper) {
2505
2573
  const { hiddenInput } = this.#options;
2506
- if (hiddenInput) {
2507
- const telInputName = this.telInput.getAttribute("name") || "";
2508
- const names = hiddenInput(telInputName);
2509
- if (names.phone) {
2510
- const existingInput = this.telInput.form?.querySelector(
2511
- `input[name="${names.phone}"]`
2512
- );
2513
- if (existingInput) {
2514
- this.hiddenInputPhone = existingInput;
2515
- } else {
2516
- this.hiddenInputPhone = createEl("input", {
2517
- type: "hidden",
2518
- name: names.phone
2519
- });
2520
- wrapper.appendChild(this.hiddenInputPhone);
2521
- }
2574
+ if (!hiddenInput) {
2575
+ return;
2576
+ }
2577
+ const telInputName = this.telInput.getAttribute("name") || "";
2578
+ const names = hiddenInput(telInputName);
2579
+ if (names.phone) {
2580
+ const existingInput = this.telInput.form?.querySelector(
2581
+ `input[name="${names.phone}"]`
2582
+ );
2583
+ if (existingInput) {
2584
+ this.hiddenInputPhone = existingInput;
2585
+ } else {
2586
+ this.hiddenInputPhone = createEl("input", {
2587
+ type: "hidden",
2588
+ name: names.phone
2589
+ });
2590
+ wrapper.appendChild(this.hiddenInputPhone);
2522
2591
  }
2523
- if (names.country) {
2524
- const existingInput = this.telInput.form?.querySelector(
2525
- `input[name="${names.country}"]`
2526
- );
2527
- if (existingInput) {
2528
- this.hiddenInputCountry = existingInput;
2529
- } else {
2530
- this.hiddenInputCountry = createEl("input", {
2531
- type: "hidden",
2532
- name: names.country
2533
- });
2534
- wrapper.appendChild(this.hiddenInputCountry);
2535
- }
2592
+ }
2593
+ if (names.country) {
2594
+ const existingInput = this.telInput.form?.querySelector(
2595
+ `input[name="${names.country}"]`
2596
+ );
2597
+ if (existingInput) {
2598
+ this.hiddenInputCountry = existingInput;
2599
+ } else {
2600
+ this.hiddenInputCountry = createEl("input", {
2601
+ type: "hidden",
2602
+ name: names.country
2603
+ });
2604
+ wrapper.appendChild(this.hiddenInputCountry);
2536
2605
  }
2537
2606
  }
2538
2607
  }
@@ -2591,30 +2660,32 @@ var UI = class _UI {
2591
2660
  //* To get the right styling to apply, all we need is a shallow clone of the container,
2592
2661
  //* and then to inject a deep clone of the selectedCountry element.
2593
2662
  #getHiddenSelectedCountryWidth() {
2594
- if (this.telInput.parentNode) {
2595
- const body = _UI.#getBody();
2596
- const containerClone = this.telInput.parentNode.cloneNode(
2597
- false
2598
- );
2599
- containerClone.style.visibility = "hidden";
2600
- body.appendChild(containerClone);
2601
- const countryContainerClone = this.countryContainer.cloneNode();
2602
- containerClone.appendChild(countryContainerClone);
2603
- const selectedCountryClone = this.selectedCountry.cloneNode(
2604
- true
2605
- );
2606
- countryContainerClone.appendChild(selectedCountryClone);
2607
- const width = selectedCountryClone.offsetWidth;
2608
- body.removeChild(containerClone);
2609
- return width;
2663
+ if (!this.telInput.parentNode) {
2664
+ return 0;
2610
2665
  }
2611
- return 0;
2666
+ const body = _UI.#getBody();
2667
+ const containerClone = this.telInput.parentNode.cloneNode(
2668
+ false
2669
+ );
2670
+ containerClone.style.visibility = "hidden";
2671
+ body.appendChild(containerClone);
2672
+ const countryContainerClone = this.countryContainer.cloneNode();
2673
+ containerClone.appendChild(countryContainerClone);
2674
+ const selectedCountryClone = this.selectedCountry.cloneNode(
2675
+ true
2676
+ );
2677
+ countryContainerClone.appendChild(selectedCountryClone);
2678
+ const width = selectedCountryClone.offsetWidth;
2679
+ body.removeChild(containerClone);
2680
+ return width;
2612
2681
  }
2613
- // this is run before we add the dropdown to the DOM
2682
+ // Get the dropdown height (before it is added to the DOM)
2614
2683
  #getHiddenInlineDropdownHeight() {
2615
2684
  const body = _UI.#getBody();
2616
2685
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2617
- const tempContainer = createEl("div", { class: "iti iti--inline-dropdown" });
2686
+ const tempContainer = createEl("div", {
2687
+ class: "iti iti--inline-dropdown"
2688
+ });
2618
2689
  tempContainer.appendChild(this.#dropdownContent);
2619
2690
  tempContainer.style.visibility = "hidden";
2620
2691
  body.appendChild(tempContainer);
@@ -2687,7 +2758,10 @@ var UI = class _UI {
2687
2758
  this.highlightedItem.classList.add(CLASSES.HIGHLIGHT);
2688
2759
  if (this.#options.countrySearch) {
2689
2760
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2690
- this.searchInput.setAttribute(ARIA.ACTIVE_DESCENDANT, activeDescendant);
2761
+ this.searchInput.setAttribute(
2762
+ ARIA.ACTIVE_DESCENDANT,
2763
+ activeDescendant
2764
+ );
2691
2765
  }
2692
2766
  if (shouldFocus) {
2693
2767
  this.highlightedItem.focus();
@@ -2768,11 +2842,7 @@ var UI = class _UI {
2768
2842
  }
2769
2843
  // UI: Open the dropdown (DOM only).
2770
2844
  openDropdown() {
2771
- const {
2772
- countrySearch,
2773
- dropdownAlwaysOpen,
2774
- dropdownContainer
2775
- } = this.#options;
2845
+ const { countrySearch, dropdownAlwaysOpen, dropdownContainer } = this.#options;
2776
2846
  this.#maybeEnsureDropdownWidthSet();
2777
2847
  if (dropdownContainer) {
2778
2848
  this.#handleDropdownContainer();
@@ -2787,15 +2857,22 @@ var UI = class _UI {
2787
2857
  }
2788
2858
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2789
2859
  this.selectedCountry.setAttribute(ARIA.EXPANDED, "true");
2790
- if (countrySearch) {
2791
- const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2792
- if (itemToHighlight) {
2793
- this.highlightListItem(itemToHighlight, false);
2794
- this.scrollCountryListToItem(itemToHighlight);
2795
- }
2796
- if (!dropdownAlwaysOpen) {
2797
- this.searchInput.focus();
2798
- }
2860
+ const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2861
+ if (itemToHighlight) {
2862
+ this.highlightListItem(itemToHighlight, false);
2863
+ this.scrollCountryListToItem(itemToHighlight);
2864
+ }
2865
+ if (countrySearch && !dropdownAlwaysOpen) {
2866
+ this.searchInput.focus();
2867
+ }
2868
+ if (this.#options.useFullscreenPopup && this.#dropdownForContainer && window.visualViewport) {
2869
+ this.#viewportHandler = () => {
2870
+ this.#adjustFullscreenPopupToViewport();
2871
+ if (this.highlightedItem) {
2872
+ this.scrollCountryListToItem(this.highlightedItem);
2873
+ }
2874
+ };
2875
+ window.visualViewport.addEventListener("resize", this.#viewportHandler);
2799
2876
  }
2800
2877
  this.#dropdownArrow.classList.add(CLASSES.ARROW_UP);
2801
2878
  }
@@ -2814,6 +2891,13 @@ var UI = class _UI {
2814
2891
  }
2815
2892
  }
2816
2893
  this.#dropdownArrow.classList.remove(CLASSES.ARROW_UP);
2894
+ if (this.#viewportHandler && window.visualViewport) {
2895
+ window.visualViewport.removeEventListener(
2896
+ "resize",
2897
+ this.#viewportHandler
2898
+ );
2899
+ this.#viewportHandler = null;
2900
+ }
2817
2901
  if (dropdownContainer) {
2818
2902
  this.#dropdownForContainer.remove();
2819
2903
  this.#dropdownForContainer.style.top = "";
@@ -2856,6 +2940,16 @@ var UI = class _UI {
2856
2940
  }
2857
2941
  dropdownContainer.appendChild(this.#dropdownForContainer);
2858
2942
  }
2943
+ // Adjust the fullscreen popup dimensions to match the visual viewport,
2944
+ // so it stays above the virtual keyboard on mobile devices.
2945
+ #adjustFullscreenPopupToViewport() {
2946
+ const vv = window.visualViewport;
2947
+ if (!vv || !this.#dropdownForContainer) {
2948
+ return;
2949
+ }
2950
+ const virtualKeyboardHeight = window.innerHeight - vv.height;
2951
+ this.#dropdownForContainer.style.bottom = `${virtualKeyboardHeight}px`;
2952
+ }
2859
2953
  // UI: Whether the dropdown is currently closed (hidden).
2860
2954
  isDropdownClosed() {
2861
2955
  return this.#dropdownContent.classList.contains(CLASSES.HIDE);
@@ -2903,7 +2997,7 @@ var processAllCountries = (options) => {
2903
2997
  (country) => !excludeCountries.includes(country.iso2)
2904
2998
  );
2905
2999
  }
2906
- return data_default;
3000
+ return [...data_default];
2907
3001
  };
2908
3002
  var generateCountryNames = (countries, options) => {
2909
3003
  const { countryNameLocale, i18n } = options;
@@ -2936,7 +3030,7 @@ var processDialCodes = (countries) => {
2936
3030
  if (dialCode.length > dialCodeMaxLen) {
2937
3031
  dialCodeMaxLen = dialCode.length;
2938
3032
  }
2939
- if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
3033
+ if (!Object.hasOwn(dialCodeToIso2Map, dialCode)) {
2940
3034
  dialCodeToIso2Map[dialCode] = [];
2941
3035
  }
2942
3036
  const iso2List = dialCodeToIso2Map[dialCode];
@@ -2945,7 +3039,9 @@ var processDialCodes = (countries) => {
2945
3039
  }
2946
3040
  iso2List.push(iso2);
2947
3041
  };
2948
- const countriesSortedByPriority = [...countries].sort((a, b) => a.priority - b.priority);
3042
+ const countriesSortedByPriority = [...countries].sort(
3043
+ (a, b) => a.priority - b.priority
3044
+ );
2949
3045
  for (const c of countriesSortedByPriority) {
2950
3046
  if (!dialCodes.has(c.dialCode)) {
2951
3047
  dialCodes.add(c.dialCode);
@@ -3010,15 +3106,12 @@ var hasRegionlessDialCode = (number) => {
3010
3106
  return number.startsWith("+") && REGIONLESS_DIAL_CODES.has(dialCode);
3011
3107
  };
3012
3108
  var beforeSetNumber = (fullNumber, hasValidDialCode, separateDialCode, selectedCountryData) => {
3013
- let number = fullNumber;
3014
- if (separateDialCode) {
3015
- if (hasValidDialCode) {
3016
- const dialCode = `+${selectedCountryData.dialCode}`;
3017
- const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3018
- number = number.substring(start);
3019
- }
3109
+ if (!separateDialCode || !hasValidDialCode) {
3110
+ return fullNumber;
3020
3111
  }
3021
- return number;
3112
+ const dialCode = `+${selectedCountryData.dialCode}`;
3113
+ const start = fullNumber[dialCode.length] === " " || fullNumber[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3114
+ return fullNumber.substring(start);
3022
3115
  };
3023
3116
  var formatNumberAsYouType = (fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) => {
3024
3117
  const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData?.iso2) : fullNumber;
@@ -3111,7 +3204,10 @@ var Numerals = class {
3111
3204
  }
3112
3205
  const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
3113
3206
  const regex = this.#userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
3114
- return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
3207
+ return str.replace(
3208
+ regex,
3209
+ (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base))
3210
+ );
3115
3211
  }
3116
3212
  isAscii() {
3117
3213
  return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
@@ -3120,7 +3216,9 @@ var Numerals = class {
3120
3216
  var id = 0;
3121
3217
  var ensureUtils = (methodName) => {
3122
3218
  if (!intlTelInput.utils) {
3123
- throw new Error(`intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`);
3219
+ throw new Error(
3220
+ `intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`
3221
+ );
3124
3222
  }
3125
3223
  };
3126
3224
  var createDeferred = () => {
@@ -3275,9 +3373,13 @@ var Iti = class _Iti {
3275
3373
  this.#ui.hiddenInputCountry.value = this.#selectedCountryData?.iso2 || "";
3276
3374
  }
3277
3375
  };
3278
- this.#ui.telInput.form?.addEventListener("submit", handleHiddenInputSubmit, {
3279
- signal: this.#abortController.signal
3280
- });
3376
+ this.#ui.telInput.form?.addEventListener(
3377
+ "submit",
3378
+ handleHiddenInputSubmit,
3379
+ {
3380
+ signal: this.#abortController.signal
3381
+ }
3382
+ );
3281
3383
  }
3282
3384
  //* initialise the dropdown listeners.
3283
3385
  #initDropdownListeners() {
@@ -3306,7 +3408,12 @@ var Iti = class _Iti {
3306
3408
  }
3307
3409
  );
3308
3410
  const handleCountryContainerKeydown = (e) => {
3309
- const allowedKeys = [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.SPACE, KEYS.ENTER];
3411
+ const allowedKeys = [
3412
+ KEYS.ARROW_UP,
3413
+ KEYS.ARROW_DOWN,
3414
+ KEYS.SPACE,
3415
+ KEYS.ENTER
3416
+ ];
3310
3417
  if (this.#ui.isDropdownClosed() && allowedKeys.includes(e.key)) {
3311
3418
  e.preventDefault();
3312
3419
  e.stopPropagation();
@@ -3324,8 +3431,8 @@ var Iti = class _Iti {
3324
3431
  }
3325
3432
  //* Init requests: utils script / geo ip lookup.
3326
3433
  #initRequests() {
3327
- const { loadUtils, initialCountry, geoIpLookup } = this.#options;
3328
- if (loadUtils && !intlTelInput.utils) {
3434
+ if (this.#utilsScriptDeferred) {
3435
+ const { loadUtils } = this.#options;
3329
3436
  const doAttachUtils = () => {
3330
3437
  intlTelInput.attachUtils(loadUtils)?.catch(() => {
3331
3438
  });
@@ -3337,13 +3444,10 @@ var Iti = class _Iti {
3337
3444
  signal: this.#abortController.signal
3338
3445
  });
3339
3446
  }
3340
- } else {
3341
- this.#utilsScriptDeferred?.resolve();
3342
3447
  }
3343
- const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
3344
- if (isAutoCountry) {
3448
+ if (this.#autoCountryDeferred) {
3345
3449
  if (this.#selectedCountryData) {
3346
- this.#autoCountryDeferred?.resolve();
3450
+ this.#autoCountryDeferred.resolve();
3347
3451
  } else {
3348
3452
  this.#loadAutoCountry();
3349
3453
  }
@@ -3353,28 +3457,29 @@ var Iti = class _Iti {
3353
3457
  #loadAutoCountry() {
3354
3458
  if (intlTelInput.autoCountry) {
3355
3459
  this.#handleAutoCountry();
3356
- } else {
3357
- this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3358
- if (!intlTelInput.startedLoadingAutoCountry) {
3359
- intlTelInput.startedLoadingAutoCountry = true;
3360
- if (typeof this.#options.geoIpLookup === "function") {
3361
- const successCallback = (iso2 = "") => {
3362
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3363
- const iso2Lower = iso2.toLowerCase();
3364
- if (isIso2(iso2Lower)) {
3365
- intlTelInput.autoCountry = iso2Lower;
3366
- setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3367
- } else {
3368
- _Iti.forEachInstance("handleAutoCountryFailure");
3369
- }
3370
- };
3371
- const failureCallback = () => {
3372
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3373
- _Iti.forEachInstance("handleAutoCountryFailure");
3374
- };
3375
- this.#options.geoIpLookup(successCallback, failureCallback);
3460
+ return;
3461
+ }
3462
+ this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3463
+ if (intlTelInput.startedLoadingAutoCountry) {
3464
+ return;
3465
+ }
3466
+ intlTelInput.startedLoadingAutoCountry = true;
3467
+ if (typeof this.#options.geoIpLookup === "function") {
3468
+ const successCallback = (iso2 = "") => {
3469
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3470
+ const iso2Lower = iso2.toLowerCase();
3471
+ if (isIso2(iso2Lower)) {
3472
+ intlTelInput.autoCountry = iso2Lower;
3473
+ setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3474
+ } else {
3475
+ _Iti.forEachInstance("handleAutoCountryFailure");
3376
3476
  }
3377
- }
3477
+ };
3478
+ const failureCallback = () => {
3479
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3480
+ _Iti.forEachInstance("handleAutoCountryFailure");
3481
+ };
3482
+ this.#options.geoIpLookup(successCallback, failureCallback);
3378
3483
  }
3379
3484
  }
3380
3485
  #openDropdownWithPlus() {
@@ -3424,10 +3529,7 @@ var Iti = class _Iti {
3424
3529
  const isAscii = this.#numerals.isAscii();
3425
3530
  if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
3426
3531
  const currentCaretPos = this.#ui.telInput.selectionStart || 0;
3427
- const valueBeforeCaret = inputValue.substring(
3428
- 0,
3429
- currentCaretPos
3430
- );
3532
+ const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
3431
3533
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(
3432
3534
  REGEX.NON_PLUS_NUMERIC_GLOBAL,
3433
3535
  ""
@@ -3470,96 +3572,100 @@ var Iti = class _Iti {
3470
3572
  }
3471
3573
  #maybeBindKeydownListener() {
3472
3574
  const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
3473
- if (strictMode || separateDialCode) {
3474
- const handleKeydownEvent = (e) => {
3475
- if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
3476
- if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3477
- e.preventDefault();
3478
- this.#openDropdownWithPlus();
3479
- return;
3480
- }
3481
- if (strictMode) {
3482
- const inputValue = this.#getTelInputValue();
3483
- const alreadyHasPlus = inputValue.startsWith("+");
3484
- const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3485
- const normalisedKey = this.#numerals.normalise(e.key);
3486
- const isNumeric = /^[0-9]$/.test(normalisedKey);
3487
- const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3488
- const input = this.#ui.telInput;
3489
- const selStart = input.selectionStart;
3490
- const selEnd = input.selectionEnd;
3491
- const before = inputValue.slice(0, selStart ?? void 0);
3492
- const after = inputValue.slice(selEnd ?? void 0);
3493
- const newValue = before + e.key + after;
3494
- const newFullNumber = this.#getFullNumber(newValue);
3495
- let hasExceededMaxLength = false;
3496
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
3497
- const coreNumber = intlTelInput.utils.getCoreNumber(
3498
- newFullNumber,
3499
- this.#selectedCountryData?.iso2
3500
- );
3501
- hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3502
- }
3503
- const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3504
- const isChangingDialCode = newCountry !== null;
3505
- if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3506
- e.preventDefault();
3507
- }
3508
- }
3509
- }
3510
- };
3511
- this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3512
- signal: this.#abortController.signal
3513
- });
3575
+ if (!strictMode && !separateDialCode) {
3576
+ return;
3514
3577
  }
3578
+ const handleKeydownEvent = (e) => {
3579
+ if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
3580
+ return;
3581
+ }
3582
+ if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3583
+ e.preventDefault();
3584
+ this.#openDropdownWithPlus();
3585
+ return;
3586
+ }
3587
+ if (!strictMode) {
3588
+ return;
3589
+ }
3590
+ const inputValue = this.#getTelInputValue();
3591
+ const alreadyHasPlus = inputValue.startsWith("+");
3592
+ const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3593
+ const normalisedKey = this.#numerals.normalise(e.key);
3594
+ const isNumeric = /^[0-9]$/.test(normalisedKey);
3595
+ const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3596
+ const input = this.#ui.telInput;
3597
+ const selStart = input.selectionStart;
3598
+ const selEnd = input.selectionEnd;
3599
+ const before = inputValue.slice(0, selStart ?? void 0);
3600
+ const after = inputValue.slice(selEnd ?? void 0);
3601
+ const newValue = before + e.key + after;
3602
+ const newFullNumber = this.#getFullNumber(newValue);
3603
+ let hasExceededMaxLength = false;
3604
+ if (intlTelInput.utils && this.#maxCoreNumberLength) {
3605
+ const coreNumber = intlTelInput.utils.getCoreNumber(
3606
+ newFullNumber,
3607
+ this.#selectedCountryData?.iso2
3608
+ );
3609
+ hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3610
+ }
3611
+ const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3612
+ const isChangingDialCode = newCountry !== null;
3613
+ if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3614
+ e.preventDefault();
3615
+ }
3616
+ };
3617
+ this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3618
+ signal: this.#abortController.signal
3619
+ });
3515
3620
  }
3516
3621
  #maybeBindPasteListener() {
3517
- if (this.#options.strictMode) {
3518
- const handlePasteEvent = (e) => {
3519
- e.preventDefault();
3520
- const input = this.#ui.telInput;
3521
- const selStart = input.selectionStart;
3522
- const selEnd = input.selectionEnd;
3523
- const inputValue = this.#getTelInputValue();
3524
- const before = inputValue.slice(0, selStart ?? void 0);
3525
- const after = inputValue.slice(selEnd ?? void 0);
3526
- const iso2 = this.#selectedCountryData?.iso2;
3527
- const pastedRaw = e.clipboardData.getData("text");
3528
- const pasted = this.#numerals.normalise(pastedRaw);
3529
- const initialCharSelected = selStart === 0 && selEnd > 0;
3530
- const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3531
- const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3532
- const hasLeadingPlus = allowedChars.startsWith("+");
3533
- const numerics = allowedChars.replace(/\+/g, "");
3534
- const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3535
- let newVal = before + sanitised + after;
3536
- if (newVal.length > 5 && intlTelInput.utils) {
3537
- let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3538
- while (coreNumber.length === 0 && newVal.length > 0) {
3539
- newVal = newVal.slice(0, -1);
3540
- coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3541
- }
3542
- if (!coreNumber) {
3622
+ if (!this.#options.strictMode) {
3623
+ return;
3624
+ }
3625
+ const handlePasteEvent = (e) => {
3626
+ e.preventDefault();
3627
+ const input = this.#ui.telInput;
3628
+ const selStart = input.selectionStart;
3629
+ const selEnd = input.selectionEnd;
3630
+ const inputValue = this.#getTelInputValue();
3631
+ const before = inputValue.slice(0, selStart ?? void 0);
3632
+ const after = inputValue.slice(selEnd ?? void 0);
3633
+ const iso2 = this.#selectedCountryData?.iso2;
3634
+ const pastedRaw = e.clipboardData.getData("text");
3635
+ const pasted = this.#numerals.normalise(pastedRaw);
3636
+ const initialCharSelected = selStart === 0 && selEnd > 0;
3637
+ const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3638
+ const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3639
+ const hasLeadingPlus = allowedChars.startsWith("+");
3640
+ const numerics = allowedChars.replace(/\+/g, "");
3641
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3642
+ let newVal = before + sanitised + after;
3643
+ if (newVal.length > 5 && intlTelInput.utils) {
3644
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3645
+ while (coreNumber.length === 0 && newVal.length > 0) {
3646
+ newVal = newVal.slice(0, -1);
3647
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3648
+ }
3649
+ if (!coreNumber) {
3650
+ return;
3651
+ }
3652
+ if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3653
+ if (input.selectionEnd === inputValue.length) {
3654
+ const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3655
+ newVal = newVal.slice(0, newVal.length - trimLength);
3656
+ } else {
3543
3657
  return;
3544
3658
  }
3545
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3546
- if (input.selectionEnd === inputValue.length) {
3547
- const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3548
- newVal = newVal.slice(0, newVal.length - trimLength);
3549
- } else {
3550
- return;
3551
- }
3552
- }
3553
3659
  }
3554
- this.#setTelInputValue(newVal);
3555
- const caretPos = selStart + sanitised.length;
3556
- input.setSelectionRange(caretPos, caretPos);
3557
- input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3558
- };
3559
- this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3560
- signal: this.#abortController.signal
3561
- });
3562
- }
3660
+ }
3661
+ this.#setTelInputValue(newVal);
3662
+ const caretPos = selStart + sanitised.length;
3663
+ input.setSelectionRange(caretPos, caretPos);
3664
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3665
+ };
3666
+ this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3667
+ signal: this.#abortController.signal
3668
+ });
3563
3669
  }
3564
3670
  //* Adhere to the input's maxlength attr.
3565
3671
  #cap(number) {
@@ -3766,7 +3872,7 @@ var Iti = class _Iti {
3766
3872
  //* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
3767
3873
  #getNewCountryFromNumber(fullNumber) {
3768
3874
  const plusIndex = fullNumber.indexOf("+");
3769
- let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
3875
+ let number = plusIndex > 0 ? fullNumber.substring(plusIndex) : fullNumber;
3770
3876
  const selectedIso2 = this.#selectedCountryData?.iso2;
3771
3877
  const selectedDialCode = this.#selectedCountryData?.dialCode;
3772
3878
  number = this.#ensureHasDialCode(number);
@@ -3834,33 +3940,34 @@ var Iti = class _Iti {
3834
3940
  //* Update the maximum valid number length for the currently selected country.
3835
3941
  #updateMaxLength() {
3836
3942
  const { strictMode, placeholderNumberType, allowedNumberTypes } = this.#options;
3943
+ if (!strictMode || !intlTelInput.utils) {
3944
+ return;
3945
+ }
3837
3946
  const iso2 = this.#selectedCountryData?.iso2;
3838
- if (strictMode && intlTelInput.utils) {
3839
- if (iso2) {
3840
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3841
- let exampleNumber = intlTelInput.utils.getExampleNumber(
3842
- iso2,
3843
- false,
3844
- numberType,
3845
- true
3846
- );
3847
- let validNumber = exampleNumber;
3848
- while (intlTelInput.utils.isPossibleNumber(
3849
- exampleNumber,
3850
- iso2,
3851
- allowedNumberTypes
3852
- )) {
3853
- validNumber = exampleNumber;
3854
- exampleNumber += "0";
3855
- }
3856
- const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
3857
- this.#maxCoreNumberLength = coreNumber.length;
3858
- if (iso2 === "by") {
3859
- this.#maxCoreNumberLength = coreNumber.length + 1;
3860
- }
3861
- } else {
3862
- this.#maxCoreNumberLength = null;
3863
- }
3947
+ if (!iso2) {
3948
+ this.#maxCoreNumberLength = null;
3949
+ return;
3950
+ }
3951
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3952
+ let exampleNumber = intlTelInput.utils.getExampleNumber(
3953
+ iso2,
3954
+ false,
3955
+ numberType,
3956
+ true
3957
+ );
3958
+ let validNumber = exampleNumber;
3959
+ while (intlTelInput.utils.isPossibleNumber(
3960
+ exampleNumber,
3961
+ iso2,
3962
+ allowedNumberTypes
3963
+ )) {
3964
+ validNumber = exampleNumber;
3965
+ exampleNumber += "0";
3966
+ }
3967
+ const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
3968
+ this.#maxCoreNumberLength = coreNumber.length;
3969
+ if (iso2 === "by") {
3970
+ this.#maxCoreNumberLength = coreNumber.length + 1;
3864
3971
  }
3865
3972
  }
3866
3973
  //* Update the input placeholder to an example number from the currently selected country.
@@ -3872,19 +3979,20 @@ var Iti = class _Iti {
3872
3979
  customPlaceholder
3873
3980
  } = this.#options;
3874
3981
  const shouldSetPlaceholder = autoPlaceholder === PLACEHOLDER_MODES.AGGRESSIVE || !this.#ui.hadInitialPlaceholder && autoPlaceholder === PLACEHOLDER_MODES.POLITE;
3875
- if (intlTelInput.utils && shouldSetPlaceholder) {
3876
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3877
- let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
3878
- this.#selectedCountryData.iso2,
3879
- nationalMode,
3880
- numberType
3881
- ) : "";
3882
- placeholder = this.#beforeSetNumber(placeholder);
3883
- if (typeof customPlaceholder === "function") {
3884
- placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
3885
- }
3886
- this.#ui.telInput.setAttribute("placeholder", placeholder);
3982
+ if (!intlTelInput.utils || !shouldSetPlaceholder) {
3983
+ return;
3984
+ }
3985
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3986
+ let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
3987
+ this.#selectedCountryData.iso2,
3988
+ nationalMode,
3989
+ numberType
3990
+ ) : "";
3991
+ placeholder = this.#beforeSetNumber(placeholder);
3992
+ if (typeof customPlaceholder === "function") {
3993
+ placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
3887
3994
  }
3995
+ this.#ui.telInput.setAttribute("placeholder", placeholder);
3888
3996
  }
3889
3997
  //* Called when the user selects a list item from the dropdown.
3890
3998
  #selectListItem(listItem) {
@@ -3916,46 +4024,49 @@ var Iti = class _Iti {
3916
4024
  //* Note: called from _selectListItem and setCountry
3917
4025
  #updateDialCode(newDialCodeBare) {
3918
4026
  const inputVal = this.#getTelInputValue();
4027
+ if (!inputVal.startsWith("+")) {
4028
+ return;
4029
+ }
3919
4030
  const newDialCode = `+${newDialCodeBare}`;
4031
+ const prevDialCode = this.#getDialCode(inputVal);
3920
4032
  let newNumber;
3921
- if (inputVal.startsWith("+")) {
3922
- const prevDialCode = this.#getDialCode(inputVal);
3923
- if (prevDialCode) {
3924
- newNumber = inputVal.replace(prevDialCode, newDialCode);
3925
- } else {
3926
- newNumber = newDialCode;
3927
- }
3928
- this.#setTelInputValue(newNumber);
4033
+ if (prevDialCode) {
4034
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
4035
+ } else {
4036
+ newNumber = newDialCode;
3929
4037
  }
4038
+ this.#setTelInputValue(newNumber);
3930
4039
  }
3931
4040
  //* Try and extract a valid international dial code from a full telephone number.
3932
4041
  //* Note: returns the raw string inc plus character and any whitespace/dots etc.
3933
4042
  #getDialCode(number, includeAreaCode) {
4043
+ if (!number.startsWith("+")) {
4044
+ return "";
4045
+ }
3934
4046
  let dialCode = "";
3935
- if (number.startsWith("+")) {
3936
- let numericChars = "";
3937
- let foundBaseDialCode = false;
3938
- for (let i = 0; i < number.length; i++) {
3939
- const c = number.charAt(i);
3940
- if (/[0-9]/.test(c)) {
3941
- numericChars += c;
3942
- const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
3943
- if (!hasMapEntry) {
3944
- break;
3945
- }
3946
- if (this.#dialCodes.has(numericChars)) {
3947
- dialCode = number.substring(0, i + 1);
3948
- foundBaseDialCode = true;
3949
- if (!includeAreaCode) {
3950
- break;
3951
- }
3952
- } else if (includeAreaCode && foundBaseDialCode) {
3953
- dialCode = number.substring(0, i + 1);
3954
- }
3955
- if (numericChars.length === this.#dialCodeMaxLen) {
3956
- break;
3957
- }
4047
+ let numericChars = "";
4048
+ let foundBaseDialCode = false;
4049
+ for (let i = 0; i < number.length; i++) {
4050
+ const c = number.charAt(i);
4051
+ if (!/[0-9]/.test(c)) {
4052
+ continue;
4053
+ }
4054
+ numericChars += c;
4055
+ const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
4056
+ if (!hasMapEntry) {
4057
+ break;
4058
+ }
4059
+ if (this.#dialCodes.has(numericChars)) {
4060
+ dialCode = number.substring(0, i + 1);
4061
+ foundBaseDialCode = true;
4062
+ if (!includeAreaCode) {
4063
+ break;
3958
4064
  }
4065
+ } else if (includeAreaCode && foundBaseDialCode) {
4066
+ dialCode = number.substring(0, i + 1);
4067
+ }
4068
+ if (numericChars.length === this.#dialCodeMaxLen) {
4069
+ break;
3959
4070
  }
3960
4071
  }
3961
4072
  return dialCode;
@@ -4003,18 +4114,19 @@ var Iti = class _Iti {
4003
4114
  //**************************
4004
4115
  //* Called when the geoip call returns.
4005
4116
  #handleAutoCountry() {
4117
+ if (!this.#autoCountryDeferred || !intlTelInput.autoCountry) {
4118
+ return;
4119
+ }
4006
4120
  if (this.#destroyed) {
4007
- this.#autoCountryDeferred?.resolve();
4121
+ this.#autoCountryDeferred.resolve();
4008
4122
  return;
4009
4123
  }
4010
- if (this.#options.initialCountry === INITIAL_COUNTRY.AUTO && intlTelInput.autoCountry) {
4011
- this.#defaultCountry = intlTelInput.autoCountry;
4012
- const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4013
- if (!hasSelectedCountryOrGlobe) {
4014
- this.setCountry(this.#defaultCountry);
4015
- }
4016
- this.#autoCountryDeferred?.resolve();
4124
+ this.#defaultCountry = intlTelInput.autoCountry;
4125
+ const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4126
+ if (!hasSelectedCountryOrGlobe) {
4127
+ this.setCountry(this.#defaultCountry);
4017
4128
  }
4129
+ this.#autoCountryDeferred.resolve();
4018
4130
  }
4019
4131
  //* Called when the geoip call fails or times out.
4020
4132
  #handleAutoCountryFailure() {
@@ -4031,15 +4143,17 @@ var Iti = class _Iti {
4031
4143
  this.#utilsScriptDeferred?.resolve();
4032
4144
  return;
4033
4145
  }
4034
- if (intlTelInput.utils) {
4035
- const inputValue = this.#getTelInputValue();
4036
- if (inputValue) {
4037
- this.#updateValFromNumber(inputValue);
4038
- }
4039
- if (this.#selectedCountryData) {
4040
- this.#updatePlaceholder();
4041
- this.#updateMaxLength();
4042
- }
4146
+ if (!intlTelInput.utils) {
4147
+ this.#utilsScriptDeferred?.resolve();
4148
+ return;
4149
+ }
4150
+ const inputValue = this.#getTelInputValue();
4151
+ if (inputValue) {
4152
+ this.#updateValFromNumber(inputValue);
4153
+ }
4154
+ if (this.#selectedCountryData) {
4155
+ this.#updatePlaceholder();
4156
+ this.#updateMaxLength();
4043
4157
  }
4044
4158
  this.#utilsScriptDeferred?.resolve();
4045
4159
  }
@@ -4181,7 +4295,9 @@ var Iti = class _Iti {
4181
4295
  const hasAlphaChar = alphaCharPosition > -1;
4182
4296
  if (hasAlphaChar) {
4183
4297
  const selectedIso2 = this.#selectedCountryData?.iso2;
4184
- const hasExtension = Boolean(intlTelInput.utils.getExtension(val, selectedIso2));
4298
+ const hasExtension = Boolean(
4299
+ intlTelInput.utils.getExtension(val, selectedIso2)
4300
+ );
4185
4301
  if (hasExtension) {
4186
4302
  return allowNumberExtensions;
4187
4303
  }
@@ -4207,15 +4323,16 @@ var Iti = class _Iti {
4207
4323
  }
4208
4324
  const currentCountry = this.#selectedCountryData?.iso2;
4209
4325
  const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
4210
- if (isCountryChange) {
4211
- this.#setCountry(iso2Lower);
4212
- this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4213
- if (this.#options.formatOnDisplay) {
4214
- const inputValue = this.#getTelInputValue();
4215
- this.#updateValFromNumber(inputValue);
4216
- }
4217
- this.#triggerCountryChange();
4326
+ if (!isCountryChange) {
4327
+ return;
4328
+ }
4329
+ this.#setCountry(iso2Lower);
4330
+ this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4331
+ if (this.#options.formatOnDisplay) {
4332
+ const inputValue = this.#getTelInputValue();
4333
+ this.#updateValFromNumber(inputValue);
4218
4334
  }
4335
+ this.#triggerCountryChange();
4219
4336
  }
4220
4337
  //* Set the input value and update the country.
4221
4338
  setNumber(number) {
@@ -4353,7 +4470,7 @@ var intlTelInput = Object.assign(
4353
4470
  attachUtils,
4354
4471
  startedLoadingUtilsScript: false,
4355
4472
  startedLoadingAutoCountry: false,
4356
- version: "27.0.0"
4473
+ version: "27.0.2"
4357
4474
  }
4358
4475
  );
4359
4476
  var intl_tel_input_default = intlTelInput;