pptxtojson 0.1.1 → 0.1.3
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 +21 -661
- package/README.md +169 -3
- package/dist/index.d.ts +5 -6
- 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/package.json +2 -2
- package/src/align.js +43 -14
- package/src/fill.js +10 -1
- package/src/fontStyle.js +7 -9
- package/src/position.js +4 -4
- package/src/pptxtojson.js +174 -95
- package/src/readXmlFile.js +4 -2
- package/src/shadow.js +5 -4
- package/src/shape.js +12 -3
- package/src/text.js +13 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pptxtojson",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A javascript tool for parsing .pptx file",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"lint": "eslint src --ext .js,.jsx,.ts,.tsx"
|
|
13
13
|
},
|
|
14
14
|
"author": "",
|
|
15
|
-
"license": "
|
|
15
|
+
"license": "MIT",
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"registry": "https://registry.npmjs.com/"
|
|
18
18
|
},
|
package/src/align.js
CHANGED
|
@@ -1,26 +1,55 @@
|
|
|
1
1
|
import { getTextByPathList } from './utils'
|
|
2
2
|
|
|
3
|
-
export function getHorizontalAlign(node,
|
|
3
|
+
export function getHorizontalAlign(node, pNode, type, warpObj) {
|
|
4
4
|
let algn = getTextByPathList(node, ['a:pPr', 'attrs', 'algn'])
|
|
5
|
+
if (!algn) algn = getTextByPathList(pNode, ['a:pPr', 'attrs', 'algn'])
|
|
5
6
|
|
|
6
|
-
if (!algn) algn = getTextByPathList(slideLayoutSpNode, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
|
|
7
|
-
if (!algn) algn = getTextByPathList(slideMasterSpNode, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
|
|
8
7
|
if (!algn) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
if (type === 'title' || type === 'ctrTitle' || type === 'subTitle') {
|
|
9
|
+
let lvlIdx = 1
|
|
10
|
+
const lvlNode = getTextByPathList(pNode, ['a:pPr', 'attrs', 'lvl'])
|
|
11
|
+
if (lvlNode) {
|
|
12
|
+
lvlIdx = parseInt(lvlNode) + 1
|
|
13
|
+
}
|
|
14
|
+
const lvlStr = 'a:lvl' + lvlIdx + 'pPr'
|
|
15
|
+
algn = getTextByPathList(warpObj, ['slideLayoutTables', 'typeTable', type, 'p:txBody', 'a:lstStyle', lvlStr, 'attrs', 'algn'])
|
|
16
|
+
if (!algn) algn = getTextByPathList(warpObj, ['slideMasterTables', 'typeTable', type, 'p:txBody', 'a:lstStyle', lvlStr, 'attrs', 'algn'])
|
|
17
|
+
if (!algn) algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:titleStyle', lvlStr, 'attrs', 'algn'])
|
|
18
|
+
if (!algn && type === 'subTitle') {
|
|
19
|
+
algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:bodyStyle', lvlStr, 'attrs', 'algn'])
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (type === 'body') {
|
|
23
|
+
algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:bodyStyle', 'a:lvl1pPr', 'attrs', 'algn'])
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
algn = getTextByPathList(warpObj, ['slideMasterTables', 'typeTable', type, 'p:txBody', 'a:lstStyle', 'a:lvl1pPr', 'attrs', 'algn'])
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let align = 'left'
|
|
31
|
+
if (algn) {
|
|
32
|
+
switch (algn) {
|
|
33
|
+
case 'l':
|
|
34
|
+
align = 'left'
|
|
35
|
+
break
|
|
36
|
+
case 'r':
|
|
37
|
+
align = 'right'
|
|
38
|
+
break
|
|
39
|
+
case 'ctr':
|
|
40
|
+
align = 'center'
|
|
41
|
+
break
|
|
42
|
+
case 'just':
|
|
43
|
+
align = 'justify'
|
|
44
|
+
break
|
|
45
|
+
case 'dist':
|
|
46
|
+
align = 'justify'
|
|
14
47
|
break
|
|
15
48
|
default:
|
|
16
|
-
|
|
49
|
+
align = 'inherit'
|
|
17
50
|
}
|
|
18
51
|
}
|
|
19
|
-
|
|
20
|
-
if (type === 'title' || type === 'subTitle' || type === 'ctrTitle') return 'center'
|
|
21
|
-
else if (type === 'sldNum') return 'right'
|
|
22
|
-
}
|
|
23
|
-
return algn === 'ctr' ? 'center' : algn === 'r' ? 'right' : 'left'
|
|
52
|
+
return align
|
|
24
53
|
}
|
|
25
54
|
|
|
26
55
|
export function getVerticalAlign(node, slideLayoutSpNode, slideMasterSpNode) {
|
package/src/fill.js
CHANGED
|
@@ -244,7 +244,7 @@ export function getShapeFill(node, isSvgMode, warpObj) {
|
|
|
244
244
|
if (isNaN(lumOff)) lumOff = 0
|
|
245
245
|
|
|
246
246
|
const color = tinycolor(fillColor).toHsl()
|
|
247
|
-
const lum = color.l *
|
|
247
|
+
const lum = color.l * lumMod + lumOff
|
|
248
248
|
return tinycolor({ h: color.h, s: color.s, l: lum, a: color.a }).toHexString()
|
|
249
249
|
}
|
|
250
250
|
|
|
@@ -264,6 +264,15 @@ export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
264
264
|
else if (solidFill['a:schemeClr']) {
|
|
265
265
|
const schemeClr = 'a:' + getTextByPathList(solidFill['a:schemeClr'], ['attrs', 'val'])
|
|
266
266
|
color = getSchemeColorFromTheme(schemeClr, warpObj)
|
|
267
|
+
|
|
268
|
+
let lumMod = parseInt(getTextByPathList(solidFill, ['a:schemeClr', 'a:lumMod', 'attrs', 'val'])) / 100000
|
|
269
|
+
let lumOff = parseInt(getTextByPathList(solidFill, ['a:schemeClr', 'a:lumOff', 'attrs', 'val'])) / 100000
|
|
270
|
+
if (isNaN(lumMod)) lumMod = 1.0
|
|
271
|
+
if (isNaN(lumOff)) lumOff = 0
|
|
272
|
+
|
|
273
|
+
color = tinycolor(color).toHsl()
|
|
274
|
+
const lum = color.l * lumMod + lumOff
|
|
275
|
+
return tinycolor({ h: color.h, s: color.s, l: lum, a: color.a }).toHex()
|
|
267
276
|
}
|
|
268
277
|
else if (solidFill['a:scrgbClr']) {
|
|
269
278
|
clrNode = solidFill['a:scrgbClr']
|
package/src/fontStyle.js
CHANGED
|
@@ -58,7 +58,7 @@ export function getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles
|
|
|
58
58
|
|
|
59
59
|
fontSize = (isNaN(fontSize) || !fontSize) ? 18 : fontSize
|
|
60
60
|
|
|
61
|
-
return fontSize * fontsizeFactor + 'px'
|
|
61
|
+
return parseFloat((fontSize * fontsizeFactor).toFixed(2)) + (fontsizeFactor === 1 ? 'pt' : 'px')
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function getFontBold(node) {
|
|
@@ -70,13 +70,11 @@ export function getFontItalic(node) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export function getFontDecoration(node) {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
return getTextByPathList(node, ['a:rPr', 'attrs', 'u']) === 'sng' ? 'underline' : ''
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
else if (!underline && strike) return strike
|
|
79
|
-
return `${underline} ${strike}`
|
|
76
|
+
export function getFontDecorationLine(node) {
|
|
77
|
+
return getTextByPathList(node, ['a:rPr', 'attrs', 'strike']) === 'sngStrike' ? 'line-through' : ''
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
export function getFontSpace(node, fontsizeFactor) {
|
|
@@ -90,10 +88,10 @@ export function getFontSubscript(node) {
|
|
|
90
88
|
return parseInt(baseline) > 0 ? 'super' : 'sub'
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
export function getFontShadow(node, warpObj
|
|
91
|
+
export function getFontShadow(node, warpObj) {
|
|
94
92
|
const txtShadow = getTextByPathList(node, ['a:rPr', 'a:effectLst', 'a:outerShdw'])
|
|
95
93
|
if (txtShadow) {
|
|
96
|
-
const shadow = getShadow(txtShadow, warpObj
|
|
94
|
+
const shadow = getShadow(txtShadow, warpObj)
|
|
97
95
|
if (shadow) {
|
|
98
96
|
const { h, v, blur, color } = shadow
|
|
99
97
|
if (!isNaN(v) && !isNaN(h)) {
|
package/src/position.js
CHANGED
|
@@ -8,8 +8,8 @@ export function getPosition(slideSpNode, slideLayoutSpNode, slideMasterSpNode, f
|
|
|
8
8
|
if (!off) return { top: 0, left: 0 }
|
|
9
9
|
|
|
10
10
|
return {
|
|
11
|
-
top: parseInt(off['y']) * factor,
|
|
12
|
-
left: parseInt(off['x']) * factor,
|
|
11
|
+
top: parseFloat((parseInt(off['y']) * factor).toFixed(2)),
|
|
12
|
+
left: parseFloat((parseInt(off['x']) * factor).toFixed(2)),
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -23,7 +23,7 @@ export function getSize(slideSpNode, slideLayoutSpNode, slideMasterSpNode, facto
|
|
|
23
23
|
if (!ext) return { width: 0, height: 0 }
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
|
-
width: parseInt(ext['cx']) * factor,
|
|
27
|
-
height: parseInt(ext['cy']) * factor,
|
|
26
|
+
width: parseFloat((parseInt(ext['cx']) * factor).toFixed(2)),
|
|
27
|
+
height: parseFloat((parseInt(ext['cy']) * factor).toFixed(2)),
|
|
28
28
|
}
|
|
29
29
|
}
|