dom-to-pptx 1.0.3 → 1.0.5
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 +18 -0
- package/Readme.md +249 -204
- package/SUPPORTED.md +50 -0
- package/dist/dom-to-pptx.bundle.js +31144 -0
- package/dist/dom-to-pptx.cjs +8568 -594
- package/dist/dom-to-pptx.min.js +8926 -952
- package/dist/dom-to-pptx.mjs +8555 -581
- package/package.json +7 -5
- package/rollup.config.js +53 -33
- package/src/image-processor.js +76 -48
- package/src/index.js +246 -91
- package/src/utils.js +452 -477
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.4] - 2025-12-06
|
|
6
|
+
### Added
|
|
7
|
+
- Standalone UMD bundle `dist/dom-to-pptx.bundle.js` which includes runtime dependencies for single-script usage.
|
|
8
|
+
- `SUPPORTED.md` listing common supported HTML elements and CSS features.
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Rounded corner math: decreased false-positive circle detection and capped `rectRadius` to avoid pill-shaped elements becoming full circles.
|
|
12
|
+
- Partial border-radius clipping: elements inside `overflow:hidden` are now correctly rendered with clipping preserved.
|
|
13
|
+
- Very small elements (sub-pixel) rendering: lowered threshold to include tiny decorative elements (e.g., 2x2 dots).
|
|
14
|
+
- Backdrop blur support: simulated `backdrop-filter: blur()` using html2canvas snapshotting.
|
|
15
|
+
- CORS canvas errors: replaced fragile foreignObject rendering with safer SVG + canvas or html2canvas-based capture where appropriate.
|
|
16
|
+
|
|
17
|
+
## [1.0.3] - Previous
|
|
18
|
+
- Minor fixes and optimizations.
|
package/Readme.md
CHANGED
|
@@ -1,204 +1,249 @@
|
|
|
1
|
-
# dom-to-pptx
|
|
2
|
-
|
|
3
|
-
**The High-Fidelity HTML to PowerPoint Converter (v1.0.
|
|
4
|
-
|
|
5
|
-
Most HTML-to-PPTX libraries fail when faced with modern web design. They break on gradients, misalign text, ignore rounded corners, or simply take a screenshot (which isn't editable).
|
|
6
|
-
|
|
7
|
-
**dom-to-pptx** is different. It is a **Coordinate Scraper & Style Engine** that traverses your DOM, calculates the exact computed styles of every element (Flexbox/Grid positions, complex gradients, shadows), and mathematically maps them to native PowerPoint shapes and text boxes. The result is a fully editable, vector-sharp presentation that looks exactly like your web view.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
### 🎨 Advanced Visual Fidelity
|
|
12
|
-
|
|
13
|
-
- **Complex Gradients:** Includes a built-in CSS Gradient Parser that converts `linear-gradient` strings (with multiple stops, angles, and transparency) into vector SVGs for perfect rendering. This now also supports `text-fill-color` gradients, falling back to the first color for broad compatibility.
|
|
14
|
-
- **Mathematically Accurate Shadows:** Converts CSS Cartesian shadows (`x`, `y`, `blur`) into PowerPoint's Polar coordinate system (`angle`, `distance`) for 1:1 depth matching.
|
|
15
|
-
- **Anti-Halo Image Processing:** Uses off-screen HTML5 Canvas with `source-in` composite masking to render rounded images without the ugly white "halo" artifacts found in other libraries.
|
|
16
|
-
- **Soft Edges/Blurs:** Accurately translates CSS `filter: blur()` into PowerPoint's soft-edge effects, preserving visual depth.
|
|
17
|
-
|
|
18
|
-
### 📐 Smart Layout & Typography
|
|
19
|
-
|
|
20
|
-
- **Auto-Scaling Engine:** Build your slide in HTML at **1920x1080** (or any aspect ratio). The library automatically calculates the scaling factor to fit it perfectly into a standard 16:9 PowerPoint slide (10 x 5.625 inches) with auto-centering.
|
|
21
|
-
- **Rich Text Blocks:** Handles mixed-style text (e.g., **bold** spans inside a normal paragraph) while sanitizing HTML source code whitespace (newlines/tabs) to prevent jagged text alignment.
|
|
22
|
-
- **Font Stack Normalization:** Automatically maps web-only fonts (like `ui-sans-serif`, `system-ui`) to safe system fonts (`Arial`, `Calibri`) to ensure the file opens correctly on any computer.
|
|
23
|
-
- **Text Transformations:** Supports CSS `text-transform: uppercase/lowercase` and `letter-spacing` (converted to PT).
|
|
24
|
-
|
|
25
|
-
### ⚡ Technical Capabilities
|
|
26
|
-
|
|
27
|
-
- **Z-Index Handling:** Respects DOM order for correct layering of elements.
|
|
28
|
-
- **Border Radius Math:** Calculates perfect corner rounding percentages based on element dimensions.
|
|
29
|
-
- **Client-Side:** Runs entirely in the browser. No server required.
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
npm install dom-to-pptx
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
This library is intended for use in the browser (React, Vue, Svelte, Vanilla JS, etc.).
|
|
40
|
-
|
|
41
|
-
### 1. Basic Example
|
|
42
|
-
|
|
43
|
-
```javascript
|
|
44
|
-
import { exportToPptx } from 'dom-to-pptx';
|
|
45
|
-
|
|
46
|
-
// Note: If you are using a module bundler, it is recommended to import pptxgenjs
|
|
47
|
-
// directly into your project to ensure tree-shaking and optimal bundle size.
|
|
48
|
-
// import PptxGenJS from 'pptxgenjs'; // Uncomment and use if needed for your setup
|
|
49
|
-
|
|
50
|
-
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
51
|
-
// Pass the CSS selector of the container you want to turn into a slide
|
|
52
|
-
await exportToPptx('#slide-container', {
|
|
53
|
-
fileName: '
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### 2. Multi-Slide Example
|
|
59
|
-
|
|
60
|
-
To export multiple HTML elements as separate slides, pass an array of elements or selectors:
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
import { exportToPptx } from 'dom-to-pptx'; // ESM or CJS import
|
|
64
|
-
|
|
65
|
-
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
66
|
-
const slideElements = document.querySelectorAll('.slide');
|
|
67
|
-
await exportToPptx(Array.from(slideElements), {
|
|
68
|
-
fileName: 'multi-slide-presentation.pptx',
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 3.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
<script
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<!--
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
</div>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
# dom-to-pptx
|
|
2
|
+
|
|
3
|
+
**The High-Fidelity HTML to PowerPoint Converter (v1.0.4).**
|
|
4
|
+
|
|
5
|
+
Most HTML-to-PPTX libraries fail when faced with modern web design. They break on gradients, misalign text, ignore rounded corners, or simply take a screenshot (which isn't editable).
|
|
6
|
+
|
|
7
|
+
**dom-to-pptx** is different. It is a **Coordinate Scraper & Style Engine** that traverses your DOM, calculates the exact computed styles of every element (Flexbox/Grid positions, complex gradients, shadows), and mathematically maps them to native PowerPoint shapes and text boxes. The result is a fully editable, vector-sharp presentation that looks exactly like your web view.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
### 🎨 Advanced Visual Fidelity
|
|
12
|
+
|
|
13
|
+
- **Complex Gradients:** Includes a built-in CSS Gradient Parser that converts `linear-gradient` strings (with multiple stops, angles, and transparency) into vector SVGs for perfect rendering. This now also supports `text-fill-color` gradients, falling back to the first color for broad compatibility.
|
|
14
|
+
- **Mathematically Accurate Shadows:** Converts CSS Cartesian shadows (`x`, `y`, `blur`) into PowerPoint's Polar coordinate system (`angle`, `distance`) for 1:1 depth matching.
|
|
15
|
+
- **Anti-Halo Image Processing:** Uses off-screen HTML5 Canvas with `source-in` composite masking to render rounded images without the ugly white "halo" artifacts found in other libraries.
|
|
16
|
+
- **Soft Edges/Blurs:** Accurately translates CSS `filter: blur()` into PowerPoint's soft-edge effects, preserving visual depth.
|
|
17
|
+
|
|
18
|
+
### 📐 Smart Layout & Typography
|
|
19
|
+
|
|
20
|
+
- **Auto-Scaling Engine:** Build your slide in HTML at **1920x1080** (or any aspect ratio). The library automatically calculates the scaling factor to fit it perfectly into a standard 16:9 PowerPoint slide (10 x 5.625 inches) with auto-centering.
|
|
21
|
+
- **Rich Text Blocks:** Handles mixed-style text (e.g., **bold** spans inside a normal paragraph) while sanitizing HTML source code whitespace (newlines/tabs) to prevent jagged text alignment.
|
|
22
|
+
- **Font Stack Normalization:** Automatically maps web-only fonts (like `ui-sans-serif`, `system-ui`) to safe system fonts (`Arial`, `Calibri`) to ensure the file opens correctly on any computer.
|
|
23
|
+
- **Text Transformations:** Supports CSS `text-transform: uppercase/lowercase` and `letter-spacing` (converted to PT).
|
|
24
|
+
|
|
25
|
+
### ⚡ Technical Capabilities
|
|
26
|
+
|
|
27
|
+
- **Z-Index Handling:** Respects DOM order for correct layering of elements.
|
|
28
|
+
- **Border Radius Math:** Calculates perfect corner rounding percentages based on element dimensions.
|
|
29
|
+
- **Client-Side:** Runs entirely in the browser. No server required.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install dom-to-pptx
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
This library is intended for use in the browser (React, Vue, Svelte, Vanilla JS, etc.).
|
|
40
|
+
|
|
41
|
+
### 1. Basic Example
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { exportToPptx } from 'dom-to-pptx';
|
|
45
|
+
|
|
46
|
+
// Note: If you are using a module bundler, it is recommended to import pptxgenjs
|
|
47
|
+
// directly into your project to ensure tree-shaking and optimal bundle size.
|
|
48
|
+
// import PptxGenJS from 'pptxgenjs'; // Uncomment and use if needed for your setup
|
|
49
|
+
|
|
50
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
51
|
+
// Pass the CSS selector of the container you want to turn into a slide
|
|
52
|
+
await exportToPptx('#slide-container', {
|
|
53
|
+
fileName: 'slide-presentation.pptx',
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Multi-Slide Example
|
|
59
|
+
|
|
60
|
+
To export multiple HTML elements as separate slides, pass an array of elements or selectors:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import { exportToPptx } from 'dom-to-pptx'; // ESM or CJS import
|
|
64
|
+
|
|
65
|
+
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
66
|
+
const slideElements = document.querySelectorAll('.slide');
|
|
67
|
+
await exportToPptx(Array.from(slideElements), {
|
|
68
|
+
fileName: 'multi-slide-presentation.pptx',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. Browser Usage (single-file bundle or legacy setup)
|
|
74
|
+
|
|
75
|
+
You can use `dom-to-pptx` directly in the browser in two ways:
|
|
76
|
+
|
|
77
|
+
- Recommended — Single-file bundle (includes runtime deps):
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<!-- Single script that contains dom-to-pptx + pptxgenjs + html2canvas -->
|
|
81
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
82
|
+
<script>
|
|
83
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
84
|
+
// The library is available globally as `domToPptx`
|
|
85
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can also load the bundle from a CDN (unpkg/jsdelivr):
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<script src="https://unpkg.com/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- Legacy — Explicit runtime includes (smaller dom-to-pptx file, you manage deps):
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<!-- Load pptxgenjs first -->
|
|
100
|
+
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
101
|
+
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
102
|
+
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
103
|
+
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
104
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.min.js"></script>
|
|
105
|
+
<script>
|
|
106
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
107
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Notes:
|
|
113
|
+
|
|
114
|
+
- The standalone `dist/dom-to-pptx.bundle.js` includes `pptxgenjs` and `html2canvas`, so you only need one script tag.
|
|
115
|
+
- If you prefer a smaller payload and already have `pptxgenjs` on the page, use the legacy `dist/dom-to-pptx.min.js` and load `pptxgenjs` first.
|
|
116
|
+
|
|
117
|
+
### 4. Recommended HTML Structure
|
|
118
|
+
|
|
119
|
+
### Recommended HTML Structure
|
|
120
|
+
|
|
121
|
+
For the best results, treat your container as a fixed-size canvas. We recommend building your slide at **1920x1080px**. The library will handle the downscaling.
|
|
122
|
+
|
|
123
|
+
```html
|
|
124
|
+
<!-- Container (16:9 Aspect Ratio) -->
|
|
125
|
+
<!-- The library will capture this background color/gradient automatically -->
|
|
126
|
+
<div
|
|
127
|
+
id="slide-container"
|
|
128
|
+
class="slide w-[1000px] h-[562px] bg-white mx-auto shadow-xl relative overflow-hidden rounded-lg flex items-center justify-center p-10"
|
|
129
|
+
>
|
|
130
|
+
<div
|
|
131
|
+
class="w-full max-w-3xl bg-white rounded-2xl shadow-xl overflow-hidden grid md:grid-cols-2 items-center
|
|
132
|
+
border-l-2 border-indigo-500"
|
|
133
|
+
>
|
|
134
|
+
<div class="p-12">
|
|
135
|
+
<h2 class="text-xl font-semibold text-indigo-500 uppercase tracking-wide mb-2">
|
|
136
|
+
Core Concept
|
|
137
|
+
</h2>
|
|
138
|
+
<h3 class="text-4xl font-bold text-slate-800 mb-6">From Bit to Qubit</h3>
|
|
139
|
+
<div class="space-y-6 text-slate-600">
|
|
140
|
+
<div class="flex items-start gap-4">
|
|
141
|
+
<div
|
|
142
|
+
class="flex-shrink-0 w-8 h-8 bg-slate-200 rounded-full flex items-center justify-center font-bold text-slate-700"
|
|
143
|
+
>
|
|
144
|
+
B
|
|
145
|
+
</div>
|
|
146
|
+
<div>
|
|
147
|
+
<h4 class="font-bold text-slate-700">Classical Bit</h4>
|
|
148
|
+
<p>
|
|
149
|
+
A fundamental unit of information that is either
|
|
150
|
+
<span class="font-semibold text-indigo-600">0</span> or
|
|
151
|
+
<span class="font-semibold text-indigo-600">1</span>.
|
|
152
|
+
</p>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
<div class="flex items-start gap-4">
|
|
156
|
+
<div
|
|
157
|
+
class="flex-shrink-0 w-8 h-8 bg-indigo-200 rounded-full flex items-center justify-center font-bold text-indigo-700"
|
|
158
|
+
>
|
|
159
|
+
Q
|
|
160
|
+
</div>
|
|
161
|
+
<div>
|
|
162
|
+
<h4 class="font-bold text-slate-700">Quantum Bit (Qubit)</h4>
|
|
163
|
+
<p>
|
|
164
|
+
Can be <span class="font-semibold text-indigo-600">0</span>,
|
|
165
|
+
<span class="font-semibold text-indigo-600">1</span>, or a
|
|
166
|
+
<span class="font-semibold text-indigo-600">superposition</span>
|
|
167
|
+
of both states simultaneously.
|
|
168
|
+
</p>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
<div class="h-64 md:h-full">
|
|
174
|
+
<img
|
|
175
|
+
src="https://picsum.photos/800/600?random=2"
|
|
176
|
+
alt="Stylized representation of a qubit"
|
|
177
|
+
class="w-full h-full object-cover"
|
|
178
|
+
/>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## API
|
|
185
|
+
|
|
186
|
+
### `exportToPptx(elementOrSelector, options)`
|
|
187
|
+
|
|
188
|
+
| Parameter | Type | Description |
|
|
189
|
+
| :------------------ | :---------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `elementOrSelector` | `string` \| `HTMLElement` \| `Array<string \| HTMLElement>` | The DOM node(s) or ID selector(s) to convert. Can be a single element/selector or an array for multi-slide export. |
|
|
191
|
+
| `options` | `object` | Configuration object. |
|
|
192
|
+
|
|
193
|
+
**Options Object:**
|
|
194
|
+
|
|
195
|
+
| Key | Type | Default | Description |
|
|
196
|
+
| :---------------- | :------- | :------------- | :-------------------------------------------- |
|
|
197
|
+
| `fileName` | `string` | `"slide.pptx"` | The name of the downloaded file. |
|
|
198
|
+
| `backgroundColor` | `string` | `null` | Force a background color for the slide (hex). |
|
|
199
|
+
|
|
200
|
+
## Important Notes
|
|
201
|
+
|
|
202
|
+
1. **CORS Images:** Because this library uses HTML5 Canvas to process rounded images, any external images must be served with `Access-Control-Allow-Origin: *` headers. If an image is "tainted" (CORS blocked), the browser will refuse to read its data, and it may appear blank in the PPTX.
|
|
203
|
+
2. **Layout System:** The library does not "read" Flexbox or Grid definitions directly. Instead, it lets the browser render the layout, measures the final `x, y, width, height` (BoundingBox) of every element, and places them absolutely on the slide. This ensures 100% visual accuracy regardless of the layout method used.
|
|
204
|
+
3. **Fonts:** PPTX files use the fonts installed on the viewer's OS. If you use a web font like "Inter", and the user doesn't have it installed, PowerPoint will fallback to Arial.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT © [Atharva Dharmendra Jagtap](https://github.com/atharva9167j) and `dom-to-pptx` contributors.
|
|
209
|
+
|
|
210
|
+
## Acknowledgements
|
|
211
|
+
|
|
212
|
+
This project is built on top of [PptxGenJS](https://github.com/gitbrent/PptxGenJS). Huge thanks to the PptxGenJS maintainers and all contributors — dom-to-pptx leverages and extends their excellent work on PPTX generation.
|
|
213
|
+
|
|
214
|
+
## Bundle & Dependencies
|
|
215
|
+
|
|
216
|
+
Starting with v1.0.4 `dom-to-pptx` ships a standalone browser bundle that includes runtime dependencies (for convenience).
|
|
217
|
+
|
|
218
|
+
- If you use npm / a bundler, run:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm install dom-to-pptx
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- For direct browser usage (single script tag), use the bundled file that already includes `pptxgenjs` and `html2canvas`:
|
|
225
|
+
|
|
226
|
+
```html
|
|
227
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.bundle.js"></script>
|
|
228
|
+
<script>
|
|
229
|
+
domToPptx.exportToPptx('#slide-container', { fileName: 'report.pptx' });
|
|
230
|
+
</script>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
If you prefer to manage `pptxgenjs` yourself (smaller bundle), the legacy `dist/dom-to-pptx.min.js` remains available and expects `pptxgenjs` to be loaded separately.
|
|
234
|
+
|
|
235
|
+
Legacy usage note:
|
|
236
|
+
|
|
237
|
+
```html
|
|
238
|
+
<!-- Load pptxgenjs first -->
|
|
239
|
+
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
240
|
+
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
241
|
+
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
242
|
+
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
243
|
+
<script src="/node_modules/dom-to-pptx/dist/dom-to-pptx.min.js"></script>
|
|
244
|
+
<script>
|
|
245
|
+
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
246
|
+
await domToPptx.exportToPptx('#slide-container', { fileName: 'dashboard-report.pptx' });
|
|
247
|
+
});
|
|
248
|
+
</script>
|
|
249
|
+
```
|
package/SUPPORTED.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Supported CSS & HTML
|
|
2
|
+
|
|
3
|
+
This document lists the common CSS features, Tailwind-like utility classes, and HTML elements that dom-to-pptx understands and maps to PowerPoint shapes/text.
|
|
4
|
+
|
|
5
|
+
Note: The library measures computed layout from the browser (getBoundingClientRect) and maps positions/sizes precisely to PPTX inches. If a CSS feature is not listed below it may still work because the browser computes layout and visual styles — the mapping focuses on visual fidelity.
|
|
6
|
+
|
|
7
|
+
## Supported HTML elements
|
|
8
|
+
|
|
9
|
+
- div, span, p, h1-h6
|
|
10
|
+
- img, svg
|
|
11
|
+
- ul, ol, li
|
|
12
|
+
- a
|
|
13
|
+
- button
|
|
14
|
+
- section, article, header, footer
|
|
15
|
+
- input (text), textarea (simple text extraction)
|
|
16
|
+
- figure, figcaption
|
|
17
|
+
|
|
18
|
+
## Supported CSS properties (rendered visually)
|
|
19
|
+
|
|
20
|
+
- background-color, background-image (linear-gradient)
|
|
21
|
+
- background-position, background-size (basic handling in gradients)
|
|
22
|
+
- color, opacity
|
|
23
|
+
- border, border-*-color, border-*-width, border-radius (per-corner)
|
|
24
|
+
- box-shadow (outer shadows mapped to PPTX outer shadows)
|
|
25
|
+
- filter: blur() (soft-edge rendering via SVG)
|
|
26
|
+
- backdrop-filter: blur() (simulated via html2canvas snapshot)
|
|
27
|
+
- transform: rotate() (extraction of rotation angle)
|
|
28
|
+
- display, position, width, height, padding, margin
|
|
29
|
+
- text-align, vertical-align, white-space, text-transform
|
|
30
|
+
- font-family, font-size, font-weight, font-style, line-height
|
|
31
|
+
|
|
32
|
+
## Common utility/Tailwind-like classes (recognized by visual result)
|
|
33
|
+
|
|
34
|
+
These classes are examples; dom-to-pptx reads computed styles, so any combination that results in the same computed value will be supported.
|
|
35
|
+
|
|
36
|
+
- `rounded`, `rounded-sm`, `rounded-md`, `rounded-lg`, `rounded-xl`, `rounded-full`, `rounded-tr-*`, `rounded-bl-full`, etc.
|
|
37
|
+
- `bg-white`, `bg-slate-50`, `bg-indigo-50`, `bg-gradient-to-r`, `from-indigo-400`, `to-cyan-400`, etc. (linear-gradients are parsed)
|
|
38
|
+
- `shadow`, `shadow-md`, `shadow-lg`, `shadow-2xl` (box-shadow)
|
|
39
|
+
- `flex`, `grid`, `items-center`, `justify-center`, `gap-*`
|
|
40
|
+
- `p-4`, `px-6`, `py-2`, `m-4`
|
|
41
|
+
- `w-*`, `h-*` (fixed pixel/percentage/wrappers — computed width/height are used)
|
|
42
|
+
- `text-xs`, `text-sm`, `text-lg`, `font-bold`, `uppercase`, `italic`, `tracking-wide`
|
|
43
|
+
|
|
44
|
+
## Limitations
|
|
45
|
+
|
|
46
|
+
- Complex CSS animations/transitions are not exported — only the current computed visual state is captured.
|
|
47
|
+
- Some advanced CSS features (CSS variables used as colors, filters beyond blur) may not map 1:1.
|
|
48
|
+
- For images to be processed via canvas (rounded images), the source must be CORS-accessible (`Access-Control-Allow-Origin` header) or the image will be skipped or rendered as-is.
|
|
49
|
+
|
|
50
|
+
If a style or element is critical and you find it not behaving as expected, open an issue with a minimal repro and I'll add support or provide a workaround.
|