@pre-markdown/layout 0.2.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/LICENSE +21 -0
- package/dist/index.cjs +1365 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +660 -0
- package/dist/index.d.ts +660 -0
- package/dist/index.js +1348 -0
- package/dist/index.js.map +1 -0
- package/dist/worker-script.js +1867 -0
- package/dist/worker-script.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,1867 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/@chenglou+pretext@0.0.4/node_modules/@chenglou/pretext/dist/bidi.js
|
|
2
|
+
var baseTypes = [
|
|
3
|
+
"BN",
|
|
4
|
+
"BN",
|
|
5
|
+
"BN",
|
|
6
|
+
"BN",
|
|
7
|
+
"BN",
|
|
8
|
+
"BN",
|
|
9
|
+
"BN",
|
|
10
|
+
"BN",
|
|
11
|
+
"BN",
|
|
12
|
+
"S",
|
|
13
|
+
"B",
|
|
14
|
+
"S",
|
|
15
|
+
"WS",
|
|
16
|
+
"B",
|
|
17
|
+
"BN",
|
|
18
|
+
"BN",
|
|
19
|
+
"BN",
|
|
20
|
+
"BN",
|
|
21
|
+
"BN",
|
|
22
|
+
"BN",
|
|
23
|
+
"BN",
|
|
24
|
+
"BN",
|
|
25
|
+
"BN",
|
|
26
|
+
"BN",
|
|
27
|
+
"BN",
|
|
28
|
+
"BN",
|
|
29
|
+
"BN",
|
|
30
|
+
"BN",
|
|
31
|
+
"B",
|
|
32
|
+
"B",
|
|
33
|
+
"B",
|
|
34
|
+
"S",
|
|
35
|
+
"WS",
|
|
36
|
+
"ON",
|
|
37
|
+
"ON",
|
|
38
|
+
"ET",
|
|
39
|
+
"ET",
|
|
40
|
+
"ET",
|
|
41
|
+
"ON",
|
|
42
|
+
"ON",
|
|
43
|
+
"ON",
|
|
44
|
+
"ON",
|
|
45
|
+
"ON",
|
|
46
|
+
"ON",
|
|
47
|
+
"CS",
|
|
48
|
+
"ON",
|
|
49
|
+
"CS",
|
|
50
|
+
"ON",
|
|
51
|
+
"EN",
|
|
52
|
+
"EN",
|
|
53
|
+
"EN",
|
|
54
|
+
"EN",
|
|
55
|
+
"EN",
|
|
56
|
+
"EN",
|
|
57
|
+
"EN",
|
|
58
|
+
"EN",
|
|
59
|
+
"EN",
|
|
60
|
+
"EN",
|
|
61
|
+
"ON",
|
|
62
|
+
"ON",
|
|
63
|
+
"ON",
|
|
64
|
+
"ON",
|
|
65
|
+
"ON",
|
|
66
|
+
"ON",
|
|
67
|
+
"ON",
|
|
68
|
+
"L",
|
|
69
|
+
"L",
|
|
70
|
+
"L",
|
|
71
|
+
"L",
|
|
72
|
+
"L",
|
|
73
|
+
"L",
|
|
74
|
+
"L",
|
|
75
|
+
"L",
|
|
76
|
+
"L",
|
|
77
|
+
"L",
|
|
78
|
+
"L",
|
|
79
|
+
"L",
|
|
80
|
+
"L",
|
|
81
|
+
"L",
|
|
82
|
+
"L",
|
|
83
|
+
"L",
|
|
84
|
+
"L",
|
|
85
|
+
"L",
|
|
86
|
+
"L",
|
|
87
|
+
"L",
|
|
88
|
+
"L",
|
|
89
|
+
"L",
|
|
90
|
+
"L",
|
|
91
|
+
"L",
|
|
92
|
+
"L",
|
|
93
|
+
"L",
|
|
94
|
+
"ON",
|
|
95
|
+
"ON",
|
|
96
|
+
"ON",
|
|
97
|
+
"ON",
|
|
98
|
+
"ON",
|
|
99
|
+
"ON",
|
|
100
|
+
"L",
|
|
101
|
+
"L",
|
|
102
|
+
"L",
|
|
103
|
+
"L",
|
|
104
|
+
"L",
|
|
105
|
+
"L",
|
|
106
|
+
"L",
|
|
107
|
+
"L",
|
|
108
|
+
"L",
|
|
109
|
+
"L",
|
|
110
|
+
"L",
|
|
111
|
+
"L",
|
|
112
|
+
"L",
|
|
113
|
+
"L",
|
|
114
|
+
"L",
|
|
115
|
+
"L",
|
|
116
|
+
"L",
|
|
117
|
+
"L",
|
|
118
|
+
"L",
|
|
119
|
+
"L",
|
|
120
|
+
"L",
|
|
121
|
+
"L",
|
|
122
|
+
"L",
|
|
123
|
+
"L",
|
|
124
|
+
"L",
|
|
125
|
+
"L",
|
|
126
|
+
"ON",
|
|
127
|
+
"ON",
|
|
128
|
+
"ON",
|
|
129
|
+
"ON",
|
|
130
|
+
"BN",
|
|
131
|
+
"BN",
|
|
132
|
+
"BN",
|
|
133
|
+
"BN",
|
|
134
|
+
"BN",
|
|
135
|
+
"BN",
|
|
136
|
+
"B",
|
|
137
|
+
"BN",
|
|
138
|
+
"BN",
|
|
139
|
+
"BN",
|
|
140
|
+
"BN",
|
|
141
|
+
"BN",
|
|
142
|
+
"BN",
|
|
143
|
+
"BN",
|
|
144
|
+
"BN",
|
|
145
|
+
"BN",
|
|
146
|
+
"BN",
|
|
147
|
+
"BN",
|
|
148
|
+
"BN",
|
|
149
|
+
"BN",
|
|
150
|
+
"BN",
|
|
151
|
+
"BN",
|
|
152
|
+
"BN",
|
|
153
|
+
"BN",
|
|
154
|
+
"BN",
|
|
155
|
+
"BN",
|
|
156
|
+
"BN",
|
|
157
|
+
"BN",
|
|
158
|
+
"BN",
|
|
159
|
+
"BN",
|
|
160
|
+
"BN",
|
|
161
|
+
"BN",
|
|
162
|
+
"BN",
|
|
163
|
+
"CS",
|
|
164
|
+
"ON",
|
|
165
|
+
"ET",
|
|
166
|
+
"ET",
|
|
167
|
+
"ET",
|
|
168
|
+
"ET",
|
|
169
|
+
"ON",
|
|
170
|
+
"ON",
|
|
171
|
+
"ON",
|
|
172
|
+
"ON",
|
|
173
|
+
"L",
|
|
174
|
+
"ON",
|
|
175
|
+
"ON",
|
|
176
|
+
"ON",
|
|
177
|
+
"ON",
|
|
178
|
+
"ON",
|
|
179
|
+
"ET",
|
|
180
|
+
"ET",
|
|
181
|
+
"EN",
|
|
182
|
+
"EN",
|
|
183
|
+
"ON",
|
|
184
|
+
"L",
|
|
185
|
+
"ON",
|
|
186
|
+
"ON",
|
|
187
|
+
"ON",
|
|
188
|
+
"EN",
|
|
189
|
+
"L",
|
|
190
|
+
"ON",
|
|
191
|
+
"ON",
|
|
192
|
+
"ON",
|
|
193
|
+
"ON",
|
|
194
|
+
"ON",
|
|
195
|
+
"L",
|
|
196
|
+
"L",
|
|
197
|
+
"L",
|
|
198
|
+
"L",
|
|
199
|
+
"L",
|
|
200
|
+
"L",
|
|
201
|
+
"L",
|
|
202
|
+
"L",
|
|
203
|
+
"L",
|
|
204
|
+
"L",
|
|
205
|
+
"L",
|
|
206
|
+
"L",
|
|
207
|
+
"L",
|
|
208
|
+
"L",
|
|
209
|
+
"L",
|
|
210
|
+
"L",
|
|
211
|
+
"L",
|
|
212
|
+
"L",
|
|
213
|
+
"L",
|
|
214
|
+
"L",
|
|
215
|
+
"L",
|
|
216
|
+
"L",
|
|
217
|
+
"L",
|
|
218
|
+
"ON",
|
|
219
|
+
"L",
|
|
220
|
+
"L",
|
|
221
|
+
"L",
|
|
222
|
+
"L",
|
|
223
|
+
"L",
|
|
224
|
+
"L",
|
|
225
|
+
"L",
|
|
226
|
+
"L",
|
|
227
|
+
"L",
|
|
228
|
+
"L",
|
|
229
|
+
"L",
|
|
230
|
+
"L",
|
|
231
|
+
"L",
|
|
232
|
+
"L",
|
|
233
|
+
"L",
|
|
234
|
+
"L",
|
|
235
|
+
"L",
|
|
236
|
+
"L",
|
|
237
|
+
"L",
|
|
238
|
+
"L",
|
|
239
|
+
"L",
|
|
240
|
+
"L",
|
|
241
|
+
"L",
|
|
242
|
+
"L",
|
|
243
|
+
"L",
|
|
244
|
+
"L",
|
|
245
|
+
"L",
|
|
246
|
+
"L",
|
|
247
|
+
"L",
|
|
248
|
+
"L",
|
|
249
|
+
"L",
|
|
250
|
+
"ON",
|
|
251
|
+
"L",
|
|
252
|
+
"L",
|
|
253
|
+
"L",
|
|
254
|
+
"L",
|
|
255
|
+
"L",
|
|
256
|
+
"L",
|
|
257
|
+
"L",
|
|
258
|
+
"L"
|
|
259
|
+
];
|
|
260
|
+
var arabicTypes = [
|
|
261
|
+
"AL",
|
|
262
|
+
"AL",
|
|
263
|
+
"AL",
|
|
264
|
+
"AL",
|
|
265
|
+
"AL",
|
|
266
|
+
"AL",
|
|
267
|
+
"AL",
|
|
268
|
+
"AL",
|
|
269
|
+
"AL",
|
|
270
|
+
"AL",
|
|
271
|
+
"AL",
|
|
272
|
+
"AL",
|
|
273
|
+
"CS",
|
|
274
|
+
"AL",
|
|
275
|
+
"ON",
|
|
276
|
+
"ON",
|
|
277
|
+
"NSM",
|
|
278
|
+
"NSM",
|
|
279
|
+
"NSM",
|
|
280
|
+
"NSM",
|
|
281
|
+
"NSM",
|
|
282
|
+
"NSM",
|
|
283
|
+
"AL",
|
|
284
|
+
"AL",
|
|
285
|
+
"AL",
|
|
286
|
+
"AL",
|
|
287
|
+
"AL",
|
|
288
|
+
"AL",
|
|
289
|
+
"AL",
|
|
290
|
+
"AL",
|
|
291
|
+
"AL",
|
|
292
|
+
"AL",
|
|
293
|
+
"AL",
|
|
294
|
+
"AL",
|
|
295
|
+
"AL",
|
|
296
|
+
"AL",
|
|
297
|
+
"AL",
|
|
298
|
+
"AL",
|
|
299
|
+
"AL",
|
|
300
|
+
"AL",
|
|
301
|
+
"AL",
|
|
302
|
+
"AL",
|
|
303
|
+
"AL",
|
|
304
|
+
"AL",
|
|
305
|
+
"AL",
|
|
306
|
+
"AL",
|
|
307
|
+
"AL",
|
|
308
|
+
"AL",
|
|
309
|
+
"AL",
|
|
310
|
+
"AL",
|
|
311
|
+
"AL",
|
|
312
|
+
"AL",
|
|
313
|
+
"AL",
|
|
314
|
+
"AL",
|
|
315
|
+
"AL",
|
|
316
|
+
"AL",
|
|
317
|
+
"AL",
|
|
318
|
+
"AL",
|
|
319
|
+
"AL",
|
|
320
|
+
"AL",
|
|
321
|
+
"AL",
|
|
322
|
+
"AL",
|
|
323
|
+
"AL",
|
|
324
|
+
"AL",
|
|
325
|
+
"AL",
|
|
326
|
+
"AL",
|
|
327
|
+
"AL",
|
|
328
|
+
"AL",
|
|
329
|
+
"AL",
|
|
330
|
+
"AL",
|
|
331
|
+
"AL",
|
|
332
|
+
"AL",
|
|
333
|
+
"AL",
|
|
334
|
+
"AL",
|
|
335
|
+
"AL",
|
|
336
|
+
"NSM",
|
|
337
|
+
"NSM",
|
|
338
|
+
"NSM",
|
|
339
|
+
"NSM",
|
|
340
|
+
"NSM",
|
|
341
|
+
"NSM",
|
|
342
|
+
"NSM",
|
|
343
|
+
"NSM",
|
|
344
|
+
"NSM",
|
|
345
|
+
"NSM",
|
|
346
|
+
"NSM",
|
|
347
|
+
"NSM",
|
|
348
|
+
"NSM",
|
|
349
|
+
"NSM",
|
|
350
|
+
"AL",
|
|
351
|
+
"AL",
|
|
352
|
+
"AL",
|
|
353
|
+
"AL",
|
|
354
|
+
"AL",
|
|
355
|
+
"AL",
|
|
356
|
+
"AL",
|
|
357
|
+
"AN",
|
|
358
|
+
"AN",
|
|
359
|
+
"AN",
|
|
360
|
+
"AN",
|
|
361
|
+
"AN",
|
|
362
|
+
"AN",
|
|
363
|
+
"AN",
|
|
364
|
+
"AN",
|
|
365
|
+
"AN",
|
|
366
|
+
"AN",
|
|
367
|
+
"ET",
|
|
368
|
+
"AN",
|
|
369
|
+
"AN",
|
|
370
|
+
"AL",
|
|
371
|
+
"AL",
|
|
372
|
+
"AL",
|
|
373
|
+
"NSM",
|
|
374
|
+
"AL",
|
|
375
|
+
"AL",
|
|
376
|
+
"AL",
|
|
377
|
+
"AL",
|
|
378
|
+
"AL",
|
|
379
|
+
"AL",
|
|
380
|
+
"AL",
|
|
381
|
+
"AL",
|
|
382
|
+
"AL",
|
|
383
|
+
"AL",
|
|
384
|
+
"AL",
|
|
385
|
+
"AL",
|
|
386
|
+
"AL",
|
|
387
|
+
"AL",
|
|
388
|
+
"AL",
|
|
389
|
+
"AL",
|
|
390
|
+
"AL",
|
|
391
|
+
"AL",
|
|
392
|
+
"AL",
|
|
393
|
+
"AL",
|
|
394
|
+
"AL",
|
|
395
|
+
"AL",
|
|
396
|
+
"AL",
|
|
397
|
+
"AL",
|
|
398
|
+
"AL",
|
|
399
|
+
"AL",
|
|
400
|
+
"AL",
|
|
401
|
+
"AL",
|
|
402
|
+
"AL",
|
|
403
|
+
"AL",
|
|
404
|
+
"AL",
|
|
405
|
+
"AL",
|
|
406
|
+
"AL",
|
|
407
|
+
"AL",
|
|
408
|
+
"AL",
|
|
409
|
+
"AL",
|
|
410
|
+
"AL",
|
|
411
|
+
"AL",
|
|
412
|
+
"AL",
|
|
413
|
+
"AL",
|
|
414
|
+
"AL",
|
|
415
|
+
"AL",
|
|
416
|
+
"AL",
|
|
417
|
+
"AL",
|
|
418
|
+
"AL",
|
|
419
|
+
"AL",
|
|
420
|
+
"AL",
|
|
421
|
+
"AL",
|
|
422
|
+
"AL",
|
|
423
|
+
"AL",
|
|
424
|
+
"AL",
|
|
425
|
+
"AL",
|
|
426
|
+
"AL",
|
|
427
|
+
"AL",
|
|
428
|
+
"AL",
|
|
429
|
+
"AL",
|
|
430
|
+
"AL",
|
|
431
|
+
"AL",
|
|
432
|
+
"AL",
|
|
433
|
+
"AL",
|
|
434
|
+
"AL",
|
|
435
|
+
"AL",
|
|
436
|
+
"AL",
|
|
437
|
+
"AL",
|
|
438
|
+
"AL",
|
|
439
|
+
"AL",
|
|
440
|
+
"AL",
|
|
441
|
+
"AL",
|
|
442
|
+
"AL",
|
|
443
|
+
"AL",
|
|
444
|
+
"AL",
|
|
445
|
+
"AL",
|
|
446
|
+
"AL",
|
|
447
|
+
"AL",
|
|
448
|
+
"AL",
|
|
449
|
+
"AL",
|
|
450
|
+
"AL",
|
|
451
|
+
"AL",
|
|
452
|
+
"AL",
|
|
453
|
+
"AL",
|
|
454
|
+
"AL",
|
|
455
|
+
"AL",
|
|
456
|
+
"AL",
|
|
457
|
+
"AL",
|
|
458
|
+
"AL",
|
|
459
|
+
"AL",
|
|
460
|
+
"AL",
|
|
461
|
+
"AL",
|
|
462
|
+
"AL",
|
|
463
|
+
"AL",
|
|
464
|
+
"AL",
|
|
465
|
+
"AL",
|
|
466
|
+
"AL",
|
|
467
|
+
"AL",
|
|
468
|
+
"AL",
|
|
469
|
+
"AL",
|
|
470
|
+
"AL",
|
|
471
|
+
"AL",
|
|
472
|
+
"AL",
|
|
473
|
+
"AL",
|
|
474
|
+
"AL",
|
|
475
|
+
"NSM",
|
|
476
|
+
"NSM",
|
|
477
|
+
"NSM",
|
|
478
|
+
"NSM",
|
|
479
|
+
"NSM",
|
|
480
|
+
"NSM",
|
|
481
|
+
"NSM",
|
|
482
|
+
"NSM",
|
|
483
|
+
"NSM",
|
|
484
|
+
"NSM",
|
|
485
|
+
"NSM",
|
|
486
|
+
"NSM",
|
|
487
|
+
"NSM",
|
|
488
|
+
"NSM",
|
|
489
|
+
"NSM",
|
|
490
|
+
"NSM",
|
|
491
|
+
"NSM",
|
|
492
|
+
"NSM",
|
|
493
|
+
"NSM",
|
|
494
|
+
"ON",
|
|
495
|
+
"NSM",
|
|
496
|
+
"NSM",
|
|
497
|
+
"NSM",
|
|
498
|
+
"NSM",
|
|
499
|
+
"AL",
|
|
500
|
+
"AL",
|
|
501
|
+
"AL",
|
|
502
|
+
"AL",
|
|
503
|
+
"AL",
|
|
504
|
+
"AL",
|
|
505
|
+
"AL",
|
|
506
|
+
"AL",
|
|
507
|
+
"AL",
|
|
508
|
+
"AL",
|
|
509
|
+
"AL",
|
|
510
|
+
"AL",
|
|
511
|
+
"AL",
|
|
512
|
+
"AL",
|
|
513
|
+
"AL",
|
|
514
|
+
"AL",
|
|
515
|
+
"AL",
|
|
516
|
+
"AL"
|
|
517
|
+
];
|
|
518
|
+
function classifyChar(charCode) {
|
|
519
|
+
if (charCode <= 255)
|
|
520
|
+
return baseTypes[charCode];
|
|
521
|
+
if (1424 <= charCode && charCode <= 1524)
|
|
522
|
+
return "R";
|
|
523
|
+
if (1536 <= charCode && charCode <= 1791)
|
|
524
|
+
return arabicTypes[charCode & 255];
|
|
525
|
+
if (1792 <= charCode && charCode <= 2220)
|
|
526
|
+
return "AL";
|
|
527
|
+
return "L";
|
|
528
|
+
}
|
|
529
|
+
function computeBidiLevels(str) {
|
|
530
|
+
const len = str.length;
|
|
531
|
+
if (len === 0)
|
|
532
|
+
return null;
|
|
533
|
+
const types = new Array(len);
|
|
534
|
+
let numBidi = 0;
|
|
535
|
+
for (let i = 0; i < len; i++) {
|
|
536
|
+
const t = classifyChar(str.charCodeAt(i));
|
|
537
|
+
if (t === "R" || t === "AL" || t === "AN")
|
|
538
|
+
numBidi++;
|
|
539
|
+
types[i] = t;
|
|
540
|
+
}
|
|
541
|
+
if (numBidi === 0)
|
|
542
|
+
return null;
|
|
543
|
+
const startLevel = len / numBidi < 0.3 ? 0 : 1;
|
|
544
|
+
const levels = new Int8Array(len);
|
|
545
|
+
for (let i = 0; i < len; i++)
|
|
546
|
+
levels[i] = startLevel;
|
|
547
|
+
const e = startLevel & 1 ? "R" : "L";
|
|
548
|
+
const sor = e;
|
|
549
|
+
let lastType = sor;
|
|
550
|
+
for (let i = 0; i < len; i++) {
|
|
551
|
+
if (types[i] === "NSM")
|
|
552
|
+
types[i] = lastType;
|
|
553
|
+
else
|
|
554
|
+
lastType = types[i];
|
|
555
|
+
}
|
|
556
|
+
lastType = sor;
|
|
557
|
+
for (let i = 0; i < len; i++) {
|
|
558
|
+
const t = types[i];
|
|
559
|
+
if (t === "EN")
|
|
560
|
+
types[i] = lastType === "AL" ? "AN" : "EN";
|
|
561
|
+
else if (t === "R" || t === "L" || t === "AL")
|
|
562
|
+
lastType = t;
|
|
563
|
+
}
|
|
564
|
+
for (let i = 0; i < len; i++) {
|
|
565
|
+
if (types[i] === "AL")
|
|
566
|
+
types[i] = "R";
|
|
567
|
+
}
|
|
568
|
+
for (let i = 1; i < len - 1; i++) {
|
|
569
|
+
if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
|
|
570
|
+
types[i] = "EN";
|
|
571
|
+
}
|
|
572
|
+
if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
|
|
573
|
+
types[i] = types[i - 1];
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
for (let i = 0; i < len; i++) {
|
|
577
|
+
if (types[i] !== "EN")
|
|
578
|
+
continue;
|
|
579
|
+
let j;
|
|
580
|
+
for (j = i - 1; j >= 0 && types[j] === "ET"; j--)
|
|
581
|
+
types[j] = "EN";
|
|
582
|
+
for (j = i + 1; j < len && types[j] === "ET"; j++)
|
|
583
|
+
types[j] = "EN";
|
|
584
|
+
}
|
|
585
|
+
for (let i = 0; i < len; i++) {
|
|
586
|
+
const t = types[i];
|
|
587
|
+
if (t === "WS" || t === "ES" || t === "ET" || t === "CS")
|
|
588
|
+
types[i] = "ON";
|
|
589
|
+
}
|
|
590
|
+
lastType = sor;
|
|
591
|
+
for (let i = 0; i < len; i++) {
|
|
592
|
+
const t = types[i];
|
|
593
|
+
if (t === "EN")
|
|
594
|
+
types[i] = lastType === "L" ? "L" : "EN";
|
|
595
|
+
else if (t === "R" || t === "L")
|
|
596
|
+
lastType = t;
|
|
597
|
+
}
|
|
598
|
+
for (let i = 0; i < len; i++) {
|
|
599
|
+
if (types[i] !== "ON")
|
|
600
|
+
continue;
|
|
601
|
+
let end = i + 1;
|
|
602
|
+
while (end < len && types[end] === "ON")
|
|
603
|
+
end++;
|
|
604
|
+
const before = i > 0 ? types[i - 1] : sor;
|
|
605
|
+
const after = end < len ? types[end] : sor;
|
|
606
|
+
const bDir = before !== "L" ? "R" : "L";
|
|
607
|
+
const aDir = after !== "L" ? "R" : "L";
|
|
608
|
+
if (bDir === aDir) {
|
|
609
|
+
for (let j = i; j < end; j++)
|
|
610
|
+
types[j] = bDir;
|
|
611
|
+
}
|
|
612
|
+
i = end - 1;
|
|
613
|
+
}
|
|
614
|
+
for (let i = 0; i < len; i++) {
|
|
615
|
+
if (types[i] === "ON")
|
|
616
|
+
types[i] = e;
|
|
617
|
+
}
|
|
618
|
+
for (let i = 0; i < len; i++) {
|
|
619
|
+
const t = types[i];
|
|
620
|
+
if ((levels[i] & 1) === 0) {
|
|
621
|
+
if (t === "R")
|
|
622
|
+
levels[i]++;
|
|
623
|
+
else if (t === "AN" || t === "EN")
|
|
624
|
+
levels[i] += 2;
|
|
625
|
+
} else if (t === "L" || t === "AN" || t === "EN") {
|
|
626
|
+
levels[i]++;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return levels;
|
|
630
|
+
}
|
|
631
|
+
function computeSegmentLevels(normalized, segStarts) {
|
|
632
|
+
const bidiLevels = computeBidiLevels(normalized);
|
|
633
|
+
if (bidiLevels === null)
|
|
634
|
+
return null;
|
|
635
|
+
const segLevels = new Int8Array(segStarts.length);
|
|
636
|
+
for (let i = 0; i < segStarts.length; i++) {
|
|
637
|
+
segLevels[i] = bidiLevels[segStarts[i]];
|
|
638
|
+
}
|
|
639
|
+
return segLevels;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// ../../node_modules/.pnpm/@chenglou+pretext@0.0.4/node_modules/@chenglou/pretext/dist/analysis.js
|
|
643
|
+
var collapsibleWhitespaceRunRe = /[ \t\n\r\f]+/g;
|
|
644
|
+
var needsWhitespaceNormalizationRe = /[\t\n\r\f]| {2,}|^ | $/;
|
|
645
|
+
function getWhiteSpaceProfile(whiteSpace) {
|
|
646
|
+
const mode = whiteSpace ?? "normal";
|
|
647
|
+
return mode === "pre-wrap" ? { mode, preserveOrdinarySpaces: true, preserveHardBreaks: true } : { mode, preserveOrdinarySpaces: false, preserveHardBreaks: false };
|
|
648
|
+
}
|
|
649
|
+
function normalizeWhitespaceNormal(text) {
|
|
650
|
+
if (!needsWhitespaceNormalizationRe.test(text))
|
|
651
|
+
return text;
|
|
652
|
+
let normalized = text.replace(collapsibleWhitespaceRunRe, " ");
|
|
653
|
+
if (normalized.charCodeAt(0) === 32) {
|
|
654
|
+
normalized = normalized.slice(1);
|
|
655
|
+
}
|
|
656
|
+
if (normalized.length > 0 && normalized.charCodeAt(normalized.length - 1) === 32) {
|
|
657
|
+
normalized = normalized.slice(0, -1);
|
|
658
|
+
}
|
|
659
|
+
return normalized;
|
|
660
|
+
}
|
|
661
|
+
function normalizeWhitespacePreWrap(text) {
|
|
662
|
+
if (!/[\r\f]/.test(text))
|
|
663
|
+
return text.replace(/\r\n/g, "\n");
|
|
664
|
+
return text.replace(/\r\n/g, "\n").replace(/[\r\f]/g, "\n");
|
|
665
|
+
}
|
|
666
|
+
var sharedWordSegmenter = null;
|
|
667
|
+
var segmenterLocale;
|
|
668
|
+
function getSharedWordSegmenter() {
|
|
669
|
+
if (sharedWordSegmenter === null) {
|
|
670
|
+
sharedWordSegmenter = new Intl.Segmenter(segmenterLocale, { granularity: "word" });
|
|
671
|
+
}
|
|
672
|
+
return sharedWordSegmenter;
|
|
673
|
+
}
|
|
674
|
+
function clearAnalysisCaches() {
|
|
675
|
+
sharedWordSegmenter = null;
|
|
676
|
+
}
|
|
677
|
+
function setAnalysisLocale(locale) {
|
|
678
|
+
const nextLocale = locale && locale.length > 0 ? locale : void 0;
|
|
679
|
+
if (segmenterLocale === nextLocale)
|
|
680
|
+
return;
|
|
681
|
+
segmenterLocale = nextLocale;
|
|
682
|
+
sharedWordSegmenter = null;
|
|
683
|
+
}
|
|
684
|
+
var arabicScriptRe = /\p{Script=Arabic}/u;
|
|
685
|
+
var combiningMarkRe = /\p{M}/u;
|
|
686
|
+
var decimalDigitRe = /\p{Nd}/u;
|
|
687
|
+
function containsArabicScript(text) {
|
|
688
|
+
return arabicScriptRe.test(text);
|
|
689
|
+
}
|
|
690
|
+
function isCJK(s) {
|
|
691
|
+
for (const ch of s) {
|
|
692
|
+
const c = ch.codePointAt(0);
|
|
693
|
+
if (c >= 19968 && c <= 40959 || c >= 13312 && c <= 19903 || c >= 131072 && c <= 173791 || c >= 173824 && c <= 177983 || c >= 177984 && c <= 178207 || c >= 178208 && c <= 183983 || c >= 183984 && c <= 191471 || c >= 196608 && c <= 201551 || c >= 63744 && c <= 64255 || c >= 194560 && c <= 195103 || c >= 12288 && c <= 12351 || c >= 12352 && c <= 12447 || c >= 12448 && c <= 12543 || c >= 44032 && c <= 55215 || c >= 65280 && c <= 65519) {
|
|
694
|
+
return true;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
var kinsokuStart = /* @__PURE__ */ new Set([
|
|
700
|
+
"\uFF0C",
|
|
701
|
+
"\uFF0E",
|
|
702
|
+
"\uFF01",
|
|
703
|
+
"\uFF1A",
|
|
704
|
+
"\uFF1B",
|
|
705
|
+
"\uFF1F",
|
|
706
|
+
"\u3001",
|
|
707
|
+
"\u3002",
|
|
708
|
+
"\u30FB",
|
|
709
|
+
"\uFF09",
|
|
710
|
+
"\u3015",
|
|
711
|
+
"\u3009",
|
|
712
|
+
"\u300B",
|
|
713
|
+
"\u300D",
|
|
714
|
+
"\u300F",
|
|
715
|
+
"\u3011",
|
|
716
|
+
"\u3017",
|
|
717
|
+
"\u3019",
|
|
718
|
+
"\u301B",
|
|
719
|
+
"\u30FC",
|
|
720
|
+
"\u3005",
|
|
721
|
+
"\u303B",
|
|
722
|
+
"\u309D",
|
|
723
|
+
"\u309E",
|
|
724
|
+
"\u30FD",
|
|
725
|
+
"\u30FE"
|
|
726
|
+
]);
|
|
727
|
+
var kinsokuEnd = /* @__PURE__ */ new Set([
|
|
728
|
+
'"',
|
|
729
|
+
"(",
|
|
730
|
+
"[",
|
|
731
|
+
"{",
|
|
732
|
+
"\u201C",
|
|
733
|
+
"\u2018",
|
|
734
|
+
"\xAB",
|
|
735
|
+
"\u2039",
|
|
736
|
+
"\uFF08",
|
|
737
|
+
"\u3014",
|
|
738
|
+
"\u3008",
|
|
739
|
+
"\u300A",
|
|
740
|
+
"\u300C",
|
|
741
|
+
"\u300E",
|
|
742
|
+
"\u3010",
|
|
743
|
+
"\u3016",
|
|
744
|
+
"\u3018",
|
|
745
|
+
"\u301A"
|
|
746
|
+
]);
|
|
747
|
+
var forwardStickyGlue = /* @__PURE__ */ new Set([
|
|
748
|
+
"'",
|
|
749
|
+
"\u2019"
|
|
750
|
+
]);
|
|
751
|
+
var leftStickyPunctuation = /* @__PURE__ */ new Set([
|
|
752
|
+
".",
|
|
753
|
+
",",
|
|
754
|
+
"!",
|
|
755
|
+
"?",
|
|
756
|
+
":",
|
|
757
|
+
";",
|
|
758
|
+
"\u060C",
|
|
759
|
+
"\u061B",
|
|
760
|
+
"\u061F",
|
|
761
|
+
"\u0964",
|
|
762
|
+
"\u0965",
|
|
763
|
+
"\u104A",
|
|
764
|
+
"\u104B",
|
|
765
|
+
"\u104C",
|
|
766
|
+
"\u104D",
|
|
767
|
+
"\u104F",
|
|
768
|
+
")",
|
|
769
|
+
"]",
|
|
770
|
+
"}",
|
|
771
|
+
"%",
|
|
772
|
+
'"',
|
|
773
|
+
"\u201D",
|
|
774
|
+
"\u2019",
|
|
775
|
+
"\xBB",
|
|
776
|
+
"\u203A",
|
|
777
|
+
"\u2026"
|
|
778
|
+
]);
|
|
779
|
+
var arabicNoSpaceTrailingPunctuation = /* @__PURE__ */ new Set([
|
|
780
|
+
":",
|
|
781
|
+
".",
|
|
782
|
+
"\u060C",
|
|
783
|
+
"\u061B"
|
|
784
|
+
]);
|
|
785
|
+
var myanmarMedialGlue = /* @__PURE__ */ new Set([
|
|
786
|
+
"\u104F"
|
|
787
|
+
]);
|
|
788
|
+
var closingQuoteChars = /* @__PURE__ */ new Set([
|
|
789
|
+
"\u201D",
|
|
790
|
+
"\u2019",
|
|
791
|
+
"\xBB",
|
|
792
|
+
"\u203A",
|
|
793
|
+
"\u300D",
|
|
794
|
+
"\u300F",
|
|
795
|
+
"\u3011",
|
|
796
|
+
"\u300B",
|
|
797
|
+
"\u3009",
|
|
798
|
+
"\u3015",
|
|
799
|
+
"\uFF09"
|
|
800
|
+
]);
|
|
801
|
+
function isLeftStickyPunctuationSegment(segment) {
|
|
802
|
+
if (isEscapedQuoteClusterSegment(segment))
|
|
803
|
+
return true;
|
|
804
|
+
let sawPunctuation = false;
|
|
805
|
+
for (const ch of segment) {
|
|
806
|
+
if (leftStickyPunctuation.has(ch)) {
|
|
807
|
+
sawPunctuation = true;
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
if (sawPunctuation && combiningMarkRe.test(ch))
|
|
811
|
+
continue;
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
return sawPunctuation;
|
|
815
|
+
}
|
|
816
|
+
function isCJKLineStartProhibitedSegment(segment) {
|
|
817
|
+
for (const ch of segment) {
|
|
818
|
+
if (!kinsokuStart.has(ch) && !leftStickyPunctuation.has(ch))
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
return segment.length > 0;
|
|
822
|
+
}
|
|
823
|
+
function isForwardStickyClusterSegment(segment) {
|
|
824
|
+
if (isEscapedQuoteClusterSegment(segment))
|
|
825
|
+
return true;
|
|
826
|
+
for (const ch of segment) {
|
|
827
|
+
if (!kinsokuEnd.has(ch) && !forwardStickyGlue.has(ch) && !combiningMarkRe.test(ch))
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
return segment.length > 0;
|
|
831
|
+
}
|
|
832
|
+
function isEscapedQuoteClusterSegment(segment) {
|
|
833
|
+
let sawQuote = false;
|
|
834
|
+
for (const ch of segment) {
|
|
835
|
+
if (ch === "\\" || combiningMarkRe.test(ch))
|
|
836
|
+
continue;
|
|
837
|
+
if (kinsokuEnd.has(ch) || leftStickyPunctuation.has(ch) || forwardStickyGlue.has(ch)) {
|
|
838
|
+
sawQuote = true;
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
return sawQuote;
|
|
844
|
+
}
|
|
845
|
+
function splitTrailingForwardStickyCluster(text) {
|
|
846
|
+
const chars = Array.from(text);
|
|
847
|
+
let splitIndex = chars.length;
|
|
848
|
+
while (splitIndex > 0) {
|
|
849
|
+
const ch = chars[splitIndex - 1];
|
|
850
|
+
if (combiningMarkRe.test(ch)) {
|
|
851
|
+
splitIndex--;
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
if (kinsokuEnd.has(ch) || forwardStickyGlue.has(ch)) {
|
|
855
|
+
splitIndex--;
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
if (splitIndex <= 0 || splitIndex === chars.length)
|
|
861
|
+
return null;
|
|
862
|
+
return {
|
|
863
|
+
head: chars.slice(0, splitIndex).join(""),
|
|
864
|
+
tail: chars.slice(splitIndex).join("")
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
function isRepeatedSingleCharRun(segment, ch) {
|
|
868
|
+
if (segment.length === 0)
|
|
869
|
+
return false;
|
|
870
|
+
for (const part of segment) {
|
|
871
|
+
if (part !== ch)
|
|
872
|
+
return false;
|
|
873
|
+
}
|
|
874
|
+
return true;
|
|
875
|
+
}
|
|
876
|
+
function endsWithArabicNoSpacePunctuation(segment) {
|
|
877
|
+
if (!containsArabicScript(segment) || segment.length === 0)
|
|
878
|
+
return false;
|
|
879
|
+
return arabicNoSpaceTrailingPunctuation.has(segment[segment.length - 1]);
|
|
880
|
+
}
|
|
881
|
+
function endsWithMyanmarMedialGlue(segment) {
|
|
882
|
+
if (segment.length === 0)
|
|
883
|
+
return false;
|
|
884
|
+
return myanmarMedialGlue.has(segment[segment.length - 1]);
|
|
885
|
+
}
|
|
886
|
+
function splitLeadingSpaceAndMarks(segment) {
|
|
887
|
+
if (segment.length < 2 || segment[0] !== " ")
|
|
888
|
+
return null;
|
|
889
|
+
const marks = segment.slice(1);
|
|
890
|
+
if (/^\p{M}+$/u.test(marks)) {
|
|
891
|
+
return { space: " ", marks };
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
function endsWithClosingQuote(text) {
|
|
896
|
+
for (let i = text.length - 1; i >= 0; i--) {
|
|
897
|
+
const ch = text[i];
|
|
898
|
+
if (closingQuoteChars.has(ch))
|
|
899
|
+
return true;
|
|
900
|
+
if (!leftStickyPunctuation.has(ch))
|
|
901
|
+
return false;
|
|
902
|
+
}
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
function classifySegmentBreakChar(ch, whiteSpaceProfile) {
|
|
906
|
+
if (whiteSpaceProfile.preserveOrdinarySpaces || whiteSpaceProfile.preserveHardBreaks) {
|
|
907
|
+
if (ch === " ")
|
|
908
|
+
return "preserved-space";
|
|
909
|
+
if (ch === " ")
|
|
910
|
+
return "tab";
|
|
911
|
+
if (whiteSpaceProfile.preserveHardBreaks && ch === "\n")
|
|
912
|
+
return "hard-break";
|
|
913
|
+
}
|
|
914
|
+
if (ch === " ")
|
|
915
|
+
return "space";
|
|
916
|
+
if (ch === "\xA0" || ch === "\u202F" || ch === "\u2060" || ch === "\uFEFF") {
|
|
917
|
+
return "glue";
|
|
918
|
+
}
|
|
919
|
+
if (ch === "\u200B")
|
|
920
|
+
return "zero-width-break";
|
|
921
|
+
if (ch === "\xAD")
|
|
922
|
+
return "soft-hyphen";
|
|
923
|
+
return "text";
|
|
924
|
+
}
|
|
925
|
+
function joinTextParts(parts) {
|
|
926
|
+
return parts.length === 1 ? parts[0] : parts.join("");
|
|
927
|
+
}
|
|
928
|
+
function splitSegmentByBreakKind(segment, isWordLike, start, whiteSpaceProfile) {
|
|
929
|
+
const pieces = [];
|
|
930
|
+
let currentKind = null;
|
|
931
|
+
let currentTextParts = [];
|
|
932
|
+
let currentStart = start;
|
|
933
|
+
let currentWordLike = false;
|
|
934
|
+
let offset = 0;
|
|
935
|
+
for (const ch of segment) {
|
|
936
|
+
const kind = classifySegmentBreakChar(ch, whiteSpaceProfile);
|
|
937
|
+
const wordLike = kind === "text" && isWordLike;
|
|
938
|
+
if (currentKind !== null && kind === currentKind && wordLike === currentWordLike) {
|
|
939
|
+
currentTextParts.push(ch);
|
|
940
|
+
offset += ch.length;
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (currentKind !== null) {
|
|
944
|
+
pieces.push({
|
|
945
|
+
text: joinTextParts(currentTextParts),
|
|
946
|
+
isWordLike: currentWordLike,
|
|
947
|
+
kind: currentKind,
|
|
948
|
+
start: currentStart
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
currentKind = kind;
|
|
952
|
+
currentTextParts = [ch];
|
|
953
|
+
currentStart = start + offset;
|
|
954
|
+
currentWordLike = wordLike;
|
|
955
|
+
offset += ch.length;
|
|
956
|
+
}
|
|
957
|
+
if (currentKind !== null) {
|
|
958
|
+
pieces.push({
|
|
959
|
+
text: joinTextParts(currentTextParts),
|
|
960
|
+
isWordLike: currentWordLike,
|
|
961
|
+
kind: currentKind,
|
|
962
|
+
start: currentStart
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
return pieces;
|
|
966
|
+
}
|
|
967
|
+
function isTextRunBoundary(kind) {
|
|
968
|
+
return kind === "space" || kind === "preserved-space" || kind === "zero-width-break" || kind === "hard-break";
|
|
969
|
+
}
|
|
970
|
+
var urlSchemeSegmentRe = /^[A-Za-z][A-Za-z0-9+.-]*:$/;
|
|
971
|
+
function isUrlLikeRunStart(segmentation, index) {
|
|
972
|
+
const text = segmentation.texts[index];
|
|
973
|
+
if (text.startsWith("www."))
|
|
974
|
+
return true;
|
|
975
|
+
return urlSchemeSegmentRe.test(text) && index + 1 < segmentation.len && segmentation.kinds[index + 1] === "text" && segmentation.texts[index + 1] === "//";
|
|
976
|
+
}
|
|
977
|
+
function isUrlQueryBoundarySegment(text) {
|
|
978
|
+
return text.includes("?") && (text.includes("://") || text.startsWith("www."));
|
|
979
|
+
}
|
|
980
|
+
function mergeUrlLikeRuns(segmentation) {
|
|
981
|
+
const texts = segmentation.texts.slice();
|
|
982
|
+
const isWordLike = segmentation.isWordLike.slice();
|
|
983
|
+
const kinds = segmentation.kinds.slice();
|
|
984
|
+
const starts = segmentation.starts.slice();
|
|
985
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
986
|
+
if (kinds[i] !== "text" || !isUrlLikeRunStart(segmentation, i))
|
|
987
|
+
continue;
|
|
988
|
+
const mergedParts = [texts[i]];
|
|
989
|
+
let j = i + 1;
|
|
990
|
+
while (j < segmentation.len && !isTextRunBoundary(kinds[j])) {
|
|
991
|
+
mergedParts.push(texts[j]);
|
|
992
|
+
isWordLike[i] = true;
|
|
993
|
+
const endsQueryPrefix = texts[j].includes("?");
|
|
994
|
+
kinds[j] = "text";
|
|
995
|
+
texts[j] = "";
|
|
996
|
+
j++;
|
|
997
|
+
if (endsQueryPrefix)
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
texts[i] = joinTextParts(mergedParts);
|
|
1001
|
+
}
|
|
1002
|
+
let compactLen = 0;
|
|
1003
|
+
for (let read = 0; read < texts.length; read++) {
|
|
1004
|
+
const text = texts[read];
|
|
1005
|
+
if (text.length === 0)
|
|
1006
|
+
continue;
|
|
1007
|
+
if (compactLen !== read) {
|
|
1008
|
+
texts[compactLen] = text;
|
|
1009
|
+
isWordLike[compactLen] = isWordLike[read];
|
|
1010
|
+
kinds[compactLen] = kinds[read];
|
|
1011
|
+
starts[compactLen] = starts[read];
|
|
1012
|
+
}
|
|
1013
|
+
compactLen++;
|
|
1014
|
+
}
|
|
1015
|
+
texts.length = compactLen;
|
|
1016
|
+
isWordLike.length = compactLen;
|
|
1017
|
+
kinds.length = compactLen;
|
|
1018
|
+
starts.length = compactLen;
|
|
1019
|
+
return {
|
|
1020
|
+
len: compactLen,
|
|
1021
|
+
texts,
|
|
1022
|
+
isWordLike,
|
|
1023
|
+
kinds,
|
|
1024
|
+
starts
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
function mergeUrlQueryRuns(segmentation) {
|
|
1028
|
+
const texts = [];
|
|
1029
|
+
const isWordLike = [];
|
|
1030
|
+
const kinds = [];
|
|
1031
|
+
const starts = [];
|
|
1032
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
1033
|
+
const text = segmentation.texts[i];
|
|
1034
|
+
texts.push(text);
|
|
1035
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1036
|
+
kinds.push(segmentation.kinds[i]);
|
|
1037
|
+
starts.push(segmentation.starts[i]);
|
|
1038
|
+
if (!isUrlQueryBoundarySegment(text))
|
|
1039
|
+
continue;
|
|
1040
|
+
const nextIndex = i + 1;
|
|
1041
|
+
if (nextIndex >= segmentation.len || isTextRunBoundary(segmentation.kinds[nextIndex])) {
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
const queryParts = [];
|
|
1045
|
+
const queryStart = segmentation.starts[nextIndex];
|
|
1046
|
+
let j = nextIndex;
|
|
1047
|
+
while (j < segmentation.len && !isTextRunBoundary(segmentation.kinds[j])) {
|
|
1048
|
+
queryParts.push(segmentation.texts[j]);
|
|
1049
|
+
j++;
|
|
1050
|
+
}
|
|
1051
|
+
if (queryParts.length > 0) {
|
|
1052
|
+
texts.push(joinTextParts(queryParts));
|
|
1053
|
+
isWordLike.push(true);
|
|
1054
|
+
kinds.push("text");
|
|
1055
|
+
starts.push(queryStart);
|
|
1056
|
+
i = j - 1;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return {
|
|
1060
|
+
len: texts.length,
|
|
1061
|
+
texts,
|
|
1062
|
+
isWordLike,
|
|
1063
|
+
kinds,
|
|
1064
|
+
starts
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
var numericJoinerChars = /* @__PURE__ */ new Set([
|
|
1068
|
+
":",
|
|
1069
|
+
"-",
|
|
1070
|
+
"/",
|
|
1071
|
+
"\xD7",
|
|
1072
|
+
",",
|
|
1073
|
+
".",
|
|
1074
|
+
"+",
|
|
1075
|
+
"\u2013",
|
|
1076
|
+
"\u2014"
|
|
1077
|
+
]);
|
|
1078
|
+
var asciiPunctuationChainSegmentRe = /^[A-Za-z0-9_]+[,:;]*$/;
|
|
1079
|
+
var asciiPunctuationChainTrailingJoinersRe = /[,:;]+$/;
|
|
1080
|
+
function segmentContainsDecimalDigit(text) {
|
|
1081
|
+
for (const ch of text) {
|
|
1082
|
+
if (decimalDigitRe.test(ch))
|
|
1083
|
+
return true;
|
|
1084
|
+
}
|
|
1085
|
+
return false;
|
|
1086
|
+
}
|
|
1087
|
+
function isNumericRunSegment(text) {
|
|
1088
|
+
if (text.length === 0)
|
|
1089
|
+
return false;
|
|
1090
|
+
for (const ch of text) {
|
|
1091
|
+
if (decimalDigitRe.test(ch) || numericJoinerChars.has(ch))
|
|
1092
|
+
continue;
|
|
1093
|
+
return false;
|
|
1094
|
+
}
|
|
1095
|
+
return true;
|
|
1096
|
+
}
|
|
1097
|
+
function mergeNumericRuns(segmentation) {
|
|
1098
|
+
const texts = [];
|
|
1099
|
+
const isWordLike = [];
|
|
1100
|
+
const kinds = [];
|
|
1101
|
+
const starts = [];
|
|
1102
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
1103
|
+
const text = segmentation.texts[i];
|
|
1104
|
+
const kind = segmentation.kinds[i];
|
|
1105
|
+
if (kind === "text" && isNumericRunSegment(text) && segmentContainsDecimalDigit(text)) {
|
|
1106
|
+
const mergedParts = [text];
|
|
1107
|
+
let j = i + 1;
|
|
1108
|
+
while (j < segmentation.len && segmentation.kinds[j] === "text" && isNumericRunSegment(segmentation.texts[j])) {
|
|
1109
|
+
mergedParts.push(segmentation.texts[j]);
|
|
1110
|
+
j++;
|
|
1111
|
+
}
|
|
1112
|
+
texts.push(joinTextParts(mergedParts));
|
|
1113
|
+
isWordLike.push(true);
|
|
1114
|
+
kinds.push("text");
|
|
1115
|
+
starts.push(segmentation.starts[i]);
|
|
1116
|
+
i = j - 1;
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
texts.push(text);
|
|
1120
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1121
|
+
kinds.push(kind);
|
|
1122
|
+
starts.push(segmentation.starts[i]);
|
|
1123
|
+
}
|
|
1124
|
+
return {
|
|
1125
|
+
len: texts.length,
|
|
1126
|
+
texts,
|
|
1127
|
+
isWordLike,
|
|
1128
|
+
kinds,
|
|
1129
|
+
starts
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function mergeAsciiPunctuationChains(segmentation) {
|
|
1133
|
+
const texts = [];
|
|
1134
|
+
const isWordLike = [];
|
|
1135
|
+
const kinds = [];
|
|
1136
|
+
const starts = [];
|
|
1137
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
1138
|
+
const text = segmentation.texts[i];
|
|
1139
|
+
const kind = segmentation.kinds[i];
|
|
1140
|
+
const wordLike = segmentation.isWordLike[i];
|
|
1141
|
+
if (kind === "text" && wordLike && asciiPunctuationChainSegmentRe.test(text)) {
|
|
1142
|
+
const mergedParts = [text];
|
|
1143
|
+
let endsWithJoiners = asciiPunctuationChainTrailingJoinersRe.test(text);
|
|
1144
|
+
let j = i + 1;
|
|
1145
|
+
while (endsWithJoiners && j < segmentation.len && segmentation.kinds[j] === "text" && segmentation.isWordLike[j] && asciiPunctuationChainSegmentRe.test(segmentation.texts[j])) {
|
|
1146
|
+
const nextText = segmentation.texts[j];
|
|
1147
|
+
mergedParts.push(nextText);
|
|
1148
|
+
endsWithJoiners = asciiPunctuationChainTrailingJoinersRe.test(nextText);
|
|
1149
|
+
j++;
|
|
1150
|
+
}
|
|
1151
|
+
texts.push(joinTextParts(mergedParts));
|
|
1152
|
+
isWordLike.push(true);
|
|
1153
|
+
kinds.push("text");
|
|
1154
|
+
starts.push(segmentation.starts[i]);
|
|
1155
|
+
i = j - 1;
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
texts.push(text);
|
|
1159
|
+
isWordLike.push(wordLike);
|
|
1160
|
+
kinds.push(kind);
|
|
1161
|
+
starts.push(segmentation.starts[i]);
|
|
1162
|
+
}
|
|
1163
|
+
return {
|
|
1164
|
+
len: texts.length,
|
|
1165
|
+
texts,
|
|
1166
|
+
isWordLike,
|
|
1167
|
+
kinds,
|
|
1168
|
+
starts
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
function splitHyphenatedNumericRuns(segmentation) {
|
|
1172
|
+
const texts = [];
|
|
1173
|
+
const isWordLike = [];
|
|
1174
|
+
const kinds = [];
|
|
1175
|
+
const starts = [];
|
|
1176
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
1177
|
+
const text = segmentation.texts[i];
|
|
1178
|
+
if (segmentation.kinds[i] === "text" && text.includes("-")) {
|
|
1179
|
+
const parts = text.split("-");
|
|
1180
|
+
let shouldSplit = parts.length > 1;
|
|
1181
|
+
for (let j = 0; j < parts.length; j++) {
|
|
1182
|
+
const part = parts[j];
|
|
1183
|
+
if (!shouldSplit)
|
|
1184
|
+
break;
|
|
1185
|
+
if (part.length === 0 || !segmentContainsDecimalDigit(part) || !isNumericRunSegment(part)) {
|
|
1186
|
+
shouldSplit = false;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (shouldSplit) {
|
|
1190
|
+
let offset = 0;
|
|
1191
|
+
for (let j = 0; j < parts.length; j++) {
|
|
1192
|
+
const part = parts[j];
|
|
1193
|
+
const splitText = j < parts.length - 1 ? `${part}-` : part;
|
|
1194
|
+
texts.push(splitText);
|
|
1195
|
+
isWordLike.push(true);
|
|
1196
|
+
kinds.push("text");
|
|
1197
|
+
starts.push(segmentation.starts[i] + offset);
|
|
1198
|
+
offset += splitText.length;
|
|
1199
|
+
}
|
|
1200
|
+
continue;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
texts.push(text);
|
|
1204
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1205
|
+
kinds.push(segmentation.kinds[i]);
|
|
1206
|
+
starts.push(segmentation.starts[i]);
|
|
1207
|
+
}
|
|
1208
|
+
return {
|
|
1209
|
+
len: texts.length,
|
|
1210
|
+
texts,
|
|
1211
|
+
isWordLike,
|
|
1212
|
+
kinds,
|
|
1213
|
+
starts
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
function mergeGlueConnectedTextRuns(segmentation) {
|
|
1217
|
+
const texts = [];
|
|
1218
|
+
const isWordLike = [];
|
|
1219
|
+
const kinds = [];
|
|
1220
|
+
const starts = [];
|
|
1221
|
+
let read = 0;
|
|
1222
|
+
while (read < segmentation.len) {
|
|
1223
|
+
const textParts = [segmentation.texts[read]];
|
|
1224
|
+
let wordLike = segmentation.isWordLike[read];
|
|
1225
|
+
let kind = segmentation.kinds[read];
|
|
1226
|
+
let start = segmentation.starts[read];
|
|
1227
|
+
if (kind === "glue") {
|
|
1228
|
+
const glueParts = [textParts[0]];
|
|
1229
|
+
const glueStart = start;
|
|
1230
|
+
read++;
|
|
1231
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1232
|
+
glueParts.push(segmentation.texts[read]);
|
|
1233
|
+
read++;
|
|
1234
|
+
}
|
|
1235
|
+
const glueText = joinTextParts(glueParts);
|
|
1236
|
+
if (read < segmentation.len && segmentation.kinds[read] === "text") {
|
|
1237
|
+
textParts[0] = glueText;
|
|
1238
|
+
textParts.push(segmentation.texts[read]);
|
|
1239
|
+
wordLike = segmentation.isWordLike[read];
|
|
1240
|
+
kind = "text";
|
|
1241
|
+
start = glueStart;
|
|
1242
|
+
read++;
|
|
1243
|
+
} else {
|
|
1244
|
+
texts.push(glueText);
|
|
1245
|
+
isWordLike.push(false);
|
|
1246
|
+
kinds.push("glue");
|
|
1247
|
+
starts.push(glueStart);
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
} else {
|
|
1251
|
+
read++;
|
|
1252
|
+
}
|
|
1253
|
+
if (kind === "text") {
|
|
1254
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1255
|
+
const glueParts = [];
|
|
1256
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1257
|
+
glueParts.push(segmentation.texts[read]);
|
|
1258
|
+
read++;
|
|
1259
|
+
}
|
|
1260
|
+
const glueText = joinTextParts(glueParts);
|
|
1261
|
+
if (read < segmentation.len && segmentation.kinds[read] === "text") {
|
|
1262
|
+
textParts.push(glueText, segmentation.texts[read]);
|
|
1263
|
+
wordLike = wordLike || segmentation.isWordLike[read];
|
|
1264
|
+
read++;
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
textParts.push(glueText);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
texts.push(joinTextParts(textParts));
|
|
1271
|
+
isWordLike.push(wordLike);
|
|
1272
|
+
kinds.push(kind);
|
|
1273
|
+
starts.push(start);
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
len: texts.length,
|
|
1277
|
+
texts,
|
|
1278
|
+
isWordLike,
|
|
1279
|
+
kinds,
|
|
1280
|
+
starts
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
function carryTrailingForwardStickyAcrossCJKBoundary(segmentation) {
|
|
1284
|
+
const texts = segmentation.texts.slice();
|
|
1285
|
+
const isWordLike = segmentation.isWordLike.slice();
|
|
1286
|
+
const kinds = segmentation.kinds.slice();
|
|
1287
|
+
const starts = segmentation.starts.slice();
|
|
1288
|
+
for (let i = 0; i < texts.length - 1; i++) {
|
|
1289
|
+
if (kinds[i] !== "text" || kinds[i + 1] !== "text")
|
|
1290
|
+
continue;
|
|
1291
|
+
if (!isCJK(texts[i]) || !isCJK(texts[i + 1]))
|
|
1292
|
+
continue;
|
|
1293
|
+
const split = splitTrailingForwardStickyCluster(texts[i]);
|
|
1294
|
+
if (split === null)
|
|
1295
|
+
continue;
|
|
1296
|
+
texts[i] = split.head;
|
|
1297
|
+
texts[i + 1] = split.tail + texts[i + 1];
|
|
1298
|
+
starts[i + 1] = starts[i] + split.head.length;
|
|
1299
|
+
}
|
|
1300
|
+
return {
|
|
1301
|
+
len: texts.length,
|
|
1302
|
+
texts,
|
|
1303
|
+
isWordLike,
|
|
1304
|
+
kinds,
|
|
1305
|
+
starts
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
function buildMergedSegmentation(normalized, profile, whiteSpaceProfile) {
|
|
1309
|
+
const wordSegmenter = getSharedWordSegmenter();
|
|
1310
|
+
let mergedLen = 0;
|
|
1311
|
+
const mergedTexts = [];
|
|
1312
|
+
const mergedWordLike = [];
|
|
1313
|
+
const mergedKinds = [];
|
|
1314
|
+
const mergedStarts = [];
|
|
1315
|
+
for (const s of wordSegmenter.segment(normalized)) {
|
|
1316
|
+
for (const piece of splitSegmentByBreakKind(s.segment, s.isWordLike ?? false, s.index, whiteSpaceProfile)) {
|
|
1317
|
+
const isText = piece.kind === "text";
|
|
1318
|
+
if (profile.carryCJKAfterClosingQuote && isText && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && isCJK(piece.text) && isCJK(mergedTexts[mergedLen - 1]) && endsWithClosingQuote(mergedTexts[mergedLen - 1])) {
|
|
1319
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1320
|
+
mergedWordLike[mergedLen - 1] = mergedWordLike[mergedLen - 1] || piece.isWordLike;
|
|
1321
|
+
} else if (isText && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && isCJKLineStartProhibitedSegment(piece.text) && isCJK(mergedTexts[mergedLen - 1])) {
|
|
1322
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1323
|
+
mergedWordLike[mergedLen - 1] = mergedWordLike[mergedLen - 1] || piece.isWordLike;
|
|
1324
|
+
} else if (isText && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && endsWithMyanmarMedialGlue(mergedTexts[mergedLen - 1])) {
|
|
1325
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1326
|
+
mergedWordLike[mergedLen - 1] = mergedWordLike[mergedLen - 1] || piece.isWordLike;
|
|
1327
|
+
} else if (isText && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && piece.isWordLike && containsArabicScript(piece.text) && endsWithArabicNoSpacePunctuation(mergedTexts[mergedLen - 1])) {
|
|
1328
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1329
|
+
mergedWordLike[mergedLen - 1] = true;
|
|
1330
|
+
} else if (isText && !piece.isWordLike && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && piece.text.length === 1 && piece.text !== "-" && piece.text !== "\u2014" && isRepeatedSingleCharRun(mergedTexts[mergedLen - 1], piece.text)) {
|
|
1331
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1332
|
+
} else if (isText && !piece.isWordLike && mergedLen > 0 && mergedKinds[mergedLen - 1] === "text" && (isLeftStickyPunctuationSegment(piece.text) || piece.text === "-" && mergedWordLike[mergedLen - 1])) {
|
|
1333
|
+
mergedTexts[mergedLen - 1] += piece.text;
|
|
1334
|
+
} else {
|
|
1335
|
+
mergedTexts[mergedLen] = piece.text;
|
|
1336
|
+
mergedWordLike[mergedLen] = piece.isWordLike;
|
|
1337
|
+
mergedKinds[mergedLen] = piece.kind;
|
|
1338
|
+
mergedStarts[mergedLen] = piece.start;
|
|
1339
|
+
mergedLen++;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
for (let i = 1; i < mergedLen; i++) {
|
|
1344
|
+
if (mergedKinds[i] === "text" && !mergedWordLike[i] && isEscapedQuoteClusterSegment(mergedTexts[i]) && mergedKinds[i - 1] === "text") {
|
|
1345
|
+
mergedTexts[i - 1] += mergedTexts[i];
|
|
1346
|
+
mergedWordLike[i - 1] = mergedWordLike[i - 1] || mergedWordLike[i];
|
|
1347
|
+
mergedTexts[i] = "";
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
for (let i = mergedLen - 2; i >= 0; i--) {
|
|
1351
|
+
if (mergedKinds[i] === "text" && !mergedWordLike[i] && isForwardStickyClusterSegment(mergedTexts[i])) {
|
|
1352
|
+
let j = i + 1;
|
|
1353
|
+
while (j < mergedLen && mergedTexts[j] === "")
|
|
1354
|
+
j++;
|
|
1355
|
+
if (j < mergedLen && mergedKinds[j] === "text") {
|
|
1356
|
+
mergedTexts[j] = mergedTexts[i] + mergedTexts[j];
|
|
1357
|
+
mergedStarts[j] = mergedStarts[i];
|
|
1358
|
+
mergedTexts[i] = "";
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
let compactLen = 0;
|
|
1363
|
+
for (let read = 0; read < mergedLen; read++) {
|
|
1364
|
+
const text = mergedTexts[read];
|
|
1365
|
+
if (text.length === 0)
|
|
1366
|
+
continue;
|
|
1367
|
+
if (compactLen !== read) {
|
|
1368
|
+
mergedTexts[compactLen] = text;
|
|
1369
|
+
mergedWordLike[compactLen] = mergedWordLike[read];
|
|
1370
|
+
mergedKinds[compactLen] = mergedKinds[read];
|
|
1371
|
+
mergedStarts[compactLen] = mergedStarts[read];
|
|
1372
|
+
}
|
|
1373
|
+
compactLen++;
|
|
1374
|
+
}
|
|
1375
|
+
mergedTexts.length = compactLen;
|
|
1376
|
+
mergedWordLike.length = compactLen;
|
|
1377
|
+
mergedKinds.length = compactLen;
|
|
1378
|
+
mergedStarts.length = compactLen;
|
|
1379
|
+
const compacted = mergeGlueConnectedTextRuns({
|
|
1380
|
+
len: compactLen,
|
|
1381
|
+
texts: mergedTexts,
|
|
1382
|
+
isWordLike: mergedWordLike,
|
|
1383
|
+
kinds: mergedKinds,
|
|
1384
|
+
starts: mergedStarts
|
|
1385
|
+
});
|
|
1386
|
+
const withMergedUrls = carryTrailingForwardStickyAcrossCJKBoundary(mergeAsciiPunctuationChains(splitHyphenatedNumericRuns(mergeNumericRuns(mergeUrlQueryRuns(mergeUrlLikeRuns(compacted))))));
|
|
1387
|
+
for (let i = 0; i < withMergedUrls.len - 1; i++) {
|
|
1388
|
+
const split = splitLeadingSpaceAndMarks(withMergedUrls.texts[i]);
|
|
1389
|
+
if (split === null)
|
|
1390
|
+
continue;
|
|
1391
|
+
if (withMergedUrls.kinds[i] !== "space" && withMergedUrls.kinds[i] !== "preserved-space" || withMergedUrls.kinds[i + 1] !== "text" || !containsArabicScript(withMergedUrls.texts[i + 1])) {
|
|
1392
|
+
continue;
|
|
1393
|
+
}
|
|
1394
|
+
withMergedUrls.texts[i] = split.space;
|
|
1395
|
+
withMergedUrls.isWordLike[i] = false;
|
|
1396
|
+
withMergedUrls.kinds[i] = withMergedUrls.kinds[i] === "preserved-space" ? "preserved-space" : "space";
|
|
1397
|
+
withMergedUrls.texts[i + 1] = split.marks + withMergedUrls.texts[i + 1];
|
|
1398
|
+
withMergedUrls.starts[i + 1] = withMergedUrls.starts[i] + split.space.length;
|
|
1399
|
+
}
|
|
1400
|
+
return withMergedUrls;
|
|
1401
|
+
}
|
|
1402
|
+
function compileAnalysisChunks(segmentation, whiteSpaceProfile) {
|
|
1403
|
+
if (segmentation.len === 0)
|
|
1404
|
+
return [];
|
|
1405
|
+
if (!whiteSpaceProfile.preserveHardBreaks) {
|
|
1406
|
+
return [{
|
|
1407
|
+
startSegmentIndex: 0,
|
|
1408
|
+
endSegmentIndex: segmentation.len,
|
|
1409
|
+
consumedEndSegmentIndex: segmentation.len
|
|
1410
|
+
}];
|
|
1411
|
+
}
|
|
1412
|
+
const chunks = [];
|
|
1413
|
+
let startSegmentIndex = 0;
|
|
1414
|
+
for (let i = 0; i < segmentation.len; i++) {
|
|
1415
|
+
if (segmentation.kinds[i] !== "hard-break")
|
|
1416
|
+
continue;
|
|
1417
|
+
chunks.push({
|
|
1418
|
+
startSegmentIndex,
|
|
1419
|
+
endSegmentIndex: i,
|
|
1420
|
+
consumedEndSegmentIndex: i + 1
|
|
1421
|
+
});
|
|
1422
|
+
startSegmentIndex = i + 1;
|
|
1423
|
+
}
|
|
1424
|
+
if (startSegmentIndex < segmentation.len) {
|
|
1425
|
+
chunks.push({
|
|
1426
|
+
startSegmentIndex,
|
|
1427
|
+
endSegmentIndex: segmentation.len,
|
|
1428
|
+
consumedEndSegmentIndex: segmentation.len
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
return chunks;
|
|
1432
|
+
}
|
|
1433
|
+
function analyzeText(text, profile, whiteSpace = "normal") {
|
|
1434
|
+
const whiteSpaceProfile = getWhiteSpaceProfile(whiteSpace);
|
|
1435
|
+
const normalized = whiteSpaceProfile.mode === "pre-wrap" ? normalizeWhitespacePreWrap(text) : normalizeWhitespaceNormal(text);
|
|
1436
|
+
if (normalized.length === 0) {
|
|
1437
|
+
return {
|
|
1438
|
+
normalized,
|
|
1439
|
+
chunks: [],
|
|
1440
|
+
len: 0,
|
|
1441
|
+
texts: [],
|
|
1442
|
+
isWordLike: [],
|
|
1443
|
+
kinds: [],
|
|
1444
|
+
starts: []
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
const segmentation = buildMergedSegmentation(normalized, profile, whiteSpaceProfile);
|
|
1448
|
+
return {
|
|
1449
|
+
normalized,
|
|
1450
|
+
chunks: compileAnalysisChunks(segmentation, whiteSpaceProfile),
|
|
1451
|
+
...segmentation
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// ../../node_modules/.pnpm/@chenglou+pretext@0.0.4/node_modules/@chenglou/pretext/dist/measurement.js
|
|
1456
|
+
var measureContext = null;
|
|
1457
|
+
var segmentMetricCaches = /* @__PURE__ */ new Map();
|
|
1458
|
+
var cachedEngineProfile = null;
|
|
1459
|
+
var emojiPresentationRe = /\p{Emoji_Presentation}/u;
|
|
1460
|
+
var maybeEmojiRe = /[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
1461
|
+
var sharedGraphemeSegmenter = null;
|
|
1462
|
+
var emojiCorrectionCache = /* @__PURE__ */ new Map();
|
|
1463
|
+
function getMeasureContext() {
|
|
1464
|
+
if (measureContext !== null)
|
|
1465
|
+
return measureContext;
|
|
1466
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
1467
|
+
measureContext = new OffscreenCanvas(1, 1).getContext("2d");
|
|
1468
|
+
return measureContext;
|
|
1469
|
+
}
|
|
1470
|
+
if (typeof document !== "undefined") {
|
|
1471
|
+
measureContext = document.createElement("canvas").getContext("2d");
|
|
1472
|
+
return measureContext;
|
|
1473
|
+
}
|
|
1474
|
+
throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.");
|
|
1475
|
+
}
|
|
1476
|
+
function getSegmentMetricCache(font) {
|
|
1477
|
+
let cache = segmentMetricCaches.get(font);
|
|
1478
|
+
if (!cache) {
|
|
1479
|
+
cache = /* @__PURE__ */ new Map();
|
|
1480
|
+
segmentMetricCaches.set(font, cache);
|
|
1481
|
+
}
|
|
1482
|
+
return cache;
|
|
1483
|
+
}
|
|
1484
|
+
function getSegmentMetrics(seg, cache) {
|
|
1485
|
+
let metrics = cache.get(seg);
|
|
1486
|
+
if (metrics === void 0) {
|
|
1487
|
+
const ctx2 = getMeasureContext();
|
|
1488
|
+
metrics = {
|
|
1489
|
+
width: ctx2.measureText(seg).width,
|
|
1490
|
+
containsCJK: isCJK(seg)
|
|
1491
|
+
};
|
|
1492
|
+
cache.set(seg, metrics);
|
|
1493
|
+
}
|
|
1494
|
+
return metrics;
|
|
1495
|
+
}
|
|
1496
|
+
function getEngineProfile() {
|
|
1497
|
+
if (cachedEngineProfile !== null)
|
|
1498
|
+
return cachedEngineProfile;
|
|
1499
|
+
if (typeof navigator === "undefined") {
|
|
1500
|
+
cachedEngineProfile = {
|
|
1501
|
+
lineFitEpsilon: 5e-3,
|
|
1502
|
+
carryCJKAfterClosingQuote: false,
|
|
1503
|
+
preferPrefixWidthsForBreakableRuns: false,
|
|
1504
|
+
preferEarlySoftHyphenBreak: false
|
|
1505
|
+
};
|
|
1506
|
+
return cachedEngineProfile;
|
|
1507
|
+
}
|
|
1508
|
+
const ua = navigator.userAgent;
|
|
1509
|
+
const vendor = navigator.vendor;
|
|
1510
|
+
const isSafari = vendor === "Apple Computer, Inc." && ua.includes("Safari/") && !ua.includes("Chrome/") && !ua.includes("Chromium/") && !ua.includes("CriOS/") && !ua.includes("FxiOS/") && !ua.includes("EdgiOS/");
|
|
1511
|
+
const isChromium = ua.includes("Chrome/") || ua.includes("Chromium/") || ua.includes("CriOS/") || ua.includes("Edg/");
|
|
1512
|
+
cachedEngineProfile = {
|
|
1513
|
+
lineFitEpsilon: isSafari ? 1 / 64 : 5e-3,
|
|
1514
|
+
carryCJKAfterClosingQuote: isChromium,
|
|
1515
|
+
preferPrefixWidthsForBreakableRuns: isSafari,
|
|
1516
|
+
preferEarlySoftHyphenBreak: isSafari
|
|
1517
|
+
};
|
|
1518
|
+
return cachedEngineProfile;
|
|
1519
|
+
}
|
|
1520
|
+
function parseFontSize(font) {
|
|
1521
|
+
const m = font.match(/(\d+(?:\.\d+)?)\s*px/);
|
|
1522
|
+
return m ? parseFloat(m[1]) : 16;
|
|
1523
|
+
}
|
|
1524
|
+
function getSharedGraphemeSegmenter() {
|
|
1525
|
+
if (sharedGraphemeSegmenter === null) {
|
|
1526
|
+
sharedGraphemeSegmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1527
|
+
}
|
|
1528
|
+
return sharedGraphemeSegmenter;
|
|
1529
|
+
}
|
|
1530
|
+
function isEmojiGrapheme(g) {
|
|
1531
|
+
return emojiPresentationRe.test(g) || g.includes("\uFE0F");
|
|
1532
|
+
}
|
|
1533
|
+
function textMayContainEmoji(text) {
|
|
1534
|
+
return maybeEmojiRe.test(text);
|
|
1535
|
+
}
|
|
1536
|
+
function getEmojiCorrection(font, fontSize) {
|
|
1537
|
+
let correction = emojiCorrectionCache.get(font);
|
|
1538
|
+
if (correction !== void 0)
|
|
1539
|
+
return correction;
|
|
1540
|
+
const ctx2 = getMeasureContext();
|
|
1541
|
+
ctx2.font = font;
|
|
1542
|
+
const canvasW = ctx2.measureText("\u{1F600}").width;
|
|
1543
|
+
correction = 0;
|
|
1544
|
+
if (canvasW > fontSize + 0.5 && typeof document !== "undefined" && document.body !== null) {
|
|
1545
|
+
const span = document.createElement("span");
|
|
1546
|
+
span.style.font = font;
|
|
1547
|
+
span.style.display = "inline-block";
|
|
1548
|
+
span.style.visibility = "hidden";
|
|
1549
|
+
span.style.position = "absolute";
|
|
1550
|
+
span.textContent = "\u{1F600}";
|
|
1551
|
+
document.body.appendChild(span);
|
|
1552
|
+
const domW = span.getBoundingClientRect().width;
|
|
1553
|
+
document.body.removeChild(span);
|
|
1554
|
+
if (canvasW - domW > 0.5) {
|
|
1555
|
+
correction = canvasW - domW;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
emojiCorrectionCache.set(font, correction);
|
|
1559
|
+
return correction;
|
|
1560
|
+
}
|
|
1561
|
+
function countEmojiGraphemes(text) {
|
|
1562
|
+
let count = 0;
|
|
1563
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter();
|
|
1564
|
+
for (const g of graphemeSegmenter.segment(text)) {
|
|
1565
|
+
if (isEmojiGrapheme(g.segment))
|
|
1566
|
+
count++;
|
|
1567
|
+
}
|
|
1568
|
+
return count;
|
|
1569
|
+
}
|
|
1570
|
+
function getEmojiCount(seg, metrics) {
|
|
1571
|
+
if (metrics.emojiCount === void 0) {
|
|
1572
|
+
metrics.emojiCount = countEmojiGraphemes(seg);
|
|
1573
|
+
}
|
|
1574
|
+
return metrics.emojiCount;
|
|
1575
|
+
}
|
|
1576
|
+
function getCorrectedSegmentWidth(seg, metrics, emojiCorrection) {
|
|
1577
|
+
if (emojiCorrection === 0)
|
|
1578
|
+
return metrics.width;
|
|
1579
|
+
return metrics.width - getEmojiCount(seg, metrics) * emojiCorrection;
|
|
1580
|
+
}
|
|
1581
|
+
function getSegmentGraphemeWidths(seg, metrics, cache, emojiCorrection) {
|
|
1582
|
+
if (metrics.graphemeWidths !== void 0)
|
|
1583
|
+
return metrics.graphemeWidths;
|
|
1584
|
+
const widths = [];
|
|
1585
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter();
|
|
1586
|
+
for (const gs of graphemeSegmenter.segment(seg)) {
|
|
1587
|
+
const graphemeMetrics = getSegmentMetrics(gs.segment, cache);
|
|
1588
|
+
widths.push(getCorrectedSegmentWidth(gs.segment, graphemeMetrics, emojiCorrection));
|
|
1589
|
+
}
|
|
1590
|
+
metrics.graphemeWidths = widths.length > 1 ? widths : null;
|
|
1591
|
+
return metrics.graphemeWidths;
|
|
1592
|
+
}
|
|
1593
|
+
function getSegmentGraphemePrefixWidths(seg, metrics, cache, emojiCorrection) {
|
|
1594
|
+
if (metrics.graphemePrefixWidths !== void 0)
|
|
1595
|
+
return metrics.graphemePrefixWidths;
|
|
1596
|
+
const prefixWidths = [];
|
|
1597
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter();
|
|
1598
|
+
let prefix = "";
|
|
1599
|
+
for (const gs of graphemeSegmenter.segment(seg)) {
|
|
1600
|
+
prefix += gs.segment;
|
|
1601
|
+
const prefixMetrics = getSegmentMetrics(prefix, cache);
|
|
1602
|
+
prefixWidths.push(getCorrectedSegmentWidth(prefix, prefixMetrics, emojiCorrection));
|
|
1603
|
+
}
|
|
1604
|
+
metrics.graphemePrefixWidths = prefixWidths.length > 1 ? prefixWidths : null;
|
|
1605
|
+
return metrics.graphemePrefixWidths;
|
|
1606
|
+
}
|
|
1607
|
+
function getFontMeasurementState(font, needsEmojiCorrection) {
|
|
1608
|
+
const ctx2 = getMeasureContext();
|
|
1609
|
+
ctx2.font = font;
|
|
1610
|
+
const cache = getSegmentMetricCache(font);
|
|
1611
|
+
const fontSize = parseFontSize(font);
|
|
1612
|
+
const emojiCorrection = needsEmojiCorrection ? getEmojiCorrection(font, fontSize) : 0;
|
|
1613
|
+
return { cache, fontSize, emojiCorrection };
|
|
1614
|
+
}
|
|
1615
|
+
function clearMeasurementCaches() {
|
|
1616
|
+
segmentMetricCaches.clear();
|
|
1617
|
+
emojiCorrectionCache.clear();
|
|
1618
|
+
sharedGraphemeSegmenter = null;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
// ../../node_modules/.pnpm/@chenglou+pretext@0.0.4/node_modules/@chenglou/pretext/dist/layout.js
|
|
1622
|
+
var sharedGraphemeSegmenter2 = null;
|
|
1623
|
+
var sharedLineTextCaches = /* @__PURE__ */ new WeakMap();
|
|
1624
|
+
function getSharedGraphemeSegmenter2() {
|
|
1625
|
+
if (sharedGraphemeSegmenter2 === null) {
|
|
1626
|
+
sharedGraphemeSegmenter2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1627
|
+
}
|
|
1628
|
+
return sharedGraphemeSegmenter2;
|
|
1629
|
+
}
|
|
1630
|
+
function createEmptyPrepared(includeSegments) {
|
|
1631
|
+
if (includeSegments) {
|
|
1632
|
+
return {
|
|
1633
|
+
widths: [],
|
|
1634
|
+
lineEndFitAdvances: [],
|
|
1635
|
+
lineEndPaintAdvances: [],
|
|
1636
|
+
kinds: [],
|
|
1637
|
+
simpleLineWalkFastPath: true,
|
|
1638
|
+
segLevels: null,
|
|
1639
|
+
breakableWidths: [],
|
|
1640
|
+
breakablePrefixWidths: [],
|
|
1641
|
+
discretionaryHyphenWidth: 0,
|
|
1642
|
+
tabStopAdvance: 0,
|
|
1643
|
+
chunks: [],
|
|
1644
|
+
segments: []
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
return {
|
|
1648
|
+
widths: [],
|
|
1649
|
+
lineEndFitAdvances: [],
|
|
1650
|
+
lineEndPaintAdvances: [],
|
|
1651
|
+
kinds: [],
|
|
1652
|
+
simpleLineWalkFastPath: true,
|
|
1653
|
+
segLevels: null,
|
|
1654
|
+
breakableWidths: [],
|
|
1655
|
+
breakablePrefixWidths: [],
|
|
1656
|
+
discretionaryHyphenWidth: 0,
|
|
1657
|
+
tabStopAdvance: 0,
|
|
1658
|
+
chunks: []
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
function measureAnalysis(analysis, font, includeSegments) {
|
|
1662
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter2();
|
|
1663
|
+
const engineProfile = getEngineProfile();
|
|
1664
|
+
const { cache, emojiCorrection } = getFontMeasurementState(font, textMayContainEmoji(analysis.normalized));
|
|
1665
|
+
const discretionaryHyphenWidth = getCorrectedSegmentWidth("-", getSegmentMetrics("-", cache), emojiCorrection);
|
|
1666
|
+
const spaceWidth = getCorrectedSegmentWidth(" ", getSegmentMetrics(" ", cache), emojiCorrection);
|
|
1667
|
+
const tabStopAdvance = spaceWidth * 8;
|
|
1668
|
+
if (analysis.len === 0)
|
|
1669
|
+
return createEmptyPrepared(includeSegments);
|
|
1670
|
+
const widths = [];
|
|
1671
|
+
const lineEndFitAdvances = [];
|
|
1672
|
+
const lineEndPaintAdvances = [];
|
|
1673
|
+
const kinds = [];
|
|
1674
|
+
let simpleLineWalkFastPath = analysis.chunks.length <= 1;
|
|
1675
|
+
const segStarts = includeSegments ? [] : null;
|
|
1676
|
+
const breakableWidths = [];
|
|
1677
|
+
const breakablePrefixWidths = [];
|
|
1678
|
+
const segments = includeSegments ? [] : null;
|
|
1679
|
+
const preparedStartByAnalysisIndex = Array.from({ length: analysis.len });
|
|
1680
|
+
const preparedEndByAnalysisIndex = Array.from({ length: analysis.len });
|
|
1681
|
+
function pushMeasuredSegment(text, width, lineEndFitAdvance, lineEndPaintAdvance, kind, start, breakable, breakablePrefix) {
|
|
1682
|
+
if (kind !== "text" && kind !== "space" && kind !== "zero-width-break") {
|
|
1683
|
+
simpleLineWalkFastPath = false;
|
|
1684
|
+
}
|
|
1685
|
+
widths.push(width);
|
|
1686
|
+
lineEndFitAdvances.push(lineEndFitAdvance);
|
|
1687
|
+
lineEndPaintAdvances.push(lineEndPaintAdvance);
|
|
1688
|
+
kinds.push(kind);
|
|
1689
|
+
segStarts?.push(start);
|
|
1690
|
+
breakableWidths.push(breakable);
|
|
1691
|
+
breakablePrefixWidths.push(breakablePrefix);
|
|
1692
|
+
if (segments !== null)
|
|
1693
|
+
segments.push(text);
|
|
1694
|
+
}
|
|
1695
|
+
for (let mi = 0; mi < analysis.len; mi++) {
|
|
1696
|
+
preparedStartByAnalysisIndex[mi] = widths.length;
|
|
1697
|
+
const segText = analysis.texts[mi];
|
|
1698
|
+
const segWordLike = analysis.isWordLike[mi];
|
|
1699
|
+
const segKind = analysis.kinds[mi];
|
|
1700
|
+
const segStart = analysis.starts[mi];
|
|
1701
|
+
if (segKind === "soft-hyphen") {
|
|
1702
|
+
pushMeasuredSegment(segText, 0, discretionaryHyphenWidth, discretionaryHyphenWidth, segKind, segStart, null, null);
|
|
1703
|
+
preparedEndByAnalysisIndex[mi] = widths.length;
|
|
1704
|
+
continue;
|
|
1705
|
+
}
|
|
1706
|
+
if (segKind === "hard-break") {
|
|
1707
|
+
pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null, null);
|
|
1708
|
+
preparedEndByAnalysisIndex[mi] = widths.length;
|
|
1709
|
+
continue;
|
|
1710
|
+
}
|
|
1711
|
+
if (segKind === "tab") {
|
|
1712
|
+
pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null, null);
|
|
1713
|
+
preparedEndByAnalysisIndex[mi] = widths.length;
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
const segMetrics = getSegmentMetrics(segText, cache);
|
|
1717
|
+
if (segKind === "text" && segMetrics.containsCJK) {
|
|
1718
|
+
let unitText = "";
|
|
1719
|
+
let unitStart = 0;
|
|
1720
|
+
for (const gs of graphemeSegmenter.segment(segText)) {
|
|
1721
|
+
const grapheme = gs.segment;
|
|
1722
|
+
if (unitText.length === 0) {
|
|
1723
|
+
unitText = grapheme;
|
|
1724
|
+
unitStart = gs.index;
|
|
1725
|
+
continue;
|
|
1726
|
+
}
|
|
1727
|
+
if (kinsokuEnd.has(unitText) || kinsokuStart.has(grapheme) || leftStickyPunctuation.has(grapheme) || engineProfile.carryCJKAfterClosingQuote && isCJK(grapheme) && endsWithClosingQuote(unitText)) {
|
|
1728
|
+
unitText += grapheme;
|
|
1729
|
+
continue;
|
|
1730
|
+
}
|
|
1731
|
+
const unitMetrics = getSegmentMetrics(unitText, cache);
|
|
1732
|
+
const w2 = getCorrectedSegmentWidth(unitText, unitMetrics, emojiCorrection);
|
|
1733
|
+
pushMeasuredSegment(unitText, w2, w2, w2, "text", segStart + unitStart, null, null);
|
|
1734
|
+
unitText = grapheme;
|
|
1735
|
+
unitStart = gs.index;
|
|
1736
|
+
}
|
|
1737
|
+
if (unitText.length > 0) {
|
|
1738
|
+
const unitMetrics = getSegmentMetrics(unitText, cache);
|
|
1739
|
+
const w2 = getCorrectedSegmentWidth(unitText, unitMetrics, emojiCorrection);
|
|
1740
|
+
pushMeasuredSegment(unitText, w2, w2, w2, "text", segStart + unitStart, null, null);
|
|
1741
|
+
}
|
|
1742
|
+
preparedEndByAnalysisIndex[mi] = widths.length;
|
|
1743
|
+
continue;
|
|
1744
|
+
}
|
|
1745
|
+
const w = getCorrectedSegmentWidth(segText, segMetrics, emojiCorrection);
|
|
1746
|
+
const lineEndFitAdvance = segKind === "space" || segKind === "preserved-space" || segKind === "zero-width-break" ? 0 : w;
|
|
1747
|
+
const lineEndPaintAdvance = segKind === "space" || segKind === "zero-width-break" ? 0 : w;
|
|
1748
|
+
if (segWordLike && segText.length > 1) {
|
|
1749
|
+
const graphemeWidths = getSegmentGraphemeWidths(segText, segMetrics, cache, emojiCorrection);
|
|
1750
|
+
const graphemePrefixWidths = engineProfile.preferPrefixWidthsForBreakableRuns ? getSegmentGraphemePrefixWidths(segText, segMetrics, cache, emojiCorrection) : null;
|
|
1751
|
+
pushMeasuredSegment(segText, w, lineEndFitAdvance, lineEndPaintAdvance, segKind, segStart, graphemeWidths, graphemePrefixWidths);
|
|
1752
|
+
} else {
|
|
1753
|
+
pushMeasuredSegment(segText, w, lineEndFitAdvance, lineEndPaintAdvance, segKind, segStart, null, null);
|
|
1754
|
+
}
|
|
1755
|
+
preparedEndByAnalysisIndex[mi] = widths.length;
|
|
1756
|
+
}
|
|
1757
|
+
const chunks = mapAnalysisChunksToPreparedChunks(analysis.chunks, preparedStartByAnalysisIndex, preparedEndByAnalysisIndex);
|
|
1758
|
+
const segLevels = segStarts === null ? null : computeSegmentLevels(analysis.normalized, segStarts);
|
|
1759
|
+
if (segments !== null) {
|
|
1760
|
+
return {
|
|
1761
|
+
widths,
|
|
1762
|
+
lineEndFitAdvances,
|
|
1763
|
+
lineEndPaintAdvances,
|
|
1764
|
+
kinds,
|
|
1765
|
+
simpleLineWalkFastPath,
|
|
1766
|
+
segLevels,
|
|
1767
|
+
breakableWidths,
|
|
1768
|
+
breakablePrefixWidths,
|
|
1769
|
+
discretionaryHyphenWidth,
|
|
1770
|
+
tabStopAdvance,
|
|
1771
|
+
chunks,
|
|
1772
|
+
segments
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
return {
|
|
1776
|
+
widths,
|
|
1777
|
+
lineEndFitAdvances,
|
|
1778
|
+
lineEndPaintAdvances,
|
|
1779
|
+
kinds,
|
|
1780
|
+
simpleLineWalkFastPath,
|
|
1781
|
+
segLevels,
|
|
1782
|
+
breakableWidths,
|
|
1783
|
+
breakablePrefixWidths,
|
|
1784
|
+
discretionaryHyphenWidth,
|
|
1785
|
+
tabStopAdvance,
|
|
1786
|
+
chunks
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
function mapAnalysisChunksToPreparedChunks(chunks, preparedStartByAnalysisIndex, preparedEndByAnalysisIndex) {
|
|
1790
|
+
const preparedChunks = [];
|
|
1791
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1792
|
+
const chunk = chunks[i];
|
|
1793
|
+
const startSegmentIndex = chunk.startSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.startSegmentIndex] : preparedEndByAnalysisIndex[preparedEndByAnalysisIndex.length - 1] ?? 0;
|
|
1794
|
+
const endSegmentIndex = chunk.endSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.endSegmentIndex] : preparedEndByAnalysisIndex[preparedEndByAnalysisIndex.length - 1] ?? 0;
|
|
1795
|
+
const consumedEndSegmentIndex = chunk.consumedEndSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.consumedEndSegmentIndex] : preparedEndByAnalysisIndex[preparedEndByAnalysisIndex.length - 1] ?? 0;
|
|
1796
|
+
preparedChunks.push({
|
|
1797
|
+
startSegmentIndex,
|
|
1798
|
+
endSegmentIndex,
|
|
1799
|
+
consumedEndSegmentIndex
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
return preparedChunks;
|
|
1803
|
+
}
|
|
1804
|
+
function prepareInternal(text, font, includeSegments, options) {
|
|
1805
|
+
const analysis = analyzeText(text, getEngineProfile(), options?.whiteSpace);
|
|
1806
|
+
return measureAnalysis(analysis, font, includeSegments);
|
|
1807
|
+
}
|
|
1808
|
+
function prepare(text, font, options) {
|
|
1809
|
+
return prepareInternal(text, font, false, options);
|
|
1810
|
+
}
|
|
1811
|
+
function prepareWithSegments(text, font, options) {
|
|
1812
|
+
return prepareInternal(text, font, true, options);
|
|
1813
|
+
}
|
|
1814
|
+
function clearCache() {
|
|
1815
|
+
clearAnalysisCaches();
|
|
1816
|
+
sharedGraphemeSegmenter2 = null;
|
|
1817
|
+
sharedLineTextCaches = /* @__PURE__ */ new WeakMap();
|
|
1818
|
+
clearMeasurementCaches();
|
|
1819
|
+
}
|
|
1820
|
+
function setLocale(locale) {
|
|
1821
|
+
setAnalysisLocale(locale);
|
|
1822
|
+
clearCache();
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
// src/worker-script.ts
|
|
1826
|
+
var ctx = globalThis;
|
|
1827
|
+
ctx.onmessage = (event) => {
|
|
1828
|
+
const { id, type, text, font, options, locale } = event.data;
|
|
1829
|
+
try {
|
|
1830
|
+
switch (type) {
|
|
1831
|
+
case "prepare": {
|
|
1832
|
+
const result = prepare(text, font, options);
|
|
1833
|
+
ctx.postMessage({ id, type: "result", result });
|
|
1834
|
+
break;
|
|
1835
|
+
}
|
|
1836
|
+
case "prepareWithSegments": {
|
|
1837
|
+
const result = prepareWithSegments(text, font, options);
|
|
1838
|
+
ctx.postMessage({ id, type: "result", result });
|
|
1839
|
+
break;
|
|
1840
|
+
}
|
|
1841
|
+
case "clearCache": {
|
|
1842
|
+
clearCache();
|
|
1843
|
+
ctx.postMessage({ id, type: "result" });
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
case "setLocale": {
|
|
1847
|
+
setLocale(locale);
|
|
1848
|
+
ctx.postMessage({ id, type: "result" });
|
|
1849
|
+
break;
|
|
1850
|
+
}
|
|
1851
|
+
default: {
|
|
1852
|
+
ctx.postMessage({
|
|
1853
|
+
id,
|
|
1854
|
+
type: "error",
|
|
1855
|
+
error: `Unknown message type: ${type}`
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
} catch (err) {
|
|
1860
|
+
ctx.postMessage({
|
|
1861
|
+
id,
|
|
1862
|
+
type: "error",
|
|
1863
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
//# sourceMappingURL=worker-script.js.map
|