pptx-craft 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.
- package/LICENSE +24 -0
- package/README.md +166 -0
- package/README.zh-CN.md +166 -0
- package/dist/index.cjs +3933 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1795 -0
- package/dist/index.d.ts +1795 -0
- package/dist/index.js +3878 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-Present dxsun97
|
|
4
|
+
|
|
5
|
+
This project is derived from PptxGenJS (https://github.com/gitbrent/PptxGenJS),
|
|
6
|
+
Copyright (c) 2015-Present Brent Ely.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
English | [中文](./README.zh-CN.md)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="docs/public/logo.svg" width="128" height="128" alt="pptx-craft logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">pptx-craft</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
Lightweight, type-safe library for creating PowerPoint (.pptx) files — charts, tables, shapes, themes, and plugins out of the box, with only one runtime dependency. Works in Node.js and the browser.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/pptx-craft"><img src="https://img.shields.io/npm/v/pptx-craft" alt="npm version"></a>
|
|
15
|
+
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/pptx-craft" alt="license"></a>
|
|
16
|
+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.6+-3178C6?logo=typescript&logoColor=white" alt="TypeScript"></a>
|
|
17
|
+
<a href="https://dxsun97.github.io/pptx-craft"><img src="https://img.shields.io/badge/docs-online-FF6B42" alt="docs"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install pptx-craft
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Presentation } from 'pptx-craft';
|
|
30
|
+
|
|
31
|
+
const pptx = new Presentation();
|
|
32
|
+
const slide = pptx.addSlide();
|
|
33
|
+
|
|
34
|
+
slide.addText('Hello World', {
|
|
35
|
+
x: 1,
|
|
36
|
+
y: 1,
|
|
37
|
+
w: 8,
|
|
38
|
+
h: 1.5,
|
|
39
|
+
fontSize: 44,
|
|
40
|
+
color: '003366',
|
|
41
|
+
bold: true,
|
|
42
|
+
align: 'center',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
slide.addShape('rect', { x: 1, y: 3, w: 8, h: 0.05, fill: '4472C4' });
|
|
46
|
+
|
|
47
|
+
await pptx.toFile('output.pptx');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- **Text** — font, size, color, bold/italic/underline, alignment, line spacing
|
|
53
|
+
- **Images** — from file path or buffer (PNG, JPEG, etc.)
|
|
54
|
+
- **Shapes** — rect, ellipse, roundRect, diamond, triangle, heart, star, arrows, and more
|
|
55
|
+
- **Tables** — cell-level formatting, borders, custom column/row sizing
|
|
56
|
+
- **Charts** — bar, column, line, pie, area, scatter, doughnut (native PowerPoint charts)
|
|
57
|
+
- **Media** — video and audio embedding
|
|
58
|
+
- **Slide Masters & Layouts** — custom backgrounds, placeholder-based layouts
|
|
59
|
+
- **Themes** — full color scheme and font customization
|
|
60
|
+
- **Speaker Notes** — per-slide notes
|
|
61
|
+
- **Plugins** — extend with custom element types
|
|
62
|
+
|
|
63
|
+
## Preview
|
|
64
|
+
|
|
65
|
+
<table>
|
|
66
|
+
<tr>
|
|
67
|
+
<td><img src="docs/public/previews/quick-example-1.png" alt="Title Slide" width="400"></td>
|
|
68
|
+
<td><img src="docs/public/previews/quick-example-2.png" alt="Table" width="400"></td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td><img src="docs/public/previews/quick-example-3.png" alt="Chart" width="400"></td>
|
|
72
|
+
<td><img src="docs/public/previews/quick-example-4.png" alt="Shapes" width="400"></td>
|
|
73
|
+
</tr>
|
|
74
|
+
</table>
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### Table
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
slide.addTable(
|
|
82
|
+
[
|
|
83
|
+
[
|
|
84
|
+
{ text: 'Name', options: { bold: true, fill: '4472C4', color: 'FFFFFF' } },
|
|
85
|
+
{ text: 'Score', options: { bold: true, fill: '4472C4', color: 'FFFFFF' } },
|
|
86
|
+
],
|
|
87
|
+
[{ text: 'Alice' }, { text: '95' }],
|
|
88
|
+
[{ text: 'Bob' }, { text: '87' }],
|
|
89
|
+
],
|
|
90
|
+
{ x: 1, y: 1, w: 6, h: 3, border: { color: 'CCCCCC', width: 1 } },
|
|
91
|
+
);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Chart
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
slide.addChart(
|
|
98
|
+
'col',
|
|
99
|
+
{
|
|
100
|
+
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
|
|
101
|
+
series: [
|
|
102
|
+
{ name: '2024', values: [120, 180, 150, 210], color: '4472C4' },
|
|
103
|
+
{ name: '2025', values: [140, 200, 190, 250], color: 'ED7D31' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{ x: 1, y: 1, w: 8, h: 5, title: 'Revenue', showLegend: true },
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Slide Master & Layout
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const pptx = new Presentation();
|
|
114
|
+
pptx.defineSlideMaster({ name: 'Corporate', background: '003366' });
|
|
115
|
+
pptx.defineLayout({
|
|
116
|
+
name: 'Title Slide',
|
|
117
|
+
type: 'titleAndContent',
|
|
118
|
+
placeholders: [
|
|
119
|
+
{ type: 'title', placement: { x: 0.5, y: 0.5, w: 9, h: 1 }, idx: 0 },
|
|
120
|
+
{ type: 'body', placement: { x: 0.5, y: 2, w: 9, h: 5 }, idx: 1 },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const slide = pptx.addSlide('Title Slide');
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Plugin
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import type { IPlugin } from 'pptx-craft';
|
|
131
|
+
|
|
132
|
+
const myPlugin: IPlugin = {
|
|
133
|
+
name: 'my-plugin',
|
|
134
|
+
install(registry) {
|
|
135
|
+
registry.registerElement('badge', badgeSerializer);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
pptx.use(myPlugin);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Output
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// Buffer
|
|
146
|
+
const buffer = pptx.toBuffer();
|
|
147
|
+
|
|
148
|
+
// File
|
|
149
|
+
await pptx.toFile('presentation.pptx');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Documentation
|
|
153
|
+
|
|
154
|
+
Full docs available at the [documentation site](https://dxsun97.github.io/pptx-craft). Run locally:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npm run docs:dev
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Acknowledgments
|
|
161
|
+
|
|
162
|
+
This project is derived from [PptxGenJS](https://github.com/gitbrent/PptxGenJS) by Brent Ely.
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT — see [LICENSE](./LICENSE) for details.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
[English](./README.md) | 中文
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="docs/public/logo.svg" width="128" height="128" alt="pptx-craft logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">pptx-craft</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
轻量、类型安全的 PowerPoint(.pptx)生成库 — 开箱即用地支持图表、表格、形状、主题与插件,仅一个运行时依赖。同时支持 Node.js 与浏览器环境。
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/pptx-craft"><img src="https://img.shields.io/npm/v/pptx-craft" alt="npm version"></a>
|
|
15
|
+
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/pptx-craft" alt="license"></a>
|
|
16
|
+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.6+-3178C6?logo=typescript&logoColor=white" alt="TypeScript"></a>
|
|
17
|
+
<a href="https://dxsun97.github.io/pptx-craft"><img src="https://img.shields.io/badge/docs-online-FF6B42" alt="docs"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
## 安装
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install pptx-craft
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 快速开始
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { Presentation } from 'pptx-craft';
|
|
30
|
+
|
|
31
|
+
const pptx = new Presentation();
|
|
32
|
+
const slide = pptx.addSlide();
|
|
33
|
+
|
|
34
|
+
slide.addText('Hello World', {
|
|
35
|
+
x: 1,
|
|
36
|
+
y: 1,
|
|
37
|
+
w: 8,
|
|
38
|
+
h: 1.5,
|
|
39
|
+
fontSize: 44,
|
|
40
|
+
color: '003366',
|
|
41
|
+
bold: true,
|
|
42
|
+
align: 'center',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
slide.addShape('rect', { x: 1, y: 3, w: 8, h: 0.05, fill: '4472C4' });
|
|
46
|
+
|
|
47
|
+
await pptx.toFile('output.pptx');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 特性
|
|
51
|
+
|
|
52
|
+
- **文本** — 字体、大小、颜色、粗体/斜体/下划线、对齐方式、行距
|
|
53
|
+
- **图片** — 支持文件路径或 Buffer(PNG、JPEG 等)
|
|
54
|
+
- **形状** — 矩形、椭圆、圆角矩形、菱形、三角形、心形、星形、箭头等
|
|
55
|
+
- **表格** — 单元格级别格式化、边框、自定义列宽/行高
|
|
56
|
+
- **图表** — 柱状图、条形图、折线图、饼图、面积图、散点图、环形图(原生 PowerPoint 图表)
|
|
57
|
+
- **媒体** — 视频和音频嵌入
|
|
58
|
+
- **母版与版式** — 自定义背景、基于占位符的版式布局
|
|
59
|
+
- **主题** — 完整的配色方案和字体自定义
|
|
60
|
+
- **演讲者备注** — 逐页添加备注
|
|
61
|
+
- **插件** — 通过自定义元素类型进行扩展
|
|
62
|
+
|
|
63
|
+
## 预览
|
|
64
|
+
|
|
65
|
+
<table>
|
|
66
|
+
<tr>
|
|
67
|
+
<td><img src="docs/public/previews/quick-example-1.png" alt="标题页" width="400"></td>
|
|
68
|
+
<td><img src="docs/public/previews/quick-example-2.png" alt="表格" width="400"></td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td><img src="docs/public/previews/quick-example-3.png" alt="图表" width="400"></td>
|
|
72
|
+
<td><img src="docs/public/previews/quick-example-4.png" alt="形状" width="400"></td>
|
|
73
|
+
</tr>
|
|
74
|
+
</table>
|
|
75
|
+
|
|
76
|
+
## 示例
|
|
77
|
+
|
|
78
|
+
### 表格
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
slide.addTable(
|
|
82
|
+
[
|
|
83
|
+
[
|
|
84
|
+
{ text: 'Name', options: { bold: true, fill: '4472C4', color: 'FFFFFF' } },
|
|
85
|
+
{ text: 'Score', options: { bold: true, fill: '4472C4', color: 'FFFFFF' } },
|
|
86
|
+
],
|
|
87
|
+
[{ text: 'Alice' }, { text: '95' }],
|
|
88
|
+
[{ text: 'Bob' }, { text: '87' }],
|
|
89
|
+
],
|
|
90
|
+
{ x: 1, y: 1, w: 6, h: 3, border: { color: 'CCCCCC', width: 1 } },
|
|
91
|
+
);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 图表
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
slide.addChart(
|
|
98
|
+
'col',
|
|
99
|
+
{
|
|
100
|
+
categories: ['Q1', 'Q2', 'Q3', 'Q4'],
|
|
101
|
+
series: [
|
|
102
|
+
{ name: '2024', values: [120, 180, 150, 210], color: '4472C4' },
|
|
103
|
+
{ name: '2025', values: [140, 200, 190, 250], color: 'ED7D31' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{ x: 1, y: 1, w: 8, h: 5, title: 'Revenue', showLegend: true },
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 母版与版式
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const pptx = new Presentation();
|
|
114
|
+
pptx.defineSlideMaster({ name: 'Corporate', background: '003366' });
|
|
115
|
+
pptx.defineLayout({
|
|
116
|
+
name: 'Title Slide',
|
|
117
|
+
type: 'titleAndContent',
|
|
118
|
+
placeholders: [
|
|
119
|
+
{ type: 'title', placement: { x: 0.5, y: 0.5, w: 9, h: 1 }, idx: 0 },
|
|
120
|
+
{ type: 'body', placement: { x: 0.5, y: 2, w: 9, h: 5 }, idx: 1 },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const slide = pptx.addSlide('Title Slide');
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 插件
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import type { IPlugin } from 'pptx-craft';
|
|
131
|
+
|
|
132
|
+
const myPlugin: IPlugin = {
|
|
133
|
+
name: 'my-plugin',
|
|
134
|
+
install(registry) {
|
|
135
|
+
registry.registerElement('badge', badgeSerializer);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
pptx.use(myPlugin);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## 输出
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// Buffer
|
|
146
|
+
const buffer = pptx.toBuffer();
|
|
147
|
+
|
|
148
|
+
// 文件
|
|
149
|
+
await pptx.toFile('presentation.pptx');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 文档
|
|
153
|
+
|
|
154
|
+
完整文档请访问[文档站点](https://dxsun97.github.io/pptx-craft)。本地运行:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
npm run docs:dev
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 致谢
|
|
161
|
+
|
|
162
|
+
本项目基于 Brent Ely 的 [PptxGenJS](https://github.com/gitbrent/PptxGenJS) 衍生开发。
|
|
163
|
+
|
|
164
|
+
## 许可证
|
|
165
|
+
|
|
166
|
+
MIT — 详见 [LICENSE](./LICENSE)。
|