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
@@ -1,618 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_latex_temml = require("./temml.cjs");
3
- const require_latex_symbols = require("./symbols.cjs");
4
- const require_latex_rational = require("./rational.cjs");
5
- //#region src/latex/lower.ts
6
- const RELATION_SUBSCRIPT_MIN_NODES = 3;
7
- const BINARY_ATOM_OPERATORS = {
8
- "+": "math:add",
9
- "-": "math:subtract",
10
- "\\cdot": "math:multiply",
11
- "\\times": "math:multiply",
12
- "\\div": "math:divide"
13
- };
14
- const RELATION_ATOM_OPERATORS = {
15
- "=": "math:eq",
16
- "\\neq": "math:neq",
17
- "\\ne": "math:neq",
18
- "<": "math:lt",
19
- "\\leq": "math:leq",
20
- "\\le": "math:leq",
21
- ">": "math:gt",
22
- "\\geq": "math:geq",
23
- "\\ge": "math:geq"
24
- };
25
- const SUBTRACT_OPERATOR = "math:subtract";
26
- const UNARY_MINUS_OPERATOR = "math:negate";
27
- const NAMED_FUNCTION_OPERATORS = {
28
- "\\sin": "math:sin",
29
- "\\cos": "math:cos",
30
- "\\tan": "math:tan",
31
- "\\cot": "math:cot",
32
- "\\sec": "math:sec",
33
- "\\csc": "math:csc",
34
- "\\arcsin": "math:arcsin",
35
- "\\arccos": "math:arccos",
36
- "\\arctan": "math:arctan",
37
- "\\sinh": "math:sinh",
38
- "\\cosh": "math:cosh",
39
- "\\tanh": "math:tanh",
40
- "\\exp": "math:exp",
41
- "\\log": "math:log",
42
- "\\ln": "math:ln"
43
- };
44
- const PRESENTATION_ONLY_TYPES = /* @__PURE__ */ new Set([
45
- "spacing",
46
- "rule",
47
- "kern"
48
- ]);
49
- const WRAPPER_TYPES = /* @__PURE__ */ new Set(["styling", "color"]);
50
- function isRecord(value) {
51
- return typeof value === "object" && value !== null && !Array.isArray(value);
52
- }
53
- function nodeText(node) {
54
- return typeof node.text === "string" ? node.text : void 0;
55
- }
56
- function glyphOfNode(node) {
57
- const text = nodeText(node);
58
- return text === void 0 ? void 0 : require_latex_symbols.glyphOfSymbolText(text);
59
- }
60
- function numericText(text) {
61
- return text.length === 1 && text >= "0" && text <= "9";
62
- }
63
- function diagnose(context, code, detail) {
64
- context.diagnostics.push({
65
- code,
66
- ...detail === void 0 ? {} : { detail }
67
- });
68
- context.sink?.({
69
- code,
70
- ...detail === void 0 ? {} : { detail }
71
- });
72
- }
73
- function unparsed(latex) {
74
- return {
75
- kind: "unparsed",
76
- latex
77
- };
78
- }
79
- function app(operator, args) {
80
- return {
81
- kind: "app",
82
- operator,
83
- args: [...args]
84
- };
85
- }
86
- function spanOfNodes(context, nodes) {
87
- let start;
88
- let end;
89
- const visit = (node) => {
90
- const loc = node.loc;
91
- if (isRecord(loc) && typeof loc.start === "number" && typeof loc.end === "number") {
92
- if (start === void 0 || loc.start < start) start = loc.start;
93
- if (end === void 0 || loc.end > end) end = loc.end;
94
- }
95
- for (const value of Object.values(node)) if (require_latex_temml.isTemmlNode(value)) visit(value);
96
- else if (Array.isArray(value)) {
97
- for (const element of value) if (require_latex_temml.isTemmlNode(element)) visit(element);
98
- }
99
- };
100
- for (const node of nodes) visit(node);
101
- return start === void 0 || end === void 0 ? "" : context.input.slice(start, end);
102
- }
103
- function nodesOfScript(script) {
104
- if (!require_latex_temml.isTemmlNode(script)) return;
105
- if (script.type === "ordgroup" || WRAPPER_TYPES.has(script.type)) {
106
- const body = script.body;
107
- return Array.isArray(body) && body.every(require_latex_temml.isTemmlNode) ? body : void 0;
108
- }
109
- return [script];
110
- }
111
- function lowerNodeList(nodes, context) {
112
- const present = nodes.filter((node) => !PRESENTATION_ONLY_TYPES.has(node.type));
113
- const segments = [];
114
- const operators = [];
115
- let current = [];
116
- let unmappable;
117
- for (const node of present) {
118
- const operator = operatorOfNode(node);
119
- if (operator !== void 0) {
120
- segments.push(current);
121
- operators.push(operator);
122
- current = [];
123
- continue;
124
- }
125
- if (isOperatorAtom(node)) {
126
- unmappable = unmappable ?? nodeText(node) ?? node.type;
127
- continue;
128
- }
129
- current.push(node);
130
- }
131
- segments.push(current);
132
- if (unmappable !== void 0) {
133
- const detail = spanOfNodes(context, present) || unmappable;
134
- diagnose(context, "latex/operator-unmapped", detail);
135
- return unparsed(detail);
136
- }
137
- const normalised = normaliseUnaryMinus(operators, segments.map((segmentNodes) => ({
138
- nodes: segmentNodes,
139
- negated: false
140
- })));
141
- const [firstSegment, ...restSegments] = normalised.segments;
142
- if (firstSegment === void 0) {
143
- diagnose(context, "latex/operator-placement-unparsed", spanOfNodes(context, present));
144
- return unparsed(spanOfNodes(context, present));
145
- }
146
- if (normalised.operators.length === 0) return lowerFoldSegment(firstSegment, context);
147
- const detail = spanOfNodes(context, present);
148
- if (firstSegment.nodes.length === 0) {
149
- diagnose(context, "latex/operator-placement-unparsed", detail);
150
- return unparsed(detail);
151
- }
152
- return fold(lowerFoldSegment(firstSegment, context), normalised.operators, restSegments, context, detail);
153
- }
154
- function isOperatorAtom(node) {
155
- return node.type === "atom" && (node.family === "bin" || node.family === "rel");
156
- }
157
- function operatorOfNode(node) {
158
- if (node.type === "atom") {
159
- const text = nodeText(node);
160
- if (text === void 0) return;
161
- return BINARY_ATOM_OPERATORS[text] ?? RELATION_ATOM_OPERATORS[text];
162
- }
163
- if (node.type === "textord" && nodeText(node) === "/") return "math:divide";
164
- }
165
- const RELATION_OPERATORS = new Set(Object.values(RELATION_ATOM_OPERATORS));
166
- function normaliseUnaryMinus(operators, segments) {
167
- const outOperators = [];
168
- const outSegments = [];
169
- let pendingNegate = false;
170
- let skipOperator = false;
171
- for (const [index, segment] of segments.entries()) {
172
- if (index > 0 && !skipOperator) {
173
- const operator = operators[index - 1];
174
- if (operator !== void 0) outOperators.push(operator);
175
- }
176
- skipOperator = false;
177
- if (segment.nodes.length === 0 && operators[index] === SUBTRACT_OPERATOR) {
178
- pendingNegate = !pendingNegate;
179
- skipOperator = true;
180
- continue;
181
- }
182
- outSegments.push({
183
- nodes: segment.nodes,
184
- negated: pendingNegate
185
- });
186
- pendingNegate = false;
187
- }
188
- return {
189
- operators: outOperators,
190
- segments: outSegments
191
- };
192
- }
193
- function fold(first, operators, segments, context, detail) {
194
- let runFirst = first;
195
- let runOperators = [];
196
- let runSegments = [];
197
- const operands = [];
198
- const relations = [];
199
- for (let index = 0; index < operators.length; index += 1) {
200
- const operator = operators[index];
201
- const segment = segments[index];
202
- if (operator === void 0 || segment === void 0) throw new Error("operator and segment lists diverged while folding a lowered sequence");
203
- if (segment.nodes.length === 0) {
204
- diagnose(context, "latex/operator-placement-unparsed", detail);
205
- return unparsed(detail);
206
- }
207
- if (RELATION_OPERATORS.has(operator)) {
208
- operands.push(foldArithmetic(runFirst, runOperators, runSegments, context));
209
- relations.push(operator);
210
- runFirst = lowerFoldSegment(segment, context);
211
- runOperators = [];
212
- runSegments = [];
213
- continue;
214
- }
215
- runOperators.push(operator);
216
- runSegments.push(segment);
217
- }
218
- operands.push(foldArithmetic(runFirst, runOperators, runSegments, context));
219
- let folded = operands[0];
220
- if (folded === void 0) throw new Error("fold produced no operand for a non-empty operator list");
221
- for (let index = 0; index < relations.length; index += 1) {
222
- const relation = relations[index];
223
- const operand = operands[index + 1];
224
- if (relation === void 0 || operand === void 0) throw new Error("relation and operand lists diverged while folding a lowered sequence");
225
- folded = app(relation, [folded, operand]);
226
- }
227
- return folded;
228
- }
229
- function foldArithmetic(first, operators, segments, context) {
230
- let folded = first;
231
- for (let index = 0; index < operators.length; index += 1) {
232
- const operator = operators[index];
233
- const segment = segments[index];
234
- if (operator === void 0 || segment === void 0) throw new Error("operator and segment lists diverged while folding an arithmetic run");
235
- folded = app(operator, [folded, lowerFoldSegment(segment, context)]);
236
- }
237
- return folded;
238
- }
239
- function lowerFoldSegment(segment, context) {
240
- const folded = lowerTerm(segment.nodes, context);
241
- return segment.negated ? app(UNARY_MINUS_OPERATOR, [folded]) : folded;
242
- }
243
- function lowerTerm(nodes, context) {
244
- return lowerTermItems(termItems(nodes), context);
245
- }
246
- function lowerTermItems(items, context) {
247
- const first = items[0];
248
- if (first === void 0) {
249
- diagnose(context, "latex/construct-unparsed");
250
- return unparsed("");
251
- }
252
- if (first.kind === "node") {
253
- const binder = readBinder(first.node, context);
254
- if (binder.status === "binder") {
255
- const rest = items.slice(1);
256
- const body = rest.length === 0 ? implicitArgument(context) : lowerTermItems(rest, {
257
- ...context,
258
- binders: [binder.binder, ...context.binders]
259
- });
260
- return {
261
- kind: binder.kind,
262
- binder: binder.binder,
263
- lower: binder.lower,
264
- upper: binder.upper,
265
- body
266
- };
267
- }
268
- if (binder.status === "degraded") return unparsed(binder.detail);
269
- const namedFunction = namedFunctionOfOp(first.node);
270
- if (namedFunction !== void 0) {
271
- const rest = items.slice(1);
272
- return app(namedFunction, [rest.length === 0 ? implicitArgument(context) : lowerTermItems(rest, context)]);
273
- }
274
- }
275
- const lowered = lowerTermItem(first, context);
276
- if (items.length > 1) {
277
- const detail = spanOfNodes(context, nodesOfItems(items));
278
- diagnose(context, "latex/juxtaposition-unparsed", detail);
279
- return unparsed(detail);
280
- }
281
- return lowered;
282
- }
283
- function nodesOfItems(items) {
284
- const nodes = [];
285
- for (const item of items) if (item.kind === "node") nodes.push(item.node);
286
- else nodes.push(...item.nodes);
287
- return nodes;
288
- }
289
- function implicitArgument(context) {
290
- diagnose(context, "latex/construct-unparsed");
291
- return unparsed("");
292
- }
293
- function termItems(nodes) {
294
- const items = [];
295
- let digits = [];
296
- let digitNodes = [];
297
- const flushDigits = () => {
298
- if (digits.length > 0) {
299
- items.push({
300
- kind: "number",
301
- literal: digits.join(""),
302
- nodes: digitNodes
303
- });
304
- digits = [];
305
- digitNodes = [];
306
- }
307
- };
308
- for (const node of nodes) {
309
- const text = nodeText(node);
310
- if (node.type === "textord" && text !== void 0 && (numericText(text) || text === ".")) {
311
- digits.push(text);
312
- digitNodes.push(node);
313
- continue;
314
- }
315
- flushDigits();
316
- items.push({
317
- kind: "node",
318
- node
319
- });
320
- }
321
- flushDigits();
322
- return items;
323
- }
324
- function lowerTermItem(item, context) {
325
- if (item.kind === "number") {
326
- const rational = require_latex_rational.decimalToRational(item.literal);
327
- if (rational === void 0) {
328
- diagnose(context, "latex/construct-unparsed", item.literal);
329
- return unparsed(item.literal);
330
- }
331
- return {
332
- kind: "num",
333
- numerator: rational.numerator,
334
- denominator: rational.denominator
335
- };
336
- }
337
- return lowerNode(item.node, context);
338
- }
339
- function lowerNode(node, context) {
340
- switch (node.type) {
341
- case "mathord": {
342
- const glyph = glyphOfNode(node);
343
- return glyph === void 0 ? degradeNode(node, context) : symbolExpression(glyph, context);
344
- }
345
- case "textord": {
346
- const text = nodeText(node);
347
- if (text === void 0) return degradeNode(node, context);
348
- if (/^[0-9]$/.test(text)) return {
349
- kind: "num",
350
- numerator: text,
351
- denominator: "1"
352
- };
353
- const glyph = require_latex_symbols.glyphOfSymbolText(text);
354
- return glyph === void 0 ? degradeNode(node, context) : symbolExpression(glyph, context);
355
- }
356
- case "atom": return degradeNode(node, context);
357
- case "genfrac": return lowerGenfrac(node, context);
358
- case "sqrt": return lowerSqrt(node, context);
359
- case "supsub": return lowerSupsub(node, context);
360
- case "op": return degradeNode(node, context);
361
- case "ordgroup":
362
- case "styling":
363
- case "color": {
364
- const body = node.body;
365
- if (!Array.isArray(body) || !body.every(require_latex_temml.isTemmlNode)) return degradeNode(node, context);
366
- return lowerNodeList(body, context);
367
- }
368
- case "delimiter":
369
- case "leftright": return lowerGrouping(node, context);
370
- case "array": return lowerArray(node, context);
371
- case "text": {
372
- const detail = spanOfNodes(context, [node]);
373
- diagnose(context, "latex/text-unparsed", detail);
374
- return unparsed(detail);
375
- }
376
- default: return degradeNode(node, context);
377
- }
378
- }
379
- function degradeNode(node, context) {
380
- const span = spanOfNodes(context, [node]);
381
- const detail = span !== "" ? span : nodeText(node) ?? node.type;
382
- diagnose(context, "latex/construct-unparsed", detail);
383
- return unparsed(detail);
384
- }
385
- function symbolExpression(glyph, context) {
386
- if (context.binders.includes(glyph)) return {
387
- kind: "sym",
388
- id: glyph
389
- };
390
- return {
391
- kind: "sym",
392
- id: context.resolver.resolve(glyph)
393
- };
394
- }
395
- function lowerGenfrac(node, context) {
396
- const hasBar = node.hasBarLine !== false;
397
- const delimited = node.leftDelim !== null && node.leftDelim !== void 0 || node.rightDelim !== null && node.rightDelim !== void 0;
398
- if (!hasBar || delimited || !require_latex_temml.isTemmlNode(node.numer) || !require_latex_temml.isTemmlNode(node.denom)) {
399
- const detail = spanOfNodes(context, [node]);
400
- diagnose(context, "latex/genfrac-unparsed", detail);
401
- return unparsed(detail);
402
- }
403
- return app("math:divide", [lowerNode(node.numer, context), lowerNode(node.denom, context)]);
404
- }
405
- function lowerSqrt(node, context) {
406
- const index = node.index === null ? void 0 : node.index;
407
- if (!require_latex_temml.isTemmlNode(node.body) || index !== void 0 && !require_latex_temml.isTemmlNode(index)) return degradeNode(node, context);
408
- const body = lowerNode(node.body, context);
409
- if (index === void 0) return app("math:sqrt", [body]);
410
- return app("math:pow", [body, app("math:divide", [{
411
- kind: "num",
412
- numerator: "1",
413
- denominator: "1"
414
- }, lowerNode(index, context)])]);
415
- }
416
- function lowerGrouping(node, context) {
417
- const body = node.body;
418
- if (!Array.isArray(body) || !body.every(require_latex_temml.isTemmlNode)) return degradeNode(node, context);
419
- if (body.length === 1) {
420
- const only = body[0];
421
- if (only?.type === "array") return lowerArray(only, context);
422
- }
423
- return lowerNodeList(body, context);
424
- }
425
- function lowerArray(node, context) {
426
- const separated = Array.isArray(node.cols) && node.cols.some((col) => !require_latex_temml.isTemmlNode(col) || col.type === "separator");
427
- const body = node.body;
428
- const envClasses = node.envClasses;
429
- const layoutEnvironment = Array.isArray(envClasses) && envClasses.length > 0;
430
- if (layoutEnvironment || separated || !Array.isArray(body)) {
431
- const detail = spanOfNodes(context, [node]);
432
- diagnose(context, layoutEnvironment ? "latex/array-environment-unparsed" : "latex/construct-unparsed", detail);
433
- return unparsed(detail);
434
- }
435
- const rows = [];
436
- for (const row of body) {
437
- if (!Array.isArray(row) || !row.every(require_latex_temml.isTemmlNode)) return degradeNode(node, context);
438
- rows.push(row.map((cell) => lowerNode(cell, context)));
439
- }
440
- if (rows.length > 0 && new Set(rows.map((row) => row.length)).size > 1) {
441
- const detail = spanOfNodes(context, [node]);
442
- diagnose(context, "latex/construct-unparsed", detail);
443
- return unparsed(detail);
444
- }
445
- return {
446
- kind: "matrix",
447
- rows
448
- };
449
- }
450
- function lowerSupsub(node, context) {
451
- const binder = readBinder(node, context);
452
- if (binder.status === "binder") return {
453
- kind: binder.kind,
454
- binder: binder.binder,
455
- lower: binder.lower,
456
- upper: binder.upper,
457
- body: implicitArgument(context)
458
- };
459
- if (binder.status === "degraded") return unparsed(binder.detail);
460
- const detail = spanOfNodes(context, [node]);
461
- const base = require_latex_temml.isTemmlNode(node.base) ? node.base : void 0;
462
- const sub = nodesOfScript(node.sub);
463
- const sup = nodesOfScript(node.sup);
464
- if (sub !== void 0) {
465
- const subWritten = simpleScriptGlyph(sub);
466
- const baseGlyph = base !== void 0 && (base.type === "mathord" || base.type === "textord") ? glyphOfNode(base) : void 0;
467
- if (baseGlyph === void 0 || subWritten === void 0) {
468
- diagnose(context, "latex/subscript-unparsed", detail);
469
- return unparsed(detail);
470
- }
471
- const subscriptedGlyph = `${baseGlyph}_${subWritten}`;
472
- if (sup === void 0) return symbolExpression(subscriptedGlyph, context);
473
- const tripleGlyph = `${subscriptedGlyph}^${scriptWrittenForm(sup, context)}`;
474
- if (context.resolver.isCurated(tripleGlyph)) return symbolExpression(tripleGlyph, context);
475
- return app("math:pow", [symbolExpression(subscriptedGlyph, context), lowerNodeList(sup, context)]);
476
- }
477
- if (sup === void 0) return degradeNode(node, context);
478
- const exponent = lowerNodeList(sup, context);
479
- if (base === void 0) return degradeNode(node, context);
480
- if (base.type !== "mathord" && base.type !== "textord") {
481
- const loweredBase = lowerNode(base, context);
482
- if (loweredBase.kind === "unparsed") {
483
- diagnose(context, "latex/script-base-unparsed", detail);
484
- return unparsed(detail);
485
- }
486
- return app("math:pow", [loweredBase, exponent]);
487
- }
488
- const baseGlyph = glyphOfNode(base);
489
- if (baseGlyph === void 0) return degradeNode(node, context);
490
- const scriptedGlyph = `${baseGlyph}^${scriptWrittenForm(sup, context)}`;
491
- if (context.resolver.isCurated(scriptedGlyph)) return symbolExpression(scriptedGlyph, context);
492
- return app("math:pow", [symbolExpression(baseGlyph, context), exponent]);
493
- }
494
- function scriptWrittenForm(nodes, context) {
495
- const span = spanOfNodes(context, nodes);
496
- if (span !== "") return span;
497
- return nodes.map((node) => glyphOfNode(node) ?? nodeText(node) ?? "").join("");
498
- }
499
- function simpleScriptGlyph(nodes) {
500
- const parts = [];
501
- for (const node of nodes) {
502
- const text = nodeText(node);
503
- if (node.type === "mathord") {
504
- const glyph = glyphOfNode(node);
505
- if (glyph === void 0) return;
506
- parts.push(glyph);
507
- continue;
508
- }
509
- if (node.type === "textord" && text !== void 0 && /^[0-9A-Za-z]$/.test(text)) {
510
- parts.push(text);
511
- continue;
512
- }
513
- return;
514
- }
515
- return parts.length === 0 ? void 0 : parts.join("");
516
- }
517
- function readBinder(node, context) {
518
- if (node.type !== "supsub") return { status: "not-a-binder" };
519
- const base = require_latex_temml.isTemmlNode(node.base) ? node.base : void 0;
520
- if (base?.type !== "op" || base.symbol !== true || typeof base.name !== "string") return { status: "not-a-binder" };
521
- if (base.name !== "\\sum" && base.name !== "\\prod") return { status: "not-a-binder" };
522
- const kind = base.name === "\\sum" ? "sum" : "prod";
523
- const detail = spanOfNodes(context, [node]);
524
- const sub = nodesOfScript(node.sub);
525
- const sup = nodesOfScript(node.sup);
526
- const upper = sup === void 0 ? implicitBound(context) : lowerNodeList(sup, context);
527
- if ((sub?.length ?? 0) >= RELATION_SUBSCRIPT_MIN_NODES) {
528
- const first = sub?.[0];
529
- const relation = sub?.[1];
530
- const rest = sub?.slice(2) ?? [];
531
- const firstGlyph = first?.type === "mathord" ? glyphOfNode(first) : void 0;
532
- if (firstGlyph !== void 0 && relation?.type === "atom" && nodeText(relation) === "=") return {
533
- status: "binder",
534
- kind,
535
- binder: firstGlyph,
536
- lower: lowerNodeList(rest, context),
537
- upper
538
- };
539
- }
540
- if (sub?.length === 1) {
541
- const singleGlyph = simpleScriptGlyph(sub);
542
- if (singleGlyph !== void 0) {
543
- diagnose(context, "latex/binder-bound-implicit", detail);
544
- return {
545
- status: "binder",
546
- kind,
547
- binder: singleGlyph,
548
- lower: unparsed(""),
549
- upper
550
- };
551
- }
552
- }
553
- diagnose(context, "latex/binder-bound-unreadable", detail);
554
- return {
555
- status: "degraded",
556
- detail
557
- };
558
- }
559
- function implicitBound(context) {
560
- diagnose(context, "latex/binder-bound-implicit");
561
- return unparsed("");
562
- }
563
- function namedFunctionOfOp(node) {
564
- if (node.type !== "op" || node.symbol === true) return;
565
- const name = typeof node.name === "string" ? node.name : void 0;
566
- return name === void 0 ? void 0 : NAMED_FUNCTION_OPERATORS[name];
567
- }
568
- function lowerLatex(latex, options) {
569
- return lowerParsed(latex, require_latex_temml.parseLatex(latex), options);
570
- }
571
- function lowerParsed(latex, parsed, options) {
572
- if (latex.trim() === "") return {
573
- expression: unparsed(""),
574
- diagnostics: [],
575
- mintedSymbols: []
576
- };
577
- const resolver = new require_latex_symbols.SymbolResolver(options?.symbolEntries ?? []);
578
- const context = {
579
- input: latex,
580
- resolver,
581
- binders: [],
582
- diagnostics: [],
583
- sink: options?.sink
584
- };
585
- if (parsed.status === "unparseable") {
586
- diagnose(context, "latex/parse-error", parsed.message);
587
- return {
588
- expression: unparsed(latex),
589
- diagnostics: context.diagnostics,
590
- mintedSymbols: resolver.mintedEntries()
591
- };
592
- }
593
- return {
594
- expression: lowerNodeList(parsed.nodes, context),
595
- diagnostics: context.diagnostics,
596
- mintedSymbols: resolver.mintedEntries()
597
- };
598
- }
599
- function latexToFormula(latex, options) {
600
- const parsed = require_latex_temml.parseLatex(latex);
601
- const lowering = lowerParsed(latex, parsed, options);
602
- return {
603
- formula: {
604
- mathml: parsed.status === "parsed" ? [...parsed.mathml] : [],
605
- presentation: { latex },
606
- content: lowering.expression,
607
- provenance: {
608
- source: options?.source ?? "lowered:latex",
609
- editTrail: []
610
- }
611
- },
612
- diagnostics: lowering.diagnostics,
613
- mintedSymbols: lowering.mintedSymbols
614
- };
615
- }
616
- //#endregion
617
- exports.latexToFormula = latexToFormula;
618
- exports.lowerLatex = lowerLatex;
2
+ const require_lower = require("../lower-DzOb13w4.cjs");
3
+ exports.RELATION_ATOM_OPERATORS = require_lower.RELATION_ATOM_OPERATORS;
4
+ exports.RELATION_OPERATORS = require_lower.RELATION_OPERATORS;
5
+ exports.SUBTRACT_OPERATOR = require_lower.SUBTRACT_OPERATOR;
6
+ exports.UNARY_MINUS_OPERATOR = require_lower.UNARY_MINUS_OPERATOR;
7
+ exports.app = require_lower.app;
8
+ exports.diagnose = require_lower.diagnose;
9
+ exports.latexToFormula = require_lower.latexToFormula;
10
+ exports.lowerLatex = require_lower.lowerLatex;
11
+ exports.lowerTerm = require_lower.lowerTerm;
12
+ exports.unparsed = require_lower.unparsed;
@@ -1,6 +1,23 @@
1
1
  import { i as LatexDiagnosticSink, n as LatexDiagnostic } from "../diagnostics-DdO0xPGy.cjs";
2
+ import { n as TemmlNode } from "../temml-1-I9N9DD.cjs";
3
+ import { t as SymbolResolver } from "../symbols-BlzXfLEe.cjs";
2
4
  import { ContentFormula, MathExpression, MathSymbolEntry } from "document-schema.js";
3
5
  //#region src/latex/lower.d.ts
6
+ declare const RELATION_ATOM_OPERATORS: Readonly<Record<string, string>>;
7
+ declare const SUBTRACT_OPERATOR = "math:subtract";
8
+ declare const UNARY_MINUS_OPERATOR = "math:negate";
9
+ declare const RELATION_OPERATORS: ReadonlySet<string>;
10
+ interface LoweringContext {
11
+ readonly input: string;
12
+ readonly resolver: SymbolResolver;
13
+ readonly binders: readonly string[];
14
+ readonly diagnostics: LatexDiagnostic[];
15
+ readonly sink?: LatexDiagnosticSink;
16
+ }
17
+ declare function diagnose(context: LoweringContext, code: LatexDiagnostic["code"], detail?: string): void;
18
+ declare function unparsed(latex: string): MathExpression;
19
+ declare function app(operator: string, args: readonly MathExpression[]): MathExpression;
20
+ declare function lowerTerm(nodes: readonly TemmlNode[], context: LoweringContext): MathExpression;
4
21
  interface LowerLatexOptions {
5
22
  readonly symbolEntries?: readonly MathSymbolEntry[];
6
23
  readonly sink?: LatexDiagnosticSink;
@@ -21,4 +38,4 @@ interface LatexFormulaResult {
21
38
  }
22
39
  declare function latexToFormula(latex: string, options?: LatexFormulaOptions): LatexFormulaResult;
23
40
  //#endregion
24
- export { LatexFormulaOptions, LatexFormulaResult, LatexLoweringResult, LowerLatexOptions, latexToFormula, lowerLatex };
41
+ export { LatexFormulaOptions, LatexFormulaResult, LatexLoweringResult, LowerLatexOptions, LoweringContext, RELATION_ATOM_OPERATORS, RELATION_OPERATORS, SUBTRACT_OPERATOR, UNARY_MINUS_OPERATOR, app, diagnose, latexToFormula, lowerLatex, lowerTerm, unparsed };
@@ -1,6 +1,23 @@
1
1
  import { i as LatexDiagnosticSink, n as LatexDiagnostic } from "../diagnostics-DdO0xPGy.js";
2
+ import { n as TemmlNode } from "../temml-1-I9N9DD.js";
3
+ import { t as SymbolResolver } from "../symbols-CKm2r4D0.js";
2
4
  import { ContentFormula, MathExpression, MathSymbolEntry } from "document-schema.js";
3
5
  //#region src/latex/lower.d.ts
6
+ declare const RELATION_ATOM_OPERATORS: Readonly<Record<string, string>>;
7
+ declare const SUBTRACT_OPERATOR = "math:subtract";
8
+ declare const UNARY_MINUS_OPERATOR = "math:negate";
9
+ declare const RELATION_OPERATORS: ReadonlySet<string>;
10
+ interface LoweringContext {
11
+ readonly input: string;
12
+ readonly resolver: SymbolResolver;
13
+ readonly binders: readonly string[];
14
+ readonly diagnostics: LatexDiagnostic[];
15
+ readonly sink?: LatexDiagnosticSink;
16
+ }
17
+ declare function diagnose(context: LoweringContext, code: LatexDiagnostic["code"], detail?: string): void;
18
+ declare function unparsed(latex: string): MathExpression;
19
+ declare function app(operator: string, args: readonly MathExpression[]): MathExpression;
20
+ declare function lowerTerm(nodes: readonly TemmlNode[], context: LoweringContext): MathExpression;
4
21
  interface LowerLatexOptions {
5
22
  readonly symbolEntries?: readonly MathSymbolEntry[];
6
23
  readonly sink?: LatexDiagnosticSink;
@@ -21,4 +38,4 @@ interface LatexFormulaResult {
21
38
  }
22
39
  declare function latexToFormula(latex: string, options?: LatexFormulaOptions): LatexFormulaResult;
23
40
  //#endregion
24
- export { LatexFormulaOptions, LatexFormulaResult, LatexLoweringResult, LowerLatexOptions, latexToFormula, lowerLatex };
41
+ export { LatexFormulaOptions, LatexFormulaResult, LatexLoweringResult, LowerLatexOptions, LoweringContext, RELATION_ATOM_OPERATORS, RELATION_OPERATORS, SUBTRACT_OPERATOR, UNARY_MINUS_OPERATOR, app, diagnose, latexToFormula, lowerLatex, lowerTerm, unparsed };