jvs-ppt-ui 0.0.32 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -0
- package/dist/lib/jvs-ppt-ui.es.js +23678 -21439
- package/dist/lib/jvs-ppt-ui.umd.js +136 -100
- package/dist/lib/style.css +1 -1
- package/package.json +2 -1
- package/src/components/CanvasArea.vue +77 -35
- package/src/components/Header.vue +184 -26
- package/src/components/PitchImportDialog.vue +29 -6
- package/src/components/PptEditor.vue +53 -1
- package/src/components/QuickColorPopover.vue +2 -1
- package/src/components/SidebarLeft.vue +367 -41
- package/src/components/SidebarRight.vue +183 -134
- package/src/components/canvas/CanvasTransformHandles.vue +27 -36
- package/src/components/canvas/elements/CanvasMediaElement.vue +4 -3
- package/src/components/canvas/elements/CanvasShapeElement.vue +9 -6
- package/src/components/sidebar/panels/LayoutThumbSvg.vue +9 -6
- package/src/components/sidebar/panels/SidebarShapeFormatPanel.vue +1 -1
- package/src/components/sidebar/panels/SidebarTextFormatPanel.vue +1 -1
- package/src/composables/canvas/useCanvasFormatting.ts +20 -13
- package/src/composables/canvas/useCanvasText.ts +4 -3
- package/src/composables/canvas/useCanvasTransform.ts +37 -10
- package/src/composables/sidebar/useSidebarElementTransform.ts +86 -57
- package/src/composables/sidebar/useSidebarTextFormat.ts +242 -19
- package/src/composables/useSlides.ts +93 -28
- package/src/configs/slideTemplates.ts +1001 -0
- package/src/style.css +265 -2
- package/src/types/index.ts +37 -1
- package/src/utils/canvas/elementStyles.ts +55 -20
- package/src/utils/canvas/formatPainter.ts +177 -30
- package/src/utils/muxHlsToMp4.ts +569 -0
- package/src/utils/pitchConverter.ts +512 -13
- package/dist/lib/templates/index.json +0 -5
|
@@ -15,7 +15,13 @@ import {
|
|
|
15
15
|
reapplyBlockStylesToListItems
|
|
16
16
|
} from '../../utils/listIndent'
|
|
17
17
|
import { parseColor, hexToRgba } from './useSidebarShapeFormat'
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
getFormatFromElement,
|
|
20
|
+
getFormatFromSelection,
|
|
21
|
+
isTransparentTextBg,
|
|
22
|
+
applyOrClearRangeHighlight,
|
|
23
|
+
applyTextStyleToHtml
|
|
24
|
+
} from '../../utils/canvas/formatPainter'
|
|
19
25
|
import { resolveEffectiveElementFontSize } from '../../utils/canvas/elementStyles'
|
|
20
26
|
import { isEllipseShape } from '../../utils/line'
|
|
21
27
|
import { defaultStyleRecipe } from '../presetThemes'
|
|
@@ -147,6 +153,27 @@ export function useSidebarTextFormat(
|
|
|
147
153
|
.replace(/line-height\s*:\s*[^;"]+;?/gi, '')
|
|
148
154
|
.replace(/color\s*:\s*[^;"]+;?/gi, '')
|
|
149
155
|
}
|
|
156
|
+
|
|
157
|
+
if (el.type === 'text' && el.autoFit?.type !== 'text') {
|
|
158
|
+
const fsNum = parseFloat(newSize) || typeConf.defaultFontSize || 18
|
|
159
|
+
const lhNum = parseFloat(String(newLineHeight)) || typeConf.defaultLineHeight || 1.2
|
|
160
|
+
const isVert = el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr'
|
|
161
|
+
if (isVert) {
|
|
162
|
+
const minW = Math.max(48, Math.ceil(fsNum * lhNum + 16))
|
|
163
|
+
const curW = parseFloat(el.style?.width) || el.width || 0
|
|
164
|
+
if (curW > 0 && curW < minW && el.style?.width !== 'auto') {
|
|
165
|
+
el.style.width = `${minW}px`
|
|
166
|
+
el.width = minW
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
const minH = Math.max(typeConf.defaultHeight || 36, Math.ceil(fsNum * lhNum + 12))
|
|
170
|
+
const curH = parseFloat(el.style?.height) || el.height || 0
|
|
171
|
+
if (curH > 0 && curH < minH && el.style?.height !== 'auto') {
|
|
172
|
+
el.style.height = `${minH}px`
|
|
173
|
+
el.height = minH
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
150
177
|
}
|
|
151
178
|
|
|
152
179
|
addHistorySnapshot()
|
|
@@ -311,23 +338,187 @@ export function useSidebarTextFormat(
|
|
|
311
338
|
}
|
|
312
339
|
})
|
|
313
340
|
|
|
341
|
+
function extractBackgroundColorFromHtml(html: string | undefined | null): string | null {
|
|
342
|
+
if (!html || typeof html !== 'string') return null
|
|
343
|
+
const clean = html.replace(/<[^>]*>/g, '').replace(/ /gi, '').trim()
|
|
344
|
+
if (!clean) return null
|
|
345
|
+
|
|
346
|
+
if (typeof document !== 'undefined') {
|
|
347
|
+
const div = document.createElement('div')
|
|
348
|
+
div.innerHTML = html
|
|
349
|
+
const inlineNodes = div.querySelectorAll('span, font, mark, b, strong, i, em, u, s, a')
|
|
350
|
+
for (const node of Array.from(inlineNodes)) {
|
|
351
|
+
const bg = (node as HTMLElement).style?.backgroundColor
|
|
352
|
+
if (bg && !isTransparentTextBg(bg)) {
|
|
353
|
+
return colorToHex(bg)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const bgMatch = html.match(/background-color\s*:\s*([^;'"\}]+)/i)
|
|
359
|
+
if (bgMatch && bgMatch[1]) {
|
|
360
|
+
const rawBg = bgMatch[1].trim()
|
|
361
|
+
if (!isTransparentTextBg(rawBg)) {
|
|
362
|
+
return colorToHex(rawBg)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return null
|
|
366
|
+
}
|
|
367
|
+
|
|
314
368
|
const styleTextBackground = computed({
|
|
315
|
-
get() {
|
|
369
|
+
get() {
|
|
370
|
+
selectionTrigger.value
|
|
371
|
+
const el = selectedElement.value as any
|
|
372
|
+
if (!el) return 'transparent'
|
|
373
|
+
|
|
374
|
+
// 1. 若存在当前选区或保存的选区,优先读取选区文字的高亮背景色
|
|
375
|
+
if (typeof window !== 'undefined') {
|
|
376
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
377
|
+
if (container) {
|
|
378
|
+
const sel = window.getSelection()
|
|
379
|
+
const activeRange = (sel && sel.rangeCount > 0 && container.contains(sel.getRangeAt(0).commonAncestorContainer))
|
|
380
|
+
? sel.getRangeAt(0)
|
|
381
|
+
: (savedSidebarRange && container.contains(savedSidebarRange.commonAncestorContainer) ? savedSidebarRange : null)
|
|
382
|
+
|
|
383
|
+
if (activeRange) {
|
|
384
|
+
const blockTags = new Set(['P', 'DIV', 'LI', 'UL', 'OL', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'TD', 'TH', 'TABLE'])
|
|
385
|
+
let startNode: Node | null = activeRange.startContainer
|
|
386
|
+
if (startNode.nodeType === Node.ELEMENT_NODE && startNode.childNodes[activeRange.startOffset]) {
|
|
387
|
+
startNode = startNode.childNodes[activeRange.startOffset]
|
|
388
|
+
}
|
|
389
|
+
let curr: Node | null = startNode?.nodeType === Node.TEXT_NODE ? startNode.parentElement : startNode
|
|
390
|
+
while (curr && curr !== container) {
|
|
391
|
+
if (curr instanceof HTMLElement && !blockTags.has(curr.tagName)) {
|
|
392
|
+
const inlineBg = curr.style?.backgroundColor
|
|
393
|
+
if (inlineBg && !isTransparentTextBg(inlineBg)) {
|
|
394
|
+
return colorToHex(inlineBg)
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
curr = curr.parentElement
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (!activeRange.collapsed) {
|
|
401
|
+
const inlineEls = container.querySelectorAll('span, font, mark, b, strong, i, em, u, s, a')
|
|
402
|
+
for (const node of Array.from(inlineEls)) {
|
|
403
|
+
if (activeRange.intersectsNode(node)) {
|
|
404
|
+
const bg = (node as HTMLElement).style?.backgroundColor
|
|
405
|
+
if (bg && !isTransparentTextBg(bg)) {
|
|
406
|
+
return colorToHex(bg)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const elBg = getStyleVal('textBackground', 'transparent')
|
|
411
|
+
return (!elBg || isTransparentTextBg(elBg)) ? 'transparent' : colorToHex(elBg)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// 2. 元素级 style.textBackground
|
|
418
|
+
const styleBg = getStyleVal('textBackground', '')
|
|
419
|
+
if (styleBg && !isTransparentTextBg(styleBg)) {
|
|
420
|
+
return colorToHex(styleBg)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// 3. 从元素 HTML 内容或实时容器提取高亮色
|
|
424
|
+
const container = typeof document !== 'undefined' ? document.getElementById(`editable-${el.id}`) : null
|
|
425
|
+
const liveHtml = container?.innerHTML
|
|
426
|
+
const rawHtml = liveHtml || (el.type === 'shape'
|
|
427
|
+
? (typeof el.text === 'string' ? el.text : el.text?.content)
|
|
428
|
+
: el.content)
|
|
429
|
+
const fromHtml = extractBackgroundColorFromHtml(rawHtml)
|
|
430
|
+
if (fromHtml) return fromHtml
|
|
431
|
+
|
|
432
|
+
if (el.type === 'group' && Array.isArray(el.elements)) {
|
|
433
|
+
for (const child of el.elements) {
|
|
434
|
+
if (child.style?.textBackground && !isTransparentTextBg(child.style.textBackground)) {
|
|
435
|
+
return colorToHex(child.style.textBackground)
|
|
436
|
+
}
|
|
437
|
+
const childHtml = child.type === 'shape'
|
|
438
|
+
? (typeof child.text === 'string' ? child.text : child.text?.content)
|
|
439
|
+
: child.content
|
|
440
|
+
const childBg = extractBackgroundColorFromHtml(childHtml)
|
|
441
|
+
if (childBg) return childBg
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
return 'transparent'
|
|
446
|
+
},
|
|
316
447
|
set(val: string) {
|
|
317
|
-
|
|
448
|
+
const normalizedVal = isTransparentTextBg(val) ? 'transparent' : val
|
|
318
449
|
const el = selectedElement.value as any
|
|
450
|
+
|
|
451
|
+
// 1. 若当前存在非折叠的富文本划词选区,优先仅对选区应用或清除高亮色
|
|
452
|
+
if (el && typeof window !== 'undefined') {
|
|
453
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
454
|
+
const sel = window.getSelection()
|
|
455
|
+
const activeRange = (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed && container && container.contains(sel.getRangeAt(0).commonAncestorContainer))
|
|
456
|
+
? sel.getRangeAt(0)
|
|
457
|
+
: (savedSidebarRange && !savedSidebarRange.collapsed && container && container.contains(savedSidebarRange.commonAncestorContainer) ? savedSidebarRange : null)
|
|
458
|
+
|
|
459
|
+
if (activeRange && !activeRange.collapsed && container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
460
|
+
const updatedRange = applyOrClearRangeHighlight(container, activeRange, normalizedVal, el)
|
|
461
|
+
if (updatedRange) {
|
|
462
|
+
savedSidebarRange = updatedRange
|
|
463
|
+
}
|
|
464
|
+
container.style.backgroundColor = el.type === 'text' ? (el.style?.fill || 'transparent') : ''
|
|
465
|
+
if (el.type === 'shape') {
|
|
466
|
+
if (el.text && typeof el.text === 'object') {
|
|
467
|
+
el.text.content = container.innerHTML
|
|
468
|
+
} else {
|
|
469
|
+
el.text = container.innerHTML
|
|
470
|
+
}
|
|
471
|
+
} else {
|
|
472
|
+
el.content = container.innerHTML
|
|
473
|
+
}
|
|
474
|
+
selectionTrigger.value++
|
|
475
|
+
addHistorySnapshot()
|
|
476
|
+
return
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// 2. 整框应用或清除前,若容器内已有最新编辑的 HTML,先同步到元素模型,防止丢失或漏清内联高亮
|
|
480
|
+
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
481
|
+
const currentDomHtml = container.innerHTML
|
|
482
|
+
if (currentDomHtml && currentDomHtml.trim()) {
|
|
483
|
+
if (el.type === 'shape') {
|
|
484
|
+
if (el.text && typeof el.text === 'object') {
|
|
485
|
+
el.text.content = currentDomHtml
|
|
486
|
+
} else {
|
|
487
|
+
el.text = currentDomHtml
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
el.content = currentDomHtml
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// 3. 整框应用或清除高亮色
|
|
497
|
+
setStyleVal('textBackground', normalizedVal)
|
|
319
498
|
if (el) {
|
|
499
|
+
if (!el.style) el.style = {}
|
|
500
|
+
el.style.textBackground = normalizedVal
|
|
320
501
|
const container = document.getElementById(`editable-${el.id}`)
|
|
321
|
-
if (container) {
|
|
322
|
-
container.style.backgroundColor = ''
|
|
502
|
+
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
503
|
+
container.style.backgroundColor = el.type === 'text' ? (el.style?.fill || 'transparent') : ''
|
|
323
504
|
if (el.type === 'shape') {
|
|
324
|
-
const raw = typeof el.text === 'string' ? el.text : (el.text?.content || '')
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
505
|
+
const raw = typeof el.text === 'string' ? el.text : (el.text?.content || container.innerHTML || '')
|
|
506
|
+
const formatted = applyTextStyleToHtml(raw, { textBackground: normalizedVal })
|
|
507
|
+
if (el.text && typeof el.text === 'object') {
|
|
508
|
+
el.text.content = formatted
|
|
509
|
+
} else {
|
|
510
|
+
el.text = formatted
|
|
511
|
+
}
|
|
512
|
+
container.innerHTML = formatted
|
|
513
|
+
} else {
|
|
514
|
+
const raw = el.content || container.innerHTML || ''
|
|
515
|
+
const formatted = applyTextStyleToHtml(raw, { textBackground: normalizedVal })
|
|
516
|
+
el.content = formatted
|
|
517
|
+
container.innerHTML = formatted
|
|
328
518
|
}
|
|
329
519
|
}
|
|
330
520
|
}
|
|
521
|
+
selectionTrigger.value++
|
|
331
522
|
}
|
|
332
523
|
})
|
|
333
524
|
|
|
@@ -351,10 +542,26 @@ export function useSidebarTextFormat(
|
|
|
351
542
|
if (dom) {
|
|
352
543
|
if (!selectedElement.value.style) selectedElement.value.style = {} as any
|
|
353
544
|
selectedElement.value.style.height = `${dom.offsetHeight}px`
|
|
545
|
+
selectedElement.value.height = dom.offsetHeight
|
|
546
|
+
if (selectedElement.value.autoFit?.type === 'shape') {
|
|
547
|
+
selectedElement.value.style.width = 'auto'
|
|
548
|
+
} else if (!selectedElement.value.style.width || selectedElement.value.style.width === 'auto') {
|
|
549
|
+
selectedElement.value.style.width = `${dom.offsetWidth}px`
|
|
550
|
+
selectedElement.value.width = dom.offsetWidth
|
|
551
|
+
}
|
|
354
552
|
}
|
|
355
553
|
} else if (isPrevVertical && !isNextVertical) {
|
|
356
|
-
|
|
554
|
+
const dom = document.getElementById(`canvas-el-${selectedElement.value.id}`)
|
|
555
|
+
if (!selectedElement.value.style) selectedElement.value.style = {} as any
|
|
556
|
+
if (dom && (!selectedElement.value.style.width || selectedElement.value.style.width === 'auto')) {
|
|
557
|
+
selectedElement.value.style.width = `${dom.offsetWidth}px`
|
|
558
|
+
selectedElement.value.width = dom.offsetWidth
|
|
559
|
+
}
|
|
560
|
+
if (selectedElement.value.autoFit?.type === 'shape') {
|
|
357
561
|
selectedElement.value.style.height = 'auto'
|
|
562
|
+
} else if (dom && (!selectedElement.value.style.height || selectedElement.value.style.height === 'auto')) {
|
|
563
|
+
selectedElement.value.style.height = `${dom.offsetHeight}px`
|
|
564
|
+
selectedElement.value.height = dom.offsetHeight
|
|
358
565
|
}
|
|
359
566
|
}
|
|
360
567
|
}
|
|
@@ -428,16 +635,16 @@ export function useSidebarTextFormat(
|
|
|
428
635
|
const styleAutoFitType = computed({
|
|
429
636
|
get() {
|
|
430
637
|
const el = selectedElement.value as any
|
|
431
|
-
if (!el) return '
|
|
432
|
-
if (
|
|
433
|
-
return
|
|
638
|
+
if (!el) return 'none'
|
|
639
|
+
if (el.autoFit && el.autoFit.type) {
|
|
640
|
+
return el.autoFit.type
|
|
434
641
|
}
|
|
435
|
-
return
|
|
642
|
+
return 'none'
|
|
436
643
|
},
|
|
437
644
|
set(val: string) {
|
|
438
645
|
const el = selectedElement.value as any
|
|
439
646
|
if (!el) return
|
|
440
|
-
const current = el.autoFit?.type ||
|
|
647
|
+
const current = el.autoFit?.type || 'none'
|
|
441
648
|
if (current === val && el.autoFit) return
|
|
442
649
|
|
|
443
650
|
el.autoFit = {
|
|
@@ -450,11 +657,13 @@ export function useSidebarTextFormat(
|
|
|
450
657
|
const dom = document.getElementById(`canvas-el-${el.id}`)
|
|
451
658
|
if (dom) {
|
|
452
659
|
if (!el.style) el.style = {}
|
|
453
|
-
if (el.style.height === 'auto') {
|
|
660
|
+
if (!el.style.height || el.style.height === 'auto') {
|
|
454
661
|
el.style.height = `${dom.offsetHeight}px`
|
|
662
|
+
el.height = dom.offsetHeight
|
|
455
663
|
}
|
|
456
|
-
if (el.style.width === 'auto') {
|
|
664
|
+
if (!el.style.width || el.style.width === 'auto') {
|
|
457
665
|
el.style.width = `${dom.offsetWidth}px`
|
|
666
|
+
el.width = dom.offsetWidth
|
|
458
667
|
}
|
|
459
668
|
}
|
|
460
669
|
} else if (val === 'shape') {
|
|
@@ -462,8 +671,20 @@ export function useSidebarTextFormat(
|
|
|
462
671
|
if (!el.style) el.style = {}
|
|
463
672
|
if (el.style.writingMode === 'vertical-rl' || el.style.writingMode === 'vertical-lr') {
|
|
464
673
|
el.style.width = 'auto'
|
|
674
|
+
nextTick(() => {
|
|
675
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
676
|
+
const dom = document.getElementById(`canvas-el-${el.id}`)
|
|
677
|
+
const actualW = Math.max(container?.scrollWidth || 0, container?.offsetWidth || 0, dom?.offsetWidth || 0)
|
|
678
|
+
if (actualW > 0) el.width = actualW
|
|
679
|
+
})
|
|
465
680
|
} else {
|
|
466
681
|
el.style.height = 'auto'
|
|
682
|
+
nextTick(() => {
|
|
683
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
684
|
+
const dom = document.getElementById(`canvas-el-${el.id}`)
|
|
685
|
+
const actualH = Math.max(container?.offsetHeight || 0, container?.scrollHeight || 0, dom?.offsetHeight || 0)
|
|
686
|
+
if (actualH > 0) el.height = actualH
|
|
687
|
+
})
|
|
467
688
|
}
|
|
468
689
|
} else if (el.type === 'shape') {
|
|
469
690
|
nextTick(() => {
|
|
@@ -497,11 +718,13 @@ export function useSidebarTextFormat(
|
|
|
497
718
|
const dom = document.getElementById(`canvas-el-${el.id}`)
|
|
498
719
|
if (dom) {
|
|
499
720
|
if (!el.style) el.style = {}
|
|
500
|
-
if (el.style.height === 'auto') {
|
|
721
|
+
if (!el.style.height || el.style.height === 'auto') {
|
|
501
722
|
el.style.height = `${dom.offsetHeight}px`
|
|
723
|
+
el.height = dom.offsetHeight
|
|
502
724
|
}
|
|
503
|
-
if (el.style.width === 'auto') {
|
|
725
|
+
if (!el.style.width || el.style.width === 'auto') {
|
|
504
726
|
el.style.width = `${dom.offsetWidth}px`
|
|
727
|
+
el.width = dom.offsetWidth
|
|
505
728
|
}
|
|
506
729
|
}
|
|
507
730
|
nextTick(() => {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '../utils/textTypes'
|
|
15
15
|
import { applyGroupGeometryFlip } from '../utils/groupFlip'
|
|
16
16
|
import { getFontVariants, getFontVariantStyle } from '../configs/fonts'
|
|
17
|
+
import { setCustomTemplates, customTemplateBaseUrl, type SlideTemplateInput } from '../configs/slideTemplates'
|
|
17
18
|
import type { CustomUploadHandler, UploadResourceContext, UploadResourceType } from '../types'
|
|
18
19
|
|
|
19
20
|
export type { SlideTextType }
|
|
@@ -302,7 +303,7 @@ export interface PresetTheme {
|
|
|
302
303
|
|
|
303
304
|
import { presetThemes, builtinStyleRecipes, type StyleRecipe } from './presetThemes'
|
|
304
305
|
import { generateMonoPalette } from '../utils/palette'
|
|
305
|
-
import { isPitchTemplateData, convertPitchTemplateToDeck } from '../utils/pitchConverter'
|
|
306
|
+
import { isPitchTemplateData, convertPitchTemplateToDeck, stringifyDeckToBlob } from '../utils/pitchConverter'
|
|
306
307
|
|
|
307
308
|
// Global reactive states
|
|
308
309
|
const presentationTitle = ref('未命名演示文稿')
|
|
@@ -415,6 +416,31 @@ function setMaterialConfig(config?: {
|
|
|
415
416
|
}
|
|
416
417
|
}
|
|
417
418
|
|
|
419
|
+
// 模板库配置状态(控制左侧“更多布局”中是否启用“模板”库及传入自定义模板)
|
|
420
|
+
const enableTemplate = ref<boolean>(true)
|
|
421
|
+
const isTemplateEnabled = computed(() => enableTemplate.value !== false)
|
|
422
|
+
|
|
423
|
+
function setTemplateConfig(config?: {
|
|
424
|
+
enable?: boolean
|
|
425
|
+
templates?: SlideTemplateInput[]
|
|
426
|
+
baseUrl?: string
|
|
427
|
+
replaceBuiltin?: boolean
|
|
428
|
+
}) {
|
|
429
|
+
if (!config) return
|
|
430
|
+
if (config.enable !== undefined) {
|
|
431
|
+
enableTemplate.value = Boolean(config.enable)
|
|
432
|
+
}
|
|
433
|
+
if (config.baseUrl !== undefined) {
|
|
434
|
+
customTemplateBaseUrl.value = (config.baseUrl || '').trim()
|
|
435
|
+
}
|
|
436
|
+
if (config.templates !== undefined && Array.isArray(config.templates)) {
|
|
437
|
+
setCustomTemplates(config.templates, {
|
|
438
|
+
replaceBuiltin: config.replaceBuiltin !== undefined ? config.replaceBuiltin : true,
|
|
439
|
+
baseUrl: config.baseUrl
|
|
440
|
+
})
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
418
444
|
/**
|
|
419
445
|
* 保存幻灯片到素材库 API
|
|
420
446
|
*/
|
|
@@ -4522,7 +4548,7 @@ function addElement(
|
|
|
4522
4548
|
const lineHeight = textCfg.lineHeight || typeConf.defaultLineHeight
|
|
4523
4549
|
const letterSpacing = textCfg.letterSpacing !== undefined ? `${textCfg.letterSpacing}px` : '0px'
|
|
4524
4550
|
const defaultW = typeConf.defaultWidth
|
|
4525
|
-
const defaultH = typeConf.defaultHeight
|
|
4551
|
+
const defaultH = Math.max(typeConf.defaultHeight, Math.ceil((parseFloat(fontSize) || typeConf.defaultFontSize) * (parseFloat(String(lineHeight)) || 1.2) + 12))
|
|
4526
4552
|
|
|
4527
4553
|
content = customContent || `<div style="color:${textColor}; font-family:${textFont}; font-size:${fontSize}; font-weight:${fontWeight};">${typeConf.defaultPlaceholder}</div>`
|
|
4528
4554
|
style = {
|
|
@@ -4538,7 +4564,7 @@ function addElement(
|
|
|
4538
4564
|
lineHeight: lineHeight,
|
|
4539
4565
|
letterSpacing: letterSpacing,
|
|
4540
4566
|
width: initialDimensions?.width !== undefined ? `${initialDimensions.width}px` : (latex ? 'auto' : `${defaultW}px`),
|
|
4541
|
-
height: initialDimensions?.height !== undefined ? `${initialDimensions.height}px` : 'auto',
|
|
4567
|
+
height: initialDimensions?.height !== undefined ? `${initialDimensions.height}px` : (latex ? 'auto' : `${defaultH}px`),
|
|
4542
4568
|
whiteSpace: 'normal',
|
|
4543
4569
|
verticalAlign: 'middle'
|
|
4544
4570
|
}
|
|
@@ -4648,7 +4674,7 @@ function addElement(
|
|
|
4648
4674
|
newElement.textColor = style.color
|
|
4649
4675
|
newElement.fontFamily = style.fontFamily
|
|
4650
4676
|
newElement.autoFit = {
|
|
4651
|
-
type: '
|
|
4677
|
+
type: 'none',
|
|
4652
4678
|
fontScale: 100,
|
|
4653
4679
|
lnSpcReduction: 0
|
|
4654
4680
|
}
|
|
@@ -4777,14 +4803,14 @@ function addElementAt(
|
|
|
4777
4803
|
fontStyle: 'normal',
|
|
4778
4804
|
fontSize: '20px',
|
|
4779
4805
|
width: '260px',
|
|
4780
|
-
height: '
|
|
4806
|
+
height: '40px',
|
|
4781
4807
|
rotate: 0,
|
|
4782
4808
|
writingMode: 'horizontal-tb',
|
|
4783
4809
|
whiteSpace: 'normal',
|
|
4784
4810
|
verticalAlign: 'middle'
|
|
4785
4811
|
}
|
|
4786
4812
|
if (subtype === 'vertical') {
|
|
4787
|
-
style.width = '
|
|
4813
|
+
style.width = '48px'
|
|
4788
4814
|
style.height = '180px'
|
|
4789
4815
|
style.writingMode = 'vertical-rl'
|
|
4790
4816
|
}
|
|
@@ -4900,7 +4926,7 @@ function addElementAt(
|
|
|
4900
4926
|
newElement.textColor = style.color
|
|
4901
4927
|
newElement.fontFamily = style.fontFamily
|
|
4902
4928
|
newElement.autoFit = {
|
|
4903
|
-
type: '
|
|
4929
|
+
type: 'none',
|
|
4904
4930
|
fontScale: 100,
|
|
4905
4931
|
lnSpcReduction: 0
|
|
4906
4932
|
}
|
|
@@ -5737,10 +5763,10 @@ function exportSlides(options?: { excludeImages?: boolean; clearContent?: boolea
|
|
|
5737
5763
|
const { excludeImages = false, clearContent = false } = options || {}
|
|
5738
5764
|
notify(excludeImages || clearContent ? '正在导出纯版式 JSON 模板...' : '正在导出幻灯片 JSON 配置...')
|
|
5739
5765
|
|
|
5740
|
-
const rawSlides =
|
|
5766
|
+
const rawSlides = slides.value || []
|
|
5741
5767
|
|
|
5742
5768
|
const processedSlides = rawSlides.map((slide: any) => {
|
|
5743
|
-
let elements = slide.elements
|
|
5769
|
+
let elements = Array.isArray(slide.elements) ? [...slide.elements] : []
|
|
5744
5770
|
|
|
5745
5771
|
if (excludeImages) {
|
|
5746
5772
|
elements = elements.filter((el: any) => el.type !== 'image' && el.type !== 'audio' && el.type !== 'video')
|
|
@@ -5776,8 +5802,12 @@ function exportSlides(options?: { excludeImages?: boolean; clearContent?: boolea
|
|
|
5776
5802
|
}
|
|
5777
5803
|
|
|
5778
5804
|
let background = slide.background
|
|
5779
|
-
if (excludeImages && background
|
|
5780
|
-
|
|
5805
|
+
if (excludeImages && background) {
|
|
5806
|
+
if (typeof background === 'object' && background.type === 'image') {
|
|
5807
|
+
background = { type: 'solid', color: '#ffffff' }
|
|
5808
|
+
} else if (typeof background === 'string' && background.includes('url(')) {
|
|
5809
|
+
background = '#ffffff'
|
|
5810
|
+
}
|
|
5781
5811
|
}
|
|
5782
5812
|
|
|
5783
5813
|
return {
|
|
@@ -5788,24 +5818,32 @@ function exportSlides(options?: { excludeImages?: boolean; clearContent?: boolea
|
|
|
5788
5818
|
})
|
|
5789
5819
|
|
|
5790
5820
|
// 🌟 导出母版内容:确保导出的完整 JSON 包含母版与其全部版式定义
|
|
5791
|
-
const rawMasters =
|
|
5821
|
+
const rawMasters = slideMasters.value || []
|
|
5792
5822
|
const processedMasters = rawMasters.map((master: any) => {
|
|
5793
|
-
let elements = master.elements
|
|
5823
|
+
let elements = Array.isArray(master.elements) ? [...master.elements] : []
|
|
5794
5824
|
if (excludeImages) {
|
|
5795
5825
|
elements = elements.filter((el: any) => el.type !== 'image' && el.type !== 'audio' && el.type !== 'video')
|
|
5796
5826
|
}
|
|
5797
5827
|
let background = master.background
|
|
5798
|
-
if (excludeImages && background
|
|
5799
|
-
|
|
5828
|
+
if (excludeImages && background) {
|
|
5829
|
+
if (typeof background === 'object' && background.type === 'image') {
|
|
5830
|
+
background = { type: 'solid', color: '#ffffff' }
|
|
5831
|
+
} else if (typeof background === 'string' && background.includes('url(')) {
|
|
5832
|
+
background = '#ffffff'
|
|
5833
|
+
}
|
|
5800
5834
|
}
|
|
5801
5835
|
const layouts = (master.layouts || []).map((layout: any) => {
|
|
5802
|
-
let lElements = layout.elements
|
|
5836
|
+
let lElements = Array.isArray(layout.elements) ? [...layout.elements] : []
|
|
5803
5837
|
if (excludeImages) {
|
|
5804
5838
|
lElements = lElements.filter((el: any) => el.type !== 'image' && el.type !== 'audio' && el.type !== 'video')
|
|
5805
5839
|
}
|
|
5806
5840
|
let lBg = layout.background
|
|
5807
|
-
if (excludeImages && lBg
|
|
5808
|
-
|
|
5841
|
+
if (excludeImages && lBg) {
|
|
5842
|
+
if (typeof lBg === 'object' && lBg.type === 'image') {
|
|
5843
|
+
lBg = { type: 'solid', color: '#ffffff' }
|
|
5844
|
+
} else if (typeof lBg === 'string' && lBg.includes('url(')) {
|
|
5845
|
+
lBg = '#ffffff'
|
|
5846
|
+
}
|
|
5809
5847
|
}
|
|
5810
5848
|
return {
|
|
5811
5849
|
...layout,
|
|
@@ -5841,13 +5879,21 @@ function exportSlides(options?: { excludeImages?: boolean; clearContent?: boolea
|
|
|
5841
5879
|
}
|
|
5842
5880
|
|
|
5843
5881
|
const filenameSuffix = excludeImages || clearContent ? '-template' : ''
|
|
5844
|
-
const
|
|
5882
|
+
const blob = stringifyDeckToBlob(json)
|
|
5883
|
+
const blobUrl = URL.createObjectURL(blob)
|
|
5845
5884
|
const downloadAnchor = document.createElement('a')
|
|
5846
|
-
downloadAnchor.setAttribute(
|
|
5847
|
-
downloadAnchor.setAttribute(
|
|
5885
|
+
downloadAnchor.setAttribute('href', blobUrl)
|
|
5886
|
+
downloadAnchor.setAttribute('download', `${presentationTitle.value}${filenameSuffix}-${Date.now()}.json`)
|
|
5848
5887
|
document.body.appendChild(downloadAnchor)
|
|
5849
5888
|
downloadAnchor.click()
|
|
5850
5889
|
downloadAnchor.remove()
|
|
5890
|
+
setTimeout(() => {
|
|
5891
|
+
try {
|
|
5892
|
+
URL.revokeObjectURL(blobUrl)
|
|
5893
|
+
} catch {
|
|
5894
|
+
// ignore
|
|
5895
|
+
}
|
|
5896
|
+
}, 60000)
|
|
5851
5897
|
}
|
|
5852
5898
|
|
|
5853
5899
|
function extractTextStyleFromHtml(html: string, defaultColor: string, defaultFont: string) {
|
|
@@ -7494,7 +7540,7 @@ function convertPPTistToLocalIfNeed(newSlides: any): Slide[] {
|
|
|
7494
7540
|
content: content,
|
|
7495
7541
|
text: text,
|
|
7496
7542
|
style: style,
|
|
7497
|
-
autoFit: el.autoFit
|
|
7543
|
+
autoFit: el.autoFit ? { ...el.autoFit } : (type === 'text' ? { type: 'none', fontScale: 100, lnSpcReduction: 0 } : undefined),
|
|
7498
7544
|
viewBox: el.viewBox,
|
|
7499
7545
|
path: (type === 'shape' && content && (content.startsWith('M') || content.startsWith('m'))) ? content : el.path,
|
|
7500
7546
|
start: start,
|
|
@@ -9156,14 +9202,21 @@ async function uploadMediaResourcesInSlides(deckOrSlides: any): Promise<void> {
|
|
|
9156
9202
|
el.content = remote
|
|
9157
9203
|
}
|
|
9158
9204
|
} else if (el.type === 'video') {
|
|
9159
|
-
|
|
9160
|
-
|
|
9205
|
+
const targetSrc = el.src || el.content
|
|
9206
|
+
if (shouldUpload(targetSrc)) {
|
|
9207
|
+
const remote = await uploadMediaUrl(targetSrc, 'video', 'mp4')
|
|
9161
9208
|
el.src = remote
|
|
9209
|
+
el.content = remote
|
|
9210
|
+
}
|
|
9211
|
+
if (el.poster && shouldUpload(el.poster)) {
|
|
9212
|
+
el.poster = await uploadMediaUrl(el.poster, 'image', 'jpg')
|
|
9162
9213
|
}
|
|
9163
9214
|
} else if (el.type === 'audio') {
|
|
9164
|
-
|
|
9165
|
-
|
|
9215
|
+
const targetSrc = el.src || el.content
|
|
9216
|
+
if (shouldUpload(targetSrc)) {
|
|
9217
|
+
const remote = await uploadMediaUrl(targetSrc, 'audio', 'mp3')
|
|
9166
9218
|
el.src = remote
|
|
9219
|
+
el.content = remote
|
|
9167
9220
|
}
|
|
9168
9221
|
} else if (el.type === 'math') {
|
|
9169
9222
|
const targetSrc = el.src || el.picBlob || el.picBase64
|
|
@@ -9179,6 +9232,11 @@ async function uploadMediaResourcesInSlides(deckOrSlides: any): Promise<void> {
|
|
|
9179
9232
|
if (el.style) el.style.pattern = remote
|
|
9180
9233
|
}
|
|
9181
9234
|
}
|
|
9235
|
+
if (Array.isArray(el.elements)) {
|
|
9236
|
+
for (const child of el.elements) {
|
|
9237
|
+
await processElement(child)
|
|
9238
|
+
}
|
|
9239
|
+
}
|
|
9182
9240
|
}
|
|
9183
9241
|
|
|
9184
9242
|
const processBackground = async (item: any) => {
|
|
@@ -9194,9 +9252,13 @@ async function uploadMediaResourcesInSlides(deckOrSlides: any): Promise<void> {
|
|
|
9194
9252
|
item.background = remote
|
|
9195
9253
|
}
|
|
9196
9254
|
} else if (item.background && typeof item.background === 'object') {
|
|
9197
|
-
|
|
9198
|
-
|
|
9255
|
+
const bgTarget = item.background.image?.src || item.background.value
|
|
9256
|
+
if (item.background.type === 'image' && shouldUpload(bgTarget)) {
|
|
9257
|
+
const remote = await uploadMediaUrl(bgTarget, 'image', 'jpg')
|
|
9199
9258
|
item.background.value = remote
|
|
9259
|
+
if (item.background.image && typeof item.background.image === 'object') {
|
|
9260
|
+
item.background.image.src = remote
|
|
9261
|
+
}
|
|
9200
9262
|
}
|
|
9201
9263
|
}
|
|
9202
9264
|
}
|
|
@@ -9906,6 +9968,9 @@ export function useSlides() {
|
|
|
9906
9968
|
enableMaterial,
|
|
9907
9969
|
isMaterialEnabled,
|
|
9908
9970
|
setMaterialConfig,
|
|
9971
|
+
enableTemplate,
|
|
9972
|
+
isTemplateEnabled,
|
|
9973
|
+
setTemplateConfig,
|
|
9909
9974
|
saveCurrentSlideToMaterial,
|
|
9910
9975
|
placeholderMaterialTargetId,
|
|
9911
9976
|
setPlaceholderMaterialTargetId,
|