intl-tel-input
Version:
A JavaScript plugin for entering and validating international telephone numbers
2,252 lines • 406 kB
JavaScript
import { mergeModels as i2, useModel as A2, ref as I1, onMounted as E2, watch as D2, onUnmounted as M2, withDirectives as P2, openBlock as x2, createElementBlock as R2, mergeProps as B2, vModelText as k2 } from "vue";
const s2 = [
[
"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"
],
[
"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"
],
[
"vi",
// U.S. Virgin Islands
"1",
24,
["340"]
],
[
"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"
]
], W = [];
for (let y = 0; y < s2.length; y++) {
const e = s2[y];
W[y] = {
name: "",
// this is now populated in the plugin
iso2: e[0],
dialCode: e[1],
priority: e[2] || 0,
areaCodes: e[3] || null,
nodeById: {},
nationalPrefix: e[4] || null
};
}
const O2 = {
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"
}, G2 = {
selectedCountryAriaLabel: "Selected country",
noCountrySelected: "No country selected",
countryListAriaLabel: "List of countries",
searchPlaceholder: "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"
}, u2 = { ...O2, ...G2 };
for (let y = 0; y < W.length; y++)
W[y].name = u2[W[y].iso2];
let F2 = 0;
const l2 = {
//* 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: typeof navigator < "u" && typeof window < "u" ? (
//* We cannot just test screen size as some smartphones/website meta tags will report desktop resolutions.
//* Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
/Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
) || window.innerWidth <= 500
) : !1,
//* The number type to enforce during validation.
validationNumberTypes: ["MOBILE"]
}, U2 = [
"800",
"822",
"833",
"844",
"855",
"866",
"877",
"880",
"881",
"882",
"883",
"884",
"885",
"886",
"887",
"888",
"889"
], c1 = (y) => y.replace(/\D/g, ""), r2 = (y = "") => y.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), o2 = (y) => {
const e = c1(y);
if (e.charAt(0) === "1") {
const n = e.substr(1, 3);
return U2.includes(n);
}
return !1;
}, V2 = (y, e, n, s) => {
if (n === 0 && !s)
return 0;
let o = 0;
for (let a = 0; a < e.length; a++) {
if (/[+0-9]/.test(e[a]) && o++, o === y && !s)
return a + 1;
if (s && o === y + 1)
return a;
}
return e.length;
}, T = (y, e, n) => {
const s = document.createElement(y);
return e && Object.entries(e).forEach(([o, a]) => s.setAttribute(o, a)), n && n.appendChild(s), s;
}, $1 = (y, ...e) => {
const { instances: n } = C;
Object.values(n).forEach((s) => s[y](...e));
};
class K2 {
constructor(e, n = {}) {
this.id = F2++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, l2, n), this.hadInitialPlaceholder = !!e.getAttribute("placeholder");
}
//* Can't be private as it's called from intlTelInput convenience wrapper.
_init() {
this.options.useFullscreenPopup && (this.options.fixDropdownWidth = !1), this.options.onlyCountries.length === 1 && (this.options.initialCountry = this.options.onlyCountries[0]), this.options.separateDialCode && (this.options.nationalMode = !1), this.options.allowDropdown && !this.options.showFlags && !this.options.separateDialCode && (this.options.nationalMode = !1), this.options.useFullscreenPopup && !this.options.dropdownContainer && (this.options.dropdownContainer = document.body), this.isAndroid = typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, this.isRTL = !!this.telInput.closest("[dir=rtl]");
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), this.options.i18n = { ...u2, ...this.options.i18n };
const n = new Promise((o, a) => {
this.resolveAutoCountryPromise = o, this.rejectAutoCountryPromise = a;
}), s = new Promise((o, a) => {
this.resolveUtilsScriptPromise = o, this.rejectUtilsScriptPromise = a;
});
this.promise = Promise.all([n, s]), 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._processAllCountries(), this._processDialCodes(), this._translateCountryNames(), this._sortCountries();
}
//* Sort countries by countryOrder option (if present), then name.
_sortCountries() {
this.options.countryOrder && (this.options.countryOrder = this.options.countryOrder.map((e) => e.toLowerCase())), this.countries.sort((e, n) => {
const { countryOrder: s } = this.options;
if (s) {
const o = s.indexOf(e.iso2), a = s.indexOf(n.iso2), c = o > -1, g = a > -1;
if (c || g)
return c && g ? o - a : c ? -1 : 1;
}
return e.name.localeCompare(n.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
_addToDialCodeMap(e, n, s) {
n.length > this.dialCodeMaxLen && (this.dialCodeMaxLen = n.length), this.dialCodeToIso2Map.hasOwnProperty(n) || (this.dialCodeToIso2Map[n] = []);
for (let a = 0; a < this.dialCodeToIso2Map[n].length; a++)
if (this.dialCodeToIso2Map[n][a] === e)
return;
const o = s !== void 0 ? s : this.dialCodeToIso2Map[n].length;
this.dialCodeToIso2Map[n][o] = e;
}
//* Process onlyCountries or excludeCountries array if present.
_processAllCountries() {
const { onlyCountries: e, excludeCountries: n } = this.options;
if (e.length) {
const s = e.map(
(o) => o.toLowerCase()
);
this.countries = W.filter(
(o) => s.includes(o.iso2)
);
} else if (n.length) {
const s = n.map(
(o) => o.toLowerCase()
);
this.countries = W.filter(
(o) => !s.includes(o.iso2)
);
} else
this.countries = W;
}
//* Translate Countries by object literal provided on config.
_translateCountryNames() {
for (let e = 0; e < this.countries.length; e++) {
const n = this.countries[e].iso2.toLowerCase();
this.options.i18n.hasOwnProperty(n) && (this.countries[e].name = this.options.i18n[n]);
}
}
//* Generate this.dialCodes and this.dialCodeToIso2Map.
_processDialCodes() {
this.dialCodes = {}, this.dialCodeMaxLen = 0, this.dialCodeToIso2Map = {};
for (let e = 0; e < this.countries.length; e++) {
const n = this.countries[e];
this.dialCodes[n.dialCode] || (this.dialCodes[n.dialCode] = !0), this._addToDialCodeMap(n.iso2, n.dialCode, n.priority);
}
for (let e = 0; e < this.countries.length; e++) {
const n = this.countries[e];
if (n.areaCodes) {
const s = this.dialCodeToIso2Map[n.dialCode][0];
for (let o = 0; o < n.areaCodes.length; o++) {
const a = n.areaCodes[o];
for (let c = 1; c < a.length; c++) {
const g = a.substr(0, c), f = n.dialCode + g;
this._addToDialCodeMap(s, f), this._addToDialCodeMap(n.iso2, f);
}
this._addToDialCodeMap(n.iso2, n.dialCode + a);
}
}
}
}
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
_generateMarkup() {
var I, A, G;
this.telInput.classList.add("iti__tel-input"), !this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete")) && this.telInput.setAttribute("autocomplete", "off");
const {
allowDropdown: e,
separateDialCode: n,
showFlags: s,
containerClass: o,
hiddenInput: a,
dropdownContainer: c,
fixDropdownWidth: g,
useFullscreenPopup: f,
countrySearch: S,
i18n: _
} = this.options;
let b = "iti";
e && (b += " iti--allow-dropdown"), s && (b += " iti--show-flags"), o && (b += ` ${o}`), f || (b += " iti--inline-dropdown");
const w = T("div", { class: b });
if ((I = this.telInput.parentNode) == null || I.insertBefore(w, this.telInput), e || s || n) {
this.countryContainer = T(
"div",
{ class: "iti__country-container" },
w
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", e ? (this.selectedCountry = T(
"button",
{
type: "button",
class: "iti__selected-country",
"aria-expanded": "false",
"aria-label": this.options.i18n.selectedCountryAriaLabel,
"aria-haspopup": "true",
"aria-controls": `iti-${this.id}__dropdown-content`,
role: "combobox"
},
this.countryContainer
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = T(
"div",
{ class: "iti__selected-country" },
this.countryContainer
);
const F = T("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
if (this.selectedCountryInner = T("div", { class: "iti__flag" }, F), this.selectedCountryA11yText = T(
"span",
{ class: "iti__a11y-text" },
this.selectedCountryInner
), e && (this.dropdownArrow = T(
"div",
{ class: "iti__arrow", "aria-hidden": "true" },
F
)), n && (this.selectedDialCode = T(
"div",
{ class: "iti__selected-dial-code" },
this.selectedCountry
)), e) {
const M = g ? "" : "iti--flexible-dropdown-width";
if (this.dropdownContent = T("div", {
id: `iti-${this.id}__dropdown-content`,
class: `iti__dropdown-content iti__hide ${M}`
}), S && (this.searchInput = T(
"input",
{
type: "text",
class: "iti__search-input",
placeholder: _.searchPlaceholder,
role: "combobox",
"aria-expanded": "true",
"aria-label": _.searchPlaceholder,
"aria-controls": `iti-${this.id}__country-listbox`,
"aria-autocomplete": "list",
autocomplete: "off"
},
this.dropdownContent
), this.searchResultsA11yText = T(
"span",
{ class: "iti__a11y-text" },
this.dropdownContent
)), this.countryList = T(
"ul",
{
class: "iti__country-list",
id: `iti-${this.id}__country-listbox`,
role: "listbox",
"aria-label": _.countryListAriaLabel
},
this.dropdownContent
), this._appendListItems(), S && this._updateSearchResultsText(), c) {
let x = "iti iti--container";
f ? x += " iti--fullscreen-popup" : x += " iti--inline-dropdown", this.dropdown = T("div", { class: x }), this.dropdown.appendChild(this.dropdownContent);
} else
this.countryContainer.appendChild(this.dropdownContent);
}
}
if (w.appendChild(this.telInput), this._updateInputPadding(), a) {
const F = this.telInput.getAttribute("name") || "", M = a(F);
if (M.phone) {
const x = (A = this.telInput.form) == null ? void 0 : A.querySelector(`input[name="${M.phone}"]`);
x ? this.hiddenInput = x : (this.hiddenInput = T("input", {
type: "hidden",
name: M.phone
}), w.appendChild(this.hiddenInput));
}
if (M.country) {
const x = (G = this.telInput.form) == null ? void 0 : G.querySelector(`input[name="${M.country}"]`);
x ? this.hiddenInputCountry = x : (this.hiddenInputCountry = T("input", {
type: "hidden",
name: M.country
}), w.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 n = this.countries[e], s = e === 0 ? "iti__highlight" : "", o = T(
"li",
{
id: `iti-${this.id}__item-${n.iso2}`,
class: `iti__country ${s}`,
tabindex: "-1",
role: "option",
"data-dial-code": n.dialCode,
"data-country-code": n.iso2,
"aria-selected": "false"
},
this.countryList
);
n.nodeById[this.id] = o;
let a = "";
this.options.showFlags && (a += `<div class='iti__flag iti__${n.iso2}'></div>`), a += `<span class='iti__country-name'>${n.name}</span>`, a += `<span class='iti__dial-code'>+${n.dialCode}</span>`, o.insertAdjacentHTML("beforeend", a);
}
}
//* 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 n = this.telInput.getAttribute("value"), s = this.telInput.value, a = n && n.charAt(0) === "+" && (!s || s.charAt(0) !== "+") ? n : s, c = this._getDialCode(a), g = o2(a), { initialCountry: f, geoIpLookup: S } = this.options, _ = f === "auto" && S;
if (c && !g)
this._updateCountryFromNumber(a);
else if (!_ || e) {
const b = f ? f.toLowerCase() : "";
b && this._getCountryData(b, !0) ? this._setCountry(b) : c && g ? this._setCountry("us") : 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.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 = (n) => {
this.dropdownContent.classList.contains("iti__hide") ? this.telInput.focus() : n.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 = (n) => {
this.dropdownContent.classList.contains("iti__hide") && ["ArrowUp", "ArrowDown", " ", "Enter"].includes(n.key) && (n.preventDefault(), n.stopPropagation(), this._openDropdown()), n.key === "Tab" && this._closeDropdown();
}, this.countryContainer.addEventListener(
"keydown",
this._handleCountryContainerKeydown
);
}
//* Init many requests: utils script / geo ip lookup.
_initRequests() {
let { loadUtils: e, initialCountry: n, geoIpLookup: s } = this.options;
e && !C.utils ? (this._handlePageLoad = () => {
var a;
window.removeEventListener("load", this._handlePageLoad), (a = C.attachUtils(e)) == null || a.catch(() => {
});
}, C.documentReady() ? this._handlePageLoad() : window.addEventListener("load", this._handlePageLoad)) : this.resolveUtilsScriptPromise(), n === "auto" && s && !this.selectedCountryData.iso2 ? this._loadAutoCountry() : this.resolveAutoCountryPromise();
}
//* Perform the geo ip lookup.
_loadAutoCountry() {
C.autoCountry ? this.handleAutoCountry() : C.startedLoadingAutoCountry || (C.startedLoadingAutoCountry = !0, typeof this.options.geoIpLookup == "function" && this.options.geoIpLookup(
(e = "") => {
const n = e.toLowerCase();
n && this._getCountryData(n, !0) ? (C.autoCountry = n, setTimeout(() => $1("handleAutoCountry"))) : (this._setInitialState(!0), $1("rejectAutoCountryPromise"));
},
() => {
this._setInitialState(!0), $1("rejectAutoCountryPromise");
}
));
}
_openDropdownWithPlus() {
this._openDropdown(), this.searchInput.value = "+", this._filterCountries("", !0);
}
//* Initialize the tel input listeners.
_initTelInputListeners() {
const { strictMode: e, formatAsYouType: n, separateDialCode: s, formatOnDisplay: o, allowDropdown: a, countrySearch: c } = this.options;
let g = !1;
new RegExp("\\p{L}", "u").test(this.telInput.value) && (g = !0), this._handleInputEvent = (f) => {
if (this.isAndroid && (f == null ? void 0 : f.data) === "+" && s && a && c) {
const w = this.telInput.selectionStart || 0, I = this.telInput.value.substring(0, w - 1), A = this.telInput.value.substring(w);
this.telInput.value = I + A, this._openDropdownWithPlus();
return;
}
this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
const S = (f == null ? void 0 : f.data) && /[^+0-9]/.test(f.data), _ = (f == null ? void 0 : f.inputType) === "insertFromPaste" && this.telInput.value;
S || _ && !e ? g = !0 : /[^+0-9]/.test(this.telInput.value) || (g = !1);
const b = (f == null ? void 0 : f.detail) && f.detail.isSetNumber && !o;
if (n && !g && !b) {
const w = this.telInput.selectionStart || 0, A = this.telInput.value.substring(0, w).replace(/[^+0-9]/g, "").length, G = (f == null ? void 0 : f.inputType) === "deleteContentForward", F = this._formatNumberAsYouType(), M = V2(A, F, w, G);
this.telInput.value = F, this.telInput.setSelectionRange(M, M);
}
}, this.telInput.addEventListener("input", this._handleInputEvent), (e || s) && (this._handleKeydownEvent = (f) => {
if (f.key && f.key.length === 1 && !f.altKey && !f.ctrlKey && !f.metaKey) {
if (s && a && c && f.key === "+") {
f.preventDefault(), this._openDropdownWithPlus();
return;
}
if (e) {
const S = this.telInput.value, _ = S.charAt(0) === "+", b = !_ && this.telInput.selectionStart === 0 && f.key === "+", w = /^[0-9]$/.test(f.key), I = s ? w : b || w, A = S.slice(0, this.telInput.selectionStart) + f.key + S.slice(this.telInput.selectionEnd), G = this._getFullNumber(A), F = C.utils.getCoreNumber(G, this.selectedCountryData.iso2), M = this.maxCoreNumberLength && F.length > this.maxCoreNumberLength;
let x = !1;
if (_) {
const f1 = this.selectedCountryData.iso2;
x = this._getCountryFromNumber(G) !== f1;
}
(!I || M && !x && !b) && f.preventDefault();
}
}
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
}
//* Adhere to the input's maxlength attr.
_cap(e) {
const n = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
return n && e.length > n ? e.substr(0, n) : e;
}
//* Trigger a custom event on the input.
_trigger(e, n = {}) {
const s = new CustomEvent(e, {
bubbles: !0,
cancelable: !0,
detail: n
});
this.telInput.dispatchEvent(s);
}
//* Open the dropdown.
_openDropdown() {
const { fixDropdownWidth: e, countrySearch: n } = 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(), n) {
const s = this.countryList.firstElementChild;
s && (this._highlightListItem(s, !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(), n = this.telInput.offsetHeight;
this.options.dropdownContainer && (this.dropdown.style.top = `${e.top + n}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 = (o) => {
var c;
const a = (c = o.target) == null ? void 0 : c.closest(".iti__country");
a && this._highlightListItem(a, !1);
}, this.countryList.addEventListener(
"mouseover",
this._handleMouseoverCountryList
), this._handleClickCountryList = (o) => {
var c;
const a = (c = o.target) == null ? void 0 : c.closest(".iti__country");
a && this._selectListItem(a);
}, this.countryList.addEventListener("click", this._handleClickCountryList);
let e = !0;
this._handleClickOffToClose = () => {
e || this._closeDropdown(), e = !1;
}, document.documentElement.addEventListener(
"click",
this._handleClickOffToClose
);
let n = "", s = null;
if (this._handleKeydownOnDropdown = (o) => {
["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(o.key) && (o.preventDefault(), o.stopPropagation(), o.key === "ArrowUp" || o.key === "ArrowDown" ? this._handleUpDownKey(o.key) : o.key === "Enter" ? this._handleEnterKey() : o.key === "Escape" && this._closeDropdown()), !this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(o.key) && (o.stopPropagation(), s && clearTimeout(s), n += o.key.toLowerCase(), this._searchForCountry(n), s = setTimeout(() => {
n = "";
}, 1e3));
}, document.addEventListener("keydown", this._handleKeydownOnDropdown), this.options.countrySearch) {
const o = () => {
const c = this.searchInput.value.trim();
c ? this._filterCountries(c) : this._filterCountries("", !0);
};
let a = null;
this._handleSearchChange = () => {
a && clearTimeout(a), a = setTimeout(() => {
o(), a = null;
}, 100);
}, this.searchInput.addEventListener("input", this._handleSearchChange), this.searchInput.addEventListener("click", (c) => c.stopPropagation());
}
}
//* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
_searchForCountry(e) {
for (let n = 0; n < this.countries.length; n++) {
const s = this.countries[n];
if (s.name.substr(0, e.length).toLowerCase() === e) {
const a = s.nodeById[this.id];
this._highlightListItem(a, !1), this._scrollTo(a);
break;
}
}
}
//* Country search enabled: Filter the countries according to the search query.
_filterCountries(e, n = !1) {
let s = !0;
this.countryList.innerHTML = "";
const o = r2(e);
for (let a = 0; a < this.countries.length; a++) {
const c = this.countries[a], g = r2(c.name), f = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((_) => _[0]).join("").toLowerCase(), S = `+${c.dialCode}`;
if (n || g.includes(o) || S.includes(o) || c.iso2.includes(o) || f.includes(o)) {
const _ = c.nodeById[this.id];
_ && this.countryList.appendChild(_), s && (this._highlightListItem(_, !1), s = !1);
}
}
s && this._highlightListItem(null, !1), this.countryList.scrollTop = 0, this._updateSearchResultsText();
}
//* Update search results text (for a11y).
_updateSearchResultsText() {
const { i18n: e } = this.options, n = this.countryList.childElementCount;
let s;
n === 0 ? s = e.zeroSearchResults : n === 1 ? s = e.oneSearchResult : s = e.multipleSearchResults.replace("${count}", n.toString()), this.searchResultsA11yText.textContent = s;
}
//* Highlight the next/prev item in the list (and ensure it is visible).
_handleUpDownKey(e) {
var s, o;
let n = e === "ArrowUp" ? (s = this.highlightedItem) == null ? void 0 : s.previousElementSibling : (o = this.highlightedItem) == null ? void 0 : o.nextElementSibling;
!n && this.countryList.childElementCount > 1 && (n = e === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild), n && (this._scrollTo(n), this._highlightListItem(n, !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 n = e;
if (this.options.formatOnDisplay && C.utils && this.selectedCountryData) {
const s = this.options.nationalMode || n.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: o, INTERNATIONAL: a } = C.utils.numberFormat, c = s ? o : a;
n = C.utils.formatNumber(
n,
this.selectedCountryData.iso2,
c
);
}
n = this._beforeSetNumber(n), this.telInput.value = n;
}
//* Check if need to select a new country based on the given number
//* Note: called from _setInitialState, keyup handler, setNumber.
_updateCountryFromNumber(e) {
const n = this._getCountryFromNumber(e);
return n !== null ? this._setCountry(n) : !1;
}
_ensureHasDialCode(e) {
const { dialCode: n, nationalPrefix: s } = this.selectedCountryData;
if (e.charAt(0) === "+" || !n)
return e;
const c = s && e.charAt(0) === s && !this.options.separateDialCode ? e.substring(1) : e;
return `+${n}${c}`;
}
_getCountryFromNumber(e) {
const n = e.indexOf("+");
let s = n ? e.substring(n) : e;
const o = this.selectedCountryData.iso2, a = this.selectedCountryData.dialCode;
s = this._ensureHasDialCode(s);
const c = this._getDialCode(s, !0), g = c1(s);
if (c) {
const f = c1(c), S = this.dialCodeToIso2Map[f];
if (!o && this.defaultCountry && S.includes(this.defaultCountry))
return this.defaultCountry;
const _ = o && S.includes(o) && (g.length === f.length || !this.selectedCountryData.areaCodes);
if (!(a === "1" && o2(g)) && !_) {
for (let w = 0; w < S.length; w++)
if (S[w])
return S[w];
}
} else {
if (s.charAt(0) === "+" && g.length)
return "";
if ((!s || s === "+") && !this.selectedCountryData.iso2)
return this.defaultCountry;
}
return null;
}
//* Remove highlighting from other list items and highlight the given item.
_highlightListItem(e, n) {
const s = this.highlightedItem;
if (s && (s.classList.remove("iti__highlight"), s.setAttribute("aria-selected", "false")), this.highlightedItem = e, this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true");
const o = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", o), this.options.countrySearch && this.searchInput.setAttribute("aria-activedescendant", o);
}
n && this.highlightedItem.focus();
}
//* Find the country data for the given iso2 code
//* the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
_getCountryData(e, n) {
for (let s = 0; s < this.countries.length; s++)
if (this.countries[s].iso2 === e)
return this.countries[s];
if (n)
return null;
throw new Error(`No country data for '${e}'`);
}
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
_setCountry(e) {
const { separateDialCode: n, showFlags: s, i18n: o } = this.options, a = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
if (this.selectedCountryData = e ? this._getCountryData(e, !1) || {} : {}, this.selectedCountryData.iso2 && (this.defaultCountry = this.selectedCountryData.iso2), this.selectedCountryInner) {
let c = "", g = "";
e && s ? (c = `iti__flag iti__${e}`, g = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`) : (c = "iti__flag iti__globe", g = o.noCountrySelected), this.selectedCountryInner.className = c, this.selectedCountryA11yText.textContent = g;
}
if (this._setSelectedCountryTitleAttribute(e, n), n) {
const c = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
this.selectedDialCode.innerHTML = c, this._updateInputPadding();
}
return this._updatePlaceholder(), this._updateMaxLength(), a.iso2 !== e;
}
//* Update the input padding to make space for the selected country/dial code.
_updateInputPadding() {
if (this.selectedCountry) {
const n = (this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth()) + 6;
this.showSelectedCountryOnLeft ? this.telInput.style.paddingLeft = `${n}px` : this.telInput.style.paddingRight = `${n}px`;
}
}
//* Update the maximum valid number length for the currently selected country.
_updateMaxLength() {
const { strictMode: e, placeholderNumberType: n, validationNumberTypes: s } = this.options, { iso2: o } = this.selectedCountryData;
if (e && C.utils)
if (o) {
const a = C.utils.numberType[n];
let c = C.utils.getExampleNumber(
o,
!1,
a,
!0
), g = c;
for (; C.utils.isPossibleNumber(c, o, s); )
g = c, c += "0";
const f = C.utils.getCoreNumber(g, o);
this.maxCoreNumberLength = f.length, o === "by" && (this.maxCoreNumberLength = f.length + 1);
} else
this.maxCoreNumberLength = null;
}
_setSelectedCountryTitleAttribute(e = null, n) {
if (!this.selectedCountry)
return;
let s;
e && !n ? s = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}` : e ? s = this.selectedCountryData.name : s = "Unknown", this.selectedCountry.setAttribute("title", s);
}
//* When the input is in a hidden container during initialisation, we must inject some markup
//* into the end of the DOM to calculate the correct offsetWidth.
//* NOTE: this is only used when separateDialCode is enabled, so countryContainer and selectedCountry
//* wil