intl-tel-input
Version:
A JavaScript plugin for entering and validating international telephone numbers
2,239 lines • 403 kB
JavaScript
import { mergeModels as $2, useModel as A2, ref as I1, onMounted as T2, watch as L2, onUnmounted as E2, withDirectives as D2, openBlock as M2, createElementBlock as P2, mergeProps as x2, vModelText as R2 } from "vue";
const n2 = [
[
"af",
// Afghanistan
"93"
],
[
"ax",
// Åland Islands
"358",
1,
["18"]
],
[
"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
],
[
"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"]
],
[
"cc",
// Cocos (Keeling) Islands
"61",
1,
["89162"]
],
[
"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"]
],
[
"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"]
],
[
"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"]
],
[
"jo",
// Jordan
"962"
],
[
"kz",
// Kazakhstan
"7",
1,
["33", "7"]
],
[
"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"]
],
[
"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
],
[
"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
],
[
"ro",
// Romania
"40"
],
[
"ru",
// Russia
"7",
0
],
[
"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
],
[
"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"]
],
[
"ye",
// Yemen
"967"
],
[
"zm",
// Zambia
"260"
],
[
"zw",
// Zimbabwe
"263"
]
], H = [];
for (let y = 0; y < n2.length; y++) {
const e = n2[y];
H[y] = {
name: "",
// this is now populated in the plugin
iso2: e[0],
dialCode: e[1],
priority: e[2] || 0,
areaCodes: e[3] || null,
nodeById: {}
};
}
const B2 = {
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"
}, k2 = {
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"
}, r2 = { ...B2, ...k2 };
for (let y = 0; y < H.length; y++)
H[y].name = r2[H[y].iso2];
let O2 = 0;
const o2 = {
//* 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: "",
//* 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,
//* Specify the path to the libphonenumber script to enable validation/formatting.
utilsScript: "",
//* The number type to enforce during validation.
validationNumberType: "MOBILE"
}, G2 = [
"800",
"822",
"833",
"844",
"855",
"866",
"877",
"880",
"881",
"882",
"883",
"884",
"885",
"886",
"887",
"888",
"889"
], c1 = (y) => y.replace(/\D/g, ""), i2 = (y = "") => y.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), s2 = (y) => {
const e = c1(y);
if (e.charAt(0) === "1") {
const n = e.substr(1, 3);
return G2.indexOf(n) !== -1;
}
return !1;
}, F2 = (y, e, n, i) => {
if (n === 0 && !i)
return 0;
let u = 0;
for (let a = 0; a < e.length; a++) {
if (/[+0-9]/.test(e[a]) && u++, u === y && !i)
return a + 1;
if (i && u === y + 1)
return a;
}
return e.length;
}, L = (y, e, n) => {
const i = document.createElement(y);
return e && Object.entries(e).forEach(([u, a]) => i.setAttribute(u, a)), n && n.appendChild(i), i;
}, $1 = (y) => {
const { instances: e } = C;
Object.values(e).forEach((n) => n[y]());
};
class U2 {
constructor(e, n = {}) {
this.id = O2++, this.telInput = e, this.highlightedItem = null, this.options = Object.assign({}, o2, 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 = { ...r2, ...this.options.i18n };
const n = new Promise((u, a) => {
this.resolveAutoCountryPromise = u, this.rejectAutoCountryPromise = a;
}), i = new Promise((u, a) => {
this.resolveUtilsScriptPromise = u, this.rejectUtilsScriptPromise = a;
});
this.promise = Promise.all([n, i]), 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: i } = this.options;
if (i) {
const u = i.indexOf(e.iso2), a = i.indexOf(n.iso2), c = u > -1, p = a > -1;
if (c || p)
return c && p ? u - a : c ? -1 : 1;
}
return e.name.localeCompare(n.name);
});
}
//* Add a dial code to this.dialCodeToIso2Map.
_addToDialCodeMap(e, n, i) {
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 u = i !== void 0 ? i : this.dialCodeToIso2Map[n].length;
this.dialCodeToIso2Map[n][u] = e;
}
//* Process onlyCountries or excludeCountries array if present.
_processAllCountries() {
const { onlyCountries: e, excludeCountries: n } = this.options;
if (e.length) {
const i = e.map(
(u) => u.toLowerCase()
);
this.countries = H.filter(
(u) => i.indexOf(u.iso2) > -1
);
} else if (n.length) {
const i = n.map(
(u) => u.toLowerCase()
);
this.countries = H.filter(
(u) => i.indexOf(u.iso2) === -1
);
} else
this.countries = H;
}
//* 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 i = this.dialCodeToIso2Map[n.dialCode][0];
for (let u = 0; u < n.areaCodes.length; u++) {
const a = n.areaCodes[u];
for (let c = 1; c < a.length; c++) {
const p = n.dialCode + a.substr(0, c);
this._addToDialCodeMap(i, p), this._addToDialCodeMap(n.iso2, p);
}
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;
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: i,
containerClass: u,
hiddenInput: a,
dropdownContainer: c,
fixDropdownWidth: p,
useFullscreenPopup: g,
countrySearch: b,
i18n: S
} = this.options;
let _ = "iti";
e && (_ += " iti--allow-dropdown"), i && (_ += " iti--show-flags"), u && (_ += ` ${u}`), g || (_ += " iti--inline-dropdown");
const N = L("div", { class: _ });
if ((I = this.telInput.parentNode) == null || I.insertBefore(N, this.telInput), e || i || n) {
this.countryContainer = L(
"div",
{ class: "iti__country-container" },
N
), this.showSelectedCountryOnLeft ? this.countryContainer.style.left = "0px" : this.countryContainer.style.right = "0px", e ? (this.selectedCountry = L(
"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 = L(
"div",
{ class: "iti__selected-country" },
this.countryContainer
);
const A = L("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
if (this.selectedCountryInner = L("div", { class: "iti__flag" }, A), this.selectedCountryA11yText = L(
"span",
{ class: "iti__a11y-text" },
this.selectedCountryInner
), e && (this.dropdownArrow = L(
"div",
{ class: "iti__arrow", "aria-hidden": "true" },
A
)), n && (this.selectedDialCode = L(
"div",
{ class: "iti__selected-dial-code" },
this.selectedCountry
)), e) {
const P = p ? "" : "iti--flexible-dropdown-width";
if (this.dropdownContent = L("div", {
id: `iti-${this.id}__dropdown-content`,
class: `iti__dropdown-content iti__hide ${P}`
}), b && (this.searchInput = L(
"input",
{
type: "text",
class: "iti__search-input",
placeholder: S.searchPlaceholder,
role: "combobox",
"aria-expanded": "true",
"aria-label": S.searchPlaceholder,
"aria-controls": `iti-${this.id}__country-listbox`,
"aria-autocomplete": "list",
autocomplete: "off"
},
this.dropdownContent
), this.searchResultsA11yText = L(
"span",
{ class: "iti__a11y-text" },
this.dropdownContent
)), this.countryList = L(
"ul",
{
class: "iti__country-list",
id: `iti-${this.id}__country-listbox`,
role: "listbox",
"aria-label": S.countryListAriaLabel
},
this.dropdownContent
), this._appendListItems(), b && this._updateSearchResultsText(), c) {
let O = "iti iti--container";
g ? O += " iti--fullscreen-popup" : O += " iti--inline-dropdown", this.dropdown = L("div", { class: O }), this.dropdown.appendChild(this.dropdownContent);
} else
this.countryContainer.appendChild(this.dropdownContent);
}
}
if (N.appendChild(this.telInput), this._updateInputPadding(), a) {
const A = this.telInput.getAttribute("name") || "", P = a(A);
P.phone && (this.hiddenInput = L("input", {
type: "hidden",
name: P.phone
}), N.appendChild(this.hiddenInput)), P.country && (this.hiddenInputCountry = L("input", {
type: "hidden",
name: P.country
}), N.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], i = e === 0 ? "iti__highlight" : "", u = L(
"li",
{
id: `iti-${this.id}__item-${n.iso2}`,
class: `iti__country ${i}`,
tabindex: "-1",
role: "option",
"data-dial-code": n.dialCode,
"data-country-code": n.iso2,
"aria-selected": "false"
},
this.countryList
);
n.nodeById[this.id] = u;
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>`, u.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"), i = this.telInput.value, a = n && n.charAt(0) === "+" && (!i || i.charAt(0) !== "+") ? n : i, c = this._getDialCode(a), p = s2(a), { initialCountry: g, geoIpLookup: b } = this.options, S = g === "auto" && b;
if (c && !p)
this._updateCountryFromNumber(a);
else if (!S || e) {
const _ = g ? g.toLowerCase() : "";
_ && this._getCountryData(_, !0) ? this._setCountry(_) : c && p ? 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() {
const { utilsScript: e, initialCountry: n, geoIpLookup: i } = this.options;
e && !C.utils ? C.documentReady() ? C.loadUtils(e) : window.addEventListener("load", () => {
C.loadUtils(e);
}) : this.resolveUtilsScriptPromise(), n === "auto" && i && !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: i, formatOnDisplay: u, allowDropdown: a, countrySearch: c } = this.options;
let p = !1;
new RegExp("\\p{L}", "u").test(this.telInput.value) && (p = !0), this._handleInputEvent = (g) => {
if (this.isAndroid && (g == null ? void 0 : g.data) === "+" && i && a && c) {
const N = this.telInput.selectionStart || 0, I = this.telInput.value.substring(0, N - 1), A = this.telInput.value.substring(N);
this.telInput.value = I + A, this._openDropdownWithPlus();
return;
}
this._updateCountryFromNumber(this.telInput.value) && this._triggerCountryChange();
const b = (g == null ? void 0 : g.data) && /[^+0-9]/.test(g.data), S = (g == null ? void 0 : g.inputType) === "insertFromPaste" && this.telInput.value;
b || S && !e ? p = !0 : /[^+0-9]/.test(this.telInput.value) || (p = !1);
const _ = (g == null ? void 0 : g.detail) && g.detail.isSetNumber && !u;
if (n && !p && !_) {
const N = this.telInput.selectionStart || 0, A = this.telInput.value.substring(0, N).replace(/[^+0-9]/g, "").length, P = (g == null ? void 0 : g.inputType) === "deleteContentForward", O = this._formatNumberAsYouType(), Z = F2(A, O, N, P);
this.telInput.value = O, this.telInput.setSelectionRange(Z, Z);
}
}, this.telInput.addEventListener("input", this._handleInputEvent), (e || i) && (this._handleKeydownEvent = (g) => {
if (g.key && g.key.length === 1 && !g.altKey && !g.ctrlKey && !g.metaKey) {
if (i && a && c && g.key === "+") {
g.preventDefault(), this._openDropdownWithPlus();
return;
}
if (e) {
const b = this.telInput.value, _ = !(b.charAt(0) === "+") && this.telInput.selectionStart === 0 && g.key === "+", N = /^[0-9]$/.test(g.key), I = i ? N : _ || N, A = this._getFullNumber(), P = C.utils.getCoreNumber(A, this.selectedCountryData.iso2), O = this.maxCoreNumberLength && P.length >= this.maxCoreNumberLength, Z = b.substring(this.telInput.selectionStart, this.telInput.selectionEnd), f1 = /\d/.test(Z), p1 = _ ? !0 : this._isChangingDialCode(g.key);
(!I || O && !f1 && !p1) && g.preventDefault();
}
}
}, this.telInput.addEventListener("keydown", this._handleKeydownEvent));
}
_isChangingDialCode(e) {
const n = this.telInput.value;
if (n.charAt(0) === "+") {
const i = this.selectedCountryData.iso2, u = n.slice(0, this.telInput.selectionStart) + e + n.slice(this.telInput.selectionEnd), a = this._getFullNumber(u);
return this._getCountryFromNumber(a) !== i;
}
return !1;
}
//* 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 i = new CustomEvent(e, {
bubbles: !0,
cancelable: !0,
detail: n
});
this.telInput.dispatchEvent(i);
}
//* 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 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(), 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 = (u) => {
var c;
const a = (c = u.target) == null ? void 0 : c.closest(".iti__country");
a && this._highlightListItem(a, !1);
}, this.countryList.addEventListener(
"mouseover",
this._handleMouseoverCountryList
), this._handleClickCountryList = (u) => {
var c;
const a = (c = u.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 = "", i = null;
if (this._handleKeydownOnDropdown = (u) => {
["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(u.key) && (u.preventDefault(), u.stopPropagation(), u.key === "ArrowUp" || u.key === "ArrowDown" ? this._handleUpDownKey(u.key) : u.key === "Enter" ? this._handleEnterKey() : u.key === "Escape" && this._closeDropdown()), !this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(u.key) && (u.stopPropagation(), i && clearTimeout(i), n += u.key.toLowerCase(), this._searchForCountry(n), i = setTimeout(() => {
n = "";
}, 1e3));
}, document.addEventListener("keydown", this._handleKeydownOnDropdown), this.options.countrySearch) {
const u = () => {
const c = this.searchInput.value.trim();
c ? this._filterCountries(c) : this._filterCountries("", !0);
};
let a = null;
this._handleSearchChange = () => {
a && clearTimeout(a), a = setTimeout(() => {
u(), 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 i = this.countries[n];
if (i.name.substr(0, e.length).toLowerCase() === e) {
const a = i.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 i = !0;
this.countryList.innerHTML = "";
const u = i2(e);
for (let a = 0; a < this.countries.length; a++) {
const c = this.countries[a], p = i2(c.name), g = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((S) => S[0]).join("").toLowerCase(), b = `+${c.dialCode}`;
if (n || p.includes(u) || b.includes(u) || c.iso2.includes(u) || g.includes(u)) {
const S = c.nodeById[this.id];
S && this.countryList.appendChild(S), i && (this._highlightListItem(S, !1), i = !1);
}
}
i && 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 i;
n === 0 ? i = e.zeroSearchResults : n === 1 ? i = e.oneSearchResult : i = e.multipleSearchResults.replace("${count}", n.toString()), this.searchResultsA11yText.textContent = i;
}
//* Highlight the next/prev item in the list (and ensure it is visible).
_handleUpDownKey(e) {
var i, u;
let n = e === "ArrowUp" ? (i = this.highlightedItem) == null ? void 0 : i.previousElementSibling : (u = this.highlightedItem) == null ? void 0 : u.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 i = this.options.nationalMode || n.charAt(0) !== "+" && !this.options.separateDialCode, { NATIONAL: u, INTERNATIONAL: a } = C.utils.numberFormat, c = i ? u : 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;
}
_getCountryFromNumber(e) {
const n = e.indexOf("+");
let i = n ? e.substring(n) : e;
const u = this.selectedCountryData.dialCode;
i && u === "1" && i.charAt(0) !== "+" && (i.charAt(0) !== "1" && (i = `1${i}`), i = `+${i}`), this.options.separateDialCode && u && i.charAt(0) !== "+" && (i = `+${u}${i}`);
const c = this._getDialCode(i, !0), p = c1(i);
if (c) {
const g = this.dialCodeToIso2Map[c1(c)], b = g.indexOf(this.selectedCountryData.iso2) !== -1 && p.length <= c.length - 1;
if (!(u === "1" && s2(p)) && !b) {
for (let _ = 0; _ < g.length; _++)
if (g[_])
return g[_];
}
} else {
if (i.charAt(0) === "+" && p.length)
return "";
if ((!i || i === "+") && !this.selectedCountryData.iso2)
return this.defaultCountry;
}
return null;
}
//* Remove highlighting from other list items and highlight the given item.
_highlightListItem(e, n) {
const i = this.highlightedItem;
if (i && (i.classList.remove("iti__highlight"), i.setAttribute("aria-selected", "false")), this.highlightedItem = e, this.highlightedItem) {
this.highlightedItem.classList.add("iti__highlight"), this.highlightedItem.setAttribute("aria-selected", "true");
const u = this.highlightedItem.getAttribute("id") || "";
this.selectedCountry.setAttribute("aria-activedescendant", u), this.options.countrySearch && this.searchInput.setAttribute("aria-activedescendant", u);
}
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 i = 0; i < this.countries.length; i++)
if (this.countries[i].iso2 === e)
return this.countries[i];
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: i, i18n: u } = 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 = "", p = "";
e && i ? (c = `iti__flag iti__${e}`, p = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`) : (c = "iti__flag iti__globe", p = u.noCountrySelected), this.selectedCountryInner.className = c, this.selectedCountryA11yText.textContent = p;
}
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, validationNumberType: i } = this.options;
if (e && C.utils)
if (this.selectedCountryData.iso2) {
const u = C.utils.numberType[n];
let a = C.utils.getExampleNumber(
this.selectedCountryData.iso2,
!1,
u,
!0
), c = a;
for (; C.utils.isPossibleNumber(a, this.selectedCountryData.iso2, i); )
c = a, a += "0";
const p = C.utils.getCoreNumber(c, this.selectedCountryData.iso2);
this.maxCoreNumberLength = p.length;
} else
this.maxCoreNumberLength = null;
}
_setSelectedCountryTitleAttribute(e = null, n) {
if (!this.selectedCountry)
return;
let i;
e && !n ? i = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}` : e ? i = this.selectedCountryData.name : i = "Unknown", this.selectedCountry.setAttribute("title", i);
}
//* 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
//* will definitely exist.
_getHiddenSelectedCountryWidth() {
if (this.telInput.parentNode) {
const e = this.telInput.parentNode.cloneNode(!1);
e.style.visibility = "hidden", document.body.appendChild(e);
const n = this.countryContainer.cloneNode();
e.appendChild(n);
const i = this.selectedCountry.cloneNode(!0);
n.appendChild(i);
const u = i.offsetWidth;
return document.body.removeChild(e), u;
}
return 0;
}
//* Update the input placeholder to an example number from the currently selected country.
_updatePlaceholder() {
const {
autoPlaceholder: e,
placeholderNumberType: n,
nationalMode: i,
customPlaceholder: u
} = this.options, a