UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.63 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{aLefTable as t,feTo06Table as r,impTabRtl as e,impTabLtr as n,ubatB as i,arabicAlefBetIntervalsBegine as o,arabicAlefBetIntervalsEnd as a,baseForm as s,medialForm as u,standAlonForm as f,primaryTable as c,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(it(this.sourceToTarget,this.targetToSource,t.length),!this.checkParameters(r,e))return t;r=this.inputFormat,e=this.outputFormat;let n=t;const i=ct,o=rt(r.charAt(1)),a=rt(e.charAt(1)),s=(r.startsWith("I")?"L":r.charAt(0))+o,u=(e.startsWith("I")?"L":e.charAt(0))+a,f=r.charAt(2)+e.charAt(2);i.defInFormat=s,i.defOutFormat=u,i.defSwap=f;const c=V(t,s,u,f,i);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=ot(this.sourceToTarget),ut=this.targetToSource,n=r.charAt(3)===e.charAt(3)?c:"S"===e.charAt(3)?I(l,c):W(c,l,!0),this.sourceToTarget=st,this.targetToSource=ut,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 dt.test(t)}}function V(t,r,e,n,i){const o=E(t,{inFormat:r,outFormat:e,swap:n},i);if(o.inFormat===o.outFormat)return t;r=o.inFormat,e=o.outFormat,n=o.swap;const a=r.slice(0,1),s=r.slice(1,4),u=e.slice(0,1),f=e.slice(1,4);if(i.inFormat=r,i.outFormat=e,i.swap=n,"L"===a&&"VLTR"===e){if("LTR"===s)return i.dir=Tt,k(t,i);if("RTL"===s)return i.dir=Lt,k(t,i)}if("V"===a&&"V"===u)return i.dir="RTL"===s?Lt:Tt,z(t,i);if("L"===a&&"VRTL"===e)return"LTR"===s?(i.dir=Tt,t=k(t,i)):(i.dir=Lt,t=k(t,i)),z(t);if("VLTR"===r&&"LLTR"===e)return i.dir=Tt,k(t,i);if("V"===a&&"L"===u&&s!==f)return t=z(t),"RTL"===s?V(t,"LLTR","VLTR",n,i):V(t,"LRTL","VRTL",n,i);if("VRTL"===r&&"LRTL"===e)return V(t,"LRTL","VRTL",n,i);if("L"===a&&"L"===u){const r=i.swap;return i.swap=r.slice(0,1)+"N","RTL"===s?(i.dir=Lt,t=k(t,i),i.swap="N"+r.slice(1,3),i.dir=Tt,t=k(t,i)):(i.dir=Tt,t=k(t,i),i.swap="N"+r.slice(1,3),t=V(t,"VLTR","LRTL",i.swap,i)),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),i=r.outFormat.slice(0,1);let o,a=r.inFormat.slice(1,4),s=r.outFormat.slice(1,4);return a.startsWith("C")&&(o=x(t),a="ltr"===o||"rtl"===o?o.toUpperCase():"L"===r.inFormat.charAt(2)?"LTR":"RTL",r.inFormat=n+a),s.startsWith("C")&&(o=x(t),"rtl"===o?s="RTL":"ltr"===o?(o=O(t),s=o.toUpperCase()):s="L"===r.outFormat.charAt(2)?"LTR":"RTL",r.outFormat=i+s),r}function I(t,r,e){if(0===r.length)return"";void 0===t&&(t=!0);const n=(r=String(r)).split("");let i=0,o=1,a=n.length;t||(i=n.length-1,o=-1,a=1);const s=j(n,i,o,a);let u="";for(let f=0;f<n.length;f++)M(s,s.length,f)>-1?(at(ut,f,!t,-1),st.splice(f,1)):u+=n[f];return u}function j(t,r,e,n,i){let o=0;const a=[];let s=0;for(let u=r;u*e<n;u+=e)if(Z(t[u])||tt(t[u])){if("ل"===t[u]&&q(t,u+e,e,n)){t[u]=nt(t[u+e],0===o?U:B),u+=e,et(t,u,e,n),a[s]=u,s++,o=0;continue}const r=t[u];1===o?t[u]=$(t,u+e,e,n)?Q(t[u]):X(t[u],S):!0===$(t,u+e,e,n)?t[u]=X(t[u],w):t[u]=X(t[u],_),tt(r)||(o=1),!0===K(r)&&(o=0)}else o=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 W(e,n,i){if(0===e.length)return"";void 0===n&&(n=!0);let o="";const a=(e=String(e)).split("");for(let s=0;s<e.length;s++){let u=!1;if(a[s]>="ﹰ"&&a[s]<"\ufeff"){const f=e.charCodeAt(s);a[s]>="ﻵ"&&a[s]<="ﻼ"?(n?(s>0&&i&&" "===a[s-1]?o=o.slice(0,-1)+"ل":(o+="ل",u=!0),o+=t[(f-65269)/2]):(o+=t[(f-65269)/2],o+="ل",s+1<e.length&&i&&" "===a[s+1]?s++:u=!0),u&&(at(ut,s,!0,1),st.splice(s,0,st[s]))):o+=r[f-65136]}else o+=a[s]}return o}function k(t,r){const e=t.split(""),n=[];return y(e,n,r),Y(e,n,r),G(2,e,n,r),G(1,e,n,r),ft=n,e.join("")}function y(t,r,o){const a=t.length,s=o.dir?e:n;let u=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<a;e++)c[e]=P(t[e]);for(let e=0;e<a;e++){const n=u,a=H(t,c,l,e,o);l[e]=a,u=s[n][a];const h=240&u;u&=15;const T=s[u][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(s[u][ht])-1===f&&(f=e);else if(f>-1){for(let t=f;t<e;t++)r[t]=T;f=-1}c[e]===i&&(r[e]=0),o.hiLevel|=T}o.hasUbatS&&D(c,r,a,o)}function D(t,r,e,n){for(let i=0;i<e;i++)if(t[i]===g){r[i]=n.dir;for(let e=i-1;e>=0&&t[e]===m;e--)r[e]=n.dir}}function Y(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 P(t){const r=t.charCodeAt(0),e=c[r>>8];return e<h?e:l[e-h][255&r]}function z(t,r){const e=t.split("");if(r){const t=[];y(e,t,r),ft=t}return e.reverse(),st.reverse(),e.join("")}function M(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<o.length;r++)if(t>=o[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,i){for(;e*n<i&&tt(r[e]);)e+=n;let o=" ";if(!(e*n<i))return!1;o=r[e];for(let a=0;a<t.length;a++)if(t[a]===o)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 i=r.length;let o,a,s,u,f,c=0;for(;c<i;){if(e[c]>=t){for(o=c+1;o<i&&e[o]>=t;)o++;for(a=c,s=o-1;a<s;a++,s--)u=r[a],r[a]=r[s],r[s]=u,f=st[a],st[a]=st[s],st[s]=f;c=o}c++}}function H(t,r,e,n,o){const a=r[n];return{UBAT_L:()=>(o.lastArabic=!1,b),UBAT_R:()=>(o.lastArabic=!1,p),UBAT_ON:()=>T,UBAT_AN:()=>L,UBAT_EN:()=>o.lastArabic?L:A,UBAT_AL:()=>(o.lastArabic=!0,o.hasUbatAl=!0,p),UBAT_WS:()=>T,UBAT_CS:()=>{let t,i;return n<1||n+1>=r.length||(t=e[n-1])!==A&&t!==L||(i=r[n+1])!==A&&i!==L?T:(o.lastArabic&&(i=L),i===t?i:T)},UBAT_ES:()=>(n>0?e[n-1]:i)===A&&n+1<r.length&&r[n+1]===A?A:T,UBAT_ET:()=>{if(n>0&&e[n-1]===A)return A;if(o.lastArabic)return T;let t=n+1;const i=r.length;for(;t<i&&r[t]===N;)t++;return t<i&&r[t]===A?A:T},UBAT_NSM:()=>{if("VLTR"===o.inFormat){const e=r.length;let i=n+1;for(;i<e&&r[i]===v;)i++;if(i<e){const e=t[n].charCodeAt(0),o=e>=1425&&e<=2303||64286===e,a=r[i];if(o&&(a===p||a===R))return p}}return n<1||r[n-1]===i?T:e[n-1]},UBAT_B:()=>(o.lastArabic=!0,o.hasUbatB=!0,o.dir),UBAT_S:()=>(o.hasUbatS=!0,T),UBAT_LRE:()=>(o.lastArabic=!1,T),UBAT_RLE:()=>(o.lastArabic=!1,T),UBAT_LRO:()=>(o.lastArabic=!1,T),UBAT_RLO:()=>(o.lastArabic=!1,T),UBAT_PDF:()=>(o.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<f.length;r++)if(f[r]===t)return!0;return!1}function Q(t){for(let r=0;r<s.length;r++)if(t===s[r])return u[r];return t}function X(t,r){for(let e=0;e<s.length;e++)if(t===s[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 it(t,r,e){st=[],ft=[];for(let n=0;n<e;n++)t[n]=n,r[n]=n,st[n]=n}function ot(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 i=0;i<t.length;i++)(t[i]>r||!e&&t[i]===r)&&(t[i]+=n)}let st=[],ut=[],ft=[];const ct={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|RCD)][(Y|N)][(S|N)]N$/,dt=/[\u0591-\u06ff\ufb1d-\ufefc]/;export{C as default};