documents.js 1.91.3 → 1.91.5
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/dist/convert/convert.d.cts +2 -2
- package/dist/convert/convert.d.ts +1 -1
- package/dist/convert/document-fonts.d.cts +1 -1
- package/dist/convert/document-fonts.d.ts +1 -1
- package/dist/convert/port.d.cts +1 -2
- package/dist/convert/port.d.ts +1 -2
- package/dist/edit/geometry.d.cts +1 -1
- package/dist/edit/geometry.d.ts +1 -1
- package/dist/edit/markdown/editor.d.cts +1 -1
- package/dist/edit/markdown/editor.d.ts +1 -1
- package/dist/edit/odg/editor.d.cts +1 -1
- package/dist/edit/odg/editor.d.ts +1 -1
- package/dist/edit/odg/page.d.cts +2 -2
- package/dist/edit/odg/page.d.ts +2 -2
- package/dist/edit/odp/editor.d.cts +1 -1
- package/dist/edit/odp/editor.d.ts +1 -1
- package/dist/edit/odp/image.d.cts +1 -1
- package/dist/edit/odp/image.d.ts +1 -1
- package/dist/edit/odp/shape.d.cts +1 -1
- package/dist/edit/odp/shape.d.ts +1 -1
- package/dist/edit/odp/slide.d.cts +4 -4
- package/dist/edit/odp/slide.d.ts +4 -4
- package/dist/edit/odt/content.d.cts +2 -2
- package/dist/edit/odt/content.d.ts +2 -2
- package/dist/edit/odt/editor.d.cts +4 -4
- package/dist/edit/odt/editor.d.ts +4 -4
- package/dist/edit/odt/formula.d.cts +1 -1
- package/dist/edit/odt/formula.d.ts +1 -1
- package/dist/edit/odt/image.d.cts +1 -1
- package/dist/edit/odt/image.d.ts +1 -1
- package/dist/edit/odt/list.d.cts +1 -1
- package/dist/edit/odt/list.d.ts +1 -1
- package/dist/edit/odt/paragraph.d.cts +1 -1
- package/dist/edit/odt/paragraph.d.ts +1 -1
- package/dist/edit/odt/table.d.cts +1 -1
- package/dist/edit/odt/table.d.ts +1 -1
- package/dist/edit/pptx/editor.d.cts +1 -1
- package/dist/edit/pptx/editor.d.ts +1 -1
- package/dist/edit/pptx/image.d.cts +1 -1
- package/dist/edit/pptx/image.d.ts +1 -1
- package/dist/edit/pptx/shape.d.cts +1 -1
- package/dist/edit/pptx/shape.d.ts +1 -1
- package/dist/edit/pptx/slide.d.cts +4 -4
- package/dist/edit/pptx/slide.d.ts +4 -4
- package/dist/edit/pptx/table.d.cts +1 -1
- package/dist/edit/pptx/table.d.ts +1 -1
- package/dist/fonts/odf.d.cts +1 -1
- package/dist/fonts/odf.d.ts +1 -1
- package/dist/fonts/ooxml.d.cts +1 -1
- package/dist/fonts/ooxml.d.ts +1 -1
- package/dist/fonts/registry.d.cts +1 -1
- package/dist/fonts/registry.d.ts +1 -1
- package/dist/geometry-DUF273hM.d.cts +6 -0
- package/dist/geometry-DUF273hM.d.ts +6 -0
- package/dist/{image-DwrOnL_Z.d.ts → image-BFn8Rm6P.d.ts} +1 -1
- package/dist/{image-Cs8xF753.d.ts → image-BgN3j3ly.d.ts} +1 -1
- package/dist/{image-M5SezZVI.d.cts → image-C6lKT9ZH.d.cts} +1 -1
- package/dist/{image-DHcA9kaK.d.ts → image-CNuBLN5L.d.ts} +1 -1
- package/dist/{image-7snmKIxn.d.cts → image-DK0YCpYO.d.cts} +1 -1
- package/dist/{image-m_rfpuY8.d.cts → image-K3MAhLJc.d.cts} +1 -1
- package/dist/index.d.cts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/layout/drawing.cjs +1 -2
- package/dist/layout/drawing.d.cts +1 -2
- package/dist/layout/drawing.d.ts +1 -2
- package/dist/layout/drawing.js +1 -2
- package/dist/layout/engine.cjs +3 -2
- package/dist/layout/engine.d.cts +1 -2
- package/dist/layout/engine.d.ts +1 -2
- package/dist/layout/engine.js +2 -1
- package/dist/layout/shared.cjs +2 -1
- package/dist/layout/shared.d.cts +1 -2
- package/dist/layout/shared.d.ts +1 -2
- package/dist/layout/shared.js +2 -1
- package/dist/layout/sheets.cjs +3 -2
- package/dist/layout/sheets.d.cts +1 -2
- package/dist/layout/sheets.d.ts +1 -2
- package/dist/layout/sheets.js +2 -1
- package/dist/layout/slides.cjs +3 -2
- package/dist/layout/slides.d.cts +1 -2
- package/dist/layout/slides.d.ts +1 -2
- package/dist/layout/slides.js +3 -2
- package/dist/layout/text-layout.cjs +215 -0
- package/dist/layout/text-layout.d.cts +5 -0
- package/dist/layout/text-layout.d.ts +5 -0
- package/dist/layout/text-layout.js +214 -0
- package/dist/{list-4lN_90Pt.d.ts → list-CSIIzXAV.d.ts} +1 -1
- package/dist/{list-fKlr6jWd.d.cts → list-MCxkKpI7.d.cts} +1 -1
- package/dist/mathml/compose.d.cts +1 -1
- package/dist/mathml/compose.d.ts +1 -1
- package/dist/mathml/layout-types.d.cts +2 -51
- package/dist/mathml/layout-types.d.ts +2 -51
- package/dist/mathml/layout.d.cts +5 -5
- package/dist/mathml/layout.d.ts +5 -5
- package/dist/mathml/radical.d.cts +1 -1
- package/dist/mathml/radical.d.ts +1 -1
- package/dist/model/geometry.cjs +12 -0
- package/dist/model/geometry.d.cts +2 -2
- package/dist/model/geometry.d.ts +2 -2
- package/dist/model/geometry.js +12 -1
- package/dist/odf/formula/detect.d.cts +1 -1
- package/dist/odf/formula/detect.d.ts +1 -1
- package/dist/odf/shared/flow-anchor.d.cts +1 -1
- package/dist/odf/shared/flow-anchor.d.ts +1 -1
- package/dist/{paragraph-Bz20facN.d.ts → paragraph--0f7PjzJ.d.ts} +1 -1
- package/dist/{paragraph-BlN-ErQS.d.cts → paragraph-D7324S0j.d.cts} +1 -1
- package/dist/{registry-CrSqLIcn.d.ts → registry-DpF4A9EM.d.ts} +2 -1
- package/dist/{registry-CeZB1W_p.d.cts → registry-ZAWlWHqJ.d.cts} +2 -1
- package/dist/{shape-lA-bEGqk.d.cts → shape-B0yAqgxZ.d.cts} +3 -3
- package/dist/{shape-C3NECkae.d.ts → shape-CnYhKn5U.d.ts} +1 -1
- package/dist/{shape-CoiqTTA-.d.cts → shape-De9583Kz.d.cts} +1 -1
- package/dist/{shape-DFO5259y.d.ts → shape-tOOiQ2UZ.d.ts} +3 -3
- package/dist/{table-BRXbauz6.d.ts → table-DUM0vvIO.d.ts} +1 -1
- package/dist/{table-DV-Glhx_.d.ts → table-ce9uQfqn.d.ts} +2 -2
- package/dist/{table-CjUjLcsE.d.cts → table-fnUiKudF.d.cts} +2 -2
- package/dist/{table-CNrk1jGM.d.cts → table-u6fXNuDO.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/geometry-DaJr8yQW.d.cts +0 -5
- package/dist/geometry-DaJr8yQW.d.ts +0 -5
- package/dist/mathml/metrics.cjs +0 -0
- package/dist/mathml/metrics.d.cts +0 -60
- package/dist/mathml/metrics.d.ts +0 -60
- package/dist/mathml/metrics.js +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/layout/text-layout.ts
|
|
3
|
+
const WORD_OR_WHITESPACE_PATTERN = /\n|\s+|\S+/g;
|
|
4
|
+
function atomizeRuns(runs, measurer) {
|
|
5
|
+
const atoms = [];
|
|
6
|
+
let wordFragments = [];
|
|
7
|
+
let wordWidth = 0;
|
|
8
|
+
function flushWord() {
|
|
9
|
+
if (wordFragments.length > 0) {
|
|
10
|
+
atoms.push({
|
|
11
|
+
kind: "box",
|
|
12
|
+
fragments: wordFragments,
|
|
13
|
+
widthPt: wordWidth
|
|
14
|
+
});
|
|
15
|
+
wordFragments = [];
|
|
16
|
+
wordWidth = 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const run of runs) {
|
|
20
|
+
const tokens = run.text.match(WORD_OR_WHITESPACE_PATTERN) ?? [];
|
|
21
|
+
for (const token of tokens) if (token === "\n") {
|
|
22
|
+
flushWord();
|
|
23
|
+
atoms.push({
|
|
24
|
+
kind: "break",
|
|
25
|
+
widthPt: 0
|
|
26
|
+
});
|
|
27
|
+
} else if (/^\s+$/.test(token)) {
|
|
28
|
+
flushWord();
|
|
29
|
+
atoms.push({
|
|
30
|
+
kind: "glue",
|
|
31
|
+
widthPt: measurer.widthOfTextAtSize(token, run.font, run.sizePt)
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
wordFragments.push({
|
|
35
|
+
text: token,
|
|
36
|
+
font: run.font,
|
|
37
|
+
sizePt: run.sizePt,
|
|
38
|
+
color: run.color,
|
|
39
|
+
underline: run.underline,
|
|
40
|
+
hyperlink: run.hyperlink,
|
|
41
|
+
sourcePath: run.sourcePath
|
|
42
|
+
});
|
|
43
|
+
wordWidth += measurer.widthOfTextAtSize(token, run.font, run.sizePt);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
flushWord();
|
|
47
|
+
return atoms;
|
|
48
|
+
}
|
|
49
|
+
function fragmentsWidth(fragments, measurer) {
|
|
50
|
+
let total = 0;
|
|
51
|
+
for (const f of fragments) total += measurer.widthOfTextAtSize(f.text, f.font, f.sizePt);
|
|
52
|
+
return total;
|
|
53
|
+
}
|
|
54
|
+
function splitTextToWidth(text, font, sizePt, measurer, maxWidthPt) {
|
|
55
|
+
const chars = Array.from(text);
|
|
56
|
+
let width = 0;
|
|
57
|
+
let splitIndex = 0;
|
|
58
|
+
for (let i = 0; i < chars.length; i++) {
|
|
59
|
+
const charWidth = measurer.widthOfTextAtSize(chars[i], font, sizePt);
|
|
60
|
+
if (width + charWidth > maxWidthPt && splitIndex > 0) break;
|
|
61
|
+
width += charWidth;
|
|
62
|
+
splitIndex = i + 1;
|
|
63
|
+
}
|
|
64
|
+
if (splitIndex === 0 && chars.length > 0) splitIndex = 1;
|
|
65
|
+
return {
|
|
66
|
+
fitText: chars.slice(0, splitIndex).join(""),
|
|
67
|
+
restText: chars.slice(splitIndex).join("")
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function splitBoxToWidth(atom, measurer, maxWidthPt) {
|
|
71
|
+
const fitFragments = [];
|
|
72
|
+
let fitWidth = 0;
|
|
73
|
+
for (let idx = 0; idx < atom.fragments.length; idx++) {
|
|
74
|
+
const fragment = atom.fragments[idx];
|
|
75
|
+
const fragmentWidth = measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
76
|
+
if (fitWidth + fragmentWidth <= maxWidthPt) {
|
|
77
|
+
fitFragments.push(fragment);
|
|
78
|
+
fitWidth += fragmentWidth;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const { fitText, restText } = splitTextToWidth(fragment.text, fragment.font, fragment.sizePt, measurer, maxWidthPt - fitWidth);
|
|
82
|
+
if (fitText.length > 0) fitFragments.push({
|
|
83
|
+
...fragment,
|
|
84
|
+
text: fitText
|
|
85
|
+
});
|
|
86
|
+
const restFragments = [];
|
|
87
|
+
if (restText.length > 0) restFragments.push({
|
|
88
|
+
...fragment,
|
|
89
|
+
text: restText
|
|
90
|
+
});
|
|
91
|
+
restFragments.push(...atom.fragments.slice(idx + 1));
|
|
92
|
+
if (restFragments.length === 0) return {
|
|
93
|
+
fit: {
|
|
94
|
+
kind: "box",
|
|
95
|
+
fragments: fitFragments,
|
|
96
|
+
widthPt: fragmentsWidth(fitFragments, measurer)
|
|
97
|
+
},
|
|
98
|
+
rest: void 0
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
fit: {
|
|
102
|
+
kind: "box",
|
|
103
|
+
fragments: fitFragments,
|
|
104
|
+
widthPt: fragmentsWidth(fitFragments, measurer)
|
|
105
|
+
},
|
|
106
|
+
rest: {
|
|
107
|
+
kind: "box",
|
|
108
|
+
fragments: restFragments,
|
|
109
|
+
widthPt: fragmentsWidth(restFragments, measurer)
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
fit: atom,
|
|
115
|
+
rest: void 0
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function buildLine(atoms, measurer) {
|
|
119
|
+
const fragments = [];
|
|
120
|
+
let xOffsetPt = 0;
|
|
121
|
+
let maxSizePt = 0;
|
|
122
|
+
let ascentPt = 0;
|
|
123
|
+
let descentPt = 0;
|
|
124
|
+
for (const atom of atoms) if (atom.kind === "box") for (const fragment of atom.fragments) {
|
|
125
|
+
fragments.push({
|
|
126
|
+
...fragment,
|
|
127
|
+
xOffsetPt
|
|
128
|
+
});
|
|
129
|
+
xOffsetPt += measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
130
|
+
maxSizePt = Math.max(maxSizePt, fragment.sizePt);
|
|
131
|
+
ascentPt = Math.max(ascentPt, measurer.ascenderAtSize(fragment.font, fragment.sizePt));
|
|
132
|
+
descentPt = Math.min(descentPt, measurer.descenderAtSize(fragment.font, fragment.sizePt));
|
|
133
|
+
}
|
|
134
|
+
else xOffsetPt += atom.widthPt;
|
|
135
|
+
return {
|
|
136
|
+
fragments,
|
|
137
|
+
widthPt: xOffsetPt,
|
|
138
|
+
maxSizePt,
|
|
139
|
+
ascentPt,
|
|
140
|
+
descentPt
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function buildEmptyLine(runs, measurer) {
|
|
144
|
+
const first = runs[0];
|
|
145
|
+
if (first === void 0) return {
|
|
146
|
+
fragments: [],
|
|
147
|
+
widthPt: 0,
|
|
148
|
+
maxSizePt: 0,
|
|
149
|
+
ascentPt: 0,
|
|
150
|
+
descentPt: 0
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
fragments: [],
|
|
154
|
+
widthPt: 0,
|
|
155
|
+
maxSizePt: first.sizePt,
|
|
156
|
+
ascentPt: measurer.ascenderAtSize(first.font, first.sizePt),
|
|
157
|
+
descentPt: measurer.descenderAtSize(first.font, first.sizePt)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function wrapRunsToWidth(runs, measurer, maxWidthPt, options = {}) {
|
|
161
|
+
const breakLongWords = options.breakLongWords ?? true;
|
|
162
|
+
if (maxWidthPt <= 0) {
|
|
163
|
+
const atoms = atomizeRuns(runs, measurer).filter((a) => a.kind !== "break");
|
|
164
|
+
return atoms.length === 0 ? [buildEmptyLine(runs, measurer)] : [buildLine(atoms, measurer)];
|
|
165
|
+
}
|
|
166
|
+
const queue = atomizeRuns(runs, measurer);
|
|
167
|
+
const lines = [];
|
|
168
|
+
let current = [];
|
|
169
|
+
let currentWidth = 0;
|
|
170
|
+
function pushLine() {
|
|
171
|
+
while (current.length > 0 && current[current.length - 1]?.kind === "glue") {
|
|
172
|
+
const removed = current.pop();
|
|
173
|
+
currentWidth -= removed?.widthPt ?? 0;
|
|
174
|
+
}
|
|
175
|
+
lines.push(current.length === 0 ? buildEmptyLine(runs, measurer) : buildLine(current, measurer));
|
|
176
|
+
current = [];
|
|
177
|
+
currentWidth = 0;
|
|
178
|
+
}
|
|
179
|
+
let i = 0;
|
|
180
|
+
while (i < queue.length) {
|
|
181
|
+
const atom = queue[i];
|
|
182
|
+
if (atom.kind === "break") {
|
|
183
|
+
pushLine();
|
|
184
|
+
i++;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (currentWidth + atom.widthPt <= maxWidthPt) {
|
|
188
|
+
current.push(atom);
|
|
189
|
+
currentWidth += atom.widthPt;
|
|
190
|
+
i++;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (current.length > 0) {
|
|
194
|
+
pushLine();
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (atom.kind === "box" && breakLongWords) {
|
|
198
|
+
const { fit, rest } = splitBoxToWidth(atom, measurer, maxWidthPt);
|
|
199
|
+
current.push(fit);
|
|
200
|
+
currentWidth += fit.widthPt;
|
|
201
|
+
if (rest === void 0) i++;
|
|
202
|
+
else queue[i] = rest;
|
|
203
|
+
pushLine();
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
current.push(atom);
|
|
207
|
+
currentWidth += atom.widthPt;
|
|
208
|
+
i++;
|
|
209
|
+
pushLine();
|
|
210
|
+
}
|
|
211
|
+
if (current.length > 0 || lines.length === 0) pushLine();
|
|
212
|
+
return lines;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
exports.wrapRunsToWidth = wrapRunsToWidth;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
|
|
2
|
+
//#region src/layout/text-layout.d.ts
|
|
3
|
+
declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
|
|
4
|
+
//#endregion
|
|
5
|
+
export { wrapRunsToWidth };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { StyledRun, TextMeasurer, WrapOptions, WrappedLine } from "document-schema.js";
|
|
2
|
+
//#region src/layout/text-layout.d.ts
|
|
3
|
+
declare function wrapRunsToWidth(runs: readonly StyledRun[], measurer: TextMeasurer, maxWidthPt: number, options?: WrapOptions): WrappedLine[];
|
|
4
|
+
//#endregion
|
|
5
|
+
export { wrapRunsToWidth };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
//#region src/layout/text-layout.ts
|
|
2
|
+
const WORD_OR_WHITESPACE_PATTERN = /\n|\s+|\S+/g;
|
|
3
|
+
function atomizeRuns(runs, measurer) {
|
|
4
|
+
const atoms = [];
|
|
5
|
+
let wordFragments = [];
|
|
6
|
+
let wordWidth = 0;
|
|
7
|
+
function flushWord() {
|
|
8
|
+
if (wordFragments.length > 0) {
|
|
9
|
+
atoms.push({
|
|
10
|
+
kind: "box",
|
|
11
|
+
fragments: wordFragments,
|
|
12
|
+
widthPt: wordWidth
|
|
13
|
+
});
|
|
14
|
+
wordFragments = [];
|
|
15
|
+
wordWidth = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const run of runs) {
|
|
19
|
+
const tokens = run.text.match(WORD_OR_WHITESPACE_PATTERN) ?? [];
|
|
20
|
+
for (const token of tokens) if (token === "\n") {
|
|
21
|
+
flushWord();
|
|
22
|
+
atoms.push({
|
|
23
|
+
kind: "break",
|
|
24
|
+
widthPt: 0
|
|
25
|
+
});
|
|
26
|
+
} else if (/^\s+$/.test(token)) {
|
|
27
|
+
flushWord();
|
|
28
|
+
atoms.push({
|
|
29
|
+
kind: "glue",
|
|
30
|
+
widthPt: measurer.widthOfTextAtSize(token, run.font, run.sizePt)
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
wordFragments.push({
|
|
34
|
+
text: token,
|
|
35
|
+
font: run.font,
|
|
36
|
+
sizePt: run.sizePt,
|
|
37
|
+
color: run.color,
|
|
38
|
+
underline: run.underline,
|
|
39
|
+
hyperlink: run.hyperlink,
|
|
40
|
+
sourcePath: run.sourcePath
|
|
41
|
+
});
|
|
42
|
+
wordWidth += measurer.widthOfTextAtSize(token, run.font, run.sizePt);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
flushWord();
|
|
46
|
+
return atoms;
|
|
47
|
+
}
|
|
48
|
+
function fragmentsWidth(fragments, measurer) {
|
|
49
|
+
let total = 0;
|
|
50
|
+
for (const f of fragments) total += measurer.widthOfTextAtSize(f.text, f.font, f.sizePt);
|
|
51
|
+
return total;
|
|
52
|
+
}
|
|
53
|
+
function splitTextToWidth(text, font, sizePt, measurer, maxWidthPt) {
|
|
54
|
+
const chars = Array.from(text);
|
|
55
|
+
let width = 0;
|
|
56
|
+
let splitIndex = 0;
|
|
57
|
+
for (let i = 0; i < chars.length; i++) {
|
|
58
|
+
const charWidth = measurer.widthOfTextAtSize(chars[i], font, sizePt);
|
|
59
|
+
if (width + charWidth > maxWidthPt && splitIndex > 0) break;
|
|
60
|
+
width += charWidth;
|
|
61
|
+
splitIndex = i + 1;
|
|
62
|
+
}
|
|
63
|
+
if (splitIndex === 0 && chars.length > 0) splitIndex = 1;
|
|
64
|
+
return {
|
|
65
|
+
fitText: chars.slice(0, splitIndex).join(""),
|
|
66
|
+
restText: chars.slice(splitIndex).join("")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function splitBoxToWidth(atom, measurer, maxWidthPt) {
|
|
70
|
+
const fitFragments = [];
|
|
71
|
+
let fitWidth = 0;
|
|
72
|
+
for (let idx = 0; idx < atom.fragments.length; idx++) {
|
|
73
|
+
const fragment = atom.fragments[idx];
|
|
74
|
+
const fragmentWidth = measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
75
|
+
if (fitWidth + fragmentWidth <= maxWidthPt) {
|
|
76
|
+
fitFragments.push(fragment);
|
|
77
|
+
fitWidth += fragmentWidth;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const { fitText, restText } = splitTextToWidth(fragment.text, fragment.font, fragment.sizePt, measurer, maxWidthPt - fitWidth);
|
|
81
|
+
if (fitText.length > 0) fitFragments.push({
|
|
82
|
+
...fragment,
|
|
83
|
+
text: fitText
|
|
84
|
+
});
|
|
85
|
+
const restFragments = [];
|
|
86
|
+
if (restText.length > 0) restFragments.push({
|
|
87
|
+
...fragment,
|
|
88
|
+
text: restText
|
|
89
|
+
});
|
|
90
|
+
restFragments.push(...atom.fragments.slice(idx + 1));
|
|
91
|
+
if (restFragments.length === 0) return {
|
|
92
|
+
fit: {
|
|
93
|
+
kind: "box",
|
|
94
|
+
fragments: fitFragments,
|
|
95
|
+
widthPt: fragmentsWidth(fitFragments, measurer)
|
|
96
|
+
},
|
|
97
|
+
rest: void 0
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
fit: {
|
|
101
|
+
kind: "box",
|
|
102
|
+
fragments: fitFragments,
|
|
103
|
+
widthPt: fragmentsWidth(fitFragments, measurer)
|
|
104
|
+
},
|
|
105
|
+
rest: {
|
|
106
|
+
kind: "box",
|
|
107
|
+
fragments: restFragments,
|
|
108
|
+
widthPt: fragmentsWidth(restFragments, measurer)
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
fit: atom,
|
|
114
|
+
rest: void 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function buildLine(atoms, measurer) {
|
|
118
|
+
const fragments = [];
|
|
119
|
+
let xOffsetPt = 0;
|
|
120
|
+
let maxSizePt = 0;
|
|
121
|
+
let ascentPt = 0;
|
|
122
|
+
let descentPt = 0;
|
|
123
|
+
for (const atom of atoms) if (atom.kind === "box") for (const fragment of atom.fragments) {
|
|
124
|
+
fragments.push({
|
|
125
|
+
...fragment,
|
|
126
|
+
xOffsetPt
|
|
127
|
+
});
|
|
128
|
+
xOffsetPt += measurer.widthOfTextAtSize(fragment.text, fragment.font, fragment.sizePt);
|
|
129
|
+
maxSizePt = Math.max(maxSizePt, fragment.sizePt);
|
|
130
|
+
ascentPt = Math.max(ascentPt, measurer.ascenderAtSize(fragment.font, fragment.sizePt));
|
|
131
|
+
descentPt = Math.min(descentPt, measurer.descenderAtSize(fragment.font, fragment.sizePt));
|
|
132
|
+
}
|
|
133
|
+
else xOffsetPt += atom.widthPt;
|
|
134
|
+
return {
|
|
135
|
+
fragments,
|
|
136
|
+
widthPt: xOffsetPt,
|
|
137
|
+
maxSizePt,
|
|
138
|
+
ascentPt,
|
|
139
|
+
descentPt
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function buildEmptyLine(runs, measurer) {
|
|
143
|
+
const first = runs[0];
|
|
144
|
+
if (first === void 0) return {
|
|
145
|
+
fragments: [],
|
|
146
|
+
widthPt: 0,
|
|
147
|
+
maxSizePt: 0,
|
|
148
|
+
ascentPt: 0,
|
|
149
|
+
descentPt: 0
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
fragments: [],
|
|
153
|
+
widthPt: 0,
|
|
154
|
+
maxSizePt: first.sizePt,
|
|
155
|
+
ascentPt: measurer.ascenderAtSize(first.font, first.sizePt),
|
|
156
|
+
descentPt: measurer.descenderAtSize(first.font, first.sizePt)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function wrapRunsToWidth(runs, measurer, maxWidthPt, options = {}) {
|
|
160
|
+
const breakLongWords = options.breakLongWords ?? true;
|
|
161
|
+
if (maxWidthPt <= 0) {
|
|
162
|
+
const atoms = atomizeRuns(runs, measurer).filter((a) => a.kind !== "break");
|
|
163
|
+
return atoms.length === 0 ? [buildEmptyLine(runs, measurer)] : [buildLine(atoms, measurer)];
|
|
164
|
+
}
|
|
165
|
+
const queue = atomizeRuns(runs, measurer);
|
|
166
|
+
const lines = [];
|
|
167
|
+
let current = [];
|
|
168
|
+
let currentWidth = 0;
|
|
169
|
+
function pushLine() {
|
|
170
|
+
while (current.length > 0 && current[current.length - 1]?.kind === "glue") {
|
|
171
|
+
const removed = current.pop();
|
|
172
|
+
currentWidth -= removed?.widthPt ?? 0;
|
|
173
|
+
}
|
|
174
|
+
lines.push(current.length === 0 ? buildEmptyLine(runs, measurer) : buildLine(current, measurer));
|
|
175
|
+
current = [];
|
|
176
|
+
currentWidth = 0;
|
|
177
|
+
}
|
|
178
|
+
let i = 0;
|
|
179
|
+
while (i < queue.length) {
|
|
180
|
+
const atom = queue[i];
|
|
181
|
+
if (atom.kind === "break") {
|
|
182
|
+
pushLine();
|
|
183
|
+
i++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (currentWidth + atom.widthPt <= maxWidthPt) {
|
|
187
|
+
current.push(atom);
|
|
188
|
+
currentWidth += atom.widthPt;
|
|
189
|
+
i++;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (current.length > 0) {
|
|
193
|
+
pushLine();
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (atom.kind === "box" && breakLongWords) {
|
|
197
|
+
const { fit, rest } = splitBoxToWidth(atom, measurer, maxWidthPt);
|
|
198
|
+
current.push(fit);
|
|
199
|
+
currentWidth += fit.widthPt;
|
|
200
|
+
if (rest === void 0) i++;
|
|
201
|
+
else queue[i] = rest;
|
|
202
|
+
pushLine();
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
current.push(atom);
|
|
206
|
+
currentWidth += atom.widthPt;
|
|
207
|
+
i++;
|
|
208
|
+
pushLine();
|
|
209
|
+
}
|
|
210
|
+
if (current.length > 0 || lines.length === 0) pushLine();
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
export { wrapRunsToWidth };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph
|
|
1
|
+
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph--0f7PjzJ.js";
|
|
2
2
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
3
3
|
//#region src/edit/odt/list.d.ts
|
|
4
4
|
declare class OdtListItem {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-
|
|
1
|
+
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-D7324S0j.cjs";
|
|
2
2
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
3
3
|
//#region src/edit/odt/list.d.ts
|
|
4
4
|
declare class OdtListItem {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathBox, MathLayoutItem } from "
|
|
1
|
+
import { MathBox, MathLayoutItem } from "document-schema.js";
|
|
2
2
|
//#region src/mathml/compose.d.ts
|
|
3
3
|
declare const EMPTY_BOX: MathBox;
|
|
4
4
|
declare function shiftItems(items: readonly MathLayoutItem[], dxPt: number, dyPt: number): MathLayoutItem[];
|
package/dist/mathml/compose.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathBox, MathLayoutItem } from "
|
|
1
|
+
import { MathBox, MathLayoutItem } from "document-schema.js";
|
|
2
2
|
//#region src/mathml/compose.d.ts
|
|
3
3
|
declare const EMPTY_BOX: MathBox;
|
|
4
4
|
declare function shiftItems(items: readonly MathLayoutItem[], dxPt: number, dyPt: number): MathLayoutItem[];
|
|
@@ -1,54 +1,5 @@
|
|
|
1
|
+
import { MathBox } from "document-schema.js";
|
|
1
2
|
//#region src/mathml/layout-types.d.ts
|
|
2
|
-
interface MathColor {
|
|
3
|
-
readonly r: number;
|
|
4
|
-
readonly g: number;
|
|
5
|
-
readonly b: number;
|
|
6
|
-
}
|
|
7
|
-
interface MathGlyphRun {
|
|
8
|
-
readonly kind: 'glyphs';
|
|
9
|
-
readonly xPt: number;
|
|
10
|
-
readonly yPt: number;
|
|
11
|
-
readonly text: string;
|
|
12
|
-
readonly sizePt: number;
|
|
13
|
-
readonly color: MathColor;
|
|
14
|
-
}
|
|
15
|
-
interface MathRule {
|
|
16
|
-
readonly kind: 'rule';
|
|
17
|
-
readonly xPt: number;
|
|
18
|
-
readonly yPt: number;
|
|
19
|
-
readonly widthPt: number;
|
|
20
|
-
readonly heightPt: number;
|
|
21
|
-
readonly color: MathColor;
|
|
22
|
-
}
|
|
23
|
-
interface MathStroke {
|
|
24
|
-
readonly kind: 'stroke';
|
|
25
|
-
readonly points: readonly {
|
|
26
|
-
readonly xPt: number;
|
|
27
|
-
readonly yPt: number;
|
|
28
|
-
}[];
|
|
29
|
-
readonly widthPt: number;
|
|
30
|
-
readonly color: MathColor;
|
|
31
|
-
}
|
|
32
|
-
interface MathGlyphPlacement {
|
|
33
|
-
readonly glyphId: number;
|
|
34
|
-
readonly xPt: number;
|
|
35
|
-
readonly yPt: number;
|
|
36
|
-
}
|
|
37
|
-
interface MathAssembledGlyphs {
|
|
38
|
-
readonly kind: 'assembled-glyphs';
|
|
39
|
-
readonly placements: readonly MathGlyphPlacement[];
|
|
40
|
-
readonly text: string;
|
|
41
|
-
readonly sizePt: number;
|
|
42
|
-
readonly color: MathColor;
|
|
43
|
-
}
|
|
44
|
-
type MathLayoutItem = MathGlyphRun | MathRule | MathStroke | MathAssembledGlyphs;
|
|
45
|
-
interface MathBox {
|
|
46
|
-
readonly widthPt: number;
|
|
47
|
-
readonly heightPt: number;
|
|
48
|
-
readonly ascentPt: number;
|
|
49
|
-
readonly descentPt: number;
|
|
50
|
-
readonly items: readonly MathLayoutItem[];
|
|
51
|
-
}
|
|
52
3
|
type MathDiagnosticKind = 'unsupported-element' | 'missing-glyph';
|
|
53
4
|
interface MathDiagnostic {
|
|
54
5
|
readonly kind: MathDiagnosticKind;
|
|
@@ -59,4 +10,4 @@ interface MathLayoutResult {
|
|
|
59
10
|
readonly diagnostics: readonly MathDiagnostic[];
|
|
60
11
|
}
|
|
61
12
|
//#endregion
|
|
62
|
-
export {
|
|
13
|
+
export { MathDiagnostic, MathDiagnosticKind, MathLayoutResult };
|
|
@@ -1,54 +1,5 @@
|
|
|
1
|
+
import { MathBox } from "document-schema.js";
|
|
1
2
|
//#region src/mathml/layout-types.d.ts
|
|
2
|
-
interface MathColor {
|
|
3
|
-
readonly r: number;
|
|
4
|
-
readonly g: number;
|
|
5
|
-
readonly b: number;
|
|
6
|
-
}
|
|
7
|
-
interface MathGlyphRun {
|
|
8
|
-
readonly kind: 'glyphs';
|
|
9
|
-
readonly xPt: number;
|
|
10
|
-
readonly yPt: number;
|
|
11
|
-
readonly text: string;
|
|
12
|
-
readonly sizePt: number;
|
|
13
|
-
readonly color: MathColor;
|
|
14
|
-
}
|
|
15
|
-
interface MathRule {
|
|
16
|
-
readonly kind: 'rule';
|
|
17
|
-
readonly xPt: number;
|
|
18
|
-
readonly yPt: number;
|
|
19
|
-
readonly widthPt: number;
|
|
20
|
-
readonly heightPt: number;
|
|
21
|
-
readonly color: MathColor;
|
|
22
|
-
}
|
|
23
|
-
interface MathStroke {
|
|
24
|
-
readonly kind: 'stroke';
|
|
25
|
-
readonly points: readonly {
|
|
26
|
-
readonly xPt: number;
|
|
27
|
-
readonly yPt: number;
|
|
28
|
-
}[];
|
|
29
|
-
readonly widthPt: number;
|
|
30
|
-
readonly color: MathColor;
|
|
31
|
-
}
|
|
32
|
-
interface MathGlyphPlacement {
|
|
33
|
-
readonly glyphId: number;
|
|
34
|
-
readonly xPt: number;
|
|
35
|
-
readonly yPt: number;
|
|
36
|
-
}
|
|
37
|
-
interface MathAssembledGlyphs {
|
|
38
|
-
readonly kind: 'assembled-glyphs';
|
|
39
|
-
readonly placements: readonly MathGlyphPlacement[];
|
|
40
|
-
readonly text: string;
|
|
41
|
-
readonly sizePt: number;
|
|
42
|
-
readonly color: MathColor;
|
|
43
|
-
}
|
|
44
|
-
type MathLayoutItem = MathGlyphRun | MathRule | MathStroke | MathAssembledGlyphs;
|
|
45
|
-
interface MathBox {
|
|
46
|
-
readonly widthPt: number;
|
|
47
|
-
readonly heightPt: number;
|
|
48
|
-
readonly ascentPt: number;
|
|
49
|
-
readonly descentPt: number;
|
|
50
|
-
readonly items: readonly MathLayoutItem[];
|
|
51
|
-
}
|
|
52
3
|
type MathDiagnosticKind = 'unsupported-element' | 'missing-glyph';
|
|
53
4
|
interface MathDiagnostic {
|
|
54
5
|
readonly kind: MathDiagnosticKind;
|
|
@@ -59,4 +10,4 @@ interface MathLayoutResult {
|
|
|
59
10
|
readonly diagnostics: readonly MathDiagnostic[];
|
|
60
11
|
}
|
|
61
12
|
//#endregion
|
|
62
|
-
export {
|
|
13
|
+
export { MathDiagnostic, MathDiagnosticKind, MathLayoutResult };
|
package/dist/mathml/layout.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as MathVariant } from "../variant-BMrebjMw.cjs";
|
|
2
|
-
import { r as MathMlNode } from "../nodes-pArN9ilm.cjs";
|
|
3
|
-
import {
|
|
4
|
-
import { MathFontMetrics } from "
|
|
2
|
+
import { r as MathMlNode$1 } from "../nodes-pArN9ilm.cjs";
|
|
3
|
+
import { MathDiagnostic, MathLayoutResult } from "./layout-types.cjs";
|
|
4
|
+
import { MathBox, MathColor, MathFontMetrics } from "document-schema.js";
|
|
5
5
|
//#region src/mathml/layout.d.ts
|
|
6
6
|
interface LayoutFormulaOptions {
|
|
7
7
|
readonly metrics: MathFontMetrics;
|
|
@@ -18,7 +18,7 @@ interface LayoutContext {
|
|
|
18
18
|
readonly scriptLevel: number;
|
|
19
19
|
readonly diagnostics: MathDiagnostic[];
|
|
20
20
|
}
|
|
21
|
-
declare function layoutNode(node: MathMlNode, ctx: LayoutContext): MathBox;
|
|
22
|
-
declare function layoutFormula(mathml: readonly MathMlNode[], options: LayoutFormulaOptions): MathLayoutResult;
|
|
21
|
+
declare function layoutNode(node: MathMlNode$1, ctx: LayoutContext): MathBox;
|
|
22
|
+
declare function layoutFormula(mathml: readonly MathMlNode$1[], options: LayoutFormulaOptions): MathLayoutResult;
|
|
23
23
|
//#endregion
|
|
24
24
|
export { LayoutFormulaOptions, layoutFormula, layoutNode };
|
package/dist/mathml/layout.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as MathVariant } from "../variant-BMrebjMw.js";
|
|
2
|
-
import { r as MathMlNode } from "../nodes-pArN9ilm.js";
|
|
3
|
-
import {
|
|
4
|
-
import { MathFontMetrics } from "
|
|
2
|
+
import { r as MathMlNode$1 } from "../nodes-pArN9ilm.js";
|
|
3
|
+
import { MathDiagnostic, MathLayoutResult } from "./layout-types.js";
|
|
4
|
+
import { MathBox, MathColor, MathFontMetrics } from "document-schema.js";
|
|
5
5
|
//#region src/mathml/layout.d.ts
|
|
6
6
|
interface LayoutFormulaOptions {
|
|
7
7
|
readonly metrics: MathFontMetrics;
|
|
@@ -18,7 +18,7 @@ interface LayoutContext {
|
|
|
18
18
|
readonly scriptLevel: number;
|
|
19
19
|
readonly diagnostics: MathDiagnostic[];
|
|
20
20
|
}
|
|
21
|
-
declare function layoutNode(node: MathMlNode, ctx: LayoutContext): MathBox;
|
|
22
|
-
declare function layoutFormula(mathml: readonly MathMlNode[], options: LayoutFormulaOptions): MathLayoutResult;
|
|
21
|
+
declare function layoutNode(node: MathMlNode$1, ctx: LayoutContext): MathBox;
|
|
22
|
+
declare function layoutFormula(mathml: readonly MathMlNode$1[], options: LayoutFormulaOptions): MathLayoutResult;
|
|
23
23
|
//#endregion
|
|
24
24
|
export { LayoutFormulaOptions, layoutFormula, layoutNode };
|
package/dist/mathml/radical.d.ts
CHANGED
package/dist/model/geometry.cjs
CHANGED
|
@@ -9,6 +9,17 @@ function flipY(box, containerHeightPt) {
|
|
|
9
9
|
heightPt: box.heightPt
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
function rotatePointAboutCenter(point, center, degrees) {
|
|
13
|
+
const radians = degrees * Math.PI / 180;
|
|
14
|
+
const cos = Math.cos(radians);
|
|
15
|
+
const sin = Math.sin(radians);
|
|
16
|
+
const dx = point.x - center.x;
|
|
17
|
+
const dy = point.y - center.y;
|
|
18
|
+
return {
|
|
19
|
+
x: center.x + dx * cos - dy * sin,
|
|
20
|
+
y: center.y + dx * sin + dy * cos
|
|
21
|
+
};
|
|
22
|
+
}
|
|
12
23
|
//#endregion
|
|
13
24
|
Object.defineProperty(exports, "BoxSchema", {
|
|
14
25
|
enumerable: true,
|
|
@@ -53,3 +64,4 @@ Object.defineProperty(exports, "SLIDE_SIZE_WIDESCREEN", {
|
|
|
53
64
|
}
|
|
54
65
|
});
|
|
55
66
|
exports.flipY = flipY;
|
|
67
|
+
exports.rotatePointAboutCenter = rotatePointAboutCenter;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PAGE_SIZE_A4, c as PageSizeSchema, d as flipY, i as MarginsSchema, l as
|
|
2
|
-
export { type Box, BoxSchema, type Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type PageSize, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY };
|
|
1
|
+
import { a as PAGE_SIZE_A4, c as PageSizeSchema, d as SLIDE_SIZE_WIDESCREEN, f as flipY, i as MarginsSchema, l as Point, n as BoxSchema, o as PAGE_SIZE_LETTER, p as rotatePointAboutCenter, r as Margins, s as PageSize, t as Box, u as SLIDE_SIZE_STANDARD } from "../geometry-DUF273hM.cjs";
|
|
2
|
+
export { type Box, BoxSchema, type Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type PageSize, PageSizeSchema, type Point, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY, rotatePointAboutCenter };
|
package/dist/model/geometry.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PAGE_SIZE_A4, c as PageSizeSchema, d as flipY, i as MarginsSchema, l as
|
|
2
|
-
export { type Box, BoxSchema, type Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type PageSize, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY };
|
|
1
|
+
import { a as PAGE_SIZE_A4, c as PageSizeSchema, d as SLIDE_SIZE_WIDESCREEN, f as flipY, i as MarginsSchema, l as Point, n as BoxSchema, o as PAGE_SIZE_LETTER, p as rotatePointAboutCenter, r as Margins, s as PageSize, t as Box, u as SLIDE_SIZE_STANDARD } from "../geometry-DUF273hM.js";
|
|
2
|
+
export { type Box, BoxSchema, type Margins, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, type PageSize, PageSizeSchema, type Point, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY, rotatePointAboutCenter };
|