dom-to-pptx 1.0.9 → 1.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 +13 -3
- package/README.md +56 -62
- package/dist/dom-to-pptx.bundle.js +45721 -663
- package/dist/dom-to-pptx.cjs +383 -7832
- package/dist/dom-to-pptx.cjs.map +1 -0
- package/dist/dom-to-pptx.min.js +55312 -347
- package/dist/dom-to-pptx.mjs +362 -7817
- package/dist/dom-to-pptx.mjs.map +1 -0
- package/package.json +83 -73
- package/rollup.config.js +63 -24
- package/src/font-embedder.js +159 -0
- package/src/font-utils.js +35 -0
- package/src/index.js +77 -5
- package/src/utils.js +99 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.0] - 2025-12-29
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Automatic Font Discovery:** The library now automatically scans the DOM for used font families, extracts their `@font-face` URLs from the document stylesheets, and embeds them into the PPTX file.
|
|
9
|
+
- **Custom Font Embedding:** Added support for manually embedding web fonts (TTF, WOFF, OTF).
|
|
10
|
+
- **Font Configuration:** Added `fonts` option for manual font URLs and `autoEmbedFonts` (default: `true`) to toggle automatic detection.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- **Build Configuration:** Updated Rollup build to include necessary Node.js polyfills (Buffer, Stream) for the browser bundle to support binary font manipulation.
|
|
14
|
+
- **Text Detection:** Improved `isTextContainer` logic to better distinguish between pure text nodes and structural inline elements (like icons or styled spans).
|
|
15
|
+
|
|
5
16
|
## [1.0.9] - 2025-12-28
|
|
6
17
|
|
|
7
18
|
### Fixed
|
|
8
|
-
|
|
9
|
-
- **
|
|
10
|
-
- **Font Awesome icon library cannot be converted**: Updated logic to handle Icons inside lists and span elements. fixes [#3].
|
|
19
|
+
- **Complex Gradients:** Fixed `linear-gradient` parsing to correctly support degree-based angles (e.g., `45deg`) and complex directional keywords (e.g., `to top right`), ensuring background gradients match the CSS exactly.
|
|
20
|
+
- **Icon Visibility:** Fixed an issue where icons (Font Awesome, Material Icons, etc.) nested within list items or text containers were being treated as empty text and failing to render, fixes [#3].
|
|
11
21
|
|
|
12
22
|
## [1.0.8] - 2025-12-12 (Hot-Patch)
|
|
13
23
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dom-to-pptx
|
|
2
2
|
|
|
3
|
-
**The High-Fidelity HTML to PowerPoint Converter (v1.0
|
|
3
|
+
**The High-Fidelity HTML to PowerPoint Converter (v1.1.0)**
|
|
4
4
|
|
|
5
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
6
|
|
|
@@ -8,19 +8,20 @@ Most HTML-to-PPTX libraries fail when faced with modern web design. They break o
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### 🚀 New in v1.1.0
|
|
12
|
+
- **Smart Font Embedding:** The library **automatically detects** the fonts used in your HTML, finds their URLs in your CSS, and embeds them into the PPTX. Your slides will look identical on any computer, even if the user doesn't have the fonts installed.
|
|
13
|
+
- **Enhanced Icon Support:** Flawless rendering of FontAwesome, Material Icons, and SVG-based icon libraries (including gradient text icons).
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
### 🎨 Advanced Visual Fidelity
|
|
16
|
+
- **Complex Gradients:** Includes a built-in CSS Gradient Parser that converts `linear-gradient` strings (with multiple stops, specific angles like `45deg`, and transparency) into vector SVGs.
|
|
14
17
|
- **Mathematically Accurate Shadows:** Converts CSS Cartesian shadows (`x`, `y`, `blur`) into PowerPoint's Polar coordinate system (`angle`, `distance`) for 1:1 depth matching.
|
|
15
18
|
- **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
19
|
- **Soft Edges/Blurs:** Accurately translates CSS `filter: blur()` into PowerPoint's soft-edge effects, preserving visual depth.
|
|
17
20
|
|
|
18
21
|
### 📐 Smart Layout & Typography
|
|
19
|
-
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
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).
|
|
22
|
+
- **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.
|
|
23
|
+
- **Rich Text Blocks:** Handles mixed-style text (e.g., **bold** spans inside a normal paragraph).
|
|
24
|
+
- **Text Transformations:** Supports CSS `text-transform: uppercase/lowercase` and `letter-spacing`.
|
|
24
25
|
|
|
25
26
|
### ⚡ Technical Capabilities
|
|
26
27
|
|
|
@@ -38,27 +39,46 @@ npm install dom-to-pptx
|
|
|
38
39
|
|
|
39
40
|
This library is intended for use in the browser (React, Vue, Svelte, Vanilla JS, etc.).
|
|
40
41
|
|
|
41
|
-
### 1. Basic Example
|
|
42
|
+
### 1. Basic Example (Auto-Font Embedding)
|
|
43
|
+
|
|
44
|
+
By default, `dom-to-pptx` attempts to automatically find and embed your web fonts.
|
|
42
45
|
|
|
43
46
|
```javascript
|
|
44
47
|
import { exportToPptx } from 'dom-to-pptx';
|
|
45
48
|
|
|
46
|
-
// import PptxGenJS from 'pptxgenjs'; // Uncomment and use if needed for your setup
|
|
47
|
-
|
|
48
49
|
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
49
|
-
// Pass the CSS selector of the container
|
|
50
|
+
// Pass the CSS selector of the container
|
|
50
51
|
await exportToPptx('#slide-container', {
|
|
51
52
|
fileName: 'slide-presentation.pptx',
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
### 2.
|
|
57
|
+
### 2. Manual Font Configuration (Optional)
|
|
58
|
+
|
|
59
|
+
If you are using external fonts (like Google Fonts) that are hosted on a server without CORS headers, automatic detection might fail. In that case, you can explicitly pass the font URLs:
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import { exportToPptx } from 'dom-to-pptx';
|
|
63
|
+
|
|
64
|
+
await exportToPptx('#slide-container', {
|
|
65
|
+
fileName: 'report.pptx',
|
|
66
|
+
// Optional: Only needed if auto-detection fails due to CORS
|
|
67
|
+
fonts: [
|
|
68
|
+
{
|
|
69
|
+
name: 'Roboto',
|
|
70
|
+
url: 'https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2'
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Multi-Slide Example
|
|
57
77
|
|
|
58
78
|
To export multiple HTML elements as separate slides, pass an array of elements or selectors:
|
|
59
79
|
|
|
60
80
|
```javascript
|
|
61
|
-
import { exportToPptx } from 'dom-to-pptx';
|
|
81
|
+
import { exportToPptx } from 'dom-to-pptx';
|
|
62
82
|
|
|
63
83
|
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
64
84
|
const slideElements = document.querySelectorAll('.slide');
|
|
@@ -68,59 +88,26 @@ document.getElementById('export-btn').addEventListener('click', async () => {
|
|
|
68
88
|
});
|
|
69
89
|
```
|
|
70
90
|
|
|
71
|
-
###
|
|
91
|
+
### 4. Browser Usage (Script Tags)
|
|
72
92
|
|
|
73
|
-
You can use `dom-to-pptx` directly
|
|
74
|
-
|
|
75
|
-
- Recommended — Single-file bundle (includes runtime deps):
|
|
93
|
+
You can use `dom-to-pptx` directly via CDN. The bundle includes all dependencies.
|
|
76
94
|
|
|
77
95
|
```html
|
|
78
|
-
<!-- Single script that contains dom-to-pptx + pptxgenjs + html2canvas -->
|
|
79
96
|
<script src="https://cdn.jsdelivr.net/npm/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
97
|
+
|
|
80
98
|
<script>
|
|
81
99
|
document.getElementById('export-btn').addEventListener('click', async () => {
|
|
82
100
|
// The library is available globally as `domToPptx`
|
|
83
|
-
await domToPptx.exportToPptx('#slide-container', {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
You can load the bundle from a CDN (unpkg/jsdelivr):
|
|
89
|
-
|
|
90
|
-
```html
|
|
91
|
-
<script src="https://unpkg.com/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
92
|
-
```
|
|
93
|
-
```html
|
|
94
|
-
<script src="https://cdn.jsdelivr.net/npm/dom-to-pptx@latest/dist/dom-to-pptx.bundle.js"></script>
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
- Legacy — Explicit runtime includes (smaller dom-to-pptx file, you manage deps):
|
|
99
|
-
|
|
100
|
-
```html
|
|
101
|
-
<!-- Load pptxgenjs first -->
|
|
102
|
-
<script src="https://cdn.jsdelivr.net/npm/pptxgenjs@latest/dist/pptxgen.bundle.js"></script>
|
|
103
|
-
<!-- html2canvas is required by the legacy dom-to-pptx build for backdrop-filter and canvas image processing -->
|
|
104
|
-
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
|
105
|
-
<!-- Then load the legacy dom-to-pptx file that expects the above libs -->
|
|
106
|
-
<script src="https://cdn.jsdelivr.net/npm/dom-to-pptx@latest/dist/dom-to-pptx.min.js"></script>
|
|
107
|
-
<script>
|
|
108
|
-
document.getElementById('download-btn').addEventListener('click', async () => {
|
|
109
|
-
await domToPptx.exportToPptx('#slide-container', { fileName: 'slide-presentation.pptx' });
|
|
101
|
+
await domToPptx.exportToPptx('#slide-container', {
|
|
102
|
+
fileName: 'slide.pptx'
|
|
103
|
+
});
|
|
110
104
|
});
|
|
111
105
|
</script>
|
|
112
106
|
```
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- The standalone `dist/dom-to-pptx.bundle.js` includes `pptxgenjs` and `html2canvas`, so you only need one script tag.
|
|
117
|
-
- 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.
|
|
108
|
+
## Recommended HTML Structure
|
|
118
109
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
### Recommended HTML Structure
|
|
122
|
-
|
|
123
|
-
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.
|
|
110
|
+
We recommend building your slide container at **1920x1080px**. The library will handle the downscaling to fit the PowerPoint slide (16:9).
|
|
124
111
|
|
|
125
112
|
```html
|
|
126
113
|
<!-- Container (16:9 Aspect Ratio) -->
|
|
@@ -309,16 +296,23 @@ For the best results, treat your container as a fixed-size canvas. We recommend
|
|
|
309
296
|
|
|
310
297
|
**Options Object:**
|
|
311
298
|
|
|
312
|
-
| Key
|
|
313
|
-
|
|
|
314
|
-
| `fileName`
|
|
315
|
-
| `
|
|
299
|
+
| Key | Type | Default | Description |
|
|
300
|
+
| :--------------- | :-------- | :------------- | :-------------------------------------------- |
|
|
301
|
+
| `fileName` | `string` | `"export.pptx"` | The name of the downloaded file. |
|
|
302
|
+
| `autoEmbedFonts` | `boolean` | `true` | Automatically detect and embed used fonts. |
|
|
303
|
+
| `fonts` | `Array` | `[]` | Manual array of font objects: `{ name, url }`. |
|
|
316
304
|
|
|
317
305
|
## Important Notes
|
|
318
306
|
|
|
319
|
-
1. **
|
|
320
|
-
|
|
321
|
-
|
|
307
|
+
1. **Fonts & CORS:**
|
|
308
|
+
* **Automatic Embedding:** Works perfectly for local fonts and external fonts served with correct CORS headers.
|
|
309
|
+
* **Google Fonts:** For auto-detection to work with Google Fonts, you must add `crossorigin="anonymous"` to your link tag:
|
|
310
|
+
`<link href="https://fonts.googleapis.com/..." rel="stylesheet" crossorigin="anonymous">`
|
|
311
|
+
* If a font cannot be accessed due to CORS, the library will log a warning and proceed without embedding it (PowerPoint will fallback to Arial).
|
|
312
|
+
|
|
313
|
+
2. **Layout System:** The library does not "read" Flexbox or Grid definitions directly. It measures the final `x, y, width, height` of every element relative to the slide root and places them absolutely. This ensures 100% visual accuracy regardless of the CSS layout method used.
|
|
314
|
+
|
|
315
|
+
3. **CORS Images:** External images (`<img>` tags) must also be served with `Access-Control-Allow-Origin: *` headers to be processed by the rounding/masking engine.
|
|
322
316
|
|
|
323
317
|
## License
|
|
324
318
|
|