UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 8.72 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{aLefTable as t,feTo06Table as r,impTabRtl as e,impTabLtr as n,ubatB as o,arabicAlefBetIntervalsBegine as i,arabicAlefBetIntervalsEnd as a,baseForm as u,medialForm as s,standAlonForm as c,primaryTable as f,unicodeTable as l,tbbase as h,ubatOn as T,ubatAn as L,ubatEn as A,typesNames as d,ubatS as g,ubatWs as m,swapTable as F,ubatR as p,ubatAl as R,ubatL as b,lamAlefInialTableFE as U,lamAlefMedialTableFE as B,finalForm as S,initialForm as w,isolatedForm as _,ubatNsm as v,ubatEt 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=ft,i=rt(r.charAt(1)),a=rt(e.charAt(1)),u=("I"===r.charAt(0)?"L":r.charAt(0))+i,s=("I"===e.charAt(0)?"L":e.charAt(0))+a,c=r.charAt(2)+e.charAt(2);o.defInFormat=u,o.defOutFormat=s,o.defSwap=c;const f=V(t,u,s,c,o);let l=!1;return"R"===e.charAt(1)?l=!0:"C"!==e.charAt(1)&&"D"!==e.charAt(1)||(l="rtl"===this.checkContextual(f)),this.sourceToTarget=ut,this.targetToSource=it(this.sourceToTarget),st=this.targetToSource,n=r.charAt(3)===e.charAt(3)?f:"S"===e.charAt(3)?I(l,f):k(f,l,!0),this.sourceToTarget=ut,this.targetToSource=st,this.levels=ct,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 dt.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 a=r.slice(0,1),u=r.slice(1,4),s=e.slice(0,1),c=e.slice(1,4);if(o.inFormat=r,o.outFormat=e,o.swap=n,"L"===a&&"VLTR"===e){if("LTR"===u)return o.dir=Tt,y(t,o);if("RTL"===u)return o.dir=Lt,y(t,o)}if("V"===a&&"V"===s)return o.dir="RTL"===u?Lt:Tt,M(t,o);if("L"===a&&"VRTL"===e)return"LTR"===u?(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"===a&&"L"===s&&u!==c)return t=M(t),"RTL"===u?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"===a&&"L"===s){const r=o.swap;return o.swap=r.slice(0,1)+"N","RTL"===u?(o.dir=Lt,t=y(t,o),o.swap="N"+r.slice(1,3),o.dir=Tt,t=y(t,o)):(o.dir=Tt,t=y(t,o),o.swap="N"+r.slice(1,3),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.slice(0,1),o=r.outFormat.slice(0,1);let i,a=r.inFormat.slice(1,4),u=r.outFormat.slice(1,4);return"C"===a.charAt(0)&&(i=x(t),a="ltr"===i||"rtl"===i?i.toUpperCase():"L"===r.inFormat.charAt(2)?"LTR":"RTL",r.inFormat=n+a),"C"===u.charAt(0)&&(i=x(t),"rtl"===i?u="RTL":"ltr"===i?(i=O(t),u=i.toUpperCase()):u="L"===r.outFormat.charAt(2)?"LTR":"RTL",r.outFormat=o+u),r}function I(t,r,e){if(0===r.length)return"";void 0===t&&(t=!0);const n=(r=String(r)).split("");let o=0,i=1,a=n.length;t||(o=n.length-1,i=-1,a=1);const u=j(n,o,i,a);let s="";for(let c=0;c<n.length;c++)W(u,u.length,c)>-1?(at(st,c,!t,-1),ut.splice(c,1)):s+=n[c];return s}function j(t,r,e,n,o){let i=0;const a=[];let u=0;for(let s=r;s*e<n;s+=e)if(Z(t[s])||tt(t[s])){if("ل"===t[s]&&q(t,s+e,e,n)){t[s]=nt(t[s+e],0===i?U:B),s+=e,et(t,s,e,n),a[u]=s,u++,i=0;continue}const r=t[s];1===i?t[s]=$(t,s+e,e,n)?Q(t[s]):X(t[s],S):!0===$(t,s+e,e,n)?t[s]=X(t[s],w):t[s]=X(t[s],_),tt(r)||(i=1),!0===K(r)&&(i=0)}else i=0;return a}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===n&&(n=!0);let i="";const a=(e=String(e)).split("");for(let u=0;u<e.length;u++){let s=!1;if(a[u]>="ﹰ"&&a[u]<"\ufeff"){const c=e.charCodeAt(u);a[u]>="ﻵ"&&a[u]<="ﻼ"?(n?(u>0&&o&&" "===a[u-1]?i=i.slice(0,-1)+"ل":(i+="ل",s=!0),i+=t[(c-65269)/2]):(i+=t[(c-65269)/2],i+="ل",u+1<e.length&&o&&" "===a[u+1]?u++:s=!0),s&&(at(st,u,!0,1),ut.splice(u,0,ut[u]))):i+=r[c-65136]}else i+=a[u]}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),ct=n,e.join("")}function D(t,r,i){const a=t.length,u=i.dir?e:n;let s=0,c=-1;const f=[],l=[];i.hiLevel=i.dir,i.lastArabic=!1,i.hasUbatAl=!1,i.hasUbatB=!1,i.hasUbatS=!1;for(let e=0;e<a;e++)f[e]=z(t[e]);for(let e=0;e<a;e++){const n=s,a=H(t,f,l,e,i);l[e]=a,s=u[n][a];const h=240&s;s&=15;const T=u[s][lt];if(r[e]=T,h>0)if(16===h){for(let t=c;t<e;t++)r[t]=1;c=-1}else c=-1;if(u[s][ht])-1===c&&(c=e);else if(c>-1){for(let t=c;t<e;t++)r[t]=T;c=-1}f[e]===o&&(r[e]=0),i.hiLevel|=T}i.hasUbatS&&Y(f,r,a,i)}function Y(t,r,e,n){for(let o=0;o<e;o++)if(t[o]===g){r[o]=n.dir;for(let e=o-1;e>=0&&t[e]===m;e--)r[e]=n.dir}}function P(t,r,e){if(0!==e.hiLevel&&e.swap[0]!==e.swap[1])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=f[r>>8];return e<h?e:l[e-h][255&r]}function M(t,r){const e=t.split("");if(r){const t=[];D(e,t,r),ct=t}return e.reverse(),ut.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<i.length;r++)if(t>=i[r]&&t<=a[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 a=0;a<t.length;a++)if(t[a]===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 ut.reverse();const o=r.length;let i,a,u,s,c,f=0;for(;f<o;){if(e[f]>=t){for(i=f+1;i<o&&e[i]>=t;)i++;for(a=f,u=i-1;a<u;a++,u--)s=r[a],r[a]=r[u],r[u]=s,c=ut[a],ut[a]=ut[u],ut[u]=c;f=i}f++}}function H(t,r,e,n,i){const a=r[n];return{UBAT_L:()=>(i.lastArabic=!1,b),UBAT_R:()=>(i.lastArabic=!1,p),UBAT_ON:()=>T,UBAT_AN:()=>L,UBAT_EN:()=>i.lastArabic?L:A,UBAT_AL:()=>(i.lastArabic=!0,i.hasUbatAl=!0,p),UBAT_WS:()=>T,UBAT_CS:()=>{let t,o;return n<1||n+1>=r.length||(t=e[n-1])!==A&&t!==L||(o=r[n+1])!==A&&o!==L?T:(i.lastArabic&&(o=L),o===t?o:T)},UBAT_ES:()=>(n>0?e[n-1]:o)===A&&n+1<r.length&&r[n+1]===A?A:T,UBAT_ET:()=>{if(n>0&&e[n-1]===A)return A;if(i.lastArabic)return T;let t=n+1;const o=r.length;for(;t<o&&r[t]===N;)t++;return t<o&&r[t]===A?A:T},UBAT_NSM:()=>{if("VLTR"===i.inFormat){const e=r.length;let o=n+1;for(;o<e&&r[o]===v;)o++;if(o<e){const e=t[n].charCodeAt(0),i=e>=1425&&e<=2303||64286===e,a=r[o];if(i&&(a===p||a===R))return p}}return n<1||r[n-1]===o?T:e[n-1]},UBAT_B:()=>(i.lastArabic=!0,i.hasUbatB=!0,i.dir),UBAT_S:()=>(i.hasUbatS=!0,T),UBAT_LRE:()=>(i.lastArabic=!1,T),UBAT_RLE:()=>(i.lastArabic=!1,T),UBAT_LRO:()=>(i.lastArabic=!1,T),UBAT_RLO:()=>(i.lastArabic=!1,T),UBAT_PDF:()=>(i.lastArabic=!1,T),UBAT_BN:()=>T}[d[a]]()}function J(t){let r,e=0,n=F.length-1;for(;e<=n;)if(r=Math.floor((e+n)/2),t<F[r][0])n=r-1;else{if(!(t>F[r][0]))return F[r][1];e=r+1}return t}function K(t){for(let r=0;r<c.length;r++)if(c[r]===t)return!0;return!1}function Q(t){for(let r=0;r<u.length;r++)if(t===u[r])return s[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){ut=[],ct=[];for(let n=0;n<e;n++)t[n]=n,r[n]=n,ut[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 at(t,r,e,n){for(let o=0;o<t.length;o++)(t[o]>r||!e&&t[o]===r)&&(t[o]+=n)}let ut=[],st=[],ct=[];const ft={dir:0,defInFormat:"LLTR",defSwap:"YN",inFormat:"LLTR",outFormat:"VLTR",swap:"YN",hiLevel:0,lastArabic:!1,hasUbatAl:!1,defOutFormat:""},lt=5,ht=6,Tt=0,Lt=1,At=/^[(I|V)][(L|R|C|D)][(Y|N)][(S|N)][N]$/,dt=/[\u0591-\u06ff\ufb1d-\ufefc]/;export{C as default};