pptxtojson 2.0.5 → 2.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 +3 -0
- package/README_zh.md +8 -5
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -12
- 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/border.js +38 -26
- package/src/pptxtojson.js +21 -7
package/package.json
CHANGED
package/src/border.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import tinycolor from 'tinycolor2'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import tinycolor from 'tinycolor2'
|
|
2
|
+
import { getSolidFill } from './fill'
|
|
3
|
+
import { getSchemeColorFromTheme } from './schemeColor'
|
|
4
|
+
import { getTextByPathList } from './utils'
|
|
5
|
+
|
|
6
|
+
function getLineEnd(node) {
|
|
7
|
+
const attrs = getTextByPathList(node, ['attrs'])
|
|
8
|
+
if (!attrs) return undefined
|
|
9
|
+
|
|
10
|
+
const lineEnd = { type: attrs.type || 'none' }
|
|
11
|
+
if (attrs.w) lineEnd.width = attrs.w
|
|
12
|
+
if (attrs.len) lineEnd.length = attrs.len
|
|
13
|
+
return lineEnd
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getBorder(node, elType, warpObj) {
|
|
6
17
|
let lineNode = getTextByPathList(node, ['p:spPr', 'a:ln'])
|
|
7
18
|
if (!lineNode) {
|
|
8
19
|
const lnRefNode = getTextByPathList(node, ['p:style', 'a:lnRef'])
|
|
@@ -22,12 +33,8 @@ export function getBorder(node, elType, warpObj) {
|
|
|
22
33
|
else borderWidth = 1
|
|
23
34
|
}
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const schemeClrNode = getTextByPathList(lineNode, ['a:solidFill', 'a:schemeClr'])
|
|
28
|
-
const schemeClr = 'a:' + getTextByPathList(schemeClrNode, ['attrs', 'val'])
|
|
29
|
-
borderColor = getSchemeColorFromTheme(schemeClr, warpObj)
|
|
30
|
-
}
|
|
36
|
+
const solidFill = getTextByPathList(lineNode, ['a:solidFill'])
|
|
37
|
+
let borderColor = getSolidFill(solidFill, undefined, undefined, warpObj)
|
|
31
38
|
|
|
32
39
|
if (!borderColor) {
|
|
33
40
|
const schemeClrNode = getTextByPathList(node, ['p:style', 'a:lnRef', 'a:schemeClr'])
|
|
@@ -44,15 +51,15 @@ export function getBorder(node, elType, warpObj) {
|
|
|
44
51
|
borderColor = tinycolor({ h: color.h, s: color.s, l: color.l * shade, a: color.a }).toHex()
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!borderColor) borderColor = '#000000'
|
|
50
|
-
else borderColor = `#${borderColor}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!borderColor) borderColor = '#000000'
|
|
57
|
+
else if (!borderColor.startsWith('#')) borderColor = `#${borderColor}`
|
|
51
58
|
|
|
52
59
|
const type = getTextByPathList(lineNode, ['a:prstDash', 'attrs', 'val'])
|
|
53
60
|
let borderType = 'solid'
|
|
54
61
|
let strokeDasharray = '0'
|
|
55
|
-
switch (type) {
|
|
62
|
+
switch (type) {
|
|
56
63
|
case 'solid':
|
|
57
64
|
borderType = 'solid'
|
|
58
65
|
strokeDasharray = '0'
|
|
@@ -93,13 +100,18 @@ export function getBorder(node, elType, warpObj) {
|
|
|
93
100
|
borderType = 'dotted'
|
|
94
101
|
strokeDasharray = '2, 5'
|
|
95
102
|
break
|
|
96
|
-
default:
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
default:
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const headEnd = getLineEnd(getTextByPathList(lineNode, ['a:headEnd']))
|
|
107
|
+
const tailEnd = getLineEnd(getTextByPathList(lineNode, ['a:tailEnd']))
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
borderColor,
|
|
111
|
+
borderWidth,
|
|
112
|
+
borderType,
|
|
113
|
+
strokeDasharray,
|
|
114
|
+
headEnd,
|
|
115
|
+
tailEnd,
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/pptxtojson.js
CHANGED
|
@@ -267,7 +267,9 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
let currentThemeContent = themeContent
|
|
270
271
|
if (themeFilename) {
|
|
272
|
+
currentThemeContent = currentThemeContent || await readXmlFileCached(zip, themeFilename, xmlCache)
|
|
271
273
|
const themeName = themeFilename.split('/').pop()
|
|
272
274
|
const themeResFileName = themeFilename.replace(themeName, '_rels/' + themeName) + '.rels'
|
|
273
275
|
const themeResContent = await readXmlFile(zip, themeResFileName)
|
|
@@ -305,7 +307,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
305
307
|
slideMasterTextStyles,
|
|
306
308
|
layoutResObj,
|
|
307
309
|
masterResObj,
|
|
308
|
-
themeContent,
|
|
310
|
+
themeContent: currentThemeContent,
|
|
309
311
|
themeResObj,
|
|
310
312
|
diagramFileCache: {},
|
|
311
313
|
defaultTextStyle,
|
|
@@ -775,6 +777,7 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
775
777
|
|
|
776
778
|
const { top, left } = getPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode)
|
|
777
779
|
const { width, height } = getSize(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode)
|
|
780
|
+
const pathViewBox = { x: 0, y: 0, width, height }
|
|
778
781
|
|
|
779
782
|
const isFlipV = getTextByPathList(slideXfrmNode, ['attrs', 'flipV']) === '1'
|
|
780
783
|
const isFlipH = getTextByPathList(slideXfrmNode, ['attrs', 'flipH']) === '1'
|
|
@@ -792,7 +795,7 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
792
795
|
let content = ''
|
|
793
796
|
if (node['p:txBody']) content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, slideMasterSpNode, type, warpObj)
|
|
794
797
|
|
|
795
|
-
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
|
|
798
|
+
const { borderColor, borderWidth, borderType, strokeDasharray, headEnd, tailEnd } = getBorder(node, type, warpObj)
|
|
796
799
|
const fill = await getShapeFill(node, warpObj, source, {
|
|
797
800
|
groupHierarchy,
|
|
798
801
|
slideLayoutSpNode,
|
|
@@ -828,9 +831,11 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
828
831
|
}
|
|
829
832
|
|
|
830
833
|
if (shadow) data.shadow = shadow
|
|
831
|
-
if (autoFit) data.autoFit = autoFit
|
|
832
|
-
if (link) data.link = link
|
|
833
|
-
if (textInset) data.textInset = textInset
|
|
834
|
+
if (autoFit) data.autoFit = autoFit
|
|
835
|
+
if (link) data.link = link
|
|
836
|
+
if (textInset) data.textInset = textInset
|
|
837
|
+
if (headEnd) data.headEnd = headEnd
|
|
838
|
+
if (tailEnd) data.tailEnd = tailEnd
|
|
834
839
|
|
|
835
840
|
const isHasValidText = data.content && hasValidText(data.content)
|
|
836
841
|
|
|
@@ -846,6 +851,7 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
846
851
|
type: 'shape',
|
|
847
852
|
shapType: 'custom',
|
|
848
853
|
path: d,
|
|
854
|
+
pathViewBox: { x: 0, y: 0, width: w, height: h },
|
|
849
855
|
}
|
|
850
856
|
if (isStrokeOnlyCustomGeometry(custShapType)) customShapeData.strokeOnly = true
|
|
851
857
|
|
|
@@ -854,26 +860,34 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
854
860
|
|
|
855
861
|
let shapePath = ''
|
|
856
862
|
if (shapType) shapePath = getShapePath(shapType, width, height, node)
|
|
863
|
+
const STROKE_ONLY_PRESET_SHAPE_TYPES = ['arc', 'leftBrace', 'rightBrace', 'bracePair', 'leftBracket', 'rightBracket', 'bracketPair']
|
|
864
|
+
const isStrokeOnlyPresetShape = STROKE_ONLY_PRESET_SHAPE_TYPES.includes(shapType)
|
|
857
865
|
|
|
858
866
|
if (shapType && (type === 'obj' || !type || shapType !== 'rect')) {
|
|
859
867
|
if (!isHasValidText) data.content = ''
|
|
860
|
-
|
|
868
|
+
const shapeData = {
|
|
861
869
|
...data,
|
|
862
870
|
type: 'shape',
|
|
863
871
|
shapType,
|
|
864
872
|
path: shapePath,
|
|
873
|
+
pathViewBox,
|
|
865
874
|
keypoints,
|
|
866
875
|
}
|
|
876
|
+
if (isStrokeOnlyPresetShape) shapeData.strokeOnly = true
|
|
877
|
+
return shapeData
|
|
867
878
|
}
|
|
868
879
|
if (shapType && !isHasValidText && (fill || borderWidth)) {
|
|
869
|
-
|
|
880
|
+
const shapeData = {
|
|
870
881
|
...data,
|
|
871
882
|
type: 'shape',
|
|
872
883
|
content: '',
|
|
873
884
|
shapType,
|
|
874
885
|
path: shapePath,
|
|
886
|
+
pathViewBox,
|
|
875
887
|
keypoints,
|
|
876
888
|
}
|
|
889
|
+
if (isStrokeOnlyPresetShape) shapeData.strokeOnly = true
|
|
890
|
+
return shapeData
|
|
877
891
|
}
|
|
878
892
|
return {
|
|
879
893
|
...data,
|