@silurus/ooxml 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,450 @@
1
+ declare interface ArrowEnd {
2
+ /** OOXML type: "none" | "triangle" | "stealth" | "diamond" | "oval" | "arrow" */
3
+ type: string;
4
+ /** Width multiplier: "sm" | "med" | "lg" */
5
+ w: string;
6
+ /** Length multiplier: "sm" | "med" | "lg" */
7
+ len: string;
8
+ }
9
+
10
+ declare type Bullet = {
11
+ type: 'none';
12
+ } | {
13
+ type: 'inherit';
14
+ } | {
15
+ type: 'char';
16
+ char: string;
17
+ color: string | null;
18
+ sizePct: number | null;
19
+ fontFamily: string | null;
20
+ } | {
21
+ type: 'autoNum';
22
+ numType: string;
23
+ startAt: number | null;
24
+ };
25
+
26
+ /**
27
+ * PPTX chart element. The Rust parser emits ChartModel fields flat at the
28
+ * top level, alongside the element position (x/y/width/height in EMU).
29
+ * Pass this straight to `renderChart` from `@silurus/ooxml-core`.
30
+ */
31
+ declare interface ChartElement {
32
+ type: 'chart';
33
+ x: number;
34
+ y: number;
35
+ width: number;
36
+ height: number;
37
+ chartType: string;
38
+ title: string | null;
39
+ categories: string[];
40
+ series: ChartSeries[];
41
+ valMax: number | null;
42
+ valMin: number | null;
43
+ subtotalIndices: number[];
44
+ showDataLabels: boolean;
45
+ catAxisHidden: boolean;
46
+ valAxisHidden: boolean;
47
+ plotAreaBg: string | null;
48
+ }
49
+
50
+ declare interface ChartSeries {
51
+ name: string;
52
+ /** Hex without '#'. null = fall back to palette. */
53
+ color: string | null;
54
+ /** Numeric values; null = missing data point. */
55
+ values: (number | null)[];
56
+ /**
57
+ * Per-data-point colors (pie / doughnut). Hex without '#'. null inside the
58
+ * array = use palette for that slice. Omit entirely for non-pie series.
59
+ */
60
+ dataPointColors?: (string | null)[] | null;
61
+ /**
62
+ * Mixed chart: per-series chart type override. Currently only "line" (XLSX)
63
+ * is honoured; other values are treated as the chart's primary type.
64
+ */
65
+ seriesType?: string | null;
66
+ /**
67
+ * Scatter-only X values (as strings). When null the series uses
68
+ * `ChartModel.categories` as X.
69
+ */
70
+ categories?: string[] | null;
71
+ }
72
+
73
+ export declare type Fill = SolidFill | NoFill | GradientFill;
74
+
75
+ declare interface GradientFill {
76
+ fillType: 'gradient';
77
+ stops: GradientStop[];
78
+ /** degrees: 0 = left→right, 90 = top→bottom */
79
+ angle: number;
80
+ /** 'linear' | 'radial' */
81
+ gradType: string;
82
+ }
83
+
84
+ declare interface GradientStop {
85
+ position: number;
86
+ color: string;
87
+ }
88
+
89
+ export declare interface LineBreak {
90
+ type: 'break';
91
+ }
92
+
93
+ export declare interface NoFill {
94
+ fillType: 'none';
95
+ }
96
+
97
+ export declare interface Paragraph {
98
+ /** Alignment: "l" | "ctr" | "r" | "just" */
99
+ alignment: string;
100
+ /** Left margin in EMU */
101
+ marL: number;
102
+ /** Right margin in EMU */
103
+ marR: number;
104
+ /** First-line indent in EMU (negative = hanging indent) */
105
+ indent: number;
106
+ spaceBefore: number | null;
107
+ spaceAfter: number | null;
108
+ spaceLine: SpaceLine | null;
109
+ /** List nesting level (0–8) */
110
+ lvl: number;
111
+ bullet: Bullet;
112
+ defFontSize: number | null;
113
+ defColor: string | null;
114
+ defBold: boolean | null;
115
+ defItalic: boolean | null;
116
+ defFontFamily: string | null;
117
+ /** Tab stops from pPr > tabLst */
118
+ tabStops: TabStop[];
119
+ runs: TextRun[];
120
+ }
121
+
122
+ declare type PathCmd = {
123
+ cmd: 'moveTo';
124
+ x: number;
125
+ y: number;
126
+ } | {
127
+ cmd: 'lineTo';
128
+ x: number;
129
+ y: number;
130
+ } | {
131
+ cmd: 'cubicBezTo';
132
+ x1: number;
133
+ y1: number;
134
+ x2: number;
135
+ y2: number;
136
+ x: number;
137
+ y: number;
138
+ } | {
139
+ cmd: 'arcTo';
140
+ wr: number;
141
+ hr: number;
142
+ stAng: number;
143
+ swAng: number;
144
+ } | {
145
+ cmd: 'close';
146
+ };
147
+
148
+ export declare interface PictureElement {
149
+ type: 'picture';
150
+ x: number;
151
+ y: number;
152
+ width: number;
153
+ height: number;
154
+ rotation: number;
155
+ flipH: boolean;
156
+ flipV: boolean;
157
+ /** Data URL, e.g. "data:image/png;base64,..." */
158
+ dataUrl: string;
159
+ /** OOXML adj value (0–100000) for roundRect clip, null = plain rectangle */
160
+ clipAdjust: number | null;
161
+ /**
162
+ * ECMA-376 a:srcRect — source image crop as fractions (0..1) of the source
163
+ * width/height. Omitted when the image is not cropped.
164
+ */
165
+ srcRect?: {
166
+ l?: number;
167
+ t?: number;
168
+ r?: number;
169
+ b?: number;
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Headless PPTX rendering engine.
175
+ *
176
+ * Parses `.pptx` archives in a background worker (WASM) but renders slides
177
+ * synchronously on the main thread, so the canvas shares the document's
178
+ * `FontFaceSet` — avoiding subtle wrap differences between system fallback
179
+ * fonts and theme-declared webfonts (e.g. Nunito Sans).
180
+ *
181
+ * Construct via the static `load` factory. A single instance can drive any
182
+ * number of canvases (scroll view, thumbnail grid, master-detail, etc.).
183
+ *
184
+ * @example
185
+ * const pres = await PptxPresentation.load(buffer);
186
+ * await pres.renderSlide(canvas, 0, { width: 960 });
187
+ */
188
+ export declare class PptxPresentation {
189
+ private readonly _worker;
190
+ private _presentation;
191
+ private _pendingParseCallbacks;
192
+ private _nextId;
193
+ private _workerReady;
194
+ private _workerReadyCallbacks;
195
+ private constructor();
196
+ /** Parse a PPTX from URL or ArrayBuffer. */
197
+ static load(source: string | ArrayBuffer): Promise<PptxPresentation>;
198
+ private _waitForWorker;
199
+ private _parse;
200
+ /** Total number of slides in the loaded presentation. */
201
+ get slideCount(): number;
202
+ /** Slide width in EMU. */
203
+ get slideWidth(): number;
204
+ /** Slide height in EMU. */
205
+ get slideHeight(): number;
206
+ /** Render a slide onto the given canvas. */
207
+ renderSlide(canvas: HTMLCanvasElement, slideIndex: number, opts?: RenderSlideOptions): Promise<void>;
208
+ /** Terminate the worker and release all resources. */
209
+ destroy(): void;
210
+ }
211
+
212
+ /**
213
+ * Opinionated single-canvas PPTX viewer.
214
+ *
215
+ * Creates a <canvas> element, appends it to the provided container, and manages
216
+ * slide navigation.
217
+ *
218
+ * For custom layouts (multi-canvas, thumbnails, scroll view) use PptxPresentation directly.
219
+ */
220
+ export declare class PptxViewer {
221
+ private readonly canvas;
222
+ private engine;
223
+ private readonly opts;
224
+ private currentSlide;
225
+ constructor(container: HTMLElement, opts?: PptxViewerOptions);
226
+ /** Load a PPTX from URL or ArrayBuffer and render the first slide. */
227
+ load(source: string | ArrayBuffer): Promise<void>;
228
+ /** Navigate to a specific slide (0-indexed). */
229
+ goToSlide(index: number): Promise<void>;
230
+ nextSlide(): Promise<void>;
231
+ prevSlide(): Promise<void>;
232
+ get slideIndex(): number;
233
+ get slideCount(): number;
234
+ /** The underlying <canvas> element. */
235
+ get canvasElement(): HTMLCanvasElement;
236
+ private renderCurrentSlide;
237
+ /** Clean up the viewer and terminate the background worker. */
238
+ destroy(): void;
239
+ }
240
+
241
+ export declare interface PptxViewerOptions extends RenderOptions {
242
+ /** Called when a slide finishes rendering */
243
+ onSlideChange?: (index: number, total: number) => void;
244
+ /** Called on parse or render errors */
245
+ onError?: (err: Error) => void;
246
+ }
247
+
248
+ export declare interface Presentation {
249
+ slideWidth: number;
250
+ slideHeight: number;
251
+ slides: Slide[];
252
+ /** Theme dk1 color (e.g. "383838"). Used as fallback text color when no explicit color is set. */
253
+ defaultTextColor: string | null;
254
+ /** Theme major (heading) font family name (e.g. "Aptos Display", "Nunito Sans"). Null if not set. */
255
+ majorFont: string | null;
256
+ /** Theme minor (body) font family name (e.g. "Aptos", "Nunito Sans"). Null if not set. */
257
+ minorFont: string | null;
258
+ }
259
+
260
+ export declare interface RenderOptions {
261
+ width?: number;
262
+ defaultTextColor?: string | null;
263
+ dpr?: number;
264
+ majorFont?: string | null;
265
+ minorFont?: string | null;
266
+ }
267
+
268
+ /**
269
+ * Render a single slide onto a <canvas> element.
270
+ * Returns the canvas for convenience.
271
+ */
272
+ export declare function renderSlide(canvas: HTMLCanvasElement | OffscreenCanvas, slide: Slide, slideWidth: number, slideHeight: number, opts?: RenderOptions): Promise<HTMLCanvasElement | OffscreenCanvas>;
273
+
274
+ /** Options for rendering a single slide onto a canvas. */
275
+ export declare interface RenderSlideOptions {
276
+ /** Display width in CSS pixels. Defaults to canvas.offsetWidth or 960. */
277
+ width?: number;
278
+ /** Device pixel ratio. Defaults to window.devicePixelRatio or 1. */
279
+ dpr?: number;
280
+ }
281
+
282
+ declare interface Shadow {
283
+ color: string;
284
+ alpha: number;
285
+ blur: number;
286
+ dist: number;
287
+ /** degrees clockwise from East */
288
+ dir: number;
289
+ }
290
+
291
+ export declare interface ShapeElement {
292
+ type: 'shape';
293
+ x: number;
294
+ y: number;
295
+ width: number;
296
+ height: number;
297
+ /** Rotation in degrees, clockwise */
298
+ rotation: number;
299
+ /** Horizontal mirror (a:xfrm flipH) */
300
+ flipH: boolean;
301
+ /** Vertical mirror (a:xfrm flipV) */
302
+ flipV: boolean;
303
+ /** OOXML preset name or "custGeom" when custom paths are used */
304
+ geometry: string;
305
+ fill: Fill | null;
306
+ stroke: Stroke | null;
307
+ textBody: TextBody | null;
308
+ /** Default text color from p:style > fontRef (hex). Used when run/para has no explicit color. */
309
+ defaultTextColor: string | null;
310
+ /** Custom geometry sub-paths (set only when geometry === "custGeom").
311
+ * Outer array: one entry per <a:path>; inner: path commands with coords in [0,1]. */
312
+ custGeom: PathCmd[][] | null;
313
+ /** First adjustment value from prstGeom avLst (e.g. trapezoid inset). Range 0–100000. */
314
+ adj: number | null;
315
+ /** Second adjustment value from prstGeom avLst (e.g. arrow head width). Range 0–100000. */
316
+ adj2: number | null;
317
+ /** Third adjustment value from prstGeom avLst (e.g. callout tip x). Range 0–100000. */
318
+ adj3: number | null;
319
+ /** Fourth adjustment value from prstGeom avLst (e.g. callout tip y). Range 0–100000. */
320
+ adj4: number | null;
321
+ /** Drop shadow from effectLst > outerShdw (null if not present). */
322
+ shadow: Shadow | null;
323
+ }
324
+
325
+ export declare interface Slide {
326
+ index: number;
327
+ /** 1-based slide number (index + 1); used to render slidenum fields */
328
+ slideNumber: number;
329
+ background: Fill | null;
330
+ elements: SlideElement[];
331
+ }
332
+
333
+ export declare type SlideElement = ShapeElement | PictureElement | TableElement | ChartElement;
334
+
335
+ export declare interface SolidFill {
336
+ fillType: 'solid';
337
+ color: string;
338
+ }
339
+
340
+ declare type SpaceLine = {
341
+ type: 'pct';
342
+ val: number;
343
+ } | {
344
+ type: 'pts';
345
+ val: number;
346
+ };
347
+
348
+ export declare interface Stroke {
349
+ color: string;
350
+ /** Width in EMU */
351
+ width: number;
352
+ /** OOXML prstDash value: "dash", "dot", "dashDot", "lgDash", "lgDashDot", etc. */
353
+ dashStyle?: string;
354
+ /** Arrow head at the start of the line */
355
+ headEnd?: ArrowEnd;
356
+ /** Arrow head at the end of the line */
357
+ tailEnd?: ArrowEnd;
358
+ }
359
+
360
+ declare interface TableCell {
361
+ textBody: TextBody | null;
362
+ fill: Fill | null;
363
+ borderL: Stroke | null;
364
+ borderR: Stroke | null;
365
+ borderT: Stroke | null;
366
+ borderB: Stroke | null;
367
+ /** Diagonal from top-left to bottom-right */
368
+ diagonalTL?: Stroke | null;
369
+ /** Diagonal from top-right to bottom-left */
370
+ diagonalTR?: Stroke | null;
371
+ /** Column span */
372
+ gridSpan: number;
373
+ /** Row span */
374
+ rowSpan: number;
375
+ /** Horizontal merge continuation */
376
+ hMerge: boolean;
377
+ /** Vertical merge continuation */
378
+ vMerge: boolean;
379
+ }
380
+
381
+ declare interface TableElement {
382
+ type: 'table';
383
+ x: number;
384
+ y: number;
385
+ width: number;
386
+ height: number;
387
+ /** Column widths in EMU */
388
+ cols: number[];
389
+ rows: TableRow[];
390
+ }
391
+
392
+ declare interface TableRow {
393
+ /** Row height in EMU */
394
+ height: number;
395
+ cells: TableCell[];
396
+ }
397
+
398
+ declare interface TabStop {
399
+ /** Position in EMU from the left edge of the text area (after lIns) */
400
+ pos: number;
401
+ /** Alignment: "l" | "r" | "ctr" | "dec" */
402
+ algn: string;
403
+ }
404
+
405
+ export declare interface TextBody {
406
+ /** Vertical anchor: "t" | "ctr" | "b" */
407
+ verticalAnchor: string;
408
+ paragraphs: Paragraph[];
409
+ /** Default pt size from lstStyle (overrides renderer default when present) */
410
+ defaultFontSize: number | null;
411
+ /** Inherited bold from layout/master defRPr (null = not set, use false as final default) */
412
+ defaultBold: boolean | null;
413
+ /** Inherited italic from layout/master defRPr (null = not set, use false as final default) */
414
+ defaultItalic: boolean | null;
415
+ /** Text insets in EMU (defaults: lIns=rIns=91440, tIns=bIns=45720) */
416
+ lIns: number;
417
+ rIns: number;
418
+ tIns: number;
419
+ bIns: number;
420
+ /** "square" = wrap, "none" = no wrap */
421
+ wrap: string;
422
+ /** Text direction: "horz" | "vert" | "vert270" | "eaVert" etc. */
423
+ vert: string;
424
+ /** Auto-fit: "sp" = shape grows to fit text, "norm" = font shrinks, "none" = no fit */
425
+ autoFit: string;
426
+ }
427
+
428
+ export declare type TextRun = TextRunData | LineBreak;
429
+
430
+ export declare interface TextRunData {
431
+ type: 'text';
432
+ text: string;
433
+ /** null = not set, inherit from paragraph/body defaults */
434
+ bold: boolean | null;
435
+ /** null = not set, inherit from paragraph/body defaults */
436
+ italic: boolean | null;
437
+ underline: boolean;
438
+ /** true when rPr strike = "sngStrike" or "dblStrike" */
439
+ strikethrough: boolean;
440
+ /** Font size in points */
441
+ fontSize: number | null;
442
+ color: string | null;
443
+ fontFamily: string | null;
444
+ /** Baseline shift in thousandths of a point. Positive = superscript, negative = subscript. */
445
+ baseline?: number;
446
+ /** Set for OOXML field runs (e.g. "slidenum"). When set, renderer replaces text with field value. */
447
+ fieldType?: string;
448
+ }
449
+
450
+ export { }