pptx-vanilla-viewer 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.
- package/CHANGELOG.md +3 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +104 -0
- package/dist/index.cjs +422 -0
- package/dist/index.d.cts +1766 -0
- package/dist/index.d.ts +1766 -0
- package/dist/index.js +422 -0
- package/package.json +72 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
import { n, o, m, l, P, d, e, X, p, q, r, s, t, u, v, w, x, y, z, A, B, D, E, F, G, H, J, K, L, h, i, k, j, f, g } from './presentation-CLc4eS3z.js';
|
|
2
|
+
export { P as PptxElement, l as PptxSlide } from './presentation-CLc4eS3z.js';
|
|
3
|
+
import { ViewerTheme } from './theme/index.js';
|
|
4
|
+
export { ViewerTheme, ViewerThemeColors, defaultCssVars, defaultRadius, defaultThemeColors, themeToCssVars, vermilionDarkTheme, vermilionLightTheme } from './theme/index.js';
|
|
5
|
+
export { TranslationKey, keyToLabel, translationsEn } from 'pptx-viewer-shared/i18n';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Built-in theme presets modelled after common PowerPoint themes.
|
|
9
|
+
*
|
|
10
|
+
* Each preset provides:
|
|
11
|
+
* - A display name
|
|
12
|
+
* - A 12-colour scheme (dk1, dk2, lt1, lt2, accent1-6, hlink, folHlink)
|
|
13
|
+
* - A font scheme (major/heading + minor/body font families)
|
|
14
|
+
*
|
|
15
|
+
* These presets can be passed directly to
|
|
16
|
+
* {@link PptxHandlerCore.switchTheme} or the React `useThemeSwitching` hook
|
|
17
|
+
* to apply a complete theme in one step.
|
|
18
|
+
*
|
|
19
|
+
* @module pptx-types/theme-presets
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A complete theme preset that can be applied to a presentation.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { THEME_PRESETS } from "pptx-viewer-core";
|
|
28
|
+
*
|
|
29
|
+
* const office = THEME_PRESETS.find(p => p.id === "office");
|
|
30
|
+
* await handler.switchTheme(office.colorScheme, office.fontScheme, office.name);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
interface PptxThemePreset {
|
|
34
|
+
/** Unique identifier for the preset. */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Human-readable display name. */
|
|
37
|
+
name: string;
|
|
38
|
+
/** The 12-colour scheme. */
|
|
39
|
+
colorScheme: d;
|
|
40
|
+
/** Heading and body font families. */
|
|
41
|
+
fontScheme: e;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* SDK input types for the headless PPTX builder API.
|
|
46
|
+
*
|
|
47
|
+
* These types provide a simplified, ergonomic interface for creating
|
|
48
|
+
* presentation elements programmatically. Internal types (PptxElement,
|
|
49
|
+
* ShapeStyle, TextStyle) are the canonical model; these types are
|
|
50
|
+
* convenience wrappers that get mapped to the internal model by
|
|
51
|
+
* the builder functions.
|
|
52
|
+
*
|
|
53
|
+
* @module sdk/types
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/** Position and size in pixels. Converted to EMU internally when needed. */
|
|
57
|
+
interface ElementPosition {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
rotation?: number;
|
|
63
|
+
}
|
|
64
|
+
type FillInput = {
|
|
65
|
+
type: 'solid';
|
|
66
|
+
color: string;
|
|
67
|
+
opacity?: number;
|
|
68
|
+
} | {
|
|
69
|
+
type: 'gradient';
|
|
70
|
+
angle?: number;
|
|
71
|
+
gradientType?: 'linear' | 'radial';
|
|
72
|
+
stops: Array<{
|
|
73
|
+
color: string;
|
|
74
|
+
position: number;
|
|
75
|
+
opacity?: number;
|
|
76
|
+
}>;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'pattern';
|
|
79
|
+
preset: string;
|
|
80
|
+
foreground?: string;
|
|
81
|
+
background?: string;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'image';
|
|
84
|
+
url: string;
|
|
85
|
+
mode?: 'stretch' | 'tile';
|
|
86
|
+
} | {
|
|
87
|
+
type: 'none';
|
|
88
|
+
};
|
|
89
|
+
interface StrokeInput {
|
|
90
|
+
color?: string;
|
|
91
|
+
width?: number;
|
|
92
|
+
dash?: h;
|
|
93
|
+
opacity?: number;
|
|
94
|
+
join?: 'round' | 'bevel' | 'miter';
|
|
95
|
+
cap?: 'flat' | 'rnd' | 'sq';
|
|
96
|
+
}
|
|
97
|
+
interface ShadowInput {
|
|
98
|
+
color?: string;
|
|
99
|
+
blur?: number;
|
|
100
|
+
offsetX?: number;
|
|
101
|
+
offsetY?: number;
|
|
102
|
+
opacity?: number;
|
|
103
|
+
}
|
|
104
|
+
interface TextStyleInput {
|
|
105
|
+
fontSize?: number;
|
|
106
|
+
fontFamily?: string;
|
|
107
|
+
bold?: boolean;
|
|
108
|
+
italic?: boolean;
|
|
109
|
+
underline?: boolean;
|
|
110
|
+
strikethrough?: boolean;
|
|
111
|
+
color?: string;
|
|
112
|
+
alignment?: 'left' | 'center' | 'right' | 'justify';
|
|
113
|
+
verticalAlignment?: 'top' | 'middle' | 'bottom';
|
|
114
|
+
lineSpacing?: number;
|
|
115
|
+
spaceBefore?: number;
|
|
116
|
+
spaceAfter?: number;
|
|
117
|
+
}
|
|
118
|
+
interface TextSegmentInput {
|
|
119
|
+
text: string;
|
|
120
|
+
style?: Partial<TextStyleInput>;
|
|
121
|
+
}
|
|
122
|
+
interface TextOptions extends Partial<ElementPosition> {
|
|
123
|
+
fontSize?: number;
|
|
124
|
+
fontFamily?: string;
|
|
125
|
+
bold?: boolean;
|
|
126
|
+
italic?: boolean;
|
|
127
|
+
underline?: boolean;
|
|
128
|
+
strikethrough?: boolean;
|
|
129
|
+
color?: string;
|
|
130
|
+
alignment?: 'left' | 'center' | 'right' | 'justify';
|
|
131
|
+
verticalAlignment?: 'top' | 'middle' | 'bottom';
|
|
132
|
+
lineSpacing?: number;
|
|
133
|
+
fill?: FillInput;
|
|
134
|
+
stroke?: StrokeInput;
|
|
135
|
+
shadow?: ShadowInput;
|
|
136
|
+
opacity?: number;
|
|
137
|
+
}
|
|
138
|
+
interface ShapeOptions extends Partial<ElementPosition> {
|
|
139
|
+
fill?: FillInput;
|
|
140
|
+
stroke?: StrokeInput;
|
|
141
|
+
text?: string;
|
|
142
|
+
textStyle?: Partial<TextStyleInput>;
|
|
143
|
+
adjustments?: Record<string, number>;
|
|
144
|
+
shadow?: ShadowInput;
|
|
145
|
+
opacity?: number;
|
|
146
|
+
}
|
|
147
|
+
interface ImageOptions extends Partial<ElementPosition> {
|
|
148
|
+
altText?: string;
|
|
149
|
+
cropLeft?: number;
|
|
150
|
+
cropTop?: number;
|
|
151
|
+
cropRight?: number;
|
|
152
|
+
cropBottom?: number;
|
|
153
|
+
opacity?: number;
|
|
154
|
+
}
|
|
155
|
+
interface TableInput {
|
|
156
|
+
rows: TableRowInput[];
|
|
157
|
+
columnWidths?: number[];
|
|
158
|
+
style?: string;
|
|
159
|
+
bandRows?: boolean;
|
|
160
|
+
bandColumns?: boolean;
|
|
161
|
+
firstRow?: boolean;
|
|
162
|
+
lastRow?: boolean;
|
|
163
|
+
firstCol?: boolean;
|
|
164
|
+
lastCol?: boolean;
|
|
165
|
+
}
|
|
166
|
+
interface TableRowInput {
|
|
167
|
+
cells: TableCellInput[];
|
|
168
|
+
height?: number;
|
|
169
|
+
}
|
|
170
|
+
interface TableCellInput {
|
|
171
|
+
text: string;
|
|
172
|
+
style?: Partial<TextStyleInput>;
|
|
173
|
+
fill?: FillInput;
|
|
174
|
+
gridSpan?: number;
|
|
175
|
+
rowSpan?: number;
|
|
176
|
+
}
|
|
177
|
+
interface TableOptions extends Partial<ElementPosition> {
|
|
178
|
+
}
|
|
179
|
+
interface ChartSeriesInput {
|
|
180
|
+
name: string;
|
|
181
|
+
values: number[];
|
|
182
|
+
color?: string;
|
|
183
|
+
}
|
|
184
|
+
interface ChartInput {
|
|
185
|
+
series: ChartSeriesInput[];
|
|
186
|
+
categories: string[];
|
|
187
|
+
title?: string;
|
|
188
|
+
hasLegend?: boolean;
|
|
189
|
+
legendPosition?: 't' | 'b' | 'l' | 'r' | 'tr';
|
|
190
|
+
grouping?: 'clustered' | 'stacked' | 'percentStacked';
|
|
191
|
+
}
|
|
192
|
+
interface ChartOptions extends Partial<ElementPosition> {
|
|
193
|
+
}
|
|
194
|
+
interface ConnectorOptions extends Partial<ElementPosition> {
|
|
195
|
+
type?: 'straight' | 'bent' | 'curved';
|
|
196
|
+
stroke?: StrokeInput;
|
|
197
|
+
startArrow?: i;
|
|
198
|
+
endArrow?: i;
|
|
199
|
+
from?: {
|
|
200
|
+
elementId: string;
|
|
201
|
+
site: number;
|
|
202
|
+
};
|
|
203
|
+
to?: {
|
|
204
|
+
elementId: string;
|
|
205
|
+
site: number;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
interface MediaOptions extends Partial<ElementPosition> {
|
|
209
|
+
autoPlay?: boolean;
|
|
210
|
+
loop?: boolean;
|
|
211
|
+
volume?: number;
|
|
212
|
+
trimStartMs?: number;
|
|
213
|
+
trimEndMs?: number;
|
|
214
|
+
posterFrame?: string;
|
|
215
|
+
}
|
|
216
|
+
interface GroupOptions extends Partial<ElementPosition> {
|
|
217
|
+
}
|
|
218
|
+
type BackgroundInput = {
|
|
219
|
+
type: 'solid';
|
|
220
|
+
color: string;
|
|
221
|
+
} | {
|
|
222
|
+
type: 'gradient';
|
|
223
|
+
angle?: number;
|
|
224
|
+
stops: Array<{
|
|
225
|
+
color: string;
|
|
226
|
+
position: number;
|
|
227
|
+
}>;
|
|
228
|
+
} | {
|
|
229
|
+
type: 'image';
|
|
230
|
+
source: string;
|
|
231
|
+
};
|
|
232
|
+
interface TransitionInput {
|
|
233
|
+
type: j;
|
|
234
|
+
duration?: number;
|
|
235
|
+
direction?: string;
|
|
236
|
+
advanceAfterMs?: number;
|
|
237
|
+
}
|
|
238
|
+
interface AnimationInput {
|
|
239
|
+
preset: f;
|
|
240
|
+
trigger?: g;
|
|
241
|
+
duration?: number;
|
|
242
|
+
delay?: number;
|
|
243
|
+
}
|
|
244
|
+
interface PresentationOptions {
|
|
245
|
+
/** Slide width in EMU. Default: 12192000 (16:9 widescreen). */
|
|
246
|
+
width?: number;
|
|
247
|
+
/** Slide height in EMU. Default: 6858000 (16:9 widescreen). */
|
|
248
|
+
height?: number;
|
|
249
|
+
/** Theme configuration. */
|
|
250
|
+
theme?: PresentationThemeInput;
|
|
251
|
+
/** Presentation title (stored in docProps/core.xml). */
|
|
252
|
+
title?: string;
|
|
253
|
+
/** Presentation author. */
|
|
254
|
+
creator?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Number of blank slides to include in the initial presentation.
|
|
257
|
+
* Default: 0 (no slides). Slides use the "Blank" layout.
|
|
258
|
+
*/
|
|
259
|
+
initialSlideCount?: number;
|
|
260
|
+
}
|
|
261
|
+
interface PresentationThemeInput {
|
|
262
|
+
name?: string;
|
|
263
|
+
colors?: {
|
|
264
|
+
dk1?: string;
|
|
265
|
+
lt1?: string;
|
|
266
|
+
dk2?: string;
|
|
267
|
+
lt2?: string;
|
|
268
|
+
accent1?: string;
|
|
269
|
+
accent2?: string;
|
|
270
|
+
accent3?: string;
|
|
271
|
+
accent4?: string;
|
|
272
|
+
accent5?: string;
|
|
273
|
+
accent6?: string;
|
|
274
|
+
hlink?: string;
|
|
275
|
+
folHlink?: string;
|
|
276
|
+
};
|
|
277
|
+
fonts?: {
|
|
278
|
+
majorFont?: string;
|
|
279
|
+
minorFont?: string;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Fluent builder for constructing slides with elements.
|
|
285
|
+
*
|
|
286
|
+
* Provides a chainable API for adding elements, setting slide properties,
|
|
287
|
+
* and building a complete {@link PptxSlide}.
|
|
288
|
+
*
|
|
289
|
+
* @module sdk/SlideBuilder
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Fluent builder for a single slide.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* const slide = new SlideBuilder(1)
|
|
298
|
+
* .addText("Hello World", { fontSize: 36, bold: true, x: 100, y: 50 })
|
|
299
|
+
* .addShape("roundRect", { fill: { type: "solid", color: "#4472C4" } })
|
|
300
|
+
* .setNotes("Remember to mention key points")
|
|
301
|
+
* .setBackground({ type: "solid", color: "#F5F5F5" })
|
|
302
|
+
* .build();
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare class SlideBuilder {
|
|
306
|
+
private readonly slide;
|
|
307
|
+
/**
|
|
308
|
+
* @param slideNumber - 1-based slide number.
|
|
309
|
+
* @param layoutPath - Optional layout archive path.
|
|
310
|
+
* @param layoutName - Optional layout display name.
|
|
311
|
+
*/
|
|
312
|
+
constructor(slideNumber: number, layoutPath?: string, layoutName?: string);
|
|
313
|
+
/** Add a text box to the slide. */
|
|
314
|
+
addText(text: string | TextSegmentInput[], options?: TextOptions): this;
|
|
315
|
+
/** Add a shape to the slide. */
|
|
316
|
+
addShape(shapeType: string, options?: ShapeOptions): this;
|
|
317
|
+
/** Add a connector (line) to the slide. */
|
|
318
|
+
addConnector(options?: ConnectorOptions): this;
|
|
319
|
+
/** Add an image to the slide. */
|
|
320
|
+
addImage(source: string, options?: ImageOptions): this;
|
|
321
|
+
/** Add a table to the slide. */
|
|
322
|
+
addTable(input: TableInput, options?: TableOptions): this;
|
|
323
|
+
/** Add a chart to the slide. */
|
|
324
|
+
addChart(chartType: k, input: ChartInput, options?: ChartOptions): this;
|
|
325
|
+
/** Add a media element (video or audio) to the slide. */
|
|
326
|
+
addMedia(mediaType: 'video' | 'audio', source: string, options?: MediaOptions): this;
|
|
327
|
+
/** Add a group of elements to the slide. */
|
|
328
|
+
addGroup(children: P[], options?: GroupOptions): this;
|
|
329
|
+
/** Add a pre-built element directly. */
|
|
330
|
+
addElement(element: P): this;
|
|
331
|
+
/** Set slide background. */
|
|
332
|
+
setBackground(bg: BackgroundInput): this;
|
|
333
|
+
/** Set slide transition. */
|
|
334
|
+
setTransition(input: TransitionInput): this;
|
|
335
|
+
/** Add an animation to an element on this slide. */
|
|
336
|
+
addAnimation(elementId: string, input: AnimationInput): this;
|
|
337
|
+
/** Set speaker notes. */
|
|
338
|
+
setNotes(text: string): this;
|
|
339
|
+
/** Mark the slide as hidden. */
|
|
340
|
+
setHidden(hidden: boolean): this;
|
|
341
|
+
/** Assign the slide to a section. */
|
|
342
|
+
setSection(name: string, id?: string): this;
|
|
343
|
+
/**
|
|
344
|
+
* Add a freeform shape from SVG path data.
|
|
345
|
+
*
|
|
346
|
+
* Creates a custom-geometry shape element using the provided SVG path
|
|
347
|
+
* string and appends it to the slide's element list.
|
|
348
|
+
*
|
|
349
|
+
* @param pathData - An SVG path data string (e.g. `"M 0 0 L 100 50 L 50 100 Z"`).
|
|
350
|
+
* @param options - Optional position, styling, and size overrides.
|
|
351
|
+
* @returns The builder instance for chaining.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* new SlideBuilder(1)
|
|
356
|
+
* .addFreeform("M 0 0 C 33 0 66 100 100 100", {
|
|
357
|
+
* stroke: { color: "#FF0000", width: 2 },
|
|
358
|
+
* })
|
|
359
|
+
* .build();
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
addFreeform(pathData: string, options?: ShapeOptions): this;
|
|
363
|
+
/**
|
|
364
|
+
* Add a pre-built element from any element builder (calls `.build()` for you).
|
|
365
|
+
*
|
|
366
|
+
* Accepts any object with a `build()` method that returns a {@link PptxElement},
|
|
367
|
+
* such as {@link TextBuilder}, {@link ShapeBuilder}, {@link ImageBuilder}, etc.
|
|
368
|
+
*
|
|
369
|
+
* @param builder - An element builder with a `.build()` method.
|
|
370
|
+
* @returns The builder instance for chaining.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* const title = TextBuilder.create("Hello").fontSize(36).bold();
|
|
375
|
+
* new SlideBuilder(1).addBuilderElement(title).build();
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
addBuilderElement(builder: {
|
|
379
|
+
build(): P;
|
|
380
|
+
}): this;
|
|
381
|
+
/**
|
|
382
|
+
* Remove an element by its ID.
|
|
383
|
+
*
|
|
384
|
+
* Filters out the element with the given ID from the slide's element list.
|
|
385
|
+
* If no element matches, the slide is left unchanged.
|
|
386
|
+
*
|
|
387
|
+
* @param elementId - The unique ID of the element to remove.
|
|
388
|
+
* @returns The builder instance for chaining.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* const slide = new SlideBuilder(1)
|
|
393
|
+
* .addText("temp", { x: 0, y: 0 })
|
|
394
|
+
* .removeElement("txt_abc123_1")
|
|
395
|
+
* .build();
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
removeElement(elementId: string): this;
|
|
399
|
+
/**
|
|
400
|
+
* Get the current list of elements on this slide.
|
|
401
|
+
*
|
|
402
|
+
* Returns a readonly view of the elements array. Useful for inspecting
|
|
403
|
+
* what has been added so far during the build process.
|
|
404
|
+
*
|
|
405
|
+
* @returns A readonly array of the slide's current elements.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* const builder = new SlideBuilder(1).addText("Hi");
|
|
410
|
+
* console.log(builder.getElements().length); // 1
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
getElements(): readonly P[];
|
|
414
|
+
/**
|
|
415
|
+
* Get the number of elements on this slide.
|
|
416
|
+
*
|
|
417
|
+
* @returns The count of elements currently added to the slide.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* const builder = new SlideBuilder(1)
|
|
422
|
+
* .addText("A").addText("B");
|
|
423
|
+
* console.log(builder.elementCount); // 2
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
get elementCount(): number;
|
|
427
|
+
/**
|
|
428
|
+
* Get the last added element (useful for getting its ID for animations).
|
|
429
|
+
*
|
|
430
|
+
* Returns `undefined` if the slide has no elements yet.
|
|
431
|
+
*
|
|
432
|
+
* @returns The most recently added element, or `undefined`.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* const builder = new SlideBuilder(1).addShape("rect");
|
|
437
|
+
* const shape = builder.getLastElement();
|
|
438
|
+
* if (shape) {
|
|
439
|
+
* builder.addAnimation(shape.id, { preset: "fadeIn" });
|
|
440
|
+
* }
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
getLastElement(): P | undefined;
|
|
444
|
+
/**
|
|
445
|
+
* Set the slide name/title for organizational purposes.
|
|
446
|
+
*
|
|
447
|
+
* Stores an arbitrary name string on the slide object. This is useful
|
|
448
|
+
* for labeling slides in tooling or custom workflows.
|
|
449
|
+
*
|
|
450
|
+
* @param name - The display name to assign to the slide.
|
|
451
|
+
* @returns The builder instance for chaining.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* new SlideBuilder(1)
|
|
456
|
+
* .setName("Introduction")
|
|
457
|
+
* .addText("Welcome!")
|
|
458
|
+
* .build();
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
setName(name: string): this;
|
|
462
|
+
/** Return the built {@link PptxSlide}. */
|
|
463
|
+
build(): l;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Factory for creating PPTX presentations from scratch.
|
|
468
|
+
*
|
|
469
|
+
* Generates a minimal valid OpenXML package (ZIP) containing all
|
|
470
|
+
* required parts (presentation.xml, theme, slide master, layouts,
|
|
471
|
+
* content types, relationships, and document properties). The
|
|
472
|
+
* generated package is then loaded by {@link PptxHandler} so that
|
|
473
|
+
* all existing editing and save operations work transparently.
|
|
474
|
+
*
|
|
475
|
+
* @module sdk/PresentationBuilder
|
|
476
|
+
*/
|
|
477
|
+
|
|
478
|
+
/** Result returned by {@link PresentationBuilder.create}. */
|
|
479
|
+
interface PresentationBuilderResult {
|
|
480
|
+
/** Initialized handler ready for editing and saving. */
|
|
481
|
+
handler: PptxHandler;
|
|
482
|
+
/** Parsed presentation data. */
|
|
483
|
+
data: m;
|
|
484
|
+
/** Convenience slide builder factory. */
|
|
485
|
+
createSlide: (layoutName?: string) => SlideBuilder;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Fluent interface for navigating and mutating a {@link PptxData} structure.
|
|
490
|
+
* Provides method-chaining access to slides, elements, and notes.
|
|
491
|
+
*/
|
|
492
|
+
interface IPptxXmlBuilder {
|
|
493
|
+
/** Navigate to a slide by zero-based index (Pascal-case alias). */
|
|
494
|
+
Slides(index: number): PptxSlideBuilder;
|
|
495
|
+
/** Navigate to a slide by zero-based index. */
|
|
496
|
+
slide(index: number): PptxSlideBuilder;
|
|
497
|
+
/** Navigate to a slide by zero-based index (plural alias). */
|
|
498
|
+
slides(index: number): PptxSlideBuilder;
|
|
499
|
+
/** Return the underlying presentation data. */
|
|
500
|
+
project(): m;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Root builder of the fluent PPTX editing API.
|
|
504
|
+
*
|
|
505
|
+
* Wraps a {@link PptxData} object and provides chainable accessors
|
|
506
|
+
* to navigate into slides, elements, and notes for in-place mutation.
|
|
507
|
+
*/
|
|
508
|
+
declare class PptxXmlBuilder implements IPptxXmlBuilder {
|
|
509
|
+
/** The presentation data being mutated. */
|
|
510
|
+
private readonly data;
|
|
511
|
+
/** @param data - The presentation data to wrap. */
|
|
512
|
+
constructor(data: m);
|
|
513
|
+
/**
|
|
514
|
+
* Factory method to create a builder from presentation data.
|
|
515
|
+
* @param data - The presentation data to wrap.
|
|
516
|
+
* @returns A new {@link PptxXmlBuilder} instance.
|
|
517
|
+
*/
|
|
518
|
+
static from(data: m): PptxXmlBuilder;
|
|
519
|
+
/** @inheritdoc */
|
|
520
|
+
Slides(index: number): PptxSlideBuilder;
|
|
521
|
+
/**
|
|
522
|
+
* Navigate to a slide by zero-based index.
|
|
523
|
+
* @param index - Zero-based slide index.
|
|
524
|
+
* @returns A {@link PptxSlideBuilder} for the requested slide.
|
|
525
|
+
* @throws Error if index is not an integer or is out of range.
|
|
526
|
+
*/
|
|
527
|
+
slide(index: number): PptxSlideBuilder;
|
|
528
|
+
/** @inheritdoc */
|
|
529
|
+
slides(index: number): PptxSlideBuilder;
|
|
530
|
+
/** Return the underlying {@link PptxData}. */
|
|
531
|
+
project(): m;
|
|
532
|
+
/** Pascal-case alias for {@link project}. */
|
|
533
|
+
Project(): m;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Fluent builder scoped to a single slide.
|
|
537
|
+
* Provides navigation to the slide's elements and notes.
|
|
538
|
+
*/
|
|
539
|
+
declare class PptxSlideBuilder {
|
|
540
|
+
/** The slide being operated on. */
|
|
541
|
+
private readonly slideValue;
|
|
542
|
+
/** Reference back to the root builder for chaining. */
|
|
543
|
+
private readonly rootBuilder;
|
|
544
|
+
/**
|
|
545
|
+
* @param slideValue - The slide data.
|
|
546
|
+
* @param rootBuilder - The parent builder.
|
|
547
|
+
*/
|
|
548
|
+
constructor(slideValue: l, rootBuilder: PptxXmlBuilder);
|
|
549
|
+
/** Navigate to the slide's notes builder (getter). */
|
|
550
|
+
get Notes(): PptxSlideNotesBuilder;
|
|
551
|
+
/** Navigate to the slide's notes builder. */
|
|
552
|
+
notes(): PptxSlideNotesBuilder;
|
|
553
|
+
/** Navigate to the slide's elements builder. */
|
|
554
|
+
elements(): PptxSlideElementsBuilder;
|
|
555
|
+
/** Return the underlying slide data. */
|
|
556
|
+
project(): l;
|
|
557
|
+
/** Pascal-case alias for {@link project}. */
|
|
558
|
+
Project(): l;
|
|
559
|
+
/** Navigate back to the root builder. */
|
|
560
|
+
done(): PptxXmlBuilder;
|
|
561
|
+
/** Pascal-case alias for {@link done}. */
|
|
562
|
+
Done(): PptxXmlBuilder;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Fluent builder for manipulating the elements array of a single slide.
|
|
566
|
+
* Supports adding, removing, and updating elements by ID.
|
|
567
|
+
*/
|
|
568
|
+
declare class PptxSlideElementsBuilder {
|
|
569
|
+
private readonly slideValue;
|
|
570
|
+
private readonly slideBuilder;
|
|
571
|
+
/**
|
|
572
|
+
* @param slideValue - The slide whose elements are being modified.
|
|
573
|
+
* @param slideBuilder - The parent slide builder for chaining.
|
|
574
|
+
*/
|
|
575
|
+
constructor(slideValue: l, slideBuilder: PptxSlideBuilder);
|
|
576
|
+
/**
|
|
577
|
+
* Append an element to the slide's element list.
|
|
578
|
+
* @param element - The element to add.
|
|
579
|
+
* @returns This builder for chaining.
|
|
580
|
+
*/
|
|
581
|
+
add(element: P): this;
|
|
582
|
+
/**
|
|
583
|
+
* Remove an element from the slide by its ID.
|
|
584
|
+
* @param elementId - The ID of the element to remove.
|
|
585
|
+
* @returns This builder for chaining.
|
|
586
|
+
*/
|
|
587
|
+
removeById(elementId: string): this;
|
|
588
|
+
/**
|
|
589
|
+
* Update an element in-place by ID using a transform function.
|
|
590
|
+
* @param elementId - The ID of the element to update.
|
|
591
|
+
* @param updater - A function that receives the current element and returns the replacement.
|
|
592
|
+
* @returns This builder for chaining.
|
|
593
|
+
*/
|
|
594
|
+
updateById(elementId: string, updater: (current: P) => P): this;
|
|
595
|
+
/** Return the current elements array. */
|
|
596
|
+
project(): P[];
|
|
597
|
+
/** Navigate back to the slide builder. */
|
|
598
|
+
done(): PptxSlideBuilder;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Fluent builder for manipulating speaker notes on a single slide.
|
|
602
|
+
* Supports adding, setting, clearing, and retrieving notes text.
|
|
603
|
+
*/
|
|
604
|
+
declare class PptxSlideNotesBuilder {
|
|
605
|
+
private readonly slideValue;
|
|
606
|
+
private readonly slideBuilder;
|
|
607
|
+
/**
|
|
608
|
+
* @param slideValue - The slide whose notes are being modified.
|
|
609
|
+
* @param slideBuilder - The parent slide builder for chaining.
|
|
610
|
+
*/
|
|
611
|
+
constructor(slideValue: l, slideBuilder: PptxSlideBuilder);
|
|
612
|
+
/**
|
|
613
|
+
* Append text to existing notes (separated by newline).
|
|
614
|
+
* @param text - The text to append.
|
|
615
|
+
* @returns This builder for chaining.
|
|
616
|
+
*/
|
|
617
|
+
add(text: string): this;
|
|
618
|
+
/** Pascal-case alias for {@link add}. */
|
|
619
|
+
Add(text: string): this;
|
|
620
|
+
/**
|
|
621
|
+
* Replace all notes with the given text.
|
|
622
|
+
* @param text - The replacement notes text. Empty string clears notes.
|
|
623
|
+
* @returns This builder for chaining.
|
|
624
|
+
*/
|
|
625
|
+
set(text: string): this;
|
|
626
|
+
/** Pascal-case alias for {@link set}. */
|
|
627
|
+
Set(text: string): this;
|
|
628
|
+
/** Remove all notes from the slide. */
|
|
629
|
+
clear(): this;
|
|
630
|
+
/** Pascal-case alias for {@link clear}. */
|
|
631
|
+
Clear(): this;
|
|
632
|
+
/** Return the current notes text, or `undefined` if none. */
|
|
633
|
+
get(): string | undefined;
|
|
634
|
+
/** Pascal-case alias for {@link get}. */
|
|
635
|
+
Get(): string | undefined;
|
|
636
|
+
/** Navigate back to the slide builder. */
|
|
637
|
+
done(): PptxSlideBuilder;
|
|
638
|
+
/** Pascal-case alias for {@link done}. */
|
|
639
|
+
Done(): PptxSlideBuilder;
|
|
640
|
+
/**
|
|
641
|
+
* Synchronize the `notesSegments` array from the plain-text notes string.
|
|
642
|
+
* Splits text on newlines and creates corresponding {@link TextSegment} entries
|
|
643
|
+
* with paragraph break markers between lines.
|
|
644
|
+
*/
|
|
645
|
+
private syncSegmentsFromNotes;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
interface PptxHandlerLoadOptions {
|
|
649
|
+
eagerDecodeImages?: boolean;
|
|
650
|
+
password?: string;
|
|
651
|
+
/**
|
|
652
|
+
* Maximum total uncompressed bytes accepted from the input ZIP archive.
|
|
653
|
+
* Defaults to 500 MiB. When the sum of `_data.uncompressedSize` across
|
|
654
|
+
* all archive entries exceeds this cap, `load()` rejects with a
|
|
655
|
+
* {@link ZipBombError}. A hard cap of 65 536 archive entries also
|
|
656
|
+
* applies.
|
|
657
|
+
*/
|
|
658
|
+
maxUncompressedBytes?: number;
|
|
659
|
+
/**
|
|
660
|
+
* When `false` (default), relationship targets that resolve to
|
|
661
|
+
* `http://` or `https://` URLs are dropped from rendered slides
|
|
662
|
+
* (image, picture, background). Set to `true` to allow external image
|
|
663
|
+
* URLs to flow through to `<img src>`.
|
|
664
|
+
*
|
|
665
|
+
* Disabled by default to mitigate SSRF / privacy-leak vectors in
|
|
666
|
+
* server-side rendering and headless export pipelines.
|
|
667
|
+
*/
|
|
668
|
+
allowExternalImages?: boolean;
|
|
669
|
+
}
|
|
670
|
+
/** Output format for the save pipeline. */
|
|
671
|
+
type PptxSaveFormat = 'pptx' | 'ppsx' | 'pptm';
|
|
672
|
+
interface PptxHandlerSaveOptions {
|
|
673
|
+
headerFooter?: r;
|
|
674
|
+
presentationProperties?: s;
|
|
675
|
+
customShows?: t[];
|
|
676
|
+
sections?: u[];
|
|
677
|
+
coreProperties?: v;
|
|
678
|
+
appProperties?: w;
|
|
679
|
+
customProperties?: x[];
|
|
680
|
+
/** Updated notes master data to save back to notesMaster1.xml. */
|
|
681
|
+
notesMaster?: y;
|
|
682
|
+
/** Updated handout master data to save back to handoutMaster1.xml. */
|
|
683
|
+
handoutMaster?: z;
|
|
684
|
+
/**
|
|
685
|
+
* Updated slide masters to save back to ppt/slideMasters/slideMaster*.xml.
|
|
686
|
+
* Each entry in the array applies typed mutations (clrMap, hf flags,
|
|
687
|
+
* background) to the master at its `path`. Masters not listed here pass
|
|
688
|
+
* through verbatim from the original load.
|
|
689
|
+
*/
|
|
690
|
+
slideMasters?: A[];
|
|
691
|
+
/**
|
|
692
|
+
* Updated slide layouts to save back to ppt/slideLayouts/slideLayout*.xml.
|
|
693
|
+
* Each entry applies typed mutations (clrMapOverride, attrs, hf flags,
|
|
694
|
+
* background) to the layout at its `path`. Layouts not listed here pass
|
|
695
|
+
* through verbatim from the original load.
|
|
696
|
+
*/
|
|
697
|
+
slideLayouts?: B[];
|
|
698
|
+
/** Updated tag collections to save back to ppt/tags/tag*.xml. */
|
|
699
|
+
tags?: D[];
|
|
700
|
+
/** Photo album metadata to save back to `p:photoAlbum`. */
|
|
701
|
+
photoAlbum?: E;
|
|
702
|
+
/** East Asian line-break settings to save back to `p:kinsoku`. */
|
|
703
|
+
kinsoku?: F;
|
|
704
|
+
/** Write-protection verifier. Set to `null` to remove, `undefined` to preserve existing. */
|
|
705
|
+
modifyVerifier?: G | null;
|
|
706
|
+
/** View properties to save back to ppt/viewProps.xml. */
|
|
707
|
+
viewProperties?: H;
|
|
708
|
+
/**
|
|
709
|
+
* Table style edits to save back to `ppt/tableStyles.xml`. Pass the
|
|
710
|
+
* `tableStyleMap` from `PptxData` (optionally with edited entries)
|
|
711
|
+
* to persist user edits. The `def` GUID and any unmodelled XML are
|
|
712
|
+
* preserved verbatim. Omitting the option round-trips the original
|
|
713
|
+
* part untouched.
|
|
714
|
+
*/
|
|
715
|
+
tableStyles?: J;
|
|
716
|
+
/**
|
|
717
|
+
* Target output format.
|
|
718
|
+
* - `'pptx'` (default): Standard presentation.
|
|
719
|
+
* - `'ppsx'`: Slide-show file (opens in presentation mode).
|
|
720
|
+
* - `'pptm'`: Macro-enabled presentation (requires VBA data).
|
|
721
|
+
*/
|
|
722
|
+
outputFormat?: PptxSaveFormat;
|
|
723
|
+
/**
|
|
724
|
+
* Embedded fonts to write back (or add) to the saved PPTX.
|
|
725
|
+
*
|
|
726
|
+
* Pass the `embeddedFonts` array from `PptxData` to preserve existing
|
|
727
|
+
* embedded fonts during save. You can also add new fonts by including
|
|
728
|
+
* entries with `rawFontData` populated.
|
|
729
|
+
*
|
|
730
|
+
* When omitted, the save pipeline will automatically re-embed any
|
|
731
|
+
* fonts that were loaded from the original PPTX and have `rawFontData`
|
|
732
|
+
* preserved (i.e. the default is lossless round-trip).
|
|
733
|
+
*/
|
|
734
|
+
embeddedFonts?: K[];
|
|
735
|
+
/**
|
|
736
|
+
* OOXML conformance class for the saved output.
|
|
737
|
+
* - `'preserve'` (default): use the same conformance as the loaded file.
|
|
738
|
+
* - `'strict'`: force Strict Open XML (ISO/IEC 29500) namespace URIs.
|
|
739
|
+
* - `'transitional'`: force Transitional (ECMA-376) namespace URIs.
|
|
740
|
+
*/
|
|
741
|
+
conformance?: 'strict' | 'transitional' | 'preserve';
|
|
742
|
+
}
|
|
743
|
+
interface IPptxHandlerRuntime {
|
|
744
|
+
/**
|
|
745
|
+
* Release all resources held by this runtime (Blob URLs, caches, ZIP).
|
|
746
|
+
* After calling, the runtime cannot be used further.
|
|
747
|
+
*/
|
|
748
|
+
dispose(): void;
|
|
749
|
+
/**
|
|
750
|
+
* Revoke all Blob URLs created during image loading.
|
|
751
|
+
*/
|
|
752
|
+
revokeBlobUrls(): void;
|
|
753
|
+
getCompatibilityWarnings(): n[];
|
|
754
|
+
getLayoutOptions(): o[];
|
|
755
|
+
createXmlBuilder(data: m): PptxXmlBuilder;
|
|
756
|
+
Builder(data: m): PptxXmlBuilder;
|
|
757
|
+
setTemplateBackground(path: string, backgroundColor: string | undefined): void;
|
|
758
|
+
setPresentationTheme(themePath: string, applyToAllMasters?: boolean): Promise<void>;
|
|
759
|
+
getTemplateBackgroundColor(path: string): string | undefined;
|
|
760
|
+
updateThemeColorScheme(colorScheme: d): Promise<void>;
|
|
761
|
+
updateThemeFontScheme(fontScheme: e): Promise<void>;
|
|
762
|
+
updateThemeName(name: string): Promise<void>;
|
|
763
|
+
applyTheme(colorScheme: d, fontScheme: e, themeName?: string): Promise<void>;
|
|
764
|
+
load(data: ArrayBuffer, options?: PptxHandlerLoadOptions): Promise<m>;
|
|
765
|
+
getChartDataForGraphicFrame(slidePath: string, graphicFrame: X | undefined): Promise<p | undefined>;
|
|
766
|
+
getSmartArtDataForGraphicFrame(slidePath: string, graphicFrame: X | undefined): Promise<q | undefined>;
|
|
767
|
+
getImageData(imagePath: string): Promise<string | undefined>;
|
|
768
|
+
/**
|
|
769
|
+
* Extract a media file from the PPTX archive as an ArrayBuffer.
|
|
770
|
+
* Returns undefined if the file is not found.
|
|
771
|
+
*/
|
|
772
|
+
getMediaArrayBuffer(mediaPath: string): Promise<ArrayBuffer | undefined>;
|
|
773
|
+
save(slides: l[], options?: PptxHandlerSaveOptions): Promise<Uint8Array>;
|
|
774
|
+
exportSlides(slides: l[], options: L): Promise<Map<number, Uint8Array>>;
|
|
775
|
+
/**
|
|
776
|
+
* Get the available slide layouts for a specific slide, based on the
|
|
777
|
+
* slide's master. Scans the slide master's relationships to find all
|
|
778
|
+
* layouts that belong to it.
|
|
779
|
+
*
|
|
780
|
+
* @param slideIndex - Zero-based slide index.
|
|
781
|
+
* @param slides - Current slides array.
|
|
782
|
+
* @returns Array of layout options belonging to the same slide master.
|
|
783
|
+
*/
|
|
784
|
+
getAvailableLayoutsForSlide(slideIndex: number, slides: l[]): Promise<o[]>;
|
|
785
|
+
/**
|
|
786
|
+
* Resolve the editable template (master + layout) elements a slide
|
|
787
|
+
* inherits, each carrying a `master-` / `layout-` prefixed id. Excludes
|
|
788
|
+
* placeholders; returns only decorative shapes/pictures/graphic frames.
|
|
789
|
+
*
|
|
790
|
+
* @param slideId - The slide's archive path (`PptxSlide.id`).
|
|
791
|
+
*/
|
|
792
|
+
getTemplateElementsForSlide(slideId: string): Promise<P[]>;
|
|
793
|
+
/**
|
|
794
|
+
* Scan the loaded PPTX archive for all theme parts.
|
|
795
|
+
*/
|
|
796
|
+
getAvailableThemes(): Promise<Array<{
|
|
797
|
+
path: string;
|
|
798
|
+
name?: string;
|
|
799
|
+
}>>;
|
|
800
|
+
/**
|
|
801
|
+
* Apply a different layout to an existing slide by updating the slide's
|
|
802
|
+
* relationship to point to the new layout and re-parsing layout
|
|
803
|
+
* placeholders / background.
|
|
804
|
+
*
|
|
805
|
+
* @param slideIndex - Zero-based slide index.
|
|
806
|
+
* @param layoutPath - Archive path of the target layout
|
|
807
|
+
* (e.g. `ppt/slideLayouts/slideLayout2.xml`).
|
|
808
|
+
* @param slides - Current slides array.
|
|
809
|
+
* @returns The updated slide with new layout path, name, and background.
|
|
810
|
+
*/
|
|
811
|
+
applyLayoutToSlide(slideIndex: number, layoutPath: string, slides: l[]): Promise<l>;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Abstract factory contract for creating {@link IPptxHandlerRuntime}
|
|
816
|
+
* instances.
|
|
817
|
+
*
|
|
818
|
+
* Implement this interface to supply a custom runtime (e.g. a
|
|
819
|
+
* WASM-backed or test-double runtime) to {@link PptxHandlerCore}.
|
|
820
|
+
*/
|
|
821
|
+
interface IPptxHandlerRuntimeFactory {
|
|
822
|
+
/** Instantiate and return a new runtime implementation. */
|
|
823
|
+
createRuntime(): IPptxHandlerRuntime;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Type definitions for OOXML encryption and decryption.
|
|
828
|
+
*
|
|
829
|
+
* Contains all interfaces and type aliases used by the OOXML crypto modules.
|
|
830
|
+
*
|
|
831
|
+
* @module ooxml-crypto-types
|
|
832
|
+
*/
|
|
833
|
+
/** Supported encryption algorithms. */
|
|
834
|
+
type EncryptionAlgorithm = 'AES128' | 'AES256';
|
|
835
|
+
/** Encryption options for creating encrypted files. */
|
|
836
|
+
interface EncryptionOptions {
|
|
837
|
+
/** The encryption algorithm to use (defaults to AES256). */
|
|
838
|
+
algorithm?: EncryptionAlgorithm;
|
|
839
|
+
/** Number of hash iterations for key derivation (defaults to 100000). Lower values speed up tests. */
|
|
840
|
+
spinCount?: number;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Dependency injection options for {@link PptxHandlerCore}.
|
|
845
|
+
*
|
|
846
|
+
* Provide either `runtime` (an already-constructed runtime) or
|
|
847
|
+
* `runtimeFactory` (a factory that will be called once). When neither
|
|
848
|
+
* is supplied the default runtime is created automatically.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```ts
|
|
852
|
+
* // Use the default runtime:
|
|
853
|
+
* const core = new PptxHandlerCore();
|
|
854
|
+
*
|
|
855
|
+
* // Inject a custom runtime:
|
|
856
|
+
* const core = new PptxHandlerCore({ runtime: myRuntime });
|
|
857
|
+
*
|
|
858
|
+
* // Supply a factory for lazy creation:
|
|
859
|
+
* const core = new PptxHandlerCore({ runtimeFactory: myFactory });
|
|
860
|
+
* // => PptxHandlerCore instance with injected runtime
|
|
861
|
+
* ```
|
|
862
|
+
*/
|
|
863
|
+
interface PptxHandlerCoreDependencies {
|
|
864
|
+
runtime?: IPptxHandlerRuntime;
|
|
865
|
+
runtimeFactory?: IPptxHandlerRuntimeFactory;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Thin facade over the PPTX runtime implementation.
|
|
869
|
+
*
|
|
870
|
+
* All heavy parsing, serialisation, and XML manipulation is delegated to an
|
|
871
|
+
* {@link IPptxHandlerRuntime}. This surface stays stable and small so that
|
|
872
|
+
* callers remain decoupled from the runtime internals and host-specific
|
|
873
|
+
* runtime swaps (e.g. WASM vs Node) can be done transparently.
|
|
874
|
+
*
|
|
875
|
+
* @remarks
|
|
876
|
+
* - Constructed once per open document.
|
|
877
|
+
* - Errors from encrypted files are caught at `load()` time via
|
|
878
|
+
* {@link EncryptedFileError}.
|
|
879
|
+
* - `PptxXmlBuilder` instances returned by `createXmlBuilder()` / `Builder()`
|
|
880
|
+
* operate directly on the runtime’s in-memory ZIP.
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* ```ts
|
|
884
|
+
* const handler = new PptxHandlerCore();
|
|
885
|
+
* const data = await handler.load(arrayBuffer);
|
|
886
|
+
* // ... mutate slides ...
|
|
887
|
+
* const out = await handler.save(data.slides);
|
|
888
|
+
* // => Uint8Array of the modified .pptx file
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
declare class PptxHandlerCore {
|
|
892
|
+
private readonly runtime;
|
|
893
|
+
/**
|
|
894
|
+
* Create a new handler, optionally injecting a custom runtime.
|
|
895
|
+
*
|
|
896
|
+
* Resolution order:
|
|
897
|
+
* 1. `dependencies.runtime` — use as-is.
|
|
898
|
+
* 2. `dependencies.runtimeFactory` — call `createRuntime()` once.
|
|
899
|
+
* 3. Fall back to {@link createDefaultPptxHandlerRuntime}.
|
|
900
|
+
*
|
|
901
|
+
* @param dependencies - Optional runtime or factory override.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* const core = new PptxHandlerCore();
|
|
906
|
+
* // => PptxHandlerCore instance with default runtime
|
|
907
|
+
* ```
|
|
908
|
+
*/
|
|
909
|
+
constructor(dependencies?: PptxHandlerCoreDependencies);
|
|
910
|
+
/**
|
|
911
|
+
* Release all resources held by this handler instance.
|
|
912
|
+
*
|
|
913
|
+
* Revokes every Blob URL created for images/media, clears all
|
|
914
|
+
* in-memory caches, and releases the in-memory ZIP archive.
|
|
915
|
+
*
|
|
916
|
+
* Call this when the handler is no longer needed (e.g. component
|
|
917
|
+
* unmount) to free memory immediately rather than waiting for GC.
|
|
918
|
+
*
|
|
919
|
+
* After calling `dispose()`, do not call any other methods — create
|
|
920
|
+
* a new `PptxHandler` instance instead.
|
|
921
|
+
*/
|
|
922
|
+
dispose(): void;
|
|
923
|
+
/**
|
|
924
|
+
* Return any compatibility warnings detected during the most recent load.
|
|
925
|
+
*
|
|
926
|
+
* Warnings indicate features the editor cannot fully represent (e.g.
|
|
927
|
+
* SmartArt, 3-D effects, embedded OLE objects).
|
|
928
|
+
*
|
|
929
|
+
* @returns Array of {@link PptxCompatibilityWarning} objects.
|
|
930
|
+
*/
|
|
931
|
+
getCompatibilityWarnings(): n[];
|
|
932
|
+
/**
|
|
933
|
+
* Get the slide layout options available in the loaded presentation.
|
|
934
|
+
*
|
|
935
|
+
* Each option maps to a `<p:sldLayout>` inside the PPTX archive.
|
|
936
|
+
*
|
|
937
|
+
* @returns Array of {@link PptxLayoutOption} entries.
|
|
938
|
+
*/
|
|
939
|
+
getLayoutOptions(): o[];
|
|
940
|
+
/**
|
|
941
|
+
* Create a fluent XML builder scoped to the given presentation data.
|
|
942
|
+
*
|
|
943
|
+
* The builder provides a chainable API for constructing and inserting
|
|
944
|
+
* OpenXML nodes directly into the runtime’s in-memory ZIP.
|
|
945
|
+
*
|
|
946
|
+
* @param data - The parsed {@link PptxData} to bind the builder to.
|
|
947
|
+
* @returns A new {@link PptxXmlBuilder} instance.
|
|
948
|
+
*/
|
|
949
|
+
createXmlBuilder(data: m): PptxXmlBuilder;
|
|
950
|
+
/**
|
|
951
|
+
* Shorthand alias for {@link createXmlBuilder}.
|
|
952
|
+
*
|
|
953
|
+
* @param data - Parsed presentation data.
|
|
954
|
+
* @returns A {@link PptxXmlBuilder} instance.
|
|
955
|
+
*/
|
|
956
|
+
Builder(data: m): PptxXmlBuilder;
|
|
957
|
+
/**
|
|
958
|
+
* Register a background image for a specific template layout path.
|
|
959
|
+
*
|
|
960
|
+
* @param path - The internal PPTX path (e.g. `ppt/slideLayouts/slideLayout1.xml`).
|
|
961
|
+
* @param backgroundColor - Optional hex colour to render behind the image.
|
|
962
|
+
*/
|
|
963
|
+
setTemplateBackground(path: string, backgroundColor: string | undefined): void;
|
|
964
|
+
/**
|
|
965
|
+
* Retrieve the background colour previously set for a template layout.
|
|
966
|
+
*
|
|
967
|
+
* @param path - The internal PPTX layout path.
|
|
968
|
+
* @returns Hex colour string, or `undefined` if none was set.
|
|
969
|
+
*/
|
|
970
|
+
getTemplateBackgroundColor(path: string): string | undefined;
|
|
971
|
+
/**
|
|
972
|
+
* Replace the presentation’s theme by loading an external `.thmx` file.
|
|
973
|
+
*
|
|
974
|
+
* @param themePath - Absolute or relative path to the `.thmx` file.
|
|
975
|
+
* @param applyToAllMasters - Apply to every slide master (default `true`).
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
978
|
+
* ```ts
|
|
979
|
+
* await handler.setPresentationTheme("./themes/corporate.thmx");
|
|
980
|
+
* // => void — theme XML replaced in the in-memory ZIP
|
|
981
|
+
* ```
|
|
982
|
+
*/
|
|
983
|
+
setPresentationTheme(themePath: string, applyToAllMasters?: boolean): Promise<void>;
|
|
984
|
+
/**
|
|
985
|
+
* Modify the theme’s colour scheme (accent colours, background, text, etc.).
|
|
986
|
+
*
|
|
987
|
+
* @param colorScheme - A {@link PptxThemeColorScheme} with hex colour values.
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* ```ts
|
|
991
|
+
* await handler.updateThemeColorScheme({
|
|
992
|
+
* dk1: "#1A1A2E", dk2: "#16213E",
|
|
993
|
+
* lt1: "#FFFFFF", lt2: "#E8E8E8",
|
|
994
|
+
* accent1: "#0F3460", accent2: "#533483",
|
|
995
|
+
* accent3: "#E94560", accent4: "#F0A500",
|
|
996
|
+
* });
|
|
997
|
+
* // => void — colour scheme updated in the in-memory theme XML
|
|
998
|
+
* ```
|
|
999
|
+
*/
|
|
1000
|
+
updateThemeColorScheme(colorScheme: d): Promise<void>;
|
|
1001
|
+
/**
|
|
1002
|
+
* Update the theme’s font scheme (heading + body typefaces).
|
|
1003
|
+
*
|
|
1004
|
+
* @param fontScheme - A {@link PptxThemeFontScheme} with font family names.
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```ts
|
|
1008
|
+
* await handler.updateThemeFontScheme({
|
|
1009
|
+
* majorFont: "Montserrat",
|
|
1010
|
+
* minorFont: "Open Sans",
|
|
1011
|
+
* });
|
|
1012
|
+
* // => void — font scheme updated in the in-memory theme XML
|
|
1013
|
+
* ```
|
|
1014
|
+
*/
|
|
1015
|
+
updateThemeFontScheme(fontScheme: e): Promise<void>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Rename the presentation theme.
|
|
1018
|
+
*
|
|
1019
|
+
* @param name - New display name for the theme.
|
|
1020
|
+
*/
|
|
1021
|
+
updateThemeName(name: string): Promise<void>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Apply a complete theme in one call (colour scheme + font scheme + optional name).
|
|
1024
|
+
*
|
|
1025
|
+
* This is a convenience wrapper over {@link updateThemeColorScheme},
|
|
1026
|
+
* {@link updateThemeFontScheme}, and {@link updateThemeName}.
|
|
1027
|
+
*
|
|
1028
|
+
* @param colorScheme - Colour definitions.
|
|
1029
|
+
* @param fontScheme - Font definitions.
|
|
1030
|
+
* @param themeName - Optional theme display name.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
* ```ts
|
|
1034
|
+
* await handler.applyTheme(
|
|
1035
|
+
* { dk1: "#000", lt1: "#FFF", accent1: "#0066CC", /* … *\/ },
|
|
1036
|
+
* { majorFont: "Helvetica", minorFont: "Arial" },
|
|
1037
|
+
* "Corporate 2025",
|
|
1038
|
+
* );
|
|
1039
|
+
* // => void — colour scheme, font scheme, and name applied atomically
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
applyTheme(colorScheme: d, fontScheme: e, themeName?: string): Promise<void>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Switch the presentation's theme, updating both the underlying XML and
|
|
1045
|
+
* re-resolving all element colours in-place.
|
|
1046
|
+
*
|
|
1047
|
+
* This is the high-level API for theme switching: it updates the theme
|
|
1048
|
+
* data in the ZIP, then patches all resolved colours in the provided
|
|
1049
|
+
* `PptxData` so that elements immediately reflect the new colour scheme
|
|
1050
|
+
* without requiring a re-parse.
|
|
1051
|
+
*
|
|
1052
|
+
* @param data - The current parsed presentation data (mutated in-place for
|
|
1053
|
+
* convenience, but a new `PptxData` object is also returned).
|
|
1054
|
+
* @param colorScheme - New colour scheme (12 colours).
|
|
1055
|
+
* @param fontScheme - Optional new font scheme.
|
|
1056
|
+
* @param themeName - Optional theme display name.
|
|
1057
|
+
* @returns The updated PptxData with re-resolved colours.
|
|
1058
|
+
*
|
|
1059
|
+
* @example
|
|
1060
|
+
* ```ts
|
|
1061
|
+
* import { THEME_PRESETS } from "pptx-viewer-core";
|
|
1062
|
+
*
|
|
1063
|
+
* const ion = THEME_PRESETS.find(p => p.id === "ion")!;
|
|
1064
|
+
* const newData = await handler.switchTheme(
|
|
1065
|
+
* data,
|
|
1066
|
+
* ion.colorScheme,
|
|
1067
|
+
* ion.fontScheme,
|
|
1068
|
+
* ion.name,
|
|
1069
|
+
* );
|
|
1070
|
+
* // => PptxData with all colours updated to the Ion theme
|
|
1071
|
+
* ```
|
|
1072
|
+
*/
|
|
1073
|
+
switchTheme(data: m, colorScheme: d, fontScheme?: e, themeName?: string): Promise<m>;
|
|
1074
|
+
/**
|
|
1075
|
+
* Apply a built-in theme preset to the presentation.
|
|
1076
|
+
*
|
|
1077
|
+
* Convenience wrapper around {@link switchTheme} that accepts a
|
|
1078
|
+
* {@link PptxThemePreset} directly.
|
|
1079
|
+
*
|
|
1080
|
+
* @param data - The current parsed presentation data.
|
|
1081
|
+
* @param preset - One of the built-in presets from {@link THEME_PRESETS}.
|
|
1082
|
+
* @returns The updated PptxData.
|
|
1083
|
+
*
|
|
1084
|
+
* @example
|
|
1085
|
+
* ```ts
|
|
1086
|
+
* import { THEME_PRESETS } from "pptx-viewer-core";
|
|
1087
|
+
*
|
|
1088
|
+
* const preset = THEME_PRESETS.find(p => p.id === "facet")!;
|
|
1089
|
+
* const newData = await handler.switchThemePreset(data, preset);
|
|
1090
|
+
* ```
|
|
1091
|
+
*/
|
|
1092
|
+
switchThemePreset(data: m, preset: PptxThemePreset): Promise<m>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Parse a PPTX file from an `ArrayBuffer` and return structured data.
|
|
1095
|
+
*
|
|
1096
|
+
* If the file is encrypted and a `password` is provided in `options`,
|
|
1097
|
+
* the file will be decrypted before parsing. If no password is provided
|
|
1098
|
+
* for an encrypted file, throws {@link EncryptedFileError}.
|
|
1099
|
+
*
|
|
1100
|
+
* @param data - Raw bytes of the `.pptx` file (may be encrypted OLE2).
|
|
1101
|
+
* @param options - Optional load-time settings, including `password`.
|
|
1102
|
+
* @returns Parsed {@link PptxData} containing slides, theme, layouts, etc.
|
|
1103
|
+
*
|
|
1104
|
+
* @example
|
|
1105
|
+
* ```ts
|
|
1106
|
+
* // Load an unencrypted file:
|
|
1107
|
+
* const pptx = await handler.load(buf.buffer);
|
|
1108
|
+
*
|
|
1109
|
+
* // Load a password-protected file:
|
|
1110
|
+
* const pptx = await handler.load(buf.buffer, { password: "secret" });
|
|
1111
|
+
* console.log(`${pptx.slides.length} slides loaded`);
|
|
1112
|
+
* ```
|
|
1113
|
+
*/
|
|
1114
|
+
load(data: ArrayBuffer, options?: PptxHandlerLoadOptions): Promise<m>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Extract chart data from a graphic-frame XML node.
|
|
1117
|
+
*
|
|
1118
|
+
* @param slidePath - Internal archive path of the slide (e.g. `ppt/slides/slide1.xml`).
|
|
1119
|
+
* @param graphicFrame - Parsed XML object for the `<p:graphicFrame>` node.
|
|
1120
|
+
* @returns Chart data, or `undefined` if the frame is not a chart.
|
|
1121
|
+
*/
|
|
1122
|
+
getChartDataForGraphicFrame(slidePath: string, graphicFrame: X | undefined): Promise<p | undefined>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Extract SmartArt data from a graphic-frame XML node.
|
|
1125
|
+
*
|
|
1126
|
+
* @param slidePath - Internal archive path of the slide.
|
|
1127
|
+
* @param graphicFrame - Parsed XML object for the `<p:graphicFrame>` node.
|
|
1128
|
+
* @returns SmartArt data, or `undefined` if the frame is not SmartArt.
|
|
1129
|
+
*/
|
|
1130
|
+
getSmartArtDataForGraphicFrame(slidePath: string, graphicFrame: X | undefined): Promise<q | undefined>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Get the base64-encoded data URL for an embedded image.
|
|
1133
|
+
*
|
|
1134
|
+
* @param imagePath - Archive-relative path (e.g. `ppt/media/image1.png`).
|
|
1135
|
+
* @returns A `data:image/...;base64,...` string, or `undefined` if not found.
|
|
1136
|
+
*/
|
|
1137
|
+
getImageData(imagePath: string): Promise<string | undefined>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Extract a media file from the PPTX archive as an ArrayBuffer.
|
|
1140
|
+
* Avoids the 33% base64 overhead of getImageData — prefer this for
|
|
1141
|
+
* audio/video media that will be played via Blob URLs.
|
|
1142
|
+
*/
|
|
1143
|
+
getMediaArrayBuffer(mediaPath: string): Promise<ArrayBuffer | undefined>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Serialise current slides back into a PPTX byte array.
|
|
1146
|
+
*
|
|
1147
|
+
* @param slides - The (possibly mutated) slide array.
|
|
1148
|
+
* @param options - Optional save-time settings (e.g. thumbnail generation).
|
|
1149
|
+
* @returns `Uint8Array` of the complete `.pptx` file.
|
|
1150
|
+
*
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```ts
|
|
1153
|
+
* const bytes = await handler.save(data.slides);
|
|
1154
|
+
* await fs.writeFile("output.pptx", Buffer.from(bytes));
|
|
1155
|
+
* // => Uint8Array written to disk as a valid .pptx file
|
|
1156
|
+
* ```
|
|
1157
|
+
*/
|
|
1158
|
+
save(slides: l[], options?: PptxHandlerSaveOptions): Promise<Uint8Array>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Serialise slides and then encrypt the output with a password.
|
|
1161
|
+
*
|
|
1162
|
+
* This is a convenience method that calls {@link save} followed by
|
|
1163
|
+
* {@link encryptPptx}. The result is an OLE2 container suitable for
|
|
1164
|
+
* opening in Microsoft PowerPoint with a password prompt.
|
|
1165
|
+
*
|
|
1166
|
+
* @param slides - The (possibly mutated) slide array.
|
|
1167
|
+
* @param password - The password to encrypt with.
|
|
1168
|
+
* @param options - Optional save-time and encryption settings.
|
|
1169
|
+
* @returns `Uint8Array` of the encrypted OLE2 file.
|
|
1170
|
+
*
|
|
1171
|
+
* @example
|
|
1172
|
+
* ```ts
|
|
1173
|
+
* const bytes = await handler.saveEncrypted(data.slides, "secret");
|
|
1174
|
+
* await fs.writeFile("protected.pptx", Buffer.from(bytes));
|
|
1175
|
+
* // => Encrypted OLE2 file requiring password to open
|
|
1176
|
+
* ```
|
|
1177
|
+
*/
|
|
1178
|
+
saveEncrypted(slides: l[], password: string, options?: PptxHandlerSaveOptions & {
|
|
1179
|
+
encryption?: EncryptionOptions;
|
|
1180
|
+
}): Promise<Uint8Array>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Get the slide layouts available for a specific slide.
|
|
1183
|
+
*
|
|
1184
|
+
* Returns layouts belonging to the same slide master as the given slide.
|
|
1185
|
+
* This is useful for building a layout picker UI scoped to the current
|
|
1186
|
+
* slide's master.
|
|
1187
|
+
*
|
|
1188
|
+
* @param slideIndex - Zero-based slide index.
|
|
1189
|
+
* @param slides - Current slides array.
|
|
1190
|
+
* @returns Array of {@link PptxLayoutOption} entries for the slide's master.
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```ts
|
|
1194
|
+
* const layouts = await handler.getAvailableLayoutsForSlide(0, data.slides);
|
|
1195
|
+
* console.log(layouts.map(l => l.name));
|
|
1196
|
+
* // => ["Title Slide", "Title and Content", "Blank", ...]
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
1199
|
+
getAvailableLayoutsForSlide(slideIndex: number, slides: l[]): Promise<o[]>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Resolve the editable template (master + layout) elements a slide
|
|
1202
|
+
* inherits, each carrying a `master-` / `layout-` prefixed id.
|
|
1203
|
+
*
|
|
1204
|
+
* This is the foundation for an "edit template/master" feature. The
|
|
1205
|
+
* returned elements are the decorative master/layout shapes the loader
|
|
1206
|
+
* already merges behind slide-authored content (master shapes behind,
|
|
1207
|
+
* layout shapes on top); placeholders are excluded. The same elements are
|
|
1208
|
+
* shared by every slide inheriting the layout/master, so editing one and
|
|
1209
|
+
* saving updates the shared part.
|
|
1210
|
+
*
|
|
1211
|
+
* To persist an edit, keep the mutated template element inside the
|
|
1212
|
+
* `slide.elements` array passed to {@link save}; the save writer reads
|
|
1213
|
+
* template elements from there and writes their shape XML back into the
|
|
1214
|
+
* owning layout/master `p:spTree`.
|
|
1215
|
+
*
|
|
1216
|
+
* @param slideId - The slide's archive path (the `PptxSlide.id`).
|
|
1217
|
+
* @returns Master + layout elements with prefixed ids (may be empty).
|
|
1218
|
+
*
|
|
1219
|
+
* @example
|
|
1220
|
+
* ```ts
|
|
1221
|
+
* const templateEls = await handler.getTemplateElementsForSlide(slide.id);
|
|
1222
|
+
* const logo = templateEls.find((e) => e.id.startsWith("master-"));
|
|
1223
|
+
* if (logo) {
|
|
1224
|
+
* logo.x += 10;
|
|
1225
|
+
* slide.elements = [...slide.elements, logo];
|
|
1226
|
+
* await handler.save(data.slides);
|
|
1227
|
+
* }
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
getTemplateElementsForSlide(slideId: string): Promise<P[]>;
|
|
1231
|
+
/**
|
|
1232
|
+
* Apply a different layout to an existing slide.
|
|
1233
|
+
*
|
|
1234
|
+
* Updates the slide's relationship to point to the new layout and
|
|
1235
|
+
* refreshes layout-derived properties (background, layout name).
|
|
1236
|
+
* The slide's own content elements are preserved.
|
|
1237
|
+
*
|
|
1238
|
+
* @param slideIndex - Zero-based slide index.
|
|
1239
|
+
* @param layoutPath - Archive path of the target layout
|
|
1240
|
+
* (e.g. `ppt/slideLayouts/slideLayout2.xml`).
|
|
1241
|
+
* @param slides - Current slides array (the slide at `slideIndex`
|
|
1242
|
+
* is replaced in-place).
|
|
1243
|
+
* @returns The updated {@link PptxSlide} with new layout metadata.
|
|
1244
|
+
*
|
|
1245
|
+
* @example
|
|
1246
|
+
* ```ts
|
|
1247
|
+
* const updated = await handler.applyLayoutToSlide(
|
|
1248
|
+
* 0,
|
|
1249
|
+
* "ppt/slideLayouts/slideLayout3.xml",
|
|
1250
|
+
* data.slides,
|
|
1251
|
+
* );
|
|
1252
|
+
* console.log(updated.layoutName);
|
|
1253
|
+
* // => "Two Content"
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
1256
|
+
applyLayoutToSlide(slideIndex: number, layoutPath: string, slides: l[]): Promise<l>;
|
|
1257
|
+
/**
|
|
1258
|
+
* Scan the loaded PPTX archive for all theme parts (`ppt/theme/theme*.xml`)
|
|
1259
|
+
* and return their paths and display names.
|
|
1260
|
+
*/
|
|
1261
|
+
getAvailableThemes(): Promise<Array<{
|
|
1262
|
+
path: string;
|
|
1263
|
+
name?: string;
|
|
1264
|
+
}>>;
|
|
1265
|
+
/**
|
|
1266
|
+
* Export selected slides as individual PPTX files.
|
|
1267
|
+
*
|
|
1268
|
+
* Each entry in the returned map is keyed by slide index and contains a
|
|
1269
|
+
* standalone `Uint8Array` PPTX with only that slide.
|
|
1270
|
+
*
|
|
1271
|
+
* @param slides - Full slide array.
|
|
1272
|
+
* @param options - Export options (slide indexes, format, etc.).
|
|
1273
|
+
* @returns A `Map<slideIndex, Uint8Array>` of exported files.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```ts
|
|
1277
|
+
* const exports = await handler.exportSlides(data.slides, {
|
|
1278
|
+
* slideIndexes: [0, 2],
|
|
1279
|
+
* });
|
|
1280
|
+
* for (const [idx, bytes] of exports) {
|
|
1281
|
+
* await fs.writeFile(`slide_${idx}.pptx`, Buffer.from(bytes));
|
|
1282
|
+
* }
|
|
1283
|
+
* // => Map<number, Uint8Array> — one standalone .pptx per exported slide
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
exportSlides(slides: l[], options: L): Promise<Map<number, Uint8Array>>;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Public facade for the PPTX editor handler.
|
|
1291
|
+
*
|
|
1292
|
+
* The implementation lives in `PptxHandlerCore` so this surface can stay small,
|
|
1293
|
+
* stable, and easy to replace with alternate implementations in the future.
|
|
1294
|
+
*/
|
|
1295
|
+
declare class PptxHandler extends PptxHandlerCore {
|
|
1296
|
+
/**
|
|
1297
|
+
* Create a new blank PPTX presentation from scratch.
|
|
1298
|
+
*
|
|
1299
|
+
* This is a convenience static method that delegates to
|
|
1300
|
+
* {@link PresentationBuilder.create}. The returned handler is fully
|
|
1301
|
+
* initialized and ready for editing, adding slides, and saving.
|
|
1302
|
+
*
|
|
1303
|
+
* @param options - Optional slide dimensions, theme, and metadata.
|
|
1304
|
+
* @returns Handler, parsed data, and a slide builder factory.
|
|
1305
|
+
*
|
|
1306
|
+
* @example
|
|
1307
|
+
* ```ts
|
|
1308
|
+
* const { handler, data, createSlide } = await PptxHandler.createBlank({
|
|
1309
|
+
* title: "My Deck",
|
|
1310
|
+
* theme: { colors: { accent1: "#FF6B6B" } },
|
|
1311
|
+
* });
|
|
1312
|
+
*
|
|
1313
|
+
* data.slides.push(
|
|
1314
|
+
* createSlide("Blank")
|
|
1315
|
+
* .addText("Hello", { fontSize: 36 })
|
|
1316
|
+
* .build()
|
|
1317
|
+
* );
|
|
1318
|
+
*
|
|
1319
|
+
* const bytes = await handler.save(data.slides);
|
|
1320
|
+
* ```
|
|
1321
|
+
*/
|
|
1322
|
+
static createBlank(options?: PresentationOptions): Promise<PresentationBuilderResult>;
|
|
1323
|
+
/**
|
|
1324
|
+
* Create a new PPTX presentation from scratch.
|
|
1325
|
+
*
|
|
1326
|
+
* Alias for {@link createBlank}. Generates a valid minimal OpenXML
|
|
1327
|
+
* package and returns a fully initialized handler ready for editing,
|
|
1328
|
+
* adding slides, and saving.
|
|
1329
|
+
*
|
|
1330
|
+
* @param options - Optional slide dimensions, theme, metadata,
|
|
1331
|
+
* and initial slide count.
|
|
1332
|
+
* @returns Handler, parsed data, and a slide builder factory.
|
|
1333
|
+
*
|
|
1334
|
+
* @example
|
|
1335
|
+
* ```ts
|
|
1336
|
+
* const { handler, data, createSlide } = await PptxHandler.create({
|
|
1337
|
+
* title: "Q4 Report",
|
|
1338
|
+
* initialSlideCount: 3,
|
|
1339
|
+
* theme: { colors: { accent1: "#FF6B6B" } },
|
|
1340
|
+
* });
|
|
1341
|
+
*
|
|
1342
|
+
* // The presentation already has 3 blank slides
|
|
1343
|
+
* console.log(data.slides.length); // => 3
|
|
1344
|
+
*
|
|
1345
|
+
* // Add more slides with content
|
|
1346
|
+
* data.slides.push(
|
|
1347
|
+
* createSlide("Blank")
|
|
1348
|
+
* .addText("Hello", { fontSize: 36 })
|
|
1349
|
+
* .build()
|
|
1350
|
+
* );
|
|
1351
|
+
*
|
|
1352
|
+
* const bytes = await handler.save(data.slides);
|
|
1353
|
+
* ```
|
|
1354
|
+
*/
|
|
1355
|
+
static create(options?: PresentationOptions): Promise<PresentationBuilderResult>;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Framework-agnostic public types shared by the viewer bindings.
|
|
1360
|
+
*
|
|
1361
|
+
* These were duplicated in the React (`types-ui.ts`) and Vue (`viewer/types.ts`)
|
|
1362
|
+
* packages; this is the canonical copy. Each binding layers its own
|
|
1363
|
+
* framework-specific prop/event/handle types on top of these.
|
|
1364
|
+
*/
|
|
1365
|
+
|
|
1366
|
+
/** Canvas dimensions in pixels. */
|
|
1367
|
+
interface CanvasSize {
|
|
1368
|
+
width: number;
|
|
1369
|
+
height: number;
|
|
1370
|
+
}
|
|
1371
|
+
/** A neutral CSS map (framework `CSSProperties` are structurally compatible). */
|
|
1372
|
+
type CssStyleMap = Record<string, string | number>;
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* Minimal i18n for the vanilla binding.
|
|
1376
|
+
*
|
|
1377
|
+
* The other bindings delegate to their framework's i18n runtime (react-i18next,
|
|
1378
|
+
* vue-i18n, ngx-translate) fed by the shared `pptx.*` dictionary. The vanilla
|
|
1379
|
+
* binding has no framework, so this module provides the one missing piece: a
|
|
1380
|
+
* `t(key, params)` lookup with `{{param}}` interpolation over the same shared
|
|
1381
|
+
* English dictionary, plus per-locale overrides supplied by the host.
|
|
1382
|
+
*
|
|
1383
|
+
* Resolution order: host dictionary for the active locale, then the built-in
|
|
1384
|
+
* English dictionary, then a humanised fallback derived from the key (shared
|
|
1385
|
+
* `keyToLabel`), so a missing key never renders as a raw `pptx.*` string.
|
|
1386
|
+
*/
|
|
1387
|
+
/** Translate a dotted `pptx.*` key with optional `{{param}}` interpolation. */
|
|
1388
|
+
type Translator = (key: string, params?: Record<string, string | number>) => string;
|
|
1389
|
+
/** Locale to flat `key: message` dictionary map supplied by the host. */
|
|
1390
|
+
type TranslationMessages = Record<string, Record<string, string>>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Build a {@link Translator} for a locale. `messages[locale]` (when provided)
|
|
1393
|
+
* wins over the built-in English dictionary; English is always the fallback.
|
|
1394
|
+
*/
|
|
1395
|
+
declare function createTranslator(locale?: string, messages?: TranslationMessages): Translator;
|
|
1396
|
+
|
|
1397
|
+
/** Discriminant values of the {@link PptxElement} union (`'text'`, `'chart'`, ...). */
|
|
1398
|
+
type PptxElementType = P['type'];
|
|
1399
|
+
/**
|
|
1400
|
+
* Everything an element renderer may need, passed to every renderer call.
|
|
1401
|
+
*
|
|
1402
|
+
* The context is immutable per slide render. Renderers must create DOM through
|
|
1403
|
+
* `context.document` (never the global `document`) so slides can render into
|
|
1404
|
+
* detached documents (tests, export pipelines).
|
|
1405
|
+
*/
|
|
1406
|
+
interface ElementRenderContext {
|
|
1407
|
+
/** Document used for all DOM creation. */
|
|
1408
|
+
readonly document: Document;
|
|
1409
|
+
/** The slide being rendered. */
|
|
1410
|
+
readonly slide: l;
|
|
1411
|
+
/** Full slide canvas size in CSS px (elements are positioned in this space). */
|
|
1412
|
+
readonly canvasSize: CanvasSize;
|
|
1413
|
+
/**
|
|
1414
|
+
* The scale the stage is rendered at (1 = 100%). The stage applies it via a
|
|
1415
|
+
* CSS transform, so renderers should lay out in unscaled canvas px; `scale`
|
|
1416
|
+
* is informational (e.g. for raster density decisions).
|
|
1417
|
+
*/
|
|
1418
|
+
readonly scale: number;
|
|
1419
|
+
/** Archive-path to displayable URL map for media + poster frames. */
|
|
1420
|
+
readonly mediaDataUrls: ReadonlyMap<string, string>;
|
|
1421
|
+
/** Shared-dictionary translator (`pptx.*` keys). */
|
|
1422
|
+
readonly t: Translator;
|
|
1423
|
+
/** The registry in effect, for renderers that need to inspect it. */
|
|
1424
|
+
readonly registry: ElementRendererRegistry;
|
|
1425
|
+
/**
|
|
1426
|
+
* Render a child element through the registry (used by the group renderer
|
|
1427
|
+
* for recursion; custom renderers may nest elements the same way).
|
|
1428
|
+
*/
|
|
1429
|
+
renderElement(element: P, zIndex: number): HTMLElement | SVGElement | null;
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Renders one slide element to a DOM node (or `null` to render nothing).
|
|
1433
|
+
*
|
|
1434
|
+
* Contract:
|
|
1435
|
+
* - Position absolutely within the stage: apply the shared
|
|
1436
|
+
* `getContainerStyle(element, zIndex)` map (or equivalent) to the returned
|
|
1437
|
+
* root node.
|
|
1438
|
+
* - Set `dataset.elementId = element.id` on the root node.
|
|
1439
|
+
* - Create all DOM via `context.document`.
|
|
1440
|
+
* - Never mutate `element` or anything on the context.
|
|
1441
|
+
*/
|
|
1442
|
+
type ElementRenderer = (element: P, zIndex: number, context: ElementRenderContext) => HTMLElement | SVGElement | null;
|
|
1443
|
+
/**
|
|
1444
|
+
* Registry dispatching elements to renderers by their `type` discriminant.
|
|
1445
|
+
*
|
|
1446
|
+
* Additional element types are supported by registering a renderer for the
|
|
1447
|
+
* type; unregistered types fall through to the fallback renderer (a typed
|
|
1448
|
+
* placeholder box by default). See `render/elements/README.md` for the
|
|
1449
|
+
* step-by-step contract.
|
|
1450
|
+
*/
|
|
1451
|
+
interface ElementRendererRegistry {
|
|
1452
|
+
/** Register (or replace) the renderer for an element type. */
|
|
1453
|
+
register(type: PptxElementType, renderer: ElementRenderer): void;
|
|
1454
|
+
/** Remove the renderer for an element type (falls back afterwards). */
|
|
1455
|
+
unregister(type: PptxElementType): void;
|
|
1456
|
+
/** The renderer registered for a type, or `undefined`. */
|
|
1457
|
+
get(type: PptxElementType): ElementRenderer | undefined;
|
|
1458
|
+
/** True when a dedicated (non-fallback) renderer is registered. */
|
|
1459
|
+
has(type: PptxElementType): boolean;
|
|
1460
|
+
/** Replace the fallback renderer used for unregistered types. */
|
|
1461
|
+
setFallback(renderer: ElementRenderer): void;
|
|
1462
|
+
/** The renderer to use for a type: registered renderer or fallback. */
|
|
1463
|
+
resolve(type: PptxElementType): ElementRenderer;
|
|
1464
|
+
/** All types with a dedicated renderer (sorted, for tests/debugging). */
|
|
1465
|
+
registeredTypes(): PptxElementType[];
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* Create an empty {@link ElementRendererRegistry}.
|
|
1470
|
+
*
|
|
1471
|
+
* The default fallback renders nothing; `createDefaultRegistry()` (in
|
|
1472
|
+
* `./elements`) installs the built-in renderers plus the typed placeholder
|
|
1473
|
+
* fallback.
|
|
1474
|
+
*/
|
|
1475
|
+
declare function createElementRendererRegistry(): ElementRendererRegistry;
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* Apply a shared `CssStyleMap` to an element. The shared builders emit a mix
|
|
1479
|
+
* of camelCase (`backgroundColor`) and kebab-case (`background-color`) keys;
|
|
1480
|
+
* both are normalised to `style.setProperty` calls.
|
|
1481
|
+
*/
|
|
1482
|
+
declare function applyStyleMap(el: HTMLElement | SVGElement, style: CssStyleMap): void;
|
|
1483
|
+
/** Create an element with an optional class and style map. */
|
|
1484
|
+
declare function createEl<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, className?: string, style?: CssStyleMap): HTMLElementTagNameMap[K];
|
|
1485
|
+
/** Create a namespaced SVG element with optional attributes. */
|
|
1486
|
+
declare function createSvgEl<K extends keyof SVGElementTagNameMap>(doc: Document, tag: K, attrs?: Record<string, string | number | undefined>): SVGElementTagNameMap[K];
|
|
1487
|
+
|
|
1488
|
+
interface SlideStageOptions {
|
|
1489
|
+
document: Document;
|
|
1490
|
+
slide: l;
|
|
1491
|
+
canvasSize: CanvasSize;
|
|
1492
|
+
mediaDataUrls: ReadonlyMap<string, string>;
|
|
1493
|
+
registry: ElementRendererRegistry;
|
|
1494
|
+
t: Translator;
|
|
1495
|
+
/** Scale applied via CSS transform (default 1). */
|
|
1496
|
+
scale?: number;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Render one slide as a fixed-size stage: the resolved slide background plus
|
|
1500
|
+
* every element dispatched through the registry, scaled with a CSS transform
|
|
1501
|
+
* (`transform-origin: top left`), exactly like the other bindings' stages.
|
|
1502
|
+
*
|
|
1503
|
+
* The returned node is `canvasSize * scale` ON SCREEN but laid out at the
|
|
1504
|
+
* unscaled canvas size, so the caller should wrap it in a box sized to
|
|
1505
|
+
* `canvasSize * scale` (the viewer's stage host and thumbnails both do).
|
|
1506
|
+
*/
|
|
1507
|
+
declare function renderSlideStage(options: SlideStageOptions): HTMLElement;
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* The registry the viewer uses by default.
|
|
1511
|
+
*
|
|
1512
|
+
* Dedicated renderers: `text`, `shape`, `image`, `picture`, `group`,
|
|
1513
|
+
* `connector`, `table`, `chart`, `smartArt`, `media`, `ink`, `ole`. The
|
|
1514
|
+
* remaining types (`contentPart`, `zoom`, `model3d`, `unknown`) fall through
|
|
1515
|
+
* to the typed placeholder fallback until their renderers land; see
|
|
1516
|
+
* `./README.md` for the contract to add one.
|
|
1517
|
+
*/
|
|
1518
|
+
declare function createDefaultRegistry(): ElementRendererRegistry;
|
|
1519
|
+
|
|
1520
|
+
/** `zoom` is either an explicit scale factor (1 = 100%) or fit-to-viewport. */
|
|
1521
|
+
type ZoomLevel = number | 'fit';
|
|
1522
|
+
/**
|
|
1523
|
+
* The vanilla viewer's reactive view state. Kept intentionally flat and small;
|
|
1524
|
+
* everything here is what the DOM render layer consumes.
|
|
1525
|
+
*/
|
|
1526
|
+
interface ViewerState {
|
|
1527
|
+
/** Parsed slides (image/media URLs already patched in by the load pipeline). */
|
|
1528
|
+
slides: l[];
|
|
1529
|
+
/** Slide canvas size in CSS pixels. */
|
|
1530
|
+
canvasSize: CanvasSize;
|
|
1531
|
+
/** Archive-path to displayable URL map for media + poster frames. */
|
|
1532
|
+
mediaDataUrls: Map<string, string>;
|
|
1533
|
+
/** Zero-based index of the visible slide. */
|
|
1534
|
+
currentSlide: number;
|
|
1535
|
+
/** Requested zoom (explicit factor or fit-to-viewport). */
|
|
1536
|
+
zoom: ZoomLevel;
|
|
1537
|
+
/** True while a load is in flight. */
|
|
1538
|
+
loading: boolean;
|
|
1539
|
+
/** Error message from the last failed load, or null. */
|
|
1540
|
+
error: string | null;
|
|
1541
|
+
/** True while presentation (fullscreen) mode is active. */
|
|
1542
|
+
presenting: boolean;
|
|
1543
|
+
/** True when editing interactions (select/move/resize/...) are enabled. */
|
|
1544
|
+
editable: boolean;
|
|
1545
|
+
/** Id of the selected element on the current slide, or null. */
|
|
1546
|
+
selectedElementId: string | null;
|
|
1547
|
+
/** True when the document has unsaved edits (cleared by a save). */
|
|
1548
|
+
dirty: boolean;
|
|
1549
|
+
/**
|
|
1550
|
+
* True while a pointer gesture (drag/resize/rotate) is in flight. Thumbnail
|
|
1551
|
+
* re-renders are deferred until the gesture ends.
|
|
1552
|
+
*/
|
|
1553
|
+
interactionActive: boolean;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* Content sources accepted by the vanilla viewer: raw bytes, a Blob/File, or
|
|
1558
|
+
* a URL string to fetch.
|
|
1559
|
+
*/
|
|
1560
|
+
type PptxViewerSource = ArrayBuffer | Uint8Array | Blob | string;
|
|
1561
|
+
|
|
1562
|
+
/**
|
|
1563
|
+
* Public API types for the vanilla (zero-framework) PowerPoint viewer.
|
|
1564
|
+
*
|
|
1565
|
+
* Derived from the Vue binding's `PowerPointViewerProps` / emits, translated
|
|
1566
|
+
* to plain options + callback functions (there is no framework event system
|
|
1567
|
+
* to emit through).
|
|
1568
|
+
*/
|
|
1569
|
+
/** Callbacks mirroring the Vue component's emits. */
|
|
1570
|
+
interface PptxViewerCallbacks {
|
|
1571
|
+
/** Fired after a presentation loads successfully. */
|
|
1572
|
+
onLoad?: (info: {
|
|
1573
|
+
slideCount: number;
|
|
1574
|
+
canvasSize: CanvasSize;
|
|
1575
|
+
}) => void;
|
|
1576
|
+
/** Fired when a load fails (message is already localised/best-effort). */
|
|
1577
|
+
onError?: (message: string, error: unknown) => void;
|
|
1578
|
+
/** Fired when the active slide changes (zero-based index). */
|
|
1579
|
+
onSlideChange?: (index: number) => void;
|
|
1580
|
+
/** Fired when the effective zoom scale changes (1 = 100%). */
|
|
1581
|
+
onZoomChange?: (scale: number) => void;
|
|
1582
|
+
/** Fired when presentation (fullscreen) mode is entered or exited. */
|
|
1583
|
+
onPresentationChange?: (presenting: boolean) => void;
|
|
1584
|
+
/** Fired after any document mutation (move, resize, edit, undo, ...). */
|
|
1585
|
+
onChange?: () => void;
|
|
1586
|
+
/** Fired when the unsaved-edits flag flips (a save resets it). */
|
|
1587
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
1588
|
+
/** Fired when the selected element changes (`null` = no selection). */
|
|
1589
|
+
onSelectionChange?: (elementId: string | null) => void;
|
|
1590
|
+
}
|
|
1591
|
+
interface PptxViewerOptions extends PptxViewerCallbacks {
|
|
1592
|
+
/**
|
|
1593
|
+
* The presentation to open: raw `.pptx` bytes (ArrayBuffer / Uint8Array),
|
|
1594
|
+
* a Blob/File, or a URL string to fetch. Omit to start empty and call
|
|
1595
|
+
* `loadFile` / `loadUrl` later.
|
|
1596
|
+
*/
|
|
1597
|
+
source?: PptxViewerSource;
|
|
1598
|
+
/** Viewer chrome theme (shared `ViewerTheme`: colors, radius, CSS vars). */
|
|
1599
|
+
theme?: ViewerTheme;
|
|
1600
|
+
/** UI locale (default `'en'`). Dictionaries come from `messages`. */
|
|
1601
|
+
locale?: string;
|
|
1602
|
+
/**
|
|
1603
|
+
* Per-locale `pptx.*` message dictionaries. English falls back to the
|
|
1604
|
+
* built-in shared dictionary; other locales fall back to English.
|
|
1605
|
+
*/
|
|
1606
|
+
messages?: TranslationMessages;
|
|
1607
|
+
/** Zero-based slide to show after load (default 0). */
|
|
1608
|
+
initialSlide?: number;
|
|
1609
|
+
/**
|
|
1610
|
+
* Enable editing (default `false`): click to select, drag/resize/rotate,
|
|
1611
|
+
* inline text editing, keyboard shortcuts, undo/redo, and the toolbar
|
|
1612
|
+
* Save button. Toggle later via `setEditable`.
|
|
1613
|
+
*/
|
|
1614
|
+
editable?: boolean;
|
|
1615
|
+
/**
|
|
1616
|
+
* Legacy flag superseded by {@link editable}; kept so existing option
|
|
1617
|
+
* objects stay type-valid. It has no effect.
|
|
1618
|
+
*/
|
|
1619
|
+
readOnly?: boolean;
|
|
1620
|
+
/** Show the toolbar (default `true`). */
|
|
1621
|
+
showToolbar?: boolean;
|
|
1622
|
+
/** Show the thumbnail sidebar (default `true`). */
|
|
1623
|
+
showThumbnails?: boolean;
|
|
1624
|
+
/**
|
|
1625
|
+
* Custom element-renderer registry. Defaults to `createDefaultRegistry()`;
|
|
1626
|
+
* pass your own (or mutate the default via `getRegistry()`) to add or
|
|
1627
|
+
* override element renderers.
|
|
1628
|
+
*/
|
|
1629
|
+
registry?: ElementRendererRegistry;
|
|
1630
|
+
}
|
|
1631
|
+
/** The viewer handle returned by `createPptxViewer`. */
|
|
1632
|
+
interface PptxViewerInstance {
|
|
1633
|
+
/** Load a presentation from bytes or a Blob/File (replaces the current one). */
|
|
1634
|
+
loadFile(file: Blob | ArrayBuffer | Uint8Array): Promise<void>;
|
|
1635
|
+
/** Fetch and load a presentation from a URL. */
|
|
1636
|
+
loadUrl(url: string): Promise<void>;
|
|
1637
|
+
/** Go to the next slide (no-op on the last slide). */
|
|
1638
|
+
next(): void;
|
|
1639
|
+
/** Go to the previous slide (no-op on the first slide). */
|
|
1640
|
+
prev(): void;
|
|
1641
|
+
/** Jump to a zero-based slide index (clamped). */
|
|
1642
|
+
goToSlide(index: number): void;
|
|
1643
|
+
/** Number of slides in the loaded presentation (0 when none). */
|
|
1644
|
+
getSlideCount(): number;
|
|
1645
|
+
/** Zero-based index of the visible slide. */
|
|
1646
|
+
getCurrentSlide(): number;
|
|
1647
|
+
/** Effective zoom scale (1 = 100%), after fit resolution. */
|
|
1648
|
+
getZoom(): number;
|
|
1649
|
+
/** Set an explicit zoom scale, or `'fit'` for fit-to-viewport. */
|
|
1650
|
+
setZoom(zoom: ZoomLevel): void;
|
|
1651
|
+
zoomIn(): void;
|
|
1652
|
+
zoomOut(): void;
|
|
1653
|
+
zoomToFit(): void;
|
|
1654
|
+
/** Apply a new viewer theme (pass `undefined` to reset to defaults). */
|
|
1655
|
+
setTheme(theme: ViewerTheme | undefined): void;
|
|
1656
|
+
/** Switch the UI locale (rebuilds the chrome labels). */
|
|
1657
|
+
setLocale(locale: string): void;
|
|
1658
|
+
/** Enter presentation mode (real Fullscreen API). */
|
|
1659
|
+
enterPresentation(): Promise<void>;
|
|
1660
|
+
/** Exit presentation mode. */
|
|
1661
|
+
exitPresentation(): Promise<void>;
|
|
1662
|
+
/** Enable or disable editing at runtime (disabling clears the selection). */
|
|
1663
|
+
setEditable(editable: boolean): void;
|
|
1664
|
+
/** Undo the last edit (no-op when the undo stack is empty). */
|
|
1665
|
+
undo(): void;
|
|
1666
|
+
/** Redo the last undone edit (no-op when the redo stack is empty). */
|
|
1667
|
+
redo(): void;
|
|
1668
|
+
canUndo(): boolean;
|
|
1669
|
+
canRedo(): boolean;
|
|
1670
|
+
/** Serialise the (edited) presentation to `.pptx` bytes and clear dirty. */
|
|
1671
|
+
save(): Promise<Uint8Array>;
|
|
1672
|
+
/** `save()` + trigger a browser download (default `presentation.pptx`). */
|
|
1673
|
+
downloadPptx(fileName?: string): Promise<void>;
|
|
1674
|
+
/** Delete the selected element (no-op without a selection). */
|
|
1675
|
+
deleteSelected(): void;
|
|
1676
|
+
/** Id of the selected element, or `null`. */
|
|
1677
|
+
getSelectedElementId(): string | null;
|
|
1678
|
+
/** The element-renderer registry in effect (extension point). */
|
|
1679
|
+
getRegistry(): ElementRendererRegistry;
|
|
1680
|
+
/**
|
|
1681
|
+
* Escape hatch: the live `pptx-viewer-core` handler for the loaded file
|
|
1682
|
+
* (or `null`). Enables advanced operations (save, markdown conversion,
|
|
1683
|
+
* archive access) without extra APIs here.
|
|
1684
|
+
*/
|
|
1685
|
+
getHandler(): PptxHandler | null;
|
|
1686
|
+
/** Tear down DOM, listeners, Blob URLs, and the core handler. */
|
|
1687
|
+
destroy(): void;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
/**
|
|
1691
|
+
* The zero-framework PowerPoint viewer. Construct via {@link createPptxViewer}
|
|
1692
|
+
* (or `new PptxViewer(container, options)`): builds its chrome inside
|
|
1693
|
+
* `container`, loads `options.source` when given, and re-renders through a
|
|
1694
|
+
* tiny reactive store. All parsing lives in `pptx-viewer-core`; all pure
|
|
1695
|
+
* render logic in `pptx-viewer-shared`.
|
|
1696
|
+
*/
|
|
1697
|
+
declare class PptxViewer implements PptxViewerInstance {
|
|
1698
|
+
private readonly container;
|
|
1699
|
+
private readonly doc;
|
|
1700
|
+
private readonly options;
|
|
1701
|
+
private readonly store;
|
|
1702
|
+
private readonly registry;
|
|
1703
|
+
private readonly renderer;
|
|
1704
|
+
private t;
|
|
1705
|
+
private chrome;
|
|
1706
|
+
private presentation;
|
|
1707
|
+
private detachKeyboard;
|
|
1708
|
+
private resizeObserver;
|
|
1709
|
+
private handler;
|
|
1710
|
+
private blobUrls;
|
|
1711
|
+
private appliedThemeVars;
|
|
1712
|
+
private loadToken;
|
|
1713
|
+
private destroyed;
|
|
1714
|
+
private editor;
|
|
1715
|
+
constructor(container: HTMLElement, options?: PptxViewerOptions);
|
|
1716
|
+
loadFile(file: Blob | ArrayBuffer | Uint8Array): Promise<void>;
|
|
1717
|
+
loadUrl(url: string): Promise<void>;
|
|
1718
|
+
private load;
|
|
1719
|
+
/** Dispose the previous handler + Blob URLs (before replacing or on destroy). */
|
|
1720
|
+
private releaseLoaded;
|
|
1721
|
+
next(): void;
|
|
1722
|
+
prev(): void;
|
|
1723
|
+
goToSlide(index: number): void;
|
|
1724
|
+
getSlideCount(): number;
|
|
1725
|
+
getCurrentSlide(): number;
|
|
1726
|
+
getZoom(): number;
|
|
1727
|
+
setZoom(zoom: ZoomLevel): void;
|
|
1728
|
+
zoomIn(): void;
|
|
1729
|
+
zoomOut(): void;
|
|
1730
|
+
zoomToFit(): void;
|
|
1731
|
+
setTheme(theme: ViewerTheme | undefined): void;
|
|
1732
|
+
setLocale(locale: string): void;
|
|
1733
|
+
setEditable(editable: boolean): void;
|
|
1734
|
+
undo(): void;
|
|
1735
|
+
redo(): void;
|
|
1736
|
+
canUndo(): boolean;
|
|
1737
|
+
canRedo(): boolean;
|
|
1738
|
+
save(): Promise<Uint8Array>;
|
|
1739
|
+
downloadPptx(fileName?: string): Promise<void>;
|
|
1740
|
+
deleteSelected(): void;
|
|
1741
|
+
getSelectedElementId(): string | null;
|
|
1742
|
+
enterPresentation(): Promise<void>;
|
|
1743
|
+
exitPresentation(): Promise<void>;
|
|
1744
|
+
getRegistry(): ElementRendererRegistry;
|
|
1745
|
+
getHandler(): PptxHandler | null;
|
|
1746
|
+
destroy(): void;
|
|
1747
|
+
private mountChrome;
|
|
1748
|
+
private unmountChrome;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Create a PowerPoint viewer inside `container`.
|
|
1752
|
+
*
|
|
1753
|
+
* ```ts
|
|
1754
|
+
* import { createPptxViewer } from 'pptx-vanilla-viewer';
|
|
1755
|
+
* const viewer = createPptxViewer(document.querySelector('#host')!, {
|
|
1756
|
+
* source: '/deck.pptx',
|
|
1757
|
+
* onSlideChange: (i) => console.log('slide', i + 1),
|
|
1758
|
+
* });
|
|
1759
|
+
* ```
|
|
1760
|
+
*/
|
|
1761
|
+
declare function createPptxViewer(container: HTMLElement, options?: PptxViewerOptions): PptxViewerInstance;
|
|
1762
|
+
|
|
1763
|
+
/** The complete viewer stylesheet text (for hosts that self-manage CSS). */
|
|
1764
|
+
declare function getViewerCss(): string;
|
|
1765
|
+
|
|
1766
|
+
export { type CssStyleMap, type ElementRenderContext, type ElementRenderer, type ElementRendererRegistry, type PptxElementType, PptxHandler, PptxViewer, type PptxViewerCallbacks, type PptxViewerInstance, type PptxViewerOptions, type PptxViewerSource, type SlideStageOptions, type TranslationMessages, type Translator, type ViewerState, type ZoomLevel, applyStyleMap, createDefaultRegistry, createEl, createElementRendererRegistry, createPptxViewer, createSvgEl, createTranslator, getViewerCss, renderSlideStage };
|