import {
makeOdf,
odpContent,
odsContent,
odtContent,
XMLNS,
} from "../office/odf/fixtures";
export interface OdfFixture {
name: string;
mimeType: string;
buffer: NodeBufferLike;
}
interface NodeBufferLike extends Uint8Array {
toString(encoding?: string): string;
}
const nodeBuffer = (
globalThis as unknown as {
Buffer: { from(value: Uint8Array): NodeBufferLike };
}
).Buffer;
function fixture(
name: string,
mimeType: string,
buffer: ArrayBuffer,
): OdfFixture {
return { name, mimeType, buffer: nodeBuffer.from(new Uint8Array(buffer)) };
}
export function createMinimalOdt(): OdfFixture {
const svg = new TextEncoder().encode(
'',
);
const metadata = `
Project-authored ODT fixtureOffice Tools
`;
const data = makeOdf(
"odt",
odtContent(`
OpenDocument Text Fixture
This document is rendered entirely in the browser.
Find the ODT Search Marker.
First local itemSecond local item
Cell ACell B
Project-authored fixture image`),
{ extra: { "Pictures/fixture.svg": svg }, meta: metadata },
);
return fixture(
"project-authored.odt",
"application/vnd.oasis.opendocument.text",
data,
);
}
export function createMinimalOds(): OdfFixture {
const data = makeOdf(
"ods",
odsContent(`
Office Tools Workbook42
ODS Search Marker84
Second sheet content`),
);
return fixture(
"project-authored.ods",
"application/vnd.oasis.opendocument.spreadsheet",
data,
);
}
export function createMinimalOdp(): OdfFixture {
const data = makeOdf(
"odp",
odpContent(`
OpenDocument Presentation Fixture
First slide body
Opening speaker note
ODP Search Marker
Second slide shape
Second speaker note
`),
);
return fixture(
"project-authored.odp",
"application/vnd.oasis.opendocument.presentation",
data,
);
}