@vectojs/core 1.7.0 → 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.
- package/README.md +14 -1
- package/THIRD_PARTY_NOTICES.md +24 -0
- package/dist/chunk-4AR425AR.js +1121 -0
- package/dist/{chunk-ZBKKRYDH.js → chunk-BA5HUUDF.js} +8 -8
- package/dist/{chunk-DFNK6OV6.js → chunk-FIQAIF55.js} +206 -4
- package/dist/chunk-IESDTEJ4.mjs +1121 -0
- package/dist/{chunk-3CODWSF3.mjs → chunk-RQ2ETTBN.mjs} +204 -2
- package/dist/{chunk-V7GUWG5C.mjs → chunk-X7I465AQ.mjs} +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +829 -130
- package/dist/index.mjs +706 -7
- package/dist/layout.js +3 -3
- package/dist/layout.mjs +2 -2
- package/dist/text/BidiResolver.d.ts +0 -1
- package/dist/text/PreparedContentGrid.d.ts +60 -0
- package/dist/text/index.d.ts +1 -0
- package/dist/text.js +5 -3
- package/dist/text.mjs +6 -4
- package/dist/tree/Entity.d.ts +21 -0
- package/dist/tree/Scene.d.ts +29 -0
- package/package.json +5 -2
- package/dist/chunk-CTZQOM5Z.js +0 -418
- package/dist/chunk-STWPTWO4.mjs +0 -418
package/dist/chunk-CTZQOM5Z.js
DELETED
|
@@ -1,418 +0,0 @@
|
|
|
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
|
-
shapedChars.push(String.fromCharCode(ligature));
|
|
114
|
-
sourceIndices.push(i);
|
|
115
|
-
i += 2;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (_ArabicShaper.isHarakat(code)) {
|
|
120
|
-
shapedChars.push(text[i]);
|
|
121
|
-
sourceIndices.push(i);
|
|
122
|
-
i++;
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
const forms = _ArabicShaper.MAPPINGS[code];
|
|
126
|
-
if (!forms) {
|
|
127
|
-
shapedChars.push(text[i]);
|
|
128
|
-
sourceIndices.push(i);
|
|
129
|
-
i++;
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
let prevCode = 0;
|
|
133
|
-
let j = i - 1;
|
|
134
|
-
while (j >= 0) {
|
|
135
|
-
const c = text.charCodeAt(j);
|
|
136
|
-
if (!_ArabicShaper.isHarakat(c)) {
|
|
137
|
-
prevCode = c;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
j--;
|
|
141
|
-
}
|
|
142
|
-
let nextCode = 0;
|
|
143
|
-
let k = i + 1;
|
|
144
|
-
while (k < len) {
|
|
145
|
-
const c = text.charCodeAt(k);
|
|
146
|
-
if (!_ArabicShaper.isHarakat(c)) {
|
|
147
|
-
nextCode = c;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
k++;
|
|
151
|
-
}
|
|
152
|
-
const connectPrev = prevCode !== 0 && _ArabicShaper.getJoiningType(prevCode) === "D" && (forms.joining === "D" || forms.joining === "R");
|
|
153
|
-
const connectNext = nextCode !== 0 && forms.joining === "D" && (_ArabicShaper.getJoiningType(nextCode) === "D" || _ArabicShaper.getJoiningType(nextCode) === "R");
|
|
154
|
-
let glyph = forms.isolated;
|
|
155
|
-
if (connectPrev && connectNext) glyph = forms.medial;
|
|
156
|
-
else if (connectPrev) glyph = forms.final;
|
|
157
|
-
else if (connectNext) glyph = forms.initial;
|
|
158
|
-
shapedChars.push(String.fromCharCode(glyph));
|
|
159
|
-
sourceIndices.push(i);
|
|
160
|
-
i++;
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
shapedText: shapedChars.join(""),
|
|
164
|
-
indexMap: new Int32Array(sourceIndices)
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}, _class.__initStatic(), _class);
|
|
168
|
-
|
|
169
|
-
// src/text/BidiResolver.ts
|
|
170
|
-
var BidiResolver = class _BidiResolver {
|
|
171
|
-
static getDirectionClass(code) {
|
|
172
|
-
if (code >= 1424 && code <= 1535 || code >= 64285 && code <= 64335) return "R";
|
|
173
|
-
if (code >= 1536 && code <= 1791 || code >= 1872 && code <= 1919 || code >= 2208 && code <= 2303 || code >= 64336 && code <= 65023 || code >= 65136 && code <= 65279) {
|
|
174
|
-
if (code === 1548 || code === 1563 || code === 1567) return "ON";
|
|
175
|
-
return "AL";
|
|
176
|
-
}
|
|
177
|
-
if (code >= 48 && code <= 57) return "EN";
|
|
178
|
-
if (code >= 1632 && code <= 1641) return "AN";
|
|
179
|
-
if (code === 32 || code === 9 || code === 160) return "WS";
|
|
180
|
-
if (code >= 8192 && code <= 8303) return "ON";
|
|
181
|
-
if (code >= 33 && code <= 47 || code >= 58 && code <= 64 || code >= 91 && code <= 96 || code >= 123 && code <= 126)
|
|
182
|
-
return "ON";
|
|
183
|
-
return "L";
|
|
184
|
-
}
|
|
185
|
-
static getBaseLevel(text) {
|
|
186
|
-
const len = text.length;
|
|
187
|
-
for (let i = 0; i < len; i++) {
|
|
188
|
-
const cls = _BidiResolver.getDirectionClass(text.charCodeAt(i));
|
|
189
|
-
if (cls === "L") return 0;
|
|
190
|
-
if (cls === "R" || cls === "AL") return 1;
|
|
191
|
-
}
|
|
192
|
-
return 0;
|
|
193
|
-
}
|
|
194
|
-
static resolveLevels(text) {
|
|
195
|
-
const len = text.length;
|
|
196
|
-
const classes = [];
|
|
197
|
-
for (let i = 0; i < len; i++) {
|
|
198
|
-
classes.push(_BidiResolver.getDirectionClass(text.charCodeAt(i)));
|
|
199
|
-
}
|
|
200
|
-
let baseLevel = 0;
|
|
201
|
-
for (let i = 0; i < len; i++) {
|
|
202
|
-
const c = classes[i];
|
|
203
|
-
if (c === "L") {
|
|
204
|
-
baseLevel = 0;
|
|
205
|
-
break;
|
|
206
|
-
} else if (c === "R" || c === "AL") {
|
|
207
|
-
baseLevel = 1;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const levels = new Uint8Array(len);
|
|
212
|
-
levels.fill(baseLevel);
|
|
213
|
-
const stack = [baseLevel];
|
|
214
|
-
let overflowCounter = 0;
|
|
215
|
-
for (let i = 0; i < len; i++) {
|
|
216
|
-
const charCode = text.charCodeAt(i);
|
|
217
|
-
const isPushLRE = charCode === 8234;
|
|
218
|
-
const isPushRLE = charCode === 8235;
|
|
219
|
-
const isPopPDF = charCode === 8236;
|
|
220
|
-
if (isPushLRE || isPushRLE) {
|
|
221
|
-
const currentLevel = stack[stack.length - 1];
|
|
222
|
-
const nextLevel = Math.min(
|
|
223
|
-
125,
|
|
224
|
-
isPushRLE ? currentLevel + 1 | 1 : currentLevel + 2 & ~1
|
|
225
|
-
);
|
|
226
|
-
if (stack.length >= 125) {
|
|
227
|
-
overflowCounter++;
|
|
228
|
-
} else {
|
|
229
|
-
stack.push(nextLevel);
|
|
230
|
-
}
|
|
231
|
-
} else if (isPopPDF) {
|
|
232
|
-
if (overflowCounter > 0) {
|
|
233
|
-
overflowCounter--;
|
|
234
|
-
} else if (stack.length > 1) {
|
|
235
|
-
stack.pop();
|
|
236
|
-
}
|
|
237
|
-
} else {
|
|
238
|
-
const currentLevel = stack[stack.length - 1];
|
|
239
|
-
const cls = classes[i];
|
|
240
|
-
let val = currentLevel;
|
|
241
|
-
if (cls === "L") {
|
|
242
|
-
val = currentLevel % 2 === 1 ? currentLevel + 1 : currentLevel;
|
|
243
|
-
} else if (cls === "R" || cls === "AL") {
|
|
244
|
-
val = currentLevel % 2 === 0 ? currentLevel + 1 : currentLevel;
|
|
245
|
-
} else if (cls === "EN" || cls === "AN") {
|
|
246
|
-
val = currentLevel % 2 === 1 ? currentLevel + 1 : currentLevel;
|
|
247
|
-
}
|
|
248
|
-
levels[i] = Math.min(125, val);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return levels;
|
|
252
|
-
}
|
|
253
|
-
static reorderVisual(nodes, baseLevel) {
|
|
254
|
-
const len = nodes.length;
|
|
255
|
-
if (len === 0) return;
|
|
256
|
-
let i = len - 1;
|
|
257
|
-
while (i >= 0) {
|
|
258
|
-
const node = nodes[i];
|
|
259
|
-
const code = node.char.charCodeAt(0);
|
|
260
|
-
const isWS = code === 32 || code === 9 || code === 160 || code === 8234 || code === 8235 || code === 8236;
|
|
261
|
-
if (isWS) {
|
|
262
|
-
node.level = baseLevel;
|
|
263
|
-
} else {
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
i--;
|
|
267
|
-
}
|
|
268
|
-
let maxLevel = baseLevel;
|
|
269
|
-
for (let j = 0; j < len; j++) {
|
|
270
|
-
if (nodes[j].level > maxLevel) maxLevel = nodes[j].level;
|
|
271
|
-
}
|
|
272
|
-
for (let level = maxLevel; level >= 1; level--) {
|
|
273
|
-
let start = 0;
|
|
274
|
-
while (start < len) {
|
|
275
|
-
if (nodes[start].level >= level) {
|
|
276
|
-
let end = start;
|
|
277
|
-
while (end < len && nodes[end].level >= level) {
|
|
278
|
-
end++;
|
|
279
|
-
}
|
|
280
|
-
let left = start;
|
|
281
|
-
let right = end - 1;
|
|
282
|
-
while (left < right) {
|
|
283
|
-
const temp = nodes[left];
|
|
284
|
-
nodes[left] = nodes[right];
|
|
285
|
-
nodes[right] = temp;
|
|
286
|
-
left++;
|
|
287
|
-
right--;
|
|
288
|
-
}
|
|
289
|
-
start = end;
|
|
290
|
-
} else {
|
|
291
|
-
start++;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
// src/layout/LayoutWorkerSource.ts
|
|
299
|
-
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';
|
|
300
|
-
|
|
301
|
-
// src/layout/LayoutWorkerManager.ts
|
|
302
|
-
var LayoutWorkerManager = (_class2 = class _LayoutWorkerManager {
|
|
303
|
-
|
|
304
|
-
__init() {this.worker = null}
|
|
305
|
-
__init2() {this.registeredFonts = /* @__PURE__ */ new Set()}
|
|
306
|
-
__init3() {this.pendingCallbacks = /* @__PURE__ */ new Map()}
|
|
307
|
-
__init4() {this.seqIdCounter = /* @__PURE__ */ new Map()}
|
|
308
|
-
__init5() {this.debounceTimers = /* @__PURE__ */ new Map()}
|
|
309
|
-
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);
|
|
310
|
-
this.worker = this.createWorker();
|
|
311
|
-
}
|
|
312
|
-
createWorker() {
|
|
313
|
-
const workerBlob = new Blob([WORKER_SOURCE_STRING], { type: "application/javascript" });
|
|
314
|
-
const workerURL = URL.createObjectURL(workerBlob);
|
|
315
|
-
let worker;
|
|
316
|
-
try {
|
|
317
|
-
worker = new Worker(workerURL);
|
|
318
|
-
} finally {
|
|
319
|
-
URL.revokeObjectURL(workerURL);
|
|
320
|
-
}
|
|
321
|
-
worker.onmessage = (e) => {
|
|
322
|
-
if (this.worker !== worker) return;
|
|
323
|
-
const response = e.data;
|
|
324
|
-
const key = `${response.id}-${response.seqId}`;
|
|
325
|
-
const callback = this.pendingCallbacks.get(key);
|
|
326
|
-
if (callback) {
|
|
327
|
-
this.pendingCallbacks.delete(key);
|
|
328
|
-
callback(response);
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
worker.onerror = () => this.handleWorkerFailure(worker);
|
|
332
|
-
worker.onmessageerror = () => this.handleWorkerFailure(worker);
|
|
333
|
-
return worker;
|
|
334
|
-
}
|
|
335
|
-
ensureWorker() {
|
|
336
|
-
if (!this.worker) this.worker = this.createWorker();
|
|
337
|
-
return this.worker;
|
|
338
|
-
}
|
|
339
|
-
handleWorkerFailure(worker) {
|
|
340
|
-
if (this.worker !== worker) return;
|
|
341
|
-
worker.terminate();
|
|
342
|
-
this.worker = null;
|
|
343
|
-
this.pendingCallbacks.clear();
|
|
344
|
-
this.registeredFonts.clear();
|
|
345
|
-
}
|
|
346
|
-
destroy() {
|
|
347
|
-
for (const timer of this.debounceTimers.values()) clearTimeout(timer);
|
|
348
|
-
this.debounceTimers.clear();
|
|
349
|
-
this.pendingCallbacks.clear();
|
|
350
|
-
this.seqIdCounter.clear();
|
|
351
|
-
this.registeredFonts.clear();
|
|
352
|
-
_optionalChain([this, 'access', _ => _.worker, 'optionalAccess', _2 => _2.terminate, 'call', _3 => _3()]);
|
|
353
|
-
this.worker = null;
|
|
354
|
-
if (_LayoutWorkerManager.instance === this) _LayoutWorkerManager.instance = void 0;
|
|
355
|
-
}
|
|
356
|
-
static getInstance() {
|
|
357
|
-
if (!_LayoutWorkerManager.instance) {
|
|
358
|
-
_LayoutWorkerManager.instance = new _LayoutWorkerManager();
|
|
359
|
-
}
|
|
360
|
-
return _LayoutWorkerManager.instance;
|
|
361
|
-
}
|
|
362
|
-
queueLayout(entityId, text, options) {
|
|
363
|
-
const existingTimer = this.debounceTimers.get(entityId);
|
|
364
|
-
if (existingTimer) {
|
|
365
|
-
clearTimeout(existingTimer);
|
|
366
|
-
}
|
|
367
|
-
const runLayout = () => {
|
|
368
|
-
this.debounceTimers.delete(entityId);
|
|
369
|
-
const nextSeqId = (_nullishCoalesce(this.seqIdCounter.get(entityId), () => ( 0))) + 1;
|
|
370
|
-
this.seqIdCounter.set(entityId, nextSeqId);
|
|
371
|
-
const request = {
|
|
372
|
-
id: entityId,
|
|
373
|
-
seqId: nextSeqId,
|
|
374
|
-
text,
|
|
375
|
-
fontId: options.fontId,
|
|
376
|
-
maxWidth: options.maxWidth,
|
|
377
|
-
maxHeight: options.maxHeight,
|
|
378
|
-
fontSize: options.fontSize,
|
|
379
|
-
lineHeight: options.lineHeight,
|
|
380
|
-
letterSpacing: options.letterSpacing
|
|
381
|
-
};
|
|
382
|
-
if (!this.registeredFonts.has(options.fontId) && options.fontData) {
|
|
383
|
-
request.fontData = options.fontData;
|
|
384
|
-
this.registeredFonts.add(options.fontId);
|
|
385
|
-
}
|
|
386
|
-
this.pendingCallbacks.set(`${entityId}-${nextSeqId}`, options.callback);
|
|
387
|
-
try {
|
|
388
|
-
this.ensureWorker().postMessage(request);
|
|
389
|
-
} catch (e2) {
|
|
390
|
-
const worker = this.worker;
|
|
391
|
-
if (worker) this.handleWorkerFailure(worker);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
if (!this.seqIdCounter.has(entityId)) {
|
|
395
|
-
runLayout();
|
|
396
|
-
} else {
|
|
397
|
-
const timer = setTimeout(runLayout, 50);
|
|
398
|
-
this.debounceTimers.set(entityId, timer);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
cancelLayout(entityId) {
|
|
402
|
-
const existingTimer = this.debounceTimers.get(entityId);
|
|
403
|
-
if (existingTimer) {
|
|
404
|
-
clearTimeout(existingTimer);
|
|
405
|
-
this.debounceTimers.delete(entityId);
|
|
406
|
-
}
|
|
407
|
-
for (const key of this.pendingCallbacks.keys()) {
|
|
408
|
-
if (key.startsWith(`${entityId}-`)) this.pendingCallbacks.delete(key);
|
|
409
|
-
}
|
|
410
|
-
this.seqIdCounter.delete(entityId);
|
|
411
|
-
}
|
|
412
|
-
}, _class2);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
exports.ArabicShaper = ArabicShaper; exports.BidiResolver = BidiResolver; exports.LayoutWorkerManager = LayoutWorkerManager;
|