pptxtojson 1.2.2 → 1.3.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": "1.2.2",
3
+ "version": "1.3.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
@@ -3,7 +3,7 @@ import { getSchemeColorFromTheme } from './schemeColor'
3
3
  import { getTextByPathList } from './utils'
4
4
 
5
5
  export function getBorder(node, elType, warpObj) {
6
- let lineNode = node['p:spPr']['a:ln']
6
+ let lineNode = getTextByPathList(node, ['p:spPr', 'a:ln'])
7
7
  if (!lineNode) {
8
8
  const lnRefNode = getTextByPathList(node, ['p:style', 'a:lnRef'])
9
9
  if (lnRefNode) {
@@ -46,7 +46,7 @@ export function getBorder(node, elType, warpObj) {
46
46
  }
47
47
  }
48
48
 
49
- if (!borderColor) borderColor = '#000'
49
+ if (!borderColor) borderColor = '#000000'
50
50
  else borderColor = `#${borderColor}`
51
51
 
52
52
  const type = getTextByPathList(lineNode, ['a:prstDash', 'attrs', 'val'])
package/src/pptxtojson.js CHANGED
@@ -781,6 +781,17 @@ async function genTable(node, warpObj) {
781
781
  const { width, height } = getSize(xfrmNode, undefined, undefined)
782
782
 
783
783
  const getTblPr = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl', 'a:tblPr'])
784
+ let getColsGrid = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl', 'a:tblGrid', 'a:gridCol'])
785
+ if (getColsGrid.constructor !== Array) getColsGrid = [getColsGrid]
786
+
787
+ const colWidths = []
788
+ if (getColsGrid) {
789
+ for (const item of getColsGrid) {
790
+ const colWidthParam = getTextByPathList(item, ['attrs', 'w']) || 0
791
+ const colWidth = parseInt(colWidthParam) * RATIO_EMUs_Points
792
+ colWidths.push(colWidth)
793
+ }
794
+ }
784
795
 
785
796
  const firstRowAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstRow'] : undefined
786
797
  const firstColAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstCol'] : undefined
@@ -818,13 +829,10 @@ async function genTable(node, warpObj) {
818
829
  }
819
830
  if (thisTblStyle) thisTblStyle['tblStylAttrObj'] = tblStylAttrObj
820
831
 
821
- let tbl_border
832
+ let borders = {}
822
833
  const tblStyl = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle'])
823
834
  const tblBorderStyl = getTextByPathList(tblStyl, ['a:tcBdr'])
824
- if (tblBorderStyl) {
825
- const tbl_borders = getTableBorders(tblBorderStyl, warpObj)
826
- if (tbl_borders) tbl_border = tbl_borders.bottom || tbl_borders.left || tbl_borders.right || tbl_borders.top
827
- }
835
+ if (tblBorderStyl) borders = getTableBorders(tblBorderStyl, warpObj)
828
836
 
829
837
  let tbl_bgcolor = ''
830
838
  let tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:tblBg', 'a:fillRef'])
@@ -840,8 +848,13 @@ async function genTable(node, warpObj) {
840
848
  if (trNodes.constructor !== Array) trNodes = [trNodes]
841
849
 
842
850
  const data = []
851
+ const rowHeights = []
843
852
  for (let i = 0; i < trNodes.length; i++) {
844
853
  const trNode = trNodes[i]
854
+
855
+ const rowHeightParam = getTextByPathList(trNodes[i], ['attrs', 'h']) || 0
856
+ const rowHeight = parseInt(rowHeightParam) * RATIO_EMUs_Points
857
+ rowHeights.push(rowHeight)
845
858
 
846
859
  const {
847
860
  fillColor,
@@ -900,6 +913,7 @@ async function genTable(node, warpObj) {
900
913
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
901
914
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
902
915
  if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
916
+ if (cell.borders) td.borders = cell.borders
903
917
 
904
918
  tr.push(td)
905
919
  }
@@ -931,6 +945,7 @@ async function genTable(node, warpObj) {
931
945
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
932
946
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
933
947
  if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
948
+ if (cell.borders) td.borders = cell.borders
934
949
 
935
950
  tr.push(td)
936
951
  }
@@ -945,7 +960,9 @@ async function genTable(node, warpObj) {
945
960
  height,
946
961
  data,
947
962
  order,
948
- ...(tbl_border || {}),
963
+ borders,
964
+ rowHeights,
965
+ colWidths,
949
966
  }
950
967
  }
951
968
 
package/src/table.js CHANGED
@@ -3,7 +3,7 @@ import { getTextByPathList } from './utils'
3
3
  import { getBorder } from './border'
4
4
 
5
5
  export function getTableBorders(node, warpObj) {
6
- const borderStyles = {}
6
+ const borders = {}
7
7
  if (node['a:bottom']) {
8
8
  const obj = {
9
9
  'p:spPr': {
@@ -11,7 +11,7 @@ export function getTableBorders(node, warpObj) {
11
11
  }
12
12
  }
13
13
  const border = getBorder(obj, undefined, warpObj)
14
- borderStyles.bottom = border
14
+ borders.bottom = border
15
15
  }
16
16
  if (node['a:top']) {
17
17
  const obj = {
@@ -20,7 +20,7 @@ export function getTableBorders(node, warpObj) {
20
20
  }
21
21
  }
22
22
  const border = getBorder(obj, undefined, warpObj)
23
- borderStyles.top = border
23
+ borders.top = border
24
24
  }
25
25
  if (node['a:right']) {
26
26
  const obj = {
@@ -29,7 +29,7 @@ export function getTableBorders(node, warpObj) {
29
29
  }
30
30
  }
31
31
  const border = getBorder(obj, undefined, warpObj)
32
- borderStyles.right = border
32
+ borders.right = border
33
33
  }
34
34
  if (node['a:left']) {
35
35
  const obj = {
@@ -38,9 +38,9 @@ export function getTableBorders(node, warpObj) {
38
38
  }
39
39
  }
40
40
  const border = getBorder(obj, undefined, warpObj)
41
- borderStyles.left = border
41
+ borders.left = border
42
42
  }
43
- return borderStyles
43
+ return borders
44
44
  }
45
45
 
46
46
  export async function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
@@ -76,10 +76,38 @@ export async function getTableCellParams(tcNode, thisTblStyle, cellSource, warpO
76
76
  if (getTextByPathList(rowTxtStyl, ['attrs', 'b']) === 'on') fontBold = true
77
77
  }
78
78
 
79
+ let lin_bottm = getTextByPathList(tcNode, ['a:tcPr', 'a:lnB'])
80
+ if (!lin_bottm) {
81
+ if (cellSource) lin_bottm = getTextByPathList(thisTblStyle[cellSource], ['a:tcStyle', 'a:tcBdr', 'a:bottom', 'a:ln'])
82
+ if (!lin_bottm) lin_bottm = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:tcBdr', 'a:bottom', 'a:ln'])
83
+ }
84
+ let lin_top = getTextByPathList(tcNode, ['a:tcPr', 'a:lnT'])
85
+ if (!lin_top) {
86
+ if (cellSource) lin_top = getTextByPathList(thisTblStyle[cellSource], ['a:tcStyle', 'a:tcBdr', 'a:top', 'a:ln'])
87
+ if (!lin_top) lin_top = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:tcBdr', 'a:top', 'a:ln'])
88
+ }
89
+ let lin_left = getTextByPathList(tcNode, ['a:tcPr', 'a:lnL'])
90
+ if (!lin_left) {
91
+ if (cellSource) lin_left = getTextByPathList(thisTblStyle[cellSource], ['a:tcStyle', 'a:tcBdr', 'a:left', 'a:ln'])
92
+ if (!lin_left) lin_left = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:tcBdr', 'a:left', 'a:ln'])
93
+ }
94
+ let lin_right = getTextByPathList(tcNode, ['a:tcPr', 'a:lnR'])
95
+ if (!lin_right) {
96
+ if (cellSource) lin_right = getTextByPathList(thisTblStyle[cellSource], ['a:tcStyle', 'a:tcBdr', 'a:right', 'a:ln'])
97
+ if (!lin_right) lin_right = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:tcBdr', 'a:right', 'a:ln'])
98
+ }
99
+
100
+ const borders = {}
101
+ if (lin_bottm) borders.bottom = getBorder(lin_bottm, undefined, warpObj)
102
+ if (lin_top) borders.top = getBorder(lin_top, undefined, warpObj)
103
+ if (lin_left) borders.left = getBorder(lin_left, undefined, warpObj)
104
+ if (lin_right) borders.right = getBorder(lin_right, undefined, warpObj)
105
+
79
106
  return {
80
107
  fillColor,
81
108
  fontColor,
82
109
  fontBold,
110
+ borders,
83
111
  rowSpan: rowSpan ? +rowSpan : undefined,
84
112
  colSpan: colSpan ? +colSpan : undefined,
85
113
  vMerge: vMerge ? +vMerge : undefined,
package/dist/wx.png DELETED
Binary file