pptxtojson 1.1.0 → 1.1.1
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/dist/index.d.ts +11 -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 +28 -6
- package/src/readXmlFile.js +8 -4
- package/src/utils.js +9 -0
package/package.json
CHANGED
package/src/pptxtojson.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getVerticalAlign } from './align'
|
|
|
7
7
|
import { getPosition, getSize } from './position'
|
|
8
8
|
import { genTextBody } from './text'
|
|
9
9
|
import { getCustomShapePath } from './shape'
|
|
10
|
-
import { extractFileExtension, base64ArrayBuffer, getTextByPathList, angleToDegrees, getMimeType, isVideoLink, escapeHtml } from './utils'
|
|
10
|
+
import { extractFileExtension, base64ArrayBuffer, getTextByPathList, angleToDegrees, getMimeType, isVideoLink, escapeHtml, hasValidText } from './utils'
|
|
11
11
|
import { getShadow } from './shadow'
|
|
12
12
|
import { getTableBorders, getTableCellParams, getTableRowParams } from './table'
|
|
13
13
|
import { RATIO_EMUs_Points } from './constants'
|
|
@@ -431,6 +431,7 @@ async function processNodesInSlide(nodeKey, nodeValue, warpObj, source) {
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
function processMathNode(node) {
|
|
434
|
+
const order = node['attrs']['order']
|
|
434
435
|
const xfrmNode = getTextByPathList(node, ['p:sp', 'p:spPr', 'a:xfrm'])
|
|
435
436
|
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
436
437
|
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
@@ -445,10 +446,12 @@ function processMathNode(node) {
|
|
|
445
446
|
width,
|
|
446
447
|
height,
|
|
447
448
|
latex,
|
|
449
|
+
order,
|
|
448
450
|
}
|
|
449
451
|
}
|
|
450
452
|
|
|
451
453
|
async function processGroupSpNode(node, warpObj, source) {
|
|
454
|
+
const order = node['attrs']['order']
|
|
452
455
|
const xfrmNode = getTextByPathList(node, ['p:grpSpPr', 'a:xfrm'])
|
|
453
456
|
if (!xfrmNode) return null
|
|
454
457
|
|
|
@@ -488,6 +491,7 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
488
491
|
width: cx,
|
|
489
492
|
height: cy,
|
|
490
493
|
rotate,
|
|
494
|
+
order,
|
|
491
495
|
elements: elements.map(element => ({
|
|
492
496
|
...element,
|
|
493
497
|
left: (element.left - chx) * ws,
|
|
@@ -502,6 +506,7 @@ function processSpNode(node, warpObj, source) {
|
|
|
502
506
|
const name = getTextByPathList(node, ['p:nvSpPr', 'p:cNvPr', 'attrs', 'name'])
|
|
503
507
|
const idx = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'idx'])
|
|
504
508
|
let type = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'type'])
|
|
509
|
+
const order = getTextByPathList(node, ['attrs', 'order'])
|
|
505
510
|
|
|
506
511
|
let slideLayoutSpNode, slideMasterSpNode
|
|
507
512
|
|
|
@@ -532,17 +537,18 @@ function processSpNode(node, warpObj, source) {
|
|
|
532
537
|
else type = 'obj'
|
|
533
538
|
}
|
|
534
539
|
|
|
535
|
-
return genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpObj)
|
|
540
|
+
return genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj)
|
|
536
541
|
}
|
|
537
542
|
|
|
538
543
|
function processCxnSpNode(node, warpObj) {
|
|
539
544
|
const name = node['p:nvCxnSpPr']['p:cNvPr']['attrs']['name']
|
|
540
545
|
const type = (node['p:nvCxnSpPr']['p:nvPr']['p:ph'] === undefined) ? undefined : node['p:nvSpPr']['p:nvPr']['p:ph']['attrs']['type']
|
|
546
|
+
const order = node['attrs']['order']
|
|
541
547
|
|
|
542
|
-
return genShape(node, undefined, undefined, name, type, warpObj)
|
|
548
|
+
return genShape(node, undefined, undefined, name, type, order, warpObj)
|
|
543
549
|
}
|
|
544
550
|
|
|
545
|
-
function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpObj) {
|
|
551
|
+
function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj) {
|
|
546
552
|
const xfrmList = ['p:spPr', 'a:xfrm']
|
|
547
553
|
const slideXfrmNode = getTextByPathList(node, xfrmList)
|
|
548
554
|
const slideLayoutXfrmNode = getTextByPathList(slideLayoutSpNode, xfrmList)
|
|
@@ -568,7 +574,10 @@ function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpOb
|
|
|
568
574
|
else txtRotate = rotate
|
|
569
575
|
|
|
570
576
|
let content = ''
|
|
571
|
-
if (node['p:txBody'])
|
|
577
|
+
if (node['p:txBody']) {
|
|
578
|
+
content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, type, warpObj)
|
|
579
|
+
if (!hasValidText(content)) content = ''
|
|
580
|
+
}
|
|
572
581
|
|
|
573
582
|
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
|
|
574
583
|
const fillColor = getShapeFill(node, undefined, warpObj) || ''
|
|
@@ -596,6 +605,7 @@ function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpOb
|
|
|
596
605
|
rotate,
|
|
597
606
|
vAlign,
|
|
598
607
|
name,
|
|
608
|
+
order,
|
|
599
609
|
}
|
|
600
610
|
|
|
601
611
|
if (shadow) data.shadow = shadow
|
|
@@ -633,6 +643,8 @@ async function processPicNode(node, warpObj, source) {
|
|
|
633
643
|
if (source === 'slideMasterBg') resObj = warpObj['masterResObj']
|
|
634
644
|
else if (source === 'slideLayoutBg') resObj = warpObj['layoutResObj']
|
|
635
645
|
else resObj = warpObj['slideResObj']
|
|
646
|
+
|
|
647
|
+
const order = node['attrs']['order']
|
|
636
648
|
|
|
637
649
|
const rid = node['p:blipFill']['a:blip']['attrs']['r:embed']
|
|
638
650
|
const imgName = resObj[rid]['target']
|
|
@@ -697,6 +709,7 @@ async function processPicNode(node, warpObj, source) {
|
|
|
697
709
|
height,
|
|
698
710
|
rotate,
|
|
699
711
|
blob: videoBlob,
|
|
712
|
+
order,
|
|
700
713
|
}
|
|
701
714
|
}
|
|
702
715
|
if (videoNode && isVdeoLink) {
|
|
@@ -708,6 +721,7 @@ async function processPicNode(node, warpObj, source) {
|
|
|
708
721
|
height,
|
|
709
722
|
rotate,
|
|
710
723
|
src: videoFile,
|
|
724
|
+
order,
|
|
711
725
|
}
|
|
712
726
|
}
|
|
713
727
|
if (audioNode) {
|
|
@@ -719,6 +733,7 @@ async function processPicNode(node, warpObj, source) {
|
|
|
719
733
|
height,
|
|
720
734
|
rotate,
|
|
721
735
|
blob: audioBlob,
|
|
736
|
+
order,
|
|
722
737
|
}
|
|
723
738
|
}
|
|
724
739
|
return {
|
|
@@ -730,7 +745,8 @@ async function processPicNode(node, warpObj, source) {
|
|
|
730
745
|
rotate,
|
|
731
746
|
src,
|
|
732
747
|
isFlipV,
|
|
733
|
-
isFlipH
|
|
748
|
+
isFlipH,
|
|
749
|
+
order,
|
|
734
750
|
}
|
|
735
751
|
}
|
|
736
752
|
|
|
@@ -759,6 +775,7 @@ async function processGraphicFrameNode(node, warpObj, source) {
|
|
|
759
775
|
}
|
|
760
776
|
|
|
761
777
|
function genTable(node, warpObj) {
|
|
778
|
+
const order = node['attrs']['order']
|
|
762
779
|
const tableNode = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl'])
|
|
763
780
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
764
781
|
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
@@ -928,11 +945,13 @@ function genTable(node, warpObj) {
|
|
|
928
945
|
width,
|
|
929
946
|
height,
|
|
930
947
|
data,
|
|
948
|
+
order,
|
|
931
949
|
...(tbl_border || {}),
|
|
932
950
|
}
|
|
933
951
|
}
|
|
934
952
|
|
|
935
953
|
async function genChart(node, warpObj) {
|
|
954
|
+
const order = node['attrs']['order']
|
|
936
955
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
937
956
|
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
938
957
|
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
@@ -954,6 +973,7 @@ async function genChart(node, warpObj) {
|
|
|
954
973
|
height,
|
|
955
974
|
data: chart.data,
|
|
956
975
|
chartType: chart.type,
|
|
976
|
+
order,
|
|
957
977
|
}
|
|
958
978
|
if (chart.marker !== undefined) data.marker = chart.marker
|
|
959
979
|
if (chart.barDir !== undefined) data.barDir = chart.barDir
|
|
@@ -965,6 +985,7 @@ async function genChart(node, warpObj) {
|
|
|
965
985
|
}
|
|
966
986
|
|
|
967
987
|
function genDiagram(node, warpObj) {
|
|
988
|
+
const order = node['attrs']['order']
|
|
968
989
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
969
990
|
const { left, top } = getPosition(xfrmNode, undefined, undefined)
|
|
970
991
|
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
@@ -985,5 +1006,6 @@ function genDiagram(node, warpObj) {
|
|
|
985
1006
|
width,
|
|
986
1007
|
height,
|
|
987
1008
|
elements,
|
|
1009
|
+
order,
|
|
988
1010
|
}
|
|
989
1011
|
}
|
package/src/readXmlFile.js
CHANGED
|
@@ -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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
kids.attrs =
|
|
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/utils.js
CHANGED
|
@@ -150,4 +150,13 @@ export function toHex(n) {
|
|
|
150
150
|
hex = '0' + hex
|
|
151
151
|
}
|
|
152
152
|
return hex
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function hasValidText(htmlString) {
|
|
156
|
+
if (!DOMParser) return true
|
|
157
|
+
|
|
158
|
+
const parser = new DOMParser()
|
|
159
|
+
const doc = parser.parseFromString(htmlString, 'text/html')
|
|
160
|
+
const text = doc.body.textContent || doc.body.innerText
|
|
161
|
+
return text.trim() !== ''
|
|
153
162
|
}
|