UNPKG

anvim

Version:

ANVIM - A New Vietnamese Input Method (AVIM-compatible Vietnamese input engine in TypeScript)

150 lines (149 loc) 4.53 kB
/** * ANVIM - A New Vietnamese Input Method * Direct TypeScript migration of AVIM.js (A Vietnamese Input Method) * * Based on AVIM JavaScript Vietnamese Input Method by Hieu Tran Dang * Migrated to TypeScript while preserving exact logic and behavior */ export interface AvimConfig { method: number; onOff: number; ckSpell: number; oldAccent: number; } export type VietnameseInputMethod = "AUTO" | "TELEX" | "VNI" | "VIQR" | "VIQR*" | "OFF"; export declare class AnvimEngine { private whit; private skey; private db1; private ds1; private os1; private ob1; private mocs1; private mocb1; private trangs1; private trangb1; private as1; private ab1; private es1; private eb1; private english; private lowen; private arA; private mocrA; private erA; private orA; private aA; private oA; private mocA; private trangA; private eA; private skey2; private DAWEO; private SFJRX; private S; private F; private J; private R; private X; private Z; private D; private moc; private trang; private A; private E; private O; private tw5; private config; constructor(config?: Partial<AvimConfig>); private fcc; private up; private nan; private getSF; /** * Return Unicode code points for tone-mark substitutions given a tone key. * Mirrors AVIM tables for S/F/J/R/X. */ private retKC; /** * Build the set of all code points that represent any tone marks excluding * the current one (when provided). Used for stripping tones. */ private repSign; /** * Remove tone marks from a word, mapping marked characters back to base. */ private unV; /** * Convert Vietnamese base characters to ASCII-like placeholders per AVIM. */ private unV2; /** * Map DAWEO (A/E/O + horn/mark) combinations for VIQR/VNI paths. */ private DAWEOF; /** * Spell checker hook (disabled, preserved for compatibility). */ private ckspell; /** * Core locator: determine position in word to apply transformation for key k * given the method-specific vowel set sf. */ private findC; /** * Transform character at located position according to mapping tables. */ private tr; /** * Return Unicode code point to replace character at pos with tone k. */ private retUni; /** * Single replacement: apply tone or diacritic for one letter. */ private sr; /** Determine which tone key (S/F/R/X/J) is currently applied in word w */ private detectToneKey; /** Normalize tone placement within the last word by reapplying the detected tone * after removing existing tone marks. This leverages the original findC logic, * avoiding any hard-coded triphthong lists. */ private normalizeTonePlacement; /** * Configure method-specific keys and markers for TELEX/VNI/VIQR variants. */ private setupForMethod; /** * Main AVIM transformation for a prefix w and typed key k under mapping a. */ private main; /** Utility: does word contain any character from set? */ private hasCharFromSet; /** Utility: does word contain any tone mark? */ private hasTone; /** Map an A/E/O/W/D key to its diacritic character set for toggle detection. */ private diacriticSetForKey; /** Flush a collected word using a fresh engine (avoid cross-word state). */ private flushWord; /** Process full text by splitting on spaces and flushing per word. */ processText(input: string): string; /** Process a full word by simulating keystrokes for each character. */ processWord(word: string): string; /** * Process a single keystroke applied to the current prefix (closer to AVIM's * real-time behavior). This method also implements two ergonomic * improvements: * - Incremental uo + w => ươ composition preserving case. * - Long-distance horn composition when uo is followed by consonants. * * These improvements are designed to be backward compatible with AVIM. */ processWithKey(prefix: string, key: string): string; setMethod(method: number): void; setMethodByString(method: VietnameseInputMethod): void; setEnabled(enabled: boolean): void; getMethod(): number; getMethodString(): VietnameseInputMethod; isEnabled(): boolean; }