96 lines
4.2 KiB
TypeScript
96 lines
4.2 KiB
TypeScript
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(
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 50"><rect width="80" height="50" rx="6" fill="#24465f"/><circle cx="25" cy="25" r="13" fill="#85c8e8"/></svg>',
|
|
);
|
|
const metadata = `<?xml version="1.0"?><office:document-meta ${XMLNS}>
|
|
<office:meta><dc:title>Project-authored ODT fixture</dc:title><dc:creator>Office Tools</dc:creator></office:meta>
|
|
</office:document-meta>`;
|
|
const data = makeOdf(
|
|
"odt",
|
|
odtContent(`
|
|
<text:h text:outline-level="1">OpenDocument Text Fixture</text:h>
|
|
<text:p>This document is rendered entirely in the browser.</text:p>
|
|
<text:p>Find the <text:span text:style-name="InlineBold">ODT Search Marker</text:span>.</text:p>
|
|
<text:list><text:list-item><text:p>First local item</text:p></text:list-item><text:list-item><text:p>Second local item</text:p></text:list-item></text:list>
|
|
<table:table table:name="Fixture table"><table:table-row><table:table-cell><text:p>Cell A</text:p></table:table-cell><table:table-cell><text:p>Cell B</text:p></table:table-cell></table:table-row></table:table>
|
|
<draw:frame svg:width="4cm" svg:height="2.5cm"><draw:image xlink:href="Pictures/fixture.svg"/><svg:desc>Project-authored fixture image</svg:desc></draw:frame>`),
|
|
{ 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(`
|
|
<table:table table:name="Overview">
|
|
<table:table-row><table:table-cell office:value-type="string"><text:p>Office Tools Workbook</text:p></table:table-cell><table:table-cell office:value-type="float" office:value="42"><text:p>42</text:p></table:table-cell></table:table-row>
|
|
<table:table-row><table:table-cell office:value-type="string"><text:p>ODS Search Marker</text:p></table:table-cell><table:table-cell office:value-type="float" office:value="84" table:formula="of:=[.B1]*2"><text:p>84</text:p></table:table-cell></table:table-row>
|
|
</table:table>
|
|
<table:table table:name="Details"><table:table-row><table:table-cell office:value-type="string"><text:p>Second sheet content</text:p></table:table-cell></table:table-row></table:table>`),
|
|
);
|
|
return fixture(
|
|
"project-authored.ods",
|
|
"application/vnd.oasis.opendocument.spreadsheet",
|
|
data,
|
|
);
|
|
}
|
|
|
|
export function createMinimalOdp(): OdfFixture {
|
|
const data = makeOdf(
|
|
"odp",
|
|
odpContent(`
|
|
<draw:page draw:name="Opening">
|
|
<draw:frame draw:id="title-1" svg:x="1cm" svg:y="1cm" svg:width="20cm" svg:height="3cm"><draw:text-box><text:h text:outline-level="1">OpenDocument Presentation Fixture</text:h></draw:text-box></draw:frame>
|
|
<draw:rect draw:id="body-1" svg:x="2cm" svg:y="6cm" svg:width="15cm" svg:height="4cm"><text:p>First slide body</text:p></draw:rect>
|
|
<presentation:notes><text:p>Opening speaker note</text:p></presentation:notes>
|
|
</draw:page>
|
|
<draw:page draw:name="Search slide">
|
|
<draw:frame draw:id="title-2" svg:x="1cm" svg:y="1cm" svg:width="20cm" svg:height="3cm"><draw:text-box><text:h text:outline-level="1">ODP Search Marker</text:h></draw:text-box></draw:frame>
|
|
<draw:ellipse draw:id="circle-2" svg:x="4cm" svg:y="6cm" svg:width="5cm" svg:height="5cm"><text:p>Second slide shape</text:p></draw:ellipse>
|
|
<presentation:notes><text:p>Second speaker note</text:p></presentation:notes>
|
|
</draw:page>`),
|
|
);
|
|
return fixture(
|
|
"project-authored.odp",
|
|
"application/vnd.oasis.opendocument.presentation",
|
|
data,
|
|
);
|
|
}
|