jvs-ppt-ui 0.0.36 → 0.0.38

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 (62) 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 +80182 -21671
  26. package/dist/lib/jvs-ppt-ui.umd.js +112 -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 +53 -14
  49. package/src/components/ChartTypeSelector.vue +15 -67
  50. package/src/components/Header.vue +10 -7
  51. package/src/components/SidebarLeft.vue +411 -35
  52. package/src/components/sidebar/common/SidebarPositionGroup.vue +199 -33
  53. package/src/components/sidebar/panels/LayoutThumbSvg.vue +82 -14
  54. package/src/components/sidebar/panels/SidebarImageFormatPanel.vue +37 -33
  55. package/src/composables/canvas/useCanvasCrop.ts +25 -2
  56. package/src/composables/sidebar/useSidebarElementTransform.ts +13 -7
  57. package/src/composables/useSlides.ts +141 -3
  58. package/src/configs/layoutLibrary.ts +113 -0
  59. package/src/style.css +107 -17
  60. package/src/utils/pptxAnimationInjector.ts +36 -4
  61. package/src/assets/chart/baseMap.png +0 -0
  62. package/src/assets/chart/boxplot.png +0 -0
@@ -37,7 +37,7 @@ import { SHAPE_LIST, type ShapePoolItem } from '../utils/shapes'
37
37
  const flatShapePoolItems: ShapePoolItem[] = SHAPE_LIST.flatMap(c => c.children)
38
38
 
39
39
  const {
40
- slides, activeIndex, selectSlide, selectAllSlides, deleteSelectedSlides,
40
+ slides, activeIndex, activeSlide, selectSlide, selectAllSlides, deleteSelectedSlides,
41
41
  copySelectedSlides, cutSelectedSlides, duplicateSelectedSlides,
42
42
  selectedSlideIndexes, isMouseOverSlideList, renderLatexToSvg, deleteSlide,
43
43
  selectedElementIds, selectedElementId, notify, startPresentation,
@@ -46,7 +46,8 @@ const {
46
46
  enterMasterView, addMaster, deleteMaster, addLayout, deleteLayout, duplicateLayout,
47
47
  clipboard, slideClipboard, handleUnifiedPaste, sortSlideElements, getEffectiveMasterElementsForSlide,
48
48
  getEffectiveSlideBackground, isCanvasDragging, activeSlideVersion, pauseHistory,
49
- activeSidebarTab, isReadonly, isTemplateEnabled, addHistorySnapshot
49
+ activeSidebarTab, isReadonly, isTemplateEnabled, addHistorySnapshot,
50
+ getActiveSlideThemeRecipe, recolorElementsWithRecipe
50
51
  } = useSlides()
51
52
 
52
53
  const displaySlides = shallowRef<any[]>([...slides.value])
@@ -225,24 +226,232 @@ import {
225
226
  parseTemplateJsonToDeck,
226
227
  type SlideTemplateItem
227
228
  } from '../configs/slideTemplates'
229
+ import {
230
+ DEFAULT_LAYOUT_LIBRARY_CATEGORIES,
231
+ loadBuiltinLayoutLibrary
232
+ } from '../configs/layoutLibrary'
228
233
 
229
234
  const presetPopoverVisible = ref(false)
230
- const presetActiveTab = ref<'templates' | 'layouts'>(isTemplateEnabled.value ? 'templates' : 'layouts')
235
+ const presetActiveTab = ref<'templates' | 'layout-library' | 'layouts'>(isTemplateEnabled.value ? 'templates' : 'layout-library')
231
236
  const templateSearchQuery = ref('')
232
237
  const selectedTemplateDeck = ref<SlideTemplateItem | null>(null)
233
238
  const loadingTemplateId = ref<string | null>(null)
234
239
  const templateJsonInputRef = ref<HTMLInputElement | null>(null)
240
+ const templateBodyRef = ref<HTMLElement | null>(null)
241
+
242
+ function resetTemplateBodyScroll() {
243
+ if (templateBodyRef.value) {
244
+ templateBodyRef.value.scrollTop = 0
245
+ }
246
+ nextTick(() => {
247
+ if (templateBodyRef.value) {
248
+ templateBodyRef.value.scrollTop = 0
249
+ }
250
+ })
251
+ }
252
+
253
+ watch(selectedTemplateDeck, () => {
254
+ resetTemplateBodyScroll()
255
+ })
256
+
257
+ // 版式库 (Layout Library) 状态与内置开箱即用加载
258
+ const layoutLibraryDeck = shallowRef<SlideTemplateItem | null>(null)
259
+ const layoutLibrarySlides = shallowRef<any[]>([])
260
+ const layoutLibraryCategories = ref<string[]>([...DEFAULT_LAYOUT_LIBRARY_CATEGORIES])
261
+ const activeLayoutLibraryCategory = ref<string>('all')
262
+ const layoutLibraryLoading = ref(false)
263
+ const layoutLibraryLoaded = ref(false)
264
+ const layoutLibraryVisibleCount = ref(24)
265
+ const layoutCategoryBarRef = ref<HTMLElement | null>(null)
266
+ const canScrollLayoutCatLeft = ref(false)
267
+ const canScrollLayoutCatRight = ref(true)
268
+ const layoutLibraryBodyRef = ref<HTMLElement | null>(null)
269
+
270
+ function updateLayoutCategoryScrollState() {
271
+ const el = layoutCategoryBarRef.value
272
+ if (!el) return
273
+ canScrollLayoutCatLeft.value = el.scrollLeft > 4
274
+ canScrollLayoutCatRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - 4
275
+ }
276
+
277
+ function scrollLayoutCategoryBar(delta: number) {
278
+ const el = layoutCategoryBarRef.value
279
+ if (!el) return
280
+ el.scrollBy({ left: delta, behavior: 'smooth' })
281
+ setTimeout(updateLayoutCategoryScrollState, 220)
282
+ }
283
+
284
+ function selectLayoutLibraryCategory(cat: string) {
285
+ activeLayoutLibraryCategory.value = cat
286
+ layoutLibraryVisibleCount.value = 24
287
+ if (layoutLibraryBodyRef.value) {
288
+ layoutLibraryBodyRef.value.scrollTop = 0
289
+ }
290
+ }
291
+
292
+ function handleLayoutLibraryScroll(e: Event) {
293
+ const el = e.target as HTMLElement
294
+ if (!el) return
295
+ if (el.scrollTop + el.clientHeight >= el.scrollHeight - 240) {
296
+ if (layoutLibraryVisibleCount.value < filteredLayoutLibrarySlides.value.length) {
297
+ layoutLibraryVisibleCount.value = Math.min(
298
+ filteredLayoutLibrarySlides.value.length,
299
+ layoutLibraryVisibleCount.value + 24
300
+ )
301
+ }
302
+ }
303
+ }
304
+
305
+ async function ensureLayoutLibraryLoaded() {
306
+ if (layoutLibraryLoaded.value || layoutLibraryLoading.value) return
307
+ layoutLibraryLoading.value = true
308
+ try {
309
+ const { deck, slides, categories } = await loadBuiltinLayoutLibrary()
310
+ layoutLibraryCategories.value = categories
311
+ layoutLibraryDeck.value = deck
312
+ layoutLibrarySlides.value = slides
313
+ layoutLibraryLoaded.value = true
314
+ nextTick(updateLayoutCategoryScrollState)
315
+ } catch (err: any) {
316
+ console.warn('[layoutLibrary] 加载内置版式库失败:', err)
317
+ } finally {
318
+ layoutLibraryLoading.value = false
319
+ }
320
+ }
321
+
322
+ const filteredLayoutLibrarySlides = computed(() => {
323
+ const cat = activeLayoutLibraryCategory.value
324
+ if (!cat || cat === 'all') return layoutLibrarySlides.value
325
+ return layoutLibrarySlides.value.filter((s: any) => s.category === cat)
326
+ })
327
+
328
+ const activeLayoutLibraryRecipe = computed(() => {
329
+ // 订阅当前选中幻灯片、母版与版本变化,确保切换页面或切换主题时版式库实时重着色
330
+ void activeIndex.value
331
+ void activeSlideVersion.value
332
+ void isMasterEditingView.value
333
+ void activeMasterId.value
334
+ return getActiveSlideThemeRecipe(activeSlide.value)
335
+ })
336
+
337
+ const themedLayoutLibraryCache = new Map<string, any>()
338
+
339
+ function applyThemeRecipeToLayoutSlide(rawSlide: any, recipe: any): any {
340
+ const cloned = cloneSlideForInsertion(rawSlide)
341
+ cloned.id = rawSlide.id
342
+ cloned.name = rawSlide.name
343
+ cloned.category = rawSlide.category
344
+ cloned.title = rawSlide.title
345
+
346
+ if (!recipe) return cloned
347
+
348
+ if (recipe.backgroundColor) {
349
+ cloned.background = recipe.backgroundColor
350
+ cloned.bgType = 'color'
351
+ }
352
+ cloned.themeId = recipe.id
353
+ cloned.themeName = recipe.name
354
+ if (Array.isArray(recipe.styleColors)) {
355
+ cloned.themeColors = [...recipe.styleColors]
356
+ }
357
+
358
+ if (Array.isArray(cloned.elements)) {
359
+ recolorElementsWithRecipe(cloned.elements, recipe)
360
+
361
+ // 保障位于实心色块(如流程卡片、按钮背景)之上的独立文本元素具备高对比度可读性
362
+ const solidShapes = cloned.elements.filter((el: any) => {
363
+ if (el?.type !== 'shape') return false
364
+ const f = el.style?.fill || el.fill
365
+ return typeof f === 'string' && f !== 'none' && f !== 'transparent'
366
+ })
367
+ if (solidShapes.length > 0) {
368
+ for (const el of cloned.elements) {
369
+ if (el?.type !== 'text') continue
370
+ const cx = (parseFloat(el.style?.left ?? el.left) || 0) + (parseFloat(el.style?.width ?? el.width) || 0) / 2
371
+ const cy = (parseFloat(el.style?.top ?? el.top) || 0) + (parseFloat(el.style?.height ?? el.height) || 0) / 2
372
+ const hostShape = solidShapes.find((sh: any) => {
373
+ const sx = parseFloat(sh.style?.left ?? sh.left) || 0
374
+ const sy = parseFloat(sh.style?.top ?? sh.top) || 0
375
+ const sw = parseFloat(sh.style?.width ?? sh.width) || 0
376
+ const shH = parseFloat(sh.style?.height ?? sh.height) || 0
377
+ return cx >= sx && cx <= sx + sw && cy >= sy && cy <= sy + shH
378
+ })
379
+ if (hostShape) {
380
+ const shFill = hostShape.style?.fill || hostShape.fill
381
+ const txtColor = el.style?.color || el.color
382
+ if (typeof shFill === 'string' && typeof txtColor === 'string') {
383
+ if (isColorDarkForMaster(shFill) === isColorDarkForMaster(txtColor)) {
384
+ const contrastColor = recipe.shape?.textColor || (isColorDarkForMaster(shFill) ? '#ffffff' : '#0f172a')
385
+ el.color = contrastColor
386
+ el.textColor = contrastColor
387
+ if (el.style) {
388
+ el.style.color = contrastColor
389
+ el.style.textColor = contrastColor
390
+ }
391
+ }
392
+ }
393
+ }
394
+ }
395
+ }
396
+ }
397
+
398
+ return cloned
399
+ }
400
+
401
+ const visibleLayoutLibrarySlides = computed(() => {
402
+ const recipe = activeLayoutLibraryRecipe.value
403
+ const recipeKey = recipe
404
+ ? `${recipe.id}_${recipe.backgroundColor}_${recipe.textStyles?.title?.color}_${recipe.textStyles?.headline?.color}_${recipe.textStyles?.normalText?.color}_${recipe.shape?.fillColor}`
405
+ : 'default'
406
+ if (themedLayoutLibraryCache.size > 400) {
407
+ themedLayoutLibraryCache.clear()
408
+ }
409
+ const slice = filteredLayoutLibrarySlides.value.slice(0, layoutLibraryVisibleCount.value)
410
+ return slice.map((rawSlide: any, idx: number) => {
411
+ const cacheKey = `${recipeKey}__${rawSlide.id || idx}`
412
+ const hit = themedLayoutLibraryCache.get(cacheKey)
413
+ if (hit) return hit
414
+ const themed = applyThemeRecipeToLayoutSlide(rawSlide, recipe)
415
+ themedLayoutLibraryCache.set(cacheKey, themed)
416
+ return themed
417
+ })
418
+ })
419
+
420
+ function insertLayoutLibrarySlide(slide: any, slideIdx: number) {
421
+ if (!slide) return
422
+ addHistorySnapshot()
423
+ const recipe = activeLayoutLibraryRecipe.value
424
+ const themedSlide = applyThemeRecipeToLayoutSlide(slide, recipe)
425
+ const cloned = cloneSlideForInsertion(themedSlide)
426
+ const curSlide = activeSlide.value
427
+ cloned.masterId = curSlide?.masterId || activeMasterId.value || slideMasters.value?.[0]?.id || 'master-default'
428
+ cloned.title = slide.name || (slide.title || '').replace(/^\[[^\]]+\]\s*/, '') || `版式 ${slideIdx + 1}`
429
+ const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
430
+ slides.value.splice(insertPos, 0, cloned)
431
+ activeIndex.value = insertPos
432
+ activeSlideVersion.value++
433
+ displaySlides.value = [...slides.value]
434
+ addHistorySnapshot()
435
+ presetPopoverVisible.value = false
436
+ notify(`已插入版式 "${cloned.title}"`)
437
+ }
235
438
 
236
439
  watch(isTemplateEnabled, (enabled) => {
237
- if (!enabled) {
238
- presetActiveTab.value = 'layouts'
440
+ if (!enabled && presetActiveTab.value === 'templates') {
441
+ presetActiveTab.value = 'layout-library'
239
442
  selectedTemplateDeck.value = null
240
443
  }
241
444
  }, { immediate: true })
242
445
 
243
446
  watch(presetPopoverVisible, (visible) => {
244
- if (visible && isTemplateEnabled.value) {
245
- ensureTemplatesFirstPageLoaded()
447
+ if (visible) {
448
+ if (isTemplateEnabled.value) {
449
+ ensureTemplatesFirstPageLoaded()
450
+ }
451
+ if (presetActiveTab.value === 'layout-library') {
452
+ ensureLayoutLibraryLoaded()
453
+ nextTick(updateLayoutCategoryScrollState)
454
+ }
246
455
  }
247
456
  })
248
457
 
@@ -255,10 +464,13 @@ const filteredSlideTemplates = computed(() => {
255
464
  )
256
465
  })
257
466
 
258
- function switchPresetTab(tab: 'templates' | 'layouts') {
467
+ function switchPresetTab(tab: 'templates' | 'layout-library' | 'layouts') {
259
468
  presetActiveTab.value = tab
260
469
  if (tab === 'templates') {
261
470
  selectedTemplateDeck.value = null
471
+ } else if (tab === 'layout-library') {
472
+ ensureLayoutLibraryLoaded()
473
+ nextTick(updateLayoutCategoryScrollState)
262
474
  }
263
475
  }
264
476
 
@@ -366,9 +578,10 @@ function ensureTemplateMasterForSlide(tpl: SlideTemplateItem, slide: any): strin
366
578
  const uid = Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
367
579
  const newMasterId = `master-tpl-${uid}`
368
580
  const baseDefault = createDefaultSlideMasters(logicalWidth.value, logicalHeight.value)[0]
581
+ const slideRecipe = getActiveSlideThemeRecipe(slide)
369
582
  const dark = isSlideThemeDarkForMaster(slide)
370
- const titleColor = dark ? '#ffffff' : '#0f172a'
371
- const bodyColor = dark ? 'rgba(255, 255, 255, 0.85)' : '#64748b'
583
+ const titleColor = slideRecipe?.textStyles?.title?.color || (dark ? '#ffffff' : '#0f172a')
584
+ const bodyColor = slideRecipe?.textStyles?.normalText?.color || (dark ? 'rgba(255, 255, 255, 0.85)' : '#64748b')
372
585
  const borderColor = dark ? 'rgba(255, 255, 255, 0.45)' : '#cbd5e1'
373
586
 
374
587
  const clonedBg = typeof rawBg === 'object' && rawBg !== null ? JSON.parse(JSON.stringify(rawBg)) : rawBg
@@ -429,6 +642,16 @@ function ensureTemplateMasterForSlide(tpl: SlideTemplateItem, slide: any): strin
429
642
  return newMasterId
430
643
  }
431
644
 
645
+ function isSlideBlankOrUnedited(slide: any): boolean {
646
+ if (!slide) return false
647
+ const els = Array.isArray(slide.elements) ? slide.elements.filter(Boolean) : []
648
+ if (els.length === 0) return true
649
+ return els.every((el: any) => {
650
+ if (el.isPlaceholderReplaced || el.replaced) return false
651
+ return isPlaceholderElement(el)
652
+ })
653
+ }
654
+
432
655
  function insertSingleTemplateSlide(tpl: SlideTemplateItem, slide: any, slideIdx: number) {
433
656
  if (!slide) return
434
657
  addHistorySnapshot()
@@ -439,9 +662,16 @@ function insertSingleTemplateSlide(tpl: SlideTemplateItem, slide: any, slideIdx:
439
662
  if (!cloned.title) {
440
663
  cloned.title = `${tpl.name} - 幻灯片 ${slideIdx + 1}`
441
664
  }
442
- const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
443
- slides.value.splice(insertPos, 0, cloned)
444
- activeIndex.value = insertPos
665
+ const currentIdx = Math.max(0, Math.min(slides.value.length - 1, activeIndex.value))
666
+ const curSlide = slides.value[currentIdx]
667
+ if (curSlide && isSlideBlankOrUnedited(curSlide)) {
668
+ slides.value.splice(currentIdx, 1, cloned)
669
+ activeIndex.value = currentIdx
670
+ } else {
671
+ const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
672
+ slides.value.splice(insertPos, 0, cloned)
673
+ activeIndex.value = insertPos
674
+ }
445
675
  activeSlideVersion.value++
446
676
  displaySlides.value = [...slides.value]
447
677
  addHistorySnapshot()
@@ -462,9 +692,16 @@ function insertAllTemplateSlides(tpl: SlideTemplateItem) {
462
692
  }
463
693
  return cloned
464
694
  })
465
- const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
466
- slides.value.splice(insertPos, 0, ...clonedList)
467
- activeIndex.value = insertPos
695
+ const currentIdx = Math.max(0, Math.min(slides.value.length - 1, activeIndex.value))
696
+ const curSlide = slides.value[currentIdx]
697
+ if (curSlide && isSlideBlankOrUnedited(curSlide)) {
698
+ slides.value.splice(currentIdx, 1, ...clonedList)
699
+ activeIndex.value = currentIdx
700
+ } else {
701
+ const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
702
+ slides.value.splice(insertPos, 0, ...clonedList)
703
+ activeIndex.value = insertPos
704
+ }
468
705
  activeSlideVersion.value++
469
706
  displaySlides.value = [...slides.value]
470
707
  addHistorySnapshot()
@@ -647,7 +884,9 @@ function getLayoutSvgElements(elements: any[]) {
647
884
  rawContentStr.includes('writing-mode:vertical')
648
885
  )
649
886
 
650
- const defaultWidthFallback = isVertical ? ((60 / baseW) * 100) : 0
887
+ const fontSize = parseFloat(el.style?.fontSize || el.fontSize || (isPlaceholder ? (el.placeholder?.type === 'title' ? '28' : '16') : '16')) || 16
888
+
889
+ const defaultWidthFallback = isVertical ? (((fontSize + 24) / baseW) * 100) : 0
651
890
  const rawLeft = parseDimValue(el.style?.left ?? el.left, baseW)
652
891
  const rawTop = parseDimValue(el.style?.top ?? el.top, baseH)
653
892
  const rawWidth = parseDimValue(el.style?.width ?? el.width, baseW, defaultWidthFallback)
@@ -674,12 +913,10 @@ function getLayoutSvgElements(elements: any[]) {
674
913
  ? `translate(${cx}, ${cy}) rotate(${rotate}) scale(${flipH ? -1 : 1}, ${flipV ? -1 : 1}) translate(${-cx}, ${-cy})`
675
914
  : undefined
676
915
 
677
- const fontSize = parseFloat(el.style?.fontSize || el.fontSize || (isPlaceholder ? (el.placeholder?.type === 'title' ? '28' : '16') : '16')) || 16
678
-
679
916
  // 缩略图字体按画布宽高真实几何比例计算,配合微缩优化保持和谐可辨识
680
917
  const baseRatio = 100 / baseW
681
918
  const rawSvgSize = fontSize * baseRatio
682
- const svgFontSize = +(Math.max(1.8, Math.min(4.5, rawSvgSize * 1.15))).toFixed(2)
919
+ const svgFontSize = +(Math.max(1.5, Math.min(7.5, rawSvgSize * 1.05))).toFixed(2)
683
920
 
684
921
  const rawSegments: { text: string; indent: number }[] = []
685
922
  if (rawContentStr) {
@@ -744,8 +981,10 @@ function getLayoutSvgElements(elements: any[]) {
744
981
  const lineHeight = +(svgFontSize * 1.25).toFixed(2)
745
982
  const lineCount = Math.min(parsedTextLines.length, 6)
746
983
  const totalTextH = lineCount * lineHeight
747
- let textStartY = +(y + svgFontSize * 1.05).toFixed(2)
748
- if (h > totalTextH && (el.style?.verticalAlign !== 'top' && el.style?.verticalAlign !== 'up')) {
984
+ const defaultVAlign = (!isVertical && isPlaceholder && h > svgFontSize * 3.8 && fontSize < 32) ? 'top' : 'middle'
985
+ const vAlign = el.verticalAlign || el.style?.verticalAlign || defaultVAlign
986
+ let textStartY = +(y + svgFontSize * 0.95).toFixed(2)
987
+ if (h > totalTextH && (vAlign !== 'top' && vAlign !== 'up')) {
749
988
  // 垂直居中起始 y 坐标
750
989
  textStartY = +(y + (h - totalTextH) / 2 + svgFontSize * 0.85).toFixed(2)
751
990
  }
@@ -773,7 +1012,7 @@ function getLayoutSvgElements(elements: any[]) {
773
1012
  const borderWidth = isPlaceholder ? 1 : (getElementBorderWidth(el) || (el.style?.borderWidth ? parseFloat(el.style.borderWidth) : (el.borderWidth ? parseFloat(el.borderWidth) : 0)))
774
1013
  const hasBorderGrad = hasElementBorderGradient(el)
775
1014
  const borderColor = isPlaceholder ? '#cbd5e1' : ((!hasBorderGrad && borderWidth <= 0) ? 'none' : (getElementBorderColor(el) || parseColorString(el.style?.borderColor || el.borderColor, 'none')))
776
- const textAlign = el.style?.textAlign || el.textAlign || (isTitle && !isVertical ? 'center' : 'left')
1015
+ const textAlign = el.style?.textAlign || el.textAlign || 'left'
777
1016
 
778
1017
  let shapePath = ''
779
1018
  let shapeViewBox: [number, number] = [200, 200]
@@ -1065,6 +1304,14 @@ const addSlideWithLayout = (layoutId: string) => {
1065
1304
  if (isPh) {
1066
1305
  if (cloned.content) cloned.content = convertPrompt(cloned.content)
1067
1306
  if (cloned.text && typeof cloned.text === 'string') cloned.text = convertPrompt(cloned.text)
1307
+ if (cloned.type === 'text' && cloned.style) {
1308
+ const isVert = cloned.style.writingMode === 'vertical-rl' || cloned.style.writingMode === 'vertical-lr'
1309
+ const hPx = parseFloat(cloned.style.height || cloned.height || '0') || 0
1310
+ const fsPx = parseFloat(cloned.style.fontSize || cloned.fontSize || '16') || 16
1311
+ if (!isVert && !cloned.style.verticalAlign && hPx > 150 && fsPx < 34) {
1312
+ cloned.style.verticalAlign = 'top'
1313
+ }
1314
+ }
1068
1315
  return {
1069
1316
  ...cloned,
1070
1317
  id: 'el_' + Date.now().toString(36) + Math.random().toString(36).substring(2, 6),
@@ -2005,6 +2252,16 @@ onUnmounted(() => {
2005
2252
  })
2006
2253
  const masterGroupedLayouts = computed(() => {
2007
2254
  const masters = slideMasters.value || []
2255
+ const normalizePreviewPrompt = (content: string) => {
2256
+ if (typeof content !== 'string') return content
2257
+ return content
2258
+ .replace(/单击此处编辑母版标题样式/g, '单击此处添加标题')
2259
+ .replace(/单击此处编辑母版副标题样式/g, '单击此处添加副标题')
2260
+ .replace(/•\s*编辑母版文本样式 第一级/g, '• 单击此处添加文本')
2261
+ .replace(/•\s*编辑母版文本样式 第二级/g, '')
2262
+ .replace(/<br\s*\/?>&nbsp;&nbsp;/g, '')
2263
+ .replace(/单击此处编辑节标题样式/g, '单击此处添加节标题')
2264
+ }
2008
2265
  return masters.map(master => ({
2009
2266
  id: master.id,
2010
2267
  name: master.name || '默认母版',
@@ -2021,6 +2278,14 @@ const masterGroupedLayouts = computed(() => {
2021
2278
  if (el.id && seenIds.has(el.id)) return false
2022
2279
  if (el.id) seenIds.add(el.id)
2023
2280
  return true
2281
+ }).map((el: any) => {
2282
+ if (el.type === 'text' && typeof el.content === 'string') {
2283
+ return {
2284
+ ...el,
2285
+ content: normalizePreviewPrompt(el.content)
2286
+ }
2287
+ }
2288
+ return el
2024
2289
  })
2025
2290
  return {
2026
2291
  id: layout.id,
@@ -2204,14 +2469,19 @@ const masterGroupedLayouts = computed(() => {
2204
2469
  v-for="(lineObj, lIdx) in item.parsedTextLines.slice(0, 6)"
2205
2470
  :key="lIdx"
2206
2471
  :x="item.isVertical
2207
- ? (item.x + item.w * 0.5)
2472
+ ? (item.x + item.w * 0.5 - (lIdx - (Math.min(item.parsedTextLines.length, 6) - 1) / 2) * item.lineHeight)
2208
2473
  : (item.textAlign === 'center' || item.w < 15
2209
2474
  ? (item.x + item.w * 0.5)
2210
2475
  : (item.textAlign === 'right'
2211
2476
  ? (item.x + item.w - 1)
2212
2477
  : (item.x + (lineObj.indent || 0) * 2.5 + 1)))"
2213
- :y="item.textStartY + lIdx * item.lineHeight"
2214
- :text-anchor="item.isVertical ? 'middle' : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2478
+ :y="item.isVertical
2479
+ ? (item.textAlign === 'center' ? item.yCenter : (item.textAlign === 'right' ? (item.y + item.h - 1.2) : (item.y + 1.2)))
2480
+ : (item.textStartY + lIdx * item.lineHeight)"
2481
+ :text-anchor="item.isVertical
2482
+ ? (item.textAlign === 'center' ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))
2483
+ : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2484
+ :dominant-baseline="item.isVertical ? 'central' : undefined"
2215
2485
  :fill="item.isPlaceholder ? '#94a3b8' : (item.color || '#334155')"
2216
2486
  :font-size="item.svgFontSize"
2217
2487
  font-family="sans-serif"
@@ -2229,9 +2499,12 @@ const masterGroupedLayouts = computed(() => {
2229
2499
  ? item.x + item.w - 1
2230
2500
  : item.x + 1))"
2231
2501
  :y="item.isVertical
2232
- ? item.y + item.svgFontSize * 1.2
2502
+ ? (item.textAlign === 'center' ? item.yCenter : (item.textAlign === 'right' ? (item.y + item.h - 1.2) : (item.y + 1.2)))
2233
2503
  : (item.textStartY || Math.min(thumbSvgHeight - 1, item.y + item.h * 0.5 + item.svgFontSize * 0.35))"
2234
- :text-anchor="item.isVertical ? 'middle' : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2504
+ :text-anchor="item.isVertical
2505
+ ? (item.textAlign === 'center' ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))
2506
+ : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2507
+ :dominant-baseline="item.isVertical ? 'central' : undefined"
2235
2508
  :fill="item.isPlaceholder ? '#94a3b8' : (item.color || '#334155')"
2236
2509
  :font-size="item.svgFontSize"
2237
2510
  font-family="sans-serif"
@@ -2426,14 +2699,19 @@ const masterGroupedLayouts = computed(() => {
2426
2699
  v-for="(lineObj, lIdx) in item.parsedTextLines.slice(0, 6)"
2427
2700
  :key="lIdx"
2428
2701
  :x="item.isVertical
2429
- ? (item.x + item.w * 0.5)
2702
+ ? (item.x + item.w * 0.5 - (lIdx - (Math.min(item.parsedTextLines.length, 6) - 1) / 2) * item.lineHeight)
2430
2703
  : (item.textAlign === 'center' || item.w < 15
2431
2704
  ? (item.x + item.w * 0.5)
2432
2705
  : (item.textAlign === 'right'
2433
2706
  ? (item.x + item.w - 1)
2434
2707
  : (item.x + (lineObj.indent || 0) * 2.5 + 1)))"
2435
- :y="item.textStartY + lIdx * item.lineHeight"
2436
- :text-anchor="item.isVertical ? 'middle' : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2708
+ :y="item.isVertical
2709
+ ? (item.textAlign === 'center' ? item.yCenter : (item.textAlign === 'right' ? (item.y + item.h - 1.2) : (item.y + 1.2)))
2710
+ : (item.textStartY + lIdx * item.lineHeight)"
2711
+ :text-anchor="item.isVertical
2712
+ ? (item.textAlign === 'center' ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))
2713
+ : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2714
+ :dominant-baseline="item.isVertical ? 'central' : undefined"
2437
2715
  :fill="item.isPlaceholder ? '#94a3b8' : (item.color || '#334155')"
2438
2716
  :font-size="item.svgFontSize"
2439
2717
  font-family="sans-serif"
@@ -2451,9 +2729,12 @@ const masterGroupedLayouts = computed(() => {
2451
2729
  ? item.x + item.w - 1
2452
2730
  : item.x + 1))"
2453
2731
  :y="item.isVertical
2454
- ? item.y + item.svgFontSize * 1.2
2732
+ ? (item.textAlign === 'center' ? item.yCenter : (item.textAlign === 'right' ? (item.y + item.h - 1.2) : (item.y + 1.2)))
2455
2733
  : (item.textStartY || Math.min(thumbSvgHeight - 1, item.y + item.h * 0.5 + item.svgFontSize * 0.35))"
2456
- :text-anchor="item.isVertical ? 'middle' : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2734
+ :text-anchor="item.isVertical
2735
+ ? (item.textAlign === 'center' ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))
2736
+ : (item.textAlign === 'center' || item.w < 15 ? 'middle' : (item.textAlign === 'right' ? 'end' : 'start'))"
2737
+ :dominant-baseline="item.isVertical ? 'central' : undefined"
2457
2738
  :fill="item.isPlaceholder ? '#94a3b8' : (item.color || '#334155')"
2458
2739
  :font-size="item.svgFontSize"
2459
2740
  font-family="sans-serif"
@@ -2546,6 +2827,13 @@ const masterGroupedLayouts = computed(() => {
2546
2827
  >
2547
2828
  <span>模板</span>
2548
2829
  </div>
2830
+ <div
2831
+ class="preset-layout-tab"
2832
+ :class="{ 'is-active': presetActiveTab === 'layout-library' }"
2833
+ @click="switchPresetTab('layout-library')"
2834
+ >
2835
+ <span>版式库</span>
2836
+ </div>
2549
2837
  <div
2550
2838
  class="preset-layout-tab"
2551
2839
  :class="{ 'is-active': presetActiveTab === 'layouts' }"
@@ -2571,8 +2859,60 @@ const masterGroupedLayouts = computed(() => {
2571
2859
  </button>
2572
2860
  </div>
2573
2861
 
2862
+ <!-- 版式库分类过滤栏 (参考 Pitch Layouts 顶部分类条) -->
2863
+ <div v-if="presetActiveTab === 'layout-library'" class="preset-layout-category-bar-wrap">
2864
+ <button
2865
+ v-show="canScrollLayoutCatLeft"
2866
+ type="button"
2867
+ class="preset-cat-scroll-btn is-left"
2868
+ title="向左滚动分类"
2869
+ @click.stop="scrollLayoutCategoryBar(-180)"
2870
+ >
2871
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2872
+ <polyline points="15 18 9 12 15 6" />
2873
+ </svg>
2874
+ </button>
2875
+
2876
+ <div
2877
+ ref="layoutCategoryBarRef"
2878
+ class="preset-layout-category-bar"
2879
+ @scroll="updateLayoutCategoryScrollState"
2880
+ >
2881
+ <button
2882
+ type="button"
2883
+ class="preset-layout-category-item"
2884
+ :class="{ 'is-active': activeLayoutLibraryCategory === 'all' }"
2885
+ @click="selectLayoutLibraryCategory('all')"
2886
+ >
2887
+ 全部
2888
+ </button>
2889
+ <button
2890
+ v-for="cat in layoutLibraryCategories"
2891
+ :key="cat"
2892
+ type="button"
2893
+ class="preset-layout-category-item"
2894
+ :class="{ 'is-active': activeLayoutLibraryCategory === cat }"
2895
+ @click="selectLayoutLibraryCategory(cat)"
2896
+ >
2897
+ {{ cat }}
2898
+ </button>
2899
+ </div>
2900
+
2901
+ <button
2902
+ v-show="canScrollLayoutCatRight"
2903
+ type="button"
2904
+ class="preset-cat-scroll-btn is-right"
2905
+ title="向右滚动分类"
2906
+ @click.stop="scrollLayoutCategoryBar(180)"
2907
+ >
2908
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2909
+ <polyline points="9 18 15 12 9 6" />
2910
+ </svg>
2911
+ </button>
2912
+ </div>
2913
+
2574
2914
  <!-- TAB 1: 模板 (Templates) -->
2575
- <div v-if="presetActiveTab === 'templates'" class="preset-layout-body preset-template-body">
2915
+ <div v-if="presetActiveTab === 'templates'" ref="templateBodyRef" class="preset-layout-body preset-template-body">
2576
2916
  <!-- 第一级:模板列表视图 (显示模板封面与名称) -->
2577
2917
  <template v-if="!selectedTemplateDeck">
2578
2918
  <div class="preset-template-search-box">
@@ -2684,7 +3024,43 @@ const masterGroupedLayouts = computed(() => {
2684
3024
  </template>
2685
3025
  </div>
2686
3026
 
2687
- <!-- TAB 2: 版式 (Layouts) -->
3027
+ <!-- TAB 2: 版式库 (Layout Library) -->
3028
+ <div
3029
+ v-else-if="presetActiveTab === 'layout-library'"
3030
+ ref="layoutLibraryBodyRef"
3031
+ class="preset-layout-body preset-layout-library-body"
3032
+ @scroll="handleLayoutLibraryScroll"
3033
+ >
3034
+ <div v-if="layoutLibraryLoading" class="preset-template-empty">
3035
+ 正在加载版式库...
3036
+ </div>
3037
+ <div v-else-if="visibleLayoutLibrarySlides.length > 0" class="preset-layout-grid">
3038
+ <div
3039
+ v-for="(lSlide, lIdx) in visibleLayoutLibrarySlides"
3040
+ :key="lSlide.id || lIdx"
3041
+ class="preset-layout-item preset-template-slide-item"
3042
+ @click="insertLayoutLibrarySlide(lSlide, lIdx)"
3043
+ >
3044
+ <div
3045
+ class="preset-layout-thumb preset-template-slide-thumb"
3046
+ :style="{ background: getSlideBackgroundCss(lSlide.background || '#ffffff') }"
3047
+ >
3048
+ <LayoutThumbSvg
3049
+ :elements="lSlide.elements || []"
3050
+ :background="lSlide.background || '#ffffff'"
3051
+ />
3052
+ </div>
3053
+ <span class="preset-layout-name" :title="lSlide.name || lSlide.title">
3054
+ {{ lSlide.name || lSlide.title }}
3055
+ </span>
3056
+ </div>
3057
+ </div>
3058
+ <div v-else class="preset-template-empty">
3059
+ 暂无该分类下的版式
3060
+ </div>
3061
+ </div>
3062
+
3063
+ <!-- TAB 3: 版式 (Layouts) -->
2688
3064
  <div v-else class="preset-layout-body">
2689
3065
  <div v-for="masterGroup in masterGroupedLayouts" :key="masterGroup.id" class="preset-layout-master-group">
2690
3066
  <div v-if="masterGroupedLayouts.length > 1" class="preset-layout-section-name" :title="masterGroup.name">{{ masterGroup.name }}</div>