lipilekhika 0.0.1-beta.1 → 0.0.1-beta.3

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.
@@ -1,2 +1,2 @@
1
- (function(O,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(O=typeof globalThis<"u"?globalThis:O||self,M(O.lipilekhika={}))})(this,(function(O){"use strict";function M(t,e,r,n){const{accessor:a,compareFn:o}=n??{},i=a??((c,l)=>c[l]);let s=0,u=e.length-1,_=-1;for(;s<=u;){const c=Math.floor((s+u)/2),l=e[c],p=i(t,l);let h;o?h=o(r,p):h=r<p?-1:r>p?1:0,h===0?(_=l,u=c-1):h<0?u=c-1:s=c+1}return _}function ee(t,e,r){const{accessor:n,compareFn:a}=r??{},o=n??((_,c)=>_[c]);let i=0,s=t.length-1,u=-1;for(;i<=s;){const _=Math.floor((i+s)/2),c=o(t,_);let l;a?l=a(e,c):l=e<c?-1:e>c?1:0,l===0?(u=_,s=_-1):l<0?s=_-1:i=_+1}return u}const ce={},q=async t=>{{if(ce[t])return ce[t];const r=`https://cdn.jsdelivr.net/npm/lipilekhika@0.0.0-alpha.4/dist/umd_json/script_data/${t}.json`,a=(await fetch(r)).json();return ce[t]=a,a}},te={"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]}]},"normal_to_all:use_typing_chars":{from_script_name:["Normal"],to_script_type:"all",check_in:"output",rules:[]},"all_to_normal:preserve_specific_chars":{from_script_type:"all",to_script_name:["Normal"],check_in:"output",rules:[]}},Se=(t,e)=>{const r=t.krama_text_arr[e]?.[0];return typeof r=="string"?r:null},z=(t,e)=>Se(t,e)??"",re=(t,e)=>M(t.krama_text_arr,t.krama_text_arr_index,e,{accessor:(r,n)=>r[n][0]}),be=()=>{let t=[];function e(c){c&&t.push(c)}function r(c){for(const l of c)e(l)}function n(){return t.at(-1)}function a(){return n()?.at(-1)}function o(){const c=n();if(!c)return;const l=c.at(-1),p=c.slice(0,-1);return p?t[t.length-1]=p:t.pop(),l}function i(c,l){t.splice(-c,c,...l.filter(Boolean))}function s(c,l){const p=o();if(!p){r(c),r(l);return}r(c),e(p),r(l)}function u(c){const l=t.at(c);return l?{cp:c,ch:l,width:l.length}:null}function _(c,l){c<0&&(c=t.length+c),!(c<0||c>=t.length)&&(t[c]=l)}return{emit:e,emitPieces:r,lastPiece:n,lastChar:a,popLastChar:o,rewriteTailPieces:i,withLastCharMovedAfter:s,toString:()=>t.join(""),rewriteAt:_,peekAt:u}},Ne=t=>{let e=[];function r(){e=[]}function n(){return e.length}function a(p){return e.at(p)}function o(){return e.at(-1)}function i(){return o()?.[0]}function s(){return o()?.[1]?.type}function u(p){return a(p)?.[1]?.type}function _(p){return a(p)?.[0]}function c(p){return s()===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:o,lastText:i,lastType:s,typeAt:u,textAt:_,isLastType:c,push:l}},Le=t=>{let e=0;function r(s){const u=t.codePointAt(s);if(u===void 0)return null;const _=String.fromCodePoint(u);return{cp:u,ch:_,width:_.length}}function n(){return r(e)}function a(s){return r(e+s)}function o(s){e+=s}function i(s,u){return t.substring(s,u)}return{get pos(){return e},peek:n,peekAt:r,peekAtOffsetUnits:a,advance:o,slice:i}},se=(t,e,r,n)=>{for(let a=0;a<r.length;a++){const o=r[r.length-1-a],i=t(e-a);if(i===null)return{matched:!1,matchedLen:0};const s=re(n,i.ch);if(s===-1||s!==o)return{matched:!1,matchedLen:0}}return{matched:!0,matchedLen:r.length}},oe=(t,e)=>t.map(r=>z(e,r)).filter(Boolean),Ie=["²","³","⁴"],N=t=>!!t&&Ie.indexOf(t)!==-1,Oe=["॒","॑","᳚","᳛"],_e=t=>!!t&&Oe.indexOf(t)!==-1,D=t=>t==="Tamil-Extended",H=(t,e,r,n)=>{if(e.length===0)return;if(!n){t.emitPieces(e);return}const a=e[0]??"";if(a[0]===r){const o=a.slice(1),i=[];o&&i.push(o);for(let s=1;s<e.length;s++)i.push(e[s]);t.withLastCharMovedAfter([r],i)}else t.withLastCharMovedAfter(e,[])},ke=["#an","#sss","#ss","#s"],De=["↓","↑↑↑","↑↑","↑"],Ce=(t,e)=>{if(!t)return t;if(t.indexOf("x")!==-1&&(t=t.replaceAll("x","kSh")),e==="Tamil-Extended")for(let r=0;r<ke.length;r++){const n=ke[r];t.indexOf(n)!==-1&&(t=t.replaceAll(n,De[r]))}return t},je=[" ",`
1
+ (function(O,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(O=typeof globalThis<"u"?globalThis:O||self,M(O.lipilekhika={}))})(this,(function(O){"use strict";function M(t,e,r,n){const{accessor:a,compareFn:o}=n??{},i=a??((c,l)=>c[l]);let s=0,u=e.length-1,_=-1;for(;s<=u;){const c=Math.floor((s+u)/2),l=e[c],p=i(t,l);let h;o?h=o(r,p):h=r<p?-1:r>p?1:0,h===0?(_=l,u=c-1):h<0?u=c-1:s=c+1}return _}function ee(t,e,r){const{accessor:n,compareFn:a}=r??{},o=n??((_,c)=>_[c]);let i=0,s=t.length-1,u=-1;for(;i<=s;){const _=Math.floor((i+s)/2),c=o(t,_);let l;a?l=a(e,c):l=e<c?-1:e>c?1:0,l===0?(u=_,s=_-1):l<0?s=_-1:i=_+1}return u}const ce={},q=async t=>{{if(ce[t])return ce[t];const r=`https://cdn.jsdelivr.net/npm/lipilekhika@0.0.1-beta.2/dist/umd_json/script_data/${t}.json`,a=(await fetch(r)).json();return ce[t]=a,a}},te={"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]}]},"normal_to_all:use_typing_chars":{from_script_name:["Normal"],to_script_type:"all",check_in:"output",rules:[]},"all_to_normal:preserve_specific_chars":{from_script_type:"all",to_script_name:["Normal"],check_in:"output",rules:[]}},Se=(t,e)=>{const r=t.krama_text_arr[e]?.[0];return typeof r=="string"?r:null},z=(t,e)=>Se(t,e)??"",re=(t,e)=>M(t.krama_text_arr,t.krama_text_arr_index,e,{accessor:(r,n)=>r[n][0]}),be=()=>{let t=[];function e(c){c&&t.push(c)}function r(c){for(const l of c)e(l)}function n(){return t.at(-1)}function a(){return n()?.at(-1)}function o(){const c=n();if(!c)return;const l=c.at(-1),p=c.slice(0,-1);return p?t[t.length-1]=p:t.pop(),l}function i(c,l){t.splice(-c,c,...l.filter(Boolean))}function s(c,l){const p=o();if(!p){r(c),r(l);return}r(c),e(p),r(l)}function u(c){const l=t.at(c);return l?{cp:c,ch:l,width:l.length}:null}function _(c,l){c<0&&(c=t.length+c),!(c<0||c>=t.length)&&(t[c]=l)}return{emit:e,emitPieces:r,lastPiece:n,lastChar:a,popLastChar:o,rewriteTailPieces:i,withLastCharMovedAfter:s,toString:()=>t.join(""),rewriteAt:_,peekAt:u}},Ne=t=>{let e=[];function r(){e=[]}function n(){return e.length}function a(p){return e.at(p)}function o(){return e.at(-1)}function i(){return o()?.[0]}function s(){return o()?.[1]?.type}function u(p){return a(p)?.[1]?.type}function _(p){return a(p)?.[0]}function c(p){return s()===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:o,lastText:i,lastType:s,typeAt:u,textAt:_,isLastType:c,push:l}},Le=t=>{let e=0;function r(s){const u=t.codePointAt(s);if(u===void 0)return null;const _=String.fromCodePoint(u);return{cp:u,ch:_,width:_.length}}function n(){return r(e)}function a(s){return r(e+s)}function o(s){e+=s}function i(s,u){return t.substring(s,u)}return{get pos(){return e},peek:n,peekAt:r,peekAtOffsetUnits:a,advance:o,slice:i}},se=(t,e,r,n)=>{for(let a=0;a<r.length;a++){const o=r[r.length-1-a],i=t(e-a);if(i===null)return{matched:!1,matchedLen:0};const s=re(n,i.ch);if(s===-1||s!==o)return{matched:!1,matchedLen:0}}return{matched:!0,matchedLen:r.length}},oe=(t,e)=>t.map(r=>z(e,r)).filter(Boolean),Ie=["²","³","⁴"],N=t=>!!t&&Ie.indexOf(t)!==-1,Oe=["॒","॑","᳚","᳛"],_e=t=>!!t&&Oe.indexOf(t)!==-1,D=t=>t==="Tamil-Extended",H=(t,e,r,n)=>{if(e.length===0)return;if(!n){t.emitPieces(e);return}const a=e[0]??"";if(a[0]===r){const o=a.slice(1),i=[];o&&i.push(o);for(let s=1;s<e.length;s++)i.push(e[s]);t.withLastCharMovedAfter([r],i)}else t.withLastCharMovedAfter(e,[])},ke=["#an","#sss","#ss","#s"],De=["↓","↑↑↑","↑↑","↑"],Ce=(t,e)=>{if(!t)return t;if(t.indexOf("x")!==-1&&(t=t.replaceAll("x","kSh")),e==="Tamil-Extended")for(let r=0;r<ke.length;r++){const n=ke[r];t.indexOf(n)!==-1&&(t=t.replaceAll(n,De[r]))}return t},je=[" ",`
2
2
  `,"\r"," ",",",";","!","@","?","%"],Pe=3;function L(t,e,r){const{from_script_name:n,to_script_name:a,from_script_data:o,to_script_data:i,trans_options:s,result:u,prev_context:_,BRAHMIC_HALANT:c,BRAHMIC_NUQTA:l,typing_mode:p,include_inherent_vowel:h}=t,{next:m,last_extra_call:A}=r??{};let $=!1;if((l&&_.typeAt(-3)==="vyanjana"&&_.textAt(-2)===l&&_.typeAt(-1)==="mAtrA"||_.typeAt(-2)==="vyanjana"&&_.typeAt(-1)==="mAtrA")&&(!e||e[1]?.type==="anya")&&_.clear(),o.script_type==="brahmic"&&i.script_type==="other")e[0]!==c&&(!(D(n)&&e[0]&&e[0].length>0)||e[0].charAt(0)!==c)&&(!l||e[0]!==l)&&(_.typeAt(-1)==="vyanjana"||l&&_.typeAt(-2)==="vyanjana"&&_.textAt(-1)===l)&&(e[1]?.type!=="mAtrA"&&e[0]!==c||e[1]?.type==="anya"||e[1]===null||e[1]===void 0)&&u.emit(i.schwa_character);else if(o.script_type==="other"&&i.script_type==="brahmic")if(_.typeAt(-1)==="vyanjana"&&(e[1]?.type==="mAtrA"||e[1]?.type==="svara")){const y=e[1].type==="svara"?z(i,e[1].mAtrA_krama_ref?.[0]??-1):e[0];D(a)&&N(u.lastChar())?H(u,[y],i.halant,!0):H(u,[y],i.halant,!1),$=!0}else!h&&_.typeAt(-1)==="vyanjana"&&!(e[0]===c||e[1]?.type==="mAtrA")?D(a)&&N(u.lastChar())?H(u,[c],i.halant,!0):(H(u,[c],i.halant,!1),a==="Sinhala"&&s["all_to_sinhala:use_conjuct_enabling_halant"]&&u.rewriteAt(-1,u.lastPiece()+"‍")):h&&e&&e[1]?.type==="vyanjana"&&(_.typeAt(-1)==="vyanjana"||l&&_.typeAt(-2)==="vyanjana"&&_.textAt(-1)===l)&&(D(a)&&N(u.lastChar())?H(u,[c],i.halant,!0):(H(u,[c],i.halant,!1),a==="Sinhala"&&s["all_to_sinhala:use_conjuct_enabling_halant"]&&u.rewriteAt(-1,u.lastPiece()+"‍")));let x=!1;return p&&(m===void 0||m.length===0)&&!A&&!(D(a)&&N(u.lastChar()))&&(x=!0,e[1]?.type==="vyanjana"&&(x=!1),x&&_.clear()),(!p||!A&&!x)&&_.push(e),$}function ve(t,e,r){const{custom_rules:n,cursor:a,result:o,from_script_data:i,to_script_data:s}=t,u=e+r;for(let _=0;_<n.length;_++){if(n[_].use_replace===!0)continue;const c=n[_];if(c.type==="replace_prev_krama_keys"){if(c.check_in==="input"){const l=se(a.peekAt,u,c.prev,i),p=a.peekAt(e);if(l.matched&&p!==null){const h=p.ch,m=re(i,h);if(m!==-1&&c.following.indexOf(m)!==-1){const A=oe(c.replace_with,s);o.rewriteTailPieces(l.matchedLen,A)}}}else if(c.check_in==="output"){const l=o.lastPiece();if(!l)continue;const p=re(s,l);if(p!==-1&&c.following.indexOf(p)!==-1){const h=se(o.peekAt,-2,c.prev,s);if(h.matched){const m=oe(c.replace_with,s);o.rewriteTailPieces(h.matchedLen+1,[...m,l])}}}}else if(c.type==="direct_replace"){const l=c.check_in==="output"?s:i;for(const p of c.to_replace){const h=se(o.peekAt,-1,p,l);if(!h.matched)continue;if(c.replace_text){o.rewriteTailPieces(h.matchedLen,[c.replace_text]);break}const m=oe(c.replace_with,l);o.rewriteTailPieces(h.matchedLen,m);break}}}}const ge=(t,e,r)=>{if(!r)return{};const n={};for(const[a,o]of Object.entries(r??{})){if(!(a in te))continue;const i=te[a];(i.from_script_type==="all"&&i.to_script_type==="all"||(i.from_script_type!==void 0&&(i.from_script_type==="all"||i.from_script_type===t.script_type)||i.from_script_name!==void 0&&i.from_script_name.includes(t.script_name))&&(i.to_script_type!==void 0&&(i.to_script_type==="all"||i.to_script_type===e.script_type)||i.to_script_name!==void 0&&i.to_script_name.includes(e.script_name)))&&(n[a]=o)}return n},Ae=(t,e,r)=>{const n=ge(t,e,r),a=Object.keys(n).flatMap(o=>n[o]===!0?te[o].rules:[]);return{trans_options:n,custom_rules:a}},xe=(t,e)=>t.replace_with.map(r=>z(e,r)).join(""),we=(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 o=a.prev.map(i=>z(e,i)).join("");for(let i of a.following){const s=z(e,i);if(!s)continue;const u=xe(a,e)+s;t=t.replaceAll(o+s,u)}}else if(a.type==="direct_replace"){const o=a.to_replace.map(i=>i.map(s=>z(e,s)).join(""));for(let i of o)t=t.replaceAll(i,xe(a,e))}}return t},Re=!0,Me=!1,Te=(t,e,r,n,a,o,i,s)=>{const u=s?.useNativeNumerals??Re,_=s?.typing_mode??!1,c=s?.includeInherentVowel??Me;if(_&&e!=="Normal")throw new Error("Typing mode is only supported with Normal script as the input");_&&(o["normal_to_all:use_typing_chars"]=!0),_&&e==="Normal"&&(t=Ce(t,r)),t=we(t,n,i,"input");const l=be();let p=0;const h=Le(t),m=Ne(Pe),A=n.script_type==="brahmic"&&a.script_type==="other"||n.script_type==="other"&&a.script_type==="brahmic"||_&&e==="Normal"&&a.script_type==="other",$=n.script_type==="brahmic"&&a.script_type==="other"?n.nuqta??null:n.script_type==="other"&&a.script_type==="brahmic"?a.nuqta??null:null,x=n.script_type==="brahmic"&&a.script_type==="other"?n.halant:n.script_type==="other"&&a.script_type==="brahmic"?a.halant:null,y={from_script_name:e,to_script_name:r,from_script_data:n,to_script_data:a,trans_options:o,custom_rules:i,cursor:h,result:l,prev_context:m,BRAHMIC_NUQTA:$,BRAHMIC_HALANT:x,typing_mode:_,include_inherent_vowel:c},V=(o["normal_to_all:use_typing_chars"]||_)&&e==="Normal"?a.typing_text_to_krama_map:n.text_to_krama_map;let k=-1;for(;h.pos<t.length;){p=h.pos;const F=h.peek();if(!F)break;const w=F.ch,U=F.width,ie=U===2?1:U;if(k!==-1&&p>=k){k=-1,h.advance(U);continue}if(je.indexOf(w)!==-1){h.advance(U),A&&(L(y,[" ",null]),m.clear()),l.emit(w);continue}if(w.match(/^\d$/)&&!u){l.emit(w),h.advance(U),L(y,[w,null]);continue}if(o["all_to_normal:preserve_specific_chars"]&&r==="Normal"){const T=ee(n.custom_script_chars_arr,w,{accessor:(E,I)=>E[I][0]});if(T!==-1){const E=n.custom_script_chars_arr[T];L(y,[E[0],n.list[E[1]??-1]??null]);const I=n.typing_text_to_krama_map[E[2]??-1]?.[0];l.emit(I??""),h.advance(E[0].length);continue}}let X=-1;{let T=0,E=-1;const I=A&&n.script_type==="other"&&a.script_type==="brahmic"&&(m.typeAt(-1)==="vyanjana"||$&&m.typeAt(-2)==="vyanjana"&&m.textAt(-1)===$);for(;;){const W=h.peekAt(p+ie+T),le=W?.ch??"";k!==-1&&le&&N(le)&&(T+=W?.width??0);const S=p+ie+T,d=k!==-1?h.slice(p,k)+(S>k?h.slice(k+1,S):""):h.slice(p,S),C=ee(V,d,{accessor:(b,j)=>b[j][0]});if(C===-1){X=-1;break}const v=V[C];if(I&&v[1].krama&&v[1].krama.length>=1){const b=v[1].krama,j=b[0],P=a.krama_text_arr[j]?.[1],ye=a.list[P??-1]?.type;if(b.length===1&&P!==null&&P!==void 0&&(ye==="svara"||ye==="mAtrA"))E=C;else if(E!==-1){X=E;break}}if(v[1].next&&v[1].next.length>0){const b=h.peekAt(S),j=b?.ch;if(D(e)&&n.script_type==="brahmic"){const Z=b?h.peekAt(S+b.width):null,P=Z?.ch,B=(b&&Z?h.peekAt(S+b.width+Z.width):null)?.ch;if(k===-1&&P!==void 0&&N(P)&&v[1].next.indexOf(P)!==-1){const Y=ee(n.text_to_krama_map,d+P,{accessor:(R,g)=>R[g][0]}),G=M(n.krama_text_arr,n.krama_text_arr_index,j??"",{accessor:(R,g)=>R[g][0]});if(Y!==-1&&G!==-1){X=Y;const R=n.krama_text_arr[G],g=n.list[R[1]??-1]?.type;if(j===n.halant||g==="mAtrA"){k=S+(b?.width??0);break}}}else if(k===-1&&B!==void 0&&N(B)&&v[1].next.indexOf(B)!==-1){const Y=ee(n.text_to_krama_map,d+B,{accessor:(g,K)=>g[K][0]}),G=M(n.krama_text_arr,n.krama_text_arr_index,j??"",{accessor:(g,K)=>g[K][0]}),R=M(n.krama_text_arr,n.krama_text_arr_index,P??"",{accessor:(g,K)=>g[K][0]});if(Y!==-1&&G!==-1&&R!==-1){const g=n.krama_text_arr[G],K=n.krama_text_arr[R];X=Y;const de=n.list[g[1]??-1]?.type,tt=n.list[K[1]??-1]?.type;if(de==="mAtrA"&&tt==="mAtrA"){k=S+(b?.width??0)+(Z?.width??0);break}}}if(k===-1&&j!==void 0&&P!==void 0&&_e(P)&&B!==void 0&&N(B)&&v[1].next.indexOf(B)!==-1){const Y=M(n.krama_text_arr,n.krama_text_arr_index,j??"",{accessor:(G,R)=>G[R][0]});if(Y!==-1){const G=n.krama_text_arr[Y];if(n.list[G[1]??-1]?.type==="mAtrA"){const g=ee(n.text_to_krama_map,d+B,{accessor:(K,de)=>K[de][0]});if(g!==-1){X=g,k=S+(b?.width??0)+(Z?.width??0);break}}}}}if(j!==void 0&&v[1].next.indexOf(j)!==-1){T+=b?.width??0;continue}}X=C;break}}const f=X!==-1?V[X]:null;if(f!==null){const T=k!==-1&&f[0].length>1&&n.list[n.krama_text_arr[f[1].krama?.[0]??-1]?.[1]??-1]?.type==="vyanjana"&&N(f[0].at(-1)??void 0)?1:0,E=f[0].length-T;if(h.advance(E),p=h.pos,o["normal_to_all:use_typing_chars"]&&"custom_back_ref"in f[1]&&f[1].custom_back_ref!==void 0&&f[1].custom_back_ref!==null){const I=a.custom_script_chars_arr[f[1].custom_back_ref]??null;te!==null&&(l.emit(I[0]),L(y,[f[0],a.list[I[1]??-1]??null],{next:f[1].next??void 0}));continue}if(f[1].krama!==null&&f[1].krama!==void 0&&f[1].krama.some(I=>I!==-1)){const W=f[1].krama.map(d=>z(a,d)),le=W.join("");let S=!1;if(A)if(n.script_type==="brahmic"&&a.script_type==="other"){let d=null;if(!o["normal_to_all:use_typing_chars"]&&f[1].fallback_list_ref!==void 0&&f[1].fallback_list_ref!==null)d=n.list[f[1].fallback_list_ref];else if(!f[1].krama||f[1].krama.length===0)d=null;else{const C=f[1].krama.map(v=>n.list[n.krama_text_arr[v][1]??-1]);D(e)&&C.some(v=>v?.type==="mAtrA")&&C.some(v=>v?.type==="vyanjana")?d={...C[0],type:"anya"}:D(e)&&C.length>1&&C.some(v=>v==null)?d=C.at(-1):d=C[0]}S=L(y,[f[0],d])}else if(a.script_type==="brahmic"&&n.script_type==="other"){let d=null;f[1].fallback_list_ref!==void 0&&f[1].fallback_list_ref!==null?d=a.list[f[1].fallback_list_ref]:d=f[1].krama&&f[1].krama.length>0?a.list[a.krama_text_arr[f[1].krama[0]]?.[1]??-1]??null:null,_&&e==="Normal"?S=L(y,[f[0],d],{next:f[1].next??void 0}):S=L(y,[f[0],d])}else _&&e==="Normal"&&a.script_type==="other"&&(S=L(y,[f[0],null],{next:f[1].next??void 0}));if(!S)if(a.script_type==="brahmic"&&D(r)&&(a.list[f[1].krama?.at(-1)??-1]?.type==="mAtrA"||le===a.halant)&&N(l.lastChar()))H(l,W,a.halant,!0);else if(D(r)&&_e(W.at(-1)?.at(-1)??"")&&N(l.lastChar())){const d=l.popLastChar();l.emitPieces(W),l.emit(d??"")}else l.emitPieces(W);ve(y,p,-E);continue}else if(f[1].krama!==null&&f[1].krama!==void 0&&f[1].krama.some(I=>I===-1)){l.emit(f[0]),_&&L(y,[f[0],null],{next:f[1].next??void 0});continue}}else h.advance(U),p=h.pos;const ne=f===null?w:f[0],ae=re(n,ne);if(ae===-1){A&&(L(y,[ne,null]),m.clear()),l.emit(ne);continue}let me=!1;if(A&&(n.script_type==="brahmic"?me=L(y,[ne,n.list[n.krama_text_arr[ae][1]??-1]]):a.script_type==="brahmic"&&(me=L(y,[ne,a.list[a.krama_text_arr[ae][1]??-1]]))),!me){const T=z(a,ae);if(a.script_type==="brahmic"&&D(r)&&(a.list[a.krama_text_arr[ae][1]??-1]?.type==="mAtrA"||T===a.halant)&&N(l.lastChar()))H(l,[T],a.halant,!0);else if(D(r)&&_e(T)&&N(l.lastChar())){const E=l.popLastChar();l.emit(T),l.emit(E??"")}else l.emit(T)}ve(y,p,-U)}A&&L(y,[void 0,null],{last_extra_call:!0});let J=l.toString();return J=we(J,a,i,"output"),{output:J,context_length:m.length()}},Ue=async(t,e,r,n,a)=>{const[o,i]=await Promise.all([q(e),q(r)]),{trans_options:s,custom_rules:u}=Ae(o,i,n);return Te(t,e,r,o,i,s,u,a)},Be={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:Ge,lang_list:Ke}=Be,ue=Object.keys(Ge),pe=Object.keys(Ke),ze=Array.from(new Set([...pe,...ue])),He={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"},Ee={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 $e(t){return t.toLowerCase().replace(/(^|-)([a-z])/g,(e,r,n)=>r+n.toUpperCase())}const Q=t=>{const e=$e(t);return ue.includes(e)?e:pe.includes(e)?He[e]:t.toLocaleLowerCase()in Ee?Ee[t.toLocaleLowerCase()]:null},Ve=async t=>{const e=Q(t);if(!e)throw new Error(`Invalid script name: ${t}`);return await q(e)};async function Fe(t,e,r,n){const a=Q(e);if(!a)throw new Error(`Invalid script name: ${e}`);const o=Q(r);if(!o)throw new Error(`Invalid script name: ${r}`);return a===o?t:(await Ue(t,a,o,n)).output}async function Xe(t,e){const r=Q(t);if(!r)throw new Error(`Invalid script name: ${t}`);const n=Q(e);if(!n)throw new Error(`Invalid script name: ${e}`);const a=await q(r),o=await q(n);return Object.keys(ge(a,o,Object.fromEntries(Object.keys(te).map(i=>[i,!0]))))}const We=4500,he=!0,fe=!1;function Ye(t,e){const{autoContextTClearTimeMs:r}=e??{};let n=e?.useNativeNumerals??he,a=e?.includeInherentVowel??fe;const o=Q(t);if(!o)throw new Error(`Invalid script name: ${t}`);let i="",s="";const u=r??We;let _=null,c=null,l=null,p={},h=[];const m=(async()=>{const[x,y]=await Promise.all([q("Normal"),q(o)]);c=x,l=y;const V=Ae(x,y);p=V.trans_options,h=V.custom_rules})();function A(){_=null,i="",s=""}function $(x){if(!c||!l)throw new Error("Typing context not ready. Await `ctx.ready` before calling takeKeyInputSync.");const y=Date.now();_&&y-_>u&&A();let V=x?.[0]??"";i+=V;let k=s;const{context_length:J,output:F}=Te(i,"Normal",o,c,l,p,h,{typing_mode:!0,useNativeNumerals:n,includeInherentVowel:a});J>0?s=F:J===0&&A();let w=0;for(;w<F.length&&w<k.length&&F[w]===k[w];)w++;let U=F.substring(w),ie=k.length-w;return _=Date.now(),{to_delete_chars_count:ie,diff_add_text:U}}return{ready:m,clearContext:A,takeKeyInput:$,updateUseNativeNumerals:x=>{n=x??he},updateIncludeInherentVowel:x=>{a=x??fe}}}async function qe(t,e,r,n){if(!(n??!0)){r?.(e?.currentTarget?.value);return}const o=e?.nativeEvent??e,i="nativeEvent"in e,s=e?.currentTarget??o?.target;if(!o||!s||o.isComposing)return;if(o.inputType!=="insertText"){r?.(s.value),t.clearContext();return}const u=o.data;if(typeof u!="string"||u.length!==1){r?.(s.value),t.clearContext();return}const _=s.selectionStart??0,c=s.selectionEnd??_;if(_!==c){r?.(s.value),t.clearContext();return}i&&r&&r(e.currentTarget.value),await t.ready;const{diff_add_text:l,to_delete_chars_count:p}=t.takeKeyInput(u),h=_,m=Math.max(0,h-p-u.length);s.setRangeText(l,m,h,"end"),r?.(s.value)}async function Qe(t,e,r,n){if(!(n??!0))return;const i="nativeEvent"in e?e.nativeEvent:e,s=e?.currentTarget??i?.target;if(!i||!s||i.isComposing||(!i.inputType||i.inputType!=="insertText")&&(!i.type||i.type!=="textInput"))return;const u=i.data;if(typeof u!="string"||u.length===0)return;if(u.length!==1){t.clearContext();return}const _=s.selectionStart??0,c=s.selectionEnd??_;if(_!==c){t.clearContext();return}i.preventDefault?.(),await t.ready;const{diff_add_text:l,to_delete_chars_count:p}=t.takeKeyInput(u),h=_,m=Math.max(0,h-p);s.setRangeText(l,m,h,"end"),r?.(s.value)}const Je=new Set(["Backspace","Delete","Enter","Tab","Escape","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]);function Ze(t,e){const r=t?.nativeEvent??t;if(r instanceof KeyboardEvent){if(r.isComposing)return!1;const n=r.key;if(!n||n==="Unidentified"||n==="Process"||n==="Dead"||r.ctrlKey||r.metaKey||r.altKey)return!1;if(Je.has(n))return e.clearContext(),!0}return!1}const et=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_INCLUDE_INHERENT_VOWEL:fe,DEFAULT_USE_NATIVE_NUMERALS:he,clearTypingContextOnKeyDown:Ze,createTypingContext:Ye,handleTypingBeforeInputEvent:Qe,handleTypingInputEvent:qe},Symbol.toStringTag,{value:"Module"}));O.ALL_LANG_SCRIPT_LIST=ze,O.LANG_LIST=pe,O.SCRIPT_LIST=ue,O.getAllOptions=Xe,O.preloadScriptData=Ve,O.transliterate=Fe,O.typing=et,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lipilekhika",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {