@mark1russell7/typeset 0.1.7 → 0.1.9
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/build/bidi.d.ts +50 -0
- package/build/bidi.d.ts.map +1 -0
- package/build/bidi.js +41 -0
- package/build/bidi.js.map +1 -0
- package/build/chunks/font.js +37 -71
- package/build/chunks/font.js.map +1 -1
- package/build/chunks/resolve.js +382 -0
- package/build/chunks/resolve.js.map +1 -0
- package/build/segmentation.d.ts +32 -4
- package/build/segmentation.d.ts.map +1 -1
- package/build/segmentation.js +116 -12
- package/build/segmentation.js.map +1 -1
- package/package.json +6 -2
- package/src/bidi/brackets.ts +23 -0
- package/src/bidi/classes.ts +43 -0
- package/src/bidi/resolve.ts +380 -0
- package/src/bidi/table.ts +5 -0
- package/src/bidi.ts +4 -0
- package/src/fonts/bidi.ts +26 -86
- package/src/segmentation/line-table.ts +2 -2
- package/src/segmentation/line.ts +71 -8
- package/src/segmentation/segments.ts +47 -0
- package/src/segmentation.ts +2 -2
package/build/segmentation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/segmentation/line-table.ts
|
|
2
2
|
const unicodeVersion = "17.0.0";
|
|
3
|
-
const classNames = "AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM".split(" ");
|
|
4
|
-
const classRuns = "
|
|
3
|
+
const classNames = "AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL SA JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM".split(" ");
|
|
4
|
+
const classRuns = "9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA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7B31A7B5AaQ4A2LngA1K3A1KnjA74(4uA1k(q?at(1:m(2An(2A5(1A5(3:2(1:2(3:1a(5@1u(2:2(b:l(j:3(1:4(3:1(3:7(1:1(1:e(1A1(1A1(1A5(1:4(1A1(2A25(7Ag(eAd(oA16(2:4(1:l(1:4(2:1p(8Ao(6A23(3:3(5:12A3I3#4Az(1:g(3:9(1:b(1:1f(38A3(4A5(2dA17(7gA1:2(1:8(8:6(1:9(a:2(3:1k(1:1p(2:1(2:1(1:h(3:1(d:y(2gA2z(3:16(9:7(6oAaQ6Ase(2A1eke(2A1eke(e1ojA1BuA2oB3kA6oB47bkA";
|
|
5
5
|
const eastAsianRuns = "3cw 2o 30p 1 hc 2 d 2 5a 4 3 1 2 1 eh 2 l 2 q 8 g c 17 1 a 6 3 1 d 1 8 2 h 2 5 2 8 1 5 1 l 1 7 2 1 1 4 1 2 1 7 1 4 2 s 1 z 1 1 1 4 3 1 1 1p 3 o 1 e 1 nv 2 1f 1 4 1 mi q 1 2h c 5y q 27 2 2e 2 2v 5 17 1 2m 1 2e 9 1c 1 14 8 mkd 3 1j wp t hv 8mc 6l8 e8 ls a m z 1 j 1 4 45 5a 3 6 2 6 2 6 2 3 3 7 1 7 m41 5 b 7 9 5p2 15 w 2p 37 6pp 4 1 7 1 2 1 83 f 1 t 3 2 1 e 4 8 b0 6bo 2f 9 n 5n1 1 5m 1 5a 1 2 a 2t 3 d 18 4 9 7 2 e 6 4a x c 9 1 1y 1 m c 17 4 5 c h 3 1 3 1z 1 1 1 57 2 1r d 4 1 o i 1 q 2 d 1 2e 2d 1c 1y 6 1 3 3 2 4 3 4 b 2 7 9 6b c 4 1 7v 1b 1 a 1 55 34 d 3 b 3 1l 1 1 4 g 2 c 4 a zr 1eke 2 1eke i9du";
|
|
6
6
|
// src/segmentation/line.ts
|
|
7
7
|
/**
|
|
@@ -28,10 +28,13 @@ function tableOf() {
|
|
|
28
28
|
lengths.forEach((length, index) => {
|
|
29
29
|
east[index + 1] = east[index] + length;
|
|
30
30
|
});
|
|
31
|
+
const codes = Array.from({ length: 128 }, (_, code) => code);
|
|
31
32
|
table = {
|
|
32
33
|
starts,
|
|
33
34
|
classes,
|
|
34
|
-
east
|
|
35
|
+
east,
|
|
36
|
+
asciiNames: codes.map((code) => classNames[classes[indexOfRun(starts, code)]]),
|
|
37
|
+
asciiEast: codes.map((code) => indexOfRun(east, code) % 2 === 1)
|
|
35
38
|
};
|
|
36
39
|
return table;
|
|
37
40
|
}
|
|
@@ -56,12 +59,12 @@ const breakClasses = /* @__PURE__ */ new Set([
|
|
|
56
59
|
]);
|
|
57
60
|
/** This function makes the items of a text. It applies the rules LB9 and LB10. */
|
|
58
61
|
function itemsOf(text) {
|
|
59
|
-
const { starts, classes, east } = tableOf();
|
|
62
|
+
const { starts, classes, east, asciiNames, asciiEast } = tableOf();
|
|
60
63
|
const items = [];
|
|
61
64
|
let offset = 0;
|
|
62
65
|
for (const character of text) {
|
|
63
66
|
const code = character.codePointAt(0);
|
|
64
|
-
const name = classNames[classes[indexOfRun(starts, code)]];
|
|
67
|
+
const name = code < 128 ? asciiNames[code] : classNames[classes[indexOfRun(starts, code)]];
|
|
65
68
|
const combining = name === "CM" || name === "ZWJ";
|
|
66
69
|
const last = items.at(-1);
|
|
67
70
|
if (combining && last !== void 0 && !breakClasses.has(last.name)) last.zwj = name === "ZWJ";
|
|
@@ -70,14 +73,24 @@ function itemsOf(text) {
|
|
|
70
73
|
code: 65,
|
|
71
74
|
start: offset,
|
|
72
75
|
east: false,
|
|
73
|
-
zwj: name === "ZWJ"
|
|
76
|
+
zwj: name === "ZWJ",
|
|
77
|
+
complex: false
|
|
78
|
+
});
|
|
79
|
+
else if (name === "SA") items.push({
|
|
80
|
+
name: "AL",
|
|
81
|
+
code,
|
|
82
|
+
start: offset,
|
|
83
|
+
east: indexOfRun(east, code) % 2 === 1,
|
|
84
|
+
zwj: false,
|
|
85
|
+
complex: true
|
|
74
86
|
});
|
|
75
87
|
else items.push({
|
|
76
88
|
name,
|
|
77
89
|
code,
|
|
78
90
|
start: offset,
|
|
79
|
-
east: indexOfRun(east, code) % 2 === 1,
|
|
80
|
-
zwj: false
|
|
91
|
+
east: code < 128 ? asciiEast[code] : indexOfRun(east, code) % 2 === 1,
|
|
92
|
+
zwj: false,
|
|
93
|
+
complex: false
|
|
81
94
|
});
|
|
82
95
|
offset += character.length;
|
|
83
96
|
}
|
|
@@ -226,11 +239,41 @@ function ruleAt(items, i) {
|
|
|
226
239
|
return 1;
|
|
227
240
|
}
|
|
228
241
|
/**
|
|
229
|
-
* This function gives the places where a line of a text can end, by the rules of UAX #14
|
|
230
|
-
* the end of the text, and an empty text has no place.
|
|
242
|
+
* This function gives the places where a line of a text can end, by the rules of UAX #14. With no option, it applies no
|
|
243
|
+
* tailoring. The last place is the end of the text, and an empty text has no place.
|
|
244
|
+
*
|
|
245
|
+
* The hook `complex` adds places inside each run of class SA. The function keeps only the places at the start of an item,
|
|
246
|
+
* so no place is before a combining mark. The places outside the runs do not change.
|
|
247
|
+
*
|
|
248
|
+
* A text of only ASCII letters, digits and spaces takes a short path, because the rules give it a simple result. A line can
|
|
249
|
+
* end after each run of spaces (LB18), and at no other place (LB7, LB23, LB25 and LB28). Such a text has no run of class
|
|
250
|
+
* SA, so the hook adds no place to it.
|
|
251
|
+
*/
|
|
252
|
+
function lineBreaks(text, options = {}) {
|
|
253
|
+
return simple.test(text) ? simpleBreaks(text) : ruleBreaks(text, options);
|
|
254
|
+
}
|
|
255
|
+
/** The texts of the short path of `lineBreaks`. */
|
|
256
|
+
const simple = /^[A-Za-z0-9 ]*$/u;
|
|
257
|
+
/** This function gives the places of a text of only ASCII letters, digits and spaces: after each run of spaces, and at the end. */
|
|
258
|
+
function simpleBreaks(text) {
|
|
259
|
+
const breaks = [];
|
|
260
|
+
for (let i = 1; i < text.length; i++) if (text.charCodeAt(i - 1) === 32 && text.charCodeAt(i) !== 32) breaks.push({
|
|
261
|
+
offset: i,
|
|
262
|
+
required: false
|
|
263
|
+
});
|
|
264
|
+
if (text.length > 0) breaks.push({
|
|
265
|
+
offset: text.length,
|
|
266
|
+
required: true
|
|
267
|
+
});
|
|
268
|
+
return breaks;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* This function gives the places of a text by the rules of UAX #14, with no short path. The tests compare `lineBreaks` with
|
|
272
|
+
* it. The entry `./segmentation` does not export it.
|
|
231
273
|
*/
|
|
232
|
-
function
|
|
274
|
+
function ruleBreaks(text, options = {}) {
|
|
233
275
|
const items = itemsOf(text);
|
|
276
|
+
const inside = options.complex === void 0 ? void 0 : complexPlaces(text, items, options.complex);
|
|
234
277
|
const breaks = [];
|
|
235
278
|
for (let i = 1; i < items.length; i++) {
|
|
236
279
|
const rule = ruleAt(items, i);
|
|
@@ -238,6 +281,10 @@ function lineBreaks(text) {
|
|
|
238
281
|
offset: items[i].start,
|
|
239
282
|
required: rule === 2
|
|
240
283
|
});
|
|
284
|
+
else if (inside?.has(i)) breaks.push({
|
|
285
|
+
offset: items[i].start,
|
|
286
|
+
required: false
|
|
287
|
+
});
|
|
241
288
|
}
|
|
242
289
|
if (text.length > 0) breaks.push({
|
|
243
290
|
offset: text.length,
|
|
@@ -245,6 +292,20 @@ function lineBreaks(text) {
|
|
|
245
292
|
});
|
|
246
293
|
return breaks;
|
|
247
294
|
}
|
|
295
|
+
/** This function gives the indexes of the items inside the runs of class SA where the hook gives a place. */
|
|
296
|
+
function complexPlaces(text, items, complex) {
|
|
297
|
+
const places = /* @__PURE__ */ new Set();
|
|
298
|
+
for (let i = 0; i < items.length; i++) {
|
|
299
|
+
if (!items[i].complex) continue;
|
|
300
|
+
let last = i;
|
|
301
|
+
while (last + 1 < items.length && items[last + 1].complex) last++;
|
|
302
|
+
const start = items[i].start;
|
|
303
|
+
const offsets = new Set(complex(text.slice(start, items[last + 1]?.start ?? text.length)));
|
|
304
|
+
for (let k = i + 1; k <= last; k++) if (offsets.has(items[k].start - start)) places.add(k);
|
|
305
|
+
i = last;
|
|
306
|
+
}
|
|
307
|
+
return places;
|
|
308
|
+
}
|
|
248
309
|
// src/segmentation/segments.ts
|
|
249
310
|
/**
|
|
250
311
|
* The segments of UAX #29, from `Intl.Segmenter`. The results follow the Unicode version of the runtime. The locale is the root
|
|
@@ -262,6 +323,49 @@ function wordBreaks(text) {
|
|
|
262
323
|
if (text.length > 0) offsets.push(text.length);
|
|
263
324
|
return offsets;
|
|
264
325
|
}
|
|
265
|
-
|
|
326
|
+
/**
|
|
327
|
+
* This function gives the word boundaries of each word of a list. Each entry equals `wordBreaks` of its word. The function
|
|
328
|
+
* segments the words in one pass, joined by line feeds, because UAX #29 breaks before and after each line feed (WB3a, WB3b).
|
|
329
|
+
* A word that ends in a carriage return gets its own pass, because a carriage return and a line feed stay together (WB3).
|
|
330
|
+
*/
|
|
331
|
+
function wordBreaksOf(words) {
|
|
332
|
+
const result = [];
|
|
333
|
+
const lists = [];
|
|
334
|
+
const starts = [];
|
|
335
|
+
const parts = [];
|
|
336
|
+
let offset = 0;
|
|
337
|
+
for (let index = 0; index < words.length; index++) {
|
|
338
|
+
const word = words[index];
|
|
339
|
+
if (word.endsWith("\r")) {
|
|
340
|
+
result[index] = wordBreaks(word);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const own = [];
|
|
344
|
+
result[index] = own;
|
|
345
|
+
lists.push(own);
|
|
346
|
+
starts.push(offset);
|
|
347
|
+
parts.push(word);
|
|
348
|
+
offset += word.length + 1;
|
|
349
|
+
}
|
|
350
|
+
const text = parts.join("\n");
|
|
351
|
+
let at = 0;
|
|
352
|
+
for (const part of wordSegmenter.segment(text)) {
|
|
353
|
+
const boundary = part.index;
|
|
354
|
+
while (at < lists.length && boundary > starts[at] + parts[at].length) at++;
|
|
355
|
+
if (at < lists.length && boundary > starts[at]) lists[at].push(boundary - starts[at]);
|
|
356
|
+
}
|
|
357
|
+
const last = lists.length - 1;
|
|
358
|
+
if (last >= 0 && parts[last].length > 0) lists[last].push(parts[last].length);
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* This function is a hook `complex` for `lineBreaks`. It gives the word boundaries inside a run of class SA, from
|
|
363
|
+
* `Intl.Segmenter` of the runtime. The runtime has the dictionary, so the entry ships no dictionary. In a browser, the places
|
|
364
|
+
* follow the dictionary of that browser.
|
|
365
|
+
*/
|
|
366
|
+
function complexBreaks(run) {
|
|
367
|
+
return wordBreaks(run).slice(0, -1);
|
|
368
|
+
}
|
|
369
|
+
export { complexBreaks, graphemes, lineBreaks, unicodeVersion, wordBreaks, wordBreaksOf };
|
|
266
370
|
|
|
267
371
|
//# sourceMappingURL=segmentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentation.js","names":[],"sources":["../src/segmentation/line-table.ts","../src/segmentation/line.ts","../src/segmentation/segments.ts"],"sourcesContent":["// Generated by `pnpm --filter @typeset/conformance tables` from Unicode 17.0.0. Do not edit.\nexport const unicodeVersion = \"17.0.0\";\nexport const classNames: readonly string[] = \"AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM\".split(\" \");\nexport const classRuns = \"9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA1UwA2kB7TdBeA1N78A7B73A1N1V4A1J1A19B1V1B1A2B1A2B1H1B8ArW4A4WdA6Q3A3K2N2AbB1H1B3H17AlBaQ1K2Q3A1B2rA1H1A7B1Q1A6B2A2B1A4B2AaQnA1BuArB2jAbBfAaQxA9B4A1N1H3A1B2JmA4B1A9B1A3B1A5B17A3B1gA2Q5A9B16AoB1QxB1iA3B1AiB1A7BaA2B2CaQhA3B1kA1B1A7B2A2B2A3B9A1BaA2B2AaQ2A2K5A1K1A1J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uns = \"3cw 2o 30p 1 hc 2 d 2 5a 4 3 1 2 1 eh 2 l 2 q 8 g c 17 1 a 6 3 1 d 1 8 2 h 2 5 2 8 1 5 1 l 1 7 2 1 1 4 1 2 1 7 1 4 2 s 1 z 1 1 1 4 3 1 1 1p 3 o 1 e 1 nv 2 1f 1 4 1 mi q 1 2h c 5y q 27 2 2e 2 2v 5 17 1 2m 1 2e 9 1c 1 14 8 mkd 3 1j wp t hv 8mc 6l8 e8 ls a m z 1 j 1 4 45 5a 3 6 2 6 2 6 2 3 3 7 1 7 m41 5 b 7 9 5p2 15 w 2p 37 6pp 4 1 7 1 2 1 83 f 1 t 3 2 1 e 4 8 b0 6bo 2f 9 n 5n1 1 5m 1 5a 1 2 a 2t 3 d 18 4 9 7 2 e 6 4a x c 9 1 1y 1 m c 17 4 5 c h 3 1 3 1z 1 1 1 57 2 1r d 4 1 o i 1 q 2 d 1 2e 2d 1c 1y 6 1 3 3 2 4 3 4 b 2 7 9 6b c 4 1 7v 1b 1 a 1 55 34 d 3 b 3 1l 1 1 4 g 2 c 4 a zr 1eke 2 1eke i9du\";\n","/**\n * The line break algorithm of UAX #14. The rules run in their order, and the first rule that matches decides. The class of a\n * code point comes from a table that the tool in `packages/conformance` makes from the property files of Unicode.\n */\nimport { classNames, classRuns, eastAsianRuns } from \"./line-table.ts\";\n\n/** A place where a line can end. */\nexport interface LineBreak {\n /** The offset in UTF-16 units of the first character after the break. */\n readonly offset: number;\n /** This value is `true` when a line must end here, as at a line feed or at the end of the text. */\n readonly required: boolean;\n}\n\ninterface Table {\n readonly starts: Uint32Array;\n readonly classes: Uint8Array;\n readonly east: Uint32Array;\n}\n\nconst alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~\";\nlet table: Table | undefined;\n\n/** This function decodes the runs one time, at the first use, so an import of the entry costs no work. */\nfunction tableOf(): Table {\n if (table !== undefined) return table;\n const runs = [...classRuns.matchAll(/([0-9a-z]+)([^0-9a-z])/gu)];\n const starts = new Uint32Array(runs.length + 1);\n const classes = new Uint8Array(runs.length);\n let start = 0;\n runs.forEach((run, index) => {\n starts[index] = start;\n classes[index] = alphabet.indexOf(run[2]!);\n start += Number.parseInt(run[1]!, 36);\n });\n starts[runs.length] = start;\n const lengths = eastAsianRuns.split(\" \").map((length) => Number.parseInt(length, 36));\n const east = new Uint32Array(lengths.length + 1);\n lengths.forEach((length, index) => {\n east[index + 1] = east[index]! + length;\n });\n table = { starts, classes, east };\n return table;\n}\n\n/** This function gives the index of the last start that is not above `code`. */\nfunction indexOfRun(starts: Uint32Array, code: number): number {\n let low = 0;\n let high = starts.length - 1;\n while (high - low > 1) {\n const middle = (low + high) >>> 1;\n if (starts[middle]! <= code) low = middle;\n else high = middle;\n }\n return low;\n}\n\n/** One base character and its combining marks, as the rule LB9 treats them. */\ninterface Item {\n readonly name: string;\n readonly code: number;\n readonly start: number;\n readonly east: boolean;\n /** This value is `true` when the last code point of the item is U+200D. */\n zwj: boolean;\n}\n\nconst breakClasses = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\"]);\n\n/** This function makes the items of a text. It applies the rules LB9 and LB10. */\nfunction itemsOf(text: string): Item[] {\n const { starts, classes, east } = tableOf();\n const items: Item[] = [];\n let offset = 0;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n const name = classNames[classes[indexOfRun(starts, code)]!]!;\n const combining = name === \"CM\" || name === \"ZWJ\";\n const last = items.at(-1);\n if (combining && last !== undefined && !breakClasses.has(last.name)) last.zwj = name === \"ZWJ\";\n else if (combining) items.push({ name: \"AL\", code: 0x41, start: offset, east: false, zwj: name === \"ZWJ\" });\n else items.push({ name, code, start: offset, east: indexOfRun(east, code) % 2 === 1, zwj: false });\n offset += character.length;\n }\n return items;\n}\n\nconst initial = /^\\p{Pi}$/u;\nconst final = /^\\p{Pf}$/u;\nconst pictographic = /^\\p{Extended_Pictographic}$/u;\nconst unassigned = /^\\p{Cn}$/u;\nconst of = (item: Item): string => String.fromCodePoint(item.code);\nconst isPi = (item: Item): boolean => initial.test(of(item));\nconst isPf = (item: Item): boolean => final.test(of(item));\nconst inClass = (item: Item | undefined, names: Set<string>): boolean => item !== undefined && names.has(item.name);\nconst isName = (item: Item | undefined, name: string): boolean => item?.name === name;\n\nconst beforeOpening = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"OP\", \"QU\", \"GL\", \"SP\", \"ZW\"]);\nconst afterClosing = new Set([\"SP\", \"GL\", \"WJ\", \"CL\", \"QU\", \"CP\", \"EX\", \"IS\", \"SY\", \"BK\", \"CR\", \"LF\", \"NL\", \"ZW\"]);\nconst beforeHyphen = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\", \"CB\", \"GL\"]);\nconst alphabetic = new Set([\"AL\", \"HL\"]);\nconst hyphens = new Set([\"HY\", \"HH\"]);\nconst emoji = new Set([\"ID\", \"EB\", \"EM\"]);\nconst prefix = new Set([\"PR\", \"PO\"]);\nconst closing = new Set([\"CL\", \"CP\"]);\nconst separators = new Set([\"SY\", \"IS\"]);\nconst hangul = new Set([\"JL\", \"JV\", \"JT\", \"H2\", \"H3\"]);\nconst aksara = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.name === \"AS\" || item.code === 0x25cc);\nconst aksaraStart = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.code === 0x25cc);\n\n/** This function tells if the items before `index` end with `NU (SY | IS)*`. */\nfunction afterNumber(items: readonly Item[], index: number): boolean {\n let i = index;\n while (i >= 0 && separators.has(items[i]!.name)) i--;\n return isName(items[i], \"NU\");\n}\n\n/** This function applies the rules LB4 to LB31 at the start of the item `i`. It gives 0 for no break, 1 for a break and 2 for a necessary break. */\nfunction ruleAt(items: readonly Item[], i: number): 0 | 1 | 2 {\n const a = items[i - 1]!;\n const b = items[i]!;\n const c = a.name;\n const d = b.name;\n const earlier = items[i - 2];\n const later = items[i + 1];\n if (c === \"BK\" || c === \"NL\" || c === \"LF\") return 2;\n if (c === \"CR\") return d === \"LF\" ? 0 : 2;\n if (d === \"BK\" || d === \"CR\" || d === \"LF\" || d === \"NL\" || d === \"SP\" || d === \"ZW\") return 0;\n let last = i - 1;\n while (last >= 0 && items[last]!.name === \"SP\") last--;\n const beforeSpaces = items[last];\n if (isName(beforeSpaces, \"ZW\")) return 1;\n if (a.zwj) return 0;\n if (d === \"WJ\" || c === \"WJ\" || c === \"GL\") return 0;\n if (d === \"GL\" && c !== \"SP\" && c !== \"BA\" && !hyphens.has(c)) return 0;\n if (d === \"CL\" || d === \"CP\" || d === \"EX\" || d === \"SY\") return 0;\n if (isName(beforeSpaces, \"OP\")) return 0;\n if (beforeSpaces !== undefined && beforeSpaces.name === \"QU\" && isPi(beforeSpaces)) {\n const before = items[last - 1];\n if (before === undefined || beforeOpening.has(before.name)) return 0;\n }\n if (d === \"QU\" && isPf(b) && (later === undefined || afterClosing.has(later.name))) return 0;\n if (c === \"SP\" && d === \"IS\" && isName(later, \"NU\")) return 1;\n if (d === \"IS\") return 0;\n if (d === \"NS\" && inClass(beforeSpaces, closing)) return 0;\n if (d === \"B2\" && isName(beforeSpaces, \"B2\")) return 0;\n if (c === \"SP\") return 1;\n if (d === \"QU\" && !isPi(b)) return 0;\n if (c === \"QU\" && !isPf(a)) return 0;\n if (d === \"QU\" && (!a.east || later === undefined || !later.east)) return 0;\n if (c === \"QU\" && (!b.east || earlier === undefined || !earlier.east)) return 0;\n if (d === \"CB\" || c === \"CB\") return 1;\n if (hyphens.has(c) && alphabetic.has(d) && (earlier === undefined || beforeHyphen.has(earlier.name))) return 0;\n if (d === \"BA\" || d === \"HH\" || d === \"HY\" || d === \"NS\" || c === \"BB\") return 0;\n if (isName(earlier, \"HL\") && hyphens.has(c) && d !== \"HL\") return 0;\n if (c === \"SY\" && d === \"HL\") return 0;\n if (d === \"IN\") return 0;\n if (alphabetic.has(c) && d === \"NU\") return 0;\n if (c === \"NU\" && alphabetic.has(d)) return 0;\n if (c === \"PR\" && emoji.has(d)) return 0;\n if (emoji.has(c) && d === \"PO\") return 0;\n if (prefix.has(c) && alphabetic.has(d)) return 0;\n if (alphabetic.has(c) && prefix.has(d)) return 0;\n if (prefix.has(d) && afterNumber(items, closing.has(c) ? i - 2 : i - 1)) return 0;\n if (d === \"NU\" && afterNumber(items, i - 1)) return 0;\n if (prefix.has(c) && (d === \"NU\" || (d === \"OP\" && (isName(later, \"NU\") || (isName(later, \"IS\") && isName(items[i + 2], \"NU\")))))) return 0;\n if ((c === \"HY\" || c === \"IS\") && d === \"NU\") return 0;\n if (c === \"JL\" && (d === \"JL\" || d === \"JV\" || d === \"H2\" || d === \"H3\")) return 0;\n if ((c === \"JV\" || c === \"H2\") && (d === \"JV\" || d === \"JT\")) return 0;\n if ((c === \"JT\" || c === \"H3\") && d === \"JT\") return 0;\n if (hangul.has(c) && d === \"PO\") return 0;\n if (c === \"PR\" && hangul.has(d)) return 0;\n if (alphabetic.has(c) && alphabetic.has(d)) return 0;\n if (c === \"AP\" && aksara(b)) return 0;\n if (aksara(a) && (d === \"VF\" || d === \"VI\")) return 0;\n if (c === \"VI\" && aksara(earlier) && aksaraStart(b)) return 0;\n if (aksara(a) && aksara(b) && isName(later, \"VF\")) return 0;\n if (c === \"IS\" && alphabetic.has(d)) return 0;\n if ((alphabetic.has(c) || c === \"NU\") && d === \"OP\" && !b.east) return 0;\n if (c === \"CP\" && !a.east && (alphabetic.has(d) || d === \"NU\")) return 0;\n if (c === \"RI\" && d === \"RI\") {\n let count = 0;\n for (let k = i - 1; k >= 0 && items[k]!.name === \"RI\"; k--) count++;\n if (count % 2 === 1) return 0;\n }\n if (d === \"EM\" && (c === \"EB\" || (pictographic.test(of(a)) && unassigned.test(of(a))))) return 0;\n return 1;\n}\n\n/**\n * This function gives the places where a line of a text can end, by the rules of UAX #14 without tailoring. The last place is\n * the end of the text, and an empty text has no place.\n */\nexport function lineBreaks(text: string): readonly LineBreak[] {\n const items = itemsOf(text);\n const breaks: LineBreak[] = [];\n for (let i = 1; i < items.length; i++) {\n const rule = ruleAt(items, i);\n if (rule !== 0) breaks.push({ offset: items[i]!.start, required: rule === 2 });\n }\n if (text.length > 0) breaks.push({ offset: text.length, required: true });\n return breaks;\n}\n","/**\n * The segments of UAX #29, from `Intl.Segmenter`. The results follow the Unicode version of the runtime. The locale is the root\n * locale, so the language of the host has no effect.\n */\nconst graphemeSegmenter = new Intl.Segmenter(\"und\", { granularity: \"grapheme\" });\nconst wordSegmenter = new Intl.Segmenter(\"und\", { granularity: \"word\" });\n\n/** This function gives the grapheme clusters of a text, in their order. */\nexport function graphemes(text: string): readonly string[] {\n return Array.from(graphemeSegmenter.segment(text), (part) => part.segment);\n}\n\n/** This function gives the offset in UTF-16 units of each word boundary of a text, with the end of the text and without its start. */\nexport function wordBreaks(text: string): readonly number[] {\n const offsets = Array.from(wordSegmenter.segment(text), (part) => part.index).slice(1);\n if (text.length > 0) offsets.push(text.length);\n return offsets;\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC,uIAAuI,MAAM,GAAG;AAC7L,MAAa,YAAY;AACzB,MAAa,gBAAgB;;;;;;ACgB7B,MAAM,WAAW;AACjB,IAAI;;AAGJ,SAAS,UAAiB;CACxB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,OAAO,CAAC,GAAG,UAAU,SAAS,0BAA0B,CAAC;CAC/D,MAAM,SAAS,IAAI,YAAY,KAAK,SAAS,CAAC;CAC9C,MAAM,UAAU,IAAI,WAAW,KAAK,MAAM;CAC1C,IAAI,QAAQ;CACZ,KAAK,SAAS,KAAK,UAAU;EAC3B,OAAO,SAAS;EAChB,QAAQ,SAAS,SAAS,QAAQ,IAAI,EAAG;EACzC,SAAS,OAAO,SAAS,IAAI,IAAK,EAAE;CACtC,CAAC;CACD,OAAO,KAAK,UAAU;CACtB,MAAM,UAAU,cAAc,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAA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"sources":["../src/segmentation/line-table.ts","../src/segmentation/line.ts","../src/segmentation/segments.ts"],"sourcesContent":["// Generated by `pnpm --filter @typeset/conformance tables` from Unicode 17.0.0. Do not edit.\nexport const unicodeVersion = \"17.0.0\";\nexport const classNames: readonly string[] = \"AL CM BA LF BK CR SP EX QU PR PO OP CP IS HY SY NU CL NL GL BB HH HL SA JL JV JT NS AK VI AS ID VF ZW ZWJ B2 IN WJ EB H2 H3 CB AP RI EM\".split(\" \");\nexport const classRuns = \"9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA1UwA2kB7TdBeA1N78A7B73A1N1V4A1J1A19B1V1B1A2B1A2B1H1B8ArW4A4WdA6Q3A3K2N2AbB1H1B3H17AlBaQ1K2Q3A1B2rA1H1A7B1Q1A6B2A2B1A4B2AaQnA1BuArB2jAbBfAaQxA9B4A1N1H3A1B2JmA4B1A9B1A3B1A5B17A3B1gA2Q5A9B16AoB1QxB1iA3B1AiB1A7BaA2B2CaQhA3B1kA1B1A7B2A2B2A3B9A1BaA2B2AaQ2A2K5A1K1A1J2A1B2A3B1kA1B1A5B4A2B2A3B3A1BkAaQ2B3A1BbA3B1kA1B1A8B1A3B1A3BkA2B2AaQ1A1J8A6B1A3B1kA1B1A7B2A2B2A3B7A3BaA2B2AaQiA1B1nA5B3A3B1A4B9A1BeAaQ9A1J6A5B1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ7A1U9A3B1U1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ3A1BcA4B1jA2B1A7B1A3B1A4B9A1BaA2B2AaQ9A1K7A3B1yA1B4A6B1A1B1A8B6AaQ2A2BdA1cX1B2X7B4A1J7X8B1AaQ2C11A2X1A1X1A5X1AoX1A1X1AaX1B2X9B1X2A5X1A1X1A7B1AaQ2A4XxA4U1A2U1T2U1C1T5H1T1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6pp 4 1 7 1 2 1 83 f 1 t 3 2 1 e 4 8 b0 6bo 2f 9 n 5n1 1 5m 1 5a 1 2 a 2t 3 d 18 4 9 7 2 e 6 4a x c 9 1 1y 1 m c 17 4 5 c h 3 1 3 1z 1 1 1 57 2 1r d 4 1 o i 1 q 2 d 1 2e 2d 1c 1y 6 1 3 3 2 4 3 4 b 2 7 9 6b c 4 1 7v 1b 1 a 1 55 34 d 3 b 3 1l 1 1 4 g 2 c 4 a zr 1eke 2 1eke i9du\";\n","/**\n * The line break algorithm of UAX #14. The rules run in their order, and the first rule that matches decides. The class of a\n * code point comes from a table that the tool in `packages/conformance` makes from the property files of Unicode.\n */\nimport { classNames, classRuns, eastAsianRuns } from \"./line-table.ts\";\n\n/** A place where a line can end. */\nexport interface LineBreak {\n /** The offset in UTF-16 units of the first character after the break. */\n readonly offset: number;\n /** This value is `true` when a line must end here, as at a line feed or at the end of the text. */\n readonly required: boolean;\n}\n\ninterface Table {\n readonly starts: Uint32Array;\n readonly classes: Uint8Array;\n readonly east: Uint32Array;\n /** The class name of each ASCII code point, from `starts` and `classes`. */\n readonly asciiNames: readonly string[];\n /** This value is `true` for an ASCII code point that is wide in East Asian text, from `east`. */\n readonly asciiEast: readonly boolean[];\n}\n\nconst alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~\";\nlet table: Table | undefined;\n\n/** This function decodes the runs one time, at the first use, so an import of the entry costs no work. */\nfunction tableOf(): Table {\n if (table !== undefined) return table;\n const runs = [...classRuns.matchAll(/([0-9a-z]+)([^0-9a-z])/gu)];\n const starts = new Uint32Array(runs.length + 1);\n const classes = new Uint8Array(runs.length);\n let start = 0;\n runs.forEach((run, index) => {\n starts[index] = start;\n classes[index] = alphabet.indexOf(run[2]!);\n start += Number.parseInt(run[1]!, 36);\n });\n starts[runs.length] = start;\n const lengths = eastAsianRuns.split(\" \").map((length) => Number.parseInt(length, 36));\n const east = new Uint32Array(lengths.length + 1);\n lengths.forEach((length, index) => {\n east[index + 1] = east[index]! + length;\n });\n const codes = Array.from({ length: 128 }, (_, code) => code);\n const asciiNames = codes.map((code) => classNames[classes[indexOfRun(starts, code)]!]!);\n const asciiEast = codes.map((code) => indexOfRun(east, code) % 2 === 1);\n table = { starts, classes, east, asciiNames, asciiEast };\n return table;\n}\n\n/** This function gives the index of the last start that is not above `code`. */\nfunction indexOfRun(starts: Uint32Array, code: number): number {\n let low = 0;\n let high = starts.length - 1;\n while (high - low > 1) {\n const middle = (low + high) >>> 1;\n if (starts[middle]! <= code) low = middle;\n else high = middle;\n }\n return low;\n}\n\n/** One base character and its combining marks, as the rule LB9 treats them. */\ninterface Item {\n readonly name: string;\n readonly code: number;\n readonly start: number;\n readonly east: boolean;\n /** This value is `true` when the last code point of the item is U+200D. */\n zwj: boolean;\n /** This value is `true` when the base character has the class SA. The rules read the item as AL. */\n readonly complex: boolean;\n}\n\nconst breakClasses = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\"]);\n\n/** This function makes the items of a text. It applies the rules LB9 and LB10. */\nfunction itemsOf(text: string): Item[] {\n const { starts, classes, east, asciiNames, asciiEast } = tableOf();\n const items: Item[] = [];\n let offset = 0;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n const name = code < 128 ? asciiNames[code]! : classNames[classes[indexOfRun(starts, code)]!]!;\n const combining = name === \"CM\" || name === \"ZWJ\";\n const last = items.at(-1);\n if (combining && last !== undefined && !breakClasses.has(last.name)) last.zwj = name === \"ZWJ\";\n else if (combining) items.push({ name: \"AL\", code: 0x41, start: offset, east: false, zwj: name === \"ZWJ\", complex: false });\n else if (name === \"SA\") items.push({ name: \"AL\", code, start: offset, east: indexOfRun(east, code) % 2 === 1, zwj: false, complex: true });\n else items.push({ name, code, start: offset, east: code < 128 ? asciiEast[code]! : indexOfRun(east, code) % 2 === 1, zwj: false, complex: false });\n offset += character.length;\n }\n return items;\n}\n\nconst initial = /^\\p{Pi}$/u;\nconst final = /^\\p{Pf}$/u;\nconst pictographic = /^\\p{Extended_Pictographic}$/u;\nconst unassigned = /^\\p{Cn}$/u;\nconst of = (item: Item): string => String.fromCodePoint(item.code);\nconst isPi = (item: Item): boolean => initial.test(of(item));\nconst isPf = (item: Item): boolean => final.test(of(item));\nconst inClass = (item: Item | undefined, names: Set<string>): boolean => item !== undefined && names.has(item.name);\nconst isName = (item: Item | undefined, name: string): boolean => item?.name === name;\n\nconst beforeOpening = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"OP\", \"QU\", \"GL\", \"SP\", \"ZW\"]);\nconst afterClosing = new Set([\"SP\", \"GL\", \"WJ\", \"CL\", \"QU\", \"CP\", \"EX\", \"IS\", \"SY\", \"BK\", \"CR\", \"LF\", \"NL\", \"ZW\"]);\nconst beforeHyphen = new Set([\"BK\", \"CR\", \"LF\", \"NL\", \"SP\", \"ZW\", \"CB\", \"GL\"]);\nconst alphabetic = new Set([\"AL\", \"HL\"]);\nconst hyphens = new Set([\"HY\", \"HH\"]);\nconst emoji = new Set([\"ID\", \"EB\", \"EM\"]);\nconst prefix = new Set([\"PR\", \"PO\"]);\nconst closing = new Set([\"CL\", \"CP\"]);\nconst separators = new Set([\"SY\", \"IS\"]);\nconst hangul = new Set([\"JL\", \"JV\", \"JT\", \"H2\", \"H3\"]);\nconst aksara = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.name === \"AS\" || item.code === 0x25cc);\nconst aksaraStart = (item: Item | undefined): boolean => item !== undefined && (item.name === \"AK\" || item.code === 0x25cc);\n\n/** This function tells if the items before `index` end with `NU (SY | IS)*`. */\nfunction afterNumber(items: readonly Item[], index: number): boolean {\n let i = index;\n while (i >= 0 && separators.has(items[i]!.name)) i--;\n return isName(items[i], \"NU\");\n}\n\n/** This function applies the rules LB4 to LB31 at the start of the item `i`. It gives 0 for no break, 1 for a break and 2 for a necessary break. */\nfunction ruleAt(items: readonly Item[], i: number): 0 | 1 | 2 {\n const a = items[i - 1]!;\n const b = items[i]!;\n const c = a.name;\n const d = b.name;\n const earlier = items[i - 2];\n const later = items[i + 1];\n if (c === \"BK\" || c === \"NL\" || c === \"LF\") return 2;\n if (c === \"CR\") return d === \"LF\" ? 0 : 2;\n if (d === \"BK\" || d === \"CR\" || d === \"LF\" || d === \"NL\" || d === \"SP\" || d === \"ZW\") return 0;\n let last = i - 1;\n while (last >= 0 && items[last]!.name === \"SP\") last--;\n const beforeSpaces = items[last];\n if (isName(beforeSpaces, \"ZW\")) return 1;\n if (a.zwj) return 0;\n if (d === \"WJ\" || c === \"WJ\" || c === \"GL\") return 0;\n if (d === \"GL\" && c !== \"SP\" && c !== \"BA\" && !hyphens.has(c)) return 0;\n if (d === \"CL\" || d === \"CP\" || d === \"EX\" || d === \"SY\") return 0;\n if (isName(beforeSpaces, \"OP\")) return 0;\n if (beforeSpaces !== undefined && beforeSpaces.name === \"QU\" && isPi(beforeSpaces)) {\n const before = items[last - 1];\n if (before === undefined || beforeOpening.has(before.name)) return 0;\n }\n if (d === \"QU\" && isPf(b) && (later === undefined || afterClosing.has(later.name))) return 0;\n if (c === \"SP\" && d === \"IS\" && isName(later, \"NU\")) return 1;\n if (d === \"IS\") return 0;\n if (d === \"NS\" && inClass(beforeSpaces, closing)) return 0;\n if (d === \"B2\" && isName(beforeSpaces, \"B2\")) return 0;\n if (c === \"SP\") return 1;\n if (d === \"QU\" && !isPi(b)) return 0;\n if (c === \"QU\" && !isPf(a)) return 0;\n if (d === \"QU\" && (!a.east || later === undefined || !later.east)) return 0;\n if (c === \"QU\" && (!b.east || earlier === undefined || !earlier.east)) return 0;\n if (d === \"CB\" || c === \"CB\") return 1;\n if (hyphens.has(c) && alphabetic.has(d) && (earlier === undefined || beforeHyphen.has(earlier.name))) return 0;\n if (d === \"BA\" || d === \"HH\" || d === \"HY\" || d === \"NS\" || c === \"BB\") return 0;\n if (isName(earlier, \"HL\") && hyphens.has(c) && d !== \"HL\") return 0;\n if (c === \"SY\" && d === \"HL\") return 0;\n if (d === \"IN\") return 0;\n if (alphabetic.has(c) && d === \"NU\") return 0;\n if (c === \"NU\" && alphabetic.has(d)) return 0;\n if (c === \"PR\" && emoji.has(d)) return 0;\n if (emoji.has(c) && d === \"PO\") return 0;\n if (prefix.has(c) && alphabetic.has(d)) return 0;\n if (alphabetic.has(c) && prefix.has(d)) return 0;\n if (prefix.has(d) && afterNumber(items, closing.has(c) ? i - 2 : i - 1)) return 0;\n if (d === \"NU\" && afterNumber(items, i - 1)) return 0;\n if (prefix.has(c) && (d === \"NU\" || (d === \"OP\" && (isName(later, \"NU\") || (isName(later, \"IS\") && isName(items[i + 2], \"NU\")))))) return 0;\n if ((c === \"HY\" || c === \"IS\") && d === \"NU\") return 0;\n if (c === \"JL\" && (d === \"JL\" || d === \"JV\" || d === \"H2\" || d === \"H3\")) return 0;\n if ((c === \"JV\" || c === \"H2\") && (d === \"JV\" || d === \"JT\")) return 0;\n if ((c === \"JT\" || c === \"H3\") && d === \"JT\") return 0;\n if (hangul.has(c) && d === \"PO\") return 0;\n if (c === \"PR\" && hangul.has(d)) return 0;\n if (alphabetic.has(c) && alphabetic.has(d)) return 0;\n if (c === \"AP\" && aksara(b)) return 0;\n if (aksara(a) && (d === \"VF\" || d === \"VI\")) return 0;\n if (c === \"VI\" && aksara(earlier) && aksaraStart(b)) return 0;\n if (aksara(a) && aksara(b) && isName(later, \"VF\")) return 0;\n if (c === \"IS\" && alphabetic.has(d)) return 0;\n if ((alphabetic.has(c) || c === \"NU\") && d === \"OP\" && !b.east) return 0;\n if (c === \"CP\" && !a.east && (alphabetic.has(d) || d === \"NU\")) return 0;\n if (c === \"RI\" && d === \"RI\") {\n let count = 0;\n for (let k = i - 1; k >= 0 && items[k]!.name === \"RI\"; k--) count++;\n if (count % 2 === 1) return 0;\n }\n if (d === \"EM\" && (c === \"EB\" || (pictographic.test(of(a)) && unassigned.test(of(a))))) return 0;\n return 1;\n}\n\n/** The options of `lineBreaks`. */\nexport interface LineBreakOptions {\n /**\n * The hook gives the break places inside a run of class SA (Thai, Lao, Khmer, Myanmar and others). It gets the text of the\n * run and gives offsets in the run. `complexBreaks` is a hook. With no hook, the rule LB1 reads the run as AL, so no break\n * is inside it, as in `LineBreakTest`.\n */\n readonly complex?: (run: string) => readonly number[];\n}\n\n/**\n * This function gives the places where a line of a text can end, by the rules of UAX #14. With no option, it applies no\n * tailoring. The last place is the end of the text, and an empty text has no place.\n *\n * The hook `complex` adds places inside each run of class SA. The function keeps only the places at the start of an item,\n * so no place is before a combining mark. The places outside the runs do not change.\n *\n * A text of only ASCII letters, digits and spaces takes a short path, because the rules give it a simple result. A line can\n * end after each run of spaces (LB18), and at no other place (LB7, LB23, LB25 and LB28). Such a text has no run of class\n * SA, so the hook adds no place to it.\n */\nexport function lineBreaks(text: string, options: LineBreakOptions = {}): readonly LineBreak[] {\n return simple.test(text) ? simpleBreaks(text) : ruleBreaks(text, options);\n}\n\n/** The texts of the short path of `lineBreaks`. */\nconst simple = /^[A-Za-z0-9 ]*$/u;\n\n/** This function gives the places of a text of only ASCII letters, digits and spaces: after each run of spaces, and at the end. */\nfunction simpleBreaks(text: string): LineBreak[] {\n const breaks: LineBreak[] = [];\n for (let i = 1; i < text.length; i++) if (text.charCodeAt(i - 1) === 32 && text.charCodeAt(i) !== 32) breaks.push({ offset: i, required: false });\n if (text.length > 0) breaks.push({ offset: text.length, required: true });\n return breaks;\n}\n\n/**\n * This function gives the places of a text by the rules of UAX #14, with no short path. The tests compare `lineBreaks` with\n * it. The entry `./segmentation` does not export it.\n */\nexport function ruleBreaks(text: string, options: LineBreakOptions = {}): readonly LineBreak[] {\n const items = itemsOf(text);\n const inside = options.complex === undefined ? undefined : complexPlaces(text, items, options.complex);\n const breaks: LineBreak[] = [];\n for (let i = 1; i < items.length; i++) {\n const rule = ruleAt(items, i);\n if (rule !== 0) breaks.push({ offset: items[i]!.start, required: rule === 2 });\n else if (inside?.has(i)) breaks.push({ offset: items[i]!.start, required: false });\n }\n if (text.length > 0) breaks.push({ offset: text.length, required: true });\n return breaks;\n}\n\n/** This function gives the indexes of the items inside the runs of class SA where the hook gives a place. */\nfunction complexPlaces(text: string, items: readonly Item[], complex: (run: string) => readonly number[]): Set<number> {\n const places = new Set<number>();\n for (let i = 0; i < items.length; i++) {\n if (!items[i]!.complex) continue;\n let last = i;\n while (last + 1 < items.length && items[last + 1]!.complex) last++;\n const start = items[i]!.start;\n const offsets = new Set(complex(text.slice(start, items[last + 1]?.start ?? text.length)));\n for (let k = i + 1; k <= last; k++) if (offsets.has(items[k]!.start - start)) places.add(k);\n i = last;\n }\n return places;\n}\n","/**\n * The segments of UAX #29, from `Intl.Segmenter`. The results follow the Unicode version of the runtime. The locale is the root\n * locale, so the language of the host has no effect.\n */\nconst graphemeSegmenter = new Intl.Segmenter(\"und\", { granularity: \"grapheme\" });\nconst wordSegmenter = new Intl.Segmenter(\"und\", { granularity: \"word\" });\n\n/** This function gives the grapheme clusters of a text, in their order. */\nexport function graphemes(text: string): readonly string[] {\n return Array.from(graphemeSegmenter.segment(text), (part) => part.segment);\n}\n\n/** This function gives the offset in UTF-16 units of each word boundary of a text, with the end of the text and without its start. */\nexport function wordBreaks(text: string): readonly number[] {\n const offsets = Array.from(wordSegmenter.segment(text), (part) => part.index).slice(1);\n if (text.length > 0) offsets.push(text.length);\n return offsets;\n}\n\n/**\n * This function gives the word boundaries of each word of a list. Each entry equals `wordBreaks` of its word. The function\n * segments the words in one pass, joined by line feeds, because UAX #29 breaks before and after each line feed (WB3a, WB3b).\n * A word that ends in a carriage return gets its own pass, because a carriage return and a line feed stay together (WB3).\n */\nexport function wordBreaksOf(words: readonly string[]): readonly (readonly number[])[] {\n const result: (readonly number[])[] = [];\n const lists: number[][] = [];\n const starts: number[] = [];\n const parts: string[] = [];\n let offset = 0;\n for (let index = 0; index < words.length; index++) {\n const word = words[index]!;\n if (word.endsWith(\"\\r\")) {\n result[index] = wordBreaks(word);\n continue;\n }\n const own: number[] = [];\n result[index] = own;\n lists.push(own);\n starts.push(offset);\n parts.push(word);\n offset += word.length + 1;\n }\n const text = parts.join(\"\\n\");\n let at = 0;\n // The boundaries come in order, so one sweep gives each boundary to its word. The boundary at the end of a word is the\n // start of the next line feed. The boundary after that line feed is the start of the next word, so no word gets it.\n for (const part of wordSegmenter.segment(text)) {\n const boundary = part.index;\n while (at < lists.length && boundary > starts[at]! + parts[at]!.length) at++;\n if (at < lists.length && boundary > starts[at]!) lists[at]!.push(boundary - starts[at]!);\n }\n const last = lists.length - 1;\n if (last >= 0 && parts[last]!.length > 0) lists[last]!.push(parts[last]!.length);\n return result;\n}\n\n/**\n * This function is a hook `complex` for `lineBreaks`. It gives the word boundaries inside a run of class SA, from\n * `Intl.Segmenter` of the runtime. The runtime has the dictionary, so the entry ships no dictionary. In a browser, the places\n * follow the dictionary of that browser.\n */\nexport function complexBreaks(run: string): readonly number[] {\n return wordBreaks(run).slice(0, -1);\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC,0IAA0I,MAAM,GAAG;AAChM,MAAa,YAAY;AACzB,MAAa,gBAAgB;;;;;;ACoB7B,MAAM,WAAW;AACjB,IAAI;;AAGJ,SAAS,UAAiB;CACxB,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,OAAO,CAAC,GAAG,UAAU,SAAS,0BAA0B,CAAC;CAC/D,MAAM,SAAS,IAAI,YAAY,KAAK,SAAS,CAAC;CAC9C,MAAM,UAAU,IAAI,WAAW,KAAK,MAAM;CAC1C,IAAI,QAAQ;CACZ,KAAK,SAAS,KAAK,UAAU;EAC3B,OAAO,SAAS;EAChB,QAAQ,SAAS,SAAS,QAAQ,IAAI,EAAG;EACzC,SAAS,OAAO,SAAS,IAAI,IAAK,EAAE;CACtC,CAAC;CACD,OAAO,KAAK,UAAU;CACtB,MAAM,UAAU,cAAc,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAAC;CACpF,MAAM,OAAO,IAAI,YAAY,QAAQ,SAAS,CA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MAAM,KAAK,CAAE,KAAK,MAAM,KAAK,CAAE,MAAM;CAC/E,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,KAAgC;CAC5D,OAAO,WAAW,GAAG,CAAC,CAAC,MAAM,GAAG,EAAE;AACpC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/typeset",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"description": "Text measurement and line breaking. The subpath ./fonts reads font tables and gives widths, ./measurer gives the advance function of a layout, ./breaking has the line breakers, ./segmentation has the break positions of Unicode, and ./text has a rope.",
|
|
4
|
+
"version": "0.1.9",
|
|
5
|
+
"description": "Text measurement and line breaking. The subpath ./fonts reads font tables and gives widths, ./measurer gives the advance function of a layout, ./breaking has the line breakers, ./segmentation has the break positions of Unicode, ./bidi has the bidirectional algorithm of Unicode, and ./text has a rope.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"typeset",
|
|
8
8
|
"line-breaking",
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
"types": "./build/measurer.d.ts",
|
|
47
47
|
"default": "./build/measurer.js"
|
|
48
48
|
},
|
|
49
|
+
"./bidi": {
|
|
50
|
+
"types": "./build/bidi.d.ts",
|
|
51
|
+
"default": "./build/bidi.js"
|
|
52
|
+
},
|
|
49
53
|
"./segmentation": {
|
|
50
54
|
"types": "./build/segmentation.d.ts",
|
|
51
55
|
"default": "./build/segmentation.js"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bracketPairs } from "./table.ts";
|
|
2
|
+
|
|
3
|
+
let brackets: Map<number, number> | undefined;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This function gives the value of a code point for the `brackets` of `resolveLevels`. The value is above 0 for an opening
|
|
7
|
+
* paired bracket, below 0 for a closing paired bracket, and 0 for each other code point. U+3009 and U+232A have the same value.
|
|
8
|
+
*/
|
|
9
|
+
export function bracketOf(codePoint: number): number {
|
|
10
|
+
if (brackets === undefined) {
|
|
11
|
+
brackets = new Map();
|
|
12
|
+
const lengths = bracketPairs.split(" ").map((length) => Number.parseInt(length, 36));
|
|
13
|
+
let open = 0;
|
|
14
|
+
for (let i = 0; i < lengths.length; i += 2) {
|
|
15
|
+
open += lengths[i]!;
|
|
16
|
+
const close = open + lengths[i + 1]!;
|
|
17
|
+
const id = close === 0x232a ? 0x3009 : close;
|
|
18
|
+
brackets.set(open, id);
|
|
19
|
+
brackets.set(close, -id);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return brackets.get(codePoint) ?? 0;
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class and the paired bracket of a code point. These values come from a table that the tool in `packages/conformance`
|
|
3
|
+
* makes from the property files of Unicode.
|
|
4
|
+
*/
|
|
5
|
+
import { bracketOf } from "./brackets.ts";
|
|
6
|
+
import { resolveLevels, type BidiClass, type ParagraphDirection, type ResolvedBidi } from "./resolve.ts";
|
|
7
|
+
import { classNames, classRuns } from "./table.ts";
|
|
8
|
+
|
|
9
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~";
|
|
10
|
+
let starts: Uint32Array | undefined;
|
|
11
|
+
let runClasses: Uint8Array | undefined;
|
|
12
|
+
|
|
13
|
+
/** This function decodes the runs one time, at the first use, so an import of the entry costs no work. */
|
|
14
|
+
function decodeRuns(): void {
|
|
15
|
+
const runs = [...classRuns.matchAll(/([0-9a-z]+)([^0-9a-z])/gu)];
|
|
16
|
+
starts = new Uint32Array(runs.length);
|
|
17
|
+
runClasses = new Uint8Array(runs.length);
|
|
18
|
+
let start = 0;
|
|
19
|
+
runs.forEach((run, index) => {
|
|
20
|
+
starts![index] = start;
|
|
21
|
+
runClasses![index] = alphabet.indexOf(run[2]!);
|
|
22
|
+
start += Number.parseInt(run[1]!, 36);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** This function gives the bidi class of a code point. */
|
|
27
|
+
export function bidiClass(codePoint: number): BidiClass {
|
|
28
|
+
if (starts === undefined) decodeRuns();
|
|
29
|
+
let low = 0;
|
|
30
|
+
let high = starts!.length;
|
|
31
|
+
while (high - low > 1) {
|
|
32
|
+
const middle = (low + high) >>> 1;
|
|
33
|
+
if (starts![middle]! <= codePoint) low = middle;
|
|
34
|
+
else high = middle;
|
|
35
|
+
}
|
|
36
|
+
return classNames[runClasses![low]!]! as BidiClass;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** This function gives the levels of each code point of a text. It applies `resolveLevels` with the exact classes and brackets. */
|
|
40
|
+
export function resolveText(text: string, direction: ParagraphDirection = "auto"): ResolvedBidi {
|
|
41
|
+
const codePoints = Array.from(text, (character) => character.codePointAt(0)!);
|
|
42
|
+
return resolveLevels(codePoints.map(bidiClass), codePoints.map(bracketOf), direction);
|
|
43
|
+
}
|