Realtime Typing
Lipi Lekhika also has a mechanism to implement realtime typing. It is based on the core transliteration functionality. On every the algorithm compares with the previus output and returns a diff. That diff contains the text to add and characters to delete. The API is same in all languages. The only difference is in naming conventions (snake_case or camelCase).
createTypingContext
Section titled “createTypingContext”import { createTypingContext } from 'lipilekhika/typing';const ctx = createTypingContext('Devanagari');A new context should be created for a new typing script.Returns a closure which has these methods:
ready: Await once, then usetakeKeyInputfor best typing latency.clearContext: Clears all internal states and contextstakeKeyInput: Accepts character-by-character input and returns the diffupdateUseNativeNumerals: Updates the use of native numerals in transliteration/typingupdateIncludeInherentVowel: Updates the include inherent vowel in transliteration/typing
Custom Typing Options
Section titled “Custom Typing Options”You can also pass custom options. Below are default values usage
import { createTypingContext } from 'lipilekhika/typing';const ctx = createTypingContext('Devanagari', { autoContextClearTimeMs: 4500, useNativeNumerals: true, // use native numerals. Example: 10 -> १० includeInherentVowel: false // no inherent vowel by default. Example: k -> क्});autoContextClearTimeMs: The time in milliseconds after which the context will be cleared automaticallyuseNativeNumerals: Use native numerals in typingincludeInherentVowel: Include inherent vowel in typing. This is the schwa deletion property.
Additional Typing Utilities
Section titled “Additional Typing Utilities”getScriptKramaData
Section titled “getScriptKramaData”Returns the sequential character array (krama) for a script with type information. Especially useful for Brahmic scripts, as they have a direct correlation in their character ordering.
import { getScriptKramaData } from 'lipilekhika/typing';
const kramaData = await getScriptKramaData('Devanagari');// Returns: [text: string, type: 'svara' | 'vyanjana' | 'anya' | 'mAtrA'][]// Example: [['अ', 'svara'], ['आ', 'svara'], ['क', 'vyanjana'], ...]This function can be used to compare character sets across scripts:
const [devanagariKrama, teluguKrama] = await Promise.all([ getScriptKramaData('Devanagari'), getScriptKramaData('Telugu')]);
// Compare corresponding charactersconsole.log(devanagariKrama[0]); // ['अ', 'svara']console.log(teluguKrama[0]); // ['అ', 'svara']getScriptTypingDataMap
Section titled “getScriptTypingDataMap”Returns detailed typing mappings for a script, including keyboard shortcuts for each character.
import { getScriptTypingDataMap } from 'lipilekhika/typing';
const typingMap = await getScriptTypingDataMap('Telugu');
// Returns an object with:// - common_krama_map: Common characters with keyboard mappings// - script_specific_krama_map: Script-specific characters with mappings// Each entry is a tuple: [character, type, [keyboard_mappings]]This function is primarily useful for:
- Building typing helper/reference UIs
- Showing keyboard shortcuts to users
- Creating visual typing guides
Note : Both functions exclude the Normal script and will throw an error if called with it.