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