jvs-ppt-ui 0.0.25 → 0.0.27

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jvs-ppt-ui",
3
3
  "private": false,
4
- "version": "0.0.25",
4
+ "version": "0.0.27",
5
5
  "type": "module",
6
6
  "main": "./dist/lib/jvs-ppt-ui.umd.js",
7
7
  "module": "./dist/lib/jvs-ppt-ui.es.js",
@@ -2,6 +2,7 @@
2
2
  import { ref, computed, watch, onMounted, onBeforeUnmount, nextTick, useSlots, getCurrentInstance, defineAsyncComponent, toRaw, type Ref } from 'vue'
3
3
  import jvsPickerColorV3 from 'jvs-picker-color-v3'
4
4
  import '../assets/iconfont/iconfont.js'
5
+ import '../../public/jvs-ppt-ui/fonts/fonts.css'
5
6
  import { saveAs } from 'file-saver'
6
7
  import Header from './Header.vue'
7
8
  import Toolbar from './Toolbar.vue'
@@ -926,7 +927,62 @@ const computedToolbarMode = computed(() => {
926
927
  return 'auto'
927
928
  })
928
929
 
930
+ let fontStyleObserver: MutationObserver | null = null
931
+ const FONT_SHIELD_SCOPE_SELECTOR = '.jvs-ppt-editor-root, .sidebar-select-popper, .autofit-popover-panel, .text-popover-popper, .style-builder-dialog'
932
+
933
+ function syncElementFontVar(el: Element) {
934
+ if (!(el instanceof HTMLElement || el instanceof SVGElement)) return
935
+ const style = el.style
936
+ if (!style) return
937
+ const rawFont = style.fontFamily?.trim() || ''
938
+ const curVar = style.getPropertyValue('--ppt-font-family').trim()
939
+ if (rawFont && rawFont !== 'inherit' && rawFont !== '默认字体') {
940
+ if (curVar !== rawFont) {
941
+ style.setProperty('--ppt-font-family', rawFont)
942
+ }
943
+ } else if (curVar) {
944
+ style.removeProperty('--ppt-font-family')
945
+ }
946
+ }
947
+
948
+ function syncSubtreeFontVars(root: Element | Document) {
949
+ if (root instanceof Element) {
950
+ syncElementFontVar(root)
951
+ }
952
+ const nodes = root.querySelectorAll('[style*="font-family"], [style*="--ppt-font-family"]')
953
+ for (let i = 0; i < nodes.length; i++) {
954
+ syncElementFontVar(nodes[i])
955
+ }
956
+ }
957
+
929
958
  onMounted(async () => {
959
+ if (typeof document !== 'undefined' && typeof MutationObserver !== 'undefined') {
960
+ syncSubtreeFontVars(document)
961
+ fontStyleObserver = new MutationObserver((mutations) => {
962
+ for (let i = 0; i < mutations.length; i++) {
963
+ const m = mutations[i]
964
+ if (m.type === 'attributes' && m.target instanceof Element) {
965
+ if (m.target.closest(FONT_SHIELD_SCOPE_SELECTOR)) {
966
+ syncElementFontVar(m.target)
967
+ }
968
+ } else if (m.type === 'childList' && m.addedNodes.length > 0) {
969
+ for (let j = 0; j < m.addedNodes.length; j++) {
970
+ const node = m.addedNodes[j]
971
+ if (node instanceof Element && (node.matches(FONT_SHIELD_SCOPE_SELECTOR) || node.closest(FONT_SHIELD_SCOPE_SELECTOR))) {
972
+ syncSubtreeFontVars(node)
973
+ }
974
+ }
975
+ }
976
+ }
977
+ })
978
+ fontStyleObserver.observe(document.body, {
979
+ attributes: true,
980
+ attributeFilter: ['style'],
981
+ childList: true,
982
+ subtree: true
983
+ })
984
+ }
985
+
930
986
  // 触发 ready 事件
931
987
  emit('ready', editorApi)
932
988
 
@@ -953,6 +1009,13 @@ onMounted(async () => {
953
1009
  }
954
1010
  }
955
1011
  })
1012
+
1013
+ onBeforeUnmount(() => {
1014
+ if (fontStyleObserver) {
1015
+ fontStyleObserver.disconnect()
1016
+ fontStyleObserver = null
1017
+ }
1018
+ })
956
1019
  </script>
957
1020
 
958
1021
  <template>
@@ -426,26 +426,17 @@ function applyTextStyleToHtml(html: string, styles: any) {
426
426
  const spans = div.querySelectorAll('span')
427
427
  const paragraphs = div.querySelectorAll('p')
428
428
 
429
- if (spans.length === 0 && paragraphs.length === 0) {
430
- if (div.children.length === 0) {
431
- const colorStyle = styles.color ? `color: ${styles.color};` : ''
432
- const bgStyle = (styles.textBackground && styles.textBackground !== 'transparent') ? `background-color: ${styles.textBackground};` : ''
433
- const fontStyle = styles.fontFamily ? `font-family: ${styles.fontFamily};` : ''
434
- const sizeStyle = styles.fontSize ? `font-size: ${styles.fontSize};` : ''
435
- return `<p><span style="${colorStyle}${bgStyle}${fontStyle}${sizeStyle}">${html}</span></p>`
436
- }
437
- div.querySelectorAll('*').forEach((child: any) => {
438
- if (styles.color) child.style.color = styles.color
439
- if (styles.fontFamily) child.style.fontFamily = styles.fontFamily
440
- if (styles.fontSize) child.style.fontSize = styles.fontSize
441
- })
442
- return div.innerHTML
443
- }
444
-
445
429
  const applyTextStyles = (elem: HTMLElement) => {
446
430
  if (styles.color) elem.style.color = styles.color
447
431
  if (styles.fontSize) elem.style.fontSize = styles.fontSize
448
- if (styles.fontFamily) elem.style.fontFamily = styles.fontFamily
432
+ if (styles.fontFamily) {
433
+ elem.style.fontFamily = styles.fontFamily
434
+ if (styles.fontFamily !== 'inherit' && styles.fontFamily !== '默认字体') {
435
+ elem.style.setProperty('--ppt-font-family', styles.fontFamily)
436
+ } else {
437
+ elem.style.removeProperty('--ppt-font-family')
438
+ }
439
+ }
449
440
  if (styles.fontWeight) elem.style.fontWeight = styles.fontWeight
450
441
  if (styles.fontStyle) elem.style.fontStyle = styles.fontStyle
451
442
  if (styles.textDecoration) elem.style.textDecoration = styles.textDecoration
@@ -460,20 +451,47 @@ function applyTextStyleToHtml(html: string, styles: any) {
460
451
  }
461
452
  }
462
453
 
454
+ if (spans.length === 0 && paragraphs.length === 0) {
455
+ if (div.children.length === 0) {
456
+ const colorStyle = styles.color ? `color: ${styles.color};` : ''
457
+ const bgStyle = (styles.textBackground && styles.textBackground !== 'transparent') ? `background-color: ${styles.textBackground};` : ''
458
+ const fontStyle = styles.fontFamily ? `font-family: ${styles.fontFamily}; --ppt-font-family: ${styles.fontFamily};` : ''
459
+ const sizeStyle = styles.fontSize ? `font-size: ${styles.fontSize};` : ''
460
+ const weightStyle = styles.fontWeight ? `font-weight: ${styles.fontWeight};` : ''
461
+ const italicStyle = styles.fontStyle ? `font-style: ${styles.fontStyle};` : ''
462
+ return `<p><span style="${colorStyle}${bgStyle}${fontStyle}${sizeStyle}${weightStyle}${italicStyle}">${html}</span></p>`
463
+ }
464
+ div.querySelectorAll('*').forEach((child: any) => {
465
+ applyTextStyles(child)
466
+ })
467
+ return div.innerHTML
468
+ }
469
+
463
470
  spans.forEach(applyTextStyles)
464
471
  if (spans.length === 0) {
465
472
  paragraphs.forEach(applyTextStyles)
466
473
  }
467
474
 
468
- // 综合处理字体与样式覆盖:如果指定了 fontFamily 或 fontSize,清理/更新所有块级和内联节点的原有硬编码值
469
- if (styles.fontFamily || styles.fontSize) {
475
+ // 综合处理字体与样式覆盖:如果指定了 fontFamily、fontSize、fontWeight 或 fontStyle,清理/更新所有块级和内联节点的原有硬编码值
476
+ if (styles.fontFamily || styles.fontSize || styles.fontWeight || styles.fontStyle) {
470
477
  div.querySelectorAll('p, div, li, h1, h2, h3, h4, h5, h6, span, b, strong, i, em, a').forEach((elem: any) => {
471
478
  if (styles.fontFamily && elem.style && elem.style.fontFamily) {
472
479
  elem.style.fontFamily = styles.fontFamily
480
+ if (styles.fontFamily !== 'inherit' && styles.fontFamily !== '默认字体') {
481
+ elem.style.setProperty('--ppt-font-family', styles.fontFamily)
482
+ } else {
483
+ elem.style.removeProperty('--ppt-font-family')
484
+ }
473
485
  }
474
486
  if (styles.fontSize && elem.style && elem.style.fontSize) {
475
487
  elem.style.fontSize = styles.fontSize
476
488
  }
489
+ if (styles.fontWeight && elem.style && elem.style.fontWeight) {
490
+ elem.style.fontWeight = styles.fontWeight
491
+ }
492
+ if (styles.fontStyle && elem.style && elem.style.fontStyle) {
493
+ elem.style.fontStyle = styles.fontStyle
494
+ }
477
495
  })
478
496
  }
479
497
 
@@ -534,6 +552,10 @@ function setStyleVal(prop: string, val: any) {
534
552
  el.content = applyTextStyleToHtml(el.content, { fontFamily: val })
535
553
  } else if (prop === 'fontSize') {
536
554
  el.content = applyTextStyleToHtml(el.content, { fontSize: val })
555
+ } else if (prop === 'fontWeight') {
556
+ el.content = applyTextStyleToHtml(el.content, { fontWeight: val })
557
+ } else if (prop === 'fontStyle') {
558
+ el.content = applyTextStyleToHtml(el.content, { fontStyle: val })
537
559
  } else if (prop === 'color' || prop === 'textColor') {
538
560
  el.content = applyTextStyleToHtml(el.content, { color: val })
539
561
  } else if (prop === 'textBackground') {
@@ -549,6 +571,10 @@ function setStyleVal(prop: string, val: any) {
549
571
  el.text.content = applyTextStyleToHtml(el.text.content, { fontFamily: val })
550
572
  } else if (prop === 'fontSize') {
551
573
  el.text.content = applyTextStyleToHtml(el.text.content, { fontSize: val })
574
+ } else if (prop === 'fontWeight') {
575
+ el.text.content = applyTextStyleToHtml(el.text.content, { fontWeight: val })
576
+ } else if (prop === 'fontStyle') {
577
+ el.text.content = applyTextStyleToHtml(el.text.content, { fontStyle: val })
552
578
  } else if (prop === 'color' || prop === 'textColor') {
553
579
  el.text.content = applyTextStyleToHtml(el.text.content, { color: val })
554
580
  } else if (prop === 'textBackground') {
@@ -563,6 +589,10 @@ function setStyleVal(prop: string, val: any) {
563
589
  el.text = applyTextStyleToHtml(el.text, { fontFamily: val })
564
590
  } else if (prop === 'fontSize') {
565
591
  el.text = applyTextStyleToHtml(el.text, { fontSize: val })
592
+ } else if (prop === 'fontWeight') {
593
+ el.text = applyTextStyleToHtml(el.text, { fontWeight: val })
594
+ } else if (prop === 'fontStyle') {
595
+ el.text = applyTextStyleToHtml(el.text, { fontStyle: val })
566
596
  } else if (prop === 'color' || prop === 'textColor') {
567
597
  el.text = applyTextStyleToHtml(el.text, { color: val })
568
598
  } else if (prop === 'textBackground') {
@@ -574,15 +604,22 @@ function setStyleVal(prop: string, val: any) {
574
604
  }
575
605
  }
576
606
 
577
- if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'textAlign') {
607
+ if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign') {
578
608
  const container = document.getElementById(`editable-${el.id}`)
579
609
  if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
580
610
  if (prop === 'fontFamily') {
581
611
  container.style.fontFamily = val
612
+ container.style.setProperty('--ppt-font-family', val)
582
613
  container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
583
614
  } else if (prop === 'fontSize') {
584
615
  container.style.fontSize = val
585
616
  container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
617
+ } else if (prop === 'fontWeight') {
618
+ container.style.fontWeight = val
619
+ container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
620
+ } else if (prop === 'fontStyle') {
621
+ container.style.fontStyle = val
622
+ container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
586
623
  } else if (prop === 'textAlign') {
587
624
  container.style.textAlign = val
588
625
  container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
@@ -638,6 +675,10 @@ function setStyleVal(prop: string, val: any) {
638
675
  el.content = applyTextStyleToHtml(el.content, { fontFamily: val })
639
676
  } else if (prop === 'fontSize') {
640
677
  el.content = applyTextStyleToHtml(el.content, { fontSize: val })
678
+ } else if (prop === 'fontWeight') {
679
+ el.content = applyTextStyleToHtml(el.content, { fontWeight: val })
680
+ } else if (prop === 'fontStyle') {
681
+ el.content = applyTextStyleToHtml(el.content, { fontStyle: val })
641
682
  } else if (prop === 'color' || prop === 'textColor') {
642
683
  el.content = applyTextStyleToHtml(el.content, { color: val })
643
684
  } else if (prop === 'textBackground') {
@@ -653,6 +694,10 @@ function setStyleVal(prop: string, val: any) {
653
694
  el.text.content = applyTextStyleToHtml(el.text.content, { fontFamily: val })
654
695
  } else if (prop === 'fontSize') {
655
696
  el.text.content = applyTextStyleToHtml(el.text.content, { fontSize: val })
697
+ } else if (prop === 'fontWeight') {
698
+ el.text.content = applyTextStyleToHtml(el.text.content, { fontWeight: val })
699
+ } else if (prop === 'fontStyle') {
700
+ el.text.content = applyTextStyleToHtml(el.text.content, { fontStyle: val })
656
701
  } else if (prop === 'color' || prop === 'textColor') {
657
702
  el.text.content = applyTextStyleToHtml(el.text.content, { color: val })
658
703
  } else if (prop === 'textBackground') {
@@ -667,6 +712,10 @@ function setStyleVal(prop: string, val: any) {
667
712
  el.text = applyTextStyleToHtml(el.text, { fontFamily: val })
668
713
  } else if (prop === 'fontSize') {
669
714
  el.text = applyTextStyleToHtml(el.text, { fontSize: val })
715
+ } else if (prop === 'fontWeight') {
716
+ el.text = applyTextStyleToHtml(el.text, { fontWeight: val })
717
+ } else if (prop === 'fontStyle') {
718
+ el.text = applyTextStyleToHtml(el.text, { fontStyle: val })
670
719
  } else if (prop === 'color' || prop === 'textColor') {
671
720
  el.text = applyTextStyleToHtml(el.text, { color: val })
672
721
  } else if (prop === 'textBackground') {
@@ -678,15 +727,22 @@ function setStyleVal(prop: string, val: any) {
678
727
  }
679
728
  }
680
729
 
681
- if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'textAlign') {
730
+ if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign') {
682
731
  const container = document.getElementById(`editable-${el.id}`)
683
732
  if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
684
733
  if (prop === 'fontFamily') {
685
734
  container.style.fontFamily = val
735
+ container.style.setProperty('--ppt-font-family', val)
686
736
  container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
687
737
  } else if (prop === 'fontSize') {
688
738
  container.style.fontSize = val
689
739
  container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
740
+ } else if (prop === 'fontWeight') {
741
+ container.style.fontWeight = val
742
+ container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
743
+ } else if (prop === 'fontStyle') {
744
+ container.style.fontStyle = val
745
+ container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
690
746
  } else if (prop === 'textAlign') {
691
747
  container.style.textAlign = val
692
748
  container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
@@ -472,7 +472,7 @@ const radarPolygons = computed(() => {
472
472
  <template>
473
473
  <svg
474
474
  :viewBox="`0 0 ${width} ${height}`"
475
- style="width: 100%; height: 100%; display: block; overflow: visible; user-select: none;"
475
+ :style="{ width: '100%', height: '100%', display: 'block', overflow: 'visible', userSelect: 'none', fontFamily: fontFamily, '--ppt-font-family': fontFamily }"
476
476
  >
477
477
  <!-- Background Grid & Ticks (Cartesian charts only) -->
478
478
  <g v-if="['bar', 'line', 'area', 'scatter'].includes(chartType) && showGridlines">