Preserve QPowerPoint slide transitions in PPTX

This commit is contained in:
Курнат Андрей
2026-06-01 20:12:49 +03:00
parent d403ea7f10
commit ae82652068
5 changed files with 114 additions and 8 deletions
+45
View File
@@ -348,6 +348,47 @@ describe("powerPointOffice helpers", () => {
expect(reimported.slides[0].hidden).toBe(true);
});
it("импортирует и экспортирует переходы слайдов PPTX через p:transition", async () => {
const zip = new JSZip();
zip.file(
"ppt/presentation.xml",
`<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><p:sldIdLst><p:sldId id="256" r:id="rId1"/></p:sldIdLst></p:presentation>`
);
zip.file(
"ppt/_rels/presentation.xml.rels",
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide1.xml"/></Relationships>`
);
zip.file("ppt/slides/slide1.xml", slideXmlWithTransition("Слайд с переходом", "fade"));
const importedBlob = await zip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const imported = await importPptxFile(new File([importedBlob], "Переход.pptx", { type: importedBlob.type }));
expect(imported.slides[0]).toMatchObject({ title: "Слайд с переходом", transition: "fade" });
const exportedBlob = await exportPptxBlob({
title: "Переход.pptx",
slides: [
{
id: "slide-1",
title: "Слайд с переходом",
subtitle: "",
notes: "",
theme: "classic",
transition: "wipe"
}
]
});
const exportedZip = await JSZip.loadAsync(await exportedBlob.arrayBuffer());
const exportedSlideXml = (await exportedZip.file("ppt/slides/slide1.xml")?.async("string")) ?? "";
const reimportedTransition = await importPptxFile(new File([exportedBlob], "Переход.pptx", { type: exportedBlob.type }));
expect(exportedSlideXml).toContain("<p:transition><p:wipe/></p:transition>");
expect(reimportedTransition.slides[0].transition).toBe("wipe");
});
it("импортирует и экспортирует цвет и размер текста слайда", async () => {
const zip = new JSZip();
zip.file(
@@ -425,6 +466,10 @@ function slideXmlWithShow(title: string, show: string) {
return `<p:sld show="${show}" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithTransition(title: string, transition: "fade" | "push" | "wipe") {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld><p:transition><p:${transition}/></p:transition></p:sld>`;
}
function slideXmlWithTextStyles(title: string, subtitle: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><p:cSld><p:spTree><p:sp><p:txBody><a:p><a:r><a:rPr sz="3400"><a:solidFill><a:srgbClr val="C2410C"/></a:solidFill><a:latin typeface="Courier New"/></a:rPr><a:t>${title}</a:t></a:r></a:p></p:txBody></p:sp><p:sp><p:txBody><a:p><a:r><a:rPr sz="2200"><a:solidFill><a:srgbClr val="0F766E"/></a:solidFill><a:latin typeface="Times New Roman"/></a:rPr><a:t>${subtitle}</a:t></a:r></a:p></p:txBody></p:sp></p:spTree></p:cSld></p:sld>`;
}