dom-to-pptx 1.0.1 → 1.0.3
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/.prettierrc +6 -0
- package/CONTRIBUTING.md +72 -0
- package/Readme.md +204 -110
- package/dist/dom-to-pptx.cjs +1038 -0
- package/dist/dom-to-pptx.min.js +1042 -0
- package/dist/dom-to-pptx.mjs +1017 -0
- package/eslint.config.js +17 -0
- package/package.json +55 -37
- package/rollup.config.js +33 -0
- package/src/image-processor.js +48 -48
- package/src/index.js +409 -160
- package/src/utils.js +477 -256
- package/code_context.txt +0 -346
package/eslint.config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import pluginJs from '@eslint/js';
|
|
3
|
+
import pluginPrettier from 'eslint-config-prettier';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{ ignores: ['dist/**'] },
|
|
7
|
+
{ files: ['**/*.js'], languageOptions: { sourceType: 'module', globals: globals.browser } },
|
|
8
|
+
pluginJs.configs.recommended,
|
|
9
|
+
pluginPrettier,
|
|
10
|
+
{
|
|
11
|
+
rules: {
|
|
12
|
+
// Custom rules or overrides
|
|
13
|
+
'no-unused-vars': 'warn',
|
|
14
|
+
'no-undef': 'warn',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
];
|
package/package.json
CHANGED
|
@@ -1,53 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dom-to-pptx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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": "
|
|
6
|
-
"
|
|
5
|
+
"main": "dist/dom-to-pptx.cjs",
|
|
6
|
+
"module": "dist/dom-to-pptx.mjs",
|
|
7
|
+
"browser": "dist/dom-to-pptx.min.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
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
|
+
"build": "npx rollup -c",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"format": "prettier --write ."
|
|
9
20
|
},
|
|
10
21
|
"repository": {
|
|
11
22
|
"type": "git",
|
|
12
23
|
"url": "git+https://github.com/atharva9167j/dom-to-pptx.git"
|
|
13
24
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
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
|
+
],
|
|
44
55
|
"author": "Atharva Dharmendra Jagtap <atharvaj321@gmail.com>",
|
|
45
56
|
"license": "MIT",
|
|
46
57
|
"bugs": {
|
|
47
58
|
"url": "https://github.com/atharva9167j/dom-to-pptx/issues"
|
|
48
59
|
},
|
|
49
|
-
"
|
|
50
|
-
"dependencies": {
|
|
60
|
+
"peerDependencies": {
|
|
51
61
|
"pptxgenjs": "^3.12.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
65
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
66
|
+
"eslint": "^9.39.1",
|
|
67
|
+
"eslint-config-prettier": "^10.1.8",
|
|
68
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
69
|
+
"prettier": "^3.7.3"
|
|
52
70
|
}
|
|
53
|
-
}
|
|
71
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
|
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: ['pptxgenjs'],
|
|
33
|
+
};
|
package/src/image-processor.js
CHANGED
|
@@ -1,48 +1,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 =
|
|
7
|
-
|
|
8
|
-
img.onload = () => {
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
img.onerror = () => resolve(null);
|
|
46
|
-
img.src = src;
|
|
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
|
+
// 1. Draw the Mask (Rounded Rect)
|
|
18
|
+
ctx.beginPath();
|
|
19
|
+
if (ctx.roundRect) {
|
|
20
|
+
ctx.roundRect(0, 0, targetW, targetH, radius);
|
|
21
|
+
} else {
|
|
22
|
+
// Fallback for older browsers if needed
|
|
23
|
+
ctx.rect(0, 0, targetW, targetH);
|
|
24
|
+
}
|
|
25
|
+
ctx.fillStyle = '#000';
|
|
26
|
+
ctx.fill();
|
|
27
|
+
|
|
28
|
+
// 2. Composite Source-In
|
|
29
|
+
ctx.globalCompositeOperation = 'source-in';
|
|
30
|
+
|
|
31
|
+
// 3. Draw Image (Object Cover Logic)
|
|
32
|
+
const wRatio = targetW / img.width;
|
|
33
|
+
const hRatio = targetH / img.height;
|
|
34
|
+
const maxRatio = Math.max(wRatio, hRatio);
|
|
35
|
+
const renderW = img.width * maxRatio;
|
|
36
|
+
const renderH = img.height * maxRatio;
|
|
37
|
+
const renderX = (targetW - renderW) / 2;
|
|
38
|
+
const renderY = (targetH - renderH) / 2;
|
|
39
|
+
|
|
40
|
+
ctx.drawImage(img, renderX, renderY, renderW, renderH);
|
|
41
|
+
|
|
42
|
+
resolve(canvas.toDataURL('image/png'));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
img.onerror = () => resolve(null);
|
|
46
|
+
img.src = src;
|
|
47
|
+
});
|
|
48
|
+
}
|