dom-to-pptx 1.0.2 → 1.0.4
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 -180
- package/SUPPORTED.md +50 -0
- package/dist/dom-to-pptx.bundle.js +31144 -0
- package/dist/dom-to-pptx.cjs +31143 -0
- package/dist/dom-to-pptx.min.js +31141 -1004
- package/dist/dom-to-pptx.mjs +31141 -0
- package/package.json +73 -64
- package/rollup.config.js +44 -17
- package/src/image-processor.js +76 -48
- package/src/index.js +657 -486
- package/src/utils.js +452 -477
package/package.json
CHANGED
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dom-to-pptx",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A client-side library that converts any HTML element into a fully editable PowerPoint slide. **dom-to-pptx** transforms DOM structures into pixel-accurate `.pptx` content, preserving gradients, shadows, rounded images, and responsive layouts. It translates CSS Flexbox/Grid, linear-gradients, box-shadows, and typography into native PowerPoint shapes, enabling precise, design-faithful slide generation directly from the browser.",
|
|
5
|
-
"main": "dist/dom-to-pptx.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"pptx
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dom-to-pptx",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "A client-side library that converts any HTML element into a fully editable PowerPoint slide. **dom-to-pptx** transforms DOM structures into pixel-accurate `.pptx` content, preserving gradients, shadows, rounded images, and responsive layouts. It translates CSS Flexbox/Grid, linear-gradients, box-shadows, and typography into native PowerPoint shapes, enabling precise, design-faithful slide generation directly from the browser.",
|
|
5
|
+
"main": "dist/dom-to-pptx.cjs",
|
|
6
|
+
"module": "dist/dom-to-pptx.mjs",
|
|
7
|
+
"browser": "dist/dom-to-pptx.bundle.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/dom-to-pptx.mjs",
|
|
11
|
+
"require": "./dist/dom-to-pptx.cjs",
|
|
12
|
+
"default": "./dist/dom-to-pptx.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
|
+
"build": "npx rollup -c",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"format": "prettier --write ."
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/atharva9167j/dom-to-pptx.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"pptx",
|
|
27
|
+
"html-to-pptx",
|
|
28
|
+
"powerpoint",
|
|
29
|
+
"pptx-generator",
|
|
30
|
+
"slide-generator",
|
|
31
|
+
"presentation-generator",
|
|
32
|
+
"dom",
|
|
33
|
+
"dom-to-pptx",
|
|
34
|
+
"export",
|
|
35
|
+
"browser-export",
|
|
36
|
+
"client-side-pptx",
|
|
37
|
+
"html-to-powerpoint",
|
|
38
|
+
"convert-html",
|
|
39
|
+
"css-to-pptx",
|
|
40
|
+
"css-to-powerpoint",
|
|
41
|
+
"pptx-creator",
|
|
42
|
+
"presentation-tools",
|
|
43
|
+
"slides",
|
|
44
|
+
"slide-creation",
|
|
45
|
+
"web-to-pptx",
|
|
46
|
+
"web-to-powerpoint",
|
|
47
|
+
"frontend-pptx",
|
|
48
|
+
"html-rendering",
|
|
49
|
+
"layout-engine",
|
|
50
|
+
"gradient-support",
|
|
51
|
+
"flexbox",
|
|
52
|
+
"css-grid",
|
|
53
|
+
"typography"
|
|
54
|
+
],
|
|
55
|
+
"author": "Atharva Dharmendra Jagtap <atharvaj321@gmail.com>",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/atharva9167j/dom-to-pptx/issues"
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
63
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
64
|
+
"eslint": "^9.39.1",
|
|
65
|
+
"eslint-config-prettier": "^10.1.8",
|
|
66
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
67
|
+
"prettier": "^3.7.3"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"html2canvas": "^1.4.1",
|
|
71
|
+
"pptxgenjs": "^3.12.0"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
input: 'src/index.js',
|
|
6
|
-
output:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
input: 'src/index.js',
|
|
6
|
+
output: [
|
|
7
|
+
// ESM build for modern bundlers
|
|
8
|
+
{
|
|
9
|
+
file: 'dist/dom-to-pptx.mjs',
|
|
10
|
+
format: 'es',
|
|
11
|
+
sourcemap: false,
|
|
12
|
+
},
|
|
13
|
+
// CommonJS build for Node / require()
|
|
14
|
+
{
|
|
15
|
+
file: 'dist/dom-to-pptx.cjs',
|
|
16
|
+
format: 'cjs',
|
|
17
|
+
sourcemap: false,
|
|
18
|
+
exports: 'named',
|
|
19
|
+
},
|
|
20
|
+
// UMD build for direct browser usage via script tag (lightweight, keeps pptxgenjs external)
|
|
21
|
+
{
|
|
22
|
+
file: 'dist/dom-to-pptx.min.js',
|
|
23
|
+
format: 'umd',
|
|
24
|
+
name: 'domToPptx',
|
|
25
|
+
esModule: false,
|
|
26
|
+
globals: {
|
|
27
|
+
pptxgenjs: 'PptxGenJS',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
// Full standalone bundle (includes dependencies) — use this when you want a single <script> to work
|
|
31
|
+
{
|
|
32
|
+
file: 'dist/dom-to-pptx.bundle.js',
|
|
33
|
+
format: 'umd',
|
|
34
|
+
name: 'domToPptx',
|
|
35
|
+
esModule: false,
|
|
36
|
+
sourcemap: false,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
plugins: [resolve(), commonjs()],
|
|
40
|
+
// Keep conventional UMD/min file compatible with consumers that already load pptxgenjs separately.
|
|
41
|
+
// For the standalone `dist/dom-to-pptx.bundle.js` we must NOT mark dependencies as external so Rollup will
|
|
42
|
+
// include them. Therefore leave the external list empty (no externals).
|
|
43
|
+
external: [],
|
|
44
|
+
};
|
package/src/image-processor.js
CHANGED
|
@@ -1,48 +1,76 @@
|
|
|
1
|
-
// src/image-processor.js
|
|
2
|
-
|
|
3
|
-
export async function getProcessedImage(src, targetW, targetH, radius) {
|
|
4
|
-
return new Promise((resolve) => {
|
|
5
|
-
const img = new Image();
|
|
6
|
-
img.crossOrigin = 'Anonymous'; // Critical for canvas manipulation
|
|
7
|
-
|
|
8
|
-
img.onload = () => {
|
|
9
|
-
const canvas = document.createElement('canvas');
|
|
10
|
-
// Double resolution for better quality
|
|
11
|
-
const scale = 2;
|
|
12
|
-
canvas.width = targetW * scale;
|
|
13
|
-
canvas.height = targetH * scale;
|
|
14
|
-
const ctx = canvas.getContext('2d');
|
|
15
|
-
ctx.scale(scale, scale);
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
} else {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ctx.
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
// src/image-processor.js
|
|
2
|
+
|
|
3
|
+
export async function getProcessedImage(src, targetW, targetH, radius) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
const img = new Image();
|
|
6
|
+
img.crossOrigin = 'Anonymous'; // Critical for canvas manipulation
|
|
7
|
+
|
|
8
|
+
img.onload = () => {
|
|
9
|
+
const canvas = document.createElement('canvas');
|
|
10
|
+
// Double resolution for better quality
|
|
11
|
+
const scale = 2;
|
|
12
|
+
canvas.width = targetW * scale;
|
|
13
|
+
canvas.height = targetH * scale;
|
|
14
|
+
const ctx = canvas.getContext('2d');
|
|
15
|
+
ctx.scale(scale, scale);
|
|
16
|
+
|
|
17
|
+
// Normalize radius input to an object { tl, tr, br, bl }
|
|
18
|
+
let r = { tl: 0, tr: 0, br: 0, bl: 0 };
|
|
19
|
+
if (typeof radius === 'number') {
|
|
20
|
+
r = { tl: radius, tr: radius, br: radius, bl: radius };
|
|
21
|
+
} else if (typeof radius === 'object' && radius !== null) {
|
|
22
|
+
r = { ...r, ...radius }; // Merge with defaults
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 1. Draw the Mask (Custom Shape with specific corners)
|
|
26
|
+
ctx.beginPath();
|
|
27
|
+
|
|
28
|
+
// Border Radius Clamping Logic (CSS Spec)
|
|
29
|
+
// Prevents corners from overlapping if radii are too large for the container
|
|
30
|
+
const factor = Math.min(
|
|
31
|
+
(targetW / (r.tl + r.tr)) || Infinity,
|
|
32
|
+
(targetH / (r.tr + r.br)) || Infinity,
|
|
33
|
+
(targetW / (r.br + r.bl)) || Infinity,
|
|
34
|
+
(targetH / (r.bl + r.tl)) || Infinity
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (factor < 1) {
|
|
38
|
+
r.tl *= factor; r.tr *= factor; r.br *= factor; r.bl *= factor;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Draw path: Top-Left -> Top-Right -> Bottom-Right -> Bottom-Left
|
|
42
|
+
ctx.moveTo(r.tl, 0);
|
|
43
|
+
ctx.lineTo(targetW - r.tr, 0);
|
|
44
|
+
ctx.arcTo(targetW, 0, targetW, r.tr, r.tr);
|
|
45
|
+
ctx.lineTo(targetW, targetH - r.br);
|
|
46
|
+
ctx.arcTo(targetW, targetH, targetW - r.br, targetH, r.br);
|
|
47
|
+
ctx.lineTo(r.bl, targetH);
|
|
48
|
+
ctx.arcTo(0, targetH, 0, targetH - r.bl, r.bl);
|
|
49
|
+
ctx.lineTo(0, r.tl);
|
|
50
|
+
ctx.arcTo(0, 0, r.tl, 0, r.tl);
|
|
51
|
+
|
|
52
|
+
ctx.closePath();
|
|
53
|
+
ctx.fillStyle = '#000';
|
|
54
|
+
ctx.fill();
|
|
55
|
+
|
|
56
|
+
// 2. Composite Source-In (Crops the next image draw to the mask)
|
|
57
|
+
ctx.globalCompositeOperation = 'source-in';
|
|
58
|
+
|
|
59
|
+
// 3. Draw Image (Object Cover Logic)
|
|
60
|
+
const wRatio = targetW / img.width;
|
|
61
|
+
const hRatio = targetH / img.height;
|
|
62
|
+
const maxRatio = Math.max(wRatio, hRatio);
|
|
63
|
+
const renderW = img.width * maxRatio;
|
|
64
|
+
const renderH = img.height * maxRatio;
|
|
65
|
+
const renderX = (targetW - renderW) / 2;
|
|
66
|
+
const renderY = (targetH - renderH) / 2;
|
|
67
|
+
|
|
68
|
+
ctx.drawImage(img, renderX, renderY, renderW, renderH);
|
|
69
|
+
|
|
70
|
+
resolve(canvas.toDataURL('image/png'));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
img.onerror = () => resolve(null);
|
|
74
|
+
img.src = src;
|
|
75
|
+
});
|
|
76
|
+
}
|