var A,B;A=this,B=function(){function A(A){return function(A,B,Q,g){var C=null;if("undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node)C=Buffer.from(Q,"base64");else{var E=globalThis.atob(Q),I=E.length;C=new Uint8Array(new ArrayBuffer(I));for(var F=0;F<I;F++)C[F]=E.charCodeAt(F)}return function(A,B){var Q=WebAssembly.instantiate,g=WebAssembly.compile;return B?Q(A,B):g(A)}(C,g)}(0,0,"[encoded data, 130388 characters]",A)}return async function(){const{instance:B}=await A({env:{emscripten_resize_heap:()=>0,_abort_js(){throw new Error("abort")},_setitimer_js(){},_emscripten_runtime_keepalive_clear(){}},wasi_snapshot_preview1:{proc_exit(){}}});B.exports.__wasm_call_ctors();const Q=B.exports.memory.buffer,g=new Uint8Array(Q),C=new Uint16Array(Q),E=new Int32Array(Q),{ushapeArabic:I,bidiProcessText:F,bidiGetParagraphEnd:w,bidiSetLine:U,bidiGetVisualRun:D,bidiWriteReverse:G,malloc:s,free:Y}=B.exports,o=new TextDecoder("utf-16le");function c(A){let B=A>>1;for(;C[B];)B++;return o.decode(g.subarray(A,B<<1))}function L(A,B){const Q=B>>1;for(let B=0;B<A.length;B++)C[Q+B]=A.charCodeAt(B);C[Q+A.length]=0}function K(A,B){const Q=[];for(let g=0;g<B;g++){const B=w(g);for(const g of A)g<B&&(!Q.length||g>Q[Q.length-1])&&Q.push(g);Q.push(B)}for(const B of A)B>Q[Q.length-1]&&Q.push(B);return Q}function N(A){const B=s(2*(A.length+1));L(A,B);const Q=F(B,A.length);return 0===Q?(Y(B),null):{stringInputPtr:B,paragraphCount:Q}}const k=/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g,i={applyArabicShaping:function(A){if(!A)return A;const B=s(2*(A.length+1));L(A,B);const Q=I(B,A.length);if(Y(B),0===Q)return A;const g=c(Q);return Y(Q),g},processBidirectionalText:function(A,B){const Q=N(A);if(!Q)return[A];const g=-1!==A.search(k),{stringInputPtr:C,paragraphCount:I}=Q,F=K(B,I);let w=0;const o=[],L=s(8),i=L>>2;for(const B of F){let Q="";const I=U(w,B);if(!I)return Y(L),Y(C),[];for(let B=0;B<I;B++){const I=D(B,L,L+4),F=w+E[i],U=E[i+1];if(I){const A=G(C,F,U);if(0===A)return Y(L),Y(C),[];Q+=c(A),Y(A)}else{const B=A.substring(F,F+U);Q+=g?B.replace(k,""):B}}o.push(Q),w=B}return Y(L),Y(C),o},processStyledBidirectionalText:function(A,B,Q){const g=N(A);if(!g)return[[A,B]];const{stringInputPtr:C,paragraphCount:I}=g,F=K(Q,I);let w=0;const o=[],L=s(8),k=L>>2;for(const Q of F){let g="",I=[];const F=U(w,Q);if(!F)return Y(L),Y(C),[];for(let Q=0;Q<F;Q++){const F=D(Q,L,L+4),U=w+E[k],s=U+E[k+1];if(F){let A=s,Q=B[A-1];for(let E=s-1;E>=U;E--)if(Q!==B[E]||E===U){const F=E===U?E:E+1,w=G(C,F,A-F);if(0===w)return Y(L),Y(C),[];const D=c(w);Y(w),g+=D;for(let A=0;A<D.length;A++)I.push(Q);Q=B[E],A=F}}else g+=A.substring(U,s),I=I.concat(B.slice(U,s))}o.push([g,I]),w=Q}return Y(L),Y(C),o}};return"undefined"!=typeof self&&self.registerRTLTextPlugin&&self.registerRTLTextPlugin(i),i}()},"object"==typeof exports&&"undefined"!=typeof module?module.exports=B():"function"==typeof define&&define.amd?define(B):(A="undefined"!=typeof globalThis?globalThis:A||self)["mapbox-gl-rtl-text"]=B();
