pptxtojson 2.0.6 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptxtojson",
3
- "version": "2.0.6",
3
+ "version": "2.1.0",
4
4
  "description": "A javascript tool for parsing .pptx file",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
package/src/border.js CHANGED
@@ -1,8 +1,19 @@
1
- import tinycolor from 'tinycolor2'
2
- import { getSchemeColorFromTheme } from './schemeColor'
3
- import { getTextByPathList } from './utils'
4
-
5
- export function getBorder(node, elType, warpObj) {
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
- let borderColor = getTextByPathList(lineNode, ['a:solidFill', 'a:srgbClr', 'attrs', 'val'])
26
- if (!borderColor) {
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
- return {
100
- borderColor,
101
- borderWidth,
102
- borderType,
103
- strokeDasharray,
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
@@ -795,7 +795,7 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
795
795
  let content = ''
796
796
  if (node['p:txBody']) content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, slideMasterSpNode, type, warpObj)
797
797
 
798
- const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
798
+ const { borderColor, borderWidth, borderType, strokeDasharray, headEnd, tailEnd } = getBorder(node, type, warpObj)
799
799
  const fill = await getShapeFill(node, warpObj, source, {
800
800
  groupHierarchy,
801
801
  slideLayoutSpNode,
@@ -831,9 +831,11 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
831
831
  }
832
832
 
833
833
  if (shadow) data.shadow = shadow
834
- if (autoFit) data.autoFit = autoFit
835
- if (link) data.link = link
836
- 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
837
839
 
838
840
  const isHasValidText = data.content && hasValidText(data.content)
839
841