@desource/phone-mask-vue 1.0.0 → 1.1.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.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { computed, toValue, ref, watchEffect, onUnmounted, nextTick, shallowRef, watch, onBeforeUnmount, onBeforeMount, defineComponent, useSlots, useModel, useTemplateRef, openBlock, createElementBlock, normalizeStyle, normalizeClass, createElementVNode, unref, renderSlot, createTextVNode, toDisplayString, createCommentVNode, createVNode, Transition, withCtx, createBlock, Teleport, Fragment, renderList, mergeModels, onMounted } from "vue";
1
+ import { computed, toValue, ref, watchEffect, onUnmounted, nextTick, shallowRef, watch, onBeforeUnmount, onBeforeMount, defineComponent, useSlots, useModel, useTemplateRef, getCurrentInstance, openBlock, createElementBlock, normalizeStyle, normalizeClass, createElementVNode, unref, renderSlot, createTextVNode, toDisplayString, createCommentVNode, createVNode, Transition, withCtx, createBlock, Teleport, Fragment, renderList, mergeModels, onMounted } from "vue";
2
2
  const M = { AC: "+247 #####", AD: ["+376 ### ###", "+376 #### ####"], AE: ["+971 # ### ####", "+971 ## ### ####", "+971 ### ######", "+971 ### # #####"], AF: "+93 ## ### ####", AG: "+1 ###-###-####", AI: "+1 ###-###-####", AL: ["+355 ## ### ###", "+355 ## ### ####", "+355 ### ####", "+355 ### ###", "+355 ### #####"], AM: ["+374 ## ######", "+374 ### ## ###"], AO: "+244 ### ### ###", AR: ["+54 ## ####-####", "+54 # ## ####-####", "+54 ###-###-####"], AS: "+1 ###-###-####", AT: ["+43 # #########", "+43 ### ######"], AU: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###", "+61 ## ### ##"], AW: "+297 ### ####", AX: ["+358 ## #######", "+358 ### ######"], AZ: ["+994 ## ### ## ##", "+994 ### ## ## ##"], BA: ["+387 ## ###-###", "+387 ## ### ###"], BB: "+1 ###-###-####", BD: ["+880 #-#######", "+880 ####-######", "+880 ###-#######"], BE: ["+32 ## ## ## ##", "+32 ### ## ## ##", "+32 ### ## ###"], BF: "+226 ## ## ## ##", BG: ["+359 # ### ###", "+359 ## ### ###", "+359 ### ## ###"], BH: "+973 #### ####", BI: "+257 ## ## ## ##", BJ: ["+229 ## ## ## ## ##", "+229 ## ## ## ##"], BL: "+590 ### ## ## ##", BM: "+1 ###-###-####", BN: "+673 ### ####", BO: ["+591 # #######", "+591 ########", "+591 ### ## ####"], BQ: "+599 ### ####", BR: ["+55 ## ####-####", "+55 ## #####-####", "+55 ### ## ####", "+55 ####-####"], BS: "+1 ###-###-####", BT: ["+975 # ### ###", "+975 ## ## ## ##"], BW: ["+267 ### ####", "+267 ## ### ###", "+267 #### ### ###", "+267 ## #####"], BY: ["+375 ### ##-##-##", "+375 ## ###-##-##", "+375 ### ### ####"], BZ: ["+501 ###-####", "+501 #-###-####-###"], CA: "+1 ###-###-####", CC: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CD: ["+243 ## #####", "+243 ### ### ###"], CF: "+236 ## ## ## ##", CG: ["+242 ## ### ####", "+242 # #### ####"], CH: ["+41 ## ### ## ##", "+41 ### ### ###"], CI: ["+225 ## ## # #####", "+225 ## ## ## ####"], CK: "+682 ## ###", CL: ["+56 ### ### ###", "+56 # #### ####", "+56 ### ### ####", "+56 ## ### ####"], CM: ["+237 # ## ## ## ##", "+237 ## ## ## ##"], CN: ["+86 ## #### ####", "+86 ### #### ####", "+86 ### ### ####", "+86 ########"], CO: ["+57 ### #######", "+57 # ### #######"], CR: ["+506 #### ####", "+506 ###-###-####"], CU: ["+53 # #######", "+53 ### #######"], CV: "+238 ### ## ##", CW: ["+599 # ### ####", "+599 ### ####"], CX: ["+61 # #### ####", "+61 ### ### ###", "+61 #### ### ###"], CY: "+357 ## ######", CZ: "+420 ### ### ###", DE: ["+49 ## ######", "+49 #### #######", "+49 ### ##########", "+49 ### # ######", "+49 ### # ####", "+49 ### #### ####", "+49 ########"], DJ: "+253 ## ## ## ##", DK: "+45 ## ## ## ##", DM: "+1 ###-###-####", DO: "+1 ###-###-####", DZ: ["+213 ## ## ## ##", "+213 ### ## ## ##", "+213 ## ### ## ##"], EC: ["+593 #-###-####", "+593 ## ### ####", "+593 #### ### ####"], EE: ["+372 ### ####", "+372 #### ####", "+372 ## ## ####"], EG: ["+20 # ########", "+20 ## ########", "+20 ### ### ####"], EH: ["+212 # ## ## ## ##", "+212 ##-#######"], ER: "+291 # ### ###", ES: ["+34 ### ## ## ##", "+34 ### ### ###"], ET: "+251 ## ### ####", FI: ["+358 ## #######", "+358 ### ######"], FJ: ["+679 ### ####", "+679 #### ### ####"], FK: "+500 #####", FM: "+691 ### ####", FO: "+298 ######", FR: ["+33 # ## ## ## ##", "+33 ### ## ## ##"], GA: "+241 ## ## ## ##", GB: ["+44 ### ### ####", "+44 #### ######", "+44 ## #### ####"], GD: "+1 ###-###-####", GE: ["+995 ## ### ## ##", "+995 ### ## ## ##", "+995 ### ### ###"], GF: "+594 ### ## ## ##", GG: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], GH: ["+233 ## ### ####", "+233 ### #####"], GI: ["+350 ### #####", "+350 ########"], GL: "+299 ## ## ##", GM: "+220 ### ####", GN: ["+224 ## ## ## ##", "+224 ### ## ## ##"], GP: "+590 ### ## ## ##", GQ: ["+240 ### ### ###", "+240 ### ######"], GR: ["+30 ## #### ####", "+30 ### ### ####"], GT: ["+502 #### ####", "+502 #### ### ####"], GU: "+1 ###-###-####", GW: ["+245 ### ### ###", "+245 ### ####"], GY: "+592 ### ####", HK: ["+852 #### ####", "+852 ### ### ###", "+852 ### ## ### ###"], HN: ["+504 ####-####", "+504 ###########"], HR: ["+385 # #### ###", "+385 ## ### ####", "+385 ### ### ###", "+385 ## ## ###", "+385 ## ### ###"], HT: "+509 ## ## ####", HU: ["+36 # ### ####", "+36 ## ### ####", "+36 ## ### ###"], ID: ["+62 ## #######", "+62 ###-###-###", "+62 ### #######", "+62 ### # ### ###", "+62 ### ### ####"], IE: ["+353 ## #####", "+353 ## ### ####", "+353 #### ### ###", "+353 ### ### ###"], IL: ["+972 #-###-####", "+972 ##-###-####", "+972 #-###-###-###"], IM: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], IN: ["+91 ##### #####", "+91 #### ## ####", "+91 #### ### ### ###", "+91 #### ### ####"], IO: "+246 ### ####", IQ: ["+964 # ### ####", "+964 ### ### ####"], IR: ["+98 ## #### ####", "+98 ### ### ####"], IS: "+354 ### ####", IT: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], JE: ["+44 #### ######", "+44 ### ### ####", "+44 ## #### ####"], JM: "+1 ###-###-####", JO: ["+962 # ### ####", "+962 # #### ####", "+962 ### #####", "+962 ## #######"], JP: ["+81 #-####-####", "+81 ##-####-####", "+81 ###-###-###", "+81 ##-###-####"], KE: ["+254 ## #######", "+254 ### ######", "+254 ### ### ###"], KG: ["+996 ### ### ###", "+996 ### ### # ##"], KH: ["+855 ## ### ###", "+855 #### ### ###"], KI: ["+686 #####", "+686 ########"], KM: "+269 ### ## ##", KN: "+1 ###-###-####", KP: ["+850 # ### ####", "+850 ### ### ####"], KR: ["+82 #-###-####", "+82 ##-####-####", "+82 ##-###-####"], KW: ["+965 #### ####", "+965 ### #####", "+965 #### ###"], KY: "+1 ###-###-####", KZ: ["+7 ##### # ## ##", "+7 ### ### ####", "+7 ### ###-##-##"], LA: ["+856 ## ### ###", "+856 ## ## ### ###"], LB: ["+961 # ### ###", "+961 ## ### ###"], LC: "+1 ###-###-####", LI: ["+423 ### ## ##", "+423 ### ### ###"], LK: ["+94 ### ### ###", "+94 ## ### ####"], LR: ["+231 ## ### ###", "+231 ## ### ####"], LS: "+266 #### ####", LT: ["+370 ### #####", "+370 ### ## ###"], LU: ["+352 ## ## ## ##", "+352 ### ### ###", "+352 ### ## ###"], LV: "+371 ## ### ###", LY: "+218 ##-#######", MA: ["+212 # ## ## ## ##", "+212 ##-#######"], MC: ["+377 ## ## ## ##", "+377 # ## ## ## ##"], MD: ["+373 ## ### ###", "+373 ### ## ###", "+373 ### #####"], ME: "+382 ## ### ###", MF: "+590 ### ## ## ##", MG: "+261 ## ## ### ##", MH: "+692 ###-####", MK: ["+389 # ### ####", "+389 ## ### ###", "+389 ### # ## ##"], ML: "+223 ## ## ## ##", MM: ["+95 # ### ###", "+95 # ### ####", "+95 ### ### ####"], MN: "+976 #### ####", MO: ["+853 #### ####", "+853 #### ###"], MP: "+1 ###-###-####", MQ: "+596 ### ## ## ##", MR: "+222 ## ## ## ##", MS: "+1 ###-###-####", MT: "+356 #### ####", MU: ["+230 #### ####", "+230 ### ####"], MV: ["+960 ###-####", "+960 ### ### ####"], MW: ["+265 # ### ###", "+265 ### ## ## ##"], MX: "+52 ### ### ####", MY: ["+60 #-#### ####", "+60 ##-### ####", "+60 #-###-##-####", "+60 ###-### ####"], MZ: ["+258 ## ### ###", "+258 ## ### ####", "+258 ### ### ###"], NA: ["+264 ## ### ###", "+264 ## ### ####", "+264 ### ### ###"], NC: "+687 ##.##.##", NE: ["+227 ## ## ## ##", "+227 ## ### ###"], NF: ["+672 ## ####", "+672 # #####"], NG: ["+234 #### ## ####", "+234 ### ### ####", "+234 ### #### ####"], NI: "+505 #### ####", NL: ["+31 ## ### ####", "+31 # ########", "+31 ### ####", "+31 ## #######"], NO: ["+47 ## ## ## ##", "+47 ### ## ###"], NP: ["+977 #-#######", "+977 ###-#######", "+977 ###########"], NR: "+674 ### ####", NU: ["+683 ####", "+683 ### ####"], NZ: ["+64 # ### ####", "+64 ## ### ####", "+64 ### ### ###"], OM: ["+968 ## ######", "+968 #### ####", "+968 ### #####"], PA: ["+507 ###-####", "+507 ####-####"], PE: ["+51 # #######", "+51 ### ### ###", "+51 ### #####"], PF: ["+689 ## ## ## ##", "+689 ### ## ## ##"], PG: ["+675 ### ####", "+675 #### ####"], PH: ["+63 # #### ####", "+63 ### ### ####", "+63 #### # ### ####"], PK: ["+92 ## ########", "+92 ### #######", "+92 ### ### ##", "+92 #### #####"], PL: ["+48 ## ### ## ##", "+48 ### ### ###"], PM: ["+508 ## ## ##", "+508 ### ## ## ##"], PR: "+1 ###-###-####", PS: ["+970 # ### ####", "+970 ### ### ###", "+970 #### ### ###"], PT: ["+351 ## ### ####", "+351 ### ### ###"], PW: "+680 ### ####", PY: ["+595 ## ### ####", "+595 ### ######", "+595 #### ### ####"], QA: ["+974 #### ####", "+974 ### ####"], RE: "+262 ### ## ## ##", RO: ["+40 ## ### ####", "+40 ### ### ###"], RS: ["+381 ## ######", "+381 ## #######", "+381 ### #####"], RU: "+7 ### ###-##-##", RW: "+250 ### ### ###", SA: ["+966 ## ### ####", "+966 ### ### ####", "+966 #### #####"], SB: ["+677 #####", "+677 ## #####"], SC: ["+248 # ### ###", "+248 #######"], SD: "+249 ## ### ####", SE: ["+46 # ## ## ##", "+46 ## ### ## ##", "+46 ## ## ## ##", "+46 ### ## ## ###"], SG: ["+65 #### ####", "+65 #### ### ####"], SH: "+290 #####", SI: ["+386 # ### ## ##", "+386 ## ### ###", "+386 ## ######", "+386 ### #####"], SJ: ["+47 ## ## ## ##", "+47 ### ## ###"], SK: ["+421 #/### ### ##", "+421 ### ### ###", "+421 #######"], SL: "+232 ## ######", SM: ["+378 #### ######", "+378 ## ## ## ##"], SN: ["+221 ## ### ## ##", "+221 ### ## ## ##"], SO: ["+252 # ######", "+252 # #######"], SR: ["+597 ###-###", "+597 ###-####", "+597 ##-##-##"], SS: "+211 ### ### ###", ST: "+239 ### ####", SV: ["+503 #### ####", "+503 ### ####"], SX: "+1 ###-###-####", SY: ["+963 ## ### ####", "+963 ### ### ###"], SZ: ["+268 #### ####", "+268 ##### ####"], TA: "+290 ####", TC: "+1 ###-###-####", TD: "+235 ## ## ## ##", TG: "+228 ## ## ## ##", TH: ["+66 # ### ####", "+66 ## ### ####", "+66 #### ### ###"], TJ: ["+992 ### ## ####", "+992 ## ### ####"], TK: "+690 ####", TL: ["+670 ### ####", "+670 #### ####"], TM: ["+993 ## ##-##-##", "+993 ## ######"], TN: "+216 ## ### ###", TO: ["+676 ##-###", "+676 ### ####", "+676 #### ###"], TR: ["+90 ### ### ## ##", "+90 ### ### ####"], TT: "+1 ###-###-####", TV: ["+688 ## ###", "+688 ## ####"], TW: ["+886 # #### ####", "+886 ### ### ###", "+886 ## ### ####", "+886 ## #### ####"], TZ: ["+255 ## ### ####", "+255 ### ### ###", "+255 ### ## ####"], UA: ["+380 #### #####", "+380 ## ### ####", "+380 ### ### ###"], UG: ["+256 ## #######", "+256 ### ######"], US: "+1 ###-###-####", UY: ["+598 #### ####", "+598 ## ### ###", "+598 ### ####"], UZ: "+998 ## ### ## ##", VA: ["+39 ## #### ####", "+39 ### ### ####", "+39 ### ### ###"], VC: "+1 ###-###-####", VE: "+58 ###-#######", VG: "+1 ###-###-####", VI: "+1 ###-###-####", VN: ["+84 ### #### ###", "+84 ### ### ###", "+84 #### ######", "+84 ## ### ## ##"], VU: ["+678 #####", "+678 ### ####"], WF: ["+681 ## ## ##", "+681 ### ## ## ##"], WS: ["+685 #####", "+685 ## #####", "+685 ### ###"], XK: ["+383 ## ### ###", "+383 ### #####"], YE: ["+967 # ### ###", "+967 ### ### ###"], YT: "+262 ### ## ## ##", ZA: ["+27 ## ### ####", "+27 ### ### ###"], ZM: ["+260 ### ### ###", "+260 ## #######", "+260 #########"], ZW: ["+263 ## #####", "+263 ## ### ####", "+263 ### ####", "+263 #### ######"] };
3
3
  const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (o2) => {
4
4
  if (!t$1.test(o2)) {
@@ -8,17 +8,17 @@ const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (o2) => {
8
8
  const e2 = [...o2.toUpperCase()].map((t2) => (t2.codePointAt(0) ?? 0) + 127397);
9
9
  return String.fromCodePoint(...e2);
10
10
  };
11
- const o$1 = "en", n = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
12
- const t2 = e2.toLowerCase(), s2 = n.get(t2);
11
+ const o$1 = "en", n$1 = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
12
+ const t2 = e2.toLowerCase(), s2 = n$1.get(t2);
13
13
  if (s2) return s2;
14
14
  const r = new Intl.DisplayNames([e2], { type: "region" });
15
- if (n.size >= 10) {
16
- for (const e3 of n.keys()) if (e3 !== o$1) {
17
- n.delete(e3);
15
+ if (n$1.size >= 10) {
16
+ for (const e3 of n$1.keys()) if (e3 !== o$1) {
17
+ n$1.delete(e3);
18
18
  break;
19
19
  }
20
20
  }
21
- return n.set(t2, r), r;
21
+ return n$1.set(t2, r), r;
22
22
  }, s$1 = Object.entries(M), divideMask = (e2) => e2.split(/ (.*)/s);
23
23
  function getCodeAndMask(e2) {
24
24
  let t2 = "", o2 = "";
@@ -68,32 +68,32 @@ const MasksFullMap = (e2) => {
68
68
  MasksFull(o$1);
69
69
  const k = countryCodeEmoji;
70
70
  function getNavigatorLang() {
71
- return "undefined" != typeof navigator && navigator.language || "en";
71
+ return globalThis.navigator?.language || "en";
72
72
  }
73
73
  function detectCountryFromLocale() {
74
74
  try {
75
75
  const t2 = getNavigatorLang();
76
76
  try {
77
- const e3 = new Intl.Locale(t2);
78
- if (e3.region) return e3.region.toUpperCase();
77
+ const r2 = new Intl.Locale(t2);
78
+ if (r2.region) return r2.region.toUpperCase();
79
79
  } catch {
80
80
  }
81
- const e2 = t2.split(/[-_]/);
82
- if (e2.length > 1) return e2[1]?.toUpperCase() || null;
81
+ const r = t2.split(/[-_]/);
82
+ if (r.length > 1) return r[1]?.toUpperCase() || null;
83
83
  } catch {
84
84
  }
85
85
  return null;
86
86
  }
87
87
  function hasCountry(t2) {
88
- const r = f;
89
- return t2.toUpperCase() in r;
88
+ const e2 = f;
89
+ return t2.toUpperCase() in e2;
90
90
  }
91
- function getCountry(e2, r) {
92
- const n2 = MasksFullMap(r), o2 = e2.toUpperCase();
91
+ function getCountry(r, e2) {
92
+ const n2 = MasksFullMap(e2), o2 = r.toUpperCase();
93
93
  return o2 in n2 ? { id: o2, ...n2[o2] } : { id: "US", ...n2.US };
94
94
  }
95
- function parseCountryCode(t2, e2) {
96
- return t2 && hasCountry(t2) ? t2.toUpperCase() : e2 || "";
95
+ function parseCountryCode(t2, r) {
96
+ return t2 && hasCountry(t2) ? t2.toUpperCase() : r || "";
97
97
  }
98
98
  function toArray(t2) {
99
99
  return Array.isArray(t2) ? t2 : [t2];
@@ -104,147 +104,137 @@ function countPlaceholders(t2) {
104
104
  function removeCountryCodePrefix(t2) {
105
105
  return t2.replace(/^\+\d+\s?/, "");
106
106
  }
107
- function pickMaskVariant(t2, e2) {
107
+ function pickMaskVariant(t2, r) {
108
+ if (!t2.length) return "";
108
109
  if (1 === t2.length) return t2[0];
109
- const r = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), n2 = r.filter((t3) => t3.count >= e2).sort((t3, e3) => t3.count - e3.count);
110
+ const e2 = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), n2 = e2.filter((t3) => t3.count >= r).sort((t3, r2) => t3.count - r2.count);
110
111
  if (n2.length > 0) return n2[0].mask;
111
- const o2 = r.sort((t3, e3) => e3.count - t3.count)[0];
112
+ const o2 = e2.sort((t3, r2) => r2.count - t3.count)[0];
112
113
  return o2 ? o2.mask : t2[0];
113
114
  }
114
- function formatDigitsWithMap(t2, e2) {
115
- let r = "";
115
+ function formatDigitsWithMap(t2, r) {
116
+ let e2 = "";
116
117
  const n2 = [];
117
118
  let o2 = 0;
118
- const a = e2.length, s2 = t2.length;
119
+ const a = r.length, s2 = t2.length;
119
120
  for (let c = 0; c < s2; c++) {
120
121
  const s3 = t2[c];
121
122
  if ("#" === s3) {
122
123
  if (!(o2 < a)) break;
123
- r += e2[o2], n2.push(o2), o2++;
124
+ e2 += r[o2], n2.push(o2), o2++;
124
125
  } else {
125
- const e3 = -1 !== t2.indexOf("#", c + 1) && o2 < a;
126
- (r.length > 0 || e3) && (r += s3, n2.push(-1));
126
+ const r2 = -1 !== t2.indexOf("#", c + 1) && o2 < a;
127
+ (e2.length > 0 || r2) && (e2 += s3, n2.push(-1));
127
128
  }
128
129
  }
129
- return { display: r, map: n2 };
130
+ return { display: e2, map: n2 };
130
131
  }
131
- function filterCountries(t2, e2) {
132
- const r = e2.trim().toUpperCase();
133
- if (!r) return t2;
134
- const n2 = r.replace(/\D/g, ""), o2 = n2.length > 0;
132
+ function filterCountries(t2, r) {
133
+ const e2 = r.trim().toUpperCase();
134
+ if (!e2) return t2;
135
+ const n2 = e2.replace(/\D/g, ""), o2 = n2.length > 0;
135
136
  return t2.map((t3) => {
136
- const e3 = t3.name.toUpperCase(), a = t3.id.toUpperCase(), s2 = t3.code.toUpperCase(), c = t3.code.replace(/\D/g, "");
137
- let i2 = 0;
138
- return e3.startsWith(r) ? i2 = 1e3 : e3.includes(r) && (i2 = 500), s2.startsWith(r) ? i2 += 100 : s2.includes(r) && (i2 += 50), a === r ? i2 += 200 : a.startsWith(r) && (i2 += 150), o2 && c.startsWith(n2) ? i2 += 80 : o2 && c.includes(n2) && (i2 += 40), { country: t3, score: i2 };
139
- }).filter((t3) => t3.score > 0).sort((t3, e3) => e3.score !== t3.score ? e3.score - t3.score : t3.country.name.localeCompare(e3.country.name)).map((t3) => t3.country);
137
+ const r2 = t3.name.toUpperCase(), a = t3.id.toUpperCase(), s2 = t3.code.toUpperCase(), c = t3.code.replace(/\D/g, "");
138
+ let i = 0;
139
+ return r2.startsWith(e2) ? i = 1e3 : r2.includes(e2) && (i = 500), s2.startsWith(e2) ? i += 100 : s2.includes(e2) && (i += 50), a === e2 ? i += 200 : a.startsWith(e2) && (i += 150), o2 && c.startsWith(n2) ? i += 80 : o2 && c.includes(n2) && (i += 40), { country: t3, score: i };
140
+ }).filter((t3) => t3.score > 0).sort((t3, r2) => r2.score === t3.score ? t3.country.name.localeCompare(r2.country.name) : r2.score - t3.score).map((t3) => t3.country);
140
141
  }
141
- const t = [" ", "-", "(", ")"], e$1 = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], i = /[^\d\s\-()]/;
142
- function extractDigits(t2, e2) {
143
- const i2 = t2.replace(/\D/g, "");
144
- return e2 ? i2.slice(0, e2) : i2;
142
+ const e$1 = [" ", "-", "(", ")"], t = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], n = /[^\d\s\-()]/;
143
+ function removeDigitsRange(e2, t2, n2) {
144
+ return { newDigits: e2.slice(0, t2) + e2.slice(n2), caretDigitIndex: t2 };
145
145
  }
146
- function getSelection(t2) {
147
- return t2 ? [t2.selectionStart ?? 0, t2.selectionEnd ?? 0] : [0, 0];
146
+ function removeSelectedDigits(e2, t2, n2, i) {
147
+ if (n2 === i) return;
148
+ const r = t2.getDigitRange(e2, n2, i);
149
+ if (!r) return;
150
+ const [s2, g] = r;
151
+ return removeDigitsRange(e2, s2, g);
148
152
  }
149
- function setCaret(t2, e2) {
150
- if (t2) try {
151
- t2.setSelectionRange(e2, e2);
153
+ function extractDigits(e2, t2) {
154
+ const n2 = e2.replace(/\D/g, "");
155
+ return t2 ? n2.slice(0, t2) : n2;
156
+ }
157
+ function getSelection(e2) {
158
+ return e2 ? [e2.selectionStart ?? 0, e2.selectionEnd ?? 0] : [0, 0];
159
+ }
160
+ function setCaret(e2, t2) {
161
+ if (e2) try {
162
+ e2.setSelectionRange(t2, t2);
152
163
  } catch {
153
164
  }
154
165
  }
155
- function processBeforeInput(t2) {
156
- if (!t2.target) return;
157
- const e2 = t2.target, n2 = t2.data;
158
- "insertText" === t2.inputType && n2 && (i.test(n2) || " " === n2 && e2.value.endsWith(" ")) && t2.preventDefault();
166
+ function processBeforeInput(e2) {
167
+ if (!e2.target) return;
168
+ const t2 = e2.target, i = e2.data;
169
+ "insertText" === e2.inputType && i && (n.test(i) || " " === i && t2.value.endsWith(" ")) && e2.preventDefault();
159
170
  }
160
- function processInput(t2, e2) {
161
- if (!t2.target) return;
162
- const i2 = t2.target, { formatter: n2 } = e2, r = n2.getMaxDigits(), s2 = extractDigits(i2.value, r);
171
+ function processInput(e2, t2) {
172
+ if (!e2.target) return;
173
+ const n2 = e2.target, { formatter: i } = t2, r = i.getMaxDigits(), s2 = extractDigits(n2.value, r);
163
174
  return { newDigits: s2, caretDigitIndex: s2.length };
164
175
  }
165
- function processKeydown(i2, n2) {
166
- if (!i2.target) return;
167
- const r = i2.target, { digits: s2, formatter: c } = n2;
168
- if (i2.ctrlKey || i2.metaKey || i2.altKey || e$1.includes(i2.key)) return;
169
- const [g, a] = getSelection(r);
170
- if ("Backspace" !== i2.key) if ("Delete" !== i2.key) /^[0-9]$/.test(i2.key) ? s2.length >= c.getMaxDigits() && i2.preventDefault() : 1 === i2.key.length && i2.preventDefault();
171
- else {
172
- if (i2.preventDefault(), g !== a) {
173
- const t2 = c.getDigitRange(s2, g, a);
174
- if (t2) {
175
- const [e2, i3] = t2;
176
- return { newDigits: s2.slice(0, e2) + s2.slice(i3), caretDigitIndex: e2 };
177
- }
178
- }
179
- if (g < r.value.length) {
180
- const t2 = c.getDigitRange(s2, g, r.value.length);
181
- if (t2) {
182
- const [e2] = t2;
183
- return { newDigits: s2.slice(0, e2) + s2.slice(e2 + 1), caretDigitIndex: e2 };
184
- }
185
- }
186
- }
187
- else {
188
- if (i2.preventDefault(), g !== a) {
189
- const t2 = c.getDigitRange(s2, g, a);
190
- if (t2) {
191
- const [e2, i3] = t2;
192
- return { newDigits: s2.slice(0, e2) + s2.slice(i3), caretDigitIndex: e2 };
193
- }
194
- }
195
- if (g > 0) {
196
- const e2 = r.value;
197
- let i3 = g - 1;
198
- for (; i3 >= 0 && t.includes(e2[i3]); ) i3--;
199
- if (i3 >= 0) {
200
- const t2 = c.getDigitRange(s2, i3, i3 + 1);
201
- if (t2) {
202
- const [e3] = t2;
203
- return { newDigits: s2.slice(0, e3) + s2.slice(e3 + 1), caretDigitIndex: e3 };
204
- }
205
- }
206
- }
207
- }
176
+ function processKeydown(n2, i) {
177
+ if (!n2.target) return;
178
+ const r = n2.target, { digits: s2, formatter: g } = i;
179
+ if ((function shouldIgnoreKeydown(e2) {
180
+ return e2.ctrlKey || e2.metaKey || e2.altKey || t.includes(e2.key);
181
+ })(n2)) return;
182
+ const [o2, c] = getSelection(r), a = r.value;
183
+ return "Backspace" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removePreviousDigit(t2, n3, i2, r2) {
184
+ if (r2 <= 0) return;
185
+ let s3 = r2 - 1;
186
+ for (; s3 >= 0 && e$1.includes(i2[s3]); ) s3--;
187
+ if (s3 < 0) return;
188
+ const g2 = n3.getDigitRange(t2, s3, s3 + 1);
189
+ if (!g2) return;
190
+ const [o3] = g2;
191
+ return removeDigitsRange(t2, o3, o3 + 1);
192
+ })(s2, g, a, o2)) : "Delete" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removeNextDigit(e2, t2, n3, i2) {
193
+ if (i2 >= n3.length) return;
194
+ const r2 = t2.getDigitRange(e2, i2, n3.length);
195
+ if (!r2) return;
196
+ const [s3] = r2;
197
+ return removeDigitsRange(e2, s3, s3 + 1);
198
+ })(s2, g, a, o2)) : void (/^\d$/.test(n2.key) ? s2.length >= g.getMaxDigits() && n2.preventDefault() : 1 === n2.key.length && n2.preventDefault());
208
199
  }
209
- function processPaste(t2, e2) {
210
- if (!t2.target) return;
211
- t2.preventDefault();
212
- const i2 = t2.target, { digits: n2, formatter: r } = e2, s2 = t2.clipboardData?.getData("text") || "", c = r.getMaxDigits(), g = extractDigits(s2, c);
213
- if (0 === g.length) return;
214
- const [a, o2] = getSelection(i2);
215
- if (a !== o2) {
216
- const t3 = r.getDigitRange(n2, a, o2);
217
- if (t3) {
218
- const [e3, i3] = t3;
219
- return { newDigits: extractDigits(n2.slice(0, e3) + g + n2.slice(i3), c), caretDigitIndex: e3 + g.length };
200
+ function processPaste(e2, t2) {
201
+ if (!e2.target) return;
202
+ e2.preventDefault();
203
+ const n2 = e2.target, { digits: i, formatter: r } = t2, s2 = e2.clipboardData?.getData("text") || "", g = r.getMaxDigits(), o2 = extractDigits(s2, g);
204
+ if (0 === o2.length) return;
205
+ const [c, a] = getSelection(n2);
206
+ if (c !== a) {
207
+ const e3 = r.getDigitRange(i, c, a);
208
+ if (e3) {
209
+ const [t3, n3] = e3;
210
+ return { newDigits: extractDigits(i.slice(0, t3) + o2 + i.slice(n3), g), caretDigitIndex: t3 + o2.length };
220
211
  }
221
212
  }
222
- const l = r.getDigitRange(n2, 0, a), f2 = l ? l[1] : 0;
223
- return { newDigits: extractDigits(n2.slice(0, f2) + g + n2.slice(f2), c), caretDigitIndex: f2 + g.length };
213
+ const u = r.getDigitRange(i, 0, c), l = u ? u[1] : 0;
214
+ return { newDigits: extractDigits(i.slice(0, l) + o2 + i.slice(l), g), caretDigitIndex: l + o2.length };
224
215
  }
225
216
  function createPhoneFormatter(o2) {
226
- const a = toArray(o2.mask), i2 = a.map((n2) => countPlaceholders(removeCountryCodePrefix(n2))), g = Math.max(...i2), getMask = (t2) => {
227
- const n2 = pickMaskVariant(a, t2);
217
+ const i = toArray(o2.mask), l = i.map((n2) => countPlaceholders(removeCountryCodePrefix(n2))), s2 = Math.max(...l), getMask = (t2) => {
218
+ const n2 = pickMaskVariant(i, t2);
228
219
  return removeCountryCodePrefix(n2);
229
220
  };
230
221
  return { formatDisplay: (t2) => {
231
222
  const e2 = getMask(t2.length);
232
223
  return formatDigitsWithMap(e2, t2).display;
233
- }, getMaxDigits: () => g, getPlaceholder: () => getMask(0), getCaretPosition: (t2) => {
234
- const e2 = getMask(t2), { display: r, map: l } = formatDigitsWithMap(e2, "0".repeat(t2));
235
- for (let e3 = 0; e3 < l.length; e3++) if (l[e3] === t2) return e3;
236
- if (t2 >= l.length) return r.length;
237
- for (let e3 = 0; e3 < l.length; e3++) if (l[e3] > t2) return e3;
238
- return r.length;
224
+ }, getMaxDigits: () => s2, getPlaceholder: () => getMask(0), getCaretPosition: (t2) => {
225
+ const e2 = Math.max(0, t2);
226
+ if (0 === e2) return 0;
227
+ const r = getMask(e2), { display: a } = formatDigitsWithMap(r, "0".repeat(e2));
228
+ return a.length;
239
229
  }, getDigitRange: (t2, e2, r) => {
240
- const l = getMask(t2.length), { map: o3 } = formatDigitsWithMap(l, t2);
241
- let a2 = 1 / 0, i3 = -1 / 0;
230
+ const a = getMask(t2.length), { map: o3 } = formatDigitsWithMap(a, t2);
231
+ let i2 = 1 / 0, l2 = -1 / 0;
242
232
  for (let t3 = e2; t3 < r && t3 < o3.length; t3++) {
243
233
  const e3 = o3[t3];
244
- void 0 !== e3 && e3 >= 0 && (a2 = Math.min(a2, e3), i3 = Math.max(i3, e3));
234
+ void 0 !== e3 && e3 >= 0 && (i2 = Math.min(i2, e3), l2 = Math.max(l2, e3));
245
235
  }
246
- return a2 === 1 / 0 ? null : [a2, i3 + 1];
247
- }, isComplete: (t2) => i2.includes(t2.length) };
236
+ return i2 === 1 / 0 ? null : [i2, l2 + 1];
237
+ }, isComplete: (t2) => l.includes(t2.length) };
248
238
  }
249
239
  const o = "https://ipapi.co/json/", e = 1500, p = "@desource/phone-mask:geo", s = 864e5;
250
240
  async function detectCountryFromGeoIP(t2 = o, r = e) {
@@ -288,7 +278,7 @@ function useCountry({
288
278
  const locale = computed(() => toValue(localeOption) || getNavigatorLang());
289
279
  const countryCode = ref(parseCountryCode(toValue(countryOption), "US"));
290
280
  const country = computed(() => getCountry(countryCode.value, locale.value));
291
- const setCountry = (code) => {
281
+ const setCountry2 = (code) => {
292
282
  const parsed = parseCountryCode(code);
293
283
  if (parsed) {
294
284
  countryCode.value = parsed;
@@ -298,14 +288,14 @@ function useCountry({
298
288
  };
299
289
  const detectCountry = async () => {
300
290
  const geoCountry = await detectByGeoIp();
301
- if (setCountry(geoCountry)) return;
291
+ if (setCountry2(geoCountry)) return;
302
292
  const localeCountry = detectCountryFromLocale();
303
- setCountry(localeCountry);
293
+ setCountry2(localeCountry);
304
294
  };
305
295
  watchEffect(() => {
306
296
  const newCountry = toValue(countryOption);
307
297
  if (newCountry && newCountry !== countryCode.value) {
308
- setCountry(newCountry);
298
+ setCountry2(newCountry);
309
299
  }
310
300
  });
311
301
  watchEffect(() => {
@@ -316,7 +306,7 @@ function useCountry({
316
306
  watchEffect(() => {
317
307
  onCountryChange?.(country.value);
318
308
  });
319
- return { country, setCountry, locale };
309
+ return { country, setCountry: setCountry2, locale };
320
310
  }
321
311
  function useFormatter({
322
312
  country,
@@ -503,8 +493,8 @@ function useCountrySelector({
503
493
  if (!rootRef.value) return;
504
494
  const rect = rootRef.value.getBoundingClientRect();
505
495
  dropdownStyle.value = {
506
- top: `${rect.bottom + window.scrollY + 8}px`,
507
- left: `${rect.left + window.scrollX}px`,
496
+ top: `${rect.bottom + globalThis.scrollY + 8}px`,
497
+ left: `${rect.left + globalThis.scrollX}px`,
508
498
  width: `${rect.width}px`
509
499
  };
510
500
  };
@@ -543,9 +533,9 @@ function useCountrySelector({
543
533
  }
544
534
  };
545
535
  const removeListeners = () => {
546
- window.removeEventListener("resize", positionDropdown);
547
- window.removeEventListener("scroll", positionDropdown, true);
548
- window.removeEventListener("click", onDocClick, true);
536
+ globalThis.removeEventListener("resize", positionDropdown);
537
+ globalThis.removeEventListener("scroll", positionDropdown, true);
538
+ globalThis.removeEventListener("click", onDocClick, true);
549
539
  };
550
540
  watch(hasDropdown, (dropdownExists) => {
551
541
  if (!dropdownExists && dropdownOpen.value) {
@@ -558,9 +548,9 @@ function useCountrySelector({
558
548
  return;
559
549
  }
560
550
  positionDropdown();
561
- window.addEventListener("resize", positionDropdown);
562
- window.addEventListener("scroll", positionDropdown, true);
563
- window.addEventListener("click", onDocClick, true);
551
+ globalThis.addEventListener("resize", positionDropdown);
552
+ globalThis.addEventListener("scroll", positionDropdown, true);
553
+ globalThis.addEventListener("click", onDocClick, true);
564
554
  });
565
555
  onBeforeUnmount(removeListeners);
566
556
  return {
@@ -638,15 +628,18 @@ function useCopyAction({ liveRef, fullFormatted, onCopy }) {
638
628
  function useTheme({ theme }) {
639
629
  const systemDark = ref(false);
640
630
  const themeClass = computed(() => {
641
- return toValue(theme) !== "auto" ? `theme-${toValue(theme)}` : systemDark.value ? "theme-dark" : "theme-light";
631
+ const resolvedTheme = toValue(theme);
632
+ if (resolvedTheme === "auto") {
633
+ return systemDark.value ? "theme-dark" : "theme-light";
634
+ }
635
+ return `theme-${resolvedTheme}`;
642
636
  });
643
637
  let mq = null;
644
638
  const handler = (e2) => {
645
639
  systemDark.value = e2.matches;
646
640
  };
647
641
  onBeforeMount(() => {
648
- if (typeof window === "undefined") return;
649
- mq = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
642
+ mq = globalThis.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
650
643
  if (!mq) return;
651
644
  systemDark.value = mq.matches;
652
645
  mq.addEventListener("change", handler);
@@ -695,13 +688,12 @@ const _hoisted_11 = {
695
688
  "aria-hidden": "true"
696
689
  };
697
690
  const _hoisted_12 = { class: "pi-search-wrap" };
698
- const _hoisted_13 = ["value", "placeholder"];
699
- const _hoisted_14 = ["aria-activedescendant"];
700
- const _hoisted_15 = ["id", "aria-selected", "title", "onClick", "onMouseenter"];
701
- const _hoisted_16 = ["aria-label"];
702
- const _hoisted_17 = { class: "pi-opt-name" };
703
- const _hoisted_18 = { class: "pi-opt-code" };
704
- const _hoisted_19 = {
691
+ const _hoisted_13 = ["value", "aria-activedescendant", "placeholder"];
692
+ const _hoisted_14 = ["id", "aria-selected", "title", "onClick", "onMouseenter"];
693
+ const _hoisted_15 = ["aria-label"];
694
+ const _hoisted_16 = { class: "pi-opt-name" };
695
+ const _hoisted_17 = { class: "pi-opt-code" };
696
+ const _hoisted_18 = {
705
697
  key: 0,
706
698
  class: "pi-empty"
707
699
  };
@@ -736,7 +728,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
736
728
  const onChange = (v) => {
737
729
  model.value = v;
738
730
  };
739
- const { country, setCountry, locale } = useCountry({
731
+ const { country, setCountry: setCountry2, locale } = useCountry({
740
732
  country: () => props.country,
741
733
  locale: () => props.locale,
742
734
  detect: () => props.detect,
@@ -766,6 +758,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
766
758
  const dropdownRef = useTemplateRef("dropdownRef");
767
759
  const searchRef = useTemplateRef("searchRef");
768
760
  const selectorRef = useTemplateRef("selectorRef");
761
+ const dropdownId = getCurrentInstance()?.uid ?? 0;
762
+ const listboxId = `pi-options-${dropdownId}`;
763
+ const getOptionId = (idx) => `pi-option-${dropdownId}-${idx}`;
769
764
  const inactive = computed(() => props.disabled || props.readonly);
770
765
  const incomplete = computed(() => showValidationHint.value && shouldShowWarn.value);
771
766
  const showCopyButton = computed(() => props.showCopy && !isEmpty.value && !props.disabled);
@@ -797,9 +792,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
797
792
  locale,
798
793
  countryOption: () => props.country,
799
794
  inactive,
800
- onSelectCountry: setCountry,
795
+ onSelectCountry: setCountry2,
801
796
  onAfterSelect: focusInput
802
797
  });
798
+ const activeOptionId = computed(
799
+ () => dropdownOpen.value && filteredCountries.value[focusedIndex.value] ? getOptionId(focusedIndex.value) : void 0
800
+ );
803
801
  const { handleBeforeInput, handleInput, handleKeydown, handlePaste } = useInputHandlers({
804
802
  formatter,
805
803
  digits,
@@ -1011,6 +1009,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1011
1009
  type: "search",
1012
1010
  class: "pi-search",
1013
1011
  "aria-label": "Search countries",
1012
+ "aria-controls": listboxId,
1013
+ "aria-activedescendant": activeOptionId.value,
1014
1014
  placeholder: __props.searchPlaceholder,
1015
1015
  onKeydown: _cache[6] || (_cache[6] = //@ts-ignore
1016
1016
  (...args) => unref(handleSearchKeydown) && unref(handleSearchKeydown)(...args)),
@@ -1019,14 +1019,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1019
1019
  }, null, 40, _hoisted_13)
1020
1020
  ]),
1021
1021
  createElementVNode("ul", {
1022
+ id: listboxId,
1022
1023
  class: "pi-options",
1023
1024
  role: "listbox",
1024
- "aria-activedescendant": `option-${unref(focusedIndex)}`,
1025
1025
  tabindex: "-1"
1026
1026
  }, [
1027
1027
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(filteredCountries), (c, idx) => {
1028
1028
  return openBlock(), createElementBlock("li", {
1029
- id: `option-${idx}`,
1029
+ id: getOptionId(idx),
1030
1030
  key: c.id,
1031
1031
  role: "option",
1032
1032
  class: normalizeClass([
@@ -1049,13 +1049,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1049
1049
  renderSlot(_ctx.$slots, "flag", { country: c }, () => [
1050
1050
  createTextVNode(toDisplayString(c.flag), 1)
1051
1051
  ], true)
1052
- ], 8, _hoisted_16),
1053
- createElementVNode("span", _hoisted_17, toDisplayString(c.name), 1),
1054
- createElementVNode("span", _hoisted_18, toDisplayString(c.code), 1)
1055
- ], 42, _hoisted_15);
1052
+ ], 8, _hoisted_15),
1053
+ createElementVNode("span", _hoisted_16, toDisplayString(c.name), 1),
1054
+ createElementVNode("span", _hoisted_17, toDisplayString(c.code), 1)
1055
+ ], 42, _hoisted_14);
1056
1056
  }), 128)),
1057
- unref(filteredCountries).length === 0 ? (openBlock(), createElementBlock("li", _hoisted_19, toDisplayString(__props.noResultsText), 1)) : createCommentVNode("", true)
1058
- ], 8, _hoisted_14)
1057
+ unref(filteredCountries).length === 0 ? (openBlock(), createElementBlock("li", _hoisted_18, toDisplayString(__props.noResultsText), 1)) : createCommentVNode("", true)
1058
+ ])
1059
1059
  ], 6)) : createCommentVNode("", true)
1060
1060
  ]),
1061
1061
  _: 3
@@ -1080,47 +1080,18 @@ const _export_sfc = (sfc, props) => {
1080
1080
  }
1081
1081
  return target;
1082
1082
  };
1083
- const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-33134720"]]);
1084
- async function initState(binding) {
1085
- const value = binding.value;
1086
- let options = {};
1087
- if (typeof value === "string") {
1088
- options = { country: value };
1089
- } else if (typeof value === "object" && value !== null) {
1090
- options = value;
1091
- }
1092
- const locale = options.locale || getNavigatorLang();
1093
- let country;
1094
- if (options.country) {
1095
- country = getCountry(options.country, locale);
1096
- } else if (options.detect) {
1097
- const geoCountry = await detectCountryFromGeoIP();
1098
- if (geoCountry) {
1099
- country = getCountry(geoCountry, locale);
1100
- } else {
1101
- const localeCountry = detectCountryFromLocale();
1102
- if (localeCountry) {
1103
- country = getCountry(localeCountry, locale);
1104
- } else {
1105
- country = getCountry("US", locale);
1106
- }
1107
- }
1108
- } else {
1109
- country = getCountry("US", locale);
1110
- }
1111
- return {
1112
- country,
1113
- formatter: createPhoneFormatter(country),
1114
- digits: "",
1115
- locale,
1116
- options
1117
- };
1083
+ const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d730aa54"]]);
1084
+ function parseParams(params) {
1085
+ if (typeof params === "string") return { country: params };
1086
+ if (params && typeof params === "object") return params;
1087
+ return {};
1118
1088
  }
1119
- function updateDisplay(el, state) {
1089
+ function updateDigits(el, state, digits) {
1090
+ state.digits = digits;
1120
1091
  el.value = state.formatter.formatDisplay(state.digits);
1121
1092
  if (state.options.onChange) {
1122
- const fullNumberFormatted = `${state.country.code} ${el.value}`;
1123
- const fullNumber = `${state.country.code}${state.digits}`;
1093
+ const fullNumberFormatted = el.value ? `${state.country.code} ${el.value}` : "";
1094
+ const fullNumber = state.digits ? `${state.country.code}${state.digits}` : "";
1124
1095
  state.options.onChange({
1125
1096
  full: fullNumber,
1126
1097
  fullFormatted: fullNumberFormatted,
@@ -1128,113 +1099,92 @@ function updateDisplay(el, state) {
1128
1099
  });
1129
1100
  }
1130
1101
  }
1131
- function createInputHandler(el, state) {
1132
- return (e2) => {
1133
- const result = processInput(e2, { formatter: state.formatter });
1134
- if (!result) return;
1135
- state.digits = result.newDigits;
1136
- updateDisplay(el, state);
1137
- nextTick(() => {
1138
- const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
1139
- setCaret(el, pos);
1140
- });
1141
- };
1102
+ function checkDigitsUpdate(el, state) {
1103
+ const maxDigits = state.formatter.getMaxDigits();
1104
+ const digits = extractDigits(el.value, maxDigits);
1105
+ const displayValue = state.formatter.formatDisplay(digits);
1106
+ if (digits !== state.digits || el.value !== displayValue) {
1107
+ updateDigits(el, state, digits);
1108
+ }
1142
1109
  }
1143
- function createKeydownHandler(el, state) {
1144
- return (e2) => {
1145
- const result = processKeydown(e2, {
1146
- digits: state.digits,
1147
- formatter: state.formatter
1148
- });
1149
- if (!result) return;
1150
- state.digits = result.newDigits;
1151
- updateDisplay(el, state);
1152
- nextTick(() => {
1153
- const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
1154
- setCaret(el, pos);
1155
- });
1156
- };
1110
+ function checkCountryUpdate(el, state) {
1111
+ const oldCountry = state.country.id;
1112
+ const newCountry = parseCountryCode(state.options.country);
1113
+ if (newCountry && newCountry !== oldCountry) {
1114
+ setCountry(el, state, newCountry);
1115
+ }
1157
1116
  }
1158
- function createPasteHandler(el, state) {
1117
+ function createHandler(el, state, handler) {
1159
1118
  return (e2) => {
1160
- const result = processPaste(e2, {
1161
- digits: state.digits,
1162
- formatter: state.formatter
1163
- });
1119
+ const result = handler(e2, state);
1164
1120
  if (!result) return;
1165
- state.digits = result.newDigits;
1166
- updateDisplay(el, state);
1121
+ updateDigits(el, state, result.newDigits);
1167
1122
  nextTick(() => {
1168
1123
  const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
1169
1124
  setCaret(el, pos);
1170
1125
  });
1171
1126
  };
1172
1127
  }
1173
- async function updateCountry(el, state, newCountryCode) {
1174
- const newCountry = getCountry(newCountryCode, state.locale);
1128
+ async function detectInitialCountry(options) {
1129
+ const countryOption = parseCountryCode(options.country);
1130
+ if (countryOption) return countryOption;
1131
+ if (options.detect) {
1132
+ const geoCountry = parseCountryCode(await detectByGeoIp());
1133
+ if (geoCountry) return geoCountry;
1134
+ const localeCountry = parseCountryCode(detectCountryFromLocale());
1135
+ if (localeCountry) return localeCountry;
1136
+ }
1137
+ return "US";
1138
+ }
1139
+ function setCountry(el, state, newCountryCode) {
1140
+ const parsed = parseCountryCode(newCountryCode);
1141
+ if (!parsed) return;
1142
+ const newCountry = getCountry(parsed, state.locale);
1175
1143
  state.country = newCountry;
1144
+ state.options.onCountryChange?.(newCountry);
1176
1145
  state.formatter = createPhoneFormatter(newCountry);
1177
1146
  el.placeholder = state.formatter.getPlaceholder();
1178
- const maxDigits = state.formatter.getMaxDigits();
1179
- if (state.digits.length > maxDigits) {
1180
- state.digits = state.digits.slice(0, maxDigits);
1181
- }
1182
- updateDisplay(el, state);
1183
- if (state.options.onCountryChange) {
1184
- state.options.onCountryChange(newCountry);
1185
- }
1147
+ checkDigitsUpdate(el, state);
1186
1148
  }
1187
1149
  const vPhoneMask = {
1188
- async mounted(el, binding) {
1150
+ mounted(el, binding) {
1189
1151
  if (el.tagName !== "INPUT") {
1190
1152
  console.warn("[v-phone-mask] Directive can only be used on input elements");
1191
1153
  return;
1192
1154
  }
1193
1155
  el.setAttribute("type", "tel");
1194
1156
  el.setAttribute("inputmode", "tel");
1195
- const state = await initState(binding);
1157
+ el.setAttribute("placeholder", "");
1158
+ const options = parseParams(binding.value);
1159
+ const locale = options.locale || getNavigatorLang();
1160
+ const country = getCountry(parseCountryCode(options.country, "US"), locale);
1161
+ const state = {
1162
+ country,
1163
+ formatter: createPhoneFormatter(country),
1164
+ digits: "",
1165
+ locale,
1166
+ options
1167
+ };
1196
1168
  el.__phoneMaskState = state;
1197
- state.inputHandler = createInputHandler(el, state);
1198
- state.keydownHandler = createKeydownHandler(el, state);
1199
- state.pasteHandler = createPasteHandler(el, state);
1169
+ state.inputHandler = createHandler(el, state, processInput);
1170
+ state.keydownHandler = createHandler(el, state, processKeydown);
1171
+ state.pasteHandler = createHandler(el, state, processPaste);
1200
1172
  state.beforeInputHandler = processBeforeInput;
1201
1173
  el.addEventListener("beforeinput", state.beforeInputHandler);
1202
1174
  el.addEventListener("input", state.inputHandler);
1203
1175
  el.addEventListener("keydown", state.keydownHandler);
1204
1176
  el.addEventListener("paste", state.pasteHandler);
1205
- el.setAttribute("placeholder", state.formatter.getPlaceholder());
1206
- if (state.options.onCountryChange) {
1207
- state.options.onCountryChange(state.country);
1208
- }
1209
- if (el.value) {
1210
- const maxDigits = state.formatter.getMaxDigits();
1211
- state.digits = extractDigits(el.value, maxDigits);
1212
- updateDisplay(el, state);
1213
- }
1177
+ detectInitialCountry(options).then((countryCode) => {
1178
+ if (el.__phoneMaskState !== state) return;
1179
+ setCountry(el, state, countryCode);
1180
+ });
1214
1181
  },
1215
- async updated(el, binding) {
1182
+ updated(el, binding) {
1216
1183
  const state = el.__phoneMaskState;
1217
1184
  if (!state) return;
1218
- const value = binding.value;
1219
- let newOptions = {};
1220
- if (typeof value === "string") {
1221
- newOptions = { country: value };
1222
- } else if (typeof value === "object" && value !== null) {
1223
- newOptions = value;
1224
- }
1225
- const oldCountry = state.options.country;
1226
- state.options = newOptions;
1227
- const newCountry = newOptions.country;
1228
- if (newCountry && newCountry !== oldCountry) {
1229
- await updateCountry(el, state, newCountry);
1230
- }
1231
- const maxDigits = state.formatter.getMaxDigits();
1232
- const newDigits = extractDigits(el.value, maxDigits);
1233
- const normalizedDisplay = state.formatter.formatDisplay(newDigits);
1234
- if (newDigits !== state.digits || el.value !== normalizedDisplay) {
1235
- state.digits = newDigits;
1236
- updateDisplay(el, state);
1237
- }
1185
+ state.options = parseParams(binding.value);
1186
+ checkCountryUpdate(el, state);
1187
+ checkDigitsUpdate(el, state);
1238
1188
  },
1239
1189
  unmounted(el) {
1240
1190
  const state = el.__phoneMaskState;
@@ -1248,7 +1198,7 @@ const vPhoneMask = {
1248
1198
  };
1249
1199
  function usePhoneMask(options) {
1250
1200
  const inputRef = shallowRef(null);
1251
- const { country, setCountry } = useCountry({
1201
+ const { country, setCountry: setCountry2 } = useCountry({
1252
1202
  country: options.country,
1253
1203
  locale: options.locale,
1254
1204
  detect: options.detect,
@@ -1312,13 +1262,14 @@ function usePhoneMask(options) {
1312
1262
  return {
1313
1263
  inputRef,
1314
1264
  digits,
1265
+ formatter,
1315
1266
  full,
1316
1267
  fullFormatted,
1317
1268
  isComplete,
1318
1269
  isEmpty,
1319
1270
  shouldShowWarn,
1320
1271
  country,
1321
- setCountry,
1272
+ setCountry: setCountry2,
1322
1273
  clear
1323
1274
  };
1324
1275
  }
@@ -1344,5 +1295,5 @@ export {
1344
1295
  install,
1345
1296
  usePhoneMask,
1346
1297
  vPhoneMask,
1347
- updateCountry as vPhoneMaskSetCountry
1298
+ setCountry as vPhoneMaskSetCountry
1348
1299
  };