UNPKG

intl-tel-input

Version:

A JavaScript plugin for entering and validating international telephone numbers

2,681 lines 422 kB
import { mergeModels as m0, useModel as Y0, ref as A1, onMounted as z0, watch as Z0, onUnmounted as J0, withDirectives as X0, createElementBlock as q0, openBlock as Q0, mergeProps as d2, vModelText as t2 } from "vue"; const e2 = [ [ "af", // Afghanistan "93", 0, null, "0" ], [ "ax", // Åland Islands "358", 1, ["18", "4"], // (4 is a mobile range shared with FI) "0" ], [ "al", // Albania "355", 0, null, "0" ], [ "dz", // Algeria "213", 0, null, "0" ], [ "as", // American Samoa "1", 5, ["684"], "1" ], [ "ad", // Andorra "376" ], [ "ao", // Angola "244" ], [ "ai", // Anguilla "1", 6, ["264"], "1" ], [ "ag", // Antigua and Barbuda "1", 7, ["268"], "1" ], [ "ar", // Argentina "54", 0, null, "0" ], [ "am", // Armenia "374", 0, null, "0" ], [ "aw", // Aruba "297" ], [ "ac", // Ascension Island "247" ], [ "au", // Australia "61", 0, ["4"], // (mobile range shared with CX and CC) "0" ], [ "at", // Austria "43", 0, null, "0" ], [ "az", // Azerbaijan "994", 0, null, "0" ], [ "bs", // Bahamas "1", 8, ["242"], "1" ], [ "bh", // Bahrain "973" ], [ "bd", // Bangladesh "880", 0, null, "0" ], [ "bb", // Barbados "1", 9, ["246"], "1" ], [ "by", // Belarus "375", 0, null, "8" ], [ "be", // Belgium "32", 0, null, "0" ], [ "bz", // Belize "501" ], [ "bj", // Benin "229" ], [ "bm", // Bermuda "1", 10, ["441"], "1" ], [ "bt", // Bhutan "975" ], [ "bo", // Bolivia "591", 0, null, "0" ], [ "ba", // Bosnia and Herzegovina "387", 0, null, "0" ], [ "bw", // Botswana "267" ], [ "br", // Brazil "55", 0, null, "0" ], [ "io", // British Indian Ocean Territory "246" ], [ "vg", // British Virgin Islands "1", 11, ["284"], "1" ], [ "bn", // Brunei "673" ], [ "bg", // Bulgaria "359", 0, null, "0" ], [ "bf", // Burkina Faso "226" ], [ "bi", // Burundi "257" ], [ "kh", // Cambodia "855", 0, null, "0" ], [ "cm", // Cameroon "237" ], [ "ca", // Canada "1", 1, ["204", "226", "236", "249", "250", "257", "263", "289", "306", "343", "354", "365", "367", "368", "382", "403", "416", "418", "428", "431", "437", "438", "450", "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", "942"], "1" ], [ "cv", // Cape Verde "238" ], [ "bq", // Caribbean Netherlands "599", 1, ["3", "4", "7"] ], [ "ky", // Cayman Islands "1", 12, ["345"], "1" ], [ "cf", // Central African Republic "236" ], [ "td", // Chad "235" ], [ "cl", // Chile "56" ], [ "cn", // China "86", 0, null, "0" ], [ "cx", // Christmas Island "61", 2, ["4", "89164"], // (4 is a mobile range shared with AU and CC) "0" ], [ "cc", // Cocos (Keeling) Islands "61", 1, ["4", "89162"], // (4 is a mobile range shared with AU and CX) "0" ], [ "co", // Colombia "57", 0, null, "0" ], [ "km", // Comoros "269" ], [ "cg", // Congo (Brazzaville) "242" ], [ "cd", // Congo (Kinshasa) "243", 0, null, "0" ], [ "ck", // Cook Islands "682" ], [ "cr", // Costa Rica "506" ], [ "ci", // Côte d'Ivoire "225" ], [ "hr", // Croatia "385", 0, null, "0" ], [ "cu", // Cuba "53", 0, null, "0" ], [ "cw", // Curaçao "599", 0 ], [ "cy", // Cyprus "357" ], [ "cz", // Czech Republic "420" ], [ "dk", // Denmark "45" ], [ "dj", // Djibouti "253" ], [ "dm", // Dominica "1", 13, ["767"], "1" ], [ "do", // Dominican Republic "1", 2, ["809", "829", "849"], "1" ], [ "ec", // Ecuador "593", 0, null, "0" ], [ "eg", // Egypt "20", 0, null, "0" ], [ "sv", // El Salvador "503" ], [ "gq", // Equatorial Guinea "240" ], [ "er", // Eritrea "291", 0, null, "0" ], [ "ee", // Estonia "372" ], [ "sz", // Eswatini "268" ], [ "et", // Ethiopia "251", 0, null, "0" ], [ "fk", // Falkland Islands (Malvinas) "500" ], [ "fo", // Faroe Islands "298" ], [ "fj", // Fiji "679" ], [ "fi", // Finland "358", 0, ["4"], // (mobile range shared with AX) "0" ], [ "fr", // France "33", 0, null, "0" ], [ "gf", // French Guiana "594", 0, null, "0" ], [ "pf", // French Polynesia "689" ], [ "ga", // Gabon "241" ], [ "gm", // Gambia "220" ], [ "ge", // Georgia "995", 0, null, "0" ], [ "de", // Germany "49", 0, null, "0" ], [ "gh", // Ghana "233", 0, null, "0" ], [ "gi", // Gibraltar "350" ], [ "gr", // Greece "30" ], [ "gl", // Greenland "299" ], [ "gd", // Grenada "1", 14, ["473"], "1" ], [ "gp", // Guadeloupe "590", 0, null, "0" ], [ "gu", // Guam "1", 15, ["671"], "1" ], [ "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", 0, null, "06" ], [ "is", // Iceland "354" ], [ "in", // India "91", 0, null, "0" ], [ "id", // Indonesia "62", 0, null, "0" ], [ "ir", // Iran "98", 0, null, "0" ], [ "iq", // Iraq "964", 0, null, "0" ], [ "ie", // Ireland "353", 0, null, "0" ], [ "im", // Isle of Man "44", 2, ["1624", "74576", "7524", "7624", "7924"], "0" ], [ "il", // Israel "972", 0, null, "0" ], [ "it", // Italy "39", 0, ["3"] // (mobile range shared with VA) ], [ "jm", // Jamaica "1", 4, ["658", "876"], "1" ], [ "jp", // Japan "81", 0, null, "0" ], [ "je", // Jersey "44", 3, ["1534", "7509", "7700", "7797", "7829", "7937"], "0" ], [ "jo", // Jordan "962", 0, null, "0" ], [ "kz", // Kazakhstan "7", 1, ["33", "7"], // (33 is shared with RU) "8" ], [ "ke", // Kenya "254", 0, null, "0" ], [ "ki", // Kiribati "686", 0, null, "0" ], [ "xk", // Kosovo "383", 0, null, "0" ], [ "kw", // Kuwait "965" ], [ "kg", // Kyrgyzstan "996", 0, null, "0" ], [ "la", // Laos "856", 0, null, "0" ], [ "lv", // Latvia "371" ], [ "lb", // Lebanon "961", 0, null, "0" ], [ "ls", // Lesotho "266" ], [ "lr", // Liberia "231", 0, null, "0" ], [ "ly", // Libya "218", 0, null, "0" ], [ "li", // Liechtenstein "423", 0, null, "0" ], [ "lt", // Lithuania "370", 0, null, "0" ], [ "lu", // Luxembourg "352" ], [ "mo", // Macao SAR China "853" ], [ "mg", // Madagascar "261", 0, null, "0" ], [ "mw", // Malawi "265", 0, null, "0" ], [ "my", // Malaysia "60", 0, null, "0" ], [ "mv", // Maldives "960" ], [ "ml", // Mali "223" ], [ "mt", // Malta "356" ], [ "mh", // Marshall Islands "692", 0, null, "1" ], [ "mq", // Martinique "596", 0, null, "0" ], [ "mr", // Mauritania "222" ], [ "mu", // Mauritius "230" ], [ "yt", // Mayotte "262", 1, ["269", "639"], "0" ], [ "mx", // Mexico "52" ], [ "fm", // Micronesia "691" ], [ "md", // Moldova "373", 0, null, "0" ], [ "mc", // Monaco "377", 0, null, "0" ], [ "mn", // Mongolia "976", 0, null, "0" ], [ "me", // Montenegro "382", 0, null, "0" ], [ "ms", // Montserrat "1", 16, ["664"], "1" ], [ "ma", // Morocco "212", 0, ["6", "7"], // (mobile ranges shared with EH) "0" ], [ "mz", // Mozambique "258" ], [ "mm", // Myanmar (Burma) "95", 0, null, "0" ], [ "na", // Namibia "264", 0, null, "0" ], [ "nr", // Nauru "674" ], [ "np", // Nepal "977", 0, null, "0" ], [ "nl", // Netherlands "31", 0, null, "0" ], [ "nc", // New Caledonia "687" ], [ "nz", // New Zealand "64", 0, null, "0" ], [ "ni", // Nicaragua "505" ], [ "ne", // Niger "227" ], [ "ng", // Nigeria "234", 0, null, "0" ], [ "nu", // Niue "683" ], [ "nf", // Norfolk Island "672" ], [ "kp", // North Korea "850", 0, null, "0" ], [ "mk", // North Macedonia "389", 0, null, "0" ], [ "mp", // Northern Mariana Islands "1", 17, ["670"], "1" ], [ "no", // Norway "47", 0, ["4", "9"] // (mobile ranges shared with SJ) ], [ "om", // Oman "968" ], [ "pk", // Pakistan "92", 0, null, "0" ], [ "pw", // Palau "680" ], [ "ps", // Palestinian Territories "970", 0, null, "0" ], [ "pa", // Panama "507" ], [ "pg", // Papua New Guinea "675" ], [ "py", // Paraguay "595", 0, null, "0" ], [ "pe", // Peru "51", 0, null, "0" ], [ "ph", // Philippines "63", 0, null, "0" ], [ "pl", // Poland "48" ], [ "pt", // Portugal "351" ], [ "pr", // Puerto Rico "1", 3, ["787", "939"], "1" ], [ "qa", // Qatar "974" ], [ "re", // Réunion "262", 0, null, "0" ], [ "ro", // Romania "40", 0, null, "0" ], [ "ru", // Russia "7", 0, ["33"], // (shared with KZ) "8" ], [ "rw", // Rwanda "250", 0, null, "0" ], [ "ws", // Samoa "685" ], [ "sm", // San Marino "378" ], [ "st", // São Tomé & Príncipe "239" ], [ "sa", // Saudi Arabia "966", 0, null, "0" ], [ "sn", // Senegal "221" ], [ "rs", // Serbia "381", 0, null, "0" ], [ "sc", // Seychelles "248" ], [ "sl", // Sierra Leone "232", 0, null, "0" ], [ "sg", // Singapore "65" ], [ "sx", // Sint Maarten "1", 21, ["721"], "1" ], [ "sk", // Slovakia "421", 0, null, "0" ], [ "si", // Slovenia "386", 0, null, "0" ], [ "sb", // Solomon Islands "677" ], [ "so", // Somalia "252", 0, null, "0" ], [ "za", // South Africa "27", 0, null, "0" ], [ "kr", // South Korea "82", 0, null, "0" ], [ "ss", // South Sudan "211", 0, null, "0" ], [ "es", // Spain "34" ], [ "lk", // Sri Lanka "94", 0, null, "0" ], [ "bl", // St. Barthélemy "590", 1, null, "0" ], [ "sh", // St. Helena "290" ], [ "kn", // St. Kitts & Nevis "1", 18, ["869"], "1" ], [ "lc", // St. Lucia "1", 19, ["758"], "1" ], [ "mf", // St. Martin "590", 2, null, "0" ], [ "pm", // St. Pierre & Miquelon "508", 0, null, "0" ], [ "vc", // St. Vincent & Grenadines "1", 20, ["784"], "1" ], [ "sd", // Sudan "249", 0, null, "0" ], [ "sr", // Suriname "597" ], [ "sj", // Svalbard & Jan Mayen "47", 1, ["4", "79", "9"] // (4 and 9 are mobile ranges shared with NO) ], [ "se", // Sweden "46", 0, null, "0" ], [ "ch", // Switzerland "41", 0, null, "0" ], [ "sy", // Syria "963", 0, null, "0" ], [ "tw", // Taiwan "886", 0, null, "0" ], [ "tj", // Tajikistan "992" ], [ "tz", // Tanzania "255", 0, null, "0" ], [ "th", // Thailand "66", 0, null, "0" ], [ "tl", // Timor-Leste "670" ], [ "tg", // Togo "228" ], [ "tk", // Tokelau "690" ], [ "to", // Tonga "676" ], [ "tt", // Trinidad & Tobago "1", 22, ["868"], "1" ], [ "tn", // Tunisia "216" ], [ "tr", // Turkey "90", 0, null, "0" ], [ "tm", // Turkmenistan "993", 0, null, "8" ], [ "tc", // Turks & Caicos Islands "1", 23, ["649"], "1" ], [ "tv", // Tuvalu "688" ], [ "vi", // U.S. Virgin Islands "1", 24, ["340"], "1" ], [ "ug", // Uganda "256", 0, null, "0" ], [ "ua", // Ukraine "380", 0, null, "0" ], [ "ae", // United Arab Emirates "971", 0, null, "0" ], [ "gb", // United Kingdom "44", 0, null, "0" ], [ "us", // United States "1", 0, null, "1" ], [ "uy", // Uruguay "598", 0, null, "0" ], [ "uz", // Uzbekistan "998" ], [ "vu", // Vanuatu "678" ], [ "va", // Vatican City "39", 1, ["06698", "3"] // (3 is a mobile range shared with IT) ], [ "ve", // Venezuela "58", 0, null, "0" ], [ "vn", // Vietnam "84", 0, null, "0" ], [ "wf", // Wallis & Futuna "681" ], [ "eh", // Western Sahara "212", 1, ["5288", "5289", "6", "7"], // (6 and 7 are mobile ranges shared with MA) "0" ], [ "ye", // Yemen "967", 0, null, "0" ], [ "zm", // Zambia "260", 0, null, "0" ], [ "zw", // Zimbabwe "263", 0, null, "0" ] ], Q = []; for (const h of e2) Q.push({ name: "", // populated in the plugin iso2: h[0], dialCode: h[1], priority: h[2] || 0, areaCodes: h[3] || null, nodeById: {}, // populated by the plugin nationalPrefix: h[4] || null, normalisedName: "", // populated in the plugin initials: "", // populated in the plugin dialCodePlus: "" // populated in the plugin }); const $2 = { 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" }, n2 = { 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" }, N0 = { ...$2, ...n2 }, g1 = { OPEN_COUNTRY_DROPDOWN: "open:countrydropdown", CLOSE_COUNTRY_DROPDOWN: "close:countrydropdown", COUNTRY_CHANGE: "countrychange", INPUT: "input" // used for synthetic input trigger }, E = { HIDE: "iti__hide", V_HIDE: "iti__v-hide", ARROW_UP: "iti__arrow--up", GLOBE: "iti__globe", FLAG: "iti__flag", COUNTRY_ITEM: "iti__country", HIGHLIGHT: "iti__highlight" }, x = { ARROW_UP: "ArrowUp", ARROW_DOWN: "ArrowDown", SPACE: " ", ENTER: "Enter", ESC: "Escape", TAB: "Tab" }, y0 = { PASTE: "insertFromPaste", DELETE_FWD: "deleteContentForward" }, q = { ALPHA_UNICODE: new RegExp("\\p{L}", "u"), // any kind of letter from any language NON_PLUS_NUMERIC: /[^+0-9]/, // chars that are NOT + or digit NON_PLUS_NUMERIC_GLOBAL: /[^+0-9]/g, // chars that are NOT + or digit (global) HIDDEN_SEARCH_CHAR: /^[a-zA-ZÀ-ÿа-яА-Я ]$/ // single acceptable hidden-search char }, i2 = { HIDDEN_SEARCH_RESET_MS: 1e3 }, I0 = { UNKNOWN_NUMBER_TYPE: -99, UNKNOWN_VALIDATION_ERROR: -99 }, w1 = { SANE_SELECTED_WITH_DIAL_WIDTH: 78, // px width fallback when separateDialCode enabled SANE_SELECTED_NO_DIAL_WIDTH: 42, // px width fallback when no separate dial code INPUT_PADDING_EXTRA_LEFT: 6 // px gap between selected country container and input text }, S0 = { NANP: "1" // North American Numbering Plan }, b1 = { DIAL_CODE: "44", // +44 United Kingdom MOBILE_PREFIX: "7", // UK mobile numbers start with 7 after national trunk (0) or core section MOBILE_CORE_LENGTH: 10 // core number length (excluding dial code / national prefix) for mobiles }, s2 = { ISO2: "us" }, M1 = { AGGRESSIVE: "aggressive", POLITE: "polite" }, T1 = { AUTO: "auto" }, _0 = { COUNTRY_CODE: "countryCode", DIAL_CODE: "dialCode" }, L = { EXPANDED: "aria-expanded", LABEL: "aria-label", SELECTED: "aria-selected", ACTIVE_DESCENDANT: "aria-activedescendant", HASPOPUP: "aria-haspopup", CONTROLS: "aria-controls", HIDDEN: "aria-hidden", AUTOCOMPLETE: "aria-autocomplete", MODAL: "aria-modal" }, D1 = (h) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(h).matches, r2 = () => { if (typeof navigator < "u" && typeof window < "u") { const h = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ), e = D1("(max-width: 500px)"), $ = D1("(max-height: 600px)"), i = D1("(pointer: coarse)"); return h || e || i && $; } return !1; }, L0 = { // 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: M1.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: r2(), //* The number type to enforce during validation. validationNumberTypes: ["MOBILE"] }, o2 = (h, e) => { h.useFullscreenPopup && (h.fixDropdownWidth = !1), h.onlyCountries.length === 1 && (h.initialCountry = h.onlyCountries[0]), h.separateDialCode && (h.nationalMode = !1), h.allowDropdown && !h.showFlags && !h.separateDialCode && (h.nationalMode = !1), h.useFullscreenPopup && !h.dropdownContainer && (h.dropdownContainer = document.body), h.i18n = { ...e, ...h.i18n }; }, m1 = (h) => h.replace(/\D/g, ""), A0 = (h = "") => h.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), u2 = (h, e) => { const $ = A0(e), i = [], s = [], a = [], u = [], f = [], C = []; for (const _ of h) _.iso2 === $ ? i.push(_) : _.normalisedName.startsWith($) ? s.push(_) : _.normalisedName.includes($) ? a.push(_) : $ === _.dialCode || $ === _.dialCodePlus ? u.push(_) : _.dialCodePlus.includes($) ? f.push(_) : _.initials.includes($) && C.push(_); const I = (_, A) => _.priority - A.priority; return [ ...i.sort(I), ...s.sort(I), ...a.sort(I), ...u.sort(I), ...f.sort(I), ...C.sort(I) ]; }, l2 = (h, e) => { const $ = e.toLowerCase(); for (const i of h) if (i.name.toLowerCase().startsWith($)) return i; return null; }, v1 = (h) => Object.keys(h).filter((e) => !!h[e]).join(" "), w = (h, e, $) => { const i = document.createElement(h); return e && Object.entries(e).forEach( ([s, a]) => i.setAttribute(s, a) ), $ && $.appendChild(i), i; }, a2 = () => ` <svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" ${L.HIDDEN}="true"> <circle cx="11" cy="11" r="7" /> <line x1="21" y1="21" x2="16.65" y2="16.65" /> </svg>`, c2 = (h) => { const e = `iti-${h}-clear-mask`; return ` <svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" ${L.HIDDEN}="true" focusable="false"> <mask id="${e}" 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(#${e})" /> </svg>`; }; class h2 { constructor(e, $, i) { this.highlightedItem = null, e.dataset.intlTelInputId = i.toString(), this.telInput = e, this.options = $, this.id = i, this.hadInitialPlaceholder = !!e.getAttribute("placeholder"), this.isRTL = !!this.telInput.closest("[dir=rtl]"), this.options.separateDialCode && (this.originalPaddingLeft = this.telInput.style.paddingLeft); } //* Generate all of the markup for the plugin: the selected country overlay, and the dropdown. generateMarkup(e) { this.countries = e, this._prepareTelInput(); const $ = this._createWrapperAndInsert(); this._maybeBuildCountryContainer($), $.appendChild(this.telInput), this._maybeUpdateInputPaddingAndReveal(), this._maybeBuildHiddenInputs($); } _prepareTelInput() { var e; this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !((e = this.telInput.form) != null && e.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off"); } _createWrapperAndInsert() { const { allowDropdown: e, showFlags: $, containerClass: i, useFullscreenPopup: s } = this.options, a = v1({ iti: !0, "iti--allow-dropdown": e, "iti--show-flags": $, "iti--inline-dropdown": !s, [i]: !!i }), u = w("div", { class: a }); return this.isRTL && u.setAttribute("dir", "ltr"), this.telInput.before(u), u; } _maybeBuildCountryContainer(e) { const { allowDropdown: $, separateDialCode: i, showFlags: s } = this.options; if ($ || s || i) { this.countryContainer = w( "div", // visibly hidden until we measure it's width to set the input padding correctly { class: `iti__country-container ${E.V_HIDE}` }, e ), $ ? (this.selectedCountry = w( "button", { type: "button", class: "iti__selected-country", [L.EXPANDED]: "false", [L.LABEL]: this.options.i18n.noCountrySelected, [L.HASPOPUP]: "dialog", [L.CONTROLS]: `iti-${this.id}__dropdown-content` }, this.countryContainer ), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = w( "div", { class: "iti__selected-country" }, this.countryContainer ); const a = w( "div", { class: "iti__selected-country-primary" }, this.selectedCountry ); this.selectedCountryInner = w( "div", { class: E.FLAG }, a ), $ && (this.dropdownArrow = w( "div", { class: "iti__arrow", [L.HIDDEN]: "true" }, a )), i && (this.selectedDialCode = w( "div", { class: "iti__selected-dial-code" }, this.selectedCountry )), $ && this._buildDropdownContent(); } } _buildDropdownContent() { const { fixDropdownWidth: e, useFullscreenPopup: $, countrySearch: i, i18n: s, dropdownContainer: a, containerClass: u } = this.options, f = e ? "" : "iti--flexible-dropdown-width"; if (this.dropdownContent = w("div", { id: `iti-${this.id}__dropdown-content`, class: `iti__dropdown-content ${E.HIDE} ${f}`, role: "dialog", [L.MODAL]: "true" }), this.isRTL && this.dropdownContent.setAttribute("dir", "rtl"), i && this._buildSearchUI(), this.countryList = w( "ul", { class: "iti__country-list", id: `iti-${this.id}__country-listbox`, role: "listbox", [L.LABEL]: s.countryListAriaLabel }, this.dropdownContent ), this._appendListItems(), i && this.updateSearchResultsA11yText(), a) { const C = v1({ iti: !0, "iti--container": !0, "iti--fullscreen-popup": $, "iti--inline-dropdown": !$, [u]: !!u }); this.dropdown = w("div", { class: C }), this.dropdown.appendChild(this.dropdownContent); } else this.countryContainer.appendChild(this.dropdownContent); } _buildSearchUI() { const { i18n: e } = this.options, $ = w( "div", { class: "iti__search-input-wrapper" }, this.dropdownContent ); this.searchIcon = w( "span", { class: "iti__search-icon", [L.HIDDEN]: "true" }, $ ), this.searchIcon.innerHTML = a2(), this.searchInput = w( "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", [L.EXPANDED]: "true", [L.LABEL]: e.searchPlaceholder, [L.CONTROLS]: `iti-${this.id}__country-listbox`, [L.AUTOCOMPLETE]: "list", autocomplete: "off" }, $ ), this.searchClearButton = w( "button", { type: "button", class: `iti__search-clear ${E.HIDE}`, [L.LABEL]: e.clearSearchAriaLabel, tabindex: "-1" }, $ ), this.searchClearButton.innerHTML = c2(this.id), this.searchResultsA11yText = w( "span", { class: "iti__a11y-text" }, this.dropdownContent ), this.searchNoResults = w( "div", { class: `iti__no-results ${E.HIDE}`, [L.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(E.V_HIDE)); } _maybeBuildHiddenInputs(e) { var i, s; const { hiddenInput: $ } = this.options; if ($) { const a = this.telInput.getAttribute("name") || "", u = $(a); if (u.phone) { const f = (i = this.telInput.form) == null ? void 0 : i.querySelector( `input[name="${u.phone}"]` ); f ? this.hiddenInput = f : (this.hiddenInput = w("input", { type: "hidden", name: u.phone }), e.appendChild(this.hiddenInput)); } if (u.country) { const f = (s = this.telInput.form) == null ? void 0 : s.querySelector( `input[name="${u.country}"]` ); f ? this.hiddenInputCountry = f : (this.hiddenInputCountry = w("input", { type: "hidden", name: u.country }), e.appendChild(this.hiddenInputCountry)); } } } //* For each country: add a country list item <li> to the countryList <ul> container. _appendListItems() { const e = document.createDocumentFragment(); for (let $ = 0; $ < this.countries.length; $++) { const i = this.countries[$], s = v1({ [E.COUNTRY_ITEM]: !0, [E.HIGHLIGHT]: $ === 0 }), a = w("li", { id: `iti-${this.id}__item-${i.iso2}`, class: s, tabindex: "-1", role: "option", [L.SELECTED]: "false" }); a.dataset.dialCode = i.dialCode, a.dataset.countryCode = i.iso2, i.nodeById[this.id] = a, this.options.showFlags && w("div", { class: `${E.FLAG} iti__${i.iso2}` }, a); const u = w("span", { class: "iti__country-name" }, a); u.textContent = i.name; const f = w("span", { class: "iti__dial-code" }, a); this.isRTL && f.setAttribute("dir", "ltr"), f.textContent = `+${i.dialCode}`, e.appendChild(a); } this.countryList.appendChild(e); } //* Update the input padding to make space for the selected country/dial code. updateInputPadding() { if (this.selectedCountry) { const e = this.options.separateDialCode ? w1.SANE_SELECTED_WITH_DIAL_WIDTH : w1.SANE_SELECTED_NO_DIAL_WIDTH, i = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || e) + w1.INPUT_PADDING_EXTRA_LEFT; this.telInput.style.paddingLeft = `${i}px`; } } //* When input is in a hidden container during init, we cannot calculate the selected country width. //* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width. //* To get the right styling to apply, all we need is a shallow clone of the container, //* and then to inject a deep clone of the selectedCountry element. _getHiddenSelectedCountryWidth() { if (this.telInput.parentNode) { let e; try { e = window.top.document.body; } catch { e = document.body; } const $ = this.telInput.parentNode.cloneNode( !1 ); $.style.visibility = "hidden", e.appendChild($); const i = this.countryContainer.cloneNode(); $.appendChild(i); const s = this.selectedCountry.cloneNode( !0 ); i.appendChild(s); const a = s.offsetWidth; return e.removeChild($), a; } return 0; } //* 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; } //* Check if an element is visible within it's container, else scroll until it is. scrollTo(e) { const $ = this.countryList, i = document.documentElement.scrollTop, s = $.offsetHeight, a = $.getBoundingClientRect().top + i, u = a + s, f = e.offsetHeight, C = e.getBoundingClientRect().top + i, I = C + f, _ = C - a + $.scrollTop; if (C < a) $.scrollTop = _; else if (I > u) { const A = s - f; $.scrollTop = _ - A; } } //* Remove highlighting from other list items and highlight the given item. highlightListItem(e, $) { const i = this.highlightedItem; if (i && (i.classList.remove(E.HIGHLIGHT), i.setAttribute(L.SELECTED, "false")), this.highlightedItem = e, this.highlightedItem && (this.highlightedItem.classList.add(E.HIGHLIGHT), this.highlightedItem.setAttribute(L.SELECTED, "true"), this.options.countrySearch)) { const s = this.highlightedItem.getAttribute("id") || ""; this.searchInput.setAttribute(L.ACTIVE_DESCENDANT, s); } $ && this.highlightedItem.focus(); } //* Country search: Filter the country list to the given array of countries. filterCountries(e) { this.countryList.innerHTML = ""; let $ = !0; for (const i of e) { const s = i.nodeById[this.id]; s && (this.countryList.appendChild(s), $ && (this.highlightListItem(s, !1), $ = !1)); } $ ? (this.highlightListItem(null, !1), this.searchNoResults && this.searchNoResults.classList.remove(E.HIDE)) : this.searchNoResults && this.searchNoResults.classList.add(E.HIDE), this.countryList.scrollTop = 0, this.updateSearchResultsA11yText(); } destroy() { this.telInput.iti = void 0, delete this.telInput.dataset.intlTelInputId, this.options.separateDialCode && (this.telInput.style.paddingLeft = this.originalPaddingLeft); const e = this.telInput.parentNode; e.before(this.telInput), e.remove(), this.telInput = null, this.countryContainer = null, this.selectedCountry = null, this.selectedCountryInner = null, this.selectedDialCode = null, this.dropdownArrow = null, this.dropdownContent = null, this.searchInput = null, this.searchIcon = null, this.searchClearButton = null, this.searchNoResults = null, this.searchResultsA11yText = null, this.countryList = null, this.dropdown = null, this.hiddenInput = null, this.hiddenInputCountry = null, this.highlightedItem = null; for (const $ of this.countries) delete $.nodeById[this.id]; this.countries = null; } } const f2 = (h) => { const { onlyCountries: e, excludeCountries: $ } = h; if (e.length) { const i = e.map( (s) => s.toLowerCase() ); return Q.filter( (s) => i.includes(s.iso2) ); } else if ($.length) { const i = $.map( (s) => s.toLowerCase() ); return Q.filter( (s) => !i.includes(s.iso2) ); } return Q; }, p2 = (h, e) => { for (const $ of h) { const i = $.iso2.toLowerCase(); e.i18n[i] && ($.name = e.i18n[i]); } }, C2 = (h, e) => { const $ = /* @__PURE__ */ new Set(); let i = 0; const s = {}, a = (u, f, C) => { if (!u || !f) return; f.length > i && (i = f.length), s.hasOwnProperty(f) || (s[f] = []); const I = s[f]; if (I.includes(u)) return; const _ = C !== void 0 ? C : I.length; I[_] = u; }; for (const u of h) { $.has(u.dialCode) || $.add(u.dialCode); for (let f = 1; f < u.dialCode.length; f++) { const C = u.dialCode.substring(0, f); a(u.iso2, C); } a(u.iso2, u.dialCode, u.priority); } (e.onlyCountries.length || e.excludeCountries.length) && $.forEach((u) => { s[u] = s[u].filter(Boolean); }); for (const u of h) if (u.areaCodes) { const f = s[u.dialCode][0]; for (const C of u.areaCodes) { for (let I = 1; I < C.length; I++) { const _ = C.substring(0, I), A = u.dialCode + _; a(f, A), a(u.iso2, A); } a(u.iso2, u.dialCode + C); } } return { dialCodes: $, dialCodeMaxLen: i, dialCodeToIso2Map: s }; }, g2 = (h, e) => { e.countryOrder && (e.countryOrder = e.countryOrder.map( ($) => $.toLowerCase() )), h.sort(($, i) => { const { countryOrder: s } = e; if (s) { const a = s.indexOf($.iso2), u = s.indexOf(i.iso2), f = a > -1, C = u > -1; if (f || C) return f && C ? a - u : f ? -1 : 1; } return $.name.localeCompare(i.name); }); }, m2 = (h) => { for (const e of h) e.normalisedName = A0(e.name), e.initials = e.normalisedName.split(/[^a-z]/).map(($) => $[0]).join(""), e.dialCodePlus = `+${e.dialCode}`; }, y2 = (h, e, $, i) => { let s = h; if ($ && e) { e = `+${i.dialCode}`; const a = s[e.length] === " " || s[e.length] === "-" ? e.length + 1 : e.length; s = s.substring(a); } return s; }, I2 = (h, e, $, i, s) => { const a = $ ? $.formatNumberAsYouType(h, i.iso2) : h, { dialCode: u } = i; return s && e.charAt(0) !== "+" && a.includes(`+${u}`) ? (a.split(`+${u}`)[1] || "").trim() : a; }, _2 = (h, e, $, i) => { if ($ === 0 && !i) return 0; let s = 0; for (let a = 0; a < e.length; a++) { if (/[+0-9]/.test(e[a]) && s++, s === h && !i) return a + 1; if (i && s === h + 1) return a; } return e.length; }, E2 = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ], E0 = (h) => { const e = m1(h); if (e.startsWith(S0.NANP) && e.length >= 4) { const $ = e.substring(1, 4); return E2.includes($); } return !1; }; for (const h of Q) h.name = N0[h.iso2]; let N2 = 0; const S2 = new Set(Q.map((h) => h.iso2)), P1 = (h) => S2.has(h); class R1 { constructor(e, $ = {}) { this.id = N2++, this.options = { ...L0, ...$ }, o2(this.options, N0), this.ui = new h2(e, this.options, this.id), this.isAndroid = R1._getIsAndroid(), this.promise = this._createInitPromises(), this.countries = f2(this.options); const { dialCodes: i, dialCodeMaxLen: s, dialCodeToIso2Map: a } = C2( this.countries, this.options ); this.dialCodes = i, this.dialCodeMaxLen = s, this.dialCodeToIso2Map = a, this.countryByIso2 = new Map(this.countries.map((u) => [u.iso2, u])), this._init(); } static _getIsAndroid() { return typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1; } _createInitPromises() { const e = new Promise((i, s) => { this.resolveAutoCountryPromise = i, this.rejectAutoCountryPromise = s; }), $ = new Promise((i, s) => { this.resolveUtilsScriptPromise = i, this.rejectUtilsScriptPromise = s; }); return Promise.all([e, $]); } //* Can't be private as it's called from intlTelInput convenience wrapper. _init() { this.selectedCountryData = {}, this.abortController = new AbortController(), this._processCountryData(), this.ui.generateMarkup(this.countries), this._setInitialState(), this._initListeners(), this._initRequests(); } //******************** //* PRIVATE METHODS //******************** //* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options. _processCountryData() { p2(this.countries, this.options), g2(this.countries, this.options), m2(this.countries); } //* 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.ui.telInput.getAttribute("value"), i = this.ui.telInput.value, a = $ && $.startsWith("+") && (!i || !i.startsWith("+")) ? $ : i, u = this._getDialCode(a), f = E0(a), { initialCountry: C, geoIpLookup: I } = this.options, _ = C === T1.AUTO && I; if (u && !f) this._updateCountryFromNumber(a); else if (!_ || e) { const A = C ? C.toLowerCase() : ""; P1(A) ? this._setCountry(A) : u && f ? this._setCountry(s2.ISO2) : this._setCountry(""); } a && this._updateValFromNumber(a); } //* Initialise the main event listeners: input keyup, and click selected country. _initListeners() { this._initTelInputListeners(), this.options.allowDropdown && this._initDropdownListeners(), (this.ui.hiddenInput || this.ui.hiddenInputCountry) && this.ui.telInput.form && this._initHiddenInputListener(); } //* Update hidden input on form submit. _initHiddenInputListener() { var $; const e = () => { this.ui.hiddenInput && (this.ui.hiddenInput.value = this.getNumber()), this.ui.hiddenInputCountry && (this.ui.hiddenInputCountry.value = this.selectedCountryData.iso2 || ""); }; ($ = this.ui.telInput.form) == null || $.addEventListener("submit", e, { signal: this.abortController.signal }); } //* initialise the dropdown listeners. _initDropdownListeners() { const e = this.abortController.signal, $ = (u) => { this.ui.dropdownContent.classList.contains(E.HIDE) ? this.ui.telInput.focus() : u.preventDefault(); }, i = this.ui.telInput.closest("label"); i && i.addEventListener("click", $, { signal: e }); const s = () => { this.ui.dropdownContent.classList.contains( E.HIDE ) && !this.ui.telInput.disabled && !this.ui.telInput.readOnly && this._openDropdown(); }; this.ui.selectedCountry.addEventListener( "click", s, { signal: e } ); const a = (u) => { this.ui.dropdownContent.classList.contains( E.HIDE ) && [x.ARROW_UP, x.ARROW_DOWN, x.SPACE, x.ENTER].includes(u.key) && (u.preventDefault(), u.stopPropagation(), this._openDropdown()), u.key === x.TAB && this._closeDropdown(); }; this.ui.countryContainer.addEventListener( "keydown", a, { signal: e } ); } //* Init many requests: utils script / geo ip lookup. _initRequests() { const { loadUtils: e, initialCountry: $, geoIpLookup: i } = this.options; if (e && !m.utils) { const a = () => { var u; (u = m.attachUtils(e)) == null || u.catch(() => { }); }; if (m.documentReady()) a(); else { const u = () => { a(); }; window.addEventListener("load", u, { signal: this.abortController.signal }); } } else this.resolveUtilsScriptPromise(); $ === T1.AUTO && i && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise(); } //* Perform the geo ip lookup. _loadAutoCountry() { m.autoCountry ? this.handleAutoCountry() : m.startedLoadingAutoCountry || (m.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup( (e = "") => { const $ = e.toLowerCase(); P1($) ? (m.autoCountry = $, setTimeout(() => r1("handleAutoCountry"))) : (this._setInitialState(!0), r1("rejectAutoCountryPromise")); }, () => { this._setInitialState(!0), r1("rejectAutoCountryPromise"); } )); } _openDropdownWithPlus() { this._openDropdown(), this.ui.searchInput.value = "+", this._filterCountriesByQuery(""); } //* Initialize the tel input listeners. _initTelInputListeners() { this._bindInputListener(), this._maybeBindKeydownListener(), this._maybeBindPasteListener(); } _bindInputListener() { const { strictMode: e, formatAsYouType: $, separateDialCode: i, allowDropdown: s, countrySearch: a } = this.options; let u = !1; q.ALPHA_UNICODE.test(this.ui.telInput.value) && (u = !0); const f = (C) => { if (t