@mark1russell7/typeset 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/chunks/text.d.ts.map +1 -1
- package/build/chunks/text.js +122 -115
- package/build/chunks/text.js.map +1 -1
- package/build/segmentation.d.ts +3 -0
- package/build/segmentation.d.ts.map +1 -1
- package/build/segmentation.js +32 -4
- package/build/segmentation.js.map +1 -1
- package/package.json +2 -1
- package/src/segmentation/line.ts +33 -4
- package/src/text/rope.ts +105 -123
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ console.log(edited.toString(), edited.width);
|
|
|
36
36
|
|
|
37
37
|
- Each edit gives a new rope. The old rope does not change, and the two share the parts that the edit does not touch.
|
|
38
38
|
- An edit uses the width function of the order of `log n` times, on the changed leaves and on short windows.
|
|
39
|
+
- The rope keeps the widths of short windows, so an edit measures only the windows that it changes. `Text.from` clears them, so a new rope sees a font that loaded.
|
|
39
40
|
- The width is exact when the width function obeys the separator law: `width(p + s + q) = width(p + s) + width(s + q) - width(s)`.
|
|
40
41
|
- The separator `s` is a space or a tab. The option `separators` changes the set.
|
|
41
42
|
- The font model of `./fonts` obeys the law for its shaping `dom` and `canvas`, with the sum `exact`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","names":[],"sources":["../../src/text/rope.ts","../../src/text.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"text.d.ts","names":[],"sources":["../../src/text/rope.ts","../../src/text.ts"],"mappings":";;UAkBiB;;;;;WAKN;;WAEA;;;;;;cAwIE;;UAIH;;SAMD,KAAK,cAAc,OAAO,SAAS,UAAS,cAAmB;;MAelE;;MAKA;;MAKA;;EAKJ;;EAKA;;EAKA,MAAM,eAAe,eAA4B;;EAYjD,QAAQ,eAAe;;EAKvB,OAAO,OAAO,OAAO;;EAMrB,OAAO,YAAY,eAAe;;EAKlC,OAAO,eAAe,cAAc;;EAKpC,QAAQ,eAAe,aAAa,eAAe"}
|
package/build/chunks/text.js
CHANGED
|
@@ -1,62 +1,91 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime.js";
|
|
2
|
+
import * as Tree from "@mark1russell7/collections/summary-tree";
|
|
2
3
|
// src/text/rope.ts
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The `Text` rope: a persistent balanced tree of strings with the width and the length of each subtree. An edit makes a
|
|
6
|
+
* new rope. The new rope shares the subtrees that do not change. The tree is the `summary-tree` record of
|
|
7
|
+
* `@mark1russell7/collections`, and this module gives it the summary of a text.
|
|
8
|
+
*
|
|
9
|
+
* A width function gives the width of a run of text. The rope uses it only for the leaves and for the windows at the
|
|
10
|
+
* seams. Thus an edit uses it of the order of `log n` times. The rope keeps the widths of the short windows, so an edit
|
|
11
|
+
* measures only the windows that it changes. `Text.from` clears this memory.
|
|
12
|
+
*
|
|
13
|
+
* The seams are exact when the width function obeys the separator law. For each text `p + s + q` with a separator `s`:
|
|
14
|
+
* `width(p + s + q) = width(p + s) + width(s + q) - width(s)`. The model of `@mark1russell7/typeset/fonts` obeys it for a space and a
|
|
15
|
+
* tab. It shapes each word alone, and its kerning goes only between two adjacent glyphs.
|
|
16
|
+
*/
|
|
17
|
+
/** The summary of the empty text. */
|
|
18
|
+
const noText = {
|
|
19
|
+
length: 0,
|
|
20
|
+
width: 0,
|
|
21
|
+
separated: false,
|
|
22
|
+
head: "",
|
|
23
|
+
headWidth: 0,
|
|
24
|
+
tail: "",
|
|
25
|
+
tailWidth: 0
|
|
26
|
+
};
|
|
27
|
+
/** The largest count of windows in the memory of a context. */
|
|
28
|
+
const windowLimit = 16384;
|
|
29
|
+
/** This function gives the width of a window. A window longer than a leaf stays out of the memory. */
|
|
30
|
+
function windowWidth(context, window) {
|
|
31
|
+
if (window.length > context.chunk) return context.width(window);
|
|
32
|
+
const known = context.windows.get(window);
|
|
33
|
+
if (known !== void 0) return known;
|
|
34
|
+
const width = context.width(window);
|
|
35
|
+
if (context.windows.size >= windowLimit) context.windows.clear();
|
|
36
|
+
context.windows.set(window, width);
|
|
37
|
+
return width;
|
|
38
|
+
}
|
|
39
|
+
function isSeparator(separators, code) {
|
|
40
|
+
for (let i = 0; i < separators.length; i++) if (separators.charCodeAt(i) === code) return true;
|
|
5
41
|
return false;
|
|
6
42
|
}
|
|
7
|
-
function
|
|
8
|
-
const
|
|
43
|
+
function summaryOfLeaf(context, text) {
|
|
44
|
+
const { separators } = context;
|
|
45
|
+
const whole = context.width(text);
|
|
9
46
|
let first = -1;
|
|
10
47
|
let last = -1;
|
|
11
48
|
for (let i = 0; i < text.length; i++) {
|
|
12
|
-
if (!isSeparator(
|
|
49
|
+
if (!isSeparator(separators, text.charCodeAt(i))) continue;
|
|
13
50
|
if (first < 0) first = i;
|
|
14
51
|
last = i;
|
|
15
52
|
}
|
|
16
53
|
if (first < 0) return {
|
|
17
|
-
kind: "leaf",
|
|
18
|
-
text,
|
|
19
|
-
height: 0,
|
|
20
54
|
length: text.length,
|
|
21
|
-
width,
|
|
55
|
+
width: whole,
|
|
22
56
|
separated: false,
|
|
23
57
|
head: text,
|
|
24
|
-
headWidth:
|
|
58
|
+
headWidth: whole,
|
|
25
59
|
tail: text,
|
|
26
|
-
tailWidth:
|
|
60
|
+
tailWidth: whole
|
|
27
61
|
};
|
|
28
62
|
const head = text.slice(0, first + 1);
|
|
29
63
|
const tail = text.slice(last);
|
|
30
64
|
return {
|
|
31
|
-
kind: "leaf",
|
|
32
|
-
text,
|
|
33
|
-
height: 0,
|
|
34
65
|
length: text.length,
|
|
35
|
-
width,
|
|
66
|
+
width: whole,
|
|
36
67
|
separated: true,
|
|
37
68
|
head,
|
|
38
|
-
headWidth: context
|
|
69
|
+
headWidth: windowWidth(context, head),
|
|
39
70
|
tail,
|
|
40
|
-
tailWidth: context
|
|
71
|
+
tailWidth: windowWidth(context, tail)
|
|
41
72
|
};
|
|
42
73
|
}
|
|
43
74
|
/**
|
|
44
|
-
* This function
|
|
45
|
-
*
|
|
75
|
+
* This function gives the summary of two runs in the order of the text. It measures one window: the tail of the left run and
|
|
76
|
+
* the head of the right run. The separator law then gives the width of all the text from the widths of the two runs.
|
|
46
77
|
*/
|
|
47
|
-
function
|
|
78
|
+
function combine(context, left, right) {
|
|
79
|
+
if (left.length === 0) return right;
|
|
80
|
+
if (right.length === 0) return left;
|
|
48
81
|
const seam = left.tail + right.head;
|
|
49
|
-
const seamWidth = context
|
|
82
|
+
const seamWidth = windowWidth(context, seam);
|
|
50
83
|
let width;
|
|
51
84
|
if (!left.separated && !right.separated) width = seamWidth;
|
|
52
85
|
else if (!left.separated) width = right.width - right.headWidth + seamWidth;
|
|
53
86
|
else if (!right.separated) width = left.width - left.tailWidth + seamWidth;
|
|
54
87
|
else width = left.width + right.width - left.tailWidth - right.headWidth + seamWidth;
|
|
55
88
|
return {
|
|
56
|
-
kind: "branch",
|
|
57
|
-
left,
|
|
58
|
-
right,
|
|
59
|
-
height: Math.max(left.height, right.height) + 1,
|
|
60
89
|
length: left.length + right.length,
|
|
61
90
|
width,
|
|
62
91
|
separated: left.separated || right.separated,
|
|
@@ -66,96 +95,60 @@ function branchOf(context, left, right) {
|
|
|
66
95
|
tailWidth: right.separated ? right.tailWidth : seamWidth
|
|
67
96
|
};
|
|
68
97
|
}
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
/** This function balances the branch of `heavy` and `right`, when `heavy` is 2 levels higher than `right`. */
|
|
95
|
-
function rotateRight(context, heavy, right) {
|
|
96
|
-
if (heavy.right.height <= heavy.left.height) return branchOf(context, heavy.left, branchOf(context, heavy.right, right));
|
|
97
|
-
const middle = heavy.right;
|
|
98
|
-
return branchOf(context, branchOf(context, heavy.left, middle.left), branchOf(context, middle.right, right));
|
|
99
|
-
}
|
|
100
|
-
/** This function divides a tree at the UTF-16 offset `at` into the text before and the text after. */
|
|
101
|
-
function split(context, node, at) {
|
|
102
|
-
if (node === void 0) return [void 0, void 0];
|
|
103
|
-
if (at <= 0) return [void 0, node];
|
|
104
|
-
if (at >= node.length) return [node, void 0];
|
|
105
|
-
if (node.kind === "leaf") return [leafOf(context, node.text.slice(0, at)), leafOf(context, node.text.slice(at))];
|
|
106
|
-
if (at === node.left.length) return [node.left, node.right];
|
|
107
|
-
if (at < node.left.length) {
|
|
108
|
-
const [before, after] = split(context, node.left, at);
|
|
109
|
-
return [before, join(context, after, node.right)];
|
|
110
|
-
}
|
|
111
|
-
const [before, after] = split(context, node.right, at - node.left.length);
|
|
112
|
-
return [join(context, node.left, before), after];
|
|
98
|
+
/** The contexts of each width function. Two ropes join only when their trees have the same spec. */
|
|
99
|
+
const contexts = /* @__PURE__ */ new WeakMap();
|
|
100
|
+
function contextOf(width, separators, chunk) {
|
|
101
|
+
const own = contexts.get(width) ?? /* @__PURE__ */ new Map();
|
|
102
|
+
contexts.set(width, own);
|
|
103
|
+
const key = `${chunk}/${separators}`;
|
|
104
|
+
const known = own.get(key);
|
|
105
|
+
if (known !== void 0) return known;
|
|
106
|
+
const context = {
|
|
107
|
+
width,
|
|
108
|
+
separators,
|
|
109
|
+
chunk,
|
|
110
|
+
spec: {
|
|
111
|
+
monoid: {
|
|
112
|
+
empty: noText,
|
|
113
|
+
combine: (left, right) => combine(context, left, right)
|
|
114
|
+
},
|
|
115
|
+
measure: (leaf) => summaryOfLeaf(context, leaf),
|
|
116
|
+
merge: (left, right) => left.length + right.length <= chunk ? left + right : void 0
|
|
117
|
+
},
|
|
118
|
+
windows: /* @__PURE__ */ new Map()
|
|
119
|
+
};
|
|
120
|
+
own.set(key, context);
|
|
121
|
+
return context;
|
|
113
122
|
}
|
|
114
123
|
/** This function gives the end of the next leaf of `text` from `start`: after a separator when it can, and not in a surrogate pair. */
|
|
115
124
|
function chunkEnd(context, text, start) {
|
|
116
125
|
const limit = start + context.chunk;
|
|
117
126
|
if (limit >= text.length) return text.length;
|
|
118
|
-
for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context, text.charCodeAt(i))) return i + 1;
|
|
127
|
+
for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context.separators, text.charCodeAt(i))) return i + 1;
|
|
119
128
|
const code = text.charCodeAt(limit - 1);
|
|
120
129
|
return code >= 55296 && code <= 56319 ? limit - 1 : limit;
|
|
121
130
|
}
|
|
122
|
-
/** This function
|
|
123
|
-
function
|
|
124
|
-
|
|
131
|
+
/** This function divides a text into leaves of at most `chunk` code units. */
|
|
132
|
+
function chunksOf(context, text) {
|
|
133
|
+
const out = [];
|
|
125
134
|
for (let start = 0; start < text.length;) {
|
|
126
135
|
const end = chunkEnd(context, text, start);
|
|
127
|
-
|
|
136
|
+
out.push(text.slice(start, end));
|
|
128
137
|
start = end;
|
|
129
138
|
}
|
|
130
|
-
if (level.length === 0) return void 0;
|
|
131
|
-
while (level.length > 1) {
|
|
132
|
-
const next = [];
|
|
133
|
-
for (let i = 0; i + 1 < level.length; i += 2) next.push(branchOf(context, level[i], level[i + 1]));
|
|
134
|
-
if (level.length % 2 === 1) next.push(level[level.length - 1]);
|
|
135
|
-
level = next;
|
|
136
|
-
}
|
|
137
|
-
return level[0];
|
|
138
|
-
}
|
|
139
|
-
function leaves(node, out) {
|
|
140
|
-
if (node === void 0) return out;
|
|
141
|
-
const stack = [node];
|
|
142
|
-
while (stack.length > 0) {
|
|
143
|
-
const top = stack.pop();
|
|
144
|
-
if (top.kind === "leaf") out.push(top.text);
|
|
145
|
-
else stack.push(top.right, top.left);
|
|
146
|
-
}
|
|
147
139
|
return out;
|
|
148
140
|
}
|
|
141
|
+
const lengthOf = (summary) => summary.length;
|
|
149
142
|
/**
|
|
150
143
|
* A text with its width: a persistent balanced rope. Each edit gives a new `Text` and does not change this one. The offsets
|
|
151
144
|
* are in UTF-16 code units, as the offsets of a JavaScript string.
|
|
152
145
|
*/
|
|
153
146
|
var Text = class Text {
|
|
154
147
|
#context;
|
|
155
|
-
#
|
|
156
|
-
constructor(context,
|
|
148
|
+
#tree;
|
|
149
|
+
constructor(context, tree) {
|
|
157
150
|
this.#context = context;
|
|
158
|
-
this.#
|
|
151
|
+
this.#tree = tree;
|
|
159
152
|
}
|
|
160
153
|
/** This function makes the rope of `text` with the width function `width`. */
|
|
161
154
|
static from(text, width, options = {}) {
|
|
@@ -166,39 +159,40 @@ var Text = class Text {
|
|
|
166
159
|
const code = separators.charCodeAt(i);
|
|
167
160
|
if (code >= 55296 && code <= 57343) throw new RangeError("a separator is one UTF-16 code unit, not a half of a surrogate pair");
|
|
168
161
|
}
|
|
169
|
-
const context =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
chunk
|
|
173
|
-
};
|
|
174
|
-
return new Text(context, build(context, text));
|
|
162
|
+
const context = contextOf(width, separators, chunk);
|
|
163
|
+
context.windows.clear();
|
|
164
|
+
return new Text(context, Tree.of(context.spec, chunksOf(context, text)));
|
|
175
165
|
}
|
|
176
166
|
/** The count of UTF-16 code units of the text. */
|
|
177
167
|
get length() {
|
|
178
|
-
return this.#
|
|
168
|
+
return Tree.summary(this.#tree).length;
|
|
179
169
|
}
|
|
180
170
|
/** The width of the text. It is equal to the width of the flat string when the width function obeys the separator law. */
|
|
181
171
|
get width() {
|
|
182
|
-
return this.#
|
|
172
|
+
return Tree.summary(this.#tree).width;
|
|
183
173
|
}
|
|
184
174
|
/** The height of the tree: 0 for a text of one leaf. The tests use it to examine the balance. */
|
|
185
175
|
get height() {
|
|
186
|
-
return this.#
|
|
176
|
+
return Math.max(0, Tree.height(this.#tree) - 1);
|
|
187
177
|
}
|
|
188
178
|
/** This function gives the flat string. */
|
|
189
179
|
toString() {
|
|
190
|
-
return
|
|
180
|
+
return this.chunks().join("");
|
|
191
181
|
}
|
|
192
182
|
/** This function gives the strings of the leaves in the order of the text. */
|
|
193
183
|
chunks() {
|
|
194
|
-
return
|
|
184
|
+
return Tree.toArray(this.#tree);
|
|
195
185
|
}
|
|
196
186
|
/** This function gives the text from `start` to `end`, as a new rope. */
|
|
197
187
|
slice(start, end = this.length) {
|
|
198
188
|
this.#check(start, end);
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
189
|
+
if (start === end) return new Text(this.#context, Tree.slice(this.#tree, 0, 0));
|
|
190
|
+
const first = Tree.locate(this.#tree, lengthOf, start);
|
|
191
|
+
const last = Tree.locate(this.#tree, lengthOf, end - 1);
|
|
192
|
+
const stop = first.offset + end - start;
|
|
193
|
+
const middle = Tree.slice(this.#tree, first.index, last.index + 1);
|
|
194
|
+
if (first.index === last.index) return new Text(this.#context, Tree.set(middle, 0, first.leaf.slice(first.offset, stop)));
|
|
195
|
+
return new Text(this.#context, Tree.set(Tree.set(middle, -1, last.leaf.slice(0, last.offset + 1)), 0, first.leaf.slice(first.offset)));
|
|
202
196
|
}
|
|
203
197
|
/** This function gives the width of the text from `start` to `end`. */
|
|
204
198
|
widthOf(start, end = this.length) {
|
|
@@ -206,9 +200,8 @@ var Text = class Text {
|
|
|
206
200
|
}
|
|
207
201
|
/** This function gives this text and then `other`. The two ropes must have the same width function and options. */
|
|
208
202
|
concat(other) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return new Text(this.#context, join(this.#context, this.#root, other.#root));
|
|
203
|
+
if (other.#context !== this.#context) throw new TypeError("the two ropes have different width functions or options");
|
|
204
|
+
return new Text(this.#context, Tree.concat(this.#tree, other.#tree));
|
|
212
205
|
}
|
|
213
206
|
/** This function puts `text` at the offset `at`. */
|
|
214
207
|
insert(at, text) {
|
|
@@ -221,10 +214,24 @@ var Text = class Text {
|
|
|
221
214
|
/** This function puts `text` in place of the text from `start` to `end`. */
|
|
222
215
|
replace(start, end, text) {
|
|
223
216
|
this.#check(start, end);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
217
|
+
if (start === end && text.length === 0) return this;
|
|
218
|
+
if (Tree.size(this.#tree) === 0) return Text.from(text, this.#context.width, this.#context);
|
|
219
|
+
const first = Tree.locate(this.#tree, lengthOf, start) ?? this.#lastPlace();
|
|
220
|
+
const last = start === end ? first : Tree.locate(this.#tree, lengthOf, end - 1);
|
|
221
|
+
const lastEnd = start === end ? first.offset : last.offset + 1;
|
|
222
|
+
const fresh = first.leaf.slice(0, first.offset) + text + last.leaf.slice(lastEnd);
|
|
223
|
+
const leaves = chunksOf(this.#context, fresh);
|
|
224
|
+
if (first.index === last.index && leaves.length === 1 && leaves[0].length * 2 >= this.#context.chunk) return new Text(this.#context, Tree.set(this.#tree, first.index, leaves[0]));
|
|
225
|
+
return new Text(this.#context, Tree.splice(this.#tree, first.index, last.index - first.index + 1, leaves));
|
|
226
|
+
}
|
|
227
|
+
/** This function gives the place after the last code unit: the end of the last leaf. */
|
|
228
|
+
#lastPlace() {
|
|
229
|
+
const leaf = Tree.at(this.#tree, -1);
|
|
230
|
+
return {
|
|
231
|
+
index: Tree.size(this.#tree) - 1,
|
|
232
|
+
leaf,
|
|
233
|
+
offset: leaf.length
|
|
234
|
+
};
|
|
228
235
|
}
|
|
229
236
|
#check(start, end) {
|
|
230
237
|
if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end < start || end > this.length) throw new RangeError(`the range ${start} to ${end} is not in the text of length ${this.length}`);
|
package/build/chunks/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","names":[],"sources":["../../src/text/rope.ts","../../src/text.ts"],"sourcesContent":["/**\n * The `Text` rope: a persistent balanced tree of strings with the width and the length of each subtree. An edit makes a\n * new rope. The new rope shares the subtrees that do not change. A width function gives the width of a run of text. The\n * rope uses it only for the leaves and for the windows at the seams. Thus an edit uses it of the order of `log n` times.\n *\n * The seams are exact when the width function obeys the separator law. For each text `p + s + q` with a separator `s`:\n * `width(p + s + q) = width(p + s) + width(s + q) - width(s)`. The model of `@mark1russell7/typeset/fonts` obeys it for a space and a\n * tab. It shapes each word alone, and its kerning goes only between two adjacent glyphs.\n */\nimport type { WidthOf } from \"../breaking/paragraph.ts\";\n\n/** The options of a rope. */\nexport interface TextOptions {\n /**\n * The separators of the separator law: each character is one UTF-16 code unit. The default is a space and a tab. An\n * empty string makes each seam measure the full text of the two sides.\n */\n readonly separators?: string;\n /** The largest count of UTF-16 code units in a leaf. The default is 256. */\n readonly chunk?: number;\n}\n\n/** The summary of a subtree: its length, its width, and the two ends that a seam measures again. */\ninterface Summary {\n /** The count of UTF-16 code units. */\n readonly length: number;\n readonly width: number;\n /** This value is `true` when the text has a separator. */\n readonly separated: boolean;\n /** The text through the first separator, or all the text when the text has no separator. */\n readonly head: string;\n readonly headWidth: number;\n /** The text from the last separator, or all the text when the text has no separator. */\n readonly tail: string;\n readonly tailWidth: number;\n}\n\ninterface Leaf extends Summary {\n readonly kind: \"leaf\";\n readonly text: string;\n readonly height: 0;\n}\n\ninterface Branch extends Summary {\n readonly kind: \"branch\";\n readonly left: Node;\n readonly right: Node;\n readonly height: number;\n}\n\ntype Node = Leaf | Branch;\n\n/** The shared state of the ropes of one width function and one set of options. */\ninterface Context {\n readonly width: WidthOf;\n readonly separators: string;\n readonly chunk: number;\n}\n\nfunction isSeparator(context: Context, code: number): boolean {\n for (let i = 0; i < context.separators.length; i++) if (context.separators.charCodeAt(i) === code) return true;\n return false;\n}\n\nfunction leafOf(context: Context, text: string): Leaf {\n const width = context.width(text);\n let first = -1;\n let last = -1;\n for (let i = 0; i < text.length; i++) {\n if (!isSeparator(context, text.charCodeAt(i))) continue;\n if (first < 0) first = i;\n last = i;\n }\n if (first < 0) return { kind: \"leaf\", text, height: 0, length: text.length, width, separated: false, head: text, headWidth: width, tail: text, tailWidth: width };\n const head = text.slice(0, first + 1);\n const tail = text.slice(last);\n return { kind: \"leaf\", text, height: 0, length: text.length, width, separated: true, head, headWidth: context.width(head), tail, tailWidth: context.width(tail) };\n}\n\n/**\n * This function makes the branch of two subtrees. It measures one window: the tail of the left side and the head of the right\n * side. The separator law then gives the width of all the text from the widths of the two sides.\n */\nfunction branchOf(context: Context, left: Node, right: Node): Branch {\n const seam = left.tail + right.head;\n const seamWidth = context.width(seam);\n let width: number;\n if (!left.separated && !right.separated) width = seamWidth;\n else if (!left.separated) width = right.width - right.headWidth + seamWidth;\n else if (!right.separated) width = left.width - left.tailWidth + seamWidth;\n else width = left.width + right.width - left.tailWidth - right.headWidth + seamWidth;\n return {\n kind: \"branch\",\n left,\n right,\n height: Math.max(left.height, right.height) + 1,\n length: left.length + right.length,\n width,\n separated: left.separated || right.separated,\n head: left.separated ? left.head : seam,\n headWidth: left.separated ? left.headWidth : seamWidth,\n tail: right.separated ? right.tail : seam,\n tailWidth: right.separated ? right.tailWidth : seamWidth,\n };\n}\n\n/** This function joins two trees in the order of the text and keeps the heights of the two children within 1. */\nfunction join(context: Context, left: Node | undefined, right: Node | undefined): Node | undefined {\n if (left === undefined) return right;\n if (right === undefined) return left;\n if (left.kind === \"leaf\" && right.kind === \"leaf\" && left.length + right.length <= context.chunk) return leafOf(context, left.text + right.text);\n if (left.height > right.height + 1) {\n const branch = left as Branch;\n const joined = join(context, branch.right, right)!;\n if (joined.height <= branch.left.height + 1) return branchOf(context, branch.left, joined);\n return rotateLeft(context, branch.left, joined as Branch);\n }\n if (right.height > left.height + 1) {\n const branch = right as Branch;\n const joined = join(context, left, branch.left)!;\n if (joined.height <= branch.right.height + 1) return branchOf(context, joined, branch.right);\n return rotateRight(context, joined as Branch, branch.right);\n }\n return branchOf(context, left, right);\n}\n\n/** This function balances the branch of `left` and `heavy`, when `heavy` is 2 levels higher than `left`. */\nfunction rotateLeft(context: Context, left: Node, heavy: Branch): Branch {\n if (heavy.left.height <= heavy.right.height) return branchOf(context, branchOf(context, left, heavy.left), heavy.right);\n const middle = heavy.left as Branch;\n return branchOf(context, branchOf(context, left, middle.left), branchOf(context, middle.right, heavy.right));\n}\n\n/** This function balances the branch of `heavy` and `right`, when `heavy` is 2 levels higher than `right`. */\nfunction rotateRight(context: Context, heavy: Branch, right: Node): Branch {\n if (heavy.right.height <= heavy.left.height) return branchOf(context, heavy.left, branchOf(context, heavy.right, right));\n const middle = heavy.right as Branch;\n return branchOf(context, branchOf(context, heavy.left, middle.left), branchOf(context, middle.right, right));\n}\n\n/** This function divides a tree at the UTF-16 offset `at` into the text before and the text after. */\nfunction split(context: Context, node: Node | undefined, at: number): [Node | undefined, Node | undefined] {\n if (node === undefined) return [undefined, undefined];\n if (at <= 0) return [undefined, node];\n if (at >= node.length) return [node, undefined];\n if (node.kind === \"leaf\") return [leafOf(context, node.text.slice(0, at)), leafOf(context, node.text.slice(at))];\n if (at === node.left.length) return [node.left, node.right];\n if (at < node.left.length) {\n const [before, after] = split(context, node.left, at);\n return [before, join(context, after, node.right)];\n }\n const [before, after] = split(context, node.right, at - node.left.length);\n return [join(context, node.left, before), after];\n}\n\n/** This function gives the end of the next leaf of `text` from `start`: after a separator when it can, and not in a surrogate pair. */\nfunction chunkEnd(context: Context, text: string, start: number): number {\n const limit = start + context.chunk;\n if (limit >= text.length) return text.length;\n for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context, text.charCodeAt(i))) return i + 1;\n const code = text.charCodeAt(limit - 1);\n return code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit;\n}\n\n/** This function makes a balanced tree of a text: leaves of at most `chunk` code units, and then a level of branches at a time. */\nfunction build(context: Context, text: string): Node | undefined {\n let level: Node[] = [];\n for (let start = 0; start < text.length; ) {\n const end = chunkEnd(context, text, start);\n level.push(leafOf(context, text.slice(start, end)));\n start = end;\n }\n if (level.length === 0) return undefined;\n while (level.length > 1) {\n const next: Node[] = [];\n for (let i = 0; i + 1 < level.length; i += 2) next.push(branchOf(context, level[i]!, level[i + 1]!));\n if (level.length % 2 === 1) next.push(level[level.length - 1]!);\n level = next;\n }\n return level[0];\n}\n\nfunction leaves(node: Node | undefined, out: string[]): string[] {\n if (node === undefined) return out;\n const stack: Node[] = [node];\n while (stack.length > 0) {\n const top = stack.pop()!;\n if (top.kind === \"leaf\") out.push(top.text);\n else stack.push(top.right, top.left);\n }\n return out;\n}\n\n/**\n * A text with its width: a persistent balanced rope. Each edit gives a new `Text` and does not change this one. The offsets\n * are in UTF-16 code units, as the offsets of a JavaScript string.\n */\nexport class Text {\n readonly #context: Context;\n readonly #root: Node | undefined;\n\n private constructor(context: Context, root: Node | undefined) {\n this.#context = context;\n this.#root = root;\n }\n\n /** This function makes the rope of `text` with the width function `width`. */\n static from(text: string, width: WidthOf, options: TextOptions = {}): Text {\n const separators = options.separators ?? \" \\t\";\n const chunk = options.chunk ?? 256;\n if (!Number.isInteger(chunk) || chunk < 2) throw new RangeError(`the chunk is ${chunk}, not an integer of 2 or more`);\n for (let i = 0; i < separators.length; i++) {\n const code = separators.charCodeAt(i);\n if (code >= 0xd800 && code <= 0xdfff) throw new RangeError(\"a separator is one UTF-16 code unit, not a half of a surrogate pair\");\n }\n const context: Context = { width, separators, chunk };\n return new Text(context, build(context, text));\n }\n\n /** The count of UTF-16 code units of the text. */\n get length(): number {\n return this.#root?.length ?? 0;\n }\n\n /** The width of the text. It is equal to the width of the flat string when the width function obeys the separator law. */\n get width(): number {\n return this.#root?.width ?? 0;\n }\n\n /** The height of the tree: 0 for a text of one leaf. The tests use it to examine the balance. */\n get height(): number {\n return this.#root?.height ?? 0;\n }\n\n /** This function gives the flat string. */\n toString(): string {\n return leaves(this.#root, []).join(\"\");\n }\n\n /** This function gives the strings of the leaves in the order of the text. */\n chunks(): string[] {\n return leaves(this.#root, []);\n }\n\n /** This function gives the text from `start` to `end`, as a new rope. */\n slice(start: number, end: number = this.length): Text {\n this.#check(start, end);\n const [, after] = split(this.#context, this.#root, start);\n const [middle] = split(this.#context, after, end - start);\n return new Text(this.#context, middle);\n }\n\n /** This function gives the width of the text from `start` to `end`. */\n widthOf(start: number, end: number = this.length): number {\n return this.slice(start, end).width;\n }\n\n /** This function gives this text and then `other`. The two ropes must have the same width function and options. */\n concat(other: Text): Text {\n const context = other.#context;\n if (context.width !== this.#context.width || context.separators !== this.#context.separators || context.chunk !== this.#context.chunk) {\n throw new TypeError(\"the two ropes have different width functions or options\");\n }\n return new Text(this.#context, join(this.#context, this.#root, other.#root));\n }\n\n /** This function puts `text` at the offset `at`. */\n insert(at: number, text: string): Text {\n return this.replace(at, at, text);\n }\n\n /** This function removes the text from `start` to `end`. */\n remove(start: number, end: number): Text {\n return this.replace(start, end, \"\");\n }\n\n /** This function puts `text` in place of the text from `start` to `end`. */\n replace(start: number, end: number, text: string): Text {\n this.#check(start, end);\n const [before, rest] = split(this.#context, this.#root, start);\n const [, after] = split(this.#context, rest, end - start);\n const middle = build(this.#context, text);\n return new Text(this.#context, join(this.#context, join(this.#context, before, middle), after));\n }\n\n #check(start: number, end: number): void {\n if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end < start || end > this.length) {\n throw new RangeError(`the range ${start} to ${end} is not in the text of length ${this.length}`);\n }\n }\n}\n","export { Text, type TextOptions } from \"./text/rope.ts\";\n"],"mappings":";;AA2DA,SAAS,YAAY,SAAkB,MAAuB;CAC5D,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,WAAW,QAAQ,KAAK,IAAI,QAAQ,WAAW,WAAW,CAAC,MAAM,MAAM,OAAO;CAC1G,OAAO;AACT;AAEA,SAAS,OAAO,SAAkB,MAAoB;CACpD,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAChC,IAAI,QAAQ;CACZ,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,IAAI,CAAC,YAAY,SAAS,KAAK,WAAW,CAAC,CAAC,GAAG;EAC/C,IAAI,QAAQ,GAAG,QAAQ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AO,OAAO,GAAG;EACtB,MAAM,CAAC,QAAQ,QAAQ,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK;EAC7D,MAAM,GAAG,SAAS,MAAM,KAAK,UAAU,MAAM,MAAM,KAAK;EACxD,MAAM,SAAS,MAAM,KAAK,UAAU,IAAI;EACxC,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,KAAK,UAAU,KAAK,KAAK,UAAU,QAAQ,MAAM,GAAG,KAAK,CAAC;CAChG;CAEA,OAAO,OAAe,KAAmB;EACvC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,CAAC,OAAO,UAAU,GAAG,KAAK,QAAQ,KAAK,MAAM,SAAS,MAAM,KAAK,QAC/F,MAAM,IAAI,WAAW,aAAa,MAAM,MAAM,IAAI,gCAAgC,KAAK,QAAQ;CAEnG;AACF"}
|
|
1
|
+
{"version":3,"file":"text.js","names":[],"sources":["../../src/text/rope.ts","../../src/text.ts"],"sourcesContent":["/**\n * The `Text` rope: a persistent balanced tree of strings with the width and the length of each subtree. An edit makes a\n * new rope. The new rope shares the subtrees that do not change. The tree is the `summary-tree` record of\n * `@mark1russell7/collections`, and this module gives it the summary of a text.\n *\n * A width function gives the width of a run of text. The rope uses it only for the leaves and for the windows at the\n * seams. Thus an edit uses it of the order of `log n` times. The rope keeps the widths of the short windows, so an edit\n * measures only the windows that it changes. `Text.from` clears this memory.\n *\n * The seams are exact when the width function obeys the separator law. For each text `p + s + q` with a separator `s`:\n * `width(p + s + q) = width(p + s) + width(s + q) - width(s)`. The model of `@mark1russell7/typeset/fonts` obeys it for a space and a\n * tab. It shapes each word alone, and its kerning goes only between two adjacent glyphs.\n */\nimport * as Tree from \"@mark1russell7/collections/summary-tree\";\nimport type { SummarySpec, SummaryTreeRecord } from \"@mark1russell7/collections/summary-tree\";\nimport type { WidthOf } from \"../breaking/paragraph.ts\";\n\n/** The options of a rope. */\nexport interface TextOptions {\n /**\n * The separators of the separator law: each character is one UTF-16 code unit. The default is a space and a tab. An\n * empty string makes each seam measure the full text of the two sides.\n */\n readonly separators?: string;\n /** The largest count of UTF-16 code units in a leaf. The default is 256. */\n readonly chunk?: number;\n}\n\n/** The summary of a run of text: its length, its width, and the two ends that a seam measures again. */\ninterface Summary {\n /** The count of UTF-16 code units. */\n readonly length: number;\n readonly width: number;\n /** This value is `true` when the text has a separator. */\n readonly separated: boolean;\n /** The text through the first separator, or all the text when the text has no separator. */\n readonly head: string;\n readonly headWidth: number;\n /** The text from the last separator, or all the text when the text has no separator. */\n readonly tail: string;\n readonly tailWidth: number;\n}\n\n/** The summary of the empty text. */\nconst noText: Summary = { length: 0, width: 0, separated: false, head: \"\", headWidth: 0, tail: \"\", tailWidth: 0 };\n\n/** The shared state of the ropes of one width function and one set of options. */\ninterface Context {\n readonly width: WidthOf;\n readonly separators: string;\n readonly chunk: number;\n readonly spec: SummarySpec<string, Summary>;\n /** The widths of the short windows. An edit gives the tree new paths, and most windows on these paths do not change. */\n readonly windows: Map<string, number>;\n}\n\n/** The largest count of windows in the memory of a context. */\nconst windowLimit = 16_384;\n\n/** This function gives the width of a window. A window longer than a leaf stays out of the memory. */\nfunction windowWidth(context: Context, window: string): number {\n if (window.length > context.chunk) return context.width(window);\n const known = context.windows.get(window);\n if (known !== undefined) return known;\n const width = context.width(window);\n if (context.windows.size >= windowLimit) context.windows.clear();\n context.windows.set(window, width);\n return width;\n}\n\nfunction isSeparator(separators: string, code: number): boolean {\n for (let i = 0; i < separators.length; i++) if (separators.charCodeAt(i) === code) return true;\n return false;\n}\n\nfunction summaryOfLeaf(context: Context, text: string): Summary {\n const { separators } = context;\n const whole = context.width(text);\n let first = -1;\n let last = -1;\n for (let i = 0; i < text.length; i++) {\n if (!isSeparator(separators, text.charCodeAt(i))) continue;\n if (first < 0) first = i;\n last = i;\n }\n if (first < 0) return { length: text.length, width: whole, separated: false, head: text, headWidth: whole, tail: text, tailWidth: whole };\n const head = text.slice(0, first + 1);\n const tail = text.slice(last);\n return { length: text.length, width: whole, separated: true, head, headWidth: windowWidth(context, head), tail, tailWidth: windowWidth(context, tail) };\n}\n\n/**\n * This function gives the summary of two runs in the order of the text. It measures one window: the tail of the left run and\n * the head of the right run. The separator law then gives the width of all the text from the widths of the two runs.\n */\nfunction combine(context: Context, left: Summary, right: Summary): Summary {\n if (left.length === 0) return right;\n if (right.length === 0) return left;\n const seam = left.tail + right.head;\n const seamWidth = windowWidth(context, seam);\n let width: number;\n if (!left.separated && !right.separated) width = seamWidth;\n else if (!left.separated) width = right.width - right.headWidth + seamWidth;\n else if (!right.separated) width = left.width - left.tailWidth + seamWidth;\n else width = left.width + right.width - left.tailWidth - right.headWidth + seamWidth;\n return {\n length: left.length + right.length,\n width,\n separated: left.separated || right.separated,\n head: left.separated ? left.head : seam,\n headWidth: left.separated ? left.headWidth : seamWidth,\n tail: right.separated ? right.tail : seam,\n tailWidth: right.separated ? right.tailWidth : seamWidth,\n };\n}\n\n/** The contexts of each width function. Two ropes join only when their trees have the same spec. */\nconst contexts = new WeakMap<WidthOf, Map<string, Context>>();\n\nfunction contextOf(width: WidthOf, separators: string, chunk: number): Context {\n const own = contexts.get(width) ?? new Map<string, Context>();\n contexts.set(width, own);\n const key = `${chunk}/${separators}`;\n const known = own.get(key);\n if (known !== undefined) return known;\n const spec: SummarySpec<string, Summary> = {\n monoid: { empty: noText, combine: (left, right) => combine(context, left, right) },\n measure: (leaf) => summaryOfLeaf(context, leaf),\n merge: (left, right) => (left.length + right.length <= chunk ? left + right : undefined),\n };\n const context: Context = { width, separators, chunk, spec, windows: new Map() };\n own.set(key, context);\n return context;\n}\n\n/** This function gives the end of the next leaf of `text` from `start`: after a separator when it can, and not in a surrogate pair. */\nfunction chunkEnd(context: Context, text: string, start: number): number {\n const limit = start + context.chunk;\n if (limit >= text.length) return text.length;\n for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context.separators, text.charCodeAt(i))) return i + 1;\n const code = text.charCodeAt(limit - 1);\n return code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit;\n}\n\n/** This function divides a text into leaves of at most `chunk` code units. */\nfunction chunksOf(context: Context, text: string): string[] {\n const out: string[] = [];\n for (let start = 0; start < text.length; ) {\n const end = chunkEnd(context, text, start);\n out.push(text.slice(start, end));\n start = end;\n }\n return out;\n}\n\nconst lengthOf = (summary: Summary): number => summary.length;\n\n/**\n * A text with its width: a persistent balanced rope. Each edit gives a new `Text` and does not change this one. The offsets\n * are in UTF-16 code units, as the offsets of a JavaScript string.\n */\nexport class Text {\n readonly #context: Context;\n readonly #tree: SummaryTreeRecord<string, Summary>;\n\n private constructor(context: Context, tree: SummaryTreeRecord<string, Summary>) {\n this.#context = context;\n this.#tree = tree;\n }\n\n /** This function makes the rope of `text` with the width function `width`. */\n static from(text: string, width: WidthOf, options: TextOptions = {}): Text {\n const separators = options.separators ?? \" \\t\";\n const chunk = options.chunk ?? 256;\n if (!Number.isInteger(chunk) || chunk < 2) throw new RangeError(`the chunk is ${chunk}, not an integer of 2 or more`);\n for (let i = 0; i < separators.length; i++) {\n const code = separators.charCodeAt(i);\n if (code >= 0xd800 && code <= 0xdfff) throw new RangeError(\"a separator is one UTF-16 code unit, not a half of a surrogate pair\");\n }\n const context = contextOf(width, separators, chunk);\n // A new rope measures again: the width function can change its result when a font loads\n context.windows.clear();\n return new Text(context, Tree.of(context.spec, chunksOf(context, text)));\n }\n\n /** The count of UTF-16 code units of the text. */\n get length(): number {\n return Tree.summary(this.#tree).length;\n }\n\n /** The width of the text. It is equal to the width of the flat string when the width function obeys the separator law. */\n get width(): number {\n return Tree.summary(this.#tree).width;\n }\n\n /** The height of the tree: 0 for a text of one leaf. The tests use it to examine the balance. */\n get height(): number {\n return Math.max(0, Tree.height(this.#tree) - 1);\n }\n\n /** This function gives the flat string. */\n toString(): string {\n return this.chunks().join(\"\");\n }\n\n /** This function gives the strings of the leaves in the order of the text. */\n chunks(): string[] {\n return Tree.toArray(this.#tree);\n }\n\n /** This function gives the text from `start` to `end`, as a new rope. */\n slice(start: number, end: number = this.length): Text {\n this.#check(start, end);\n if (start === end) return new Text(this.#context, Tree.slice(this.#tree, 0, 0));\n const first = Tree.locate(this.#tree, lengthOf, start)!;\n const last = Tree.locate(this.#tree, lengthOf, end - 1)!;\n const stop = first.offset + end - start;\n const middle = Tree.slice(this.#tree, first.index, last.index + 1);\n if (first.index === last.index) return new Text(this.#context, Tree.set(middle, 0, first.leaf.slice(first.offset, stop)));\n return new Text(this.#context, Tree.set(Tree.set(middle, -1, last.leaf.slice(0, last.offset + 1)), 0, first.leaf.slice(first.offset)));\n }\n\n /** This function gives the width of the text from `start` to `end`. */\n widthOf(start: number, end: number = this.length): number {\n return this.slice(start, end).width;\n }\n\n /** This function gives this text and then `other`. The two ropes must have the same width function and options. */\n concat(other: Text): Text {\n if (other.#context !== this.#context) throw new TypeError(\"the two ropes have different width functions or options\");\n return new Text(this.#context, Tree.concat(this.#tree, other.#tree));\n }\n\n /** This function puts `text` at the offset `at`. */\n insert(at: number, text: string): Text {\n return this.replace(at, at, text);\n }\n\n /** This function removes the text from `start` to `end`. */\n remove(start: number, end: number): Text {\n return this.replace(start, end, \"\");\n }\n\n /** This function puts `text` in place of the text from `start` to `end`. */\n replace(start: number, end: number, text: string): Text {\n this.#check(start, end);\n if (start === end && text.length === 0) return this;\n const size = Tree.size(this.#tree);\n if (size === 0) return Text.from(text, this.#context.width, this.#context);\n const first = Tree.locate(this.#tree, lengthOf, start) ?? this.#lastPlace();\n const last = start === end ? first : Tree.locate(this.#tree, lengthOf, end - 1)!;\n const lastEnd = start === end ? first.offset : last.offset + 1;\n const fresh = first.leaf.slice(0, first.offset) + text + last.leaf.slice(lastEnd);\n const leaves = chunksOf(this.#context, fresh);\n // One long leaf in place of one leaf changes only a path. A short leaf goes through the seams, so that it can merge\n if (first.index === last.index && leaves.length === 1 && leaves[0]!.length * 2 >= this.#context.chunk) {\n return new Text(this.#context, Tree.set(this.#tree, first.index, leaves[0]!));\n }\n return new Text(this.#context, Tree.splice(this.#tree, first.index, last.index - first.index + 1, leaves));\n }\n\n /** This function gives the place after the last code unit: the end of the last leaf. */\n #lastPlace(): { index: number; leaf: string; offset: number } {\n const leaf = Tree.at(this.#tree, -1)!;\n return { index: Tree.size(this.#tree) - 1, leaf, offset: leaf.length };\n }\n\n #check(start: number, end: number): void {\n if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end < start || end > this.length) {\n throw new RangeError(`the range ${start} to ${end} is not in the text of length ${this.length}`);\n }\n }\n}\n","export { Text, type TextOptions } from \"./text/rope.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;AA4CA,MAAM,SAAkB;CAAE,QAAQ;CAAG,OAAO;CAAG,WAAW;CAAO,MAAM;CAAI,WAAW;CAAG,MAAM;CAAI,WAAW;AAAE;;AAahH,MAAM,cAAc;;AAGpB,SAAS,YAAY,SAAkB,QAAwB;CAC7D,IAAI,OAAO,SAAS,QAAQ,OAAO,OAAO,QAAQ,MAAM,MAAM;CAC9D,MAAM,QAAQ,QAAQ,QAAQ,IAAI,MAAM;CACxC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,QAAQ,QAAQ,MAAM,MAAM;CAClC,IAAI,QAAQ,QAAQ,QAAQ,aAAa,QAAQ,QAAQ,MAAM;CAC/D,QAAQ,QAAQ,IAAI,QAAQ,KAAK;CACjC,OAAO;AACT;AAEA,SAAS,YAAY,YAAoB,MAAuB;CAC9D,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK,IAAI,WAAW,WAAW,CAAC,MAAM,MAAM,OAAO;CAC1F,OAAO;AACT;AAEA,SAAS,cAAc,SAAkB,MAAuB;CAC9D,MAAM,EAAE,eAAe;CACvB,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAChC,IAAI,QAAQ;CACZ,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,IAAI,CAAC,YAAY,YAAY,KAAK,WAAW,CAAC,CAAC,GAAG;EAClD,IAAI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K,MAAM,GAAG,MAAM,MAAM,IAAI,OAAO,KAAK,KAAK,MAAM,OAAO;EAChF,MAAM,SAAS,SAAS,KAAK,UAAU,KAAK;EAE5C,IAAI,MAAM,UAAU,KAAK,SAAS,OAAO,WAAW,KAAK,OAAO,EAAE,CAAE,SAAS,KAAK,KAAK,SAAS,OAC9F,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,IAAI,KAAK,OAAO,MAAM,OAAO,OAAO,EAAG,CAAC;EAE9E,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,OAAO,KAAK,OAAO,MAAM,OAAO,KAAK,QAAQ,MAAM,QAAQ,GAAG,MAAM,CAAC;CAC3G;;CAGA,aAA8D;EAC5D,MAAM,OAAO,KAAK,GAAG,KAAK,OAAO,EAAE;EACnC,OAAO;GAAE,OAAO,KAAK,KAAK,KAAK,KAAK,IAAI;GAAG;GAAM,QAAQ,KAAK;EAAO;CACvE;CAEA,OAAO,OAAe,KAAmB;EACvC,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,CAAC,OAAO,UAAU,GAAG,KAAK,QAAQ,KAAK,MAAM,SAAS,MAAM,KAAK,QAC/F,MAAM,IAAI,WAAW,aAAa,MAAM,MAAM,IAAI,gCAAgC,KAAK,QAAQ;CAEnG;AACF"}
|
package/build/segmentation.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ interface LineBreak {
|
|
|
8
8
|
/**
|
|
9
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
10
|
* the end of the text, and an empty text has no place.
|
|
11
|
+
*
|
|
12
|
+
* 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).
|
|
11
14
|
*/
|
|
12
15
|
export declare function lineBreaks(text: string): readonly LineBreak[];
|
|
13
16
|
export declare const unicodeVersion = "17.0.0";
|
|
@@ -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
|
|
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"}
|
package/build/segmentation.js
CHANGED
|
@@ -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";
|
|
@@ -76,7 +79,7 @@ function itemsOf(text) {
|
|
|
76
79
|
name,
|
|
77
80
|
code,
|
|
78
81
|
start: offset,
|
|
79
|
-
east: indexOfRun(east, code) % 2 === 1,
|
|
82
|
+
east: code < 128 ? asciiEast[code] : indexOfRun(east, code) % 2 === 1,
|
|
80
83
|
zwj: false
|
|
81
84
|
});
|
|
82
85
|
offset += character.length;
|
|
@@ -228,8 +231,33 @@ function ruleAt(items, i) {
|
|
|
228
231
|
/**
|
|
229
232
|
* 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
|
|
230
233
|
* the end of the text, and an empty text has no place.
|
|
234
|
+
*
|
|
235
|
+
* A text of only ASCII letters, digits and spaces takes a short path, because the rules give it a simple result. A line can
|
|
236
|
+
* end after each run of spaces (LB18), and at no other place (LB7, LB23, LB25 and LB28).
|
|
231
237
|
*/
|
|
232
238
|
function lineBreaks(text) {
|
|
239
|
+
return simple.test(text) ? simpleBreaks(text) : ruleBreaks(text);
|
|
240
|
+
}
|
|
241
|
+
/** The texts of the short path of `lineBreaks`. */
|
|
242
|
+
const simple = /^[A-Za-z0-9 ]*$/u;
|
|
243
|
+
/** This function gives the places of a text of only ASCII letters, digits and spaces: after each run of spaces, and at the end. */
|
|
244
|
+
function simpleBreaks(text) {
|
|
245
|
+
const breaks = [];
|
|
246
|
+
for (let i = 1; i < text.length; i++) if (text.charCodeAt(i - 1) === 32 && text.charCodeAt(i) !== 32) breaks.push({
|
|
247
|
+
offset: i,
|
|
248
|
+
required: false
|
|
249
|
+
});
|
|
250
|
+
if (text.length > 0) breaks.push({
|
|
251
|
+
offset: text.length,
|
|
252
|
+
required: true
|
|
253
|
+
});
|
|
254
|
+
return breaks;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* This function gives the places of a text by the rules of UAX #14, with no short path. The tests compare `lineBreaks` with
|
|
258
|
+
* it. The entry `./segmentation` does not export it.
|
|
259
|
+
*/
|
|
260
|
+
function ruleBreaks(text) {
|
|
233
261
|
const items = itemsOf(text);
|
|
234
262
|
const breaks = [];
|
|
235
263
|
for (let i = 1; i < items.length; i++) {
|
|
@@ -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 = \"9B1C1D2E1FiB1G1H1I1A1J1K1A1I1L1M1A1J1N1O1N1PaQ2N3A1HrA1L1J1MtA1L1C1R1A6B1SqB1T1L1K3J5A1I1A1C2A1K1J2A1U6A1I3A1LegA1U3A1UiA1UwA2kB7TdBeA1N78A7B73A1N1V4A1J1A19B1V1B1A2B1A2B1H1B8ArW4A4WdA6Q3A3K2N2AbB1H1B3H17AlBaQ1K2Q3A1B2rA1H1A7B1Q1A6B2A2B1A4B2AaQnA1BuArB2jAbBfAaQxA9B4A1N1H3A1B2JmA4B1A9B1A3B1A5B17A3B1gA2Q5A9B16AoB1QxB1iA3B1AiB1A7BaA2B2CaQhA3B1kA1B1A7B2A2B2A3B9A1BaA2B2AaQ2A2K5A1K1A1J2A1B2A3B1kA1B1A5B4A2B2A3B3A1BkAaQ2B3A1BbA3B1kA1B1A8B1A3B1A3BkA2B2AaQ1A1J8A6B1A3B1kA1B1A7B2A2B2A3B7A3BaA2B2AaQiA1B1nA5B3A3B1A4B9A1BeAaQ9A1J6A5B1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ7A1U9A3B1U1jA1B1A7B1A3B1A4B7A2BbA2B2AaQ3A1BcA4B1jA2B1A7B1A3B1A4B9A1BaA2B2A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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,CAAC;CACpF,MAAM,OAAO,IAAI,YAAY,QAAQ,SAAS,CAAC;CAC/C,QAAQ,SAAS,QAAQ,UAAU;EACjC,KAAK,QAAQ,KAAK,KAAK,SAAU;CACnC,CAAC;CACD,QAAQ;EAAE;EAAQ;EAAS;CAAK;CAChC,OAAO;AACT;;AAGA,SAAS,WAAW,QAAqB,MAAsB;CAC7D,IAAI,MAAM;CACV,IAAI,OAAO,OAAO,SAAS;CAC3B,OAAO,OAAO,MAAM,GAAG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GAAG,CAAC,CAAC,IAAK,OAAO;CAC/F,OAAO;AACT;;;;;AAMA,SAAgB,WAAW,MAAoC;CAC7D,MAAM,QAAQ,QAAQ,IAAI;CAC1B,MAAM,SAAsB,CAAC;CAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,OAAO,OAAO,CAAC;EAC5B,IAAI,SAAS,GAAG,OAAO,KAAK;GAAE,QAAQ,MAAM,EAAE,CAAE;GAAO,UAAU,SAAS;EAAE,CAAC;CAC/E;CACA,IAAI,KAAK,SAAS,GAAG,OAAO,KAAK;EAAE,QAAQ,KAAK;EAAQ,UAAU;CAAK,CAAC;CACxE,OAAO;AACT;;;;;;ACtMA,MAAM,oBAAoB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,WAAW,CAAC;AAC/E,MAAM,gBAAgB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,OAAO,CAAC;;AAGvE,SAAgB,UAAU,MAAiC;CACzD,OAAO,MAAM,KAAK,kBAAkB,QAAQ,IAAI,IAAI,SAAS,KAAK,OAAO;AAC3E;;AAGA,SAAgB,WAAW,MAAiC;CAC1D,MAAM,UAAU,MAAM,KAAK,cAAc,QAAQ,IAAI,IAAI,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,CAAC;CACrF,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,KAAK,MAAM;CAC7C,OAAO;AACT"}
|
|
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 classR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4BaQ5A1JdoA4BaQ6sA2B1AaQ6gA1B2A1B7A2B5A1Bd6A7B31A7B5AaQ4A2LngA1K3A1KnjA74&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\";\nexport 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\";\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}\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\" });\n else items.push({ name, code, start: offset, east: code < 128 ? asciiEast[code]! : 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 *\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).\n */\nexport function lineBreaks(text: string): readonly LineBreak[] {\n return simple.test(text) ? simpleBreaks(text) : ruleBreaks(text);\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): 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;;;;;;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,O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,QAAQ,QAAQ,IAAI;CAC1B,MAAM,SAAsB,CAAC;CAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,OAAO,OAAO,CAAC;EAC5B,IAAI,SAAS,GAAG,OAAO,KAAK;GAAE,QAAQ,MAAM,EAAE,CAAE;GAAO,UAAU,SAAS;EAAE,CAAC;CAC/E;CACA,IAAI,KAAK,SAAS,GAAG,OAAO,KAAK;EAAE,QAAQ,KAAK;EAAQ,UAAU;CAAK,CAAC;CACxE,OAAO;AACT;;;;;;ACnOA,MAAM,oBAAoB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,WAAW,CAAC;AAC/E,MAAM,gBAAgB,IAAI,KAAK,UAAU,OAAO,EAAE,aAAa,OAAO,CAAC;;AAGvE,SAAgB,UAAU,MAAiC;CACzD,OAAO,MAAM,KAAK,kBAAkB,QAAQ,IAAI,IAAI,SAAS,KAAK,OAAO;AAC3E;;AAGA,SAAgB,WAAW,MAAiC;CAC1D,MAAM,UAAU,MAAM,KAAK,cAAc,QAAQ,IAAI,IAAI,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,CAAC;CACrF,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,KAAK,MAAM;CAC7C,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/typeset",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.8",
|
|
5
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.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"typeset",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
+
"@mark1russell7/collections": "^0.9.3",
|
|
72
73
|
"@mark1russell7/rigor-generators": "^0.1.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
package/src/segmentation/line.ts
CHANGED
|
@@ -16,6 +16,10 @@ interface Table {
|
|
|
16
16
|
readonly starts: Uint32Array;
|
|
17
17
|
readonly classes: Uint8Array;
|
|
18
18
|
readonly east: Uint32Array;
|
|
19
|
+
/** The class name of each ASCII code point, from `starts` and `classes`. */
|
|
20
|
+
readonly asciiNames: readonly string[];
|
|
21
|
+
/** This value is `true` for an ASCII code point that is wide in East Asian text, from `east`. */
|
|
22
|
+
readonly asciiEast: readonly boolean[];
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-./:;<=>?@[]^_{|}~";
|
|
@@ -39,7 +43,10 @@ function tableOf(): Table {
|
|
|
39
43
|
lengths.forEach((length, index) => {
|
|
40
44
|
east[index + 1] = east[index]! + length;
|
|
41
45
|
});
|
|
42
|
-
|
|
46
|
+
const codes = Array.from({ length: 128 }, (_, code) => code);
|
|
47
|
+
const asciiNames = codes.map((code) => classNames[classes[indexOfRun(starts, code)]!]!);
|
|
48
|
+
const asciiEast = codes.map((code) => indexOfRun(east, code) % 2 === 1);
|
|
49
|
+
table = { starts, classes, east, asciiNames, asciiEast };
|
|
43
50
|
return table;
|
|
44
51
|
}
|
|
45
52
|
|
|
@@ -69,17 +76,17 @@ const breakClasses = new Set(["BK", "CR", "LF", "NL", "SP", "ZW"]);
|
|
|
69
76
|
|
|
70
77
|
/** This function makes the items of a text. It applies the rules LB9 and LB10. */
|
|
71
78
|
function itemsOf(text: string): Item[] {
|
|
72
|
-
const { starts, classes, east } = tableOf();
|
|
79
|
+
const { starts, classes, east, asciiNames, asciiEast } = tableOf();
|
|
73
80
|
const items: Item[] = [];
|
|
74
81
|
let offset = 0;
|
|
75
82
|
for (const character of text) {
|
|
76
83
|
const code = character.codePointAt(0)!;
|
|
77
|
-
const name = classNames[classes[indexOfRun(starts, code)]!]!;
|
|
84
|
+
const name = code < 128 ? asciiNames[code]! : classNames[classes[indexOfRun(starts, code)]!]!;
|
|
78
85
|
const combining = name === "CM" || name === "ZWJ";
|
|
79
86
|
const last = items.at(-1);
|
|
80
87
|
if (combining && last !== undefined && !breakClasses.has(last.name)) last.zwj = name === "ZWJ";
|
|
81
88
|
else if (combining) items.push({ name: "AL", code: 0x41, start: offset, east: false, zwj: name === "ZWJ" });
|
|
82
|
-
else items.push({ name, code, start: offset, east: indexOfRun(east, code) % 2 === 1, zwj: false });
|
|
89
|
+
else items.push({ name, code, start: offset, east: code < 128 ? asciiEast[code]! : indexOfRun(east, code) % 2 === 1, zwj: false });
|
|
83
90
|
offset += character.length;
|
|
84
91
|
}
|
|
85
92
|
return items;
|
|
@@ -190,8 +197,30 @@ function ruleAt(items: readonly Item[], i: number): 0 | 1 | 2 {
|
|
|
190
197
|
/**
|
|
191
198
|
* 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
|
|
192
199
|
* the end of the text, and an empty text has no place.
|
|
200
|
+
*
|
|
201
|
+
* A text of only ASCII letters, digits and spaces takes a short path, because the rules give it a simple result. A line can
|
|
202
|
+
* end after each run of spaces (LB18), and at no other place (LB7, LB23, LB25 and LB28).
|
|
193
203
|
*/
|
|
194
204
|
export function lineBreaks(text: string): readonly LineBreak[] {
|
|
205
|
+
return simple.test(text) ? simpleBreaks(text) : ruleBreaks(text);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The texts of the short path of `lineBreaks`. */
|
|
209
|
+
const simple = /^[A-Za-z0-9 ]*$/u;
|
|
210
|
+
|
|
211
|
+
/** This function gives the places of a text of only ASCII letters, digits and spaces: after each run of spaces, and at the end. */
|
|
212
|
+
function simpleBreaks(text: string): LineBreak[] {
|
|
213
|
+
const breaks: LineBreak[] = [];
|
|
214
|
+
for (let i = 1; i < text.length; i++) if (text.charCodeAt(i - 1) === 32 && text.charCodeAt(i) !== 32) breaks.push({ offset: i, required: false });
|
|
215
|
+
if (text.length > 0) breaks.push({ offset: text.length, required: true });
|
|
216
|
+
return breaks;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* This function gives the places of a text by the rules of UAX #14, with no short path. The tests compare `lineBreaks` with
|
|
221
|
+
* it. The entry `./segmentation` does not export it.
|
|
222
|
+
*/
|
|
223
|
+
export function ruleBreaks(text: string): readonly LineBreak[] {
|
|
195
224
|
const items = itemsOf(text);
|
|
196
225
|
const breaks: LineBreak[] = [];
|
|
197
226
|
for (let i = 1; i < items.length; i++) {
|
package/src/text/rope.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `Text` rope: a persistent balanced tree of strings with the width and the length of each subtree. An edit makes a
|
|
3
|
-
* new rope. The new rope shares the subtrees that do not change.
|
|
4
|
-
*
|
|
3
|
+
* new rope. The new rope shares the subtrees that do not change. The tree is the `summary-tree` record of
|
|
4
|
+
* `@mark1russell7/collections`, and this module gives it the summary of a text.
|
|
5
|
+
*
|
|
6
|
+
* A width function gives the width of a run of text. The rope uses it only for the leaves and for the windows at the
|
|
7
|
+
* seams. Thus an edit uses it of the order of `log n` times. The rope keeps the widths of the short windows, so an edit
|
|
8
|
+
* measures only the windows that it changes. `Text.from` clears this memory.
|
|
5
9
|
*
|
|
6
10
|
* The seams are exact when the width function obeys the separator law. For each text `p + s + q` with a separator `s`:
|
|
7
11
|
* `width(p + s + q) = width(p + s) + width(s + q) - width(s)`. The model of `@mark1russell7/typeset/fonts` obeys it for a space and a
|
|
8
12
|
* tab. It shapes each word alone, and its kerning goes only between two adjacent glyphs.
|
|
9
13
|
*/
|
|
14
|
+
import * as Tree from "@mark1russell7/collections/summary-tree";
|
|
15
|
+
import type { SummarySpec, SummaryTreeRecord } from "@mark1russell7/collections/summary-tree";
|
|
10
16
|
import type { WidthOf } from "../breaking/paragraph.ts";
|
|
11
17
|
|
|
12
18
|
/** The options of a rope. */
|
|
@@ -20,7 +26,7 @@ export interface TextOptions {
|
|
|
20
26
|
readonly chunk?: number;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
/** The summary of a
|
|
29
|
+
/** The summary of a run of text: its length, its width, and the two ends that a seam measures again. */
|
|
24
30
|
interface Summary {
|
|
25
31
|
/** The count of UTF-16 code units. */
|
|
26
32
|
readonly length: number;
|
|
@@ -35,65 +41,69 @@ interface Summary {
|
|
|
35
41
|
readonly tailWidth: number;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readonly text: string;
|
|
41
|
-
readonly height: 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface Branch extends Summary {
|
|
45
|
-
readonly kind: "branch";
|
|
46
|
-
readonly left: Node;
|
|
47
|
-
readonly right: Node;
|
|
48
|
-
readonly height: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type Node = Leaf | Branch;
|
|
44
|
+
/** The summary of the empty text. */
|
|
45
|
+
const noText: Summary = { length: 0, width: 0, separated: false, head: "", headWidth: 0, tail: "", tailWidth: 0 };
|
|
52
46
|
|
|
53
47
|
/** The shared state of the ropes of one width function and one set of options. */
|
|
54
48
|
interface Context {
|
|
55
49
|
readonly width: WidthOf;
|
|
56
50
|
readonly separators: string;
|
|
57
51
|
readonly chunk: number;
|
|
52
|
+
readonly spec: SummarySpec<string, Summary>;
|
|
53
|
+
/** The widths of the short windows. An edit gives the tree new paths, and most windows on these paths do not change. */
|
|
54
|
+
readonly windows: Map<string, number>;
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
/** The largest count of windows in the memory of a context. */
|
|
58
|
+
const windowLimit = 16_384;
|
|
59
|
+
|
|
60
|
+
/** This function gives the width of a window. A window longer than a leaf stays out of the memory. */
|
|
61
|
+
function windowWidth(context: Context, window: string): number {
|
|
62
|
+
if (window.length > context.chunk) return context.width(window);
|
|
63
|
+
const known = context.windows.get(window);
|
|
64
|
+
if (known !== undefined) return known;
|
|
65
|
+
const width = context.width(window);
|
|
66
|
+
if (context.windows.size >= windowLimit) context.windows.clear();
|
|
67
|
+
context.windows.set(window, width);
|
|
68
|
+
return width;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isSeparator(separators: string, code: number): boolean {
|
|
72
|
+
for (let i = 0; i < separators.length; i++) if (separators.charCodeAt(i) === code) return true;
|
|
62
73
|
return false;
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
function
|
|
66
|
-
const
|
|
76
|
+
function summaryOfLeaf(context: Context, text: string): Summary {
|
|
77
|
+
const { separators } = context;
|
|
78
|
+
const whole = context.width(text);
|
|
67
79
|
let first = -1;
|
|
68
80
|
let last = -1;
|
|
69
81
|
for (let i = 0; i < text.length; i++) {
|
|
70
|
-
if (!isSeparator(
|
|
82
|
+
if (!isSeparator(separators, text.charCodeAt(i))) continue;
|
|
71
83
|
if (first < 0) first = i;
|
|
72
84
|
last = i;
|
|
73
85
|
}
|
|
74
|
-
if (first < 0) return {
|
|
86
|
+
if (first < 0) return { length: text.length, width: whole, separated: false, head: text, headWidth: whole, tail: text, tailWidth: whole };
|
|
75
87
|
const head = text.slice(0, first + 1);
|
|
76
88
|
const tail = text.slice(last);
|
|
77
|
-
return {
|
|
89
|
+
return { length: text.length, width: whole, separated: true, head, headWidth: windowWidth(context, head), tail, tailWidth: windowWidth(context, tail) };
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
/**
|
|
81
|
-
* This function
|
|
82
|
-
*
|
|
93
|
+
* This function gives the summary of two runs in the order of the text. It measures one window: the tail of the left run and
|
|
94
|
+
* the head of the right run. The separator law then gives the width of all the text from the widths of the two runs.
|
|
83
95
|
*/
|
|
84
|
-
function
|
|
96
|
+
function combine(context: Context, left: Summary, right: Summary): Summary {
|
|
97
|
+
if (left.length === 0) return right;
|
|
98
|
+
if (right.length === 0) return left;
|
|
85
99
|
const seam = left.tail + right.head;
|
|
86
|
-
const seamWidth = context
|
|
100
|
+
const seamWidth = windowWidth(context, seam);
|
|
87
101
|
let width: number;
|
|
88
102
|
if (!left.separated && !right.separated) width = seamWidth;
|
|
89
103
|
else if (!left.separated) width = right.width - right.headWidth + seamWidth;
|
|
90
104
|
else if (!right.separated) width = left.width - left.tailWidth + seamWidth;
|
|
91
105
|
else width = left.width + right.width - left.tailWidth - right.headWidth + seamWidth;
|
|
92
106
|
return {
|
|
93
|
-
kind: "branch",
|
|
94
|
-
left,
|
|
95
|
-
right,
|
|
96
|
-
height: Math.max(left.height, right.height) + 1,
|
|
97
107
|
length: left.length + right.length,
|
|
98
108
|
width,
|
|
99
109
|
separated: left.separated || right.separated,
|
|
@@ -104,104 +114,58 @@ function branchOf(context: Context, left: Node, right: Node): Branch {
|
|
|
104
114
|
};
|
|
105
115
|
}
|
|
106
116
|
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
if (left === undefined) return right;
|
|
110
|
-
if (right === undefined) return left;
|
|
111
|
-
if (left.kind === "leaf" && right.kind === "leaf" && left.length + right.length <= context.chunk) return leafOf(context, left.text + right.text);
|
|
112
|
-
if (left.height > right.height + 1) {
|
|
113
|
-
const branch = left as Branch;
|
|
114
|
-
const joined = join(context, branch.right, right)!;
|
|
115
|
-
if (joined.height <= branch.left.height + 1) return branchOf(context, branch.left, joined);
|
|
116
|
-
return rotateLeft(context, branch.left, joined as Branch);
|
|
117
|
-
}
|
|
118
|
-
if (right.height > left.height + 1) {
|
|
119
|
-
const branch = right as Branch;
|
|
120
|
-
const joined = join(context, left, branch.left)!;
|
|
121
|
-
if (joined.height <= branch.right.height + 1) return branchOf(context, joined, branch.right);
|
|
122
|
-
return rotateRight(context, joined as Branch, branch.right);
|
|
123
|
-
}
|
|
124
|
-
return branchOf(context, left, right);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** This function balances the branch of `left` and `heavy`, when `heavy` is 2 levels higher than `left`. */
|
|
128
|
-
function rotateLeft(context: Context, left: Node, heavy: Branch): Branch {
|
|
129
|
-
if (heavy.left.height <= heavy.right.height) return branchOf(context, branchOf(context, left, heavy.left), heavy.right);
|
|
130
|
-
const middle = heavy.left as Branch;
|
|
131
|
-
return branchOf(context, branchOf(context, left, middle.left), branchOf(context, middle.right, heavy.right));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** This function balances the branch of `heavy` and `right`, when `heavy` is 2 levels higher than `right`. */
|
|
135
|
-
function rotateRight(context: Context, heavy: Branch, right: Node): Branch {
|
|
136
|
-
if (heavy.right.height <= heavy.left.height) return branchOf(context, heavy.left, branchOf(context, heavy.right, right));
|
|
137
|
-
const middle = heavy.right as Branch;
|
|
138
|
-
return branchOf(context, branchOf(context, heavy.left, middle.left), branchOf(context, middle.right, right));
|
|
139
|
-
}
|
|
117
|
+
/** The contexts of each width function. Two ropes join only when their trees have the same spec. */
|
|
118
|
+
const contexts = new WeakMap<WidthOf, Map<string, Context>>();
|
|
140
119
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
const
|
|
153
|
-
|
|
120
|
+
function contextOf(width: WidthOf, separators: string, chunk: number): Context {
|
|
121
|
+
const own = contexts.get(width) ?? new Map<string, Context>();
|
|
122
|
+
contexts.set(width, own);
|
|
123
|
+
const key = `${chunk}/${separators}`;
|
|
124
|
+
const known = own.get(key);
|
|
125
|
+
if (known !== undefined) return known;
|
|
126
|
+
const spec: SummarySpec<string, Summary> = {
|
|
127
|
+
monoid: { empty: noText, combine: (left, right) => combine(context, left, right) },
|
|
128
|
+
measure: (leaf) => summaryOfLeaf(context, leaf),
|
|
129
|
+
merge: (left, right) => (left.length + right.length <= chunk ? left + right : undefined),
|
|
130
|
+
};
|
|
131
|
+
const context: Context = { width, separators, chunk, spec, windows: new Map() };
|
|
132
|
+
own.set(key, context);
|
|
133
|
+
return context;
|
|
154
134
|
}
|
|
155
135
|
|
|
156
136
|
/** This function gives the end of the next leaf of `text` from `start`: after a separator when it can, and not in a surrogate pair. */
|
|
157
137
|
function chunkEnd(context: Context, text: string, start: number): number {
|
|
158
138
|
const limit = start + context.chunk;
|
|
159
139
|
if (limit >= text.length) return text.length;
|
|
160
|
-
for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context, text.charCodeAt(i))) return i + 1;
|
|
140
|
+
for (let i = limit - 1; i >= start + context.chunk / 2; i--) if (isSeparator(context.separators, text.charCodeAt(i))) return i + 1;
|
|
161
141
|
const code = text.charCodeAt(limit - 1);
|
|
162
142
|
return code >= 0xd800 && code <= 0xdbff ? limit - 1 : limit;
|
|
163
143
|
}
|
|
164
144
|
|
|
165
|
-
/** This function
|
|
166
|
-
function
|
|
167
|
-
|
|
145
|
+
/** This function divides a text into leaves of at most `chunk` code units. */
|
|
146
|
+
function chunksOf(context: Context, text: string): string[] {
|
|
147
|
+
const out: string[] = [];
|
|
168
148
|
for (let start = 0; start < text.length; ) {
|
|
169
149
|
const end = chunkEnd(context, text, start);
|
|
170
|
-
|
|
150
|
+
out.push(text.slice(start, end));
|
|
171
151
|
start = end;
|
|
172
152
|
}
|
|
173
|
-
if (level.length === 0) return undefined;
|
|
174
|
-
while (level.length > 1) {
|
|
175
|
-
const next: Node[] = [];
|
|
176
|
-
for (let i = 0; i + 1 < level.length; i += 2) next.push(branchOf(context, level[i]!, level[i + 1]!));
|
|
177
|
-
if (level.length % 2 === 1) next.push(level[level.length - 1]!);
|
|
178
|
-
level = next;
|
|
179
|
-
}
|
|
180
|
-
return level[0];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function leaves(node: Node | undefined, out: string[]): string[] {
|
|
184
|
-
if (node === undefined) return out;
|
|
185
|
-
const stack: Node[] = [node];
|
|
186
|
-
while (stack.length > 0) {
|
|
187
|
-
const top = stack.pop()!;
|
|
188
|
-
if (top.kind === "leaf") out.push(top.text);
|
|
189
|
-
else stack.push(top.right, top.left);
|
|
190
|
-
}
|
|
191
153
|
return out;
|
|
192
154
|
}
|
|
193
155
|
|
|
156
|
+
const lengthOf = (summary: Summary): number => summary.length;
|
|
157
|
+
|
|
194
158
|
/**
|
|
195
159
|
* A text with its width: a persistent balanced rope. Each edit gives a new `Text` and does not change this one. The offsets
|
|
196
160
|
* are in UTF-16 code units, as the offsets of a JavaScript string.
|
|
197
161
|
*/
|
|
198
162
|
export class Text {
|
|
199
163
|
readonly #context: Context;
|
|
200
|
-
readonly #
|
|
164
|
+
readonly #tree: SummaryTreeRecord<string, Summary>;
|
|
201
165
|
|
|
202
|
-
private constructor(context: Context,
|
|
166
|
+
private constructor(context: Context, tree: SummaryTreeRecord<string, Summary>) {
|
|
203
167
|
this.#context = context;
|
|
204
|
-
this.#
|
|
168
|
+
this.#tree = tree;
|
|
205
169
|
}
|
|
206
170
|
|
|
207
171
|
/** This function makes the rope of `text` with the width function `width`. */
|
|
@@ -213,41 +177,47 @@ export class Text {
|
|
|
213
177
|
const code = separators.charCodeAt(i);
|
|
214
178
|
if (code >= 0xd800 && code <= 0xdfff) throw new RangeError("a separator is one UTF-16 code unit, not a half of a surrogate pair");
|
|
215
179
|
}
|
|
216
|
-
const context
|
|
217
|
-
|
|
180
|
+
const context = contextOf(width, separators, chunk);
|
|
181
|
+
// A new rope measures again: the width function can change its result when a font loads
|
|
182
|
+
context.windows.clear();
|
|
183
|
+
return new Text(context, Tree.of(context.spec, chunksOf(context, text)));
|
|
218
184
|
}
|
|
219
185
|
|
|
220
186
|
/** The count of UTF-16 code units of the text. */
|
|
221
187
|
get length(): number {
|
|
222
|
-
return this.#
|
|
188
|
+
return Tree.summary(this.#tree).length;
|
|
223
189
|
}
|
|
224
190
|
|
|
225
191
|
/** The width of the text. It is equal to the width of the flat string when the width function obeys the separator law. */
|
|
226
192
|
get width(): number {
|
|
227
|
-
return this.#
|
|
193
|
+
return Tree.summary(this.#tree).width;
|
|
228
194
|
}
|
|
229
195
|
|
|
230
196
|
/** The height of the tree: 0 for a text of one leaf. The tests use it to examine the balance. */
|
|
231
197
|
get height(): number {
|
|
232
|
-
return this.#
|
|
198
|
+
return Math.max(0, Tree.height(this.#tree) - 1);
|
|
233
199
|
}
|
|
234
200
|
|
|
235
201
|
/** This function gives the flat string. */
|
|
236
202
|
toString(): string {
|
|
237
|
-
return
|
|
203
|
+
return this.chunks().join("");
|
|
238
204
|
}
|
|
239
205
|
|
|
240
206
|
/** This function gives the strings of the leaves in the order of the text. */
|
|
241
207
|
chunks(): string[] {
|
|
242
|
-
return
|
|
208
|
+
return Tree.toArray(this.#tree);
|
|
243
209
|
}
|
|
244
210
|
|
|
245
211
|
/** This function gives the text from `start` to `end`, as a new rope. */
|
|
246
212
|
slice(start: number, end: number = this.length): Text {
|
|
247
213
|
this.#check(start, end);
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
214
|
+
if (start === end) return new Text(this.#context, Tree.slice(this.#tree, 0, 0));
|
|
215
|
+
const first = Tree.locate(this.#tree, lengthOf, start)!;
|
|
216
|
+
const last = Tree.locate(this.#tree, lengthOf, end - 1)!;
|
|
217
|
+
const stop = first.offset + end - start;
|
|
218
|
+
const middle = Tree.slice(this.#tree, first.index, last.index + 1);
|
|
219
|
+
if (first.index === last.index) return new Text(this.#context, Tree.set(middle, 0, first.leaf.slice(first.offset, stop)));
|
|
220
|
+
return new Text(this.#context, Tree.set(Tree.set(middle, -1, last.leaf.slice(0, last.offset + 1)), 0, first.leaf.slice(first.offset)));
|
|
251
221
|
}
|
|
252
222
|
|
|
253
223
|
/** This function gives the width of the text from `start` to `end`. */
|
|
@@ -257,11 +227,8 @@ export class Text {
|
|
|
257
227
|
|
|
258
228
|
/** This function gives this text and then `other`. The two ropes must have the same width function and options. */
|
|
259
229
|
concat(other: Text): Text {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
throw new TypeError("the two ropes have different width functions or options");
|
|
263
|
-
}
|
|
264
|
-
return new Text(this.#context, join(this.#context, this.#root, other.#root));
|
|
230
|
+
if (other.#context !== this.#context) throw new TypeError("the two ropes have different width functions or options");
|
|
231
|
+
return new Text(this.#context, Tree.concat(this.#tree, other.#tree));
|
|
265
232
|
}
|
|
266
233
|
|
|
267
234
|
/** This function puts `text` at the offset `at`. */
|
|
@@ -277,10 +244,25 @@ export class Text {
|
|
|
277
244
|
/** This function puts `text` in place of the text from `start` to `end`. */
|
|
278
245
|
replace(start: number, end: number, text: string): Text {
|
|
279
246
|
this.#check(start, end);
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
247
|
+
if (start === end && text.length === 0) return this;
|
|
248
|
+
const size = Tree.size(this.#tree);
|
|
249
|
+
if (size === 0) return Text.from(text, this.#context.width, this.#context);
|
|
250
|
+
const first = Tree.locate(this.#tree, lengthOf, start) ?? this.#lastPlace();
|
|
251
|
+
const last = start === end ? first : Tree.locate(this.#tree, lengthOf, end - 1)!;
|
|
252
|
+
const lastEnd = start === end ? first.offset : last.offset + 1;
|
|
253
|
+
const fresh = first.leaf.slice(0, first.offset) + text + last.leaf.slice(lastEnd);
|
|
254
|
+
const leaves = chunksOf(this.#context, fresh);
|
|
255
|
+
// One long leaf in place of one leaf changes only a path. A short leaf goes through the seams, so that it can merge
|
|
256
|
+
if (first.index === last.index && leaves.length === 1 && leaves[0]!.length * 2 >= this.#context.chunk) {
|
|
257
|
+
return new Text(this.#context, Tree.set(this.#tree, first.index, leaves[0]!));
|
|
258
|
+
}
|
|
259
|
+
return new Text(this.#context, Tree.splice(this.#tree, first.index, last.index - first.index + 1, leaves));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** This function gives the place after the last code unit: the end of the last leaf. */
|
|
263
|
+
#lastPlace(): { index: number; leaf: string; offset: number } {
|
|
264
|
+
const leaf = Tree.at(this.#tree, -1)!;
|
|
265
|
+
return { index: Tree.size(this.#tree) - 1, leaf, offset: leaf.length };
|
|
284
266
|
}
|
|
285
267
|
|
|
286
268
|
#check(start: number, end: number): void {
|