@betteroffice/pptx
v0.0.4
Published
PowerPoint-faithful PPTX editor and viewer core — full OOXML fidelity, real-time human + AI agent collaboration. Framework-free (Rust/Wasm).
Maintainers
Readme
@betteroffice/pptx
Framework-free core for the BetterOffice PPTX editor — the Rust parser, yrs deck model, slide layout, and display-list engine compiled to WebAssembly, plus the Canvas2D replay host.
Early (
0.0.x). The core surfaces — opening/saving documents, the editor components, collaboration — are settling and unlikely to change shape. Smaller APIs may still move between releases; breaking changes are always listed in the changelog.
bun add @betteroffice/pptxMost apps want the turnkey React component in
@betteroffice/pptx-react.
Use this package directly to build custom presentation chrome.
Open and render a slide
import {
initWasm,
openPresentation,
paintSlide,
sizeCanvasForSlide,
} from '@betteroffice/pptx';
await initWasm();
const bytes = new Uint8Array(await file.arrayBuffer());
const deck = openPresentation(bytes, {
fonts: [{ family: 'My Sans', bytes: fontBytes }],
});
const frame = deck.layoutSlide(0);
sizeCanvasForSlide(canvas, frame, devicePixelRatio);
await paintSlide(canvas.getContext('2d')!, frame, devicePixelRatio);All parsing, edits, collaboration state, text shaping, layout, hit-testing, and
display-list emission stay in Rust. The package decodes the typed boundary and
replays the resulting primitives on canvas. Font bytes are supplied by the host
and registered with the Rust shaper through openPresentation.
Beyond rendering, PresentationHandle covers editing: text
(insertText / deleteText / formatText), slides
(insertSlide / deleteSlide / moveSlide), shapes
(addTextBox / moveShape / resizeShape), hitTest, undo/redo, and
save(), which serializes the deck back to .pptx bytes with edits applied —
untouched slides keep their exact source part bytes.
Collaboration
PresentationHandle is a collaboration replica. Pair it with
CollaborationProvider and a transport implementing the small
CollaborationTransport interface. The provider speaks the standard Yjs sync-v1
wire protocol, performs state-vector handshakes, forwards only local updates,
and bounds frames and pending backpressure bytes.
import { CollaborationProvider } from '@betteroffice/pptx';
const provider = new CollaborationProvider(deck, transport, {
user: { name: "Ada" }, // identity for this peer's presence chip
});
deck.onUpdate((_update, origin) => {
if (origin === 'remote') repaint();
});
provider.connect();Development
The generated .wasm binary is intentionally not committed. From the repository
root, install wasm-pack 0.15.0 and binaryen, then run
bun scripts/build-pptx-wasm.ts.
Package builds copy the binary into dist/generated.
Docs: https://betteroffice.dev · Apache-2.0.
