@desource/phone-mask-vue 1.0.0 → 1.1.1
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/CHANGELOG.md +41 -0
- package/README.md +5 -2
- package/dist/index.cjs +222 -271
- package/dist/index.js +222 -271
- package/dist/index.mjs +223 -272
- package/dist/phone-mask-vue.css +64 -64
- package/dist/types/components/PhoneInput.vue.d.ts.map +1 -1
- package/dist/types/composables/internal/useTheme.d.ts.map +1 -1
- package/dist/types/composables/usePhoneMask.d.ts.map +1 -1
- package/dist/types/directives/vPhoneMask.d.ts +1 -2
- package/dist/types/directives/vPhoneMask.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -9,17 +9,17 @@ var lib = (function(exports, vue) {
|
|
|
9
9
|
const e2 = [...o2.toUpperCase()].map((t2) => (t2.codePointAt(0) ?? 0) + 127397);
|
|
10
10
|
return String.fromCodePoint(...e2);
|
|
11
11
|
};
|
|
12
|
-
const o$1 = "en", n = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
|
|
13
|
-
const t2 = e2.toLowerCase(), s2 = n.get(t2);
|
|
12
|
+
const o$1 = "en", n$1 = /* @__PURE__ */ new Map(), getDisplayNames = (e2) => {
|
|
13
|
+
const t2 = e2.toLowerCase(), s2 = n$1.get(t2);
|
|
14
14
|
if (s2) return s2;
|
|
15
15
|
const r = new Intl.DisplayNames([e2], { type: "region" });
|
|
16
|
-
if (n.size >= 10) {
|
|
17
|
-
for (const e3 of n.keys()) if (e3 !== o$1) {
|
|
18
|
-
n.delete(e3);
|
|
16
|
+
if (n$1.size >= 10) {
|
|
17
|
+
for (const e3 of n$1.keys()) if (e3 !== o$1) {
|
|
18
|
+
n$1.delete(e3);
|
|
19
19
|
break;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
return n.set(t2, r), r;
|
|
22
|
+
return n$1.set(t2, r), r;
|
|
23
23
|
}, s$1 = Object.entries(M), divideMask = (e2) => e2.split(/ (.*)/s);
|
|
24
24
|
function getCodeAndMask(e2) {
|
|
25
25
|
let t2 = "", o2 = "";
|
|
@@ -69,32 +69,32 @@ var lib = (function(exports, vue) {
|
|
|
69
69
|
MasksFull(o$1);
|
|
70
70
|
const k = countryCodeEmoji;
|
|
71
71
|
function getNavigatorLang() {
|
|
72
|
-
return
|
|
72
|
+
return globalThis.navigator?.language || "en";
|
|
73
73
|
}
|
|
74
74
|
function detectCountryFromLocale() {
|
|
75
75
|
try {
|
|
76
76
|
const t2 = getNavigatorLang();
|
|
77
77
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
78
|
+
const r2 = new Intl.Locale(t2);
|
|
79
|
+
if (r2.region) return r2.region.toUpperCase();
|
|
80
80
|
} catch {
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
82
|
+
const r = t2.split(/[-_]/);
|
|
83
|
+
if (r.length > 1) return r[1]?.toUpperCase() || null;
|
|
84
84
|
} catch {
|
|
85
85
|
}
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
88
88
|
function hasCountry(t2) {
|
|
89
|
-
const
|
|
90
|
-
return t2.toUpperCase() in
|
|
89
|
+
const e2 = f;
|
|
90
|
+
return t2.toUpperCase() in e2;
|
|
91
91
|
}
|
|
92
|
-
function getCountry(
|
|
93
|
-
const n2 = MasksFullMap(
|
|
92
|
+
function getCountry(r, e2) {
|
|
93
|
+
const n2 = MasksFullMap(e2), o2 = r.toUpperCase();
|
|
94
94
|
return o2 in n2 ? { id: o2, ...n2[o2] } : { id: "US", ...n2.US };
|
|
95
95
|
}
|
|
96
|
-
function parseCountryCode(t2,
|
|
97
|
-
return t2 && hasCountry(t2) ? t2.toUpperCase() :
|
|
96
|
+
function parseCountryCode(t2, r) {
|
|
97
|
+
return t2 && hasCountry(t2) ? t2.toUpperCase() : r || "";
|
|
98
98
|
}
|
|
99
99
|
function toArray(t2) {
|
|
100
100
|
return Array.isArray(t2) ? t2 : [t2];
|
|
@@ -105,147 +105,137 @@ var lib = (function(exports, vue) {
|
|
|
105
105
|
function removeCountryCodePrefix(t2) {
|
|
106
106
|
return t2.replace(/^\+\d+\s?/, "");
|
|
107
107
|
}
|
|
108
|
-
function pickMaskVariant(t2,
|
|
108
|
+
function pickMaskVariant(t2, r) {
|
|
109
|
+
if (!t2.length) return "";
|
|
109
110
|
if (1 === t2.length) return t2[0];
|
|
110
|
-
const
|
|
111
|
+
const e2 = t2.map((t3) => ({ mask: t3, count: countPlaceholders(t3) })), n2 = e2.filter((t3) => t3.count >= r).sort((t3, r2) => t3.count - r2.count);
|
|
111
112
|
if (n2.length > 0) return n2[0].mask;
|
|
112
|
-
const o2 =
|
|
113
|
+
const o2 = e2.sort((t3, r2) => r2.count - t3.count)[0];
|
|
113
114
|
return o2 ? o2.mask : t2[0];
|
|
114
115
|
}
|
|
115
|
-
function formatDigitsWithMap(t2,
|
|
116
|
-
let
|
|
116
|
+
function formatDigitsWithMap(t2, r) {
|
|
117
|
+
let e2 = "";
|
|
117
118
|
const n2 = [];
|
|
118
119
|
let o2 = 0;
|
|
119
|
-
const a =
|
|
120
|
+
const a = r.length, s2 = t2.length;
|
|
120
121
|
for (let c = 0; c < s2; c++) {
|
|
121
122
|
const s3 = t2[c];
|
|
122
123
|
if ("#" === s3) {
|
|
123
124
|
if (!(o2 < a)) break;
|
|
124
|
-
|
|
125
|
+
e2 += r[o2], n2.push(o2), o2++;
|
|
125
126
|
} else {
|
|
126
|
-
const
|
|
127
|
-
(
|
|
127
|
+
const r2 = -1 !== t2.indexOf("#", c + 1) && o2 < a;
|
|
128
|
+
(e2.length > 0 || r2) && (e2 += s3, n2.push(-1));
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
return { display:
|
|
131
|
+
return { display: e2, map: n2 };
|
|
131
132
|
}
|
|
132
|
-
function filterCountries(t2,
|
|
133
|
-
const
|
|
134
|
-
if (!
|
|
135
|
-
const n2 =
|
|
133
|
+
function filterCountries(t2, r) {
|
|
134
|
+
const e2 = r.trim().toUpperCase();
|
|
135
|
+
if (!e2) return t2;
|
|
136
|
+
const n2 = e2.replace(/\D/g, ""), o2 = n2.length > 0;
|
|
136
137
|
return t2.map((t3) => {
|
|
137
|
-
const
|
|
138
|
-
let
|
|
139
|
-
return
|
|
140
|
-
}).filter((t3) => t3.score > 0).sort((t3,
|
|
138
|
+
const r2 = t3.name.toUpperCase(), a = t3.id.toUpperCase(), s2 = t3.code.toUpperCase(), c = t3.code.replace(/\D/g, "");
|
|
139
|
+
let i = 0;
|
|
140
|
+
return r2.startsWith(e2) ? i = 1e3 : r2.includes(e2) && (i = 500), s2.startsWith(e2) ? i += 100 : s2.includes(e2) && (i += 50), a === e2 ? i += 200 : a.startsWith(e2) && (i += 150), o2 && c.startsWith(n2) ? i += 80 : o2 && c.includes(n2) && (i += 40), { country: t3, score: i };
|
|
141
|
+
}).filter((t3) => t3.score > 0).sort((t3, r2) => r2.score === t3.score ? t3.country.name.localeCompare(r2.country.name) : r2.score - t3.score).map((t3) => t3.country);
|
|
141
142
|
}
|
|
142
|
-
const
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
return e2 ? i2.slice(0, e2) : i2;
|
|
143
|
+
const e$1 = [" ", "-", "(", ")"], t = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home", "End", "Tab"], n = /[^\d\s\-()]/;
|
|
144
|
+
function removeDigitsRange(e2, t2, n2) {
|
|
145
|
+
return { newDigits: e2.slice(0, t2) + e2.slice(n2), caretDigitIndex: t2 };
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
147
|
+
function removeSelectedDigits(e2, t2, n2, i) {
|
|
148
|
+
if (n2 === i) return;
|
|
149
|
+
const r = t2.getDigitRange(e2, n2, i);
|
|
150
|
+
if (!r) return;
|
|
151
|
+
const [s2, g] = r;
|
|
152
|
+
return removeDigitsRange(e2, s2, g);
|
|
149
153
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
function extractDigits(e2, t2) {
|
|
155
|
+
const n2 = e2.replace(/\D/g, "");
|
|
156
|
+
return t2 ? n2.slice(0, t2) : n2;
|
|
157
|
+
}
|
|
158
|
+
function getSelection(e2) {
|
|
159
|
+
return e2 ? [e2.selectionStart ?? 0, e2.selectionEnd ?? 0] : [0, 0];
|
|
160
|
+
}
|
|
161
|
+
function setCaret(e2, t2) {
|
|
162
|
+
if (e2) try {
|
|
163
|
+
e2.setSelectionRange(t2, t2);
|
|
153
164
|
} catch {
|
|
154
165
|
}
|
|
155
166
|
}
|
|
156
|
-
function processBeforeInput(
|
|
157
|
-
if (!
|
|
158
|
-
const
|
|
159
|
-
"insertText" ===
|
|
167
|
+
function processBeforeInput(e2) {
|
|
168
|
+
if (!e2.target) return;
|
|
169
|
+
const t2 = e2.target, i = e2.data;
|
|
170
|
+
"insertText" === e2.inputType && i && (n.test(i) || " " === i && t2.value.endsWith(" ")) && e2.preventDefault();
|
|
160
171
|
}
|
|
161
|
-
function processInput(
|
|
162
|
-
if (!
|
|
163
|
-
const
|
|
172
|
+
function processInput(e2, t2) {
|
|
173
|
+
if (!e2.target) return;
|
|
174
|
+
const n2 = e2.target, { formatter: i } = t2, r = i.getMaxDigits(), s2 = extractDigits(n2.value, r);
|
|
164
175
|
return { newDigits: s2, caretDigitIndex: s2.length };
|
|
165
176
|
}
|
|
166
|
-
function processKeydown(
|
|
167
|
-
if (!
|
|
168
|
-
const r =
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (i2.preventDefault(), g !== a) {
|
|
190
|
-
const t2 = c.getDigitRange(s2, g, a);
|
|
191
|
-
if (t2) {
|
|
192
|
-
const [e2, i3] = t2;
|
|
193
|
-
return { newDigits: s2.slice(0, e2) + s2.slice(i3), caretDigitIndex: e2 };
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (g > 0) {
|
|
197
|
-
const e2 = r.value;
|
|
198
|
-
let i3 = g - 1;
|
|
199
|
-
for (; i3 >= 0 && t.includes(e2[i3]); ) i3--;
|
|
200
|
-
if (i3 >= 0) {
|
|
201
|
-
const t2 = c.getDigitRange(s2, i3, i3 + 1);
|
|
202
|
-
if (t2) {
|
|
203
|
-
const [e3] = t2;
|
|
204
|
-
return { newDigits: s2.slice(0, e3) + s2.slice(e3 + 1), caretDigitIndex: e3 };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
177
|
+
function processKeydown(n2, i) {
|
|
178
|
+
if (!n2.target) return;
|
|
179
|
+
const r = n2.target, { digits: s2, formatter: g } = i;
|
|
180
|
+
if ((function shouldIgnoreKeydown(e2) {
|
|
181
|
+
return e2.ctrlKey || e2.metaKey || e2.altKey || t.includes(e2.key);
|
|
182
|
+
})(n2)) return;
|
|
183
|
+
const [o2, c] = getSelection(r), a = r.value;
|
|
184
|
+
return "Backspace" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removePreviousDigit(t2, n3, i2, r2) {
|
|
185
|
+
if (r2 <= 0) return;
|
|
186
|
+
let s3 = r2 - 1;
|
|
187
|
+
for (; s3 >= 0 && e$1.includes(i2[s3]); ) s3--;
|
|
188
|
+
if (s3 < 0) return;
|
|
189
|
+
const g2 = n3.getDigitRange(t2, s3, s3 + 1);
|
|
190
|
+
if (!g2) return;
|
|
191
|
+
const [o3] = g2;
|
|
192
|
+
return removeDigitsRange(t2, o3, o3 + 1);
|
|
193
|
+
})(s2, g, a, o2)) : "Delete" === n2.key ? (n2.preventDefault(), removeSelectedDigits(s2, g, o2, c) ?? (function removeNextDigit(e2, t2, n3, i2) {
|
|
194
|
+
if (i2 >= n3.length) return;
|
|
195
|
+
const r2 = t2.getDigitRange(e2, i2, n3.length);
|
|
196
|
+
if (!r2) return;
|
|
197
|
+
const [s3] = r2;
|
|
198
|
+
return removeDigitsRange(e2, s3, s3 + 1);
|
|
199
|
+
})(s2, g, a, o2)) : void (/^\d$/.test(n2.key) ? s2.length >= g.getMaxDigits() && n2.preventDefault() : 1 === n2.key.length && n2.preventDefault());
|
|
209
200
|
}
|
|
210
|
-
function processPaste(
|
|
211
|
-
if (!
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
if (0 ===
|
|
215
|
-
const [
|
|
216
|
-
if (
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
const [
|
|
220
|
-
return { newDigits: extractDigits(
|
|
201
|
+
function processPaste(e2, t2) {
|
|
202
|
+
if (!e2.target) return;
|
|
203
|
+
e2.preventDefault();
|
|
204
|
+
const n2 = e2.target, { digits: i, formatter: r } = t2, s2 = e2.clipboardData?.getData("text") || "", g = r.getMaxDigits(), o2 = extractDigits(s2, g);
|
|
205
|
+
if (0 === o2.length) return;
|
|
206
|
+
const [c, a] = getSelection(n2);
|
|
207
|
+
if (c !== a) {
|
|
208
|
+
const e3 = r.getDigitRange(i, c, a);
|
|
209
|
+
if (e3) {
|
|
210
|
+
const [t3, n3] = e3;
|
|
211
|
+
return { newDigits: extractDigits(i.slice(0, t3) + o2 + i.slice(n3), g), caretDigitIndex: t3 + o2.length };
|
|
221
212
|
}
|
|
222
213
|
}
|
|
223
|
-
const
|
|
224
|
-
return { newDigits: extractDigits(
|
|
214
|
+
const u = r.getDigitRange(i, 0, c), l = u ? u[1] : 0;
|
|
215
|
+
return { newDigits: extractDigits(i.slice(0, l) + o2 + i.slice(l), g), caretDigitIndex: l + o2.length };
|
|
225
216
|
}
|
|
226
217
|
function createPhoneFormatter(o2) {
|
|
227
|
-
const
|
|
228
|
-
const n2 = pickMaskVariant(
|
|
218
|
+
const i = toArray(o2.mask), l = i.map((n2) => countPlaceholders(removeCountryCodePrefix(n2))), s2 = Math.max(...l), getMask = (t2) => {
|
|
219
|
+
const n2 = pickMaskVariant(i, t2);
|
|
229
220
|
return removeCountryCodePrefix(n2);
|
|
230
221
|
};
|
|
231
222
|
return { formatDisplay: (t2) => {
|
|
232
223
|
const e2 = getMask(t2.length);
|
|
233
224
|
return formatDigitsWithMap(e2, t2).display;
|
|
234
|
-
}, getMaxDigits: () =>
|
|
235
|
-
const e2 =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return r.length;
|
|
225
|
+
}, getMaxDigits: () => s2, getPlaceholder: () => getMask(0), getCaretPosition: (t2) => {
|
|
226
|
+
const e2 = Math.max(0, t2);
|
|
227
|
+
if (0 === e2) return 0;
|
|
228
|
+
const r = getMask(e2), { display: a } = formatDigitsWithMap(r, "0".repeat(e2));
|
|
229
|
+
return a.length;
|
|
240
230
|
}, getDigitRange: (t2, e2, r) => {
|
|
241
|
-
const
|
|
242
|
-
let
|
|
231
|
+
const a = getMask(t2.length), { map: o3 } = formatDigitsWithMap(a, t2);
|
|
232
|
+
let i2 = 1 / 0, l2 = -1 / 0;
|
|
243
233
|
for (let t3 = e2; t3 < r && t3 < o3.length; t3++) {
|
|
244
234
|
const e3 = o3[t3];
|
|
245
|
-
void 0 !== e3 && e3 >= 0 && (
|
|
235
|
+
void 0 !== e3 && e3 >= 0 && (i2 = Math.min(i2, e3), l2 = Math.max(l2, e3));
|
|
246
236
|
}
|
|
247
|
-
return
|
|
248
|
-
}, isComplete: (t2) =>
|
|
237
|
+
return i2 === 1 / 0 ? null : [i2, l2 + 1];
|
|
238
|
+
}, isComplete: (t2) => l.includes(t2.length) };
|
|
249
239
|
}
|
|
250
240
|
const o = "https://ipapi.co/json/", e = 1500, p = "@desource/phone-mask:geo", s = 864e5;
|
|
251
241
|
async function detectCountryFromGeoIP(t2 = o, r = e) {
|
|
@@ -289,7 +279,7 @@ var lib = (function(exports, vue) {
|
|
|
289
279
|
const locale = vue.computed(() => vue.toValue(localeOption) || getNavigatorLang());
|
|
290
280
|
const countryCode = vue.ref(parseCountryCode(vue.toValue(countryOption), "US"));
|
|
291
281
|
const country = vue.computed(() => getCountry(countryCode.value, locale.value));
|
|
292
|
-
const
|
|
282
|
+
const setCountry2 = (code) => {
|
|
293
283
|
const parsed = parseCountryCode(code);
|
|
294
284
|
if (parsed) {
|
|
295
285
|
countryCode.value = parsed;
|
|
@@ -299,14 +289,14 @@ var lib = (function(exports, vue) {
|
|
|
299
289
|
};
|
|
300
290
|
const detectCountry = async () => {
|
|
301
291
|
const geoCountry = await detectByGeoIp();
|
|
302
|
-
if (
|
|
292
|
+
if (setCountry2(geoCountry)) return;
|
|
303
293
|
const localeCountry = detectCountryFromLocale();
|
|
304
|
-
|
|
294
|
+
setCountry2(localeCountry);
|
|
305
295
|
};
|
|
306
296
|
vue.watchEffect(() => {
|
|
307
297
|
const newCountry = vue.toValue(countryOption);
|
|
308
298
|
if (newCountry && newCountry !== countryCode.value) {
|
|
309
|
-
|
|
299
|
+
setCountry2(newCountry);
|
|
310
300
|
}
|
|
311
301
|
});
|
|
312
302
|
vue.watchEffect(() => {
|
|
@@ -317,7 +307,7 @@ var lib = (function(exports, vue) {
|
|
|
317
307
|
vue.watchEffect(() => {
|
|
318
308
|
onCountryChange?.(country.value);
|
|
319
309
|
});
|
|
320
|
-
return { country, setCountry, locale };
|
|
310
|
+
return { country, setCountry: setCountry2, locale };
|
|
321
311
|
}
|
|
322
312
|
function useFormatter({
|
|
323
313
|
country,
|
|
@@ -504,8 +494,8 @@ var lib = (function(exports, vue) {
|
|
|
504
494
|
if (!rootRef.value) return;
|
|
505
495
|
const rect = rootRef.value.getBoundingClientRect();
|
|
506
496
|
dropdownStyle.value = {
|
|
507
|
-
top: `${rect.bottom +
|
|
508
|
-
left: `${rect.left +
|
|
497
|
+
top: `${rect.bottom + globalThis.scrollY + 8}px`,
|
|
498
|
+
left: `${rect.left + globalThis.scrollX}px`,
|
|
509
499
|
width: `${rect.width}px`
|
|
510
500
|
};
|
|
511
501
|
};
|
|
@@ -544,9 +534,9 @@ var lib = (function(exports, vue) {
|
|
|
544
534
|
}
|
|
545
535
|
};
|
|
546
536
|
const removeListeners = () => {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
537
|
+
globalThis.removeEventListener("resize", positionDropdown);
|
|
538
|
+
globalThis.removeEventListener("scroll", positionDropdown, true);
|
|
539
|
+
globalThis.removeEventListener("click", onDocClick, true);
|
|
550
540
|
};
|
|
551
541
|
vue.watch(hasDropdown, (dropdownExists) => {
|
|
552
542
|
if (!dropdownExists && dropdownOpen.value) {
|
|
@@ -559,9 +549,9 @@ var lib = (function(exports, vue) {
|
|
|
559
549
|
return;
|
|
560
550
|
}
|
|
561
551
|
positionDropdown();
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
552
|
+
globalThis.addEventListener("resize", positionDropdown);
|
|
553
|
+
globalThis.addEventListener("scroll", positionDropdown, true);
|
|
554
|
+
globalThis.addEventListener("click", onDocClick, true);
|
|
565
555
|
});
|
|
566
556
|
vue.onBeforeUnmount(removeListeners);
|
|
567
557
|
return {
|
|
@@ -639,15 +629,18 @@ var lib = (function(exports, vue) {
|
|
|
639
629
|
function useTheme({ theme }) {
|
|
640
630
|
const systemDark = vue.ref(false);
|
|
641
631
|
const themeClass = vue.computed(() => {
|
|
642
|
-
|
|
632
|
+
const resolvedTheme = vue.toValue(theme);
|
|
633
|
+
if (resolvedTheme === "auto") {
|
|
634
|
+
return systemDark.value ? "theme-dark" : "theme-light";
|
|
635
|
+
}
|
|
636
|
+
return `theme-${resolvedTheme}`;
|
|
643
637
|
});
|
|
644
638
|
let mq = null;
|
|
645
639
|
const handler = (e2) => {
|
|
646
640
|
systemDark.value = e2.matches;
|
|
647
641
|
};
|
|
648
642
|
vue.onBeforeMount(() => {
|
|
649
|
-
|
|
650
|
-
mq = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
|
|
643
|
+
mq = globalThis.matchMedia?.("(prefers-color-scheme: dark)") ?? null;
|
|
651
644
|
if (!mq) return;
|
|
652
645
|
systemDark.value = mq.matches;
|
|
653
646
|
mq.addEventListener("change", handler);
|
|
@@ -696,13 +689,12 @@ var lib = (function(exports, vue) {
|
|
|
696
689
|
"aria-hidden": "true"
|
|
697
690
|
};
|
|
698
691
|
const _hoisted_12 = { class: "pi-search-wrap" };
|
|
699
|
-
const _hoisted_13 = ["value", "placeholder"];
|
|
700
|
-
const _hoisted_14 = ["aria-
|
|
701
|
-
const _hoisted_15 = ["
|
|
702
|
-
const _hoisted_16 =
|
|
703
|
-
const _hoisted_17 = { class: "pi-opt-
|
|
704
|
-
const _hoisted_18 = {
|
|
705
|
-
const _hoisted_19 = {
|
|
692
|
+
const _hoisted_13 = ["value", "aria-activedescendant", "placeholder"];
|
|
693
|
+
const _hoisted_14 = ["id", "aria-selected", "title", "onClick", "onMouseenter"];
|
|
694
|
+
const _hoisted_15 = ["aria-label"];
|
|
695
|
+
const _hoisted_16 = { class: "pi-opt-name" };
|
|
696
|
+
const _hoisted_17 = { class: "pi-opt-code" };
|
|
697
|
+
const _hoisted_18 = {
|
|
706
698
|
key: 0,
|
|
707
699
|
class: "pi-empty"
|
|
708
700
|
};
|
|
@@ -737,7 +729,7 @@ var lib = (function(exports, vue) {
|
|
|
737
729
|
const onChange = (v) => {
|
|
738
730
|
model.value = v;
|
|
739
731
|
};
|
|
740
|
-
const { country, setCountry, locale } = useCountry({
|
|
732
|
+
const { country, setCountry: setCountry2, locale } = useCountry({
|
|
741
733
|
country: () => props.country,
|
|
742
734
|
locale: () => props.locale,
|
|
743
735
|
detect: () => props.detect,
|
|
@@ -767,6 +759,9 @@ var lib = (function(exports, vue) {
|
|
|
767
759
|
const dropdownRef = vue.useTemplateRef("dropdownRef");
|
|
768
760
|
const searchRef = vue.useTemplateRef("searchRef");
|
|
769
761
|
const selectorRef = vue.useTemplateRef("selectorRef");
|
|
762
|
+
const dropdownId = vue.getCurrentInstance()?.uid ?? 0;
|
|
763
|
+
const listboxId = `pi-options-${dropdownId}`;
|
|
764
|
+
const getOptionId = (idx) => `pi-option-${dropdownId}-${idx}`;
|
|
770
765
|
const inactive = vue.computed(() => props.disabled || props.readonly);
|
|
771
766
|
const incomplete = vue.computed(() => showValidationHint.value && shouldShowWarn.value);
|
|
772
767
|
const showCopyButton = vue.computed(() => props.showCopy && !isEmpty.value && !props.disabled);
|
|
@@ -798,9 +793,12 @@ var lib = (function(exports, vue) {
|
|
|
798
793
|
locale,
|
|
799
794
|
countryOption: () => props.country,
|
|
800
795
|
inactive,
|
|
801
|
-
onSelectCountry:
|
|
796
|
+
onSelectCountry: setCountry2,
|
|
802
797
|
onAfterSelect: focusInput
|
|
803
798
|
});
|
|
799
|
+
const activeOptionId = vue.computed(
|
|
800
|
+
() => dropdownOpen.value && filteredCountries.value[focusedIndex.value] ? getOptionId(focusedIndex.value) : void 0
|
|
801
|
+
);
|
|
804
802
|
const { handleBeforeInput, handleInput, handleKeydown, handlePaste } = useInputHandlers({
|
|
805
803
|
formatter,
|
|
806
804
|
digits,
|
|
@@ -1012,6 +1010,8 @@ var lib = (function(exports, vue) {
|
|
|
1012
1010
|
type: "search",
|
|
1013
1011
|
class: "pi-search",
|
|
1014
1012
|
"aria-label": "Search countries",
|
|
1013
|
+
"aria-controls": listboxId,
|
|
1014
|
+
"aria-activedescendant": activeOptionId.value,
|
|
1015
1015
|
placeholder: __props.searchPlaceholder,
|
|
1016
1016
|
onKeydown: _cache[6] || (_cache[6] = //@ts-ignore
|
|
1017
1017
|
(...args) => vue.unref(handleSearchKeydown) && vue.unref(handleSearchKeydown)(...args)),
|
|
@@ -1020,14 +1020,14 @@ var lib = (function(exports, vue) {
|
|
|
1020
1020
|
}, null, 40, _hoisted_13)
|
|
1021
1021
|
]),
|
|
1022
1022
|
vue.createElementVNode("ul", {
|
|
1023
|
+
id: listboxId,
|
|
1023
1024
|
class: "pi-options",
|
|
1024
1025
|
role: "listbox",
|
|
1025
|
-
"aria-activedescendant": `option-${vue.unref(focusedIndex)}`,
|
|
1026
1026
|
tabindex: "-1"
|
|
1027
1027
|
}, [
|
|
1028
1028
|
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(filteredCountries), (c, idx) => {
|
|
1029
1029
|
return vue.openBlock(), vue.createElementBlock("li", {
|
|
1030
|
-
id:
|
|
1030
|
+
id: getOptionId(idx),
|
|
1031
1031
|
key: c.id,
|
|
1032
1032
|
role: "option",
|
|
1033
1033
|
class: vue.normalizeClass([
|
|
@@ -1050,13 +1050,13 @@ var lib = (function(exports, vue) {
|
|
|
1050
1050
|
vue.renderSlot(_ctx.$slots, "flag", { country: c }, () => [
|
|
1051
1051
|
vue.createTextVNode(vue.toDisplayString(c.flag), 1)
|
|
1052
1052
|
], true)
|
|
1053
|
-
], 8,
|
|
1054
|
-
vue.createElementVNode("span",
|
|
1055
|
-
vue.createElementVNode("span",
|
|
1056
|
-
], 42,
|
|
1053
|
+
], 8, _hoisted_15),
|
|
1054
|
+
vue.createElementVNode("span", _hoisted_16, vue.toDisplayString(c.name), 1),
|
|
1055
|
+
vue.createElementVNode("span", _hoisted_17, vue.toDisplayString(c.code), 1)
|
|
1056
|
+
], 42, _hoisted_14);
|
|
1057
1057
|
}), 128)),
|
|
1058
|
-
vue.unref(filteredCountries).length === 0 ? (vue.openBlock(), vue.createElementBlock("li",
|
|
1059
|
-
]
|
|
1058
|
+
vue.unref(filteredCountries).length === 0 ? (vue.openBlock(), vue.createElementBlock("li", _hoisted_18, vue.toDisplayString(__props.noResultsText), 1)) : vue.createCommentVNode("", true)
|
|
1059
|
+
])
|
|
1060
1060
|
], 6)) : vue.createCommentVNode("", true)
|
|
1061
1061
|
]),
|
|
1062
1062
|
_: 3
|
|
@@ -1081,47 +1081,18 @@ var lib = (function(exports, vue) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
return target;
|
|
1083
1083
|
};
|
|
1084
|
-
const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
options = { country: value };
|
|
1090
|
-
} else if (typeof value === "object" && value !== null) {
|
|
1091
|
-
options = value;
|
|
1092
|
-
}
|
|
1093
|
-
const locale = options.locale || getNavigatorLang();
|
|
1094
|
-
let country;
|
|
1095
|
-
if (options.country) {
|
|
1096
|
-
country = getCountry(options.country, locale);
|
|
1097
|
-
} else if (options.detect) {
|
|
1098
|
-
const geoCountry = await detectCountryFromGeoIP();
|
|
1099
|
-
if (geoCountry) {
|
|
1100
|
-
country = getCountry(geoCountry, locale);
|
|
1101
|
-
} else {
|
|
1102
|
-
const localeCountry = detectCountryFromLocale();
|
|
1103
|
-
if (localeCountry) {
|
|
1104
|
-
country = getCountry(localeCountry, locale);
|
|
1105
|
-
} else {
|
|
1106
|
-
country = getCountry("US", locale);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
} else {
|
|
1110
|
-
country = getCountry("US", locale);
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
country,
|
|
1114
|
-
formatter: createPhoneFormatter(country),
|
|
1115
|
-
digits: "",
|
|
1116
|
-
locale,
|
|
1117
|
-
options
|
|
1118
|
-
};
|
|
1084
|
+
const PhoneInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d730aa54"]]);
|
|
1085
|
+
function parseParams(params) {
|
|
1086
|
+
if (typeof params === "string") return { country: params };
|
|
1087
|
+
if (params && typeof params === "object") return params;
|
|
1088
|
+
return {};
|
|
1119
1089
|
}
|
|
1120
|
-
function
|
|
1090
|
+
function updateDigits(el, state, digits) {
|
|
1091
|
+
state.digits = digits;
|
|
1121
1092
|
el.value = state.formatter.formatDisplay(state.digits);
|
|
1122
1093
|
if (state.options.onChange) {
|
|
1123
|
-
const fullNumberFormatted = `${state.country.code} ${el.value}
|
|
1124
|
-
const fullNumber = `${state.country.code}${state.digits}
|
|
1094
|
+
const fullNumberFormatted = el.value ? `${state.country.code} ${el.value}` : "";
|
|
1095
|
+
const fullNumber = state.digits ? `${state.country.code}${state.digits}` : "";
|
|
1125
1096
|
state.options.onChange({
|
|
1126
1097
|
full: fullNumber,
|
|
1127
1098
|
fullFormatted: fullNumberFormatted,
|
|
@@ -1129,113 +1100,92 @@ var lib = (function(exports, vue) {
|
|
|
1129
1100
|
});
|
|
1130
1101
|
}
|
|
1131
1102
|
}
|
|
1132
|
-
function
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
|
|
1140
|
-
setCaret(el, pos);
|
|
1141
|
-
});
|
|
1142
|
-
};
|
|
1103
|
+
function checkDigitsUpdate(el, state) {
|
|
1104
|
+
const maxDigits = state.formatter.getMaxDigits();
|
|
1105
|
+
const digits = extractDigits(el.value, maxDigits);
|
|
1106
|
+
const displayValue = state.formatter.formatDisplay(digits);
|
|
1107
|
+
if (digits !== state.digits || el.value !== displayValue) {
|
|
1108
|
+
updateDigits(el, state, digits);
|
|
1109
|
+
}
|
|
1143
1110
|
}
|
|
1144
|
-
function
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
if (!result) return;
|
|
1151
|
-
state.digits = result.newDigits;
|
|
1152
|
-
updateDisplay(el, state);
|
|
1153
|
-
vue.nextTick(() => {
|
|
1154
|
-
const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
|
|
1155
|
-
setCaret(el, pos);
|
|
1156
|
-
});
|
|
1157
|
-
};
|
|
1111
|
+
function checkCountryUpdate(el, state) {
|
|
1112
|
+
const oldCountry = state.country.id;
|
|
1113
|
+
const newCountry = parseCountryCode(state.options.country);
|
|
1114
|
+
if (newCountry && newCountry !== oldCountry) {
|
|
1115
|
+
setCountry(el, state, newCountry);
|
|
1116
|
+
}
|
|
1158
1117
|
}
|
|
1159
|
-
function
|
|
1118
|
+
function createHandler(el, state, handler) {
|
|
1160
1119
|
return (e2) => {
|
|
1161
|
-
const result =
|
|
1162
|
-
digits: state.digits,
|
|
1163
|
-
formatter: state.formatter
|
|
1164
|
-
});
|
|
1120
|
+
const result = handler(e2, state);
|
|
1165
1121
|
if (!result) return;
|
|
1166
|
-
state
|
|
1167
|
-
updateDisplay(el, state);
|
|
1122
|
+
updateDigits(el, state, result.newDigits);
|
|
1168
1123
|
vue.nextTick(() => {
|
|
1169
1124
|
const pos = state.formatter.getCaretPosition(result.caretDigitIndex);
|
|
1170
1125
|
setCaret(el, pos);
|
|
1171
1126
|
});
|
|
1172
1127
|
};
|
|
1173
1128
|
}
|
|
1174
|
-
async function
|
|
1175
|
-
const
|
|
1129
|
+
async function detectInitialCountry(options) {
|
|
1130
|
+
const countryOption = parseCountryCode(options.country);
|
|
1131
|
+
if (countryOption) return countryOption;
|
|
1132
|
+
if (options.detect) {
|
|
1133
|
+
const geoCountry = parseCountryCode(await detectByGeoIp());
|
|
1134
|
+
if (geoCountry) return geoCountry;
|
|
1135
|
+
const localeCountry = parseCountryCode(detectCountryFromLocale());
|
|
1136
|
+
if (localeCountry) return localeCountry;
|
|
1137
|
+
}
|
|
1138
|
+
return "US";
|
|
1139
|
+
}
|
|
1140
|
+
function setCountry(el, state, newCountryCode) {
|
|
1141
|
+
const parsed = parseCountryCode(newCountryCode);
|
|
1142
|
+
if (!parsed) return;
|
|
1143
|
+
const newCountry = getCountry(parsed, state.locale);
|
|
1176
1144
|
state.country = newCountry;
|
|
1145
|
+
state.options.onCountryChange?.(newCountry);
|
|
1177
1146
|
state.formatter = createPhoneFormatter(newCountry);
|
|
1178
1147
|
el.placeholder = state.formatter.getPlaceholder();
|
|
1179
|
-
|
|
1180
|
-
if (state.digits.length > maxDigits) {
|
|
1181
|
-
state.digits = state.digits.slice(0, maxDigits);
|
|
1182
|
-
}
|
|
1183
|
-
updateDisplay(el, state);
|
|
1184
|
-
if (state.options.onCountryChange) {
|
|
1185
|
-
state.options.onCountryChange(newCountry);
|
|
1186
|
-
}
|
|
1148
|
+
checkDigitsUpdate(el, state);
|
|
1187
1149
|
}
|
|
1188
1150
|
const vPhoneMask = {
|
|
1189
|
-
|
|
1151
|
+
mounted(el, binding) {
|
|
1190
1152
|
if (el.tagName !== "INPUT") {
|
|
1191
1153
|
console.warn("[v-phone-mask] Directive can only be used on input elements");
|
|
1192
1154
|
return;
|
|
1193
1155
|
}
|
|
1194
1156
|
el.setAttribute("type", "tel");
|
|
1195
1157
|
el.setAttribute("inputmode", "tel");
|
|
1196
|
-
|
|
1158
|
+
el.setAttribute("placeholder", "");
|
|
1159
|
+
const options = parseParams(binding.value);
|
|
1160
|
+
const locale = options.locale || getNavigatorLang();
|
|
1161
|
+
const country = getCountry(parseCountryCode(options.country, "US"), locale);
|
|
1162
|
+
const state = {
|
|
1163
|
+
country,
|
|
1164
|
+
formatter: createPhoneFormatter(country),
|
|
1165
|
+
digits: "",
|
|
1166
|
+
locale,
|
|
1167
|
+
options
|
|
1168
|
+
};
|
|
1197
1169
|
el.__phoneMaskState = state;
|
|
1198
|
-
state.inputHandler =
|
|
1199
|
-
state.keydownHandler =
|
|
1200
|
-
state.pasteHandler =
|
|
1170
|
+
state.inputHandler = createHandler(el, state, processInput);
|
|
1171
|
+
state.keydownHandler = createHandler(el, state, processKeydown);
|
|
1172
|
+
state.pasteHandler = createHandler(el, state, processPaste);
|
|
1201
1173
|
state.beforeInputHandler = processBeforeInput;
|
|
1202
1174
|
el.addEventListener("beforeinput", state.beforeInputHandler);
|
|
1203
1175
|
el.addEventListener("input", state.inputHandler);
|
|
1204
1176
|
el.addEventListener("keydown", state.keydownHandler);
|
|
1205
1177
|
el.addEventListener("paste", state.pasteHandler);
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
|
-
if (el.value) {
|
|
1211
|
-
const maxDigits = state.formatter.getMaxDigits();
|
|
1212
|
-
state.digits = extractDigits(el.value, maxDigits);
|
|
1213
|
-
updateDisplay(el, state);
|
|
1214
|
-
}
|
|
1178
|
+
detectInitialCountry(options).then((countryCode) => {
|
|
1179
|
+
if (el.__phoneMaskState !== state) return;
|
|
1180
|
+
setCountry(el, state, countryCode);
|
|
1181
|
+
});
|
|
1215
1182
|
},
|
|
1216
|
-
|
|
1183
|
+
updated(el, binding) {
|
|
1217
1184
|
const state = el.__phoneMaskState;
|
|
1218
1185
|
if (!state) return;
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
newOptions = { country: value };
|
|
1223
|
-
} else if (typeof value === "object" && value !== null) {
|
|
1224
|
-
newOptions = value;
|
|
1225
|
-
}
|
|
1226
|
-
const oldCountry = state.options.country;
|
|
1227
|
-
state.options = newOptions;
|
|
1228
|
-
const newCountry = newOptions.country;
|
|
1229
|
-
if (newCountry && newCountry !== oldCountry) {
|
|
1230
|
-
await updateCountry(el, state, newCountry);
|
|
1231
|
-
}
|
|
1232
|
-
const maxDigits = state.formatter.getMaxDigits();
|
|
1233
|
-
const newDigits = extractDigits(el.value, maxDigits);
|
|
1234
|
-
const normalizedDisplay = state.formatter.formatDisplay(newDigits);
|
|
1235
|
-
if (newDigits !== state.digits || el.value !== normalizedDisplay) {
|
|
1236
|
-
state.digits = newDigits;
|
|
1237
|
-
updateDisplay(el, state);
|
|
1238
|
-
}
|
|
1186
|
+
state.options = parseParams(binding.value);
|
|
1187
|
+
checkCountryUpdate(el, state);
|
|
1188
|
+
checkDigitsUpdate(el, state);
|
|
1239
1189
|
},
|
|
1240
1190
|
unmounted(el) {
|
|
1241
1191
|
const state = el.__phoneMaskState;
|
|
@@ -1249,7 +1199,7 @@ var lib = (function(exports, vue) {
|
|
|
1249
1199
|
};
|
|
1250
1200
|
function usePhoneMask(options) {
|
|
1251
1201
|
const inputRef = vue.shallowRef(null);
|
|
1252
|
-
const { country, setCountry } = useCountry({
|
|
1202
|
+
const { country, setCountry: setCountry2 } = useCountry({
|
|
1253
1203
|
country: options.country,
|
|
1254
1204
|
locale: options.locale,
|
|
1255
1205
|
detect: options.detect,
|
|
@@ -1313,13 +1263,14 @@ var lib = (function(exports, vue) {
|
|
|
1313
1263
|
return {
|
|
1314
1264
|
inputRef,
|
|
1315
1265
|
digits,
|
|
1266
|
+
formatter,
|
|
1316
1267
|
full,
|
|
1317
1268
|
fullFormatted,
|
|
1318
1269
|
isComplete,
|
|
1319
1270
|
isEmpty,
|
|
1320
1271
|
shouldShowWarn,
|
|
1321
1272
|
country,
|
|
1322
|
-
setCountry,
|
|
1273
|
+
setCountry: setCountry2,
|
|
1323
1274
|
clear
|
|
1324
1275
|
};
|
|
1325
1276
|
}
|
|
@@ -1344,7 +1295,7 @@ var lib = (function(exports, vue) {
|
|
|
1344
1295
|
exports.install = install;
|
|
1345
1296
|
exports.usePhoneMask = usePhoneMask;
|
|
1346
1297
|
exports.vPhoneMask = vPhoneMask;
|
|
1347
|
-
exports.vPhoneMaskSetCountry =
|
|
1298
|
+
exports.vPhoneMaskSetCountry = setCountry;
|
|
1348
1299
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
1349
1300
|
return exports;
|
|
1350
1301
|
})({}, Vue);
|