js.documents 4.4.8 → 4.6.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 (62) hide show
  1. package/README.md +12 -2
  2. package/dist/convert/convert.cjs +1 -1
  3. package/dist/convert/convert.js +1 -1
  4. package/dist/convert/pdf-package-tables.cjs +15 -0
  5. package/dist/convert/pdf-package-tables.js +15 -0
  6. package/dist/edit/odg/content.cjs +1 -1
  7. package/dist/edit/odg/content.js +1 -1
  8. package/dist/edit/odg/page.d.cts +1 -1
  9. package/dist/edit/odg/page.d.ts +1 -1
  10. package/dist/edit/odp/content.cjs +1 -1
  11. package/dist/edit/odp/content.js +1 -1
  12. package/dist/edit/odp/shape.d.cts +1 -1
  13. package/dist/edit/odp/shape.d.ts +1 -1
  14. package/dist/edit/odp/slide.d.cts +2 -2
  15. package/dist/edit/odp/slide.d.ts +2 -2
  16. package/dist/edit/ods/cell.cjs +1 -1
  17. package/dist/edit/ods/cell.js +1 -1
  18. package/dist/edit/odt/content.cjs +10 -8
  19. package/dist/edit/odt/content.d.cts +7 -4
  20. package/dist/edit/odt/content.d.ts +7 -4
  21. package/dist/edit/odt/content.js +10 -8
  22. package/dist/edit/odt/editor.cjs +1 -1
  23. package/dist/edit/odt/editor.d.cts +3 -3
  24. package/dist/edit/odt/editor.d.ts +3 -3
  25. package/dist/edit/odt/editor.js +1 -1
  26. package/dist/edit/odt/list.cjs +1 -1
  27. package/dist/edit/odt/list.d.cts +1 -1
  28. package/dist/edit/odt/list.d.ts +1 -1
  29. package/dist/edit/odt/list.js +1 -1
  30. package/dist/edit/odt/paragraph.cjs +22 -1
  31. package/dist/edit/odt/paragraph.d.cts +1 -1
  32. package/dist/edit/odt/paragraph.d.ts +1 -1
  33. package/dist/edit/odt/paragraph.js +22 -1
  34. package/dist/edit/odt/scaffold.cjs +12 -1
  35. package/dist/edit/odt/scaffold.js +12 -1
  36. package/dist/edit/odt/table.d.cts +1 -1
  37. package/dist/edit/odt/table.d.ts +1 -1
  38. package/dist/edit/pptx/content.cjs +2 -0
  39. package/dist/edit/pptx/content.d.cts +3 -2
  40. package/dist/edit/pptx/content.d.ts +3 -2
  41. package/dist/edit/pptx/content.js +3 -2
  42. package/dist/index.cjs +2 -1
  43. package/dist/index.d.cts +6 -6
  44. package/dist/index.d.ts +6 -6
  45. package/dist/index.js +3 -3
  46. package/dist/layout/drawing.cjs +1 -1
  47. package/dist/layout/drawing.js +1 -1
  48. package/dist/layout/reconstruct.cjs +263 -47
  49. package/dist/layout/reconstruct.js +263 -47
  50. package/dist/layout/shared.cjs +1 -0
  51. package/dist/layout/shared.d.cts +5 -1
  52. package/dist/layout/shared.d.ts +5 -1
  53. package/dist/layout/shared.js +1 -1
  54. package/dist/{list-D9MtQtjK.d.ts → list-Cg_zlwVv.d.ts} +1 -1
  55. package/dist/{list-BT1Zb3PV.d.cts → list-CzGRStUr.d.cts} +1 -1
  56. package/dist/{paragraph-CdGRPSYA.d.cts → paragraph-C9jf4pMK.d.cts} +3 -0
  57. package/dist/{paragraph-BPRc-VVV.d.ts → paragraph-CeFnOpEi.d.ts} +3 -0
  58. package/dist/{shape-Cuk0RTZn.d.cts → shape-C56METn9.d.cts} +2 -2
  59. package/dist/{shape-CCPBGhbV.d.ts → shape-JrdFW78K.d.ts} +2 -2
  60. package/dist/{table-Dtml8NyR.d.ts → table-CY1ChByv.d.ts} +1 -1
  61. package/dist/{table-b9-ipGtZ.d.cts → table-Cu8f1XmW.d.cts} +1 -1
  62. package/package.json +2 -2
package/README.md CHANGED
@@ -303,7 +303,17 @@ const { comments, footnotes, headers, footers, numbering } = readDocxExtras(deco
303
303
  console.log(Object.values(numbering)[0]?.levels['0']?.format); // numbering is keyed by numId, each level by its own level index
304
304
  ```
305
305
 
306
- `openPptx`/`createPptx` and `PptxSlide`/`PptxShape` are the pptx equivalent. `openOdt`/`createOdt` and `OdtParagraph`/`OdtRun`/`OdtTable`/`OdtList` are the odt equivalent, built on ODF's style-name-referencing model. `openOdp`/`createOdp` and `OdpSlide`/`OdpShape` reuse `OdtParagraph`/`OdtRun`/`OdtList` directly (a `draw:frame`'s `draw:text-box` holds the identical `text:p`/`text:span` model):
306
+ `openPptx`/`createPptx` and `PptxSlide`/`PptxShape` are the pptx equivalent. `embeddedPresentationSerialiser` is ooxml.js's embedded-presentation port wired from this package's own pptx builder. ooxml.js has no PresentationML writer and cannot depend on the one pptx writer in the ecosystem (`buildPptxPackage`, living here one layer above it), so its docx writer instead accepts an injected serialiser; pass this value as `BuildDocxContentOptions.serialiseEmbeddedPresentation` and a docx carrying an OLE-embedded presentation — which `readDocxContent` genuinely recovers as an `embeddedObject` block — round-trips through that writer, the nested deck re-serialised into a real `word/embeddings/oleObject<N>.pptx` payload rather than refused:
307
+
308
+ ```ts
309
+ import { embeddedPresentationSerialiser } from 'documents.js';
310
+ import { buildDocxPackageFromContent, decodePackage, encodePackage, readDocxContent } from 'ooxml.js';
311
+
312
+ const content = readDocxContent(decodePackage(docxBytes)); // carries a presentation embed
313
+ const rebuilt = encodePackage(buildDocxPackageFromContent(content, { serialiseEmbeddedPresentation: embeddedPresentationSerialiser }));
314
+ ```
315
+
316
+ `openOdt`/`createOdt` and `OdtParagraph`/`OdtRun`/`OdtTable`/`OdtList` are the odt equivalent, built on ODF's style-name-referencing model. `openOdp`/`createOdp` and `OdpSlide`/`OdpShape` reuse `OdtParagraph`/`OdtRun`/`OdtList` directly (a `draw:frame`'s `draw:text-box` holds the identical `text:p`/`text:span` model):
307
317
 
308
318
  ```ts
309
319
  import { createOdp } from 'documents.js';
@@ -565,7 +575,7 @@ The package is layered from generic primitives outward to the two conversion dir
565
575
  - **`src/markdown/`** — third adapter family, via `markdown-codec`. `readMarkdownContent` passes `readMarkdownContent`'s (markdown-codec's flat reader, so named since that package's 4.0.0; the bare `readMarkdown` name is now its tree-form `DocumentPackage` reader) result through the math-lowering pass (`math.ts` — markdown-codec's preserved `$$` display blocks and `\( \)` inline spans become two-layer formula blocks, with the document's symbol table seeded from its own prose). `buildMarkdownText` wraps `writeMarkdownContent`, reconstructing markdown math syntax from formula blocks carrying a presentation layer. `text.ts` is the byte↔text boundary. `MarkdownEditor` holds a mutable in-memory `ContentDocument`.
566
576
  - **`src/csv/`** — fourth adapter family, sharing the spreadsheet variant with xlsx/ods. `records.ts` is the RFC 4180 record parser/writer (one shared `quoteCsvField`, also used by the `.odb` CSV exporter); `text.ts` is the byte↔text boundary, rejecting malformed UTF-8; `read.ts` turns records into a spreadsheet `ContentDocument` (first record as verbatim string header, data cells through the same cell-typing heuristic `pdfToOds` uses); `write.ts` turns one sheet of a spreadsheet `ContentDocument` back into records via each cell's `displayText`. TSV is the same format with `{ delimiter: '\t' }` on either side.
567
577
  - **`src/svg/`** — fifth adapter family, sharing the drawing variant with odg. `text.ts` is the byte↔text boundary, rejecting malformed UTF-8; `read.ts` maps the six SVG shape primitives (rect/circle/ellipse/line/polyline/polygon/path) onto a one-page drawing `ContentDocument`, with transform lists composed as 2×3 affines and CSS lengths and the viewBox map resolved into page points; `write.ts` writes the six primitives back out, one shape element each; `path.ts` is the full SVG path-data grammar (M/L/H/V/C/S/Z plus Q/T/A and the relative forms — S/Q/T convert exactly, A is the one bounded approximation at ≤90° per cubic); `transform.ts` parses and composes the transform attribute and classifies the result by frame representability; `units.ts` resolves CSS length units and the viewBox; `paint.ts` resolves fill/stroke presentation attributes and dash styles; `diagnostics.ts` is the shared scope-limit vocabulary.
568
- - **`src/layout/`** — the pure conversion algorithms: `engine.ts` (wordprocessing → layout: flow, line-breaking, pagination), `slides.ts` (presentation → layout: direct placement), `sheets.ts` (spreadsheet → layout: grid, print settings, the first algorithm accepting `AbortSignal`), `drawing.ts` (drawing → layout: vector primitives + shape reuse), `reconstruct.ts` (layout → content: baseline clustering for wordprocessing/presentation, near-1:1 mapping for drawing, gridline-lattice-or-text-clustering for spreadsheet; plus the PDF construct surfacing — link reconciliation to `ContentRun.hyperlink` or link constructs, hidden-layer content dropped, anchor/comment and AcroForm contentControl constructs).
578
+ - **`src/layout/`** — the pure conversion algorithms: `engine.ts` (wordprocessing → layout: flow, line-breaking, pagination), `slides.ts` (presentation → layout: direct placement), `sheets.ts` (spreadsheet → layout: grid, print settings, the first algorithm accepting `AbortSignal`), `drawing.ts` (drawing → layout: vector primitives + shape reuse), `reconstruct.ts` (layout → content: baseline clustering for wordprocessing/presentation, near-1:1 mapping for drawing, gridline-lattice-or-text-clustering for spreadsheet; plus the PDF construct surfacing — link reconciliation to `ContentRun.hyperlink` or link constructs, hidden-layer content dropped, anchor/comment and AcroForm contentControl constructs, and tagged-structure semantics where the file states them: heading levels from owning `H1`..`H6` elements over the font-size census, lattice-free table recovery from `/Table`/`/TR`/`/TH`/`/TD` ownership, and `division` constructs around `/Part`/`/Sect`/`/Div` extents).
569
579
  - **`src/hsqldb/`** — `.odb` decoders, four tiers: `script.ts` (TEXT-script DDL/DML parser), `rowformat.ts`/`cache.ts` (CACHED binary row-store), `binary-script.ts` (BINARY/COMPRESSED whole-script). All import only `document-schema.js` — no odf.js knowledge.
570
580
  - **`src/firebird/`** — Tier 3: gbak logical-backup reader. `reader.ts` (attribute framing + RLE decompression + XDR decoding), `schema.ts`/`data.ts` (table/row walking). No ratified spec — built against Firebird's own engine source.
571
581
  - **`src/odb/`** — decoder-selection and pivot-mapping: `read.ts` routes to the right tier, `spreadsheet.ts`/`csv.ts` map to output formats. `odb/sql/` is the bounded SQL engine, `odb/formula/` is the rpt formula engine, `odb/report/` is the renderer, `odb/values.ts` is shared comparison/aggregation semantics.
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_geometry = require("../model/geometry.cjs");
3
3
  const require_model_metadata = require("../model/metadata.cjs");
4
4
  const require_edit_docx_content = require("../edit/docx/content.cjs");
5
+ const require_mathml_layout = require("../mathml/layout.cjs");
5
6
  const require_edit_odt_content = require("../edit/odt/content.cjs");
6
7
  const require_fonts_registry = require("../fonts/registry.cjs");
7
- const require_mathml_layout = require("../mathml/layout.cjs");
8
8
  const require_odf_formula_read = require("../odf/formula/read.cjs");
9
9
  const require_odf_odt_read = require("../odf/odt/read.cjs");
10
10
  const require_layout_engine = require("../layout/engine.cjs");
@@ -1,9 +1,9 @@
1
1
  import { flipY } from "../model/geometry.js";
2
2
  import { resolveMetadataTimestamps } from "../model/metadata.js";
3
3
  import { buildDocxPackage } from "../edit/docx/content.js";
4
+ import { layoutFormula } from "../mathml/layout.js";
4
5
  import { buildOdtPackage } from "../edit/odt/content.js";
5
6
  import { extractSourceFonts } from "../fonts/registry.js";
6
- import { layoutFormula } from "../mathml/layout.js";
7
7
  import { readOdfFormulaContent as readOdfFormulaContent$1 } from "../odf/formula/read.js";
8
8
  import { readOdtContent as readOdtContent$1 } from "../odf/odt/read.js";
9
9
  import { convertWordprocessingToLayout } from "../layout/engine.js";
@@ -67,10 +67,25 @@ function stampPdfPackageTables(pkg, layout) {
67
67
  };
68
68
  });
69
69
  });
70
+ if (layout.structure !== void 0) walkStructureElements(layout.structure, void 0, definitions);
70
71
  if (Object.keys(definitions).length > 0) pkg.definitions = {
71
72
  ...pkg.definitions,
72
73
  ...definitions
73
74
  };
74
75
  }
76
+ function walkStructureElements(elements, parentKey, definitions) {
77
+ for (const element of elements) {
78
+ definitions[element.id] = {
79
+ kind: "structure",
80
+ type: element.type,
81
+ ...element.title !== void 0 ? { title: element.title } : {},
82
+ ...element.language !== void 0 ? { language: element.language } : {},
83
+ ...element.alt !== void 0 ? { alt: element.alt } : {},
84
+ ...element.actualText !== void 0 ? { actualText: element.actualText } : {},
85
+ ...parentKey !== void 0 ? { parent: parentKey } : {}
86
+ };
87
+ walkStructureElements(element.children, element.id, definitions);
88
+ }
89
+ }
75
90
  //#endregion
76
91
  exports.stampPdfPackageTables = stampPdfPackageTables;
@@ -66,10 +66,25 @@ function stampPdfPackageTables(pkg, layout) {
66
66
  };
67
67
  });
68
68
  });
69
+ if (layout.structure !== void 0) walkStructureElements(layout.structure, void 0, definitions);
69
70
  if (Object.keys(definitions).length > 0) pkg.definitions = {
70
71
  ...pkg.definitions,
71
72
  ...definitions
72
73
  };
73
74
  }
75
+ function walkStructureElements(elements, parentKey, definitions) {
76
+ for (const element of elements) {
77
+ definitions[element.id] = {
78
+ kind: "structure",
79
+ type: element.type,
80
+ ...element.title !== void 0 ? { title: element.title } : {},
81
+ ...element.language !== void 0 ? { language: element.language } : {},
82
+ ...element.alt !== void 0 ? { alt: element.alt } : {},
83
+ ...element.actualText !== void 0 ? { actualText: element.actualText } : {},
84
+ ...parentKey !== void 0 ? { parent: parentKey } : {}
85
+ };
86
+ walkStructureElements(element.children, element.id, definitions);
87
+ }
88
+ }
74
89
  //#endregion
75
90
  export { stampPdfPackageTables };
@@ -41,7 +41,7 @@ function appendShape(page, shape) {
41
41
  textShape.paragraphs()[0]?.remove();
42
42
  for (const block of shape.blocks) {
43
43
  if (block.kind !== "paragraph") continue;
44
- require_edit_odt_content.populateParagraph(textShape.appendParagraph(), block);
44
+ require_edit_odt_content.populateParagraph(textShape.appendParagraph(), block, { headings: false });
45
45
  }
46
46
  }
47
47
  //#endregion
@@ -40,7 +40,7 @@ function appendShape(page, shape) {
40
40
  textShape.paragraphs()[0]?.remove();
41
41
  for (const block of shape.blocks) {
42
42
  if (block.kind !== "paragraph") continue;
43
- populateParagraph(textShape.appendParagraph(), block);
43
+ populateParagraph(textShape.appendParagraph(), block, { headings: false });
44
44
  }
45
45
  }
46
46
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { t as ImageInit } from "../../image-3ql9_z1y.cjs";
2
- import { t as OdpShape } from "../../shape-Cuk0RTZn.cjs";
2
+ import { t as OdpShape } from "../../shape-C56METn9.cjs";
3
3
  import { a as OdgLineVector, l as PathVectorInit, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as OdgVector, t as BoxVectorInit } from "../../vector-D03KX8Ux.cjs";
4
4
  import { Box, ContentVector } from "document-schema.js";
5
5
  import { Package, XmlElement, XmlNode } from "odf.js";
@@ -1,5 +1,5 @@
1
1
  import { t as ImageInit } from "../../image-3ql9_z1y.js";
2
- import { t as OdpShape } from "../../shape-CCPBGhbV.js";
2
+ import { t as OdpShape } from "../../shape-JrdFW78K.js";
3
3
  import { a as OdgLineVector, l as PathVectorInit, n as LineVectorInit, o as OdgPathVector, r as OdgBoxVector, s as OdgVector, t as BoxVectorInit } from "../../vector-D03KX8Ux.js";
4
4
  import { Box, ContentVector } from "document-schema.js";
5
5
  import { Package, XmlElement, XmlNode } from "odf.js";
@@ -70,7 +70,7 @@ function appendShape(slide, shape) {
70
70
  textShape.paragraphs()[0]?.remove();
71
71
  for (const block of shape.blocks) {
72
72
  if (block.kind !== "paragraph") continue;
73
- require_edit_odt_content.populateParagraph(textShape.appendParagraph(), block);
73
+ require_edit_odt_content.populateParagraph(textShape.appendParagraph(), block, { headings: false });
74
74
  }
75
75
  }
76
76
  //#endregion
@@ -69,7 +69,7 @@ function appendShape(slide, shape) {
69
69
  textShape.paragraphs()[0]?.remove();
70
70
  for (const block of shape.blocks) {
71
71
  if (block.kind !== "paragraph") continue;
72
- populateParagraph(textShape.appendParagraph(), block);
72
+ populateParagraph(textShape.appendParagraph(), block, { headings: false });
73
73
  }
74
74
  }
75
75
  //#endregion
@@ -1,2 +1,2 @@
1
- import { i as buildTextBoxFrame, n as buildImageFrame, r as buildTableFrame, t as OdpShape } from "../../shape-Cuk0RTZn.cjs";
1
+ import { i as buildTextBoxFrame, n as buildImageFrame, r as buildTableFrame, t as OdpShape } from "../../shape-C56METn9.cjs";
2
2
  export { OdpShape, buildImageFrame, buildTableFrame, buildTextBoxFrame };
@@ -1,2 +1,2 @@
1
- import { i as buildTextBoxFrame, n as buildImageFrame, r as buildTableFrame, t as OdpShape } from "../../shape-CCPBGhbV.js";
1
+ import { i as buildTextBoxFrame, n as buildImageFrame, r as buildTableFrame, t as OdpShape } from "../../shape-JrdFW78K.js";
2
2
  export { OdpShape, buildImageFrame, buildTableFrame, buildTextBoxFrame };
@@ -1,7 +1,7 @@
1
1
  import { t as ImageInit } from "../../image-3ql9_z1y.cjs";
2
- import { t as OdpShape } from "../../shape-Cuk0RTZn.cjs";
2
+ import { t as OdpShape } from "../../shape-C56METn9.cjs";
3
3
  import { s as OdgVector } from "../../vector-D03KX8Ux.cjs";
4
- import { a as TableInit, n as OdtTable } from "../../table-b9-ipGtZ.cjs";
4
+ import { a as TableInit, n as OdtTable } from "../../table-Cu8f1XmW.cjs";
5
5
  import { Box, ContentFormula, ContentVector } from "document-schema.js";
6
6
  import { Package, XmlElement, XmlNode } from "odf.js";
7
7
  //#region src/edit/odp/slide.d.ts
@@ -1,7 +1,7 @@
1
1
  import { t as ImageInit } from "../../image-3ql9_z1y.js";
2
- import { t as OdpShape } from "../../shape-CCPBGhbV.js";
2
+ import { t as OdpShape } from "../../shape-JrdFW78K.js";
3
3
  import { s as OdgVector } from "../../vector-D03KX8Ux.js";
4
- import { a as TableInit, n as OdtTable } from "../../table-Dtml8NyR.js";
4
+ import { a as TableInit, n as OdtTable } from "../../table-CY1ChByv.js";
5
5
  import { Box, ContentFormula, ContentVector } from "document-schema.js";
6
6
  import { Package, XmlElement, XmlNode } from "odf.js";
7
7
  //#region src/edit/odp/slide.d.ts
@@ -175,7 +175,7 @@ var OdsCell = class {
175
175
  require_edit_odt_content.populateParagraph(paragraph, {
176
176
  kind: "paragraph",
177
177
  runs: [...runs]
178
- });
178
+ }, { headings: false });
179
179
  }
180
180
  };
181
181
  //#endregion
@@ -174,7 +174,7 @@ var OdsCell = class {
174
174
  populateParagraph(paragraph, {
175
175
  kind: "paragraph",
176
176
  runs: [...runs]
177
- });
177
+ }, { headings: false });
178
178
  }
179
179
  };
180
180
  //#endregion
@@ -23,7 +23,8 @@ function isMergeableImageParagraph(block) {
23
23
  }
24
24
  function appendMergedImageParagraph(body, paragraphBlock, imageBlock) {
25
25
  const paragraph = body.appendParagraph();
26
- if (paragraphBlock.styleId !== void 0) paragraph.styleId = paragraphBlock.styleId;
26
+ if (paragraphBlock.headingLevel !== void 0) paragraph.headingLevel = paragraphBlock.headingLevel;
27
+ else if (paragraphBlock.styleId !== void 0) paragraph.styleId = paragraphBlock.styleId;
27
28
  if (paragraphBlock.alignment !== void 0) paragraph.alignment = paragraphBlock.alignment;
28
29
  paragraph.insertImageAfter({
29
30
  format: imageBlock.format,
@@ -83,12 +84,13 @@ function appendListRun(body, paragraphs) {
83
84
  const currentList = stack[stack.length - 1];
84
85
  if (currentList === void 0) continue;
85
86
  const item = currentList.addItem();
86
- populateParagraph(item.appendParagraph(), para);
87
+ populateParagraph(item.appendParagraph(), para, { headings: true });
87
88
  lastItem = item;
88
89
  }
89
90
  }
90
- function populateParagraph(paragraph, block) {
91
- if (block.styleId !== void 0) paragraph.styleId = block.styleId;
91
+ function populateParagraph(paragraph, block, options) {
92
+ if (options.headings && block.headingLevel !== void 0) paragraph.headingLevel = block.headingLevel;
93
+ else if (block.styleId !== void 0) paragraph.styleId = block.styleId;
92
94
  if (block.alignment !== void 0) paragraph.alignment = block.alignment;
93
95
  if (block.spacingBeforePt !== void 0) paragraph.spacingBeforePt = block.spacingBeforePt;
94
96
  if (block.spacingAfterPt !== void 0) paragraph.spacingAfterPt = block.spacingAfterPt;
@@ -114,7 +116,7 @@ function populateParagraph(paragraph, block) {
114
116
  function populateCellBlocks(cell, blocks) {
115
117
  const [firstBlock, ...restBlocks] = blocks;
116
118
  const firstParagraph = cell.paragraphs()[0];
117
- if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
119
+ if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock, { headings: false });
118
120
  else if (firstBlock?.kind === "image" && firstParagraph !== void 0) firstParagraph.insertImageAfter({
119
121
  format: firstBlock.format,
120
122
  bytes: (0, odf_js.base64ToBytes)(firstBlock.base64),
@@ -172,7 +174,7 @@ function appendTable(body, block) {
172
174
  }), block);
173
175
  }
174
176
  function appendCellBlock(cell, block) {
175
- if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block);
177
+ if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block, { headings: false });
176
178
  else if (block.kind === "image") cell.appendParagraph().insertImageAfter({
177
179
  format: block.format,
178
180
  bytes: (0, odf_js.base64ToBytes)(block.base64),
@@ -182,7 +184,7 @@ function appendCellBlock(cell, block) {
182
184
  });
183
185
  }
184
186
  function appendBlock(body, block) {
185
- if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block);
187
+ if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block, { headings: true });
186
188
  else if (block.kind === "image") body.appendParagraph().insertImageAfter({
187
189
  format: block.format,
188
190
  bytes: (0, odf_js.base64ToBytes)(block.base64),
@@ -205,7 +207,7 @@ function appendEmbeddedObject(body, block) {
205
207
  populateParagraph(body.appendParagraph(), {
206
208
  kind: "paragraph",
207
209
  runs: [{ text: require_model_formula.formulaPlaceholderText(formula) }]
208
- });
210
+ }, { headings: false });
209
211
  return;
210
212
  }
211
213
  body.appendFormula(formula, block.frame);
@@ -1,6 +1,6 @@
1
1
  import { t as ClockPort } from "../../clock-C7SUuYN0.cjs";
2
- import { t as OdtParagraph } from "../../paragraph-CdGRPSYA.cjs";
3
- import { n as OdtTable } from "../../table-b9-ipGtZ.cjs";
2
+ import { t as OdtParagraph } from "../../paragraph-C9jf4pMK.cjs";
3
+ import { n as OdtTable } from "../../table-Cu8f1XmW.cjs";
4
4
  import { ContentDocument, ContentParagraph, ContentTable } from "document-schema.js";
5
5
  import { Package } from "odf.js";
6
6
  //#region src/edit/odt/content.d.ts
@@ -8,7 +8,10 @@ interface BuildOdtPackageOptions {
8
8
  readonly clock?: ClockPort;
9
9
  }
10
10
  declare function buildOdtPackage(content: ContentDocument, options?: BuildOdtPackageOptions): Package;
11
- declare function populateParagraph(paragraph: OdtParagraph, block: ContentParagraph): void;
11
+ interface PopulateParagraphOptions {
12
+ readonly headings: boolean;
13
+ }
14
+ declare function populateParagraph(paragraph: OdtParagraph, block: ContentParagraph, options: PopulateParagraphOptions): void;
12
15
  declare function populateOdtTable(table: OdtTable, block: ContentTable): void;
13
16
  //#endregion
14
- export { BuildOdtPackageOptions, buildOdtPackage, populateOdtTable, populateParagraph };
17
+ export { BuildOdtPackageOptions, PopulateParagraphOptions, buildOdtPackage, populateOdtTable, populateParagraph };
@@ -1,6 +1,6 @@
1
1
  import { t as ClockPort } from "../../clock-C7SUuYN0.js";
2
- import { t as OdtParagraph } from "../../paragraph-BPRc-VVV.js";
3
- import { n as OdtTable } from "../../table-Dtml8NyR.js";
2
+ import { t as OdtParagraph } from "../../paragraph-CeFnOpEi.js";
3
+ import { n as OdtTable } from "../../table-CY1ChByv.js";
4
4
  import { ContentDocument, ContentParagraph, ContentTable } from "document-schema.js";
5
5
  import { Package } from "odf.js";
6
6
  //#region src/edit/odt/content.d.ts
@@ -8,7 +8,10 @@ interface BuildOdtPackageOptions {
8
8
  readonly clock?: ClockPort;
9
9
  }
10
10
  declare function buildOdtPackage(content: ContentDocument, options?: BuildOdtPackageOptions): Package;
11
- declare function populateParagraph(paragraph: OdtParagraph, block: ContentParagraph): void;
11
+ interface PopulateParagraphOptions {
12
+ readonly headings: boolean;
13
+ }
14
+ declare function populateParagraph(paragraph: OdtParagraph, block: ContentParagraph, options: PopulateParagraphOptions): void;
12
15
  declare function populateOdtTable(table: OdtTable, block: ContentTable): void;
13
16
  //#endregion
14
- export { BuildOdtPackageOptions, buildOdtPackage, populateOdtTable, populateParagraph };
17
+ export { BuildOdtPackageOptions, PopulateParagraphOptions, buildOdtPackage, populateOdtTable, populateParagraph };
@@ -22,7 +22,8 @@ function isMergeableImageParagraph(block) {
22
22
  }
23
23
  function appendMergedImageParagraph(body, paragraphBlock, imageBlock) {
24
24
  const paragraph = body.appendParagraph();
25
- if (paragraphBlock.styleId !== void 0) paragraph.styleId = paragraphBlock.styleId;
25
+ if (paragraphBlock.headingLevel !== void 0) paragraph.headingLevel = paragraphBlock.headingLevel;
26
+ else if (paragraphBlock.styleId !== void 0) paragraph.styleId = paragraphBlock.styleId;
26
27
  if (paragraphBlock.alignment !== void 0) paragraph.alignment = paragraphBlock.alignment;
27
28
  paragraph.insertImageAfter({
28
29
  format: imageBlock.format,
@@ -82,12 +83,13 @@ function appendListRun(body, paragraphs) {
82
83
  const currentList = stack[stack.length - 1];
83
84
  if (currentList === void 0) continue;
84
85
  const item = currentList.addItem();
85
- populateParagraph(item.appendParagraph(), para);
86
+ populateParagraph(item.appendParagraph(), para, { headings: true });
86
87
  lastItem = item;
87
88
  }
88
89
  }
89
- function populateParagraph(paragraph, block) {
90
- if (block.styleId !== void 0) paragraph.styleId = block.styleId;
90
+ function populateParagraph(paragraph, block, options) {
91
+ if (options.headings && block.headingLevel !== void 0) paragraph.headingLevel = block.headingLevel;
92
+ else if (block.styleId !== void 0) paragraph.styleId = block.styleId;
91
93
  if (block.alignment !== void 0) paragraph.alignment = block.alignment;
92
94
  if (block.spacingBeforePt !== void 0) paragraph.spacingBeforePt = block.spacingBeforePt;
93
95
  if (block.spacingAfterPt !== void 0) paragraph.spacingAfterPt = block.spacingAfterPt;
@@ -113,7 +115,7 @@ function populateParagraph(paragraph, block) {
113
115
  function populateCellBlocks(cell, blocks) {
114
116
  const [firstBlock, ...restBlocks] = blocks;
115
117
  const firstParagraph = cell.paragraphs()[0];
116
- if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
118
+ if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock, { headings: false });
117
119
  else if (firstBlock?.kind === "image" && firstParagraph !== void 0) firstParagraph.insertImageAfter({
118
120
  format: firstBlock.format,
119
121
  bytes: base64ToBytes(firstBlock.base64),
@@ -171,7 +173,7 @@ function appendTable(body, block) {
171
173
  }), block);
172
174
  }
173
175
  function appendCellBlock(cell, block) {
174
- if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block);
176
+ if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block, { headings: false });
175
177
  else if (block.kind === "image") cell.appendParagraph().insertImageAfter({
176
178
  format: block.format,
177
179
  bytes: base64ToBytes(block.base64),
@@ -181,7 +183,7 @@ function appendCellBlock(cell, block) {
181
183
  });
182
184
  }
183
185
  function appendBlock(body, block) {
184
- if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block);
186
+ if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block, { headings: true });
185
187
  else if (block.kind === "image") body.appendParagraph().insertImageAfter({
186
188
  format: block.format,
187
189
  bytes: base64ToBytes(block.base64),
@@ -204,7 +206,7 @@ function appendEmbeddedObject(body, block) {
204
206
  populateParagraph(body.appendParagraph(), {
205
207
  kind: "paragraph",
206
208
  runs: [{ text: formulaPlaceholderText(formula) }]
207
- });
209
+ }, { headings: false });
208
210
  return;
209
211
  }
210
212
  body.appendFormula(formula, block.frame);
@@ -80,7 +80,7 @@ var OdtEditor = class {
80
80
  paragraphs() {
81
81
  const officeText = findOfficeText(findContentRoot(this.pkg));
82
82
  const out = [];
83
- for (const child of officeText.children) if (child.type === "element" && child.tag === "text:p") out.push(new require_edit_odt_paragraph.OdtParagraph(officeText.children, child, this.pkg));
83
+ for (const child of officeText.children) if (child.type === "element" && (child.tag === "text:p" || child.tag === "text:h")) out.push(new require_edit_odt_paragraph.OdtParagraph(officeText.children, child, this.pkg));
84
84
  return out;
85
85
  }
86
86
  tables() {
@@ -1,7 +1,7 @@
1
1
  import { t as ClockPort } from "../../clock-C7SUuYN0.cjs";
2
- import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-CdGRPSYA.cjs";
3
- import { t as OdtList } from "../../list-BT1Zb3PV.cjs";
4
- import { a as TableInit, n as OdtTable } from "../../table-b9-ipGtZ.cjs";
2
+ import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-C9jf4pMK.cjs";
3
+ import { t as OdtList } from "../../list-CzGRStUr.cjs";
4
+ import { a as TableInit, n as OdtTable } from "../../table-Cu8f1XmW.cjs";
5
5
  import { Box, ContentFormula, ContentVector } from "document-schema.js";
6
6
  import { Package } from "odf.js";
7
7
  //#region src/edit/odt/editor.d.ts
@@ -1,7 +1,7 @@
1
1
  import { t as ClockPort } from "../../clock-C7SUuYN0.js";
2
- import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-BPRc-VVV.js";
3
- import { t as OdtList } from "../../list-D9MtQtjK.js";
4
- import { a as TableInit, n as OdtTable } from "../../table-Dtml8NyR.js";
2
+ import { n as ParagraphInit, t as OdtParagraph } from "../../paragraph-CeFnOpEi.js";
3
+ import { t as OdtList } from "../../list-Cg_zlwVv.js";
4
+ import { a as TableInit, n as OdtTable } from "../../table-CY1ChByv.js";
5
5
  import { Box, ContentFormula, ContentVector } from "document-schema.js";
6
6
  import { Package } from "odf.js";
7
7
  //#region src/edit/odt/editor.d.ts
@@ -79,7 +79,7 @@ var OdtEditor = class {
79
79
  paragraphs() {
80
80
  const officeText = findOfficeText(findContentRoot(this.pkg));
81
81
  const out = [];
82
- for (const child of officeText.children) if (child.type === "element" && child.tag === "text:p") out.push(new OdtParagraph(officeText.children, child, this.pkg));
82
+ for (const child of officeText.children) if (child.type === "element" && (child.tag === "text:p" || child.tag === "text:h")) out.push(new OdtParagraph(officeText.children, child, this.pkg));
83
83
  return out;
84
84
  }
85
85
  tables() {
@@ -35,7 +35,7 @@ var OdtListItem = class {
35
35
  }
36
36
  paragraphs() {
37
37
  const out = [];
38
- for (const child of this.node.children) if (child.type === "element" && child.tag === "text:p") out.push(new require_edit_odt_paragraph.OdtParagraph(this.node.children, child, this.pkg));
38
+ for (const child of this.node.children) if (child.type === "element" && (child.tag === "text:p" || child.tag === "text:h")) out.push(new require_edit_odt_paragraph.OdtParagraph(this.node.children, child, this.pkg));
39
39
  return out;
40
40
  }
41
41
  get text() {
@@ -1,2 +1,2 @@
1
- import { n as OdtListItem, r as buildList, t as OdtList } from "../../list-BT1Zb3PV.cjs";
1
+ import { n as OdtListItem, r as buildList, t as OdtList } from "../../list-CzGRStUr.cjs";
2
2
  export { OdtList, OdtListItem, buildList };
@@ -1,2 +1,2 @@
1
- import { n as OdtListItem, r as buildList, t as OdtList } from "../../list-D9MtQtjK.js";
1
+ import { n as OdtListItem, r as buildList, t as OdtList } from "../../list-Cg_zlwVv.js";
2
2
  export { OdtList, OdtListItem, buildList };
@@ -34,7 +34,7 @@ var OdtListItem = class {
34
34
  }
35
35
  paragraphs() {
36
36
  const out = [];
37
- for (const child of this.node.children) if (child.type === "element" && child.tag === "text:p") out.push(new OdtParagraph(this.node.children, child, this.pkg));
37
+ 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));
38
38
  return out;
39
39
  }
40
40
  get text() {
@@ -71,6 +71,26 @@ var OdtParagraph = class {
71
71
  }
72
72
  require_xml_edit.setAttr(node, "text:style-name", value);
73
73
  }
74
+ get headingLevel() {
75
+ const node = this.live();
76
+ if (node.tag !== "text:h") return;
77
+ const raw = (0, ooxml_js.attr)(node, "text:outline-level");
78
+ if (raw === void 0) return 1;
79
+ const parsed = Number.parseInt(raw, 10);
80
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
81
+ }
82
+ set headingLevel(value) {
83
+ const node = this.live();
84
+ if (value === void 0) {
85
+ node.tag = "text:p";
86
+ require_xml_edit.removeAttr(node, "text:outline-level");
87
+ require_xml_edit.removeAttr(node, "text:style-name");
88
+ return;
89
+ }
90
+ node.tag = "text:h";
91
+ require_xml_edit.setAttr(node, "text:outline-level", String(value));
92
+ require_xml_edit.setAttr(node, "text:style-name", `Heading_20_${String(value)}`);
93
+ }
74
94
  get alignment() {
75
95
  return require_edit_odt_props.readCurrentStyleProperties(this.pkg, this.live(), "paragraph").alignment;
76
96
  }
@@ -125,7 +145,8 @@ var OdtParagraph = class {
125
145
  function buildParagraph(pkg, init = {}) {
126
146
  const node = require_xml_fragment.el("text:p");
127
147
  const paragraph = new OdtParagraph([], node, pkg);
128
- if (init.styleId !== void 0) paragraph.styleId = init.styleId;
148
+ if (init.headingLevel !== void 0) paragraph.headingLevel = init.headingLevel;
149
+ else if (init.styleId !== void 0) paragraph.styleId = init.styleId;
129
150
  if (init.alignment !== void 0) paragraph.alignment = init.alignment;
130
151
  if (init.text !== void 0) node.children.push(require_edit_odt_run.buildRun(pkg, { text: init.text }));
131
152
  return node;
@@ -1,2 +1,2 @@
1
- import { n as ParagraphInit, r as buildParagraph, t as OdtParagraph } from "../../paragraph-CdGRPSYA.cjs";
1
+ import { n as ParagraphInit, r as buildParagraph, t as OdtParagraph } from "../../paragraph-C9jf4pMK.cjs";
2
2
  export { OdtParagraph, ParagraphInit, buildParagraph };
@@ -1,2 +1,2 @@
1
- import { n as ParagraphInit, r as buildParagraph, t as OdtParagraph } from "../../paragraph-BPRc-VVV.js";
1
+ import { n as ParagraphInit, r as buildParagraph, t as OdtParagraph } from "../../paragraph-CeFnOpEi.js";
2
2
  export { OdtParagraph, ParagraphInit, buildParagraph };
@@ -70,6 +70,26 @@ var OdtParagraph = class {
70
70
  }
71
71
  setAttr(node, "text:style-name", value);
72
72
  }
73
+ get headingLevel() {
74
+ const node = this.live();
75
+ if (node.tag !== "text:h") return;
76
+ const raw = attr(node, "text:outline-level");
77
+ if (raw === void 0) return 1;
78
+ const parsed = Number.parseInt(raw, 10);
79
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : 1;
80
+ }
81
+ set headingLevel(value) {
82
+ const node = this.live();
83
+ if (value === void 0) {
84
+ node.tag = "text:p";
85
+ removeAttr(node, "text:outline-level");
86
+ removeAttr(node, "text:style-name");
87
+ return;
88
+ }
89
+ node.tag = "text:h";
90
+ setAttr(node, "text:outline-level", String(value));
91
+ setAttr(node, "text:style-name", `Heading_20_${String(value)}`);
92
+ }
73
93
  get alignment() {
74
94
  return readCurrentStyleProperties(this.pkg, this.live(), "paragraph").alignment;
75
95
  }
@@ -124,7 +144,8 @@ var OdtParagraph = class {
124
144
  function buildParagraph(pkg, init = {}) {
125
145
  const node = el("text:p");
126
146
  const paragraph = new OdtParagraph([], node, pkg);
127
- if (init.styleId !== void 0) paragraph.styleId = init.styleId;
147
+ if (init.headingLevel !== void 0) paragraph.headingLevel = init.headingLevel;
148
+ else if (init.styleId !== void 0) paragraph.styleId = init.styleId;
128
149
  if (init.alignment !== void 0) paragraph.alignment = init.alignment;
129
150
  if (init.text !== void 0) node.children.push(buildRun(pkg, { text: init.text }));
130
151
  return node;
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_xml_fragment = require("../../xml/fragment.cjs");
3
3
  const require_xml_entities = require("../../xml/entities.cjs");
4
+ const require_layout_shared = require("../../layout/shared.cjs");
4
5
  let document_schema_js = require("document-schema.js");
5
6
  let odf_js = require("odf.js");
6
7
  //#region src/edit/odt/scaffold.ts
@@ -62,12 +63,22 @@ function buildPageLayout() {
62
63
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
63
64
  })]);
64
65
  }
66
+ function buildHeadingStyles() {
67
+ return Object.entries(require_layout_shared.HEADING_STYLES).map(([level, style]) => require_xml_fragment.el("style:style", {
68
+ "style:name": `Heading_20_${level}`,
69
+ "style:display-name": `Heading ${level}`,
70
+ "style:family": "paragraph"
71
+ }, [require_xml_fragment.el("style:text-properties", {
72
+ "fo:font-size": `${String(style.sizePt)}pt`,
73
+ "fo:font-weight": style.bold ? "bold" : "normal"
74
+ })]));
75
+ }
65
76
  function buildStylesXml() {
66
77
  return require_xml_fragment.el("office:document-styles", {
67
78
  ...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
68
79
  "office:version": ODF_VERSION
69
80
  }, [
70
- require_xml_fragment.el("office:styles"),
81
+ require_xml_fragment.el("office:styles", {}, buildHeadingStyles()),
71
82
  require_xml_fragment.el("office:automatic-styles", {}, [buildPageLayout()]),
72
83
  require_xml_fragment.el("office:master-styles", {}, [require_xml_fragment.el("style:master-page", {
73
84
  "style:name": MASTER_PAGE_NAME,
@@ -1,5 +1,6 @@
1
1
  import { el, txt } from "../../xml/fragment.js";
2
2
  import { encodeXmlText as encodeXmlText$1 } from "../../xml/entities.js";
3
+ import { HEADING_STYLES } from "../../layout/shared.js";
3
4
  import { PAGE_SIZE_LETTER } from "document-schema.js";
4
5
  import { ODF_MEDIA_TYPES, setDocumentMediaType, syncManifest, xmlnsAttributes } from "odf.js";
5
6
  //#region src/edit/odt/scaffold.ts
@@ -61,12 +62,22 @@ function buildPageLayout() {
61
62
  "fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
62
63
  })]);
63
64
  }
65
+ function buildHeadingStyles() {
66
+ return Object.entries(HEADING_STYLES).map(([level, style]) => el("style:style", {
67
+ "style:name": `Heading_20_${level}`,
68
+ "style:display-name": `Heading ${level}`,
69
+ "style:family": "paragraph"
70
+ }, [el("style:text-properties", {
71
+ "fo:font-size": `${String(style.sizePt)}pt`,
72
+ "fo:font-weight": style.bold ? "bold" : "normal"
73
+ })]));
74
+ }
64
75
  function buildStylesXml() {
65
76
  return el("office:document-styles", {
66
77
  ...xmlnsAttributes([...STYLES_NS_PREFIXES]),
67
78
  "office:version": ODF_VERSION
68
79
  }, [
69
- el("office:styles"),
80
+ el("office:styles", {}, buildHeadingStyles()),
70
81
  el("office:automatic-styles", {}, [buildPageLayout()]),
71
82
  el("office:master-styles", {}, [el("style:master-page", {
72
83
  "style:name": MASTER_PAGE_NAME,