/** * PptxRenderer — main API class for rendering PPTX files. * * Handles Wasm lifecycle, PPTX loading, SVG rendering, and export. */ import type { FontFallbackMap } from './font-fallbacks.js'; /** Options for text measurement callback. Font size is in CSS pixels (px). */ export interface MeasureTextFn { (text: string, fontFace: string, fontSizePx: number): number; } /** A comment on a slide. */ export interface SlideComment { authorId: number; date: string; index: number; text: string; x: number; y: number; } /** A comment author in the presentation. */ export interface CommentAuthor { id: number; name: string; initials: string; } /** Log level for controlling console output. */ export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug'; /** Options for initializing PptxRenderer. */ export interface PptxRendererOptions { /** Custom text measurement function. If not provided, uses Canvas 2D (browser only). */ measureText?: MeasureTextFn; /** * Custom font fallback mappings. Merged with built-in defaults (lib/font-fallbacks.ts). * User entries override built-in entries for the same font name. */ fontFallbacks?: FontFallbackMap; /** * Log level for console output. Default: `'error'`. * - `'silent'`: No console output at all * - `'error'`: Errors only (default) * - `'warn'`: Errors + warnings * - `'info'`: Errors + warnings + info messages * - `'debug'`: All messages including debug details */ logLevel?: LogLevel; } /** Internal logger that respects log level. */ export interface Logger { debug(...args: unknown[]): void; info(...args: unknown[]): void; warn(...args: unknown[]): void; error(...args: unknown[]): void; } export declare class PptxRenderer { private wasm; /** Decompressed text ZIP entries (path → UTF-8 string) */ private files; /** Raw binary ZIP entries (path → bytes) */ private rawFiles; /** Original PPTX bytes for export */ private originalBuffer; /** Files added after loadPptx (not in original ZIP) */ private addedFiles; /** Files removed after loadPptx */ private removedFiles; /** Binary files added/replaced after loadPptx (e.g. images) */ private addedBinaryFiles; /** Canvas for text measurement (lazily created) */ private canvas; private ctx; /** Custom text measurement function */ private measureTextFn; /** Font fallback lookup map (source → comma-separated fallbacks) */ private fontFallbackCache; /** Internal logger */ private log; constructor(options?: PptxRendererOptions); /** Get typed Wasm exports. */ private get exports(); /** * Initialize the renderer by loading the Wasm module. * * When called without arguments, the bundled Wasm binary is loaded * automatically via `import.meta.url` resolution. This works with * Vite, webpack, Rollup, and CDN imports (unpkg, jsdelivr). * * In Node.js, pass an ArrayBuffer (e.g. from `fs.readFileSync(path).buffer`) * or a file:// URL / http(s):// URL string. * * @param wasmSource - Optional URL string, file path (Node.js), or ArrayBuffer of .wasm bytes. * If omitted, the bundled Wasm is used. */ init(wasmSource?: string | ArrayBuffer | Uint8Array): Promise; /** * Load a PPTX file from an ArrayBuffer. * @returns Object with slideCount */ loadPptx(arrayBuffer: ArrayBuffer): Promise<{ slideCount: number; }>; /** Number of slides in the loaded presentation. */ getSlideCount(): number; /** Check if a slide is hidden (0-indexed). */ isSlideHidden(slideIdx: number): boolean; /** Get the raw XML of a slide (0-indexed). For debugging. */ getSlideXmlRaw(slideIdx: number): string; /** Get all entry paths in the PPTX archive. For debugging. */ getEntryList(): string[]; /** * Render a slide as an SVG string (0-indexed). * @returns SVG markup, or a string starting with "ERROR:" on failure */ renderSlideSvg(slideIdx: number): string; /** * Update a slide's internal data from an edited SVG string. * Parses the SVG's data-ooxml-* attributes back into SlideData. * @returns "OK" on success, "ERROR:..." on failure */ updateSlideFromSvg(slideIdx: number, svgString: string): string; /** * Get the OOXML slide XML for a slide (0-indexed). * Returns modified XML if the slide was updated, otherwise original. */ getSlideOoxml(slideIdx: number): string; /** * Export the (possibly modified) presentation as a PPTX ArrayBuffer. * Replaces modified slide XML entries in the original ZIP and rebuilds it. */ exportPptx(): Promise; /** * Get speaker notes text for a slide (0-indexed). * @returns Array of paragraph strings, or empty array if no notes exist. */ getSlideNotes(slideIdx: number): string[]; /** * Get comments for a slide (0-indexed). * @returns Array of comment objects, or empty array if no comments exist. */ getSlideComments(slideIdx: number): SlideComment[]; /** * Get comment authors defined in the presentation. * @returns Array of author objects, or empty array if none exist. */ getCommentAuthors(): CommentAuthor[]; /** * Render a single shape as SVG (0-indexed slide and shape). * Returns SVG fragment (`...` + `...`), or "ERROR:..." on failure. */ renderShapeSvg(slideIdx: number, shapeIdx: number): string; /** * Update a shape's transform (position, size, rotation) and return re-rendered SVG. * All values are in EMU. Marks the slide as modified. */ updateShapeTransform(slideIdx: number, shapeIdx: number, x: number, y: number, cx: number, cy: number, rot: number): string; /** * Update a text run's content and return the shape's re-rendered SVG. * Marks the slide as modified. */ updateShapeText(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, text: string): string; /** * Update a shape's solid fill color (RGB 0-255) and return re-rendered SVG. * Marks the slide as modified. */ updateShapeFill(slideIdx: number, shapeIdx: number, r: number, g: number, b: number): string; /** * Delete a shape from a slide. * @returns "OK" on success, "ERROR:..." on failure. */ deleteShape(slideIdx: number, shapeIdx: number): string; /** * Add a basic AutoShape to a slide. * @param geomType - Preset geometry: "rect", "ellipse", "roundRect", "line", etc. * @param x, y, cx, cy - Position and size in EMU. * @param fillR, fillG, fillB - Fill color (0-255). Pass -1 for no fill. * @returns "OK:" on success, "ERROR:..." on failure. */ addShape(slideIdx: number, geomType: string, x: number, y: number, cx: number, cy: number, fillR?: number, fillG?: number, fillB?: number): string; /** * Add a text paragraph to a shape. Creates a single run with the given text. * @param fontSize - Font size in hundredths of a point (e.g. 1800 = 18pt). 0 = inherit. * @param colorR, colorG, colorB - Text color (0-255). Pass -1 for default/inherit. * @returns "OK:" on success, "ERROR:..." on failure. */ addShapeText(slideIdx: number, shapeIdx: number, text: string, fontSize?: number, colorR?: number, colorG?: number, colorB?: number): string; /** * Duplicate a shape, offset by (dxEmu, dyEmu) from the original. * @returns "OK:" on success, "ERROR:..." on failure. */ duplicateShape(slideIdx: number, shapeIdx: number, dxEmu?: number, dyEmu?: number): string; /** * Update a shape's fill to a linear gradient. Returns re-rendered SVG. * @param angle - Gradient angle in 60000ths of a degree (e.g. 5400000 = 90deg). * @param stops - Array of { pos, r, g, b } where pos is 0-100000. */ updateShapeGradientFill(slideIdx: number, shapeIdx: number, angle: number, stops: Array<{ pos: number; r: number; g: number; b: number; }>): string; /** * Update a shape's stroke (outline). Returns re-rendered SVG. * @param r, g, b - Stroke color (0-255). Pass -1 to remove stroke. * @param widthEmu - Stroke width in EMU (default 12700 = 1pt). * @param dash - Dash preset: "dash", "dot", "dashDot", "lgDash", etc. "" = solid. */ updateShapeStroke(slideIdx: number, shapeIdx: number, r: number, g: number, b: number, widthEmu?: number, dash?: string): string; /** * Add a new paragraph to a shape with a single text run. * @param align - "l" (left), "ctr" (center), "r" (right), "just" (justify), "" (inherit). * @returns "OK:" on success, "ERROR:..." on failure. */ addParagraph(slideIdx: number, shapeIdx: number, text: string, align?: string): string; /** * Delete a paragraph from a shape. * @returns "OK" on success, "ERROR:..." on failure. */ deleteParagraph(slideIdx: number, shapeIdx: number, paraIdx: number): string; /** * Add a new text run to a paragraph. * @returns "OK:" on success, "ERROR:..." on failure. */ addRun(slideIdx: number, shapeIdx: number, paraIdx: number, text: string): string; /** * Delete a text run from a paragraph. * @returns "OK" on success, "ERROR:..." on failure. */ deleteRun(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number): string; /** * Update a text run's bold/italic style. Returns re-rendered shape SVG. * @param bold - 1 = set bold, 0 = unset bold, -1 = no change. * @param italic - 1 = set italic, 0 = unset italic, -1 = no change. */ updateTextRunStyle(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, bold?: number, italic?: number): string; /** * Update a text run's font size. Returns re-rendered shape SVG. * @param fontSize - In hundredths of a point (e.g. 1800 = 18pt). 0 = inherit. */ updateTextRunFontSize(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, fontSize: number): string; /** * Update a text run's color (RGB 0-255). Returns re-rendered shape SVG. * Pass r = -1 to clear (inherit from theme/master). */ updateTextRunColor(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, r: number, g: number, b: number): string; /** * Update a text run's font family. Returns re-rendered shape SVG. * @param fontFace - Latin font name. Empty string = no change. * @param eaFont - East Asian font name. Empty string = no change. * @param csFont - Complex Script font name. Empty string = no change. */ updateTextRunFont(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, fontFace?: string, eaFont?: string, csFont?: string): string; /** * Update a paragraph's alignment. Returns re-rendered shape SVG. * @param align - "l" (left), "ctr" (center), "r" (right), "just" (justify), "" (inherit). */ updateParagraphAlign(slideIdx: number, shapeIdx: number, paraIdx: number, align: string): string; /** * Update a text run's decoration (underline, strikethrough, baseline shift). * Returns re-rendered shape SVG. * @param underline - "sng" (single), "dbl" (double), "" (no change), "none" (remove). * @param strike - "sngStrike", "dblStrike", "" (no change), "none" (remove). * @param baseline - 30000 = superscript, -25000 = subscript, 0 = normal, -1 = no change. */ updateTextRunDecoration(slideIdx: number, shapeIdx: number, paraIdx: number, runIdx: number, underline?: string, strike?: string, baseline?: number): string; /** * Add a blank slide at the specified position (0-indexed). * If `afterIdx` is omitted, the slide is appended at the end. * If `sourceSlideIdx` is provided, the new slide copies that slide's layout. * * @param afterIdx - Insert after this slide index (0-indexed). Use -1 to insert at the beginning. * @param sourceSlideIdx - Copy layout from this slide (0-indexed). Defaults to last slide. * @returns Object with the new slide count and the index of the inserted slide. */ addSlide(afterIdx?: number, sourceSlideIdx?: number): Promise<{ slideCount: number; insertedIdx: number; }>; /** * Delete a slide at the specified index (0-indexed). * At least one slide must remain. * * @param slideIdx - The 0-indexed slide to delete. * @returns Object with the new slide count. */ deleteSlide(slideIdx: number): Promise<{ slideCount: number; }>; /** * Reorder slides according to the given index mapping. * * @param newOrder - Array where newOrder[i] is the old index of the slide that should appear at position i. * Must be a permutation of [0, 1, ..., slideCount-1]. * @returns Object with the slide count (unchanged). */ reorderSlides(newOrder: number[]): Promise<{ slideCount: number; }>; /** Rewrite slide files in the files map with correct 1..N numbering. */ private rewriteSlideFiles; /** Extract a relationship target from .rels XML by type suffix. */ private extractRelTarget; /** Extract slide size from presentation.xml. */ private extractSlideSize; /** Create minimal blank slide XML. */ private createBlankSlideXml; /** Find the next available sldId in presentation.xml. */ private findNextSlideId; /** Find the next available rId in a .rels XML string. */ private nextRid; /** Update presentation.xml and .rels for slide addition. */ private updatePresentationXmlForAdd; /** Update presentation.xml and .rels for slide deletion. */ private updatePresentationXmlForDelete; /** Update presentation.xml sldId order for reorder. */ private updatePresentationXmlForReorder; /** Parse all entries from presentation.xml as raw strings. */ private parseSldIdEntries; /** Parse slide relationships: rId → target path. */ private parseSlideRelationships; /** Ensure [Content_Types].xml has an Override for the given slide number. */ private ensureContentTypeForSlide; /** * Add an image to a slide as a Picture shape. * @param slideIdx - Slide index (0-based). * @param imageData - Raw image bytes (PNG, JPEG, GIF, etc.). * @param mimeType - MIME type (e.g. "image/png", "image/jpeg"). * @param x, y, cx, cy - Position and size in EMU. * @returns "OK:" on success, "ERROR:..." on failure. */ addImage(slideIdx: number, imageData: Uint8Array, mimeType: string, x: number, y: number, cx: number, cy: number): string; /** * Replace the image data of an existing Picture shape. * @param slideIdx - Slide index (0-based). * @param shapeIdx - Shape index (composite index for groups). * @param imageData - New image bytes. * @param mimeType - MIME type of the new image. * @returns "OK" on success, "ERROR:..." on failure. */ replaceImage(slideIdx: number, shapeIdx: number, imageData: Uint8Array, mimeType: string): string; /** * Delete a Picture shape and mark its media file for removal. * @param slideIdx - Slide index (0-based). * @param shapeIdx - Shape index. * @returns "OK" on success, "ERROR:..." on failure. */ deleteImage(slideIdx: number, shapeIdx: number): string; /** Resolve a relationship ID to its Target attribute in a .rels XML string. */ private resolveRidTarget; /** Generate the next available media file path. */ private nextMediaPath; /** Ensure [Content_Types].xml has a Default entry for the given extension. */ private ensureContentTypeForExtension; /** Check if a media file is referenced by any slide other than the given one. */ private isMediaReferencedElsewhere; /** Update a file in both the live files map and the export tracking map. */ private persistFile; /** Re-initialize the Wasm engine after structural changes to the files map. */ private reinitializeWasm; /** Build the Wasm import object that satisfies MoonBit's FFI declarations. */ private buildImportObject; /** Convert an EMF/WMF file to an SVG data URI. Returns "" if conversion fails. */ private convertEmf; /** Quote a font name for use in CSS font shorthand (names with spaces need quotes). */ private static quoteFontName; /** Measure the rendered pixel width of text. */ private measureText; /** * Resolve a relationship target path for a slide. * @param slideIdx - 0-indexed slide index * @param relType - last segment of the relationship type (e.g. 'notesSlide', 'comments') */ private resolveRelTarget; /** Resolve a relative path like "../notesSlides/notesSlide1.xml" from a base dir. */ private resolveRelPath; /** * Decode XML entity references in a raw inner-text string. Returns plain * text suitable for `.textContent`. Callers must NOT pass the result to * `.innerHTML` — use `.textContent` to avoid HTML re-interpretation. */ private decodeXmlEntities; /** Extract text paragraphs from a notesSlide XML (body placeholder). */ private extractNotesText; /** Parse comments XML into SlideComment array. */ private parseComments; /** Parse commentAuthors XML into CommentAuthor array. */ private parseCommentAuthors; } //# sourceMappingURL=pptx-renderer.d.ts.map