dom-to-pptx 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,73 +1,73 @@
1
- {
2
- "name": "dom-to-pptx",
3
- "version": "1.0.5",
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
- }
1
+ {
2
+ "name": "dom-to-pptx",
3
+ "version": "1.0.6",
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
+ "devDependencies": {
61
+ "@rollup/plugin-commonjs": "^29.0.0",
62
+ "@rollup/plugin-node-resolve": "^16.0.3",
63
+ "rollup-plugin-polyfill-node": "^0.10.1",
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,53 +1,56 @@
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];
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import polyfillNode from 'rollup-plugin-polyfill-node';
4
+
5
+ const input = 'src/index.js';
6
+
7
+ // Config A: produce module (mjs), cjs and a lightweight UMD that keeps `pptxgenjs` external.
8
+ const configModules = {
9
+ input,
10
+ output: [
11
+ {
12
+ file: 'dist/dom-to-pptx.mjs',
13
+ format: 'es',
14
+ sourcemap: false,
15
+ },
16
+ {
17
+ file: 'dist/dom-to-pptx.cjs',
18
+ format: 'cjs',
19
+ sourcemap: false,
20
+ exports: 'named',
21
+ },
22
+ {
23
+ file: 'dist/dom-to-pptx.min.js',
24
+ format: 'umd',
25
+ name: 'domToPptx',
26
+ esModule: false,
27
+ globals: {
28
+ pptxgenjs: 'PptxGenJS',
29
+ },
30
+ },
31
+ ],
32
+ plugins: [resolve(), commonjs()],
33
+ // Keep pptxgenjs external for module builds so bundlers like Vite don't attempt to resolve Node-only
34
+ // builtins that may be present in pptxgenjs; consumers should install `pptxgenjs` alongside this package
35
+ // when using ESM/CJS builds.
36
+ external: ['pptxgenjs'],
37
+ };
38
+
39
+ // Config B: produce a single standalone UMD bundle that includes dependencies (for script-tag consumers).
40
+ const configBundle = {
41
+ input,
42
+ output: {
43
+ file: 'dist/dom-to-pptx.bundle.js',
44
+ format: 'umd',
45
+ name: 'domToPptx',
46
+ esModule: false,
47
+ sourcemap: false,
48
+ },
49
+ // Use a node polyfill plugin first so Node built-ins (stream, buffer, util, events, etc.)
50
+ // are shimmed for browser environments when creating the standalone bundle.
51
+ plugins: [polyfillNode(), resolve(), commonjs()],
52
+ // Bundle everything for the standalone artifact.
53
+ external: [],
54
+ };
55
+
56
+ export default [configModules, configBundle];
@@ -1,76 +1,79 @@
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
- }
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;
39
+ r.tr *= factor;
40
+ r.br *= factor;
41
+ r.bl *= factor;
42
+ }
43
+
44
+ // Draw path: Top-Left -> Top-Right -> Bottom-Right -> Bottom-Left
45
+ ctx.moveTo(r.tl, 0);
46
+ ctx.lineTo(targetW - r.tr, 0);
47
+ ctx.arcTo(targetW, 0, targetW, r.tr, r.tr);
48
+ ctx.lineTo(targetW, targetH - r.br);
49
+ ctx.arcTo(targetW, targetH, targetW - r.br, targetH, r.br);
50
+ ctx.lineTo(r.bl, targetH);
51
+ ctx.arcTo(0, targetH, 0, targetH - r.bl, r.bl);
52
+ ctx.lineTo(0, r.tl);
53
+ ctx.arcTo(0, 0, r.tl, 0, r.tl);
54
+
55
+ ctx.closePath();
56
+ ctx.fillStyle = '#000';
57
+ ctx.fill();
58
+
59
+ // 2. Composite Source-In (Crops the next image draw to the mask)
60
+ ctx.globalCompositeOperation = 'source-in';
61
+
62
+ // 3. Draw Image (Object Cover Logic)
63
+ const wRatio = targetW / img.width;
64
+ const hRatio = targetH / img.height;
65
+ const maxRatio = Math.max(wRatio, hRatio);
66
+ const renderW = img.width * maxRatio;
67
+ const renderH = img.height * maxRatio;
68
+ const renderX = (targetW - renderW) / 2;
69
+ const renderY = (targetH - renderH) / 2;
70
+
71
+ ctx.drawImage(img, renderX, renderY, renderW, renderH);
72
+
73
+ resolve(canvas.toDataURL('image/png'));
74
+ };
75
+
76
+ img.onerror = () => resolve(null);
77
+ img.src = src;
78
+ });
79
+ }