@desource/phone-mask-svelte 1.0.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 +35 -0
- package/LICENSE +21 -0
- package/README.md +529 -0
- package/dist/index.cjs +1301 -0
- package/dist/index.mjs +1284 -0
- package/dist/phone-mask-svelte.css +383 -0
- package/dist/types/composables/internal/useCopyAction.svelte.d.ts +13 -0
- package/dist/types/composables/internal/useCopyAction.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useCountry.svelte.d.ts +17 -0
- package/dist/types/composables/internal/useCountry.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useCountrySelector.svelte.d.ts +31 -0
- package/dist/types/composables/internal/useCountrySelector.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useFormatter.svelte.d.ts +29 -0
- package/dist/types/composables/internal/useFormatter.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useInputHandlers.svelte.d.ts +18 -0
- package/dist/types/composables/internal/useInputHandlers.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useTheme.svelte.d.ts +9 -0
- package/dist/types/composables/internal/useTheme.svelte.d.ts.map +1 -0
- package/dist/types/composables/internal/useValidationHint.svelte.d.ts +6 -0
- package/dist/types/composables/internal/useValidationHint.svelte.d.ts.map +1 -0
- package/dist/types/composables/usePhoneMask.svelte.d.ts +31 -0
- package/dist/types/composables/usePhoneMask.svelte.d.ts.map +1 -0
- package/dist/types/composables/utility/useClipboard.svelte.d.ts +6 -0
- package/dist/types/composables/utility/useClipboard.svelte.d.ts.map +1 -0
- package/dist/types/composables/utility/useTimer.svelte.d.ts +8 -0
- package/dist/types/composables/utility/useTimer.svelte.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +84 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +77 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1284 @@
|
|
|
1
|
+
import "svelte/internal/disclose-version";
|
|
2
|
+
import * as $ from "svelte/internal/client";
|
|
3
|
+
import { onDestroy, tick } from "svelte";
|
|
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 = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
|
|
14
|
+
const t2 = e2.toLowerCase(), s2 = n.get(t2);
|
|
15
|
+
if (s2) return s2;
|
|
16
|
+
const r = new Intl.DisplayNames([e2], { type: "region" });
|
|
17
|
+
if (n.size >= 10) {
|
|
18
|
+
for (const e3 of n.keys()) if (e3 !== o$1) {
|
|
19
|
+
n.delete(e3);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return n.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 "undefined" != typeof navigator && navigator.language || "en";
|
|
74
|
+
}
|
|
75
|
+
function detectCountryFromLocale() {
|
|
76
|
+
try {
|
|
77
|
+
const t2 = getNavigatorLang();
|
|
78
|
+
try {
|
|
79
|
+
const e3 = new Intl.Locale(t2);
|
|
80
|
+
if (e3.region) return e3.region.toUpperCase();
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
const e2 = t2.split(/[-_]/);
|
|
84
|
+
if (e2.length > 1) return e2[1]?.toUpperCase() || null;
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function hasCountry(t2) {
|
|
90
|
+
const r = f;
|
|
91
|
+
return t2.toUpperCase() in r;
|
|
92
|
+
}
|
|
93
|
+
function getCountry(e2, r) {
|
|
94
|
+
const n2 = MasksFullMap(r), o2 = e2.toUpperCase();
|
|
95
|
+
return o2 in n2 ? { id: o2, ...n2[o2] } : { id: "US", ...n2.US };
|
|
96
|
+
}
|
|
97
|
+
function parseCountryCode(t2, e2) {
|
|
98
|
+
return t2 && hasCountry(t2) ? t2.toUpperCase() : e2 || "";
|
|
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, e2) {
|
|
110
|
+
if (1 === t2.length) return t2[0];
|
|
111
|
+
const r = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), n2 = r.filter((t3) => t3.count >= e2).sort((t3, e3) => t3.count - e3.count);
|
|
112
|
+
if (n2.length > 0) return n2[0].mask;
|
|
113
|
+
const o2 = r.sort((t3, e3) => e3.count - t3.count)[0];
|
|
114
|
+
return o2 ? o2.mask : t2[0];
|
|
115
|
+
}
|
|
116
|
+
function formatDigitsWithMap(t2, e2) {
|
|
117
|
+
let r = "";
|
|
118
|
+
const n2 = [];
|
|
119
|
+
let o2 = 0;
|
|
120
|
+
const a = e2.length, s2 = t2.length;
|
|
121
|
+
for (let c = 0; c < s2; c++) {
|
|
122
|
+
const s3 = t2[c];
|
|
123
|
+
if ("#" === s3) {
|
|
124
|
+
if (!(o2 < a)) break;
|
|
125
|
+
r += e2[o2], n2.push(o2), o2++;
|
|
126
|
+
} else {
|
|
127
|
+
const e3 = -1 !== t2.indexOf("#", c + 1) && o2 < a;
|
|
128
|
+
(r.length > 0 || e3) && (r += s3, n2.push(-1));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return { display: r, map: n2 };
|
|
132
|
+
}
|
|
133
|
+
function filterCountries(t2, e2) {
|
|
134
|
+
const r = e2.trim().toUpperCase();
|
|
135
|
+
if (!r) return t2;
|
|
136
|
+
const n2 = r.replace(/\D/g, ""), o2 = n2.length > 0;
|
|
137
|
+
return t2.map((t3) => {
|
|
138
|
+
const e3 = t3.name.toUpperCase(), a = t3.id.toUpperCase(), s2 = t3.code.toUpperCase(), c = t3.code.replace(/\D/g, "");
|
|
139
|
+
let i2 = 0;
|
|
140
|
+
return e3.startsWith(r) ? i2 = 1e3 : e3.includes(r) && (i2 = 500), s2.startsWith(r) ? i2 += 100 : s2.includes(r) && (i2 += 50), a === r ? i2 += 200 : a.startsWith(r) && (i2 += 150), o2 && c.startsWith(n2) ? i2 += 80 : o2 && c.includes(n2) && (i2 += 40), { country: t3, score: i2 };
|
|
141
|
+
}).filter((t3) => t3.score > 0).sort((t3, e3) => e3.score !== t3.score ? e3.score - t3.score : t3.country.name.localeCompare(e3.country.name)).map((t3) => t3.country);
|
|
142
|
+
}
|
|
143
|
+
const t = [" ", "-", "(", ")"], e$1 = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], i = /[^\d\s\-()]/;
|
|
144
|
+
function extractDigits(t2, e2) {
|
|
145
|
+
const i2 = t2.replace(/\D/g, "");
|
|
146
|
+
return e2 ? i2.slice(0, e2) : i2;
|
|
147
|
+
}
|
|
148
|
+
function getSelection(t2) {
|
|
149
|
+
return t2 ? [t2.selectionStart ?? 0, t2.selectionEnd ?? 0] : [0, 0];
|
|
150
|
+
}
|
|
151
|
+
function setCaret(t2, e2) {
|
|
152
|
+
if (t2) try {
|
|
153
|
+
t2.setSelectionRange(e2, e2);
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function processBeforeInput(t2) {
|
|
158
|
+
if (!t2.target) return;
|
|
159
|
+
const e2 = t2.target, n2 = t2.data;
|
|
160
|
+
"insertText" === t2.inputType && n2 && (i.test(n2) || " " === n2 && e2.value.endsWith(" ")) && t2.preventDefault();
|
|
161
|
+
}
|
|
162
|
+
function processInput(t2, e2) {
|
|
163
|
+
if (!t2.target) return;
|
|
164
|
+
const i2 = t2.target, { formatter: n2 } = e2, r = n2.getMaxDigits(), s2 = extractDigits(i2.value, r);
|
|
165
|
+
return { newDigits: s2, caretDigitIndex: s2.length };
|
|
166
|
+
}
|
|
167
|
+
function processKeydown(i2, n2) {
|
|
168
|
+
if (!i2.target) return;
|
|
169
|
+
const r = i2.target, { digits: s2, formatter: c } = n2;
|
|
170
|
+
if (i2.ctrlKey || i2.metaKey || i2.altKey || e$1.includes(i2.key)) return;
|
|
171
|
+
const [g, a] = getSelection(r);
|
|
172
|
+
if ("Backspace" !== i2.key) if ("Delete" !== i2.key) /^[0-9]$/.test(i2.key) ? s2.length >= c.getMaxDigits() && i2.preventDefault() : 1 === i2.key.length && i2.preventDefault();
|
|
173
|
+
else {
|
|
174
|
+
if (i2.preventDefault(), g !== a) {
|
|
175
|
+
const t2 = c.getDigitRange(s2, g, a);
|
|
176
|
+
if (t2) {
|
|
177
|
+
const [e2, i3] = t2;
|
|
178
|
+
return { newDigits: s2.slice(0, e2) + s2.slice(i3), caretDigitIndex: e2 };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (g < r.value.length) {
|
|
182
|
+
const t2 = c.getDigitRange(s2, g, r.value.length);
|
|
183
|
+
if (t2) {
|
|
184
|
+
const [e2] = t2;
|
|
185
|
+
return { newDigits: s2.slice(0, e2) + s2.slice(e2 + 1), caretDigitIndex: e2 };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
if (i2.preventDefault(), g !== a) {
|
|
191
|
+
const t2 = c.getDigitRange(s2, g, a);
|
|
192
|
+
if (t2) {
|
|
193
|
+
const [e2, i3] = t2;
|
|
194
|
+
return { newDigits: s2.slice(0, e2) + s2.slice(i3), caretDigitIndex: e2 };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (g > 0) {
|
|
198
|
+
const e2 = r.value;
|
|
199
|
+
let i3 = g - 1;
|
|
200
|
+
for (; i3 >= 0 && t.includes(e2[i3]); ) i3--;
|
|
201
|
+
if (i3 >= 0) {
|
|
202
|
+
const t2 = c.getDigitRange(s2, i3, i3 + 1);
|
|
203
|
+
if (t2) {
|
|
204
|
+
const [e3] = t2;
|
|
205
|
+
return { newDigits: s2.slice(0, e3) + s2.slice(e3 + 1), caretDigitIndex: e3 };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function processPaste(t2, e2) {
|
|
212
|
+
if (!t2.target) return;
|
|
213
|
+
t2.preventDefault();
|
|
214
|
+
const i2 = t2.target, { digits: n2, formatter: r } = e2, s2 = t2.clipboardData?.getData("text") || "", c = r.getMaxDigits(), g = extractDigits(s2, c);
|
|
215
|
+
if (0 === g.length) return;
|
|
216
|
+
const [a, o2] = getSelection(i2);
|
|
217
|
+
if (a !== o2) {
|
|
218
|
+
const t3 = r.getDigitRange(n2, a, o2);
|
|
219
|
+
if (t3) {
|
|
220
|
+
const [e3, i3] = t3;
|
|
221
|
+
return { newDigits: extractDigits(n2.slice(0, e3) + g + n2.slice(i3), c), caretDigitIndex: e3 + g.length };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const l = r.getDigitRange(n2, 0, a), f2 = l ? l[1] : 0;
|
|
225
|
+
return { newDigits: extractDigits(n2.slice(0, f2) + g + n2.slice(f2), c), caretDigitIndex: f2 + g.length };
|
|
226
|
+
}
|
|
227
|
+
function createPhoneFormatter(o2) {
|
|
228
|
+
const a = toArray(o2.mask), i2 = a.map((n2) => countPlaceholders(removeCountryCodePrefix(n2))), g = Math.max(...i2), getMask = (t2) => {
|
|
229
|
+
const n2 = pickMaskVariant(a, t2);
|
|
230
|
+
return removeCountryCodePrefix(n2);
|
|
231
|
+
};
|
|
232
|
+
return { formatDisplay: (t2) => {
|
|
233
|
+
const e2 = getMask(t2.length);
|
|
234
|
+
return formatDigitsWithMap(e2, t2).display;
|
|
235
|
+
}, getMaxDigits: () => g, getPlaceholder: () => getMask(0), getCaretPosition: (t2) => {
|
|
236
|
+
const e2 = getMask(t2), { display: r, map: l } = formatDigitsWithMap(e2, "0".repeat(t2));
|
|
237
|
+
for (let e3 = 0; e3 < l.length; e3++) if (l[e3] === t2) return e3;
|
|
238
|
+
if (t2 >= l.length) return r.length;
|
|
239
|
+
for (let e3 = 0; e3 < l.length; e3++) if (l[e3] > t2) return e3;
|
|
240
|
+
return r.length;
|
|
241
|
+
}, getDigitRange: (t2, e2, r) => {
|
|
242
|
+
const l = getMask(t2.length), { map: o3 } = formatDigitsWithMap(l, t2);
|
|
243
|
+
let a2 = 1 / 0, i3 = -1 / 0;
|
|
244
|
+
for (let t3 = e2; t3 < r && t3 < o3.length; t3++) {
|
|
245
|
+
const e3 = o3[t3];
|
|
246
|
+
void 0 !== e3 && e3 >= 0 && (a2 = Math.min(a2, e3), i3 = Math.max(i3, e3));
|
|
247
|
+
}
|
|
248
|
+
return a2 === 1 / 0 ? null : [a2, i3 + 1];
|
|
249
|
+
}, isComplete: (t2) => i2.includes(t2.length) };
|
|
250
|
+
}
|
|
251
|
+
const o = "https://ipapi.co/json/", e = 1500, p = "@desource/phone-mask:geo", s = 864e5;
|
|
252
|
+
async function detectCountryFromGeoIP(t2 = o, r = e) {
|
|
253
|
+
const n2 = new AbortController(), c = setTimeout(() => n2.abort(), r);
|
|
254
|
+
try {
|
|
255
|
+
const o2 = await fetch(t2, { signal: n2.signal, headers: { Accept: "application/json" } });
|
|
256
|
+
if (clearTimeout(c), !o2.ok) return null;
|
|
257
|
+
const e2 = await o2.json();
|
|
258
|
+
return (e2.country || e2.country_code || e2.countryCode || e2.country_code2 || "").toString().toUpperCase() || null;
|
|
259
|
+
} catch {
|
|
260
|
+
return clearTimeout(c), null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async function detectByGeoIp() {
|
|
264
|
+
try {
|
|
265
|
+
const o3 = localStorage.getItem(p);
|
|
266
|
+
if (o3) {
|
|
267
|
+
const e3 = JSON.parse(o3), c = Date.now() - e3.ts > s, a = parseCountryCode(e3.country_code);
|
|
268
|
+
if (a && !c) return a;
|
|
269
|
+
localStorage.removeItem(p);
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
}
|
|
273
|
+
const o2 = await detectCountryFromGeoIP(), e2 = parseCountryCode(o2);
|
|
274
|
+
if (e2) {
|
|
275
|
+
try {
|
|
276
|
+
const t2 = JSON.stringify({ country_code: e2, ts: Date.now() });
|
|
277
|
+
localStorage.setItem(p, t2);
|
|
278
|
+
} catch {
|
|
279
|
+
}
|
|
280
|
+
return e2;
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
function useCountry({
|
|
285
|
+
country: countryOption,
|
|
286
|
+
locale: localeOption,
|
|
287
|
+
detect,
|
|
288
|
+
onCountryChange
|
|
289
|
+
} = {}) {
|
|
290
|
+
let countryCode = $.state($.proxy(parseCountryCode(countryOption?.(), "US")));
|
|
291
|
+
const locale = $.derived(() => localeOption?.() || getNavigatorLang());
|
|
292
|
+
const country = $.derived(() => getCountry($.get(countryCode), $.get(locale)));
|
|
293
|
+
const setCountry = (code) => {
|
|
294
|
+
const parsed = parseCountryCode(code);
|
|
295
|
+
if (parsed) {
|
|
296
|
+
$.set(countryCode, parsed, true);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
};
|
|
301
|
+
const detectCountry = async () => {
|
|
302
|
+
const geoCountry = await detectByGeoIp();
|
|
303
|
+
if (setCountry(geoCountry)) return;
|
|
304
|
+
const localeCountry = detectCountryFromLocale();
|
|
305
|
+
setCountry(localeCountry);
|
|
306
|
+
};
|
|
307
|
+
$.user_effect(() => {
|
|
308
|
+
const newCountry = countryOption?.();
|
|
309
|
+
if (newCountry && newCountry !== $.get(countryCode)) {
|
|
310
|
+
setCountry(newCountry);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
$.user_effect(() => {
|
|
314
|
+
if (detect?.() && !countryOption?.()) {
|
|
315
|
+
detectCountry();
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
$.user_effect(() => {
|
|
319
|
+
onCountryChange?.($.get(country));
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
get country() {
|
|
323
|
+
return $.get(country);
|
|
324
|
+
},
|
|
325
|
+
get locale() {
|
|
326
|
+
return $.get(locale);
|
|
327
|
+
},
|
|
328
|
+
setCountry
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function useFormatter({ country, value, onChange, onPhoneChange, onValidationChange }) {
|
|
332
|
+
const formatter = $.derived(() => createPhoneFormatter(country()));
|
|
333
|
+
const maxDigits = $.derived(() => $.get(formatter).getMaxDigits());
|
|
334
|
+
const digits = $.derived(() => extractDigits(value(), $.get(maxDigits)));
|
|
335
|
+
const displayPlaceholder = $.derived(() => $.get(formatter).getPlaceholder());
|
|
336
|
+
const displayValue = $.derived(() => $.get(formatter).formatDisplay($.get(digits)));
|
|
337
|
+
const full = $.derived(() => $.get(digits) ? `${country().code}${$.get(digits)}` : "");
|
|
338
|
+
const fullFormatted = $.derived(() => $.get(displayValue) ? `${country().code} ${$.get(displayValue)}` : "");
|
|
339
|
+
const isComplete = $.derived(() => $.get(formatter).isComplete($.get(digits)));
|
|
340
|
+
const isEmpty = $.derived(() => $.get(digits).length === 0);
|
|
341
|
+
const shouldShowWarn = $.derived(() => !$.get(isEmpty) && !$.get(isComplete));
|
|
342
|
+
const phoneData = $.derived(() => ({
|
|
343
|
+
full: $.get(full),
|
|
344
|
+
fullFormatted: $.get(fullFormatted),
|
|
345
|
+
digits: $.get(digits)
|
|
346
|
+
}));
|
|
347
|
+
$.user_pre_effect(() => {
|
|
348
|
+
const raw = value();
|
|
349
|
+
const clamped = $.get(digits);
|
|
350
|
+
if (raw !== clamped) {
|
|
351
|
+
onChange(clamped);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
$.user_effect(() => {
|
|
355
|
+
onPhoneChange?.($.get(phoneData));
|
|
356
|
+
});
|
|
357
|
+
$.user_effect(() => {
|
|
358
|
+
onValidationChange?.($.get(isComplete));
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
get digits() {
|
|
362
|
+
return $.get(digits);
|
|
363
|
+
},
|
|
364
|
+
get formatter() {
|
|
365
|
+
return $.get(formatter);
|
|
366
|
+
},
|
|
367
|
+
get displayPlaceholder() {
|
|
368
|
+
return $.get(displayPlaceholder);
|
|
369
|
+
},
|
|
370
|
+
get displayValue() {
|
|
371
|
+
return $.get(displayValue);
|
|
372
|
+
},
|
|
373
|
+
get full() {
|
|
374
|
+
return $.get(full);
|
|
375
|
+
},
|
|
376
|
+
get fullFormatted() {
|
|
377
|
+
return $.get(fullFormatted);
|
|
378
|
+
},
|
|
379
|
+
get isComplete() {
|
|
380
|
+
return $.get(isComplete);
|
|
381
|
+
},
|
|
382
|
+
get isEmpty() {
|
|
383
|
+
return $.get(isEmpty);
|
|
384
|
+
},
|
|
385
|
+
get shouldShowWarn() {
|
|
386
|
+
return $.get(shouldShowWarn);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function useTimer() {
|
|
391
|
+
let timerRef = null;
|
|
392
|
+
const clear = () => {
|
|
393
|
+
if (timerRef) {
|
|
394
|
+
clearTimeout(timerRef);
|
|
395
|
+
timerRef = null;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
const set = (callback, delay) => {
|
|
399
|
+
clear();
|
|
400
|
+
timerRef = setTimeout(callback, delay);
|
|
401
|
+
};
|
|
402
|
+
onDestroy(clear);
|
|
403
|
+
return { set, clear };
|
|
404
|
+
}
|
|
405
|
+
function useValidationHint() {
|
|
406
|
+
let showValidationHint = $.state(false);
|
|
407
|
+
const validationTimer = useTimer();
|
|
408
|
+
const clearValidationHint = (hideHint = true) => {
|
|
409
|
+
if (hideHint) $.set(showValidationHint, false);
|
|
410
|
+
validationTimer.clear();
|
|
411
|
+
};
|
|
412
|
+
const scheduleValidationHint = (delay) => {
|
|
413
|
+
$.set(showValidationHint, false);
|
|
414
|
+
validationTimer.set(
|
|
415
|
+
() => {
|
|
416
|
+
$.set(showValidationHint, true);
|
|
417
|
+
},
|
|
418
|
+
delay
|
|
419
|
+
);
|
|
420
|
+
};
|
|
421
|
+
return {
|
|
422
|
+
get showValidationHint() {
|
|
423
|
+
return $.get(showValidationHint);
|
|
424
|
+
},
|
|
425
|
+
clearValidationHint,
|
|
426
|
+
scheduleValidationHint
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const HINT_DELAY_INPUT = 500;
|
|
430
|
+
const HINT_DELAY_ACTION = 300;
|
|
431
|
+
function useInputHandlers(options) {
|
|
432
|
+
const {
|
|
433
|
+
formatter,
|
|
434
|
+
digits,
|
|
435
|
+
inactive,
|
|
436
|
+
onChange,
|
|
437
|
+
scheduleValidationHint
|
|
438
|
+
} = options;
|
|
439
|
+
const scheduleCaretUpdate = (el, digitIndex) => {
|
|
440
|
+
tick().then(() => {
|
|
441
|
+
if (!el) return;
|
|
442
|
+
const pos = formatter().getCaretPosition(digitIndex);
|
|
443
|
+
setCaret(el, pos);
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
const handleBeforeInput = (e2) => {
|
|
447
|
+
processBeforeInput(e2);
|
|
448
|
+
};
|
|
449
|
+
const handleInput = (e2) => {
|
|
450
|
+
if (inactive?.()) return;
|
|
451
|
+
const result = processInput(e2, { formatter: formatter() });
|
|
452
|
+
if (!result) return;
|
|
453
|
+
onChange?.(result.newDigits);
|
|
454
|
+
scheduleCaretUpdate(e2.target, result.caretDigitIndex);
|
|
455
|
+
scheduleValidationHint?.(HINT_DELAY_INPUT);
|
|
456
|
+
};
|
|
457
|
+
const handleKeydown = (e2) => {
|
|
458
|
+
if (inactive?.()) return;
|
|
459
|
+
const result = processKeydown(e2, { digits: digits(), formatter: formatter() });
|
|
460
|
+
if (!result) return;
|
|
461
|
+
onChange?.(result.newDigits);
|
|
462
|
+
scheduleCaretUpdate(e2.target, result.caretDigitIndex);
|
|
463
|
+
scheduleValidationHint?.(HINT_DELAY_ACTION);
|
|
464
|
+
};
|
|
465
|
+
const handlePaste = (e2) => {
|
|
466
|
+
if (inactive?.()) return;
|
|
467
|
+
const result = processPaste(e2, { digits: digits(), formatter: formatter() });
|
|
468
|
+
if (!result) return;
|
|
469
|
+
onChange?.(result.newDigits);
|
|
470
|
+
scheduleCaretUpdate(e2.target, result.caretDigitIndex);
|
|
471
|
+
scheduleValidationHint?.(HINT_DELAY_ACTION);
|
|
472
|
+
};
|
|
473
|
+
return { handleBeforeInput, handleInput, handleKeydown, handlePaste };
|
|
474
|
+
}
|
|
475
|
+
function useCountrySelector({
|
|
476
|
+
rootRef,
|
|
477
|
+
dropdownRef,
|
|
478
|
+
searchRef,
|
|
479
|
+
selectorRef,
|
|
480
|
+
locale,
|
|
481
|
+
countryOption,
|
|
482
|
+
inactive,
|
|
483
|
+
onSelectCountry,
|
|
484
|
+
onAfterSelect
|
|
485
|
+
}) {
|
|
486
|
+
let search = $.state("");
|
|
487
|
+
let dropdownOpen = $.state(false);
|
|
488
|
+
let isClosing = $.state(false);
|
|
489
|
+
let dropdownStyle = $.state($.proxy({}));
|
|
490
|
+
let focusedIndex = $.state(0);
|
|
491
|
+
const countries = $.derived(() => MasksFull(locale()));
|
|
492
|
+
const filteredCountries = $.derived(() => filterCountries($.get(countries), $.get(search)));
|
|
493
|
+
const hasDropdown = $.derived(() => !countryOption?.() && $.get(countries).length > 1);
|
|
494
|
+
const setFocusedIndex = (index) => {
|
|
495
|
+
$.set(focusedIndex, index, true);
|
|
496
|
+
};
|
|
497
|
+
const focusSearch = () => {
|
|
498
|
+
tick().then(() => searchRef()?.focus({ preventScroll: true }));
|
|
499
|
+
};
|
|
500
|
+
const closeDropdown = () => {
|
|
501
|
+
if (!$.get(dropdownOpen)) return;
|
|
502
|
+
$.set(isClosing, true);
|
|
503
|
+
};
|
|
504
|
+
const openDropdown = () => {
|
|
505
|
+
$.set(isClosing, false);
|
|
506
|
+
$.set(dropdownOpen, true);
|
|
507
|
+
setFocusedIndex(0);
|
|
508
|
+
focusSearch();
|
|
509
|
+
};
|
|
510
|
+
const handleDropdownAnimationEnd = () => {
|
|
511
|
+
if (!$.get(isClosing)) return;
|
|
512
|
+
$.set(dropdownOpen, false);
|
|
513
|
+
$.set(isClosing, false);
|
|
514
|
+
};
|
|
515
|
+
const toggleDropdown = () => {
|
|
516
|
+
if (inactive?.() || !$.get(hasDropdown)) return;
|
|
517
|
+
if ($.get(dropdownOpen)) {
|
|
518
|
+
closeDropdown();
|
|
519
|
+
} else {
|
|
520
|
+
openDropdown();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const selectCountry = (code) => {
|
|
524
|
+
onSelectCountry(code);
|
|
525
|
+
closeDropdown();
|
|
526
|
+
$.set(search, "");
|
|
527
|
+
setFocusedIndex(0);
|
|
528
|
+
onAfterSelect?.();
|
|
529
|
+
};
|
|
530
|
+
const handleSearchChange = (e2) => {
|
|
531
|
+
$.set(search, e2.target.value, true);
|
|
532
|
+
setFocusedIndex(0);
|
|
533
|
+
};
|
|
534
|
+
const onDocClick = (ev) => {
|
|
535
|
+
const target = ev.target;
|
|
536
|
+
const dropdownEl = dropdownRef();
|
|
537
|
+
const selectorEl = selectorRef();
|
|
538
|
+
if (!target) return;
|
|
539
|
+
if (dropdownEl?.contains(target)) return;
|
|
540
|
+
if (selectorEl?.contains(target)) return;
|
|
541
|
+
closeDropdown();
|
|
542
|
+
};
|
|
543
|
+
const positionDropdown = (e2) => {
|
|
544
|
+
if (e2?.type === "scroll" && e2.target && dropdownRef()?.contains(e2.target)) return;
|
|
545
|
+
const root2 = rootRef();
|
|
546
|
+
if (!root2) return;
|
|
547
|
+
const rect = root2.getBoundingClientRect();
|
|
548
|
+
$.set(
|
|
549
|
+
dropdownStyle,
|
|
550
|
+
{
|
|
551
|
+
top: `${rect.bottom + window.scrollY + 8}px`,
|
|
552
|
+
left: `${rect.left + window.scrollX}px`,
|
|
553
|
+
width: `${rect.width}px`
|
|
554
|
+
},
|
|
555
|
+
true
|
|
556
|
+
);
|
|
557
|
+
};
|
|
558
|
+
const scrollFocusedIntoView = () => {
|
|
559
|
+
tick().then(() => {
|
|
560
|
+
const list = dropdownRef()?.lastElementChild;
|
|
561
|
+
const option = list?.children[$.get(focusedIndex)];
|
|
562
|
+
if (!list || !option) return;
|
|
563
|
+
const listRect = list.getBoundingClientRect();
|
|
564
|
+
const optionRect = option.getBoundingClientRect();
|
|
565
|
+
let scrollAmount = 0;
|
|
566
|
+
if (optionRect.top < listRect.top) {
|
|
567
|
+
scrollAmount = list.scrollTop - (listRect.top - optionRect.top);
|
|
568
|
+
} else if (optionRect.bottom > listRect.bottom) {
|
|
569
|
+
scrollAmount = list.scrollTop + (optionRect.bottom - listRect.bottom);
|
|
570
|
+
} else {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
list.scrollTo({ top: scrollAmount, behavior: "smooth" });
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
const handleSearchKeydown = (e2) => {
|
|
577
|
+
if (e2.key === "ArrowDown") {
|
|
578
|
+
e2.preventDefault();
|
|
579
|
+
setFocusedIndex(Math.min($.get(focusedIndex) + 1, $.get(filteredCountries).length - 1));
|
|
580
|
+
scrollFocusedIntoView();
|
|
581
|
+
} else if (e2.key === "ArrowUp") {
|
|
582
|
+
e2.preventDefault();
|
|
583
|
+
setFocusedIndex(Math.max($.get(focusedIndex) - 1, 0));
|
|
584
|
+
scrollFocusedIntoView();
|
|
585
|
+
} else if (e2.key === "Enter" && $.get(filteredCountries)[$.get(focusedIndex)]) {
|
|
586
|
+
e2.preventDefault();
|
|
587
|
+
selectCountry($.get(filteredCountries)[$.get(focusedIndex)].id);
|
|
588
|
+
} else if (e2.key === "Escape") {
|
|
589
|
+
closeDropdown();
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
const removeListeners = () => {
|
|
593
|
+
window.removeEventListener("resize", positionDropdown);
|
|
594
|
+
window.removeEventListener("scroll", positionDropdown, true);
|
|
595
|
+
window.removeEventListener("click", onDocClick, true);
|
|
596
|
+
};
|
|
597
|
+
$.user_effect(() => {
|
|
598
|
+
if (!$.get(hasDropdown) && $.get(dropdownOpen)) {
|
|
599
|
+
closeDropdown();
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
$.user_effect(() => {
|
|
603
|
+
if (!$.get(dropdownOpen)) {
|
|
604
|
+
removeListeners();
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
positionDropdown();
|
|
608
|
+
window.addEventListener("resize", positionDropdown);
|
|
609
|
+
window.addEventListener("scroll", positionDropdown, true);
|
|
610
|
+
window.addEventListener("click", onDocClick, true);
|
|
611
|
+
});
|
|
612
|
+
onDestroy(removeListeners);
|
|
613
|
+
return {
|
|
614
|
+
get dropdownOpen() {
|
|
615
|
+
return $.get(dropdownOpen);
|
|
616
|
+
},
|
|
617
|
+
get isClosing() {
|
|
618
|
+
return $.get(isClosing);
|
|
619
|
+
},
|
|
620
|
+
get search() {
|
|
621
|
+
return $.get(search);
|
|
622
|
+
},
|
|
623
|
+
get focusedIndex() {
|
|
624
|
+
return $.get(focusedIndex);
|
|
625
|
+
},
|
|
626
|
+
get dropdownStyle() {
|
|
627
|
+
return $.get(dropdownStyle);
|
|
628
|
+
},
|
|
629
|
+
get filteredCountries() {
|
|
630
|
+
return $.get(filteredCountries);
|
|
631
|
+
},
|
|
632
|
+
get hasDropdown() {
|
|
633
|
+
return $.get(hasDropdown);
|
|
634
|
+
},
|
|
635
|
+
openDropdown,
|
|
636
|
+
closeDropdown,
|
|
637
|
+
toggleDropdown,
|
|
638
|
+
selectCountry,
|
|
639
|
+
setFocusedIndex,
|
|
640
|
+
handleSearchChange,
|
|
641
|
+
handleSearchKeydown,
|
|
642
|
+
handleDropdownAnimationEnd
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function useClipboard(delay = 1800) {
|
|
646
|
+
let copied = $.state(false);
|
|
647
|
+
let isCopying = $.state(false);
|
|
648
|
+
const copyTimer = useTimer();
|
|
649
|
+
const copy = async (text) => {
|
|
650
|
+
if ($.get(isCopying)) return false;
|
|
651
|
+
const trimmedText = text.trim();
|
|
652
|
+
if (!trimmedText) return false;
|
|
653
|
+
$.set(isCopying, true);
|
|
654
|
+
try {
|
|
655
|
+
await navigator.clipboard.writeText(trimmedText);
|
|
656
|
+
$.set(copied, true);
|
|
657
|
+
copyTimer.set(
|
|
658
|
+
() => {
|
|
659
|
+
$.set(copied, false);
|
|
660
|
+
},
|
|
661
|
+
delay
|
|
662
|
+
);
|
|
663
|
+
return true;
|
|
664
|
+
} catch (err) {
|
|
665
|
+
console.warn("Copy failed", err);
|
|
666
|
+
return false;
|
|
667
|
+
} finally {
|
|
668
|
+
$.set(isCopying, false);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
return {
|
|
672
|
+
get copied() {
|
|
673
|
+
return $.get(copied);
|
|
674
|
+
},
|
|
675
|
+
get isCopying() {
|
|
676
|
+
return $.get(isCopying);
|
|
677
|
+
},
|
|
678
|
+
copy
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
const DELAY = 1800;
|
|
682
|
+
function useCopyAction({ liveRef, fullFormatted, onCopy }) {
|
|
683
|
+
const liveTimer = useTimer();
|
|
684
|
+
const clipboard = useClipboard(DELAY);
|
|
685
|
+
const copyAriaLabel = $.derived(() => clipboard.copied ? "Copied" : `Copy ${fullFormatted()}`);
|
|
686
|
+
const copyButtonTitle = $.derived(() => clipboard.copied ? "Copied" : "Copy phone number");
|
|
687
|
+
const announceToScreenReader = (message) => {
|
|
688
|
+
const el = liveRef?.();
|
|
689
|
+
if (!el) return;
|
|
690
|
+
el.textContent = message;
|
|
691
|
+
liveTimer.set(
|
|
692
|
+
() => {
|
|
693
|
+
const el2 = liveRef?.();
|
|
694
|
+
if (el2) el2.textContent = "";
|
|
695
|
+
},
|
|
696
|
+
DELAY
|
|
697
|
+
);
|
|
698
|
+
};
|
|
699
|
+
const onCopyClick = async () => {
|
|
700
|
+
const valueToCopy = fullFormatted().trim();
|
|
701
|
+
const success = await clipboard.copy(valueToCopy);
|
|
702
|
+
if (success) {
|
|
703
|
+
onCopy?.(valueToCopy);
|
|
704
|
+
announceToScreenReader("Phone number copied to clipboard");
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
return {
|
|
708
|
+
get copied() {
|
|
709
|
+
return clipboard.copied;
|
|
710
|
+
},
|
|
711
|
+
get copyAriaLabel() {
|
|
712
|
+
return $.get(copyAriaLabel);
|
|
713
|
+
},
|
|
714
|
+
get copyButtonTitle() {
|
|
715
|
+
return $.get(copyButtonTitle);
|
|
716
|
+
},
|
|
717
|
+
onCopyClick
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
function useTheme({ theme }) {
|
|
721
|
+
let systemDark = $.state(false);
|
|
722
|
+
const themeClass = $.derived(() => theme() !== "auto" ? `theme-${theme()}` : $.get(systemDark) ? "theme-dark" : "theme-light");
|
|
723
|
+
$.user_effect(() => {
|
|
724
|
+
if (typeof window === "undefined") return;
|
|
725
|
+
const mq = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
|
|
726
|
+
if (!mq) return;
|
|
727
|
+
$.set(systemDark, mq.matches, true);
|
|
728
|
+
const handler = (e2) => {
|
|
729
|
+
$.set(systemDark, e2.matches, true);
|
|
730
|
+
};
|
|
731
|
+
mq.addEventListener("change", handler);
|
|
732
|
+
return () => mq.removeEventListener("change", handler);
|
|
733
|
+
});
|
|
734
|
+
return {
|
|
735
|
+
get themeClass() {
|
|
736
|
+
return $.get(themeClass);
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
var root_3 = $.from_svg(`<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><path d="M2.5 4.5L6 8L9.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>`);
|
|
741
|
+
var root_7 = $.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><path d="M6.5 11.5L3 8L4.06 6.94L6.5 9.38L11.94 3.94L13 5L6.5 11.5Z" fill="currentColor"></path></svg>`);
|
|
742
|
+
var root_8 = $.from_svg(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><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"></path></svg>`);
|
|
743
|
+
var root_5 = $.from_html(`<button type="button"><!></button>`);
|
|
744
|
+
var root_11 = $.from_svg(`<svg width="11" height="11" viewBox="0 0 14 14" fill="none" aria-hidden="true"><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"></path></svg>`);
|
|
745
|
+
var root_9 = $.from_html(`<button type="button" class="pi-btn pi-btn-clear"><!></button>`);
|
|
746
|
+
var root_13 = $.from_html(`<li role="option"><span class="pi-flag" role="img"><!></span> <span class="pi-opt-name"> </span> <span class="pi-opt-code"> </span></li>`);
|
|
747
|
+
var root_16 = $.from_html(`<li class="pi-empty"> </li>`);
|
|
748
|
+
var root_12 = $.from_html(`<div role="dialog" aria-modal="false" aria-label="Select country"><div class="pi-search-wrap"><input type="search" class="pi-search" aria-label="Search countries"/></div> <ul class="pi-options" role="listbox" tabindex="-1"></ul></div>`);
|
|
749
|
+
var root = $.from_html(`<div><div class="pi-selector"><button type="button"><span class="pi-flag" role="img"><!></span> <span class="pi-code"> </span> <!></button></div> <div class="pi-input-wrap"><input type="tel" inputmode="tel" autocomplete="tel-national" autocorrect="off" autocapitalize="off" spellcheck="false" class="pi-input"/> <div class="pi-actions" role="toolbar" aria-label="Phone input actions"><!> <!> <!></div></div></div> <!> <div class="sr-only" role="status" aria-live="polite" aria-atomic="true"></div>`, 1);
|
|
750
|
+
function PhoneInput$1($$anchor, $$props) {
|
|
751
|
+
$.push($$props, true);
|
|
752
|
+
let value = $.prop($$props, "value", 15, ""), detect = $.prop($$props, "detect", 3, true), size = $.prop($$props, "size", 3, "normal"), theme = $.prop($$props, "theme", 3, "auto"), disabled = $.prop($$props, "disabled", 3, false), readonly = $.prop($$props, "readonly", 3, false), showCopy = $.prop($$props, "showCopy", 3, true), showClear = $.prop($$props, "showClear", 3, false), withValidity = $.prop($$props, "withValidity", 3, true), searchPlaceholder = $.prop($$props, "searchPlaceholder", 3, "Search country or code..."), noResultsText = $.prop($$props, "noResultsText", 3, "No countries found"), clearButtonLabel = $.prop($$props, "clearButtonLabel", 3, "Clear phone number"), dropdownClass = $.prop($$props, "dropdownClass", 3, ""), disableDefaultStyles = $.prop($$props, "disableDefaultStyles", 3, false), restProps = $.rest_props($$props, [
|
|
753
|
+
"$$slots",
|
|
754
|
+
"$$events",
|
|
755
|
+
"$$legacy",
|
|
756
|
+
"value",
|
|
757
|
+
"country",
|
|
758
|
+
"detect",
|
|
759
|
+
"locale",
|
|
760
|
+
"size",
|
|
761
|
+
"theme",
|
|
762
|
+
"disabled",
|
|
763
|
+
"readonly",
|
|
764
|
+
"showCopy",
|
|
765
|
+
"showClear",
|
|
766
|
+
"withValidity",
|
|
767
|
+
"searchPlaceholder",
|
|
768
|
+
"noResultsText",
|
|
769
|
+
"clearButtonLabel",
|
|
770
|
+
"dropdownClass",
|
|
771
|
+
"disableDefaultStyles",
|
|
772
|
+
"onchange",
|
|
773
|
+
"oncountrychange",
|
|
774
|
+
"onvalidationchange",
|
|
775
|
+
"onfocus",
|
|
776
|
+
"onblur",
|
|
777
|
+
"oncopy",
|
|
778
|
+
"onclear",
|
|
779
|
+
"flag",
|
|
780
|
+
"copysvg",
|
|
781
|
+
"clearsvg",
|
|
782
|
+
"actionsbefore",
|
|
783
|
+
"class"
|
|
784
|
+
]);
|
|
785
|
+
let rootEl = $.state(null);
|
|
786
|
+
let telEl = $.state(null);
|
|
787
|
+
let liveEl = $.state(null);
|
|
788
|
+
let dropdownEl = $.state(null);
|
|
789
|
+
let searchEl = $.state(null);
|
|
790
|
+
let selectorEl = $.state(null);
|
|
791
|
+
const countryData = useCountry({
|
|
792
|
+
country: () => $$props.country,
|
|
793
|
+
locale: () => $$props.locale,
|
|
794
|
+
detect: () => detect(),
|
|
795
|
+
onCountryChange: (...args) => $$props.oncountrychange?.(...args)
|
|
796
|
+
});
|
|
797
|
+
const formatterData = useFormatter({
|
|
798
|
+
country: () => countryData.country,
|
|
799
|
+
value: () => value(),
|
|
800
|
+
onChange: (v) => value(v),
|
|
801
|
+
onPhoneChange: (...args) => $$props.onchange?.(...args),
|
|
802
|
+
onValidationChange: (...args) => $$props.onvalidationchange?.(...args)
|
|
803
|
+
});
|
|
804
|
+
const validationHint = useValidationHint();
|
|
805
|
+
const inactive = $.derived(() => disabled() || readonly());
|
|
806
|
+
const incomplete = $.derived(() => validationHint.showValidationHint && formatterData.shouldShowWarn);
|
|
807
|
+
const showCopyButton = $.derived(() => showCopy() && !formatterData.isEmpty && !disabled());
|
|
808
|
+
const showClearButton = $.derived(() => showClear() && !formatterData.isEmpty && !$.get(inactive));
|
|
809
|
+
const copyData = useCopyAction({
|
|
810
|
+
liveRef: () => $.get(liveEl),
|
|
811
|
+
fullFormatted: () => formatterData.fullFormatted,
|
|
812
|
+
onCopy: (...args) => $$props.oncopy?.(...args)
|
|
813
|
+
});
|
|
814
|
+
const focusInput = () => tick().then(() => $.get(telEl)?.focus());
|
|
815
|
+
const selectorData = useCountrySelector({
|
|
816
|
+
rootRef: () => $.get(rootEl),
|
|
817
|
+
dropdownRef: () => $.get(dropdownEl),
|
|
818
|
+
searchRef: () => $.get(searchEl),
|
|
819
|
+
selectorRef: () => $.get(selectorEl),
|
|
820
|
+
locale: () => countryData.locale,
|
|
821
|
+
countryOption: () => $$props.country,
|
|
822
|
+
inactive: () => $.get(inactive),
|
|
823
|
+
onSelectCountry: countryData.setCountry,
|
|
824
|
+
onAfterSelect: focusInput
|
|
825
|
+
});
|
|
826
|
+
const inputHandlers = useInputHandlers({
|
|
827
|
+
formatter: () => formatterData.formatter,
|
|
828
|
+
digits: () => formatterData.digits,
|
|
829
|
+
inactive: () => $.get(inactive),
|
|
830
|
+
onChange: (v) => value(v),
|
|
831
|
+
scheduleValidationHint: validationHint.scheduleValidationHint
|
|
832
|
+
});
|
|
833
|
+
const handleFocus = (e2) => {
|
|
834
|
+
validationHint.clearValidationHint(false);
|
|
835
|
+
selectorData.closeDropdown();
|
|
836
|
+
$$props.onfocus?.(e2);
|
|
837
|
+
};
|
|
838
|
+
const handleBlur = (e2) => $$props.onblur?.(e2);
|
|
839
|
+
function focus() {
|
|
840
|
+
focusInput();
|
|
841
|
+
}
|
|
842
|
+
function blur() {
|
|
843
|
+
$.get(telEl)?.blur();
|
|
844
|
+
}
|
|
845
|
+
function clear() {
|
|
846
|
+
value("");
|
|
847
|
+
validationHint.clearValidationHint();
|
|
848
|
+
$$props.onclear?.();
|
|
849
|
+
}
|
|
850
|
+
function selectCountry(code) {
|
|
851
|
+
countryData.setCountry(code);
|
|
852
|
+
}
|
|
853
|
+
function getFullNumber() {
|
|
854
|
+
return formatterData.full;
|
|
855
|
+
}
|
|
856
|
+
function getFullFormattedNumber() {
|
|
857
|
+
return formatterData.fullFormatted;
|
|
858
|
+
}
|
|
859
|
+
function getDigits() {
|
|
860
|
+
return formatterData.digits;
|
|
861
|
+
}
|
|
862
|
+
function isValid() {
|
|
863
|
+
return formatterData.isComplete;
|
|
864
|
+
}
|
|
865
|
+
function isComplete() {
|
|
866
|
+
return formatterData.isComplete;
|
|
867
|
+
}
|
|
868
|
+
const handleClearClick = () => {
|
|
869
|
+
clear();
|
|
870
|
+
focusInput();
|
|
871
|
+
};
|
|
872
|
+
const themeData = useTheme({ theme: () => theme() });
|
|
873
|
+
const rootClasses = $.derived(() => [
|
|
874
|
+
"phone-input",
|
|
875
|
+
`size-${size()}`,
|
|
876
|
+
themeData.themeClass,
|
|
877
|
+
disabled() && "is-disabled",
|
|
878
|
+
readonly() && "is-readonly",
|
|
879
|
+
disableDefaultStyles() && "is-unstyled",
|
|
880
|
+
withValidity() && $.get(incomplete) && "is-incomplete",
|
|
881
|
+
withValidity() && formatterData.isComplete && "is-complete",
|
|
882
|
+
$$props.class
|
|
883
|
+
].filter(Boolean).join(" "));
|
|
884
|
+
const actionsCount = $.derived(() => +$.get(showCopyButton) + +$.get(showClearButton) + ($$props.actionsbefore ? 1 : 0));
|
|
885
|
+
function portal(node) {
|
|
886
|
+
document.body.appendChild(node);
|
|
887
|
+
return { destroy: () => node.remove() };
|
|
888
|
+
}
|
|
889
|
+
var $$exports = {
|
|
890
|
+
focus,
|
|
891
|
+
blur,
|
|
892
|
+
clear,
|
|
893
|
+
selectCountry,
|
|
894
|
+
getFullNumber,
|
|
895
|
+
getFullFormattedNumber,
|
|
896
|
+
getDigits,
|
|
897
|
+
isValid,
|
|
898
|
+
isComplete
|
|
899
|
+
};
|
|
900
|
+
var fragment = root();
|
|
901
|
+
var div = $.first_child(fragment);
|
|
902
|
+
$.attribute_effect(div, () => ({
|
|
903
|
+
class: $.get(rootClasses),
|
|
904
|
+
...restProps,
|
|
905
|
+
role: "group",
|
|
906
|
+
"aria-label": "Phone input with country selector",
|
|
907
|
+
[$.STYLE]: { "--pi-actions-count": $.get(actionsCount) }
|
|
908
|
+
}));
|
|
909
|
+
var div_1 = $.child(div);
|
|
910
|
+
var button = $.child(div_1);
|
|
911
|
+
let classes;
|
|
912
|
+
var span = $.child(button);
|
|
913
|
+
var node_1 = $.child(span);
|
|
914
|
+
{
|
|
915
|
+
var consequent = ($$anchor2) => {
|
|
916
|
+
var fragment_1 = $.comment();
|
|
917
|
+
var node_2 = $.first_child(fragment_1);
|
|
918
|
+
$.snippet(node_2, () => $$props.flag, () => countryData.country);
|
|
919
|
+
$.append($$anchor2, fragment_1);
|
|
920
|
+
};
|
|
921
|
+
var alternate = ($$anchor2) => {
|
|
922
|
+
var text = $.text();
|
|
923
|
+
$.template_effect(() => $.set_text(text, countryData.country.flag));
|
|
924
|
+
$.append($$anchor2, text);
|
|
925
|
+
};
|
|
926
|
+
$.if(node_1, ($$render) => {
|
|
927
|
+
if ($$props.flag) $$render(consequent);
|
|
928
|
+
else $$render(alternate, -1);
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
$.reset(span);
|
|
932
|
+
var span_1 = $.sibling(span, 2);
|
|
933
|
+
var text_1 = $.child(span_1, true);
|
|
934
|
+
$.reset(span_1);
|
|
935
|
+
var node_3 = $.sibling(span_1, 2);
|
|
936
|
+
{
|
|
937
|
+
var consequent_1 = ($$anchor2) => {
|
|
938
|
+
var svg = root_3();
|
|
939
|
+
let classes_1;
|
|
940
|
+
$.template_effect(() => classes_1 = $.set_class(svg, 0, "pi-chevron", null, classes_1, { "is-open": selectorData.dropdownOpen }));
|
|
941
|
+
$.append($$anchor2, svg);
|
|
942
|
+
};
|
|
943
|
+
$.if(node_3, ($$render) => {
|
|
944
|
+
if (!$.get(inactive) && selectorData.hasDropdown) $$render(consequent_1);
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
$.reset(button);
|
|
948
|
+
$.reset(div_1);
|
|
949
|
+
$.bind_this(div_1, ($$value) => $.set(selectorEl, $$value), () => $.get(selectorEl));
|
|
950
|
+
var div_2 = $.sibling(div_1, 2);
|
|
951
|
+
var input = $.child(div_2);
|
|
952
|
+
$.remove_input_defaults(input);
|
|
953
|
+
$.bind_this(input, ($$value) => $.set(telEl, $$value), () => $.get(telEl));
|
|
954
|
+
var div_3 = $.sibling(input, 2);
|
|
955
|
+
var node_4 = $.child(div_3);
|
|
956
|
+
{
|
|
957
|
+
var consequent_2 = ($$anchor2) => {
|
|
958
|
+
var fragment_3 = $.comment();
|
|
959
|
+
var node_5 = $.first_child(fragment_3);
|
|
960
|
+
$.snippet(node_5, () => $$props.actionsbefore);
|
|
961
|
+
$.append($$anchor2, fragment_3);
|
|
962
|
+
};
|
|
963
|
+
$.if(node_4, ($$render) => {
|
|
964
|
+
if ($$props.actionsbefore) $$render(consequent_2);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
var node_6 = $.sibling(node_4, 2);
|
|
968
|
+
{
|
|
969
|
+
var consequent_5 = ($$anchor2) => {
|
|
970
|
+
var button_1 = root_5();
|
|
971
|
+
let classes_2;
|
|
972
|
+
var node_7 = $.child(button_1);
|
|
973
|
+
{
|
|
974
|
+
var consequent_3 = ($$anchor3) => {
|
|
975
|
+
var fragment_4 = $.comment();
|
|
976
|
+
var node_8 = $.first_child(fragment_4);
|
|
977
|
+
$.snippet(node_8, () => $$props.copysvg, () => copyData.copied);
|
|
978
|
+
$.append($$anchor3, fragment_4);
|
|
979
|
+
};
|
|
980
|
+
var consequent_4 = ($$anchor3) => {
|
|
981
|
+
var svg_1 = root_7();
|
|
982
|
+
$.append($$anchor3, svg_1);
|
|
983
|
+
};
|
|
984
|
+
var alternate_1 = ($$anchor3) => {
|
|
985
|
+
var svg_2 = root_8();
|
|
986
|
+
$.append($$anchor3, svg_2);
|
|
987
|
+
};
|
|
988
|
+
$.if(node_7, ($$render) => {
|
|
989
|
+
if ($$props.copysvg) $$render(consequent_3);
|
|
990
|
+
else if (copyData.copied) $$render(consequent_4, 1);
|
|
991
|
+
else $$render(alternate_1, -1);
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
$.reset(button_1);
|
|
995
|
+
$.template_effect(() => {
|
|
996
|
+
classes_2 = $.set_class(button_1, 1, "pi-btn pi-btn-copy", null, classes_2, { "is-copied": copyData.copied });
|
|
997
|
+
$.set_attribute(button_1, "aria-label", copyData.copyAriaLabel);
|
|
998
|
+
$.set_attribute(button_1, "title", copyData.copyButtonTitle);
|
|
999
|
+
});
|
|
1000
|
+
$.delegated("click", button_1, function(...$$args) {
|
|
1001
|
+
copyData.onCopyClick?.apply(this, $$args);
|
|
1002
|
+
});
|
|
1003
|
+
$.append($$anchor2, button_1);
|
|
1004
|
+
};
|
|
1005
|
+
$.if(node_6, ($$render) => {
|
|
1006
|
+
if ($.get(showCopyButton)) $$render(consequent_5);
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
var node_9 = $.sibling(node_6, 2);
|
|
1010
|
+
{
|
|
1011
|
+
var consequent_7 = ($$anchor2) => {
|
|
1012
|
+
var button_2 = root_9();
|
|
1013
|
+
var node_10 = $.child(button_2);
|
|
1014
|
+
{
|
|
1015
|
+
var consequent_6 = ($$anchor3) => {
|
|
1016
|
+
var fragment_5 = $.comment();
|
|
1017
|
+
var node_11 = $.first_child(fragment_5);
|
|
1018
|
+
$.snippet(node_11, () => $$props.clearsvg);
|
|
1019
|
+
$.append($$anchor3, fragment_5);
|
|
1020
|
+
};
|
|
1021
|
+
var alternate_2 = ($$anchor3) => {
|
|
1022
|
+
var svg_3 = root_11();
|
|
1023
|
+
$.append($$anchor3, svg_3);
|
|
1024
|
+
};
|
|
1025
|
+
$.if(node_10, ($$render) => {
|
|
1026
|
+
if ($$props.clearsvg) $$render(consequent_6);
|
|
1027
|
+
else $$render(alternate_2, -1);
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
$.reset(button_2);
|
|
1031
|
+
$.template_effect(() => {
|
|
1032
|
+
$.set_attribute(button_2, "aria-label", clearButtonLabel());
|
|
1033
|
+
$.set_attribute(button_2, "title", clearButtonLabel());
|
|
1034
|
+
});
|
|
1035
|
+
$.delegated("click", button_2, handleClearClick);
|
|
1036
|
+
$.append($$anchor2, button_2);
|
|
1037
|
+
};
|
|
1038
|
+
$.if(node_9, ($$render) => {
|
|
1039
|
+
if ($.get(showClearButton)) $$render(consequent_7);
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
$.reset(div_3);
|
|
1043
|
+
$.reset(div_2);
|
|
1044
|
+
$.reset(div);
|
|
1045
|
+
$.bind_this(div, ($$value) => $.set(rootEl, $$value), () => $.get(rootEl));
|
|
1046
|
+
var node_12 = $.sibling(div, 2);
|
|
1047
|
+
{
|
|
1048
|
+
var consequent_9 = ($$anchor2) => {
|
|
1049
|
+
var div_4 = root_12();
|
|
1050
|
+
let classes_3;
|
|
1051
|
+
let styles;
|
|
1052
|
+
var div_5 = $.child(div_4);
|
|
1053
|
+
var input_1 = $.child(div_5);
|
|
1054
|
+
$.remove_input_defaults(input_1);
|
|
1055
|
+
$.bind_this(input_1, ($$value) => $.set(searchEl, $$value), () => $.get(searchEl));
|
|
1056
|
+
$.reset(div_5);
|
|
1057
|
+
var ul = $.sibling(div_5, 2);
|
|
1058
|
+
$.each(
|
|
1059
|
+
ul,
|
|
1060
|
+
23,
|
|
1061
|
+
() => selectorData.filteredCountries,
|
|
1062
|
+
(c) => c.id,
|
|
1063
|
+
($$anchor3, c, idx) => {
|
|
1064
|
+
var li = root_13();
|
|
1065
|
+
let classes_4;
|
|
1066
|
+
var span_2 = $.child(li);
|
|
1067
|
+
var node_13 = $.child(span_2);
|
|
1068
|
+
{
|
|
1069
|
+
var consequent_8 = ($$anchor4) => {
|
|
1070
|
+
var fragment_6 = $.comment();
|
|
1071
|
+
var node_14 = $.first_child(fragment_6);
|
|
1072
|
+
$.snippet(node_14, () => $$props.flag, () => $.get(c));
|
|
1073
|
+
$.append($$anchor4, fragment_6);
|
|
1074
|
+
};
|
|
1075
|
+
var alternate_3 = ($$anchor4) => {
|
|
1076
|
+
var text_2 = $.text();
|
|
1077
|
+
$.template_effect(() => $.set_text(text_2, $.get(c).flag));
|
|
1078
|
+
$.append($$anchor4, text_2);
|
|
1079
|
+
};
|
|
1080
|
+
$.if(node_13, ($$render) => {
|
|
1081
|
+
if ($$props.flag) $$render(consequent_8);
|
|
1082
|
+
else $$render(alternate_3, -1);
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
$.reset(span_2);
|
|
1086
|
+
var span_3 = $.sibling(span_2, 2);
|
|
1087
|
+
var text_3 = $.child(span_3, true);
|
|
1088
|
+
$.reset(span_3);
|
|
1089
|
+
var span_4 = $.sibling(span_3, 2);
|
|
1090
|
+
var text_4 = $.child(span_4, true);
|
|
1091
|
+
$.reset(span_4);
|
|
1092
|
+
$.reset(li);
|
|
1093
|
+
$.template_effect(() => {
|
|
1094
|
+
$.set_attribute(li, "id", `option-${$.get(idx) ?? ""}`);
|
|
1095
|
+
classes_4 = $.set_class(li, 1, "pi-option", null, classes_4, {
|
|
1096
|
+
"is-focused": $.get(idx) === selectorData.focusedIndex,
|
|
1097
|
+
"is-selected": $.get(c).id === countryData.country.id
|
|
1098
|
+
});
|
|
1099
|
+
$.set_attribute(li, "aria-selected", $.get(c).id === countryData.country.id);
|
|
1100
|
+
$.set_attribute(li, "title", $.get(c).name);
|
|
1101
|
+
$.set_attribute(span_2, "aria-label", `${$.get(c).name ?? ""} flag`);
|
|
1102
|
+
$.set_text(text_3, $.get(c).name);
|
|
1103
|
+
$.set_text(text_4, $.get(c).code);
|
|
1104
|
+
});
|
|
1105
|
+
$.delegated("click", li, () => selectorData.selectCountry($.get(c).id));
|
|
1106
|
+
$.delegated("keydown", li, (e2) => {
|
|
1107
|
+
if (e2.key === "Enter" || e2.key === " ") {
|
|
1108
|
+
e2.preventDefault();
|
|
1109
|
+
selectorData.selectCountry($.get(c).id);
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
$.event("mouseenter", li, () => selectorData.setFocusedIndex($.get(idx)));
|
|
1113
|
+
$.append($$anchor3, li);
|
|
1114
|
+
},
|
|
1115
|
+
($$anchor3) => {
|
|
1116
|
+
var li_1 = root_16();
|
|
1117
|
+
var text_5 = $.child(li_1, true);
|
|
1118
|
+
$.reset(li_1);
|
|
1119
|
+
$.template_effect(() => $.set_text(text_5, noResultsText()));
|
|
1120
|
+
$.append($$anchor3, li_1);
|
|
1121
|
+
}
|
|
1122
|
+
);
|
|
1123
|
+
$.reset(ul);
|
|
1124
|
+
$.reset(div_4);
|
|
1125
|
+
$.action(div_4, ($$node) => portal?.($$node));
|
|
1126
|
+
$.bind_this(div_4, ($$value) => $.set(dropdownEl, $$value), () => $.get(dropdownEl));
|
|
1127
|
+
$.template_effect(() => {
|
|
1128
|
+
classes_3 = $.set_class(div_4, 1, `phone-dropdown ${dropdownClass() ?? ""} ${themeData.themeClass ?? ""}`, null, classes_3, { "is-closing": selectorData.isClosing });
|
|
1129
|
+
styles = $.set_style(div_4, "", styles, {
|
|
1130
|
+
position: "absolute",
|
|
1131
|
+
top: selectorData.dropdownStyle.top,
|
|
1132
|
+
left: selectorData.dropdownStyle.left,
|
|
1133
|
+
width: selectorData.dropdownStyle.width
|
|
1134
|
+
});
|
|
1135
|
+
$.set_attribute(input_1, "placeholder", searchPlaceholder());
|
|
1136
|
+
$.set_value(input_1, selectorData.search);
|
|
1137
|
+
$.set_attribute(ul, "aria-activedescendant", `option-${selectorData.focusedIndex ?? ""}`);
|
|
1138
|
+
});
|
|
1139
|
+
$.event("animationend", div_4, function(...$$args) {
|
|
1140
|
+
selectorData.handleDropdownAnimationEnd?.apply(this, $$args);
|
|
1141
|
+
});
|
|
1142
|
+
$.delegated("keydown", input_1, function(...$$args) {
|
|
1143
|
+
selectorData.handleSearchKeydown?.apply(this, $$args);
|
|
1144
|
+
});
|
|
1145
|
+
$.delegated("input", input_1, function(...$$args) {
|
|
1146
|
+
selectorData.handleSearchChange?.apply(this, $$args);
|
|
1147
|
+
});
|
|
1148
|
+
$.append($$anchor2, div_4);
|
|
1149
|
+
};
|
|
1150
|
+
$.if(node_12, ($$render) => {
|
|
1151
|
+
if (selectorData.dropdownOpen) $$render(consequent_9);
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
var div_6 = $.sibling(node_12, 2);
|
|
1155
|
+
$.bind_this(div_6, ($$value) => $.set(liveEl, $$value), () => $.get(liveEl));
|
|
1156
|
+
$.template_effect(() => {
|
|
1157
|
+
classes = $.set_class(button, 1, "pi-selector-btn", null, classes, { "no-dropdown": !selectorData.hasDropdown || readonly() });
|
|
1158
|
+
button.disabled = disabled();
|
|
1159
|
+
$.set_attribute(button, "tabindex", $.get(inactive) || !selectorData.hasDropdown ? -1 : void 0);
|
|
1160
|
+
$.set_attribute(button, "aria-label", `Selected country: ${countryData.country.name ?? ""}`);
|
|
1161
|
+
$.set_attribute(button, "aria-expanded", selectorData.dropdownOpen);
|
|
1162
|
+
$.set_attribute(button, "aria-haspopup", selectorData.hasDropdown ? "listbox" : void 0);
|
|
1163
|
+
$.set_attribute(span, "aria-label", `${countryData.country.name ?? ""} flag`);
|
|
1164
|
+
$.set_text(text_1, countryData.country.code);
|
|
1165
|
+
$.set_attribute(input, "placeholder", formatterData.displayPlaceholder);
|
|
1166
|
+
$.set_value(input, formatterData.displayValue);
|
|
1167
|
+
input.disabled = disabled();
|
|
1168
|
+
input.readOnly = readonly();
|
|
1169
|
+
$.set_attribute(input, "aria-invalid", $.get(incomplete));
|
|
1170
|
+
});
|
|
1171
|
+
$.delegated("click", button, function(...$$args) {
|
|
1172
|
+
selectorData.toggleDropdown?.apply(this, $$args);
|
|
1173
|
+
});
|
|
1174
|
+
$.delegated("beforeinput", input, function(...$$args) {
|
|
1175
|
+
inputHandlers.handleBeforeInput?.apply(this, $$args);
|
|
1176
|
+
});
|
|
1177
|
+
$.delegated("input", input, function(...$$args) {
|
|
1178
|
+
inputHandlers.handleInput?.apply(this, $$args);
|
|
1179
|
+
});
|
|
1180
|
+
$.delegated("keydown", input, function(...$$args) {
|
|
1181
|
+
inputHandlers.handleKeydown?.apply(this, $$args);
|
|
1182
|
+
});
|
|
1183
|
+
$.event("paste", input, function(...$$args) {
|
|
1184
|
+
inputHandlers.handlePaste?.apply(this, $$args);
|
|
1185
|
+
});
|
|
1186
|
+
$.event("focus", input, handleFocus);
|
|
1187
|
+
$.event("blur", input, handleBlur);
|
|
1188
|
+
$.append($$anchor, fragment);
|
|
1189
|
+
return $.pop($$exports);
|
|
1190
|
+
}
|
|
1191
|
+
$.delegate(["click", "beforeinput", "input", "keydown"]);
|
|
1192
|
+
function usePhoneMask(options) {
|
|
1193
|
+
let inputRef = $.state(null);
|
|
1194
|
+
const countryData = useCountry({
|
|
1195
|
+
country: options.country,
|
|
1196
|
+
locale: options.locale,
|
|
1197
|
+
detect: options.detect,
|
|
1198
|
+
onCountryChange: options.onCountryChange
|
|
1199
|
+
});
|
|
1200
|
+
const formatterData = useFormatter({
|
|
1201
|
+
country: () => countryData.country,
|
|
1202
|
+
value: options.value,
|
|
1203
|
+
onChange: options.onChange,
|
|
1204
|
+
onPhoneChange: options.onPhoneChange
|
|
1205
|
+
});
|
|
1206
|
+
const { handleBeforeInput, handleInput, handleKeydown, handlePaste } = useInputHandlers({
|
|
1207
|
+
formatter: () => formatterData.formatter,
|
|
1208
|
+
digits: () => formatterData.digits,
|
|
1209
|
+
onChange: options.onChange
|
|
1210
|
+
});
|
|
1211
|
+
$.user_effect(() => {
|
|
1212
|
+
const el = $.get(inputRef);
|
|
1213
|
+
if (!el) return;
|
|
1214
|
+
el.setAttribute("type", "tel");
|
|
1215
|
+
el.setAttribute("inputmode", "tel");
|
|
1216
|
+
el.addEventListener("beforeinput", handleBeforeInput);
|
|
1217
|
+
el.addEventListener("input", handleInput);
|
|
1218
|
+
el.addEventListener("keydown", handleKeydown);
|
|
1219
|
+
el.addEventListener("paste", handlePaste);
|
|
1220
|
+
return () => {
|
|
1221
|
+
el.removeEventListener("beforeinput", handleBeforeInput);
|
|
1222
|
+
el.removeEventListener("input", handleInput);
|
|
1223
|
+
el.removeEventListener("keydown", handleKeydown);
|
|
1224
|
+
el.removeEventListener("paste", handlePaste);
|
|
1225
|
+
};
|
|
1226
|
+
});
|
|
1227
|
+
$.user_effect(() => {
|
|
1228
|
+
const el = $.get(inputRef);
|
|
1229
|
+
if (!el) return;
|
|
1230
|
+
el.value = formatterData.displayValue;
|
|
1231
|
+
el.setAttribute("placeholder", formatterData.displayPlaceholder);
|
|
1232
|
+
});
|
|
1233
|
+
const clear = () => {
|
|
1234
|
+
options.onChange("");
|
|
1235
|
+
};
|
|
1236
|
+
return {
|
|
1237
|
+
get inputRef() {
|
|
1238
|
+
return $.get(inputRef);
|
|
1239
|
+
},
|
|
1240
|
+
set inputRef(el) {
|
|
1241
|
+
$.set(inputRef, el, true);
|
|
1242
|
+
},
|
|
1243
|
+
get digits() {
|
|
1244
|
+
return formatterData.digits;
|
|
1245
|
+
},
|
|
1246
|
+
get full() {
|
|
1247
|
+
return formatterData.full;
|
|
1248
|
+
},
|
|
1249
|
+
get fullFormatted() {
|
|
1250
|
+
return formatterData.fullFormatted;
|
|
1251
|
+
},
|
|
1252
|
+
get isComplete() {
|
|
1253
|
+
return formatterData.isComplete;
|
|
1254
|
+
},
|
|
1255
|
+
get isEmpty() {
|
|
1256
|
+
return formatterData.isEmpty;
|
|
1257
|
+
},
|
|
1258
|
+
get shouldShowWarn() {
|
|
1259
|
+
return formatterData.shouldShowWarn;
|
|
1260
|
+
},
|
|
1261
|
+
get country() {
|
|
1262
|
+
return countryData.country;
|
|
1263
|
+
},
|
|
1264
|
+
get locale() {
|
|
1265
|
+
return countryData.locale;
|
|
1266
|
+
},
|
|
1267
|
+
setCountry: countryData.setCountry,
|
|
1268
|
+
clear
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
const PhoneInput = PhoneInput$1;
|
|
1272
|
+
const PMaskHelpers = {
|
|
1273
|
+
getFlagEmoji: k,
|
|
1274
|
+
countPlaceholders,
|
|
1275
|
+
formatDigitsWithMap,
|
|
1276
|
+
pickMaskVariant,
|
|
1277
|
+
removeCountryCodePrefix,
|
|
1278
|
+
toArray
|
|
1279
|
+
};
|
|
1280
|
+
export {
|
|
1281
|
+
PMaskHelpers,
|
|
1282
|
+
PhoneInput,
|
|
1283
|
+
usePhoneMask
|
|
1284
|
+
};
|