@officedk/pptxdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
import { BuildError, CapabilityError, capabilityErrorToDiagnostic, toBuildDiagnostic } from "../../core/dist/diagnostics.js";
|
|
2
|
+
import { bytesSha256 } from "../../core/dist/font-seal.js";
|
|
3
|
+
import { buildOptionsSchema, formatBaseline, targets } from "../../core/dist/stage-options.js";
|
|
4
|
+
import "../../core/dist/build.js";
|
|
5
|
+
import "../../core/dist/capability.js";
|
|
6
|
+
import { createBuildQuery } from "../../core/dist/query.js";
|
|
7
|
+
import { getInternalResolution } from "../../core/dist/resolution.js";
|
|
8
|
+
import { assertXml10Characters, countAllocatedMasterThemeParts, hasThemeOverrideContent, pptxParts } from "./ooxml.js";
|
|
9
|
+
import { strToU8, zipSync } from "fflate";
|
|
10
|
+
// ../emit/dist/emit.js
|
|
11
|
+
function diagnostic(path, code, message, details) {
|
|
12
|
+
return toBuildDiagnostic(path, code, message, details);
|
|
13
|
+
}
|
|
14
|
+
function allocateTextFieldId(document) {
|
|
15
|
+
return `{00000000-0000-4000-8000-${(document.nextTextFieldId++).toString(16).padStart(12, "0").toUpperCase()}}`;
|
|
16
|
+
}
|
|
17
|
+
function readValueAtPath(root, path) {
|
|
18
|
+
let current = root;
|
|
19
|
+
for (const key of path) {
|
|
20
|
+
if (typeof current !== "object" || current === null) return void 0;
|
|
21
|
+
current = Reflect.get(current, key);
|
|
22
|
+
}
|
|
23
|
+
return current;
|
|
24
|
+
}
|
|
25
|
+
function mapBuildOptionsIssue(rawOptions, issue) {
|
|
26
|
+
const [head, second, third] = issue.path;
|
|
27
|
+
if (head === void 0) {
|
|
28
|
+
if (issue.code === "unrecognized_keys") return diagnostic("build", "unknown-parameter", `Build options contain unknown parameter ${issue.keys[0]}`, {
|
|
29
|
+
prop: String(issue.keys[0]),
|
|
30
|
+
scope: "options"
|
|
31
|
+
});
|
|
32
|
+
return diagnostic("build", "invalid-options", "Build options must be an object");
|
|
33
|
+
}
|
|
34
|
+
if (head === "embedFonts") return diagnostic("build.embedFonts", "unsupported-font-embedding", "embedFonts currently only supports 'full' or 'subset'", {
|
|
35
|
+
field: "embedFonts",
|
|
36
|
+
mechanism: "embedFonts"
|
|
37
|
+
});
|
|
38
|
+
if (head === "signal") return diagnostic("build.signal", "invalid-options", "Build options signal must be an AbortSignal", { field: "signal" });
|
|
39
|
+
if (head === "target") {
|
|
40
|
+
if (second === void 0) {
|
|
41
|
+
if (issue.code === "unrecognized_keys") return diagnostic("build.target", "unknown-parameter", `Target contains unknown parameter ${issue.keys[0]}`, {
|
|
42
|
+
prop: String(issue.keys[0]),
|
|
43
|
+
scope: "options",
|
|
44
|
+
field: "target"
|
|
45
|
+
});
|
|
46
|
+
return diagnostic("build.target", "invalid-target", "Target must be an object", { field: "target" });
|
|
47
|
+
}
|
|
48
|
+
if (second === "name") return diagnostic("build.target", "invalid-target", "Target requires a non-empty name", { field: "target.name" });
|
|
49
|
+
if (second === "format") return diagnostic("build.target", "unsupported-format", `This build only emits ${formatBaseline}`, {
|
|
50
|
+
field: "target.format",
|
|
51
|
+
expected: formatBaseline
|
|
52
|
+
});
|
|
53
|
+
if (second === "extensions") {
|
|
54
|
+
if (third === void 0) return diagnostic("build.target", "invalid-target", "Target extensions must be an array", { field: "target.extensions" });
|
|
55
|
+
if (issue.code === "custom") return diagnostic("build.target", "duplicate-extension", issue.message, { field: "target.extensions" });
|
|
56
|
+
const badExtension = readValueAtPath(rawOptions, issue.path);
|
|
57
|
+
return diagnostic("build.target", "unsupported-extension", `Unsupported target extension ${String(badExtension)}`, {
|
|
58
|
+
field: "target.extensions",
|
|
59
|
+
extension: String(badExtension)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return diagnostic("build", "invalid-options", issue.message);
|
|
64
|
+
}
|
|
65
|
+
/** Validates emit/build options (`target`, `embedFonts`, `signal`) and normalizes the target. */
|
|
66
|
+
function validateOptions(options) {
|
|
67
|
+
const parsed = buildOptionsSchema.safeParse(options);
|
|
68
|
+
if (!parsed.success) throw new BuildError(parsed.error.issues.map((issue) => mapBuildOptionsIssue(options, issue)));
|
|
69
|
+
return parsed.data.target ?? targets.transitional;
|
|
70
|
+
}
|
|
71
|
+
function addResource(resource, context, objectId) {
|
|
72
|
+
if ("externalTarget" in resource) {
|
|
73
|
+
if (typeof resource.externalTarget !== "string" || resource.externalTarget.trim() === "" || typeof resource.relationshipType !== "string" || resource.relationshipType.trim() === "") throw new CapabilityError("invalid-resource", "External resource target or relationship type is invalid");
|
|
74
|
+
try {
|
|
75
|
+
assertXml10Characters(resource.externalTarget);
|
|
76
|
+
assertXml10Characters(resource.relationshipType);
|
|
77
|
+
} catch {
|
|
78
|
+
throw new CapabilityError("invalid-resource", "External resource contains characters not allowed in XML");
|
|
79
|
+
}
|
|
80
|
+
const relationshipKey = `external\u0000${resource.relationshipType}\u0000${resource.externalTarget}`;
|
|
81
|
+
const existingRelationship = context.slide.relationshipIds.get(relationshipKey);
|
|
82
|
+
if (existingRelationship !== void 0) return existingRelationship;
|
|
83
|
+
const id = `rId${context.slide.relationships.length + context.slide.baseRelationshipCount + 1}`;
|
|
84
|
+
context.slide.relationshipIds.set(relationshipKey, id);
|
|
85
|
+
context.slide.relationships.push({
|
|
86
|
+
id,
|
|
87
|
+
type: resource.relationshipType,
|
|
88
|
+
target: resource.externalTarget,
|
|
89
|
+
targetMode: "External"
|
|
90
|
+
});
|
|
91
|
+
return id;
|
|
92
|
+
}
|
|
93
|
+
if (!(resource.bytes instanceof Uint8Array) || resource.bytes.byteLength === 0) throw new CapabilityError("invalid-resource", "Resource must contain non-empty binary content");
|
|
94
|
+
if (typeof resource.extension !== "string" || !/^[a-z0-9]+$/iu.test(resource.extension) || typeof resource.contentType !== "string" || resource.contentType.trim() === "" || typeof resource.relationshipType !== "string" || resource.relationshipType.trim() === "") throw new CapabilityError("invalid-resource", "Resource format or relationship type is invalid");
|
|
95
|
+
const extension = resource.extension.toLowerCase();
|
|
96
|
+
if (extension === "xml" || extension === "rels") throw new CapabilityError("invalid-resource", `Resource extension .${extension} conflicts with core PPTX parts`);
|
|
97
|
+
const knownType = context.document.resourceTypes.get(extension);
|
|
98
|
+
if (knownType !== void 0 && knownType !== resource.contentType) throw new CapabilityError("conflicting-resource-type", `Resource extension .${extension} corresponds to multiple content types`);
|
|
99
|
+
context.document.resourceTypes.set(extension, resource.contentType);
|
|
100
|
+
try {
|
|
101
|
+
assertXml10Characters(resource.contentType);
|
|
102
|
+
assertXml10Characters(resource.relationshipType);
|
|
103
|
+
} catch {
|
|
104
|
+
throw new CapabilityError("invalid-resource", "Resource relationship contains characters not allowed in XML");
|
|
105
|
+
}
|
|
106
|
+
const digest = bytesSha256(resource.bytes);
|
|
107
|
+
const assetKey = `${extension}\u0000${resource.contentType}\u0000${digest}`;
|
|
108
|
+
let asset = context.document.resources.get(assetKey);
|
|
109
|
+
if (asset === void 0) {
|
|
110
|
+
asset = {
|
|
111
|
+
name: `resource${context.document.resources.size + 1}.${extension}`,
|
|
112
|
+
bytes: new Uint8Array(resource.bytes),
|
|
113
|
+
extension,
|
|
114
|
+
contentType: resource.contentType
|
|
115
|
+
};
|
|
116
|
+
context.document.resources.set(assetKey, asset);
|
|
117
|
+
}
|
|
118
|
+
if (objectId !== void 0) recordResourceObservation(context.slide, objectId, {
|
|
119
|
+
part: `ppt/media/${asset.name}`,
|
|
120
|
+
contentType: asset.contentType,
|
|
121
|
+
byteLength: asset.bytes.byteLength
|
|
122
|
+
});
|
|
123
|
+
const relationshipKey = `${assetKey}\u0000${resource.relationshipType}`;
|
|
124
|
+
const existingRelationship = context.slide.relationshipIds.get(relationshipKey);
|
|
125
|
+
if (existingRelationship !== void 0) return existingRelationship;
|
|
126
|
+
const id = `rId${context.slide.relationships.length + context.slide.baseRelationshipCount + 1}`;
|
|
127
|
+
context.slide.relationshipIds.set(relationshipKey, id);
|
|
128
|
+
context.slide.relationships.push({
|
|
129
|
+
id,
|
|
130
|
+
type: resource.relationshipType,
|
|
131
|
+
target: relationshipTarget(context.slide.partPath, `ppt/media/${asset.name}`)
|
|
132
|
+
});
|
|
133
|
+
return id;
|
|
134
|
+
}
|
|
135
|
+
function relationshipTarget(sourcePath, targetPath) {
|
|
136
|
+
const sourceSegments = sourcePath.split("/").slice(0, -1);
|
|
137
|
+
const targetSegments = targetPath.split("/");
|
|
138
|
+
while (sourceSegments.length > 0 && targetSegments.length > 0 && sourceSegments[0] === targetSegments[0]) {
|
|
139
|
+
sourceSegments.shift();
|
|
140
|
+
targetSegments.shift();
|
|
141
|
+
}
|
|
142
|
+
return [...sourceSegments.map(() => ".."), ...targetSegments].join("/");
|
|
143
|
+
}
|
|
144
|
+
function recordResourceObservation(slide, objectId, resource) {
|
|
145
|
+
if (slide.resourceObservations.some((existing) => existing.objectId === objectId && existing.part === resource.part)) return;
|
|
146
|
+
slide.resourceObservations.push({
|
|
147
|
+
objectId,
|
|
148
|
+
...resource
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function packagePartPath(template, sequence) {
|
|
152
|
+
if ((template.match(/\{n\}/gu) ?? []).length !== 1 || !/^(?:[a-z0-9_-]+\/)*[a-z0-9_-]+\.[a-z0-9]+$/iu.test(template.replace("{n}", String(sequence)))) throw new CapabilityError("invalid-part", "Native part path must be a safe package-relative path containing a single part number");
|
|
153
|
+
return template.replace("{n}", String(sequence));
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Allocates a shared part path without colliding with generated deck parts.
|
|
157
|
+
*
|
|
158
|
+
* Shared part templates normally start at a free sequence number. A template such as
|
|
159
|
+
* `ppt/theme/theme{n}.xml` must nevertheless skip the theme part generated from the deck theme,
|
|
160
|
+
* which is written outside shared part registration but already reserved for the package.
|
|
161
|
+
*/
|
|
162
|
+
function allocateSharedPackagePartPath(template, document) {
|
|
163
|
+
for (;;) {
|
|
164
|
+
const path = packagePartPath(template, document.nextPackagePartId++);
|
|
165
|
+
if (!document.packageParts.has(path) && !document.presentationPartPaths.has(path)) return path;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function addPackagePart(packagePart, context, objectId) {
|
|
169
|
+
const { part, relatedParts } = packagePart;
|
|
170
|
+
if (typeof part.pathTemplate !== "string" || typeof part.contentType !== "string" || part.contentType.trim() === "" || typeof packagePart.relationshipType !== "string" || packagePart.relationshipType.trim() === "" || typeof packagePart.content !== "function" || !Array.isArray(relatedParts) || relatedParts.some((related) => typeof related.pathTemplate !== "string" || typeof related.contentType !== "string" || related.contentType.trim() === "" || typeof related.relationshipType !== "string" || related.relationshipType.trim() === "" || !(related.bytes instanceof Uint8Array) || related.bytes.byteLength === 0)) throw new CapabilityError("invalid-part", "Native part or its related parts format and relationships are invalid");
|
|
171
|
+
try {
|
|
172
|
+
for (const value of [part.contentType, packagePart.relationshipType]) assertXml10Characters(value);
|
|
173
|
+
for (const related of relatedParts) for (const value of [related.contentType, related.relationshipType]) assertXml10Characters(value);
|
|
174
|
+
} catch {
|
|
175
|
+
throw new CapabilityError("invalid-part", "Native part content type or relationship contains characters not allowed in XML 1.0");
|
|
176
|
+
}
|
|
177
|
+
const sequence = context.document.nextPackagePartId++;
|
|
178
|
+
const partPath = packagePartPath(part.pathTemplate, sequence);
|
|
179
|
+
const related = relatedParts.map((item, index) => ({
|
|
180
|
+
path: packagePartPath(item.pathTemplate, sequence),
|
|
181
|
+
relationship: {
|
|
182
|
+
id: `rId${index + 1}`,
|
|
183
|
+
type: item.relationshipType,
|
|
184
|
+
target: ""
|
|
185
|
+
},
|
|
186
|
+
descriptor: item
|
|
187
|
+
}));
|
|
188
|
+
for (const item of related) item.relationship.target = relationshipTarget(partPath, item.path);
|
|
189
|
+
const relatedIds = related.map(({ relationship }) => relationship.id);
|
|
190
|
+
const content = packagePart.content(relatedIds);
|
|
191
|
+
if (!(typeof content === "string" ? content.length > 0 : content instanceof Uint8Array && content.byteLength > 0)) throw new CapabilityError("invalid-part", "Native part must contain content");
|
|
192
|
+
const relatedPaths = new Set(related.map(({ path }) => path));
|
|
193
|
+
if (context.document.packageParts.has(partPath) || relatedPaths.size !== related.length || relatedPaths.has(partPath) || related.some(({ path }) => context.document.packageParts.has(path))) throw new CapabilityError("duplicate-part", "Duplicate PPTX part path");
|
|
194
|
+
if (objectId !== void 0) {
|
|
195
|
+
recordResourceObservation(context.slide, objectId, {
|
|
196
|
+
part: partPath,
|
|
197
|
+
contentType: part.contentType,
|
|
198
|
+
byteLength: typeof content === "string" ? strToU8(content).byteLength : content.byteLength
|
|
199
|
+
});
|
|
200
|
+
for (const item of related) recordResourceObservation(context.slide, objectId, {
|
|
201
|
+
part: item.path,
|
|
202
|
+
contentType: item.descriptor.contentType,
|
|
203
|
+
byteLength: item.descriptor.bytes.byteLength
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
context.document.packageParts.set(partPath, {
|
|
207
|
+
path: partPath,
|
|
208
|
+
content,
|
|
209
|
+
contentType: part.contentType
|
|
210
|
+
});
|
|
211
|
+
for (const item of related) context.document.packageParts.set(item.path, {
|
|
212
|
+
path: item.path,
|
|
213
|
+
content: new Uint8Array(item.descriptor.bytes),
|
|
214
|
+
contentType: item.descriptor.contentType
|
|
215
|
+
});
|
|
216
|
+
if (related.length > 0) context.document.packageRelationships.set(partPath, related.map(({ relationship }) => relationship));
|
|
217
|
+
const relationshipId = `rId${context.slide.relationships.length + context.slide.baseRelationshipCount + 1}`;
|
|
218
|
+
context.slide.relationships.push({
|
|
219
|
+
id: relationshipId,
|
|
220
|
+
type: packagePart.relationshipType,
|
|
221
|
+
target: relationshipTarget(context.slide.partPath, partPath)
|
|
222
|
+
});
|
|
223
|
+
return relationshipId;
|
|
224
|
+
}
|
|
225
|
+
function packagePath(value, label) {
|
|
226
|
+
if (typeof value !== "string" || !/^(?:[a-z0-9_-]+\/)*[a-z0-9_-]+\.[a-z0-9]+$/iu.test(value)) throw new CapabilityError("invalid-part", `${label} must be a safe package-relative path`);
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
function packagePartDescriptor(part, relationshipType, relationships, content, label, allowsSlideTarget = false) {
|
|
230
|
+
if (typeof part.pathTemplate !== "string" || typeof part.contentType !== "string" || part.contentType.trim() === "" || relationshipType !== void 0 && (typeof relationshipType !== "string" || relationshipType.trim() === "") || typeof content !== "function" || relationships !== void 0 && !Array.isArray(relationships) || Array.isArray(relationships) && relationships.some((relationship) => typeof relationship !== "object" || relationship === null || typeof relationship.relationshipType !== "string" || relationship.relationshipType.trim() === "" || typeof relationship.target !== "object" || relationship.target === null || ![
|
|
231
|
+
"slide",
|
|
232
|
+
"part",
|
|
233
|
+
"path"
|
|
234
|
+
].includes(relationship.target.kind) || relationship.target.kind === "part" && (typeof relationship.target.key !== "string" || relationship.target.key === "") || relationship.target.kind === "path" && typeof relationship.target.path !== "string" || relationship.target.kind === "slide" && !allowsSlideTarget)) throw new CapabilityError("invalid-part", `${label} declaration is invalid`);
|
|
235
|
+
try {
|
|
236
|
+
assertXml10Characters(part.contentType);
|
|
237
|
+
if (typeof relationshipType === "string") assertXml10Characters(relationshipType);
|
|
238
|
+
for (const relationship of relationships ?? []) {
|
|
239
|
+
assertXml10Characters(relationship.relationshipType);
|
|
240
|
+
if (relationship.target.kind === "part") assertXml10Characters(relationship.target.key);
|
|
241
|
+
else if (relationship.target.kind === "path") assertXml10Characters(relationship.target.path);
|
|
242
|
+
}
|
|
243
|
+
} catch {
|
|
244
|
+
throw new CapabilityError("invalid-part", `${label} contains characters not allowed in XML 1.0`);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
pathTemplate: part.pathTemplate,
|
|
248
|
+
contentType: part.contentType,
|
|
249
|
+
...typeof relationshipType === "string" ? { relationshipType } : {},
|
|
250
|
+
relationships: relationships ?? []
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function targetPartPath(target, context) {
|
|
254
|
+
if (target.kind === "slide") return `ppt/slides/slide${context.slide.index}.xml`;
|
|
255
|
+
if (target.kind === "part") {
|
|
256
|
+
const shared = context.document.sharedParts.get(target.key);
|
|
257
|
+
if (shared === void 0) throw new CapabilityError("missing-part-target", `Package part relationship references unregistered shared part ${JSON.stringify(target.key)}`);
|
|
258
|
+
return shared.path;
|
|
259
|
+
}
|
|
260
|
+
return packagePath(target.path, "Package part relationship target");
|
|
261
|
+
}
|
|
262
|
+
function partContent(content, label) {
|
|
263
|
+
if (!(typeof content === "string" ? content.length > 0 : content instanceof Uint8Array && content.byteLength > 0)) throw new CapabilityError("invalid-part", `${label} must contain content`);
|
|
264
|
+
if (typeof content === "string") assertXml10Characters(content);
|
|
265
|
+
return content;
|
|
266
|
+
}
|
|
267
|
+
function addSlidePackagePart(part, context) {
|
|
268
|
+
const descriptor = packagePartDescriptor(part.part, part.slideRelationshipType, part.relationships, part.content, "slide part", true);
|
|
269
|
+
const slideRelationshipType = descriptor.relationshipType;
|
|
270
|
+
if (slideRelationshipType === void 0) throw new CapabilityError("invalid-part", "Slide part relationship type is required");
|
|
271
|
+
const sequence = context.document.nextPackagePartId++;
|
|
272
|
+
const partPath = packagePartPath(descriptor.pathTemplate, sequence);
|
|
273
|
+
if (context.document.packageParts.has(partPath) || context.document.presentationPartPaths.has(partPath)) throw new CapabilityError("duplicate-part", "Duplicate PPTX part path");
|
|
274
|
+
const relationships = descriptor.relationships.map((relationship, index) => ({
|
|
275
|
+
id: `rId${index + 1}`,
|
|
276
|
+
type: relationship.relationshipType,
|
|
277
|
+
target: relationshipTarget(partPath, targetPartPath(relationship.target, context))
|
|
278
|
+
}));
|
|
279
|
+
const content = partContent(part.content(relationships.map(({ id }) => id)), "Slide part");
|
|
280
|
+
context.document.presentationPartPaths.add(partPath);
|
|
281
|
+
context.document.packageParts.set(partPath, {
|
|
282
|
+
path: partPath,
|
|
283
|
+
content,
|
|
284
|
+
contentType: descriptor.contentType
|
|
285
|
+
});
|
|
286
|
+
if (relationships.length > 0) context.document.packageRelationships.set(partPath, relationships);
|
|
287
|
+
const relationshipId = `rId${context.slide.relationships.length + context.slide.baseRelationshipCount + 1}`;
|
|
288
|
+
context.slide.relationships.push({
|
|
289
|
+
id: relationshipId,
|
|
290
|
+
type: slideRelationshipType,
|
|
291
|
+
target: relationshipTarget(context.slide.partPath, partPath)
|
|
292
|
+
});
|
|
293
|
+
return relationshipId;
|
|
294
|
+
}
|
|
295
|
+
function addSharedPackagePart(key, part, context) {
|
|
296
|
+
if (typeof key !== "string" || key.trim() === "") throw new CapabilityError("invalid-part", "Shared part key must be a non-empty string");
|
|
297
|
+
const descriptor = packagePartDescriptor(part.part, part.presentationRelationshipType, part.relationships, part.content, "shared part");
|
|
298
|
+
const presentationRelationshipType = descriptor.relationshipType;
|
|
299
|
+
if (part.presentationElement !== void 0 && presentationRelationshipType === void 0) throw new CapabilityError("invalid-part", "Shared part presentation element requires a presentation relationship type");
|
|
300
|
+
const existing = context.document.sharedParts.get(key);
|
|
301
|
+
if (existing !== void 0) {
|
|
302
|
+
if (!(existing.descriptor.part.pathTemplate === descriptor.pathTemplate && existing.descriptor.part.contentType === descriptor.contentType && existing.descriptor.presentationRelationshipType === descriptor.relationshipType && JSON.stringify(existing.descriptor.relationships ?? []) === JSON.stringify(descriptor.relationships))) throw new CapabilityError("conflicting-shared-part", `Shared part ${JSON.stringify(key)} has conflicting declarations`);
|
|
303
|
+
return {
|
|
304
|
+
path: existing.path,
|
|
305
|
+
...existing.relationshipId === void 0 ? {} : { relationshipId: existing.relationshipId }
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const partPath = allocateSharedPackagePartPath(descriptor.pathTemplate, context.document);
|
|
309
|
+
const relationships = descriptor.relationships.map((relationship, index) => ({
|
|
310
|
+
id: `rId${index + 1}`,
|
|
311
|
+
type: relationship.relationshipType,
|
|
312
|
+
target: relationshipTarget(partPath, targetPartPath(relationship.target, context))
|
|
313
|
+
}));
|
|
314
|
+
const content = partContent(part.content(relationships.map(({ id }) => id)), "Shared part");
|
|
315
|
+
context.document.presentationPartPaths.add(partPath);
|
|
316
|
+
context.document.packageParts.set(partPath, {
|
|
317
|
+
path: partPath,
|
|
318
|
+
content,
|
|
319
|
+
contentType: descriptor.contentType
|
|
320
|
+
});
|
|
321
|
+
if (relationships.length > 0) context.document.packageRelationships.set(partPath, relationships);
|
|
322
|
+
let relationshipId;
|
|
323
|
+
if (presentationRelationshipType !== void 0) {
|
|
324
|
+
relationshipId = `rId${context.document.nextPresentationRelationshipId++}`;
|
|
325
|
+
const presentationRelationships = context.document.packageRelationships.get("ppt/presentation.xml") ?? [];
|
|
326
|
+
presentationRelationships.push({
|
|
327
|
+
id: relationshipId,
|
|
328
|
+
type: presentationRelationshipType,
|
|
329
|
+
target: relationshipTarget("ppt/presentation.xml", partPath)
|
|
330
|
+
});
|
|
331
|
+
context.document.packageRelationships.set("ppt/presentation.xml", presentationRelationships);
|
|
332
|
+
const element = part.presentationElement;
|
|
333
|
+
if (element !== void 0) {
|
|
334
|
+
if (element.position !== "before-slides" && element.position !== "after-notes-size" || typeof element.content !== "function") throw new CapabilityError("invalid-part", "Shared part presentation element declaration is invalid");
|
|
335
|
+
const xml = element.content(relationshipId);
|
|
336
|
+
if (typeof xml !== "string" || xml.trim() === "") throw new CapabilityError("invalid-part", "Shared part presentation element must generate content");
|
|
337
|
+
assertXml10Characters(xml);
|
|
338
|
+
context.document.presentationElements.push({
|
|
339
|
+
position: element.position,
|
|
340
|
+
content: xml
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
context.document.sharedParts.set(key, {
|
|
345
|
+
path: partPath,
|
|
346
|
+
...relationshipId === void 0 ? {} : { relationshipId },
|
|
347
|
+
descriptor: {
|
|
348
|
+
part: {
|
|
349
|
+
pathTemplate: descriptor.pathTemplate,
|
|
350
|
+
contentType: descriptor.contentType
|
|
351
|
+
},
|
|
352
|
+
...presentationRelationshipType === void 0 ? {} : { presentationRelationshipType },
|
|
353
|
+
...part.relationships === void 0 ? {} : { relationships: descriptor.relationships },
|
|
354
|
+
...part.presentationElement === void 0 ? {} : { presentationElement: part.presentationElement },
|
|
355
|
+
content: part.content
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return {
|
|
359
|
+
path: partPath,
|
|
360
|
+
...relationshipId === void 0 ? {} : { relationshipId }
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function xmlName(value) {
|
|
364
|
+
return /^(?:[A-Za-z_][A-Za-z0-9_.-]*:)?[A-Za-z_][A-Za-z0-9_.-]*$/u.test(value);
|
|
365
|
+
}
|
|
366
|
+
function addPresentationContribution(contribution, context, path, objectId) {
|
|
367
|
+
const { collection, record, item } = contribution;
|
|
368
|
+
if (!xmlName(collection) || typeof record.key !== "string" || record.key === "" || typeof record.identity !== "string" || typeof record.tagName !== "string" || !xmlName(record.tagName) || typeof record.content !== "string" || typeof item.key !== "string" || item.key === "" || typeof item.identity !== "string" || !Number.isInteger(item.order) || item.order < 0 || typeof item.relationshipType !== "string" || item.relationshipType.trim() === "" || typeof item.pathTemplate !== "string" || typeof item.contentType !== "string" || item.contentType.trim() === "" || item.bytes !== void 0 && (!(item.bytes instanceof Uint8Array) || item.bytes.byteLength === 0) || item.bytes === void 0 && item.resolveBytes === void 0 || item.resourceClaim === void 0 !== (item.resolveBytes === void 0) || item.resourceClaim !== void 0 && (typeof item.resourceClaim.kind !== "string" || item.resourceClaim.kind === "" || typeof item.resourceClaim.key !== "string" || item.resourceClaim.key === "") || item.resolveBytes !== void 0 && typeof item.resolveBytes !== "function" || typeof item.content !== "function" || item.onConflict !== void 0 && (typeof item.onConflict !== "object" || item.onConflict === null || typeof item.onConflict.code !== "string" || item.onConflict.code.trim() === "" || typeof item.onConflict.message !== "string" || item.onConflict.message.trim() === "" || item.onConflict.details !== void 0 && (typeof item.onConflict.details !== "object" || item.onConflict.details === null))) throw new CapabilityError("invalid-presentation-contribution", "Presentation-level contribution record, relationship, or resource is invalid");
|
|
369
|
+
try {
|
|
370
|
+
assertXml10Characters(collection);
|
|
371
|
+
assertXml10Characters(record.content);
|
|
372
|
+
assertXml10Characters(item.relationshipType);
|
|
373
|
+
assertXml10Characters(item.contentType);
|
|
374
|
+
for (const [name, value] of Object.entries(contribution.presentationAttributes ?? {})) {
|
|
375
|
+
if (!xmlName(name) || typeof value !== "string") throw new Error("invalid presentation attribute");
|
|
376
|
+
assertXml10Characters(value);
|
|
377
|
+
}
|
|
378
|
+
} catch {
|
|
379
|
+
throw new CapabilityError("invalid-presentation-contribution", "Presentation-level contribution contains invalid XML name or characters");
|
|
380
|
+
}
|
|
381
|
+
for (const [name, value] of Object.entries(contribution.presentationAttributes ?? {})) {
|
|
382
|
+
const existing = context.document.presentationAttributes.get(name);
|
|
383
|
+
if (existing !== void 0 && existing !== value) context.slide.diagnostics.push(diagnostic(path, "conflicting-presentation-attribute", `Conflicting contribution value for presentation attribute ${name}`));
|
|
384
|
+
else context.document.presentationAttributes.set(name, value);
|
|
385
|
+
}
|
|
386
|
+
let targetCollection = context.document.presentationCollections.get(collection);
|
|
387
|
+
if (targetCollection === void 0) {
|
|
388
|
+
targetCollection = {
|
|
389
|
+
tagName: collection,
|
|
390
|
+
records: /* @__PURE__ */ new Map()
|
|
391
|
+
};
|
|
392
|
+
context.document.presentationCollections.set(collection, targetCollection);
|
|
393
|
+
}
|
|
394
|
+
let targetRecord = targetCollection.records.get(record.key);
|
|
395
|
+
if (targetRecord === void 0) {
|
|
396
|
+
targetRecord = {
|
|
397
|
+
identity: record.identity,
|
|
398
|
+
tagName: record.tagName,
|
|
399
|
+
content: record.content,
|
|
400
|
+
items: /* @__PURE__ */ new Map()
|
|
401
|
+
};
|
|
402
|
+
targetCollection.records.set(record.key, targetRecord);
|
|
403
|
+
} else if (targetRecord.identity !== record.identity || targetRecord.tagName !== record.tagName) {
|
|
404
|
+
context.slide.diagnostics.push(diagnostic(path, "conflicting-presentation-record", `Conflicting declaration for presentation-level record ${record.key}`));
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
let preview;
|
|
408
|
+
try {
|
|
409
|
+
preview = item.content("rId0");
|
|
410
|
+
assertXml10Characters(preview);
|
|
411
|
+
} catch {
|
|
412
|
+
throw new CapabilityError("invalid-presentation-contribution", "Presentation-level contribution failed to generate XML content");
|
|
413
|
+
}
|
|
414
|
+
if (preview.trim() === "") throw new CapabilityError("invalid-presentation-contribution", "Presentation-level contribution must generate content");
|
|
415
|
+
const existingItem = targetRecord.items.get(item.key);
|
|
416
|
+
if (existingItem !== void 0) {
|
|
417
|
+
if (existingItem.identity !== item.identity || existingItem.order !== item.order || existingItem.preview !== preview || existingItem.resourceClaim?.kind !== item.resourceClaim?.kind || existingItem.resourceClaim?.key !== item.resourceClaim?.key) context.slide.diagnostics.push(item.onConflict === void 0 ? diagnostic(path, "conflicting-presentation-item", `Presentation-level record ${record.key} item ${item.key} uses conflicting resources`) : diagnostic(path, item.onConflict.code, item.onConflict.message, item.onConflict.details));
|
|
418
|
+
else {
|
|
419
|
+
const objectIds = existingItem.resourceOwners.get(context.slide) ?? /* @__PURE__ */ new Set();
|
|
420
|
+
if (objectId !== void 0) objectIds.add(objectId);
|
|
421
|
+
existingItem.resourceOwners.set(context.slide, objectIds);
|
|
422
|
+
}
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
let sequence = 1;
|
|
426
|
+
let partPath = packagePartPath(item.pathTemplate, sequence);
|
|
427
|
+
while (context.document.packageParts.has(partPath) || context.document.presentationPartPaths.has(partPath)) {
|
|
428
|
+
sequence += 1;
|
|
429
|
+
partPath = packagePartPath(item.pathTemplate, sequence);
|
|
430
|
+
}
|
|
431
|
+
context.document.presentationPartPaths.add(partPath);
|
|
432
|
+
const relationshipId = `rId${context.document.nextPresentationRelationshipId++}`;
|
|
433
|
+
const content = item.content(relationshipId);
|
|
434
|
+
targetRecord.items.set(item.key, {
|
|
435
|
+
identity: item.identity,
|
|
436
|
+
order: item.order,
|
|
437
|
+
preview,
|
|
438
|
+
content,
|
|
439
|
+
partPath,
|
|
440
|
+
relationshipId,
|
|
441
|
+
relationshipType: item.relationshipType,
|
|
442
|
+
contentType: item.contentType,
|
|
443
|
+
path,
|
|
444
|
+
resourceOwners: /* @__PURE__ */ new Map([[context.slide, objectId === void 0 ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([objectId])]]),
|
|
445
|
+
...item.bytes === void 0 ? {} : { bytes: item.bytes },
|
|
446
|
+
...item.resourceClaim === void 0 ? {} : { resourceClaim: item.resourceClaim },
|
|
447
|
+
...item.resolveBytes === void 0 ? {} : { resolveBytes: item.resolveBytes }
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function finalizePresentationContributions(document) {
|
|
451
|
+
for (const collection of document.presentationCollections.values()) for (const record of collection.records.values()) for (const item of record.items.values()) {
|
|
452
|
+
let bytes = item.bytes;
|
|
453
|
+
if (item.resourceClaim !== void 0) {
|
|
454
|
+
const claimKey = `${item.resourceClaim.kind}\u0000${item.resourceClaim.key}`;
|
|
455
|
+
const claim = document.resourceClaims.get(claimKey);
|
|
456
|
+
if (claim === void 0 || claim.identity !== item.identity) throw new BuildError([diagnostic(item.path, "missing-resource-claim", `Presentation resource ${item.resourceClaim.key} is missing matching character claims`)]);
|
|
457
|
+
try {
|
|
458
|
+
bytes = item.resolveBytes(claim.characters);
|
|
459
|
+
} catch (error) {
|
|
460
|
+
if (error instanceof CapabilityError) throw new BuildError([capabilityErrorToDiagnostic(error, item.path)]);
|
|
461
|
+
throw new BuildError([diagnostic(item.path, "resource-contribution-failed", error instanceof Error ? error.message : String(error))]);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength === 0) throw new BuildError([diagnostic(item.path, "invalid-presentation-contribution", "Presentation-level contribution did not produce valid resource bytes")]);
|
|
465
|
+
document.packageParts.set(item.partPath, {
|
|
466
|
+
path: item.partPath,
|
|
467
|
+
content: new Uint8Array(bytes),
|
|
468
|
+
contentType: item.contentType
|
|
469
|
+
});
|
|
470
|
+
const relationships = document.packageRelationships.get("ppt/presentation.xml") ?? [];
|
|
471
|
+
relationships.push({
|
|
472
|
+
id: item.relationshipId,
|
|
473
|
+
type: item.relationshipType,
|
|
474
|
+
target: relationshipTarget("ppt/presentation.xml", item.partPath)
|
|
475
|
+
});
|
|
476
|
+
document.packageRelationships.set("ppt/presentation.xml", relationships);
|
|
477
|
+
for (const [slide, objectIds] of item.resourceOwners) for (const objectId of objectIds) recordResourceObservation(slide, objectId, {
|
|
478
|
+
part: item.partPath,
|
|
479
|
+
contentType: item.contentType,
|
|
480
|
+
byteLength: bytes.byteLength
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function presentationContent(document) {
|
|
485
|
+
const rendered = [...document.presentationCollections.values()].map(({ tagName, records }) => `<${tagName}>${[...records.values()].map((record) => `<${record.tagName}>${record.content}${[...record.items.values()].sort((left, right) => left.order - right.order).map(({ content }) => content).join("")}</${record.tagName}>`).join("")}</${tagName}>`).join("");
|
|
486
|
+
const elements = (position) => document.presentationElements.filter((element) => element.position === position).map(({ content }) => content).join("");
|
|
487
|
+
return {
|
|
488
|
+
beforeSlides: elements("before-slides"),
|
|
489
|
+
afterNotesSize: rendered + elements("after-notes-size")
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function registerLinkRelationship(link, slideIndexById, slide) {
|
|
493
|
+
const { target } = link;
|
|
494
|
+
if ("id" in target) {
|
|
495
|
+
const targetIndex = slideIndexById.get(target.id);
|
|
496
|
+
if (targetIndex === void 0) throw new Error(`Missing validated target slide ${JSON.stringify(target.id)}`);
|
|
497
|
+
const relationshipKey = `link:slide:${target.id}`;
|
|
498
|
+
let relationshipId = slide.relationshipIds.get(relationshipKey);
|
|
499
|
+
if (relationshipId === void 0) {
|
|
500
|
+
relationshipId = `rId${slide.relationships.length + slide.baseRelationshipCount + 1}`;
|
|
501
|
+
slide.relationshipIds.set(relationshipKey, relationshipId);
|
|
502
|
+
slide.relationships.push({
|
|
503
|
+
id: relationshipId,
|
|
504
|
+
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide",
|
|
505
|
+
target: relationshipTarget(slide.partPath, `ppt/slides/slide${targetIndex}.xml`)
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
relationshipId,
|
|
510
|
+
action: "ppaction://hlinksldjump"
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
if ("url" in target) {
|
|
514
|
+
const relationshipKey = `link:url:${target.url}`;
|
|
515
|
+
let relationshipId = slide.relationshipIds.get(relationshipKey);
|
|
516
|
+
if (relationshipId === void 0) {
|
|
517
|
+
relationshipId = `rId${slide.relationships.length + slide.baseRelationshipCount + 1}`;
|
|
518
|
+
slide.relationshipIds.set(relationshipKey, relationshipId);
|
|
519
|
+
slide.relationships.push({
|
|
520
|
+
id: relationshipId,
|
|
521
|
+
type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
|
|
522
|
+
target: target.url,
|
|
523
|
+
targetMode: "External"
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
return { relationshipId };
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
relationshipId: "",
|
|
530
|
+
action: "ppaction://hlinkshowjump?jump=firstslide"
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function slideSlotOrder(slot) {
|
|
534
|
+
return slot === "transition" ? 0 : 1;
|
|
535
|
+
}
|
|
536
|
+
function createDocumentEmitState(internal) {
|
|
537
|
+
const themePartCount = countAllocatedMasterThemeParts(internal.masters, internal.theme.theme);
|
|
538
|
+
return {
|
|
539
|
+
usedExtensions: /* @__PURE__ */ new Set(),
|
|
540
|
+
resourceClaims: internal.resourceClaims,
|
|
541
|
+
resources: /* @__PURE__ */ new Map(),
|
|
542
|
+
resourceTypes: /* @__PURE__ */ new Map(),
|
|
543
|
+
packageParts: /* @__PURE__ */ new Map(),
|
|
544
|
+
packageRelationships: /* @__PURE__ */ new Map(),
|
|
545
|
+
presentationAttributes: /* @__PURE__ */ new Map(),
|
|
546
|
+
presentationPartPaths: new Set(Array.from({ length: themePartCount }, (_, index) => `ppt/theme/theme${index + 1}.xml`)),
|
|
547
|
+
presentationCollections: /* @__PURE__ */ new Map(),
|
|
548
|
+
sharedParts: /* @__PURE__ */ new Map(),
|
|
549
|
+
presentationElements: [],
|
|
550
|
+
nextPackagePartId: 1,
|
|
551
|
+
nextPresentationRelationshipId: (internal.masters?.length ?? 1) + internal.slides.length + 1,
|
|
552
|
+
nextTextFieldId: 1
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
function checkExtensions(extensions, target, usedExtensions, diagnostics, path) {
|
|
556
|
+
for (const extension of extensions) if (!target.extensions.includes(extension)) diagnostics.push(diagnostic(path, "forbidden-mechanism", `Target forbids ${extension}`, {
|
|
557
|
+
target: target.name,
|
|
558
|
+
extension
|
|
559
|
+
}));
|
|
560
|
+
else usedExtensions.add(extension);
|
|
561
|
+
}
|
|
562
|
+
function emitLayer(layer, slideIndexById, docEmit, slideEmit, target, options) {
|
|
563
|
+
const packageCtx = {
|
|
564
|
+
document: docEmit,
|
|
565
|
+
slide: slideEmit
|
|
566
|
+
};
|
|
567
|
+
checkExtensions(layer.extensions, target, docEmit.usedExtensions, slideEmit.diagnostics, layer.path);
|
|
568
|
+
const childrenXml = layer.childComposition === "members" ? layer.memberLayers.map((child) => emitLayer(child, slideIndexById, docEmit, slideEmit, target, options)).join("") : "";
|
|
569
|
+
const siblingXml = layer.childComposition === "siblings" ? layer.siblingLayers.map((child) => emitLayer(child, slideIndexById, docEmit, slideEmit, target, options)).join("") : "";
|
|
570
|
+
let ownXml = "";
|
|
571
|
+
try {
|
|
572
|
+
const nativeLink = layer.resolvedLink === void 0 ? void 0 : registerLinkRelationship(layer.resolvedLink, slideIndexById, slideEmit);
|
|
573
|
+
const emitContext = {
|
|
574
|
+
id: layer.objectId,
|
|
575
|
+
path: layer.path,
|
|
576
|
+
theme: layer.theme,
|
|
577
|
+
options,
|
|
578
|
+
slideNumber: slideEmit.index,
|
|
579
|
+
...nativeLink === void 0 ? {} : { nativeLink },
|
|
580
|
+
childrenXml,
|
|
581
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
582
|
+
registerResource: (resource) => addResource(resource, packageCtx, layer.objectId),
|
|
583
|
+
registerPackagePart: (part) => addPackagePart(part, packageCtx, layer.objectId)
|
|
584
|
+
};
|
|
585
|
+
const output = layer.emit(emitContext);
|
|
586
|
+
ownXml = output.xml;
|
|
587
|
+
if (layer.morphKey !== void 0 && layer.emitsObject && ownXml === "") slideEmit.diagnostics.push(diagnostic(layer.path, "morph-needs-object", "morphKey can only be used with capabilities that produce native objects"));
|
|
588
|
+
for (const contribution of output.presentationContributions ?? []) addPresentationContribution(contribution, {
|
|
589
|
+
document: docEmit,
|
|
590
|
+
slide: slideEmit
|
|
591
|
+
}, layer.path, layer.objectId);
|
|
592
|
+
} catch (error) {
|
|
593
|
+
slideEmit.diagnostics.push(error instanceof CapabilityError ? capabilityErrorToDiagnostic(error, layer.path, true) : diagnostic(layer.path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
594
|
+
}
|
|
595
|
+
return layer.childComposition === "members" ? ownXml : ownXml + siblingXml;
|
|
596
|
+
}
|
|
597
|
+
const emittedQueries = /* @__PURE__ */ new WeakMap();
|
|
598
|
+
function maxResolvedObjectId(layers) {
|
|
599
|
+
let maxId = 1;
|
|
600
|
+
for (const layer of layers) {
|
|
601
|
+
if (layer.objectId > maxId) maxId = layer.objectId;
|
|
602
|
+
const memberMax = maxResolvedObjectId(layer.memberLayers);
|
|
603
|
+
if (memberMax > maxId) maxId = memberMax;
|
|
604
|
+
const siblingMax = maxResolvedObjectId(layer.siblingLayers);
|
|
605
|
+
if (siblingMax > maxId) maxId = siblingMax;
|
|
606
|
+
}
|
|
607
|
+
return maxId;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Returns the slide locator index enriched with emitted package resources for a BuildReport produced by `emit()`.
|
|
611
|
+
*/
|
|
612
|
+
function emittedBuildQuery(report, fallbackQuery) {
|
|
613
|
+
return emittedQueries.get(report) ?? fallbackQuery;
|
|
614
|
+
}
|
|
615
|
+
function emitMasterOrLayoutCapabilities(capabilities, internal, docEmit, partEmit, target, options) {
|
|
616
|
+
if (capabilities === void 0 || capabilities.length === 0) return {
|
|
617
|
+
transitionXml: "",
|
|
618
|
+
timingXml: ""
|
|
619
|
+
};
|
|
620
|
+
const packageCtx = {
|
|
621
|
+
document: docEmit,
|
|
622
|
+
slide: partEmit
|
|
623
|
+
};
|
|
624
|
+
const transitionParts = [];
|
|
625
|
+
const timingParts = [];
|
|
626
|
+
for (const cap of capabilities) {
|
|
627
|
+
checkExtensions(cap.extensions, target, docEmit.usedExtensions, partEmit.diagnostics, cap.path);
|
|
628
|
+
try {
|
|
629
|
+
const output = cap.emit({
|
|
630
|
+
path: cap.path,
|
|
631
|
+
dimensions: internal.dimensions,
|
|
632
|
+
theme: cap.theme,
|
|
633
|
+
options,
|
|
634
|
+
slideNumber: 0,
|
|
635
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
636
|
+
registerResource: (resource) => addResource(resource, packageCtx),
|
|
637
|
+
registerPackagePart: (part) => addSlidePackagePart(part, packageCtx),
|
|
638
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, packageCtx)
|
|
639
|
+
});
|
|
640
|
+
if (cap.slot === "transition" && output.xml !== "") transitionParts.push(output.xml);
|
|
641
|
+
else if (cap.slot === "timing" && output.xml !== "") timingParts.push(output.xml);
|
|
642
|
+
} catch (error) {
|
|
643
|
+
partEmit.diagnostics.push(error instanceof CapabilityError ? capabilityErrorToDiagnostic(error, cap.path) : diagnostic(cap.path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
transitionXml: transitionParts.join(""),
|
|
648
|
+
timingXml: timingParts.join("")
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
function emitOwnerPlaceholderVisuals(placeholderVisuals, internal, docEmit, ownerEmit, ownerCtx, target, options) {
|
|
652
|
+
if (placeholderVisuals === void 0) return void 0;
|
|
653
|
+
checkExtensions(placeholderVisuals.extensions, target, docEmit.usedExtensions, ownerEmit.diagnostics, placeholderVisuals.path);
|
|
654
|
+
return placeholderVisuals.emit({
|
|
655
|
+
path: placeholderVisuals.path,
|
|
656
|
+
dimensions: internal.dimensions,
|
|
657
|
+
theme: placeholderVisuals.theme,
|
|
658
|
+
options,
|
|
659
|
+
slideNumber: 1,
|
|
660
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
661
|
+
registerResource: (resource) => addResource(resource, ownerCtx),
|
|
662
|
+
registerPackagePart: (part) => addSlidePackagePart(part, ownerCtx),
|
|
663
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, ownerCtx)
|
|
664
|
+
}).placeholderSpPrByKey;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Emits a PPTX archive and BuildReport from an existing Resolution without re-resolving the document.
|
|
668
|
+
*/
|
|
669
|
+
function emit(resolution, options = {}) {
|
|
670
|
+
const target = validateOptions(options);
|
|
671
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
672
|
+
const internal = getInternalResolution(resolution);
|
|
673
|
+
const docEmit = createDocumentEmitState(internal);
|
|
674
|
+
let sectionXml = "";
|
|
675
|
+
if (internal.sectionsEmitter !== void 0) {
|
|
676
|
+
const forbiddenExtensions = internal.sectionsEmitter.extensions.filter((ext) => !target.extensions.includes(ext));
|
|
677
|
+
if (forbiddenExtensions.length > 0) throw new BuildError([diagnostic("deck/sections", "forbidden-mechanism", "Current target forbids p14 section mechanism", {
|
|
678
|
+
target: target.name,
|
|
679
|
+
extension: forbiddenExtensions[0],
|
|
680
|
+
mechanism: "sections"
|
|
681
|
+
})]);
|
|
682
|
+
for (const ext of internal.sectionsEmitter.extensions) docEmit.usedExtensions.add(ext);
|
|
683
|
+
sectionXml = internal.sectionsEmitter.emit().xml;
|
|
684
|
+
}
|
|
685
|
+
const mastersEmitDriver = internal.mastersEmitDriver;
|
|
686
|
+
const slideIndexById = new Map(internal.slides.map((slide) => [slide.id, slide.index]));
|
|
687
|
+
let globalLayoutNumber = 0;
|
|
688
|
+
const emittedMasters = internal.masters?.map((master, masterIndex) => {
|
|
689
|
+
const masterEmit = {
|
|
690
|
+
partPath: `ppt/slideMasters/slideMaster${masterIndex + 1}.xml`,
|
|
691
|
+
baseRelationshipCount: master.layouts.length + 1,
|
|
692
|
+
index: 1,
|
|
693
|
+
diagnostics: [],
|
|
694
|
+
relationships: [],
|
|
695
|
+
relationshipIds: /* @__PURE__ */ new Map(),
|
|
696
|
+
resourceObservations: []
|
|
697
|
+
};
|
|
698
|
+
const masterCtx = {
|
|
699
|
+
document: docEmit,
|
|
700
|
+
slide: masterEmit
|
|
701
|
+
};
|
|
702
|
+
const masterCapXml = emitMasterOrLayoutCapabilities(master.slideCapabilities, internal, docEmit, masterEmit, target, options);
|
|
703
|
+
let masterBackgroundXml = "";
|
|
704
|
+
if (master.background !== void 0) {
|
|
705
|
+
checkExtensions(master.background.extensions, target, docEmit.usedExtensions, masterEmit.diagnostics, master.background.path);
|
|
706
|
+
masterBackgroundXml = master.background.emit({
|
|
707
|
+
path: master.background.path,
|
|
708
|
+
dimensions: internal.dimensions,
|
|
709
|
+
theme: master.background.theme,
|
|
710
|
+
options,
|
|
711
|
+
slideNumber: 1,
|
|
712
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
713
|
+
registerResource: (resource) => addResource(resource, masterCtx),
|
|
714
|
+
registerPackagePart: (part) => addSlidePackagePart(part, masterCtx),
|
|
715
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, masterCtx)
|
|
716
|
+
}).xml;
|
|
717
|
+
}
|
|
718
|
+
let nextMasterObjectId = Math.max(maxResolvedObjectId(master.layers ?? []), 1 + Object.keys(master.placeholders ?? {}).length) + 1;
|
|
719
|
+
const masterShapeFragments = (master.layers ?? []).map((layer) => emitLayer(layer, slideIndexById, docEmit, masterEmit, target, options));
|
|
720
|
+
if (master.footerPlaceholders !== void 0) {
|
|
721
|
+
checkExtensions(master.footerPlaceholders.extensions, target, docEmit.usedExtensions, masterEmit.diagnostics, master.footerPlaceholders.path);
|
|
722
|
+
const fpOut = master.footerPlaceholders.emit({
|
|
723
|
+
path: master.footerPlaceholders.path,
|
|
724
|
+
dimensions: internal.dimensions,
|
|
725
|
+
theme: master.footerPlaceholders.theme,
|
|
726
|
+
options,
|
|
727
|
+
slideNumber: 1,
|
|
728
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
729
|
+
allocateObjectId: () => nextMasterObjectId++,
|
|
730
|
+
registerResource: (resource) => addResource(resource, masterCtx),
|
|
731
|
+
registerPackagePart: (part) => addSlidePackagePart(part, masterCtx),
|
|
732
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, masterCtx)
|
|
733
|
+
});
|
|
734
|
+
masterShapeFragments.push(fpOut.xml);
|
|
735
|
+
for (const contribution of fpOut.presentationContributions ?? []) addPresentationContribution(contribution, {
|
|
736
|
+
document: docEmit,
|
|
737
|
+
slide: masterEmit
|
|
738
|
+
}, master.footerPlaceholders.path);
|
|
739
|
+
}
|
|
740
|
+
const masterShapeXml = mastersEmitDriver !== void 0 ? mastersEmitDriver.emitSharedCanvas(masterShapeFragments) : masterShapeFragments.join("");
|
|
741
|
+
const masterPlaceholderSpPrByKey = emitOwnerPlaceholderVisuals(master.placeholderVisuals, internal, docEmit, masterEmit, masterCtx, target, options);
|
|
742
|
+
if (masterEmit.diagnostics.length > 0) throw new BuildError(masterEmit.diagnostics);
|
|
743
|
+
const emittedLayouts = master.layouts.map((layout) => {
|
|
744
|
+
const layoutEmit = {
|
|
745
|
+
partPath: `ppt/slideLayouts/slideLayout${++globalLayoutNumber}.xml`,
|
|
746
|
+
baseRelationshipCount: hasThemeOverrideContent(layout.themeOverride) ? 2 : 1,
|
|
747
|
+
index: 1,
|
|
748
|
+
diagnostics: [],
|
|
749
|
+
relationships: [],
|
|
750
|
+
relationshipIds: /* @__PURE__ */ new Map(),
|
|
751
|
+
resourceObservations: []
|
|
752
|
+
};
|
|
753
|
+
const layoutCtx = {
|
|
754
|
+
document: docEmit,
|
|
755
|
+
slide: layoutEmit
|
|
756
|
+
};
|
|
757
|
+
const layoutCapXml = emitMasterOrLayoutCapabilities(layout.slideCapabilities, internal, docEmit, layoutEmit, target, options);
|
|
758
|
+
let layoutBackgroundXml = "";
|
|
759
|
+
if (layout.background !== void 0) {
|
|
760
|
+
checkExtensions(layout.background.extensions, target, docEmit.usedExtensions, layoutEmit.diagnostics, layout.background.path);
|
|
761
|
+
layoutBackgroundXml = layout.background.emit({
|
|
762
|
+
path: layout.background.path,
|
|
763
|
+
dimensions: internal.dimensions,
|
|
764
|
+
theme: layout.background.theme,
|
|
765
|
+
options,
|
|
766
|
+
slideNumber: 1,
|
|
767
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
768
|
+
registerResource: (resource) => addResource(resource, layoutCtx),
|
|
769
|
+
registerPackagePart: (part) => addSlidePackagePart(part, layoutCtx),
|
|
770
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, layoutCtx)
|
|
771
|
+
}).xml;
|
|
772
|
+
}
|
|
773
|
+
let nextLayoutObjectId = Math.max(maxResolvedObjectId(layout.layers ?? []), 1 + Object.keys(layout.placeholders ?? {}).length) + 1;
|
|
774
|
+
const layoutShapeFragments = (layout.layers ?? []).map((layer) => emitLayer(layer, slideIndexById, docEmit, layoutEmit, target, options));
|
|
775
|
+
if (layout.footerPlaceholders !== void 0) {
|
|
776
|
+
checkExtensions(layout.footerPlaceholders.extensions, target, docEmit.usedExtensions, layoutEmit.diagnostics, layout.footerPlaceholders.path);
|
|
777
|
+
const fpOut = layout.footerPlaceholders.emit({
|
|
778
|
+
path: layout.footerPlaceholders.path,
|
|
779
|
+
dimensions: internal.dimensions,
|
|
780
|
+
theme: layout.footerPlaceholders.theme,
|
|
781
|
+
options,
|
|
782
|
+
slideNumber: 1,
|
|
783
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
784
|
+
allocateObjectId: () => nextLayoutObjectId++,
|
|
785
|
+
registerResource: (resource) => addResource(resource, layoutCtx),
|
|
786
|
+
registerPackagePart: (part) => addSlidePackagePart(part, layoutCtx),
|
|
787
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, layoutCtx)
|
|
788
|
+
});
|
|
789
|
+
layoutShapeFragments.push(fpOut.xml);
|
|
790
|
+
for (const contribution of fpOut.presentationContributions ?? []) addPresentationContribution(contribution, {
|
|
791
|
+
document: docEmit,
|
|
792
|
+
slide: layoutEmit
|
|
793
|
+
}, layout.footerPlaceholders.path);
|
|
794
|
+
}
|
|
795
|
+
const layoutShapeXml = mastersEmitDriver !== void 0 ? mastersEmitDriver.emitSharedCanvas(layoutShapeFragments) : layoutShapeFragments.join("");
|
|
796
|
+
const layoutPlaceholderSpPrByKey = emitOwnerPlaceholderVisuals(layout.placeholderVisuals, internal, docEmit, layoutEmit, layoutCtx, target, options);
|
|
797
|
+
if (layoutEmit.diagnostics.length > 0) throw new BuildError(layoutEmit.diagnostics);
|
|
798
|
+
return {
|
|
799
|
+
key: layout.key,
|
|
800
|
+
...layout.name === void 0 ? {} : { name: layout.name },
|
|
801
|
+
...layout.type === void 0 ? {} : { type: layout.type },
|
|
802
|
+
...layout.preserve === void 0 ? {} : { preserve: layout.preserve },
|
|
803
|
+
...layout.matchingName === void 0 ? {} : { matchingName: layout.matchingName },
|
|
804
|
+
...layout.userDrawn === void 0 ? {} : { userDrawn: layout.userDrawn },
|
|
805
|
+
...layout.showMasterShapes === void 0 ? {} : { showMasterShapes: layout.showMasterShapes },
|
|
806
|
+
...layout.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: layout.showMasterPlaceholderAnimations },
|
|
807
|
+
...layout.placeholders === void 0 ? {} : { placeholders: layout.placeholders },
|
|
808
|
+
...layoutPlaceholderSpPrByKey === void 0 ? {} : { placeholderSpPrByKey: layoutPlaceholderSpPrByKey },
|
|
809
|
+
...layout.colorMapOverride === void 0 ? {} : { colorMapOverride: layout.colorMapOverride },
|
|
810
|
+
...layout.themeOverride === void 0 ? {} : { themeOverride: layout.themeOverride },
|
|
811
|
+
...layout.headerFooter === void 0 ? {} : { headerFooter: layout.headerFooter },
|
|
812
|
+
...layoutBackgroundXml === "" ? {} : { backgroundXml: layoutBackgroundXml },
|
|
813
|
+
...layoutShapeXml === "" ? {} : { shapeXml: layoutShapeXml },
|
|
814
|
+
...layoutEmit.relationships.length === 0 ? {} : { extraRelationships: layoutEmit.relationships },
|
|
815
|
+
...layoutCapXml.transitionXml === "" ? {} : { transitionXml: layoutCapXml.transitionXml },
|
|
816
|
+
...layoutCapXml.timingXml === "" ? {} : { timingXml: layoutCapXml.timingXml }
|
|
817
|
+
};
|
|
818
|
+
});
|
|
819
|
+
return {
|
|
820
|
+
key: master.key,
|
|
821
|
+
...master.name === void 0 ? {} : { name: master.name },
|
|
822
|
+
...master.preserve === void 0 ? {} : { preserve: master.preserve },
|
|
823
|
+
theme: master.theme,
|
|
824
|
+
themeContext: master.themeContext,
|
|
825
|
+
colorMap: master.colorMap,
|
|
826
|
+
...master.placeholders === void 0 ? {} : { placeholders: master.placeholders },
|
|
827
|
+
...masterPlaceholderSpPrByKey === void 0 ? {} : { placeholderSpPrByKey: masterPlaceholderSpPrByKey },
|
|
828
|
+
...master.textStyles === void 0 ? {} : { textStyles: master.textStyles },
|
|
829
|
+
...master.headerFooter === void 0 ? {} : { headerFooter: master.headerFooter },
|
|
830
|
+
...masterBackgroundXml === "" ? {} : { backgroundXml: masterBackgroundXml },
|
|
831
|
+
...masterShapeXml === "" ? {} : { shapeXml: masterShapeXml },
|
|
832
|
+
...masterEmit.relationships.length === 0 ? {} : { extraRelationships: masterEmit.relationships },
|
|
833
|
+
...masterCapXml.transitionXml === "" ? {} : { transitionXml: masterCapXml.transitionXml },
|
|
834
|
+
...masterCapXml.timingXml === "" ? {} : { timingXml: masterCapXml.timingXml },
|
|
835
|
+
layouts: emittedLayouts
|
|
836
|
+
};
|
|
837
|
+
});
|
|
838
|
+
const emittedSlides = internal.slides.map((resolvedSlide) => {
|
|
839
|
+
const slideEmit = {
|
|
840
|
+
partPath: `ppt/slides/slide${resolvedSlide.index}.xml`,
|
|
841
|
+
baseRelationshipCount: 1,
|
|
842
|
+
index: resolvedSlide.index,
|
|
843
|
+
diagnostics: [],
|
|
844
|
+
relationships: [],
|
|
845
|
+
relationshipIds: /* @__PURE__ */ new Map(),
|
|
846
|
+
resourceObservations: []
|
|
847
|
+
};
|
|
848
|
+
const packageCtx = {
|
|
849
|
+
document: docEmit,
|
|
850
|
+
slide: slideEmit
|
|
851
|
+
};
|
|
852
|
+
let nextSlideObjectId = maxResolvedObjectId(resolvedSlide.layers) + 1;
|
|
853
|
+
let shapeXml = resolvedSlide.layers.map((layer) => emitLayer(layer, slideIndexById, docEmit, slideEmit, target, options)).join("");
|
|
854
|
+
let backgroundXml = "";
|
|
855
|
+
const slideXmlParts = [];
|
|
856
|
+
for (const slideCap of resolvedSlide.slideCapabilities) {
|
|
857
|
+
checkExtensions(slideCap.extensions, target, docEmit.usedExtensions, slideEmit.diagnostics, slideCap.path);
|
|
858
|
+
try {
|
|
859
|
+
const slideEmitContext = {
|
|
860
|
+
path: slideCap.path,
|
|
861
|
+
dimensions: internal.dimensions,
|
|
862
|
+
theme: slideCap.theme,
|
|
863
|
+
options,
|
|
864
|
+
slideNumber: resolvedSlide.index,
|
|
865
|
+
createTextFieldId: () => allocateTextFieldId(docEmit),
|
|
866
|
+
allocateObjectId: () => nextSlideObjectId++,
|
|
867
|
+
registerResource: (resource) => addResource(resource, packageCtx),
|
|
868
|
+
registerPackagePart: (part) => addSlidePackagePart(part, packageCtx),
|
|
869
|
+
registerSharedPart: (key, part) => addSharedPackagePart(key, part, packageCtx)
|
|
870
|
+
};
|
|
871
|
+
const output = slideCap.emit(slideEmitContext);
|
|
872
|
+
if (slideCap.slot === "background") backgroundXml += output.xml;
|
|
873
|
+
else if (slideCap.slot === "shape-tree") shapeXml += output.xml;
|
|
874
|
+
else slideXmlParts.push({
|
|
875
|
+
slot: slideCap.slot,
|
|
876
|
+
xml: output.xml
|
|
877
|
+
});
|
|
878
|
+
for (const contribution of output.presentationContributions ?? []) addPresentationContribution(contribution, {
|
|
879
|
+
document: docEmit,
|
|
880
|
+
slide: slideEmit
|
|
881
|
+
}, slideCap.path);
|
|
882
|
+
} catch (error) {
|
|
883
|
+
slideEmit.diagnostics.push(error instanceof CapabilityError ? capabilityErrorToDiagnostic(error, slideCap.path) : diagnostic(slideCap.path, "capability-failure", error instanceof Error ? error.message : String(error)));
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (slideEmit.diagnostics.length > 0) throw new BuildError(slideEmit.diagnostics);
|
|
887
|
+
return {
|
|
888
|
+
id: resolvedSlide.id,
|
|
889
|
+
...resolvedSlide.name === void 0 ? {} : { name: resolvedSlide.name },
|
|
890
|
+
...resolvedSlide.layoutKey === void 0 ? {} : { layoutKey: resolvedSlide.layoutKey },
|
|
891
|
+
...resolvedSlide.colorMapOverride === void 0 ? {} : { colorMapOverride: resolvedSlide.colorMapOverride },
|
|
892
|
+
...resolvedSlide.themeOverride === void 0 ? {} : { themeOverride: resolvedSlide.themeOverride },
|
|
893
|
+
hidden: resolvedSlide.hidden,
|
|
894
|
+
...resolvedSlide.showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations: resolvedSlide.showMasterPlaceholderAnimations },
|
|
895
|
+
...resolvedSlide.showMasterShapes === void 0 ? {} : { showMasterShapes: resolvedSlide.showMasterShapes },
|
|
896
|
+
shapeXml,
|
|
897
|
+
backgroundXml,
|
|
898
|
+
slideXml: slideXmlParts.map((item, index) => ({
|
|
899
|
+
item,
|
|
900
|
+
index
|
|
901
|
+
})).sort((left, right) => slideSlotOrder(left.item.slot) - slideSlotOrder(right.item.slot) || left.index - right.index).map(({ item }) => item.xml).join(""),
|
|
902
|
+
relationships: slideEmit.relationships,
|
|
903
|
+
resourceObservations: slideEmit.resourceObservations
|
|
904
|
+
};
|
|
905
|
+
});
|
|
906
|
+
finalizePresentationContributions(docEmit);
|
|
907
|
+
const parts = pptxParts(internal.dimensions, emittedSlides.map(({ id, name, layoutKey, colorMapOverride, themeOverride, hidden, showMasterPlaceholderAnimations, showMasterShapes, shapeXml, backgroundXml, slideXml, relationships }) => ({
|
|
908
|
+
id,
|
|
909
|
+
...name === void 0 ? {} : { name },
|
|
910
|
+
...layoutKey === void 0 ? {} : { layoutKey },
|
|
911
|
+
...colorMapOverride === void 0 ? {} : { colorMapOverride },
|
|
912
|
+
...themeOverride === void 0 ? {} : { themeOverride },
|
|
913
|
+
hidden,
|
|
914
|
+
...showMasterPlaceholderAnimations === void 0 ? {} : { showMasterPlaceholderAnimations },
|
|
915
|
+
...showMasterShapes === void 0 ? {} : { showMasterShapes },
|
|
916
|
+
shapeXml,
|
|
917
|
+
backgroundXml,
|
|
918
|
+
slideXml,
|
|
919
|
+
relationships
|
|
920
|
+
})), [...docEmit.resources.values()], [...docEmit.packageParts.values()], [...docEmit.packageRelationships].map(([sourcePath, relationships]) => ({
|
|
921
|
+
sourcePath,
|
|
922
|
+
relationships
|
|
923
|
+
})), presentationContent(docEmit), [...docEmit.presentationAttributes].map(([name, value]) => ({
|
|
924
|
+
name,
|
|
925
|
+
value
|
|
926
|
+
})), internal.theme.theme, internal.title, sectionXml, emittedMasters, mastersEmitDriver);
|
|
927
|
+
const pptx = zipSync(Object.fromEntries(Object.entries(parts).map(([partPath, content]) => [partPath, typeof content === "string" ? strToU8(content) : content])), {
|
|
928
|
+
level: 6,
|
|
929
|
+
mtime: /* @__PURE__ */ new Date("2020-01-01T00:00:00Z")
|
|
930
|
+
});
|
|
931
|
+
const report = Object.freeze({
|
|
932
|
+
evidence: "generation",
|
|
933
|
+
...typeof internal.title === "string" ? { title: internal.title } : {},
|
|
934
|
+
dimensions: resolution.report.dimensions,
|
|
935
|
+
target: Object.freeze({
|
|
936
|
+
name: target.name,
|
|
937
|
+
format: target.format,
|
|
938
|
+
extensions: Object.freeze([...target.extensions])
|
|
939
|
+
}),
|
|
940
|
+
extensions: Object.freeze([...docEmit.usedExtensions]),
|
|
941
|
+
fonts: resolution.report.fonts,
|
|
942
|
+
...resolution.report.masters === void 0 ? {} : { masters: resolution.report.masters },
|
|
943
|
+
slides: resolution.report.slides
|
|
944
|
+
});
|
|
945
|
+
const query = createBuildQuery(internal.slides.map((slide, index) => ({
|
|
946
|
+
observation: report.slides[index],
|
|
947
|
+
dimensions: report.dimensions,
|
|
948
|
+
content: slide.content,
|
|
949
|
+
resources: emittedSlides[index].resourceObservations
|
|
950
|
+
})));
|
|
951
|
+
emittedQueries.set(report, query);
|
|
952
|
+
return Object.freeze({
|
|
953
|
+
pptx,
|
|
954
|
+
report
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
export { emit, emittedBuildQuery, validateOptions };
|