intl-tel-input 28.0.3 → 28.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/data.js +1 -1
- package/dist/js/data.min.js +1 -1
- package/dist/js/intlTelInput.js +93 -43
- package/dist/js/intlTelInput.min.js +2 -20
- package/dist/js/intlTelInput.mjs +92 -42
- package/dist/js/intlTelInputWithUtils.js +269 -240
- package/dist/js/intlTelInputWithUtils.min.js +2 -20
- package/dist/js/intlTelInputWithUtils.mjs +268 -239
- package/dist/js/utils.js +35 -37
- package/package.json +8 -4
package/dist/js/intlTelInput.mjs
CHANGED
|
@@ -2250,40 +2250,62 @@ var createEl = (tagName, attrs, container) => {
|
|
|
2250
2250
|
};
|
|
2251
2251
|
|
|
2252
2252
|
// packages/core/src/js/core/icons.ts
|
|
2253
|
-
var
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2253
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
2254
|
+
var buildSvg = ([tag, attrs, children]) => {
|
|
2255
|
+
const el = document.createElementNS(SVG_NS, tag);
|
|
2256
|
+
if (attrs) {
|
|
2257
|
+
for (const k in attrs) {
|
|
2258
|
+
el.setAttribute(k, String(attrs[k]));
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
if (children) {
|
|
2262
|
+
for (const c of children) {
|
|
2263
|
+
el.appendChild(buildSvg(c));
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
return el;
|
|
2267
|
+
};
|
|
2268
|
+
var buildSearchIcon = () => buildSvg(
|
|
2269
|
+
["svg", { class: "iti__search-icon-svg", width: 14, height: 14, viewBox: "0 0 24 24", focusable: "false", [ARIA.HIDDEN]: "true" }, [
|
|
2270
|
+
["circle", { cx: 11, cy: 11, r: 7 }],
|
|
2271
|
+
["line", { x1: 21, y1: 21, x2: 16.65, y2: 16.65 }]
|
|
2272
|
+
]]
|
|
2273
|
+
);
|
|
2258
2274
|
var buildClearIcon = (id) => {
|
|
2259
2275
|
const maskId = `iti-${id}-clear-mask`;
|
|
2260
|
-
return
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2276
|
+
return buildSvg(
|
|
2277
|
+
["svg", { class: "iti__search-clear-svg", width: 12, height: 12, viewBox: "0 0 16 16", [ARIA.HIDDEN]: "true", focusable: "false" }, [
|
|
2278
|
+
["mask", { id: maskId, maskUnits: "userSpaceOnUse" }, [
|
|
2279
|
+
["rect", { width: 16, height: 16, fill: "white" }],
|
|
2280
|
+
["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" }]
|
|
2281
|
+
]],
|
|
2282
|
+
["circle", { cx: 8, cy: 8, r: 8, class: "iti__search-clear-bg", mask: `url(#${maskId})` }]
|
|
2283
|
+
]]
|
|
2284
|
+
);
|
|
2268
2285
|
};
|
|
2269
|
-
var buildCheckIcon = () =>
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2286
|
+
var buildCheckIcon = () => buildSvg(
|
|
2287
|
+
["svg", { class: "iti__country-check-svg", width: 14, height: 14, viewBox: "0 0 16 16", fill: "currentColor", focusable: "false", [ARIA.HIDDEN]: "true" }, [
|
|
2288
|
+
["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" }]
|
|
2289
|
+
]]
|
|
2290
|
+
);
|
|
2291
|
+
var buildGlobeIcon = () => buildSvg(
|
|
2292
|
+
["svg", { width: 256, height: 256, viewBox: "0 0 512 512", class: "iti__globe-svg" }, [
|
|
2293
|
+
["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" }],
|
|
2294
|
+
["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" }]
|
|
2295
|
+
]]
|
|
2296
|
+
);
|
|
2278
2297
|
|
|
2279
2298
|
// packages/core/src/js/core/countrySearch.ts
|
|
2299
|
+
var normaliseName = (s) => normaliseString(s).replace(/[^\p{L}]+/gu, " ").trim();
|
|
2280
2300
|
var buildSearchTokens = (countries) => {
|
|
2281
2301
|
const tokens = /* @__PURE__ */ new Map();
|
|
2282
2302
|
for (const c of countries) {
|
|
2283
|
-
const normalisedName =
|
|
2284
|
-
const
|
|
2303
|
+
const normalisedName = normaliseName(c.name);
|
|
2304
|
+
const words = normalisedName.split(" ").filter(Boolean);
|
|
2305
|
+
const initials = words.map((w) => w[0] || "").join("");
|
|
2285
2306
|
tokens.set(c.iso2, {
|
|
2286
2307
|
normalisedName,
|
|
2308
|
+
words,
|
|
2287
2309
|
initials,
|
|
2288
2310
|
dialCodePlus: `+${c.dialCode}`
|
|
2289
2311
|
});
|
|
@@ -2291,29 +2313,49 @@ var buildSearchTokens = (countries) => {
|
|
|
2291
2313
|
return tokens;
|
|
2292
2314
|
};
|
|
2293
2315
|
var getMatchedCountries = (countries, searchTokens, query) => {
|
|
2294
|
-
const
|
|
2316
|
+
const lowerQuery = normaliseString(query);
|
|
2317
|
+
const nameQuery = normaliseName(query);
|
|
2318
|
+
const skipNameBuckets = lowerQuery !== "" && nameQuery === "";
|
|
2295
2319
|
const iso2Matches = [];
|
|
2296
2320
|
const nameStartsWith = [];
|
|
2297
2321
|
const nameContains = [];
|
|
2298
2322
|
const dialCodeMatches = [];
|
|
2299
2323
|
const dialCodeContains = [];
|
|
2300
2324
|
const initialsMatches = [];
|
|
2325
|
+
const wordMatches = [];
|
|
2301
2326
|
for (const c of countries) {
|
|
2302
2327
|
const t = searchTokens.get(c.iso2);
|
|
2303
|
-
if (c.iso2 ===
|
|
2328
|
+
if (c.iso2 === lowerQuery) {
|
|
2304
2329
|
iso2Matches.push(c);
|
|
2305
|
-
} else if (t.normalisedName.startsWith(
|
|
2330
|
+
} else if (!skipNameBuckets && t.normalisedName.startsWith(nameQuery)) {
|
|
2306
2331
|
nameStartsWith.push(c);
|
|
2307
|
-
} else if (t.normalisedName.includes(
|
|
2332
|
+
} else if (!skipNameBuckets && t.normalisedName.includes(nameQuery)) {
|
|
2308
2333
|
nameContains.push(c);
|
|
2309
|
-
} else if (
|
|
2334
|
+
} else if (lowerQuery === c.dialCode || lowerQuery === t.dialCodePlus) {
|
|
2310
2335
|
dialCodeMatches.push(c);
|
|
2311
|
-
} else if (t.dialCodePlus.includes(
|
|
2336
|
+
} else if (t.dialCodePlus.includes(lowerQuery)) {
|
|
2312
2337
|
dialCodeContains.push(c);
|
|
2313
|
-
} else if (t.initials.includes(
|
|
2338
|
+
} else if (t.initials.includes(lowerQuery)) {
|
|
2314
2339
|
initialsMatches.push(c);
|
|
2315
2340
|
}
|
|
2316
2341
|
}
|
|
2342
|
+
const queryWords = nameQuery.split(" ").filter(Boolean);
|
|
2343
|
+
if (queryWords.length > 1 && iso2Matches.length === 0 && nameStartsWith.length === 0 && nameContains.length === 0) {
|
|
2344
|
+
const claimed = /* @__PURE__ */ new Set([
|
|
2345
|
+
...dialCodeMatches.map((c) => c.iso2),
|
|
2346
|
+
...dialCodeContains.map((c) => c.iso2),
|
|
2347
|
+
...initialsMatches.map((c) => c.iso2)
|
|
2348
|
+
]);
|
|
2349
|
+
for (const c of countries) {
|
|
2350
|
+
if (claimed.has(c.iso2)) {
|
|
2351
|
+
continue;
|
|
2352
|
+
}
|
|
2353
|
+
const t = searchTokens.get(c.iso2);
|
|
2354
|
+
if (queryWords.some((qw) => t.words.some((sw) => sw.startsWith(qw)))) {
|
|
2355
|
+
wordMatches.push(c);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2317
2359
|
const sortByPriority = (a, b) => a.priority - b.priority;
|
|
2318
2360
|
return [
|
|
2319
2361
|
...iso2Matches,
|
|
@@ -2322,14 +2364,15 @@ var getMatchedCountries = (countries, searchTokens, query) => {
|
|
|
2322
2364
|
// 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)
|
|
2323
2365
|
...dialCodeMatches.sort(sortByPriority),
|
|
2324
2366
|
...dialCodeContains.sort(sortByPriority),
|
|
2325
|
-
...initialsMatches
|
|
2367
|
+
...initialsMatches,
|
|
2368
|
+
...wordMatches
|
|
2326
2369
|
];
|
|
2327
2370
|
};
|
|
2328
2371
|
var findFirstCountryStartingWith = (countries, searchTokens, query) => {
|
|
2329
|
-
const
|
|
2372
|
+
const nameQuery = normaliseName(query);
|
|
2330
2373
|
for (const c of countries) {
|
|
2331
2374
|
const { normalisedName } = searchTokens.get(c.iso2);
|
|
2332
|
-
if (normalisedName.startsWith(
|
|
2375
|
+
if (normalisedName.startsWith(nameQuery)) {
|
|
2333
2376
|
return c;
|
|
2334
2377
|
}
|
|
2335
2378
|
}
|
|
@@ -2627,7 +2670,7 @@ var UI = class _UI {
|
|
|
2627
2670
|
},
|
|
2628
2671
|
searchWrapper
|
|
2629
2672
|
);
|
|
2630
|
-
this.#searchIconEl.
|
|
2673
|
+
this.#searchIconEl.appendChild(buildSearchIcon());
|
|
2631
2674
|
this.#searchInputEl = createEl(
|
|
2632
2675
|
"input",
|
|
2633
2676
|
{
|
|
@@ -2656,7 +2699,7 @@ var UI = class _UI {
|
|
|
2656
2699
|
},
|
|
2657
2700
|
searchWrapper
|
|
2658
2701
|
);
|
|
2659
|
-
this.#searchClearButtonEl.
|
|
2702
|
+
this.#searchClearButtonEl.appendChild(buildClearIcon(this.#id));
|
|
2660
2703
|
this.#searchResultsLiveRegionEl = createEl(
|
|
2661
2704
|
"span",
|
|
2662
2705
|
{ class: "iti__a11y-text" },
|
|
@@ -3156,7 +3199,7 @@ var UI = class _UI {
|
|
|
3156
3199
|
{ class: "iti__country-check", [ARIA.HIDDEN]: "true" },
|
|
3157
3200
|
newListItem
|
|
3158
3201
|
);
|
|
3159
|
-
checkIcon.
|
|
3202
|
+
checkIcon.appendChild(buildCheckIcon());
|
|
3160
3203
|
this.#selectedListItemEl = newListItem;
|
|
3161
3204
|
if (this.#options.dropdownAlwaysOpen) {
|
|
3162
3205
|
this.#highlightListItem(newListItem);
|
|
@@ -3301,20 +3344,27 @@ var UI = class _UI {
|
|
|
3301
3344
|
}
|
|
3302
3345
|
if (this.#selectedCountryEl) {
|
|
3303
3346
|
const flagClass = iso2 && showFlags ? `${CLASSES.FLAG} iti__${iso2}` : `${CLASSES.FLAG} ${CLASSES.GLOBE}`;
|
|
3304
|
-
let ariaLabel, title
|
|
3347
|
+
let ariaLabel, title;
|
|
3348
|
+
let flagContent = null;
|
|
3305
3349
|
if (iso2) {
|
|
3306
3350
|
title = name;
|
|
3307
3351
|
ariaLabel = i18n.selectedCountryAriaLabel.replace("${countryName}", name).replace("${dialCode}", `+${dialCode}`);
|
|
3308
|
-
|
|
3352
|
+
if (!showFlags) {
|
|
3353
|
+
flagContent = buildGlobeIcon();
|
|
3354
|
+
}
|
|
3309
3355
|
} else {
|
|
3310
3356
|
title = i18n.noCountrySelected;
|
|
3311
3357
|
ariaLabel = i18n.noCountrySelected;
|
|
3312
|
-
|
|
3358
|
+
flagContent = buildGlobeIcon();
|
|
3313
3359
|
}
|
|
3314
3360
|
this.#selectedFlagEl.className = flagClass;
|
|
3315
3361
|
this.#selectedCountryEl.setAttribute("title", title);
|
|
3316
3362
|
this.#selectedCountryEl.setAttribute(ARIA.LABEL, ariaLabel);
|
|
3317
|
-
|
|
3363
|
+
if (flagContent) {
|
|
3364
|
+
this.#selectedFlagEl.replaceChildren(flagContent);
|
|
3365
|
+
} else {
|
|
3366
|
+
this.#selectedFlagEl.replaceChildren();
|
|
3367
|
+
}
|
|
3318
3368
|
}
|
|
3319
3369
|
if (separateDialCode) {
|
|
3320
3370
|
const fullDialCode = dialCode ? `+${dialCode}` : "";
|
|
@@ -4633,7 +4683,7 @@ var intlTelInput = Object.assign(
|
|
|
4633
4683
|
attachUtils,
|
|
4634
4684
|
startedLoadingUtils: false,
|
|
4635
4685
|
startedLoadingAutoCountry: false,
|
|
4636
|
-
version: "28.0.
|
|
4686
|
+
version: "28.0.5",
|
|
4637
4687
|
NUMBER_FORMAT,
|
|
4638
4688
|
NUMBER_TYPE,
|
|
4639
4689
|
VALIDATION_ERROR
|