pptx-browser 4.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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # pptx-browser
2
+
3
+ Render PowerPoint (`.pptx`) slides directly onto an HTML `<canvas>` element — **zero dependencies**, no server required.
4
+
5
+ Uses only native browser/Node APIs: `DecompressionStream` for ZIP decompression, `DOMParser` for XML, and the Canvas 2D API for rendering.
6
+
7
+ ## Browser support
8
+
9
+ Chrome 80+ · Firefox 113+ · Safari 16.4+ · Node 18+ (with [`node-canvas`](https://github.com/Automattic/node-canvas))
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install pptx-browser
17
+ ```
18
+
19
+ No `JSZip`, no `pptxjs`, no other dependencies.
20
+
21
+ ---
22
+
23
+ ## Quick start
24
+
25
+ ```js
26
+ import { PptxRenderer } from 'pptx-browser';
27
+
28
+ const renderer = new PptxRenderer();
29
+
30
+ // Load from a <input type="file"> element
31
+ const [file] = fileInput.files;
32
+ await renderer.load(file, (progress, msg) => console.log(progress, msg));
33
+
34
+ console.log(renderer.slideCount); // number of slides
35
+
36
+ // Render slide 0 onto a canvas
37
+ const canvas = document.getElementById('my-canvas');
38
+ await renderer.renderSlide(0, canvas, 1280); // 1280px wide
39
+
40
+ // Clean up blob URLs when done
41
+ renderer.destroy();
42
+ ```
43
+
44
+ ---
45
+
46
+ ## API
47
+
48
+ ### `new PptxRenderer()`
49
+
50
+ Creates a new renderer instance. Each instance is independent and can load one PPTX at a time.
51
+
52
+ ---
53
+
54
+ ### `renderer.load(source, onProgress?)`
55
+
56
+ Load a PPTX file.
57
+
58
+ | Parameter | Type | Description |
59
+ |--------------|----------------------------------------------|-------------------------------------|
60
+ | `source` | `File \| Blob \| ArrayBuffer \| Uint8Array` | The PPTX data |
61
+ | `onProgress` | `(progress: number, message: string) => void`| Optional. Called with 0–1 progress |
62
+
63
+ Returns: `Promise<void>`
64
+
65
+ ---
66
+
67
+ ### `renderer.renderSlide(index, canvas, width?)`
68
+
69
+ Render a single slide.
70
+
71
+ | Parameter | Type | Default | Description |
72
+ |-----------|----------------------|---------|--------------------------|
73
+ | `index` | `number` | — | 0-based slide index |
74
+ | `canvas` | `HTMLCanvasElement` | — | Target canvas element |
75
+ | `width` | `number` | `1280` | Output width in pixels |
76
+
77
+ Canvas height is set automatically to maintain the correct aspect ratio.
78
+
79
+ Returns: `Promise<void>`
80
+
81
+ ---
82
+
83
+ ### `renderer.renderAllSlides(width?)`
84
+
85
+ Render all slides and return an array of canvas elements. Useful for thumbnail strips.
86
+
87
+ ```js
88
+ const canvases = await renderer.renderAllSlides(320);
89
+ canvases.forEach((c, i) => document.body.appendChild(c));
90
+ ```
91
+
92
+ Returns: `Promise<HTMLCanvasElement[]>`
93
+
94
+ ---
95
+
96
+ ### `renderer.slideCount`
97
+
98
+ `number` — total number of slides. Available after `load()` resolves.
99
+
100
+ ---
101
+
102
+ ### `renderer.destroy()`
103
+
104
+ Releases all `blob:` URLs created during rendering. Call this when you're done with the renderer or loading a new file.
105
+
106
+ ---
107
+
108
+ ## React example
109
+
110
+ ```jsx
111
+ import { useRef, useState } from 'react';
112
+ import { PptxRenderer } from 'pptx-browser';
113
+
114
+ export function PptxViewer() {
115
+ const canvasRef = useRef(null);
116
+ const [renderer] = useState(() => new PptxRenderer());
117
+ const [slideCount, setSlideCount] = useState(0);
118
+ const [current, setCurrent] = useState(0);
119
+
120
+ async function onFile(e) {
121
+ const file = e.target.files[0];
122
+ if (!file) return;
123
+ renderer.destroy();
124
+ await renderer.load(file);
125
+ setSlideCount(renderer.slideCount);
126
+ await renderer.renderSlide(0, canvasRef.current, 1280);
127
+ setCurrent(0);
128
+ }
129
+
130
+ async function goTo(i) {
131
+ await renderer.renderSlide(i, canvasRef.current, 1280);
132
+ setCurrent(i);
133
+ }
134
+
135
+ return (
136
+ <div>
137
+ <input type="file" accept=".pptx" onChange={onFile} />
138
+ <p>Slide {current + 1} / {slideCount}</p>
139
+ <canvas ref={canvasRef} style={{ maxWidth: '100%' }} />
140
+ <div>
141
+ {current > 0 && <button onClick={() => goTo(current - 1)}>←</button>}
142
+ {current < slideCount - 1 && <button onClick={() => goTo(current + 1)}>→</button>}
143
+ </div>
144
+ </div>
145
+ );
146
+ }
147
+ ```
148
+
149
+ ---
150
+
151
+ ## What's rendered
152
+
153
+ | Feature | Status |
154
+ |----------------------------|---------|
155
+ | Theme colours (all 12) | ✅ |
156
+ | Colour transforms (lumMod, lumOff, tint, shade, sat, hue, alpha…) | ✅ |
157
+ | Gradient fills (linear + radial) | ✅ |
158
+ | Image fills + cropping | ✅ |
159
+ | Pattern fills | ✅ (simplified) |
160
+ | 50+ preset shapes | ✅ |
161
+ | Custom geometry (custGeom) | ✅ |
162
+ | Drop shadows + glow | ✅ |
163
+ | Text rendering (wrapping, alignment, superscript/subscript) | ✅ |
164
+ | Font mapping MS→Google Fonts | ✅ (80+ fonts) |
165
+ | normAutoFit text scaling | ✅ |
166
+ | Tables | ✅ |
167
+ | Images in shapes/backgrounds | ✅ |
168
+ | Slide master & layout inheritance | ✅ |
169
+ | Placeholder position inheritance | ✅ |
170
+ | Rotation & flip | ✅ |
171
+ | Group shapes | ✅ |
172
+ | Charts/SmartArt | Placeholder box |
173
+
174
+ ---
175
+
176
+ ## How ZIP decompression works (no JSZip)
177
+
178
+ PPTX files are ZIP archives. Instead of bundling JSZip (~100KB), this library uses the browser-native `DecompressionStream('deflate-raw')` API, available since:
179
+
180
+ - Chrome 80 (Apr 2020)
181
+ - Firefox 113 (May 2023)
182
+ - Safari 16.4 (Mar 2023)
183
+ - Node.js 18 (Apr 2022)
184
+
185
+ The custom ZIP parser is ~80 lines of code vs JSZip's 3,000+.
186
+
187
+ ---
188
+
189
+ ## Font handling
190
+
191
+ Microsoft Office fonts (Calibri, Cambria, Franklin Gothic, etc.) aren't available in browsers. This library automatically maps them to the nearest metric-compatible Google Font and loads it via the Google Fonts API before rendering. Key mappings:
192
+
193
+ | Office font | Web substitute | Notes |
194
+ |--------------------|-------------------------|------------------------------------|
195
+ | Calibri | **Carlito** | Metric-compatible (identical widths) |
196
+ | Calibri Light | Carlito Light | Metric-compatible |
197
+ | Cambria | **Caladea** | Metric-compatible |
198
+ | Aptos (new default)| Inter | |
199
+ | Franklin Gothic | Libre Franklin | |
200
+ | Gill Sans | Quattrocento Sans | |
201
+ | Segoe UI | Inter | |
202
+
203
+ Fonts are loaded once and cached for the session.
204
+
205
+ ---
206
+
207
+ ## License
208
+
209
+ MIT
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "pptx-browser",
3
+ "version": "4.1.0",
4
+ "description": "Render, edit, and export PowerPoint (PPTX) slides. Canvas rendering, SVG export, PDF export, PPTX writer/template engine, slide show, text extraction, animations. Zero dependencies.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "exports": {
9
+ ".": "./src/index.js",
10
+ "./writer": "./src/writer.js",
11
+ "./pdf": "./src/pdf.js",
12
+ "./svg": "./src/svg.js",
13
+ "./animation": "./src/animation.js",
14
+ "./slideshow": "./src/slideshow.js",
15
+ "./extract": "./src/extract.js",
16
+ "./clipboard": "./src/clipboard.js",
17
+ "./zip-writer": "./src/zip-writer.js"
18
+ },
19
+ "files": [
20
+ "src/",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "keywords": [
25
+ "pptx",
26
+ "powerpoint",
27
+ "canvas",
28
+ "pdf",
29
+ "svg",
30
+ "presentation",
31
+ "renderer",
32
+ "editor",
33
+ "template"
34
+ ],
35
+ "author": "",
36
+ "license": "MIT",
37
+ "dependencies": {},
38
+ "devDependencies": {
39
+ "esbuild": "^0.20.0"
40
+ },
41
+ "scripts": {
42
+ "build": "esbuild src/index.js --bundle --format=esm --outfile=dist/pptx-canvas-renderer.esm.js && esbuild src/index.js --bundle --format=iife --global-name=PptxCanvasRenderer --outfile=dist/pptx-canvas-renderer.umd.js",
43
+ "build:esm": "esbuild src/index.js --bundle --format=esm --outfile=dist/pptx-canvas-renderer.esm.js",
44
+ "build:umd": "esbuild src/index.js --bundle --format=iife --global-name=PptxCanvasRenderer --outfile=dist/pptx-canvas-renderer.umd.js"
45
+ },
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ },
49
+ "browser": {
50
+ "./src/index.js": "./src/index.js"
51
+ },
52
+ "sideEffects": false
53
+ }