pptxtojson 1.2.1 → 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.1",
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
@@ -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, getSolidFill } from './fill'
4
+ import { getSlideBackgroundFill, getShapeFill, getSolidFill, getPicFill } from './fill'
5
5
  import { getChartInfo } from './chart'
6
6
  import { getVerticalAlign } from './align'
7
7
  import { getPosition, getSize } from './position'
@@ -414,7 +414,7 @@ async function processNodesInSlide(nodeKey, nodeValue, warpObj, source) {
414
414
  json = await processGroupSpNode(getTextByPathList(nodeValue, ['mc:Fallback']), warpObj, source)
415
415
  }
416
416
  else if (getTextByPathList(nodeValue, ['mc:Choice'])) {
417
- json = processMathNode(getTextByPathList(nodeValue, ['mc:Choice']))
417
+ json = await processMathNode(nodeValue, warpObj, source)
418
418
  }
419
419
  break
420
420
  default:
@@ -423,15 +423,21 @@ async function processNodesInSlide(nodeKey, nodeValue, warpObj, source) {
423
423
  return json
424
424
  }
425
425
 
426
- function processMathNode(node) {
426
+ async function processMathNode(node, warpObj, source) {
427
+ const choice = getTextByPathList(node, ['mc:Choice'])
428
+ const fallback = getTextByPathList(node, ['mc:Fallback'])
429
+
427
430
  const order = node['attrs']['order']
428
- const xfrmNode = getTextByPathList(node, ['p:sp', 'p:spPr', 'a:xfrm'])
431
+ const xfrmNode = getTextByPathList(choice, ['p:sp', 'p:spPr', 'a:xfrm'])
429
432
  const { top, left } = getPosition(xfrmNode, undefined, undefined)
430
433
  const { width, height } = getSize(xfrmNode, undefined, undefined)
431
434
 
432
- const oMath = findOMath(node)[0]
435
+ const oMath = findOMath(choice)[0]
433
436
  const latex = latexFormart(parseOMath(oMath))
434
437
 
438
+ const blipFill = getTextByPathList(fallback, ['p:sp', 'p:spPr', 'a:blipFill'])
439
+ const picBase64 = await getPicFill(source, blipFill, warpObj)
440
+
435
441
  return {
436
442
  type: 'math',
437
443
  top,
@@ -439,6 +445,7 @@ function processMathNode(node) {
439
445
  width,
440
446
  height,
441
447
  latex,
448
+ picBase64,
442
449
  order,
443
450
  }
444
451
  }
@@ -774,6 +781,17 @@ async function genTable(node, warpObj) {
774
781
  const { width, height } = getSize(xfrmNode, undefined, undefined)
775
782
 
776
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
+ }
777
795
 
778
796
  const firstRowAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstRow'] : undefined
779
797
  const firstColAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstCol'] : undefined
@@ -811,13 +829,10 @@ async function genTable(node, warpObj) {
811
829
  }
812
830
  if (thisTblStyle) thisTblStyle['tblStylAttrObj'] = tblStylAttrObj
813
831
 
814
- let tbl_border
832
+ let borders = {}
815
833
  const tblStyl = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle'])
816
834
  const tblBorderStyl = getTextByPathList(tblStyl, ['a:tcBdr'])
817
- if (tblBorderStyl) {
818
- const tbl_borders = getTableBorders(tblBorderStyl, warpObj)
819
- if (tbl_borders) tbl_border = tbl_borders.bottom || tbl_borders.left || tbl_borders.right || tbl_borders.top
820
- }
835
+ if (tblBorderStyl) borders = getTableBorders(tblBorderStyl, warpObj)
821
836
 
822
837
  let tbl_bgcolor = ''
823
838
  let tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:tblBg', 'a:fillRef'])
@@ -833,8 +848,13 @@ async function genTable(node, warpObj) {
833
848
  if (trNodes.constructor !== Array) trNodes = [trNodes]
834
849
 
835
850
  const data = []
851
+ const rowHeights = []
836
852
  for (let i = 0; i < trNodes.length; i++) {
837
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)
838
858
 
839
859
  const {
840
860
  fillColor,
@@ -893,6 +913,7 @@ async function genTable(node, warpObj) {
893
913
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
894
914
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
895
915
  if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
916
+ if (cell.borders) td.borders = cell.borders
896
917
 
897
918
  tr.push(td)
898
919
  }
@@ -924,6 +945,7 @@ async function genTable(node, warpObj) {
924
945
  if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
925
946
  if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
926
947
  if (cell.fillColor || fillColor || tbl_bgcolor) td.fillColor = cell.fillColor || fillColor || tbl_bgcolor
948
+ if (cell.borders) td.borders = cell.borders
927
949
 
928
950
  tr.push(td)
929
951
  }
@@ -938,7 +960,9 @@ async function genTable(node, warpObj) {
938
960
  height,
939
961
  data,
940
962
  order,
941
- ...(tbl_border || {}),
963
+ borders,
964
+ rowHeights,
965
+ colWidths,
942
966
  }
943
967
  }
944
968
 
package/src/shape.js CHANGED
@@ -35,7 +35,7 @@ export function getCustomShapePath(custShapType, w, h) {
35
35
  const pathLstNode = getTextByPathList(custShapType, ['a:pathLst'])
36
36
  let pathNodes = getTextByPathList(pathLstNode, ['a:path'])
37
37
 
38
- if (Array.isArray(pathNodes)) pathNodes = pathNodes.pop()
38
+ if (Array.isArray(pathNodes)) pathNodes = pathNodes.shift()
39
39
 
40
40
  const maxX = parseInt(pathNodes['attrs']['w'])
41
41
  const maxY = parseInt(pathNodes['attrs']['h'])
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