@neo-office/web-sdk
v0.1.1
Published
High-level browser SDK for viewing and editing Office documents (DOCX, PPTX, XLSX). Built on top of the Neo Office WASM engine — no server, no external services.
Readme
@neo-office/web-sdk
High-level browser SDK for viewing and editing Office documents (DOCX, PPTX, XLSX). Built on top of the Neo Office WASM engine — no server, no external services.
Installation
npm install @neo-office/web-sdkQuick Start
import { NeoPreviewEngine } from '@neo-office/web-sdk';
const engine = new NeoPreviewEngine();
await engine.init();
// Open a file (File object from <input> or drag-and-drop)
const handle = await engine.openFile(file);
// Render a page to an HTML element
await engine.renderPage(handle, 0, document.getElementById('viewer'));
// Clean up
engine.dispose();PPTX — HTML Renderer
Render a PowerPoint slide as a pixel-perfect HTML/CSS/SVG layout:
import { renderSlideToHtml } from '@neo-office/web-sdk';
import type { PptxHtmlRenderOptions } from '@neo-office/web-sdk';
const options: PptxHtmlRenderOptions = {
slideIndex: 0,
containerWidth: 960,
};
const html = renderSlideToHtml(presentation, options);
document.getElementById('slide').innerHTML = html;PPTX — Animations
Play entrance animations and slide transitions:
import { PptxAnimationPlayer, playSlideTransition } from '@neo-office/web-sdk';
// Entrance animations (click-to-advance)
const player = new PptxAnimationPlayer(slideEl, slide.animations);
player.start();
player.advance(); // trigger next click group
// Slide transitions
await playSlideTransition(fromEl, toEl, transition);Edit Session
Track mutations before committing them back to the document:
import { EditSession } from '@neo-office/web-sdk';
const session = new EditSession(handle);
session.apply({ type: 'SET_TEXT', shapeId: 'sp1', text: 'Hello' });
session.apply({ type: 'MOVE_SHAPE', shapeId: 'sp1', x: 100, y: 200 });
const mutations = session.mutations; // inspect pending changes
session.commit(); // finaliseAPI Reference
NeoPreviewEngine
| Method | Returns | Description |
|---|---|---|
| init() | Promise<void> | Initialise the WASM engine |
| openFile(file) | Promise<DocumentHandle> | Load a File object |
| openBytes(bytes, name) | Promise<DocumentHandle> | Load raw Uint8Array |
| renderPage(handle, page, el) | Promise<void> | Render a page into a DOM element |
| getMetadata(handle) | Promise<object> | Title, author, word count, … |
| search(handle, query) | Promise<SearchResult[]> | Full-text search |
| dispose() | void | Release all resources |
renderSlideToHtml(presentation, options)
Converts a parsed PptxPresentation slide into an HTML string. Options:
interface PptxHtmlRenderOptions {
slideIndex: number; // 0-based
containerWidth?: number; // px, default 960
containerHeight?: number; // px, auto-calculated if omitted
}Peer Dependencies
None — the WASM engine is bundled.
License
MIT
