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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dom-to-pptx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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
5
|
"main": "dist/dom-to-pptx.cjs",
|
|
6
6
|
"module": "dist/dom-to-pptx.mjs",
|
|
7
|
-
"browser": "dist/dom-to-pptx.
|
|
7
|
+
"browser": "dist/dom-to-pptx.bundle.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/dom-to-pptx.mjs",
|
|
@@ -57,9 +57,7 @@
|
|
|
57
57
|
"bugs": {
|
|
58
58
|
"url": "https://github.com/atharva9167j/dom-to-pptx/issues"
|
|
59
59
|
},
|
|
60
|
-
|
|
61
|
-
"pptxgenjs": "^3.12.0"
|
|
62
|
-
},
|
|
60
|
+
|
|
63
61
|
"devDependencies": {
|
|
64
62
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
65
63
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
@@ -67,5 +65,9 @@
|
|
|
67
65
|
"eslint-config-prettier": "^10.1.8",
|
|
68
66
|
"eslint-plugin-prettier": "^5.5.4",
|
|
69
67
|
"prettier": "^3.7.3"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"html2canvas": "^1.4.1",
|
|
71
|
+
"pptxgenjs": "^3.12.0"
|
|
70
72
|
}
|
|
71
73
|
}
|
package/rollup.config.js
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
],
|
|
31
|
-
plugins: [resolve(), commonjs()],
|
|
32
|
-
external
|
|
33
|
-
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
|
|
4
|
+
const input = 'src/index.js';
|
|
5
|
+
|
|
6
|
+
// Config A: produce module (mjs), cjs and a lightweight UMD that keeps `pptxgenjs` external.
|
|
7
|
+
const configModules = {
|
|
8
|
+
input,
|
|
9
|
+
output: [
|
|
10
|
+
{
|
|
11
|
+
file: 'dist/dom-to-pptx.mjs',
|
|
12
|
+
format: 'es',
|
|
13
|
+
sourcemap: false,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
file: 'dist/dom-to-pptx.cjs',
|
|
17
|
+
format: 'cjs',
|
|
18
|
+
sourcemap: false,
|
|
19
|
+
exports: 'named',
|
|
20
|
+
},
|
|
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
|
+
],
|
|
31
|
+
plugins: [resolve(), commonjs()],
|
|
32
|
+
// Keep pptxgenjs external for module builds so bundlers like Vite don't attempt to resolve Node-only
|
|
33
|
+
// builtins that may be present in pptxgenjs; consumers should install `pptxgenjs` alongside this package
|
|
34
|
+
// when using ESM/CJS builds.
|
|
35
|
+
external: ['pptxgenjs'],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Config B: produce a single standalone UMD bundle that includes dependencies (for script-tag consumers).
|
|
39
|
+
const configBundle = {
|
|
40
|
+
input,
|
|
41
|
+
output: {
|
|
42
|
+
file: 'dist/dom-to-pptx.bundle.js',
|
|
43
|
+
format: 'umd',
|
|
44
|
+
name: 'domToPptx',
|
|
45
|
+
esModule: false,
|
|
46
|
+
sourcemap: false,
|
|
47
|
+
},
|
|
48
|
+
plugins: [resolve(), commonjs()],
|
|
49
|
+
// Bundle everything for the standalone artifact.
|
|
50
|
+
external: [],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default [configModules, configBundle];
|
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
|
+
}
|