js.documents 1.91.4 → 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/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/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 +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/layout/drawing.cjs +1 -2
- package/dist/layout/drawing.js +1 -2
- package/dist/layout/engine.cjs +3 -2
- package/dist/layout/engine.js +2 -1
- package/dist/layout/shared.cjs +2 -1
- package/dist/layout/shared.js +2 -1
- package/dist/layout/sheets.cjs +3 -2
- package/dist/layout/sheets.js +2 -1
- package/dist/layout/slides.cjs +3 -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/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/{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/layout/sheets.js
CHANGED
|
@@ -2,10 +2,11 @@ import { flipY } from "../model/geometry.js";
|
|
|
2
2
|
import { COLOR_BLACK as COLOR_BLACK$1, rgbHexToColor as rgbHexToColor$1 } from "../model/color.js";
|
|
3
3
|
import { DEFAULT_LAYOUT_FONT } from "../model/style.js";
|
|
4
4
|
import { layoutFormula } from "../mathml/layout.js";
|
|
5
|
+
import { wrapRunsToWidth } from "./text-layout.js";
|
|
5
6
|
import { alignmentOffsetPt, formulaSizePtForFrame, justifyLineGapsPt, lineNaturalHeightPt, pushCellBorderLines, registerImage, sumColumnWidthsPt, toStyledRuns } from "./shared.js";
|
|
6
7
|
import { throwIfAborted } from "../ports/abort.js";
|
|
7
8
|
import { LAYOUT_FORMAT_VERSION } from "document-schema.js";
|
|
8
|
-
import { loadMathFont
|
|
9
|
+
import { loadMathFont } from "pdf-codec";
|
|
9
10
|
//#region src/layout/sheets.ts
|
|
10
11
|
function anchoredFormulas(sheet) {
|
|
11
12
|
const resolved = [];
|
package/dist/layout/slides.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_model_geometry = require("../model/geometry.cjs");
|
|
3
3
|
const require_model_formula = require("../model/formula.cjs");
|
|
4
4
|
const require_mathml_layout = require("../mathml/layout.cjs");
|
|
5
|
+
const require_layout_text_layout = require("./text-layout.cjs");
|
|
5
6
|
const require_layout_shared = require("./shared.cjs");
|
|
6
7
|
let document_schema_js = require("document-schema.js");
|
|
7
8
|
let pdf_codec = require("pdf-codec");
|
|
@@ -17,7 +18,7 @@ function shapePlacement(flippedFrame, rotationDeg) {
|
|
|
17
18
|
y: flippedFrame.yPt + flippedFrame.heightPt / 2
|
|
18
19
|
};
|
|
19
20
|
return {
|
|
20
|
-
place: (p) =>
|
|
21
|
+
place: (p) => require_model_geometry.rotatePointAboutCenter(p, center, ccwDeg),
|
|
21
22
|
layoutRotationDeg: ccwDeg
|
|
22
23
|
};
|
|
23
24
|
}
|
|
@@ -27,7 +28,7 @@ function layoutParagraph(paragraph, contentLeftXDown, contentWidthPt, startYDown
|
|
|
27
28
|
const fallbackRun = effectiveRuns[0];
|
|
28
29
|
const paragraphLeftXDown = contentLeftXDown + (paragraph.indentLeftPt ?? 0);
|
|
29
30
|
const paragraphWidthPt = Math.max(0, contentWidthPt - (paragraph.indentLeftPt ?? 0));
|
|
30
|
-
const lines =
|
|
31
|
+
const lines = require_layout_text_layout.wrapRunsToWidth(effectiveRuns, measurer, paragraphWidthPt);
|
|
31
32
|
lines.forEach((line, lineIndex) => {
|
|
32
33
|
const scaledLineHeightPt = require_layout_shared.lineNaturalHeightPt(line, measurer, fallbackRun) * (paragraph.lineSpacing ?? 1) * spacingScale;
|
|
33
34
|
const baselineYDown = cursorYDown + line.ascentPt;
|
package/dist/layout/slides.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { flipY } from "../model/geometry.js";
|
|
1
|
+
import { flipY, rotatePointAboutCenter } from "../model/geometry.js";
|
|
2
2
|
import { formulaOfBlock } from "../model/formula.js";
|
|
3
3
|
import { layoutFormula } from "../mathml/layout.js";
|
|
4
|
+
import { wrapRunsToWidth } from "./text-layout.js";
|
|
4
5
|
import { alignmentOffsetPt, effectiveStyledRuns, estimateRowHeightPt, formulaSizePtForFrame, justifyLineGapsPt, lineNaturalHeightPt, registerImage, sumColumnWidthsPt } from "./shared.js";
|
|
5
6
|
import { COLOR_BLACK, LAYOUT_FORMAT_VERSION } from "document-schema.js";
|
|
6
|
-
import { loadMathFont
|
|
7
|
+
import { loadMathFont } from "pdf-codec";
|
|
7
8
|
//#region src/layout/slides.ts
|
|
8
9
|
function shapePlacement(flippedFrame, rotationDeg) {
|
|
9
10
|
if (rotationDeg === void 0 || rotationDeg === 0) return {
|
|
@@ -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 {
|
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 };
|
package/dist/model/geometry.js
CHANGED
|
@@ -8,5 +8,16 @@ function flipY(box, containerHeightPt) {
|
|
|
8
8
|
heightPt: box.heightPt
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
function rotatePointAboutCenter(point, center, degrees) {
|
|
12
|
+
const radians = degrees * Math.PI / 180;
|
|
13
|
+
const cos = Math.cos(radians);
|
|
14
|
+
const sin = Math.sin(radians);
|
|
15
|
+
const dx = point.x - center.x;
|
|
16
|
+
const dy = point.y - center.y;
|
|
17
|
+
return {
|
|
18
|
+
x: center.x + dx * cos - dy * sin,
|
|
19
|
+
y: center.y + dx * sin + dy * cos
|
|
20
|
+
};
|
|
21
|
+
}
|
|
11
22
|
//#endregion
|
|
12
|
-
export { BoxSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY };
|
|
23
|
+
export { BoxSchema, MarginsSchema, PAGE_SIZE_A4, PAGE_SIZE_LETTER, PageSizeSchema, SLIDE_SIZE_STANDARD, SLIDE_SIZE_WIDESCREEN, flipY, rotatePointAboutCenter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Box } from "../../geometry-
|
|
1
|
+
import { t as Box } from "../../geometry-DUF273hM.cjs";
|
|
2
2
|
import { XmlElement } from "odf.js";
|
|
3
3
|
//#region src/odf/shared/flow-anchor.d.ts
|
|
4
4
|
declare function flowAnchoredFrameBox(frame: XmlElement): Box | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Alignment } from "./style-DkamR3aY.js";
|
|
2
|
-
import { t as ImageInit } from "./image-
|
|
2
|
+
import { t as ImageInit } from "./image-BFn8Rm6P.js";
|
|
3
3
|
import { n as RunInit, t as OdtRun } from "./run-SLSPO-4y.js";
|
|
4
4
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
5
5
|
//#region src/edit/odt/paragraph.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Alignment } from "./style-DkamR3aY.cjs";
|
|
2
|
-
import { t as ImageInit } from "./image-
|
|
2
|
+
import { t as ImageInit } from "./image-K3MAhLJc.cjs";
|
|
3
3
|
import { n as RunInit, t as OdtRun } from "./run-DQtEGilU.cjs";
|
|
4
4
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
5
5
|
//#region src/edit/odt/paragraph.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Box } from "./geometry-
|
|
2
|
-
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-
|
|
3
|
-
import { t as OdtList } from "./list-
|
|
1
|
+
import { t as Box } from "./geometry-DUF273hM.cjs";
|
|
2
|
+
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-D7324S0j.cjs";
|
|
3
|
+
import { t as OdtList } from "./list-MCxkKpI7.cjs";
|
|
4
4
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
5
5
|
//#region src/edit/odp/shape.d.ts
|
|
6
6
|
declare class OdpShape {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as LayoutColor } from "./color-BHhGSqAh.js";
|
|
2
|
-
import { t as Box } from "./geometry-
|
|
2
|
+
import { t as Box } from "./geometry-DUF273hM.js";
|
|
3
3
|
import { t as Alignment } from "./style-DkamR3aY.js";
|
|
4
4
|
import { XmlElement, XmlNode } from "ooxml.js";
|
|
5
5
|
//#region src/edit/pptx/shape.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as LayoutColor } from "./color-71eoF1Up.cjs";
|
|
2
|
-
import { t as Box } from "./geometry-
|
|
2
|
+
import { t as Box } from "./geometry-DUF273hM.cjs";
|
|
3
3
|
import { t as Alignment } from "./style-DkamR3aY.cjs";
|
|
4
4
|
import { XmlElement, XmlNode } from "ooxml.js";
|
|
5
5
|
//#region src/edit/pptx/shape.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Box } from "./geometry-
|
|
2
|
-
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph
|
|
3
|
-
import { t as OdtList } from "./list-
|
|
1
|
+
import { t as Box } from "./geometry-DUF273hM.js";
|
|
2
|
+
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph--0f7PjzJ.js";
|
|
3
|
+
import { t as OdtList } from "./list-CSIIzXAV.js";
|
|
4
4
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
5
5
|
//#region src/edit/odp/shape.d.ts
|
|
6
6
|
declare class OdpShape {
|
|
@@ -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 { Color, ContentCellBorders } from "document-schema.js";
|
|
3
3
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
4
4
|
//#region src/edit/odt/table.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as Box$1 } from "./geometry-
|
|
2
|
-
import { t as DrawingParagraphInit } from "./shape-
|
|
1
|
+
import { t as Box$1 } from "./geometry-DUF273hM.js";
|
|
2
|
+
import { t as DrawingParagraphInit } from "./shape-CnYhKn5U.js";
|
|
3
3
|
import { XmlElement } from "ooxml.js";
|
|
4
4
|
import { Color, ContentCellBorders } from "document-schema.js";
|
|
5
5
|
//#region src/edit/pptx/table.d.ts
|