From aeee2b25d2563fbd3e26545854564f3a19697ec1 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Sun, 7 Jan 2024 21:56:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9B=B4=E6=96=B0pptxtojson=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=AF=BC=E5=85=A5PPTX=20de?= =?UTF-8?q?mo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 14 +++++++------- package.json | 2 +- src/hooks/useImport.ts | 31 ++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 802da0ff..34689896 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "number-precision": "^1.6.0", "pinia": "^2.1.7", "pptxgenjs": "^3.12.0", - "pptxtojson": "^0.1.2", + "pptxtojson": "^0.1.3", "prosemirror-commands": "^1.5.2", "prosemirror-dropcursor": "^1.8.1", "prosemirror-gapcursor": "^1.3.2", @@ -4011,9 +4011,9 @@ } }, "node_modules/pptxtojson": { - "version": "0.1.2", - "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.2.tgz", - "integrity": "sha512-UvzEuCnspfZqc1Tf7TU6tSyXV+4OngkTfoAEZdPVW2i6wedU16wr8hkNzwQ77ePyfoyaODAFwS9cfJnnEhwfKQ==", + "version": "0.1.3", + "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.3.tgz", + "integrity": "sha512-UKtoa9jiyMyZYHTiRTPjVdnByzGK0e7xcscpMTTBSUFVKvX1dnNGfYxqyY54RxppYm10ZVb4TJhmxBLnu+M0xw==", "dependencies": { "jszip": "^3.10.1", "tinycolor2": "1.6.0", @@ -8098,9 +8098,9 @@ } }, "pptxtojson": { - "version": "0.1.2", - "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.2.tgz", - "integrity": "sha512-UvzEuCnspfZqc1Tf7TU6tSyXV+4OngkTfoAEZdPVW2i6wedU16wr8hkNzwQ77ePyfoyaODAFwS9cfJnnEhwfKQ==", + "version": "0.1.3", + "resolved": "https://registry.npmmirror.com/pptxtojson/-/pptxtojson-0.1.3.tgz", + "integrity": "sha512-UKtoa9jiyMyZYHTiRTPjVdnByzGK0e7xcscpMTTBSUFVKvX1dnNGfYxqyY54RxppYm10ZVb4TJhmxBLnu+M0xw==", "requires": { "jszip": "^3.10.1", "tinycolor2": "1.6.0", diff --git a/package.json b/package.json index 8454f0a6..895f5694 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "number-precision": "^1.6.0", "pinia": "^2.1.7", "pptxgenjs": "^3.12.0", - "pptxtojson": "^0.1.2", + "pptxtojson": "^0.1.3", "prosemirror-commands": "^1.5.2", "prosemirror-dropcursor": "^1.8.1", "prosemirror-gapcursor": "^1.3.2", diff --git a/src/hooks/useImport.ts b/src/hooks/useImport.ts index 2d3b049e..0d2352eb 100644 --- a/src/hooks/useImport.ts +++ b/src/hooks/useImport.ts @@ -138,6 +138,11 @@ export default () => { const parseElements = (elements: Element[]) => { 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.height = el.height * scale el.left = el.left * scale @@ -178,6 +183,8 @@ export default () => { top: el.top, fixedRatio: true, rotate: el.rotate, + flipH: el.isFlipH, + flipV: el.isFlipV, }) } else if (el.type === 'audio') { @@ -270,7 +277,7 @@ export default () => { if (el.shapType === 'custom') { element.special = true element.path = el.path! - element.viewBox = [el.width, el.height] + element.viewBox = [originWidth, originHeight] } slide.elements.push(element) @@ -289,13 +296,27 @@ export default () => { const rowCells: TableCell[] = [] for (let j = 0; j < col; 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({ id: nanoid(10), colspan: cellData.colSpan || 1, rowspan: cellData.rowSpan || 1, - text: cellData.text, - style, + text: textDiv.innerText, + style: { + ...style, + align: ['left', 'right', 'center'].includes(align) ? (align as 'left' | 'right' | 'center') : 'left', + fontsize, + fontname, + }, }) + textDiv = null } data.push(rowCells) } @@ -397,8 +418,8 @@ export default () => { else if (el.type === 'group' || el.type === 'diagram') { const elements = el.elements.map(_el => ({ ..._el, - left: _el.left + el.left, - top: _el.top + el.top, + left: _el.left + originLeft, + top: _el.top + originTop, })) parseElements(elements) }