Rendering mode
Choose where layout and paint run.
Parsing always runs in a Worker. Keep the default mode: 'main' for ordinary
previews. Choose mode: 'worker' when document layout and Canvas paint compete
with your application's UI.
main | worker | |
|---|---|---|
| Layout and paint | Main thread | Web Worker |
| Best fit | Most previews and custom renderer objects | Large or complex files |
| Browser requirement | Canvas | Worker and OffscreenCanvas |
Ownership
Let one Viewer own one document, unless views need to share it.
The usual path is to construct a Viewer, call load(source), and destroy the
Viewer when its host unmounts. The Viewer owns the loaded document.
Load the document model yourself only when several views must share one parse. Destroy every borrowed view before destroying the shared model.
| Format | Shared model | Borrowing factory |
|---|---|---|
| DOCX | DocxDocument | fromDocument() |
| PPTX | PptxPresentation | fromPresentation() |
| XLSX | XlsxWorkbook | fromWorkbook() |
import { DocxDocument, DocxScrollViewer } from '@silurus/ooxml/docx';
const document = await DocxDocument.load(source, { mode: 'worker' });
const first = DocxScrollViewer.fromDocument(firstContainer, document);
const second = DocxScrollViewer.fromDocument(secondContainer, document);
// Destroy every view before the shared document.
first.destroy();
second.destroy();
document.destroy(); Optional renderers
Add only the rendering modules a product needs.
Equations, ChartEx, 3-D charts, and Region Maps use separate package entries and the same Viewer options across DOCX, XLSX, and PPTX. Classic 2-D charts remain included with each format.
import { XlsxViewer } from '@silurus/ooxml/xlsx';
import { math } from '@silurus/ooxml/math';
import { chartEx } from '@silurus/ooxml/chart-ex';
import { threeD } from '@silurus/ooxml/three-d';
import { regionMap } from '@silurus/ooxml/region-map';
const viewer = new XlsxViewer(container, {
math,
chartEx,
threeD,
regionMap,
}); | Capability | Import | Viewer option |
|---|---|---|
| Equation renderer | @silurus/ooxml/math | math |
| Microsoft ChartEx renderer | @silurus/ooxml/chart-ex | chartEx |
| 3-D chart renderer | @silurus/ooxml/three-d | threeD |
| Offline Region Map renderer | @silurus/ooxml/region-map | regionMap |