js.documents 14.4.56 → 14.4.57
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/codecs/read.cjs +2 -2
- package/dist/codecs/read.js +1 -1
- package/dist/composition-plan-CfvhXeOC.cjs +627 -0
- package/dist/composition-plan-DU9nPPN7.d.cts +102 -0
- package/dist/composition-plan-f0zaExUW.js +508 -0
- package/dist/composition-plan-l6QPO4FX.d.ts +102 -0
- package/dist/convert/composition-plan.cjs +7 -0
- package/dist/convert/composition-plan.d.cts +2 -0
- package/dist/convert/composition-plan.d.ts +2 -0
- package/dist/convert/composition-plan.js +2 -0
- package/dist/convert/composition-to-pdf.cjs +12 -12
- package/dist/convert/composition-to-pdf.d.cts +1 -1
- package/dist/convert/composition-to-pdf.d.ts +1 -1
- package/dist/convert/composition-to-pdf.js +2 -2
- package/dist/convert/composition.cjs +16 -511
- package/dist/convert/composition.d.cts +2 -85
- package/dist/convert/composition.d.ts +2 -85
- package/dist/convert/composition.js +2 -502
- package/dist/convert/convert.cjs +2 -2
- package/dist/convert/convert.js +1 -1
- package/dist/convert/from-package.cjs +3 -3
- package/dist/convert/from-package.js +2 -2
- package/dist/convert/from-pdf.cjs +18 -18
- package/dist/convert/from-pdf.js +2 -2
- package/dist/convert/local.cjs +3 -3
- package/dist/convert/local.js +1 -1
- package/dist/edit/odp/slide.cjs +4 -4
- package/dist/edit/odp/slide.d.cts +1 -1
- package/dist/edit/odp/slide.d.ts +1 -1
- package/dist/edit/odp/slide.js +1 -1
- package/dist/edit/odt/content.d.cts +1 -1
- package/dist/edit/odt/content.d.ts +1 -1
- package/dist/edit/odt/editor.cjs +4 -4
- package/dist/edit/odt/editor.d.cts +1 -1
- package/dist/edit/odt/editor.d.ts +1 -1
- package/dist/edit/odt/editor.js +1 -1
- package/dist/edit/odt/table-grid.cjs +23 -0
- package/dist/edit/odt/table-grid.d.cts +54 -0
- package/dist/edit/odt/table-grid.d.ts +54 -0
- package/dist/edit/odt/table-grid.js +2 -0
- package/dist/edit/odt/table.cjs +12 -653
- package/dist/edit/odt/table.d.cts +2 -2
- package/dist/edit/odt/table.d.ts +2 -2
- package/dist/edit/odt/table.js +2 -647
- package/dist/{evaluate-BbOsgdmN.d.cts → evaluate-BSEUxiUK.d.cts} +3 -1
- package/dist/evaluate-CEzsBx3w.cjs +564 -0
- package/dist/{evaluate-C7fmk69X.d.ts → evaluate-D8fG2ZeB.d.ts} +3 -1
- package/dist/evaluate-IK-3aMv5.js +445 -0
- package/dist/evaluate-columns-CyqKHkIW.d.cts +41 -0
- package/dist/evaluate-columns-cOo8fOfT.d.ts +41 -0
- package/dist/index.cjs +24 -24
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +8 -8
- package/dist/latex/lint.cjs +2 -2
- package/dist/latex/lint.js +1 -1
- package/dist/latex/lower-fold.cjs +6 -0
- package/dist/latex/lower-fold.d.cts +17 -0
- package/dist/latex/lower-fold.d.ts +17 -0
- package/dist/latex/lower-fold.js +2 -0
- package/dist/latex/lower.cjs +11 -617
- package/dist/latex/lower.d.cts +18 -1
- package/dist/latex/lower.d.ts +18 -1
- package/dist/latex/lower.js +2 -616
- package/dist/latex/symbols.d.cts +1 -15
- package/dist/latex/symbols.d.ts +1 -15
- package/dist/latex/temml.d.cts +1 -24
- package/dist/latex/temml.d.ts +1 -24
- package/dist/layout/engine.cjs +2 -2
- package/dist/layout/engine.js +1 -1
- package/dist/layout/reconstruct-lines.cjs +315 -0
- package/dist/layout/reconstruct-lines.d.cts +2 -0
- package/dist/layout/reconstruct-lines.d.ts +2 -0
- package/dist/layout/reconstruct-lines.js +297 -0
- package/dist/layout/reconstruct-presentations-prod.cjs +9 -0
- package/dist/layout/reconstruct-presentations-prod.d.cts +26 -0
- package/dist/layout/reconstruct-presentations-prod.d.ts +26 -0
- package/dist/layout/reconstruct-presentations-prod.js +2 -0
- package/dist/layout/reconstruct-tables.cjs +5 -0
- package/dist/layout/reconstruct-tables.d.cts +22 -0
- package/dist/layout/reconstruct-tables.d.ts +22 -0
- package/dist/layout/reconstruct-tables.js +2 -0
- package/dist/layout/reconstruct.cjs +11 -1545
- package/dist/layout/reconstruct.d.cts +2 -14
- package/dist/layout/reconstruct.d.ts +2 -14
- package/dist/layout/reconstruct.js +2 -1542
- package/dist/layout/shared.cjs +2 -2
- package/dist/layout/shared.js +1 -1
- package/dist/layout/sheets-render.cjs +19 -0
- package/dist/layout/sheets-render.d.cts +41 -0
- package/dist/layout/sheets-render.d.ts +41 -0
- package/dist/layout/sheets-render.js +2 -0
- package/dist/layout/sheets.cjs +10 -544
- package/dist/layout/sheets.d.cts +13 -2
- package/dist/layout/sheets.d.ts +13 -2
- package/dist/layout/sheets.js +2 -543
- package/dist/layout/slides.cjs +2 -2
- package/dist/layout/slides.js +1 -1
- package/dist/layout-DIJzJk4x.js +526 -0
- package/dist/layout-iuiyl_Fk.cjs +621 -0
- package/dist/layout-types-oSbHvZid.d.cts +13 -0
- package/dist/layout-types-oSbHvZid.d.ts +13 -0
- package/dist/lower-DCs3rWI7.js +618 -0
- package/dist/lower-DzOb13w4.cjs +701 -0
- package/dist/markdown/math.cjs +2 -2
- package/dist/markdown/math.js +1 -1
- package/dist/mathml/layout-stretch.cjs +16 -0
- package/dist/mathml/layout-stretch.d.cts +24 -0
- package/dist/mathml/layout-stretch.d.ts +24 -0
- package/dist/mathml/layout-stretch.js +2 -0
- package/dist/mathml/layout-types.d.cts +1 -12
- package/dist/mathml/layout-types.d.ts +1 -12
- package/dist/mathml/layout.cjs +3 -525
- package/dist/mathml/layout.d.cts +2 -2
- package/dist/mathml/layout.d.ts +2 -2
- package/dist/mathml/layout.js +1 -523
- package/dist/odb/formula/evaluate.d.cts +1 -1
- package/dist/odb/formula/evaluate.d.ts +1 -1
- package/dist/odb/report/render.d.cts +1 -1
- package/dist/odb/report/render.d.ts +1 -1
- package/dist/odb/report/source.cjs +2 -2
- package/dist/odb/report/source.d.cts +1 -1
- package/dist/odb/report/source.d.ts +1 -1
- package/dist/odb/report/source.js +1 -1
- package/dist/odb/sql/evaluate-columns.cjs +122 -0
- package/dist/odb/sql/evaluate-columns.d.cts +2 -0
- package/dist/odb/sql/evaluate-columns.d.ts +2 -0
- package/dist/odb/sql/evaluate-columns.js +114 -0
- package/dist/odb/sql/evaluate-predicates.cjs +16 -0
- package/dist/odb/sql/evaluate-predicates.d.cts +23 -0
- package/dist/odb/sql/evaluate-predicates.d.ts +23 -0
- package/dist/odb/sql/evaluate-predicates.js +2 -0
- package/dist/odb/sql/evaluate.cjs +7 -556
- package/dist/odb/sql/evaluate.d.cts +2 -2
- package/dist/odb/sql/evaluate.d.ts +2 -2
- package/dist/odb/sql/evaluate.js +2 -552
- package/dist/read-BSH--XB4.js +682 -0
- package/dist/read-CahCZMwG.cjs +759 -0
- package/dist/reconstruct-BKOCAedo.d.ts +29 -0
- package/dist/reconstruct-D4TEteZ6.d.cts +29 -0
- package/dist/reconstruct-lines-B7t66ICm.d.cts +33 -0
- package/dist/reconstruct-lines-B7t66ICm.d.ts +33 -0
- package/dist/reconstruct-presentations-prod-B5fkPiRZ.js +1256 -0
- package/dist/reconstruct-presentations-prod-X315aBmI.cjs +1375 -0
- package/dist/sheets-BQCpNXsE.cjs +700 -0
- package/dist/sheets-DWDvGN-g.js +545 -0
- package/dist/svg/read-geometry.cjs +10 -0
- package/dist/svg/read-geometry.d.cts +24 -0
- package/dist/svg/read-geometry.d.ts +24 -0
- package/dist/svg/read-geometry.js +2 -0
- package/dist/svg/read.cjs +6 -680
- package/dist/svg/read.d.cts +17 -2
- package/dist/svg/read.d.ts +17 -2
- package/dist/svg/read.js +2 -679
- package/dist/symbols-BlzXfLEe.d.cts +16 -0
- package/dist/symbols-CKm2r4D0.d.ts +16 -0
- package/dist/table-B5gSMY7w.js +649 -0
- package/dist/{table-DrE6jEWv.d.cts → table-BK_Ao-Y6.d.cts} +9 -1
- package/dist/{table-B5htMG3g.d.ts → table-CxY85YUj.d.ts} +9 -1
- package/dist/table-DqUIOSPV.cjs +840 -0
- package/dist/temml-1-I9N9DD.d.cts +25 -0
- package/dist/temml-1-I9N9DD.d.ts +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
import { parseMathLength } from "./mathml/length.js";
|
|
2
|
+
import { attrValue, elementChildren, elementLocalName, isMathMlElement, textContent } from "./mathml/nodes.js";
|
|
3
|
+
import { operatorProperties } from "./mathml/operators.js";
|
|
4
|
+
import { applyMathVariant, isMathVariant } from "./mathml/variant.js";
|
|
5
|
+
import { EMPTY_BOX, concatBoxesHorizontally, placeChild, shiftItems } from "./mathml/compose.js";
|
|
6
|
+
import { buildRadicalSign } from "./mathml/radical.js";
|
|
7
|
+
//#region src/mathml/layout-stretch.ts
|
|
8
|
+
function isStretchyOperator(element) {
|
|
9
|
+
if (elementLocalName(element) !== "mo") return false;
|
|
10
|
+
if (attrValue(element, "stretchy") === "false") return false;
|
|
11
|
+
return operatorProperties(textContent(element).trim()).stretchy;
|
|
12
|
+
}
|
|
13
|
+
function singleCodePoint(text) {
|
|
14
|
+
const codePoints = [...text];
|
|
15
|
+
return codePoints.length === 1 ? codePoints[0]?.codePointAt(0) : void 0;
|
|
16
|
+
}
|
|
17
|
+
function stretchedBox(result, text, ctx) {
|
|
18
|
+
const axisPt = ctx.metrics.axisHeightPt;
|
|
19
|
+
const inkHeightPt = result.inkAscentPt + result.inkDescentPt;
|
|
20
|
+
const originAboveBaselinePt = axisPt - (result.inkAscentPt - result.inkDescentPt) / 2;
|
|
21
|
+
const ascentPt = axisPt + inkHeightPt / 2;
|
|
22
|
+
const descentPt = inkHeightPt / 2 - axisPt;
|
|
23
|
+
const items = [{
|
|
24
|
+
kind: "assembled-glyphs",
|
|
25
|
+
placements: result.placements.map((placement) => ({
|
|
26
|
+
glyphId: placement.glyphId,
|
|
27
|
+
xPt: 0,
|
|
28
|
+
yPt: ascentPt - originAboveBaselinePt - placement.offsetPt
|
|
29
|
+
})),
|
|
30
|
+
text,
|
|
31
|
+
sizePt: ctx.sizePt,
|
|
32
|
+
color: ctx.color
|
|
33
|
+
}];
|
|
34
|
+
return {
|
|
35
|
+
widthPt: result.advanceWidthPt,
|
|
36
|
+
ascentPt,
|
|
37
|
+
descentPt,
|
|
38
|
+
heightPt: ascentPt + descentPt,
|
|
39
|
+
items
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function stretchOperator(element, targetSizePt, ctx) {
|
|
43
|
+
const text = textContent(element).trim();
|
|
44
|
+
const codePoint = singleCodePoint(text);
|
|
45
|
+
if (codePoint === void 0) return;
|
|
46
|
+
const result = ctx.metrics.stretch(codePoint, "vertical", targetSizePt, ctx.sizePt);
|
|
47
|
+
if (result === void 0 || result.kind === "base") return;
|
|
48
|
+
return stretchedBox(result, text, ctx);
|
|
49
|
+
}
|
|
50
|
+
function horizontallyStretchedBox(result, text, ctx) {
|
|
51
|
+
const ascentPt = result.inkAscentPt;
|
|
52
|
+
const descentPt = result.inkDescentPt;
|
|
53
|
+
const items = [{
|
|
54
|
+
kind: "assembled-glyphs",
|
|
55
|
+
placements: result.placements.map((placement) => ({
|
|
56
|
+
glyphId: placement.glyphId,
|
|
57
|
+
xPt: placement.offsetPt,
|
|
58
|
+
yPt: ascentPt
|
|
59
|
+
})),
|
|
60
|
+
text,
|
|
61
|
+
sizePt: ctx.sizePt,
|
|
62
|
+
color: ctx.color
|
|
63
|
+
}];
|
|
64
|
+
return {
|
|
65
|
+
widthPt: result.sizePt,
|
|
66
|
+
ascentPt,
|
|
67
|
+
descentPt,
|
|
68
|
+
heightPt: ascentPt + descentPt,
|
|
69
|
+
items
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function stretchHorizontalOperator(element, targetWidthPt, ctx) {
|
|
73
|
+
const text = textContent(element).trim();
|
|
74
|
+
const codePoint = singleCodePoint(text);
|
|
75
|
+
if (codePoint === void 0) return;
|
|
76
|
+
const result = ctx.metrics.stretch(codePoint, "horizontal", targetWidthPt, ctx.sizePt);
|
|
77
|
+
if (result === void 0 || result.kind === "base") return;
|
|
78
|
+
return horizontallyStretchedBox(result, text, ctx);
|
|
79
|
+
}
|
|
80
|
+
function layoutUnderOverChild(childElement, targetWidthPt, scriptCtx) {
|
|
81
|
+
if (isStretchyOperator(childElement)) {
|
|
82
|
+
const stretched = stretchHorizontalOperator(childElement, targetWidthPt, scriptCtx);
|
|
83
|
+
if (stretched !== void 0) return stretched;
|
|
84
|
+
}
|
|
85
|
+
return layoutNode(childElement, scriptCtx);
|
|
86
|
+
}
|
|
87
|
+
function stretchRowOperators(children, boxes, ctx) {
|
|
88
|
+
const stretchy = children.map(isStretchyOperator);
|
|
89
|
+
const others = boxes.filter((_, index) => stretchy[index] !== true);
|
|
90
|
+
if (others.length === 0) return boxes;
|
|
91
|
+
const axisPt = ctx.metrics.axisHeightPt;
|
|
92
|
+
const maxAscentPt = others.reduce((max, box) => Math.max(max, box.ascentPt), 0);
|
|
93
|
+
const maxDescentPt = others.reduce((max, box) => Math.max(max, box.descentPt), 0);
|
|
94
|
+
const targetSizePt = 2 * Math.max(maxAscentPt - axisPt, maxDescentPt + axisPt);
|
|
95
|
+
return boxes.map((box, index) => {
|
|
96
|
+
if (stretchy[index] !== true) return box;
|
|
97
|
+
const element = children[index];
|
|
98
|
+
return (element === void 0 ? void 0 : stretchOperator(element, targetSizePt, ctx)) ?? box;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function layoutRowChildren(children, ctx) {
|
|
102
|
+
const boxes = stretchRowOperators(children, children.map((child) => layoutNode(child, ctx)), ctx);
|
|
103
|
+
const gapsPt = [];
|
|
104
|
+
let carriedRspaceEm = 0;
|
|
105
|
+
for (const [index, child] of children.entries()) {
|
|
106
|
+
const properties = elementLocalName(child) === "mo" ? operatorProperties(textContent(child).trim()) : void 0;
|
|
107
|
+
const gapEm = index === 0 ? 0 : carriedRspaceEm + (properties?.lspaceEm ?? 0);
|
|
108
|
+
gapsPt.push(gapEm * ctx.sizePt);
|
|
109
|
+
carriedRspaceEm = properties?.rspaceEm ?? 0;
|
|
110
|
+
}
|
|
111
|
+
return concatBoxesHorizontally(boxes, gapsPt);
|
|
112
|
+
}
|
|
113
|
+
function layoutSemantics(element, ctx) {
|
|
114
|
+
const content = elementChildren(element).find((child) => {
|
|
115
|
+
const name = elementLocalName(child);
|
|
116
|
+
return name !== "annotation" && name !== "annotation-xml";
|
|
117
|
+
});
|
|
118
|
+
return content === void 0 ? EMPTY_BOX : layoutNode(content, ctx);
|
|
119
|
+
}
|
|
120
|
+
function mstyleContext(element, ctx) {
|
|
121
|
+
let next = ctx;
|
|
122
|
+
const displayAttr = attrValue(element, "displaystyle");
|
|
123
|
+
if (displayAttr === "true" || displayAttr === "false") next = {
|
|
124
|
+
...next,
|
|
125
|
+
displayStyle: displayAttr === "true"
|
|
126
|
+
};
|
|
127
|
+
const variantAttr = attrValue(element, "mathvariant");
|
|
128
|
+
if (variantAttr !== void 0 && isMathVariant(variantAttr)) next = {
|
|
129
|
+
...next,
|
|
130
|
+
inheritedVariant: variantAttr
|
|
131
|
+
};
|
|
132
|
+
return next;
|
|
133
|
+
}
|
|
134
|
+
function layoutScripts(base, subscript, superscript, ctx) {
|
|
135
|
+
const metrics = ctx.metrics;
|
|
136
|
+
const initialSupShiftUpPt = Math.max(ctx.cramped ? metrics.superscriptShiftUpCrampedPt : metrics.superscriptShiftUpPt, base.ascentPt - metrics.superscriptBaselineDropMaxPt);
|
|
137
|
+
const initialSubShiftDownPt = Math.max(metrics.subscriptShiftDownPt, base.descentPt + metrics.subscriptBaselineDropMinPt);
|
|
138
|
+
let correctionPt = 0;
|
|
139
|
+
if (superscript !== void 0 && subscript !== void 0) {
|
|
140
|
+
const gapPt = initialSupShiftUpPt - superscript.descentPt + (initialSubShiftDownPt - subscript.ascentPt);
|
|
141
|
+
correctionPt = Math.max(0, metrics.subSuperscriptGapMinPt - gapPt) / 2;
|
|
142
|
+
}
|
|
143
|
+
const supShiftUpPt = initialSupShiftUpPt + correctionPt;
|
|
144
|
+
const subShiftDownPt = initialSubShiftDownPt + correctionPt;
|
|
145
|
+
const ascentPt = Math.max(base.ascentPt, superscript === void 0 ? 0 : supShiftUpPt + superscript.ascentPt);
|
|
146
|
+
const descentPt = Math.max(base.descentPt, subscript === void 0 ? 0 : subShiftDownPt + subscript.descentPt);
|
|
147
|
+
const scriptWidthPt = Math.max(superscript?.widthPt ?? 0, subscript?.widthPt ?? 0);
|
|
148
|
+
const widthPt = base.widthPt + (scriptWidthPt > 0 ? scriptWidthPt + metrics.spaceAfterScriptPt : 0);
|
|
149
|
+
const items = [...placeChild(base, 0, 0, ascentPt)];
|
|
150
|
+
if (superscript !== void 0) items.push(...placeChild(superscript, base.widthPt, -supShiftUpPt, ascentPt));
|
|
151
|
+
if (subscript !== void 0) items.push(...placeChild(subscript, base.widthPt, subShiftDownPt, ascentPt));
|
|
152
|
+
return {
|
|
153
|
+
widthPt,
|
|
154
|
+
ascentPt,
|
|
155
|
+
descentPt,
|
|
156
|
+
heightPt: ascentPt + descentPt,
|
|
157
|
+
items
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function layoutUnderOver(base, under, over, ctx, accentAttachment = {}) {
|
|
161
|
+
const gapPt = ctx.metrics.stackGapMinPt;
|
|
162
|
+
const overHeightPt = over === void 0 ? 0 : gapPt + over.heightPt;
|
|
163
|
+
const underHeightPt = under === void 0 ? 0 : gapPt + under.heightPt;
|
|
164
|
+
const ascentPt = base.ascentPt + overHeightPt;
|
|
165
|
+
const descentPt = base.descentPt + underHeightPt;
|
|
166
|
+
const widthPt = Math.max(base.widthPt, under?.widthPt ?? 0, over?.widthPt ?? 0);
|
|
167
|
+
const baseXPt = (widthPt - base.widthPt) / 2;
|
|
168
|
+
const items = [...placeChild(base, baseXPt, 0, ascentPt)];
|
|
169
|
+
if (over !== void 0) {
|
|
170
|
+
const overXPt = accentAttachment.overXPt === void 0 ? (widthPt - over.widthPt) / 2 : baseXPt + accentAttachment.overXPt - over.widthPt / 2;
|
|
171
|
+
items.push(...placeChild(over, overXPt, -(base.ascentPt + gapPt + over.descentPt), ascentPt));
|
|
172
|
+
}
|
|
173
|
+
if (under !== void 0) {
|
|
174
|
+
const underXPt = accentAttachment.underXPt === void 0 ? (widthPt - under.widthPt) / 2 : baseXPt + accentAttachment.underXPt - under.widthPt / 2;
|
|
175
|
+
items.push(...placeChild(under, underXPt, base.descentPt + gapPt + under.ascentPt, ascentPt));
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
widthPt,
|
|
179
|
+
ascentPt,
|
|
180
|
+
descentPt,
|
|
181
|
+
heightPt: ascentPt + descentPt,
|
|
182
|
+
items
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function isMovableLimitsOperator(element) {
|
|
186
|
+
return elementLocalName(element) === "mo" && operatorProperties(textContent(element).trim()).movablelimits;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/mathml/layout.ts
|
|
190
|
+
const HEX_RADIX = 16;
|
|
191
|
+
const UNICODE_HEX_DIGITS = 4;
|
|
192
|
+
const PERCENT_SCALE = 100;
|
|
193
|
+
const RADICAL_SIGN = 8730;
|
|
194
|
+
const TABLE_COLUMN_GAP_EM = .8;
|
|
195
|
+
const TABLE_ROW_GAP_EM = .5;
|
|
196
|
+
function rootContext(options, diagnostics) {
|
|
197
|
+
return {
|
|
198
|
+
metrics: options.metrics,
|
|
199
|
+
sizePt: options.sizePt,
|
|
200
|
+
color: options.color,
|
|
201
|
+
inheritedVariant: void 0,
|
|
202
|
+
displayStyle: true,
|
|
203
|
+
cramped: false,
|
|
204
|
+
firstScriptLevel: true,
|
|
205
|
+
diagnostics
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function scriptContext(ctx, cramped) {
|
|
209
|
+
const scale = ctx.firstScriptLevel ? ctx.metrics.scriptPercentScaleDown : ctx.metrics.scriptScriptPercentScaleDown;
|
|
210
|
+
return {
|
|
211
|
+
...ctx,
|
|
212
|
+
sizePt: ctx.sizePt * scale,
|
|
213
|
+
displayStyle: false,
|
|
214
|
+
cramped,
|
|
215
|
+
firstScriptLevel: false
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function unsupported(ctx, element) {
|
|
219
|
+
ctx.diagnostics.push({
|
|
220
|
+
kind: "unsupported-element",
|
|
221
|
+
detail: elementLocalName(element)
|
|
222
|
+
});
|
|
223
|
+
return layoutToken(textContent(element), "normal", ctx);
|
|
224
|
+
}
|
|
225
|
+
function layoutToken(rawText, variant, ctx) {
|
|
226
|
+
const styled = applyMathVariant(rawText, variant);
|
|
227
|
+
const nominalAscentPt = ctx.metrics.ascentPerEm * ctx.sizePt;
|
|
228
|
+
const nominalDescentPt = ctx.metrics.descentPerEm * ctx.sizePt;
|
|
229
|
+
let widthPt = 0;
|
|
230
|
+
let ascentPt = 0;
|
|
231
|
+
let descentPt = 0;
|
|
232
|
+
let text = "";
|
|
233
|
+
for (const ch of styled) {
|
|
234
|
+
const codePoint = ch.codePointAt(0);
|
|
235
|
+
if (codePoint === void 0) continue;
|
|
236
|
+
const glyph = ctx.metrics.glyph(codePoint, ctx.sizePt);
|
|
237
|
+
if (glyph === void 0) {
|
|
238
|
+
ctx.diagnostics.push({
|
|
239
|
+
kind: "missing-glyph",
|
|
240
|
+
detail: `U+${codePoint.toString(HEX_RADIX).toUpperCase().padStart(UNICODE_HEX_DIGITS, "0")}`
|
|
241
|
+
});
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
text += ch;
|
|
245
|
+
widthPt += glyph.advanceWidthPt;
|
|
246
|
+
ascentPt = Math.max(ascentPt, glyph.inkAscentPt ?? nominalAscentPt);
|
|
247
|
+
descentPt = Math.max(descentPt, glyph.inkDescentPt ?? nominalDescentPt);
|
|
248
|
+
}
|
|
249
|
+
if (text.length === 0) return EMPTY_BOX;
|
|
250
|
+
const items = [{
|
|
251
|
+
kind: "glyphs",
|
|
252
|
+
xPt: 0,
|
|
253
|
+
yPt: ascentPt,
|
|
254
|
+
text,
|
|
255
|
+
sizePt: ctx.sizePt,
|
|
256
|
+
color: ctx.color
|
|
257
|
+
}];
|
|
258
|
+
return {
|
|
259
|
+
widthPt,
|
|
260
|
+
ascentPt,
|
|
261
|
+
descentPt,
|
|
262
|
+
heightPt: ascentPt + descentPt,
|
|
263
|
+
items
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function tokenVariant(element, intrinsicDefault, ctx) {
|
|
267
|
+
const attr = attrValue(element, "mathvariant");
|
|
268
|
+
if (attr !== void 0 && isMathVariant(attr)) return attr;
|
|
269
|
+
return ctx.inheritedVariant ?? intrinsicDefault;
|
|
270
|
+
}
|
|
271
|
+
function miIntrinsicDefault(content) {
|
|
272
|
+
return [...content].length === 1 ? "italic" : "normal";
|
|
273
|
+
}
|
|
274
|
+
function resolveTopAccentXPt(baseElement, ctx) {
|
|
275
|
+
const name = elementLocalName(baseElement);
|
|
276
|
+
let rawText;
|
|
277
|
+
let intrinsicDefault;
|
|
278
|
+
if (name === "mi") {
|
|
279
|
+
rawText = textContent(baseElement);
|
|
280
|
+
intrinsicDefault = miIntrinsicDefault(rawText);
|
|
281
|
+
} else if (name === "mn" || name === "mtext") {
|
|
282
|
+
rawText = textContent(baseElement);
|
|
283
|
+
intrinsicDefault = "normal";
|
|
284
|
+
} else if (name === "mo") {
|
|
285
|
+
rawText = textContent(baseElement).trim();
|
|
286
|
+
intrinsicDefault = "normal";
|
|
287
|
+
} else return;
|
|
288
|
+
const codePoint = singleCodePoint(applyMathVariant(rawText, tokenVariant(baseElement, intrinsicDefault, ctx)));
|
|
289
|
+
if (codePoint === void 0) return;
|
|
290
|
+
return ctx.metrics.glyph(codePoint, ctx.sizePt)?.topAccentXPt;
|
|
291
|
+
}
|
|
292
|
+
function layoutUnderOverElement(element, kind, ctx) {
|
|
293
|
+
const children = elementChildren(element);
|
|
294
|
+
const baseElement = children[0];
|
|
295
|
+
if (baseElement === void 0) return EMPTY_BOX;
|
|
296
|
+
if (!ctx.displayStyle && isMovableLimitsOperator(baseElement)) {
|
|
297
|
+
const base = layoutNode(baseElement, ctx);
|
|
298
|
+
const scriptCtx = scriptContext(ctx, ctx.cramped);
|
|
299
|
+
if (kind === "mover") return layoutScripts(base, void 0, children[1] === void 0 ? void 0 : layoutNode(children[1], scriptCtx), ctx);
|
|
300
|
+
return layoutScripts(base, children[1] === void 0 ? void 0 : layoutNode(children[1], scriptCtx), children[2] === void 0 ? void 0 : layoutNode(children[2], scriptCtx), ctx);
|
|
301
|
+
}
|
|
302
|
+
const base = layoutNode(baseElement, ctx);
|
|
303
|
+
const scriptCtx = scriptContext(ctx, false);
|
|
304
|
+
const isAccent = attrValue(element, "accent") === "true";
|
|
305
|
+
const isAccentUnder = attrValue(element, "accentunder") === "true";
|
|
306
|
+
const accentAttachment = {
|
|
307
|
+
overXPt: isAccent ? resolveTopAccentXPt(baseElement, ctx) : void 0,
|
|
308
|
+
underXPt: isAccentUnder ? resolveTopAccentXPt(baseElement, ctx) : void 0
|
|
309
|
+
};
|
|
310
|
+
if (kind === "mover") return layoutUnderOver(base, void 0, children[1] === void 0 ? void 0 : layoutUnderOverChild(children[1], base.widthPt, scriptCtx), ctx, accentAttachment);
|
|
311
|
+
return layoutUnderOver(base, children[1] === void 0 ? void 0 : layoutUnderOverChild(children[1], base.widthPt, scriptCtx), children[2] === void 0 ? void 0 : layoutUnderOverChild(children[2], base.widthPt, scriptCtx), ctx, accentAttachment);
|
|
312
|
+
}
|
|
313
|
+
function layoutFraction(element, ctx) {
|
|
314
|
+
const children = elementChildren(element);
|
|
315
|
+
const numeratorElement = children[0];
|
|
316
|
+
const denominatorElement = children[1];
|
|
317
|
+
if (numeratorElement === void 0) return EMPTY_BOX;
|
|
318
|
+
if (denominatorElement === void 0) return EMPTY_BOX;
|
|
319
|
+
const fracCtx = {
|
|
320
|
+
...ctx,
|
|
321
|
+
displayStyle: false,
|
|
322
|
+
cramped: false
|
|
323
|
+
};
|
|
324
|
+
const numerator = layoutNode(numeratorElement, fracCtx);
|
|
325
|
+
const denominator = layoutNode(denominatorElement, {
|
|
326
|
+
...fracCtx,
|
|
327
|
+
cramped: true
|
|
328
|
+
});
|
|
329
|
+
const metrics = ctx.metrics;
|
|
330
|
+
const lineThicknessAttr = attrValue(element, "linethickness");
|
|
331
|
+
const ruleThicknessPt = (lineThicknessAttr === void 0 ? void 0 : parseMathLength(lineThicknessAttr, ctx.sizePt)) ?? metrics.fractionRuleThicknessPt;
|
|
332
|
+
const axisPt = metrics.axisHeightPt;
|
|
333
|
+
const numShiftUpPt = Math.max(ctx.displayStyle ? metrics.fractionNumeratorDisplayShiftUpPt : metrics.fractionNumeratorShiftUpPt, axisPt + ruleThicknessPt / 2 + metrics.fractionNumeratorGapMinPt + numerator.descentPt);
|
|
334
|
+
const denShiftDownPt = Math.max(ctx.displayStyle ? metrics.fractionDenominatorDisplayShiftDownPt : metrics.fractionDenominatorShiftDownPt, ruleThicknessPt / 2 + metrics.fractionDenominatorGapMinPt + denominator.ascentPt - axisPt);
|
|
335
|
+
const widthPt = Math.max(numerator.widthPt, denominator.widthPt);
|
|
336
|
+
const ascentPt = numShiftUpPt + numerator.ascentPt;
|
|
337
|
+
const descentPt = denShiftDownPt + denominator.descentPt;
|
|
338
|
+
const items = [
|
|
339
|
+
...placeChild(numerator, (widthPt - numerator.widthPt) / 2, -numShiftUpPt, ascentPt),
|
|
340
|
+
...placeChild(denominator, (widthPt - denominator.widthPt) / 2, denShiftDownPt, ascentPt),
|
|
341
|
+
{
|
|
342
|
+
kind: "rule",
|
|
343
|
+
xPt: 0,
|
|
344
|
+
yPt: ascentPt - axisPt - ruleThicknessPt / 2,
|
|
345
|
+
widthPt,
|
|
346
|
+
heightPt: ruleThicknessPt,
|
|
347
|
+
color: ctx.color
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
return {
|
|
351
|
+
widthPt,
|
|
352
|
+
ascentPt,
|
|
353
|
+
descentPt,
|
|
354
|
+
heightPt: ascentPt + descentPt,
|
|
355
|
+
items
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function layoutRadical(element, kind, ctx) {
|
|
359
|
+
const children = elementChildren(element);
|
|
360
|
+
if (kind === "msqrt") return wrapRadical(layoutRowChildren(children, {
|
|
361
|
+
...ctx,
|
|
362
|
+
cramped: true
|
|
363
|
+
}), void 0, ctx);
|
|
364
|
+
const radicandElement = children[0];
|
|
365
|
+
const indexElement = children[1];
|
|
366
|
+
if (radicandElement === void 0) return EMPTY_BOX;
|
|
367
|
+
return wrapRadical(layoutNode(radicandElement, {
|
|
368
|
+
...ctx,
|
|
369
|
+
cramped: true
|
|
370
|
+
}), indexElement === void 0 ? void 0 : layoutNode(indexElement, scriptContext(scriptContext(ctx, false), false)), ctx);
|
|
371
|
+
}
|
|
372
|
+
function wrapRadical(radicand, index, ctx) {
|
|
373
|
+
const metrics = ctx.metrics;
|
|
374
|
+
const ruleThicknessPt = metrics.radicalRuleThicknessPt;
|
|
375
|
+
const gapPt = metrics.radicalVerticalGapPt;
|
|
376
|
+
const signHeightPt = metrics.radicalExtraAscenderPt + ruleThicknessPt + gapPt + radicand.heightPt;
|
|
377
|
+
const degreeWidthPt = index === void 0 ? 0 : metrics.radicalKernBeforeDegreePt + index.widthPt + metrics.radicalKernAfterDegreePt;
|
|
378
|
+
const signOriginXPt = Math.max(0, degreeWidthPt);
|
|
379
|
+
const ascentPt = metrics.radicalExtraAscenderPt + ruleThicknessPt + gapPt + radicand.ascentPt;
|
|
380
|
+
const descentPt = radicand.descentPt;
|
|
381
|
+
const items = [];
|
|
382
|
+
const stretched = ctx.metrics.stretch(RADICAL_SIGN, "vertical", signHeightPt - metrics.radicalExtraAscenderPt, ctx.sizePt);
|
|
383
|
+
let signWidthPt;
|
|
384
|
+
if (stretched !== void 0) {
|
|
385
|
+
const placements = stretched.placements.map((placement) => ({
|
|
386
|
+
glyphId: placement.glyphId,
|
|
387
|
+
xPt: signOriginXPt,
|
|
388
|
+
yPt: metrics.radicalExtraAscenderPt + stretched.inkAscentPt - placement.offsetPt
|
|
389
|
+
}));
|
|
390
|
+
items.push({
|
|
391
|
+
kind: "assembled-glyphs",
|
|
392
|
+
placements,
|
|
393
|
+
text: "√",
|
|
394
|
+
sizePt: ctx.sizePt,
|
|
395
|
+
color: ctx.color
|
|
396
|
+
});
|
|
397
|
+
items.push({
|
|
398
|
+
kind: "rule",
|
|
399
|
+
xPt: signOriginXPt,
|
|
400
|
+
yPt: metrics.radicalExtraAscenderPt,
|
|
401
|
+
widthPt: stretched.advanceWidthPt + radicand.widthPt,
|
|
402
|
+
heightPt: ruleThicknessPt,
|
|
403
|
+
color: ctx.color
|
|
404
|
+
});
|
|
405
|
+
signWidthPt = stretched.advanceWidthPt;
|
|
406
|
+
} else {
|
|
407
|
+
const sign = buildRadicalSign(signOriginXPt, 0, signHeightPt, radicand.widthPt, ruleThicknessPt, ctx.color);
|
|
408
|
+
items.push(sign.hook, sign.vinculum);
|
|
409
|
+
signWidthPt = sign.widthPt;
|
|
410
|
+
}
|
|
411
|
+
items.push(...placeChild(radicand, signOriginXPt + signWidthPt, 0, ascentPt));
|
|
412
|
+
if (index !== void 0) {
|
|
413
|
+
const raisePt = (ascentPt + descentPt) * metrics.radicalDegreeBottomRaisePercent / PERCENT_SCALE;
|
|
414
|
+
const degreeBaselineFromTopPt = ascentPt + descentPt - raisePt - index.descentPt;
|
|
415
|
+
items.push(...shiftItems(index.items, metrics.radicalKernBeforeDegreePt, degreeBaselineFromTopPt - index.ascentPt));
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
widthPt: signOriginXPt + signWidthPt + radicand.widthPt,
|
|
419
|
+
ascentPt,
|
|
420
|
+
descentPt,
|
|
421
|
+
heightPt: ascentPt + descentPt,
|
|
422
|
+
items
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function layoutTable(element, ctx) {
|
|
426
|
+
const rows = elementChildren(element).filter((child) => elementLocalName(child) === "mtr");
|
|
427
|
+
const columnAlignAttr = attrValue(element, "columnalign");
|
|
428
|
+
const columnAligns = columnAlignAttr === void 0 ? [] : columnAlignAttr.match(/\S+/g) ?? [];
|
|
429
|
+
const rowCells = rows.map((row) => elementChildren(row).filter((child) => elementLocalName(child) === "mtd").map((cell) => layoutRowChildren(elementChildren(cell), ctx)));
|
|
430
|
+
const columnCount = rowCells.reduce((max, row) => Math.max(max, row.length), 0);
|
|
431
|
+
if (columnCount === 0) return EMPTY_BOX;
|
|
432
|
+
const columnWidthsPt = Array.from({ length: columnCount }, (_, column) => rowCells.reduce((max, row) => Math.max(max, row[column]?.widthPt ?? 0), 0));
|
|
433
|
+
const columnGapPt = TABLE_COLUMN_GAP_EM * ctx.sizePt;
|
|
434
|
+
const rowGapPt = TABLE_ROW_GAP_EM * ctx.sizePt;
|
|
435
|
+
const items = [];
|
|
436
|
+
let cursorYTopPt = 0;
|
|
437
|
+
rowCells.forEach((row, rowIndex) => {
|
|
438
|
+
const rowAscentPt = row.reduce((max, cell) => Math.max(max, cell.ascentPt), 0);
|
|
439
|
+
const rowDescentPt = row.reduce((max, cell) => Math.max(max, cell.descentPt), 0);
|
|
440
|
+
let cursorXPt = 0;
|
|
441
|
+
row.forEach((cell, columnIndex) => {
|
|
442
|
+
const columnWidthPt = columnWidthsPt[columnIndex] ?? cell.widthPt;
|
|
443
|
+
const align = columnAligns[columnIndex] ?? columnAligns[columnAligns.length - 1];
|
|
444
|
+
const extraPt = columnWidthPt - cell.widthPt;
|
|
445
|
+
const dxPt = align === "left" ? 0 : align === "right" ? extraPt : extraPt / 2;
|
|
446
|
+
items.push(...placeChild(cell, cursorXPt + dxPt, 0, cursorYTopPt + rowAscentPt));
|
|
447
|
+
cursorXPt += columnWidthPt + columnGapPt;
|
|
448
|
+
});
|
|
449
|
+
cursorYTopPt += rowAscentPt + rowDescentPt + (rowIndex < rowCells.length - 1 ? rowGapPt : 0);
|
|
450
|
+
});
|
|
451
|
+
const widthPt = columnWidthsPt.reduce((sum, w) => sum + w, 0) + columnGapPt * Math.max(0, columnCount - 1);
|
|
452
|
+
let descentPt = cursorYTopPt - (cursorYTopPt / 2 + ctx.metrics.axisHeightPt);
|
|
453
|
+
if (descentPt < 0) descentPt = 0;
|
|
454
|
+
return {
|
|
455
|
+
widthPt,
|
|
456
|
+
ascentPt: cursorYTopPt - descentPt,
|
|
457
|
+
descentPt,
|
|
458
|
+
heightPt: cursorYTopPt,
|
|
459
|
+
items
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function layoutSpace(element, ctx) {
|
|
463
|
+
const widthAttr = attrValue(element, "width");
|
|
464
|
+
const heightAttr = attrValue(element, "height");
|
|
465
|
+
const depthAttr = attrValue(element, "depth");
|
|
466
|
+
const widthPt = Math.max(0, (widthAttr === void 0 ? void 0 : parseMathLength(widthAttr, ctx.sizePt)) ?? 0);
|
|
467
|
+
const ascentPt = Math.max(0, (heightAttr === void 0 ? void 0 : parseMathLength(heightAttr, ctx.sizePt)) ?? 0);
|
|
468
|
+
const descentPt = Math.max(0, (depthAttr === void 0 ? void 0 : parseMathLength(depthAttr, ctx.sizePt)) ?? 0);
|
|
469
|
+
return {
|
|
470
|
+
widthPt,
|
|
471
|
+
ascentPt,
|
|
472
|
+
descentPt,
|
|
473
|
+
heightPt: ascentPt + descentPt,
|
|
474
|
+
items: []
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function layoutNode(node, ctx) {
|
|
478
|
+
if (!isMathMlElement(node)) return EMPTY_BOX;
|
|
479
|
+
switch (elementLocalName(node)) {
|
|
480
|
+
case "mrow": return layoutRowChildren(elementChildren(node), ctx);
|
|
481
|
+
case "semantics": return layoutSemantics(node, ctx);
|
|
482
|
+
case "mstyle": return layoutRowChildren(elementChildren(node), mstyleContext(node, ctx));
|
|
483
|
+
case "mi": {
|
|
484
|
+
const text = textContent(node);
|
|
485
|
+
return layoutToken(text, tokenVariant(node, miIntrinsicDefault(text), ctx), ctx);
|
|
486
|
+
}
|
|
487
|
+
case "mn": return layoutToken(textContent(node), tokenVariant(node, "normal", ctx), ctx);
|
|
488
|
+
case "mo": return layoutToken(textContent(node).trim(), tokenVariant(node, "normal", ctx), ctx);
|
|
489
|
+
case "mtext": return layoutToken(textContent(node), tokenVariant(node, "normal", ctx), ctx);
|
|
490
|
+
case "mspace": return layoutSpace(node, ctx);
|
|
491
|
+
case "msub": {
|
|
492
|
+
const children = elementChildren(node);
|
|
493
|
+
return layoutScripts(children[0] === void 0 ? EMPTY_BOX : layoutNode(children[0], ctx), children[1] === void 0 ? void 0 : layoutNode(children[1], scriptContext(ctx, ctx.cramped)), void 0, ctx);
|
|
494
|
+
}
|
|
495
|
+
case "msup": {
|
|
496
|
+
const children = elementChildren(node);
|
|
497
|
+
return layoutScripts(children[0] === void 0 ? EMPTY_BOX : layoutNode(children[0], ctx), void 0, children[1] === void 0 ? void 0 : layoutNode(children[1], scriptContext(ctx, ctx.cramped)), ctx);
|
|
498
|
+
}
|
|
499
|
+
case "msubsup": {
|
|
500
|
+
const children = elementChildren(node);
|
|
501
|
+
const base = children[0] === void 0 ? EMPTY_BOX : layoutNode(children[0], ctx);
|
|
502
|
+
const scriptCtx = scriptContext(ctx, ctx.cramped);
|
|
503
|
+
return layoutScripts(base, children[1] === void 0 ? void 0 : layoutNode(children[1], scriptCtx), children[2] === void 0 ? void 0 : layoutNode(children[2], scriptCtx), ctx);
|
|
504
|
+
}
|
|
505
|
+
case "munder": return layoutUnderOverElement(node, "munder", ctx);
|
|
506
|
+
case "mover": return layoutUnderOverElement(node, "mover", ctx);
|
|
507
|
+
case "munderover": return layoutUnderOverElement(node, "munderover", ctx);
|
|
508
|
+
case "mfrac": return layoutFraction(node, ctx);
|
|
509
|
+
case "msqrt": return layoutRadical(node, "msqrt", ctx);
|
|
510
|
+
case "mroot": return layoutRadical(node, "mroot", ctx);
|
|
511
|
+
case "mtable": return layoutTable(node, ctx);
|
|
512
|
+
case "mtr":
|
|
513
|
+
case "mtd": return layoutRowChildren(elementChildren(node), ctx);
|
|
514
|
+
default: return unsupported(ctx, node);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function layoutFormula(mathml, options) {
|
|
518
|
+
const diagnostics = [];
|
|
519
|
+
const ctx = rootContext(options, diagnostics);
|
|
520
|
+
return {
|
|
521
|
+
box: layoutRowChildren(mathml.filter(isMathMlElement), ctx),
|
|
522
|
+
diagnostics
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
//#endregion
|
|
526
|
+
export { isStretchyOperator as a, layoutSemantics as c, mstyleContext as d, singleCodePoint as f, stretchedBox as g, stretchRowOperators as h, isMovableLimitsOperator as i, layoutUnderOver as l, stretchOperator as m, layoutNode as n, layoutRowChildren as o, stretchHorizontalOperator as p, horizontallyStretchedBox as r, layoutScripts as s, layoutFormula as t, layoutUnderOverChild as u };
|