theseus/extensions/docx-editor/README.md
Local Dev e6c9f8f5c9 feat(docx-editor): Save as…, PDF export, and a mark of our own
Three gaps, one theme: the editor could produce a file but not decide where
it went, what format it was in, or look like anything in the dock.

**Save as…** opens a real file dialog, and the extension typed there picks
the format. Save then writes to that file instead of dropping another copy
in Downloads every time. The renderer never names a path: the dialog returns
an opaque token, and the add-on will only write to a path a dialog actually
returned. An extension page is the least trusted thing in the add-on, and
"write these bytes anywhere" is not a capability it needs.

**PDF** goes through Chromium's own print pipeline in a hidden window — the
same engine as Ctrl+P — on the paper size read out of the document's own
sectPr. For that to match what the user was looking at, the page's
typography had to stop living in editor.css, which the export window can't
reach: it moves to lib/doc-css.js and both surfaces read the one string. The
result embeds subsetted fonts, keeps images, and turns hyperlinks into real
PDF link annotations.

**The icon** is ours. Microsoft's Word mark is a trademark and borrowing it
to look official is not something a browser that talks about sovereignty
should do. icon.svg says "text document" in its own words — a turned corner,
a heading rule, body lines, a pilcrow badge in Silent Mode green — and
`npm run icons` derives the PNGs and addon.json's copy from it, so there is
one drawing rather than several that drift.

Also: the scratch folder follows the profile rename to extensions-data/ via
the api.dataDir the host now provides, instead of creating a stale
addons-data/ beside it.
2026-09-21 03:35:55 +02:00

82 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Word editor — a Theseus community extension
Opens, edits and saves Word documents (`.docx`) in a full Theseus tab, and
exports them as PDF.
Saving comes in three shapes. **Save** drops a copy in your downloads until the
document has a home; **Save as…** opens a real file dialog where the extension
you type — `.docx` or `.pdf` — decides the format, and from then on Save writes
straight to that file; **PDF** is the one-click export. PDFs are rendered by
Chromium's own print pipeline from `lib/doc-css.js`, the same stylesheet the
editor displays, on the paper size the document itself specifies — so the
export matches the preview rather than being a second opinion about it.
This is **not** a bundled add-on. It isn't in `bundled-addons/`, it isn't in
the installer's `extraResources`, and a fresh Theseus profile doesn't have it.
Users get it the same way they'd get anyone else's extension: from
**Settings › Extensions › Community**, which lists whatever is in the
catalogue at theseus.x/extensions.
Living outside the browser build is the point. A .docx editor is a big
dependency — a megabyte of vendored library — and nobody should carry it
because they wanted a browser.
## The icon
`icon.svg` is the one drawing. `npm run icons` rasterises it to
`icon-16/32/48/128/256.png` and writes a minified copy into `addon.json`'s
`icon` field, which is what the dock button and the catalogue card read — so
there is never a second version to keep in step.
It is deliberately not Microsoft's Word icon. That mark, and the blue sheet
with a white W it belongs to, are Microsoft's trademarks; dressing our
extension up as theirs would be both a legal problem and a dishonest one. The
mark here says "text document" in its own words: a page with a turned corner,
a heading rule, body lines, and a pilcrow badge in Silent Mode green.
## Building
The vendored libraries (mammoth, ProseMirror, docx, JSZip) are bundled by a
build step that lives outside this folder, because mammoth needs local patches
before it can carry everything the editor edits:
cd ../../addon-build/docx-editor
npm install
npm run build # writes vendor/docx-vendor.js here
npm run pack # writes out/docx-editor-<version>.tar.gz
`vendor/docx-vendor.js` is committed, so the extension is installable straight
from a checkout; re-run `npm run build` after touching anything under
`addon-build/`.
## Publishing
`npm run pack` produces the tarball and its sha256. Uploading it is a separate
step, and this repo can't do it: a community extension is signed by the
**owner of a BNS name**, using that name's wallet.
The straightforward route is the publish page at
**theseus.x/extensions/publish** — it unlocks a wallet in the browser, checks
that the name is yours, then signs and `PUT`s the tarball to
`/api/ext/<publisher-name>/docx-editor/<version>`. The gateway verifies both
signatures against the name's current owner, stores the tarball on Sia and
updates `catalog.json`, which is what Settings and the site both read.
Version numbers must increase, and the id `docx-editor` belongs to whichever
name publishes it first.
## Testing
Three levels, all re-runnable, all from `../../addon-build/docx-editor`:
node test/roundtrip.mjs # the built-in fixture
node test/corpus.mjs <folder of .docx> # real documents
node ../../../scratchpad/verify-docx-editor/drive.mjs # a real Theseus, over CDP
The last one installs this folder into a throwaway profile the way the
community channel would, and is the only one that catches browser-only
breakage.
What survives a round trip, and what doesn't, is written up in
[ROUND-TRIP.md](ROUND-TRIP.md). Read that before promising anyone a Word
feature.