pptxtojson 1.3.1 → 1.4.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/README.md +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/pptxtojson.js +33 -4
- package/src/shadow.js +1 -1
- package/src/shapePath.js +4635 -0
- package/src/utils.js +4 -1
package/package.json
CHANGED
package/src/pptxtojson.js
CHANGED
|
@@ -12,6 +12,7 @@ import { getShadow } from './shadow'
|
|
|
12
12
|
import { getTableBorders, getTableCellParams, getTableRowParams } from './table'
|
|
13
13
|
import { RATIO_EMUs_Points } from './constants'
|
|
14
14
|
import { findOMath, latexFormart, parseOMath } from './math'
|
|
15
|
+
import { getShapePath } from './shapePath'
|
|
15
16
|
|
|
16
17
|
export async function parse(file) {
|
|
17
18
|
const slides = []
|
|
@@ -438,6 +439,12 @@ async function processMathNode(node, warpObj, source) {
|
|
|
438
439
|
const blipFill = getTextByPathList(fallback, ['p:sp', 'p:spPr', 'a:blipFill'])
|
|
439
440
|
const picBase64 = await getPicFill(source, blipFill, warpObj)
|
|
440
441
|
|
|
442
|
+
let text = ''
|
|
443
|
+
if (getTextByPathList(choice, ['p:sp', 'p:txBody', 'a:p', 'a:r'])) {
|
|
444
|
+
const sp = getTextByPathList(choice, ['p:sp'])
|
|
445
|
+
text = genTextBody(sp['p:txBody'], sp, undefined, undefined, warpObj)
|
|
446
|
+
}
|
|
447
|
+
|
|
441
448
|
return {
|
|
442
449
|
type: 'math',
|
|
443
450
|
top,
|
|
@@ -446,6 +453,7 @@ async function processMathNode(node, warpObj, source) {
|
|
|
446
453
|
height,
|
|
447
454
|
latex,
|
|
448
455
|
picBase64,
|
|
456
|
+
text,
|
|
449
457
|
order,
|
|
450
458
|
}
|
|
451
459
|
}
|
|
@@ -612,12 +620,14 @@ async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name,
|
|
|
612
620
|
|
|
613
621
|
if (shadow) data.shadow = shadow
|
|
614
622
|
|
|
623
|
+
const isHasValidText = data.content && hasValidText(data.content)
|
|
624
|
+
|
|
615
625
|
if (custShapType && type !== 'diagram') {
|
|
616
626
|
const ext = getTextByPathList(slideXfrmNode, ['a:ext', 'attrs'])
|
|
617
627
|
const w = parseInt(ext['cx']) * RATIO_EMUs_Points
|
|
618
628
|
const h = parseInt(ext['cy']) * RATIO_EMUs_Points
|
|
619
629
|
const d = getCustomShapePath(custShapType, w, h)
|
|
620
|
-
if (
|
|
630
|
+
if (!isHasValidText) data.content = ''
|
|
621
631
|
|
|
622
632
|
return {
|
|
623
633
|
...data,
|
|
@@ -626,12 +636,26 @@ async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name,
|
|
|
626
636
|
path: d,
|
|
627
637
|
}
|
|
628
638
|
}
|
|
629
|
-
|
|
630
|
-
|
|
639
|
+
|
|
640
|
+
let shapePath = ''
|
|
641
|
+
if (shapType) shapePath = getShapePath(shapType, width, height, node)
|
|
642
|
+
|
|
643
|
+
if (shapType && (type === 'obj' || !type || shapType !== 'rect')) {
|
|
644
|
+
if (!isHasValidText) data.content = ''
|
|
645
|
+
return {
|
|
646
|
+
...data,
|
|
647
|
+
type: 'shape',
|
|
648
|
+
shapType,
|
|
649
|
+
path: shapePath,
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (shapType && !isHasValidText && (fill || borderWidth)) {
|
|
631
653
|
return {
|
|
632
654
|
...data,
|
|
633
655
|
type: 'shape',
|
|
656
|
+
content: '',
|
|
634
657
|
shapType,
|
|
658
|
+
path: shapePath,
|
|
635
659
|
}
|
|
636
660
|
}
|
|
637
661
|
return {
|
|
@@ -655,7 +679,12 @@ async function processPicNode(node, warpObj, source) {
|
|
|
655
679
|
const imgFileExt = extractFileExtension(imgName).toLowerCase()
|
|
656
680
|
const zip = warpObj['zip']
|
|
657
681
|
const imgArrayBuffer = await zip.file(imgName).async('arraybuffer')
|
|
658
|
-
|
|
682
|
+
|
|
683
|
+
let xfrmNode = node['p:spPr']['a:xfrm']
|
|
684
|
+
if (!xfrmNode) {
|
|
685
|
+
const idx = getTextByPathList(node, ['p:nvPicPr', 'p:nvPr', 'p:ph', 'attrs', 'idx'])
|
|
686
|
+
if (idx) xfrmNode = getTextByPathList(warpObj['slideLayoutTables'], ['idxTable', idx, 'p:spPr', 'a:xfrm'])
|
|
687
|
+
}
|
|
659
688
|
|
|
660
689
|
const mimeType = getMimeType(imgFileExt)
|
|
661
690
|
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
package/src/shadow.js
CHANGED
|
@@ -5,7 +5,7 @@ export function getShadow(node, warpObj) {
|
|
|
5
5
|
const chdwClrNode = getSolidFill(node, undefined, undefined, warpObj)
|
|
6
6
|
const outerShdwAttrs = node['attrs']
|
|
7
7
|
const dir = outerShdwAttrs['dir'] ? (parseInt(outerShdwAttrs['dir']) / 60000) : 0
|
|
8
|
-
const dist = parseInt(outerShdwAttrs['dist']) * RATIO_EMUs_Points
|
|
8
|
+
const dist = outerShdwAttrs['dist'] ? parseInt(outerShdwAttrs['dist']) * RATIO_EMUs_Points : 0
|
|
9
9
|
const blurRad = outerShdwAttrs['blurRad'] ? parseInt(outerShdwAttrs['blurRad']) * RATIO_EMUs_Points : ''
|
|
10
10
|
const vx = dist * Math.sin(dir * Math.PI / 180)
|
|
11
11
|
const hx = dist * Math.cos(dir * Math.PI / 180)
|