jvs-ppt-ui 0.0.35 → 0.0.37

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 (61) hide show
  1. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.css +7 -3
  2. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.js +1 -1
  3. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.json +7 -0
  4. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.ttf +0 -0
  5. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.woff +0 -0
  6. package/dist/lib/jvs-ppt-ui/iconfont/iconfont.woff2 +0 -0
  7. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_01de32e3d01df54a.svg +9 -0
  8. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_12935f21f0b1ae78.png +0 -0
  9. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_201146e666f28fff.png +0 -0
  10. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_32ef4f2c1d76ea32.svg +15 -0
  11. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_571054b13f220252.svg +10 -0
  12. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_5b14f99769a8894c.svg +10 -0
  13. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_62fc021bdae89b21.png +0 -0
  14. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_649d2b36f7fc251e.png +0 -0
  15. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_7e57de8ea8d46aba.png +0 -0
  16. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_9ad1284e63535689.svg +15 -0
  17. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_9ff268d3709d6454.png +0 -0
  18. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_b8f80ac591d69945.png +0 -0
  19. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_dce239981c2cd1aa.svg +15 -0
  20. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_e2ea31ca7735e5c0.png +0 -0
  21. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_e585ddb9ec5c408e.png +0 -0
  22. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_f3335fad3673d648.svg +10 -0
  23. package/dist/lib/jvs-ppt-ui/layout-library/layout-image/img_fb925327432cc7e7.svg +15 -0
  24. package/dist/lib/jvs-ppt-ui/layout-library/layout-library.json +1 -0
  25. package/dist/lib/jvs-ppt-ui.es.js +81545 -23219
  26. package/dist/lib/jvs-ppt-ui.umd.js +113 -112
  27. package/dist/lib/style.css +1 -1
  28. package/package.json +1 -1
  29. package/scripts/patch-pptxtojson.cjs +33 -0
  30. package/src/assets/chart/baseArea.png +0 -0
  31. package/src/assets/chart/baseBar.png +0 -0
  32. package/src/assets/chart/baseHistogram.png +0 -0
  33. package/src/assets/chart/basePie.png +0 -0
  34. package/src/assets/chart/bubbleChart.png +0 -0
  35. package/src/assets/chart/circyChart.png +0 -0
  36. package/src/assets/chart/compPolyline.png +0 -0
  37. package/src/assets/chart/lineChart.png +0 -0
  38. package/src/assets/chart/otherLine.png +0 -0
  39. package/src/assets/chart/otherLineChart.png +0 -0
  40. package/src/assets/chart/perHistogram.png +0 -0
  41. package/src/assets/chart/radarChart.png +0 -0
  42. package/src/assets/chart/roseChart.png +0 -0
  43. package/src/assets/chart/roseCircyChart.png +0 -0
  44. package/src/assets/chart/stackArea.png +0 -0
  45. package/src/assets/chart/stackBar.png +0 -0
  46. package/src/assets/chart/stackHistogram.png +0 -0
  47. package/src/assets/iconfont/iconfont.js +1 -1
  48. package/src/components/CanvasArea.vue +26 -13
  49. package/src/components/ChartTypeSelector.vue +15 -67
  50. package/src/components/Header.vue +10 -7
  51. package/src/components/SidebarLeft.vue +382 -30
  52. package/src/components/SidebarRight.vue +39 -1
  53. package/src/components/sidebar/panels/LayoutThumbSvg.vue +82 -14
  54. package/src/components/sidebar/panels/SidebarChartFormatPanel.vue +676 -3
  55. package/src/composables/sidebar/useSidebarChart.ts +88 -39
  56. package/src/composables/useSlides.ts +245 -25
  57. package/src/configs/layoutLibrary.ts +113 -0
  58. package/src/style.css +107 -17
  59. package/src/utils/pptxAnimationInjector.ts +36 -4
  60. package/src/assets/chart/baseMap.png +0 -0
  61. package/src/assets/chart/boxplot.png +0 -0
@@ -1,4 +1,4 @@
1
- import { ref, computed, type ComputedRef } from 'vue'
1
+ import { ref, computed, watch, type ComputedRef } from 'vue'
2
2
  import { generateMonoPalette } from '../../utils/palette'
3
3
 
4
4
  export const CHART_PRESET_PALETTES = [
@@ -22,6 +22,7 @@ export function useSidebarChart(
22
22
  selectedElement: ComputedRef<any>,
23
23
  addHistorySnapshot: () => void
24
24
  ) {
25
+ const chartActiveTab = ref<'chart' | 'data'>('chart')
25
26
  const chartDataDialogVisible = ref(false)
26
27
  const tempChartDataText = ref('')
27
28
  const tempChartLabels = ref<string[]>([])
@@ -181,19 +182,92 @@ export function useSidebarChart(
181
182
  return getDefaultStructuredData(el)
182
183
  }
183
184
 
185
+ let isApplyingChartData = false
186
+
187
+ function applyChartDataToElement() {
188
+ if (!selectedElement.value || selectedElement.value.type !== 'chart') return
189
+ isApplyingChartData = true
190
+ try {
191
+ const cleanLabels: string[] = []
192
+ const cleanDatasets: ChartDatasetItem[] = tempChartDatasets.value.map((ds, idx) => ({
193
+ label: (ds.label || '').trim() || `系列${idx + 1}`,
194
+ data: []
195
+ }))
196
+
197
+ tempChartLabels.value.forEach((lbl, rIdx) => {
198
+ const trimmed = (lbl || '').trim()
199
+ const hasAnyValue = tempChartDatasets.value.some(ds => ds.data[rIdx] !== undefined && !isNaN(Number(ds.data[rIdx])))
200
+ if (trimmed || hasAnyValue) {
201
+ cleanLabels.push(trimmed || `分类${cleanLabels.length + 1}`)
202
+ tempChartDatasets.value.forEach((ds, sIdx) => {
203
+ const num = Number(ds.data[rIdx])
204
+ cleanDatasets[sIdx].data.push(isNaN(num) ? 0 : num)
205
+ })
206
+ }
207
+ })
208
+
209
+ if (cleanLabels.length > 0 && cleanDatasets.length > 0) {
210
+ selectedElement.value.data = {
211
+ labels: cleanLabels,
212
+ datasets: cleanDatasets
213
+ }
214
+ }
215
+ addHistorySnapshot()
216
+ } finally {
217
+ isApplyingChartData = false
218
+ }
219
+ }
220
+
221
+ function loadChartDataFromElement(el: any) {
222
+ if (!el || el.type !== 'chart' || isApplyingChartData) return
223
+ const { labels, datasets } = extractStructuredData(el)
224
+ tempChartLabels.value = labels
225
+ tempChartDatasets.value = datasets
226
+ previewChartType.value = el.chartType || 'bar'
227
+ const labelsVal = tempChartLabels.value
228
+ const datasetsVal = tempChartDatasets.value
229
+ if (!labelsVal.length || !datasetsVal.length) {
230
+ tempChartDataText.value = ''
231
+ } else {
232
+ tempChartDataText.value = labelsVal
233
+ .map((l, rIdx) => {
234
+ const vals = datasetsVal.map(ds => (ds.data[rIdx] !== undefined ? ds.data[rIdx] : 0))
235
+ return [l, ...vals].join(', ')
236
+ })
237
+ .join('\n')
238
+ }
239
+ }
240
+
241
+ watch(
242
+ [() => selectedElement.value?.id, () => selectedElement.value?.chartType],
243
+ () => {
244
+ if (selectedElement.value?.type === 'chart') {
245
+ loadChartDataFromElement(selectedElement.value)
246
+ }
247
+ },
248
+ { immediate: true }
249
+ )
250
+
251
+ watch(chartActiveTab, (tab) => {
252
+ if (tab === 'data' && selectedElement.value?.type === 'chart') {
253
+ loadChartDataFromElement(selectedElement.value)
254
+ }
255
+ })
256
+
184
257
  function syncStructuredToText() {
185
258
  const labels = tempChartLabels.value
186
259
  const datasets = tempChartDatasets.value
187
260
  if (!labels.length || !datasets.length) {
188
261
  tempChartDataText.value = ''
189
- return
262
+ } else {
263
+ tempChartDataText.value = labels
264
+ .map((l, rIdx) => {
265
+ const vals = datasets.map(ds => (ds.data[rIdx] !== undefined ? ds.data[rIdx] : 0))
266
+ return [l, ...vals].join(', ')
267
+ })
268
+ .join('\n')
190
269
  }
191
- tempChartDataText.value = labels
192
- .map((l, rIdx) => {
193
- const vals = datasets.map(ds => (ds.data[rIdx] !== undefined ? ds.data[rIdx] : 0))
194
- return [l, ...vals].join(', ')
195
- })
196
- .join('\n')
270
+ applyChartDataToElement()
197
271
  }
198
272
 
199
273
  function syncTextToStructured(text: string) {
@@ -225,6 +299,7 @@ export function useSidebarChart(
225
299
  label: tempChartDatasets.value[idx]?.label || `系列${idx + 1}`,
226
300
  data: labels.map((_, rIdx) => vals[rIdx] ?? 0)
227
301
  }))
302
+ applyChartDataToElement()
228
303
  }
229
304
  }
230
305
 
@@ -280,13 +355,9 @@ export function useSidebarChart(
280
355
 
281
356
  function openChartDataDialog() {
282
357
  if (selectedElement.value) {
283
- const { labels, datasets } = extractStructuredData(selectedElement.value)
284
- tempChartLabels.value = labels
285
- tempChartDatasets.value = datasets
286
- previewChartType.value = selectedElement.value.chartType || 'bar'
358
+ loadChartDataFromElement(selectedElement.value)
287
359
  chartEditMode.value = 'table'
288
- syncStructuredToText()
289
- chartDataDialogVisible.value = true
360
+ chartActiveTab.value = 'data'
290
361
  }
291
362
  }
292
363
 
@@ -294,40 +365,18 @@ export function useSidebarChart(
294
365
  if (selectedElement.value) {
295
366
  if (chartEditMode.value === 'csv') {
296
367
  syncTextToStructured(tempChartDataText.value)
297
- }
298
- const cleanLabels: string[] = []
299
- const cleanDatasets: ChartDatasetItem[] = tempChartDatasets.value.map((ds, idx) => ({
300
- label: (ds.label || '').trim() || `系列${idx + 1}`,
301
- data: []
302
- }))
303
-
304
- tempChartLabels.value.forEach((lbl, rIdx) => {
305
- const trimmed = (lbl || '').trim()
306
- const hasAnyValue = tempChartDatasets.value.some(ds => ds.data[rIdx] !== undefined && !isNaN(Number(ds.data[rIdx])))
307
- if (trimmed || hasAnyValue) {
308
- cleanLabels.push(trimmed || `分类${cleanLabels.length + 1}`)
309
- tempChartDatasets.value.forEach((ds, sIdx) => {
310
- const num = Number(ds.data[rIdx])
311
- cleanDatasets[sIdx].data.push(isNaN(num) ? 0 : num)
312
- })
313
- }
314
- })
315
-
316
- if (cleanLabels.length > 0 && cleanDatasets.length > 0) {
317
- selectedElement.value.data = {
318
- labels: cleanLabels,
319
- datasets: cleanDatasets
320
- }
368
+ } else {
369
+ applyChartDataToElement()
321
370
  }
322
371
  if (previewChartType.value && selectedElement.value.chartType !== previewChartType.value) {
323
372
  selectedElement.value.chartType = previewChartType.value
324
373
  }
325
- addHistorySnapshot()
326
374
  chartDataDialogVisible.value = false
327
375
  }
328
376
  }
329
377
 
330
378
  return {
379
+ chartActiveTab,
331
380
  chartDataDialogVisible,
332
381
  tempChartDataText,
333
382
  tempChartLabels,
@@ -1349,7 +1349,12 @@ function applyPresetTheme(preset: PresetTheme) {
1349
1349
  el.textColor = preset.fontColor
1350
1350
  el.color = preset.fontColor
1351
1351
  if (el.content) {
1352
- el.content = el.content.replace(/color\s*:\s*[^;"]+;?/gi, '').replace(/(?:--ppt-)?font-family\s*:\s*[^;"]+;?/gi, '')
1352
+ el.content = el.content
1353
+ .replace(/color\s*:\s*[^;"]+;?/gi, '')
1354
+ .replace(/(?:--ppt-)?font-family\s*:\s*[^;"]+;?/gi, '')
1355
+ .replace(/\s*style="\s*;?\s*"/gi, '')
1356
+ .replace(/style="\s+/gi, 'style="')
1357
+ .replace(/\s+"/gi, '"')
1353
1358
  }
1354
1359
  }
1355
1360
  if (el.type === 'shape') {
@@ -1597,7 +1602,12 @@ export function recolorElementsWithRecipe(elements: any[], recipe: StyleRecipe)
1597
1602
  if (cfg.letterSpacing !== undefined) el.style.letterSpacing = `${cfg.letterSpacing}px`
1598
1603
 
1599
1604
  if (el.content) {
1600
- el.content = el.content.replace(/color\s*:\s*[^;"]+;?/gi, '').replace(/(?:--ppt-)?font-family\s*:\s*[^;"]+;?/gi, '')
1605
+ el.content = el.content
1606
+ .replace(/color\s*:\s*[^;"]+;?/gi, '')
1607
+ .replace(/(?:--ppt-)?font-family\s*:\s*[^;"]+;?/gi, '')
1608
+ .replace(/\s*style="\s*;?\s*"/gi, '')
1609
+ .replace(/style="\s+/gi, 'style="')
1610
+ .replace(/\s+"/gi, '"')
1601
1611
  }
1602
1612
 
1603
1613
  // 处理超链接元素或 <a> 标签的链接颜色与下划线 (linkUnderline)
@@ -1662,8 +1672,10 @@ export function recolorElementsWithRecipe(elements: any[], recipe: StyleRecipe)
1662
1672
  if (typeof el.text.content === 'string' && el.text.content.includes('<')) {
1663
1673
  const div = document.createElement('div')
1664
1674
  div.innerHTML = el.text.content
1665
- div.querySelectorAll('span, p, font, td, th').forEach((child: any) => {
1675
+ div.querySelectorAll('div, span, p, font, td, th').forEach((child: any) => {
1666
1676
  child.style.color = textColor
1677
+ child.style.removeProperty('font-family')
1678
+ child.style.removeProperty('--ppt-font-family')
1667
1679
  })
1668
1680
  el.text.content = div.innerHTML
1669
1681
  }
@@ -1671,16 +1683,20 @@ export function recolorElementsWithRecipe(elements: any[], recipe: StyleRecipe)
1671
1683
  if (el.text && typeof el.text === 'string' && el.text.includes('<')) {
1672
1684
  const div = document.createElement('div')
1673
1685
  div.innerHTML = el.text
1674
- div.querySelectorAll('span, p, font, td, th').forEach((child: any) => {
1686
+ div.querySelectorAll('div, span, p, font, td, th').forEach((child: any) => {
1675
1687
  child.style.color = textColor
1688
+ child.style.removeProperty('font-family')
1689
+ child.style.removeProperty('--ppt-font-family')
1676
1690
  })
1677
1691
  el.text = div.innerHTML
1678
1692
  }
1679
1693
  if (el.content && typeof el.content === 'string' && el.content.includes('<')) {
1680
1694
  const div = document.createElement('div')
1681
1695
  div.innerHTML = el.content
1682
- div.querySelectorAll('span, p, font, td, th').forEach((child: any) => {
1696
+ div.querySelectorAll('div, span, p, font, td, th').forEach((child: any) => {
1683
1697
  child.style.color = textColor
1698
+ child.style.removeProperty('font-family')
1699
+ child.style.removeProperty('--ppt-font-family')
1684
1700
  })
1685
1701
  el.content = div.innerHTML
1686
1702
  }
@@ -2327,6 +2343,28 @@ function getThemeUsageLabel(themeId: string): { type: 'all' | 'partial' | 'none'
2327
2343
  return { type: 'none', text: '未被使用', fullText: '未被使用', pages: [] }
2328
2344
  }
2329
2345
 
2346
+ function isHexOrRgbDark(colorStr?: string): boolean {
2347
+ if (!colorStr || typeof colorStr !== 'string') return false
2348
+ const s = colorStr.trim().toLowerCase()
2349
+ const hexMatch = s.match(/#([0-9a-f]{3,8})\b/i)
2350
+ if (hexMatch) {
2351
+ let hex = hexMatch[1]
2352
+ if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
2353
+ const r = parseInt(hex.slice(0, 2), 16)
2354
+ const g = parseInt(hex.slice(2, 4), 16)
2355
+ const b = parseInt(hex.slice(4, 6), 16)
2356
+ return ((0.299 * r + 0.587 * g + 0.114 * b) / 255) < 0.58
2357
+ }
2358
+ const rgbMatch = s.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i)
2359
+ if (rgbMatch) {
2360
+ const r = parseInt(rgbMatch[1], 10)
2361
+ const g = parseInt(rgbMatch[2], 10)
2362
+ const b = parseInt(rgbMatch[3], 10)
2363
+ return ((0.299 * r + 0.587 * g + 0.114 * b) / 255) < 0.58
2364
+ }
2365
+ return false
2366
+ }
2367
+
2330
2368
  function getActiveSlideThemeRecipe(targetSlide?: any): StyleRecipe {
2331
2369
  let effSlide: Slide | null = null
2332
2370
  if (targetSlide && targetSlide.elements) {
@@ -2336,9 +2374,125 @@ function getActiveSlideThemeRecipe(targetSlide?: any): StyleRecipe {
2336
2374
  } else if (activeSlide.value) {
2337
2375
  effSlide = activeSlide.value
2338
2376
  }
2339
- const themeId = effSlide?.themeId || (isMasterEditingView.value ? ((slideMasters.value.find(m => m.id === activeMasterId.value) as any)?.themeId || 'tech-blue') : 'tech-blue')
2340
- const recipe = builtinStyleRecipes.find(r => r.id === themeId || (themeId === 'default-recipe' && r.id === 'tech-blue')) || defaultStyleRecipe
2341
- return recipe
2377
+
2378
+ const resolved = effSlide ? resolveSlideMasterAndLayout(effSlide) : { masterId: activeMasterId.value, layoutId: '' }
2379
+ const master = slideMasters.value.find(m => m && m.id === (isMasterEditingView.value ? activeMasterId.value : resolved.masterId)) || slideMasters.value[0]
2380
+ const rawThemeId = isMasterEditingView.value
2381
+ ? ((master as any)?.themeId || effSlide?.themeId || 'tech-blue')
2382
+ : (effSlide?.themeId || (master as any)?.themeId || 'tech-blue')
2383
+
2384
+ const matched = builtinStyleRecipes.find(
2385
+ r => r.id === rawThemeId || (rawThemeId === 'default-recipe' && r.id === 'tech-blue')
2386
+ )
2387
+ if (matched) {
2388
+ return matched
2389
+ }
2390
+
2391
+ // 若当前幻灯片来自外部模板/导入页面且其 themeId 未注册在 builtinStyleRecipes 中,
2392
+ // 动态从当前幻灯片(及同主题/同母版页面)提取真实主题色生成 StyleRecipe,保证版式库与母版版式实时跟随当前幻灯片配色
2393
+ if (effSlide) {
2394
+ const rawBg = effSlide.background || master?.background || '#ffffff'
2395
+ const bgStr = (typeof rawBg === 'string' && !rawBg.includes('url(') && !rawBg.includes('gradient('))
2396
+ ? rawBg
2397
+ : (typeof (rawBg as any)?.color === 'string' ? (rawBg as any).color : '#ffffff')
2398
+ const isDark = isHexOrRgbDark(bgStr)
2399
+
2400
+ const textColors: Partial<Record<SlideTextType, string>> = {}
2401
+ let detectedShapeFill = ''
2402
+ let detectedFont = master?.fontFamily ? master.fontFamily.replace(/['"]/g, '').split(',')[0].trim() : 'SourceHanSansCN'
2403
+
2404
+ const peerSlides = [
2405
+ effSlide,
2406
+ ...(slides.value || []).filter(s => s && s !== effSlide && (
2407
+ (effSlide.themeId && s.themeId === effSlide.themeId) ||
2408
+ (effSlide.masterId && s.masterId === effSlide.masterId)
2409
+ ))
2410
+ ]
2411
+
2412
+ const inspectElements = (els: any[]) => {
2413
+ for (const el of els || []) {
2414
+ if (!el || typeof el !== 'object') continue
2415
+ if (el.type === 'text') {
2416
+ const c = el.style?.color || el.color || el.style?.textColor
2417
+ if (typeof c === 'string' && c !== 'transparent' && c !== 'none') {
2418
+ const tType: SlideTextType = el.textType ? normalizeTextType(el.textType) : inferElementTextType(el)
2419
+ if (!textColors[tType]) textColors[tType] = c
2420
+ }
2421
+ const f = el.style?.fontFamily || el.fontFamily
2422
+ if (typeof f === 'string' && f && detectedFont === 'SourceHanSansCN') {
2423
+ detectedFont = f.replace(/['"]/g, '').split(',')[0].trim() || 'SourceHanSansCN'
2424
+ }
2425
+ } else if (el.type === 'shape' && !detectedShapeFill) {
2426
+ const fill = el.style?.fill || el.fill
2427
+ if (typeof fill === 'string' && fill !== 'none' && fill !== 'transparent' && fill.toLowerCase() !== bgStr.toLowerCase()) {
2428
+ detectedShapeFill = fill
2429
+ }
2430
+ } else if (el.type === 'group' && Array.isArray(el.elements)) {
2431
+ inspectElements(el.elements)
2432
+ }
2433
+ }
2434
+ }
2435
+
2436
+ for (const s of peerSlides) {
2437
+ if (Array.isArray(s?.elements)) inspectElements(s.elements)
2438
+ }
2439
+
2440
+ const titleColor = textColors.title || textColors.headline || (isDark ? '#ffffff' : '#0f172a')
2441
+ const headlineColor = textColors.headline || titleColor
2442
+ const normalColor = textColors.normalText || textColors.smallText || textColors.subheadline || (isDark ? '#e2e8f0' : '#334155')
2443
+ const subheadlineColor = textColors.subheadline || headlineColor || normalColor
2444
+ const smallColor = textColors.smallText || normalColor
2445
+ const accentColor = (titleColor.toLowerCase() !== normalColor.toLowerCase() && titleColor.toLowerCase() !== bgStr.toLowerCase())
2446
+ ? titleColor
2447
+ : (detectedShapeFill || master?.themeColors?.[0] || '#2563eb')
2448
+ const shapeFill = detectedShapeFill || accentColor
2449
+ const shapeText = isHexOrRgbDark(shapeFill) ? '#ffffff' : '#0f172a'
2450
+ const palette = Array.isArray(master?.themeColors) && master.themeColors.length > 0
2451
+ ? [...master.themeColors]
2452
+ : [accentColor, titleColor, subheadlineColor, normalColor, smallColor, bgStr]
2453
+
2454
+ return {
2455
+ ...defaultStyleRecipe,
2456
+ id: rawThemeId || `slide-derived-${effSlide.id}`,
2457
+ name: (effSlide as any).themeName || (master as any)?.themeName || '当前页面主题',
2458
+ styleColors: palette,
2459
+ styleFonts: {
2460
+ titleFont: detectedFont,
2461
+ bodyFont: detectedFont
2462
+ },
2463
+ backgroundColor: bgStr,
2464
+ bulletPointsColor: accentColor,
2465
+ linkColor: accentColor,
2466
+ textStyles: {
2467
+ title: { ...defaultStyleRecipe.textStyles.title, color: titleColor, fontFamily: detectedFont },
2468
+ headline: { ...defaultStyleRecipe.textStyles.headline, color: headlineColor, fontFamily: detectedFont },
2469
+ subheadline: { ...defaultStyleRecipe.textStyles.subheadline, color: subheadlineColor, fontFamily: detectedFont },
2470
+ normalText: { ...defaultStyleRecipe.textStyles.normalText, color: normalColor, fontFamily: detectedFont },
2471
+ smallText: { ...defaultStyleRecipe.textStyles.smallText, color: smallColor, fontFamily: detectedFont }
2472
+ },
2473
+ table: {
2474
+ headerBg: accentColor,
2475
+ headerTextColor: isHexOrRgbDark(accentColor) ? '#ffffff' : '#0f172a',
2476
+ borderColor: isDark ? '#334155' : '#cbd5e1',
2477
+ alternateRowBg: isDark ? 'rgba(255,255,255,0.06)' : '#f8fafc',
2478
+ textColor: normalColor
2479
+ },
2480
+ chart: {
2481
+ ...defaultStyleRecipe.chart,
2482
+ chartColor: accentColor,
2483
+ palette: palette.length >= 4 ? palette : defaultStyleRecipe.chart.palette,
2484
+ labelColor: normalColor,
2485
+ gridColor: isDark ? '#334155' : '#e2e8f0'
2486
+ },
2487
+ shape: {
2488
+ fillColor: shapeFill,
2489
+ borderColor: accentColor,
2490
+ textColor: shapeText
2491
+ }
2492
+ }
2493
+ }
2494
+
2495
+ return defaultStyleRecipe
2342
2496
  }
2343
2497
 
2344
2498
  function initMathJax() {
@@ -2398,6 +2552,7 @@ const slides = ref<Slide[]>([
2398
2552
  background: '#ffffff',
2399
2553
  bgType: 'color',
2400
2554
  elements: [],
2555
+ animations: [],
2401
2556
  notes: '',
2402
2557
  masterId: 'master-default',
2403
2558
  layoutId: 'layout-title'
@@ -2415,6 +2570,7 @@ watch(activeIndex, (newIdx) => {
2415
2570
  if (!selectedSlideIndexes.value.includes(newIdx)) {
2416
2571
  selectedSlideIndexes.value = [newIdx]
2417
2572
  }
2573
+ if (isUndoingRedoing.value) return
2418
2574
  const curSlide = slides.value[newIdx]
2419
2575
  if (curSlide?.themeId && !isMasterEditingView.value) {
2420
2576
  const resolved = resolveSlideMasterAndLayout(curSlide)
@@ -2801,10 +2957,11 @@ function replacePlaceholderElement(
2801
2957
 
2802
2958
  const currentSlideAnimations = computed(() => {
2803
2959
  if (!activeSlide.value) return []
2804
- if (!activeSlide.value.animations) activeSlide.value.animations = []
2960
+ const slideAnims = activeSlide.value.animations
2961
+ if (!Array.isArray(slideAnims) || slideAnims.length === 0) return []
2805
2962
 
2806
2963
  const elIds = activeSlide.value.elements.map(el => el.id)
2807
- return activeSlide.value.animations.filter(animation => elIds.includes(animation.elId))
2964
+ return slideAnims.filter(animation => elIds.includes(animation.elId))
2808
2965
  })
2809
2966
 
2810
2967
  interface FormatedAnimation {
@@ -2818,10 +2975,11 @@ function isTriggerAnimation(animation: PPTAnimation): boolean {
2818
2975
 
2819
2976
  const formatedAnimations = computed(() => {
2820
2977
  if (!activeSlide.value) return []
2821
- if (!activeSlide.value.animations) activeSlide.value.animations = []
2978
+ const slideAnims = activeSlide.value.animations
2979
+ if (!Array.isArray(slideAnims) || slideAnims.length === 0) return []
2822
2980
 
2823
2981
  const elIds = activeSlide.value.elements.map(el => el.id)
2824
- const animations = activeSlide.value.animations.filter(animation => elIds.includes(animation.elId) && !isTriggerAnimation(animation))
2982
+ const animations = slideAnims.filter(animation => elIds.includes(animation.elId) && !isTriggerAnimation(animation))
2825
2983
 
2826
2984
  const formatted: FormatedAnimation[] = []
2827
2985
  for (const animation of animations) {
@@ -3174,10 +3332,21 @@ function initHistory() {
3174
3332
  activeSlideVersion.value++
3175
3333
  }
3176
3334
 
3177
- function syncActiveEditingTextToElement() {
3178
- if (typeof document === 'undefined' || !slides.value) return
3335
+ function normalizeComparableHtml(html: string): string {
3336
+ if (!html) return ''
3337
+ return html
3338
+ .replace(/;?\s*--ppt-font-family\s*:\s*[^;"]+;?/gi, '')
3339
+ .replace(/\s*style="\s*;?\s*"/gi, '')
3340
+ .replace(/style="\s+/gi, 'style="')
3341
+ .replace(/\s+"/gi, '"')
3342
+ .trim()
3343
+ }
3344
+
3345
+ function syncActiveEditingTextToElement(): boolean {
3346
+ if (typeof document === 'undefined' || !slides.value) return false
3179
3347
  const curSlide = slides.value[activeIndex.value]
3180
- if (!curSlide || !curSlide.elements) return
3348
+ if (!curSlide || !curSlide.elements) return false
3349
+ let syncedAny = false
3181
3350
  const syncList = (elements: any[]) => {
3182
3351
  elements.forEach((el: any) => {
3183
3352
  if (!el) return
@@ -3190,29 +3359,38 @@ function syncActiveEditingTextToElement() {
3190
3359
  const isEditingContainer = Boolean(
3191
3360
  container &&
3192
3361
  (container.getAttribute('contenteditable') === 'true' ||
3193
- (document.activeElement && container.contains(document.activeElement)))
3362
+ (document.activeElement && (container === document.activeElement || container.contains(document.activeElement))))
3194
3363
  )
3195
3364
  if (container && isEditingContainer && (!el.content || !el.content.includes('<table'))) {
3196
3365
  const htmlVal = container.innerHTML
3366
+ if (htmlVal.includes('color: rgb(153, 153, 153)') && htmlVal.includes('user-select: none')) {
3367
+ return
3368
+ }
3197
3369
  if (el.type === 'shape') {
3198
3370
  // 空 DOM 抓到 '' 时不能给无文本 shape 制造 text:"" 新键:
3199
3371
  // 语义等价但字符串不等,会被当作变更推入幽灵快照,导致 undo 永远撤不到底
3200
3372
  const isEmptyNoop = htmlVal === '' && !el.text
3201
3373
  if (!isEmptyNoop) {
3202
3374
  if (el.text && typeof el.text === 'object') {
3203
- if (el.text.content !== htmlVal) el.text.content = htmlVal
3204
- } else if (el.text !== htmlVal) {
3375
+ if (normalizeComparableHtml(el.text.content || '') !== normalizeComparableHtml(htmlVal)) {
3376
+ el.text.content = htmlVal
3377
+ syncedAny = true
3378
+ }
3379
+ } else if (normalizeComparableHtml(typeof el.text === 'string' ? el.text : '') !== normalizeComparableHtml(htmlVal)) {
3205
3380
  el.text = htmlVal
3381
+ syncedAny = true
3206
3382
  }
3207
3383
  }
3208
- } else if (el.content !== htmlVal) {
3384
+ } else if (normalizeComparableHtml(el.content || '') !== normalizeComparableHtml(htmlVal)) {
3209
3385
  el.content = htmlVal
3386
+ syncedAny = true
3210
3387
  }
3211
3388
  }
3212
3389
  }
3213
3390
  })
3214
3391
  }
3215
3392
  syncList(curSlide.elements)
3393
+ return syncedAny
3216
3394
  }
3217
3395
 
3218
3396
  function syncDOMWithRestoredSlides() {
@@ -3250,6 +3428,23 @@ function syncDOMWithRestoredSlides() {
3250
3428
  })
3251
3429
  }
3252
3430
 
3431
+ let isPostSnapshotMicrotask = false
3432
+ let isPostMasterSnapshotMicrotask = false
3433
+
3434
+ function markPostSnapshotMicrotask() {
3435
+ isPostSnapshotMicrotask = true
3436
+ queueMicrotask(() => {
3437
+ isPostSnapshotMicrotask = false
3438
+ })
3439
+ }
3440
+
3441
+ function markPostMasterSnapshotMicrotask() {
3442
+ isPostMasterSnapshotMicrotask = true
3443
+ queueMicrotask(() => {
3444
+ isPostMasterSnapshotMicrotask = false
3445
+ })
3446
+ }
3447
+
3253
3448
  function addHistorySnapshot(skipDomSync = false) {
3254
3449
  if (isUndoingRedoing.value || pauseHistory.value) return
3255
3450
  if (historySnapshotTimer) {
@@ -3323,6 +3518,9 @@ function addHistorySnapshot(skipDomSync = false) {
3323
3518
  dirtyMasterIndexes.clear()
3324
3519
  }
3325
3520
 
3521
+ // 抑制当前同步 tick 内已经被快照吸收的变更在下一个 microtask (pre-flush watcher) 中再次把页面/母版标脏
3522
+ markPostSnapshotMicrotask()
3523
+
3326
3524
  if (!changed) {
3327
3525
  if (import.meta.env.DEV) console.debug(`[perf:addSnapshot-dedup] ${(performance.now() - __perfT0).toFixed(1)}ms pages=${slides.value.length} dirty=${candidates.size}`)
3328
3526
  return
@@ -3396,6 +3594,7 @@ function addMasterHistorySnapshot() {
3396
3594
  }
3397
3595
  currentMasterStrs.length = n
3398
3596
  dirtyMasterIndexes.clear()
3597
+ markPostMasterSnapshotMicrotask()
3399
3598
  if (!changed) return
3400
3599
 
3401
3600
  masterHistoryStack.value = masterHistoryStack.value.slice(0, masterHistoryIndex.value + 1)
@@ -3427,10 +3626,11 @@ function scheduleHistorySnapshot() {
3427
3626
  }
3428
3627
 
3429
3628
  historySnapshotTimer = setTimeout(() => {
3629
+ historySnapshotTimer = null
3430
3630
  if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
3431
3631
  historyIdleCallbackId = window.requestIdleCallback(() => {
3432
- addHistorySnapshot()
3433
3632
  historyIdleCallbackId = null
3633
+ addHistorySnapshot()
3434
3634
  }, { timeout: 800 })
3435
3635
  } else {
3436
3636
  addHistorySnapshot()
@@ -3453,8 +3653,9 @@ function ensurePageWatchers() {
3453
3653
  // undo/redo 整体替换数组会触发全部页 watcher(deep 回调不比较新旧值),全是假阳性;
3454
3654
  // 此窗口内还原路径已同步 currentPageStrs,无需标脏。watcher 回调先于 nextTick 复位执行,守卫可靠
3455
3655
  if (isUndoingRedoing.value) return
3456
- dirtyPageIndexes.add(i)
3457
3656
  slidesRevision.value++
3657
+ if (isPostSnapshotMicrotask) return
3658
+ dirtyPageIndexes.add(i)
3458
3659
  scheduleHistorySnapshot()
3459
3660
  }, { deep: true }))
3460
3661
  }
@@ -3462,8 +3663,10 @@ function ensurePageWatchers() {
3462
3663
 
3463
3664
  // 长度哨兵:纯尾部追加(末页后 addSlide)不触发任何 index getter,必须靠它补注册 watcher
3464
3665
  watch(() => slides.value.length, () => {
3666
+ if (isUndoingRedoing.value) return
3465
3667
  ensurePageWatchers()
3466
3668
  slidesRevision.value++
3669
+ if (isPostSnapshotMicrotask) return
3467
3670
  scheduleHistorySnapshot()
3468
3671
  })
3469
3672
 
@@ -3486,10 +3689,11 @@ function scheduleMasterHistorySnapshot() {
3486
3689
  }
3487
3690
 
3488
3691
  masterSnapshotTimer = setTimeout(() => {
3692
+ masterSnapshotTimer = null
3489
3693
  if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
3490
3694
  masterIdleCallbackId = window.requestIdleCallback(() => {
3491
- addMasterHistorySnapshot()
3492
3695
  masterIdleCallbackId = null
3696
+ addMasterHistorySnapshot()
3493
3697
  }, { timeout: 800 })
3494
3698
  } else {
3495
3699
  addMasterHistorySnapshot()
@@ -3504,11 +3708,14 @@ function ensureMasterWatchers() {
3504
3708
  const i = masterWatchers.length
3505
3709
  masterWatchers.push(watch(() => slideMasters.value[i], () => {
3506
3710
  if (isUndoingRedoing.value) return
3507
- dirtyMasterIndexes.add(i)
3508
3711
  slidesRevision.value++
3509
3712
  if (isMasterEditingView.value) {
3713
+ if (isPostMasterSnapshotMicrotask) return
3714
+ dirtyMasterIndexes.add(i)
3510
3715
  scheduleMasterHistorySnapshot()
3511
3716
  } else {
3717
+ if (isPostSnapshotMicrotask) return
3718
+ dirtyMasterIndexes.add(i)
3512
3719
  scheduleHistorySnapshot()
3513
3720
  }
3514
3721
  }, { deep: true }))
@@ -3516,11 +3723,14 @@ function ensureMasterWatchers() {
3516
3723
  }
3517
3724
 
3518
3725
  watch(() => slideMasters.value.length, () => {
3726
+ if (isUndoingRedoing.value) return
3519
3727
  ensureMasterWatchers()
3520
3728
  slidesRevision.value++
3521
3729
  if (isMasterEditingView.value) {
3730
+ if (isPostMasterSnapshotMicrotask) return
3522
3731
  scheduleMasterHistorySnapshot()
3523
3732
  } else {
3733
+ if (isPostSnapshotMicrotask) return
3524
3734
  scheduleHistorySnapshot()
3525
3735
  }
3526
3736
  })
@@ -3537,6 +3747,7 @@ watch([activeMasterId, activeLayoutId], ([mid, lid]) => {
3537
3747
  // 立即落盘尚在防抖中的快照:undo/redo 前调用,
3538
3748
  // 避免编辑后 350ms 内撤销导致该步编辑被定时器取消而丢失
3539
3749
  function flushPendingHistorySnapshot() {
3750
+ const hadPendingTimer = Boolean(historySnapshotTimer || historyIdleCallbackId)
3540
3751
  if (historySnapshotTimer) {
3541
3752
  clearTimeout(historySnapshotTimer)
3542
3753
  historySnapshotTimer = null
@@ -3545,10 +3756,14 @@ function flushPendingHistorySnapshot() {
3545
3756
  window.cancelIdleCallback(historyIdleCallbackId)
3546
3757
  historyIdleCallbackId = null
3547
3758
  }
3548
- addHistorySnapshot()
3759
+ const syncedFromDom = syncActiveEditingTextToElement()
3760
+ if (syncedFromDom || hadPendingTimer || dirtyPageIndexes.size > 0 || dirtyMasterIndexes.size > 0) {
3761
+ addHistorySnapshot(true)
3762
+ }
3549
3763
  }
3550
3764
 
3551
3765
  function flushPendingMasterHistorySnapshot() {
3766
+ const hadPendingTimer = Boolean(masterSnapshotTimer || masterIdleCallbackId)
3552
3767
  if (masterSnapshotTimer) {
3553
3768
  clearTimeout(masterSnapshotTimer)
3554
3769
  masterSnapshotTimer = null
@@ -3557,7 +3772,9 @@ function flushPendingMasterHistorySnapshot() {
3557
3772
  window.cancelIdleCallback(masterIdleCallbackId)
3558
3773
  masterIdleCallbackId = null
3559
3774
  }
3560
- addMasterHistorySnapshot()
3775
+ if (hadPendingTimer || dirtyMasterIndexes.size > 0) {
3776
+ addMasterHistorySnapshot()
3777
+ }
3561
3778
  }
3562
3779
 
3563
3780
  // Initialize history stack
@@ -3603,6 +3820,8 @@ function undo() {
3603
3820
  activeLayoutId.value = masterHistoryActiveLids[masterHistoryIndex.value]
3604
3821
  selectedElementId.value = null
3605
3822
  selectedElementIds.value = []
3823
+ syncDOMWithRestoredSlides()
3824
+ activeSlideVersion.value++
3606
3825
  if (import.meta.env.DEV) console.debug(`[perf:undo-master] patch ${(performance.now() - __perfT0).toFixed(1)}ms masters=${slideMasters.value.length}`)
3607
3826
  notify('已撤销')
3608
3827
  nextTick(() => {
@@ -10006,6 +10225,7 @@ export function useSlides() {
10006
10225
  canRedo,
10007
10226
  historyStack,
10008
10227
  historyIndex,
10228
+ isUndoingRedoing,
10009
10229
  pauseHistory,
10010
10230
  isCanvasDragging,
10011
10231
  activeSlideVersion,