@mark1russell7/typeset 0.1.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/build/bidi.d.ts.map +1 -1
- package/build/bidi.js +1 -1
- package/build/breaking.d.ts +3 -3
- package/build/breaking.js +1 -1
- package/build/chunks/breaking.d.ts +22 -6
- package/build/chunks/breaking.d.ts.map +1 -1
- package/build/chunks/breaking.js +70 -13
- package/build/chunks/breaking.js.map +1 -1
- package/build/chunks/font.d.ts +4 -3
- package/build/chunks/font.d.ts.map +1 -1
- package/build/chunks/font.js +62 -15
- package/build/chunks/font.js.map +1 -1
- package/build/chunks/hyphen.d.ts +46 -0
- package/build/chunks/hyphen.d.ts.map +1 -0
- package/build/chunks/hyphen.js +55 -0
- package/build/chunks/hyphen.js.map +1 -0
- package/build/chunks/paragraph.d.ts +19 -2
- package/build/chunks/paragraph.d.ts.map +1 -1
- package/build/chunks/resolve.js +68 -7
- package/build/chunks/resolve.js.map +1 -1
- package/build/fonts-inspect.d.ts +4 -4
- package/build/fonts-inspect.d.ts.map +1 -1
- package/build/hyphen/de.d.ts +6 -0
- package/build/hyphen/de.d.ts.map +1 -0
- package/build/hyphen/de.js +76 -0
- package/build/hyphen/de.js.map +1 -0
- package/build/hyphen/en-us.d.ts +6 -0
- package/build/hyphen/en-us.d.ts.map +1 -0
- package/build/hyphen/en-us.js +45 -0
- package/build/hyphen/en-us.js.map +1 -0
- package/build/hyphen/fr.d.ts +6 -0
- package/build/hyphen/fr.d.ts.map +1 -0
- package/build/hyphen/fr.js +71 -0
- package/build/hyphen/fr.js.map +1 -0
- package/build/hyphen.d.ts +2 -0
- package/build/hyphen.js +1 -0
- package/package.json +18 -2
- package/src/bidi/resolve.ts +72 -3
- package/src/breaking/breakers.ts +23 -7
- package/src/breaking/measures.ts +21 -1
- package/src/breaking/paragraph.ts +31 -2
- package/src/breaking.ts +2 -2
- package/src/fonts/bidi.ts +9 -1
- package/src/fonts/font.ts +8 -7
- package/src/fonts/words.ts +47 -10
- package/src/hyphen/de.ts +57 -0
- package/src/hyphen/en-us.ts +26 -0
- package/src/hyphen/fr.ts +52 -0
- package/src/hyphen/liang.ts +98 -0
- package/src/hyphen.ts +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The matcher of Liang: a word takes the digits of each pattern that it holds, and an odd digit marks a hyphen place. Each
|
|
3
|
+
* language subpath gives its own data to this module, so the data of a language stays out of each other entry.
|
|
4
|
+
*/
|
|
5
|
+
/** The data of a language. */
|
|
6
|
+
interface PatternSet {
|
|
7
|
+
/** The patterns of Liang, with a space between them. A dot marks the start or the end of a word. */
|
|
8
|
+
readonly patterns: string;
|
|
9
|
+
/** The words with known hyphen places, with a hyphen at each place and a space between the words. */
|
|
10
|
+
readonly exceptions: string;
|
|
11
|
+
/** The least count of characters before a hyphen. */
|
|
12
|
+
readonly left: number;
|
|
13
|
+
/** The least count of characters after a hyphen. */
|
|
14
|
+
readonly right: number;
|
|
15
|
+
}
|
|
16
|
+
/** The origin of a language set, and the result of the set on its word list. */
|
|
17
|
+
interface HyphenSource {
|
|
18
|
+
/** The language tag of the set. */
|
|
19
|
+
readonly language: string;
|
|
20
|
+
/** The file of the patterns, with the commit of its repository and its SHA-256. */
|
|
21
|
+
readonly file: string;
|
|
22
|
+
readonly commit: string;
|
|
23
|
+
readonly sha256: string;
|
|
24
|
+
/** The name of the license of the patterns. */
|
|
25
|
+
readonly license: string;
|
|
26
|
+
/** The result of the set on its word list. `docs/HYPHENATION.md` tells each field. */
|
|
27
|
+
readonly words: {
|
|
28
|
+
/** The name of the word list. */
|
|
29
|
+
readonly list: string;
|
|
30
|
+
/** This value is `true` when the word list does not come from the project of the patterns. */
|
|
31
|
+
readonly independent: boolean;
|
|
32
|
+
/** The count of words of the test. */
|
|
33
|
+
readonly count: number;
|
|
34
|
+
/** The hyphen places of the list that the set finds, from 0 to 1. */
|
|
35
|
+
readonly found: number;
|
|
36
|
+
/** The hyphen places of the set that the list holds, from 0 to 1. */
|
|
37
|
+
readonly confirmed: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This function gives the function for the `hyphenate` hook of `paragraphOf`. The function finds each run of letters of a word,
|
|
42
|
+
* and it gives the hyphen places of each run. The table of the patterns comes at the first use, so an import costs no time.
|
|
43
|
+
*/
|
|
44
|
+
declare function hyphenator(set: PatternSet): (word: string) => readonly number[];
|
|
45
|
+
export { PatternSet as n, hyphenator as r, HyphenSource as t };
|
|
46
|
+
//# sourceMappingURL=hyphen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyphen.d.ts","names":[],"sources":["../../src/hyphen/liang.ts"],"mappings":";;;;;UAMiB;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;WACA;WACA;;WAEA;;WAEA;;aAEE;;aAEA;;aAEA;;aAEA;;aAEA;;;;;;;iBAgCG,WAAW,KAAK,cAAc"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/hyphen/liang.ts
|
|
2
|
+
/** The letters of a word for the patterns. An apostrophe is a letter, because the patterns of French use it. */
|
|
3
|
+
const letters = /[\p{L}\p{M}'’]+/gu;
|
|
4
|
+
/** This function gives the offsets of the hyphen places of a lowercase word, from the patterns. */
|
|
5
|
+
function placesOf(word, table, longest, set) {
|
|
6
|
+
const dotted = `.${word}.`;
|
|
7
|
+
const digits = new Uint8Array(dotted.length + 1);
|
|
8
|
+
for (let start = 0; start < dotted.length; start++) {
|
|
9
|
+
const stop = Math.min(start + longest, dotted.length);
|
|
10
|
+
for (let end = start + 1; end <= stop; end++) {
|
|
11
|
+
const pattern = table.get(dotted.slice(start, end));
|
|
12
|
+
if (pattern === void 0) continue;
|
|
13
|
+
let place = start;
|
|
14
|
+
for (const character of pattern) if (character >= "0" && character <= "9") digits[place] = Math.max(digits[place], Number(character));
|
|
15
|
+
else place++;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const places = [];
|
|
19
|
+
for (let offset = set.left; offset <= word.length - set.right; offset++) if (digits[offset + 1] % 2 === 1) places.push(offset);
|
|
20
|
+
return places;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This function gives the function for the `hyphenate` hook of `paragraphOf`. The function finds each run of letters of a word,
|
|
24
|
+
* and it gives the hyphen places of each run. The table of the patterns comes at the first use, so an import costs no time.
|
|
25
|
+
*/
|
|
26
|
+
function hyphenator(set) {
|
|
27
|
+
const table = /* @__PURE__ */ new Map();
|
|
28
|
+
const exceptions = /* @__PURE__ */ new Map();
|
|
29
|
+
let longest = 0;
|
|
30
|
+
const load = () => {
|
|
31
|
+
for (const pattern of set.patterns.split(" ")) {
|
|
32
|
+
const key = pattern.replace(/\d/gu, "");
|
|
33
|
+
table.set(key, pattern);
|
|
34
|
+
longest = Math.max(longest, key.length);
|
|
35
|
+
}
|
|
36
|
+
for (const entry of set.exceptions.split(" ").filter((text) => text !== "")) {
|
|
37
|
+
const parts = entry.split("-");
|
|
38
|
+
let offset = 0;
|
|
39
|
+
exceptions.set(parts.join(""), parts.slice(0, -1).map((part) => offset += part.length));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return (word) => {
|
|
43
|
+
if (table.size === 0) load();
|
|
44
|
+
const places = [];
|
|
45
|
+
for (const match of word.matchAll(letters)) {
|
|
46
|
+
const lower = match[0].toLowerCase().replaceAll("’", "'");
|
|
47
|
+
if (lower.length !== match[0].length) continue;
|
|
48
|
+
for (const offset of exceptions.get(lower) ?? placesOf(lower, table, longest, set)) places.push(match.index + offset);
|
|
49
|
+
}
|
|
50
|
+
return places;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { hyphenator as t };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=hyphen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyphen.js","names":[],"sources":["../../src/hyphen/liang.ts"],"sourcesContent":["/**\n * The matcher of Liang: a word takes the digits of each pattern that it holds, and an odd digit marks a hyphen place. Each\n * language subpath gives its own data to this module, so the data of a language stays out of each other entry.\n */\n\n/** The data of a language. */\nexport interface PatternSet {\n /** The patterns of Liang, with a space between them. A dot marks the start or the end of a word. */\n readonly patterns: string;\n /** The words with known hyphen places, with a hyphen at each place and a space between the words. */\n readonly exceptions: string;\n /** The least count of characters before a hyphen. */\n readonly left: number;\n /** The least count of characters after a hyphen. */\n readonly right: number;\n}\n\n/** The origin of a language set, and the result of the set on its word list. */\nexport interface HyphenSource {\n /** The language tag of the set. */\n readonly language: string;\n /** The file of the patterns, with the commit of its repository and its SHA-256. */\n readonly file: string;\n readonly commit: string;\n readonly sha256: string;\n /** The name of the license of the patterns. */\n readonly license: string;\n /** The result of the set on its word list. `docs/HYPHENATION.md` tells each field. */\n readonly words: {\n /** The name of the word list. */\n readonly list: string;\n /** This value is `true` when the word list does not come from the project of the patterns. */\n readonly independent: boolean;\n /** The count of words of the test. */\n readonly count: number;\n /** The hyphen places of the list that the set finds, from 0 to 1. */\n readonly found: number;\n /** The hyphen places of the set that the list holds, from 0 to 1. */\n readonly confirmed: number;\n };\n}\n\n/** The letters of a word for the patterns. An apostrophe is a letter, because the patterns of French use it. */\nconst letters = /[\\p{L}\\p{M}'’]+/gu;\n\n/** This function gives the offsets of the hyphen places of a lowercase word, from the patterns. */\nfunction placesOf(word: string, table: ReadonlyMap<string, string>, longest: number, set: PatternSet): number[] {\n const dotted = `.${word}.`;\n const digits = new Uint8Array(dotted.length + 1);\n for (let start = 0; start < dotted.length; start++) {\n const stop = Math.min(start + longest, dotted.length);\n for (let end = start + 1; end <= stop; end++) {\n const pattern = table.get(dotted.slice(start, end));\n if (pattern === undefined) continue;\n let place = start;\n for (const character of pattern) {\n if (character >= \"0\" && character <= \"9\") digits[place] = Math.max(digits[place]!, Number(character));\n else place++;\n }\n }\n }\n const places: number[] = [];\n for (let offset = set.left; offset <= word.length - set.right; offset++) if (digits[offset + 1]! % 2 === 1) places.push(offset);\n return places;\n}\n\n/**\n * This function gives the function for the `hyphenate` hook of `paragraphOf`. The function finds each run of letters of a word,\n * and it gives the hyphen places of each run. The table of the patterns comes at the first use, so an import costs no time.\n */\nexport function hyphenator(set: PatternSet): (word: string) => readonly number[] {\n const table = new Map<string, string>();\n const exceptions = new Map<string, number[]>();\n let longest = 0;\n const load = (): void => {\n for (const pattern of set.patterns.split(\" \")) {\n const key = pattern.replace(/\\d/gu, \"\");\n table.set(key, pattern);\n longest = Math.max(longest, key.length);\n }\n for (const entry of set.exceptions.split(\" \").filter((text) => text !== \"\")) {\n const parts = entry.split(\"-\");\n let offset = 0;\n exceptions.set(parts.join(\"\"), parts.slice(0, -1).map((part) => (offset += part.length)));\n }\n };\n return (word) => {\n if (table.size === 0) load();\n const places: number[] = [];\n for (const match of word.matchAll(letters)) {\n const lower = match[0].toLowerCase().replaceAll(\"’\", \"'\");\n // A lowercase form with another length has no offsets in the word. Such a run stays whole.\n if (lower.length !== match[0].length) continue;\n for (const offset of exceptions.get(lower) ?? placesOf(lower, table, longest, set)) places.push(match.index + offset);\n }\n return places;\n };\n}\n"],"mappings":";;AA2CA,MAAM,UAAU;;AAGhB,SAAS,SAAS,MAAc,OAAoC,SAAiB,KAA2B;CAC9G,MAAM,SAAS,IAAI,KAAK;CACxB,MAAM,SAAS,IAAI,WAAW,OAAO,SAAS,CAAC;CAC/C,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;EAClD,MAAM,OAAO,KAAK,IAAI,QAAQ,SAAS,OAAO,MAAM;EACpD,KAAK,IAAI,MAAM,QAAQ,GAAG,OAAO,MAAM,OAAO;GAC5C,MAAM,UAAU,MAAM,IAAI,OAAO,MAAM,OAAO,GAAG,CAAC;GAClD,IAAI,YAAY,KAAA,GAAW;GAC3B,IAAI,QAAQ;GACZ,KAAK,MAAM,aAAa,SACtB,IAAI,aAAa,OAAO,aAAa,KAAK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@@ -10,11 +10,18 @@ interface Box {
|
|
|
10
10
|
readonly text: string;
|
|
11
11
|
readonly width: number;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Glue: a space between two boxes. A line can end at glue that comes after a box. The line then does not show the glue. A
|
|
15
|
+
* justified line sets each glue to its width plus a part of its stretch, or less a part of its shrink.
|
|
16
|
+
*/
|
|
14
17
|
interface Glue {
|
|
15
18
|
readonly type: "glue";
|
|
16
19
|
readonly text: string;
|
|
17
20
|
readonly width: number;
|
|
21
|
+
/** The width that the glue can add to a justified line. The default is 0. */
|
|
22
|
+
readonly stretch?: number;
|
|
23
|
+
/** The width that the glue can take from a justified line, at most its width. The default is 0. */
|
|
24
|
+
readonly shrink?: number;
|
|
18
25
|
}
|
|
19
26
|
/**
|
|
20
27
|
* A penalty: a break opportunity with a cost. A line that ends at the penalty shows its text, for example a hyphen. A cost of
|
|
@@ -52,6 +59,10 @@ interface ParagraphOptions {
|
|
|
52
59
|
readonly hyphen?: string;
|
|
53
60
|
/** The cost of a hyphen break. The default is 50, as in TeX. */
|
|
54
61
|
readonly hyphenCost?: number;
|
|
62
|
+
/** The stretch of each glue, in the unit of `widthOf`. The default is 0. TeX uses a half of a space. */
|
|
63
|
+
readonly stretch?: number;
|
|
64
|
+
/** The shrink of each glue, in the unit of `widthOf`. The default is 0. TeX uses a third of a space. */
|
|
65
|
+
readonly shrink?: number;
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
57
68
|
* This function makes the paragraph of a text with the break opportunities of CSS `white-space: normal`. Each run of white
|
|
@@ -74,10 +85,16 @@ declare function isBreak(items: readonly Item[], index: number): boolean;
|
|
|
74
85
|
declare function lineStart(items: readonly Item[], index: number): number;
|
|
75
86
|
/** This function gives the width of the line from the item `start` to a break at `end`, with the text of a penalty at `end`. */
|
|
76
87
|
declare function lineWidth(items: readonly Item[], start: number, end: number): number;
|
|
88
|
+
/**
|
|
89
|
+
* This function gives the adjustment ratio of Knuth and Plass for the line from the item `start` to a break at `end`. The
|
|
90
|
+
* ratio is the free width divided by the stretch of the line, or by its shrink when the line is too wide. A ratio below -1
|
|
91
|
+
* needs more shrink than the line has. The ratio is infinite when the line needs stretch or shrink and has none.
|
|
92
|
+
*/
|
|
93
|
+
declare function adjustmentRatio(items: readonly Item[], start: number, end: number, width: number): number;
|
|
77
94
|
/**
|
|
78
95
|
* This function gives the lines of a paragraph from the indices of its breaks. Each break is the index of glue or of a penalty.
|
|
79
96
|
* The last line ends at the end of the items.
|
|
80
97
|
*/
|
|
81
98
|
declare function linesOf(paragraph: Paragraph, breaks: readonly number[]): Line[];
|
|
82
|
-
export { Paragraph as a, WidthOf as c,
|
|
99
|
+
export { Paragraph as a, WidthOf as c, lineStart as d, lineWidth as f, Line as i, adjustmentRatio as l, paragraphOf as m, Glue as n, ParagraphOptions as o, linesOf as p, Item as r, Penalty as s, Box as t, isBreak as u };
|
|
83
100
|
//# sourceMappingURL=paragraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.d.ts","names":[],"sources":["../../src/breaking/paragraph.ts"],"mappings":";;;;;KAMY,WAAW;;UAGN;WACN;WACA;WACA
|
|
1
|
+
{"version":3,"file":"paragraph.d.ts","names":[],"sources":["../../src/breaking/paragraph.ts"],"mappings":";;;;;KAMY,WAAW;;UAGN;WACN;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;;WAEA;;WAEA;;;;;;UAOM;WACN;WACA;WACA;WACA;;WAEA;;;KAIC,OAAO,MAAM,OAAO;;UAGf;WACN,gBAAgB;;;UAIV;;WAEN,SAAS;;;;;WAKT,aAAa;;;;;WAKb,UAAU;;WAEV;;WAEA;;WAEA;;WAEA;;;;;;iBASK,YAAY,cAAc,SAAS,mBAAmB;;UA4BrD;WACN;;WAEA;;WAEA;;WAEA;;;iBAIK,QAAQ,gBAAgB,QAAQ;;iBAOhC,UAAU,gBAAgB,QAAQ;;iBAOlC,UAAU,gBAAgB,QAAQ,eAAe;;;;;;iBAejD,gBAAgB,gBAAgB,QAAQ,eAAe,aAAa;;;;;iBAepE,QAAQ,WAAW,WAAW,4BAA4B"}
|
package/build/chunks/resolve.js
CHANGED
|
@@ -126,7 +126,14 @@ function firstStrong(original, start, end, match) {
|
|
|
126
126
|
}
|
|
127
127
|
return 0;
|
|
128
128
|
}
|
|
129
|
-
/** This function
|
|
129
|
+
/** This function gives the flag of a level: `L` for an even level and `R` for an odd level, as `DIRPROP_FLAG_LR` of ICU. */
|
|
130
|
+
function sideOf(level) {
|
|
131
|
+
return level & 1 ? R : L;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* This function applies the rules X1 to X9. It sets `levels` and it changes `types` where an override applies. It gives
|
|
135
|
+
* the flags of `resolveExplicitLevels` in `ubidi.cpp` of ICU, and `icuDirection` uses them.
|
|
136
|
+
*/
|
|
130
137
|
function resolveExplicit(original, types, match, levels, start, end, paragraph) {
|
|
131
138
|
const stack = [{
|
|
132
139
|
level: paragraph,
|
|
@@ -136,6 +143,8 @@ function resolveExplicit(original, types, match, levels, start, end, paragraph)
|
|
|
136
143
|
let overflowIsolates = 0;
|
|
137
144
|
let overflowEmbeddings = 0;
|
|
138
145
|
let validIsolates = 0;
|
|
146
|
+
let flags = 0;
|
|
147
|
+
let previous = paragraph;
|
|
139
148
|
for (let i = start; i < end; i++) {
|
|
140
149
|
const type = original[i];
|
|
141
150
|
let top = stack.at(-1);
|
|
@@ -143,9 +152,17 @@ function resolveExplicit(original, types, match, levels, start, end, paragraph)
|
|
|
143
152
|
const isolate = (type & isolates) !== 0;
|
|
144
153
|
levels[i] = isolate ? top.level : -1;
|
|
145
154
|
if (isolate && top.override) types[i] = top.override;
|
|
146
|
-
const
|
|
155
|
+
const right = type & 1245184 || type === FSI && firstStrong(original, i + 1, match[i], match) === 1;
|
|
156
|
+
const level = right ? top.level + 1 | 1 : top.level + 2 & -2;
|
|
157
|
+
if (isolate) {
|
|
158
|
+
flags |= ON | sideOf(top.level);
|
|
159
|
+
previous = top.level;
|
|
160
|
+
} else flags |= BN;
|
|
147
161
|
if (level <= maxDepth && overflowIsolates === 0 && overflowEmbeddings === 0) {
|
|
148
|
-
if (isolate)
|
|
162
|
+
if (isolate) {
|
|
163
|
+
validIsolates++;
|
|
164
|
+
flags |= right ? RLI : LRI;
|
|
165
|
+
}
|
|
149
166
|
stack.push({
|
|
150
167
|
level,
|
|
151
168
|
override: type === RLO ? R : type === LRO ? L : 0,
|
|
@@ -156,6 +173,7 @@ function resolveExplicit(original, types, match, levels, start, end, paragraph)
|
|
|
156
173
|
} else if (type === PDI) {
|
|
157
174
|
if (overflowIsolates > 0) overflowIsolates--;
|
|
158
175
|
else if (validIsolates > 0) {
|
|
176
|
+
flags |= PDI;
|
|
159
177
|
overflowEmbeddings = 0;
|
|
160
178
|
while (!stack.at(-1).isolate) stack.pop();
|
|
161
179
|
stack.pop();
|
|
@@ -164,19 +182,30 @@ function resolveExplicit(original, types, match, levels, start, end, paragraph)
|
|
|
164
182
|
top = stack.at(-1);
|
|
165
183
|
levels[i] = top.level;
|
|
166
184
|
if (top.override) types[i] = top.override;
|
|
185
|
+
flags |= ON | sideOf(top.level);
|
|
186
|
+
previous = top.level;
|
|
167
187
|
} else if (type === PDF) {
|
|
168
188
|
levels[i] = -1;
|
|
189
|
+
flags |= BN;
|
|
169
190
|
if (overflowIsolates === 0) {
|
|
170
191
|
if (overflowEmbeddings > 0) overflowEmbeddings--;
|
|
171
192
|
else if (!top.isolate && stack.length > 1) stack.pop();
|
|
172
193
|
}
|
|
173
|
-
} else if (type === BN)
|
|
174
|
-
|
|
175
|
-
|
|
194
|
+
} else if (type === BN) {
|
|
195
|
+
levels[i] = -1;
|
|
196
|
+
flags |= BN;
|
|
197
|
+
} else if (type === B) {
|
|
198
|
+
levels[i] = paragraph;
|
|
199
|
+
flags |= B;
|
|
200
|
+
} else {
|
|
176
201
|
levels[i] = top.level;
|
|
177
202
|
if (top.override) types[i] = top.override;
|
|
203
|
+
if (top.level !== previous) flags |= top.level & 1 ? top.override ? RLO : RLE : top.override ? LRO : LRE;
|
|
204
|
+
previous = top.level;
|
|
205
|
+
flags |= type;
|
|
178
206
|
}
|
|
179
207
|
}
|
|
208
|
+
return flags;
|
|
180
209
|
}
|
|
181
210
|
/** This function applies the rule BD13. It gives the indexes of each isolating run sequence. */
|
|
182
211
|
function sequencesOf(original, match, levels, start, end) {
|
|
@@ -353,6 +382,38 @@ function resolveLevels(classes, brackets = [], direction = "auto") {
|
|
|
353
382
|
paragraphs
|
|
354
383
|
};
|
|
355
384
|
}
|
|
385
|
+
const towardRight = 1245190;
|
|
386
|
+
const towardLeft = 573513;
|
|
387
|
+
const possibleNeutrals = 8388272;
|
|
388
|
+
/** This function gives the direction of a set of flags, as `directionFromFlags` of ICU. A number next to a neutral can make it RTL. */
|
|
389
|
+
function directionOfFlags(flags) {
|
|
390
|
+
if (!(flags & towardRight || flags & AN && flags & possibleNeutrals)) return "ltr";
|
|
391
|
+
return flags & towardLeft ? "mixed" : "rtl";
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* This function gives the direction that `ubidi_getDirection` of ICU gives to a text of one paragraph at the level
|
|
395
|
+
* `paragraph`. ICU first reads the flags of the classes. When they are mixed and the text has a control, it reads the
|
|
396
|
+
* flags of the explicit levels. Blink divides the text of a canvas into bidi runs only for the direction `mixed`.
|
|
397
|
+
*/
|
|
398
|
+
function icuDirection(classes, paragraph) {
|
|
399
|
+
const n = classes.length;
|
|
400
|
+
const original = new Int32Array(n);
|
|
401
|
+
for (let i = 0; i < n; i++) original[i] = bits[classes[i]];
|
|
402
|
+
const match = new Int32Array(n);
|
|
403
|
+
matchIsolates(original, 0, n, match);
|
|
404
|
+
let classFlags = sideOf(paragraph);
|
|
405
|
+
let explicit = false;
|
|
406
|
+
for (let i = 0; i < n; i++) {
|
|
407
|
+
const type = original[i];
|
|
408
|
+
explicit ||= (type & 8372224) !== 0;
|
|
409
|
+
classFlags |= type === FSI ? firstStrong(original, i + 1, match[i], match) === 1 ? RLI : LRI : type;
|
|
410
|
+
}
|
|
411
|
+
const direction = directionOfFlags(classFlags);
|
|
412
|
+
if (direction !== "mixed" || !explicit) return direction;
|
|
413
|
+
let flags = resolveExplicit(original, original.slice(), match, new Array(n).fill(0), 0, n, paragraph);
|
|
414
|
+
if (flags & 8388528) flags |= sideOf(paragraph);
|
|
415
|
+
return directionOfFlags(flags);
|
|
416
|
+
}
|
|
356
417
|
/**
|
|
357
418
|
* This function puts items in the visual order of the rule L2 of UAX #9. Each item has the level `levels[i]`. From the
|
|
358
419
|
* highest level to the level 1, it reverses each sequence of items at that level or higher.
|
|
@@ -377,6 +438,6 @@ function visualIndexes({ levels, paragraphs }) {
|
|
|
377
438
|
return visualOrder(kept, kept.map((i) => levels[i]));
|
|
378
439
|
});
|
|
379
440
|
}
|
|
380
|
-
export {
|
|
441
|
+
export { visualOrder as a, classRuns as c, visualIndexes as i, unicodeVersion as l, removed as n, bracketOf as o, resolveLevels as r, classNames as s, icuDirection as t };
|
|
381
442
|
|
|
382
443
|
//# sourceMappingURL=resolve.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","names":[],"sources":["../../src/bidi/table.ts","../../src/bidi/brackets.ts","../../src/bidi/resolve.ts"],"sourcesContent":["// Generated by `pnpm --filter @typeset/conformance tables` from Unicode 17.0.0. Do not edit.\nexport const unicodeVersion = \"17.0.0\";\nexport const classNames: readonly string[] = [\"L\",\"R\",\"AL\",\"ET\",\"EN\",\"ES\",\"AN\",\"CS\",\"B\",\"S\",\"WS\",\"ON\",\"BN\",\"NSM\",\"LRO\",\"RLO\",\"LRE\",\"RLE\",\"PDF\",\"LRI\",\"RLI\",\"FSI\",\"PDI\"];\nexport const classRuns = \"9M1J1I1J1K1IeM3I1J1K2L3D5L1F1H1F2HaE1H6LqA6LqA4L6M1IqM1H1L4D4L1A2L1M2L2D2E1L1A3L1E1A5LnA1LvA1LchA2L7AeL2AeL5A9L1Ah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N6AfN8ugAcN3A3N1xcA5N1nA7Nt4A1N1rA4N27A1L1A1Nf5kA2N1A4M318A5yLqAaE3L3Ac4L6AnLfAhLfA1aN2AnNf4A3N9A8M8N2A7NuA4N1nA2LlA1uL3N1L56A2fLoaA1LpA1LvA1LpA1LvA1LpA1LvA1LpA1LvA1LpA1LaA1eEe8A1jN4A1eN8A1NeA1NmA5N1AfN11sA7N1AhN2A7N1A2N1A5N2sA1N4gA7NafA1N1pA4NfA1DdoA4N72A2N6rA1N2A1N7A2N5A1N7eA5sB7N31B7NmdB28C1sB28C4wB6oC2LeC74B18L4A2sLcAfL2AfL1AfL1A11LaAbE5LvA1L1mA6L1pA1L4yA6L4aArdL3AhL3AdL3A62L6AcL4A1LfAcL4A1kL8AaL6A14L8AuL2AcL4A2LeA9L13A9kL8AeL2AdL3AbL3A1lL1A1L4AgL2AcL4AaL7A43L1A2kLaE1LsjA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA76M6oN2s0M1bemA2M1ekeA2M1ekeA2M\";\nexport const bracketPairs = \"14 1 1f 2 w 2 2wv 1 2 1 1gf 1 1wq 1 1k 1 g 1 hn 1 2 1 v 1 u7 1 2 1 2 1 2 1 2 1 2 1 2 1 29 1 x 1 2 1 2 1 2 1 2 1 b9 1 2 1 2 1 2 1 2 1 2 3 2 -1 2 1 2 1 2 1 2 1 1t 1 2 1 y 1 ti 1 2 1 2 1 2 1 19 1 2 1 2 1 2 1 bx 1 2 1 2 1 2 1 2 1 4 1 2 1 2 1 2 1 14qn 1 2 1 2 1 4r 1 1f 2 w 2 4 1 3 1\";\n","import { bracketPairs } from \"./table.ts\";\n\nlet brackets: Map<number, number> | undefined;\n\n/**\n * This function gives the value of a code point for the `brackets` of `resolveLevels`. The value is above 0 for an opening\n * paired bracket, below 0 for a closing paired bracket, and 0 for each other code point. U+3009 and U+232A have the same value.\n */\nexport function bracketOf(codePoint: number): number {\n if (brackets === undefined) {\n brackets = new Map();\n const lengths = bracketPairs.split(\" \").map((length) => Number.parseInt(length, 36));\n let open = 0;\n for (let i = 0; i < lengths.length; i += 2) {\n open += lengths[i]!;\n const close = open + lengths[i + 1]!;\n const id = close === 0x232a ? 0x3009 : close;\n brackets.set(open, id);\n brackets.set(close, -id);\n }\n }\n return brackets.get(codePoint) ?? 0;\n}\n","/**\n * The rules of the Unicode Bidirectional Algorithm (UAX #9). This module works on bidi classes and has no table, so `./fonts`\n * can use it with its own classes. The comments give the names of the rules. This module treats each paragraph as one line.\n */\n\n/** A bidi class of UAX #9. */\nexport type BidiClass =\n | \"L\"\n | \"R\"\n | \"AL\"\n | \"EN\"\n | \"ES\"\n | \"ET\"\n | \"AN\"\n | \"CS\"\n | \"NSM\"\n | \"BN\"\n | \"B\"\n | \"S\"\n | \"WS\"\n | \"ON\"\n | \"LRE\"\n | \"LRO\"\n | \"RLE\"\n | \"RLO\"\n | \"PDF\"\n | \"LRI\"\n | \"RLI\"\n | \"FSI\"\n | \"PDI\";\n\n/** The paragraph direction: `0` is left to right, `1` is right to left, and `\"auto\"` applies the rules P2 and P3. */\nexport type ParagraphDirection = 0 | 1 | \"auto\";\n\n/** One paragraph of a resolved text. */\nexport interface BidiParagraph {\n /** The index of the first character. */\n readonly start: number;\n /** The index after the last character. */\n readonly end: number;\n /** The paragraph embedding level. */\n readonly level: number;\n}\n\n/** The result of `resolveLevels`. */\nexport interface ResolvedBidi {\n /** The level of each character. The value is `removed` for a character that the rule X9 removes. */\n readonly levels: number[];\n readonly paragraphs: readonly BidiParagraph[];\n}\n\n/** This value is the level of a character that the rule X9 removes. */\nexport const removed = -1;\n\nconst L = 1 << 0;\nconst R = 1 << 1;\nconst AL = 1 << 2;\nconst EN = 1 << 3;\nconst ES = 1 << 4;\nconst ET = 1 << 5;\nconst AN = 1 << 6;\nconst CS = 1 << 7;\nconst NSM = 1 << 8;\nconst BN = 1 << 9;\nconst B = 1 << 10;\nconst S = 1 << 11;\nconst WS = 1 << 12;\nconst ON = 1 << 13;\nconst LRE = 1 << 14;\nconst LRO = 1 << 15;\nconst RLE = 1 << 16;\nconst RLO = 1 << 17;\nconst PDF = 1 << 18;\nconst LRI = 1 << 19;\nconst RLI = 1 << 20;\nconst FSI = 1 << 21;\nconst PDI = 1 << 22;\n\nconst bits: Readonly<Record<BidiClass, number>> = { L, R, AL, EN, ES, ET, AN, CS, NSM, BN, B, S, WS, ON, LRE, LRO, RLE, RLO, PDF, LRI, RLI, FSI, PDI };\nconst isolates = LRI | RLI | FSI;\nconst neutrals = B | S | WS | ON | isolates | PDI;\nconst maxDepth = 125;\nconst maxBrackets = 63;\n\n/** One entry of the directional status stack of the rule X1. */\ninterface Status {\n readonly level: number;\n readonly override: number;\n readonly isolate: boolean;\n}\n\n/** This function gives the direction of a type for the rules N0 to N2: numbers count as `R`, and a neutral gives 0. */\nfunction strong(type: number): number {\n if (type === L) return L;\n return type & (R | EN | AN) ? R : 0;\n}\n\n/** This function applies the rule BD9. It gives each isolate initiator the index of its PDI, or `end` when it has no PDI. */\nfunction matchIsolates(original: Int32Array, start: number, end: number, match: Int32Array): void {\n const open: number[] = [];\n for (let i = start; i < end; i++) {\n if (original[i]! & isolates) {\n open.push(i);\n match[i] = end;\n } else if (original[i] === PDI && open.length > 0) {\n match[open.pop()!] = i;\n }\n }\n}\n\n/** This function applies the rules P2 and P3 to a range. It gives the level of the first strong character, or else 0. */\nfunction firstStrong(original: Int32Array, start: number, end: number, match: Int32Array): number {\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n if (type === L) return 0;\n if (type & (R | AL)) return 1;\n if (type & isolates) i = match[i]!;\n }\n return 0;\n}\n\n/** This function applies the rules X1 to X9. It sets `levels` and it changes `types` where an override applies. */\nfunction resolveExplicit(original: Int32Array, types: Int32Array, match: Int32Array, levels: number[], start: number, end: number, paragraph: number): void {\n const stack: Status[] = [{ level: paragraph, override: 0, isolate: false }];\n let overflowIsolates = 0;\n let overflowEmbeddings = 0;\n let validIsolates = 0;\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n let top = stack.at(-1)!;\n if (type & (RLE | LRE | RLO | LRO | isolates)) {\n const isolate = (type & isolates) !== 0;\n levels[i] = isolate ? top.level : removed;\n if (isolate && top.override) types[i] = top.override;\n const right = type & (RLE | RLO | RLI) || (type === FSI && firstStrong(original, i + 1, match[i]!, match) === 1);\n const level = right ? (top.level + 1) | 1 : (top.level + 2) & ~1;\n if (level <= maxDepth && overflowIsolates === 0 && overflowEmbeddings === 0) {\n if (isolate) validIsolates++;\n stack.push({ level, override: type === RLO ? R : type === LRO ? L : 0, isolate });\n } else if (isolate) {\n overflowIsolates++;\n } else if (overflowIsolates === 0) {\n overflowEmbeddings++;\n }\n } else if (type === PDI) {\n if (overflowIsolates > 0) {\n overflowIsolates--;\n } else if (validIsolates > 0) {\n overflowEmbeddings = 0;\n while (!stack.at(-1)!.isolate) stack.pop();\n stack.pop();\n validIsolates--;\n }\n top = stack.at(-1)!;\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n } else if (type === PDF) {\n levels[i] = removed;\n if (overflowIsolates === 0) {\n if (overflowEmbeddings > 0) overflowEmbeddings--;\n else if (!top.isolate && stack.length > 1) stack.pop();\n }\n } else if (type === BN) {\n levels[i] = removed;\n } else if (type === B) {\n levels[i] = paragraph;\n } else {\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n }\n }\n}\n\n/** This function applies the rule BD13. It gives the indexes of each isolating run sequence. */\nfunction sequencesOf(original: Int32Array, match: Int32Array, levels: readonly number[], start: number, end: number): number[][] {\n const sequences: number[][] = [];\n const continued = new Map<number, number[]>();\n let sequence: number[] = [];\n let level = removed;\n for (let i = start; i < end; i++) {\n if (levels[i] === removed) continue;\n if (levels[i] !== level) {\n level = levels[i]!;\n const next = continued.get(i);\n if (next === undefined) sequences.push((sequence = []));\n else sequence = next;\n }\n sequence.push(i);\n if (original[i]! & isolates) continued.set(match[i]!, sequence);\n }\n return sequences;\n}\n\n/** This function applies the rules W1 to W7 to the types of one sequence. */\nfunction resolveWeak(sequenceTypes: number[], sos: number): void {\n const n = sequenceTypes.length;\n let previous = sos;\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] === NSM) sequenceTypes[k] = previous & (isolates | PDI) ? ON : previous;\n previous = sequenceTypes[k]!;\n }\n let last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (L | R | AL)) last = type;\n else if (type === EN && last === AL) sequenceTypes[k] = AN;\n if (type === AL) sequenceTypes[k] = R;\n }\n for (let k = 1; k + 1 < n; k++) {\n const type = sequenceTypes[k]!;\n const before = sequenceTypes[k - 1]!;\n if (type & (ES | CS) && before === sequenceTypes[k + 1] && (before === EN || (before === AN && type === CS))) sequenceTypes[k] = before;\n }\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] !== ET) continue;\n let end = k;\n while (end < n && sequenceTypes[end] === ET) end++;\n if (sequenceTypes[k - 1] === EN || sequenceTypes[end] === EN) sequenceTypes.fill(EN, k, end);\n k = end - 1;\n }\n last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (ES | ET | CS)) sequenceTypes[k] = ON;\n else if (type & (L | R)) last = type;\n else if (type === EN && last === L) sequenceTypes[k] = L;\n }\n}\n\n/** This function applies the rules BD16 and N0 to one sequence. A value of `brackets` is above 0 at an opening bracket and below 0 at its closing bracket. */\nfunction resolveBrackets(sequenceTypes: number[], sequence: readonly number[], original: Int32Array, brackets: readonly number[], direction: number, sos: number): void {\n const pairs: [number, number][] = [];\n const stack: number[] = [];\n const n = sequence.length;\n for (let k = 0; k < n; k++) {\n const bracket = brackets[sequence[k]!];\n if (!bracket || sequenceTypes[k] !== ON) continue;\n if (bracket > 0) {\n if (stack.length === maxBrackets) {\n pairs.length = 0;\n break;\n }\n stack.push(k);\n } else {\n for (let depth = stack.length - 1; depth >= 0; depth--) {\n if (brackets[sequence[stack[depth]!]!] !== -bracket) continue;\n pairs.push([stack[depth]!, k]);\n stack.length = depth;\n break;\n }\n }\n }\n pairs.sort((first, second) => first[0] - second[0]);\n for (const [open, close] of pairs) {\n let found = 0;\n for (let k = open + 1; k < close && found !== direction; k++) found = strong(sequenceTypes[k]!) || found;\n if (found === 0) continue;\n if (found !== direction) {\n let context = sos;\n for (let k = open - 1; k >= 0; k--) {\n if (strong(sequenceTypes[k]!) === 0) continue;\n context = strong(sequenceTypes[k]!);\n break;\n }\n if (context !== found) found = direction;\n }\n for (const bracket of [open, close]) {\n sequenceTypes[bracket] = found;\n for (let k = bracket + 1; k < n && original[sequence[k]!] === NSM; k++) sequenceTypes[k] = found;\n }\n }\n}\n\n/** This function applies the rules N1 and N2 to the types of one sequence. */\nfunction resolveNeutrals(sequenceTypes: number[], direction: number, sos: number, eos: number): void {\n const n = sequenceTypes.length;\n for (let k = 0; k < n; k++) {\n if (!(sequenceTypes[k]! & neutrals)) continue;\n let end = k;\n while (end < n && sequenceTypes[end]! & neutrals) end++;\n const before = k === 0 ? sos : strong(sequenceTypes[k - 1]!);\n const after = end === n ? eos : strong(sequenceTypes[end]!);\n sequenceTypes.fill(before === after ? before : direction, k, end);\n k = end - 1;\n }\n}\n\n/** This function applies the rule X10 and the rules W1 to N2 to one sequence. The level of the rules X1 to X9 gives the values of `sos` and `eos`. */\nfunction resolveSequence(sequence: readonly number[], original: Int32Array, types: Int32Array, brackets: readonly number[], levels: readonly number[], start: number, end: number, paragraph: number): void {\n const first = sequence[0]!;\n const last = sequence.at(-1)!;\n const level = levels[first]!;\n let before = first - 1;\n while (before >= start && levels[before] === removed) before--;\n let after = last + 1;\n while (after < end && levels[after] === removed) after++;\n const sos = Math.max(level, before < start ? paragraph : levels[before]!) & 1 ? R : L;\n const eos = Math.max(level, after === end || original[last]! & isolates ? paragraph : levels[after]!) & 1 ? R : L;\n const sequenceTypes = sequence.map((i) => types[i]!);\n const direction = level & 1 ? R : L;\n resolveWeak(sequenceTypes, sos);\n resolveBrackets(sequenceTypes, sequence, original, brackets, direction, sos);\n resolveNeutrals(sequenceTypes, direction, sos, eos);\n sequence.forEach((i, k) => {\n types[i] = sequenceTypes[k]!;\n });\n}\n\n/** This function applies the rules I1, I2 and L1 to one paragraph. */\nfunction resolveImplicit(original: Int32Array, types: Int32Array, levels: number[], start: number, end: number, paragraph: number): void {\n let atEnd = true;\n for (let i = end - 1; i >= start; i--) {\n if (levels[i] === removed) continue;\n const type = types[i]!;\n const kind = original[i]!;\n levels[i]! += levels[i]! & 1 ? (type === R ? 0 : 1) : type === L ? 0 : type === R ? 1 : 2;\n if (kind & (S | B)) atEnd = true;\n else if (!(kind & (WS | isolates | PDI))) atEnd = false;\n if (atEnd) levels[i] = paragraph;\n }\n}\n\n/**\n * This function gives the levels of a text from its classes, with the rules P1 to L1 of UAX #9. A class `B` ends a paragraph.\n * A value of `brackets` is 0 for a character that is not a paired bracket. It is above 0 at an opening bracket and below 0\n * at the closing bracket with the same absolute value. `bracketOf` of `./bidi` gives these values.\n */\nexport function resolveLevels(classes: readonly BidiClass[], brackets: readonly number[] = [], direction: ParagraphDirection = \"auto\"): ResolvedBidi {\n const n = classes.length;\n const original = new Int32Array(n);\n for (let i = 0; i < n; i++) original[i] = bits[classes[i]!];\n const types = original.slice();\n const match = new Int32Array(n);\n const levels = new Array<number>(n).fill(0);\n const paragraphs: BidiParagraph[] = [];\n for (let start = 0; start < n; ) {\n let end = start;\n while (end < n && original[end] !== B) end++;\n end = Math.min(end + 1, n);\n matchIsolates(original, start, end, match);\n const level = direction === \"auto\" ? firstStrong(original, start, end, match) : direction;\n resolveExplicit(original, types, match, levels, start, end, level);\n for (const sequence of sequencesOf(original, match, levels, start, end)) resolveSequence(sequence, original, types, brackets, levels, start, end, level);\n resolveImplicit(original, types, levels, start, end, level);\n paragraphs.push({ start, end, level });\n start = end;\n }\n return { levels, paragraphs };\n}\n\n/**\n * This function puts items in the visual order of the rule L2 of UAX #9. Each item has the level `levels[i]`. From the\n * highest level to the level 1, it reverses each sequence of items at that level or higher.\n */\nexport function visualOrder<T>(items: readonly T[], levels: readonly number[]): T[] {\n const order = items.map((_, i) => i);\n const n = order.length;\n for (let level = levels.reduce((highest, value) => Math.max(highest, value), 0); level >= 1; level--) {\n for (let i = 0; i < n; i++) {\n if (levels[order[i]!]! < level) continue;\n let end = i;\n while (end < n && levels[order[end]!]! >= level) end++;\n for (let low = i, high = end - 1; low < high; low++, high--) [order[low], order[high]] = [order[high]!, order[low]!];\n i = end;\n }\n }\n return order.map((i) => items[i]!);\n}\n\n/** This function gives the indexes of the characters in the visual order, for each paragraph as one line. It omits each removed character. */\nexport function visualIndexes({ levels, paragraphs }: ResolvedBidi): number[] {\n return paragraphs.flatMap(({ start, end }) => {\n const kept: number[] = [];\n for (let i = start; i < end; i++) if (levels[i] !== removed) kept.push(i);\n return visualOrder(\n kept,\n kept.map((i) => levels[i]!),\n );\n });\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC;CAAC;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAK;AACtK,MAAa,YAAY;AACzB,MAAa,eAAe;;ACF5B,IAAI;;;;;AAMJ,SAAgB,UAAU,WAA2B;CACnD,IAAI,aAAa,KAAA,GAAW;EAC1B,2BAAW,IAAI,IAAI;EACnB,MAAM,UAAU,aAAa,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAAC;EACnF,IAAI,OAAO;EACX,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;GAC1C,QAAQ,QAAQ;GAChB,MAAM,QAAQ,OAAO,QAAQ,IAAI;GACjC,MAAM,KAAK,UAAU,OAAS,QAAS;GACvC,SAAS,IAAI,MAAM,EAAE;GACrB,SAAS,IAAI,OAAO,CAAC,EAAE;EACzB;CACF;CACA,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MAAM,IAAK;EACnH,IAAI;CACN;CAEF,OAAO,MAAM,KAAK,MAAM,MAAM,EAAG;AACnC;;AAGA,SAAgB,cAAc,EAAE,QAAQ,cAAsC;CAC5E,OAAO,WAAW,SAAS,EAAE,OAAO,UAAU;EAC5C,MAAM,OAAiB,CAAC;EACxB,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,KAAK,IAAI,OAAO,OAAA,IAAgB,KAAK,KAAK,CAAC;EACxE,OAAO,YACL,MACA,KAAK,KAAK,MAAM,OAAO,EAAG,CAC5B;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"resolve.js","names":[],"sources":["../../src/bidi/table.ts","../../src/bidi/brackets.ts","../../src/bidi/resolve.ts"],"sourcesContent":["// Generated by `pnpm --filter @typeset/conformance tables` from Unicode 17.0.0. Do not edit.\nexport const unicodeVersion = \"17.0.0\";\nexport const classNames: readonly string[] = [\"L\",\"R\",\"AL\",\"ET\",\"EN\",\"ES\",\"AN\",\"CS\",\"B\",\"S\",\"WS\",\"ON\",\"BN\",\"NSM\",\"LRO\",\"RLO\",\"LRE\",\"RLE\",\"PDF\",\"LRI\",\"RLI\",\"FSI\",\"PDI\"];\nexport const classRuns = \"9M1J1I1J1K1IeM3I1J1K2L3D5L1F1H1F2HaE1H6LqA6LqA4L6M1IqM1H1L4D4L1A2L1M2L2D2E1L1A3L1E1A5LnA1LvA1LchA2L7AeL2AeL5A9L1AhL34N4A2L8A1L5A2L1A1L32A1L3wA7N74A1L2A2L1D1B19N1B1N1B2N1B2N1B1N1kB6G2L1C2D1C1H1C2LbN1cClNaG1D2G3C1N2tC7N1G1L6N2C2N1L4N2CaEnC1NuCrN2jCbNfC17B9N2B4L3B1NoB4N1B9N1B3N1B5N17B3N4B1cC2G5C9N16CoN1GwN1jA1N1A1N4A8N4A1N3A7NaA2NtA1N1mA1N4A4N8A1NkA2NeA2D7A1D2A1N2A2N1lA1N4A2N4A2N2A3N3A1NuA2N3A1NbA2N1lA1N4A5N1A2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sB28C4wB6oC2LeC74B18L4A2sLcAfL2AfL1AfL1A11LaAbE5LvA1L1mA6L1pA1L4yA6L4aArdL3AhL3AdL3A62L6AcL4A1LfAcL4A1kL8AaL6A14L8AuL2AcL4A2LeA9L13A9kL8AeL2AdL3AbL3A1lL1A1L4AgL2AcL4AaL7A43L1A2kLaE1LsjA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA2M1ekeA76M6oN2s0M1bemA2M1ekeA2M1ekeA2M\";\nexport const bracketPairs = \"14 1 1f 2 w 2 2wv 1 2 1 1gf 1 1wq 1 1k 1 g 1 hn 1 2 1 v 1 u7 1 2 1 2 1 2 1 2 1 2 1 2 1 29 1 x 1 2 1 2 1 2 1 2 1 b9 1 2 1 2 1 2 1 2 1 2 3 2 -1 2 1 2 1 2 1 2 1 1t 1 2 1 y 1 ti 1 2 1 2 1 2 1 19 1 2 1 2 1 2 1 bx 1 2 1 2 1 2 1 2 1 4 1 2 1 2 1 2 1 14qn 1 2 1 2 1 4r 1 1f 2 w 2 4 1 3 1\";\n","import { bracketPairs } from \"./table.ts\";\n\nlet brackets: Map<number, number> | undefined;\n\n/**\n * This function gives the value of a code point for the `brackets` of `resolveLevels`. The value is above 0 for an opening\n * paired bracket, below 0 for a closing paired bracket, and 0 for each other code point. U+3009 and U+232A have the same value.\n */\nexport function bracketOf(codePoint: number): number {\n if (brackets === undefined) {\n brackets = new Map();\n const lengths = bracketPairs.split(\" \").map((length) => Number.parseInt(length, 36));\n let open = 0;\n for (let i = 0; i < lengths.length; i += 2) {\n open += lengths[i]!;\n const close = open + lengths[i + 1]!;\n const id = close === 0x232a ? 0x3009 : close;\n brackets.set(open, id);\n brackets.set(close, -id);\n }\n }\n return brackets.get(codePoint) ?? 0;\n}\n","/**\n * The rules of the Unicode Bidirectional Algorithm (UAX #9). This module works on bidi classes and has no table, so `./fonts`\n * can use it with its own classes. The comments give the names of the rules. This module treats each paragraph as one line.\n */\n\n/** A bidi class of UAX #9. */\nexport type BidiClass =\n | \"L\"\n | \"R\"\n | \"AL\"\n | \"EN\"\n | \"ES\"\n | \"ET\"\n | \"AN\"\n | \"CS\"\n | \"NSM\"\n | \"BN\"\n | \"B\"\n | \"S\"\n | \"WS\"\n | \"ON\"\n | \"LRE\"\n | \"LRO\"\n | \"RLE\"\n | \"RLO\"\n | \"PDF\"\n | \"LRI\"\n | \"RLI\"\n | \"FSI\"\n | \"PDI\";\n\n/** The paragraph direction: `0` is left to right, `1` is right to left, and `\"auto\"` applies the rules P2 and P3. */\nexport type ParagraphDirection = 0 | 1 | \"auto\";\n\n/** One paragraph of a resolved text. */\nexport interface BidiParagraph {\n /** The index of the first character. */\n readonly start: number;\n /** The index after the last character. */\n readonly end: number;\n /** The paragraph embedding level. */\n readonly level: number;\n}\n\n/** The result of `resolveLevels`. */\nexport interface ResolvedBidi {\n /** The level of each character. The value is `removed` for a character that the rule X9 removes. */\n readonly levels: number[];\n readonly paragraphs: readonly BidiParagraph[];\n}\n\n/** This value is the level of a character that the rule X9 removes. */\nexport const removed = -1;\n\nconst L = 1 << 0;\nconst R = 1 << 1;\nconst AL = 1 << 2;\nconst EN = 1 << 3;\nconst ES = 1 << 4;\nconst ET = 1 << 5;\nconst AN = 1 << 6;\nconst CS = 1 << 7;\nconst NSM = 1 << 8;\nconst BN = 1 << 9;\nconst B = 1 << 10;\nconst S = 1 << 11;\nconst WS = 1 << 12;\nconst ON = 1 << 13;\nconst LRE = 1 << 14;\nconst LRO = 1 << 15;\nconst RLE = 1 << 16;\nconst RLO = 1 << 17;\nconst PDF = 1 << 18;\nconst LRI = 1 << 19;\nconst RLI = 1 << 20;\nconst FSI = 1 << 21;\nconst PDI = 1 << 22;\n\nconst bits: Readonly<Record<BidiClass, number>> = { L, R, AL, EN, ES, ET, AN, CS, NSM, BN, B, S, WS, ON, LRE, LRO, RLE, RLO, PDF, LRI, RLI, FSI, PDI };\nconst isolates = LRI | RLI | FSI;\nconst neutrals = B | S | WS | ON | isolates | PDI;\nconst maxDepth = 125;\nconst maxBrackets = 63;\n\n/** One entry of the directional status stack of the rule X1. */\ninterface Status {\n readonly level: number;\n readonly override: number;\n readonly isolate: boolean;\n}\n\n/** This function gives the direction of a type for the rules N0 to N2: numbers count as `R`, and a neutral gives 0. */\nfunction strong(type: number): number {\n if (type === L) return L;\n return type & (R | EN | AN) ? R : 0;\n}\n\n/** This function applies the rule BD9. It gives each isolate initiator the index of its PDI, or `end` when it has no PDI. */\nfunction matchIsolates(original: Int32Array, start: number, end: number, match: Int32Array): void {\n const open: number[] = [];\n for (let i = start; i < end; i++) {\n if (original[i]! & isolates) {\n open.push(i);\n match[i] = end;\n } else if (original[i] === PDI && open.length > 0) {\n match[open.pop()!] = i;\n }\n }\n}\n\n/** This function applies the rules P2 and P3 to a range. It gives the level of the first strong character, or else 0. */\nfunction firstStrong(original: Int32Array, start: number, end: number, match: Int32Array): number {\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n if (type === L) return 0;\n if (type & (R | AL)) return 1;\n if (type & isolates) i = match[i]!;\n }\n return 0;\n}\n\n/** This function gives the flag of a level: `L` for an even level and `R` for an odd level, as `DIRPROP_FLAG_LR` of ICU. */\nfunction sideOf(level: number): number {\n return level & 1 ? R : L;\n}\n\n/**\n * This function applies the rules X1 to X9. It sets `levels` and it changes `types` where an override applies. It gives\n * the flags of `resolveExplicitLevels` in `ubidi.cpp` of ICU, and `icuDirection` uses them.\n */\nfunction resolveExplicit(original: Int32Array, types: Int32Array, match: Int32Array, levels: number[], start: number, end: number, paragraph: number): number {\n const stack: Status[] = [{ level: paragraph, override: 0, isolate: false }];\n let overflowIsolates = 0;\n let overflowEmbeddings = 0;\n let validIsolates = 0;\n let flags = 0;\n let previous = paragraph;\n for (let i = start; i < end; i++) {\n const type = original[i]!;\n let top = stack.at(-1)!;\n if (type & (RLE | LRE | RLO | LRO | isolates)) {\n const isolate = (type & isolates) !== 0;\n levels[i] = isolate ? top.level : removed;\n if (isolate && top.override) types[i] = top.override;\n const right = type & (RLE | RLO | RLI) || (type === FSI && firstStrong(original, i + 1, match[i]!, match) === 1);\n const level = right ? (top.level + 1) | 1 : (top.level + 2) & ~1;\n if (isolate) {\n flags |= ON | sideOf(top.level);\n previous = top.level;\n } else {\n flags |= BN;\n }\n if (level <= maxDepth && overflowIsolates === 0 && overflowEmbeddings === 0) {\n if (isolate) {\n validIsolates++;\n flags |= right ? RLI : LRI;\n }\n stack.push({ level, override: type === RLO ? R : type === LRO ? L : 0, isolate });\n } else if (isolate) {\n overflowIsolates++;\n } else if (overflowIsolates === 0) {\n overflowEmbeddings++;\n }\n } else if (type === PDI) {\n if (overflowIsolates > 0) {\n overflowIsolates--;\n } else if (validIsolates > 0) {\n flags |= PDI;\n overflowEmbeddings = 0;\n while (!stack.at(-1)!.isolate) stack.pop();\n stack.pop();\n validIsolates--;\n }\n top = stack.at(-1)!;\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n flags |= ON | sideOf(top.level);\n previous = top.level;\n } else if (type === PDF) {\n levels[i] = removed;\n flags |= BN;\n if (overflowIsolates === 0) {\n if (overflowEmbeddings > 0) overflowEmbeddings--;\n else if (!top.isolate && stack.length > 1) stack.pop();\n }\n } else if (type === BN) {\n levels[i] = removed;\n flags |= BN;\n } else if (type === B) {\n levels[i] = paragraph;\n flags |= B;\n } else {\n levels[i] = top.level;\n if (top.override) types[i] = top.override;\n // ICU marks a change of the embedding level with the flag of an embedding or an override of that side\n if (top.level !== previous) flags |= top.level & 1 ? (top.override ? RLO : RLE) : top.override ? LRO : LRE;\n previous = top.level;\n flags |= type;\n }\n }\n return flags;\n}\n\n/** This function applies the rule BD13. It gives the indexes of each isolating run sequence. */\nfunction sequencesOf(original: Int32Array, match: Int32Array, levels: readonly number[], start: number, end: number): number[][] {\n const sequences: number[][] = [];\n const continued = new Map<number, number[]>();\n let sequence: number[] = [];\n let level = removed;\n for (let i = start; i < end; i++) {\n if (levels[i] === removed) continue;\n if (levels[i] !== level) {\n level = levels[i]!;\n const next = continued.get(i);\n if (next === undefined) sequences.push((sequence = []));\n else sequence = next;\n }\n sequence.push(i);\n if (original[i]! & isolates) continued.set(match[i]!, sequence);\n }\n return sequences;\n}\n\n/** This function applies the rules W1 to W7 to the types of one sequence. */\nfunction resolveWeak(sequenceTypes: number[], sos: number): void {\n const n = sequenceTypes.length;\n let previous = sos;\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] === NSM) sequenceTypes[k] = previous & (isolates | PDI) ? ON : previous;\n previous = sequenceTypes[k]!;\n }\n let last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (L | R | AL)) last = type;\n else if (type === EN && last === AL) sequenceTypes[k] = AN;\n if (type === AL) sequenceTypes[k] = R;\n }\n for (let k = 1; k + 1 < n; k++) {\n const type = sequenceTypes[k]!;\n const before = sequenceTypes[k - 1]!;\n if (type & (ES | CS) && before === sequenceTypes[k + 1] && (before === EN || (before === AN && type === CS))) sequenceTypes[k] = before;\n }\n for (let k = 0; k < n; k++) {\n if (sequenceTypes[k] !== ET) continue;\n let end = k;\n while (end < n && sequenceTypes[end] === ET) end++;\n if (sequenceTypes[k - 1] === EN || sequenceTypes[end] === EN) sequenceTypes.fill(EN, k, end);\n k = end - 1;\n }\n last = sos;\n for (let k = 0; k < n; k++) {\n const type = sequenceTypes[k]!;\n if (type & (ES | ET | CS)) sequenceTypes[k] = ON;\n else if (type & (L | R)) last = type;\n else if (type === EN && last === L) sequenceTypes[k] = L;\n }\n}\n\n/** This function applies the rules BD16 and N0 to one sequence. A value of `brackets` is above 0 at an opening bracket and below 0 at its closing bracket. */\nfunction resolveBrackets(sequenceTypes: number[], sequence: readonly number[], original: Int32Array, brackets: readonly number[], direction: number, sos: number): void {\n const pairs: [number, number][] = [];\n const stack: number[] = [];\n const n = sequence.length;\n for (let k = 0; k < n; k++) {\n const bracket = brackets[sequence[k]!];\n if (!bracket || sequenceTypes[k] !== ON) continue;\n if (bracket > 0) {\n if (stack.length === maxBrackets) {\n pairs.length = 0;\n break;\n }\n stack.push(k);\n } else {\n for (let depth = stack.length - 1; depth >= 0; depth--) {\n if (brackets[sequence[stack[depth]!]!] !== -bracket) continue;\n pairs.push([stack[depth]!, k]);\n stack.length = depth;\n break;\n }\n }\n }\n pairs.sort((first, second) => first[0] - second[0]);\n for (const [open, close] of pairs) {\n let found = 0;\n for (let k = open + 1; k < close && found !== direction; k++) found = strong(sequenceTypes[k]!) || found;\n if (found === 0) continue;\n if (found !== direction) {\n let context = sos;\n for (let k = open - 1; k >= 0; k--) {\n if (strong(sequenceTypes[k]!) === 0) continue;\n context = strong(sequenceTypes[k]!);\n break;\n }\n if (context !== found) found = direction;\n }\n for (const bracket of [open, close]) {\n sequenceTypes[bracket] = found;\n for (let k = bracket + 1; k < n && original[sequence[k]!] === NSM; k++) sequenceTypes[k] = found;\n }\n }\n}\n\n/** This function applies the rules N1 and N2 to the types of one sequence. */\nfunction resolveNeutrals(sequenceTypes: number[], direction: number, sos: number, eos: number): void {\n const n = sequenceTypes.length;\n for (let k = 0; k < n; k++) {\n if (!(sequenceTypes[k]! & neutrals)) continue;\n let end = k;\n while (end < n && sequenceTypes[end]! & neutrals) end++;\n const before = k === 0 ? sos : strong(sequenceTypes[k - 1]!);\n const after = end === n ? eos : strong(sequenceTypes[end]!);\n sequenceTypes.fill(before === after ? before : direction, k, end);\n k = end - 1;\n }\n}\n\n/** This function applies the rule X10 and the rules W1 to N2 to one sequence. The level of the rules X1 to X9 gives the values of `sos` and `eos`. */\nfunction resolveSequence(sequence: readonly number[], original: Int32Array, types: Int32Array, brackets: readonly number[], levels: readonly number[], start: number, end: number, paragraph: number): void {\n const first = sequence[0]!;\n const last = sequence.at(-1)!;\n const level = levels[first]!;\n let before = first - 1;\n while (before >= start && levels[before] === removed) before--;\n let after = last + 1;\n while (after < end && levels[after] === removed) after++;\n const sos = Math.max(level, before < start ? paragraph : levels[before]!) & 1 ? R : L;\n const eos = Math.max(level, after === end || original[last]! & isolates ? paragraph : levels[after]!) & 1 ? R : L;\n const sequenceTypes = sequence.map((i) => types[i]!);\n const direction = level & 1 ? R : L;\n resolveWeak(sequenceTypes, sos);\n resolveBrackets(sequenceTypes, sequence, original, brackets, direction, sos);\n resolveNeutrals(sequenceTypes, direction, sos, eos);\n sequence.forEach((i, k) => {\n types[i] = sequenceTypes[k]!;\n });\n}\n\n/** This function applies the rules I1, I2 and L1 to one paragraph. */\nfunction resolveImplicit(original: Int32Array, types: Int32Array, levels: number[], start: number, end: number, paragraph: number): void {\n let atEnd = true;\n for (let i = end - 1; i >= start; i--) {\n if (levels[i] === removed) continue;\n const type = types[i]!;\n const kind = original[i]!;\n levels[i]! += levels[i]! & 1 ? (type === R ? 0 : 1) : type === L ? 0 : type === R ? 1 : 2;\n if (kind & (S | B)) atEnd = true;\n else if (!(kind & (WS | isolates | PDI))) atEnd = false;\n if (atEnd) levels[i] = paragraph;\n }\n}\n\n/**\n * This function gives the levels of a text from its classes, with the rules P1 to L1 of UAX #9. A class `B` ends a paragraph.\n * A value of `brackets` is 0 for a character that is not a paired bracket. It is above 0 at an opening bracket and below 0\n * at the closing bracket with the same absolute value. `bracketOf` of `./bidi` gives these values.\n */\nexport function resolveLevels(classes: readonly BidiClass[], brackets: readonly number[] = [], direction: ParagraphDirection = \"auto\"): ResolvedBidi {\n const n = classes.length;\n const original = new Int32Array(n);\n for (let i = 0; i < n; i++) original[i] = bits[classes[i]!];\n const types = original.slice();\n const match = new Int32Array(n);\n const levels = new Array<number>(n).fill(0);\n const paragraphs: BidiParagraph[] = [];\n for (let start = 0; start < n; ) {\n let end = start;\n while (end < n && original[end] !== B) end++;\n end = Math.min(end + 1, n);\n matchIsolates(original, start, end, match);\n const level = direction === \"auto\" ? firstStrong(original, start, end, match) : direction;\n resolveExplicit(original, types, match, levels, start, end, level);\n for (const sequence of sequencesOf(original, match, levels, start, end)) resolveSequence(sequence, original, types, brackets, levels, start, end, level);\n resolveImplicit(original, types, levels, start, end, level);\n paragraphs.push({ start, end, level });\n start = end;\n }\n return { levels, paragraphs };\n}\n\n/** The direction of a paragraph that `ubidi_getDirection` of ICU gives. */\nexport type IcuDirection = \"ltr\" | \"rtl\" | \"mixed\";\n\nconst towardRight = R | AL | RLE | RLO | RLI;\nconst towardLeft = L | EN | AN | LRE | LRO | LRI;\nconst possibleNeutrals = ON | CS | ES | ET | WS | B | S | BN | LRE | RLE | LRO | RLO | PDF | isolates | PDI;\n\n/** This function gives the direction of a set of flags, as `directionFromFlags` of ICU. A number next to a neutral can make it RTL. */\nfunction directionOfFlags(flags: number): IcuDirection {\n if (!(flags & towardRight || (flags & AN && flags & possibleNeutrals))) return \"ltr\";\n return flags & towardLeft ? \"mixed\" : \"rtl\";\n}\n\n/**\n * This function gives the direction that `ubidi_getDirection` of ICU gives to a text of one paragraph at the level\n * `paragraph`. ICU first reads the flags of the classes. When they are mixed and the text has a control, it reads the\n * flags of the explicit levels. Blink divides the text of a canvas into bidi runs only for the direction `mixed`.\n */\nexport function icuDirection(classes: readonly BidiClass[], paragraph: 0 | 1): IcuDirection {\n const n = classes.length;\n const original = new Int32Array(n);\n for (let i = 0; i < n; i++) original[i] = bits[classes[i]!];\n const match = new Int32Array(n);\n matchIsolates(original, 0, n, match);\n let classFlags = sideOf(paragraph);\n let explicit = false;\n for (let i = 0; i < n; i++) {\n const type = original[i]!;\n explicit ||= (type & (RLE | LRE | RLO | LRO | PDF | isolates | PDI)) !== 0;\n // ICU gives an FSI the class of the isolate that the rules P2 and P3 choose\n classFlags |= type === FSI ? (firstStrong(original, i + 1, match[i]!, match) === 1 ? RLI : LRI) : type;\n }\n const direction = directionOfFlags(classFlags);\n if (direction !== \"mixed\" || !explicit) return direction;\n let flags = resolveExplicit(original, original.slice(), match, new Array<number>(n).fill(0), 0, n, paragraph);\n if (flags & (NSM | possibleNeutrals)) flags |= sideOf(paragraph);\n return directionOfFlags(flags);\n}\n\n/**\n * This function puts items in the visual order of the rule L2 of UAX #9. Each item has the level `levels[i]`. From the\n * highest level to the level 1, it reverses each sequence of items at that level or higher.\n */\nexport function visualOrder<T>(items: readonly T[], levels: readonly number[]): T[] {\n const order = items.map((_, i) => i);\n const n = order.length;\n for (let level = levels.reduce((highest, value) => Math.max(highest, value), 0); level >= 1; level--) {\n for (let i = 0; i < n; i++) {\n if (levels[order[i]!]! < level) continue;\n let end = i;\n while (end < n && levels[order[end]!]! >= level) end++;\n for (let low = i, high = end - 1; low < high; low++, high--) [order[low], order[high]] = [order[high]!, order[low]!];\n i = end;\n }\n }\n return order.map((i) => items[i]!);\n}\n\n/** This function gives the indexes of the characters in the visual order, for each paragraph as one line. It omits each removed character. */\nexport function visualIndexes({ levels, paragraphs }: ResolvedBidi): number[] {\n return paragraphs.flatMap(({ start, end }) => {\n const kept: number[] = [];\n for (let i = start; i < end; i++) if (levels[i] !== removed) kept.push(i);\n return visualOrder(\n kept,\n kept.map((i) => levels[i]!),\n );\n });\n}\n"],"mappings":";AACA,MAAa,iBAAiB;AAC9B,MAAa,aAAgC;CAAC;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;AAAK;AACtK,MAAa,YAAY;AACzB,MAAa,eAAe;;ACF5B,IAAI;;;;;AAMJ,SAAgB,UAAU,WAA2B;CACnD,IAAI,aAAa,KAAA,GAAW;EAC1B,2BAAW,IAAI,IAAI;EACnB,MAAM,UAAU,aAAa,MAAM,GAAG,CAAC,CAAC,KAAK,WAAW,OAAO,SAAS,QAAQ,EAAE,CAAC;EACnF,IAAI,OAAO;EACX,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;GAC1C,QAAQ,QAAQ;GAChB,MAAM,QAAQ,OAAO,QAAQ,IAAI;GACjC,MAAM,KAAK,UAAU,OAAS,QAAS;GACvC,SAAS,IAAI,MAAM,EAAE;GACrB,S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,SAAS,GAAG,SAC3F,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EAC1B,IAAI,OAAO,MAAM,MAAQ,OAAO;EAChC,IAAI,MAAM;EACV,OAAO,MAAM,KAAK,OAAO,MAAM,SAAW,OAAO;EACjD,KAAK,IAAI,MAAM,GAAG,OAAO,MAAM,GAAG,MAAM,MAAM,OAAO,QAAQ,CAAC,MAAM,MAAM,MAAM,SAAS,CAAC,MAAM,OAAQ,MAAM,IAAK;EACnH,IAAI;CACN;CAEF,OAAO,MAAM,KAAK,MAAM,MAAM,EAAG;AACnC;;AAGA,SAAgB,cAAc,EAAE,QAAQ,cAAsC;CAC5E,OAAO,WAAW,SAAS,EAAE,OAAO,UAAU;EAC5C,MAAM,OAAiB,CAAC;EACxB,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,KAAK,IAAI,OAAO,OAAA,IAAgB,KAAK,KAAK,CAAC;EACxE,OAAO,YACL,MACA,KAAK,KAAK,MAAM,OAAO,EAAG,CAC5B;CACF,CAAC;AACH"}
|
package/build/fonts-inspect.d.ts
CHANGED
|
@@ -12,13 +12,13 @@ export declare function indicSyllables(text: string): {
|
|
|
12
12
|
}[];
|
|
13
13
|
/**
|
|
14
14
|
* This function divides the text of a canvas into the words that Blink shapes one at a time. Each space, tab and zero
|
|
15
|
-
* width space is a word alone. Each
|
|
16
|
-
* Common after it.
|
|
15
|
+
* width space is a word alone. Each character that `canvasText` changes into one of them is also a word alone. Each CJK
|
|
16
|
+
* character starts a word, with its marks and the CJK characters of the script Common after it.
|
|
17
17
|
*/
|
|
18
18
|
export declare function canvasWords(text: string): string[];
|
|
19
19
|
/**
|
|
20
|
-
* This function gives the segments of
|
|
21
|
-
*
|
|
20
|
+
* This function gives the segments of `canvasRuns` in the visual order. Blink shapes each bidi run alone and adds the
|
|
21
|
+
* widths of the words in this order.
|
|
22
22
|
*/
|
|
23
23
|
export declare function canvasSegments(text: string): string[];
|
|
24
24
|
export { type IndicSyllableType, defaultFeatures, glyphAdvances, readTables, shapingWords };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fonts-inspect.d.ts","names":[],"sources":["../src/fonts/indic.ts","../src/fonts/words.ts"],"mappings":";;;KAqMY;;;;;wBAOI,eAAe;WAA0B;WAAuB,MAAM;;;;;;;
|
|
1
|
+
{"version":3,"file":"fonts-inspect.d.ts","names":[],"sources":["../src/fonts/indic.ts","../src/fonts/words.ts"],"mappings":";;;KAqMY;;;;;wBAOI,eAAe;WAA0B;WAAuB,MAAM;;;;;;;wBC5HtE,YAAY;;;;;wBA4CZ,eAAe"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { t as HyphenSource } from "../chunks/hyphen.js";
|
|
2
|
+
/** The origin of this set, and its result on its word list. */
|
|
3
|
+
export declare const source: HyphenSource;
|
|
4
|
+
/** This function gives the hyphen places of a word. Give it to the hook `hyphenate` of `paragraphOf`. */
|
|
5
|
+
export declare const hyphenate: (word: string) => readonly number[];
|
|
6
|
+
//# sourceMappingURL=de.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"de.d.ts","names":[],"sources":["../../src/hyphen/de.ts"],"mappings":";;qBAqDa,QAAQ;;qBAGR,YAAY"}
|