pptxtojson 1.6.0 → 1.6.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.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +3 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/fill.js +52 -13
- package/src/pptxtojson.js +14 -11
package/package.json
CHANGED
package/src/fill.js
CHANGED
|
@@ -461,7 +461,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
-
export async function getShapeFill(node, pNode, isSvgMode, warpObj, source) {
|
|
464
|
+
export async function getShapeFill(node, pNode, isSvgMode, warpObj, source, groupHierarchy = []) {
|
|
465
465
|
const fillType = getFillType(getTextByPathList(node, ['p:spPr']))
|
|
466
466
|
let type = 'color'
|
|
467
467
|
let fillValue = ''
|
|
@@ -488,23 +488,16 @@ export async function getShapeFill(node, pNode, isSvgMode, warpObj, source) {
|
|
|
488
488
|
}
|
|
489
489
|
type = 'image'
|
|
490
490
|
}
|
|
491
|
+
else if (fillType === 'GROUP_FILL') {
|
|
492
|
+
return findFillInGroupHierarchy(groupHierarchy, warpObj, source)
|
|
493
|
+
}
|
|
491
494
|
if (!fillValue) {
|
|
492
495
|
const clrName = getTextByPathList(node, ['p:style', 'a:fillRef'])
|
|
493
496
|
fillValue = getSolidFill(clrName, undefined, undefined, warpObj)
|
|
494
497
|
type = 'color'
|
|
495
498
|
}
|
|
496
|
-
if (!fillValue && pNode) {
|
|
497
|
-
|
|
498
|
-
if (grpFill) {
|
|
499
|
-
const grpShpFill = pNode['p:grpSpPr']
|
|
500
|
-
if (grpShpFill) {
|
|
501
|
-
const spShpNode = { 'p:spPr': grpShpFill }
|
|
502
|
-
return getShapeFill(spShpNode, node, isSvgMode, warpObj, source)
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
else if (fillType === 'NO_FILL') {
|
|
506
|
-
return isSvgMode ? 'none' : ''
|
|
507
|
-
}
|
|
499
|
+
if (!fillValue && pNode && fillType === 'NO_FILL') {
|
|
500
|
+
return isSvgMode ? 'none' : ''
|
|
508
501
|
}
|
|
509
502
|
|
|
510
503
|
return {
|
|
@@ -513,6 +506,52 @@ export async function getShapeFill(node, pNode, isSvgMode, warpObj, source) {
|
|
|
513
506
|
}
|
|
514
507
|
}
|
|
515
508
|
|
|
509
|
+
async function findFillInGroupHierarchy(groupHierarchy, warpObj, source) {
|
|
510
|
+
for (const groupNode of groupHierarchy) {
|
|
511
|
+
if (!groupNode || !groupNode['p:grpSpPr']) continue
|
|
512
|
+
|
|
513
|
+
const grpSpPr = groupNode['p:grpSpPr']
|
|
514
|
+
const fillType = getFillType(grpSpPr)
|
|
515
|
+
|
|
516
|
+
if (fillType === 'SOLID_FILL') {
|
|
517
|
+
const shpFill = grpSpPr['a:solidFill']
|
|
518
|
+
const fillValue = getSolidFill(shpFill, undefined, undefined, warpObj)
|
|
519
|
+
if (fillValue) {
|
|
520
|
+
return {
|
|
521
|
+
type: 'color',
|
|
522
|
+
value: fillValue,
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else if (fillType === 'GRADIENT_FILL') {
|
|
527
|
+
const shpFill = grpSpPr['a:gradFill']
|
|
528
|
+
const fillValue = getGradientFill(shpFill, warpObj)
|
|
529
|
+
if (fillValue) {
|
|
530
|
+
return {
|
|
531
|
+
type: 'gradient',
|
|
532
|
+
value: fillValue,
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
else if (fillType === 'PIC_FILL') {
|
|
537
|
+
const shpFill = grpSpPr['a:blipFill']
|
|
538
|
+
const picBase64 = await getPicFill(source, shpFill, warpObj)
|
|
539
|
+
const opacity = getPicFillOpacity(shpFill)
|
|
540
|
+
if (picBase64) {
|
|
541
|
+
return {
|
|
542
|
+
type: 'image',
|
|
543
|
+
value: {
|
|
544
|
+
picBase64,
|
|
545
|
+
opacity,
|
|
546
|
+
},
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return null
|
|
553
|
+
}
|
|
554
|
+
|
|
516
555
|
export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
517
556
|
if (!solidFill) return ''
|
|
518
557
|
|
package/src/pptxtojson.js
CHANGED
|
@@ -399,12 +399,12 @@ function indexNodes(content) {
|
|
|
399
399
|
return { idTable, idxTable, typeTable }
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source) {
|
|
402
|
+
async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source, groupHierarchy = []) {
|
|
403
403
|
let json
|
|
404
404
|
|
|
405
405
|
switch (nodeKey) {
|
|
406
406
|
case 'p:sp': // Shape, Text
|
|
407
|
-
json = await processSpNode(nodeValue, nodes, warpObj, source)
|
|
407
|
+
json = await processSpNode(nodeValue, nodes, warpObj, source, groupHierarchy)
|
|
408
408
|
break
|
|
409
409
|
case 'p:cxnSp': // Shape, Text
|
|
410
410
|
json = await processCxnSpNode(nodeValue, nodes, warpObj, source)
|
|
@@ -416,11 +416,11 @@ async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source) {
|
|
|
416
416
|
json = await processGraphicFrameNode(nodeValue, warpObj, source)
|
|
417
417
|
break
|
|
418
418
|
case 'p:grpSp':
|
|
419
|
-
json = await processGroupSpNode(nodeValue, warpObj, source)
|
|
419
|
+
json = await processGroupSpNode(nodeValue, warpObj, source, groupHierarchy)
|
|
420
420
|
break
|
|
421
421
|
case 'mc:AlternateContent':
|
|
422
422
|
if (getTextByPathList(nodeValue, ['mc:Fallback', 'p:grpSpPr', 'a:xfrm'])) {
|
|
423
|
-
json = await processGroupSpNode(getTextByPathList(nodeValue, ['mc:Fallback']), warpObj, source)
|
|
423
|
+
json = await processGroupSpNode(getTextByPathList(nodeValue, ['mc:Fallback']), warpObj, source, groupHierarchy)
|
|
424
424
|
}
|
|
425
425
|
else if (getTextByPathList(nodeValue, ['mc:Choice'])) {
|
|
426
426
|
json = await processMathNode(nodeValue, warpObj, source)
|
|
@@ -466,7 +466,7 @@ async function processMathNode(node, warpObj, source) {
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
-
async function processGroupSpNode(node, warpObj, source) {
|
|
469
|
+
async function processGroupSpNode(node, warpObj, source, parentGroupHierarchy = []) {
|
|
470
470
|
const order = node['attrs']['order']
|
|
471
471
|
const xfrmNode = getTextByPathList(node, ['p:grpSpPr', 'a:xfrm'])
|
|
472
472
|
if (!xfrmNode) return null
|
|
@@ -489,16 +489,19 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
489
489
|
const ws = cx / chcx
|
|
490
490
|
const hs = cy / chcy
|
|
491
491
|
|
|
492
|
+
// 构建当前组合层级(将当前组合添加到父级层级中)
|
|
493
|
+
const currentGroupHierarchy = [...parentGroupHierarchy, node]
|
|
494
|
+
|
|
492
495
|
const elements = []
|
|
493
496
|
for (const nodeKey in node) {
|
|
494
497
|
if (node[nodeKey].constructor === Array) {
|
|
495
498
|
for (const item of node[nodeKey]) {
|
|
496
|
-
const ret = await processNodesInSlide(nodeKey, item, node, warpObj, source)
|
|
499
|
+
const ret = await processNodesInSlide(nodeKey, item, node, warpObj, source, currentGroupHierarchy)
|
|
497
500
|
if (ret) elements.push(ret)
|
|
498
501
|
}
|
|
499
502
|
}
|
|
500
503
|
else {
|
|
501
|
-
const ret = await processNodesInSlide(nodeKey, node[nodeKey], node, warpObj, source)
|
|
504
|
+
const ret = await processNodesInSlide(nodeKey, node[nodeKey], node, warpObj, source, currentGroupHierarchy)
|
|
502
505
|
if (ret) elements.push(ret)
|
|
503
506
|
}
|
|
504
507
|
}
|
|
@@ -523,7 +526,7 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
523
526
|
}
|
|
524
527
|
}
|
|
525
528
|
|
|
526
|
-
async function processSpNode(node, pNode, warpObj, source) {
|
|
529
|
+
async function processSpNode(node, pNode, warpObj, source, groupHierarchy = []) {
|
|
527
530
|
const name = getTextByPathList(node, ['p:nvSpPr', 'p:cNvPr', 'attrs', 'name'])
|
|
528
531
|
const idx = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'idx'])
|
|
529
532
|
let type = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'type'])
|
|
@@ -558,7 +561,7 @@ async function processSpNode(node, pNode, warpObj, source) {
|
|
|
558
561
|
else type = 'obj'
|
|
559
562
|
}
|
|
560
563
|
|
|
561
|
-
return await genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source)
|
|
564
|
+
return await genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source, groupHierarchy)
|
|
562
565
|
}
|
|
563
566
|
|
|
564
567
|
async function processCxnSpNode(node, pNode, warpObj, source) {
|
|
@@ -569,7 +572,7 @@ async function processCxnSpNode(node, pNode, warpObj, source) {
|
|
|
569
572
|
return await genShape(node, pNode, undefined, undefined, name, type, order, warpObj, source)
|
|
570
573
|
}
|
|
571
574
|
|
|
572
|
-
async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source) {
|
|
575
|
+
async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name, type, order, warpObj, source, groupHierarchy = []) {
|
|
573
576
|
const xfrmList = ['p:spPr', 'a:xfrm']
|
|
574
577
|
const slideXfrmNode = getTextByPathList(node, xfrmList)
|
|
575
578
|
const slideLayoutXfrmNode = getTextByPathList(slideLayoutSpNode, xfrmList)
|
|
@@ -598,7 +601,7 @@ async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name,
|
|
|
598
601
|
if (node['p:txBody']) content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, type, warpObj)
|
|
599
602
|
|
|
600
603
|
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
|
|
601
|
-
const fill = await getShapeFill(node, pNode, undefined, warpObj, source) || ''
|
|
604
|
+
const fill = await getShapeFill(node, pNode, undefined, warpObj, source, groupHierarchy) || ''
|
|
602
605
|
|
|
603
606
|
let shadow
|
|
604
607
|
const outerShdwNode = getTextByPathList(node, ['p:spPr', 'a:effectLst', 'a:outerShdw'])
|