pptxtojson 1.1.1 → 1.2.1
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 +55 -37
- package/dist/index.d.ts +35 -30
- 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/dist/wx.png +0 -0
- package/index.html +1 -1
- package/package.json +2 -2
- package/src/border.js +12 -2
- package/src/chart.js +41 -1
- package/src/fill.js +84 -37
- package/src/pptxtojson.js +172 -175
- package/src/table.js +6 -2
- package/src/utils.js +0 -2
package/dist/wx.png
ADDED
|
Binary file
|
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pptxtojson",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A javascript tool for parsing .pptx file",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"homepage": "https://github.com/pipipi-pikachu/pptxtojson",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"publishConfig": {
|
|
27
|
-
"registry": "https://registry.npmjs.
|
|
27
|
+
"registry": "https://registry.npmjs.org"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"jszip": "^3.10.1",
|
package/src/border.js
CHANGED
|
@@ -3,9 +3,19 @@ import { getSchemeColorFromTheme } from './schemeColor'
|
|
|
3
3
|
import { getTextByPathList } from './utils'
|
|
4
4
|
|
|
5
5
|
export function getBorder(node, elType, warpObj) {
|
|
6
|
-
|
|
6
|
+
let lineNode = node['p:spPr']['a:ln']
|
|
7
|
+
if (!lineNode) {
|
|
8
|
+
const lnRefNode = getTextByPathList(node, ['p:style', 'a:lnRef'])
|
|
9
|
+
if (lnRefNode) {
|
|
10
|
+
const lnIdx = getTextByPathList(lnRefNode, ['attrs', 'idx'])
|
|
11
|
+
lineNode = warpObj['themeContent']['a:theme']['a:themeElements']['a:fmtScheme']['a:lnStyleLst']['a:ln'][Number(lnIdx) - 1]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (!lineNode) lineNode = node
|
|
15
|
+
|
|
16
|
+
const isNoFill = getTextByPathList(lineNode, ['a:noFill'])
|
|
7
17
|
|
|
8
|
-
let borderWidth = parseInt(getTextByPathList(lineNode, ['attrs', 'w'])) / 12700
|
|
18
|
+
let borderWidth = isNoFill ? 0 : (parseInt(getTextByPathList(lineNode, ['attrs', 'w'])) / 12700)
|
|
9
19
|
if (isNaN(borderWidth)) {
|
|
10
20
|
if (lineNode) borderWidth = 0
|
|
11
21
|
else if (elType !== 'obj') borderWidth = 0
|
package/src/chart.js
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { eachElement, getTextByPathList } from './utils'
|
|
2
|
+
import { applyTint } from './color'
|
|
3
|
+
|
|
4
|
+
function extractChartColors(serNode, warpObj) {
|
|
5
|
+
if (serNode.constructor !== Array) serNode = [serNode]
|
|
6
|
+
const schemeClrs = []
|
|
7
|
+
for (const node of serNode) {
|
|
8
|
+
let schemeClr = getTextByPathList(node, ['c:spPr', 'a:solidFill', 'a:schemeClr'])
|
|
9
|
+
if (!schemeClr) schemeClr = getTextByPathList(node, ['c:spPr', 'a:ln', 'a:solidFill', 'a:schemeClr'])
|
|
10
|
+
if (!schemeClr) schemeClr = getTextByPathList(node, ['c:marker', 'c:spPr', 'a:ln', 'a:solidFill', 'a:schemeClr'])
|
|
11
|
+
|
|
12
|
+
let clr = getTextByPathList(schemeClr, ['attrs', 'val'])
|
|
13
|
+
if (clr) {
|
|
14
|
+
clr = getTextByPathList(warpObj['themeContent'], ['a:theme', 'a:themeElements', 'a:clrScheme', `a:${clr}`, 'a:srgbClr', 'attrs', 'val'])
|
|
15
|
+
const tint = getTextByPathList(schemeClr, ['a:tint', 'attrs', 'val']) / 100000
|
|
16
|
+
if (clr && !isNaN(tint)) {
|
|
17
|
+
clr = applyTint(clr, tint)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else clr = getTextByPathList(node, ['c:spPr', 'a:solidFill', 'a:srgbClr', 'attrs', 'val'])
|
|
21
|
+
|
|
22
|
+
if (clr) clr = '#' + clr
|
|
23
|
+
schemeClrs.push(clr)
|
|
24
|
+
}
|
|
25
|
+
return schemeClrs
|
|
26
|
+
}
|
|
2
27
|
|
|
3
28
|
function extractChartData(serNode) {
|
|
4
29
|
const dataMat = []
|
|
@@ -59,7 +84,7 @@ function extractChartData(serNode) {
|
|
|
59
84
|
return dataMat
|
|
60
85
|
}
|
|
61
86
|
|
|
62
|
-
export function getChartInfo(plotArea) {
|
|
87
|
+
export function getChartInfo(plotArea, warpObj) {
|
|
63
88
|
let chart = null
|
|
64
89
|
for (const key in plotArea) {
|
|
65
90
|
switch (key) {
|
|
@@ -67,6 +92,7 @@ export function getChartInfo(plotArea) {
|
|
|
67
92
|
chart = {
|
|
68
93
|
type: 'lineChart',
|
|
69
94
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
95
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
70
96
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
71
97
|
marker: plotArea[key]['c:marker'] ? true : false,
|
|
72
98
|
}
|
|
@@ -75,6 +101,7 @@ export function getChartInfo(plotArea) {
|
|
|
75
101
|
chart = {
|
|
76
102
|
type: 'line3DChart',
|
|
77
103
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
104
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
78
105
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
79
106
|
}
|
|
80
107
|
break
|
|
@@ -82,6 +109,7 @@ export function getChartInfo(plotArea) {
|
|
|
82
109
|
chart = {
|
|
83
110
|
type: 'barChart',
|
|
84
111
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
112
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
85
113
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
86
114
|
barDir: getTextByPathList(plotArea[key], ['c:barDir', 'attrs', 'val']),
|
|
87
115
|
}
|
|
@@ -90,6 +118,7 @@ export function getChartInfo(plotArea) {
|
|
|
90
118
|
chart = {
|
|
91
119
|
type: 'bar3DChart',
|
|
92
120
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
121
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
93
122
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
94
123
|
barDir: getTextByPathList(plotArea[key], ['c:barDir', 'attrs', 'val']),
|
|
95
124
|
}
|
|
@@ -98,18 +127,21 @@ export function getChartInfo(plotArea) {
|
|
|
98
127
|
chart = {
|
|
99
128
|
type: 'pieChart',
|
|
100
129
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
130
|
+
colors: extractChartColors(plotArea[key]['c:ser']['c:dPt'], warpObj),
|
|
101
131
|
}
|
|
102
132
|
break
|
|
103
133
|
case 'c:pie3DChart':
|
|
104
134
|
chart = {
|
|
105
135
|
type: 'pie3DChart',
|
|
106
136
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
137
|
+
colors: extractChartColors(plotArea[key]['c:ser']['c:dPt'], warpObj),
|
|
107
138
|
}
|
|
108
139
|
break
|
|
109
140
|
case 'c:doughnutChart':
|
|
110
141
|
chart = {
|
|
111
142
|
type: 'doughnutChart',
|
|
112
143
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
144
|
+
colors: extractChartColors(plotArea[key]['c:ser']['c:dPt'], warpObj),
|
|
113
145
|
holeSize: getTextByPathList(plotArea[key], ['c:holeSize', 'attrs', 'val']),
|
|
114
146
|
}
|
|
115
147
|
break
|
|
@@ -117,6 +149,7 @@ export function getChartInfo(plotArea) {
|
|
|
117
149
|
chart = {
|
|
118
150
|
type: 'areaChart',
|
|
119
151
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
152
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
120
153
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
121
154
|
}
|
|
122
155
|
break
|
|
@@ -124,6 +157,7 @@ export function getChartInfo(plotArea) {
|
|
|
124
157
|
chart = {
|
|
125
158
|
type: 'area3DChart',
|
|
126
159
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
160
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
127
161
|
grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
|
|
128
162
|
}
|
|
129
163
|
break
|
|
@@ -131,6 +165,7 @@ export function getChartInfo(plotArea) {
|
|
|
131
165
|
chart = {
|
|
132
166
|
type: 'scatterChart',
|
|
133
167
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
168
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
134
169
|
style: getTextByPathList(plotArea[key], ['c:scatterStyle', 'attrs', 'val']),
|
|
135
170
|
}
|
|
136
171
|
break
|
|
@@ -138,12 +173,14 @@ export function getChartInfo(plotArea) {
|
|
|
138
173
|
chart = {
|
|
139
174
|
type: 'bubbleChart',
|
|
140
175
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
176
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
141
177
|
}
|
|
142
178
|
break
|
|
143
179
|
case 'c:radarChart':
|
|
144
180
|
chart = {
|
|
145
181
|
type: 'radarChart',
|
|
146
182
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
183
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
147
184
|
style: getTextByPathList(plotArea[key], ['c:radarStyle', 'attrs', 'val']),
|
|
148
185
|
}
|
|
149
186
|
break
|
|
@@ -151,18 +188,21 @@ export function getChartInfo(plotArea) {
|
|
|
151
188
|
chart = {
|
|
152
189
|
type: 'surfaceChart',
|
|
153
190
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
191
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
154
192
|
}
|
|
155
193
|
break
|
|
156
194
|
case 'c:surface3DChart':
|
|
157
195
|
chart = {
|
|
158
196
|
type: 'surface3DChart',
|
|
159
197
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
198
|
+
colors: extractChartColors(plotArea[key]['c:ser'], warpObj),
|
|
160
199
|
}
|
|
161
200
|
break
|
|
162
201
|
case 'c:stockChart':
|
|
163
202
|
chart = {
|
|
164
203
|
type: 'stockChart',
|
|
165
204
|
data: extractChartData(plotArea[key]['c:ser']),
|
|
205
|
+
colors: [],
|
|
166
206
|
}
|
|
167
207
|
break
|
|
168
208
|
default:
|
package/src/fill.js
CHANGED
|
@@ -63,10 +63,26 @@ export async function getPicFill(type, node, warpObj) {
|
|
|
63
63
|
const imgArrayBuffer = await warpObj['zip'].file(imgPath).async('arraybuffer')
|
|
64
64
|
const imgMimeType = getMimeType(imgExt)
|
|
65
65
|
img = `data:${imgMimeType};base64,${base64ArrayBuffer(imgArrayBuffer)}`
|
|
66
|
+
|
|
67
|
+
const loadedImages = warpObj['loaded-images'] || {}
|
|
68
|
+
loadedImages[imgPath] = img
|
|
69
|
+
warpObj['loaded-images'] = loadedImages
|
|
66
70
|
}
|
|
67
71
|
return img
|
|
68
72
|
}
|
|
69
73
|
|
|
74
|
+
export function getPicFillOpacity(node) {
|
|
75
|
+
const aBlipNode = node['a:blip']
|
|
76
|
+
|
|
77
|
+
const aphaModFixNode = getTextByPathList(aBlipNode, ['a:alphaModFix', 'attrs'])
|
|
78
|
+
let opacity = 1
|
|
79
|
+
if (aphaModFixNode && aphaModFixNode['amt'] && aphaModFixNode['amt'] !== '') {
|
|
80
|
+
opacity = parseInt(aphaModFixNode['amt']) / 100000
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return opacity
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
export async function getBgPicFill(bgPr, sorce, warpObj) {
|
|
71
87
|
const picBase64 = await getPicFill(sorce, bgPr['a:blipFill'], warpObj)
|
|
72
88
|
const aBlipNode = bgPr['a:blipFill']['a:blip']
|
|
@@ -83,31 +99,60 @@ export async function getBgPicFill(bgPr, sorce, warpObj) {
|
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
|
|
102
|
+
export function getGradientFill(node, warpObj) {
|
|
103
|
+
const gsLst = node['a:gsLst']['a:gs']
|
|
104
|
+
const colors = []
|
|
105
|
+
for (let i = 0; i < gsLst.length; i++) {
|
|
106
|
+
const lo_color = getSolidFill(gsLst[i], undefined, undefined, warpObj)
|
|
107
|
+
const pos = getTextByPathList(gsLst[i], ['attrs', 'pos'])
|
|
108
|
+
|
|
109
|
+
colors[i] = {
|
|
110
|
+
pos: pos ? (pos / 1000 + '%') : '',
|
|
111
|
+
color: lo_color,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const lin = node['a:lin']
|
|
115
|
+
let rot = 0
|
|
116
|
+
let pathType = 'line'
|
|
117
|
+
if (lin) rot = angleToDegrees(lin['attrs']['ang'])
|
|
118
|
+
else {
|
|
119
|
+
const path = node['a:path']
|
|
120
|
+
if (path && path['attrs'] && path['attrs']['path']) pathType = path['attrs']['path']
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
rot,
|
|
124
|
+
path: pathType,
|
|
125
|
+
colors: colors.sort((a, b) => parseInt(a.pos) - parseInt(b.pos)),
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
86
129
|
export function getBgGradientFill(bgPr, phClr, slideMasterContent, warpObj) {
|
|
87
130
|
if (bgPr) {
|
|
88
131
|
const grdFill = bgPr['a:gradFill']
|
|
89
132
|
const gsLst = grdFill['a:gsLst']['a:gs']
|
|
90
|
-
const
|
|
133
|
+
const colors = []
|
|
91
134
|
|
|
92
135
|
for (let i = 0; i < gsLst.length; i++) {
|
|
93
136
|
const lo_color = getSolidFill(gsLst[i], slideMasterContent['p:sldMaster']['p:clrMap']['attrs'], phClr, warpObj)
|
|
94
137
|
const pos = getTextByPathList(gsLst[i], ['attrs', 'pos'])
|
|
95
138
|
|
|
96
|
-
|
|
139
|
+
colors[i] = {
|
|
97
140
|
pos: pos ? (pos / 1000 + '%') : '',
|
|
98
141
|
color: lo_color,
|
|
99
142
|
}
|
|
100
143
|
}
|
|
101
144
|
const lin = grdFill['a:lin']
|
|
102
|
-
let rot =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
145
|
+
let rot = 0
|
|
146
|
+
let pathType = 'line'
|
|
147
|
+
if (lin) rot = angleToDegrees(lin['attrs']['ang']) + 0
|
|
148
|
+
else {
|
|
149
|
+
const path = grdFill['a:path']
|
|
150
|
+
if (path && path['attrs'] && path['attrs']['path']) pathType = path['attrs']['path']
|
|
106
151
|
}
|
|
107
|
-
|
|
108
152
|
return {
|
|
109
153
|
rot,
|
|
110
|
-
|
|
154
|
+
path: pathType,
|
|
155
|
+
colors: colors.sort((a, b) => parseInt(a.pos) - parseInt(b.pos)),
|
|
111
156
|
}
|
|
112
157
|
}
|
|
113
158
|
else if (phClr) {
|
|
@@ -414,41 +459,43 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
414
459
|
}
|
|
415
460
|
}
|
|
416
461
|
|
|
417
|
-
export function getShapeFill(node, isSvgMode, warpObj) {
|
|
418
|
-
|
|
462
|
+
export async function getShapeFill(node, isSvgMode, warpObj, source) {
|
|
463
|
+
const fillType = getFillType(getTextByPathList(node, ['p:spPr']))
|
|
464
|
+
let type = 'color'
|
|
465
|
+
let fillValue = ''
|
|
466
|
+
if (fillType === 'NO_FILL') {
|
|
419
467
|
return isSvgMode ? 'none' : ''
|
|
468
|
+
}
|
|
469
|
+
else if (fillType === 'SOLID_FILL') {
|
|
470
|
+
const shpFill = node['p:spPr']['a:solidFill']
|
|
471
|
+
fillValue = getSolidFill(shpFill, undefined, undefined, warpObj)
|
|
472
|
+
type = 'color'
|
|
420
473
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
474
|
+
else if (fillType === 'GRADIENT_FILL') {
|
|
475
|
+
const shpFill = node['p:spPr']['a:gradFill']
|
|
476
|
+
fillValue = getGradientFill(shpFill, warpObj)
|
|
477
|
+
type = 'gradient'
|
|
425
478
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
|
|
479
|
+
else if (fillType === 'PIC_FILL') {
|
|
480
|
+
const shpFill = node['p:spPr']['a:blipFill']
|
|
481
|
+
const picBase64 = await getPicFill(source, shpFill, warpObj)
|
|
482
|
+
const opacity = getPicFillOpacity(shpFill)
|
|
483
|
+
fillValue = {
|
|
484
|
+
picBase64,
|
|
485
|
+
opacity,
|
|
486
|
+
}
|
|
487
|
+
type = 'image'
|
|
430
488
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
489
|
+
if (!fillValue) {
|
|
490
|
+
const clrName = getTextByPathList(node, ['p:style', 'a:fillRef'])
|
|
491
|
+
fillValue = getSolidFill(clrName, undefined, undefined, warpObj)
|
|
492
|
+
type = 'color'
|
|
435
493
|
}
|
|
436
494
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
let lumOff = parseInt(getTextByPathList(node, ['p:spPr', 'a:solidFill', 'a:schemeClr', 'a:lumOff', 'attrs', 'val'])) / 100000
|
|
442
|
-
if (isNaN(lumMod)) lumMod = 1.0
|
|
443
|
-
if (isNaN(lumOff)) lumOff = 0
|
|
444
|
-
|
|
445
|
-
const color = tinycolor(fillColor).toHsl()
|
|
446
|
-
const lum = color.l * lumMod + lumOff
|
|
447
|
-
return tinycolor({ h: color.h, s: color.s, l: lum, a: color.a }).toHexString()
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (isSvgMode) return 'none'
|
|
451
|
-
return fillColor
|
|
495
|
+
return {
|
|
496
|
+
type,
|
|
497
|
+
value: fillValue,
|
|
498
|
+
}
|
|
452
499
|
}
|
|
453
500
|
|
|
454
501
|
export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|