Preserve QPowerPoint image hyperlinks in PPTX

This commit is contained in:
Курнат Андрей
2026-06-02 06:17:58 +03:00
parent 0a675236b3
commit e5727b4484
6 changed files with 165 additions and 8 deletions
+69
View File
@@ -290,6 +290,35 @@ describe("powerPointOffice helpers", () => {
]);
});
it("импортирует внешние ссылки изображений PPTX через hlinkClick relationships", 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", slideXmlWithLinkedPicture("Слайд с кликабельным изображением"));
zip.file(
"ppt/slides/_rels/slide1.xml.rels",
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rIdImage" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/logo.png"/><Relationship Id="rIdImageLink" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="https://example.com/logo" TargetMode="External"/></Relationships>`
);
zip.file("ppt/media/logo.png", tinyPngBase64, { base64: true });
const blob = await zip.generateAsync({
type: "blob",
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
});
const imported = await importPptxFile(new File([blob], "Кликабельное изображение.pptx", { type: blob.type }));
expect(imported.slides[0].images?.[0]).toMatchObject({
alt: "Логотип",
hyperlink: "https://example.com/logo"
});
});
it("экспортирует изображения слайда в PPTX media relationships", async () => {
const blob = await exportPptxBlob({
title: "Слайды с изображением.pptx",
@@ -325,6 +354,42 @@ describe("powerPointOffice helpers", () => {
expect(mediaFiles.length).toBeGreaterThan(0);
});
it("экспортирует внешние ссылки изображений PPTX", async () => {
const blob = await exportPptxBlob({
title: "Кликабельное изображение.pptx",
slides: [
{
id: "slide-1",
title: "Слайд с кликабельным изображением",
subtitle: "Проверка ссылки",
notes: "",
theme: "classic",
images: [
{
id: "image-1",
src: `data:image/png;base64,${tinyPngBase64}`,
alt: "Логотип",
hyperlink: "https://example.com/logo",
x: 1,
y: 2,
width: 3,
height: 1.5
}
]
}
]
});
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
const slideXml = (await zip.file("ppt/slides/slide1.xml")?.async("string")) ?? "";
const relationshipsXml = (await zip.file("ppt/slides/_rels/slide1.xml.rels")?.async("string")) ?? "";
const reimported = await importPptxFile(new File([blob], "Кликабельное изображение.pptx", { type: blob.type }));
expect(slideXml).toContain("hlinkClick");
expect(relationshipsXml).toContain('Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"');
expect(relationshipsXml).toContain('Target="https://example.com/logo"');
expect(reimported.slides[0].images?.[0]).toMatchObject({ hyperlink: "https://example.com/logo" });
});
it("экспортирует заметки докладчика в PPTX notesSlide relationships", async () => {
const blob = await exportPptxBlob({
title: "Заметки.pptx",
@@ -641,3 +706,7 @@ function slideXmlWithListSubtitle(title: string, subtitleLines: string[], listSt
function slideXmlWithPicture(title: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><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:pic><p:nvPicPr><p:cNvPr id="4" name="Picture 1" descr="Логотип"/></p:nvPicPr><p:blipFill><a:blip r:embed="rIdImage"/></p:blipFill><p:spPr><a:xfrm><a:off x="914400" y="1828800"/><a:ext cx="2743200" cy="1371600"/></a:xfrm></p:spPr></p:pic></p:spTree></p:cSld></p:sld>`;
}
function slideXmlWithLinkedPicture(title: string) {
return `<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><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:pic><p:nvPicPr><p:cNvPr id="4" name="Picture 1" descr="Логотип"><a:hlinkClick r:id="rIdImageLink"/></p:cNvPr></p:nvPicPr><p:blipFill><a:blip r:embed="rIdImage"/></p:blipFill><p:spPr><a:xfrm><a:off x="914400" y="1828800"/><a:ext cx="2743200" cy="1371600"/></a:xfrm></p:spPr></p:pic></p:spTree></p:cSld></p:sld>`;
}