{"version":3,"sources":["../src/index.ts","../src/aksharamukha/index.ts","../src/constants.ts"],"sourcesContent":["import Aksharamukha from './aksharamukha';\nexport default Aksharamukha;\nexport * from './aksharamukha';","import { loadPyodide, type PyodideInterface } from 'pyodide';\nimport { wheelBaseURL, wheels } from '../constants';\n\nconst isNode = typeof window === 'undefined' || (typeof process !== 'undefined' && process.versions?.node);\n\nexport type ProcessArgs = {\n\tsrc: string,\n\ttgt: string,\n\ttxt: string,\n\tprops: ProcessProps\n};\n\nexport type AutoDetectArgs = {\n\ttxt: string,\n\tplugin: boolean\n};\n\nexport type ProcessProps = {\n\tnativize: boolean;\n\tparam: ProcessParam;\n\tpreOptions: string[];\n\tpostOptions: string[];\n};\n\nexport const ProcessParams = {\n\tdefault: 'default',\n\tscriptCode: 'script_code',\n\tlangCode: 'lang_code',\n\tlangName: 'lang_name'\n} as const;\n\nexport type ProcessParam = typeof ProcessParams[keyof typeof ProcessParams];\n\nexport const defaultProcessProps: ProcessProps = {\n\tnativize: true,\n\tparam: ProcessParams.default,\n\tpreOptions: [],\n\tpostOptions: []\n};\n\nexport type AksharamukhaInitOptions = {\n\tpyodide?: PyodideInterface;\n};\n\nexport default class Aksharamukha {\n\tstatic _isTestEnv: boolean = false;\n\tstatic _currentScript: HTMLScriptElement;\n\tpyodide: PyodideInterface;\n\n\tprivate constructor(pyodide: PyodideInterface) {\n\t\tthis.pyodide = pyodide;\n\t}\n\n\tpublic static _setCurrentScript(script: HTMLScriptElement) {\n\t\tthis._currentScript = script;\n\t}\n\n\tpublic static async new(opts?: AksharamukhaInitOptions): Promise<Aksharamukha> {\n\t\tlet pyodide = opts?.pyodide;\n\t\tif (pyodide == null) {\n\t\t\tif (this._isTestEnv) {\n\t\t\t\tpyodide = await loadTestPyodide();\n\t\t\t} else {\n\t\t\t\tpyodide = await loadPyodide();\n\t\t\t}\n\t\t}\n\n\t\tawait pyodide.loadPackage('micropip');\n\t\tconst micropip = pyodide.pyimport('micropip');\n\n\t\tif (isNode) {\n\t\t\tconst fs = await import('fs');\n\n\t\t\tfor (const wheel of wheels) {\n\t\t\t\tlet wheelData: Buffer<ArrayBuffer>;\n\t\t\t\tconst currentDir = getCurrentDir()\n\n\t\t\t\ttry {\n\t\t\t\t\tconst wheelPath = `${currentDir}/${wheel}`;\n\t\t\t\t\twheelData = fs.readFileSync(wheelPath);\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.warn(`Wheel file missing in script directory, trying ../../downloads: ${e}`);\n\t\t\t\t\tconst wheelPath = `${currentDir}/../../downloads/${wheel}`;\n\t\t\t\t\twheelData = fs.readFileSync(wheelPath);\n\t\t\t\t}\n\n\t\t\t\tpyodide.FS.writeFile(`/tmp/${wheel}`, wheelData);\n\t\t\t}\n\n\t\t\tawait micropip.install(wheels.map(wheel => `emfs:/tmp/${wheel}`), { keep_going: true });\n\n\t\t\tfor (const wheel of wheels) {\n\t\t\t\tpyodide.FS.unlink(`/tmp/${wheel}`);\n\t\t\t}\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tconst scriptPath = this._currentScript.src;\n\t\t\t\tconst parentPath = scriptPath.substring(0, scriptPath.lastIndexOf('/'));\n\t\t\t\tawait micropip.install(wheels.map(wheel => `${parentPath}/${wheel}`), { keep_going: true })\n\t\t\t} catch {\n\t\t\t\tawait micropip.install(wheels.map(wheel => `${wheelBaseURL}/${wheel}`), { keep_going: true })\n\t\t\t}\n\t\t}\n\n\t\t// Pre-import to speed up further calls\n\t\tpyodide.runPython(`from aksharamukha import *`);\n\t\tconst instance = new Aksharamukha(pyodide);\n\n\t\t// Pre-heat by doing the first process call\n\t\tinstance.process('autodetect', 'Devanagari', 'praNAm');\n\t\treturn instance;\n\t}\n\n\tpublic async test() {\n\t\tconst result = await this.pyodide.runPythonAsync(`1 + 1`);\n\t\tif (result !== 2) {\n\t\t\tthrow new Error('Pyodide not functioning correctly.');\n\t\t}\n\t}\n\n\tpublic process(\n\t\tsrc: string,\n\t\ttgt: string,\n\t\ttxt: string,\n\t\t{\n\t\t\tnativize,\n\t\t\tparam,\n\t\t\tpreOptions,\n\t\t\tpostOptions\n\t\t}: ProcessProps = defaultProcessProps\n\t): string {\n\t\tconst cmd = buildProcessCMD({\n\t\t\tsrc,\n\t\t\ttgt,\n\t\t\ttxt,\n\t\t\tprops: {\n\t\t\t\tnativize: nativize ?? defaultProcessProps.nativize,\n\t\t\t\tparam: param ?? defaultProcessProps.param,\n\t\t\t\tpreOptions: preOptions ?? defaultProcessProps.preOptions,\n\t\t\t\tpostOptions: postOptions ?? defaultProcessProps.postOptions\n\t\t\t}\n\t\t});\n\t\treturn this.pyodide.runPython(cmd);\n\t}\n\n\tpublic async processAsync(\n\t\tsrc: string,\n\t\ttgt: string,\n\t\ttxt: string,\n\t\t{\n\t\t\tnativize,\n\t\t\tparam,\n\t\t\tpreOptions,\n\t\t\tpostOptions\n\t\t}: ProcessProps = defaultProcessProps\n\t): Promise<string> {\n\t\tconst cmd = buildProcessCMD({\n\t\t\tsrc,\n\t\t\ttgt,\n\t\t\ttxt,\n\t\t\tprops: {\n\t\t\t\tnativize: nativize ?? defaultProcessProps.nativize,\n\t\t\t\tparam: param ?? defaultProcessProps.param,\n\t\t\t\tpreOptions: preOptions ?? defaultProcessProps.preOptions,\n\t\t\t\tpostOptions: postOptions ?? defaultProcessProps.postOptions\n\t\t\t}\n\t\t});\n\t\treturn await this.pyodide.runPythonAsync(cmd);\n\t}\n\n\tpublic autoDetect(\n\t\ttxt: string,\n\t\tplugin: boolean = false\n\t): string {\n\t\tconst cmd = buildAutoDetectCMD({ txt, plugin });\n\t\treturn this.pyodide.runPython(cmd);\n\t}\n\n\tpublic autoDetectAsync(\n\t\ttxt: string,\n\t\tplugin: boolean = false\n\t): Promise<string> {\n\t\tconst cmd = buildAutoDetectCMD({ txt, plugin });\n\t\treturn this.pyodide.runPythonAsync(cmd);\n\t}\n}\n\nasync function loadTestPyodide(): Promise<PyodideInterface> {\n\treturn await loadPyodide({\n\t\tindexURL: './node_modules/pyodide',\n\t\tpackageCacheDir: './node_modules/pyodide'\n\t})\n}\n\nfunction buildProcessCMD(props: ProcessArgs) {\n\treturn `\n\t\tfrom aksharamukha import transliterate\n\t\ttransliterate.process(\n\t\t\t${JSON.stringify(props.src)},\n\t\t\t${JSON.stringify(props.tgt)},\n\t\t\t${JSON.stringify(props.txt)},\n\t\t\tnativize=${props.props.nativize ? 'True' : 'False'},\n\t\t\tparam=${JSON.stringify(props.props.param)},\n\t\t\tpre_options=${JSON.stringify(props.props.preOptions)},\n\t\t\tpost_options=${JSON.stringify(props.props.postOptions)}\n\t\t)\n\t`\n}\n\nfunction buildAutoDetectCMD(props: AutoDetectArgs) {\n\treturn `\n\t\tfrom aksharamukha import transliterate\n\t\ttransliterate.auto_detect(\n\t\t\t${JSON.stringify(props.txt)},\n\t\t\t${props.plugin ? 'True' : 'False'}\n\t\t)\n\t`\n}\n\nfunction getCurrentDir(): string {\n\tif (!isNode) {\n\t\tthrow new Error('getCurrentDir is only supported in Node.js environment.');\n\t}\n\n\ttry {\n\t\treturn __dirname;\n\t} catch {\n\t\treturn import.meta.dirname;\n\t}\n}","export const wheels = [\n\t'jaconv-0.4.0-py3-none-any.whl',\n\t'marisa_trie-1.3.2.dev0-cp313-cp313-pyodide_2025_0_wasm32.whl',\n\t'aksharamukha-2.3-py3-none-any.whl'\n];\n\nexport const wheelBaseURL = 'https://github.com/paramsiddharth/aksharamukha.js/releases/download/v2.3.0-0';"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,YAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAAmD,mBCA5C,IAAMC,EAAS,CACrB,gCACA,+DACA,mCACD,EAEaC,EAAe,+EDN5B,IAAAC,EAAA,GAGMC,EAAS,OAAO,OAAW,KAAgB,OAAO,QAAY,KAAe,QAAQ,UAAU,KAqBxFC,EAAgB,CAC5B,QAAS,UACT,WAAY,cACZ,SAAU,YACV,SAAU,WACX,EAI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CAAG,CAClC,CAEO,gBACNL,EACAO,EAAkB,GACA,CAClB,IAAMF,EAAMG,EAAmB,CAAE,IAAAR,EAAK,OAAAO,CAAO,CAAC,EAC9C,OAAO,KAAK,QAAQ,eAAeF,CAAG,CACvC,CACD,EAEA,eAAerB,GAA6C,CAC3D,OAAO,QAAM,eAAY,CACxB,SAAU,yBACV,gBAAiB,wBAClB,CAAC,CACF,CAEA,SAASsB,EAAgBG,EAAoB,CAC5C,MAAO;AAAA;AAAA;AAAA,KAGH,KAAK,UAAUA,EAAM,GAAG,CAAC;AAAA,KACzB,KAAK,UAAUA,EAAM,GAAG,CAAC;AAAA,KACzB,KAAK,UAAUA,EAAM,GAAG,CAAC;AAAA,cAChBA,EAAM,MAAM,SAAW,OAAS,OAAO;AAAA,WAC1C,KAAK,UAAUA,EAAM,MAAM,KAAK,CAAC;AAAA,iBAC3B,KAAK,UAAUA,EAAM,MAAM,UAAU,CAAC;AAAA,kBACrC,KAAK,UAAUA,EAAM,MAAM,WAAW,CAAC;AAAA;AAAA,EAGzD,CAEA,SAASD,EAAmBC,EAAuB,CAClD,MAAO;AAAA;AAAA;AAAA,KAGH,KAAK,UAAUA,EAAM,GAAG,CAAC;AAAA,KACzBA,EAAM,OAAS,OAAS,OAAO;AAAA;AAAA,EAGpC,CAEA,SAASlB,GAAwB,CAChC,GAAI,CAACf,EACJ,MAAM,IAAI,MAAM,yDAAyD,EAG1E,GAAI,CACH,OAAO,SACR,MAAQ,CACP,OAAOD,EAAY,OACpB,CACD,CDpOA,IAAOmC,EAAQC","names":["index_exports","__export","ProcessParams","index_default","defaultProcessProps","__toCommonJS","import_pyodide","wheels","wheelBaseURL","import_meta","isNode","ProcessParams","defaultProcessProps","Aksharamukha","_Aksharamukha","pyodide","script","opts","loadTestPyodide","micropip","fs","wheel","wheels","wheelData","currentDir","getCurrentDir","wheelPath","e","scriptPath","parentPath","wheelBaseURL","instance","src","tgt","txt","nativize","param","preOptions","postOptions","cmd","buildProcessCMD","plugin","buildAutoDetectCMD","props","index_default","Aksharamukha"]}