ppt-codec 1.6.0 → 1.7.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 +44 -40
- package/dist/document/master-write.cjs +1 -1
- package/dist/document/master-write.js +1 -1
- package/dist/document/notes-write.cjs +1 -1
- package/dist/document/notes-write.js +1 -1
- package/dist/drawing/properties.cjs +8 -0
- package/dist/drawing/properties.d.cts +5 -1
- package/dist/drawing/properties.d.ts +5 -1
- package/dist/drawing/properties.js +5 -1
- package/dist/drawing/shapes-write.cjs +37 -7
- package/dist/drawing/shapes-write.d.cts +1 -0
- package/dist/drawing/shapes-write.d.ts +1 -0
- package/dist/drawing/shapes-write.js +38 -8
- package/dist/index.cjs +10 -2
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/ole/embedded-write.cjs +66 -0
- package/dist/ole/embedded-write.d.cts +12 -0
- package/dist/ole/embedded-write.d.ts +12 -0
- package/dist/ole/embedded-write.js +63 -0
- package/dist/ole/embedded.cjs +66 -0
- package/dist/ole/embedded.d.cts +12 -0
- package/dist/ole/embedded.d.ts +12 -0
- package/dist/ole/embedded.js +63 -0
- package/dist/read.cjs +52 -11
- package/dist/read.d.cts +12 -5
- package/dist/read.d.ts +12 -5
- package/dist/read.js +53 -12
- package/dist/stream/current-user.cjs +1 -0
- package/dist/stream/current-user.d.cts +2 -1
- package/dist/stream/current-user.d.ts +2 -1
- package/dist/stream/current-user.js +1 -1
- package/dist/units.cjs +10 -0
- package/dist/units.d.cts +4 -1
- package/dist/units.d.ts +4 -1
- package/dist/units.js +8 -1
- package/dist/write.cjs +41 -5
- package/dist/write.d.cts +6 -2
- package/dist/write.d.ts +6 -2
- package/dist/write.js +41 -5
- package/package.json +2 -2
package/dist/write.js
CHANGED
|
@@ -7,8 +7,8 @@ import { concatBytes, writeContainer } from "./record/write.js";
|
|
|
7
7
|
import { writeDocumentAtom } from "./document/document-atom-write.js";
|
|
8
8
|
import { writeEnvironment } from "./document/fonts-write.js";
|
|
9
9
|
import { isBlipFormat, writeDrawingGroupContainer } from "./drawing/blips.js";
|
|
10
|
-
import { writeSlideDrawing } from "./drawing/shapes-write.js";
|
|
11
10
|
import { CURRENT_USER_STREAM, POWERPOINT_DOCUMENT_STREAM, SUMMARY_INFORMATION_STREAM } from "./read.js";
|
|
11
|
+
import { writeSlideDrawing } from "./drawing/shapes-write.js";
|
|
12
12
|
import { writeMainMaster, writeMasterListWithText, writeSlideAtomForSlide } from "./document/master-write.js";
|
|
13
13
|
import { writeNotesListWithText } from "./document/notes-list-write.js";
|
|
14
14
|
import { writeNotesContainer } from "./document/notes-write.js";
|
|
@@ -16,6 +16,7 @@ import { writeSlideListWithText } from "./document/slide-list-write.js";
|
|
|
16
16
|
import { layoutMetadataToSummaryInformation as layoutMetadataToSummaryInformation$1 } from "./metadata.js";
|
|
17
17
|
import { writeCurrentUserAtom } from "./stream/current-user-write.js";
|
|
18
18
|
import { writePersistDirectoryAtom, writeUserEditAtom } from "./stream/persist-write.js";
|
|
19
|
+
import { writeExObjListContainer, writeExOleObjStg, writeOleClientData } from "./ole/embedded-write.js";
|
|
19
20
|
import { hasSummaryInformationFields, writeCompoundFile, writeSummaryInformationStream } from "archive-codec";
|
|
20
21
|
import { flattenTree } from "document-schema.js";
|
|
21
22
|
//#region src/write.ts
|
|
@@ -34,10 +35,10 @@ function requireOneSlideSize(slides) {
|
|
|
34
35
|
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`);
|
|
35
36
|
return first;
|
|
36
37
|
}
|
|
37
|
-
function writeSlideContainer(shapes, notesIdRef, context) {
|
|
38
|
+
function writeSlideContainer(shapes, notesIdRef, context, clientDataFor) {
|
|
38
39
|
const drawing = writeSlideDrawing(shapes.map((shape) => ({
|
|
39
40
|
shape,
|
|
40
|
-
clientData:
|
|
41
|
+
clientData: clientDataFor(shape)
|
|
41
42
|
})), context);
|
|
42
43
|
return {
|
|
43
44
|
bytes: writeContainer(RT_Slide, [writeSlideAtomForSlide(notesIdRef), drawing.bytes]),
|
|
@@ -45,6 +46,34 @@ function writeSlideContainer(shapes, notesIdRef, context) {
|
|
|
45
46
|
maxSpid: drawing.maxSpid
|
|
46
47
|
};
|
|
47
48
|
}
|
|
49
|
+
function planOleEmbeds(slides, serialise, firstPersistId) {
|
|
50
|
+
const embeds = [];
|
|
51
|
+
const persistObjects = [];
|
|
52
|
+
const clientDataByShape = /* @__PURE__ */ new Map();
|
|
53
|
+
if (serialise !== void 0) for (const slide of slides) for (const shape of slide.shapes) {
|
|
54
|
+
const embedBlock = shape.blocks.find((block) => block.kind === "embeddedObject");
|
|
55
|
+
if (embedBlock === void 0) continue;
|
|
56
|
+
const storageBytes = serialise(embedBlock.document);
|
|
57
|
+
if (storageBytes === void 0) continue;
|
|
58
|
+
const exObjId = embeds.length + 1;
|
|
59
|
+
const persistId = firstPersistId + persistObjects.length;
|
|
60
|
+
embeds.push({
|
|
61
|
+
exObjId,
|
|
62
|
+
persistIdRef: persistId,
|
|
63
|
+
objectKind: embedBlock.objectKind
|
|
64
|
+
});
|
|
65
|
+
persistObjects.push({
|
|
66
|
+
persistId,
|
|
67
|
+
bytes: writeExOleObjStg(storageBytes)
|
|
68
|
+
});
|
|
69
|
+
clientDataByShape.set(shape, writeOleClientData(exObjId));
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
embeds,
|
|
73
|
+
persistObjects,
|
|
74
|
+
clientDataFor: (shape) => clientDataByShape.get(shape)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
48
77
|
function planBlipStore(slides) {
|
|
49
78
|
const blips = [];
|
|
50
79
|
const pibByKey = /* @__PURE__ */ new Map();
|
|
@@ -80,10 +109,12 @@ function writePptStreams(document, options = {}) {
|
|
|
80
109
|
return index;
|
|
81
110
|
};
|
|
82
111
|
const store = planBlipStore(slides);
|
|
112
|
+
const strict = options.onUnwritableBlock === "throw";
|
|
83
113
|
const contextFor = (location) => ({
|
|
84
114
|
fontIndexOf,
|
|
85
115
|
blipIndexOf: store.pibOf,
|
|
86
116
|
sink,
|
|
117
|
+
strict,
|
|
87
118
|
location
|
|
88
119
|
});
|
|
89
120
|
const slidePersistRefs = slides.map((_slide, index) => ({
|
|
@@ -91,6 +122,8 @@ function writePptStreams(document, options = {}) {
|
|
|
91
122
|
slideId: FIRST_SLIDE_ID + index
|
|
92
123
|
}));
|
|
93
124
|
const notesIdRefs = slides.map((slide, index) => slide.notes.length === 0 ? NO_NOTES_ID_REF : FIRST_NOTES_ID + slides.slice(0, index).filter((earlier) => earlier.notes.length > 0).length);
|
|
125
|
+
const notesCount = notesIdRefs.filter((id) => id !== NO_NOTES_ID_REF).length;
|
|
126
|
+
const oleEmbeds = planOleEmbeds(slides, options.serialiseEmbeddedObject, FIRST_SLIDE_PERSIST_ID + slides.length + notesCount);
|
|
94
127
|
let shapeCount = 0;
|
|
95
128
|
let maxSpid = 0;
|
|
96
129
|
let drawingCount = 0;
|
|
@@ -105,7 +138,7 @@ function writePptStreams(document, options = {}) {
|
|
|
105
138
|
const ref = slidePersistRefs[index];
|
|
106
139
|
const notesIdRef = notesIdRefs[index];
|
|
107
140
|
if (ref === void 0 || notesIdRef === void 0) throw new PptUnsupportedContentError("internal error: slide persist reference missing for a slide being written");
|
|
108
|
-
const container = writeSlideContainer(slide.shapes, notesIdRef, contextFor(`slide ${index + 1}`));
|
|
141
|
+
const container = writeSlideContainer(slide.shapes, notesIdRef, contextFor(`slide ${index + 1}`), oleEmbeds.clientDataFor);
|
|
109
142
|
account(container);
|
|
110
143
|
return {
|
|
111
144
|
persistId: ref.persistIdRef,
|
|
@@ -131,6 +164,8 @@ function writePptStreams(document, options = {}) {
|
|
|
131
164
|
});
|
|
132
165
|
const environment = writeEnvironment(fontNames);
|
|
133
166
|
const documentChildren = [writeDocumentAtom(size)];
|
|
167
|
+
const exObjList = writeExObjListContainer(oleEmbeds.embeds);
|
|
168
|
+
if (exObjList !== void 0) documentChildren.push(exObjList);
|
|
134
169
|
if (environment !== void 0) documentChildren.push(environment);
|
|
135
170
|
documentChildren.push(writeDrawingGroupContainer(store.blips, {
|
|
136
171
|
spidMax: maxSpid,
|
|
@@ -151,7 +186,8 @@ function writePptStreams(document, options = {}) {
|
|
|
151
186
|
bytes: mainMaster.bytes
|
|
152
187
|
},
|
|
153
188
|
...slideContainers,
|
|
154
|
-
...notesContainers
|
|
189
|
+
...notesContainers,
|
|
190
|
+
...oleEmbeds.persistObjects
|
|
155
191
|
];
|
|
156
192
|
const persistEntries = [];
|
|
157
193
|
let offset = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ppt-codec",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
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": {
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"packageManager": "pnpm@11.6.0",
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"archive-codec": "1.11.0",
|
|
82
|
+
"byte-codec": "1.5.0",
|
|
82
83
|
"document-schema.js": "7.11.0"
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
@@ -88,7 +89,6 @@
|
|
|
88
89
|
"@stryker-mutator/typescript-checker": "10.0.0",
|
|
89
90
|
"@stryker-mutator/vitest-runner": "10.0.0",
|
|
90
91
|
"@types/node": "26.2.0",
|
|
91
|
-
"byte-codec": "1.5.0",
|
|
92
92
|
"eslint": "10.8.1",
|
|
93
93
|
"husky": "9.1.7",
|
|
94
94
|
"jiti": "2.7.0",
|