ppt-codec 1.0.2 → 1.1.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 +142 -38
- package/dist/content-write.cjs +114 -0
- package/dist/content-write.d.cts +11 -0
- package/dist/content-write.d.ts +11 -0
- package/dist/content-write.js +112 -0
- package/dist/content.cjs +22 -2
- package/dist/content.js +22 -2
- package/dist/document/color-scheme-write.cjs +57 -0
- package/dist/document/color-scheme-write.d.cts +4 -0
- package/dist/document/color-scheme-write.d.ts +4 -0
- package/dist/document/color-scheme-write.js +56 -0
- package/dist/document/document-atom-write.cjs +12 -0
- package/dist/document/document-atom-write.d.cts +5 -0
- package/dist/document/document-atom-write.d.ts +5 -0
- package/dist/document/document-atom-write.js +11 -0
- package/dist/document/fonts-write.cjs +17 -0
- package/dist/document/fonts-write.d.cts +4 -0
- package/dist/document/fonts-write.d.ts +4 -0
- package/dist/document/fonts-write.js +16 -0
- package/dist/document/master-write.cjs +128 -0
- package/dist/document/master-write.d.cts +15 -0
- package/dist/document/master-write.d.ts +15 -0
- package/dist/document/master-write.js +123 -0
- package/dist/document/notes-list-write.cjs +12 -0
- package/dist/document/notes-list-write.d.cts +5 -0
- package/dist/document/notes-list-write.d.ts +5 -0
- package/dist/document/notes-list-write.js +11 -0
- package/dist/document/notes-list.cjs +22 -0
- package/dist/document/notes-list.d.cts +9 -0
- package/dist/document/notes-list.d.ts +9 -0
- package/dist/document/notes-list.js +21 -0
- package/dist/document/notes-write.cjs +43 -0
- package/dist/document/notes-write.d.cts +6 -0
- package/dist/document/notes-write.d.ts +6 -0
- package/dist/document/notes-write.js +41 -0
- package/dist/document/notes.cjs +41 -0
- package/dist/document/notes.d.cts +12 -0
- package/dist/document/notes.d.ts +12 -0
- package/dist/document/notes.js +37 -0
- package/dist/document/slide-list-write.cjs +12 -0
- package/dist/document/slide-list-write.d.cts +8 -0
- package/dist/document/slide-list-write.d.ts +8 -0
- package/dist/document/slide-list-write.js +11 -0
- package/dist/drawing/shapes-write.cjs +60 -0
- package/dist/drawing/shapes-write.d.cts +10 -0
- package/dist/drawing/shapes-write.d.ts +10 -0
- package/dist/drawing/shapes-write.js +58 -0
- package/dist/errors.cjs +7 -0
- package/dist/errors.d.cts +4 -1
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +7 -1
- package/dist/index.cjs +112 -3
- package/dist/index.d.cts +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +25 -8
- package/dist/metadata.cjs +14 -0
- package/dist/metadata.d.cts +6 -0
- package/dist/metadata.d.ts +6 -0
- package/dist/metadata.js +13 -0
- package/dist/read.cjs +33 -8
- package/dist/read.d.cts +5 -1
- package/dist/read.d.ts +5 -1
- package/dist/read.js +32 -10
- package/dist/record/types.cjs +8 -0
- package/dist/record/types.d.cts +5 -1
- package/dist/record/types.d.ts +5 -1
- package/dist/record/types.js +5 -1
- package/dist/record/write.cjs +75 -0
- package/dist/record/write.d.cts +17 -0
- package/dist/record/write.d.ts +17 -0
- package/dist/record/write.js +65 -0
- package/dist/stream/current-user-write.cjs +13 -0
- package/dist/stream/current-user-write.d.cts +4 -0
- package/dist/stream/current-user-write.d.ts +4 -0
- package/dist/stream/current-user-write.js +12 -0
- package/dist/stream/current-user.cjs +7 -5
- package/dist/stream/current-user.d.cts +3 -1
- package/dist/stream/current-user.d.ts +3 -1
- package/dist/stream/current-user.js +6 -6
- package/dist/stream/persist-write.cjs +14 -0
- package/dist/stream/persist-write.d.cts +16 -0
- package/dist/stream/persist-write.d.ts +16 -0
- package/dist/stream/persist-write.js +12 -0
- package/dist/text/style-write.cjs +79 -0
- package/dist/text/style-write.d.cts +5 -0
- package/dist/text/style-write.d.ts +5 -0
- package/dist/text/style-write.js +78 -0
- package/dist/text/style.cjs +85 -30
- package/dist/text/style.d.cts +50 -1
- package/dist/text/style.d.ts +50 -1
- package/dist/text/style.js +44 -31
- package/dist/units.cjs +4 -0
- package/dist/units.d.cts +2 -1
- package/dist/units.d.ts +2 -1
- package/dist/units.js +4 -1
- package/dist/write.cjs +145 -0
- package/dist/write.d.cts +11 -0
- package/dist/write.d.ts +11 -0
- package/dist/write.js +142 -0
- package/package.json +4 -4
package/dist/write.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("./errors.cjs");
|
|
3
|
+
const require_record_types = require("./record/types.cjs");
|
|
4
|
+
const require_content_write = require("./content-write.cjs");
|
|
5
|
+
const require_record_write = require("./record/write.cjs");
|
|
6
|
+
const require_document_document_atom_write = require("./document/document-atom-write.cjs");
|
|
7
|
+
const require_document_fonts_write = require("./document/fonts-write.cjs");
|
|
8
|
+
const require_drawing_shapes_write = require("./drawing/shapes-write.cjs");
|
|
9
|
+
const require_read = require("./read.cjs");
|
|
10
|
+
const require_document_master_write = require("./document/master-write.cjs");
|
|
11
|
+
const require_document_notes_list_write = require("./document/notes-list-write.cjs");
|
|
12
|
+
const require_document_notes_write = require("./document/notes-write.cjs");
|
|
13
|
+
const require_document_slide_list_write = require("./document/slide-list-write.cjs");
|
|
14
|
+
const require_metadata = require("./metadata.cjs");
|
|
15
|
+
const require_stream_current_user_write = require("./stream/current-user-write.cjs");
|
|
16
|
+
const require_stream_persist_write = require("./stream/persist-write.cjs");
|
|
17
|
+
let archive_codec = require("archive-codec");
|
|
18
|
+
let document_schema_js = require("document-schema.js");
|
|
19
|
+
//#region src/write.ts
|
|
20
|
+
const DOCUMENT_PERSIST_ID = 1;
|
|
21
|
+
const MASTER_PERSIST_ID = 2;
|
|
22
|
+
const FIRST_SLIDE_PERSIST_ID = 3;
|
|
23
|
+
const FIRST_SLIDE_ID = 256;
|
|
24
|
+
const FIRST_NOTES_ID = 512;
|
|
25
|
+
const NO_NOTES_ID_REF = 0;
|
|
26
|
+
const DEFAULT_SLIDE_SIZE = {
|
|
27
|
+
widthPt: 720,
|
|
28
|
+
heightPt: 540
|
|
29
|
+
};
|
|
30
|
+
function requireOneSlideSize(slides) {
|
|
31
|
+
const first = slides[0]?.size ?? DEFAULT_SLIDE_SIZE;
|
|
32
|
+
for (const slide of slides) if (slide.size.widthPt !== first.widthPt || slide.size.heightPt !== first.heightPt) throw new require_errors.PptUnsupportedContentError(`ppt-codec's writer cannot express per-slide sizes: slide sizes ${JSON.stringify(first)} and ${JSON.stringify(slide.size)} both appear, but [MS-PPT]'s DocumentAtom states exactly one slide size for the whole presentation`);
|
|
33
|
+
return first;
|
|
34
|
+
}
|
|
35
|
+
function writeSlideContainer(shapes, notesIdRef, fontIndexOf) {
|
|
36
|
+
return require_record_write.writeContainer(require_record_types.RT_Slide, [require_document_master_write.writeSlideAtomForSlide(notesIdRef), require_drawing_shapes_write.writeSlideDrawing(shapes, fontIndexOf)]);
|
|
37
|
+
}
|
|
38
|
+
function writePptStreams(document) {
|
|
39
|
+
const { slides } = document;
|
|
40
|
+
const size = requireOneSlideSize(slides);
|
|
41
|
+
const fontNames = require_content_write.collectFontFamilies(slides.map((slide) => slide.shapes.flatMap((shape) => shape.blocks)));
|
|
42
|
+
const fontIndexOf = (family) => {
|
|
43
|
+
const index = fontNames.indexOf(family);
|
|
44
|
+
if (index === -1) throw new require_errors.PptUnsupportedContentError(`font family '${family}' was not collected into the document's font table before writing`);
|
|
45
|
+
return index;
|
|
46
|
+
};
|
|
47
|
+
const slidePersistRefs = slides.map((_slide, index) => ({
|
|
48
|
+
persistIdRef: FIRST_SLIDE_PERSIST_ID + index,
|
|
49
|
+
slideId: FIRST_SLIDE_ID + index
|
|
50
|
+
}));
|
|
51
|
+
const notesPersists = [];
|
|
52
|
+
const notesContainers = [];
|
|
53
|
+
const notesIdRefs = slides.map((slide, index) => {
|
|
54
|
+
if (slide.notes.length === 0) return NO_NOTES_ID_REF;
|
|
55
|
+
const notesId = FIRST_NOTES_ID + notesPersists.length;
|
|
56
|
+
notesPersists.push({
|
|
57
|
+
persistIdRef: FIRST_SLIDE_PERSIST_ID + slides.length + notesPersists.length,
|
|
58
|
+
notesId
|
|
59
|
+
});
|
|
60
|
+
notesContainers.push(require_document_notes_write.writeNotesContainer(FIRST_SLIDE_ID + index, slide.notes, size, fontIndexOf));
|
|
61
|
+
return notesId;
|
|
62
|
+
});
|
|
63
|
+
const environment = require_document_fonts_write.writeEnvironment(fontNames);
|
|
64
|
+
const documentChildren = [require_document_document_atom_write.writeDocumentAtom(size)];
|
|
65
|
+
if (environment !== void 0) documentChildren.push(environment);
|
|
66
|
+
documentChildren.push(require_document_master_write.writeMasterListWithText(MASTER_PERSIST_ID));
|
|
67
|
+
documentChildren.push(require_document_slide_list_write.writeSlideListWithText(slidePersistRefs));
|
|
68
|
+
if (notesPersists.length > 0) documentChildren.push(require_document_notes_list_write.writeNotesListWithText(notesPersists));
|
|
69
|
+
const documentContainer = require_record_write.writeContainer(require_record_types.RT_Document, documentChildren);
|
|
70
|
+
const persistObjects = [{
|
|
71
|
+
persistId: DOCUMENT_PERSIST_ID,
|
|
72
|
+
bytes: documentContainer
|
|
73
|
+
}, {
|
|
74
|
+
persistId: MASTER_PERSIST_ID,
|
|
75
|
+
bytes: require_document_master_write.writeMainMaster(size, fontIndexOf)
|
|
76
|
+
}];
|
|
77
|
+
slides.forEach((slide, index) => {
|
|
78
|
+
const ref = slidePersistRefs[index];
|
|
79
|
+
const notesIdRef = notesIdRefs[index];
|
|
80
|
+
if (ref === void 0 || notesIdRef === void 0) throw new require_errors.PptUnsupportedContentError("internal error: slide persist reference missing for a slide being written");
|
|
81
|
+
persistObjects.push({
|
|
82
|
+
persistId: ref.persistIdRef,
|
|
83
|
+
bytes: writeSlideContainer(slide.shapes, notesIdRef, fontIndexOf)
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
notesPersists.forEach((persist, index) => {
|
|
87
|
+
const bytes = notesContainers[index];
|
|
88
|
+
if (bytes === void 0) throw new require_errors.PptUnsupportedContentError("internal error: notes container missing for a notes persist reference");
|
|
89
|
+
persistObjects.push({
|
|
90
|
+
persistId: persist.persistIdRef,
|
|
91
|
+
bytes
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const persistEntries = [];
|
|
95
|
+
let offset = 0;
|
|
96
|
+
for (const object of persistObjects) {
|
|
97
|
+
persistEntries.push({
|
|
98
|
+
persistId: object.persistId,
|
|
99
|
+
offset
|
|
100
|
+
});
|
|
101
|
+
offset += object.bytes.length;
|
|
102
|
+
}
|
|
103
|
+
const persistDirectoryOffset = offset;
|
|
104
|
+
const persistDirectory = require_stream_persist_write.writePersistDirectoryAtom(persistEntries);
|
|
105
|
+
const userEditOffset = persistDirectoryOffset + persistDirectory.length;
|
|
106
|
+
const lastSlideId = slidePersistRefs.at(-1)?.slideId ?? 0;
|
|
107
|
+
const userEdit = require_stream_persist_write.writeUserEditAtom({
|
|
108
|
+
lastSlideIdRef: lastSlideId,
|
|
109
|
+
offsetLastEdit: 0,
|
|
110
|
+
offsetPersistDirectory: persistDirectoryOffset,
|
|
111
|
+
docPersistIdRef: DOCUMENT_PERSIST_ID,
|
|
112
|
+
persistIdSeed: Math.max(...persistEntries.map((entry) => entry.persistId)) + 1
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
currentUserStream: require_stream_current_user_write.writeCurrentUserAtom(userEditOffset),
|
|
116
|
+
powerPointDocumentStream: require_record_write.concatBytes(...persistObjects.map((object) => object.bytes), persistDirectory, userEdit)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function writePptContent(document) {
|
|
120
|
+
const { currentUserStream, powerPointDocumentStream } = writePptStreams(document);
|
|
121
|
+
const streams = [{
|
|
122
|
+
path: require_read.CURRENT_USER_STREAM,
|
|
123
|
+
bytes: currentUserStream
|
|
124
|
+
}, {
|
|
125
|
+
path: require_read.POWERPOINT_DOCUMENT_STREAM,
|
|
126
|
+
bytes: powerPointDocumentStream
|
|
127
|
+
}];
|
|
128
|
+
if ((0, archive_codec.hasSummaryInformationFields)(document.metadata)) streams.push({
|
|
129
|
+
path: require_read.SUMMARY_INFORMATION_STREAM,
|
|
130
|
+
bytes: (0, archive_codec.writeSummaryInformationStream)(require_metadata.layoutMetadataToSummaryInformation(document.metadata))
|
|
131
|
+
});
|
|
132
|
+
return (0, archive_codec.writeCompoundFile)(streams);
|
|
133
|
+
}
|
|
134
|
+
function writePpt(tree) {
|
|
135
|
+
const content = (0, document_schema_js.flattenTree)(tree);
|
|
136
|
+
if (content.kind !== "presentation") throw new require_errors.PptUnsupportedContentError(`ppt-codec's writer only writes presentation documents; got a '${content.kind}' document`);
|
|
137
|
+
return writePptContent({
|
|
138
|
+
metadata: content.metadata,
|
|
139
|
+
slides: content.slides
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
exports.writePpt = writePpt;
|
|
144
|
+
exports.writePptContent = writePptContent;
|
|
145
|
+
exports.writePptStreams = writePptStreams;
|
package/dist/write.d.cts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PptDocument } from "./read.cjs";
|
|
2
|
+
import { DocumentTree } from "document-schema.js";
|
|
3
|
+
//#region src/write.d.ts
|
|
4
|
+
declare function writePptStreams(document: PptDocument): {
|
|
5
|
+
readonly currentUserStream: Uint8Array<ArrayBuffer>;
|
|
6
|
+
readonly powerPointDocumentStream: Uint8Array<ArrayBuffer>;
|
|
7
|
+
};
|
|
8
|
+
declare function writePptContent(document: PptDocument): Uint8Array<ArrayBuffer>;
|
|
9
|
+
declare function writePpt(tree: DocumentTree): Uint8Array<ArrayBuffer>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { writePpt, writePptContent, writePptStreams };
|
package/dist/write.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PptDocument } from "./read.js";
|
|
2
|
+
import { DocumentTree } from "document-schema.js";
|
|
3
|
+
//#region src/write.d.ts
|
|
4
|
+
declare function writePptStreams(document: PptDocument): {
|
|
5
|
+
readonly currentUserStream: Uint8Array<ArrayBuffer>;
|
|
6
|
+
readonly powerPointDocumentStream: Uint8Array<ArrayBuffer>;
|
|
7
|
+
};
|
|
8
|
+
declare function writePptContent(document: PptDocument): Uint8Array<ArrayBuffer>;
|
|
9
|
+
declare function writePpt(tree: DocumentTree): Uint8Array<ArrayBuffer>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { writePpt, writePptContent, writePptStreams };
|
package/dist/write.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { PptUnsupportedContentError } from "./errors.js";
|
|
2
|
+
import { RT_Document, RT_Slide } from "./record/types.js";
|
|
3
|
+
import { collectFontFamilies } from "./content-write.js";
|
|
4
|
+
import { concatBytes, writeContainer } from "./record/write.js";
|
|
5
|
+
import { writeDocumentAtom } from "./document/document-atom-write.js";
|
|
6
|
+
import { writeEnvironment } from "./document/fonts-write.js";
|
|
7
|
+
import { writeSlideDrawing } from "./drawing/shapes-write.js";
|
|
8
|
+
import { CURRENT_USER_STREAM, POWERPOINT_DOCUMENT_STREAM, SUMMARY_INFORMATION_STREAM } from "./read.js";
|
|
9
|
+
import { writeMainMaster, writeMasterListWithText, writeSlideAtomForSlide } from "./document/master-write.js";
|
|
10
|
+
import { writeNotesListWithText } from "./document/notes-list-write.js";
|
|
11
|
+
import { writeNotesContainer } from "./document/notes-write.js";
|
|
12
|
+
import { writeSlideListWithText } from "./document/slide-list-write.js";
|
|
13
|
+
import { layoutMetadataToSummaryInformation as layoutMetadataToSummaryInformation$1 } from "./metadata.js";
|
|
14
|
+
import { writeCurrentUserAtom } from "./stream/current-user-write.js";
|
|
15
|
+
import { writePersistDirectoryAtom, writeUserEditAtom } from "./stream/persist-write.js";
|
|
16
|
+
import { hasSummaryInformationFields, writeCompoundFile, writeSummaryInformationStream } from "archive-codec";
|
|
17
|
+
import { flattenTree } from "document-schema.js";
|
|
18
|
+
//#region src/write.ts
|
|
19
|
+
const DOCUMENT_PERSIST_ID = 1;
|
|
20
|
+
const MASTER_PERSIST_ID = 2;
|
|
21
|
+
const FIRST_SLIDE_PERSIST_ID = 3;
|
|
22
|
+
const FIRST_SLIDE_ID = 256;
|
|
23
|
+
const FIRST_NOTES_ID = 512;
|
|
24
|
+
const NO_NOTES_ID_REF = 0;
|
|
25
|
+
const DEFAULT_SLIDE_SIZE = {
|
|
26
|
+
widthPt: 720,
|
|
27
|
+
heightPt: 540
|
|
28
|
+
};
|
|
29
|
+
function requireOneSlideSize(slides) {
|
|
30
|
+
const first = slides[0]?.size ?? DEFAULT_SLIDE_SIZE;
|
|
31
|
+
for (const slide of slides) if (slide.size.widthPt !== first.widthPt || slide.size.heightPt !== first.heightPt) throw new PptUnsupportedContentError(`ppt-codec's writer cannot express per-slide sizes: slide sizes ${JSON.stringify(first)} and ${JSON.stringify(slide.size)} both appear, but [MS-PPT]'s DocumentAtom states exactly one slide size for the whole presentation`);
|
|
32
|
+
return first;
|
|
33
|
+
}
|
|
34
|
+
function writeSlideContainer(shapes, notesIdRef, fontIndexOf) {
|
|
35
|
+
return writeContainer(RT_Slide, [writeSlideAtomForSlide(notesIdRef), writeSlideDrawing(shapes, fontIndexOf)]);
|
|
36
|
+
}
|
|
37
|
+
function writePptStreams(document) {
|
|
38
|
+
const { slides } = document;
|
|
39
|
+
const size = requireOneSlideSize(slides);
|
|
40
|
+
const fontNames = collectFontFamilies(slides.map((slide) => slide.shapes.flatMap((shape) => shape.blocks)));
|
|
41
|
+
const fontIndexOf = (family) => {
|
|
42
|
+
const index = fontNames.indexOf(family);
|
|
43
|
+
if (index === -1) throw new PptUnsupportedContentError(`font family '${family}' was not collected into the document's font table before writing`);
|
|
44
|
+
return index;
|
|
45
|
+
};
|
|
46
|
+
const slidePersistRefs = slides.map((_slide, index) => ({
|
|
47
|
+
persistIdRef: FIRST_SLIDE_PERSIST_ID + index,
|
|
48
|
+
slideId: FIRST_SLIDE_ID + index
|
|
49
|
+
}));
|
|
50
|
+
const notesPersists = [];
|
|
51
|
+
const notesContainers = [];
|
|
52
|
+
const notesIdRefs = slides.map((slide, index) => {
|
|
53
|
+
if (slide.notes.length === 0) return NO_NOTES_ID_REF;
|
|
54
|
+
const notesId = FIRST_NOTES_ID + notesPersists.length;
|
|
55
|
+
notesPersists.push({
|
|
56
|
+
persistIdRef: FIRST_SLIDE_PERSIST_ID + slides.length + notesPersists.length,
|
|
57
|
+
notesId
|
|
58
|
+
});
|
|
59
|
+
notesContainers.push(writeNotesContainer(FIRST_SLIDE_ID + index, slide.notes, size, fontIndexOf));
|
|
60
|
+
return notesId;
|
|
61
|
+
});
|
|
62
|
+
const environment = writeEnvironment(fontNames);
|
|
63
|
+
const documentChildren = [writeDocumentAtom(size)];
|
|
64
|
+
if (environment !== void 0) documentChildren.push(environment);
|
|
65
|
+
documentChildren.push(writeMasterListWithText(MASTER_PERSIST_ID));
|
|
66
|
+
documentChildren.push(writeSlideListWithText(slidePersistRefs));
|
|
67
|
+
if (notesPersists.length > 0) documentChildren.push(writeNotesListWithText(notesPersists));
|
|
68
|
+
const documentContainer = writeContainer(RT_Document, documentChildren);
|
|
69
|
+
const persistObjects = [{
|
|
70
|
+
persistId: DOCUMENT_PERSIST_ID,
|
|
71
|
+
bytes: documentContainer
|
|
72
|
+
}, {
|
|
73
|
+
persistId: MASTER_PERSIST_ID,
|
|
74
|
+
bytes: writeMainMaster(size, fontIndexOf)
|
|
75
|
+
}];
|
|
76
|
+
slides.forEach((slide, index) => {
|
|
77
|
+
const ref = slidePersistRefs[index];
|
|
78
|
+
const notesIdRef = notesIdRefs[index];
|
|
79
|
+
if (ref === void 0 || notesIdRef === void 0) throw new PptUnsupportedContentError("internal error: slide persist reference missing for a slide being written");
|
|
80
|
+
persistObjects.push({
|
|
81
|
+
persistId: ref.persistIdRef,
|
|
82
|
+
bytes: writeSlideContainer(slide.shapes, notesIdRef, fontIndexOf)
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
notesPersists.forEach((persist, index) => {
|
|
86
|
+
const bytes = notesContainers[index];
|
|
87
|
+
if (bytes === void 0) throw new PptUnsupportedContentError("internal error: notes container missing for a notes persist reference");
|
|
88
|
+
persistObjects.push({
|
|
89
|
+
persistId: persist.persistIdRef,
|
|
90
|
+
bytes
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
const persistEntries = [];
|
|
94
|
+
let offset = 0;
|
|
95
|
+
for (const object of persistObjects) {
|
|
96
|
+
persistEntries.push({
|
|
97
|
+
persistId: object.persistId,
|
|
98
|
+
offset
|
|
99
|
+
});
|
|
100
|
+
offset += object.bytes.length;
|
|
101
|
+
}
|
|
102
|
+
const persistDirectoryOffset = offset;
|
|
103
|
+
const persistDirectory = writePersistDirectoryAtom(persistEntries);
|
|
104
|
+
const userEditOffset = persistDirectoryOffset + persistDirectory.length;
|
|
105
|
+
const lastSlideId = slidePersistRefs.at(-1)?.slideId ?? 0;
|
|
106
|
+
const userEdit = writeUserEditAtom({
|
|
107
|
+
lastSlideIdRef: lastSlideId,
|
|
108
|
+
offsetLastEdit: 0,
|
|
109
|
+
offsetPersistDirectory: persistDirectoryOffset,
|
|
110
|
+
docPersistIdRef: DOCUMENT_PERSIST_ID,
|
|
111
|
+
persistIdSeed: Math.max(...persistEntries.map((entry) => entry.persistId)) + 1
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
currentUserStream: writeCurrentUserAtom(userEditOffset),
|
|
115
|
+
powerPointDocumentStream: concatBytes(...persistObjects.map((object) => object.bytes), persistDirectory, userEdit)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function writePptContent(document) {
|
|
119
|
+
const { currentUserStream, powerPointDocumentStream } = writePptStreams(document);
|
|
120
|
+
const streams = [{
|
|
121
|
+
path: CURRENT_USER_STREAM,
|
|
122
|
+
bytes: currentUserStream
|
|
123
|
+
}, {
|
|
124
|
+
path: POWERPOINT_DOCUMENT_STREAM,
|
|
125
|
+
bytes: powerPointDocumentStream
|
|
126
|
+
}];
|
|
127
|
+
if (hasSummaryInformationFields(document.metadata)) streams.push({
|
|
128
|
+
path: SUMMARY_INFORMATION_STREAM,
|
|
129
|
+
bytes: writeSummaryInformationStream(layoutMetadataToSummaryInformation$1(document.metadata))
|
|
130
|
+
});
|
|
131
|
+
return writeCompoundFile(streams);
|
|
132
|
+
}
|
|
133
|
+
function writePpt(tree) {
|
|
134
|
+
const content = flattenTree(tree);
|
|
135
|
+
if (content.kind !== "presentation") throw new PptUnsupportedContentError(`ppt-codec's writer only writes presentation documents; got a '${content.kind}' document`);
|
|
136
|
+
return writePptContent({
|
|
137
|
+
metadata: content.metadata,
|
|
138
|
+
slides: content.slides
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { writePpt, writePptContent, writePptStreams };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ppt-codec",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Hand-written PowerPoint 97-2003 binary (.ppt, [MS-PPT]) reader against the shared document-schema.js content pivot.",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Hand-written PowerPoint 97-2003 binary (.ppt, [MS-PPT]) reader and writer against the shared document-schema.js content pivot.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"license": "MIT",
|
|
76
76
|
"packageManager": "pnpm@11.6.0",
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"archive-codec": "^1.
|
|
79
|
-
"document-schema.js": "^5.5.
|
|
78
|
+
"archive-codec": "^1.4.0",
|
|
79
|
+
"document-schema.js": "^5.5.1"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@arethetypeswrong/cli": "^0.18.5",
|