12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{AlefTable as t,FETo06Table as r,impTabRtl as e,impTabLtr as n,TBBASE as o,UnicodeTable as i,TYPES_NAMES as u,UBAT_B as s,UBAT_S as a,UBAT_WS as f,PrimaryTable as c,ArabicAlefBetIntervalsBegine as l,ArabicAlefBetIntervalsEnd as h,UBAT_L as T,UBAT_R as L,UBAT_ON as A,UBAT_AN as g,UBAT_EN as d,UBAT_ET as m,UBAT_NSM as F,UBAT_AL as b,SwapTable as p,StandAlonForm as R,BaseForm as U,MedialForm as B,LamAlefInialTableFE as S,LamAlefMedialTableFE as w,FinalForm as _,InitialForm as v,IsolatedForm as N}from"./bidiEngineTables.js";class C{constructor(){this.inputFormat="ILYNN",this.outputFormat="VLNNN",this.sourceToTarget=[],this.targetToSource=[],this.levels=[]}bidiTransform(t,r,e){if(this.sourceToTarget=[],this.targetToSource=[],!t)return"";if(ot(this.sourceToTarget,this.targetToSource,t.length),!this.checkParameters(r,e))return t;r=this.inputFormat,e=this.outputFormat;let n=t;const o=ct,i=rt(r.charAt(1)),u=rt(e.charAt(1)),s=("I"===r.charAt(0)?"L":r.charAt(0))+i,a=("I"===e.charAt(0)?"L":e.charAt(0))+u,f=r.charAt(2)+e.charAt(2);o.defInFormat=s,o.defOutFormat=a,o.defSwap=f;const c=V(t,s,a,f,o);let l=!1;return"R"===e.charAt(1)?l=!0:"C"!==e.charAt(1)&&"D"!==e.charAt(1)||(l="rtl"===this.checkContextual(c)),this.sourceToTarget=st,this.targetToSource=it(this.sourceToTarget),at=this.targetToSource,n=r.charAt(3)===e.charAt(3)?c:"S"===e.charAt(3)?I(l,c,!0):k(c,l,!0),this.sourceToTarget=st,this.targetToSource=at,this.levels=ft,n}_inputFormatSetter(t){if(!At.test(t))throw new Error("dojox/string/BidiEngine: the bidi layout string is wrong!");this.inputFormat=t}_outputFormatSetter(t){if(!At.test(t))throw new Error("dojox/string/BidiEngine: the bidi layout string is wrong!");this.outputFormat=t}checkParameters(t,r){return t?this._inputFormatSetter(t):t=this.inputFormat,r?this._outputFormatSetter(r):r=this.outputFormat,t!==r}checkContextual(t){let r=x(t);if("ltr"!==r&&"rtl"!==r){try{r=document.dir.toLowerCase()}catch(e){}"ltr"!==r&&"rtl"!==r&&(r="ltr")}return r}hasBidiChar(t){return gt.test(t)}}function V(t,r,e,n,o){const i=E(t,{inFormat:r,outFormat:e,swap:n},o);if(i.inFormat===i.outFormat)return t;r=i.inFormat,e=i.outFormat,n=i.swap;const u=r.substring(0,1),s=r.substring(1,4),a=e.substring(0,1),f=e.substring(1,4);if(o.inFormat=r,o.outFormat=e,o.swap=n,"L"===u&&"VLTR"===e){if("LTR"===s)return o.dir=Tt,y(t,o);if("RTL"===s)return o.dir=Lt,y(t,o)}if("V"===u&&"V"===a)return o.dir="RTL"===s?Lt:Tt,M(t,o);if("L"===u&&"VRTL"===e)return"LTR"===s?(o.dir=Tt,t=y(t,o)):(o.dir=Lt,t=y(t,o)),M(t);if("VLTR"===r&&"LLTR"===e)return o.dir=Tt,y(t,o);if("V"===u&&"L"===a&&s!==f)return t=M(t),"RTL"===s?V(t,"LLTR","VLTR",n,o):V(t,"LRTL","VRTL",n,o);if("VRTL"===r&&"LRTL"===e)return V(t,"LRTL","VRTL",n,o);if("L"===u&&"L"===a){const r=o.swap;return o.swap=r.substr(0,1)+"N","RTL"===s?(o.dir=Lt,t=y(t,o),o.swap="N"+r.substr(1,2),o.dir=Tt,t=y(t,o)):(o.dir=Tt,t=y(t,o),o.swap="N"+r.substr(1,2),t=V(t,"VLTR","LRTL",o.swap,o)),t}return t}function E(t,r,e){if(void 0===r.inFormat&&(r.inFormat=e.defInFormat),void 0===r.outFormat&&(r.outFormat=e.defOutFormat),void 0===r.swap&&(r.swap=e.defSwap),r.inFormat===r.outFormat)return r;const n=r.inFormat.substring(0,1),o=r.outFormat.substring(0,1);let i,u=r.inFormat.substring(1,4),s=r.outFormat.substring(1,4);return"C"===u.charAt(0)&&(i=x(t),u="ltr"===i||"rtl"===i?i.toUpperCase():"L"===r.inFormat.charAt(2)?"LTR":"RTL",r.inFormat=n+u),"C"===s.charAt(0)&&(i=x(t),"rtl"===i?s="RTL":"ltr"===i?(i=O(t),s=i.toUpperCase()):s="L"===r.outFormat.charAt(2)?"LTR":"RTL",r.outFormat=o+s),r}function I(t,r,e){if(0===r.length)return"";void 0===t&&(t=!0),void 0===e&&(e=!0);const n=(r=String(r)).split("");let o=0,i=1,u=n.length;t||(o=n.length-1,i=-1,u=1);const s=j(n,o,i,u,e);let a="";for(let f=0;f<n.length;f++)e&&W(s,s.length,f)>-1?(ut(at,f,!t,-1),st.splice(f,1)):a+=n[f];return a}function j(t,r,e,n,o){let i=0;const u=[];let s=0;for(let a=r;a*e<n;a+=e)if(Z(t[a])||tt(t[a])){if("ل"===t[a]&&q(t,a+e,e,n)){t[a]=nt(t[a+e],0===i?S:w),a+=e,et(t,a,e,n),o&&(u[s]=a,s++),i=0;continue}const r=t[a];1===i?t[a]=$(t,a+e,e,n)?Q(t[a]):X(t[a],_):!0===$(t,a+e,e,n)?t[a]=X(t[a],v):t[a]=X(t[a],N),tt(r)||(i=1),!0===K(r)&&(i=0)}else i=0;return u}function x(t){const r=/[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(t);return r?r[0]<="z"?"ltr":"rtl":""}function O(t){const r=t.split("");return r.reverse(),x(r.join(""))}function k(e,n,o){if(0===e.length)return"";void 0===o&&(o=!0),void 0===n&&(n=!0);let i="";const u=(e=String(e)).split("");for(let s=0;s<e.length;s++){let a=!1;if(u[s]>="ﹰ"&&u[s]<"\ufeff"){const f=e.charCodeAt(s);u[s]>="ﻵ"&&u[s]<="ﻼ"?(n?(s>0&&o&&" "===u[s-1]?i=i.substring(0,i.length-1)+"ل":(i+="ل",a=!0),i+=t[(f-65269)/2]):(i+=t[(f-65269)/2],i+="ل",s+1<e.length&&o&&" "===u[s+1]?s++:a=!0),a&&(ut(at,s,!0,1),st.splice(s,0,st[s]))):i+=r[f-65136]}else i+=u[s]}return i}function y(t,r){const e=t.split(""),n=[];return D(e,n,r),P(e,n,r),G(2,e,n,r),G(1,e,n,r),ft=n,e.join("")}function D(t,r,o){const i=t.length,u=o.dir?e:n;let a=0,f=-1;const c=[],l=[];o.hiLevel=o.dir,o.lastArabic=!1,o.hasUbatAl=!1,o.hasUbatB=!1,o.hasUbatS=!1;for(let e=0;e<i;e++)c[e]=z(t[e]);for(let e=0;e<i;e++){const n=a,i=H(t,c,l,e,o);l[e]=i,a=u[n][i];const h=240&a;a&=15;const T=u[a][lt];if(r[e]=T,h>0)if(16===h){for(let t=f;t<e;t++)r[t]=1;f=-1}else f=-1;if(u[a][ht])-1===f&&(f=e);else if(f>-1){for(let t=f;t<e;t++)r[t]=T;f=-1}c[e]===s&&(r[e]=0),o.hiLevel|=T}o.hasUbatS&&Y(c,r,i,o)}function Y(t,r,e,n){for(let o=0;o<e;o++)if(t[o]===a){r[o]=n.dir;for(let e=o-1;e>=0&&t[e]===f;e--)r[e]=n.dir}}function P(t,r,e){if(0!==e.hiLevel&&e.swap.substr(0,1)!==e.swap.substr(1,2))for(let n=0;n<t.length;n++)1===r[n]&&(t[n]=J(t[n]))}function z(t){const r=t.charCodeAt(0),e=c[r>>8];return e<o?e:i[e-o][255&r]}function M(t,r){const e=t.split("");if(r){const t=[];D(e,t,r),ft=t}return e.reverse(),st.reverse(),e.join("")}function W(t,r,e){for(let n=0;n<r;n++)if(t[n]===e)return n;return-1}function Z(t){for(let r=0;r<l.length;r++)if(t>=l[r]&&t<=h[r])return!0;return!1}function $(t,r,e,n){for(;r*e<n&&tt(t[r]);)r+=e;return!!(r*e<n&&Z(t[r]))}function q(r,e,n,o){for(;e*n<o&&tt(r[e]);)e+=n;let i=" ";if(!(e*n<o))return!1;i=r[e];for(let u=0;u<t.length;u++)if(t[u]===i)return!0;return!1}function G(t,r,e,n){if(n.hiLevel<t)return;if(1===t&&n.dir===Lt&&!n.hasUbatB)return r.reverse(),void st.reverse();const o=r.length;let i,u,s,a,f,c=0;for(;c<o;){if(e[c]>=t){for(i=c+1;i<o&&e[i]>=t;)i++;for(u=c,s=i-1;u<s;u++,s--)a=r[u],r[u]=r[s],r[s]=a,f=st[u],st[u]=st[s],st[s]=f;c=i}c++}}function H(t,r,e,n,o){const i=r[n];return{UBAT_L:()=>(o.lastArabic=!1,T),UBAT_R:()=>(o.lastArabic=!1,L),UBAT_ON:()=>A,UBAT_AN:()=>g,UBAT_EN:()=>o.lastArabic?g:d,UBAT_AL:()=>(o.lastArabic=!0,o.hasUbatAl=!0,L),UBAT_WS:()=>A,UBAT_CS:()=>{let t,i;return n<1||n+1>=r.length||(t=e[n-1])!==d&&t!==g||(i=r[n+1])!==d&&i!==g?A:(o.lastArabic&&(i=g),i===t?i:A)},UBAT_ES:()=>(n>0?e[n-1]:s)===d&&n+1<r.length&&r[n+1]===d?d:A,UBAT_ET:()=>{if(n>0&&e[n-1]===d)return d;if(o.lastArabic)return A;let t=n+1;const i=r.length;for(;t<i&&r[t]===m;)t++;return t<i&&r[t]===d?d:A},UBAT_NSM:()=>{if("VLTR"===o.inFormat){const e=r.length;let o=n+1;for(;o<e&&r[o]===F;)o++;if(o<e){const e=t[n].charCodeAt[0],i=e>=1425&&e<=2303||64286===e,u=r[o];if(i&&(u===L||u===b))return L}}return n<1||r[n-1]===s?A:e[n-1]},UBAT_B:()=>(o.lastArabic=!0,o.hasUbatB=!0,o.dir),UBAT_S:()=>(o.hasUbatS=!0,A),UBAT_LRE:()=>(o.lastArabic=!1,A),UBAT_RLE:()=>(o.lastArabic=!1,A),UBAT_LRO:()=>(o.lastArabic=!1,A),UBAT_RLO:()=>(o.lastArabic=!1,A),UBAT_PDF:()=>(o.lastArabic=!1,A),UBAT_BN:()=>A}[u[i]]()}function J(t){let r,e=0,n=p.length-1;for(;e<=n;)if(r=Math.floor((e+n)/2),t<p[r][0])n=r-1;else{if(!(t>p[r][0]))return p[r][1];e=r+1}return t}function K(t){for(let r=0;r<R.length;r++)if(R[r]===t)return!0;return!1}function Q(t){for(let r=0;r<U.length;r++)if(t===U[r])return B[r];return t}function X(t,r){for(let e=0;e<U.length;e++)if(t===U[e])return r[e];return t}function tt(t){return t>="ً"&&t<="ٕ"}function rt(t){return"L"===t?"LTR":"R"===t?"RTL":"C"===t?"CLR":"D"===t?"CRL":""}function et(t,r,e,n){for(;r*e<n&&tt(t[r]);)r+=e;return r*e<n&&(t[r]=" ",!0)}function nt(r,e){for(let n=0;n<t.length;n++)if(r===t[n])return e[n];return r}function ot(t,r,e){st=[],ft=[];for(let n=0;n<e;n++)t[n]=n,r[n]=n,st[n]=n}function it(t){const r=new Array(t.length);for(let e=0;e<t.length;e++)r[t[e]]=e;return r}function ut(t,r,e,n){for(let o=0;o<t.length;o++)(t[o]>r||!e&&t[o]===r)&&(t[o]+=n)}let st=[],at=[],ft=[];const ct={dir:0,defInFormat:"LLTR",defoutFormat:"VLTR",defSwap:"YN",inFormat:"LLTR",outFormat:"VLTR",swap:"YN",hiLevel:0,lastArabic:!1,hasUbatAl:!1,hasBlockSep:!1,hasSegSep:!1,defOutFormat:""},lt=5,ht=6,Tt=0,Lt=1,At=/^[(I|V)][(L|R|C|D)][(Y|N)][(S|N)][N]$/,gt=/[\u0591-\u06ff\ufb1d-\ufefc]/;export{C as default};
|