### Get All Options Example Source: https://lipilekhika.in/getting-started/python Example of using `get_all_options` to fetch all available custom transliteration options between two specified scripts. The output is a list of option keys. ```python options = get_all_options('Normal', 'Devanagari') for option in options: print(option) ``` -------------------------------- ### Install Lipi Lekhika Source: https://lipilekhika.in/getting-started/go Use the go get command to add the package to your project. ```bash go get github.com/shubhattin/lipilekhika/packages/go/lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using bun Source: https://lipilekhika.in/getting-started/javascript Use this command to install the Lipi Lekhika package via bun. ```bash bun add lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using yarn Source: https://lipilekhika.in/getting-started/javascript Use this command to install the Lipi Lekhika package via yarn. ```bash yarn add lipilekhika ``` -------------------------------- ### Install lipilekhika Package Source: https://lipilekhika.in/getting-started/wasm Install the lipilekhika package using your preferred package manager. ```bash npm install lipilekhika ``` ```bash pnpm add lipilekhika ``` ```bash bun add lipilekhika ``` ```bash yarn add lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using npm Source: https://lipilekhika.in/getting-started/javascript Use this command to install the Lipi Lekhika package via npm. ```bash npm install lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using uv Source: https://lipilekhika.in/getting-started/python Install the Lipi Lekhika package using uv. Ensure you have Python 3.10 or higher. ```bash uv add lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using poetry Source: https://lipilekhika.in/getting-started/python Install the Lipi Lekhika package using poetry. Ensure you have Python 3.10 or higher. ```bash poetry add lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using pnpm Source: https://lipilekhika.in/getting-started/javascript Use this command to install the Lipi Lekhika package via pnpm. ```bash pnpm add lipilekhika ``` -------------------------------- ### Emulate typing with a context Source: https://lipilekhika.in/getting-started/python A complete implementation example for managing a text buffer using the typing context. ```python from lipilekhika.typing import create_typing_context def emulate_typing(text: str, script: str) -> str: """Emulate typing character by character.""" ctx = create_typing_context(script) result = "" for char in text: diff = ctx.take_key_input(char) # Apply the diff if diff.to_delete_chars_count > 0: result = result[:-diff.to_delete_chars_count] result += diff.diff_add_text return result # Usage output = emulate_typing("namaste", "Devanagari") print(output) # नमस्ते ``` -------------------------------- ### Preload Script Data Example Source: https://lipilekhika.in/getting-started/python Example of using the `preload_script_data` function to load data for a specific script. This is beneficial for optimizing performance by avoiding repeated data loading. ```python preload_script_data('Devanagari') ``` -------------------------------- ### Install Lipi Lekhika using pip Source: https://lipilekhika.in/getting-started/python Install the Lipi Lekhika package using pip. Ensure you have Python 3.10 or higher. ```bash pip install lipilekhika ``` -------------------------------- ### Install Lipi Lekhika using Cargo Source: https://lipilekhika.in/getting-started/rust Use `cargo add` to install the Lipi Lekhika library into your Rust project. ```rust cargo add lipilekhika ``` -------------------------------- ### Get Normalized Script Name Example Source: https://lipilekhika.in/getting-started/python Demonstrates how to use `get_normalized_script_name` to obtain the standardized name for a given script or language. This is useful for ensuring consistent script identification. ```python from lipilekhika import get_normalized_script_name script = get_normalized_script_name('Hindi') print(script) # 'Devanagari' ``` -------------------------------- ### Preload WASM Module API Example Source: https://lipilekhika.in/getting-started/wasm Demonstrates the usage of the `preloadWasm()` function, which should be called during application initialization. After preloading, subsequent calls to WASM-based transliteration functions will be instantaneous. ```javascript // During app initialization await preloadWasm(); // Now WASM calls are instant const result = await transliterate_wasm('text', 'Normal', 'Devanagari'); ``` -------------------------------- ### Transliterate Text Example Source: https://lipilekhika.in/getting-started/python Example demonstrating the `transliterate` function to convert text from one script to another. This function is synchronous and returns the transliterated string directly. ```python result = transliterate('hello', 'Normal', 'Telugu') print(result) # హెల్లొ ``` -------------------------------- ### Node.js WASM Transliteration Source: https://lipilekhika.in/getting-started/wasm Example of using the `transliterate_wasm` function within a Node.js environment. Ensure the `lipilekhika` package is installed. ```javascript import { transliterate_wasm } from 'lipilekhika'; const result = await transliterate_wasm('text', 'Normal', 'Devanagari'); console.log(result); ``` -------------------------------- ### Getting All Available Transliteration Options Source: https://lipilekhika.in/getting-started/python Retrieve a list of all supported custom transliteration options for a given script pair using `get_all_options`. This helps in understanding and utilizing advanced transliteration features. ```python from lipilekhika import get_all_options # Get all available custom options for a script pair options = get_all_options('Normal', 'Devanagari') print(options) # ['normal_to_brahmic:use_alternative_mAtrA_form', ...] ``` -------------------------------- ### Transliterate WASM Example Source: https://lipilekhika.in/getting-started/wasm A straightforward example of using the `transliterate_wasm` function to convert text from 'Normal' script to 'Telugu'. This function is part of the WASM module for enhanced performance. ```javascript const result = await transliterate_wasm('hello', 'Normal', 'Telugu'); console.log(result); // హెల్లొ ``` -------------------------------- ### Get Available Options API Source: https://lipilekhika.in/getting-started/rust Retrieves a list of available custom transliteration options for a given script pair. ```APIDOC ## GET /options/available ### Description Gets a list of available custom transliteration options for a given source and target script. ### Method GET ### Endpoint /options/available ### Parameters #### Query Parameters - **from_script_name** (string) - Required - Source script/language name - **to_script_name** (string) - Required - Target script/language name ### Response #### Success Response (200) - **options** (array of strings) - A list of available option keys. #### Response Example ```json { "options": [ "brahmic_to_brahmic:replace_pancham_varna_varna_with_anusvAra" ] } ``` ``` -------------------------------- ### Transliterate text using WASM in Deno and Bun Source: https://lipilekhika.in/getting-started/wasm Examples for importing and using the transliterate_wasm function in different runtime environments. ```javascript import { transliterate_wasm } from 'npm:lipilekhika'; const result = await transliterate_wasm('text', 'Normal', 'Devanagari'); console.log(result); ``` ```javascript import { transliterate_wasm } from 'lipilekhika'; const result = await transliterate_wasm('text', 'Normal', 'Devanagari'); console.log(result); ``` -------------------------------- ### Get Available Transliteration Options in Rust Source: https://lipilekhika.in/getting-started/rust Uses the `get_all_option` function to discover available custom transliteration options for a given script pair. It returns a `Result, String>` containing option keys. ```rust use lipilekhika::get_all_option; fn main() { let options = get_all_option("Devanagari", "Telugu").unwrap(); for option in options { println!("Available option: {}", option); } } ``` -------------------------------- ### Retrieve Script Typing Data Map Source: https://lipilekhika.in/reference/realtime_typing Fetches detailed typing mappings including keyboard shortcuts, useful for building UI helpers or visual typing guides. ```javascript 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]] ``` -------------------------------- ### Get Script List Data API Source: https://lipilekhika.in/getting-started/rust Retrieves cached script metadata, including supported scripts, languages, and alias maps. ```APIDOC ## GET /scripts/list_data ### Description Retrieves the cached script metadata, including supported scripts, languages, and maps for resolving aliases. ### Method GET ### Endpoint /scripts/list_data ### Response #### Success Response (200) - **scripts** (array of strings) - List of supported script/language names. - **lang_script_map** (object) - A map from language names to their corresponding script names. #### Response Example ```json { "scripts": ["Devanagari", "Telugu", "Gujarati"], "lang_script_map": { "Devanagari": "Devanagari", "Telugu": "Telugu", "Gujarati": "Gujarati" } } ``` ``` -------------------------------- ### Get Script Typing Data API Source: https://lipilekhika.in/getting-started/rust Retrieves typing mappings for a specific script, useful for building custom input methods. ```APIDOC ## GET /scripts/typing_data ### Description Retrieves typing mappings for a given script, which can be used for building custom input methods. ### Method GET ### Endpoint /scripts/typing_data ### Parameters #### Query Parameters - **script** (string) - Required - The name of the script/language. ### Response #### Success Response (200) - **common_krama_map** (array of objects) - Mappings for common characters. Each object contains `text`, `type`, and `input_mappings`. - **script_specific_krama_map** (array of objects) - Mappings for script-specific characters. Each object contains `text`, `type`, and `input_mappings`. #### Response Example ```json { "common_krama_map": [ { "text": "a", "type": "ListType", "input_mappings": ["a"] } ], "script_specific_krama_map": [ { "text": "\u0906", "type": "ListType", "input_mappings": ["A", "aa"] } ] } ``` ``` -------------------------------- ### Browser (ESM) WASM Transliteration Source: https://lipilekhika.in/getting-started/wasm Example of using the `transliterate_wasm` function in a browser environment using ES Modules. The WASM module is imported from a CDN. ```javascript ``` -------------------------------- ### Get Script Typing Data in Rust Source: https://lipilekhika.in/getting-started/rust Fetches typing mappings for a script using `get_script_typing_data_map`. This is useful for building custom input methods and returns typing data including common and script-specific character mappings. ```rust use lipilekhika::get_script_typing_data_map; fn main() { let typing_data = get_script_typing_data_map("Devanagari").unwrap(); // Access common character mappings for (text, list_type, mappings) in &typing_data.common_krama_map { if !mappings.is_empty() { println!("{} can be typed using: {:?}", text, mappings); } } // Access script-specific character mappings for (text, list_type, mappings) in &typing_data.script_specific_krama_map { if !mappings.is_empty() { println!("{} (script-specific) can be typed using: {:?}", text, mappings); } } } ``` -------------------------------- ### Transliteration with Custom Options (WASM) Source: https://lipilekhika.in/getting-started/wasm Utilize custom transliteration options with the `transliterate_wasm` function, similar to the standard function. This example demonstrates replacing 'pancham varga varna' with 'anusvAra'. ```javascript import { transliterate_wasm } from 'lipilekhika'; const result = await transliterate_wasm( 'గంగా', 'Telugu', 'Gujarati', { 'brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra': true } ); console.log(result); // ગંગા (instead of ગઙ્ગા) ``` -------------------------------- ### Get Script List Data in Rust Source: https://lipilekhika.in/getting-started/rust Retrieves cached script metadata using `get_script_list_data()`. This function returns a `&'static ScriptListData` containing script names, language mappings, and aliases. The data is stored in a `OnceLock` for zero-cost access after the first call. ```rust use lipilekhika::get_script_list_data; fn main() { let data = get_script_list_data(); println!("Supported scripts: {:?}", data.scripts); println!("Language to script map: {:?}", data.lang_script_map); } ``` -------------------------------- ### Solid: Create Typing Context with createMemo Source: https://lipilekhika.in/getting-started/browser_typing_tool Create a typing context in Solid using `createMemo` for efficient updates when the script changes. ```javascript const ctx = createMemo(() => createTypingContext(script())); ``` -------------------------------- ### Create a Typing Context Source: https://lipilekhika.in/reference/realtime_typing Initializes a new typing context for a specific script. Await the ready method before using takeKeyInput for optimal performance. ```javascript import { createTypingContext } from 'lipilekhika/typing'; const ctx = createTypingContext('Devanagari'); ``` -------------------------------- ### Implement Realtime Typing Source: https://lipilekhika.in/getting-started/go Use the typing package to handle character-by-character input and receive diffs for buffer updates. ```go package main import ( "fmt" "github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing" ) func main() { ctx, err := typing.NewTypingContext("Devanagari", nil) if err != nil { panic(err) } diff, err := ctx.TakeKeyInput("k") if err != nil { panic(err) } fmt.Printf("delete=%d add=%q\n", diff.ToDeleteCharsCount, diff.DiffAddText) } ``` -------------------------------- ### Configure Typing Context Source: https://lipilekhika.in/getting-started/go Initialize a typing context with custom options like auto-clear time and numeral settings. ```go package main import "github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing" func main() { useNative := false includeInherent := true clearMs := 3000 ctx, _ := typing.NewTypingContext("Devanagari", &typing.TypingContextOptions{ AutoContextClearTimeMs: &clearMs, UseNativeNumerals: &useNative, IncludeInherentVowel: &includeInherent, }) _ = ctx } ``` -------------------------------- ### Initialize and Use Basic Typing Context Source: https://lipilekhika.in/getting-started/rust Demonstrates creating a TypingContext for Devanagari script and processing character inputs. Use this for basic text input processing where default options are sufficient. ```rust use lipilekhika::typing::{TypingContext, TypingContextOptions}; fn main() { let mut ctx = TypingContext::new("Devanagari", None).unwrap(); // Process character-by-character input let diff = ctx.take_key_input("n").unwrap(); println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text); // Output: Delete: 0, Add: 'न्' let diff = ctx.take_key_input("a").unwrap(); println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text); // Output: Delete: 2, Add: 'न' // Clear context when needed ctx.clear_context(); } ``` -------------------------------- ### GET get_schwa_status_for_script Source: https://lipilekhika.in/getting-started/python Retrieves the schwa deletion characteristic for a given script. ```APIDOC ## GET get_schwa_status_for_script(script_name) ### Description Returns the schwa deletion characteristic of the script, indicating if an inherent vowel 'a' (अ) is added to the end of consonant characters. ### Parameters #### Path Parameters - **script_name** (ScriptLangType) - Required - The script/language name to check ### Response - **Returns** (bool | None) - True if the script has schwa deletion, False if it doesn't, None if the script is not a Brahmic script. ### Errors - **Exception** - Raised if an invalid script name is provided. ``` -------------------------------- ### POST create_typing_context Source: https://lipilekhika.in/getting-started/python Initializes a stateful context for real-time character-by-character transliteration. ```APIDOC ## POST create_typing_context(typing_lang, options=None) ### Description Creates a stateful isolated context for character-by-character input typing. ### Parameters - **typing_lang** (ScriptLangType) - Required - The script/language to type in - **options** (TypingContextOptions) - Optional - Configuration settings for the typing context ### Response - **Returns** (TypingContext) - A context object providing methods: clear_context(), take_key_input(key), update_use_native_numerals(value), update_include_inherent_vowel(value), get_use_native_numerals(), get_include_inherent_vowel(). ### Errors - **Exception** - Raised if an invalid script name is provided. ``` -------------------------------- ### Initialize Typing Context with Custom Options Source: https://lipilekhika.in/getting-started/rust Shows how to create a TypingContext with specific options, such as auto-clear time, native numerals, and inherent vowel inclusion. Use this when default behavior needs modification. ```rust use lipilekhika::typing::{TypingContext, TypingContextOptions}; fn main() { let options = TypingContextOptions { auto_context_clear_time_ms: 3000, use_native_numerals: true, include_inherent_vowel: true, // For Hindi/Bengali style typing }; let mut ctx = TypingContext::new("Devanagari", Some(options)).unwrap(); let diff = ctx.take_key_input("k").unwrap(); println!("{}", diff.diff_add_text); // क (with inherent vowel) } ``` -------------------------------- ### Configure typing context with options Source: https://lipilekhika.in/getting-started/python Initialize a typing context with custom configuration settings like native numerals and inherent vowel handling. ```python from lipilekhika.typing import create_typing_context, TypingContextOptions # Create with custom options options = TypingContextOptions( auto_context_clear_time_ms=4500, use_native_numerals=True, include_inherent_vowel=False ) ctx = create_typing_context('Devanagari', options) # Process input diff = ctx.take_key_input('n') print(diff.diff_add_text) # 'न्' ``` -------------------------------- ### TypingContextOptions Source: https://lipilekhika.in/getting-started/rust Configuration structure for defining typing behavior during initialization. ```APIDOC ## TypingContextOptions ### Parameters - **auto_context_clear_time_ms** (u64) - Auto-clear timeout in milliseconds (default: 4500ms). - **use_native_numerals** (bool) - Use script-native numerals (default: true). - **include_inherent_vowel** (bool) - Include inherent vowel/schwa (default: false). ### Request Example let options = TypingContextOptions { auto_context_clear_time_ms: 3000, use_native_numerals: true, include_inherent_vowel: true }; ``` -------------------------------- ### get_all_options(from_script, to_script) Source: https://lipilekhika.in/getting-started/python Retrieves a list of supported custom options for a specific script pair. ```APIDOC ## Function: get_all_options ### Description Returns the list of all supported custom options for transliterations between the provided script pair. ### Parameters - **from_script** (ScriptLangType) - Required - The script/language to transliterate from - **to_script** (ScriptLangType) - Required - The script/language to transliterate to ### Response - **Returns** (list[str]) - List of all supported custom option keys ### Errors - **Exception** - Raised if an invalid script name is provided ``` -------------------------------- ### React: Create Typing Context with useMemo Source: https://lipilekhika.in/getting-started/browser_typing_tool Create a typing context in React using `useMemo` to optimize performance. Ensure the context is recreated if the script changes. ```javascript const ctx = useMemo(() => createTypingContext(script), [script]); ``` -------------------------------- ### Runtime Configuration Source: https://lipilekhika.in/getting-started/rust Methods to dynamically update or retrieve typing configuration settings after context initialization. ```APIDOC ## Runtime Configuration ### Description Allows dynamic modification of typing behavior settings during the lifecycle of a TypingContext instance. ### Methods - **update_use_native_numerals(bool)** - Enable or disable native script numerals. - **update_include_inherent_vowel(bool)** - Enable or disable inherent vowel inclusion. - **get_use_native_numerals()** - Returns current native numerals setting. - **get_include_inherent_vowel()** - Returns current inherent vowel setting. - **get_normalized_script()** - Returns the current normalized script name. ``` -------------------------------- ### Solid: Eagerly Await Context Ready State Source: https://lipilekhika.in/getting-started/browser_typing_tool Ensure script data is loaded before typing in Solid by eagerly awaiting `ctx().ready` within a `createEffect` hook. ```javascript createEffect(() => { ctx().ready; }); ``` -------------------------------- ### Access library constants Source: https://lipilekhika.in/getting-started/python Retrieve lists of supported scripts and languages provided by the package. ```python from lipilekhika import SCRIPT_LIST, LANG_LIST, ALL_SCRIPT_LANG_LIST print(SCRIPT_LIST) # ['Devanagari', 'Bengali', 'Telugu', ...] print(LANG_LIST) # ['Sanskrit', 'Hindi', 'Marathi', ...] print(ALL_SCRIPT_LANG_LIST) # Combined list ``` -------------------------------- ### Get Script Typing Data Map Source: https://lipilekhika.in/getting-started/python Retrieves the typing data map for a specified script, which includes common and script-specific character mappings. This is useful for comparing script data or building typing helper interfaces. ```APIDOC ## GET /api/typing/script_data_map ### Description Returns the typing data map for a script. This function is useful for comparing the krama array of two scripts or building typing helper UIs. ### Method GET ### Endpoint /api/typing/script_data_map ### Parameters #### Query Parameters - **script** (ScriptLangType) - Required - The script to get the typing data map for. ### Response #### Success Response (200) - **common_krama_map** (list[tuple[str, Literal["anya", "vyanjana", "matra", "svara"], list[str]]]) - Mappings for common characters across scripts. - **script_specific_krama_map** (list[tuple[str, Literal["anya", "vyanjana", "matra", "svara"], list[str]]]) - Mappings for script-specific characters. Each mapping is a tuple of (text, type, mappings) where: * text: str - The displayed character in the target script * type: Literal["anya", "vyanjana", "matra", "svara"] - Character category * mappings: list[str] - List of input key sequences that produce this character #### Response Example { "common_krama_map": [ ["अ", "svara", ["a"]], ["क", "vyanjana", ["k"]] ], "script_specific_krama_map": [ ["ा", "matra", ["aa", "A"]] ] } ### Error Handling - **Exception** - If an invalid script name is provided or if ‘Normal’ is used. ``` -------------------------------- ### Configure TypingContextOptions Source: https://lipilekhika.in/getting-started/python Initializes the configuration class for typing contexts with custom parameters. ```python from lipilekhika.typing import TypingContextOptions, DEFAULT_AUTO_CONTEXT_CLEAR_TIME_MS options = TypingContextOptions( auto_context_clear_time_ms=DEFAULT_AUTO_CONTEXT_CLEAR_TIME_MS, use_native_numerals=False, include_inherent_vowel=True ) ``` -------------------------------- ### createTypingContext Source: https://lipilekhika.in/reference/realtime_typing Initializes a new typing context for a specific script, returning a closure with methods to manage input and state. ```APIDOC ## createTypingContext ### Description Initializes a new typing context for a specific script. Returns a closure containing methods for handling character-by-character input and managing internal state. ### Parameters - **script** (string) - Required - The name of the script (e.g., 'Devanagari'). - **options** (object) - Optional - Configuration object. - **autoContextClearTimeMs** (number) - Time in milliseconds to clear context. - **useNativeNumerals** (boolean) - Whether to use native numerals. - **includeInherentVowel** (boolean) - Whether to include inherent vowels. ### Request Example const ctx = createTypingContext('Devanagari', { autoContextClearTimeMs: 4500, useNativeNumerals: true, includeInherentVowel: false }); ### Response - **ready** (function) - Await once before using takeKeyInput. - **clearContext** (function) - Clears internal states. - **takeKeyInput** (function) - Processes input and returns diff. - **updateUseNativeNumerals** (function) - Updates numeral setting. - **updateIncludeInherentVowel** (function) - Updates inherent vowel setting. ``` -------------------------------- ### Create a Typing Context Source: https://lipilekhika.in/getting-started/browser_typing_tool Instantiate a typing context for a specific script. A new context should be created for each script and element combination. ```javascript const ctx = createTypingContext('Telugu'); ``` -------------------------------- ### Import Lipi Lekhika Typing Functions Source: https://lipilekhika.in/getting-started/browser_typing_tool Import the necessary functions for creating and managing typing contexts. ```javascript import { createTypingContext, clearTypingContextOnKeyDown, handleTypingBeforeInputEvent } from 'lipilekhika/typing'; ``` -------------------------------- ### Solid: Textarea Element with Typing Handlers Source: https://lipilekhika.in/getting-started/browser_typing_tool Integrate Lipi Lekhika typing into a Solid textarea element, managing state with `value` and `onInput`, and attaching event handlers for `onBeforeInput`, `onBlur`, and `onKeyDown`. ```html ``` -------------------------------- ### Apply Custom Transliteration Options Source: https://lipilekhika.in/getting-started/go Pass a map of boolean options to customize the transliteration behavior. ```go package main import ( "fmt" "github.com/shubhattin/lipilekhika/packages/go/lipilekhika" ) func main() { out, err := lipilekhika.Transliterate( "गङ्गा", "Devanagari", "Gujarati", map[string]bool{ "brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra": true, }, ) if err != nil { panic(err) } fmt.Println(out) // ગંગા } ``` -------------------------------- ### Configure Custom Typing Options Source: https://lipilekhika.in/reference/realtime_typing Initializes a typing context with custom configuration for auto-clearing, numeral formatting, and inherent vowel handling. ```javascript 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 -> क् }); ``` -------------------------------- ### Preload WASM Module for Instant Calls Source: https://lipilekhika.in/getting-started/wasm Preload the WASM module using `preloadWasm()` during application initialization to eliminate the initial loading delay for subsequent `transliterate_wasm` calls. This ensures transliteration is instant once the module is ready. ```javascript import { preloadWasm, transliterate_wasm } from 'lipilekhika'; // Preload during app initialization await preloadWasm(); // Later calls will be instant (no loading delay) const result = await transliterate_wasm('namaste', 'Normal', 'Devanagari'); console.log(result); // नमस्ते ``` -------------------------------- ### Typing Context Options Source: https://lipilekhika.in/getting-started/python Configuration class for customizing typing contexts, including auto-context clearing time, numeral usage, and inherent vowel inclusion. ```APIDOC ## Class: TypingContextOptions ### Description Configuration class for typing contexts. ### Attributes - **auto_context_clear_time_ms** (int) - Optional - Time in ms after which context is cleared (default: 4500). - **use_native_numerals** (bool) - Optional - Whether to use native numerals (default: True). - **include_inherent_vowel** (bool) - Optional - Whether to include inherent vowels/schwa (default: False). ### Example ```python from lipilekhika.typing import TypingContextOptions options = TypingContextOptions( auto_context_clear_time_ms=4500, use_native_numerals=False, include_inherent_vowel=True ) ``` ``` -------------------------------- ### Basic Transliteration using JavaScript Source: https://lipilekhika.in/getting-started/javascript Import and use the `transliterate` function for basic transliteration. This function returns a Promise. ```javascript import { transliterate } from 'lipilekhika'; const result = await transliterate('na jAyatE mriyatE vA', 'Normal', 'Devanagari'); console.log(result); // न जायते म्रियते वा ``` -------------------------------- ### ESM Usage in Browser Source: https://lipilekhika.in/getting-started/javascript Integrate Lipi Lekhika in the browser using ESM by importing directly from a CDN. The `transliterate` function is available. ```html ``` -------------------------------- ### React: Input Element with Typing Handlers Source: https://lipilekhika.in/getting-started/browser_typing_tool Integrate Lipi Lekhika typing into a React textarea element by attaching event handlers for `onBeforeInput`, `onBlur`, and `onKeyDown`. ```javascript ``` -------------------------------- ### Svelte: Eagerly Await Context Ready State Source: https://lipilekhika.in/getting-started/browser_typing_tool Ensure script data is loaded before typing in Svelte by eagerly awaiting `ctx.ready` using the `$effect` directive. ```javascript $effect(() => { ctx.ready; }); ``` -------------------------------- ### Basic Transliteration in Rust Source: https://lipilekhika.in/getting-started/rust Demonstrates the primary `transliterate` function for converting text between scripts. It returns a `Result` and requires specifying source and target script names. ```rust use lipilekhika::transliterate; fn main() { let result = transliterate( "na jAyatE mriyatE vA", "Normal", "Devanagari", None ).unwrap(); println!("{}", result); // न जायते म्रियते वा } ``` -------------------------------- ### Basic Transliteration with Lipi Lekhika Source: https://lipilekhika.in/getting-started/python Use the `transliterate` function for direct string transliteration. It supports IDE autocompletion and type checking for script names. ```python from lipilekhika import transliterate result = transliterate('na jAyatE mriyatE vA', 'Normal', 'Devanagari') print(result) # न जायते म्रियते वा ``` -------------------------------- ### UMD Usage in Browser Source: https://lipilekhika.in/getting-started/javascript Use the UMD build of Lipi Lekhika in the browser by including the script tag from a CDN. The `transliterate` function is accessible via the `lipilekhika` global object. ```html ``` -------------------------------- ### Transliteration with Custom Options in Rust Source: https://lipilekhika.in/getting-started/rust Shows how to use custom transliteration options by passing a `HashMap` as the fourth argument to the `transliterate` function. This allows fine-tuning of the transliteration behavior. ```rust use lipilekhika::transliterate; use std::collections::HashMap; fn main() { let mut options = HashMap::new(); options.insert( "brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra".to_string(), true ); let result = transliterate( "గంగా", "Telugu", "Gujarati", Some(&options) ).unwrap(); println!("{}", result); // ગંગા (instead of ગઙ્ગા) } ``` -------------------------------- ### Lipi Lekhika Realtime Typing API Source: https://lipilekhika.in/getting-started/go The typing package provides functionalities for character-by-character input processing, enabling realtime typing experiences. ```APIDOC ## Realtime Typing Module ### Description Provides functionalities for character-by-character input processing, enabling realtime typing experiences. ### Key Types - `typing.TypingContext`: Manages the state for realtime typing. - `typing.TypingContextOptions`: Configuration options for `TypingContext`. - `typing.TypingDiff`: Represents the difference between input and output. ### Initialization #### `NewTypingContext` Initializes a new typing context. ```go func NewTypingContext( script string, options *TypingContextOptions, ) (*TypingContext, error) ``` - **script** (string) - The script to use for typing. - **options** (*TypingContextOptions) - Optional configuration options. ### Core Functionality #### `TakeKeyInput` Processes a single key input and returns the difference to apply. ```go func (ctx *TypingContext) TakeKeyInput( key string, ) (*TypingDiff, error) ``` - **key** (string) - The input key pressed. - **Returns**: `*TypingDiff` - The difference to apply to the buffer, and an `error` if any occurs. ### Diff Structure #### `TypingDiff` Represents the changes needed for the buffer. - **ToDeleteCharsCount** (int) - Number of characters to delete from the buffer tail. - **DiffAddText** (string) - The text to append to the buffer. ### Example Usage (Basic) ```go package main import ( "fmt" "github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing" ) func main() { ctx, err := typing.NewTypingContext("Devanagari", nil) if err != nil { panic(err) } diff, err := ctx.TakeKeyInput("k") if err != nil { panic(err) } fmt.Printf("delete=%d add=%q\n", diff.ToDeleteCharsCount, diff.DiffAddText) } ``` ### Typing With Options #### `TypingContextOptions` Allows customization of the typing context. - **AutoContextClearTimeMs** (*int) - Time in milliseconds to automatically clear context. - **UseNativeNumerals** (*bool) - Whether to use native numerals. - **IncludeInherentVowel** (*bool) - Whether to include inherent vowels. ### Example Usage (WithOptions) ```go package main import "github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing" func main() { useNative := false includeInherent := true clearMs := 3000 ctx, _ := typing.NewTypingContext("Devanagari", &typing.TypingContextOptions{ AutoContextClearTimeMs: &clearMs, UseNativeNumerals: &useNative, IncludeInherentVowel: &includeInherent, }) _ = ctx } ``` ### Runtime Updates on Context - `UpdateUseNativeNumerals(bool)` - `UpdateIncludeInherentVowel(bool)` - `ClearContext()` ### Error Handling If a script name is invalid, all APIs return a non-nil `error`. Use the supported scripts list or its aliases to normalize names before calling. ``` -------------------------------- ### Transliteration using Node.js Native Module Source: https://lipilekhika.in/getting-started/javascript Utilize the Node.js native module for near-native performance. Optional preloading is available to avoid initial loading delays. ```javascript import { transliterate_node, preloadNode } from 'lipilekhika/node'; import { createTypingContext } from 'lipilekhika/node'; // Optional: preload the native module await preloadNode(); const result = await transliterate_node('na jAyatE mriyatE vA', 'Normal', 'Devanagari'); console.log(result); // न जायते म्रियते वा // Typing context (same API as the TS version) const ctx = createTypingContext('Telugu'); await ctx.ready; const diff = ctx.takeKeyInput('k'); ``` -------------------------------- ### React: Eagerly Await Context Ready State Source: https://lipilekhika.in/getting-started/browser_typing_tool Ensure script data is loaded before typing begins by eagerly awaiting `ctx.ready` within a `useEffect` hook, especially when `ctx` is created with `useMemo`. ```javascript useEffect(() => { ctx.ready; }, [ctx]); ``` -------------------------------- ### getScriptTypingDataMap Source: https://lipilekhika.in/reference/realtime_typing Retrieves detailed typing mappings for a script, including keyboard shortcuts. ```APIDOC ## getScriptTypingDataMap ### Description Returns detailed typing mappings for a script, including keyboard shortcuts for each character. Useful for building typing helper UIs. ### Parameters - **script** (string) - Required - The name of the script. ### Response - **Object** (object) - Contains 'common_krama_map' and 'script_specific_krama_map', where each entry is a tuple of [character, type, [keyboard_mappings]]. ``` -------------------------------- ### Svelte: Create Typing Context with $derived Source: https://lipilekhika.in/getting-started/browser_typing_tool Create a typing context in Svelte using the `$derived` directive for reactive script changes. ```javascript const ctx = $derived(createTypingContext(script)); ``` -------------------------------- ### Vue: Create Typing Context with computed Source: https://lipilekhika.in/getting-started/browser_typing_tool Create a typing context in Vue using `computed` to ensure reactivity with script changes. ```javascript const ctx = computed(() => createTypingContext(script.value)); ``` -------------------------------- ### preloadWasm() Source: https://lipilekhika.in/getting-started/wasm Preloads the WASM module to eliminate initial loading latency. ```APIDOC ## preloadWasm() ### Description Preloads the WASM module into memory. It is recommended to call this during application initialization to ensure subsequent transliteration calls are instant. ### Returns - **Promise** - Resolves when the module is loaded. ### Request Example ```javascript await preloadWasm(); ``` ``` -------------------------------- ### Transliteration Options Configuration Source: https://lipilekhika.in/reference/custom_trans_options A collection of available transliteration flags used to modify the output of script conversions. ```APIDOC ## Transliteration Options ### Description These options allow fine-grained control over how characters are transformed during the transliteration process. ### Available Options - **all_to_normal:replace_pancham_varga_varna_with_n**: Replaces ङ (G) and ञ (J) with ‘n’. - **brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra**: Replaces 5th varga consonants with anusvāra (ं) when followed by consonants of the same varga. - **all_to_sinhala:use_conjunct_enabling_halant**: Uses conjunct-enabling halant (්‍) for Sinhala output. - **all_to_normal:remove_virAma_and_double_virAma**: Removes virāma (।) and pūrṇa virāma (॥) punctuation. - **all_to_normal:replace_avagraha_with_a**: Replaces avagraha (ऽ) with ‘a’. - **normal_to_all:use_typing_chars**: Enables typing mode characters and script-specific alternatives. - **all_to_normal:preserve_specific_chars**: Preserves script-specific characters during conversion to Normal script. ``` -------------------------------- ### Handle BeforeInput Event Source: https://lipilekhika.in/getting-started/browser_typing_tool Call `handleTypingBeforeInputEvent` with the typing context, the event object, and an optional callback to process the updated input value. ```javascript handleTypingBeforeInputEvent(ctx, event, callback, options?); ``` -------------------------------- ### Access typing constants Source: https://lipilekhika.in/getting-started/python Retrieves default values for typing context configuration. ```python from lipilekhika.typing import ( DEFAULT_AUTO_CONTEXT_CLEAR_TIME_MS, DEFAULT_USE_NATIVE_NUMERALS, DEFAULT_INCLUDE_INHERENT_VOWEL ) print(DEFAULT_AUTO_CONTEXT_CLEAR_TIME_MS) # 4500 print(DEFAULT_USE_NATIVE_NUMERALS) # True print(DEFAULT_INCLUDE_INHERENT_VOWEL) # False ``` -------------------------------- ### Implement real-time typing Source: https://lipilekhika.in/getting-started/python Process character-by-character input to generate transliteration diffs for interactive interfaces. ```python from lipilekhika.typing import create_typing_context ctx = create_typing_context('Telugu') # Process each character as the user types for char in "namaste": diff = ctx.take_key_input(char) # The diff tells you what to change in your text buffer: # - Remove the last diff.to_delete_chars_count characters # - Append diff.diff_add_text print(f"Delete {diff.to_delete_chars_count}, Add: {diff.diff_add_text}") ``` -------------------------------- ### preload_script_data(script_name) Source: https://lipilekhika.in/getting-started/python Preloads script data to optimize performance and avoid initial loading delays. ```APIDOC ## Function: preload_script_data ### Description Preloads the script data for the given script/language. ### Parameters - **script_name** (ScriptLangType) - Required - The name of the script/language to preload ### Errors - **Exception** - Raised if an invalid script name is provided ```