@alikhalilll/a-tel-input 1.0.2 → 1.1.0

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.
Files changed (39) hide show
  1. package/README.md +585 -72
  2. package/dist/_chunks/types.d.ts +661 -0
  3. package/dist/_chunks/types.js +52 -0
  4. package/dist/_chunks/types.js.map +1 -0
  5. package/dist/_chunks/usePhoneValidation.js +539 -0
  6. package/dist/_chunks/usePhoneValidation.js.map +1 -0
  7. package/dist/index.cjs +444 -683
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +122 -587
  10. package/dist/index.d.ts +122 -587
  11. package/dist/index.js +427 -646
  12. package/dist/index.js.map +1 -1
  13. package/dist/styles.css +3 -2
  14. package/dist/vee-validate/index.cjs +113 -0
  15. package/dist/vee-validate/index.cjs.map +1 -0
  16. package/dist/vee-validate/index.d.cts +86 -0
  17. package/dist/vee-validate/index.d.ts +86 -0
  18. package/dist/vee-validate/index.js +112 -0
  19. package/dist/vee-validate/index.js.map +1 -0
  20. package/dist/zod/index.cjs +211 -0
  21. package/dist/zod/index.cjs.map +1 -0
  22. package/dist/zod/index.d.cts +65 -0
  23. package/dist/zod/index.d.ts +65 -0
  24. package/dist/zod/index.js +208 -0
  25. package/dist/zod/index.js.map +1 -0
  26. package/package.json +33 -3
  27. package/src/components/ATelInput.vue +206 -66
  28. package/src/composables/useCountryDetection.ts +28 -11
  29. package/src/composables/useCountryMatching.ts +160 -20
  30. package/src/composables/useCountrySelection.ts +71 -0
  31. package/src/composables/usePhoneValidation.ts +81 -18
  32. package/src/composables/useSyncedModel.ts +80 -0
  33. package/src/composables/useTelInputValidation.ts +50 -11
  34. package/src/index.ts +2 -0
  35. package/src/types.ts +80 -0
  36. package/src/vee-validate/index.ts +2 -0
  37. package/src/vee-validate/useTelField.ts +202 -0
  38. package/src/zod/index.ts +259 -0
  39. package/web-types.json +44 -1
@@ -0,0 +1,661 @@
1
+ import { ComputedRef, HTMLAttributes, Ref } from "vue";
2
+ import { VariantProps } from "class-variance-authority";
3
+
4
+ //#region src/composables/useCountryDetection.d.ts
5
+ type DetectionStrategy = 'auto' | 'locale' | 'none';
6
+ interface DetectCountryOptions {
7
+ /**
8
+ * - `'auto'` — try IP geolocation first, then timezone, then `navigator.language`, then default.
9
+ * - `'locale'` — skip the network call, use timezone + locale only.
10
+ * - `'none'` — return `defaultCountry` immediately.
11
+ */
12
+ strategy?: DetectionStrategy;
13
+ /** Endpoint returning a JSON body with a `country_code` (or `country`) field. */
14
+ ipEndpoint?: string;
15
+ /** Fallback ISO2 used when every step fails. */
16
+ defaultCountry?: string;
17
+ /** Abort the IP request after this many ms. */
18
+ timeoutMs?: number;
19
+ /** Persist the resolved country in sessionStorage so re-mounts within the session skip detection. */
20
+ cache?: boolean;
21
+ }
22
+ /**
23
+ * Imperative API. Use this when you want to call detection from outside Vue (e.g. inside a
24
+ * non-component composable, server middleware, or unit test).
25
+ */
26
+ declare function detectCountry(opts?: DetectCountryOptions): Promise<string>;
27
+ interface UseCountryDetectionReturn {
28
+ /** Resolved ISO2 code. Initially `null` until detection completes. */
29
+ country: Ref<string | null>;
30
+ /** True while detection is in flight. */
31
+ isLoading: Ref<boolean>;
32
+ /** Manually re-run detection (e.g. after the user changes their VPN). */
33
+ refresh: () => Promise<string>;
34
+ }
35
+ /**
36
+ * Reactive wrapper. Kicks off detection in `onMounted` so SSR renders an empty value and the
37
+ * client patches in the real country once resolved.
38
+ */
39
+ declare function useCountryDetection(opts?: DetectCountryOptions): UseCountryDetectionReturn;
40
+ //#endregion
41
+ //#region src/composables/usePhoneValidation.d.ts
42
+ interface RestCountry {
43
+ name?: {
44
+ common?: string;
45
+ };
46
+ cca2?: string;
47
+ idd?: {
48
+ root?: string;
49
+ suffixes?: string[];
50
+ };
51
+ flags?: {
52
+ png?: string;
53
+ svg?: string;
54
+ };
55
+ }
56
+ interface CountryOption<T = RestCountry> {
57
+ /** Display label, e.g. "Egypt (+20)". */
58
+ label: string;
59
+ /** Stable unique ID — the ISO 3166-1 alpha-2 code, e.g. "EG". */
60
+ value: string;
61
+ /** Precomputed normalized string for fast substring search. */
62
+ search_key: string;
63
+ raw_data: {
64
+ iso2: string;
65
+ dial_code: string;
66
+ dial_digits: string;
67
+ name: string;
68
+ flag: string | null;
69
+ source: 'restcountries' | 'fallback';
70
+ original: T;
71
+ };
72
+ }
73
+ interface PhoneRequiredInfo {
74
+ iso2: string;
75
+ dial_code: string;
76
+ /** Empty by default — consumer passes a placeholder via the component prop. */
77
+ placeholder: string;
78
+ example_national: string;
79
+ example_e164: string;
80
+ national_number_length: {
81
+ min: number | null;
82
+ max: number | null;
83
+ };
84
+ format_hint: string;
85
+ }
86
+ type PhoneValidationReason = 'missing_country' | 'country_not_supported' | 'phone_has_non_digits' | 'too_short' | 'too_long' | 'invalid_phone' | 'parse_failed';
87
+ interface PhoneValidationResult {
88
+ ok: boolean;
89
+ reason: PhoneValidationReason | null;
90
+ country: {
91
+ iso2: string;
92
+ dial_code: string;
93
+ } | null;
94
+ phone: {
95
+ raw: string | null;
96
+ digits: string;
97
+ };
98
+ full_phone: string | null;
99
+ required: PhoneRequiredInfo | null;
100
+ details?: Record<string, unknown>;
101
+ }
102
+ type ValidateArgs = {
103
+ country: {
104
+ iso2: string;
105
+ dial_code?: string;
106
+ } | null | undefined;
107
+ phone?: undefined; /** BCP-47 locale — localizes the numerals in the returned `required.format_hint`. */
108
+ locale?: string;
109
+ } | {
110
+ country: {
111
+ iso2: string;
112
+ dial_code?: string;
113
+ } | null | undefined;
114
+ phone: string | null; /** BCP-47 locale — localizes the numerals in the returned `required.format_hint`. */
115
+ locale?: string;
116
+ };
117
+ /**
118
+ * Return a copy of the country list with display names localized to `locale` via
119
+ * `Intl.DisplayNames`. `search_key` is rebuilt (keeping the English name too) so search
120
+ * still matches either spelling. Unknown locales / regions fall back to the English name.
121
+ */
122
+ declare function localizeCountries(list: CountryOption[], locale?: string): CountryOption[];
123
+ interface UsePhoneValidationReturn {
124
+ countries: Ref<CountryOption[]>;
125
+ isCountriesLoading: Ref<boolean>;
126
+ getCountries(options?: {
127
+ force?: boolean;
128
+ }): Promise<CountryOption[]>;
129
+ searchCountries(keyword: string, limit?: number): CountryOption[];
130
+ getCountryByValue(value: string): CountryOption | null;
131
+ getCountriesByDial(dial: string): CountryOption[];
132
+ getRequiredInfo(country: {
133
+ iso2: string;
134
+ dial_code?: string;
135
+ }, locale?: string): PhoneRequiredInfo | null;
136
+ validate(input: ValidateArgs): PhoneValidationResult;
137
+ }
138
+ declare function usePhoneValidation(): UsePhoneValidationReturn;
139
+ //#endregion
140
+ //#region src/composables/useTelInputValidation.d.ts
141
+ /**
142
+ * Validation surfacing facade for ATelInput.
143
+ *
144
+ * Wraps the raw `usePhoneValidation()` calls and produces the *view-layer* surface the
145
+ * component needs:
146
+ *
147
+ * - `validation` / `validationState` — the raw + simplified state of the current input.
148
+ * - `visibleValidationState` — `validationState` gated by `validateOn` + the
149
+ * `hasFinishedTyping` flag from {@link useTypingPhase}, so error tints / icons /
150
+ * messages only appear at the right moment (after typing pause, after blur, or eagerly).
151
+ * This is the value the template should bind to.
152
+ * - `errorMessage` — localised error string for the current `validation.reason`, or
153
+ * `null` when the input is empty / valid. When an external `error` is supplied
154
+ * (e.g. from VeeValidate), it wins.
155
+ * - `showError` / `showHint` — boolean computed properties for conditional rendering
156
+ * in the template; both already respect `showValidation` and the visible-state gate.
157
+ * - `selectedDialCode` — the human-readable dial prefix (`+20`, `+1`, …) for the
158
+ * selected country, used as an in-input prefix.
159
+ *
160
+ * Design notes:
161
+ *
162
+ * - The composable takes the `usePhoneValidation()` return value as a *dependency*
163
+ * rather than calling `usePhoneValidation()` itself. That function creates a fresh
164
+ * country index per invocation; calling it here would produce a second, empty index
165
+ * that never gets populated by the caller's `getCountries()` (the same bug pattern
166
+ * {@link useCountryMatching} avoids).
167
+ *
168
+ * - All inputs are `Ref` / `ComputedRef` so reactivity flows correctly. Method
169
+ * references on the validation singleton (`validate`, `getRequiredInfo`,
170
+ * `getCountryByValue`) are passed verbatim — their backing state is reactive.
171
+ */
172
+ interface UseTelInputValidationDeps {
173
+ validate: UsePhoneValidationReturn['validate'];
174
+ getRequiredInfo: UsePhoneValidationReturn['getRequiredInfo'];
175
+ getCountryByValue: UsePhoneValidationReturn['getCountryByValue'];
176
+ }
177
+ /** When to surface validation in the UI.
178
+ * - `'change'` (default) — visible state mirrors the typing-paused state. Errors light up
179
+ * a beat after the user stops typing. Best for inline forms.
180
+ * - `'blur'` — visible state stays `'idle'` until the input has been blurred at least
181
+ * once, then mirrors typing-paused state. Best for VeeValidate / form-library flows
182
+ * that validate on blur.
183
+ * - `'eager'` — visible state mirrors raw `validationState` immediately on every keystroke,
184
+ * no typing pause. Use sparingly; can feel aggressive.
185
+ */
186
+ type ATelInputValidateOn = 'change' | 'blur' | 'eager';
187
+ interface UseTelInputValidationInputs {
188
+ /** Digits-only national number model. */
189
+ phone: Ref<string>;
190
+ /** Currently selected ISO2 — empty string when no country chosen. */
191
+ selectedIso2: Ref<string>;
192
+ /** From {@link useTypingPhase} — gates visible state during the debounce window. */
193
+ hasFinishedTyping: Readonly<Ref<boolean>>;
194
+ /** Whether the input has been blurred at least once. Drives `validateOn: 'blur'`. */
195
+ hasBlurred: Readonly<Ref<boolean>>;
196
+ /** Resolved i18n messages (merged defaults + consumer overrides). */
197
+ messages: ComputedRef<TelInputMessages>;
198
+ }
199
+ interface UseTelInputValidationConfig {
200
+ /** BCP-47 locale; affects `format_hint` numeral rendering. */
201
+ locale: () => string | undefined;
202
+ /** Light up field tinting + error message line. From props. */
203
+ showValidation: () => boolean | undefined;
204
+ /** Per-reason error string overrides. From props. */
205
+ errorMessages: () => Partial<Record<PhoneValidationReason, string>> | undefined;
206
+ /** When to surface validation in the UI. Defaults to `'change'`. */
207
+ validateOn: () => ATelInputValidateOn | undefined;
208
+ /**
209
+ * Externally controlled error (from VeeValidate / Zod / a custom form layer). When set
210
+ * to a non-empty string, the component is forced into `'error'` state and surfaces this
211
+ * message regardless of internal validation. `null` / `undefined` / `''` defers to the
212
+ * internal validator.
213
+ */
214
+ externalError: () => string | null | undefined;
215
+ }
216
+ interface UseTelInputValidationReturn {
217
+ validation: ComputedRef<PhoneValidationResult>;
218
+ required: ComputedRef<PhoneRequiredInfo | null>;
219
+ validationState: ComputedRef<'idle' | 'valid' | 'error'>;
220
+ visibleValidationState: ComputedRef<'idle' | 'valid' | 'error'>;
221
+ errorMessage: ComputedRef<string | null>;
222
+ showError: ComputedRef<boolean>;
223
+ showHint: ComputedRef<boolean>;
224
+ selectedDialCode: ComputedRef<string | null>;
225
+ }
226
+ declare function useTelInputValidation(deps: UseTelInputValidationDeps, inputs: UseTelInputValidationInputs, config: UseTelInputValidationConfig): UseTelInputValidationReturn;
227
+ //#endregion
228
+ //#region src/utils/flag-url.d.ts
229
+ /**
230
+ * Default flag URL builder — flagcdn.com hosts PNG flags at multiple widths and is
231
+ * generous with caching + no API key required. Swap via the `flagUrl` prop on
232
+ * ATelInput / ACountrySelect / ACountryFlag to use any other source.
233
+ */
234
+ declare function defaultFlagUrl(iso2: string, width?: number): string;
235
+ type FlagUrlBuilder = (iso2: string, width: number) => string;
236
+ //#endregion
237
+ //#region ../AUiBase/dist/index.d.ts
238
+ //#endregion
239
+ //#region src/sizes.d.ts
240
+ /**
241
+ * Shared size scale for every interactive component in the @alikhalilll/a-* set.
242
+ *
243
+ * xs = 28px · sm = 36px · md = 43px (default) · lg = 52px · xl = 60px
244
+ *
245
+ * Use the {@link controlHeight}, {@link controlPaddingX}, {@link controlTextSize}
246
+ * maps when building a CVA variant so every component stays in lockstep.
247
+ */
248
+ type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
249
+ //#endregion
250
+ //#region src/types.d.ts
251
+ /** Alias for the shared `Size` scale — kept for backwards-friendly naming. */
252
+ type ATelInputSize = Size;
253
+ declare const aTelInputVariants: (props?: ({
254
+ size?: "xs" | "sm" | "md" | "lg" | "xl" | null | undefined;
255
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
256
+ type ATelInputVariants = VariantProps<typeof aTelInputVariants>;
257
+ /** Text direction for the field. `'auto'` (or omitting the prop) inherits from the
258
+ * nearest `[dir]` ancestor / `<html dir>`; `'ltr'` / `'rtl'` force it. */
259
+ type ATelInputDir = 'ltr' | 'rtl' | 'auto';
260
+ /**
261
+ * Every user-facing string in the tel-input UI, bundled so a consumer can localize the
262
+ * component in one prop. Each key has an English default in {@link DEFAULT_MESSAGES}.
263
+ */
264
+ interface TelInputMessages {
265
+ /** Placeholder of the country-picker search box. */
266
+ searchPlaceholder: string;
267
+ /** Shown when a search yields no countries. */
268
+ emptyText: string;
269
+ /** Shown while the country list is loading. */
270
+ loadingText: string;
271
+ /** Header of the "Suggested" group (current + recent picks). */
272
+ suggestedLabel: string;
273
+ /** Header of the full country list. */
274
+ allCountriesLabel: string;
275
+ /** Validation error text, keyed by reason. */
276
+ errorMessages: Record<PhoneValidationReason, string>;
277
+ /** Prefix of the country trigger's `aria-label`, e.g. `"Country: Egypt"`. */
278
+ countryLabel: string;
279
+ /** `aria-label` of the country trigger when no country is selected. */
280
+ selectCountryLabel: string;
281
+ /** `aria-label` of the phone input element. */
282
+ phoneInputLabel: string;
283
+ }
284
+ /** Partial override shape for the `messages` prop — every key (and every error reason) is optional. */
285
+ type TelInputMessagesInput = Partial<Omit<TelInputMessages, 'errorMessages'>> & {
286
+ errorMessages?: Partial<Record<PhoneValidationReason, string>>;
287
+ };
288
+ interface ATelInputProps {
289
+ class?: HTMLAttributes['class'];
290
+ /**
291
+ * Default `v-model` — the canonical **E.164** string (e.g. `'+201066105963'`).
292
+ *
293
+ * Reads + writes the full international number as a single value. Designed to drop
294
+ * straight into VeeValidate's `<Field v-slot="{ field }">` pattern (use
295
+ * `v-bind="field"`), native `<form>` submission, or any `v-model="phoneE164"` consumer.
296
+ *
297
+ * Stays in sync with the split `v-model:phone` + `v-model:country` contract — use
298
+ * either, or both.
299
+ */
300
+ modelValue?: string;
301
+ /**
302
+ * Forwarded to the inner `<input name="">`. Set this when participating in a native
303
+ * `<form>` submission, or when a form library (VeeValidate, etc.) wants a stable name.
304
+ */
305
+ name?: string;
306
+ /**
307
+ * Externally controlled error message. When set to a non-empty string the component
308
+ * is forced into the error visual state and renders this message via the `#error`
309
+ * slot — overriding internal libphonenumber validation. Wire this from VeeValidate,
310
+ * Zod, an async server check ("this phone is already registered"), or any custom
311
+ * validation layer.
312
+ *
313
+ * Pass `null` / `undefined` / `''` to defer to internal validation.
314
+ */
315
+ error?: string | null;
316
+ /**
317
+ * `true` while an async validation is in flight (e.g. a server-side uniqueness
318
+ * check). Renders a small spinner inside the field and sets `aria-busy="true"` on
319
+ * the input. Does **not** disable the field — use `loading` for that. Replace the
320
+ * spinner via the `#validating` slot.
321
+ *
322
+ * Designed to be bound to the `validating` ref returned by `useTelField()`.
323
+ */
324
+ validating?: boolean;
325
+ /**
326
+ * When to surface validation in the UI.
327
+ * - `'change'` (default) — visible state mirrors the typing-paused state.
328
+ * - `'blur'` — stays idle until the input has been blurred once (form-library friendly).
329
+ * - `'eager'` — mirror raw validation immediately, no typing pause.
330
+ */
331
+ validateOn?: ATelInputValidateOn;
332
+ placeholder?: string;
333
+ disabled?: boolean;
334
+ loading?: boolean;
335
+ size?: ATelInputSize;
336
+ /**
337
+ * Text direction. Omit (or pass `'auto'`) to inherit from the page — RTL pages get an
338
+ * RTL field automatically. Pass `'ltr'` / `'rtl'` to force it.
339
+ */
340
+ dir?: ATelInputDir;
341
+ /**
342
+ * BCP-47 locale (e.g. `'ar'`, `'fr'`). When set, country names render localized via
343
+ * `Intl.DisplayNames` and the format hint uses the locale's numerals.
344
+ */
345
+ locale?: string;
346
+ /**
347
+ * Localized UI strings. A single bag covering the picker, validation errors, and a11y
348
+ * labels. Individual props (`searchPlaceholder`, `emptyText`, `loadingText`,
349
+ * `errorMessages`) take precedence over the matching `messages` key when both are set.
350
+ */
351
+ messages?: TelInputMessagesInput;
352
+ /**
353
+ * Whitelist of allowed dial-digit codes (no `+`), e.g. `['20', '966']`.
354
+ * Countries outside this list are still shown in the picker but rendered as disabled.
355
+ */
356
+ allowedDialCodes?: string[];
357
+ /** Light up the field's validation styling — coloured border + ring on the input and the
358
+ * error message line below — when the number is valid / invalid. Default `false`, so the
359
+ * field stays neutral and validation surfacing is left to the consumer (via the
360
+ * `validation` ref exposure). */
361
+ showValidation?: boolean;
362
+ /** Show the green check / red alert icon at the end of the field. Default `false`; opt
363
+ * in with `true`. Independent of `showValidation` — you can show the icon without the
364
+ * coloured field, or vice versa. The slots `#valid-icon` / `#error-icon` still apply. */
365
+ showValidationIcon?: boolean;
366
+ /**
367
+ * Country auto-detect strategy. Defaults to `'auto'` — try IP geolocation first, then
368
+ * timezone, then `navigator.language`, finally `defaultCountry`.
369
+ */
370
+ detectCountry?: DetectionStrategy;
371
+ /**
372
+ * Initial country. Accepts either an ISO2 code (`'EG'`) or a dial-digit string
373
+ * (`'20'`, `'+20'`). When set, the picker is visible at mount with this country
374
+ * pre-selected — overrides the hidden-until-detected default.
375
+ */
376
+ defaultCountry?: string;
377
+ /** Override the IP geolocation endpoint. Must return JSON with `country_code` or `country`. */
378
+ ipEndpoint?: string;
379
+ /** Localized strings for the country picker UI. */
380
+ searchPlaceholder?: string;
381
+ emptyText?: string;
382
+ loadingText?: string;
383
+ /** Error labels keyed by reason. Each gets a sensible English default. */
384
+ errorMessages?: Partial<Record<PhoneValidationReason, string>>;
385
+ /**
386
+ * When true, the country picker is hidden until a leading dial code is detected in the
387
+ * phone input. Every keystroke runs a longest-prefix match against known dial codes; on
388
+ * first match the picker reveals with that country and the matched dial digits are
389
+ * stripped from `phone`. Skips the onMount IP/timezone/locale detection chain.
390
+ */
391
+ detectFromInput?: boolean;
392
+ /**
393
+ * Debounce window (ms) for `detectFromInput` detection. Each keystroke schedules the
394
+ * libphonenumber parse + lookup; bursts of typing/paste collapse into a single call.
395
+ * Clearing the input is not debounced — the picker hides immediately. Default 150ms.
396
+ */
397
+ detectDebounceMs?: number;
398
+ /** Override the flag URL builder, forwarded to ACountrySelect. */
399
+ flagUrl?: (iso2: string, width: number) => string;
400
+ /** Custom search predicate, forwarded to ACountrySelect. */
401
+ searcher?: (query: string, country: CountryOption) => boolean;
402
+ /** Provide your own country list, forwarded to ACountrySelect. */
403
+ countries?: CountryOption[];
404
+ /**
405
+ * Fully custom country detection. When provided, this function runs in place of the
406
+ * built-in chain — `detectCountry`-style options are still honored but the function
407
+ * receives them and is free to ignore them.
408
+ */
409
+ detector?: (options: DetectCountryOptions) => Promise<string | null | undefined>;
410
+ /** Forwarded to ACountrySelect: classes for the popover content surface. */
411
+ contentClass?: string;
412
+ /** Forwarded to ACountrySelect: classes for the desktop popover surface. */
413
+ popoverClass?: string;
414
+ /** Forwarded to ACountrySelect: classes for the mobile drawer surface. */
415
+ drawerClass?: string;
416
+ /** Classes for the inner phone field input element. */
417
+ inputClass?: string;
418
+ /** Classes for the outer wrapper that holds country select + input. */
419
+ fieldClass?: string;
420
+ /** Classes for the helper hint line. */
421
+ hintClass?: string;
422
+ /** Classes for the error message line. */
423
+ errorClass?: string;
424
+ /**
425
+ * How page scroll is blocked while the country popover is open. Defaults to `'events'`
426
+ * (sticky-safe document-level lock). Pass `'body'` for the legacy
427
+ * `body { overflow: hidden }` lock, or `'none'` to leave page scrolling alone.
428
+ */
429
+ scrollLock?: 'events' | 'body' | 'none';
430
+ }
431
+ /**
432
+ * Props for {@link ACountryFlag} — the standalone flag image component. Renders a
433
+ * `flagcdn` image for an ISO2 code with an automatic text-badge fallback when the
434
+ * image fails to load. Surface separately so it can be used outside `ATelInput`
435
+ * (e.g., in a custom country picker).
436
+ */
437
+ interface ACountryFlagProps {
438
+ /** ISO 3166-1 alpha-2 country code, case-insensitive. */
439
+ iso2: string;
440
+ /** Pixel width served by flagcdn. 40 is crisp at retina up to ~24px wide. */
441
+ width?: number;
442
+ /** Optional explicit URL override. When set, `iso2` / `width` / `flagUrl` are ignored. */
443
+ src?: string | null;
444
+ /** Function `(iso2, width) => string` — fully replace the URL builder. */
445
+ flagUrl?: FlagUrlBuilder;
446
+ alt?: string;
447
+ class?: HTMLAttributes['class'];
448
+ }
449
+ /**
450
+ * Slot prop shape for {@link ACountryFlag}. The `empty` slot is rendered when no
451
+ * flag URL is available and no ISO2 fallback can be derived.
452
+ */
453
+ interface ACountryFlagSlots {
454
+ /** Rendered when the flag URL is unavailable and no ISO2 text fallback can be derived. */
455
+ empty?: () => unknown;
456
+ }
457
+ declare const DEFAULT_ERROR_MESSAGES: Record<PhoneValidationReason, string>;
458
+ /** English defaults for every {@link TelInputMessages} key. */
459
+ declare const DEFAULT_MESSAGES: TelInputMessages;
460
+ /**
461
+ * Merge a partial `messages` override onto the English defaults. Used internally by
462
+ * `ATelInput` to resolve a complete {@link TelInputMessages} object.
463
+ */
464
+ declare function resolveMessages(input?: TelInputMessagesInput): TelInputMessages;
465
+ /**
466
+ * Slot prop shape for {@link ATelInput}. Use to get full slot-prop type inference
467
+ * when overriding slots in a consumer template:
468
+ *
469
+ * <ATelInput #suffix="{ validationState }">…</ATelInput>
470
+ * ↑ inferred as `'idle' | 'valid' | 'error'`
471
+ *
472
+ * Or in TypeScript code:
473
+ * type SuffixProps = Parameters<NonNullable<ATelInputSlots['suffix']>>[0];
474
+ */
475
+ interface ATelInputSlots {
476
+ /** Content before the country select trigger (e.g. an icon). */
477
+ prefix?: () => unknown;
478
+ /** Content between the input and the validation icons. */
479
+ suffix?: (props: {
480
+ validationState: 'idle' | 'valid' | 'error';
481
+ validation: PhoneValidationResult;
482
+ }) => unknown;
483
+ /** Replace the green check shown when the number validates. */
484
+ 'valid-icon'?: () => unknown;
485
+ /** Replace the warning icon shown when the number fails validation. */
486
+ 'error-icon'?: (props: {
487
+ reason: string;
488
+ }) => unknown;
489
+ /** Replace the dim helper line shown below the input when empty. */
490
+ hint?: (props: {
491
+ country: string;
492
+ formatHint: string;
493
+ example: string | null;
494
+ }) => unknown;
495
+ /** Replace the error message rendered when invalid. */
496
+ error?: (props: {
497
+ message: string;
498
+ reason: string;
499
+ validation: PhoneValidationResult;
500
+ }) => unknown;
501
+ /** Forwarded to ACountrySelect — replace the trigger button. */
502
+ trigger?: (props: {
503
+ selectedCountry: CountryOption | null;
504
+ open: boolean;
505
+ sizeClasses: string;
506
+ }) => unknown;
507
+ /** Forwarded to ACountrySelect — replace the chevron. */
508
+ chevron?: (props: {
509
+ open: boolean;
510
+ }) => unknown;
511
+ /** Forwarded — replace any flag rendering. */
512
+ flag?: (props: {
513
+ country: CountryOption;
514
+ context: 'trigger' | 'item';
515
+ }) => unknown;
516
+ /** Forwarded — replace each country list row. */
517
+ item?: (props: {
518
+ country: CountryOption;
519
+ selected: boolean;
520
+ disabled: boolean;
521
+ select: () => void;
522
+ }) => unknown;
523
+ /** Forwarded — section header. */
524
+ 'group-header'?: (props: {
525
+ label: string;
526
+ group: 'suggested' | 'all';
527
+ }) => unknown;
528
+ /** Forwarded — search bar. */
529
+ search?: (props: {
530
+ value: string;
531
+ setValue: (v: string) => void;
532
+ isSearching: boolean;
533
+ }) => unknown;
534
+ loading?: () => unknown;
535
+ empty?: (props: {
536
+ query: string;
537
+ }) => unknown;
538
+ /** Replace the spinner shown in the picker slot during the debounce window. */
539
+ detecting?: () => unknown;
540
+ /** Replace the spinner shown inside the field while async validation is in flight. */
541
+ validating?: () => unknown;
542
+ }
543
+ /**
544
+ * Emit map for {@link ATelInput}. `update:phone` carries the digits-only string,
545
+ * `update:country` carries the dial-number (not ISO2). Surface for consumers who
546
+ * wire the events manually instead of via `v-model:phone` / `v-model:country`.
547
+ *
548
+ * `blur` / `focus` mirror the inner input's native events — useful for form
549
+ * libraries (VeeValidate's `handleBlur`, etc.).
550
+ */
551
+ type ATelInputEmits = {
552
+ 'update:modelValue': [value: string];
553
+ 'update:phone': [value: string];
554
+ 'update:country': [value: number | null];
555
+ blur: [event: FocusEvent];
556
+ focus: [event: FocusEvent];
557
+ };
558
+ /**
559
+ * Props for {@link ACountrySelect} — the standalone country picker. Surface
560
+ * separately so it can be used outside `ATelInput` with full type support.
561
+ */
562
+ interface ACountrySelectProps {
563
+ class?: HTMLAttributes['class'];
564
+ triggerClass?: HTMLAttributes['class'];
565
+ contentClass?: HTMLAttributes['class'];
566
+ popoverClass?: HTMLAttributes['class'];
567
+ drawerClass?: HTMLAttributes['class'];
568
+ searchPlaceholder?: string;
569
+ emptyText?: string;
570
+ loadingText?: string;
571
+ suggestedLabel?: string;
572
+ allCountriesLabel?: string;
573
+ /** ISO2 codes that are selectable. Others are listed but disabled. */
574
+ allowedDialCodes?: string[];
575
+ disabled?: boolean;
576
+ /** Drives the trigger button padding + text size. Matches ATelInput's `size`. */
577
+ size?: ATelInputSize;
578
+ /** Max items rendered under the "Suggested" header (current + recents, deduped). */
579
+ suggestedLimit?: number;
580
+ /** Cap the number of matching countries shown in search results. */
581
+ maxResults?: number;
582
+ /** Override the flag URL builder, e.g. `(iso, w) => `/flags/${iso}.svg``. */
583
+ flagUrl?: (iso2: string, width: number) => string;
584
+ /** Custom search predicate. Default: substring match on the precomputed `search_key`. */
585
+ searcher?: (query: string, country: CountryOption) => boolean;
586
+ /** Provide your own country list (bypasses the REST Countries fetch). */
587
+ countries?: CountryOption[];
588
+ /** Override the right-side kbd hints. Pass `null` to hide. */
589
+ kbdOpen?: string | null;
590
+ kbdClose?: string | null;
591
+ /** BCP-47 locale — country names render localized via `Intl.DisplayNames`. */
592
+ locale?: string;
593
+ /** Prefix of the trigger's `aria-label` when a country is selected, e.g. `"Country"`. */
594
+ countryLabel?: string;
595
+ /** Trigger's `aria-label` when no country is selected. */
596
+ selectCountryLabel?: string;
597
+ /** How page scroll is blocked while the popover is open. Default `'events'`. */
598
+ scrollLock?: 'events' | 'body' | 'none';
599
+ }
600
+ /**
601
+ * Slot prop shape for {@link ACountrySelect}. Forwarded versions of these slots
602
+ * also appear on {@link ATelInputSlots} (`trigger`, `chevron`, `flag`, `item`,
603
+ * etc.) — keep them in sync when changing one.
604
+ */
605
+ interface ACountrySelectSlots {
606
+ /** Replace the entire country picker trigger button. */
607
+ trigger?: (props: {
608
+ selectedCountry: CountryOption | null;
609
+ open: boolean;
610
+ sizeClasses: string;
611
+ }) => unknown;
612
+ /** Replace the chevron icon. */
613
+ chevron?: (props: {
614
+ open: boolean;
615
+ }) => unknown;
616
+ /** Replace just the flag rendered in the trigger and items. */
617
+ flag?: (props: {
618
+ country: CountryOption;
619
+ context: 'trigger' | 'item';
620
+ }) => unknown;
621
+ /** Replace the entire search bar (input + icon + kbd). */
622
+ search?: (props: {
623
+ value: string;
624
+ setValue: (v: string) => void;
625
+ isSearching: boolean;
626
+ }) => unknown;
627
+ /** Replace the search-bar leading icon. */
628
+ 'search-icon'?: () => unknown;
629
+ /** Replace the loading state. */
630
+ loading?: () => unknown;
631
+ /** Replace the empty/no-results state. */
632
+ empty?: (props: {
633
+ query: string;
634
+ }) => unknown;
635
+ /** Replace a section header. */
636
+ 'group-header'?: (props: {
637
+ label: string;
638
+ group: 'suggested' | 'all';
639
+ }) => unknown;
640
+ /** Replace each country list row. */
641
+ item?: (props: {
642
+ country: CountryOption;
643
+ selected: boolean;
644
+ disabled: boolean;
645
+ select: () => void;
646
+ }) => unknown;
647
+ /** Replace just the right-side check icon for the selected row. */
648
+ 'item-check'?: (props: {
649
+ country: CountryOption;
650
+ }) => unknown;
651
+ }
652
+ /**
653
+ * Emit map for {@link ACountrySelect}. The `selected` is `v-model:selected`,
654
+ * carrying the ISO2 code of the picked country.
655
+ */
656
+ type ACountrySelectEmits = {
657
+ 'update:selected': [value: string];
658
+ };
659
+ //#endregion
660
+ export { RestCountry as A, UseTelInputValidationInputs as C, PhoneRequiredInfo as D, CountryOption as E, DetectCountryOptions as F, DetectionStrategy as I, UseCountryDetectionReturn as L, ValidateArgs as M, localizeCountries as N, PhoneValidationReason as O, usePhoneValidation as P, detectCountry as R, UseTelInputValidationDeps as S, useTelInputValidation as T, resolveMessages as _, ACountrySelectSlots as a, ATelInputValidateOn as b, ATelInputProps as c, ATelInputVariants as d, DEFAULT_ERROR_MESSAGES as f, aTelInputVariants as g, TelInputMessagesInput as h, ACountrySelectProps as i, UsePhoneValidationReturn as j, PhoneValidationResult as k, ATelInputSize as l, TelInputMessages as m, ACountryFlagSlots as n, ATelInputDir as o, DEFAULT_MESSAGES as p, ACountrySelectEmits as r, ATelInputEmits as s, ACountryFlagProps as t, ATelInputSlots as u, FlagUrlBuilder as v, UseTelInputValidationReturn as w, UseTelInputValidationConfig as x, defaultFlagUrl as y, useCountryDetection as z };
661
+ //# sourceMappingURL=types.d.ts.map