pptxtojson 2.0.0 → 2.0.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/src/align.js DELETED
@@ -1,164 +0,0 @@
1
- import { getTextByPathList } from './utils'
2
-
3
- function getParagraphLevel(node) {
4
- let lvlIdx = 1
5
- const lvlNode = getTextByPathList(node, ['a:pPr', 'attrs', 'lvl'])
6
- if (lvlNode !== undefined) lvlIdx = parseInt(lvlNode) + 1
7
- return lvlIdx
8
- }
9
-
10
- function getAlignFromTextNode(node, lvlStr) {
11
- if (!node) return ''
12
-
13
- let algn = getTextByPathList(node, ['p:txBody', 'a:lstStyle', lvlStr, 'attrs', 'algn'])
14
- if (!algn) algn = getTextByPathList(node, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
15
-
16
- return algn || ''
17
- }
18
-
19
- export function getHorizontalAlign(node, pNode, type, slideLayoutSpNode, slideMasterSpNode, warpObj) {
20
- let algn = getTextByPathList(node, ['a:pPr', 'attrs', 'algn'])
21
-
22
- if (!algn) algn = getTextByPathList(pNode, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
23
-
24
- if (!algn) {
25
- const lvlIdx = getParagraphLevel(node)
26
- const lvlStr = 'a:lvl' + lvlIdx + 'pPr'
27
-
28
- algn = getAlignFromTextNode(slideLayoutSpNode, lvlStr)
29
- if (!algn) algn = getAlignFromTextNode(slideMasterSpNode, lvlStr)
30
-
31
- if (!algn && (type === 'title' || type === 'ctrTitle' || type === 'subTitle')) {
32
- algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:titleStyle', lvlStr, 'attrs', 'algn'])
33
- if (!algn && type === 'subTitle') {
34
- algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:bodyStyle', lvlStr, 'attrs', 'algn'])
35
- }
36
- }
37
- else if (!algn && type === 'body') {
38
- algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:bodyStyle', lvlStr, 'attrs', 'algn'])
39
- }
40
- else if (!algn) {
41
- algn = getTextByPathList(warpObj, ['slideMasterTextStyles', 'p:otherStyle', lvlStr, 'attrs', 'algn'])
42
- }
43
- }
44
-
45
- let align = 'left'
46
- if (algn) {
47
- switch (algn) {
48
- case 'l':
49
- align = 'left'
50
- break
51
- case 'r':
52
- align = 'right'
53
- break
54
- case 'ctr':
55
- align = 'center'
56
- break
57
- case 'just':
58
- align = 'justify'
59
- break
60
- case 'dist':
61
- align = 'justify'
62
- break
63
- default:
64
- align = 'inherit'
65
- }
66
- }
67
- return align
68
- }
69
-
70
- export function getVerticalAlign(node, slideLayoutSpNode, slideMasterSpNode) {
71
- let anchor = getTextByPathList(node, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
72
- if (!anchor) {
73
- anchor = getTextByPathList(slideLayoutSpNode, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
74
- if (!anchor) {
75
- anchor = getTextByPathList(slideMasterSpNode, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
76
- if (!anchor) anchor = 't'
77
- }
78
- }
79
- return (anchor === 'ctr') ? 'mid' : ((anchor === 'b') ? 'down' : 'up')
80
- }
81
-
82
- export function getTextAutoFit(node, slideLayoutSpNode, slideMasterSpNode) {
83
- function checkBodyPr(bodyPr) {
84
- if (!bodyPr) return null
85
-
86
- if (bodyPr['a:noAutofit']) return { result: null }
87
- else if (bodyPr['a:spAutoFit']) return { result: { type: 'shape' } }
88
- else if (bodyPr['a:normAutofit']) {
89
- const fontScale = getTextByPathList(bodyPr['a:normAutofit'], ['attrs', 'fontScale'])
90
- if (fontScale) {
91
- const scalePercent = parseInt(fontScale) / 1000
92
- return {
93
- result: {
94
- type: 'text',
95
- fontScale: scalePercent,
96
- }
97
- }
98
- }
99
- return { result: { type: 'text' } }
100
- }
101
- return null
102
- }
103
-
104
- const nodeCheck = checkBodyPr(getTextByPathList(node, ['p:txBody', 'a:bodyPr']))
105
- if (nodeCheck) return nodeCheck.result
106
-
107
- const layoutCheck = checkBodyPr(getTextByPathList(slideLayoutSpNode, ['p:txBody', 'a:bodyPr']))
108
- if (layoutCheck) return layoutCheck.result
109
-
110
- const masterCheck = checkBodyPr(getTextByPathList(slideMasterSpNode, ['p:txBody', 'a:bodyPr']))
111
- if (masterCheck) return masterCheck.result
112
-
113
- return null
114
- }
115
-
116
- export function getParagraphSpacing(pNode) {
117
- if (!pNode) return null
118
-
119
- const pPrNode = pNode['a:pPr']
120
- if (!pPrNode) return null
121
-
122
- const spacing = {}
123
-
124
- const lnSpcNode = pPrNode['a:lnSpc']
125
- if (lnSpcNode) {
126
- const spcPct = getTextByPathList(lnSpcNode, ['a:spcPct', 'attrs', 'val'])
127
- const spcPts = getTextByPathList(lnSpcNode, ['a:spcPts', 'attrs', 'val'])
128
-
129
- if (spcPct) {
130
- spacing.lineSpacing = parseInt(spcPct) / 1000 / 100
131
- }
132
- else if (spcPts) {
133
- spacing.lineSpacing = parseInt(spcPts) / 100 + 'pt'
134
- }
135
- }
136
-
137
- const spcBefNode = pPrNode['a:spcBef']
138
- if (spcBefNode) {
139
- const spcPct = getTextByPathList(spcBefNode, ['a:spcPct', 'attrs', 'val'])
140
- const spcPts = getTextByPathList(spcBefNode, ['a:spcPts', 'attrs', 'val'])
141
-
142
- if (spcPct) {
143
- spacing.spaceBefore = parseInt(spcPct) / 1000 + 'em'
144
- }
145
- else if (spcPts) {
146
- spacing.spaceBefore = parseInt(spcPts) / 100 + 'pt'
147
- }
148
- }
149
-
150
- const spcAftNode = pPrNode['a:spcAft']
151
- if (spcAftNode) {
152
- const spcPct = getTextByPathList(spcAftNode, ['a:spcPct', 'attrs', 'val'])
153
- const spcPts = getTextByPathList(spcAftNode, ['a:spcPts', 'attrs', 'val'])
154
-
155
- if (spcPct) {
156
- spacing.spaceAfter = parseInt(spcPct) / 1000 + 'em'
157
- }
158
- else if (spcPts) {
159
- spacing.spaceAfter = parseInt(spcPts) / 100 + 'pt'
160
- }
161
- }
162
-
163
- return Object.keys(spacing).length > 0 ? spacing : null
164
- }