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.
Files changed (163) hide show
  1. package/dist/codecs/read.cjs +2 -2
  2. package/dist/codecs/read.js +1 -1
  3. package/dist/composition-plan-CfvhXeOC.cjs +627 -0
  4. package/dist/composition-plan-DU9nPPN7.d.cts +102 -0
  5. package/dist/composition-plan-f0zaExUW.js +508 -0
  6. package/dist/composition-plan-l6QPO4FX.d.ts +102 -0
  7. package/dist/convert/composition-plan.cjs +7 -0
  8. package/dist/convert/composition-plan.d.cts +2 -0
  9. package/dist/convert/composition-plan.d.ts +2 -0
  10. package/dist/convert/composition-plan.js +2 -0
  11. package/dist/convert/composition-to-pdf.cjs +12 -12
  12. package/dist/convert/composition-to-pdf.d.cts +1 -1
  13. package/dist/convert/composition-to-pdf.d.ts +1 -1
  14. package/dist/convert/composition-to-pdf.js +2 -2
  15. package/dist/convert/composition.cjs +16 -511
  16. package/dist/convert/composition.d.cts +2 -85
  17. package/dist/convert/composition.d.ts +2 -85
  18. package/dist/convert/composition.js +2 -502
  19. package/dist/convert/convert.cjs +2 -2
  20. package/dist/convert/convert.js +1 -1
  21. package/dist/convert/from-package.cjs +3 -3
  22. package/dist/convert/from-package.js +2 -2
  23. package/dist/convert/from-pdf.cjs +18 -18
  24. package/dist/convert/from-pdf.js +2 -2
  25. package/dist/convert/local.cjs +3 -3
  26. package/dist/convert/local.js +1 -1
  27. package/dist/edit/odp/slide.cjs +4 -4
  28. package/dist/edit/odp/slide.d.cts +1 -1
  29. package/dist/edit/odp/slide.d.ts +1 -1
  30. package/dist/edit/odp/slide.js +1 -1
  31. package/dist/edit/odt/content.d.cts +1 -1
  32. package/dist/edit/odt/content.d.ts +1 -1
  33. package/dist/edit/odt/editor.cjs +4 -4
  34. package/dist/edit/odt/editor.d.cts +1 -1
  35. package/dist/edit/odt/editor.d.ts +1 -1
  36. package/dist/edit/odt/editor.js +1 -1
  37. package/dist/edit/odt/table-grid.cjs +23 -0
  38. package/dist/edit/odt/table-grid.d.cts +54 -0
  39. package/dist/edit/odt/table-grid.d.ts +54 -0
  40. package/dist/edit/odt/table-grid.js +2 -0
  41. package/dist/edit/odt/table.cjs +12 -653
  42. package/dist/edit/odt/table.d.cts +2 -2
  43. package/dist/edit/odt/table.d.ts +2 -2
  44. package/dist/edit/odt/table.js +2 -647
  45. package/dist/{evaluate-BbOsgdmN.d.cts → evaluate-BSEUxiUK.d.cts} +3 -1
  46. package/dist/evaluate-CEzsBx3w.cjs +564 -0
  47. package/dist/{evaluate-C7fmk69X.d.ts → evaluate-D8fG2ZeB.d.ts} +3 -1
  48. package/dist/evaluate-IK-3aMv5.js +445 -0
  49. package/dist/evaluate-columns-CyqKHkIW.d.cts +41 -0
  50. package/dist/evaluate-columns-cOo8fOfT.d.ts +41 -0
  51. package/dist/index.cjs +24 -24
  52. package/dist/index.d.cts +6 -5
  53. package/dist/index.d.ts +6 -5
  54. package/dist/index.js +8 -8
  55. package/dist/latex/lint.cjs +2 -2
  56. package/dist/latex/lint.js +1 -1
  57. package/dist/latex/lower-fold.cjs +6 -0
  58. package/dist/latex/lower-fold.d.cts +17 -0
  59. package/dist/latex/lower-fold.d.ts +17 -0
  60. package/dist/latex/lower-fold.js +2 -0
  61. package/dist/latex/lower.cjs +11 -617
  62. package/dist/latex/lower.d.cts +18 -1
  63. package/dist/latex/lower.d.ts +18 -1
  64. package/dist/latex/lower.js +2 -616
  65. package/dist/latex/symbols.d.cts +1 -15
  66. package/dist/latex/symbols.d.ts +1 -15
  67. package/dist/latex/temml.d.cts +1 -24
  68. package/dist/latex/temml.d.ts +1 -24
  69. package/dist/layout/engine.cjs +2 -2
  70. package/dist/layout/engine.js +1 -1
  71. package/dist/layout/reconstruct-lines.cjs +315 -0
  72. package/dist/layout/reconstruct-lines.d.cts +2 -0
  73. package/dist/layout/reconstruct-lines.d.ts +2 -0
  74. package/dist/layout/reconstruct-lines.js +297 -0
  75. package/dist/layout/reconstruct-presentations-prod.cjs +9 -0
  76. package/dist/layout/reconstruct-presentations-prod.d.cts +26 -0
  77. package/dist/layout/reconstruct-presentations-prod.d.ts +26 -0
  78. package/dist/layout/reconstruct-presentations-prod.js +2 -0
  79. package/dist/layout/reconstruct-tables.cjs +5 -0
  80. package/dist/layout/reconstruct-tables.d.cts +22 -0
  81. package/dist/layout/reconstruct-tables.d.ts +22 -0
  82. package/dist/layout/reconstruct-tables.js +2 -0
  83. package/dist/layout/reconstruct.cjs +11 -1545
  84. package/dist/layout/reconstruct.d.cts +2 -14
  85. package/dist/layout/reconstruct.d.ts +2 -14
  86. package/dist/layout/reconstruct.js +2 -1542
  87. package/dist/layout/shared.cjs +2 -2
  88. package/dist/layout/shared.js +1 -1
  89. package/dist/layout/sheets-render.cjs +19 -0
  90. package/dist/layout/sheets-render.d.cts +41 -0
  91. package/dist/layout/sheets-render.d.ts +41 -0
  92. package/dist/layout/sheets-render.js +2 -0
  93. package/dist/layout/sheets.cjs +10 -544
  94. package/dist/layout/sheets.d.cts +13 -2
  95. package/dist/layout/sheets.d.ts +13 -2
  96. package/dist/layout/sheets.js +2 -543
  97. package/dist/layout/slides.cjs +2 -2
  98. package/dist/layout/slides.js +1 -1
  99. package/dist/layout-DIJzJk4x.js +526 -0
  100. package/dist/layout-iuiyl_Fk.cjs +621 -0
  101. package/dist/layout-types-oSbHvZid.d.cts +13 -0
  102. package/dist/layout-types-oSbHvZid.d.ts +13 -0
  103. package/dist/lower-DCs3rWI7.js +618 -0
  104. package/dist/lower-DzOb13w4.cjs +701 -0
  105. package/dist/markdown/math.cjs +2 -2
  106. package/dist/markdown/math.js +1 -1
  107. package/dist/mathml/layout-stretch.cjs +16 -0
  108. package/dist/mathml/layout-stretch.d.cts +24 -0
  109. package/dist/mathml/layout-stretch.d.ts +24 -0
  110. package/dist/mathml/layout-stretch.js +2 -0
  111. package/dist/mathml/layout-types.d.cts +1 -12
  112. package/dist/mathml/layout-types.d.ts +1 -12
  113. package/dist/mathml/layout.cjs +3 -525
  114. package/dist/mathml/layout.d.cts +2 -2
  115. package/dist/mathml/layout.d.ts +2 -2
  116. package/dist/mathml/layout.js +1 -523
  117. package/dist/odb/formula/evaluate.d.cts +1 -1
  118. package/dist/odb/formula/evaluate.d.ts +1 -1
  119. package/dist/odb/report/render.d.cts +1 -1
  120. package/dist/odb/report/render.d.ts +1 -1
  121. package/dist/odb/report/source.cjs +2 -2
  122. package/dist/odb/report/source.d.cts +1 -1
  123. package/dist/odb/report/source.d.ts +1 -1
  124. package/dist/odb/report/source.js +1 -1
  125. package/dist/odb/sql/evaluate-columns.cjs +122 -0
  126. package/dist/odb/sql/evaluate-columns.d.cts +2 -0
  127. package/dist/odb/sql/evaluate-columns.d.ts +2 -0
  128. package/dist/odb/sql/evaluate-columns.js +114 -0
  129. package/dist/odb/sql/evaluate-predicates.cjs +16 -0
  130. package/dist/odb/sql/evaluate-predicates.d.cts +23 -0
  131. package/dist/odb/sql/evaluate-predicates.d.ts +23 -0
  132. package/dist/odb/sql/evaluate-predicates.js +2 -0
  133. package/dist/odb/sql/evaluate.cjs +7 -556
  134. package/dist/odb/sql/evaluate.d.cts +2 -2
  135. package/dist/odb/sql/evaluate.d.ts +2 -2
  136. package/dist/odb/sql/evaluate.js +2 -552
  137. package/dist/read-BSH--XB4.js +682 -0
  138. package/dist/read-CahCZMwG.cjs +759 -0
  139. package/dist/reconstruct-BKOCAedo.d.ts +29 -0
  140. package/dist/reconstruct-D4TEteZ6.d.cts +29 -0
  141. package/dist/reconstruct-lines-B7t66ICm.d.cts +33 -0
  142. package/dist/reconstruct-lines-B7t66ICm.d.ts +33 -0
  143. package/dist/reconstruct-presentations-prod-B5fkPiRZ.js +1256 -0
  144. package/dist/reconstruct-presentations-prod-X315aBmI.cjs +1375 -0
  145. package/dist/sheets-BQCpNXsE.cjs +700 -0
  146. package/dist/sheets-DWDvGN-g.js +545 -0
  147. package/dist/svg/read-geometry.cjs +10 -0
  148. package/dist/svg/read-geometry.d.cts +24 -0
  149. package/dist/svg/read-geometry.d.ts +24 -0
  150. package/dist/svg/read-geometry.js +2 -0
  151. package/dist/svg/read.cjs +6 -680
  152. package/dist/svg/read.d.cts +17 -2
  153. package/dist/svg/read.d.ts +17 -2
  154. package/dist/svg/read.js +2 -679
  155. package/dist/symbols-BlzXfLEe.d.cts +16 -0
  156. package/dist/symbols-CKm2r4D0.d.ts +16 -0
  157. package/dist/table-B5gSMY7w.js +649 -0
  158. package/dist/{table-DrE6jEWv.d.cts → table-BK_Ao-Y6.d.cts} +9 -1
  159. package/dist/{table-B5htMG3g.d.ts → table-CxY85YUj.d.ts} +9 -1
  160. package/dist/table-DqUIOSPV.cjs +840 -0
  161. package/dist/temml-1-I9N9DD.d.cts +25 -0
  162. package/dist/temml-1-I9N9DD.d.ts +25 -0
  163. package/package.json +1 -1
@@ -0,0 +1,621 @@
1
+ const require_mathml_length = require("./mathml/length.cjs");
2
+ const require_mathml_nodes = require("./mathml/nodes.cjs");
3
+ const require_mathml_operators = require("./mathml/operators.cjs");
4
+ const require_mathml_variant = require("./mathml/variant.cjs");
5
+ const require_mathml_compose = require("./mathml/compose.cjs");
6
+ const require_mathml_radical = require("./mathml/radical.cjs");
7
+ //#region src/mathml/layout-stretch.ts
8
+ function isStretchyOperator(element) {
9
+ if (require_mathml_nodes.elementLocalName(element) !== "mo") return false;
10
+ if (require_mathml_nodes.attrValue(element, "stretchy") === "false") return false;
11
+ return require_mathml_operators.operatorProperties(require_mathml_nodes.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 = require_mathml_nodes.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 = require_mathml_nodes.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 = require_mathml_nodes.elementLocalName(child) === "mo" ? require_mathml_operators.operatorProperties(require_mathml_nodes.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 require_mathml_compose.concatBoxesHorizontally(boxes, gapsPt);
112
+ }
113
+ function layoutSemantics(element, ctx) {
114
+ const content = require_mathml_nodes.elementChildren(element).find((child) => {
115
+ const name = require_mathml_nodes.elementLocalName(child);
116
+ return name !== "annotation" && name !== "annotation-xml";
117
+ });
118
+ return content === void 0 ? require_mathml_compose.EMPTY_BOX : layoutNode(content, ctx);
119
+ }
120
+ function mstyleContext(element, ctx) {
121
+ let next = ctx;
122
+ const displayAttr = require_mathml_nodes.attrValue(element, "displaystyle");
123
+ if (displayAttr === "true" || displayAttr === "false") next = {
124
+ ...next,
125
+ displayStyle: displayAttr === "true"
126
+ };
127
+ const variantAttr = require_mathml_nodes.attrValue(element, "mathvariant");
128
+ if (variantAttr !== void 0 && require_mathml_variant.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 = [...require_mathml_compose.placeChild(base, 0, 0, ascentPt)];
150
+ if (superscript !== void 0) items.push(...require_mathml_compose.placeChild(superscript, base.widthPt, -supShiftUpPt, ascentPt));
151
+ if (subscript !== void 0) items.push(...require_mathml_compose.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 = [...require_mathml_compose.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(...require_mathml_compose.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(...require_mathml_compose.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 require_mathml_nodes.elementLocalName(element) === "mo" && require_mathml_operators.operatorProperties(require_mathml_nodes.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: require_mathml_nodes.elementLocalName(element)
222
+ });
223
+ return layoutToken(require_mathml_nodes.textContent(element), "normal", ctx);
224
+ }
225
+ function layoutToken(rawText, variant, ctx) {
226
+ const styled = require_mathml_variant.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 require_mathml_compose.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 = require_mathml_nodes.attrValue(element, "mathvariant");
268
+ if (attr !== void 0 && require_mathml_variant.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 = require_mathml_nodes.elementLocalName(baseElement);
276
+ let rawText;
277
+ let intrinsicDefault;
278
+ if (name === "mi") {
279
+ rawText = require_mathml_nodes.textContent(baseElement);
280
+ intrinsicDefault = miIntrinsicDefault(rawText);
281
+ } else if (name === "mn" || name === "mtext") {
282
+ rawText = require_mathml_nodes.textContent(baseElement);
283
+ intrinsicDefault = "normal";
284
+ } else if (name === "mo") {
285
+ rawText = require_mathml_nodes.textContent(baseElement).trim();
286
+ intrinsicDefault = "normal";
287
+ } else return;
288
+ const codePoint = singleCodePoint(require_mathml_variant.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 = require_mathml_nodes.elementChildren(element);
294
+ const baseElement = children[0];
295
+ if (baseElement === void 0) return require_mathml_compose.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 = require_mathml_nodes.attrValue(element, "accent") === "true";
305
+ const isAccentUnder = require_mathml_nodes.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 = require_mathml_nodes.elementChildren(element);
315
+ const numeratorElement = children[0];
316
+ const denominatorElement = children[1];
317
+ if (numeratorElement === void 0) return require_mathml_compose.EMPTY_BOX;
318
+ if (denominatorElement === void 0) return require_mathml_compose.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 = require_mathml_nodes.attrValue(element, "linethickness");
331
+ const ruleThicknessPt = (lineThicknessAttr === void 0 ? void 0 : require_mathml_length.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
+ ...require_mathml_compose.placeChild(numerator, (widthPt - numerator.widthPt) / 2, -numShiftUpPt, ascentPt),
340
+ ...require_mathml_compose.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 = require_mathml_nodes.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 require_mathml_compose.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 = require_mathml_radical.buildRadicalSign(signOriginXPt, 0, signHeightPt, radicand.widthPt, ruleThicknessPt, ctx.color);
408
+ items.push(sign.hook, sign.vinculum);
409
+ signWidthPt = sign.widthPt;
410
+ }
411
+ items.push(...require_mathml_compose.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(...require_mathml_compose.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 = require_mathml_nodes.elementChildren(element).filter((child) => require_mathml_nodes.elementLocalName(child) === "mtr");
427
+ const columnAlignAttr = require_mathml_nodes.attrValue(element, "columnalign");
428
+ const columnAligns = columnAlignAttr === void 0 ? [] : columnAlignAttr.match(/\S+/g) ?? [];
429
+ const rowCells = rows.map((row) => require_mathml_nodes.elementChildren(row).filter((child) => require_mathml_nodes.elementLocalName(child) === "mtd").map((cell) => layoutRowChildren(require_mathml_nodes.elementChildren(cell), ctx)));
430
+ const columnCount = rowCells.reduce((max, row) => Math.max(max, row.length), 0);
431
+ if (columnCount === 0) return require_mathml_compose.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(...require_mathml_compose.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 = require_mathml_nodes.attrValue(element, "width");
464
+ const heightAttr = require_mathml_nodes.attrValue(element, "height");
465
+ const depthAttr = require_mathml_nodes.attrValue(element, "depth");
466
+ const widthPt = Math.max(0, (widthAttr === void 0 ? void 0 : require_mathml_length.parseMathLength(widthAttr, ctx.sizePt)) ?? 0);
467
+ const ascentPt = Math.max(0, (heightAttr === void 0 ? void 0 : require_mathml_length.parseMathLength(heightAttr, ctx.sizePt)) ?? 0);
468
+ const descentPt = Math.max(0, (depthAttr === void 0 ? void 0 : require_mathml_length.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 (!require_mathml_nodes.isMathMlElement(node)) return require_mathml_compose.EMPTY_BOX;
479
+ switch (require_mathml_nodes.elementLocalName(node)) {
480
+ case "mrow": return layoutRowChildren(require_mathml_nodes.elementChildren(node), ctx);
481
+ case "semantics": return layoutSemantics(node, ctx);
482
+ case "mstyle": return layoutRowChildren(require_mathml_nodes.elementChildren(node), mstyleContext(node, ctx));
483
+ case "mi": {
484
+ const text = require_mathml_nodes.textContent(node);
485
+ return layoutToken(text, tokenVariant(node, miIntrinsicDefault(text), ctx), ctx);
486
+ }
487
+ case "mn": return layoutToken(require_mathml_nodes.textContent(node), tokenVariant(node, "normal", ctx), ctx);
488
+ case "mo": return layoutToken(require_mathml_nodes.textContent(node).trim(), tokenVariant(node, "normal", ctx), ctx);
489
+ case "mtext": return layoutToken(require_mathml_nodes.textContent(node), tokenVariant(node, "normal", ctx), ctx);
490
+ case "mspace": return layoutSpace(node, ctx);
491
+ case "msub": {
492
+ const children = require_mathml_nodes.elementChildren(node);
493
+ return layoutScripts(children[0] === void 0 ? require_mathml_compose.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 = require_mathml_nodes.elementChildren(node);
497
+ return layoutScripts(children[0] === void 0 ? require_mathml_compose.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 = require_mathml_nodes.elementChildren(node);
501
+ const base = children[0] === void 0 ? require_mathml_compose.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(require_mathml_nodes.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(require_mathml_nodes.isMathMlElement), ctx),
522
+ diagnostics
523
+ };
524
+ }
525
+ //#endregion
526
+ Object.defineProperty(exports, "horizontallyStretchedBox", {
527
+ enumerable: true,
528
+ get: function() {
529
+ return horizontallyStretchedBox;
530
+ }
531
+ });
532
+ Object.defineProperty(exports, "isMovableLimitsOperator", {
533
+ enumerable: true,
534
+ get: function() {
535
+ return isMovableLimitsOperator;
536
+ }
537
+ });
538
+ Object.defineProperty(exports, "isStretchyOperator", {
539
+ enumerable: true,
540
+ get: function() {
541
+ return isStretchyOperator;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, "layoutFormula", {
545
+ enumerable: true,
546
+ get: function() {
547
+ return layoutFormula;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, "layoutNode", {
551
+ enumerable: true,
552
+ get: function() {
553
+ return layoutNode;
554
+ }
555
+ });
556
+ Object.defineProperty(exports, "layoutRowChildren", {
557
+ enumerable: true,
558
+ get: function() {
559
+ return layoutRowChildren;
560
+ }
561
+ });
562
+ Object.defineProperty(exports, "layoutScripts", {
563
+ enumerable: true,
564
+ get: function() {
565
+ return layoutScripts;
566
+ }
567
+ });
568
+ Object.defineProperty(exports, "layoutSemantics", {
569
+ enumerable: true,
570
+ get: function() {
571
+ return layoutSemantics;
572
+ }
573
+ });
574
+ Object.defineProperty(exports, "layoutUnderOver", {
575
+ enumerable: true,
576
+ get: function() {
577
+ return layoutUnderOver;
578
+ }
579
+ });
580
+ Object.defineProperty(exports, "layoutUnderOverChild", {
581
+ enumerable: true,
582
+ get: function() {
583
+ return layoutUnderOverChild;
584
+ }
585
+ });
586
+ Object.defineProperty(exports, "mstyleContext", {
587
+ enumerable: true,
588
+ get: function() {
589
+ return mstyleContext;
590
+ }
591
+ });
592
+ Object.defineProperty(exports, "singleCodePoint", {
593
+ enumerable: true,
594
+ get: function() {
595
+ return singleCodePoint;
596
+ }
597
+ });
598
+ Object.defineProperty(exports, "stretchHorizontalOperator", {
599
+ enumerable: true,
600
+ get: function() {
601
+ return stretchHorizontalOperator;
602
+ }
603
+ });
604
+ Object.defineProperty(exports, "stretchOperator", {
605
+ enumerable: true,
606
+ get: function() {
607
+ return stretchOperator;
608
+ }
609
+ });
610
+ Object.defineProperty(exports, "stretchRowOperators", {
611
+ enumerable: true,
612
+ get: function() {
613
+ return stretchRowOperators;
614
+ }
615
+ });
616
+ Object.defineProperty(exports, "stretchedBox", {
617
+ enumerable: true,
618
+ get: function() {
619
+ return stretchedBox;
620
+ }
621
+ });
@@ -0,0 +1,13 @@
1
+ import { MathBox } from "document-schema.js";
2
+ //#region src/mathml/layout-types.d.ts
3
+ type MathDiagnosticKind = "unsupported-element" | "missing-glyph";
4
+ interface MathDiagnostic {
5
+ readonly kind: MathDiagnosticKind;
6
+ readonly detail: string;
7
+ }
8
+ interface MathLayoutResult {
9
+ readonly box: MathBox;
10
+ readonly diagnostics: readonly MathDiagnostic[];
11
+ }
12
+ //#endregion
13
+ export { MathDiagnosticKind as n, MathLayoutResult as r, MathDiagnostic as t };
@@ -0,0 +1,13 @@
1
+ import { MathBox } from "document-schema.js";
2
+ //#region src/mathml/layout-types.d.ts
3
+ type MathDiagnosticKind = "unsupported-element" | "missing-glyph";
4
+ interface MathDiagnostic {
5
+ readonly kind: MathDiagnosticKind;
6
+ readonly detail: string;
7
+ }
8
+ interface MathLayoutResult {
9
+ readonly box: MathBox;
10
+ readonly diagnostics: readonly MathDiagnostic[];
11
+ }
12
+ //#endregion
13
+ export { MathDiagnosticKind as n, MathLayoutResult as r, MathDiagnostic as t };