jvs-ppt-ui 0.0.35 → 0.0.36

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.
@@ -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
  }
@@ -2398,6 +2414,7 @@ const slides = ref<Slide[]>([
2398
2414
  background: '#ffffff',
2399
2415
  bgType: 'color',
2400
2416
  elements: [],
2417
+ animations: [],
2401
2418
  notes: '',
2402
2419
  masterId: 'master-default',
2403
2420
  layoutId: 'layout-title'
@@ -2415,6 +2432,7 @@ watch(activeIndex, (newIdx) => {
2415
2432
  if (!selectedSlideIndexes.value.includes(newIdx)) {
2416
2433
  selectedSlideIndexes.value = [newIdx]
2417
2434
  }
2435
+ if (isUndoingRedoing.value) return
2418
2436
  const curSlide = slides.value[newIdx]
2419
2437
  if (curSlide?.themeId && !isMasterEditingView.value) {
2420
2438
  const resolved = resolveSlideMasterAndLayout(curSlide)
@@ -2801,10 +2819,11 @@ function replacePlaceholderElement(
2801
2819
 
2802
2820
  const currentSlideAnimations = computed(() => {
2803
2821
  if (!activeSlide.value) return []
2804
- if (!activeSlide.value.animations) activeSlide.value.animations = []
2822
+ const slideAnims = activeSlide.value.animations
2823
+ if (!Array.isArray(slideAnims) || slideAnims.length === 0) return []
2805
2824
 
2806
2825
  const elIds = activeSlide.value.elements.map(el => el.id)
2807
- return activeSlide.value.animations.filter(animation => elIds.includes(animation.elId))
2826
+ return slideAnims.filter(animation => elIds.includes(animation.elId))
2808
2827
  })
2809
2828
 
2810
2829
  interface FormatedAnimation {
@@ -2818,10 +2837,11 @@ function isTriggerAnimation(animation: PPTAnimation): boolean {
2818
2837
 
2819
2838
  const formatedAnimations = computed(() => {
2820
2839
  if (!activeSlide.value) return []
2821
- if (!activeSlide.value.animations) activeSlide.value.animations = []
2840
+ const slideAnims = activeSlide.value.animations
2841
+ if (!Array.isArray(slideAnims) || slideAnims.length === 0) return []
2822
2842
 
2823
2843
  const elIds = activeSlide.value.elements.map(el => el.id)
2824
- const animations = activeSlide.value.animations.filter(animation => elIds.includes(animation.elId) && !isTriggerAnimation(animation))
2844
+ const animations = slideAnims.filter(animation => elIds.includes(animation.elId) && !isTriggerAnimation(animation))
2825
2845
 
2826
2846
  const formatted: FormatedAnimation[] = []
2827
2847
  for (const animation of animations) {
@@ -3174,10 +3194,21 @@ function initHistory() {
3174
3194
  activeSlideVersion.value++
3175
3195
  }
3176
3196
 
3177
- function syncActiveEditingTextToElement() {
3178
- if (typeof document === 'undefined' || !slides.value) return
3197
+ function normalizeComparableHtml(html: string): string {
3198
+ if (!html) return ''
3199
+ return html
3200
+ .replace(/;?\s*--ppt-font-family\s*:\s*[^;"]+;?/gi, '')
3201
+ .replace(/\s*style="\s*;?\s*"/gi, '')
3202
+ .replace(/style="\s+/gi, 'style="')
3203
+ .replace(/\s+"/gi, '"')
3204
+ .trim()
3205
+ }
3206
+
3207
+ function syncActiveEditingTextToElement(): boolean {
3208
+ if (typeof document === 'undefined' || !slides.value) return false
3179
3209
  const curSlide = slides.value[activeIndex.value]
3180
- if (!curSlide || !curSlide.elements) return
3210
+ if (!curSlide || !curSlide.elements) return false
3211
+ let syncedAny = false
3181
3212
  const syncList = (elements: any[]) => {
3182
3213
  elements.forEach((el: any) => {
3183
3214
  if (!el) return
@@ -3190,29 +3221,38 @@ function syncActiveEditingTextToElement() {
3190
3221
  const isEditingContainer = Boolean(
3191
3222
  container &&
3192
3223
  (container.getAttribute('contenteditable') === 'true' ||
3193
- (document.activeElement && container.contains(document.activeElement)))
3224
+ (document.activeElement && (container === document.activeElement || container.contains(document.activeElement))))
3194
3225
  )
3195
3226
  if (container && isEditingContainer && (!el.content || !el.content.includes('<table'))) {
3196
3227
  const htmlVal = container.innerHTML
3228
+ if (htmlVal.includes('color: rgb(153, 153, 153)') && htmlVal.includes('user-select: none')) {
3229
+ return
3230
+ }
3197
3231
  if (el.type === 'shape') {
3198
3232
  // 空 DOM 抓到 '' 时不能给无文本 shape 制造 text:"" 新键:
3199
3233
  // 语义等价但字符串不等,会被当作变更推入幽灵快照,导致 undo 永远撤不到底
3200
3234
  const isEmptyNoop = htmlVal === '' && !el.text
3201
3235
  if (!isEmptyNoop) {
3202
3236
  if (el.text && typeof el.text === 'object') {
3203
- if (el.text.content !== htmlVal) el.text.content = htmlVal
3204
- } else if (el.text !== htmlVal) {
3237
+ if (normalizeComparableHtml(el.text.content || '') !== normalizeComparableHtml(htmlVal)) {
3238
+ el.text.content = htmlVal
3239
+ syncedAny = true
3240
+ }
3241
+ } else if (normalizeComparableHtml(typeof el.text === 'string' ? el.text : '') !== normalizeComparableHtml(htmlVal)) {
3205
3242
  el.text = htmlVal
3243
+ syncedAny = true
3206
3244
  }
3207
3245
  }
3208
- } else if (el.content !== htmlVal) {
3246
+ } else if (normalizeComparableHtml(el.content || '') !== normalizeComparableHtml(htmlVal)) {
3209
3247
  el.content = htmlVal
3248
+ syncedAny = true
3210
3249
  }
3211
3250
  }
3212
3251
  }
3213
3252
  })
3214
3253
  }
3215
3254
  syncList(curSlide.elements)
3255
+ return syncedAny
3216
3256
  }
3217
3257
 
3218
3258
  function syncDOMWithRestoredSlides() {
@@ -3250,6 +3290,23 @@ function syncDOMWithRestoredSlides() {
3250
3290
  })
3251
3291
  }
3252
3292
 
3293
+ let isPostSnapshotMicrotask = false
3294
+ let isPostMasterSnapshotMicrotask = false
3295
+
3296
+ function markPostSnapshotMicrotask() {
3297
+ isPostSnapshotMicrotask = true
3298
+ queueMicrotask(() => {
3299
+ isPostSnapshotMicrotask = false
3300
+ })
3301
+ }
3302
+
3303
+ function markPostMasterSnapshotMicrotask() {
3304
+ isPostMasterSnapshotMicrotask = true
3305
+ queueMicrotask(() => {
3306
+ isPostMasterSnapshotMicrotask = false
3307
+ })
3308
+ }
3309
+
3253
3310
  function addHistorySnapshot(skipDomSync = false) {
3254
3311
  if (isUndoingRedoing.value || pauseHistory.value) return
3255
3312
  if (historySnapshotTimer) {
@@ -3323,6 +3380,9 @@ function addHistorySnapshot(skipDomSync = false) {
3323
3380
  dirtyMasterIndexes.clear()
3324
3381
  }
3325
3382
 
3383
+ // 抑制当前同步 tick 内已经被快照吸收的变更在下一个 microtask (pre-flush watcher) 中再次把页面/母版标脏
3384
+ markPostSnapshotMicrotask()
3385
+
3326
3386
  if (!changed) {
3327
3387
  if (import.meta.env.DEV) console.debug(`[perf:addSnapshot-dedup] ${(performance.now() - __perfT0).toFixed(1)}ms pages=${slides.value.length} dirty=${candidates.size}`)
3328
3388
  return
@@ -3396,6 +3456,7 @@ function addMasterHistorySnapshot() {
3396
3456
  }
3397
3457
  currentMasterStrs.length = n
3398
3458
  dirtyMasterIndexes.clear()
3459
+ markPostMasterSnapshotMicrotask()
3399
3460
  if (!changed) return
3400
3461
 
3401
3462
  masterHistoryStack.value = masterHistoryStack.value.slice(0, masterHistoryIndex.value + 1)
@@ -3427,10 +3488,11 @@ function scheduleHistorySnapshot() {
3427
3488
  }
3428
3489
 
3429
3490
  historySnapshotTimer = setTimeout(() => {
3491
+ historySnapshotTimer = null
3430
3492
  if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
3431
3493
  historyIdleCallbackId = window.requestIdleCallback(() => {
3432
- addHistorySnapshot()
3433
3494
  historyIdleCallbackId = null
3495
+ addHistorySnapshot()
3434
3496
  }, { timeout: 800 })
3435
3497
  } else {
3436
3498
  addHistorySnapshot()
@@ -3453,8 +3515,9 @@ function ensurePageWatchers() {
3453
3515
  // undo/redo 整体替换数组会触发全部页 watcher(deep 回调不比较新旧值),全是假阳性;
3454
3516
  // 此窗口内还原路径已同步 currentPageStrs,无需标脏。watcher 回调先于 nextTick 复位执行,守卫可靠
3455
3517
  if (isUndoingRedoing.value) return
3456
- dirtyPageIndexes.add(i)
3457
3518
  slidesRevision.value++
3519
+ if (isPostSnapshotMicrotask) return
3520
+ dirtyPageIndexes.add(i)
3458
3521
  scheduleHistorySnapshot()
3459
3522
  }, { deep: true }))
3460
3523
  }
@@ -3462,8 +3525,10 @@ function ensurePageWatchers() {
3462
3525
 
3463
3526
  // 长度哨兵:纯尾部追加(末页后 addSlide)不触发任何 index getter,必须靠它补注册 watcher
3464
3527
  watch(() => slides.value.length, () => {
3528
+ if (isUndoingRedoing.value) return
3465
3529
  ensurePageWatchers()
3466
3530
  slidesRevision.value++
3531
+ if (isPostSnapshotMicrotask) return
3467
3532
  scheduleHistorySnapshot()
3468
3533
  })
3469
3534
 
@@ -3486,10 +3551,11 @@ function scheduleMasterHistorySnapshot() {
3486
3551
  }
3487
3552
 
3488
3553
  masterSnapshotTimer = setTimeout(() => {
3554
+ masterSnapshotTimer = null
3489
3555
  if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
3490
3556
  masterIdleCallbackId = window.requestIdleCallback(() => {
3491
- addMasterHistorySnapshot()
3492
3557
  masterIdleCallbackId = null
3558
+ addMasterHistorySnapshot()
3493
3559
  }, { timeout: 800 })
3494
3560
  } else {
3495
3561
  addMasterHistorySnapshot()
@@ -3504,11 +3570,14 @@ function ensureMasterWatchers() {
3504
3570
  const i = masterWatchers.length
3505
3571
  masterWatchers.push(watch(() => slideMasters.value[i], () => {
3506
3572
  if (isUndoingRedoing.value) return
3507
- dirtyMasterIndexes.add(i)
3508
3573
  slidesRevision.value++
3509
3574
  if (isMasterEditingView.value) {
3575
+ if (isPostMasterSnapshotMicrotask) return
3576
+ dirtyMasterIndexes.add(i)
3510
3577
  scheduleMasterHistorySnapshot()
3511
3578
  } else {
3579
+ if (isPostSnapshotMicrotask) return
3580
+ dirtyMasterIndexes.add(i)
3512
3581
  scheduleHistorySnapshot()
3513
3582
  }
3514
3583
  }, { deep: true }))
@@ -3516,11 +3585,14 @@ function ensureMasterWatchers() {
3516
3585
  }
3517
3586
 
3518
3587
  watch(() => slideMasters.value.length, () => {
3588
+ if (isUndoingRedoing.value) return
3519
3589
  ensureMasterWatchers()
3520
3590
  slidesRevision.value++
3521
3591
  if (isMasterEditingView.value) {
3592
+ if (isPostMasterSnapshotMicrotask) return
3522
3593
  scheduleMasterHistorySnapshot()
3523
3594
  } else {
3595
+ if (isPostSnapshotMicrotask) return
3524
3596
  scheduleHistorySnapshot()
3525
3597
  }
3526
3598
  })
@@ -3537,6 +3609,7 @@ watch([activeMasterId, activeLayoutId], ([mid, lid]) => {
3537
3609
  // 立即落盘尚在防抖中的快照:undo/redo 前调用,
3538
3610
  // 避免编辑后 350ms 内撤销导致该步编辑被定时器取消而丢失
3539
3611
  function flushPendingHistorySnapshot() {
3612
+ const hadPendingTimer = Boolean(historySnapshotTimer || historyIdleCallbackId)
3540
3613
  if (historySnapshotTimer) {
3541
3614
  clearTimeout(historySnapshotTimer)
3542
3615
  historySnapshotTimer = null
@@ -3545,10 +3618,14 @@ function flushPendingHistorySnapshot() {
3545
3618
  window.cancelIdleCallback(historyIdleCallbackId)
3546
3619
  historyIdleCallbackId = null
3547
3620
  }
3548
- addHistorySnapshot()
3621
+ const syncedFromDom = syncActiveEditingTextToElement()
3622
+ if (syncedFromDom || hadPendingTimer || dirtyPageIndexes.size > 0 || dirtyMasterIndexes.size > 0) {
3623
+ addHistorySnapshot(true)
3624
+ }
3549
3625
  }
3550
3626
 
3551
3627
  function flushPendingMasterHistorySnapshot() {
3628
+ const hadPendingTimer = Boolean(masterSnapshotTimer || masterIdleCallbackId)
3552
3629
  if (masterSnapshotTimer) {
3553
3630
  clearTimeout(masterSnapshotTimer)
3554
3631
  masterSnapshotTimer = null
@@ -3557,7 +3634,9 @@ function flushPendingMasterHistorySnapshot() {
3557
3634
  window.cancelIdleCallback(masterIdleCallbackId)
3558
3635
  masterIdleCallbackId = null
3559
3636
  }
3560
- addMasterHistorySnapshot()
3637
+ if (hadPendingTimer || dirtyMasterIndexes.size > 0) {
3638
+ addMasterHistorySnapshot()
3639
+ }
3561
3640
  }
3562
3641
 
3563
3642
  // Initialize history stack
@@ -3603,6 +3682,8 @@ function undo() {
3603
3682
  activeLayoutId.value = masterHistoryActiveLids[masterHistoryIndex.value]
3604
3683
  selectedElementId.value = null
3605
3684
  selectedElementIds.value = []
3685
+ syncDOMWithRestoredSlides()
3686
+ activeSlideVersion.value++
3606
3687
  if (import.meta.env.DEV) console.debug(`[perf:undo-master] patch ${(performance.now() - __perfT0).toFixed(1)}ms masters=${slideMasters.value.length}`)
3607
3688
  notify('已撤销')
3608
3689
  nextTick(() => {
@@ -10006,6 +10087,7 @@ export function useSlides() {
10006
10087
  canRedo,
10007
10088
  historyStack,
10008
10089
  historyIndex,
10090
+ isUndoingRedoing,
10009
10091
  pauseHistory,
10010
10092
  isCanvasDragging,
10011
10093
  activeSlideVersion,