@vectojs/core 1.7.1 → 1.8.0

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.
@@ -0,0 +1,1121 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// src/text/ArabicShaper.ts
2
+ var ArabicShaper = (_class = class _ArabicShaper {
3
+ static __initStatic() {this.MAPPINGS = {
4
+ 1569: { isolated: 65152, initial: 65152, medial: 65152, final: 65152, joining: "U" },
5
+ // Hamza
6
+ 1570: { isolated: 65153, initial: 65153, medial: 65154, final: 65154, joining: "R" },
7
+ // Alef Madda
8
+ 1571: { isolated: 65155, initial: 65155, medial: 65156, final: 65156, joining: "R" },
9
+ // Alef Hamza Above
10
+ 1572: { isolated: 65157, initial: 65157, medial: 65158, final: 65158, joining: "R" },
11
+ // Waw Hamza
12
+ 1573: { isolated: 65159, initial: 65159, medial: 65160, final: 65160, joining: "R" },
13
+ // Alef Hamza Below
14
+ 1574: { isolated: 65161, initial: 65163, medial: 65164, final: 65162, joining: "D" },
15
+ // Yeh Hamza
16
+ 1575: { isolated: 65165, initial: 65165, medial: 65166, final: 65166, joining: "R" },
17
+ // Alef
18
+ 1576: { isolated: 65167, initial: 65169, medial: 65170, final: 65168, joining: "D" },
19
+ // Ba
20
+ 1577: { isolated: 65171, initial: 65171, medial: 65172, final: 65172, joining: "R" },
21
+ // Teh Marbuta
22
+ 1578: { isolated: 65173, initial: 65175, medial: 65176, final: 65174, joining: "D" },
23
+ // Teh
24
+ 1579: { isolated: 65177, initial: 65179, medial: 65180, final: 65178, joining: "D" },
25
+ // Theh
26
+ 1580: { isolated: 65181, initial: 65183, medial: 65184, final: 65182, joining: "D" },
27
+ // Jeem
28
+ 1581: { isolated: 65185, initial: 65187, medial: 65188, final: 65186, joining: "D" },
29
+ // Hah
30
+ 1582: { isolated: 65189, initial: 65191, medial: 65192, final: 65190, joining: "D" },
31
+ // Khav
32
+ 1583: { isolated: 65193, initial: 65193, medial: 65194, final: 65194, joining: "R" },
33
+ // Dal
34
+ 1584: { isolated: 65195, initial: 65195, medial: 65196, final: 65196, joining: "R" },
35
+ // Thal
36
+ 1585: { isolated: 65197, initial: 65197, medial: 65198, final: 65198, joining: "R" },
37
+ // Ra
38
+ 1586: { isolated: 65199, initial: 65199, medial: 65200, final: 65200, joining: "R" },
39
+ // Zay
40
+ 1587: { isolated: 65201, initial: 65203, medial: 65204, final: 65202, joining: "D" },
41
+ // Seen
42
+ 1588: { isolated: 65205, initial: 65207, medial: 65208, final: 65206, joining: "D" },
43
+ // Sheen
44
+ 1589: { isolated: 65209, initial: 65211, medial: 65212, final: 65210, joining: "D" },
45
+ // Sad
46
+ 1590: { isolated: 65213, initial: 65215, medial: 65216, final: 65214, joining: "D" },
47
+ // Dad
48
+ 1591: { isolated: 65217, initial: 65219, medial: 65220, final: 65218, joining: "D" },
49
+ // Tah
50
+ 1592: { isolated: 65221, initial: 65223, medial: 65224, final: 65222, joining: "D" },
51
+ // Zah
52
+ 1593: { isolated: 65225, initial: 65227, medial: 65228, final: 65226, joining: "D" },
53
+ // Ain
54
+ 1594: { isolated: 65229, initial: 65231, medial: 65232, final: 65230, joining: "D" },
55
+ // Ghain
56
+ 1601: { isolated: 65233, initial: 65235, medial: 65236, final: 65234, joining: "D" },
57
+ // Feh
58
+ 1602: { isolated: 65237, initial: 65239, medial: 65240, final: 65238, joining: "D" },
59
+ // Qaf
60
+ 1603: { isolated: 65241, initial: 65243, medial: 65244, final: 65242, joining: "D" },
61
+ // Kaf
62
+ 1604: { isolated: 65245, initial: 65247, medial: 65248, final: 65246, joining: "D" },
63
+ // Lam
64
+ 1605: { isolated: 65249, initial: 65251, medial: 65252, final: 65250, joining: "D" },
65
+ // Meem
66
+ 1606: { isolated: 65253, initial: 65255, medial: 65256, final: 65254, joining: "D" },
67
+ // Noon
68
+ 1607: { isolated: 65257, initial: 65259, medial: 65260, final: 65258, joining: "D" },
69
+ // Heh
70
+ 1608: { isolated: 65261, initial: 65261, medial: 65262, final: 65262, joining: "R" },
71
+ // Waw
72
+ 1609: { isolated: 65263, initial: 65263, medial: 65264, final: 65264, joining: "R" },
73
+ // Alef Maksura
74
+ 1610: { isolated: 65265, initial: 65267, medial: 65268, final: 65266, joining: "D" },
75
+ // Yeh
76
+ // Persian / Urdu Extensions
77
+ 1662: { isolated: 64342, initial: 64344, medial: 64345, final: 64343, joining: "D" },
78
+ // Peh
79
+ 1670: { isolated: 64378, initial: 64380, medial: 64381, final: 64379, joining: "D" },
80
+ // Tcheh
81
+ 1705: { isolated: 64398, initial: 64400, medial: 64401, final: 64399, joining: "D" },
82
+ // Keheh
83
+ 1729: { isolated: 64422, initial: 64424, medial: 64425, final: 64423, joining: "D" },
84
+ // Heh Goal
85
+ 1740: { isolated: 64509, initial: 64511, medial: 64512, final: 64510, joining: "D" }
86
+ // Farsi Yeh
87
+ }}
88
+ static isHarakat(code) {
89
+ return code >= 1611 && code <= 1631 || code === 1648;
90
+ }
91
+ static getJoiningType(code) {
92
+ const f = _ArabicShaper.MAPPINGS[code];
93
+ return f ? f.joining : "U";
94
+ }
95
+ static shapeArabic(text) {
96
+ const len = text.length;
97
+ const shapedChars = [];
98
+ const sourceIndices = [];
99
+ let i = 0;
100
+ while (i < len) {
101
+ const code = text.charCodeAt(i);
102
+ if (code === 1604 && i + 1 < len) {
103
+ const nextCode2 = text.charCodeAt(i + 1);
104
+ let ligature = 0;
105
+ if (nextCode2 === 1570)
106
+ ligature = 65269;
107
+ else if (nextCode2 === 1571)
108
+ ligature = 65271;
109
+ else if (nextCode2 === 1573)
110
+ ligature = 65273;
111
+ else if (nextCode2 === 1575) ligature = 65275;
112
+ if (ligature !== 0) {
113
+ let previousBase = 0;
114
+ let previousIndex = i - 1;
115
+ while (previousIndex >= 0) {
116
+ const previousCode = text.charCodeAt(previousIndex);
117
+ if (!_ArabicShaper.isHarakat(previousCode)) {
118
+ previousBase = previousCode;
119
+ break;
120
+ }
121
+ previousIndex--;
122
+ }
123
+ if (_ArabicShaper.getJoiningType(previousBase) === "D") ligature++;
124
+ shapedChars.push(String.fromCharCode(ligature));
125
+ sourceIndices.push(i);
126
+ i += 2;
127
+ continue;
128
+ }
129
+ }
130
+ if (_ArabicShaper.isHarakat(code)) {
131
+ shapedChars.push(text[i]);
132
+ sourceIndices.push(i);
133
+ i++;
134
+ continue;
135
+ }
136
+ const forms = _ArabicShaper.MAPPINGS[code];
137
+ if (!forms) {
138
+ shapedChars.push(text[i]);
139
+ sourceIndices.push(i);
140
+ i++;
141
+ continue;
142
+ }
143
+ let prevCode = 0;
144
+ let j = i - 1;
145
+ while (j >= 0) {
146
+ const c = text.charCodeAt(j);
147
+ if (!_ArabicShaper.isHarakat(c)) {
148
+ prevCode = c;
149
+ break;
150
+ }
151
+ j--;
152
+ }
153
+ let nextCode = 0;
154
+ let k = i + 1;
155
+ while (k < len) {
156
+ const c = text.charCodeAt(k);
157
+ if (!_ArabicShaper.isHarakat(c)) {
158
+ nextCode = c;
159
+ break;
160
+ }
161
+ k++;
162
+ }
163
+ const connectPrev = prevCode !== 0 && _ArabicShaper.getJoiningType(prevCode) === "D" && (forms.joining === "D" || forms.joining === "R");
164
+ const connectNext = nextCode !== 0 && forms.joining === "D" && (_ArabicShaper.getJoiningType(nextCode) === "D" || _ArabicShaper.getJoiningType(nextCode) === "R");
165
+ let glyph = forms.isolated;
166
+ if (connectPrev && connectNext) glyph = forms.medial;
167
+ else if (connectPrev) glyph = forms.final;
168
+ else if (connectNext) glyph = forms.initial;
169
+ shapedChars.push(String.fromCharCode(glyph));
170
+ sourceIndices.push(i);
171
+ i++;
172
+ }
173
+ return {
174
+ shapedText: shapedChars.join(""),
175
+ indexMap: new Int32Array(sourceIndices)
176
+ };
177
+ }
178
+ }, _class.__initStatic(), _class);
179
+
180
+ // ../../node_modules/.bun/bidi-js@1.0.3/node_modules/bidi-js/dist/bidi.mjs
181
+ function bidiFactory() {
182
+ var bidi2 = (function(exports) {
183
+ var DATA = {
184
+ "R": "13k,1a,2,3,3,2+1j,ch+16,a+1,5+2,2+n,5,a,4,6+16,4+3,h+1b,4mo,179q,2+9,2+11,2i9+7y,2+68,4,3+4,5+13,4+3,2+4k,3+29,8+cf,1t+7z,w+17,3+3m,1t+3z,16o1+5r,8+30,8+mc,29+1r,29+4v,75+73",
185
+ "EN": "1c+9,3d+1,6,187+9,513,4+5,7+9,sf+j,175h+9,qw+q,161f+1d,4xt+a,25i+9",
186
+ "ES": "17,2,6dp+1,f+1,av,16vr,mx+1,4o,2",
187
+ "ET": "z+2,3h+3,b+1,ym,3e+1,2o,p4+1,8,6u,7c,g6,1wc,1n9+4,30+1b,2n,6d,qhx+1,h0m,a+1,49+2,63+1,4+1,6bb+3,12jj",
188
+ "AN": "16o+5,2j+9,2+1,35,ed,1ff2+9,87+u",
189
+ "CS": "18,2+1,b,2u,12k,55v,l,17v0,2,3,53,2+1,b",
190
+ "B": "a,3,f+2,2v,690",
191
+ "S": "9,2,k",
192
+ "WS": "c,k,4f4,1vk+a,u,1j,335",
193
+ "ON": "x+1,4+4,h+5,r+5,r+3,z,5+3,2+1,2+1,5,2+2,3+4,o,w,ci+1,8+d,3+d,6+8,2+g,39+1,9,6+1,2,33,b8,3+1,3c+1,7+1,5r,b,7h+3,sa+5,2,3i+6,jg+3,ur+9,2v,ij+1,9g+9,7+a,8m,4+1,49+x,14u,2+2,c+2,e+2,e+2,e+1,i+n,e+e,2+p,u+2,e+2,36+1,2+3,2+1,b,2+2,6+5,2,2,2,h+1,5+4,6+3,3+f,16+2,5+3l,3+81,1y+p,2+40,q+a,m+13,2r+ch,2+9e,75+hf,3+v,2+2w,6e+5,f+6,75+2a,1a+p,2+2g,d+5x,r+b,6+3,4+o,g,6+1,6+2,2k+1,4,2j,5h+z,1m+1,1e+f,t+2,1f+e,d+3,4o+3,2s+1,w,535+1r,h3l+1i,93+2,2s,b+1,3l+x,2v,4g+3,21+3,kz+1,g5v+1,5a,j+9,n+v,2,3,2+8,2+1,3+2,2,3,46+1,4+4,h+5,r+5,r+a,3h+2,4+6,b+4,78,1r+24,4+c,4,1hb,ey+6,103+j,16j+c,1ux+7,5+g,fsh,jdq+1t,4,57+2e,p1,1m,1m,1m,1m,4kt+1,7j+17,5+2r,d+e,3+e,2+e,2+10,m+4,w,1n+5,1q,4z+5,4b+rb,9+c,4+c,4+37,d+2g,8+b,l+b,5+1j,9+9,7+13,9+t,3+1,27+3c,2+29,2+3q,d+d,3+4,4+2,6+6,a+o,8+6,a+2,e+6,16+42,2+1i",
194
+ "BN": "0+8,6+d,2s+5,2+p,e,4m9,1kt+2,2b+5,5+5,17q9+v,7k,6p+8,6+1,119d+3,440+7,96s+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+75,6p+2rz,1ben+1,1ekf+1,1ekf+1",
195
+ "NSM": "lc+33,7o+6,7c+18,2,2+1,2+1,2,21+a,1d+k,h,2u+6,3+5,3+1,2+3,10,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,g+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+g,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,k1+w,2db+2,3y,2p+v,ff+3,30+1,n9x+3,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,r2,6b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+5,3+1,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2d+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,f0c+4,1o+6,t5,1s+3,2a,f5l+1,43t+2,i+7,3+6,v+3,45+2,1j0+1i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,gzhy+6n",
196
+ "AL": "16w,3,2,e+1b,z+2,2+2s,g+1,8+1,b+m,2+t,s+2i,c+e,4h+f,1d+1e,1bwe+dp,3+3z,x+c,2+1,35+3y,2rm+z,5+7,b+5,dt+l,c+u,17nl+27,1t+27,4x+6n,3+d",
197
+ "LRO": "6ct",
198
+ "RLO": "6cu",
199
+ "LRE": "6cq",
200
+ "RLE": "6cr",
201
+ "PDF": "6cs",
202
+ "LRI": "6ee",
203
+ "RLI": "6ef",
204
+ "FSI": "6eg",
205
+ "PDI": "6eh"
206
+ };
207
+ var TYPES = {};
208
+ var TYPES_TO_NAMES = {};
209
+ TYPES.L = 1;
210
+ TYPES_TO_NAMES[1] = "L";
211
+ Object.keys(DATA).forEach(function(type, i) {
212
+ TYPES[type] = 1 << i + 1;
213
+ TYPES_TO_NAMES[TYPES[type]] = type;
214
+ });
215
+ Object.freeze(TYPES);
216
+ var ISOLATE_INIT_TYPES = TYPES.LRI | TYPES.RLI | TYPES.FSI;
217
+ var STRONG_TYPES = TYPES.L | TYPES.R | TYPES.AL;
218
+ var NEUTRAL_ISOLATE_TYPES = TYPES.B | TYPES.S | TYPES.WS | TYPES.ON | TYPES.FSI | TYPES.LRI | TYPES.RLI | TYPES.PDI;
219
+ var BN_LIKE_TYPES = TYPES.BN | TYPES.RLE | TYPES.LRE | TYPES.RLO | TYPES.LRO | TYPES.PDF;
220
+ var TRAILING_TYPES = TYPES.S | TYPES.WS | TYPES.B | ISOLATE_INIT_TYPES | TYPES.PDI | BN_LIKE_TYPES;
221
+ var map = null;
222
+ function parseData() {
223
+ if (!map) {
224
+ map = /* @__PURE__ */ new Map();
225
+ var loop = function(type2) {
226
+ if (DATA.hasOwnProperty(type2)) {
227
+ var lastCode = 0;
228
+ DATA[type2].split(",").forEach(function(range) {
229
+ var ref = range.split("+");
230
+ var skip = ref[0];
231
+ var step = ref[1];
232
+ skip = parseInt(skip, 36);
233
+ step = step ? parseInt(step, 36) : 0;
234
+ map.set(lastCode += skip, TYPES[type2]);
235
+ for (var i = 0; i < step; i++) {
236
+ map.set(++lastCode, TYPES[type2]);
237
+ }
238
+ });
239
+ }
240
+ };
241
+ for (var type in DATA) loop(type);
242
+ }
243
+ }
244
+ function getBidiCharType(char) {
245
+ parseData();
246
+ return map.get(char.codePointAt(0)) || TYPES.L;
247
+ }
248
+ function getBidiCharTypeName(char) {
249
+ return TYPES_TO_NAMES[getBidiCharType(char)];
250
+ }
251
+ var data$1 = {
252
+ "pairs": "14>1,1e>2,u>2,2wt>1,1>1,1ge>1,1wp>1,1j>1,f>1,hm>1,1>1,u>1,u6>1,1>1,+5,28>1,w>1,1>1,+3,b8>1,1>1,+3,1>3,-1>-1,3>1,1>1,+2,1s>1,1>1,x>1,th>1,1>1,+2,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,4q>1,1e>2,u>2,2>1,+1",
253
+ "canonical": "6f1>-6dx,6dy>-6dx,6ec>-6ed,6ee>-6ed,6ww>2jj,-2ji>2jj,14r4>-1e7l,1e7m>-1e7l,1e7m>-1e5c,1e5d>-1e5b,1e5c>-14qx,14qy>-14qx,14vn>-1ecg,1ech>-1ecg,1edu>-1ecg,1eci>-1ecg,1eda>-1ecg,1eci>-1ecg,1eci>-168q,168r>-168q,168s>-14ye,14yf>-14ye"
254
+ };
255
+ function parseCharacterMap(encodedString, includeReverse) {
256
+ var radix = 36;
257
+ var lastCode = 0;
258
+ var map2 = /* @__PURE__ */ new Map();
259
+ var reverseMap = includeReverse && /* @__PURE__ */ new Map();
260
+ var prevPair;
261
+ encodedString.split(",").forEach(function visit(entry) {
262
+ if (entry.indexOf("+") !== -1) {
263
+ for (var i = +entry; i--; ) {
264
+ visit(prevPair);
265
+ }
266
+ } else {
267
+ prevPair = entry;
268
+ var ref = entry.split(">");
269
+ var a = ref[0];
270
+ var b = ref[1];
271
+ a = String.fromCodePoint(lastCode += parseInt(a, radix));
272
+ b = String.fromCodePoint(lastCode += parseInt(b, radix));
273
+ map2.set(a, b);
274
+ includeReverse && reverseMap.set(b, a);
275
+ }
276
+ });
277
+ return { map: map2, reverseMap };
278
+ }
279
+ var openToClose, closeToOpen, canonical;
280
+ function parse$1() {
281
+ if (!openToClose) {
282
+ var ref = parseCharacterMap(data$1.pairs, true);
283
+ var map2 = ref.map;
284
+ var reverseMap = ref.reverseMap;
285
+ openToClose = map2;
286
+ closeToOpen = reverseMap;
287
+ canonical = parseCharacterMap(data$1.canonical, false).map;
288
+ }
289
+ }
290
+ function openingToClosingBracket(char) {
291
+ parse$1();
292
+ return openToClose.get(char) || null;
293
+ }
294
+ function closingToOpeningBracket(char) {
295
+ parse$1();
296
+ return closeToOpen.get(char) || null;
297
+ }
298
+ function getCanonicalBracket(char) {
299
+ parse$1();
300
+ return canonical.get(char) || null;
301
+ }
302
+ var TYPE_L = TYPES.L;
303
+ var TYPE_R = TYPES.R;
304
+ var TYPE_EN = TYPES.EN;
305
+ var TYPE_ES = TYPES.ES;
306
+ var TYPE_ET = TYPES.ET;
307
+ var TYPE_AN = TYPES.AN;
308
+ var TYPE_CS = TYPES.CS;
309
+ var TYPE_B = TYPES.B;
310
+ var TYPE_S = TYPES.S;
311
+ var TYPE_ON = TYPES.ON;
312
+ var TYPE_BN = TYPES.BN;
313
+ var TYPE_NSM = TYPES.NSM;
314
+ var TYPE_AL = TYPES.AL;
315
+ var TYPE_LRO = TYPES.LRO;
316
+ var TYPE_RLO = TYPES.RLO;
317
+ var TYPE_LRE = TYPES.LRE;
318
+ var TYPE_RLE = TYPES.RLE;
319
+ var TYPE_PDF = TYPES.PDF;
320
+ var TYPE_LRI = TYPES.LRI;
321
+ var TYPE_RLI = TYPES.RLI;
322
+ var TYPE_FSI = TYPES.FSI;
323
+ var TYPE_PDI = TYPES.PDI;
324
+ function getEmbeddingLevels(string, baseDirection) {
325
+ var MAX_DEPTH = 125;
326
+ var charTypes = new Uint32Array(string.length);
327
+ for (var i = 0; i < string.length; i++) {
328
+ charTypes[i] = getBidiCharType(string[i]);
329
+ }
330
+ var charTypeCounts = /* @__PURE__ */ new Map();
331
+ function changeCharType(i2, type2) {
332
+ var oldType = charTypes[i2];
333
+ charTypes[i2] = type2;
334
+ charTypeCounts.set(oldType, charTypeCounts.get(oldType) - 1);
335
+ if (oldType & NEUTRAL_ISOLATE_TYPES) {
336
+ charTypeCounts.set(NEUTRAL_ISOLATE_TYPES, charTypeCounts.get(NEUTRAL_ISOLATE_TYPES) - 1);
337
+ }
338
+ charTypeCounts.set(type2, (charTypeCounts.get(type2) || 0) + 1);
339
+ if (type2 & NEUTRAL_ISOLATE_TYPES) {
340
+ charTypeCounts.set(NEUTRAL_ISOLATE_TYPES, (charTypeCounts.get(NEUTRAL_ISOLATE_TYPES) || 0) + 1);
341
+ }
342
+ }
343
+ var embedLevels = new Uint8Array(string.length);
344
+ var isolationPairs = /* @__PURE__ */ new Map();
345
+ var paragraphs = [];
346
+ var paragraph = null;
347
+ for (var i$1 = 0; i$1 < string.length; i$1++) {
348
+ if (!paragraph) {
349
+ paragraphs.push(paragraph = {
350
+ start: i$1,
351
+ end: string.length - 1,
352
+ // 3.3.1 P2-P3: Determine the paragraph level
353
+ level: baseDirection === "rtl" ? 1 : baseDirection === "ltr" ? 0 : determineAutoEmbedLevel(i$1, false)
354
+ });
355
+ }
356
+ if (charTypes[i$1] & TYPE_B) {
357
+ paragraph.end = i$1;
358
+ paragraph = null;
359
+ }
360
+ }
361
+ var FORMATTING_TYPES = TYPE_RLE | TYPE_LRE | TYPE_RLO | TYPE_LRO | ISOLATE_INIT_TYPES | TYPE_PDI | TYPE_PDF | TYPE_B;
362
+ var nextEven = function(n) {
363
+ return n + (n & 1 ? 1 : 2);
364
+ };
365
+ var nextOdd = function(n) {
366
+ return n + (n & 1 ? 2 : 1);
367
+ };
368
+ for (var paraIdx = 0; paraIdx < paragraphs.length; paraIdx++) {
369
+ paragraph = paragraphs[paraIdx];
370
+ var statusStack = [{
371
+ _level: paragraph.level,
372
+ _override: 0,
373
+ //0=neutral, 1=L, 2=R
374
+ _isolate: 0
375
+ //bool
376
+ }];
377
+ var stackTop = void 0;
378
+ var overflowIsolateCount = 0;
379
+ var overflowEmbeddingCount = 0;
380
+ var validIsolateCount = 0;
381
+ charTypeCounts.clear();
382
+ for (var i$2 = paragraph.start; i$2 <= paragraph.end; i$2++) {
383
+ var charType = charTypes[i$2];
384
+ stackTop = statusStack[statusStack.length - 1];
385
+ charTypeCounts.set(charType, (charTypeCounts.get(charType) || 0) + 1);
386
+ if (charType & NEUTRAL_ISOLATE_TYPES) {
387
+ charTypeCounts.set(NEUTRAL_ISOLATE_TYPES, (charTypeCounts.get(NEUTRAL_ISOLATE_TYPES) || 0) + 1);
388
+ }
389
+ if (charType & FORMATTING_TYPES) {
390
+ if (charType & (TYPE_RLE | TYPE_LRE)) {
391
+ embedLevels[i$2] = stackTop._level;
392
+ var level = (charType === TYPE_RLE ? nextOdd : nextEven)(stackTop._level);
393
+ if (level <= MAX_DEPTH && !overflowIsolateCount && !overflowEmbeddingCount) {
394
+ statusStack.push({
395
+ _level: level,
396
+ _override: 0,
397
+ _isolate: 0
398
+ });
399
+ } else if (!overflowIsolateCount) {
400
+ overflowEmbeddingCount++;
401
+ }
402
+ } else if (charType & (TYPE_RLO | TYPE_LRO)) {
403
+ embedLevels[i$2] = stackTop._level;
404
+ var level$1 = (charType === TYPE_RLO ? nextOdd : nextEven)(stackTop._level);
405
+ if (level$1 <= MAX_DEPTH && !overflowIsolateCount && !overflowEmbeddingCount) {
406
+ statusStack.push({
407
+ _level: level$1,
408
+ _override: charType & TYPE_RLO ? TYPE_R : TYPE_L,
409
+ _isolate: 0
410
+ });
411
+ } else if (!overflowIsolateCount) {
412
+ overflowEmbeddingCount++;
413
+ }
414
+ } else if (charType & ISOLATE_INIT_TYPES) {
415
+ if (charType & TYPE_FSI) {
416
+ charType = determineAutoEmbedLevel(i$2 + 1, true) === 1 ? TYPE_RLI : TYPE_LRI;
417
+ }
418
+ embedLevels[i$2] = stackTop._level;
419
+ if (stackTop._override) {
420
+ changeCharType(i$2, stackTop._override);
421
+ }
422
+ var level$2 = (charType === TYPE_RLI ? nextOdd : nextEven)(stackTop._level);
423
+ if (level$2 <= MAX_DEPTH && overflowIsolateCount === 0 && overflowEmbeddingCount === 0) {
424
+ validIsolateCount++;
425
+ statusStack.push({
426
+ _level: level$2,
427
+ _override: 0,
428
+ _isolate: 1,
429
+ _isolInitIndex: i$2
430
+ });
431
+ } else {
432
+ overflowIsolateCount++;
433
+ }
434
+ } else if (charType & TYPE_PDI) {
435
+ if (overflowIsolateCount > 0) {
436
+ overflowIsolateCount--;
437
+ } else if (validIsolateCount > 0) {
438
+ overflowEmbeddingCount = 0;
439
+ while (!statusStack[statusStack.length - 1]._isolate) {
440
+ statusStack.pop();
441
+ }
442
+ var isolInitIndex = statusStack[statusStack.length - 1]._isolInitIndex;
443
+ if (isolInitIndex != null) {
444
+ isolationPairs.set(isolInitIndex, i$2);
445
+ isolationPairs.set(i$2, isolInitIndex);
446
+ }
447
+ statusStack.pop();
448
+ validIsolateCount--;
449
+ }
450
+ stackTop = statusStack[statusStack.length - 1];
451
+ embedLevels[i$2] = stackTop._level;
452
+ if (stackTop._override) {
453
+ changeCharType(i$2, stackTop._override);
454
+ }
455
+ } else if (charType & TYPE_PDF) {
456
+ if (overflowIsolateCount === 0) {
457
+ if (overflowEmbeddingCount > 0) {
458
+ overflowEmbeddingCount--;
459
+ } else if (!stackTop._isolate && statusStack.length > 1) {
460
+ statusStack.pop();
461
+ stackTop = statusStack[statusStack.length - 1];
462
+ }
463
+ }
464
+ embedLevels[i$2] = stackTop._level;
465
+ } else if (charType & TYPE_B) {
466
+ embedLevels[i$2] = paragraph.level;
467
+ }
468
+ } else {
469
+ embedLevels[i$2] = stackTop._level;
470
+ if (stackTop._override && charType !== TYPE_BN) {
471
+ changeCharType(i$2, stackTop._override);
472
+ }
473
+ }
474
+ }
475
+ var levelRuns = [];
476
+ var currentRun = null;
477
+ for (var i$3 = paragraph.start; i$3 <= paragraph.end; i$3++) {
478
+ var charType$1 = charTypes[i$3];
479
+ if (!(charType$1 & BN_LIKE_TYPES)) {
480
+ var lvl = embedLevels[i$3];
481
+ var isIsolInit = charType$1 & ISOLATE_INIT_TYPES;
482
+ var isPDI = charType$1 === TYPE_PDI;
483
+ if (currentRun && lvl === currentRun._level) {
484
+ currentRun._end = i$3;
485
+ currentRun._endsWithIsolInit = isIsolInit;
486
+ } else {
487
+ levelRuns.push(currentRun = {
488
+ _start: i$3,
489
+ _end: i$3,
490
+ _level: lvl,
491
+ _startsWithPDI: isPDI,
492
+ _endsWithIsolInit: isIsolInit
493
+ });
494
+ }
495
+ }
496
+ }
497
+ var isolatingRunSeqs = [];
498
+ for (var runIdx = 0; runIdx < levelRuns.length; runIdx++) {
499
+ var run = levelRuns[runIdx];
500
+ if (!run._startsWithPDI || run._startsWithPDI && !isolationPairs.has(run._start)) {
501
+ var seqRuns = [currentRun = run];
502
+ for (var pdiIndex = void 0; currentRun && currentRun._endsWithIsolInit && (pdiIndex = isolationPairs.get(currentRun._end)) != null; ) {
503
+ for (var i$4 = runIdx + 1; i$4 < levelRuns.length; i$4++) {
504
+ if (levelRuns[i$4]._start === pdiIndex) {
505
+ seqRuns.push(currentRun = levelRuns[i$4]);
506
+ break;
507
+ }
508
+ }
509
+ }
510
+ var seqIndices = [];
511
+ for (var i$5 = 0; i$5 < seqRuns.length; i$5++) {
512
+ var run$1 = seqRuns[i$5];
513
+ for (var j = run$1._start; j <= run$1._end; j++) {
514
+ seqIndices.push(j);
515
+ }
516
+ }
517
+ var firstLevel = embedLevels[seqIndices[0]];
518
+ var prevLevel = paragraph.level;
519
+ for (var i$6 = seqIndices[0] - 1; i$6 >= 0; i$6--) {
520
+ if (!(charTypes[i$6] & BN_LIKE_TYPES)) {
521
+ prevLevel = embedLevels[i$6];
522
+ break;
523
+ }
524
+ }
525
+ var lastIndex = seqIndices[seqIndices.length - 1];
526
+ var lastLevel = embedLevels[lastIndex];
527
+ var nextLevel = paragraph.level;
528
+ if (!(charTypes[lastIndex] & ISOLATE_INIT_TYPES)) {
529
+ for (var i$7 = lastIndex + 1; i$7 <= paragraph.end; i$7++) {
530
+ if (!(charTypes[i$7] & BN_LIKE_TYPES)) {
531
+ nextLevel = embedLevels[i$7];
532
+ break;
533
+ }
534
+ }
535
+ }
536
+ isolatingRunSeqs.push({
537
+ _seqIndices: seqIndices,
538
+ _sosType: Math.max(prevLevel, firstLevel) % 2 ? TYPE_R : TYPE_L,
539
+ _eosType: Math.max(nextLevel, lastLevel) % 2 ? TYPE_R : TYPE_L
540
+ });
541
+ }
542
+ }
543
+ for (var seqIdx = 0; seqIdx < isolatingRunSeqs.length; seqIdx++) {
544
+ var ref = isolatingRunSeqs[seqIdx];
545
+ var seqIndices$1 = ref._seqIndices;
546
+ var sosType = ref._sosType;
547
+ var eosType = ref._eosType;
548
+ var embedDirection = embedLevels[seqIndices$1[0]] & 1 ? TYPE_R : TYPE_L;
549
+ if (charTypeCounts.get(TYPE_NSM)) {
550
+ for (var si = 0; si < seqIndices$1.length; si++) {
551
+ var i$8 = seqIndices$1[si];
552
+ if (charTypes[i$8] & TYPE_NSM) {
553
+ var prevType = sosType;
554
+ for (var sj = si - 1; sj >= 0; sj--) {
555
+ if (!(charTypes[seqIndices$1[sj]] & BN_LIKE_TYPES)) {
556
+ prevType = charTypes[seqIndices$1[sj]];
557
+ break;
558
+ }
559
+ }
560
+ changeCharType(i$8, prevType & (ISOLATE_INIT_TYPES | TYPE_PDI) ? TYPE_ON : prevType);
561
+ }
562
+ }
563
+ }
564
+ if (charTypeCounts.get(TYPE_EN)) {
565
+ for (var si$1 = 0; si$1 < seqIndices$1.length; si$1++) {
566
+ var i$9 = seqIndices$1[si$1];
567
+ if (charTypes[i$9] & TYPE_EN) {
568
+ for (var sj$1 = si$1 - 1; sj$1 >= -1; sj$1--) {
569
+ var prevCharType = sj$1 === -1 ? sosType : charTypes[seqIndices$1[sj$1]];
570
+ if (prevCharType & STRONG_TYPES) {
571
+ if (prevCharType === TYPE_AL) {
572
+ changeCharType(i$9, TYPE_AN);
573
+ }
574
+ break;
575
+ }
576
+ }
577
+ }
578
+ }
579
+ }
580
+ if (charTypeCounts.get(TYPE_AL)) {
581
+ for (var si$2 = 0; si$2 < seqIndices$1.length; si$2++) {
582
+ var i$10 = seqIndices$1[si$2];
583
+ if (charTypes[i$10] & TYPE_AL) {
584
+ changeCharType(i$10, TYPE_R);
585
+ }
586
+ }
587
+ }
588
+ if (charTypeCounts.get(TYPE_ES) || charTypeCounts.get(TYPE_CS)) {
589
+ for (var si$3 = 1; si$3 < seqIndices$1.length - 1; si$3++) {
590
+ var i$11 = seqIndices$1[si$3];
591
+ if (charTypes[i$11] & (TYPE_ES | TYPE_CS)) {
592
+ var prevType$1 = 0, nextType = 0;
593
+ for (var sj$2 = si$3 - 1; sj$2 >= 0; sj$2--) {
594
+ prevType$1 = charTypes[seqIndices$1[sj$2]];
595
+ if (!(prevType$1 & BN_LIKE_TYPES)) {
596
+ break;
597
+ }
598
+ }
599
+ for (var sj$3 = si$3 + 1; sj$3 < seqIndices$1.length; sj$3++) {
600
+ nextType = charTypes[seqIndices$1[sj$3]];
601
+ if (!(nextType & BN_LIKE_TYPES)) {
602
+ break;
603
+ }
604
+ }
605
+ if (prevType$1 === nextType && (charTypes[i$11] === TYPE_ES ? prevType$1 === TYPE_EN : prevType$1 & (TYPE_EN | TYPE_AN))) {
606
+ changeCharType(i$11, prevType$1);
607
+ }
608
+ }
609
+ }
610
+ }
611
+ if (charTypeCounts.get(TYPE_EN)) {
612
+ for (var si$4 = 0; si$4 < seqIndices$1.length; si$4++) {
613
+ var i$12 = seqIndices$1[si$4];
614
+ if (charTypes[i$12] & TYPE_EN) {
615
+ for (var sj$4 = si$4 - 1; sj$4 >= 0 && charTypes[seqIndices$1[sj$4]] & (TYPE_ET | BN_LIKE_TYPES); sj$4--) {
616
+ changeCharType(seqIndices$1[sj$4], TYPE_EN);
617
+ }
618
+ for (si$4++; si$4 < seqIndices$1.length && charTypes[seqIndices$1[si$4]] & (TYPE_ET | BN_LIKE_TYPES | TYPE_EN); si$4++) {
619
+ if (charTypes[seqIndices$1[si$4]] !== TYPE_EN) {
620
+ changeCharType(seqIndices$1[si$4], TYPE_EN);
621
+ }
622
+ }
623
+ }
624
+ }
625
+ }
626
+ if (charTypeCounts.get(TYPE_ET) || charTypeCounts.get(TYPE_ES) || charTypeCounts.get(TYPE_CS)) {
627
+ for (var si$5 = 0; si$5 < seqIndices$1.length; si$5++) {
628
+ var i$13 = seqIndices$1[si$5];
629
+ if (charTypes[i$13] & (TYPE_ET | TYPE_ES | TYPE_CS)) {
630
+ changeCharType(i$13, TYPE_ON);
631
+ for (var sj$5 = si$5 - 1; sj$5 >= 0 && charTypes[seqIndices$1[sj$5]] & BN_LIKE_TYPES; sj$5--) {
632
+ changeCharType(seqIndices$1[sj$5], TYPE_ON);
633
+ }
634
+ for (var sj$6 = si$5 + 1; sj$6 < seqIndices$1.length && charTypes[seqIndices$1[sj$6]] & BN_LIKE_TYPES; sj$6++) {
635
+ changeCharType(seqIndices$1[sj$6], TYPE_ON);
636
+ }
637
+ }
638
+ }
639
+ }
640
+ if (charTypeCounts.get(TYPE_EN)) {
641
+ for (var si$6 = 0, prevStrongType = sosType; si$6 < seqIndices$1.length; si$6++) {
642
+ var i$14 = seqIndices$1[si$6];
643
+ var type = charTypes[i$14];
644
+ if (type & TYPE_EN) {
645
+ if (prevStrongType === TYPE_L) {
646
+ changeCharType(i$14, TYPE_L);
647
+ }
648
+ } else if (type & STRONG_TYPES) {
649
+ prevStrongType = type;
650
+ }
651
+ }
652
+ }
653
+ if (charTypeCounts.get(NEUTRAL_ISOLATE_TYPES)) {
654
+ var R_TYPES_FOR_N_STEPS = TYPE_R | TYPE_EN | TYPE_AN;
655
+ var STRONG_TYPES_FOR_N_STEPS = R_TYPES_FOR_N_STEPS | TYPE_L;
656
+ var bracketPairs = [];
657
+ {
658
+ var openerStack = [];
659
+ for (var si$7 = 0; si$7 < seqIndices$1.length; si$7++) {
660
+ if (charTypes[seqIndices$1[si$7]] & NEUTRAL_ISOLATE_TYPES) {
661
+ var char = string[seqIndices$1[si$7]];
662
+ var oppositeBracket = void 0;
663
+ if (openingToClosingBracket(char) !== null) {
664
+ if (openerStack.length < 63) {
665
+ openerStack.push({ char, seqIndex: si$7 });
666
+ } else {
667
+ break;
668
+ }
669
+ } else if ((oppositeBracket = closingToOpeningBracket(char)) !== null) {
670
+ for (var stackIdx = openerStack.length - 1; stackIdx >= 0; stackIdx--) {
671
+ var stackChar = openerStack[stackIdx].char;
672
+ if (stackChar === oppositeBracket || stackChar === closingToOpeningBracket(getCanonicalBracket(char)) || openingToClosingBracket(getCanonicalBracket(stackChar)) === char) {
673
+ bracketPairs.push([openerStack[stackIdx].seqIndex, si$7]);
674
+ openerStack.length = stackIdx;
675
+ break;
676
+ }
677
+ }
678
+ }
679
+ }
680
+ }
681
+ bracketPairs.sort(function(a, b) {
682
+ return a[0] - b[0];
683
+ });
684
+ }
685
+ for (var pairIdx = 0; pairIdx < bracketPairs.length; pairIdx++) {
686
+ var ref$1 = bracketPairs[pairIdx];
687
+ var openSeqIdx = ref$1[0];
688
+ var closeSeqIdx = ref$1[1];
689
+ var foundStrongType = false;
690
+ var useStrongType = 0;
691
+ for (var si$8 = openSeqIdx + 1; si$8 < closeSeqIdx; si$8++) {
692
+ var i$15 = seqIndices$1[si$8];
693
+ if (charTypes[i$15] & STRONG_TYPES_FOR_N_STEPS) {
694
+ foundStrongType = true;
695
+ var lr = charTypes[i$15] & R_TYPES_FOR_N_STEPS ? TYPE_R : TYPE_L;
696
+ if (lr === embedDirection) {
697
+ useStrongType = lr;
698
+ break;
699
+ }
700
+ }
701
+ }
702
+ if (foundStrongType && !useStrongType) {
703
+ useStrongType = sosType;
704
+ for (var si$9 = openSeqIdx - 1; si$9 >= 0; si$9--) {
705
+ var i$16 = seqIndices$1[si$9];
706
+ if (charTypes[i$16] & STRONG_TYPES_FOR_N_STEPS) {
707
+ var lr$1 = charTypes[i$16] & R_TYPES_FOR_N_STEPS ? TYPE_R : TYPE_L;
708
+ if (lr$1 !== embedDirection) {
709
+ useStrongType = lr$1;
710
+ } else {
711
+ useStrongType = embedDirection;
712
+ }
713
+ break;
714
+ }
715
+ }
716
+ }
717
+ if (useStrongType) {
718
+ charTypes[seqIndices$1[openSeqIdx]] = charTypes[seqIndices$1[closeSeqIdx]] = useStrongType;
719
+ if (useStrongType !== embedDirection) {
720
+ for (var si$10 = openSeqIdx + 1; si$10 < seqIndices$1.length; si$10++) {
721
+ if (!(charTypes[seqIndices$1[si$10]] & BN_LIKE_TYPES)) {
722
+ if (getBidiCharType(string[seqIndices$1[si$10]]) & TYPE_NSM) {
723
+ charTypes[seqIndices$1[si$10]] = useStrongType;
724
+ }
725
+ break;
726
+ }
727
+ }
728
+ }
729
+ if (useStrongType !== embedDirection) {
730
+ for (var si$11 = closeSeqIdx + 1; si$11 < seqIndices$1.length; si$11++) {
731
+ if (!(charTypes[seqIndices$1[si$11]] & BN_LIKE_TYPES)) {
732
+ if (getBidiCharType(string[seqIndices$1[si$11]]) & TYPE_NSM) {
733
+ charTypes[seqIndices$1[si$11]] = useStrongType;
734
+ }
735
+ break;
736
+ }
737
+ }
738
+ }
739
+ }
740
+ }
741
+ for (var si$12 = 0; si$12 < seqIndices$1.length; si$12++) {
742
+ if (charTypes[seqIndices$1[si$12]] & NEUTRAL_ISOLATE_TYPES) {
743
+ var niRunStart = si$12, niRunEnd = si$12;
744
+ var prevType$2 = sosType;
745
+ for (var si2 = si$12 - 1; si2 >= 0; si2--) {
746
+ if (charTypes[seqIndices$1[si2]] & BN_LIKE_TYPES) {
747
+ niRunStart = si2;
748
+ } else {
749
+ prevType$2 = charTypes[seqIndices$1[si2]] & R_TYPES_FOR_N_STEPS ? TYPE_R : TYPE_L;
750
+ break;
751
+ }
752
+ }
753
+ var nextType$1 = eosType;
754
+ for (var si2$1 = si$12 + 1; si2$1 < seqIndices$1.length; si2$1++) {
755
+ if (charTypes[seqIndices$1[si2$1]] & (NEUTRAL_ISOLATE_TYPES | BN_LIKE_TYPES)) {
756
+ niRunEnd = si2$1;
757
+ } else {
758
+ nextType$1 = charTypes[seqIndices$1[si2$1]] & R_TYPES_FOR_N_STEPS ? TYPE_R : TYPE_L;
759
+ break;
760
+ }
761
+ }
762
+ for (var sj$7 = niRunStart; sj$7 <= niRunEnd; sj$7++) {
763
+ charTypes[seqIndices$1[sj$7]] = prevType$2 === nextType$1 ? prevType$2 : embedDirection;
764
+ }
765
+ si$12 = niRunEnd;
766
+ }
767
+ }
768
+ }
769
+ }
770
+ for (var i$17 = paragraph.start; i$17 <= paragraph.end; i$17++) {
771
+ var level$3 = embedLevels[i$17];
772
+ var type$1 = charTypes[i$17];
773
+ if (level$3 & 1) {
774
+ if (type$1 & (TYPE_L | TYPE_EN | TYPE_AN)) {
775
+ embedLevels[i$17]++;
776
+ }
777
+ } else {
778
+ if (type$1 & TYPE_R) {
779
+ embedLevels[i$17]++;
780
+ } else if (type$1 & (TYPE_AN | TYPE_EN)) {
781
+ embedLevels[i$17] += 2;
782
+ }
783
+ }
784
+ if (type$1 & BN_LIKE_TYPES) {
785
+ embedLevels[i$17] = i$17 === 0 ? paragraph.level : embedLevels[i$17 - 1];
786
+ }
787
+ if (i$17 === paragraph.end || getBidiCharType(string[i$17]) & (TYPE_S | TYPE_B)) {
788
+ for (var j$1 = i$17; j$1 >= 0 && getBidiCharType(string[j$1]) & TRAILING_TYPES; j$1--) {
789
+ embedLevels[j$1] = paragraph.level;
790
+ }
791
+ }
792
+ }
793
+ }
794
+ return {
795
+ levels: embedLevels,
796
+ paragraphs
797
+ };
798
+ function determineAutoEmbedLevel(start, isFSI) {
799
+ for (var i2 = start; i2 < string.length; i2++) {
800
+ var charType2 = charTypes[i2];
801
+ if (charType2 & (TYPE_R | TYPE_AL)) {
802
+ return 1;
803
+ }
804
+ if (charType2 & (TYPE_B | TYPE_L) || isFSI && charType2 === TYPE_PDI) {
805
+ return 0;
806
+ }
807
+ if (charType2 & ISOLATE_INIT_TYPES) {
808
+ var pdi = indexOfMatchingPDI(i2);
809
+ i2 = pdi === -1 ? string.length : pdi;
810
+ }
811
+ }
812
+ return 0;
813
+ }
814
+ function indexOfMatchingPDI(isolateStart) {
815
+ var isolationLevel = 1;
816
+ for (var i2 = isolateStart + 1; i2 < string.length; i2++) {
817
+ var charType2 = charTypes[i2];
818
+ if (charType2 & TYPE_B) {
819
+ break;
820
+ }
821
+ if (charType2 & TYPE_PDI) {
822
+ if (--isolationLevel === 0) {
823
+ return i2;
824
+ }
825
+ } else if (charType2 & ISOLATE_INIT_TYPES) {
826
+ isolationLevel++;
827
+ }
828
+ }
829
+ return -1;
830
+ }
831
+ }
832
+ var data = "14>1,j>2,t>2,u>2,1a>g,2v3>1,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1";
833
+ var mirrorMap;
834
+ function parse() {
835
+ if (!mirrorMap) {
836
+ var ref = parseCharacterMap(data, true);
837
+ var map2 = ref.map;
838
+ var reverseMap = ref.reverseMap;
839
+ reverseMap.forEach(function(value, key) {
840
+ map2.set(key, value);
841
+ });
842
+ mirrorMap = map2;
843
+ }
844
+ }
845
+ function getMirroredCharacter(char) {
846
+ parse();
847
+ return mirrorMap.get(char) || null;
848
+ }
849
+ function getMirroredCharactersMap(string, embeddingLevels, start, end) {
850
+ var strLen = string.length;
851
+ start = Math.max(0, start == null ? 0 : +start);
852
+ end = Math.min(strLen - 1, end == null ? strLen - 1 : +end);
853
+ var map2 = /* @__PURE__ */ new Map();
854
+ for (var i = start; i <= end; i++) {
855
+ if (embeddingLevels[i] & 1) {
856
+ var mirror = getMirroredCharacter(string[i]);
857
+ if (mirror !== null) {
858
+ map2.set(i, mirror);
859
+ }
860
+ }
861
+ }
862
+ return map2;
863
+ }
864
+ function getReorderSegments(string, embeddingLevelsResult, start, end) {
865
+ var strLen = string.length;
866
+ start = Math.max(0, start == null ? 0 : +start);
867
+ end = Math.min(strLen - 1, end == null ? strLen - 1 : +end);
868
+ var segments = [];
869
+ embeddingLevelsResult.paragraphs.forEach(function(paragraph) {
870
+ var lineStart = Math.max(start, paragraph.start);
871
+ var lineEnd = Math.min(end, paragraph.end);
872
+ if (lineStart < lineEnd) {
873
+ var lineLevels = embeddingLevelsResult.levels.slice(lineStart, lineEnd + 1);
874
+ for (var i = lineEnd; i >= lineStart && getBidiCharType(string[i]) & TRAILING_TYPES; i--) {
875
+ lineLevels[i] = paragraph.level;
876
+ }
877
+ var maxLevel = paragraph.level;
878
+ var minOddLevel = Infinity;
879
+ for (var i$1 = 0; i$1 < lineLevels.length; i$1++) {
880
+ var level = lineLevels[i$1];
881
+ if (level > maxLevel) {
882
+ maxLevel = level;
883
+ }
884
+ if (level < minOddLevel) {
885
+ minOddLevel = level | 1;
886
+ }
887
+ }
888
+ for (var lvl = maxLevel; lvl >= minOddLevel; lvl--) {
889
+ for (var i$2 = 0; i$2 < lineLevels.length; i$2++) {
890
+ if (lineLevels[i$2] >= lvl) {
891
+ var segStart = i$2;
892
+ while (i$2 + 1 < lineLevels.length && lineLevels[i$2 + 1] >= lvl) {
893
+ i$2++;
894
+ }
895
+ if (i$2 > segStart) {
896
+ segments.push([segStart + lineStart, i$2 + lineStart]);
897
+ }
898
+ }
899
+ }
900
+ }
901
+ }
902
+ });
903
+ return segments;
904
+ }
905
+ function getReorderedString(string, embedLevelsResult, start, end) {
906
+ var indices = getReorderedIndices(string, embedLevelsResult, start, end);
907
+ var chars = [].concat(string);
908
+ indices.forEach(function(charIndex, i) {
909
+ chars[i] = (embedLevelsResult.levels[charIndex] & 1 ? getMirroredCharacter(string[charIndex]) : null) || string[charIndex];
910
+ });
911
+ return chars.join("");
912
+ }
913
+ function getReorderedIndices(string, embedLevelsResult, start, end) {
914
+ var segments = getReorderSegments(string, embedLevelsResult, start, end);
915
+ var indices = [];
916
+ for (var i = 0; i < string.length; i++) {
917
+ indices[i] = i;
918
+ }
919
+ segments.forEach(function(ref) {
920
+ var start2 = ref[0];
921
+ var end2 = ref[1];
922
+ var slice = indices.slice(start2, end2 + 1);
923
+ for (var i2 = slice.length; i2--; ) {
924
+ indices[end2 - i2] = slice[i2];
925
+ }
926
+ });
927
+ return indices;
928
+ }
929
+ exports.closingToOpeningBracket = closingToOpeningBracket;
930
+ exports.getBidiCharType = getBidiCharType;
931
+ exports.getBidiCharTypeName = getBidiCharTypeName;
932
+ exports.getCanonicalBracket = getCanonicalBracket;
933
+ exports.getEmbeddingLevels = getEmbeddingLevels;
934
+ exports.getMirroredCharacter = getMirroredCharacter;
935
+ exports.getMirroredCharactersMap = getMirroredCharactersMap;
936
+ exports.getReorderSegments = getReorderSegments;
937
+ exports.getReorderedIndices = getReorderedIndices;
938
+ exports.getReorderedString = getReorderedString;
939
+ exports.openingToClosingBracket = openingToClosingBracket;
940
+ Object.defineProperty(exports, "__esModule", { value: true });
941
+ return exports;
942
+ })({});
943
+ return bidi2;
944
+ }
945
+ var bidi_default = bidiFactory;
946
+
947
+ // src/text/BidiResolver.ts
948
+ var bidi = bidi_default();
949
+ var BidiResolver = class {
950
+ static getBaseLevel(text) {
951
+ return _nullishCoalesce(_optionalChain([bidi, 'access', _ => _.getEmbeddingLevels, 'call', _2 => _2(text), 'access', _3 => _3.paragraphs, 'access', _4 => _4[0], 'optionalAccess', _5 => _5.level]), () => ( 0));
952
+ }
953
+ static resolveLevels(text) {
954
+ return bidi.getEmbeddingLevels(text).levels;
955
+ }
956
+ static reorderVisual(nodes, baseLevel) {
957
+ const len = nodes.length;
958
+ if (len === 0) return;
959
+ let i = len - 1;
960
+ while (i >= 0) {
961
+ const node = nodes[i];
962
+ const code = node.char.charCodeAt(0);
963
+ const isWS = code === 32 || code === 9 || code === 160 || code === 8234 || code === 8235 || code === 8236;
964
+ if (isWS) {
965
+ node.level = baseLevel;
966
+ } else {
967
+ break;
968
+ }
969
+ i--;
970
+ }
971
+ let maxLevel = baseLevel;
972
+ for (let j = 0; j < len; j++) {
973
+ if (nodes[j].level > maxLevel) maxLevel = nodes[j].level;
974
+ }
975
+ for (let level = maxLevel; level >= 1; level--) {
976
+ let start = 0;
977
+ while (start < len) {
978
+ if (nodes[start].level >= level) {
979
+ let end = start;
980
+ while (end < len && nodes[end].level >= level) {
981
+ end++;
982
+ }
983
+ let left = start;
984
+ let right = end - 1;
985
+ while (left < right) {
986
+ const temp = nodes[left];
987
+ nodes[left] = nodes[right];
988
+ nodes[right] = temp;
989
+ left++;
990
+ right--;
991
+ }
992
+ start = end;
993
+ } else {
994
+ start++;
995
+ }
996
+ }
997
+ }
998
+ }
999
+ };
1000
+
1001
+ // src/layout/LayoutWorkerSource.ts
1002
+ var WORKER_SOURCE_STRING = '"use strict";(()=>{var C=new Map;function f(t){return typeof t=="number"&&Number.isFinite(t)}function U(t){return t.origin?t.origin===self.location.origin:!0}function j(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.id=="string"&&f(e.seqId)&&typeof e.text=="string"&&typeof e.fontId=="string"&&(e.fontData===void 0||typeof e.fontData=="object")&&f(e.maxWidth)&&f(e.maxHeight)&&f(e.fontSize)&&(e.lineHeight===void 0||f(e.lineHeight))&&(e.letterSpacing===void 0||f(e.letterSpacing))}self.onmessage=t=>{if(!U(t)||!j(t.data))return;let{id:e,seqId:D,text:L,fontId:k,fontData:S,maxWidth:H,maxHeight:z,fontSize:d,lineHeight:I,letterSpacing:M}=t.data;S&&C.set(k,S);let g=C.get(k);if(!g)return;let m=[],i=[],h=[],w=[],n=0,c=0,r=0,o=-1,p=g.metrics?.ascender??.8,R=g.metrics?.descender??-.2,b=I??d*(p-R),P=M??0,F=new Map;for(let s of g.glyphs??[])F.set(s.unicode,s.advance);let x=()=>{n>r&&(r=n),n=0,c++,o=-1},A=Array.from(L);for(let s=0;s<A.length;s++){let a=A[s].codePointAt(0);if(a===10){x();continue}let W=(F.get(a)??1)*d,q=a>=11904;if(q&&(o=-1),n+W>H&&n>0){if(a===32){x();continue}if(o>=0&&i[o]>0){let l=i[o];l>r&&(r=l),c++;let v=c*b+p*d;for(let y=o;y<i.length;y++)i[y]-=l,h[y]=v;n-=l}else x()}a===32?o=-1:o===-1&&!q&&(o=m.length),m.push(a),i.push(n),h.push(c*b+p*d),w.push(-256),n+=W+P}n>r&&(r=n);let u={id:e,seqId:D,width:r,height:(c+1)*b,codePoints:new Uint32Array(m),xCoords:new Float32Array(i),yCoords:new Float32Array(h),packedStyles:new Uint32Array(w)};self.postMessage(u,[u.codePoints.buffer,u.xCoords.buffer,u.yCoords.buffer,u.packedStyles.buffer])};})();\n';
1003
+
1004
+ // src/layout/LayoutWorkerManager.ts
1005
+ var LayoutWorkerManager = (_class2 = class _LayoutWorkerManager {
1006
+
1007
+ __init() {this.worker = null}
1008
+ __init2() {this.registeredFonts = /* @__PURE__ */ new Set()}
1009
+ __init3() {this.pendingCallbacks = /* @__PURE__ */ new Map()}
1010
+ __init4() {this.seqIdCounter = /* @__PURE__ */ new Map()}
1011
+ __init5() {this.debounceTimers = /* @__PURE__ */ new Map()}
1012
+ constructor() {;_class2.prototype.__init.call(this);_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
1013
+ this.worker = this.createWorker();
1014
+ }
1015
+ createWorker() {
1016
+ const workerBlob = new Blob([WORKER_SOURCE_STRING], { type: "application/javascript" });
1017
+ const workerURL = URL.createObjectURL(workerBlob);
1018
+ let worker;
1019
+ try {
1020
+ worker = new Worker(workerURL);
1021
+ } finally {
1022
+ URL.revokeObjectURL(workerURL);
1023
+ }
1024
+ worker.onmessage = (e) => {
1025
+ if (this.worker !== worker) return;
1026
+ const response = e.data;
1027
+ const key = `${response.id}-${response.seqId}`;
1028
+ const callback = this.pendingCallbacks.get(key);
1029
+ if (callback) {
1030
+ this.pendingCallbacks.delete(key);
1031
+ callback(response);
1032
+ }
1033
+ };
1034
+ worker.onerror = () => this.handleWorkerFailure(worker);
1035
+ worker.onmessageerror = () => this.handleWorkerFailure(worker);
1036
+ return worker;
1037
+ }
1038
+ ensureWorker() {
1039
+ if (!this.worker) this.worker = this.createWorker();
1040
+ return this.worker;
1041
+ }
1042
+ handleWorkerFailure(worker) {
1043
+ if (this.worker !== worker) return;
1044
+ worker.terminate();
1045
+ this.worker = null;
1046
+ this.pendingCallbacks.clear();
1047
+ this.registeredFonts.clear();
1048
+ }
1049
+ destroy() {
1050
+ for (const timer of this.debounceTimers.values()) clearTimeout(timer);
1051
+ this.debounceTimers.clear();
1052
+ this.pendingCallbacks.clear();
1053
+ this.seqIdCounter.clear();
1054
+ this.registeredFonts.clear();
1055
+ _optionalChain([this, 'access', _6 => _6.worker, 'optionalAccess', _7 => _7.terminate, 'call', _8 => _8()]);
1056
+ this.worker = null;
1057
+ if (_LayoutWorkerManager.instance === this) _LayoutWorkerManager.instance = void 0;
1058
+ }
1059
+ static getInstance() {
1060
+ if (!_LayoutWorkerManager.instance) {
1061
+ _LayoutWorkerManager.instance = new _LayoutWorkerManager();
1062
+ }
1063
+ return _LayoutWorkerManager.instance;
1064
+ }
1065
+ queueLayout(entityId, text, options) {
1066
+ const existingTimer = this.debounceTimers.get(entityId);
1067
+ if (existingTimer) {
1068
+ clearTimeout(existingTimer);
1069
+ }
1070
+ const runLayout = () => {
1071
+ this.debounceTimers.delete(entityId);
1072
+ const nextSeqId = (_nullishCoalesce(this.seqIdCounter.get(entityId), () => ( 0))) + 1;
1073
+ this.seqIdCounter.set(entityId, nextSeqId);
1074
+ const request = {
1075
+ id: entityId,
1076
+ seqId: nextSeqId,
1077
+ text,
1078
+ fontId: options.fontId,
1079
+ maxWidth: options.maxWidth,
1080
+ maxHeight: options.maxHeight,
1081
+ fontSize: options.fontSize,
1082
+ lineHeight: options.lineHeight,
1083
+ letterSpacing: options.letterSpacing
1084
+ };
1085
+ if (!this.registeredFonts.has(options.fontId) && options.fontData) {
1086
+ request.fontData = options.fontData;
1087
+ this.registeredFonts.add(options.fontId);
1088
+ }
1089
+ this.pendingCallbacks.set(`${entityId}-${nextSeqId}`, options.callback);
1090
+ try {
1091
+ this.ensureWorker().postMessage(request);
1092
+ } catch (e2) {
1093
+ const worker = this.worker;
1094
+ if (worker) this.handleWorkerFailure(worker);
1095
+ }
1096
+ };
1097
+ if (!this.seqIdCounter.has(entityId)) {
1098
+ runLayout();
1099
+ } else {
1100
+ const timer = setTimeout(runLayout, 50);
1101
+ this.debounceTimers.set(entityId, timer);
1102
+ }
1103
+ }
1104
+ cancelLayout(entityId) {
1105
+ const existingTimer = this.debounceTimers.get(entityId);
1106
+ if (existingTimer) {
1107
+ clearTimeout(existingTimer);
1108
+ this.debounceTimers.delete(entityId);
1109
+ }
1110
+ for (const key of this.pendingCallbacks.keys()) {
1111
+ if (key.startsWith(`${entityId}-`)) this.pendingCallbacks.delete(key);
1112
+ }
1113
+ this.seqIdCounter.delete(entityId);
1114
+ }
1115
+ }, _class2);
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+ exports.ArabicShaper = ArabicShaper; exports.BidiResolver = BidiResolver; exports.LayoutWorkerManager = LayoutWorkerManager;