jvs-ppt-ui 0.0.33 → 0.0.35
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/dist/lib/jvs-ppt-ui.es.js +20752 -20255
- package/dist/lib/jvs-ppt-ui.umd.js +115 -116
- package/dist/lib/style.css +1 -1
- package/package.json +1 -1
- package/src/components/CanvasArea.vue +85 -37
- package/src/components/PresentationGroupChild.vue +11 -1
- package/src/components/PresentationMode.vue +10 -1
- package/src/components/QuickColorPopover.vue +2 -1
- package/src/components/SidebarLeft.vue +3354 -3212
- package/src/components/SidebarRight.vue +183 -134
- package/src/components/canvas/CanvasTransformHandles.vue +27 -36
- package/src/components/canvas/elements/CanvasShapeElement.vue +3 -2
- package/src/components/canvas/elements/CanvasTextElement.vue +4 -0
- package/src/components/sidebar/panels/LayoutThumbSvg.vue +130 -57
- package/src/components/sidebar/panels/SidebarDesignPanel.vue +7 -14
- package/src/components/sidebar/panels/SidebarShapeFormatPanel.vue +1 -1
- package/src/components/sidebar/panels/SidebarTextFormatPanel.vue +1 -1
- package/src/composables/canvas/useCanvasContextMenu.ts +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/useSidebarDesign.ts +2 -1
- package/src/composables/sidebar/useSidebarElementTransform.ts +87 -58
- package/src/composables/sidebar/useSidebarTextFormat.ts +242 -19
- package/src/composables/useSlides.ts +228 -62
- package/src/configs/slideTemplates.ts +7 -3
- package/src/style.css +3 -3
- package/src/utils/canvas/elementStyles.ts +11 -1
- package/src/utils/canvas/formatPainter.ts +177 -30
|
@@ -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(() => {
|