pptxtojson 1.0.1 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptxtojson",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A javascript tool for parsing .pptx file",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
package/src/fill.js CHANGED
@@ -452,9 +452,9 @@ export function getShapeFill(node, isSvgMode, warpObj) {
452
452
  }
453
453
 
454
454
  export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
455
- if (!solidFill) return solidFill
455
+ if (!solidFill) return ''
456
456
 
457
- let color = '#ffffff'
457
+ let color = ''
458
458
  let clrNode
459
459
 
460
460
  if (solidFill['a:srgbClr']) {
@@ -464,7 +464,7 @@ export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
464
464
  else if (solidFill['a:schemeClr']) {
465
465
  clrNode = solidFill['a:schemeClr']
466
466
  const schemeClr = 'a:' + getTextByPathList(clrNode, ['attrs', 'val'])
467
- color = getSchemeColorFromTheme(schemeClr, warpObj, clrMap, phClr) || '#ffffff'
467
+ color = getSchemeColorFromTheme(schemeClr, warpObj, clrMap, phClr) || ''
468
468
  }
469
469
  else if (solidFill['a:scrgbClr']) {
470
470
  clrNode = solidFill['a:scrgbClr']
package/src/fontStyle.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getTextByPathList } from './utils'
2
2
  import { getShadow } from './shadow'
3
+ import { getFillType, getSolidFill } from './fill'
3
4
 
4
5
  export function getFontType(node, type, warpObj) {
5
6
  let typeface = getTextByPathList(node, ['a:rPr', 'a:latin', 'attrs', 'typeface'])
@@ -21,9 +22,30 @@ export function getFontType(node, type, warpObj) {
21
22
  return typeface || ''
22
23
  }
23
24
 
24
- export function getFontColor(node) {
25
- const color = getTextByPathList(node, ['a:rPr', 'a:solidFill', 'a:srgbClr', 'attrs', 'val'])
26
- return color ? `#${color}` : ''
25
+ export function getFontColor(node, pNode, lstStyle, pFontStyle, lvl, warpObj) {
26
+ const rPrNode = getTextByPathList(node, ['a:rPr'])
27
+ let filTyp, color
28
+ if (rPrNode) {
29
+ filTyp = getFillType(rPrNode)
30
+ if (filTyp === 'SOLID_FILL') {
31
+ const solidFillNode = rPrNode['a:solidFill']
32
+ color = getSolidFill(solidFillNode, undefined, undefined, warpObj)
33
+ }
34
+ }
35
+ if (!color && getTextByPathList(lstStyle, ['a:lvl' + lvl + 'pPr', 'a:defRPr'])) {
36
+ const lstStyledefRPr = getTextByPathList(lstStyle, ['a:lvl' + lvl + 'pPr', 'a:defRPr'])
37
+ filTyp = getFillType(lstStyledefRPr)
38
+ if (filTyp === 'SOLID_FILL') {
39
+ const solidFillNode = lstStyledefRPr['a:solidFill']
40
+ color = getSolidFill(solidFillNode, undefined, undefined, warpObj)
41
+ }
42
+ }
43
+ if (!color) {
44
+ const sPstyle = getTextByPathList(pNode, ['p:style', 'a:fontRef'])
45
+ if (sPstyle) color = getSolidFill(sPstyle, undefined, undefined, warpObj)
46
+ if (!color && pFontStyle) color = getSolidFill(pFontStyle, undefined, undefined, warpObj)
47
+ }
48
+ return color || ''
27
49
  }
28
50
 
29
51
  export function getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles) {
@@ -95,7 +117,7 @@ export function getFontShadow(node, warpObj) {
95
117
  if (shadow) {
96
118
  const { h, v, blur, color } = shadow
97
119
  if (!isNaN(v) && !isNaN(h)) {
98
- return h + 'px ' + v + 'px ' + (blur ? blur + 'px' : '') + ' ' + color
120
+ return h + 'pt ' + v + 'pt ' + (blur ? blur + 'pt' : '') + ' ' + color
99
121
  }
100
122
  }
101
123
  }
package/src/pptxtojson.js CHANGED
@@ -9,7 +9,7 @@ import { genTextBody } from './text'
9
9
  import { getCustomShapePath } from './shape'
10
10
  import { extractFileExtension, base64ArrayBuffer, getTextByPathList, angleToDegrees, getMimeType, isVideoLink, escapeHtml } from './utils'
11
11
  import { getShadow } from './shadow'
12
- import { getTableCellParams, getTableRowParams } from './table'
12
+ import { getTableBorders, getTableCellParams, getTableRowParams } from './table'
13
13
  import { RATIO_EMUs_Points } from './constants'
14
14
 
15
15
  export async function parse(file) {
@@ -410,7 +410,10 @@ async function processGroupSpNode(node, warpObj, source) {
410
410
  const cy = parseInt(xfrmNode['a:ext']['attrs']['cy']) * RATIO_EMUs_Points
411
411
  const chcx = parseInt(xfrmNode['a:chExt']['attrs']['cx']) * RATIO_EMUs_Points
412
412
  const chcy = parseInt(xfrmNode['a:chExt']['attrs']['cy']) * RATIO_EMUs_Points
413
- // children coordinate
413
+
414
+ let rotate = getTextByPathList(xfrmNode, ['attrs', 'rot']) || 0
415
+ if (rotate) rotate = angleToDegrees(rotate)
416
+
414
417
  const ws = cx / chcx
415
418
  const hs = cy / chcy
416
419
 
@@ -434,6 +437,7 @@ async function processGroupSpNode(node, warpObj, source) {
434
437
  left: x,
435
438
  width: cx,
436
439
  height: cy,
440
+ rotate,
437
441
  elements: elements.map(element => ({
438
442
  ...element,
439
443
  left: (element.left - chx) * ws,
@@ -748,6 +752,14 @@ function genTable(node, warpObj) {
748
752
  }
749
753
  if (thisTblStyle) thisTblStyle['tblStylAttrObj'] = tblStylAttrObj
750
754
 
755
+ let tbl_border
756
+ const tblStyl = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle'])
757
+ const tblBorderStyl = getTextByPathList(tblStyl, ['a:tcBdr'])
758
+ if (tblBorderStyl) {
759
+ const tbl_borders = getTableBorders(tblBorderStyl, warpObj)
760
+ if (tbl_borders) tbl_border = tbl_borders.bottom || tbl_borders.left || tbl_borders.right || tbl_borders.top
761
+ }
762
+
751
763
  let tbl_bgcolor = ''
752
764
  let tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:tblBg', 'a:fillRef'])
753
765
  if (tbl_bgFillschemeClr) {
@@ -821,7 +833,7 @@ function genTable(node, warpObj) {
821
833
  if (cell.hMerge) td.hMerge = cell.hMerge
822
834
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
823
835
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
824
- if (cell.fillColor || fillColor || tbl_bgcolor) td.fill = cell.fillColor || fillColor || tbl_bgcolor
836
+ if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
825
837
 
826
838
  tr.push(td)
827
839
  }
@@ -852,7 +864,7 @@ function genTable(node, warpObj) {
852
864
  if (cell.hMerge) td.hMerge = cell.hMerge
853
865
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
854
866
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
855
- if (cell.fillColor || fillColor || tbl_bgcolor) td.fill = cell.fillColor || fillColor || tbl_bgcolor
867
+ if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
856
868
 
857
869
  tr.push(td)
858
870
  }
@@ -866,6 +878,7 @@ function genTable(node, warpObj) {
866
878
  width,
867
879
  height,
868
880
  data,
881
+ ...(tbl_border || {}),
869
882
  }
870
883
  }
871
884
 
package/src/table.js CHANGED
@@ -1,6 +1,47 @@
1
1
  import { getShapeFill, getSolidFill } from './fill'
2
2
  import { getTextByPathList } from './utils'
3
+ import { getBorder } from './border'
3
4
 
5
+ export function getTableBorders(node, warpObj) {
6
+ const borderStyles = {}
7
+ if (node['a:bottom']) {
8
+ const obj = {
9
+ 'p:spPr': {
10
+ 'a:ln': node['a:bottom']['a:ln']
11
+ }
12
+ }
13
+ const border = getBorder(obj, undefined, warpObj)
14
+ borderStyles.bottom = border
15
+ }
16
+ if (node['a:top']) {
17
+ const obj = {
18
+ 'p:spPr': {
19
+ 'a:ln': node['a:top']['a:ln']
20
+ }
21
+ }
22
+ const border = getBorder(obj, undefined, warpObj)
23
+ borderStyles.top = border
24
+ }
25
+ if (node['a:right']) {
26
+ const obj = {
27
+ 'p:spPr': {
28
+ 'a:ln': node['a:right']['a:ln']
29
+ }
30
+ }
31
+ const border = getBorder(obj, undefined, warpObj)
32
+ borderStyles.right = border
33
+ }
34
+ if (node['a:left']) {
35
+ const obj = {
36
+ 'p:spPr': {
37
+ 'a:ln': node['a:left']['a:ln']
38
+ }
39
+ }
40
+ const border = getBorder(obj, undefined, warpObj)
41
+ borderStyles.left = border
42
+ }
43
+ return borderStyles
44
+ }
4
45
 
5
46
  export function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
6
47
  const rowSpan = getTextByPathList(tcNode, ['attrs', 'rowSpan'])
@@ -35,10 +76,10 @@ export function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
35
76
  fillColor,
36
77
  fontColor,
37
78
  fontBold,
38
- rowSpan,
39
- colSpan,
40
- vMerge,
41
- hMerge,
79
+ rowSpan: rowSpan ? +rowSpan : undefined,
80
+ colSpan: colSpan ? +colSpan : undefined,
81
+ vMerge: vMerge ? +vMerge : undefined,
82
+ hMerge: hMerge ? +hMerge : undefined,
42
83
  }
43
84
  }
44
85
 
package/src/text.js CHANGED
@@ -19,6 +19,8 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpO
19
19
 
20
20
  let text = ''
21
21
 
22
+ const pFontStyle = getTextByPathList(spNode, ['p:style', 'a:fontRef'])
23
+
22
24
  const pNode = textBodyNode['a:p']
23
25
  const pNodes = pNode.constructor === Array ? pNode : [pNode]
24
26
 
@@ -71,10 +73,10 @@ export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, type, warpO
71
73
  text += `<p style="text-align: ${align};">`
72
74
  }
73
75
 
74
- if (!rNode) text += genSpanElement(pNode, slideLayoutSpNode, type, warpObj)
76
+ if (!rNode) text += genSpanElement(pNode, spNode, textBodyNode, pFontStyle, slideLayoutSpNode, type, warpObj)
75
77
  else {
76
78
  for (const rNodeItem of rNode) {
77
- text += genSpanElement(rNodeItem, slideLayoutSpNode, type, warpObj)
79
+ text += genSpanElement(rNodeItem, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, type, warpObj)
78
80
  }
79
81
  }
80
82
 
@@ -94,15 +96,21 @@ export function getListType(node) {
94
96
  return ''
95
97
  }
96
98
 
97
- export function genSpanElement(node, slideLayoutSpNode, type, warpObj) {
99
+ export function genSpanElement(node, pNode, textBodyNode, pFontStyle, slideLayoutSpNode, type, warpObj) {
100
+ const lstStyle = textBodyNode['a:lstStyle']
98
101
  const slideMasterTextStyles = warpObj['slideMasterTextStyles']
99
102
 
103
+ let lvl = 1
104
+ const pPrNode = pNode['a:pPr']
105
+ const lvlNode = getTextByPathList(pPrNode, ['attrs', 'lvl'])
106
+ if (lvlNode !== undefined) lvl = parseInt(lvlNode) + 1
107
+
100
108
  let text = node['a:t']
101
109
  if (typeof text !== 'string') text = getTextByPathList(node, ['a:fld', 'a:t'])
102
110
  if (typeof text !== 'string') text = '&nbsp;'
103
111
 
104
112
  let styleText = ''
105
- const fontColor = getFontColor(node)
113
+ const fontColor = getFontColor(node, pNode, lstStyle, pFontStyle, lvl, warpObj)
106
114
  const fontSize = getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles)
107
115
  const fontType = getFontType(node, type, warpObj)
108
116
  const fontBold = getFontBold(node)