pptxtojson 0.1.8 → 1.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/README.md +38 -15
- package/dist/index.d.ts +3 -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/index.html +1 -4
- package/package.json +1 -1
- package/src/color.js +9 -0
- package/src/constants.js +3 -0
- package/src/fill.js +21 -22
- package/src/fontStyle.js +4 -4
- package/src/position.js +8 -6
- package/src/pptxtojson.js +143 -79
- package/src/shadow.js +7 -7
- package/src/table.js +126 -0
- package/src/text.js +2 -2
- package/src/utils.js +2 -5
package/index.html
CHANGED
|
@@ -106,10 +106,7 @@
|
|
|
106
106
|
|
|
107
107
|
const reader = new FileReader()
|
|
108
108
|
reader.onload = async e => {
|
|
109
|
-
const json = await pptxtojson.parse(e.target.result
|
|
110
|
-
// slideFactor: 75 / 914400,
|
|
111
|
-
// fontsizeFactor: 100 / 96,
|
|
112
|
-
})
|
|
109
|
+
const json = await pptxtojson.parse(e.target.result)
|
|
113
110
|
editor.set(json)
|
|
114
111
|
console.log(json)
|
|
115
112
|
}
|
package/package.json
CHANGED
package/src/color.js
CHANGED
|
@@ -165,4 +165,13 @@ export function applySatMod(rgbStr, multiplier, isAlpha) {
|
|
|
165
165
|
l: color.l,
|
|
166
166
|
a: color.a
|
|
167
167
|
}).toHex()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getColorName2Hex(name) {
|
|
171
|
+
let hex
|
|
172
|
+
const colorName = ['white', 'AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'black', 'BlanchedAlmond', 'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue', 'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue', 'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGrey', 'DarkGreen', 'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrange', 'DarkOrchid', 'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray', 'DarkSlateGrey', 'DarkTurquoise', 'DarkViolet', 'DeepPink', 'DeepSkyBlue', 'DimGray', 'DimGrey', 'DodgerBlue', 'FireBrick', 'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite', 'Gold', 'GoldenRod', 'Gray', 'Grey', 'Green', 'GreenYellow', 'HoneyDew', 'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral', 'LightCyan', 'LightGoldenRodYellow', 'LightGray', 'LightGrey', 'LightGreen', 'LightPink', 'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSlateGrey', 'LightSteelBlue', 'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'MediumAquaMarine', 'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue', 'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue', 'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive', 'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'PaleGoldenRod', 'PaleGreen', 'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum', 'PowderBlue', 'Purple', 'RebeccaPurple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon', 'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue', 'SlateGray', 'SlateGrey', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen']
|
|
173
|
+
const colorHex = ['ffffff', 'f0f8ff', 'faebd7', '00ffff', '7fffd4', 'f0ffff', 'f5f5dc', 'ffe4c4', '000000', 'ffebcd', '0000ff', '8a2be2', 'a52a2a', 'deb887', '5f9ea0', '7fff00', 'd2691e', 'ff7f50', '6495ed', 'fff8dc', 'dc143c', '00ffff', '00008b', '008b8b', 'b8860b', 'a9a9a9', 'a9a9a9', '006400', 'bdb76b', '8b008b', '556b2f', 'ff8c00', '9932cc', '8b0000', 'e9967a', '8fbc8f', '483d8b', '2f4f4f', '2f4f4f', '00ced1', '9400d3', 'ff1493', '00bfff', '696969', '696969', '1e90ff', 'b22222', 'fffaf0', '228b22', 'ff00ff', 'dcdcdc', 'f8f8ff', 'ffd700', 'daa520', '808080', '808080', '008000', 'adff2f', 'f0fff0', 'ff69b4', 'cd5c5c', '4b0082', 'fffff0', 'f0e68c', 'e6e6fa', 'fff0f5', '7cfc00', 'fffacd', 'add8e6', 'f08080', 'e0ffff', 'fafad2', 'd3d3d3', 'd3d3d3', '90ee90', 'ffb6c1', 'ffa07a', '20b2aa', '87cefa', '778899', '778899', 'b0c4de', 'ffffe0', '00ff00', '32cd32', 'faf0e6', 'ff00ff', '800000', '66cdaa', '0000cd', 'ba55d3', '9370db', '3cb371', '7b68ee', '00fa9a', '48d1cc', 'c71585', '191970', 'f5fffa', 'ffe4e1', 'ffe4b5', 'ffdead', '000080', 'fdf5e6', '808000', '6b8e23', 'ffa500', 'ff4500', 'da70d6', 'eee8aa', '98fb98', 'afeeee', 'db7093', 'ffefd5', 'ffdab9', 'cd853f', 'ffc0cb', 'dda0dd', 'b0e0e6', '800080', '663399', 'ff0000', 'bc8f8f', '4169e1', '8b4513', 'fa8072', 'f4a460', '2e8b57', 'fff5ee', 'a0522d', 'c0c0c0', '87ceeb', '6a5acd', '708090', '708090', 'fffafa', '00ff7f', '4682b4', 'd2b48c', '008080', 'd8bfd8', 'ff6347', '40e0d0', 'ee82ee', 'f5deb3', 'ffffff', 'f5f5f5', 'ffff00', '9acd32']
|
|
174
|
+
const findIndx = colorName.indexOf(name)
|
|
175
|
+
if (findIndx !== -1) hex = colorHex[findIndx]
|
|
176
|
+
return hex
|
|
168
177
|
}
|
package/src/constants.js
ADDED
package/src/fill.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
applyHueMod,
|
|
9
9
|
applySatMod,
|
|
10
10
|
hslToRgb,
|
|
11
|
+
getColorName2Hex,
|
|
11
12
|
} from './color'
|
|
12
13
|
|
|
13
14
|
import {
|
|
@@ -94,7 +95,7 @@ export function getBgGradientFill(bgPr, phClr, slideMasterContent, warpObj) {
|
|
|
94
95
|
|
|
95
96
|
color_ary[i] = {
|
|
96
97
|
pos: pos ? (pos / 1000 + '%') : '',
|
|
97
|
-
color:
|
|
98
|
+
color: lo_color,
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
const lin = grdFill['a:lin']
|
|
@@ -109,7 +110,9 @@ export function getBgGradientFill(bgPr, phClr, slideMasterContent, warpObj) {
|
|
|
109
110
|
colors: color_ary.sort((a, b) => parseInt(a.pos) - parseInt(b.pos)),
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
else if (phClr)
|
|
113
|
+
else if (phClr) {
|
|
114
|
+
return phClr.indexOf('#') === -1 ? `#${phClr}` : phClr
|
|
115
|
+
}
|
|
113
116
|
return null
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -138,7 +141,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
138
141
|
else clrMapOvr = getTextByPathList(slideMasterContent, ['p:sldMaster', 'p:clrMap', 'attrs'])
|
|
139
142
|
}
|
|
140
143
|
const sldBgClr = getSolidFill(sldFill, clrMapOvr, undefined, warpObj)
|
|
141
|
-
background =
|
|
144
|
+
background = sldBgClr
|
|
142
145
|
}
|
|
143
146
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
144
147
|
const gradientFill = getBgGradientFill(bgPr, undefined, slideMasterContent, warpObj)
|
|
@@ -207,7 +210,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
207
210
|
if (bgFillTyp === 'SOLID_FILL') {
|
|
208
211
|
const sldFill = bgFillLstIdx['a:solidFill']
|
|
209
212
|
const sldBgClr = getSolidFill(sldFill, clrMapOvr, undefined, warpObj)
|
|
210
|
-
background =
|
|
213
|
+
background = sldBgClr
|
|
211
214
|
}
|
|
212
215
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
213
216
|
const gradientFill = getBgGradientFill(bgFillLstIdx, phClr, slideMasterContent, warpObj)
|
|
@@ -235,7 +238,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
235
238
|
if (bgFillTyp === 'SOLID_FILL') {
|
|
236
239
|
const sldFill = bgPr['a:solidFill']
|
|
237
240
|
const sldBgClr = getSolidFill(sldFill, clrMapOvr, undefined, warpObj)
|
|
238
|
-
background =
|
|
241
|
+
background = sldBgClr
|
|
239
242
|
}
|
|
240
243
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
241
244
|
const gradientFill = getBgGradientFill(bgPr, undefined, slideMasterContent, warpObj)
|
|
@@ -296,7 +299,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
296
299
|
if (bgFillTyp === 'SOLID_FILL') {
|
|
297
300
|
const sldFill = bgFillLstIdx['a:solidFill']
|
|
298
301
|
const sldBgClr = getSolidFill(sldFill, clrMapOvr, undefined, warpObj)
|
|
299
|
-
background =
|
|
302
|
+
background = sldBgClr
|
|
300
303
|
}
|
|
301
304
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
302
305
|
const gradientFill = getBgGradientFill(bgFillLstIdx, phClr, slideMasterContent, warpObj)
|
|
@@ -324,7 +327,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
324
327
|
if (bgFillTyp === 'SOLID_FILL') {
|
|
325
328
|
const sldFill = bgPr['a:solidFill']
|
|
326
329
|
const sldBgClr = getSolidFill(sldFill, clrMap, undefined, warpObj)
|
|
327
|
-
background =
|
|
330
|
+
background = sldBgClr
|
|
328
331
|
}
|
|
329
332
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
330
333
|
const gradientFill = getBgGradientFill(bgPr, undefined, slideMasterContent, warpObj)
|
|
@@ -385,7 +388,7 @@ export async function getSlideBackgroundFill(warpObj) {
|
|
|
385
388
|
if (bgFillTyp === 'SOLID_FILL') {
|
|
386
389
|
const sldFill = bgFillLstIdx['a:solidFill']
|
|
387
390
|
const sldBgClr = getSolidFill(sldFill, clrMapOvr, undefined, warpObj)
|
|
388
|
-
background =
|
|
391
|
+
background = sldBgClr
|
|
389
392
|
}
|
|
390
393
|
else if (bgFillTyp === 'GRADIENT_FILL') {
|
|
391
394
|
const gradientFill = getBgGradientFill(bgFillLstIdx, phClr, slideMasterContent, warpObj)
|
|
@@ -451,24 +454,17 @@ export function getShapeFill(node, isSvgMode, warpObj) {
|
|
|
451
454
|
export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
452
455
|
if (!solidFill) return solidFill
|
|
453
456
|
|
|
454
|
-
let color = '
|
|
457
|
+
let color = '#ffffff'
|
|
455
458
|
let clrNode
|
|
456
459
|
|
|
457
460
|
if (solidFill['a:srgbClr']) {
|
|
458
|
-
|
|
461
|
+
clrNode = solidFill['a:srgbClr']
|
|
462
|
+
color = getTextByPathList(clrNode, ['attrs', 'val'])
|
|
459
463
|
}
|
|
460
464
|
else if (solidFill['a:schemeClr']) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
let lumMod = parseInt(getTextByPathList(solidFill, ['a:schemeClr', 'a:lumMod', 'attrs', 'val'])) / 100000
|
|
465
|
-
let lumOff = parseInt(getTextByPathList(solidFill, ['a:schemeClr', 'a:lumOff', 'attrs', 'val'])) / 100000
|
|
466
|
-
if (isNaN(lumMod)) lumMod = 1.0
|
|
467
|
-
if (isNaN(lumOff)) lumOff = 0
|
|
468
|
-
|
|
469
|
-
color = tinycolor(color).toHsl()
|
|
470
|
-
const lum = color.l * lumMod + lumOff
|
|
471
|
-
return tinycolor({ h: color.h, s: color.s, l: lum, a: color.a }).toHex()
|
|
465
|
+
clrNode = solidFill['a:schemeClr']
|
|
466
|
+
const schemeClr = 'a:' + getTextByPathList(clrNode, ['attrs', 'val'])
|
|
467
|
+
color = getSchemeColorFromTheme(schemeClr, warpObj, clrMap, phClr) || '#ffffff'
|
|
472
468
|
}
|
|
473
469
|
else if (solidFill['a:scrgbClr']) {
|
|
474
470
|
clrNode = solidFill['a:scrgbClr']
|
|
@@ -480,7 +476,8 @@ export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
480
476
|
}
|
|
481
477
|
else if (solidFill['a:prstClr']) {
|
|
482
478
|
clrNode = solidFill['a:prstClr']
|
|
483
|
-
|
|
479
|
+
const prstClr = getTextByPathList(clrNode, ['attrs', 'val'])
|
|
480
|
+
color = getColorName2Hex(prstClr)
|
|
484
481
|
}
|
|
485
482
|
else if (solidFill['a:hslClr']) {
|
|
486
483
|
clrNode = solidFill['a:hslClr']
|
|
@@ -531,5 +528,7 @@ export function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
531
528
|
color = applyTint(color, tint, isAlpha)
|
|
532
529
|
}
|
|
533
530
|
|
|
531
|
+
if (color && color.indexOf('#') === -1) color = '#' + color
|
|
532
|
+
|
|
534
533
|
return color
|
|
535
534
|
}
|
package/src/fontStyle.js
CHANGED
|
@@ -26,7 +26,7 @@ export function getFontColor(node) {
|
|
|
26
26
|
return color ? `#${color}` : ''
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles
|
|
29
|
+
export function getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles) {
|
|
30
30
|
let fontSize
|
|
31
31
|
|
|
32
32
|
if (getTextByPathList(node, ['a:rPr', 'attrs', 'sz'])) fontSize = getTextByPathList(node, ['a:rPr', 'attrs', 'sz']) / 100
|
|
@@ -58,7 +58,7 @@ export function getFontSize(node, slideLayoutSpNode, type, slideMasterTextStyles
|
|
|
58
58
|
|
|
59
59
|
fontSize = (isNaN(fontSize) || !fontSize) ? 18 : fontSize
|
|
60
60
|
|
|
61
|
-
return
|
|
61
|
+
return fontSize + 'pt'
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function getFontBold(node) {
|
|
@@ -77,9 +77,9 @@ export function getFontDecorationLine(node) {
|
|
|
77
77
|
return getTextByPathList(node, ['a:rPr', 'attrs', 'strike']) === 'sngStrike' ? 'line-through' : ''
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
export function getFontSpace(node
|
|
80
|
+
export function getFontSpace(node) {
|
|
81
81
|
const spc = getTextByPathList(node, ['a:rPr', 'attrs', 'spc'])
|
|
82
|
-
return spc ? (parseInt(spc) / 100
|
|
82
|
+
return spc ? (parseInt(spc) / 100 + 'pt') : ''
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export function getFontSubscript(node) {
|
package/src/position.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { RATIO_EMUs_Points } from './constants'
|
|
2
|
+
|
|
3
|
+
export function getPosition(slideSpNode, slideLayoutSpNode, slideMasterSpNode) {
|
|
2
4
|
let off
|
|
3
5
|
|
|
4
6
|
if (slideSpNode) off = slideSpNode['a:off']['attrs']
|
|
@@ -8,12 +10,12 @@ export function getPosition(slideSpNode, slideLayoutSpNode, slideMasterSpNode, f
|
|
|
8
10
|
if (!off) return { top: 0, left: 0 }
|
|
9
11
|
|
|
10
12
|
return {
|
|
11
|
-
top:
|
|
12
|
-
left:
|
|
13
|
+
top: parseInt(off['y']) * RATIO_EMUs_Points,
|
|
14
|
+
left: parseInt(off['x']) * RATIO_EMUs_Points,
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export function getSize(slideSpNode, slideLayoutSpNode, slideMasterSpNode
|
|
18
|
+
export function getSize(slideSpNode, slideLayoutSpNode, slideMasterSpNode) {
|
|
17
19
|
let ext
|
|
18
20
|
|
|
19
21
|
if (slideSpNode) ext = slideSpNode['a:ext']['attrs']
|
|
@@ -23,7 +25,7 @@ export function getSize(slideSpNode, slideLayoutSpNode, slideMasterSpNode, facto
|
|
|
23
25
|
if (!ext) return { width: 0, height: 0 }
|
|
24
26
|
|
|
25
27
|
return {
|
|
26
|
-
width:
|
|
27
|
-
height:
|
|
28
|
+
width: parseInt(ext['cx']) * RATIO_EMUs_Points,
|
|
29
|
+
height: parseInt(ext['cy']) * RATIO_EMUs_Points,
|
|
28
30
|
}
|
|
29
31
|
}
|
package/src/pptxtojson.js
CHANGED
|
@@ -9,25 +9,20 @@ import { genTextBody } from './text'
|
|
|
9
9
|
import { getCustomShapePath } from './shape'
|
|
10
10
|
import { extractFileExtension, base64ArrayBuffer, getTextByPathList, angleToDegrees, getMimeType, isVideoLink, escapeHtml } from './utils'
|
|
11
11
|
import { getShadow } from './shadow'
|
|
12
|
+
import { getTableCellParams, getTableRowParams } from './table'
|
|
13
|
+
import { RATIO_EMUs_Points } from './constants'
|
|
12
14
|
|
|
13
|
-
export async function parse(file
|
|
14
|
-
const defaultOptions = {
|
|
15
|
-
slideFactor: 96 / 914400,
|
|
16
|
-
fontsizeFactor: 100 / 75,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
options = { ...defaultOptions, ...options }
|
|
20
|
-
|
|
15
|
+
export async function parse(file) {
|
|
21
16
|
const slides = []
|
|
22
17
|
|
|
23
18
|
const zip = await JSZip.loadAsync(file)
|
|
24
19
|
|
|
25
20
|
const filesInfo = await getContentTypes(zip)
|
|
26
|
-
const { width, height, defaultTextStyle } = await getSlideInfo(zip
|
|
21
|
+
const { width, height, defaultTextStyle } = await getSlideInfo(zip)
|
|
27
22
|
const themeContent = await loadTheme(zip)
|
|
28
23
|
|
|
29
24
|
for (const filename of filesInfo.slides) {
|
|
30
|
-
const singleSlide = await processSingleSlide(zip, filename, themeContent, defaultTextStyle
|
|
25
|
+
const singleSlide = await processSingleSlide(zip, filename, themeContent, defaultTextStyle)
|
|
31
26
|
slides.push(singleSlide)
|
|
32
27
|
}
|
|
33
28
|
|
|
@@ -72,13 +67,13 @@ async function getContentTypes(zip) {
|
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
async function getSlideInfo(zip
|
|
70
|
+
async function getSlideInfo(zip) {
|
|
76
71
|
const content = await readXmlFile(zip, 'ppt/presentation.xml')
|
|
77
72
|
const sldSzAttrs = content['p:presentation']['p:sldSz']['attrs']
|
|
78
73
|
const defaultTextStyle = content['p:presentation']['p:defaultTextStyle']
|
|
79
74
|
return {
|
|
80
|
-
width: parseInt(sldSzAttrs['cx']) *
|
|
81
|
-
height: parseInt(sldSzAttrs['cy']) *
|
|
75
|
+
width: parseInt(sldSzAttrs['cx']) * RATIO_EMUs_Points,
|
|
76
|
+
height: parseInt(sldSzAttrs['cy']) * RATIO_EMUs_Points,
|
|
82
77
|
defaultTextStyle,
|
|
83
78
|
}
|
|
84
79
|
}
|
|
@@ -104,7 +99,7 @@ async function loadTheme(zip) {
|
|
|
104
99
|
return await readXmlFile(zip, 'ppt/' + themeURI)
|
|
105
100
|
}
|
|
106
101
|
|
|
107
|
-
async function processSingleSlide(zip, sldFileName, themeContent, defaultTextStyle
|
|
102
|
+
async function processSingleSlide(zip, sldFileName, themeContent, defaultTextStyle) {
|
|
108
103
|
const resName = sldFileName.replace('slides/slide', 'slides/_rels/slide') + '.rels'
|
|
109
104
|
const resContent = await readXmlFile(zip, resName)
|
|
110
105
|
let relationshipArray = resContent['Relationships']['Relationship']
|
|
@@ -267,7 +262,6 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
267
262
|
digramFileContent,
|
|
268
263
|
diagramResObj,
|
|
269
264
|
defaultTextStyle,
|
|
270
|
-
options,
|
|
271
265
|
}
|
|
272
266
|
// const bgElements = await getBackground(warpObj)
|
|
273
267
|
const bgColor = await getSlideBackgroundFill(warpObj)
|
|
@@ -408,16 +402,14 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
408
402
|
const xfrmNode = getTextByPathList(node, ['p:grpSpPr', 'a:xfrm'])
|
|
409
403
|
if (!xfrmNode) return null
|
|
410
404
|
|
|
411
|
-
const x = parseInt(xfrmNode['a:off']['attrs']['x']) *
|
|
412
|
-
const y = parseInt(xfrmNode['a:off']['attrs']['y']) *
|
|
413
|
-
|
|
414
|
-
const
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
const chcx = parseInt(xfrmNode['a:chExt']['attrs']['cx']) * warpObj.options.slideFactor
|
|
420
|
-
const chcy = parseInt(xfrmNode['a:chExt']['attrs']['cy']) * warpObj.options.slideFactor
|
|
405
|
+
const x = parseInt(xfrmNode['a:off']['attrs']['x']) * RATIO_EMUs_Points
|
|
406
|
+
const y = parseInt(xfrmNode['a:off']['attrs']['y']) * RATIO_EMUs_Points
|
|
407
|
+
const chx = parseInt(xfrmNode['a:chOff']['attrs']['x']) * RATIO_EMUs_Points
|
|
408
|
+
const chy = parseInt(xfrmNode['a:chOff']['attrs']['y']) * RATIO_EMUs_Points
|
|
409
|
+
const cx = parseInt(xfrmNode['a:ext']['attrs']['cx']) * RATIO_EMUs_Points
|
|
410
|
+
const cy = parseInt(xfrmNode['a:ext']['attrs']['cy']) * RATIO_EMUs_Points
|
|
411
|
+
const chcx = parseInt(xfrmNode['a:chExt']['attrs']['cx']) * RATIO_EMUs_Points
|
|
412
|
+
const chcy = parseInt(xfrmNode['a:chExt']['attrs']['cy']) * RATIO_EMUs_Points
|
|
421
413
|
// children coordinate
|
|
422
414
|
const ws = cx / chcx
|
|
423
415
|
const hs = cy / chcy
|
|
@@ -438,16 +430,16 @@ async function processGroupSpNode(node, warpObj, source) {
|
|
|
438
430
|
|
|
439
431
|
return {
|
|
440
432
|
type: 'group',
|
|
441
|
-
top:
|
|
442
|
-
left:
|
|
443
|
-
width:
|
|
444
|
-
height:
|
|
433
|
+
top: y,
|
|
434
|
+
left: x,
|
|
435
|
+
width: cx,
|
|
436
|
+
height: cy,
|
|
445
437
|
elements: elements.map(element => ({
|
|
446
438
|
...element,
|
|
447
|
-
left:
|
|
448
|
-
top:
|
|
449
|
-
width:
|
|
450
|
-
height:
|
|
439
|
+
left: (element.left - chx) * ws,
|
|
440
|
+
top: (element.top - chy) * hs,
|
|
441
|
+
width: element.width * ws,
|
|
442
|
+
height: element.height * hs,
|
|
451
443
|
}))
|
|
452
444
|
}
|
|
453
445
|
}
|
|
@@ -505,8 +497,8 @@ function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpOb
|
|
|
505
497
|
const shapType = getTextByPathList(node, ['p:spPr', 'a:prstGeom', 'attrs', 'prst'])
|
|
506
498
|
const custShapType = getTextByPathList(node, ['p:spPr', 'a:custGeom'])
|
|
507
499
|
|
|
508
|
-
const { top, left } = getPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode
|
|
509
|
-
const { width, height } = getSize(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode
|
|
500
|
+
const { top, left } = getPosition(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode)
|
|
501
|
+
const { width, height } = getSize(slideXfrmNode, slideLayoutXfrmNode, slideMasterXfrmNode)
|
|
510
502
|
|
|
511
503
|
const isFlipV = getTextByPathList(slideXfrmNode, ['attrs', 'flipV']) === '1'
|
|
512
504
|
const isFlipH = getTextByPathList(slideXfrmNode, ['attrs', 'flipH']) === '1'
|
|
@@ -556,8 +548,8 @@ function genShape(node, slideLayoutSpNode, slideMasterSpNode, name, type, warpOb
|
|
|
556
548
|
|
|
557
549
|
if (custShapType && type !== 'diagram') {
|
|
558
550
|
const ext = getTextByPathList(slideXfrmNode, ['a:ext', 'attrs'])
|
|
559
|
-
const w = parseInt(ext['cx']) *
|
|
560
|
-
const h = parseInt(ext['cy']) *
|
|
551
|
+
const w = parseInt(ext['cx']) * RATIO_EMUs_Points
|
|
552
|
+
const h = parseInt(ext['cy']) * RATIO_EMUs_Points
|
|
561
553
|
const d = getCustomShapePath(custShapType, w, h)
|
|
562
554
|
|
|
563
555
|
return {
|
|
@@ -596,8 +588,8 @@ async function processPicNode(node, warpObj, source) {
|
|
|
596
588
|
const xfrmNode = node['p:spPr']['a:xfrm']
|
|
597
589
|
|
|
598
590
|
const mimeType = getMimeType(imgFileExt)
|
|
599
|
-
const { top, left } = getPosition(xfrmNode, undefined, undefined
|
|
600
|
-
const { width, height } = getSize(xfrmNode, undefined, undefined
|
|
591
|
+
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
592
|
+
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
601
593
|
const src = `data:${mimeType};base64,${base64ArrayBuffer(imgArrayBuffer)}`
|
|
602
594
|
|
|
603
595
|
const isFlipV = getTextByPathList(xfrmNode, ['attrs', 'flipV']) === '1'
|
|
@@ -715,11 +707,26 @@ async function processGraphicFrameNode(node, warpObj, source) {
|
|
|
715
707
|
function genTable(node, warpObj) {
|
|
716
708
|
const tableNode = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl'])
|
|
717
709
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
718
|
-
const { top, left } = getPosition(xfrmNode, undefined, undefined
|
|
719
|
-
const { width, height } = getSize(xfrmNode, undefined, undefined
|
|
710
|
+
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
711
|
+
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
720
712
|
|
|
721
713
|
const getTblPr = getTextByPathList(node, ['a:graphic', 'a:graphicData', 'a:tbl', 'a:tblPr'])
|
|
722
714
|
|
|
715
|
+
const firstRowAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstRow'] : undefined
|
|
716
|
+
const firstColAttr = getTblPr['attrs'] ? getTblPr['attrs']['firstCol'] : undefined
|
|
717
|
+
const lastRowAttr = getTblPr['attrs'] ? getTblPr['attrs']['lastRow'] : undefined
|
|
718
|
+
const lastColAttr = getTblPr['attrs'] ? getTblPr['attrs']['lastCol'] : undefined
|
|
719
|
+
const bandRowAttr = getTblPr['attrs'] ? getTblPr['attrs']['bandRow'] : undefined
|
|
720
|
+
const bandColAttr = getTblPr['attrs'] ? getTblPr['attrs']['bandCol'] : undefined
|
|
721
|
+
const tblStylAttrObj = {
|
|
722
|
+
isFrstRowAttr: (firstRowAttr && firstRowAttr === '1') ? 1 : 0,
|
|
723
|
+
isFrstColAttr: (firstColAttr && firstColAttr === '1') ? 1 : 0,
|
|
724
|
+
isLstRowAttr: (lastRowAttr && lastRowAttr === '1') ? 1 : 0,
|
|
725
|
+
isLstColAttr: (lastColAttr && lastColAttr === '1') ? 1 : 0,
|
|
726
|
+
isBandRowAttr: (bandRowAttr && bandRowAttr === '1') ? 1 : 0,
|
|
727
|
+
isBandColAttr: (bandColAttr && bandColAttr === '1') ? 1 : 0,
|
|
728
|
+
}
|
|
729
|
+
|
|
723
730
|
let thisTblStyle
|
|
724
731
|
const tbleStyleId = getTblPr['a:tableStyleId']
|
|
725
732
|
if (tbleStyleId) {
|
|
@@ -739,57 +746,115 @@ function genTable(node, warpObj) {
|
|
|
739
746
|
}
|
|
740
747
|
}
|
|
741
748
|
}
|
|
749
|
+
if (thisTblStyle) thisTblStyle['tblStylAttrObj'] = tblStylAttrObj
|
|
742
750
|
|
|
743
|
-
let
|
|
751
|
+
let tbl_bgcolor = ''
|
|
744
752
|
let tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:tblBg', 'a:fillRef'])
|
|
745
753
|
if (tbl_bgFillschemeClr) {
|
|
746
|
-
|
|
754
|
+
tbl_bgcolor = getSolidFill(tbl_bgFillschemeClr, undefined, undefined, warpObj)
|
|
747
755
|
}
|
|
748
756
|
if (tbl_bgFillschemeClr === undefined) {
|
|
749
757
|
tbl_bgFillschemeClr = getTextByPathList(thisTblStyle, ['a:wholeTbl', 'a:tcStyle', 'a:fill', 'a:solidFill'])
|
|
750
|
-
|
|
758
|
+
tbl_bgcolor = getSolidFill(tbl_bgFillschemeClr, undefined, undefined, warpObj)
|
|
751
759
|
}
|
|
752
|
-
if (themeColor !== '') themeColor = '#' + themeColor
|
|
753
760
|
|
|
754
|
-
|
|
761
|
+
let trNodes = tableNode['a:tr']
|
|
762
|
+
if (trNodes.constructor !== Array) trNodes = [trNodes]
|
|
755
763
|
|
|
756
764
|
const data = []
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
const vMerge = getTextByPathList(tcNode, ['attrs', 'vMerge'])
|
|
768
|
-
const hMerge = getTextByPathList(tcNode, ['attrs', 'hMerge'])
|
|
769
|
-
|
|
770
|
-
tr.push({ text, rowSpan, colSpan, vMerge, hMerge })
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
const text = genTextBody(tcNodes['a:txBody'], tcNodes, undefined, undefined, warpObj)
|
|
775
|
-
tr.push({ text })
|
|
776
|
-
}
|
|
777
|
-
data.push(tr)
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
const tcNodes = trNodes['a:tc']
|
|
765
|
+
for (let i = 0; i < trNodes.length; i++) {
|
|
766
|
+
const trNode = trNodes[i]
|
|
767
|
+
|
|
768
|
+
const {
|
|
769
|
+
fillColor,
|
|
770
|
+
fontColor,
|
|
771
|
+
fontBold,
|
|
772
|
+
} = getTableRowParams(trNodes, i, tblStylAttrObj, thisTblStyle, warpObj)
|
|
773
|
+
|
|
774
|
+
const tcNodes = trNode['a:tc']
|
|
782
775
|
const tr = []
|
|
783
776
|
|
|
784
777
|
if (tcNodes.constructor === Array) {
|
|
785
|
-
for (
|
|
778
|
+
for (let j = 0; j < tcNodes.length; j++) {
|
|
779
|
+
const tcNode = tcNodes[j]
|
|
780
|
+
let a_sorce
|
|
781
|
+
if (j === 0 && tblStylAttrObj['isFrstColAttr'] === 1) {
|
|
782
|
+
a_sorce = 'a:firstCol'
|
|
783
|
+
if (tblStylAttrObj['isLstRowAttr'] === 1 && i === (trNodes.length - 1) && getTextByPathList(thisTblStyle, ['a:seCell'])) {
|
|
784
|
+
a_sorce = 'a:seCell'
|
|
785
|
+
}
|
|
786
|
+
else if (tblStylAttrObj['isFrstRowAttr'] === 1 && i === 0 &&
|
|
787
|
+
getTextByPathList(thisTblStyle, ['a:neCell'])) {
|
|
788
|
+
a_sorce = 'a:neCell'
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
else if (
|
|
792
|
+
(j > 0 && tblStylAttrObj['isBandColAttr'] === 1) &&
|
|
793
|
+
!(tblStylAttrObj['isFrstColAttr'] === 1 && i === 0) &&
|
|
794
|
+
!(tblStylAttrObj['isLstRowAttr'] === 1 && i === (trNodes.length - 1)) &&
|
|
795
|
+
j !== (tcNodes.length - 1)
|
|
796
|
+
) {
|
|
797
|
+
if ((j % 2) !== 0) {
|
|
798
|
+
let aBandNode = getTextByPathList(thisTblStyle, ['a:band2V'])
|
|
799
|
+
if (aBandNode === undefined) {
|
|
800
|
+
aBandNode = getTextByPathList(thisTblStyle, ['a:band1V'])
|
|
801
|
+
if (aBandNode) a_sorce = 'a:band2V'
|
|
802
|
+
}
|
|
803
|
+
else a_sorce = 'a:band2V'
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
if (j === (tcNodes.length - 1) && tblStylAttrObj['isLstColAttr'] === 1) {
|
|
807
|
+
a_sorce = 'a:lastCol'
|
|
808
|
+
if (tblStylAttrObj['isLstRowAttr'] === 1 && i === (trNodes.length - 1) && getTextByPathList(thisTblStyle, ['a:swCell'])) {
|
|
809
|
+
a_sorce = 'a:swCell'
|
|
810
|
+
}
|
|
811
|
+
else if (tblStylAttrObj['isFrstRowAttr'] === 1 && i === 0 && getTextByPathList(thisTblStyle, ['a:nwCell'])) {
|
|
812
|
+
a_sorce = 'a:nwCell'
|
|
813
|
+
}
|
|
814
|
+
}
|
|
786
815
|
const text = genTextBody(tcNode['a:txBody'], tcNode, undefined, undefined, warpObj)
|
|
787
|
-
|
|
816
|
+
const cell = getTableCellParams(tcNode, thisTblStyle, a_sorce, warpObj)
|
|
817
|
+
const td = { text }
|
|
818
|
+
if (cell.rowSpan) td.rowSpan = cell.rowSpan
|
|
819
|
+
if (cell.colSpan) td.colSpan = cell.colSpan
|
|
820
|
+
if (cell.vMerge) td.vMerge = cell.vMerge
|
|
821
|
+
if (cell.hMerge) td.hMerge = cell.hMerge
|
|
822
|
+
if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
|
|
823
|
+
if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
|
|
824
|
+
if (cell.fillColor || fillColor || tbl_bgcolor) td.fill = cell.fillColor || fillColor || tbl_bgcolor
|
|
825
|
+
|
|
826
|
+
tr.push(td)
|
|
788
827
|
}
|
|
789
828
|
}
|
|
790
829
|
else {
|
|
830
|
+
let a_sorce
|
|
831
|
+
if (tblStylAttrObj['isFrstColAttr'] === 1 && tblStylAttrObj['isLstRowAttr'] !== 1) {
|
|
832
|
+
a_sorce = 'a:firstCol'
|
|
833
|
+
}
|
|
834
|
+
else if (tblStylAttrObj['isBandColAttr'] === 1 && tblStylAttrObj['isLstRowAttr'] !== 1) {
|
|
835
|
+
let aBandNode = getTextByPathList(thisTblStyle, ['a:band2V'])
|
|
836
|
+
if (!aBandNode) {
|
|
837
|
+
aBandNode = getTextByPathList(thisTblStyle, ['a:band1V'])
|
|
838
|
+
if (aBandNode) a_sorce = 'a:band2V'
|
|
839
|
+
}
|
|
840
|
+
else a_sorce = 'a:band2V'
|
|
841
|
+
}
|
|
842
|
+
if (tblStylAttrObj['isLstColAttr'] === 1 && tblStylAttrObj['isLstRowAttr'] !== 1) {
|
|
843
|
+
a_sorce = 'a:lastCol'
|
|
844
|
+
}
|
|
845
|
+
|
|
791
846
|
const text = genTextBody(tcNodes['a:txBody'], tcNodes, undefined, undefined, warpObj)
|
|
792
|
-
|
|
847
|
+
const cell = getTableCellParams(tcNodes, thisTblStyle, a_sorce, warpObj)
|
|
848
|
+
const td = { text }
|
|
849
|
+
if (cell.rowSpan) td.rowSpan = cell.rowSpan
|
|
850
|
+
if (cell.colSpan) td.colSpan = cell.colSpan
|
|
851
|
+
if (cell.vMerge) td.vMerge = cell.vMerge
|
|
852
|
+
if (cell.hMerge) td.hMerge = cell.hMerge
|
|
853
|
+
if (cell.fontBold || fontBold) td.fontBold = cell.fontBold || fontBold
|
|
854
|
+
if (cell.fontColor || fontColor) td.fontColor = cell.fontColor || fontColor
|
|
855
|
+
if (cell.fillColor || fillColor || tbl_bgcolor) td.fill = cell.fillColor || fillColor || tbl_bgcolor
|
|
856
|
+
|
|
857
|
+
tr.push(td)
|
|
793
858
|
}
|
|
794
859
|
data.push(tr)
|
|
795
860
|
}
|
|
@@ -801,14 +866,13 @@ function genTable(node, warpObj) {
|
|
|
801
866
|
width,
|
|
802
867
|
height,
|
|
803
868
|
data,
|
|
804
|
-
themeColor,
|
|
805
869
|
}
|
|
806
870
|
}
|
|
807
871
|
|
|
808
872
|
async function genChart(node, warpObj) {
|
|
809
873
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
810
|
-
const { top, left } = getPosition(xfrmNode, undefined, undefined
|
|
811
|
-
const { width, height } = getSize(xfrmNode, undefined, undefined
|
|
874
|
+
const { top, left } = getPosition(xfrmNode, undefined, undefined)
|
|
875
|
+
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
812
876
|
|
|
813
877
|
const rid = node['a:graphic']['a:graphicData']['c:chart']['attrs']['r:id']
|
|
814
878
|
const refName = warpObj['slideResObj'][rid]['target']
|
|
@@ -839,8 +903,8 @@ async function genChart(node, warpObj) {
|
|
|
839
903
|
|
|
840
904
|
function genDiagram(node, warpObj) {
|
|
841
905
|
const xfrmNode = getTextByPathList(node, ['p:xfrm'])
|
|
842
|
-
const { left, top } = getPosition(xfrmNode, undefined, undefined
|
|
843
|
-
const { width, height } = getSize(xfrmNode, undefined, undefined
|
|
906
|
+
const { left, top } = getPosition(xfrmNode, undefined, undefined)
|
|
907
|
+
const { width, height } = getSize(xfrmNode, undefined, undefined)
|
|
844
908
|
|
|
845
909
|
const dgmDrwSpArray = getTextByPathList(warpObj['digramFileContent'], ['p:drawing', 'p:spTree', 'p:sp'])
|
|
846
910
|
const elements = []
|
package/src/shadow.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { getSolidFill } from './fill'
|
|
2
|
+
import { RATIO_EMUs_Points } from './constants'
|
|
2
3
|
|
|
3
4
|
export function getShadow(node, warpObj) {
|
|
4
|
-
const slideFactor = warpObj.options.slideFactor
|
|
5
5
|
const chdwClrNode = getSolidFill(node, undefined, undefined, warpObj)
|
|
6
6
|
const outerShdwAttrs = node['attrs']
|
|
7
|
-
const dir =
|
|
8
|
-
const dist = parseInt(outerShdwAttrs['dist']) *
|
|
9
|
-
const blurRad = outerShdwAttrs['blurRad'] ?
|
|
7
|
+
const dir = outerShdwAttrs['dir'] ? (parseInt(outerShdwAttrs['dir']) / 60000) : 0
|
|
8
|
+
const dist = parseInt(outerShdwAttrs['dist']) * RATIO_EMUs_Points
|
|
9
|
+
const blurRad = outerShdwAttrs['blurRad'] ? parseInt(outerShdwAttrs['blurRad']) * RATIO_EMUs_Points : ''
|
|
10
10
|
const vx = dist * Math.sin(dir * Math.PI / 180)
|
|
11
11
|
const hx = dist * Math.cos(dir * Math.PI / 180)
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
|
-
h:
|
|
15
|
-
v:
|
|
14
|
+
h: hx,
|
|
15
|
+
v: vx,
|
|
16
16
|
blur: blurRad,
|
|
17
|
-
color:
|
|
17
|
+
color: chdwClrNode,
|
|
18
18
|
}
|
|
19
19
|
}
|