UNPKG

intl-tel-input

Version:

A JavaScript plugin for entering and validating international telephone numbers

2,300 lines 414 kB
import { mergeModels as r2, useModel as P2, ref as I1, onMounted as x2, watch as B2, onUnmounted as R2, withDirectives as k2, createElementBlock as O2, openBlock as G2, mergeProps as U2, vModelText as F2 } from "vue"; const K2 = [ [ "af", // Afghanistan "93" ], [ "ax", // Åland Islands "358", 1 ], [ "al", // Albania "355" ], [ "dz", // Algeria "213" ], [ "as", // American Samoa "1", 5, ["684"] ], [ "ad", // Andorra "376" ], [ "ao", // Angola "244" ], [ "ai", // Anguilla "1", 6, ["264"] ], [ "ag", // Antigua and Barbuda "1", 7, ["268"] ], [ "ar", // Argentina "54" ], [ "am", // Armenia "374" ], [ "aw", // Aruba "297" ], [ "ac", // Ascension Island "247" ], [ "au", // Australia "61", 0, null, "0" ], [ "at", // Austria "43" ], [ "az", // Azerbaijan "994" ], [ "bs", // Bahamas "1", 8, ["242"] ], [ "bh", // Bahrain "973" ], [ "bd", // Bangladesh "880" ], [ "bb", // Barbados "1", 9, ["246"] ], [ "by", // Belarus "375" ], [ "be", // Belgium "32" ], [ "bz", // Belize "501" ], [ "bj", // Benin "229" ], [ "bm", // Bermuda "1", 10, ["441"] ], [ "bt", // Bhutan "975" ], [ "bo", // Bolivia "591" ], [ "ba", // Bosnia and Herzegovina "387" ], [ "bw", // Botswana "267" ], [ "br", // Brazil "55" ], [ "io", // British Indian Ocean Territory "246" ], [ "vg", // British Virgin Islands "1", 11, ["284"] ], [ "bn", // Brunei "673" ], [ "bg", // Bulgaria "359" ], [ "bf", // Burkina Faso "226" ], [ "bi", // Burundi "257" ], [ "kh", // Cambodia "855" ], [ "cm", // Cameroon "237" ], [ "ca", // Canada "1", 1, ["204", "226", "236", "249", "250", "263", "289", "306", "343", "354", "365", "367", "368", "382", "387", "403", "416", "418", "428", "431", "437", "438", "450", "584", "468", "474", "506", "514", "519", "548", "579", "581", "584", "587", "604", "613", "639", "647", "672", "683", "705", "709", "742", "753", "778", "780", "782", "807", "819", "825", "867", "873", "879", "902", "905"] ], [ "cv", // Cape Verde "238" ], [ "bq", // Caribbean Netherlands "599", 1, ["3", "4", "7"] ], [ "ky", // Cayman Islands "1", 12, ["345"] ], [ "cf", // Central African Republic "236" ], [ "td", // Chad "235" ], [ "cl", // Chile "56" ], [ "cn", // China "86" ], [ "cx", // Christmas Island "61", 2, ["89164"], "0" ], [ "cc", // Cocos (Keeling) Islands "61", 1, ["89162"], "0" ], [ "co", // Colombia "57" ], [ "km", // Comoros "269" ], [ "cg", // Congo (Brazzaville) "242" ], [ "cd", // Congo (Kinshasa) "243" ], [ "ck", // Cook Islands "682" ], [ "cr", // Costa Rica "506" ], [ "ci", // Côte d'Ivoire "225" ], [ "hr", // Croatia "385" ], [ "cu", // Cuba "53" ], [ "cw", // Curaçao "599", 0 ], [ "cy", // Cyprus "357" ], [ "cz", // Czech Republic "420" ], [ "dk", // Denmark "45" ], [ "dj", // Djibouti "253" ], [ "dm", // Dominica "1", 13, ["767"] ], [ "do", // Dominican Republic "1", 2, ["809", "829", "849"] ], [ "ec", // Ecuador "593" ], [ "eg", // Egypt "20" ], [ "sv", // El Salvador "503" ], [ "gq", // Equatorial Guinea "240" ], [ "er", // Eritrea "291" ], [ "ee", // Estonia "372" ], [ "sz", // Eswatini "268" ], [ "et", // Ethiopia "251" ], [ "fk", // Falkland Islands (Malvinas) "500" ], [ "fo", // Faroe Islands "298" ], [ "fj", // Fiji "679" ], [ "fi", // Finland "358", 0 ], [ "fr", // France "33" ], [ "gf", // French Guiana "594" ], [ "pf", // French Polynesia "689" ], [ "ga", // Gabon "241" ], [ "gm", // Gambia "220" ], [ "ge", // Georgia "995" ], [ "de", // Germany "49" ], [ "gh", // Ghana "233" ], [ "gi", // Gibraltar "350" ], [ "gr", // Greece "30" ], [ "gl", // Greenland "299" ], [ "gd", // Grenada "1", 14, ["473"] ], [ "gp", // Guadeloupe "590", 0 ], [ "gu", // Guam "1", 15, ["671"] ], [ "gt", // Guatemala "502" ], [ "gg", // Guernsey "44", 1, ["1481", "7781", "7839", "7911"], "0" ], [ "gn", // Guinea "224" ], [ "gw", // Guinea-Bissau "245" ], [ "gy", // Guyana "592" ], [ "ht", // Haiti "509" ], [ "hn", // Honduras "504" ], [ "hk", // Hong Kong SAR China "852" ], [ "hu", // Hungary "36" ], [ "is", // Iceland "354" ], [ "in", // India "91" ], [ "id", // Indonesia "62" ], [ "ir", // Iran "98" ], [ "iq", // Iraq "964" ], [ "ie", // Ireland "353" ], [ "im", // Isle of Man "44", 2, ["1624", "74576", "7524", "7924", "7624"], "0" ], [ "il", // Israel "972" ], [ "it", // Italy "39", 0 ], [ "jm", // Jamaica "1", 4, ["876", "658"] ], [ "jp", // Japan "81" ], [ "je", // Jersey "44", 3, ["1534", "7509", "7700", "7797", "7829", "7937"], "0" ], [ "jo", // Jordan "962" ], [ "kz", // Kazakhstan "7", 1, ["33", "7"], "8" ], [ "ke", // Kenya "254" ], [ "ki", // Kiribati "686" ], [ "xk", // Kosovo "383" ], [ "kw", // Kuwait "965" ], [ "kg", // Kyrgyzstan "996" ], [ "la", // Laos "856" ], [ "lv", // Latvia "371" ], [ "lb", // Lebanon "961" ], [ "ls", // Lesotho "266" ], [ "lr", // Liberia "231" ], [ "ly", // Libya "218" ], [ "li", // Liechtenstein "423" ], [ "lt", // Lithuania "370" ], [ "lu", // Luxembourg "352" ], [ "mo", // Macao SAR China "853" ], [ "mg", // Madagascar "261" ], [ "mw", // Malawi "265" ], [ "my", // Malaysia "60" ], [ "mv", // Maldives "960" ], [ "ml", // Mali "223" ], [ "mt", // Malta "356" ], [ "mh", // Marshall Islands "692" ], [ "mq", // Martinique "596" ], [ "mr", // Mauritania "222" ], [ "mu", // Mauritius "230" ], [ "yt", // Mayotte "262", 1, ["269", "639"], "0" ], [ "mx", // Mexico "52" ], [ "fm", // Micronesia "691" ], [ "md", // Moldova "373" ], [ "mc", // Monaco "377" ], [ "mn", // Mongolia "976" ], [ "me", // Montenegro "382" ], [ "ms", // Montserrat "1", 16, ["664"] ], [ "ma", // Morocco "212", 0, null, "0" ], [ "mz", // Mozambique "258" ], [ "mm", // Myanmar (Burma) "95" ], [ "na", // Namibia "264" ], [ "nr", // Nauru "674" ], [ "np", // Nepal "977" ], [ "nl", // Netherlands "31" ], [ "nc", // New Caledonia "687" ], [ "nz", // New Zealand "64" ], [ "ni", // Nicaragua "505" ], [ "ne", // Niger "227" ], [ "ng", // Nigeria "234" ], [ "nu", // Niue "683" ], [ "nf", // Norfolk Island "672" ], [ "kp", // North Korea "850" ], [ "mk", // North Macedonia "389" ], [ "mp", // Northern Mariana Islands "1", 17, ["670"] ], [ "no", // Norway "47", 0 ], [ "om", // Oman "968" ], [ "pk", // Pakistan "92" ], [ "pw", // Palau "680" ], [ "ps", // Palestinian Territories "970" ], [ "pa", // Panama "507" ], [ "pg", // Papua New Guinea "675" ], [ "py", // Paraguay "595" ], [ "pe", // Peru "51" ], [ "ph", // Philippines "63" ], [ "pl", // Poland "48" ], [ "pt", // Portugal "351" ], [ "pr", // Puerto Rico "1", 3, ["787", "939"] ], [ "qa", // Qatar "974" ], [ "re", // Réunion "262", 0, null, "0" ], [ "ro", // Romania "40" ], [ "ru", // Russia "7", 0, null, "8" ], [ "rw", // Rwanda "250" ], [ "ws", // Samoa "685" ], [ "sm", // San Marino "378" ], [ "st", // São Tomé & Príncipe "239" ], [ "sa", // Saudi Arabia "966" ], [ "sn", // Senegal "221" ], [ "rs", // Serbia "381" ], [ "sc", // Seychelles "248" ], [ "sl", // Sierra Leone "232" ], [ "sg", // Singapore "65" ], [ "sx", // Sint Maarten "1", 21, ["721"] ], [ "sk", // Slovakia "421" ], [ "si", // Slovenia "386" ], [ "sb", // Solomon Islands "677" ], [ "so", // Somalia "252" ], [ "za", // South Africa "27" ], [ "kr", // South Korea "82" ], [ "ss", // South Sudan "211" ], [ "es", // Spain "34" ], [ "lk", // Sri Lanka "94" ], [ "bl", // St. Barthélemy "590", 1 ], [ "sh", // St. Helena "290" ], [ "kn", // St. Kitts & Nevis "1", 18, ["869"] ], [ "lc", // St. Lucia "1", 19, ["758"] ], [ "mf", // St. Martin "590", 2 ], [ "pm", // St. Pierre & Miquelon "508" ], [ "vc", // St. Vincent & Grenadines "1", 20, ["784"] ], [ "sd", // Sudan "249" ], [ "sr", // Suriname "597" ], [ "sj", // Svalbard & Jan Mayen "47", 1, ["79"] ], [ "se", // Sweden "46" ], [ "ch", // Switzerland "41" ], [ "sy", // Syria "963" ], [ "tw", // Taiwan "886" ], [ "tj", // Tajikistan "992" ], [ "tz", // Tanzania "255" ], [ "th", // Thailand "66" ], [ "tl", // Timor-Leste "670" ], [ "tg", // Togo "228" ], [ "tk", // Tokelau "690" ], [ "to", // Tonga "676" ], [ "tt", // Trinidad & Tobago "1", 22, ["868"] ], [ "tn", // Tunisia "216" ], [ "tr", // Turkey "90" ], [ "tm", // Turkmenistan "993" ], [ "tc", // Turks & Caicos Islands "1", 23, ["649"] ], [ "tv", // Tuvalu "688" ], [ "vi", // U.S. Virgin Islands "1", 24, ["340"] ], [ "ug", // Uganda "256" ], [ "ua", // Ukraine "380" ], [ "ae", // United Arab Emirates "971" ], [ "gb", // United Kingdom "44", 0, null, "0" ], [ "us", // United States "1", 0 ], [ "uy", // Uruguay "598" ], [ "uz", // Uzbekistan "998" ], [ "vu", // Vanuatu "678" ], [ "va", // Vatican City "39", 1, ["06698"] ], [ "ve", // Venezuela "58" ], [ "vn", // Vietnam "84" ], [ "wf", // Wallis & Futuna "681" ], [ "eh", // Western Sahara "212", 1, ["5288", "5289"], "0" ], [ "ye", // Yemen "967" ], [ "zm", // Zambia "260" ], [ "zw", // Zimbabwe "263" ] ], Z = []; for (const f of K2) Z.push({ name: "", // populated in the plugin iso2: f[0], dialCode: f[1], priority: f[2] || 0, areaCodes: f[3] || null, nodeById: {}, // populated by the plugin nationalPrefix: f[4] || null }); const V2 = { ad: "Andorra", ae: "United Arab Emirates", af: "Afghanistan", ag: "Antigua & Barbuda", ai: "Anguilla", al: "Albania", am: "Armenia", ao: "Angola", ar: "Argentina", as: "American Samoa", at: "Austria", au: "Australia", aw: "Aruba", ax: "Åland Islands", az: "Azerbaijan", ba: "Bosnia & Herzegovina", bb: "Barbados", bd: "Bangladesh", be: "Belgium", bf: "Burkina Faso", bg: "Bulgaria", bh: "Bahrain", bi: "Burundi", bj: "Benin", bl: "St. Barthélemy", bm: "Bermuda", bn: "Brunei", bo: "Bolivia", bq: "Caribbean Netherlands", br: "Brazil", bs: "Bahamas", bt: "Bhutan", bw: "Botswana", by: "Belarus", bz: "Belize", ca: "Canada", cc: "Cocos (Keeling) Islands", cd: "Congo - Kinshasa", cf: "Central African Republic", cg: "Congo - Brazzaville", ch: "Switzerland", ci: "Côte d’Ivoire", ck: "Cook Islands", cl: "Chile", cm: "Cameroon", cn: "China", co: "Colombia", cr: "Costa Rica", cu: "Cuba", cv: "Cape Verde", cw: "Curaçao", cx: "Christmas Island", cy: "Cyprus", cz: "Czechia", de: "Germany", dj: "Djibouti", dk: "Denmark", dm: "Dominica", do: "Dominican Republic", dz: "Algeria", ec: "Ecuador", ee: "Estonia", eg: "Egypt", eh: "Western Sahara", er: "Eritrea", es: "Spain", et: "Ethiopia", fi: "Finland", fj: "Fiji", fk: "Falkland Islands", fm: "Micronesia", fo: "Faroe Islands", fr: "France", ga: "Gabon", gb: "United Kingdom", gd: "Grenada", ge: "Georgia", gf: "French Guiana", gg: "Guernsey", gh: "Ghana", gi: "Gibraltar", gl: "Greenland", gm: "Gambia", gn: "Guinea", gp: "Guadeloupe", gq: "Equatorial Guinea", gr: "Greece", gt: "Guatemala", gu: "Guam", gw: "Guinea-Bissau", gy: "Guyana", hk: "Hong Kong SAR China", hn: "Honduras", hr: "Croatia", ht: "Haiti", hu: "Hungary", id: "Indonesia", ie: "Ireland", il: "Israel", im: "Isle of Man", in: "India", io: "British Indian Ocean Territory", iq: "Iraq", ir: "Iran", is: "Iceland", it: "Italy", je: "Jersey", jm: "Jamaica", jo: "Jordan", jp: "Japan", ke: "Kenya", kg: "Kyrgyzstan", kh: "Cambodia", ki: "Kiribati", km: "Comoros", kn: "St. Kitts & Nevis", kp: "North Korea", kr: "South Korea", kw: "Kuwait", ky: "Cayman Islands", kz: "Kazakhstan", la: "Laos", lb: "Lebanon", lc: "St. Lucia", li: "Liechtenstein", lk: "Sri Lanka", lr: "Liberia", ls: "Lesotho", lt: "Lithuania", lu: "Luxembourg", lv: "Latvia", ly: "Libya", ma: "Morocco", mc: "Monaco", md: "Moldova", me: "Montenegro", mf: "St. Martin", mg: "Madagascar", mh: "Marshall Islands", mk: "North Macedonia", ml: "Mali", mm: "Myanmar (Burma)", mn: "Mongolia", mo: "Macao SAR China", mp: "Northern Mariana Islands", mq: "Martinique", mr: "Mauritania", ms: "Montserrat", mt: "Malta", mu: "Mauritius", mv: "Maldives", mw: "Malawi", mx: "Mexico", my: "Malaysia", mz: "Mozambique", na: "Namibia", nc: "New Caledonia", ne: "Niger", nf: "Norfolk Island", ng: "Nigeria", ni: "Nicaragua", nl: "Netherlands", no: "Norway", np: "Nepal", nr: "Nauru", nu: "Niue", nz: "New Zealand", om: "Oman", pa: "Panama", pe: "Peru", pf: "French Polynesia", pg: "Papua New Guinea", ph: "Philippines", pk: "Pakistan", pl: "Poland", pm: "St. Pierre & Miquelon", pr: "Puerto Rico", ps: "Palestinian Territories", pt: "Portugal", pw: "Palau", py: "Paraguay", qa: "Qatar", re: "Réunion", ro: "Romania", rs: "Serbia", ru: "Russia", rw: "Rwanda", sa: "Saudi Arabia", sb: "Solomon Islands", sc: "Seychelles", sd: "Sudan", se: "Sweden", sg: "Singapore", sh: "St. Helena", si: "Slovenia", sj: "Svalbard & Jan Mayen", sk: "Slovakia", sl: "Sierra Leone", sm: "San Marino", sn: "Senegal", so: "Somalia", sr: "Suriname", ss: "South Sudan", st: "São Tomé & Príncipe", sv: "El Salvador", sx: "Sint Maarten", sy: "Syria", sz: "Eswatini", tc: "Turks & Caicos Islands", td: "Chad", tg: "Togo", th: "Thailand", tj: "Tajikistan", tk: "Tokelau", tl: "Timor-Leste", tm: "Turkmenistan", tn: "Tunisia", to: "Tonga", tr: "Turkey", tt: "Trinidad & Tobago", tv: "Tuvalu", tw: "Taiwan", tz: "Tanzania", ua: "Ukraine", ug: "Uganda", us: "United States", uy: "Uruguay", uz: "Uzbekistan", va: "Vatican City", vc: "St. Vincent & Grenadines", ve: "Venezuela", vg: "British Virgin Islands", vi: "U.S. Virgin Islands", vn: "Vietnam", vu: "Vanuatu", wf: "Wallis & Futuna", ws: "Samoa", ye: "Yemen", yt: "Mayotte", za: "South Africa", zm: "Zambia", zw: "Zimbabwe" }, H2 = { selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})", noCountrySelected: "Select country", countryListAriaLabel: "List of countries", searchPlaceholder: "Search", clearSearchAriaLabel: "Clear search", zeroSearchResults: "No results found", oneSearchResult: "1 result found", multipleSearchResults: "${count} results found", // additional countries (not supported by country-list library) ac: "Ascension Island", xk: "Kosovo" }, a2 = { ...V2, ...H2 }, v1 = (f) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(f).matches, j2 = () => { if (typeof navigator < "u" && typeof window < "u") { const f = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), e = v1("(max-width: 500px)"), $ = v1("(max-height: 600px)"), i = v1("(pointer: coarse)"); return f || e || i && $; } return !1; }, u2 = { // Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers allowPhonewords: !1, //* Whether or not to allow the dropdown. allowDropdown: !0, //* Add a placeholder in the input with an example number for the selected country. autoPlaceholder: "polite", //* Modify the parentClass. containerClass: "", //* The order of the countries in the dropdown. Defaults to alphabetical. countryOrder: null, //* Add a country search input at the top of the dropdown. countrySearch: !0, //* Modify the auto placeholder. customPlaceholder: null, //* Append menu to specified element. dropdownContainer: null, //* Don't display these countries. excludeCountries: [], //* Fix the dropdown width to the input width (rather than being as wide as the longest country name). fixDropdownWidth: !0, //* Format the number as the user types formatAsYouType: !0, //* Format the input value during initialisation and on setNumber. formatOnDisplay: !0, //* geoIp lookup function. geoIpLookup: null, //* Inject a hidden input with the name returned from this function, and on submit, populate it with the result of getNumber. hiddenInput: null, //* Internationalise the plugin text e.g. search input placeholder, country names. i18n: {}, //* Initial country. initialCountry: "", //* A function to load the utils script. loadUtils: null, //* National vs international formatting for numbers e.g. placeholders and displaying existing numbers. nationalMode: !0, //* Display only these countries. onlyCountries: [], //* Number type to use for placeholders. placeholderNumberType: "MOBILE", //* Show flags - for both the selected country, and in the country dropdown showFlags: !0, //* Display the international dial code next to the selected flag. separateDialCode: !1, //* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length. strictMode: !1, //* Use full screen popup instead of dropdown for country list. useFullscreenPopup: j2(), //* The number type to enforce during validation. validationNumberTypes: ["MOBILE"] }; function W2(f) { f.useFullscreenPopup && (f.fixDropdownWidth = !1), f.onlyCountries.length === 1 && (f.initialCountry = f.onlyCountries[0]), f.separateDialCode && (f.nationalMode = !1), f.allowDropdown && !f.showFlags && !f.separateDialCode && (f.nationalMode = !1), f.useFullscreenPopup && !f.dropdownContainer && (f.dropdownContainer = document.body), f.i18n = { ...a2, ...f.i18n }; } const h1 = (f) => f.replace(/\D/g, ""), l2 = (f = "") => f.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), L = (f, e, $) => { const i = document.createElement(f); return e && Object.entries(e).forEach(([s, u]) => i.setAttribute(s, u)), $ && $.appendChild(i), i; }; function z2(f) { const { onlyCountries: e, excludeCountries: $ } = f; if (e.length) { const i = e.map((s) => s.toLowerCase()); return Z.filter((s) => i.includes(s.iso2)); } else if ($.length) { const i = $.map((s) => s.toLowerCase()); return Z.filter((s) => !i.includes(s.iso2)); } return Z; } function Z2(f, e) { for (const $ of f) { const i = $.iso2.toLowerCase(); e.i18n[i] && ($.name = e.i18n[i]); } } function Y2(f, e) { const $ = /* @__PURE__ */ new Set(); let i = 0; const s = {}, u = (h, c, C) => { if (!h || !c) return; c.length > i && (i = c.length), s.hasOwnProperty(c) || (s[c] = []); const g = s[c]; if (g.includes(h)) return; const I = C !== void 0 ? C : g.length; g[I] = h; }; for (const h of f) $.has(h.dialCode) || $.add(h.dialCode), u(h.iso2, h.dialCode, h.priority); (e.onlyCountries.length || e.excludeCountries.length) && $.forEach((h) => { s[h] = s[h].filter(Boolean); }); for (const h of f) if (h.areaCodes) { const c = s[h.dialCode][0]; for (const C of h.areaCodes) { for (let g = 1; g < C.length; g++) { const I = C.substring(0, g), S = h.dialCode + I; u(c, S), u(h.iso2, S); } u(h.iso2, h.dialCode + C); } } return { dialCodes: $, dialCodeMaxLen: i, dialCodeToIso2Map: s }; } function J2(f, e) { e.countryOrder && (e.countryOrder = e.countryOrder.map(($) => $.toLowerCase())), f.sort(($, i) => { const { countryOrder: s } = e; if (s) { const u = s.indexOf($.iso2), h = s.indexOf(i.iso2), c = u > -1, C = h > -1; if (c || C) return c && C ? u - h : c ? -1 : 1; } return $.name.localeCompare(i.name); }); } function q2(f) { for (const e of f) e.normalisedName = l2(e.name), e.initials = e.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map(($) => $[0]).join("").toLowerCase(), e.dialCodePlus = `+${e.dialCode}`; } function X2(f, e, $, i) { let s = f; if ($ && e) { e = `+${i.dialCode}`; const u = s[e.length] === " " || s[e.length] === "-" ? e.length + 1 : e.length; s = s.substring(u); } return s; } function Q2(f, e, $, i, s) { const u = $ ? $.formatNumberAsYouType(f, i.iso2) : f, { dialCode: h } = i; return s && e.charAt(0) !== "+" && u.includes(`+${h}`) ? (u.split(`+${h}`)[1] || "").trim() : u; } function d0(f, e, $, i) { if ($ === 0 && !i) return 0; let s = 0; for (let u = 0; u < e.length; u++) { if (/[+0-9]/.test(e[u]) && s++, s === f && !i) return u + 1; if (i && s === f + 1) return u; } return e.length; } const t0 = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ], o2 = (f) => { const e = h1(f); if (e.charAt(0) === "1") { const $ = e.substring(1, 4); return t0.includes($); } return !1; }; for (const f of Z) f.name = a2[f.iso2]; let e0 = 0; const $0 = new Set(Z.map((f) => f.iso2)), w1 = (f) => $0.has(f), e1 = (f, ...e) => { const { instances: $ } = y; Object.values($).forEach((i) => i[f](...e)); }; class c1 { /** * Build a space-delimited class string from an object map of className -> truthy/falsey. * Only keys with truthy values are included. */ static _buildClassNames(e) { return Object.keys(e).filter(($) => !!e[$]).join(" "); } constructor(e, $ = {}) { this.id = e0++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, u2, $), this.hadInitialPlaceholder = !!e.getAttribute("placeholder"); } _detectEnvironmentAndLayout() { this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.telInput.dir = "ltr"; const e = this.options.allowDropdown || this.options.separateDialCode; this.showSelectedCountryOnLeft = this.isRTL ? !e : e, this.options.separateDialCode && (this.isRTL ? this.originalPaddingRight = this.telInput.style.paddingRight : this.originalPaddingLeft = this.telInput.style.paddingLeft); } _createInitPromises() { const e = new Promise((i, s) => { this.resolveAutoCountryPromise = i, this.rejectAutoCountryPromise = s; }), $ = new Promise((i, s) => { this.resolveUtilsScriptPromise = i, this.rejectUtilsScriptPromise = s; }); this.promise = Promise.all([e, $]); } //* Can't be private as it's called from intlTelInput convenience wrapper. _init() { W2(this.options), this._detectEnvironmentAndLayout(), this._createInitPromises(), this.selectedCountryData = {}, this._processCountryData(), this._generateMarkup(), this._setInitialState(), this._initListeners(), this._initRequests(); } //******************** //* PRIVATE METHODS //******************** //* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options. _processCountryData() { this.countries = z2(this.options); const e = Y2(this.countries, this.options); this.dialCodes = e.dialCodes, this.dialCodeMaxLen = e.dialCodeMaxLen, this.dialCodeToIso2Map = e.dialCodeToIso2Map, Z2(this.countries, this.options), J2(this.countries, this.options), this.countryByIso2 = new Map(this.countries.map(($) => [$.iso2, $])), q2(this.countries); } //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown. _generateMarkup() { this._prepareTelInput(); const e = this._createWrapperAndInsert(); this._maybeBuildCountryContainer(e), e.appendChild(this.telInput), this._maybeUpdateInputPaddingAndReveal(), this._maybeBuildHiddenInputs(e); } _prepareTelInput() { this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off"); } _createWrapperAndInsert() { var c; const { allowDropdown: e, showFlags: $, containerClass: i, useFullscreenPopup: s } = this.options, u = c1._buildClassNames({ iti: !0, "iti--allow-dropdown": e, "iti--show-flags": $, "iti--inline-dropdown": !s, [i]: !!i }), h = L("div", { class: u }); return (c = this.telInput.parentNode) == null || c.insertBefore(h, this.telInput), h; } _maybeBuildCountryContainer(e) { const { allowDropdown: $, separateDialCode: i, showFlags: s } = this.options; if ($ || s || i) { this.countryContainer = L( "div", // visibly hidden until we measure it's width to set the input padding correctly { class: "iti__country-container iti__v-hide" }, e ), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", $ ? (this.selectedCountry = L( "button", { type: "button", class: "iti__selected-country", "aria-expanded": "false", "aria-label": this.options.i18n.noCountrySelected, "aria-haspopup": "dialog", "aria-controls": `iti-${this.id}__dropdown-content` }, this.countryContainer ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = L( "div", { class: "iti__selected-country" }, this.countryContainer ); const u = L( "div", { class: "iti__selected-country-primary" }, this.selectedCountry ); this.selectedCountryInner = L( "div", { class: "iti__flag" }, u ), $ && (this.dropdownArrow = L( "div", { class: "iti__arrow", "aria-hidden": "true" }, u )), i && (this.selectedDialCode = L( "div", { class: "iti__selected-dial-code", dir: "ltr" }, this.selectedCountry )), $ && this._buildDropdownContent(); } } _buildDropdownContent() { const { fixDropdownWidth: e, useFullscreenPopup: $, countrySearch: i, i18n: s, dropdownContainer: u, containerClass: h } = this.options, c = e ? "" : "iti--flexible-dropdown-width"; if (this.dropdownContent = L("div", { id: `iti-${this.id}__dropdown-content`, class: `iti__dropdown-content iti__hide ${c}`, role: "dialog", "aria-modal": "true" }), i && this._buildSearchUI(), this.countryList = L( "ul", { class: "iti__country-list", id: `iti-${this.id}__country-listbox`, role: "listbox", "aria-label": s.countryListAriaLabel }, this.dropdownContent ), this._appendListItems(), i && this._updateSearchResultsA11yText(), u) { const C = c1._buildClassNames({ iti: !0, "iti--container": !0, "iti--fullscreen-popup": $, "iti--inline-dropdown": !$, [h]: !!h }); this.dropdown = L("div", { class: C }), this.dropdown.appendChild(this.dropdownContent); } else this.countryContainer.appendChild(this.dropdownContent); } _buildSearchUI() { const { i18n: e } = this.options, $ = L( "div", { class: "iti__search-input-wrapper" }, this.dropdownContent ); this.searchIcon = L( "span", { class: "iti__search-icon", "aria-hidden": "true" }, $ ), this.searchIcon.innerHTML = ` <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" aria-hidden="true"> <circle cx="11" cy="11" r="7" /> <line x1="21" y1="21" x2="16.65" y2="16.65" /> </svg>`, this.searchInput = L( "input", { id: `iti-${this.id}__search-input`, // Chrome says inputs need either a name or an id type: "search", class: "iti__search-input", placeholder: e.searchPlaceholder, // role=combobox + aria-autocomplete=list + aria-activedescendant allows maintaining focus on the search input while allowing users to navigate search results with up/down keyboard keys role: "combobox", "aria-expanded": "true", "aria-label": e.searchPlaceholder, "aria-controls": `iti-${this.id}__country-listbox`, "aria-autocomplete": "list", autocomplete: "off" }, $ ), this.searchClearButton = L( "button", { type: "button", class: "iti__search-clear iti__hide", "aria-label": e.clearSearchAriaLabel, tabindex: "-1" }, $ ); const i = `iti-${this.id}-clear-mask`; this.searchClearButton.innerHTML = ` <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" aria-hidden="true" focusable="false"> <mask id="${i}" maskUnits="userSpaceOnUse"> <rect width="16" height="16" fill="white" /> <path d="M5.2 5.2 L10.8 10.8 M10.8 5.2 L5.2 10.8" stroke="black" stroke-linecap="round" class="iti__search-clear-x" /> </mask> <circle cx="8" cy="8" r="8" class="iti__search-clear-bg" mask="url(#${i})" /> </svg>`, this.searchResultsA11yText = L( "span", { class: "iti__a11y-text" }, this.dropdownContent ), this.searchNoResults = L( "div", { class: "iti__no-results iti__hide", "aria-hidden": "true" // all a11y messaging happens in this.searchResultsA11yText }, this.dropdownContent ), this.searchNoResults.textContent = e.zeroSearchResults; } _maybeUpdateInputPaddingAndReveal() { this.countryContainer && (this._updateInputPadding(), this.countryContainer.classList.remove("iti__v-hide")); } _maybeBuildHiddenInputs(e) { var i, s; const { hiddenInput: $ } = this.options; if ($) { const u = this.telInput.getAttribute("name") || "", h = $(u); if (h.phone) { const c = (i = this.telInput.form) == null ? void 0 : i.querySelector(`input[name="${h.phone}"]`); c ? this.hiddenInput = c : (this.hiddenInput = L("input", { type: "hidden", name: h.phone }), e.appendChild(this.hiddenInput)); } if (h.country) { const c = (s = this.telInput.form) == null ? void 0 : s.querySelector(`input[name="${h.country}"]`); c ? this.hiddenInputCountry = c : (this.hiddenInputCountry = L("input", { type: "hidden", name: h.country }), e.appendChild(this.hiddenInputCountry)); } } } //* For each country: add a country list item <li> to the countryList <ul> container. _appendListItems() { for (let e = 0; e < this.countries.length; e++) { const $ = this.countries[e], i = e === 0 ? "iti__highlight" : "", s = L( "li", { id: `iti-${this.id}__item-${$.iso2}`, class: `iti__country ${i}`, tabindex: "-1", role: "option", "data-dial-code": $.dialCode, "data-country-code": $.iso2, "aria-selected": "false" }, this.countryList ); $.nodeById[this.id] = s; let u = ""; this.options.showFlags && (u += `<div class='iti__flag iti__${$.iso2}'></div>`), u += `<span class='iti__country-name'>${$.name}</span>`, u += `<span class='iti__dial-code' dir='ltr'>+${$.dialCode}</span>`, s.insertAdjacentHTML("beforeend", u); } } //* Set the initial state of the input value and the selected country by: //* 1. Extracting a dial code from the given number //* 2. Using explicit initialCountry _setInitialState(e = !1) { const $ = this.telInput.getAttribute("value"), i = this.telInput.value, u = $ && $.charAt(0) === "+" && (!i || i.charAt(0) !== "+") ? $ : i, h = this._getDialCode(u), c = o2(u), { initialCountry: C, geoIpLookup: g } = this.options, I = C === "auto" && g; if (h && !c) this._updateCountryFromNumber(u); else if (!I || e) { const S = C ? C.toLowerCase() : ""; w1(S) ? this._setCountry(S) : h && c ? this._setCountry("us") : this._setCountry(""); } u && this._updateValFromNumber(u); } //* Initialise the main event listeners: input keyup, and click selected country. _initListeners() { this._initTelInputListeners(), this.options.allowDropdown && this._initDropdownListeners(), (this.hiddenInput || this.hiddenInputCountry) && this.telInput.form && this._initHiddenInputListener(); } //* Update hidden input on form submit. _initHiddenInputListener() { var e; this._handleHiddenInputSubmit = () => { this.hiddenInput && (this.hiddenInput.value = this.getNumber()), this.hiddenInputCountry && (this.hiddenInputCountry.value = this.getSelectedCountryData().iso2 || ""); }, (e = this.telInput.form) == null || e.addEventListener( "submit", this._handleHiddenInputSubmit ); } //* initialise the dropdown listeners. _initDropdownListeners() { this._handleLabelClick = ($) => { this.dropdownContent.classList.contains("iti__hide") ? this.telInput.focus() : $.preventDefault(); }; const e = this.telInput.closest("label"); e && e.addEventListener("click", this._handleLabelClick), this._handleClickSelectedCountry = () => { this.dropdownContent.classList.contains("iti__hide") && !this.telInput.disabled && !this.telInput.readOnly && this._openDropdown(); }, this.selectedCountry.addEventListener("click", this._handleClickSelectedCountry), this._handleCountryContainerKeydown = ($) => { this.dropdownContent.classList.contains("iti__hide") && ["ArrowUp", "ArrowDown", " ", "Enter"].includes($.key) && ($.preventDefault(), $.stopPropagation(), this._openDropdown()), $.key === "Tab" && this._closeDropdown(); }, this.countryContainer.addEventListener( "keydown", this._handleCountryContainerKeydown ); } //* Init many requests: utils script / geo ip lookup. _initRequests() { let { loadUtils: e, initialCountry: $, geoIpLookup: i } = this.options; e && !y.utils ? (this._handlePageLoad = () => { var u; window.removeEventListener("load", this._handlePageLoad), (u = y.attachUtils(e)) == null || u.catch(() => { }); }, y.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), $ === "auto" && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); } //* Perform the geo ip lookup. _loadAutoCountry() { y.autoCountry ? this.handleAutoCountry() : y.startedLoadingAutoCountry || (y.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup( (e = "") => { const $ = e.toLowerCase(); w1($) ? (y.autoCountry = $, setTimeout(() => e1("handleAutoCountry"))) : (this._setInitialState(!0), e1("rejectAutoCountryPromise")); }, () => { this._setInitialState(!0), e1("rejectAutoCountryPromise"); } )); } _openDropdownWithPlus() { this._openDropdown(), this.searchInput.value = "+", this._filterCountries(""); } //* Initialize the tel input listeners. _initTelInputListeners() { this._bindInputListener(), this._maybeBindKeydownListener(), this._maybeBindPasteListener(); } _bindInputListener() { const { strictMode: e, formatAsYouType: $, separateDialCode: i, allowDropdown: s, countrySearch: u } = this.options; let h = !1; new RegExp("\\p{L}", "u").test(this.telInput.value) && (h = !0), this._handleInputEvent = (c) => { if (this.isAndroid && (c == null ? void 0 : c.data) === "+" && i && s && u) { const S = this.telInput.selectionStart || 0, R = this.telInput.value.substring(0, S - 1), v = this.telInput.value.substring(S); this.telInput.value = R + v, this._openDropdownWithPlus(); return; } this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange(); const C = (c == null ? void 0 : c.data) && /[^+0-9]/.test(c.data), g = (c == null ? void 0 : c.inputType) === "insertFromPaste" && this.telInput.value; C || g && !e ? h = !0 : /[^+0-9]/.test(this.telInput.value) || (h = !1); const I = (c == null ? void 0 : c.detail) && c.detail.isSetNumber; if ($ && !h && !I) { const S = this.telInput.selectionStart || 0, v = this.telInput.value.substring(0, S).replace(/[^+0-9]/g, "").length, D = (c == null ? void 0 : c.inputType) === "deleteContentForward", A = this._getFullNumber(), k = Q2( A, this.telInput.value, y.utils, this.selectedCountryData, this.options.separateDialCode ), H = d0(v, k, S, D); this.telInput.value = k, this.telInput.setSelectionRange(H, H); } }, this.telInput.addEventListener("input", this._handleInputEvent); } _maybeBindKeydownListener() { const { strictMode: e, separateDialCode: $, allowDropdown: i, countrySearch: s } = this.options; (e || $) && (this._handleKeydownEvent = (u) => { if (u.key && u.key.length === 1 && !u.altKey && !u.ctrlKey && !u.metaKey) { if ($ && i && s && u.key === "+") { u.preventDefault(), this._openDropdownWithPlus(); return; } if (e) { const h = this.telInput.value, C = !(h.charAt(0) === "+") && this.telInput.selectionStart === 0 && u.key === "+", g = /^[0-9]$/.test(u.key), I = $ ? g : C || g, S = h.slice(0, this.telInput.selectionStart) + u.key + h.slice(this.telInput.selectionEnd), R = this._getFullNumber(S), v = y.utils.getCoreNumber(R, this.selectedCountryData.iso2), D = this.maxCoreNumberLength && v.length > this.maxCoreNumberLength, k = this._getNewCountryFromNumber(R) !== null; (!I || D && !k && !C) && u.preventDefault(); } } }, this.telInput.addEventListener("keydown", this._handleKeydownEvent)); } _maybeBindPasteListener() { this.options.strictMode && (this._handlePasteEvent = (e) => { e.preventDefault(); const $ = this.telInput, i = $.selectionStart, s = $.selectionEnd, u = $.value.slice(0, i), h = $.value.slice(s), c = this.selectedCountryData.iso2, C = e.clipboardData.getData("text"), g = i === 0 && s > 0, I = !$.value.startsWith("+") || g, S = C.replace(/[^0-9+]/g, ""), R = S.startsWith("+"), v = S.replace(/\+/g, ""), D = R && I ? `+${v}` : v; let A = u + D + h, k = y.utils.getCoreNumber(A, c); for (; k.length === 0 && A.length > 0; ) A = A.slice(0, -1), k = y.utils.getCoreNumber(A, c); if (!k) return; if (this.maxCoreNumberLength && k.length > this.maxCoreNumberLength) if ($.selectionEnd === $.value.length) { const f1 = k.length - this.maxCoreNumberLength; A = A.slice(0, A.length - f1); } else return; $.value = A; const H = i + D.length; $.setSelectionRange(H, H), $.dispatchEvent(new InputEvent("input", { bubbles: !0 })); }, this.telInput.addEventListener("paste", this._handlePasteEvent)); } //* Adhere to the input's maxlength attr. _cap(e) { const $ = parseInt(this.telInput.getAttribute("maxlength") || "", 10); return $ && e.length > $ ? e.substring(0, $) : e; } //* Trigger a custom event on the input. _trigger(e, $ = {}) { const i = new CustomEvent(e, { bubbles: !0, cancelable: !0, detail: $ }); this.telInput.dispatchEvent(i); } //* Open the dropdown. _openDropdown() { const { fixDropdownWidth: e, countrySearch: $ } = this.options; if (e && (this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`), this.dropdownContent.classList.remove("iti__hide"), this.selectedCountry.setAttribute("aria-expanded", "true"), this._setDropdownPosition(), $) { const i = this.countryList.firstElementChild; i && (this._highlightListItem(i, !1), this.countryList.scrollTop = 0), this.searchInput.focus(); } this._bindDropdownListeners(), this.dropdownArrow.classList.add("iti__arrow--up"), this._trigger("open:countrydropdown"); } //* Set the dropdown position _setDropdownPosition() { if (this.options.dropdownContainer && this.options.dropdownContainer.appendChild(this.dropdown), !this.options.useFullscreenPopup) { const e = this.telInput.getBoundingClientRect(), $ = this.telInput.offsetHeight; this.options.dropdownContainer && (this.dropdown.style.top = `${e.top + $}px`, this.dropdown.style.left = `${e.left}px`, this._handleWindowScroll = () => this._closeDropdown(), window.addEventListener("scroll", this._handleWindowScroll)); } } //* We only bind dropdown listeners when the dropdown is open. _bindDropdownListeners() { this._handleMouseoverCountryList = (i) => { var u; const s = (u = i.target) == null ? void 0 : u.closest(".iti__country"); s && this._highlightListItem(s, !1); }, this.countryList.addEventListener( "mouseover", this._handleMouseoverCountryList ), this._handleClickCountryList = (i) => { var u; const s = (u = i.target) == null ? void 0 : u.closest(".iti__country"); s && this._selectListItem(s); }, this.countryList.addEventListener("click", this._handleClickCountryList), this._handleClickOffToClose = (i) => { !!i.target.closest(`#iti-${this.id}__dropdown-content`) || this._closeDropdown(); }, setTimeout(() => { document.documentElement.addEventListener( "click", this._handleClickOffToClose ); }, 0); let e = "", $ = null; if (this._handleKeydownOnDropdown = (i) => { ["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(i.key) && (i.preventDefault(), i.stopPropagation(), i.key === "ArrowUp" || i.key === "ArrowDown" ? this._handleUpDownKey(i.key) : i.key === "Enter" ? this._handleEnterKey() : i.key === "Escape" && this._closeDropdown()), !this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(i.key) && (i.stopPropagation(), $ && clearTimeout($), e += i.key.toLowerCase(), this._searchForCountry(e), $ = setTimeout(() => { e = ""; }, 1e3)); }, document.addEventListener("keydown", this._handleKeydownOnDropdown), this.options.countrySearch) { const i = () => { const u = this.searchInput.value.trim(); this._filterCountries(u), this.searchInput.value ? this.searchClearButton.classList.remove("iti__hide") : this.searchClearButton.classList.add("iti__hide"); }; let s = null; this._handleSearchChange = () => { s && clearTimeout(s), s = setTimeout(() => { i(), s = null; }, 100); }, this.searchInput.addEventListener("input", this._handleSearchChange), this._handleSearchClear = () => { this.searchInput.value = "", this.searchInput.focus(), i(); }, this.searchClearButton.addEventListener("click", this._handleSearchClear); } } //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string. _searchForCountry(e) { for (const $ of this.countries) if ($.name.substring(0, e.length).toLowerCase() === e) { const s = $.nodeById[this.id]; this._highlightListItem(s, !1), this._scrollTo(s); break; } } //* Country search enabled: Filter the countries according to the search query. _filterCountries(e) { this.countryList.innerHTML = ""; let $; e === "" ? $ = this.countries : $ = this._getMatchedCountries(e); let i = !0; for (const s of $) { const u = s.nodeById[this.id]; u && (this.countryList.appendChild(u), i && (this._highlightListItem(u, !1), i = !1)); } i ? (this._highlightListItem(null, !1), this.searchNoResults && this.searchNoResults.classList.remove("iti__hide")) : this.searchNoResults && this.searchNoResults.classList.add("iti__hide"), this.countryList.scrollTop = 0, this._updateSearchResultsA11yText(); } _getMatchedCountries(e) { const $ = l2(e), i = [], s = [], u = [], h = [], c = [], C = []; for (const g of this.countries) g.iso2 === $ ? i.push(g) : g.normalisedName.startsWith($) ? s.push(g) : g.normalisedName.includes($) ? u.push(g) : $ === g.dialCode || $ === g.dialCodePlus ? h.push(g) : g.dialCodePlus.includes($) ? c.push(g) : g.initials.includes($) && C.push(g); return [ ...i.sort((g, I) => g.priority - I.priority), ...s.sort((g, I) => g.priority - I.priority), ...u.sort((g, I) => g.priority - I.priority), ...h.sort((g, I) => g.priority - I.priority), ...c.sort((g, I) => g.priority - I.priority), ...C.sort((g, I) => g.priority - I.priority) ]; } //* Update search results text (for a11y). _updateSearchResultsA11yText() { const { i18n: e } = this.options, $ = this.countryList.childElementCount; let i; $ === 0 ? i = e.zeroSearchResults : e.searchResultsText ? i = e.searchResultsText($) : $ === 1 ? i = e.oneSearchResult : i = e.multipleSearchResults.replace("${count}", $.toString()), this.searchResultsA11yText.textContent = i; } //* Highlight the next/prev item in the list (and ensure it is visible). _handleUpDownKey(e) { var i, s; let $ = e === "ArrowUp" ? (i = this.highlightedItem) == null ? void 0 : i.previousElementSibling : (s = this.highlightedItem) == null ? void 0 : s.nextElementSibling; !$ && this.countryList.childElementCount > 1 && ($ = e === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild), $ && (this._scrollTo($), this._highlightListItem($, !1)); } //* Select the currently highlighted item. _handleEnterKey() { this.highlightedItem && this._selectListItem(this.highlightedItem); } //* Update the input's value to the given val (format first if possible) //* NOTE: this is called from _setInitialState, handleUtils and setNumber. _updateValFromNumber(e) { let $ = e; if (this.options.formatOnDisplay && y.utils && this.selectedCountryData) { const i = this.options.nationalMode || $.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: s, INTERNATIONAL: u } = y.utils.numberFormat, h = i ? s : u; $ = y.utils.formatNumber( $, this.selectedCountryData.iso2, h ); } $ = this._beforeSetNumber($), this.telInput.value = $; } //* Check if need to select a n