lipilekhika 0.0.0-alpha.2 → 0.0.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/lipilekhika.umd.js +2 -2
  2. package/dist/types/src/custom_options.json.d.ts +220 -0
  3. package/dist/types/src/index.d.ts +100 -0
  4. package/dist/types/src/make_script_data/custom_options_input.d.ts +62 -0
  5. package/dist/types/src/make_script_data/input_data/Assamese.d.ts +3 -0
  6. package/dist/types/src/make_script_data/input_data/Bengali.d.ts +3 -0
  7. package/dist/types/src/make_script_data/input_data/Brahmi.d.ts +3 -0
  8. package/dist/types/src/make_script_data/input_data/Devanagari.d.ts +3 -0
  9. package/dist/types/src/make_script_data/input_data/Granth.d.ts +3 -0
  10. package/dist/types/src/make_script_data/input_data/Gujarati.d.ts +3 -0
  11. package/dist/types/src/make_script_data/input_data/Gurumukhi.d.ts +3 -0
  12. package/dist/types/src/make_script_data/input_data/Kannada.d.ts +3 -0
  13. package/dist/types/src/make_script_data/input_data/Malayalam.d.ts +3 -0
  14. package/dist/types/src/make_script_data/input_data/Modi.d.ts +3 -0
  15. package/dist/types/src/make_script_data/input_data/Normal.d.ts +3 -0
  16. package/dist/types/src/make_script_data/input_data/Odia.d.ts +3 -0
  17. package/dist/types/src/make_script_data/input_data/Purna-Devanagari.d.ts +3 -0
  18. package/dist/types/src/make_script_data/input_data/Romanized.d.ts +3 -0
  19. package/dist/types/src/make_script_data/input_data/Sharada.d.ts +3 -0
  20. package/dist/types/src/make_script_data/input_data/Siddham.d.ts +3 -0
  21. package/dist/types/src/make_script_data/input_data/Sinhala.d.ts +3 -0
  22. package/dist/types/src/make_script_data/input_data/Tamil-Extended.d.ts +3 -0
  23. package/dist/types/src/make_script_data/input_data/Tamil.d.ts +3 -0
  24. package/dist/types/src/make_script_data/input_data/Telugu.d.ts +3 -0
  25. package/dist/types/src/make_script_data/input_script_data_schema.d.ts +91 -0
  26. package/dist/types/src/make_script_data/krama_array_keys.d.ts +145 -0
  27. package/dist/types/src/make_script_data/make_output_script_data.d.ts +1 -0
  28. package/dist/types/src/make_script_data/output_script_data_schema.d.ts +46 -0
  29. package/dist/types/src/tools/kry.d.ts +18 -0
  30. package/dist/types/src/transliteration/a.d.ts +1 -0
  31. package/dist/types/src/transliteration/active_option_resolver.test.d.ts +1 -0
  32. package/dist/types/src/transliteration/context_clear.test.d.ts +1 -0
  33. package/dist/types/src/transliteration/emulate_typing.test.d.ts +1 -0
  34. package/dist/types/src/transliteration/helpers.d.ts +90 -0
  35. package/dist/types/src/transliteration/test_commons.d.ts +13 -0
  36. package/dist/types/src/transliteration/transliterate.d.ts +47 -0
  37. package/dist/types/src/transliteration/transliterate.test.d.ts +2 -0
  38. package/dist/types/src/utils/binary_search/binary_search.d.ts +25 -0
  39. package/dist/types/src/utils/binary_search/binary_search.test.d.ts +1 -0
  40. package/dist/types/src/utils/get_script_data.d.ts +8 -0
  41. package/dist/types/src/utils/lang_list/index.d.ts +50 -0
  42. package/dist/types/src/utils/lang_list/langs.json.d.ts +44 -0
  43. package/dist/types/src/utils/lang_list/script_normalization.d.ts +6 -0
  44. package/dist/types/src/utils/lang_list/script_normalization.test.d.ts +1 -0
  45. package/dist/types/src/utils/non_bmp.d.ts +3 -0
  46. package/dist/types/src/utils/runtime_macros.d.ts +5 -0
  47. package/package.json +2 -4
  48. package/dist/cjs/Assamese-Dv2Uz5Ga.cjs +0 -1
  49. package/dist/cjs/Bengali-CP-jqwb3.cjs +0 -1
  50. package/dist/cjs/Brahmi-BOnETq6u.cjs +0 -1
  51. package/dist/cjs/Devanagari-DogoRXY8.cjs +0 -1
  52. package/dist/cjs/Granth-9Z5eCctH.cjs +0 -1
  53. package/dist/cjs/Gujarati-CUm-ZsKN.cjs +0 -1
  54. package/dist/cjs/Gurumukhi-CsObr-GI.cjs +0 -1
  55. package/dist/cjs/Kannada-SXQdSng_.cjs +0 -1
  56. package/dist/cjs/Malayalam-IcKWWsaB.cjs +0 -1
  57. package/dist/cjs/Modi-C3Chvoab.cjs +0 -1
  58. package/dist/cjs/Normal-BZe6xAux.cjs +0 -1
  59. package/dist/cjs/Odia-C_-bjsx6.cjs +0 -1
  60. package/dist/cjs/Purna-Devanagari-BkPRDmig.cjs +0 -1
  61. package/dist/cjs/Romanized-B_o6BaP0.cjs +0 -1
  62. package/dist/cjs/Sharada-DfQQFnhQ.cjs +0 -1
  63. package/dist/cjs/Siddham-D4xax5q5.cjs +0 -1
  64. package/dist/cjs/Sinhala-oz5fU6-H.cjs +0 -1
  65. package/dist/cjs/Tamil-Extended-Bg0_zDSf.cjs +0 -1
  66. package/dist/cjs/Tamil-pc27DGFa.cjs +0 -1
  67. package/dist/cjs/Telugu-C9jvVXuj.cjs +0 -1
  68. package/dist/cjs/index.cjs +0 -2
  69. package/dist/esm/Assamese-C2ZNJvdv.js +0 -25
  70. package/dist/esm/Bengali-B4lwiGw-.js +0 -25
  71. package/dist/esm/Brahmi-P_BhbEU1.js +0 -23
  72. package/dist/esm/Devanagari-CU6oiaDU.js +0 -25
  73. package/dist/esm/Granth-v69SsV6n.js +0 -25
  74. package/dist/esm/Gujarati-GMDcD3zf.js +0 -25
  75. package/dist/esm/Gurumukhi-cSQGlqXa.js +0 -25
  76. package/dist/esm/Kannada-BC0s2WZG.js +0 -25
  77. package/dist/esm/Malayalam-R6qN3iwf.js +0 -23
  78. package/dist/esm/Modi-B8YiZBXf.js +0 -23
  79. package/dist/esm/Normal-DH6dfVGR.js +0 -21
  80. package/dist/esm/Odia-DphK-sRO.js +0 -25
  81. package/dist/esm/Purna-Devanagari-iW765mfa.js +0 -25
  82. package/dist/esm/Romanized-BQU9AmMX.js +0 -21
  83. package/dist/esm/Sharada-DOmuoJ5u.js +0 -25
  84. package/dist/esm/Siddham-CZ7F2rJg.js +0 -25
  85. package/dist/esm/Sinhala-BKPrzGBh.js +0 -23
  86. package/dist/esm/Tamil-B_Q1LP6g.js +0 -23
  87. package/dist/esm/Tamil-Extended-8h88s1_g.js +0 -23
  88. package/dist/esm/Telugu-w-eiYYTU.js +0 -23
  89. package/dist/esm/index.mjs +0 -672
  90. package/dist/index.d.ts +0 -614
  91. package/dist/tsdoc-metadata.json +0 -11
@@ -1,2 +1,2 @@
1
- (function(A,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(A=typeof globalThis<"u"?globalThis:A||self,C(A.lipilekhika={}))})(this,(function(A){"use strict";function C(n,t,i,_){const{accessor:c,compareFn:l}=_??{},e=c??((r,o)=>r[o]);let a=0,h=t.length-1,p=-1;for(;a<=h;){const r=Math.floor((a+h)/2),o=t[r],s=e(n,o);let f;l?f=l(i,s):f=i<s?-1:i>s?1:0,f===0?(p=o,h=r-1):f<0?h=r-1:a=r+1}return p}function et(n,t,i){const{accessor:_,compareFn:c}=i??{},l=_??((p,r)=>p[r]);let e=0,a=n.length-1,h=-1;for(;e<=a;){const p=Math.floor((e+a)/2),r=l(n,p);let o;c?o=c(t,r):o=t<r?-1:t>r?1:0,o===0?(h=p,a=p-1):o<0?a=p-1:e=p+1}return h}const at={},U=async n=>{{if(at[n])return at[n];const i=`https://cdn.jsdelivr.net/npm/lipilekhika@0.0.0-alpha.2/dist/umd_json/script_data/${n}.json`,c=await(await fetch(i)).json();return at[n]=c,c}},J={"all_to_normal:replace_pancham_varga_varna_with_n":{from_script_type:"all",to_script_name:["Normal"],check_in:"output",rules:[{type:"replace_prev_krama_keys",check_in:"output",prev:[60],following:[52,53,54,55,56,57,58,59],replace_with:[72]},{type:"replace_prev_krama_keys",check_in:"output",prev:[67],following:[61,62,63,64,65,66],replace_with:[72]}]},"brahmic_to_brahmic:replace_pancham_varga_varna_with_anuvsvAra":{from_script_type:"brahmic",to_script_type:"brahmic",check_in:"input",rules:[{type:"replace_prev_krama_keys",check_in:"input",prev:[60,49],following:[52,53,54,55,56,57,58,59],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[67,49],following:[61,62,63,64,65,66],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[81,49],following:[74,75,76,77,78,79,80],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[72,49],following:[68,69,70,71],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[88,49],following:[82,83,85,86,87],replace_with:[45]}]},"all_to_sinhala:use_conjuct_enabling_halant":{from_script_type:"all",to_script_name:["Sinhala"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[49]],replace_text:"්‍",replace_with:[]}]},"all_to_normal:remove_virAma_and_double_virAma":{from_script_type:"all",to_script_name:["Normal","Romanized"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[116],[115]],replace_with:[-1]}]},"all_to_normal:replace_avagraha_with_a":{from_script_type:"all",to_script_name:["Normal","Romanized"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[48]],replace_with:[1]}]}},kt=(n,t)=>{const i=n.krama_text_arr[t]?.[0];return typeof i=="string"?i:null},O=(n,t)=>kt(n,t)??"",Y=(n,t)=>C(n.krama_text_arr,n.krama_text_arr_index,t,{accessor:(i,_)=>i[_][0]}),gt=()=>{let n=[];function t(r){r&&n.push(r)}function i(r){for(const o of r)t(o)}function _(){return n.at(-1)}function c(){return _()?.at(-1)}function l(){const r=_();if(!r)return;const o=r.at(-1),s=r.slice(0,-1);return s?n[n.length-1]=s:n.pop(),o}function e(r,o){n.splice(-r,r,...o.filter(Boolean))}function a(r,o){const s=l();if(!s){i(r),i(o);return}i(r),t(s),i(o)}function h(r){const o=n.at(r);return o?{cp:r,ch:o,width:o.length}:null}function p(r,o){r<0&&(r=n.length+r),!(r<0||r>=n.length)&&(n[r]=o)}return{emit:t,emitPieces:i,lastPiece:_,lastChar:c,popLastChar:l,rewriteTailPieces:e,withLastCharMovedAfter:a,toString:()=>n.join(""),rewriteAt:p,peekAt:h}},vt=n=>{let t=[];function i(){t=[]}function _(){return t.length}function c(s){return t.at(s)}function l(){return t.at(-1)}function e(){return l()?.[0]}function a(){return l()?.[1]?.type}function h(s){return c(s)?.[1]?.type}function p(s){return c(s)?.[0]}function r(s){return a()===s}function o(s){const f=s[0];f!==void 0&&f.length>0&&t.push(s),t.length>n&&t.shift()}return{clear:i,length:_,at:c,last:l,lastText:e,lastType:a,typeAt:h,textAt:p,isLastType:r,push:o}},At=n=>{let t=0;function i(a){const h=n.codePointAt(a);if(h===void 0)return null;const p=String.fromCodePoint(h);return{cp:h,ch:p,width:p.length}}function _(){return i(t)}function c(a){return i(t+a)}function l(a){t+=a}function e(a,h){return n.substring(a,h)}return{get pos(){return t},peek:_,peekAt:i,peekAtOffsetUnits:c,advance:l,slice:e}},nt=(n,t,i,_)=>{for(let c=0;c<i.length;c++){const l=i[i.length-1-c],e=n(t-c);if(e===null)return{matched:!1,matchedLen:0};const a=Y(_,e.ch);if(a===-1||a!==l)return{matched:!1,matchedLen:0}}return{matched:!0,matchedLen:i.length}},rt=(n,t)=>n.map(i=>O(t,i)).filter(Boolean),xt=["²","³","⁴"],P=n=>!!n&&xt.indexOf(n)!==-1,I=n=>n==="Tamil-Extended",z=(n,t,i,_)=>{if(t.length===0)return;if(!_){n.emitPieces(t);return}const c=t[0]??"";if(c[0]===i){const l=c.slice(1),e=[];l&&e.push(l);for(let a=1;a<t.length;a++)e.push(t[a]);n.withLastCharMovedAfter([i],e)}else n.withLastCharMovedAfter(t,[])},wt=[" ",`
2
- `,"\r"," ",",",";","!","@","?","%"],Tt=3;function T(n,t,i,_){const{from_script_name:c,to_script_name:l,from_script_data:e,to_script_data:a,trans_options:h,result:p,prev_context:r,BRAHMIC_HALANT:o,BRAHMIC_NUQTA:s,typing_mode:f}=n;let d=!1;if((s&&r.typeAt(-3)==="vyanjana"&&r.textAt(-2)===s&&r.typeAt(-1)==="mAtrA"||r.typeAt(-2)==="vyanjana"&&r.typeAt(-1)==="mAtrA")&&(!t||t[1]?.type==="anya")&&r.clear(),e.script_type==="brahmic"&&a.script_type==="other")t[0]!==o&&(!(I(c)&&t[0]&&t[0].length>0)||t[0].charAt(0)!==o)&&(!s||t[0]!==s)&&(r.typeAt(-1)==="vyanjana"||s&&r.typeAt(-2)==="vyanjana"&&r.textAt(-1)===s)&&(t[1]?.type!=="mAtrA"&&t[0]!==o||t[1]?.type==="anya"||t[1]===null||t[1]===void 0)&&p.emit(a.schwa_character);else if(e.script_type==="other"&&a.script_type==="brahmic")if(r.typeAt(-1)==="vyanjana"&&(t[1]?.type==="mAtrA"||t[1]?.type==="svara")){const Z=t[1].type==="svara"?O(a,t[1].mAtrA_krama_ref?.[0]??-1):t[0];I(l)&&P(p.lastChar())?z(p,[Z],a.halant,!0):z(p,[Z],a.halant,!1),d=!0}else r.typeAt(-1)==="vyanjana"&&!(t[0]===o||t[1]?.type==="mAtrA")&&(I(l)&&P(p.lastChar())?z(p,[o],a.halant,!0):(z(p,[o],a.halant,!1),l==="Sinhala"&&h["all_to_sinhala:use_conjuct_enabling_halant"]&&p.rewriteAt(-1,p.lastPiece()+"‍")));let b=!1;return f&&(i===void 0||i.length===0)&&!_&&(b=!0,t[1]?.type==="vyanjana"&&(b=!1),b&&r.clear()),(!f||!_&&!b)&&r.push(t),d}function pt(n,t,i){const{custom_rules:_,cursor:c,result:l,from_script_data:e,to_script_data:a}=n,h=t+i;for(let p=0;p<_.length;p++){if(_[p].use_replace===!0)continue;const r=_[p];if(r.type==="replace_prev_krama_keys"){if(r.check_in==="input"){const o=nt(c.peekAt,h,r.prev,e),s=c.peekAt(t);if(o.matched&&s!==null){const f=s.ch,d=Y(e,f);if(d!==-1&&r.following.indexOf(d)!==-1){const b=rt(r.replace_with,a);l.rewriteTailPieces(o.matchedLen,b)}}}else if(r.check_in==="output"){const o=l.lastPiece();if(!o)continue;const s=Y(a,o);if(s!==-1&&r.following.indexOf(s)!==-1){const f=nt(l.peekAt,-2,r.prev,a);if(f.matched){const d=rt(r.replace_with,a);l.rewriteTailPieces(f.matchedLen+1,[...d,o])}}}}else if(r.type==="direct_replace"){const o=r.check_in==="output"?a:e;for(const s of r.to_replace){const f=nt(l.peekAt,-1,s,o);if(!f.matched)continue;if(r.replace_text){l.rewriteTailPieces(f.matchedLen,[r.replace_text]);break}const d=rt(r.replace_with,o);l.rewriteTailPieces(f.matchedLen,d);break}}}}const ut=(n,t,i)=>{if(!i)return{};const _={};for(const[c,l]of Object.entries(i??{})){if(!l||!(c in J))continue;const e=J[c];(e.from_script_type!==void 0&&(e.from_script_type==="all"||e.from_script_type===n.script_type)||e.from_script_name!==void 0&&e.from_script_name.includes(n.script_name))&&(e.to_script_type!==void 0&&(e.to_script_type==="all"||e.to_script_type===t.script_type)||e.to_script_name!==void 0&&e.to_script_name.includes(t.script_name))&&(_[c]=!0)}return _},ht=(n,t)=>n.replace_with.map(i=>O(t,i)).join(""),ft=(n,t,i,_)=>{if(i.length===0)return n;for(const c of i)if(!(c.use_replace!==!0||c.check_in!==_)){if(c.type==="replace_prev_krama_keys"){const l=c.prev.map(e=>O(t,e)).join("");for(let e of c.following){const a=O(t,e);if(!a)continue;const h=ht(c,t)+a;n=n.replaceAll(l+a,h)}}else if(c.type==="direct_replace"){const l=c.to_replace.map(e=>e.map(a=>O(t,a)).join(""));for(let e of l)n=n.replaceAll(e,ht(c,t))}}return n},mt=async(n,t,i,_,c)=>{const l=c?.typing_mode??!1;if(l&&t!=="Normal")throw new Error("Typing mode is only supported with Normal script as the input");const e=await U(t),a=await U(i),h=ut(e,a,_),p=Object.keys(h).flatMap(K=>J[K].rules);n=ft(n,e,p,"input");const r=gt();let o=0;const s=At(n),f=vt(Tt),d=e.script_type==="brahmic"&&a.script_type==="other"||e.script_type==="other"&&a.script_type==="brahmic"||l&&t==="Normal"&&a.script_type==="other",b=e.script_type==="brahmic"&&a.script_type==="other"?e.nuqta??null:e.script_type==="other"&&a.script_type==="brahmic"?a.nuqta??null:null,Z=e.script_type==="brahmic"&&a.script_type==="other"?e.halant:e.script_type==="other"&&a.script_type==="brahmic"?a.halant:null,x={from_script_name:t,to_script_name:i,from_script_data:e,to_script_data:a,trans_options:h,custom_rules:p,cursor:s,result:r,prev_context:f,BRAHMIC_NUQTA:b,BRAHMIC_HALANT:Z,typing_mode:l};let y=-1;for(;s.pos<n.length;){o=s.pos;const K=s.peek();if(!K)break;const ot=K.ch,$=K.width,yt=$===2?1:$;if(y!==-1&&o>=y){y=-1,s.advance($);continue}if(wt.indexOf(ot)!==-1){s.advance($),d&&(T(x,[" ",null]),f.clear()),r.emit(ot);continue}let R=-1;{let S=0,H=-1;const j=d&&e.script_type==="other"&&a.script_type==="brahmic"&&(f.typeAt(-1)==="vyanjana"||b&&f.typeAt(-2)==="vyanjana"&&f.textAt(-1)===b);for(;;){const tt=s.peekAt(o+yt+S),E=tt?.ch??"";y!==-1&&E&&P(E)&&(S+=tt?.width??0);const m=o+yt+S,w=y!==-1?s.slice(o,y)+(m>y?s.slice(y+1,m):""):s.slice(o,m),k=et(e.text_to_krama_map,w,{accessor:(g,L)=>g[L][0]});if(k===-1){R=-1;break}const D=e.text_to_krama_map[k];if(j&&D[1].krama&&D[1].krama.length>=1){const g=D[1].krama,L=g[0],N=a.krama_text_arr[L]?.[1],_t=a.list[N??-1]?.type;if(g.length===1&&N!==null&&N!==void 0&&(_t==="svara"||_t==="mAtrA"))H=k;else if(H!==-1){R=H;break}}if(D[1].next&&D[1].next.length>0){const g=s.peekAt(m),L=g?.ch;if(I(t)&&e.script_type==="brahmic"){const F=g?s.peekAt(m+g.width):null,N=F?.ch,W=(g&&F?s.peekAt(m+g.width+F.width):null)?.ch;if(y===-1&&N!==void 0&&P(N)&&D[1].next.indexOf(N)!==-1){const Q=et(e.text_to_krama_map,w+N,{accessor:(M,v)=>M[v][0]}),V=C(e.krama_text_arr,e.krama_text_arr_index,L??"",{accessor:(M,v)=>M[v][0]});if(Q!==-1&&V!==-1){R=Q;const M=e.krama_text_arr[V],v=e.list[M[1]??-1]?.type;if(L===e.halant||v==="mAtrA"){y=m+(g?.width??0);break}}}else if(y===-1&&W!==void 0&&P(W)&&D[1].next.indexOf(W)!==-1){const Q=et(e.text_to_krama_map,w+W,{accessor:(v,G)=>v[G][0]}),V=C(e.krama_text_arr,e.krama_text_arr_index,L??"",{accessor:(v,G)=>v[G][0]}),M=C(e.krama_text_arr,e.krama_text_arr_index,N??"",{accessor:(v,G)=>v[G][0]});if(Q!==-1&&V!==-1&&M!==-1){const v=e.krama_text_arr[V],G=e.krama_text_arr[M];R=Q;const Dt=e.list[v[1]??-1]?.type,Mt=e.list[G[1]??-1]?.type;if(Dt==="mAtrA"&&Mt==="mAtrA"){y=m+(g?.width??0)+(F?.width??0);break}}}}if(L!==void 0&&D[1].next.indexOf(L)!==-1){S+=g?.width??0;continue}}R=k;break}}const u=R!==-1?e.text_to_krama_map[R]:null;if(u!==null){const S=y!==-1&&u[0].length>1&&e.list[e.krama_text_arr[u[1].krama?.[0]??-1]?.[1]??-1]?.type==="vyanjana"&&P(u[0].at(-1)??void 0)?1:0,H=u[0].length-S;if(s.advance(H),o=s.pos,u[1].krama!==null&&u[1].krama!==void 0&&u[1].krama.some(j=>j!==-1)){const j=u[1].krama.map(m=>O(a,m)),tt=j.join("");let E=!1;if(d)if(e.script_type==="brahmic"&&a.script_type==="other"){let m=null;if(u[1].fallback_list_ref!==void 0&&u[1].fallback_list_ref!==null)m=e.list[u[1].fallback_list_ref];else if(!u[1].krama||u[1].krama.length===0)m=null;else{const w=u[1].krama.map(k=>e.list[e.krama_text_arr[k][1]??-1]);I(t)&&w.some(k=>k?.type==="mAtrA")&&w.some(k=>k?.type==="vyanjana")?m={...w[0],type:"anya"}:I(t)&&w.length>1&&w.some(k=>k==null)?m=w.at(-1):m=w[0]}E=T(x,[u[0],m])}else if(a.script_type==="brahmic"&&e.script_type==="other"){let m=null;u[1].fallback_list_ref!==void 0&&u[1].fallback_list_ref!==null?m=a.list[u[1].fallback_list_ref]:m=u[1].krama&&u[1].krama.length>0?a.list[a.krama_text_arr[u[1].krama[0]]?.[1]??-1]??null:null,l&&t==="Normal"?E=T(x,[u[0],m],u[1].next??void 0):E=T(x,[u[0],m])}else l&&t==="Normal"&&a.script_type==="other"&&(E=T(x,[u[0],null],u[1].next??void 0));E||(a.script_type==="brahmic"&&I(i)&&(a.list[u[1].krama?.at(-1)??-1]?.type==="mAtrA"||tt===a.halant)&&P(r.lastChar())?z(r,j,a.halant,!0):r.emitPieces(j)),pt(x,o,-H);continue}else if(u[1].krama!==null&&u[1].krama!==void 0&&u[1].krama.some(j=>j===-1)){r.emit(u[0]),l&&T(x,[u[0],null],u[1].next??void 0);continue}}else s.advance($),o=s.pos;const X=u===null?ot:u[0],q=Y(e,X);if(q===-1){d&&(T(x,[X,null]),f.clear()),r.emit(X);continue}let st=!1;if(d&&(e.script_type==="brahmic"?st=T(x,[X,e.list[e.krama_text_arr[q][1]??-1]]):a.script_type==="brahmic"&&(st=T(x,[X,a.list[a.krama_text_arr[q][1]??-1]]))),!st){const S=O(a,q);a.script_type==="brahmic"&&I(i)&&(a.list[a.krama_text_arr[q][1]??-1]?.type==="mAtrA"||S===a.halant)&&P(r.lastChar())?z(r,[S],a.halant,!0):r.emit(S)}pt(x,o,-$)}d&&T(x,[void 0,null],void 0,!0);let lt=r.toString();return lt=ft(lt,a,p,"output"),{output:lt,context_length:f.length()}},bt={script_list:{Devanagari:1,Telugu:2,Tamil:3,"Tamil-Extended":4,Bengali:5,Kannada:6,Gujarati:7,Malayalam:8,Odia:9,Sinhala:10,Normal:11,Romanized:12,Gurumukhi:13,Assamese:14,"Purna-Devanagari":15,Brahmi:16,Granth:17,Modi:18,Sharada:20,Siddham:21},lang_list:{English:1,Sanskrit:2,Hindi:3,Telugu:4,Tamil:5,Bengali:6,Kannada:7,Gujarati:8,Malayalam:9,Odia:10,Sinhala:11,Marathi:12,Nepali:13,Punjabi:14,Assamese:15}},{script_list:St,lang_list:jt}=bt,it=Object.keys(St),ct=Object.keys(jt),Lt=Array.from(new Set([...ct,...it])),Nt={Bengali:"Bengali",Gujarati:"Gujarati",Hindi:"Devanagari",Kannada:"Kannada",Malayalam:"Malayalam",Odia:"Odia",Sinhala:"Sinhala",Tamil:"Tamil",Telugu:"Telugu",English:"Normal",Sanskrit:"Devanagari",Marathi:"Devanagari",Nepali:"Devanagari",Punjabi:"Gurumukhi",Assamese:"Assamese"},dt={dev:"Devanagari",te:"Telugu",tel:"Telugu",tam:"Tamil","tam-ex":"Tamil-Extended",ben:"Bengali",be:"Bengali",ka:"Kannada",kan:"Kannada",gu:"Gujarati",guj:"Gujarati",mal:"Malayalam",or:"Odia",od:"Odia",oriya:"Odia",si:"Sinhala",sinh:"Sinhala",sin:"Sinhala",en:"Normal",eng:"Normal",la:"Normal",lat:"Normal",nor:"Normal",norm:"Normal",rom:"Romanized",gur:"Gurumukhi",as:"Assamese",sa:"Devanagari",san:"Devanagari",hin:"Devanagari",hi:"Devanagari",mar:"Devanagari",ne:"Devanagari",nep:"Devanagari",pun:"Gurumukhi"};function Ct(n){return n.toLowerCase().replace(/(^|-)([a-z])/g,(t,i,_)=>i+_.toUpperCase())}const B=n=>{const t=Ct(n);return it.includes(t)?t:ct.includes(t)?Nt[t]:n.toLocaleLowerCase()in dt?dt[n.toLocaleLowerCase()]:null},Ot=async n=>{const t=B(n);if(!t)throw new Error(`Invalid script name: ${n}`);return await U(t)};async function Pt(n,t,i,_){const c=B(t);if(!c)throw new Error(`Invalid script name: ${t}`);const l=B(i);if(!l)throw new Error(`Invalid script name: ${i}`);return c===l?n:(await mt(n,c,l,_)).output}async function It(n,t){const i=B(n);if(!i)throw new Error(`Invalid script name: ${n}`);const _=B(t);if(!_)throw new Error(`Invalid script name: ${t}`);const c=await U(i),l=await U(_);return Object.keys(ut(c,l,Object.fromEntries(Object.keys(J).map(e=>[e,!0]))))}async function Et(n,t){const i=B(t);if(!i)throw new Error(`Invalid script name: ${t}`);let _="",c="",l="";for(let e=0;e<n.length;e++){c+=n[e];const{context_length:a,output:h}=await mt(c,"Normal",i,{},{typing_mode:!0});a>0?l=h:a===0&&(c="",l="",_+=h)}return l.length>0&&(_+=l),_}A.ALL_LANG_SCRIPT_LIST=Lt,A.LANG_LIST=ct,A.SCRIPT_LIST=it,A.emulateTyping=Et,A.getAllOptions=It,A.preloadScriptData=Ot,A.transliterate=Pt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(g=typeof globalThis<"u"?globalThis:g||self,L(g.lipilekhika={}))})(this,(function(g){"use strict";function L(t,e,r,n){const{accessor:a,compareFn:s}=n??{},c=a??((i,l)=>i[l]);let u=0,_=e.length-1,o=-1;for(;u<=_;){const i=Math.floor((u+_)/2),l=e[i],p=c(t,l);let h;s?h=s(r,p):h=r<p?-1:r>p?1:0,h===0?(o=l,_=i-1):h<0?_=i-1:u=i+1}return o}function ee(t,e,r){const{accessor:n,compareFn:a}=r??{},s=n??((o,i)=>o[i]);let c=0,u=t.length-1,_=-1;for(;c<=u;){const o=Math.floor((c+u)/2),i=s(t,o);let l;a?l=a(e,i):l=e<i?-1:e>i?1:0,l===0?(_=o,u=o-1):l<0?u=o-1:c=o+1}return _}const te={},M=async t=>{{if(te[t])return te[t];const r=`https://cdn.jsdelivr.net/npm/lipilekhika@0.0.0-alpha.21/dist/umd_json/script_data/${t}.json`,a=(await fetch(r)).json();return te[t]=a,a}},V={"all_to_normal:replace_pancham_varga_varna_with_n":{from_script_type:"all",to_script_name:["Normal"],check_in:"output",rules:[{type:"replace_prev_krama_keys",check_in:"output",prev:[60],following:[52,53,54,55,56,57,58,59],replace_with:[72]},{type:"replace_prev_krama_keys",check_in:"output",prev:[67],following:[61,62,63,64,65,66],replace_with:[72]}]},"brahmic_to_brahmic:replace_pancham_varga_varna_with_anuvsvAra":{from_script_type:"brahmic",to_script_type:"brahmic",check_in:"input",rules:[{type:"replace_prev_krama_keys",check_in:"input",prev:[60,49],following:[52,53,54,55,56,57,58,59],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[67,49],following:[61,62,63,64,65,66],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[81,49],following:[74,75,76,77,78,79,80],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[72,49],following:[68,69,70,71],replace_with:[45]},{type:"replace_prev_krama_keys",check_in:"input",prev:[88,49],following:[82,83,85,86,87],replace_with:[45]}]},"all_to_sinhala:use_conjuct_enabling_halant":{from_script_type:"all",to_script_name:["Sinhala"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[49]],replace_text:"්‍",replace_with:[]}]},"all_to_normal:remove_virAma_and_double_virAma":{from_script_type:"all",to_script_name:["Normal","Romanized"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[116],[115]],replace_with:[-1]}]},"all_to_normal:replace_avagraha_with_a":{from_script_type:"all",to_script_name:["Normal","Romanized"],check_in:"output",rules:[{type:"direct_replace",check_in:"output",to_replace:[[48]],replace_with:[1]}]}},de=(t,e)=>{const r=t.krama_text_arr[e]?.[0];return typeof r=="string"?r:null},j=(t,e)=>de(t,e)??"",Y=(t,e)=>L(t.krama_text_arr,t.krama_text_arr_index,e,{accessor:(r,n)=>r[n][0]}),ge=()=>{let t=[];function e(i){i&&t.push(i)}function r(i){for(const l of i)e(l)}function n(){return t.at(-1)}function a(){return n()?.at(-1)}function s(){const i=n();if(!i)return;const l=i.at(-1),p=i.slice(0,-1);return p?t[t.length-1]=p:t.pop(),l}function c(i,l){t.splice(-i,i,...l.filter(Boolean))}function u(i,l){const p=s();if(!p){r(i),r(l);return}r(i),e(p),r(l)}function _(i){const l=t.at(i);return l?{cp:i,ch:l,width:l.length}:null}function o(i,l){i<0&&(i=t.length+i),!(i<0||i>=t.length)&&(t[i]=l)}return{emit:e,emitPieces:r,lastPiece:n,lastChar:a,popLastChar:s,rewriteTailPieces:c,withLastCharMovedAfter:u,toString:()=>t.join(""),rewriteAt:o,peekAt:_}},ve=t=>{let e=[];function r(){e=[]}function n(){return e.length}function a(p){return e.at(p)}function s(){return e.at(-1)}function c(){return s()?.[0]}function u(){return s()?.[1]?.type}function _(p){return a(p)?.[1]?.type}function o(p){return a(p)?.[0]}function i(p){return u()===p}function l(p){const h=p[0];h!==void 0&&h.length>0&&e.push(p),e.length>t&&e.shift()}return{clear:r,length:n,at:a,last:s,lastText:c,lastType:u,typeAt:_,textAt:o,isLastType:i,push:l}},xe=t=>{let e=0;function r(u){const _=t.codePointAt(u);if(_===void 0)return null;const o=String.fromCodePoint(_);return{cp:_,ch:o,width:o.length}}function n(){return r(e)}function a(u){return r(e+u)}function s(u){e+=u}function c(u,_){return t.substring(u,_)}return{get pos(){return e},peek:n,peekAt:r,peekAtOffsetUnits:a,advance:s,slice:c}},ne=(t,e,r,n)=>{for(let a=0;a<r.length;a++){const s=r[r.length-1-a],c=t(e-a);if(c===null)return{matched:!1,matchedLen:0};const u=Y(n,c.ch);if(u===-1||u!==s)return{matched:!1,matchedLen:0}}return{matched:!0,matchedLen:r.length}},ae=(t,e)=>t.map(r=>j(e,r)).filter(Boolean),Ae=["²","³","⁴"],I=t=>!!t&&Ae.indexOf(t)!==-1,P=t=>t==="Tamil-Extended",B=(t,e,r,n)=>{if(e.length===0)return;if(!n){t.emitPieces(e);return}const a=e[0]??"";if(a[0]===r){const s=a.slice(1),c=[];s&&c.push(s);for(let u=1;u<e.length;u++)c.push(e[u]);t.withLastCharMovedAfter([r],c)}else t.withLastCharMovedAfter(e,[])},we=[" ",`
2
+ `,"\r"," ",",",";","!","@","?","%"],Te=3;function b(t,e,r){const{from_script_name:n,to_script_name:a,from_script_data:s,to_script_data:c,trans_options:u,result:_,prev_context:o,BRAHMIC_HALANT:i,BRAHMIC_NUQTA:l,typing_mode:p}=t,{next:h,last_extra_call:d}=r??{};let v=!1;if((l&&o.typeAt(-3)==="vyanjana"&&o.textAt(-2)===l&&o.typeAt(-1)==="mAtrA"||o.typeAt(-2)==="vyanjana"&&o.typeAt(-1)==="mAtrA")&&(!e||e[1]?.type==="anya")&&o.clear(),s.script_type==="brahmic"&&c.script_type==="other")e[0]!==i&&(!(P(n)&&e[0]&&e[0].length>0)||e[0].charAt(0)!==i)&&(!l||e[0]!==l)&&(o.typeAt(-1)==="vyanjana"||l&&o.typeAt(-2)==="vyanjana"&&o.textAt(-1)===l)&&(e[1]?.type!=="mAtrA"&&e[0]!==i||e[1]?.type==="anya"||e[1]===null||e[1]===void 0)&&_.emit(c.schwa_character);else if(s.script_type==="other"&&c.script_type==="brahmic")if(o.typeAt(-1)==="vyanjana"&&(e[1]?.type==="mAtrA"||e[1]?.type==="svara")){const k=e[1].type==="svara"?j(c,e[1].mAtrA_krama_ref?.[0]??-1):e[0];P(a)&&I(_.lastChar())?B(_,[k],c.halant,!0):B(_,[k],c.halant,!1),v=!0}else o.typeAt(-1)==="vyanjana"&&!(e[0]===i||e[1]?.type==="mAtrA")&&(P(a)&&I(_.lastChar())?B(_,[i],c.halant,!0):(B(_,[i],c.halant,!1),a==="Sinhala"&&u["all_to_sinhala:use_conjuct_enabling_halant"]&&_.rewriteAt(-1,_.lastPiece()+"‍")));let m=!1;return p&&(h===void 0||h.length===0)&&!d&&(m=!0,e[1]?.type==="vyanjana"&&(m=!1),m&&o.clear()),(!p||!d&&!m)&&o.push(e),v}function ue(t,e,r){const{custom_rules:n,cursor:a,result:s,from_script_data:c,to_script_data:u}=t,_=e+r;for(let o=0;o<n.length;o++){if(n[o].use_replace===!0)continue;const i=n[o];if(i.type==="replace_prev_krama_keys"){if(i.check_in==="input"){const l=ne(a.peekAt,_,i.prev,c),p=a.peekAt(e);if(l.matched&&p!==null){const h=p.ch,d=Y(c,h);if(d!==-1&&i.following.indexOf(d)!==-1){const v=ae(i.replace_with,u);s.rewriteTailPieces(l.matchedLen,v)}}}else if(i.check_in==="output"){const l=s.lastPiece();if(!l)continue;const p=Y(u,l);if(p!==-1&&i.following.indexOf(p)!==-1){const h=ne(s.peekAt,-2,i.prev,u);if(h.matched){const d=ae(i.replace_with,u);s.rewriteTailPieces(h.matchedLen+1,[...d,l])}}}}else if(i.type==="direct_replace"){const l=i.check_in==="output"?u:c;for(const p of i.to_replace){const h=ne(s.peekAt,-1,p,l);if(!h.matched)continue;if(i.replace_text){s.rewriteTailPieces(h.matchedLen,[i.replace_text]);break}const d=ae(i.replace_with,l);s.rewriteTailPieces(h.matchedLen,d);break}}}}const _e=(t,e,r)=>{if(!r)return{};const n={};for(const[a,s]of Object.entries(r??{})){if(!s||!(a in V))continue;const c=V[a];(c.from_script_type!==void 0&&(c.from_script_type==="all"||c.from_script_type===t.script_type)||c.from_script_name!==void 0&&c.from_script_name.includes(t.script_name))&&(c.to_script_type!==void 0&&(c.to_script_type==="all"||c.to_script_type===e.script_type)||c.to_script_name!==void 0&&c.to_script_name.includes(e.script_name))&&(n[a]=!0)}return n},pe=(t,e,r)=>{const n=_e(t,e,r),a=Object.keys(n).flatMap(s=>V[s].rules);return{trans_options:n,custom_rules:a}},he=(t,e)=>t.replace_with.map(r=>j(e,r)).join(""),fe=(t,e,r,n)=>{if(r.length===0)return t;for(const a of r)if(!(a.use_replace!==!0||a.check_in!==n)){if(a.type==="replace_prev_krama_keys"){const s=a.prev.map(c=>j(e,c)).join("");for(let c of a.following){const u=j(e,c);if(!u)continue;const _=he(a,e)+u;t=t.replaceAll(s+u,_)}}else if(a.type==="direct_replace"){const s=a.to_replace.map(c=>c.map(u=>j(e,u)).join(""));for(let c of s)t=t.replaceAll(c,he(a,e))}}return t},me=(t,e,r,n,a,s,c,u)=>{const _=u?.typing_mode??!1;if(_&&e!=="Normal")throw new Error("Typing mode is only supported with Normal script as the input");t=fe(t,n,c,"input");const o=ge();let i=0;const l=xe(t),p=ve(Te),h=n.script_type==="brahmic"&&a.script_type==="other"||n.script_type==="other"&&a.script_type==="brahmic"||_&&e==="Normal"&&a.script_type==="other",d=n.script_type==="brahmic"&&a.script_type==="other"?n.nuqta??null:n.script_type==="other"&&a.script_type==="brahmic"?a.nuqta??null:null,v=n.script_type==="brahmic"&&a.script_type==="other"?n.halant:n.script_type==="other"&&a.script_type==="brahmic"?a.halant:null,m={from_script_name:e,to_script_name:r,from_script_data:n,to_script_data:a,trans_options:s,custom_rules:c,cursor:l,result:o,prev_context:p,BRAHMIC_NUQTA:d,BRAHMIC_HALANT:v,typing_mode:_};let k=-1;for(;l.pos<t.length;){i=l.pos;const le=l.peek();if(!le)break;const ce=le.ch,H=le.width,ke=H===2?1:H;if(k!==-1&&i>=k){k=-1,l.advance(H);continue}if(we.indexOf(ce)!==-1){l.advance(H),h&&(b(m,[" ",null]),p.clear()),o.emit(ce);continue}let G=-1;{let S=0,U=-1;const E=h&&n.script_type==="other"&&a.script_type==="brahmic"&&(p.typeAt(-1)==="vyanjana"||d&&p.typeAt(-2)==="vyanjana"&&p.textAt(-1)===d);for(;;){const Z=l.peekAt(i+ke+S),O=Z?.ch??"";k!==-1&&O&&I(O)&&(S+=Z?.width??0);const y=i+ke+S,T=k!==-1?l.slice(i,k)+(y>k?l.slice(k+1,y):""):l.slice(i,y),x=ee(n.text_to_krama_map,T,{accessor:(A,N)=>A[N][0]});if(x===-1){G=-1;break}const D=n.text_to_krama_map[x];if(E&&D[1].krama&&D[1].krama.length>=1){const A=D[1].krama,N=A[0],C=a.krama_text_arr[N]?.[1],se=a.list[C??-1]?.type;if(A.length===1&&C!==null&&C!==void 0&&(se==="svara"||se==="mAtrA"))U=x;else if(U!==-1){G=U;break}}if(D[1].next&&D[1].next.length>0){const A=l.peekAt(y),N=A?.ch;if(P(e)&&n.script_type==="brahmic"){const q=A?l.peekAt(y+A.width):null,C=q?.ch,F=(A&&q?l.peekAt(y+A.width+q.width):null)?.ch;if(k===-1&&C!==void 0&&I(C)&&D[1].next.indexOf(C)!==-1){const W=ee(n.text_to_krama_map,T+C,{accessor:(R,w)=>R[w][0]}),Q=L(n.krama_text_arr,n.krama_text_arr_index,N??"",{accessor:(R,w)=>R[w][0]});if(W!==-1&&Q!==-1){G=W;const R=n.krama_text_arr[Q],w=n.list[R[1]??-1]?.type;if(N===n.halant||w==="mAtrA"){k=y+(A?.width??0);break}}}else if(k===-1&&F!==void 0&&I(F)&&D[1].next.indexOf(F)!==-1){const W=ee(n.text_to_krama_map,T+F,{accessor:(w,K)=>w[K][0]}),Q=L(n.krama_text_arr,n.krama_text_arr_index,N??"",{accessor:(w,K)=>w[K][0]}),R=L(n.krama_text_arr,n.krama_text_arr_index,C??"",{accessor:(w,K)=>w[K][0]});if(W!==-1&&Q!==-1&&R!==-1){const w=n.krama_text_arr[Q],K=n.krama_text_arr[R];G=W;const Be=n.list[w[1]??-1]?.type,ze=n.list[K[1]??-1]?.type;if(Be==="mAtrA"&&ze==="mAtrA"){k=y+(A?.width??0)+(q?.width??0);break}}}}if(N!==void 0&&D[1].next.indexOf(N)!==-1){S+=A?.width??0;continue}}G=x;break}}const f=G!==-1?n.text_to_krama_map[G]:null;if(f!==null){const S=k!==-1&&f[0].length>1&&n.list[n.krama_text_arr[f[1].krama?.[0]??-1]?.[1]??-1]?.type==="vyanjana"&&I(f[0].at(-1)??void 0)?1:0,U=f[0].length-S;if(l.advance(U),i=l.pos,f[1].krama!==null&&f[1].krama!==void 0&&f[1].krama.some(E=>E!==-1)){const E=f[1].krama.map(y=>j(a,y)),Z=E.join("");let O=!1;if(h)if(n.script_type==="brahmic"&&a.script_type==="other"){let y=null;if(f[1].fallback_list_ref!==void 0&&f[1].fallback_list_ref!==null)y=n.list[f[1].fallback_list_ref];else if(!f[1].krama||f[1].krama.length===0)y=null;else{const T=f[1].krama.map(x=>n.list[n.krama_text_arr[x][1]??-1]);P(e)&&T.some(x=>x?.type==="mAtrA")&&T.some(x=>x?.type==="vyanjana")?y={...T[0],type:"anya"}:P(e)&&T.length>1&&T.some(x=>x==null)?y=T.at(-1):y=T[0]}O=b(m,[f[0],y])}else if(a.script_type==="brahmic"&&n.script_type==="other"){let y=null;f[1].fallback_list_ref!==void 0&&f[1].fallback_list_ref!==null?y=a.list[f[1].fallback_list_ref]:y=f[1].krama&&f[1].krama.length>0?a.list[a.krama_text_arr[f[1].krama[0]]?.[1]??-1]??null:null,_&&e==="Normal"?O=b(m,[f[0],y],{next:f[1].next??void 0}):O=b(m,[f[0],y])}else _&&e==="Normal"&&a.script_type==="other"&&(O=b(m,[f[0],null],{next:f[1].next??void 0}));O||(a.script_type==="brahmic"&&P(r)&&(a.list[f[1].krama?.at(-1)??-1]?.type==="mAtrA"||Z===a.halant)&&I(o.lastChar())?B(o,E,a.halant,!0):o.emitPieces(E)),ue(m,i,-U);continue}else if(f[1].krama!==null&&f[1].krama!==void 0&&f[1].krama.some(E=>E===-1)){o.emit(f[0]),_&&b(m,[f[0],null],{next:f[1].next??void 0});continue}}else l.advance(H),i=l.pos;const $=f===null?ce:f[0],X=Y(n,$);if(X===-1){h&&(b(m,[$,null]),p.clear()),o.emit($);continue}let oe=!1;if(h&&(n.script_type==="brahmic"?oe=b(m,[$,n.list[n.krama_text_arr[X][1]??-1]]):a.script_type==="brahmic"&&(oe=b(m,[$,a.list[a.krama_text_arr[X][1]??-1]]))),!oe){const S=j(a,X);a.script_type==="brahmic"&&P(r)&&(a.list[a.krama_text_arr[X][1]??-1]?.type==="mAtrA"||S===a.halant)&&I(o.lastChar())?B(o,[S],a.halant,!0):o.emit(S)}ue(m,i,-H)}h&&b(m,[void 0,null],{last_extra_call:!0});let J=o.toString();return J=fe(J,a,c,"output"),{output:J,context_length:p.length()}},be=async(t,e,r,n,a)=>{const[s,c]=await Promise.all([M(e),M(r)]),{trans_options:u,custom_rules:_}=pe(s,c,n);return me(t,e,r,s,c,u,_,a)},Se={script_list:{Devanagari:1,Telugu:2,Tamil:3,"Tamil-Extended":4,Bengali:5,Kannada:6,Gujarati:7,Malayalam:8,Odia:9,Sinhala:10,Normal:11,Romanized:12,Gurumukhi:13,Assamese:14,"Purna-Devanagari":15,Brahmi:16,Granth:17,Modi:18,Sharada:20,Siddham:21},lang_list:{English:1,Sanskrit:2,Hindi:3,Telugu:4,Tamil:5,Bengali:6,Kannada:7,Gujarati:8,Malayalam:9,Odia:10,Sinhala:11,Marathi:12,Nepali:13,Punjabi:14,Assamese:15}},{script_list:Ee,lang_list:Ne}=Se,re=Object.keys(Ee),ie=Object.keys(Ne),Ce=Array.from(new Set([...ie,...re])),Le={Bengali:"Bengali",Gujarati:"Gujarati",Hindi:"Devanagari",Kannada:"Kannada",Malayalam:"Malayalam",Odia:"Odia",Sinhala:"Sinhala",Tamil:"Tamil",Telugu:"Telugu",English:"Normal",Sanskrit:"Devanagari",Marathi:"Devanagari",Nepali:"Devanagari",Punjabi:"Gurumukhi",Assamese:"Assamese"},ye={dev:"Devanagari",te:"Telugu",tel:"Telugu",tam:"Tamil","tam-ex":"Tamil-Extended",ben:"Bengali",be:"Bengali",ka:"Kannada",kan:"Kannada",gu:"Gujarati",guj:"Gujarati",mal:"Malayalam",or:"Odia",od:"Odia",oriya:"Odia",si:"Sinhala",sinh:"Sinhala",sin:"Sinhala",en:"Normal",eng:"Normal",la:"Normal",lat:"Normal",nor:"Normal",norm:"Normal",rom:"Romanized",gur:"Gurumukhi",as:"Assamese",sa:"Devanagari",san:"Devanagari",hin:"Devanagari",hi:"Devanagari",mar:"Devanagari",ne:"Devanagari",nep:"Devanagari",pun:"Gurumukhi"};function je(t){return t.toLowerCase().replace(/(^|-)([a-z])/g,(e,r,n)=>r+n.toUpperCase())}const z=t=>{const e=je(t);return re.includes(e)?e:ie.includes(e)?Le[e]:t.toLocaleLowerCase()in ye?ye[t.toLocaleLowerCase()]:null},Ie=async t=>{const e=z(t);if(!e)throw new Error(`Invalid script name: ${t}`);return await M(e)};async function Pe(t,e,r,n){const a=z(e);if(!a)throw new Error(`Invalid script name: ${e}`);const s=z(r);if(!s)throw new Error(`Invalid script name: ${r}`);return a===s?t:(await be(t,a,s,n)).output}async function Oe(t,e){const r=z(t);if(!r)throw new Error(`Invalid script name: ${t}`);const n=z(e);if(!n)throw new Error(`Invalid script name: ${e}`);const a=await M(r),s=await M(n);return Object.keys(_e(a,s,Object.fromEntries(Object.keys(V).map(c=>[c,!0]))))}function De(t){const e=z(t);if(!e)throw new Error(`Invalid script name: ${t}`);let r="",n="",a=null,s=null,c={},u=[];const _=(async()=>{const[l,p]=await Promise.all([M("Normal"),M(e)]);a=l,s=p;const h=pe(l,p);c=h.trans_options,u=h.custom_rules})();function o(){r="",n=""}function i(l){if(!a||!s)throw new Error("Typing context not ready. Await `ctx.ready` before calling takeKeyInputSync.");let p=l?.[0]??"";r+=p;let h=n;const{context_length:d,output:v}=me(r,"Normal",e,a,s,c,u,{typing_mode:!0});d>0?n=v:d===0&&(r="",n="");let m=0;for(;m<v.length&&m<h.length&&v[m]===h[m];)m++;let k=v.substring(m);return{to_delete_chars_count:h.length-m,diff_add_text:k}}return{ready:_,clearContext:o,takeKeyInput:i,getCurrentOutput:()=>n}}function Re(t){return"nativeEvent"in t?t.nativeEvent:t}async function Me(t,e,r){const n=e.currentTarget,a=Re(e);if(typeof InputEvent<"u"&&a instanceof InputEvent&&a.data!==null){await t.ready;const{diff_add_text:c,to_delete_chars_count:u}=t.takeKeyInput(a.data),_=n.value,o=(n.selectionStart??0)+1,i=o-u-2,l=_.substring(0,i),p=c;let h="";const d=_.length+1===o,v=_.length+1!==o;d?h=_.substring(o+1):v&&(h=_.substring(o-1));const m=l.length+p.length,k=l+p+h;n.value=k,n.focus(),n.selectionStart=m,n.selectionEnd=m,r?.(k)}else r?.(n.value),t.clearContext()}const Ge=new Set(["Backspace","Delete","Enter","Tab","Escape","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]);function Ke(t,e){if(t.isComposing)return!1;const r=t.key;return!r||r==="Unidentified"||r==="Process"||r==="Dead"||t.ctrlKey||t.metaKey||t.altKey?!1:Ge.has(r)?(e.clearContext(),!0):!1}g.ALL_LANG_SCRIPT_LIST=Ce,g.LANG_LIST=ie,g.SCRIPT_LIST=re,g.clearTypingContextOnKeyDown=Ke,g.createTypingContext=De,g.getAllOptions=Oe,g.handleTypingInputEvent=Me,g.preloadScriptData=Ie,g.transliterate=Pe,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,220 @@
1
+ declare const _default: {
2
+ "all_to_normal:replace_pancham_varga_varna_with_n": {
3
+ "from_script_type": "all",
4
+ "to_script_name": [
5
+ "Normal"
6
+ ],
7
+ "check_in": "output",
8
+ "rules": [
9
+ {
10
+ "type": "replace_prev_krama_keys",
11
+ "check_in": "output",
12
+ "prev": [
13
+ 60
14
+ ],
15
+ "following": [
16
+ 52,
17
+ 53,
18
+ 54,
19
+ 55,
20
+ 56,
21
+ 57,
22
+ 58,
23
+ 59
24
+ ],
25
+ "replace_with": [
26
+ 72
27
+ ]
28
+ },
29
+ {
30
+ "type": "replace_prev_krama_keys",
31
+ "check_in": "output",
32
+ "prev": [
33
+ 67
34
+ ],
35
+ "following": [
36
+ 61,
37
+ 62,
38
+ 63,
39
+ 64,
40
+ 65,
41
+ 66
42
+ ],
43
+ "replace_with": [
44
+ 72
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ "brahmic_to_brahmic:replace_pancham_varga_varna_with_anuvsvAra": {
50
+ "from_script_type": "brahmic",
51
+ "to_script_type": "brahmic",
52
+ "check_in": "input",
53
+ "rules": [
54
+ {
55
+ "type": "replace_prev_krama_keys",
56
+ "check_in": "input",
57
+ "prev": [
58
+ 60,
59
+ 49
60
+ ],
61
+ "following": [
62
+ 52,
63
+ 53,
64
+ 54,
65
+ 55,
66
+ 56,
67
+ 57,
68
+ 58,
69
+ 59
70
+ ],
71
+ "replace_with": [
72
+ 45
73
+ ]
74
+ },
75
+ {
76
+ "type": "replace_prev_krama_keys",
77
+ "check_in": "input",
78
+ "prev": [
79
+ 67,
80
+ 49
81
+ ],
82
+ "following": [
83
+ 61,
84
+ 62,
85
+ 63,
86
+ 64,
87
+ 65,
88
+ 66
89
+ ],
90
+ "replace_with": [
91
+ 45
92
+ ]
93
+ },
94
+ {
95
+ "type": "replace_prev_krama_keys",
96
+ "check_in": "input",
97
+ "prev": [
98
+ 81,
99
+ 49
100
+ ],
101
+ "following": [
102
+ 74,
103
+ 75,
104
+ 76,
105
+ 77,
106
+ 78,
107
+ 79,
108
+ 80
109
+ ],
110
+ "replace_with": [
111
+ 45
112
+ ]
113
+ },
114
+ {
115
+ "type": "replace_prev_krama_keys",
116
+ "check_in": "input",
117
+ "prev": [
118
+ 72,
119
+ 49
120
+ ],
121
+ "following": [
122
+ 68,
123
+ 69,
124
+ 70,
125
+ 71
126
+ ],
127
+ "replace_with": [
128
+ 45
129
+ ]
130
+ },
131
+ {
132
+ "type": "replace_prev_krama_keys",
133
+ "check_in": "input",
134
+ "prev": [
135
+ 88,
136
+ 49
137
+ ],
138
+ "following": [
139
+ 82,
140
+ 83,
141
+ 85,
142
+ 86,
143
+ 87
144
+ ],
145
+ "replace_with": [
146
+ 45
147
+ ]
148
+ }
149
+ ]
150
+ },
151
+ "all_to_sinhala:use_conjuct_enabling_halant": {
152
+ "from_script_type": "all",
153
+ "to_script_name": [
154
+ "Sinhala"
155
+ ],
156
+ "check_in": "output",
157
+ "rules": [
158
+ {
159
+ "type": "direct_replace",
160
+ "check_in": "output",
161
+ "to_replace": [
162
+ [
163
+ 49
164
+ ]
165
+ ],
166
+ "replace_text": "්‍",
167
+ "replace_with": []
168
+ }
169
+ ]
170
+ },
171
+ "all_to_normal:remove_virAma_and_double_virAma": {
172
+ "from_script_type": "all",
173
+ "to_script_name": [
174
+ "Normal",
175
+ "Romanized"
176
+ ],
177
+ "check_in": "output",
178
+ "rules": [
179
+ {
180
+ "type": "direct_replace",
181
+ "check_in": "output",
182
+ "to_replace": [
183
+ [
184
+ 116
185
+ ],
186
+ [
187
+ 115
188
+ ]
189
+ ],
190
+ "replace_with": [
191
+ -1
192
+ ]
193
+ }
194
+ ]
195
+ },
196
+ "all_to_normal:replace_avagraha_with_a": {
197
+ "from_script_type": "all",
198
+ "to_script_name": [
199
+ "Normal",
200
+ "Romanized"
201
+ ],
202
+ "check_in": "output",
203
+ "rules": [
204
+ {
205
+ "type": "direct_replace",
206
+ "check_in": "output",
207
+ "to_replace": [
208
+ [
209
+ 48
210
+ ]
211
+ ],
212
+ "replace_with": [
213
+ 1
214
+ ]
215
+ }
216
+ ]
217
+ }
218
+ };
219
+
220
+ export default _default;
@@ -0,0 +1,100 @@
1
+ import { CustomOptionType } from './transliteration/transliterate';
2
+ import { script_input_name_type } from './utils/lang_list/script_normalization';
3
+ import { SCRIPT_LIST, LANG_LIST, ALL_LANG_SCRIPT_LIST, script_list_type, lang_list_type, script_and_lang_list_type } from './utils/lang_list';
4
+ export {
5
+ /**
6
+ * The list of all supported script names
7
+ */
8
+ SCRIPT_LIST,
9
+ /**
10
+ * The list of all supported language names which are mapped to a script
11
+ */
12
+ LANG_LIST,
13
+ /** Lists of all Supported Script/Language */
14
+ ALL_LANG_SCRIPT_LIST };
15
+ /** Type of the script list */
16
+ export type ScriptListType = script_list_type;
17
+ /** Type of the language list */
18
+ export type LangListType = lang_list_type;
19
+ /** Type of the script and language list */
20
+ export type ScriptAndLangListType = script_and_lang_list_type;
21
+ /**
22
+ * Preloads the script data. Useful for browsers as avoids the fetch latency
23
+ * @param name - The name of the script/language to preload
24
+ * @returns The script data
25
+ * @public
26
+ */
27
+ export declare const preloadScriptData: (name: script_input_name_type) => Promise<import('./make_script_data/output_script_data_schema').OutputScriptData>;
28
+ /**
29
+ * Supported script/language identifier types
30
+ */
31
+ export type ScriptLangType = script_input_name_type;
32
+ /**
33
+ * Transliterates `text` from `from` to `to`.
34
+ * @param text - The text to transliterate
35
+ * @param from - The script/language to transliterate from
36
+ * @param to - The script/language to transliterate to
37
+ * @param options - The custom options to use for the transliteration
38
+ * @returns The transliterated text
39
+ */
40
+ export declare function transliterate(text: string, from: ScriptLangType, to: ScriptLangType, options?: CustomOptionType): Promise<string>;
41
+ /**
42
+ * This returns the list of all supported custom options for
43
+ * transliterations for the provided script pair
44
+ * @param from_script_name - The script/language to transliterate from
45
+ * @param to_script_name - The script/language to transliterate to
46
+ * @returns The list of all supported custom options for the provided script pair
47
+ */
48
+ export declare function getAllOptions(from_script_name: ScriptLangType, to_script_name: ScriptLangType): Promise<("all_to_normal:replace_pancham_varga_varna_with_n" | "brahmic_to_brahmic:replace_pancham_varga_varna_with_anuvsvAra" | "all_to_sinhala:use_conjuct_enabling_halant" | "all_to_normal:remove_virAma_and_double_virAma" | "all_to_normal:replace_avagraha_with_a")[]>;
49
+ /**
50
+ * Custom Transliteration Options
51
+ */
52
+ export type TransliterationOptions = CustomOptionType;
53
+ /**
54
+ * Creates a stateful isolated context for character by character input typing.
55
+ * This is the main function which returns the `diff`, different realtime schems can be implemented using this.
56
+ *
57
+ * **Note** :- Script Data is loaded in background but it would still be good to await `ready` before using the context.
58
+ * @param typing_lang - The script/language to type in
59
+ * @returns A closed over context object with the following methods:
60
+ */
61
+ export declare function createTypingContext(typing_lang: ScriptLangType): {
62
+ /** Await once, then use `takeKeyInputSync` for best typing latency. */
63
+ ready: Promise<void>;
64
+ clearContext: () => void;
65
+ takeKeyInput: (key: string) => {
66
+ /** These number of characters need to be deleted from the current "app" input state */
67
+ to_delete_chars_count: number;
68
+ /** These characters need to be added to the current "app" input state */
69
+ diff_add_text: string;
70
+ };
71
+ getCurrentOutput: () => string;
72
+ };
73
+ type TextInputElement = HTMLInputElement | HTMLTextAreaElement;
74
+ /**
75
+ * Cross-framework event type for `<input>` / `<textarea>` handlers.
76
+ *
77
+ * - Svelte / Solid / Vue typically pass the native DOM event (`InputEvent` at runtime).
78
+ * - React wraps DOM events in a SyntheticEvent which exposes the original via `nativeEvent`.
79
+ */
80
+ export type TextInputEvent = (Event & {
81
+ currentTarget: TextInputElement;
82
+ }) | {
83
+ currentTarget: TextInputElement;
84
+ nativeEvent: Event;
85
+ };
86
+ /**
87
+ * Handles input events for transliteration typing in `input` and `textarea` elements
88
+ *
89
+ * @param typingContext - The typing context created for the element
90
+ * @param event - Input Event
91
+ * @param onValueChange - Optional callback function invoked when the value changes
92
+ */
93
+ export declare function handleTypingInputEvent(typingContext: ReturnType<typeof createTypingContext>, event: TextInputEvent, onValueChange?: (updatedValue: string) => void): Promise<void>;
94
+ /**
95
+ * Checks if the keydown event should clear the typing context
96
+ * @param e - The keydown event
97
+ * @param ctx - The typing context
98
+ * @returns True if the keydown event should clear the typing context, false otherwise
99
+ */
100
+ export declare function clearTypingContextOnKeyDown(e: KeyboardEvent, ctx: ReturnType<typeof createTypingContext>): boolean;
@@ -0,0 +1,62 @@
1
+ import { script_list_type } from '../utils/lang_list';
2
+ import { KramaKeysExtendedType } from './krama_array_keys';
3
+ type ReplacePrevKramaKeysRule = {
4
+ /** in this we check if the string prev_krama_keys combines string appears before any one of the following_krama_keys */
5
+ type: 'replace_prev_krama_keys';
6
+ prev: KramaKeysExtendedType[];
7
+ following: KramaKeysExtendedType[];
8
+ /** will be combined to a single string */
9
+ replace_with: KramaKeysExtendedType[];
10
+ };
11
+ type DirectReplaceRule = {
12
+ type: 'direct_replace';
13
+ /** set of individual krama key combinations to replace */
14
+ to_replace: KramaKeysExtendedType[][];
15
+ replace_with: (KramaKeysExtendedType | null)[];
16
+ /** If this is present it will take precedence over the replace_with array.
17
+ * Text here will be directly without any krama mappings
18
+ */
19
+ replace_text?: string;
20
+ };
21
+ type CommonRuleTypeAttributes = {
22
+ /** Specifies if the pattern has to checked in input or output text */
23
+ check_in: 'input' | 'output';
24
+ /** Use `replaceAll` to directly replace the pattern with the replace_with string
25
+ *
26
+ * **Note** :- Avoid using this pattern as much as possible it can be slower for large inputs
27
+ *
28
+ * When the `check_in` is `input` then we replace before the process and
29
+ * when it is `output` then we replace after the process.
30
+ *
31
+ * Always fall back to `use_replace` only when implementation becomes too complex or otherwise.
32
+ * The *Aim* should be to develop techniques so we dont have to rely on it too much.
33
+ */
34
+ use_replace?: boolean;
35
+ };
36
+ type InputRuleTypes = Omit<CommonRuleTypeAttributes, 'check_in'> & {
37
+ check_in?: CommonRuleTypeAttributes['check_in'];
38
+ } & (ReplacePrevKramaKeysRule | DirectReplaceRule);
39
+ type CustomOptionsRecordType = {
40
+ from_script_name?: script_list_type[];
41
+ from_script_type?: 'brahmic' | 'other' | 'all';
42
+ to_script_name?: script_list_type[];
43
+ to_script_type?: 'brahmic' | 'other' | 'all';
44
+ rules: InputRuleTypes[];
45
+ } & CommonRuleTypeAttributes;
46
+ type InputCustomOptionsType = Record<`${string}:${string}`, CustomOptionsRecordType>;
47
+ type out_ReplacePrevKramaKeysRule = Pick<ReplacePrevKramaKeysRule, 'type'> & {
48
+ prev: number[];
49
+ following: number[];
50
+ replace_with: number[];
51
+ };
52
+ type out_DirectReplaceRule = Pick<DirectReplaceRule, 'type'> & {
53
+ to_replace: number[][];
54
+ replace_with: number[];
55
+ replace_text?: string;
56
+ };
57
+ /** This is final type that will be actually used by the transliterator */
58
+ export type OptionsType = Record<`${string}:${string}`, Omit<CustomOptionsRecordType, 'rules'> & {
59
+ rules: (CommonRuleTypeAttributes & (out_ReplacePrevKramaKeysRule | out_DirectReplaceRule))[];
60
+ }>;
61
+ export declare const CustomOptionsInput: InputCustomOptionsType;
62
+ export {};
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Assamese: InputBrahmicScriptType;
3
+ export default Assamese;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Bengali: InputBrahmicScriptType;
3
+ export default Bengali;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Brahmi: InputBrahmicScriptType;
3
+ export default Brahmi;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Devanagari: InputBrahmicScriptType;
3
+ export default Devanagari;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Granth: InputBrahmicScriptType;
3
+ export default Granth;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Gujarati: InputBrahmicScriptType;
3
+ export default Gujarati;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Gurumukhi: InputBrahmicScriptType;
3
+ export default Gurumukhi;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Kannada: InputBrahmicScriptType;
3
+ export default Kannada;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Malayalam: InputBrahmicScriptType;
3
+ export default Malayalam;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Modi: InputBrahmicScriptType;
3
+ export default Modi;
@@ -0,0 +1,3 @@
1
+ import { InputOtherScriptType } from '../input_script_data_schema';
2
+ declare const Normal: InputOtherScriptType;
3
+ export default Normal;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Odia: InputBrahmicScriptType;
3
+ export default Odia;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Purna_Devanagari: InputBrahmicScriptType;
3
+ export default Purna_Devanagari;
@@ -0,0 +1,3 @@
1
+ import { InputOtherScriptType } from '../input_script_data_schema';
2
+ declare const Romanized: InputOtherScriptType;
3
+ export default Romanized;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Sharada: InputBrahmicScriptType;
3
+ export default Sharada;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Siddham: InputBrahmicScriptType;
3
+ export default Siddham;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Sinhala: InputBrahmicScriptType;
3
+ export default Sinhala;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Tamil_Extended: InputBrahmicScriptType;
3
+ export default Tamil_Extended;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Tamil: InputBrahmicScriptType;
3
+ export default Tamil;
@@ -0,0 +1,3 @@
1
+ import { InputBrahmicScriptType } from '../input_script_data_schema';
2
+ declare const Telugu: InputBrahmicScriptType;
3
+ export default Telugu;