pptxtojson 2.0.0 → 2.0.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 +1 -1
- package/dist/index.cjs.map +1 -1
- 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/diagram.js +2 -1
- package/src/pptxtojson.js +2 -2
- package/src/readXmlFile.js +6 -1
- package/src/shapePath.js +27 -21
- package/src/text.js +8 -2
package/package.json
CHANGED
package/src/diagram.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readXmlFile } from './readXmlFile'
|
|
2
|
+
import { getTextNodeValue } from './text'
|
|
2
3
|
import { getTextByPathList } from './utils'
|
|
3
4
|
|
|
4
5
|
export async function loadDiagramFile(warpObj, filename, transformDrawing = false) {
|
|
@@ -112,7 +113,7 @@ export function getSmartArtTextData(dataContent) {
|
|
|
112
113
|
if (!Array.isArray(runs)) runs = [runs]
|
|
113
114
|
|
|
114
115
|
runs.forEach(r => {
|
|
115
|
-
const t = getTextByPathList(r, ['a:t'])
|
|
116
|
+
const t = getTextNodeValue(getTextByPathList(r, ['a:t']))
|
|
116
117
|
if (t && typeof t === 'string') nodeText += t
|
|
117
118
|
})
|
|
118
119
|
}
|
package/src/pptxtojson.js
CHANGED
|
@@ -5,7 +5,7 @@ import { getSlideBackgroundFill, getShapeFill, getSolidFill, getPicFill, getPicF
|
|
|
5
5
|
import { getChartInfo } from './chart'
|
|
6
6
|
import { getVerticalAlign, getTextAutoFit } from './align'
|
|
7
7
|
import { getPosition, getSize } from './position'
|
|
8
|
-
import { genTextBody } from './text'
|
|
8
|
+
import { genTextBody, getTextNodeValue } from './text'
|
|
9
9
|
import { getCustomShapePath, identifyShape } from './shape'
|
|
10
10
|
import { extractFileExtension, getTextByPathList, angleToDegrees, isVideoLink, escapeHtml, hasValidText, numberToFixed } from './utils'
|
|
11
11
|
import { getShadow } from './shadow'
|
|
@@ -392,7 +392,7 @@ function getNote(noteContent) {
|
|
|
392
392
|
if (rNodes) {
|
|
393
393
|
if (rNodes.constructor !== Array) rNodes = [rNodes]
|
|
394
394
|
for (const r of rNodes) {
|
|
395
|
-
const t = getTextByPathList(r, ['a:t'])
|
|
395
|
+
const t = getTextNodeValue(getTextByPathList(r, ['a:t']))
|
|
396
396
|
if (t && typeof t === 'string') text += t
|
|
397
397
|
}
|
|
398
398
|
}
|
package/src/readXmlFile.js
CHANGED
|
@@ -2,6 +2,10 @@ import * as txml from 'txml/dist/txml.mjs'
|
|
|
2
2
|
|
|
3
3
|
let cust_attr_order = 0
|
|
4
4
|
|
|
5
|
+
function isWhitespaceTextNode(node) {
|
|
6
|
+
return typeof node === 'string' && node.trim() === ''
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
export function simplifyLostLess(children, parentAttributes = {}) {
|
|
6
10
|
const out = {}
|
|
7
11
|
if (!children.length) return out
|
|
@@ -13,6 +17,7 @@ export function simplifyLostLess(children, parentAttributes = {}) {
|
|
|
13
17
|
} : children[0]
|
|
14
18
|
}
|
|
15
19
|
for (const child of children) {
|
|
20
|
+
if (isWhitespaceTextNode(child)) continue
|
|
16
21
|
if (typeof child !== 'object') return
|
|
17
22
|
if (child.tagName === '?xml') continue
|
|
18
23
|
|
|
@@ -39,7 +44,7 @@ export function simplifyLostLess(children, parentAttributes = {}) {
|
|
|
39
44
|
export async function readXmlFile(zip, filename) {
|
|
40
45
|
try {
|
|
41
46
|
const data = await zip.file(filename).async('string')
|
|
42
|
-
return simplifyLostLess(txml.parse(data))
|
|
47
|
+
return simplifyLostLess(txml.parse(data, { keepWhitespace: true }))
|
|
43
48
|
}
|
|
44
49
|
catch {
|
|
45
50
|
return null
|
package/src/shapePath.js
CHANGED
|
@@ -4,28 +4,33 @@ import { RATIO_EMUs_Points } from './constants'
|
|
|
4
4
|
import { getTextByPathList } from './utils'
|
|
5
5
|
|
|
6
6
|
function shapePie(H, w, adj1, adj2, isClose) {
|
|
7
|
-
const pieVal =
|
|
8
|
-
const piAngle =
|
|
7
|
+
const pieVal = parseFloat(adj2)
|
|
8
|
+
const piAngle = parseFloat(adj1)
|
|
9
9
|
const size = parseInt(H)
|
|
10
|
-
const
|
|
10
|
+
const radiusY = size / 2
|
|
11
|
+
const radiusX = w / 2
|
|
12
|
+
const centerX = radiusX
|
|
13
|
+
const centerY = radiusY
|
|
11
14
|
|
|
12
15
|
let value = pieVal - piAngle
|
|
13
16
|
if (value < 0) value = 360 + value
|
|
14
17
|
value = Math.min(Math.max(value, 0), 360)
|
|
15
18
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
19
|
+
const startRadians = piAngle * Math.PI / 180
|
|
20
|
+
const endRadians = (piAngle + value) * Math.PI / 180
|
|
21
|
+
const startX = centerX + Math.cos(startRadians) * radiusX
|
|
22
|
+
const startY = centerY + Math.sin(startRadians) * radiusY
|
|
23
|
+
const endX = centerX + Math.cos(endRadians) * radiusX
|
|
24
|
+
const endY = centerY + Math.sin(endRadians) * radiusY
|
|
18
25
|
|
|
19
26
|
let longArc, d
|
|
20
27
|
if (isClose) {
|
|
21
28
|
longArc = (value <= 180) ? 0 : 1
|
|
22
|
-
d = `M${
|
|
29
|
+
d = `M${centerX},${centerY} L${startX},${startY} A${radiusX},${radiusY} 0 ${longArc},1 ${endX},${endY} z`
|
|
23
30
|
}
|
|
24
31
|
else {
|
|
25
32
|
longArc = (value <= 180) ? 0 : 1
|
|
26
|
-
|
|
27
|
-
const radius2 = w / 2
|
|
28
|
-
d = `M${radius1},0 A${radius2},${radius1} 0 ${longArc},1 ${radius2 + y * radius2},${radius1 - x * radius1}`
|
|
33
|
+
d = `M${startX},${startY} A${radiusX},${radiusY} 0 ${longArc},1 ${endX},${endY}`
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
return d
|
|
@@ -1434,17 +1439,18 @@ export function getShapePath(shapType, w, h, node) {
|
|
|
1434
1439
|
}
|
|
1435
1440
|
|
|
1436
1441
|
if (shapAdjst) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1442
|
+
const shapAdjstAry = Array.isArray(shapAdjst) ? shapAdjst : [shapAdjst]
|
|
1443
|
+
for (const adj of shapAdjstAry) {
|
|
1444
|
+
const name = getTextByPathList(adj, ['attrs', 'name'])
|
|
1445
|
+
const fmla = getTextByPathList(adj, ['attrs', 'fmla'])
|
|
1446
|
+
if (!name || !fmla) continue
|
|
1447
|
+
|
|
1448
|
+
if (name === 'adj1') {
|
|
1449
|
+
adj1 = parseInt(fmla.substring(4)) / 60000
|
|
1450
|
+
}
|
|
1451
|
+
else if (name === 'adj2') {
|
|
1452
|
+
adj2 = parseInt(fmla.substring(4)) / 60000
|
|
1453
|
+
}
|
|
1448
1454
|
}
|
|
1449
1455
|
}
|
|
1450
1456
|
|
|
@@ -4628,4 +4634,4 @@ export function getShapePath(shapType, w, h, node) {
|
|
|
4628
4634
|
}
|
|
4629
4635
|
|
|
4630
4636
|
return pathData
|
|
4631
|
-
}
|
|
4637
|
+
}
|
package/src/text.js
CHANGED
|
@@ -14,6 +14,12 @@ import {
|
|
|
14
14
|
getFontShadow,
|
|
15
15
|
} from './fontStyle'
|
|
16
16
|
|
|
17
|
+
export function getTextNodeValue(node) {
|
|
18
|
+
if (typeof node === 'string') return node
|
|
19
|
+
if (node && typeof node.value === 'string') return node.value
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
export function genTextBody(textBodyNode, spNode, slideLayoutSpNode, slideMasterSpNode, type, warpObj) {
|
|
18
24
|
if (!textBodyNode) return ''
|
|
19
25
|
|
|
@@ -170,8 +176,8 @@ export function getSpanStyleInfo(node, pNode, textBodyNode, pFontStyle, slideLay
|
|
|
170
176
|
const lvlNode = getTextByPathList(pPrNode, ['attrs', 'lvl'])
|
|
171
177
|
if (lvlNode !== undefined) lvl = parseInt(lvlNode) + 1
|
|
172
178
|
|
|
173
|
-
let text = node['a:t']
|
|
174
|
-
if (typeof text !== 'string') text = getTextByPathList(node, ['a:fld', 'a:t'])
|
|
179
|
+
let text = getTextNodeValue(node['a:t'])
|
|
180
|
+
if (typeof text !== 'string') text = getTextNodeValue(getTextByPathList(node, ['a:fld', 'a:t']))
|
|
175
181
|
if (typeof text !== 'string') text = ' '
|
|
176
182
|
|
|
177
183
|
let styleText = ''
|