documents.js 1.60.3 → 1.62.0

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 (216) hide show
  1. package/README.md +84 -44
  2. package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
  3. package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
  4. package/dist/convert/capability.cjs +1 -0
  5. package/dist/convert/capability.d.cts +1 -1
  6. package/dist/convert/capability.d.ts +1 -1
  7. package/dist/convert/capability.js +1 -0
  8. package/dist/convert/convert.cjs +29 -27
  9. package/dist/convert/convert.d.cts +9 -3
  10. package/dist/convert/convert.d.ts +9 -3
  11. package/dist/convert/convert.js +29 -27
  12. package/dist/edit/docx/content.cjs +75 -13
  13. package/dist/edit/docx/content.d.cts +8 -2
  14. package/dist/edit/docx/content.d.ts +8 -2
  15. package/dist/edit/docx/content.js +75 -13
  16. package/dist/edit/docx/paragraph.cjs +14 -0
  17. package/dist/edit/docx/paragraph.d.cts +5 -0
  18. package/dist/edit/docx/paragraph.d.ts +5 -0
  19. package/dist/edit/docx/paragraph.js +14 -0
  20. package/dist/edit/docx/run.cjs +1 -1
  21. package/dist/edit/docx/run.js +1 -1
  22. package/dist/edit/docx/table.cjs +41 -0
  23. package/dist/edit/docx/table.d.cts +7 -1
  24. package/dist/edit/docx/table.d.ts +7 -1
  25. package/dist/edit/docx/table.js +42 -1
  26. package/dist/edit/geometry.cjs +38 -0
  27. package/dist/edit/geometry.d.cts +7 -0
  28. package/dist/edit/geometry.d.ts +7 -0
  29. package/dist/edit/geometry.js +36 -0
  30. package/dist/edit/odg/content.cjs +15 -12
  31. package/dist/edit/odg/content.js +15 -12
  32. package/dist/edit/odg/editor.d.cts +1 -1
  33. package/dist/edit/odg/editor.d.ts +1 -1
  34. package/dist/edit/odg/page.d.cts +3 -3
  35. package/dist/edit/odg/page.d.ts +3 -3
  36. package/dist/edit/odg/vector.cjs +22 -13
  37. package/dist/edit/odg/vector.d.cts +1 -1
  38. package/dist/edit/odg/vector.d.ts +1 -1
  39. package/dist/edit/odg/vector.js +23 -14
  40. package/dist/edit/odp/content.cjs +15 -0
  41. package/dist/edit/odp/content.js +16 -1
  42. package/dist/edit/odp/editor.d.cts +1 -1
  43. package/dist/edit/odp/editor.d.ts +1 -1
  44. package/dist/edit/odp/image.d.cts +1 -1
  45. package/dist/edit/odp/image.d.ts +1 -1
  46. package/dist/edit/odp/shape.cjs +11 -30
  47. package/dist/edit/odp/shape.d.cts +2 -2
  48. package/dist/edit/odp/shape.d.ts +2 -2
  49. package/dist/edit/odp/shape.js +13 -33
  50. package/dist/edit/odp/slide.cjs +11 -0
  51. package/dist/edit/odp/slide.d.cts +14 -4
  52. package/dist/edit/odp/slide.d.ts +14 -4
  53. package/dist/edit/odp/slide.js +12 -1
  54. package/dist/edit/odt/content.cjs +56 -16
  55. package/dist/edit/odt/content.d.cts +4 -2
  56. package/dist/edit/odt/content.d.ts +4 -2
  57. package/dist/edit/odt/content.js +56 -17
  58. package/dist/edit/odt/editor.d.cts +1 -1
  59. package/dist/edit/odt/editor.d.ts +1 -1
  60. package/dist/edit/odt/table.cjs +36 -0
  61. package/dist/edit/odt/table.d.cts +1 -36
  62. package/dist/edit/odt/table.d.ts +1 -36
  63. package/dist/edit/odt/table.js +37 -1
  64. package/dist/edit/pptx/content.cjs +71 -3
  65. package/dist/edit/pptx/content.js +71 -3
  66. package/dist/edit/pptx/editor.d.cts +1 -1
  67. package/dist/edit/pptx/editor.d.ts +1 -1
  68. package/dist/edit/pptx/image.d.cts +1 -1
  69. package/dist/edit/pptx/image.d.ts +1 -1
  70. package/dist/edit/pptx/shape.cjs +23 -1
  71. package/dist/edit/pptx/shape.d.cts +2 -2
  72. package/dist/edit/pptx/shape.d.ts +2 -2
  73. package/dist/edit/pptx/shape.js +23 -3
  74. package/dist/edit/pptx/slide.cjs +10 -1
  75. package/dist/edit/pptx/slide.d.cts +11 -4
  76. package/dist/edit/pptx/slide.d.ts +11 -4
  77. package/dist/edit/pptx/slide.js +10 -1
  78. package/dist/edit/pptx/table.cjs +136 -0
  79. package/dist/edit/pptx/table.d.cts +2 -0
  80. package/dist/edit/pptx/table.d.ts +2 -0
  81. package/dist/edit/pptx/table.js +131 -0
  82. package/dist/firebird/backup.d.cts +1 -1
  83. package/dist/firebird/backup.d.ts +1 -1
  84. package/dist/firebird/blr-types.cjs +2 -2
  85. package/dist/firebird/blr-types.d.cts +1 -1
  86. package/dist/firebird/blr-types.d.ts +1 -1
  87. package/dist/firebird/blr-types.js +2 -2
  88. package/dist/firebird/data.cjs +68 -14
  89. package/dist/firebird/data.d.cts +1 -1
  90. package/dist/firebird/data.d.ts +1 -1
  91. package/dist/firebird/data.js +68 -14
  92. package/dist/firebird/schema.cjs +13 -1
  93. package/dist/firebird/schema.d.cts +1 -1
  94. package/dist/firebird/schema.d.ts +1 -1
  95. package/dist/firebird/schema.js +13 -1
  96. package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
  97. package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
  98. package/dist/hsqldb/binary-script.cjs +154 -0
  99. package/dist/hsqldb/binary-script.d.cts +15 -0
  100. package/dist/hsqldb/binary-script.d.ts +15 -0
  101. package/dist/hsqldb/binary-script.js +151 -0
  102. package/dist/hsqldb/cache.cjs +18 -11
  103. package/dist/hsqldb/cache.d.cts +9 -4
  104. package/dist/hsqldb/cache.d.ts +9 -4
  105. package/dist/hsqldb/cache.js +18 -11
  106. package/dist/hsqldb/rowformat.cjs +60 -16
  107. package/dist/hsqldb/rowformat.d.cts +2 -21
  108. package/dist/hsqldb/rowformat.d.ts +2 -21
  109. package/dist/hsqldb/rowformat.js +60 -17
  110. package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
  111. package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
  112. package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
  113. package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
  114. package/dist/index.cjs +54 -3
  115. package/dist/index.d.cts +28 -20
  116. package/dist/index.d.ts +27 -19
  117. package/dist/index.js +13 -4
  118. package/dist/layout/cell-typing.cjs +209 -0
  119. package/dist/layout/cell-typing.d.cts +22 -0
  120. package/dist/layout/cell-typing.d.ts +22 -0
  121. package/dist/layout/cell-typing.js +208 -0
  122. package/dist/layout/drawing.cjs +193 -17
  123. package/dist/layout/drawing.js +193 -17
  124. package/dist/layout/engine.cjs +46 -29
  125. package/dist/layout/engine.d.cts +0 -2
  126. package/dist/layout/engine.d.ts +0 -2
  127. package/dist/layout/engine.js +47 -30
  128. package/dist/layout/lattice.cjs +139 -0
  129. package/dist/layout/lattice.d.cts +20 -0
  130. package/dist/layout/lattice.d.ts +20 -0
  131. package/dist/layout/lattice.js +135 -0
  132. package/dist/layout/reconstruct.cjs +176 -113
  133. package/dist/layout/reconstruct.d.cts +2 -0
  134. package/dist/layout/reconstruct.d.ts +2 -0
  135. package/dist/layout/reconstruct.js +173 -110
  136. package/dist/layout/shared.cjs +52 -0
  137. package/dist/layout/shared.d.cts +4 -2
  138. package/dist/layout/shared.d.ts +4 -2
  139. package/dist/layout/shared.js +51 -1
  140. package/dist/layout/sheets.cjs +45 -11
  141. package/dist/layout/sheets.js +46 -12
  142. package/dist/layout/slides.cjs +7 -7
  143. package/dist/layout/slides.d.cts +0 -3
  144. package/dist/layout/slides.d.ts +0 -3
  145. package/dist/layout/slides.js +7 -7
  146. package/dist/markdown/write.cjs +19 -6
  147. package/dist/markdown/write.js +19 -6
  148. package/dist/mathml/layout.cjs +43 -9
  149. package/dist/mathml/layout.d.cts +1 -1
  150. package/dist/mathml/layout.d.ts +1 -1
  151. package/dist/mathml/layout.js +43 -9
  152. package/dist/mathml/variant.cjs +48 -5
  153. package/dist/mathml/variant.js +48 -5
  154. package/dist/model/embedded-drawing.cjs +32 -0
  155. package/dist/model/embedded-drawing.d.cts +8 -0
  156. package/dist/model/embedded-drawing.d.ts +8 -0
  157. package/dist/model/embedded-drawing.js +30 -0
  158. package/dist/model/formula.cjs +31 -0
  159. package/dist/model/formula.d.cts +6 -6
  160. package/dist/model/formula.d.ts +6 -6
  161. package/dist/model/formula.js +27 -0
  162. package/dist/model/geometry.d.cts +1 -1
  163. package/dist/model/geometry.d.ts +1 -1
  164. package/dist/model/paint-order.cjs +15 -0
  165. package/dist/model/paint-order.d.cts +14 -0
  166. package/dist/model/paint-order.d.ts +14 -0
  167. package/dist/model/paint-order.js +14 -0
  168. package/dist/odb/components.cjs +12 -0
  169. package/dist/odb/components.d.cts +6 -0
  170. package/dist/odb/components.d.ts +6 -0
  171. package/dist/odb/components.js +10 -0
  172. package/dist/odb/read.cjs +11 -7
  173. package/dist/odb/read.d.cts +3 -2
  174. package/dist/odb/read.d.ts +3 -2
  175. package/dist/odb/read.js +11 -7
  176. package/dist/odf/formula/detect.cjs +86 -18
  177. package/dist/odf/formula/detect.d.cts +10 -6
  178. package/dist/odf/formula/detect.d.ts +10 -6
  179. package/dist/odf/formula/detect.js +86 -19
  180. package/dist/odf/formula/read.cjs +4 -16
  181. package/dist/odf/formula/read.d.cts +4 -8
  182. package/dist/odf/formula/read.d.ts +4 -8
  183. package/dist/odf/formula/read.js +5 -17
  184. package/dist/odf/odp/read.cjs +9 -19
  185. package/dist/odf/odp/read.d.cts +2 -7
  186. package/dist/odf/odp/read.d.ts +2 -7
  187. package/dist/odf/odp/read.js +10 -20
  188. package/dist/odf/odt/read.cjs +63 -23
  189. package/dist/odf/odt/read.d.cts +2 -7
  190. package/dist/odf/odt/read.d.ts +2 -7
  191. package/dist/odf/odt/read.js +64 -24
  192. package/dist/omml/write.cjs +258 -0
  193. package/dist/omml/write.d.cts +2 -0
  194. package/dist/omml/write.d.ts +2 -0
  195. package/dist/omml/write.js +256 -0
  196. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  197. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  198. package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
  199. package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
  200. package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
  201. package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
  202. package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
  203. package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
  204. package/dist/table-C3CPZ--2.d.cts +35 -0
  205. package/dist/table-DjYcNOFm.d.cts +44 -0
  206. package/dist/table-DqfqMkVq.d.ts +44 -0
  207. package/dist/table-DvS_7UQS.d.ts +35 -0
  208. package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
  209. package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
  210. package/dist/write-DuyfnbL_.d.cts +16 -0
  211. package/dist/write-Zqwx6pka.d.ts +16 -0
  212. package/package.json +4 -4
  213. package/dist/odf/formula/placeholder.cjs +0 -36
  214. package/dist/odf/formula/placeholder.d.cts +0 -14
  215. package/dist/odf/formula/placeholder.d.ts +0 -14
  216. package/dist/odf/formula/placeholder.js +0 -36
@@ -1,6 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_geometry = require("../model/geometry.cjs");
3
+ const require_model_embedded_drawing = require("../model/embedded-drawing.cjs");
3
4
  const require_ports_abort = require("../ports/abort.cjs");
5
+ const require_layout_cell_typing = require("./cell-typing.cjs");
6
+ const require_layout_lattice = require("./lattice.cjs");
4
7
  let document_schema_js = require("document-schema.js");
5
8
  let pdf_codec = require("pdf-codec");
6
9
  //#region src/layout/reconstruct.ts
@@ -135,7 +138,9 @@ function buildSection(pages, images) {
135
138
  };
136
139
  }
137
140
  function reconstructPageBlocks(page, images) {
138
- const textItems = page.items.filter((i) => i.kind === "text");
141
+ const recoveredTable = recoverTable(page);
142
+ const consumedText = recoveredTable?.consumedText;
143
+ const textItems = page.items.filter((i) => i.kind === "text" && consumedText?.has(i) !== true);
139
144
  const imageItems = page.items.filter((i) => i.kind === "image");
140
145
  const paragraphs = clusterIntoParagraphs(clusterIntoLines(textItems));
141
146
  const positioned = [];
@@ -156,6 +161,15 @@ function reconstructPageBlocks(page, images) {
156
161
  }
157
162
  });
158
163
  }
164
+ if (recoveredTable !== void 0) positioned.push({
165
+ yPt: recoveredTable.topYPt,
166
+ block: recoveredTable.table
167
+ });
168
+ const recoveredVectors = recoverPageVectors(page, recoveredTable?.latticeItems ?? NO_ITEMS);
169
+ if (recoveredVectors !== void 0) positioned.push({
170
+ yPt: recoveredVectors.topYPt,
171
+ block: recoveredVectors.block
172
+ });
159
173
  positioned.sort((a, b) => b.yPt - a.yPt);
160
174
  return positioned.map((p) => p.block);
161
175
  }
@@ -213,7 +227,9 @@ function reconstructPresentation(doc, options) {
213
227
  };
214
228
  }
215
229
  function reconstructSlide(page, images) {
216
- const textItems = page.items.filter((i) => i.kind === "text");
230
+ const recoveredTable = recoverTable(page);
231
+ const consumedText = recoveredTable?.consumedText;
232
+ const textItems = page.items.filter((i) => i.kind === "text" && consumedText?.has(i) !== true);
217
233
  const imageItems = page.items.filter((i) => i.kind === "image");
218
234
  const textShapes = clusterIntoBlocks(clusterIntoLines(textItems)).map((block) => blockToShape(block, page.heightPt));
219
235
  const imageShapes = [];
@@ -221,15 +237,38 @@ function reconstructSlide(page, images) {
221
237
  const shape = imageToShape(img, page.heightPt, images);
222
238
  if (shape !== void 0) imageShapes.push(shape);
223
239
  }
240
+ const recoveredVectors = recoverPageVectors(page, recoveredTable?.latticeItems ?? NO_ITEMS);
241
+ const vectorShapes = recoveredVectors === void 0 ? [] : [wrapBlockInShape(recoveredVectors.block, {
242
+ xPt: 0,
243
+ yPt: 0,
244
+ widthPt: page.widthPt,
245
+ heightPt: page.heightPt
246
+ })];
247
+ const tableShapes = recoveredTable === void 0 ? [] : [wrapBlockInShape(recoveredTable.table, recoveredTable.frame)];
224
248
  return {
225
249
  size: {
226
250
  widthPt: page.widthPt,
227
251
  heightPt: page.heightPt
228
252
  },
229
- shapes: [...imageShapes, ...textShapes],
253
+ shapes: [
254
+ ...vectorShapes,
255
+ ...imageShapes,
256
+ ...tableShapes,
257
+ ...textShapes
258
+ ],
230
259
  notes: page.notes ?? ""
231
260
  };
232
261
  }
262
+ function wrapBlockInShape(block, frame) {
263
+ return {
264
+ frame,
265
+ insetLeftPt: 0,
266
+ insetTopPt: 0,
267
+ insetRightPt: 0,
268
+ insetBottomPt: 0,
269
+ blocks: [block]
270
+ };
271
+ }
233
272
  function splitLineByLargeGaps(line) {
234
273
  const segments = [];
235
274
  let current = [];
@@ -353,14 +392,27 @@ function reconstructDrawing(doc, options) {
353
392
  function reconstructDrawPage(page, images) {
354
393
  const vectors = [];
355
394
  const shapes = [];
356
- for (const item of page.items) if (item.kind === "rect") vectors.push(layoutRectToVector(item, page.heightPt));
357
- else if (item.kind === "ellipse") vectors.push(layoutEllipseToVector(item, page.heightPt));
358
- else if (item.kind === "line") vectors.push(layoutLineToVector(item, page.heightPt));
359
- else if (item.kind === "path") vectors.push(layoutPathToVector(item, page.heightPt));
360
- else if (item.kind === "text") shapes.push(layoutTextToShape(item, page.heightPt));
361
- else if (item.kind === "image") {
362
- const shape = imageToShape(item, page.heightPt, images);
363
- if (shape !== void 0) shapes.push(shape);
395
+ let paintOrder = 0;
396
+ for (const item of page.items) {
397
+ const vector = layoutItemToVector(item, page.heightPt);
398
+ if (vector !== void 0) {
399
+ vectors.push({
400
+ ...vector,
401
+ paintOrder: paintOrder++
402
+ });
403
+ continue;
404
+ }
405
+ if (item.kind === "text") shapes.push({
406
+ ...layoutTextToShape(item, page.heightPt),
407
+ paintOrder: paintOrder++
408
+ });
409
+ else if (item.kind === "image") {
410
+ const shape = imageToShape(item, page.heightPt, images);
411
+ if (shape !== void 0) shapes.push({
412
+ ...shape,
413
+ paintOrder: paintOrder++
414
+ });
415
+ }
364
416
  }
365
417
  return {
366
418
  size: {
@@ -371,6 +423,12 @@ function reconstructDrawPage(page, images) {
371
423
  vectors
372
424
  };
373
425
  }
426
+ function layoutItemToVector(item, pageHeightPt) {
427
+ if (item.kind === "rect") return layoutRectToVector(item, pageHeightPt);
428
+ if (item.kind === "ellipse") return layoutEllipseToVector(item, pageHeightPt);
429
+ if (item.kind === "line") return layoutLineToVector(item, pageHeightPt);
430
+ if (item.kind === "path") return layoutPathToVector(item, pageHeightPt);
431
+ }
374
432
  function layoutRectToVector(item, pageHeightPt) {
375
433
  return {
376
434
  kind: "rect",
@@ -533,99 +591,82 @@ function layoutTextToShape(item, pageHeightPt) {
533
591
  }]
534
592
  };
535
593
  }
536
- function extractLineCandidates(items) {
537
- const segments = [];
538
- for (const item of items) {
539
- if (item.kind === "line") {
540
- segments.push({
541
- x1Pt: item.x1Pt,
542
- y1Pt: item.y1Pt,
543
- x2Pt: item.x2Pt,
544
- y2Pt: item.y2Pt
545
- });
546
- continue;
547
- }
548
- if (item.kind === "path" && item.stroke !== void 0 && item.subpaths.length === 1) {
549
- const subpath = item.subpaths[0];
550
- if (subpath.segments.length === 1 && subpath.segments[0].kind === "line") {
551
- const segment = subpath.segments[0];
552
- segments.push({
553
- x1Pt: subpath.startXPt,
554
- y1Pt: subpath.startYPt,
555
- x2Pt: segment.xPt,
556
- y2Pt: segment.yPt
557
- });
558
- }
559
- }
560
- }
561
- return segments;
594
+ function vectorTopYDownPt(vector) {
595
+ return vector.kind === "line" ? Math.min(vector.from.yPt, vector.to.yPt) : vector.frame.yPt;
562
596
  }
563
- const AXIS_ALIGNMENT_TOLERANCE_PT = .5;
564
- const MIN_GRIDLINE_LENGTH_PT = 4;
565
- function classifyAxisLine(seg) {
566
- const dx = Math.abs(seg.x2Pt - seg.x1Pt);
567
- const dy = Math.abs(seg.y2Pt - seg.y1Pt);
568
- if (dy <= AXIS_ALIGNMENT_TOLERANCE_PT && dx >= MIN_GRIDLINE_LENGTH_PT) return {
569
- axis: "horizontal",
570
- position: (seg.y1Pt + seg.y2Pt) / 2,
571
- spanPt: dx
572
- };
573
- if (dx <= AXIS_ALIGNMENT_TOLERANCE_PT && dy >= MIN_GRIDLINE_LENGTH_PT) return {
574
- axis: "vertical",
575
- position: (seg.x1Pt + seg.x2Pt) / 2,
576
- spanPt: dy
577
- };
578
- }
579
- const POSITION_DEDUPE_TOLERANCE_PT = .5;
580
- function dedupeAxisLines(lines, descending) {
581
- const sorted = [...lines].sort((a, b) => descending ? b.position - a.position : a.position - b.position);
582
- const result = [];
583
- for (const candidate of sorted) {
584
- const last = result[result.length - 1];
585
- if (last !== void 0 && Math.abs(candidate.position - last.position) <= POSITION_DEDUPE_TOLERANCE_PT) last.spanPt = Math.max(last.spanPt, candidate.spanPt);
586
- else result.push({
587
- position: candidate.position,
588
- spanPt: candidate.spanPt
597
+ function recoverPageVectors(page, excluded) {
598
+ const vectors = [];
599
+ for (const item of page.items) {
600
+ if (excluded.has(item)) continue;
601
+ const vector = layoutItemToVector(item, page.heightPt);
602
+ if (vector !== void 0) vectors.push({
603
+ ...vector,
604
+ paintOrder: vectors.length
589
605
  });
590
606
  }
591
- return result;
592
- }
593
- const MIN_GRIDLINE_COUNT_PER_AXIS = 3;
594
- const GRID_SPAN_CONSISTENCY_RATIO = .9;
595
- function isRegularLattice(lines) {
596
- if (lines.length < MIN_GRIDLINE_COUNT_PER_AXIS) return false;
597
- const maxSpanPt = Math.max(...lines.map((l) => l.spanPt));
598
- return lines.filter((l) => l.spanPt >= maxSpanPt * GRID_SPAN_CONSISTENCY_RATIO).length >= MIN_GRIDLINE_COUNT_PER_AXIS;
599
- }
600
- function detectGridLattice(items) {
601
- const horizontal = [];
602
- const vertical = [];
603
- for (const seg of extractLineCandidates(items)) {
604
- const classified = classifyAxisLine(seg);
605
- if (classified === void 0) continue;
606
- (classified.axis === "horizontal" ? horizontal : vertical).push(classified);
607
- }
608
- const rowBoundaries = dedupeAxisLines(horizontal, true);
609
- const columnBoundaries = dedupeAxisLines(vertical, false);
610
- if (!isRegularLattice(rowBoundaries) || !isRegularLattice(columnBoundaries)) return;
607
+ if (vectors.length === 0) return;
608
+ const topYDownPt = Math.min(...vectors.map(vectorTopYDownPt));
611
609
  return {
612
- rowBoundariesDescPt: rowBoundaries.map((l) => l.position),
613
- columnBoundariesAscPt: columnBoundaries.map((l) => l.position)
610
+ block: require_model_embedded_drawing.buildDrawingBlock({
611
+ widthPt: page.widthPt,
612
+ heightPt: page.heightPt
613
+ }, vectors),
614
+ topYPt: page.heightPt - topYDownPt
614
615
  };
615
616
  }
616
- const OUTER_EDGE_TOLERANCE_PT = 3;
617
- function findRowIndex(rowBoundariesDescPt, yPt) {
618
- const lastIndex = rowBoundariesDescPt.length - 1;
619
- if (yPt > rowBoundariesDescPt[0] + OUTER_EDGE_TOLERANCE_PT || yPt < rowBoundariesDescPt[lastIndex] - OUTER_EDGE_TOLERANCE_PT) return;
620
- for (let i = 0; i < lastIndex; i++) if (yPt > rowBoundariesDescPt[i + 1]) return i;
621
- return lastIndex - 1;
617
+ function cellBlocksFromItems(items) {
618
+ return clusterIntoLines(items).map(lineToParagraph);
622
619
  }
623
- function findColumnIndex(columnBoundariesAscPt, xPt) {
624
- const lastIndex = columnBoundariesAscPt.length - 1;
625
- if (xPt < columnBoundariesAscPt[0] - OUTER_EDGE_TOLERANCE_PT || xPt > columnBoundariesAscPt[lastIndex] + OUTER_EDGE_TOLERANCE_PT) return;
626
- for (let j = 0; j < lastIndex; j++) if (xPt < columnBoundariesAscPt[j + 1]) return j;
627
- return lastIndex - 1;
620
+ function recoverTable(page) {
621
+ const lattice = require_layout_lattice.detectGridLattice(page.items);
622
+ if (lattice === void 0) return;
623
+ const rowCount = lattice.rowBoundariesDescPt.length - 1;
624
+ const columnCount = lattice.columnBoundariesAscPt.length - 1;
625
+ const groups = /* @__PURE__ */ new Map();
626
+ const consumedText = /* @__PURE__ */ new Set();
627
+ for (const item of page.items) {
628
+ if (item.kind !== "text") continue;
629
+ const row = require_layout_lattice.findRowIndex(lattice.rowBoundariesDescPt, item.yPt);
630
+ const column = require_layout_lattice.findColumnIndex(lattice.columnBoundariesAscPt, item.xPt);
631
+ if (row === void 0 || column === void 0) continue;
632
+ addToGroup(groups, row, column, item);
633
+ consumedText.add(item);
634
+ }
635
+ if (consumedText.size === 0) return;
636
+ const columnWidthsPt = [];
637
+ for (let j = 0; j < columnCount; j++) columnWidthsPt.push(lattice.columnBoundariesAscPt[j + 1] - lattice.columnBoundariesAscPt[j]);
638
+ const rows = [];
639
+ for (let i = 0; i < rowCount; i++) {
640
+ const cells = [];
641
+ for (let j = 0; j < columnCount; j++) cells.push({ blocks: cellBlocksFromItems(groups.get(groupKey(i, j)) ?? []) });
642
+ rows.push({
643
+ cells,
644
+ heightPt: lattice.rowBoundariesDescPt[i] - lattice.rowBoundariesDescPt[i + 1]
645
+ });
646
+ }
647
+ const leftXPt = lattice.columnBoundariesAscPt[0];
648
+ const rightXPt = lattice.columnBoundariesAscPt[columnCount];
649
+ const topYPt = lattice.rowBoundariesDescPt[0];
650
+ const bottomYPt = lattice.rowBoundariesDescPt[rowCount];
651
+ const frame = require_model_geometry.flipY({
652
+ xPt: leftXPt,
653
+ yPt: bottomYPt,
654
+ widthPt: rightXPt - leftXPt,
655
+ heightPt: topYPt - bottomYPt
656
+ }, page.heightPt);
657
+ return {
658
+ table: {
659
+ kind: "table",
660
+ rows,
661
+ columnWidthsPt
662
+ },
663
+ frame,
664
+ topYPt,
665
+ consumedText,
666
+ latticeItems: lattice.sourceItems
667
+ };
628
668
  }
669
+ const NO_ITEMS = /* @__PURE__ */ new Set();
629
670
  function joinCellText(items) {
630
671
  const sorted = [...items].sort((a, b) => a.xPt - b.xPt);
631
672
  let text = "";
@@ -647,30 +688,48 @@ function addToGroup(groups, row, column, item) {
647
688
  if (existing === void 0) groups.set(key, [item]);
648
689
  else existing.push(item);
649
690
  }
650
- function buildCellsFromGroups(groups) {
691
+ function buildCellsFromGroups(groups, context) {
651
692
  const cells = [];
652
693
  for (const [key, items] of groups) {
653
694
  const displayText = joinCellText(items);
654
695
  if (displayText.length === 0) continue;
655
696
  const [rowPart, columnPart] = key.split(",");
697
+ const row = Number(rowPart);
698
+ const column = Number(columnPart);
656
699
  cells.push({
657
- row: Number(rowPart),
658
- column: Number(columnPart),
659
- value: {
660
- kind: "string",
661
- value: displayText
662
- },
700
+ row,
701
+ column,
702
+ value: inferredCellValue(displayText, row, column, context),
663
703
  displayText
664
704
  });
665
705
  }
666
706
  cells.sort((a, b) => a.row - b.row || a.column - b.column);
667
707
  return cells;
668
708
  }
669
- function buildGridFromLattice(textItems, lattice) {
709
+ function inferredCellValue(displayText, row, column, context) {
710
+ const inference = require_layout_cell_typing.inferCellValue(displayText);
711
+ if (inference === void 0) return {
712
+ kind: "string",
713
+ value: displayText
714
+ };
715
+ const reported = {
716
+ sheetIndex: context.sheetIndex,
717
+ row,
718
+ column,
719
+ displayText,
720
+ ...inference
721
+ };
722
+ context.sink?.(reported);
723
+ return inference.outcome === "retyped" ? inference.value : {
724
+ kind: "string",
725
+ value: displayText
726
+ };
727
+ }
728
+ function buildGridFromLattice(textItems, lattice, context) {
670
729
  const groups = /* @__PURE__ */ new Map();
671
730
  for (const item of textItems) {
672
- const row = findRowIndex(lattice.rowBoundariesDescPt, item.yPt);
673
- const column = findColumnIndex(lattice.columnBoundariesAscPt, item.xPt);
731
+ const row = require_layout_lattice.findRowIndex(lattice.rowBoundariesDescPt, item.yPt);
732
+ const column = require_layout_lattice.findColumnIndex(lattice.columnBoundariesAscPt, item.xPt);
674
733
  if (row === void 0 || column === void 0) continue;
675
734
  addToGroup(groups, row, column, item);
676
735
  }
@@ -685,7 +744,7 @@ function buildGridFromLattice(textItems, lattice) {
685
744
  heightPt: lattice.rowBoundariesDescPt[i] - lattice.rowBoundariesDescPt[i + 1]
686
745
  });
687
746
  return {
688
- cells: buildCellsFromGroups(groups),
747
+ cells: buildCellsFromGroups(groups, context),
689
748
  columns,
690
749
  rows,
691
750
  gridlines: true
@@ -724,7 +783,7 @@ function lastColumnWidthPt(groups, columnIndex, anchorXPt) {
724
783
  }
725
784
  return maxWidthPt > 0 ? maxWidthPt : DEFAULT_COLUMN_WIDTH_FALLBACK_PT;
726
785
  }
727
- function buildGridFromTextClustering(textItems) {
786
+ function buildGridFromTextClustering(textItems, context) {
728
787
  const lines = clusterIntoLines(textItems);
729
788
  if (lines.length === 0) return {
730
789
  cells: [],
@@ -760,16 +819,20 @@ function buildGridFromTextClustering(textItems) {
760
819
  };
761
820
  });
762
821
  return {
763
- cells: buildCellsFromGroups(groups),
822
+ cells: buildCellsFromGroups(groups, context),
764
823
  columns,
765
824
  rows,
766
825
  gridlines: false
767
826
  };
768
827
  }
769
- function reconstructSheet(page, pageIndex) {
828
+ function reconstructSheet(page, pageIndex, sink) {
770
829
  const textItems = page.items.filter((i) => i.kind === "text");
771
- const lattice = detectGridLattice(page.items);
772
- const grid = lattice !== void 0 ? buildGridFromLattice(textItems, lattice) : buildGridFromTextClustering(textItems);
830
+ const lattice = require_layout_lattice.detectGridLattice(page.items);
831
+ const context = {
832
+ sheetIndex: pageIndex,
833
+ sink
834
+ };
835
+ const grid = lattice !== void 0 ? buildGridFromLattice(textItems, lattice, context) : buildGridFromTextClustering(textItems, context);
773
836
  const printSettings = {
774
837
  pageSize: {
775
838
  widthPt: page.widthPt,
@@ -793,7 +856,7 @@ function reconstructSpreadsheet(doc, options) {
793
856
  const signal = options?.signal;
794
857
  const sheets = doc.pages.map((page, index) => {
795
858
  require_ports_abort.throwIfAborted(signal);
796
- return reconstructSheet(page, index);
859
+ return reconstructSheet(page, index, options?.onCellTypeInference);
797
860
  });
798
861
  return {
799
862
  kind: "spreadsheet",
@@ -1,7 +1,9 @@
1
+ import { CellTypeInferenceSink } from "./cell-typing.cjs";
1
2
  import { ContentDocument, LayoutDocument } from "document-schema.js";
2
3
  //#region src/layout/reconstruct.d.ts
3
4
  interface ReconstructOptions {
4
5
  readonly signal?: AbortSignal;
6
+ readonly onCellTypeInference?: CellTypeInferenceSink;
5
7
  }
6
8
  declare function reconstructWordprocessing(doc: LayoutDocument, options?: ReconstructOptions): ContentDocument;
7
9
  declare function reconstructPresentation(doc: LayoutDocument, options?: ReconstructOptions): ContentDocument;
@@ -1,7 +1,9 @@
1
+ import { CellTypeInferenceSink } from "./cell-typing.js";
1
2
  import { ContentDocument, LayoutDocument } from "document-schema.js";
2
3
  //#region src/layout/reconstruct.d.ts
3
4
  interface ReconstructOptions {
4
5
  readonly signal?: AbortSignal;
6
+ readonly onCellTypeInference?: CellTypeInferenceSink;
5
7
  }
6
8
  declare function reconstructWordprocessing(doc: LayoutDocument, options?: ReconstructOptions): ContentDocument;
7
9
  declare function reconstructPresentation(doc: LayoutDocument, options?: ReconstructOptions): ContentDocument;