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
  [
@@ -1928,9 +1984,10 @@ var warn = (message) => {
1928
1984
  console.warn(`[intl-tel-input] ${message}`);
1929
1985
  };
1930
1986
  var warnOption = (optionName, expectedType, actualValue) => {
1931
- warn(`Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`);
1987
+ warn(
1988
+ `Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`
1989
+ );
1932
1990
  };
1933
- var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
1934
1991
  var validateIso2Array = (key, value) => {
1935
1992
  const expectedType = "an array of ISO2 country code strings";
1936
1993
  if (!Array.isArray(value)) {
@@ -1963,7 +2020,7 @@ var validateOptions = (customOptions) => {
1963
2020
  }
1964
2021
  const validatedOptions = {};
1965
2022
  for (const [key, value] of Object.entries(customOptions)) {
1966
- if (!hasOwn(defaults, key)) {
2023
+ if (!Object.hasOwn(defaults, key)) {
1967
2024
  warn(`Unknown option '${key}'. Ignoring.`);
1968
2025
  continue;
1969
2026
  }
@@ -2057,8 +2114,12 @@ var validateOptions = (customOptions) => {
2057
2114
  break;
2058
2115
  }
2059
2116
  const lower = value.toLowerCase();
2060
- if (lower && (lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower))) {
2061
- warnOption("initialCountry", "a valid ISO2 country code or 'auto'", value);
2117
+ if (lower && lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower)) {
2118
+ warnOption(
2119
+ "initialCountry",
2120
+ "a valid ISO2 country code or 'auto'",
2121
+ value
2122
+ );
2062
2123
  break;
2063
2124
  }
2064
2125
  validatedOptions[key] = value;
@@ -2075,14 +2136,22 @@ var validateOptions = (customOptions) => {
2075
2136
  case "allowedNumberTypes":
2076
2137
  if (value !== null) {
2077
2138
  if (!Array.isArray(value)) {
2078
- warnOption("allowedNumberTypes", "an array of number types or null", value);
2139
+ warnOption(
2140
+ "allowedNumberTypes",
2141
+ "an array of number types or null",
2142
+ value
2143
+ );
2079
2144
  break;
2080
2145
  }
2081
2146
  let allValid = true;
2082
2147
  for (const v of value) {
2083
2148
  if (typeof v !== "string" || !NUMBER_TYPE_SET.has(v)) {
2084
2149
  const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
2085
- warnOption("allowedNumberTypes", `an array of valid number types (${validTypes})`, v);
2150
+ warnOption(
2151
+ "allowedNumberTypes",
2152
+ `an array of valid number types (${validTypes})`,
2153
+ v
2154
+ );
2086
2155
  allValid = false;
2087
2156
  break;
2088
2157
  }
@@ -2251,6 +2320,7 @@ var UI = class _UI {
2251
2320
  #searchResultsA11yText;
2252
2321
  #dropdownForContainer;
2253
2322
  #selectedItem = null;
2323
+ #viewportHandler = null;
2254
2324
  // public
2255
2325
  telInput;
2256
2326
  countryContainer;
@@ -2301,16 +2371,12 @@ var UI = class _UI {
2301
2371
  const wrapper = this.#createWrapperAndInsert();
2302
2372
  this.#maybeBuildCountryContainer(wrapper);
2303
2373
  wrapper.appendChild(this.telInput);
2374
+ this.#maybeEnsureDropdownWidthSet();
2304
2375
  this.#maybeUpdateInputPaddingAndReveal();
2305
2376
  this.#maybeBuildHiddenInputs(wrapper);
2306
2377
  }
2307
2378
  #createWrapperAndInsert() {
2308
- const {
2309
- allowDropdown,
2310
- showFlags,
2311
- containerClass,
2312
- useFullscreenPopup
2313
- } = this.#options;
2379
+ const { allowDropdown, showFlags, containerClass, useFullscreenPopup } = this.#options;
2314
2380
  const parentClasses = buildClassNames({
2315
2381
  iti: true,
2316
2382
  "iti--allow-dropdown": allowDropdown,
@@ -2327,72 +2393,74 @@ var UI = class _UI {
2327
2393
  }
2328
2394
  #maybeBuildCountryContainer(wrapper) {
2329
2395
  const { allowDropdown, separateDialCode, showFlags } = this.#options;
2330
- if (allowDropdown || showFlags || separateDialCode) {
2331
- this.countryContainer = createEl(
2332
- "div",
2333
- // visibly hidden until we measure it's width to set the input padding correctly
2334
- { class: `iti__country-container ${CLASSES.V_HIDE}` },
2335
- wrapper
2396
+ if (!allowDropdown && !showFlags && !separateDialCode) {
2397
+ return;
2398
+ }
2399
+ this.countryContainer = createEl(
2400
+ "div",
2401
+ // visibly hidden until we measure its width to set the input padding correctly
2402
+ { class: `iti__country-container ${CLASSES.V_HIDE}` },
2403
+ wrapper
2404
+ );
2405
+ if (allowDropdown) {
2406
+ this.selectedCountry = createEl(
2407
+ "button",
2408
+ {
2409
+ type: "button",
2410
+ class: "iti__selected-country",
2411
+ [ARIA.EXPANDED]: "false",
2412
+ [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2413
+ [ARIA.HASPOPUP]: "dialog",
2414
+ [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2415
+ },
2416
+ this.countryContainer
2336
2417
  );
2337
- if (allowDropdown) {
2338
- this.selectedCountry = createEl(
2339
- "button",
2340
- {
2341
- type: "button",
2342
- class: "iti__selected-country",
2343
- [ARIA.EXPANDED]: "false",
2344
- [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2345
- [ARIA.HASPOPUP]: "dialog",
2346
- [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2347
- },
2348
- this.countryContainer
2349
- );
2350
- if (this.telInput.disabled) {
2351
- this.selectedCountry.setAttribute("disabled", "true");
2352
- }
2353
- } else {
2354
- this.selectedCountry = createEl(
2355
- "div",
2356
- { class: "iti__selected-country" },
2357
- this.countryContainer
2358
- );
2418
+ if (this.telInput.disabled) {
2419
+ this.selectedCountry.setAttribute("disabled", "true");
2359
2420
  }
2360
- const selectedCountryPrimary = createEl(
2421
+ } else {
2422
+ this.selectedCountry = createEl(
2361
2423
  "div",
2362
- { class: "iti__selected-country-primary" },
2363
- this.selectedCountry
2424
+ { class: "iti__selected-country" },
2425
+ this.countryContainer
2364
2426
  );
2365
- this.selectedCountryInner = createEl(
2427
+ }
2428
+ const selectedCountryPrimary = createEl(
2429
+ "div",
2430
+ { class: "iti__selected-country-primary" },
2431
+ this.selectedCountry
2432
+ );
2433
+ this.selectedCountryInner = createEl(
2434
+ "div",
2435
+ { class: CLASSES.FLAG },
2436
+ selectedCountryPrimary
2437
+ );
2438
+ if (allowDropdown) {
2439
+ this.#dropdownArrow = createEl(
2366
2440
  "div",
2367
- { class: CLASSES.FLAG },
2441
+ { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2368
2442
  selectedCountryPrimary
2369
2443
  );
2370
- if (allowDropdown) {
2371
- this.#dropdownArrow = createEl(
2372
- "div",
2373
- { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2374
- selectedCountryPrimary
2375
- );
2376
- }
2377
- if (separateDialCode) {
2378
- this.#selectedDialCode = createEl(
2379
- "div",
2380
- { class: "iti__selected-dial-code" },
2381
- this.selectedCountry
2382
- );
2383
- }
2384
- if (allowDropdown) {
2385
- this.#buildDropdownContent();
2386
- }
2444
+ }
2445
+ if (separateDialCode) {
2446
+ this.#selectedDialCode = createEl(
2447
+ "div",
2448
+ { class: "iti__selected-dial-code" },
2449
+ this.selectedCountry
2450
+ );
2451
+ }
2452
+ if (allowDropdown) {
2453
+ this.#buildDropdownContent();
2387
2454
  }
2388
2455
  }
2389
2456
  #maybeEnsureDropdownWidthSet() {
2390
- const { fixDropdownWidth } = this.#options;
2391
- if (fixDropdownWidth && !this.#dropdownContent.style.width) {
2392
- const inputWidth = this.telInput.offsetWidth;
2393
- if (inputWidth > 0) {
2394
- this.#dropdownContent.style.width = `${inputWidth}px`;
2395
- }
2457
+ const { fixDropdownWidth, allowDropdown } = this.#options;
2458
+ if (!allowDropdown || !fixDropdownWidth || this.#dropdownContent.style.width) {
2459
+ return;
2460
+ }
2461
+ const inputWidth = this.telInput.offsetWidth;
2462
+ if (inputWidth > 0) {
2463
+ this.#dropdownContent.style.width = `${inputWidth}px`;
2396
2464
  }
2397
2465
  }
2398
2466
  #buildDropdownContent() {
@@ -2432,7 +2500,6 @@ var UI = class _UI {
2432
2500
  this.#updateSearchResultsA11yText();
2433
2501
  }
2434
2502
  if (!useFullscreenPopup) {
2435
- this.#maybeEnsureDropdownWidthSet();
2436
2503
  this.#inlineDropdownHeight = this.#getHiddenInlineDropdownHeight();
2437
2504
  if (countrySearch) {
2438
2505
  this.#dropdownContent.style.height = `${this.#inlineDropdownHeight}px`;
@@ -2514,43 +2581,45 @@ var UI = class _UI {
2514
2581
  this.#searchNoResults.textContent = i18n.searchEmptyState ?? null;
2515
2582
  }
2516
2583
  #maybeUpdateInputPaddingAndReveal() {
2517
- if (this.countryContainer) {
2518
- this.#updateInputPadding();
2519
- this.countryContainer.classList.remove(CLASSES.V_HIDE);
2584
+ if (!this.countryContainer) {
2585
+ return;
2520
2586
  }
2587
+ this.#updateInputPadding();
2588
+ this.countryContainer.classList.remove(CLASSES.V_HIDE);
2521
2589
  }
2522
2590
  #maybeBuildHiddenInputs(wrapper) {
2523
2591
  const { hiddenInput } = this.#options;
2524
- if (hiddenInput) {
2525
- const telInputName = this.telInput.getAttribute("name") || "";
2526
- const names = hiddenInput(telInputName);
2527
- if (names.phone) {
2528
- const existingInput = this.telInput.form?.querySelector(
2529
- `input[name="${names.phone}"]`
2530
- );
2531
- if (existingInput) {
2532
- this.hiddenInputPhone = existingInput;
2533
- } else {
2534
- this.hiddenInputPhone = createEl("input", {
2535
- type: "hidden",
2536
- name: names.phone
2537
- });
2538
- wrapper.appendChild(this.hiddenInputPhone);
2539
- }
2592
+ if (!hiddenInput) {
2593
+ return;
2594
+ }
2595
+ const telInputName = this.telInput.getAttribute("name") || "";
2596
+ const names = hiddenInput(telInputName);
2597
+ if (names.phone) {
2598
+ const existingInput = this.telInput.form?.querySelector(
2599
+ `input[name="${names.phone}"]`
2600
+ );
2601
+ if (existingInput) {
2602
+ this.hiddenInputPhone = existingInput;
2603
+ } else {
2604
+ this.hiddenInputPhone = createEl("input", {
2605
+ type: "hidden",
2606
+ name: names.phone
2607
+ });
2608
+ wrapper.appendChild(this.hiddenInputPhone);
2540
2609
  }
2541
- if (names.country) {
2542
- const existingInput = this.telInput.form?.querySelector(
2543
- `input[name="${names.country}"]`
2544
- );
2545
- if (existingInput) {
2546
- this.hiddenInputCountry = existingInput;
2547
- } else {
2548
- this.hiddenInputCountry = createEl("input", {
2549
- type: "hidden",
2550
- name: names.country
2551
- });
2552
- wrapper.appendChild(this.hiddenInputCountry);
2553
- }
2610
+ }
2611
+ if (names.country) {
2612
+ const existingInput = this.telInput.form?.querySelector(
2613
+ `input[name="${names.country}"]`
2614
+ );
2615
+ if (existingInput) {
2616
+ this.hiddenInputCountry = existingInput;
2617
+ } else {
2618
+ this.hiddenInputCountry = createEl("input", {
2619
+ type: "hidden",
2620
+ name: names.country
2621
+ });
2622
+ wrapper.appendChild(this.hiddenInputCountry);
2554
2623
  }
2555
2624
  }
2556
2625
  }
@@ -2609,30 +2678,32 @@ var UI = class _UI {
2609
2678
  //* To get the right styling to apply, all we need is a shallow clone of the container,
2610
2679
  //* and then to inject a deep clone of the selectedCountry element.
2611
2680
  #getHiddenSelectedCountryWidth() {
2612
- if (this.telInput.parentNode) {
2613
- const body = _UI.#getBody();
2614
- const containerClone = this.telInput.parentNode.cloneNode(
2615
- false
2616
- );
2617
- containerClone.style.visibility = "hidden";
2618
- body.appendChild(containerClone);
2619
- const countryContainerClone = this.countryContainer.cloneNode();
2620
- containerClone.appendChild(countryContainerClone);
2621
- const selectedCountryClone = this.selectedCountry.cloneNode(
2622
- true
2623
- );
2624
- countryContainerClone.appendChild(selectedCountryClone);
2625
- const width = selectedCountryClone.offsetWidth;
2626
- body.removeChild(containerClone);
2627
- return width;
2681
+ if (!this.telInput.parentNode) {
2682
+ return 0;
2628
2683
  }
2629
- return 0;
2684
+ const body = _UI.#getBody();
2685
+ const containerClone = this.telInput.parentNode.cloneNode(
2686
+ false
2687
+ );
2688
+ containerClone.style.visibility = "hidden";
2689
+ body.appendChild(containerClone);
2690
+ const countryContainerClone = this.countryContainer.cloneNode();
2691
+ containerClone.appendChild(countryContainerClone);
2692
+ const selectedCountryClone = this.selectedCountry.cloneNode(
2693
+ true
2694
+ );
2695
+ countryContainerClone.appendChild(selectedCountryClone);
2696
+ const width = selectedCountryClone.offsetWidth;
2697
+ body.removeChild(containerClone);
2698
+ return width;
2630
2699
  }
2631
- // this is run before we add the dropdown to the DOM
2700
+ // Get the dropdown height (before it is added to the DOM)
2632
2701
  #getHiddenInlineDropdownHeight() {
2633
2702
  const body = _UI.#getBody();
2634
2703
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2635
- const tempContainer = createEl("div", { class: "iti iti--inline-dropdown" });
2704
+ const tempContainer = createEl("div", {
2705
+ class: "iti iti--inline-dropdown"
2706
+ });
2636
2707
  tempContainer.appendChild(this.#dropdownContent);
2637
2708
  tempContainer.style.visibility = "hidden";
2638
2709
  body.appendChild(tempContainer);
@@ -2705,7 +2776,10 @@ var UI = class _UI {
2705
2776
  this.highlightedItem.classList.add(CLASSES.HIGHLIGHT);
2706
2777
  if (this.#options.countrySearch) {
2707
2778
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2708
- this.searchInput.setAttribute(ARIA.ACTIVE_DESCENDANT, activeDescendant);
2779
+ this.searchInput.setAttribute(
2780
+ ARIA.ACTIVE_DESCENDANT,
2781
+ activeDescendant
2782
+ );
2709
2783
  }
2710
2784
  if (shouldFocus) {
2711
2785
  this.highlightedItem.focus();
@@ -2786,11 +2860,7 @@ var UI = class _UI {
2786
2860
  }
2787
2861
  // UI: Open the dropdown (DOM only).
2788
2862
  openDropdown() {
2789
- const {
2790
- countrySearch,
2791
- dropdownAlwaysOpen,
2792
- dropdownContainer
2793
- } = this.#options;
2863
+ const { countrySearch, dropdownAlwaysOpen, dropdownContainer } = this.#options;
2794
2864
  this.#maybeEnsureDropdownWidthSet();
2795
2865
  if (dropdownContainer) {
2796
2866
  this.#handleDropdownContainer();
@@ -2805,15 +2875,22 @@ var UI = class _UI {
2805
2875
  }
2806
2876
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2807
2877
  this.selectedCountry.setAttribute(ARIA.EXPANDED, "true");
2808
- if (countrySearch) {
2809
- const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2810
- if (itemToHighlight) {
2811
- this.highlightListItem(itemToHighlight, false);
2812
- this.scrollCountryListToItem(itemToHighlight);
2813
- }
2814
- if (!dropdownAlwaysOpen) {
2815
- this.searchInput.focus();
2816
- }
2878
+ const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2879
+ if (itemToHighlight) {
2880
+ this.highlightListItem(itemToHighlight, false);
2881
+ this.scrollCountryListToItem(itemToHighlight);
2882
+ }
2883
+ if (countrySearch && !dropdownAlwaysOpen) {
2884
+ this.searchInput.focus();
2885
+ }
2886
+ if (this.#options.useFullscreenPopup && this.#dropdownForContainer && window.visualViewport) {
2887
+ this.#viewportHandler = () => {
2888
+ this.#adjustFullscreenPopupToViewport();
2889
+ if (this.highlightedItem) {
2890
+ this.scrollCountryListToItem(this.highlightedItem);
2891
+ }
2892
+ };
2893
+ window.visualViewport.addEventListener("resize", this.#viewportHandler);
2817
2894
  }
2818
2895
  this.#dropdownArrow.classList.add(CLASSES.ARROW_UP);
2819
2896
  }
@@ -2832,6 +2909,13 @@ var UI = class _UI {
2832
2909
  }
2833
2910
  }
2834
2911
  this.#dropdownArrow.classList.remove(CLASSES.ARROW_UP);
2912
+ if (this.#viewportHandler && window.visualViewport) {
2913
+ window.visualViewport.removeEventListener(
2914
+ "resize",
2915
+ this.#viewportHandler
2916
+ );
2917
+ this.#viewportHandler = null;
2918
+ }
2835
2919
  if (dropdownContainer) {
2836
2920
  this.#dropdownForContainer.remove();
2837
2921
  this.#dropdownForContainer.style.top = "";
@@ -2874,6 +2958,16 @@ var UI = class _UI {
2874
2958
  }
2875
2959
  dropdownContainer.appendChild(this.#dropdownForContainer);
2876
2960
  }
2961
+ // Adjust the fullscreen popup dimensions to match the visual viewport,
2962
+ // so it stays above the virtual keyboard on mobile devices.
2963
+ #adjustFullscreenPopupToViewport() {
2964
+ const vv = window.visualViewport;
2965
+ if (!vv || !this.#dropdownForContainer) {
2966
+ return;
2967
+ }
2968
+ const virtualKeyboardHeight = window.innerHeight - vv.height;
2969
+ this.#dropdownForContainer.style.bottom = `${virtualKeyboardHeight}px`;
2970
+ }
2877
2971
  // UI: Whether the dropdown is currently closed (hidden).
2878
2972
  isDropdownClosed() {
2879
2973
  return this.#dropdownContent.classList.contains(CLASSES.HIDE);
@@ -2923,7 +3017,7 @@ var processAllCountries = (options) => {
2923
3017
  (country) => !excludeCountries.includes(country.iso2)
2924
3018
  );
2925
3019
  }
2926
- return data_default;
3020
+ return [...data_default];
2927
3021
  };
2928
3022
  var generateCountryNames = (countries, options) => {
2929
3023
  const { countryNameLocale, i18n } = options;
@@ -2956,7 +3050,7 @@ var processDialCodes = (countries) => {
2956
3050
  if (dialCode.length > dialCodeMaxLen) {
2957
3051
  dialCodeMaxLen = dialCode.length;
2958
3052
  }
2959
- if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
3053
+ if (!Object.hasOwn(dialCodeToIso2Map, dialCode)) {
2960
3054
  dialCodeToIso2Map[dialCode] = [];
2961
3055
  }
2962
3056
  const iso2List = dialCodeToIso2Map[dialCode];
@@ -2965,7 +3059,9 @@ var processDialCodes = (countries) => {
2965
3059
  }
2966
3060
  iso2List.push(iso2);
2967
3061
  };
2968
- const countriesSortedByPriority = [...countries].sort((a, b) => a.priority - b.priority);
3062
+ const countriesSortedByPriority = [...countries].sort(
3063
+ (a, b) => a.priority - b.priority
3064
+ );
2969
3065
  for (const c of countriesSortedByPriority) {
2970
3066
  if (!dialCodes.has(c.dialCode)) {
2971
3067
  dialCodes.add(c.dialCode);
@@ -3034,15 +3130,12 @@ var hasRegionlessDialCode = (number) => {
3034
3130
 
3035
3131
  // src/js/format/formatting.ts
3036
3132
  var beforeSetNumber = (fullNumber, hasValidDialCode, separateDialCode, selectedCountryData) => {
3037
- let number = fullNumber;
3038
- if (separateDialCode) {
3039
- if (hasValidDialCode) {
3040
- const dialCode = `+${selectedCountryData.dialCode}`;
3041
- const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3042
- number = number.substring(start);
3043
- }
3133
+ if (!separateDialCode || !hasValidDialCode) {
3134
+ return fullNumber;
3044
3135
  }
3045
- return number;
3136
+ const dialCode = `+${selectedCountryData.dialCode}`;
3137
+ const start = fullNumber[dialCode.length] === " " || fullNumber[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3138
+ return fullNumber.substring(start);
3046
3139
  };
3047
3140
  var formatNumberAsYouType = (fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) => {
3048
3141
  const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData?.iso2) : fullNumber;
@@ -3141,7 +3234,10 @@ var Numerals = class {
3141
3234
  }
3142
3235
  const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
3143
3236
  const regex = this.#userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
3144
- return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
3237
+ return str.replace(
3238
+ regex,
3239
+ (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base))
3240
+ );
3145
3241
  }
3146
3242
  isAscii() {
3147
3243
  return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
@@ -3152,7 +3248,9 @@ var Numerals = class {
3152
3248
  var id = 0;
3153
3249
  var ensureUtils = (methodName) => {
3154
3250
  if (!intlTelInput.utils) {
3155
- throw new Error(`intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`);
3251
+ throw new Error(
3252
+ `intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`
3253
+ );
3156
3254
  }
3157
3255
  };
3158
3256
  var createDeferred = () => {
@@ -3307,9 +3405,13 @@ var Iti = class _Iti {
3307
3405
  this.#ui.hiddenInputCountry.value = this.#selectedCountryData?.iso2 || "";
3308
3406
  }
3309
3407
  };
3310
- this.#ui.telInput.form?.addEventListener("submit", handleHiddenInputSubmit, {
3311
- signal: this.#abortController.signal
3312
- });
3408
+ this.#ui.telInput.form?.addEventListener(
3409
+ "submit",
3410
+ handleHiddenInputSubmit,
3411
+ {
3412
+ signal: this.#abortController.signal
3413
+ }
3414
+ );
3313
3415
  }
3314
3416
  //* initialise the dropdown listeners.
3315
3417
  #initDropdownListeners() {
@@ -3338,7 +3440,12 @@ var Iti = class _Iti {
3338
3440
  }
3339
3441
  );
3340
3442
  const handleCountryContainerKeydown = (e) => {
3341
- const allowedKeys = [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.SPACE, KEYS.ENTER];
3443
+ const allowedKeys = [
3444
+ KEYS.ARROW_UP,
3445
+ KEYS.ARROW_DOWN,
3446
+ KEYS.SPACE,
3447
+ KEYS.ENTER
3448
+ ];
3342
3449
  if (this.#ui.isDropdownClosed() && allowedKeys.includes(e.key)) {
3343
3450
  e.preventDefault();
3344
3451
  e.stopPropagation();
@@ -3356,8 +3463,8 @@ var Iti = class _Iti {
3356
3463
  }
3357
3464
  //* Init requests: utils script / geo ip lookup.
3358
3465
  #initRequests() {
3359
- const { loadUtils, initialCountry, geoIpLookup } = this.#options;
3360
- if (loadUtils && !intlTelInput.utils) {
3466
+ if (this.#utilsScriptDeferred) {
3467
+ const { loadUtils } = this.#options;
3361
3468
  const doAttachUtils = () => {
3362
3469
  intlTelInput.attachUtils(loadUtils)?.catch(() => {
3363
3470
  });
@@ -3369,13 +3476,10 @@ var Iti = class _Iti {
3369
3476
  signal: this.#abortController.signal
3370
3477
  });
3371
3478
  }
3372
- } else {
3373
- this.#utilsScriptDeferred?.resolve();
3374
3479
  }
3375
- const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
3376
- if (isAutoCountry) {
3480
+ if (this.#autoCountryDeferred) {
3377
3481
  if (this.#selectedCountryData) {
3378
- this.#autoCountryDeferred?.resolve();
3482
+ this.#autoCountryDeferred.resolve();
3379
3483
  } else {
3380
3484
  this.#loadAutoCountry();
3381
3485
  }
@@ -3385,28 +3489,29 @@ var Iti = class _Iti {
3385
3489
  #loadAutoCountry() {
3386
3490
  if (intlTelInput.autoCountry) {
3387
3491
  this.#handleAutoCountry();
3388
- } else {
3389
- this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3390
- if (!intlTelInput.startedLoadingAutoCountry) {
3391
- intlTelInput.startedLoadingAutoCountry = true;
3392
- if (typeof this.#options.geoIpLookup === "function") {
3393
- const successCallback = (iso2 = "") => {
3394
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3395
- const iso2Lower = iso2.toLowerCase();
3396
- if (isIso2(iso2Lower)) {
3397
- intlTelInput.autoCountry = iso2Lower;
3398
- setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3399
- } else {
3400
- _Iti.forEachInstance("handleAutoCountryFailure");
3401
- }
3402
- };
3403
- const failureCallback = () => {
3404
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3405
- _Iti.forEachInstance("handleAutoCountryFailure");
3406
- };
3407
- this.#options.geoIpLookup(successCallback, failureCallback);
3492
+ return;
3493
+ }
3494
+ this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3495
+ if (intlTelInput.startedLoadingAutoCountry) {
3496
+ return;
3497
+ }
3498
+ intlTelInput.startedLoadingAutoCountry = true;
3499
+ if (typeof this.#options.geoIpLookup === "function") {
3500
+ const successCallback = (iso2 = "") => {
3501
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3502
+ const iso2Lower = iso2.toLowerCase();
3503
+ if (isIso2(iso2Lower)) {
3504
+ intlTelInput.autoCountry = iso2Lower;
3505
+ setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3506
+ } else {
3507
+ _Iti.forEachInstance("handleAutoCountryFailure");
3408
3508
  }
3409
- }
3509
+ };
3510
+ const failureCallback = () => {
3511
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3512
+ _Iti.forEachInstance("handleAutoCountryFailure");
3513
+ };
3514
+ this.#options.geoIpLookup(successCallback, failureCallback);
3410
3515
  }
3411
3516
  }
3412
3517
  #openDropdownWithPlus() {
@@ -3456,10 +3561,7 @@ var Iti = class _Iti {
3456
3561
  const isAscii = this.#numerals.isAscii();
3457
3562
  if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
3458
3563
  const currentCaretPos = this.#ui.telInput.selectionStart || 0;
3459
- const valueBeforeCaret = inputValue.substring(
3460
- 0,
3461
- currentCaretPos
3462
- );
3564
+ const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
3463
3565
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(
3464
3566
  REGEX.NON_PLUS_NUMERIC_GLOBAL,
3465
3567
  ""
@@ -3502,96 +3604,100 @@ var Iti = class _Iti {
3502
3604
  }
3503
3605
  #maybeBindKeydownListener() {
3504
3606
  const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
3505
- if (strictMode || separateDialCode) {
3506
- const handleKeydownEvent = (e) => {
3507
- if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
3508
- if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3509
- e.preventDefault();
3510
- this.#openDropdownWithPlus();
3511
- return;
3512
- }
3513
- if (strictMode) {
3514
- const inputValue = this.#getTelInputValue();
3515
- const alreadyHasPlus = inputValue.startsWith("+");
3516
- const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3517
- const normalisedKey = this.#numerals.normalise(e.key);
3518
- const isNumeric = /^[0-9]$/.test(normalisedKey);
3519
- const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3520
- const input = this.#ui.telInput;
3521
- const selStart = input.selectionStart;
3522
- const selEnd = input.selectionEnd;
3523
- const before = inputValue.slice(0, selStart ?? void 0);
3524
- const after = inputValue.slice(selEnd ?? void 0);
3525
- const newValue = before + e.key + after;
3526
- const newFullNumber = this.#getFullNumber(newValue);
3527
- let hasExceededMaxLength = false;
3528
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
3529
- const coreNumber = intlTelInput.utils.getCoreNumber(
3530
- newFullNumber,
3531
- this.#selectedCountryData?.iso2
3532
- );
3533
- hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3534
- }
3535
- const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3536
- const isChangingDialCode = newCountry !== null;
3537
- if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3538
- e.preventDefault();
3539
- }
3540
- }
3541
- }
3542
- };
3543
- this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3544
- signal: this.#abortController.signal
3545
- });
3607
+ if (!strictMode && !separateDialCode) {
3608
+ return;
3546
3609
  }
3610
+ const handleKeydownEvent = (e) => {
3611
+ if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
3612
+ return;
3613
+ }
3614
+ if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3615
+ e.preventDefault();
3616
+ this.#openDropdownWithPlus();
3617
+ return;
3618
+ }
3619
+ if (!strictMode) {
3620
+ return;
3621
+ }
3622
+ const inputValue = this.#getTelInputValue();
3623
+ const alreadyHasPlus = inputValue.startsWith("+");
3624
+ const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3625
+ const normalisedKey = this.#numerals.normalise(e.key);
3626
+ const isNumeric = /^[0-9]$/.test(normalisedKey);
3627
+ const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3628
+ const input = this.#ui.telInput;
3629
+ const selStart = input.selectionStart;
3630
+ const selEnd = input.selectionEnd;
3631
+ const before = inputValue.slice(0, selStart ?? void 0);
3632
+ const after = inputValue.slice(selEnd ?? void 0);
3633
+ const newValue = before + e.key + after;
3634
+ const newFullNumber = this.#getFullNumber(newValue);
3635
+ let hasExceededMaxLength = false;
3636
+ if (intlTelInput.utils && this.#maxCoreNumberLength) {
3637
+ const coreNumber = intlTelInput.utils.getCoreNumber(
3638
+ newFullNumber,
3639
+ this.#selectedCountryData?.iso2
3640
+ );
3641
+ hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3642
+ }
3643
+ const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3644
+ const isChangingDialCode = newCountry !== null;
3645
+ if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3646
+ e.preventDefault();
3647
+ }
3648
+ };
3649
+ this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3650
+ signal: this.#abortController.signal
3651
+ });
3547
3652
  }
3548
3653
  #maybeBindPasteListener() {
3549
- if (this.#options.strictMode) {
3550
- const handlePasteEvent = (e) => {
3551
- e.preventDefault();
3552
- const input = this.#ui.telInput;
3553
- const selStart = input.selectionStart;
3554
- const selEnd = input.selectionEnd;
3555
- const inputValue = this.#getTelInputValue();
3556
- const before = inputValue.slice(0, selStart ?? void 0);
3557
- const after = inputValue.slice(selEnd ?? void 0);
3558
- const iso2 = this.#selectedCountryData?.iso2;
3559
- const pastedRaw = e.clipboardData.getData("text");
3560
- const pasted = this.#numerals.normalise(pastedRaw);
3561
- const initialCharSelected = selStart === 0 && selEnd > 0;
3562
- const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3563
- const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3564
- const hasLeadingPlus = allowedChars.startsWith("+");
3565
- const numerics = allowedChars.replace(/\+/g, "");
3566
- const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3567
- let newVal = before + sanitised + after;
3568
- if (newVal.length > 5 && intlTelInput.utils) {
3569
- let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3570
- while (coreNumber.length === 0 && newVal.length > 0) {
3571
- newVal = newVal.slice(0, -1);
3572
- coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3573
- }
3574
- if (!coreNumber) {
3654
+ if (!this.#options.strictMode) {
3655
+ return;
3656
+ }
3657
+ const handlePasteEvent = (e) => {
3658
+ e.preventDefault();
3659
+ const input = this.#ui.telInput;
3660
+ const selStart = input.selectionStart;
3661
+ const selEnd = input.selectionEnd;
3662
+ const inputValue = this.#getTelInputValue();
3663
+ const before = inputValue.slice(0, selStart ?? void 0);
3664
+ const after = inputValue.slice(selEnd ?? void 0);
3665
+ const iso2 = this.#selectedCountryData?.iso2;
3666
+ const pastedRaw = e.clipboardData.getData("text");
3667
+ const pasted = this.#numerals.normalise(pastedRaw);
3668
+ const initialCharSelected = selStart === 0 && selEnd > 0;
3669
+ const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3670
+ const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3671
+ const hasLeadingPlus = allowedChars.startsWith("+");
3672
+ const numerics = allowedChars.replace(/\+/g, "");
3673
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3674
+ let newVal = before + sanitised + after;
3675
+ if (newVal.length > 5 && intlTelInput.utils) {
3676
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3677
+ while (coreNumber.length === 0 && newVal.length > 0) {
3678
+ newVal = newVal.slice(0, -1);
3679
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3680
+ }
3681
+ if (!coreNumber) {
3682
+ return;
3683
+ }
3684
+ if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3685
+ if (input.selectionEnd === inputValue.length) {
3686
+ const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3687
+ newVal = newVal.slice(0, newVal.length - trimLength);
3688
+ } else {
3575
3689
  return;
3576
3690
  }
3577
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3578
- if (input.selectionEnd === inputValue.length) {
3579
- const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3580
- newVal = newVal.slice(0, newVal.length - trimLength);
3581
- } else {
3582
- return;
3583
- }
3584
- }
3585
3691
  }
3586
- this.#setTelInputValue(newVal);
3587
- const caretPos = selStart + sanitised.length;
3588
- input.setSelectionRange(caretPos, caretPos);
3589
- input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3590
- };
3591
- this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3592
- signal: this.#abortController.signal
3593
- });
3594
- }
3692
+ }
3693
+ this.#setTelInputValue(newVal);
3694
+ const caretPos = selStart + sanitised.length;
3695
+ input.setSelectionRange(caretPos, caretPos);
3696
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3697
+ };
3698
+ this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3699
+ signal: this.#abortController.signal
3700
+ });
3595
3701
  }
3596
3702
  //* Adhere to the input's maxlength attr.
3597
3703
  #cap(number) {
@@ -3798,7 +3904,7 @@ var Iti = class _Iti {
3798
3904
  //* 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).
3799
3905
  #getNewCountryFromNumber(fullNumber) {
3800
3906
  const plusIndex = fullNumber.indexOf("+");
3801
- let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
3907
+ let number = plusIndex > 0 ? fullNumber.substring(plusIndex) : fullNumber;
3802
3908
  const selectedIso2 = this.#selectedCountryData?.iso2;
3803
3909
  const selectedDialCode = this.#selectedCountryData?.dialCode;
3804
3910
  number = this.#ensureHasDialCode(number);
@@ -3866,33 +3972,34 @@ var Iti = class _Iti {
3866
3972
  //* Update the maximum valid number length for the currently selected country.
3867
3973
  #updateMaxLength() {
3868
3974
  const { strictMode, placeholderNumberType, allowedNumberTypes } = this.#options;
3975
+ if (!strictMode || !intlTelInput.utils) {
3976
+ return;
3977
+ }
3869
3978
  const iso2 = this.#selectedCountryData?.iso2;
3870
- if (strictMode && intlTelInput.utils) {
3871
- if (iso2) {
3872
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3873
- let exampleNumber = intlTelInput.utils.getExampleNumber(
3874
- iso2,
3875
- false,
3876
- numberType,
3877
- true
3878
- );
3879
- let validNumber = exampleNumber;
3880
- while (intlTelInput.utils.isPossibleNumber(
3881
- exampleNumber,
3882
- iso2,
3883
- allowedNumberTypes
3884
- )) {
3885
- validNumber = exampleNumber;
3886
- exampleNumber += "0";
3887
- }
3888
- const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
3889
- this.#maxCoreNumberLength = coreNumber.length;
3890
- if (iso2 === "by") {
3891
- this.#maxCoreNumberLength = coreNumber.length + 1;
3892
- }
3893
- } else {
3894
- this.#maxCoreNumberLength = null;
3895
- }
3979
+ if (!iso2) {
3980
+ this.#maxCoreNumberLength = null;
3981
+ return;
3982
+ }
3983
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3984
+ let exampleNumber = intlTelInput.utils.getExampleNumber(
3985
+ iso2,
3986
+ false,
3987
+ numberType,
3988
+ true
3989
+ );
3990
+ let validNumber = exampleNumber;
3991
+ while (intlTelInput.utils.isPossibleNumber(
3992
+ exampleNumber,
3993
+ iso2,
3994
+ allowedNumberTypes
3995
+ )) {
3996
+ validNumber = exampleNumber;
3997
+ exampleNumber += "0";
3998
+ }
3999
+ const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
4000
+ this.#maxCoreNumberLength = coreNumber.length;
4001
+ if (iso2 === "by") {
4002
+ this.#maxCoreNumberLength = coreNumber.length + 1;
3896
4003
  }
3897
4004
  }
3898
4005
  //* Update the input placeholder to an example number from the currently selected country.
@@ -3904,19 +4011,20 @@ var Iti = class _Iti {
3904
4011
  customPlaceholder
3905
4012
  } = this.#options;
3906
4013
  const shouldSetPlaceholder = autoPlaceholder === PLACEHOLDER_MODES.AGGRESSIVE || !this.#ui.hadInitialPlaceholder && autoPlaceholder === PLACEHOLDER_MODES.POLITE;
3907
- if (intlTelInput.utils && shouldSetPlaceholder) {
3908
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3909
- let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
3910
- this.#selectedCountryData.iso2,
3911
- nationalMode,
3912
- numberType
3913
- ) : "";
3914
- placeholder = this.#beforeSetNumber(placeholder);
3915
- if (typeof customPlaceholder === "function") {
3916
- placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
3917
- }
3918
- this.#ui.telInput.setAttribute("placeholder", placeholder);
4014
+ if (!intlTelInput.utils || !shouldSetPlaceholder) {
4015
+ return;
3919
4016
  }
4017
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
4018
+ let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
4019
+ this.#selectedCountryData.iso2,
4020
+ nationalMode,
4021
+ numberType
4022
+ ) : "";
4023
+ placeholder = this.#beforeSetNumber(placeholder);
4024
+ if (typeof customPlaceholder === "function") {
4025
+ placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
4026
+ }
4027
+ this.#ui.telInput.setAttribute("placeholder", placeholder);
3920
4028
  }
3921
4029
  //* Called when the user selects a list item from the dropdown.
3922
4030
  #selectListItem(listItem) {
@@ -3948,46 +4056,49 @@ var Iti = class _Iti {
3948
4056
  //* Note: called from _selectListItem and setCountry
3949
4057
  #updateDialCode(newDialCodeBare) {
3950
4058
  const inputVal = this.#getTelInputValue();
4059
+ if (!inputVal.startsWith("+")) {
4060
+ return;
4061
+ }
3951
4062
  const newDialCode = `+${newDialCodeBare}`;
4063
+ const prevDialCode = this.#getDialCode(inputVal);
3952
4064
  let newNumber;
3953
- if (inputVal.startsWith("+")) {
3954
- const prevDialCode = this.#getDialCode(inputVal);
3955
- if (prevDialCode) {
3956
- newNumber = inputVal.replace(prevDialCode, newDialCode);
3957
- } else {
3958
- newNumber = newDialCode;
3959
- }
3960
- this.#setTelInputValue(newNumber);
4065
+ if (prevDialCode) {
4066
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
4067
+ } else {
4068
+ newNumber = newDialCode;
3961
4069
  }
4070
+ this.#setTelInputValue(newNumber);
3962
4071
  }
3963
4072
  //* Try and extract a valid international dial code from a full telephone number.
3964
4073
  //* Note: returns the raw string inc plus character and any whitespace/dots etc.
3965
4074
  #getDialCode(number, includeAreaCode) {
4075
+ if (!number.startsWith("+")) {
4076
+ return "";
4077
+ }
3966
4078
  let dialCode = "";
3967
- if (number.startsWith("+")) {
3968
- let numericChars = "";
3969
- let foundBaseDialCode = false;
3970
- for (let i = 0; i < number.length; i++) {
3971
- const c = number.charAt(i);
3972
- if (/[0-9]/.test(c)) {
3973
- numericChars += c;
3974
- const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
3975
- if (!hasMapEntry) {
3976
- break;
3977
- }
3978
- if (this.#dialCodes.has(numericChars)) {
3979
- dialCode = number.substring(0, i + 1);
3980
- foundBaseDialCode = true;
3981
- if (!includeAreaCode) {
3982
- break;
3983
- }
3984
- } else if (includeAreaCode && foundBaseDialCode) {
3985
- dialCode = number.substring(0, i + 1);
3986
- }
3987
- if (numericChars.length === this.#dialCodeMaxLen) {
3988
- break;
3989
- }
4079
+ let numericChars = "";
4080
+ let foundBaseDialCode = false;
4081
+ for (let i = 0; i < number.length; i++) {
4082
+ const c = number.charAt(i);
4083
+ if (!/[0-9]/.test(c)) {
4084
+ continue;
4085
+ }
4086
+ numericChars += c;
4087
+ const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
4088
+ if (!hasMapEntry) {
4089
+ break;
4090
+ }
4091
+ if (this.#dialCodes.has(numericChars)) {
4092
+ dialCode = number.substring(0, i + 1);
4093
+ foundBaseDialCode = true;
4094
+ if (!includeAreaCode) {
4095
+ break;
3990
4096
  }
4097
+ } else if (includeAreaCode && foundBaseDialCode) {
4098
+ dialCode = number.substring(0, i + 1);
4099
+ }
4100
+ if (numericChars.length === this.#dialCodeMaxLen) {
4101
+ break;
3991
4102
  }
3992
4103
  }
3993
4104
  return dialCode;
@@ -4035,18 +4146,19 @@ var Iti = class _Iti {
4035
4146
  //**************************
4036
4147
  //* Called when the geoip call returns.
4037
4148
  #handleAutoCountry() {
4149
+ if (!this.#autoCountryDeferred || !intlTelInput.autoCountry) {
4150
+ return;
4151
+ }
4038
4152
  if (this.#destroyed) {
4039
- this.#autoCountryDeferred?.resolve();
4153
+ this.#autoCountryDeferred.resolve();
4040
4154
  return;
4041
4155
  }
4042
- if (this.#options.initialCountry === INITIAL_COUNTRY.AUTO && intlTelInput.autoCountry) {
4043
- this.#defaultCountry = intlTelInput.autoCountry;
4044
- const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4045
- if (!hasSelectedCountryOrGlobe) {
4046
- this.setCountry(this.#defaultCountry);
4047
- }
4048
- this.#autoCountryDeferred?.resolve();
4156
+ this.#defaultCountry = intlTelInput.autoCountry;
4157
+ const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4158
+ if (!hasSelectedCountryOrGlobe) {
4159
+ this.setCountry(this.#defaultCountry);
4049
4160
  }
4161
+ this.#autoCountryDeferred.resolve();
4050
4162
  }
4051
4163
  //* Called when the geoip call fails or times out.
4052
4164
  #handleAutoCountryFailure() {
@@ -4063,15 +4175,17 @@ var Iti = class _Iti {
4063
4175
  this.#utilsScriptDeferred?.resolve();
4064
4176
  return;
4065
4177
  }
4066
- if (intlTelInput.utils) {
4067
- const inputValue = this.#getTelInputValue();
4068
- if (inputValue) {
4069
- this.#updateValFromNumber(inputValue);
4070
- }
4071
- if (this.#selectedCountryData) {
4072
- this.#updatePlaceholder();
4073
- this.#updateMaxLength();
4074
- }
4178
+ if (!intlTelInput.utils) {
4179
+ this.#utilsScriptDeferred?.resolve();
4180
+ return;
4181
+ }
4182
+ const inputValue = this.#getTelInputValue();
4183
+ if (inputValue) {
4184
+ this.#updateValFromNumber(inputValue);
4185
+ }
4186
+ if (this.#selectedCountryData) {
4187
+ this.#updatePlaceholder();
4188
+ this.#updateMaxLength();
4075
4189
  }
4076
4190
  this.#utilsScriptDeferred?.resolve();
4077
4191
  }
@@ -4213,7 +4327,9 @@ var Iti = class _Iti {
4213
4327
  const hasAlphaChar = alphaCharPosition > -1;
4214
4328
  if (hasAlphaChar) {
4215
4329
  const selectedIso2 = this.#selectedCountryData?.iso2;
4216
- const hasExtension = Boolean(intlTelInput.utils.getExtension(val, selectedIso2));
4330
+ const hasExtension = Boolean(
4331
+ intlTelInput.utils.getExtension(val, selectedIso2)
4332
+ );
4217
4333
  if (hasExtension) {
4218
4334
  return allowNumberExtensions;
4219
4335
  }
@@ -4239,15 +4355,16 @@ var Iti = class _Iti {
4239
4355
  }
4240
4356
  const currentCountry = this.#selectedCountryData?.iso2;
4241
4357
  const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
4242
- if (isCountryChange) {
4243
- this.#setCountry(iso2Lower);
4244
- this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4245
- if (this.#options.formatOnDisplay) {
4246
- const inputValue = this.#getTelInputValue();
4247
- this.#updateValFromNumber(inputValue);
4248
- }
4249
- this.#triggerCountryChange();
4358
+ if (!isCountryChange) {
4359
+ return;
4360
+ }
4361
+ this.#setCountry(iso2Lower);
4362
+ this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4363
+ if (this.#options.formatOnDisplay) {
4364
+ const inputValue = this.#getTelInputValue();
4365
+ this.#updateValFromNumber(inputValue);
4250
4366
  }
4367
+ this.#triggerCountryChange();
4251
4368
  }
4252
4369
  //* Set the input value and update the country.
4253
4370
  setNumber(number) {
@@ -4385,7 +4502,7 @@ var intlTelInput = Object.assign(
4385
4502
  attachUtils,
4386
4503
  startedLoadingUtilsScript: false,
4387
4504
  startedLoadingAutoCountry: false,
4388
- version: "27.0.0"
4505
+ version: "27.0.2"
4389
4506
  }
4390
4507
  );
4391
4508
  var intl_tel_input_default = intlTelInput;