@mark1russell7/typeset 0.1.8 → 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.
@@ -0,0 +1,382 @@
1
+ // src/bidi/table.ts
2
+ const unicodeVersion = "17.0.0";
3
+ const classNames = [
4
+ "L",
5
+ "R",
6
+ "AL",
7
+ "ET",
8
+ "EN",
9
+ "ES",
10
+ "AN",
11
+ "CS",
12
+ "B",
13
+ "S",
14
+ "WS",
15
+ "ON",
16
+ "BN",
17
+ "NSM",
18
+ "LRO",
19
+ "RLO",
20
+ "LRE",
21
+ "RLE",
22
+ "PDF",
23
+ "LRI",
24
+ "RLI",
25
+ "FSI",
26
+ "PDI"
27
+ ];
28
+ const classRuns = "9M1J1I1J1K1IeM3I1J1K2L3D5L1F1H1F2HaE1H6LqA6LqA4L6M1IqM1H1L4D4L1A2L1M2L2D2E1L1A3L1E1A5LnA1LvA1LchA2L7AeL2AeL5A9L1AhL34N4A2L8A1L5A2L1A1L32A1L3wA7N74A1L2A2L1D1B19N1B1N1B2N1B2N1B1N1kB6G2L1C2D1C1H1C2LbN1cClNaG1D2G3C1N2tC7N1G1L6N2C2N1L4N2CaEnC1NuCrN2jCbNfC17B9N2B4L3B1NoB4N1B9N1B3N1B5N17B3N4B1cC2G5C9N16CoN1GwN1jA1N1A1N4A8N4A1N3A7NaA2NtA1N1mA1N4A4N8A1NkA2NeA2D7A1D2A1N2A2N1lA1N4A2N4A2N2A3N3A1NuA2N3A1NbA2N1lA1N4A5N1A2N4A1NkA2NdA1D8A6N1A1N1mA1N2A1N1A4N8A1N7A2NbA2NuA1N1pA1NcA1N11A6L1D1L5A1N3A1N1jA1N1A3N5A3N1A4N7A2NbA2NkA7L2A1N1mA1NfA2NkA2NsA2N1lA2N4A4N8A1NkA2NtA1N20A1N7A3N1A1N2iA1N2A7N4A1D7A8N2qA1N2A9NbA7N21A2NrA1N1A1N1A1N4L1fAeN1A5N1A2N5AbN1A10N9A1N2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2M1ekeA2M1ekeA2M1ekeA2M1ekeA76M6oN2s0M1bemA2M1ekeA2M1ekeA2M";
29
+ const bracketPairs = "14 1 1f 2 w 2 2wv 1 2 1 1gf 1 1wq 1 1k 1 g 1 hn 1 2 1 v 1 u7 1 2 1 2 1 2 1 2 1 2 1 2 1 29 1 x 1 2 1 2 1 2 1 2 1 b9 1 2 1 2 1 2 1 2 1 2 3 2 -1 2 1 2 1 2 1 2 1 1t 1 2 1 y 1 ti 1 2 1 2 1 2 1 19 1 2 1 2 1 2 1 bx 1 2 1 2 1 2 1 2 1 4 1 2 1 2 1 2 1 14qn 1 2 1 2 1 4r 1 1f 2 w 2 4 1 3 1";
30
+ // src/bidi/brackets.ts
31
+ let brackets;
32
+ /**
33
+ * This function gives the value of a code point for the `brackets` of `resolveLevels`. The value is above 0 for an opening
34
+ * 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.
35
+ */
36
+ function bracketOf(codePoint) {
37
+ if (brackets === void 0) {
38
+ brackets = /* @__PURE__ */ new Map();
39
+ const lengths = bracketPairs.split(" ").map((length) => Number.parseInt(length, 36));
40
+ let open = 0;
41
+ for (let i = 0; i < lengths.length; i += 2) {
42
+ open += lengths[i];
43
+ const close = open + lengths[i + 1];
44
+ const id = close === 9002 ? 12297 : close;
45
+ brackets.set(open, id);
46
+ brackets.set(close, -id);
47
+ }
48
+ }
49
+ return brackets.get(codePoint) ?? 0;
50
+ }
51
+ // src/bidi/resolve.ts
52
+ /** This value is the level of a character that the rule X9 removes. */
53
+ const removed = -1;
54
+ const L = 1;
55
+ const R = 2;
56
+ const AL = 4;
57
+ const EN = 8;
58
+ const ES = 16;
59
+ const ET = 32;
60
+ const AN = 64;
61
+ const CS = 128;
62
+ const NSM = 256;
63
+ const BN = 512;
64
+ const B = 1024;
65
+ const S = 2048;
66
+ const WS = 4096;
67
+ const ON = 8192;
68
+ const LRE = 16384;
69
+ const LRO = 32768;
70
+ const RLE = 65536;
71
+ const RLO = 1 << 17;
72
+ const PDF = 1 << 18;
73
+ const LRI = 1 << 19;
74
+ const RLI = 1 << 20;
75
+ const FSI = 1 << 21;
76
+ const PDI = 1 << 22;
77
+ const bits = {
78
+ L,
79
+ R,
80
+ AL,
81
+ EN,
82
+ ES,
83
+ ET,
84
+ AN,
85
+ CS,
86
+ NSM,
87
+ BN,
88
+ B,
89
+ S,
90
+ WS,
91
+ ON,
92
+ LRE,
93
+ LRO,
94
+ RLE,
95
+ RLO,
96
+ PDF,
97
+ LRI,
98
+ RLI,
99
+ FSI,
100
+ PDI
101
+ };
102
+ const isolates = 3670016;
103
+ const neutrals = 7879680;
104
+ const maxDepth = 125;
105
+ const maxBrackets = 63;
106
+ /** This function gives the direction of a type for the rules N0 to N2: numbers count as `R`, and a neutral gives 0. */
107
+ function strong(type) {
108
+ if (type === L) return L;
109
+ return type & 74 ? R : 0;
110
+ }
111
+ /** This function applies the rule BD9. It gives each isolate initiator the index of its PDI, or `end` when it has no PDI. */
112
+ function matchIsolates(original, start, end, match) {
113
+ const open = [];
114
+ for (let i = start; i < end; i++) if (original[i] & isolates) {
115
+ open.push(i);
116
+ match[i] = end;
117
+ } else if (original[i] === PDI && open.length > 0) match[open.pop()] = i;
118
+ }
119
+ /** This function applies the rules P2 and P3 to a range. It gives the level of the first strong character, or else 0. */
120
+ function firstStrong(original, start, end, match) {
121
+ for (let i = start; i < end; i++) {
122
+ const type = original[i];
123
+ if (type === L) return 0;
124
+ if (type & 6) return 1;
125
+ if (type & isolates) i = match[i];
126
+ }
127
+ return 0;
128
+ }
129
+ /** This function applies the rules X1 to X9. It sets `levels` and it changes `types` where an override applies. */
130
+ function resolveExplicit(original, types, match, levels, start, end, paragraph) {
131
+ const stack = [{
132
+ level: paragraph,
133
+ override: 0,
134
+ isolate: false
135
+ }];
136
+ let overflowIsolates = 0;
137
+ let overflowEmbeddings = 0;
138
+ let validIsolates = 0;
139
+ for (let i = start; i < end; i++) {
140
+ const type = original[i];
141
+ let top = stack.at(-1);
142
+ if (type & 3915776) {
143
+ const isolate = (type & isolates) !== 0;
144
+ levels[i] = isolate ? top.level : -1;
145
+ if (isolate && top.override) types[i] = top.override;
146
+ const level = type & 1245184 || type === FSI && firstStrong(original, i + 1, match[i], match) === 1 ? top.level + 1 | 1 : top.level + 2 & -2;
147
+ if (level <= maxDepth && overflowIsolates === 0 && overflowEmbeddings === 0) {
148
+ if (isolate) validIsolates++;
149
+ stack.push({
150
+ level,
151
+ override: type === RLO ? R : type === LRO ? L : 0,
152
+ isolate
153
+ });
154
+ } else if (isolate) overflowIsolates++;
155
+ else if (overflowIsolates === 0) overflowEmbeddings++;
156
+ } else if (type === PDI) {
157
+ if (overflowIsolates > 0) overflowIsolates--;
158
+ else if (validIsolates > 0) {
159
+ overflowEmbeddings = 0;
160
+ while (!stack.at(-1).isolate) stack.pop();
161
+ stack.pop();
162
+ validIsolates--;
163
+ }
164
+ top = stack.at(-1);
165
+ levels[i] = top.level;
166
+ if (top.override) types[i] = top.override;
167
+ } else if (type === PDF) {
168
+ levels[i] = -1;
169
+ if (overflowIsolates === 0) {
170
+ if (overflowEmbeddings > 0) overflowEmbeddings--;
171
+ else if (!top.isolate && stack.length > 1) stack.pop();
172
+ }
173
+ } else if (type === BN) levels[i] = -1;
174
+ else if (type === B) levels[i] = paragraph;
175
+ else {
176
+ levels[i] = top.level;
177
+ if (top.override) types[i] = top.override;
178
+ }
179
+ }
180
+ }
181
+ /** This function applies the rule BD13. It gives the indexes of each isolating run sequence. */
182
+ function sequencesOf(original, match, levels, start, end) {
183
+ const sequences = [];
184
+ const continued = /* @__PURE__ */ new Map();
185
+ let sequence = [];
186
+ let level = -1;
187
+ for (let i = start; i < end; i++) {
188
+ if (levels[i] === -1) continue;
189
+ if (levels[i] !== level) {
190
+ level = levels[i];
191
+ const next = continued.get(i);
192
+ if (next === void 0) sequences.push(sequence = []);
193
+ else sequence = next;
194
+ }
195
+ sequence.push(i);
196
+ if (original[i] & isolates) continued.set(match[i], sequence);
197
+ }
198
+ return sequences;
199
+ }
200
+ /** This function applies the rules W1 to W7 to the types of one sequence. */
201
+ function resolveWeak(sequenceTypes, sos) {
202
+ const n = sequenceTypes.length;
203
+ let previous = sos;
204
+ for (let k = 0; k < n; k++) {
205
+ if (sequenceTypes[k] === NSM) sequenceTypes[k] = previous & 7864320 ? ON : previous;
206
+ previous = sequenceTypes[k];
207
+ }
208
+ let last = sos;
209
+ for (let k = 0; k < n; k++) {
210
+ const type = sequenceTypes[k];
211
+ if (type & 7) last = type;
212
+ else if (type === EN && last === AL) sequenceTypes[k] = AN;
213
+ if (type === AL) sequenceTypes[k] = R;
214
+ }
215
+ for (let k = 1; k + 1 < n; k++) {
216
+ const type = sequenceTypes[k];
217
+ const before = sequenceTypes[k - 1];
218
+ if (type & 144 && before === sequenceTypes[k + 1] && (before === EN || before === AN && type === CS)) sequenceTypes[k] = before;
219
+ }
220
+ for (let k = 0; k < n; k++) {
221
+ if (sequenceTypes[k] !== ET) continue;
222
+ let end = k;
223
+ while (end < n && sequenceTypes[end] === ET) end++;
224
+ if (sequenceTypes[k - 1] === EN || sequenceTypes[end] === EN) sequenceTypes.fill(EN, k, end);
225
+ k = end - 1;
226
+ }
227
+ last = sos;
228
+ for (let k = 0; k < n; k++) {
229
+ const type = sequenceTypes[k];
230
+ if (type & 176) sequenceTypes[k] = ON;
231
+ else if (type & 3) last = type;
232
+ else if (type === EN && last === L) sequenceTypes[k] = L;
233
+ }
234
+ }
235
+ /** This function applies the rules BD16 and N0 to one sequence. A value of `brackets` is above 0 at an opening bracket and below 0 at its closing bracket. */
236
+ function resolveBrackets(sequenceTypes, sequence, original, brackets, direction, sos) {
237
+ const pairs = [];
238
+ const stack = [];
239
+ const n = sequence.length;
240
+ for (let k = 0; k < n; k++) {
241
+ const bracket = brackets[sequence[k]];
242
+ if (!bracket || sequenceTypes[k] !== ON) continue;
243
+ if (bracket > 0) {
244
+ if (stack.length === maxBrackets) {
245
+ pairs.length = 0;
246
+ break;
247
+ }
248
+ stack.push(k);
249
+ } else for (let depth = stack.length - 1; depth >= 0; depth--) {
250
+ if (brackets[sequence[stack[depth]]] !== -bracket) continue;
251
+ pairs.push([stack[depth], k]);
252
+ stack.length = depth;
253
+ break;
254
+ }
255
+ }
256
+ pairs.sort((first, second) => first[0] - second[0]);
257
+ for (const [open, close] of pairs) {
258
+ let found = 0;
259
+ for (let k = open + 1; k < close && found !== direction; k++) found = strong(sequenceTypes[k]) || found;
260
+ if (found === 0) continue;
261
+ if (found !== direction) {
262
+ let context = sos;
263
+ for (let k = open - 1; k >= 0; k--) {
264
+ if (strong(sequenceTypes[k]) === 0) continue;
265
+ context = strong(sequenceTypes[k]);
266
+ break;
267
+ }
268
+ if (context !== found) found = direction;
269
+ }
270
+ for (const bracket of [open, close]) {
271
+ sequenceTypes[bracket] = found;
272
+ for (let k = bracket + 1; k < n && original[sequence[k]] === NSM; k++) sequenceTypes[k] = found;
273
+ }
274
+ }
275
+ }
276
+ /** This function applies the rules N1 and N2 to the types of one sequence. */
277
+ function resolveNeutrals(sequenceTypes, direction, sos, eos) {
278
+ const n = sequenceTypes.length;
279
+ for (let k = 0; k < n; k++) {
280
+ if (!(sequenceTypes[k] & neutrals)) continue;
281
+ let end = k;
282
+ while (end < n && sequenceTypes[end] & neutrals) end++;
283
+ const before = k === 0 ? sos : strong(sequenceTypes[k - 1]);
284
+ const after = end === n ? eos : strong(sequenceTypes[end]);
285
+ sequenceTypes.fill(before === after ? before : direction, k, end);
286
+ k = end - 1;
287
+ }
288
+ }
289
+ /** This function applies the rule X10 and the rules W1 to N2 to one sequence. The level of the rules X1 to X9 gives the values of `sos` and `eos`. */
290
+ function resolveSequence(sequence, original, types, brackets, levels, start, end, paragraph) {
291
+ const first = sequence[0];
292
+ const last = sequence.at(-1);
293
+ const level = levels[first];
294
+ let before = first - 1;
295
+ while (before >= start && levels[before] === -1) before--;
296
+ let after = last + 1;
297
+ while (after < end && levels[after] === -1) after++;
298
+ const sos = Math.max(level, before < start ? paragraph : levels[before]) & 1 ? R : L;
299
+ const eos = Math.max(level, after === end || original[last] & isolates ? paragraph : levels[after]) & 1 ? R : L;
300
+ const sequenceTypes = sequence.map((i) => types[i]);
301
+ const direction = level & 1 ? R : L;
302
+ resolveWeak(sequenceTypes, sos);
303
+ resolveBrackets(sequenceTypes, sequence, original, brackets, direction, sos);
304
+ resolveNeutrals(sequenceTypes, direction, sos, eos);
305
+ sequence.forEach((i, k) => {
306
+ types[i] = sequenceTypes[k];
307
+ });
308
+ }
309
+ /** This function applies the rules I1, I2 and L1 to one paragraph. */
310
+ function resolveImplicit(original, types, levels, start, end, paragraph) {
311
+ let atEnd = true;
312
+ for (let i = end - 1; i >= start; i--) {
313
+ if (levels[i] === -1) continue;
314
+ const type = types[i];
315
+ const kind = original[i];
316
+ levels[i] += levels[i] & 1 ? type === R ? 0 : 1 : type === L ? 0 : type === R ? 1 : 2;
317
+ if (kind & 3072) atEnd = true;
318
+ else if (!(kind & 7868416)) atEnd = false;
319
+ if (atEnd) levels[i] = paragraph;
320
+ }
321
+ }
322
+ /**
323
+ * This function gives the levels of a text from its classes, with the rules P1 to L1 of UAX #9. A class `B` ends a paragraph.
324
+ * A value of `brackets` is 0 for a character that is not a paired bracket. It is above 0 at an opening bracket and below 0
325
+ * at the closing bracket with the same absolute value. `bracketOf` of `./bidi` gives these values.
326
+ */
327
+ function resolveLevels(classes, brackets = [], direction = "auto") {
328
+ const n = classes.length;
329
+ const original = new Int32Array(n);
330
+ for (let i = 0; i < n; i++) original[i] = bits[classes[i]];
331
+ const types = original.slice();
332
+ const match = new Int32Array(n);
333
+ const levels = new Array(n).fill(0);
334
+ const paragraphs = [];
335
+ for (let start = 0; start < n;) {
336
+ let end = start;
337
+ while (end < n && original[end] !== B) end++;
338
+ end = Math.min(end + 1, n);
339
+ matchIsolates(original, start, end, match);
340
+ const level = direction === "auto" ? firstStrong(original, start, end, match) : direction;
341
+ resolveExplicit(original, types, match, levels, start, end, level);
342
+ for (const sequence of sequencesOf(original, match, levels, start, end)) resolveSequence(sequence, original, types, brackets, levels, start, end, level);
343
+ resolveImplicit(original, types, levels, start, end, level);
344
+ paragraphs.push({
345
+ start,
346
+ end,
347
+ level
348
+ });
349
+ start = end;
350
+ }
351
+ return {
352
+ levels,
353
+ paragraphs
354
+ };
355
+ }
356
+ /**
357
+ * This function puts items in the visual order of the rule L2 of UAX #9. Each item has the level `levels[i]`. From the
358
+ * highest level to the level 1, it reverses each sequence of items at that level or higher.
359
+ */
360
+ function visualOrder(items, levels) {
361
+ const order = items.map((_, i) => i);
362
+ const n = order.length;
363
+ for (let level = levels.reduce((highest, value) => Math.max(highest, value), 0); level >= 1; level--) for (let i = 0; i < n; i++) {
364
+ if (levels[order[i]] < level) continue;
365
+ let end = i;
366
+ while (end < n && levels[order[end]] >= level) end++;
367
+ for (let low = i, high = end - 1; low < high; low++, high--) [order[low], order[high]] = [order[high], order[low]];
368
+ i = end;
369
+ }
370
+ return order.map((i) => items[i]);
371
+ }
372
+ /** This function gives the indexes of the characters in the visual order, for each paragraph as one line. It omits each removed character. */
373
+ function visualIndexes({ levels, paragraphs }) {
374
+ return paragraphs.flatMap(({ start, end }) => {
375
+ const kept = [];
376
+ for (let i = start; i < end; i++) if (levels[i] !== -1) kept.push(i);
377
+ return visualOrder(kept, kept.map((i) => levels[i]));
378
+ });
379
+ }
380
+ export { bracketOf as a, unicodeVersion as c, visualOrder as i, resolveLevels as n, classNames as o, visualIndexes as r, classRuns as s, removed as t };
381
+
382
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","names":[],"sources":["../../src/bidi/table.ts","../../src/bidi/brackets.ts","../../src/bidi/resolve.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[] = [\"L\",\"R\",\"AL\",\"ET\",\"EN\",\"ES\",\"AN\",\"CS\",\"B\",\"S\",\"WS\",\"ON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 2 1 2 1 2 1 14qn 1 2 1 2 1 4r 1 1f 2 w 2 4 1 3 1\";\n","import { bracketPairs } from \"./table.ts\";\n\nlet brackets: Map<number, number> | undefined;\n\n/**\n * This function gives the value of a code point for the `brackets` of `resolveLevels`. The value is above 0 for an opening\n * 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.\n */\nexport function bracketOf(codePoint: number): number {\n if (brackets === undefined) {\n brackets = new Map();\n const lengths = bracketPairs.split(\" \").map((length) => Number.parseInt(length, 36));\n let open = 0;\n for (let i = 0; i < lengths.length; i += 2) {\n open += lengths[i]!;\n const close = open + lengths[i + 1]!;\n const id = close === 0x232a ? 0x3009 : close;\n brackets.set(open, id);\n brackets.set(close, -id);\n }\n }\n return brackets.get(codePoint) ?? 0;\n}\n","/**\n * The rules of the Unicode Bidirectional Algorithm (UAX #9). This module works on bidi classes and has no table, so `./fonts`\n * can use it with its own classes. The comments give the names of the rules. This module treats each paragraph as one line.\n */\n\n/** A bidi class of UAX #9. */\nexport type BidiClass =\n | \"L\"\n | \"R\"\n | \"AL\"\n | \"EN\"\n | \"ES\"\n | \"ET\"\n | \"AN\"\n | \"CS\"\n | \"NSM\"\n | \"BN\"\n | \"B\"\n | \"S\"\n | \"WS\"\n | \"ON\"\n | \"LRE\"\n | \"LRO\"\n | \"RLE\"\n | \"RLO\"\n | \"PDF\"\n | \"LRI\"\n | \"RLI\"\n | \"FSI\"\n | \"PDI\";\n\n/** The paragraph direction: `0` is left to right, `1` is right to left, and `\"auto\"` applies the rules P2 and P3. */\nexport type ParagraphDirection = 0 | 1 | \"auto\";\n\n/** One paragraph of a resolved text. */\nexport interface BidiParagraph {\n /** The index of the first character. */\n readonly start: number;\n /** The index after the last character. */\n readonly end: number;\n /** The paragraph embedding level. */\n readonly level: number;\n}\n\n/** The result of `resolveLevels`. */\nexport interface ResolvedBidi {\n /** The level of each character. The value is `removed` for a character that the rule X9 removes. */\n readonly levels: number[];\n readonly paragraphs: readonly BidiParagraph[];\n}\n\n/** This value is the level of a character that the rule X9 removes. */\nexport const removed = -1;\n\nconst L = 1 << 0;\nconst R = 1 << 1;\nconst AL = 1 << 2;\nconst EN = 1 << 3;\nconst ES = 1 << 4;\nconst ET = 1 << 5;\nconst AN = 1 << 6;\nconst CS = 1 << 7;\nconst NSM = 1 << 8;\nconst BN = 1 << 9;\nconst B = 1 << 10;\nconst S = 1 << 11;\nconst WS = 1 << 12;\nconst ON = 1 << 13;\nconst LRE = 1 << 14;\nconst LRO = 1 << 15;\nconst RLE = 1 << 16;\nconst RLO = 1 << 17;\nconst PDF = 1 << 18;\nconst LRI = 1 << 19;\nconst RLI = 1 << 20;\nconst FSI = 1 << 21;\nconst PDI = 1 << 22;\n\nconst bits: Readonly<Record<BidiClass, number>> = { L, R, AL, EN, ES, ET, AN, CS, NSM, BN, B, S, WS, ON, LRE, LRO, RLE, RLO, PDF, LRI, RLI, FSI, PDI };\nconst isolates = LRI | RLI | FSI;\nconst neutrals = B | S | WS | ON | isolates | PDI;\nconst maxDepth = 125;\nconst maxBrackets = 63;\n\n/** One entry of the directional status stack of the rule X1. */\ninterface Status {\n readonly level: number;\n readonly override: number;\n readonly isolate: boolean;\n}\n\n/** This function gives the direction of a type for the rules N0 to N2: numbers count as `R`, and a neutral gives 0. */\nfunction strong(type: number): number {\n if (type === L) return L;\n return type & (R | EN | AN) ? R : 0;\n}\n\n/** This function applies the rule BD9. It gives each isolate initiator the index of its PDI, or `end` when it has no PDI. */\nfunction matchIsolates(original: Int32Array, start: number, end: number, match: Int32Array): void {\n const open: number[] = [];\n for (let i = start; i < end; i++) {\n if (original[i]! & isolates) {\n open.push(i);\n match[i] = end;\n } else if (original[i] === PDI && open.length > 0) {\n match[open.pop()!] = i;\n }\n }\n}\n\n/** This function applies the rules P2 and P3 to a range. It gives the level of the first strong character, or else 0. */\nfunction firstStrong(original: Int32Array, start: number, end: number, match: Int32Array): number {\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n if (type === L) return 0;\n if (type & (R | AL)) return 1;\n if (type & isolates) i = match[i]!;\n }\n return 0;\n}\n\n/** This function applies the rules X1 to X9. It sets `levels` and it changes `types` where an override applies. */\nfunction resolveExplicit(original: Int32Array, types: Int32Array, match: Int32Array, levels: number[], start: number, end: number, paragraph: number): void {\n const stack: Status[] = [{ level: paragraph, override: 0, isolate: false }];\n let overflowIsolates = 0;\n let overflowEmbeddings = 0;\n let validIsolates = 0;\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n let top = stack.at(-1)!;\n if (type & (RLE | LRE | RLO | LRO | isolates)) {\n const isolate = (type & isolates) !== 0;\n levels[i] = isolate ? top.level : removed;\n if (isolate && top.override) types[i] = top.override;\n const right = type & (RLE | RLO | RLI) || (type === FSI && firstStrong(original, i + 1, match[i]!, match) === 1);\n const level = right ? (top.level + 1) | 1 : (top.level + 2) & ~1;\n if (level <= maxDepth && overflowIsolates === 0 && overflowEmbeddings === 0) {\n if (isolate) validIsolates++;\n stack.push({ level, override: type === RLO ? R : type === LRO ? L : 0, isolate });\n } else if (isolate) {\n overflowIsolates++;\n } else if (overflowIsolates === 0) {\n overflowEmbeddings++;\n }\n } else if (type === PDI) {\n if (overflowIsolates > 0) {\n overflowIsolates--;\n } else if (validIsolates > 0) {\n overflowEmbeddings = 0;\n while (!stack.at(-1)!.isolate) stack.pop();\n stack.pop();\n validIsolates--;\n }\n top = stack.at(-1)!;\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n } else if (type === PDF) {\n levels[i] = removed;\n if (overflowIsolates === 0) {\n if (overflowEmbeddings > 0) overflowEmbeddings--;\n else if (!top.isolate && stack.length > 1) stack.pop();\n }\n } else if (type === BN) {\n levels[i] = removed;\n } else if (type === B) {\n levels[i] = paragraph;\n } else {\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n }\n }\n}\n\n/** This function applies the rule BD13. It gives the indexes of each isolating run sequence. */\nfunction sequencesOf(original: Int32Array, match: Int32Array, levels: readonly number[], start: number, end: number): number[][] {\n const sequences: number[][] = [];\n const continued = new Map<number, number[]>();\n let sequence: number[] = [];\n let level = removed;\n for (let i = start; i < end; i++) {\n if (levels[i] === removed) continue;\n if (levels[i] !== level) {\n level = levels[i]!;\n const next = continued.get(i);\n if (next === undefined) sequences.push((sequence = []));\n else sequence = next;\n }\n sequence.push(i);\n if (original[i]! & isolates) continued.set(match[i]!, sequence);\n }\n return sequences;\n}\n\n/** This function applies the rules W1 to W7 to the types of one sequence. */\nfunction resolveWeak(sequenceTypes: number[], sos: number): void {\n const n = sequenceTypes.length;\n let previous = sos;\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] === NSM) sequenceTypes[k] = previous & (isolates | PDI) ? ON : previous;\n previous = sequenceTypes[k]!;\n }\n let last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (L | R | AL)) last = type;\n else if (type === EN && last === AL) sequenceTypes[k] = AN;\n if (type === AL) sequenceTypes[k] = R;\n }\n for (let k = 1; k + 1 < n; k++) {\n const type = sequenceTypes[k]!;\n const before = sequenceTypes[k - 1]!;\n if (type & (ES | CS) && before === sequenceTypes[k + 1] && (before === EN || (before === AN && type === CS))) sequenceTypes[k] = before;\n }\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] !== ET) continue;\n let end = k;\n while (end < n && sequenceTypes[end] === ET) end++;\n if (sequenceTypes[k - 1] === EN || sequenceTypes[end] === EN) sequenceTypes.fill(EN, k, end);\n k = end - 1;\n }\n last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (ES | ET | CS)) sequenceTypes[k] = ON;\n else if (type & (L | R)) last = type;\n else if (type === EN && last === L) sequenceTypes[k] = L;\n }\n}\n\n/** This function applies the rules BD16 and N0 to one sequence. A value of `brackets` is above 0 at an opening bracket and below 0 at its closing bracket. */\nfunction resolveBrackets(sequenceTypes: number[], sequence: readonly number[], original: Int32Array, brackets: readonly number[], direction: number, sos: number): void {\n const pairs: [number, number][] = [];\n const stack: number[] = [];\n const n = sequence.length;\n for (let k = 0; k < n; k++) {\n const bracket = brackets[sequence[k]!];\n if (!bracket || sequenceTypes[k] !== ON) continue;\n if (bracket > 0) {\n if (stack.length === maxBrackets) {\n pairs.length = 0;\n break;\n }\n stack.push(k);\n } else {\n for (let depth = stack.length - 1; depth >= 0; depth--) {\n if (brackets[sequence[stack[depth]!]!] !== -bracket) continue;\n pairs.push([stack[depth]!, k]);\n stack.length = depth;\n break;\n }\n }\n }\n pairs.sort((first, second) => first[0] - second[0]);\n for (const [open, close] of pairs) {\n let found = 0;\n for (let k = open + 1; k < close && found !== direction; k++) found = strong(sequenceTypes[k]!) || found;\n if (found === 0) continue;\n if (found !== direction) {\n let context = sos;\n for (let k = open - 1; k >= 0; k--) {\n if (strong(sequenceTypes[k]!) === 0) continue;\n context = strong(sequenceTypes[k]!);\n break;\n }\n if (context !== found) found = direction;\n }\n for (const bracket of [open, close]) {\n sequenceTypes[bracket] = found;\n for (let k = bracket + 1; k < n && original[sequence[k]!] === NSM; k++) sequenceTypes[k] = found;\n }\n }\n}\n\n/** This function applies the rules N1 and N2 to the types of one sequence. */\nfunction resolveNeutrals(sequenceTypes: number[], direction: number, sos: number, eos: number): void {\n const n = sequenceTypes.length;\n for (let k = 0; k < n; k++) {\n if (!(sequenceTypes[k]! & neutrals)) continue;\n let end = k;\n while (end < n && sequenceTypes[end]! & neutrals) end++;\n const before = k === 0 ? sos : strong(sequenceTypes[k - 1]!);\n const after = end === n ? eos : strong(sequenceTypes[end]!);\n sequenceTypes.fill(before === after ? before : direction, k, end);\n k = end - 1;\n }\n}\n\n/** This function applies the rule X10 and the rules W1 to N2 to one sequence. The level of the rules X1 to X9 gives the values of `sos` and `eos`. */\nfunction resolveSequence(sequence: readonly number[], original: Int32Array, types: Int32Array, brackets: readonly number[], levels: readonly number[], start: number, end: number, paragraph: number): void {\n const first = sequence[0]!;\n const last = sequence.at(-1)!;\n const level = levels[first]!;\n let before = first - 1;\n while (before >= start && levels[before] === removed) before--;\n let after = last + 1;\n while (after < end && levels[after] === removed) after++;\n const sos = Math.max(level, before < start ? paragraph : levels[before]!) & 1 ? R : L;\n const eos = Math.max(level, after === end || original[last]! & isolates ? paragraph : levels[after]!) & 1 ? R : L;\n const sequenceTypes = sequence.map((i) => types[i]!);\n const direction = level & 1 ? R : L;\n resolveWeak(sequenceTypes, sos);\n resolveBrackets(sequenceTypes, sequence, original, brackets, direction, sos);\n resolveNeutrals(sequenceTypes, direction, sos, eos);\n sequence.forEach((i, k) => {\n types[i] = sequenceTypes[k]!;\n });\n}\n\n/** This function applies the rules I1, I2 and L1 to one paragraph. */\nfunction resolveImplicit(original: Int32Array, types: Int32Array, levels: number[], start: number, end: number, paragraph: number): void {\n let atEnd = true;\n for (let i = end - 1; i >= start; i--) {\n if (levels[i] === removed) continue;\n const type = types[i]!;\n const kind = original[i]!;\n levels[i]! += levels[i]! & 1 ? (type === R ? 0 : 1) : type === L ? 0 : type === R ? 1 : 2;\n if (kind & (S | B)) atEnd = true;\n else if (!(kind & (WS | isolates | PDI))) atEnd = false;\n if (atEnd) levels[i] = paragraph;\n }\n}\n\n/**\n * This function gives the levels of a text from its classes, with the rules P1 to L1 of UAX #9. A class `B` ends a paragraph.\n * A value of `brackets` is 0 for a character that is not a paired bracket. It is above 0 at an opening bracket and below 0\n * at the closing bracket with the same absolute value. `bracketOf` of `./bidi` gives these values.\n */\nexport function resolveLevels(classes: readonly BidiClass[], brackets: readonly number[] = [], direction: ParagraphDirection = \"auto\"): ResolvedBidi {\n const n = classes.length;\n const original = new Int32Array(n);\n for (let i = 0; i < n; i++) original[i] = bits[classes[i]!];\n const types = original.slice();\n const match = new Int32Array(n);\n const levels = new Array<number>(n).fill(0);\n const paragraphs: BidiParagraph[] = [];\n for (let start = 0; start < n; ) {\n let end = start;\n while (end < n && original[end] !== B) end++;\n end = Math.min(end + 1, n);\n matchIsolates(original, start, end, match);\n const level = direction === \"auto\" ? firstStrong(original, start, end, match) : direction;\n resolveExplicit(original, types, match, levels, start, end, level);\n for (const sequence of sequencesOf(original, match, levels, start, end)) resolveSequence(sequence, original, types, brackets, levels, start, end, level);\n resolveImplicit(original, types, levels, start, end, level);\n paragraphs.push({ start, end, level });\n start = end;\n }\n return { levels, paragraphs };\n}\n\n/**\n * This function puts items in the visual order of the rule L2 of UAX #9. Each item has the level `levels[i]`. From the\n * highest level to the level 1, it reverses each sequence of items at that level or higher.\n */\nexport function visualOrder<T>(items: readonly T[], levels: readonly number[]): T[] {\n const order = items.map((_, i) => i);\n const n = order.length;\n for (let level = levels.reduce((highest, value) => Math.max(highest, value), 0); level >= 1; level--) {\n for (let i = 0; i < n; i++) {\n if (levels[order[i]!]! < level) continue;\n let end = i;\n while (end < n && levels[order[end]!]! >= level) end++;\n for (let low = i, high = end - 1; low < high; low++, high--) [order[low], order[high]] = [order[high]!, order[low]!];\n i = end;\n }\n }\n return order.map((i) => items[i]!);\n}\n\n/** This function gives the indexes of the characters in the visual order, for each paragraph as one line. It omits each removed character. */\nexport function visualIndexes({ levels, paragraphs }: ResolvedBidi): number[] {\n return paragraphs.flatMap(({ start, end }) => {\n const kept: number[] = [];\n for (let i = start; i < end; i++) if (levels[i] !== removed) kept.push(i);\n return visualOrder(\n kept,\n kept.map((i) => levels[i]!),\n );\n });\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC;CAAC;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAK;AACtK,MAAa,YAAY;AACzB,MAAa,eAAe;;ACF5B,IAAI;;;;;AAMJ,SAAgB,UAAU,WAA2B;CACnD,IAAI,aAAa,KAAA,GAAW;EAC1B,2BAAW,IAAI,IAAI;EACnB,MAAM,UAAU,aAAa,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAAC;EACnF,IAAI,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,IAAI,GAAG,KAAK;EAC1B,IAAI,OAAO,MAAM,MAAQ,OAAO;EAChC,IAAI,MAAM;EACV,OAAO,MAAM,KAAK,OAAO,MAAM,SAAW,OAAO;EACjD,KAAK,IAAI,MAAM,GAAG,OAAO,MAAM,GAAG,MAAM,MAAM,OAAO,QAAQ,CAAC,MAAM,MAAM,MAAM,SAAS,CAAC,MAAM,OAAQ,MAAM,IAAK;EACnH,IAAI;CACN;CAEF,OAAO,MAAM,KAAK,MAAM,MAAM,EAAG;AACnC;;AAGA,SAAgB,cAAc,EAAE,QAAQ,cAAsC;CAC5E,OAAO,WAAW,SAAS,EAAE,OAAO,UAAU;EAC5C,MAAM,OAAiB,CAAC;EACxB,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,KAAK,IAAI,OAAO,OAAA,IAAgB,KAAK,KAAK,CAAC;EACxE,OAAO,YACL,MACA,KAAK,KAAK,MAAM,OAAO,EAAG,CAC5B;CACF,CAAC;AACH"}
@@ -5,18 +5,43 @@ interface LineBreak {
5
5
  /** This value is `true` when a line must end here, as at a line feed or at the end of the text. */
6
6
  readonly required: boolean;
7
7
  }
8
+ /** The options of `lineBreaks`. */
9
+ interface LineBreakOptions {
10
+ /**
11
+ * The hook gives the break places inside a run of class SA (Thai, Lao, Khmer, Myanmar and others). It gets the text of the
12
+ * 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
13
+ * is inside it, as in `LineBreakTest`.
14
+ */
15
+ readonly complex?: (run: string) => readonly number[];
16
+ }
8
17
  /**
9
- * 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
10
- * the end of the text, and an empty text has no place.
18
+ * 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
19
+ * tailoring. The last place is the end of the text, and an empty text has no place.
20
+ *
21
+ * The hook `complex` adds places inside each run of class SA. The function keeps only the places at the start of an item,
22
+ * so no place is before a combining mark. The places outside the runs do not change.
11
23
  *
12
24
  * A text of only ASCII letters, digits and spaces takes a short path, because the rules give it a simple result. A line can
13
- * end after each run of spaces (LB18), and at no other place (LB7, LB23, LB25 and LB28).
25
+ * 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
26
+ * SA, so the hook adds no place to it.
14
27
  */
15
- export declare function lineBreaks(text: string): readonly LineBreak[];
28
+ export declare function lineBreaks(text: string, options?: LineBreakOptions): readonly LineBreak[];
16
29
  export declare const unicodeVersion = "17.0.0";
17
30
  /** This function gives the grapheme clusters of a text, in their order. */
18
31
  export declare function graphemes(text: string): readonly string[];
19
32
  /** 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. */
20
33
  export declare function wordBreaks(text: string): readonly number[];
21
- export type { LineBreak };
34
+ /**
35
+ * This function gives the word boundaries of each word of a list. Each entry equals `wordBreaks` of its word. The function
36
+ * segments the words in one pass, joined by line feeds, because UAX #29 breaks before and after each line feed (WB3a, WB3b).
37
+ * A word that ends in a carriage return gets its own pass, because a carriage return and a line feed stay together (WB3).
38
+ */
39
+ export declare function wordBreaksOf(words: readonly string[]): readonly (readonly number[])[];
40
+ /**
41
+ * This function is a hook `complex` for `lineBreaks`. It gives the word boundaries inside a run of class SA, from
42
+ * `Intl.Segmenter` of the runtime. The runtime has the dictionary, so the entry ships no dictionary. In a browser, the places
43
+ * follow the dictionary of that browser.
44
+ */
45
+ export declare function complexBreaks(run: string): readonly number[];
46
+ export type { LineBreak, LineBreakOptions };
22
47
  //# sourceMappingURL=segmentation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"segmentation.d.ts","names":[],"sources":["../src/segmentation/line.ts","../src/segmentation/line-table.ts","../src/segmentation/segments.ts"],"mappings":";UAOiB;;WAEN;;WAEA;;;;;;;;;wBAgMK,WAAW,wBAAwB;qBC1MtC;;wBCOG,UAAU;;wBAKV,WAAW"}
1
+ {"version":3,"file":"segmentation.d.ts","names":[],"sources":["../src/segmentation/line.ts","../src/segmentation/line-table.ts","../src/segmentation/segments.ts"],"mappings":";UAOiB;;WAEN;;WAEA;;;UA6LM;;;;;;WAMN,WAAW;;;;;;;;;;;;;wBAcN,WAAW,cAAc,UAAS,4BAAiC;qBC3NtE;;wBCOG,UAAU;;wBAKV,WAAW;;;;;;wBAWX,aAAa;;;;;;wBAsCb,cAAc"}