@desource/phone-mask-vue 1.1.1 → 1.1.2

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.cjs CHANGED
@@ -1,1299 +1 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const vue = require("vue");
4
- 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 #### ######"] };
5
- const t$1 = /^[a-z]{2}$/i, countryCodeEmoji = (o2) => {
6
- if (!t$1.test(o2)) {
7
- const t2 = typeof o2;
8
- throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${"string" === t2 ? o2 : t2}' instead.`);
9
- }
10
- const e2 = [...o2.toUpperCase()].map((t2) => (t2.codePointAt(0) ?? 0) + 127397);
11
- return String.fromCodePoint(...e2);
12
- };
13
- const o$1 = "en", n$1 = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
14
- const t2 = e2.toLowerCase(), s2 = n$1.get(t2);
15
- if (s2) return s2;
16
- const r = new Intl.DisplayNames([e2], { type: "region" });
17
- if (n$1.size >= 10) {
18
- for (const e3 of n$1.keys()) if (e3 !== o$1) {
19
- n$1.delete(e3);
20
- break;
21
- }
22
- }
23
- return n$1.set(t2, r), r;
24
- }, s$1 = Object.entries(M), divideMask = (e2) => e2.split(/ (.*)/s);
25
- function getCodeAndMask(e2) {
26
- let t2 = "", o2 = "";
27
- if (Array.isArray(e2)) {
28
- const n2 = [];
29
- for (const o3 of e2) {
30
- const [e3, s2] = divideMask(o3);
31
- t2 || (t2 = e3), n2.push(s2);
32
- }
33
- o2 = n2;
34
- } else {
35
- const [n2, s2] = divideMask(e2);
36
- t2 = n2, o2 = s2;
37
- }
38
- return [t2, o2];
39
- }
40
- s$1.map(([e2, t2]) => ({ id: e2, mask: t2 }));
41
- s$1.reduce((e2, [t2, o2]) => {
42
- const [n2, s2] = getCodeAndMask(o2);
43
- return e2[t2] = { code: n2, mask: s2 }, e2;
44
- }, {});
45
- s$1.map(([e2, t2]) => {
46
- const [o2, n2] = getCodeAndMask(t2);
47
- return { id: e2, code: o2, mask: n2 };
48
- });
49
- s$1.reduce((e2, [o2, n2]) => {
50
- const [s2, r] = getCodeAndMask(n2);
51
- return e2[o2] = { code: s2, mask: r, flag: countryCodeEmoji(o2) }, e2;
52
- }, {});
53
- s$1.map(([e2, o2]) => {
54
- const [n2, s2] = getCodeAndMask(o2);
55
- return { id: e2, code: n2, mask: s2, flag: countryCodeEmoji(e2) };
56
- });
57
- const MasksFullMap = (e2) => {
58
- const o2 = getDisplayNames(e2);
59
- return s$1.reduce((e3, [n2, s2]) => {
60
- const [r, a] = getCodeAndMask(s2), d = o2.of(n2) ?? "";
61
- return e3[n2] = { code: r, mask: a, name: d, flag: countryCodeEmoji(n2) }, e3;
62
- }, {});
63
- }, MasksFull = (e2) => {
64
- const o2 = getDisplayNames(e2);
65
- return s$1.map(([e3, n2]) => {
66
- const [s2, r] = getCodeAndMask(n2);
67
- return { id: e3, code: s2, mask: r, name: o2.of(e3) ?? "", flag: countryCodeEmoji(e3) };
68
- });
69
- }, f = MasksFullMap(o$1);
70
- MasksFull(o$1);
71
- const k = countryCodeEmoji;
72
- function getNavigatorLang() {
73
- return globalThis.navigator?.language || "en";
74
- }
75
- function detectCountryFromLocale() {
76
- try {
77
- const t2 = getNavigatorLang();
78
- try {
79
- const r2 = new Intl.Locale(t2);
80
- if (r2.region) return r2.region.toUpperCase();
81
- } catch {
82
- }
83
- const r = t2.split(/[-_]/);
84
- if (r.length > 1) return r[1]?.toUpperCase() || null;
85
- } catch {
86
- }
87
- return null;
88
- }
89
- function hasCountry(t2) {
90
- const e2 = f;
91
- return t2.toUpperCase() in e2;
92
- }
93
- function getCountry(r, e2) {
94
- const n2 = MasksFullMap(e2), o2 = r.toUpperCase();
95
- return o2 in n2 ? { id: o2, ...n2[o2] } : { id: "US", ...n2.US };
96
- }
97
- function parseCountryCode(t2, r) {
98
- return t2 && hasCountry(t2) ? t2.toUpperCase() : r || "";
99
- }
100
- function toArray(t2) {
101
- return Array.isArray(t2) ? t2 : [t2];
102
- }
103
- function countPlaceholders(t2) {
104
- return (t2.match(/#/g) || []).length;
105
- }
106
- function removeCountryCodePrefix(t2) {
107
- return t2.replace(/^\+\d+\s?/, "");
108
- }
109
- function pickMaskVariant(t2, r) {
110
- if (!t2.length) return "";
111
- if (1 === t2.length) return t2[0];
112
- const e2 = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), n2 = e2.filter((t3) => t3.count >= r).sort((t3, r2) => t3.count - r2.count);
113
- if (n2.length > 0) return n2[0].mask;
114
- const o2 = e2.sort((t3, r2) => r2.count - t3.count)[0];
115
- return o2 ? o2.mask : t2[0];
116
- }
117
- function formatDigitsWithMap(t2, r) {
118
- let e2 = "";
119
- const n2 = [];
120
- let o2 = 0;
121
- const a = r.length, s2 = t2.length;
122
- for (let c = 0; c < s2; c++) {
123
- const s3 = t2[c];
124
- if ("#" === s3) {
125
- if (!(o2 < a)) break;
126
- e2 += r[o2], n2.push(o2), o2++;
127
- } else {
128
- const r2 = -1 !== t2.indexOf("#", c + 1) && o2 < a;
129
- (e2.length > 0 || r2) && (e2 += s3, n2.push(-1));
130
- }
131
- }
132
- return { display: e2, map: n2 };
133
- }
134
- function filterCountries(t2, r) {
135
- const e2 = r.trim().toUpperCase();
136
- if (!e2) return t2;
137
- const n2 = e2.replace(/\D/g, ""), o2 = n2.length > 0;
138
- return t2.map((t3) => {
139
- const r2 = t3.name.toUpperCase(), a = t3.id.toUpperCase(), s2 = t3.code.toUpperCase(), c = t3.code.replace(/\D/g, "");
140
- let i = 0;
141
- 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 };
142
- }).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);
143
- }
144
- const e$1 = [" ", "-", "(", ")"], t = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], n = /[^\d\s\-()]/;
145
- function removeDigitsRange(e2, t2, n2) {
146
- return { newDigits: e2.slice(0, t2) + e2.slice(n2), caretDigitIndex: t2 };
147
- }
148
- function removeSelectedDigits(e2, t2, n2, i) {
149
- if (n2 === i) return;
150
- const r = t2.getDigitRange(e2, n2, i);
151
- if (!r) return;
152
- const [s2, g] = r;
153
- return removeDigitsRange(e2, s2, g);
154
- }
155
- function extractDigits(e2, t2) {
156
- const n2 = e2.replace(/\D/g, "");
157
- return t2 ? n2.slice(0, t2) : n2;
158
- }
159
- function getSelection(e2) {
160
- return e2 ? [e2.selectionStart ?? 0, e2.selectionEnd ?? 0] : [0, 0];
161
- }
162
- function setCaret(e2, t2) {
163
- if (e2) try {
164
- e2.setSelectionRange(t2, t2);
165
- } catch {
166
- }
167
- }
168
- function processBeforeInput(e2) {
169
- if (!e2.target) return;
170
- const t2 = e2.target, i = e2.data;
171
- "insertText" === e2.inputType && i && (n.test(i) || " " === i && t2.value.endsWith(" ")) && e2.preventDefault();
172
- }
173
- function processInput(e2, t2) {
174
- if (!e2.target) return;
175
- const n2 = e2.target, { formatter: i } = t2, r = i.getMaxDigits(), s2 = extractDigits(n2.value, r);
176
- return { newDigits: s2, caretDigitIndex: s2.length };
177
- }
178
- function processKeydown(n2, i) {
179
- if (!n2.target) return;
180
- const r = n2.target, { digits: s2, formatter: g } = i;
181
- if ((function shouldIgnoreKeydown(e2) {
182
- return e2.ctrlKey || e2.metaKey || e2.altKey || t.includes(e2.key);
183
- })(n2)) return;
184
- const [o2, c] = getSelection(r), a = r.value;
185
- return "Backspace" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removePreviousDigit(t2, n3, i2, r2) {
186
- if (r2 <= 0) return;
187
- let s3 = r2 - 1;
188
- for (; s3 >= 0 && e$1.includes(i2[s3]); ) s3--;
189
- if (s3 < 0) return;
190
- const g2 = n3.getDigitRange(t2, s3, s3 + 1);
191
- if (!g2) return;
192
- const [o3] = g2;
193
- return removeDigitsRange(t2, o3, o3 + 1);
194
- })(s2, g, a, o2)) : "Delete" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removeNextDigit(e2, t2, n3, i2) {
195
- if (i2 >= n3.length) return;
196
- const r2 = t2.getDigitRange(e2, i2, n3.length);
197
- if (!r2) return;
198
- const [s3] = r2;
199
- return removeDigitsRange(e2, s3, s3 + 1);
200
- })(s2, g, a, o2)) : void (/^\d$/.test(n2.key) ? s2.length >= g.getMaxDigits() && n2.preventDefault() : 1 === n2.key.length && n2.preventDefault());
201
- }
202
- function processPaste(e2, t2) {
203
- if (!e2.target) return;
204
- e2.preventDefault();
205
- const n2 = e2.target, { digits: i, formatter: r } = t2, s2 = e2.clipboardData?.getData("text") || "", g = r.getMaxDigits(), o2 = extractDigits(s2, g);
206
- if (0 === o2.length) return;
207
- const [c, a] = getSelection(n2);
208
- if (c !== a) {
209
- const e3 = r.getDigitRange(i, c, a);
210
- if (e3) {
211
- const [t3, n3] = e3;
212
- return { newDigits: extractDigits(i.slice(0, t3) + o2 + i.slice(n3), g), caretDigitIndex: t3 + o2.length };
213
- }
214
- }
215
- const u = r.getDigitRange(i, 0, c), l = u ? u[1] : 0;
216
- return { newDigits: extractDigits(i.slice(0, l) + o2 + i.slice(l), g), caretDigitIndex: l + o2.length };
217
- }
218
- function createPhoneFormatter(o2) {
219
- const i = toArray(o2.mask), l = i.map((n2) => countPlaceholders(removeCountryCodePrefix(n2))), s2 = Math.max(...l), getMask = (t2) => {
220
- const n2 = pickMaskVariant(i, t2);
221
- return removeCountryCodePrefix(n2);
222
- };
223
- return { formatDisplay: (t2) => {
224
- const e2 = getMask(t2.length);
225
- return formatDigitsWithMap(e2, t2).display;
226
- }, getMaxDigits: () => s2, getPlaceholder: () => getMask(0), getCaretPosition: (t2) => {
227
- const e2 = Math.max(0, t2);
228
- if (0 === e2) return 0;
229
- const r = getMask(e2), { display: a } = formatDigitsWithMap(r, "0".repeat(e2));
230
- return a.length;
231
- }, getDigitRange: (t2, e2, r) => {
232
- const a = getMask(t2.length), { map: o3 } = formatDigitsWithMap(a, t2);
233
- let i2 = 1 / 0, l2 = -1 / 0;
234
- for (let t3 = e2; t3 < r && t3 < o3.length; t3++) {
235
- const e3 = o3[t3];
236
- void 0 !== e3 && e3 >= 0 && (i2 = Math.min(i2, e3), l2 = Math.max(l2, e3));
237
- }
238
- return i2 === 1 / 0 ? null : [i2, l2 + 1];
239
- }, isComplete: (t2) => l.includes(t2.length) };
240
- }
241
- const o = "https://ipapi.co/json/", e = 1500, p = "@desource/phone-mask:geo", s = 864e5;
242
- async function detectCountryFromGeoIP(t2 = o, r = e) {
243
- const n2 = new AbortController(), c = setTimeout(() => n2.abort(), r);
244
- try {
245
- const o2 = await fetch(t2, { signal: n2.signal, headers: { Accept: "application/json" } });
246
- if (clearTimeout(c), !o2.ok) return null;
247
- const e2 = await o2.json();
248
- return (e2.country || e2.country_code || e2.countryCode || e2.country_code2 || "").toString().toUpperCase() || null;
249
- } catch {
250
- return clearTimeout(c), null;
251
- }
252
- }
253
- async function detectByGeoIp() {
254
- try {
255
- const o3 = localStorage.getItem(p);
256
- if (o3) {
257
- const e3 = JSON.parse(o3), c = Date.now() - e3.ts > s, a = parseCountryCode(e3.country_code);
258
- if (a && !c) return a;
259
- localStorage.removeItem(p);
260
- }
261
- } catch {
262
- }
263
- const o2 = await detectCountryFromGeoIP(), e2 = parseCountryCode(o2);
264
- if (e2) {
265
- try {
266
- const t2 = JSON.stringify({ country_code: e2, ts: Date.now() });
267
- localStorage.setItem(p, t2);
268
- } catch {
269
- }
270
- return e2;
271
- }
272
- return null;
273
- }
274
- function useCountry({
275
- country: countryOption,
276
- locale: localeOption,
277
- detect,
278
- onCountryChange
279
- } = {}) {
280
- const locale = vue.computed(() => vue.toValue(localeOption) || getNavigatorLang());
281
- const countryCode = vue.ref(parseCountryCode(vue.toValue(countryOption), "US"));
282
- const country = vue.computed(() => getCountry(countryCode.value, locale.value));
283
- const setCountry2 = (code) => {
284
- const parsed = parseCountryCode(code);
285
- if (parsed) {
286
- countryCode.value = parsed;
287
- return true;
288
- }
289
- return false;
290
- };
291
- const detectCountry = async () => {
292
- const geoCountry = await detectByGeoIp();
293
- if (setCountry2(geoCountry)) return;
294
- const localeCountry = detectCountryFromLocale();
295
- setCountry2(localeCountry);
296
- };
297
- vue.watchEffect(() => {
298
- const newCountry = vue.toValue(countryOption);
299
- if (newCountry && newCountry !== countryCode.value) {
300
- setCountry2(newCountry);
301
- }
302
- });
303
- vue.watchEffect(() => {
304
- if (vue.toValue(detect) && !vue.toValue(countryOption)) {
305
- detectCountry();
306
- }
307
- });
308
- vue.watchEffect(() => {
309
- onCountryChange?.(country.value);
310
- });
311
- return { country, setCountry: setCountry2, locale };
312
- }
313
- function useFormatter({
314
- country,
315
- value,
316
- onChange,
317
- onPhoneChange,
318
- onValidationChange
319
- }) {
320
- const formatter = vue.computed(() => createPhoneFormatter(vue.toValue(country)));
321
- const maxDigits = vue.computed(() => formatter.value.getMaxDigits());
322
- const digits = vue.computed(() => extractDigits(vue.toValue(value), maxDigits.value));
323
- const displayPlaceholder = vue.computed(() => formatter.value.getPlaceholder());
324
- const displayValue = vue.computed(() => formatter.value.formatDisplay(digits.value));
325
- const full = vue.computed(() => digits.value ? `${vue.toValue(country).code}${digits.value}` : "");
326
- const fullFormatted = vue.computed(() => displayValue.value ? `${vue.toValue(country).code} ${displayValue.value}` : "");
327
- const isComplete = vue.computed(() => formatter.value.isComplete(digits.value));
328
- const isEmpty = vue.computed(() => digits.value.length === 0);
329
- const shouldShowWarn = vue.computed(() => !isEmpty.value && !isComplete.value);
330
- const phoneData = vue.computed(() => ({
331
- full: full.value,
332
- fullFormatted: fullFormatted.value,
333
- digits: digits.value
334
- }));
335
- vue.watchEffect(() => {
336
- if (vue.toValue(value) !== digits.value) {
337
- onChange(digits.value);
338
- }
339
- });
340
- vue.watchEffect(() => {
341
- onPhoneChange?.(phoneData.value);
342
- });
343
- vue.watchEffect(() => {
344
- onValidationChange?.(isComplete.value);
345
- });
346
- return {
347
- digits,
348
- formatter,
349
- displayPlaceholder,
350
- displayValue,
351
- full,
352
- fullFormatted,
353
- isComplete,
354
- isEmpty,
355
- shouldShowWarn
356
- };
357
- }
358
- function useTimer() {
359
- let timerRef = null;
360
- const clear = () => {
361
- if (timerRef) {
362
- clearTimeout(timerRef);
363
- timerRef = null;
364
- }
365
- };
366
- const set = (callback, delay) => {
367
- clear();
368
- timerRef = setTimeout(callback, delay);
369
- };
370
- vue.onUnmounted(clear);
371
- return { set, clear };
372
- }
373
- function useValidationHint() {
374
- const showValidationHint = vue.ref(false);
375
- const validationTimer = useTimer();
376
- const clearValidationHint = (hideHint = true) => {
377
- if (hideHint) showValidationHint.value = false;
378
- validationTimer.clear();
379
- };
380
- const scheduleValidationHint = (delay) => {
381
- showValidationHint.value = false;
382
- validationTimer.set(() => {
383
- showValidationHint.value = true;
384
- }, delay);
385
- };
386
- return { showValidationHint, clearValidationHint, scheduleValidationHint };
387
- }
388
- const HINT_DELAY_INPUT = 500;
389
- const HINT_DELAY_ACTION = 300;
390
- function useInputHandlers(options) {
391
- const { formatter, digits, inactive, onChange, scheduleValidationHint } = options;
392
- const scheduleCaretUpdate = (el, digitIndex) => {
393
- vue.nextTick(() => {
394
- if (!el) return;
395
- const pos = vue.toValue(formatter).getCaretPosition(digitIndex);
396
- setCaret(el, pos);
397
- });
398
- };
399
- const handleBeforeInput = (e2) => {
400
- processBeforeInput(e2);
401
- };
402
- const handleInput = (e2) => {
403
- if (vue.toValue(inactive)) return;
404
- const result = processInput(e2, { formatter: vue.toValue(formatter) });
405
- if (!result) return;
406
- onChange?.(result.newDigits);
407
- scheduleCaretUpdate(e2.target, result.caretDigitIndex);
408
- scheduleValidationHint?.(HINT_DELAY_INPUT);
409
- };
410
- const handleKeydown = (e2) => {
411
- if (vue.toValue(inactive)) return;
412
- const result = processKeydown(e2, { digits: vue.toValue(digits), formatter: vue.toValue(formatter) });
413
- if (!result) return;
414
- onChange?.(result.newDigits);
415
- scheduleCaretUpdate(e2.target, result.caretDigitIndex);
416
- scheduleValidationHint?.(HINT_DELAY_ACTION);
417
- };
418
- const handlePaste = (e2) => {
419
- if (vue.toValue(inactive)) return;
420
- const result = processPaste(e2, { digits: vue.toValue(digits), formatter: vue.toValue(formatter) });
421
- if (!result) return;
422
- onChange?.(result.newDigits);
423
- scheduleCaretUpdate(e2.target, result.caretDigitIndex);
424
- scheduleValidationHint?.(HINT_DELAY_ACTION);
425
- };
426
- return {
427
- handleBeforeInput,
428
- handleInput,
429
- handleKeydown,
430
- handlePaste
431
- };
432
- }
433
- function useCountrySelector({
434
- rootRef,
435
- dropdownRef,
436
- searchRef,
437
- selectorRef,
438
- locale,
439
- countryOption,
440
- inactive,
441
- onSelectCountry,
442
- onAfterSelect
443
- }) {
444
- const search = vue.ref("");
445
- const dropdownOpen = vue.ref(false);
446
- const dropdownStyle = vue.shallowRef({});
447
- const focusedIndex = vue.ref(0);
448
- const countries = vue.computed(() => MasksFull(vue.toValue(locale)));
449
- const filteredCountries = vue.computed(() => filterCountries(countries.value, search.value));
450
- const hasDropdown = vue.computed(() => !vue.toValue(countryOption) && countries.value.length > 1);
451
- const setFocusedIndex = (index2) => {
452
- focusedIndex.value = index2;
453
- };
454
- const focusSearch = () => {
455
- vue.nextTick(() => searchRef.value?.focus({ preventScroll: true }));
456
- };
457
- const closeDropdown = () => {
458
- dropdownOpen.value = false;
459
- };
460
- const openDropdown = () => {
461
- dropdownOpen.value = true;
462
- setFocusedIndex(0);
463
- focusSearch();
464
- };
465
- const toggleDropdown = () => {
466
- if (vue.toValue(inactive) || !hasDropdown.value) return;
467
- if (dropdownOpen.value) {
468
- closeDropdown();
469
- } else {
470
- openDropdown();
471
- }
472
- };
473
- const selectCountry = (code) => {
474
- onSelectCountry(code);
475
- closeDropdown();
476
- search.value = "";
477
- setFocusedIndex(0);
478
- onAfterSelect?.();
479
- };
480
- const handleSearchChange = (e2) => {
481
- search.value = e2.target.value;
482
- setFocusedIndex(0);
483
- };
484
- const onDocClick = (ev) => {
485
- const target = ev.target;
486
- const dropdownEl = dropdownRef.value;
487
- const selectorEl = selectorRef.value;
488
- if (!target) return;
489
- if (dropdownEl?.contains(target)) return;
490
- if (selectorEl?.contains(target)) return;
491
- closeDropdown();
492
- };
493
- const positionDropdown = (e2) => {
494
- if (e2?.type === "scroll" && e2.target && dropdownRef.value?.contains(e2.target)) return;
495
- if (!rootRef.value) return;
496
- const rect = rootRef.value.getBoundingClientRect();
497
- dropdownStyle.value = {
498
- top: `${rect.bottom + globalThis.scrollY + 8}px`,
499
- left: `${rect.left + globalThis.scrollX}px`,
500
- width: `${rect.width}px`
501
- };
502
- };
503
- const scrollFocusedIntoView = () => {
504
- vue.nextTick(() => {
505
- const list = dropdownRef.value?.lastElementChild;
506
- const option = list?.children[focusedIndex.value];
507
- if (!list || !option) return;
508
- const listRect = list.getBoundingClientRect();
509
- const optionRect = option.getBoundingClientRect();
510
- let scrollAmount = 0;
511
- if (optionRect.top < listRect.top) {
512
- scrollAmount = list.scrollTop - (listRect.top - optionRect.top);
513
- } else if (optionRect.bottom > listRect.bottom) {
514
- scrollAmount = list.scrollTop + (optionRect.bottom - listRect.bottom);
515
- } else {
516
- return;
517
- }
518
- list.scrollTo({ top: scrollAmount, behavior: "smooth" });
519
- });
520
- };
521
- const handleSearchKeydown = (e2) => {
522
- if (e2.key === "ArrowDown") {
523
- e2.preventDefault();
524
- setFocusedIndex(Math.min(focusedIndex.value + 1, filteredCountries.value.length - 1));
525
- scrollFocusedIntoView();
526
- } else if (e2.key === "ArrowUp") {
527
- e2.preventDefault();
528
- setFocusedIndex(Math.max(focusedIndex.value - 1, 0));
529
- scrollFocusedIntoView();
530
- } else if (e2.key === "Enter" && filteredCountries.value[focusedIndex.value]) {
531
- e2.preventDefault();
532
- selectCountry(filteredCountries.value[focusedIndex.value].id);
533
- } else if (e2.key === "Escape") {
534
- closeDropdown();
535
- }
536
- };
537
- const removeListeners = () => {
538
- globalThis.removeEventListener("resize", positionDropdown);
539
- globalThis.removeEventListener("scroll", positionDropdown, true);
540
- globalThis.removeEventListener("click", onDocClick, true);
541
- };
542
- vue.watch(hasDropdown, (dropdownExists) => {
543
- if (!dropdownExists && dropdownOpen.value) {
544
- closeDropdown();
545
- }
546
- });
547
- vue.watch(dropdownOpen, (isOpen) => {
548
- if (!isOpen) {
549
- removeListeners();
550
- return;
551
- }
552
- positionDropdown();
553
- globalThis.addEventListener("resize", positionDropdown);
554
- globalThis.addEventListener("scroll", positionDropdown, true);
555
- globalThis.addEventListener("click", onDocClick, true);
556
- });
557
- vue.onBeforeUnmount(removeListeners);
558
- return {
559
- // State
560
- dropdownOpen,
561
- search,
562
- focusedIndex,
563
- dropdownStyle,
564
- // Derived
565
- filteredCountries,
566
- hasDropdown,
567
- // Actions
568
- openDropdown,
569
- closeDropdown,
570
- toggleDropdown,
571
- selectCountry,
572
- setFocusedIndex,
573
- handleSearchChange,
574
- handleSearchKeydown
575
- };
576
- }
577
- function useClipboard(delay = 1800) {
578
- const copied = vue.ref(false);
579
- const isCopying = vue.ref(false);
580
- const copyTimer = useTimer();
581
- const copy = async (text) => {
582
- if (isCopying.value) return false;
583
- const trimmedText = text.trim();
584
- if (!trimmedText) return false;
585
- isCopying.value = true;
586
- try {
587
- await navigator.clipboard.writeText(trimmedText);
588
- copied.value = true;
589
- copyTimer.set(() => {
590
- copied.value = false;
591
- }, delay);
592
- return true;
593
- } catch (err) {
594
- console.warn("Copy failed", err);
595
- return false;
596
- } finally {
597
- isCopying.value = false;
598
- }
599
- };
600
- return { copied, isCopying, copy };
601
- }
602
- const DELAY = 1800;
603
- function useCopyAction({ liveRef, fullFormatted, onCopy }) {
604
- const liveTimer = useTimer();
605
- const { copied, copy } = useClipboard(DELAY);
606
- const copyAriaLabel = vue.computed(() => copied.value ? "Copied" : `Copy ${fullFormatted.value}`);
607
- const copyButtonTitle = vue.computed(() => copied.value ? "Copied" : "Copy phone number");
608
- const announceToScreenReader = (message) => {
609
- if (!liveRef?.value) return;
610
- liveRef.value.textContent = message;
611
- liveTimer.set(() => {
612
- if (liveRef.value) liveRef.value.textContent = "";
613
- }, DELAY);
614
- };
615
- const onCopyClick = async () => {
616
- const valueToCopy = fullFormatted.value.trim();
617
- const success = await copy(valueToCopy);
618
- if (success) {
619
- onCopy?.(valueToCopy);
620
- announceToScreenReader("Phone number copied to clipboard");
621
- }
622
- };
623
- return {
624
- copied,
625
- copyAriaLabel,
626
- copyButtonTitle,
627
- onCopyClick
628
- };
629
- }
630
- function useTheme({ theme }) {
631
- const systemDark = vue.ref(false);
632
- const themeClass = vue.computed(() => {
633
- const resolvedTheme = vue.toValue(theme);
634
- if (resolvedTheme === "auto") {
635
- return systemDark.value ? "theme-dark" : "theme-light";
636
- }
637
- return `theme-${resolvedTheme}`;
638
- });
639
- let mq = null;
640
- const handler = (e2) => {
641
- systemDark.value = e2.matches;
642
- };
643
- vue.onBeforeMount(() => {
644
- mq = globalThis.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
645
- if (!mq) return;
646
- systemDark.value = mq.matches;
647
- mq.addEventListener("change", handler);
648
- });
649
- vue.onBeforeUnmount(() => {
650
- mq?.removeEventListener("change", handler);
651
- });
652
- return {
653
- themeClass
654
- };
655
- }
656
- const _hoisted_1 = ["disabled", "tabindex", "aria-label", "aria-expanded", "aria-haspopup"];
657
- const _hoisted_2 = ["aria-label"];
658
- const _hoisted_3 = { class: "pi-code" };
659
- const _hoisted_4 = { class: "pi-input-wrap" };
660
- const _hoisted_5 = ["placeholder", "value", "disabled", "readonly", "aria-invalid"];
661
- const _hoisted_6 = {
662
- class: "pi-actions",
663
- role: "toolbar",
664
- "aria-label": "Phone input actions"
665
- };
666
- const _hoisted_7 = ["aria-label", "title"];
667
- const _hoisted_8 = {
668
- key: 1,
669
- width: "16",
670
- height: "16",
671
- viewBox: "0 0 16 16",
672
- fill: "none",
673
- "aria-hidden": "true"
674
- };
675
- const _hoisted_9 = {
676
- key: 2,
677
- width: "16",
678
- height: "16",
679
- viewBox: "0 0 16 16",
680
- fill: "none",
681
- "aria-hidden": "true"
682
- };
683
- const _hoisted_10 = ["aria-label", "title"];
684
- const _hoisted_11 = {
685
- key: 0,
686
- width: "11",
687
- height: "11",
688
- viewBox: "0 0 14 14",
689
- fill: "none",
690
- "aria-hidden": "true"
691
- };
692
- const _hoisted_12 = { class: "pi-search-wrap" };
693
- const _hoisted_13 = ["value", "aria-activedescendant", "placeholder"];
694
- const _hoisted_14 = ["id", "aria-selected", "title", "onClick", "onMouseenter"];
695
- const _hoisted_15 = ["aria-label"];
696
- const _hoisted_16 = { class: "pi-opt-name" };
697
- const _hoisted_17 = { class: "pi-opt-code" };
698
- const _hoisted_18 = {
699
- key: 0,
700
- class: "pi-empty"
701
- };
702
- const _sfc_main = /* @__PURE__ */ vue.defineComponent({
703
- __name: "PhoneInput",
704
- props: /* @__PURE__ */ vue.mergeModels({
705
- country: {},
706
- detect: { type: Boolean, default: true },
707
- locale: {},
708
- size: { default: "normal" },
709
- theme: { default: "auto" },
710
- disabled: { type: Boolean, default: false },
711
- readonly: { type: Boolean, default: false },
712
- showCopy: { type: Boolean, default: true },
713
- showClear: { type: Boolean, default: false },
714
- withValidity: { type: Boolean, default: true },
715
- searchPlaceholder: { default: "Search country or code..." },
716
- noResultsText: { default: "No countries found" },
717
- clearButtonLabel: { default: "Clear phone number" },
718
- dropdownClass: {},
719
- disableDefaultStyles: { type: Boolean, default: false }
720
- }, {
721
- "modelValue": { default: "" },
722
- "modelModifiers": {}
723
- }),
724
- emits: /* @__PURE__ */ vue.mergeModels(["change", "country-change", "validation-change", "focus", "blur", "copy", "clear"], ["update:modelValue"]),
725
- setup(__props, { expose: __expose, emit: __emit }) {
726
- const props = __props;
727
- const slots = vue.useSlots();
728
- const emit = __emit;
729
- const model = vue.useModel(__props, "modelValue");
730
- const onChange = (v) => {
731
- model.value = v;
732
- };
733
- const { country, setCountry: setCountry2, locale } = useCountry({
734
- country: () => props.country,
735
- locale: () => props.locale,
736
- detect: () => props.detect,
737
- onCountryChange: (c) => emit("country-change", c)
738
- });
739
- const {
740
- digits,
741
- formatter,
742
- displayPlaceholder,
743
- displayValue,
744
- full,
745
- fullFormatted,
746
- isComplete,
747
- isEmpty,
748
- shouldShowWarn
749
- } = useFormatter({
750
- country,
751
- value: model,
752
- onChange,
753
- onPhoneChange: (data) => emit("change", data),
754
- onValidationChange: (complete) => emit("validation-change", complete)
755
- });
756
- const { showValidationHint, clearValidationHint, scheduleValidationHint } = useValidationHint();
757
- const rootRef = vue.useTemplateRef("rootRef");
758
- const telRef = vue.useTemplateRef("telRef");
759
- const liveRef = vue.useTemplateRef("liveRef");
760
- const dropdownRef = vue.useTemplateRef("dropdownRef");
761
- const searchRef = vue.useTemplateRef("searchRef");
762
- const selectorRef = vue.useTemplateRef("selectorRef");
763
- const dropdownId = vue.getCurrentInstance()?.uid ?? 0;
764
- const listboxId = `pi-options-${dropdownId}`;
765
- const getOptionId = (idx) => `pi-option-${dropdownId}-${idx}`;
766
- const inactive = vue.computed(() => props.disabled || props.readonly);
767
- const incomplete = vue.computed(() => showValidationHint.value && shouldShowWarn.value);
768
- const showCopyButton = vue.computed(() => props.showCopy && !isEmpty.value && !props.disabled);
769
- const showClearButton = vue.computed(() => props.showClear && !isEmpty.value && !inactive.value);
770
- const { copied, copyAriaLabel, copyButtonTitle, onCopyClick } = useCopyAction({
771
- liveRef,
772
- fullFormatted,
773
- onCopy: (v) => emit("copy", v)
774
- });
775
- const focusInput = () => vue.nextTick(() => telRef.value?.focus());
776
- const {
777
- dropdownOpen,
778
- search,
779
- focusedIndex,
780
- dropdownStyle,
781
- filteredCountries,
782
- hasDropdown,
783
- closeDropdown,
784
- toggleDropdown,
785
- selectCountry,
786
- setFocusedIndex,
787
- handleSearchChange,
788
- handleSearchKeydown
789
- } = useCountrySelector({
790
- rootRef,
791
- dropdownRef,
792
- searchRef,
793
- selectorRef,
794
- locale,
795
- countryOption: () => props.country,
796
- inactive,
797
- onSelectCountry: setCountry2,
798
- onAfterSelect: focusInput
799
- });
800
- const activeOptionId = vue.computed(
801
- () => dropdownOpen.value && filteredCountries.value[focusedIndex.value] ? getOptionId(focusedIndex.value) : void 0
802
- );
803
- const { handleBeforeInput, handleInput, handleKeydown, handlePaste } = useInputHandlers({
804
- formatter,
805
- digits,
806
- inactive,
807
- onChange,
808
- scheduleValidationHint
809
- });
810
- const handleFocus = (e2) => {
811
- clearValidationHint(false);
812
- closeDropdown();
813
- emit("focus", e2);
814
- };
815
- const handleBlur = (e2) => emit("blur", e2);
816
- const clear = () => {
817
- onChange("");
818
- clearValidationHint();
819
- emit("clear");
820
- };
821
- const onClearClick = () => {
822
- clear();
823
- focusInput();
824
- };
825
- __expose({
826
- focus: focusInput,
827
- blur: () => telRef.value?.blur(),
828
- clear,
829
- selectCountry,
830
- getFullNumber: () => full.value,
831
- getFullFormattedNumber: () => fullFormatted.value,
832
- getDigits: () => digits.value,
833
- isValid: () => isComplete.value,
834
- isComplete: () => isComplete.value
835
- });
836
- const { themeClass } = useTheme({
837
- theme: () => props.theme
838
- });
839
- const rootClasses = vue.computed(() => [
840
- "phone-input",
841
- `size-${props.size}`,
842
- themeClass.value,
843
- {
844
- "is-disabled": props.disabled,
845
- "is-readonly": props.readonly,
846
- "is-unstyled": props.disableDefaultStyles,
847
- "is-incomplete": props.withValidity && incomplete.value,
848
- "is-complete": props.withValidity && isComplete.value
849
- }
850
- ]);
851
- const rootStyles = vue.computed(() => ({
852
- "--pi-actions-count": +showCopyButton.value + +showClearButton.value + (slots["actions-before"] ? 1 : 0)
853
- }));
854
- return (_ctx, _cache) => {
855
- return vue.openBlock(), vue.createElementBlock("div", {
856
- ref_key: "rootRef",
857
- ref: rootRef,
858
- "aria-label": "Phone input with country selector",
859
- role: "group",
860
- class: vue.normalizeClass(rootClasses.value),
861
- style: vue.normalizeStyle(rootStyles.value)
862
- }, [
863
- vue.createElementVNode("div", {
864
- ref_key: "selectorRef",
865
- ref: selectorRef,
866
- class: "pi-selector"
867
- }, [
868
- vue.createElementVNode("button", {
869
- type: "button",
870
- class: vue.normalizeClass(["pi-selector-btn", { "no-dropdown": !vue.unref(hasDropdown) || __props.readonly }]),
871
- disabled: __props.disabled,
872
- tabindex: inactive.value || !vue.unref(hasDropdown) ? -1 : void 0,
873
- "aria-label": `Selected country: ${vue.unref(country).name}`,
874
- "aria-expanded": vue.unref(dropdownOpen),
875
- "aria-haspopup": vue.unref(hasDropdown) ? "listbox" : void 0,
876
- onClick: _cache[0] || (_cache[0] = //@ts-ignore
877
- (...args) => vue.unref(toggleDropdown) && vue.unref(toggleDropdown)(...args))
878
- }, [
879
- vue.createElementVNode("span", {
880
- class: "pi-flag",
881
- role: "img",
882
- "aria-label": `${vue.unref(country).name} flag`
883
- }, [
884
- vue.renderSlot(_ctx.$slots, "flag", { country: vue.unref(country) }, () => [
885
- vue.createTextVNode(vue.toDisplayString(vue.unref(country).flag), 1)
886
- ], true)
887
- ], 8, _hoisted_2),
888
- vue.createElementVNode("span", _hoisted_3, vue.toDisplayString(vue.unref(country).code), 1),
889
- !inactive.value && vue.unref(hasDropdown) ? (vue.openBlock(), vue.createElementBlock("svg", {
890
- key: 0,
891
- class: vue.normalizeClass(["pi-chevron", { "is-open": vue.unref(dropdownOpen) }]),
892
- width: "12",
893
- height: "12",
894
- viewBox: "0 0 12 12",
895
- fill: "none",
896
- "aria-hidden": "true"
897
- }, [..._cache[8] || (_cache[8] = [
898
- vue.createElementVNode("path", {
899
- d: "M2.5 4.5L6 8L9.5 4.5",
900
- stroke: "currentColor",
901
- "stroke-width": "1.5",
902
- "stroke-linecap": "round",
903
- "stroke-linejoin": "round"
904
- }, null, -1)
905
- ])], 2)) : vue.createCommentVNode("", true)
906
- ], 10, _hoisted_1)
907
- ], 512),
908
- vue.createElementVNode("div", _hoisted_4, [
909
- vue.createElementVNode("input", {
910
- ref_key: "telRef",
911
- ref: telRef,
912
- type: "tel",
913
- inputmode: "tel",
914
- autocomplete: "tel-national",
915
- autocorrect: "off",
916
- autocapitalize: "off",
917
- spellcheck: "false",
918
- class: "pi-input",
919
- placeholder: vue.unref(displayPlaceholder),
920
- value: vue.unref(displayValue),
921
- disabled: __props.disabled,
922
- readonly: __props.readonly,
923
- "aria-invalid": incomplete.value,
924
- onBeforeinput: _cache[1] || (_cache[1] = //@ts-ignore
925
- (...args) => vue.unref(handleBeforeInput) && vue.unref(handleBeforeInput)(...args)),
926
- onInput: _cache[2] || (_cache[2] = //@ts-ignore
927
- (...args) => vue.unref(handleInput) && vue.unref(handleInput)(...args)),
928
- onKeydown: _cache[3] || (_cache[3] = //@ts-ignore
929
- (...args) => vue.unref(handleKeydown) && vue.unref(handleKeydown)(...args)),
930
- onPaste: _cache[4] || (_cache[4] = //@ts-ignore
931
- (...args) => vue.unref(handlePaste) && vue.unref(handlePaste)(...args)),
932
- onFocus: handleFocus,
933
- onBlur: handleBlur
934
- }, null, 40, _hoisted_5),
935
- vue.createElementVNode("div", _hoisted_6, [
936
- vue.createVNode(vue.Transition, { name: "fade-scale" }, {
937
- default: vue.withCtx(() => [
938
- vue.renderSlot(_ctx.$slots, "actions-before", {}, void 0, true)
939
- ]),
940
- _: 3
941
- }),
942
- vue.createVNode(vue.Transition, { name: "fade-scale" }, {
943
- default: vue.withCtx(() => [
944
- showCopyButton.value ? (vue.openBlock(), vue.createElementBlock("button", {
945
- key: 0,
946
- type: "button",
947
- class: vue.normalizeClass(["pi-btn", "pi-btn-copy", { "is-copied": vue.unref(copied) }]),
948
- "aria-label": vue.unref(copyAriaLabel),
949
- title: vue.unref(copyButtonTitle),
950
- onClick: _cache[5] || (_cache[5] = //@ts-ignore
951
- (...args) => vue.unref(onCopyClick) && vue.unref(onCopyClick)(...args))
952
- }, [
953
- slots["copy-svg"] ? vue.renderSlot(_ctx.$slots, "copy-svg", {
954
- key: 0,
955
- copied: vue.unref(copied)
956
- }, void 0, true) : !vue.unref(copied) ? (vue.openBlock(), vue.createElementBlock("svg", _hoisted_8, [..._cache[9] || (_cache[9] = [
957
- vue.createElementVNode("path", {
958
- d: "M13.5 5.5V13.5H5.5V5.5H13.5ZM13.5 4H5.5C4.67 4 4 4.67 4 5.5V13.5C4 14.33 4.67 15 5.5 15H13.5C14.33 15 15 14.33 15 13.5V5.5C15 4.67 14.33 4 13.5 4ZM10.5 1H2.5V11H4V2.5H10.5V1Z",
959
- fill: "currentColor"
960
- }, null, -1)
961
- ])])) : (vue.openBlock(), vue.createElementBlock("svg", _hoisted_9, [..._cache[10] || (_cache[10] = [
962
- vue.createElementVNode("path", {
963
- d: "M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z",
964
- fill: "currentColor"
965
- }, null, -1)
966
- ])]))
967
- ], 10, _hoisted_7)) : vue.createCommentVNode("", true)
968
- ]),
969
- _: 3
970
- }),
971
- vue.createVNode(vue.Transition, { name: "fade-scale" }, {
972
- default: vue.withCtx(() => [
973
- showClearButton.value ? (vue.openBlock(), vue.createElementBlock("button", {
974
- key: 0,
975
- type: "button",
976
- class: "pi-btn pi-btn-clear",
977
- "aria-label": __props.clearButtonLabel,
978
- title: __props.clearButtonLabel,
979
- onClick: onClearClick
980
- }, [
981
- !slots["clear-svg"] ? (vue.openBlock(), vue.createElementBlock("svg", _hoisted_11, [..._cache[11] || (_cache[11] = [
982
- vue.createElementVNode("path", {
983
- d: "M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z",
984
- fill: "currentColor"
985
- }, null, -1)
986
- ])])) : vue.renderSlot(_ctx.$slots, "clear-svg", { key: 1 }, void 0, true)
987
- ], 8, _hoisted_10)) : vue.createCommentVNode("", true)
988
- ]),
989
- _: 3
990
- })
991
- ])
992
- ]),
993
- (vue.openBlock(), vue.createBlock(vue.Teleport, { to: "body" }, [
994
- vue.createVNode(vue.Transition, { name: "dropdown" }, {
995
- default: vue.withCtx(() => [
996
- vue.unref(dropdownOpen) ? (vue.openBlock(), vue.createElementBlock("div", {
997
- key: 0,
998
- ref_key: "dropdownRef",
999
- ref: dropdownRef,
1000
- class: vue.normalizeClass(["phone-dropdown", [__props.dropdownClass, vue.unref(themeClass)]]),
1001
- role: "dialog",
1002
- "aria-modal": "false",
1003
- "aria-label": "Select country",
1004
- style: vue.normalizeStyle(vue.unref(dropdownStyle))
1005
- }, [
1006
- vue.createElementVNode("div", _hoisted_12, [
1007
- vue.createElementVNode("input", {
1008
- ref_key: "searchRef",
1009
- ref: searchRef,
1010
- value: vue.unref(search),
1011
- type: "search",
1012
- class: "pi-search",
1013
- "aria-label": "Search countries",
1014
- "aria-controls": listboxId,
1015
- "aria-activedescendant": activeOptionId.value,
1016
- placeholder: __props.searchPlaceholder,
1017
- onKeydown: _cache[6] || (_cache[6] = //@ts-ignore
1018
- (...args) => vue.unref(handleSearchKeydown) && vue.unref(handleSearchKeydown)(...args)),
1019
- onInput: _cache[7] || (_cache[7] = //@ts-ignore
1020
- (...args) => vue.unref(handleSearchChange) && vue.unref(handleSearchChange)(...args))
1021
- }, null, 40, _hoisted_13)
1022
- ]),
1023
- vue.createElementVNode("ul", {
1024
- id: listboxId,
1025
- class: "pi-options",
1026
- role: "listbox",
1027
- tabindex: "-1"
1028
- }, [
1029
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(filteredCountries), (c, idx) => {
1030
- return vue.openBlock(), vue.createElementBlock("li", {
1031
- id: getOptionId(idx),
1032
- key: c.id,
1033
- role: "option",
1034
- class: vue.normalizeClass([
1035
- "pi-option",
1036
- {
1037
- "is-focused": idx === vue.unref(focusedIndex),
1038
- "is-selected": c.id === vue.unref(country).id
1039
- }
1040
- ]),
1041
- "aria-selected": c.id === vue.unref(country).id,
1042
- title: c.name,
1043
- onClick: ($event) => vue.unref(selectCountry)(c.id),
1044
- onMouseenter: ($event) => vue.unref(setFocusedIndex)(idx)
1045
- }, [
1046
- vue.createElementVNode("span", {
1047
- class: "pi-flag",
1048
- role: "img",
1049
- "aria-label": `${c.name} flag`
1050
- }, [
1051
- vue.renderSlot(_ctx.$slots, "flag", { country: c }, () => [
1052
- vue.createTextVNode(vue.toDisplayString(c.flag), 1)
1053
- ], true)
1054
- ], 8, _hoisted_15),
1055
- vue.createElementVNode("span", _hoisted_16, vue.toDisplayString(c.name), 1),
1056
- vue.createElementVNode("span", _hoisted_17, vue.toDisplayString(c.code), 1)
1057
- ], 42, _hoisted_14);
1058
- }), 128)),
1059
- vue.unref(filteredCountries).length === 0 ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_18, vue.toDisplayString(__props.noResultsText), 1)) : vue.createCommentVNode("", true)
1060
- ])
1061
- ], 6)) : vue.createCommentVNode("", true)
1062
- ]),
1063
- _: 3
1064
- })
1065
- ])),
1066
- vue.createElementVNode("div", {
1067
- ref_key: "liveRef",
1068
- ref: liveRef,
1069
- class: "sr-only",
1070
- role: "status",
1071
- "aria-live": "polite",
1072
- "aria-atomic": "true"
1073
- }, null, 512)
1074
- ], 6);
1075
- };
1076
- }
1077
- });
1078
- const _export_sfc = (sfc, props) => {
1079
- const target = sfc.__vccOpts || sfc;
1080
- for (const [key, val] of props) {
1081
- target[key] = val;
1082
- }
1083
- return target;
1084
- };
1085
- const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d730aa54"]]);
1086
- function parseParams(params) {
1087
- if (typeof params === "string") return { country: params };
1088
- if (params && typeof params === "object") return params;
1089
- return {};
1090
- }
1091
- function updateDigits(el, state, digits) {
1092
- state.digits = digits;
1093
- el.value = state.formatter.formatDisplay(state.digits);
1094
- if (state.options.onChange) {
1095
- const fullNumberFormatted = el.value ? `${state.country.code} ${el.value}` : "";
1096
- const fullNumber = state.digits ? `${state.country.code}${state.digits}` : "";
1097
- state.options.onChange({
1098
- full: fullNumber,
1099
- fullFormatted: fullNumberFormatted,
1100
- digits: state.digits
1101
- });
1102
- }
1103
- }
1104
- function checkDigitsUpdate(el, state) {
1105
- const maxDigits = state.formatter.getMaxDigits();
1106
- const digits = extractDigits(el.value, maxDigits);
1107
- const displayValue = state.formatter.formatDisplay(digits);
1108
- if (digits !== state.digits || el.value !== displayValue) {
1109
- updateDigits(el, state, digits);
1110
- }
1111
- }
1112
- function checkCountryUpdate(el, state) {
1113
- const oldCountry = state.country.id;
1114
- const newCountry = parseCountryCode(state.options.country);
1115
- if (newCountry && newCountry !== oldCountry) {
1116
- setCountry(el, state, newCountry);
1117
- }
1118
- }
1119
- function createHandler(el, state, handler) {
1120
- return (e2) => {
1121
- const result = handler(e2, state);
1122
- if (!result) return;
1123
- updateDigits(el, state, result.newDigits);
1124
- vue.nextTick(() => {
1125
- const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
1126
- setCaret(el, pos);
1127
- });
1128
- };
1129
- }
1130
- async function detectInitialCountry(options) {
1131
- const countryOption = parseCountryCode(options.country);
1132
- if (countryOption) return countryOption;
1133
- if (options.detect) {
1134
- const geoCountry = parseCountryCode(await detectByGeoIp());
1135
- if (geoCountry) return geoCountry;
1136
- const localeCountry = parseCountryCode(detectCountryFromLocale());
1137
- if (localeCountry) return localeCountry;
1138
- }
1139
- return "US";
1140
- }
1141
- function setCountry(el, state, newCountryCode) {
1142
- const parsed = parseCountryCode(newCountryCode);
1143
- if (!parsed) return;
1144
- const newCountry = getCountry(parsed, state.locale);
1145
- state.country = newCountry;
1146
- state.options.onCountryChange?.(newCountry);
1147
- state.formatter = createPhoneFormatter(newCountry);
1148
- el.placeholder = state.formatter.getPlaceholder();
1149
- checkDigitsUpdate(el, state);
1150
- }
1151
- const vPhoneMask = {
1152
- mounted(el, binding) {
1153
- if (el.tagName !== "INPUT") {
1154
- console.warn("[v-phone-mask] Directive can only be used on input elements");
1155
- return;
1156
- }
1157
- el.setAttribute("type", "tel");
1158
- el.setAttribute("inputmode", "tel");
1159
- el.setAttribute("placeholder", "");
1160
- const options = parseParams(binding.value);
1161
- const locale = options.locale || getNavigatorLang();
1162
- const country = getCountry(parseCountryCode(options.country, "US"), locale);
1163
- const state = {
1164
- country,
1165
- formatter: createPhoneFormatter(country),
1166
- digits: "",
1167
- locale,
1168
- options
1169
- };
1170
- el.__phoneMaskState = state;
1171
- state.inputHandler = createHandler(el, state, processInput);
1172
- state.keydownHandler = createHandler(el, state, processKeydown);
1173
- state.pasteHandler = createHandler(el, state, processPaste);
1174
- state.beforeInputHandler = processBeforeInput;
1175
- el.addEventListener("beforeinput", state.beforeInputHandler);
1176
- el.addEventListener("input", state.inputHandler);
1177
- el.addEventListener("keydown", state.keydownHandler);
1178
- el.addEventListener("paste", state.pasteHandler);
1179
- detectInitialCountry(options).then((countryCode) => {
1180
- if (el.__phoneMaskState !== state) return;
1181
- setCountry(el, state, countryCode);
1182
- });
1183
- },
1184
- updated(el, binding) {
1185
- const state = el.__phoneMaskState;
1186
- if (!state) return;
1187
- state.options = parseParams(binding.value);
1188
- checkCountryUpdate(el, state);
1189
- checkDigitsUpdate(el, state);
1190
- },
1191
- unmounted(el) {
1192
- const state = el.__phoneMaskState;
1193
- if (!state) return;
1194
- if (state.beforeInputHandler) el.removeEventListener("beforeinput", state.beforeInputHandler);
1195
- if (state.inputHandler) el.removeEventListener("input", state.inputHandler);
1196
- if (state.keydownHandler) el.removeEventListener("keydown", state.keydownHandler);
1197
- if (state.pasteHandler) el.removeEventListener("paste", state.pasteHandler);
1198
- delete el.__phoneMaskState;
1199
- }
1200
- };
1201
- function usePhoneMask(options) {
1202
- const inputRef = vue.shallowRef(null);
1203
- const { country, setCountry: setCountry2 } = useCountry({
1204
- country: options.country,
1205
- locale: options.locale,
1206
- detect: options.detect,
1207
- onCountryChange: options.onCountryChange
1208
- });
1209
- const {
1210
- digits,
1211
- formatter,
1212
- displayPlaceholder,
1213
- displayValue,
1214
- full,
1215
- fullFormatted,
1216
- isComplete,
1217
- isEmpty,
1218
- shouldShowWarn
1219
- } = useFormatter({
1220
- country,
1221
- value: options.value,
1222
- onChange: options.onChange,
1223
- onPhoneChange: options.onPhoneChange
1224
- });
1225
- const { handleBeforeInput, handleInput, handleKeydown, handlePaste } = useInputHandlers({
1226
- formatter,
1227
- digits,
1228
- onChange: options.onChange
1229
- });
1230
- vue.onMounted(() => {
1231
- const el = inputRef.value;
1232
- if (!el) return;
1233
- el.setAttribute("type", "tel");
1234
- el.setAttribute("inputmode", "tel");
1235
- });
1236
- vue.watchEffect(
1237
- () => {
1238
- const el = inputRef.value;
1239
- if (!el) return;
1240
- el.value = displayValue.value;
1241
- el.setAttribute("placeholder", displayPlaceholder.value);
1242
- },
1243
- { flush: "post" }
1244
- );
1245
- vue.onMounted(() => {
1246
- const el = inputRef.value;
1247
- if (!el) return;
1248
- el.addEventListener("beforeinput", handleBeforeInput);
1249
- el.addEventListener("input", handleInput);
1250
- el.addEventListener("keydown", handleKeydown);
1251
- el.addEventListener("paste", handlePaste);
1252
- });
1253
- vue.onUnmounted(() => {
1254
- const el = inputRef.value;
1255
- if (!el) return;
1256
- el.removeEventListener("beforeinput", handleBeforeInput);
1257
- el.removeEventListener("input", handleInput);
1258
- el.removeEventListener("keydown", handleKeydown);
1259
- el.removeEventListener("paste", handlePaste);
1260
- });
1261
- const clear = () => {
1262
- options.onChange("");
1263
- };
1264
- return {
1265
- inputRef,
1266
- digits,
1267
- formatter,
1268
- full,
1269
- fullFormatted,
1270
- isComplete,
1271
- isEmpty,
1272
- shouldShowWarn,
1273
- country,
1274
- setCountry: setCountry2,
1275
- clear
1276
- };
1277
- }
1278
- function install(app) {
1279
- app.component("PhoneInput", PhoneInput);
1280
- app.directive("phone-mask", vPhoneMask);
1281
- }
1282
- const index = {
1283
- install
1284
- };
1285
- const PMaskHelpers = {
1286
- getFlagEmoji: k,
1287
- countPlaceholders,
1288
- formatDigitsWithMap,
1289
- pickMaskVariant,
1290
- removeCountryCodePrefix,
1291
- toArray
1292
- };
1293
- exports.PMaskHelpers = PMaskHelpers;
1294
- exports.PhoneInput = PhoneInput;
1295
- exports.default = index;
1296
- exports.install = install;
1297
- exports.usePhoneMask = usePhoneMask;
1298
- exports.vPhoneMask = vPhoneMask;
1299
- exports.vPhoneMaskSetCountry = setCountry;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@desource/phone-mask`),t=require(`vue`);function n({country:n,locale:r,detect:i,onCountryChange:a}={}){let o=(0,t.computed)(()=>(0,t.toValue)(r)||(0,e.getNavigatorLang)()),s=(0,t.ref)((0,e.parseCountryCode)((0,t.toValue)(n),`US`)),c=(0,t.computed)(()=>(0,e.getCountry)(s.value,o.value)),l=t=>{let n=(0,e.parseCountryCode)(t);return n?(s.value=n,!0):!1},u=async()=>{l(await(0,e.detectByGeoIp)())||l((0,e.detectCountryFromLocale)())};return(0,t.watchEffect)(()=>{let e=(0,t.toValue)(n);e&&e!==s.value&&l(e)}),(0,t.watchEffect)(()=>{(0,t.toValue)(i)&&!(0,t.toValue)(n)&&u()}),(0,t.watchEffect)(()=>{a?.(c.value)}),{country:c,setCountry:l,locale:o}}function r({country:n,value:r,onChange:i,onPhoneChange:a,onValidationChange:o}){let s=(0,t.computed)(()=>(0,e.createPhoneFormatter)((0,t.toValue)(n))),c=(0,t.computed)(()=>s.value.getMaxDigits()),l=(0,t.computed)(()=>(0,e.extractDigits)((0,t.toValue)(r),c.value)),u=(0,t.computed)(()=>s.value.getPlaceholder()),d=(0,t.computed)(()=>s.value.formatDisplay(l.value)),f=(0,t.computed)(()=>l.value?`${(0,t.toValue)(n).code}${l.value}`:``),p=(0,t.computed)(()=>d.value?`${(0,t.toValue)(n).code} ${d.value}`:``),m=(0,t.computed)(()=>s.value.isComplete(l.value)),h=(0,t.computed)(()=>l.value.length===0),g=(0,t.computed)(()=>!h.value&&!m.value),_=(0,t.computed)(()=>({full:f.value,fullFormatted:p.value,digits:l.value}));return(0,t.watchEffect)(()=>{(0,t.toValue)(r)!==l.value&&i(l.value)}),(0,t.watchEffect)(()=>{a?.(_.value)}),(0,t.watchEffect)(()=>{o?.(m.value)}),{digits:l,formatter:s,displayPlaceholder:u,displayValue:d,full:f,fullFormatted:p,isComplete:m,isEmpty:h,shouldShowWarn:g}}function i(){let e=null,n=()=>{e&&=(clearTimeout(e),null)};return(0,t.onUnmounted)(n),{set:(t,r)=>{n(),e=setTimeout(t,r)},clear:n}}function a(){let e=(0,t.ref)(!1),n=i();return{showValidationHint:e,clearValidationHint:(t=!0)=>{t&&(e.value=!1),n.clear()},scheduleValidationHint:t=>{e.value=!1,n.set(()=>{e.value=!0},t)}}}var o=500,s=300;function c(n){let{formatter:r,digits:i,inactive:a,onChange:c,scheduleValidationHint:l}=n,u=(n,i)=>{(0,t.nextTick)(()=>{n&&(0,e.setCaret)(n,(0,t.toValue)(r).getCaretPosition(i))})};return{handleBeforeInput:t=>{(0,e.processBeforeInput)(t)},handleInput:n=>{if((0,t.toValue)(a))return;let i=(0,e.processInput)(n,{formatter:(0,t.toValue)(r)});i&&(c?.(i.newDigits),u(n.target,i.caretDigitIndex),l?.(o))},handleKeydown:n=>{if((0,t.toValue)(a))return;let o=(0,e.processKeydown)(n,{digits:(0,t.toValue)(i),formatter:(0,t.toValue)(r)});o&&(c?.(o.newDigits),u(n.target,o.caretDigitIndex),l?.(s))},handlePaste:n=>{if((0,t.toValue)(a))return;let o=(0,e.processPaste)(n,{digits:(0,t.toValue)(i),formatter:(0,t.toValue)(r)});o&&(c?.(o.newDigits),u(n.target,o.caretDigitIndex),l?.(s))}}}function l({rootRef:n,dropdownRef:r,searchRef:i,selectorRef:a,locale:o,countryOption:s,inactive:c,onSelectCountry:l,onAfterSelect:u}){let d=(0,t.ref)(``),f=(0,t.ref)(!1),p=(0,t.shallowRef)({}),m=(0,t.ref)(0),h=(0,t.computed)(()=>(0,e.MasksFull)((0,t.toValue)(o))),g=(0,t.computed)(()=>(0,e.filterCountries)(h.value,d.value)),_=(0,t.computed)(()=>!(0,t.toValue)(s)&&h.value.length>1),v=e=>{m.value=e},y=()=>{(0,t.nextTick)(()=>i.value?.focus({preventScroll:!0}))},b=()=>{f.value=!1},x=()=>{f.value=!0,v(0),y()},ee=()=>{(0,t.toValue)(c)||!_.value||(f.value?b():x())},S=e=>{l(e),b(),d.value=``,v(0),u?.()},te=e=>{d.value=e.target.value,v(0)},C=e=>{let t=e.target,n=r.value,i=a.value;t&&(n?.contains(t)||i?.contains(t)||b())},w=e=>{if(e?.type===`scroll`&&e.target&&r.value?.contains(e.target)||!n.value)return;let t=n.value.getBoundingClientRect();p.value={top:`${t.bottom+globalThis.scrollY+8}px`,left:`${t.left+globalThis.scrollX}px`,width:`${t.width}px`}},T=()=>{(0,t.nextTick)(()=>{let e=r.value?.lastElementChild,t=e?.children[m.value];if(!e||!t)return;let n=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=0;if(i.top<n.top)a=e.scrollTop-(n.top-i.top);else if(i.bottom>n.bottom)a=e.scrollTop+(i.bottom-n.bottom);else return;e.scrollTo({top:a,behavior:`smooth`})})},ne=e=>{e.key===`ArrowDown`?(e.preventDefault(),v(Math.min(m.value+1,g.value.length-1)),T()):e.key===`ArrowUp`?(e.preventDefault(),v(Math.max(m.value-1,0)),T()):e.key===`Enter`&&g.value[m.value]?(e.preventDefault(),S(g.value[m.value].id)):e.key===`Escape`&&b()},E=()=>{globalThis.removeEventListener(`resize`,w),globalThis.removeEventListener(`scroll`,w,!0),globalThis.removeEventListener(`click`,C,!0)};return(0,t.watch)(_,e=>{!e&&f.value&&b()}),(0,t.watch)(f,e=>{if(!e){E();return}w(),globalThis.addEventListener(`resize`,w),globalThis.addEventListener(`scroll`,w,!0),globalThis.addEventListener(`click`,C,!0)}),(0,t.onBeforeUnmount)(E),{dropdownOpen:f,search:d,focusedIndex:m,dropdownStyle:p,filteredCountries:g,hasDropdown:_,openDropdown:x,closeDropdown:b,toggleDropdown:ee,selectCountry:S,setFocusedIndex:v,handleSearchChange:te,handleSearchKeydown:ne}}function u(e=1800){let n=(0,t.ref)(!1),r=(0,t.ref)(!1),a=i();return{copied:n,isCopying:r,copy:async t=>{if(r.value)return!1;let i=t.trim();if(!i)return!1;r.value=!0;try{return await navigator.clipboard.writeText(i),n.value=!0,a.set(()=>{n.value=!1},e),!0}catch(e){return console.warn(`Copy failed`,e),!1}finally{r.value=!1}}}}var d=1800;function f({liveRef:e,fullFormatted:n,onCopy:r}){let a=i(),{copied:o,copy:s}=u(d),c=(0,t.computed)(()=>o.value?`Copied`:`Copy ${n.value}`),l=(0,t.computed)(()=>o.value?`Copied`:`Copy phone number`),f=t=>{e?.value&&(e.value.textContent=t,a.set(()=>{e.value&&(e.value.textContent=``)},d))};return{copied:o,copyAriaLabel:c,copyButtonTitle:l,onCopyClick:async()=>{let e=n.value.trim();await s(e)&&(r?.(e),f(`Phone number copied to clipboard`))}}}function p({theme:e}){let n=(0,t.ref)(!1),r=(0,t.computed)(()=>{let r=(0,t.toValue)(e);return r===`auto`?n.value?`theme-dark`:`theme-light`:`theme-${r}`}),i=null,a=e=>{n.value=e.matches};return(0,t.onBeforeMount)(()=>{i=globalThis.matchMedia?.(`(prefers-color-scheme: dark)`)??null,i&&(n.value=i.matches,i.addEventListener(`change`,a))}),(0,t.onBeforeUnmount)(()=>{i?.removeEventListener(`change`,a)}),{themeClass:r}}var m=[`disabled`,`tabindex`,`aria-label`,`aria-expanded`,`aria-haspopup`],h=[`aria-label`],g={class:`pi-code`},_={class:`pi-input-wrap`},v=[`placeholder`,`value`,`disabled`,`readonly`,`aria-invalid`],y={class:`pi-actions`,role:`toolbar`,"aria-label":`Phone input actions`},b=[`aria-label`,`title`],x={key:1,width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`},ee={key:2,width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`},S=[`aria-label`,`title`],te={key:0,width:`11`,height:`11`,viewBox:`0 0 14 14`,fill:`none`,"aria-hidden":`true`},C={class:`pi-search-wrap`},w=[`value`,`aria-activedescendant`,`placeholder`],T=[`id`,`aria-selected`,`title`,`onClick`,`onMouseenter`],ne=[`aria-label`],E={class:`pi-opt-name`},re={class:`pi-opt-code`},ie={key:0,class:`pi-empty`},D=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,t.defineComponent)({__name:`PhoneInput`,props:(0,t.mergeModels)({country:{},detect:{type:Boolean,default:!0},locale:{},size:{default:`normal`},theme:{default:`auto`},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},showCopy:{type:Boolean,default:!0},showClear:{type:Boolean,default:!1},withValidity:{type:Boolean,default:!0},searchPlaceholder:{default:`Search country or code...`},noResultsText:{default:`No countries found`},clearButtonLabel:{default:`Clear phone number`},dropdownClass:{},disableDefaultStyles:{type:Boolean,default:!1}},{modelValue:{default:``},modelModifiers:{}}),emits:(0,t.mergeModels)([`change`,`country-change`,`validation-change`,`focus`,`blur`,`copy`,`clear`],[`update:modelValue`]),setup(e,{expose:i,emit:o}){let s=e,u=(0,t.useSlots)(),d=o,D=(0,t.useModel)(e,`modelValue`),O=e=>{D.value=e},{country:k,setCountry:A,locale:ae}=n({country:()=>s.country,locale:()=>s.locale,detect:()=>s.detect,onCountryChange:e=>d(`country-change`,e)}),{digits:j,formatter:oe,displayPlaceholder:M,displayValue:N,full:se,fullFormatted:P,isComplete:F,isEmpty:I,shouldShowWarn:ce}=r({country:k,value:D,onChange:O,onPhoneChange:e=>d(`change`,e),onValidationChange:e=>d(`validation-change`,e)}),{showValidationHint:le,clearValidationHint:L,scheduleValidationHint:ue}=a(),R=(0,t.useTemplateRef)(`rootRef`),z=(0,t.useTemplateRef)(`telRef`),B=(0,t.useTemplateRef)(`liveRef`),V=(0,t.useTemplateRef)(`dropdownRef`),H=(0,t.useTemplateRef)(`searchRef`),U=(0,t.useTemplateRef)(`selectorRef`),W=(0,t.getCurrentInstance)()?.uid??0,G=`pi-options-${W}`,de=e=>`pi-option-${W}-${e}`,K=(0,t.computed)(()=>s.disabled||s.readonly),fe=(0,t.computed)(()=>le.value&&ce.value),pe=(0,t.computed)(()=>s.showCopy&&!I.value&&!s.disabled),me=(0,t.computed)(()=>s.showClear&&!I.value&&!K.value),{copied:q,copyAriaLabel:he,copyButtonTitle:ge,onCopyClick:_e}=f({liveRef:B,fullFormatted:P,onCopy:e=>d(`copy`,e)}),J=()=>(0,t.nextTick)(()=>z.value?.focus()),{dropdownOpen:Y,search:ve,focusedIndex:X,dropdownStyle:ye,filteredCountries:Z,hasDropdown:Q,closeDropdown:be,toggleDropdown:xe,selectCountry:Se,setFocusedIndex:Ce,handleSearchChange:$,handleSearchKeydown:we}=l({rootRef:R,dropdownRef:V,searchRef:H,selectorRef:U,locale:ae,countryOption:()=>s.country,inactive:K,onSelectCountry:A,onAfterSelect:J}),Te=(0,t.computed)(()=>Y.value&&Z.value[X.value]?de(X.value):void 0),{handleBeforeInput:Ee,handleInput:De,handleKeydown:Oe,handlePaste:ke}=c({formatter:oe,digits:j,inactive:K,onChange:O,scheduleValidationHint:ue}),Ae=e=>{L(!1),be(),d(`focus`,e)},je=e=>d(`blur`,e),Me=()=>{O(``),L(),d(`clear`)},Ne=()=>{Me(),J()};i({focus:J,blur:()=>z.value?.blur(),clear:Me,selectCountry:Se,getFullNumber:()=>se.value,getFullFormattedNumber:()=>P.value,getDigits:()=>j.value,isValid:()=>F.value,isComplete:()=>F.value});let{themeClass:Pe}=p({theme:()=>s.theme}),Fe=(0,t.computed)(()=>[`phone-input`,`size-${s.size}`,Pe.value,{"is-disabled":s.disabled,"is-readonly":s.readonly,"is-unstyled":s.disableDefaultStyles,"is-incomplete":s.withValidity&&fe.value,"is-complete":s.withValidity&&F.value}]),Ie=(0,t.computed)(()=>({"--pi-actions-count":+pe.value+ +me.value+(u[`actions-before`]?1:0)}));return(n,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootRef`,ref:R,"aria-label":`Phone input with country selector`,role:`group`,class:(0,t.normalizeClass)(Fe.value),style:(0,t.normalizeStyle)(Ie.value)},[(0,t.createElementVNode)(`div`,{ref_key:`selectorRef`,ref:U,class:`pi-selector`},[(0,t.createElementVNode)(`button`,{type:`button`,class:(0,t.normalizeClass)([`pi-selector-btn`,{"no-dropdown":!(0,t.unref)(Q)||e.readonly}]),disabled:e.disabled,tabindex:K.value||!(0,t.unref)(Q)?-1:void 0,"aria-label":`Selected country: ${(0,t.unref)(k).name}`,"aria-expanded":(0,t.unref)(Y),"aria-haspopup":(0,t.unref)(Q)?`listbox`:void 0,onClick:r[0]||=(...e)=>(0,t.unref)(xe)&&(0,t.unref)(xe)(...e)},[(0,t.createElementVNode)(`span`,{class:`pi-flag`,role:`img`,"aria-label":`${(0,t.unref)(k).name} flag`},[(0,t.renderSlot)(n.$slots,`flag`,{country:(0,t.unref)(k)},()=>[(0,t.createTextVNode)((0,t.toDisplayString)((0,t.unref)(k).flag),1)],!0)],8,h),(0,t.createElementVNode)(`span`,g,(0,t.toDisplayString)((0,t.unref)(k).code),1),!K.value&&(0,t.unref)(Q)?((0,t.openBlock)(),(0,t.createElementBlock)(`svg`,{key:0,class:(0,t.normalizeClass)([`pi-chevron`,{"is-open":(0,t.unref)(Y)}]),width:`12`,height:`12`,viewBox:`0 0 12 12`,fill:`none`,"aria-hidden":`true`},[...r[8]||=[(0,t.createElementVNode)(`path`,{d:`M2.5 4.5L6 8L9.5 4.5`,stroke:`currentColor`,"stroke-width":`1.5`,"stroke-linecap":`round`,"stroke-linejoin":`round`},null,-1)]],2)):(0,t.createCommentVNode)(``,!0)],10,m)],512),(0,t.createElementVNode)(`div`,_,[(0,t.createElementVNode)(`input`,{ref_key:`telRef`,ref:z,type:`tel`,inputmode:`tel`,autocomplete:`tel-national`,autocorrect:`off`,autocapitalize:`off`,spellcheck:`false`,class:`pi-input`,placeholder:(0,t.unref)(M),value:(0,t.unref)(N),disabled:e.disabled,readonly:e.readonly,"aria-invalid":fe.value,onBeforeinput:r[1]||=(...e)=>(0,t.unref)(Ee)&&(0,t.unref)(Ee)(...e),onInput:r[2]||=(...e)=>(0,t.unref)(De)&&(0,t.unref)(De)(...e),onKeydown:r[3]||=(...e)=>(0,t.unref)(Oe)&&(0,t.unref)(Oe)(...e),onPaste:r[4]||=(...e)=>(0,t.unref)(ke)&&(0,t.unref)(ke)(...e),onFocus:Ae,onBlur:je},null,40,v),(0,t.createElementVNode)(`div`,y,[(0,t.createVNode)(t.Transition,{name:`fade-scale`},{default:(0,t.withCtx)(()=>[(0,t.renderSlot)(n.$slots,`actions-before`,{},void 0,!0)]),_:3}),(0,t.createVNode)(t.Transition,{name:`fade-scale`},{default:(0,t.withCtx)(()=>[pe.value?((0,t.openBlock)(),(0,t.createElementBlock)(`button`,{key:0,type:`button`,class:(0,t.normalizeClass)([`pi-btn`,`pi-btn-copy`,{"is-copied":(0,t.unref)(q)}]),"aria-label":(0,t.unref)(he),title:(0,t.unref)(ge),onClick:r[5]||=(...e)=>(0,t.unref)(_e)&&(0,t.unref)(_e)(...e)},[u[`copy-svg`]?(0,t.renderSlot)(n.$slots,`copy-svg`,{key:0,copied:(0,t.unref)(q)},void 0,!0):(0,t.unref)(q)?((0,t.openBlock)(),(0,t.createElementBlock)(`svg`,ee,[...r[10]||=[(0,t.createElementVNode)(`path`,{d:`M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z`,fill:`currentColor`},null,-1)]])):((0,t.openBlock)(),(0,t.createElementBlock)(`svg`,x,[...r[9]||=[(0,t.createElementVNode)(`path`,{d:`M13.5 5.5V13.5H5.5V5.5H13.5ZM13.5 4H5.5C4.67 4 4 4.67 4 5.5V13.5C4 14.33 4.67 15 5.5 15H13.5C14.33 15 15 14.33 15 13.5V5.5C15 4.67 14.33 4 13.5 4ZM10.5 1H2.5V11H4V2.5H10.5V1Z`,fill:`currentColor`},null,-1)]]))],10,b)):(0,t.createCommentVNode)(``,!0)]),_:3}),(0,t.createVNode)(t.Transition,{name:`fade-scale`},{default:(0,t.withCtx)(()=>[me.value?((0,t.openBlock)(),(0,t.createElementBlock)(`button`,{key:0,type:`button`,class:`pi-btn pi-btn-clear`,"aria-label":e.clearButtonLabel,title:e.clearButtonLabel,onClick:Ne},[u[`clear-svg`]?(0,t.renderSlot)(n.$slots,`clear-svg`,{key:1},void 0,!0):((0,t.openBlock)(),(0,t.createElementBlock)(`svg`,te,[...r[11]||=[(0,t.createElementVNode)(`path`,{d:`M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z`,fill:`currentColor`},null,-1)]]))],8,S)):(0,t.createCommentVNode)(``,!0)]),_:3})])]),((0,t.openBlock)(),(0,t.createBlock)(t.Teleport,{to:`body`},[(0,t.createVNode)(t.Transition,{name:`dropdown`},{default:(0,t.withCtx)(()=>[(0,t.unref)(Y)?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:0,ref_key:`dropdownRef`,ref:V,class:(0,t.normalizeClass)([`phone-dropdown`,[e.dropdownClass,(0,t.unref)(Pe)]]),role:`dialog`,"aria-modal":`false`,"aria-label":`Select country`,style:(0,t.normalizeStyle)((0,t.unref)(ye))},[(0,t.createElementVNode)(`div`,C,[(0,t.createElementVNode)(`input`,{ref_key:`searchRef`,ref:H,value:(0,t.unref)(ve),type:`search`,class:`pi-search`,"aria-label":`Search countries`,"aria-controls":G,"aria-activedescendant":Te.value,placeholder:e.searchPlaceholder,onKeydown:r[6]||=(...e)=>(0,t.unref)(we)&&(0,t.unref)(we)(...e),onInput:r[7]||=(...e)=>(0,t.unref)($)&&(0,t.unref)($)(...e)},null,40,w)]),(0,t.createElementVNode)(`ul`,{id:G,class:`pi-options`,role:`listbox`,tabindex:`-1`},[((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)((0,t.unref)(Z),(e,r)=>((0,t.openBlock)(),(0,t.createElementBlock)(`li`,{id:de(r),key:e.id,role:`option`,class:(0,t.normalizeClass)([`pi-option`,{"is-focused":r===(0,t.unref)(X),"is-selected":e.id===(0,t.unref)(k).id}]),"aria-selected":e.id===(0,t.unref)(k).id,title:e.name,onClick:n=>(0,t.unref)(Se)(e.id),onMouseenter:e=>(0,t.unref)(Ce)(r)},[(0,t.createElementVNode)(`span`,{class:`pi-flag`,role:`img`,"aria-label":`${e.name} flag`},[(0,t.renderSlot)(n.$slots,`flag`,{country:e},()=>[(0,t.createTextVNode)((0,t.toDisplayString)(e.flag),1)],!0)],8,ne),(0,t.createElementVNode)(`span`,E,(0,t.toDisplayString)(e.name),1),(0,t.createElementVNode)(`span`,re,(0,t.toDisplayString)(e.code),1)],42,T))),128)),(0,t.unref)(Z).length===0?((0,t.openBlock)(),(0,t.createElementBlock)(`li`,ie,(0,t.toDisplayString)(e.noResultsText),1)):(0,t.createCommentVNode)(``,!0)])],6)):(0,t.createCommentVNode)(``,!0)]),_:3})])),(0,t.createElementVNode)(`div`,{ref_key:`liveRef`,ref:B,class:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`},null,512)],6))}}),[[`__scopeId`,`data-v-d730aa54`]]);function O(e){return typeof e==`string`?{country:e}:e&&typeof e==`object`?e:{}}function k(e,t,n){if(t.digits=n,e.value=t.formatter.formatDisplay(t.digits),t.options.onChange){let n=e.value?`${t.country.code} ${e.value}`:``,r=t.digits?`${t.country.code}${t.digits}`:``;t.options.onChange({full:r,fullFormatted:n,digits:t.digits})}}function A(t,n){let r=n.formatter.getMaxDigits(),i=(0,e.extractDigits)(t.value,r),a=n.formatter.formatDisplay(i);(i!==n.digits||t.value!==a)&&k(t,n,i)}function ae(t,n){let r=n.country.id,i=(0,e.parseCountryCode)(n.options.country);i&&i!==r&&M(t,n,i)}function j(n,r,i){return a=>{let o=i(a,r);o&&(k(n,r,o.newDigits),(0,t.nextTick)(()=>{(0,e.setCaret)(n,r.formatter.getCaretPosition(o.caretDigitIndex))}))}}async function oe(t){let n=(0,e.parseCountryCode)(t.country);if(n)return n;if(t.detect){let t=(0,e.parseCountryCode)(await(0,e.detectByGeoIp)());if(t)return t;let n=(0,e.parseCountryCode)((0,e.detectCountryFromLocale)());if(n)return n}return`US`}function M(t,n,r){let i=(0,e.parseCountryCode)(r);if(!i)return;let a=(0,e.getCountry)(i,n.locale);n.country=a,n.options.onCountryChange?.(a),n.formatter=(0,e.createPhoneFormatter)(a),t.placeholder=n.formatter.getPlaceholder(),A(t,n)}var N={mounted(t,n){if(t.tagName!==`INPUT`){console.warn(`[v-phone-mask] Directive can only be used on input elements`);return}t.setAttribute(`type`,`tel`),t.setAttribute(`inputmode`,`tel`),t.setAttribute(`placeholder`,``);let r=O(n.value),i=r.locale||(0,e.getNavigatorLang)(),a=(0,e.getCountry)((0,e.parseCountryCode)(r.country,`US`),i),o={country:a,formatter:(0,e.createPhoneFormatter)(a),digits:``,locale:i,options:r};t.__phoneMaskState=o,o.inputHandler=j(t,o,e.processInput),o.keydownHandler=j(t,o,e.processKeydown),o.pasteHandler=j(t,o,e.processPaste),o.beforeInputHandler=e.processBeforeInput,t.addEventListener(`beforeinput`,o.beforeInputHandler),t.addEventListener(`input`,o.inputHandler),t.addEventListener(`keydown`,o.keydownHandler),t.addEventListener(`paste`,o.pasteHandler),oe(r).then(e=>{t.__phoneMaskState===o&&M(t,o,e)})},updated(e,t){let n=e.__phoneMaskState;n&&(n.options=O(t.value),ae(e,n),A(e,n))},unmounted(e){let t=e.__phoneMaskState;t&&(t.beforeInputHandler&&e.removeEventListener(`beforeinput`,t.beforeInputHandler),t.inputHandler&&e.removeEventListener(`input`,t.inputHandler),t.keydownHandler&&e.removeEventListener(`keydown`,t.keydownHandler),t.pasteHandler&&e.removeEventListener(`paste`,t.pasteHandler),delete e.__phoneMaskState)}};function se(e){let i=(0,t.shallowRef)(null),{country:a,setCountry:o}=n({country:e.country,locale:e.locale,detect:e.detect,onCountryChange:e.onCountryChange}),{digits:s,formatter:l,displayPlaceholder:u,displayValue:d,full:f,fullFormatted:p,isComplete:m,isEmpty:h,shouldShowWarn:g}=r({country:a,value:e.value,onChange:e.onChange,onPhoneChange:e.onPhoneChange}),{handleBeforeInput:_,handleInput:v,handleKeydown:y,handlePaste:b}=c({formatter:l,digits:s,onChange:e.onChange});return(0,t.onMounted)(()=>{let e=i.value;e&&(e.setAttribute(`type`,`tel`),e.setAttribute(`inputmode`,`tel`))}),(0,t.watchEffect)(()=>{let e=i.value;e&&(e.value=d.value,e.setAttribute(`placeholder`,u.value))},{flush:`post`}),(0,t.onMounted)(()=>{let e=i.value;e&&(e.addEventListener(`beforeinput`,_),e.addEventListener(`input`,v),e.addEventListener(`keydown`,y),e.addEventListener(`paste`,b))}),(0,t.onUnmounted)(()=>{let e=i.value;e&&(e.removeEventListener(`beforeinput`,_),e.removeEventListener(`input`,v),e.removeEventListener(`keydown`,y),e.removeEventListener(`paste`,b))}),{inputRef:i,digits:s,formatter:l,full:f,fullFormatted:p,isComplete:m,isEmpty:h,shouldShowWarn:g,country:a,setCountry:o,clear:()=>{e.onChange(``)}}}function P(e){e.component(`PhoneInput`,D),e.directive(`phone-mask`,N)}var F={install:P},I={getFlagEmoji:e.getFlagEmoji,countPlaceholders:e.countPlaceholders,formatDigitsWithMap:e.formatDigitsWithMap,pickMaskVariant:e.pickMaskVariant,removeCountryCodePrefix:e.removeCountryCodePrefix,toArray:e.toArray};exports.PMaskHelpers=I,exports.PhoneInput=D,exports.default=F,exports.install=P,exports.usePhoneMask=se,exports.vPhoneMask=N,exports.vPhoneMaskSetCountry=M;