lite-phone-input 0.4.0 → 0.5.0

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.
@@ -2831,7 +2831,27 @@ var phone_countries_default = [
2831
2831
  // src/core/format.ts
2832
2832
  var TRAILING_SEP = /[\s\-]+$/;
2833
2833
  var FALLBACK_GROUP = /(.{4})(?=.)/g;
2834
- var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9]/g;
2834
+ var NUMERAL_BASES = [
2835
+ 1632,
2836
+ // Arabic-Indic ٠-٩
2837
+ 1776,
2838
+ // Persian ۰-۹
2839
+ 2406,
2840
+ // Devanagari ०-९
2841
+ 2534,
2842
+ // Bengali ০-৯
2843
+ 3664,
2844
+ // Thai ๐-๙
2845
+ 3792,
2846
+ // Lao ໐-໙
2847
+ 4160,
2848
+ // Myanmar ၀-၉
2849
+ 6112,
2850
+ // Khmer ០-៩
2851
+ 65296
2852
+ // Fullwidth 0-9
2853
+ ];
2854
+ var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9\u0966-\u096F\u09E6-\u09EF\u0E50-\u0E59\u0ED0-\u0ED9\u1040-\u1049\u17E0-\u17E9\uFF10-\uFF19]/g;
2835
2855
  function isRelevantChar(ch) {
2836
2856
  const c = ch.charCodeAt(0);
2837
2857
  return c >= 48 && c <= 57 || c === 43;
@@ -2881,9 +2901,18 @@ function extractDigits(value) {
2881
2901
  function normalizeNumerals(value) {
2882
2902
  return value.replace(NON_ASCII_DIGITS, (c) => {
2883
2903
  const code = c.charCodeAt(0);
2884
- return code <= 1641 ? String(code - 1632) : String(code - 1776);
2904
+ for (const base of NUMERAL_BASES) {
2905
+ if (code >= base && code <= base + 9) {
2906
+ return String(code - base);
2907
+ }
2908
+ }
2909
+ return c;
2885
2910
  });
2886
2911
  }
2912
+ function isNonAsciiDigit(ch) {
2913
+ const code = ch.charCodeAt(0);
2914
+ return NUMERAL_BASES.some((base) => code >= base && code <= base + 9);
2915
+ }
2887
2916
 
2888
2917
  // src/core/countries.ts
2889
2918
  function getFlag(code) {
@@ -3521,7 +3550,7 @@ var PhoneInput = class _PhoneInput {
3521
3550
  const formatted = this.formatNationalValue(digits);
3522
3551
  const np = this.shouldPrependPrefix ? this.selectedCountry.nationalPrefix : "";
3523
3552
  const display = !digits && np && extractDigits(raw).length > 0 ? np : digits && np ? np + formatted : formatted;
3524
- const newCursor = this.getNationalCursor(this.inputEl.value, oldCursor, formatted);
3553
+ const newCursor = this.getNationalCursor(raw, oldCursor, formatted);
3525
3554
  this.inputEl.value = display;
3526
3555
  this.inputEl.setSelectionRange(newCursor, newCursor);
3527
3556
  } else {
@@ -3548,7 +3577,7 @@ var PhoneInput = class _PhoneInput {
3548
3577
  } else {
3549
3578
  formatted = this.formatNationalValue(national);
3550
3579
  }
3551
- const newCursor = getCursorPosition(this.inputEl.value, oldCursor, formatted);
3580
+ const newCursor = getCursorPosition(raw, oldCursor, formatted);
3552
3581
  this.inputEl.value = formatted;
3553
3582
  this.inputEl.setSelectionRange(newCursor, newCursor);
3554
3583
  }
@@ -3563,11 +3592,8 @@ var PhoneInput = class _PhoneInput {
3563
3592
  if (!this.isNationalInput && e.key === "+" && this.inputEl.selectionStart === 0) {
3564
3593
  return;
3565
3594
  }
3566
- if (e.key.length === 1 && !/\d/.test(e.key)) {
3567
- const code = e.key.charCodeAt(0);
3568
- if (!(code >= 1632 && code <= 1641 || code >= 1776 && code <= 1785)) {
3569
- e.preventDefault();
3570
- }
3595
+ if (e.key.length === 1 && !/\d/.test(e.key) && !isNonAsciiDigit(e.key)) {
3596
+ e.preventDefault();
3571
3597
  }
3572
3598
  }
3573
3599
  handlePaste(e) {