jvs-ppt-ui 0.0.32 → 0.0.33

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/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.33",
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
  ],
@@ -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
  },
@@ -5,6 +5,7 @@ import { useSlides } from '../composables/useSlides'
5
5
  import {
6
6
  fetchAndConvertPitchTemplate,
7
7
  normalizePitchTemplateUrl,
8
+ stringifyDeckToBlob,
8
9
  PITCH_LAYOUT_CATEGORIES
9
10
  } from '../utils/pitchConverter'
10
11
 
@@ -26,6 +27,7 @@ const templateUrl = ref(DEFAULT_DEMO_URL)
26
27
  const rawJsonText = ref('')
27
28
  const selectedCategory = ref('all')
28
29
  const isLoading = ref(false)
30
+ const progressText = ref('')
29
31
  const errorMsg = ref('')
30
32
 
31
33
  const isLayoutLibraryUrl = computed(() => {
@@ -70,26 +72,32 @@ async function runConvert(action: 'import' | 'download') {
70
72
  }
71
73
 
72
74
  isLoading.value = true
75
+ progressText.value = '正在拉取并解析模板...'
73
76
  try {
74
77
  const deck = await fetchAndConvertPitchTemplate(source, {
75
- categoryFilter: isLayoutLibraryUrl.value ? selectedCategory.value : 'all'
78
+ categoryFilter: isLayoutLibraryUrl.value ? selectedCategory.value : 'all',
79
+ convertMediaToBase64: true,
80
+ onProgress: (done, total) => {
81
+ progressText.value = `正在转换图片/音视频为 Base64 (${done}/${total})...`
82
+ }
76
83
  })
77
84
  if (action === 'download') {
78
- const blob = new Blob([JSON.stringify(deck, null, 2)], { type: 'application/json;charset=utf-8' })
85
+ const blob = stringifyDeckToBlob(deck)
79
86
  saveAs(blob, `${deck.title || 'pitch-template'}.json`)
80
- notify(`已转换并下载 "${deck.title}"(共 ${deck.slides.length} 页,${deck.styleRecipes.length} 套主题)`)
87
+ notify(`已转换并下载 "${deck.title}"(共 ${deck.slides.length} 页,${deck.styleRecipes.length} 套主题,媒体已转 Base64)`)
81
88
  } else {
82
89
  importSlides(deck)
83
90
  if (deck.title) {
84
91
  presentationTitle.value = deck.title
85
92
  }
86
- notify(`成功导入 "${deck.title}"(共 ${deck.slides.length} 页,${deck.styleRecipes.length} 套主题)`)
93
+ notify(`成功导入 "${deck.title}"(共 ${deck.slides.length} 页,${deck.styleRecipes.length} 套主题,媒体已转 Base64)`)
87
94
  emit('update:visible', false)
88
95
  }
89
96
  } catch (err: any) {
90
97
  errorMsg.value = err?.message || '转换失败,请检查模板地址或数据格式'
91
98
  } finally {
92
99
  isLoading.value = false
100
+ progressText.value = ''
93
101
  }
94
102
  }
95
103
  </script>
@@ -162,6 +170,7 @@ async function runConvert(action: 'import' | 'download') {
162
170
  <div class="tip-title">支持自动转换的内容:</div>
163
171
  <ul>
164
172
  <li>单模板 (<code>templates/&lt;uuid&gt;</code>) 与全量官方版式库 (<code>key-layouts.transit</code> 共 9 大类 149 套版式)</li>
173
+ <li>图片、视频、音频及背景图资源自动并发拉取并内联为 <code>Base64 DataURL</code>,便于离线下载与服务端持久化</li>
165
174
  <li>Cognitect Transit-JSON 缓存表解码(<code>["^ ", ...]</code> 与 <code>^xx</code> 字典还原)及 <code>group</code> 组合容器</li>
166
175
  <li>内嵌主题配方(<code>StyleRecipe</code> 字体、字号比例、色板、表格与图表配色)</li>
167
176
  <li>归一化坐标映射到 <code>1280 × 720</code> 画布、背景图去重、人像裁切对焦与线性渐变形状</li>
@@ -185,6 +194,10 @@ async function runConvert(action: 'import' | 'download') {
185
194
  ></textarea>
186
195
  </div>
187
196
 
197
+ <div v-if="isLoading && progressText" class="progress-banner">
198
+ {{ progressText }}
199
+ </div>
200
+
188
201
  <div v-if="errorMsg" class="error-banner">
189
202
  {{ errorMsg }}
190
203
  </div>
@@ -202,7 +215,7 @@ async function runConvert(action: 'import' | 'download') {
202
215
  :disabled="isLoading"
203
216
  @click="runConvert('download')"
204
217
  >
205
- {{ isLoading ? '处理中...' : '转换并下载 JSON' }}
218
+ {{ isLoading ? (progressText || '处理中...') : '转换并下载 JSON' }}
206
219
  </button>
207
220
  <button
208
221
  type="button"
@@ -210,7 +223,7 @@ async function runConvert(action: 'import' | 'download') {
210
223
  :disabled="isLoading"
211
224
  @click="runConvert('import')"
212
225
  >
213
- {{ isLoading ? '正在拉取并转换...' : '拉取并转换导入' }}
226
+ {{ isLoading ? (progressText || '正在拉取并转换...') : '拉取并转换导入' }}
214
227
  </button>
215
228
  </div>
216
229
  </div>
@@ -386,6 +399,16 @@ async function runConvert(action: 'import' | 'download') {
386
399
  padding-left: 18px;
387
400
  }
388
401
 
402
+ .progress-banner {
403
+ padding: 8px 12px;
404
+ background: #eff6ff;
405
+ border: 1px solid #bfdbfe;
406
+ border-radius: 6px;
407
+ color: #1d4ed8;
408
+ font-size: 12px;
409
+ font-weight: 500;
410
+ }
411
+
389
412
  .error-banner {
390
413
  padding: 8px 12px;
391
414
  background: #fef2f2;
@@ -4,6 +4,7 @@ import jvsPickerColorV3 from 'jvs-picker-color-v3'
4
4
  import '../assets/iconfont/iconfont.js'
5
5
  import '../../public/jvs-ppt-ui/fonts/fonts.css'
6
6
  import { saveAs } from 'file-saver'
7
+ import { stringifyDeckToBlob } from '../utils/pitchConverter'
7
8
  import Header from './Header.vue'
8
9
  import Toolbar from './Toolbar.vue'
9
10
  import SidebarLeft from './SidebarLeft.vue'
@@ -28,6 +29,7 @@ if (currentApp) {
28
29
  }
29
30
 
30
31
  import { useSlides } from '../composables/useSlides'
32
+ import { builtinSlideTemplates, setCustomTemplates, addCustomTemplate } from '../configs/slideTemplates'
31
33
  import type { Slide, SlideMaster, DeckData, PptEditorProps, PptEditorApi, SaveOptions, LoadSourceOptions, LoadSourceResult } from '../types'
32
34
 
33
35
  const props = withDefaults(defineProps<PptEditorProps>(), {
@@ -50,6 +52,11 @@ const props = withDefaults(defineProps<PptEditorProps>(), {
50
52
  materialTypeApiUrl: '',
51
53
  materialSaveApiUrl: '',
52
54
  materialHeaders: () => ({}),
55
+ enableTemplate: undefined,
56
+ enableTemplates: undefined,
57
+ templates: undefined,
58
+ templateBaseUrl: '',
59
+ replaceBuiltinTemplates: undefined,
53
60
  config: () => ({})
54
61
  })
55
62
 
@@ -104,6 +111,8 @@ const {
104
111
  isAiBeautifyEnabled,
105
112
  setMaterialConfig,
106
113
  isMaterialEnabled,
114
+ setTemplateConfig,
115
+ isTemplateEnabled,
107
116
  saveCurrentSlideToMaterial,
108
117
  isCanvasDragging,
109
118
  pauseHistory,
@@ -211,6 +220,44 @@ watch(
211
220
  { immediate: true }
212
221
  )
213
222
 
223
+ // 监听外部传入的模板库相关配置(优先 props,次选 config 对象)
224
+ watch(
225
+ [
226
+ () => props.enableTemplate,
227
+ () => props.enableTemplates,
228
+ () => props.config?.enableTemplate,
229
+ () => props.config?.enableTemplates,
230
+ () => props.templates,
231
+ () => props.config?.templates,
232
+ () => props.templateBaseUrl,
233
+ () => props.config?.templateBaseUrl,
234
+ () => props.replaceBuiltinTemplates,
235
+ () => props.config?.replaceBuiltinTemplates
236
+ ],
237
+ () => {
238
+ const rawEnable = props.enableTemplate !== undefined
239
+ ? props.enableTemplate
240
+ : (props.enableTemplates !== undefined
241
+ ? props.enableTemplates
242
+ : (props.config?.enableTemplate !== undefined
243
+ ? props.config.enableTemplate
244
+ : props.config?.enableTemplates))
245
+ const templates = props.templates !== undefined ? props.templates : props.config?.templates
246
+ const baseUrl = props.templateBaseUrl || props.config?.templateBaseUrl || ''
247
+ const replaceBuiltin = props.replaceBuiltinTemplates !== undefined
248
+ ? props.replaceBuiltinTemplates
249
+ : props.config?.replaceBuiltinTemplates
250
+
251
+ setTemplateConfig({
252
+ enable: rawEnable !== undefined ? Boolean(rawEnable) : true,
253
+ templates,
254
+ baseUrl,
255
+ replaceBuiltin
256
+ })
257
+ },
258
+ { immediate: true, deep: true }
259
+ )
260
+
214
261
  // 初始化标题
215
262
  if (props.config?.title) {
216
263
  presentationTitle.value = props.config.title
@@ -276,7 +323,7 @@ const headerRef = ref<any>(null)
276
323
  */
277
324
  function getSaveJsonBlob(): Blob {
278
325
  const deck = getDeck()
279
- return new Blob([JSON.stringify(deck, null, 2)], { type: 'application/json' })
326
+ return stringifyDeckToBlob(deck as any)
280
327
  }
281
328
 
282
329
  /**
@@ -877,6 +924,11 @@ const editorApi: PptEditorApi = {
877
924
  saveMaterial: (meta) => saveCurrentSlideToMaterial(meta),
878
925
  setCustomUploadHandler,
879
926
  getCustomUploadHandler,
927
+ setTemplateConfig,
928
+ setTemplates: (templates, options) => setCustomTemplates(templates, options),
929
+ addTemplate: (template) => addCustomTemplate(template),
930
+ getTemplates: () => [...builtinSlideTemplates],
931
+ isTemplateEnabled,
880
932
  slidesComposable: slidesState
881
933
  }
882
934