pptxtojson 1.1.1 → 1.2.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 +55 -37
- package/dist/index.d.ts +34 -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/chart.js +41 -1
- package/src/fill.js +72 -37
- package/src/pptxtojson.js +167 -174
- 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.0",
|
|
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/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,48 @@ 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 = 90
|
|
116
|
+
if (lin) rot = angleToDegrees(lin['attrs']['ang']) + 90
|
|
117
|
+
return {
|
|
118
|
+
rot,
|
|
119
|
+
colors: colors.sort((a, b) => parseInt(a.pos) - parseInt(b.pos)),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
86
123
|
export function getBgGradientFill(bgPr, phClr, slideMasterContent, warpObj) {
|
|
87
124
|
if (bgPr) {
|
|
88
125
|
const grdFill = bgPr['a:gradFill']
|
|
89
126
|
const gsLst = grdFill['a:gsLst']['a:gs']
|
|
90
|
-
const
|
|
127
|
+
const colors = []
|
|
91
128
|
|
|
92
129
|
for (let i = 0; i < gsLst.length; i++) {
|
|
93
130
|
const lo_color = getSolidFill(gsLst[i], slideMasterContent['p:sldMaster']['p:clrMap']['attrs'], phClr, warpObj)
|
|
94
131
|
const pos = getTextByPathList(gsLst[i], ['attrs', 'pos'])
|
|
95
132
|
|
|
96
|
-
|
|
133
|
+
colors[i] = {
|
|
97
134
|
pos: pos ? (pos / 1000 + '%') : '',
|
|
98
135
|
color: lo_color,
|
|
99
136
|
}
|
|
100
137
|
}
|
|
101
138
|
const lin = grdFill['a:lin']
|
|
102
139
|
let rot = 90
|
|
103
|
-
if (lin)
|
|
104
|
-
rot = angleToDegrees(lin['attrs']['ang'])
|
|
105
|
-
rot = rot + 90
|
|
106
|
-
}
|
|
107
|
-
|
|
140
|
+
if (lin) rot = angleToDegrees(lin['attrs']['ang']) + 90
|
|
108
141
|
return {
|
|
109
142
|
rot,
|
|
110
|
-
colors:
|
|
143
|
+
colors: colors.sort((a, b) => parseInt(a.pos) - parseInt(b.pos)),
|
|
111
144
|
}
|
|
112
145
|
}
|
|
113
146
|
else if (phClr) {
|
|
@@ -414,41 +447,43 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
414
447
|
}
|
|
415
448
|
}
|
|
416
449
|
|
|
417
|
-
export function getShapeFill(node, isSvgMode, warpObj) {
|
|
418
|
-
|
|
450
|
+
export async function getShapeFill(node, isSvgMode, warpObj, source) {
|
|
451
|
+
const fillType = getFillType(getTextByPathList(node, ['p:spPr']))
|
|
452
|
+
let type = 'color'
|
|
453
|
+
let fillValue = ''
|
|
454
|
+
if (fillType === 'NO_FILL') {
|
|
419
455
|
return isSvgMode ? 'none' : ''
|
|
456
|
+
}
|
|
457
|
+
else if (fillType === 'SOLID_FILL') {
|
|
458
|
+
const shpFill = node['p:spPr']['a:solidFill']
|
|
459
|
+
fillValue = getSolidFill(shpFill, undefined, undefined, warpObj)
|
|
460
|
+
type = 'color'
|
|
420
461
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
462
|
+
else if (fillType === 'GRADIENT_FILL') {
|
|
463
|
+
const shpFill = node['p:spPr']['a:gradFill']
|
|
464
|
+
fillValue = getGradientFill(shpFill, warpObj)
|
|
465
|
+
type = 'gradient'
|
|
425
466
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
|
|
467
|
+
else if (fillType === 'PIC_FILL') {
|
|
468
|
+
const shpFill = node['p:spPr']['a:blipFill']
|
|
469
|
+
const picBase64 = await getPicFill(source, shpFill, warpObj)
|
|
470
|
+
const opacity = getPicFillOpacity(shpFill)
|
|
471
|
+
fillValue = {
|
|
472
|
+
picBase64,
|
|
473
|
+
opacity,
|
|
474
|
+
}
|
|
475
|
+
type = 'image'
|
|
430
476
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
477
|
+
if (!fillValue) {
|
|
478
|
+
const clrName = getTextByPathList(node, ['p:style', 'a:fillRef'])
|
|
479
|
+
fillValue = getSolidFill(clrName, undefined, undefined, warpObj)
|
|
480
|
+
type = 'color'
|
|
435
481
|
}
|
|
436
482
|
|
|
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
|
|
483
|
+
return {
|
|
484
|
+
type,
|
|
485
|
+
value: fillValue,
|
|
486
|
+
}
|
|
452
487
|
}
|
|
453
488
|
|
|
454
489
|
export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|