pptxtojson 1.5.2 → 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/README.md +145 -136
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -0
- 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/favicon.ico +0 -0
- package/index.html +437 -93
- package/package.json +1 -1
- package/src/animation.js +81 -0
- package/src/fill.js +52 -13
- package/src/pptxtojson.js +22 -11
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
|
@@ -13,6 +13,7 @@ import { getTableBorders, getTableCellParams, getTableRowParams } from './table'
|
|
|
13
13
|
import { RATIO_EMUs_Points } from './constants'
|
|
14
14
|
import { findOMath, latexFormart, parseOMath } from './math'
|
|
15
15
|
import { getShapePath } from './shapePath'
|
|
16
|
+
import { parseTransition, findTransitionNode } from './animation'
|
|
16
17
|
|
|
17
18
|
export async function parse(file) {
|
|
18
19
|
const slides = []
|
|
@@ -274,11 +275,18 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
274
275
|
}
|
|
275
276
|
}
|
|
276
277
|
|
|
278
|
+
let transitionNode = findTransitionNode(slideContent, 'p:sld')
|
|
279
|
+
if (!transitionNode) transitionNode = findTransitionNode(slideLayoutContent, 'p:sldLayout')
|
|
280
|
+
if (!transitionNode) transitionNode = findTransitionNode(slideMasterContent, 'p:sldMaster')
|
|
281
|
+
|
|
282
|
+
const transition = parseTransition(transitionNode)
|
|
283
|
+
|
|
277
284
|
return {
|
|
278
285
|
fill,
|
|
279
286
|
elements,
|
|
280
287
|
layoutElements,
|
|
281
288
|
note,
|
|
289
|
+
transition,
|
|
282
290
|
}
|
|
283
291
|
}
|
|
284
292
|
|
|
@@ -391,12 +399,12 @@ function indexNodes(content) {
|
|
|
391
399
|
return { idTable, idxTable, typeTable }
|
|
392
400
|
}
|
|
393
401
|
|
|
394
|
-
async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source) {
|
|
402
|
+
async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source, groupHierarchy = []) {
|
|
395
403
|
let json
|
|
396
404
|
|
|
397
405
|
switch (nodeKey) {
|
|
398
406
|
case 'p:sp': // Shape, Text
|
|
399
|
-
json = await processSpNode(nodeValue, nodes, warpObj, source)
|
|
407
|
+
json = await processSpNode(nodeValue, nodes, warpObj, source, groupHierarchy)
|
|
400
408
|
break
|
|
401
409
|
case 'p:cxnSp': // Shape, Text
|
|
402
410
|
json = await processCxnSpNode(nodeValue, nodes, warpObj, source)
|
|
@@ -408,11 +416,11 @@ async function processNodesInSlide(nodeKey, nodeValue, nodes, warpObj, source) {
|
|
|
408
416
|
json = await processGraphicFrameNode(nodeValue, warpObj, source)
|
|
409
417
|
break
|
|
410
418
|
case 'p:grpSp':
|
|
411
|
-
json = await processGroupSpNode(nodeValue, warpObj, source)
|
|
419
|
+
json = await processGroupSpNode(nodeValue, warpObj, source, groupHierarchy)
|
|
412
420
|
break
|
|
413
421
|
case 'mc:AlternateContent':
|
|
414
422
|
if (getTextByPathList(nodeValue, ['mc:Fallback', 'p:grpSpPr', 'a:xfrm'])) {
|
|
415
|
-
json = await processGroupSpNode(getTextByPathList(nodeValue, ['mc:Fallback']), warpObj, source)
|
|
423
|
+
json = await processGroupSpNode(getTextByPathList(nodeValue, ['mc:Fallback']), warpObj, source, groupHierarchy)
|
|
416
424
|
}
|
|
417
425
|
else if (getTextByPathList(nodeValue, ['mc:Choice'])) {
|
|
418
426
|
json = await processMathNode(nodeValue, warpObj, source)
|
|
@@ -458,7 +466,7 @@ async function processMathNode(node, warpObj, source) {
|
|
|
458
466
|
}
|
|
459
467
|
}
|
|
460
468
|
|
|
461
|
-
async function processGroupSpNode(node, warpObj, source) {
|
|
469
|
+
async function processGroupSpNode(node, warpObj, source, parentGroupHierarchy = []) {
|
|
462
470
|
const order = node['attrs']['order']
|
|
463
471
|
const xfrmNode = getTextByPathList(node, ['p:grpSpPr', 'a:xfrm'])
|
|
464
472
|
if (!xfrmNode) return null
|
|
@@ -481,16 +489,19 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
481
489
|
const ws = cx / chcx
|
|
482
490
|
const hs = cy / chcy
|
|
483
491
|
|
|
492
|
+
// 构建当前组合层级(将当前组合添加到父级层级中)
|
|
493
|
+
const currentGroupHierarchy = [...parentGroupHierarchy, node]
|
|
494
|
+
|
|
484
495
|
const elements = []
|
|
485
496
|
for (const nodeKey in node) {
|
|
486
497
|
if (node[nodeKey].constructor === Array) {
|
|
487
498
|
for (const item of node[nodeKey]) {
|
|
488
|
-
const ret = await processNodesInSlide(nodeKey, item, node, warpObj, source)
|
|
499
|
+
const ret = await processNodesInSlide(nodeKey, item, node, warpObj, source, currentGroupHierarchy)
|
|
489
500
|
if (ret) elements.push(ret)
|
|
490
501
|
}
|
|
491
502
|
}
|
|
492
503
|
else {
|
|
493
|
-
const ret = await processNodesInSlide(nodeKey, node[nodeKey], node, warpObj, source)
|
|
504
|
+
const ret = await processNodesInSlide(nodeKey, node[nodeKey], node, warpObj, source, currentGroupHierarchy)
|
|
494
505
|
if (ret) elements.push(ret)
|
|
495
506
|
}
|
|
496
507
|
}
|
|
@@ -515,7 +526,7 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
515
526
|
}
|
|
516
527
|
}
|
|
517
528
|
|
|
518
|
-
async function processSpNode(node, pNode, warpObj, source) {
|
|
529
|
+
async function processSpNode(node, pNode, warpObj, source, groupHierarchy = []) {
|
|
519
530
|
const name = getTextByPathList(node, ['p:nvSpPr', 'p:cNvPr', 'attrs', 'name'])
|
|
520
531
|
const idx = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'idx'])
|
|
521
532
|
let type = getTextByPathList(node, ['p:nvSpPr', 'p:nvPr', 'p:ph', 'attrs', 'type'])
|
|
@@ -550,7 +561,7 @@ async function processSpNode(node, pNode, warpObj, source) {
|
|
|
550
561
|
else type = 'obj'
|
|
551
562
|
}
|
|
552
563
|
|
|
553
|
-
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)
|
|
554
565
|
}
|
|
555
566
|
|
|
556
567
|
async function processCxnSpNode(node, pNode, warpObj, source) {
|
|
@@ -561,7 +572,7 @@ async function processCxnSpNode(node, pNode, warpObj, source) {
|
|
|
561
572
|
return await genShape(node, pNode, undefined, undefined, name, type, order, warpObj, source)
|
|
562
573
|
}
|
|
563
574
|
|
|
564
|
-
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 = []) {
|
|
565
576
|
const xfrmList = ['p:spPr', 'a:xfrm']
|
|
566
577
|
const slideXfrmNode = getTextByPathList(node, xfrmList)
|
|
567
578
|
const slideLayoutXfrmNode = getTextByPathList(slideLayoutSpNode, xfrmList)
|
|
@@ -590,7 +601,7 @@ async function genShape(node, pNode, slideLayoutSpNode, slideMasterSpNode, name,
|
|
|
590
601
|
if (node['p:txBody']) content = genTextBody(node['p:txBody'], node, slideLayoutSpNode, type, warpObj)
|
|
591
602
|
|
|
592
603
|
const { borderColor, borderWidth, borderType, strokeDasharray } = getBorder(node, type, warpObj)
|
|
593
|
-
const fill = await getShapeFill(node, pNode, undefined, warpObj, source) || ''
|
|
604
|
+
const fill = await getShapeFill(node, pNode, undefined, warpObj, source, groupHierarchy) || ''
|
|
594
605
|
|
|
595
606
|
let shadow
|
|
596
607
|
const outerShdwNode = getTextByPathList(node, ['p:spPr', 'a:effectLst', 'a:outerShdw'])
|