js.documents 6.5.3 → 7.0.1

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 (48) hide show
  1. package/README.md +10 -1
  2. package/dist/convert/from-package.cjs +6 -4
  3. package/dist/convert/from-package.js +7 -5
  4. package/dist/edit/docx/content.cjs +2 -1
  5. package/dist/edit/docx/content.js +2 -1
  6. package/dist/edit/docx/table.cjs +2 -4
  7. package/dist/edit/docx/table.js +4 -6
  8. package/dist/edit/odp/slide.d.cts +1 -1
  9. package/dist/edit/odp/slide.d.ts +1 -1
  10. package/dist/edit/odt/content.cjs +3 -1
  11. package/dist/edit/odt/content.d.cts +1 -1
  12. package/dist/edit/odt/content.d.ts +1 -1
  13. package/dist/edit/odt/content.js +3 -1
  14. package/dist/edit/odt/editor.d.cts +1 -1
  15. package/dist/edit/odt/editor.d.ts +1 -1
  16. package/dist/edit/odt/table.cjs +64 -0
  17. package/dist/edit/odt/table.d.cts +1 -1
  18. package/dist/edit/odt/table.d.ts +1 -1
  19. package/dist/edit/odt/table.js +65 -1
  20. package/dist/edit/pptx/content.cjs +2 -1
  21. package/dist/edit/pptx/content.js +2 -1
  22. package/dist/edit/pptx/table.cjs +3 -1
  23. package/dist/edit/pptx/table.js +3 -1
  24. package/dist/index.cjs +2 -0
  25. package/dist/index.d.cts +5 -5
  26. package/dist/index.d.ts +5 -5
  27. package/dist/index.js +3 -3
  28. package/dist/latex/lint.cjs +2 -26
  29. package/dist/latex/lint.js +2 -26
  30. package/dist/layout/engine.cjs +3 -2
  31. package/dist/layout/engine.js +4 -3
  32. package/dist/layout/reconstruct.cjs +6 -3
  33. package/dist/layout/reconstruct.js +6 -3
  34. package/dist/layout/sheets.cjs +3 -1
  35. package/dist/layout/sheets.js +4 -2
  36. package/dist/layout/slides.cjs +3 -2
  37. package/dist/layout/slides.js +4 -3
  38. package/dist/metadata/write.cjs +19 -2
  39. package/dist/metadata/write.d.cts +5 -1
  40. package/dist/metadata/write.d.ts +5 -1
  41. package/dist/metadata/write.js +19 -3
  42. package/dist/model/formula.cjs +70 -2
  43. package/dist/model/formula.d.cts +10 -3
  44. package/dist/model/formula.d.ts +10 -3
  45. package/dist/model/formula.js +70 -3
  46. package/dist/{table-DCqmpGAB.d.ts → table-BmMyqRML.d.ts} +2 -0
  47. package/dist/{table-CnRh10dW.d.cts → table-COmzfIOe.d.cts} +2 -0
  48. package/package.json +13 -13
@@ -1,11 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_bytes = require("../model/bytes.cjs");
3
+ const require_opc_core_properties = require("../opc/core-properties.cjs");
3
4
  const require_ports_abort = require("../ports/abort.cjs");
4
5
  const require_codecs_registry = require("../codecs/registry.cjs");
6
+ let ooxml_js = require("ooxml.js");
5
7
  let pdf_codec = require("pdf-codec");
6
8
  //#region src/metadata/write.ts
7
9
  const REBUILD_FORMATS = {
8
- docx: true,
9
10
  pptx: true,
10
11
  odt: true,
11
12
  odp: true,
@@ -37,16 +38,30 @@ function mergeMetadata(current, overrides) {
37
38
  ...overrides.keywords !== void 0 ? { keywords: overrides.keywords } : {}
38
39
  };
39
40
  }
41
+ function hasWritableMetadataOverride(overrides) {
42
+ return overrides.title !== void 0 || overrides.author !== void 0 || overrides.subject !== void 0 || overrides.keywords !== void 0 && overrides.keywords.length > 0;
43
+ }
44
+ function patchDocxMetadata(bytes, overrides, options) {
45
+ require_ports_abort.throwIfAborted(options?.signal);
46
+ const pkg = (0, ooxml_js.decodePackage)(bytes);
47
+ if ((0, ooxml_js.hasCoreProperties)(pkg)) (0, ooxml_js.patchCoreProperties)(pkg, overrides);
48
+ else if (hasWritableMetadataOverride(overrides)) require_opc_core_properties.addCoreProperties(pkg, mergeMetadata({}, overrides));
49
+ return (0, ooxml_js.encodePackage)(pkg);
50
+ }
40
51
  function classifyWritePath(source, target) {
41
52
  if (source === "pdf" && target === "pdf") return { kind: "pdf" };
53
+ if (source === "docx" && target === "docx") return { kind: "docx-patch" };
42
54
  if (target === "odf" || source === "odf") return { errorMessage: "'odf' (a standalone formula document) is not a supported setDocumentMetadata source or target -- it has no write path back out at all" };
43
55
  if (target === "csv" || source === "csv") return { errorMessage: "'csv' is not a supported setDocumentMetadata source or target -- RFC 4180 text has no metadata container, so a rebuild would silently drop the override. Convert to or from csv first, then patch metadata on the package format." };
44
56
  if (target === "svg" || source === "svg") return { errorMessage: "'svg' is not a supported setDocumentMetadata source or target -- this package's SVG metadata surface is the root <title> element alone, so an author/subject/keywords override would be silently dropped by the rebuild. Convert to or from svg first, then patch metadata on the package format." };
45
57
  if (target === "doc" || source === "doc") return { errorMessage: "'doc' is not a supported setDocumentMetadata source or target -- doc-codec's reader always returns empty metadata and its writer never references document.metadata at all, so a rebuild would silently drop the override. Convert to or from doc first, then patch metadata on the package format." };
46
58
  if (target === "xls" || source === "xls") return { errorMessage: "'xls' is not a supported setDocumentMetadata source or target -- xls-codec's reader always returns empty metadata and its writer never references document.metadata at all, so a rebuild would silently drop the override. Convert to or from xls first, then patch metadata on the package format." };
47
59
  if (target === "ppt" || source === "ppt") return { errorMessage: "'ppt' is not a supported setDocumentMetadata source or target -- ppt-codec's reader always returns empty metadata (document properties live in the compound file's own SummaryInformation stream, which it does not read) and its writer never references it either, so a rebuild would silently drop the override. Convert to or from ppt first, then patch metadata on the package format." };
48
- if (!isRebuildFormat(source) || !isRebuildFormat(target)) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format (or both 'pdf'). Convert first if you need a different target format.` };
60
+ const sourcePatchable = source === "docx" || isRebuildFormat(source);
61
+ const targetPatchable = target === "docx" || isRebuildFormat(target);
62
+ if (!sourcePatchable || !targetPatchable) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format (or both 'pdf'). Convert first if you need a different target format.` };
49
63
  if (source !== target) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format. Convert first if you need a different target format.` };
64
+ if (!isRebuildFormat(source)) throw new Error(`classifyWritePath: unreachable -- '${source}' is patchable and matches its target but is neither 'docx' nor a RebuildFormat`);
50
65
  return {
51
66
  kind: "rebuild",
52
67
  format: source
@@ -64,6 +79,7 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
64
79
  };
65
80
  return (0, pdf_codec.writePdf)(patched, { signal: options?.signal });
66
81
  }
82
+ if (writePath.kind === "docx-patch") return patchDocxMetadata(bytes, overrides, { signal: options?.signal });
67
83
  const content = readContentForFormat(writePath.format, bytes, {
68
84
  signal: options?.signal,
69
85
  images: options?.images
@@ -75,4 +91,5 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
75
91
  return buildBytesForRebuildFormat(writePath.format, nextContent);
76
92
  }
77
93
  //#endregion
94
+ exports.patchDocxMetadata = patchDocxMetadata;
78
95
  exports.setDocumentMetadata = setDocumentMetadata;
@@ -7,10 +7,14 @@ interface MetadataOverrides {
7
7
  readonly subject?: string;
8
8
  readonly keywords?: string[];
9
9
  }
10
+ interface PatchDocxMetadataOptions {
11
+ readonly signal?: AbortSignal;
12
+ }
13
+ declare function patchDocxMetadata(bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: PatchDocxMetadataOptions): Uint8Array<ArrayBuffer>;
10
14
  interface SetDocumentMetadataOptions {
11
15
  readonly signal?: AbortSignal;
12
16
  readonly images?: MarkdownImageResolver;
13
17
  }
14
18
  declare function setDocumentMetadata(sourceFormat: DocumentFormat, targetFormat: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: SetDocumentMetadataOptions): Uint8Array<ArrayBuffer>;
15
19
  //#endregion
16
- export { MetadataOverrides, SetDocumentMetadataOptions, setDocumentMetadata };
20
+ export { MetadataOverrides, PatchDocxMetadataOptions, SetDocumentMetadataOptions, patchDocxMetadata, setDocumentMetadata };
@@ -7,10 +7,14 @@ interface MetadataOverrides {
7
7
  readonly subject?: string;
8
8
  readonly keywords?: string[];
9
9
  }
10
+ interface PatchDocxMetadataOptions {
11
+ readonly signal?: AbortSignal;
12
+ }
13
+ declare function patchDocxMetadata(bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: PatchDocxMetadataOptions): Uint8Array<ArrayBuffer>;
10
14
  interface SetDocumentMetadataOptions {
11
15
  readonly signal?: AbortSignal;
12
16
  readonly images?: MarkdownImageResolver;
13
17
  }
14
18
  declare function setDocumentMetadata(sourceFormat: DocumentFormat, targetFormat: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: SetDocumentMetadataOptions): Uint8Array<ArrayBuffer>;
15
19
  //#endregion
16
- export { MetadataOverrides, SetDocumentMetadataOptions, setDocumentMetadata };
20
+ export { MetadataOverrides, PatchDocxMetadataOptions, SetDocumentMetadataOptions, patchDocxMetadata, setDocumentMetadata };
@@ -1,10 +1,11 @@
1
1
  import { requireArrayBufferBytes } from "../model/bytes.js";
2
+ import { addCoreProperties } from "../opc/core-properties.js";
2
3
  import { throwIfAborted } from "../ports/abort.js";
3
4
  import { DOCUMENT_FORMAT_CODECS } from "../codecs/registry.js";
5
+ import { decodePackage, encodePackage, hasCoreProperties, patchCoreProperties } from "ooxml.js";
4
6
  import { readPdf, writePdf } from "pdf-codec";
5
7
  //#region src/metadata/write.ts
6
8
  const REBUILD_FORMATS = {
7
- docx: true,
8
9
  pptx: true,
9
10
  odt: true,
10
11
  odp: true,
@@ -36,16 +37,30 @@ function mergeMetadata(current, overrides) {
36
37
  ...overrides.keywords !== void 0 ? { keywords: overrides.keywords } : {}
37
38
  };
38
39
  }
40
+ function hasWritableMetadataOverride(overrides) {
41
+ return overrides.title !== void 0 || overrides.author !== void 0 || overrides.subject !== void 0 || overrides.keywords !== void 0 && overrides.keywords.length > 0;
42
+ }
43
+ function patchDocxMetadata(bytes, overrides, options) {
44
+ throwIfAborted(options?.signal);
45
+ const pkg = decodePackage(bytes);
46
+ if (hasCoreProperties(pkg)) patchCoreProperties(pkg, overrides);
47
+ else if (hasWritableMetadataOverride(overrides)) addCoreProperties(pkg, mergeMetadata({}, overrides));
48
+ return encodePackage(pkg);
49
+ }
39
50
  function classifyWritePath(source, target) {
40
51
  if (source === "pdf" && target === "pdf") return { kind: "pdf" };
52
+ if (source === "docx" && target === "docx") return { kind: "docx-patch" };
41
53
  if (target === "odf" || source === "odf") return { errorMessage: "'odf' (a standalone formula document) is not a supported setDocumentMetadata source or target -- it has no write path back out at all" };
42
54
  if (target === "csv" || source === "csv") return { errorMessage: "'csv' is not a supported setDocumentMetadata source or target -- RFC 4180 text has no metadata container, so a rebuild would silently drop the override. Convert to or from csv first, then patch metadata on the package format." };
43
55
  if (target === "svg" || source === "svg") return { errorMessage: "'svg' is not a supported setDocumentMetadata source or target -- this package's SVG metadata surface is the root <title> element alone, so an author/subject/keywords override would be silently dropped by the rebuild. Convert to or from svg first, then patch metadata on the package format." };
44
56
  if (target === "doc" || source === "doc") return { errorMessage: "'doc' is not a supported setDocumentMetadata source or target -- doc-codec's reader always returns empty metadata and its writer never references document.metadata at all, so a rebuild would silently drop the override. Convert to or from doc first, then patch metadata on the package format." };
45
57
  if (target === "xls" || source === "xls") return { errorMessage: "'xls' is not a supported setDocumentMetadata source or target -- xls-codec's reader always returns empty metadata and its writer never references document.metadata at all, so a rebuild would silently drop the override. Convert to or from xls first, then patch metadata on the package format." };
46
58
  if (target === "ppt" || source === "ppt") return { errorMessage: "'ppt' is not a supported setDocumentMetadata source or target -- ppt-codec's reader always returns empty metadata (document properties live in the compound file's own SummaryInformation stream, which it does not read) and its writer never references it either, so a rebuild would silently drop the override. Convert to or from ppt first, then patch metadata on the package format." };
47
- if (!isRebuildFormat(source) || !isRebuildFormat(target)) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format (or both 'pdf'). Convert first if you need a different target format.` };
59
+ const sourcePatchable = source === "docx" || isRebuildFormat(source);
60
+ const targetPatchable = target === "docx" || isRebuildFormat(target);
61
+ if (!sourcePatchable || !targetPatchable) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format (or both 'pdf'). Convert first if you need a different target format.` };
48
62
  if (source !== target) return { errorMessage: `setDocumentMetadata only patches metadata in place; it does not convert format -- source ('${source}') and target ('${target}') must be the same format. Convert first if you need a different target format.` };
63
+ if (!isRebuildFormat(source)) throw new Error(`classifyWritePath: unreachable -- '${source}' is patchable and matches its target but is neither 'docx' nor a RebuildFormat`);
49
64
  return {
50
65
  kind: "rebuild",
51
66
  format: source
@@ -63,6 +78,7 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
63
78
  };
64
79
  return writePdf(patched, { signal: options?.signal });
65
80
  }
81
+ if (writePath.kind === "docx-patch") return patchDocxMetadata(bytes, overrides, { signal: options?.signal });
66
82
  const content = readContentForFormat(writePath.format, bytes, {
67
83
  signal: options?.signal,
68
84
  images: options?.images
@@ -74,4 +90,4 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
74
90
  return buildBytesForRebuildFormat(writePath.format, nextContent);
75
91
  }
76
92
  //#endregion
77
- export { setDocumentMetadata };
93
+ export { patchDocxMetadata, setDocumentMetadata };
@@ -16,14 +16,82 @@ function buildFormulaBlock(formula, frame, sourcePath) {
16
16
  sourcePath
17
17
  };
18
18
  }
19
- function formulaOfBlock(block) {
20
- return block.document.kind === "formula" ? block.document.formula : void 0;
19
+ function formulaOfBlock(object) {
20
+ return object.document.kind === "formula" ? object.document.formula : void 0;
21
+ }
22
+ function collectFormulasFromBlocks(blocks, locate, symbolTable, out) {
23
+ for (const [index, block] of blocks.entries()) {
24
+ if (block.kind === "table") {
25
+ for (const [rowIndex, row] of block.rows.entries()) for (const [cellIndex, cell] of row.cells.entries()) collectFormulasFromBlocks(cell.blocks, `${locate}/blocks[${String(index)}].rows[${String(rowIndex)}].cells[${String(cellIndex)}]`, symbolTable, out);
26
+ continue;
27
+ }
28
+ if (block.kind === "embeddedObject") {
29
+ const formula = formulaOfBlock(block);
30
+ const blockLocate = `${locate}/blocks[${String(index)}]`;
31
+ if (formula !== void 0) out.push({
32
+ formula,
33
+ sourcePath: block.sourcePath,
34
+ locate: blockLocate,
35
+ symbolTable: block.document.symbolTable ?? symbolTable
36
+ });
37
+ else for (const nested of collectDocumentFormulas(block.document, symbolTable)) out.push({
38
+ formula: nested.formula,
39
+ sourcePath: nested.sourcePath,
40
+ locate: `${blockLocate}/${nested.locate}`,
41
+ symbolTable: nested.symbolTable
42
+ });
43
+ }
44
+ }
45
+ }
46
+ function collectDocumentFormulas(document, enclosingSymbolTable) {
47
+ const symbolTable = document.symbolTable ?? enclosingSymbolTable;
48
+ const out = [];
49
+ switch (document.kind) {
50
+ case "wordprocessing":
51
+ for (const [index, section] of document.sections.entries()) collectFormulasFromBlocks(section.blocks, `sections[${String(index)}]`, symbolTable, out);
52
+ break;
53
+ case "presentation":
54
+ for (const [slideIndex, slide] of document.slides.entries()) for (const [shapeIndex, shape] of slide.shapes.entries()) collectFormulasFromBlocks(shape.blocks, `slides[${String(slideIndex)}].shapes[${String(shapeIndex)}]`, symbolTable, out);
55
+ break;
56
+ case "drawing":
57
+ for (const [pageIndex, page] of document.pages.entries()) for (const [shapeIndex, shape] of page.shapes.entries()) collectFormulasFromBlocks(shape.blocks, `pages[${String(pageIndex)}].shapes[${String(shapeIndex)}]`, symbolTable, out);
58
+ break;
59
+ case "spreadsheet":
60
+ for (const [sheetIndex, sheet] of document.sheets.entries()) for (const [objectIndex, object] of (sheet.embeddedObjects ?? []).entries()) {
61
+ const formula = formulaOfBlock(object);
62
+ const objectLocate = `sheets[${String(sheetIndex)}].embeddedObjects[${String(objectIndex)}]`;
63
+ if (formula !== void 0) out.push({
64
+ formula,
65
+ sourcePath: void 0,
66
+ locate: objectLocate,
67
+ symbolTable: object.document.symbolTable ?? symbolTable
68
+ });
69
+ else for (const nested of collectDocumentFormulas(object.document, symbolTable)) out.push({
70
+ formula: nested.formula,
71
+ sourcePath: nested.sourcePath,
72
+ locate: `${objectLocate}/${nested.locate}`,
73
+ symbolTable: nested.symbolTable
74
+ });
75
+ }
76
+ break;
77
+ case "formula":
78
+ out.push({
79
+ formula: document.formula,
80
+ sourcePath: void 0,
81
+ locate: "formula",
82
+ symbolTable
83
+ });
84
+ break;
85
+ default: throw new Error(`collectDocumentFormulas: unhandled ContentDocument kind ${JSON.stringify(document.kind)}`);
86
+ }
87
+ return out;
21
88
  }
22
89
  function formulaPlaceholderText(formula) {
23
90
  return formula.starMath ?? formula.presentation?.latex ?? "[formula]";
24
91
  }
25
92
  //#endregion
26
93
  exports.buildFormulaBlock = buildFormulaBlock;
94
+ exports.collectDocumentFormulas = collectDocumentFormulas;
27
95
  exports.formulaDocument = formulaDocument;
28
96
  exports.formulaOfBlock = formulaOfBlock;
29
97
  exports.formulaPlaceholderText = formulaPlaceholderText;
@@ -1,8 +1,15 @@
1
- import { Box, ContentDocument, ContentEmbeddedObjectBlock, ContentFormula, LayoutMetadata } from "document-schema.js";
1
+ import { Box, ContentDocument, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentFormula, LayoutMetadata, SymbolTable } from "document-schema.js";
2
2
  //#region src/model/formula.d.ts
3
3
  declare function formulaDocument(formula: ContentFormula, metadata?: LayoutMetadata): ContentDocument;
4
4
  declare function buildFormulaBlock(formula: ContentFormula, frame: Box, sourcePath: string): ContentEmbeddedObjectBlock;
5
- declare function formulaOfBlock(block: ContentEmbeddedObjectBlock): ContentFormula | undefined;
5
+ declare function formulaOfBlock(object: ContentEmbeddedObject): ContentFormula | undefined;
6
+ interface DocumentFormulaEntry {
7
+ readonly formula: ContentFormula;
8
+ readonly sourcePath: string | undefined;
9
+ readonly locate: string;
10
+ readonly symbolTable: SymbolTable | undefined;
11
+ }
12
+ declare function collectDocumentFormulas(document: ContentDocument, enclosingSymbolTable?: SymbolTable): DocumentFormulaEntry[];
6
13
  declare function formulaPlaceholderText(formula: ContentFormula): string;
7
14
  //#endregion
8
- export { buildFormulaBlock, formulaDocument, formulaOfBlock, formulaPlaceholderText };
15
+ export { DocumentFormulaEntry, buildFormulaBlock, collectDocumentFormulas, formulaDocument, formulaOfBlock, formulaPlaceholderText };
@@ -1,8 +1,15 @@
1
- import { Box, ContentDocument, ContentEmbeddedObjectBlock, ContentFormula, LayoutMetadata } from "document-schema.js";
1
+ import { Box, ContentDocument, ContentEmbeddedObject, ContentEmbeddedObjectBlock, ContentFormula, LayoutMetadata, SymbolTable } from "document-schema.js";
2
2
  //#region src/model/formula.d.ts
3
3
  declare function formulaDocument(formula: ContentFormula, metadata?: LayoutMetadata): ContentDocument;
4
4
  declare function buildFormulaBlock(formula: ContentFormula, frame: Box, sourcePath: string): ContentEmbeddedObjectBlock;
5
- declare function formulaOfBlock(block: ContentEmbeddedObjectBlock): ContentFormula | undefined;
5
+ declare function formulaOfBlock(object: ContentEmbeddedObject): ContentFormula | undefined;
6
+ interface DocumentFormulaEntry {
7
+ readonly formula: ContentFormula;
8
+ readonly sourcePath: string | undefined;
9
+ readonly locate: string;
10
+ readonly symbolTable: SymbolTable | undefined;
11
+ }
12
+ declare function collectDocumentFormulas(document: ContentDocument, enclosingSymbolTable?: SymbolTable): DocumentFormulaEntry[];
6
13
  declare function formulaPlaceholderText(formula: ContentFormula): string;
7
14
  //#endregion
8
- export { buildFormulaBlock, formulaDocument, formulaOfBlock, formulaPlaceholderText };
15
+ export { DocumentFormulaEntry, buildFormulaBlock, collectDocumentFormulas, formulaDocument, formulaOfBlock, formulaPlaceholderText };
@@ -15,11 +15,78 @@ function buildFormulaBlock(formula, frame, sourcePath) {
15
15
  sourcePath
16
16
  };
17
17
  }
18
- function formulaOfBlock(block) {
19
- return block.document.kind === "formula" ? block.document.formula : void 0;
18
+ function formulaOfBlock(object) {
19
+ return object.document.kind === "formula" ? object.document.formula : void 0;
20
+ }
21
+ function collectFormulasFromBlocks(blocks, locate, symbolTable, out) {
22
+ for (const [index, block] of blocks.entries()) {
23
+ if (block.kind === "table") {
24
+ for (const [rowIndex, row] of block.rows.entries()) for (const [cellIndex, cell] of row.cells.entries()) collectFormulasFromBlocks(cell.blocks, `${locate}/blocks[${String(index)}].rows[${String(rowIndex)}].cells[${String(cellIndex)}]`, symbolTable, out);
25
+ continue;
26
+ }
27
+ if (block.kind === "embeddedObject") {
28
+ const formula = formulaOfBlock(block);
29
+ const blockLocate = `${locate}/blocks[${String(index)}]`;
30
+ if (formula !== void 0) out.push({
31
+ formula,
32
+ sourcePath: block.sourcePath,
33
+ locate: blockLocate,
34
+ symbolTable: block.document.symbolTable ?? symbolTable
35
+ });
36
+ else for (const nested of collectDocumentFormulas(block.document, symbolTable)) out.push({
37
+ formula: nested.formula,
38
+ sourcePath: nested.sourcePath,
39
+ locate: `${blockLocate}/${nested.locate}`,
40
+ symbolTable: nested.symbolTable
41
+ });
42
+ }
43
+ }
44
+ }
45
+ function collectDocumentFormulas(document, enclosingSymbolTable) {
46
+ const symbolTable = document.symbolTable ?? enclosingSymbolTable;
47
+ const out = [];
48
+ switch (document.kind) {
49
+ case "wordprocessing":
50
+ for (const [index, section] of document.sections.entries()) collectFormulasFromBlocks(section.blocks, `sections[${String(index)}]`, symbolTable, out);
51
+ break;
52
+ case "presentation":
53
+ for (const [slideIndex, slide] of document.slides.entries()) for (const [shapeIndex, shape] of slide.shapes.entries()) collectFormulasFromBlocks(shape.blocks, `slides[${String(slideIndex)}].shapes[${String(shapeIndex)}]`, symbolTable, out);
54
+ break;
55
+ case "drawing":
56
+ for (const [pageIndex, page] of document.pages.entries()) for (const [shapeIndex, shape] of page.shapes.entries()) collectFormulasFromBlocks(shape.blocks, `pages[${String(pageIndex)}].shapes[${String(shapeIndex)}]`, symbolTable, out);
57
+ break;
58
+ case "spreadsheet":
59
+ for (const [sheetIndex, sheet] of document.sheets.entries()) for (const [objectIndex, object] of (sheet.embeddedObjects ?? []).entries()) {
60
+ const formula = formulaOfBlock(object);
61
+ const objectLocate = `sheets[${String(sheetIndex)}].embeddedObjects[${String(objectIndex)}]`;
62
+ if (formula !== void 0) out.push({
63
+ formula,
64
+ sourcePath: void 0,
65
+ locate: objectLocate,
66
+ symbolTable: object.document.symbolTable ?? symbolTable
67
+ });
68
+ else for (const nested of collectDocumentFormulas(object.document, symbolTable)) out.push({
69
+ formula: nested.formula,
70
+ sourcePath: nested.sourcePath,
71
+ locate: `${objectLocate}/${nested.locate}`,
72
+ symbolTable: nested.symbolTable
73
+ });
74
+ }
75
+ break;
76
+ case "formula":
77
+ out.push({
78
+ formula: document.formula,
79
+ sourcePath: void 0,
80
+ locate: "formula",
81
+ symbolTable
82
+ });
83
+ break;
84
+ default: throw new Error(`collectDocumentFormulas: unhandled ContentDocument kind ${JSON.stringify(document.kind)}`);
85
+ }
86
+ return out;
20
87
  }
21
88
  function formulaPlaceholderText(formula) {
22
89
  return formula.starMath ?? formula.presentation?.latex ?? "[formula]";
23
90
  }
24
91
  //#endregion
25
- export { buildFormulaBlock, formulaDocument, formulaOfBlock, formulaPlaceholderText };
92
+ export { buildFormulaBlock, collectDocumentFormulas, formulaDocument, formulaOfBlock, formulaPlaceholderText };
@@ -34,6 +34,8 @@ declare class OdtTableRow {
34
34
  private readonly pkg;
35
35
  constructor(node: XmlElement, pkg: Package);
36
36
  cells(): OdtTableCell[];
37
+ get heightPt(): number | undefined;
38
+ set heightPt(value: number | undefined);
37
39
  appendCell(): OdtTableCell;
38
40
  appendCoveredCell(): void;
39
41
  private gridCells;
@@ -34,6 +34,8 @@ declare class OdtTableRow {
34
34
  private readonly pkg;
35
35
  constructor(node: XmlElement, pkg: Package);
36
36
  cells(): OdtTableCell[];
37
+ get heightPt(): number | undefined;
38
+ set heightPt(value: number | undefined);
37
39
  appendCell(): OdtTableCell;
38
40
  appendCoveredCell(): void;
39
41
  private gridCells;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "6.5.3",
3
+ "version": "7.0.1",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -77,21 +77,21 @@
77
77
  ],
78
78
  "license": "MIT",
79
79
  "dependencies": {
80
- "archive-codec": "^1.4.2",
81
- "byte-codec": "^1.2.1",
82
- "doc-codec": "^1.1.2",
83
- "document-schema.js": "^5.6.0",
80
+ "archive-codec": "^1.4.3",
81
+ "byte-codec": "^1.2.2",
82
+ "doc-codec": "^2.0.0",
83
+ "document-schema.js": "^6.0.0",
84
84
  "fflate": "^0.8.3",
85
- "markdown-codec": "^6.1.6",
86
- "odf.js": "^6.4.1",
87
- "ooxml.js": "^6.3.7",
88
- "pdf-codec": "^3.6.5",
89
- "ppt-codec": "^1.1.2",
90
- "rtf-codec": "^1.1.2",
85
+ "markdown-codec": "^6.1.7",
86
+ "odf.js": "^7.0.0",
87
+ "ooxml.js": "^7.0.0",
88
+ "pdf-codec": "^3.6.6",
89
+ "ppt-codec": "^1.1.3",
90
+ "rtf-codec": "^2.0.0",
91
91
  "temml": "0.13.4",
92
- "xls-codec": "^2.0.2",
92
+ "xls-codec": "^3.0.0",
93
93
  "zod": "^4.4.3",
94
- "wpd-codec": "^1.1.3"
94
+ "wpd-codec": "^2.0.0"
95
95
  },
96
96
  "devDependencies": {
97
97
  "@arethetypeswrong/cli": "^0.18.5",