UNPKG

v-phone-input

Version:

International phone field for Vuetify 3 and Vue 3.

1,051 lines (1,050 loc) 33.4 kB
import { computed as c, defineComponent as nn, h as q, ref as S, watchEffect as En, onBeforeMount as Kn, onBeforeUpdate as Fn, useSlots as On, useAttrs as Un, markRaw as un, watch as A, onMounted as wn, nextTick as ln, createElementBlock as dn, openBlock as O, mergeProps as Dn, renderSlot as I, normalizeProps as b, guardReactiveProps as L, createBlock as k, resolveDynamicComponent as Z, unref as g, createSlots as pn, withCtx as N, createVNode as Hn, createElementVNode as $n, toDisplayString as Q, createCommentVNode as kn, renderList as yn } from "vue"; import { getSupportedRegionCodes as Zn, getCountryCodeForRegionCode as Wn, getExample as _n, parsePhoneNumber as zn } from "awesome-phonenumber"; import { VTextField as Cn, VSelect as Jn, VListItem as vn } from "vuetify/components"; function mn() { return { country: { required: !0, type: Object }, decorative: { type: Boolean, default: !1 } }; } function Sn({ props: n }) { const e = c(() => n.decorative ? void 0 : "img"), a = c(() => n.decorative ? void 0 : n.country.name); return { role: e, title: a }; } const Yn = nn({ props: mn(), setup(n) { const { role: e, title: a } = Sn({ props: n }); return () => q("span", { role: e.value, title: a.value, class: ["v-phone-input__country__icon", "f32"] }, q("span", { class: ["flag", n.country.iso2.toLowerCase()] })); } }), xn = nn({ props: mn(), setup(n) { const { role: e, title: a } = Sn({ props: n }); return () => q("span", { role: e.value, title: a.value, class: [ "v-phone-input__country__icon", "fi", `fi-${n.country.iso2.toLowerCase()}` ] }); } }); function Qn(n) { return "setPreference" in n; } function U(n) { return n && typeof n == "object" ? n.iso2 : (n || "").toUpperCase(); } function jn({ props: n }) { const e = Zn(), a = S({}), r = S(0), l = S([]), o = S([]), $ = c(() => n.preferCountries.map(U)), y = c(() => n.includeCountries.map(U)), V = c(() => n.excludeCountries.map(U)); En(() => { const p = {}, E = [], K = []; n.allCountries.forEach((C) => { const M = U(C.iso2); if (e.indexOf(M) === -1 || y.value.length && y.value.indexOf(M) === -1 || V.value.indexOf(M) !== -1) return; const h = { ...C, iso2: M }; p[h.iso2] = h, $.value.indexOf(M) !== -1 ? E.push(h) : K.push(h); }), E.sort((C, M) => $.value.indexOf(C.iso2) - $.value.indexOf(M.iso2)), a.value = p, l.value = E, o.value = K, r.value = E.length + K.length, r.value || console.error('[v-phone-input] resulting countries from "allCountries", "includeCountries" and "excludeCountries" must be a non-empty list'); }); const w = c(() => { const p = l.value[0] ?? o.value[0]; return p ? a.value[p.iso2] : void 0; }), R = (p) => a.value[U(p)], G = S(!1), D = c(() => !n.disableGuessLoading && G.value); return { countriesCount: r, preferredCountries: l, otherCountries: o, guessingCountry: D, findCountry: R, firstCountry: w, setCountryPreference: (p) => { G.value = !1, Qn(n.countryGuesser) && n.countryGuesser.setPreference(p); }, guessCountry: async () => { if (!n.guessCountry) return; G.value = !0; const p = R(await n.countryGuesser.guess()); return G.value = !1, p == null ? void 0 : p.iso2; } }; } function Xn({ props: n }) { return { countryIconComponent: c(() => { switch (n.countryIconMode) { case "svg": return xn; case "sprite": return Yn; case "text": return; default: return n.countryIconMode; } }) }; } function qn({ props: n }) { return { countrySelectComponent: c(() => n.enableSearchingCountry ? { type: "VAutocomplete", props: { autocomplete: "new-password", "aria-autocomplete": "off", filterKeys: ["raw.name", "raw.iso2", "raw.dialCode"] } } : { type: "VSelect", props: {} }) }; } function nt({ props: n, country: e, example: a }) { const r = (B, H) => typeof B == "function" ? B(H) : B, l = c(() => ({ country: e.value, example: a.value })), o = c(() => r(n.label, l.value)), $ = c(() => r(n.ariaLabel, l.value)), y = c(() => ({ ...l.value, label: o.value || $.value })), V = c(() => r(n.countryLabel, y.value)), w = c( () => r(n.countryAriaLabel, y.value) ), R = c(() => r(n.placeholder, y.value)), G = c(() => r(n.hint, y.value)), D = c( () => r(n.invalidMessage, y.value) ); return { label: o, ariaLabel: $, countryLabel: V, countryAriaLabel: w, placeholder: R, hint: G, invalidMessage: D, messageOptions: l }; } function tt(n, e) { const a = S({}), r = () => { const l = {}; Object.keys(n).forEach((o) => { const [$, ...y] = o.split(":"); !y.length || e.indexOf($) === -1 ? l.default = { ...l.default || {}, [o]: o } : l[$] = { ...l[$] || {}, [y.join(":")]: o }; }), a.value = l; }; return Kn(r), Fn(r), { namespacedSlots: a }; } const ot = "Andorra", et = "United Arab Emirates", at = "Afghanistan", st = "Antigua and Barbuda", ct = "Anguilla", rt = "Albania", it = "Armenia", ut = "Angola", lt = "Antarctica", dt = "Argentina", pt = "American Samoa", $t = "Austria", yt = "Australia", Ct = "Aruba", vt = "Aland", mt = "Azerbaijan", St = "Bosnia and Herzegovina", Mt = "Barbados", ft = "Bangladesh", gt = "Belgium", ht = "Burkina Faso", It = "Bulgaria", Gt = "Bahrain", Bt = "Burundi", Tt = "Benin", At = "Saint Barthelemy", Pt = "Bermuda", bt = "Brunei", Lt = "Bolivia", Nt = "Bonaire", Vt = "Brazil", Rt = "Bahamas", Et = "Bhutan", Kt = "Bouvet Island", Ft = "Botswana", Ot = "Belarus", Ut = "Belize", wt = "Canada", Dt = "Cocos (Keeling) Islands", Ht = "Democratic Republic of the Congo", kt = "Central African Republic", Zt = "Republic of the Congo", Wt = "Switzerland", _t = "Ivory Coast", zt = "Cook Islands", Jt = "Chile", Yt = "Cameroon", xt = "China", Qt = "Colombia", jt = "Costa Rica", Xt = "Cuba", qt = "Cape Verde", no = "Curacao", to = "Christmas Island", oo = "Cyprus", eo = "Czech Republic", ao = "Germany", so = "Djibouti", co = "Denmark", ro = "Dominica", io = "Dominican Republic", uo = "Algeria", lo = "Ecuador", po = "Estonia", $o = "Egypt", yo = "Western Sahara", Co = "Eritrea", vo = "Spain", mo = "Ethiopia", So = "Finland", Mo = "Fiji", fo = "Falkland Islands", go = "Micronesia", ho = "Faroe Islands", Io = "France", Go = "Gabon", Bo = "United Kingdom", To = "Grenada", Ao = "Georgia", Po = "French Guiana", bo = "Guernsey", Lo = "Ghana", No = "Gibraltar", Vo = "Greenland", Ro = "Gambia", Eo = "Guinea", Ko = "Guadeloupe", Fo = "Equatorial Guinea", Oo = "Greece", Uo = "South Georgia and the South Sandwich Islands", wo = "Guatemala", Do = "Guam", Ho = "Guinea-Bissau", ko = "Guyana", Zo = "Hong Kong", Wo = "Heard Island and McDonald Islands", _o = "Honduras", zo = "Croatia", Jo = "Haiti", Yo = "Hungary", xo = "Indonesia", Qo = "Ireland", jo = "Israel", Xo = "Isle of Man", qo = "India", ne = "British Indian Ocean Territory", te = "Iraq", oe = "Iran", ee = "Iceland", ae = "Italy", se = "Jersey", ce = "Jamaica", re = "Jordan", ie = "Japan", ue = "Kenya", le = "Kyrgyzstan", de = "Cambodia", pe = "Kiribati", $e = "Comoros", ye = "Saint Kitts and Nevis", Ce = "North Korea", ve = "South Korea", me = "Kuwait", Se = "Cayman Islands", Me = "Kazakhstan", fe = "Laos", ge = "Lebanon", he = "Saint Lucia", Ie = "Liechtenstein", Ge = "Sri Lanka", Be = "Liberia", Te = "Lesotho", Ae = "Lithuania", Pe = "Luxembourg", be = "Latvia", Le = "Libya", Ne = "Morocco", Ve = "Monaco", Re = "Moldova", Ee = "Montenegro", Ke = "Saint Martin", Fe = "Madagascar", Oe = "Marshall Islands", Ue = "North Macedonia", we = "Mali", De = "Myanmar (Burma)", He = "Mongolia", ke = "Macao", Ze = "Northern Mariana Islands", We = "Martinique", _e = "Mauritania", ze = "Montserrat", Je = "Malta", Ye = "Mauritius", xe = "Maldives", Qe = "Malawi", je = "Mexico", Xe = "Malaysia", qe = "Mozambique", na = "Namibia", ta = "New Caledonia", oa = "Niger", ea = "Norfolk Island", aa = "Nigeria", sa = "Nicaragua", ca = "Netherlands", ra = "Norway", ia = "Nepal", ua = "Nauru", la = "Niue", da = "New Zealand", pa = "Oman", $a = "Panama", ya = "Peru", Ca = "French Polynesia", va = "Papua New Guinea", ma = "Philippines", Sa = "Pakistan", Ma = "Poland", fa = "Saint Pierre and Miquelon", ga = "Pitcairn Islands", ha = "Puerto Rico", Ia = "Palestine", Ga = "Portugal", Ba = "Palau", Ta = "Paraguay", Aa = "Qatar", Pa = "Reunion", ba = "Romania", La = "Serbia", Na = "Russia", Va = "Rwanda", Ra = "Saudi Arabia", Ea = "Solomon Islands", Ka = "Seychelles", Fa = "Sudan", Oa = "Sweden", Ua = "Singapore", wa = "Saint Helena", Da = "Slovenia", Ha = "Svalbard and Jan Mayen", ka = "Slovakia", Za = "Sierra Leone", Wa = "San Marino", _a = "Senegal", za = "Somalia", Ja = "Suriname", Ya = "South Sudan", xa = "Sao Tome and Principe", Qa = "El Salvador", ja = "Sint Maarten", Xa = "Syria", qa = "Eswatini", ns = "Turks and Caicos Islands", ts = "Chad", os = "French Southern Territories", es = "Togo", as = "Thailand", ss = "Tajikistan", cs = "Tokelau", rs = "East Timor", is = "Turkmenistan", us = "Tunisia", ls = "Tonga", ds = "Turkey", ps = "Trinidad and Tobago", $s = "Tuvalu", ys = "Taiwan", Cs = "Tanzania", vs = "Ukraine", ms = "Uganda", Ss = "U.S. Minor Outlying Islands", Ms = "United States", fs = "Uruguay", gs = "Uzbekistan", hs = "Vatican City", Is = "Saint Vincent and the Grenadines", Gs = "Venezuela", Bs = "British Virgin Islands", Ts = "U.S. Virgin Islands", As = "Vietnam", Ps = "Vanuatu", bs = "Wallis and Futuna", Ls = "Samoa", Ns = "Kosovo", Vs = "Yemen", Rs = "Mayotte", Es = "South Africa", Ks = "Zambia", Fs = "Zimbabwe", Os = { AD: ot, AE: et, AF: at, AG: st, AI: ct, AL: rt, AM: it, AO: ut, AQ: lt, AR: dt, AS: pt, AT: $t, AU: yt, AW: Ct, AX: vt, AZ: mt, BA: St, BB: Mt, BD: ft, BE: gt, BF: ht, BG: It, BH: Gt, BI: Bt, BJ: Tt, BL: At, BM: Pt, BN: bt, BO: Lt, BQ: Nt, BR: Vt, BS: Rt, BT: Et, BV: Kt, BW: Ft, BY: Ot, BZ: Ut, CA: wt, CC: Dt, CD: Ht, CF: kt, CG: Zt, CH: Wt, CI: _t, CK: zt, CL: Jt, CM: Yt, CN: xt, CO: Qt, CR: jt, CU: Xt, CV: qt, CW: no, CX: to, CY: oo, CZ: eo, DE: ao, DJ: so, DK: co, DM: ro, DO: io, DZ: uo, EC: lo, EE: po, EG: $o, EH: yo, ER: Co, ES: vo, ET: mo, FI: So, FJ: Mo, FK: fo, FM: go, FO: ho, FR: Io, GA: Go, GB: Bo, GD: To, GE: Ao, GF: Po, GG: bo, GH: Lo, GI: No, GL: Vo, GM: Ro, GN: Eo, GP: Ko, GQ: Fo, GR: Oo, GS: Uo, GT: wo, GU: Do, GW: Ho, GY: ko, HK: Zo, HM: Wo, HN: _o, HR: zo, HT: Jo, HU: Yo, ID: xo, IE: Qo, IL: jo, IM: Xo, IN: qo, IO: ne, IQ: te, IR: oe, IS: ee, IT: ae, JE: se, JM: ce, JO: re, JP: ie, KE: ue, KG: le, KH: de, KI: pe, KM: $e, KN: ye, KP: Ce, KR: ve, KW: me, KY: Se, KZ: Me, LA: fe, LB: ge, LC: he, LI: Ie, LK: Ge, LR: Be, LS: Te, LT: Ae, LU: Pe, LV: be, LY: Le, MA: Ne, MC: Ve, MD: Re, ME: Ee, MF: Ke, MG: Fe, MH: Oe, MK: Ue, ML: we, MM: De, MN: He, MO: ke, MP: Ze, MQ: We, MR: _e, MS: ze, MT: Je, MU: Ye, MV: xe, MW: Qe, MX: je, MY: Xe, MZ: qe, NA: na, NC: ta, NE: oa, NF: ea, NG: aa, NI: sa, NL: ca, NO: ra, NP: ia, NR: ua, NU: la, NZ: da, OM: pa, PA: $a, PE: ya, PF: Ca, PG: va, PH: ma, PK: Sa, PL: Ma, PM: fa, PN: ga, PR: ha, PS: Ia, PT: Ga, PW: Ba, PY: Ta, QA: Aa, RE: Pa, RO: ba, RS: La, RU: Na, RW: Va, SA: Ra, SB: Ea, SC: Ka, SD: Fa, SE: Oa, SG: Ua, SH: wa, SI: Da, SJ: Ha, SK: ka, SL: Za, SM: Wa, SN: _a, SO: za, SR: Ja, SS: Ya, ST: xa, SV: Qa, SX: ja, SY: Xa, SZ: qa, TC: ns, TD: ts, TF: os, TG: es, TH: as, TJ: ss, TK: cs, TL: rs, TM: is, TN: us, TO: ls, TR: ds, TT: ps, TV: $s, TW: ys, TZ: Cs, UA: vs, UG: ms, UM: Ss, US: Ms, UY: fs, UZ: gs, VA: hs, VC: Is, VE: Gs, VG: Bs, VI: Ts, VN: As, VU: Ps, WF: bs, WS: Ls, XK: Ns, YE: Vs, YT: Rs, ZA: Es, ZM: Ks, ZW: Fs }, Us = "Andorra", ws = "دولة الإمارات العربية المتحدة", Ds = "افغانستان", Hs = "Antigua and Barbuda", ks = "Anguilla", Zs = "Shqipëria", Ws = "Հայաստան", _s = "Angola", zs = "Antarctica", Js = "Argentina", Ys = "American Samoa", xs = "Österreich", Qs = "Australia", js = "Aruba", Xs = "Åland", qs = "Azərbaycan", nc = "Bosna i Hercegovina", tc = "Barbados", oc = "Bangladesh", ec = "België", ac = "Burkina Faso", sc = "България", cc = "‏البحرين", rc = "Burundi", ic = "Bénin", uc = "Saint-Barthélemy", lc = "Bermuda", dc = "Negara Brunei Darussalam", pc = "Bolivia", $c = "Bonaire", yc = "Brasil", Cc = "Bahamas", vc = "ʼbrug-yul", mc = "Bouvetøya", Sc = "Botswana", Mc = "Белару́сь", fc = "Belize", gc = "Canada", hc = "Cocos (Keeling) Islands", Ic = "République démocratique du Congo", Gc = "Ködörösêse tî Bêafrîka", Bc = "République du Congo", Tc = "Schweiz", Ac = "Côte d'Ivoire", Pc = "Cook Islands", bc = "Chile", Lc = "Cameroon", Nc = "中国", Vc = "Colombia", Rc = "Costa Rica", Ec = "Cuba", Kc = "Cabo Verde", Fc = "Curaçao", Oc = "Christmas Island", Uc = "Κύπρος", wc = "Česká republika", Dc = "Deutschland", Hc = "Djibouti", kc = "Danmark", Zc = "Dominica", Wc = "República Dominicana", _c = "الجزائر", zc = "Ecuador", Jc = "Eesti", Yc = "مصر‎", xc = "الصحراء الغربية", Qc = "ኤርትራ", jc = "España", Xc = "ኢትዮጵያ", qc = "Suomi", nr = "Fiji", tr = "Falkland Islands", or = "Micronesia", er = "Føroyar", ar = "France", sr = "Gabon", cr = "United Kingdom", rr = "Grenada", ir = "საქართველო", ur = "Guyane française", lr = "Guernsey", dr = "Ghana", pr = "Gibraltar", $r = "Kalaallit Nunaat", yr = "Gambia", Cr = "Guinée", vr = "Guadeloupe", mr = "Guinea Ecuatorial", Sr = "Ελλάδα", Mr = "South Georgia", fr = "Guatemala", gr = "Guam", hr = "Guiné-Bissau", Ir = "Guyana", Gr = "香港", Br = "Heard Island and McDonald Islands", Tr = "Honduras", Ar = "Hrvatska", Pr = "Haïti", br = "Magyarország", Lr = "Indonesia", Nr = "Éire", Vr = "יִשְׂרָאֵל", Rr = "Isle of Man", Er = "भारत", Kr = "British Indian Ocean Territory", Fr = "العراق", Or = "ایران", Ur = "Ísland", wr = "Italia", Dr = "Jersey", Hr = "Jamaica", kr = "الأردن", Zr = "日本", Wr = "Kenya", _r = "Кыргызстан", zr = "Kâmpŭchéa", Jr = "Kiribati", Yr = "Komori", xr = "Saint Kitts and Nevis", Qr = "북한", jr = "대한민국", Xr = "الكويت", qr = "Cayman Islands", ni = "Қазақстан", ti = "ສປປລາວ", oi = "لبنان", ei = "Saint Lucia", ai = "Liechtenstein", si = "śrī laṃkāva", ci = "Liberia", ri = "Lesotho", ii = "Lietuva", ui = "Luxembourg", li = "Latvija", di = "‏ليبيا", pi = "المغرب", $i = "Monaco", yi = "Moldova", Ci = "Црна Гора", vi = "Saint-Martin", mi = "Madagasikara", Si = "M̧ajeļ", Mi = "Северна Македонија", fi = "Mali", gi = "မြန်မာ", hi = "Монгол улс", Ii = "澳門", Gi = "Northern Mariana Islands", Bi = "Martinique", Ti = "موريتانيا", Ai = "Montserrat", Pi = "Malta", bi = "Maurice", Li = "Maldives", Ni = "Malawi", Vi = "México", Ri = "Malaysia", Ei = "Moçambique", Ki = "Namibia", Fi = "Nouvelle-Calédonie", Oi = "Niger", Ui = "Norfolk Island", wi = "Nigeria", Di = "Nicaragua", Hi = "Nederland", ki = "Norge", Zi = "नेपाल", Wi = "Nauru", _i = "Niuē", zi = "New Zealand", Ji = "عمان", Yi = "Panamá", xi = "Perú", Qi = "Polynésie française", ji = "Papua Niugini", Xi = "Pilipinas", qi = "Pakistan", nu = "Polska", tu = "Saint-Pierre-et-Miquelon", ou = "Pitcairn Islands", eu = "Puerto Rico", au = "فلسطين", su = "Portugal", cu = "Palau", ru = "Paraguay", iu = "قطر", uu = "La Réunion", lu = "România", du = "Србија", pu = "Россия", $u = "Rwanda", yu = "العربية السعودية", Cu = "Solomon Islands", vu = "Seychelles", mu = "السودان", Su = "Sverige", Mu = "Singapore", fu = "Saint Helena", gu = "Slovenija", hu = "Svalbard og Jan Mayen", Iu = "Slovensko", Gu = "Sierra Leone", Bu = "San Marino", Tu = "Sénégal", Au = "Soomaaliya", Pu = "Suriname", bu = "South Sudan", Lu = "São Tomé e Príncipe", Nu = "El Salvador", Vu = "Sint Maarten", Ru = "سوريا", Eu = "Eswatini", Ku = "Turks and Caicos Islands", Fu = "Tchad", Ou = "Territoire des Terres australes et antarctiques fr", Uu = "Togo", wu = "ประเทศไทย", Du = "Тоҷикистон", Hu = "Tokelau", ku = "Timor-Leste", Zu = "Türkmenistan", Wu = "تونس", _u = "Tonga", zu = "Türkiye", Ju = "Trinidad and Tobago", Yu = "Tuvalu", xu = "臺灣", Qu = "Tanzania", ju = "Україна", Xu = "Uganda", qu = "United States Minor Outlying Islands", nl = "United States", tl = "Uruguay", ol = "O'zbekiston", el = "Vaticano", al = "Saint Vincent and the Grenadines", sl = "Venezuela", cl = "British Virgin Islands", rl = "United States Virgin Islands", il = "Việt Nam", ul = "Vanuatu", ll = "Wallis et Futuna", dl = "Samoa", pl = "Republika e Kosovës", $l = "اليَمَن", yl = "Mayotte", Cl = "South Africa", vl = "Zambia", ml = "Zimbabwe", j = { AD: Us, AE: ws, AF: Ds, AG: Hs, AI: ks, AL: Zs, AM: Ws, AO: _s, AQ: zs, AR: Js, AS: Ys, AT: xs, AU: Qs, AW: js, AX: Xs, AZ: qs, BA: nc, BB: tc, BD: oc, BE: ec, BF: ac, BG: sc, BH: cc, BI: rc, BJ: ic, BL: uc, BM: lc, BN: dc, BO: pc, BQ: $c, BR: yc, BS: Cc, BT: vc, BV: mc, BW: Sc, BY: Mc, BZ: fc, CA: gc, CC: hc, CD: Ic, CF: Gc, CG: Bc, CH: Tc, CI: Ac, CK: Pc, CL: bc, CM: Lc, CN: Nc, CO: Vc, CR: Rc, CU: Ec, CV: Kc, CW: Fc, CX: Oc, CY: Uc, CZ: wc, DE: Dc, DJ: Hc, DK: kc, DM: Zc, DO: Wc, DZ: _c, EC: zc, EE: Jc, EG: Yc, EH: xc, ER: Qc, ES: jc, ET: Xc, FI: qc, FJ: nr, FK: tr, FM: or, FO: er, FR: ar, GA: sr, GB: cr, GD: rr, GE: ir, GF: ur, GG: lr, GH: dr, GI: pr, GL: $r, GM: yr, GN: Cr, GP: vr, GQ: mr, GR: Sr, GS: Mr, GT: fr, GU: gr, GW: hr, GY: Ir, HK: Gr, HM: Br, HN: Tr, HR: Ar, HT: Pr, HU: br, ID: Lr, IE: Nr, IL: Vr, IM: Rr, IN: Er, IO: Kr, IQ: Fr, IR: Or, IS: Ur, IT: wr, JE: Dr, JM: Hr, JO: kr, JP: Zr, KE: Wr, KG: _r, KH: zr, KI: Jr, KM: Yr, KN: xr, KP: Qr, KR: jr, KW: Xr, KY: qr, KZ: ni, LA: ti, LB: oi, LC: ei, LI: ai, LK: si, LR: ci, LS: ri, LT: ii, LU: ui, LV: li, LY: di, MA: pi, MC: $i, MD: yi, ME: Ci, MF: vi, MG: mi, MH: Si, MK: Mi, ML: fi, MM: gi, MN: hi, MO: Ii, MP: Gi, MQ: Bi, MR: Ti, MS: Ai, MT: Pi, MU: bi, MV: Li, MW: Ni, MX: Vi, MY: Ri, MZ: Ei, NA: Ki, NC: Fi, NE: Oi, NF: Ui, NG: wi, NI: Di, NL: Hi, NO: ki, NP: Zi, NR: Wi, NU: _i, NZ: zi, OM: Ji, PA: Yi, PE: xi, PF: Qi, PG: ji, PH: Xi, PK: qi, PL: nu, PM: tu, PN: ou, PR: eu, PS: au, PT: su, PW: cu, PY: ru, QA: iu, RE: uu, RO: lu, RS: du, RU: pu, RW: $u, SA: yu, SB: Cu, SC: vu, SD: mu, SE: Su, SG: Mu, SH: fu, SI: gu, SJ: hu, SK: Iu, SL: Gu, SM: Bu, SN: Tu, SO: Au, SR: Pu, SS: bu, ST: Lu, SV: Nu, SX: Vu, SY: Ru, SZ: Eu, TC: Ku, TD: Fu, TF: Ou, TG: Uu, TH: wu, TJ: Du, TK: Hu, TL: ku, TM: Zu, TN: Wu, TO: _u, TR: zu, TT: Ju, TV: Yu, TW: xu, TZ: Qu, UA: ju, UG: Xu, UM: qu, US: nl, UY: tl, UZ: ol, VA: el, VC: al, VE: sl, VG: cl, VI: rl, VN: il, VU: ul, WF: ll, WS: dl, XK: pl, YE: $l, YT: yl, ZA: Cl, ZM: vl, ZW: ml }, Sl = Object.entries(Os).sort(([n, e], [a, r]) => e.localeCompare(r)).map(([n, e]) => ({ name: e !== j[n] ? `${j[n]} (${e})` : j[n], iso2: U(n), dialCode: `${Wn(n)}` })), _ = class _ { // eslint-disable-next-line class-methods-use-this async guess() { let e, a; try { e = await fetch(_.IP2C_URL), a = await e.text(); } catch { return; } const r = a.toString().split(";"); if (!(!r || r[0] !== "1")) return r[1]; } }; _.IP2C_URL = "https://ip2c.org/s"; let W = _; class Ml extends W { constructor() { super(...arguments), this.memoCountry = void 0; } async guess() { return this.memoCountry || (this.memoCountry = await super.guess()), this.memoCountry; } setPreference(e) { this.memoCountry = e; } } const fl = { label: "Phone", ariaLabel: void 0, countryLabel: void 0, countryAriaLabel: (n) => `Country for ${n.label}`, placeholder: void 0, hint: void 0, invalidMessage: (n) => `The "${n.label}" field is not a valid phone number (example: ${n.example}).`, example: void 0, persistentPlaceholder: void 0, persistentHint: void 0, countryIconMode: void 0, allCountries: Sl, preferCountries: [], includeCountries: [], excludeCountries: [], defaultCountry: void 0, countryGuesser: new Ml(), guessCountry: !1, disableGuessLoading: !1, enableSearchingCountry: !1, displayFormat: "national", phoneValidator: (n) => n.valid }, Mn = { ...fl }; function gl(n) { Object.assign(Mn, n); } function u(n) { return Mn[n]; } function hl(n, e) { var a, r; return ((a = n.number) == null ? void 0 : a[e]) || ((r = n.number) == null ? void 0 : r.input) || ""; } function Il(n) { return _n(n); } function X(n, e) { return zn((n || "").trim(), { regionCode: e }); } const Gl = { key: 1 }, Bl = { class: "v-phone-input__country__title" }, Tl = { class: "v-phone-input__country__append text-body-2" }, Al = /* @__PURE__ */ nn({ components: { VListItem: vn, VSelect: Jn, VTextField: Cn }, __name: "VPhoneInput", props: { label: { type: [Function, String], default: () => u("label") }, ariaLabel: { type: [Function, String], default: () => u("ariaLabel") }, countryLabel: { type: [Function, String], default: () => u("countryLabel") }, countryAriaLabel: { type: [Function, String], default: () => u("countryAriaLabel") }, placeholder: { type: [Function, String], default: () => u("placeholder") }, hint: { type: [Function, String], default: () => u("hint") }, invalidMessage: { type: [Function, String], default: () => u("invalidMessage") }, example: { type: [String, Function], default: () => u("example") }, appendIcon: { default: void 0 }, appendInnerIcon: { default: void 0 }, prependIcon: { default: void 0 }, prependInnerIcon: { default: void 0 }, rules: { default: () => [] }, validateOn: { default: void 0 }, phoneValidator: { type: Function, default: u("phoneValidator") }, countryIconMode: { type: [String, Object, Function], default: u("countryIconMode") }, allCountries: { default: () => u("allCountries") }, preferCountries: { default: () => u("preferCountries") }, includeCountries: { default: () => u("includeCountries") }, excludeCountries: { default: () => u("excludeCountries") }, defaultCountry: { default: u("defaultCountry") }, countryGuesser: { default: () => u("countryGuesser") }, guessCountry: { type: Boolean, default: u("guessCountry") }, disableGuessLoading: { type: Boolean, default: u("disableGuessLoading") }, enableSearchingCountry: { type: Boolean, default: u("enableSearchingCountry") }, displayFormat: { default: u("displayFormat") }, country: { default: "" }, modelValue: { default: "" }, wrapperProps: { default: () => ({}) }, countryProps: { default: () => ({}) }, phoneProps: { default: () => ({}) } }, emits: ["update:modelValue", "update:country"], setup(n, { expose: e, emit: a }) { const r = [ "id", "class", "style" ], l = [ "variant", "flat", "tile", "density", "singleLine", "hideDetails", "direction", "reverse", "color", "bgColor", "theme", "disabled", "readonly", "rounded" ], o = n, $ = a, y = On(), V = Un(), { countriesCount: w, preferredCountries: R, otherCountries: G, guessingCountry: D, findCountry: B, firstCountry: H, setCountryPreference: p, guessCountry: E } = jn({ props: o }), K = S(null), C = S(null), { namespacedSlots: M } = tt(y, ["country"]), { countryIconComponent: h } = Xn({ props: o }), { countrySelectComponent: tn } = qn({ props: o }), z = S(!1), J = S([]), i = S(o.country), v = S(o.modelValue || ""), m = S(un(X(""))), Y = (t) => Object.keys(V).reduce((s, d) => t(d) ? { ...s, [d]: V[d] } : s, {}), fn = c(() => ({ ...Y((t) => r.indexOf(t) !== -1), ...o.wrapperProps })), gn = c(() => B(o.defaultCountry) || H.value), T = c(() => B(i.value) || gn.value), hn = c(() => [...R.value.map((s) => ({ ...s, preferred: !0 })), ...G.value]), x = (t) => hl(t, o.displayFormat), In = c(() => o.example !== void 0 ? typeof o.example == "function" ? o.example(T.value) : o.example : x(Il(T.value.iso2))), Gn = c(() => { var s; const t = new Set(((s = o.validateOn) == null ? void 0 : s.split("")) || []); return t.size === 0 || t.has("input"); }), f = nt({ props: o, country: T, example: In }), on = () => { var t; Gn.value && ((t = C.value) == null || t.validate()); }, en = () => { const t = o.rules.map((s) => typeof s == "function" ? () => s(v.value ?? "", m.value, f.messageOptions.value) : s); f.invalidMessage.value ? J.value = [ ...t, () => !v.value || o.phoneValidator(m.value) || f.invalidMessage.value ] : J.value = t; }, Bn = () => { o.phoneValidator(m.value) && (v.value = x(m.value)); }, Tn = () => { var t, s; o.modelValue !== (((t = m.value.number) == null ? void 0 : t.input) ?? "") && o.modelValue !== (((s = m.value.number) == null ? void 0 : s.e164) ?? "") && (v.value = o.modelValue || ""); }, An = () => { o.country && o.country !== i.value && (i.value = o.country); }; A(() => o.rules, en, { deep: !0, immediate: !0 }), A(() => o.displayFormat, Bn), A(() => o.modelValue, Tn), A(() => o.country, An); const Pn = () => { en(), (v.value ?? "") !== "" && on(); }; A(f.invalidMessage, Pn); const bn = () => { z.value = !0; }, Ln = () => { z.value = !1; }, an = () => { m.value = un(X(v.value, i.value)), o.phoneValidator(m.value) && (v.value = x(m.value)); }, Nn = (t, s) => { i.value ? ($("update:country", i.value), p(i.value)) : ln(() => { i.value || (i.value = s); }), an(), (v.value ?? "") !== "" && on(); }, sn = () => { if ((v.value || "").startsWith("+")) { const s = X(v.value).regionCode; s && i.value !== s && B(s) && (i.value = s); } an(); }, Vn = () => { var P, F; const t = ((P = m.value.number) == null ? void 0 : P.input) || "", s = ((F = m.value.number) == null ? void 0 : F.e164) || t, d = o.phoneValidator(m.value); (o.modelValue !== t || o.modelValue !== s && d) && $("update:modelValue", d ? s : t); }; A(i, Nn), A(v, sn), A(m, Vn, { deep: !0 }); const Rn = async () => { if (i.value) return; if (w.value === 1) { i.value = H.value.iso2; return; } const t = await E(); !i.value && t && (i.value = t), i.value = i.value || T.value.iso2; }, cn = c(() => ({ ref: K, modelValue: i.value, label: f.countryLabel.value, "aria-label": f.countryAriaLabel.value, items: hn.value, itemTitle: "name", itemValue: "iso2", loading: D.value, prependIcon: o.prependIcon, prependInnerIcon: o.prependInnerIcon, ...Y((t) => r.indexOf(t) === -1 && l.indexOf(t) !== -1), class: ["v-phone-input__country__input", { "v-phone-input--focused": z.value }], "onUpdate:modelValue": (t) => { i.value = t; }, onFocus: bn, onBlur: Ln })), rn = c(() => ({ ref: C, modelValue: v.value, label: f.label.value, "aria-label": f.ariaLabel.value, placeholder: f.placeholder.value, hint: f.hint.value, rules: J.value, appendIcon: o.appendIcon, appendInnerIcon: o.appendInnerIcon, ...Y((t) => r.indexOf(t) === -1), validateOn: o.validateOn, class: "v-phone-input__phone__input", type: "tel", "onUpdate:modelValue": (t) => { v.value = t; } })); return wn(() => { sn(), ln(() => { Rn(); }); }), e({ countryInputRef: K, phoneInputRef: C, isValid: c(() => { var t; return ((t = C.value) == null ? void 0 : t.isValid) ?? !0; }), errorMessages: c(() => { var t; return ((t = C.value) == null ? void 0 : t.errorMessages) ?? []; }), reset: async () => { var t; await ((t = C.value) == null ? void 0 : t.reset()); }, resetValidation: async () => { var t; await ((t = C.value) == null ? void 0 : t.resetValidation()); }, validate: async (t) => { var s; return await ((s = C.value) == null ? void 0 : s.validate(t)) ?? []; } }), (t, s) => (O(), dn("div", Dn({ class: [{ "v-phone-input--prepend-inner-icon": t.prependInnerIcon }, "v-phone-input"] }, fn.value), [ I(t.$slots, "country-input", b(L({ props: cn.value })), () => [ (O(), k(Z(g(tn).type), b(L({ ...g(tn).props, ...t.countryProps, menuProps: { maxHeight: 300, contentClass: "v-phone-input__country__menu", closeOnContentClick: !0, ...(t.countryProps ? t.countryProps.menuProps : void 0) || {} }, ...cn.value })), pn({ selection: N(() => [ I(t.$slots, "country-selection", { country: T.value }, () => [ I(t.$slots, "country-icon", { country: T.value, decorative: !1 }, () => [ g(h) ? (O(), k(Z(g(h)), { key: 0, country: T.value, decorative: !1 }, null, 8, ["country"])) : (O(), dn("span", Gl, Q(`+${T.value.dialCode}`), 1)) ]) ]) ]), item: N((d) => [ Hn(g(vn), b(L(d.props)), { prepend: N(() => [ I(t.$slots, "country-icon", { country: d.item.raw, decorative: !0 }, () => [ g(h) ? (O(), k(Z(g(h)), { key: 0, country: d.item.raw, decorative: !0 }, null, 8, ["country"])) : kn("", !0) ]) ]), title: N(() => [ I(t.$slots, "country-title", { country: d.item.raw }, () => [ $n("span", Bl, Q(d.item.raw.name), 1) ]) ]), append: N(() => [ I(t.$slots, "country-append", { country: d.item.raw }, () => [ $n("span", Tl, " +" + Q(d.item.raw.dialCode), 1) ]) ]), _: 2 }, 1040) ]), _: 2 }, [ yn(g(M).country, (d, P) => ({ name: P, fn: N((F) => [ I(t.$slots, d, b(L(F))) ]) })) ]), 1040)) ]), I(t.$slots, "phone-input", b(L({ props: rn.value })), () => [ (O(), k(Z(g(Cn)), b(L({ ...t.phoneProps, ...rn.value })), pn({ _: 2 }, [ yn(g(M).default, (d, P) => ({ name: P, fn: N((F) => [ I(t.$slots, P, b(L(F))) ]) })) ]), 1040)) ]) ], 16)); } }); function Nl(n) { return (e, a) => { a && console.warn("[v-phone-input] options must be passed as first argument of createVPhoneInput()"), gl(n || {}), e.component("VPhoneInput", Al); }; } class Vl extends W { constructor(e = {}) { super(), this.storage = e.storage || localStorage, this.key = e.key || "v_phone_input_country"; } async guess() { const e = this.retrieveStoredCountry(); if (e) return e; const a = await super.guess(); return a && this.saveStoredCountry(a), a; } setPreference(e) { this.saveStoredCountry(e); } retrieveStoredCountry() { return this.storage.getItem(this.key) || void 0; } saveStoredCountry(e) { this.storage.setItem(this.key, e); } getStorage() { return this.storage; } getKey() { return this.key; } } export { fl as DEFAULT_OPTIONS, W as Ip2cCountryGuesser, Ml as MemoIp2cCountryGuesser, Vl as StorageMemoIp2cCountryGuesser, Yn as VCountryIconSprite, xn as VCountryIconSvg, Al as VPhoneInput, Sl as countries, Nl as createVPhoneInput, hl as formatPhone, u as getOption, Il as makeExample, X as makePhone, gl as mergeOptions };