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,647 +1,2 @@
1
- import { el } from "../../xml/fragment.js";
2
- import { removeAttr, removeChild, setAttr } from "../../xml/edit.js";
3
- import { resolveLiveTableGrid } from "../table-grid.js";
4
- import { ensureAutomaticStyles, nextStyleName } from "./automatic-styles.js";
5
- import { OdtParagraph, buildParagraph } from "./paragraph.js";
6
- import { COLUMN_REPEAT_ATTR, collectRunMembers, isCellOrCoveredCell, readRunRepeatCount, replaceRun } from "../odf-repeated-runs.js";
7
- import { attr } from "ooxml.js";
8
- import { tableCellColumnSpan, tableCellRowSpan } from "document-schema.js";
9
- import { findStyleElement, formatOdfColor, formatOdfLength, parseOdfColor, parseOdfLength } from "odf.js";
10
- //#region src/edit/odt/table.ts
11
- const DEFAULT_TABLE_WIDTH_PT = 468;
12
- const TABLE_COLUMN_STYLE_PREFIX = "OdtCol";
13
- const TABLE_CELL_STYLE_PREFIX = "OdtCell";
14
- const TABLE_ROW_STYLE_PREFIX = "OdtRow";
15
- const BORDER_EDGE_ATTRS = {
16
- top: "fo:border-top",
17
- right: "fo:border-right",
18
- bottom: "fo:border-bottom",
19
- left: "fo:border-left"
20
- };
21
- function formatBorderShorthand(color, widthPt, style) {
22
- return `${formatOdfLength(widthPt)} ${style ?? "solid"} ${formatOdfColor(color)}`;
23
- }
24
- function findCellPropertiesReadOnly(pkg, element) {
25
- const styleName = attr(element, "table:style-name");
26
- if (styleName === void 0) return;
27
- const part = pkg.parts["content.xml"];
28
- const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
29
- if (root === void 0) return;
30
- for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") {
31
- for (const style of child.children) if (style.type === "element" && style.tag === "style:style" && attr(style, "style:name") === styleName && attr(style, "style:family") === "table-cell") {
32
- for (const props of style.children) if (props.type === "element" && props.tag === "style:table-cell-properties") return props;
33
- }
34
- }
35
- }
36
- function readCellDecoration(pkg, element) {
37
- const props = findCellPropertiesReadOnly(pkg, element);
38
- if (props === void 0) return {};
39
- let background;
40
- const backgroundValue = attr(props, "fo:background-color");
41
- if (backgroundValue !== void 0) background = parseOdfColor(backgroundValue);
42
- const borders = {};
43
- [
44
- "top",
45
- "right",
46
- "bottom",
47
- "left"
48
- ].forEach((edge) => {
49
- const raw = attr(props, BORDER_EDGE_ATTRS[edge]);
50
- if (raw === void 0) return;
51
- const tokens = raw.trim().split(/\s+/);
52
- const widthToken = tokens[0];
53
- const styleToken = tokens[1];
54
- const colorToken = tokens[2];
55
- if (widthToken === void 0 || styleToken === void 0 || colorToken === void 0 || styleToken === "none" || styleToken === "hidden") return;
56
- const widthPt = parseOdfLength(widthToken);
57
- const color = parseOdfColor(colorToken);
58
- if (widthPt === void 0 || widthPt <= 0 || color === void 0) return;
59
- const style = styleToken === "solid" || styleToken === "dashed" || styleToken === "dotted" || styleToken === "double" ? styleToken : void 0;
60
- borders[edge] = style === void 0 ? {
61
- color,
62
- widthPt
63
- } : {
64
- color,
65
- widthPt,
66
- style
67
- };
68
- });
69
- return {
70
- background,
71
- borders: Object.keys(borders).length === 0 ? void 0 : borders
72
- };
73
- }
74
- function buildCellStyle(pkg, decoration) {
75
- const automaticStyles = ensureAutomaticStyles(pkg);
76
- const name = nextStyleName(automaticStyles, "style:style", TABLE_CELL_STYLE_PREFIX);
77
- const propsAttrs = {};
78
- if (decoration.background !== void 0) propsAttrs["fo:background-color"] = formatOdfColor(decoration.background);
79
- if (decoration.borders !== void 0) [
80
- "top",
81
- "right",
82
- "bottom",
83
- "left"
84
- ].forEach((edge) => {
85
- const border = decoration.borders[edge];
86
- if (border !== void 0) propsAttrs[BORDER_EDGE_ATTRS[edge]] = formatBorderShorthand(border.color, border.widthPt, border.style);
87
- });
88
- const properties = Object.keys(propsAttrs).length === 0 ? [] : [el("style:table-cell-properties", propsAttrs)];
89
- automaticStyles.children.push(el("style:style", {
90
- "style:name": name,
91
- "style:family": "table-cell"
92
- }, properties));
93
- return name;
94
- }
95
- function internTableColumnWidth(pkg, widthPt) {
96
- const automaticStyles = ensureAutomaticStyles(pkg);
97
- const formatted = formatOdfLength(widthPt, "pt");
98
- for (const child of automaticStyles.children) {
99
- if (child.type !== "element" || child.tag !== "style:style" || attr(child, "style:family") !== "table-column") continue;
100
- const props = child.children.find((c) => c.type === "element" && c.tag === "style:table-column-properties");
101
- if (props !== void 0 && attr(props, "style:column-width") === formatted) {
102
- const existingName = attr(child, "style:name");
103
- if (existingName !== void 0) return existingName;
104
- }
105
- }
106
- const name = nextStyleName(automaticStyles, "style:style", TABLE_COLUMN_STYLE_PREFIX);
107
- automaticStyles.children.push(el("style:style", {
108
- "style:name": name,
109
- "style:family": "table-column"
110
- }, [el("style:table-column-properties", { "style:column-width": formatted })]));
111
- return name;
112
- }
113
- function currentRowPropertiesElement(pkg, rowElement) {
114
- const styleName = attr(rowElement, "table:style-name");
115
- const styleElement = styleName === void 0 ? void 0 : findStyleElement(styleName, "table-row", pkg);
116
- return styleElement === void 0 ? void 0 : styleElement.children.find((c) => c.type === "element" && c.tag === "style:table-row-properties");
117
- }
118
- function cloneCurrentRowProperties(pkg, rowElement) {
119
- const props = currentRowPropertiesElement(pkg, rowElement);
120
- return props === void 0 ? el("style:table-row-properties") : structuredClone(props);
121
- }
122
- function xmlNodesEqual(a, b) {
123
- if (a.type === "element" && b.type === "element") return xmlElementsEqual(a, b);
124
- if (a.type === "text" && b.type === "text") return a.value === b.value;
125
- if (a.type === "cdata" && b.type === "cdata") return a.value === b.value;
126
- if (a.type === "comment" && b.type === "comment") return a.value === b.value;
127
- return false;
128
- }
129
- function xmlElementsEqual(a, b) {
130
- if (a.tag !== b.tag || a.attributes.length !== b.attributes.length) return false;
131
- if (!a.attributes.every((candidate) => attr(b, candidate.name) === candidate.value)) return false;
132
- if (a.children.length !== b.children.length) return false;
133
- for (let index = 0; index < a.children.length; index++) {
134
- const childA = a.children[index];
135
- const childB = b.children[index];
136
- if (childA === void 0 || childB === void 0) return false;
137
- if (!xmlNodesEqual(childA, childB)) return false;
138
- }
139
- return true;
140
- }
141
- function internTableRowProperties(pkg, properties) {
142
- const automaticStyles = ensureAutomaticStyles(pkg);
143
- for (const child of automaticStyles.children) {
144
- if (child.type !== "element" || child.tag !== "style:style" || attr(child, "style:family") !== "table-row") continue;
145
- const props = child.children.find((c) => c.type === "element" && c.tag === "style:table-row-properties");
146
- if (props !== void 0 && xmlElementsEqual(props, properties)) {
147
- const existingName = attr(child, "style:name");
148
- if (existingName !== void 0) return existingName;
149
- }
150
- }
151
- const name = nextStyleName(automaticStyles, "style:style", TABLE_ROW_STYLE_PREFIX);
152
- automaticStyles.children.push(el("style:style", {
153
- "style:name": name,
154
- "style:family": "table-row"
155
- }, [properties]));
156
- return name;
157
- }
158
- var OdtTableCell = class {
159
- node;
160
- pkg;
161
- constructor(node, pkg) {
162
- this.node = node;
163
- this.pkg = pkg;
164
- }
165
- paragraphs() {
166
- const out = [];
167
- for (const child of this.node.children) if (child.type === "element" && (child.tag === "text:p" || child.tag === "text:h")) out.push(new OdtParagraph(this.node.children, child, this.pkg));
168
- return out;
169
- }
170
- appendParagraph(init) {
171
- const paragraphElement = buildParagraph(this.pkg, init);
172
- this.node.children.push(paragraphElement);
173
- return new OdtParagraph(this.node.children, paragraphElement, this.pkg);
174
- }
175
- get text() {
176
- return this.paragraphs().map((p) => p.text).join("\n");
177
- }
178
- get colSpan() {
179
- const raw = attr(this.node, "table:number-columns-spanned");
180
- return raw === void 0 ? void 0 : Number(raw);
181
- }
182
- set colSpan(value) {
183
- if (value === void 0) {
184
- removeAttr(this.node, "table:number-columns-spanned");
185
- return;
186
- }
187
- setAttr(this.node, "table:number-columns-spanned", String(value));
188
- }
189
- get rowSpan() {
190
- const raw = attr(this.node, "table:number-rows-spanned");
191
- return raw === void 0 ? void 0 : Number(raw);
192
- }
193
- set rowSpan(value) {
194
- if (value === void 0) {
195
- removeAttr(this.node, "table:number-rows-spanned");
196
- return;
197
- }
198
- setAttr(this.node, "table:number-rows-spanned", String(value));
199
- }
200
- get background() {
201
- return readCellDecoration(this.pkg, this.node).background;
202
- }
203
- set background(value) {
204
- writeCellBackground(this.pkg, this.node, value);
205
- }
206
- get borders() {
207
- return readCellDecoration(this.pkg, this.node).borders;
208
- }
209
- set borders(value) {
210
- writeCellBorders(this.pkg, this.node, value);
211
- }
212
- };
213
- function writeCellBackground(pkg, node, value) {
214
- const name = buildCellStyle(pkg, {
215
- background: value,
216
- borders: readCellDecoration(pkg, node).borders
217
- });
218
- setAttr(node, "table:style-name", name);
219
- }
220
- function writeCellBorders(pkg, node, value) {
221
- const name = buildCellStyle(pkg, {
222
- background: readCellDecoration(pkg, node).background,
223
- borders: value
224
- });
225
- setAttr(node, "table:style-name", name);
226
- }
227
- var OdtCoveredTableCell = class {
228
- node;
229
- pkg;
230
- constructor(node, pkg) {
231
- this.node = node;
232
- this.pkg = pkg;
233
- }
234
- get background() {
235
- return readCellDecoration(this.pkg, this.node).background;
236
- }
237
- set background(value) {
238
- writeCellBackground(this.pkg, this.node, value);
239
- }
240
- get borders() {
241
- return readCellDecoration(this.pkg, this.node).borders;
242
- }
243
- set borders(value) {
244
- writeCellBorders(this.pkg, this.node, value);
245
- }
246
- };
247
- const COVERED_CELL_KEPT_ATTRIBUTE = "table:style-name";
248
- function retagAsCovered(element) {
249
- element.tag = "table:covered-table-cell";
250
- element.attributes = element.attributes.filter((attribute) => attribute.name === COVERED_CELL_KEPT_ATTRIBUTE);
251
- element.children = [];
252
- }
253
- function gridColumnElements(row) {
254
- const out = [];
255
- let columnIndex = 0;
256
- for (const member of collectRunMembers(row.children, isCellOrCoveredCell, void 0)) {
257
- const repeat = readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR);
258
- for (let offset = 0; offset < repeat; offset++) out.push({
259
- columnIndex: columnIndex + offset,
260
- element: member.node
261
- });
262
- columnIndex += repeat;
263
- }
264
- return out;
265
- }
266
- function rowGridColumnCount(row) {
267
- return collectRunMembers(row.children, isCellOrCoveredCell, void 0).reduce((sum, member) => sum + readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR), 0);
268
- }
269
- function locateGridColumnElement(row, columnIndex) {
270
- if (columnIndex < 0) return;
271
- let cursor = 0;
272
- for (const member of collectRunMembers(row.children, isCellOrCoveredCell, void 0)) {
273
- const count = readRunRepeatCount(member.node, COLUMN_REPEAT_ATTR);
274
- if (columnIndex < cursor + count) return member.node;
275
- cursor += count;
276
- }
277
- }
278
- function individuateGridColumn(row, columnIndex) {
279
- return replaceRun(row.children, isCellOrCoveredCell, columnIndex, COLUMN_REPEAT_ATTR, () => {
280
- throw new Error(`individuateGridColumn: column ${columnIndex} has no existing element to individuate in this row — callers must bounds-check against rowGridColumnCount first`);
281
- });
282
- }
283
- function tableRowElements(table) {
284
- return tableRowEntries(table).map((entry) => entry.element);
285
- }
286
- function placedCells(row, pkg) {
287
- return gridColumnElements(row).flatMap(({ columnIndex, element }) => {
288
- if (element.tag !== "table:table-cell") return [];
289
- const cell = new OdtTableCell(element, pkg);
290
- return [{
291
- columnIndex,
292
- cell,
293
- colSpan: cell.colSpan,
294
- rowSpan: cell.rowSpan
295
- }];
296
- });
297
- }
298
- function resolveOdtGrid(table, pkg) {
299
- const placedRows = [];
300
- let declaredColumns = 0;
301
- for (const column of tableColumnElements(table)) declaredColumns += readRunRepeatCount(column, COLUMN_REPEAT_ATTR);
302
- for (const row of tableRowElements(table)) placedRows.push(placedCells(row, pkg));
303
- return resolveLiveTableGrid(placedRows, declaredColumns);
304
- }
305
- function regionCovers(region, rowIndex, columnIndex) {
306
- return region.row <= rowIndex && rowIndex < region.row + region.rowSpan && region.column <= columnIndex && columnIndex < region.column + region.columnSpan;
307
- }
308
- function regionsIntersect(a, b) {
309
- return a.row < b.row + b.rowSpan && b.row < a.row + a.rowSpan && a.column < b.column + b.columnSpan && b.column < a.column + a.columnSpan;
310
- }
311
- function regionContains(outer, inner) {
312
- return outer.row <= inner.row && outer.column <= inner.column && inner.row + inner.rowSpan <= outer.row + outer.rowSpan && inner.column + inner.columnSpan <= outer.column + outer.columnSpan;
313
- }
314
- function anchorRegions(grid) {
315
- return grid.rows.flatMap((positions, row) => positions.flatMap((position, column) => {
316
- if (position?.isAnchor !== true) return [];
317
- const spans = {
318
- blocks: [],
319
- colSpan: position.cell.colSpan,
320
- rowSpan: position.cell.rowSpan
321
- };
322
- return [{
323
- row,
324
- column,
325
- rowSpan: tableCellRowSpan(spans),
326
- columnSpan: tableCellColumnSpan(spans)
327
- }];
328
- }));
329
- }
330
- function isUnchangedAnchor(region, target) {
331
- return target.rowSpan === 1 && region.column === target.column && region.columnSpan === target.columnSpan;
332
- }
333
- function describeRegionAnchor(region) {
334
- return `the merge anchored at row ${region.row}, column ${region.column}`;
335
- }
336
- function refuseMerge(rowIndex, reason) {
337
- return { refusal: {
338
- rowIndex,
339
- reason
340
- } };
341
- }
342
- function planMerge(table, pkg, target, rows) {
343
- const [anchorRow, ...coveredRows] = rows;
344
- const anchorElement = locateGridColumnElement(anchorRow, target.column);
345
- if (anchorElement === void 0) return refuseMerge(target.row, `column ${target.column} does not exist in this row`);
346
- const endColumn = target.column + target.columnSpan;
347
- for (const [offset, row] of rows.entries()) {
348
- const totalColumns = rowGridColumnCount(row);
349
- if (endColumn > totalColumns) return refuseMerge(target.row + offset, `colSpan ${target.columnSpan} starting at column ${target.column} exceeds this row's own ${totalColumns} grid columns`);
350
- }
351
- const regions = anchorRegions(resolveOdtGrid(table, pkg));
352
- if (anchorElement.tag === "table:covered-table-cell") {
353
- const covering = regions.find((region) => regionCovers(region, target.row, target.column));
354
- return refuseMerge(target.row, covering === void 0 ? `column ${target.column} is a covered position that no merge anchors` : `column ${target.column} is covered by ${describeRegionAnchor(covering)}`);
355
- }
356
- const cutting = regions.find((region) => regionsIntersect(region, target) && !regionContains(target, region) && !isUnchangedAnchor(region, target));
357
- if (cutting !== void 0) {
358
- const column = Math.max(cutting.column, target.column);
359
- return refuseMerge(Math.max(cutting.row, target.row), `column ${column} belongs to ${describeRegionAnchor(cutting)}, which reaches outside the region being merged and cannot be merged over`);
360
- }
361
- const consumed = [];
362
- for (let column = target.column + 1; column < endColumn; column++) consumed.push({
363
- row: anchorRow,
364
- column
365
- });
366
- for (const row of coveredRows) for (let column = target.column; column < endColumn; column++) consumed.push({
367
- row,
368
- column
369
- });
370
- return {
371
- anchor: {
372
- row: anchorRow,
373
- column: target.column
374
- },
375
- consumed
376
- };
377
- }
378
- function applyMerge(plan, target, pkg) {
379
- for (const position of plan.consumed) retagAsCovered(individuateGridColumn(position.row, position.column));
380
- const anchor = new OdtTableCell(individuateGridColumn(plan.anchor.row, plan.anchor.column), pkg);
381
- anchor.colSpan = target.columnSpan;
382
- if (target.rowSpan > 1) anchor.rowSpan = target.rowSpan;
383
- return anchor;
384
- }
385
- const ROW_WRAPPER_TAGS = /* @__PURE__ */ new Set([
386
- "table:table-rows",
387
- "table:table-header-rows",
388
- "table:table-row-group"
389
- ]);
390
- function tableRowEntries(parent, insideHeader = false) {
391
- const entries = [];
392
- for (const child of parent.children) {
393
- if (child.type !== "element") continue;
394
- if (child.tag === "table:table-row") entries.push({
395
- element: child,
396
- insideHeader
397
- });
398
- else if (ROW_WRAPPER_TAGS.has(child.tag)) entries.push(...tableRowEntries(child, insideHeader || child.tag === "table:table-header-rows"));
399
- }
400
- return entries;
401
- }
402
- const COLUMN_WRAPPER_TAGS = /* @__PURE__ */ new Set([
403
- "table:table-columns",
404
- "table:table-header-columns",
405
- "table:table-column-group"
406
- ]);
407
- function tableColumnEntries(parent, insideHeader = false) {
408
- const entries = [];
409
- for (const child of parent.children) {
410
- if (child.type !== "element") continue;
411
- if (child.tag === "table:table-column") entries.push({
412
- element: child,
413
- insideHeader
414
- });
415
- else if (COLUMN_WRAPPER_TAGS.has(child.tag)) entries.push(...tableColumnEntries(child, insideHeader || child.tag === "table:table-header-columns"));
416
- }
417
- return entries;
418
- }
419
- function tableColumnElements(table) {
420
- return tableColumnEntries(table).map((entry) => entry.element);
421
- }
422
- var OdtTableRow = class {
423
- node;
424
- pkg;
425
- table;
426
- constructor(node, pkg, table) {
427
- this.node = node;
428
- this.pkg = pkg;
429
- this.table = table;
430
- }
431
- cells() {
432
- const out = [];
433
- for (const child of this.node.children) if (child.type === "element" && child.tag === "table:table-cell") out.push(new OdtTableCell(child, this.pkg));
434
- return out;
435
- }
436
- get heightPt() {
437
- const props = currentRowPropertiesElement(this.pkg, this.node);
438
- const raw = props === void 0 ? void 0 : attr(props, "style:row-height");
439
- return raw === void 0 ? void 0 : parseOdfLength(raw);
440
- }
441
- set heightPt(value) {
442
- const props = cloneCurrentRowProperties(this.pkg, this.node);
443
- if (value === void 0) removeAttr(props, "style:row-height");
444
- else {
445
- setAttr(props, "style:row-height", formatOdfLength(value, "pt"));
446
- if (attr(props, "style:use-optimal-row-height") === "true") setAttr(props, "style:use-optimal-row-height", "false");
447
- }
448
- if (props.attributes.length === 0 && props.children.length === 0) {
449
- removeAttr(this.node, "table:style-name");
450
- return;
451
- }
452
- setAttr(this.node, "table:style-name", internTableRowProperties(this.pkg, props));
453
- }
454
- appendCell() {
455
- const cellElement = buildCell(this.pkg);
456
- this.node.children.push(cellElement);
457
- return new OdtTableCell(cellElement, this.pkg);
458
- }
459
- appendCoveredCell() {
460
- const coveredElement = el("table:covered-table-cell");
461
- this.node.children.push(coveredElement);
462
- return new OdtCoveredTableCell(coveredElement, this.pkg);
463
- }
464
- mergeCellsHorizontally(startColumnIndex, colSpan) {
465
- if (!Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCellsHorizontally: colSpan must be a positive integer, got ${colSpan}`);
466
- const target = {
467
- row: tableRowElements(this.table).indexOf(this.node),
468
- column: startColumnIndex,
469
- rowSpan: 1,
470
- columnSpan: colSpan
471
- };
472
- const plan = planMerge(this.table, this.pkg, target, [this.node]);
473
- if (plan.refusal !== void 0) throw new Error(`mergeCellsHorizontally: ${plan.refusal.reason}`);
474
- return applyMerge(plan, target, this.pkg);
475
- }
476
- markCellCovered(columnIndex) {
477
- const totalColumns = rowGridColumnCount(this.node);
478
- if (columnIndex < 0 || columnIndex >= totalColumns) throw new Error(`markCellCovered: column ${columnIndex} does not exist in this row`);
479
- const rowIndex = tableRowElements(this.table).indexOf(this.node);
480
- const anchored = anchorRegions(resolveOdtGrid(this.table, this.pkg)).find((region) => region.row === rowIndex && region.column === columnIndex && (region.rowSpan > 1 || region.columnSpan > 1));
481
- if (anchored !== void 0) throw new Error(`markCellCovered: column ${columnIndex} anchors a merge with rowSpan ${anchored.rowSpan} and colSpan ${anchored.columnSpan}, so covering it would leave the rest of that merge without an anchor`);
482
- retagAsCovered(individuateGridColumn(this.node, columnIndex));
483
- }
484
- };
485
- function buildCell(pkg) {
486
- return el("table:table-cell", {}, [buildParagraph(pkg)]);
487
- }
488
- function buildRow(pkg, columnCount) {
489
- const cells = [];
490
- for (let i = 0; i < columnCount; i++) cells.push(buildCell(pkg));
491
- return el("table:table-row", {}, cells);
492
- }
493
- var OdtTable = class {
494
- container;
495
- node;
496
- pkg;
497
- removed = false;
498
- constructor(container, node, pkg) {
499
- this.container = container;
500
- this.node = node;
501
- this.pkg = pkg;
502
- }
503
- live() {
504
- if (this.removed) throw new Error("this OdtTable has been removed and can no longer be used");
505
- return this.node;
506
- }
507
- rows() {
508
- return tableRowElements(this.live()).map((row) => new OdtTableRow(row, this.pkg, this.node));
509
- }
510
- headerRows() {
511
- return tableRowEntries(this.live()).map((entry) => entry.insideHeader);
512
- }
513
- setHeaderRows(flags) {
514
- const table = this.live();
515
- const rows = tableRowElements(table);
516
- const regrouped = [];
517
- let run = [];
518
- const closeRun = () => {
519
- if (run.length > 0) {
520
- regrouped.push(el("table:table-header-rows", {}, run));
521
- run = [];
522
- }
523
- };
524
- rows.forEach((row, index) => {
525
- if (flags[index] === true) {
526
- run.push(row);
527
- return;
528
- }
529
- closeRun();
530
- regrouped.push(row);
531
- });
532
- closeRun();
533
- const rest = [];
534
- let placed = false;
535
- for (const child of table.children) {
536
- if (!(child.type === "element" && (child.tag === "table:table-row" || ROW_WRAPPER_TAGS.has(child.tag)))) {
537
- rest.push(child);
538
- continue;
539
- }
540
- if (!placed) {
541
- rest.push(...regrouped);
542
- placed = true;
543
- }
544
- }
545
- if (!placed) rest.push(...regrouped);
546
- table.children = rest;
547
- }
548
- headerColumns() {
549
- return tableColumnEntries(this.live()).map((entry) => entry.insideHeader);
550
- }
551
- setHeaderColumns(flags) {
552
- const table = this.live();
553
- const columns = tableColumnElements(table);
554
- const regrouped = [];
555
- let run = [];
556
- const closeRun = () => {
557
- if (run.length > 0) {
558
- regrouped.push(el("table:table-header-columns", {}, run));
559
- run = [];
560
- }
561
- };
562
- columns.forEach((column, index) => {
563
- if (flags[index] === true) {
564
- run.push(column);
565
- return;
566
- }
567
- closeRun();
568
- regrouped.push(column);
569
- });
570
- closeRun();
571
- const rest = [];
572
- let placed = false;
573
- for (const child of table.children) {
574
- if (!(child.type === "element" && (child.tag === "table:table-column" || COLUMN_WRAPPER_TAGS.has(child.tag)))) {
575
- rest.push(child);
576
- continue;
577
- }
578
- if (!placed) {
579
- rest.push(...regrouped);
580
- placed = true;
581
- }
582
- }
583
- if (!placed) rest.push(...regrouped);
584
- table.children = rest;
585
- }
586
- gridRows() {
587
- return this.grid().rows;
588
- }
589
- gridColumnCount() {
590
- return this.grid().columnCount;
591
- }
592
- grid() {
593
- return resolveOdtGrid(this.live(), this.pkg);
594
- }
595
- cell(rowIndex, columnIndex) {
596
- const row = this.rows()[rowIndex];
597
- if (row === void 0) throw new Error(`row ${rowIndex} does not exist in this table`);
598
- const cell = row.cells()[columnIndex];
599
- if (cell === void 0) throw new Error(`column ${columnIndex} does not exist in row ${rowIndex}`);
600
- return cell;
601
- }
602
- appendRow(columnCount) {
603
- const node = this.live();
604
- const row = buildRow(this.pkg, columnCount);
605
- node.children.push(row);
606
- return new OdtTableRow(row, this.pkg, node);
607
- }
608
- appendEmptyRow() {
609
- const node = this.live();
610
- const row = el("table:table-row");
611
- node.children.push(row);
612
- return new OdtTableRow(row, this.pkg, node);
613
- }
614
- mergeCells(startRow, startColumn, rowSpan, colSpan) {
615
- if (!Number.isInteger(rowSpan) || rowSpan < 1 || !Number.isInteger(colSpan) || colSpan < 1) throw new Error(`mergeCells: rowSpan and colSpan must be positive integers, got rowSpan=${rowSpan}, colSpan=${colSpan}`);
616
- const rows = tableRowElements(this.live());
617
- const anchorRow = rows[startRow];
618
- if (anchorRow === void 0) throw new Error(`mergeCells: row ${startRow} does not exist in this table`);
619
- if (startRow + rowSpan > rows.length) throw new Error(`mergeCells: rowSpan ${rowSpan} starting at row ${startRow} exceeds this table's own ${rows.length} rows`);
620
- const target = {
621
- row: startRow,
622
- column: startColumn,
623
- rowSpan,
624
- columnSpan: colSpan
625
- };
626
- const plan = planMerge(this.live(), this.pkg, target, [anchorRow, ...rows.slice(startRow + 1, startRow + rowSpan)]);
627
- if (plan.refusal !== void 0) throw new Error(`mergeCells: row ${plan.refusal.rowIndex}: ${plan.refusal.reason}`);
628
- return applyMerge(plan, target, this.pkg);
629
- }
630
- remove() {
631
- removeChild(this.container, this.live());
632
- this.removed = true;
633
- }
634
- };
635
- function buildTable(pkg, init) {
636
- const defaultWidth = DEFAULT_TABLE_WIDTH_PT / init.columns;
637
- const columns = [];
638
- for (let i = 0; i < init.columns; i++) {
639
- const widthPt = init.columnWidthsPt?.[i] ?? defaultWidth;
640
- columns.push(el("table:table-column", { "table:style-name": internTableColumnWidth(pkg, widthPt) }));
641
- }
642
- const rows = [];
643
- for (let r = 0; r < init.rows; r++) rows.push(buildRow(pkg, init.columns));
644
- return el("table:table", {}, [...columns, ...rows]);
645
- }
646
- //#endregion
647
- export { OdtCoveredTableCell, OdtTable, OdtTableCell, OdtTableRow, buildCellStyle, buildTable, readCellDecoration };
1
+ import { a as TABLE_ROW_STYLE_PREFIX, c as readCellDecoration, d as tableRowEntries, i as OdtTableRow, l as retagAsCovered, n as OdtTable, o as buildCellStyle, r as OdtTableCell, s as buildTable, t as OdtCoveredTableCell, u as tableColumnElements } from "../../table-B5gSMY7w.js";
2
+ export { OdtCoveredTableCell, OdtTable, OdtTableCell, OdtTableRow, TABLE_ROW_STYLE_PREFIX, buildCellStyle, buildTable, readCellDecoration, retagAsCovered, tableColumnElements, tableRowEntries };
@@ -1,5 +1,6 @@
1
1
  import { r as HsqldbTable } from "./script-pkZ2Kor4.cjs";
2
2
  import { h as SqlSelectStatement } from "./parser-BTA1wXPd.cjs";
3
+ import { n as OuterScope } from "./evaluate-columns-CyqKHkIW.cjs";
3
4
  import { ContentCellValue } from "document-schema.js";
4
5
  //#region src/odb/sql/evaluate.d.ts
5
6
  interface SqlResultSet {
@@ -7,9 +8,10 @@ interface SqlResultSet {
7
8
  readonly rows: readonly (readonly ContentCellValue[])[];
8
9
  }
9
10
  declare function evaluateSelect(statement: SqlSelectStatement, tables: readonly HsqldbTable[]): SqlResultSet;
11
+ declare function evaluateSelectInScope(statement: SqlSelectStatement, tables: readonly HsqldbTable[], outer: OuterScope | undefined): SqlResultSet;
10
12
  declare function assertNeverOperator(value: never): never;
11
13
  declare function assertNeverLiteralKind(value: never): never;
12
14
  declare function assertNeverPredicateKind(value: never): never;
13
15
  declare function assertNeverValueKind(value: never): never;
14
16
  //#endregion
15
- export { assertNeverValueKind as a, assertNeverPredicateKind as i, assertNeverLiteralKind as n, evaluateSelect as o, assertNeverOperator as r, SqlResultSet as t };
17
+ export { assertNeverValueKind as a, assertNeverPredicateKind as i, assertNeverLiteralKind as n, evaluateSelect as o, assertNeverOperator as r, evaluateSelectInScope as s, SqlResultSet as t };