pptxtojson 1.1.0 → 1.2.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.
@@ -19,11 +19,15 @@ export function simplifyLostLess(children, parentAttributes = {}) {
19
19
  if (!out[child.tagName]) out[child.tagName] = []
20
20
 
21
21
  const kids = simplifyLostLess(child.children || [], child.attributes)
22
- out[child.tagName].push(kids)
23
-
24
- if (Object.keys(child.attributes).length) {
25
- kids.attrs = { order: cust_attr_order++, ...child.attributes }
22
+
23
+ if (typeof kids === 'object') {
24
+ if (!kids.attrs) kids.attrs = { order: cust_attr_order++ }
25
+ else kids.attrs.order = cust_attr_order++
26
26
  }
27
+ if (Object.keys(child.attributes || {}).length) {
28
+ kids.attrs = { ...kids.attrs, ...child.attributes }
29
+ }
30
+ out[child.tagName].push(kids)
27
31
  }
28
32
  for (const child in out) {
29
33
  if (out[child].length === 1) out[child] = out[child][0]
package/src/table.js CHANGED
@@ -43,7 +43,7 @@ export function getTableBorders(node, warpObj) {
43
43
  return borderStyles
44
44
  }
45
45
 
46
- export function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
46
+ export async function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
47
47
  const rowSpan = getTextByPathList(tcNode, ['attrs', 'rowSpan'])
48
48
  const colSpan = getTextByPathList(tcNode, ['attrs', 'gridSpan'])
49
49
  const vMerge = getTextByPathList(tcNode, ['attrs', 'vMerge'])
@@ -55,7 +55,11 @@ export function getTableCellParams(tcNode, thisTblStyle, cellSource, warpObj) {
55
55
  const getCelFill = getTextByPathList(tcNode, ['a:tcPr'])
56
56
  if (getCelFill) {
57
57
  const cellObj = { 'p:spPr': getCelFill }
58
- fillColor = getShapeFill(cellObj, undefined, warpObj)
58
+ const fill = await getShapeFill(cellObj, undefined, warpObj)
59
+
60
+ if (fill && fill.type === 'color' && fill.value) {
61
+ fillColor = fill.value
62
+ }
59
63
  }
60
64
  if (!fillColor) {
61
65
  let bgFillschemeClr
package/src/utils.js CHANGED
@@ -54,8 +54,6 @@ export function eachElement(node, func) {
54
54
  }
55
55
 
56
56
  export function getTextByPathList(node, path) {
57
- if (path.constructor !== Array) throw Error('Error of path type! path is not array.')
58
-
59
57
  if (!node) return node
60
58
 
61
59
  for (const key of path) {
@@ -150,4 +148,13 @@ export function toHex(n) {
150
148
  hex = '0' + hex
151
149
  }
152
150
  return hex
151
+ }
152
+
153
+ export function hasValidText(htmlString) {
154
+ if (!DOMParser) return true
155
+
156
+ const parser = new DOMParser()
157
+ const doc = parser.parseFromString(htmlString, 'text/html')
158
+ const text = doc.body.textContent || doc.body.innerText
159
+ return text.trim() !== ''
153
160
  }