@desource/phone-mask-react 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +455 -0
- package/dist/esm/components/PhoneInput.d.ts +11 -0
- package/dist/esm/components/PhoneInput.d.ts.map +1 -0
- package/dist/esm/consts.d.ts +4 -0
- package/dist/esm/consts.d.ts.map +1 -0
- package/dist/esm/hooks/usePhoneMask.d.ts +7 -0
- package/dist/esm/hooks/usePhoneMask.d.ts.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +864 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +181 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/utils.d.ts +16 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/phone-mask-react.cjs +2 -0
- package/dist/phone-mask-react.cjs.map +1 -0
- package/dist/phone-mask-react.css +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
import { jsxs as oe, Fragment as Tt, jsx as v } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as W, useState as x, useMemo as Ee, useEffect as B, useCallback as b, useImperativeHandle as Mt } from "react";
|
|
3
|
+
import { createPortal as Lt } from "react-dom";
|
|
4
|
+
const St = { 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 #### ######"] }, kt = /^[a-z]{2}$/i, me = (e) => {
|
|
5
|
+
if (!kt.test(e)) {
|
|
6
|
+
const t = typeof e;
|
|
7
|
+
throw new TypeError(`cc argument must be an ISO 3166-1 alpha-2 string, but got '${t === "string" ? e : t}' instead.`);
|
|
8
|
+
}
|
|
9
|
+
const r = [...e.toUpperCase()].map((t) => (t.codePointAt(0) ?? 0) + 127397);
|
|
10
|
+
return String.fromCodePoint(...r);
|
|
11
|
+
}, te = Object.entries(St), et = (e) => e.split(/ (.*)/s);
|
|
12
|
+
function se(e) {
|
|
13
|
+
let r = "", t = "";
|
|
14
|
+
if (Array.isArray(e)) {
|
|
15
|
+
const s = [];
|
|
16
|
+
for (const f of e) {
|
|
17
|
+
const [c, y] = et(f);
|
|
18
|
+
r || (r = c), s.push(y);
|
|
19
|
+
}
|
|
20
|
+
t = s;
|
|
21
|
+
} else {
|
|
22
|
+
const [s, f] = et(e);
|
|
23
|
+
r = s, t = f;
|
|
24
|
+
}
|
|
25
|
+
return [r, t];
|
|
26
|
+
}
|
|
27
|
+
te.map(([e, r]) => ({ id: e, mask: r }));
|
|
28
|
+
te.reduce((e, [r, t]) => {
|
|
29
|
+
const [s, f] = se(t);
|
|
30
|
+
return e[r] = { code: s, mask: f }, e;
|
|
31
|
+
}, {});
|
|
32
|
+
te.map(([e, r]) => {
|
|
33
|
+
const [t, s] = se(r);
|
|
34
|
+
return { id: e, code: t, mask: s };
|
|
35
|
+
});
|
|
36
|
+
te.reduce((e, [r, t]) => {
|
|
37
|
+
const [s, f] = se(t);
|
|
38
|
+
return e[r] = { code: s, mask: f, flag: me(r) }, e;
|
|
39
|
+
}, {});
|
|
40
|
+
te.map(([e, r]) => {
|
|
41
|
+
const [t, s] = se(r);
|
|
42
|
+
return { id: e, code: t, mask: s, flag: me(e) };
|
|
43
|
+
});
|
|
44
|
+
const bt = (e) => {
|
|
45
|
+
const r = new Intl.DisplayNames([e], { type: "region" });
|
|
46
|
+
return te.reduce((t, [s, f]) => {
|
|
47
|
+
const [c, y] = se(f), d = r.of(s) ?? "";
|
|
48
|
+
return t[s] = { code: c, mask: y, name: d, flag: me(s) }, t;
|
|
49
|
+
}, {});
|
|
50
|
+
}, Et = te.reduce((e, [r, t]) => {
|
|
51
|
+
const [s, f] = se(t), c = new Intl.DisplayNames(["en"], { type: "region" });
|
|
52
|
+
return e[r] = { code: s, mask: f, name: c.of(r) ?? "", flag: me(r) }, e;
|
|
53
|
+
}, {});
|
|
54
|
+
te.map(([e, r]) => {
|
|
55
|
+
const [t, s] = se(r);
|
|
56
|
+
return { id: e, code: t, mask: s, name: new Intl.DisplayNames(["en"], { type: "region" }).of(e) ?? "", flag: me(e) };
|
|
57
|
+
});
|
|
58
|
+
const Pt = me;
|
|
59
|
+
function Ne() {
|
|
60
|
+
return typeof navigator < "u" && navigator.language || "en";
|
|
61
|
+
}
|
|
62
|
+
function tt(e) {
|
|
63
|
+
return e.toLowerCase().startsWith("en") ? Et : bt(e);
|
|
64
|
+
}
|
|
65
|
+
function O(e, r) {
|
|
66
|
+
const t = tt(r), s = e.toUpperCase();
|
|
67
|
+
return s in t ? { id: s, ...t[s] } : { id: "US", ...t.US };
|
|
68
|
+
}
|
|
69
|
+
function nt(e) {
|
|
70
|
+
return Array.isArray(e) ? e : [e];
|
|
71
|
+
}
|
|
72
|
+
function Ge(e) {
|
|
73
|
+
return (e.match(/#/g) || []).length;
|
|
74
|
+
}
|
|
75
|
+
function Ue(e) {
|
|
76
|
+
return e.replace(/^\+\d+\s?/, "");
|
|
77
|
+
}
|
|
78
|
+
function rt(e, r) {
|
|
79
|
+
if (e.length === 1) return e[0];
|
|
80
|
+
const t = e.map((c) => ({ mask: c, count: Ge(c) })), s = t.filter((c) => c.count >= r).sort((c, y) => c.count - y.count);
|
|
81
|
+
if (s.length > 0) return s[0].mask;
|
|
82
|
+
const f = t.sort((c, y) => y.count - c.count)[0];
|
|
83
|
+
return f ? f.mask : e[0];
|
|
84
|
+
}
|
|
85
|
+
function Pe(e, r) {
|
|
86
|
+
let t = "";
|
|
87
|
+
const s = [];
|
|
88
|
+
let f = 0;
|
|
89
|
+
const c = r.length, y = e.length;
|
|
90
|
+
for (let d = 0; d < y; d++) {
|
|
91
|
+
const M = e[d];
|
|
92
|
+
if (M === "#") {
|
|
93
|
+
if (!(f < c)) break;
|
|
94
|
+
t += r[f], s.push(f), f++;
|
|
95
|
+
} else {
|
|
96
|
+
const D = e.indexOf("#", d + 1) !== -1 && f < c;
|
|
97
|
+
(t.length > 0 || D) && (t += M, s.push(-1));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { display: t, map: s };
|
|
101
|
+
}
|
|
102
|
+
const Nt = "https://ipapi.co/json/", It = 1500, Fe = "@desource/phone-mask:geo", Rt = 864e5;
|
|
103
|
+
async function ot(e = Nt, r = It) {
|
|
104
|
+
const t = new AbortController(), s = setTimeout(() => t.abort(), r);
|
|
105
|
+
try {
|
|
106
|
+
const f = await fetch(e, { signal: t.signal, headers: { Accept: "application/json" } });
|
|
107
|
+
if (clearTimeout(s), !f.ok) return null;
|
|
108
|
+
const c = await f.json();
|
|
109
|
+
return (c.country || c.country_code || c.countryCode || c.country_code2 || "").toString().toUpperCase() || null;
|
|
110
|
+
} catch {
|
|
111
|
+
return clearTimeout(s), null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function At(e) {
|
|
115
|
+
try {
|
|
116
|
+
const t = localStorage.getItem(Fe);
|
|
117
|
+
if (t) {
|
|
118
|
+
const s = JSON.parse(t), f = Date.now() - s.ts > Rt;
|
|
119
|
+
if (!f && s.country_code && e(s.country_code)) return s.country_code.toUpperCase();
|
|
120
|
+
f && localStorage.removeItem(Fe);
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
const r = await ot();
|
|
125
|
+
if (r && e(r)) {
|
|
126
|
+
try {
|
|
127
|
+
localStorage.setItem(Fe, JSON.stringify({ country_code: r, ts: Date.now() }));
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
return r;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
function He(e) {
|
|
135
|
+
const r = nt(e.mask), t = r.map((c) => Ge(Ue(c))), s = Math.max(...t), f = (c) => {
|
|
136
|
+
const y = rt(r, c);
|
|
137
|
+
return Ue(y);
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
formatDisplay: (c) => {
|
|
141
|
+
const y = f(c.length);
|
|
142
|
+
return Pe(y, c).display;
|
|
143
|
+
},
|
|
144
|
+
getMaxDigits: () => s,
|
|
145
|
+
getPlaceholder: () => f(0),
|
|
146
|
+
getCaretPosition: (c) => {
|
|
147
|
+
const y = f(c), { display: d, map: M } = Pe(y, "0".repeat(c));
|
|
148
|
+
for (let D = 0; D < M.length; D++)
|
|
149
|
+
if (M[D] === c) return D;
|
|
150
|
+
if (c >= M.length) return d.length;
|
|
151
|
+
for (let D = 0; D < M.length; D++)
|
|
152
|
+
if (M[D] > c) return D;
|
|
153
|
+
return d.length;
|
|
154
|
+
},
|
|
155
|
+
getDigitRange: (c, y, d) => {
|
|
156
|
+
const M = f(c.length), { map: D } = Pe(M, c);
|
|
157
|
+
let $ = 1 / 0, J = -1 / 0;
|
|
158
|
+
for (let K = y; K < d && K < D.length; K++) {
|
|
159
|
+
const _ = D[K];
|
|
160
|
+
_ !== void 0 && _ >= 0 && ($ = Math.min($, _), J = Math.max(J, _));
|
|
161
|
+
}
|
|
162
|
+
return $ === 1 / 0 ? null : [$, J + 1];
|
|
163
|
+
},
|
|
164
|
+
isComplete: (c) => t.includes(c.length)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function R(e, r) {
|
|
168
|
+
if (e)
|
|
169
|
+
try {
|
|
170
|
+
e.setSelectionRange(r, r);
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function j(e, r) {
|
|
175
|
+
const t = e.replace(/\D/g, "");
|
|
176
|
+
return r ? t.slice(0, r) : t;
|
|
177
|
+
}
|
|
178
|
+
function Ie(e) {
|
|
179
|
+
return e ? [e.selectionStart ?? 0, e.selectionEnd ?? 0] : [0, 0];
|
|
180
|
+
}
|
|
181
|
+
const st = [" ", "-", "(", ")"], it = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], at = /[^\d\s\-()]/;
|
|
182
|
+
function xt(e) {
|
|
183
|
+
const r = tt(e);
|
|
184
|
+
return Object.entries(r).map(([t, s]) => ({ id: t, ...s }));
|
|
185
|
+
}
|
|
186
|
+
const Bt = ({ ref: e, ...r }) => {
|
|
187
|
+
const {
|
|
188
|
+
value: t = "",
|
|
189
|
+
country: s,
|
|
190
|
+
detect: f = !0,
|
|
191
|
+
locale: c,
|
|
192
|
+
size: y = "normal",
|
|
193
|
+
theme: d = "auto",
|
|
194
|
+
disabled: M = !1,
|
|
195
|
+
readonly: D = !1,
|
|
196
|
+
showCopy: $ = !0,
|
|
197
|
+
showClear: J = !1,
|
|
198
|
+
withValidity: K = !0,
|
|
199
|
+
searchPlaceholder: _ = "Search country or code...",
|
|
200
|
+
noResultsText: Me = "No countries found",
|
|
201
|
+
clearButtonLabel: ie = "Clear phone number",
|
|
202
|
+
dropdownClass: Le = "",
|
|
203
|
+
disableDefaultStyles: Se = !1,
|
|
204
|
+
onChange: z,
|
|
205
|
+
onPhoneChange: X,
|
|
206
|
+
onCountryChange: o,
|
|
207
|
+
onValidationChange: m,
|
|
208
|
+
onFocus: h,
|
|
209
|
+
onBlur: L,
|
|
210
|
+
onCopy: T,
|
|
211
|
+
onClear: C,
|
|
212
|
+
renderActionsBefore: N,
|
|
213
|
+
renderFlag: E,
|
|
214
|
+
renderCopySvg: F,
|
|
215
|
+
renderClearSvg: ae
|
|
216
|
+
} = r, U = W(null), he = W(null), Q = W(null), ye = W(null), Ce = W(null), ke = W(null), H = c || Ne(), [I, ce] = x(() => O(s || "US", H)), [g, G] = x(""), [q, $e] = x(!1), [ct, Re] = x(!1), [Ae, Ke] = x(""), [we, le] = x(0), [De, Ve] = x(!1), [We, Oe] = x(!1), [lt, ut] = x({}), [dt, ee] = x(!1), S = W(null), ne = W(null), ue = W(null), [ve, ft] = x(!s), w = Ee(() => He(I), [I]), de = Ee(() => xt(H), [H]), xe = w.formatDisplay(g), pt = w.getPlaceholder(), re = w.isComplete(g), Be = g.length === 0, Ze = dt && !Be && !re, be = `${I.code}${g}`, fe = g ? `${I.code} ${xe}` : "", pe = Ee(() => {
|
|
217
|
+
const n = Ae.trim();
|
|
218
|
+
if (!n) return de;
|
|
219
|
+
const i = n.toUpperCase(), l = i.replace(/\D/g, ""), p = l.length > 0;
|
|
220
|
+
return de.map((a) => {
|
|
221
|
+
const u = a.name.toUpperCase(), k = a.id.toUpperCase(), P = a.code.toUpperCase(), Y = a.code.replace(/\D/g, "");
|
|
222
|
+
let A = 0;
|
|
223
|
+
return u.startsWith(i) ? A = 1e3 : u.includes(i) && (A = 500), P.startsWith(i) ? A += 100 : P.includes(i) && (A += 50), k === i ? A += 200 : k.startsWith(i) && (A += 150), p && Y.startsWith(l) ? A += 80 : p && Y.includes(l) && (A += 40), { country: a, score: A };
|
|
224
|
+
}).filter((a) => a.score > 0).sort((a, u) => u.score !== a.score ? u.score - a.score : a.country.name.localeCompare(u.country.name)).map((a) => a.country);
|
|
225
|
+
}, [de, Ae]), V = M || D, Ye = $ && !Be && !M, je = J && !Be && !V;
|
|
226
|
+
B(() => {
|
|
227
|
+
ft(!s && de.length > 1);
|
|
228
|
+
const n = (l) => {
|
|
229
|
+
if (!l) return !1;
|
|
230
|
+
const p = l.toUpperCase();
|
|
231
|
+
return de.some((a) => a.id === p);
|
|
232
|
+
}, i = () => {
|
|
233
|
+
const l = typeof navigator < "u" && navigator.language ? navigator.language : "";
|
|
234
|
+
try {
|
|
235
|
+
if (Intl.Locale) {
|
|
236
|
+
const a = new Intl.Locale(l);
|
|
237
|
+
if (a?.region && n(a.region)) return a.region.toUpperCase();
|
|
238
|
+
}
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
const p = l.split(/[-_]/);
|
|
242
|
+
return p.length > 1 && n(p[1]) ? p[1].toUpperCase() : null;
|
|
243
|
+
};
|
|
244
|
+
(async () => {
|
|
245
|
+
if (s && n(s)) {
|
|
246
|
+
const a = O(s, H);
|
|
247
|
+
ce((u) => u.id === a.id ? u : (o?.(a), a));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (!f) return;
|
|
251
|
+
const l = await At(n);
|
|
252
|
+
if (l) {
|
|
253
|
+
const a = O(l, H);
|
|
254
|
+
ce((u) => u.id === a.id ? u : (o?.(a), a));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const p = i();
|
|
258
|
+
if (p) {
|
|
259
|
+
const a = O(p, H);
|
|
260
|
+
ce((u) => u.id === a.id ? u : (o?.(a), a));
|
|
261
|
+
}
|
|
262
|
+
})();
|
|
263
|
+
}, [s, f, de, H]), B(() => {
|
|
264
|
+
const n = w.getMaxDigits();
|
|
265
|
+
g.length > n && G((i) => i.slice(0, n));
|
|
266
|
+
}, [w]), B(() => {
|
|
267
|
+
const n = j(t || "");
|
|
268
|
+
n !== g && G(n);
|
|
269
|
+
}, [t]), B(() => {
|
|
270
|
+
m?.(re);
|
|
271
|
+
}, [re, m]);
|
|
272
|
+
const Je = b(() => {
|
|
273
|
+
z?.(g), X?.({ full: be, fullFormatted: fe, digits: g });
|
|
274
|
+
}, [g, be, fe, z, X]);
|
|
275
|
+
B(() => {
|
|
276
|
+
Je();
|
|
277
|
+
}, [Je]);
|
|
278
|
+
const _e = b((n) => {
|
|
279
|
+
const i = n.data;
|
|
280
|
+
if (n.inputType !== "insertText" || !i) return;
|
|
281
|
+
const l = U.current;
|
|
282
|
+
l && (at.test(i) || i === " " && l.value.endsWith(" ")) && n.preventDefault();
|
|
283
|
+
}, []), gt = b(() => {
|
|
284
|
+
const n = U.current;
|
|
285
|
+
if (!n || V) return;
|
|
286
|
+
const i = n.value || "", l = w.getMaxDigits(), p = j(i, l);
|
|
287
|
+
G(p), setTimeout(() => {
|
|
288
|
+
const a = w.getCaretPosition(p.length);
|
|
289
|
+
R(n, a);
|
|
290
|
+
}, 0), ee(!1), S.current && clearTimeout(S.current), p.length > 0 && (S.current = setTimeout(() => {
|
|
291
|
+
ee(!0);
|
|
292
|
+
}, 500));
|
|
293
|
+
}, [w, V]), ze = b(
|
|
294
|
+
(n) => {
|
|
295
|
+
if (V) return;
|
|
296
|
+
const i = U.current;
|
|
297
|
+
if (!i || n.ctrlKey || n.metaKey || n.altKey || it.includes(n.key)) return;
|
|
298
|
+
const [l, p] = Ie(i);
|
|
299
|
+
ee(!1), S.current && clearTimeout(S.current);
|
|
300
|
+
const a = () => {
|
|
301
|
+
S.current && clearTimeout(S.current), S.current = setTimeout(() => {
|
|
302
|
+
ee(!0);
|
|
303
|
+
}, 300);
|
|
304
|
+
};
|
|
305
|
+
if (n.key === "Backspace") {
|
|
306
|
+
if (n.preventDefault(), l !== p) {
|
|
307
|
+
const u = w.getDigitRange(g, l, p);
|
|
308
|
+
if (u) {
|
|
309
|
+
const [k, P] = u;
|
|
310
|
+
G(g.slice(0, k) + g.slice(P)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
|
|
311
|
+
}
|
|
312
|
+
} else if (l > 0) {
|
|
313
|
+
let u = l - 1;
|
|
314
|
+
for (; u >= 0 && st.includes(i.value[u]); ) u--;
|
|
315
|
+
if (u >= 0) {
|
|
316
|
+
const k = w.getDigitRange(g, u, u + 1);
|
|
317
|
+
if (k) {
|
|
318
|
+
const [P] = k;
|
|
319
|
+
G(g.slice(0, P) + g.slice(P + 1)), setTimeout(() => R(i, w.getCaretPosition(P)), 0);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
a();
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (n.key === "Delete") {
|
|
327
|
+
if (n.preventDefault(), l !== p) {
|
|
328
|
+
const u = w.getDigitRange(g, l, p);
|
|
329
|
+
if (u) {
|
|
330
|
+
const [k, P] = u;
|
|
331
|
+
G(g.slice(0, k) + g.slice(P)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
|
|
332
|
+
}
|
|
333
|
+
} else if (l < i.value.length) {
|
|
334
|
+
const u = w.getDigitRange(g, l, l + 1);
|
|
335
|
+
if (u) {
|
|
336
|
+
const [k] = u;
|
|
337
|
+
G(g.slice(0, k) + g.slice(k + 1)), setTimeout(() => R(i, w.getCaretPosition(k)), 0);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
a();
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (/^[0-9]$/.test(n.key)) {
|
|
344
|
+
g.length >= w.getMaxDigits() && n.preventDefault(), a();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
n.key.length === 1 && n.preventDefault(), a();
|
|
348
|
+
},
|
|
349
|
+
[V, w, g]
|
|
350
|
+
), Xe = b(
|
|
351
|
+
(n) => {
|
|
352
|
+
if (V) return;
|
|
353
|
+
n.preventDefault();
|
|
354
|
+
const i = U.current;
|
|
355
|
+
if (!i) return;
|
|
356
|
+
const l = n.clipboardData?.getData("text") || "", p = w.getMaxDigits(), a = j(l, p);
|
|
357
|
+
if (!a) return;
|
|
358
|
+
const [u, k] = Ie(i);
|
|
359
|
+
if (u !== k) {
|
|
360
|
+
const P = w.getDigitRange(g, u, k);
|
|
361
|
+
if (P) {
|
|
362
|
+
const [Y, A] = P, vt = j(g.slice(0, Y) + a + g.slice(A), p);
|
|
363
|
+
G(vt), setTimeout(() => R(i, w.getCaretPosition(Y + a.length)), 0);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
const P = w.getDigitRange(g, u, u), Y = P ? P[0] : g.length, A = j(
|
|
367
|
+
g.slice(0, Y) + a + g.slice(Y),
|
|
368
|
+
p
|
|
369
|
+
);
|
|
370
|
+
G(A), setTimeout(() => R(i, w.getCaretPosition(Y + a.length)), 0);
|
|
371
|
+
}
|
|
372
|
+
ee(!1), S.current && clearTimeout(S.current), S.current = setTimeout(() => {
|
|
373
|
+
ee(!0);
|
|
374
|
+
}, 300);
|
|
375
|
+
},
|
|
376
|
+
[V, w, g]
|
|
377
|
+
), Z = b(() => {
|
|
378
|
+
q && (Re(!0), ne.current && clearTimeout(ne.current), ne.current = setTimeout(() => {
|
|
379
|
+
$e(!1), Re(!1);
|
|
380
|
+
}, 200));
|
|
381
|
+
}, [q]), mt = b(
|
|
382
|
+
(n) => {
|
|
383
|
+
S.current && clearTimeout(S.current), Z(), h?.(n);
|
|
384
|
+
},
|
|
385
|
+
[h, Z]
|
|
386
|
+
);
|
|
387
|
+
B(() => {
|
|
388
|
+
const n = U.current;
|
|
389
|
+
if (!n) return;
|
|
390
|
+
const i = _e, l = ze, p = Xe;
|
|
391
|
+
return n.addEventListener("beforeinput", i), n.addEventListener("keydown", l), n.addEventListener("paste", p), () => {
|
|
392
|
+
n.removeEventListener("beforeinput", i), n.removeEventListener("keydown", l), n.removeEventListener("paste", p);
|
|
393
|
+
};
|
|
394
|
+
}, [_e, ze, Xe]);
|
|
395
|
+
const Te = b(
|
|
396
|
+
(n) => {
|
|
397
|
+
const i = O(n, H);
|
|
398
|
+
ce(i), Z(), Ke(""), le(0), o?.(i), setTimeout(() => U.current?.focus(), 0);
|
|
399
|
+
},
|
|
400
|
+
[H, o, Z]
|
|
401
|
+
), ge = b(() => {
|
|
402
|
+
if (!he.current) return;
|
|
403
|
+
const n = he.current.getBoundingClientRect();
|
|
404
|
+
ut({
|
|
405
|
+
top: `${n.bottom + window.scrollY + 8}px`,
|
|
406
|
+
left: `${n.left + window.scrollX}px`,
|
|
407
|
+
width: `${n.width}px`
|
|
408
|
+
});
|
|
409
|
+
}, []);
|
|
410
|
+
B(() => {
|
|
411
|
+
if (!q) return;
|
|
412
|
+
ge();
|
|
413
|
+
const n = setTimeout(() => ye.current?.focus({ preventScroll: !0 }), 0), i = (l) => {
|
|
414
|
+
const p = l.target, a = Q.current, u = ke.current;
|
|
415
|
+
p && (a?.contains(p) || u?.contains(p) || Z());
|
|
416
|
+
};
|
|
417
|
+
return window.addEventListener("resize", ge), window.addEventListener("scroll", ge, !0), window.addEventListener("click", i, !0), () => {
|
|
418
|
+
clearTimeout(n), window.removeEventListener("resize", ge), window.removeEventListener("scroll", ge, !0), window.removeEventListener("click", i, !0);
|
|
419
|
+
};
|
|
420
|
+
}, [q, ge, Z]), B(() => () => {
|
|
421
|
+
ne.current && clearTimeout(ne.current), ue.current && clearTimeout(ue.current), S.current && clearTimeout(S.current);
|
|
422
|
+
}, []);
|
|
423
|
+
const ht = b(async () => {
|
|
424
|
+
if (We) return;
|
|
425
|
+
const n = fe.trim();
|
|
426
|
+
if (n) {
|
|
427
|
+
Oe(!0);
|
|
428
|
+
try {
|
|
429
|
+
await navigator.clipboard.writeText(n), Ve(!0), T?.(n), Ce.current && (Ce.current.textContent = "Phone number copied to clipboard"), ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
|
|
430
|
+
Ve(!1), ue.current = null;
|
|
431
|
+
}, 1800);
|
|
432
|
+
} catch (i) {
|
|
433
|
+
console.warn("Copy failed", i);
|
|
434
|
+
} finally {
|
|
435
|
+
Oe(!1);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}, [fe, T, We]), yt = b(() => {
|
|
439
|
+
G(""), ee(!1), S.current && clearTimeout(S.current), z?.(""), X?.({ full: "", fullFormatted: "", digits: "" }), C?.(), setTimeout(() => U.current?.focus(), 0);
|
|
440
|
+
}, [z, X, C]);
|
|
441
|
+
Mt(
|
|
442
|
+
e,
|
|
443
|
+
() => ({
|
|
444
|
+
focus: () => U.current?.focus(),
|
|
445
|
+
blur: () => U.current?.blur(),
|
|
446
|
+
clear: () => {
|
|
447
|
+
G(""), ee(!1), S.current && clearTimeout(S.current), z?.(""), X?.({ full: "", fullFormatted: "", digits: "" }), C?.();
|
|
448
|
+
},
|
|
449
|
+
selectCountry: Te,
|
|
450
|
+
getFullNumber: () => be,
|
|
451
|
+
getFullFormattedNumber: () => fe,
|
|
452
|
+
getDigits: () => g,
|
|
453
|
+
isValid: () => re,
|
|
454
|
+
isComplete: () => re
|
|
455
|
+
}),
|
|
456
|
+
[Te, be, fe, g, re, C, z, X]
|
|
457
|
+
);
|
|
458
|
+
const Qe = (n) => {
|
|
459
|
+
setTimeout(() => {
|
|
460
|
+
const i = Q.current?.lastElementChild, l = i?.children[n];
|
|
461
|
+
if (!i || !l) return;
|
|
462
|
+
const p = i.getBoundingClientRect(), a = l.getBoundingClientRect();
|
|
463
|
+
let u = 0;
|
|
464
|
+
if (a.top < p.top)
|
|
465
|
+
u = i.scrollTop - (p.top - a.top);
|
|
466
|
+
else if (a.bottom > p.bottom)
|
|
467
|
+
u = i.scrollTop + (a.bottom - p.bottom);
|
|
468
|
+
else
|
|
469
|
+
return;
|
|
470
|
+
i.scrollTo({ top: u, behavior: "smooth" });
|
|
471
|
+
}, 0);
|
|
472
|
+
}, Ct = b(
|
|
473
|
+
(n) => {
|
|
474
|
+
n.key === "ArrowDown" ? (n.preventDefault(), le((i) => {
|
|
475
|
+
const l = Math.min(i + 1, pe.length - 1);
|
|
476
|
+
return Qe(l), l;
|
|
477
|
+
})) : n.key === "ArrowUp" ? (n.preventDefault(), le((i) => {
|
|
478
|
+
const l = Math.max(i - 1, 0);
|
|
479
|
+
return Qe(l), l;
|
|
480
|
+
})) : n.key === "Enter" && pe[we] ? (n.preventDefault(), Te(pe[we].id)) : n.key === "Escape" && Z();
|
|
481
|
+
},
|
|
482
|
+
[pe, we, Te, Z]
|
|
483
|
+
), qe = Ee(() => d !== "auto" ? `theme-${d}` : typeof window < "u" && window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "theme-dark" : "theme-light", [d]), wt = [
|
|
484
|
+
"phone-input",
|
|
485
|
+
`size-${y}`,
|
|
486
|
+
qe,
|
|
487
|
+
M && "is-disabled",
|
|
488
|
+
D && "is-readonly",
|
|
489
|
+
Se && "is-unstyled",
|
|
490
|
+
K && Ze && "is-incomplete",
|
|
491
|
+
K && re && "is-complete"
|
|
492
|
+
].filter(Boolean).join(" "), Dt = +Ye + +je + (N ? 1 : 0);
|
|
493
|
+
return /* @__PURE__ */ oe(Tt, { children: [
|
|
494
|
+
/* @__PURE__ */ oe(
|
|
495
|
+
"div",
|
|
496
|
+
{
|
|
497
|
+
ref: he,
|
|
498
|
+
className: wt,
|
|
499
|
+
style: { "--pi-actions-count": Dt },
|
|
500
|
+
role: "group",
|
|
501
|
+
"aria-label": "Phone input with country selector",
|
|
502
|
+
children: [
|
|
503
|
+
/* @__PURE__ */ v("div", { className: "pi-selector", ref: ke, children: /* @__PURE__ */ oe(
|
|
504
|
+
"button",
|
|
505
|
+
{
|
|
506
|
+
type: "button",
|
|
507
|
+
className: `pi-selector-btn ${!ve || D ? "no-dropdown" : ""}`,
|
|
508
|
+
disabled: M,
|
|
509
|
+
tabIndex: V || !ve ? -1 : void 0,
|
|
510
|
+
"aria-label": `Selected country: ${I.name}`,
|
|
511
|
+
"aria-expanded": q,
|
|
512
|
+
"aria-haspopup": ve ? "listbox" : void 0,
|
|
513
|
+
onClick: () => {
|
|
514
|
+
V || !ve || (q ? Z() : (ne.current && clearTimeout(ne.current), Re(!1), $e(!0), le(0)));
|
|
515
|
+
},
|
|
516
|
+
children: [
|
|
517
|
+
/* @__PURE__ */ v("span", { className: "pi-flag", role: "img", "aria-label": `${I.name} flag`, children: E ? E(I) : I.flag }),
|
|
518
|
+
/* @__PURE__ */ v("span", { className: "pi-code", children: I.code }),
|
|
519
|
+
!V && ve && /* @__PURE__ */ v(
|
|
520
|
+
"svg",
|
|
521
|
+
{
|
|
522
|
+
className: `pi-chevron ${q ? "is-open" : ""}`,
|
|
523
|
+
width: "12",
|
|
524
|
+
height: "12",
|
|
525
|
+
viewBox: "0 0 12 12",
|
|
526
|
+
fill: "none",
|
|
527
|
+
"aria-hidden": "true",
|
|
528
|
+
children: /* @__PURE__ */ v(
|
|
529
|
+
"path",
|
|
530
|
+
{
|
|
531
|
+
d: "M2.5 4.5L6 8L9.5 4.5",
|
|
532
|
+
stroke: "currentColor",
|
|
533
|
+
strokeWidth: "1.5",
|
|
534
|
+
strokeLinecap: "round",
|
|
535
|
+
strokeLinejoin: "round"
|
|
536
|
+
}
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
) }),
|
|
543
|
+
/* @__PURE__ */ oe("div", { className: "pi-input-wrap", children: [
|
|
544
|
+
/* @__PURE__ */ v(
|
|
545
|
+
"input",
|
|
546
|
+
{
|
|
547
|
+
ref: U,
|
|
548
|
+
type: "tel",
|
|
549
|
+
inputMode: "tel",
|
|
550
|
+
autoComplete: "tel-national",
|
|
551
|
+
autoCorrect: "off",
|
|
552
|
+
autoCapitalize: "off",
|
|
553
|
+
spellCheck: !1,
|
|
554
|
+
className: "pi-input",
|
|
555
|
+
placeholder: pt,
|
|
556
|
+
value: xe,
|
|
557
|
+
disabled: M,
|
|
558
|
+
readOnly: D,
|
|
559
|
+
"aria-invalid": Ze,
|
|
560
|
+
onInput: gt,
|
|
561
|
+
onFocus: mt,
|
|
562
|
+
onBlur: L
|
|
563
|
+
}
|
|
564
|
+
),
|
|
565
|
+
/* @__PURE__ */ oe("div", { className: "pi-actions", role: "toolbar", "aria-label": "Phone input actions", children: [
|
|
566
|
+
N && N(),
|
|
567
|
+
Ye && /* @__PURE__ */ v(
|
|
568
|
+
"button",
|
|
569
|
+
{
|
|
570
|
+
type: "button",
|
|
571
|
+
className: `pi-btn ${De ? "is-copied" : ""}`,
|
|
572
|
+
"aria-label": De ? "Copied" : `Copy ${I.code} ${xe}`,
|
|
573
|
+
title: De ? "Copied" : "Copy phone number",
|
|
574
|
+
onClick: ht,
|
|
575
|
+
children: F ? F(De) : De ? /* @__PURE__ */ v("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v("path", { d: "M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z", fill: "currentColor" }) }) : /* @__PURE__ */ v("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v(
|
|
576
|
+
"path",
|
|
577
|
+
{
|
|
578
|
+
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",
|
|
579
|
+
fill: "currentColor"
|
|
580
|
+
}
|
|
581
|
+
) })
|
|
582
|
+
}
|
|
583
|
+
),
|
|
584
|
+
je && /* @__PURE__ */ v(
|
|
585
|
+
"button",
|
|
586
|
+
{
|
|
587
|
+
type: "button",
|
|
588
|
+
className: "pi-btn",
|
|
589
|
+
"aria-label": ie,
|
|
590
|
+
title: ie,
|
|
591
|
+
onClick: yt,
|
|
592
|
+
children: ae ? ae() : /* @__PURE__ */ v("svg", { width: "11", height: "11", viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ v(
|
|
593
|
+
"path",
|
|
594
|
+
{
|
|
595
|
+
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",
|
|
596
|
+
fill: "currentColor"
|
|
597
|
+
}
|
|
598
|
+
) })
|
|
599
|
+
}
|
|
600
|
+
)
|
|
601
|
+
] })
|
|
602
|
+
] })
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
),
|
|
606
|
+
q && typeof document < "u" && Lt(
|
|
607
|
+
/* @__PURE__ */ oe(
|
|
608
|
+
"div",
|
|
609
|
+
{
|
|
610
|
+
ref: Q,
|
|
611
|
+
className: `phone-dropdown ${Le} ${qe} ${ct ? "is-closing" : ""}`,
|
|
612
|
+
style: lt,
|
|
613
|
+
role: "dialog",
|
|
614
|
+
"aria-modal": "false",
|
|
615
|
+
"aria-label": "Select country",
|
|
616
|
+
children: [
|
|
617
|
+
/* @__PURE__ */ v("div", { className: "pi-search-wrap", children: /* @__PURE__ */ v(
|
|
618
|
+
"input",
|
|
619
|
+
{
|
|
620
|
+
ref: ye,
|
|
621
|
+
type: "search",
|
|
622
|
+
className: "pi-search",
|
|
623
|
+
"aria-label": "Search countries",
|
|
624
|
+
placeholder: _,
|
|
625
|
+
value: Ae,
|
|
626
|
+
onChange: (n) => {
|
|
627
|
+
Ke(n.target.value), le(0);
|
|
628
|
+
},
|
|
629
|
+
onKeyDown: Ct
|
|
630
|
+
}
|
|
631
|
+
) }),
|
|
632
|
+
/* @__PURE__ */ v("ul", { className: "pi-options", role: "listbox", "aria-activedescendant": `option-${we}`, tabIndex: -1, children: pe.length > 0 ? pe.map((n, i) => /* @__PURE__ */ oe(
|
|
633
|
+
"li",
|
|
634
|
+
{
|
|
635
|
+
id: `option-${i}`,
|
|
636
|
+
role: "option",
|
|
637
|
+
className: `pi-option ${i === we ? "is-focused" : ""} ${n.id === I.id ? "is-selected" : ""}`,
|
|
638
|
+
"aria-selected": n.id === I.id,
|
|
639
|
+
title: n.name,
|
|
640
|
+
onClick: () => Te(n.id),
|
|
641
|
+
onMouseEnter: () => le(i),
|
|
642
|
+
children: [
|
|
643
|
+
/* @__PURE__ */ v("span", { className: "pi-flag", role: "img", "aria-label": `${n.name} flag`, children: E ? E(n) : n.flag }),
|
|
644
|
+
/* @__PURE__ */ v("span", { className: "pi-opt-name", children: n.name }),
|
|
645
|
+
/* @__PURE__ */ v("span", { className: "pi-opt-code", children: n.code })
|
|
646
|
+
]
|
|
647
|
+
},
|
|
648
|
+
n.id
|
|
649
|
+
)) : /* @__PURE__ */ v("li", { className: "pi-empty", children: Me }) })
|
|
650
|
+
]
|
|
651
|
+
}
|
|
652
|
+
),
|
|
653
|
+
document.body
|
|
654
|
+
),
|
|
655
|
+
/* @__PURE__ */ v("div", { ref: Ce, className: "sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true" })
|
|
656
|
+
] });
|
|
657
|
+
};
|
|
658
|
+
Bt.displayName = "PhoneInput";
|
|
659
|
+
function Ft() {
|
|
660
|
+
try {
|
|
661
|
+
const e = Ne();
|
|
662
|
+
try {
|
|
663
|
+
const t = new Intl.Locale(e);
|
|
664
|
+
if (t.region) return t.region.toUpperCase();
|
|
665
|
+
} catch {
|
|
666
|
+
}
|
|
667
|
+
const r = e.split(/[-_]/);
|
|
668
|
+
if (r.length > 1) return r[1]?.toUpperCase() || null;
|
|
669
|
+
} catch {
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
function $t(e = {}) {
|
|
674
|
+
const r = W(null), [t, s] = x(""), [f, c] = x(() => {
|
|
675
|
+
const o = e.locale || Ne();
|
|
676
|
+
return O(e.country || "US", o);
|
|
677
|
+
}), y = e.locale || Ne(), d = He(f), M = d.formatDisplay(t), D = `${f.code}${t}`, $ = t ? `${f.code} ${M}` : "", J = d.isComplete(t), K = t.length === 0, _ = !K && !J;
|
|
678
|
+
B(() => {
|
|
679
|
+
e.detect && (async () => {
|
|
680
|
+
const o = await ot();
|
|
681
|
+
if (o) {
|
|
682
|
+
const h = O(o, y);
|
|
683
|
+
c(h), e.onCountryChange?.(h);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
const m = Ft();
|
|
687
|
+
if (m) {
|
|
688
|
+
const h = O(m, y);
|
|
689
|
+
c(h), e.onCountryChange?.(h);
|
|
690
|
+
}
|
|
691
|
+
})();
|
|
692
|
+
}, [e.detect]), B(() => {
|
|
693
|
+
if (e.country) {
|
|
694
|
+
const o = O(e.country, y);
|
|
695
|
+
o.id !== f.id && (c(o), e.onCountryChange?.(o));
|
|
696
|
+
}
|
|
697
|
+
}, [e.country, y]), B(() => {
|
|
698
|
+
const o = r.current;
|
|
699
|
+
o && (o.value = M, o.placeholder = d.getPlaceholder());
|
|
700
|
+
}, [M, d]), B(() => {
|
|
701
|
+
if (e.onChange) {
|
|
702
|
+
const o = {
|
|
703
|
+
full: D,
|
|
704
|
+
fullFormatted: $,
|
|
705
|
+
digits: t
|
|
706
|
+
};
|
|
707
|
+
e.onChange(o);
|
|
708
|
+
}
|
|
709
|
+
}, [t, D, $]);
|
|
710
|
+
const Me = b((o) => {
|
|
711
|
+
const m = o.data;
|
|
712
|
+
if (o.inputType !== "insertText" || !m) return;
|
|
713
|
+
const h = r.current;
|
|
714
|
+
h && (at.test(m) || m === " " && h.value.endsWith(" ")) && o.preventDefault();
|
|
715
|
+
}, []), ie = b(() => {
|
|
716
|
+
const o = r.current;
|
|
717
|
+
if (!o) return;
|
|
718
|
+
const m = o.value || "", h = d.getMaxDigits(), L = j(m, h);
|
|
719
|
+
s(L), setTimeout(() => {
|
|
720
|
+
const T = d.getCaretPosition(L.length);
|
|
721
|
+
R(o, T);
|
|
722
|
+
}, 0);
|
|
723
|
+
}, [d]), Le = b(
|
|
724
|
+
(o) => {
|
|
725
|
+
const m = r.current;
|
|
726
|
+
if (!m || o.ctrlKey || o.metaKey || o.altKey || it.includes(o.key)) return;
|
|
727
|
+
const [h, L] = Ie(m);
|
|
728
|
+
if (o.key === "Backspace") {
|
|
729
|
+
if (o.preventDefault(), h !== L) {
|
|
730
|
+
const T = d.getDigitRange(t, h, L);
|
|
731
|
+
if (T) {
|
|
732
|
+
const [C, N] = T, E = t.slice(0, C) + t.slice(N);
|
|
733
|
+
s(E), setTimeout(() => {
|
|
734
|
+
const F = d.getCaretPosition(C);
|
|
735
|
+
R(m, F);
|
|
736
|
+
}, 0);
|
|
737
|
+
}
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (h > 0) {
|
|
741
|
+
const T = m.value;
|
|
742
|
+
let C = h - 1;
|
|
743
|
+
for (; C >= 0 && st.includes(T[C]); )
|
|
744
|
+
C--;
|
|
745
|
+
if (C >= 0) {
|
|
746
|
+
const N = d.getDigitRange(t, C, C + 1);
|
|
747
|
+
if (N) {
|
|
748
|
+
const [E] = N, F = t.slice(0, E) + t.slice(E + 1);
|
|
749
|
+
s(F), setTimeout(() => {
|
|
750
|
+
const ae = d.getCaretPosition(E);
|
|
751
|
+
R(m, ae);
|
|
752
|
+
}, 0);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (o.key === "Delete") {
|
|
759
|
+
if (o.preventDefault(), h !== L) {
|
|
760
|
+
const T = d.getDigitRange(t, h, L);
|
|
761
|
+
if (T) {
|
|
762
|
+
const [C, N] = T, E = t.slice(0, C) + t.slice(N);
|
|
763
|
+
s(E), setTimeout(() => {
|
|
764
|
+
const F = d.getCaretPosition(C);
|
|
765
|
+
R(m, F);
|
|
766
|
+
}, 0);
|
|
767
|
+
}
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (h < m.value.length) {
|
|
771
|
+
const T = d.getDigitRange(t, h, h + 1);
|
|
772
|
+
if (T) {
|
|
773
|
+
const [C] = T, N = t.slice(0, C) + t.slice(C + 1);
|
|
774
|
+
s(N), setTimeout(() => {
|
|
775
|
+
const E = d.getCaretPosition(C);
|
|
776
|
+
R(m, E);
|
|
777
|
+
}, 0);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
if (/^[0-9]$/.test(o.key)) {
|
|
783
|
+
t.length >= d.getMaxDigits() && o.preventDefault();
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
o.key.length === 1 && o.preventDefault();
|
|
787
|
+
},
|
|
788
|
+
[t, d]
|
|
789
|
+
), Se = b(
|
|
790
|
+
(o) => {
|
|
791
|
+
o.preventDefault();
|
|
792
|
+
const m = r.current;
|
|
793
|
+
if (!m) return;
|
|
794
|
+
const h = o.clipboardData?.getData("text") || "", L = d.getMaxDigits(), T = j(h, L);
|
|
795
|
+
if (T.length === 0) return;
|
|
796
|
+
const [C, N] = Ie(m);
|
|
797
|
+
if (C !== N) {
|
|
798
|
+
const Q = d.getDigitRange(t, C, N);
|
|
799
|
+
if (Q) {
|
|
800
|
+
const [ye, Ce] = Q, ke = t.slice(0, ye), H = t.slice(Ce), I = j(ke + T + H, L);
|
|
801
|
+
s(I), setTimeout(() => {
|
|
802
|
+
const ce = d.getCaretPosition(ye + T.length);
|
|
803
|
+
R(m, ce);
|
|
804
|
+
}, 0);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
const E = d.getDigitRange(t, C, C), F = E ? E[0] : t.length, ae = t.slice(0, F), U = t.slice(F), he = j(ae + T + U, L);
|
|
809
|
+
s(he), setTimeout(() => {
|
|
810
|
+
const Q = d.getCaretPosition(F + T.length);
|
|
811
|
+
R(m, Q);
|
|
812
|
+
}, 0);
|
|
813
|
+
},
|
|
814
|
+
[t, d]
|
|
815
|
+
);
|
|
816
|
+
B(() => {
|
|
817
|
+
const o = r.current;
|
|
818
|
+
if (!o) return;
|
|
819
|
+
o.setAttribute("type", "tel"), o.setAttribute("inputmode", "tel"), o.setAttribute("placeholder", d.getPlaceholder());
|
|
820
|
+
const m = Me, h = Le, L = Se;
|
|
821
|
+
return o.addEventListener("beforeinput", m), o.addEventListener("input", ie), o.addEventListener("keydown", h), o.addEventListener("paste", L), () => {
|
|
822
|
+
o.removeEventListener("beforeinput", m), o.removeEventListener("input", ie), o.removeEventListener("keydown", h), o.removeEventListener("paste", L);
|
|
823
|
+
};
|
|
824
|
+
}, [Me, ie, Le, Se, d]);
|
|
825
|
+
const z = b(
|
|
826
|
+
(o) => {
|
|
827
|
+
const m = O(o, y);
|
|
828
|
+
c(m);
|
|
829
|
+
const L = He(m).getMaxDigits();
|
|
830
|
+
t.length > L && s(t.slice(0, L)), e.onCountryChange?.(m);
|
|
831
|
+
},
|
|
832
|
+
[y, t, e]
|
|
833
|
+
), X = b(() => {
|
|
834
|
+
s("");
|
|
835
|
+
const o = r.current;
|
|
836
|
+
o && (o.value = "");
|
|
837
|
+
}, []);
|
|
838
|
+
return {
|
|
839
|
+
ref: r,
|
|
840
|
+
digits: t,
|
|
841
|
+
full: D,
|
|
842
|
+
fullFormatted: $,
|
|
843
|
+
isComplete: J,
|
|
844
|
+
isEmpty: K,
|
|
845
|
+
shouldShowWarn: _,
|
|
846
|
+
country: f,
|
|
847
|
+
setCountry: z,
|
|
848
|
+
clear: X
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
const Kt = {
|
|
852
|
+
getFlagEmoji: Pt,
|
|
853
|
+
countPlaceholders: Ge,
|
|
854
|
+
formatDigitsWithMap: Pe,
|
|
855
|
+
pickMaskVariant: rt,
|
|
856
|
+
removeCountryCodePrefix: Ue,
|
|
857
|
+
toArray: nt
|
|
858
|
+
};
|
|
859
|
+
export {
|
|
860
|
+
Kt as PMaskHelpers,
|
|
861
|
+
Bt as PhoneInput,
|
|
862
|
+
$t as usePhoneMask
|
|
863
|
+
};
|
|
864
|
+
//# sourceMappingURL=index.js.map
|