import { CountryCode as CountryCode$1 } from 'libphonenumber-js/min'; export { CountryCode } from 'libphonenumber-js/min'; import { CountryCode } from 'libphonenumber-js'; /** * Configuration options for MaskDial */ interface MaskDialOptions { /** ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'IN') */ country?: CountryCode; /** Fallback country when auto-detection fails */ defaultCountry?: CountryCode; /** Show international format with country code prefix */ international?: boolean; /** Placeholder character for unfilled digits (default: none) */ placeholder?: string; /** Called after each format operation */ onFormat?: (data: FormatData) => void; /** Called when validation state changes */ onValidate?: (isValid: boolean, isPossible: boolean) => void; /** Called when detected country changes */ onCountryChange?: (country: CountryCode | undefined) => void; } /** * Data returned after formatting a phone number */ interface FormatData { /** Formatted display value */ formatted: string; /** E.164 format (e.g., +12025551234) */ e164: string | undefined; /** National format without country code */ national: string; /** Raw digits only */ digits: string; /** Detected or specified country ISO code */ country: CountryCode | undefined; /** Is the number valid for the detected country */ isValid: boolean; /** Is the number possibly valid (less strict) */ isPossible: boolean; /** Format template (e.g., "(xxx) xxx-xxxx") */ template: string | undefined; /** Country calling code (e.g., "1" for US) */ countryCallingCode: string | undefined; } /** * Public interface for MaskDial instances */ interface MaskDialInstance { /** Get current formatted value */ getValue(): string; /** Get E.164 format (+12025551234) */ getE164(): string | undefined; /** Get national format (e.g., (202) 555-1234) */ getNational(): string; /** Get international format (e.g., +1 202 555 1234) */ getInternational(): string; /** Get raw digits only */ getDigits(): string; /** Check if number is valid */ isValid(): boolean; /** Check if number is possibly valid (less strict) */ isPossible(): boolean; /** Get detected or specified country */ getCountry(): CountryCode | undefined; /** Get country calling code */ getCountryCallingCode(): string | undefined; /** Change the country */ setCountry(country: CountryCode): void; /** Get current options */ getOptions(): MaskDialOptions; /** Update options */ setOptions(options: Partial): void; /** Remove event listeners and cleanup */ destroy(): void; } /** * Internal state for the formatter */ interface FormatterState { rawValue: string; formattedValue: string; country: CountryCode | undefined; isValid: boolean; isPossible: boolean; cursorPosition: number; } /** * Result from core formatting operation */ interface FormatResult { formatted: string; e164: string | undefined; national: string; international: string; digits: string; country: CountryCode | undefined; countryCallingCode: string | undefined; isValid: boolean; isPossible: boolean; template: string | undefined; } /** * Cursor position calculation input */ interface CursorInput { oldValue: string; newValue: string; oldCursorPosition: number; isDelete: boolean; } /** * Event types for vanilla JS adapter */ type MaskDialEventType = 'format' | 'validate' | 'countrychange'; /** * Custom event detail for format event */ interface FormatEventDetail { data: FormatData; } /** * Custom event detail for validate event */ interface ValidateEventDetail { isValid: boolean; isPossible: boolean; } /** * Custom event detail for country change event */ interface CountryChangeEventDetail { country: CountryCode | undefined; } /** * Core formatting engine - framework agnostic * Handles all phone number formatting logic without DOM dependencies */ declare class MaskDialCore { private options; private formatter; private lastFormatResult; private lastValidState; private lastCountry; constructor(options?: MaskDialOptions); /** * Normalize options with defaults */ private normalizeOptions; /** * Process input and return formatted result with cursor position */ processInput(newValue: string, oldValue?: string, oldCursorPosition?: number): { formatted: string; cursorPosition: number; data: FormatData; }; /** * Trigger appropriate callbacks based on state changes */ private triggerCallbacks; /** * Format a value without cursor calculation (for programmatic use) */ format(value: string): FormatData; /** * Get current formatted value */ getValue(): string; /** * Get E.164 format */ getE164(): string | undefined; /** * Get national format */ getNational(): string; /** * Get international format */ getInternational(): string; /** * Get raw digits */ getDigits(): string; /** * Check if current value is valid */ isValid(): boolean; /** * Check if current value is possibly valid */ isPossible(): boolean; /** * Get current country */ getCountry(): CountryCode$1 | undefined; /** * Get country calling code */ getCountryCallingCode(): string | undefined; /** * Set the country */ setCountry(country: CountryCode$1): void; /** * Get current options */ getOptions(): MaskDialOptions; /** * Update options */ setOptions(options: Partial): void; /** * Reset internal state */ reset(): void; } /** * Phone number formatter using libphonenumber-js * Provides caching for O(1) formatter instance retrieval */ declare class PhoneFormatter { private formatterCache; /** * Get or create a cached AsYouType formatter for the given country */ private getFormatter; /** * Format a phone number string */ format(input: string, country?: CountryCode$1): FormatResult; /** * Extract only digits from a string */ extractDigits(input: string): string; /** * Clear formatter cache */ clearCache(): void; } declare const phoneFormatter: PhoneFormatter; /** * Calculate the new cursor position after formatting * * Algorithm: * 1. Count digits before cursor in old value * 2. Find position in new value with same digit count * * This ensures cursor stays "with" the digits the user typed, * even when formatting characters are inserted/removed. */ declare function calculateCursorPosition(input: CursorInput): number; /** * Count the number of digit characters in a string */ declare function countDigits(str: string): number; /** * Check if a character is a digit */ declare function isDigit(char: string): boolean; /** * Get the position of the nth digit in a string * Returns -1 if there aren't enough digits */ declare function getNthDigitPosition(str: string, n: number): number; /** * Determine if the input change was a deletion */ declare function isDeleteOperation(oldValue: string, newValue: string): boolean; /** * Validation result with detailed information */ interface ValidationResult { isValid: boolean; isPossible: boolean; error?: string; } /** * Validate a phone number for a specific country */ declare function validatePhoneNumber(phoneNumber: string, country?: CountryCode$1): ValidationResult; /** * Get E.164 format if the number is valid */ declare function getE164(phoneNumber: string, country?: CountryCode$1): string | undefined; /** * Get national format */ declare function getNationalFormat(phoneNumber: string, country?: CountryCode$1): string; /** * Get international format */ declare function getInternationalFormat(phoneNumber: string, country?: CountryCode$1): string; /** * Detect the country from a phone number */ declare function detectCountry(phoneNumber: string): CountryCode$1 | undefined; /** * Check if a phone number looks like it could be international * (starts with + or 00) */ declare function isInternationalFormat(phoneNumber: string): boolean; /** * Custom event names */ declare const EVENTS: { readonly FORMAT: "maskdial:format"; readonly VALIDATE: "maskdial:validate"; readonly COUNTRY_CHANGE: "maskdial:countrychange"; }; /** * Vanilla JavaScript MaskDial class * Binds to an input element and handles phone number formatting */ declare class MaskDial implements MaskDialInstance { private element; private core; private isComposing; private handleInputBound; private handleFocusBound; private handleBlurBound; private handlePasteBound; private handleKeydownBound; private handleCompositionStartBound; private handleCompositionEndBound; constructor(element: HTMLInputElement | string, options?: MaskDialOptions); /** * Attach DOM event listeners */ private attachListeners; /** * Detach DOM event listeners */ private detachListeners; /** * Handle input event */ private handleInput; /** * Handle focus event */ private handleFocus; /** * Handle blur event */ private handleBlur; /** * Handle paste event */ private handlePaste; /** * Handle keydown for special keys */ private handleKeydown; /** * Handle composition start (IME input) */ private handleCompositionStart; /** * Handle composition end (IME input) */ private handleCompositionEnd; /** * Format the current value and update the input */ private formatValue; /** * Emit a custom event on the element */ private emitEvent; getValue(): string; getE164(): string | undefined; getNational(): string; getInternational(): string; getDigits(): string; isValid(): boolean; isPossible(): boolean; getCountry(): CountryCode$1 | undefined; getCountryCallingCode(): string | undefined; setCountry(country: CountryCode$1): void; getOptions(): MaskDialOptions; setOptions(options: Partial): void; destroy(): void; } export { type CountryChangeEventDetail, type CursorInput, EVENTS, type FormatData, type FormatEventDetail, type FormatResult, type FormatterState, MaskDial, MaskDialCore, type MaskDialEventType, type MaskDialInstance, type MaskDialOptions, PhoneFormatter, type ValidateEventDetail, calculateCursorPosition, countDigits, detectCountry, getE164, getInternationalFormat, getNationalFormat, getNthDigitPosition, isDeleteOperation, isDigit, isInternationalFormat, phoneFormatter, validatePhoneNumber };