@web-ppt/viewer-core
v0.5.0
Published
Headless presentation state machine for Web-PPT: navigation, zoom, search and click-batched animation playback, drivable from any UI framework.
Maintainers
Readme
@web-ppt/viewer-core
English · 简体中文
The headless layer of Web-PPT.
PresentationState is a pure state machine with zero DOM — navigation, zoom, search, animation batching, auto-advance. Drive it from plain DOM, React, Vue or Svelte, or run it straight in Node for tests. Viewer is the thinnest possible DOM binding on top (inject SVG, set visibility, kick off playback — about 24 lines).
npm i @web-ppt/core @web-ppt/viewer-coreBatteries included
import { parse } from '@web-ppt/core';
import { Viewer } from '@web-ppt/viewer-core';
const pres = await parse(file);
const v = new Viewer(container, pres, { animate: true, autoAdvance: true });
v.next(); // plays a pending animation batch, otherwise advances the slide
v.prev(); // rewinds one finished click, otherwise the previous slide at its end build
v.finishAnimations(); // jump to this slide's end state
v.setZoom(1.5);
v.search('keyword'); // → array of matching slide indices
await v.exportPng(2); // → BlobInternal slide links support both click and Tab/Enter; external links can be intercepted with v.onLinkClick.
destroy() removes both navigation listeners.
Bring your own UI
import { PresentationState, playGroup, playTransition } from '@web-ppt/viewer-core';
const st = new PresentationState(pres, { skipHidden: true, animate: true });
st.subscribe((change) => {
if (change.type === 'slide') {
render(change.index);
if (change.transition) playTransition(prevEl, nextEl, change.transition);
} else if (change.type === 'animation' && change.group) {
playGroup(container, change.group);
} else if (change.type === 'animation' && change.settle) {
// repaint, then apply hiddenElementIds and the settled style of completed steps
}
});
st.next();
st.hiddenElementIds; // element ids that should be hidden at the current batch
st.resolveLink(href); // 'slide:3' → 2, external links → nullThe state machine only decides what should be visible; the UI layer performs the actual playback through playGroup / playTransition — so switching frameworks rewrites no logic.
MIT
