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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v27.0.0
2
+ * International Telephone Input v27.0.2
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -301,7 +301,63 @@ var _factory = (() => {
301
301
  // Canada
302
302
  "1",
303
303
  1,
304
- ["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"],
304
+ [
305
+ "204",
306
+ "226",
307
+ "236",
308
+ "249",
309
+ "250",
310
+ "257",
311
+ "263",
312
+ "289",
313
+ "306",
314
+ "343",
315
+ "354",
316
+ "365",
317
+ "367",
318
+ "368",
319
+ "382",
320
+ "403",
321
+ "416",
322
+ "418",
323
+ "428",
324
+ "431",
325
+ "437",
326
+ "438",
327
+ "450",
328
+ "468",
329
+ "474",
330
+ "506",
331
+ "514",
332
+ "519",
333
+ "548",
334
+ "579",
335
+ "581",
336
+ "584",
337
+ "587",
338
+ "604",
339
+ "613",
340
+ "639",
341
+ "647",
342
+ "672",
343
+ "683",
344
+ "705",
345
+ "709",
346
+ "742",
347
+ "753",
348
+ "778",
349
+ "780",
350
+ "782",
351
+ "807",
352
+ "819",
353
+ "825",
354
+ "867",
355
+ "873",
356
+ "879",
357
+ "902",
358
+ "905",
359
+ "942"
360
+ ],
305
361
  "1"
306
362
  ],
307
363
  [
@@ -1960,9 +2016,10 @@ var _factory = (() => {
1960
2016
  console.warn(`[intl-tel-input] ${message}`);
1961
2017
  };
1962
2018
  var warnOption = (optionName, expectedType, actualValue) => {
1963
- warn(`Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`);
2019
+ warn(
2020
+ `Option '${optionName}' must be ${expectedType}; got ${toString(actualValue)}. Ignoring.`
2021
+ );
1964
2022
  };
1965
- var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
1966
2023
  var validateIso2Array = (key, value) => {
1967
2024
  const expectedType = "an array of ISO2 country code strings";
1968
2025
  if (!Array.isArray(value)) {
@@ -1995,7 +2052,7 @@ var _factory = (() => {
1995
2052
  }
1996
2053
  const validatedOptions = {};
1997
2054
  for (const [key, value] of Object.entries(customOptions)) {
1998
- if (!hasOwn(defaults, key)) {
2055
+ if (!Object.hasOwn(defaults, key)) {
1999
2056
  warn(`Unknown option '${key}'. Ignoring.`);
2000
2057
  continue;
2001
2058
  }
@@ -2089,8 +2146,12 @@ var _factory = (() => {
2089
2146
  break;
2090
2147
  }
2091
2148
  const lower = value.toLowerCase();
2092
- if (lower && (lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower))) {
2093
- warnOption("initialCountry", "a valid ISO2 country code or 'auto'", value);
2149
+ if (lower && lower !== INITIAL_COUNTRY.AUTO && !isIso2(lower)) {
2150
+ warnOption(
2151
+ "initialCountry",
2152
+ "a valid ISO2 country code or 'auto'",
2153
+ value
2154
+ );
2094
2155
  break;
2095
2156
  }
2096
2157
  validatedOptions[key] = value;
@@ -2107,14 +2168,22 @@ var _factory = (() => {
2107
2168
  case "allowedNumberTypes":
2108
2169
  if (value !== null) {
2109
2170
  if (!Array.isArray(value)) {
2110
- warnOption("allowedNumberTypes", "an array of number types or null", value);
2171
+ warnOption(
2172
+ "allowedNumberTypes",
2173
+ "an array of number types or null",
2174
+ value
2175
+ );
2111
2176
  break;
2112
2177
  }
2113
2178
  let allValid = true;
2114
2179
  for (const v of value) {
2115
2180
  if (typeof v !== "string" || !NUMBER_TYPE_SET.has(v)) {
2116
2181
  const validTypes = Array.from(NUMBER_TYPE_SET).join(", ");
2117
- warnOption("allowedNumberTypes", `an array of valid number types (${validTypes})`, v);
2182
+ warnOption(
2183
+ "allowedNumberTypes",
2184
+ `an array of valid number types (${validTypes})`,
2185
+ v
2186
+ );
2118
2187
  allValid = false;
2119
2188
  break;
2120
2189
  }
@@ -2283,6 +2352,7 @@ var _factory = (() => {
2283
2352
  #searchResultsA11yText;
2284
2353
  #dropdownForContainer;
2285
2354
  #selectedItem = null;
2355
+ #viewportHandler = null;
2286
2356
  // public
2287
2357
  telInput;
2288
2358
  countryContainer;
@@ -2333,16 +2403,12 @@ var _factory = (() => {
2333
2403
  const wrapper = this.#createWrapperAndInsert();
2334
2404
  this.#maybeBuildCountryContainer(wrapper);
2335
2405
  wrapper.appendChild(this.telInput);
2406
+ this.#maybeEnsureDropdownWidthSet();
2336
2407
  this.#maybeUpdateInputPaddingAndReveal();
2337
2408
  this.#maybeBuildHiddenInputs(wrapper);
2338
2409
  }
2339
2410
  #createWrapperAndInsert() {
2340
- const {
2341
- allowDropdown,
2342
- showFlags,
2343
- containerClass,
2344
- useFullscreenPopup
2345
- } = this.#options;
2411
+ const { allowDropdown, showFlags, containerClass, useFullscreenPopup } = this.#options;
2346
2412
  const parentClasses = buildClassNames({
2347
2413
  iti: true,
2348
2414
  "iti--allow-dropdown": allowDropdown,
@@ -2359,72 +2425,74 @@ var _factory = (() => {
2359
2425
  }
2360
2426
  #maybeBuildCountryContainer(wrapper) {
2361
2427
  const { allowDropdown, separateDialCode, showFlags } = this.#options;
2362
- if (allowDropdown || showFlags || separateDialCode) {
2363
- this.countryContainer = createEl(
2364
- "div",
2365
- // visibly hidden until we measure it's width to set the input padding correctly
2366
- { class: `iti__country-container ${CLASSES.V_HIDE}` },
2367
- wrapper
2428
+ if (!allowDropdown && !showFlags && !separateDialCode) {
2429
+ return;
2430
+ }
2431
+ this.countryContainer = createEl(
2432
+ "div",
2433
+ // visibly hidden until we measure its width to set the input padding correctly
2434
+ { class: `iti__country-container ${CLASSES.V_HIDE}` },
2435
+ wrapper
2436
+ );
2437
+ if (allowDropdown) {
2438
+ this.selectedCountry = createEl(
2439
+ "button",
2440
+ {
2441
+ type: "button",
2442
+ class: "iti__selected-country",
2443
+ [ARIA.EXPANDED]: "false",
2444
+ [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2445
+ [ARIA.HASPOPUP]: "dialog",
2446
+ [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2447
+ },
2448
+ this.countryContainer
2368
2449
  );
2369
- if (allowDropdown) {
2370
- this.selectedCountry = createEl(
2371
- "button",
2372
- {
2373
- type: "button",
2374
- class: "iti__selected-country",
2375
- [ARIA.EXPANDED]: "false",
2376
- [ARIA.LABEL]: this.#options.i18n.noCountrySelected,
2377
- [ARIA.HASPOPUP]: "dialog",
2378
- [ARIA.CONTROLS]: `iti-${this.#id}__dropdown-content`
2379
- },
2380
- this.countryContainer
2381
- );
2382
- if (this.telInput.disabled) {
2383
- this.selectedCountry.setAttribute("disabled", "true");
2384
- }
2385
- } else {
2386
- this.selectedCountry = createEl(
2387
- "div",
2388
- { class: "iti__selected-country" },
2389
- this.countryContainer
2390
- );
2450
+ if (this.telInput.disabled) {
2451
+ this.selectedCountry.setAttribute("disabled", "true");
2391
2452
  }
2392
- const selectedCountryPrimary = createEl(
2453
+ } else {
2454
+ this.selectedCountry = createEl(
2393
2455
  "div",
2394
- { class: "iti__selected-country-primary" },
2395
- this.selectedCountry
2456
+ { class: "iti__selected-country" },
2457
+ this.countryContainer
2396
2458
  );
2397
- this.selectedCountryInner = createEl(
2459
+ }
2460
+ const selectedCountryPrimary = createEl(
2461
+ "div",
2462
+ { class: "iti__selected-country-primary" },
2463
+ this.selectedCountry
2464
+ );
2465
+ this.selectedCountryInner = createEl(
2466
+ "div",
2467
+ { class: CLASSES.FLAG },
2468
+ selectedCountryPrimary
2469
+ );
2470
+ if (allowDropdown) {
2471
+ this.#dropdownArrow = createEl(
2398
2472
  "div",
2399
- { class: CLASSES.FLAG },
2473
+ { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2400
2474
  selectedCountryPrimary
2401
2475
  );
2402
- if (allowDropdown) {
2403
- this.#dropdownArrow = createEl(
2404
- "div",
2405
- { class: "iti__arrow", [ARIA.HIDDEN]: "true" },
2406
- selectedCountryPrimary
2407
- );
2408
- }
2409
- if (separateDialCode) {
2410
- this.#selectedDialCode = createEl(
2411
- "div",
2412
- { class: "iti__selected-dial-code" },
2413
- this.selectedCountry
2414
- );
2415
- }
2416
- if (allowDropdown) {
2417
- this.#buildDropdownContent();
2418
- }
2476
+ }
2477
+ if (separateDialCode) {
2478
+ this.#selectedDialCode = createEl(
2479
+ "div",
2480
+ { class: "iti__selected-dial-code" },
2481
+ this.selectedCountry
2482
+ );
2483
+ }
2484
+ if (allowDropdown) {
2485
+ this.#buildDropdownContent();
2419
2486
  }
2420
2487
  }
2421
2488
  #maybeEnsureDropdownWidthSet() {
2422
- const { fixDropdownWidth } = this.#options;
2423
- if (fixDropdownWidth && !this.#dropdownContent.style.width) {
2424
- const inputWidth = this.telInput.offsetWidth;
2425
- if (inputWidth > 0) {
2426
- this.#dropdownContent.style.width = `${inputWidth}px`;
2427
- }
2489
+ const { fixDropdownWidth, allowDropdown } = this.#options;
2490
+ if (!allowDropdown || !fixDropdownWidth || this.#dropdownContent.style.width) {
2491
+ return;
2492
+ }
2493
+ const inputWidth = this.telInput.offsetWidth;
2494
+ if (inputWidth > 0) {
2495
+ this.#dropdownContent.style.width = `${inputWidth}px`;
2428
2496
  }
2429
2497
  }
2430
2498
  #buildDropdownContent() {
@@ -2464,7 +2532,6 @@ var _factory = (() => {
2464
2532
  this.#updateSearchResultsA11yText();
2465
2533
  }
2466
2534
  if (!useFullscreenPopup) {
2467
- this.#maybeEnsureDropdownWidthSet();
2468
2535
  this.#inlineDropdownHeight = this.#getHiddenInlineDropdownHeight();
2469
2536
  if (countrySearch) {
2470
2537
  this.#dropdownContent.style.height = `${this.#inlineDropdownHeight}px`;
@@ -2546,43 +2613,45 @@ var _factory = (() => {
2546
2613
  this.#searchNoResults.textContent = i18n.searchEmptyState ?? null;
2547
2614
  }
2548
2615
  #maybeUpdateInputPaddingAndReveal() {
2549
- if (this.countryContainer) {
2550
- this.#updateInputPadding();
2551
- this.countryContainer.classList.remove(CLASSES.V_HIDE);
2616
+ if (!this.countryContainer) {
2617
+ return;
2552
2618
  }
2619
+ this.#updateInputPadding();
2620
+ this.countryContainer.classList.remove(CLASSES.V_HIDE);
2553
2621
  }
2554
2622
  #maybeBuildHiddenInputs(wrapper) {
2555
2623
  const { hiddenInput } = this.#options;
2556
- if (hiddenInput) {
2557
- const telInputName = this.telInput.getAttribute("name") || "";
2558
- const names = hiddenInput(telInputName);
2559
- if (names.phone) {
2560
- const existingInput = this.telInput.form?.querySelector(
2561
- `input[name="${names.phone}"]`
2562
- );
2563
- if (existingInput) {
2564
- this.hiddenInputPhone = existingInput;
2565
- } else {
2566
- this.hiddenInputPhone = createEl("input", {
2567
- type: "hidden",
2568
- name: names.phone
2569
- });
2570
- wrapper.appendChild(this.hiddenInputPhone);
2571
- }
2624
+ if (!hiddenInput) {
2625
+ return;
2626
+ }
2627
+ const telInputName = this.telInput.getAttribute("name") || "";
2628
+ const names = hiddenInput(telInputName);
2629
+ if (names.phone) {
2630
+ const existingInput = this.telInput.form?.querySelector(
2631
+ `input[name="${names.phone}"]`
2632
+ );
2633
+ if (existingInput) {
2634
+ this.hiddenInputPhone = existingInput;
2635
+ } else {
2636
+ this.hiddenInputPhone = createEl("input", {
2637
+ type: "hidden",
2638
+ name: names.phone
2639
+ });
2640
+ wrapper.appendChild(this.hiddenInputPhone);
2572
2641
  }
2573
- if (names.country) {
2574
- const existingInput = this.telInput.form?.querySelector(
2575
- `input[name="${names.country}"]`
2576
- );
2577
- if (existingInput) {
2578
- this.hiddenInputCountry = existingInput;
2579
- } else {
2580
- this.hiddenInputCountry = createEl("input", {
2581
- type: "hidden",
2582
- name: names.country
2583
- });
2584
- wrapper.appendChild(this.hiddenInputCountry);
2585
- }
2642
+ }
2643
+ if (names.country) {
2644
+ const existingInput = this.telInput.form?.querySelector(
2645
+ `input[name="${names.country}"]`
2646
+ );
2647
+ if (existingInput) {
2648
+ this.hiddenInputCountry = existingInput;
2649
+ } else {
2650
+ this.hiddenInputCountry = createEl("input", {
2651
+ type: "hidden",
2652
+ name: names.country
2653
+ });
2654
+ wrapper.appendChild(this.hiddenInputCountry);
2586
2655
  }
2587
2656
  }
2588
2657
  }
@@ -2641,30 +2710,32 @@ var _factory = (() => {
2641
2710
  //* To get the right styling to apply, all we need is a shallow clone of the container,
2642
2711
  //* and then to inject a deep clone of the selectedCountry element.
2643
2712
  #getHiddenSelectedCountryWidth() {
2644
- if (this.telInput.parentNode) {
2645
- const body = _UI.#getBody();
2646
- const containerClone = this.telInput.parentNode.cloneNode(
2647
- false
2648
- );
2649
- containerClone.style.visibility = "hidden";
2650
- body.appendChild(containerClone);
2651
- const countryContainerClone = this.countryContainer.cloneNode();
2652
- containerClone.appendChild(countryContainerClone);
2653
- const selectedCountryClone = this.selectedCountry.cloneNode(
2654
- true
2655
- );
2656
- countryContainerClone.appendChild(selectedCountryClone);
2657
- const width = selectedCountryClone.offsetWidth;
2658
- body.removeChild(containerClone);
2659
- return width;
2713
+ if (!this.telInput.parentNode) {
2714
+ return 0;
2660
2715
  }
2661
- return 0;
2716
+ const body = _UI.#getBody();
2717
+ const containerClone = this.telInput.parentNode.cloneNode(
2718
+ false
2719
+ );
2720
+ containerClone.style.visibility = "hidden";
2721
+ body.appendChild(containerClone);
2722
+ const countryContainerClone = this.countryContainer.cloneNode();
2723
+ containerClone.appendChild(countryContainerClone);
2724
+ const selectedCountryClone = this.selectedCountry.cloneNode(
2725
+ true
2726
+ );
2727
+ countryContainerClone.appendChild(selectedCountryClone);
2728
+ const width = selectedCountryClone.offsetWidth;
2729
+ body.removeChild(containerClone);
2730
+ return width;
2662
2731
  }
2663
- // this is run before we add the dropdown to the DOM
2732
+ // Get the dropdown height (before it is added to the DOM)
2664
2733
  #getHiddenInlineDropdownHeight() {
2665
2734
  const body = _UI.#getBody();
2666
2735
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2667
- const tempContainer = createEl("div", { class: "iti iti--inline-dropdown" });
2736
+ const tempContainer = createEl("div", {
2737
+ class: "iti iti--inline-dropdown"
2738
+ });
2668
2739
  tempContainer.appendChild(this.#dropdownContent);
2669
2740
  tempContainer.style.visibility = "hidden";
2670
2741
  body.appendChild(tempContainer);
@@ -2737,7 +2808,10 @@ var _factory = (() => {
2737
2808
  this.highlightedItem.classList.add(CLASSES.HIGHLIGHT);
2738
2809
  if (this.#options.countrySearch) {
2739
2810
  const activeDescendant = this.highlightedItem.getAttribute("id") || "";
2740
- this.searchInput.setAttribute(ARIA.ACTIVE_DESCENDANT, activeDescendant);
2811
+ this.searchInput.setAttribute(
2812
+ ARIA.ACTIVE_DESCENDANT,
2813
+ activeDescendant
2814
+ );
2741
2815
  }
2742
2816
  if (shouldFocus) {
2743
2817
  this.highlightedItem.focus();
@@ -2818,11 +2892,7 @@ var _factory = (() => {
2818
2892
  }
2819
2893
  // UI: Open the dropdown (DOM only).
2820
2894
  openDropdown() {
2821
- const {
2822
- countrySearch,
2823
- dropdownAlwaysOpen,
2824
- dropdownContainer
2825
- } = this.#options;
2895
+ const { countrySearch, dropdownAlwaysOpen, dropdownContainer } = this.#options;
2826
2896
  this.#maybeEnsureDropdownWidthSet();
2827
2897
  if (dropdownContainer) {
2828
2898
  this.#handleDropdownContainer();
@@ -2837,15 +2907,22 @@ var _factory = (() => {
2837
2907
  }
2838
2908
  this.#dropdownContent.classList.remove(CLASSES.HIDE);
2839
2909
  this.selectedCountry.setAttribute(ARIA.EXPANDED, "true");
2840
- if (countrySearch) {
2841
- const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2842
- if (itemToHighlight) {
2843
- this.highlightListItem(itemToHighlight, false);
2844
- this.scrollCountryListToItem(itemToHighlight);
2845
- }
2846
- if (!dropdownAlwaysOpen) {
2847
- this.searchInput.focus();
2848
- }
2910
+ const itemToHighlight = this.#selectedItem ?? this.countryList.firstElementChild;
2911
+ if (itemToHighlight) {
2912
+ this.highlightListItem(itemToHighlight, false);
2913
+ this.scrollCountryListToItem(itemToHighlight);
2914
+ }
2915
+ if (countrySearch && !dropdownAlwaysOpen) {
2916
+ this.searchInput.focus();
2917
+ }
2918
+ if (this.#options.useFullscreenPopup && this.#dropdownForContainer && window.visualViewport) {
2919
+ this.#viewportHandler = () => {
2920
+ this.#adjustFullscreenPopupToViewport();
2921
+ if (this.highlightedItem) {
2922
+ this.scrollCountryListToItem(this.highlightedItem);
2923
+ }
2924
+ };
2925
+ window.visualViewport.addEventListener("resize", this.#viewportHandler);
2849
2926
  }
2850
2927
  this.#dropdownArrow.classList.add(CLASSES.ARROW_UP);
2851
2928
  }
@@ -2864,6 +2941,13 @@ var _factory = (() => {
2864
2941
  }
2865
2942
  }
2866
2943
  this.#dropdownArrow.classList.remove(CLASSES.ARROW_UP);
2944
+ if (this.#viewportHandler && window.visualViewport) {
2945
+ window.visualViewport.removeEventListener(
2946
+ "resize",
2947
+ this.#viewportHandler
2948
+ );
2949
+ this.#viewportHandler = null;
2950
+ }
2867
2951
  if (dropdownContainer) {
2868
2952
  this.#dropdownForContainer.remove();
2869
2953
  this.#dropdownForContainer.style.top = "";
@@ -2906,6 +2990,16 @@ var _factory = (() => {
2906
2990
  }
2907
2991
  dropdownContainer.appendChild(this.#dropdownForContainer);
2908
2992
  }
2993
+ // Adjust the fullscreen popup dimensions to match the visual viewport,
2994
+ // so it stays above the virtual keyboard on mobile devices.
2995
+ #adjustFullscreenPopupToViewport() {
2996
+ const vv = window.visualViewport;
2997
+ if (!vv || !this.#dropdownForContainer) {
2998
+ return;
2999
+ }
3000
+ const virtualKeyboardHeight = window.innerHeight - vv.height;
3001
+ this.#dropdownForContainer.style.bottom = `${virtualKeyboardHeight}px`;
3002
+ }
2909
3003
  // UI: Whether the dropdown is currently closed (hidden).
2910
3004
  isDropdownClosed() {
2911
3005
  return this.#dropdownContent.classList.contains(CLASSES.HIDE);
@@ -2955,7 +3049,7 @@ var _factory = (() => {
2955
3049
  (country) => !excludeCountries.includes(country.iso2)
2956
3050
  );
2957
3051
  }
2958
- return data_default;
3052
+ return [...data_default];
2959
3053
  };
2960
3054
  var generateCountryNames = (countries, options) => {
2961
3055
  const { countryNameLocale, i18n } = options;
@@ -2988,7 +3082,7 @@ var _factory = (() => {
2988
3082
  if (dialCode.length > dialCodeMaxLen) {
2989
3083
  dialCodeMaxLen = dialCode.length;
2990
3084
  }
2991
- if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
3085
+ if (!Object.hasOwn(dialCodeToIso2Map, dialCode)) {
2992
3086
  dialCodeToIso2Map[dialCode] = [];
2993
3087
  }
2994
3088
  const iso2List = dialCodeToIso2Map[dialCode];
@@ -2997,7 +3091,9 @@ var _factory = (() => {
2997
3091
  }
2998
3092
  iso2List.push(iso2);
2999
3093
  };
3000
- const countriesSortedByPriority = [...countries].sort((a, b) => a.priority - b.priority);
3094
+ const countriesSortedByPriority = [...countries].sort(
3095
+ (a, b) => a.priority - b.priority
3096
+ );
3001
3097
  for (const c of countriesSortedByPriority) {
3002
3098
  if (!dialCodes.has(c.dialCode)) {
3003
3099
  dialCodes.add(c.dialCode);
@@ -3066,15 +3162,12 @@ var _factory = (() => {
3066
3162
 
3067
3163
  // src/js/format/formatting.ts
3068
3164
  var beforeSetNumber = (fullNumber, hasValidDialCode, separateDialCode, selectedCountryData) => {
3069
- let number = fullNumber;
3070
- if (separateDialCode) {
3071
- if (hasValidDialCode) {
3072
- const dialCode = `+${selectedCountryData.dialCode}`;
3073
- const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3074
- number = number.substring(start);
3075
- }
3165
+ if (!separateDialCode || !hasValidDialCode) {
3166
+ return fullNumber;
3076
3167
  }
3077
- return number;
3168
+ const dialCode = `+${selectedCountryData.dialCode}`;
3169
+ const start = fullNumber[dialCode.length] === " " || fullNumber[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
3170
+ return fullNumber.substring(start);
3078
3171
  };
3079
3172
  var formatNumberAsYouType = (fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) => {
3080
3173
  const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData?.iso2) : fullNumber;
@@ -3173,7 +3266,10 @@ var _factory = (() => {
3173
3266
  }
3174
3267
  const base = this.#userNumeralSet === "arabic-indic" ? 1632 : 1776;
3175
3268
  const regex = this.#userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
3176
- return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
3269
+ return str.replace(
3270
+ regex,
3271
+ (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base))
3272
+ );
3177
3273
  }
3178
3274
  isAscii() {
3179
3275
  return !this.#userNumeralSet || this.#userNumeralSet === "ascii";
@@ -3184,7 +3280,9 @@ var _factory = (() => {
3184
3280
  var id = 0;
3185
3281
  var ensureUtils = (methodName) => {
3186
3282
  if (!intlTelInput.utils) {
3187
- throw new Error(`intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`);
3283
+ throw new Error(
3284
+ `intlTelInput.utils is required for ${methodName}(). See: https://intl-tel-input.com/docs/utils`
3285
+ );
3188
3286
  }
3189
3287
  };
3190
3288
  var createDeferred = () => {
@@ -3339,9 +3437,13 @@ var _factory = (() => {
3339
3437
  this.#ui.hiddenInputCountry.value = this.#selectedCountryData?.iso2 || "";
3340
3438
  }
3341
3439
  };
3342
- this.#ui.telInput.form?.addEventListener("submit", handleHiddenInputSubmit, {
3343
- signal: this.#abortController.signal
3344
- });
3440
+ this.#ui.telInput.form?.addEventListener(
3441
+ "submit",
3442
+ handleHiddenInputSubmit,
3443
+ {
3444
+ signal: this.#abortController.signal
3445
+ }
3446
+ );
3345
3447
  }
3346
3448
  //* initialise the dropdown listeners.
3347
3449
  #initDropdownListeners() {
@@ -3370,7 +3472,12 @@ var _factory = (() => {
3370
3472
  }
3371
3473
  );
3372
3474
  const handleCountryContainerKeydown = (e) => {
3373
- const allowedKeys = [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.SPACE, KEYS.ENTER];
3475
+ const allowedKeys = [
3476
+ KEYS.ARROW_UP,
3477
+ KEYS.ARROW_DOWN,
3478
+ KEYS.SPACE,
3479
+ KEYS.ENTER
3480
+ ];
3374
3481
  if (this.#ui.isDropdownClosed() && allowedKeys.includes(e.key)) {
3375
3482
  e.preventDefault();
3376
3483
  e.stopPropagation();
@@ -3388,8 +3495,8 @@ var _factory = (() => {
3388
3495
  }
3389
3496
  //* Init requests: utils script / geo ip lookup.
3390
3497
  #initRequests() {
3391
- const { loadUtils, initialCountry, geoIpLookup } = this.#options;
3392
- if (loadUtils && !intlTelInput.utils) {
3498
+ if (this.#utilsScriptDeferred) {
3499
+ const { loadUtils } = this.#options;
3393
3500
  const doAttachUtils = () => {
3394
3501
  intlTelInput.attachUtils(loadUtils)?.catch(() => {
3395
3502
  });
@@ -3401,13 +3508,10 @@ var _factory = (() => {
3401
3508
  signal: this.#abortController.signal
3402
3509
  });
3403
3510
  }
3404
- } else {
3405
- this.#utilsScriptDeferred?.resolve();
3406
3511
  }
3407
- const isAutoCountry = initialCountry === INITIAL_COUNTRY.AUTO && geoIpLookup;
3408
- if (isAutoCountry) {
3512
+ if (this.#autoCountryDeferred) {
3409
3513
  if (this.#selectedCountryData) {
3410
- this.#autoCountryDeferred?.resolve();
3514
+ this.#autoCountryDeferred.resolve();
3411
3515
  } else {
3412
3516
  this.#loadAutoCountry();
3413
3517
  }
@@ -3417,28 +3521,29 @@ var _factory = (() => {
3417
3521
  #loadAutoCountry() {
3418
3522
  if (intlTelInput.autoCountry) {
3419
3523
  this.#handleAutoCountry();
3420
- } else {
3421
- this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3422
- if (!intlTelInput.startedLoadingAutoCountry) {
3423
- intlTelInput.startedLoadingAutoCountry = true;
3424
- if (typeof this.#options.geoIpLookup === "function") {
3425
- const successCallback = (iso2 = "") => {
3426
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3427
- const iso2Lower = iso2.toLowerCase();
3428
- if (isIso2(iso2Lower)) {
3429
- intlTelInput.autoCountry = iso2Lower;
3430
- setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3431
- } else {
3432
- _Iti.forEachInstance("handleAutoCountryFailure");
3433
- }
3434
- };
3435
- const failureCallback = () => {
3436
- this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3437
- _Iti.forEachInstance("handleAutoCountryFailure");
3438
- };
3439
- this.#options.geoIpLookup(successCallback, failureCallback);
3524
+ return;
3525
+ }
3526
+ this.#ui.selectedCountryInner.classList.add(CLASSES.LOADING);
3527
+ if (intlTelInput.startedLoadingAutoCountry) {
3528
+ return;
3529
+ }
3530
+ intlTelInput.startedLoadingAutoCountry = true;
3531
+ if (typeof this.#options.geoIpLookup === "function") {
3532
+ const successCallback = (iso2 = "") => {
3533
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3534
+ const iso2Lower = iso2.toLowerCase();
3535
+ if (isIso2(iso2Lower)) {
3536
+ intlTelInput.autoCountry = iso2Lower;
3537
+ setTimeout(() => _Iti.forEachInstance("handleAutoCountry"));
3538
+ } else {
3539
+ _Iti.forEachInstance("handleAutoCountryFailure");
3440
3540
  }
3441
- }
3541
+ };
3542
+ const failureCallback = () => {
3543
+ this.#ui.selectedCountryInner.classList.remove(CLASSES.LOADING);
3544
+ _Iti.forEachInstance("handleAutoCountryFailure");
3545
+ };
3546
+ this.#options.geoIpLookup(successCallback, failureCallback);
3442
3547
  }
3443
3548
  }
3444
3549
  #openDropdownWithPlus() {
@@ -3488,10 +3593,7 @@ var _factory = (() => {
3488
3593
  const isAscii = this.#numerals.isAscii();
3489
3594
  if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
3490
3595
  const currentCaretPos = this.#ui.telInput.selectionStart || 0;
3491
- const valueBeforeCaret = inputValue.substring(
3492
- 0,
3493
- currentCaretPos
3494
- );
3596
+ const valueBeforeCaret = inputValue.substring(0, currentCaretPos);
3495
3597
  const relevantCharsBeforeCaret = valueBeforeCaret.replace(
3496
3598
  REGEX.NON_PLUS_NUMERIC_GLOBAL,
3497
3599
  ""
@@ -3534,96 +3636,100 @@ var _factory = (() => {
3534
3636
  }
3535
3637
  #maybeBindKeydownListener() {
3536
3638
  const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.#options;
3537
- if (strictMode || separateDialCode) {
3538
- const handleKeydownEvent = (e) => {
3539
- if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
3540
- if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3541
- e.preventDefault();
3542
- this.#openDropdownWithPlus();
3543
- return;
3544
- }
3545
- if (strictMode) {
3546
- const inputValue = this.#getTelInputValue();
3547
- const alreadyHasPlus = inputValue.startsWith("+");
3548
- const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3549
- const normalisedKey = this.#numerals.normalise(e.key);
3550
- const isNumeric = /^[0-9]$/.test(normalisedKey);
3551
- const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3552
- const input = this.#ui.telInput;
3553
- const selStart = input.selectionStart;
3554
- const selEnd = input.selectionEnd;
3555
- const before = inputValue.slice(0, selStart ?? void 0);
3556
- const after = inputValue.slice(selEnd ?? void 0);
3557
- const newValue = before + e.key + after;
3558
- const newFullNumber = this.#getFullNumber(newValue);
3559
- let hasExceededMaxLength = false;
3560
- if (intlTelInput.utils && this.#maxCoreNumberLength) {
3561
- const coreNumber = intlTelInput.utils.getCoreNumber(
3562
- newFullNumber,
3563
- this.#selectedCountryData?.iso2
3564
- );
3565
- hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3566
- }
3567
- const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3568
- const isChangingDialCode = newCountry !== null;
3569
- if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3570
- e.preventDefault();
3571
- }
3572
- }
3573
- }
3574
- };
3575
- this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3576
- signal: this.#abortController.signal
3577
- });
3639
+ if (!strictMode && !separateDialCode) {
3640
+ return;
3578
3641
  }
3642
+ const handleKeydownEvent = (e) => {
3643
+ if (!e.key || e.key.length !== 1 || e.altKey || e.ctrlKey || e.metaKey) {
3644
+ return;
3645
+ }
3646
+ if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
3647
+ e.preventDefault();
3648
+ this.#openDropdownWithPlus();
3649
+ return;
3650
+ }
3651
+ if (!strictMode) {
3652
+ return;
3653
+ }
3654
+ const inputValue = this.#getTelInputValue();
3655
+ const alreadyHasPlus = inputValue.startsWith("+");
3656
+ const isInitialPlus = !alreadyHasPlus && this.#ui.telInput.selectionStart === 0 && e.key === "+";
3657
+ const normalisedKey = this.#numerals.normalise(e.key);
3658
+ const isNumeric = /^[0-9]$/.test(normalisedKey);
3659
+ const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3660
+ const input = this.#ui.telInput;
3661
+ const selStart = input.selectionStart;
3662
+ const selEnd = input.selectionEnd;
3663
+ const before = inputValue.slice(0, selStart ?? void 0);
3664
+ const after = inputValue.slice(selEnd ?? void 0);
3665
+ const newValue = before + e.key + after;
3666
+ const newFullNumber = this.#getFullNumber(newValue);
3667
+ let hasExceededMaxLength = false;
3668
+ if (intlTelInput.utils && this.#maxCoreNumberLength) {
3669
+ const coreNumber = intlTelInput.utils.getCoreNumber(
3670
+ newFullNumber,
3671
+ this.#selectedCountryData?.iso2
3672
+ );
3673
+ hasExceededMaxLength = coreNumber.length > this.#maxCoreNumberLength;
3674
+ }
3675
+ const newCountry = this.#getNewCountryFromNumber(newFullNumber);
3676
+ const isChangingDialCode = newCountry !== null;
3677
+ if (!isAllowedChar || hasExceededMaxLength && !isChangingDialCode && !isInitialPlus) {
3678
+ e.preventDefault();
3679
+ }
3680
+ };
3681
+ this.#ui.telInput.addEventListener("keydown", handleKeydownEvent, {
3682
+ signal: this.#abortController.signal
3683
+ });
3579
3684
  }
3580
3685
  #maybeBindPasteListener() {
3581
- if (this.#options.strictMode) {
3582
- const handlePasteEvent = (e) => {
3583
- e.preventDefault();
3584
- const input = this.#ui.telInput;
3585
- const selStart = input.selectionStart;
3586
- const selEnd = input.selectionEnd;
3587
- const inputValue = this.#getTelInputValue();
3588
- const before = inputValue.slice(0, selStart ?? void 0);
3589
- const after = inputValue.slice(selEnd ?? void 0);
3590
- const iso2 = this.#selectedCountryData?.iso2;
3591
- const pastedRaw = e.clipboardData.getData("text");
3592
- const pasted = this.#numerals.normalise(pastedRaw);
3593
- const initialCharSelected = selStart === 0 && selEnd > 0;
3594
- const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3595
- const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3596
- const hasLeadingPlus = allowedChars.startsWith("+");
3597
- const numerics = allowedChars.replace(/\+/g, "");
3598
- const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3599
- let newVal = before + sanitised + after;
3600
- if (newVal.length > 5 && intlTelInput.utils) {
3601
- let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3602
- while (coreNumber.length === 0 && newVal.length > 0) {
3603
- newVal = newVal.slice(0, -1);
3604
- coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3605
- }
3606
- if (!coreNumber) {
3686
+ if (!this.#options.strictMode) {
3687
+ return;
3688
+ }
3689
+ const handlePasteEvent = (e) => {
3690
+ e.preventDefault();
3691
+ const input = this.#ui.telInput;
3692
+ const selStart = input.selectionStart;
3693
+ const selEnd = input.selectionEnd;
3694
+ const inputValue = this.#getTelInputValue();
3695
+ const before = inputValue.slice(0, selStart ?? void 0);
3696
+ const after = inputValue.slice(selEnd ?? void 0);
3697
+ const iso2 = this.#selectedCountryData?.iso2;
3698
+ const pastedRaw = e.clipboardData.getData("text");
3699
+ const pasted = this.#numerals.normalise(pastedRaw);
3700
+ const initialCharSelected = selStart === 0 && selEnd > 0;
3701
+ const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3702
+ const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3703
+ const hasLeadingPlus = allowedChars.startsWith("+");
3704
+ const numerics = allowedChars.replace(/\+/g, "");
3705
+ const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3706
+ let newVal = before + sanitised + after;
3707
+ if (newVal.length > 5 && intlTelInput.utils) {
3708
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3709
+ while (coreNumber.length === 0 && newVal.length > 0) {
3710
+ newVal = newVal.slice(0, -1);
3711
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3712
+ }
3713
+ if (!coreNumber) {
3714
+ return;
3715
+ }
3716
+ if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3717
+ if (input.selectionEnd === inputValue.length) {
3718
+ const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3719
+ newVal = newVal.slice(0, newVal.length - trimLength);
3720
+ } else {
3607
3721
  return;
3608
3722
  }
3609
- if (this.#maxCoreNumberLength && coreNumber.length > this.#maxCoreNumberLength) {
3610
- if (input.selectionEnd === inputValue.length) {
3611
- const trimLength = coreNumber.length - this.#maxCoreNumberLength;
3612
- newVal = newVal.slice(0, newVal.length - trimLength);
3613
- } else {
3614
- return;
3615
- }
3616
- }
3617
3723
  }
3618
- this.#setTelInputValue(newVal);
3619
- const caretPos = selStart + sanitised.length;
3620
- input.setSelectionRange(caretPos, caretPos);
3621
- input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3622
- };
3623
- this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3624
- signal: this.#abortController.signal
3625
- });
3626
- }
3724
+ }
3725
+ this.#setTelInputValue(newVal);
3726
+ const caretPos = selStart + sanitised.length;
3727
+ input.setSelectionRange(caretPos, caretPos);
3728
+ input.dispatchEvent(new InputEvent("input", { bubbles: true }));
3729
+ };
3730
+ this.#ui.telInput.addEventListener("paste", handlePasteEvent, {
3731
+ signal: this.#abortController.signal
3732
+ });
3627
3733
  }
3628
3734
  //* Adhere to the input's maxlength attr.
3629
3735
  #cap(number) {
@@ -3830,7 +3936,7 @@ var _factory = (() => {
3830
3936
  //* 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).
3831
3937
  #getNewCountryFromNumber(fullNumber) {
3832
3938
  const plusIndex = fullNumber.indexOf("+");
3833
- let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
3939
+ let number = plusIndex > 0 ? fullNumber.substring(plusIndex) : fullNumber;
3834
3940
  const selectedIso2 = this.#selectedCountryData?.iso2;
3835
3941
  const selectedDialCode = this.#selectedCountryData?.dialCode;
3836
3942
  number = this.#ensureHasDialCode(number);
@@ -3898,33 +4004,34 @@ var _factory = (() => {
3898
4004
  //* Update the maximum valid number length for the currently selected country.
3899
4005
  #updateMaxLength() {
3900
4006
  const { strictMode, placeholderNumberType, allowedNumberTypes } = this.#options;
4007
+ if (!strictMode || !intlTelInput.utils) {
4008
+ return;
4009
+ }
3901
4010
  const iso2 = this.#selectedCountryData?.iso2;
3902
- if (strictMode && intlTelInput.utils) {
3903
- if (iso2) {
3904
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3905
- let exampleNumber = intlTelInput.utils.getExampleNumber(
3906
- iso2,
3907
- false,
3908
- numberType,
3909
- true
3910
- );
3911
- let validNumber = exampleNumber;
3912
- while (intlTelInput.utils.isPossibleNumber(
3913
- exampleNumber,
3914
- iso2,
3915
- allowedNumberTypes
3916
- )) {
3917
- validNumber = exampleNumber;
3918
- exampleNumber += "0";
3919
- }
3920
- const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
3921
- this.#maxCoreNumberLength = coreNumber.length;
3922
- if (iso2 === "by") {
3923
- this.#maxCoreNumberLength = coreNumber.length + 1;
3924
- }
3925
- } else {
3926
- this.#maxCoreNumberLength = null;
3927
- }
4011
+ if (!iso2) {
4012
+ this.#maxCoreNumberLength = null;
4013
+ return;
4014
+ }
4015
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
4016
+ let exampleNumber = intlTelInput.utils.getExampleNumber(
4017
+ iso2,
4018
+ false,
4019
+ numberType,
4020
+ true
4021
+ );
4022
+ let validNumber = exampleNumber;
4023
+ while (intlTelInput.utils.isPossibleNumber(
4024
+ exampleNumber,
4025
+ iso2,
4026
+ allowedNumberTypes
4027
+ )) {
4028
+ validNumber = exampleNumber;
4029
+ exampleNumber += "0";
4030
+ }
4031
+ const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, iso2);
4032
+ this.#maxCoreNumberLength = coreNumber.length;
4033
+ if (iso2 === "by") {
4034
+ this.#maxCoreNumberLength = coreNumber.length + 1;
3928
4035
  }
3929
4036
  }
3930
4037
  //* Update the input placeholder to an example number from the currently selected country.
@@ -3936,19 +4043,20 @@ var _factory = (() => {
3936
4043
  customPlaceholder
3937
4044
  } = this.#options;
3938
4045
  const shouldSetPlaceholder = autoPlaceholder === PLACEHOLDER_MODES.AGGRESSIVE || !this.#ui.hadInitialPlaceholder && autoPlaceholder === PLACEHOLDER_MODES.POLITE;
3939
- if (intlTelInput.utils && shouldSetPlaceholder) {
3940
- const numberType = intlTelInput.utils.numberType[placeholderNumberType];
3941
- let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
3942
- this.#selectedCountryData.iso2,
3943
- nationalMode,
3944
- numberType
3945
- ) : "";
3946
- placeholder = this.#beforeSetNumber(placeholder);
3947
- if (typeof customPlaceholder === "function") {
3948
- placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
3949
- }
3950
- this.#ui.telInput.setAttribute("placeholder", placeholder);
4046
+ if (!intlTelInput.utils || !shouldSetPlaceholder) {
4047
+ return;
3951
4048
  }
4049
+ const numberType = intlTelInput.utils.numberType[placeholderNumberType];
4050
+ let placeholder = this.#selectedCountryData ? intlTelInput.utils.getExampleNumber(
4051
+ this.#selectedCountryData.iso2,
4052
+ nationalMode,
4053
+ numberType
4054
+ ) : "";
4055
+ placeholder = this.#beforeSetNumber(placeholder);
4056
+ if (typeof customPlaceholder === "function") {
4057
+ placeholder = customPlaceholder(placeholder, this.#selectedCountryData);
4058
+ }
4059
+ this.#ui.telInput.setAttribute("placeholder", placeholder);
3952
4060
  }
3953
4061
  //* Called when the user selects a list item from the dropdown.
3954
4062
  #selectListItem(listItem) {
@@ -3980,46 +4088,49 @@ var _factory = (() => {
3980
4088
  //* Note: called from _selectListItem and setCountry
3981
4089
  #updateDialCode(newDialCodeBare) {
3982
4090
  const inputVal = this.#getTelInputValue();
4091
+ if (!inputVal.startsWith("+")) {
4092
+ return;
4093
+ }
3983
4094
  const newDialCode = `+${newDialCodeBare}`;
4095
+ const prevDialCode = this.#getDialCode(inputVal);
3984
4096
  let newNumber;
3985
- if (inputVal.startsWith("+")) {
3986
- const prevDialCode = this.#getDialCode(inputVal);
3987
- if (prevDialCode) {
3988
- newNumber = inputVal.replace(prevDialCode, newDialCode);
3989
- } else {
3990
- newNumber = newDialCode;
3991
- }
3992
- this.#setTelInputValue(newNumber);
4097
+ if (prevDialCode) {
4098
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
4099
+ } else {
4100
+ newNumber = newDialCode;
3993
4101
  }
4102
+ this.#setTelInputValue(newNumber);
3994
4103
  }
3995
4104
  //* Try and extract a valid international dial code from a full telephone number.
3996
4105
  //* Note: returns the raw string inc plus character and any whitespace/dots etc.
3997
4106
  #getDialCode(number, includeAreaCode) {
4107
+ if (!number.startsWith("+")) {
4108
+ return "";
4109
+ }
3998
4110
  let dialCode = "";
3999
- if (number.startsWith("+")) {
4000
- let numericChars = "";
4001
- let foundBaseDialCode = false;
4002
- for (let i = 0; i < number.length; i++) {
4003
- const c = number.charAt(i);
4004
- if (/[0-9]/.test(c)) {
4005
- numericChars += c;
4006
- const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
4007
- if (!hasMapEntry) {
4008
- break;
4009
- }
4010
- if (this.#dialCodes.has(numericChars)) {
4011
- dialCode = number.substring(0, i + 1);
4012
- foundBaseDialCode = true;
4013
- if (!includeAreaCode) {
4014
- break;
4015
- }
4016
- } else if (includeAreaCode && foundBaseDialCode) {
4017
- dialCode = number.substring(0, i + 1);
4018
- }
4019
- if (numericChars.length === this.#dialCodeMaxLen) {
4020
- break;
4021
- }
4111
+ let numericChars = "";
4112
+ let foundBaseDialCode = false;
4113
+ for (let i = 0; i < number.length; i++) {
4114
+ const c = number.charAt(i);
4115
+ if (!/[0-9]/.test(c)) {
4116
+ continue;
4117
+ }
4118
+ numericChars += c;
4119
+ const hasMapEntry = Boolean(this.#dialCodeToIso2Map[numericChars]);
4120
+ if (!hasMapEntry) {
4121
+ break;
4122
+ }
4123
+ if (this.#dialCodes.has(numericChars)) {
4124
+ dialCode = number.substring(0, i + 1);
4125
+ foundBaseDialCode = true;
4126
+ if (!includeAreaCode) {
4127
+ break;
4022
4128
  }
4129
+ } else if (includeAreaCode && foundBaseDialCode) {
4130
+ dialCode = number.substring(0, i + 1);
4131
+ }
4132
+ if (numericChars.length === this.#dialCodeMaxLen) {
4133
+ break;
4023
4134
  }
4024
4135
  }
4025
4136
  return dialCode;
@@ -4067,18 +4178,19 @@ var _factory = (() => {
4067
4178
  //**************************
4068
4179
  //* Called when the geoip call returns.
4069
4180
  #handleAutoCountry() {
4181
+ if (!this.#autoCountryDeferred || !intlTelInput.autoCountry) {
4182
+ return;
4183
+ }
4070
4184
  if (this.#destroyed) {
4071
- this.#autoCountryDeferred?.resolve();
4185
+ this.#autoCountryDeferred.resolve();
4072
4186
  return;
4073
4187
  }
4074
- if (this.#options.initialCountry === INITIAL_COUNTRY.AUTO && intlTelInput.autoCountry) {
4075
- this.#defaultCountry = intlTelInput.autoCountry;
4076
- const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4077
- if (!hasSelectedCountryOrGlobe) {
4078
- this.setCountry(this.#defaultCountry);
4079
- }
4080
- this.#autoCountryDeferred?.resolve();
4188
+ this.#defaultCountry = intlTelInput.autoCountry;
4189
+ const hasSelectedCountryOrGlobe = this.#selectedCountryData || this.#ui.selectedCountryInner.classList.contains(CLASSES.GLOBE);
4190
+ if (!hasSelectedCountryOrGlobe) {
4191
+ this.setCountry(this.#defaultCountry);
4081
4192
  }
4193
+ this.#autoCountryDeferred.resolve();
4082
4194
  }
4083
4195
  //* Called when the geoip call fails or times out.
4084
4196
  #handleAutoCountryFailure() {
@@ -4095,15 +4207,17 @@ var _factory = (() => {
4095
4207
  this.#utilsScriptDeferred?.resolve();
4096
4208
  return;
4097
4209
  }
4098
- if (intlTelInput.utils) {
4099
- const inputValue = this.#getTelInputValue();
4100
- if (inputValue) {
4101
- this.#updateValFromNumber(inputValue);
4102
- }
4103
- if (this.#selectedCountryData) {
4104
- this.#updatePlaceholder();
4105
- this.#updateMaxLength();
4106
- }
4210
+ if (!intlTelInput.utils) {
4211
+ this.#utilsScriptDeferred?.resolve();
4212
+ return;
4213
+ }
4214
+ const inputValue = this.#getTelInputValue();
4215
+ if (inputValue) {
4216
+ this.#updateValFromNumber(inputValue);
4217
+ }
4218
+ if (this.#selectedCountryData) {
4219
+ this.#updatePlaceholder();
4220
+ this.#updateMaxLength();
4107
4221
  }
4108
4222
  this.#utilsScriptDeferred?.resolve();
4109
4223
  }
@@ -4245,7 +4359,9 @@ var _factory = (() => {
4245
4359
  const hasAlphaChar = alphaCharPosition > -1;
4246
4360
  if (hasAlphaChar) {
4247
4361
  const selectedIso2 = this.#selectedCountryData?.iso2;
4248
- const hasExtension = Boolean(intlTelInput.utils.getExtension(val, selectedIso2));
4362
+ const hasExtension = Boolean(
4363
+ intlTelInput.utils.getExtension(val, selectedIso2)
4364
+ );
4249
4365
  if (hasExtension) {
4250
4366
  return allowNumberExtensions;
4251
4367
  }
@@ -4271,15 +4387,16 @@ var _factory = (() => {
4271
4387
  }
4272
4388
  const currentCountry = this.#selectedCountryData?.iso2;
4273
4389
  const isCountryChange = iso2 && iso2Lower !== currentCountry || !iso2 && currentCountry;
4274
- if (isCountryChange) {
4275
- this.#setCountry(iso2Lower);
4276
- this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4277
- if (this.#options.formatOnDisplay) {
4278
- const inputValue = this.#getTelInputValue();
4279
- this.#updateValFromNumber(inputValue);
4280
- }
4281
- this.#triggerCountryChange();
4390
+ if (!isCountryChange) {
4391
+ return;
4392
+ }
4393
+ this.#setCountry(iso2Lower);
4394
+ this.#updateDialCode(this.#selectedCountryData?.dialCode || "");
4395
+ if (this.#options.formatOnDisplay) {
4396
+ const inputValue = this.#getTelInputValue();
4397
+ this.#updateValFromNumber(inputValue);
4282
4398
  }
4399
+ this.#triggerCountryChange();
4283
4400
  }
4284
4401
  //* Set the input value and update the country.
4285
4402
  setNumber(number) {
@@ -4417,7 +4534,7 @@ var _factory = (() => {
4417
4534
  attachUtils,
4418
4535
  startedLoadingUtilsScript: false,
4419
4536
  startedLoadingAutoCountry: false,
4420
- version: "27.0.0"
4537
+ version: "27.0.2"
4421
4538
  }
4422
4539
  );
4423
4540
  var intl_tel_input_default = intlTelInput;