jvs-ppt-ui 0.0.32 → 0.0.34

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.
Files changed (32) hide show
  1. package/README.md +152 -0
  2. package/dist/lib/jvs-ppt-ui.es.js +23678 -21439
  3. package/dist/lib/jvs-ppt-ui.umd.js +136 -100
  4. package/dist/lib/style.css +1 -1
  5. package/package.json +2 -1
  6. package/src/components/CanvasArea.vue +77 -35
  7. package/src/components/Header.vue +184 -26
  8. package/src/components/PitchImportDialog.vue +29 -6
  9. package/src/components/PptEditor.vue +53 -1
  10. package/src/components/QuickColorPopover.vue +2 -1
  11. package/src/components/SidebarLeft.vue +367 -41
  12. package/src/components/SidebarRight.vue +183 -134
  13. package/src/components/canvas/CanvasTransformHandles.vue +27 -36
  14. package/src/components/canvas/elements/CanvasMediaElement.vue +4 -3
  15. package/src/components/canvas/elements/CanvasShapeElement.vue +9 -6
  16. package/src/components/sidebar/panels/LayoutThumbSvg.vue +9 -6
  17. package/src/components/sidebar/panels/SidebarShapeFormatPanel.vue +1 -1
  18. package/src/components/sidebar/panels/SidebarTextFormatPanel.vue +1 -1
  19. package/src/composables/canvas/useCanvasFormatting.ts +20 -13
  20. package/src/composables/canvas/useCanvasText.ts +4 -3
  21. package/src/composables/canvas/useCanvasTransform.ts +37 -10
  22. package/src/composables/sidebar/useSidebarElementTransform.ts +86 -57
  23. package/src/composables/sidebar/useSidebarTextFormat.ts +242 -19
  24. package/src/composables/useSlides.ts +93 -28
  25. package/src/configs/slideTemplates.ts +1001 -0
  26. package/src/style.css +265 -2
  27. package/src/types/index.ts +37 -1
  28. package/src/utils/canvas/elementStyles.ts +55 -20
  29. package/src/utils/canvas/formatPainter.ts +177 -30
  30. package/src/utils/muxHlsToMp4.ts +569 -0
  31. package/src/utils/pitchConverter.ts +512 -13
  32. package/dist/lib/templates/index.json +0 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jvs-ppt-ui",
3
3
  "private": false,
4
- "version": "0.0.32",
4
+ "version": "0.0.34",
5
5
  "type": "module",
6
6
  "main": "./dist/lib/jvs-ppt-ui.umd.js",
7
7
  "module": "./dist/lib/jvs-ppt-ui.es.js",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "dist/lib",
20
+ "!dist/lib/templates/**",
20
21
  "src",
21
22
  "scripts"
22
23
  ],
@@ -1010,13 +1010,19 @@ const getOverlayWidth = (el: any) => {
1010
1010
  }
1011
1011
  const isVerticalText = el.type === 'text' && !el.content?.includes('<table') && !el.latex && (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr')
1012
1012
  if (isVerticalText && !isDragging.value) {
1013
- const dom = document.getElementById(`editable-${el.id}`) || document.getElementById(`canvas-el-${el.id}`)
1014
- if (dom) {
1015
- const w = Math.max(dom.scrollWidth || 0, dom.offsetWidth || 0)
1016
- if (w > 0) return `${w}px`
1013
+ if (el.autoFit?.type === 'shape' || el.style?.width === 'auto' || el.style?.width === undefined) {
1014
+ const dom = document.getElementById(`editable-${el.id}`) || document.getElementById(`canvas-el-${el.id}`)
1015
+ if (dom) {
1016
+ const w = Math.max(dom.scrollWidth || 0, dom.offsetWidth || 0)
1017
+ if (w > 0) return `${w}px`
1018
+ }
1019
+ } else if (el.style?.width && el.style.width !== 'auto') {
1020
+ return `${getElementWidthHeight(el).width}px`
1021
+ } else if (el.width && el.width > 0) {
1022
+ return `${el.width}px`
1017
1023
  }
1018
1024
  }
1019
- if (el.style?.width && el.style.width !== 'auto' && !isVerticalText) {
1025
+ if (el.style?.width && el.style.width !== 'auto') {
1020
1026
  return `${getElementWidthHeight(el).width}px`
1021
1027
  }
1022
1028
  if (el.id === selectedElementId.value && !isResizing.value && selectedElementWidth.value && selectedElementWidth.value !== '0px') {
@@ -1208,7 +1214,8 @@ function syncSelectedElementDimensionsFromDom(id: string | null) {
1208
1214
  const editableDom = document.getElementById(`editable-${id}`)
1209
1215
  const selEl = activeSlide.value?.elements.find((x: any) => x.id === id)
1210
1216
  const isVertical = selEl && (selEl.style?.writingMode === 'vertical-rl' || selEl.style?.writingMode === 'vertical-lr')
1211
- const initialW = isVertical && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
1217
+ const isVerticalAutoW = isVertical && (selEl?.autoFit?.type === 'shape' || !selEl?.style?.width || selEl.style.width === 'auto')
1218
+ const initialW = isVerticalAutoW && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
1212
1219
  const initialH = dom.offsetHeight > 0 ? dom.offsetHeight : (tableEl && tableEl.offsetHeight > 0 ? tableEl.offsetHeight : 0)
1213
1220
  selectedElementWidth.value = `${initialW}px`
1214
1221
  selectedElementHeight.value = `${initialH}px`
@@ -1237,7 +1244,8 @@ function observeSelectedElement() {
1237
1244
  const editableDom = document.getElementById(`editable-${selectedElementId.value}`)
1238
1245
  const selEl = activeSlide.value?.elements.find((x: any) => x.id === selectedElementId.value)
1239
1246
  const isVertical = selEl && (selEl.style?.writingMode === 'vertical-rl' || selEl.style?.writingMode === 'vertical-lr')
1240
- const initialW = isVertical && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
1247
+ const isVerticalAutoW = isVertical && (selEl?.autoFit?.type === 'shape' || !selEl?.style?.width || selEl.style.width === 'auto')
1248
+ const initialW = isVerticalAutoW && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
1241
1249
  const initialH = dom.offsetHeight > 0 ? dom.offsetHeight : (tableEl && tableEl.offsetHeight > 0 ? tableEl.offsetHeight : 0)
1242
1250
  selectedElementWidth.value = `${initialW}px`
1243
1251
  selectedElementHeight.value = `${initialH}px`
@@ -1249,7 +1257,8 @@ function observeSelectedElement() {
1249
1257
  const curEditableDom = document.getElementById(`editable-${selectedElementId.value}`)
1250
1258
  const currentSelEl = activeSlide.value?.elements.find((x: any) => x.id === selectedElementId.value)
1251
1259
  const curIsVertical = currentSelEl && (currentSelEl.style?.writingMode === 'vertical-rl' || currentSelEl.style?.writingMode === 'vertical-lr')
1252
- const curW = curIsVertical && curEditableDom
1260
+ const curIsVerticalAutoW = curIsVertical && (currentSelEl?.autoFit?.type === 'shape' || !currentSelEl?.style?.width || currentSelEl.style.width === 'auto')
1261
+ const curW = curIsVerticalAutoW && curEditableDom
1253
1262
  ? Math.max(curEditableDom.scrollWidth, dom.offsetWidth)
1254
1263
  : dom.offsetWidth
1255
1264
  // 值相等守卫:避免 RO → 渲染 → RO 的无谓链路
@@ -1274,6 +1283,7 @@ watch(selectedElementId, observeSelectedElement)
1274
1283
  watch(
1275
1284
  () => [
1276
1285
  selectedElement.value?.content,
1286
+ (selectedElement.value as any)?.text,
1277
1287
  selectedElement.value?.style?.fontSize,
1278
1288
  selectedElement.value?.style?.fontFamily,
1279
1289
  selectedElement.value?.style?.lineHeight,
@@ -1284,9 +1294,15 @@ watch(
1284
1294
  selectedElement.value?.autoFit?.type
1285
1295
  ],
1286
1296
  () => {
1287
- if (selectedElement.value?.type === 'text' && selectedElement.value?.autoFit?.type === 'text') {
1297
+ const el = selectedElement.value
1298
+ if (!el) return
1299
+ if ((el.type === 'text' || el.type === 'shape') && el.autoFit?.type === 'text') {
1288
1300
  nextTick(() => {
1289
- updateTextFontScale(selectedElement.value)
1301
+ updateTextFontScale(el)
1302
+ })
1303
+ } else if (el.type === 'shape' && el.autoFit?.type === 'shape') {
1304
+ nextTick(() => {
1305
+ syncShapeAutoFitHeight(el)
1290
1306
  })
1291
1307
  }
1292
1308
  },
@@ -2773,14 +2789,16 @@ function handleCanvasMouseDown(e: MouseEvent) {
2773
2789
  const fontWeight = textCfg.fontWeight || typeConf.defaultFontWeight
2774
2790
  const lineHeight = textCfg.lineHeight || typeConf.defaultLineHeight
2775
2791
  const letterSpacing = textCfg.letterSpacing !== undefined ? `${textCfg.letterSpacing}px` : '0px'
2776
- const defaultW = `${typeConf.defaultWidth}px`
2792
+ const defaultWNum = typeConf.defaultWidth
2793
+ const defaultW = `${defaultWNum}px`
2794
+ const defaultHNum = Math.max(typeConf.defaultHeight || 36, Math.ceil((parseFloat(fontSize) || typeConf.defaultFontSize || 18) * (parseFloat(String(lineHeight)) || 1.2) + 12))
2777
2795
 
2778
2796
  content = `<div style="color:${textColor}; font-family:${textFont};"><br></div>`
2779
2797
  style = {
2780
2798
  top: `${creationStartPctY.toFixed(2)}%`,
2781
2799
  left: `${creationStartPctX.toFixed(2)}%`,
2782
2800
  width: defaultW,
2783
- height: 'auto',
2801
+ height: `${defaultHNum}px`,
2784
2802
  color: textColor,
2785
2803
  textColor: textColor,
2786
2804
  fontFamily: textFont,
@@ -2801,10 +2819,17 @@ function handleCanvasMouseDown(e: MouseEvent) {
2801
2819
  name: typeConf.label,
2802
2820
  content,
2803
2821
  style,
2822
+ width: defaultWNum,
2823
+ height: defaultHNum,
2804
2824
  color: textColor,
2805
2825
  textColor: textColor,
2806
2826
  fontFamily: textFont,
2807
- verticalAlign: 'middle'
2827
+ verticalAlign: 'middle',
2828
+ autoFit: {
2829
+ type: 'none',
2830
+ fontScale: 100,
2831
+ lnSpcReduction: 0
2832
+ }
2808
2833
  }
2809
2834
  } else if (activeTool.value === 'text-vertical') {
2810
2835
  type = 'text'
@@ -2822,12 +2847,13 @@ function handleCanvasMouseDown(e: MouseEvent) {
2822
2847
  const fontWeight = textCfg.fontWeight || typeConf.defaultFontWeight
2823
2848
  const lineHeight = textCfg.lineHeight || typeConf.defaultLineHeight
2824
2849
  const letterSpacing = textCfg.letterSpacing !== undefined ? `${textCfg.letterSpacing}px` : '0px'
2850
+ const defaultVertW = Math.max(48, Math.ceil((parseFloat(fontSize) || typeConf.defaultFontSize || 18) * (parseFloat(String(lineHeight)) || 1.2) + 16))
2825
2851
 
2826
2852
  content = `<div style="color:${textColor}; font-family:${textFont};"><br></div>`
2827
2853
  style = {
2828
2854
  top: `${creationStartPctY.toFixed(2)}%`,
2829
2855
  left: `${creationStartPctX.toFixed(2)}%`,
2830
- width: 'auto',
2856
+ width: `${defaultVertW}px`,
2831
2857
  height: '180px',
2832
2858
  color: textColor,
2833
2859
  textColor: textColor,
@@ -2849,10 +2875,17 @@ function handleCanvasMouseDown(e: MouseEvent) {
2849
2875
  name: `竖排${typeConf.label}`,
2850
2876
  content,
2851
2877
  style,
2878
+ width: defaultVertW,
2879
+ height: 180,
2852
2880
  color: textColor,
2853
2881
  textColor: textColor,
2854
2882
  fontFamily: textFont,
2855
- verticalAlign: 'middle'
2883
+ verticalAlign: 'middle',
2884
+ autoFit: {
2885
+ type: 'none',
2886
+ fontScale: 100,
2887
+ lnSpcReduction: 0
2888
+ }
2856
2889
  }
2857
2890
  } else if (activeTool.value === 'shape-draw') {
2858
2891
  type = 'shape'
@@ -3108,14 +3141,6 @@ function updateCreationPosition(e: MouseEvent) {
3108
3141
  const midPoint = [(startRel[0] + endRel[0]) / 2, (startRel[1] + endRel[1]) / 2] as [number, number]
3109
3142
  createdElement.cubic = [midPoint, midPoint]
3110
3143
  }
3111
- } else if (createdElement.type === 'text') {
3112
- if (createdElement.style.writingMode === 'vertical-rl' || createdElement.style.writingMode === 'vertical-lr') {
3113
- createdElement.style.height = `${heightPx.toFixed(0)}px`
3114
- createdElement.style.width = 'auto'
3115
- } else {
3116
- createdElement.style.width = `${widthPx.toFixed(0)}px`
3117
- createdElement.style.height = 'auto'
3118
- }
3119
3144
  }
3120
3145
  }
3121
3146
 
@@ -3192,17 +3217,32 @@ function stopCreationDrag() {
3192
3217
  }
3193
3218
  }
3194
3219
  } else if (createdElement.type === 'text') {
3220
+ const typeConf = TEXT_TYPE_CONFIGS[createdElement.textType as SlideTextType] || TEXT_TYPE_CONFIGS.normalText
3221
+ const fs = parseFloat(createdElement.style.fontSize) || typeConf.defaultFontSize || 18
3222
+ const lh = parseFloat(String(createdElement.style.lineHeight)) || typeConf.defaultLineHeight || 1.3
3223
+ const minVertW = Math.max(48, Math.ceil(fs * lh + 16))
3224
+ const minHorizH = Math.max(typeConf.defaultHeight || 36, Math.ceil(fs * lh + 12))
3195
3225
  if (createdElement.style.writingMode === 'vertical-rl' || createdElement.style.writingMode === 'vertical-lr') {
3196
3226
  if (heightVal < 15) {
3197
3227
  createdElement.style.height = '180px'
3198
3228
  }
3199
- createdElement.style.width = 'auto'
3229
+ if (widthVal < minVertW) {
3230
+ createdElement.style.width = `${minVertW}px`
3231
+ }
3200
3232
  } else {
3201
3233
  if (widthVal < 15) {
3202
- const typeConf = TEXT_TYPE_CONFIGS[createdElement.textType as SlideTextType] || TEXT_TYPE_CONFIGS.normalText
3203
3234
  createdElement.style.width = `${typeConf.defaultWidth}px`
3204
3235
  }
3205
- createdElement.style.height = 'auto'
3236
+ if (heightVal < minHorizH) {
3237
+ createdElement.style.height = `${minHorizH}px`
3238
+ }
3239
+ }
3240
+ createdElement.width = parseFloat(createdElement.style.width) || typeConf.defaultWidth
3241
+ createdElement.height = parseFloat(createdElement.style.height) || typeConf.defaultHeight
3242
+ createdElement.autoFit = {
3243
+ type: 'none',
3244
+ fontScale: 100,
3245
+ lnSpcReduction: 0
3206
3246
  }
3207
3247
  }
3208
3248
 
@@ -4381,10 +4421,12 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
4381
4421
  if (!isNaN(w) && !isNaN(h) && w > 0 && h > 0) {
4382
4422
  if (el.type === 'text' && !el.content?.includes('<table') && !el.latex && !isDragging.value) {
4383
4423
  if (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr') {
4384
- const editableDom = document.getElementById(`editable-${el.id}`)
4385
- const dom = document.getElementById(`canvas-el-${el.id}`)
4386
- const actualW = Math.max(editableDom?.scrollWidth || 0, dom?.offsetWidth || 0, w)
4387
- return { width: actualW, height: h }
4424
+ if (el.autoFit?.type === 'shape') {
4425
+ const editableDom = document.getElementById(`editable-${el.id}`)
4426
+ const dom = document.getElementById(`canvas-el-${el.id}`)
4427
+ const actualW = Math.max(editableDom?.scrollWidth || 0, dom?.offsetWidth || 0, w)
4428
+ return { width: actualW, height: h }
4429
+ }
4388
4430
  } else if (el.autoFit?.type === 'shape') {
4389
4431
  const dom = document.getElementById(`canvas-el-${el.id}`) || document.getElementById(`canvas-content-${el.id}`)
4390
4432
  if (dom && dom.offsetHeight > 0) {
@@ -4400,7 +4442,7 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
4400
4442
  return { width: el.width, height: el.height }
4401
4443
  }
4402
4444
 
4403
- const fitType = el.autoFit?.type || ((el.style?.height && el.style.height !== 'auto') ? 'none' : (el.type === 'text' ? 'shape' : undefined))
4445
+ const fitType = el.autoFit?.type || 'none'
4404
4446
  const isWidthAuto = el.style?.width === 'auto' || (el.type === 'text' && fitType === 'shape' && (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr' || el.style?.whiteSpace === 'nowrap'))
4405
4447
  const isHeightAuto = el.style?.height === 'auto' || el.style?.height === undefined || (el.type === 'text' && !el.content?.includes('<table') && !el.latex && fitType === 'shape' && (!(el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr') || el.style?.whiteSpace === 'nowrap'))
4406
4448
 
@@ -4467,7 +4509,7 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
4467
4509
  }
4468
4510
  }
4469
4511
 
4470
- if (el.type === 'text' && !el.content?.includes('<table') && !el.latex && el.style?.writingMode !== 'vertical-rl' && el.style?.writingMode !== 'vertical-lr') {
4512
+ if (isHeightAuto && el.type === 'text' && !el.content?.includes('<table') && !el.latex && el.style?.writingMode !== 'vertical-rl' && el.style?.writingMode !== 'vertical-lr') {
4471
4513
  if (dom && dom.offsetHeight > 0) {
4472
4514
  height = Math.max(height, dom.offsetHeight)
4473
4515
  }
@@ -7156,7 +7198,7 @@ function handleTextBlur(e: FocusEvent, el: any) {
7156
7198
  el.style.height = `${el.height || 40}px`
7157
7199
  }
7158
7200
  } else {
7159
- const fitType = el.autoFit?.type || 'shape'
7201
+ const fitType = el.autoFit?.type || 'none'
7160
7202
  if (fitType === 'shape') {
7161
7203
  el.style.height = 'auto'
7162
7204
  if (container.offsetHeight > 0) {
@@ -8254,11 +8296,11 @@ async function handleGlobalPaste(e: ClipboardEvent) {
8254
8296
  v-memo="[
8255
8297
  (isDragging || isCanvasDragging)
8256
8298
  ? (selectedElementIds.includes(el.id)
8257
- ? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}`
8299
+ ? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${(el as any).autoFit?.fontScale || ''}`
8258
8300
  : (el.type === 'line'
8259
8301
  ? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}`
8260
8302
  : 'frozen'))
8261
- : `${el.id}_${el.type}_${el.content}_${(el as any).src}_${el.isPlaceholderReplaced}_${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${el.type === 'line' ? `${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}_` : ''}${selectedElementIds.includes(el.id)}_${selectedElementId === el.id}_${isEditingText}_${activeTab}_${activeSlideVersion}_${(el.style as any)?.reflection?.enabled}_${(el.style as any)?.reflection?.distance}_${(el.style as any)?.reflection?.size}_${(el.style as any)?.reflection?.blur}_${(el.style as any)?.reflection?.opacity}`
8303
+ : `${el.id}_${el.type}_${el.content}_${typeof (el as any).text === 'string' ? (el as any).text : ((el as any).text?.content || '')}_${(el.style as any)?.textBackground || ''}_${(el as any).autoFit?.type || ''}_${(el as any).autoFit?.fontScale || ''}_${(el as any).src}_${el.isPlaceholderReplaced}_${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${el.type === 'line' ? `${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}_` : ''}${selectedElementIds.includes(el.id)}_${selectedElementId === el.id}_${isEditingText}_${activeTab}_${activeSlideVersion}_${(el.style as any)?.reflection?.enabled}_${(el.style as any)?.reflection?.distance}_${(el.style as any)?.reflection?.size}_${(el.style as any)?.reflection?.blur}_${(el.style as any)?.reflection?.opacity}`
8262
8304
  ]"
8263
8305
  :class="{
8264
8306
  selected: selectedElementIds.includes(el.id),
@@ -3812,6 +3812,66 @@ function parseCustGeomToPolygon(custGeomXml: string): string | null {
3812
3812
  return points.length >= 3 ? points.join(', ') : null
3813
3813
  }
3814
3814
 
3815
+ // 解析 OOXML 自定义几何路径 <a:custGeom> 为标准 SVG path 与 viewBox,用于母版/版式装饰自由形状(如点阵背景、圆环弧、自定义多边形)
3816
+ function parseCustGeomToSvgPath(
3817
+ custGeomXml: string,
3818
+ pxWidth: number,
3819
+ pxHeight: number,
3820
+ emuCx: number,
3821
+ emuCy: number
3822
+ ): { path: string; viewBox: [number, number] } | null {
3823
+ const pathBlocks = custGeomXml.match(/<a:path\b[\s\S]*?<\/a:path>/g) || []
3824
+ if (pathBlocks.length === 0) return null
3825
+ const targetW = pxWidth > 0 ? pxWidth : 200
3826
+ const targetH = pxHeight > 0 ? pxHeight : 200
3827
+ const dParts: string[] = []
3828
+
3829
+ for (const block of pathBlocks) {
3830
+ const openTag = (block.match(/<a:path\b[^>]*>/) || [''])[0]
3831
+ const wM = openTag.match(/\bw="(\d+)"/)
3832
+ const hM = openTag.match(/\bh="(\d+)"/)
3833
+ const pathW = wM ? parseInt(wM[1], 10) : (emuCx > 0 ? emuCx : targetW)
3834
+ const pathH = hM ? parseInt(hM[1], 10) : (emuCy > 0 ? emuCy : targetH)
3835
+ if (pathW <= 0 || pathH <= 0) continue
3836
+ const sx = targetW / pathW
3837
+ const sy = targetH / pathH
3838
+ const fmtX = (v: number) => +(v * sx).toFixed(2)
3839
+ const fmtY = (v: number) => +(v * sy).toFixed(2)
3840
+
3841
+ const cmdRegex = /<a:(moveTo|lnTo|cubicBezTo|quadBezTo)\b[^>]*>([\s\S]*?)<\/a:\1>|<a:(close)\b[^>]*\/?>/g
3842
+ let m: RegExpExecArray | null
3843
+ while ((m = cmdRegex.exec(block)) !== null) {
3844
+ if (m[3] === 'close') {
3845
+ dParts.push('Z')
3846
+ continue
3847
+ }
3848
+ const cmd = m[1]
3849
+ const inner = m[2] || ''
3850
+ const pts: Array<[number, number]> = []
3851
+ const ptRe = /<a:pt\b[^>]*x="(-?\d+)"[^>]*y="(-?\d+)"/g
3852
+ let pm: RegExpExecArray | null
3853
+ while ((pm = ptRe.exec(inner)) !== null) {
3854
+ pts.push([parseInt(pm[1], 10), parseInt(pm[2], 10)])
3855
+ }
3856
+ if (cmd === 'moveTo' && pts.length >= 1) {
3857
+ dParts.push(`M ${fmtX(pts[0][0])} ${fmtY(pts[0][1])}`)
3858
+ } else if (cmd === 'lnTo' && pts.length >= 1) {
3859
+ dParts.push(`L ${fmtX(pts[0][0])} ${fmtY(pts[0][1])}`)
3860
+ } else if (cmd === 'cubicBezTo' && pts.length >= 3) {
3861
+ dParts.push(`C ${fmtX(pts[0][0])} ${fmtY(pts[0][1])} ${fmtX(pts[1][0])} ${fmtY(pts[1][1])} ${fmtX(pts[2][0])} ${fmtY(pts[2][1])}`)
3862
+ } else if (cmd === 'quadBezTo' && pts.length >= 2) {
3863
+ dParts.push(`Q ${fmtX(pts[0][0])} ${fmtY(pts[0][1])} ${fmtX(pts[1][0])} ${fmtY(pts[1][1])}`)
3864
+ }
3865
+ }
3866
+ }
3867
+
3868
+ if (dParts.length === 0) return null
3869
+ return {
3870
+ path: dParts.join(' '),
3871
+ viewBox: [targetW, targetH]
3872
+ }
3873
+ }
3874
+
3815
3875
  function extractPrimaryTextColorFromHtml(html: string | undefined | null): string | null {
3816
3876
  if (!html || typeof html !== 'string') return null
3817
3877
  const clean = html.replace(/<[^>]*>/g, '').replace(/&nbsp;/gi, '').trim()
@@ -4447,8 +4507,9 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
4447
4507
  const rawLineCap = el.borderLineCap || el.border?.lineCap || el.lineCap || (el.outline?.lineCap)
4448
4508
  const lineCap = (rawLineCap === 'rnd' || rawLineCap === 'round') ? 'round' : (rawLineCap === 'sq' || rawLineCap === 'square' ? 'square' : (rawLineCap === 'flat' ? 'flat' : undefined))
4449
4509
 
4510
+ const hasActualBorder = Boolean(outlineGrad || (el.borderWidth && el.borderWidth > 0))
4450
4511
  const outline: any = {
4451
- color: el.borderColor,
4512
+ color: hasActualBorder ? (el.borderColor || 'transparent') : 'transparent',
4452
4513
  width: +(el.borderWidth * ratio).toFixed(2),
4453
4514
  style: el.borderType,
4454
4515
  gradient: outlineGrad,
@@ -4507,7 +4568,7 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
4507
4568
  if (pattern) {
4508
4569
  element.style.pattern = pattern
4509
4570
  }
4510
- element.style.borderColor = el.borderColor || (el.outline?.color || 'transparent')
4571
+ element.style.borderColor = hasActualBorder ? (el.borderColor || (el.outline?.color || 'transparent')) : 'transparent'
4511
4572
  element.style.borderWidth = el.borderWidth !== undefined ? `${+(el.borderWidth * ratio).toFixed(2)}px` : (el.outline?.width !== undefined ? `${el.outline.width}px` : '0px')
4512
4573
  element.style.borderStyle = el.borderType || (el.outline?.style || 'solid')
4513
4574
  if (el.placeholderType === 'pic' && el.borderWidth > 0) element.style.enableBorder = true
@@ -6108,17 +6169,34 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6108
6169
  const clrMap: Record<string, string> = (zipMeta as any)?.clrMap || { bg1: 'lt1', tx1: 'dk1', bg2: 'lt2', tx2: 'dk2' }
6109
6170
  const resolveSchemeSlot = (v: string) => clrMap[v] || (v === 'tx1' ? 'dk1' : v === 'bg1' ? 'lt1' : v === 'tx2' ? 'dk2' : v === 'bg2' ? 'lt2' : v)
6110
6171
 
6172
+ const applyAlphaToHex = (hex: string, xmlFragment: string): string => {
6173
+ if (!hex || !hex.startsWith('#')) return hex
6174
+ const alphaM = xmlFragment.match(/<a:alpha\s+val="(\d+)"/)
6175
+ if (!alphaM) return hex
6176
+ const alphaVal = Math.max(0, Math.min(100000, parseInt(alphaM[1], 10))) / 100000
6177
+ if (alphaVal >= 0.999) return hex.slice(0, 7).toUpperCase()
6178
+ const alphaHex = Math.round(alphaVal * 255).toString(16).padStart(2, '0').toUpperCase()
6179
+ return `${hex.slice(0, 7).toUpperCase()}${alphaHex}`
6180
+ }
6181
+
6111
6182
  const parseSpGradFill = (gradXml: string): any => {
6112
6183
  const gsList = gradXml.match(/<a:gs\b[\s\S]*?<\/a:gs>/g) || []
6113
6184
  if (gsList.length === 0) return null
6114
- const colors: Array<{ pos: string; color: string }> = []
6115
- for (const gs of gsList) {
6185
+ const rawStops: Array<{ posNum: number; idx: number; color: string }> = []
6186
+ for (let gIdx = 0; gIdx < gsList.length; gIdx++) {
6187
+ const gs = gsList[gIdx]
6116
6188
  const posM = gs.match(/pos="(\d+)"/)
6117
6189
  const posVal = posM ? Math.round(parseInt(posM[1], 10) / 1000) : 0
6118
6190
  let col = '#FFFFFF'
6119
6191
  const srgbM = gs.match(/<a:srgbClr\s+val="([0-9A-Fa-f]{6})"/)
6120
6192
  if (srgbM) {
6121
- col = '#' + srgbM[1].toUpperCase()
6193
+ const lumModM = gs.match(/<a:lumMod val="(\d+)"/)
6194
+ const lumOffM = gs.match(/<a:lumOff val="(\d+)"/)
6195
+ const lumMod = lumModM ? parseInt(lumModM[1], 10) / 100000 : 1
6196
+ const lumOff = lumOffM ? parseInt(lumOffM[1], 10) / 100000 : 0
6197
+ const baseHex = '#' + srgbM[1].toUpperCase()
6198
+ col = (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(baseHex, lumMod, lumOff) : baseHex
6199
+ col = applyAlphaToHex(col, gs)
6122
6200
  } else {
6123
6201
  const schemeM = gs.match(/<a:schemeClr\s+val="([^"]+)"([\s\S]*?)<\/a:schemeClr>/) || gs.match(/<a:schemeClr\s+val="([^"]+)"\s*\/>/)
6124
6202
  if (schemeM) {
@@ -6131,10 +6209,16 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6131
6209
  const slot = resolveSchemeSlot(val)
6132
6210
  const baseHex = themeColors[slot] || themeColors[val] || (slot === 'dk1' || slot === 'tx1' ? '#000000' : '#FFFFFF')
6133
6211
  col = (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(baseHex, lumMod, lumOff) : baseHex
6212
+ col = applyAlphaToHex(col, inner)
6134
6213
  }
6135
6214
  }
6136
- colors.push({ pos: `${posVal}%`, color: col })
6215
+ rawStops.push({ posNum: posVal, idx: gIdx, color: col })
6137
6216
  }
6217
+ rawStops.sort((a, b) => a.posNum - b.posNum || a.idx - b.idx)
6218
+ const colors: Array<{ pos: string; color: string }> = rawStops.map(s => ({
6219
+ pos: `${s.posNum}%`,
6220
+ color: s.color
6221
+ }))
6138
6222
 
6139
6223
  const pathMatch = gradXml.match(/<a:path\b[^>]*path="([^"]+)"/i)
6140
6224
  const pathKind = pathMatch ? pathMatch[1].toLowerCase() : ''
@@ -6208,7 +6292,7 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6208
6292
  if (parsedG) return parsedG
6209
6293
  }
6210
6294
 
6211
- // 2. 提取单色填充元素(含子节点),便于读取 lumMod/lumOff
6295
+ // 2. 提取单色填充元素(含子节点),便于读取 lumMod/lumOff 与 alpha 透明度
6212
6296
  const fillEl = spXml.match(/<a:solidFill[^>]*>([\s\S]*?)<\/a:solidFill>/)
6213
6297
  if (fillEl) {
6214
6298
  const inner = fillEl[1]
@@ -6219,18 +6303,23 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6219
6303
  const srgb = inner.match(/<a:srgbClr val="([0-9A-Fa-f]{6})"/)
6220
6304
  if (srgb) {
6221
6305
  const hex = '#' + srgb[1].toUpperCase()
6222
- return (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6306
+ const adjusted = (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6307
+ return applyAlphaToHex(adjusted, inner)
6223
6308
  }
6224
6309
  const sys = inner.match(/<a:sysClr[^>]*lastClr="([0-9A-Fa-f]{6})"/)
6225
6310
  if (sys) {
6226
6311
  const hex = '#' + sys[1].toUpperCase()
6227
- return (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6312
+ const adjusted = (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6313
+ return applyAlphaToHex(adjusted, inner)
6228
6314
  }
6229
6315
  const schemeVal = (inner.match(/<a:schemeClr val="(\w+)"/) || [])[1]
6230
6316
  if (schemeVal) {
6231
6317
  const slot = resolveSchemeSlot(schemeVal)
6232
6318
  const hex = themeColors[slot] || themeColors[schemeVal] || ''
6233
- if (hex) return (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6319
+ if (hex) {
6320
+ const adjusted = (lumMod !== 1 || lumOff !== 0) ? applyLumAdjust(hex, lumMod, lumOff) : hex
6321
+ return applyAlphaToHex(adjusted, inner)
6322
+ }
6234
6323
  }
6235
6324
  }
6236
6325
  // p:style 里的主题填充引用(fillRef)
@@ -6385,42 +6474,108 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6385
6474
  } else {
6386
6475
  // 非占位符 sp = 版式/母版自带装饰元素,按真实样式还原
6387
6476
  const spPrXml = (sp.match(/<p:spPr[^>]*>[\s\S]*?<\/p:spPr>/) || [''])[0]
6388
- const resolved = resolveSpFill(spPrXml)
6477
+ // 剥离 <a:ln> 与 <a:effectLst> 再解析填充,防止将边框色或阴影色误识别为形状填充色
6478
+ const spPrNoLnXml = spPrXml
6479
+ .replace(/<a:ln\b[\s\S]*?<\/a:ln>/g, '')
6480
+ .replace(/<a:ln\b[^>]*\/>/g, '')
6481
+ .replace(/<a:effectLst\b[\s\S]*?<\/a:effectLst>/g, '')
6482
+ const hasExplicitNoFill = /<a:noFill\b/.test(spPrNoLnXml)
6483
+ let resolved = hasExplicitNoFill ? '' : resolveSpFill(spPrNoLnXml)
6484
+ if (!resolved && !hasExplicitNoFill) {
6485
+ const styleXml = (sp.match(/<p:style\b[\s\S]*?<\/p:style>/) || [''])[0]
6486
+ const fillRefXml = (styleXml.match(/<a:fillRef\b[^>]*>[\s\S]*?<\/a:fillRef>/) || [''])[0]
6487
+ if (fillRefXml && !/\bidx="0"/.test(fillRefXml)) {
6488
+ resolved = resolveSpFill(fillRefXml)
6489
+ }
6490
+ }
6389
6491
  const isGrad = resolved && typeof resolved === 'object'
6390
6492
  const fill = isGrad ? 'transparent' : (resolved || 'transparent')
6391
6493
  const gradient = isGrad ? resolved : undefined
6392
6494
 
6393
- // 解析装饰图元边框 <a:ln>
6495
+ // 解析旋转与翻转 (<a:xfrm rot="..." flipH="1" flipV="1">)
6496
+ const xfrmOpen = (spPrXml.match(/<a:xfrm\b[^>]*>/) || [''])[0]
6497
+ const rotM = xfrmOpen.match(/\brot="(-?\d+)"/)
6498
+ const rotate = rotM ? ((Math.round(parseInt(rotM[1], 10) / 60000) % 360) + 360) % 360 : 0
6499
+ const flipH = /\bflipH="(?:1|true)"/i.test(xfrmOpen)
6500
+ const flipV = /\bflipV="(?:1|true)"/i.test(xfrmOpen)
6501
+
6502
+ // 解析自定义几何路径 (<a:custGeom>) 或预设几何形状 (<a:prstGeom>)
6503
+ let shapePath: string | undefined = undefined
6504
+ let shapeViewBox: [number, number] | undefined = undefined
6505
+ let shapType: string = geom
6506
+ let pathFormula: string | undefined = undefined
6507
+ const custGeomMatch = spPrXml.match(/<a:custGeom\b[\s\S]*?<\/a:custGeom>/)
6508
+ if (custGeomMatch) {
6509
+ const parsedCust = parseCustGeomToSvgPath(custGeomMatch[0], pxWidth, pxHeight, cx, cy)
6510
+ if (parsedCust) {
6511
+ shapePath = parsedCust.path
6512
+ shapeViewBox = parsedCust.viewBox
6513
+ shapType = 'custom'
6514
+ }
6515
+ } else if (geom && geom !== 'rect' && geom !== 'ellipse') {
6516
+ const normGeom = geom.toLowerCase()
6517
+ for (const item of shapeList) {
6518
+ const itemPptxType = (item.pptxShapeType || '').toLowerCase()
6519
+ const itemFormula = (item.pathFormula || '').toLowerCase()
6520
+ if (itemPptxType === normGeom || itemFormula === normGeom) {
6521
+ if (item.pathFormula && shapeFormulas()[item.pathFormula]) {
6522
+ const formula = shapeFormulas()[item.pathFormula]
6523
+ const kps = formula.defaultValue ? [...formula.defaultValue] : []
6524
+ shapePath = formula.formula(pxWidth, pxHeight, kps)
6525
+ shapeViewBox = [pxWidth, pxHeight]
6526
+ pathFormula = item.pathFormula
6527
+ } else if (item.path) {
6528
+ shapePath = item.path
6529
+ shapeViewBox = item.viewBox || [200, 200]
6530
+ pathFormula = item.pathFormula
6531
+ }
6532
+ break
6533
+ }
6534
+ }
6535
+ }
6536
+
6537
+ // 解析装饰图元边框 <a:ln>(显式 <a:noFill/> 或无有效填充时严禁生成黑框)
6394
6538
  let outline: any = undefined
6395
6539
  let borderWidth = '0px'
6396
6540
  let borderColor = 'transparent'
6397
- const lnMatch = spPrXml.match(/<a:ln\b[^>]*>([\s\S]*?)<\/a:ln>/) || spPrXml.match(/<a:ln\b([^>]*)\/>/)
6398
- if (lnMatch) {
6541
+ const lnMatch = spPrXml.match(/<a:ln\b[^>]*>([\s\S]*?)<\/a:ln>/)
6542
+ if (lnMatch && !/<a:noFill\b/.test(lnMatch[0])) {
6399
6543
  const lnXml = lnMatch[0]
6400
- const wM = lnXml.match(/\bw="(\d+)"/)
6401
- const pxW = wM ? Math.max(1, Math.round(parseInt(wM[1], 10) / 9525)) : 1
6402
- borderWidth = `${pxW}px`
6403
6544
  const lnGradM = lnXml.match(/<a:gradFill\b[\s\S]*?<\/a:gradFill>/)
6404
6545
  const lnGrad = lnGradM ? parseSpGradFill(lnGradM[0]) : undefined
6405
6546
  const lnSolid = resolveSpFill(lnXml)
6406
- borderColor = typeof lnSolid === 'string' && lnSolid ? lnSolid : (lnGrad?.colors?.[0]?.color || '#333333')
6407
- outline = {
6408
- color: borderColor,
6409
- width: pxW,
6410
- style: 'solid',
6411
- gradient: lnGrad
6547
+ if (lnGrad || (typeof lnSolid === 'string' && lnSolid)) {
6548
+ const wM = lnXml.match(/\bw="(\d+)"/)
6549
+ const pxW = wM ? Math.max(1, Math.round(parseInt(wM[1], 10) / 9525)) : 1
6550
+ borderWidth = `${pxW}px`
6551
+ borderColor = typeof lnSolid === 'string' && lnSolid ? lnSolid : (lnGrad?.colors?.[0]?.color || 'transparent')
6552
+ outline = {
6553
+ color: borderColor,
6554
+ width: pxW,
6555
+ style: 'solid',
6556
+ gradient: lnGrad
6557
+ }
6412
6558
  }
6413
6559
  }
6414
6560
 
6415
6561
  elements.push({
6416
6562
  id: elId,
6417
6563
  type: textContent ? 'text' : 'shape',
6564
+ shapType,
6565
+ pathFormula,
6566
+ path: shapePath,
6567
+ viewBox: shapeViewBox,
6418
6568
  name: spName || (textContent ? (isMaster ? `母版文本 ${sIdx + 1}` : `版式文本 ${sIdx + 1}`) : (isMaster ? `母版装饰 ${sIdx + 1}` : `版式装饰 ${sIdx + 1}`)),
6419
6569
  left: pxLeft,
6420
6570
  top: pxTop,
6421
6571
  width: pxWidth,
6422
6572
  height: pxHeight,
6423
- content: textContent ? `<div>${textContent}</div>` : '',
6573
+ rotate,
6574
+ flipH,
6575
+ flipV,
6576
+ isFlipH: flipH,
6577
+ isFlipV: flipV,
6578
+ content: textContent ? `<div>${textContent}</div>` : (shapePath || ''),
6424
6579
  fill,
6425
6580
  gradient,
6426
6581
  outline,
@@ -6430,12 +6585,15 @@ const parsePPTXJSONData = (json: any, zipMeta?: any) => {
6430
6585
  top: `${pxTop}px`,
6431
6586
  width: `${pxWidth}px`,
6432
6587
  height: `${pxHeight}px`,
6433
- borderRadius: geom === 'ellipse' ? '50%' : (geom === 'roundRect' ? '8px' : '0px'),
6588
+ rotate,
6589
+ flipH,
6590
+ flipV,
6591
+ borderRadius: geom === 'ellipse' ? '50%' : (geom === 'roundRect' && !shapePath ? '8px' : '0px'),
6434
6592
  fill,
6435
6593
  color: '#333333',
6436
6594
  textAlign: 'center',
6437
6595
  borderColor: outline?.gradient ? 'transparent' : borderColor,
6438
- borderWidth: outline ? borderWidth : undefined,
6596
+ borderWidth: outline ? borderWidth : '0px',
6439
6597
  borderStyle: outline ? 'solid' : undefined,
6440
6598
  borderGradient: outline?.gradient
6441
6599
  },