pptxtojson 0.1.1 → 0.1.2
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/dist/index.d.ts +3 -2
- 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 +1 -1
- package/src/fontStyle.js +4 -6
- package/src/pptxtojson.js +38 -1
- package/src/readXmlFile.js +4 -2
- package/src/shape.js +12 -3
- package/src/text.js +3 -0
package/package.json
CHANGED
package/src/fontStyle.js
CHANGED
|
@@ -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) {
|
package/src/pptxtojson.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import JSZip from 'jszip'
|
|
2
2
|
import { readXmlFile } from './readXmlFile'
|
|
3
3
|
import { getBorder } from './border'
|
|
4
|
-
import { getSlideBackgroundFill, getShapeFill } from './fill'
|
|
4
|
+
import { getSlideBackgroundFill, getShapeFill, getSolidFill } from './fill'
|
|
5
5
|
import { getChartInfo } from './chart'
|
|
6
6
|
import { getVerticalAlign } from './align'
|
|
7
7
|
import { getPosition, getSize } from './position'
|
|
@@ -252,6 +252,8 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
const tableStyles = await readXmlFile(zip, 'ppt/tableStyles.xml')
|
|
256
|
+
|
|
255
257
|
const slideContent = await readXmlFile(zip, sldFileName)
|
|
256
258
|
const nodes = slideContent['p:sld']['p:cSld']['p:spTree']
|
|
257
259
|
const warpObj = {
|
|
@@ -261,6 +263,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
261
263
|
slideMasterContent: slideMasterContent,
|
|
262
264
|
slideMasterTables: slideMasterTables,
|
|
263
265
|
slideContent: slideContent,
|
|
266
|
+
tableStyles: tableStyles,
|
|
264
267
|
slideResObj: slideResObj,
|
|
265
268
|
slideMasterTextStyles: slideMasterTextStyles,
|
|
266
269
|
layoutResObj: layoutResObj,
|
|
@@ -673,6 +676,39 @@ function genTable(node, warpObj) {
|
|
|
673
676
|
const { top, left } = getPosition(xfrmNode, undefined, undefined, SLIDE_FACTOR)
|
|
674
677
|
const { width, height } = getSize(xfrmNode, undefined, undefined, SLIDE_FACTOR)
|
|
675
678
|
|
|
679
|
+
const getTblPr = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl', 'a:tblPr'])
|
|
680
|
+
|
|
681
|
+
let thisTblStyle
|
|
682
|
+
const tbleStyleId = getTblPr['a:tableStyleId']
|
|
683
|
+
if (tbleStyleId) {
|
|
684
|
+
const tbleStylList = warpObj['tableStyles']['a:tblStyleLst']['a:tblStyle']
|
|
685
|
+
if (tbleStylList) {
|
|
686
|
+
if (tbleStylList.constructor === Array) {
|
|
687
|
+
for (let k = 0; k < tbleStylList.length; k++) {
|
|
688
|
+
if (tbleStylList[k]['attrs']['styleId'] === tbleStyleId) {
|
|
689
|
+
thisTblStyle = tbleStylList[k]
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
if (tbleStylList['attrs']['styleId'] === tbleStyleId) {
|
|
695
|
+
thisTblStyle = tbleStylList
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
let themeColor = ''
|
|
702
|
+
let tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:tblBg', 'a:fillRef'])
|
|
703
|
+
if (tbl_bgFillschemeClr) {
|
|
704
|
+
themeColor = getSolidFill(tbl_bgFillschemeClr, undefined, undefined, warpObj)
|
|
705
|
+
}
|
|
706
|
+
if (tbl_bgFillschemeClr === undefined) {
|
|
707
|
+
tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:fill', 'a:solidFill'])
|
|
708
|
+
themeColor = getSolidFill(tbl_bgFillschemeClr, undefined, undefined, warpObj)
|
|
709
|
+
}
|
|
710
|
+
if (themeColor !== '') themeColor = '#' + themeColor
|
|
711
|
+
|
|
676
712
|
const trNodes = tableNode['a:tr']
|
|
677
713
|
|
|
678
714
|
const data = []
|
|
@@ -723,6 +759,7 @@ function genTable(node, warpObj) {
|
|
|
723
759
|
width,
|
|
724
760
|
height,
|
|
725
761
|
data,
|
|
762
|
+
themeColor,
|
|
726
763
|
}
|
|
727
764
|
}
|
|
728
765
|
|
package/src/readXmlFile.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as txml from 'txml/dist/txml.mjs'
|
|
2
2
|
|
|
3
|
+
let cust_attr_order = 0
|
|
4
|
+
|
|
3
5
|
export function simplifyLostLess(children, parentAttributes = {}) {
|
|
4
6
|
const out = {}
|
|
5
7
|
if (!children.length) return out
|
|
6
8
|
|
|
7
9
|
if (children.length === 1 && typeof children[0] === 'string') {
|
|
8
10
|
return Object.keys(parentAttributes).length ? {
|
|
9
|
-
attrs: parentAttributes,
|
|
11
|
+
attrs: { order: cust_attr_order++, ...parentAttributes },
|
|
10
12
|
value: children[0],
|
|
11
13
|
} : children[0]
|
|
12
14
|
}
|
|
@@ -20,7 +22,7 @@ export function simplifyLostLess(children, parentAttributes = {}) {
|
|
|
20
22
|
out[child.tagName].push(kids)
|
|
21
23
|
|
|
22
24
|
if (Object.keys(child.attributes).length) {
|
|
23
|
-
kids.attrs = child.attributes
|
|
25
|
+
kids.attrs = { order: cust_attr_order++, ...child.attributes }
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
for (const child in out) {
|
package/src/shape.js
CHANGED
|
@@ -57,11 +57,12 @@ export function getCustomShapePath(custShapType, w, h) {
|
|
|
57
57
|
const moveToNoPt = moveToPtNode[key]
|
|
58
58
|
const spX = moveToNoPt['attrs', 'x']
|
|
59
59
|
const spY = moveToNoPt['attrs', 'y']
|
|
60
|
-
|
|
60
|
+
const order = moveToNoPt['attrs', 'order']
|
|
61
61
|
multiSapeAry.push({
|
|
62
62
|
type: 'movto',
|
|
63
63
|
x: spX,
|
|
64
64
|
y: spY,
|
|
65
|
+
order,
|
|
65
66
|
})
|
|
66
67
|
})
|
|
67
68
|
}
|
|
@@ -74,10 +75,12 @@ export function getCustomShapePath(custShapType, w, h) {
|
|
|
74
75
|
const lnToNoPt = lnToPtNode[key]
|
|
75
76
|
const ptX = lnToNoPt['attrs', 'x']
|
|
76
77
|
const ptY = lnToNoPt['attrs', 'y']
|
|
78
|
+
const order = lnToNoPt['attrs', 'order']
|
|
77
79
|
multiSapeAry.push({
|
|
78
80
|
type: 'lnto',
|
|
79
81
|
x: ptX,
|
|
80
82
|
y: ptY,
|
|
83
|
+
order,
|
|
81
84
|
})
|
|
82
85
|
})
|
|
83
86
|
}
|
|
@@ -101,14 +104,17 @@ export function getCustomShapePath(custShapType, w, h) {
|
|
|
101
104
|
}
|
|
102
105
|
pts_ary.push(pt_obj)
|
|
103
106
|
})
|
|
107
|
+
const order = key[0]['attrs']['order']
|
|
104
108
|
multiSapeAry.push({
|
|
105
109
|
type: 'cubicBezTo',
|
|
106
|
-
cubBzPt: pts_ary
|
|
110
|
+
cubBzPt: pts_ary,
|
|
111
|
+
order,
|
|
107
112
|
})
|
|
108
113
|
})
|
|
109
114
|
}
|
|
110
115
|
if (arcToNodes) {
|
|
111
116
|
const arcToNodesAttrs = arcToNodes['attrs']
|
|
117
|
+
const order = arcToNodesAttrs['order']
|
|
112
118
|
const hR = arcToNodesAttrs['hR']
|
|
113
119
|
const wR = arcToNodesAttrs['wR']
|
|
114
120
|
const stAng = arcToNodesAttrs['stAng']
|
|
@@ -128,6 +134,7 @@ export function getCustomShapePath(custShapType, w, h) {
|
|
|
128
134
|
swAng: swAng,
|
|
129
135
|
shftX: shftX,
|
|
130
136
|
shftY: shftY,
|
|
137
|
+
order,
|
|
131
138
|
})
|
|
132
139
|
}
|
|
133
140
|
if (closeNode) {
|
|
@@ -135,13 +142,15 @@ export function getCustomShapePath(custShapType, w, h) {
|
|
|
135
142
|
Object.keys(closeNode).forEach(() => {
|
|
136
143
|
multiSapeAry.push({
|
|
137
144
|
type: 'close',
|
|
145
|
+
order: Infinity,
|
|
138
146
|
})
|
|
139
147
|
})
|
|
140
148
|
}
|
|
141
149
|
|
|
150
|
+
multiSapeAry.sort((a, b) => a.order - b.order)
|
|
151
|
+
|
|
142
152
|
let k = 0
|
|
143
153
|
while (k < multiSapeAry.length) {
|
|
144
|
-
|
|
145
154
|
if (multiSapeAry[k].type === 'movto') {
|
|
146
155
|
const spX = parseInt(multiSapeAry[k].x) * cX
|
|
147
156
|
const spY = parseInt(multiSapeAry[k].y) * cY
|
package/src/text.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getFontBold,
|
|
9
9
|
getFontItalic,
|
|
10
10
|
getFontDecoration,
|
|
11
|
+
getFontDecorationLine,
|
|
11
12
|
getFontSpace,
|
|
12
13
|
getFontSubscript,
|
|
13
14
|
getFontShadow,
|
|
@@ -108,6 +109,7 @@ export function genSpanElement(node, slideLayoutSpNode, type, warpObj, fontsizeF
|
|
|
108
109
|
const fontBold = getFontBold(node)
|
|
109
110
|
const fontItalic = getFontItalic(node)
|
|
110
111
|
const fontDecoration = getFontDecoration(node)
|
|
112
|
+
const fontDecorationLine = getFontDecorationLine(node)
|
|
111
113
|
const fontSpace = getFontSpace(node, fontsizeFactor)
|
|
112
114
|
const shadow = getFontShadow(node, warpObj, slideFactor)
|
|
113
115
|
const subscript = getFontSubscript(node)
|
|
@@ -118,6 +120,7 @@ export function genSpanElement(node, slideLayoutSpNode, type, warpObj, fontsizeF
|
|
|
118
120
|
if (fontBold) styleText += `font-weight: ${fontBold};`
|
|
119
121
|
if (fontItalic) styleText += `font-style: ${fontItalic};`
|
|
120
122
|
if (fontDecoration) styleText += `text-decoration: ${fontDecoration};`
|
|
123
|
+
if (fontDecorationLine) styleText += `text-decoration-line: ${fontDecorationLine};`
|
|
121
124
|
if (fontSpace) styleText += `letter-spacing: ${fontSpace};`
|
|
122
125
|
if (subscript) styleText += `vertical-align: ${subscript}; font-size: smaller;`
|
|
123
126
|
if (shadow) styleText += `text-shadow: ${shadow};`
|