js.documents 14.4.124 → 14.5.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.
- package/README.md +21 -3
- package/dist/{composition-plan-l6QPO4FX.d.ts → composition-plan-B1Nn2JCQ.d.ts} +10 -1
- package/dist/{composition-plan-CfvhXeOC.cjs → composition-plan-BgsXTscN.cjs} +19 -7
- package/dist/{composition-plan-DU9nPPN7.d.cts → composition-plan-Cofo9qPI.d.cts} +10 -1
- package/dist/{composition-plan-f0zaExUW.js → composition-plan-mRolIOZY.js} +19 -7
- package/dist/convert/composition-plan.cjs +1 -1
- package/dist/convert/composition-plan.d.cts +1 -1
- package/dist/convert/composition-plan.d.ts +1 -1
- package/dist/convert/composition-plan.js +1 -1
- package/dist/convert/composition-to-pdf.cjs +1 -1
- package/dist/convert/composition-to-pdf.d.cts +1 -1
- package/dist/convert/composition-to-pdf.d.ts +1 -1
- package/dist/convert/composition-to-pdf.js +1 -1
- package/dist/convert/composition.cjs +1 -1
- package/dist/convert/composition.d.cts +1 -1
- package/dist/convert/composition.d.ts +1 -1
- package/dist/convert/composition.js +1 -1
- package/dist/convert/from-package.cjs +1 -1
- package/dist/convert/from-package.js +1 -1
- package/dist/convert/from-pdf.cjs +10 -6
- package/dist/convert/from-pdf.d.cts +10 -0
- package/dist/convert/from-pdf.d.ts +10 -0
- package/dist/convert/from-pdf.js +11 -7
- package/dist/convert/local.cjs +1 -1
- package/dist/convert/local.js +1 -1
- package/dist/convert/pdf-package-tables.cjs +3 -1
- package/dist/convert/pdf-package-tables.js +3 -1
- package/dist/edit/pdf/editor.cjs +4 -1
- package/dist/edit/pdf/editor.d.cts +1 -1
- package/dist/edit/pdf/editor.d.ts +1 -1
- package/dist/edit/pdf/editor.js +4 -1
- package/dist/index.cjs +22 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/layout/reconstruct-presentations-prod.cjs +1 -1
- package/dist/layout/reconstruct-presentations-prod.js +1 -1
- package/dist/layout/reconstruct-tables.cjs +1 -1
- package/dist/layout/reconstruct-tables.js +1 -1
- package/dist/layout/reconstruct.cjs +1 -1
- package/dist/layout/reconstruct.js +1 -1
- package/dist/markdown/render.d.cts +2 -2
- package/dist/markdown/render.d.ts +2 -2
- package/dist/markdown/write.cjs +54 -1
- package/dist/markdown/write.d.cts +23 -2
- package/dist/markdown/write.d.ts +23 -2
- package/dist/markdown/write.js +53 -2
- package/dist/{reconstruct-presentations-prod-X315aBmI.cjs → reconstruct-presentations-prod-CA4no_aw.cjs} +13 -12
- package/dist/{reconstruct-presentations-prod-B5fkPiRZ.js → reconstruct-presentations-prod-CC8ct-5O.js} +13 -12
- package/package.json +2 -2
package/dist/markdown/write.js
CHANGED
|
@@ -5,6 +5,56 @@ const MATH_BLOCK_STYLE_ID = "MathBlock";
|
|
|
5
5
|
const MATH_INLINE_FONT_MARKER = "Cambria Math";
|
|
6
6
|
const MATH_INLINE_SOURCE = "markdown:math-inline";
|
|
7
7
|
const PAGE_BREAK_MARKER = "<!-- page break -->";
|
|
8
|
+
/**
|
|
9
|
+
* The marker opening a page that `BuildMarkdownTextOptions.pageNumbers` labels: an HTML comment naming the page's number, `<!-- page 7 -->` for page 7, on a line of its own. An output-only annotation for readers of the text rather than a directive: unlike {@link PAGE_BREAK_MARKER} it states which page follows, not that a page ends, and nothing reads it back as one. Reading markdown that carries it keeps it as an ordinary HTML-comment paragraph, exactly as any other comment in a markdown source is kept, so a hand-written comment of the same shape is never mistaken for a label and lost.
|
|
10
|
+
* @param pageNumber - the number the page is labelled with, as the caller supplied it
|
|
11
|
+
* @returns the marker text
|
|
12
|
+
*/
|
|
13
|
+
function pageNumberMarker(pageNumber) {
|
|
14
|
+
return `<!-- page ${String(pageNumber)} -->`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `BuildMarkdownTextOptions.pageNumbers` did not supply exactly one number per page of the document. Thrown rather than labelling a prefix or padding, since a label on the wrong page is worse than none.
|
|
18
|
+
*/
|
|
19
|
+
var MarkdownPageNumberCountError = class extends Error {
|
|
20
|
+
pageCount;
|
|
21
|
+
pageNumberCount;
|
|
22
|
+
constructor(pageCount, pageNumberCount) {
|
|
23
|
+
super(`pageNumbers supplies ${String(pageNumberCount)} page numbers for a document of ${String(pageCount)} pages; it must supply exactly one per page`);
|
|
24
|
+
this.name = "MarkdownPageNumberCountError";
|
|
25
|
+
this.pageCount = pageCount;
|
|
26
|
+
this.pageNumberCount = pageNumberCount;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function pageNumberParagraph(pageNumber) {
|
|
30
|
+
return {
|
|
31
|
+
kind: "paragraph",
|
|
32
|
+
runs: [{ text: pageNumberMarker(pageNumber) }],
|
|
33
|
+
styleId: HTML_PREFORMATTED_STYLE_ID
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function labelPages(sections, pageNumbers) {
|
|
37
|
+
let pageCount = 0;
|
|
38
|
+
const label = () => {
|
|
39
|
+
const pageNumber = pageNumbers[pageCount];
|
|
40
|
+
pageCount++;
|
|
41
|
+
return pageNumber === void 0 ? [] : [pageNumberParagraph(pageNumber)];
|
|
42
|
+
};
|
|
43
|
+
const labelled = sections.map((section, sectionIndex) => {
|
|
44
|
+
const blocks = [];
|
|
45
|
+
if (sectionIndex === 0 || section.breakType !== "continuous") blocks.push(...label());
|
|
46
|
+
for (const block of section.blocks) {
|
|
47
|
+
blocks.push(block);
|
|
48
|
+
if (block.kind === "pageBreak") blocks.push(...label());
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...section,
|
|
52
|
+
blocks
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
if (pageCount !== pageNumbers.length) throw new MarkdownPageNumberCountError(pageCount, pageNumbers.length);
|
|
56
|
+
return labelled;
|
|
57
|
+
}
|
|
8
58
|
function formulaParagraph(formula) {
|
|
9
59
|
const latex = formula.presentation?.latex;
|
|
10
60
|
if (latex === void 0) return {
|
|
@@ -52,7 +102,8 @@ function markdownTableCell(cell) {
|
|
|
52
102
|
}
|
|
53
103
|
function buildMarkdownText(document, options) {
|
|
54
104
|
if (document.kind !== "wordprocessing") throw new MarkdownUnsupportedDocumentKindError(document.kind);
|
|
55
|
-
const
|
|
105
|
+
const pageNumbers = options?.pageNumbers;
|
|
106
|
+
const sections = (pageNumbers === void 0 ? document.sections : labelPages(document.sections, pageNumbers)).map((section) => ({
|
|
56
107
|
...section,
|
|
57
108
|
blocks: section.blocks.map(markdownBlock)
|
|
58
109
|
}));
|
|
@@ -62,4 +113,4 @@ function buildMarkdownText(document, options) {
|
|
|
62
113
|
}, options);
|
|
63
114
|
}
|
|
64
115
|
//#endregion
|
|
65
|
-
export { PAGE_BREAK_MARKER, buildMarkdownText };
|
|
116
|
+
export { MarkdownPageNumberCountError, PAGE_BREAK_MARKER, buildMarkdownText, pageNumberMarker };
|
|
@@ -6,6 +6,7 @@ const require_ports_abort = require("./ports/abort.cjs");
|
|
|
6
6
|
const require_layout_reconstruct_lines = require("./layout/reconstruct-lines.cjs");
|
|
7
7
|
const require_layout_lattice = require("./layout/lattice.cjs");
|
|
8
8
|
let document_schema_js = require("document-schema.js");
|
|
9
|
+
let pdf_codec_layout = require("pdf-codec/layout");
|
|
9
10
|
//#region src/layout/reconstruct-tables.ts
|
|
10
11
|
function recoverTables(page, pageIndex, structure) {
|
|
11
12
|
if (structure !== void 0) {
|
|
@@ -381,17 +382,17 @@ function reconstructWordprocessing(doc, options) {
|
|
|
381
382
|
const structure = indexStructure(doc);
|
|
382
383
|
const sections = [];
|
|
383
384
|
let currentGroup = [];
|
|
384
|
-
let
|
|
385
|
+
let groupStartPosition = 0;
|
|
385
386
|
for (const page of doc.pages) {
|
|
386
387
|
require_ports_abort.throwIfAborted(signal);
|
|
387
388
|
if (currentGroup.length > 0 && !samePageSize(currentGroup[0], page)) {
|
|
388
|
-
sections.push(buildSection(currentGroup,
|
|
389
|
-
|
|
389
|
+
sections.push(buildSection(currentGroup, groupStartPosition, doc.images, headingLevels, doc.form, structure));
|
|
390
|
+
groupStartPosition += currentGroup.length;
|
|
390
391
|
currentGroup = [];
|
|
391
392
|
}
|
|
392
393
|
currentGroup.push(page);
|
|
393
394
|
}
|
|
394
|
-
if (currentGroup.length > 0) sections.push(buildSection(currentGroup,
|
|
395
|
+
if (currentGroup.length > 0) sections.push(buildSection(currentGroup, groupStartPosition, doc.images, headingLevels, doc.form, structure));
|
|
395
396
|
return {
|
|
396
397
|
kind: "wordprocessing",
|
|
397
398
|
metadata: doc.metadata,
|
|
@@ -492,12 +493,12 @@ function headingLevelOf(paragraph, levels) {
|
|
|
492
493
|
function samePageSize(a, b) {
|
|
493
494
|
return a.widthPt === b.widthPt && a.heightPt === b.heightPt;
|
|
494
495
|
}
|
|
495
|
-
function buildSection(pages,
|
|
496
|
+
function buildSection(pages, startPosition, images, headingLevels, form, structure) {
|
|
496
497
|
const blocks = [];
|
|
497
498
|
const divisionByBlock = /* @__PURE__ */ new WeakMap();
|
|
498
499
|
pages.forEach((page, i) => {
|
|
499
500
|
if (i > 0) blocks.push({ kind: "pageBreak" });
|
|
500
|
-
blocks.push(...reconstructPageBlocks(page,
|
|
501
|
+
blocks.push(...reconstructPageBlocks(page, (0, pdf_codec_layout.sourcePageIndex)(page, startPosition + i), images, headingLevels, form, structure, divisionByBlock));
|
|
501
502
|
});
|
|
502
503
|
return {
|
|
503
504
|
pageSize: {
|
|
@@ -736,9 +737,9 @@ function appendFormFieldConstructs(blocks, form, pageIndex) {
|
|
|
736
737
|
}
|
|
737
738
|
function reconstructSpreadsheet(doc, options) {
|
|
738
739
|
const signal = options?.signal;
|
|
739
|
-
const sheets = doc.pages.map((page,
|
|
740
|
+
const sheets = doc.pages.map((page, position) => {
|
|
740
741
|
require_ports_abort.throwIfAborted(signal);
|
|
741
|
-
return reconstructSheet(page,
|
|
742
|
+
return reconstructSheet(page, (0, pdf_codec_layout.sourcePageIndex)(page, position), options?.onCellTypeInference);
|
|
742
743
|
});
|
|
743
744
|
return {
|
|
744
745
|
kind: "spreadsheet",
|
|
@@ -751,9 +752,9 @@ function reconstructSpreadsheet(doc, options) {
|
|
|
751
752
|
function reconstructPresentation(doc, options) {
|
|
752
753
|
const signal = options?.signal;
|
|
753
754
|
const structure = indexStructure(doc);
|
|
754
|
-
const slides = doc.pages.map((page,
|
|
755
|
+
const slides = doc.pages.map((page, position) => {
|
|
755
756
|
require_ports_abort.throwIfAborted(signal);
|
|
756
|
-
return reconstructSlide(page,
|
|
757
|
+
return reconstructSlide(page, (0, pdf_codec_layout.sourcePageIndex)(page, position), doc.images, structure);
|
|
757
758
|
});
|
|
758
759
|
return {
|
|
759
760
|
kind: "presentation",
|
|
@@ -933,9 +934,9 @@ function imageToShape(img, slideHeightPt, pageIndex, images) {
|
|
|
933
934
|
}
|
|
934
935
|
function reconstructDrawing(doc, options) {
|
|
935
936
|
const signal = options?.signal;
|
|
936
|
-
const pages = doc.pages.map((page,
|
|
937
|
+
const pages = doc.pages.map((page, position) => {
|
|
937
938
|
require_ports_abort.throwIfAborted(signal);
|
|
938
|
-
return reconstructDrawPage(page,
|
|
939
|
+
return reconstructDrawPage(page, (0, pdf_codec_layout.sourcePageIndex)(page, position), doc.images);
|
|
939
940
|
});
|
|
940
941
|
return {
|
|
941
942
|
kind: "drawing",
|
|
@@ -6,6 +6,7 @@ import { throwIfAborted } from "./ports/abort.js";
|
|
|
6
6
|
import { HALF_POINT_BUCKET_PT, bucketCounts, clusterIntoLines, clusterIntoParagraphs, estimateModalLineSpacing, fontSizesClose, gapExceeds, lineBox, modeOf, paragraphToContentParagraph, pushRunsForLine, textBoxOfItem, textItemToContentRun, textItemVerticalExtent } from "./layout/reconstruct-lines.js";
|
|
7
7
|
import { detectGridLattice, findColumnIndex, findRowIndex } from "./layout/lattice.js";
|
|
8
8
|
import { denseTableRows } from "document-schema.js";
|
|
9
|
+
import { sourcePageIndex } from "pdf-codec/layout";
|
|
9
10
|
//#region src/layout/reconstruct-tables.ts
|
|
10
11
|
function recoverTables(page, pageIndex, structure) {
|
|
11
12
|
if (structure !== void 0) {
|
|
@@ -381,17 +382,17 @@ function reconstructWordprocessing(doc, options) {
|
|
|
381
382
|
const structure = indexStructure(doc);
|
|
382
383
|
const sections = [];
|
|
383
384
|
let currentGroup = [];
|
|
384
|
-
let
|
|
385
|
+
let groupStartPosition = 0;
|
|
385
386
|
for (const page of doc.pages) {
|
|
386
387
|
throwIfAborted(signal);
|
|
387
388
|
if (currentGroup.length > 0 && !samePageSize(currentGroup[0], page)) {
|
|
388
|
-
sections.push(buildSection(currentGroup,
|
|
389
|
-
|
|
389
|
+
sections.push(buildSection(currentGroup, groupStartPosition, doc.images, headingLevels, doc.form, structure));
|
|
390
|
+
groupStartPosition += currentGroup.length;
|
|
390
391
|
currentGroup = [];
|
|
391
392
|
}
|
|
392
393
|
currentGroup.push(page);
|
|
393
394
|
}
|
|
394
|
-
if (currentGroup.length > 0) sections.push(buildSection(currentGroup,
|
|
395
|
+
if (currentGroup.length > 0) sections.push(buildSection(currentGroup, groupStartPosition, doc.images, headingLevels, doc.form, structure));
|
|
395
396
|
return {
|
|
396
397
|
kind: "wordprocessing",
|
|
397
398
|
metadata: doc.metadata,
|
|
@@ -492,12 +493,12 @@ function headingLevelOf(paragraph, levels) {
|
|
|
492
493
|
function samePageSize(a, b) {
|
|
493
494
|
return a.widthPt === b.widthPt && a.heightPt === b.heightPt;
|
|
494
495
|
}
|
|
495
|
-
function buildSection(pages,
|
|
496
|
+
function buildSection(pages, startPosition, images, headingLevels, form, structure) {
|
|
496
497
|
const blocks = [];
|
|
497
498
|
const divisionByBlock = /* @__PURE__ */ new WeakMap();
|
|
498
499
|
pages.forEach((page, i) => {
|
|
499
500
|
if (i > 0) blocks.push({ kind: "pageBreak" });
|
|
500
|
-
blocks.push(...reconstructPageBlocks(page,
|
|
501
|
+
blocks.push(...reconstructPageBlocks(page, sourcePageIndex(page, startPosition + i), images, headingLevels, form, structure, divisionByBlock));
|
|
501
502
|
});
|
|
502
503
|
return {
|
|
503
504
|
pageSize: {
|
|
@@ -736,9 +737,9 @@ function appendFormFieldConstructs(blocks, form, pageIndex) {
|
|
|
736
737
|
}
|
|
737
738
|
function reconstructSpreadsheet(doc, options) {
|
|
738
739
|
const signal = options?.signal;
|
|
739
|
-
const sheets = doc.pages.map((page,
|
|
740
|
+
const sheets = doc.pages.map((page, position) => {
|
|
740
741
|
throwIfAborted(signal);
|
|
741
|
-
return reconstructSheet(page,
|
|
742
|
+
return reconstructSheet(page, sourcePageIndex(page, position), options?.onCellTypeInference);
|
|
742
743
|
});
|
|
743
744
|
return {
|
|
744
745
|
kind: "spreadsheet",
|
|
@@ -751,9 +752,9 @@ function reconstructSpreadsheet(doc, options) {
|
|
|
751
752
|
function reconstructPresentation(doc, options) {
|
|
752
753
|
const signal = options?.signal;
|
|
753
754
|
const structure = indexStructure(doc);
|
|
754
|
-
const slides = doc.pages.map((page,
|
|
755
|
+
const slides = doc.pages.map((page, position) => {
|
|
755
756
|
throwIfAborted(signal);
|
|
756
|
-
return reconstructSlide(page,
|
|
757
|
+
return reconstructSlide(page, sourcePageIndex(page, position), doc.images, structure);
|
|
757
758
|
});
|
|
758
759
|
return {
|
|
759
760
|
kind: "presentation",
|
|
@@ -933,9 +934,9 @@ function imageToShape(img, slideHeightPt, pageIndex, images) {
|
|
|
933
934
|
}
|
|
934
935
|
function reconstructDrawing(doc, options) {
|
|
935
936
|
const signal = options?.signal;
|
|
936
|
-
const pages = doc.pages.map((page,
|
|
937
|
+
const pages = doc.pages.map((page, position) => {
|
|
937
938
|
throwIfAborted(signal);
|
|
938
|
-
return reconstructDrawPage(page,
|
|
939
|
+
return reconstructDrawPage(page, sourcePageIndex(page, position), doc.images);
|
|
939
940
|
});
|
|
940
941
|
return {
|
|
941
942
|
kind: "drawing",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js.documents",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.5.0",
|
|
4
4
|
"description": "Converts between docx, pptx, odt, odp, ods, odg, xlsx, csv, svg, markdown, rtf, doc, xls, ppt and PDF through one shared, Zod-typed content schema (wpd read-only), plus read+write editors for OOXML and OpenDocument. Worker-isomorphic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"markdown-codec": "11.1.16",
|
|
87
87
|
"odf.js": "11.2.2",
|
|
88
88
|
"ooxml.js": "12.2.32",
|
|
89
|
-
"pdf-codec": "5.
|
|
89
|
+
"pdf-codec": "5.4.0",
|
|
90
90
|
"ppt-codec": "2.2.23",
|
|
91
91
|
"rtf-codec": "8.1.24",
|
|
92
92
|
"temml": "0.13.4",
|