json2pptx 0.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.
Files changed (2) hide show
  1. package/README.md +70 -0
  2. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # json2pptx
2
+
3
+ 将 JSON 幻灯片数据转换为 PPTX 的工具库,基于 PptxGenJS。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm i json2pptx
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```ts
14
+ import { buildPptxBlob } from 'json2pptx'
15
+
16
+ const deck = {
17
+ title: 'Demo',
18
+ width: 1000,
19
+ height: 562.5,
20
+ slides: [
21
+ {
22
+ background: { color: '#ffffff' },
23
+ elements: [
24
+ {
25
+ type: 'text',
26
+ left: 100,
27
+ top: 100,
28
+ width: 400,
29
+ height: 200,
30
+ content: '<p><strong>Hello</strong> PPTX</p>'
31
+ }
32
+ ]
33
+ }
34
+ ]
35
+ }
36
+
37
+ const { blob, fileName } = await buildPptxBlob(deck)
38
+ // 在浏览器中下载:
39
+ // const url = URL.createObjectURL(blob)
40
+ // const a = document.createElement('a')
41
+ // a.href = url
42
+ // a.download = fileName
43
+ // a.click()
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `buildPptxBlob(template: Deck): Promise<{ blob: Blob; fileName: string }>`
49
+
50
+ 根据 `Deck` 数据生成 PPTX 的 `Blob` 与建议文件名。
51
+
52
+ ### `resolveImageData(src: string): Promise<string>`
53
+
54
+ 将图片地址转换为 data URL(`data:image/*;base64,...`)。支持:
55
+ - data URL
56
+ - 远程 URL
57
+ - 本地文件路径(Node 环境)
58
+
59
+ ## 类型
60
+
61
+ 包内导出了常用类型:
62
+ `Deck`、`Slide`、`SlideElement`、`TextElement`、`ImageElement`、`ShapeElement`、`LineElement` 等。
63
+
64
+ ## 开发
65
+
66
+ ```bash
67
+ npm run build
68
+ npm run test
69
+ npm run typecheck
70
+ ```
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "json2pptx",
3
+ "version": "0.1.0",
4
+ "description": "Convert JSON slide definitions to PPTX using PptxGenJS.",
5
+ "license": "MIT",
6
+ "author": "",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.mjs",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "sideEffects": false,
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit"
27
+ },
28
+ "dependencies": {
29
+ "jszip": "^3.10.1",
30
+ "pptxgenjs": "^3.12.0",
31
+ "svg-arc-to-cubic-bezier": "^3.2.0",
32
+ "svg-pathdata": "^6.0.1",
33
+ "tinycolor2": "^1.6.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.11.30",
37
+ "tsup": "^8.0.1",
38
+ "typescript": "^5.3.3",
39
+ "vitest": "^1.6.0"
40
+ }
41
+ }