intl-tel-input 25.12.6 → 25.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v25.12.6
2
+ * International Telephone Input v25.13.1
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -2747,11 +2747,11 @@ var factoryOutput = (() => {
2747
2747
  }
2748
2748
  }
2749
2749
  };
2750
- var processDialCodes = (countries, options) => {
2750
+ var processDialCodes = (countries) => {
2751
2751
  const dialCodes = /* @__PURE__ */ new Set();
2752
2752
  let dialCodeMaxLen = 0;
2753
2753
  const dialCodeToIso2Map = {};
2754
- const _addToDialCodeMap = (iso2, dialCode, priority) => {
2754
+ const _addToDialCodeMap = (iso2, dialCode) => {
2755
2755
  if (!iso2 || !dialCode) {
2756
2756
  return;
2757
2757
  }
@@ -2765,10 +2765,10 @@ var factoryOutput = (() => {
2765
2765
  if (iso2List.includes(iso2)) {
2766
2766
  return;
2767
2767
  }
2768
- const index = priority !== void 0 ? priority : iso2List.length;
2769
- iso2List[index] = iso2;
2768
+ iso2List.push(iso2);
2770
2769
  };
2771
- for (const c of countries) {
2770
+ const countriesSortedByPriority = [...countries].sort((a, b) => a.priority - b.priority);
2771
+ for (const c of countriesSortedByPriority) {
2772
2772
  if (!dialCodes.has(c.dialCode)) {
2773
2773
  dialCodes.add(c.dialCode);
2774
2774
  }
@@ -2776,14 +2776,7 @@ var factoryOutput = (() => {
2776
2776
  const partialDialCode = c.dialCode.substring(0, k);
2777
2777
  _addToDialCodeMap(c.iso2, partialDialCode);
2778
2778
  }
2779
- _addToDialCodeMap(c.iso2, c.dialCode, c.priority);
2780
- }
2781
- if (options.onlyCountries.length || options.excludeCountries.length) {
2782
- dialCodes.forEach((dialCode) => {
2783
- dialCodeToIso2Map[dialCode] = dialCodeToIso2Map[dialCode].filter(Boolean);
2784
- });
2785
- }
2786
- for (const c of countries) {
2779
+ _addToDialCodeMap(c.iso2, c.dialCode);
2787
2780
  if (c.areaCodes) {
2788
2781
  const rootIso2Code = dialCodeToIso2Map[c.dialCode][0];
2789
2782
  for (const areaCode of c.areaCodes) {
@@ -2918,8 +2911,7 @@ var factoryOutput = (() => {
2918
2911
  this.promise = this._createInitPromises();
2919
2912
  this.countries = processAllCountries(this.options);
2920
2913
  const { dialCodes, dialCodeMaxLen, dialCodeToIso2Map } = processDialCodes(
2921
- this.countries,
2922
- this.options
2914
+ this.countries
2923
2915
  );
2924
2916
  this.dialCodes = dialCodes;
2925
2917
  this.dialCodeMaxLen = dialCodeMaxLen;
@@ -2930,6 +2922,45 @@ var factoryOutput = (() => {
2930
2922
  static _getIsAndroid() {
2931
2923
  return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
2932
2924
  }
2925
+ _updateNumeralSet(str) {
2926
+ if (/[\u0660-\u0669]/.test(str)) {
2927
+ this.userNumeralSet = "arabic-indic";
2928
+ } else if (/[\u06F0-\u06F9]/.test(str)) {
2929
+ this.userNumeralSet = "persian";
2930
+ } else {
2931
+ this.userNumeralSet = "ascii";
2932
+ }
2933
+ }
2934
+ _mapAsciiToUserNumerals(str) {
2935
+ if (!this.userNumeralSet) {
2936
+ this._updateNumeralSet(this.ui.telInput.value);
2937
+ }
2938
+ if (this.userNumeralSet === "ascii") {
2939
+ return str;
2940
+ }
2941
+ const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
2942
+ return str.replace(/[0-9]/g, (d) => String.fromCharCode(base + Number(d)));
2943
+ }
2944
+ // Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
2945
+ _normaliseNumerals(str) {
2946
+ if (!str) {
2947
+ return "";
2948
+ }
2949
+ this._updateNumeralSet(str);
2950
+ if (this.userNumeralSet === "ascii") {
2951
+ return str;
2952
+ }
2953
+ const base = this.userNumeralSet === "arabic-indic" ? 1632 : 1776;
2954
+ const regex = this.userNumeralSet === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
2955
+ return str.replace(regex, (ch) => String.fromCharCode(48 + (ch.charCodeAt(0) - base)));
2956
+ }
2957
+ _getTelInputValue() {
2958
+ const inputValue = this.ui.telInput.value.trim();
2959
+ return this._normaliseNumerals(inputValue);
2960
+ }
2961
+ _setTelInputValue(asciiValue) {
2962
+ this.ui.telInput.value = this._mapAsciiToUserNumerals(asciiValue);
2963
+ }
2933
2964
  _createInitPromises() {
2934
2965
  const autoCountryPromise = new Promise((resolve, reject) => {
2935
2966
  this.resolveAutoCountryPromise = resolve;
@@ -2964,8 +2995,9 @@ var factoryOutput = (() => {
2964
2995
  //* 1. Extracting a dial code from the given number
2965
2996
  //* 2. Using explicit initialCountry
2966
2997
  _setInitialState(overrideAutoCountry = false) {
2967
- const attributeValue = this.ui.telInput.getAttribute("value");
2968
- const inputValue = this.ui.telInput.value;
2998
+ const attributeValueRaw = this.ui.telInput.getAttribute("value");
2999
+ const attributeValue = this._normaliseNumerals(attributeValueRaw);
3000
+ const inputValue = this._getTelInputValue();
2969
3001
  const useAttribute = attributeValue && attributeValue.startsWith("+") && (!inputValue || !inputValue.startsWith("+"));
2970
3002
  const val = useAttribute ? attributeValue : inputValue;
2971
3003
  const dialCode = this._getDialCode(val);
@@ -3136,35 +3168,34 @@ var factoryOutput = (() => {
3136
3168
  countrySearch
3137
3169
  } = this.options;
3138
3170
  let userOverrideFormatting = false;
3139
- if (REGEX.ALPHA_UNICODE.test(this.ui.telInput.value)) {
3171
+ if (REGEX.ALPHA_UNICODE.test(this._getTelInputValue())) {
3140
3172
  userOverrideFormatting = true;
3141
3173
  }
3142
3174
  const handleInputEvent = (e) => {
3175
+ const inputValue = this._getTelInputValue();
3143
3176
  if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
3144
3177
  const currentCaretPos = this.ui.telInput.selectionStart || 0;
3145
- const valueBeforeCaret = this.ui.telInput.value.substring(
3146
- 0,
3147
- currentCaretPos - 1
3148
- );
3149
- const valueAfterCaret = this.ui.telInput.value.substring(currentCaretPos);
3150
- this.ui.telInput.value = valueBeforeCaret + valueAfterCaret;
3178
+ const valueBeforeCaret = inputValue.substring(0, currentCaretPos - 1);
3179
+ const valueAfterCaret = inputValue.substring(currentCaretPos);
3180
+ this._setTelInputValue(valueBeforeCaret + valueAfterCaret);
3151
3181
  this._openDropdownWithPlus();
3152
3182
  return;
3153
3183
  }
3154
- if (this._updateCountryFromNumber(this.ui.telInput.value)) {
3184
+ if (this._updateCountryFromNumber(inputValue)) {
3155
3185
  this._triggerCountryChange();
3156
3186
  }
3157
3187
  const isFormattingChar = e?.data && REGEX.NON_PLUS_NUMERIC.test(e.data);
3158
- const isPaste = e?.inputType === INPUT_TYPES.PASTE && this.ui.telInput.value;
3188
+ const isPaste = e?.inputType === INPUT_TYPES.PASTE && inputValue;
3159
3189
  if (isFormattingChar || isPaste && !strictMode) {
3160
3190
  userOverrideFormatting = true;
3161
- } else if (!REGEX.NON_PLUS_NUMERIC.test(this.ui.telInput.value)) {
3191
+ } else if (!REGEX.NON_PLUS_NUMERIC.test(inputValue)) {
3162
3192
  userOverrideFormatting = false;
3163
3193
  }
3164
3194
  const isSetNumber = e?.detail && e.detail["isSetNumber"];
3165
- if (formatAsYouType && !userOverrideFormatting && !isSetNumber) {
3195
+ const isAscii = this.userNumeralSet === "ascii";
3196
+ if (formatAsYouType && !userOverrideFormatting && !isSetNumber && isAscii) {
3166
3197
  const currentCaretPos = this.ui.telInput.selectionStart || 0;
3167
- const valueBeforeCaret = this.ui.telInput.value.substring(
3198
+ const valueBeforeCaret = inputValue.substring(
3168
3199
  0,
3169
3200
  currentCaretPos
3170
3201
  );
@@ -3176,7 +3207,7 @@ var factoryOutput = (() => {
3176
3207
  const fullNumber = this._getFullNumber();
3177
3208
  const formattedValue = formatNumberAsYouType(
3178
3209
  fullNumber,
3179
- this.ui.telInput.value,
3210
+ inputValue,
3180
3211
  intlTelInput.utils,
3181
3212
  this.selectedCountryData,
3182
3213
  this.options.separateDialCode
@@ -3187,7 +3218,7 @@ var factoryOutput = (() => {
3187
3218
  currentCaretPos,
3188
3219
  isDeleteForwards
3189
3220
  );
3190
- this.ui.telInput.value = formattedValue;
3221
+ this._setTelInputValue(formattedValue);
3191
3222
  this.ui.telInput.setSelectionRange(newCaretPos, newCaretPos);
3192
3223
  }
3193
3224
  };
@@ -3210,12 +3241,18 @@ var factoryOutput = (() => {
3210
3241
  return;
3211
3242
  }
3212
3243
  if (strictMode) {
3213
- const value = this.ui.telInput.value;
3214
- const alreadyHasPlus = value.startsWith("+");
3244
+ const inputValue = this._getTelInputValue();
3245
+ const alreadyHasPlus = inputValue.startsWith("+");
3215
3246
  const isInitialPlus = !alreadyHasPlus && this.ui.telInput.selectionStart === 0 && e.key === "+";
3216
- const isNumeric = /^[0-9]$/.test(e.key);
3247
+ const normalisedKey = this._normaliseNumerals(e.key);
3248
+ const isNumeric = /^[0-9]$/.test(normalisedKey);
3217
3249
  const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
3218
- const newValue = value.slice(0, this.ui.telInput.selectionStart) + e.key + value.slice(this.ui.telInput.selectionEnd);
3250
+ const input = this.ui.telInput;
3251
+ const selStart = input.selectionStart;
3252
+ const selEnd = input.selectionEnd;
3253
+ const before = inputValue.slice(0, selStart);
3254
+ const after = inputValue.slice(selEnd);
3255
+ const newValue = before + e.key + after;
3219
3256
  const newFullNumber = this._getFullNumber(newValue);
3220
3257
  const coreNumber = intlTelInput.utils.getCoreNumber(
3221
3258
  newFullNumber,
@@ -3242,34 +3279,38 @@ var factoryOutput = (() => {
3242
3279
  const input = this.ui.telInput;
3243
3280
  const selStart = input.selectionStart;
3244
3281
  const selEnd = input.selectionEnd;
3245
- const before = input.value.slice(0, selStart);
3246
- const after = input.value.slice(selEnd);
3282
+ const inputValue = this._getTelInputValue();
3283
+ const before = inputValue.slice(0, selStart);
3284
+ const after = inputValue.slice(selEnd);
3247
3285
  const iso2 = this.selectedCountryData.iso2;
3248
- const pasted = e.clipboardData.getData("text");
3286
+ const pastedRaw = e.clipboardData.getData("text");
3287
+ const pasted = this._normaliseNumerals(pastedRaw);
3249
3288
  const initialCharSelected = selStart === 0 && selEnd > 0;
3250
- const allowLeadingPlus = !input.value.startsWith("+") || initialCharSelected;
3289
+ const allowLeadingPlus = !inputValue.startsWith("+") || initialCharSelected;
3251
3290
  const allowedChars = pasted.replace(REGEX.NON_PLUS_NUMERIC_GLOBAL, "");
3252
3291
  const hasLeadingPlus = allowedChars.startsWith("+");
3253
3292
  const numerics = allowedChars.replace(/\+/g, "");
3254
3293
  const sanitised = hasLeadingPlus && allowLeadingPlus ? `+${numerics}` : numerics;
3255
3294
  let newVal = before + sanitised + after;
3256
- let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3257
- while (coreNumber.length === 0 && newVal.length > 0) {
3258
- newVal = newVal.slice(0, -1);
3259
- coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3260
- }
3261
- if (!coreNumber) {
3262
- return;
3263
- }
3264
- if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
3265
- if (input.selectionEnd === input.value.length) {
3266
- const trimLength = coreNumber.length - this.maxCoreNumberLength;
3267
- newVal = newVal.slice(0, newVal.length - trimLength);
3268
- } else {
3295
+ if (newVal.length > 5) {
3296
+ let coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3297
+ while (coreNumber.length === 0 && newVal.length > 0) {
3298
+ newVal = newVal.slice(0, -1);
3299
+ coreNumber = intlTelInput.utils.getCoreNumber(newVal, iso2);
3300
+ }
3301
+ if (!coreNumber) {
3269
3302
  return;
3270
3303
  }
3304
+ if (this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength) {
3305
+ if (input.selectionEnd === inputValue.length) {
3306
+ const trimLength = coreNumber.length - this.maxCoreNumberLength;
3307
+ newVal = newVal.slice(0, newVal.length - trimLength);
3308
+ } else {
3309
+ return;
3310
+ }
3311
+ }
3271
3312
  }
3272
- input.value = newVal;
3313
+ this._setTelInputValue(newVal);
3273
3314
  const caretPos = selStart + sanitised.length;
3274
3315
  input.setSelectionRange(caretPos, caretPos);
3275
3316
  input.dispatchEvent(new InputEvent("input", { bubbles: true }));
@@ -3521,7 +3562,7 @@ var factoryOutput = (() => {
3521
3562
  );
3522
3563
  }
3523
3564
  number = this._beforeSetNumber(number);
3524
- this.ui.telInput.value = number;
3565
+ this._setTelInputValue(number);
3525
3566
  }
3526
3567
  //* Check if need to select a new country based on the given number
3527
3568
  //* Note: called from _setInitialState, keyup handler, setNumber.
@@ -3695,7 +3736,8 @@ var factoryOutput = (() => {
3695
3736
  const dialCode = listItem.dataset[DATA_KEYS.DIAL_CODE];
3696
3737
  this._updateDialCode(dialCode);
3697
3738
  if (this.options.formatOnDisplay) {
3698
- this._updateValFromNumber(this.ui.telInput.value);
3739
+ const inputValue = this._getTelInputValue();
3740
+ this._updateValFromNumber(inputValue);
3699
3741
  }
3700
3742
  this.ui.telInput.focus();
3701
3743
  if (countryChanged) {
@@ -3726,7 +3768,7 @@ var factoryOutput = (() => {
3726
3768
  //* Replace any existing dial code with the new one
3727
3769
  //* Note: called from _selectListItem and setCountry
3728
3770
  _updateDialCode(newDialCodeBare) {
3729
- const inputVal = this.ui.telInput.value;
3771
+ const inputVal = this._getTelInputValue();
3730
3772
  const newDialCode = `+${newDialCodeBare}`;
3731
3773
  let newNumber;
3732
3774
  if (inputVal.startsWith("+")) {
@@ -3736,7 +3778,7 @@ var factoryOutput = (() => {
3736
3778
  } else {
3737
3779
  newNumber = newDialCode;
3738
3780
  }
3739
- this.ui.telInput.value = newNumber;
3781
+ this._setTelInputValue(newNumber);
3740
3782
  }
3741
3783
  }
3742
3784
  //* Try and extract a valid international dial code from a full telephone number.
@@ -3773,7 +3815,7 @@ var factoryOutput = (() => {
3773
3815
  }
3774
3816
  //* Get the input val, adding the dial code if separateDialCode is enabled.
3775
3817
  _getFullNumber(overrideVal) {
3776
- const val = overrideVal || this.ui.telInput.value.trim();
3818
+ const val = overrideVal ? this._normaliseNumerals(overrideVal) : this._getTelInputValue();
3777
3819
  const { dialCode } = this.selectedCountryData;
3778
3820
  let prefix;
3779
3821
  const numericVal = getNumeric(val);
@@ -3816,8 +3858,9 @@ var factoryOutput = (() => {
3816
3858
  //* This is called when the utils request completes.
3817
3859
  handleUtils() {
3818
3860
  if (intlTelInput.utils) {
3819
- if (this.ui.telInput.value) {
3820
- this._updateValFromNumber(this.ui.telInput.value);
3861
+ const inputValue = this._getTelInputValue();
3862
+ if (inputValue) {
3863
+ this._updateValFromNumber(inputValue);
3821
3864
  }
3822
3865
  if (this.selectedCountryData.iso2) {
3823
3866
  this._updatePlaceholder();
@@ -3860,11 +3903,13 @@ var factoryOutput = (() => {
3860
3903
  getNumber(format) {
3861
3904
  if (intlTelInput.utils) {
3862
3905
  const { iso2 } = this.selectedCountryData;
3863
- return intlTelInput.utils.formatNumber(
3864
- this._getFullNumber(),
3906
+ const fullNumber = this._getFullNumber();
3907
+ const formattedNumber = intlTelInput.utils.formatNumber(
3908
+ fullNumber,
3865
3909
  iso2,
3866
3910
  format
3867
3911
  );
3912
+ return this._mapAsciiToUserNumerals(formattedNumber);
3868
3913
  }
3869
3914
  return "";
3870
3915
  }
@@ -3952,15 +3997,17 @@ var factoryOutput = (() => {
3952
3997
  this._setCountry(iso2Lower);
3953
3998
  this._updateDialCode(this.selectedCountryData.dialCode);
3954
3999
  if (this.options.formatOnDisplay) {
3955
- this._updateValFromNumber(this.ui.telInput.value);
4000
+ const inputValue = this._getTelInputValue();
4001
+ this._updateValFromNumber(inputValue);
3956
4002
  }
3957
4003
  this._triggerCountryChange();
3958
4004
  }
3959
4005
  }
3960
4006
  //* Set the input value and update the country.
3961
4007
  setNumber(number) {
3962
- const countryChanged = this._updateCountryFromNumber(number);
3963
- this._updateValFromNumber(number);
4008
+ const normalisedNumber = this._normaliseNumerals(number);
4009
+ const countryChanged = this._updateCountryFromNumber(normalisedNumber);
4010
+ this._updateValFromNumber(normalisedNumber);
3964
4011
  if (countryChanged) {
3965
4012
  this._triggerCountryChange();
3966
4013
  }
@@ -4045,7 +4092,7 @@ var factoryOutput = (() => {
4045
4092
  attachUtils,
4046
4093
  startedLoadingUtilsScript: false,
4047
4094
  startedLoadingAutoCountry: false,
4048
- version: "25.12.6"
4095
+ version: "25.13.1"
4049
4096
  }
4050
4097
  );
4051
4098
  var intl_tel_input_default = intlTelInput;