8000 Add first-class OpenDocument (ODF) package support by DominikPalo · Pull Request #5 · DominikPalo/OOXML-Toolkit · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
All notable changes to this project are documented here. Each release is published on the
[releases page](https://github.com/DominikPalo/OOXML-Toolkit/releases) with its installers.

## Unreleased

- **Added:** OpenDocument packages (`.odt`, `.ods`, `.odp`, templates, …) are first-class citizens.
- The overview shows the document properties from `meta.xml` (title, author, keywords, dates, editing
time, custom properties, statistics).
- A **Manifest** view of `META-INF/manifest.xml` replaces the (empty) relationship view, including
missing and unlisted files, and part headers show the media type from the manifest.
- The package check verifies `mimetype` (first entry, stored, no trailing whitespace, matches the
manifest) and compares the manifest with the parts.
- Adding or renaming a part updates the manifest; `mimetype` is shown as text and always saved first
and uncompressed (previously it was deflated on save, which breaks ODF consumers).
- There are no slide, document or worksheet previews for OpenDocument yet.

## 0.2.0 — 2026-10-07

- **Added:** EMF and WMF images can be previewed — in the image view, the slide preview and the
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

A cross-platform desktop app (macOS, Windows, Linux) for **viewing, editing and comparing OOXML
packages** — `.docx`, `.xlsx`, `.pptx` and their macro/template variants (`.docm`, `.xlsm`, `.pptm`,
`.dotx`, `.xltx`, `.potx`, …). Basic support for ODF packages (`.odt`, `.ods`, `.odp`) and plain ZIP
files comes for free, because they are ZIP + XML as well.
`.dotx`, `.xltx`, `.potx`, …). OpenDocument packages (`.odt`, `.ods`, `.odp`, …) and plain ZIP files
open as well, because they are ZIP + XML too — ODF files get their document properties, a manifest
view and an ODF-specific package check.

![Animated tour: browse, edit, review, search, compare and check a document](docs/demo.gif)

Expand Down Expand Up @@ -163,6 +164,25 @@ metafiles, which are drawn as vector graphics (CAD and Visio exports, pasted Off
| --- | --- |
| ![Go to part](docs/screenshots/quick-open.png) | ![Bookmarks](docs/screenshots/bookmarks.png) |

### 10. Open OpenDocument files too

`.odt`, `.ods`, `.odp` and the other ODF formats open like any other package. ODF has no relationships
or content types, so the app follows its own conventions instead:

- The **overview** reads `meta.xml` — title, author, keywords, dates, editing time, slide / page /
word counts and any custom properties.
- **Manifest** (next to *Parts* in the explorer) lists every file in `META-INF/manifest.xml` with its
media type, flags entries that point at a missing file and collects files the manifest does not list.
- Renaming or adding a part updates the manifest; `mimetype` is always saved first and uncompressed,
as the format requires.
- The **package check** verifies the `mimetype` entry and compares the manifest with the actual parts.

| | |
| --- | --- |
| ![Overview of an OpenDocument presentation](docs/screenshots/odf-overview.png) | ![Manifest view](docs/screenshots/odf-manifest.png) |

There are no slide, text or cell previews for ODF documents yet — you see (and edit) the XML.

## Features at a glance

**Viewing** — highlighted, foldable source; relationship tables (incoming and outgoing); image (PNG, SVG,
Expand Down Expand Up @@ -260,6 +280,8 @@ Key ideas:
- EMF / WMF previews are converted to SVG with [emf-converter](https://github.com/ChristopherVR/emf-converter):
the picture is sized to the drawn content rather than to the header frame, and text uses the fonts
installed on your machine. Very large metafiles (hundreds of thousands of records) take a moment.
- OpenDocument files have no slide, document or worksheet preview yet (the XML, properties, manifest
and package check work). Encrypted ODF entries are listed but cannot be read.
- ZIP64 archives can be read but are not written (archives must stay below 4 GiB / 65 535 entries).

## License
Expand Down
59 changes: 53 additions & 6 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ There are several ways to open a document:
and OpenDocument files). If the app is already running, the files open in the existing window.

Supported: Office Open XML (`.docx .docm .dotx .xlsx .xlsm .xltx .pptx .pptm .potx .ppsx …`), Visio
`.vsdx`, OpenDocument (`.odt .ods .odp .odg`) and any other ZIP file. Password-protected Office files and
`.vsdx`, OpenDocument (`.odt .ods .odp .odg` and their templates — see
[OpenDocument files](#opendocument-files)) and any other ZIP file. Password-protected Office files and
legacy binary formats (`.doc`, `.xls`, `.ppt`) are not ZIP packages and cannot be opened.

Each file gets its own tab. A dot in place of the ✕ means the document has unsaved changes.
Expand Down Expand Up @@ -84,6 +85,15 @@ document: `presentation.xml → slideMaster, slides, theme …`. Each row shows
`relationship id · type`. External links, targets that do not exist (shown in red) and cycles are marked.
Parts that no chain of relationships reaches are collected under **Unreferenced parts**.

### Manifest mode (OpenDocument)

![Manifest view of an OpenDocument presentation](screenshots/odf-manifest.png)

For OpenDocument packages the *Relations* button becomes **Manifest**. ODF has no relationships; the
tree lists `mimetype`, `META-INF/manifest.xml` and then every file entry of the manifest with its media
type. Entries that point at a file that is not in the package are shown in red, and files that exist but
are not listed are collected under **Not in manifest**. Encrypted entries are marked.

### Context menus

Right-click a row:
Expand All @@ -97,24 +107,26 @@ Right-click a row:

![Context menu for an element](screenshots/context-menu.png)

*Rename* updates every relationship that targets the part and its `[Content_Types].xml` override;
*Delete* leaves references alone on purpose (the package check will list them) and can be undone.
*Rename* updates every relationship that targets the part and its `[Content_Types].xml` override (in an
OpenDocument file: its entry in `META-INF/manifest.xml`); *Delete* leaves references alone on purpose
(the package check will list them) and can be undone.

## 4. What you see for each selection

| Selection | Tabs |
| --- | --- |
| Package (root) | **Overview** |
| Folder | List of contents with sizes |
| XML part | **Preview** (worksheets, the main document part, slides) · **Source** · **Relationships** · **Info** |
| XML part | **Preview** (worksheets, the main document part, slides) · **Source** · **Relationships** (not in OpenDocument files) · **Info** |
| `.rels` part | **Table** · **Source** · **Info** |
| XML element | **Source** (highlighted) · **Inspector** |
| Image | **Preview** · **Hex** · **Info** (SVG also has **Source**; EMF and WMF are previewed too) |
| Text file | **Source** · **Hex** · **Info** |
| Embedded package | **Info** (with *Open as package*) · **Hex** |
| Other binary | **Hex** · **Info** |

**Overview** — part counts, largest parts, document properties (`docProps/core.xml` and `app.xml`),
**Overview** — part counts, largest parts, document properties (`docProps/core.xml` and `app.xml`; in
OpenDocument files `meta.xml`),
the main part, a package-check summary and, when you have edits, the list of unsaved changes with a
*Review changes* button.

Expand All @@ -141,6 +153,26 @@ point at it). Click a row to go to the other end.
**Info** — content type, kind, size, compressed size, CRC-32, ZIP timestamp, text encoding, line count,
status, who refers to the part and an on-demand SHA-256.

### OpenDocument files

OpenDocument packages (`.odt`, `.ods`, `.odp`, `.odg`, their templates and `.odm`) are ZIP + XML like
OOXML, so most of the app works unchanged: tree, source editor, inspector, search, compare, bookmarks.
What differs:

![Overview of an OpenDocument presentation](screenshots/odf-overview.png)

- **Overview** shows the properties from `meta.xml`: title, subject, author, last editor, keywords,
created / modified, language, editing cycles and time, custom properties, the generating
application and the document statistics (slides, sheets or pages, objects, words, …).
- **Manifest** replaces *Relations* in the explorer (see [Manifest mode](#manifest-mode-opendocument)).
The main part is `content.xml`.
- **Media types** shown for a part come from the manifest.
- **Add / rename** keep the manifest in sync; **delete** leaves its entry (like relationships in OOXML)
and the package check reports it.
- `mimetype` is shown as text and always written first and stored uncompressed.

There are no slide, document or worksheet previews for OpenDocument yet.

## 5. Editing

### Source editor
Expand Down Expand Up @@ -173,7 +205,8 @@ prefixes, attribute order, whitespace — is left exactly as it was.

### Parts

Add a file as a new part (a `Default` content type is added for new extensions), replace a part's
Add a file as a new part (a `Default` content type is added for new extensions; in an OpenDocument file
a `file-entry` is added to the manifest), replace a part's
content with a file, export a part, rename or delete it — from the tree's context menu. Embedded
packages (e.g. a workbook embedded in a document) can be opened in their own tab.

Expand All @@ -195,6 +228,9 @@ with your edits:

![Reviewing unsaved changes](screenshots/review-changes.png)

OpenDocument files keep their `mimetype` entry first and uncompressed when saved — a requirement of the
format that many generic ZIP tools get wrong.

In the browser build (`npm run dev:web`) *Save* downloads the file.

## 7. Searching
Expand Down Expand Up @@ -260,6 +296,17 @@ or *Browse…*. Unsaved edits of open documents are included.
| Warning | Part without a content type; content-type override for a missing part; relationships for a missing part; no main document |
| Info | Part not referenced by any relationship |

For OpenDocument files the check applies the ODF packaging rules instead:

| Severity | Finding |
| --- | --- |
| Error | `mimetype` is missing, is not the first entry (folder entries count), or is compressed |
| Error | `META-INF/manifest.xml` is missing, is not a manifest, or lists a file that is not in the package |
| Warning | `mimetype` has trailing whitespace or disagrees with the manifest; a file is not listed in the manifest; no `content.xml` |
| Info | Encrypted entries (listed, but their content cannot be read) |

Parts that are not well-formed XML are reported for every kind of package.

The check looks at the package structure, not at ECMA-376 schema validity. Results are marked
*outdated* when the package has changed since the check ran.

Expand Down
Binary file added docs/screenshots/odf-manifest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/odf-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 17 additions & 2 deletions e2e/screenshots.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ for (const f of readdirSync(out)) rmSync(join(out, f)); // drop stale images
const samplesDir = join(process.platform === 'win32' ? tmpdir() : '/tmp', 'ooxml-samples');
mkdirSync(samplesDir, { recursive: true });
for (const f of readdirSync(join(root, 'samples')))
if (/\.(docx|xlsx|pptx)$/.test(f)) copyFileSync(join(root, 'samples', f), join(samplesDir, f));
if (/\.(docx|xlsx|pptx|odp)$/.test(f))
copyFileSync(join(root, 'samples', f), join(samplesDir, f));
const sample = (n) => join(samplesDir, n);
const profile = join(mkdtempSync(join(tmpdir(), 'ooxml-shots-')), 'profile');

Expand All @@ -34,13 +35,14 @@ const app = await electron.launch({
'sample.xlsx',
'sample.pptx',
'sample-v2.pptx',
'sample.odp',
].map(sample),
],
env: { ...process.env, OOXML_E2E: '1' },
});
const page = await app.firstWindow();
await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].setSize(1360, 860));
await page.waitForFunction(() => document.querySelectorAll('.tab').length >= 6);
await page.waitForFunction(() => document.querySelectorAll('.tab').length >= 7);

// ---- helpers ------------------------------------------------------------------------------------
const command = (id) =>
Expand Down Expand Up @@ -170,6 +172,19 @@ await detailTab('Preview');
await shot('relations-slide');
await page.getByRole('button', { name: /^Parts$/ }).click();

// ---- 4b. An OpenDocument package: metadata and the manifest ----------------------------------
await openTab('sample.odp');
await explorer();
await row('sample.odp').click();
await settle(300);
await shot('odf-overview');
await page.getByRole('button', { name: /Manifest/ }).click();
await settle(200);
await row('content.xml').click();
await settle(400);
await shot('odf-manifest');
await page.getByRole('button', { name: /^Parts$/ }).click();

// ---- 5. Search: text and XPath ----------------------------------------------------------------
await openTab('sample.docx');
await command('view.search');
Expand Down
21 changes: 20 additions & 1 deletion e2e/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ if (!existsSync(join(root, 'samples', 'sample.docx')))
const work = mkdtempSync(join(tmpdir(), 'ooxml-e2e-'));
const docPath = join(work, 'work.docx');
const sheetPath = join(work, 'book.xlsx');
const deckPath = join(work, 'deck.odp');
copyFileSync(join(root, 'samples', 'sample.docx'), docPath);
copyFileSync(join(root, 'samples', 'sample.xlsx'), sheetPath);
copyFileSync(join(root, 'samples', 'sample.odp'), deckPath);
const original = unzipSync(new Uint8Array(readFileSync(docPath)));

const executable = process.env.OOXML_E2E_EXECUTABLE
Expand All @@ -36,6 +38,7 @@ const app = await electron.launch({
`--user-data-dir=${join(work, 'profile')}`,
docPath,
sheetPath,
deckPath,
],
env: { ...process.env, OOXML_E2E: '1', ELECTRON_ENABLE_LOGGING: '0' },
});
Expand All @@ -51,7 +54,7 @@ const step = async (name, fn) => {
};

await step('window opens the files passed on the command line', async () => {
await page.waitForFunction(() => document.querySelectorAll('.tab').length === 2, undefined, {
await page.waitForFunction(() => document.querySelectorAll('.tab').length === 3, undefined, {
timeout: 15000,
});
assert.equal(await page.evaluate(() => window.host?.kind), 'electron');
Expand Down Expand Up @@ -161,6 +164,21 @@ await step('review changes opens a diff', async () => {
await page.screenshot({ path: join(shots, '03-review-changes.png') });
});

await step('an OpenDocument file shows its metadata and a manifest view', async () => {
await page.locator('.tab', { hasText: 'deck.odp' }).click();
await page.waitForSelector('.overview');
const overview = await page.textContent('.overview');
assert.match(overview, /OpenDocument presentation/);
assert.match(overview, /Sample Editor/); // dc:creator from meta.xml
assert.match(overview, /Slides/);
assert.match(overview, /content\.xml/); // the main part of an ODF package
await page.screenshot({ path: join(shots, '05-odf-overview.png') });
await page.getByRole('button', { name: /^Manifest$/ }).click();
await page.locator('.tree-row', { hasText: 'Pictures/image1.png' }).first().waitFor();
assert.match(await page.textContent('.tree'), /image\/png/); // media types come from the manifest
await page.getByRole('button', { name: /^Parts$/ }).click();
});

await step('no console errors', async () => {
assert.deepEqual(errors, []);
});
Expand All @@ -182,6 +200,7 @@ await step('the previous file is restored on the next start', async () => {
await page2.waitForSelector('.tab', { timeout: 15000 });
assert.match(await page2.textContent('.tabs'), /work\.docx/);
assert.match(await page2.textContent('.tabs'), /book\.xlsx/);
assert.match(await page2.textContent('.tabs'), /deck\.odp/);
await page2.waitForSelector('.cm-content, .part-view, .overview', { timeout: 10000 });
await page2.screenshot({ path: join(shots, '04-restored.png') });
});
Expand Down
Binary file added samples/sample.odp
Binary file not shown.
10 changes: 9 additions & 1 deletion scripts/make-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { PackageModel } from '../src/core/package/model';
import { buildDocx, buildPptx, buildXlsx } from '../tests/fixtures/builders';
import { buildDocx, buildOdp, buildPptx, buildXlsx } from '../tests/fixtures/builders';

const dir = join(process.cwd(), 'samples');
mkdirSync(dir, { recursive: true });
Expand All @@ -29,6 +29,14 @@ const files: Record<string, Uint8Array> = {
],
}),
'sample-broken.docx': buildBrokenDocx(),
// An OpenDocument presentation, laid out the way LibreOffice writes one.
'sample.odp': buildOdp({
keywords: ['kickoff', 'quarterly review'],
userDefined: [
{ name: 'Project', value: 'Atlas' },
{ name: 'Budget', value: '1200.5', type: 'float' },
],
}),
'sample.xlsx': buildXlsx(),
'sample-v2.xlsx': buildXlsx({ b2: 99, sheetName: 'Fruit & Veg' }),
'sample.pptx': buildPptx(),
Expand Down
1 change: 1 addition & 0 deletions src/core/package/kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function baseName(name: string): string {

export function partKind(name: string, contentType?: string, head?: Uint8Array): PartKind {
const ext = extensionOf(name);
if (name === 'mimetype') return 'text'; // ODF: the media type of the package
if (ext === 'rels') return 'rels';
if (ext === 'svg') return 'image';
if (XML_EXT.has(ext)) return 'xml';
Expand Down
16 changes: 14 additions & 2 deletions src/core/package/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class PackageModel implements PartSource {

/** Increments on every change (including undo/redo). */
version = 0;
/** Increments when parts are added/removed or `[Content_Types].xml`/`.rels` parts change. */
/** Increments when parts are added/removed or `[Content_Types].xml`, `.rels` or the ODF manifest change. */
structureVersion = 0;

private constructor(archive: ZipArchive, label: string) {
Expand Down Expand Up @@ -131,6 +131,15 @@ export class PackageModel implements PartSource {
return out;
}

/** Every entry — directories included — in the order `serialize()` writes them. */
entryOrder(): string[] {
const out: string[] = [];
for (const e of this.archive.entries)
if (this.overlay.get(e.name)?.kind !== 'absent') out.push(e.name);
for (const n of this.added) out.push(n);
return out;
}

has(name: string): boolean {
const o = this.overlay.get(name);
if (o) return o.kind !== 'absent';
Expand Down Expand Up @@ -292,7 +301,10 @@ export class PackageModel implements PartSource {
}

private isStructural(name: string): boolean {
return name === '[Content_Types].xml' || name.endsWith('.rels');
// The ODF manifest plays the part of [Content_Types].xml: it types every part.
return (
name === '[Content_Types].xml' || name === 'META-INF/manifest.xml' || name.endsWith('.rels')
);
}

// ---- History -----------------------------------------------------------------------------
Expand Down
Loading
Loading
0