pptxtojson 1.3.0 → 1.3.2
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 +6 -0
- package/dist/index.d.ts +13 -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/fill.js +14 -1
- package/src/pptxtojson.js +55 -20
- package/src/shadow.js +1 -1
- package/src/table.js +1 -1
package/package.json
CHANGED
package/src/fill.js
CHANGED
|
@@ -459,7 +459,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
export async function getShapeFill(node, isSvgMode, warpObj, source) {
|
|
462
|
+
export async function getShapeFill(node, pNode, isSvgMode, warpObj, source) {
|
|
463
463
|
const fillType = getFillType(getTextByPathList(node, ['p:spPr']))
|
|
464
464
|
let type = 'color'
|
|
465
465
|
let fillValue = ''
|
|
@@ -491,6 +491,19 @@ export async function getShapeFill(node, isSvgMode, warpObj, source) {
|
|
|
491
491
|
fillValue = getSolidFill(clrName, undefined, undefined, warpObj)
|
|
492
492
|
type = 'color'
|
|
493
493
|
}
|
|
494
|
+
if (!fillValue && pNode) {
|
|
495
|
+
const grpFill = getTextByPathList(node, ['p:spPr', 'a:grpFill'])
|
|
496
|
+
if (grpFill) {
|
|
497
|
+
const grpShpFill = pNode['p:grpSpPr']
|
|
498
|
+
if (grpShpFill) {
|
|
499
|
+
const spShpNode = { 'p:spPr': grpShpFill }
|
|
500
|
+
return getShapeFill(spShpNode, node, isSvgMode, warpObj, source)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
else if (fillType === 'NO_FILL') {
|
|
504
|
+
return isSvgMode ? 'none' : ''
|
|
505
|
+
}
|
|
506
|
+
}
|
|
494
507
|
|
|
495
508
|
return {
|
|
496
509
|
type,
|
package/src/pptxtojson.js
CHANGED
|
@@ -268,7 +268,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
268
268
|
for (const nodeKey in nodes) {
|
|
269
269
|
if (nodes[nodeKey].constructor !== Array) nodes[nodeKey] = [nodes[nodeKey]]
|
|
270
270
|
for (const node of nodes[nodeKey]) {
|
|
271
|
-
const ret = await processNodesInSlide(nodeKey, node, warpObj, 'slide')
|
|
271
|
+
const ret = await processNodesInSlide(nodeKey, node, nodes, warpObj, 'slide')
|
|
272
272
|
if (ret) elements.push(ret)
|
|
273
273
|
}
|
|
274
274
|
}
|
|
@@ -314,7 +314,7 @@ async function getLayoutElements(warpObj) {
|
|
|
314
314
|
for (let i = 0; i < nodesSldLayout[nodeKey].length; i++) {
|
|
315
315
|
const ph = getTextByPathList(nodesSldLayout[nodeKey][i], ['p:nvSpPr', 'p:nvPr', 'p:ph'])
|
|
316
316
|
if (!ph) {
|
|
317
|
-
const ret = await processNodesInSlide(nodeKey, nodesSldLayout[nodeKey][i], warpObj, 'slideLayoutBg')
|
|
317
|
+
const ret = await processNodesInSlide(nodeKey, nodesSldLayout[nodeKey][i], nodesSldLayout, warpObj, 'slideLayoutBg')
|
|
318
318
|
if (ret) elements.push(ret)
|
|
319
319
|
}
|
|
320
320
|
}
|
|
@@ -322,7 +322,7 @@ async function getLayoutElements(warpObj) {
|
|
|
322
322
|
else {
|
|
323
323
|
const ph = getTextByPathList(nodesSldLayout[nodeKey], ['p:nvSpPr', 'p:nvPr', 'p:ph'])
|
|
324
324
|
if (!ph) {
|
|
325
|
-
const ret = await processNodesInSlide(nodeKey, nodesSldLayout[nodeKey], warpObj, 'slideLayoutBg')
|
|
325
|
+
const ret = await processNodesInSlide(nodeKey, nodesSldLayout[nodeKey], nodesSldLayout, warpObj, 'slideLayoutBg')
|
|
326
326
|
if (ret) elements.push(ret)
|
|
327
327
|
}
|
|
328
328
|
}
|
|
@@ -334,7 +334,7 @@ async function getLayoutElements(warpObj) {
|
|
|
334
334
|
for (let i = 0; i < nodesSldMaster[nodeKey].length; i++) {
|
|
335
335
|
const ph = getTextByPathList(nodesSldMaster[nodeKey][i], ['p:nvSpPr', 'p:nvPr', 'p:ph'])
|
|
336
336
|
if (!ph) {
|
|
337
|
-
const ret = await processNodesInSlide(nodeKey, nodesSldMaster[nodeKey][i], warpObj, 'slideMasterBg')
|
|
337
|
+
const ret = await processNodesInSlide(nodeKey, nodesSldMaster[nodeKey][i], nodesSldMaster, warpObj, 'slideMasterBg')
|
|
338
338
|
if (ret) elements.push(ret)
|
|
339
339
|
}
|
|
340
340
|
}
|
|
@@ -342,7 +342,7 @@ async function getLayoutElements(warpObj) {
|
|
|
342
342
|
else {
|
|
343
343
|
const ph = getTextByPathList(nodesSldMaster[nodeKey], ['p:nvSpPr', 'p:nvPr', 'p:ph'])
|
|
344
344
|
if (!ph) {
|
|
345
|
-
const ret = await processNodesInSlide(nodeKey, nodesSldMaster[nodeKey], warpObj, 'slideMasterBg')
|
|
345
|
+
const ret = await processNodesInSlide(nodeKey, nodesSldMaster[nodeKey], nodesSldMaster, warpObj, 'slideMasterBg')
|
|
346
346
|
if (ret) elements.push(ret)
|
|
347
347
|
}
|
|
348
348
|
}
|
|
@@ -390,15 +390,15 @@ function indexNodes(content) {
|
|
|
390
390
|
return { idTable, idxTable, typeTable }
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
async function processNodesInSlide(nodeKey, nodeValue, warpObj, source) {
|
|
393
|
+
async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source) {
|
|
394
394
|
let json
|
|
395
395
|
|
|
396
396
|
switch (nodeKey) {
|
|
397
397
|
case 'p:sp': // Shape, Text
|
|
398
|
-
json = await processSpNode(nodeValue, warpObj, source)
|
|
398
|
+
json = await processSpNode(nodeValue, nodes, warpObj, source)
|
|
399
399
|
break
|
|
400
400
|
case 'p:cxnSp': // Shape, Text
|
|
401
|
-
json = await processCxnSpNode(nodeValue, warpObj, source)
|
|
401
|
+
json = await processCxnSpNode(nodeValue, nodes, warpObj, source)
|
|
402
402
|
break
|
|
403
403
|
case 'p:pic': // Image, Video, Audio
|
|
404
404
|
json = await processPicNode(nodeValue, warpObj, source)
|
|
@@ -464,6 +464,9 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
464
464
|
const chcx = parseInt(xfrmNode['a:chExt']['attrs']['cx']) * RATIO_EMUs_Points
|
|
465
465
|
const chcy = parseInt(xfrmNode['a:chExt']['attrs']['cy']) * RATIO_EMUs_Points
|
|
466
466
|
|
|
467
|
+
const isFlipV = getTextByPathList(xfrmNode, ['attrs', 'flipV']) === '1'
|
|
468
|
+
const isFlipH = getTextByPathList(xfrmNode, ['attrs', 'flipH']) === '1'
|
|
469
|
+
|
|
467
470
|
let rotate = getTextByPathList(xfrmNode, ['attrs', 'rot']) || 0
|
|
468
471
|
if (rotate) rotate = angleToDegrees(rotate)
|
|
469
472
|
|
|
@@ -474,12 +477,12 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
474
477
|
for (const nodeKey in node) {
|
|
475
478
|
if (node[nodeKey].constructor === Array) {
|
|
476
479
|
for (const item of node[nodeKey]) {
|
|
477
|
-
const ret = await processNodesInSlide(nodeKey, item, warpObj, source)
|
|
480
|
+
const ret = await processNodesInSlide(nodeKey, item, node, warpObj, source)
|
|
478
481
|
if (ret) elements.push(ret)
|
|
479
482
|
}
|
|
480
483
|
}
|
|
481
484
|
else {
|
|
482
|
-
const ret = await processNodesInSlide(nodeKey, node[nodeKey], warpObj, source)
|
|
485
|
+
const ret = await processNodesInSlide(nodeKey, node[nodeKey], node, warpObj, source)
|
|
483
486
|
if (ret) elements.push(ret)
|
|
484
487
|
}
|
|
485
488
|
}
|
|
@@ -492,6 +495,8 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
492
495
|
height: cy,
|
|
493
496
|
rotate,
|
|
494
497
|
order,
|
|
498
|
+
isFlipV,
|
|
499
|
+
isFlipH,
|
|
495
500
|
elements: elements.map(element => ({
|
|
496
501
|
...element,
|
|
497
502
|
left: (element.left - chx) * ws,
|
|
@@ -502,7 +507,7 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
502
507
|
}
|
|
503
508
|
}
|
|
504
509
|
|
|
505
|
-
async function processSpNode(node, warpObj, source) {
|
|
510
|
+
async function processSpNode(node, pNode, warpObj, source) {
|
|
506
511
|
const name = getTextByPathList(node, ['p:nvSpPr', 'p:cNvPr', 'attrs', 'name'])
|
|
507
512
|
const idx = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'idx'])
|
|
508
513
|
let type = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'type'])
|
|
@@ -537,18 +542,18 @@ async function processSpNode(node, warpObj, source) {
|
|
|
537
542
|
else type = 'obj'
|
|
538
543
|
}
|
|
539
544
|
|
|
540
|
-
return await genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source)
|
|
545
|
+
return await genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source)
|
|
541
546
|
}
|
|
542
547
|
|
|
543
|
-
async function processCxnSpNode(node, warpObj, source) {
|
|
548
|
+
async function processCxnSpNode(node, pNode, warpObj, source) {
|
|
544
549
|
const name = node['p:nvCxnSpPr']['p:cNvPr']['attrs']['name']
|
|
545
550
|
const type = (node['p:nvCxnSpPr']['p:nvPr']['p:ph'] === undefined) ? undefined : node['p:nvSpPr']['p:nvPr']['p:ph']['attrs']['type']
|
|
546
551
|
const order = node['attrs']['order']
|
|
547
552
|
|
|
548
|
-
return await genShape(node, undefined, undefined, name, type, order, warpObj, source)
|
|
553
|
+
return await genShape(node, pNode, undefined, undefined, name, type, order, warpObj, source)
|
|
549
554
|
}
|
|
550
555
|
|
|
551
|
-
async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source) {
|
|
556
|
+
async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source) {
|
|
552
557
|
const xfrmList = ['p:spPr', 'a:xfrm']
|
|
553
558
|
const slideXfrmNode = getTextByPathList(node, xfrmList)
|
|
554
559
|
const slideLayoutXfrmNode = getTextByPathList(slideLayoutSpNode, xfrmList)
|
|
@@ -577,7 +582,7 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
577
582
|
if (node['p:txBody']) content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, type, warpObj)
|
|
578
583
|
|
|
579
584
|
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
|
|
580
|
-
const fill = await getShapeFill(node, undefined, warpObj, source) || ''
|
|
585
|
+
const fill = await getShapeFill(node, pNode, undefined, warpObj, source) || ''
|
|
581
586
|
|
|
582
587
|
let shadow
|
|
583
588
|
const outerShdwNode = getTextByPathList(node, ['p:spPr', 'a:effectLst', 'a:outerShdw'])
|
|
@@ -607,12 +612,14 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
607
612
|
|
|
608
613
|
if (shadow) data.shadow = shadow
|
|
609
614
|
|
|
615
|
+
const isHasValidText = data.content && hasValidText(data.content)
|
|
616
|
+
|
|
610
617
|
if (custShapType && type !== 'diagram') {
|
|
611
618
|
const ext = getTextByPathList(slideXfrmNode, ['a:ext', 'attrs'])
|
|
612
619
|
const w = parseInt(ext['cx']) * RATIO_EMUs_Points
|
|
613
620
|
const h = parseInt(ext['cy']) * RATIO_EMUs_Points
|
|
614
621
|
const d = getCustomShapePath(custShapType, w, h)
|
|
615
|
-
if (
|
|
622
|
+
if (!isHasValidText) data.content = ''
|
|
616
623
|
|
|
617
624
|
return {
|
|
618
625
|
...data,
|
|
@@ -621,11 +628,19 @@ async function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type,
|
|
|
621
628
|
path: d,
|
|
622
629
|
}
|
|
623
630
|
}
|
|
624
|
-
if (shapType && (type === 'obj' || !type)) {
|
|
625
|
-
if (
|
|
631
|
+
if (shapType && (type === 'obj' || !type || shapType !== 'rect')) {
|
|
632
|
+
if (!isHasValidText) data.content = ''
|
|
633
|
+
return {
|
|
634
|
+
...data,
|
|
635
|
+
type: 'shape',
|
|
636
|
+
shapType,
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
if (shapType && !isHasValidText && (fill || borderWidth)) {
|
|
626
640
|
return {
|
|
627
641
|
...data,
|
|
628
642
|
type: 'shape',
|
|
643
|
+
content: '',
|
|
629
644
|
shapType,
|
|
630
645
|
}
|
|
631
646
|
}
|
|
@@ -735,6 +750,20 @@ async function processPicNode(node, warpObj, source) {
|
|
|
735
750
|
order,
|
|
736
751
|
}
|
|
737
752
|
}
|
|
753
|
+
|
|
754
|
+
let rect
|
|
755
|
+
const srcRectAttrs = getTextByPathList(node, ['p:blipFill', 'a:srcRect', 'attrs'])
|
|
756
|
+
if (srcRectAttrs && (srcRectAttrs.t || srcRectAttrs.b || srcRectAttrs.l || srcRectAttrs.r)) {
|
|
757
|
+
rect = {}
|
|
758
|
+
if (srcRectAttrs.t) rect.t = srcRectAttrs.t / 1000
|
|
759
|
+
if (srcRectAttrs.b) rect.b = srcRectAttrs.b / 1000
|
|
760
|
+
if (srcRectAttrs.l) rect.l = srcRectAttrs.l / 1000
|
|
761
|
+
if (srcRectAttrs.r) rect.r = srcRectAttrs.r / 1000
|
|
762
|
+
}
|
|
763
|
+
const geom = getTextByPathList(node, ['p:spPr', 'a:prstGeom', 'attrs', 'prst']) || 'rect'
|
|
764
|
+
|
|
765
|
+
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, undefined, warpObj)
|
|
766
|
+
|
|
738
767
|
return {
|
|
739
768
|
type: 'image',
|
|
740
769
|
top,
|
|
@@ -746,6 +775,12 @@ async function processPicNode(node, warpObj, source) {
|
|
|
746
775
|
isFlipV,
|
|
747
776
|
isFlipH,
|
|
748
777
|
order,
|
|
778
|
+
rect,
|
|
779
|
+
geom,
|
|
780
|
+
borderColor,
|
|
781
|
+
borderWidth,
|
|
782
|
+
borderType,
|
|
783
|
+
borderStrokeDasharray: strokeDasharray,
|
|
749
784
|
}
|
|
750
785
|
}
|
|
751
786
|
|
|
@@ -1015,7 +1050,7 @@ async function genDiagram(node, warpObj) {
|
|
|
1015
1050
|
const elements = []
|
|
1016
1051
|
if (dgmDrwSpArray) {
|
|
1017
1052
|
for (const item of dgmDrwSpArray) {
|
|
1018
|
-
const el = await processSpNode(item, warpObj, 'diagramBg')
|
|
1053
|
+
const el = await processSpNode(item, node, warpObj, 'diagramBg')
|
|
1019
1054
|
if (el) elements.push(el)
|
|
1020
1055
|
}
|
|
1021
1056
|
}
|
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)
|
package/src/table.js
CHANGED
|
@@ -55,7 +55,7 @@ export async function getTableCellParams(tcNode, thisTblStyle, cellSource, warpO
|
|
|
55
55
|
const getCelFill = getTextByPathList(tcNode, ['a:tcPr'])
|
|
56
56
|
if (getCelFill) {
|
|
57
57
|
const cellObj = { 'p:spPr': getCelFill }
|
|
58
|
-
const fill = await getShapeFill(cellObj, undefined, warpObj)
|
|
58
|
+
const fill = await getShapeFill(cellObj, undefined, false, warpObj, 'slide')
|
|
59
59
|
|
|
60
60
|
if (fill && fill.type === 'color' && fill.value) {
|
|
61
61
|
fillColor = fill.value
|