pptxtojson 0.0.13 → 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/README.md +9 -6
- package/dist/index.d.ts +67 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/index.html +4 -1
- package/package.json +2 -2
- package/src/align.js +36 -0
- package/src/border.js +95 -0
- package/src/chart.js +173 -0
- package/src/color.js +168 -0
- package/src/fill.js +330 -0
- package/src/fontStyle.js +105 -0
- package/src/position.js +29 -0
- package/src/pptxtojson.js +248 -1070
- package/src/readXmlFile.js +41 -0
- package/src/schemeColor.js +24 -0
- package/src/shadow.js +18 -0
- package/src/shape.js +178 -0
- package/src/text.js +131 -0
- package/src/utils.js +16 -3
- package/test.pptx +0 -0
- package/test2.pptx +0 -0
- package/test3.pptx +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# 🎨 PPTX2JSON
|
|
2
|
-
|
|
2
|
+
这是一个可以将PPT幻灯片(.pptx)文件解析为 JSON 数据的库。
|
|
3
3
|
|
|
4
4
|
在线DEMO:https://pipipi-pikachu.github.io/pptx2json/
|
|
5
5
|
|
|
6
|
-
相较于原版:
|
|
7
|
-
- 使用更现代的语法和依赖重写(原项目年代较久远),方便阅读和理解;
|
|
8
|
-
- 删除了所有非核心代码,仅关注 XML 的解析过程;
|
|
9
|
-
- 输出 JSON 格式的解析结果;
|
|
10
6
|
|
|
11
7
|
# 🔨安装
|
|
12
8
|
> npm install pptxtojson
|
|
@@ -19,18 +15,25 @@
|
|
|
19
15
|
```js
|
|
20
16
|
import { parse } from 'pptxtojson'
|
|
21
17
|
|
|
18
|
+
const options = {
|
|
19
|
+
slideFactor: 75 / 914400, // 幻灯片尺寸转换因子,默认 96 / 914400
|
|
20
|
+
fontsizeFactor: 100 / 96, // 字号转换因子,默认 100 / 75
|
|
21
|
+
}
|
|
22
|
+
|
|
22
23
|
document.querySelector('input').addEventListener('change', evt => {
|
|
23
24
|
const file = evt.target.files[0]
|
|
24
25
|
|
|
25
26
|
const reader = new FileReader()
|
|
26
27
|
reader.onload = async e => {
|
|
27
|
-
const json = await parse(e.target.result)
|
|
28
|
+
const json = await parse(e.target.result, options)
|
|
28
29
|
console.log(json)
|
|
29
30
|
}
|
|
30
31
|
reader.readAsArrayBuffer(file)
|
|
31
32
|
})
|
|
32
33
|
```
|
|
33
34
|
|
|
35
|
+
# 🙏 感谢
|
|
36
|
+
> 本仓库主要参考了 [PPTX2HTML](https://github.com/g21589/PPTX2HTML) 、[PPTXjs](https://github.com/meshesha/PPTXjs) 的实现
|
|
34
37
|
|
|
35
38
|
# 📄 开源协议
|
|
36
39
|
AGPL-3.0 License | Copyright © 2020-PRESENT [pipipi-pikachu](https://github.com/pipipi-pikachu)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export interface Shadow {
|
|
2
|
+
h: number
|
|
3
|
+
v: number
|
|
4
|
+
blur: number
|
|
5
|
+
color: string
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
export interface Shape {
|
|
2
9
|
type: 'shape'
|
|
3
10
|
left: number
|
|
@@ -8,7 +15,9 @@ export interface Shape {
|
|
|
8
15
|
cy: number
|
|
9
16
|
borderColor: string
|
|
10
17
|
borderWidth: number
|
|
11
|
-
borderType: 'solid' | 'dashed'
|
|
18
|
+
borderType: 'solid' | 'dashed' | 'dotted'
|
|
19
|
+
borderStrokeDasharray: string
|
|
20
|
+
shadow?: Shadow
|
|
12
21
|
fillColor: string
|
|
13
22
|
content: string
|
|
14
23
|
isFlipV: boolean
|
|
@@ -29,10 +38,13 @@ export interface Text {
|
|
|
29
38
|
height: number
|
|
30
39
|
borderColor: string
|
|
31
40
|
borderWidth: number
|
|
32
|
-
borderType: 'solid' | 'dashed'
|
|
41
|
+
borderType: 'solid' | 'dashed' | 'dotted'
|
|
42
|
+
borderStrokeDasharray: string
|
|
43
|
+
shadow?: Shadow
|
|
33
44
|
fillColor: string
|
|
34
45
|
isFlipV: boolean
|
|
35
46
|
isFlipH: boolean
|
|
47
|
+
isVertical: boolean
|
|
36
48
|
rotate: number
|
|
37
49
|
content: string
|
|
38
50
|
vAlign: string
|
|
@@ -66,7 +78,22 @@ export interface Table {
|
|
|
66
78
|
data: TableCell[][]
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
export type ChartType = 'lineChart' |
|
|
81
|
+
export type ChartType = 'lineChart' |
|
|
82
|
+
'line3DChart' |
|
|
83
|
+
'barChart' |
|
|
84
|
+
'bar3DChart' |
|
|
85
|
+
'pieChart' |
|
|
86
|
+
'pie3DChart' |
|
|
87
|
+
'doughnutChart' |
|
|
88
|
+
'areaChart' |
|
|
89
|
+
'area3DChart' |
|
|
90
|
+
'scatterChart' |
|
|
91
|
+
'bubbleChart' |
|
|
92
|
+
'radarChart' |
|
|
93
|
+
'surfaceChart' |
|
|
94
|
+
'surface3DChart' |
|
|
95
|
+
'stockChart'
|
|
96
|
+
|
|
70
97
|
export interface ChartValue {
|
|
71
98
|
x: string
|
|
72
99
|
y: number
|
|
@@ -86,8 +113,13 @@ export interface CommonChart {
|
|
|
86
113
|
top: number
|
|
87
114
|
width: number
|
|
88
115
|
height: number
|
|
89
|
-
data: ChartItem[]
|
|
116
|
+
data: ChartItem[]
|
|
90
117
|
chartType: ChartType
|
|
118
|
+
barDir?: 'bar' | 'col'
|
|
119
|
+
marker?: boolean
|
|
120
|
+
holeSize?: string
|
|
121
|
+
grouping?: string
|
|
122
|
+
style?: string
|
|
91
123
|
}
|
|
92
124
|
export interface ScatterChart {
|
|
93
125
|
type: 'chart'
|
|
@@ -100,15 +132,35 @@ export interface ScatterChart {
|
|
|
100
132
|
}
|
|
101
133
|
export type Chart = CommonChart | ScatterChart
|
|
102
134
|
|
|
135
|
+
export interface Video {
|
|
136
|
+
type: 'video'
|
|
137
|
+
left: number
|
|
138
|
+
top: number
|
|
139
|
+
width: number
|
|
140
|
+
height: number
|
|
141
|
+
blob?: string
|
|
142
|
+
src?: string
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface Audio {
|
|
146
|
+
type: 'audio'
|
|
147
|
+
left: number
|
|
148
|
+
top: number
|
|
149
|
+
width: number
|
|
150
|
+
height: number
|
|
151
|
+
blob: string
|
|
152
|
+
}
|
|
153
|
+
|
|
103
154
|
export interface Diagram {
|
|
104
155
|
type: 'diagram'
|
|
105
156
|
left: number
|
|
106
157
|
top: number
|
|
107
158
|
width: number
|
|
108
159
|
height: number
|
|
160
|
+
elements: (Shape | Text)[]
|
|
109
161
|
}
|
|
110
162
|
|
|
111
|
-
export type BaseElement = Shape | Text | Image | Table | Chart | Diagram
|
|
163
|
+
export type BaseElement = Shape | Text | Image | Table | Chart | Video | Audio | Diagram
|
|
112
164
|
|
|
113
165
|
export interface Group {
|
|
114
166
|
type: 'group'
|
|
@@ -137,8 +189,10 @@ export interface SlideGradientFill {
|
|
|
137
189
|
type: 'gradient'
|
|
138
190
|
value: {
|
|
139
191
|
rot: number
|
|
140
|
-
colors:
|
|
141
|
-
|
|
192
|
+
colors: {
|
|
193
|
+
pos: string
|
|
194
|
+
color: string
|
|
195
|
+
}[]
|
|
142
196
|
}
|
|
143
197
|
}
|
|
144
198
|
|
|
@@ -149,7 +203,12 @@ export interface Slide {
|
|
|
149
203
|
elements: Element[]
|
|
150
204
|
}
|
|
151
205
|
|
|
152
|
-
export
|
|
206
|
+
export interface Options {
|
|
207
|
+
slideFactor?: number
|
|
208
|
+
fontsizeFactor?: number
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const parse: (file: ArrayBuffer, options?: Options) => Promise<{
|
|
153
212
|
slides: Slide[]
|
|
154
213
|
size: {
|
|
155
214
|
width: number
|