pptxtojson 0.0.13 → 0.1.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/index.html CHANGED
@@ -106,7 +106,10 @@
106
106
 
107
107
  const reader = new FileReader()
108
108
  reader.onload = async e => {
109
- const json = await pptxtojson.parse(e.target.result)
109
+ const json = await pptxtojson.parse(e.target.result, {
110
+ // slideFactor: 75 / 914400,
111
+ // fontsizeFactor: 100 / 96,
112
+ })
110
113
  editor.set(json)
111
114
  console.log(json)
112
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptxtojson",
3
- "version": "0.0.13",
3
+ "version": "0.1.1",
4
4
  "description": "A javascript tool for parsing .pptx file",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
@@ -12,7 +12,7 @@
12
12
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx"
13
13
  },
14
14
  "author": "",
15
- "license": "GPL-3.0",
15
+ "license": "AGPL-3.0",
16
16
  "publishConfig": {
17
17
  "registry": "https://registry.npmjs.com/"
18
18
  },
package/src/align.js ADDED
@@ -0,0 +1,36 @@
1
+ import { getTextByPathList } from './utils'
2
+
3
+ export function getHorizontalAlign(node, slideLayoutSpNode, slideMasterSpNode, type, slideMasterTextStyles) {
4
+ let algn = getTextByPathList(node, ['a:pPr', 'attrs', 'algn'])
5
+
6
+ if (!algn) algn = getTextByPathList(slideLayoutSpNode, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
7
+ if (!algn) algn = getTextByPathList(slideMasterSpNode, ['p:txBody', 'a:p', 'a:pPr', 'attrs', 'algn'])
8
+ if (!algn) {
9
+ switch (type) {
10
+ case 'title':
11
+ case 'subTitle':
12
+ case 'ctrTitle':
13
+ algn = getTextByPathList(slideMasterTextStyles, ['p:titleStyle', 'a:lvl1pPr', 'attrs', 'algn'])
14
+ break
15
+ default:
16
+ algn = getTextByPathList(slideMasterTextStyles, ['p:otherStyle', 'a:lvl1pPr', 'attrs', 'algn'])
17
+ }
18
+ }
19
+ if (!algn) {
20
+ if (type === 'title' || type === 'subTitle' || type === 'ctrTitle') return 'center'
21
+ else if (type === 'sldNum') return 'right'
22
+ }
23
+ return algn === 'ctr' ? 'center' : algn === 'r' ? 'right' : 'left'
24
+ }
25
+
26
+ export function getVerticalAlign(node, slideLayoutSpNode, slideMasterSpNode) {
27
+ let anchor = getTextByPathList(node, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
28
+ if (!anchor) {
29
+ anchor = getTextByPathList(slideLayoutSpNode, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
30
+ if (!anchor) {
31
+ anchor = getTextByPathList(slideMasterSpNode, ['p:txBody', 'a:bodyPr', 'attrs', 'anchor'])
32
+ if (!anchor) anchor = 't'
33
+ }
34
+ }
35
+ return (anchor === 'ctr') ? 'mid' : ((anchor === 'b') ? 'down' : 'up')
36
+ }
package/src/border.js ADDED
@@ -0,0 +1,95 @@
1
+ import tinycolor from 'tinycolor2'
2
+ import { getSchemeColorFromTheme } from './schemeColor'
3
+ import { getTextByPathList } from './utils'
4
+
5
+ export function getBorder(node, elType, warpObj) {
6
+ const lineNode = node['p:spPr']['a:ln']
7
+
8
+ let borderWidth = parseInt(getTextByPathList(lineNode, ['attrs', 'w'])) / 12700
9
+ if (isNaN(borderWidth)) {
10
+ if (lineNode) borderWidth = 0
11
+ else if (elType === 'text') borderWidth = 0
12
+ else borderWidth = 1
13
+ }
14
+
15
+ let borderColor = getTextByPathList(lineNode, ['a:solidFill', 'a:srgbClr', 'attrs', 'val'])
16
+ if (!borderColor) {
17
+ const schemeClrNode = getTextByPathList(lineNode, ['a:solidFill', 'a:schemeClr'])
18
+ const schemeClr = 'a:' + getTextByPathList(schemeClrNode, ['attrs', 'val'])
19
+ borderColor = getSchemeColorFromTheme(schemeClr, warpObj)
20
+ }
21
+
22
+ if (!borderColor) {
23
+ const schemeClrNode = getTextByPathList(node, ['p:style', 'a:lnRef', 'a:schemeClr'])
24
+ const schemeClr = 'a:' + getTextByPathList(schemeClrNode, ['attrs', 'val'])
25
+ borderColor = getSchemeColorFromTheme(schemeClr, warpObj)
26
+
27
+ if (borderColor) {
28
+ let shade = getTextByPathList(schemeClrNode, ['a:shade', 'attrs', 'val'])
29
+
30
+ if (shade) {
31
+ shade = parseInt(shade) / 100000
32
+
33
+ const color = tinycolor('#' + borderColor).toHsl()
34
+ borderColor = tinycolor({ h: color.h, s: color.s, l: color.l * shade, a: color.a }).toHex()
35
+ }
36
+ }
37
+ }
38
+
39
+ if (!borderColor) borderColor = '#000'
40
+ else borderColor = `#${borderColor}`
41
+
42
+ const type = getTextByPathList(lineNode, ['a:prstDash', 'attrs', 'val'])
43
+ let borderType = 'solid'
44
+ let strokeDasharray = '0'
45
+ switch (type) {
46
+ case 'solid':
47
+ borderType = 'solid'
48
+ strokeDasharray = '0'
49
+ break
50
+ case 'dash':
51
+ borderType = 'dashed'
52
+ strokeDasharray = '5'
53
+ break
54
+ case 'dashDot':
55
+ borderType = 'dashed'
56
+ strokeDasharray = '5, 5, 1, 5'
57
+ break
58
+ case 'dot':
59
+ borderType = 'dotted'
60
+ strokeDasharray = '1, 5'
61
+ break
62
+ case 'lgDash':
63
+ borderType = 'dashed'
64
+ strokeDasharray = '10, 5'
65
+ break
66
+ case 'lgDashDotDot':
67
+ borderType = 'dotted'
68
+ strokeDasharray = '10, 5, 1, 5, 1, 5'
69
+ break
70
+ case 'sysDash':
71
+ borderType = 'dashed'
72
+ strokeDasharray = '5, 2'
73
+ break
74
+ case 'sysDashDot':
75
+ borderType = 'dotted'
76
+ strokeDasharray = '5, 2, 1, 5'
77
+ break
78
+ case 'sysDashDotDot':
79
+ borderType = 'dotted'
80
+ strokeDasharray = '5, 2, 1, 5, 1, 5'
81
+ break
82
+ case 'sysDot':
83
+ borderType = 'dotted'
84
+ strokeDasharray = '2, 5'
85
+ break
86
+ default:
87
+ }
88
+
89
+ return {
90
+ borderColor,
91
+ borderWidth,
92
+ borderType,
93
+ strokeDasharray,
94
+ }
95
+ }
package/src/chart.js ADDED
@@ -0,0 +1,173 @@
1
+ import { eachElement, getTextByPathList } from './utils'
2
+
3
+ function extractChartData(serNode) {
4
+ const dataMat = []
5
+ if (!serNode) return dataMat
6
+
7
+ if (serNode['c:xVal']) {
8
+ let dataRow = []
9
+ eachElement(serNode['c:xVal']['c:numRef']['c:numCache']['c:pt'], innerNode => {
10
+ dataRow.push(parseFloat(innerNode['c:v']))
11
+ return ''
12
+ })
13
+ dataMat.push(dataRow)
14
+ dataRow = []
15
+ eachElement(serNode['c:yVal']['c:numRef']['c:numCache']['c:pt'], innerNode => {
16
+ dataRow.push(parseFloat(innerNode['c:v']))
17
+ return ''
18
+ })
19
+ dataMat.push(dataRow)
20
+ }
21
+ else {
22
+ eachElement(serNode, (innerNode, index) => {
23
+ const dataRow = []
24
+ const colName = getTextByPathList(innerNode, ['c:tx', 'c:strRef', 'c:strCache', 'c:pt', 'c:v']) || index
25
+
26
+ const rowNames = {}
27
+ if (getTextByPathList(innerNode, ['c:cat', 'c:strRef', 'c:strCache', 'c:pt'])) {
28
+ eachElement(innerNode['c:cat']['c:strRef']['c:strCache']['c:pt'], innerNode => {
29
+ rowNames[innerNode['attrs']['idx']] = innerNode['c:v']
30
+ return ''
31
+ })
32
+ }
33
+ else if (getTextByPathList(innerNode, ['c:cat', 'c:numRef', 'c:numCache', 'c:pt'])) {
34
+ eachElement(innerNode['c:cat']['c:numRef']['c:numCache']['c:pt'], innerNode => {
35
+ rowNames[innerNode['attrs']['idx']] = innerNode['c:v']
36
+ return ''
37
+ })
38
+ }
39
+
40
+ if (getTextByPathList(innerNode, ['c:val', 'c:numRef', 'c:numCache', 'c:pt'])) {
41
+ eachElement(innerNode['c:val']['c:numRef']['c:numCache']['c:pt'], innerNode => {
42
+ dataRow.push({
43
+ x: innerNode['attrs']['idx'],
44
+ y: parseFloat(innerNode['c:v']),
45
+ })
46
+ return ''
47
+ })
48
+ }
49
+
50
+ dataMat.push({
51
+ key: colName,
52
+ values: dataRow,
53
+ xlabels: rowNames,
54
+ })
55
+ return ''
56
+ })
57
+ }
58
+
59
+ return dataMat
60
+ }
61
+
62
+ export function getChartInfo(plotArea) {
63
+ let chart = null
64
+ for (const key in plotArea) {
65
+ switch (key) {
66
+ case 'c:lineChart':
67
+ chart = {
68
+ type: 'lineChart',
69
+ data: extractChartData(plotArea[key]['c:ser']),
70
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
71
+ marker: plotArea[key]['c:marker'] ? true : false,
72
+ }
73
+ break
74
+ case 'c:line3DChart':
75
+ chart = {
76
+ type: 'line3DChart',
77
+ data: extractChartData(plotArea[key]['c:ser']),
78
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
79
+ }
80
+ break
81
+ case 'c:barChart':
82
+ chart = {
83
+ type: 'barChart',
84
+ data: extractChartData(plotArea[key]['c:ser']),
85
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
86
+ barDir: getTextByPathList(plotArea[key], ['c:barDir', 'attrs', 'val']),
87
+ }
88
+ break
89
+ case 'c:bar3DChart':
90
+ chart = {
91
+ type: 'bar3DChart',
92
+ data: extractChartData(plotArea[key]['c:ser']),
93
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
94
+ barDir: getTextByPathList(plotArea[key], ['c:barDir', 'attrs', 'val']),
95
+ }
96
+ break
97
+ case 'c:pieChart':
98
+ chart = {
99
+ type: 'pieChart',
100
+ data: extractChartData(plotArea[key]['c:ser']),
101
+ }
102
+ break
103
+ case 'c:pie3DChart':
104
+ chart = {
105
+ type: 'pie3DChart',
106
+ data: extractChartData(plotArea[key]['c:ser']),
107
+ }
108
+ break
109
+ case 'c:doughnutChart':
110
+ chart = {
111
+ type: 'doughnutChart',
112
+ data: extractChartData(plotArea[key]['c:ser']),
113
+ holeSize: getTextByPathList(plotArea[key], ['c:holeSize', 'attrs', 'val']),
114
+ }
115
+ break
116
+ case 'c:areaChart':
117
+ chart = {
118
+ type: 'areaChart',
119
+ data: extractChartData(plotArea[key]['c:ser']),
120
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
121
+ }
122
+ break
123
+ case 'c:area3DChart':
124
+ chart = {
125
+ type: 'area3DChart',
126
+ data: extractChartData(plotArea[key]['c:ser']),
127
+ grouping: getTextByPathList(plotArea[key], ['c:grouping', 'attrs', 'val']),
128
+ }
129
+ break
130
+ case 'c:scatterChart':
131
+ chart = {
132
+ type: 'scatterChart',
133
+ data: extractChartData(plotArea[key]['c:ser']),
134
+ style: getTextByPathList(plotArea[key], ['c:scatterStyle', 'attrs', 'val']),
135
+ }
136
+ break
137
+ case 'c:bubbleChart':
138
+ chart = {
139
+ type: 'bubbleChart',
140
+ data: extractChartData(plotArea[key]['c:ser']),
141
+ }
142
+ break
143
+ case 'c:radarChart':
144
+ chart = {
145
+ type: 'radarChart',
146
+ data: extractChartData(plotArea[key]['c:ser']),
147
+ style: getTextByPathList(plotArea[key], ['c:radarStyle', 'attrs', 'val']),
148
+ }
149
+ break
150
+ case 'c:surfaceChart':
151
+ chart = {
152
+ type: 'surfaceChart',
153
+ data: extractChartData(plotArea[key]['c:ser']),
154
+ }
155
+ break
156
+ case 'c:surface3DChart':
157
+ chart = {
158
+ type: 'surface3DChart',
159
+ data: extractChartData(plotArea[key]['c:ser']),
160
+ }
161
+ break
162
+ case 'c:stockChart':
163
+ chart = {
164
+ type: 'stockChart',
165
+ data: extractChartData(plotArea[key]['c:ser']),
166
+ }
167
+ break
168
+ default:
169
+ }
170
+ }
171
+
172
+ return chart
173
+ }
package/src/color.js ADDED
@@ -0,0 +1,168 @@
1
+ import tinycolor from 'tinycolor2'
2
+
3
+ export function hueToRgb(t1, t2, hue) {
4
+ if (hue < 0) hue += 6
5
+ if (hue >= 6) hue -= 6
6
+ if (hue < 1) return (t2 - t1) * hue + t1
7
+ else if (hue < 3) return t2
8
+ else if (hue < 4) return (t2 - t1) * (4 - hue) + t1
9
+ return t1
10
+ }
11
+
12
+ export function hslToRgb(hue, sat, light) {
13
+ let t2
14
+ hue = hue / 60
15
+ if (light <= 0.5) {
16
+ t2 = light * (sat + 1)
17
+ }
18
+ else {
19
+ t2 = light + sat - (light * sat)
20
+ }
21
+ const t1 = light * 2 - t2
22
+ const r = hueToRgb(t1, t2, hue + 2) * 255
23
+ const g = hueToRgb(t1, t2, hue) * 255
24
+ const b = hueToRgb(t1, t2, hue - 2) * 255
25
+ return { r, g, b }
26
+ }
27
+
28
+ export function applyShade(rgbStr, shadeValue, isAlpha) {
29
+ const color = tinycolor(rgbStr).toHsl()
30
+ if (shadeValue >= 1) shadeValue = 1
31
+ const cacl_l = Math.min(color.l * shadeValue, 1)
32
+ if (isAlpha) {
33
+ return tinycolor({
34
+ h: color.h,
35
+ s: color.s,
36
+ l: cacl_l,
37
+ a: color.a
38
+ }).toHex8()
39
+ }
40
+
41
+ return tinycolor({
42
+ h: color.h,
43
+ s: color.s,
44
+ l: cacl_l,
45
+ a: color.a,
46
+ }).toHex()
47
+ }
48
+
49
+ export function applyTint(rgbStr, tintValue, isAlpha) {
50
+ const color = tinycolor(rgbStr).toHsl()
51
+ if (tintValue >= 1) tintValue = 1
52
+ const cacl_l = color.l * tintValue + (1 - tintValue)
53
+ if (isAlpha) {
54
+ return tinycolor({
55
+ h: color.h,
56
+ s: color.s,
57
+ l: cacl_l,
58
+ a: color.a
59
+ }).toHex8()
60
+ }
61
+
62
+ return tinycolor({
63
+ h: color.h,
64
+ s: color.s,
65
+ l: cacl_l,
66
+ a: color.a
67
+ }).toHex()
68
+ }
69
+
70
+ export function applyLumOff(rgbStr, offset, isAlpha) {
71
+ const color = tinycolor(rgbStr).toHsl()
72
+ const lum = offset + color.l
73
+ if (lum >= 1) {
74
+ if (isAlpha) {
75
+ return tinycolor({
76
+ h: color.h,
77
+ s: color.s,
78
+ l: 1,
79
+ a: color.a
80
+ }).toHex8()
81
+ }
82
+
83
+ return tinycolor({
84
+ h: color.h,
85
+ s: color.s,
86
+ l: 1,
87
+ a: color.a
88
+ }).toHex()
89
+ }
90
+ if (isAlpha) {
91
+ return tinycolor({
92
+ h: color.h,
93
+ s: color.s,
94
+ l: lum,
95
+ a: color.a
96
+ }).toHex8()
97
+ }
98
+
99
+ return tinycolor({
100
+ h: color.h,
101
+ s: color.s,
102
+ l: lum,
103
+ a: color.a
104
+ }).toHex()
105
+ }
106
+
107
+ export function applyLumMod(rgbStr, multiplier, isAlpha) {
108
+ const color = tinycolor(rgbStr).toHsl()
109
+ let cacl_l = color.l * multiplier
110
+ if (cacl_l >= 1) cacl_l = 1
111
+ if (isAlpha) {
112
+ return tinycolor({
113
+ h: color.h,
114
+ s: color.s,
115
+ l: cacl_l,
116
+ a: color.a
117
+ }).toHex8()
118
+ }
119
+
120
+ return tinycolor({
121
+ h: color.h,
122
+ s: color.s,
123
+ l: cacl_l,
124
+ a: color.a
125
+ }).toHex()
126
+ }
127
+
128
+ export function applyHueMod(rgbStr, multiplier, isAlpha) {
129
+ const color = tinycolor(rgbStr).toHsl()
130
+ let cacl_h = color.h * multiplier
131
+ if (cacl_h >= 360) cacl_h = cacl_h - 360
132
+ if (isAlpha) {
133
+ return tinycolor({
134
+ h: cacl_h,
135
+ s: color.s,
136
+ l: color.l,
137
+ a: color.a
138
+ }).toHex8()
139
+ }
140
+
141
+ return tinycolor({
142
+ h: cacl_h,
143
+ s: color.s,
144
+ l: color.l,
145
+ a: color.a
146
+ }).toHex()
147
+ }
148
+
149
+ export function applySatMod(rgbStr, multiplier, isAlpha) {
150
+ const color = tinycolor(rgbStr).toHsl()
151
+ let cacl_s = color.s * multiplier
152
+ if (cacl_s >= 1) cacl_s = 1
153
+ if (isAlpha) {
154
+ return tinycolor({
155
+ h: color.h,
156
+ s: cacl_s,
157
+ l: color.l,
158
+ a: color.a
159
+ }).toHex8()
160
+ }
161
+
162
+ return tinycolor({
163
+ h: color.h,
164
+ s: cacl_s,
165
+ l: color.l,
166
+ a: color.a
167
+ }).toHex()
168
+ }