perf: 更新pptxtojson版本,更新导入PPTX demo

This commit is contained in:
pipipi-pikachu 2024-01-07 21:56:07 +08:00
parent 483547854a
commit aeee2b25d2
3 changed files with 34 additions and 13 deletions

14
package-lock.json generated
View File

@ -23,7 +23,7 @@
"number-precision": "^1.6.0", "number-precision": "^1.6.0",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pptxgenjs": "^3.12.0", "pptxgenjs": "^3.12.0",
"pptxtojson": "^0.1.2", "pptxtojson": "^0.1.3",
"prosemirror-commands": "^1.5.2", "prosemirror-commands": "^1.5.2",
"prosemirror-dropcursor": "^1.8.1", "prosemirror-dropcursor": "^1.8.1",
"prosemirror-gapcursor": "^1.3.2", "prosemirror-gapcursor": "^1.3.2",
@ -4011,9 +4011,9 @@
} }
}, },
"node_modules/pptxtojson": { "node_modules/pptxtojson": {
"version": "0.1.2", "version": "0.1.3",
"resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.2.tgz", "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.3.tgz",
"integrity": "sha512-UvzEuCnspfZqc1Tf7TU6tSyXV+4OngkTfoAEZdPVW2i6wedU16wr8hkNzwQ77ePyfoyaODAFwS9cfJnnEhwfKQ==", "integrity": "sha512-UKtoa9jiyMyZYHTiRTPjVdnByzGK0e7xcscpMTTBSUFVKvX1dnNGfYxqyY54RxppYm10ZVb4TJhmxBLnu+M0xw==",
"dependencies": { "dependencies": {
"jszip": "^3.10.1", "jszip": "^3.10.1",
"tinycolor2": "1.6.0", "tinycolor2": "1.6.0",
@ -8098,9 +8098,9 @@
} }
}, },
"pptxtojson": { "pptxtojson": {
"version": "0.1.2", "version": "0.1.3",
"resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.2.tgz", "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.3.tgz",
"integrity": "sha512-UvzEuCnspfZqc1Tf7TU6tSyXV+4OngkTfoAEZdPVW2i6wedU16wr8hkNzwQ77ePyfoyaODAFwS9cfJnnEhwfKQ==", "integrity": "sha512-UKtoa9jiyMyZYHTiRTPjVdnByzGK0e7xcscpMTTBSUFVKvX1dnNGfYxqyY54RxppYm10ZVb4TJhmxBLnu+M0xw==",
"requires": { "requires": {
"jszip": "^3.10.1", "jszip": "^3.10.1",
"tinycolor2": "1.6.0", "tinycolor2": "1.6.0",

View File

@ -28,7 +28,7 @@
"number-precision": "^1.6.0", "number-precision": "^1.6.0",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pptxgenjs": "^3.12.0", "pptxgenjs": "^3.12.0",
"pptxtojson": "^0.1.2", "pptxtojson": "^0.1.3",
"prosemirror-commands": "^1.5.2", "prosemirror-commands": "^1.5.2",
"prosemirror-dropcursor": "^1.8.1", "prosemirror-dropcursor": "^1.8.1",
"prosemirror-gapcursor": "^1.3.2", "prosemirror-gapcursor": "^1.3.2",

View File

@ -138,6 +138,11 @@ export default () => {
const parseElements = (elements: Element[]) => { const parseElements = (elements: Element[]) => {
for (const el of elements) { for (const el of elements) {
const originWidth = el.width
const originHeight = el.height
const originLeft = el.left
const originTop = el.top
el.width = el.width * scale el.width = el.width * scale
el.height = el.height * scale el.height = el.height * scale
el.left = el.left * scale el.left = el.left * scale
@ -178,6 +183,8 @@ export default () => {
top: el.top, top: el.top,
fixedRatio: true, fixedRatio: true,
rotate: el.rotate, rotate: el.rotate,
flipH: el.isFlipH,
flipV: el.isFlipV,
}) })
} }
else if (el.type === 'audio') { else if (el.type === 'audio') {
@ -270,7 +277,7 @@ export default () => {
if (el.shapType === 'custom') { if (el.shapType === 'custom') {
element.special = true element.special = true
element.path = el.path! element.path = el.path!
element.viewBox = [el.width, el.height] element.viewBox = [originWidth, originHeight]
} }
slide.elements.push(element) slide.elements.push(element)
@ -289,13 +296,27 @@ export default () => {
const rowCells: TableCell[] = [] const rowCells: TableCell[] = []
for (let j = 0; j < col; j++) { for (let j = 0; j < col; j++) {
const cellData = el.data[i][j] const cellData = el.data[i][j]
let textDiv: HTMLDivElement | null = document.createElement('div')
textDiv.innerHTML = cellData.text
const p = textDiv.querySelector('p')
const align = p?.style.textAlign || 'left'
const fontsize = p?.style.fontSize || ''
const fontname = p?.style.fontFamily || ''
rowCells.push({ rowCells.push({
id: nanoid(10), id: nanoid(10),
colspan: cellData.colSpan || 1, colspan: cellData.colSpan || 1,
rowspan: cellData.rowSpan || 1, rowspan: cellData.rowSpan || 1,
text: cellData.text, text: textDiv.innerText,
style, style: {
...style,
align: ['left', 'right', 'center'].includes(align) ? (align as 'left' | 'right' | 'center') : 'left',
fontsize,
fontname,
},
}) })
textDiv = null
} }
data.push(rowCells) data.push(rowCells)
} }
@ -397,8 +418,8 @@ export default () => {
else if (el.type === 'group' || el.type === 'diagram') { else if (el.type === 'group' || el.type === 'diagram') {
const elements = el.elements.map(_el => ({ const elements = el.elements.map(_el => ({
..._el, ..._el,
left: _el.left + el.left, left: _el.left + originLeft,
top: _el.top + el.top, top: _el.top + originTop,
})) }))
parseElements(elements) parseElements(elements)
} }