@vyaz/core 0.0.16 → 0.1.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/bin/vyaz.js +27 -0
- package/dist/cli/check.d.ts +12 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +4077 -0
- package/dist/compile/ParagraphCompiler.d.ts +84 -0
- package/dist/compile/ParagraphCompiler.d.ts.map +1 -0
- package/dist/debug/lines-to-yaml.d.ts +14 -0
- package/dist/debug/lines-to-yaml.d.ts.map +1 -0
- package/dist/debug.d.ts +11 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +4 -0
- package/dist/index.browser.d.ts +9 -4
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +3197 -5031
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4709 -796
- package/dist/layout/AutoFitEngine.d.ts.map +1 -1
- package/dist/layout/LineBoxValidator.d.ts +5 -10
- package/dist/layout/LineBoxValidator.d.ts.map +1 -1
- package/dist/layout/ParagraphLayoutEngine.d.ts +13 -8
- package/dist/layout/ParagraphLayoutEngine.d.ts.map +1 -1
- package/dist/layout/PositioningEngine.d.ts +1 -1
- package/dist/layout/PositioningEngine.d.ts.map +1 -1
- package/dist/layout/TextFrameLayoutEngine.d.ts +84 -15
- package/dist/layout/TextFrameLayoutEngine.d.ts.map +1 -1
- package/dist/layout/create-engine.d.ts +32 -0
- package/dist/layout/create-engine.d.ts.map +1 -0
- package/dist/layout/resolve-font.d.ts +25 -0
- package/dist/layout/resolve-font.d.ts.map +1 -0
- package/dist/measure/FontEngine.d.ts +44 -1
- package/dist/measure/FontEngine.d.ts.map +1 -1
- package/dist/measure/FontMetricsProvider.d.ts +3 -10
- package/dist/measure/FontMetricsProvider.d.ts.map +1 -1
- package/dist/measure/FontkitMeasureContext.d.ts +109 -0
- package/dist/measure/FontkitMeasureContext.d.ts.map +1 -0
- package/dist/measure/canvas-polyfill.d.ts.map +1 -1
- package/dist/types/Document.d.ts +36 -23
- package/dist/types/Document.d.ts.map +1 -1
- package/dist/types/FontTypes.d.ts +1 -1
- package/dist/types/FontTypes.d.ts.map +1 -1
- package/dist/types/LayoutTypes.d.ts +19 -2
- package/dist/types/LayoutTypes.d.ts.map +1 -1
- package/package.json +16 -4
|
@@ -0,0 +1,4077 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
var __require = import.meta.require;
|
|
18
|
+
|
|
19
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/generated/bidi-data.js
|
|
20
|
+
var latin1BidiTypes, nonLatin1BidiRanges;
|
|
21
|
+
var init_bidi_data = __esm(() => {
|
|
22
|
+
latin1BidiTypes = [
|
|
23
|
+
"BN",
|
|
24
|
+
"BN",
|
|
25
|
+
"BN",
|
|
26
|
+
"BN",
|
|
27
|
+
"BN",
|
|
28
|
+
"BN",
|
|
29
|
+
"BN",
|
|
30
|
+
"BN",
|
|
31
|
+
"BN",
|
|
32
|
+
"S",
|
|
33
|
+
"B",
|
|
34
|
+
"S",
|
|
35
|
+
"WS",
|
|
36
|
+
"B",
|
|
37
|
+
"BN",
|
|
38
|
+
"BN",
|
|
39
|
+
"BN",
|
|
40
|
+
"BN",
|
|
41
|
+
"BN",
|
|
42
|
+
"BN",
|
|
43
|
+
"BN",
|
|
44
|
+
"BN",
|
|
45
|
+
"BN",
|
|
46
|
+
"BN",
|
|
47
|
+
"BN",
|
|
48
|
+
"BN",
|
|
49
|
+
"BN",
|
|
50
|
+
"BN",
|
|
51
|
+
"B",
|
|
52
|
+
"B",
|
|
53
|
+
"B",
|
|
54
|
+
"S",
|
|
55
|
+
"WS",
|
|
56
|
+
"ON",
|
|
57
|
+
"ON",
|
|
58
|
+
"ET",
|
|
59
|
+
"ET",
|
|
60
|
+
"ET",
|
|
61
|
+
"ON",
|
|
62
|
+
"ON",
|
|
63
|
+
"ON",
|
|
64
|
+
"ON",
|
|
65
|
+
"ON",
|
|
66
|
+
"ES",
|
|
67
|
+
"CS",
|
|
68
|
+
"ES",
|
|
69
|
+
"CS",
|
|
70
|
+
"CS",
|
|
71
|
+
"EN",
|
|
72
|
+
"EN",
|
|
73
|
+
"EN",
|
|
74
|
+
"EN",
|
|
75
|
+
"EN",
|
|
76
|
+
"EN",
|
|
77
|
+
"EN",
|
|
78
|
+
"EN",
|
|
79
|
+
"EN",
|
|
80
|
+
"EN",
|
|
81
|
+
"CS",
|
|
82
|
+
"ON",
|
|
83
|
+
"ON",
|
|
84
|
+
"ON",
|
|
85
|
+
"ON",
|
|
86
|
+
"ON",
|
|
87
|
+
"ON",
|
|
88
|
+
"L",
|
|
89
|
+
"L",
|
|
90
|
+
"L",
|
|
91
|
+
"L",
|
|
92
|
+
"L",
|
|
93
|
+
"L",
|
|
94
|
+
"L",
|
|
95
|
+
"L",
|
|
96
|
+
"L",
|
|
97
|
+
"L",
|
|
98
|
+
"L",
|
|
99
|
+
"L",
|
|
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
|
+
"ON",
|
|
115
|
+
"ON",
|
|
116
|
+
"ON",
|
|
117
|
+
"ON",
|
|
118
|
+
"ON",
|
|
119
|
+
"ON",
|
|
120
|
+
"L",
|
|
121
|
+
"L",
|
|
122
|
+
"L",
|
|
123
|
+
"L",
|
|
124
|
+
"L",
|
|
125
|
+
"L",
|
|
126
|
+
"L",
|
|
127
|
+
"L",
|
|
128
|
+
"L",
|
|
129
|
+
"L",
|
|
130
|
+
"L",
|
|
131
|
+
"L",
|
|
132
|
+
"L",
|
|
133
|
+
"L",
|
|
134
|
+
"L",
|
|
135
|
+
"L",
|
|
136
|
+
"L",
|
|
137
|
+
"L",
|
|
138
|
+
"L",
|
|
139
|
+
"L",
|
|
140
|
+
"L",
|
|
141
|
+
"L",
|
|
142
|
+
"L",
|
|
143
|
+
"L",
|
|
144
|
+
"L",
|
|
145
|
+
"L",
|
|
146
|
+
"ON",
|
|
147
|
+
"ON",
|
|
148
|
+
"ON",
|
|
149
|
+
"ON",
|
|
150
|
+
"BN",
|
|
151
|
+
"BN",
|
|
152
|
+
"BN",
|
|
153
|
+
"BN",
|
|
154
|
+
"BN",
|
|
155
|
+
"BN",
|
|
156
|
+
"B",
|
|
157
|
+
"BN",
|
|
158
|
+
"BN",
|
|
159
|
+
"BN",
|
|
160
|
+
"BN",
|
|
161
|
+
"BN",
|
|
162
|
+
"BN",
|
|
163
|
+
"BN",
|
|
164
|
+
"BN",
|
|
165
|
+
"BN",
|
|
166
|
+
"BN",
|
|
167
|
+
"BN",
|
|
168
|
+
"BN",
|
|
169
|
+
"BN",
|
|
170
|
+
"BN",
|
|
171
|
+
"BN",
|
|
172
|
+
"BN",
|
|
173
|
+
"BN",
|
|
174
|
+
"BN",
|
|
175
|
+
"BN",
|
|
176
|
+
"BN",
|
|
177
|
+
"BN",
|
|
178
|
+
"BN",
|
|
179
|
+
"BN",
|
|
180
|
+
"BN",
|
|
181
|
+
"BN",
|
|
182
|
+
"BN",
|
|
183
|
+
"CS",
|
|
184
|
+
"ON",
|
|
185
|
+
"ET",
|
|
186
|
+
"ET",
|
|
187
|
+
"ET",
|
|
188
|
+
"ET",
|
|
189
|
+
"ON",
|
|
190
|
+
"ON",
|
|
191
|
+
"ON",
|
|
192
|
+
"ON",
|
|
193
|
+
"L",
|
|
194
|
+
"ON",
|
|
195
|
+
"ON",
|
|
196
|
+
"BN",
|
|
197
|
+
"ON",
|
|
198
|
+
"ON",
|
|
199
|
+
"ET",
|
|
200
|
+
"ET",
|
|
201
|
+
"EN",
|
|
202
|
+
"EN",
|
|
203
|
+
"ON",
|
|
204
|
+
"L",
|
|
205
|
+
"ON",
|
|
206
|
+
"ON",
|
|
207
|
+
"ON",
|
|
208
|
+
"EN",
|
|
209
|
+
"L",
|
|
210
|
+
"ON",
|
|
211
|
+
"ON",
|
|
212
|
+
"ON",
|
|
213
|
+
"ON",
|
|
214
|
+
"ON",
|
|
215
|
+
"L",
|
|
216
|
+
"L",
|
|
217
|
+
"L",
|
|
218
|
+
"L",
|
|
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
|
+
"ON",
|
|
239
|
+
"L",
|
|
240
|
+
"L",
|
|
241
|
+
"L",
|
|
242
|
+
"L",
|
|
243
|
+
"L",
|
|
244
|
+
"L",
|
|
245
|
+
"L",
|
|
246
|
+
"L",
|
|
247
|
+
"L",
|
|
248
|
+
"L",
|
|
249
|
+
"L",
|
|
250
|
+
"L",
|
|
251
|
+
"L",
|
|
252
|
+
"L",
|
|
253
|
+
"L",
|
|
254
|
+
"L",
|
|
255
|
+
"L",
|
|
256
|
+
"L",
|
|
257
|
+
"L",
|
|
258
|
+
"L",
|
|
259
|
+
"L",
|
|
260
|
+
"L",
|
|
261
|
+
"L",
|
|
262
|
+
"L",
|
|
263
|
+
"L",
|
|
264
|
+
"L",
|
|
265
|
+
"L",
|
|
266
|
+
"L",
|
|
267
|
+
"L",
|
|
268
|
+
"L",
|
|
269
|
+
"L",
|
|
270
|
+
"ON",
|
|
271
|
+
"L",
|
|
272
|
+
"L",
|
|
273
|
+
"L",
|
|
274
|
+
"L",
|
|
275
|
+
"L",
|
|
276
|
+
"L",
|
|
277
|
+
"L",
|
|
278
|
+
"L"
|
|
279
|
+
];
|
|
280
|
+
nonLatin1BidiRanges = [
|
|
281
|
+
[697, 698, "ON"],
|
|
282
|
+
[706, 719, "ON"],
|
|
283
|
+
[722, 735, "ON"],
|
|
284
|
+
[741, 749, "ON"],
|
|
285
|
+
[751, 767, "ON"],
|
|
286
|
+
[768, 879, "NSM"],
|
|
287
|
+
[884, 885, "ON"],
|
|
288
|
+
[894, 894, "ON"],
|
|
289
|
+
[900, 901, "ON"],
|
|
290
|
+
[903, 903, "ON"],
|
|
291
|
+
[1014, 1014, "ON"],
|
|
292
|
+
[1155, 1161, "NSM"],
|
|
293
|
+
[1418, 1418, "ON"],
|
|
294
|
+
[1421, 1422, "ON"],
|
|
295
|
+
[1423, 1423, "ET"],
|
|
296
|
+
[1424, 1424, "R"],
|
|
297
|
+
[1425, 1469, "NSM"],
|
|
298
|
+
[1470, 1470, "R"],
|
|
299
|
+
[1471, 1471, "NSM"],
|
|
300
|
+
[1472, 1472, "R"],
|
|
301
|
+
[1473, 1474, "NSM"],
|
|
302
|
+
[1475, 1475, "R"],
|
|
303
|
+
[1476, 1477, "NSM"],
|
|
304
|
+
[1478, 1478, "R"],
|
|
305
|
+
[1479, 1479, "NSM"],
|
|
306
|
+
[1480, 1535, "R"],
|
|
307
|
+
[1536, 1541, "AN"],
|
|
308
|
+
[1542, 1543, "ON"],
|
|
309
|
+
[1544, 1544, "AL"],
|
|
310
|
+
[1545, 1546, "ET"],
|
|
311
|
+
[1547, 1547, "AL"],
|
|
312
|
+
[1548, 1548, "CS"],
|
|
313
|
+
[1549, 1549, "AL"],
|
|
314
|
+
[1550, 1551, "ON"],
|
|
315
|
+
[1552, 1562, "NSM"],
|
|
316
|
+
[1563, 1610, "AL"],
|
|
317
|
+
[1611, 1631, "NSM"],
|
|
318
|
+
[1632, 1641, "AN"],
|
|
319
|
+
[1642, 1642, "ET"],
|
|
320
|
+
[1643, 1644, "AN"],
|
|
321
|
+
[1645, 1647, "AL"],
|
|
322
|
+
[1648, 1648, "NSM"],
|
|
323
|
+
[1649, 1749, "AL"],
|
|
324
|
+
[1750, 1756, "NSM"],
|
|
325
|
+
[1757, 1757, "AN"],
|
|
326
|
+
[1758, 1758, "ON"],
|
|
327
|
+
[1759, 1764, "NSM"],
|
|
328
|
+
[1765, 1766, "AL"],
|
|
329
|
+
[1767, 1768, "NSM"],
|
|
330
|
+
[1769, 1769, "ON"],
|
|
331
|
+
[1770, 1773, "NSM"],
|
|
332
|
+
[1774, 1775, "AL"],
|
|
333
|
+
[1776, 1785, "EN"],
|
|
334
|
+
[1786, 1808, "AL"],
|
|
335
|
+
[1809, 1809, "NSM"],
|
|
336
|
+
[1810, 1839, "AL"],
|
|
337
|
+
[1840, 1866, "NSM"],
|
|
338
|
+
[1867, 1957, "AL"],
|
|
339
|
+
[1958, 1968, "NSM"],
|
|
340
|
+
[1969, 1983, "AL"],
|
|
341
|
+
[1984, 2026, "R"],
|
|
342
|
+
[2027, 2035, "NSM"],
|
|
343
|
+
[2036, 2037, "R"],
|
|
344
|
+
[2038, 2041, "ON"],
|
|
345
|
+
[2042, 2044, "R"],
|
|
346
|
+
[2045, 2045, "NSM"],
|
|
347
|
+
[2046, 2069, "R"],
|
|
348
|
+
[2070, 2073, "NSM"],
|
|
349
|
+
[2074, 2074, "R"],
|
|
350
|
+
[2075, 2083, "NSM"],
|
|
351
|
+
[2084, 2084, "R"],
|
|
352
|
+
[2085, 2087, "NSM"],
|
|
353
|
+
[2088, 2088, "R"],
|
|
354
|
+
[2089, 2093, "NSM"],
|
|
355
|
+
[2094, 2136, "R"],
|
|
356
|
+
[2137, 2139, "NSM"],
|
|
357
|
+
[2140, 2143, "R"],
|
|
358
|
+
[2144, 2191, "AL"],
|
|
359
|
+
[2192, 2193, "AN"],
|
|
360
|
+
[2194, 2198, "AL"],
|
|
361
|
+
[2199, 2207, "NSM"],
|
|
362
|
+
[2208, 2249, "AL"],
|
|
363
|
+
[2250, 2273, "NSM"],
|
|
364
|
+
[2274, 2274, "AN"],
|
|
365
|
+
[2275, 2306, "NSM"],
|
|
366
|
+
[2362, 2362, "NSM"],
|
|
367
|
+
[2364, 2364, "NSM"],
|
|
368
|
+
[2369, 2376, "NSM"],
|
|
369
|
+
[2381, 2381, "NSM"],
|
|
370
|
+
[2385, 2391, "NSM"],
|
|
371
|
+
[2402, 2403, "NSM"],
|
|
372
|
+
[2433, 2433, "NSM"],
|
|
373
|
+
[2492, 2492, "NSM"],
|
|
374
|
+
[2497, 2500, "NSM"],
|
|
375
|
+
[2509, 2509, "NSM"],
|
|
376
|
+
[2530, 2531, "NSM"],
|
|
377
|
+
[2546, 2547, "ET"],
|
|
378
|
+
[2555, 2555, "ET"],
|
|
379
|
+
[2558, 2558, "NSM"],
|
|
380
|
+
[2561, 2562, "NSM"],
|
|
381
|
+
[2620, 2620, "NSM"],
|
|
382
|
+
[2625, 2626, "NSM"],
|
|
383
|
+
[2631, 2632, "NSM"],
|
|
384
|
+
[2635, 2637, "NSM"],
|
|
385
|
+
[2641, 2641, "NSM"],
|
|
386
|
+
[2672, 2673, "NSM"],
|
|
387
|
+
[2677, 2677, "NSM"],
|
|
388
|
+
[2689, 2690, "NSM"],
|
|
389
|
+
[2748, 2748, "NSM"],
|
|
390
|
+
[2753, 2757, "NSM"],
|
|
391
|
+
[2759, 2760, "NSM"],
|
|
392
|
+
[2765, 2765, "NSM"],
|
|
393
|
+
[2786, 2787, "NSM"],
|
|
394
|
+
[2801, 2801, "ET"],
|
|
395
|
+
[2810, 2815, "NSM"],
|
|
396
|
+
[2817, 2817, "NSM"],
|
|
397
|
+
[2876, 2876, "NSM"],
|
|
398
|
+
[2879, 2879, "NSM"],
|
|
399
|
+
[2881, 2884, "NSM"],
|
|
400
|
+
[2893, 2893, "NSM"],
|
|
401
|
+
[2901, 2902, "NSM"],
|
|
402
|
+
[2914, 2915, "NSM"],
|
|
403
|
+
[2946, 2946, "NSM"],
|
|
404
|
+
[3008, 3008, "NSM"],
|
|
405
|
+
[3021, 3021, "NSM"],
|
|
406
|
+
[3059, 3064, "ON"],
|
|
407
|
+
[3065, 3065, "ET"],
|
|
408
|
+
[3066, 3066, "ON"],
|
|
409
|
+
[3072, 3072, "NSM"],
|
|
410
|
+
[3076, 3076, "NSM"],
|
|
411
|
+
[3132, 3132, "NSM"],
|
|
412
|
+
[3134, 3136, "NSM"],
|
|
413
|
+
[3142, 3144, "NSM"],
|
|
414
|
+
[3146, 3149, "NSM"],
|
|
415
|
+
[3157, 3158, "NSM"],
|
|
416
|
+
[3170, 3171, "NSM"],
|
|
417
|
+
[3192, 3198, "ON"],
|
|
418
|
+
[3201, 3201, "NSM"],
|
|
419
|
+
[3260, 3260, "NSM"],
|
|
420
|
+
[3276, 3277, "NSM"],
|
|
421
|
+
[3298, 3299, "NSM"],
|
|
422
|
+
[3328, 3329, "NSM"],
|
|
423
|
+
[3387, 3388, "NSM"],
|
|
424
|
+
[3393, 3396, "NSM"],
|
|
425
|
+
[3405, 3405, "NSM"],
|
|
426
|
+
[3426, 3427, "NSM"],
|
|
427
|
+
[3457, 3457, "NSM"],
|
|
428
|
+
[3530, 3530, "NSM"],
|
|
429
|
+
[3538, 3540, "NSM"],
|
|
430
|
+
[3542, 3542, "NSM"],
|
|
431
|
+
[3633, 3633, "NSM"],
|
|
432
|
+
[3636, 3642, "NSM"],
|
|
433
|
+
[3647, 3647, "ET"],
|
|
434
|
+
[3655, 3662, "NSM"],
|
|
435
|
+
[3761, 3761, "NSM"],
|
|
436
|
+
[3764, 3772, "NSM"],
|
|
437
|
+
[3784, 3790, "NSM"],
|
|
438
|
+
[3864, 3865, "NSM"],
|
|
439
|
+
[3893, 3893, "NSM"],
|
|
440
|
+
[3895, 3895, "NSM"],
|
|
441
|
+
[3897, 3897, "NSM"],
|
|
442
|
+
[3898, 3901, "ON"],
|
|
443
|
+
[3953, 3966, "NSM"],
|
|
444
|
+
[3968, 3972, "NSM"],
|
|
445
|
+
[3974, 3975, "NSM"],
|
|
446
|
+
[3981, 3991, "NSM"],
|
|
447
|
+
[3993, 4028, "NSM"],
|
|
448
|
+
[4038, 4038, "NSM"],
|
|
449
|
+
[4141, 4144, "NSM"],
|
|
450
|
+
[4146, 4151, "NSM"],
|
|
451
|
+
[4153, 4154, "NSM"],
|
|
452
|
+
[4157, 4158, "NSM"],
|
|
453
|
+
[4184, 4185, "NSM"],
|
|
454
|
+
[4190, 4192, "NSM"],
|
|
455
|
+
[4209, 4212, "NSM"],
|
|
456
|
+
[4226, 4226, "NSM"],
|
|
457
|
+
[4229, 4230, "NSM"],
|
|
458
|
+
[4237, 4237, "NSM"],
|
|
459
|
+
[4253, 4253, "NSM"],
|
|
460
|
+
[4957, 4959, "NSM"],
|
|
461
|
+
[5008, 5017, "ON"],
|
|
462
|
+
[5120, 5120, "ON"],
|
|
463
|
+
[5760, 5760, "WS"],
|
|
464
|
+
[5787, 5788, "ON"],
|
|
465
|
+
[5906, 5908, "NSM"],
|
|
466
|
+
[5938, 5939, "NSM"],
|
|
467
|
+
[5970, 5971, "NSM"],
|
|
468
|
+
[6002, 6003, "NSM"],
|
|
469
|
+
[6068, 6069, "NSM"],
|
|
470
|
+
[6071, 6077, "NSM"],
|
|
471
|
+
[6086, 6086, "NSM"],
|
|
472
|
+
[6089, 6099, "NSM"],
|
|
473
|
+
[6107, 6107, "ET"],
|
|
474
|
+
[6109, 6109, "NSM"],
|
|
475
|
+
[6128, 6137, "ON"],
|
|
476
|
+
[6144, 6154, "ON"],
|
|
477
|
+
[6155, 6157, "NSM"],
|
|
478
|
+
[6158, 6158, "BN"],
|
|
479
|
+
[6159, 6159, "NSM"],
|
|
480
|
+
[6277, 6278, "NSM"],
|
|
481
|
+
[6313, 6313, "NSM"],
|
|
482
|
+
[6432, 6434, "NSM"],
|
|
483
|
+
[6439, 6440, "NSM"],
|
|
484
|
+
[6450, 6450, "NSM"],
|
|
485
|
+
[6457, 6459, "NSM"],
|
|
486
|
+
[6464, 6464, "ON"],
|
|
487
|
+
[6468, 6469, "ON"],
|
|
488
|
+
[6622, 6655, "ON"],
|
|
489
|
+
[6679, 6680, "NSM"],
|
|
490
|
+
[6683, 6683, "NSM"],
|
|
491
|
+
[6742, 6742, "NSM"],
|
|
492
|
+
[6744, 6750, "NSM"],
|
|
493
|
+
[6752, 6752, "NSM"],
|
|
494
|
+
[6754, 6754, "NSM"],
|
|
495
|
+
[6757, 6764, "NSM"],
|
|
496
|
+
[6771, 6780, "NSM"],
|
|
497
|
+
[6783, 6783, "NSM"],
|
|
498
|
+
[6832, 6877, "NSM"],
|
|
499
|
+
[6880, 6891, "NSM"],
|
|
500
|
+
[6912, 6915, "NSM"],
|
|
501
|
+
[6964, 6964, "NSM"],
|
|
502
|
+
[6966, 6970, "NSM"],
|
|
503
|
+
[6972, 6972, "NSM"],
|
|
504
|
+
[6978, 6978, "NSM"],
|
|
505
|
+
[7019, 7027, "NSM"],
|
|
506
|
+
[7040, 7041, "NSM"],
|
|
507
|
+
[7074, 7077, "NSM"],
|
|
508
|
+
[7080, 7081, "NSM"],
|
|
509
|
+
[7083, 7085, "NSM"],
|
|
510
|
+
[7142, 7142, "NSM"],
|
|
511
|
+
[7144, 7145, "NSM"],
|
|
512
|
+
[7149, 7149, "NSM"],
|
|
513
|
+
[7151, 7153, "NSM"],
|
|
514
|
+
[7212, 7219, "NSM"],
|
|
515
|
+
[7222, 7223, "NSM"],
|
|
516
|
+
[7376, 7378, "NSM"],
|
|
517
|
+
[7380, 7392, "NSM"],
|
|
518
|
+
[7394, 7400, "NSM"],
|
|
519
|
+
[7405, 7405, "NSM"],
|
|
520
|
+
[7412, 7412, "NSM"],
|
|
521
|
+
[7416, 7417, "NSM"],
|
|
522
|
+
[7616, 7679, "NSM"],
|
|
523
|
+
[8125, 8125, "ON"],
|
|
524
|
+
[8127, 8129, "ON"],
|
|
525
|
+
[8141, 8143, "ON"],
|
|
526
|
+
[8157, 8159, "ON"],
|
|
527
|
+
[8173, 8175, "ON"],
|
|
528
|
+
[8189, 8190, "ON"],
|
|
529
|
+
[8192, 8202, "WS"],
|
|
530
|
+
[8203, 8205, "BN"],
|
|
531
|
+
[8207, 8207, "R"],
|
|
532
|
+
[8208, 8231, "ON"],
|
|
533
|
+
[8232, 8232, "WS"],
|
|
534
|
+
[8233, 8233, "B"],
|
|
535
|
+
[8234, 8238, "BN"],
|
|
536
|
+
[8239, 8239, "CS"],
|
|
537
|
+
[8240, 8244, "ET"],
|
|
538
|
+
[8245, 8259, "ON"],
|
|
539
|
+
[8260, 8260, "CS"],
|
|
540
|
+
[8261, 8286, "ON"],
|
|
541
|
+
[8287, 8287, "WS"],
|
|
542
|
+
[8288, 8303, "BN"],
|
|
543
|
+
[8304, 8304, "EN"],
|
|
544
|
+
[8308, 8313, "EN"],
|
|
545
|
+
[8314, 8315, "ES"],
|
|
546
|
+
[8316, 8318, "ON"],
|
|
547
|
+
[8320, 8329, "EN"],
|
|
548
|
+
[8330, 8331, "ES"],
|
|
549
|
+
[8332, 8334, "ON"],
|
|
550
|
+
[8352, 8399, "ET"],
|
|
551
|
+
[8400, 8432, "NSM"],
|
|
552
|
+
[8448, 8449, "ON"],
|
|
553
|
+
[8451, 8454, "ON"],
|
|
554
|
+
[8456, 8457, "ON"],
|
|
555
|
+
[8468, 8468, "ON"],
|
|
556
|
+
[8470, 8472, "ON"],
|
|
557
|
+
[8478, 8483, "ON"],
|
|
558
|
+
[8485, 8485, "ON"],
|
|
559
|
+
[8487, 8487, "ON"],
|
|
560
|
+
[8489, 8489, "ON"],
|
|
561
|
+
[8494, 8494, "ET"],
|
|
562
|
+
[8506, 8507, "ON"],
|
|
563
|
+
[8512, 8516, "ON"],
|
|
564
|
+
[8522, 8525, "ON"],
|
|
565
|
+
[8528, 8543, "ON"],
|
|
566
|
+
[8585, 8587, "ON"],
|
|
567
|
+
[8592, 8721, "ON"],
|
|
568
|
+
[8722, 8722, "ES"],
|
|
569
|
+
[8723, 8723, "ET"],
|
|
570
|
+
[8724, 9013, "ON"],
|
|
571
|
+
[9083, 9108, "ON"],
|
|
572
|
+
[9110, 9257, "ON"],
|
|
573
|
+
[9280, 9290, "ON"],
|
|
574
|
+
[9312, 9351, "ON"],
|
|
575
|
+
[9352, 9371, "EN"],
|
|
576
|
+
[9450, 9899, "ON"],
|
|
577
|
+
[9901, 10239, "ON"],
|
|
578
|
+
[10496, 11123, "ON"],
|
|
579
|
+
[11126, 11263, "ON"],
|
|
580
|
+
[11493, 11498, "ON"],
|
|
581
|
+
[11503, 11505, "NSM"],
|
|
582
|
+
[11513, 11519, "ON"],
|
|
583
|
+
[11647, 11647, "NSM"],
|
|
584
|
+
[11744, 11775, "NSM"],
|
|
585
|
+
[11776, 11869, "ON"],
|
|
586
|
+
[11904, 11929, "ON"],
|
|
587
|
+
[11931, 12019, "ON"],
|
|
588
|
+
[12032, 12245, "ON"],
|
|
589
|
+
[12272, 12287, "ON"],
|
|
590
|
+
[12288, 12288, "WS"],
|
|
591
|
+
[12289, 12292, "ON"],
|
|
592
|
+
[12296, 12320, "ON"],
|
|
593
|
+
[12330, 12333, "NSM"],
|
|
594
|
+
[12336, 12336, "ON"],
|
|
595
|
+
[12342, 12343, "ON"],
|
|
596
|
+
[12349, 12351, "ON"],
|
|
597
|
+
[12441, 12442, "NSM"],
|
|
598
|
+
[12443, 12444, "ON"],
|
|
599
|
+
[12448, 12448, "ON"],
|
|
600
|
+
[12539, 12539, "ON"],
|
|
601
|
+
[12736, 12773, "ON"],
|
|
602
|
+
[12783, 12783, "ON"],
|
|
603
|
+
[12829, 12830, "ON"],
|
|
604
|
+
[12880, 12895, "ON"],
|
|
605
|
+
[12924, 12926, "ON"],
|
|
606
|
+
[12977, 12991, "ON"],
|
|
607
|
+
[13004, 13007, "ON"],
|
|
608
|
+
[13175, 13178, "ON"],
|
|
609
|
+
[13278, 13279, "ON"],
|
|
610
|
+
[13311, 13311, "ON"],
|
|
611
|
+
[19904, 19967, "ON"],
|
|
612
|
+
[42128, 42182, "ON"],
|
|
613
|
+
[42509, 42511, "ON"],
|
|
614
|
+
[42607, 42610, "NSM"],
|
|
615
|
+
[42611, 42611, "ON"],
|
|
616
|
+
[42612, 42621, "NSM"],
|
|
617
|
+
[42622, 42623, "ON"],
|
|
618
|
+
[42654, 42655, "NSM"],
|
|
619
|
+
[42736, 42737, "NSM"],
|
|
620
|
+
[42752, 42785, "ON"],
|
|
621
|
+
[42888, 42888, "ON"],
|
|
622
|
+
[43010, 43010, "NSM"],
|
|
623
|
+
[43014, 43014, "NSM"],
|
|
624
|
+
[43019, 43019, "NSM"],
|
|
625
|
+
[43045, 43046, "NSM"],
|
|
626
|
+
[43048, 43051, "ON"],
|
|
627
|
+
[43052, 43052, "NSM"],
|
|
628
|
+
[43064, 43065, "ET"],
|
|
629
|
+
[43124, 43127, "ON"],
|
|
630
|
+
[43204, 43205, "NSM"],
|
|
631
|
+
[43232, 43249, "NSM"],
|
|
632
|
+
[43263, 43263, "NSM"],
|
|
633
|
+
[43302, 43309, "NSM"],
|
|
634
|
+
[43335, 43345, "NSM"],
|
|
635
|
+
[43392, 43394, "NSM"],
|
|
636
|
+
[43443, 43443, "NSM"],
|
|
637
|
+
[43446, 43449, "NSM"],
|
|
638
|
+
[43452, 43453, "NSM"],
|
|
639
|
+
[43493, 43493, "NSM"],
|
|
640
|
+
[43561, 43566, "NSM"],
|
|
641
|
+
[43569, 43570, "NSM"],
|
|
642
|
+
[43573, 43574, "NSM"],
|
|
643
|
+
[43587, 43587, "NSM"],
|
|
644
|
+
[43596, 43596, "NSM"],
|
|
645
|
+
[43644, 43644, "NSM"],
|
|
646
|
+
[43696, 43696, "NSM"],
|
|
647
|
+
[43698, 43700, "NSM"],
|
|
648
|
+
[43703, 43704, "NSM"],
|
|
649
|
+
[43710, 43711, "NSM"],
|
|
650
|
+
[43713, 43713, "NSM"],
|
|
651
|
+
[43756, 43757, "NSM"],
|
|
652
|
+
[43766, 43766, "NSM"],
|
|
653
|
+
[43882, 43883, "ON"],
|
|
654
|
+
[44005, 44005, "NSM"],
|
|
655
|
+
[44008, 44008, "NSM"],
|
|
656
|
+
[44013, 44013, "NSM"],
|
|
657
|
+
[64285, 64285, "R"],
|
|
658
|
+
[64286, 64286, "NSM"],
|
|
659
|
+
[64287, 64296, "R"],
|
|
660
|
+
[64297, 64297, "ES"],
|
|
661
|
+
[64298, 64335, "R"],
|
|
662
|
+
[64336, 64450, "AL"],
|
|
663
|
+
[64451, 64466, "ON"],
|
|
664
|
+
[64467, 64829, "AL"],
|
|
665
|
+
[64830, 64847, "ON"],
|
|
666
|
+
[64848, 64911, "AL"],
|
|
667
|
+
[64912, 64913, "ON"],
|
|
668
|
+
[64914, 64967, "AL"],
|
|
669
|
+
[64968, 64975, "ON"],
|
|
670
|
+
[64976, 65007, "BN"],
|
|
671
|
+
[65008, 65020, "AL"],
|
|
672
|
+
[65021, 65023, "ON"],
|
|
673
|
+
[65024, 65039, "NSM"],
|
|
674
|
+
[65040, 65049, "ON"],
|
|
675
|
+
[65056, 65071, "NSM"],
|
|
676
|
+
[65072, 65103, "ON"],
|
|
677
|
+
[65104, 65104, "CS"],
|
|
678
|
+
[65105, 65105, "ON"],
|
|
679
|
+
[65106, 65106, "CS"],
|
|
680
|
+
[65108, 65108, "ON"],
|
|
681
|
+
[65109, 65109, "CS"],
|
|
682
|
+
[65110, 65118, "ON"],
|
|
683
|
+
[65119, 65119, "ET"],
|
|
684
|
+
[65120, 65121, "ON"],
|
|
685
|
+
[65122, 65123, "ES"],
|
|
686
|
+
[65124, 65126, "ON"],
|
|
687
|
+
[65128, 65128, "ON"],
|
|
688
|
+
[65129, 65130, "ET"],
|
|
689
|
+
[65131, 65131, "ON"],
|
|
690
|
+
[65136, 65278, "AL"],
|
|
691
|
+
[65279, 65279, "BN"],
|
|
692
|
+
[65281, 65282, "ON"],
|
|
693
|
+
[65283, 65285, "ET"],
|
|
694
|
+
[65286, 65290, "ON"],
|
|
695
|
+
[65291, 65291, "ES"],
|
|
696
|
+
[65292, 65292, "CS"],
|
|
697
|
+
[65293, 65293, "ES"],
|
|
698
|
+
[65294, 65295, "CS"],
|
|
699
|
+
[65296, 65305, "EN"],
|
|
700
|
+
[65306, 65306, "CS"],
|
|
701
|
+
[65307, 65312, "ON"],
|
|
702
|
+
[65339, 65344, "ON"],
|
|
703
|
+
[65371, 65381, "ON"],
|
|
704
|
+
[65504, 65505, "ET"],
|
|
705
|
+
[65506, 65508, "ON"],
|
|
706
|
+
[65509, 65510, "ET"],
|
|
707
|
+
[65512, 65518, "ON"],
|
|
708
|
+
[65520, 65528, "BN"],
|
|
709
|
+
[65529, 65533, "ON"],
|
|
710
|
+
[65534, 65535, "BN"],
|
|
711
|
+
[65793, 65793, "ON"],
|
|
712
|
+
[65856, 65932, "ON"],
|
|
713
|
+
[65936, 65948, "ON"],
|
|
714
|
+
[65952, 65952, "ON"],
|
|
715
|
+
[66045, 66045, "NSM"],
|
|
716
|
+
[66272, 66272, "NSM"],
|
|
717
|
+
[66273, 66299, "EN"],
|
|
718
|
+
[66422, 66426, "NSM"],
|
|
719
|
+
[67584, 67870, "R"],
|
|
720
|
+
[67871, 67871, "ON"],
|
|
721
|
+
[67872, 68096, "R"],
|
|
722
|
+
[68097, 68099, "NSM"],
|
|
723
|
+
[68100, 68100, "R"],
|
|
724
|
+
[68101, 68102, "NSM"],
|
|
725
|
+
[68103, 68107, "R"],
|
|
726
|
+
[68108, 68111, "NSM"],
|
|
727
|
+
[68112, 68151, "R"],
|
|
728
|
+
[68152, 68154, "NSM"],
|
|
729
|
+
[68155, 68158, "R"],
|
|
730
|
+
[68159, 68159, "NSM"],
|
|
731
|
+
[68160, 68324, "R"],
|
|
732
|
+
[68325, 68326, "NSM"],
|
|
733
|
+
[68327, 68408, "R"],
|
|
734
|
+
[68409, 68415, "ON"],
|
|
735
|
+
[68416, 68863, "R"],
|
|
736
|
+
[68864, 68899, "AL"],
|
|
737
|
+
[68900, 68903, "NSM"],
|
|
738
|
+
[68904, 68911, "AL"],
|
|
739
|
+
[68912, 68921, "AN"],
|
|
740
|
+
[68922, 68927, "AL"],
|
|
741
|
+
[68928, 68937, "AN"],
|
|
742
|
+
[68938, 68968, "R"],
|
|
743
|
+
[68969, 68973, "NSM"],
|
|
744
|
+
[68974, 68974, "ON"],
|
|
745
|
+
[68975, 69215, "R"],
|
|
746
|
+
[69216, 69246, "AN"],
|
|
747
|
+
[69247, 69290, "R"],
|
|
748
|
+
[69291, 69292, "NSM"],
|
|
749
|
+
[69293, 69311, "R"],
|
|
750
|
+
[69312, 69327, "AL"],
|
|
751
|
+
[69328, 69336, "ON"],
|
|
752
|
+
[69337, 69369, "AL"],
|
|
753
|
+
[69370, 69375, "NSM"],
|
|
754
|
+
[69376, 69423, "R"],
|
|
755
|
+
[69424, 69445, "AL"],
|
|
756
|
+
[69446, 69456, "NSM"],
|
|
757
|
+
[69457, 69487, "AL"],
|
|
758
|
+
[69488, 69505, "R"],
|
|
759
|
+
[69506, 69509, "NSM"],
|
|
760
|
+
[69510, 69631, "R"],
|
|
761
|
+
[69633, 69633, "NSM"],
|
|
762
|
+
[69688, 69702, "NSM"],
|
|
763
|
+
[69714, 69733, "ON"],
|
|
764
|
+
[69744, 69744, "NSM"],
|
|
765
|
+
[69747, 69748, "NSM"],
|
|
766
|
+
[69759, 69761, "NSM"],
|
|
767
|
+
[69811, 69814, "NSM"],
|
|
768
|
+
[69817, 69818, "NSM"],
|
|
769
|
+
[69826, 69826, "NSM"],
|
|
770
|
+
[69888, 69890, "NSM"],
|
|
771
|
+
[69927, 69931, "NSM"],
|
|
772
|
+
[69933, 69940, "NSM"],
|
|
773
|
+
[70003, 70003, "NSM"],
|
|
774
|
+
[70016, 70017, "NSM"],
|
|
775
|
+
[70070, 70078, "NSM"],
|
|
776
|
+
[70089, 70092, "NSM"],
|
|
777
|
+
[70095, 70095, "NSM"],
|
|
778
|
+
[70191, 70193, "NSM"],
|
|
779
|
+
[70196, 70196, "NSM"],
|
|
780
|
+
[70198, 70199, "NSM"],
|
|
781
|
+
[70206, 70206, "NSM"],
|
|
782
|
+
[70209, 70209, "NSM"],
|
|
783
|
+
[70367, 70367, "NSM"],
|
|
784
|
+
[70371, 70378, "NSM"],
|
|
785
|
+
[70400, 70401, "NSM"],
|
|
786
|
+
[70459, 70460, "NSM"],
|
|
787
|
+
[70464, 70464, "NSM"],
|
|
788
|
+
[70502, 70508, "NSM"],
|
|
789
|
+
[70512, 70516, "NSM"],
|
|
790
|
+
[70587, 70592, "NSM"],
|
|
791
|
+
[70606, 70606, "NSM"],
|
|
792
|
+
[70608, 70608, "NSM"],
|
|
793
|
+
[70610, 70610, "NSM"],
|
|
794
|
+
[70625, 70626, "NSM"],
|
|
795
|
+
[70712, 70719, "NSM"],
|
|
796
|
+
[70722, 70724, "NSM"],
|
|
797
|
+
[70726, 70726, "NSM"],
|
|
798
|
+
[70750, 70750, "NSM"],
|
|
799
|
+
[70835, 70840, "NSM"],
|
|
800
|
+
[70842, 70842, "NSM"],
|
|
801
|
+
[70847, 70848, "NSM"],
|
|
802
|
+
[70850, 70851, "NSM"],
|
|
803
|
+
[71090, 71093, "NSM"],
|
|
804
|
+
[71100, 71101, "NSM"],
|
|
805
|
+
[71103, 71104, "NSM"],
|
|
806
|
+
[71132, 71133, "NSM"],
|
|
807
|
+
[71219, 71226, "NSM"],
|
|
808
|
+
[71229, 71229, "NSM"],
|
|
809
|
+
[71231, 71232, "NSM"],
|
|
810
|
+
[71264, 71276, "ON"],
|
|
811
|
+
[71339, 71339, "NSM"],
|
|
812
|
+
[71341, 71341, "NSM"],
|
|
813
|
+
[71344, 71349, "NSM"],
|
|
814
|
+
[71351, 71351, "NSM"],
|
|
815
|
+
[71453, 71453, "NSM"],
|
|
816
|
+
[71455, 71455, "NSM"],
|
|
817
|
+
[71458, 71461, "NSM"],
|
|
818
|
+
[71463, 71467, "NSM"],
|
|
819
|
+
[71727, 71735, "NSM"],
|
|
820
|
+
[71737, 71738, "NSM"],
|
|
821
|
+
[71995, 71996, "NSM"],
|
|
822
|
+
[71998, 71998, "NSM"],
|
|
823
|
+
[72003, 72003, "NSM"],
|
|
824
|
+
[72148, 72151, "NSM"],
|
|
825
|
+
[72154, 72155, "NSM"],
|
|
826
|
+
[72160, 72160, "NSM"],
|
|
827
|
+
[72193, 72198, "NSM"],
|
|
828
|
+
[72201, 72202, "NSM"],
|
|
829
|
+
[72243, 72248, "NSM"],
|
|
830
|
+
[72251, 72254, "NSM"],
|
|
831
|
+
[72263, 72263, "NSM"],
|
|
832
|
+
[72273, 72278, "NSM"],
|
|
833
|
+
[72281, 72283, "NSM"],
|
|
834
|
+
[72330, 72342, "NSM"],
|
|
835
|
+
[72344, 72345, "NSM"],
|
|
836
|
+
[72544, 72544, "NSM"],
|
|
837
|
+
[72546, 72548, "NSM"],
|
|
838
|
+
[72550, 72550, "NSM"],
|
|
839
|
+
[72752, 72758, "NSM"],
|
|
840
|
+
[72760, 72765, "NSM"],
|
|
841
|
+
[72850, 72871, "NSM"],
|
|
842
|
+
[72874, 72880, "NSM"],
|
|
843
|
+
[72882, 72883, "NSM"],
|
|
844
|
+
[72885, 72886, "NSM"],
|
|
845
|
+
[73009, 73014, "NSM"],
|
|
846
|
+
[73018, 73018, "NSM"],
|
|
847
|
+
[73020, 73021, "NSM"],
|
|
848
|
+
[73023, 73029, "NSM"],
|
|
849
|
+
[73031, 73031, "NSM"],
|
|
850
|
+
[73104, 73105, "NSM"],
|
|
851
|
+
[73109, 73109, "NSM"],
|
|
852
|
+
[73111, 73111, "NSM"],
|
|
853
|
+
[73459, 73460, "NSM"],
|
|
854
|
+
[73472, 73473, "NSM"],
|
|
855
|
+
[73526, 73530, "NSM"],
|
|
856
|
+
[73536, 73536, "NSM"],
|
|
857
|
+
[73538, 73538, "NSM"],
|
|
858
|
+
[73562, 73562, "NSM"],
|
|
859
|
+
[73685, 73692, "ON"],
|
|
860
|
+
[73693, 73696, "ET"],
|
|
861
|
+
[73697, 73713, "ON"],
|
|
862
|
+
[78912, 78912, "NSM"],
|
|
863
|
+
[78919, 78933, "NSM"],
|
|
864
|
+
[90398, 90409, "NSM"],
|
|
865
|
+
[90413, 90415, "NSM"],
|
|
866
|
+
[92912, 92916, "NSM"],
|
|
867
|
+
[92976, 92982, "NSM"],
|
|
868
|
+
[94031, 94031, "NSM"],
|
|
869
|
+
[94095, 94098, "NSM"],
|
|
870
|
+
[94178, 94178, "ON"],
|
|
871
|
+
[94180, 94180, "NSM"],
|
|
872
|
+
[113821, 113822, "NSM"],
|
|
873
|
+
[113824, 113827, "BN"],
|
|
874
|
+
[117760, 117973, "ON"],
|
|
875
|
+
[118000, 118009, "EN"],
|
|
876
|
+
[118010, 118012, "ON"],
|
|
877
|
+
[118016, 118451, "ON"],
|
|
878
|
+
[118458, 118480, "ON"],
|
|
879
|
+
[118496, 118512, "ON"],
|
|
880
|
+
[118528, 118573, "NSM"],
|
|
881
|
+
[118576, 118598, "NSM"],
|
|
882
|
+
[119143, 119145, "NSM"],
|
|
883
|
+
[119155, 119162, "BN"],
|
|
884
|
+
[119163, 119170, "NSM"],
|
|
885
|
+
[119173, 119179, "NSM"],
|
|
886
|
+
[119210, 119213, "NSM"],
|
|
887
|
+
[119273, 119274, "ON"],
|
|
888
|
+
[119296, 119361, "ON"],
|
|
889
|
+
[119362, 119364, "NSM"],
|
|
890
|
+
[119365, 119365, "ON"],
|
|
891
|
+
[119552, 119638, "ON"],
|
|
892
|
+
[120513, 120513, "ON"],
|
|
893
|
+
[120539, 120539, "ON"],
|
|
894
|
+
[120571, 120571, "ON"],
|
|
895
|
+
[120597, 120597, "ON"],
|
|
896
|
+
[120629, 120629, "ON"],
|
|
897
|
+
[120655, 120655, "ON"],
|
|
898
|
+
[120687, 120687, "ON"],
|
|
899
|
+
[120713, 120713, "ON"],
|
|
900
|
+
[120745, 120745, "ON"],
|
|
901
|
+
[120771, 120771, "ON"],
|
|
902
|
+
[120782, 120831, "EN"],
|
|
903
|
+
[121344, 121398, "NSM"],
|
|
904
|
+
[121403, 121452, "NSM"],
|
|
905
|
+
[121461, 121461, "NSM"],
|
|
906
|
+
[121476, 121476, "NSM"],
|
|
907
|
+
[121499, 121503, "NSM"],
|
|
908
|
+
[121505, 121519, "NSM"],
|
|
909
|
+
[122880, 122886, "NSM"],
|
|
910
|
+
[122888, 122904, "NSM"],
|
|
911
|
+
[122907, 122913, "NSM"],
|
|
912
|
+
[122915, 122916, "NSM"],
|
|
913
|
+
[122918, 122922, "NSM"],
|
|
914
|
+
[123023, 123023, "NSM"],
|
|
915
|
+
[123184, 123190, "NSM"],
|
|
916
|
+
[123566, 123566, "NSM"],
|
|
917
|
+
[123628, 123631, "NSM"],
|
|
918
|
+
[123647, 123647, "ET"],
|
|
919
|
+
[124140, 124143, "NSM"],
|
|
920
|
+
[124398, 124399, "NSM"],
|
|
921
|
+
[124643, 124643, "NSM"],
|
|
922
|
+
[124646, 124646, "NSM"],
|
|
923
|
+
[124654, 124655, "NSM"],
|
|
924
|
+
[124661, 124661, "NSM"],
|
|
925
|
+
[124928, 125135, "R"],
|
|
926
|
+
[125136, 125142, "NSM"],
|
|
927
|
+
[125143, 125251, "R"],
|
|
928
|
+
[125252, 125258, "NSM"],
|
|
929
|
+
[125259, 126063, "R"],
|
|
930
|
+
[126064, 126143, "AL"],
|
|
931
|
+
[126144, 126207, "R"],
|
|
932
|
+
[126208, 126287, "AL"],
|
|
933
|
+
[126288, 126463, "R"],
|
|
934
|
+
[126464, 126703, "AL"],
|
|
935
|
+
[126704, 126705, "ON"],
|
|
936
|
+
[126706, 126719, "AL"],
|
|
937
|
+
[126720, 126975, "R"],
|
|
938
|
+
[126976, 127019, "ON"],
|
|
939
|
+
[127024, 127123, "ON"],
|
|
940
|
+
[127136, 127150, "ON"],
|
|
941
|
+
[127153, 127167, "ON"],
|
|
942
|
+
[127169, 127183, "ON"],
|
|
943
|
+
[127185, 127221, "ON"],
|
|
944
|
+
[127232, 127242, "EN"],
|
|
945
|
+
[127243, 127247, "ON"],
|
|
946
|
+
[127279, 127279, "ON"],
|
|
947
|
+
[127338, 127343, "ON"],
|
|
948
|
+
[127405, 127405, "ON"],
|
|
949
|
+
[127584, 127589, "ON"],
|
|
950
|
+
[127744, 128728, "ON"],
|
|
951
|
+
[128732, 128748, "ON"],
|
|
952
|
+
[128752, 128764, "ON"],
|
|
953
|
+
[128768, 128985, "ON"],
|
|
954
|
+
[128992, 129003, "ON"],
|
|
955
|
+
[129008, 129008, "ON"],
|
|
956
|
+
[129024, 129035, "ON"],
|
|
957
|
+
[129040, 129095, "ON"],
|
|
958
|
+
[129104, 129113, "ON"],
|
|
959
|
+
[129120, 129159, "ON"],
|
|
960
|
+
[129168, 129197, "ON"],
|
|
961
|
+
[129200, 129211, "ON"],
|
|
962
|
+
[129216, 129217, "ON"],
|
|
963
|
+
[129232, 129240, "ON"],
|
|
964
|
+
[129280, 129623, "ON"],
|
|
965
|
+
[129632, 129645, "ON"],
|
|
966
|
+
[129648, 129660, "ON"],
|
|
967
|
+
[129664, 129674, "ON"],
|
|
968
|
+
[129678, 129734, "ON"],
|
|
969
|
+
[129736, 129736, "ON"],
|
|
970
|
+
[129741, 129756, "ON"],
|
|
971
|
+
[129759, 129770, "ON"],
|
|
972
|
+
[129775, 129784, "ON"],
|
|
973
|
+
[129792, 129938, "ON"],
|
|
974
|
+
[129940, 130031, "ON"],
|
|
975
|
+
[130032, 130041, "EN"],
|
|
976
|
+
[130042, 130042, "ON"],
|
|
977
|
+
[131070, 131071, "BN"],
|
|
978
|
+
[196606, 196607, "BN"],
|
|
979
|
+
[262142, 262143, "BN"],
|
|
980
|
+
[327678, 327679, "BN"],
|
|
981
|
+
[393214, 393215, "BN"],
|
|
982
|
+
[458750, 458751, "BN"],
|
|
983
|
+
[524286, 524287, "BN"],
|
|
984
|
+
[589822, 589823, "BN"],
|
|
985
|
+
[655358, 655359, "BN"],
|
|
986
|
+
[720894, 720895, "BN"],
|
|
987
|
+
[786430, 786431, "BN"],
|
|
988
|
+
[851966, 851967, "BN"],
|
|
989
|
+
[917502, 917759, "BN"],
|
|
990
|
+
[917760, 917999, "NSM"],
|
|
991
|
+
[918000, 921599, "BN"],
|
|
992
|
+
[983038, 983039, "BN"],
|
|
993
|
+
[1048574, 1048575, "BN"],
|
|
994
|
+
[1114110, 1114111, "BN"]
|
|
995
|
+
];
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/bidi.js
|
|
999
|
+
function classifyCodePoint(codePoint) {
|
|
1000
|
+
if (codePoint <= 255)
|
|
1001
|
+
return latin1BidiTypes[codePoint];
|
|
1002
|
+
let lo = 0;
|
|
1003
|
+
let hi = nonLatin1BidiRanges.length - 1;
|
|
1004
|
+
while (lo <= hi) {
|
|
1005
|
+
const mid = lo + hi >> 1;
|
|
1006
|
+
const range = nonLatin1BidiRanges[mid];
|
|
1007
|
+
if (codePoint < range[0]) {
|
|
1008
|
+
hi = mid - 1;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (codePoint > range[1]) {
|
|
1012
|
+
lo = mid + 1;
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
return range[2];
|
|
1016
|
+
}
|
|
1017
|
+
return "L";
|
|
1018
|
+
}
|
|
1019
|
+
function computeBidiLevels(str) {
|
|
1020
|
+
const len = str.length;
|
|
1021
|
+
if (len === 0)
|
|
1022
|
+
return null;
|
|
1023
|
+
const types = new Array(len);
|
|
1024
|
+
let sawBidi = false;
|
|
1025
|
+
for (let i = 0;i < len; ) {
|
|
1026
|
+
const first = str.charCodeAt(i);
|
|
1027
|
+
let codePoint = first;
|
|
1028
|
+
let codeUnitLength = 1;
|
|
1029
|
+
if (first >= 55296 && first <= 56319 && i + 1 < len) {
|
|
1030
|
+
const second = str.charCodeAt(i + 1);
|
|
1031
|
+
if (second >= 56320 && second <= 57343) {
|
|
1032
|
+
codePoint = (first - 55296 << 10) + (second - 56320) + 65536;
|
|
1033
|
+
codeUnitLength = 2;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
const t = classifyCodePoint(codePoint);
|
|
1037
|
+
if (t === "R" || t === "AL" || t === "AN")
|
|
1038
|
+
sawBidi = true;
|
|
1039
|
+
for (let j = 0;j < codeUnitLength; j++) {
|
|
1040
|
+
types[i + j] = t;
|
|
1041
|
+
}
|
|
1042
|
+
i += codeUnitLength;
|
|
1043
|
+
}
|
|
1044
|
+
if (!sawBidi)
|
|
1045
|
+
return null;
|
|
1046
|
+
let startLevel = 0;
|
|
1047
|
+
for (let i = 0;i < len; i++) {
|
|
1048
|
+
const t = types[i];
|
|
1049
|
+
if (t === "L") {
|
|
1050
|
+
startLevel = 0;
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
if (t === "R" || t === "AL") {
|
|
1054
|
+
startLevel = 1;
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const levels = new Int8Array(len);
|
|
1059
|
+
for (let i = 0;i < len; i++)
|
|
1060
|
+
levels[i] = startLevel;
|
|
1061
|
+
const e = startLevel & 1 ? "R" : "L";
|
|
1062
|
+
const sor = e;
|
|
1063
|
+
let lastType = sor;
|
|
1064
|
+
for (let i = 0;i < len; i++) {
|
|
1065
|
+
if (types[i] === "NSM")
|
|
1066
|
+
types[i] = lastType;
|
|
1067
|
+
else
|
|
1068
|
+
lastType = types[i];
|
|
1069
|
+
}
|
|
1070
|
+
lastType = sor;
|
|
1071
|
+
for (let i = 0;i < len; i++) {
|
|
1072
|
+
const t = types[i];
|
|
1073
|
+
if (t === "EN")
|
|
1074
|
+
types[i] = lastType === "AL" ? "AN" : "EN";
|
|
1075
|
+
else if (t === "R" || t === "L" || t === "AL")
|
|
1076
|
+
lastType = t;
|
|
1077
|
+
}
|
|
1078
|
+
for (let i = 0;i < len; i++) {
|
|
1079
|
+
if (types[i] === "AL")
|
|
1080
|
+
types[i] = "R";
|
|
1081
|
+
}
|
|
1082
|
+
for (let i = 1;i < len - 1; i++) {
|
|
1083
|
+
if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
|
|
1084
|
+
types[i] = "EN";
|
|
1085
|
+
}
|
|
1086
|
+
if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
|
|
1087
|
+
types[i] = types[i - 1];
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
for (let i = 0;i < len; i++) {
|
|
1091
|
+
if (types[i] !== "EN")
|
|
1092
|
+
continue;
|
|
1093
|
+
let j;
|
|
1094
|
+
for (j = i - 1;j >= 0 && types[j] === "ET"; j--)
|
|
1095
|
+
types[j] = "EN";
|
|
1096
|
+
for (j = i + 1;j < len && types[j] === "ET"; j++)
|
|
1097
|
+
types[j] = "EN";
|
|
1098
|
+
}
|
|
1099
|
+
for (let i = 0;i < len; i++) {
|
|
1100
|
+
const t = types[i];
|
|
1101
|
+
if (t === "WS" || t === "ES" || t === "ET" || t === "CS")
|
|
1102
|
+
types[i] = "ON";
|
|
1103
|
+
}
|
|
1104
|
+
lastType = sor;
|
|
1105
|
+
for (let i = 0;i < len; i++) {
|
|
1106
|
+
const t = types[i];
|
|
1107
|
+
if (t === "EN")
|
|
1108
|
+
types[i] = lastType === "L" ? "L" : "EN";
|
|
1109
|
+
else if (t === "R" || t === "L")
|
|
1110
|
+
lastType = t;
|
|
1111
|
+
}
|
|
1112
|
+
for (let i = 0;i < len; i++) {
|
|
1113
|
+
if (types[i] !== "ON")
|
|
1114
|
+
continue;
|
|
1115
|
+
let end = i + 1;
|
|
1116
|
+
while (end < len && types[end] === "ON")
|
|
1117
|
+
end++;
|
|
1118
|
+
const before = i > 0 ? types[i - 1] : sor;
|
|
1119
|
+
const after = end < len ? types[end] : sor;
|
|
1120
|
+
const bDir = before !== "L" ? "R" : "L";
|
|
1121
|
+
const aDir = after !== "L" ? "R" : "L";
|
|
1122
|
+
if (bDir === aDir) {
|
|
1123
|
+
for (let j = i;j < end; j++)
|
|
1124
|
+
types[j] = bDir;
|
|
1125
|
+
}
|
|
1126
|
+
i = end - 1;
|
|
1127
|
+
}
|
|
1128
|
+
for (let i = 0;i < len; i++) {
|
|
1129
|
+
if (types[i] === "ON")
|
|
1130
|
+
types[i] = e;
|
|
1131
|
+
}
|
|
1132
|
+
for (let i = 0;i < len; i++) {
|
|
1133
|
+
const t = types[i];
|
|
1134
|
+
if ((levels[i] & 1) === 0) {
|
|
1135
|
+
if (t === "R")
|
|
1136
|
+
levels[i]++;
|
|
1137
|
+
else if (t === "AN" || t === "EN")
|
|
1138
|
+
levels[i] += 2;
|
|
1139
|
+
} else if (t === "L" || t === "AN" || t === "EN") {
|
|
1140
|
+
levels[i]++;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return levels;
|
|
1144
|
+
}
|
|
1145
|
+
function computeSegmentLevels(normalized, segStarts) {
|
|
1146
|
+
const bidiLevels = computeBidiLevels(normalized);
|
|
1147
|
+
if (bidiLevels === null)
|
|
1148
|
+
return null;
|
|
1149
|
+
const segLevels = new Int8Array(segStarts.length);
|
|
1150
|
+
for (let i = 0;i < segStarts.length; i++) {
|
|
1151
|
+
segLevels[i] = bidiLevels[segStarts[i]];
|
|
1152
|
+
}
|
|
1153
|
+
return segLevels;
|
|
1154
|
+
}
|
|
1155
|
+
var init_bidi = __esm(() => {
|
|
1156
|
+
init_bidi_data();
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/analysis.js
|
|
1160
|
+
function getWhiteSpaceProfile(whiteSpace) {
|
|
1161
|
+
const mode = whiteSpace ?? "normal";
|
|
1162
|
+
return mode === "pre-wrap" ? { mode, preserveOrdinarySpaces: true, preserveHardBreaks: true } : { mode, preserveOrdinarySpaces: false, preserveHardBreaks: false };
|
|
1163
|
+
}
|
|
1164
|
+
function normalizeWhitespaceNormal(text) {
|
|
1165
|
+
if (!needsWhitespaceNormalizationRe.test(text))
|
|
1166
|
+
return text;
|
|
1167
|
+
let normalized = text.replace(collapsibleWhitespaceRunRe, " ");
|
|
1168
|
+
if (normalized.charCodeAt(0) === 32) {
|
|
1169
|
+
normalized = normalized.slice(1);
|
|
1170
|
+
}
|
|
1171
|
+
if (normalized.length > 0 && normalized.charCodeAt(normalized.length - 1) === 32) {
|
|
1172
|
+
normalized = normalized.slice(0, -1);
|
|
1173
|
+
}
|
|
1174
|
+
return normalized;
|
|
1175
|
+
}
|
|
1176
|
+
function normalizeWhitespacePreWrap(text) {
|
|
1177
|
+
if (!/[\r\f]/.test(text))
|
|
1178
|
+
return text;
|
|
1179
|
+
return text.replace(/\r\n/g, `
|
|
1180
|
+
`).replace(/[\r\f]/g, `
|
|
1181
|
+
`);
|
|
1182
|
+
}
|
|
1183
|
+
function getSharedWordSegmenter() {
|
|
1184
|
+
if (sharedWordSegmenter === null) {
|
|
1185
|
+
sharedWordSegmenter = new Intl.Segmenter(segmenterLocale, { granularity: "word" });
|
|
1186
|
+
}
|
|
1187
|
+
return sharedWordSegmenter;
|
|
1188
|
+
}
|
|
1189
|
+
function clearAnalysisCaches() {
|
|
1190
|
+
sharedWordSegmenter = null;
|
|
1191
|
+
}
|
|
1192
|
+
function setAnalysisLocale(locale) {
|
|
1193
|
+
const nextLocale = locale && locale.length > 0 ? locale : undefined;
|
|
1194
|
+
if (segmenterLocale === nextLocale)
|
|
1195
|
+
return;
|
|
1196
|
+
segmenterLocale = nextLocale;
|
|
1197
|
+
sharedWordSegmenter = null;
|
|
1198
|
+
}
|
|
1199
|
+
function containsArabicScript(text) {
|
|
1200
|
+
return arabicScriptRe.test(text);
|
|
1201
|
+
}
|
|
1202
|
+
function isCJKCodePoint(codePoint) {
|
|
1203
|
+
return codePoint >= 19968 && codePoint <= 40959 || codePoint >= 13312 && codePoint <= 19903 || codePoint >= 131072 && codePoint <= 173791 || codePoint >= 173824 && codePoint <= 177983 || codePoint >= 177984 && codePoint <= 178207 || codePoint >= 178208 && codePoint <= 183983 || codePoint >= 183984 && codePoint <= 191471 || codePoint >= 191472 && codePoint <= 192093 || codePoint >= 194560 && codePoint <= 195103 || codePoint >= 196608 && codePoint <= 201551 || codePoint >= 201552 && codePoint <= 205743 || codePoint >= 205744 && codePoint <= 210041 || codePoint >= 63744 && codePoint <= 64255 || codePoint >= 12288 && codePoint <= 12351 || codePoint >= 12352 && codePoint <= 12447 || codePoint >= 12448 && codePoint <= 12543 || codePoint >= 12592 && codePoint <= 12687 || codePoint >= 44032 && codePoint <= 55215 || codePoint >= 65280 && codePoint <= 65519;
|
|
1204
|
+
}
|
|
1205
|
+
function isCJK(s) {
|
|
1206
|
+
for (let i = 0;i < s.length; i++) {
|
|
1207
|
+
const first = s.charCodeAt(i);
|
|
1208
|
+
if (first < 12288)
|
|
1209
|
+
continue;
|
|
1210
|
+
if (first >= 55296 && first <= 56319 && i + 1 < s.length) {
|
|
1211
|
+
const second = s.charCodeAt(i + 1);
|
|
1212
|
+
if (second >= 56320 && second <= 57343) {
|
|
1213
|
+
const codePoint = (first - 55296 << 10) + (second - 56320) + 65536;
|
|
1214
|
+
if (isCJKCodePoint(codePoint))
|
|
1215
|
+
return true;
|
|
1216
|
+
i++;
|
|
1217
|
+
continue;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
if (isCJKCodePoint(first))
|
|
1221
|
+
return true;
|
|
1222
|
+
}
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
function endsWithLineStartProhibitedText(text) {
|
|
1226
|
+
const last = getLastCodePoint(text);
|
|
1227
|
+
return last !== null && (kinsokuStart.has(last) || leftStickyPunctuation.has(last));
|
|
1228
|
+
}
|
|
1229
|
+
function endsWithKeepAllGlueText(text) {
|
|
1230
|
+
const last = getLastCodePoint(text);
|
|
1231
|
+
return last !== null && keepAllGlueChars.has(last);
|
|
1232
|
+
}
|
|
1233
|
+
function endsWithKeepAllDashBreakText(text) {
|
|
1234
|
+
const last = getLastCodePoint(text);
|
|
1235
|
+
return last !== null && keepAllDashBreakChars.has(last);
|
|
1236
|
+
}
|
|
1237
|
+
function canContinueKeepAllTextRun(previousText, breakAfterPunctuation) {
|
|
1238
|
+
if (endsWithKeepAllGlueText(previousText))
|
|
1239
|
+
return false;
|
|
1240
|
+
if (!breakAfterPunctuation)
|
|
1241
|
+
return true;
|
|
1242
|
+
if (endsWithLineStartProhibitedText(previousText))
|
|
1243
|
+
return false;
|
|
1244
|
+
if (endsWithKeepAllDashBreakText(previousText))
|
|
1245
|
+
return false;
|
|
1246
|
+
return true;
|
|
1247
|
+
}
|
|
1248
|
+
function isLeftStickyPunctuationSegment(segment) {
|
|
1249
|
+
if (isEscapedQuoteClusterSegment(segment))
|
|
1250
|
+
return true;
|
|
1251
|
+
let sawPunctuation = false;
|
|
1252
|
+
for (const ch of segment) {
|
|
1253
|
+
if (leftStickyPunctuation.has(ch) || isLineBreakNumericAffix(ch)) {
|
|
1254
|
+
sawPunctuation = true;
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
if (sawPunctuation && combiningMarkRe.test(ch))
|
|
1258
|
+
continue;
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
return sawPunctuation;
|
|
1262
|
+
}
|
|
1263
|
+
function isCJKLineStartProhibitedSegment(segment) {
|
|
1264
|
+
for (const ch of segment) {
|
|
1265
|
+
if (!kinsokuStart.has(ch) && !leftStickyPunctuation.has(ch))
|
|
1266
|
+
return false;
|
|
1267
|
+
}
|
|
1268
|
+
return segment.length > 0;
|
|
1269
|
+
}
|
|
1270
|
+
function isForwardStickyClusterSegment(segment) {
|
|
1271
|
+
if (isEscapedQuoteClusterSegment(segment))
|
|
1272
|
+
return true;
|
|
1273
|
+
for (const ch of segment) {
|
|
1274
|
+
if (!kinsokuEnd.has(ch) && !forwardStickyGlue.has(ch) && !combiningMarkRe.test(ch) && !isLineBreakNumericAffix(ch)) {
|
|
1275
|
+
return false;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return segment.length > 0;
|
|
1279
|
+
}
|
|
1280
|
+
function isEscapedQuoteClusterSegment(segment) {
|
|
1281
|
+
let sawQuote = false;
|
|
1282
|
+
for (const ch of segment) {
|
|
1283
|
+
if (ch === "\\" || combiningMarkRe.test(ch))
|
|
1284
|
+
continue;
|
|
1285
|
+
if (kinsokuEnd.has(ch) || leftStickyPunctuation.has(ch) || forwardStickyGlue.has(ch)) {
|
|
1286
|
+
sawQuote = true;
|
|
1287
|
+
continue;
|
|
1288
|
+
}
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
return sawQuote;
|
|
1292
|
+
}
|
|
1293
|
+
function previousCodePointStart(text, end) {
|
|
1294
|
+
const last = end - 1;
|
|
1295
|
+
if (last <= 0)
|
|
1296
|
+
return Math.max(last, 0);
|
|
1297
|
+
const lastCodeUnit = text.charCodeAt(last);
|
|
1298
|
+
if (lastCodeUnit < 56320 || lastCodeUnit > 57343)
|
|
1299
|
+
return last;
|
|
1300
|
+
const maybeHigh = last - 1;
|
|
1301
|
+
if (maybeHigh < 0)
|
|
1302
|
+
return last;
|
|
1303
|
+
const highCodeUnit = text.charCodeAt(maybeHigh);
|
|
1304
|
+
return highCodeUnit >= 55296 && highCodeUnit <= 56319 ? maybeHigh : last;
|
|
1305
|
+
}
|
|
1306
|
+
function getLastCodePoint(text) {
|
|
1307
|
+
if (text.length === 0)
|
|
1308
|
+
return null;
|
|
1309
|
+
const start = previousCodePointStart(text, text.length);
|
|
1310
|
+
return text.slice(start);
|
|
1311
|
+
}
|
|
1312
|
+
function getFirstSignificantCodePoint(text) {
|
|
1313
|
+
for (const ch of text) {
|
|
1314
|
+
if (!combiningMarkRe.test(ch))
|
|
1315
|
+
return ch;
|
|
1316
|
+
}
|
|
1317
|
+
return null;
|
|
1318
|
+
}
|
|
1319
|
+
function getLastSignificantCodePoint(text) {
|
|
1320
|
+
for (let end = text.length;end > 0; ) {
|
|
1321
|
+
const start = previousCodePointStart(text, end);
|
|
1322
|
+
const ch = text.slice(start, end);
|
|
1323
|
+
if (!combiningMarkRe.test(ch))
|
|
1324
|
+
return ch;
|
|
1325
|
+
end = start;
|
|
1326
|
+
}
|
|
1327
|
+
return null;
|
|
1328
|
+
}
|
|
1329
|
+
function isCodePointInRanges(codePoint, ranges) {
|
|
1330
|
+
for (let i = 0;i < ranges.length; i += 2) {
|
|
1331
|
+
if (codePoint >= ranges[i] && codePoint <= ranges[i + 1])
|
|
1332
|
+
return true;
|
|
1333
|
+
}
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
function isLineBreakNumericAffix(ch) {
|
|
1337
|
+
const codePoint = ch.codePointAt(0);
|
|
1338
|
+
return codePoint !== undefined && isCodePointInRanges(codePoint, lineBreakNumericAffixRanges);
|
|
1339
|
+
}
|
|
1340
|
+
function endsWithLineBreakNumericAffix(text) {
|
|
1341
|
+
const last = getLastSignificantCodePoint(text);
|
|
1342
|
+
return last !== null && isLineBreakNumericAffix(last);
|
|
1343
|
+
}
|
|
1344
|
+
function startsWithDecimalDigit(text) {
|
|
1345
|
+
const first = getFirstSignificantCodePoint(text);
|
|
1346
|
+
return first !== null && decimalDigitRe.test(first);
|
|
1347
|
+
}
|
|
1348
|
+
function splitTrailingForwardStickyCluster(text) {
|
|
1349
|
+
const chars = Array.from(text);
|
|
1350
|
+
let splitIndex = chars.length;
|
|
1351
|
+
while (splitIndex > 0) {
|
|
1352
|
+
const ch = chars[splitIndex - 1];
|
|
1353
|
+
if (combiningMarkRe.test(ch)) {
|
|
1354
|
+
splitIndex--;
|
|
1355
|
+
continue;
|
|
1356
|
+
}
|
|
1357
|
+
if (kinsokuEnd.has(ch) || forwardStickyGlue.has(ch)) {
|
|
1358
|
+
splitIndex--;
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
if (splitIndex <= 0 || splitIndex === chars.length)
|
|
1364
|
+
return null;
|
|
1365
|
+
return {
|
|
1366
|
+
head: chars.slice(0, splitIndex).join(""),
|
|
1367
|
+
tail: chars.slice(splitIndex).join("")
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
function getRepeatableSingleCharRunChar(text, isWordLike, kind) {
|
|
1371
|
+
return kind === "text" && !isWordLike && text.length === 1 && text !== "-" && text !== "\u2014" ? text : null;
|
|
1372
|
+
}
|
|
1373
|
+
function materializeDeferredSingleCharRun(texts, chars, lengths, index) {
|
|
1374
|
+
const ch = chars[index];
|
|
1375
|
+
const text = texts[index];
|
|
1376
|
+
if (ch == null)
|
|
1377
|
+
return text;
|
|
1378
|
+
const length = lengths[index];
|
|
1379
|
+
if (text.length === length)
|
|
1380
|
+
return text;
|
|
1381
|
+
const materialized = ch.repeat(length);
|
|
1382
|
+
texts[index] = materialized;
|
|
1383
|
+
return materialized;
|
|
1384
|
+
}
|
|
1385
|
+
function hasArabicNoSpacePunctuation(containsArabic, lastCodePoint) {
|
|
1386
|
+
return containsArabic && lastCodePoint !== null && arabicNoSpaceTrailingPunctuation.has(lastCodePoint);
|
|
1387
|
+
}
|
|
1388
|
+
function endsWithMyanmarMedialGlue(segment) {
|
|
1389
|
+
const lastCodePoint = getLastCodePoint(segment);
|
|
1390
|
+
return lastCodePoint !== null && myanmarMedialGlue.has(lastCodePoint);
|
|
1391
|
+
}
|
|
1392
|
+
function splitLeadingSpaceAndMarks(segment) {
|
|
1393
|
+
if (segment.length < 2 || segment[0] !== " ")
|
|
1394
|
+
return null;
|
|
1395
|
+
const marks = segment.slice(1);
|
|
1396
|
+
if (/^\p{M}+$/u.test(marks)) {
|
|
1397
|
+
return { space: " ", marks };
|
|
1398
|
+
}
|
|
1399
|
+
return null;
|
|
1400
|
+
}
|
|
1401
|
+
function endsWithClosingQuote(text) {
|
|
1402
|
+
let end = text.length;
|
|
1403
|
+
while (end > 0) {
|
|
1404
|
+
const start = previousCodePointStart(text, end);
|
|
1405
|
+
const ch = text.slice(start, end);
|
|
1406
|
+
if (closingQuoteChars.has(ch))
|
|
1407
|
+
return true;
|
|
1408
|
+
if (!leftStickyPunctuation.has(ch))
|
|
1409
|
+
return false;
|
|
1410
|
+
end = start;
|
|
1411
|
+
}
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1414
|
+
function classifySegmentBreakChar(ch, whiteSpaceProfile) {
|
|
1415
|
+
if (whiteSpaceProfile.preserveOrdinarySpaces || whiteSpaceProfile.preserveHardBreaks) {
|
|
1416
|
+
if (ch === " ")
|
|
1417
|
+
return "preserved-space";
|
|
1418
|
+
if (ch === "\t")
|
|
1419
|
+
return "tab";
|
|
1420
|
+
if (whiteSpaceProfile.preserveHardBreaks && ch === `
|
|
1421
|
+
`)
|
|
1422
|
+
return "hard-break";
|
|
1423
|
+
}
|
|
1424
|
+
if (ch === " ")
|
|
1425
|
+
return "space";
|
|
1426
|
+
if (ch === "\xA0" || ch === "\u202F" || ch === "\u2060" || ch === "\uFEFF") {
|
|
1427
|
+
return "glue";
|
|
1428
|
+
}
|
|
1429
|
+
if (ch === "\u200B")
|
|
1430
|
+
return "zero-width-break";
|
|
1431
|
+
if (ch === "\xAD")
|
|
1432
|
+
return "soft-hyphen";
|
|
1433
|
+
return "text";
|
|
1434
|
+
}
|
|
1435
|
+
function joinTextParts(parts) {
|
|
1436
|
+
return parts.length === 1 ? parts[0] : parts.join("");
|
|
1437
|
+
}
|
|
1438
|
+
function joinReversedPrefixParts(prefixParts, tail) {
|
|
1439
|
+
const parts = [];
|
|
1440
|
+
for (let i = prefixParts.length - 1;i >= 0; i--) {
|
|
1441
|
+
parts.push(prefixParts[i]);
|
|
1442
|
+
}
|
|
1443
|
+
parts.push(tail);
|
|
1444
|
+
return joinTextParts(parts);
|
|
1445
|
+
}
|
|
1446
|
+
function splitSegmentByBreakKind(segment, isWordLike, start, whiteSpaceProfile) {
|
|
1447
|
+
if (!breakCharRe.test(segment)) {
|
|
1448
|
+
return [{ text: segment, isWordLike, kind: "text", start }];
|
|
1449
|
+
}
|
|
1450
|
+
const pieces = [];
|
|
1451
|
+
let currentKind = null;
|
|
1452
|
+
let currentTextParts = [];
|
|
1453
|
+
let currentStart = start;
|
|
1454
|
+
let currentWordLike = false;
|
|
1455
|
+
let offset = 0;
|
|
1456
|
+
for (const ch of segment) {
|
|
1457
|
+
const kind = classifySegmentBreakChar(ch, whiteSpaceProfile);
|
|
1458
|
+
const wordLike = kind === "text" && isWordLike;
|
|
1459
|
+
if (currentKind !== null && kind === currentKind && wordLike === currentWordLike) {
|
|
1460
|
+
currentTextParts.push(ch);
|
|
1461
|
+
offset += ch.length;
|
|
1462
|
+
continue;
|
|
1463
|
+
}
|
|
1464
|
+
if (currentKind !== null) {
|
|
1465
|
+
pieces.push({
|
|
1466
|
+
text: joinTextParts(currentTextParts),
|
|
1467
|
+
isWordLike: currentWordLike,
|
|
1468
|
+
kind: currentKind,
|
|
1469
|
+
start: currentStart
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
currentKind = kind;
|
|
1473
|
+
currentTextParts = [ch];
|
|
1474
|
+
currentStart = start + offset;
|
|
1475
|
+
currentWordLike = wordLike;
|
|
1476
|
+
offset += ch.length;
|
|
1477
|
+
}
|
|
1478
|
+
if (currentKind !== null) {
|
|
1479
|
+
pieces.push({
|
|
1480
|
+
text: joinTextParts(currentTextParts),
|
|
1481
|
+
isWordLike: currentWordLike,
|
|
1482
|
+
kind: currentKind,
|
|
1483
|
+
start: currentStart
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
return pieces;
|
|
1487
|
+
}
|
|
1488
|
+
function isTextRunBoundary(kind) {
|
|
1489
|
+
return kind === "space" || kind === "preserved-space" || kind === "zero-width-break" || kind === "hard-break";
|
|
1490
|
+
}
|
|
1491
|
+
function isUrlLikeRunStart(segmentation, index) {
|
|
1492
|
+
const text = segmentation.texts[index];
|
|
1493
|
+
if (text.startsWith("www."))
|
|
1494
|
+
return true;
|
|
1495
|
+
return urlSchemeSegmentRe.test(text) && index + 1 < segmentation.len && segmentation.kinds[index + 1] === "text" && segmentation.texts[index + 1] === "//";
|
|
1496
|
+
}
|
|
1497
|
+
function isUrlQueryBoundarySegment(text) {
|
|
1498
|
+
return text.includes("?") && (text.includes("://") || text.startsWith("www."));
|
|
1499
|
+
}
|
|
1500
|
+
function mergeUrlLikeRuns(segmentation) {
|
|
1501
|
+
const texts = segmentation.texts.slice();
|
|
1502
|
+
const isWordLike = segmentation.isWordLike.slice();
|
|
1503
|
+
const kinds = segmentation.kinds.slice();
|
|
1504
|
+
const starts = segmentation.starts.slice();
|
|
1505
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
1506
|
+
if (kinds[i] !== "text" || !isUrlLikeRunStart(segmentation, i))
|
|
1507
|
+
continue;
|
|
1508
|
+
const mergedParts = [texts[i]];
|
|
1509
|
+
let j = i + 1;
|
|
1510
|
+
while (j < segmentation.len && !isTextRunBoundary(kinds[j])) {
|
|
1511
|
+
mergedParts.push(texts[j]);
|
|
1512
|
+
isWordLike[i] = true;
|
|
1513
|
+
const endsQueryPrefix = texts[j].includes("?");
|
|
1514
|
+
kinds[j] = "text";
|
|
1515
|
+
texts[j] = "";
|
|
1516
|
+
j++;
|
|
1517
|
+
if (endsQueryPrefix)
|
|
1518
|
+
break;
|
|
1519
|
+
}
|
|
1520
|
+
texts[i] = joinTextParts(mergedParts);
|
|
1521
|
+
}
|
|
1522
|
+
let compactLen = 0;
|
|
1523
|
+
for (let read = 0;read < texts.length; read++) {
|
|
1524
|
+
const text = texts[read];
|
|
1525
|
+
if (text.length === 0)
|
|
1526
|
+
continue;
|
|
1527
|
+
if (compactLen !== read) {
|
|
1528
|
+
texts[compactLen] = text;
|
|
1529
|
+
isWordLike[compactLen] = isWordLike[read];
|
|
1530
|
+
kinds[compactLen] = kinds[read];
|
|
1531
|
+
starts[compactLen] = starts[read];
|
|
1532
|
+
}
|
|
1533
|
+
compactLen++;
|
|
1534
|
+
}
|
|
1535
|
+
texts.length = compactLen;
|
|
1536
|
+
isWordLike.length = compactLen;
|
|
1537
|
+
kinds.length = compactLen;
|
|
1538
|
+
starts.length = compactLen;
|
|
1539
|
+
return {
|
|
1540
|
+
len: compactLen,
|
|
1541
|
+
texts,
|
|
1542
|
+
isWordLike,
|
|
1543
|
+
kinds,
|
|
1544
|
+
starts
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
function mergeUrlQueryRuns(segmentation) {
|
|
1548
|
+
const texts = [];
|
|
1549
|
+
const isWordLike = [];
|
|
1550
|
+
const kinds = [];
|
|
1551
|
+
const starts = [];
|
|
1552
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
1553
|
+
const text = segmentation.texts[i];
|
|
1554
|
+
texts.push(text);
|
|
1555
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1556
|
+
kinds.push(segmentation.kinds[i]);
|
|
1557
|
+
starts.push(segmentation.starts[i]);
|
|
1558
|
+
if (!isUrlQueryBoundarySegment(text))
|
|
1559
|
+
continue;
|
|
1560
|
+
const nextIndex = i + 1;
|
|
1561
|
+
if (nextIndex >= segmentation.len || isTextRunBoundary(segmentation.kinds[nextIndex])) {
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
const queryParts = [];
|
|
1565
|
+
const queryStart = segmentation.starts[nextIndex];
|
|
1566
|
+
let j = nextIndex;
|
|
1567
|
+
while (j < segmentation.len && !isTextRunBoundary(segmentation.kinds[j])) {
|
|
1568
|
+
queryParts.push(segmentation.texts[j]);
|
|
1569
|
+
j++;
|
|
1570
|
+
}
|
|
1571
|
+
if (queryParts.length > 0) {
|
|
1572
|
+
texts.push(joinTextParts(queryParts));
|
|
1573
|
+
isWordLike.push(true);
|
|
1574
|
+
kinds.push("text");
|
|
1575
|
+
starts.push(queryStart);
|
|
1576
|
+
i = j - 1;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return {
|
|
1580
|
+
len: texts.length,
|
|
1581
|
+
texts,
|
|
1582
|
+
isWordLike,
|
|
1583
|
+
kinds,
|
|
1584
|
+
starts
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
function isAsciiWordInternalSymbolCode(code) {
|
|
1588
|
+
return code >= 33 && code <= 47 && code !== 45 || code >= 58 && code <= 64 && code !== 63 || code >= 91 && code <= 96 || code >= 123 && code <= 126;
|
|
1589
|
+
}
|
|
1590
|
+
function isNoSpaceWordInternalSymbol(ch) {
|
|
1591
|
+
const code = ch.charCodeAt(0);
|
|
1592
|
+
if (code < 128)
|
|
1593
|
+
return isAsciiWordInternalSymbolCode(code);
|
|
1594
|
+
return !noSpaceWordBreakAfterChars.has(ch) && !emojiPresentationRe.test(ch) && wordInternalSymbolRe.test(ch);
|
|
1595
|
+
}
|
|
1596
|
+
function isNoSpaceWordInternalSymbolSegment(text) {
|
|
1597
|
+
let sawSymbol = false;
|
|
1598
|
+
for (const ch of text) {
|
|
1599
|
+
if (combiningMarkRe.test(ch))
|
|
1600
|
+
continue;
|
|
1601
|
+
if (!isNoSpaceWordInternalSymbol(ch))
|
|
1602
|
+
return false;
|
|
1603
|
+
sawSymbol = true;
|
|
1604
|
+
}
|
|
1605
|
+
return sawSymbol;
|
|
1606
|
+
}
|
|
1607
|
+
function endsWithNoSpaceWordJoiner(text) {
|
|
1608
|
+
for (let end = text.length;end > 0; ) {
|
|
1609
|
+
const start = previousCodePointStart(text, end);
|
|
1610
|
+
const ch = text.slice(start, end);
|
|
1611
|
+
if (combiningMarkRe.test(ch)) {
|
|
1612
|
+
end = start;
|
|
1613
|
+
continue;
|
|
1614
|
+
}
|
|
1615
|
+
return isNoSpaceWordInternalSymbol(ch) || isLineBreakNumericAffix(ch);
|
|
1616
|
+
}
|
|
1617
|
+
return false;
|
|
1618
|
+
}
|
|
1619
|
+
function canJoinNoSpaceWordBoundary(leftText, leftWordLike, rightText, rightWordLike) {
|
|
1620
|
+
const leftSymbol = !leftWordLike && isNoSpaceWordInternalSymbolSegment(leftText);
|
|
1621
|
+
const rightSymbol = !rightWordLike && isNoSpaceWordInternalSymbolSegment(rightText);
|
|
1622
|
+
const leftAffix = endsWithLineBreakNumericAffix(leftText);
|
|
1623
|
+
const leftEndsJoiner = (leftWordLike || leftAffix) && endsWithNoSpaceWordJoiner(leftText);
|
|
1624
|
+
if (!leftSymbol && !rightSymbol && !leftEndsJoiner)
|
|
1625
|
+
return false;
|
|
1626
|
+
if (isCJK(leftText) || isCJK(rightText))
|
|
1627
|
+
return false;
|
|
1628
|
+
return (leftWordLike || leftSymbol || leftAffix) && (rightWordLike || rightSymbol);
|
|
1629
|
+
}
|
|
1630
|
+
function segmentContainsDecimalDigit(text) {
|
|
1631
|
+
for (const ch of text) {
|
|
1632
|
+
if (decimalDigitRe.test(ch))
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
function isNumericRunSegment(text) {
|
|
1638
|
+
if (text.length === 0)
|
|
1639
|
+
return false;
|
|
1640
|
+
for (const ch of text) {
|
|
1641
|
+
if (decimalDigitRe.test(ch) || numericJoinerChars.has(ch))
|
|
1642
|
+
continue;
|
|
1643
|
+
return false;
|
|
1644
|
+
}
|
|
1645
|
+
return true;
|
|
1646
|
+
}
|
|
1647
|
+
function mergeNumericRuns(segmentation) {
|
|
1648
|
+
const texts = [];
|
|
1649
|
+
const isWordLike = [];
|
|
1650
|
+
const kinds = [];
|
|
1651
|
+
const starts = [];
|
|
1652
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
1653
|
+
const text = segmentation.texts[i];
|
|
1654
|
+
const kind = segmentation.kinds[i];
|
|
1655
|
+
if (kind === "text" && isNumericRunSegment(text) && segmentContainsDecimalDigit(text)) {
|
|
1656
|
+
const mergedParts = [text];
|
|
1657
|
+
let j = i + 1;
|
|
1658
|
+
while (j < segmentation.len && segmentation.kinds[j] === "text" && isNumericRunSegment(segmentation.texts[j])) {
|
|
1659
|
+
mergedParts.push(segmentation.texts[j]);
|
|
1660
|
+
j++;
|
|
1661
|
+
}
|
|
1662
|
+
texts.push(joinTextParts(mergedParts));
|
|
1663
|
+
isWordLike.push(true);
|
|
1664
|
+
kinds.push("text");
|
|
1665
|
+
starts.push(segmentation.starts[i]);
|
|
1666
|
+
i = j - 1;
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
texts.push(text);
|
|
1670
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1671
|
+
kinds.push(kind);
|
|
1672
|
+
starts.push(segmentation.starts[i]);
|
|
1673
|
+
}
|
|
1674
|
+
return {
|
|
1675
|
+
len: texts.length,
|
|
1676
|
+
texts,
|
|
1677
|
+
isWordLike,
|
|
1678
|
+
kinds,
|
|
1679
|
+
starts
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
function mergeNoSpaceWordChains(segmentation) {
|
|
1683
|
+
const texts = [];
|
|
1684
|
+
const isWordLike = [];
|
|
1685
|
+
const kinds = [];
|
|
1686
|
+
const starts = [];
|
|
1687
|
+
let i = 0;
|
|
1688
|
+
while (i < segmentation.len) {
|
|
1689
|
+
const text = segmentation.texts[i];
|
|
1690
|
+
const kind = segmentation.kinds[i];
|
|
1691
|
+
const wordLike = segmentation.isWordLike[i];
|
|
1692
|
+
if (kind === "text") {
|
|
1693
|
+
const mergedParts = [text];
|
|
1694
|
+
let j = i + 1;
|
|
1695
|
+
let mergedWordLike = wordLike;
|
|
1696
|
+
while (j < segmentation.len && segmentation.kinds[j] === "text" && canJoinNoSpaceWordBoundary(segmentation.texts[j - 1], segmentation.isWordLike[j - 1], segmentation.texts[j], segmentation.isWordLike[j])) {
|
|
1697
|
+
const nextText = segmentation.texts[j];
|
|
1698
|
+
mergedParts.push(nextText);
|
|
1699
|
+
mergedWordLike = mergedWordLike || segmentation.isWordLike[j];
|
|
1700
|
+
j++;
|
|
1701
|
+
}
|
|
1702
|
+
if (j > i + 1) {
|
|
1703
|
+
texts.push(joinTextParts(mergedParts));
|
|
1704
|
+
isWordLike.push(mergedWordLike);
|
|
1705
|
+
kinds.push("text");
|
|
1706
|
+
starts.push(segmentation.starts[i]);
|
|
1707
|
+
i = j;
|
|
1708
|
+
continue;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
texts.push(text);
|
|
1712
|
+
isWordLike.push(wordLike);
|
|
1713
|
+
kinds.push(kind);
|
|
1714
|
+
starts.push(segmentation.starts[i]);
|
|
1715
|
+
i++;
|
|
1716
|
+
}
|
|
1717
|
+
return {
|
|
1718
|
+
len: texts.length,
|
|
1719
|
+
texts,
|
|
1720
|
+
isWordLike,
|
|
1721
|
+
kinds,
|
|
1722
|
+
starts
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
function splitHyphenatedNumericRuns(segmentation) {
|
|
1726
|
+
const texts = [];
|
|
1727
|
+
const isWordLike = [];
|
|
1728
|
+
const kinds = [];
|
|
1729
|
+
const starts = [];
|
|
1730
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
1731
|
+
const text = segmentation.texts[i];
|
|
1732
|
+
if (segmentation.kinds[i] === "text" && text.includes("-")) {
|
|
1733
|
+
const parts = text.split("-");
|
|
1734
|
+
let shouldSplit = parts.length > 1;
|
|
1735
|
+
for (let j = 0;j < parts.length; j++) {
|
|
1736
|
+
const part = parts[j];
|
|
1737
|
+
if (!shouldSplit)
|
|
1738
|
+
break;
|
|
1739
|
+
if (part.length === 0 || !segmentContainsDecimalDigit(part) || !isNumericRunSegment(part)) {
|
|
1740
|
+
shouldSplit = false;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
if (shouldSplit) {
|
|
1744
|
+
let offset = 0;
|
|
1745
|
+
for (let j = 0;j < parts.length; j++) {
|
|
1746
|
+
const part = parts[j];
|
|
1747
|
+
const splitText = j < parts.length - 1 ? `${part}-` : part;
|
|
1748
|
+
texts.push(splitText);
|
|
1749
|
+
isWordLike.push(true);
|
|
1750
|
+
kinds.push("text");
|
|
1751
|
+
starts.push(segmentation.starts[i] + offset);
|
|
1752
|
+
offset += splitText.length;
|
|
1753
|
+
}
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
texts.push(text);
|
|
1758
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
1759
|
+
kinds.push(segmentation.kinds[i]);
|
|
1760
|
+
starts.push(segmentation.starts[i]);
|
|
1761
|
+
}
|
|
1762
|
+
return {
|
|
1763
|
+
len: texts.length,
|
|
1764
|
+
texts,
|
|
1765
|
+
isWordLike,
|
|
1766
|
+
kinds,
|
|
1767
|
+
starts
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
function mergeGlueConnectedTextRuns(segmentation) {
|
|
1771
|
+
const texts = [];
|
|
1772
|
+
const isWordLike = [];
|
|
1773
|
+
const kinds = [];
|
|
1774
|
+
const starts = [];
|
|
1775
|
+
let read = 0;
|
|
1776
|
+
while (read < segmentation.len) {
|
|
1777
|
+
const textParts = [segmentation.texts[read]];
|
|
1778
|
+
let wordLike = segmentation.isWordLike[read];
|
|
1779
|
+
let kind = segmentation.kinds[read];
|
|
1780
|
+
let start = segmentation.starts[read];
|
|
1781
|
+
if (kind === "glue") {
|
|
1782
|
+
const glueParts = [textParts[0]];
|
|
1783
|
+
const glueStart = start;
|
|
1784
|
+
read++;
|
|
1785
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1786
|
+
glueParts.push(segmentation.texts[read]);
|
|
1787
|
+
read++;
|
|
1788
|
+
}
|
|
1789
|
+
const glueText = joinTextParts(glueParts);
|
|
1790
|
+
if (read < segmentation.len && segmentation.kinds[read] === "text") {
|
|
1791
|
+
textParts[0] = glueText;
|
|
1792
|
+
textParts.push(segmentation.texts[read]);
|
|
1793
|
+
wordLike = segmentation.isWordLike[read];
|
|
1794
|
+
kind = "text";
|
|
1795
|
+
start = glueStart;
|
|
1796
|
+
read++;
|
|
1797
|
+
} else {
|
|
1798
|
+
texts.push(glueText);
|
|
1799
|
+
isWordLike.push(false);
|
|
1800
|
+
kinds.push("glue");
|
|
1801
|
+
starts.push(glueStart);
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
} else {
|
|
1805
|
+
read++;
|
|
1806
|
+
}
|
|
1807
|
+
if (kind === "text") {
|
|
1808
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1809
|
+
const glueParts = [];
|
|
1810
|
+
while (read < segmentation.len && segmentation.kinds[read] === "glue") {
|
|
1811
|
+
glueParts.push(segmentation.texts[read]);
|
|
1812
|
+
read++;
|
|
1813
|
+
}
|
|
1814
|
+
const glueText = joinTextParts(glueParts);
|
|
1815
|
+
if (read < segmentation.len && segmentation.kinds[read] === "text") {
|
|
1816
|
+
textParts.push(glueText, segmentation.texts[read]);
|
|
1817
|
+
wordLike = wordLike || segmentation.isWordLike[read];
|
|
1818
|
+
read++;
|
|
1819
|
+
continue;
|
|
1820
|
+
}
|
|
1821
|
+
textParts.push(glueText);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
texts.push(joinTextParts(textParts));
|
|
1825
|
+
isWordLike.push(wordLike);
|
|
1826
|
+
kinds.push(kind);
|
|
1827
|
+
starts.push(start);
|
|
1828
|
+
}
|
|
1829
|
+
return {
|
|
1830
|
+
len: texts.length,
|
|
1831
|
+
texts,
|
|
1832
|
+
isWordLike,
|
|
1833
|
+
kinds,
|
|
1834
|
+
starts
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
function carryTrailingForwardStickyAcrossCJKBoundary(segmentation) {
|
|
1838
|
+
const texts = segmentation.texts.slice();
|
|
1839
|
+
const isWordLike = segmentation.isWordLike.slice();
|
|
1840
|
+
const kinds = segmentation.kinds.slice();
|
|
1841
|
+
const starts = segmentation.starts.slice();
|
|
1842
|
+
for (let i = 0;i < texts.length - 1; i++) {
|
|
1843
|
+
if (kinds[i] !== "text" || kinds[i + 1] !== "text")
|
|
1844
|
+
continue;
|
|
1845
|
+
if (!isCJK(texts[i]) || !isCJK(texts[i + 1]))
|
|
1846
|
+
continue;
|
|
1847
|
+
const split = splitTrailingForwardStickyCluster(texts[i]);
|
|
1848
|
+
if (split === null)
|
|
1849
|
+
continue;
|
|
1850
|
+
texts[i] = split.head;
|
|
1851
|
+
texts[i + 1] = split.tail + texts[i + 1];
|
|
1852
|
+
starts[i + 1] = starts[i] + split.head.length;
|
|
1853
|
+
}
|
|
1854
|
+
return {
|
|
1855
|
+
len: texts.length,
|
|
1856
|
+
texts,
|
|
1857
|
+
isWordLike,
|
|
1858
|
+
kinds,
|
|
1859
|
+
starts
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
function buildMergedSegmentation(normalized, profile, whiteSpaceProfile) {
|
|
1863
|
+
const wordSegmenter = getSharedWordSegmenter();
|
|
1864
|
+
let mergedLen = 0;
|
|
1865
|
+
const mergedTexts = [];
|
|
1866
|
+
const mergedTextParts = [];
|
|
1867
|
+
const mergedWordLike = [];
|
|
1868
|
+
const mergedKinds = [];
|
|
1869
|
+
const mergedStarts = [];
|
|
1870
|
+
const mergedSingleCharRunChars = [];
|
|
1871
|
+
const mergedSingleCharRunLengths = [];
|
|
1872
|
+
const mergedContainsCJK = [];
|
|
1873
|
+
const mergedContainsArabicScript = [];
|
|
1874
|
+
const mergedEndsWithClosingQuote = [];
|
|
1875
|
+
const mergedEndsWithMyanmarMedialGlue = [];
|
|
1876
|
+
const mergedHasArabicNoSpacePunctuation = [];
|
|
1877
|
+
for (const s of wordSegmenter.segment(normalized)) {
|
|
1878
|
+
for (const piece of splitSegmentByBreakKind(s.segment, s.isWordLike ?? false, s.index, whiteSpaceProfile)) {
|
|
1879
|
+
let appendPieceToPrevious = function() {
|
|
1880
|
+
if (mergedSingleCharRunChars[prevIndex] !== null) {
|
|
1881
|
+
mergedTextParts[prevIndex] = [
|
|
1882
|
+
materializeDeferredSingleCharRun(mergedTexts, mergedSingleCharRunChars, mergedSingleCharRunLengths, prevIndex)
|
|
1883
|
+
];
|
|
1884
|
+
mergedSingleCharRunChars[prevIndex] = null;
|
|
1885
|
+
}
|
|
1886
|
+
mergedTextParts[prevIndex].push(piece.text);
|
|
1887
|
+
mergedWordLike[prevIndex] = mergedWordLike[prevIndex] || piece.isWordLike;
|
|
1888
|
+
mergedContainsCJK[prevIndex] = mergedContainsCJK[prevIndex] || pieceContainsCJK;
|
|
1889
|
+
mergedContainsArabicScript[prevIndex] = mergedContainsArabicScript[prevIndex] || pieceContainsArabicScript;
|
|
1890
|
+
mergedEndsWithClosingQuote[prevIndex] = pieceEndsWithClosingQuote;
|
|
1891
|
+
mergedEndsWithMyanmarMedialGlue[prevIndex] = pieceEndsWithMyanmarMedialGlue;
|
|
1892
|
+
mergedHasArabicNoSpacePunctuation[prevIndex] = hasArabicNoSpacePunctuation(mergedContainsArabicScript[prevIndex], pieceLastCodePoint);
|
|
1893
|
+
};
|
|
1894
|
+
const isText = piece.kind === "text";
|
|
1895
|
+
const repeatableSingleCharRunChar = getRepeatableSingleCharRunChar(piece.text, piece.isWordLike, piece.kind);
|
|
1896
|
+
const pieceContainsCJK = isCJK(piece.text);
|
|
1897
|
+
const pieceContainsArabicScript = containsArabicScript(piece.text);
|
|
1898
|
+
const pieceLastCodePoint = getLastCodePoint(piece.text);
|
|
1899
|
+
const pieceEndsWithClosingQuote = endsWithClosingQuote(piece.text);
|
|
1900
|
+
const pieceEndsWithMyanmarMedialGlue = endsWithMyanmarMedialGlue(piece.text);
|
|
1901
|
+
const prevIndex = mergedLen - 1;
|
|
1902
|
+
if (profile.carryCJKAfterClosingQuote && isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && pieceContainsCJK && mergedContainsCJK[prevIndex] && mergedEndsWithClosingQuote[prevIndex]) {
|
|
1903
|
+
appendPieceToPrevious();
|
|
1904
|
+
} else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && isCJKLineStartProhibitedSegment(piece.text) && mergedContainsCJK[prevIndex]) {
|
|
1905
|
+
appendPieceToPrevious();
|
|
1906
|
+
} else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && mergedEndsWithMyanmarMedialGlue[prevIndex]) {
|
|
1907
|
+
appendPieceToPrevious();
|
|
1908
|
+
} else if (isText && mergedLen > 0 && mergedKinds[prevIndex] === "text" && piece.isWordLike && pieceContainsArabicScript && mergedHasArabicNoSpacePunctuation[prevIndex]) {
|
|
1909
|
+
appendPieceToPrevious();
|
|
1910
|
+
mergedWordLike[prevIndex] = true;
|
|
1911
|
+
} else if (repeatableSingleCharRunChar !== null && mergedLen > 0 && mergedKinds[prevIndex] === "text" && mergedSingleCharRunChars[prevIndex] === repeatableSingleCharRunChar) {
|
|
1912
|
+
mergedSingleCharRunLengths[prevIndex] = (mergedSingleCharRunLengths[prevIndex] ?? 1) + 1;
|
|
1913
|
+
} else if (isText && !piece.isWordLike && mergedLen > 0 && mergedKinds[prevIndex] === "text" && !mergedContainsCJK[prevIndex] && (isLeftStickyPunctuationSegment(piece.text) || piece.text === "-" && mergedWordLike[prevIndex])) {
|
|
1914
|
+
appendPieceToPrevious();
|
|
1915
|
+
} else {
|
|
1916
|
+
mergedTexts[mergedLen] = piece.text;
|
|
1917
|
+
mergedTextParts[mergedLen] = [piece.text];
|
|
1918
|
+
mergedWordLike[mergedLen] = piece.isWordLike;
|
|
1919
|
+
mergedKinds[mergedLen] = piece.kind;
|
|
1920
|
+
mergedStarts[mergedLen] = piece.start;
|
|
1921
|
+
mergedSingleCharRunChars[mergedLen] = repeatableSingleCharRunChar;
|
|
1922
|
+
mergedSingleCharRunLengths[mergedLen] = repeatableSingleCharRunChar === null ? 0 : 1;
|
|
1923
|
+
mergedContainsCJK[mergedLen] = pieceContainsCJK;
|
|
1924
|
+
mergedContainsArabicScript[mergedLen] = pieceContainsArabicScript;
|
|
1925
|
+
mergedEndsWithClosingQuote[mergedLen] = pieceEndsWithClosingQuote;
|
|
1926
|
+
mergedEndsWithMyanmarMedialGlue[mergedLen] = pieceEndsWithMyanmarMedialGlue;
|
|
1927
|
+
mergedHasArabicNoSpacePunctuation[mergedLen] = hasArabicNoSpacePunctuation(pieceContainsArabicScript, pieceLastCodePoint);
|
|
1928
|
+
mergedLen++;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
for (let i = 0;i < mergedLen; i++) {
|
|
1933
|
+
if (mergedSingleCharRunChars[i] !== null) {
|
|
1934
|
+
mergedTexts[i] = materializeDeferredSingleCharRun(mergedTexts, mergedSingleCharRunChars, mergedSingleCharRunLengths, i);
|
|
1935
|
+
continue;
|
|
1936
|
+
}
|
|
1937
|
+
mergedTexts[i] = joinTextParts(mergedTextParts[i]);
|
|
1938
|
+
}
|
|
1939
|
+
for (let i = 1;i < mergedLen; i++) {
|
|
1940
|
+
if (mergedKinds[i] === "text" && !mergedWordLike[i] && isEscapedQuoteClusterSegment(mergedTexts[i]) && mergedKinds[i - 1] === "text" && !mergedContainsCJK[i - 1]) {
|
|
1941
|
+
mergedTexts[i - 1] += mergedTexts[i];
|
|
1942
|
+
mergedWordLike[i - 1] = mergedWordLike[i - 1] || mergedWordLike[i];
|
|
1943
|
+
mergedTexts[i] = "";
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
const forwardStickyPrefixParts = Array.from({ length: mergedLen }, () => null);
|
|
1947
|
+
let nextLiveIndex = -1;
|
|
1948
|
+
for (let i = mergedLen - 1;i >= 0; i--) {
|
|
1949
|
+
const text = mergedTexts[i];
|
|
1950
|
+
if (text.length === 0)
|
|
1951
|
+
continue;
|
|
1952
|
+
if (mergedKinds[i] === "text" && !mergedWordLike[i] && nextLiveIndex >= 0 && mergedKinds[nextLiveIndex] === "text" && (isForwardStickyClusterSegment(text) || text === "-" && startsWithDecimalDigit(mergedTexts[nextLiveIndex]))) {
|
|
1953
|
+
const prefixParts = forwardStickyPrefixParts[nextLiveIndex] ?? [];
|
|
1954
|
+
prefixParts.push(text);
|
|
1955
|
+
forwardStickyPrefixParts[nextLiveIndex] = prefixParts;
|
|
1956
|
+
mergedStarts[nextLiveIndex] = mergedStarts[i];
|
|
1957
|
+
mergedTexts[i] = "";
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
nextLiveIndex = i;
|
|
1961
|
+
}
|
|
1962
|
+
for (let i = 0;i < mergedLen; i++) {
|
|
1963
|
+
const prefixParts = forwardStickyPrefixParts[i];
|
|
1964
|
+
if (prefixParts == null)
|
|
1965
|
+
continue;
|
|
1966
|
+
mergedTexts[i] = joinReversedPrefixParts(prefixParts, mergedTexts[i]);
|
|
1967
|
+
}
|
|
1968
|
+
let compactLen = 0;
|
|
1969
|
+
for (let read = 0;read < mergedLen; read++) {
|
|
1970
|
+
const text = mergedTexts[read];
|
|
1971
|
+
if (text.length === 0)
|
|
1972
|
+
continue;
|
|
1973
|
+
if (compactLen !== read) {
|
|
1974
|
+
mergedTexts[compactLen] = text;
|
|
1975
|
+
mergedWordLike[compactLen] = mergedWordLike[read];
|
|
1976
|
+
mergedKinds[compactLen] = mergedKinds[read];
|
|
1977
|
+
mergedStarts[compactLen] = mergedStarts[read];
|
|
1978
|
+
}
|
|
1979
|
+
compactLen++;
|
|
1980
|
+
}
|
|
1981
|
+
mergedTexts.length = compactLen;
|
|
1982
|
+
mergedWordLike.length = compactLen;
|
|
1983
|
+
mergedKinds.length = compactLen;
|
|
1984
|
+
mergedStarts.length = compactLen;
|
|
1985
|
+
const compacted = mergeGlueConnectedTextRuns({
|
|
1986
|
+
len: compactLen,
|
|
1987
|
+
texts: mergedTexts,
|
|
1988
|
+
isWordLike: mergedWordLike,
|
|
1989
|
+
kinds: mergedKinds,
|
|
1990
|
+
starts: mergedStarts
|
|
1991
|
+
});
|
|
1992
|
+
const withMergedUrls = carryTrailingForwardStickyAcrossCJKBoundary(mergeNoSpaceWordChains(splitHyphenatedNumericRuns(mergeNumericRuns(mergeUrlQueryRuns(mergeUrlLikeRuns(compacted))))));
|
|
1993
|
+
for (let i = 0;i < withMergedUrls.len - 1; i++) {
|
|
1994
|
+
const split = splitLeadingSpaceAndMarks(withMergedUrls.texts[i]);
|
|
1995
|
+
if (split === null)
|
|
1996
|
+
continue;
|
|
1997
|
+
if (withMergedUrls.kinds[i] !== "space" && withMergedUrls.kinds[i] !== "preserved-space" || withMergedUrls.kinds[i + 1] !== "text" || !containsArabicScript(withMergedUrls.texts[i + 1])) {
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
withMergedUrls.texts[i] = split.space;
|
|
2001
|
+
withMergedUrls.isWordLike[i] = false;
|
|
2002
|
+
withMergedUrls.kinds[i] = withMergedUrls.kinds[i] === "preserved-space" ? "preserved-space" : "space";
|
|
2003
|
+
withMergedUrls.texts[i + 1] = split.marks + withMergedUrls.texts[i + 1];
|
|
2004
|
+
withMergedUrls.starts[i + 1] = withMergedUrls.starts[i] + split.space.length;
|
|
2005
|
+
}
|
|
2006
|
+
return withMergedUrls;
|
|
2007
|
+
}
|
|
2008
|
+
function compileAnalysisChunks(segmentation, whiteSpaceProfile) {
|
|
2009
|
+
if (segmentation.len === 0)
|
|
2010
|
+
return [];
|
|
2011
|
+
if (!whiteSpaceProfile.preserveHardBreaks) {
|
|
2012
|
+
return [{
|
|
2013
|
+
startSegmentIndex: 0,
|
|
2014
|
+
endSegmentIndex: segmentation.len,
|
|
2015
|
+
consumedEndSegmentIndex: segmentation.len
|
|
2016
|
+
}];
|
|
2017
|
+
}
|
|
2018
|
+
const chunks = [];
|
|
2019
|
+
let startSegmentIndex = 0;
|
|
2020
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
2021
|
+
if (segmentation.kinds[i] !== "hard-break")
|
|
2022
|
+
continue;
|
|
2023
|
+
chunks.push({
|
|
2024
|
+
startSegmentIndex,
|
|
2025
|
+
endSegmentIndex: i,
|
|
2026
|
+
consumedEndSegmentIndex: i + 1
|
|
2027
|
+
});
|
|
2028
|
+
startSegmentIndex = i + 1;
|
|
2029
|
+
}
|
|
2030
|
+
if (startSegmentIndex < segmentation.len) {
|
|
2031
|
+
chunks.push({
|
|
2032
|
+
startSegmentIndex,
|
|
2033
|
+
endSegmentIndex: segmentation.len,
|
|
2034
|
+
consumedEndSegmentIndex: segmentation.len
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
return chunks;
|
|
2038
|
+
}
|
|
2039
|
+
function mergeKeepAllTextSegments(normalized, segmentation, breakAfterPunctuation) {
|
|
2040
|
+
if (segmentation.len <= 1)
|
|
2041
|
+
return segmentation;
|
|
2042
|
+
const texts = [];
|
|
2043
|
+
const isWordLike = [];
|
|
2044
|
+
const kinds = [];
|
|
2045
|
+
const starts = [];
|
|
2046
|
+
let groupStart = -1;
|
|
2047
|
+
let groupContainsCJK = false;
|
|
2048
|
+
function pushOriginalText(index) {
|
|
2049
|
+
texts.push(segmentation.texts[index]);
|
|
2050
|
+
isWordLike.push(segmentation.isWordLike[index]);
|
|
2051
|
+
kinds.push("text");
|
|
2052
|
+
starts.push(segmentation.starts[index]);
|
|
2053
|
+
}
|
|
2054
|
+
function pushMergedText(start, end) {
|
|
2055
|
+
let wordLike = false;
|
|
2056
|
+
for (let i = start;i < end; i++) {
|
|
2057
|
+
wordLike = wordLike || segmentation.isWordLike[i];
|
|
2058
|
+
}
|
|
2059
|
+
const sourceStart = segmentation.starts[start];
|
|
2060
|
+
const sourceEnd = end < segmentation.len ? segmentation.starts[end] : normalized.length;
|
|
2061
|
+
texts.push(normalized.slice(sourceStart, sourceEnd));
|
|
2062
|
+
isWordLike.push(wordLike);
|
|
2063
|
+
kinds.push("text");
|
|
2064
|
+
starts.push(sourceStart);
|
|
2065
|
+
}
|
|
2066
|
+
function flushGroup(end) {
|
|
2067
|
+
if (groupStart < 0)
|
|
2068
|
+
return;
|
|
2069
|
+
if (groupContainsCJK) {
|
|
2070
|
+
if (groupStart + 1 === end) {
|
|
2071
|
+
pushOriginalText(groupStart);
|
|
2072
|
+
} else {
|
|
2073
|
+
pushMergedText(groupStart, end);
|
|
2074
|
+
}
|
|
2075
|
+
} else {
|
|
2076
|
+
for (let i = groupStart;i < end; i++)
|
|
2077
|
+
pushOriginalText(i);
|
|
2078
|
+
}
|
|
2079
|
+
groupStart = -1;
|
|
2080
|
+
groupContainsCJK = false;
|
|
2081
|
+
}
|
|
2082
|
+
for (let i = 0;i < segmentation.len; i++) {
|
|
2083
|
+
const text = segmentation.texts[i];
|
|
2084
|
+
const kind = segmentation.kinds[i];
|
|
2085
|
+
if (kind === "text") {
|
|
2086
|
+
if (groupStart >= 0 && !canContinueKeepAllTextRun(segmentation.texts[i - 1], breakAfterPunctuation)) {
|
|
2087
|
+
flushGroup(i);
|
|
2088
|
+
}
|
|
2089
|
+
if (groupStart < 0)
|
|
2090
|
+
groupStart = i;
|
|
2091
|
+
groupContainsCJK = groupContainsCJK || isCJK(text);
|
|
2092
|
+
continue;
|
|
2093
|
+
}
|
|
2094
|
+
flushGroup(i);
|
|
2095
|
+
texts.push(text);
|
|
2096
|
+
isWordLike.push(segmentation.isWordLike[i]);
|
|
2097
|
+
kinds.push(kind);
|
|
2098
|
+
starts.push(segmentation.starts[i]);
|
|
2099
|
+
}
|
|
2100
|
+
flushGroup(segmentation.len);
|
|
2101
|
+
return {
|
|
2102
|
+
len: texts.length,
|
|
2103
|
+
texts,
|
|
2104
|
+
isWordLike,
|
|
2105
|
+
kinds,
|
|
2106
|
+
starts
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
function analyzeText(text, profile, whiteSpace = "normal", wordBreak = "normal") {
|
|
2110
|
+
const whiteSpaceProfile = getWhiteSpaceProfile(whiteSpace);
|
|
2111
|
+
const normalized = whiteSpaceProfile.mode === "pre-wrap" ? normalizeWhitespacePreWrap(text) : normalizeWhitespaceNormal(text);
|
|
2112
|
+
if (normalized.length === 0) {
|
|
2113
|
+
return {
|
|
2114
|
+
normalized,
|
|
2115
|
+
chunks: [],
|
|
2116
|
+
len: 0,
|
|
2117
|
+
texts: [],
|
|
2118
|
+
isWordLike: [],
|
|
2119
|
+
kinds: [],
|
|
2120
|
+
starts: []
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
const mergedSegmentation = buildMergedSegmentation(normalized, profile, whiteSpaceProfile);
|
|
2124
|
+
const segmentation = wordBreak === "keep-all" ? mergeKeepAllTextSegments(normalized, mergedSegmentation, profile.breakKeepAllAfterPunctuation) : mergedSegmentation;
|
|
2125
|
+
return {
|
|
2126
|
+
normalized,
|
|
2127
|
+
chunks: compileAnalysisChunks(segmentation, whiteSpaceProfile),
|
|
2128
|
+
...segmentation
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
var collapsibleWhitespaceRunRe, needsWhitespaceNormalizationRe, sharedWordSegmenter = null, segmenterLocale, arabicScriptRe, combiningMarkRe, decimalDigitRe, keepAllGlueChars, keepAllDashBreakChars, kinsokuStart, kinsokuEnd, forwardStickyGlue, leftStickyPunctuation, arabicNoSpaceTrailingPunctuation, myanmarMedialGlue, closingQuoteChars, lineBreakNumericAffixRanges, breakCharRe, urlSchemeSegmentRe, numericJoinerChars, wordInternalSymbolRe, emojiPresentationRe, noSpaceWordBreakAfterChars;
|
|
2132
|
+
var init_analysis = __esm(() => {
|
|
2133
|
+
collapsibleWhitespaceRunRe = /[ \t\n\r\f]+/g;
|
|
2134
|
+
needsWhitespaceNormalizationRe = /[\t\n\r\f]| {2,}|^ | $/;
|
|
2135
|
+
arabicScriptRe = /\p{Script=Arabic}/u;
|
|
2136
|
+
combiningMarkRe = /\p{M}/u;
|
|
2137
|
+
decimalDigitRe = /\p{Nd}/u;
|
|
2138
|
+
keepAllGlueChars = new Set([
|
|
2139
|
+
"\xA0",
|
|
2140
|
+
"\u202F",
|
|
2141
|
+
"\u2060",
|
|
2142
|
+
"\uFEFF"
|
|
2143
|
+
]);
|
|
2144
|
+
keepAllDashBreakChars = new Set([
|
|
2145
|
+
"-",
|
|
2146
|
+
"\u2010",
|
|
2147
|
+
"\u2013",
|
|
2148
|
+
"\u2014"
|
|
2149
|
+
]);
|
|
2150
|
+
kinsokuStart = new Set([
|
|
2151
|
+
"\uFF0C",
|
|
2152
|
+
"\uFF0E",
|
|
2153
|
+
"\uFF01",
|
|
2154
|
+
"\uFF1A",
|
|
2155
|
+
"\uFF1B",
|
|
2156
|
+
"\uFF1F",
|
|
2157
|
+
"\u3001",
|
|
2158
|
+
"\u3002",
|
|
2159
|
+
"\u30FB",
|
|
2160
|
+
"\uFF09",
|
|
2161
|
+
"\u3015",
|
|
2162
|
+
"\u3009",
|
|
2163
|
+
"\u300B",
|
|
2164
|
+
"\u300D",
|
|
2165
|
+
"\u300F",
|
|
2166
|
+
"\u3011",
|
|
2167
|
+
"\u3017",
|
|
2168
|
+
"\u3019",
|
|
2169
|
+
"\u301B",
|
|
2170
|
+
"\u30FC",
|
|
2171
|
+
"\u3005",
|
|
2172
|
+
"\u303B",
|
|
2173
|
+
"\u309D",
|
|
2174
|
+
"\u309E",
|
|
2175
|
+
"\u30FD",
|
|
2176
|
+
"\u30FE"
|
|
2177
|
+
]);
|
|
2178
|
+
kinsokuEnd = new Set([
|
|
2179
|
+
'"',
|
|
2180
|
+
"(",
|
|
2181
|
+
"[",
|
|
2182
|
+
"{",
|
|
2183
|
+
"\xA1",
|
|
2184
|
+
"\xBF",
|
|
2185
|
+
"\u201C",
|
|
2186
|
+
"\u2018",
|
|
2187
|
+
"\u201A",
|
|
2188
|
+
"\u201E",
|
|
2189
|
+
"\xAB",
|
|
2190
|
+
"\u2039",
|
|
2191
|
+
"\u2E18",
|
|
2192
|
+
"\uFF08",
|
|
2193
|
+
"\u3014",
|
|
2194
|
+
"\u3008",
|
|
2195
|
+
"\u300A",
|
|
2196
|
+
"\u300C",
|
|
2197
|
+
"\u300E",
|
|
2198
|
+
"\u3010",
|
|
2199
|
+
"\u3016",
|
|
2200
|
+
"\u3018",
|
|
2201
|
+
"\u301A"
|
|
2202
|
+
]);
|
|
2203
|
+
forwardStickyGlue = new Set([
|
|
2204
|
+
"'",
|
|
2205
|
+
"\u2019"
|
|
2206
|
+
]);
|
|
2207
|
+
leftStickyPunctuation = new Set([
|
|
2208
|
+
".",
|
|
2209
|
+
",",
|
|
2210
|
+
"!",
|
|
2211
|
+
"?",
|
|
2212
|
+
":",
|
|
2213
|
+
";",
|
|
2214
|
+
"\u060C",
|
|
2215
|
+
"\u061B",
|
|
2216
|
+
"\u061F",
|
|
2217
|
+
"\u0964",
|
|
2218
|
+
"\u0965",
|
|
2219
|
+
"\u104A",
|
|
2220
|
+
"\u104B",
|
|
2221
|
+
"\u104C",
|
|
2222
|
+
"\u104D",
|
|
2223
|
+
"\u104F",
|
|
2224
|
+
")",
|
|
2225
|
+
"]",
|
|
2226
|
+
"}",
|
|
2227
|
+
"%",
|
|
2228
|
+
'"',
|
|
2229
|
+
"\u201D",
|
|
2230
|
+
"\u2019",
|
|
2231
|
+
"\xBB",
|
|
2232
|
+
"\u203A",
|
|
2233
|
+
"\u2026"
|
|
2234
|
+
]);
|
|
2235
|
+
arabicNoSpaceTrailingPunctuation = new Set([
|
|
2236
|
+
":",
|
|
2237
|
+
".",
|
|
2238
|
+
"\u060C",
|
|
2239
|
+
"\u061B"
|
|
2240
|
+
]);
|
|
2241
|
+
myanmarMedialGlue = new Set([
|
|
2242
|
+
"\u104F"
|
|
2243
|
+
]);
|
|
2244
|
+
closingQuoteChars = new Set([
|
|
2245
|
+
"\u201D",
|
|
2246
|
+
"\u2019",
|
|
2247
|
+
"\xBB",
|
|
2248
|
+
"\u203A",
|
|
2249
|
+
"\u300D",
|
|
2250
|
+
"\u300F",
|
|
2251
|
+
"\u3011",
|
|
2252
|
+
"\u300B",
|
|
2253
|
+
"\u3009",
|
|
2254
|
+
"\u3015",
|
|
2255
|
+
"\uFF09"
|
|
2256
|
+
]);
|
|
2257
|
+
lineBreakNumericAffixRanges = [
|
|
2258
|
+
36,
|
|
2259
|
+
37,
|
|
2260
|
+
43,
|
|
2261
|
+
43,
|
|
2262
|
+
92,
|
|
2263
|
+
92,
|
|
2264
|
+
162,
|
|
2265
|
+
165,
|
|
2266
|
+
176,
|
|
2267
|
+
177,
|
|
2268
|
+
1423,
|
|
2269
|
+
1423,
|
|
2270
|
+
1545,
|
|
2271
|
+
1547,
|
|
2272
|
+
1642,
|
|
2273
|
+
1642,
|
|
2274
|
+
2046,
|
|
2275
|
+
2047,
|
|
2276
|
+
2546,
|
|
2277
|
+
2547,
|
|
2278
|
+
2553,
|
|
2279
|
+
2555,
|
|
2280
|
+
2801,
|
|
2281
|
+
2801,
|
|
2282
|
+
3065,
|
|
2283
|
+
3065,
|
|
2284
|
+
3449,
|
|
2285
|
+
3449,
|
|
2286
|
+
3647,
|
|
2287
|
+
3647,
|
|
2288
|
+
6107,
|
|
2289
|
+
6107,
|
|
2290
|
+
8240,
|
|
2291
|
+
8247,
|
|
2292
|
+
8279,
|
|
2293
|
+
8279,
|
|
2294
|
+
8352,
|
|
2295
|
+
8399,
|
|
2296
|
+
8451,
|
|
2297
|
+
8451,
|
|
2298
|
+
8457,
|
|
2299
|
+
8457,
|
|
2300
|
+
8470,
|
|
2301
|
+
8470,
|
|
2302
|
+
8722,
|
|
2303
|
+
8723,
|
|
2304
|
+
43064,
|
|
2305
|
+
43064,
|
|
2306
|
+
65020,
|
|
2307
|
+
65020,
|
|
2308
|
+
65129,
|
|
2309
|
+
65130,
|
|
2310
|
+
65284,
|
|
2311
|
+
65285,
|
|
2312
|
+
65504,
|
|
2313
|
+
65505,
|
|
2314
|
+
65509,
|
|
2315
|
+
65510,
|
|
2316
|
+
73693,
|
|
2317
|
+
73696,
|
|
2318
|
+
123647,
|
|
2319
|
+
123647,
|
|
2320
|
+
126124,
|
|
2321
|
+
126124,
|
|
2322
|
+
126128,
|
|
2323
|
+
126128
|
|
2324
|
+
];
|
|
2325
|
+
breakCharRe = /[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;
|
|
2326
|
+
urlSchemeSegmentRe = /^[A-Za-z][A-Za-z0-9+.-]*:$/;
|
|
2327
|
+
numericJoinerChars = new Set([
|
|
2328
|
+
":",
|
|
2329
|
+
"-",
|
|
2330
|
+
"/",
|
|
2331
|
+
"\xD7",
|
|
2332
|
+
",",
|
|
2333
|
+
".",
|
|
2334
|
+
"+",
|
|
2335
|
+
"\u2013",
|
|
2336
|
+
"\u2014"
|
|
2337
|
+
]);
|
|
2338
|
+
wordInternalSymbolRe = /[\p{P}\p{S}\p{Co}]/u;
|
|
2339
|
+
emojiPresentationRe = /\p{Emoji_Presentation}/u;
|
|
2340
|
+
noSpaceWordBreakAfterChars = new Set([
|
|
2341
|
+
"?",
|
|
2342
|
+
"\u058A",
|
|
2343
|
+
"-",
|
|
2344
|
+
"\u2010",
|
|
2345
|
+
"\u2012",
|
|
2346
|
+
"\u2013",
|
|
2347
|
+
"\u2014",
|
|
2348
|
+
"\u2026",
|
|
2349
|
+
"\u203C",
|
|
2350
|
+
"\u203D",
|
|
2351
|
+
"\u2049"
|
|
2352
|
+
]);
|
|
2353
|
+
});
|
|
2354
|
+
|
|
2355
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/measurement.js
|
|
2356
|
+
function getMeasureContext() {
|
|
2357
|
+
if (measureContext !== null)
|
|
2358
|
+
return measureContext;
|
|
2359
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
2360
|
+
measureContext = new OffscreenCanvas(1, 1).getContext("2d");
|
|
2361
|
+
return measureContext;
|
|
2362
|
+
}
|
|
2363
|
+
if (typeof document !== "undefined") {
|
|
2364
|
+
measureContext = document.createElement("canvas").getContext("2d");
|
|
2365
|
+
return measureContext;
|
|
2366
|
+
}
|
|
2367
|
+
throw new Error("Text measurement requires OffscreenCanvas or a DOM canvas context.");
|
|
2368
|
+
}
|
|
2369
|
+
function getSegmentMetricCache(font) {
|
|
2370
|
+
let cache = segmentMetricCaches.get(font);
|
|
2371
|
+
if (!cache) {
|
|
2372
|
+
cache = new Map;
|
|
2373
|
+
segmentMetricCaches.set(font, cache);
|
|
2374
|
+
}
|
|
2375
|
+
return cache;
|
|
2376
|
+
}
|
|
2377
|
+
function getSegmentMetrics(seg, cache) {
|
|
2378
|
+
let metrics = cache.get(seg);
|
|
2379
|
+
if (metrics === undefined) {
|
|
2380
|
+
const ctx = getMeasureContext();
|
|
2381
|
+
metrics = {
|
|
2382
|
+
width: ctx.measureText(seg).width,
|
|
2383
|
+
containsCJK: isCJK(seg)
|
|
2384
|
+
};
|
|
2385
|
+
cache.set(seg, metrics);
|
|
2386
|
+
}
|
|
2387
|
+
return metrics;
|
|
2388
|
+
}
|
|
2389
|
+
function getEngineProfile() {
|
|
2390
|
+
if (cachedEngineProfile !== null)
|
|
2391
|
+
return cachedEngineProfile;
|
|
2392
|
+
if (typeof navigator === "undefined") {
|
|
2393
|
+
cachedEngineProfile = {
|
|
2394
|
+
lineFitEpsilon: 0.005,
|
|
2395
|
+
carryCJKAfterClosingQuote: false,
|
|
2396
|
+
breakKeepAllAfterPunctuation: true,
|
|
2397
|
+
preferPrefixWidthsForBreakableRuns: false,
|
|
2398
|
+
preferEarlySoftHyphenBreak: false
|
|
2399
|
+
};
|
|
2400
|
+
return cachedEngineProfile;
|
|
2401
|
+
}
|
|
2402
|
+
const ua = navigator.userAgent;
|
|
2403
|
+
const vendor = navigator.vendor;
|
|
2404
|
+
const isSafari = vendor === "Apple Computer, Inc." && ua.includes("Safari/") && !ua.includes("Chrome/") && !ua.includes("Chromium/") && !ua.includes("CriOS/") && !ua.includes("FxiOS/") && !ua.includes("EdgiOS/");
|
|
2405
|
+
const isChromium = ua.includes("Chrome/") || ua.includes("Chromium/") || ua.includes("CriOS/") || ua.includes("Edg/");
|
|
2406
|
+
cachedEngineProfile = {
|
|
2407
|
+
lineFitEpsilon: isSafari ? 1 / 64 : 0.005,
|
|
2408
|
+
carryCJKAfterClosingQuote: isChromium,
|
|
2409
|
+
breakKeepAllAfterPunctuation: !isSafari,
|
|
2410
|
+
preferPrefixWidthsForBreakableRuns: isSafari,
|
|
2411
|
+
preferEarlySoftHyphenBreak: isSafari
|
|
2412
|
+
};
|
|
2413
|
+
return cachedEngineProfile;
|
|
2414
|
+
}
|
|
2415
|
+
function parseFontSize(font) {
|
|
2416
|
+
const m = font.match(/(\d+(?:\.\d+)?)\s*px/);
|
|
2417
|
+
return m ? parseFloat(m[1]) : 16;
|
|
2418
|
+
}
|
|
2419
|
+
function getSharedGraphemeSegmenter() {
|
|
2420
|
+
if (sharedGraphemeSegmenter === null) {
|
|
2421
|
+
sharedGraphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
2422
|
+
}
|
|
2423
|
+
return sharedGraphemeSegmenter;
|
|
2424
|
+
}
|
|
2425
|
+
function isEmojiGrapheme(g) {
|
|
2426
|
+
return emojiPresentationRe2.test(g) || g.includes("\uFE0F");
|
|
2427
|
+
}
|
|
2428
|
+
function textMayContainEmoji(text) {
|
|
2429
|
+
return maybeEmojiRe.test(text);
|
|
2430
|
+
}
|
|
2431
|
+
function getEmojiCorrection(font, fontSize) {
|
|
2432
|
+
let correction = emojiCorrectionCache.get(font);
|
|
2433
|
+
if (correction !== undefined)
|
|
2434
|
+
return correction;
|
|
2435
|
+
const ctx = getMeasureContext();
|
|
2436
|
+
ctx.font = font;
|
|
2437
|
+
const canvasW = ctx.measureText("\uD83D\uDE00").width;
|
|
2438
|
+
correction = 0;
|
|
2439
|
+
if (canvasW > fontSize + 0.5 && typeof document !== "undefined" && document.body !== null) {
|
|
2440
|
+
const span = document.createElement("span");
|
|
2441
|
+
span.style.font = font;
|
|
2442
|
+
span.style.display = "inline-block";
|
|
2443
|
+
span.style.visibility = "hidden";
|
|
2444
|
+
span.style.position = "absolute";
|
|
2445
|
+
span.textContent = "\uD83D\uDE00";
|
|
2446
|
+
document.body.appendChild(span);
|
|
2447
|
+
const domW = span.getBoundingClientRect().width;
|
|
2448
|
+
document.body.removeChild(span);
|
|
2449
|
+
if (canvasW - domW > 0.5) {
|
|
2450
|
+
correction = canvasW - domW;
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
emojiCorrectionCache.set(font, correction);
|
|
2454
|
+
return correction;
|
|
2455
|
+
}
|
|
2456
|
+
function countEmojiGraphemes(text) {
|
|
2457
|
+
let count = 0;
|
|
2458
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter();
|
|
2459
|
+
for (const g of graphemeSegmenter.segment(text)) {
|
|
2460
|
+
if (isEmojiGrapheme(g.segment))
|
|
2461
|
+
count++;
|
|
2462
|
+
}
|
|
2463
|
+
return count;
|
|
2464
|
+
}
|
|
2465
|
+
function getEmojiCount(seg, metrics) {
|
|
2466
|
+
if (metrics.emojiCount === undefined) {
|
|
2467
|
+
metrics.emojiCount = countEmojiGraphemes(seg);
|
|
2468
|
+
}
|
|
2469
|
+
return metrics.emojiCount;
|
|
2470
|
+
}
|
|
2471
|
+
function getCorrectedSegmentWidth(seg, metrics, emojiCorrection) {
|
|
2472
|
+
if (emojiCorrection === 0)
|
|
2473
|
+
return metrics.width;
|
|
2474
|
+
return metrics.width - getEmojiCount(seg, metrics) * emojiCorrection;
|
|
2475
|
+
}
|
|
2476
|
+
function getSegmentBreakableFitAdvances(seg, metrics, cache, emojiCorrection, mode) {
|
|
2477
|
+
if (metrics.breakableFitAdvances !== undefined && metrics.breakableFitMode === mode) {
|
|
2478
|
+
return metrics.breakableFitAdvances;
|
|
2479
|
+
}
|
|
2480
|
+
metrics.breakableFitMode = mode;
|
|
2481
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter();
|
|
2482
|
+
const graphemes = [];
|
|
2483
|
+
for (const gs of graphemeSegmenter.segment(seg)) {
|
|
2484
|
+
graphemes.push(gs.segment);
|
|
2485
|
+
}
|
|
2486
|
+
if (graphemes.length <= 1) {
|
|
2487
|
+
metrics.breakableFitAdvances = null;
|
|
2488
|
+
return metrics.breakableFitAdvances;
|
|
2489
|
+
}
|
|
2490
|
+
if (mode === "sum-graphemes") {
|
|
2491
|
+
const advances2 = [];
|
|
2492
|
+
for (const grapheme of graphemes) {
|
|
2493
|
+
const graphemeMetrics = getSegmentMetrics(grapheme, cache);
|
|
2494
|
+
advances2.push(getCorrectedSegmentWidth(grapheme, graphemeMetrics, emojiCorrection));
|
|
2495
|
+
}
|
|
2496
|
+
metrics.breakableFitAdvances = advances2;
|
|
2497
|
+
return metrics.breakableFitAdvances;
|
|
2498
|
+
}
|
|
2499
|
+
if (mode === "pair-context" || graphemes.length > MAX_PREFIX_FIT_GRAPHEMES) {
|
|
2500
|
+
const advances2 = [];
|
|
2501
|
+
let previousGrapheme = null;
|
|
2502
|
+
let previousWidth = 0;
|
|
2503
|
+
for (const grapheme of graphemes) {
|
|
2504
|
+
const graphemeMetrics = getSegmentMetrics(grapheme, cache);
|
|
2505
|
+
const currentWidth = getCorrectedSegmentWidth(grapheme, graphemeMetrics, emojiCorrection);
|
|
2506
|
+
if (previousGrapheme === null) {
|
|
2507
|
+
advances2.push(currentWidth);
|
|
2508
|
+
} else {
|
|
2509
|
+
const pair = previousGrapheme + grapheme;
|
|
2510
|
+
const pairMetrics = getSegmentMetrics(pair, cache);
|
|
2511
|
+
advances2.push(getCorrectedSegmentWidth(pair, pairMetrics, emojiCorrection) - previousWidth);
|
|
2512
|
+
}
|
|
2513
|
+
previousGrapheme = grapheme;
|
|
2514
|
+
previousWidth = currentWidth;
|
|
2515
|
+
}
|
|
2516
|
+
metrics.breakableFitAdvances = advances2;
|
|
2517
|
+
return metrics.breakableFitAdvances;
|
|
2518
|
+
}
|
|
2519
|
+
const advances = [];
|
|
2520
|
+
let prefix = "";
|
|
2521
|
+
let prefixWidth = 0;
|
|
2522
|
+
for (const grapheme of graphemes) {
|
|
2523
|
+
prefix += grapheme;
|
|
2524
|
+
const prefixMetrics = getSegmentMetrics(prefix, cache);
|
|
2525
|
+
const nextPrefixWidth = getCorrectedSegmentWidth(prefix, prefixMetrics, emojiCorrection);
|
|
2526
|
+
advances.push(nextPrefixWidth - prefixWidth);
|
|
2527
|
+
prefixWidth = nextPrefixWidth;
|
|
2528
|
+
}
|
|
2529
|
+
metrics.breakableFitAdvances = advances;
|
|
2530
|
+
return metrics.breakableFitAdvances;
|
|
2531
|
+
}
|
|
2532
|
+
function getFontMeasurementState(font, needsEmojiCorrection) {
|
|
2533
|
+
const ctx = getMeasureContext();
|
|
2534
|
+
ctx.font = font;
|
|
2535
|
+
const cache = getSegmentMetricCache(font);
|
|
2536
|
+
const fontSize = parseFontSize(font);
|
|
2537
|
+
const emojiCorrection = needsEmojiCorrection ? getEmojiCorrection(font, fontSize) : 0;
|
|
2538
|
+
return { cache, fontSize, emojiCorrection };
|
|
2539
|
+
}
|
|
2540
|
+
function clearMeasurementCaches() {
|
|
2541
|
+
segmentMetricCaches.clear();
|
|
2542
|
+
emojiCorrectionCache.clear();
|
|
2543
|
+
sharedGraphemeSegmenter = null;
|
|
2544
|
+
}
|
|
2545
|
+
var measureContext = null, segmentMetricCaches, cachedEngineProfile = null, MAX_PREFIX_FIT_GRAPHEMES = 96, emojiPresentationRe2, maybeEmojiRe, sharedGraphemeSegmenter = null, emojiCorrectionCache;
|
|
2546
|
+
var init_measurement = __esm(() => {
|
|
2547
|
+
init_analysis();
|
|
2548
|
+
segmentMetricCaches = new Map;
|
|
2549
|
+
emojiPresentationRe2 = /\p{Emoji_Presentation}/u;
|
|
2550
|
+
maybeEmojiRe = /[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u;
|
|
2551
|
+
emojiCorrectionCache = new Map;
|
|
2552
|
+
});
|
|
2553
|
+
|
|
2554
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/line-break.js
|
|
2555
|
+
function consumesAtLineStart(kind) {
|
|
2556
|
+
return kind === "space" || kind === "zero-width-break" || kind === "soft-hyphen";
|
|
2557
|
+
}
|
|
2558
|
+
function breaksAfter(kind) {
|
|
2559
|
+
return kind === "space" || kind === "preserved-space" || kind === "tab" || kind === "zero-width-break" || kind === "soft-hyphen";
|
|
2560
|
+
}
|
|
2561
|
+
function normalizeLineStartSegmentIndex(prepared, segmentIndex, endSegmentIndex = prepared.widths.length) {
|
|
2562
|
+
while (segmentIndex < endSegmentIndex) {
|
|
2563
|
+
const kind = prepared.kinds[segmentIndex];
|
|
2564
|
+
if (!consumesAtLineStart(kind))
|
|
2565
|
+
break;
|
|
2566
|
+
segmentIndex++;
|
|
2567
|
+
}
|
|
2568
|
+
return segmentIndex;
|
|
2569
|
+
}
|
|
2570
|
+
function getTabAdvance(lineWidth, tabStopAdvance) {
|
|
2571
|
+
if (tabStopAdvance <= 0)
|
|
2572
|
+
return 0;
|
|
2573
|
+
const remainder = lineWidth % tabStopAdvance;
|
|
2574
|
+
if (Math.abs(remainder) <= 0.000001)
|
|
2575
|
+
return tabStopAdvance;
|
|
2576
|
+
return tabStopAdvance - remainder;
|
|
2577
|
+
}
|
|
2578
|
+
function getLeadingLetterSpacing(prepared, hasContent, segmentIndex) {
|
|
2579
|
+
return prepared.letterSpacing !== 0 && hasContent && prepared.spacingGraphemeCounts[segmentIndex] > 0 ? prepared.letterSpacing : 0;
|
|
2580
|
+
}
|
|
2581
|
+
function getLineEndContribution(leadingSpacing, segmentContribution) {
|
|
2582
|
+
return segmentContribution === 0 ? 0 : leadingSpacing + segmentContribution;
|
|
2583
|
+
}
|
|
2584
|
+
function getTabTrailingLetterSpacing(prepared, segmentIndex) {
|
|
2585
|
+
return prepared.letterSpacing !== 0 && prepared.spacingGraphemeCounts[segmentIndex] > 0 ? prepared.letterSpacing : 0;
|
|
2586
|
+
}
|
|
2587
|
+
function getWholeSegmentFitContribution(prepared, kind, segmentIndex, leadingSpacing, segmentWidth) {
|
|
2588
|
+
const segmentContribution = kind === "tab" ? segmentWidth + getTabTrailingLetterSpacing(prepared, segmentIndex) : prepared.lineEndFitAdvances[segmentIndex];
|
|
2589
|
+
return getLineEndContribution(leadingSpacing, segmentContribution);
|
|
2590
|
+
}
|
|
2591
|
+
function getBreakOpportunityFitContribution(prepared, kind, segmentIndex, leadingSpacing) {
|
|
2592
|
+
const segmentContribution = kind === "tab" ? 0 : prepared.lineEndFitAdvances[segmentIndex];
|
|
2593
|
+
return getLineEndContribution(leadingSpacing, segmentContribution);
|
|
2594
|
+
}
|
|
2595
|
+
function getLineEndPaintContribution(prepared, kind, segmentIndex, leadingSpacing, segmentWidth) {
|
|
2596
|
+
const segmentContribution = kind === "tab" ? segmentWidth : prepared.lineEndPaintAdvances[segmentIndex];
|
|
2597
|
+
return getLineEndContribution(leadingSpacing, segmentContribution);
|
|
2598
|
+
}
|
|
2599
|
+
function getBreakableGraphemeAdvance(prepared, hasContent, baseAdvance) {
|
|
2600
|
+
return prepared.letterSpacing !== 0 && hasContent ? baseAdvance + prepared.letterSpacing : baseAdvance;
|
|
2601
|
+
}
|
|
2602
|
+
function getBreakableCandidateFitWidth(prepared, candidatePaintWidth) {
|
|
2603
|
+
return prepared.letterSpacing === 0 ? candidatePaintWidth : candidatePaintWidth + prepared.letterSpacing;
|
|
2604
|
+
}
|
|
2605
|
+
function getNextPreferredBreakIndex(preferredBreaks, preferredBreakIndex, graphemeEnd) {
|
|
2606
|
+
let index = preferredBreakIndex;
|
|
2607
|
+
while (index < preferredBreaks.length && preferredBreaks[index] < graphemeEnd) {
|
|
2608
|
+
index++;
|
|
2609
|
+
}
|
|
2610
|
+
return index;
|
|
2611
|
+
}
|
|
2612
|
+
function getTerminalLetterSpacing(prepared, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
|
|
2613
|
+
if (prepared.letterSpacing === 0)
|
|
2614
|
+
return 0;
|
|
2615
|
+
if (endGraphemeIndex > 0) {
|
|
2616
|
+
return prepared.spacingGraphemeCounts[endSegmentIndex] > 0 ? prepared.letterSpacing : 0;
|
|
2617
|
+
}
|
|
2618
|
+
for (let i = endSegmentIndex - 1;i >= startSegmentIndex; i--) {
|
|
2619
|
+
const kind = prepared.kinds[i];
|
|
2620
|
+
if (kind === "space" || kind === "zero-width-break" || kind === "hard-break")
|
|
2621
|
+
continue;
|
|
2622
|
+
if (kind === "soft-hyphen") {
|
|
2623
|
+
if (i === endSegmentIndex - 1)
|
|
2624
|
+
return 0;
|
|
2625
|
+
continue;
|
|
2626
|
+
}
|
|
2627
|
+
if (i === startSegmentIndex && startGraphemeIndex > 0) {
|
|
2628
|
+
return prepared.letterSpacing;
|
|
2629
|
+
}
|
|
2630
|
+
return prepared.spacingGraphemeCounts[i] > 0 ? prepared.letterSpacing : 0;
|
|
2631
|
+
}
|
|
2632
|
+
return 0;
|
|
2633
|
+
}
|
|
2634
|
+
function finalizeLinePaintWidth(prepared, width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
|
|
2635
|
+
return width + getTerminalLetterSpacing(prepared, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex);
|
|
2636
|
+
}
|
|
2637
|
+
function findChunkIndexForStart(prepared, segmentIndex) {
|
|
2638
|
+
let lo = 0;
|
|
2639
|
+
let hi = prepared.chunks.length;
|
|
2640
|
+
while (lo < hi) {
|
|
2641
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
2642
|
+
if (segmentIndex < prepared.chunks[mid].consumedEndSegmentIndex) {
|
|
2643
|
+
hi = mid;
|
|
2644
|
+
} else {
|
|
2645
|
+
lo = mid + 1;
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
return lo < prepared.chunks.length ? lo : -1;
|
|
2649
|
+
}
|
|
2650
|
+
function normalizeLineStartInChunk(prepared, chunkIndex, cursor) {
|
|
2651
|
+
let segmentIndex = cursor.segmentIndex;
|
|
2652
|
+
if (cursor.graphemeIndex > 0)
|
|
2653
|
+
return chunkIndex;
|
|
2654
|
+
const chunk = prepared.chunks[chunkIndex];
|
|
2655
|
+
if (chunk.startSegmentIndex === chunk.endSegmentIndex && segmentIndex === chunk.startSegmentIndex) {
|
|
2656
|
+
cursor.segmentIndex = segmentIndex;
|
|
2657
|
+
cursor.graphemeIndex = 0;
|
|
2658
|
+
return chunkIndex;
|
|
2659
|
+
}
|
|
2660
|
+
if (segmentIndex < chunk.startSegmentIndex)
|
|
2661
|
+
segmentIndex = chunk.startSegmentIndex;
|
|
2662
|
+
segmentIndex = normalizeLineStartSegmentIndex(prepared, segmentIndex, chunk.endSegmentIndex);
|
|
2663
|
+
if (segmentIndex < chunk.endSegmentIndex) {
|
|
2664
|
+
cursor.segmentIndex = segmentIndex;
|
|
2665
|
+
cursor.graphemeIndex = 0;
|
|
2666
|
+
return chunkIndex;
|
|
2667
|
+
}
|
|
2668
|
+
if (chunk.consumedEndSegmentIndex >= prepared.widths.length)
|
|
2669
|
+
return -1;
|
|
2670
|
+
cursor.segmentIndex = chunk.consumedEndSegmentIndex;
|
|
2671
|
+
cursor.graphemeIndex = 0;
|
|
2672
|
+
return chunkIndex + 1;
|
|
2673
|
+
}
|
|
2674
|
+
function normalizePreparedLineStart(prepared, cursor) {
|
|
2675
|
+
if (cursor.segmentIndex >= prepared.widths.length)
|
|
2676
|
+
return -1;
|
|
2677
|
+
const chunkIndex = findChunkIndexForStart(prepared, cursor.segmentIndex);
|
|
2678
|
+
if (chunkIndex < 0)
|
|
2679
|
+
return -1;
|
|
2680
|
+
return normalizeLineStartInChunk(prepared, chunkIndex, cursor);
|
|
2681
|
+
}
|
|
2682
|
+
function normalizeLineStartChunkIndexFromHint(prepared, chunkIndex, cursor) {
|
|
2683
|
+
if (cursor.segmentIndex >= prepared.widths.length)
|
|
2684
|
+
return -1;
|
|
2685
|
+
let nextChunkIndex = chunkIndex;
|
|
2686
|
+
while (nextChunkIndex < prepared.chunks.length && cursor.segmentIndex >= prepared.chunks[nextChunkIndex].consumedEndSegmentIndex) {
|
|
2687
|
+
nextChunkIndex++;
|
|
2688
|
+
}
|
|
2689
|
+
if (nextChunkIndex >= prepared.chunks.length)
|
|
2690
|
+
return -1;
|
|
2691
|
+
return normalizeLineStartInChunk(prepared, nextChunkIndex, cursor);
|
|
2692
|
+
}
|
|
2693
|
+
function countPreparedLines(prepared, maxWidth) {
|
|
2694
|
+
return walkPreparedLinesRaw(prepared, maxWidth);
|
|
2695
|
+
}
|
|
2696
|
+
function walkPreparedLinesSimple(prepared, maxWidth, onLine) {
|
|
2697
|
+
const { widths, kinds, breakableFitAdvances, breakablePreferredBreaks } = prepared;
|
|
2698
|
+
if (widths.length === 0)
|
|
2699
|
+
return 0;
|
|
2700
|
+
const engineProfile = getEngineProfile();
|
|
2701
|
+
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
2702
|
+
const fitLimit = maxWidth + lineFitEpsilon;
|
|
2703
|
+
let lineCount = 0;
|
|
2704
|
+
let lineW = 0;
|
|
2705
|
+
let hasContent = false;
|
|
2706
|
+
let lineStartSegmentIndex = 0;
|
|
2707
|
+
let lineStartGraphemeIndex = 0;
|
|
2708
|
+
let lineEndSegmentIndex = 0;
|
|
2709
|
+
let lineEndGraphemeIndex = 0;
|
|
2710
|
+
let pendingBreakSegmentIndex = -1;
|
|
2711
|
+
let pendingBreakPaintWidth = 0;
|
|
2712
|
+
function clearPendingBreak() {
|
|
2713
|
+
pendingBreakSegmentIndex = -1;
|
|
2714
|
+
pendingBreakPaintWidth = 0;
|
|
2715
|
+
}
|
|
2716
|
+
function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width = lineW) {
|
|
2717
|
+
lineCount++;
|
|
2718
|
+
onLine?.(width, lineStartSegmentIndex, lineStartGraphemeIndex, endSegmentIndex, endGraphemeIndex);
|
|
2719
|
+
lineW = 0;
|
|
2720
|
+
hasContent = false;
|
|
2721
|
+
clearPendingBreak();
|
|
2722
|
+
}
|
|
2723
|
+
function startLineAtSegment(segmentIndex, width) {
|
|
2724
|
+
hasContent = true;
|
|
2725
|
+
lineStartSegmentIndex = segmentIndex;
|
|
2726
|
+
lineStartGraphemeIndex = 0;
|
|
2727
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2728
|
+
lineEndGraphemeIndex = 0;
|
|
2729
|
+
lineW = width;
|
|
2730
|
+
}
|
|
2731
|
+
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
2732
|
+
hasContent = true;
|
|
2733
|
+
lineStartSegmentIndex = segmentIndex;
|
|
2734
|
+
lineStartGraphemeIndex = graphemeIndex;
|
|
2735
|
+
lineEndSegmentIndex = segmentIndex;
|
|
2736
|
+
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
2737
|
+
lineW = width;
|
|
2738
|
+
}
|
|
2739
|
+
function appendWholeSegment(segmentIndex, width) {
|
|
2740
|
+
if (!hasContent) {
|
|
2741
|
+
startLineAtSegment(segmentIndex, width);
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
lineW += width;
|
|
2745
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2746
|
+
lineEndGraphemeIndex = 0;
|
|
2747
|
+
}
|
|
2748
|
+
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
2749
|
+
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
2750
|
+
const preferredBreaks = breakablePreferredBreaks[segmentIndex] ?? null;
|
|
2751
|
+
let preferredBreakIndex = preferredBreaks === null ? -1 : getNextPreferredBreakIndex(preferredBreaks, 0, startGraphemeIndex + 1);
|
|
2752
|
+
let lastPreferredBreakEnd = -1;
|
|
2753
|
+
let lastPreferredBreakWidth = 0;
|
|
2754
|
+
let g = startGraphemeIndex;
|
|
2755
|
+
while (g < fitAdvances.length) {
|
|
2756
|
+
const gw = fitAdvances[g];
|
|
2757
|
+
if (!hasContent) {
|
|
2758
|
+
startLineAtGrapheme(segmentIndex, g, gw);
|
|
2759
|
+
} else if (lineW + gw > fitLimit) {
|
|
2760
|
+
if (preferredBreaks !== null && lastPreferredBreakEnd > startGraphemeIndex) {
|
|
2761
|
+
emitCurrentLine(segmentIndex, lastPreferredBreakEnd, lastPreferredBreakWidth);
|
|
2762
|
+
g = lastPreferredBreakEnd;
|
|
2763
|
+
preferredBreakIndex = getNextPreferredBreakIndex(preferredBreaks, preferredBreakIndex, g + 1);
|
|
2764
|
+
lastPreferredBreakEnd = -1;
|
|
2765
|
+
lastPreferredBreakWidth = 0;
|
|
2766
|
+
continue;
|
|
2767
|
+
}
|
|
2768
|
+
emitCurrentLine();
|
|
2769
|
+
startLineAtGrapheme(segmentIndex, g, gw);
|
|
2770
|
+
} else {
|
|
2771
|
+
lineW += gw;
|
|
2772
|
+
lineEndSegmentIndex = segmentIndex;
|
|
2773
|
+
lineEndGraphemeIndex = g + 1;
|
|
2774
|
+
}
|
|
2775
|
+
const graphemeEnd = g + 1;
|
|
2776
|
+
if (preferredBreaks !== null && preferredBreaks[preferredBreakIndex] === graphemeEnd) {
|
|
2777
|
+
lastPreferredBreakEnd = graphemeEnd;
|
|
2778
|
+
lastPreferredBreakWidth = lineW;
|
|
2779
|
+
preferredBreakIndex++;
|
|
2780
|
+
}
|
|
2781
|
+
g++;
|
|
2782
|
+
}
|
|
2783
|
+
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
2784
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2785
|
+
lineEndGraphemeIndex = 0;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
let i = 0;
|
|
2789
|
+
while (i < widths.length) {
|
|
2790
|
+
if (!hasContent) {
|
|
2791
|
+
i = normalizeLineStartSegmentIndex(prepared, i);
|
|
2792
|
+
if (i >= widths.length)
|
|
2793
|
+
break;
|
|
2794
|
+
}
|
|
2795
|
+
const w = widths[i];
|
|
2796
|
+
const kind = kinds[i];
|
|
2797
|
+
const breakAfter = breaksAfter(kind);
|
|
2798
|
+
if (!hasContent) {
|
|
2799
|
+
if (w > fitLimit && breakableFitAdvances[i] !== null) {
|
|
2800
|
+
appendBreakableSegmentFrom(i, 0);
|
|
2801
|
+
} else {
|
|
2802
|
+
startLineAtSegment(i, w);
|
|
2803
|
+
}
|
|
2804
|
+
if (breakAfter) {
|
|
2805
|
+
pendingBreakSegmentIndex = i + 1;
|
|
2806
|
+
pendingBreakPaintWidth = lineW - w;
|
|
2807
|
+
}
|
|
2808
|
+
i++;
|
|
2809
|
+
continue;
|
|
2810
|
+
}
|
|
2811
|
+
const newW = lineW + w;
|
|
2812
|
+
if (newW > fitLimit) {
|
|
2813
|
+
if (breakAfter) {
|
|
2814
|
+
appendWholeSegment(i, w);
|
|
2815
|
+
emitCurrentLine(i + 1, 0, lineW - w);
|
|
2816
|
+
i++;
|
|
2817
|
+
continue;
|
|
2818
|
+
}
|
|
2819
|
+
if (pendingBreakSegmentIndex >= 0) {
|
|
2820
|
+
if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
|
|
2821
|
+
emitCurrentLine();
|
|
2822
|
+
continue;
|
|
2823
|
+
}
|
|
2824
|
+
emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
2825
|
+
continue;
|
|
2826
|
+
}
|
|
2827
|
+
if (w > fitLimit && breakableFitAdvances[i] !== null) {
|
|
2828
|
+
emitCurrentLine();
|
|
2829
|
+
appendBreakableSegmentFrom(i, 0);
|
|
2830
|
+
i++;
|
|
2831
|
+
continue;
|
|
2832
|
+
}
|
|
2833
|
+
emitCurrentLine();
|
|
2834
|
+
continue;
|
|
2835
|
+
}
|
|
2836
|
+
appendWholeSegment(i, w);
|
|
2837
|
+
if (breakAfter) {
|
|
2838
|
+
pendingBreakSegmentIndex = i + 1;
|
|
2839
|
+
pendingBreakPaintWidth = lineW - w;
|
|
2840
|
+
}
|
|
2841
|
+
i++;
|
|
2842
|
+
}
|
|
2843
|
+
if (hasContent)
|
|
2844
|
+
emitCurrentLine();
|
|
2845
|
+
return lineCount;
|
|
2846
|
+
}
|
|
2847
|
+
function walkPreparedLinesRaw(prepared, maxWidth, onLine) {
|
|
2848
|
+
if (prepared.simpleLineWalkFastPath) {
|
|
2849
|
+
return walkPreparedLinesSimple(prepared, maxWidth, onLine);
|
|
2850
|
+
}
|
|
2851
|
+
const { widths, kinds, breakableFitAdvances, breakablePreferredBreaks, discretionaryHyphenWidth, chunks } = prepared;
|
|
2852
|
+
if (widths.length === 0 || chunks.length === 0)
|
|
2853
|
+
return 0;
|
|
2854
|
+
const engineProfile = getEngineProfile();
|
|
2855
|
+
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
2856
|
+
const fitLimit = maxWidth + lineFitEpsilon;
|
|
2857
|
+
let lineCount = 0;
|
|
2858
|
+
let lineW = 0;
|
|
2859
|
+
let hasContent = false;
|
|
2860
|
+
let lineStartSegmentIndex = 0;
|
|
2861
|
+
let lineStartGraphemeIndex = 0;
|
|
2862
|
+
let lineEndSegmentIndex = 0;
|
|
2863
|
+
let lineEndGraphemeIndex = 0;
|
|
2864
|
+
let pendingBreakSegmentIndex = -1;
|
|
2865
|
+
let pendingBreakFitWidth = 0;
|
|
2866
|
+
let pendingBreakPaintWidth = 0;
|
|
2867
|
+
let pendingBreakKind = null;
|
|
2868
|
+
function clearPendingBreak() {
|
|
2869
|
+
pendingBreakSegmentIndex = -1;
|
|
2870
|
+
pendingBreakFitWidth = 0;
|
|
2871
|
+
pendingBreakPaintWidth = 0;
|
|
2872
|
+
pendingBreakKind = null;
|
|
2873
|
+
}
|
|
2874
|
+
function getCurrentLinePaintWidth() {
|
|
2875
|
+
return pendingBreakKind === "soft-hyphen" && pendingBreakSegmentIndex === lineEndSegmentIndex && lineEndGraphemeIndex === 0 ? pendingBreakPaintWidth : lineW;
|
|
2876
|
+
}
|
|
2877
|
+
function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width) {
|
|
2878
|
+
lineCount++;
|
|
2879
|
+
if (onLine !== undefined) {
|
|
2880
|
+
onLine(finalizeLinePaintWidth(prepared, width ?? getCurrentLinePaintWidth(), lineStartSegmentIndex, lineStartGraphemeIndex, endSegmentIndex, endGraphemeIndex), lineStartSegmentIndex, lineStartGraphemeIndex, endSegmentIndex, endGraphemeIndex);
|
|
2881
|
+
}
|
|
2882
|
+
lineW = 0;
|
|
2883
|
+
hasContent = false;
|
|
2884
|
+
clearPendingBreak();
|
|
2885
|
+
}
|
|
2886
|
+
function startLineAtSegment(segmentIndex, width) {
|
|
2887
|
+
hasContent = true;
|
|
2888
|
+
lineStartSegmentIndex = segmentIndex;
|
|
2889
|
+
lineStartGraphemeIndex = 0;
|
|
2890
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2891
|
+
lineEndGraphemeIndex = 0;
|
|
2892
|
+
lineW = width;
|
|
2893
|
+
}
|
|
2894
|
+
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
2895
|
+
hasContent = true;
|
|
2896
|
+
lineStartSegmentIndex = segmentIndex;
|
|
2897
|
+
lineStartGraphemeIndex = graphemeIndex;
|
|
2898
|
+
lineEndSegmentIndex = segmentIndex;
|
|
2899
|
+
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
2900
|
+
lineW = width;
|
|
2901
|
+
}
|
|
2902
|
+
function appendWholeSegment(segmentIndex, advance) {
|
|
2903
|
+
if (!hasContent) {
|
|
2904
|
+
startLineAtSegment(segmentIndex, advance);
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
lineW += advance;
|
|
2908
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2909
|
+
lineEndGraphemeIndex = 0;
|
|
2910
|
+
}
|
|
2911
|
+
function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth, leadingSpacing, advance) {
|
|
2912
|
+
if (!breakAfter)
|
|
2913
|
+
return;
|
|
2914
|
+
const fitAdvance = getBreakOpportunityFitContribution(prepared, kind, segmentIndex, leadingSpacing);
|
|
2915
|
+
const paintAdvance = getLineEndPaintContribution(prepared, kind, segmentIndex, leadingSpacing, segmentWidth);
|
|
2916
|
+
pendingBreakSegmentIndex = segmentIndex + 1;
|
|
2917
|
+
pendingBreakFitWidth = lineW - advance + fitAdvance;
|
|
2918
|
+
pendingBreakPaintWidth = lineW - advance + paintAdvance;
|
|
2919
|
+
pendingBreakKind = kind;
|
|
2920
|
+
}
|
|
2921
|
+
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
2922
|
+
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
2923
|
+
const preferredBreaks = breakablePreferredBreaks[segmentIndex] ?? null;
|
|
2924
|
+
let preferredBreakIndex = preferredBreaks === null ? -1 : getNextPreferredBreakIndex(preferredBreaks, 0, startGraphemeIndex + 1);
|
|
2925
|
+
let lastPreferredBreakEnd = -1;
|
|
2926
|
+
let lastPreferredBreakWidth = 0;
|
|
2927
|
+
let g = startGraphemeIndex;
|
|
2928
|
+
while (g < fitAdvances.length) {
|
|
2929
|
+
const baseGw = fitAdvances[g];
|
|
2930
|
+
if (!hasContent) {
|
|
2931
|
+
startLineAtGrapheme(segmentIndex, g, baseGw);
|
|
2932
|
+
} else {
|
|
2933
|
+
const gw = getBreakableGraphemeAdvance(prepared, true, baseGw);
|
|
2934
|
+
const candidatePaintWidth = lineW + gw;
|
|
2935
|
+
if (getBreakableCandidateFitWidth(prepared, candidatePaintWidth) > fitLimit) {
|
|
2936
|
+
if (preferredBreaks !== null && lastPreferredBreakEnd > startGraphemeIndex) {
|
|
2937
|
+
emitCurrentLine(segmentIndex, lastPreferredBreakEnd, lastPreferredBreakWidth);
|
|
2938
|
+
g = lastPreferredBreakEnd;
|
|
2939
|
+
preferredBreakIndex = getNextPreferredBreakIndex(preferredBreaks, preferredBreakIndex, g + 1);
|
|
2940
|
+
lastPreferredBreakEnd = -1;
|
|
2941
|
+
lastPreferredBreakWidth = 0;
|
|
2942
|
+
continue;
|
|
2943
|
+
}
|
|
2944
|
+
emitCurrentLine();
|
|
2945
|
+
startLineAtGrapheme(segmentIndex, g, baseGw);
|
|
2946
|
+
} else {
|
|
2947
|
+
lineW = candidatePaintWidth;
|
|
2948
|
+
lineEndSegmentIndex = segmentIndex;
|
|
2949
|
+
lineEndGraphemeIndex = g + 1;
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
const graphemeEnd = g + 1;
|
|
2953
|
+
if (preferredBreaks !== null && preferredBreaks[preferredBreakIndex] === graphemeEnd) {
|
|
2954
|
+
lastPreferredBreakEnd = graphemeEnd;
|
|
2955
|
+
lastPreferredBreakWidth = lineW;
|
|
2956
|
+
preferredBreakIndex++;
|
|
2957
|
+
}
|
|
2958
|
+
g++;
|
|
2959
|
+
}
|
|
2960
|
+
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
2961
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
2962
|
+
lineEndGraphemeIndex = 0;
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
function emitEmptyChunk(chunk) {
|
|
2966
|
+
lineCount++;
|
|
2967
|
+
onLine?.(0, chunk.startSegmentIndex, 0, chunk.consumedEndSegmentIndex, 0);
|
|
2968
|
+
clearPendingBreak();
|
|
2969
|
+
}
|
|
2970
|
+
for (let chunkIndex = 0;chunkIndex < chunks.length; chunkIndex++) {
|
|
2971
|
+
const chunk = chunks[chunkIndex];
|
|
2972
|
+
if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
|
|
2973
|
+
emitEmptyChunk(chunk);
|
|
2974
|
+
continue;
|
|
2975
|
+
}
|
|
2976
|
+
hasContent = false;
|
|
2977
|
+
lineW = 0;
|
|
2978
|
+
lineStartSegmentIndex = chunk.startSegmentIndex;
|
|
2979
|
+
lineStartGraphemeIndex = 0;
|
|
2980
|
+
lineEndSegmentIndex = chunk.startSegmentIndex;
|
|
2981
|
+
lineEndGraphemeIndex = 0;
|
|
2982
|
+
clearPendingBreak();
|
|
2983
|
+
let i = chunk.startSegmentIndex;
|
|
2984
|
+
while (i < chunk.endSegmentIndex) {
|
|
2985
|
+
if (!hasContent) {
|
|
2986
|
+
i = normalizeLineStartSegmentIndex(prepared, i, chunk.endSegmentIndex);
|
|
2987
|
+
if (i >= chunk.endSegmentIndex)
|
|
2988
|
+
break;
|
|
2989
|
+
}
|
|
2990
|
+
const kind = kinds[i];
|
|
2991
|
+
const breakAfter = breaksAfter(kind);
|
|
2992
|
+
const leadingSpacing = getLeadingLetterSpacing(prepared, hasContent, i);
|
|
2993
|
+
const w = kind === "tab" ? getTabAdvance(lineW + leadingSpacing, prepared.tabStopAdvance) : widths[i];
|
|
2994
|
+
const advance = leadingSpacing + w;
|
|
2995
|
+
const fitAdvance = getWholeSegmentFitContribution(prepared, kind, i, leadingSpacing, w);
|
|
2996
|
+
if (kind === "soft-hyphen") {
|
|
2997
|
+
if (hasContent) {
|
|
2998
|
+
lineEndSegmentIndex = i + 1;
|
|
2999
|
+
lineEndGraphemeIndex = 0;
|
|
3000
|
+
pendingBreakSegmentIndex = i + 1;
|
|
3001
|
+
pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
|
|
3002
|
+
pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
|
|
3003
|
+
pendingBreakKind = kind;
|
|
3004
|
+
}
|
|
3005
|
+
i++;
|
|
3006
|
+
continue;
|
|
3007
|
+
}
|
|
3008
|
+
if (!hasContent) {
|
|
3009
|
+
if (fitAdvance > fitLimit && breakableFitAdvances[i] !== null) {
|
|
3010
|
+
appendBreakableSegmentFrom(i, 0);
|
|
3011
|
+
} else {
|
|
3012
|
+
startLineAtSegment(i, w);
|
|
3013
|
+
}
|
|
3014
|
+
updatePendingBreakForWholeSegment(kind, breakAfter, i, w, leadingSpacing, advance);
|
|
3015
|
+
i++;
|
|
3016
|
+
continue;
|
|
3017
|
+
}
|
|
3018
|
+
const newFitW = lineW + fitAdvance;
|
|
3019
|
+
if (newFitW > fitLimit) {
|
|
3020
|
+
const currentBreakFitWidth = lineW + getBreakOpportunityFitContribution(prepared, kind, i, leadingSpacing);
|
|
3021
|
+
const currentBreakPaintWidth = lineW + getLineEndPaintContribution(prepared, kind, i, leadingSpacing, w);
|
|
3022
|
+
if (pendingBreakKind === "soft-hyphen" && engineProfile.preferEarlySoftHyphenBreak && pendingBreakFitWidth <= fitLimit) {
|
|
3023
|
+
emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3024
|
+
continue;
|
|
3025
|
+
}
|
|
3026
|
+
if (breakAfter && currentBreakFitWidth <= fitLimit) {
|
|
3027
|
+
appendWholeSegment(i, advance);
|
|
3028
|
+
emitCurrentLine(i + 1, 0, currentBreakPaintWidth);
|
|
3029
|
+
i++;
|
|
3030
|
+
continue;
|
|
3031
|
+
}
|
|
3032
|
+
if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
|
|
3033
|
+
if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
|
|
3034
|
+
emitCurrentLine();
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
const nextSegmentIndex = pendingBreakSegmentIndex;
|
|
3038
|
+
emitCurrentLine(nextSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3039
|
+
i = nextSegmentIndex;
|
|
3040
|
+
continue;
|
|
3041
|
+
}
|
|
3042
|
+
if (fitAdvance > fitLimit && breakableFitAdvances[i] !== null) {
|
|
3043
|
+
emitCurrentLine();
|
|
3044
|
+
appendBreakableSegmentFrom(i, 0);
|
|
3045
|
+
i++;
|
|
3046
|
+
continue;
|
|
3047
|
+
}
|
|
3048
|
+
emitCurrentLine();
|
|
3049
|
+
continue;
|
|
3050
|
+
}
|
|
3051
|
+
appendWholeSegment(i, advance);
|
|
3052
|
+
updatePendingBreakForWholeSegment(kind, breakAfter, i, w, leadingSpacing, advance);
|
|
3053
|
+
i++;
|
|
3054
|
+
}
|
|
3055
|
+
if (hasContent) {
|
|
3056
|
+
const finalPaintWidth = pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex ? pendingBreakPaintWidth : lineW;
|
|
3057
|
+
emitCurrentLine(chunk.consumedEndSegmentIndex, 0, finalPaintWidth);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
return lineCount;
|
|
3061
|
+
}
|
|
3062
|
+
function stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth) {
|
|
3063
|
+
const chunk = prepared.chunks[chunkIndex];
|
|
3064
|
+
if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
|
|
3065
|
+
cursor.segmentIndex = chunk.consumedEndSegmentIndex;
|
|
3066
|
+
cursor.graphemeIndex = 0;
|
|
3067
|
+
return 0;
|
|
3068
|
+
}
|
|
3069
|
+
const { widths, kinds, breakableFitAdvances, breakablePreferredBreaks, discretionaryHyphenWidth } = prepared;
|
|
3070
|
+
const engineProfile = getEngineProfile();
|
|
3071
|
+
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
3072
|
+
const fitLimit = maxWidth + lineFitEpsilon;
|
|
3073
|
+
const lineStartSegmentIndex = cursor.segmentIndex;
|
|
3074
|
+
const lineStartGraphemeIndex = cursor.graphemeIndex;
|
|
3075
|
+
let lineW = 0;
|
|
3076
|
+
let hasContent = false;
|
|
3077
|
+
let lineEndSegmentIndex = cursor.segmentIndex;
|
|
3078
|
+
let lineEndGraphemeIndex = cursor.graphemeIndex;
|
|
3079
|
+
let pendingBreakSegmentIndex = -1;
|
|
3080
|
+
let pendingBreakFitWidth = 0;
|
|
3081
|
+
let pendingBreakPaintWidth = 0;
|
|
3082
|
+
let pendingBreakKind = null;
|
|
3083
|
+
function getCurrentLinePaintWidth() {
|
|
3084
|
+
return pendingBreakKind === "soft-hyphen" && pendingBreakSegmentIndex === lineEndSegmentIndex && lineEndGraphemeIndex === 0 ? pendingBreakPaintWidth : lineW;
|
|
3085
|
+
}
|
|
3086
|
+
function finishLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width = getCurrentLinePaintWidth()) {
|
|
3087
|
+
if (!hasContent)
|
|
3088
|
+
return null;
|
|
3089
|
+
cursor.segmentIndex = endSegmentIndex;
|
|
3090
|
+
cursor.graphemeIndex = endGraphemeIndex;
|
|
3091
|
+
return finalizeLinePaintWidth(prepared, width, lineStartSegmentIndex, lineStartGraphemeIndex, endSegmentIndex, endGraphemeIndex);
|
|
3092
|
+
}
|
|
3093
|
+
function startLineAtSegment(segmentIndex, width) {
|
|
3094
|
+
hasContent = true;
|
|
3095
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
3096
|
+
lineEndGraphemeIndex = 0;
|
|
3097
|
+
lineW = width;
|
|
3098
|
+
}
|
|
3099
|
+
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
3100
|
+
hasContent = true;
|
|
3101
|
+
lineEndSegmentIndex = segmentIndex;
|
|
3102
|
+
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
3103
|
+
lineW = width;
|
|
3104
|
+
}
|
|
3105
|
+
function appendWholeSegment(segmentIndex, advance) {
|
|
3106
|
+
if (!hasContent) {
|
|
3107
|
+
startLineAtSegment(segmentIndex, advance);
|
|
3108
|
+
return;
|
|
3109
|
+
}
|
|
3110
|
+
lineW += advance;
|
|
3111
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
3112
|
+
lineEndGraphemeIndex = 0;
|
|
3113
|
+
}
|
|
3114
|
+
function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth, leadingSpacing, advance) {
|
|
3115
|
+
if (!breakAfter)
|
|
3116
|
+
return;
|
|
3117
|
+
const fitAdvance = getBreakOpportunityFitContribution(prepared, kind, segmentIndex, leadingSpacing);
|
|
3118
|
+
const paintAdvance = getLineEndPaintContribution(prepared, kind, segmentIndex, leadingSpacing, segmentWidth);
|
|
3119
|
+
pendingBreakSegmentIndex = segmentIndex + 1;
|
|
3120
|
+
pendingBreakFitWidth = lineW - advance + fitAdvance;
|
|
3121
|
+
pendingBreakPaintWidth = lineW - advance + paintAdvance;
|
|
3122
|
+
pendingBreakKind = kind;
|
|
3123
|
+
}
|
|
3124
|
+
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
3125
|
+
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
3126
|
+
const preferredBreaks = breakablePreferredBreaks[segmentIndex] ?? null;
|
|
3127
|
+
let preferredBreakIndex = preferredBreaks === null ? -1 : getNextPreferredBreakIndex(preferredBreaks, 0, startGraphemeIndex + 1);
|
|
3128
|
+
let lastPreferredBreakEnd = -1;
|
|
3129
|
+
let lastPreferredBreakWidth = 0;
|
|
3130
|
+
for (let g = startGraphemeIndex;g < fitAdvances.length; g++) {
|
|
3131
|
+
const baseGw = fitAdvances[g];
|
|
3132
|
+
if (!hasContent) {
|
|
3133
|
+
startLineAtGrapheme(segmentIndex, g, baseGw);
|
|
3134
|
+
} else {
|
|
3135
|
+
const gw = getBreakableGraphemeAdvance(prepared, true, baseGw);
|
|
3136
|
+
const candidatePaintWidth = lineW + gw;
|
|
3137
|
+
if (getBreakableCandidateFitWidth(prepared, candidatePaintWidth) > fitLimit) {
|
|
3138
|
+
if (preferredBreaks !== null && lastPreferredBreakEnd > startGraphemeIndex) {
|
|
3139
|
+
return finishLine(segmentIndex, lastPreferredBreakEnd, lastPreferredBreakWidth);
|
|
3140
|
+
}
|
|
3141
|
+
return finishLine();
|
|
3142
|
+
}
|
|
3143
|
+
lineW = candidatePaintWidth;
|
|
3144
|
+
lineEndSegmentIndex = segmentIndex;
|
|
3145
|
+
lineEndGraphemeIndex = g + 1;
|
|
3146
|
+
}
|
|
3147
|
+
const graphemeEnd = g + 1;
|
|
3148
|
+
if (preferredBreaks !== null && preferredBreaks[preferredBreakIndex] === graphemeEnd) {
|
|
3149
|
+
lastPreferredBreakEnd = graphemeEnd;
|
|
3150
|
+
lastPreferredBreakWidth = lineW;
|
|
3151
|
+
preferredBreakIndex++;
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
3155
|
+
lineEndSegmentIndex = segmentIndex + 1;
|
|
3156
|
+
lineEndGraphemeIndex = 0;
|
|
3157
|
+
}
|
|
3158
|
+
return null;
|
|
3159
|
+
}
|
|
3160
|
+
function maybeFinishAtSoftHyphen() {
|
|
3161
|
+
if (pendingBreakKind !== "soft-hyphen" || pendingBreakSegmentIndex < 0)
|
|
3162
|
+
return null;
|
|
3163
|
+
if (pendingBreakFitWidth <= fitLimit) {
|
|
3164
|
+
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3165
|
+
}
|
|
3166
|
+
return null;
|
|
3167
|
+
}
|
|
3168
|
+
for (let i = cursor.segmentIndex;i < chunk.endSegmentIndex; i++) {
|
|
3169
|
+
const kind = kinds[i];
|
|
3170
|
+
const breakAfter = breaksAfter(kind);
|
|
3171
|
+
const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
|
|
3172
|
+
const leadingSpacing = getLeadingLetterSpacing(prepared, hasContent, i);
|
|
3173
|
+
const w = kind === "tab" ? getTabAdvance(lineW + leadingSpacing, prepared.tabStopAdvance) : widths[i];
|
|
3174
|
+
const advance = leadingSpacing + w;
|
|
3175
|
+
const fitAdvance = getWholeSegmentFitContribution(prepared, kind, i, leadingSpacing, w);
|
|
3176
|
+
if (kind === "soft-hyphen" && startGraphemeIndex === 0) {
|
|
3177
|
+
if (hasContent) {
|
|
3178
|
+
lineEndSegmentIndex = i + 1;
|
|
3179
|
+
lineEndGraphemeIndex = 0;
|
|
3180
|
+
pendingBreakSegmentIndex = i + 1;
|
|
3181
|
+
pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
|
|
3182
|
+
pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
|
|
3183
|
+
pendingBreakKind = kind;
|
|
3184
|
+
}
|
|
3185
|
+
continue;
|
|
3186
|
+
}
|
|
3187
|
+
if (!hasContent) {
|
|
3188
|
+
if (startGraphemeIndex > 0) {
|
|
3189
|
+
const line = appendBreakableSegmentFrom(i, startGraphemeIndex);
|
|
3190
|
+
if (line !== null)
|
|
3191
|
+
return line;
|
|
3192
|
+
} else if (fitAdvance > fitLimit && breakableFitAdvances[i] !== null) {
|
|
3193
|
+
const line = appendBreakableSegmentFrom(i, 0);
|
|
3194
|
+
if (line !== null)
|
|
3195
|
+
return line;
|
|
3196
|
+
} else {
|
|
3197
|
+
startLineAtSegment(i, w);
|
|
3198
|
+
}
|
|
3199
|
+
updatePendingBreakForWholeSegment(kind, breakAfter, i, w, leadingSpacing, advance);
|
|
3200
|
+
continue;
|
|
3201
|
+
}
|
|
3202
|
+
const newFitW = lineW + fitAdvance;
|
|
3203
|
+
if (newFitW > fitLimit) {
|
|
3204
|
+
const currentBreakFitWidth = lineW + getBreakOpportunityFitContribution(prepared, kind, i, leadingSpacing);
|
|
3205
|
+
const currentBreakPaintWidth = lineW + getLineEndPaintContribution(prepared, kind, i, leadingSpacing, w);
|
|
3206
|
+
if (pendingBreakKind === "soft-hyphen" && engineProfile.preferEarlySoftHyphenBreak && pendingBreakFitWidth <= fitLimit) {
|
|
3207
|
+
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3208
|
+
}
|
|
3209
|
+
const softBreakLine = maybeFinishAtSoftHyphen();
|
|
3210
|
+
if (softBreakLine !== null)
|
|
3211
|
+
return softBreakLine;
|
|
3212
|
+
if (breakAfter && currentBreakFitWidth <= fitLimit) {
|
|
3213
|
+
appendWholeSegment(i, advance);
|
|
3214
|
+
return finishLine(i + 1, 0, currentBreakPaintWidth);
|
|
3215
|
+
}
|
|
3216
|
+
if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
|
|
3217
|
+
if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
|
|
3218
|
+
return finishLine();
|
|
3219
|
+
}
|
|
3220
|
+
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3221
|
+
}
|
|
3222
|
+
if (fitAdvance > fitLimit && breakableFitAdvances[i] !== null) {
|
|
3223
|
+
const currentLine = finishLine();
|
|
3224
|
+
if (currentLine !== null)
|
|
3225
|
+
return currentLine;
|
|
3226
|
+
const line = appendBreakableSegmentFrom(i, 0);
|
|
3227
|
+
if (line !== null)
|
|
3228
|
+
return line;
|
|
3229
|
+
}
|
|
3230
|
+
return finishLine();
|
|
3231
|
+
}
|
|
3232
|
+
appendWholeSegment(i, advance);
|
|
3233
|
+
updatePendingBreakForWholeSegment(kind, breakAfter, i, w, leadingSpacing, advance);
|
|
3234
|
+
}
|
|
3235
|
+
if (pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex && lineEndGraphemeIndex === 0) {
|
|
3236
|
+
return finishLine(chunk.consumedEndSegmentIndex, 0, pendingBreakPaintWidth);
|
|
3237
|
+
}
|
|
3238
|
+
return finishLine(chunk.consumedEndSegmentIndex, 0, lineW);
|
|
3239
|
+
}
|
|
3240
|
+
function stepPreparedSimpleLineGeometry(prepared, cursor, maxWidth) {
|
|
3241
|
+
const { widths, kinds, breakableFitAdvances, breakablePreferredBreaks } = prepared;
|
|
3242
|
+
const engineProfile = getEngineProfile();
|
|
3243
|
+
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
3244
|
+
const fitLimit = maxWidth + lineFitEpsilon;
|
|
3245
|
+
let lineW = 0;
|
|
3246
|
+
let hasContent = false;
|
|
3247
|
+
let lineEndSegmentIndex = cursor.segmentIndex;
|
|
3248
|
+
let lineEndGraphemeIndex = cursor.graphemeIndex;
|
|
3249
|
+
let pendingBreakSegmentIndex = -1;
|
|
3250
|
+
let pendingBreakPaintWidth = 0;
|
|
3251
|
+
for (let i = cursor.segmentIndex;i < widths.length; i++) {
|
|
3252
|
+
const kind = kinds[i];
|
|
3253
|
+
const breakAfter = breaksAfter(kind);
|
|
3254
|
+
const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
|
|
3255
|
+
const breakableFitAdvance = breakableFitAdvances[i];
|
|
3256
|
+
const w = widths[i];
|
|
3257
|
+
if (!hasContent) {
|
|
3258
|
+
if (startGraphemeIndex > 0 || w > fitLimit && breakableFitAdvance !== null) {
|
|
3259
|
+
const fitAdvances = breakableFitAdvance;
|
|
3260
|
+
const preferredBreaks = breakablePreferredBreaks[i] ?? null;
|
|
3261
|
+
let preferredBreakIndex = preferredBreaks === null ? -1 : getNextPreferredBreakIndex(preferredBreaks, 0, startGraphemeIndex + 1);
|
|
3262
|
+
let lastPreferredBreakEnd = -1;
|
|
3263
|
+
let lastPreferredBreakWidth = 0;
|
|
3264
|
+
const firstGraphemeWidth = fitAdvances[startGraphemeIndex];
|
|
3265
|
+
hasContent = true;
|
|
3266
|
+
lineW = firstGraphemeWidth;
|
|
3267
|
+
lineEndSegmentIndex = i;
|
|
3268
|
+
lineEndGraphemeIndex = startGraphemeIndex + 1;
|
|
3269
|
+
if (preferredBreaks !== null && preferredBreaks[preferredBreakIndex] === lineEndGraphemeIndex) {
|
|
3270
|
+
lastPreferredBreakEnd = lineEndGraphemeIndex;
|
|
3271
|
+
lastPreferredBreakWidth = lineW;
|
|
3272
|
+
preferredBreakIndex++;
|
|
3273
|
+
}
|
|
3274
|
+
for (let g = startGraphemeIndex + 1;g < fitAdvances.length; g++) {
|
|
3275
|
+
const gw = fitAdvances[g];
|
|
3276
|
+
if (lineW + gw > fitLimit) {
|
|
3277
|
+
if (preferredBreaks !== null && lastPreferredBreakEnd > startGraphemeIndex) {
|
|
3278
|
+
cursor.segmentIndex = i;
|
|
3279
|
+
cursor.graphemeIndex = lastPreferredBreakEnd;
|
|
3280
|
+
return lastPreferredBreakWidth;
|
|
3281
|
+
}
|
|
3282
|
+
cursor.segmentIndex = lineEndSegmentIndex;
|
|
3283
|
+
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
3284
|
+
return lineW;
|
|
3285
|
+
}
|
|
3286
|
+
lineW += gw;
|
|
3287
|
+
lineEndSegmentIndex = i;
|
|
3288
|
+
lineEndGraphemeIndex = g + 1;
|
|
3289
|
+
if (preferredBreaks !== null && preferredBreaks[preferredBreakIndex] === lineEndGraphemeIndex) {
|
|
3290
|
+
lastPreferredBreakEnd = lineEndGraphemeIndex;
|
|
3291
|
+
lastPreferredBreakWidth = lineW;
|
|
3292
|
+
preferredBreakIndex++;
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
if (lineEndSegmentIndex === i && lineEndGraphemeIndex === fitAdvances.length) {
|
|
3296
|
+
lineEndSegmentIndex = i + 1;
|
|
3297
|
+
lineEndGraphemeIndex = 0;
|
|
3298
|
+
}
|
|
3299
|
+
} else {
|
|
3300
|
+
hasContent = true;
|
|
3301
|
+
lineW = w;
|
|
3302
|
+
lineEndSegmentIndex = i + 1;
|
|
3303
|
+
lineEndGraphemeIndex = 0;
|
|
3304
|
+
}
|
|
3305
|
+
if (breakAfter) {
|
|
3306
|
+
pendingBreakSegmentIndex = i + 1;
|
|
3307
|
+
pendingBreakPaintWidth = lineW - w;
|
|
3308
|
+
}
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
if (lineW + w > fitLimit) {
|
|
3312
|
+
if (breakAfter) {
|
|
3313
|
+
cursor.segmentIndex = i + 1;
|
|
3314
|
+
cursor.graphemeIndex = 0;
|
|
3315
|
+
return lineW;
|
|
3316
|
+
}
|
|
3317
|
+
if (pendingBreakSegmentIndex >= 0) {
|
|
3318
|
+
if (lineEndSegmentIndex > pendingBreakSegmentIndex || lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0) {
|
|
3319
|
+
cursor.segmentIndex = lineEndSegmentIndex;
|
|
3320
|
+
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
3321
|
+
return lineW;
|
|
3322
|
+
}
|
|
3323
|
+
cursor.segmentIndex = pendingBreakSegmentIndex;
|
|
3324
|
+
cursor.graphemeIndex = 0;
|
|
3325
|
+
return pendingBreakPaintWidth;
|
|
3326
|
+
}
|
|
3327
|
+
cursor.segmentIndex = lineEndSegmentIndex;
|
|
3328
|
+
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
3329
|
+
return lineW;
|
|
3330
|
+
}
|
|
3331
|
+
lineW += w;
|
|
3332
|
+
lineEndSegmentIndex = i + 1;
|
|
3333
|
+
lineEndGraphemeIndex = 0;
|
|
3334
|
+
if (breakAfter) {
|
|
3335
|
+
pendingBreakSegmentIndex = i + 1;
|
|
3336
|
+
pendingBreakPaintWidth = lineW - w;
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
if (!hasContent)
|
|
3340
|
+
return null;
|
|
3341
|
+
cursor.segmentIndex = lineEndSegmentIndex;
|
|
3342
|
+
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
3343
|
+
return lineW;
|
|
3344
|
+
}
|
|
3345
|
+
function stepPreparedLineGeometryFromChunk(prepared, cursor, chunkIndex, maxWidth) {
|
|
3346
|
+
if (prepared.simpleLineWalkFastPath) {
|
|
3347
|
+
return stepPreparedSimpleLineGeometry(prepared, cursor, maxWidth);
|
|
3348
|
+
}
|
|
3349
|
+
return stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth);
|
|
3350
|
+
}
|
|
3351
|
+
function stepPreparedLineGeometry(prepared, cursor, maxWidth) {
|
|
3352
|
+
const chunkIndex = normalizePreparedLineStart(prepared, cursor);
|
|
3353
|
+
if (chunkIndex < 0)
|
|
3354
|
+
return null;
|
|
3355
|
+
return stepPreparedLineGeometryFromChunk(prepared, cursor, chunkIndex, maxWidth);
|
|
3356
|
+
}
|
|
3357
|
+
function measurePreparedLineGeometry(prepared, maxWidth) {
|
|
3358
|
+
if (prepared.widths.length === 0) {
|
|
3359
|
+
return {
|
|
3360
|
+
lineCount: 0,
|
|
3361
|
+
maxLineWidth: 0
|
|
3362
|
+
};
|
|
3363
|
+
}
|
|
3364
|
+
const cursor = {
|
|
3365
|
+
segmentIndex: 0,
|
|
3366
|
+
graphemeIndex: 0
|
|
3367
|
+
};
|
|
3368
|
+
let lineCount = 0;
|
|
3369
|
+
let maxLineWidth = 0;
|
|
3370
|
+
if (!prepared.simpleLineWalkFastPath) {
|
|
3371
|
+
let chunkIndex = normalizePreparedLineStart(prepared, cursor);
|
|
3372
|
+
while (chunkIndex >= 0) {
|
|
3373
|
+
const lineWidth = stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth);
|
|
3374
|
+
if (lineWidth === null) {
|
|
3375
|
+
return {
|
|
3376
|
+
lineCount,
|
|
3377
|
+
maxLineWidth
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
lineCount++;
|
|
3381
|
+
if (lineWidth > maxLineWidth)
|
|
3382
|
+
maxLineWidth = lineWidth;
|
|
3383
|
+
chunkIndex = normalizeLineStartChunkIndexFromHint(prepared, chunkIndex, cursor);
|
|
3384
|
+
}
|
|
3385
|
+
return {
|
|
3386
|
+
lineCount,
|
|
3387
|
+
maxLineWidth
|
|
3388
|
+
};
|
|
3389
|
+
}
|
|
3390
|
+
while (true) {
|
|
3391
|
+
const lineWidth = stepPreparedLineGeometry(prepared, cursor, maxWidth);
|
|
3392
|
+
if (lineWidth === null) {
|
|
3393
|
+
return {
|
|
3394
|
+
lineCount,
|
|
3395
|
+
maxLineWidth
|
|
3396
|
+
};
|
|
3397
|
+
}
|
|
3398
|
+
lineCount++;
|
|
3399
|
+
if (lineWidth > maxLineWidth)
|
|
3400
|
+
maxLineWidth = lineWidth;
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
var init_line_break = __esm(() => {
|
|
3404
|
+
init_measurement();
|
|
3405
|
+
});
|
|
3406
|
+
|
|
3407
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/line-text.js
|
|
3408
|
+
function getSharedGraphemeSegmenter2() {
|
|
3409
|
+
if (sharedGraphemeSegmenter2 === null) {
|
|
3410
|
+
sharedGraphemeSegmenter2 = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
3411
|
+
}
|
|
3412
|
+
return sharedGraphemeSegmenter2;
|
|
3413
|
+
}
|
|
3414
|
+
function getSegmentGraphemes(segmentIndex, segments, cache) {
|
|
3415
|
+
let graphemes = cache.get(segmentIndex);
|
|
3416
|
+
if (graphemes !== undefined)
|
|
3417
|
+
return graphemes;
|
|
3418
|
+
graphemes = [];
|
|
3419
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter2();
|
|
3420
|
+
for (const gs of graphemeSegmenter.segment(segments[segmentIndex])) {
|
|
3421
|
+
graphemes.push(gs.segment);
|
|
3422
|
+
}
|
|
3423
|
+
cache.set(segmentIndex, graphemes);
|
|
3424
|
+
return graphemes;
|
|
3425
|
+
}
|
|
3426
|
+
function lineHasDiscretionaryHyphen(kinds, startSegmentIndex, endSegmentIndex) {
|
|
3427
|
+
return endSegmentIndex > startSegmentIndex && kinds[endSegmentIndex - 1] === "soft-hyphen";
|
|
3428
|
+
}
|
|
3429
|
+
function appendSegmentGraphemeRange(text, graphemes, startGraphemeIndex, endGraphemeIndex) {
|
|
3430
|
+
for (let i = startGraphemeIndex;i < endGraphemeIndex; i++) {
|
|
3431
|
+
text += graphemes[i];
|
|
3432
|
+
}
|
|
3433
|
+
return text;
|
|
3434
|
+
}
|
|
3435
|
+
function getLineTextCache(prepared) {
|
|
3436
|
+
let cache = sharedLineTextCaches.get(prepared);
|
|
3437
|
+
if (cache !== undefined)
|
|
3438
|
+
return cache;
|
|
3439
|
+
cache = new Map;
|
|
3440
|
+
sharedLineTextCaches.set(prepared, cache);
|
|
3441
|
+
return cache;
|
|
3442
|
+
}
|
|
3443
|
+
function buildLineTextFromRange(prepared, cache, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
|
|
3444
|
+
let text = "";
|
|
3445
|
+
const endsWithDiscretionaryHyphen = lineHasDiscretionaryHyphen(prepared.kinds, startSegmentIndex, endSegmentIndex);
|
|
3446
|
+
for (let i = startSegmentIndex;i < endSegmentIndex; i++) {
|
|
3447
|
+
if (prepared.kinds[i] === "soft-hyphen" || prepared.kinds[i] === "hard-break")
|
|
3448
|
+
continue;
|
|
3449
|
+
if (i === startSegmentIndex && startGraphemeIndex > 0) {
|
|
3450
|
+
const graphemes = getSegmentGraphemes(i, prepared.segments, cache);
|
|
3451
|
+
text = appendSegmentGraphemeRange(text, graphemes, startGraphemeIndex, graphemes.length);
|
|
3452
|
+
} else {
|
|
3453
|
+
text += prepared.segments[i];
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
if (endGraphemeIndex > 0) {
|
|
3457
|
+
if (endsWithDiscretionaryHyphen)
|
|
3458
|
+
text += "-";
|
|
3459
|
+
const graphemes = getSegmentGraphemes(endSegmentIndex, prepared.segments, cache);
|
|
3460
|
+
text = appendSegmentGraphemeRange(text, graphemes, startSegmentIndex === endSegmentIndex ? startGraphemeIndex : 0, endGraphemeIndex);
|
|
3461
|
+
} else if (endsWithDiscretionaryHyphen) {
|
|
3462
|
+
text += "-";
|
|
3463
|
+
}
|
|
3464
|
+
return text;
|
|
3465
|
+
}
|
|
3466
|
+
function clearLineTextCaches() {
|
|
3467
|
+
sharedGraphemeSegmenter2 = null;
|
|
3468
|
+
sharedLineTextCaches = new WeakMap;
|
|
3469
|
+
}
|
|
3470
|
+
var sharedGraphemeSegmenter2 = null, sharedLineTextCaches;
|
|
3471
|
+
var init_line_text = __esm(() => {
|
|
3472
|
+
sharedLineTextCaches = new WeakMap;
|
|
3473
|
+
});
|
|
3474
|
+
|
|
3475
|
+
// ../../node_modules/.bun/@chenglou+pretext@0.0.8/node_modules/@chenglou/pretext/dist/layout.js
|
|
3476
|
+
var exports_layout = {};
|
|
3477
|
+
__export(exports_layout, {
|
|
3478
|
+
walkLineRanges: () => walkLineRanges,
|
|
3479
|
+
setLocale: () => setLocale,
|
|
3480
|
+
prepareWithSegments: () => prepareWithSegments,
|
|
3481
|
+
prepare: () => prepare,
|
|
3482
|
+
measureNaturalWidth: () => measureNaturalWidth,
|
|
3483
|
+
measureLineStats: () => measureLineStats,
|
|
3484
|
+
materializeLineRange: () => materializeLineRange,
|
|
3485
|
+
layoutWithLines: () => layoutWithLines,
|
|
3486
|
+
layoutNextLineRange: () => layoutNextLineRange,
|
|
3487
|
+
layoutNextLine: () => layoutNextLine,
|
|
3488
|
+
layout: () => layout,
|
|
3489
|
+
clearCache: () => clearCache
|
|
3490
|
+
});
|
|
3491
|
+
function getSharedGraphemeSegmenter3() {
|
|
3492
|
+
if (sharedGraphemeSegmenter3 === null) {
|
|
3493
|
+
sharedGraphemeSegmenter3 = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
3494
|
+
}
|
|
3495
|
+
return sharedGraphemeSegmenter3;
|
|
3496
|
+
}
|
|
3497
|
+
function createEmptyPrepared(includeSegments) {
|
|
3498
|
+
if (includeSegments) {
|
|
3499
|
+
return {
|
|
3500
|
+
widths: [],
|
|
3501
|
+
lineEndFitAdvances: [],
|
|
3502
|
+
lineEndPaintAdvances: [],
|
|
3503
|
+
kinds: [],
|
|
3504
|
+
simpleLineWalkFastPath: true,
|
|
3505
|
+
segLevels: null,
|
|
3506
|
+
breakableFitAdvances: [],
|
|
3507
|
+
breakablePreferredBreaks: [],
|
|
3508
|
+
letterSpacing: 0,
|
|
3509
|
+
spacingGraphemeCounts: [],
|
|
3510
|
+
discretionaryHyphenWidth: 0,
|
|
3511
|
+
tabStopAdvance: 0,
|
|
3512
|
+
chunks: [],
|
|
3513
|
+
segments: []
|
|
3514
|
+
};
|
|
3515
|
+
}
|
|
3516
|
+
return {
|
|
3517
|
+
widths: [],
|
|
3518
|
+
lineEndFitAdvances: [],
|
|
3519
|
+
lineEndPaintAdvances: [],
|
|
3520
|
+
kinds: [],
|
|
3521
|
+
simpleLineWalkFastPath: true,
|
|
3522
|
+
segLevels: null,
|
|
3523
|
+
breakableFitAdvances: [],
|
|
3524
|
+
breakablePreferredBreaks: [],
|
|
3525
|
+
letterSpacing: 0,
|
|
3526
|
+
spacingGraphemeCounts: [],
|
|
3527
|
+
discretionaryHyphenWidth: 0,
|
|
3528
|
+
tabStopAdvance: 0,
|
|
3529
|
+
chunks: []
|
|
3530
|
+
};
|
|
3531
|
+
}
|
|
3532
|
+
function buildBaseCjkUnits(segText, engineProfile) {
|
|
3533
|
+
const units = [];
|
|
3534
|
+
let unitParts = [];
|
|
3535
|
+
let unitStart = 0;
|
|
3536
|
+
let unitContainsCJK = false;
|
|
3537
|
+
let unitEndsWithClosingQuote = false;
|
|
3538
|
+
let unitIsSingleKinsokuEnd = false;
|
|
3539
|
+
function pushUnit() {
|
|
3540
|
+
if (unitParts.length === 0)
|
|
3541
|
+
return;
|
|
3542
|
+
units.push({
|
|
3543
|
+
text: unitParts.length === 1 ? unitParts[0] : unitParts.join(""),
|
|
3544
|
+
start: unitStart
|
|
3545
|
+
});
|
|
3546
|
+
unitParts = [];
|
|
3547
|
+
unitContainsCJK = false;
|
|
3548
|
+
unitEndsWithClosingQuote = false;
|
|
3549
|
+
unitIsSingleKinsokuEnd = false;
|
|
3550
|
+
}
|
|
3551
|
+
function startUnit(grapheme, start, graphemeContainsCJK) {
|
|
3552
|
+
unitParts = [grapheme];
|
|
3553
|
+
unitStart = start;
|
|
3554
|
+
unitContainsCJK = graphemeContainsCJK;
|
|
3555
|
+
unitEndsWithClosingQuote = endsWithClosingQuote(grapheme);
|
|
3556
|
+
unitIsSingleKinsokuEnd = kinsokuEnd.has(grapheme);
|
|
3557
|
+
}
|
|
3558
|
+
function appendToUnit(grapheme, graphemeContainsCJK) {
|
|
3559
|
+
unitParts.push(grapheme);
|
|
3560
|
+
unitContainsCJK = unitContainsCJK || graphemeContainsCJK;
|
|
3561
|
+
const graphemeEndsWithClosingQuote = endsWithClosingQuote(grapheme);
|
|
3562
|
+
if (grapheme.length === 1 && leftStickyPunctuation.has(grapheme)) {
|
|
3563
|
+
unitEndsWithClosingQuote = unitEndsWithClosingQuote || graphemeEndsWithClosingQuote;
|
|
3564
|
+
} else {
|
|
3565
|
+
unitEndsWithClosingQuote = graphemeEndsWithClosingQuote;
|
|
3566
|
+
}
|
|
3567
|
+
unitIsSingleKinsokuEnd = false;
|
|
3568
|
+
}
|
|
3569
|
+
for (const gs of getSharedGraphemeSegmenter3().segment(segText)) {
|
|
3570
|
+
const grapheme = gs.segment;
|
|
3571
|
+
const graphemeContainsCJK = isCJK(grapheme);
|
|
3572
|
+
if (unitParts.length === 0) {
|
|
3573
|
+
startUnit(grapheme, gs.index, graphemeContainsCJK);
|
|
3574
|
+
continue;
|
|
3575
|
+
}
|
|
3576
|
+
if (unitIsSingleKinsokuEnd || kinsokuStart.has(grapheme) || leftStickyPunctuation.has(grapheme) || engineProfile.carryCJKAfterClosingQuote && graphemeContainsCJK && unitEndsWithClosingQuote) {
|
|
3577
|
+
appendToUnit(grapheme, graphemeContainsCJK);
|
|
3578
|
+
continue;
|
|
3579
|
+
}
|
|
3580
|
+
if (!unitContainsCJK && !graphemeContainsCJK) {
|
|
3581
|
+
appendToUnit(grapheme, graphemeContainsCJK);
|
|
3582
|
+
continue;
|
|
3583
|
+
}
|
|
3584
|
+
pushUnit();
|
|
3585
|
+
startUnit(grapheme, gs.index, graphemeContainsCJK);
|
|
3586
|
+
}
|
|
3587
|
+
pushUnit();
|
|
3588
|
+
return units;
|
|
3589
|
+
}
|
|
3590
|
+
function mergeKeepAllTextUnits(segText, units, breakAfterPunctuation) {
|
|
3591
|
+
if (units.length <= 1)
|
|
3592
|
+
return units;
|
|
3593
|
+
const merged = [];
|
|
3594
|
+
let groupStart = -1;
|
|
3595
|
+
let groupContainsCJK = false;
|
|
3596
|
+
function pushMergedUnit(start, end) {
|
|
3597
|
+
const sourceStart = units[start].start;
|
|
3598
|
+
const sourceEnd = end < units.length ? units[end].start : segText.length;
|
|
3599
|
+
merged.push({
|
|
3600
|
+
text: segText.slice(sourceStart, sourceEnd),
|
|
3601
|
+
start: sourceStart
|
|
3602
|
+
});
|
|
3603
|
+
}
|
|
3604
|
+
function flushGroup(end) {
|
|
3605
|
+
if (groupStart < 0)
|
|
3606
|
+
return;
|
|
3607
|
+
if (groupContainsCJK) {
|
|
3608
|
+
if (groupStart + 1 === end) {
|
|
3609
|
+
merged.push(units[groupStart]);
|
|
3610
|
+
} else {
|
|
3611
|
+
pushMergedUnit(groupStart, end);
|
|
3612
|
+
}
|
|
3613
|
+
} else {
|
|
3614
|
+
for (let i = groupStart;i < end; i++)
|
|
3615
|
+
merged.push(units[i]);
|
|
3616
|
+
}
|
|
3617
|
+
groupStart = -1;
|
|
3618
|
+
groupContainsCJK = false;
|
|
3619
|
+
}
|
|
3620
|
+
for (let i = 0;i < units.length; i++) {
|
|
3621
|
+
const unit = units[i];
|
|
3622
|
+
if (groupStart >= 0 && !canContinueKeepAllTextRun(units[i - 1].text, breakAfterPunctuation)) {
|
|
3623
|
+
flushGroup(i);
|
|
3624
|
+
}
|
|
3625
|
+
if (groupStart < 0)
|
|
3626
|
+
groupStart = i;
|
|
3627
|
+
groupContainsCJK = groupContainsCJK || isCJK(unit.text);
|
|
3628
|
+
}
|
|
3629
|
+
flushGroup(units.length);
|
|
3630
|
+
return merged;
|
|
3631
|
+
}
|
|
3632
|
+
function countRenderedSpacingGraphemes(text, kind) {
|
|
3633
|
+
if (kind === "zero-width-break" || kind === "soft-hyphen" || kind === "hard-break") {
|
|
3634
|
+
return 0;
|
|
3635
|
+
}
|
|
3636
|
+
if (kind === "tab")
|
|
3637
|
+
return 1;
|
|
3638
|
+
let count = 0;
|
|
3639
|
+
const graphemeSegmenter = getSharedGraphemeSegmenter3();
|
|
3640
|
+
for (const _ of graphemeSegmenter.segment(text))
|
|
3641
|
+
count++;
|
|
3642
|
+
return count;
|
|
3643
|
+
}
|
|
3644
|
+
function isPreferredBreakGrapheme(grapheme) {
|
|
3645
|
+
return grapheme === "-" || grapheme === "\u058A" || grapheme === "\u2010" || grapheme === "\u2012" || grapheme === "\u2013" || grapheme === "\u2014";
|
|
3646
|
+
}
|
|
3647
|
+
function getBreakablePreferredBreaks(text) {
|
|
3648
|
+
if (!/[-\u058A\u2010\u2012\u2013\u2014]/u.test(text))
|
|
3649
|
+
return null;
|
|
3650
|
+
const breaks = [];
|
|
3651
|
+
let graphemeIndex = 0;
|
|
3652
|
+
for (const gs of getSharedGraphemeSegmenter3().segment(text)) {
|
|
3653
|
+
graphemeIndex++;
|
|
3654
|
+
if (isPreferredBreakGrapheme(gs.segment))
|
|
3655
|
+
breaks.push(graphemeIndex);
|
|
3656
|
+
}
|
|
3657
|
+
return breaks.length === 0 ? null : breaks;
|
|
3658
|
+
}
|
|
3659
|
+
function addInternalLetterSpacing(width, graphemeCount, letterSpacing) {
|
|
3660
|
+
return graphemeCount > 1 ? width + (graphemeCount - 1) * letterSpacing : width;
|
|
3661
|
+
}
|
|
3662
|
+
function measureAnalysis(analysis, font, includeSegments, wordBreak, letterSpacing) {
|
|
3663
|
+
const engineProfile = getEngineProfile();
|
|
3664
|
+
const { cache, emojiCorrection } = getFontMeasurementState(font, textMayContainEmoji(analysis.normalized));
|
|
3665
|
+
const discretionaryHyphenWidth = getCorrectedSegmentWidth("-", getSegmentMetrics("-", cache), emojiCorrection) + (letterSpacing === 0 ? 0 : letterSpacing * 2);
|
|
3666
|
+
const spaceWidth = getCorrectedSegmentWidth(" ", getSegmentMetrics(" ", cache), emojiCorrection);
|
|
3667
|
+
const tabStopAdvance = spaceWidth * 8;
|
|
3668
|
+
const hasLetterSpacing = letterSpacing !== 0;
|
|
3669
|
+
if (analysis.len === 0)
|
|
3670
|
+
return createEmptyPrepared(includeSegments);
|
|
3671
|
+
const widths = [];
|
|
3672
|
+
const lineEndFitAdvances = [];
|
|
3673
|
+
const lineEndPaintAdvances = [];
|
|
3674
|
+
const kinds = [];
|
|
3675
|
+
let simpleLineWalkFastPath = analysis.chunks.length <= 1 && !hasLetterSpacing;
|
|
3676
|
+
const segStarts = includeSegments ? [] : null;
|
|
3677
|
+
const breakableFitAdvances = [];
|
|
3678
|
+
const breakablePreferredBreaks = [];
|
|
3679
|
+
const spacingGraphemeCounts = [];
|
|
3680
|
+
const segments = includeSegments ? [] : null;
|
|
3681
|
+
const preparedStartByAnalysisIndex = Array.from({ length: analysis.len });
|
|
3682
|
+
function pushMeasuredSegment(text, width, lineEndFitAdvance, lineEndPaintAdvance, kind, start, breakableFitAdvance, breakablePreferredBreak, spacingGraphemeCount) {
|
|
3683
|
+
if (kind !== "text" && kind !== "space" && kind !== "zero-width-break") {
|
|
3684
|
+
simpleLineWalkFastPath = false;
|
|
3685
|
+
}
|
|
3686
|
+
widths.push(width);
|
|
3687
|
+
lineEndFitAdvances.push(lineEndFitAdvance);
|
|
3688
|
+
lineEndPaintAdvances.push(lineEndPaintAdvance);
|
|
3689
|
+
kinds.push(kind);
|
|
3690
|
+
segStarts?.push(start);
|
|
3691
|
+
breakableFitAdvances.push(breakableFitAdvance);
|
|
3692
|
+
breakablePreferredBreaks.push(breakablePreferredBreak);
|
|
3693
|
+
if (hasLetterSpacing)
|
|
3694
|
+
spacingGraphemeCounts.push(spacingGraphemeCount);
|
|
3695
|
+
if (segments !== null)
|
|
3696
|
+
segments.push(text);
|
|
3697
|
+
}
|
|
3698
|
+
function pushMeasuredTextSegment(text, kind, start, wordLike, allowOverflowBreaks) {
|
|
3699
|
+
const textMetrics = getSegmentMetrics(text, cache);
|
|
3700
|
+
const spacingGraphemeCount = hasLetterSpacing ? countRenderedSpacingGraphemes(text, kind) : 0;
|
|
3701
|
+
const width = addInternalLetterSpacing(getCorrectedSegmentWidth(text, textMetrics, emojiCorrection), spacingGraphemeCount, letterSpacing);
|
|
3702
|
+
const baseLineEndFitAdvance = kind === "space" || kind === "preserved-space" || kind === "zero-width-break" ? 0 : width;
|
|
3703
|
+
const lineEndFitAdvance = baseLineEndFitAdvance === 0 ? 0 : baseLineEndFitAdvance + (spacingGraphemeCount > 0 ? letterSpacing : 0);
|
|
3704
|
+
const lineEndPaintAdvance = kind === "space" || kind === "zero-width-break" ? 0 : width;
|
|
3705
|
+
if (allowOverflowBreaks && wordLike && text.length > 1) {
|
|
3706
|
+
let fitMode = "sum-graphemes";
|
|
3707
|
+
if (letterSpacing !== 0) {
|
|
3708
|
+
fitMode = "segment-prefixes";
|
|
3709
|
+
} else if (isNumericRunSegment(text)) {
|
|
3710
|
+
fitMode = "pair-context";
|
|
3711
|
+
} else if (engineProfile.preferPrefixWidthsForBreakableRuns) {
|
|
3712
|
+
fitMode = "segment-prefixes";
|
|
3713
|
+
}
|
|
3714
|
+
const fitAdvances = getSegmentBreakableFitAdvances(text, textMetrics, cache, emojiCorrection, fitMode);
|
|
3715
|
+
const preferredBreaks = fitAdvances === null || wordBreak === "keep-all" ? null : getBreakablePreferredBreaks(text);
|
|
3716
|
+
pushMeasuredSegment(text, width, lineEndFitAdvance, lineEndPaintAdvance, kind, start, fitAdvances, preferredBreaks, spacingGraphemeCount);
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
pushMeasuredSegment(text, width, lineEndFitAdvance, lineEndPaintAdvance, kind, start, null, null, spacingGraphemeCount);
|
|
3720
|
+
}
|
|
3721
|
+
for (let mi = 0;mi < analysis.len; mi++) {
|
|
3722
|
+
preparedStartByAnalysisIndex[mi] = widths.length;
|
|
3723
|
+
const segText = analysis.texts[mi];
|
|
3724
|
+
const segWordLike = analysis.isWordLike[mi];
|
|
3725
|
+
const segKind = analysis.kinds[mi];
|
|
3726
|
+
const segStart = analysis.starts[mi];
|
|
3727
|
+
if (segKind === "soft-hyphen") {
|
|
3728
|
+
pushMeasuredSegment(segText, 0, discretionaryHyphenWidth, discretionaryHyphenWidth, segKind, segStart, null, null, 0);
|
|
3729
|
+
continue;
|
|
3730
|
+
}
|
|
3731
|
+
if (segKind === "hard-break") {
|
|
3732
|
+
pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null, null, 0);
|
|
3733
|
+
continue;
|
|
3734
|
+
}
|
|
3735
|
+
if (segKind === "tab") {
|
|
3736
|
+
pushMeasuredSegment(segText, 0, 0, 0, segKind, segStart, null, null, hasLetterSpacing ? countRenderedSpacingGraphemes(segText, segKind) : 0);
|
|
3737
|
+
continue;
|
|
3738
|
+
}
|
|
3739
|
+
const segMetrics = getSegmentMetrics(segText, cache);
|
|
3740
|
+
if (segKind === "text" && segMetrics.containsCJK) {
|
|
3741
|
+
const baseUnits = buildBaseCjkUnits(segText, engineProfile);
|
|
3742
|
+
const measuredUnits = wordBreak === "keep-all" ? mergeKeepAllTextUnits(segText, baseUnits, engineProfile.breakKeepAllAfterPunctuation) : baseUnits;
|
|
3743
|
+
for (let i = 0;i < measuredUnits.length; i++) {
|
|
3744
|
+
const unit = measuredUnits[i];
|
|
3745
|
+
pushMeasuredTextSegment(unit.text, "text", segStart + unit.start, segWordLike, wordBreak === "keep-all" || !isCJK(unit.text));
|
|
3746
|
+
}
|
|
3747
|
+
continue;
|
|
3748
|
+
}
|
|
3749
|
+
pushMeasuredTextSegment(segText, segKind, segStart, segWordLike, true);
|
|
3750
|
+
}
|
|
3751
|
+
const chunks = mapAnalysisChunksToPreparedChunks(analysis.chunks, preparedStartByAnalysisIndex, widths.length);
|
|
3752
|
+
const segLevels = segStarts === null ? null : computeSegmentLevels(analysis.normalized, segStarts);
|
|
3753
|
+
if (segments !== null) {
|
|
3754
|
+
return {
|
|
3755
|
+
widths,
|
|
3756
|
+
lineEndFitAdvances,
|
|
3757
|
+
lineEndPaintAdvances,
|
|
3758
|
+
kinds,
|
|
3759
|
+
simpleLineWalkFastPath,
|
|
3760
|
+
segLevels,
|
|
3761
|
+
breakableFitAdvances,
|
|
3762
|
+
breakablePreferredBreaks,
|
|
3763
|
+
letterSpacing,
|
|
3764
|
+
spacingGraphemeCounts,
|
|
3765
|
+
discretionaryHyphenWidth,
|
|
3766
|
+
tabStopAdvance,
|
|
3767
|
+
chunks,
|
|
3768
|
+
segments
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
return {
|
|
3772
|
+
widths,
|
|
3773
|
+
lineEndFitAdvances,
|
|
3774
|
+
lineEndPaintAdvances,
|
|
3775
|
+
kinds,
|
|
3776
|
+
simpleLineWalkFastPath,
|
|
3777
|
+
segLevels,
|
|
3778
|
+
breakableFitAdvances,
|
|
3779
|
+
breakablePreferredBreaks,
|
|
3780
|
+
letterSpacing,
|
|
3781
|
+
spacingGraphemeCounts,
|
|
3782
|
+
discretionaryHyphenWidth,
|
|
3783
|
+
tabStopAdvance,
|
|
3784
|
+
chunks
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
function mapAnalysisChunksToPreparedChunks(chunks, preparedStartByAnalysisIndex, preparedEndSegmentIndex) {
|
|
3788
|
+
const preparedChunks = [];
|
|
3789
|
+
for (let i = 0;i < chunks.length; i++) {
|
|
3790
|
+
const chunk = chunks[i];
|
|
3791
|
+
const startSegmentIndex = chunk.startSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.startSegmentIndex] : preparedEndSegmentIndex;
|
|
3792
|
+
const endSegmentIndex = chunk.endSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.endSegmentIndex] : preparedEndSegmentIndex;
|
|
3793
|
+
const consumedEndSegmentIndex = chunk.consumedEndSegmentIndex < preparedStartByAnalysisIndex.length ? preparedStartByAnalysisIndex[chunk.consumedEndSegmentIndex] : preparedEndSegmentIndex;
|
|
3794
|
+
preparedChunks.push({
|
|
3795
|
+
startSegmentIndex,
|
|
3796
|
+
endSegmentIndex,
|
|
3797
|
+
consumedEndSegmentIndex
|
|
3798
|
+
});
|
|
3799
|
+
}
|
|
3800
|
+
return preparedChunks;
|
|
3801
|
+
}
|
|
3802
|
+
function prepareInternal(text, font, includeSegments, options) {
|
|
3803
|
+
const wordBreak = options?.wordBreak ?? "normal";
|
|
3804
|
+
const letterSpacing = options?.letterSpacing ?? 0;
|
|
3805
|
+
const analysis = analyzeText(text, getEngineProfile(), options?.whiteSpace, wordBreak);
|
|
3806
|
+
return measureAnalysis(analysis, font, includeSegments, wordBreak, letterSpacing);
|
|
3807
|
+
}
|
|
3808
|
+
function prepare(text, font, options) {
|
|
3809
|
+
return prepareInternal(text, font, false, options);
|
|
3810
|
+
}
|
|
3811
|
+
function prepareWithSegments(text, font, options) {
|
|
3812
|
+
return prepareInternal(text, font, true, options);
|
|
3813
|
+
}
|
|
3814
|
+
function getInternalPrepared(prepared) {
|
|
3815
|
+
return prepared;
|
|
3816
|
+
}
|
|
3817
|
+
function layout(prepared, maxWidth, lineHeight) {
|
|
3818
|
+
const lineCount = countPreparedLines(getInternalPrepared(prepared), maxWidth);
|
|
3819
|
+
return { lineCount, height: lineCount * lineHeight };
|
|
3820
|
+
}
|
|
3821
|
+
function createLayoutLine(prepared, cache, width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
|
|
3822
|
+
return {
|
|
3823
|
+
text: buildLineTextFromRange(prepared, cache, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex),
|
|
3824
|
+
width,
|
|
3825
|
+
start: {
|
|
3826
|
+
segmentIndex: startSegmentIndex,
|
|
3827
|
+
graphemeIndex: startGraphemeIndex
|
|
3828
|
+
},
|
|
3829
|
+
end: {
|
|
3830
|
+
segmentIndex: endSegmentIndex,
|
|
3831
|
+
graphemeIndex: endGraphemeIndex
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
function createLayoutLineRange(width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) {
|
|
3836
|
+
return {
|
|
3837
|
+
width,
|
|
3838
|
+
start: {
|
|
3839
|
+
segmentIndex: startSegmentIndex,
|
|
3840
|
+
graphemeIndex: startGraphemeIndex
|
|
3841
|
+
},
|
|
3842
|
+
end: {
|
|
3843
|
+
segmentIndex: endSegmentIndex,
|
|
3844
|
+
graphemeIndex: endGraphemeIndex
|
|
3845
|
+
}
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
function materializeLineRange(prepared, line) {
|
|
3849
|
+
return createLayoutLine(prepared, getLineTextCache(prepared), line.width, line.start.segmentIndex, line.start.graphemeIndex, line.end.segmentIndex, line.end.graphemeIndex);
|
|
3850
|
+
}
|
|
3851
|
+
function walkLineRanges(prepared, maxWidth, onLine) {
|
|
3852
|
+
if (prepared.widths.length === 0)
|
|
3853
|
+
return 0;
|
|
3854
|
+
return walkPreparedLinesRaw(getInternalPrepared(prepared), maxWidth, (width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) => {
|
|
3855
|
+
onLine(createLayoutLineRange(width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex));
|
|
3856
|
+
});
|
|
3857
|
+
}
|
|
3858
|
+
function measureLineStats(prepared, maxWidth) {
|
|
3859
|
+
return measurePreparedLineGeometry(getInternalPrepared(prepared), maxWidth);
|
|
3860
|
+
}
|
|
3861
|
+
function measureNaturalWidth(prepared) {
|
|
3862
|
+
let maxWidth = 0;
|
|
3863
|
+
walkPreparedLinesRaw(getInternalPrepared(prepared), Number.POSITIVE_INFINITY, (width) => {
|
|
3864
|
+
if (width > maxWidth)
|
|
3865
|
+
maxWidth = width;
|
|
3866
|
+
});
|
|
3867
|
+
return maxWidth;
|
|
3868
|
+
}
|
|
3869
|
+
function layoutNextLine(prepared, start, maxWidth) {
|
|
3870
|
+
const internal = getInternalPrepared(prepared);
|
|
3871
|
+
const end = {
|
|
3872
|
+
segmentIndex: start.segmentIndex,
|
|
3873
|
+
graphemeIndex: start.graphemeIndex
|
|
3874
|
+
};
|
|
3875
|
+
const chunkIndex = normalizePreparedLineStart(internal, end);
|
|
3876
|
+
if (chunkIndex < 0)
|
|
3877
|
+
return null;
|
|
3878
|
+
const lineStartSegmentIndex = end.segmentIndex;
|
|
3879
|
+
const lineStartGraphemeIndex = end.graphemeIndex;
|
|
3880
|
+
const width = stepPreparedLineGeometryFromChunk(internal, end, chunkIndex, maxWidth);
|
|
3881
|
+
if (width === null)
|
|
3882
|
+
return null;
|
|
3883
|
+
return createLayoutLine(prepared, getLineTextCache(prepared), width, lineStartSegmentIndex, lineStartGraphemeIndex, end.segmentIndex, end.graphemeIndex);
|
|
3884
|
+
}
|
|
3885
|
+
function layoutNextLineRange(prepared, start, maxWidth) {
|
|
3886
|
+
const internal = getInternalPrepared(prepared);
|
|
3887
|
+
const end = {
|
|
3888
|
+
segmentIndex: start.segmentIndex,
|
|
3889
|
+
graphemeIndex: start.graphemeIndex
|
|
3890
|
+
};
|
|
3891
|
+
const chunkIndex = normalizePreparedLineStart(internal, end);
|
|
3892
|
+
if (chunkIndex < 0)
|
|
3893
|
+
return null;
|
|
3894
|
+
const lineStartSegmentIndex = end.segmentIndex;
|
|
3895
|
+
const lineStartGraphemeIndex = end.graphemeIndex;
|
|
3896
|
+
const width = stepPreparedLineGeometryFromChunk(internal, end, chunkIndex, maxWidth);
|
|
3897
|
+
if (width === null)
|
|
3898
|
+
return null;
|
|
3899
|
+
return createLayoutLineRange(width, lineStartSegmentIndex, lineStartGraphemeIndex, end.segmentIndex, end.graphemeIndex);
|
|
3900
|
+
}
|
|
3901
|
+
function layoutWithLines(prepared, maxWidth, lineHeight) {
|
|
3902
|
+
const lines = [];
|
|
3903
|
+
if (prepared.widths.length === 0)
|
|
3904
|
+
return { lineCount: 0, height: 0, lines };
|
|
3905
|
+
const graphemeCache = getLineTextCache(prepared);
|
|
3906
|
+
const lineCount = walkPreparedLinesRaw(getInternalPrepared(prepared), maxWidth, (width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex) => {
|
|
3907
|
+
lines.push(createLayoutLine(prepared, graphemeCache, width, startSegmentIndex, startGraphemeIndex, endSegmentIndex, endGraphemeIndex));
|
|
3908
|
+
});
|
|
3909
|
+
return { lineCount, height: lineCount * lineHeight, lines };
|
|
3910
|
+
}
|
|
3911
|
+
function clearCache() {
|
|
3912
|
+
clearAnalysisCaches();
|
|
3913
|
+
sharedGraphemeSegmenter3 = null;
|
|
3914
|
+
clearLineTextCaches();
|
|
3915
|
+
clearMeasurementCaches();
|
|
3916
|
+
}
|
|
3917
|
+
function setLocale(locale) {
|
|
3918
|
+
setAnalysisLocale(locale);
|
|
3919
|
+
clearCache();
|
|
3920
|
+
}
|
|
3921
|
+
var sharedGraphemeSegmenter3 = null;
|
|
3922
|
+
var init_layout = __esm(() => {
|
|
3923
|
+
init_bidi();
|
|
3924
|
+
init_analysis();
|
|
3925
|
+
init_measurement();
|
|
3926
|
+
init_line_break();
|
|
3927
|
+
init_line_text();
|
|
3928
|
+
});
|
|
3929
|
+
|
|
3930
|
+
// src/cli/check.ts
|
|
3931
|
+
var _process = typeof globalThis !== "undefined" ? globalThis.process : undefined;
|
|
3932
|
+
var GREEN = "\x1B[32m";
|
|
3933
|
+
var RED = "\x1B[31m";
|
|
3934
|
+
var YELLOW = "\x1B[33m";
|
|
3935
|
+
var RESET = "\x1B[0m";
|
|
3936
|
+
var BOLD = "\x1B[1m";
|
|
3937
|
+
function ok(label, msg) {
|
|
3938
|
+
console.log(` ${GREEN}\u2713${RESET} ${label.padEnd(20)} ${msg}`);
|
|
3939
|
+
}
|
|
3940
|
+
function fail(label, msg) {
|
|
3941
|
+
console.log(` ${RED}\u2717${RESET} ${label.padEnd(20)} ${msg}`);
|
|
3942
|
+
}
|
|
3943
|
+
function skip(label, msg) {
|
|
3944
|
+
console.log(` ${YELLOW}\u2212${RESET} ${label.padEnd(20)} ${msg}`);
|
|
3945
|
+
}
|
|
3946
|
+
function _requireModule(name) {
|
|
3947
|
+
let _require = null;
|
|
3948
|
+
if (typeof _process?.getBuiltinModule === "function") {
|
|
3949
|
+
const mb = _process.getBuiltinModule("module");
|
|
3950
|
+
if (mb)
|
|
3951
|
+
_require = mb.createRequire(import.meta.url);
|
|
3952
|
+
}
|
|
3953
|
+
if (!_require) {
|
|
3954
|
+
const cjsRequire = globalThis["require"];
|
|
3955
|
+
if (typeof cjsRequire === "function")
|
|
3956
|
+
_require = cjsRequire;
|
|
3957
|
+
}
|
|
3958
|
+
if (!_require)
|
|
3959
|
+
throw new Error("Cannot find require() \u2014 browser?");
|
|
3960
|
+
return _require(name);
|
|
3961
|
+
}
|
|
3962
|
+
async function checkCanvasModule() {
|
|
3963
|
+
try {
|
|
3964
|
+
const canvas = _requireModule("@napi-rs/canvas");
|
|
3965
|
+
if (typeof canvas.createCanvas !== "function") {
|
|
3966
|
+
fail("@napi-rs/canvas", "createCanvas is not a function");
|
|
3967
|
+
return false;
|
|
3968
|
+
}
|
|
3969
|
+
const c = canvas.createCanvas(10, 10);
|
|
3970
|
+
const ctx = c.getContext("2d");
|
|
3971
|
+
if (!ctx || typeof ctx.measureText !== "function") {
|
|
3972
|
+
fail("@napi-rs/canvas", "getContext or measureText unavailable");
|
|
3973
|
+
return false;
|
|
3974
|
+
}
|
|
3975
|
+
ok("@napi-rs/canvas", "createCanvas + measureText work");
|
|
3976
|
+
return true;
|
|
3977
|
+
} catch (err) {
|
|
3978
|
+
fail("@napi-rs/canvas", `not available \u2014 ${err.message}`);
|
|
3979
|
+
return false;
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
async function checkFontkitModule() {
|
|
3983
|
+
try {
|
|
3984
|
+
const fontkit = await import("fontkit");
|
|
3985
|
+
const fk = fontkit.default || fontkit;
|
|
3986
|
+
if (typeof fk.create !== "function") {
|
|
3987
|
+
fail("fontkit", "create is not a function");
|
|
3988
|
+
return false;
|
|
3989
|
+
}
|
|
3990
|
+
ok("fontkit", "fontkit.create() is available");
|
|
3991
|
+
return true;
|
|
3992
|
+
} catch (err) {
|
|
3993
|
+
fail("fontkit", `not available \u2014 ${err.message}`);
|
|
3994
|
+
return false;
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
async function checkPretextModule() {
|
|
3998
|
+
try {
|
|
3999
|
+
const pretext = await Promise.resolve().then(() => (init_layout(), exports_layout));
|
|
4000
|
+
const pt = pretext.default || pretext;
|
|
4001
|
+
if (typeof pt.prepare !== "function") {
|
|
4002
|
+
fail("@chenglou/pretext", "prepare is not a function");
|
|
4003
|
+
return false;
|
|
4004
|
+
}
|
|
4005
|
+
ok("@chenglou/pretext", "pretext.prepare() is available");
|
|
4006
|
+
return true;
|
|
4007
|
+
} catch (err) {
|
|
4008
|
+
fail("@chenglou/pretext", `not available \u2014 ${err.message}`);
|
|
4009
|
+
return false;
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
async function checkMeasureText() {
|
|
4013
|
+
try {
|
|
4014
|
+
const canvas = _requireModule("@napi-rs/canvas");
|
|
4015
|
+
const c = canvas.createCanvas(200, 50);
|
|
4016
|
+
const ctx = c.getContext("2d");
|
|
4017
|
+
ctx.font = "16px serif";
|
|
4018
|
+
const m = ctx.measureText("M");
|
|
4019
|
+
if (m.width > 0) {
|
|
4020
|
+
ok("measureText", `width = ${m.width} (> 0) \u2014 fontconfig OK`);
|
|
4021
|
+
return true;
|
|
4022
|
+
}
|
|
4023
|
+
fail("measureText", `width = ${m.width} \u2014 fontconfig probably missing
|
|
4024
|
+
` + ` ${YELLOW}Solution: install fontconfig and run fc-cache -f${RESET}`);
|
|
4025
|
+
return false;
|
|
4026
|
+
} catch (err) {
|
|
4027
|
+
fail("measureText", `error \u2014 ${err.message}`);
|
|
4028
|
+
return false;
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
async function checkSystemFontsModule() {
|
|
4032
|
+
try {
|
|
4033
|
+
const mod = await import("get-system-fonts");
|
|
4034
|
+
const getSystemFonts = mod.default || mod;
|
|
4035
|
+
if (typeof getSystemFonts !== "function") {
|
|
4036
|
+
skip("get-system-fonts", "not a function (browser build?)");
|
|
4037
|
+
return true;
|
|
4038
|
+
}
|
|
4039
|
+
const paths = await getSystemFonts();
|
|
4040
|
+
ok("get-system-fonts", `${paths.length} system fonts found`);
|
|
4041
|
+
return true;
|
|
4042
|
+
} catch (err) {
|
|
4043
|
+
fail("get-system-fonts", `not available \u2014 ${err.message}`);
|
|
4044
|
+
return false;
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
async function run() {
|
|
4048
|
+
console.log(`${BOLD}vyaz environment check${RESET}
|
|
4049
|
+
`);
|
|
4050
|
+
const results = await Promise.all([
|
|
4051
|
+
checkCanvasModule(),
|
|
4052
|
+
checkFontkitModule(),
|
|
4053
|
+
checkPretextModule(),
|
|
4054
|
+
checkMeasureText(),
|
|
4055
|
+
checkSystemFontsModule()
|
|
4056
|
+
]);
|
|
4057
|
+
const passed = results.filter(Boolean).length;
|
|
4058
|
+
const total = results.length;
|
|
4059
|
+
const allOk = passed === total;
|
|
4060
|
+
console.log();
|
|
4061
|
+
if (allOk) {
|
|
4062
|
+
console.log(` ${GREEN}${BOLD}\u2714 All ${total} checks passed${RESET}`);
|
|
4063
|
+
_process?.exit(0);
|
|
4064
|
+
} else {
|
|
4065
|
+
console.log(` ${RED}${BOLD}\u2718 ${passed}/${total} checks passed${RESET}
|
|
4066
|
+
`);
|
|
4067
|
+
if (!results[3]) {
|
|
4068
|
+
console.log(` ${YELLOW}Hint: measureText returned 0 \u2014 fontconfig is likely missing.${RESET}
|
|
4069
|
+
${YELLOW}Install it with: apt-get install -y fontconfig && fc-cache -f${RESET}
|
|
4070
|
+
`);
|
|
4071
|
+
}
|
|
4072
|
+
_process?.exit(1);
|
|
4073
|
+
}
|
|
4074
|
+
}
|
|
4075
|
+
export {
|
|
4076
|
+
run
|
|
4077
|
+
};
|