intl-tel-input
Version:
A JavaScript plugin for entering and validating international telephone numbers
3,439 lines • 85.7 kB
JavaScript
var pe = (r) => {
throw TypeError(r);
};
var Vt = (r, t, s) => t.has(r) || pe("Cannot " + s);
var e = (r, t, s) => (Vt(r, t, "read from private field"), s ? s.call(r) : t.get(r)), I = (r, t, s) => t.has(r) ? pe("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, s), p = (r, t, s, i) => (Vt(r, t, "write to private field"), i ? i.call(r, s) : t.set(r, s), s), a = (r, t, s) => (Vt(r, t, "access private method"), s);
const ps = [
[
"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"
]
], Ct = [];
for (const r of ps)
Ct.push({
name: "",
// populated in the plugin
iso2: r[0],
dialCode: r[1],
priority: r[2] || 0,
areaCodes: r[3] || null,
nodeById: {},
// populated by the plugin
nationalPrefix: r[4] || null,
normalisedName: "",
// populated in the plugin
initials: "",
// populated in the plugin
dialCodePlus: ""
// populated in the plugin
});
const fs = new Set(Ct.map((r) => r.iso2)), At = (r) => fs.has(r), Ht = {
OPEN_COUNTRY_DROPDOWN: "open:countrydropdown",
CLOSE_COUNTRY_DROPDOWN: "close:countrydropdown",
COUNTRY_CHANGE: "countrychange",
INPUT: "input"
// used for synthetic input trigger
}, b = {
HIDE: "iti__hide",
V_HIDE: "iti__v-hide",
ARROW_UP: "iti__arrow--up",
GLOBE: "iti__globe",
FLAG: "iti__flag",
LOADING: "iti__loading",
COUNTRY_ITEM: "iti__country",
HIGHLIGHT: "iti__highlight"
}, S = {
ARROW_UP: "ArrowUp",
ARROW_DOWN: "ArrowDown",
SPACE: " ",
ENTER: "Enter",
ESC: "Escape",
TAB: "Tab"
}, fe = {
PASTE: "insertFromPaste",
DELETE_FWD: "deleteContentForward"
}, Z = {
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
}, De = {
SEARCH_DEBOUNCE_MS: 100,
HIDDEN_SEARCH_RESET_MS: 1e3
}, Ce = {
UNKNOWN_NUMBER_TYPE: -99,
UNKNOWN_VALIDATION_ERROR: -99
}, q = {
NARROW_VIEWPORT_WIDTH: 500,
// keep in sync with .iti__country-list CSS media query
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
DROPDOWN_MARGIN: 3,
// px margin between dropdown and tel input
SANE_DROPDOWN_HEIGHT: 200
// px height fallback for dropdown
}, Le = {
NANP: "1"
// North American Numbering Plan
}, jt = {
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
}, Cs = {
ISO2: "us"
}, $t = {
AGGRESSIVE: "aggressive",
POLITE: "polite",
OFF: "off"
}, bt = {
AUTO: "auto"
}, ys = [
"FIXED_LINE",
"MOBILE",
"FIXED_LINE_OR_MOBILE",
"TOLL_FREE",
"PREMIUM_RATE",
"SHARED_COST",
"VOIP",
"PERSONAL_NUMBER",
"PAGER",
"UAN",
"VOICEMAIL",
"UNKNOWN"
], Mt = new Set(ys), ye = {
COUNTRY_CODE: "countryCode",
DIAL_CODE: "dialCode"
}, N = {
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"
}, ms = {
selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})",
noCountrySelected: "Select country",
countryListAriaLabel: "List of countries",
searchPlaceholder: "Search",
clearSearchAriaLabel: "Clear search",
searchEmptyState: "No results found",
searchSummaryAria(r) {
return r === 0 ? "No results found" : r === 1 ? "1 result found" : `${r} results found`;
}
}, Kt = (r) => typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia(r).matches, Ae = () => Kt(`(max-width: ${q.NARROW_VIEWPORT_WIDTH}px)`), gs = () => {
if (typeof navigator < "u" && typeof window < "u") {
const r = Kt("(max-height: 600px)"), t = Kt("(pointer: coarse)");
return Ae() || t && r;
}
return !1;
}, ce = {
//* Whether or not to allow the dropdown.
allowDropdown: !0,
//* The number type to enforce during validation.
allowedNumberTypes: ["MOBILE", "FIXED_LINE"],
//* Whether or not to allow extensions after the main number.
allowNumberExtensions: !1,
// Allow alphanumeric "phonewords" (e.g. +1 800 FLOWERS) as valid numbers
allowPhonewords: !1,
//* Add a placeholder in the input with an example number for the selected country.
autoPlaceholder: $t.POLITE,
//* Add a custom class to the (injected) container element.
containerClass: "",
//* Locale for localising country names via Intl.DisplayNames.
countryNameLocale: "en",
//* 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,
//* Always show the dropdown
dropdownAlwaysOpen: !1,
//* 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",
//* Add custom classes to the search input element.
searchInputClass: "",
//* Display the international dial code next to the selected flag.
separateDialCode: !1,
//* Show flags - for both the selected country, and in the country dropdown
showFlags: !0,
//* 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: gs()
}, _e = (r) => JSON.stringify(r), me = (r) => !!r && typeof r == "object" && !Array.isArray(r), Is = (r) => typeof r == "function", Es = (r) => {
if (!r || typeof r != "object") return !1;
const t = r;
return t.nodeType === 1 && typeof t.tagName == "string" && typeof t.appendChild == "function";
}, ge = new Set(Object.values($t)), Ft = (r) => {
console.warn(`[intl-tel-input] ${r}`);
}, x = (r, t, s) => {
Ft(`Option '${r}' must be ${t}; got ${_e(s)}. Ignoring.`);
}, bs = (r, t) => Object.prototype.hasOwnProperty.call(r, t), Ie = (r, t) => {
const s = "an array of ISO2 country code strings";
if (!Array.isArray(t))
return x(r, s, t), !1;
const i = [];
for (const n of t) {
if (typeof n != "string")
return x(r, s, t), !1;
const l = n.toLowerCase();
At(l) ? i.push(n) : Ft(`Invalid country code in '${r}': '${n}'. Skipping.`);
}
return i;
}, Ns = (r) => {
if (r === void 0)
return {};
if (!me(r)) {
const s = `The second argument must be an options object; got ${_e(r)}. Using defaults.`;
return Ft(s), {};
}
const t = {};
for (const [s, i] of Object.entries(r)) {
if (!bs(ce, s)) {
Ft(`Unknown option '${s}'. Ignoring.`);
continue;
}
switch (s) {
case "allowDropdown":
case "allowNumberExtensions":
case "allowPhonewords":
case "countrySearch":
case "dropdownAlwaysOpen":
case "fixDropdownWidth":
case "formatAsYouType":
case "formatOnDisplay":
case "nationalMode":
case "showFlags":
case "separateDialCode":
case "strictMode":
case "useFullscreenPopup":
if (typeof i != "boolean") {
x(s, "a boolean", i);
break;
}
t[s] = i;
break;
case "autoPlaceholder":
if (typeof i != "string" || !ge.has(i)) {
const n = Array.from(ge).join(", ");
x("autoPlaceholder", `one of ${n}`, i);
break;
}
t[s] = i;
break;
case "containerClass":
case "searchInputClass":
case "countryNameLocale":
if (typeof i != "string") {
x(s, "a string", i);
break;
}
t[s] = i;
break;
case "countryOrder": {
if (i === null)
t[s] = i;
else {
const n = Ie(s, i);
n !== !1 && (t[s] = n);
}
break;
}
case "customPlaceholder":
case "geoIpLookup":
case "hiddenInput":
case "loadUtils":
if (i !== null && !Is(i)) {
x(s, "a function or null", i);
break;
}
t[s] = i;
break;
case "dropdownContainer":
if (i !== null && !Es(i)) {
x("dropdownContainer", "an HTMLElement or null", i);
break;
}
t[s] = i;
break;
case "excludeCountries":
case "onlyCountries": {
const n = Ie(s, i);
n !== !1 && (t[s] = n);
break;
}
case "i18n":
if (i && !me(i)) {
x("i18n", "an object", i);
break;
}
t[s] = i;
break;
case "initialCountry": {
if (typeof i != "string") {
x("initialCountry", "a string", i);
break;
}
const n = i.toLowerCase();
if (n && n !== bt.AUTO && !At(n)) {
x("initialCountry", "a valid ISO2 country code or 'auto'", i);
break;
}
t[s] = i;
break;
}
case "placeholderNumberType":
if (typeof i != "string" || !Mt.has(i)) {
const n = Array.from(Mt).join(", ");
x("placeholderNumberType", `one of ${n}`, i);
break;
}
t[s] = i;
break;
case "allowedNumberTypes":
if (i !== null) {
if (!Array.isArray(i)) {
x("allowedNumberTypes", "an array of number types or null", i);
break;
}
let n = !0;
for (const l of i)
if (typeof l != "string" || !Mt.has(l)) {
const u = Array.from(Mt).join(", ");
x("allowedNumberTypes", `an array of valid number types (${u})`, l), n = !1;
break;
}
n && (t[s] = i);
} else
t[s] = null;
break;
}
}
return t;
}, ws = (r) => {
var t, s;
r.initialCountry && (r.initialCountry = r.initialCountry.toLowerCase()), (t = r.onlyCountries) != null && t.length && (r.onlyCountries = r.onlyCountries.map((i) => i.toLowerCase())), (s = r.excludeCountries) != null && s.length && (r.excludeCountries = r.excludeCountries.map((i) => i.toLowerCase())), r.countryOrder && (r.countryOrder = r.countryOrder.map((i) => i.toLowerCase()));
}, Ds = (r) => {
r.dropdownAlwaysOpen && (r.useFullscreenPopup = !1, r.allowDropdown = !0), r.useFullscreenPopup ? r.fixDropdownWidth = !1 : Ae() && (r.fixDropdownWidth = !0), r.onlyCountries.length === 1 && (r.initialCountry = r.onlyCountries[0]), r.separateDialCode && (r.nationalMode = !1), r.allowDropdown && !r.showFlags && !r.separateDialCode && (r.nationalMode = !1), r.useFullscreenPopup && !r.dropdownContainer && (r.dropdownContainer = document.body), r.i18n = { ...ms, ...r.i18n };
}, pt = (r) => r.replace(/\D/g, ""), de = (r = "") => r.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase(), Ls = () => typeof navigator < "u" ? /Android/i.test(navigator.userAgent) : !1, As = (r, t) => {
const s = de(t), i = [], n = [], l = [], u = [], h = [], d = [];
for (const m of r)
m.iso2 === s ? i.push(m) : m.normalisedName.startsWith(s) ? n.push(m) : m.normalisedName.includes(s) ? l.push(m) : s === m.dialCode || s === m.dialCodePlus ? u.push(m) : m.dialCodePlus.includes(s) ? h.push(m) : m.initials.includes(s) && d.push(m);
const C = (m, A) => m.priority - A.priority;
return [
...i,
...n,
...l,
// priority sort is only relevant when showing multiple countries with the same dial code (that's what the priority field is used to distinguish between)
...u.sort(C),
...h.sort(C),
...d
];
}, _s = (r, t) => {
const s = de(t);
for (const i of r)
if (i.normalisedName.startsWith(s))
return i;
return null;
}, Yt = (r) => Object.keys(r).filter((t) => !!r[t]).join(" "), D = (r, t, s) => {
const i = document.createElement(r);
return t && Object.entries(t).forEach(
([n, l]) => i.setAttribute(n, l)
), s && s.appendChild(i), i;
}, Os = () => `
<svg class="iti__search-icon-svg" width="14" height="14" viewBox="0 0 24 24" focusable="false" ${N.HIDDEN}="true">
<circle cx="11" cy="11" r="7" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</svg>`, Ts = (r) => {
const t = `iti-${r}-clear-mask`;
return `
<svg class="iti__search-clear-svg" width="12" height="12" viewBox="0 0 16 16" ${N.HIDDEN}="true" focusable="false">
<mask id="${t}" 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(#${t})" />
</svg>`;
}, Ps = () => `
<svg class="iti__country-check-svg" width="14" height="14" viewBox="0 0 16 16" fill="currentColor" focusable="false" ${N.HIDDEN}="true">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
</svg>`, Ee = () => `
<svg width="256" height="256" viewBox="0 0 512 512" class="iti__globe-svg">
<path d="M508 213a240 240 0 0 0-449-87l-2 5-2 5c-8 14-13 30-17 46a65 65 0 0 1 56 4c16-10 35-19 56-27l9-3c-6 23-10 48-10 74h-16l4 6c3 4 5 8 6 13h6c0 22 3 44 8 65l2 10-25-10-4 5 12 18 9 3 6 2 8 3 9 26 1 2 16-7h1l-5-13-1-2c24 6 49 9 75 10v26l11 10 7 7v-30l1-13c22 0 44-3 65-8l10-2-21 48-1 1a317 317 0 0 1-14 23l-21 5h-2c6 16 7 33 1 50a240 240 0 0 0 211-265m-401-56-11 6c19-44 54-79 98-98-11 20-21 44-29 69-21 6-40 15-58 23m154 182v4c-29-1-57-6-81-13-7-25-12-52-13-81h94zm0-109h-94c1-29 6-56 13-81 24-7 52-12 81-13zm0-112c-22 1-44 4-65 8l-10 2 12-30 9-17 1-2a332 332 0 0 1 13-23c13-4 26-6 40-7zm187 69 6 4c4 12 6 25 6 38v1h-68c-1-26-4-51-10-74l48 20 1 1 14 8zm-14-44 10 20c-20-11-43-21-68-29-8-25-18-49-29-69 37 16 67 44 87 78M279 49h1c13 1 27 3 39 7l14 23 1 2a343 343 0 0 1 12 26l2 5 6 16c-23-6-48-9-74-10h-1zm0 87h1c29 1 56 6 81 13 7 24 12 51 12 80v1h-94zm2 207h-2v-94h95c-1 29-6 56-13 81-24 7-51 12-80 13m86 60-20 10c11-20 21-43 29-68 25-8 48-18 68-29-16 37-43 67-77 87m87-115-7 5-16 9-2 1a337 337 0 0 1-47 21c6-24 9-49 10-75h68c0 13-2 27-6 39"/>
<path d="m261 428-2-2-22-21a40 40 0 0 0-32-11h-1a37 37 0 0 0-18 8l-1 1-4 2-2 2-5 4c-9-3-36-31-47-44s-32-45-34-55l3-2a151 151 0 0 0 11-9v-1a39 39 0 0 0 5-48l-3-3-11-19-3-4-5-7h-1l-3-3-4-3-5-2a35 35 0 0 0-16-3h-5c-4 1-14 5-24 11l-4 2-4 3-4 2c-9 8-17 17-18 27a380 380 0 0 0 212 259h3c12 0 25-10 36-21l10-12 6-11a39 39 0 0 0-8-40"/>
</svg>`;
var L, R, rt, Tt, z, et, at, yt, ut, w, mt, X, gt, _, W, g, Oe, Te, zt, Pe, Se, ve, Re, ke, Xt, Pt, qt, Ue, xe, Qt, Jt, He, Me, Zt, We;
const _t = class _t {
constructor(t, s, i) {
I(this, g);
// private
I(this, L);
I(this, R);
I(this, rt);
I(this, Tt);
I(this, z);
I(this, et);
I(this, at);
I(this, yt);
I(this, ut);
I(this, w);
I(this, mt);
I(this, X);
I(this, gt);
I(this, _);
I(this, W);
p(this, et, null), p(this, at, null), p(this, _, null), p(this, W, null), this.highlightedItem = null, t.dataset.intlTelInputId = i.toString(), this.telInput = t, p(this, L, s), p(this, R, i), this.hadInitialPlaceholder = !!t.getAttribute("placeholder"), p(this, rt, !!this.telInput.closest("[dir=rtl]")), e(this, L).separateDialCode && p(this, Tt, this.telInput.style.paddingLeft);
}
// Validate that the provided element is an HTMLInputElement.
static validateInput(t) {
const s = t == null ? void 0 : t.tagName;
if (!(!!t && typeof t == "object" && s === "INPUT" && typeof t.setAttribute == "function")) {
const n = Object.prototype.toString.call(t);
throw new TypeError(
`The first argument must be an HTMLInputElement, not ${n}`
);
}
}
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
generateMarkup(t) {
p(this, z, t), this.telInput.classList.add("iti__tel-input"), this.telInput.hasAttribute("autocomplete") || this.telInput.setAttribute("autocomplete", "tel"), this.telInput.hasAttribute("inputmode") || this.telInput.setAttribute("inputmode", "tel");
const s = a(this, g, Oe).call(this);
a(this, g, Te).call(this, s), s.appendChild(this.telInput), a(this, g, ve).call(this), a(this, g, Re).call(this, s);
}
//* Country search: Filter the countries according to the search query.
filterCountriesByQuery(t) {
let s;
t === "" ? s = e(this, z) : s = As(e(this, z), t), a(this, g, Me).call(this, s);
}
handleSearchChange() {
e(this, et) && clearTimeout(e(this, et)), p(this, et, setTimeout(() => {
a(this, g, Jt).call(this), p(this, et, null);
}, De.SEARCH_DEBOUNCE_MS));
}
handleSearchClear() {
this.searchInput.value = "", this.searchInput.focus(), a(this, g, Jt).call(this);
}
//* Check if a country list item element is visible within it's container (the country list), else scroll until it is.
scrollCountryListToItem(t) {
const s = this.countryList, i = s.getBoundingClientRect(), n = t.getBoundingClientRect(), l = n.top - i.top + s.scrollTop;
n.top < i.top ? s.scrollTop = l : n.bottom > i.bottom && (s.scrollTop = l - i.height + n.height);
}
//* Remove highlighting from the previous list item and highlight the new one.
highlightListItem(t, s) {
const i = this.highlightedItem;
if (i && i.classList.remove(b.HIGHLIGHT), this.highlightedItem = t, this.highlightedItem) {
if (this.highlightedItem.classList.add(b.HIGHLIGHT), e(this, L).countrySearch) {
const n = this.highlightedItem.getAttribute("id") || "";
this.searchInput.setAttribute(N.ACTIVE_DESCENDANT, n);
}
s && this.highlightedItem.focus();
}
}
//* Highlight the next/prev item in the list (and ensure it is visible).
handleUpDownKey(t) {
var i, n;
let s = t === S.ARROW_UP ? (i = this.highlightedItem) == null ? void 0 : i.previousElementSibling : (n = this.highlightedItem) == null ? void 0 : n.nextElementSibling;
!s && this.countryList.childElementCount > 1 && (s = t === S.ARROW_UP ? this.countryList.lastElementChild : this.countryList.firstElementChild), s && (this.scrollCountryListToItem(s), this.highlightListItem(s, !1));
}
destroy() {
this.telInput.iti = void 0, delete this.telInput.dataset.intlTelInputId, e(this, L).separateDialCode && (this.telInput.style.paddingLeft = e(this, Tt));
const t = this.telInput.parentNode;
t.before(this.telInput), t.remove(), this.telInput = null, this.countryContainer = null, this.selectedCountry = null, this.selectedCountryInner = null, this.searchInput = null, this.searchClearButton = null, this.countryList = null, this.hiddenInput = null, this.hiddenInputCountry = null, this.highlightedItem = null, p(this, yt, null), p(this, ut, null), p(this, w, null), p(this, mt, null), p(this, X, null), p(this, gt, null), p(this, _, null), p(this, W, null);
for (const s of e(this, z))
delete s.nodeById[e(this, R)];
p(this, z, null);
}
// UI: Open the dropdown (DOM only).
openDropdown() {
const {
countrySearch: t,
dropdownAlwaysOpen: s,
dropdownContainer: i
} = e(this, L);
if (a(this, g, zt).call(this), i)
a(this, g, We).call(this);
else {
const n = a(this, g, Zt).call(this), l = this.telInput.offsetHeight + q.DROPDOWN_MARGIN;
n ? e(this, w).style.top = `${l}px` : e(this, w).style.bottom = `${l}px`;
}
if (e(this, w).classList.remove(b.HIDE), this.selectedCountry.setAttribute(N.EXPANDED, "true"), t) {
const n = this.countryList.firstElementChild;
n && (this.highlightListItem(n, !1), this.countryList.scrollTop = 0), s || this.searchInput.focus();
}
e(this, ut).classList.add(b.ARROW_UP);
}
// UI: Close the dropdown (DOM only).
closeDropdown() {
const { countrySearch: t, dropdownContainer: s } = e(this, L);
e(this, w).classList.add(b.HIDE), this.selectedCountry.setAttribute(N.EXPANDED, "false"), t && (this.searchInput.removeAttribute(N.ACTIVE_DESCENDANT), this.highlightedItem && (this.highlightedItem.classList.remove(b.HIGHLIGHT), this.highlightedItem = null)), e(this, ut).classList.remove(b.ARROW_UP), s ? (e(this, _).remove(), e(this, _).style.top = "", e(this, _).style.bottom = "", e(this, _).style.paddingLeft = "", e(this, _).style.paddingRight = "") : (e(this, w).style.top = "", e(this, w).style.bottom = "");
}
// UI: Whether the dropdown is currently closed (hidden).
isDropdownClosed() {
return e(this, w).classList.contains(b.HIDE);
}
setCountry(t) {
const { allowDropdown: s, showFlags: i, separateDialCode: n, i18n: l } = e(this, L), { name: u, dialCode: h, iso2: d = "" } = t;
if (s && a(this, g, He).call(this, d), this.selectedCountry) {
const C = d && i ? `${b.FLAG} iti__${d}` : `${b.FLAG} ${b.GLOBE}`;
let m, A, O;
d ? (A = u, m = l.selectedCountryAriaLabel.replace("${countryName}", u).replace("${dialCode}", `+${h}`), O = i ? "" : Ee()) : (A = l.noCountrySelected, m = l.noCountrySelected, O = Ee()), this.selectedCountryInner.className = C, this.selectedCountry.setAttribute("title", A), this.selectedCountry.setAttribute(N.LABEL, m), this.selectedCountryInner.innerHTML = O;
}
if (n) {
const C = h ? `+${h}` : "";
e(this, yt).textContent = C, a(this, g, Xt).call(this);
}
}
};
L = new WeakMap(), R = new WeakMap(), rt = new WeakMap(), Tt = new WeakMap(), z = new WeakMap(), et = new WeakMap(), at = new WeakMap(), yt = new WeakMap(), ut = new WeakMap(), w = new WeakMap(), mt = new WeakMap(), X = new WeakMap(), gt = new WeakMap(), _ = new WeakMap(), W = new WeakMap(), g = new WeakSet(), Oe = function() {
const {
allowDropdown: t,
showFlags: s,
containerClass: i,
useFullscreenPopup: n
} = e(this, L), l = Yt({
iti: !0,
"iti--allow-dropdown": t,
"iti--show-flags": s,
"iti--inline-dropdown": !n,
[i]: !!i
}), u = D("div", { class: l });
return e(this, rt) && u.setAttribute("dir", "ltr"), this.telInput.before(u), u;
}, Te = function(t) {
const { allowDropdown: s, separateDialCode: i, showFlags: n } = e(this, L);
if (s || n || i) {
this.countryContainer = D(
"div",
// visibly hidden until we measure it's width to set the input padding correctly
{ class: `iti__country-container ${b.V_HIDE}` },
t
), s ? (this.selectedCountry = D(
"button",
{
type: "button",
class: "iti__selected-country",
[N.EXPANDED]: "false",
[N.LABEL]: e(this, L).i18n.noCountrySelected,
[N.HASPOPUP]: "dialog",
[N.CONTROLS]: `iti-${e(this, R)}__dropdown-content`
},
this.countryContainer
), this.telInput.disabled && this.selectedCountry.setAttribute("disabled", "true")) : this.selectedCountry = D(
"div",
{ class: "iti__selected-country" },
this.countryContainer
);
const l = D(
"div",
{ class: "iti__selected-country-primary" },
this.selectedCountry
);
this.selectedCountryInner = D(
"div",
{ class: b.FLAG },
l
), s && p(this, ut, D(
"div",
{ class: "iti__arrow", [N.HIDDEN]: "true" },
l
)), i && p(this, yt, D(
"div",
{ class: "iti__selected-dial-code" },
this.selectedCountry
)), s && a(this, g, Pe).call(this);
}
}, zt = function() {
const { fixDropdownWidth: t } = e(this, L);
if (t && !e(this, w).style.width) {
const s = this.telInput.offsetWidth;
s > 0 && (e(this, w).style.width = `${s}px`);
}
}, Pe = function() {
const {
fixDropdownWidth: t,
useFullscreenPopup: s,
countrySearch: i,
i18n: n,
dropdownContainer: l,
containerClass: u
} = e(this, L), h = t ? "" : "iti--flexible-dropdown-width";
if (p(this, w, D("div", {
id: `iti-${e(this, R)}__dropdown-content`,
class: `iti__dropdown-content ${b.HIDE} ${h}`,
role: "dialog",
[N.MODAL]: "true"
})), e(this, rt) && e(this, w).setAttribute("dir", "rtl"), i && a(this, g, Se).call(this), this.countryList = D(
"ul",
{
class: "iti__country-list",
id: `iti-${e(this, R)}__country-listbox`,
role: "listbox",
[N.LABEL]: n.countryListAriaLabel
},
e(this, w)
), a(this, g, ke).call(this), i && a(this, g, Qt).call(this), s || (a(this, g, zt).call(this), p(this, at, a(this, g, xe).call(this)), i && (e(this, w).style.height = `${e(this, at)}px`)), l) {
const d = Yt({
iti: !0,
"iti--container": !0,
"iti--fullscreen-popup": s,
"iti--inline-dropdown": !s,
[u]: !!u
});
p(this, _, D("div", { class: d })), e(this, _).appendChild(e(this, w));
} else
this.countryContainer.appendChild(e(this, w));
}, Se = function() {
const { i18n: t, searchInputClass: s } = e(this, L), i = D(
"div",
{ class: "iti__search-input-wrapper" },
e(this, w)
);
p(this, mt, D(
"span",
{
class: "iti__search-icon",
[N.HIDDEN]: "true"
},
i
)), e(this, mt).innerHTML = Os(), this.searchInput = D(
"input",
{
id: `iti-${e(this, R)}__search-input`,
// Chrome says inputs need either a name or an id
type: "search",
class: `iti__search-input ${s}`,
placeholder: t.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",
[N.EXPANDED]: "true",
[N.LABEL]: t.searchPlaceholder,
[N.CONTROLS]: `iti-${e(this, R)}__country-listbox`,
[N.AUTOCOMPLETE]: "list",
autocomplete: "off"
},
i
), this.searchClearButton = D(
"button",
{
type: "button",
class: `iti__search-clear ${b.HIDE}`,
[N.LABEL]: t.clearSearchAriaLabel,
tabindex: "-1"
},
i
), this.searchClearButton.innerHTML = Ts(e(this, R)), p(this, gt, D(
"span",
{ class: "iti__a11y-text" },
e(this, w)
)), p(this, X, D(
"div",
{
class: `iti__no-results ${b.HIDE}`,
[N.HIDDEN]: "true"
// all a11y messaging happens in this.#searchResultsA11yText
},
e(this, w)
)), e(this, X).textContent = t.searchEmptyState;
}, ve = function() {
this.countryContainer && (a(this, g, Xt).call(this), this.countryContainer.classList.remove(b.V_HIDE));
}, Re = function(t) {
var i, n;
const { hiddenInput: s } = e(this, L);
if (s) {
const l = this.telInput.getAttribute("name") || "", u = s(l);
if (u.phone) {
const h = (i = this.telInput.form) == null ? void 0 : i.querySelector(
`input[name="${u.phone}"]`
);
h ? this.hiddenInput = h : (this.hiddenInput = D("input", {
type: "hidden",
name: u.phone
}), t.appendChild(this.hiddenInput));
}
if (u.country) {
const h = (n = this.telInput.form) == null ? void 0 : n.querySelector(
`input[name="${u.country}"]`
);
h ? this.hiddenInputCountry = h : (this.hiddenInputCountry = D("input", {
type: "hidden",
name: u.country
}), t.appendChild(this.hiddenInputCountry));
}
}
}, //* For each country: add a country list item <li> to the countryList <ul> container.
ke = function() {
const t = document.createDocumentFragment();
for (let s = 0; s < e(this, z).length; s++) {
const i = e(this, z)[s], n = Yt({
[b.COUNTRY_ITEM]: !0
}), l = D("li", {
id: `iti-${e(this, R)}__item-${i.iso2}`,
class: n,
tabindex: "-1",
role: "option",
[N.SELECTED]: "false"
});
l.dataset.dialCode = i.dialCode, l.dataset.countryCode = i.iso2, i.nodeById[e(this, R)] = l, e(this, L).showFlags && D("div", { class: `${b.FLAG} iti__${i.iso2}` }, l);
const u = D("span", { class: "iti__country-name" }, l);
u.textContent = `${i.name} `;
const h = D("span", { class: "iti__dial-code" }, u);
e(this, rt) && h.setAttribute("dir", "ltr"), h.textContent = `(+${i.dialCode})`, t.appendChild(l);
}
this.countryList.appendChild(t);
}, //* Update the input padding to make space for the selected country/dial code.
Xt = function() {
if (this.selectedCountry) {
const t = e(this, L).separateDialCode ? q.SANE_SELECTED_WITH_DIAL_WIDTH : q.SANE_SELECTED_NO_DIAL_WIDTH, i = (this.selectedCountry.offsetWidth || a(this, g, Ue).call(this) || t) + q.INPUT_PADDING_EXTRA_LEFT;
this.telInput.style.paddingLeft = `${i}px`;
}
}, Pt = new WeakSet(), qt = function() {
let t;
try {
t = window.top.document.body;
} catch {
t = document.body;
}
return t;
}, //* 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.
Ue = function() {
var t;
if (this.telInput.parentNode) {
const s = a(t = _t, Pt, qt).call(t), i = this.telInput.parentNode.cloneNode(
!1
);
i.style.visibility = "hidden", s.appendChild(i);
const n = this.countryContainer.cloneNode();
i.appendChild(n);
const l = this.selectedCountry.cloneNode(
!0
);
n.appendChild(l);
const u = l.offsetWidth;
return s.removeChild(i), u;
}
return 0;
}, // this is run before we add the dropdown to the DOM
xe = function() {
var n;
const t = a(n = _t, Pt, qt).call(n);
e(this, w).classList.remove(b.HIDE);
const s = D("div", { class: "iti iti--inline-dropdown" });
s.appendChild(e(this, w)), s.style.visibility = "hidden", t.appendChild(s);
const i = e(this, w).offsetHeight;
return t.removeChild(s), s.style.visibility = "", e(this, w).classList.add(b.HIDE), i > 0 ? i : q.SANE_DROPDOWN_HEIGHT;
}, //* Update search results text (for a11y).
Qt = function() {
const { i18n: t } = e(this, L), s = this.countryList.childElementCount;
e(this, gt).textContent = t.searchSummaryAria(s);
}, // Search input handlers
Jt = function() {
const t = this.searchInput.value.trim();
this.filterCountriesByQuery(t), this.searchInput.value ? this.searchClearButton.classList.remove(b.HIDE) : this.searchClearButton.classList.add(b.HIDE);
}, // Update the selected list item in the dropdown
He = function(t) {
var s;
if (e(this, W) && e(this, W).dataset.countryCode !== t && (e(this, W).setAttribute(N.SELECTED, "false"), (s = e(this, W).querySelector(".iti__country-check")) == null || s.remove(), p(this, W, null)), t && !e(this, W)) {
const i = this.countryList.querySelector(
`[data-country-code="${t}"]`
);
if (i) {
i.setAttribute(N.SELECTED, "true");
const n = D(
"span",
{ class: "iti__country-check", [N.HIDDEN]: "true" },
i
);
n.innerHTML = Ps(), p(this, W, i);
}
}
}, //* Country search: Filter the country list to the given array of countries.
Me = function(t) {
this.countryList.replaceChildren();
let s = !0;
for (const i of t) {
const n = i.nodeById[e(this, R)];
n && (this.countryList.appendChild(n), s && (this.highlightListItem(n, !1), s = !1));
}
s ? (this.highlightListItem(null, !1), e(this, X) && e(this, X).classList.remove(b.HIDE)) : e(this, X) && e(this, X).classList.add(b.HIDE), this.countryList.scrollTop = 0, a(this, g, Qt).call(this);
}, Zt = function() {
if (e(this, L).dropdownAlwaysOpen)
return !0;
const t = this.telInput.getBoundingClientRect(), s = t.top, i = window.innerHeight - t.bottom;
return i >= e(this, at) || i >= s;
}, // inject dropdown into container and apply positioning styles
We = function() {
const { dropdownContainer: t, useFullscreenPopup: s } = e(this, L);
if (s) {
if (window.innerWidth >= q.NARROW_VIEWPORT_WIDTH) {
const i = this.telInput.getBoundingClientRect();
e(this, _).style.paddingLeft = `${i.left}px`, e(this, _).style.paddingRight = `${window.innerWidth - i.right}px`;
}
} else {
const i = this.telInput.getBoundingClientRect();
e(this, _).style.left = `${i.left}px`, a(this, g, Zt).call(this) ? e(this, _).style.top = `${i.bottom + q.DROPDOWN_MARGIN}px` : (e(this, _).style.top = "unset", e(this, _).style.bottom = `${window.innerHeight - i.top + q.DROPDOWN_MARGIN}px`);
}
t.appendChild(e(this, _));
}, I(_t, Pt);
let Gt = _t;
const Ss = (r) => {
const { onlyCountries: t, excludeCountries: s } = r;
return t != null && t.length ? Ct.filter(
(i) => t.includes(i.iso2)
) : s != null && s.length ? Ct.filter(
(i) => !s.includes(i.iso2)
) : Ct;
}, vs = (r, t) => {
const { countryNameLocale: s, i18n: i } = t;
let n;
try {
typeof Intl < "u" && typeof Intl.DisplayNames == "function" ? n = new Intl.DisplayNames(s, {
type: "region"
}) : n = null;
} catch (l) {
console.error(l), n = null;
}
for (const l of r)
l.name = i[l.iso2] || (n == null ? void 0 : n.of(l.iso2.toUpperCase())) || "";
}, Rs = (r) => {
const t = /* @__PURE__ */ new Set();
let s = 0;
const i = {}, n = (u, h) => {
if (!u || !h)
return;
h.length > s && (s = h.length), i.hasOwnProperty(h) || (i[h] = []);
const d = i[h];
d.includes(u) || d.push(u);
}, l = [...r].sort((u, h) => u.priority - h.priority);
for (const u of l) {
t.has(u.dialCode) || t.add(u.dialCode);
for (let h = 1; h < u.dialCode.length; h++) {
const d = u.dialCode.substring(0, h);
n(u.iso2, d);
}
if (n(u.iso2, u.dialCode), u.areaCodes) {
const h = i[u.dialCode][0];
for (const d of u.areaCodes) {
for (let C = 1; C < d.length; C++) {
const m = d.substring(0, C), A = u.dialCode + m;
n(h, A), n(u.iso2, A);
}
n(u.iso2, u.dialCode + d);
}
}
}
return { dialCodes: t, dialCodeMaxLen: s, dialCodeToIso2Map: i };
}, ks = (r, t) => {
const { countryOrder: s } = t;
r.sort((i, n) => {
if (s) {
const l = s.indexOf(i.iso2), u = s.indexOf(n.iso2), h = l > -1, d = u > -1;
if (h || d)
return h && d ? l - u : h ? -1 : 1;
}
return i.name.localeCompare(n.name);
});
}, Us = (r) => {
for (const t of r)
t.normalisedName = de(t.name), t.initials = t.normalisedName.split(/[^a-z]/).map((s) => s[0]).join(""), t.dialCodePlus = `+${t.dialCode}`;
}, xs = /* @__PURE__ */ new Set([
"800",
"808",
"870",
"881",
"882",
"883",
"888",
"979"
]), be = (r) => {
const t = pt(r).slice(0, 3);
return r.startsWith("+") && xs.has(t);
}, Ne = (r, t, s, i) => {
let n = r;
if (s && t) {
const l = `+${i.dialCode}`, u = n[l.length] === " " || n[l.length] === "-" ? l.length + 1 : l.length;
n = n.substring(u);
}
return n;
}, Hs = (r, t, s, i, n) => {
const l = s ? s.formatNumberAsYouType(r, i.iso2) : r, { dialCode: u } = i;
return n && t.charAt(0) !== "+" && l.includes(`+${u}`) ? (l.split(`+${u}`)[1] || "").trim() : l;
}, Ms = (r, t, s, i) => {
if (s === 0 && !i)
return 0;
let n = 0;
for (let l = 0; l < t.length; l++) {
if (/[+0-9]/.test(t[l]) && n++, n === r && !i)
return l + 1;
if (i && n === r + 1)
return l;
}
return t.length;
}, Ws = /* @__PURE__ */ new Set([
"800",
"822",
"833",
"844",
"855",
"866",
"877",
"880",
"881",
"882",
"883",
"884",
"885",
"886",
"887",
"888",
"889"
]), we = (r) => {
const t = pt(r);
if (t.startsWith(Le.NANP) && t.length >= 4) {
const s = t.substring(1, 4);
return Ws.has(s);
}
return !1;
};
var k, St, te;
class Bs {
constructor(t) {
I(this, St);
I(this, k);
t && a(this, St, te).call(this, t);
}
// Denormalise ASCII 0-9 to the user's numeral set. If not yet known, return as-is.
// NOTE: normalise is always called before this, so it should be impossible for the numeral set to be unknown at this point.
denormalise(t) {
if (!e(this, k) || e(this, k) === "ascii")
return t;
const s = e(this, k) === "arabic-indic" ? 1632 : 1776;
return t.replace(/[0-9]/g, (i) => String.fromCharCode(s + Number(i)));
}
// Normalize Eastern Arabic (U+0660-0669) and Persian/Extended Arabic-Indic (U+06F0-06F9) numerals to ASCII 0-9
normalise(t) {
if (!t)
return "";
if (a(this, St, te).call(this, t), e(this, k) === "ascii")
return t;
const s = e(this, k) === "arabic-indic" ? 1632 : 1776, i = e(this, k) === "arabic-indic" ? /[\u0660-\u0669]/g : /[\u06F0-\u06F9]/g;
return t.replace(i, (n) => String.fromCharCode(48 + (n.charCodeAt(0) - s)));
}
isAscii() {
return !e(this, k) || e(this, k) === "ascii";
}
}
k = new WeakMap(), St = new WeakSet(), // If any Arabic-Indic digits, then label it as that set. Same for Persian. Otherwise assume ASCII.
te = function(t) {
/[\u0660-\u0669]/.test(t) ? p(this, k, "arabic-indic") : /[\u06F0-\u06F9]/.test(t) ? p(this, k, "persian") : p(this, k, "ascii");
};
let $s = 0;
var c, E, vt, G, Rt, It, kt, Ut, y, V, j, B, st, H, it, ht, nt, ct, o, F, ot, Be, $e, Fe, ee, Ge, Ve, je, Ye, Ke, se, ze, Xe, qe, Qe, Je, Nt, wt, Ze, ts, es, ss, is, ns, os, ls, dt, Wt, rs, ie, tt, ne, Bt, oe, lt, le, Dt, Q, re, ae, Lt, ue, as, us, hs, cs, he, ds;
const ft = class ft {
constructor(t, s = {}) {
I(this, o);
//* PRIVATE FIELDS
I(this, c);
I(this, E);
I(this, vt);
// country data
I(this, G);
I(this, Rt);
I(this, It);
I(this, kt);
I(this, Ut);
I(this, y);
I(this, V);
I(this, j);
I(this, B);
I(this, st);
I(this, H);
I(this, it);
I(this, ht);
I(this, nt);
I(this, ct);
this.id = $s++, Gt.validateInput(t);
const i = Ns(s);
p(this, E, { ...ce, ...i }), ws(e(this, E)), Ds(e(this, E)), p(this, c, new Gt(t, e(this, E), this.id)), p(this, vt, Ls()), p(this, H, new Bs(t.value)), this.promise = a(this, o, Be).call(this, e(this, E)), p(this, G, Ss(e(this, E)));
const { dialCodes: n, dialCodeMaxLen: l, dialCodeToIso2Map: u } = Rs(
e(this, G)
);
p(this, kt, n), p(this, Rt, l), p(this, It, u), p(this, Ut, new Map(e(this, G).map((h) => [h.iso2, h]))), a(this, o, $e).call(this);
}
//********************
//* PUBLIC METHODS
//********************
//* Remove plugin.
destroy() {
e(this, c).telInput && (e(this, E).allowDropdown && a(this, o, lt).call(this, !0), e(this, B).abort(), p(this, B, null), e(this, c).destroy(), delete f.instances[this.id]);
}
// check if the instance is still valid (not destroyed/unmounted)
isActive() {
var t;
return !!((t = e(this, c)) != null && t.telInput);
}
//* Get the extension from the current number.
getExtension() {
var t;
return f.utils && e(this, c).telInput ? f.utils.getExtension(
a(this, o, Q).call(this),
(t = e(this, y)) == null ? void 0 : t.iso2
) : "";
}
//* Format the number to the given format.
getNumber(t) {
var s;
if (f.utils && e(this, c).telInput) {
const i = (s = e(this, y)) == null ? void 0 : s.iso2, n = a(this, o, Q).call(this), l = f.utils.formatNumber(
n,
i,
t
);
return e(this, H).denormalise(l);
}
return "";
}
//* Get the type of the entered number e.g. landline/mobile.
getNumberType() {
var t;
return f.utils && e(this, c).telInput ? f.utils.getNumberType(
a(this, o, Q).call(this),
(t = e(this, y)) == null ? void 0 : t.iso2
) : Ce.UNKNOWN_NUMBER_TYPE;
}
//* Get the country data for the currently selected country.
getSelectedCountryData() {
return a(this, o, ae).call(this);
}
//* Get the validation error.
getValidationError() {
var t;
if (f.utils && e(this, c).telInput) {
const s = (t = e(this, y)) == null ? void 0 : t.iso2;
return f.utils.getValidationError(a(this, o, Q).call(this), s);
}
return Ce.UNKNOWN_VALIDATION_ERROR;
}
//* Validate the input val using number length only
isValidNumber() {
var i, n;
const t = (i = e(this, y)) == null ? void 0 : i.dialCode, s = (n = e(this, y)) == null ? void 0 : n.iso2;
if (f.utils && e(this, c).telInput) {
const l = a(this, o, Q).call(this), u = f.utils.getCoreNumber(l, s);
if (u) {
if (t === jt.DIAL_CODE && u[0] === jt.MOBILE_PREFIX && u.length !== jt.MOBILE_CORE_LENGTH)
return !1;
if (!Z.ALPHA_UNICODE.test(l) && t) {
const d = l.startsWith("+") ? l.slice(1 + t.length) : l, C = pt(d).length;
if (u.length > C)
return !1;
}
}
}
return a(this, o, he).call(this, !1);
}
//* Validate the input val with precise validation
isValidNumberPrecise() {
return a(this, o, he).call(this, !0);
}
//* Update the selected country, and update the input val accordingly.
setCountry(t) {
var l, u;
if (!e(this, c).telInput)
return;
const s = t == null ? void 0 : t.toLowerCase();
if (!At(s))
throw new Error(`Invalid country code: '${s}'`);
const i = (l = e(this, y)) == null ? void 0 : l.iso2;
if (t && s !== i || !t && i) {
if (a(this, o, tt).call(this, s), a(this, o, le).call(this, ((u = e(this, y)) == null ? void 0 : u.dialCode) || ""), e(this, E).formatOnDisplay) {
const h = a(this, o, F).call(this);
a(this, o, dt).call(this, h);
}
a(this, o, Lt).call(this);
}
}
//* Set the input value and update the country.
setNumber(t) {
if (!e(this, c).telInput)
return;
const s = e(this, H).normalise(t), i = a(this, o, Wt).call(this, s);
a(this, o, dt).call(this, s), i && a(this, o, Lt).call(this), a(this, o, Nt).call(this, Ht.INPUT, { isSetNumber: !0 });
}
//* Set the placeholder number typ
setPlaceholderNumberType(t) {
e(this, c).telInput && (e(this, E).placeholderNumberType = t, a(this, o, Bt).call(this));
}
setDisabled(t) {
e(this, c).telInput && (e(this, c).telInput.disabled = t, e(this, c).selectedCountry && (t ? e(this, c).selectedCountry.setAttribute("disabled", "true") : e(this, c).selectedCountry.removeAttribute("disabled")));
}
//********************
//* STATIC METHODS
//********************
// Internal instance notification used by utils/geoip loaders.
// Kept public so module-level helpers (e.g. attachUtils) can call it, while still allowing
// access to private instance methods.
static forEachInstance(t, ...s) {
const i = Object.values(f.instances), n = s[0];
i.forEach((l) => {
var u, h, d, C;
if (l instanceof ft)
switch (t) {
case "handleUtils":
a(u = l, o, us).call(u);
break;
case "handleUtilsFailure":
a(h = l, o, hs).call(h, n);
break;
case "handleAutoCountry":
a(d = l, o, ue).call(d);
break;
case "handleAutoCountryFailure":
a(C = l, o, as).call(C);
break;
}
});
}
};
c = new WeakMap(), E = new WeakMap(), vt = new WeakMap(), G = new WeakMap(), Rt = new WeakMap(), It = new WeakMap(), kt = new WeakMap(), Ut = new WeakMap(), y = new WeakMap(), V = new WeakMap(), j = new WeakMap(), B = new WeakMap(), st = new WeakMap(), H = new WeakMap(), it = new WeakMap(), ht = new WeakMap(), nt = new WeakMap(), ct = new WeakMap(), o = new WeakSet(), F = function() {
const t = e(this, c).telInput.value.trim();
return e(this, H).normalise(t);
}, ot = function(t) {
e(this, c).telInput.value = e(this, H).denormalise(t);
}, Be = function(t) {
const { initialCountry: s, geoIpLookup: i, loadUtils: n } = t, l = s === bt.AUTO && !!i, u = !!n && !f.utils;
let h;
l ? h = new Promise((C, m) => {
p(this, it, C), p(this, ht, m);
}) : (h = Promise.resolve(void 0), p(this, it, () => {
}), p(this, ht, () => {
}));
let d;
return u ? d = new Promise((C, m) => {
p(this, nt, C), p(this, ct, m);
}) : (d = Promise.resolve(void 0), p(this, nt, () => {
}), p(this, ct, () => {
})), Promise.all([h, d]).then(() => {
});
}, $e = function() {
p(this, y, null), p(this, B, new AbortController()), a(this, o, Fe).call(this), e(this, c).generateMarkup(e(this, G)), a(this, o, ee).call(this), a(this, o, Ge).call(this), a(this, o, Ye).call(this), e(this, E).dropdownAlwaysOpen && a(this, o, wt).call(this);
}, //********************
//* PRIVATE METHODS
//********************
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
Fe = function() {
vs(e(this, G), e(this, E)), ks(e(this, G), e(this, E)), Us(e(this, G));
}, //* 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
ee = function(t = !1) {
const s = e(this, c).telInput.getAttribute("value"), i = e(this, H).normalise(s), n = a(this, o, F).call(this), u = i && i.startsWith("+") && (!n || !n.startsWith("+")) ? i : n, h = a(this, o, Dt).call(this, u), d = we(u), { initialCountry: C, geoIpLookup: m } = e(this, E), O = C === bt.AUTO && m && !t, v = At(C);
h ? d ? v ? a(this, o, tt).call(this, C) : O || a(this, o, tt).call(this, Cs.ISO2) : a(this, o, Wt).call(this, u) : v ? a(this, o, tt).call(this, C) : O || a(this, o, tt).call(this, ""), u && a(this, o, dt).call(this, u);
}, //* Initialise the main event listeners: input keyup, and click selected country.
Ge = function() {
a(this, o, ze).call(this), e(this, E).allowDropdown && a(this, o, je).call(this), (e(this, c).hiddenInput || e(this, c).hiddenInputCountry) && e(this, c).telInput.form && a(this, o, Ve).call(this);
}, //* Update hidden input on form submit.
Ve = function() {
var s;
const t = () => {
var i;
e(this, c).hiddenInput && (e(this, c).hiddenInput.value = this.getNumber()), e(this, c).hiddenInputCountry && (e(this, c).hiddenInputCountry.value = ((i = e(this, y)) == null ? void 0 : i.iso2) || "");
};
(s = e(this, c).telInput.form) == null || s.addEventListener("submit", t, {
signal: e(this, B).signal
});
}, //* initialise the dropdown listeners.
je = function() {
const t = e(this, B).signal, s = (u) => {
e(this, c).isDropdownClosed() ? e(this, c).telInput.focus() : u.preventDefault();
}, i = e(this, c).telInput.closest("label");
i && i.addEventListener("click", s, { signal: t });
const n = () => {
e(this, c).isDropdownClosed() && !e(this, c).telInput.disabled && !e(this, c).telInput.readOnly && a(this, o, wt).call(this);
};
e(this, c).selectedCountry.addEventListener(
"click",
n,
{
signal: t
}
);
const l = (u) => {
const h = [S.ARROW_UP, S.ARROW_DOWN, S.SPACE, S.ENTER];
e(this, c).isDropdownClosed() && h.includes(u.key) && (u.preventDefault(), u.stopPropagation(), a(this, o, wt).call(this)), u.key === S.TAB && a(this, o, lt).call(this);
};
e(this, c).countryContainer.addEventListener(
"keydown",
l,
{ signal: t }
);
}, //* Init requests: utils script / geo ip lookup.
Ye = function() {
var l;
const { loadUtils: t, initialCountry: s, geoIpLookup: i } = e(this, E);
if (t && !f.utils) {
const u = () => {
var h;
(h = f.attachUtils(t)) == null || h.catch(() => {
});
};
f.documentReady() ? u() : window.addEventListener("load", u, {
signal: e(this, B).signal
});
} else
e(this, nt).call(this);
s === bt.AUTO && i && ((l = e(this, y)) != null && l.iso2 ? e(this, it).call(this) : a(this, o, Ke).call(this));
}, //* Perform the geo ip lookup.
Ke = function() {
if (f.autoCountry)
a(this, o, ue).call(this);
else if (e(this, c).selectedCountryInner.classList.add(b.LOADING), !f.startedLoadingAutoCountry && (f.startedLoadingAutoCountry = !0, typeof e(this, E).geoIpLookup == "function")) {
const t = (i = "") => {
e(this, c).selectedCountryInner.classList.remove(b.LOADING);
const n = i.toLowerCase();
At(n) ? (f.autoCountry = n, setTimeout(() => ft.forEachInstance("handleAutoCountry"))) : ft.forEachInstance("handleAutoCountryFailure");
}, s = () => {
e(this, c).selectedCountryInner.classList.remove(b.LOADING), ft.forEachInstance("handleAutoCountryFailure");
};
e(this, E).geoIpLookup(t, s);
}
}, se = function() {
a(this, o, wt).call(this), e(this, c).searchInput.value = "+", e(this, c).filterCountriesByQuery("");
}, //* Initialize the tel input listeners.
ze = function() {
a(this, o, Xe).call(this), a(this, o, qe).call(this), a(this, o, Qe).call(this);
}, Xe = function() {
const {
strictMode: t,
formatAsYouType: s,
separateDialCode: i,
allowDropdown: n,
countrySearch: l
} = e(this, E);
let u = !1;
Z.ALPHA_UNICODE.test(a(this, o, F).call(this)) && (u = !0);
const h = (d) => {
var T;
const C = a(this, o, F).call(this);
if (e(this, vt) && (d == null ? void 0 : d.data) === "+" && i && n && l) {
const M = e(this, c).telInput.selectionStart || 0, $ = C.substring(0, M - 1), Y = C.substring(M);
a(this, o, ot).call(this, $ + Y), a(this, o, se).call(this);
return;
}
a(this, o, Wt).call(this, C) && a(this, o, Lt).call(this);
const m = (d == null ? void 0 : d.data) && Z.NON_PLUS_NUMERIC.test(d.data), A = (d == null ? void 0 : d.inputType) === fe.PASTE && C;
m || A && !t ? u = !0 : Z.NON_PLUS_NUMERIC.test(C) || (u = !1);
const O = (d == null ? void 0 : d.detail) && d.detail.isSetNumber, v = e(this, H).isAscii();
if (s && !u && !O && v) {
const M = e(this, c).telInput.selectionStart || 0, Y = C.substring(
0,
M
).replace(
Z.NON_PLUS_NUMERIC_GLOBAL,
""
).length, P = (d == null ? void 0 : d.inputType) === fe.DELETE_FWD, J = a(this, o, Q).call(this), K = Hs(
J,
C,
f.utils,
e(this, y) ?? {},
i
), U = Ms(
Y,
K,
M,
P
);
a(this, o, ot).call(this, K), e(this, c).telInput.setSelectionRange(U, U);
}
if (i && C.startsWith("+") && ((T = e(this, y)) != null && T.dialCode)) {
const M = Ne(
C,
!0,
i,
e(this, y) ?? {}
);
a(this, o, ot).call(this, M);
}
};
e(this, c).telInput.addEventListener(
"input",
h,
{
signal: e(this, B).signal
}
);
}, qe = function() {
const { strictMode: t, separateDialCode: s, allowDropdown: i, countrySearch: n } = e(this, E);
if (t || s) {
const l = (u) => {
var h;
if (u.key && u.key.length === 1 && !u.altKey && !u.ctrlKey && !u.metaKey) {
if (s && i && n && u.key === "+") {
u.preventDefault(), a(this, o, se).call(this);
return;
}
if (t) {
const d = a(this, o, F).call(this), m = !d.startsWith("+") && e(this, c).telInput.selectionStart === 0 && u.key === "+", A = e(this, H).normalise(u.key), O = /^[0-9]$/.test(A), v = s ? O : m || O, T = e(this, c).telInput, M = T.selectionStart, $ = T.selectionEnd, Y = d.slice(0, M), P = d.slice($), J = Y + u.key + P, K = a(this, o, Q).call(this, J);
let U = !1;
f.utils && e(this, V) && (U = f.utils.getCoreNumber(
K,
(h = e(this, y)) == null ? void 0 : h.iso2
).length > e(this, V));
const Et = a(this, o, ie).call(this, K) !== null;
(!v || U && !Et && !m) && u.preventDefault();
}
}
};
e(this, c).telInput.addEventListener("keydown", l, {
signal: e(this, B).signal
});
}
}, Qe = function() {
if (e(this, E).strictMode) {
const t = (s) => {
var K;
s.preventDefault();
const i = e(this, c).telInput, n = i.selectionStart, l = i.selectionEnd, u = a(this, o, F).call(this), h = u.slice(0, n), d = u.slice(l), C = (K = e(this, y)) == null ? void 0 : K.iso2, m = s.clipboardData.getData("text"), A = e(this, H).normalise(m), O = n === 0 && l > 0, v = !u.startsWith("+") || O, T = A.replace(Z.NON_PLUS_NUMERIC_GLOBAL, ""), M = T.startsWith("+"), $ = T.replace(/\+/g, ""), Y = M && v ? `+${$}` : $;
let P = h + Y + d;
if (P.length > 5) {
let U = f.utils.getCoreNumber(P, C);
for (; U.length === 0 && P.length > 0; )
P = P.slice(0, -1), U = f.utils.getCoreNumber(P, C);
if (!U)
return;
if (e(this, V) && U.length > e(this, V))
if (i.selectionEnd === u.length) {
const xt = U.length - e(this, V);
P = P.slice(0, P.length - xt);
} else
return;
}
a(this, o, ot).call(this, P);
const J = n + Y.length;
i.setSelectionRange(J, J), i.dispatchEvent(new InputEvent("input", { bubbles: !0 }));
};
e(this, c).telInput.addEventListener("paste", t, {
signal: e(this, B).signal
});
}
}, //* Adhere to the input's maxlength attr.
Je = function(t) {
const s = Number(e(this, c).telInput.getAttribute("maxlength"));
return s && t.length > s ? t.substring(0, s) : t;
}, //* Trigger a custom event on the input (typed via ItiEventMap).
Nt = function(t, s = {}) {
const i = new CustomEvent(t, {
bubbles: !0,
cancelable: !0,
detail: s
});
e(this, c).telInput.dispatchEvent(i);
}, //* Open the dropdown.
wt = function() {
const { dropdownContainer: t, useFullscreenPopup: s } = e(this, E);
if (p(this, st, new AbortController()), e(this, c).openDropdown(), !s && t) {
const i = () => a(this, o, lt).call(this);
window.addEventListener("scroll", i, {
signal: e(this, st).signal
});
}
a(this, o, Ze).call(this), a(this, o, Nt).call(this, Ht.OPEN_COUNTRY_DROPDOWN);
}, //* We only bind dropdown listeners when the dropdown is open.
Ze = function() {
const t = e(this, st).signal;
a(this, o, ts).call(this, t), a(this, o, es).call(this, t), e(this, E).dropdownAlwaysOpen || a(this, o, ss).call(this, t), a(this, o, is).call(this, t), e(this, E).countrySearch && a(this, o, ns).call(this, t);
}, //* When mouse over a list item, just highlight that one
//* we add the class "highlight", so if they hit "enter" we know which one to select.
ts = function(t) {
const s = (i) => {
var l;
const n = (l = i.target) == null ? void 0 : l.closest(
`.${b.COUNTRY_ITEM}`
);
n && e(this, c).highlightListItem(n, !1);
};
e(this, c).countryList.addEventListener(
"mouseover",
s,
{
signal: t
}
);
}, //* Listen for country selection.
es = function(t) {
const s = (i) => {
var l;
const n = (l = i.target) == null ? void 0 : l.closest(
`.${b.COUNTRY_ITEM}`
);
n && a(this, o, oe).call(this, n);
};
e(this, c).countryList.addEventListener("click", s, {
signal: t
});
}, //* Click off to close (except when this initial opening click is bubbling up).
//* We cannot just stopPropagation as it may be needed to close another instance.
ss = function(t) {
const s = (i) => {
!!i.target.closest(
`#iti-${this.id}__dropdown-content`
) || a(this, o, lt).call(this);
};
setTimeout(() => {
document.documentElement.addEventListener(
"click",
s,
{ signal: t }
);
}, 0);
}, //* Listen for up/down scrolling, enter to select, or escape to close.
//* Use keydown as keypress doesn't fire for non-char keys and we want to catch if they
//* just hit down and hold it to scroll down (no keyup event).
//* Listen on the document because that's where key events are triggered if no input has focus.
is = function(t) {
let s = "", i = null;
const n = (l) => {
[
S.ARROW_UP,
S.ARROW_DOWN,
S.ENTER,
S.ESC
].includes(l.key) && (l.preventDefault(), l.stopPropagation(), l.key === S.ARROW_UP || l.key === S.ARROW_DOWN ? e(this, c).handleUpDownKey(l.key) : l.key === S.ENTER && !l.isComposing ? a(this, o, ls).call(this) : l.key === S.ESC && (a(this, o, lt).call(this), e(this, c).selectedCountry.focus())), !e(this, E).countrySearch && Z.HIDDEN_SEARCH_CHAR.test(l.key) && (l.stopPropagation(), i && clearTimeout(i), s += l.key.toLowerCase(), a(this, o, os).call(this, s), i = setTimeout(() => {
s = "";
}, De.HIDDEN_SEARCH_RESET_MS));
};
document.addEventListener("keydown", n, { signal: t });
}, //* Search input listeners when countrySearch enabled.
ns = function(t) {
e(this, c).searchInput.addEventListener(
"input",
() => e(this, c).handleSearchChange(),
{ signal: t }
), e(this, c).searchClearButton.addEventListener(
"click",
() => e(this, c).handleSearchClear(),
{ signal: t }
);
}, //* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
os = function(t) {
const s = _s(e(this, G), t);
if (s) {
const i = s.nodeById[this.id];
e(this, c).highlightListItem(i, !1), e(this, c).scrollCountryListToItem(i);
}
}, //* Select the currently highlighted item.
ls = function() {
e(this, c).highlightedItem && a(this, o, oe).call(this, e(this, c).highlightedItem);
}, //* Update the input's value to the given val (format first if possible)
//* NOTE: this is called from _setInitialState, handleUtils and setNumber.
dt = function(t) {
var u;
const { formatOnDisplay: s, nationalMode: i, separateDialCode: n } = e(this, E);
let l = t;
if (s && f.utils && e(this, y)) {
const h = be(t), d = i && !h || !l.startsWith("+") && !n, { NATIONAL: C, INTERNATIONAL: m } = f.utils.numberFormat, A = d ? C : m;
l = f.utils.formatNumber(
l,
(u = e(this, y)) == null ? void 0 : u.iso2,
A
);
}
l = a(this, o, re).call(this, l), a(this, o, ot).call(this, l);
}, //* Check if need to select a new country based on the given number
//* Note: called from _setInitialState, keyup handler, setNumber.
Wt = function(t) {
const s = a(this, o, ie).call(this, t);
return s !== null ? a(this, o, tt).call(this, s) : !1;
}, // if there is a selected country, and the number doesn't start with a dial code, then add it
rs = function(t) {
var h, d;
const s = (h = e(this, y)) == null ? void 0 : h.dialCode, i = (d = e(this, y)) == null ? void 0 : d.nationalPrefix;
if (t.startsWith("+") || !s)
return t;
const u = i && t.startsWith(i) && !e(this, E).separateDialCode ? t.substring(1) : t;
return `+${s}${u}`;
}, //* Get the new country based on the input number, or return null if no change, or empty string if should be empty (e.g. if they type an invalid dial code).
ie = function(t) {
var d, C, m, A, O;
const s = t.indexOf("+");
let i = s ? t.substring(s) : t;
const n = (d = e(this, y)) == null ? void 0 : d.iso2, l = (C = e(this, y)) == null ? void 0 : C.dialCode;
i = a(this, o, rs).call(this, i);
const u = a(this, o, Dt).call(this, i, !0), h = pt(i);
if (u) {
const v = pt(u), T = e(this, It)[v];
if (T.length === 1)
return T[0] === n ? null : T[0];
if (!n && e(this, j) && T.includes(e(this, j)))
return e(this, j);
if (l === Le.NANP && we(h))
return null;
const $ = (m = e(this, y)) == null ? void 0 : m.areaCodes, Y = (A = e(this, y)) == null ? void 0 : A.priority;
if ($) {
const xt = $.map(
(Et) => `${l}${Et}`
);
for (const Et of xt)
if (h.startsWith(Et))
return null;
}
const J = $ && !(Y === 0) && h.length > v.length, K = n && T.includes(n) && !J, U = n === T[0];
if (!K && !U)
return T[0];
} else if (i.startsWith("+") && h.length) {
const v = ((O = e(this, y)) == null ? void 0 : O.dialCode) || "";
return v && v.startsWith(h) ? null : "";
} else if ((!i || i === "+") && !n && e(this, j))
return e(this, j);
return null;
}, //* Update the selected country, dial code (if separateDialCode), placeholder, title, and selected list item.
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
tt = function(t) {
var i, n;
const s = ((i = e(this, y)) == null ? void 0 : i.iso2) || "";
return p(this, y, t ? e(this, Ut).get(t) : null), (n = e(this, y)) != null && n.iso2 && p(this, j, e(this, y).iso2), e(this, c).setCountry(e(this, y) ?? {}), a(this, o, Bt).call(this), a(this, o, ne).call(this), s !== t;
}, //* Update the maximum valid number length for the currently selected country.
ne = function() {
var l;
const { strictMode: t, placeholderNumberType: s, allowedNumberTypes: i } = e(this, E), n = (l = e(this, y)) == null ? void 0 : l.iso2;
if (t && f.utils)
if (n) {
const u = f.utils.numberType[s];
let h = f.utils.getExampleNumber(
n,
!1,
u,
!0
), d = h;
for (; f.utils.isPossibleNumber(
h,
n,
i
); )
d = h, h += "0";
const C = f.utils.getCoreNumber(d, n);
p(this, V, C.length), n === "by" && p(this, V, C.length + 1);
} else
p(this, V, null);
}, //* Update the input placeholder to an example number from the currently selected country.
Bt = function() {
var u;
const {
autoPlaceholder: t,
placeholderNumberType: s,
nationalMode: i,
customPlaceholder: n
} = e(this, E), l = t === $t.AGGRESSIVE || !e(this, c).hadInitialPlaceholder && t === $t.POLITE;
if (f.utils && l) {
const h = f.utils.numberType[s];
let d = (u = e(this, y)) != null && u.iso2 ? f.utils.getExampleNumber(
e(this, y).iso2,
i,
h
) : "";
d = a(this, o, re).call(this, d), typeof n == "function" && (d = n(d, e(this, y) ?? {})), e(this, c).telInput.setAttribute("placeholder", d);
}
}, //* Called when the user selects a list item from the dropdown.
oe = function(t) {
const s = t.dataset[ye.COUNTRY_CODE], i = a(this, o, tt).call(this, s);
a(this, o, lt).call(this);
const n = t.dataset[ye.DIAL_CODE];
if (a(this, o, le).call(this, n), e(this, E).formatOnDisplay) {
const l = a(this, o, F).call(this);
a(this, o, dt).call(this, l);
}
e(this, c).telInput.focus(), i && a(this, o, Lt).call(this);
}, //* Close the dropdown and unbind any listeners.
lt = function(t) {
e(this, c).isDropdownClosed() || e(this, E).dropdownAlwaysOpen && !t || (e(this, c).closeDropdown(), e(this, st).abort(), p(this, st, null), a(this, o, Nt).call(this, Ht.CLOSE_COUNTRY_DROPDOWN));
}, //* Replace any existing dial code with the new one
//* Note: called from _selectListItem and setCountry
le = function(t) {
const s = a(this, o, F).call(this), i = `+${t}`;
let n;
if (s.startsWith("+")) {
const l = a(this, o, Dt).call(this, s);
l ? n = s.replace(l, i) : n = i, a(this, o, ot).call(this, n);
}
}, //* Try and extract a valid international dial code from a full telephone number.
//* Note: returns the raw string inc plus character and any whitespace/dots etc.
Dt = function(t, s) {
let i = "";
if (t.startsWith("+")) {
let n = "", l = !1;
for (let u = 0; u < t.length; u++) {
const h = t.charAt(u);
if (/[0-9]/.test(h)) {
if (n += h, !!!e(this, It)[n])
break;
if (e(this, kt).has(n)) {
if (i = t.substring(0, u + 1), l = !0, !s)
break;
} else s && l && (i = t.substring(0, u + 1));
if (n.length === e(this, Rt))
break;
}
}
}
return i;
}, //* Get the input val, adding the dial code if separateDialCode is enabled.
Q = function(t) {
var u;
const s = t ? e(this, H).normalise(t) : a(this, o, F).call(this), i = (u = e(this, y)) == null ? void 0 : u.dialCode;
let n;
const l = pt(s);
return e(this, E).separateDialCode && !s.startsWith("+") && i && l ? n = `+${i}` : n = "", n + s;
}, //* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
re = function(t) {
const s = !!a(this, o, Dt).call(this, t), i = Ne(
t,
s,
e(this, E).separateDialCode,
e(this, y) ?? {}
);
return a(this, o, Je).call(this, i);
}, //* Return only the public-facing subset of the selected country data.
ae = function() {
const t = e(this, y);
if (!t) return {};
const { iso2: s, dialCode: i, name: n } = t;
return { iso2: s, dialCode: i, name: n };
}, //* Trigger the 'countrychange' event.
Lt = function() {
const t = a(this, o, ae).call(this);
a(this, o, Nt).call(this, Ht.COUNTRY_CHANGE, t);
}, //**************************
//* INTERNAL METHODS
//**************************
//* Called when the geoip call returns.
ue = function() {
var t, s;
if (!e(this, c).telInput) {
(t = e(this, it)) == null || t.call(this);
return;
}
e(this, E).initialCountry === bt.AUTO && f.autoCountry && (p(this, j, f.autoCountry), (s = e(this, y)) != null && s.iso2 || e(this, c).selectedCountryInner.classList.contains(b.GLOBE) || this.setCountry(e(this, j)), e(this, it).call(this));
}, //* Called when the geoip call fails or times out.
as = function() {
var t;
if (!e(this, c).telInput) {
(t = e(this, ht)) == null || t.call(this);
return;
}
a(this, o, ee).call(this, !0), e(this, ht).call(this);
}, //* Called when the utils request completes.
us = function() {
var t, s;
if (!e(this, c).telInput) {
(t = e(this, nt)) == null || t.call(this);
return;
}
if (f.utils) {
const i = a(this, o, F).call(this);
i && a(this, o, dt).call(this, i), (s = e(this, y)) != null && s.iso2 && (a(this, o, Bt).call(this), a(this, o, ne).call(this));
}
e(this, nt).call(this);
}, //* Called when the utils request fails or times out.
hs = function(t) {
var s;
if (!e(this, c).telInput) {
(s = e(this, ct)) == null || s.call(this, t);
return;
}
e(this, ct).call(this, t);
}, cs = function(t) {
var s;
return f.utils ? f.utils.isPossibleNumber(
t,
(s = e(this, y)) == null ? void 0 : s.iso2,
e(this, E).allowedNumberTypes
) : null;
}, //* Shared internal validation logic to handle alpha character extension rules.
he = function(t) {
var d, C;
if (!f.utils || !e(this, c).telInput)
return null;
const { allowNumberExtensions: s, allowPhonewords: i } = e(this, E), n = (m) => t ? a(this, o, ds).call(this, m) : a(this, o, cs).call(this, m), l = a(this, o, Q).call(this);
if (!((d = e(this, y)) != null && d.iso2) && !be(l) || !n(l))
return !1;
if (l.search(Z.ALPHA_UNICODE) > -1) {
const m = (C = e(this, y)) == null ? void 0 : C.iso2;
return f.utils.getExtension(l, m) ? s : i;
}
return !0;
}, ds = function(t) {
var s;
return f.utils ? f.utils.isValidNumber(
t,
(s = e(this, y)) == null ? void 0 : s.iso2,
e(this, E).allowedNumberTypes
) : null;
};
let Ot = ft;
const Fs = (r) => {
if (!f.utils && !f.startedLoadingUtilsScript) {
let t;
if (typeof r == "function")
try {
t = Promise.resolve(r());
} catch (s) {
return Promise.reject(s);
}
else
return Promise.reject(
new TypeError(
`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof r}`
)
);
return f.startedLoadingUtilsScript = !0, t.then((s) => {
const i = s == null ? void 0 : s.default;
if (!i || typeof i != "object")
throw new TypeError(
"The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
);
return f.utils = i, Ot.forEachInstance("handleUtils"), !0;
}).catch((s) => {
throw Ot.forEachInstance("handleUtilsFailure", s), s;
});
}
return null;
}, f = Object.assign(
(r, t) => {
const s = new Ot(r, t);
return f.instances[s.id] = s, r.iti = s, s;
},
{
defaults: ce,
//* Using a static var like this allows us to mock it in the tests.
documentReady: () => document.readyState === "complete",
//* Get the country data object.
getCountryData: () => Ct,
//* A getter for the plugin instance.
getInstance: (r) => {
const t = r.dataset.intlTelInputId;
return t ? f.instances[t] : null;
},
//* A map from instance ID to instance object.
instances: {},
attachUtils: Fs,
startedLoadingUtilsScript: !1,
startedLoadingAutoCountry: !1,
version: "26.9.1"
}
);
export {
f as i
};