doc-codec 2.8.6 → 2.9.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 +28 -23
- package/dist/fib/write.cjs +8 -0
- package/dist/fib/write.d.cts +16 -0
- package/dist/fib/write.d.ts +16 -0
- package/dist/fib/write.js +8 -0
- package/dist/headers-footers.cjs +5 -3
- package/dist/headers-footers.d.cts +5 -1
- package/dist/headers-footers.d.ts +5 -1
- package/dist/headers-footers.js +4 -4
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/read.cjs +18 -1
- package/dist/read.js +18 -1
- package/dist/subdocument-write.cjs +108 -0
- package/dist/subdocument-write.d.cts +42 -0
- package/dist/subdocument-write.d.ts +42 -0
- package/dist/subdocument-write.js +104 -0
- package/dist/subdocument.cjs +8 -1
- package/dist/subdocument.js +8 -1
- package/dist/table/write.cjs +20 -1
- package/dist/table/write.js +20 -1
- package/dist/write.cjs +35 -5
- package/dist/write.d.cts +11 -2
- package/dist/write.d.ts +11 -2
- package/dist/write.js +35 -5
- package/package.json +3 -3
package/dist/write.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
import { HeaderFooterStory } from "./headers-footers.js";
|
|
1
2
|
import { r as WriteWarning } from "./write-t4rFgnA-.js";
|
|
3
|
+
import { Comment, Footnote } from "./notes.js";
|
|
2
4
|
import { ContentDocument } from "document-schema.js";
|
|
3
5
|
//#region src/write.d.ts
|
|
4
6
|
interface WriteDocContentOptions {
|
|
5
7
|
/** Reports a non-fatal write-time degradation -- today, only table/write.ts's own per-row lost-boundary-budget fallback (ExaDev/documents.js#1013), the same `onWarning` shape byte-codec's PNG decoder and pdf-codec already use for a recoverable, non-fatal defect. Not a guarantee the write itself goes on to succeed: when a row's own assigned lost boundaries can't be trimmed down to a split that fits at all, this still fires once -- reporting that the row's boundaries could not be stated and that its fully-unsplit encoding is being attempted instead -- before writeDocContent can discover, further down the same pipeline, that even that unsplit encoding overflows the row's own byte budget and throws its usual DocFormatError; the warning describes what this fallback could not recover, not a promise that a hard failure won't immediately follow it. It is never called in place of a genuine refusal this writer makes outright (an unsupported block kind, more than one section, and so on) -- those always throw DocFormatError/DocUnsupportedError directly, with no warning first. */
|
|
6
8
|
readonly onWarning?: WriteWarning;
|
|
7
9
|
}
|
|
8
|
-
|
|
10
|
+
/** writeDocContent's own input: a `ContentDocument` widened by the same story fields `readDocContent`'s own `DocContent` output carries (read.ts) -- footnotes, endnotes, comments, and header/footer stories -- each OPTIONAL, exactly the shape ooxml.js's own `DocxContent` input already established for the identical constructs, so a plain `ContentDocument` (none of the four stated) still writes exactly as it always did, while a genuine `DocContent` assigns straight across. A type-alias intersection rather than an interface for the identical reason DocContent is one: ContentDocument is a union of document kinds, and only the intersection spreads its members statically. The stories are written back as genuine subdocuments (subdocument-write.ts); a document that states none writes no subdocument at all, with every story ccp and fc/lcb pair left zero. */
|
|
11
|
+
type WritableDocContent = ContentDocument & {
|
|
12
|
+
readonly footnotes?: readonly Footnote[];
|
|
13
|
+
readonly endnotes?: readonly Footnote[];
|
|
14
|
+
readonly comments?: readonly Comment[];
|
|
15
|
+
readonly headerFooterStories?: readonly HeaderFooterStory[];
|
|
16
|
+
};
|
|
17
|
+
declare function writeDocContent(document: WritableDocContent, options?: WriteDocContentOptions): Uint8Array<ArrayBuffer>;
|
|
9
18
|
//#endregion
|
|
10
|
-
export { WriteDocContentOptions, writeDocContent };
|
|
19
|
+
export { WritableDocContent, WriteDocContentOptions, writeDocContent };
|
package/dist/write.js
CHANGED
|
@@ -12,8 +12,9 @@ import { encodeCharacterGrpprl } from "./prop/chp-write.js";
|
|
|
12
12
|
import { encodeParagraphGrpprl } from "./prop/pap-write.js";
|
|
13
13
|
import { buildPlcfSed, buildSepx, encodeSectionGrpprl } from "./prop/sep-write.js";
|
|
14
14
|
import { buildFontTable } from "./style/fonts.js";
|
|
15
|
-
import { buildNumberingTables, gatherListUsage } from "./list/numbering-write.js";
|
|
16
15
|
import { flattenSectionBlocks } from "./table/write.js";
|
|
16
|
+
import { buildStorySubdocuments, paragraphCharacters } from "./subdocument-write.js";
|
|
17
|
+
import { buildNumberingTables, gatherListUsage } from "./list/numbering-write.js";
|
|
17
18
|
import { hasSummaryInformationFields, writeCompoundFile, writeSummaryInformationStream } from "archive-codec";
|
|
18
19
|
//#region src/write.ts
|
|
19
20
|
/** Where the text is written in the WordDocument stream: past the FIB (which needs under 900 bytes for the fields this writer populates), on a page boundary though not required to be. */
|
|
@@ -37,7 +38,16 @@ function writeDocContent(document, options = {}) {
|
|
|
37
38
|
runningIndex += paragraphs.length;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
+
const mainParagraphs = sectionParagraphLists.flat();
|
|
42
|
+
const stories = buildStorySubdocuments(document, dataStream, options.onWarning);
|
|
43
|
+
const ccpText = mainParagraphs.reduce((count, paragraph) => count + paragraphCharacters(paragraph), 0);
|
|
44
|
+
const writeParagraphs = [
|
|
45
|
+
...mainParagraphs,
|
|
46
|
+
...stories.footnote?.paragraphs ?? [],
|
|
47
|
+
...stories.header?.paragraphs ?? [],
|
|
48
|
+
...stories.comment?.paragraphs ?? [],
|
|
49
|
+
...stories.endnote?.paragraphs ?? []
|
|
50
|
+
];
|
|
41
51
|
const FIRST_NON_HEADING_ISTD = 10;
|
|
42
52
|
const MAX_HEADING_ISTD = 9;
|
|
43
53
|
const styleNames = /* @__PURE__ */ new Map();
|
|
@@ -175,7 +185,7 @@ function writeDocContent(document, options = {}) {
|
|
|
175
185
|
const papxBinTable = buildPropertyBinTable([...papxPages.map(firstFcOfPage), textFcLim], papxPages.map((_, index) => papxPageStart + index));
|
|
176
186
|
const stsh = buildStshForStyles(styleNames);
|
|
177
187
|
const fontTable = fontNames.length > 0 ? buildFontTable(fontNames) : void 0;
|
|
178
|
-
const plcfSed = buildPlcfSed(sectionStartCps,
|
|
188
|
+
const plcfSed = buildPlcfSed(sectionStartCps, ccpText, fcSepxList);
|
|
179
189
|
let cursor = 0;
|
|
180
190
|
const place = (bytes) => {
|
|
181
191
|
const offset = cursor;
|
|
@@ -190,6 +200,10 @@ function writeDocContent(document, options = {}) {
|
|
|
190
200
|
const fcSttbfFfn = fontTable !== void 0 ? place(fontTable) : 0;
|
|
191
201
|
const fcPlfLst = numberingTables !== void 0 ? place(numberingTables.plfLst) : 0;
|
|
192
202
|
const fcPlfLfo = numberingTables !== void 0 ? place(numberingTables.plfLfo) : 0;
|
|
203
|
+
const fcPlcffndTxt = stories.footnote !== void 0 ? place(stories.footnote.plex) : 0;
|
|
204
|
+
const fcPlcfHdd = stories.header !== void 0 ? place(stories.header.plex) : 0;
|
|
205
|
+
const fcPlcfandTxt = stories.comment !== void 0 ? place(stories.comment.plex) : 0;
|
|
206
|
+
const fcPlcfendTxt = stories.endnote !== void 0 ? place(stories.endnote.plex) : 0;
|
|
193
207
|
const table = new Uint8Array(cursor);
|
|
194
208
|
table.set(clx, fcClx);
|
|
195
209
|
table.set(chpxBinTable, fcPlcfBteChpx);
|
|
@@ -201,8 +215,12 @@ function writeDocContent(document, options = {}) {
|
|
|
201
215
|
table.set(numberingTables.plfLst, fcPlfLst);
|
|
202
216
|
table.set(numberingTables.plfLfo, fcPlfLfo);
|
|
203
217
|
}
|
|
218
|
+
if (stories.footnote !== void 0) table.set(stories.footnote.plex, fcPlcffndTxt);
|
|
219
|
+
if (stories.header !== void 0) table.set(stories.header.plex, fcPlcfHdd);
|
|
220
|
+
if (stories.comment !== void 0) table.set(stories.comment.plex, fcPlcfandTxt);
|
|
221
|
+
if (stories.endnote !== void 0) table.set(stories.endnote.plex, fcPlcfendTxt);
|
|
204
222
|
const fib = buildFib({
|
|
205
|
-
ccpText
|
|
223
|
+
ccpText,
|
|
206
224
|
cbMac: wordDocument.length,
|
|
207
225
|
fcClx,
|
|
208
226
|
lcbClx: clx.length,
|
|
@@ -219,7 +237,19 @@ function writeDocContent(document, options = {}) {
|
|
|
219
237
|
fcPlfLst,
|
|
220
238
|
lcbPlfLst: numberingTables?.lcbPlfLst ?? 0,
|
|
221
239
|
fcPlfLfo,
|
|
222
|
-
lcbPlfLfo: numberingTables?.plfLfo.length ?? 0
|
|
240
|
+
lcbPlfLfo: numberingTables?.plfLfo.length ?? 0,
|
|
241
|
+
ccpFtn: stories.footnote?.ccp ?? 0,
|
|
242
|
+
fcPlcffndTxt,
|
|
243
|
+
lcbPlcffndTxt: stories.footnote?.plex.length ?? 0,
|
|
244
|
+
ccpHdd: stories.header?.ccp ?? 0,
|
|
245
|
+
fcPlcfHdd,
|
|
246
|
+
lcbPlcfHdd: stories.header?.plex.length ?? 0,
|
|
247
|
+
ccpAtn: stories.comment?.ccp ?? 0,
|
|
248
|
+
fcPlcfandTxt,
|
|
249
|
+
lcbPlcfandTxt: stories.comment?.plex.length ?? 0,
|
|
250
|
+
ccpEdn: stories.endnote?.ccp ?? 0,
|
|
251
|
+
fcPlcfendTxt,
|
|
252
|
+
lcbPlcfendTxt: stories.endnote?.plex.length ?? 0
|
|
223
253
|
});
|
|
224
254
|
wordDocument.set(fib, 0);
|
|
225
255
|
const streams = [{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doc-codec",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "A hand-written reader for the Word Binary File Format ([MS-DOC], .doc) against the shared document-schema.js content pivot: FIB parsing, piece-table text reconstruction, and CHPX/PAPX formatting exceptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"license": "MIT",
|
|
81
81
|
"packageManager": "pnpm@11.6.0",
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"archive-codec": "1.
|
|
84
|
-
"document-schema.js": "7.
|
|
83
|
+
"archive-codec": "1.11.0",
|
|
84
|
+
"document-schema.js": "7.11.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@arethetypeswrong/cli": "0.18.5",
|