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.
@@ -2810,7 +2810,27 @@ var phone_countries_default = [
2810
2810
  // src/core/format.ts
2811
2811
  var TRAILING_SEP = /[\s\-]+$/;
2812
2812
  var FALLBACK_GROUP = /(.{4})(?=.)/g;
2813
- var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9]/g;
2813
+ var NUMERAL_BASES = [
2814
+ 1632,
2815
+ // Arabic-Indic ٠-٩
2816
+ 1776,
2817
+ // Persian ۰-۹
2818
+ 2406,
2819
+ // Devanagari ०-९
2820
+ 2534,
2821
+ // Bengali ০-৯
2822
+ 3664,
2823
+ // Thai ๐-๙
2824
+ 3792,
2825
+ // Lao ໐-໙
2826
+ 4160,
2827
+ // Myanmar ၀-၉
2828
+ 6112,
2829
+ // Khmer ០-៩
2830
+ 65296
2831
+ // Fullwidth 0-9
2832
+ ];
2833
+ var NON_ASCII_DIGITS = /[\u0660-\u0669\u06F0-\u06F9\u0966-\u096F\u09E6-\u09EF\u0E50-\u0E59\u0ED0-\u0ED9\u1040-\u1049\u17E0-\u17E9\uFF10-\uFF19]/g;
2814
2834
  function isRelevantChar(ch) {
2815
2835
  const c = ch.charCodeAt(0);
2816
2836
  return c >= 48 && c <= 57 || c === 43;
@@ -2860,9 +2880,18 @@ function extractDigits(value) {
2860
2880
  function normalizeNumerals(value) {
2861
2881
  return value.replace(NON_ASCII_DIGITS, (c) => {
2862
2882
  const code = c.charCodeAt(0);
2863
- return code <= 1641 ? String(code - 1632) : String(code - 1776);
2883
+ for (const base of NUMERAL_BASES) {
2884
+ if (code >= base && code <= base + 9) {
2885
+ return String(code - base);
2886
+ }
2887
+ }
2888
+ return c;
2864
2889
  });
2865
2890
  }
2891
+ function isNonAsciiDigit(ch) {
2892
+ const code = ch.charCodeAt(0);
2893
+ return NUMERAL_BASES.some((base) => code >= base && code <= base + 9);
2894
+ }
2866
2895
 
2867
2896
  // src/core/countries.ts
2868
2897
  function getFlag(code) {
@@ -3500,7 +3529,7 @@ var PhoneInput = class _PhoneInput {
3500
3529
  const formatted = this.formatNationalValue(digits);
3501
3530
  const np = this.shouldPrependPrefix ? this.selectedCountry.nationalPrefix : "";
3502
3531
  const display = !digits && np && extractDigits(raw).length > 0 ? np : digits && np ? np + formatted : formatted;
3503
- const newCursor = this.getNationalCursor(this.inputEl.value, oldCursor, formatted);
3532
+ const newCursor = this.getNationalCursor(raw, oldCursor, formatted);
3504
3533
  this.inputEl.value = display;
3505
3534
  this.inputEl.setSelectionRange(newCursor, newCursor);
3506
3535
  } else {
@@ -3527,7 +3556,7 @@ var PhoneInput = class _PhoneInput {
3527
3556
  } else {
3528
3557
  formatted = this.formatNationalValue(national);
3529
3558
  }
3530
- const newCursor = getCursorPosition(this.inputEl.value, oldCursor, formatted);
3559
+ const newCursor = getCursorPosition(raw, oldCursor, formatted);
3531
3560
  this.inputEl.value = formatted;
3532
3561
  this.inputEl.setSelectionRange(newCursor, newCursor);
3533
3562
  }
@@ -3542,11 +3571,8 @@ var PhoneInput = class _PhoneInput {
3542
3571
  if (!this.isNationalInput && e.key === "+" && this.inputEl.selectionStart === 0) {
3543
3572
  return;
3544
3573
  }
3545
- if (e.key.length === 1 && !/\d/.test(e.key)) {
3546
- const code = e.key.charCodeAt(0);
3547
- if (!(code >= 1632 && code <= 1641 || code >= 1776 && code <= 1785)) {
3548
- e.preventDefault();
3549
- }
3574
+ if (e.key.length === 1 && !/\d/.test(e.key) && !isNonAsciiDigit(e.key)) {
3575
+ e.preventDefault();
3550
3576
  }
3551
3577
  }
3552
3578
  handlePaste(e) {