Plan 2 of the web embedding SDK: a self-contained, framework-agnostic TypeScript core wrapping the Plan-1 wasm Viewer. createViewer -> OpViewer with load, read-only snapshots (document/pages/pageCount/activePage), pan/zoom navigation (+ wheel), SVG export, load/viewportchange events, and destroy. Read-only: no .op editing/mutation. Self-contained: zero @zseven-w/pen-* deps (types vendored from jian-ops-schema ts-rs), tsup build, vitest+jsdom tests that mock the wasm seam. 10/10 tests; tsc clean; post-destroy use-after-free guarded. React+Vue adapters follow in Plan 3.
21 lines
775 B
TypeScript
21 lines
775 B
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { MockViewer } from './mock-wasm.js';
|
|
let current: MockViewer;
|
|
vi.mock('../src/wasm.js', () => ({
|
|
ensureWasm: vi.fn(async () => {}), WasmViewer: vi.fn(() => { current = new MockViewer(); return current; }), _export: vi.fn(),
|
|
}));
|
|
import { createViewer } from '../src/index.js';
|
|
|
|
describe('events', () => {
|
|
beforeEach(() => vi.clearAllMocks());
|
|
it('fires viewportchange on setZoom and stops after off', async () => {
|
|
const v = await createViewer({ canvas: document.createElement('canvas') });
|
|
const cb = vi.fn();
|
|
const off = v.on('viewportchange', cb);
|
|
v.setZoom(2);
|
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
off(); v.setZoom(3);
|
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|